aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2006-04-12 16:54:16 -0400
committerJeff Garzik <jeff@garzik.org>2006-04-12 16:54:16 -0400
commit875999c5539999f61a45620aae0c3e5fb1d2b035 (patch)
tree4535032a8a10f5782c0aef6a620b1a624ea9f863 /drivers/scsi
parent79072f38909e3d9883317238887460c39ddcc4cb (diff)
parent26ec634c31a11a003040e10b4d650495158632fd (diff)
Merge branch 'upstream'
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/3w-xxxx.c3
-rw-r--r--drivers/scsi/Makefile2
-rw-r--r--drivers/scsi/ahci.c57
-rw-r--r--drivers/scsi/aic7xxx/Kconfig.aic7xxx2
-rw-r--r--drivers/scsi/ata_piix.c7
-rw-r--r--drivers/scsi/hosts.c12
-rw-r--r--drivers/scsi/ibmmca.c2
-rw-r--r--drivers/scsi/ibmvscsi/rpa_vscsi.c10
-rw-r--r--drivers/scsi/lasi700.c2
-rw-r--r--drivers/scsi/libata-core.c917
-rw-r--r--drivers/scsi/libata-eh.c263
-rw-r--r--drivers/scsi/libata-scsi.c199
-rw-r--r--drivers/scsi/libata.h21
-rw-r--r--drivers/scsi/pcmcia/aha152x_stub.c112
-rw-r--r--drivers/scsi/pcmcia/fdomain_stub.c155
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.c136
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.h8
-rw-r--r--drivers/scsi/pcmcia/qlogic_stub.c127
-rw-r--r--drivers/scsi/pcmcia/sym53c500_cs.c124
-rw-r--r--drivers/scsi/pdc_adma.c7
-rw-r--r--drivers/scsi/sata_mv.c5
-rw-r--r--drivers/scsi/sata_nv.c5
-rw-r--r--drivers/scsi/sata_promise.c7
-rw-r--r--drivers/scsi/sata_qstor.c7
-rw-r--r--drivers/scsi/sata_sil.c9
-rw-r--r--drivers/scsi/sata_sil24.c250
-rw-r--r--drivers/scsi/sata_sis.c3
-rw-r--r--drivers/scsi/sata_svw.c5
-rw-r--r--drivers/scsi/sata_sx4.c9
-rw-r--r--drivers/scsi/sata_uli.c3
-rw-r--r--drivers/scsi/sata_via.c3
-rw-r--r--drivers/scsi/sata_vsc.c3
-rw-r--r--drivers/scsi/scsi_error.c4
-rw-r--r--drivers/scsi/zalon.c2
34 files changed, 1312 insertions, 1169 deletions
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index 25f678d0780b..e8e41e6eb42a 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -1508,10 +1508,12 @@ static void tw_transfer_internal(TW_Device_Extension *tw_dev, int request_id,
1508 struct scsi_cmnd *cmd = tw_dev->srb[request_id]; 1508 struct scsi_cmnd *cmd = tw_dev->srb[request_id];
1509 void *buf; 1509 void *buf;
1510 unsigned int transfer_len; 1510 unsigned int transfer_len;
1511 unsigned long flags = 0;
1511 1512
1512 if (cmd->use_sg) { 1513 if (cmd->use_sg) {
1513 struct scatterlist *sg = 1514 struct scatterlist *sg =
1514 (struct scatterlist *)cmd->request_buffer; 1515 (struct scatterlist *)cmd->request_buffer;
1516 local_irq_save(flags);
1515 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset; 1517 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
1516 transfer_len = min(sg->length, len); 1518 transfer_len = min(sg->length, len);
1517 } else { 1519 } else {
@@ -1526,6 +1528,7 @@ static void tw_transfer_internal(TW_Device_Extension *tw_dev, int request_id,
1526 1528
1527 sg = (struct scatterlist *)cmd->request_buffer; 1529 sg = (struct scatterlist *)cmd->request_buffer;
1528 kunmap_atomic(buf - sg->offset, KM_IRQ0); 1530 kunmap_atomic(buf - sg->offset, KM_IRQ0);
1531 local_irq_restore(flags);
1529 } 1532 }
1530} 1533}
1531 1534
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index e513c3158ad9..503f189dab3b 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -165,7 +165,7 @@ ncr53c8xx-flags-$(CONFIG_SCSI_ZALON) \
165CFLAGS_ncr53c8xx.o := $(ncr53c8xx-flags-y) $(ncr53c8xx-flags-m) 165CFLAGS_ncr53c8xx.o := $(ncr53c8xx-flags-y) $(ncr53c8xx-flags-m)
166zalon7xx-objs := zalon.o ncr53c8xx.o 166zalon7xx-objs := zalon.o ncr53c8xx.o
167NCR_Q720_mod-objs := NCR_Q720.o ncr53c8xx.o 167NCR_Q720_mod-objs := NCR_Q720.o ncr53c8xx.o
168libata-objs := libata-core.o libata-scsi.o libata-bmdma.o 168libata-objs := libata-core.o libata-scsi.o libata-bmdma.o libata-eh.o
169oktagon_esp_mod-objs := oktagon_esp.o oktagon_io.o 169oktagon_esp_mod-objs := oktagon_esp.o oktagon_io.o
170 170
171# Files generated that shall be removed upon make clean 171# Files generated that shall be removed upon make clean
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index ffba65656a83..1b8429cb3c96 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -48,7 +48,7 @@
48#include <asm/io.h> 48#include <asm/io.h>
49 49
50#define DRV_NAME "ahci" 50#define DRV_NAME "ahci"
51#define DRV_VERSION "1.2" 51#define DRV_VERSION "1.3"
52 52
53 53
54enum { 54enum {
@@ -207,7 +207,6 @@ static struct scsi_host_template ahci_sht = {
207 .name = DRV_NAME, 207 .name = DRV_NAME,
208 .ioctl = ata_scsi_ioctl, 208 .ioctl = ata_scsi_ioctl,
209 .queuecommand = ata_scsi_queuecmd, 209 .queuecommand = ata_scsi_queuecmd,
210 .eh_strategy_handler = ata_scsi_error,
211 .can_queue = ATA_DEF_QUEUE, 210 .can_queue = ATA_DEF_QUEUE,
212 .this_id = ATA_SHT_THIS_ID, 211 .this_id = ATA_SHT_THIS_ID,
213 .sg_tablesize = AHCI_MAX_SG, 212 .sg_tablesize = AHCI_MAX_SG,
@@ -293,6 +292,10 @@ static const struct pci_device_id ahci_pci_tbl[] = {
293 board_ahci }, /* JMicron JMB360 */ 292 board_ahci }, /* JMicron JMB360 */
294 { 0x197b, 0x2363, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 293 { 0x197b, 0x2363, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
295 board_ahci }, /* JMicron JMB363 */ 294 board_ahci }, /* JMicron JMB363 */
295 { PCI_VENDOR_ID_ATI, 0x4380, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
296 board_ahci }, /* ATI SB600 non-raid */
297 { PCI_VENDOR_ID_ATI, 0x4381, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
298 board_ahci }, /* ATI SB600 raid */
296 { } /* terminate list */ 299 { } /* terminate list */
297}; 300};
298 301
@@ -513,25 +516,7 @@ static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, u32 opts)
513 pp->cmd_slot[0].tbl_addr_hi = cpu_to_le32((pp->cmd_tbl_dma >> 16) >> 16); 516 pp->cmd_slot[0].tbl_addr_hi = cpu_to_le32((pp->cmd_tbl_dma >> 16) >> 16);
514} 517}
515 518
516static int ahci_poll_register(void __iomem *reg, u32 mask, u32 val, 519static int ahci_softreset(struct ata_port *ap, unsigned int *class)
517 unsigned long interval_msec,
518 unsigned long timeout_msec)
519{
520 unsigned long timeout;
521 u32 tmp;
522
523 timeout = jiffies + (timeout_msec * HZ) / 1000;
524 do {
525 tmp = readl(reg);
526 if ((tmp & mask) == val)
527 return 0;
528 msleep(interval_msec);
529 } while (time_before(jiffies, timeout));
530
531 return -1;
532}
533
534static int ahci_softreset(struct ata_port *ap, int verbose, unsigned int *class)
535{ 520{
536 struct ahci_host_priv *hpriv = ap->host_set->private_data; 521 struct ahci_host_priv *hpriv = ap->host_set->private_data;
537 struct ahci_port_priv *pp = ap->private_data; 522 struct ahci_port_priv *pp = ap->private_data;
@@ -540,11 +525,18 @@ static int ahci_softreset(struct ata_port *ap, int verbose, unsigned int *class)
540 const u32 cmd_fis_len = 5; /* five dwords */ 525 const u32 cmd_fis_len = 5; /* five dwords */
541 const char *reason = NULL; 526 const char *reason = NULL;
542 struct ata_taskfile tf; 527 struct ata_taskfile tf;
528 u32 tmp;
543 u8 *fis; 529 u8 *fis;
544 int rc; 530 int rc;
545 531
546 DPRINTK("ENTER\n"); 532 DPRINTK("ENTER\n");
547 533
534 if (!sata_dev_present(ap)) {
535 DPRINTK("PHY reports no device\n");
536 *class = ATA_DEV_NONE;
537 return 0;
538 }
539
548 /* prepare for SRST (AHCI-1.1 10.4.1) */ 540 /* prepare for SRST (AHCI-1.1 10.4.1) */
549 rc = ahci_stop_engine(ap); 541 rc = ahci_stop_engine(ap);
550 if (rc) { 542 if (rc) {
@@ -555,8 +547,6 @@ static int ahci_softreset(struct ata_port *ap, int verbose, unsigned int *class)
555 /* check BUSY/DRQ, perform Command List Override if necessary */ 547 /* check BUSY/DRQ, perform Command List Override if necessary */
556 ahci_tf_read(ap, &tf); 548 ahci_tf_read(ap, &tf);
557 if (tf.command & (ATA_BUSY | ATA_DRQ)) { 549 if (tf.command & (ATA_BUSY | ATA_DRQ)) {
558 u32 tmp;
559
560 if (!(hpriv->cap & HOST_CAP_CLO)) { 550 if (!(hpriv->cap & HOST_CAP_CLO)) {
561 rc = -EIO; 551 rc = -EIO;
562 reason = "port busy but no CLO"; 552 reason = "port busy but no CLO";
@@ -566,10 +556,10 @@ static int ahci_softreset(struct ata_port *ap, int verbose, unsigned int *class)
566 tmp = readl(port_mmio + PORT_CMD); 556 tmp = readl(port_mmio + PORT_CMD);
567 tmp |= PORT_CMD_CLO; 557 tmp |= PORT_CMD_CLO;
568 writel(tmp, port_mmio + PORT_CMD); 558 writel(tmp, port_mmio + PORT_CMD);
569 readl(port_mmio + PORT_CMD); /* flush */
570 559
571 if (ahci_poll_register(port_mmio + PORT_CMD, PORT_CMD_CLO, 0x0, 560 tmp = ata_wait_register(port_mmio + PORT_CMD,
572 1, 500)) { 561 PORT_CMD_CLO, PORT_CMD_CLO, 1, 500);
562 if (tmp & PORT_CMD_CLO) {
573 rc = -EIO; 563 rc = -EIO;
574 reason = "CLO failed"; 564 reason = "CLO failed";
575 goto fail_restart; 565 goto fail_restart;
@@ -590,9 +580,9 @@ static int ahci_softreset(struct ata_port *ap, int verbose, unsigned int *class)
590 fis[1] &= ~(1 << 7); /* turn off Command FIS bit */ 580 fis[1] &= ~(1 << 7); /* turn off Command FIS bit */
591 581
592 writel(1, port_mmio + PORT_CMD_ISSUE); 582 writel(1, port_mmio + PORT_CMD_ISSUE);
593 readl(port_mmio + PORT_CMD_ISSUE); /* flush */
594 583
595 if (ahci_poll_register(port_mmio + PORT_CMD_ISSUE, 0x1, 0x0, 1, 500)) { 584 tmp = ata_wait_register(port_mmio + PORT_CMD_ISSUE, 0x1, 0x1, 1, 500);
585 if (tmp & 0x1) {
596 rc = -EIO; 586 rc = -EIO;
597 reason = "1st FIS failed"; 587 reason = "1st FIS failed";
598 goto fail; 588 goto fail;
@@ -637,22 +627,19 @@ static int ahci_softreset(struct ata_port *ap, int verbose, unsigned int *class)
637 fail_restart: 627 fail_restart:
638 ahci_start_engine(ap); 628 ahci_start_engine(ap);
639 fail: 629 fail:
640 if (verbose) 630 printk(KERN_ERR "ata%u: softreset failed (%s)\n",
641 printk(KERN_ERR "ata%u: softreset failed (%s)\n", 631 ap->id, reason);
642 ap->id, reason);
643 else
644 DPRINTK("EXIT, rc=%d reason=\"%s\"\n", rc, reason);
645 return rc; 632 return rc;
646} 633}
647 634
648static int ahci_hardreset(struct ata_port *ap, int verbose, unsigned int *class) 635static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
649{ 636{
650 int rc; 637 int rc;
651 638
652 DPRINTK("ENTER\n"); 639 DPRINTK("ENTER\n");
653 640
654 ahci_stop_engine(ap); 641 ahci_stop_engine(ap);
655 rc = sata_std_hardreset(ap, verbose, class); 642 rc = sata_std_hardreset(ap, class);
656 ahci_start_engine(ap); 643 ahci_start_engine(ap);
657 644
658 if (rc == 0) 645 if (rc == 0)
diff --git a/drivers/scsi/aic7xxx/Kconfig.aic7xxx b/drivers/scsi/aic7xxx/Kconfig.aic7xxx
index 6c2c395554ff..5517da5855f0 100644
--- a/drivers/scsi/aic7xxx/Kconfig.aic7xxx
+++ b/drivers/scsi/aic7xxx/Kconfig.aic7xxx
@@ -86,7 +86,7 @@ config AIC7XXX_DEBUG_MASK
86 default "0" 86 default "0"
87 help 87 help
88 Bit mask of debug options that is only valid if the 88 Bit mask of debug options that is only valid if the
89 CONFIG_AIC7XXX_DEBUG_ENBLE option is enabled. The bits in this mask 89 CONFIG_AIC7XXX_DEBUG_ENABLE option is enabled. The bits in this mask
90 are defined in the drivers/scsi/aic7xxx/aic7xxx.h - search for the 90 are defined in the drivers/scsi/aic7xxx/aic7xxx.h - search for the
91 variable ahc_debug in that file to find them. 91 variable ahc_debug in that file to find them.
92 92
diff --git a/drivers/scsi/ata_piix.c b/drivers/scsi/ata_piix.c
index 2d5be84d8bd4..62dabf74188e 100644
--- a/drivers/scsi/ata_piix.c
+++ b/drivers/scsi/ata_piix.c
@@ -93,7 +93,7 @@
93#include <linux/libata.h> 93#include <linux/libata.h>
94 94
95#define DRV_NAME "ata_piix" 95#define DRV_NAME "ata_piix"
96#define DRV_VERSION "1.05" 96#define DRV_VERSION "1.10"
97 97
98enum { 98enum {
99 PIIX_IOCFG = 0x54, /* IDE I/O configuration register */ 99 PIIX_IOCFG = 0x54, /* IDE I/O configuration register */
@@ -209,7 +209,6 @@ static struct scsi_host_template piix_sht = {
209 .name = DRV_NAME, 209 .name = DRV_NAME,
210 .ioctl = ata_scsi_ioctl, 210 .ioctl = ata_scsi_ioctl,
211 .queuecommand = ata_scsi_queuecmd, 211 .queuecommand = ata_scsi_queuecmd,
212 .eh_strategy_handler = ata_scsi_error,
213 .can_queue = ATA_DEF_QUEUE, 212 .can_queue = ATA_DEF_QUEUE,
214 .this_id = ATA_SHT_THIS_ID, 213 .this_id = ATA_SHT_THIS_ID,
215 .sg_tablesize = LIBATA_MAX_PRD, 214 .sg_tablesize = LIBATA_MAX_PRD,
@@ -301,7 +300,7 @@ static struct piix_map_db ich6_map_db = {
301 .mask = 0x3, 300 .mask = 0x3,
302 .map = { 301 .map = {
303 /* PM PS SM SS MAP */ 302 /* PM PS SM SS MAP */
304 { P0, P1, P2, P3 }, /* 00b */ 303 { P0, P2, P1, P3 }, /* 00b */
305 { IDE, IDE, P1, P3 }, /* 01b */ 304 { IDE, IDE, P1, P3 }, /* 01b */
306 { P0, P2, IDE, IDE }, /* 10b */ 305 { P0, P2, IDE, IDE }, /* 10b */
307 { RV, RV, RV, RV }, 306 { RV, RV, RV, RV },
@@ -312,7 +311,7 @@ static struct piix_map_db ich6m_map_db = {
312 .mask = 0x3, 311 .mask = 0x3,
313 .map = { 312 .map = {
314 /* PM PS SM SS MAP */ 313 /* PM PS SM SS MAP */
315 { P0, P1, P2, P3 }, /* 00b */ 314 { P0, P2, RV, RV }, /* 00b */
316 { RV, RV, RV, RV }, 315 { RV, RV, RV, RV },
317 { P0, P2, IDE, IDE }, /* 10b */ 316 { P0, P2, IDE, IDE }, /* 10b */
318 { RV, RV, RV, RV }, 317 { RV, RV, RV, RV },
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index ef57f253031c..dfcb96f3e60c 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -294,18 +294,6 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
294 if (sht->unchecked_isa_dma && privsize) 294 if (sht->unchecked_isa_dma && privsize)
295 gfp_mask |= __GFP_DMA; 295 gfp_mask |= __GFP_DMA;
296 296
297 /* Check to see if this host has any error handling facilities */
298 if (!sht->eh_strategy_handler && !sht->eh_abort_handler &&
299 !sht->eh_device_reset_handler && !sht->eh_bus_reset_handler &&
300 !sht->eh_host_reset_handler) {
301 printk(KERN_ERR "ERROR: SCSI host `%s' has no error handling\n"
302 "ERROR: This is not a safe way to run your "
303 "SCSI host\n"
304 "ERROR: The error handling must be added to "
305 "this driver\n", sht->proc_name);
306 dump_stack();
307 }
308
309 shost = kzalloc(sizeof(struct Scsi_Host) + privsize, gfp_mask); 297 shost = kzalloc(sizeof(struct Scsi_Host) + privsize, gfp_mask);
310 if (!shost) 298 if (!shost)
311 return NULL; 299 return NULL;
diff --git a/drivers/scsi/ibmmca.c b/drivers/scsi/ibmmca.c
index 3a8462e8d063..24eb59e143a9 100644
--- a/drivers/scsi/ibmmca.c
+++ b/drivers/scsi/ibmmca.c
@@ -2488,7 +2488,7 @@ static int option_setup(char *str)
2488 } 2488 }
2489 ints[0] = i - 1; 2489 ints[0] = i - 1;
2490 internal_ibmmca_scsi_setup(cur, ints); 2490 internal_ibmmca_scsi_setup(cur, ints);
2491 return 0; 2491 return 1;
2492} 2492}
2493 2493
2494__setup("ibmmcascsi=", option_setup); 2494__setup("ibmmcascsi=", option_setup);
diff --git a/drivers/scsi/ibmvscsi/rpa_vscsi.c b/drivers/scsi/ibmvscsi/rpa_vscsi.c
index f47dd87c05e7..892e8ed63091 100644
--- a/drivers/scsi/ibmvscsi/rpa_vscsi.c
+++ b/drivers/scsi/ibmvscsi/rpa_vscsi.c
@@ -80,7 +80,7 @@ void ibmvscsi_release_crq_queue(struct crq_queue *queue,
80 tasklet_kill(&hostdata->srp_task); 80 tasklet_kill(&hostdata->srp_task);
81 do { 81 do {
82 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); 82 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
83 } while ((rc == H_Busy) || (H_isLongBusy(rc))); 83 } while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
84 dma_unmap_single(hostdata->dev, 84 dma_unmap_single(hostdata->dev,
85 queue->msg_token, 85 queue->msg_token,
86 queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL); 86 queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL);
@@ -230,7 +230,7 @@ int ibmvscsi_init_crq_queue(struct crq_queue *queue,
230 rc = plpar_hcall_norets(H_REG_CRQ, 230 rc = plpar_hcall_norets(H_REG_CRQ,
231 vdev->unit_address, 231 vdev->unit_address,
232 queue->msg_token, PAGE_SIZE); 232 queue->msg_token, PAGE_SIZE);
233 if (rc == H_Resource) 233 if (rc == H_RESOURCE)
234 /* maybe kexecing and resource is busy. try a reset */ 234 /* maybe kexecing and resource is busy. try a reset */
235 rc = ibmvscsi_reset_crq_queue(queue, 235 rc = ibmvscsi_reset_crq_queue(queue,
236 hostdata); 236 hostdata);
@@ -269,7 +269,7 @@ int ibmvscsi_init_crq_queue(struct crq_queue *queue,
269 req_irq_failed: 269 req_irq_failed:
270 do { 270 do {
271 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); 271 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
272 } while ((rc == H_Busy) || (H_isLongBusy(rc))); 272 } while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
273 reg_crq_failed: 273 reg_crq_failed:
274 dma_unmap_single(hostdata->dev, 274 dma_unmap_single(hostdata->dev,
275 queue->msg_token, 275 queue->msg_token,
@@ -295,7 +295,7 @@ int ibmvscsi_reenable_crq_queue(struct crq_queue *queue,
295 /* Re-enable the CRQ */ 295 /* Re-enable the CRQ */
296 do { 296 do {
297 rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address); 297 rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address);
298 } while ((rc == H_InProgress) || (rc == H_Busy) || (H_isLongBusy(rc))); 298 } while ((rc == H_IN_PROGRESS) || (rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
299 299
300 if (rc) 300 if (rc)
301 printk(KERN_ERR "ibmvscsi: Error %d enabling adapter\n", rc); 301 printk(KERN_ERR "ibmvscsi: Error %d enabling adapter\n", rc);
@@ -317,7 +317,7 @@ int ibmvscsi_reset_crq_queue(struct crq_queue *queue,
317 /* Close the CRQ */ 317 /* Close the CRQ */
318 do { 318 do {
319 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); 319 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
320 } while ((rc == H_Busy) || (H_isLongBusy(rc))); 320 } while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
321 321
322 /* Clean out the queue */ 322 /* Clean out the queue */
323 memset(queue->msgs, 0x00, PAGE_SIZE); 323 memset(queue->msgs, 0x00, PAGE_SIZE);
diff --git a/drivers/scsi/lasi700.c b/drivers/scsi/lasi700.c
index 459a4daebece..eb7bd310cc82 100644
--- a/drivers/scsi/lasi700.c
+++ b/drivers/scsi/lasi700.c
@@ -112,7 +112,7 @@ lasi700_probe(struct parisc_device *dev)
112 112
113 hostdata->dev = &dev->dev; 113 hostdata->dev = &dev->dev;
114 dma_set_mask(&dev->dev, DMA_32BIT_MASK); 114 dma_set_mask(&dev->dev, DMA_32BIT_MASK);
115 hostdata->base = ioremap(base, 0x100); 115 hostdata->base = ioremap_nocache(base, 0x100);
116 hostdata->differential = 0; 116 hostdata->differential = 0;
117 117
118 if (dev->id.sversion == LASI_700_SVERSION) { 118 if (dev->id.sversion == LASI_700_SVERSION) {
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 21b0ed583b8a..509178c3700c 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -65,7 +65,6 @@ static unsigned int ata_dev_init_params(struct ata_port *ap,
65 struct ata_device *dev, 65 struct ata_device *dev,
66 u16 heads, 66 u16 heads,
67 u16 sectors); 67 u16 sectors);
68static void ata_set_mode(struct ata_port *ap);
69static unsigned int ata_dev_set_xfermode(struct ata_port *ap, 68static unsigned int ata_dev_set_xfermode(struct ata_port *ap,
70 struct ata_device *dev); 69 struct ata_device *dev);
71static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev); 70static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev);
@@ -77,6 +76,10 @@ int atapi_enabled = 1;
77module_param(atapi_enabled, int, 0444); 76module_param(atapi_enabled, int, 0444);
78MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)"); 77MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)");
79 78
79int atapi_dmadir = 0;
80module_param(atapi_dmadir, int, 0444);
81MODULE_PARM_DESC(atapi_dmadir, "Enable ATAPI DMADIR bridge support (0=off, 1=on)");
82
80int libata_fua = 0; 83int libata_fua = 0;
81module_param_named(fua, libata_fua, int, 0444); 84module_param_named(fua, libata_fua, int, 0444);
82MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)"); 85MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)");
@@ -278,7 +281,7 @@ static void ata_unpack_xfermask(unsigned int xfer_mask,
278} 281}
279 282
280static const struct ata_xfer_ent { 283static const struct ata_xfer_ent {
281 unsigned int shift, bits; 284 int shift, bits;
282 u8 base; 285 u8 base;
283} ata_xfer_tbl[] = { 286} ata_xfer_tbl[] = {
284 { ATA_SHIFT_PIO, ATA_BITS_PIO, XFER_PIO_0 }, 287 { ATA_SHIFT_PIO, ATA_BITS_PIO, XFER_PIO_0 },
@@ -397,9 +400,21 @@ static const char *ata_mode_string(unsigned int xfer_mask)
397 return "<n/a>"; 400 return "<n/a>";
398} 401}
399 402
400static void ata_dev_disable(struct ata_port *ap, struct ata_device *dev) 403static const char *sata_spd_string(unsigned int spd)
401{ 404{
402 if (ata_dev_present(dev)) { 405 static const char * const spd_str[] = {
406 "1.5 Gbps",
407 "3.0 Gbps",
408 };
409
410 if (spd == 0 || (spd - 1) >= ARRAY_SIZE(spd_str))
411 return "<unknown>";
412 return spd_str[spd - 1];
413}
414
415void ata_dev_disable(struct ata_port *ap, struct ata_device *dev)
416{
417 if (ata_dev_enabled(dev)) {
403 printk(KERN_WARNING "ata%u: dev %u disabled\n", 418 printk(KERN_WARNING "ata%u: dev %u disabled\n",
404 ap->id, dev->devno); 419 ap->id, dev->devno);
405 dev->class++; 420 dev->class++;
@@ -949,6 +964,7 @@ void ata_qc_complete_internal(struct ata_queued_cmd *qc)
949 * @ap: Port to which the command is sent 964 * @ap: Port to which the command is sent
950 * @dev: Device to which the command is sent 965 * @dev: Device to which the command is sent
951 * @tf: Taskfile registers for the command and the result 966 * @tf: Taskfile registers for the command and the result
967 * @cdb: CDB for packet command
952 * @dma_dir: Data tranfer direction of the command 968 * @dma_dir: Data tranfer direction of the command
953 * @buf: Data buffer of the command 969 * @buf: Data buffer of the command
954 * @buflen: Length of data buffer 970 * @buflen: Length of data buffer
@@ -963,10 +979,9 @@ void ata_qc_complete_internal(struct ata_queued_cmd *qc)
963 * None. Should be called with kernel context, might sleep. 979 * None. Should be called with kernel context, might sleep.
964 */ 980 */
965 981
966static unsigned 982unsigned ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
967ata_exec_internal(struct ata_port *ap, struct ata_device *dev, 983 struct ata_taskfile *tf, const u8 *cdb,
968 struct ata_taskfile *tf, 984 int dma_dir, void *buf, unsigned int buflen)
969 int dma_dir, void *buf, unsigned int buflen)
970{ 985{
971 u8 command = tf->command; 986 u8 command = tf->command;
972 struct ata_queued_cmd *qc; 987 struct ata_queued_cmd *qc;
@@ -980,6 +995,8 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
980 BUG_ON(qc == NULL); 995 BUG_ON(qc == NULL);
981 996
982 qc->tf = *tf; 997 qc->tf = *tf;
998 if (cdb)
999 memcpy(qc->cdb, cdb, ATAPI_CDB_LEN);
983 qc->dma_dir = dma_dir; 1000 qc->dma_dir = dma_dir;
984 if (dma_dir != DMA_NONE) { 1001 if (dma_dir != DMA_NONE) {
985 ata_sg_init_one(qc, buf, buflen); 1002 ata_sg_init_one(qc, buf, buflen);
@@ -989,9 +1006,7 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
989 qc->private_data = &wait; 1006 qc->private_data = &wait;
990 qc->complete_fn = ata_qc_complete_internal; 1007 qc->complete_fn = ata_qc_complete_internal;
991 1008
992 qc->err_mask = ata_qc_issue(qc); 1009 ata_qc_issue(qc);
993 if (qc->err_mask)
994 ata_qc_complete(qc);
995 1010
996 spin_unlock_irqrestore(&ap->host_set->lock, flags); 1011 spin_unlock_irqrestore(&ap->host_set->lock, flags);
997 1012
@@ -1032,7 +1047,7 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
1032 * 1047 *
1033 * Kill the following code as soon as those drivers are fixed. 1048 * Kill the following code as soon as those drivers are fixed.
1034 */ 1049 */
1035 if (ap->flags & ATA_FLAG_PORT_DISABLED) { 1050 if (ap->flags & ATA_FLAG_DISABLED) {
1036 err_mask |= AC_ERR_SYSTEM; 1051 err_mask |= AC_ERR_SYSTEM;
1037 ata_port_probe(ap); 1052 ata_port_probe(ap);
1038 } 1053 }
@@ -1131,7 +1146,7 @@ static int ata_dev_read_id(struct ata_port *ap, struct ata_device *dev,
1131 1146
1132 tf.protocol = ATA_PROT_PIO; 1147 tf.protocol = ATA_PROT_PIO;
1133 1148
1134 err_mask = ata_exec_internal(ap, dev, &tf, DMA_FROM_DEVICE, 1149 err_mask = ata_exec_internal(ap, dev, &tf, NULL, DMA_FROM_DEVICE,
1135 id, sizeof(id[0]) * ATA_ID_WORDS); 1150 id, sizeof(id[0]) * ATA_ID_WORDS);
1136 if (err_mask) { 1151 if (err_mask) {
1137 rc = -EIO; 1152 rc = -EIO;
@@ -1212,7 +1227,7 @@ static int ata_dev_configure(struct ata_port *ap, struct ata_device *dev,
1212 unsigned int xfer_mask; 1227 unsigned int xfer_mask;
1213 int i, rc; 1228 int i, rc;
1214 1229
1215 if (!ata_dev_present(dev)) { 1230 if (!ata_dev_enabled(dev)) {
1216 DPRINTK("ENTER/EXIT (host %u, dev %u) -- nodev\n", 1231 DPRINTK("ENTER/EXIT (host %u, dev %u) -- nodev\n",
1217 ap->id, dev->devno); 1232 ap->id, dev->devno);
1218 return 0; 1233 return 0;
@@ -1228,7 +1243,7 @@ static int ata_dev_configure(struct ata_port *ap, struct ata_device *dev,
1228 id[84], id[85], id[86], id[87], id[88]); 1243 id[84], id[85], id[86], id[87], id[88]);
1229 1244
1230 /* initialize to-be-configured parameters */ 1245 /* initialize to-be-configured parameters */
1231 dev->flags = 0; 1246 dev->flags &= ~ATA_DFLAG_CFG_MASK;
1232 dev->max_sectors = 0; 1247 dev->max_sectors = 0;
1233 dev->cdb_len = 0; 1248 dev->cdb_len = 0;
1234 dev->n_sectors = 0; 1249 dev->n_sectors = 0;
@@ -1351,16 +1366,24 @@ err_out_nosup:
1351 * PCI/etc. bus probe sem. 1366 * PCI/etc. bus probe sem.
1352 * 1367 *
1353 * RETURNS: 1368 * RETURNS:
1354 * Zero on success, non-zero on error. 1369 * Zero on success, negative errno otherwise.
1355 */ 1370 */
1356 1371
1357static int ata_bus_probe(struct ata_port *ap) 1372static int ata_bus_probe(struct ata_port *ap)
1358{ 1373{
1359 unsigned int classes[ATA_MAX_DEVICES]; 1374 unsigned int classes[ATA_MAX_DEVICES];
1360 unsigned int i, rc, found = 0; 1375 int tries[ATA_MAX_DEVICES];
1376 int i, rc, down_xfermask;
1377 struct ata_device *dev;
1361 1378
1362 ata_port_probe(ap); 1379 ata_port_probe(ap);
1363 1380
1381 for (i = 0; i < ATA_MAX_DEVICES; i++)
1382 tries[i] = ATA_PROBE_MAX_TRIES;
1383
1384 retry:
1385 down_xfermask = 0;
1386
1364 /* reset and determine device classes */ 1387 /* reset and determine device classes */
1365 for (i = 0; i < ATA_MAX_DEVICES; i++) 1388 for (i = 0; i < ATA_MAX_DEVICES; i++)
1366 classes[i] = ATA_DEV_UNKNOWN; 1389 classes[i] = ATA_DEV_UNKNOWN;
@@ -1374,7 +1397,7 @@ static int ata_bus_probe(struct ata_port *ap)
1374 } else { 1397 } else {
1375 ap->ops->phy_reset(ap); 1398 ap->ops->phy_reset(ap);
1376 1399
1377 if (!(ap->flags & ATA_FLAG_PORT_DISABLED)) 1400 if (!(ap->flags & ATA_FLAG_DISABLED))
1378 for (i = 0; i < ATA_MAX_DEVICES; i++) 1401 for (i = 0; i < ATA_MAX_DEVICES; i++)
1379 classes[i] = ap->device[i].class; 1402 classes[i] = ap->device[i].class;
1380 1403
@@ -1387,43 +1410,76 @@ static int ata_bus_probe(struct ata_port *ap)
1387 1410
1388 /* read IDENTIFY page and configure devices */ 1411 /* read IDENTIFY page and configure devices */
1389 for (i = 0; i < ATA_MAX_DEVICES; i++) { 1412 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1390 struct ata_device *dev = &ap->device[i]; 1413 dev = &ap->device[i];
1391 1414
1392 dev->class = classes[i]; 1415 if (tries[i])
1416 dev->class = classes[i];
1393 1417
1394 if (!ata_dev_present(dev)) 1418 if (!ata_dev_enabled(dev))
1395 continue; 1419 continue;
1396 1420
1397 WARN_ON(dev->id != NULL); 1421 kfree(dev->id);
1398 if (ata_dev_read_id(ap, dev, &dev->class, 1, &dev->id)) { 1422 dev->id = NULL;
1399 dev->class = ATA_DEV_NONE; 1423 rc = ata_dev_read_id(ap, dev, &dev->class, 1, &dev->id);
1400 continue; 1424 if (rc)
1401 } 1425 goto fail;
1402 1426
1403 if (ata_dev_configure(ap, dev, 1)) { 1427 rc = ata_dev_configure(ap, dev, 1);
1404 ata_dev_disable(ap, dev); 1428 if (rc)
1405 continue; 1429 goto fail;
1406 } 1430 }
1407 1431
1408 found = 1; 1432 /* configure transfer mode */
1433 if (ap->ops->set_mode) {
1434 /* FIXME: make ->set_mode handle no device case and
1435 * return error code and failing device on failure as
1436 * ata_set_mode() does.
1437 */
1438 for (i = 0; i < ATA_MAX_DEVICES; i++)
1439 if (ata_dev_enabled(&ap->device[i])) {
1440 ap->ops->set_mode(ap);
1441 break;
1442 }
1443 rc = 0;
1444 } else
1445 rc = ata_set_mode(ap, &dev);
1446
1447 if (rc) {
1448 down_xfermask = 1;
1449 goto fail;
1409 } 1450 }
1410 1451
1411 if (!found) 1452 for (i = 0; i < ATA_MAX_DEVICES; i++)
1412 goto err_out_disable; 1453 if (ata_dev_enabled(&ap->device[i]))
1454 return 0;
1413 1455
1414 if (ap->ops->set_mode) 1456 /* no device present, disable port */
1415 ap->ops->set_mode(ap); 1457 ata_port_disable(ap);
1416 else 1458 ap->ops->port_disable(ap);
1417 ata_set_mode(ap); 1459 return -ENODEV;
1418 1460
1419 if (ap->flags & ATA_FLAG_PORT_DISABLED) 1461 fail:
1420 goto err_out_disable; 1462 switch (rc) {
1463 case -EINVAL:
1464 case -ENODEV:
1465 tries[dev->devno] = 0;
1466 break;
1467 case -EIO:
1468 ata_down_sata_spd_limit(ap);
1469 /* fall through */
1470 default:
1471 tries[dev->devno]--;
1472 if (down_xfermask &&
1473 ata_down_xfermask_limit(ap, dev, tries[dev->devno] == 1))
1474 tries[dev->devno] = 0;
1475 }
1421 1476
1422 return 0; 1477 if (!tries[dev->devno]) {
1478 ata_down_xfermask_limit(ap, dev, 1);
1479 ata_dev_disable(ap, dev);
1480 }
1423 1481
1424err_out_disable: 1482 goto retry;
1425 ap->ops->port_disable(ap);
1426 return -1;
1427} 1483}
1428 1484
1429/** 1485/**
@@ -1439,7 +1495,7 @@ err_out_disable:
1439 1495
1440void ata_port_probe(struct ata_port *ap) 1496void ata_port_probe(struct ata_port *ap)
1441{ 1497{
1442 ap->flags &= ~ATA_FLAG_PORT_DISABLED; 1498 ap->flags &= ~ATA_FLAG_DISABLED;
1443} 1499}
1444 1500
1445/** 1501/**
@@ -1453,27 +1509,23 @@ void ata_port_probe(struct ata_port *ap)
1453 */ 1509 */
1454static void sata_print_link_status(struct ata_port *ap) 1510static void sata_print_link_status(struct ata_port *ap)
1455{ 1511{
1456 u32 sstatus, tmp; 1512 u32 sstatus, scontrol, tmp;
1457 const char *speed;
1458 1513
1459 if (!ap->ops->scr_read) 1514 if (!ap->ops->scr_read)
1460 return; 1515 return;
1461 1516
1462 sstatus = scr_read(ap, SCR_STATUS); 1517 sstatus = scr_read(ap, SCR_STATUS);
1518 scontrol = scr_read(ap, SCR_CONTROL);
1463 1519
1464 if (sata_dev_present(ap)) { 1520 if (sata_dev_present(ap)) {
1465 tmp = (sstatus >> 4) & 0xf; 1521 tmp = (sstatus >> 4) & 0xf;
1466 if (tmp & (1 << 0)) 1522 printk(KERN_INFO
1467 speed = "1.5"; 1523 "ata%u: SATA link up %s (SStatus %X SControl %X)\n",
1468 else if (tmp & (1 << 1)) 1524 ap->id, sata_spd_string(tmp), sstatus, scontrol);
1469 speed = "3.0";
1470 else
1471 speed = "<unknown>";
1472 printk(KERN_INFO "ata%u: SATA link up %s Gbps (SStatus %X)\n",
1473 ap->id, speed, sstatus);
1474 } else { 1525 } else {
1475 printk(KERN_INFO "ata%u: SATA link down (SStatus %X)\n", 1526 printk(KERN_INFO
1476 ap->id, sstatus); 1527 "ata%u: SATA link down (SStatus %X SControl %X)\n",
1528 ap->id, sstatus, scontrol);
1477 } 1529 }
1478} 1530}
1479 1531
@@ -1520,7 +1572,7 @@ void __sata_phy_reset(struct ata_port *ap)
1520 else 1572 else
1521 ata_port_disable(ap); 1573 ata_port_disable(ap);
1522 1574
1523 if (ap->flags & ATA_FLAG_PORT_DISABLED) 1575 if (ap->flags & ATA_FLAG_DISABLED)
1524 return; 1576 return;
1525 1577
1526 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { 1578 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) {
@@ -1545,7 +1597,7 @@ void __sata_phy_reset(struct ata_port *ap)
1545void sata_phy_reset(struct ata_port *ap) 1597void sata_phy_reset(struct ata_port *ap)
1546{ 1598{
1547 __sata_phy_reset(ap); 1599 __sata_phy_reset(ap);
1548 if (ap->flags & ATA_FLAG_PORT_DISABLED) 1600 if (ap->flags & ATA_FLAG_DISABLED)
1549 return; 1601 return;
1550 ata_bus_reset(ap); 1602 ata_bus_reset(ap);
1551} 1603}
@@ -1562,7 +1614,7 @@ void sata_phy_reset(struct ata_port *ap)
1562struct ata_device *ata_dev_pair(struct ata_port *ap, struct ata_device *adev) 1614struct ata_device *ata_dev_pair(struct ata_port *ap, struct ata_device *adev)
1563{ 1615{
1564 struct ata_device *pair = &ap->device[1 - adev->devno]; 1616 struct ata_device *pair = &ap->device[1 - adev->devno];
1565 if (!ata_dev_present(pair)) 1617 if (!ata_dev_enabled(pair))
1566 return NULL; 1618 return NULL;
1567 return pair; 1619 return pair;
1568} 1620}
@@ -1584,7 +1636,121 @@ void ata_port_disable(struct ata_port *ap)
1584{ 1636{
1585 ap->device[0].class = ATA_DEV_NONE; 1637 ap->device[0].class = ATA_DEV_NONE;
1586 ap->device[1].class = ATA_DEV_NONE; 1638 ap->device[1].class = ATA_DEV_NONE;
1587 ap->flags |= ATA_FLAG_PORT_DISABLED; 1639 ap->flags |= ATA_FLAG_DISABLED;
1640}
1641
1642/**
1643 * ata_down_sata_spd_limit - adjust SATA spd limit downward
1644 * @ap: Port to adjust SATA spd limit for
1645 *
1646 * Adjust SATA spd limit of @ap downward. Note that this
1647 * function only adjusts the limit. The change must be applied
1648 * using ata_set_sata_spd().
1649 *
1650 * LOCKING:
1651 * Inherited from caller.
1652 *
1653 * RETURNS:
1654 * 0 on success, negative errno on failure
1655 */
1656int ata_down_sata_spd_limit(struct ata_port *ap)
1657{
1658 u32 spd, mask;
1659 int highbit;
1660
1661 if (ap->cbl != ATA_CBL_SATA || !ap->ops->scr_read)
1662 return -EOPNOTSUPP;
1663
1664 mask = ap->sata_spd_limit;
1665 if (mask <= 1)
1666 return -EINVAL;
1667 highbit = fls(mask) - 1;
1668 mask &= ~(1 << highbit);
1669
1670 spd = (scr_read(ap, SCR_STATUS) >> 4) & 0xf;
1671 if (spd <= 1)
1672 return -EINVAL;
1673 spd--;
1674 mask &= (1 << spd) - 1;
1675 if (!mask)
1676 return -EINVAL;
1677
1678 ap->sata_spd_limit = mask;
1679
1680 printk(KERN_WARNING "ata%u: limiting SATA link speed to %s\n",
1681 ap->id, sata_spd_string(fls(mask)));
1682
1683 return 0;
1684}
1685
1686static int __ata_set_sata_spd_needed(struct ata_port *ap, u32 *scontrol)
1687{
1688 u32 spd, limit;
1689
1690 if (ap->sata_spd_limit == UINT_MAX)
1691 limit = 0;
1692 else
1693 limit = fls(ap->sata_spd_limit);
1694
1695 spd = (*scontrol >> 4) & 0xf;
1696 *scontrol = (*scontrol & ~0xf0) | ((limit & 0xf) << 4);
1697
1698 return spd != limit;
1699}
1700
1701/**
1702 * ata_set_sata_spd_needed - is SATA spd configuration needed
1703 * @ap: Port in question
1704 *
1705 * Test whether the spd limit in SControl matches
1706 * @ap->sata_spd_limit. This function is used to determine
1707 * whether hardreset is necessary to apply SATA spd
1708 * configuration.
1709 *
1710 * LOCKING:
1711 * Inherited from caller.
1712 *
1713 * RETURNS:
1714 * 1 if SATA spd configuration is needed, 0 otherwise.
1715 */
1716int ata_set_sata_spd_needed(struct ata_port *ap)
1717{
1718 u32 scontrol;
1719
1720 if (ap->cbl != ATA_CBL_SATA || !ap->ops->scr_read)
1721 return 0;
1722
1723 scontrol = scr_read(ap, SCR_CONTROL);
1724
1725 return __ata_set_sata_spd_needed(ap, &scontrol);
1726}
1727
1728/**
1729 * ata_set_sata_spd - set SATA spd according to spd limit
1730 * @ap: Port to set SATA spd for
1731 *
1732 * Set SATA spd of @ap according to sata_spd_limit.
1733 *
1734 * LOCKING:
1735 * Inherited from caller.
1736 *
1737 * RETURNS:
1738 * 0 if spd doesn't need to be changed, 1 if spd has been
1739 * changed. -EOPNOTSUPP if SCR registers are inaccessible.
1740 */
1741int ata_set_sata_spd(struct ata_port *ap)
1742{
1743 u32 scontrol;
1744
1745 if (ap->cbl != ATA_CBL_SATA || !ap->ops->scr_read)
1746 return -EOPNOTSUPP;
1747
1748 scontrol = scr_read(ap, SCR_CONTROL);
1749 if (!__ata_set_sata_spd_needed(ap, &scontrol))
1750 return 0;
1751
1752 scr_write(ap, SCR_CONTROL, scontrol);
1753 return 1;
1588} 1754}
1589 1755
1590/* 1756/*
@@ -1735,11 +1901,62 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
1735 return 0; 1901 return 0;
1736} 1902}
1737 1903
1904/**
1905 * ata_down_xfermask_limit - adjust dev xfer masks downward
1906 * @ap: Port associated with device @dev
1907 * @dev: Device to adjust xfer masks
1908 * @force_pio0: Force PIO0
1909 *
1910 * Adjust xfer masks of @dev downward. Note that this function
1911 * does not apply the change. Invoking ata_set_mode() afterwards
1912 * will apply the limit.
1913 *
1914 * LOCKING:
1915 * Inherited from caller.
1916 *
1917 * RETURNS:
1918 * 0 on success, negative errno on failure
1919 */
1920int ata_down_xfermask_limit(struct ata_port *ap, struct ata_device *dev,
1921 int force_pio0)
1922{
1923 unsigned long xfer_mask;
1924 int highbit;
1925
1926 xfer_mask = ata_pack_xfermask(dev->pio_mask, dev->mwdma_mask,
1927 dev->udma_mask);
1928
1929 if (!xfer_mask)
1930 goto fail;
1931 /* don't gear down to MWDMA from UDMA, go directly to PIO */
1932 if (xfer_mask & ATA_MASK_UDMA)
1933 xfer_mask &= ~ATA_MASK_MWDMA;
1934
1935 highbit = fls(xfer_mask) - 1;
1936 xfer_mask &= ~(1 << highbit);
1937 if (force_pio0)
1938 xfer_mask &= 1 << ATA_SHIFT_PIO;
1939 if (!xfer_mask)
1940 goto fail;
1941
1942 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask,
1943 &dev->udma_mask);
1944
1945 printk(KERN_WARNING "ata%u: dev %u limiting speed to %s\n",
1946 ap->id, dev->devno, ata_mode_string(xfer_mask));
1947
1948 return 0;
1949
1950 fail:
1951 return -EINVAL;
1952}
1953
1738static int ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev) 1954static int ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev)
1739{ 1955{
1740 unsigned int err_mask; 1956 unsigned int err_mask;
1741 int rc; 1957 int rc;
1742 1958
1959 dev->flags &= ~ATA_DFLAG_PIO;
1743 if (dev->xfer_shift == ATA_SHIFT_PIO) 1960 if (dev->xfer_shift == ATA_SHIFT_PIO)
1744 dev->flags |= ATA_DFLAG_PIO; 1961 dev->flags |= ATA_DFLAG_PIO;
1745 1962
@@ -1752,12 +1969,8 @@ static int ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev)
1752 } 1969 }
1753 1970
1754 rc = ata_dev_revalidate(ap, dev, 0); 1971 rc = ata_dev_revalidate(ap, dev, 0);
1755 if (rc) { 1972 if (rc)
1756 printk(KERN_ERR
1757 "ata%u: failed to revalidate after set xfermode\n",
1758 ap->id);
1759 return rc; 1973 return rc;
1760 }
1761 1974
1762 DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n", 1975 DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n",
1763 dev->xfer_shift, (int)dev->xfer_mode); 1976 dev->xfer_shift, (int)dev->xfer_mode);
@@ -1768,118 +1981,107 @@ static int ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev)
1768 return 0; 1981 return 0;
1769} 1982}
1770 1983
1771static int ata_host_set_pio(struct ata_port *ap)
1772{
1773 int i;
1774
1775 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1776 struct ata_device *dev = &ap->device[i];
1777
1778 if (!ata_dev_present(dev))
1779 continue;
1780
1781 if (!dev->pio_mode) {
1782 printk(KERN_WARNING "ata%u: no PIO support for device %d.\n", ap->id, i);
1783 return -1;
1784 }
1785
1786 dev->xfer_mode = dev->pio_mode;
1787 dev->xfer_shift = ATA_SHIFT_PIO;
1788 if (ap->ops->set_piomode)
1789 ap->ops->set_piomode(ap, dev);
1790 }
1791
1792 return 0;
1793}
1794
1795static void ata_host_set_dma(struct ata_port *ap)
1796{
1797 int i;
1798
1799 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1800 struct ata_device *dev = &ap->device[i];
1801
1802 if (!ata_dev_present(dev) || !dev->dma_mode)
1803 continue;
1804
1805 dev->xfer_mode = dev->dma_mode;
1806 dev->xfer_shift = ata_xfer_mode2shift(dev->dma_mode);
1807 if (ap->ops->set_dmamode)
1808 ap->ops->set_dmamode(ap, dev);
1809 }
1810}
1811
1812/** 1984/**
1813 * ata_set_mode - Program timings and issue SET FEATURES - XFER 1985 * ata_set_mode - Program timings and issue SET FEATURES - XFER
1814 * @ap: port on which timings will be programmed 1986 * @ap: port on which timings will be programmed
1987 * @r_failed_dev: out paramter for failed device
1815 * 1988 *
1816 * Set ATA device disk transfer mode (PIO3, UDMA6, etc.). 1989 * Set ATA device disk transfer mode (PIO3, UDMA6, etc.). If
1990 * ata_set_mode() fails, pointer to the failing device is
1991 * returned in @r_failed_dev.
1817 * 1992 *
1818 * LOCKING: 1993 * LOCKING:
1819 * PCI/etc. bus probe sem. 1994 * PCI/etc. bus probe sem.
1995 *
1996 * RETURNS:
1997 * 0 on success, negative errno otherwise
1820 */ 1998 */
1821static void ata_set_mode(struct ata_port *ap) 1999int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
1822{ 2000{
1823 int i, rc, used_dma = 0; 2001 struct ata_device *dev;
2002 int i, rc = 0, used_dma = 0, found = 0;
1824 2003
1825 /* step 1: calculate xfer_mask */ 2004 /* step 1: calculate xfer_mask */
1826 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2005 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1827 struct ata_device *dev = &ap->device[i];
1828 unsigned int pio_mask, dma_mask; 2006 unsigned int pio_mask, dma_mask;
1829 2007
1830 if (!ata_dev_present(dev)) 2008 dev = &ap->device[i];
2009
2010 if (!ata_dev_enabled(dev))
1831 continue; 2011 continue;
1832 2012
1833 ata_dev_xfermask(ap, dev); 2013 ata_dev_xfermask(ap, dev);
1834 2014
1835 /* TODO: let LLDD filter dev->*_mask here */
1836
1837 pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0); 2015 pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0);
1838 dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask); 2016 dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask);
1839 dev->pio_mode = ata_xfer_mask2mode(pio_mask); 2017 dev->pio_mode = ata_xfer_mask2mode(pio_mask);
1840 dev->dma_mode = ata_xfer_mask2mode(dma_mask); 2018 dev->dma_mode = ata_xfer_mask2mode(dma_mask);
1841 2019
2020 found = 1;
1842 if (dev->dma_mode) 2021 if (dev->dma_mode)
1843 used_dma = 1; 2022 used_dma = 1;
1844 } 2023 }
2024 if (!found)
2025 goto out;
1845 2026
1846 /* step 2: always set host PIO timings */ 2027 /* step 2: always set host PIO timings */
1847 rc = ata_host_set_pio(ap); 2028 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1848 if (rc) 2029 dev = &ap->device[i];
1849 goto err_out; 2030 if (!ata_dev_enabled(dev))
2031 continue;
2032
2033 if (!dev->pio_mode) {
2034 printk(KERN_WARNING "ata%u: dev %u no PIO support\n",
2035 ap->id, dev->devno);
2036 rc = -EINVAL;
2037 goto out;
2038 }
2039
2040 dev->xfer_mode = dev->pio_mode;
2041 dev->xfer_shift = ATA_SHIFT_PIO;
2042 if (ap->ops->set_piomode)
2043 ap->ops->set_piomode(ap, dev);
2044 }
1850 2045
1851 /* step 3: set host DMA timings */ 2046 /* step 3: set host DMA timings */
1852 ata_host_set_dma(ap); 2047 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2048 dev = &ap->device[i];
2049
2050 if (!ata_dev_enabled(dev) || !dev->dma_mode)
2051 continue;
2052
2053 dev->xfer_mode = dev->dma_mode;
2054 dev->xfer_shift = ata_xfer_mode2shift(dev->dma_mode);
2055 if (ap->ops->set_dmamode)
2056 ap->ops->set_dmamode(ap, dev);
2057 }
1853 2058
1854 /* step 4: update devices' xfer mode */ 2059 /* step 4: update devices' xfer mode */
1855 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2060 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1856 struct ata_device *dev = &ap->device[i]; 2061 dev = &ap->device[i];
1857 2062
1858 if (!ata_dev_present(dev)) 2063 if (!ata_dev_enabled(dev))
1859 continue; 2064 continue;
1860 2065
1861 if (ata_dev_set_mode(ap, dev)) 2066 rc = ata_dev_set_mode(ap, dev);
1862 goto err_out; 2067 if (rc)
2068 goto out;
1863 } 2069 }
1864 2070
1865 /* 2071 /* Record simplex status. If we selected DMA then the other
1866 * Record simplex status. If we selected DMA then the other 2072 * host channels are not permitted to do so.
1867 * host channels are not permitted to do so.
1868 */ 2073 */
1869
1870 if (used_dma && (ap->host_set->flags & ATA_HOST_SIMPLEX)) 2074 if (used_dma && (ap->host_set->flags & ATA_HOST_SIMPLEX))
1871 ap->host_set->simplex_claimed = 1; 2075 ap->host_set->simplex_claimed = 1;
1872 2076
1873 /* 2077 /* step5: chip specific finalisation */
1874 * Chip specific finalisation
1875 */
1876 if (ap->ops->post_set_mode) 2078 if (ap->ops->post_set_mode)
1877 ap->ops->post_set_mode(ap); 2079 ap->ops->post_set_mode(ap);
1878 2080
1879 return; 2081 out:
1880 2082 if (rc)
1881err_out: 2083 *r_failed_dev = dev;
1882 ata_port_disable(ap); 2084 return rc;
1883} 2085}
1884 2086
1885/** 2087/**
@@ -2032,8 +2234,10 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
2032 * the bus shows 0xFF because the odd clown forgets the D7 2234 * the bus shows 0xFF because the odd clown forgets the D7
2033 * pulldown resistor. 2235 * pulldown resistor.
2034 */ 2236 */
2035 if (ata_check_status(ap) == 0xFF) 2237 if (ata_check_status(ap) == 0xFF) {
2238 printk(KERN_ERR "ata%u: SRST failed (status 0xFF)\n", ap->id);
2036 return AC_ERR_OTHER; 2239 return AC_ERR_OTHER;
2240 }
2037 2241
2038 ata_bus_post_reset(ap, devmask); 2242 ata_bus_post_reset(ap, devmask);
2039 2243
@@ -2057,7 +2261,7 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
2057 * Obtains host_set lock. 2261 * Obtains host_set lock.
2058 * 2262 *
2059 * SIDE EFFECTS: 2263 * SIDE EFFECTS:
2060 * Sets ATA_FLAG_PORT_DISABLED if bus reset fails. 2264 * Sets ATA_FLAG_DISABLED if bus reset fails.
2061 */ 2265 */
2062 2266
2063void ata_bus_reset(struct ata_port *ap) 2267void ata_bus_reset(struct ata_port *ap)
@@ -2134,9 +2338,11 @@ err_out:
2134static int sata_phy_resume(struct ata_port *ap) 2338static int sata_phy_resume(struct ata_port *ap)
2135{ 2339{
2136 unsigned long timeout = jiffies + (HZ * 5); 2340 unsigned long timeout = jiffies + (HZ * 5);
2137 u32 sstatus; 2341 u32 scontrol, sstatus;
2138 2342
2139 scr_write_flush(ap, SCR_CONTROL, 0x300); 2343 scontrol = scr_read(ap, SCR_CONTROL);
2344 scontrol = (scontrol & 0x0f0) | 0x300;
2345 scr_write_flush(ap, SCR_CONTROL, scontrol);
2140 2346
2141 /* Wait for phy to become ready, if necessary. */ 2347 /* Wait for phy to become ready, if necessary. */
2142 do { 2348 do {
@@ -2165,7 +2371,18 @@ static int sata_phy_resume(struct ata_port *ap)
2165void ata_std_probeinit(struct ata_port *ap) 2371void ata_std_probeinit(struct ata_port *ap)
2166{ 2372{
2167 if ((ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read) { 2373 if ((ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read) {
2374 u32 spd;
2375
2376 /* set cable type and resume link */
2377 ap->cbl = ATA_CBL_SATA;
2168 sata_phy_resume(ap); 2378 sata_phy_resume(ap);
2379
2380 /* init sata_spd_limit to the current value */
2381 spd = (scr_read(ap, SCR_CONTROL) & 0xf0) >> 4;
2382 if (spd)
2383 ap->sata_spd_limit &= (1 << spd) - 1;
2384
2385 /* wait for device */
2169 if (sata_dev_present(ap)) 2386 if (sata_dev_present(ap))
2170 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 2387 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
2171 } 2388 }
@@ -2174,7 +2391,6 @@ void ata_std_probeinit(struct ata_port *ap)
2174/** 2391/**
2175 * ata_std_softreset - reset host port via ATA SRST 2392 * ata_std_softreset - reset host port via ATA SRST
2176 * @ap: port to reset 2393 * @ap: port to reset
2177 * @verbose: fail verbosely
2178 * @classes: resulting classes of attached devices 2394 * @classes: resulting classes of attached devices
2179 * 2395 *
2180 * Reset host port using ATA SRST. This function is to be used 2396 * Reset host port using ATA SRST. This function is to be used
@@ -2186,7 +2402,7 @@ void ata_std_probeinit(struct ata_port *ap)
2186 * RETURNS: 2402 * RETURNS:
2187 * 0 on success, -errno otherwise. 2403 * 0 on success, -errno otherwise.
2188 */ 2404 */
2189int ata_std_softreset(struct ata_port *ap, int verbose, unsigned int *classes) 2405int ata_std_softreset(struct ata_port *ap, unsigned int *classes)
2190{ 2406{
2191 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; 2407 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
2192 unsigned int devmask = 0, err_mask; 2408 unsigned int devmask = 0, err_mask;
@@ -2212,12 +2428,8 @@ int ata_std_softreset(struct ata_port *ap, int verbose, unsigned int *classes)
2212 DPRINTK("about to softreset, devmask=%x\n", devmask); 2428 DPRINTK("about to softreset, devmask=%x\n", devmask);
2213 err_mask = ata_bus_softreset(ap, devmask); 2429 err_mask = ata_bus_softreset(ap, devmask);
2214 if (err_mask) { 2430 if (err_mask) {
2215 if (verbose) 2431 printk(KERN_ERR "ata%u: SRST failed (err_mask=0x%x)\n",
2216 printk(KERN_ERR "ata%u: SRST failed (err_mask=0x%x)\n", 2432 ap->id, err_mask);
2217 ap->id, err_mask);
2218 else
2219 DPRINTK("EXIT, softreset failed (err_mask=0x%x)\n",
2220 err_mask);
2221 return -EIO; 2433 return -EIO;
2222 } 2434 }
2223 2435
@@ -2234,7 +2446,6 @@ int ata_std_softreset(struct ata_port *ap, int verbose, unsigned int *classes)
2234/** 2446/**
2235 * sata_std_hardreset - reset host port via SATA phy reset 2447 * sata_std_hardreset - reset host port via SATA phy reset
2236 * @ap: port to reset 2448 * @ap: port to reset
2237 * @verbose: fail verbosely
2238 * @class: resulting class of attached device 2449 * @class: resulting class of attached device
2239 * 2450 *
2240 * SATA phy-reset host port using DET bits of SControl register. 2451 * SATA phy-reset host port using DET bits of SControl register.
@@ -2247,20 +2458,36 @@ int ata_std_softreset(struct ata_port *ap, int verbose, unsigned int *classes)
2247 * RETURNS: 2458 * RETURNS:
2248 * 0 on success, -errno otherwise. 2459 * 0 on success, -errno otherwise.
2249 */ 2460 */
2250int sata_std_hardreset(struct ata_port *ap, int verbose, unsigned int *class) 2461int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
2251{ 2462{
2463 u32 scontrol;
2464
2252 DPRINTK("ENTER\n"); 2465 DPRINTK("ENTER\n");
2253 2466
2254 /* Issue phy wake/reset */ 2467 if (ata_set_sata_spd_needed(ap)) {
2255 scr_write_flush(ap, SCR_CONTROL, 0x301); 2468 /* SATA spec says nothing about how to reconfigure
2469 * spd. To be on the safe side, turn off phy during
2470 * reconfiguration. This works for at least ICH7 AHCI
2471 * and Sil3124.
2472 */
2473 scontrol = scr_read(ap, SCR_CONTROL);
2474 scontrol = (scontrol & 0x0f0) | 0x302;
2475 scr_write_flush(ap, SCR_CONTROL, scontrol);
2256 2476
2257 /* 2477 ata_set_sata_spd(ap);
2258 * Couldn't find anything in SATA I/II specs, but AHCI-1.1 2478 }
2479
2480 /* issue phy wake/reset */
2481 scontrol = scr_read(ap, SCR_CONTROL);
2482 scontrol = (scontrol & 0x0f0) | 0x301;
2483 scr_write_flush(ap, SCR_CONTROL, scontrol);
2484
2485 /* Couldn't find anything in SATA I/II specs, but AHCI-1.1
2259 * 10.4.2 says at least 1 ms. 2486 * 10.4.2 says at least 1 ms.
2260 */ 2487 */
2261 msleep(1); 2488 msleep(1);
2262 2489
2263 /* Bring phy back */ 2490 /* bring phy back */
2264 sata_phy_resume(ap); 2491 sata_phy_resume(ap);
2265 2492
2266 /* TODO: phy layer with polling, timeouts, etc. */ 2493 /* TODO: phy layer with polling, timeouts, etc. */
@@ -2271,11 +2498,8 @@ int sata_std_hardreset(struct ata_port *ap, int verbose, unsigned int *class)
2271 } 2498 }
2272 2499
2273 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { 2500 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) {
2274 if (verbose) 2501 printk(KERN_ERR
2275 printk(KERN_ERR "ata%u: COMRESET failed " 2502 "ata%u: COMRESET failed (device not ready)\n", ap->id);
2276 "(device not ready)\n", ap->id);
2277 else
2278 DPRINTK("EXIT, device not ready\n");
2279 return -EIO; 2503 return -EIO;
2280 } 2504 }
2281 2505
@@ -2306,10 +2530,6 @@ void ata_std_postreset(struct ata_port *ap, unsigned int *classes)
2306{ 2530{
2307 DPRINTK("ENTER\n"); 2531 DPRINTK("ENTER\n");
2308 2532
2309 /* set cable type if it isn't already set */
2310 if (ap->cbl == ATA_CBL_NONE && ap->flags & ATA_FLAG_SATA)
2311 ap->cbl = ATA_CBL_SATA;
2312
2313 /* print link status */ 2533 /* print link status */
2314 if (ap->cbl == ATA_CBL_SATA) 2534 if (ap->cbl == ATA_CBL_SATA)
2315 sata_print_link_status(ap); 2535 sata_print_link_status(ap);
@@ -2359,7 +2579,7 @@ int ata_std_probe_reset(struct ata_port *ap, unsigned int *classes)
2359 ata_reset_fn_t hardreset; 2579 ata_reset_fn_t hardreset;
2360 2580
2361 hardreset = NULL; 2581 hardreset = NULL;
2362 if (ap->flags & ATA_FLAG_SATA && ap->ops->scr_read) 2582 if (ap->cbl == ATA_CBL_SATA && ap->ops->scr_read)
2363 hardreset = sata_std_hardreset; 2583 hardreset = sata_std_hardreset;
2364 2584
2365 return ata_drive_probe_reset(ap, ata_std_probeinit, 2585 return ata_drive_probe_reset(ap, ata_std_probeinit,
@@ -2367,16 +2587,15 @@ int ata_std_probe_reset(struct ata_port *ap, unsigned int *classes)
2367 ata_std_postreset, classes); 2587 ata_std_postreset, classes);
2368} 2588}
2369 2589
2370static int do_probe_reset(struct ata_port *ap, ata_reset_fn_t reset, 2590int ata_do_reset(struct ata_port *ap, ata_reset_fn_t reset,
2371 ata_postreset_fn_t postreset, 2591 ata_postreset_fn_t postreset, unsigned int *classes)
2372 unsigned int *classes)
2373{ 2592{
2374 int i, rc; 2593 int i, rc;
2375 2594
2376 for (i = 0; i < ATA_MAX_DEVICES; i++) 2595 for (i = 0; i < ATA_MAX_DEVICES; i++)
2377 classes[i] = ATA_DEV_UNKNOWN; 2596 classes[i] = ATA_DEV_UNKNOWN;
2378 2597
2379 rc = reset(ap, 0, classes); 2598 rc = reset(ap, classes);
2380 if (rc) 2599 if (rc)
2381 return rc; 2600 return rc;
2382 2601
@@ -2396,7 +2615,7 @@ static int do_probe_reset(struct ata_port *ap, ata_reset_fn_t reset,
2396 if (postreset) 2615 if (postreset)
2397 postreset(ap, classes); 2616 postreset(ap, classes);
2398 2617
2399 return classes[0] != ATA_DEV_UNKNOWN ? 0 : -ENODEV; 2618 return 0;
2400} 2619}
2401 2620
2402/** 2621/**
@@ -2420,8 +2639,6 @@ static int do_probe_reset(struct ata_port *ap, ata_reset_fn_t reset,
2420 * - If classification is supported, fill classes[] with 2639 * - If classification is supported, fill classes[] with
2421 * recognized class codes. 2640 * recognized class codes.
2422 * - If classification is not supported, leave classes[] alone. 2641 * - If classification is not supported, leave classes[] alone.
2423 * - If verbose is non-zero, print error message on failure;
2424 * otherwise, shut up.
2425 * 2642 *
2426 * LOCKING: 2643 * LOCKING:
2427 * Kernel thread context (may sleep) 2644 * Kernel thread context (may sleep)
@@ -2440,22 +2657,46 @@ int ata_drive_probe_reset(struct ata_port *ap, ata_probeinit_fn_t probeinit,
2440 if (probeinit) 2657 if (probeinit)
2441 probeinit(ap); 2658 probeinit(ap);
2442 2659
2443 if (softreset) { 2660 if (softreset && !ata_set_sata_spd_needed(ap)) {
2444 rc = do_probe_reset(ap, softreset, postreset, classes); 2661 rc = ata_do_reset(ap, softreset, postreset, classes);
2445 if (rc == 0) 2662 if (rc == 0 && classes[0] != ATA_DEV_UNKNOWN)
2446 return 0; 2663 goto done;
2664 printk(KERN_INFO "ata%u: softreset failed, will try "
2665 "hardreset in 5 secs\n", ap->id);
2666 ssleep(5);
2447 } 2667 }
2448 2668
2449 if (!hardreset) 2669 if (!hardreset)
2450 return rc; 2670 goto done;
2451 2671
2452 rc = do_probe_reset(ap, hardreset, postreset, classes); 2672 while (1) {
2453 if (rc == 0 || rc != -ENODEV) 2673 rc = ata_do_reset(ap, hardreset, postreset, classes);
2454 return rc; 2674 if (rc == 0) {
2675 if (classes[0] != ATA_DEV_UNKNOWN)
2676 goto done;
2677 break;
2678 }
2679
2680 if (ata_down_sata_spd_limit(ap))
2681 goto done;
2682
2683 printk(KERN_INFO "ata%u: hardreset failed, will retry "
2684 "in 5 secs\n", ap->id);
2685 ssleep(5);
2686 }
2455 2687
2456 if (softreset) 2688 if (softreset) {
2457 rc = do_probe_reset(ap, softreset, postreset, classes); 2689 printk(KERN_INFO "ata%u: hardreset succeeded without "
2690 "classification, will retry softreset in 5 secs\n",
2691 ap->id);
2692 ssleep(5);
2458 2693
2694 rc = ata_do_reset(ap, softreset, postreset, classes);
2695 }
2696
2697 done:
2698 if (rc == 0 && classes[0] == ATA_DEV_UNKNOWN)
2699 rc = -ENODEV;
2459 return rc; 2700 return rc;
2460} 2701}
2461 2702
@@ -2539,15 +2780,14 @@ static int ata_dev_same_device(struct ata_port *ap, struct ata_device *dev,
2539int ata_dev_revalidate(struct ata_port *ap, struct ata_device *dev, 2780int ata_dev_revalidate(struct ata_port *ap, struct ata_device *dev,
2540 int post_reset) 2781 int post_reset)
2541{ 2782{
2542 unsigned int class; 2783 unsigned int class = dev->class;
2543 u16 *id; 2784 u16 *id = NULL;
2544 int rc; 2785 int rc;
2545 2786
2546 if (!ata_dev_present(dev)) 2787 if (!ata_dev_enabled(dev)) {
2547 return -ENODEV; 2788 rc = -ENODEV;
2548 2789 goto fail;
2549 class = dev->class; 2790 }
2550 id = NULL;
2551 2791
2552 /* allocate & read ID data */ 2792 /* allocate & read ID data */
2553 rc = ata_dev_read_id(ap, dev, &class, post_reset, &id); 2793 rc = ata_dev_read_id(ap, dev, &class, post_reset, &id);
@@ -2564,7 +2804,9 @@ int ata_dev_revalidate(struct ata_port *ap, struct ata_device *dev,
2564 dev->id = id; 2804 dev->id = id;
2565 2805
2566 /* configure device according to the new ID */ 2806 /* configure device according to the new ID */
2567 return ata_dev_configure(ap, dev, 0); 2807 rc = ata_dev_configure(ap, dev, 0);
2808 if (rc == 0)
2809 return 0;
2568 2810
2569 fail: 2811 fail:
2570 printk(KERN_ERR "ata%u: dev %u revalidation failed (errno=%d)\n", 2812 printk(KERN_ERR "ata%u: dev %u revalidation failed (errno=%d)\n",
@@ -2666,23 +2908,34 @@ static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev)
2666 unsigned long xfer_mask; 2908 unsigned long xfer_mask;
2667 int i; 2909 int i;
2668 2910
2669 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, 2911 xfer_mask = ata_pack_xfermask(ap->pio_mask,
2670 ap->udma_mask); 2912 ap->mwdma_mask, ap->udma_mask);
2913
2914 /* Apply cable rule here. Don't apply it early because when
2915 * we handle hot plug the cable type can itself change.
2916 */
2917 if (ap->cbl == ATA_CBL_PATA40)
2918 xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA);
2671 2919
2672 /* FIXME: Use port-wide xfermask for now */ 2920 /* FIXME: Use port-wide xfermask for now */
2673 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2921 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2674 struct ata_device *d = &ap->device[i]; 2922 struct ata_device *d = &ap->device[i];
2675 if (!ata_dev_present(d)) 2923
2924 if (ata_dev_absent(d))
2676 continue; 2925 continue;
2677 xfer_mask &= ata_pack_xfermask(d->pio_mask, d->mwdma_mask, 2926
2678 d->udma_mask); 2927 if (ata_dev_disabled(d)) {
2928 /* to avoid violating device selection timing */
2929 xfer_mask &= ata_pack_xfermask(d->pio_mask,
2930 UINT_MAX, UINT_MAX);
2931 continue;
2932 }
2933
2934 xfer_mask &= ata_pack_xfermask(d->pio_mask,
2935 d->mwdma_mask, d->udma_mask);
2679 xfer_mask &= ata_id_xfermask(d->id); 2936 xfer_mask &= ata_id_xfermask(d->id);
2680 if (ata_dma_blacklisted(d)) 2937 if (ata_dma_blacklisted(d))
2681 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); 2938 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
2682 /* Apply cable rule here. Don't apply it early because when
2683 we handle hot plug the cable type can itself change */
2684 if (ap->cbl == ATA_CBL_PATA40)
2685 xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA);
2686 } 2939 }
2687 2940
2688 if (ata_dma_blacklisted(dev)) 2941 if (ata_dma_blacklisted(dev))
@@ -2693,11 +2946,12 @@ static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev)
2693 if (hs->simplex_claimed) 2946 if (hs->simplex_claimed)
2694 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); 2947 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
2695 } 2948 }
2949
2696 if (ap->ops->mode_filter) 2950 if (ap->ops->mode_filter)
2697 xfer_mask = ap->ops->mode_filter(ap, dev, xfer_mask); 2951 xfer_mask = ap->ops->mode_filter(ap, dev, xfer_mask);
2698 2952
2699 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask, 2953 ata_unpack_xfermask(xfer_mask, &dev->pio_mask,
2700 &dev->udma_mask); 2954 &dev->mwdma_mask, &dev->udma_mask);
2701} 2955}
2702 2956
2703/** 2957/**
@@ -2731,7 +2985,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_port *ap,
2731 tf.protocol = ATA_PROT_NODATA; 2985 tf.protocol = ATA_PROT_NODATA;
2732 tf.nsect = dev->xfer_mode; 2986 tf.nsect = dev->xfer_mode;
2733 2987
2734 err_mask = ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0); 2988 err_mask = ata_exec_internal(ap, dev, &tf, NULL, DMA_NONE, NULL, 0);
2735 2989
2736 DPRINTK("EXIT, err_mask=%x\n", err_mask); 2990 DPRINTK("EXIT, err_mask=%x\n", err_mask);
2737 return err_mask; 2991 return err_mask;
@@ -2771,7 +3025,7 @@ static unsigned int ata_dev_init_params(struct ata_port *ap,
2771 tf.nsect = sectors; 3025 tf.nsect = sectors;
2772 tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ 3026 tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */
2773 3027
2774 err_mask = ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0); 3028 err_mask = ata_exec_internal(ap, dev, &tf, NULL, DMA_NONE, NULL, 0);
2775 3029
2776 DPRINTK("EXIT, err_mask=%x\n", err_mask); 3030 DPRINTK("EXIT, err_mask=%x\n", err_mask);
2777 return err_mask; 3031 return err_mask;
@@ -3159,7 +3413,7 @@ void ata_poll_qc_complete(struct ata_queued_cmd *qc)
3159 3413
3160/** 3414/**
3161 * ata_pio_poll - poll using PIO, depending on current state 3415 * ata_pio_poll - poll using PIO, depending on current state
3162 * @ap: the target ata_port 3416 * @qc: qc in progress
3163 * 3417 *
3164 * LOCKING: 3418 * LOCKING:
3165 * None. (executing in kernel thread context) 3419 * None. (executing in kernel thread context)
@@ -3167,17 +3421,13 @@ void ata_poll_qc_complete(struct ata_queued_cmd *qc)
3167 * RETURNS: 3421 * RETURNS:
3168 * timeout value to use 3422 * timeout value to use
3169 */ 3423 */
3170 3424static unsigned long ata_pio_poll(struct ata_queued_cmd *qc)
3171static unsigned long ata_pio_poll(struct ata_port *ap)
3172{ 3425{
3173 struct ata_queued_cmd *qc; 3426 struct ata_port *ap = qc->ap;
3174 u8 status; 3427 u8 status;
3175 unsigned int poll_state = HSM_ST_UNKNOWN; 3428 unsigned int poll_state = HSM_ST_UNKNOWN;
3176 unsigned int reg_state = HSM_ST_UNKNOWN; 3429 unsigned int reg_state = HSM_ST_UNKNOWN;
3177 3430
3178 qc = ata_qc_from_tag(ap, ap->active_tag);
3179 WARN_ON(qc == NULL);
3180
3181 switch (ap->hsm_task_state) { 3431 switch (ap->hsm_task_state) {
3182 case HSM_ST: 3432 case HSM_ST:
3183 case HSM_ST_POLL: 3433 case HSM_ST_POLL:
@@ -3211,7 +3461,7 @@ static unsigned long ata_pio_poll(struct ata_port *ap)
3211 3461
3212/** 3462/**
3213 * ata_pio_complete - check if drive is busy or idle 3463 * ata_pio_complete - check if drive is busy or idle
3214 * @ap: the target ata_port 3464 * @qc: qc to complete
3215 * 3465 *
3216 * LOCKING: 3466 * LOCKING:
3217 * None. (executing in kernel thread context) 3467 * None. (executing in kernel thread context)
@@ -3219,10 +3469,9 @@ static unsigned long ata_pio_poll(struct ata_port *ap)
3219 * RETURNS: 3469 * RETURNS:
3220 * Non-zero if qc completed, zero otherwise. 3470 * Non-zero if qc completed, zero otherwise.
3221 */ 3471 */
3222 3472static int ata_pio_complete(struct ata_queued_cmd *qc)
3223static int ata_pio_complete (struct ata_port *ap)
3224{ 3473{
3225 struct ata_queued_cmd *qc; 3474 struct ata_port *ap = qc->ap;
3226 u8 drv_stat; 3475 u8 drv_stat;
3227 3476
3228 /* 3477 /*
@@ -3243,9 +3492,6 @@ static int ata_pio_complete (struct ata_port *ap)
3243 } 3492 }
3244 } 3493 }
3245 3494
3246 qc = ata_qc_from_tag(ap, ap->active_tag);
3247 WARN_ON(qc == NULL);
3248
3249 drv_stat = ata_wait_idle(ap); 3495 drv_stat = ata_wait_idle(ap);
3250 if (!ata_ok(drv_stat)) { 3496 if (!ata_ok(drv_stat)) {
3251 qc->err_mask |= __ac_err_mask(drv_stat); 3497 qc->err_mask |= __ac_err_mask(drv_stat);
@@ -3581,15 +3827,14 @@ err_out:
3581 3827
3582/** 3828/**
3583 * ata_pio_block - start PIO on a block 3829 * ata_pio_block - start PIO on a block
3584 * @ap: the target ata_port 3830 * @qc: qc to transfer block for
3585 * 3831 *
3586 * LOCKING: 3832 * LOCKING:
3587 * None. (executing in kernel thread context) 3833 * None. (executing in kernel thread context)
3588 */ 3834 */
3589 3835static void ata_pio_block(struct ata_queued_cmd *qc)
3590static void ata_pio_block(struct ata_port *ap)
3591{ 3836{
3592 struct ata_queued_cmd *qc; 3837 struct ata_port *ap = qc->ap;
3593 u8 status; 3838 u8 status;
3594 3839
3595 /* 3840 /*
@@ -3611,9 +3856,6 @@ static void ata_pio_block(struct ata_port *ap)
3611 } 3856 }
3612 } 3857 }
3613 3858
3614 qc = ata_qc_from_tag(ap, ap->active_tag);
3615 WARN_ON(qc == NULL);
3616
3617 /* check error */ 3859 /* check error */
3618 if (status & (ATA_ERR | ATA_DF)) { 3860 if (status & (ATA_ERR | ATA_DF)) {
3619 qc->err_mask |= AC_ERR_DEV; 3861 qc->err_mask |= AC_ERR_DEV;
@@ -3642,15 +3884,13 @@ static void ata_pio_block(struct ata_port *ap)
3642 } 3884 }
3643} 3885}
3644 3886
3645static void ata_pio_error(struct ata_port *ap) 3887static void ata_pio_error(struct ata_queued_cmd *qc)
3646{ 3888{
3647 struct ata_queued_cmd *qc; 3889 struct ata_port *ap = qc->ap;
3648
3649 qc = ata_qc_from_tag(ap, ap->active_tag);
3650 WARN_ON(qc == NULL);
3651 3890
3652 if (qc->tf.command != ATA_CMD_PACKET) 3891 if (qc->tf.command != ATA_CMD_PACKET)
3653 printk(KERN_WARNING "ata%u: PIO error\n", ap->id); 3892 printk(KERN_WARNING "ata%u: dev %u PIO error\n",
3893 ap->id, qc->dev->devno);
3654 3894
3655 /* make sure qc->err_mask is available to 3895 /* make sure qc->err_mask is available to
3656 * know what's wrong and recover 3896 * know what's wrong and recover
@@ -3664,7 +3904,8 @@ static void ata_pio_error(struct ata_port *ap)
3664 3904
3665static void ata_pio_task(void *_data) 3905static void ata_pio_task(void *_data)
3666{ 3906{
3667 struct ata_port *ap = _data; 3907 struct ata_queued_cmd *qc = _data;
3908 struct ata_port *ap = qc->ap;
3668 unsigned long timeout; 3909 unsigned long timeout;
3669 int qc_completed; 3910 int qc_completed;
3670 3911
@@ -3677,33 +3918,33 @@ fsm_start:
3677 return; 3918 return;
3678 3919
3679 case HSM_ST: 3920 case HSM_ST:
3680 ata_pio_block(ap); 3921 ata_pio_block(qc);
3681 break; 3922 break;
3682 3923
3683 case HSM_ST_LAST: 3924 case HSM_ST_LAST:
3684 qc_completed = ata_pio_complete(ap); 3925 qc_completed = ata_pio_complete(qc);
3685 break; 3926 break;
3686 3927
3687 case HSM_ST_POLL: 3928 case HSM_ST_POLL:
3688 case HSM_ST_LAST_POLL: 3929 case HSM_ST_LAST_POLL:
3689 timeout = ata_pio_poll(ap); 3930 timeout = ata_pio_poll(qc);
3690 break; 3931 break;
3691 3932
3692 case HSM_ST_TMOUT: 3933 case HSM_ST_TMOUT:
3693 case HSM_ST_ERR: 3934 case HSM_ST_ERR:
3694 ata_pio_error(ap); 3935 ata_pio_error(qc);
3695 return; 3936 return;
3696 } 3937 }
3697 3938
3698 if (timeout) 3939 if (timeout)
3699 ata_port_queue_task(ap, ata_pio_task, ap, timeout); 3940 ata_port_queue_task(ap, ata_pio_task, qc, timeout);
3700 else if (!qc_completed) 3941 else if (!qc_completed)
3701 goto fsm_start; 3942 goto fsm_start;
3702} 3943}
3703 3944
3704/** 3945/**
3705 * atapi_packet_task - Write CDB bytes to hardware 3946 * atapi_packet_task - Write CDB bytes to hardware
3706 * @_data: Port to which ATAPI device is attached. 3947 * @_data: qc in progress
3707 * 3948 *
3708 * When device has indicated its readiness to accept 3949 * When device has indicated its readiness to accept
3709 * a CDB, this function is called. Send the CDB. 3950 * a CDB, this function is called. Send the CDB.
@@ -3714,17 +3955,12 @@ fsm_start:
3714 * LOCKING: 3955 * LOCKING:
3715 * Kernel thread context (may sleep) 3956 * Kernel thread context (may sleep)
3716 */ 3957 */
3717
3718static void atapi_packet_task(void *_data) 3958static void atapi_packet_task(void *_data)
3719{ 3959{
3720 struct ata_port *ap = _data; 3960 struct ata_queued_cmd *qc = _data;
3721 struct ata_queued_cmd *qc; 3961 struct ata_port *ap = qc->ap;
3722 u8 status; 3962 u8 status;
3723 3963
3724 qc = ata_qc_from_tag(ap, ap->active_tag);
3725 WARN_ON(qc == NULL);
3726 WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE));
3727
3728 /* sleep-wait for BSY to clear */ 3964 /* sleep-wait for BSY to clear */
3729 DPRINTK("busy wait\n"); 3965 DPRINTK("busy wait\n");
3730 if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) { 3966 if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) {
@@ -3764,7 +4000,7 @@ static void atapi_packet_task(void *_data)
3764 4000
3765 /* PIO commands are handled by polling */ 4001 /* PIO commands are handled by polling */
3766 ap->hsm_task_state = HSM_ST; 4002 ap->hsm_task_state = HSM_ST;
3767 ata_port_queue_task(ap, ata_pio_task, ap, 0); 4003 ata_port_queue_task(ap, ata_pio_task, qc, 0);
3768 } 4004 }
3769 4005
3770 return; 4006 return;
@@ -3774,99 +4010,6 @@ err_out:
3774} 4010}
3775 4011
3776/** 4012/**
3777 * ata_qc_timeout - Handle timeout of queued command
3778 * @qc: Command that timed out
3779 *
3780 * Some part of the kernel (currently, only the SCSI layer)
3781 * has noticed that the active command on port @ap has not
3782 * completed after a specified length of time. Handle this
3783 * condition by disabling DMA (if necessary) and completing
3784 * transactions, with error if necessary.
3785 *
3786 * This also handles the case of the "lost interrupt", where
3787 * for some reason (possibly hardware bug, possibly driver bug)
3788 * an interrupt was not delivered to the driver, even though the
3789 * transaction completed successfully.
3790 *
3791 * LOCKING:
3792 * Inherited from SCSI layer (none, can sleep)
3793 */
3794
3795static void ata_qc_timeout(struct ata_queued_cmd *qc)
3796{
3797 struct ata_port *ap = qc->ap;
3798 struct ata_host_set *host_set = ap->host_set;
3799 u8 host_stat = 0, drv_stat;
3800 unsigned long flags;
3801
3802 DPRINTK("ENTER\n");
3803
3804 ap->hsm_task_state = HSM_ST_IDLE;
3805
3806 spin_lock_irqsave(&host_set->lock, flags);
3807
3808 switch (qc->tf.protocol) {
3809
3810 case ATA_PROT_DMA:
3811 case ATA_PROT_ATAPI_DMA:
3812 host_stat = ap->ops->bmdma_status(ap);
3813
3814 /* before we do anything else, clear DMA-Start bit */
3815 ap->ops->bmdma_stop(qc);
3816
3817 /* fall through */
3818
3819 default:
3820 ata_altstatus(ap);
3821 drv_stat = ata_chk_status(ap);
3822
3823 /* ack bmdma irq events */
3824 ap->ops->irq_clear(ap);
3825
3826 printk(KERN_ERR "ata%u: command 0x%x timeout, stat 0x%x host_stat 0x%x\n",
3827 ap->id, qc->tf.command, drv_stat, host_stat);
3828
3829 /* complete taskfile transaction */
3830 qc->err_mask |= ac_err_mask(drv_stat);
3831 break;
3832 }
3833
3834 spin_unlock_irqrestore(&host_set->lock, flags);
3835
3836 ata_eh_qc_complete(qc);
3837
3838 DPRINTK("EXIT\n");
3839}
3840
3841/**
3842 * ata_eng_timeout - Handle timeout of queued command
3843 * @ap: Port on which timed-out command is active
3844 *
3845 * Some part of the kernel (currently, only the SCSI layer)
3846 * has noticed that the active command on port @ap has not
3847 * completed after a specified length of time. Handle this
3848 * condition by disabling DMA (if necessary) and completing
3849 * transactions, with error if necessary.
3850 *
3851 * This also handles the case of the "lost interrupt", where
3852 * for some reason (possibly hardware bug, possibly driver bug)
3853 * an interrupt was not delivered to the driver, even though the
3854 * transaction completed successfully.
3855 *
3856 * LOCKING:
3857 * Inherited from SCSI layer (none, can sleep)
3858 */
3859
3860void ata_eng_timeout(struct ata_port *ap)
3861{
3862 DPRINTK("ENTER\n");
3863
3864 ata_qc_timeout(ata_qc_from_tag(ap, ap->active_tag));
3865
3866 DPRINTK("EXIT\n");
3867}
3868
3869/**
3870 * ata_qc_new - Request an available ATA command, for queueing 4013 * ata_qc_new - Request an available ATA command, for queueing
3871 * @ap: Port associated with device @dev 4014 * @ap: Port associated with device @dev
3872 * @dev: Device from whom we request an available command structure 4015 * @dev: Device from whom we request an available command structure
@@ -3997,15 +4140,14 @@ static inline int ata_should_dma_map(struct ata_queued_cmd *qc)
3997 * 4140 *
3998 * LOCKING: 4141 * LOCKING:
3999 * spin_lock_irqsave(host_set lock) 4142 * spin_lock_irqsave(host_set lock)
4000 *
4001 * RETURNS:
4002 * Zero on success, AC_ERR_* mask on failure
4003 */ 4143 */
4004 4144void ata_qc_issue(struct ata_queued_cmd *qc)
4005unsigned int ata_qc_issue(struct ata_queued_cmd *qc)
4006{ 4145{
4007 struct ata_port *ap = qc->ap; 4146 struct ata_port *ap = qc->ap;
4008 4147
4148 qc->ap->active_tag = qc->tag;
4149 qc->flags |= ATA_QCFLAG_ACTIVE;
4150
4009 if (ata_should_dma_map(qc)) { 4151 if (ata_should_dma_map(qc)) {
4010 if (qc->flags & ATA_QCFLAG_SG) { 4152 if (qc->flags & ATA_QCFLAG_SG) {
4011 if (ata_sg_setup(qc)) 4153 if (ata_sg_setup(qc))
@@ -4020,17 +4162,18 @@ unsigned int ata_qc_issue(struct ata_queued_cmd *qc)
4020 4162
4021 ap->ops->qc_prep(qc); 4163 ap->ops->qc_prep(qc);
4022 4164
4023 qc->ap->active_tag = qc->tag; 4165 qc->err_mask |= ap->ops->qc_issue(qc);
4024 qc->flags |= ATA_QCFLAG_ACTIVE; 4166 if (unlikely(qc->err_mask))
4025 4167 goto err;
4026 return ap->ops->qc_issue(qc); 4168 return;
4027 4169
4028sg_err: 4170sg_err:
4029 qc->flags &= ~ATA_QCFLAG_DMAMAP; 4171 qc->flags &= ~ATA_QCFLAG_DMAMAP;
4030 return AC_ERR_SYSTEM; 4172 qc->err_mask |= AC_ERR_SYSTEM;
4173err:
4174 ata_qc_complete(qc);
4031} 4175}
4032 4176
4033
4034/** 4177/**
4035 * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner 4178 * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner
4036 * @qc: command to issue to device 4179 * @qc: command to issue to device
@@ -4070,26 +4213,26 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
4070 ata_qc_set_polling(qc); 4213 ata_qc_set_polling(qc);
4071 ata_tf_to_host(ap, &qc->tf); 4214 ata_tf_to_host(ap, &qc->tf);
4072 ap->hsm_task_state = HSM_ST; 4215 ap->hsm_task_state = HSM_ST;
4073 ata_port_queue_task(ap, ata_pio_task, ap, 0); 4216 ata_port_queue_task(ap, ata_pio_task, qc, 0);
4074 break; 4217 break;
4075 4218
4076 case ATA_PROT_ATAPI: 4219 case ATA_PROT_ATAPI:
4077 ata_qc_set_polling(qc); 4220 ata_qc_set_polling(qc);
4078 ata_tf_to_host(ap, &qc->tf); 4221 ata_tf_to_host(ap, &qc->tf);
4079 ata_port_queue_task(ap, atapi_packet_task, ap, 0); 4222 ata_port_queue_task(ap, atapi_packet_task, qc, 0);
4080 break; 4223 break;
4081 4224
4082 case ATA_PROT_ATAPI_NODATA: 4225 case ATA_PROT_ATAPI_NODATA:
4083 ap->flags |= ATA_FLAG_NOINTR; 4226 ap->flags |= ATA_FLAG_NOINTR;
4084 ata_tf_to_host(ap, &qc->tf); 4227 ata_tf_to_host(ap, &qc->tf);
4085 ata_port_queue_task(ap, atapi_packet_task, ap, 0); 4228 ata_port_queue_task(ap, atapi_packet_task, qc, 0);
4086 break; 4229 break;
4087 4230
4088 case ATA_PROT_ATAPI_DMA: 4231 case ATA_PROT_ATAPI_DMA:
4089 ap->flags |= ATA_FLAG_NOINTR; 4232 ap->flags |= ATA_FLAG_NOINTR;
4090 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ 4233 ap->ops->tf_load(ap, &qc->tf); /* load tf registers */
4091 ap->ops->bmdma_setup(qc); /* set up bmdma */ 4234 ap->ops->bmdma_setup(qc); /* set up bmdma */
4092 ata_port_queue_task(ap, atapi_packet_task, ap, 0); 4235 ata_port_queue_task(ap, atapi_packet_task, qc, 0);
4093 break; 4236 break;
4094 4237
4095 default: 4238 default:
@@ -4211,7 +4354,7 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
4211 4354
4212 ap = host_set->ports[i]; 4355 ap = host_set->ports[i];
4213 if (ap && 4356 if (ap &&
4214 !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { 4357 !(ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR))) {
4215 struct ata_queued_cmd *qc; 4358 struct ata_queued_cmd *qc;
4216 4359
4217 qc = ata_qc_from_tag(ap, ap->active_tag); 4360 qc = ata_qc_from_tag(ap, ap->active_tag);
@@ -4243,7 +4386,7 @@ static int ata_do_simple_cmd(struct ata_port *ap, struct ata_device *dev,
4243 tf.flags |= ATA_TFLAG_DEVICE; 4386 tf.flags |= ATA_TFLAG_DEVICE;
4244 tf.protocol = ATA_PROT_NODATA; 4387 tf.protocol = ATA_PROT_NODATA;
4245 4388
4246 err = ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0); 4389 err = ata_exec_internal(ap, dev, &tf, NULL, DMA_NONE, NULL, 0);
4247 if (err) 4390 if (err)
4248 printk(KERN_ERR "%s: ata command failed: %d\n", 4391 printk(KERN_ERR "%s: ata command failed: %d\n",
4249 __FUNCTION__, err); 4392 __FUNCTION__, err);
@@ -4289,10 +4432,12 @@ static int ata_start_drive(struct ata_port *ap, struct ata_device *dev)
4289int ata_device_resume(struct ata_port *ap, struct ata_device *dev) 4432int ata_device_resume(struct ata_port *ap, struct ata_device *dev)
4290{ 4433{
4291 if (ap->flags & ATA_FLAG_SUSPENDED) { 4434 if (ap->flags & ATA_FLAG_SUSPENDED) {
4435 struct ata_device *failed_dev;
4292 ap->flags &= ~ATA_FLAG_SUSPENDED; 4436 ap->flags &= ~ATA_FLAG_SUSPENDED;
4293 ata_set_mode(ap); 4437 while (ata_set_mode(ap, &failed_dev))
4438 ata_dev_disable(ap, failed_dev);
4294 } 4439 }
4295 if (!ata_dev_present(dev)) 4440 if (!ata_dev_enabled(dev))
4296 return 0; 4441 return 0;
4297 if (dev->class == ATA_DEV_ATA) 4442 if (dev->class == ATA_DEV_ATA)
4298 ata_start_drive(ap, dev); 4443 ata_start_drive(ap, dev);
@@ -4310,7 +4455,7 @@ int ata_device_resume(struct ata_port *ap, struct ata_device *dev)
4310 */ 4455 */
4311int ata_device_suspend(struct ata_port *ap, struct ata_device *dev, pm_message_t state) 4456int ata_device_suspend(struct ata_port *ap, struct ata_device *dev, pm_message_t state)
4312{ 4457{
4313 if (!ata_dev_present(dev)) 4458 if (!ata_dev_enabled(dev))
4314 return 0; 4459 return 0;
4315 if (dev->class == ATA_DEV_ATA) 4460 if (dev->class == ATA_DEV_ATA)
4316 ata_flush_cache(ap, dev); 4461 ata_flush_cache(ap, dev);
@@ -4430,7 +4575,7 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
4430 host->unique_id = ata_unique_id++; 4575 host->unique_id = ata_unique_id++;
4431 host->max_cmd_len = 12; 4576 host->max_cmd_len = 12;
4432 4577
4433 ap->flags = ATA_FLAG_PORT_DISABLED; 4578 ap->flags = ATA_FLAG_DISABLED;
4434 ap->id = host->unique_id; 4579 ap->id = host->unique_id;
4435 ap->host = host; 4580 ap->host = host;
4436 ap->ctl = ATA_DEVCTL_OBS; 4581 ap->ctl = ATA_DEVCTL_OBS;
@@ -4445,6 +4590,7 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
4445 ap->flags |= ent->host_flags; 4590 ap->flags |= ent->host_flags;
4446 ap->ops = ent->port_ops; 4591 ap->ops = ent->port_ops;
4447 ap->cbl = ATA_CBL_NONE; 4592 ap->cbl = ATA_CBL_NONE;
4593 ap->sata_spd_limit = UINT_MAX;
4448 ap->active_tag = ATA_TAG_POISON; 4594 ap->active_tag = ATA_TAG_POISON;
4449 ap->last_ctl = 0xFF; 4595 ap->last_ctl = 0xFF;
4450 4596
@@ -4505,7 +4651,7 @@ static struct ata_port * ata_host_add(const struct ata_probe_ent *ent,
4505 4651
4506 host->transportt = &ata_scsi_transport_template; 4652 host->transportt = &ata_scsi_transport_template;
4507 4653
4508 ap = (struct ata_port *) &host->hostdata[0]; 4654 ap = ata_shost_to_port(host);
4509 4655
4510 ata_host_init(ap, host, host_set, ent, port_no); 4656 ata_host_init(ap, host, host_set, ent, port_no);
4511 4657
@@ -4718,7 +4864,7 @@ void ata_host_set_remove(struct ata_host_set *host_set)
4718 4864
4719int ata_scsi_release(struct Scsi_Host *host) 4865int ata_scsi_release(struct Scsi_Host *host)
4720{ 4866{
4721 struct ata_port *ap = (struct ata_port *) &host->hostdata[0]; 4867 struct ata_port *ap = ata_shost_to_port(host);
4722 int i; 4868 int i;
4723 4869
4724 DPRINTK("ENTER\n"); 4870 DPRINTK("ENTER\n");
@@ -4885,6 +5031,52 @@ int ata_ratelimit(void)
4885 return rc; 5031 return rc;
4886} 5032}
4887 5033
5034/**
5035 * ata_wait_register - wait until register value changes
5036 * @reg: IO-mapped register
5037 * @mask: Mask to apply to read register value
5038 * @val: Wait condition
5039 * @interval_msec: polling interval in milliseconds
5040 * @timeout_msec: timeout in milliseconds
5041 *
5042 * Waiting for some bits of register to change is a common
5043 * operation for ATA controllers. This function reads 32bit LE
5044 * IO-mapped register @reg and tests for the following condition.
5045 *
5046 * (*@reg & mask) != val
5047 *
5048 * If the condition is met, it returns; otherwise, the process is
5049 * repeated after @interval_msec until timeout.
5050 *
5051 * LOCKING:
5052 * Kernel thread context (may sleep)
5053 *
5054 * RETURNS:
5055 * The final register value.
5056 */
5057u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val,
5058 unsigned long interval_msec,
5059 unsigned long timeout_msec)
5060{
5061 unsigned long timeout;
5062 u32 tmp;
5063
5064 tmp = ioread32(reg);
5065
5066 /* Calculate timeout _after_ the first read to make sure
5067 * preceding writes reach the controller before starting to
5068 * eat away the timeout.
5069 */
5070 timeout = jiffies + (timeout_msec * HZ) / 1000;
5071
5072 while ((tmp & mask) == val && time_before(jiffies, timeout)) {
5073 msleep(interval_msec);
5074 tmp = ioread32(reg);
5075 }
5076
5077 return tmp;
5078}
5079
4888/* 5080/*
4889 * libata is essentially a library of internal helper functions for 5081 * libata is essentially a library of internal helper functions for
4890 * low-level ATA host controller drivers. As such, the API/ABI is 5082 * low-level ATA host controller drivers. As such, the API/ABI is
@@ -4900,7 +5092,6 @@ EXPORT_SYMBOL_GPL(ata_sg_init);
4900EXPORT_SYMBOL_GPL(ata_sg_init_one); 5092EXPORT_SYMBOL_GPL(ata_sg_init_one);
4901EXPORT_SYMBOL_GPL(__ata_qc_complete); 5093EXPORT_SYMBOL_GPL(__ata_qc_complete);
4902EXPORT_SYMBOL_GPL(ata_qc_issue_prot); 5094EXPORT_SYMBOL_GPL(ata_qc_issue_prot);
4903EXPORT_SYMBOL_GPL(ata_eng_timeout);
4904EXPORT_SYMBOL_GPL(ata_tf_load); 5095EXPORT_SYMBOL_GPL(ata_tf_load);
4905EXPORT_SYMBOL_GPL(ata_tf_read); 5096EXPORT_SYMBOL_GPL(ata_tf_read);
4906EXPORT_SYMBOL_GPL(ata_noop_dev_select); 5097EXPORT_SYMBOL_GPL(ata_noop_dev_select);
@@ -4922,6 +5113,7 @@ EXPORT_SYMBOL_GPL(ata_bmdma_irq_clear);
4922EXPORT_SYMBOL_GPL(ata_bmdma_status); 5113EXPORT_SYMBOL_GPL(ata_bmdma_status);
4923EXPORT_SYMBOL_GPL(ata_bmdma_stop); 5114EXPORT_SYMBOL_GPL(ata_bmdma_stop);
4924EXPORT_SYMBOL_GPL(ata_port_probe); 5115EXPORT_SYMBOL_GPL(ata_port_probe);
5116EXPORT_SYMBOL_GPL(ata_set_sata_spd);
4925EXPORT_SYMBOL_GPL(sata_phy_reset); 5117EXPORT_SYMBOL_GPL(sata_phy_reset);
4926EXPORT_SYMBOL_GPL(__sata_phy_reset); 5118EXPORT_SYMBOL_GPL(__sata_phy_reset);
4927EXPORT_SYMBOL_GPL(ata_bus_reset); 5119EXPORT_SYMBOL_GPL(ata_bus_reset);
@@ -4936,19 +5128,17 @@ EXPORT_SYMBOL_GPL(ata_dev_classify);
4936EXPORT_SYMBOL_GPL(ata_dev_pair); 5128EXPORT_SYMBOL_GPL(ata_dev_pair);
4937EXPORT_SYMBOL_GPL(ata_port_disable); 5129EXPORT_SYMBOL_GPL(ata_port_disable);
4938EXPORT_SYMBOL_GPL(ata_ratelimit); 5130EXPORT_SYMBOL_GPL(ata_ratelimit);
5131EXPORT_SYMBOL_GPL(ata_wait_register);
4939EXPORT_SYMBOL_GPL(ata_busy_sleep); 5132EXPORT_SYMBOL_GPL(ata_busy_sleep);
4940EXPORT_SYMBOL_GPL(ata_port_queue_task); 5133EXPORT_SYMBOL_GPL(ata_port_queue_task);
4941EXPORT_SYMBOL_GPL(ata_scsi_ioctl); 5134EXPORT_SYMBOL_GPL(ata_scsi_ioctl);
4942EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); 5135EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
4943EXPORT_SYMBOL_GPL(ata_scsi_error);
4944EXPORT_SYMBOL_GPL(ata_scsi_slave_config); 5136EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
4945EXPORT_SYMBOL_GPL(ata_scsi_release); 5137EXPORT_SYMBOL_GPL(ata_scsi_release);
4946EXPORT_SYMBOL_GPL(ata_host_intr); 5138EXPORT_SYMBOL_GPL(ata_host_intr);
4947EXPORT_SYMBOL_GPL(ata_id_string); 5139EXPORT_SYMBOL_GPL(ata_id_string);
4948EXPORT_SYMBOL_GPL(ata_id_c_string); 5140EXPORT_SYMBOL_GPL(ata_id_c_string);
4949EXPORT_SYMBOL_GPL(ata_scsi_simulate); 5141EXPORT_SYMBOL_GPL(ata_scsi_simulate);
4950EXPORT_SYMBOL_GPL(ata_eh_qc_complete);
4951EXPORT_SYMBOL_GPL(ata_eh_qc_retry);
4952 5142
4953EXPORT_SYMBOL_GPL(ata_pio_need_iordy); 5143EXPORT_SYMBOL_GPL(ata_pio_need_iordy);
4954EXPORT_SYMBOL_GPL(ata_timing_compute); 5144EXPORT_SYMBOL_GPL(ata_timing_compute);
@@ -4970,3 +5160,8 @@ EXPORT_SYMBOL_GPL(ata_device_suspend);
4970EXPORT_SYMBOL_GPL(ata_device_resume); 5160EXPORT_SYMBOL_GPL(ata_device_resume);
4971EXPORT_SYMBOL_GPL(ata_scsi_device_suspend); 5161EXPORT_SYMBOL_GPL(ata_scsi_device_suspend);
4972EXPORT_SYMBOL_GPL(ata_scsi_device_resume); 5162EXPORT_SYMBOL_GPL(ata_scsi_device_resume);
5163
5164EXPORT_SYMBOL_GPL(ata_scsi_error);
5165EXPORT_SYMBOL_GPL(ata_eng_timeout);
5166EXPORT_SYMBOL_GPL(ata_eh_qc_complete);
5167EXPORT_SYMBOL_GPL(ata_eh_qc_retry);
diff --git a/drivers/scsi/libata-eh.c b/drivers/scsi/libata-eh.c
new file mode 100644
index 000000000000..c31b13fd5307
--- /dev/null
+++ b/drivers/scsi/libata-eh.c
@@ -0,0 +1,263 @@
1/*
2 * libata-eh.c - libata error handling
3 *
4 * Maintained by: Jeff Garzik <jgarzik@pobox.com>
5 * Please ALWAYS copy linux-ide@vger.kernel.org
6 * on emails.
7 *
8 * Copyright 2006 Tejun Heo <htejun@gmail.com>
9 *
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
24 * USA.
25 *
26 *
27 * libata documentation is available via 'make {ps|pdf}docs',
28 * as Documentation/DocBook/libata.*
29 *
30 * Hardware documentation available from http://www.t13.org/ and
31 * http://www.sata-io.org/
32 *
33 */
34
35#include <linux/config.h>
36#include <linux/kernel.h>
37#include <scsi/scsi.h>
38#include <scsi/scsi_host.h>
39#include <scsi/scsi_eh.h>
40#include <scsi/scsi_device.h>
41#include <scsi/scsi_cmnd.h>
42
43#include <linux/libata.h>
44
45#include "libata.h"
46
47/**
48 * ata_scsi_timed_out - SCSI layer time out callback
49 * @cmd: timed out SCSI command
50 *
51 * Handles SCSI layer timeout. We race with normal completion of
52 * the qc for @cmd. If the qc is already gone, we lose and let
53 * the scsi command finish (EH_HANDLED). Otherwise, the qc has
54 * timed out and EH should be invoked. Prevent ata_qc_complete()
55 * from finishing it by setting EH_SCHEDULED and return
56 * EH_NOT_HANDLED.
57 *
58 * LOCKING:
59 * Called from timer context
60 *
61 * RETURNS:
62 * EH_HANDLED or EH_NOT_HANDLED
63 */
64enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
65{
66 struct Scsi_Host *host = cmd->device->host;
67 struct ata_port *ap = ata_shost_to_port(host);
68 unsigned long flags;
69 struct ata_queued_cmd *qc;
70 enum scsi_eh_timer_return ret = EH_HANDLED;
71
72 DPRINTK("ENTER\n");
73
74 spin_lock_irqsave(&ap->host_set->lock, flags);
75 qc = ata_qc_from_tag(ap, ap->active_tag);
76 if (qc) {
77 WARN_ON(qc->scsicmd != cmd);
78 qc->flags |= ATA_QCFLAG_EH_SCHEDULED;
79 qc->err_mask |= AC_ERR_TIMEOUT;
80 ret = EH_NOT_HANDLED;
81 }
82 spin_unlock_irqrestore(&ap->host_set->lock, flags);
83
84 DPRINTK("EXIT, ret=%d\n", ret);
85 return ret;
86}
87
88/**
89 * ata_scsi_error - SCSI layer error handler callback
90 * @host: SCSI host on which error occurred
91 *
92 * Handles SCSI-layer-thrown error events.
93 *
94 * LOCKING:
95 * Inherited from SCSI layer (none, can sleep)
96 *
97 * RETURNS:
98 * Zero.
99 */
100void ata_scsi_error(struct Scsi_Host *host)
101{
102 struct ata_port *ap = ata_shost_to_port(host);
103
104 DPRINTK("ENTER\n");
105
106 /* synchronize with IRQ handler and port task */
107 spin_unlock_wait(&ap->host_set->lock);
108 ata_port_flush_task(ap);
109
110 WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL);
111
112 ap->ops->eng_timeout(ap);
113
114 WARN_ON(host->host_failed || !list_empty(&host->eh_cmd_q));
115
116 scsi_eh_flush_done_q(&ap->eh_done_q);
117
118 DPRINTK("EXIT\n");
119}
120
121/**
122 * ata_qc_timeout - Handle timeout of queued command
123 * @qc: Command that timed out
124 *
125 * Some part of the kernel (currently, only the SCSI layer)
126 * has noticed that the active command on port @ap has not
127 * completed after a specified length of time. Handle this
128 * condition by disabling DMA (if necessary) and completing
129 * transactions, with error if necessary.
130 *
131 * This also handles the case of the "lost interrupt", where
132 * for some reason (possibly hardware bug, possibly driver bug)
133 * an interrupt was not delivered to the driver, even though the
134 * transaction completed successfully.
135 *
136 * LOCKING:
137 * Inherited from SCSI layer (none, can sleep)
138 */
139static void ata_qc_timeout(struct ata_queued_cmd *qc)
140{
141 struct ata_port *ap = qc->ap;
142 struct ata_host_set *host_set = ap->host_set;
143 u8 host_stat = 0, drv_stat;
144 unsigned long flags;
145
146 DPRINTK("ENTER\n");
147
148 ap->hsm_task_state = HSM_ST_IDLE;
149
150 spin_lock_irqsave(&host_set->lock, flags);
151
152 switch (qc->tf.protocol) {
153
154 case ATA_PROT_DMA:
155 case ATA_PROT_ATAPI_DMA:
156 host_stat = ap->ops->bmdma_status(ap);
157
158 /* before we do anything else, clear DMA-Start bit */
159 ap->ops->bmdma_stop(qc);
160
161 /* fall through */
162
163 default:
164 ata_altstatus(ap);
165 drv_stat = ata_chk_status(ap);
166
167 /* ack bmdma irq events */
168 ap->ops->irq_clear(ap);
169
170 printk(KERN_ERR "ata%u: command 0x%x timeout, stat 0x%x host_stat 0x%x\n",
171 ap->id, qc->tf.command, drv_stat, host_stat);
172
173 /* complete taskfile transaction */
174 qc->err_mask |= ac_err_mask(drv_stat);
175 break;
176 }
177
178 spin_unlock_irqrestore(&host_set->lock, flags);
179
180 ata_eh_qc_complete(qc);
181
182 DPRINTK("EXIT\n");
183}
184
185/**
186 * ata_eng_timeout - Handle timeout of queued command
187 * @ap: Port on which timed-out command is active
188 *
189 * Some part of the kernel (currently, only the SCSI layer)
190 * has noticed that the active command on port @ap has not
191 * completed after a specified length of time. Handle this
192 * condition by disabling DMA (if necessary) and completing
193 * transactions, with error if necessary.
194 *
195 * This also handles the case of the "lost interrupt", where
196 * for some reason (possibly hardware bug, possibly driver bug)
197 * an interrupt was not delivered to the driver, even though the
198 * transaction completed successfully.
199 *
200 * LOCKING:
201 * Inherited from SCSI layer (none, can sleep)
202 */
203void ata_eng_timeout(struct ata_port *ap)
204{
205 DPRINTK("ENTER\n");
206
207 ata_qc_timeout(ata_qc_from_tag(ap, ap->active_tag));
208
209 DPRINTK("EXIT\n");
210}
211
212static void ata_eh_scsidone(struct scsi_cmnd *scmd)
213{
214 /* nada */
215}
216
217static void __ata_eh_qc_complete(struct ata_queued_cmd *qc)
218{
219 struct ata_port *ap = qc->ap;
220 struct scsi_cmnd *scmd = qc->scsicmd;
221 unsigned long flags;
222
223 spin_lock_irqsave(&ap->host_set->lock, flags);
224 qc->scsidone = ata_eh_scsidone;
225 __ata_qc_complete(qc);
226 WARN_ON(ata_tag_valid(qc->tag));
227 spin_unlock_irqrestore(&ap->host_set->lock, flags);
228
229 scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
230}
231
232/**
233 * ata_eh_qc_complete - Complete an active ATA command from EH
234 * @qc: Command to complete
235 *
236 * Indicate to the mid and upper layers that an ATA command has
237 * completed. To be used from EH.
238 */
239void ata_eh_qc_complete(struct ata_queued_cmd *qc)
240{
241 struct scsi_cmnd *scmd = qc->scsicmd;
242 scmd->retries = scmd->allowed;
243 __ata_eh_qc_complete(qc);
244}
245
246/**
247 * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH
248 * @qc: Command to retry
249 *
250 * Indicate to the mid and upper layers that an ATA command
251 * should be retried. To be used from EH.
252 *
253 * SCSI midlayer limits the number of retries to scmd->allowed.
254 * scmd->retries is decremented for commands which get retried
255 * due to unrelated failures (qc->err_mask is zero).
256 */
257void ata_eh_qc_retry(struct ata_queued_cmd *qc)
258{
259 struct scsi_cmnd *scmd = qc->scsicmd;
260 if (!qc->err_mask && scmd->retries)
261 scmd->retries--;
262 __ata_eh_qc_complete(qc);
263}
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 410c78795ca8..159537879f7e 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -53,7 +53,6 @@
53typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, const u8 *scsicmd); 53typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, const u8 *scsicmd);
54static struct ata_device * 54static struct ata_device *
55ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev); 55ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev);
56enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd);
57 56
58#define RW_RECOVERY_MPAGE 0x1 57#define RW_RECOVERY_MPAGE 0x1
59#define RW_RECOVERY_MPAGE_LEN 12 58#define RW_RECOVERY_MPAGE_LEN 12
@@ -99,6 +98,7 @@ static const u8 def_control_mpage[CONTROL_MPAGE_LEN] = {
99 * It just needs the eh_timed_out hook. 98 * It just needs the eh_timed_out hook.
100 */ 99 */
101struct scsi_transport_template ata_scsi_transport_template = { 100struct scsi_transport_template ata_scsi_transport_template = {
101 .eh_strategy_handler = ata_scsi_error,
102 .eh_timed_out = ata_scsi_timed_out, 102 .eh_timed_out = ata_scsi_timed_out,
103}; 103};
104 104
@@ -395,7 +395,7 @@ void ata_dump_status(unsigned id, struct ata_taskfile *tf)
395 395
396int ata_scsi_device_resume(struct scsi_device *sdev) 396int ata_scsi_device_resume(struct scsi_device *sdev)
397{ 397{
398 struct ata_port *ap = (struct ata_port *) &sdev->host->hostdata[0]; 398 struct ata_port *ap = ata_shost_to_port(sdev->host);
399 struct ata_device *dev = &ap->device[sdev->id]; 399 struct ata_device *dev = &ap->device[sdev->id];
400 400
401 return ata_device_resume(ap, dev); 401 return ata_device_resume(ap, dev);
@@ -403,7 +403,7 @@ int ata_scsi_device_resume(struct scsi_device *sdev)
403 403
404int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state) 404int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state)
405{ 405{
406 struct ata_port *ap = (struct ata_port *) &sdev->host->hostdata[0]; 406 struct ata_port *ap = ata_shost_to_port(sdev->host);
407 struct ata_device *dev = &ap->device[sdev->id]; 407 struct ata_device *dev = &ap->device[sdev->id];
408 408
409 return ata_device_suspend(ap, dev, state); 409 return ata_device_suspend(ap, dev, state);
@@ -546,16 +546,11 @@ void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc)
546 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; 546 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
547 547
548 /* 548 /*
549 * Read the controller registers.
550 */
551 WARN_ON(qc->ap->ops->tf_read == NULL);
552 qc->ap->ops->tf_read(qc->ap, tf);
553
554 /*
555 * Use ata_to_sense_error() to map status register bits 549 * Use ata_to_sense_error() to map status register bits
556 * onto sense key, asc & ascq. 550 * onto sense key, asc & ascq.
557 */ 551 */
558 if (tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { 552 if (qc->err_mask ||
553 tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) {
559 ata_to_sense_error(qc->ap->id, tf->command, tf->feature, 554 ata_to_sense_error(qc->ap->id, tf->command, tf->feature,
560 &sb[1], &sb[2], &sb[3]); 555 &sb[1], &sb[2], &sb[3]);
561 sb[1] &= 0x0f; 556 sb[1] &= 0x0f;
@@ -621,16 +616,11 @@ void ata_gen_fixed_sense(struct ata_queued_cmd *qc)
621 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; 616 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
622 617
623 /* 618 /*
624 * Read the controller registers.
625 */
626 WARN_ON(qc->ap->ops->tf_read == NULL);
627 qc->ap->ops->tf_read(qc->ap, tf);
628
629 /*
630 * Use ata_to_sense_error() to map status register bits 619 * Use ata_to_sense_error() to map status register bits
631 * onto sense key, asc & ascq. 620 * onto sense key, asc & ascq.
632 */ 621 */
633 if (tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { 622 if (qc->err_mask ||
623 tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) {
634 ata_to_sense_error(qc->ap->id, tf->command, tf->feature, 624 ata_to_sense_error(qc->ap->id, tf->command, tf->feature,
635 &sb[2], &sb[12], &sb[13]); 625 &sb[2], &sb[12], &sb[13]);
636 sb[2] &= 0x0f; 626 sb[2] &= 0x0f;
@@ -714,7 +704,7 @@ int ata_scsi_slave_config(struct scsi_device *sdev)
714 struct ata_port *ap; 704 struct ata_port *ap;
715 struct ata_device *dev; 705 struct ata_device *dev;
716 706
717 ap = (struct ata_port *) &sdev->host->hostdata[0]; 707 ap = ata_shost_to_port(sdev->host);
718 dev = &ap->device[sdev->id]; 708 dev = &ap->device[sdev->id];
719 709
720 ata_scsi_dev_config(sdev, dev); 710 ata_scsi_dev_config(sdev, dev);
@@ -724,141 +714,6 @@ int ata_scsi_slave_config(struct scsi_device *sdev)
724} 714}
725 715
726/** 716/**
727 * ata_scsi_timed_out - SCSI layer time out callback
728 * @cmd: timed out SCSI command
729 *
730 * Handles SCSI layer timeout. We race with normal completion of
731 * the qc for @cmd. If the qc is already gone, we lose and let
732 * the scsi command finish (EH_HANDLED). Otherwise, the qc has
733 * timed out and EH should be invoked. Prevent ata_qc_complete()
734 * from finishing it by setting EH_SCHEDULED and return
735 * EH_NOT_HANDLED.
736 *
737 * LOCKING:
738 * Called from timer context
739 *
740 * RETURNS:
741 * EH_HANDLED or EH_NOT_HANDLED
742 */
743enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
744{
745 struct Scsi_Host *host = cmd->device->host;
746 struct ata_port *ap = (struct ata_port *) &host->hostdata[0];
747 unsigned long flags;
748 struct ata_queued_cmd *qc;
749 enum scsi_eh_timer_return ret = EH_HANDLED;
750
751 DPRINTK("ENTER\n");
752
753 spin_lock_irqsave(&ap->host_set->lock, flags);
754 qc = ata_qc_from_tag(ap, ap->active_tag);
755 if (qc) {
756 WARN_ON(qc->scsicmd != cmd);
757 qc->flags |= ATA_QCFLAG_EH_SCHEDULED;
758 qc->err_mask |= AC_ERR_TIMEOUT;
759 ret = EH_NOT_HANDLED;
760 }
761 spin_unlock_irqrestore(&ap->host_set->lock, flags);
762
763 DPRINTK("EXIT, ret=%d\n", ret);
764 return ret;
765}
766
767/**
768 * ata_scsi_error - SCSI layer error handler callback
769 * @host: SCSI host on which error occurred
770 *
771 * Handles SCSI-layer-thrown error events.
772 *
773 * LOCKING:
774 * Inherited from SCSI layer (none, can sleep)
775 *
776 * RETURNS:
777 * Zero.
778 */
779
780int ata_scsi_error(struct Scsi_Host *host)
781{
782 struct ata_port *ap;
783 unsigned long flags;
784
785 DPRINTK("ENTER\n");
786
787 ap = (struct ata_port *) &host->hostdata[0];
788
789 spin_lock_irqsave(&ap->host_set->lock, flags);
790 WARN_ON(ap->flags & ATA_FLAG_IN_EH);
791 ap->flags |= ATA_FLAG_IN_EH;
792 WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL);
793 spin_unlock_irqrestore(&ap->host_set->lock, flags);
794
795 ata_port_flush_task(ap);
796
797 ap->ops->eng_timeout(ap);
798
799 WARN_ON(host->host_failed || !list_empty(&host->eh_cmd_q));
800
801 scsi_eh_flush_done_q(&ap->eh_done_q);
802
803 spin_lock_irqsave(&ap->host_set->lock, flags);
804 ap->flags &= ~ATA_FLAG_IN_EH;
805 spin_unlock_irqrestore(&ap->host_set->lock, flags);
806
807 DPRINTK("EXIT\n");
808 return 0;
809}
810
811static void ata_eh_scsidone(struct scsi_cmnd *scmd)
812{
813 /* nada */
814}
815
816static void __ata_eh_qc_complete(struct ata_queued_cmd *qc)
817{
818 struct ata_port *ap = qc->ap;
819 struct scsi_cmnd *scmd = qc->scsicmd;
820 unsigned long flags;
821
822 spin_lock_irqsave(&ap->host_set->lock, flags);
823 qc->scsidone = ata_eh_scsidone;
824 __ata_qc_complete(qc);
825 WARN_ON(ata_tag_valid(qc->tag));
826 spin_unlock_irqrestore(&ap->host_set->lock, flags);
827
828 scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
829}
830
831/**
832 * ata_eh_qc_complete - Complete an active ATA command from EH
833 * @qc: Command to complete
834 *
835 * Indicate to the mid and upper layers that an ATA command has
836 * completed. To be used from EH.
837 */
838void ata_eh_qc_complete(struct ata_queued_cmd *qc)
839{
840 struct scsi_cmnd *scmd = qc->scsicmd;
841 scmd->retries = scmd->allowed;
842 __ata_eh_qc_complete(qc);
843}
844
845/**
846 * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH
847 * @qc: Command to retry
848 *
849 * Indicate to the mid and upper layers that an ATA command
850 * should be retried. To be used from EH.
851 *
852 * SCSI midlayer limits the number of retries to scmd->allowed.
853 * This function might need to adjust scmd->retries for commands
854 * which get retried due to unrelated NCQ failures.
855 */
856void ata_eh_qc_retry(struct ata_queued_cmd *qc)
857{
858 __ata_eh_qc_complete(qc);
859}
860
861/**
862 * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command 717 * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command
863 * @qc: Storage for translated ATA taskfile 718 * @qc: Storage for translated ATA taskfile
864 * @scsicmd: SCSI command to translate 719 * @scsicmd: SCSI command to translate
@@ -1197,6 +1052,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1197 u64 block; 1052 u64 block;
1198 u32 n_block; 1053 u32 n_block;
1199 1054
1055 qc->flags |= ATA_QCFLAG_IO;
1200 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; 1056 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
1201 1057
1202 if (scsicmd[0] == WRITE_10 || scsicmd[0] == WRITE_6 || 1058 if (scsicmd[0] == WRITE_10 || scsicmd[0] == WRITE_6 ||
@@ -1343,11 +1199,14 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
1343 */ 1199 */
1344 if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) && 1200 if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) &&
1345 ((cdb[2] & 0x20) || need_sense)) { 1201 ((cdb[2] & 0x20) || need_sense)) {
1202 qc->ap->ops->tf_read(qc->ap, &qc->tf);
1346 ata_gen_ata_desc_sense(qc); 1203 ata_gen_ata_desc_sense(qc);
1347 } else { 1204 } else {
1348 if (!need_sense) { 1205 if (!need_sense) {
1349 cmd->result = SAM_STAT_GOOD; 1206 cmd->result = SAM_STAT_GOOD;
1350 } else { 1207 } else {
1208 qc->ap->ops->tf_read(qc->ap, &qc->tf);
1209
1351 /* TODO: decide which descriptor format to use 1210 /* TODO: decide which descriptor format to use
1352 * for 48b LBA devices and call that here 1211 * for 48b LBA devices and call that here
1353 * instead of the fixed desc, which is only 1212 * instead of the fixed desc, which is only
@@ -1431,9 +1290,7 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev,
1431 goto early_finish; 1290 goto early_finish;
1432 1291
1433 /* select device, send command to hardware */ 1292 /* select device, send command to hardware */
1434 qc->err_mask = ata_qc_issue(qc); 1293 ata_qc_issue(qc);
1435 if (qc->err_mask)
1436 ata_qc_complete(qc);
1437 1294
1438 VPRINTK("EXIT\n"); 1295 VPRINTK("EXIT\n");
1439 return; 1296 return;
@@ -2141,13 +1998,15 @@ void ata_scsi_badcmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), u8
2141 1998
2142static void atapi_sense_complete(struct ata_queued_cmd *qc) 1999static void atapi_sense_complete(struct ata_queued_cmd *qc)
2143{ 2000{
2144 if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0)) 2001 if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0)) {
2145 /* FIXME: not quite right; we don't want the 2002 /* FIXME: not quite right; we don't want the
2146 * translation of taskfile registers into 2003 * translation of taskfile registers into
2147 * a sense descriptors, since that's only 2004 * a sense descriptors, since that's only
2148 * correct for ATA, not ATAPI 2005 * correct for ATA, not ATAPI
2149 */ 2006 */
2007 qc->ap->ops->tf_read(qc->ap, &qc->tf);
2150 ata_gen_ata_desc_sense(qc); 2008 ata_gen_ata_desc_sense(qc);
2009 }
2151 2010
2152 qc->scsidone(qc->scsicmd); 2011 qc->scsidone(qc->scsicmd);
2153 ata_qc_free(qc); 2012 ata_qc_free(qc);
@@ -2199,9 +2058,7 @@ static void atapi_request_sense(struct ata_queued_cmd *qc)
2199 2058
2200 qc->complete_fn = atapi_sense_complete; 2059 qc->complete_fn = atapi_sense_complete;
2201 2060
2202 qc->err_mask = ata_qc_issue(qc); 2061 ata_qc_issue(qc);
2203 if (qc->err_mask)
2204 ata_qc_complete(qc);
2205 2062
2206 DPRINTK("EXIT\n"); 2063 DPRINTK("EXIT\n");
2207} 2064}
@@ -2217,17 +2074,15 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc)
2217 cmd->result = SAM_STAT_CHECK_CONDITION; 2074 cmd->result = SAM_STAT_CHECK_CONDITION;
2218 atapi_request_sense(qc); 2075 atapi_request_sense(qc);
2219 return; 2076 return;
2220 } 2077 } else if (unlikely(err_mask)) {
2221
2222 else if (unlikely(err_mask))
2223 /* FIXME: not quite right; we don't want the 2078 /* FIXME: not quite right; we don't want the
2224 * translation of taskfile registers into 2079 * translation of taskfile registers into
2225 * a sense descriptors, since that's only 2080 * a sense descriptors, since that's only
2226 * correct for ATA, not ATAPI 2081 * correct for ATA, not ATAPI
2227 */ 2082 */
2083 qc->ap->ops->tf_read(qc->ap, &qc->tf);
2228 ata_gen_ata_desc_sense(qc); 2084 ata_gen_ata_desc_sense(qc);
2229 2085 } else {
2230 else {
2231 u8 *scsicmd = cmd->cmnd; 2086 u8 *scsicmd = cmd->cmnd;
2232 2087
2233 if ((scsicmd[0] == INQUIRY) && ((scsicmd[1] & 0x03) == 0)) { 2088 if ((scsicmd[0] == INQUIRY) && ((scsicmd[1] & 0x03) == 0)) {
@@ -2309,11 +2164,9 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
2309 qc->tf.protocol = ATA_PROT_ATAPI_DMA; 2164 qc->tf.protocol = ATA_PROT_ATAPI_DMA;
2310 qc->tf.feature |= ATAPI_PKT_DMA; 2165 qc->tf.feature |= ATAPI_PKT_DMA;
2311 2166
2312#ifdef ATAPI_ENABLE_DMADIR 2167 if (atapi_dmadir && (cmd->sc_data_direction != DMA_TO_DEVICE))
2313 /* some SATA bridges need us to indicate data xfer direction */ 2168 /* some SATA bridges need us to indicate data xfer direction */
2314 if (cmd->sc_data_direction != DMA_TO_DEVICE)
2315 qc->tf.feature |= ATAPI_DMADIR; 2169 qc->tf.feature |= ATAPI_DMADIR;
2316#endif
2317 } 2170 }
2318 2171
2319 qc->nbytes = cmd->bufflen; 2172 qc->nbytes = cmd->bufflen;
@@ -2353,7 +2206,7 @@ ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev)
2353 (scsidev->lun != 0))) 2206 (scsidev->lun != 0)))
2354 return NULL; 2207 return NULL;
2355 2208
2356 if (unlikely(!ata_dev_present(dev))) 2209 if (unlikely(!ata_dev_enabled(dev)))
2357 return NULL; 2210 return NULL;
2358 2211
2359 if (!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) { 2212 if (!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) {
@@ -2625,7 +2478,7 @@ int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
2625 struct scsi_device *scsidev = cmd->device; 2478 struct scsi_device *scsidev = cmd->device;
2626 struct Scsi_Host *shost = scsidev->host; 2479 struct Scsi_Host *shost = scsidev->host;
2627 2480
2628 ap = (struct ata_port *) &shost->hostdata[0]; 2481 ap = ata_shost_to_port(shost);
2629 2482
2630 spin_unlock(shost->host_lock); 2483 spin_unlock(shost->host_lock);
2631 spin_lock(&ap->host_set->lock); 2484 spin_lock(&ap->host_set->lock);
@@ -2741,13 +2594,13 @@ void ata_scsi_scan_host(struct ata_port *ap)
2741 struct ata_device *dev; 2594 struct ata_device *dev;
2742 unsigned int i; 2595 unsigned int i;
2743 2596
2744 if (ap->flags & ATA_FLAG_PORT_DISABLED) 2597 if (ap->flags & ATA_FLAG_DISABLED)
2745 return; 2598 return;
2746 2599
2747 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2600 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2748 dev = &ap->device[i]; 2601 dev = &ap->device[i];
2749 2602
2750 if (ata_dev_present(dev)) 2603 if (ata_dev_enabled(dev))
2751 scsi_scan_target(&ap->host->shost_gendev, 0, i, 0, 0); 2604 scsi_scan_target(&ap->host->shost_gendev, 0, i, 0, 0);
2752 } 2605 }
2753} 2606}
diff --git a/drivers/scsi/libata.h b/drivers/scsi/libata.h
index 65f52beea884..3f8b0a863781 100644
--- a/drivers/scsi/libata.h
+++ b/drivers/scsi/libata.h
@@ -29,7 +29,7 @@
29#define __LIBATA_H__ 29#define __LIBATA_H__
30 30
31#define DRV_NAME "libata" 31#define DRV_NAME "libata"
32#define DRV_VERSION "1.20" /* must be exactly four chars */ 32#define DRV_VERSION "1.30" /* must be exactly four chars */
33 33
34struct ata_scsi_args { 34struct ata_scsi_args {
35 struct ata_port *ap; 35 struct ata_port *ap;
@@ -41,13 +41,25 @@ struct ata_scsi_args {
41 41
42/* libata-core.c */ 42/* libata-core.c */
43extern int atapi_enabled; 43extern int atapi_enabled;
44extern int atapi_dmadir;
44extern int libata_fua; 45extern int libata_fua;
45extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, 46extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap,
46 struct ata_device *dev); 47 struct ata_device *dev);
47extern int ata_rwcmd_protocol(struct ata_queued_cmd *qc); 48extern int ata_rwcmd_protocol(struct ata_queued_cmd *qc);
49extern void ata_dev_disable(struct ata_port *ap, struct ata_device *dev);
48extern void ata_port_flush_task(struct ata_port *ap); 50extern void ata_port_flush_task(struct ata_port *ap);
51extern unsigned ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
52 struct ata_taskfile *tf, const u8 *cdb,
53 int dma_dir, void *buf, unsigned int buflen);
54extern int ata_down_sata_spd_limit(struct ata_port *ap);
55extern int ata_set_sata_spd_needed(struct ata_port *ap);
56extern int ata_down_xfermask_limit(struct ata_port *ap, struct ata_device *dev,
57 int force_pio0);
58extern int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev);
59extern int ata_do_reset(struct ata_port *ap, ata_reset_fn_t reset,
60 ata_postreset_fn_t postreset, unsigned int *classes);
49extern void ata_qc_free(struct ata_queued_cmd *qc); 61extern void ata_qc_free(struct ata_queued_cmd *qc);
50extern unsigned int ata_qc_issue(struct ata_queued_cmd *qc); 62extern void ata_qc_issue(struct ata_queued_cmd *qc);
51extern int ata_check_atapi_dma(struct ata_queued_cmd *qc); 63extern int ata_check_atapi_dma(struct ata_queued_cmd *qc);
52extern void ata_dev_select(struct ata_port *ap, unsigned int device, 64extern void ata_dev_select(struct ata_port *ap, unsigned int device,
53 unsigned int wait, unsigned int can_sleep); 65 unsigned int wait, unsigned int can_sleep);
@@ -60,7 +72,6 @@ extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg);
60extern struct scsi_transport_template ata_scsi_transport_template; 72extern struct scsi_transport_template ata_scsi_transport_template;
61 73
62extern void ata_scsi_scan_host(struct ata_port *ap); 74extern void ata_scsi_scan_host(struct ata_port *ap);
63extern int ata_scsi_error(struct Scsi_Host *host);
64extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf, 75extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf,
65 unsigned int buflen); 76 unsigned int buflen);
66 77
@@ -90,4 +101,8 @@ extern void ata_scsi_rbuf_fill(struct ata_scsi_args *args,
90 unsigned int (*actor) (struct ata_scsi_args *args, 101 unsigned int (*actor) (struct ata_scsi_args *args,
91 u8 *rbuf, unsigned int buflen)); 102 u8 *rbuf, unsigned int buflen));
92 103
104/* libata-eh.c */
105extern enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd);
106extern void ata_scsi_error(struct Scsi_Host *host);
107
93#endif /* __LIBATA_H__ */ 108#endif /* __LIBATA_H__ */
diff --git a/drivers/scsi/pcmcia/aha152x_stub.c b/drivers/scsi/pcmcia/aha152x_stub.c
index 5609847e254a..ee449b29fc82 100644
--- a/drivers/scsi/pcmcia/aha152x_stub.c
+++ b/drivers/scsi/pcmcia/aha152x_stub.c
@@ -89,29 +89,29 @@ MODULE_LICENSE("Dual MPL/GPL");
89/*====================================================================*/ 89/*====================================================================*/
90 90
91typedef struct scsi_info_t { 91typedef struct scsi_info_t {
92 dev_link_t link; 92 struct pcmcia_device *p_dev;
93 dev_node_t node; 93 dev_node_t node;
94 struct Scsi_Host *host; 94 struct Scsi_Host *host;
95} scsi_info_t; 95} scsi_info_t;
96 96
97static void aha152x_release_cs(dev_link_t *link); 97static void aha152x_release_cs(struct pcmcia_device *link);
98static void aha152x_detach(struct pcmcia_device *p_dev); 98static void aha152x_detach(struct pcmcia_device *p_dev);
99static void aha152x_config_cs(dev_link_t *link); 99static int aha152x_config_cs(struct pcmcia_device *link);
100 100
101static dev_link_t *dev_list; 101static struct pcmcia_device *dev_list;
102 102
103static int aha152x_attach(struct pcmcia_device *p_dev) 103static int aha152x_probe(struct pcmcia_device *link)
104{ 104{
105 scsi_info_t *info; 105 scsi_info_t *info;
106 dev_link_t *link; 106
107
108 DEBUG(0, "aha152x_attach()\n"); 107 DEBUG(0, "aha152x_attach()\n");
109 108
110 /* Create new SCSI device */ 109 /* Create new SCSI device */
111 info = kmalloc(sizeof(*info), GFP_KERNEL); 110 info = kmalloc(sizeof(*info), GFP_KERNEL);
112 if (!info) return -ENOMEM; 111 if (!info) return -ENOMEM;
113 memset(info, 0, sizeof(*info)); 112 memset(info, 0, sizeof(*info));
114 link = &info->link; link->priv = info; 113 info->p_dev = link;
114 link->priv = info;
115 115
116 link->io.NumPorts1 = 0x20; 116 link->io.NumPorts1 = 0x20;
117 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 117 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
@@ -119,41 +119,22 @@ static int aha152x_attach(struct pcmcia_device *p_dev)
119 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 119 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
120 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 120 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
121 link->conf.Attributes = CONF_ENABLE_IRQ; 121 link->conf.Attributes = CONF_ENABLE_IRQ;
122 link->conf.Vcc = 50;
123 link->conf.IntType = INT_MEMORY_AND_IO; 122 link->conf.IntType = INT_MEMORY_AND_IO;
124 link->conf.Present = PRESENT_OPTION; 123 link->conf.Present = PRESENT_OPTION;
125 124
126 link->handle = p_dev; 125 return aha152x_config_cs(link);
127 p_dev->instance = link;
128
129 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
130 aha152x_config_cs(link);
131
132 return 0;
133} /* aha152x_attach */ 126} /* aha152x_attach */
134 127
135/*====================================================================*/ 128/*====================================================================*/
136 129
137static void aha152x_detach(struct pcmcia_device *p_dev) 130static void aha152x_detach(struct pcmcia_device *link)
138{ 131{
139 dev_link_t *link = dev_to_instance(p_dev);
140 dev_link_t **linkp;
141
142 DEBUG(0, "aha152x_detach(0x%p)\n", link); 132 DEBUG(0, "aha152x_detach(0x%p)\n", link);
143
144 /* Locate device structure */
145 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
146 if (*linkp == link) break;
147 if (*linkp == NULL)
148 return;
149 133
150 if (link->state & DEV_CONFIG) 134 aha152x_release_cs(link);
151 aha152x_release_cs(link);
152 135
153 /* Unlink device structure, free bits */ 136 /* Unlink device structure, free bits */
154 *linkp = link->next;
155 kfree(link->priv); 137 kfree(link->priv);
156
157} /* aha152x_detach */ 138} /* aha152x_detach */
158 139
159/*====================================================================*/ 140/*====================================================================*/
@@ -161,9 +142,8 @@ static void aha152x_detach(struct pcmcia_device *p_dev)
161#define CS_CHECK(fn, ret) \ 142#define CS_CHECK(fn, ret) \
162do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 143do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
163 144
164static void aha152x_config_cs(dev_link_t *link) 145static int aha152x_config_cs(struct pcmcia_device *link)
165{ 146{
166 client_handle_t handle = link->handle;
167 scsi_info_t *info = link->priv; 147 scsi_info_t *info = link->priv;
168 struct aha152x_setup s; 148 struct aha152x_setup s;
169 tuple_t tuple; 149 tuple_t tuple;
@@ -178,19 +158,16 @@ static void aha152x_config_cs(dev_link_t *link)
178 tuple.TupleData = tuple_data; 158 tuple.TupleData = tuple_data;
179 tuple.TupleDataMax = 64; 159 tuple.TupleDataMax = 64;
180 tuple.TupleOffset = 0; 160 tuple.TupleOffset = 0;
181 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 161 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
182 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 162 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
183 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 163 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
184 link->conf.ConfigBase = parse.config.base; 164 link->conf.ConfigBase = parse.config.base;
185 165
186 /* Configure card */
187 link->state |= DEV_CONFIG;
188
189 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 166 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
190 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 167 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
191 while (1) { 168 while (1) {
192 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 169 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
193 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 170 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
194 goto next_entry; 171 goto next_entry;
195 /* For New Media T&J, look for a SCSI window */ 172 /* For New Media T&J, look for a SCSI window */
196 if (parse.cftable_entry.io.win[0].len >= 0x20) 173 if (parse.cftable_entry.io.win[0].len >= 0x20)
@@ -201,15 +178,15 @@ static void aha152x_config_cs(dev_link_t *link)
201 if ((parse.cftable_entry.io.nwin > 0) && 178 if ((parse.cftable_entry.io.nwin > 0) &&
202 (link->io.BasePort1 < 0xffff)) { 179 (link->io.BasePort1 < 0xffff)) {
203 link->conf.ConfigIndex = parse.cftable_entry.index; 180 link->conf.ConfigIndex = parse.cftable_entry.index;
204 i = pcmcia_request_io(handle, &link->io); 181 i = pcmcia_request_io(link, &link->io);
205 if (i == CS_SUCCESS) break; 182 if (i == CS_SUCCESS) break;
206 } 183 }
207 next_entry: 184 next_entry:
208 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 185 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
209 } 186 }
210 187
211 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 188 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
212 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 189 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
213 190
214 /* Set configuration options for the aha152x driver */ 191 /* Set configuration options for the aha152x driver */
215 memset(&s, 0, sizeof(s)); 192 memset(&s, 0, sizeof(s));
@@ -231,53 +208,30 @@ static void aha152x_config_cs(dev_link_t *link)
231 } 208 }
232 209
233 sprintf(info->node.dev_name, "scsi%d", host->host_no); 210 sprintf(info->node.dev_name, "scsi%d", host->host_no);
234 link->dev = &info->node; 211 link->dev_node = &info->node;
235 info->host = host; 212 info->host = host;
236 213
237 link->state &= ~DEV_CONFIG_PENDING; 214 return 0;
238 return; 215
239
240cs_failed: 216cs_failed:
241 cs_error(link->handle, last_fn, last_ret); 217 cs_error(link, last_fn, last_ret);
242 aha152x_release_cs(link); 218 aha152x_release_cs(link);
243 return; 219 return -ENODEV;
244} 220}
245 221
246static void aha152x_release_cs(dev_link_t *link) 222static void aha152x_release_cs(struct pcmcia_device *link)
247{ 223{
248 scsi_info_t *info = link->priv; 224 scsi_info_t *info = link->priv;
249 225
250 aha152x_release(info->host); 226 aha152x_release(info->host);
251 link->dev = NULL; 227 pcmcia_disable_device(link);
252
253 pcmcia_release_configuration(link->handle);
254 pcmcia_release_io(link->handle, &link->io);
255 pcmcia_release_irq(link->handle, &link->irq);
256
257 link->state &= ~DEV_CONFIG;
258} 228}
259 229
260static int aha152x_suspend(struct pcmcia_device *dev) 230static int aha152x_resume(struct pcmcia_device *link)
261{ 231{
262 dev_link_t *link = dev_to_instance(dev);
263
264 link->state |= DEV_SUSPEND;
265 if (link->state & DEV_CONFIG)
266 pcmcia_release_configuration(link->handle);
267
268 return 0;
269}
270
271static int aha152x_resume(struct pcmcia_device *dev)
272{
273 dev_link_t *link = dev_to_instance(dev);
274 scsi_info_t *info = link->priv; 232 scsi_info_t *info = link->priv;
275 233
276 link->state &= ~DEV_SUSPEND; 234 aha152x_host_reset_host(info->host);
277 if (link->state & DEV_CONFIG) {
278 pcmcia_request_configuration(link->handle, &link->conf);
279 aha152x_host_reset_host(info->host);
280 }
281 235
282 return 0; 236 return 0;
283} 237}
@@ -297,10 +251,9 @@ static struct pcmcia_driver aha152x_cs_driver = {
297 .drv = { 251 .drv = {
298 .name = "aha152x_cs", 252 .name = "aha152x_cs",
299 }, 253 },
300 .probe = aha152x_attach, 254 .probe = aha152x_probe,
301 .remove = aha152x_detach, 255 .remove = aha152x_detach,
302 .id_table = aha152x_ids, 256 .id_table = aha152x_ids,
303 .suspend = aha152x_suspend,
304 .resume = aha152x_resume, 257 .resume = aha152x_resume,
305}; 258};
306 259
@@ -317,4 +270,3 @@ static void __exit exit_aha152x_cs(void)
317 270
318module_init(init_aha152x_cs); 271module_init(init_aha152x_cs);
319module_exit(exit_aha152x_cs); 272module_exit(exit_aha152x_cs);
320
diff --git a/drivers/scsi/pcmcia/fdomain_stub.c b/drivers/scsi/pcmcia/fdomain_stub.c
index 788c58d805f3..85f7ffac19a0 100644
--- a/drivers/scsi/pcmcia/fdomain_stub.c
+++ b/drivers/scsi/pcmcia/fdomain_stub.c
@@ -73,57 +73,48 @@ static char *version =
73/*====================================================================*/ 73/*====================================================================*/
74 74
75typedef struct scsi_info_t { 75typedef struct scsi_info_t {
76 dev_link_t link; 76 struct pcmcia_device *p_dev;
77 dev_node_t node; 77 dev_node_t node;
78 struct Scsi_Host *host; 78 struct Scsi_Host *host;
79} scsi_info_t; 79} scsi_info_t;
80 80
81 81
82static void fdomain_release(dev_link_t *link); 82static void fdomain_release(struct pcmcia_device *link);
83static void fdomain_detach(struct pcmcia_device *p_dev); 83static void fdomain_detach(struct pcmcia_device *p_dev);
84static void fdomain_config(dev_link_t *link); 84static int fdomain_config(struct pcmcia_device *link);
85 85
86static int fdomain_attach(struct pcmcia_device *p_dev) 86static int fdomain_probe(struct pcmcia_device *link)
87{ 87{
88 scsi_info_t *info; 88 scsi_info_t *info;
89 dev_link_t *link; 89
90 90 DEBUG(0, "fdomain_attach()\n");
91 DEBUG(0, "fdomain_attach()\n"); 91
92 92 /* Create new SCSI device */
93 /* Create new SCSI device */ 93 info = kzalloc(sizeof(*info), GFP_KERNEL);
94 info = kmalloc(sizeof(*info), GFP_KERNEL); 94 if (!info)
95 if (!info) return -ENOMEM; 95 return -ENOMEM;
96 memset(info, 0, sizeof(*info)); 96
97 link = &info->link; link->priv = info; 97 info->p_dev = link;
98 link->io.NumPorts1 = 0x10; 98 link->priv = info;
99 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 99 link->io.NumPorts1 = 0x10;
100 link->io.IOAddrLines = 10; 100 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
101 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 101 link->io.IOAddrLines = 10;
102 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 102 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
103 link->conf.Attributes = CONF_ENABLE_IRQ; 103 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
104 link->conf.Vcc = 50; 104 link->conf.Attributes = CONF_ENABLE_IRQ;
105 link->conf.IntType = INT_MEMORY_AND_IO; 105 link->conf.IntType = INT_MEMORY_AND_IO;
106 link->conf.Present = PRESENT_OPTION; 106 link->conf.Present = PRESENT_OPTION;
107 107
108 link->handle = p_dev; 108 return fdomain_config(link);
109 p_dev->instance = link;
110
111 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
112 fdomain_config(link);
113
114 return 0;
115} /* fdomain_attach */ 109} /* fdomain_attach */
116 110
117/*====================================================================*/ 111/*====================================================================*/
118 112
119static void fdomain_detach(struct pcmcia_device *p_dev) 113static void fdomain_detach(struct pcmcia_device *link)
120{ 114{
121 dev_link_t *link = dev_to_instance(p_dev);
122
123 DEBUG(0, "fdomain_detach(0x%p)\n", link); 115 DEBUG(0, "fdomain_detach(0x%p)\n", link);
124 116
125 if (link->state & DEV_CONFIG) 117 fdomain_release(link);
126 fdomain_release(link);
127 118
128 kfree(link->priv); 119 kfree(link->priv);
129} /* fdomain_detach */ 120} /* fdomain_detach */
@@ -133,9 +124,8 @@ static void fdomain_detach(struct pcmcia_device *p_dev)
133#define CS_CHECK(fn, ret) \ 124#define CS_CHECK(fn, ret) \
134do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 125do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
135 126
136static void fdomain_config(dev_link_t *link) 127static int fdomain_config(struct pcmcia_device *link)
137{ 128{
138 client_handle_t handle = link->handle;
139 scsi_info_t *info = link->priv; 129 scsi_info_t *info = link->priv;
140 tuple_t tuple; 130 tuple_t tuple;
141 cisparse_t parse; 131 cisparse_t parse;
@@ -150,103 +140,75 @@ static void fdomain_config(dev_link_t *link)
150 tuple.TupleData = tuple_data; 140 tuple.TupleData = tuple_data;
151 tuple.TupleDataMax = 64; 141 tuple.TupleDataMax = 64;
152 tuple.TupleOffset = 0; 142 tuple.TupleOffset = 0;
153 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 143 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
154 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 144 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
155 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 145 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
156 link->conf.ConfigBase = parse.config.base; 146 link->conf.ConfigBase = parse.config.base;
157 147
158 /* Configure card */
159 link->state |= DEV_CONFIG;
160
161 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 148 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
162 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 149 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
163 while (1) { 150 while (1) {
164 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 151 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
165 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 152 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
166 goto next_entry; 153 goto next_entry;
167 link->conf.ConfigIndex = parse.cftable_entry.index; 154 link->conf.ConfigIndex = parse.cftable_entry.index;
168 link->io.BasePort1 = parse.cftable_entry.io.win[0].base; 155 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
169 i = pcmcia_request_io(handle, &link->io); 156 i = pcmcia_request_io(link, &link->io);
170 if (i == CS_SUCCESS) break; 157 if (i == CS_SUCCESS) break;
171 next_entry: 158 next_entry:
172 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 159 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
173 } 160 }
174 161
175 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 162 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
176 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 163 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
177 164
178 /* A bad hack... */ 165 /* A bad hack... */
179 release_region(link->io.BasePort1, link->io.NumPorts1); 166 release_region(link->io.BasePort1, link->io.NumPorts1);
180 167
181 /* Set configuration options for the fdomain driver */ 168 /* Set configuration options for the fdomain driver */
182 sprintf(str, "%d,%d", link->io.BasePort1, link->irq.AssignedIRQ); 169 sprintf(str, "%d,%d", link->io.BasePort1, link->irq.AssignedIRQ);
183 fdomain_setup(str); 170 fdomain_setup(str);
184 171
185 host = __fdomain_16x0_detect(&fdomain_driver_template); 172 host = __fdomain_16x0_detect(&fdomain_driver_template);
186 if (!host) { 173 if (!host) {
187 printk(KERN_INFO "fdomain_cs: no SCSI devices found\n"); 174 printk(KERN_INFO "fdomain_cs: no SCSI devices found\n");
188 goto cs_failed; 175 goto cs_failed;
189 } 176 }
190 177
191 scsi_add_host(host, NULL); /* XXX handle failure */ 178 if (scsi_add_host(host, NULL))
179 goto cs_failed;
192 scsi_scan_host(host); 180 scsi_scan_host(host);
193 181
194 sprintf(info->node.dev_name, "scsi%d", host->host_no); 182 sprintf(info->node.dev_name, "scsi%d", host->host_no);
195 link->dev = &info->node; 183 link->dev_node = &info->node;
196 info->host = host; 184 info->host = host;
197 185
198 link->state &= ~DEV_CONFIG_PENDING; 186 return 0;
199 return; 187
200
201cs_failed: 188cs_failed:
202 cs_error(link->handle, last_fn, last_ret); 189 cs_error(link, last_fn, last_ret);
203 fdomain_release(link); 190 fdomain_release(link);
204 return; 191 return -ENODEV;
205
206} /* fdomain_config */ 192} /* fdomain_config */
207 193
208/*====================================================================*/ 194/*====================================================================*/
209 195
210static void fdomain_release(dev_link_t *link) 196static void fdomain_release(struct pcmcia_device *link)
211{ 197{
212 scsi_info_t *info = link->priv; 198 scsi_info_t *info = link->priv;
213 199
214 DEBUG(0, "fdomain_release(0x%p)\n", link); 200 DEBUG(0, "fdomain_release(0x%p)\n", link);
215 201
216 scsi_remove_host(info->host); 202 scsi_remove_host(info->host);
217 link->dev = NULL; 203 pcmcia_disable_device(link);
218 204 scsi_unregister(info->host);
219 pcmcia_release_configuration(link->handle);
220 pcmcia_release_io(link->handle, &link->io);
221 pcmcia_release_irq(link->handle, &link->irq);
222
223 scsi_unregister(info->host);
224
225 link->state &= ~DEV_CONFIG;
226} 205}
227 206
228/*====================================================================*/ 207/*====================================================================*/
229 208
230static int fdomain_suspend(struct pcmcia_device *dev) 209static int fdomain_resume(struct pcmcia_device *link)
231{ 210{
232 dev_link_t *link = dev_to_instance(dev); 211 fdomain_16x0_bus_reset(NULL);
233
234 link->state |= DEV_SUSPEND;
235 if (link->state & DEV_CONFIG)
236 pcmcia_release_configuration(link->handle);
237
238 return 0;
239}
240
241static int fdomain_resume(struct pcmcia_device *dev)
242{
243 dev_link_t *link = dev_to_instance(dev);
244
245 link->state &= ~DEV_SUSPEND;
246 if (link->state & DEV_CONFIG) {
247 pcmcia_request_configuration(link->handle, &link->conf);
248 fdomain_16x0_bus_reset(NULL);
249 }
250 212
251 return 0; 213 return 0;
252} 214}
@@ -264,10 +226,9 @@ static struct pcmcia_driver fdomain_cs_driver = {
264 .drv = { 226 .drv = {
265 .name = "fdomain_cs", 227 .name = "fdomain_cs",
266 }, 228 },
267 .probe = fdomain_attach, 229 .probe = fdomain_probe,
268 .remove = fdomain_detach, 230 .remove = fdomain_detach,
269 .id_table = fdomain_ids, 231 .id_table = fdomain_ids,
270 .suspend = fdomain_suspend,
271 .resume = fdomain_resume, 232 .resume = fdomain_resume,
272}; 233};
273 234
diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c
index 9e3ab3fd5355..231f9c311c69 100644
--- a/drivers/scsi/pcmcia/nsp_cs.c
+++ b/drivers/scsi/pcmcia/nsp_cs.c
@@ -1593,11 +1593,11 @@ static int nsp_eh_host_reset(Scsi_Cmnd *SCpnt)
1593 configure the card at this point -- we wait until we receive a 1593 configure the card at this point -- we wait until we receive a
1594 card insertion event. 1594 card insertion event.
1595======================================================================*/ 1595======================================================================*/
1596static int nsp_cs_attach(struct pcmcia_device *p_dev) 1596static int nsp_cs_probe(struct pcmcia_device *link)
1597{ 1597{
1598 scsi_info_t *info; 1598 scsi_info_t *info;
1599 dev_link_t *link;
1600 nsp_hw_data *data = &nsp_data_base; 1599 nsp_hw_data *data = &nsp_data_base;
1600 int ret;
1601 1601
1602 nsp_dbg(NSP_DEBUG_INIT, "in"); 1602 nsp_dbg(NSP_DEBUG_INIT, "in");
1603 1603
@@ -1605,7 +1605,7 @@ static int nsp_cs_attach(struct pcmcia_device *p_dev)
1605 info = kmalloc(sizeof(*info), GFP_KERNEL); 1605 info = kmalloc(sizeof(*info), GFP_KERNEL);
1606 if (info == NULL) { return -ENOMEM; } 1606 if (info == NULL) { return -ENOMEM; }
1607 memset(info, 0, sizeof(*info)); 1607 memset(info, 0, sizeof(*info));
1608 link = &info->link; 1608 info->p_dev = link;
1609 link->priv = info; 1609 link->priv = info;
1610 data->ScsiInfo = info; 1610 data->ScsiInfo = info;
1611 1611
@@ -1627,18 +1627,13 @@ static int nsp_cs_attach(struct pcmcia_device *p_dev)
1627 1627
1628 /* General socket configuration */ 1628 /* General socket configuration */
1629 link->conf.Attributes = CONF_ENABLE_IRQ; 1629 link->conf.Attributes = CONF_ENABLE_IRQ;
1630 link->conf.Vcc = 50;
1631 link->conf.IntType = INT_MEMORY_AND_IO; 1630 link->conf.IntType = INT_MEMORY_AND_IO;
1632 link->conf.Present = PRESENT_OPTION; 1631 link->conf.Present = PRESENT_OPTION;
1633 1632
1634 link->handle = p_dev; 1633 ret = nsp_cs_config(link);
1635 p_dev->instance = link;
1636
1637 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1638 nsp_cs_config(link);
1639 1634
1640 nsp_dbg(NSP_DEBUG_INIT, "link=0x%p", link); 1635 nsp_dbg(NSP_DEBUG_INIT, "link=0x%p", link);
1641 return 0; 1636 return ret;
1642} /* nsp_cs_attach */ 1637} /* nsp_cs_attach */
1643 1638
1644 1639
@@ -1648,16 +1643,12 @@ static int nsp_cs_attach(struct pcmcia_device *p_dev)
1648 structures are freed. Otherwise, the structures will be freed 1643 structures are freed. Otherwise, the structures will be freed
1649 when the device is released. 1644 when the device is released.
1650======================================================================*/ 1645======================================================================*/
1651static void nsp_cs_detach(struct pcmcia_device *p_dev) 1646static void nsp_cs_detach(struct pcmcia_device *link)
1652{ 1647{
1653 dev_link_t *link = dev_to_instance(p_dev);
1654
1655 nsp_dbg(NSP_DEBUG_INIT, "in, link=0x%p", link); 1648 nsp_dbg(NSP_DEBUG_INIT, "in, link=0x%p", link);
1656 1649
1657 if (link->state & DEV_CONFIG) { 1650 ((scsi_info_t *)link->priv)->stop = 1;
1658 ((scsi_info_t *)link->priv)->stop = 1; 1651 nsp_cs_release(link);
1659 nsp_cs_release(link);
1660 }
1661 1652
1662 kfree(link->priv); 1653 kfree(link->priv);
1663 link->priv = NULL; 1654 link->priv = NULL;
@@ -1672,9 +1663,9 @@ static void nsp_cs_detach(struct pcmcia_device *p_dev)
1672#define CS_CHECK(fn, ret) \ 1663#define CS_CHECK(fn, ret) \
1673do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 1664do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
1674/*====================================================================*/ 1665/*====================================================================*/
1675static void nsp_cs_config(dev_link_t *link) 1666static int nsp_cs_config(struct pcmcia_device *link)
1676{ 1667{
1677 client_handle_t handle = link->handle; 1668 int ret;
1678 scsi_info_t *info = link->priv; 1669 scsi_info_t *info = link->priv;
1679 tuple_t tuple; 1670 tuple_t tuple;
1680 cisparse_t parse; 1671 cisparse_t parse;
@@ -1698,26 +1689,22 @@ static void nsp_cs_config(dev_link_t *link)
1698 tuple.TupleData = tuple_data; 1689 tuple.TupleData = tuple_data;
1699 tuple.TupleDataMax = sizeof(tuple_data); 1690 tuple.TupleDataMax = sizeof(tuple_data);
1700 tuple.TupleOffset = 0; 1691 tuple.TupleOffset = 0;
1701 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 1692 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
1702 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 1693 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
1703 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 1694 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
1704 link->conf.ConfigBase = parse.config.base; 1695 link->conf.ConfigBase = parse.config.base;
1705 link->conf.Present = parse.config.rmask[0]; 1696 link->conf.Present = parse.config.rmask[0];
1706 1697
1707 /* Configure card */
1708 link->state |= DEV_CONFIG;
1709
1710 /* Look up the current Vcc */ 1698 /* Look up the current Vcc */
1711 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf)); 1699 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &conf));
1712 link->conf.Vcc = conf.Vcc;
1713 1700
1714 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 1701 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
1715 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 1702 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
1716 while (1) { 1703 while (1) {
1717 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 1704 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
1718 1705
1719 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 1706 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
1720 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 1707 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
1721 goto next_entry; 1708 goto next_entry;
1722 1709
1723 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) { dflt = *cfg; } 1710 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) { dflt = *cfg; }
@@ -1743,10 +1730,10 @@ static void nsp_cs_config(dev_link_t *link)
1743 } 1730 }
1744 1731
1745 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) { 1732 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) {
1746 link->conf.Vpp1 = link->conf.Vpp2 = 1733 link->conf.Vpp =
1747 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 1734 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
1748 } else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) { 1735 } else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) {
1749 link->conf.Vpp1 = link->conf.Vpp2 = 1736 link->conf.Vpp =
1750 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; 1737 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
1751 } 1738 }
1752 1739
@@ -1773,7 +1760,7 @@ static void nsp_cs_config(dev_link_t *link)
1773 link->io.NumPorts2 = io->win[1].len; 1760 link->io.NumPorts2 = io->win[1].len;
1774 } 1761 }
1775 /* This reserves IO space but doesn't actually enable it */ 1762 /* This reserves IO space but doesn't actually enable it */
1776 if (pcmcia_request_io(link->handle, &link->io) != 0) 1763 if (pcmcia_request_io(link, &link->io) != 0)
1777 goto next_entry; 1764 goto next_entry;
1778 } 1765 }
1779 1766
@@ -1788,7 +1775,7 @@ static void nsp_cs_config(dev_link_t *link)
1788 req.Size = 0x1000; 1775 req.Size = 0x1000;
1789 } 1776 }
1790 req.AccessSpeed = 0; 1777 req.AccessSpeed = 0;
1791 if (pcmcia_request_window(&link->handle, &req, &link->win) != 0) 1778 if (pcmcia_request_window(&link, &req, &link->win) != 0)
1792 goto next_entry; 1779 goto next_entry;
1793 map.Page = 0; map.CardOffset = mem->win[0].card_addr; 1780 map.Page = 0; map.CardOffset = mem->win[0].card_addr;
1794 if (pcmcia_map_mem_page(link->win, &map) != 0) 1781 if (pcmcia_map_mem_page(link->win, &map) != 0)
@@ -1802,17 +1789,14 @@ static void nsp_cs_config(dev_link_t *link)
1802 1789
1803 next_entry: 1790 next_entry:
1804 nsp_dbg(NSP_DEBUG_INIT, "next"); 1791 nsp_dbg(NSP_DEBUG_INIT, "next");
1805 1792 pcmcia_disable_device(link);
1806 if (link->io.NumPorts1) { 1793 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
1807 pcmcia_release_io(link->handle, &link->io);
1808 }
1809 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple));
1810 } 1794 }
1811 1795
1812 if (link->conf.Attributes & CONF_ENABLE_IRQ) { 1796 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
1813 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 1797 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
1814 } 1798 }
1815 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 1799 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
1816 1800
1817 if (free_ports) { 1801 if (free_ports) {
1818 if (link->io.BasePort1) { 1802 if (link->io.BasePort1) {
@@ -1854,16 +1838,19 @@ static void nsp_cs_config(dev_link_t *link)
1854 1838
1855 1839
1856#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74)) 1840#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74))
1857 scsi_add_host (host, NULL); 1841 ret = scsi_add_host (host, NULL);
1842 if (ret)
1843 goto cs_failed;
1844
1858 scsi_scan_host(host); 1845 scsi_scan_host(host);
1859 1846
1860 snprintf(info->node.dev_name, sizeof(info->node.dev_name), "scsi%d", host->host_no); 1847 snprintf(info->node.dev_name, sizeof(info->node.dev_name), "scsi%d", host->host_no);
1861 link->dev = &info->node; 1848 link->dev_node = &info->node;
1862 info->host = host; 1849 info->host = host;
1863 1850
1864#else 1851#else
1865 nsp_dbg(NSP_DEBUG_INIT, "GET_SCSI_INFO"); 1852 nsp_dbg(NSP_DEBUG_INIT, "GET_SCSI_INFO");
1866 tail = &link->dev; 1853 tail = &link->dev_node;
1867 info->ndev = 0; 1854 info->ndev = 0;
1868 1855
1869 nsp_dbg(NSP_DEBUG_INIT, "host=0x%p", host); 1856 nsp_dbg(NSP_DEBUG_INIT, "host=0x%p", host);
@@ -1908,11 +1895,10 @@ static void nsp_cs_config(dev_link_t *link)
1908#endif 1895#endif
1909 1896
1910 /* Finally, report what we've done */ 1897 /* Finally, report what we've done */
1911 printk(KERN_INFO "nsp_cs: index 0x%02x: Vcc %d.%d", 1898 printk(KERN_INFO "nsp_cs: index 0x%02x: ",
1912 link->conf.ConfigIndex, 1899 link->conf.ConfigIndex);
1913 link->conf.Vcc/10, link->conf.Vcc%10); 1900 if (link->conf.Vpp) {
1914 if (link->conf.Vpp1) { 1901 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
1915 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
1916 } 1902 }
1917 if (link->conf.Attributes & CONF_ENABLE_IRQ) { 1903 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
1918 printk(", irq %d", link->irq.AssignedIRQ); 1904 printk(", irq %d", link->irq.AssignedIRQ);
@@ -1929,15 +1915,14 @@ static void nsp_cs_config(dev_link_t *link)
1929 req.Base+req.Size-1); 1915 req.Base+req.Size-1);
1930 printk("\n"); 1916 printk("\n");
1931 1917
1932 link->state &= ~DEV_CONFIG_PENDING; 1918 return 0;
1933 return;
1934 1919
1935 cs_failed: 1920 cs_failed:
1936 nsp_dbg(NSP_DEBUG_INIT, "config fail"); 1921 nsp_dbg(NSP_DEBUG_INIT, "config fail");
1937 cs_error(link->handle, last_fn, last_ret); 1922 cs_error(link, last_fn, last_ret);
1938 nsp_cs_release(link); 1923 nsp_cs_release(link);
1939 1924
1940 return; 1925 return -ENODEV;
1941} /* nsp_cs_config */ 1926} /* nsp_cs_config */
1942#undef CS_CHECK 1927#undef CS_CHECK
1943 1928
@@ -1947,7 +1932,7 @@ static void nsp_cs_config(dev_link_t *link)
1947 device, and release the PCMCIA configuration. If the device is 1932 device, and release the PCMCIA configuration. If the device is
1948 still open, this will be postponed until it is closed. 1933 still open, this will be postponed until it is closed.
1949======================================================================*/ 1934======================================================================*/
1950static void nsp_cs_release(dev_link_t *link) 1935static void nsp_cs_release(struct pcmcia_device *link)
1951{ 1936{
1952 scsi_info_t *info = link->priv; 1937 scsi_info_t *info = link->priv;
1953 nsp_hw_data *data = NULL; 1938 nsp_hw_data *data = NULL;
@@ -1968,22 +1953,15 @@ static void nsp_cs_release(dev_link_t *link)
1968#else 1953#else
1969 scsi_unregister_host(&nsp_driver_template); 1954 scsi_unregister_host(&nsp_driver_template);
1970#endif 1955#endif
1971 link->dev = NULL; 1956 link->dev_node = NULL;
1972 1957
1973 if (link->win) { 1958 if (link->win) {
1974 if (data != NULL) { 1959 if (data != NULL) {
1975 iounmap((void *)(data->MmioAddress)); 1960 iounmap((void *)(data->MmioAddress));
1976 } 1961 }
1977 pcmcia_release_window(link->win);
1978 }
1979 pcmcia_release_configuration(link->handle);
1980 if (link->io.NumPorts1) {
1981 pcmcia_release_io(link->handle, &link->io);
1982 } 1962 }
1983 if (link->irq.AssignedIRQ) { 1963 pcmcia_disable_device(link);
1984 pcmcia_release_irq(link->handle, &link->irq); 1964
1985 }
1986 link->state &= ~DEV_CONFIG;
1987#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,2)) 1965#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,2))
1988 if (info->host != NULL) { 1966 if (info->host != NULL) {
1989 scsi_host_put(info->host); 1967 scsi_host_put(info->host);
@@ -1991,14 +1969,11 @@ static void nsp_cs_release(dev_link_t *link)
1991#endif 1969#endif
1992} /* nsp_cs_release */ 1970} /* nsp_cs_release */
1993 1971
1994static int nsp_cs_suspend(struct pcmcia_device *dev) 1972static int nsp_cs_suspend(struct pcmcia_device *link)
1995{ 1973{
1996 dev_link_t *link = dev_to_instance(dev);
1997 scsi_info_t *info = link->priv; 1974 scsi_info_t *info = link->priv;
1998 nsp_hw_data *data; 1975 nsp_hw_data *data;
1999 1976
2000 link->state |= DEV_SUSPEND;
2001
2002 nsp_dbg(NSP_DEBUG_INIT, "event: suspend"); 1977 nsp_dbg(NSP_DEBUG_INIT, "event: suspend");
2003 1978
2004 if (info->host != NULL) { 1979 if (info->host != NULL) {
@@ -2011,25 +1986,16 @@ static int nsp_cs_suspend(struct pcmcia_device *dev)
2011 1986
2012 info->stop = 1; 1987 info->stop = 1;
2013 1988
2014 if (link->state & DEV_CONFIG)
2015 pcmcia_release_configuration(link->handle);
2016
2017 return 0; 1989 return 0;
2018} 1990}
2019 1991
2020static int nsp_cs_resume(struct pcmcia_device *dev) 1992static int nsp_cs_resume(struct pcmcia_device *link)
2021{ 1993{
2022 dev_link_t *link = dev_to_instance(dev);
2023 scsi_info_t *info = link->priv; 1994 scsi_info_t *info = link->priv;
2024 nsp_hw_data *data; 1995 nsp_hw_data *data;
2025 1996
2026 nsp_dbg(NSP_DEBUG_INIT, "event: resume"); 1997 nsp_dbg(NSP_DEBUG_INIT, "event: resume");
2027 1998
2028 link->state &= ~DEV_SUSPEND;
2029
2030 if (link->state & DEV_CONFIG)
2031 pcmcia_request_configuration(link->handle, &link->conf);
2032
2033 info->stop = 0; 1999 info->stop = 0;
2034 2000
2035 if (info->host != NULL) { 2001 if (info->host != NULL) {
@@ -2065,7 +2031,7 @@ static struct pcmcia_driver nsp_driver = {
2065 .drv = { 2031 .drv = {
2066 .name = "nsp_cs", 2032 .name = "nsp_cs",
2067 }, 2033 },
2068 .probe = nsp_cs_attach, 2034 .probe = nsp_cs_probe,
2069 .remove = nsp_cs_detach, 2035 .remove = nsp_cs_detach,
2070 .id_table = nsp_cs_ids, 2036 .id_table = nsp_cs_ids,
2071 .suspend = nsp_cs_suspend, 2037 .suspend = nsp_cs_suspend,
@@ -2098,19 +2064,7 @@ static int __init nsp_cs_init(void)
2098static void __exit nsp_cs_exit(void) 2064static void __exit nsp_cs_exit(void)
2099{ 2065{
2100 nsp_msg(KERN_INFO, "unloading..."); 2066 nsp_msg(KERN_INFO, "unloading...");
2101
2102#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,68))
2103 pcmcia_unregister_driver(&nsp_driver); 2067 pcmcia_unregister_driver(&nsp_driver);
2104#else
2105 unregister_pcmcia_driver(&dev_info);
2106 /* XXX: this really needs to move into generic code.. */
2107 while (dev_list != NULL) {
2108 if (dev_list->state & DEV_CONFIG) {
2109 nsp_cs_release(dev_list);
2110 }
2111 nsp_cs_detach(dev_list);
2112 }
2113#endif
2114} 2068}
2115 2069
2116 2070
diff --git a/drivers/scsi/pcmcia/nsp_cs.h b/drivers/scsi/pcmcia/nsp_cs.h
index b66b140a745e..8908b8e5b78a 100644
--- a/drivers/scsi/pcmcia/nsp_cs.h
+++ b/drivers/scsi/pcmcia/nsp_cs.h
@@ -225,7 +225,7 @@
225/*====================================================================*/ 225/*====================================================================*/
226 226
227typedef struct scsi_info_t { 227typedef struct scsi_info_t {
228 dev_link_t link; 228 struct pcmcia_device *p_dev;
229 struct Scsi_Host *host; 229 struct Scsi_Host *host;
230#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74)) 230#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74))
231 dev_node_t node; 231 dev_node_t node;
@@ -297,8 +297,8 @@ typedef struct _nsp_hw_data {
297 297
298/* Card service functions */ 298/* Card service functions */
299static void nsp_cs_detach (struct pcmcia_device *p_dev); 299static void nsp_cs_detach (struct pcmcia_device *p_dev);
300static void nsp_cs_release(dev_link_t *link); 300static void nsp_cs_release(struct pcmcia_device *link);
301static void nsp_cs_config (dev_link_t *link); 301static int nsp_cs_config (struct pcmcia_device *link);
302 302
303/* Linux SCSI subsystem specific functions */ 303/* Linux SCSI subsystem specific functions */
304static struct Scsi_Host *nsp_detect (struct scsi_host_template *sht); 304static struct Scsi_Host *nsp_detect (struct scsi_host_template *sht);
@@ -450,7 +450,7 @@ static inline struct Scsi_Host *scsi_host_hn_get(unsigned short hostno)
450 return host; 450 return host;
451} 451}
452 452
453static void cs_error(client_handle_t handle, int func, int ret) 453static void cs_error(struct pcmcia_device *handle, int func, int ret)
454{ 454{
455 error_info_t err = { func, ret }; 455 error_info_t err = { func, ret };
456 pcmcia_report_error(handle, &err); 456 pcmcia_report_error(handle, &err);
diff --git a/drivers/scsi/pcmcia/qlogic_stub.c b/drivers/scsi/pcmcia/qlogic_stub.c
index dce7e687fd4a..86c2ac6ae623 100644
--- a/drivers/scsi/pcmcia/qlogic_stub.c
+++ b/drivers/scsi/pcmcia/qlogic_stub.c
@@ -91,18 +91,18 @@ static struct scsi_host_template qlogicfas_driver_template = {
91/*====================================================================*/ 91/*====================================================================*/
92 92
93typedef struct scsi_info_t { 93typedef struct scsi_info_t {
94 dev_link_t link; 94 struct pcmcia_device *p_dev;
95 dev_node_t node; 95 dev_node_t node;
96 struct Scsi_Host *host; 96 struct Scsi_Host *host;
97 unsigned short manf_id; 97 unsigned short manf_id;
98} scsi_info_t; 98} scsi_info_t;
99 99
100static void qlogic_release(dev_link_t *link); 100static void qlogic_release(struct pcmcia_device *link);
101static void qlogic_detach(struct pcmcia_device *p_dev); 101static void qlogic_detach(struct pcmcia_device *p_dev);
102static void qlogic_config(dev_link_t * link); 102static int qlogic_config(struct pcmcia_device * link);
103 103
104static struct Scsi_Host *qlogic_detect(struct scsi_host_template *host, 104static struct Scsi_Host *qlogic_detect(struct scsi_host_template *host,
105 dev_link_t *link, int qbase, int qlirq) 105 struct pcmcia_device *link, int qbase, int qlirq)
106{ 106{
107 int qltyp; /* type of chip */ 107 int qltyp; /* type of chip */
108 int qinitid; 108 int qinitid;
@@ -156,10 +156,9 @@ free_scsi_host:
156err: 156err:
157 return NULL; 157 return NULL;
158} 158}
159static int qlogic_attach(struct pcmcia_device *p_dev) 159static int qlogic_probe(struct pcmcia_device *link)
160{ 160{
161 scsi_info_t *info; 161 scsi_info_t *info;
162 dev_link_t *link;
163 162
164 DEBUG(0, "qlogic_attach()\n"); 163 DEBUG(0, "qlogic_attach()\n");
165 164
@@ -168,7 +167,7 @@ static int qlogic_attach(struct pcmcia_device *p_dev)
168 if (!info) 167 if (!info)
169 return -ENOMEM; 168 return -ENOMEM;
170 memset(info, 0, sizeof(*info)); 169 memset(info, 0, sizeof(*info));
171 link = &info->link; 170 info->p_dev = link;
172 link->priv = info; 171 link->priv = info;
173 link->io.NumPorts1 = 16; 172 link->io.NumPorts1 = 16;
174 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 173 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
@@ -176,30 +175,19 @@ static int qlogic_attach(struct pcmcia_device *p_dev)
176 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 175 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
177 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 176 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
178 link->conf.Attributes = CONF_ENABLE_IRQ; 177 link->conf.Attributes = CONF_ENABLE_IRQ;
179 link->conf.Vcc = 50;
180 link->conf.IntType = INT_MEMORY_AND_IO; 178 link->conf.IntType = INT_MEMORY_AND_IO;
181 link->conf.Present = PRESENT_OPTION; 179 link->conf.Present = PRESENT_OPTION;
182 180
183 link->handle = p_dev; 181 return qlogic_config(link);
184 p_dev->instance = link;
185
186 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
187 qlogic_config(link);
188
189 return 0;
190} /* qlogic_attach */ 182} /* qlogic_attach */
191 183
192/*====================================================================*/ 184/*====================================================================*/
193 185
194static void qlogic_detach(struct pcmcia_device *p_dev) 186static void qlogic_detach(struct pcmcia_device *link)
195{ 187{
196 dev_link_t *link = dev_to_instance(p_dev);
197
198 DEBUG(0, "qlogic_detach(0x%p)\n", link); 188 DEBUG(0, "qlogic_detach(0x%p)\n", link);
199 189
200 if (link->state & DEV_CONFIG) 190 qlogic_release(link);
201 qlogic_release(link);
202
203 kfree(link->priv); 191 kfree(link->priv);
204 192
205} /* qlogic_detach */ 193} /* qlogic_detach */
@@ -209,9 +197,8 @@ static void qlogic_detach(struct pcmcia_device *p_dev)
209#define CS_CHECK(fn, ret) \ 197#define CS_CHECK(fn, ret) \
210do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 198do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
211 199
212static void qlogic_config(dev_link_t * link) 200static int qlogic_config(struct pcmcia_device * link)
213{ 201{
214 client_handle_t handle = link->handle;
215 scsi_info_t *info = link->priv; 202 scsi_info_t *info = link->priv;
216 tuple_t tuple; 203 tuple_t tuple;
217 cisparse_t parse; 204 cisparse_t parse;
@@ -225,38 +212,35 @@ static void qlogic_config(dev_link_t * link)
225 tuple.TupleDataMax = 64; 212 tuple.TupleDataMax = 64;
226 tuple.TupleOffset = 0; 213 tuple.TupleOffset = 0;
227 tuple.DesiredTuple = CISTPL_CONFIG; 214 tuple.DesiredTuple = CISTPL_CONFIG;
228 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 215 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
229 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 216 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
230 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 217 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
231 link->conf.ConfigBase = parse.config.base; 218 link->conf.ConfigBase = parse.config.base;
232 219
233 tuple.DesiredTuple = CISTPL_MANFID; 220 tuple.DesiredTuple = CISTPL_MANFID;
234 if ((pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) && (pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS)) 221 if ((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) && (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS))
235 info->manf_id = le16_to_cpu(tuple.TupleData[0]); 222 info->manf_id = le16_to_cpu(tuple.TupleData[0]);
236 223
237 /* Configure card */
238 link->state |= DEV_CONFIG;
239
240 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 224 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
241 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 225 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
242 while (1) { 226 while (1) {
243 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 227 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
244 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 228 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
245 goto next_entry; 229 goto next_entry;
246 link->conf.ConfigIndex = parse.cftable_entry.index; 230 link->conf.ConfigIndex = parse.cftable_entry.index;
247 link->io.BasePort1 = parse.cftable_entry.io.win[0].base; 231 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
248 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len; 232 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
249 if (link->io.BasePort1 != 0) { 233 if (link->io.BasePort1 != 0) {
250 i = pcmcia_request_io(handle, &link->io); 234 i = pcmcia_request_io(link, &link->io);
251 if (i == CS_SUCCESS) 235 if (i == CS_SUCCESS)
252 break; 236 break;
253 } 237 }
254 next_entry: 238 next_entry:
255 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 239 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
256 } 240 }
257 241
258 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 242 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
259 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 243 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
260 244
261 if ((info->manf_id == MANFID_MACNICA) || (info->manf_id == MANFID_PIONEER) || (info->manf_id == 0x0098)) { 245 if ((info->manf_id == MANFID_MACNICA) || (info->manf_id == MANFID_PIONEER) || (info->manf_id == 0x0098)) {
262 /* set ATAcmd */ 246 /* set ATAcmd */
@@ -275,82 +259,54 @@ static void qlogic_config(dev_link_t * link)
275 259
276 if (!host) { 260 if (!host) {
277 printk(KERN_INFO "%s: no SCSI devices found\n", qlogic_name); 261 printk(KERN_INFO "%s: no SCSI devices found\n", qlogic_name);
278 goto out; 262 goto cs_failed;
279 } 263 }
280 264
281 sprintf(info->node.dev_name, "scsi%d", host->host_no); 265 sprintf(info->node.dev_name, "scsi%d", host->host_no);
282 link->dev = &info->node; 266 link->dev_node = &info->node;
283 info->host = host; 267 info->host = host;
284 268
285out: 269 return 0;
286 link->state &= ~DEV_CONFIG_PENDING;
287 return;
288 270
289cs_failed: 271cs_failed:
290 cs_error(link->handle, last_fn, last_ret); 272 cs_error(link, last_fn, last_ret);
291 link->dev = NULL; 273 pcmcia_disable_device(link);
292 pcmcia_release_configuration(link->handle); 274 return -ENODEV;
293 pcmcia_release_io(link->handle, &link->io);
294 pcmcia_release_irq(link->handle, &link->irq);
295 link->state &= ~DEV_CONFIG;
296 return;
297 275
298} /* qlogic_config */ 276} /* qlogic_config */
299 277
300/*====================================================================*/ 278/*====================================================================*/
301 279
302static void qlogic_release(dev_link_t *link) 280static void qlogic_release(struct pcmcia_device *link)
303{ 281{
304 scsi_info_t *info = link->priv; 282 scsi_info_t *info = link->priv;
305 283
306 DEBUG(0, "qlogic_release(0x%p)\n", link); 284 DEBUG(0, "qlogic_release(0x%p)\n", link);
307 285
308 scsi_remove_host(info->host); 286 scsi_remove_host(info->host);
309 link->dev = NULL;
310 287
311 free_irq(link->irq.AssignedIRQ, info->host); 288 free_irq(link->irq.AssignedIRQ, info->host);
312 289 pcmcia_disable_device(link);
313 pcmcia_release_configuration(link->handle);
314 pcmcia_release_io(link->handle, &link->io);
315 pcmcia_release_irq(link->handle, &link->irq);
316 290
317 scsi_host_put(info->host); 291 scsi_host_put(info->host);
318
319 link->state &= ~DEV_CONFIG;
320} 292}
321 293
322/*====================================================================*/ 294/*====================================================================*/
323 295
324static int qlogic_suspend(struct pcmcia_device *dev) 296static int qlogic_resume(struct pcmcia_device *link)
325{ 297{
326 dev_link_t *link = dev_to_instance(dev); 298 scsi_info_t *info = link->priv;
327
328 link->state |= DEV_SUSPEND;
329 if (link->state & DEV_CONFIG)
330 pcmcia_release_configuration(link->handle);
331
332 return 0;
333}
334 299
335static int qlogic_resume(struct pcmcia_device *dev) 300 pcmcia_request_configuration(link, &link->conf);
336{ 301 if ((info->manf_id == MANFID_MACNICA) ||
337 dev_link_t *link = dev_to_instance(dev); 302 (info->manf_id == MANFID_PIONEER) ||
338 303 (info->manf_id == 0x0098)) {
339 link->state &= ~DEV_SUSPEND; 304 outb(0x80, link->io.BasePort1 + 0xd);
340 if (link->state & DEV_CONFIG) { 305 outb(0x24, link->io.BasePort1 + 0x9);
341 scsi_info_t *info = link->priv; 306 outb(0x04, link->io.BasePort1 + 0xd);
342
343 pcmcia_request_configuration(link->handle, &link->conf);
344 if ((info->manf_id == MANFID_MACNICA) ||
345 (info->manf_id == MANFID_PIONEER) ||
346 (info->manf_id == 0x0098)) {
347 outb(0x80, link->io.BasePort1 + 0xd);
348 outb(0x24, link->io.BasePort1 + 0x9);
349 outb(0x04, link->io.BasePort1 + 0xd);
350 }
351 /* Ugggglllyyyy!!! */
352 qlogicfas408_bus_reset(NULL);
353 } 307 }
308 /* Ugggglllyyyy!!! */
309 qlogicfas408_bus_reset(NULL);
354 310
355 return 0; 311 return 0;
356} 312}
@@ -382,10 +338,9 @@ static struct pcmcia_driver qlogic_cs_driver = {
382 .drv = { 338 .drv = {
383 .name = "qlogic_cs", 339 .name = "qlogic_cs",
384 }, 340 },
385 .probe = qlogic_attach, 341 .probe = qlogic_probe,
386 .remove = qlogic_detach, 342 .remove = qlogic_detach,
387 .id_table = qlogic_ids, 343 .id_table = qlogic_ids,
388 .suspend = qlogic_suspend,
389 .resume = qlogic_resume, 344 .resume = qlogic_resume,
390}; 345};
391 346
diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c
index 3a4dd6f5b81f..9f59827707f0 100644
--- a/drivers/scsi/pcmcia/sym53c500_cs.c
+++ b/drivers/scsi/pcmcia/sym53c500_cs.c
@@ -202,7 +202,7 @@ static char *version =
202/* ================================================================== */ 202/* ================================================================== */
203 203
204struct scsi_info_t { 204struct scsi_info_t {
205 dev_link_t link; 205 struct pcmcia_device *p_dev;
206 dev_node_t node; 206 dev_node_t node;
207 struct Scsi_Host *host; 207 struct Scsi_Host *host;
208 unsigned short manf_id; 208 unsigned short manf_id;
@@ -527,7 +527,7 @@ idle_out:
527} 527}
528 528
529static void 529static void
530SYM53C500_release(dev_link_t *link) 530SYM53C500_release(struct pcmcia_device *link)
531{ 531{
532 struct scsi_info_t *info = link->priv; 532 struct scsi_info_t *info = link->priv;
533 struct Scsi_Host *shost = info->host; 533 struct Scsi_Host *shost = info->host;
@@ -550,13 +550,7 @@ SYM53C500_release(dev_link_t *link)
550 if (shost->io_port && shost->n_io_port) 550 if (shost->io_port && shost->n_io_port)
551 release_region(shost->io_port, shost->n_io_port); 551 release_region(shost->io_port, shost->n_io_port);
552 552
553 link->dev = NULL; 553 pcmcia_disable_device(link);
554
555 pcmcia_release_configuration(link->handle);
556 pcmcia_release_io(link->handle, &link->io);
557 pcmcia_release_irq(link->handle, &link->irq);
558
559 link->state &= ~DEV_CONFIG;
560 554
561 scsi_host_put(shost); 555 scsi_host_put(shost);
562} /* SYM53C500_release */ 556} /* SYM53C500_release */
@@ -713,10 +707,9 @@ static struct scsi_host_template sym53c500_driver_template = {
713#define CS_CHECK(fn, ret) \ 707#define CS_CHECK(fn, ret) \
714do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 708do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
715 709
716static void 710static int
717SYM53C500_config(dev_link_t *link) 711SYM53C500_config(struct pcmcia_device *link)
718{ 712{
719 client_handle_t handle = link->handle;
720 struct scsi_info_t *info = link->priv; 713 struct scsi_info_t *info = link->priv;
721 tuple_t tuple; 714 tuple_t tuple;
722 cisparse_t parse; 715 cisparse_t parse;
@@ -733,40 +726,37 @@ SYM53C500_config(dev_link_t *link)
733 tuple.TupleDataMax = 64; 726 tuple.TupleDataMax = 64;
734 tuple.TupleOffset = 0; 727 tuple.TupleOffset = 0;
735 tuple.DesiredTuple = CISTPL_CONFIG; 728 tuple.DesiredTuple = CISTPL_CONFIG;
736 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 729 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
737 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 730 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
738 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 731 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
739 link->conf.ConfigBase = parse.config.base; 732 link->conf.ConfigBase = parse.config.base;
740 733
741 tuple.DesiredTuple = CISTPL_MANFID; 734 tuple.DesiredTuple = CISTPL_MANFID;
742 if ((pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) && 735 if ((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) &&
743 (pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS)) 736 (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS))
744 info->manf_id = le16_to_cpu(tuple.TupleData[0]); 737 info->manf_id = le16_to_cpu(tuple.TupleData[0]);
745 738
746 /* Configure card */
747 link->state |= DEV_CONFIG;
748
749 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 739 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
750 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 740 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
751 while (1) { 741 while (1) {
752 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 742 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
753 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 743 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
754 goto next_entry; 744 goto next_entry;
755 link->conf.ConfigIndex = parse.cftable_entry.index; 745 link->conf.ConfigIndex = parse.cftable_entry.index;
756 link->io.BasePort1 = parse.cftable_entry.io.win[0].base; 746 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
757 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len; 747 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
758 748
759 if (link->io.BasePort1 != 0) { 749 if (link->io.BasePort1 != 0) {
760 i = pcmcia_request_io(handle, &link->io); 750 i = pcmcia_request_io(link, &link->io);
761 if (i == CS_SUCCESS) 751 if (i == CS_SUCCESS)
762 break; 752 break;
763 } 753 }
764next_entry: 754next_entry:
765 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 755 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
766 } 756 }
767 757
768 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 758 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
769 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 759 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
770 760
771 /* 761 /*
772 * That's the trouble with copying liberally from another driver. 762 * That's the trouble with copying liberally from another driver.
@@ -835,7 +825,7 @@ next_entry:
835 data->fast_pio = USE_FAST_PIO; 825 data->fast_pio = USE_FAST_PIO;
836 826
837 sprintf(info->node.dev_name, "scsi%d", host->host_no); 827 sprintf(info->node.dev_name, "scsi%d", host->host_no);
838 link->dev = &info->node; 828 link->dev_node = &info->node;
839 info->host = host; 829 info->host = host;
840 830
841 if (scsi_add_host(host, NULL)) 831 if (scsi_add_host(host, NULL))
@@ -843,7 +833,7 @@ next_entry:
843 833
844 scsi_scan_host(host); 834 scsi_scan_host(host);
845 835
846 goto out; /* SUCCESS */ 836 return 0;
847 837
848err_free_irq: 838err_free_irq:
849 free_irq(irq_level, host); 839 free_irq(irq_level, host);
@@ -852,74 +842,50 @@ err_free_scsi:
852err_release: 842err_release:
853 release_region(port_base, 0x10); 843 release_region(port_base, 0x10);
854 printk(KERN_INFO "sym53c500_cs: no SCSI devices found\n"); 844 printk(KERN_INFO "sym53c500_cs: no SCSI devices found\n");
855 845 return -ENODEV;
856out:
857 link->state &= ~DEV_CONFIG_PENDING;
858 return;
859 846
860cs_failed: 847cs_failed:
861 cs_error(link->handle, last_fn, last_ret); 848 cs_error(link, last_fn, last_ret);
862 SYM53C500_release(link); 849 SYM53C500_release(link);
863 return; 850 return -ENODEV;
864} /* SYM53C500_config */ 851} /* SYM53C500_config */
865 852
866static int sym53c500_suspend(struct pcmcia_device *dev) 853static int sym53c500_resume(struct pcmcia_device *link)
867{
868 dev_link_t *link = dev_to_instance(dev);
869
870 link->state |= DEV_SUSPEND;
871 if (link->state & DEV_CONFIG)
872 pcmcia_release_configuration(link->handle);
873
874 return 0;
875}
876
877static int sym53c500_resume(struct pcmcia_device *dev)
878{ 854{
879 dev_link_t *link = dev_to_instance(dev);
880 struct scsi_info_t *info = link->priv; 855 struct scsi_info_t *info = link->priv;
881 856
882 link->state &= ~DEV_SUSPEND; 857 /* See earlier comment about manufacturer IDs. */
883 if (link->state & DEV_CONFIG) { 858 if ((info->manf_id == MANFID_MACNICA) ||
884 pcmcia_request_configuration(link->handle, &link->conf); 859 (info->manf_id == MANFID_PIONEER) ||
885 860 (info->manf_id == 0x0098)) {
886 /* See earlier comment about manufacturer IDs. */ 861 outb(0x80, link->io.BasePort1 + 0xd);
887 if ((info->manf_id == MANFID_MACNICA) || 862 outb(0x24, link->io.BasePort1 + 0x9);
888 (info->manf_id == MANFID_PIONEER) || 863 outb(0x04, link->io.BasePort1 + 0xd);
889 (info->manf_id == 0x0098)) {
890 outb(0x80, link->io.BasePort1 + 0xd);
891 outb(0x24, link->io.BasePort1 + 0x9);
892 outb(0x04, link->io.BasePort1 + 0xd);
893 }
894 /*
895 * If things don't work after a "resume",
896 * this is a good place to start looking.
897 */
898 SYM53C500_int_host_reset(link->io.BasePort1);
899 } 864 }
865 /*
866 * If things don't work after a "resume",
867 * this is a good place to start looking.
868 */
869 SYM53C500_int_host_reset(link->io.BasePort1);
900 870
901 return 0; 871 return 0;
902} 872}
903 873
904static void 874static void
905SYM53C500_detach(struct pcmcia_device *p_dev) 875SYM53C500_detach(struct pcmcia_device *link)
906{ 876{
907 dev_link_t *link = dev_to_instance(p_dev);
908
909 DEBUG(0, "SYM53C500_detach(0x%p)\n", link); 877 DEBUG(0, "SYM53C500_detach(0x%p)\n", link);
910 878
911 if (link->state & DEV_CONFIG) 879 SYM53C500_release(link);
912 SYM53C500_release(link);
913 880
914 kfree(link->priv); 881 kfree(link->priv);
915 link->priv = NULL; 882 link->priv = NULL;
916} /* SYM53C500_detach */ 883} /* SYM53C500_detach */
917 884
918static int 885static int
919SYM53C500_attach(struct pcmcia_device *p_dev) 886SYM53C500_probe(struct pcmcia_device *link)
920{ 887{
921 struct scsi_info_t *info; 888 struct scsi_info_t *info;
922 dev_link_t *link;
923 889
924 DEBUG(0, "SYM53C500_attach()\n"); 890 DEBUG(0, "SYM53C500_attach()\n");
925 891
@@ -928,7 +894,7 @@ SYM53C500_attach(struct pcmcia_device *p_dev)
928 if (!info) 894 if (!info)
929 return -ENOMEM; 895 return -ENOMEM;
930 memset(info, 0, sizeof(*info)); 896 memset(info, 0, sizeof(*info));
931 link = &info->link; 897 info->p_dev = link;
932 link->priv = info; 898 link->priv = info;
933 link->io.NumPorts1 = 16; 899 link->io.NumPorts1 = 16;
934 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 900 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
@@ -936,17 +902,10 @@ SYM53C500_attach(struct pcmcia_device *p_dev)
936 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 902 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
937 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 903 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
938 link->conf.Attributes = CONF_ENABLE_IRQ; 904 link->conf.Attributes = CONF_ENABLE_IRQ;
939 link->conf.Vcc = 50;
940 link->conf.IntType = INT_MEMORY_AND_IO; 905 link->conf.IntType = INT_MEMORY_AND_IO;
941 link->conf.Present = PRESENT_OPTION; 906 link->conf.Present = PRESENT_OPTION;
942 907
943 link->handle = p_dev; 908 return SYM53C500_config(link);
944 p_dev->instance = link;
945
946 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
947 SYM53C500_config(link);
948
949 return 0;
950} /* SYM53C500_attach */ 909} /* SYM53C500_attach */
951 910
952MODULE_AUTHOR("Bob Tracy <rct@frus.com>"); 911MODULE_AUTHOR("Bob Tracy <rct@frus.com>");
@@ -966,10 +925,9 @@ static struct pcmcia_driver sym53c500_cs_driver = {
966 .drv = { 925 .drv = {
967 .name = "sym53c500_cs", 926 .name = "sym53c500_cs",
968 }, 927 },
969 .probe = SYM53C500_attach, 928 .probe = SYM53C500_probe,
970 .remove = SYM53C500_detach, 929 .remove = SYM53C500_detach,
971 .id_table = sym53c500_ids, 930 .id_table = sym53c500_ids,
972 .suspend = sym53c500_suspend,
973 .resume = sym53c500_resume, 931 .resume = sym53c500_resume,
974}; 932};
975 933
diff --git a/drivers/scsi/pdc_adma.c b/drivers/scsi/pdc_adma.c
index 3c85c4b66e19..b9a3c566f833 100644
--- a/drivers/scsi/pdc_adma.c
+++ b/drivers/scsi/pdc_adma.c
@@ -46,7 +46,7 @@
46#include <linux/libata.h> 46#include <linux/libata.h>
47 47
48#define DRV_NAME "pdc_adma" 48#define DRV_NAME "pdc_adma"
49#define DRV_VERSION "0.03" 49#define DRV_VERSION "0.04"
50 50
51/* macro to calculate base address for ATA regs */ 51/* macro to calculate base address for ATA regs */
52#define ADMA_ATA_REGS(base,port_no) ((base) + ((port_no) * 0x40)) 52#define ADMA_ATA_REGS(base,port_no) ((base) + ((port_no) * 0x40))
@@ -143,7 +143,6 @@ static struct scsi_host_template adma_ata_sht = {
143 .name = DRV_NAME, 143 .name = DRV_NAME,
144 .ioctl = ata_scsi_ioctl, 144 .ioctl = ata_scsi_ioctl,
145 .queuecommand = ata_scsi_queuecmd, 145 .queuecommand = ata_scsi_queuecmd,
146 .eh_strategy_handler = ata_scsi_error,
147 .can_queue = ATA_DEF_QUEUE, 146 .can_queue = ATA_DEF_QUEUE,
148 .this_id = ATA_SHT_THIS_ID, 147 .this_id = ATA_SHT_THIS_ID,
149 .sg_tablesize = LIBATA_MAX_PRD, 148 .sg_tablesize = LIBATA_MAX_PRD,
@@ -456,7 +455,7 @@ static inline unsigned int adma_intr_pkt(struct ata_host_set *host_set)
456 continue; 455 continue;
457 handled = 1; 456 handled = 1;
458 adma_enter_reg_mode(ap); 457 adma_enter_reg_mode(ap);
459 if (ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR)) 458 if (ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR))
460 continue; 459 continue;
461 pp = ap->private_data; 460 pp = ap->private_data;
462 if (!pp || pp->state != adma_state_pkt) 461 if (!pp || pp->state != adma_state_pkt)
@@ -481,7 +480,7 @@ static inline unsigned int adma_intr_mmio(struct ata_host_set *host_set)
481 for (port_no = 0; port_no < host_set->n_ports; ++port_no) { 480 for (port_no = 0; port_no < host_set->n_ports; ++port_no) {
482 struct ata_port *ap; 481 struct ata_port *ap;
483 ap = host_set->ports[port_no]; 482 ap = host_set->ports[port_no];
484 if (ap && (!(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR)))) { 483 if (ap && (!(ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR)))) {
485 struct ata_queued_cmd *qc; 484 struct ata_queued_cmd *qc;
486 struct adma_port_priv *pp = ap->private_data; 485 struct adma_port_priv *pp = ap->private_data;
487 if (!pp || pp->state != adma_state_mmio) 486 if (!pp || pp->state != adma_state_mmio)
diff --git a/drivers/scsi/sata_mv.c b/drivers/scsi/sata_mv.c
index fa901fd65085..4aabc759fcec 100644
--- a/drivers/scsi/sata_mv.c
+++ b/drivers/scsi/sata_mv.c
@@ -378,7 +378,6 @@ static struct scsi_host_template mv_sht = {
378 .name = DRV_NAME, 378 .name = DRV_NAME,
379 .ioctl = ata_scsi_ioctl, 379 .ioctl = ata_scsi_ioctl,
380 .queuecommand = ata_scsi_queuecmd, 380 .queuecommand = ata_scsi_queuecmd,
381 .eh_strategy_handler = ata_scsi_error,
382 .can_queue = MV_USE_Q_DEPTH, 381 .can_queue = MV_USE_Q_DEPTH,
383 .this_id = ATA_SHT_THIS_ID, 382 .this_id = ATA_SHT_THIS_ID,
384 .sg_tablesize = MV_MAX_SG_CT / 2, 383 .sg_tablesize = MV_MAX_SG_CT / 2,
@@ -1397,7 +1396,7 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1397 } 1396 }
1398 } 1397 }
1399 1398
1400 if (ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR)) 1399 if (ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR))
1401 continue; 1400 continue;
1402 1401
1403 err_mask = ac_err_mask(ata_status); 1402 err_mask = ac_err_mask(ata_status);
@@ -1991,7 +1990,7 @@ comreset_retry:
1991 tf.nsect = readb((void __iomem *) ap->ioaddr.nsect_addr); 1990 tf.nsect = readb((void __iomem *) ap->ioaddr.nsect_addr);
1992 1991
1993 dev->class = ata_dev_classify(&tf); 1992 dev->class = ata_dev_classify(&tf);
1994 if (!ata_dev_present(dev)) { 1993 if (!ata_dev_enabled(dev)) {
1995 VPRINTK("Port disabled post-sig: No device present.\n"); 1994 VPRINTK("Port disabled post-sig: No device present.\n");
1996 ata_port_disable(ap); 1995 ata_port_disable(ap);
1997 } 1996 }
diff --git a/drivers/scsi/sata_nv.c b/drivers/scsi/sata_nv.c
index f77bf183dfab..3a70875be8ba 100644
--- a/drivers/scsi/sata_nv.c
+++ b/drivers/scsi/sata_nv.c
@@ -44,7 +44,7 @@
44#include <linux/libata.h> 44#include <linux/libata.h>
45 45
46#define DRV_NAME "sata_nv" 46#define DRV_NAME "sata_nv"
47#define DRV_VERSION "0.8" 47#define DRV_VERSION "0.9"
48 48
49enum { 49enum {
50 NV_PORTS = 2, 50 NV_PORTS = 2,
@@ -201,7 +201,6 @@ static struct scsi_host_template nv_sht = {
201 .name = DRV_NAME, 201 .name = DRV_NAME,
202 .ioctl = ata_scsi_ioctl, 202 .ioctl = ata_scsi_ioctl,
203 .queuecommand = ata_scsi_queuecmd, 203 .queuecommand = ata_scsi_queuecmd,
204 .eh_strategy_handler = ata_scsi_error,
205 .can_queue = ATA_DEF_QUEUE, 204 .can_queue = ATA_DEF_QUEUE,
206 .this_id = ATA_SHT_THIS_ID, 205 .this_id = ATA_SHT_THIS_ID,
207 .sg_tablesize = LIBATA_MAX_PRD, 206 .sg_tablesize = LIBATA_MAX_PRD,
@@ -280,7 +279,7 @@ static irqreturn_t nv_interrupt (int irq, void *dev_instance,
280 279
281 ap = host_set->ports[i]; 280 ap = host_set->ports[i];
282 if (ap && 281 if (ap &&
283 !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { 282 !(ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR))) {
284 struct ata_queued_cmd *qc; 283 struct ata_queued_cmd *qc;
285 284
286 qc = ata_qc_from_tag(ap, ap->active_tag); 285 qc = ata_qc_from_tag(ap, ap->active_tag);
diff --git a/drivers/scsi/sata_promise.c b/drivers/scsi/sata_promise.c
index cc928c68a479..ddbc0c6dd9fe 100644
--- a/drivers/scsi/sata_promise.c
+++ b/drivers/scsi/sata_promise.c
@@ -111,7 +111,6 @@ static struct scsi_host_template pdc_ata_sht = {
111 .name = DRV_NAME, 111 .name = DRV_NAME,
112 .ioctl = ata_scsi_ioctl, 112 .ioctl = ata_scsi_ioctl,
113 .queuecommand = ata_scsi_queuecmd, 113 .queuecommand = ata_scsi_queuecmd,
114 .eh_strategy_handler = ata_scsi_error,
115 .can_queue = ATA_DEF_QUEUE, 114 .can_queue = ATA_DEF_QUEUE,
116 .this_id = ATA_SHT_THIS_ID, 115 .this_id = ATA_SHT_THIS_ID,
117 .sg_tablesize = LIBATA_MAX_PRD, 116 .sg_tablesize = LIBATA_MAX_PRD,
@@ -534,7 +533,7 @@ static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *r
534 ap = host_set->ports[i]; 533 ap = host_set->ports[i];
535 tmp = mask & (1 << (i + 1)); 534 tmp = mask & (1 << (i + 1));
536 if (tmp && ap && 535 if (tmp && ap &&
537 !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { 536 !(ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR))) {
538 struct ata_queued_cmd *qc; 537 struct ata_queued_cmd *qc;
539 538
540 qc = ata_qc_from_tag(ap, ap->active_tag); 539 qc = ata_qc_from_tag(ap, ap->active_tag);
@@ -677,10 +676,6 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
677 if (!printed_version++) 676 if (!printed_version++)
678 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 677 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
679 678
680 /*
681 * If this driver happens to only be useful on Apple's K2, then
682 * we should check that here as it has a normal Serverworks ID
683 */
684 rc = pci_enable_device(pdev); 679 rc = pci_enable_device(pdev);
685 if (rc) 680 if (rc)
686 return rc; 681 return rc;
diff --git a/drivers/scsi/sata_qstor.c b/drivers/scsi/sata_qstor.c
index 9ffe1ef0d205..259c2dec4e21 100644
--- a/drivers/scsi/sata_qstor.c
+++ b/drivers/scsi/sata_qstor.c
@@ -41,7 +41,7 @@
41#include <linux/libata.h> 41#include <linux/libata.h>
42 42
43#define DRV_NAME "sata_qstor" 43#define DRV_NAME "sata_qstor"
44#define DRV_VERSION "0.05" 44#define DRV_VERSION "0.06"
45 45
46enum { 46enum {
47 QS_PORTS = 4, 47 QS_PORTS = 4,
@@ -132,7 +132,6 @@ static struct scsi_host_template qs_ata_sht = {
132 .name = DRV_NAME, 132 .name = DRV_NAME,
133 .ioctl = ata_scsi_ioctl, 133 .ioctl = ata_scsi_ioctl,
134 .queuecommand = ata_scsi_queuecmd, 134 .queuecommand = ata_scsi_queuecmd,
135 .eh_strategy_handler = ata_scsi_error,
136 .can_queue = ATA_DEF_QUEUE, 135 .can_queue = ATA_DEF_QUEUE,
137 .this_id = ATA_SHT_THIS_ID, 136 .this_id = ATA_SHT_THIS_ID,
138 .sg_tablesize = QS_MAX_PRD, 137 .sg_tablesize = QS_MAX_PRD,
@@ -396,7 +395,7 @@ static inline unsigned int qs_intr_pkt(struct ata_host_set *host_set)
396 sff1, sff0, port_no, sHST, sDST); 395 sff1, sff0, port_no, sHST, sDST);
397 handled = 1; 396 handled = 1;
398 if (ap && !(ap->flags & 397 if (ap && !(ap->flags &
399 (ATA_FLAG_PORT_DISABLED|ATA_FLAG_NOINTR))) { 398 (ATA_FLAG_DISABLED|ATA_FLAG_NOINTR))) {
400 struct ata_queued_cmd *qc; 399 struct ata_queued_cmd *qc;
401 struct qs_port_priv *pp = ap->private_data; 400 struct qs_port_priv *pp = ap->private_data;
402 if (!pp || pp->state != qs_state_pkt) 401 if (!pp || pp->state != qs_state_pkt)
@@ -429,7 +428,7 @@ static inline unsigned int qs_intr_mmio(struct ata_host_set *host_set)
429 struct ata_port *ap; 428 struct ata_port *ap;
430 ap = host_set->ports[port_no]; 429 ap = host_set->ports[port_no];
431 if (ap && 430 if (ap &&
432 !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { 431 !(ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR))) {
433 struct ata_queued_cmd *qc; 432 struct ata_queued_cmd *qc;
434 struct qs_port_priv *pp = ap->private_data; 433 struct qs_port_priv *pp = ap->private_data;
435 if (!pp || pp->state != qs_state_mmio) 434 if (!pp || pp->state != qs_state_mmio)
diff --git a/drivers/scsi/sata_sil.c b/drivers/scsi/sata_sil.c
index 18c296c56899..c9333577330e 100644
--- a/drivers/scsi/sata_sil.c
+++ b/drivers/scsi/sata_sil.c
@@ -46,7 +46,7 @@
46#include <linux/libata.h> 46#include <linux/libata.h>
47 47
48#define DRV_NAME "sata_sil" 48#define DRV_NAME "sata_sil"
49#define DRV_VERSION "0.9" 49#define DRV_VERSION "1.0"
50 50
51enum { 51enum {
52 /* 52 /*
@@ -146,7 +146,6 @@ static struct scsi_host_template sil_sht = {
146 .name = DRV_NAME, 146 .name = DRV_NAME,
147 .ioctl = ata_scsi_ioctl, 147 .ioctl = ata_scsi_ioctl,
148 .queuecommand = ata_scsi_queuecmd, 148 .queuecommand = ata_scsi_queuecmd,
149 .eh_strategy_handler = ata_scsi_error,
150 .can_queue = ATA_DEF_QUEUE, 149 .can_queue = ATA_DEF_QUEUE,
151 .this_id = ATA_SHT_THIS_ID, 150 .this_id = ATA_SHT_THIS_ID,
152 .sg_tablesize = LIBATA_MAX_PRD, 151 .sg_tablesize = LIBATA_MAX_PRD,
@@ -264,7 +263,7 @@ static void sil_post_set_mode (struct ata_port *ap)
264 263
265 for (i = 0; i < 2; i++) { 264 for (i = 0; i < 2; i++) {
266 dev = &ap->device[i]; 265 dev = &ap->device[i];
267 if (!ata_dev_present(dev)) 266 if (!ata_dev_enabled(dev))
268 dev_mode[i] = 0; /* PIO0/1/2 */ 267 dev_mode[i] = 0; /* PIO0/1/2 */
269 else if (dev->flags & ATA_DFLAG_PIO) 268 else if (dev->flags & ATA_DFLAG_PIO)
270 dev_mode[i] = 1; /* PIO3/4 */ 269 dev_mode[i] = 1; /* PIO3/4 */
@@ -391,10 +390,6 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
391 if (!printed_version++) 390 if (!printed_version++)
392 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 391 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
393 392
394 /*
395 * If this driver happens to only be useful on Apple's K2, then
396 * we should check that here as it has a normal Serverworks ID
397 */
398 rc = pci_enable_device(pdev); 393 rc = pci_enable_device(pdev);
399 if (rc) 394 if (rc)
400 return rc; 395 return rc;
diff --git a/drivers/scsi/sata_sil24.c b/drivers/scsi/sata_sil24.c
index 068c98a4111b..e9fd869140c5 100644
--- a/drivers/scsi/sata_sil24.c
+++ b/drivers/scsi/sata_sil24.c
@@ -31,7 +31,7 @@
31#include <asm/io.h> 31#include <asm/io.h>
32 32
33#define DRV_NAME "sata_sil24" 33#define DRV_NAME "sata_sil24"
34#define DRV_VERSION "0.23" 34#define DRV_VERSION "0.24"
35 35
36/* 36/*
37 * Port request block (PRB) 32 bytes 37 * Port request block (PRB) 32 bytes
@@ -86,6 +86,13 @@ enum {
86 /* HOST_SLOT_STAT bits */ 86 /* HOST_SLOT_STAT bits */
87 HOST_SSTAT_ATTN = (1 << 31), 87 HOST_SSTAT_ATTN = (1 << 31),
88 88
89 /* HOST_CTRL bits */
90 HOST_CTRL_M66EN = (1 << 16), /* M66EN PCI bus signal */
91 HOST_CTRL_TRDY = (1 << 17), /* latched PCI TRDY */
92 HOST_CTRL_STOP = (1 << 18), /* latched PCI STOP */
93 HOST_CTRL_DEVSEL = (1 << 19), /* latched PCI DEVSEL */
94 HOST_CTRL_REQ64 = (1 << 20), /* latched PCI REQ64 */
95
89 /* 96 /*
90 * Port registers 97 * Port registers
91 * (8192 bytes @ +0x0000, +0x2000, +0x4000 and +0x6000 @ BAR2) 98 * (8192 bytes @ +0x0000, +0x2000, +0x4000 and +0x6000 @ BAR2)
@@ -142,8 +149,12 @@ enum {
142 PORT_IRQ_PWR_CHG = (1 << 3), /* power management change */ 149 PORT_IRQ_PWR_CHG = (1 << 3), /* power management change */
143 PORT_IRQ_PHYRDY_CHG = (1 << 4), /* PHY ready change */ 150 PORT_IRQ_PHYRDY_CHG = (1 << 4), /* PHY ready change */
144 PORT_IRQ_COMWAKE = (1 << 5), /* COMWAKE received */ 151 PORT_IRQ_COMWAKE = (1 << 5), /* COMWAKE received */
145 PORT_IRQ_UNK_FIS = (1 << 6), /* Unknown FIS received */ 152 PORT_IRQ_UNK_FIS = (1 << 6), /* unknown FIS received */
146 PORT_IRQ_SDB_FIS = (1 << 11), /* SDB FIS received */ 153 PORT_IRQ_DEV_XCHG = (1 << 7), /* device exchanged */
154 PORT_IRQ_8B10B = (1 << 8), /* 8b/10b decode error threshold */
155 PORT_IRQ_CRC = (1 << 9), /* CRC error threshold */
156 PORT_IRQ_HANDSHAKE = (1 << 10), /* handshake error threshold */
157 PORT_IRQ_SDB_NOTIFY = (1 << 11), /* SDB notify received */
147 158
148 /* bits[27:16] are unmasked (raw) */ 159 /* bits[27:16] are unmasked (raw) */
149 PORT_IRQ_RAW_SHIFT = 16, 160 PORT_IRQ_RAW_SHIFT = 16,
@@ -174,7 +185,7 @@ enum {
174 PORT_CERR_CMD_PCIPERR = 27, /* ctrl[15:13] 110 - PCI parity err while fetching PRB */ 185 PORT_CERR_CMD_PCIPERR = 27, /* ctrl[15:13] 110 - PCI parity err while fetching PRB */
175 PORT_CERR_XFR_UNDEF = 32, /* PSD ecode 00 - undefined */ 186 PORT_CERR_XFR_UNDEF = 32, /* PSD ecode 00 - undefined */
176 PORT_CERR_XFR_TGTABRT = 33, /* PSD ecode 01 - target abort */ 187 PORT_CERR_XFR_TGTABRT = 33, /* PSD ecode 01 - target abort */
177 PORT_CERR_XFR_MSGABRT = 34, /* PSD ecode 10 - master abort */ 188 PORT_CERR_XFR_MSTABRT = 34, /* PSD ecode 10 - master abort */
178 PORT_CERR_XFR_PCIPERR = 35, /* PSD ecode 11 - PCI prity err during transfer */ 189 PORT_CERR_XFR_PCIPERR = 35, /* PSD ecode 11 - PCI prity err during transfer */
179 PORT_CERR_SENDSERVICE = 36, /* FIS received while sending service */ 190 PORT_CERR_SENDSERVICE = 36, /* FIS received while sending service */
180 191
@@ -207,6 +218,11 @@ enum {
207 BID_SIL3132 = 1, 218 BID_SIL3132 = 1,
208 BID_SIL3131 = 2, 219 BID_SIL3131 = 2,
209 220
221 /* host flags */
222 SIL24_COMMON_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
223 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA,
224 SIL24_FLAG_PCIX_IRQ_WOC = (1 << 24), /* IRQ loss errata on PCI-X */
225
210 IRQ_STAT_4PORTS = 0xf, 226 IRQ_STAT_4PORTS = 0xf,
211}; 227};
212 228
@@ -281,7 +297,6 @@ static struct scsi_host_template sil24_sht = {
281 .name = DRV_NAME, 297 .name = DRV_NAME,
282 .ioctl = ata_scsi_ioctl, 298 .ioctl = ata_scsi_ioctl,
283 .queuecommand = ata_scsi_queuecmd, 299 .queuecommand = ata_scsi_queuecmd,
284 .eh_strategy_handler = ata_scsi_error,
285 .can_queue = ATA_DEF_QUEUE, 300 .can_queue = ATA_DEF_QUEUE,
286 .this_id = ATA_SHT_THIS_ID, 301 .this_id = ATA_SHT_THIS_ID,
287 .sg_tablesize = LIBATA_MAX_PRD, 302 .sg_tablesize = LIBATA_MAX_PRD,
@@ -334,9 +349,8 @@ static struct ata_port_info sil24_port_info[] = {
334 /* sil_3124 */ 349 /* sil_3124 */
335 { 350 {
336 .sht = &sil24_sht, 351 .sht = &sil24_sht,
337 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 352 .host_flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(4) |
338 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA | 353 SIL24_FLAG_PCIX_IRQ_WOC,
339 SIL24_NPORTS2FLAG(4),
340 .pio_mask = 0x1f, /* pio0-4 */ 354 .pio_mask = 0x1f, /* pio0-4 */
341 .mwdma_mask = 0x07, /* mwdma0-2 */ 355 .mwdma_mask = 0x07, /* mwdma0-2 */
342 .udma_mask = 0x3f, /* udma0-5 */ 356 .udma_mask = 0x3f, /* udma0-5 */
@@ -345,9 +359,7 @@ static struct ata_port_info sil24_port_info[] = {
345 /* sil_3132 */ 359 /* sil_3132 */
346 { 360 {
347 .sht = &sil24_sht, 361 .sht = &sil24_sht,
348 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 362 .host_flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(2),
349 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
350 SIL24_NPORTS2FLAG(2),
351 .pio_mask = 0x1f, /* pio0-4 */ 363 .pio_mask = 0x1f, /* pio0-4 */
352 .mwdma_mask = 0x07, /* mwdma0-2 */ 364 .mwdma_mask = 0x07, /* mwdma0-2 */
353 .udma_mask = 0x3f, /* udma0-5 */ 365 .udma_mask = 0x3f, /* udma0-5 */
@@ -356,9 +368,7 @@ static struct ata_port_info sil24_port_info[] = {
356 /* sil_3131/sil_3531 */ 368 /* sil_3131/sil_3531 */
357 { 369 {
358 .sht = &sil24_sht, 370 .sht = &sil24_sht,
359 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 371 .host_flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(1),
360 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
361 SIL24_NPORTS2FLAG(1),
362 .pio_mask = 0x1f, /* pio0-4 */ 372 .pio_mask = 0x1f, /* pio0-4 */
363 .mwdma_mask = 0x07, /* mwdma0-2 */ 373 .mwdma_mask = 0x07, /* mwdma0-2 */
364 .udma_mask = 0x3f, /* udma0-5 */ 374 .udma_mask = 0x3f, /* udma0-5 */
@@ -427,15 +437,30 @@ static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
427 *tf = pp->tf; 437 *tf = pp->tf;
428} 438}
429 439
430static int sil24_softreset(struct ata_port *ap, int verbose, 440static int sil24_init_port(struct ata_port *ap)
431 unsigned int *class) 441{
442 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
443 u32 tmp;
444
445 writel(PORT_CS_INIT, port + PORT_CTRL_STAT);
446 ata_wait_register(port + PORT_CTRL_STAT,
447 PORT_CS_INIT, PORT_CS_INIT, 10, 100);
448 tmp = ata_wait_register(port + PORT_CTRL_STAT,
449 PORT_CS_RDY, 0, 10, 100);
450
451 if ((tmp & (PORT_CS_INIT | PORT_CS_RDY)) != PORT_CS_RDY)
452 return -EIO;
453 return 0;
454}
455
456static int sil24_softreset(struct ata_port *ap, unsigned int *class)
432{ 457{
433 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 458 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
434 struct sil24_port_priv *pp = ap->private_data; 459 struct sil24_port_priv *pp = ap->private_data;
435 struct sil24_prb *prb = &pp->cmd_block[0].ata.prb; 460 struct sil24_prb *prb = &pp->cmd_block[0].ata.prb;
436 dma_addr_t paddr = pp->cmd_block_dma; 461 dma_addr_t paddr = pp->cmd_block_dma;
437 unsigned long timeout = jiffies + ATA_TMOUT_BOOT * HZ; 462 u32 mask, irq_enable, irq_stat;
438 u32 irq_enable, irq_stat; 463 const char *reason;
439 464
440 DPRINTK("ENTER\n"); 465 DPRINTK("ENTER\n");
441 466
@@ -449,34 +474,35 @@ static int sil24_softreset(struct ata_port *ap, int verbose,
449 irq_enable = readl(port + PORT_IRQ_ENABLE_SET); 474 irq_enable = readl(port + PORT_IRQ_ENABLE_SET);
450 writel(irq_enable, port + PORT_IRQ_ENABLE_CLR); 475 writel(irq_enable, port + PORT_IRQ_ENABLE_CLR);
451 476
452 /* 477 /* put the port into known state */
453 * XXX: Not sure whether the following sleep is needed or not. 478 if (sil24_init_port(ap)) {
454 * The original driver had it. So.... 479 reason ="port not ready";
455 */ 480 goto err;
456 msleep(10); 481 }
457 482
458 prb->ctrl = PRB_CTRL_SRST; 483 /* do SRST */
484 prb->ctrl = cpu_to_le16(PRB_CTRL_SRST);
459 prb->fis[1] = 0; /* no PM yet */ 485 prb->fis[1] = 0; /* no PM yet */
460 486
461 writel((u32)paddr, port + PORT_CMD_ACTIVATE); 487 writel((u32)paddr, port + PORT_CMD_ACTIVATE);
488 writel((u64)paddr >> 32, port + PORT_CMD_ACTIVATE + 4);
462 489
463 do { 490 mask = (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR) << PORT_IRQ_RAW_SHIFT;
464 irq_stat = readl(port + PORT_IRQ_STAT); 491 irq_stat = ata_wait_register(port + PORT_IRQ_STAT, mask, 0x0,
465 writel(irq_stat, port + PORT_IRQ_STAT); /* clear irq */ 492 100, ATA_TMOUT_BOOT / HZ * 1000);
466
467 irq_stat >>= PORT_IRQ_RAW_SHIFT;
468 if (irq_stat & (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR))
469 break;
470 493
471 msleep(100); 494 writel(irq_stat, port + PORT_IRQ_STAT); /* clear IRQs */
472 } while (time_before(jiffies, timeout)); 495 irq_stat >>= PORT_IRQ_RAW_SHIFT;
473 496
474 /* restore IRQs */ 497 /* restore IRQs */
475 writel(irq_enable, port + PORT_IRQ_ENABLE_SET); 498 writel(irq_enable, port + PORT_IRQ_ENABLE_SET);
476 499
477 if (!(irq_stat & PORT_IRQ_COMPLETE)) { 500 if (!(irq_stat & PORT_IRQ_COMPLETE)) {
478 DPRINTK("EXIT, srst failed\n"); 501 if (irq_stat & PORT_IRQ_ERROR)
479 return -EIO; 502 reason = "SRST command error";
503 else
504 reason = "timeout";
505 goto err;
480 } 506 }
481 507
482 sil24_update_tf(ap); 508 sil24_update_tf(ap);
@@ -488,15 +514,55 @@ static int sil24_softreset(struct ata_port *ap, int verbose,
488 out: 514 out:
489 DPRINTK("EXIT, class=%u\n", *class); 515 DPRINTK("EXIT, class=%u\n", *class);
490 return 0; 516 return 0;
517
518 err:
519 printk(KERN_ERR "ata%u: softreset failed (%s)\n", ap->id, reason);
520 return -EIO;
491} 521}
492 522
493static int sil24_hardreset(struct ata_port *ap, int verbose, 523static int sil24_hardreset(struct ata_port *ap, unsigned int *class)
494 unsigned int *class)
495{ 524{
496 unsigned int dummy_class; 525 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
526 const char *reason;
527 int tout_msec;
528 u32 tmp;
529
530 /* sil24 does the right thing(tm) without any protection */
531 ata_set_sata_spd(ap);
532
533 tout_msec = 100;
534 if (sata_dev_present(ap))
535 tout_msec = 5000;
497 536
498 /* sil24 doesn't report device signature after hard reset */ 537 writel(PORT_CS_DEV_RST, port + PORT_CTRL_STAT);
499 return sata_std_hardreset(ap, verbose, &dummy_class); 538 tmp = ata_wait_register(port + PORT_CTRL_STAT,
539 PORT_CS_DEV_RST, PORT_CS_DEV_RST, 10, tout_msec);
540
541 /* SStatus oscillates between zero and valid status for short
542 * duration after DEV_RST, give it time to settle.
543 */
544 msleep(100);
545
546 if (tmp & PORT_CS_DEV_RST) {
547 if (!sata_dev_present(ap))
548 return 0;
549 reason = "link not ready";
550 goto err;
551 }
552
553 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) {
554 reason = "device not ready";
555 goto err;
556 }
557
558 /* sil24 doesn't report device class code after hardreset,
559 * leave *class alone.
560 */
561 return 0;
562
563 err:
564 printk(KERN_ERR "ata%u: hardreset failed (%s)\n", ap->id, reason);
565 return -EIO;
500} 566}
501 567
502static int sil24_probe_reset(struct ata_port *ap, unsigned int *classes) 568static int sil24_probe_reset(struct ata_port *ap, unsigned int *classes)
@@ -532,6 +598,7 @@ static void sil24_qc_prep(struct ata_queued_cmd *qc)
532 union sil24_cmd_block *cb = pp->cmd_block + qc->tag; 598 union sil24_cmd_block *cb = pp->cmd_block + qc->tag;
533 struct sil24_prb *prb; 599 struct sil24_prb *prb;
534 struct sil24_sge *sge; 600 struct sil24_sge *sge;
601 u16 ctrl = 0;
535 602
536 switch (qc->tf.protocol) { 603 switch (qc->tf.protocol) {
537 case ATA_PROT_PIO: 604 case ATA_PROT_PIO:
@@ -539,7 +606,6 @@ static void sil24_qc_prep(struct ata_queued_cmd *qc)
539 case ATA_PROT_NODATA: 606 case ATA_PROT_NODATA:
540 prb = &cb->ata.prb; 607 prb = &cb->ata.prb;
541 sge = cb->ata.sge; 608 sge = cb->ata.sge;
542 prb->ctrl = 0;
543 break; 609 break;
544 610
545 case ATA_PROT_ATAPI: 611 case ATA_PROT_ATAPI:
@@ -552,12 +618,10 @@ static void sil24_qc_prep(struct ata_queued_cmd *qc)
552 618
553 if (qc->tf.protocol != ATA_PROT_ATAPI_NODATA) { 619 if (qc->tf.protocol != ATA_PROT_ATAPI_NODATA) {
554 if (qc->tf.flags & ATA_TFLAG_WRITE) 620 if (qc->tf.flags & ATA_TFLAG_WRITE)
555 prb->ctrl = PRB_CTRL_PACKET_WRITE; 621 ctrl = PRB_CTRL_PACKET_WRITE;
556 else 622 else
557 prb->ctrl = PRB_CTRL_PACKET_READ; 623 ctrl = PRB_CTRL_PACKET_READ;
558 } else 624 }
559 prb->ctrl = 0;
560
561 break; 625 break;
562 626
563 default: 627 default:
@@ -566,6 +630,7 @@ static void sil24_qc_prep(struct ata_queued_cmd *qc)
566 BUG(); 630 BUG();
567 } 631 }
568 632
633 prb->ctrl = cpu_to_le16(ctrl);
569 ata_tf_to_fis(&qc->tf, prb->fis, 0); 634 ata_tf_to_fis(&qc->tf, prb->fis, 0);
570 635
571 if (qc->flags & ATA_QCFLAG_DMAMAP) 636 if (qc->flags & ATA_QCFLAG_DMAMAP)
@@ -580,6 +645,8 @@ static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc)
580 dma_addr_t paddr = pp->cmd_block_dma + qc->tag * sizeof(*pp->cmd_block); 645 dma_addr_t paddr = pp->cmd_block_dma + qc->tag * sizeof(*pp->cmd_block);
581 646
582 writel((u32)paddr, port + PORT_CMD_ACTIVATE); 647 writel((u32)paddr, port + PORT_CMD_ACTIVATE);
648 writel((u64)paddr >> 32, port + PORT_CMD_ACTIVATE + 4);
649
583 return 0; 650 return 0;
584} 651}
585 652
@@ -728,6 +795,10 @@ static inline void sil24_host_intr(struct ata_port *ap)
728 slot_stat = readl(port + PORT_SLOT_STAT); 795 slot_stat = readl(port + PORT_SLOT_STAT);
729 if (!(slot_stat & HOST_SSTAT_ATTN)) { 796 if (!(slot_stat & HOST_SSTAT_ATTN)) {
730 struct sil24_port_priv *pp = ap->private_data; 797 struct sil24_port_priv *pp = ap->private_data;
798
799 if (ap->flags & SIL24_FLAG_PCIX_IRQ_WOC)
800 writel(PORT_IRQ_COMPLETE, port + PORT_IRQ_STAT);
801
731 /* 802 /*
732 * !HOST_SSAT_ATTN guarantees successful completion, 803 * !HOST_SSAT_ATTN guarantees successful completion,
733 * so reading back tf registers is unnecessary for 804 * so reading back tf registers is unnecessary for
@@ -770,7 +841,7 @@ static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *
770 for (i = 0; i < host_set->n_ports; i++) 841 for (i = 0; i < host_set->n_ports; i++)
771 if (status & (1 << i)) { 842 if (status & (1 << i)) {
772 struct ata_port *ap = host_set->ports[i]; 843 struct ata_port *ap = host_set->ports[i];
773 if (ap && !(ap->flags & ATA_FLAG_PORT_DISABLED)) { 844 if (ap && !(ap->flags & ATA_FLAG_DISABLED)) {
774 sil24_host_intr(host_set->ports[i]); 845 sil24_host_intr(host_set->ports[i]);
775 handled++; 846 handled++;
776 } else 847 } else
@@ -859,6 +930,7 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
859 void __iomem *host_base = NULL; 930 void __iomem *host_base = NULL;
860 void __iomem *port_base = NULL; 931 void __iomem *port_base = NULL;
861 int i, rc; 932 int i, rc;
933 u32 tmp;
862 934
863 if (!printed_version++) 935 if (!printed_version++)
864 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 936 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
@@ -911,35 +983,51 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
911 /* 983 /*
912 * Configure the device 984 * Configure the device
913 */ 985 */
914 /* 986 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
915 * FIXME: This device is certainly 64-bit capable. We just 987 rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
916 * don't know how to use it. After fixing 32bit activation in 988 if (rc) {
917 * this function, enable 64bit masks here. 989 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
918 */ 990 if (rc) {
919 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 991 dev_printk(KERN_ERR, &pdev->dev,
920 if (rc) { 992 "64-bit DMA enable failed\n");
921 dev_printk(KERN_ERR, &pdev->dev, 993 goto out_free;
922 "32-bit DMA enable failed\n"); 994 }
923 goto out_free; 995 }
924 } 996 } else {
925 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 997 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
926 if (rc) { 998 if (rc) {
927 dev_printk(KERN_ERR, &pdev->dev, 999 dev_printk(KERN_ERR, &pdev->dev,
928 "32-bit consistent DMA enable failed\n"); 1000 "32-bit DMA enable failed\n");
929 goto out_free; 1001 goto out_free;
1002 }
1003 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
1004 if (rc) {
1005 dev_printk(KERN_ERR, &pdev->dev,
1006 "32-bit consistent DMA enable failed\n");
1007 goto out_free;
1008 }
930 } 1009 }
931 1010
932 /* GPIO off */ 1011 /* GPIO off */
933 writel(0, host_base + HOST_FLASH_CMD); 1012 writel(0, host_base + HOST_FLASH_CMD);
934 1013
935 /* Mask interrupts during initialization */ 1014 /* Apply workaround for completion IRQ loss on PCI-X errata */
1015 if (probe_ent->host_flags & SIL24_FLAG_PCIX_IRQ_WOC) {
1016 tmp = readl(host_base + HOST_CTRL);
1017 if (tmp & (HOST_CTRL_TRDY | HOST_CTRL_STOP | HOST_CTRL_DEVSEL))
1018 dev_printk(KERN_INFO, &pdev->dev,
1019 "Applying completion IRQ loss on PCI-X "
1020 "errata fix\n");
1021 else
1022 probe_ent->host_flags &= ~SIL24_FLAG_PCIX_IRQ_WOC;
1023 }
1024
1025 /* clear global reset & mask interrupts during initialization */
936 writel(0, host_base + HOST_CTRL); 1026 writel(0, host_base + HOST_CTRL);
937 1027
938 for (i = 0; i < probe_ent->n_ports; i++) { 1028 for (i = 0; i < probe_ent->n_ports; i++) {
939 void __iomem *port = port_base + i * PORT_REGS_SIZE; 1029 void __iomem *port = port_base + i * PORT_REGS_SIZE;
940 unsigned long portu = (unsigned long)port; 1030 unsigned long portu = (unsigned long)port;
941 u32 tmp;
942 int cnt;
943 1031
944 probe_ent->port[i].cmd_addr = portu + PORT_PRB; 1032 probe_ent->port[i].cmd_addr = portu + PORT_PRB;
945 probe_ent->port[i].scr_addr = portu + PORT_SCONTROL; 1033 probe_ent->port[i].scr_addr = portu + PORT_SCONTROL;
@@ -953,18 +1041,20 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
953 tmp = readl(port + PORT_CTRL_STAT); 1041 tmp = readl(port + PORT_CTRL_STAT);
954 if (tmp & PORT_CS_PORT_RST) { 1042 if (tmp & PORT_CS_PORT_RST) {
955 writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR); 1043 writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR);
956 readl(port + PORT_CTRL_STAT); /* sync */ 1044 tmp = ata_wait_register(port + PORT_CTRL_STAT,
957 for (cnt = 0; cnt < 10; cnt++) { 1045 PORT_CS_PORT_RST,
958 msleep(10); 1046 PORT_CS_PORT_RST, 10, 100);
959 tmp = readl(port + PORT_CTRL_STAT);
960 if (!(tmp & PORT_CS_PORT_RST))
961 break;
962 }
963 if (tmp & PORT_CS_PORT_RST) 1047 if (tmp & PORT_CS_PORT_RST)
964 dev_printk(KERN_ERR, &pdev->dev, 1048 dev_printk(KERN_ERR, &pdev->dev,
965 "failed to clear port RST\n"); 1049 "failed to clear port RST\n");
966 } 1050 }
967 1051
1052 /* Configure IRQ WoC */
1053 if (probe_ent->host_flags & SIL24_FLAG_PCIX_IRQ_WOC)
1054 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_STAT);
1055 else
1056 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_CLR);
1057
968 /* Zero error counters. */ 1058 /* Zero error counters. */
969 writel(0x8000, port + PORT_DECODE_ERR_THRESH); 1059 writel(0x8000, port + PORT_DECODE_ERR_THRESH);
970 writel(0x8000, port + PORT_CRC_ERR_THRESH); 1060 writel(0x8000, port + PORT_CRC_ERR_THRESH);
@@ -973,14 +1063,13 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
973 writel(0x0000, port + PORT_CRC_ERR_CNT); 1063 writel(0x0000, port + PORT_CRC_ERR_CNT);
974 writel(0x0000, port + PORT_HSHK_ERR_CNT); 1064 writel(0x0000, port + PORT_HSHK_ERR_CNT);
975 1065
976 /* FIXME: 32bit activation? */ 1066 /* Always use 64bit activation */
977 writel(0, port + PORT_ACTIVATE_UPPER_ADDR); 1067 writel(PORT_CS_32BIT_ACTV, port + PORT_CTRL_CLR);
978 writel(PORT_CS_32BIT_ACTV, port + PORT_CTRL_STAT);
979 1068
980 /* Configure interrupts */ 1069 /* Configure interrupts */
981 writel(0xffff, port + PORT_IRQ_ENABLE_CLR); 1070 writel(0xffff, port + PORT_IRQ_ENABLE_CLR);
982 writel(PORT_IRQ_COMPLETE | PORT_IRQ_ERROR | PORT_IRQ_SDB_FIS, 1071 writel(PORT_IRQ_COMPLETE | PORT_IRQ_ERROR |
983 port + PORT_IRQ_ENABLE_SET); 1072 PORT_IRQ_SDB_NOTIFY, port + PORT_IRQ_ENABLE_SET);
984 1073
985 /* Clear interrupts */ 1074 /* Clear interrupts */
986 writel(0x0fff0fff, port + PORT_IRQ_STAT); 1075 writel(0x0fff0fff, port + PORT_IRQ_STAT);
@@ -988,11 +1077,6 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
988 1077
989 /* Clear port multiplier enable and resume bits */ 1078 /* Clear port multiplier enable and resume bits */
990 writel(PORT_CS_PM_EN | PORT_CS_RESUME, port + PORT_CTRL_CLR); 1079 writel(PORT_CS_PM_EN | PORT_CS_RESUME, port + PORT_CTRL_CLR);
991
992 /* Reset itself */
993 if (__sil24_reset_controller(port))
994 dev_printk(KERN_ERR, &pdev->dev,
995 "failed to reset controller\n");
996 } 1080 }
997 1081
998 /* Turn on interrupts */ 1082 /* Turn on interrupts */
diff --git a/drivers/scsi/sata_sis.c b/drivers/scsi/sata_sis.c
index acc8439dea23..3097821688dc 100644
--- a/drivers/scsi/sata_sis.c
+++ b/drivers/scsi/sata_sis.c
@@ -43,7 +43,7 @@
43#include <linux/libata.h> 43#include <linux/libata.h>
44 44
45#define DRV_NAME "sata_sis" 45#define DRV_NAME "sata_sis"
46#define DRV_VERSION "0.5" 46#define DRV_VERSION "0.6"
47 47
48enum { 48enum {
49 sis_180 = 0, 49 sis_180 = 0,
@@ -87,7 +87,6 @@ static struct scsi_host_template sis_sht = {
87 .name = DRV_NAME, 87 .name = DRV_NAME,
88 .ioctl = ata_scsi_ioctl, 88 .ioctl = ata_scsi_ioctl,
89 .queuecommand = ata_scsi_queuecmd, 89 .queuecommand = ata_scsi_queuecmd,
90 .eh_strategy_handler = ata_scsi_error,
91 .can_queue = ATA_DEF_QUEUE, 90 .can_queue = ATA_DEF_QUEUE,
92 .this_id = ATA_SHT_THIS_ID, 91 .this_id = ATA_SHT_THIS_ID,
93 .sg_tablesize = ATA_MAX_PRD, 92 .sg_tablesize = ATA_MAX_PRD,
diff --git a/drivers/scsi/sata_svw.c b/drivers/scsi/sata_svw.c
index 724f0ed6a52d..d5eb5375e265 100644
--- a/drivers/scsi/sata_svw.c
+++ b/drivers/scsi/sata_svw.c
@@ -54,7 +54,7 @@
54#endif /* CONFIG_PPC_OF */ 54#endif /* CONFIG_PPC_OF */
55 55
56#define DRV_NAME "sata_svw" 56#define DRV_NAME "sata_svw"
57#define DRV_VERSION "1.07" 57#define DRV_VERSION "1.8"
58 58
59enum { 59enum {
60 /* Taskfile registers offsets */ 60 /* Taskfile registers offsets */
@@ -257,7 +257,7 @@ static int k2_sata_proc_info(struct Scsi_Host *shost, char *page, char **start,
257 int len, index; 257 int len, index;
258 258
259 /* Find the ata_port */ 259 /* Find the ata_port */
260 ap = (struct ata_port *) &shost->hostdata[0]; 260 ap = ata_shost_to_port(shost);
261 if (ap == NULL) 261 if (ap == NULL)
262 return 0; 262 return 0;
263 263
@@ -290,7 +290,6 @@ static struct scsi_host_template k2_sata_sht = {
290 .name = DRV_NAME, 290 .name = DRV_NAME,
291 .ioctl = ata_scsi_ioctl, 291 .ioctl = ata_scsi_ioctl,
292 .queuecommand = ata_scsi_queuecmd, 292 .queuecommand = ata_scsi_queuecmd,
293 .eh_strategy_handler = ata_scsi_error,
294 .can_queue = ATA_DEF_QUEUE, 293 .can_queue = ATA_DEF_QUEUE,
295 .this_id = ATA_SHT_THIS_ID, 294 .this_id = ATA_SHT_THIS_ID,
296 .sg_tablesize = LIBATA_MAX_PRD, 295 .sg_tablesize = LIBATA_MAX_PRD,
diff --git a/drivers/scsi/sata_sx4.c b/drivers/scsi/sata_sx4.c
index ae70f60c7c0d..a669d0589889 100644
--- a/drivers/scsi/sata_sx4.c
+++ b/drivers/scsi/sata_sx4.c
@@ -46,7 +46,7 @@
46#include "sata_promise.h" 46#include "sata_promise.h"
47 47
48#define DRV_NAME "sata_sx4" 48#define DRV_NAME "sata_sx4"
49#define DRV_VERSION "0.8" 49#define DRV_VERSION "0.9"
50 50
51 51
52enum { 52enum {
@@ -182,7 +182,6 @@ static struct scsi_host_template pdc_sata_sht = {
182 .name = DRV_NAME, 182 .name = DRV_NAME,
183 .ioctl = ata_scsi_ioctl, 183 .ioctl = ata_scsi_ioctl,
184 .queuecommand = ata_scsi_queuecmd, 184 .queuecommand = ata_scsi_queuecmd,
185 .eh_strategy_handler = ata_scsi_error,
186 .can_queue = ATA_DEF_QUEUE, 185 .can_queue = ATA_DEF_QUEUE,
187 .this_id = ATA_SHT_THIS_ID, 186 .this_id = ATA_SHT_THIS_ID,
188 .sg_tablesize = LIBATA_MAX_PRD, 187 .sg_tablesize = LIBATA_MAX_PRD,
@@ -834,7 +833,7 @@ static irqreturn_t pdc20621_interrupt (int irq, void *dev_instance, struct pt_re
834 tmp = mask & (1 << i); 833 tmp = mask & (1 << i);
835 VPRINTK("seq %u, port_no %u, ap %p, tmp %x\n", i, port_no, ap, tmp); 834 VPRINTK("seq %u, port_no %u, ap %p, tmp %x\n", i, port_no, ap, tmp);
836 if (tmp && ap && 835 if (tmp && ap &&
837 !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { 836 !(ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR))) {
838 struct ata_queued_cmd *qc; 837 struct ata_queued_cmd *qc;
839 838
840 qc = ata_qc_from_tag(ap, ap->active_tag); 839 qc = ata_qc_from_tag(ap, ap->active_tag);
@@ -1376,10 +1375,6 @@ static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *
1376 if (!printed_version++) 1375 if (!printed_version++)
1377 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 1376 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1378 1377
1379 /*
1380 * If this driver happens to only be useful on Apple's K2, then
1381 * we should check that here as it has a normal Serverworks ID
1382 */
1383 rc = pci_enable_device(pdev); 1378 rc = pci_enable_device(pdev);
1384 if (rc) 1379 if (rc)
1385 return rc; 1380 return rc;
diff --git a/drivers/scsi/sata_uli.c b/drivers/scsi/sata_uli.c
index 7ac5a5f5a905..15f81bfc30f0 100644
--- a/drivers/scsi/sata_uli.c
+++ b/drivers/scsi/sata_uli.c
@@ -37,7 +37,7 @@
37#include <linux/libata.h> 37#include <linux/libata.h>
38 38
39#define DRV_NAME "sata_uli" 39#define DRV_NAME "sata_uli"
40#define DRV_VERSION "0.5" 40#define DRV_VERSION "0.6"
41 41
42enum { 42enum {
43 uli_5289 = 0, 43 uli_5289 = 0,
@@ -81,7 +81,6 @@ static struct scsi_host_template uli_sht = {
81 .name = DRV_NAME, 81 .name = DRV_NAME,
82 .ioctl = ata_scsi_ioctl, 82 .ioctl = ata_scsi_ioctl,
83 .queuecommand = ata_scsi_queuecmd, 83 .queuecommand = ata_scsi_queuecmd,
84 .eh_strategy_handler = ata_scsi_error,
85 .can_queue = ATA_DEF_QUEUE, 84 .can_queue = ATA_DEF_QUEUE,
86 .this_id = ATA_SHT_THIS_ID, 85 .this_id = ATA_SHT_THIS_ID,
87 .sg_tablesize = LIBATA_MAX_PRD, 86 .sg_tablesize = LIBATA_MAX_PRD,
diff --git a/drivers/scsi/sata_via.c b/drivers/scsi/sata_via.c
index 791bf652ba63..17aefab5f42f 100644
--- a/drivers/scsi/sata_via.c
+++ b/drivers/scsi/sata_via.c
@@ -47,7 +47,7 @@
47#include <asm/io.h> 47#include <asm/io.h>
48 48
49#define DRV_NAME "sata_via" 49#define DRV_NAME "sata_via"
50#define DRV_VERSION "1.1" 50#define DRV_VERSION "1.2"
51 51
52enum board_ids_enum { 52enum board_ids_enum {
53 vt6420, 53 vt6420,
@@ -94,7 +94,6 @@ static struct scsi_host_template svia_sht = {
94 .name = DRV_NAME, 94 .name = DRV_NAME,
95 .ioctl = ata_scsi_ioctl, 95 .ioctl = ata_scsi_ioctl,
96 .queuecommand = ata_scsi_queuecmd, 96 .queuecommand = ata_scsi_queuecmd,
97 .eh_strategy_handler = ata_scsi_error,
98 .can_queue = ATA_DEF_QUEUE, 97 .can_queue = ATA_DEF_QUEUE,
99 .this_id = ATA_SHT_THIS_ID, 98 .this_id = ATA_SHT_THIS_ID,
100 .sg_tablesize = LIBATA_MAX_PRD, 99 .sg_tablesize = LIBATA_MAX_PRD,
diff --git a/drivers/scsi/sata_vsc.c b/drivers/scsi/sata_vsc.c
index 836bbbb26ff2..9646c3932129 100644
--- a/drivers/scsi/sata_vsc.c
+++ b/drivers/scsi/sata_vsc.c
@@ -222,7 +222,7 @@ static irqreturn_t vsc_sata_interrupt (int irq, void *dev_instance,
222 ap = host_set->ports[i]; 222 ap = host_set->ports[i];
223 223
224 if (ap && !(ap->flags & 224 if (ap && !(ap->flags &
225 (ATA_FLAG_PORT_DISABLED|ATA_FLAG_NOINTR))) { 225 (ATA_FLAG_DISABLED|ATA_FLAG_NOINTR))) {
226 struct ata_queued_cmd *qc; 226 struct ata_queued_cmd *qc;
227 227
228 qc = ata_qc_from_tag(ap, ap->active_tag); 228 qc = ata_qc_from_tag(ap, ap->active_tag);
@@ -263,7 +263,6 @@ static struct scsi_host_template vsc_sata_sht = {
263 .name = DRV_NAME, 263 .name = DRV_NAME,
264 .ioctl = ata_scsi_ioctl, 264 .ioctl = ata_scsi_ioctl,
265 .queuecommand = ata_scsi_queuecmd, 265 .queuecommand = ata_scsi_queuecmd,
266 .eh_strategy_handler = ata_scsi_error,
267 .can_queue = ATA_DEF_QUEUE, 266 .can_queue = ATA_DEF_QUEUE,
268 .this_id = ATA_SHT_THIS_ID, 267 .this_id = ATA_SHT_THIS_ID,
269 .sg_tablesize = LIBATA_MAX_PRD, 268 .sg_tablesize = LIBATA_MAX_PRD,
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 5f0fdfb2618c..1c75646f9689 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -1537,8 +1537,8 @@ int scsi_error_handler(void *data)
1537 * what we need to do to get it up and online again (if we can). 1537 * what we need to do to get it up and online again (if we can).
1538 * If we fail, we end up taking the thing offline. 1538 * If we fail, we end up taking the thing offline.
1539 */ 1539 */
1540 if (shost->hostt->eh_strategy_handler) 1540 if (shost->transportt->eh_strategy_handler)
1541 shost->hostt->eh_strategy_handler(shost); 1541 shost->transportt->eh_strategy_handler(shost);
1542 else 1542 else
1543 scsi_unjam_host(shost); 1543 scsi_unjam_host(shost);
1544 1544
diff --git a/drivers/scsi/zalon.c b/drivers/scsi/zalon.c
index b131432c677d..a6cfbb3b361c 100644
--- a/drivers/scsi/zalon.c
+++ b/drivers/scsi/zalon.c
@@ -88,7 +88,7 @@ zalon_probe(struct parisc_device *dev)
88 struct gsc_irq gsc_irq; 88 struct gsc_irq gsc_irq;
89 u32 zalon_vers; 89 u32 zalon_vers;
90 int error = -ENODEV; 90 int error = -ENODEV;
91 void __iomem *zalon = ioremap(dev->hpa.start, 4096); 91 void __iomem *zalon = ioremap_nocache(dev->hpa.start, 4096);
92 void __iomem *io_port = zalon + GSC_SCSI_ZALON_OFFSET; 92 void __iomem *io_port = zalon + GSC_SCSI_ZALON_OFFSET;
93 static int unit = 0; 93 static int unit = 0;
94 struct Scsi_Host *host; 94 struct Scsi_Host *host;