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