aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-probe.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide/ide-probe.c')
-rw-r--r--drivers/ide/ide-probe.c104
1 files changed, 59 insertions, 45 deletions
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 7f264ed1141b..f371b0de314f 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -97,7 +97,7 @@ static void ide_disk_init_mult_count(ide_drive_t *drive)
97 drive->mult_req = id[ATA_ID_MULTSECT] & 0xff; 97 drive->mult_req = id[ATA_ID_MULTSECT] & 0xff;
98 98
99 if (drive->mult_req) 99 if (drive->mult_req)
100 drive->special.b.set_multmode = 1; 100 drive->special_flags |= IDE_SFLAG_SET_MULTMODE;
101 } 101 }
102} 102}
103 103
@@ -295,7 +295,7 @@ int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id)
295 295
296 timeout = ((cmd == ATA_CMD_ID_ATA) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2; 296 timeout = ((cmd == ATA_CMD_ID_ATA) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2;
297 297
298 if (ide_busy_sleep(hwif, timeout, use_altstatus)) 298 if (ide_busy_sleep(drive, timeout, use_altstatus))
299 return 1; 299 return 1;
300 300
301 /* wait for IRQ and ATA_DRQ */ 301 /* wait for IRQ and ATA_DRQ */
@@ -316,8 +316,9 @@ int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id)
316 return rc; 316 return rc;
317} 317}
318 318
319int ide_busy_sleep(ide_hwif_t *hwif, unsigned long timeout, int altstatus) 319int ide_busy_sleep(ide_drive_t *drive, unsigned long timeout, int altstatus)
320{ 320{
321 ide_hwif_t *hwif = drive->hwif;
321 u8 stat; 322 u8 stat;
322 323
323 timeout += jiffies; 324 timeout += jiffies;
@@ -330,6 +331,8 @@ int ide_busy_sleep(ide_hwif_t *hwif, unsigned long timeout, int altstatus)
330 return 0; 331 return 0;
331 } while (time_before(jiffies, timeout)); 332 } while (time_before(jiffies, timeout));
332 333
334 printk(KERN_ERR "%s: timeout in %s\n", drive->name, __func__);
335
333 return 1; /* drive timed-out */ 336 return 1; /* drive timed-out */
334} 337}
335 338
@@ -420,7 +423,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
420 tp_ops->dev_select(drive); 423 tp_ops->dev_select(drive);
421 msleep(50); 424 msleep(50);
422 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET); 425 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
423 (void)ide_busy_sleep(hwif, WAIT_WORSTCASE, 0); 426 (void)ide_busy_sleep(drive, WAIT_WORSTCASE, 0);
424 rc = ide_dev_read_id(drive, cmd, id); 427 rc = ide_dev_read_id(drive, cmd, id);
425 } 428 }
426 429
@@ -462,23 +465,8 @@ static u8 probe_for_drive(ide_drive_t *drive)
462 int rc; 465 int rc;
463 u8 cmd; 466 u8 cmd;
464 467
465 /*
466 * In order to keep things simple we have an id
467 * block for all drives at all times. If the device
468 * is pre ATA or refuses ATA/ATAPI identify we
469 * will add faked data to this.
470 *
471 * Also note that 0 everywhere means "can't do X"
472 */
473
474 drive->dev_flags &= ~IDE_DFLAG_ID_READ; 468 drive->dev_flags &= ~IDE_DFLAG_ID_READ;
475 469
476 drive->id = kzalloc(SECTOR_SIZE, GFP_KERNEL);
477 if (drive->id == NULL) {
478 printk(KERN_ERR "ide: out of memory for id data.\n");
479 return 0;
480 }
481
482 m = (char *)&drive->id[ATA_ID_PROD]; 470 m = (char *)&drive->id[ATA_ID_PROD];
483 strcpy(m, "UNKNOWN"); 471 strcpy(m, "UNKNOWN");
484 472
@@ -494,7 +482,7 @@ static u8 probe_for_drive(ide_drive_t *drive)
494 } 482 }
495 483
496 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) 484 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
497 goto out_free; 485 return 0;
498 486
499 /* identification failed? */ 487 /* identification failed? */
500 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) { 488 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
@@ -518,7 +506,7 @@ static u8 probe_for_drive(ide_drive_t *drive)
518 } 506 }
519 507
520 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) 508 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
521 goto out_free; 509 return 0;
522 510
523 /* The drive wasn't being helpful. Add generic info only */ 511 /* The drive wasn't being helpful. Add generic info only */
524 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) { 512 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
@@ -532,9 +520,6 @@ static u8 probe_for_drive(ide_drive_t *drive)
532 } 520 }
533 521
534 return 1; 522 return 1;
535out_free:
536 kfree(drive->id);
537 return 0;
538} 523}
539 524
540static void hwif_release_dev(struct device *dev) 525static void hwif_release_dev(struct device *dev)
@@ -699,8 +684,14 @@ static int ide_probe_port(ide_hwif_t *hwif)
699 if (irqd) 684 if (irqd)
700 disable_irq(hwif->irq); 685 disable_irq(hwif->irq);
701 686
702 if (ide_port_wait_ready(hwif) == -EBUSY) 687 rc = ide_port_wait_ready(hwif);
703 printk(KERN_DEBUG "%s: Wait for ready failed before probe !\n", hwif->name); 688 if (rc == -ENODEV) {
689 printk(KERN_INFO "%s: no devices on the port\n", hwif->name);
690 goto out;
691 } else if (rc == -EBUSY)
692 printk(KERN_ERR "%s: not ready before the probe\n", hwif->name);
693 else
694 rc = -ENODEV;
704 695
705 /* 696 /*
706 * Second drive should only exist if first drive was found, 697 * Second drive should only exist if first drive was found,
@@ -711,7 +702,7 @@ static int ide_probe_port(ide_hwif_t *hwif)
711 if (drive->dev_flags & IDE_DFLAG_PRESENT) 702 if (drive->dev_flags & IDE_DFLAG_PRESENT)
712 rc = 0; 703 rc = 0;
713 } 704 }
714 705out:
715 /* 706 /*
716 * Use cached IRQ number. It might be (and is...) changed by probe 707 * Use cached IRQ number. It might be (and is...) changed by probe
717 * code above 708 * code above
@@ -729,6 +720,8 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
729 int i; 720 int i;
730 721
731 ide_port_for_each_present_dev(i, drive, hwif) { 722 ide_port_for_each_present_dev(i, drive, hwif) {
723 ide_check_nien_quirk_list(drive);
724
732 if (port_ops && port_ops->quirkproc) 725 if (port_ops && port_ops->quirkproc)
733 port_ops->quirkproc(drive); 726 port_ops->quirkproc(drive);
734 } 727 }
@@ -814,8 +807,6 @@ static int ide_port_setup_devices(ide_hwif_t *hwif)
814 if (ide_init_queue(drive)) { 807 if (ide_init_queue(drive)) {
815 printk(KERN_ERR "ide: failed to init %s\n", 808 printk(KERN_ERR "ide: failed to init %s\n",
816 drive->name); 809 drive->name);
817 kfree(drive->id);
818 drive->id = NULL;
819 drive->dev_flags &= ~IDE_DFLAG_PRESENT; 810 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
820 continue; 811 continue;
821 } 812 }
@@ -944,9 +935,6 @@ static void drive_release_dev (struct device *dev)
944 blk_cleanup_queue(drive->queue); 935 blk_cleanup_queue(drive->queue);
945 drive->queue = NULL; 936 drive->queue = NULL;
946 937
947 kfree(drive->id);
948 drive->id = NULL;
949
950 drive->dev_flags &= ~IDE_DFLAG_PRESENT; 938 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
951 939
952 complete(&drive->gendev_rel_comp); 940 complete(&drive->gendev_rel_comp);
@@ -1032,6 +1020,15 @@ static void ide_port_init_devices(ide_hwif_t *hwif)
1032 if (port_ops && port_ops->init_dev) 1020 if (port_ops && port_ops->init_dev)
1033 port_ops->init_dev(drive); 1021 port_ops->init_dev(drive);
1034 } 1022 }
1023
1024 ide_port_for_each_dev(i, drive, hwif) {
1025 /*
1026 * default to PIO Mode 0 before we figure out
1027 * the most suited mode for the attached device
1028 */
1029 if (port_ops && port_ops->set_pio_mode)
1030 port_ops->set_pio_mode(drive, 0);
1031 }
1035} 1032}
1036 1033
1037static void ide_init_port(ide_hwif_t *hwif, unsigned int port, 1034static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
@@ -1039,8 +1036,7 @@ static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
1039{ 1036{
1040 hwif->channel = port; 1037 hwif->channel = port;
1041 1038
1042 if (d->chipset) 1039 hwif->chipset = d->chipset ? d->chipset : ide_pci;
1043 hwif->chipset = d->chipset;
1044 1040
1045 if (d->init_iops) 1041 if (d->init_iops)
1046 d->init_iops(hwif); 1042 d->init_iops(hwif);
@@ -1121,16 +1117,19 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
1121 1117
1122 ide_port_for_each_dev(i, drive, hwif) { 1118 ide_port_for_each_dev(i, drive, hwif) {
1123 u8 j = (hwif->index * MAX_DRIVES) + i; 1119 u8 j = (hwif->index * MAX_DRIVES) + i;
1120 u16 *saved_id = drive->id;
1124 1121
1125 memset(drive, 0, sizeof(*drive)); 1122 memset(drive, 0, sizeof(*drive));
1123 memset(saved_id, 0, SECTOR_SIZE);
1124 drive->id = saved_id;
1126 1125
1127 drive->media = ide_disk; 1126 drive->media = ide_disk;
1128 drive->select = (i << 4) | ATA_DEVICE_OBS; 1127 drive->select = (i << 4) | ATA_DEVICE_OBS;
1129 drive->hwif = hwif; 1128 drive->hwif = hwif;
1130 drive->ready_stat = ATA_DRDY; 1129 drive->ready_stat = ATA_DRDY;
1131 drive->bad_wstat = BAD_W_STAT; 1130 drive->bad_wstat = BAD_W_STAT;
1132 drive->special.b.recalibrate = 1; 1131 drive->special_flags = IDE_SFLAG_RECALIBRATE |
1133 drive->special.b.set_geometry = 1; 1132 IDE_SFLAG_SET_GEOMETRY;
1134 drive->name[0] = 'h'; 1133 drive->name[0] = 'h';
1135 drive->name[1] = 'd'; 1134 drive->name[1] = 'd';
1136 drive->name[2] = 'a' + j; 1135 drive->name[2] = 'a' + j;
@@ -1165,11 +1164,10 @@ static void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
1165 ide_port_init_devices_data(hwif); 1164 ide_port_init_devices_data(hwif);
1166} 1165}
1167 1166
1168static void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw) 1167static void ide_init_port_hw(ide_hwif_t *hwif, struct ide_hw *hw)
1169{ 1168{
1170 memcpy(&hwif->io_ports, &hw->io_ports, sizeof(hwif->io_ports)); 1169 memcpy(&hwif->io_ports, &hw->io_ports, sizeof(hwif->io_ports));
1171 hwif->irq = hw->irq; 1170 hwif->irq = hw->irq;
1172 hwif->chipset = hw->chipset;
1173 hwif->dev = hw->dev; 1171 hwif->dev = hw->dev;
1174 hwif->gendev.parent = hw->parent ? hw->parent : hw->dev; 1172 hwif->gendev.parent = hw->parent ? hw->parent : hw->dev;
1175 hwif->ack_intr = hw->ack_intr; 1173 hwif->ack_intr = hw->ack_intr;
@@ -1230,8 +1228,10 @@ static void ide_port_free_devices(ide_hwif_t *hwif)
1230 ide_drive_t *drive; 1228 ide_drive_t *drive;
1231 int i; 1229 int i;
1232 1230
1233 ide_port_for_each_dev(i, drive, hwif) 1231 ide_port_for_each_dev(i, drive, hwif) {
1232 kfree(drive->id);
1234 kfree(drive); 1233 kfree(drive);
1234 }
1235} 1235}
1236 1236
1237static int ide_port_alloc_devices(ide_hwif_t *hwif, int node) 1237static int ide_port_alloc_devices(ide_hwif_t *hwif, int node)
@@ -1245,6 +1245,18 @@ static int ide_port_alloc_devices(ide_hwif_t *hwif, int node)
1245 if (drive == NULL) 1245 if (drive == NULL)
1246 goto out_nomem; 1246 goto out_nomem;
1247 1247
1248 /*
1249 * In order to keep things simple we have an id
1250 * block for all drives at all times. If the device
1251 * is pre ATA or refuses ATA/ATAPI identify we
1252 * will add faked data to this.
1253 *
1254 * Also note that 0 everywhere means "can't do X"
1255 */
1256 drive->id = kzalloc_node(SECTOR_SIZE, GFP_KERNEL, node);
1257 if (drive->id == NULL)
1258 goto out_nomem;
1259
1248 hwif->devices[i] = drive; 1260 hwif->devices[i] = drive;
1249 } 1261 }
1250 return 0; 1262 return 0;
@@ -1254,7 +1266,8 @@ out_nomem:
1254 return -ENOMEM; 1266 return -ENOMEM;
1255} 1267}
1256 1268
1257struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws) 1269struct ide_host *ide_host_alloc(const struct ide_port_info *d,
1270 struct ide_hw **hws, unsigned int n_ports)
1258{ 1271{
1259 struct ide_host *host; 1272 struct ide_host *host;
1260 struct device *dev = hws[0] ? hws[0]->dev : NULL; 1273 struct device *dev = hws[0] ? hws[0]->dev : NULL;
@@ -1265,7 +1278,7 @@ struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
1265 if (host == NULL) 1278 if (host == NULL)
1266 return NULL; 1279 return NULL;
1267 1280
1268 for (i = 0; i < MAX_HOST_PORTS; i++) { 1281 for (i = 0; i < n_ports; i++) {
1269 ide_hwif_t *hwif; 1282 ide_hwif_t *hwif;
1270 int idx; 1283 int idx;
1271 1284
@@ -1285,6 +1298,7 @@ struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
1285 if (idx < 0) { 1298 if (idx < 0) {
1286 printk(KERN_ERR "%s: no free slot for interface\n", 1299 printk(KERN_ERR "%s: no free slot for interface\n",
1287 d ? d->name : "ide"); 1300 d ? d->name : "ide");
1301 ide_port_free_devices(hwif);
1288 kfree(hwif); 1302 kfree(hwif);
1289 continue; 1303 continue;
1290 } 1304 }
@@ -1341,7 +1355,7 @@ static void ide_disable_port(ide_hwif_t *hwif)
1341} 1355}
1342 1356
1343int ide_host_register(struct ide_host *host, const struct ide_port_info *d, 1357int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1344 hw_regs_t **hws) 1358 struct ide_hw **hws)
1345{ 1359{
1346 ide_hwif_t *hwif, *mate = NULL; 1360 ide_hwif_t *hwif, *mate = NULL;
1347 int i, j = 0; 1361 int i, j = 0;
@@ -1435,13 +1449,13 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1435} 1449}
1436EXPORT_SYMBOL_GPL(ide_host_register); 1450EXPORT_SYMBOL_GPL(ide_host_register);
1437 1451
1438int ide_host_add(const struct ide_port_info *d, hw_regs_t **hws, 1452int ide_host_add(const struct ide_port_info *d, struct ide_hw **hws,
1439 struct ide_host **hostp) 1453 unsigned int n_ports, struct ide_host **hostp)
1440{ 1454{
1441 struct ide_host *host; 1455 struct ide_host *host;
1442 int rc; 1456 int rc;
1443 1457
1444 host = ide_host_alloc(d, hws); 1458 host = ide_host_alloc(d, hws, n_ports);
1445 if (host == NULL) 1459 if (host == NULL)
1446 return -ENOMEM; 1460 return -ENOMEM;
1447 1461