^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2005, 2007 Bartlomiej Zolnierkiewicz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Mostly written by Mark Lord <mlord@pobox.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * and Gadi Oxman <gadio@netvision.net.il>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * and Andre Hedrick <andre@linux-ide.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * See linux/MAINTAINERS for address of current maintainer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * This is the IDE probe module, as evolved from hd.c and ide.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * -- increase WAIT_PIDENTIFY to avoid CD-ROM locking at boot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * by Andrea Arcangeli
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/kernel.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/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/ide.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/kmod.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/scatterlist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <asm/irq.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 <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * generic_id - add a generic drive id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * @drive: drive to make an ID block for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * Add a fake id field to the drive we are passed. This allows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * use to skip a ton of NULL checks (which people always miss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * and make drive properties unconditional outside of this file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static void generic_id(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u16 *id = drive->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) id[ATA_ID_CUR_CYLS] = id[ATA_ID_CYLS] = drive->cyl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) id[ATA_ID_CUR_HEADS] = id[ATA_ID_HEADS] = drive->head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) id[ATA_ID_CUR_SECTORS] = id[ATA_ID_SECTORS] = drive->sect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static void ide_disk_init_chs(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) u16 *id = drive->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* Extract geometry if we did not already have one for the drive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (!drive->cyl || !drive->head || !drive->sect) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) drive->cyl = drive->bios_cyl = id[ATA_ID_CYLS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) drive->head = drive->bios_head = id[ATA_ID_HEADS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) drive->sect = drive->bios_sect = id[ATA_ID_SECTORS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* Handle logical geometry translation by the drive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (ata_id_current_chs_valid(id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) drive->cyl = id[ATA_ID_CUR_CYLS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) drive->head = id[ATA_ID_CUR_HEADS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) drive->sect = id[ATA_ID_CUR_SECTORS];
^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) /* Use physical geometry if what we have still makes no sense */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (drive->head > 16 && id[ATA_ID_HEADS] && id[ATA_ID_HEADS] <= 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) drive->cyl = id[ATA_ID_CYLS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) drive->head = id[ATA_ID_HEADS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) drive->sect = id[ATA_ID_SECTORS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static void ide_disk_init_mult_count(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u16 *id = drive->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) u8 max_multsect = id[ATA_ID_MAX_MULTSECT] & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (max_multsect) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if ((max_multsect / 2) > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) id[ATA_ID_MULTSECT] = max_multsect | 0x100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) id[ATA_ID_MULTSECT] &= ~0x1ff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) drive->mult_req = id[ATA_ID_MULTSECT] & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (drive->mult_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) drive->special_flags |= IDE_SFLAG_SET_MULTMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static void ide_classify_ata_dev(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) u16 *id = drive->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) char *m = (char *)&id[ATA_ID_PROD];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) int is_cfa = ata_id_is_cfa(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* CF devices are *not* removable in Linux definition of the term */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (is_cfa == 0 && (id[ATA_ID_CONFIG] & (1 << 7)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) drive->dev_flags |= IDE_DFLAG_REMOVABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) drive->media = ide_disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (!ata_id_has_unload(drive->id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) printk(KERN_INFO "%s: %s, %s DISK drive\n", drive->name, m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) is_cfa ? "CFA" : "ATA");
^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 void ide_classify_atapi_dev(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) u16 *id = drive->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) char *m = (char *)&id[ATA_ID_PROD];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) u8 type = (id[ATA_ID_CONFIG] >> 8) & 0x1f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) printk(KERN_INFO "%s: %s, ATAPI ", drive->name, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) case ide_floppy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (!strstr(m, "CD-ROM")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (!strstr(m, "oppy") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) !strstr(m, "poyp") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) !strstr(m, "ZIP"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) printk(KERN_CONT "cdrom or floppy?, assuming ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (drive->media != ide_cdrom) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) printk(KERN_CONT "FLOPPY");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) drive->dev_flags |= IDE_DFLAG_REMOVABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* Early cdrom models used zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) type = ide_cdrom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) case ide_cdrom:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) drive->dev_flags |= IDE_DFLAG_REMOVABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #ifdef CONFIG_PPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /* kludge for Apple PowerBook internal zip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (!strstr(m, "CD-ROM") && strstr(m, "ZIP")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) printk(KERN_CONT "FLOPPY");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) type = ide_floppy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) printk(KERN_CONT "CD/DVD-ROM");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) case ide_tape:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) printk(KERN_CONT "TAPE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) case ide_optical:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) printk(KERN_CONT "OPTICAL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) drive->dev_flags |= IDE_DFLAG_REMOVABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) printk(KERN_CONT "UNKNOWN (type %d)", type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) printk(KERN_CONT " drive\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) drive->media = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* an ATAPI device ignores DRDY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) drive->ready_stat = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (ata_id_cdb_intr(id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) drive->dev_flags |= IDE_DFLAG_DOORLOCKING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /* we don't do head unloading on ATAPI devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * do_identify - identify a drive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * @drive: drive to identify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * @cmd: command used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * @id: buffer for IDENTIFY data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * Called when we have issued a drive identify command to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * read and parse the results. This function is run with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * interrupts disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static void do_identify(ide_drive_t *drive, u8 cmd, u16 *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) char *m = (char *)&id[ATA_ID_PROD];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int bswap = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /* local CPU only; some systems need this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* read 512 bytes of id info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) hwif->tp_ops->input_data(drive, NULL, id, SECTOR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) drive->dev_flags |= IDE_DFLAG_ID_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) printk(KERN_INFO "%s: dumping identify data\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) ide_dump_identify((u8 *)id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) ide_fix_driveid(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * ATA_CMD_ID_ATA returns little-endian info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * ATA_CMD_ID_ATAPI *usually* returns little-endian info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (cmd == ATA_CMD_ID_ATAPI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if ((m[0] == 'N' && m[1] == 'E') || /* NEC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) (m[0] == 'F' && m[1] == 'X') || /* Mitsumi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) (m[0] == 'P' && m[1] == 'i')) /* Pioneer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* Vertos drives may still be weird */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) bswap ^= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) ide_fixstring(m, ATA_ID_PROD_LEN, bswap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) ide_fixstring((char *)&id[ATA_ID_FW_REV], ATA_ID_FW_REV_LEN, bswap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) ide_fixstring((char *)&id[ATA_ID_SERNO], ATA_ID_SERNO_LEN, bswap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /* we depend on this a lot! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) m[ATA_ID_PROD_LEN - 1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (strstr(m, "E X A B Y T E N E S T"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) drive->dev_flags &= ~IDE_DFLAG_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) drive->dev_flags |= IDE_DFLAG_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * ide_dev_read_id - send ATA/ATAPI IDENTIFY command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * @drive: drive to identify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * @cmd: command to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * @id: buffer for IDENTIFY data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * @irq_ctx: flag set when called from the IRQ context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * Sends an ATA(PI) IDENTIFY request to a drive and waits for a response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * Returns: 0 device was identified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * 1 device timed-out (no response to identify request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * 2 device aborted the command (refused to identify itself)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id, int irq_ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct ide_io_ports *io_ports = &hwif->io_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) const struct ide_tp_ops *tp_ops = hwif->tp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int use_altstatus = 0, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) unsigned long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) u8 s = 0, a = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * Disable device IRQ. Otherwise we'll get spurious interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * during the identify phase that the IRQ handler isn't expecting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (io_ports->ctl_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) tp_ops->write_devctl(hwif, ATA_NIEN | ATA_DEVCTL_OBS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /* take a deep breath */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (irq_ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) mdelay(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (io_ports->ctl_addr &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) (hwif->host_flags & IDE_HFLAG_BROKEN_ALTSTATUS) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) a = tp_ops->read_altstatus(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) s = tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if ((a ^ s) & ~ATA_SENSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /* ancient Seagate drives, broken interfaces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) printk(KERN_INFO "%s: probing with STATUS(0x%02x) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) "instead of ALTSTATUS(0x%02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) drive->name, s, a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* use non-intrusive polling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) use_altstatus = 1;
^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) /* set features register for atapi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) * identify command to be sure of reply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (cmd == ATA_CMD_ID_ATAPI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct ide_taskfile tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) memset(&tf, 0, sizeof(tf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /* disable DMA & overlap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) tp_ops->tf_load(drive, &tf, IDE_VALID_FEATURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /* ask drive for ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) tp_ops->exec_command(hwif, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) timeout = ((cmd == ATA_CMD_ID_ATA) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /* wait for IRQ and ATA_DRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (irq_ctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) rc = __ide_wait_stat(drive, ATA_DRQ, BAD_R_STAT, timeout, &s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) rc = ide_busy_sleep(drive, timeout, use_altstatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) s = tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (OK_STAT(s, ATA_DRQ, BAD_R_STAT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /* drive returned ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) do_identify(drive, cmd, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) /* drive responded with ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) /* clear drive IRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) (void)tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) /* drive refused ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) rc = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) int ide_busy_sleep(ide_drive_t *drive, unsigned long timeout, int altstatus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) u8 stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) timeout += jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) msleep(50); /* give drive a breather */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) stat = altstatus ? hwif->tp_ops->read_altstatus(hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) : hwif->tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if ((stat & ATA_BUSY) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) } while (time_before(jiffies, timeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) printk(KERN_ERR "%s: timeout in %s\n", drive->name, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return 1; /* drive timed-out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) static u8 ide_read_device(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct ide_taskfile tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) drive->hwif->tp_ops->tf_read(drive, &tf, IDE_VALID_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) return tf.device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * do_probe - probe an IDE device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * @drive: drive to probe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * @cmd: command to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * do_probe() has the difficult job of finding a drive if it exists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * without getting hung up if it doesn't exist, without trampling on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * ethernet cards, and without leaving any IRQs dangling to haunt us later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) * If a drive is "known" to exist (from CMOS or kernel parameters),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) * but does not respond right away, the probe will "hang in there"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) * for the maximum wait time (about 30 seconds), otherwise it will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * exit much more quickly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) * Returns: 0 device was identified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * 1 device timed-out (no response to identify request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * 2 device aborted the command (refused to identify itself)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) * 3 bad status from device (possible for ATAPI drives)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * 4 probe was not attempted because failure was obvious
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static int do_probe (ide_drive_t *drive, u8 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) const struct ide_tp_ops *tp_ops = hwif->tp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) u16 *id = drive->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) u8 present = !!(drive->dev_flags & IDE_DFLAG_PRESENT), stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) /* avoid waiting for inappropriate probes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) if (present && drive->media != ide_disk && cmd == ATA_CMD_ID_ATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) return 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) printk(KERN_INFO "probing for %s: present=%d, media=%d, probetype=%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) drive->name, present, drive->media,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) (cmd == ATA_CMD_ID_ATA) ? "ATA" : "ATAPI");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) /* needed for some systems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * (e.g. crw9624 as drive0 with disk as slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) tp_ops->dev_select(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (ide_read_device(drive) != drive->select && present == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (drive->dn & 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) /* exit with drive0 selected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) tp_ops->dev_select(hwif->devices[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /* allow ATA_BUSY to assert & clear */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /* no i/f present: mmm.. this should be a 4 -ml */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) stat = tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) if (OK_STAT(stat, ATA_DRDY, ATA_BUSY) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) present || cmd == ATA_CMD_ID_ATAPI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) rc = ide_dev_read_id(drive, cmd, id, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /* failed: try again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) rc = ide_dev_read_id(drive, cmd, id, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) stat = tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (stat == (ATA_BUSY | ATA_DRDY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) return 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (rc == 1 && cmd == ATA_CMD_ID_ATAPI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) printk(KERN_ERR "%s: no response (status = 0x%02x), "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) "resetting drive\n", drive->name, stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) tp_ops->dev_select(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) (void)ide_busy_sleep(drive, WAIT_WORSTCASE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) rc = ide_dev_read_id(drive, cmd, id, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) /* ensure drive IRQ is clear */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) stat = tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (rc == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) printk(KERN_ERR "%s: no response (status = 0x%02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) drive->name, stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /* not present or maybe ATAPI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) rc = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if (drive->dn & 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) /* exit with drive0 selected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) tp_ops->dev_select(hwif->devices[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) /* ensure drive irq is clear */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) (void)tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^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) * probe_for_drives - upper level drive probe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) * @drive: drive to probe for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * probe_for_drive() tests for existence of a given drive using do_probe()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * and presents things to the user as needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) * Returns: 0 no device was found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * 1 device was found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * (note: IDE_DFLAG_PRESENT might still be not set)
^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) static u8 probe_for_drive(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) char *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) u8 cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) drive->dev_flags &= ~IDE_DFLAG_ID_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) m = (char *)&drive->id[ATA_ID_PROD];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) strcpy(m, "UNKNOWN");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) /* skip probing? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) /* if !(success||timed-out) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) cmd = ATA_CMD_ID_ATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) rc = do_probe(drive, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (rc >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) /* look for ATAPI device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) cmd = ATA_CMD_ID_ATAPI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) rc = do_probe(drive, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) /* identification failed? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (drive->media == ide_disk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) printk(KERN_INFO "%s: non-IDE drive, CHS=%d/%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) drive->name, drive->cyl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) drive->head, drive->sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) } else if (drive->media == ide_cdrom) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) printk(KERN_INFO "%s: ATAPI cdrom (?)\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) /* nuke it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) printk(KERN_WARNING "%s: Unknown device on bus refused identification. Ignoring.\n", drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) drive->dev_flags &= ~IDE_DFLAG_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if (cmd == ATA_CMD_ID_ATAPI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) ide_classify_atapi_dev(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) ide_classify_ata_dev(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) /* The drive wasn't being helpful. Add generic info only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) generic_id(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (drive->media == ide_disk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) ide_disk_init_chs(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) ide_disk_init_mult_count(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) static void hwif_release_dev(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) ide_hwif_t *hwif = container_of(dev, ide_hwif_t, gendev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) complete(&hwif->gendev_rel_comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) static int ide_register_port(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) /* register with global device tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) dev_set_name(&hwif->gendev, "%s", hwif->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) dev_set_drvdata(&hwif->gendev, hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) if (hwif->gendev.parent == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) hwif->gendev.parent = hwif->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) hwif->gendev.release = hwif_release_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) ret = device_register(&hwif->gendev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) printk(KERN_WARNING "IDE: %s: device_register error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) hwif->portdev = device_create(ide_port_class, &hwif->gendev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) MKDEV(0, 0), hwif, "%s", hwif->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) if (IS_ERR(hwif->portdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) ret = PTR_ERR(hwif->portdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) device_unregister(&hwif->gendev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * ide_port_wait_ready - wait for port to become ready
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * @hwif: IDE port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) * This is needed on some PPCs and a bunch of BIOS-less embedded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) * platforms. Typical cases are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) * - The firmware hard reset the disk before booting the kernel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) * the drive is still doing it's poweron-reset sequence, that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) * can take up to 30 seconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) * - The firmware does nothing (or no firmware), the device is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) * still in POST state (same as above actually).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) * - Some CD/DVD/Writer combo drives tend to drive the bus during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) * their reset sequence even when they are non-selected slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) * devices, thus preventing discovery of the main HD.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) * Doing this wait-for-non-busy should not harm any existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) * configuration and fix some issues like the above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) * BenH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) * Returns 0 on success, error code (< 0) otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) static int ide_port_wait_ready(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) const struct ide_tp_ops *tp_ops = hwif->tp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) ide_drive_t *drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) int i, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) printk(KERN_DEBUG "Probing IDE interface %s...\n", hwif->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) /* Let HW settle down a bit from whatever init state we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) * come from */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) mdelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) /* Wait for BSY bit to go away, spec timeout is 30 seconds,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) * I know of at least one disk who takes 31 seconds, I use 35
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) * here to be safe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) rc = ide_wait_not_busy(hwif, 35000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) /* Now make sure both master & slave are ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) ide_port_for_each_dev(i, drive, hwif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) /* Ignore disks that we will not probe for later. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) (drive->dev_flags & IDE_DFLAG_PRESENT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) tp_ops->dev_select(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) mdelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) rc = ide_wait_not_busy(hwif, 35000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) printk(KERN_DEBUG "%s: ide_wait_not_busy() skipped\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) /* Exit function with master reselected (let's be sane) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) if (i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) tp_ops->dev_select(hwif->devices[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) * ide_undecoded_slave - look for bad CF adapters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) * @dev1: slave device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) * Analyse the drives on the interface and attempt to decide if we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) * have the same drive viewed twice. This occurs with crap CF adapters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) * and PCMCIA sometimes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) void ide_undecoded_slave(ide_drive_t *dev1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) ide_drive_t *dev0 = dev1->hwif->devices[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) if ((dev1->dn & 1) == 0 || (dev0->dev_flags & IDE_DFLAG_PRESENT) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) /* If the models don't match they are not the same product */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (strcmp((char *)&dev0->id[ATA_ID_PROD],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) (char *)&dev1->id[ATA_ID_PROD]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) /* Serial numbers do not match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) if (strncmp((char *)&dev0->id[ATA_ID_SERNO],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) (char *)&dev1->id[ATA_ID_SERNO], ATA_ID_SERNO_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /* No serial number, thankfully very rare for CF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) if (*(char *)&dev0->id[ATA_ID_SERNO] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) /* Appears to be an IDE flash adapter with decode bugs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) printk(KERN_WARNING "ide-probe: ignoring undecoded slave\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) dev1->dev_flags &= ~IDE_DFLAG_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) EXPORT_SYMBOL_GPL(ide_undecoded_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) static int ide_probe_port(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) ide_drive_t *drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) unsigned int irqd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) int i, rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) BUG_ON(hwif->present);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) if ((hwif->devices[0]->dev_flags & IDE_DFLAG_NOPROBE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) (hwif->devices[1]->dev_flags & IDE_DFLAG_NOPROBE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) return -EACCES;
^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) * We must always disable IRQ, as probe_for_drive will assert IRQ, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) * we'll install our IRQ driver much later...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) irqd = hwif->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) if (irqd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) disable_irq(hwif->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) if (ide_port_wait_ready(hwif) == -EBUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) printk(KERN_DEBUG "%s: Wait for ready failed before probe !\n", hwif->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) * Second drive should only exist if first drive was found,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) * but a lot of cdrom drives are configured as single slaves.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) ide_port_for_each_dev(i, drive, hwif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) (void) probe_for_drive(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if (drive->dev_flags & IDE_DFLAG_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) * Use cached IRQ number. It might be (and is...) changed by probe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) * code above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) if (irqd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) enable_irq(irqd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) static void ide_port_tune_devices(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) const struct ide_port_ops *port_ops = hwif->port_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) ide_drive_t *drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) ide_port_for_each_present_dev(i, drive, hwif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) ide_check_nien_quirk_list(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) if (port_ops && port_ops->quirkproc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) port_ops->quirkproc(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) ide_port_for_each_present_dev(i, drive, hwif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) ide_set_max_pio(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) drive->dev_flags |= IDE_DFLAG_NICE1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) if (hwif->dma_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) ide_set_dma(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) static void ide_initialize_rq(struct request *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) struct ide_request *req = blk_mq_rq_to_pdu(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) req->special = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) scsi_req_init(&req->sreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) req->sreq.sense = req->sense;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) static const struct blk_mq_ops ide_mq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) .queue_rq = ide_queue_rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) .initialize_rq_fn = ide_initialize_rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) * init request queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) static int ide_init_queue(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) struct request_queue *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) int max_sectors = 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) int max_sg_entries = PRD_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) struct blk_mq_tag_set *set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) * Our default set up assumes the normal IDE case,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) * that is 64K segmenting, standard PRD setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) * and LBA28. Some drivers then impose their own
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) * limits and LBA48 we could raise it but as yet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) * do not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) set = &drive->tag_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) set->ops = &ide_mq_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) set->nr_hw_queues = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) set->queue_depth = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) set->reserved_tags = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) set->cmd_size = sizeof(struct ide_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) set->numa_node = hwif_to_node(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) set->flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_BLOCKING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) if (blk_mq_alloc_tag_set(set))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) q = blk_mq_init_queue(set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) if (IS_ERR(q)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) blk_mq_free_tag_set(set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) blk_queue_flag_set(QUEUE_FLAG_SCSI_PASSTHROUGH, q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) q->queuedata = drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) blk_queue_segment_boundary(q, 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) if (hwif->rqsize < max_sectors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) max_sectors = hwif->rqsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) blk_queue_max_hw_sectors(q, max_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) #ifdef CONFIG_PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) /* When we have an IOMMU, we may have a problem where pci_map_sg()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) * creates segments that don't completely match our boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) * requirements and thus need to be broken up again. Because it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) * doesn't align properly either, we may actually have to break up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) * to more segments than what was we got in the first place, a max
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) * worst case is twice as many.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) * This will be fixed once we teach pci_map_sg() about our boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) * requirements, hopefully soon. *FIXME*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) max_sg_entries >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) #endif /* CONFIG_PCI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) blk_queue_max_segments(q, max_sg_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) /* assign drive queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) drive->queue = q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) static DEFINE_MUTEX(ide_cfg_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) * For any present drive:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) * - allocate the block device queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) static int ide_port_setup_devices(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) ide_drive_t *drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) int i, j = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) mutex_lock(&ide_cfg_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) ide_port_for_each_present_dev(i, drive, hwif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) if (ide_init_queue(drive)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) printk(KERN_ERR "ide: failed to init %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) drive->dev_flags &= ~IDE_DFLAG_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) j++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) mutex_unlock(&ide_cfg_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) return j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) static void ide_host_enable_irqs(struct ide_host *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) ide_hwif_t *hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) ide_host_for_each_port(i, hwif, host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) if (hwif == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) /* clear any pending IRQs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) hwif->tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) /* unmask IRQs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) if (hwif->io_ports.ctl_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) hwif->tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) * This routine sets up the IRQ for an IDE interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) static int init_irq (ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) struct ide_io_ports *io_ports = &hwif->io_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) struct ide_host *host = hwif->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) irq_handler_t irq_handler = host->irq_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) int sa = host->irq_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) if (irq_handler == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) irq_handler = ide_intr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) if (!host->get_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) if (request_irq(hwif->irq, irq_handler, sa, hwif->name, hwif))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) goto out_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) #if !defined(__mc68000__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) printk(KERN_INFO "%s at 0x%03lx-0x%03lx,0x%03lx on irq %d", hwif->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) io_ports->data_addr, io_ports->status_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) io_ports->ctl_addr, hwif->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) printk(KERN_INFO "%s at 0x%08lx on irq %d", hwif->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) io_ports->data_addr, hwif->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) #endif /* __mc68000__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) if (hwif->host->host_flags & IDE_HFLAG_SERIALIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) printk(KERN_CONT " (serialized)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) printk(KERN_CONT "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) out_up:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) static int ata_lock(dev_t dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) /* FIXME: we want to pin hwif down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) static struct kobject *ata_probe(dev_t dev, int *part, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) ide_hwif_t *hwif = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) int unit = *part >> PARTN_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) ide_drive_t *drive = hwif->devices[unit];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) if (drive->media == ide_disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) request_module("ide-disk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) if (drive->media == ide_cdrom || drive->media == ide_optical)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) request_module("ide-cd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) if (drive->media == ide_tape)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) request_module("ide-tape");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) if (drive->media == ide_floppy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) request_module("ide-floppy");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) static struct kobject *exact_match(dev_t dev, int *part, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) struct gendisk *p = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) *part &= (1 << PARTN_BITS) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) return &disk_to_dev(p)->kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) static int exact_lock(dev_t dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) struct gendisk *p = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) if (!get_disk_and_module(p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) void ide_register_region(struct gendisk *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) blk_register_region(MKDEV(disk->major, disk->first_minor),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) disk->minors, NULL, exact_match, exact_lock, disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) EXPORT_SYMBOL_GPL(ide_register_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) void ide_unregister_region(struct gendisk *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) blk_unregister_region(MKDEV(disk->major, disk->first_minor),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) disk->minors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) EXPORT_SYMBOL_GPL(ide_unregister_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) void ide_init_disk(struct gendisk *disk, ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) unsigned int unit = drive->dn & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) disk->major = hwif->major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) disk->first_minor = unit << PARTN_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) sprintf(disk->disk_name, "hd%c", 'a' + hwif->index * MAX_DRIVES + unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) disk->queue = drive->queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) EXPORT_SYMBOL_GPL(ide_init_disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) static void drive_release_dev (struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) ide_drive_t *drive = container_of(dev, ide_drive_t, gendev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) ide_proc_unregister_device(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) if (drive->sense_rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) blk_mq_free_request(drive->sense_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) blk_cleanup_queue(drive->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) drive->queue = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) blk_mq_free_tag_set(&drive->tag_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) drive->dev_flags &= ~IDE_DFLAG_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) complete(&drive->gendev_rel_comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) static int hwif_init(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) if (!hwif->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) printk(KERN_ERR "%s: disabled, no IRQ\n", hwif->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) if (register_blkdev(hwif->major, hwif->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) if (!hwif->sg_max_nents)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) hwif->sg_max_nents = PRD_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) hwif->sg_table = kmalloc_array(hwif->sg_max_nents,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) sizeof(struct scatterlist),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) if (!hwif->sg_table) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) printk(KERN_ERR "%s: unable to allocate SG table.\n", hwif->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) sg_init_table(hwif->sg_table, hwif->sg_max_nents);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) if (init_irq(hwif)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) printk(KERN_ERR "%s: disabled, unable to get IRQ %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) hwif->name, hwif->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) blk_register_region(MKDEV(hwif->major, 0), MAX_DRIVES << PARTN_BITS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) THIS_MODULE, ata_probe, ata_lock, hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) unregister_blkdev(hwif->major, hwif->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) static void hwif_register_devices(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) ide_drive_t *drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) ide_port_for_each_present_dev(i, drive, hwif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) struct device *dev = &drive->gendev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) dev_set_name(dev, "%u.%u", hwif->index, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) dev_set_drvdata(dev, drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) dev->parent = &hwif->gendev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) dev->bus = &ide_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) dev->release = drive_release_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) ret = device_register(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) printk(KERN_WARNING "IDE: %s: device_register error: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) "%d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) static void ide_port_init_devices(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) const struct ide_port_ops *port_ops = hwif->port_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) ide_drive_t *drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) ide_port_for_each_dev(i, drive, hwif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) drive->dn = i + hwif->channel * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) if (hwif->host_flags & IDE_HFLAG_IO_32BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) drive->io_32bit = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) if (hwif->host_flags & IDE_HFLAG_NO_IO_32BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) if (hwif->host_flags & IDE_HFLAG_UNMASK_IRQS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) drive->dev_flags |= IDE_DFLAG_UNMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) drive->dev_flags |= IDE_DFLAG_NO_UNMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) drive->pio_mode = XFER_PIO_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) if (port_ops && port_ops->init_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) port_ops->init_dev(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) const struct ide_port_info *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) hwif->channel = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) hwif->chipset = d->chipset ? d->chipset : ide_pci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) if (d->init_iops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) d->init_iops(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) /* ->host_flags may be set by ->init_iops (or even earlier...) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) hwif->host_flags |= d->host_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) hwif->pio_mask = d->pio_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) if (d->tp_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) hwif->tp_ops = d->tp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) /* ->set_pio_mode for DTC2278 is currently limited to port 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) if ((hwif->host_flags & IDE_HFLAG_DTC2278) == 0 || hwif->channel == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) hwif->port_ops = d->port_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) hwif->swdma_mask = d->swdma_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) hwif->mwdma_mask = d->mwdma_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) hwif->ultra_mask = d->udma_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) if ((d->host_flags & IDE_HFLAG_NO_DMA) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) hwif->dma_ops = d->dma_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) if (d->init_dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) rc = d->init_dma(hwif, d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) rc = ide_hwif_setup_dma(hwif, d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) printk(KERN_INFO "%s: DMA disabled\n", hwif->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) hwif->dma_ops = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) hwif->dma_base = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) hwif->swdma_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) hwif->mwdma_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) hwif->ultra_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) if ((d->host_flags & IDE_HFLAG_SERIALIZE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) ((d->host_flags & IDE_HFLAG_SERIALIZE_DMA) && hwif->dma_base))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) hwif->host->host_flags |= IDE_HFLAG_SERIALIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) if (d->max_sectors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) hwif->rqsize = d->max_sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) if ((hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) (hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) hwif->rqsize = 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) hwif->rqsize = 65536;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) /* call chipset specific routine for each enabled port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) if (d->init_hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) d->init_hwif(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) static void ide_port_cable_detect(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) const struct ide_port_ops *port_ops = hwif->port_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) if (port_ops && port_ops->cable_detect && (hwif->ultra_mask & 0x78)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) if (hwif->cbl != ATA_CBL_PATA40_SHORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) hwif->cbl = port_ops->cable_detect(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) * Deferred request list insertion handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) static void drive_rq_insert_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) ide_drive_t *drive = container_of(work, ide_drive_t, rq_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) struct request *rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) blk_status_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) LIST_HEAD(list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) blk_mq_quiesce_queue(drive->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) ret = BLK_STS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) spin_lock_irq(&hwif->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) while (!list_empty(&drive->rq_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) rq = list_first_entry(&drive->rq_list, struct request, queuelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) list_del_init(&rq->queuelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) spin_unlock_irq(&hwif->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) ret = ide_issue_rq(drive, rq, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) spin_lock_irq(&hwif->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) spin_unlock_irq(&hwif->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) blk_mq_unquiesce_queue(drive->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) if (ret != BLK_STS_OK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) kblockd_schedule_work(&drive->rq_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) static const u8 ide_hwif_to_major[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) { IDE0_MAJOR, IDE1_MAJOR, IDE2_MAJOR, IDE3_MAJOR, IDE4_MAJOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) IDE5_MAJOR, IDE6_MAJOR, IDE7_MAJOR, IDE8_MAJOR, IDE9_MAJOR };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) static void ide_port_init_devices_data(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) ide_drive_t *drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) ide_port_for_each_dev(i, drive, hwif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) u8 j = (hwif->index * MAX_DRIVES) + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) u16 *saved_id = drive->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) memset(drive, 0, sizeof(*drive));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) memset(saved_id, 0, SECTOR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) drive->id = saved_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) drive->media = ide_disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) drive->select = (i << 4) | ATA_DEVICE_OBS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) drive->hwif = hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) drive->ready_stat = ATA_DRDY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) drive->bad_wstat = BAD_W_STAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) drive->special_flags = IDE_SFLAG_RECALIBRATE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) IDE_SFLAG_SET_GEOMETRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) drive->name[0] = 'h';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) drive->name[1] = 'd';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) drive->name[2] = 'a' + j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) INIT_LIST_HEAD(&drive->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) init_completion(&drive->gendev_rel_comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) INIT_WORK(&drive->rq_work, drive_rq_insert_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) INIT_LIST_HEAD(&drive->rq_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) static void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) /* fill in any non-zero initial values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) hwif->index = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) hwif->major = ide_hwif_to_major[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) hwif->name[0] = 'i';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) hwif->name[1] = 'd';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) hwif->name[2] = 'e';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) hwif->name[3] = '0' + index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) spin_lock_init(&hwif->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) timer_setup(&hwif->timer, ide_timer_expiry, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) init_completion(&hwif->gendev_rel_comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) hwif->tp_ops = &default_tp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) ide_port_init_devices_data(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) static void ide_init_port_hw(ide_hwif_t *hwif, struct ide_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) memcpy(&hwif->io_ports, &hw->io_ports, sizeof(hwif->io_ports));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) hwif->irq = hw->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) hwif->dev = hw->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) hwif->gendev.parent = hw->parent ? hw->parent : hw->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) hwif->config_data = hw->config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) static unsigned int ide_indexes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) * ide_find_port_slot - find free port slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) * @d: IDE port info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) * Return the new port slot index or -ENOENT if we are out of free slots.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) static int ide_find_port_slot(const struct ide_port_info *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) int idx = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) u8 bootable = (d && (d->host_flags & IDE_HFLAG_NON_BOOTABLE)) ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) u8 i = (d && (d->host_flags & IDE_HFLAG_QD_2ND_PORT)) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) * Claim an unassigned slot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) * Give preference to claiming other slots before claiming ide0/ide1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) * just in case there's another interface yet-to-be-scanned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) * which uses ports 0x1f0/0x170 (the ide0/ide1 defaults).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) * Unless there is a bootable card that does not use the standard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) * ports 0x1f0/0x170 (the ide0/ide1 defaults).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) mutex_lock(&ide_cfg_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) if (bootable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) if ((ide_indexes | i) != (1 << MAX_HWIFS) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) idx = ffz(ide_indexes | i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) if ((ide_indexes | 3) != (1 << MAX_HWIFS) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) idx = ffz(ide_indexes | 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) else if ((ide_indexes & 3) != 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) idx = ffz(ide_indexes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) if (idx >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) ide_indexes |= (1 << idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) mutex_unlock(&ide_cfg_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) return idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) static void ide_free_port_slot(int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) mutex_lock(&ide_cfg_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) ide_indexes &= ~(1 << idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) mutex_unlock(&ide_cfg_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) static void ide_port_free_devices(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) ide_drive_t *drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) ide_port_for_each_dev(i, drive, hwif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) kfree(drive->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) kfree(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) static int ide_port_alloc_devices(ide_hwif_t *hwif, int node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) ide_drive_t *drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) for (i = 0; i < MAX_DRIVES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) drive = kzalloc_node(sizeof(*drive), GFP_KERNEL, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) if (drive == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) goto out_nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) * In order to keep things simple we have an id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) * block for all drives at all times. If the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) * is pre ATA or refuses ATA/ATAPI identify we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) * will add faked data to this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) * Also note that 0 everywhere means "can't do X"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) drive->id = kzalloc_node(SECTOR_SIZE, GFP_KERNEL, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) if (drive->id == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) goto out_free_drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) hwif->devices[i] = drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) out_free_drive:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) kfree(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) out_nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) ide_port_free_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) struct ide_host *ide_host_alloc(const struct ide_port_info *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) struct ide_hw **hws, unsigned int n_ports)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) struct ide_host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) struct device *dev = hws[0] ? hws[0]->dev : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) int node = dev ? dev_to_node(dev) : -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) host = kzalloc_node(sizeof(*host), GFP_KERNEL, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) if (host == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) for (i = 0; i < n_ports; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) ide_hwif_t *hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) if (hws[i] == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) hwif = kzalloc_node(sizeof(*hwif), GFP_KERNEL, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) if (hwif == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) if (ide_port_alloc_devices(hwif, node) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) kfree(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) idx = ide_find_port_slot(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) if (idx < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) printk(KERN_ERR "%s: no free slot for interface\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) d ? d->name : "ide");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) ide_port_free_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) kfree(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) ide_init_port_data(hwif, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) hwif->host = host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) host->ports[i] = hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) host->n_ports++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) if (host->n_ports == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) kfree(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) host->dev[0] = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) if (d) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) host->init_chipset = d->init_chipset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) host->get_lock = d->get_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) host->release_lock = d->release_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) host->host_flags = d->host_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) host->irq_flags = d->irq_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) return host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) EXPORT_SYMBOL_GPL(ide_host_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) static void ide_port_free(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) ide_port_free_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) ide_free_port_slot(hwif->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) kfree(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) static void ide_disable_port(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) struct ide_host *host = hwif->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) printk(KERN_INFO "%s: disabling port\n", hwif->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) for (i = 0; i < MAX_HOST_PORTS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) if (host->ports[i] == hwif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) host->ports[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) host->n_ports--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) ide_port_free(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) struct ide_hw **hws)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) ide_hwif_t *hwif, *mate = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) int i, j = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) pr_warn("legacy IDE will be removed in 2021, please switch to libata\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) "Report any missing HW support to linux-ide@vger.kernel.org\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) ide_host_for_each_port(i, hwif, host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) if (hwif == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) mate = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) ide_init_port_hw(hwif, hws[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) ide_port_apply_params(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) if ((i & 1) && mate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) hwif->mate = mate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) mate->mate = hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) mate = (i & 1) ? NULL : hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) ide_init_port(hwif, i & 1, d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) ide_port_cable_detect(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) hwif->port_flags |= IDE_PFLAG_PROBING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) ide_port_init_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) ide_host_for_each_port(i, hwif, host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) if (hwif == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) if (ide_probe_port(hwif) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) hwif->present = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) hwif->port_flags &= ~IDE_PFLAG_PROBING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) if ((hwif->host_flags & IDE_HFLAG_4DRIVES) == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) hwif->mate == NULL || hwif->mate->present == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) if (ide_register_port(hwif)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) ide_disable_port(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) if (hwif->present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) ide_port_tune_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) ide_host_enable_irqs(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) ide_host_for_each_port(i, hwif, host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) if (hwif == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) if (hwif_init(hwif) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) printk(KERN_INFO "%s: failed to initialize IDE "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) "interface\n", hwif->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) device_unregister(hwif->portdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) device_unregister(&hwif->gendev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) ide_disable_port(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) if (hwif->present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) if (ide_port_setup_devices(hwif) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) hwif->present = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) j++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) ide_acpi_init_port(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) if (hwif->present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) ide_acpi_port_init_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) ide_host_for_each_port(i, hwif, host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) if (hwif == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) ide_sysfs_register_port(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) ide_proc_register_port(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) if (hwif->present) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) ide_proc_port_register_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) hwif_register_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) return j ? 0 : -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) EXPORT_SYMBOL_GPL(ide_host_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) int ide_host_add(const struct ide_port_info *d, struct ide_hw **hws,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) unsigned int n_ports, struct ide_host **hostp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) struct ide_host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) host = ide_host_alloc(d, hws, n_ports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) if (host == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) rc = ide_host_register(host, d, hws);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) ide_host_free(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) if (hostp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) *hostp = host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) EXPORT_SYMBOL_GPL(ide_host_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) static void __ide_port_unregister_devices(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) ide_drive_t *drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) ide_port_for_each_present_dev(i, drive, hwif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) device_unregister(&drive->gendev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) wait_for_completion(&drive->gendev_rel_comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) void ide_port_unregister_devices(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) mutex_lock(&ide_cfg_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) __ide_port_unregister_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) hwif->present = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) ide_port_init_devices_data(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) mutex_unlock(&ide_cfg_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) EXPORT_SYMBOL_GPL(ide_port_unregister_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) * ide_unregister - free an IDE interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) * @hwif: IDE interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) * Perform the final unregister of an IDE interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) * Locking:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) * The caller must not hold the IDE locks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) * It is up to the caller to be sure there is no pending I/O here,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) * and that the interface will not be reopened (present/vanishing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) * locking isn't yet done BTW).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) static void ide_unregister(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) BUG_ON(in_interrupt());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) BUG_ON(irqs_disabled());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) mutex_lock(&ide_cfg_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) if (hwif->present) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) __ide_port_unregister_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) hwif->present = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) ide_proc_unregister_port(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) if (!hwif->host->get_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) free_irq(hwif->irq, hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) device_unregister(hwif->portdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) device_unregister(&hwif->gendev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) wait_for_completion(&hwif->gendev_rel_comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) * Remove us from the kernel's knowledge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) kfree(hwif->sg_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) unregister_blkdev(hwif->major, hwif->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) ide_release_dma_engine(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) mutex_unlock(&ide_cfg_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) void ide_host_free(struct ide_host *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) ide_hwif_t *hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) ide_host_for_each_port(i, hwif, host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) if (hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) ide_port_free(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) kfree(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) EXPORT_SYMBOL_GPL(ide_host_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) void ide_host_remove(struct ide_host *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) ide_hwif_t *hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) ide_host_for_each_port(i, hwif, host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) if (hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) ide_unregister(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) ide_host_free(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) EXPORT_SYMBOL_GPL(ide_host_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) void ide_port_scan(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) ide_port_apply_params(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) ide_port_cable_detect(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) hwif->port_flags |= IDE_PFLAG_PROBING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) ide_port_init_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) rc = ide_probe_port(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) hwif->port_flags &= ~IDE_PFLAG_PROBING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) hwif->present = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) ide_port_tune_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) ide_port_setup_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) ide_acpi_port_init_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) hwif_register_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) ide_proc_port_register_devices(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) EXPORT_SYMBOL_GPL(ide_port_scan);