aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/ahci.c55
-rw-r--r--drivers/scsi/arm/scsi.h6
-rw-r--r--drivers/scsi/ata_piix.c15
-rw-r--r--drivers/scsi/dec_esp.c2
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.c9
-rw-r--r--drivers/scsi/ide-scsi.c38
-rw-r--r--drivers/scsi/libata-core.c104
-rw-r--r--drivers/scsi/libata-scsi.c804
-rw-r--r--drivers/scsi/libata.h5
-rw-r--r--drivers/scsi/mesh.c2
-rw-r--r--drivers/scsi/pdc_adma.c46
-rw-r--r--drivers/scsi/sata_mv.c41
-rw-r--r--drivers/scsi/sata_nv.c3
-rw-r--r--drivers/scsi/sata_promise.c23
-rw-r--r--drivers/scsi/sata_qstor.c27
-rw-r--r--drivers/scsi/sata_sil.c7
-rw-r--r--drivers/scsi/sata_sil24.c76
-rw-r--r--drivers/scsi/sata_sis.c13
-rw-r--r--drivers/scsi/sata_svw.c25
-rw-r--r--drivers/scsi/sata_sx4.c13
-rw-r--r--drivers/scsi/sata_uli.c5
-rw-r--r--drivers/scsi/sata_via.c38
-rw-r--r--drivers/scsi/sata_vsc.c23
-rw-r--r--drivers/scsi/scsi_transport_fc.c1
-rw-r--r--drivers/scsi/scsi_transport_iscsi.c3
-rw-r--r--drivers/scsi/sg.c17
-rw-r--r--drivers/scsi/st.c10
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_hipd.c3
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_hipd.h2
29 files changed, 972 insertions, 444 deletions
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index fe8187d6f58b..e2a5657d5fdb 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -41,6 +41,7 @@
41#include <linux/interrupt.h> 41#include <linux/interrupt.h>
42#include <linux/sched.h> 42#include <linux/sched.h>
43#include <linux/dma-mapping.h> 43#include <linux/dma-mapping.h>
44#include <linux/device.h>
44#include "scsi.h" 45#include "scsi.h"
45#include <scsi/scsi_host.h> 46#include <scsi/scsi_host.h>
46#include <linux/libata.h> 47#include <linux/libata.h>
@@ -192,7 +193,6 @@ static void ahci_port_stop(struct ata_port *ap);
192static void ahci_tf_read(struct ata_port *ap, struct ata_taskfile *tf); 193static void ahci_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
193static void ahci_qc_prep(struct ata_queued_cmd *qc); 194static void ahci_qc_prep(struct ata_queued_cmd *qc);
194static u8 ahci_check_status(struct ata_port *ap); 195static u8 ahci_check_status(struct ata_port *ap);
195static u8 ahci_check_err(struct ata_port *ap);
196static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc); 196static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc);
197static void ahci_remove_one (struct pci_dev *pdev); 197static void ahci_remove_one (struct pci_dev *pdev);
198 198
@@ -221,7 +221,6 @@ static const struct ata_port_operations ahci_ops = {
221 221
222 .check_status = ahci_check_status, 222 .check_status = ahci_check_status,
223 .check_altstatus = ahci_check_status, 223 .check_altstatus = ahci_check_status,
224 .check_err = ahci_check_err,
225 .dev_select = ata_noop_dev_select, 224 .dev_select = ata_noop_dev_select,
226 225
227 .tf_read = ahci_tf_read, 226 .tf_read = ahci_tf_read,
@@ -458,13 +457,6 @@ static u8 ahci_check_status(struct ata_port *ap)
458 return readl(mmio + PORT_TFDATA) & 0xFF; 457 return readl(mmio + PORT_TFDATA) & 0xFF;
459} 458}
460 459
461static u8 ahci_check_err(struct ata_port *ap)
462{
463 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr;
464
465 return (readl(mmio + PORT_TFDATA) >> 8) & 0xFF;
466}
467
468static void ahci_tf_read(struct ata_port *ap, struct ata_taskfile *tf) 460static void ahci_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
469{ 461{
470 struct ahci_port_priv *pp = ap->private_data; 462 struct ahci_port_priv *pp = ap->private_data;
@@ -609,7 +601,7 @@ static void ahci_eng_timeout(struct ata_port *ap)
609 * not being called from the SCSI EH. 601 * not being called from the SCSI EH.
610 */ 602 */
611 qc->scsidone = scsi_finish_command; 603 qc->scsidone = scsi_finish_command;
612 ata_qc_complete(qc, ATA_ERR); 604 ata_qc_complete(qc, AC_ERR_OTHER);
613 } 605 }
614 606
615 spin_unlock_irqrestore(&host_set->lock, flags); 607 spin_unlock_irqrestore(&host_set->lock, flags);
@@ -638,7 +630,7 @@ static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
638 if (status & PORT_IRQ_FATAL) { 630 if (status & PORT_IRQ_FATAL) {
639 ahci_intr_error(ap, status); 631 ahci_intr_error(ap, status);
640 if (qc) 632 if (qc)
641 ata_qc_complete(qc, ATA_ERR); 633 ata_qc_complete(qc, AC_ERR_OTHER);
642 } 634 }
643 635
644 return 1; 636 return 1;
@@ -683,10 +675,10 @@ static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *
683 if (!ahci_host_intr(ap, qc)) 675 if (!ahci_host_intr(ap, qc))
684 if (ata_ratelimit()) { 676 if (ata_ratelimit()) {
685 struct pci_dev *pdev = 677 struct pci_dev *pdev =
686 to_pci_dev(ap->host_set->dev); 678 to_pci_dev(ap->host_set->dev);
687 printk(KERN_WARNING 679 dev_printk(KERN_WARNING, &pdev->dev,
688 "ahci(%s): unhandled interrupt on port %u\n", 680 "unhandled interrupt on port %u\n",
689 pci_name(pdev), i); 681 i);
690 } 682 }
691 683
692 VPRINTK("port %u\n", i); 684 VPRINTK("port %u\n", i);
@@ -694,10 +686,9 @@ static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *
694 VPRINTK("port %u (no irq)\n", i); 686 VPRINTK("port %u (no irq)\n", i);
695 if (ata_ratelimit()) { 687 if (ata_ratelimit()) {
696 struct pci_dev *pdev = 688 struct pci_dev *pdev =
697 to_pci_dev(ap->host_set->dev); 689 to_pci_dev(ap->host_set->dev);
698 printk(KERN_WARNING 690 dev_printk(KERN_WARNING, &pdev->dev,
699 "ahci(%s): interrupt on disabled port %u\n", 691 "interrupt on disabled port %u\n", i);
700 pci_name(pdev), i);
701 } 692 }
702 } 693 }
703 694
@@ -769,8 +760,8 @@ static int ahci_host_init(struct ata_probe_ent *probe_ent)
769 760
770 tmp = readl(mmio + HOST_CTL); 761 tmp = readl(mmio + HOST_CTL);
771 if (tmp & HOST_RESET) { 762 if (tmp & HOST_RESET) {
772 printk(KERN_ERR DRV_NAME "(%s): controller reset failed (0x%x)\n", 763 dev_printk(KERN_ERR, &pdev->dev,
773 pci_name(pdev), tmp); 764 "controller reset failed (0x%x)\n", tmp);
774 return -EIO; 765 return -EIO;
775 } 766 }
776 767
@@ -798,22 +789,22 @@ static int ahci_host_init(struct ata_probe_ent *probe_ent)
798 if (rc) { 789 if (rc) {
799 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 790 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
800 if (rc) { 791 if (rc) {
801 printk(KERN_ERR DRV_NAME "(%s): 64-bit DMA enable failed\n", 792 dev_printk(KERN_ERR, &pdev->dev,
802 pci_name(pdev)); 793 "64-bit DMA enable failed\n");
803 return rc; 794 return rc;
804 } 795 }
805 } 796 }
806 } else { 797 } else {
807 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 798 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
808 if (rc) { 799 if (rc) {
809 printk(KERN_ERR DRV_NAME "(%s): 32-bit DMA enable failed\n", 800 dev_printk(KERN_ERR, &pdev->dev,
810 pci_name(pdev)); 801 "32-bit DMA enable failed\n");
811 return rc; 802 return rc;
812 } 803 }
813 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 804 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
814 if (rc) { 805 if (rc) {
815 printk(KERN_ERR DRV_NAME "(%s): 32-bit consistent DMA enable failed\n", 806 dev_printk(KERN_ERR, &pdev->dev,
816 pci_name(pdev)); 807 "32-bit consistent DMA enable failed\n");
817 return rc; 808 return rc;
818 } 809 }
819 } 810 }
@@ -916,10 +907,10 @@ static void ahci_print_info(struct ata_probe_ent *probe_ent)
916 else 907 else
917 scc_s = "unknown"; 908 scc_s = "unknown";
918 909
919 printk(KERN_INFO DRV_NAME "(%s) AHCI %02x%02x.%02x%02x " 910 dev_printk(KERN_INFO, &pdev->dev,
911 "AHCI %02x%02x.%02x%02x "
920 "%u slots %u ports %s Gbps 0x%x impl %s mode\n" 912 "%u slots %u ports %s Gbps 0x%x impl %s mode\n"
921 , 913 ,
922 pci_name(pdev),
923 914
924 (vers >> 24) & 0xff, 915 (vers >> 24) & 0xff,
925 (vers >> 16) & 0xff, 916 (vers >> 16) & 0xff,
@@ -932,11 +923,11 @@ static void ahci_print_info(struct ata_probe_ent *probe_ent)
932 impl, 923 impl,
933 scc_s); 924 scc_s);
934 925
935 printk(KERN_INFO DRV_NAME "(%s) flags: " 926 dev_printk(KERN_INFO, &pdev->dev,
927 "flags: "
936 "%s%s%s%s%s%s" 928 "%s%s%s%s%s%s"
937 "%s%s%s%s%s%s%s\n" 929 "%s%s%s%s%s%s%s\n"
938 , 930 ,
939 pci_name(pdev),
940 931
941 cap & (1 << 31) ? "64bit " : "", 932 cap & (1 << 31) ? "64bit " : "",
942 cap & (1 << 30) ? "ncq " : "", 933 cap & (1 << 30) ? "ncq " : "",
@@ -969,7 +960,7 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
969 VPRINTK("ENTER\n"); 960 VPRINTK("ENTER\n");
970 961
971 if (!printed_version++) 962 if (!printed_version++)
972 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 963 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
973 964
974 rc = pci_enable_device(pdev); 965 rc = pci_enable_device(pdev);
975 if (rc) 966 if (rc)
diff --git a/drivers/scsi/arm/scsi.h b/drivers/scsi/arm/scsi.h
index 48e1c4d9738b..19937640e2e7 100644
--- a/drivers/scsi/arm/scsi.h
+++ b/drivers/scsi/arm/scsi.h
@@ -10,6 +10,8 @@
10 * Commonly used scsi driver functions. 10 * Commonly used scsi driver functions.
11 */ 11 */
12 12
13#include <linux/scatterlist.h>
14
13#define BELT_AND_BRACES 15#define BELT_AND_BRACES
14 16
15/* 17/*
@@ -22,9 +24,7 @@ static inline int copy_SCp_to_sg(struct scatterlist *sg, Scsi_Pointer *SCp, int
22 24
23 BUG_ON(bufs + 1 > max); 25 BUG_ON(bufs + 1 > max);
24 26
25 sg->page = virt_to_page(SCp->ptr); 27 sg_set_buf(sg, SCp->ptr, SCp->this_residual);
26 sg->offset = offset_in_page(SCp->ptr);
27 sg->length = SCp->this_residual;
28 28
29 if (bufs) 29 if (bufs)
30 memcpy(sg + 1, SCp->buffer + 1, 30 memcpy(sg + 1, SCp->buffer + 1,
diff --git a/drivers/scsi/ata_piix.c b/drivers/scsi/ata_piix.c
index be021478f416..7f8aa1b552ce 100644
--- a/drivers/scsi/ata_piix.c
+++ b/drivers/scsi/ata_piix.c
@@ -45,6 +45,7 @@
45#include <linux/init.h> 45#include <linux/init.h>
46#include <linux/blkdev.h> 46#include <linux/blkdev.h>
47#include <linux/delay.h> 47#include <linux/delay.h>
48#include <linux/device.h>
48#include "scsi.h" 49#include "scsi.h"
49#include <scsi/scsi_host.h> 50#include <scsi/scsi_host.h>
50#include <linux/libata.h> 51#include <linux/libata.h>
@@ -621,18 +622,19 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
621{ 622{
622 static int printed_version; 623 static int printed_version;
623 struct ata_port_info *port_info[2]; 624 struct ata_port_info *port_info[2];
624 unsigned int combined = 0, n_ports = 1; 625 unsigned int combined = 0;
625 unsigned int pata_chan = 0, sata_chan = 0; 626 unsigned int pata_chan = 0, sata_chan = 0;
626 627
627 if (!printed_version++) 628 if (!printed_version++)
628 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 629 dev_printk(KERN_DEBUG, &pdev->dev,
630 "version " DRV_VERSION "\n");
629 631
630 /* no hotplugging support (FIXME) */ 632 /* no hotplugging support (FIXME) */
631 if (!in_module_init) 633 if (!in_module_init)
632 return -ENODEV; 634 return -ENODEV;
633 635
634 port_info[0] = &piix_port_info[ent->driver_data]; 636 port_info[0] = &piix_port_info[ent->driver_data];
635 port_info[1] = NULL; 637 port_info[1] = &piix_port_info[ent->driver_data];
636 638
637 if (port_info[0]->host_flags & PIIX_FLAG_AHCI) { 639 if (port_info[0]->host_flags & PIIX_FLAG_AHCI) {
638 u8 tmp; 640 u8 tmp;
@@ -670,12 +672,13 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
670 port_info[sata_chan] = &piix_port_info[ent->driver_data]; 672 port_info[sata_chan] = &piix_port_info[ent->driver_data];
671 port_info[sata_chan]->host_flags |= ATA_FLAG_SLAVE_POSS; 673 port_info[sata_chan]->host_flags |= ATA_FLAG_SLAVE_POSS;
672 port_info[pata_chan] = &piix_port_info[ich5_pata]; 674 port_info[pata_chan] = &piix_port_info[ich5_pata];
673 n_ports++;
674 675
675 printk(KERN_WARNING DRV_NAME ": combined mode detected\n"); 676 dev_printk(KERN_WARNING, &pdev->dev,
677 "combined mode detected (p=%u, s=%u)\n",
678 pata_chan, sata_chan);
676 } 679 }
677 680
678 return ata_pci_init_one(pdev, port_info, n_ports); 681 return ata_pci_init_one(pdev, port_info, 2);
679} 682}
680 683
681static int __init piix_init(void) 684static int __init piix_init(void)
diff --git a/drivers/scsi/dec_esp.c b/drivers/scsi/dec_esp.c
index 315f95a0d6c0..4f39890b44ac 100644
--- a/drivers/scsi/dec_esp.c
+++ b/drivers/scsi/dec_esp.c
@@ -228,7 +228,7 @@ static int dec_esp_detect(Scsi_Host_Template * tpnt)
228 mem_start = get_tc_base_addr(slot); 228 mem_start = get_tc_base_addr(slot);
229 229
230 /* Store base addr into esp struct */ 230 /* Store base addr into esp struct */
231 esp->slot = PHYSADDR(mem_start); 231 esp->slot = CPHYSADDR(mem_start);
232 232
233 esp->dregs = 0; 233 esp->dregs = 0;
234 esp->eregs = (struct ESP_regs *) (mem_start + DEC_SCSI_SREG); 234 esp->eregs = (struct ESP_regs *) (mem_start + DEC_SCSI_SREG);
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index ff25210b00ba..822b9fa706f3 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -1543,13 +1543,16 @@ static struct vio_device_id ibmvscsi_device_table[] __devinitdata = {
1543 {"vscsi", "IBM,v-scsi"}, 1543 {"vscsi", "IBM,v-scsi"},
1544 { "", "" } 1544 { "", "" }
1545}; 1545};
1546
1547MODULE_DEVICE_TABLE(vio, ibmvscsi_device_table); 1546MODULE_DEVICE_TABLE(vio, ibmvscsi_device_table);
1547
1548static struct vio_driver ibmvscsi_driver = { 1548static struct vio_driver ibmvscsi_driver = {
1549 .name = "ibmvscsi",
1550 .id_table = ibmvscsi_device_table, 1549 .id_table = ibmvscsi_device_table,
1551 .probe = ibmvscsi_probe, 1550 .probe = ibmvscsi_probe,
1552 .remove = ibmvscsi_remove 1551 .remove = ibmvscsi_remove,
1552 .driver = {
1553 .name = "ibmvscsi",
1554 .owner = THIS_MODULE,
1555 }
1553}; 1556};
1554 1557
1555int __init ibmvscsi_module_init(void) 1558int __init ibmvscsi_module_init(void)
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 3d62c9bcbff7..00d6a6657ebc 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -180,19 +180,12 @@ static void idescsi_input_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigne
180 return; 180 return;
181 } 181 }
182 count = min(pc->sg->length - pc->b_count, bcount); 182 count = min(pc->sg->length - pc->b_count, bcount);
183 if (PageHighMem(pc->sg->page)) { 183 buf = kmap_atomic(pc->sg->page, KM_IRQ0);
184 unsigned long flags; 184 drive->hwif->atapi_input_bytes(drive,
185 185 buf + pc->b_count + pc->sg->offset, count);
186 local_irq_save(flags); 186 kunmap_atomic(buf, KM_IRQ0);
187 buf = kmap_atomic(pc->sg->page, KM_IRQ0) + pc->sg->offset; 187 bcount -= count;
188 drive->hwif->atapi_input_bytes(drive, buf + pc->b_count, count); 188 pc->b_count += count;
189 kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
190 local_irq_restore(flags);
191 } else {
192 buf = page_address(pc->sg->page) + pc->sg->offset;
193 drive->hwif->atapi_input_bytes(drive, buf + pc->b_count, count);
194 }
195 bcount -= count; pc->b_count += count;
196 if (pc->b_count == pc->sg->length) { 189 if (pc->b_count == pc->sg->length) {
197 pc->sg++; 190 pc->sg++;
198 pc->b_count = 0; 191 pc->b_count = 0;
@@ -212,19 +205,12 @@ static void idescsi_output_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsign
212 return; 205 return;
213 } 206 }
214 count = min(pc->sg->length - pc->b_count, bcount); 207 count = min(pc->sg->length - pc->b_count, bcount);
215 if (PageHighMem(pc->sg->page)) { 208 buf = kmap_atomic(pc->sg->page, KM_IRQ0);
216 unsigned long flags; 209 drive->hwif->atapi_output_bytes(drive,
217 210 buf + pc->b_count + pc->sg->offset, count);
218 local_irq_save(flags); 211 kunmap_atomic(buf, KM_IRQ0);
219 buf = kmap_atomic(pc->sg->page, KM_IRQ0) + pc->sg->offset; 212 bcount -= count;
220 drive->hwif->atapi_output_bytes(drive, buf + pc->b_count, count); 213 pc->b_count += count;
221 kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
222 local_irq_restore(flags);
223 } else {
224 buf = page_address(pc->sg->page) + pc->sg->offset;
225 drive->hwif->atapi_output_bytes(drive, buf + pc->b_count, count);
226 }
227 bcount -= count; pc->b_count += count;
228 if (pc->b_count == pc->sg->length) { 214 if (pc->b_count == pc->sg->length) {
229 pc->sg++; 215 pc->sg++;
230 pc->b_count = 0; 216 pc->b_count = 0;
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index f53d7b8ac33f..8be7dc0b47b8 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -49,6 +49,7 @@
49#include <linux/suspend.h> 49#include <linux/suspend.h>
50#include <linux/workqueue.h> 50#include <linux/workqueue.h>
51#include <linux/jiffies.h> 51#include <linux/jiffies.h>
52#include <linux/scatterlist.h>
52#include <scsi/scsi.h> 53#include <scsi/scsi.h>
53#include "scsi.h" 54#include "scsi.h"
54#include "scsi_priv.h" 55#include "scsi_priv.h"
@@ -370,6 +371,8 @@ static void ata_tf_read_pio(struct ata_port *ap, struct ata_taskfile *tf)
370{ 371{
371 struct ata_ioports *ioaddr = &ap->ioaddr; 372 struct ata_ioports *ioaddr = &ap->ioaddr;
372 373
374 tf->command = ata_check_status(ap);
375 tf->feature = inb(ioaddr->error_addr);
373 tf->nsect = inb(ioaddr->nsect_addr); 376 tf->nsect = inb(ioaddr->nsect_addr);
374 tf->lbal = inb(ioaddr->lbal_addr); 377 tf->lbal = inb(ioaddr->lbal_addr);
375 tf->lbam = inb(ioaddr->lbam_addr); 378 tf->lbam = inb(ioaddr->lbam_addr);
@@ -402,6 +405,8 @@ static void ata_tf_read_mmio(struct ata_port *ap, struct ata_taskfile *tf)
402{ 405{
403 struct ata_ioports *ioaddr = &ap->ioaddr; 406 struct ata_ioports *ioaddr = &ap->ioaddr;
404 407
408 tf->command = ata_check_status(ap);
409 tf->feature = readb((void __iomem *)ioaddr->error_addr);
405 tf->nsect = readb((void __iomem *)ioaddr->nsect_addr); 410 tf->nsect = readb((void __iomem *)ioaddr->nsect_addr);
406 tf->lbal = readb((void __iomem *)ioaddr->lbal_addr); 411 tf->lbal = readb((void __iomem *)ioaddr->lbal_addr);
407 tf->lbam = readb((void __iomem *)ioaddr->lbam_addr); 412 tf->lbam = readb((void __iomem *)ioaddr->lbam_addr);
@@ -522,30 +527,6 @@ u8 ata_altstatus(struct ata_port *ap)
522 527
523 528
524/** 529/**
525 * ata_chk_err - Read device error reg
526 * @ap: port where the device is
527 *
528 * Reads ATA taskfile error register for
529 * currently-selected device and return its value.
530 *
531 * Note: may NOT be used as the check_err() entry in
532 * ata_port_operations.
533 *
534 * LOCKING:
535 * Inherited from caller.
536 */
537u8 ata_chk_err(struct ata_port *ap)
538{
539 if (ap->ops->check_err)
540 return ap->ops->check_err(ap);
541
542 if (ap->flags & ATA_FLAG_MMIO) {
543 return readb((void __iomem *) ap->ioaddr.error_addr);
544 }
545 return inb(ap->ioaddr.error_addr);
546}
547
548/**
549 * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure 530 * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure
550 * @tf: Taskfile to convert 531 * @tf: Taskfile to convert
551 * @fis: Buffer into which data will output 532 * @fis: Buffer into which data will output
@@ -897,8 +878,8 @@ static u8 ata_dev_try_classify(struct ata_port *ap, unsigned int device)
897 878
898 memset(&tf, 0, sizeof(tf)); 879 memset(&tf, 0, sizeof(tf));
899 880
900 err = ata_chk_err(ap);
901 ap->ops->tf_read(ap, &tf); 881 ap->ops->tf_read(ap, &tf);
882 err = tf.feature;
902 883
903 dev->class = ATA_DEV_NONE; 884 dev->class = ATA_DEV_NONE;
904 885
@@ -1135,7 +1116,6 @@ static void ata_dev_identify(struct ata_port *ap, unsigned int device)
1135 unsigned int major_version; 1116 unsigned int major_version;
1136 u16 tmp; 1117 u16 tmp;
1137 unsigned long xfer_modes; 1118 unsigned long xfer_modes;
1138 u8 status;
1139 unsigned int using_edd; 1119 unsigned int using_edd;
1140 DECLARE_COMPLETION(wait); 1120 DECLARE_COMPLETION(wait);
1141 struct ata_queued_cmd *qc; 1121 struct ata_queued_cmd *qc;
@@ -1189,8 +1169,11 @@ retry:
1189 else 1169 else
1190 wait_for_completion(&wait); 1170 wait_for_completion(&wait);
1191 1171
1192 status = ata_chk_status(ap); 1172 spin_lock_irqsave(&ap->host_set->lock, flags);
1193 if (status & ATA_ERR) { 1173 ap->ops->tf_read(ap, &qc->tf);
1174 spin_unlock_irqrestore(&ap->host_set->lock, flags);
1175
1176 if (qc->tf.command & ATA_ERR) {
1194 /* 1177 /*
1195 * arg! EDD works for all test cases, but seems to return 1178 * arg! EDD works for all test cases, but seems to return
1196 * the ATA signature for some ATAPI devices. Until the 1179 * the ATA signature for some ATAPI devices. Until the
@@ -1203,7 +1186,7 @@ retry:
1203 * to have this problem. 1186 * to have this problem.
1204 */ 1187 */
1205 if ((using_edd) && (qc->tf.command == ATA_CMD_ID_ATA)) { 1188 if ((using_edd) && (qc->tf.command == ATA_CMD_ID_ATA)) {
1206 u8 err = ata_chk_err(ap); 1189 u8 err = qc->tf.feature;
1207 if (err & ATA_ABORTED) { 1190 if (err & ATA_ABORTED) {
1208 dev->class = ATA_DEV_ATAPI; 1191 dev->class = ATA_DEV_ATAPI;
1209 qc->cursg = 0; 1192 qc->cursg = 0;
@@ -2572,19 +2555,12 @@ void ata_qc_prep(struct ata_queued_cmd *qc)
2572 2555
2573void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen) 2556void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen)
2574{ 2557{
2575 struct scatterlist *sg;
2576
2577 qc->flags |= ATA_QCFLAG_SINGLE; 2558 qc->flags |= ATA_QCFLAG_SINGLE;
2578 2559
2579 memset(&qc->sgent, 0, sizeof(qc->sgent));
2580 qc->sg = &qc->sgent; 2560 qc->sg = &qc->sgent;
2581 qc->n_elem = 1; 2561 qc->n_elem = 1;
2582 qc->buf_virt = buf; 2562 qc->buf_virt = buf;
2583 2563 sg_init_one(qc->sg, buf, buflen);
2584 sg = qc->sg;
2585 sg->page = virt_to_page(buf);
2586 sg->offset = (unsigned long) buf & ~PAGE_MASK;
2587 sg->length = buflen;
2588} 2564}
2589 2565
2590/** 2566/**
@@ -2687,7 +2663,7 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
2687 * None. (grabs host lock) 2663 * None. (grabs host lock)
2688 */ 2664 */
2689 2665
2690void ata_poll_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) 2666void ata_poll_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask)
2691{ 2667{
2692 struct ata_port *ap = qc->ap; 2668 struct ata_port *ap = qc->ap;
2693 unsigned long flags; 2669 unsigned long flags;
@@ -2695,7 +2671,7 @@ void ata_poll_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
2695 spin_lock_irqsave(&ap->host_set->lock, flags); 2671 spin_lock_irqsave(&ap->host_set->lock, flags);
2696 ap->flags &= ~ATA_FLAG_NOINTR; 2672 ap->flags &= ~ATA_FLAG_NOINTR;
2697 ata_irq_on(ap); 2673 ata_irq_on(ap);
2698 ata_qc_complete(qc, drv_stat); 2674 ata_qc_complete(qc, err_mask);
2699 spin_unlock_irqrestore(&ap->host_set->lock, flags); 2675 spin_unlock_irqrestore(&ap->host_set->lock, flags);
2700} 2676}
2701 2677
@@ -2792,7 +2768,7 @@ static int ata_pio_complete (struct ata_port *ap)
2792 2768
2793 ap->hsm_task_state = HSM_ST_IDLE; 2769 ap->hsm_task_state = HSM_ST_IDLE;
2794 2770
2795 ata_poll_qc_complete(qc, drv_stat); 2771 ata_poll_qc_complete(qc, 0);
2796 2772
2797 /* another command may start at this point */ 2773 /* another command may start at this point */
2798 2774
@@ -3160,18 +3136,15 @@ static void ata_pio_block(struct ata_port *ap)
3160static void ata_pio_error(struct ata_port *ap) 3136static void ata_pio_error(struct ata_port *ap)
3161{ 3137{
3162 struct ata_queued_cmd *qc; 3138 struct ata_queued_cmd *qc;
3163 u8 drv_stat; 3139
3140 printk(KERN_WARNING "ata%u: PIO error\n", ap->id);
3164 3141
3165 qc = ata_qc_from_tag(ap, ap->active_tag); 3142 qc = ata_qc_from_tag(ap, ap->active_tag);
3166 assert(qc != NULL); 3143 assert(qc != NULL);
3167 3144
3168 drv_stat = ata_chk_status(ap);
3169 printk(KERN_WARNING "ata%u: PIO error, drv_stat 0x%x\n",
3170 ap->id, drv_stat);
3171
3172 ap->hsm_task_state = HSM_ST_IDLE; 3145 ap->hsm_task_state = HSM_ST_IDLE;
3173 3146
3174 ata_poll_qc_complete(qc, drv_stat | ATA_ERR); 3147 ata_poll_qc_complete(qc, AC_ERR_ATA_BUS);
3175} 3148}
3176 3149
3177static void ata_pio_task(void *_data) 3150static void ata_pio_task(void *_data)
@@ -3294,7 +3267,7 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc)
3294 ap->id, qc->tf.command, drv_stat, host_stat); 3267 ap->id, qc->tf.command, drv_stat, host_stat);
3295 3268
3296 /* complete taskfile transaction */ 3269 /* complete taskfile transaction */
3297 ata_qc_complete(qc, drv_stat); 3270 ata_qc_complete(qc, ac_err_mask(drv_stat));
3298 break; 3271 break;
3299 } 3272 }
3300 3273
@@ -3399,7 +3372,7 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap,
3399 return qc; 3372 return qc;
3400} 3373}
3401 3374
3402int ata_qc_complete_noop(struct ata_queued_cmd *qc, u8 drv_stat) 3375int ata_qc_complete_noop(struct ata_queued_cmd *qc, unsigned int err_mask)
3403{ 3376{
3404 return 0; 3377 return 0;
3405} 3378}
@@ -3458,7 +3431,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
3458 * spin_lock_irqsave(host_set lock) 3431 * spin_lock_irqsave(host_set lock)
3459 */ 3432 */
3460 3433
3461void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) 3434void ata_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask)
3462{ 3435{
3463 int rc; 3436 int rc;
3464 3437
@@ -3475,7 +3448,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
3475 qc->flags &= ~ATA_QCFLAG_ACTIVE; 3448 qc->flags &= ~ATA_QCFLAG_ACTIVE;
3476 3449
3477 /* call completion callback */ 3450 /* call completion callback */
3478 rc = qc->complete_fn(qc, drv_stat); 3451 rc = qc->complete_fn(qc, err_mask);
3479 3452
3480 /* if callback indicates not to complete command (non-zero), 3453 /* if callback indicates not to complete command (non-zero),
3481 * return immediately 3454 * return immediately
@@ -3913,7 +3886,7 @@ inline unsigned int ata_host_intr (struct ata_port *ap,
3913 ap->ops->irq_clear(ap); 3886 ap->ops->irq_clear(ap);
3914 3887
3915 /* complete taskfile transaction */ 3888 /* complete taskfile transaction */
3916 ata_qc_complete(qc, status); 3889 ata_qc_complete(qc, ac_err_mask(status));
3917 break; 3890 break;
3918 3891
3919 default: 3892 default:
@@ -4008,7 +3981,7 @@ static void atapi_packet_task(void *_data)
4008 /* sleep-wait for BSY to clear */ 3981 /* sleep-wait for BSY to clear */
4009 DPRINTK("busy wait\n"); 3982 DPRINTK("busy wait\n");
4010 if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) 3983 if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB))
4011 goto err_out; 3984 goto err_out_status;
4012 3985
4013 /* make sure DRQ is set */ 3986 /* make sure DRQ is set */
4014 status = ata_chk_status(ap); 3987 status = ata_chk_status(ap);
@@ -4045,8 +4018,10 @@ static void atapi_packet_task(void *_data)
4045 4018
4046 return; 4019 return;
4047 4020
4021err_out_status:
4022 status = ata_chk_status(ap);
4048err_out: 4023err_out:
4049 ata_poll_qc_complete(qc, ATA_ERR); 4024 ata_poll_qc_complete(qc, __ac_err_mask(status));
4050} 4025}
4051 4026
4052 4027
@@ -4254,11 +4229,10 @@ int ata_device_add(const struct ata_probe_ent *ent)
4254 4229
4255 DPRINTK("ENTER\n"); 4230 DPRINTK("ENTER\n");
4256 /* alloc a container for our list of ATA ports (buses) */ 4231 /* alloc a container for our list of ATA ports (buses) */
4257 host_set = kmalloc(sizeof(struct ata_host_set) + 4232 host_set = kzalloc(sizeof(struct ata_host_set) +
4258 (ent->n_ports * sizeof(void *)), GFP_KERNEL); 4233 (ent->n_ports * sizeof(void *)), GFP_KERNEL);
4259 if (!host_set) 4234 if (!host_set)
4260 return 0; 4235 return 0;
4261 memset(host_set, 0, sizeof(struct ata_host_set) + (ent->n_ports * sizeof(void *)));
4262 spin_lock_init(&host_set->lock); 4236 spin_lock_init(&host_set->lock);
4263 4237
4264 host_set->dev = dev; 4238 host_set->dev = dev;
@@ -4298,10 +4272,8 @@ int ata_device_add(const struct ata_probe_ent *ent)
4298 count++; 4272 count++;
4299 } 4273 }
4300 4274
4301 if (!count) { 4275 if (!count)
4302 kfree(host_set); 4276 goto err_free_ret;
4303 return 0;
4304 }
4305 4277
4306 /* obtain irq, that is shared between channels */ 4278 /* obtain irq, that is shared between channels */
4307 if (request_irq(ent->irq, ent->port_ops->irq_handler, ent->irq_flags, 4279 if (request_irq(ent->irq, ent->port_ops->irq_handler, ent->irq_flags,
@@ -4359,6 +4331,7 @@ err_out:
4359 ata_host_remove(host_set->ports[i], 1); 4331 ata_host_remove(host_set->ports[i], 1);
4360 scsi_host_put(host_set->ports[i]->host); 4332 scsi_host_put(host_set->ports[i]->host);
4361 } 4333 }
4334err_free_ret:
4362 kfree(host_set); 4335 kfree(host_set);
4363 VPRINTK("EXIT, returning 0\n"); 4336 VPRINTK("EXIT, returning 0\n");
4364 return 0; 4337 return 0;
@@ -4468,15 +4441,13 @@ ata_probe_ent_alloc(struct device *dev, const struct ata_port_info *port)
4468{ 4441{
4469 struct ata_probe_ent *probe_ent; 4442 struct ata_probe_ent *probe_ent;
4470 4443
4471 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 4444 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
4472 if (!probe_ent) { 4445 if (!probe_ent) {
4473 printk(KERN_ERR DRV_NAME "(%s): out of memory\n", 4446 printk(KERN_ERR DRV_NAME "(%s): out of memory\n",
4474 kobject_name(&(dev->kobj))); 4447 kobject_name(&(dev->kobj)));
4475 return NULL; 4448 return NULL;
4476 } 4449 }
4477 4450
4478 memset(probe_ent, 0, sizeof(*probe_ent));
4479
4480 INIT_LIST_HEAD(&probe_ent->node); 4451 INIT_LIST_HEAD(&probe_ent->node);
4481 probe_ent->dev = dev; 4452 probe_ent->dev = dev;
4482 4453
@@ -4556,11 +4527,11 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int
4556 return probe_ent; 4527 return probe_ent;
4557} 4528}
4558 4529
4559static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev, struct ata_port_info **port, int port_num) 4530static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev, struct ata_port_info *port, int port_num)
4560{ 4531{
4561 struct ata_probe_ent *probe_ent; 4532 struct ata_probe_ent *probe_ent;
4562 4533
4563 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); 4534 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port);
4564 if (!probe_ent) 4535 if (!probe_ent)
4565 return NULL; 4536 return NULL;
4566 4537
@@ -4707,9 +4678,9 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
4707 4678
4708 if (legacy_mode) { 4679 if (legacy_mode) {
4709 if (legacy_mode & (1 << 0)) 4680 if (legacy_mode & (1 << 0))
4710 probe_ent = ata_pci_init_legacy_port(pdev, port, 0); 4681 probe_ent = ata_pci_init_legacy_port(pdev, port[0], 0);
4711 if (legacy_mode & (1 << 1)) 4682 if (legacy_mode & (1 << 1))
4712 probe_ent2 = ata_pci_init_legacy_port(pdev, port, 1); 4683 probe_ent2 = ata_pci_init_legacy_port(pdev, port[1], 1);
4713 } else { 4684 } else {
4714 if (n_ports == 2) 4685 if (n_ports == 2)
4715 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 4686 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
@@ -4873,7 +4844,6 @@ EXPORT_SYMBOL_GPL(ata_tf_to_fis);
4873EXPORT_SYMBOL_GPL(ata_tf_from_fis); 4844EXPORT_SYMBOL_GPL(ata_tf_from_fis);
4874EXPORT_SYMBOL_GPL(ata_check_status); 4845EXPORT_SYMBOL_GPL(ata_check_status);
4875EXPORT_SYMBOL_GPL(ata_altstatus); 4846EXPORT_SYMBOL_GPL(ata_altstatus);
4876EXPORT_SYMBOL_GPL(ata_chk_err);
4877EXPORT_SYMBOL_GPL(ata_exec_command); 4847EXPORT_SYMBOL_GPL(ata_exec_command);
4878EXPORT_SYMBOL_GPL(ata_port_start); 4848EXPORT_SYMBOL_GPL(ata_port_start);
4879EXPORT_SYMBOL_GPL(ata_port_stop); 4849EXPORT_SYMBOL_GPL(ata_port_stop);
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 58858886d751..1e3792f86fcf 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -40,14 +40,56 @@
40#include "scsi.h" 40#include "scsi.h"
41#include <scsi/scsi_host.h> 41#include <scsi/scsi_host.h>
42#include <linux/libata.h> 42#include <linux/libata.h>
43#include <linux/hdreg.h>
43#include <asm/uaccess.h> 44#include <asm/uaccess.h>
44 45
45#include "libata.h" 46#include "libata.h"
46 47
48#define SECTOR_SIZE 512
49
47typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, const u8 *scsicmd); 50typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, const u8 *scsicmd);
48static struct ata_device * 51static struct ata_device *
49ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev); 52ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev);
50 53
54#define RW_RECOVERY_MPAGE 0x1
55#define RW_RECOVERY_MPAGE_LEN 12
56#define CACHE_MPAGE 0x8
57#define CACHE_MPAGE_LEN 20
58#define CONTROL_MPAGE 0xa
59#define CONTROL_MPAGE_LEN 12
60#define ALL_MPAGES 0x3f
61#define ALL_SUB_MPAGES 0xff
62
63
64static const u8 def_rw_recovery_mpage[] = {
65 RW_RECOVERY_MPAGE,
66 RW_RECOVERY_MPAGE_LEN - 2,
67 (1 << 7) | /* AWRE, sat-r06 say it shall be 0 */
68 (1 << 6), /* ARRE (auto read reallocation) */
69 0, /* read retry count */
70 0, 0, 0, 0,
71 0, /* write retry count */
72 0, 0, 0
73};
74
75static const u8 def_cache_mpage[CACHE_MPAGE_LEN] = {
76 CACHE_MPAGE,
77 CACHE_MPAGE_LEN - 2,
78 0, /* contains WCE, needs to be 0 for logic */
79 0, 0, 0, 0, 0, 0, 0, 0, 0,
80 0, /* contains DRA, needs to be 0 for logic */
81 0, 0, 0, 0, 0, 0, 0
82};
83
84static const u8 def_control_mpage[CONTROL_MPAGE_LEN] = {
85 CONTROL_MPAGE,
86 CONTROL_MPAGE_LEN - 2,
87 2, /* DSENSE=0, GLTSD=1 */
88 0, /* [QAM+QERR may be 1, see 05-359r1] */
89 0, 0, 0, 0, 0xff, 0xff,
90 0, 30 /* extended self test time, see 05-359r1 */
91};
92
51 93
52static void ata_scsi_invalid_field(struct scsi_cmnd *cmd, 94static void ata_scsi_invalid_field(struct scsi_cmnd *cmd,
53 void (*done)(struct scsi_cmnd *)) 95 void (*done)(struct scsi_cmnd *))
@@ -86,6 +128,150 @@ int ata_std_bios_param(struct scsi_device *sdev, struct block_device *bdev,
86 return 0; 128 return 0;
87} 129}
88 130
131/**
132 * ata_cmd_ioctl - Handler for HDIO_DRIVE_CMD ioctl
133 * @dev: Device to whom we are issuing command
134 * @arg: User provided data for issuing command
135 *
136 * LOCKING:
137 * Defined by the SCSI layer. We don't really care.
138 *
139 * RETURNS:
140 * Zero on success, negative errno on error.
141 */
142
143int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
144{
145 int rc = 0;
146 u8 scsi_cmd[MAX_COMMAND_SIZE];
147 u8 args[4], *argbuf = NULL;
148 int argsize = 0;
149 struct scsi_request *sreq;
150
151 if (NULL == (void *)arg)
152 return -EINVAL;
153
154 if (copy_from_user(args, arg, sizeof(args)))
155 return -EFAULT;
156
157 sreq = scsi_allocate_request(scsidev, GFP_KERNEL);
158 if (!sreq)
159 return -EINTR;
160
161 memset(scsi_cmd, 0, sizeof(scsi_cmd));
162
163 if (args[3]) {
164 argsize = SECTOR_SIZE * args[3];
165 argbuf = kmalloc(argsize, GFP_KERNEL);
166 if (argbuf == NULL) {
167 rc = -ENOMEM;
168 goto error;
169 }
170
171 scsi_cmd[1] = (4 << 1); /* PIO Data-in */
172 scsi_cmd[2] = 0x0e; /* no off.line or cc, read from dev,
173 block count in sector count field */
174 sreq->sr_data_direction = DMA_FROM_DEVICE;
175 } else {
176 scsi_cmd[1] = (3 << 1); /* Non-data */
177 /* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */
178 sreq->sr_data_direction = DMA_NONE;
179 }
180
181 scsi_cmd[0] = ATA_16;
182
183 scsi_cmd[4] = args[2];
184 if (args[0] == WIN_SMART) { /* hack -- ide driver does this too... */
185 scsi_cmd[6] = args[3];
186 scsi_cmd[8] = args[1];
187 scsi_cmd[10] = 0x4f;
188 scsi_cmd[12] = 0xc2;
189 } else {
190 scsi_cmd[6] = args[1];
191 }
192 scsi_cmd[14] = args[0];
193
194 /* Good values for timeout and retries? Values below
195 from scsi_ioctl_send_command() for default case... */
196 scsi_wait_req(sreq, scsi_cmd, argbuf, argsize, (10*HZ), 5);
197
198 if (sreq->sr_result) {
199 rc = -EIO;
200 goto error;
201 }
202
203 /* Need code to retrieve data from check condition? */
204
205 if ((argbuf)
206 && copy_to_user((void *)(arg + sizeof(args)), argbuf, argsize))
207 rc = -EFAULT;
208error:
209 scsi_release_request(sreq);
210
211 if (argbuf)
212 kfree(argbuf);
213
214 return rc;
215}
216
217/**
218 * ata_task_ioctl - Handler for HDIO_DRIVE_TASK ioctl
219 * @dev: Device to whom we are issuing command
220 * @arg: User provided data for issuing command
221 *
222 * LOCKING:
223 * Defined by the SCSI layer. We don't really care.
224 *
225 * RETURNS:
226 * Zero on success, negative errno on error.
227 */
228int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
229{
230 int rc = 0;
231 u8 scsi_cmd[MAX_COMMAND_SIZE];
232 u8 args[7];
233 struct scsi_request *sreq;
234
235 if (NULL == (void *)arg)
236 return -EINVAL;
237
238 if (copy_from_user(args, arg, sizeof(args)))
239 return -EFAULT;
240
241 memset(scsi_cmd, 0, sizeof(scsi_cmd));
242 scsi_cmd[0] = ATA_16;
243 scsi_cmd[1] = (3 << 1); /* Non-data */
244 /* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */
245 scsi_cmd[4] = args[1];
246 scsi_cmd[6] = args[2];
247 scsi_cmd[8] = args[3];
248 scsi_cmd[10] = args[4];
249 scsi_cmd[12] = args[5];
250 scsi_cmd[14] = args[0];
251
252 sreq = scsi_allocate_request(scsidev, GFP_KERNEL);
253 if (!sreq) {
254 rc = -EINTR;
255 goto error;
256 }
257
258 sreq->sr_data_direction = DMA_NONE;
259 /* Good values for timeout and retries? Values below
260 from scsi_ioctl_send_command() for default case... */
261 scsi_wait_req(sreq, scsi_cmd, NULL, 0, (10*HZ), 5);
262
263 if (sreq->sr_result) {
264 rc = -EIO;
265 goto error;
266 }
267
268 /* Need code to retrieve data from check condition? */
269
270error:
271 scsi_release_request(sreq);
272 return rc;
273}
274
89int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg) 275int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg)
90{ 276{
91 struct ata_port *ap; 277 struct ata_port *ap;
@@ -115,6 +301,16 @@ int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg)
115 return -EINVAL; 301 return -EINVAL;
116 return 0; 302 return 0;
117 303
304 case HDIO_DRIVE_CMD:
305 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
306 return -EACCES;
307 return ata_cmd_ioctl(scsidev, arg);
308
309 case HDIO_DRIVE_TASK:
310 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
311 return -EACCES;
312 return ata_task_ioctl(scsidev, arg);
313
118 default: 314 default:
119 rc = -ENOTTY; 315 rc = -ENOTTY;
120 break; 316 break;
@@ -173,23 +369,70 @@ struct ata_queued_cmd *ata_scsi_qc_new(struct ata_port *ap,
173} 369}
174 370
175/** 371/**
372 * ata_dump_status - user friendly display of error info
373 * @id: id of the port in question
374 * @tf: ptr to filled out taskfile
375 *
376 * Decode and dump the ATA error/status registers for the user so
377 * that they have some idea what really happened at the non
378 * make-believe layer.
379 *
380 * LOCKING:
381 * inherited from caller
382 */
383void ata_dump_status(unsigned id, struct ata_taskfile *tf)
384{
385 u8 stat = tf->command, err = tf->feature;
386
387 printk(KERN_WARNING "ata%u: status=0x%02x { ", id, stat);
388 if (stat & ATA_BUSY) {
389 printk("Busy }\n"); /* Data is not valid in this case */
390 } else {
391 if (stat & 0x40) printk("DriveReady ");
392 if (stat & 0x20) printk("DeviceFault ");
393 if (stat & 0x10) printk("SeekComplete ");
394 if (stat & 0x08) printk("DataRequest ");
395 if (stat & 0x04) printk("CorrectedError ");
396 if (stat & 0x02) printk("Index ");
397 if (stat & 0x01) printk("Error ");
398 printk("}\n");
399
400 if (err) {
401 printk(KERN_WARNING "ata%u: error=0x%02x { ", id, err);
402 if (err & 0x04) printk("DriveStatusError ");
403 if (err & 0x80) {
404 if (err & 0x04) printk("BadCRC ");
405 else printk("Sector ");
406 }
407 if (err & 0x40) printk("UncorrectableError ");
408 if (err & 0x10) printk("SectorIdNotFound ");
409 if (err & 0x02) printk("TrackZeroNotFound ");
410 if (err & 0x01) printk("AddrMarkNotFound ");
411 printk("}\n");
412 }
413 }
414}
415
416/**
176 * ata_to_sense_error - convert ATA error to SCSI error 417 * ata_to_sense_error - convert ATA error to SCSI error
177 * @qc: Command that we are erroring out
178 * @drv_stat: value contained in ATA status register 418 * @drv_stat: value contained in ATA status register
419 * @drv_err: value contained in ATA error register
420 * @sk: the sense key we'll fill out
421 * @asc: the additional sense code we'll fill out
422 * @ascq: the additional sense code qualifier we'll fill out
179 * 423 *
180 * Converts an ATA error into a SCSI error. While we are at it 424 * Converts an ATA error into a SCSI error. Fill out pointers to
181 * we decode and dump the ATA error for the user so that they 425 * SK, ASC, and ASCQ bytes for later use in fixed or descriptor
182 * have some idea what really happened at the non make-believe 426 * format sense blocks.
183 * layer.
184 * 427 *
185 * LOCKING: 428 * LOCKING:
186 * spin_lock_irqsave(host_set lock) 429 * spin_lock_irqsave(host_set lock)
187 */ 430 */
188 431void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc,
189void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat) 432 u8 *ascq)
190{ 433{
191 struct scsi_cmnd *cmd = qc->scsicmd; 434 int i;
192 u8 err = 0; 435
193 /* Based on the 3ware driver translation table */ 436 /* Based on the 3ware driver translation table */
194 static unsigned char sense_table[][4] = { 437 static unsigned char sense_table[][4] = {
195 /* BBD|ECC|ID|MAR */ 438 /* BBD|ECC|ID|MAR */
@@ -230,96 +473,192 @@ void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat)
230 {0x04, RECOVERED_ERROR, 0x11, 0x00}, // Recovered ECC error Medium error, recovered 473 {0x04, RECOVERED_ERROR, 0x11, 0x00}, // Recovered ECC error Medium error, recovered
231 {0xFF, 0xFF, 0xFF, 0xFF}, // END mark 474 {0xFF, 0xFF, 0xFF, 0xFF}, // END mark
232 }; 475 };
233 int i = 0;
234 476
235 /* 477 /*
236 * Is this an error we can process/parse 478 * Is this an error we can process/parse
237 */ 479 */
480 if (drv_stat & ATA_BUSY) {
481 drv_err = 0; /* Ignore the err bits, they're invalid */
482 }
238 483
239 if(drv_stat & ATA_ERR) 484 if (drv_err) {
240 /* Read the err bits */ 485 /* Look for drv_err */
241 err = ata_chk_err(qc->ap); 486 for (i = 0; sense_table[i][0] != 0xFF; i++) {
487 /* Look for best matches first */
488 if ((sense_table[i][0] & drv_err) ==
489 sense_table[i][0]) {
490 *sk = sense_table[i][1];
491 *asc = sense_table[i][2];
492 *ascq = sense_table[i][3];
493 goto translate_done;
494 }
495 }
496 /* No immediate match */
497 printk(KERN_WARNING "ata%u: no sense translation for "
498 "error 0x%02x\n", id, drv_err);
499 }
242 500
243 /* Display the ATA level error info */ 501 /* Fall back to interpreting status bits */
502 for (i = 0; stat_table[i][0] != 0xFF; i++) {
503 if (stat_table[i][0] & drv_stat) {
504 *sk = stat_table[i][1];
505 *asc = stat_table[i][2];
506 *ascq = stat_table[i][3];
507 goto translate_done;
508 }
509 }
510 /* No error? Undecoded? */
511 printk(KERN_WARNING "ata%u: no sense translation for status: 0x%02x\n",
512 id, drv_stat);
244 513
245 printk(KERN_WARNING "ata%u: status=0x%02x { ", qc->ap->id, drv_stat); 514 /* For our last chance pick, use medium read error because
246 if(drv_stat & 0x80) 515 * it's much more common than an ATA drive telling you a write
247 { 516 * has failed.
248 printk("Busy "); 517 */
249 err = 0; /* Data is not valid in this case */ 518 *sk = MEDIUM_ERROR;
519 *asc = 0x11; /* "unrecovered read error" */
520 *ascq = 0x04; /* "auto-reallocation failed" */
521
522 translate_done:
523 printk(KERN_ERR "ata%u: translated ATA stat/err 0x%02x/%02x to "
524 "SCSI SK/ASC/ASCQ 0x%x/%02x/%02x\n", id, drv_stat, drv_err,
525 *sk, *asc, *ascq);
526 return;
527}
528
529/*
530 * ata_gen_ata_desc_sense - Generate check condition sense block.
531 * @qc: Command that completed.
532 *
533 * This function is specific to the ATA descriptor format sense
534 * block specified for the ATA pass through commands. Regardless
535 * of whether the command errored or not, return a sense
536 * block. Copy all controller registers into the sense
537 * block. Clear sense key, ASC & ASCQ if there is no error.
538 *
539 * LOCKING:
540 * spin_lock_irqsave(host_set lock)
541 */
542void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc)
543{
544 struct scsi_cmnd *cmd = qc->scsicmd;
545 struct ata_taskfile *tf = &qc->tf;
546 unsigned char *sb = cmd->sense_buffer;
547 unsigned char *desc = sb + 8;
548
549 memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
550
551 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
552
553 /*
554 * Read the controller registers.
555 */
556 assert(NULL != qc->ap->ops->tf_read);
557 qc->ap->ops->tf_read(qc->ap, tf);
558
559 /*
560 * Use ata_to_sense_error() to map status register bits
561 * onto sense key, asc & ascq.
562 */
563 if (tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) {
564 ata_to_sense_error(qc->ap->id, tf->command, tf->feature,
565 &sb[1], &sb[2], &sb[3]);
566 sb[1] &= 0x0f;
250 } 567 }
251 else { 568
252 if(drv_stat & 0x40) printk("DriveReady "); 569 /*
253 if(drv_stat & 0x20) printk("DeviceFault "); 570 * Sense data is current and format is descriptor.
254 if(drv_stat & 0x10) printk("SeekComplete "); 571 */
255 if(drv_stat & 0x08) printk("DataRequest "); 572 sb[0] = 0x72;
256 if(drv_stat & 0x04) printk("CorrectedError "); 573
257 if(drv_stat & 0x02) printk("Index "); 574 desc[0] = 0x09;
258 if(drv_stat & 0x01) printk("Error "); 575
576 /*
577 * Set length of additional sense data.
578 * Since we only populate descriptor 0, the total
579 * length is the same (fixed) length as descriptor 0.
580 */
581 desc[1] = sb[7] = 14;
582
583 /*
584 * Copy registers into sense buffer.
585 */
586 desc[2] = 0x00;
587 desc[3] = tf->feature; /* == error reg */
588 desc[5] = tf->nsect;
589 desc[7] = tf->lbal;
590 desc[9] = tf->lbam;
591 desc[11] = tf->lbah;
592 desc[12] = tf->device;
593 desc[13] = tf->command; /* == status reg */
594
595 /*
596 * Fill in Extend bit, and the high order bytes
597 * if applicable.
598 */
599 if (tf->flags & ATA_TFLAG_LBA48) {
600 desc[2] |= 0x01;
601 desc[4] = tf->hob_nsect;
602 desc[6] = tf->hob_lbal;
603 desc[8] = tf->hob_lbam;
604 desc[10] = tf->hob_lbah;
259 } 605 }
260 printk("}\n"); 606}
261
262 if(err)
263 {
264 printk(KERN_WARNING "ata%u: error=0x%02x { ", qc->ap->id, err);
265 if(err & 0x04) printk("DriveStatusError ");
266 if(err & 0x80)
267 {
268 if(err & 0x04)
269 printk("BadCRC ");
270 else
271 printk("Sector ");
272 }
273 if(err & 0x40) printk("UncorrectableError ");
274 if(err & 0x10) printk("SectorIdNotFound ");
275 if(err & 0x02) printk("TrackZeroNotFound ");
276 if(err & 0x01) printk("AddrMarkNotFound ");
277 printk("}\n");
278 607
279 /* Should we dump sector info here too ?? */ 608/**
609 * ata_gen_fixed_sense - generate a SCSI fixed sense block
610 * @qc: Command that we are erroring out
611 *
612 * Leverage ata_to_sense_error() to give us the codes. Fit our
613 * LBA in here if there's room.
614 *
615 * LOCKING:
616 * inherited from caller
617 */
618void ata_gen_fixed_sense(struct ata_queued_cmd *qc)
619{
620 struct scsi_cmnd *cmd = qc->scsicmd;
621 struct ata_taskfile *tf = &qc->tf;
622 unsigned char *sb = cmd->sense_buffer;
623
624 memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
625
626 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
627
628 /*
629 * Read the controller registers.
630 */
631 assert(NULL != qc->ap->ops->tf_read);
632 qc->ap->ops->tf_read(qc->ap, tf);
633
634 /*
635 * Use ata_to_sense_error() to map status register bits
636 * onto sense key, asc & ascq.
637 */
638 if (tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) {
639 ata_to_sense_error(qc->ap->id, tf->command, tf->feature,
640 &sb[2], &sb[12], &sb[13]);
641 sb[2] &= 0x0f;
280 } 642 }
281 643
644 sb[0] = 0x70;
645 sb[7] = 0x0a;
282 646
283 /* Look for err */ 647 if (tf->flags & ATA_TFLAG_LBA48) {
284 while(sense_table[i][0] != 0xFF) 648 /* TODO: find solution for LBA48 descriptors */
285 {
286 /* Look for best matches first */
287 if((sense_table[i][0] & err) == sense_table[i][0])
288 {
289 ata_scsi_set_sense(cmd, sense_table[i][1] /* sk */,
290 sense_table[i][2] /* asc */,
291 sense_table[i][3] /* ascq */ );
292 return;
293 }
294 i++;
295 } 649 }
296 /* No immediate match */
297 if(err)
298 printk(KERN_DEBUG "ata%u: no sense translation for 0x%02x\n", qc->ap->id, err);
299 650
300 i = 0; 651 else if (tf->flags & ATA_TFLAG_LBA) {
301 /* Fall back to interpreting status bits */ 652 /* A small (28b) LBA will fit in the 32b info field */
302 while(stat_table[i][0] != 0xFF) 653 sb[0] |= 0x80; /* set valid bit */
303 { 654 sb[3] = tf->device & 0x0f;
304 if(stat_table[i][0] & drv_stat) 655 sb[4] = tf->lbah;
305 { 656 sb[5] = tf->lbam;
306 ata_scsi_set_sense(cmd, sense_table[i][1] /* sk */, 657 sb[6] = tf->lbal;
307 sense_table[i][2] /* asc */,
308 sense_table[i][3] /* ascq */ );
309 return;
310 }
311 i++;
312 } 658 }
313 /* No error ?? */
314 printk(KERN_ERR "ata%u: called with no error (%02X)!\n", qc->ap->id, drv_stat);
315 /* additional-sense-code[-qualifier] */
316 659
317 if (cmd->sc_data_direction == DMA_FROM_DEVICE) { 660 else {
318 ata_scsi_set_sense(cmd, MEDIUM_ERROR, 0x11, 0x4); 661 /* TODO: C/H/S */
319 /* "unrecovered read error" */
320 } else {
321 ata_scsi_set_sense(cmd, MEDIUM_ERROR, 0xc, 0x2);
322 /* "write error - auto-reallocation failed" */
323 } 662 }
324} 663}
325 664
@@ -868,14 +1207,41 @@ nothing_to_do:
868 return 1; 1207 return 1;
869} 1208}
870 1209
871static int ata_scsi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) 1210static int ata_scsi_qc_complete(struct ata_queued_cmd *qc,
1211 unsigned int err_mask)
872{ 1212{
873 struct scsi_cmnd *cmd = qc->scsicmd; 1213 struct scsi_cmnd *cmd = qc->scsicmd;
1214 u8 *cdb = cmd->cmnd;
1215 int need_sense = (err_mask != 0);
1216
1217 /* For ATA pass thru (SAT) commands, generate a sense block if
1218 * user mandated it or if there's an error. Note that if we
1219 * generate because the user forced us to, a check condition
1220 * is generated and the ATA register values are returned
1221 * whether the command completed successfully or not. If there
1222 * was no error, SK, ASC and ASCQ will all be zero.
1223 */
1224 if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) &&
1225 ((cdb[2] & 0x20) || need_sense)) {
1226 ata_gen_ata_desc_sense(qc);
1227 } else {
1228 if (!need_sense) {
1229 cmd->result = SAM_STAT_GOOD;
1230 } else {
1231 /* TODO: decide which descriptor format to use
1232 * for 48b LBA devices and call that here
1233 * instead of the fixed desc, which is only
1234 * good for smaller LBA (and maybe CHS?)
1235 * devices.
1236 */
1237 ata_gen_fixed_sense(qc);
1238 }
1239 }
874 1240
875 if (unlikely(drv_stat & (ATA_ERR | ATA_BUSY | ATA_DRQ))) 1241 if (need_sense) {
876 ata_to_sense_error(qc, drv_stat); 1242 /* The ata_gen_..._sense routines fill in tf */
877 else 1243 ata_dump_status(qc->ap->id, &qc->tf);
878 cmd->result = SAM_STAT_GOOD; 1244 }
879 1245
880 qc->scsidone(cmd); 1246 qc->scsidone(cmd);
881 1247
@@ -1266,13 +1632,9 @@ static void ata_msense_push(u8 **ptr_io, const u8 *last,
1266static unsigned int ata_msense_caching(u16 *id, u8 **ptr_io, 1632static unsigned int ata_msense_caching(u16 *id, u8 **ptr_io,
1267 const u8 *last) 1633 const u8 *last)
1268{ 1634{
1269 u8 page[] = { 1635 u8 page[CACHE_MPAGE_LEN];
1270 0x8, /* page code */
1271 0x12, /* page length */
1272 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10 zeroes */
1273 0, 0, 0, 0, 0, 0, 0, 0 /* 8 zeroes */
1274 };
1275 1636
1637 memcpy(page, def_cache_mpage, sizeof(page));
1276 if (ata_id_wcache_enabled(id)) 1638 if (ata_id_wcache_enabled(id))
1277 page[2] |= (1 << 2); /* write cache enable */ 1639 page[2] |= (1 << 2); /* write cache enable */
1278 if (!ata_id_rahead_enabled(id)) 1640 if (!ata_id_rahead_enabled(id))
@@ -1296,15 +1658,9 @@ static unsigned int ata_msense_caching(u16 *id, u8 **ptr_io,
1296 1658
1297static unsigned int ata_msense_ctl_mode(u8 **ptr_io, const u8 *last) 1659static unsigned int ata_msense_ctl_mode(u8 **ptr_io, const u8 *last)
1298{ 1660{
1299 const u8 page[] = {0xa, 0xa, 6, 0, 0, 0, 0, 0, 0xff, 0xff, 0, 30}; 1661 ata_msense_push(ptr_io, last, def_control_mpage,
1300 1662 sizeof(def_control_mpage));
1301 /* byte 2: set the descriptor format sense data bit (bit 2) 1663 return sizeof(def_control_mpage);
1302 * since we need to support returning this format for SAT
1303 * commands and any SCSI commands against a 48b LBA device.
1304 */
1305
1306 ata_msense_push(ptr_io, last, page, sizeof(page));
1307 return sizeof(page);
1308} 1664}
1309 1665
1310/** 1666/**
@@ -1321,15 +1677,10 @@ static unsigned int ata_msense_ctl_mode(u8 **ptr_io, const u8 *last)
1321 1677
1322static unsigned int ata_msense_rw_recovery(u8 **ptr_io, const u8 *last) 1678static unsigned int ata_msense_rw_recovery(u8 **ptr_io, const u8 *last)
1323{ 1679{
1324 const u8 page[] = {
1325 0x1, /* page code */
1326 0xa, /* page length */
1327 (1 << 7) | (1 << 6), /* note auto r/w reallocation */
1328 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 9 zeroes */
1329 };
1330 1680
1331 ata_msense_push(ptr_io, last, page, sizeof(page)); 1681 ata_msense_push(ptr_io, last, def_rw_recovery_mpage,
1332 return sizeof(page); 1682 sizeof(def_rw_recovery_mpage));
1683 return sizeof(def_rw_recovery_mpage);
1333} 1684}
1334 1685
1335/** 1686/**
@@ -1338,7 +1689,9 @@ static unsigned int ata_msense_rw_recovery(u8 **ptr_io, const u8 *last)
1338 * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. 1689 * @rbuf: Response buffer, to which simulated SCSI cmd output is sent.
1339 * @buflen: Response buffer length. 1690 * @buflen: Response buffer length.
1340 * 1691 *
1341 * Simulate MODE SENSE commands. 1692 * Simulate MODE SENSE commands. Assume this is invoked for direct
1693 * access devices (e.g. disks) only. There should be no block
1694 * descriptor for other device types.
1342 * 1695 *
1343 * LOCKING: 1696 * LOCKING:
1344 * spin_lock_irqsave(host_set lock) 1697 * spin_lock_irqsave(host_set lock)
@@ -1348,15 +1701,22 @@ unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf,
1348 unsigned int buflen) 1701 unsigned int buflen)
1349{ 1702{
1350 u8 *scsicmd = args->cmd->cmnd, *p, *last; 1703 u8 *scsicmd = args->cmd->cmnd, *p, *last;
1351 unsigned int page_control, six_byte, output_len; 1704 const u8 sat_blk_desc[] = {
1705 0, 0, 0, 0, /* number of blocks: sat unspecified */
1706 0,
1707 0, 0x2, 0x0 /* block length: 512 bytes */
1708 };
1709 u8 pg, spg;
1710 unsigned int ebd, page_control, six_byte, output_len, alloc_len, minlen;
1352 1711
1353 VPRINTK("ENTER\n"); 1712 VPRINTK("ENTER\n");
1354 1713
1355 six_byte = (scsicmd[0] == MODE_SENSE); 1714 six_byte = (scsicmd[0] == MODE_SENSE);
1356 1715 ebd = !(scsicmd[1] & 0x8); /* dbd bit inverted == edb */
1357 /* we only support saved and current values (which we treat 1716 /*
1358 * in the same manner) 1717 * LLBA bit in msense(10) ignored (compliant)
1359 */ 1718 */
1719
1360 page_control = scsicmd[2] >> 6; 1720 page_control = scsicmd[2] >> 6;
1361 switch (page_control) { 1721 switch (page_control) {
1362 case 0: /* current */ 1722 case 0: /* current */
@@ -1369,29 +1729,42 @@ unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf,
1369 goto invalid_fld; 1729 goto invalid_fld;
1370 } 1730 }
1371 1731
1372 if (six_byte) 1732 if (six_byte) {
1373 output_len = 4; 1733 output_len = 4 + (ebd ? 8 : 0);
1374 else 1734 alloc_len = scsicmd[4];
1375 output_len = 8; 1735 } else {
1736 output_len = 8 + (ebd ? 8 : 0);
1737 alloc_len = (scsicmd[7] << 8) + scsicmd[8];
1738 }
1739 minlen = (alloc_len < buflen) ? alloc_len : buflen;
1376 1740
1377 p = rbuf + output_len; 1741 p = rbuf + output_len;
1378 last = rbuf + buflen - 1; 1742 last = rbuf + minlen - 1;
1379 1743
1380 switch(scsicmd[2] & 0x3f) { 1744 pg = scsicmd[2] & 0x3f;
1381 case 0x01: /* r/w error recovery */ 1745 spg = scsicmd[3];
1746 /*
1747 * No mode subpages supported (yet) but asking for _all_
1748 * subpages may be valid
1749 */
1750 if (spg && (spg != ALL_SUB_MPAGES))
1751 goto invalid_fld;
1752
1753 switch(pg) {
1754 case RW_RECOVERY_MPAGE:
1382 output_len += ata_msense_rw_recovery(&p, last); 1755 output_len += ata_msense_rw_recovery(&p, last);
1383 break; 1756 break;
1384 1757
1385 case 0x08: /* caching */ 1758 case CACHE_MPAGE:
1386 output_len += ata_msense_caching(args->id, &p, last); 1759 output_len += ata_msense_caching(args->id, &p, last);
1387 break; 1760 break;
1388 1761
1389 case 0x0a: { /* control mode */ 1762 case CONTROL_MPAGE: {
1390 output_len += ata_msense_ctl_mode(&p, last); 1763 output_len += ata_msense_ctl_mode(&p, last);
1391 break; 1764 break;
1392 } 1765 }
1393 1766
1394 case 0x3f: /* all pages */ 1767 case ALL_MPAGES:
1395 output_len += ata_msense_rw_recovery(&p, last); 1768 output_len += ata_msense_rw_recovery(&p, last);
1396 output_len += ata_msense_caching(args->id, &p, last); 1769 output_len += ata_msense_caching(args->id, &p, last);
1397 output_len += ata_msense_ctl_mode(&p, last); 1770 output_len += ata_msense_ctl_mode(&p, last);
@@ -1401,15 +1774,31 @@ unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf,
1401 goto invalid_fld; 1774 goto invalid_fld;
1402 } 1775 }
1403 1776
1777 if (minlen < 1)
1778 return 0;
1404 if (six_byte) { 1779 if (six_byte) {
1405 output_len--; 1780 output_len--;
1406 rbuf[0] = output_len; 1781 rbuf[0] = output_len;
1782 if (ebd) {
1783 if (minlen > 3)
1784 rbuf[3] = sizeof(sat_blk_desc);
1785 if (minlen > 11)
1786 memcpy(rbuf + 4, sat_blk_desc,
1787 sizeof(sat_blk_desc));
1788 }
1407 } else { 1789 } else {
1408 output_len -= 2; 1790 output_len -= 2;
1409 rbuf[0] = output_len >> 8; 1791 rbuf[0] = output_len >> 8;
1410 rbuf[1] = output_len; 1792 if (minlen > 1)
1793 rbuf[1] = output_len;
1794 if (ebd) {
1795 if (minlen > 7)
1796 rbuf[7] = sizeof(sat_blk_desc);
1797 if (minlen > 15)
1798 memcpy(rbuf + 8, sat_blk_desc,
1799 sizeof(sat_blk_desc));
1800 }
1411 } 1801 }
1412
1413 return 0; 1802 return 0;
1414 1803
1415invalid_fld: 1804invalid_fld:
@@ -1616,16 +2005,13 @@ void atapi_request_sense(struct ata_port *ap, struct ata_device *dev,
1616 DPRINTK("EXIT\n"); 2005 DPRINTK("EXIT\n");
1617} 2006}
1618 2007
1619static int atapi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) 2008static int atapi_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask)
1620{ 2009{
1621 struct scsi_cmnd *cmd = qc->scsicmd; 2010 struct scsi_cmnd *cmd = qc->scsicmd;
1622 2011
1623 VPRINTK("ENTER, drv_stat == 0x%x\n", drv_stat); 2012 VPRINTK("ENTER, err_mask 0x%X\n", err_mask);
1624
1625 if (unlikely(drv_stat & (ATA_BUSY | ATA_DRQ)))
1626 ata_to_sense_error(qc, drv_stat);
1627 2013
1628 else if (unlikely(drv_stat & ATA_ERR)) { 2014 if (unlikely(err_mask & AC_ERR_DEV)) {
1629 DPRINTK("request check condition\n"); 2015 DPRINTK("request check condition\n");
1630 2016
1631 /* FIXME: command completion with check condition 2017 /* FIXME: command completion with check condition
@@ -1642,6 +2028,14 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
1642 return 1; 2028 return 1;
1643 } 2029 }
1644 2030
2031 else if (unlikely(err_mask))
2032 /* FIXME: not quite right; we don't want the
2033 * translation of taskfile registers into
2034 * a sense descriptors, since that's only
2035 * correct for ATA, not ATAPI
2036 */
2037 ata_gen_ata_desc_sense(qc);
2038
1645 else { 2039 else {
1646 u8 *scsicmd = cmd->cmnd; 2040 u8 *scsicmd = cmd->cmnd;
1647 2041
@@ -1782,6 +2176,143 @@ ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev)
1782 return dev; 2176 return dev;
1783} 2177}
1784 2178
2179/*
2180 * ata_scsi_map_proto - Map pass-thru protocol value to taskfile value.
2181 * @byte1: Byte 1 from pass-thru CDB.
2182 *
2183 * RETURNS:
2184 * ATA_PROT_UNKNOWN if mapping failed/unimplemented, protocol otherwise.
2185 */
2186static u8
2187ata_scsi_map_proto(u8 byte1)
2188{
2189 switch((byte1 & 0x1e) >> 1) {
2190 case 3: /* Non-data */
2191 return ATA_PROT_NODATA;
2192
2193 case 6: /* DMA */
2194 return ATA_PROT_DMA;
2195
2196 case 4: /* PIO Data-in */
2197 case 5: /* PIO Data-out */
2198 if (byte1 & 0xe0) {
2199 return ATA_PROT_PIO_MULT;
2200 }
2201 return ATA_PROT_PIO;
2202
2203 case 10: /* Device Reset */
2204 case 0: /* Hard Reset */
2205 case 1: /* SRST */
2206 case 2: /* Bus Idle */
2207 case 7: /* Packet */
2208 case 8: /* DMA Queued */
2209 case 9: /* Device Diagnostic */
2210 case 11: /* UDMA Data-in */
2211 case 12: /* UDMA Data-Out */
2212 case 13: /* FPDMA */
2213 default: /* Reserved */
2214 break;
2215 }
2216
2217 return ATA_PROT_UNKNOWN;
2218}
2219
2220/**
2221 * ata_scsi_pass_thru - convert ATA pass-thru CDB to taskfile
2222 * @qc: command structure to be initialized
2223 * @cmd: SCSI command to convert
2224 *
2225 * Handles either 12 or 16-byte versions of the CDB.
2226 *
2227 * RETURNS:
2228 * Zero on success, non-zero on failure.
2229 */
2230static unsigned int
2231ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2232{
2233 struct ata_taskfile *tf = &(qc->tf);
2234 struct scsi_cmnd *cmd = qc->scsicmd;
2235
2236 if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN)
2237 return 1;
2238
2239 /*
2240 * 12 and 16 byte CDBs use different offsets to
2241 * provide the various register values.
2242 */
2243 if (scsicmd[0] == ATA_16) {
2244 /*
2245 * 16-byte CDB - may contain extended commands.
2246 *
2247 * If that is the case, copy the upper byte register values.
2248 */
2249 if (scsicmd[1] & 0x01) {
2250 tf->hob_feature = scsicmd[3];
2251 tf->hob_nsect = scsicmd[5];
2252 tf->hob_lbal = scsicmd[7];
2253 tf->hob_lbam = scsicmd[9];
2254 tf->hob_lbah = scsicmd[11];
2255 tf->flags |= ATA_TFLAG_LBA48;
2256 } else
2257 tf->flags &= ~ATA_TFLAG_LBA48;
2258
2259 /*
2260 * Always copy low byte, device and command registers.
2261 */
2262 tf->feature = scsicmd[4];
2263 tf->nsect = scsicmd[6];
2264 tf->lbal = scsicmd[8];
2265 tf->lbam = scsicmd[10];
2266 tf->lbah = scsicmd[12];
2267 tf->device = scsicmd[13];
2268 tf->command = scsicmd[14];
2269 } else {
2270 /*
2271 * 12-byte CDB - incapable of extended commands.
2272 */
2273 tf->flags &= ~ATA_TFLAG_LBA48;
2274
2275 tf->feature = scsicmd[3];
2276 tf->nsect = scsicmd[4];
2277 tf->lbal = scsicmd[5];
2278 tf->lbam = scsicmd[6];
2279 tf->lbah = scsicmd[7];
2280 tf->device = scsicmd[8];
2281 tf->command = scsicmd[9];
2282 }
2283
2284 /*
2285 * Filter SET_FEATURES - XFER MODE command -- otherwise,
2286 * SET_FEATURES - XFER MODE must be preceded/succeeded
2287 * by an update to hardware-specific registers for each
2288 * controller (i.e. the reason for ->set_piomode(),
2289 * ->set_dmamode(), and ->post_set_mode() hooks).
2290 */
2291 if ((tf->command == ATA_CMD_SET_FEATURES)
2292 && (tf->feature == SETFEATURES_XFER))
2293 return 1;
2294
2295 /*
2296 * Set flags so that all registers will be written,
2297 * and pass on write indication (used for PIO/DMA
2298 * setup.)
2299 */
2300 tf->flags |= (ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE);
2301
2302 if (cmd->sc_data_direction == DMA_TO_DEVICE)
2303 tf->flags |= ATA_TFLAG_WRITE;
2304
2305 /*
2306 * Set transfer length.
2307 *
2308 * TODO: find out if we need to do more here to
2309 * cover scatter/gather case.
2310 */
2311 qc->nsect = cmd->bufflen / ATA_SECT_SIZE;
2312
2313 return 0;
2314}
2315
1785/** 2316/**
1786 * ata_get_xlat_func - check if SCSI to ATA translation is possible 2317 * ata_get_xlat_func - check if SCSI to ATA translation is possible
1787 * @dev: ATA device 2318 * @dev: ATA device
@@ -1814,6 +2345,11 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd)
1814 case VERIFY: 2345 case VERIFY:
1815 case VERIFY_16: 2346 case VERIFY_16:
1816 return ata_scsi_verify_xlat; 2347 return ata_scsi_verify_xlat;
2348
2349 case ATA_12:
2350 case ATA_16:
2351 return ata_scsi_pass_thru;
2352
1817 case START_STOP: 2353 case START_STOP:
1818 return ata_scsi_start_stop_xlat; 2354 return ata_scsi_start_stop_xlat;
1819 } 2355 }
@@ -1972,7 +2508,7 @@ void ata_scsi_simulate(u16 *id,
1972 ata_scsi_rbuf_fill(&args, ata_scsiop_report_luns); 2508 ata_scsi_rbuf_fill(&args, ata_scsiop_report_luns);
1973 break; 2509 break;
1974 2510
1975 /* mandantory commands we haven't implemented yet */ 2511 /* mandatory commands we haven't implemented yet */
1976 case REQUEST_SENSE: 2512 case REQUEST_SENSE:
1977 2513
1978 /* all other commands */ 2514 /* all other commands */
diff --git a/drivers/scsi/libata.h b/drivers/scsi/libata.h
index 3d60190584ba..10ecd9e15e4f 100644
--- a/drivers/scsi/libata.h
+++ b/drivers/scsi/libata.h
@@ -39,7 +39,7 @@ struct ata_scsi_args {
39 39
40/* libata-core.c */ 40/* libata-core.c */
41extern int atapi_enabled; 41extern int atapi_enabled;
42extern int ata_qc_complete_noop(struct ata_queued_cmd *qc, u8 drv_stat); 42extern int ata_qc_complete_noop(struct ata_queued_cmd *qc, unsigned int err_mask);
43extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, 43extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap,
44 struct ata_device *dev); 44 struct ata_device *dev);
45extern void ata_rwcmd_protocol(struct ata_queued_cmd *qc); 45extern void ata_rwcmd_protocol(struct ata_queued_cmd *qc);
@@ -50,13 +50,14 @@ extern void ata_dev_select(struct ata_port *ap, unsigned int device,
50 unsigned int wait, unsigned int can_sleep); 50 unsigned int wait, unsigned int can_sleep);
51extern void ata_tf_to_host_nolock(struct ata_port *ap, const struct ata_taskfile *tf); 51extern void ata_tf_to_host_nolock(struct ata_port *ap, const struct ata_taskfile *tf);
52extern void swap_buf_le16(u16 *buf, unsigned int buf_words); 52extern void swap_buf_le16(u16 *buf, unsigned int buf_words);
53extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg);
54extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg);
53 55
54 56
55/* libata-scsi.c */ 57/* libata-scsi.c */
56extern void atapi_request_sense(struct ata_port *ap, struct ata_device *dev, 58extern void atapi_request_sense(struct ata_port *ap, struct ata_device *dev,
57 struct scsi_cmnd *cmd); 59 struct scsi_cmnd *cmd);
58extern void ata_scsi_scan_host(struct ata_port *ap); 60extern void ata_scsi_scan_host(struct ata_port *ap);
59extern void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat);
60extern int ata_scsi_error(struct Scsi_Host *host); 61extern int ata_scsi_error(struct Scsi_Host *host);
61extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf, 62extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf,
62 unsigned int buflen); 63 unsigned int buflen);
diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index b235556b7b65..bdccf73cf9fe 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -730,7 +730,7 @@ static void start_phase(struct mesh_state *ms)
730 * issue a SEQ_MSGOUT to get the mesh to drop ACK. 730 * issue a SEQ_MSGOUT to get the mesh to drop ACK.
731 */ 731 */
732 if ((in_8(&mr->bus_status0) & BS0_ATN) == 0) { 732 if ((in_8(&mr->bus_status0) & BS0_ATN) == 0) {
733 dlog(ms, "bus0 was %.2x explictly asserting ATN", mr->bus_status0); 733 dlog(ms, "bus0 was %.2x explicitly asserting ATN", mr->bus_status0);
734 out_8(&mr->bus_status0, BS0_ATN); /* explicit ATN */ 734 out_8(&mr->bus_status0, BS0_ATN); /* explicit ATN */
735 mesh_flush_io(mr); 735 mesh_flush_io(mr);
736 udelay(1); 736 udelay(1);
diff --git a/drivers/scsi/pdc_adma.c b/drivers/scsi/pdc_adma.c
index 9820f272f889..665017eda8a6 100644
--- a/drivers/scsi/pdc_adma.c
+++ b/drivers/scsi/pdc_adma.c
@@ -40,13 +40,14 @@
40#include <linux/delay.h> 40#include <linux/delay.h>
41#include <linux/interrupt.h> 41#include <linux/interrupt.h>
42#include <linux/sched.h> 42#include <linux/sched.h>
43#include <linux/device.h>
43#include "scsi.h" 44#include "scsi.h"
44#include <scsi/scsi_host.h> 45#include <scsi/scsi_host.h>
45#include <asm/io.h> 46#include <asm/io.h>
46#include <linux/libata.h> 47#include <linux/libata.h>
47 48
48#define DRV_NAME "pdc_adma" 49#define DRV_NAME "pdc_adma"
49#define DRV_VERSION "0.01" 50#define DRV_VERSION "0.03"
50 51
51/* macro to calculate base address for ATA regs */ 52/* macro to calculate base address for ATA regs */
52#define ADMA_ATA_REGS(base,port_no) ((base) + ((port_no) * 0x40)) 53#define ADMA_ATA_REGS(base,port_no) ((base) + ((port_no) * 0x40))
@@ -79,7 +80,6 @@ enum {
79 aNIEN = (1 << 8), /* irq mask: 1==masked */ 80 aNIEN = (1 << 8), /* irq mask: 1==masked */
80 aGO = (1 << 7), /* packet trigger ("Go!") */ 81 aGO = (1 << 7), /* packet trigger ("Go!") */
81 aRSTADM = (1 << 5), /* ADMA logic reset */ 82 aRSTADM = (1 << 5), /* ADMA logic reset */
82 aRSTA = (1 << 2), /* ATA hard reset */
83 aPIOMD4 = 0x0003, /* PIO mode 4 */ 83 aPIOMD4 = 0x0003, /* PIO mode 4 */
84 84
85 /* ADMA_STATUS register bits */ 85 /* ADMA_STATUS register bits */
@@ -452,24 +452,28 @@ static inline unsigned int adma_intr_pkt(struct ata_host_set *host_set)
452 struct adma_port_priv *pp; 452 struct adma_port_priv *pp;
453 struct ata_queued_cmd *qc; 453 struct ata_queued_cmd *qc;
454 void __iomem *chan = ADMA_REGS(mmio_base, port_no); 454 void __iomem *chan = ADMA_REGS(mmio_base, port_no);
455 u8 drv_stat, status = readb(chan + ADMA_STATUS); 455 u8 status = readb(chan + ADMA_STATUS);
456 456
457 if (status == 0) 457 if (status == 0)
458 continue; 458 continue;
459 handled = 1; 459 handled = 1;
460 adma_enter_reg_mode(ap); 460 adma_enter_reg_mode(ap);
461 if ((ap->flags & ATA_FLAG_PORT_DISABLED)) 461 if (ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))
462 continue; 462 continue;
463 pp = ap->private_data; 463 pp = ap->private_data;
464 if (!pp || pp->state != adma_state_pkt) 464 if (!pp || pp->state != adma_state_pkt)
465 continue; 465 continue;
466 qc = ata_qc_from_tag(ap, ap->active_tag); 466 qc = ata_qc_from_tag(ap, ap->active_tag);
467 drv_stat = 0; 467 if (qc && (!(qc->tf.ctl & ATA_NIEN))) {
468 if ((status & (aPERR | aPSD | aUIRQ))) 468 unsigned int err_mask = 0;
469 drv_stat = ATA_ERR; 469
470 else if (pp->pkt[0] != cDONE) 470 if ((status & (aPERR | aPSD | aUIRQ)))
471 drv_stat = ATA_ERR; 471 err_mask = AC_ERR_OTHER;
472 ata_qc_complete(qc, drv_stat); 472 else if (pp->pkt[0] != cDONE)
473 err_mask = AC_ERR_OTHER;
474
475 ata_qc_complete(qc, err_mask);
476 }
473 } 477 }
474 return handled; 478 return handled;
475} 479}
@@ -490,7 +494,7 @@ static inline unsigned int adma_intr_mmio(struct ata_host_set *host_set)
490 if (qc && (!(qc->tf.ctl & ATA_NIEN))) { 494 if (qc && (!(qc->tf.ctl & ATA_NIEN))) {
491 495
492 /* check main status, clearing INTRQ */ 496 /* check main status, clearing INTRQ */
493 u8 status = ata_chk_status(ap); 497 u8 status = ata_check_status(ap);
494 if ((status & ATA_BUSY)) 498 if ((status & ATA_BUSY))
495 continue; 499 continue;
496 DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n", 500 DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n",
@@ -498,7 +502,7 @@ static inline unsigned int adma_intr_mmio(struct ata_host_set *host_set)
498 502
499 /* complete taskfile transaction */ 503 /* complete taskfile transaction */
500 pp->state = adma_state_idle; 504 pp->state = adma_state_idle;
501 ata_qc_complete(qc, status); 505 ata_qc_complete(qc, ac_err_mask(status));
502 handled = 1; 506 handled = 1;
503 } 507 }
504 } 508 }
@@ -561,15 +565,15 @@ static int adma_port_start(struct ata_port *ap)
561 if ((pp->pkt_dma & 7) != 0) { 565 if ((pp->pkt_dma & 7) != 0) {
562 printk("bad alignment for pp->pkt_dma: %08x\n", 566 printk("bad alignment for pp->pkt_dma: %08x\n",
563 (u32)pp->pkt_dma); 567 (u32)pp->pkt_dma);
564 goto err_out_kfree2; 568 dma_free_coherent(dev, ADMA_PKT_BYTES,
569 pp->pkt, pp->pkt_dma);
570 goto err_out_kfree;
565 } 571 }
566 memset(pp->pkt, 0, ADMA_PKT_BYTES); 572 memset(pp->pkt, 0, ADMA_PKT_BYTES);
567 ap->private_data = pp; 573 ap->private_data = pp;
568 adma_reinit_engine(ap); 574 adma_reinit_engine(ap);
569 return 0; 575 return 0;
570 576
571err_out_kfree2:
572 kfree(pp);
573err_out_kfree: 577err_out_kfree:
574 kfree(pp); 578 kfree(pp);
575err_out: 579err_out:
@@ -623,16 +627,14 @@ static int adma_set_dma_masks(struct pci_dev *pdev, void __iomem *mmio_base)
623 627
624 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 628 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
625 if (rc) { 629 if (rc) {
626 printk(KERN_ERR DRV_NAME 630 dev_printk(KERN_ERR, &pdev->dev,
627 "(%s): 32-bit DMA enable failed\n", 631 "32-bit DMA enable failed\n");
628 pci_name(pdev));
629 return rc; 632 return rc;
630 } 633 }
631 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 634 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
632 if (rc) { 635 if (rc) {
633 printk(KERN_ERR DRV_NAME 636 dev_printk(KERN_ERR, &pdev->dev,
634 "(%s): 32-bit consistent DMA enable failed\n", 637 "32-bit consistent DMA enable failed\n");
635 pci_name(pdev));
636 return rc; 638 return rc;
637 } 639 }
638 return 0; 640 return 0;
@@ -648,7 +650,7 @@ static int adma_ata_init_one(struct pci_dev *pdev,
648 int rc, port_no; 650 int rc, port_no;
649 651
650 if (!printed_version++) 652 if (!printed_version++)
651 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 653 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
652 654
653 rc = pci_enable_device(pdev); 655 rc = pci_enable_device(pdev);
654 if (rc) 656 if (rc)
diff --git a/drivers/scsi/sata_mv.c b/drivers/scsi/sata_mv.c
index 422e0b6f603a..46dbdee79f77 100644
--- a/drivers/scsi/sata_mv.c
+++ b/drivers/scsi/sata_mv.c
@@ -29,6 +29,7 @@
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30#include <linux/sched.h> 30#include <linux/sched.h>
31#include <linux/dma-mapping.h> 31#include <linux/dma-mapping.h>
32#include <linux/device.h>
32#include "scsi.h" 33#include "scsi.h"
33#include <scsi/scsi_host.h> 34#include <scsi/scsi_host.h>
34#include <linux/libata.h> 35#include <linux/libata.h>
@@ -258,7 +259,6 @@ struct mv_host_priv {
258static void mv_irq_clear(struct ata_port *ap); 259static void mv_irq_clear(struct ata_port *ap);
259static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in); 260static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in);
260static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 261static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
261static u8 mv_check_err(struct ata_port *ap);
262static void mv_phy_reset(struct ata_port *ap); 262static void mv_phy_reset(struct ata_port *ap);
263static void mv_host_stop(struct ata_host_set *host_set); 263static void mv_host_stop(struct ata_host_set *host_set);
264static int mv_port_start(struct ata_port *ap); 264static int mv_port_start(struct ata_port *ap);
@@ -296,7 +296,6 @@ static const struct ata_port_operations mv_ops = {
296 .tf_load = ata_tf_load, 296 .tf_load = ata_tf_load,
297 .tf_read = ata_tf_read, 297 .tf_read = ata_tf_read,
298 .check_status = ata_check_status, 298 .check_status = ata_check_status,
299 .check_err = mv_check_err,
300 .exec_command = ata_exec_command, 299 .exec_command = ata_exec_command,
301 .dev_select = ata_std_dev_select, 300 .dev_select = ata_std_dev_select,
302 301
@@ -1067,6 +1066,7 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1067 struct ata_queued_cmd *qc; 1066 struct ata_queued_cmd *qc;
1068 u32 hc_irq_cause; 1067 u32 hc_irq_cause;
1069 int shift, port, port0, hard_port, handled; 1068 int shift, port, port0, hard_port, handled;
1069 unsigned int err_mask;
1070 u8 ata_status = 0; 1070 u8 ata_status = 0;
1071 1071
1072 if (hc == 0) { 1072 if (hc == 0) {
@@ -1102,15 +1102,15 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1102 handled++; 1102 handled++;
1103 } 1103 }
1104 1104
1105 err_mask = ac_err_mask(ata_status);
1106
1105 shift = port << 1; /* (port * 2) */ 1107 shift = port << 1; /* (port * 2) */
1106 if (port >= MV_PORTS_PER_HC) { 1108 if (port >= MV_PORTS_PER_HC) {
1107 shift++; /* skip bit 8 in the HC Main IRQ reg */ 1109 shift++; /* skip bit 8 in the HC Main IRQ reg */
1108 } 1110 }
1109 if ((PORT0_ERR << shift) & relevant) { 1111 if ((PORT0_ERR << shift) & relevant) {
1110 mv_err_intr(ap); 1112 mv_err_intr(ap);
1111 /* OR in ATA_ERR to ensure libata knows we took one */ 1113 err_mask |= AC_ERR_OTHER;
1112 ata_status = readb((void __iomem *)
1113 ap->ioaddr.status_addr) | ATA_ERR;
1114 handled++; 1114 handled++;
1115 } 1115 }
1116 1116
@@ -1120,7 +1120,7 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1120 VPRINTK("port %u IRQ found for qc, " 1120 VPRINTK("port %u IRQ found for qc, "
1121 "ata_status 0x%x\n", port,ata_status); 1121 "ata_status 0x%x\n", port,ata_status);
1122 /* mark qc status appropriately */ 1122 /* mark qc status appropriately */
1123 ata_qc_complete(qc, ata_status); 1123 ata_qc_complete(qc, err_mask);
1124 } 1124 }
1125 } 1125 }
1126 } 1126 }
@@ -1185,22 +1185,6 @@ static irqreturn_t mv_interrupt(int irq, void *dev_instance,
1185} 1185}
1186 1186
1187/** 1187/**
1188 * mv_check_err - Return the error shadow register to caller.
1189 * @ap: ATA channel to manipulate
1190 *
1191 * Marvell requires DMA to be stopped before accessing shadow
1192 * registers. So we do that, then return the needed register.
1193 *
1194 * LOCKING:
1195 * Inherited from caller. FIXME: protect mv_stop_dma with lock?
1196 */
1197static u8 mv_check_err(struct ata_port *ap)
1198{
1199 mv_stop_dma(ap); /* can't read shadow regs if DMA on */
1200 return readb((void __iomem *) ap->ioaddr.error_addr);
1201}
1202
1203/**
1204 * mv_phy_reset - Perform eDMA reset followed by COMRESET 1188 * mv_phy_reset - Perform eDMA reset followed by COMRESET
1205 * @ap: ATA channel to manipulate 1189 * @ap: ATA channel to manipulate
1206 * 1190 *
@@ -1312,7 +1296,7 @@ static void mv_eng_timeout(struct ata_port *ap)
1312 */ 1296 */
1313 spin_lock_irqsave(&ap->host_set->lock, flags); 1297 spin_lock_irqsave(&ap->host_set->lock, flags);
1314 qc->scsidone = scsi_finish_command; 1298 qc->scsidone = scsi_finish_command;
1315 ata_qc_complete(qc, ATA_ERR); 1299 ata_qc_complete(qc, AC_ERR_OTHER);
1316 spin_unlock_irqrestore(&ap->host_set->lock, flags); 1300 spin_unlock_irqrestore(&ap->host_set->lock, flags);
1317 } 1301 }
1318} 1302}
@@ -1454,9 +1438,9 @@ static void mv_print_info(struct ata_probe_ent *probe_ent)
1454 else 1438 else
1455 scc_s = "unknown"; 1439 scc_s = "unknown";
1456 1440
1457 printk(KERN_INFO DRV_NAME 1441 dev_printk(KERN_INFO, &pdev->dev,
1458 "(%s) %u slots %u ports %s mode IRQ via %s\n", 1442 "%u slots %u ports %s mode IRQ via %s\n",
1459 pci_name(pdev), (unsigned)MV_MAX_Q_DEPTH, probe_ent->n_ports, 1443 (unsigned)MV_MAX_Q_DEPTH, probe_ent->n_ports,
1460 scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx"); 1444 scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx");
1461} 1445}
1462 1446
@@ -1477,9 +1461,8 @@ static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1477 void __iomem *mmio_base; 1461 void __iomem *mmio_base;
1478 int pci_dev_busy = 0, rc; 1462 int pci_dev_busy = 0, rc;
1479 1463
1480 if (!printed_version++) { 1464 if (!printed_version++)
1481 printk(KERN_INFO DRV_NAME " version " DRV_VERSION "\n"); 1465 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
1482 }
1483 1466
1484 rc = pci_enable_device(pdev); 1467 rc = pci_enable_device(pdev);
1485 if (rc) { 1468 if (rc) {
diff --git a/drivers/scsi/sata_nv.c b/drivers/scsi/sata_nv.c
index 1a56d6c79ddd..d573888eda76 100644
--- a/drivers/scsi/sata_nv.c
+++ b/drivers/scsi/sata_nv.c
@@ -61,6 +61,7 @@
61#include <linux/blkdev.h> 61#include <linux/blkdev.h>
62#include <linux/delay.h> 62#include <linux/delay.h>
63#include <linux/interrupt.h> 63#include <linux/interrupt.h>
64#include <linux/device.h>
64#include "scsi.h" 65#include "scsi.h"
65#include <scsi/scsi_host.h> 66#include <scsi/scsi_host.h>
66#include <linux/libata.h> 67#include <linux/libata.h>
@@ -383,7 +384,7 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
383 return -ENODEV; 384 return -ENODEV;
384 385
385 if (!printed_version++) 386 if (!printed_version++)
386 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 387 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
387 388
388 rc = pci_enable_device(pdev); 389 rc = pci_enable_device(pdev);
389 if (rc) 390 if (rc)
diff --git a/drivers/scsi/sata_promise.c b/drivers/scsi/sata_promise.c
index eee93b0016df..b41c977d6fab 100644
--- a/drivers/scsi/sata_promise.c
+++ b/drivers/scsi/sata_promise.c
@@ -38,6 +38,7 @@
38#include <linux/delay.h> 38#include <linux/delay.h>
39#include <linux/interrupt.h> 39#include <linux/interrupt.h>
40#include <linux/sched.h> 40#include <linux/sched.h>
41#include <linux/device.h>
41#include "scsi.h" 42#include "scsi.h"
42#include <scsi/scsi_host.h> 43#include <scsi/scsi_host.h>
43#include <linux/libata.h> 44#include <linux/libata.h>
@@ -195,6 +196,8 @@ static struct ata_port_info pdc_port_info[] = {
195static struct pci_device_id pdc_ata_pci_tbl[] = { 196static struct pci_device_id pdc_ata_pci_tbl[] = {
196 { PCI_VENDOR_ID_PROMISE, 0x3371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 197 { PCI_VENDOR_ID_PROMISE, 0x3371, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
197 board_2037x }, 198 board_2037x },
199 { PCI_VENDOR_ID_PROMISE, 0x3570, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
200 board_2037x },
198 { PCI_VENDOR_ID_PROMISE, 0x3571, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 201 { PCI_VENDOR_ID_PROMISE, 0x3571, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
199 board_2037x }, 202 board_2037x },
200 { PCI_VENDOR_ID_PROMISE, 0x3373, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 203 { PCI_VENDOR_ID_PROMISE, 0x3373, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
@@ -207,6 +210,8 @@ static struct pci_device_id pdc_ata_pci_tbl[] = {
207 board_2037x }, 210 board_2037x },
208 { PCI_VENDOR_ID_PROMISE, 0x3d75, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 211 { PCI_VENDOR_ID_PROMISE, 0x3d75, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
209 board_2037x }, 212 board_2037x },
213 { PCI_VENDOR_ID_PROMISE, 0x3d73, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
214 board_2037x },
210 215
211 { PCI_VENDOR_ID_PROMISE, 0x3318, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 216 { PCI_VENDOR_ID_PROMISE, 0x3318, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
212 board_20319 }, 217 board_20319 },
@@ -395,7 +400,8 @@ static void pdc_eng_timeout(struct ata_port *ap)
395 case ATA_PROT_DMA: 400 case ATA_PROT_DMA:
396 case ATA_PROT_NODATA: 401 case ATA_PROT_NODATA:
397 printk(KERN_ERR "ata%u: command timeout\n", ap->id); 402 printk(KERN_ERR "ata%u: command timeout\n", ap->id);
398 ata_qc_complete(qc, ata_wait_idle(ap) | ATA_ERR); 403 drv_stat = ata_wait_idle(ap);
404 ata_qc_complete(qc, __ac_err_mask(drv_stat));
399 break; 405 break;
400 406
401 default: 407 default:
@@ -404,7 +410,7 @@ static void pdc_eng_timeout(struct ata_port *ap)
404 printk(KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n", 410 printk(KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n",
405 ap->id, qc->tf.command, drv_stat); 411 ap->id, qc->tf.command, drv_stat);
406 412
407 ata_qc_complete(qc, drv_stat); 413 ata_qc_complete(qc, ac_err_mask(drv_stat));
408 break; 414 break;
409 } 415 }
410 416
@@ -416,24 +422,21 @@ out:
416static inline unsigned int pdc_host_intr( struct ata_port *ap, 422static inline unsigned int pdc_host_intr( struct ata_port *ap,
417 struct ata_queued_cmd *qc) 423 struct ata_queued_cmd *qc)
418{ 424{
419 u8 status; 425 unsigned int handled = 0, err_mask = 0;
420 unsigned int handled = 0, have_err = 0;
421 u32 tmp; 426 u32 tmp;
422 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL; 427 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL;
423 428
424 tmp = readl(mmio); 429 tmp = readl(mmio);
425 if (tmp & PDC_ERR_MASK) { 430 if (tmp & PDC_ERR_MASK) {
426 have_err = 1; 431 err_mask = AC_ERR_DEV;
427 pdc_reset_port(ap); 432 pdc_reset_port(ap);
428 } 433 }
429 434
430 switch (qc->tf.protocol) { 435 switch (qc->tf.protocol) {
431 case ATA_PROT_DMA: 436 case ATA_PROT_DMA:
432 case ATA_PROT_NODATA: 437 case ATA_PROT_NODATA:
433 status = ata_wait_idle(ap); 438 err_mask |= ac_err_mask(ata_wait_idle(ap));
434 if (have_err) 439 ata_qc_complete(qc, err_mask);
435 status |= ATA_ERR;
436 ata_qc_complete(qc, status);
437 handled = 1; 440 handled = 1;
438 break; 441 break;
439 442
@@ -631,7 +634,7 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
631 int rc; 634 int rc;
632 635
633 if (!printed_version++) 636 if (!printed_version++)
634 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 637 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
635 638
636 /* 639 /*
637 * If this driver happens to only be useful on Apple's K2, then 640 * If this driver happens to only be useful on Apple's K2, then
diff --git a/drivers/scsi/sata_qstor.c b/drivers/scsi/sata_qstor.c
index 250dafa6bc36..9938dae782b6 100644
--- a/drivers/scsi/sata_qstor.c
+++ b/drivers/scsi/sata_qstor.c
@@ -35,6 +35,7 @@
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/interrupt.h> 36#include <linux/interrupt.h>
37#include <linux/sched.h> 37#include <linux/sched.h>
38#include <linux/device.h>
38#include "scsi.h" 39#include "scsi.h"
39#include <scsi/scsi_host.h> 40#include <scsi/scsi_host.h>
40#include <asm/io.h> 41#include <asm/io.h>
@@ -400,11 +401,12 @@ static inline unsigned int qs_intr_pkt(struct ata_host_set *host_set)
400 qc = ata_qc_from_tag(ap, ap->active_tag); 401 qc = ata_qc_from_tag(ap, ap->active_tag);
401 if (qc && (!(qc->tf.ctl & ATA_NIEN))) { 402 if (qc && (!(qc->tf.ctl & ATA_NIEN))) {
402 switch (sHST) { 403 switch (sHST) {
403 case 0: /* sucessful CPB */ 404 case 0: /* successful CPB */
404 case 3: /* device error */ 405 case 3: /* device error */
405 pp->state = qs_state_idle; 406 pp->state = qs_state_idle;
406 qs_enter_reg_mode(qc->ap); 407 qs_enter_reg_mode(qc->ap);
407 ata_qc_complete(qc, sDST); 408 ata_qc_complete(qc,
409 ac_err_mask(sDST));
408 break; 410 break;
409 default: 411 default:
410 break; 412 break;
@@ -433,7 +435,7 @@ static inline unsigned int qs_intr_mmio(struct ata_host_set *host_set)
433 if (qc && (!(qc->tf.ctl & ATA_NIEN))) { 435 if (qc && (!(qc->tf.ctl & ATA_NIEN))) {
434 436
435 /* check main status, clearing INTRQ */ 437 /* check main status, clearing INTRQ */
436 u8 status = ata_chk_status(ap); 438 u8 status = ata_check_status(ap);
437 if ((status & ATA_BUSY)) 439 if ((status & ATA_BUSY))
438 continue; 440 continue;
439 DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n", 441 DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n",
@@ -441,7 +443,7 @@ static inline unsigned int qs_intr_mmio(struct ata_host_set *host_set)
441 443
442 /* complete taskfile transaction */ 444 /* complete taskfile transaction */
443 pp->state = qs_state_idle; 445 pp->state = qs_state_idle;
444 ata_qc_complete(qc, status); 446 ata_qc_complete(qc, ac_err_mask(status));
445 handled = 1; 447 handled = 1;
446 } 448 }
447 } 449 }
@@ -599,25 +601,22 @@ static int qs_set_dma_masks(struct pci_dev *pdev, void __iomem *mmio_base)
599 if (rc) { 601 if (rc) {
600 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 602 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
601 if (rc) { 603 if (rc) {
602 printk(KERN_ERR DRV_NAME 604 dev_printk(KERN_ERR, &pdev->dev,
603 "(%s): 64-bit DMA enable failed\n", 605 "64-bit DMA enable failed\n");
604 pci_name(pdev));
605 return rc; 606 return rc;
606 } 607 }
607 } 608 }
608 } else { 609 } else {
609 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 610 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
610 if (rc) { 611 if (rc) {
611 printk(KERN_ERR DRV_NAME 612 dev_printk(KERN_ERR, &pdev->dev,
612 "(%s): 32-bit DMA enable failed\n", 613 "32-bit DMA enable failed\n");
613 pci_name(pdev));
614 return rc; 614 return rc;
615 } 615 }
616 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 616 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
617 if (rc) { 617 if (rc) {
618 printk(KERN_ERR DRV_NAME 618 dev_printk(KERN_ERR, &pdev->dev,
619 "(%s): 32-bit consistent DMA enable failed\n", 619 "32-bit consistent DMA enable failed\n");
620 pci_name(pdev));
621 return rc; 620 return rc;
622 } 621 }
623 } 622 }
@@ -634,7 +633,7 @@ static int qs_ata_init_one(struct pci_dev *pdev,
634 int rc, port_no; 633 int rc, port_no;
635 634
636 if (!printed_version++) 635 if (!printed_version++)
637 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 636 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
638 637
639 rc = pci_enable_device(pdev); 638 rc = pci_enable_device(pdev);
640 if (rc) 639 if (rc)
diff --git a/drivers/scsi/sata_sil.c b/drivers/scsi/sata_sil.c
index 3a056173fb95..435f7e0085ec 100644
--- a/drivers/scsi/sata_sil.c
+++ b/drivers/scsi/sata_sil.c
@@ -41,6 +41,7 @@
41#include <linux/blkdev.h> 41#include <linux/blkdev.h>
42#include <linux/delay.h> 42#include <linux/delay.h>
43#include <linux/interrupt.h> 43#include <linux/interrupt.h>
44#include <linux/device.h>
44#include "scsi.h" 45#include "scsi.h"
45#include <scsi/scsi_host.h> 46#include <scsi/scsi_host.h>
46#include <linux/libata.h> 47#include <linux/libata.h>
@@ -386,7 +387,7 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
386 u8 cls; 387 u8 cls;
387 388
388 if (!printed_version++) 389 if (!printed_version++)
389 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 390 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
390 391
391 /* 392 /*
392 * If this driver happens to only be useful on Apple's K2, then 393 * If this driver happens to only be useful on Apple's K2, then
@@ -463,8 +464,8 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
463 writeb(cls, mmio_base + SIL_FIFO_W3); 464 writeb(cls, mmio_base + SIL_FIFO_W3);
464 } 465 }
465 } else 466 } else
466 printk(KERN_WARNING DRV_NAME "(%s): cache line size not set. Driver may not function\n", 467 dev_printk(KERN_WARNING, &pdev->dev,
467 pci_name(pdev)); 468 "cache line size not set. Driver may not function\n");
468 469
469 if (ent->driver_data == sil_3114) { 470 if (ent->driver_data == sil_3114) {
470 irq_mask = SIL_MASK_4PORT; 471 irq_mask = SIL_MASK_4PORT;
diff --git a/drivers/scsi/sata_sil24.c b/drivers/scsi/sata_sil24.c
index 32d730bd5bb6..c66548025657 100644
--- a/drivers/scsi/sata_sil24.c
+++ b/drivers/scsi/sata_sil24.c
@@ -35,6 +35,7 @@
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/interrupt.h> 36#include <linux/interrupt.h>
37#include <linux/dma-mapping.h> 37#include <linux/dma-mapping.h>
38#include <linux/device.h>
38#include <scsi/scsi_host.h> 39#include <scsi/scsi_host.h>
39#include "scsi.h" 40#include "scsi.h"
40#include <linux/libata.h> 41#include <linux/libata.h>
@@ -220,12 +221,11 @@ struct sil24_port_priv {
220 221
221/* ap->host_set->private_data */ 222/* ap->host_set->private_data */
222struct sil24_host_priv { 223struct sil24_host_priv {
223 void *host_base; /* global controller control (128 bytes @BAR0) */ 224 void __iomem *host_base; /* global controller control (128 bytes @BAR0) */
224 void *port_base; /* port registers (4 * 8192 bytes @BAR2) */ 225 void __iomem *port_base; /* port registers (4 * 8192 bytes @BAR2) */
225}; 226};
226 227
227static u8 sil24_check_status(struct ata_port *ap); 228static u8 sil24_check_status(struct ata_port *ap);
228static u8 sil24_check_err(struct ata_port *ap);
229static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg); 229static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg);
230static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val); 230static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val);
231static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf); 231static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
@@ -280,7 +280,6 @@ static const struct ata_port_operations sil24_ops = {
280 280
281 .check_status = sil24_check_status, 281 .check_status = sil24_check_status,
282 .check_altstatus = sil24_check_status, 282 .check_altstatus = sil24_check_status,
283 .check_err = sil24_check_err,
284 .dev_select = ata_noop_dev_select, 283 .dev_select = ata_noop_dev_select,
285 284
286 .tf_read = sil24_tf_read, 285 .tf_read = sil24_tf_read,
@@ -349,10 +348,12 @@ static struct ata_port_info sil24_port_info[] = {
349static inline void sil24_update_tf(struct ata_port *ap) 348static inline void sil24_update_tf(struct ata_port *ap)
350{ 349{
351 struct sil24_port_priv *pp = ap->private_data; 350 struct sil24_port_priv *pp = ap->private_data;
352 void *port = (void *)ap->ioaddr.cmd_addr; 351 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
353 struct sil24_prb *prb = port; 352 struct sil24_prb __iomem *prb = port;
353 u8 fis[6 * 4];
354 354
355 ata_tf_from_fis(prb->fis, &pp->tf); 355 memcpy_fromio(fis, prb->fis, 6 * 4);
356 ata_tf_from_fis(fis, &pp->tf);
356} 357}
357 358
358static u8 sil24_check_status(struct ata_port *ap) 359static u8 sil24_check_status(struct ata_port *ap)
@@ -361,12 +362,6 @@ static u8 sil24_check_status(struct ata_port *ap)
361 return pp->tf.command; 362 return pp->tf.command;
362} 363}
363 364
364static u8 sil24_check_err(struct ata_port *ap)
365{
366 struct sil24_port_priv *pp = ap->private_data;
367 return pp->tf.feature;
368}
369
370static int sil24_scr_map[] = { 365static int sil24_scr_map[] = {
371 [SCR_CONTROL] = 0, 366 [SCR_CONTROL] = 0,
372 [SCR_STATUS] = 1, 367 [SCR_STATUS] = 1,
@@ -376,9 +371,9 @@ static int sil24_scr_map[] = {
376 371
377static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg) 372static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg)
378{ 373{
379 void *scr_addr = (void *)ap->ioaddr.scr_addr; 374 void __iomem *scr_addr = (void __iomem *)ap->ioaddr.scr_addr;
380 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) { 375 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) {
381 void *addr; 376 void __iomem *addr;
382 addr = scr_addr + sil24_scr_map[sc_reg] * 4; 377 addr = scr_addr + sil24_scr_map[sc_reg] * 4;
383 return readl(scr_addr + sil24_scr_map[sc_reg] * 4); 378 return readl(scr_addr + sil24_scr_map[sc_reg] * 4);
384 } 379 }
@@ -387,9 +382,9 @@ static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg)
387 382
388static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val) 383static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val)
389{ 384{
390 void *scr_addr = (void *)ap->ioaddr.scr_addr; 385 void __iomem *scr_addr = (void __iomem *)ap->ioaddr.scr_addr;
391 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) { 386 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) {
392 void *addr; 387 void __iomem *addr;
393 addr = scr_addr + sil24_scr_map[sc_reg] * 4; 388 addr = scr_addr + sil24_scr_map[sc_reg] * 4;
394 writel(val, scr_addr + sil24_scr_map[sc_reg] * 4); 389 writel(val, scr_addr + sil24_scr_map[sc_reg] * 4);
395 } 390 }
@@ -454,7 +449,7 @@ static void sil24_qc_prep(struct ata_queued_cmd *qc)
454static int sil24_qc_issue(struct ata_queued_cmd *qc) 449static int sil24_qc_issue(struct ata_queued_cmd *qc)
455{ 450{
456 struct ata_port *ap = qc->ap; 451 struct ata_port *ap = qc->ap;
457 void *port = (void *)ap->ioaddr.cmd_addr; 452 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
458 struct sil24_port_priv *pp = ap->private_data; 453 struct sil24_port_priv *pp = ap->private_data;
459 dma_addr_t paddr = pp->cmd_block_dma + qc->tag * sizeof(*pp->cmd_block); 454 dma_addr_t paddr = pp->cmd_block_dma + qc->tag * sizeof(*pp->cmd_block);
460 455
@@ -467,7 +462,7 @@ static void sil24_irq_clear(struct ata_port *ap)
467 /* unused */ 462 /* unused */
468} 463}
469 464
470static int __sil24_reset_controller(void *port) 465static int __sil24_reset_controller(void __iomem *port)
471{ 466{
472 int cnt; 467 int cnt;
473 u32 tmp; 468 u32 tmp;
@@ -493,7 +488,7 @@ static void sil24_reset_controller(struct ata_port *ap)
493{ 488{
494 printk(KERN_NOTICE DRV_NAME 489 printk(KERN_NOTICE DRV_NAME
495 " ata%u: resetting controller...\n", ap->id); 490 " ata%u: resetting controller...\n", ap->id);
496 if (__sil24_reset_controller((void *)ap->ioaddr.cmd_addr)) 491 if (__sil24_reset_controller((void __iomem *)ap->ioaddr.cmd_addr))
497 printk(KERN_ERR DRV_NAME 492 printk(KERN_ERR DRV_NAME
498 " ata%u: failed to reset controller\n", ap->id); 493 " ata%u: failed to reset controller\n", ap->id);
499} 494}
@@ -504,7 +499,7 @@ static void sil24_eng_timeout(struct ata_port *ap)
504 499
505 qc = ata_qc_from_tag(ap, ap->active_tag); 500 qc = ata_qc_from_tag(ap, ap->active_tag);
506 if (!qc) { 501 if (!qc) {
507 printk(KERN_ERR "ata%u: BUG: tiemout without command\n", 502 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
508 ap->id); 503 ap->id);
509 return; 504 return;
510 } 505 }
@@ -518,7 +513,7 @@ static void sil24_eng_timeout(struct ata_port *ap)
518 */ 513 */
519 printk(KERN_ERR "ata%u: command timeout\n", ap->id); 514 printk(KERN_ERR "ata%u: command timeout\n", ap->id);
520 qc->scsidone = scsi_finish_command; 515 qc->scsidone = scsi_finish_command;
521 ata_qc_complete(qc, ATA_ERR); 516 ata_qc_complete(qc, AC_ERR_OTHER);
522 517
523 sil24_reset_controller(ap); 518 sil24_reset_controller(ap);
524} 519}
@@ -527,8 +522,9 @@ static void sil24_error_intr(struct ata_port *ap, u32 slot_stat)
527{ 522{
528 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag); 523 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag);
529 struct sil24_port_priv *pp = ap->private_data; 524 struct sil24_port_priv *pp = ap->private_data;
530 void *port = (void *)ap->ioaddr.cmd_addr; 525 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
531 u32 irq_stat, cmd_err, sstatus, serror; 526 u32 irq_stat, cmd_err, sstatus, serror;
527 unsigned int err_mask;
532 528
533 irq_stat = readl(port + PORT_IRQ_STAT); 529 irq_stat = readl(port + PORT_IRQ_STAT);
534 writel(irq_stat, port + PORT_IRQ_STAT); /* clear irq */ 530 writel(irq_stat, port + PORT_IRQ_STAT); /* clear irq */
@@ -556,17 +552,18 @@ static void sil24_error_intr(struct ata_port *ap, u32 slot_stat)
556 * Device is reporting error, tf registers are valid. 552 * Device is reporting error, tf registers are valid.
557 */ 553 */
558 sil24_update_tf(ap); 554 sil24_update_tf(ap);
555 err_mask = ac_err_mask(pp->tf.command);
559 } else { 556 } else {
560 /* 557 /*
561 * Other errors. libata currently doesn't have any 558 * Other errors. libata currently doesn't have any
562 * mechanism to report these errors. Just turn on 559 * mechanism to report these errors. Just turn on
563 * ATA_ERR. 560 * ATA_ERR.
564 */ 561 */
565 pp->tf.command = ATA_ERR; 562 err_mask = AC_ERR_OTHER;
566 } 563 }
567 564
568 if (qc) 565 if (qc)
569 ata_qc_complete(qc, pp->tf.command); 566 ata_qc_complete(qc, err_mask);
570 567
571 sil24_reset_controller(ap); 568 sil24_reset_controller(ap);
572} 569}
@@ -574,7 +571,7 @@ static void sil24_error_intr(struct ata_port *ap, u32 slot_stat)
574static inline void sil24_host_intr(struct ata_port *ap) 571static inline void sil24_host_intr(struct ata_port *ap)
575{ 572{
576 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag); 573 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag);
577 void *port = (void *)ap->ioaddr.cmd_addr; 574 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
578 u32 slot_stat; 575 u32 slot_stat;
579 576
580 slot_stat = readl(port + PORT_SLOT_STAT); 577 slot_stat = readl(port + PORT_SLOT_STAT);
@@ -591,7 +588,7 @@ static inline void sil24_host_intr(struct ata_port *ap)
591 sil24_update_tf(ap); 588 sil24_update_tf(ap);
592 589
593 if (qc) 590 if (qc)
594 ata_qc_complete(qc, pp->tf.command); 591 ata_qc_complete(qc, ac_err_mask(pp->tf.command));
595 } else 592 } else
596 sil24_error_intr(ap, slot_stat); 593 sil24_error_intr(ap, slot_stat);
597} 594}
@@ -689,11 +686,12 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
689 struct ata_port_info *pinfo = &sil24_port_info[board_id]; 686 struct ata_port_info *pinfo = &sil24_port_info[board_id];
690 struct ata_probe_ent *probe_ent = NULL; 687 struct ata_probe_ent *probe_ent = NULL;
691 struct sil24_host_priv *hpriv = NULL; 688 struct sil24_host_priv *hpriv = NULL;
692 void *host_base = NULL, *port_base = NULL; 689 void __iomem *host_base = NULL;
690 void __iomem *port_base = NULL;
693 int i, rc; 691 int i, rc;
694 692
695 if (!printed_version++) 693 if (!printed_version++)
696 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 694 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
697 695
698 rc = pci_enable_device(pdev); 696 rc = pci_enable_device(pdev);
699 if (rc) 697 if (rc)
@@ -753,14 +751,14 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
753 */ 751 */
754 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 752 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
755 if (rc) { 753 if (rc) {
756 printk(KERN_ERR DRV_NAME "(%s): 32-bit DMA enable failed\n", 754 dev_printk(KERN_ERR, &pdev->dev,
757 pci_name(pdev)); 755 "32-bit DMA enable failed\n");
758 goto out_free; 756 goto out_free;
759 } 757 }
760 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 758 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
761 if (rc) { 759 if (rc) {
762 printk(KERN_ERR DRV_NAME "(%s): 32-bit consistent DMA enable failed\n", 760 dev_printk(KERN_ERR, &pdev->dev,
763 pci_name(pdev)); 761 "32-bit consistent DMA enable failed\n");
764 goto out_free; 762 goto out_free;
765 } 763 }
766 764
@@ -771,7 +769,7 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
771 writel(0, host_base + HOST_CTRL); 769 writel(0, host_base + HOST_CTRL);
772 770
773 for (i = 0; i < probe_ent->n_ports; i++) { 771 for (i = 0; i < probe_ent->n_ports; i++) {
774 void *port = port_base + i * PORT_REGS_SIZE; 772 void __iomem *port = port_base + i * PORT_REGS_SIZE;
775 unsigned long portu = (unsigned long)port; 773 unsigned long portu = (unsigned long)port;
776 u32 tmp; 774 u32 tmp;
777 int cnt; 775 int cnt;
@@ -796,9 +794,8 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
796 break; 794 break;
797 } 795 }
798 if (tmp & PORT_CS_PORT_RST) 796 if (tmp & PORT_CS_PORT_RST)
799 printk(KERN_ERR DRV_NAME 797 dev_printk(KERN_ERR, &pdev->dev,
800 "(%s): failed to clear port RST\n", 798 "failed to clear port RST\n");
801 pci_name(pdev));
802 } 799 }
803 800
804 /* Zero error counters. */ 801 /* Zero error counters. */
@@ -827,9 +824,8 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
827 824
828 /* Reset itself */ 825 /* Reset itself */
829 if (__sil24_reset_controller(port)) 826 if (__sil24_reset_controller(port))
830 printk(KERN_ERR DRV_NAME 827 dev_printk(KERN_ERR, &pdev->dev,
831 "(%s): failed to reset controller\n", 828 "failed to reset controller\n");
832 pci_name(pdev));
833 } 829 }
834 830
835 /* Turn on interrupts */ 831 /* Turn on interrupts */
diff --git a/drivers/scsi/sata_sis.c b/drivers/scsi/sata_sis.c
index 057f7b98b6c4..42288be0e561 100644
--- a/drivers/scsi/sata_sis.c
+++ b/drivers/scsi/sata_sis.c
@@ -38,6 +38,7 @@
38#include <linux/blkdev.h> 38#include <linux/blkdev.h>
39#include <linux/delay.h> 39#include <linux/delay.h>
40#include <linux/interrupt.h> 40#include <linux/interrupt.h>
41#include <linux/device.h>
41#include "scsi.h" 42#include "scsi.h"
42#include <scsi/scsi_host.h> 43#include <scsi/scsi_host.h>
43#include <linux/libata.h> 44#include <linux/libata.h>
@@ -237,6 +238,7 @@ static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
237 238
238static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 239static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
239{ 240{
241 static int printed_version;
240 struct ata_probe_ent *probe_ent = NULL; 242 struct ata_probe_ent *probe_ent = NULL;
241 int rc; 243 int rc;
242 u32 genctl; 244 u32 genctl;
@@ -245,6 +247,9 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
245 u8 pmr; 247 u8 pmr;
246 u8 port2_start; 248 u8 port2_start;
247 249
250 if (!printed_version++)
251 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
252
248 rc = pci_enable_device(pdev); 253 rc = pci_enable_device(pdev);
249 if (rc) 254 if (rc)
250 return rc; 255 return rc;
@@ -288,16 +293,18 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
288 pci_read_config_byte(pdev, SIS_PMR, &pmr); 293 pci_read_config_byte(pdev, SIS_PMR, &pmr);
289 if (ent->device != 0x182) { 294 if (ent->device != 0x182) {
290 if ((pmr & SIS_PMR_COMBINED) == 0) { 295 if ((pmr & SIS_PMR_COMBINED) == 0) {
291 printk(KERN_INFO "sata_sis: Detected SiS 180/181 chipset in SATA mode\n"); 296 dev_printk(KERN_INFO, &pdev->dev,
297 "Detected SiS 180/181 chipset in SATA mode\n");
292 port2_start = 64; 298 port2_start = 64;
293 } 299 }
294 else { 300 else {
295 printk(KERN_INFO "sata_sis: Detected SiS 180/181 chipset in combined mode\n"); 301 dev_printk(KERN_INFO, &pdev->dev,
302 "Detected SiS 180/181 chipset in combined mode\n");
296 port2_start=0; 303 port2_start=0;
297 } 304 }
298 } 305 }
299 else { 306 else {
300 printk(KERN_INFO "sata_sis: Detected SiS 182 chipset\n"); 307 dev_printk(KERN_INFO, &pdev->dev, "Detected SiS 182 chipset\n");
301 port2_start = 0x20; 308 port2_start = 0x20;
302 } 309 }
303 310
diff --git a/drivers/scsi/sata_svw.c b/drivers/scsi/sata_svw.c
index e0f9570bc6dd..db615ff794d8 100644
--- a/drivers/scsi/sata_svw.c
+++ b/drivers/scsi/sata_svw.c
@@ -44,6 +44,7 @@
44#include <linux/blkdev.h> 44#include <linux/blkdev.h>
45#include <linux/delay.h> 45#include <linux/delay.h>
46#include <linux/interrupt.h> 46#include <linux/interrupt.h>
47#include <linux/device.h>
47#include "scsi.h" 48#include "scsi.h"
48#include <scsi/scsi_host.h> 49#include <scsi/scsi_host.h>
49#include <linux/libata.h> 50#include <linux/libata.h>
@@ -84,6 +85,8 @@
84/* Port stride */ 85/* Port stride */
85#define K2_SATA_PORT_OFFSET 0x100 86#define K2_SATA_PORT_OFFSET 0x100
86 87
88static u8 k2_stat_check_status(struct ata_port *ap);
89
87 90
88static u32 k2_sata_scr_read (struct ata_port *ap, unsigned int sc_reg) 91static u32 k2_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
89{ 92{
@@ -136,16 +139,24 @@ static void k2_sata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
136static void k2_sata_tf_read(struct ata_port *ap, struct ata_taskfile *tf) 139static void k2_sata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
137{ 140{
138 struct ata_ioports *ioaddr = &ap->ioaddr; 141 struct ata_ioports *ioaddr = &ap->ioaddr;
139 u16 nsect, lbal, lbam, lbah; 142 u16 nsect, lbal, lbam, lbah, feature;
140 143
141 nsect = tf->nsect = readw(ioaddr->nsect_addr); 144 tf->command = k2_stat_check_status(ap);
142 lbal = tf->lbal = readw(ioaddr->lbal_addr);
143 lbam = tf->lbam = readw(ioaddr->lbam_addr);
144 lbah = tf->lbah = readw(ioaddr->lbah_addr);
145 tf->device = readw(ioaddr->device_addr); 145 tf->device = readw(ioaddr->device_addr);
146 feature = readw(ioaddr->error_addr);
147 nsect = readw(ioaddr->nsect_addr);
148 lbal = readw(ioaddr->lbal_addr);
149 lbam = readw(ioaddr->lbam_addr);
150 lbah = readw(ioaddr->lbah_addr);
151
152 tf->feature = feature;
153 tf->nsect = nsect;
154 tf->lbal = lbal;
155 tf->lbam = lbam;
156 tf->lbah = lbah;
146 157
147 if (tf->flags & ATA_TFLAG_LBA48) { 158 if (tf->flags & ATA_TFLAG_LBA48) {
148 tf->hob_feature = readw(ioaddr->error_addr) >> 8; 159 tf->hob_feature = feature >> 8;
149 tf->hob_nsect = nsect >> 8; 160 tf->hob_nsect = nsect >> 8;
150 tf->hob_lbal = lbal >> 8; 161 tf->hob_lbal = lbal >> 8;
151 tf->hob_lbam = lbam >> 8; 162 tf->hob_lbam = lbam >> 8;
@@ -352,7 +363,7 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
352 int i; 363 int i;
353 364
354 if (!printed_version++) 365 if (!printed_version++)
355 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 366 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
356 367
357 /* 368 /*
358 * If this driver happens to only be useful on Apple's K2, then 369 * If this driver happens to only be useful on Apple's K2, then
diff --git a/drivers/scsi/sata_sx4.c b/drivers/scsi/sata_sx4.c
index af08f4f650c1..0ec21e09f5d8 100644
--- a/drivers/scsi/sata_sx4.c
+++ b/drivers/scsi/sata_sx4.c
@@ -38,6 +38,7 @@
38#include <linux/delay.h> 38#include <linux/delay.h>
39#include <linux/interrupt.h> 39#include <linux/interrupt.h>
40#include <linux/sched.h> 40#include <linux/sched.h>
41#include <linux/device.h>
41#include "scsi.h" 42#include "scsi.h"
42#include <scsi/scsi_host.h> 43#include <scsi/scsi_host.h>
43#include <linux/libata.h> 44#include <linux/libata.h>
@@ -718,7 +719,7 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
718 VPRINTK("ata%u: read hdma, 0x%x 0x%x\n", ap->id, 719 VPRINTK("ata%u: read hdma, 0x%x 0x%x\n", ap->id,
719 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT)); 720 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT));
720 /* get drive status; clear intr; complete txn */ 721 /* get drive status; clear intr; complete txn */
721 ata_qc_complete(qc, ata_wait_idle(ap)); 722 ata_qc_complete(qc, ac_err_mask(ata_wait_idle(ap)));
722 pdc20621_pop_hdma(qc); 723 pdc20621_pop_hdma(qc);
723 } 724 }
724 725
@@ -756,7 +757,7 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
756 VPRINTK("ata%u: write ata, 0x%x 0x%x\n", ap->id, 757 VPRINTK("ata%u: write ata, 0x%x 0x%x\n", ap->id,
757 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT)); 758 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT));
758 /* get drive status; clear intr; complete txn */ 759 /* get drive status; clear intr; complete txn */
759 ata_qc_complete(qc, ata_wait_idle(ap)); 760 ata_qc_complete(qc, ac_err_mask(ata_wait_idle(ap)));
760 pdc20621_pop_hdma(qc); 761 pdc20621_pop_hdma(qc);
761 } 762 }
762 handled = 1; 763 handled = 1;
@@ -766,7 +767,7 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
766 767
767 status = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000); 768 status = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
768 DPRINTK("BUS_NODATA (drv_stat 0x%X)\n", status); 769 DPRINTK("BUS_NODATA (drv_stat 0x%X)\n", status);
769 ata_qc_complete(qc, status); 770 ata_qc_complete(qc, ac_err_mask(status));
770 handled = 1; 771 handled = 1;
771 772
772 } else { 773 } else {
@@ -881,7 +882,7 @@ static void pdc_eng_timeout(struct ata_port *ap)
881 case ATA_PROT_DMA: 882 case ATA_PROT_DMA:
882 case ATA_PROT_NODATA: 883 case ATA_PROT_NODATA:
883 printk(KERN_ERR "ata%u: command timeout\n", ap->id); 884 printk(KERN_ERR "ata%u: command timeout\n", ap->id);
884 ata_qc_complete(qc, ata_wait_idle(ap) | ATA_ERR); 885 ata_qc_complete(qc, __ac_err_mask(ata_wait_idle(ap)));
885 break; 886 break;
886 887
887 default: 888 default:
@@ -890,7 +891,7 @@ static void pdc_eng_timeout(struct ata_port *ap)
890 printk(KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n", 891 printk(KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n",
891 ap->id, qc->tf.command, drv_stat); 892 ap->id, qc->tf.command, drv_stat);
892 893
893 ata_qc_complete(qc, drv_stat); 894 ata_qc_complete(qc, ac_err_mask(drv_stat));
894 break; 895 break;
895 } 896 }
896 897
@@ -1385,7 +1386,7 @@ static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *
1385 int rc; 1386 int rc;
1386 1387
1387 if (!printed_version++) 1388 if (!printed_version++)
1388 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 1389 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1389 1390
1390 /* 1391 /*
1391 * If this driver happens to only be useful on Apple's K2, then 1392 * If this driver happens to only be useful on Apple's K2, then
diff --git a/drivers/scsi/sata_uli.c b/drivers/scsi/sata_uli.c
index d68dc7d3422c..a5e245c098e1 100644
--- a/drivers/scsi/sata_uli.c
+++ b/drivers/scsi/sata_uli.c
@@ -32,6 +32,7 @@
32#include <linux/blkdev.h> 32#include <linux/blkdev.h>
33#include <linux/delay.h> 33#include <linux/delay.h>
34#include <linux/interrupt.h> 34#include <linux/interrupt.h>
35#include <linux/device.h>
35#include "scsi.h" 36#include "scsi.h"
36#include <scsi/scsi_host.h> 37#include <scsi/scsi_host.h>
37#include <linux/libata.h> 38#include <linux/libata.h>
@@ -178,12 +179,16 @@ static void uli_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
178 179
179static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 180static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
180{ 181{
182 static int printed_version;
181 struct ata_probe_ent *probe_ent; 183 struct ata_probe_ent *probe_ent;
182 struct ata_port_info *ppi; 184 struct ata_port_info *ppi;
183 int rc; 185 int rc;
184 unsigned int board_idx = (unsigned int) ent->driver_data; 186 unsigned int board_idx = (unsigned int) ent->driver_data;
185 int pci_dev_busy = 0; 187 int pci_dev_busy = 0;
186 188
189 if (!printed_version++)
190 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
191
187 rc = pci_enable_device(pdev); 192 rc = pci_enable_device(pdev);
188 if (rc) 193 if (rc)
189 return rc; 194 return rc;
diff --git a/drivers/scsi/sata_via.c b/drivers/scsi/sata_via.c
index 80e291a909a9..b3ecdbe400e9 100644
--- a/drivers/scsi/sata_via.c
+++ b/drivers/scsi/sata_via.c
@@ -41,6 +41,7 @@
41#include <linux/init.h> 41#include <linux/init.h>
42#include <linux/blkdev.h> 42#include <linux/blkdev.h>
43#include <linux/delay.h> 43#include <linux/delay.h>
44#include <linux/device.h>
44#include "scsi.h" 45#include "scsi.h"
45#include <scsi/scsi_host.h> 46#include <scsi/scsi_host.h>
46#include <linux/libata.h> 47#include <linux/libata.h>
@@ -259,15 +260,15 @@ static void svia_configure(struct pci_dev *pdev)
259 u8 tmp8; 260 u8 tmp8;
260 261
261 pci_read_config_byte(pdev, PCI_INTERRUPT_LINE, &tmp8); 262 pci_read_config_byte(pdev, PCI_INTERRUPT_LINE, &tmp8);
262 printk(KERN_INFO DRV_NAME "(%s): routed to hard irq line %d\n", 263 dev_printk(KERN_INFO, &pdev->dev, "routed to hard irq line %d\n",
263 pci_name(pdev),
264 (int) (tmp8 & 0xf0) == 0xf0 ? 0 : tmp8 & 0x0f); 264 (int) (tmp8 & 0xf0) == 0xf0 ? 0 : tmp8 & 0x0f);
265 265
266 /* make sure SATA channels are enabled */ 266 /* make sure SATA channels are enabled */
267 pci_read_config_byte(pdev, SATA_CHAN_ENAB, &tmp8); 267 pci_read_config_byte(pdev, SATA_CHAN_ENAB, &tmp8);
268 if ((tmp8 & ALL_PORTS) != ALL_PORTS) { 268 if ((tmp8 & ALL_PORTS) != ALL_PORTS) {
269 printk(KERN_DEBUG DRV_NAME "(%s): enabling SATA channels (0x%x)\n", 269 dev_printk(KERN_DEBUG, &pdev->dev,
270 pci_name(pdev), (int) tmp8); 270 "enabling SATA channels (0x%x)\n",
271 (int) tmp8);
271 tmp8 |= ALL_PORTS; 272 tmp8 |= ALL_PORTS;
272 pci_write_config_byte(pdev, SATA_CHAN_ENAB, tmp8); 273 pci_write_config_byte(pdev, SATA_CHAN_ENAB, tmp8);
273 } 274 }
@@ -275,8 +276,9 @@ static void svia_configure(struct pci_dev *pdev)
275 /* make sure interrupts for each channel sent to us */ 276 /* make sure interrupts for each channel sent to us */
276 pci_read_config_byte(pdev, SATA_INT_GATE, &tmp8); 277 pci_read_config_byte(pdev, SATA_INT_GATE, &tmp8);
277 if ((tmp8 & ALL_PORTS) != ALL_PORTS) { 278 if ((tmp8 & ALL_PORTS) != ALL_PORTS) {
278 printk(KERN_DEBUG DRV_NAME "(%s): enabling SATA channel interrupts (0x%x)\n", 279 dev_printk(KERN_DEBUG, &pdev->dev,
279 pci_name(pdev), (int) tmp8); 280 "enabling SATA channel interrupts (0x%x)\n",
281 (int) tmp8);
280 tmp8 |= ALL_PORTS; 282 tmp8 |= ALL_PORTS;
281 pci_write_config_byte(pdev, SATA_INT_GATE, tmp8); 283 pci_write_config_byte(pdev, SATA_INT_GATE, tmp8);
282 } 284 }
@@ -284,8 +286,9 @@ static void svia_configure(struct pci_dev *pdev)
284 /* make sure native mode is enabled */ 286 /* make sure native mode is enabled */
285 pci_read_config_byte(pdev, SATA_NATIVE_MODE, &tmp8); 287 pci_read_config_byte(pdev, SATA_NATIVE_MODE, &tmp8);
286 if ((tmp8 & NATIVE_MODE_ALL) != NATIVE_MODE_ALL) { 288 if ((tmp8 & NATIVE_MODE_ALL) != NATIVE_MODE_ALL) {
287 printk(KERN_DEBUG DRV_NAME "(%s): enabling SATA channel native mode (0x%x)\n", 289 dev_printk(KERN_DEBUG, &pdev->dev,
288 pci_name(pdev), (int) tmp8); 290 "enabling SATA channel native mode (0x%x)\n",
291 (int) tmp8);
289 tmp8 |= NATIVE_MODE_ALL; 292 tmp8 |= NATIVE_MODE_ALL;
290 pci_write_config_byte(pdev, SATA_NATIVE_MODE, tmp8); 293 pci_write_config_byte(pdev, SATA_NATIVE_MODE, tmp8);
291 } 294 }
@@ -303,7 +306,7 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
303 u8 tmp8; 306 u8 tmp8;
304 307
305 if (!printed_version++) 308 if (!printed_version++)
306 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 309 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
307 310
308 rc = pci_enable_device(pdev); 311 rc = pci_enable_device(pdev);
309 if (rc) 312 if (rc)
@@ -318,8 +321,9 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
318 if (board_id == vt6420) { 321 if (board_id == vt6420) {
319 pci_read_config_byte(pdev, SATA_PATA_SHARING, &tmp8); 322 pci_read_config_byte(pdev, SATA_PATA_SHARING, &tmp8);
320 if (tmp8 & SATA_2DEV) { 323 if (tmp8 & SATA_2DEV) {
321 printk(KERN_ERR DRV_NAME "(%s): SATA master/slave not supported (0x%x)\n", 324 dev_printk(KERN_ERR, &pdev->dev,
322 pci_name(pdev), (int) tmp8); 325 "SATA master/slave not supported (0x%x)\n",
326 (int) tmp8);
323 rc = -EIO; 327 rc = -EIO;
324 goto err_out_regions; 328 goto err_out_regions;
325 } 329 }
@@ -332,10 +336,11 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
332 for (i = 0; i < ARRAY_SIZE(svia_bar_sizes); i++) 336 for (i = 0; i < ARRAY_SIZE(svia_bar_sizes); i++)
333 if ((pci_resource_start(pdev, i) == 0) || 337 if ((pci_resource_start(pdev, i) == 0) ||
334 (pci_resource_len(pdev, i) < bar_sizes[i])) { 338 (pci_resource_len(pdev, i) < bar_sizes[i])) {
335 printk(KERN_ERR DRV_NAME "(%s): invalid PCI BAR %u (sz 0x%lx, val 0x%lx)\n", 339 dev_printk(KERN_ERR, &pdev->dev,
336 pci_name(pdev), i, 340 "invalid PCI BAR %u (sz 0x%lx, val 0x%lx)\n",
337 pci_resource_start(pdev, i), 341 i,
338 pci_resource_len(pdev, i)); 342 pci_resource_start(pdev, i),
343 pci_resource_len(pdev, i));
339 rc = -ENODEV; 344 rc = -ENODEV;
340 goto err_out_regions; 345 goto err_out_regions;
341 } 346 }
@@ -353,8 +358,7 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
353 probe_ent = vt6421_init_probe_ent(pdev); 358 probe_ent = vt6421_init_probe_ent(pdev);
354 359
355 if (!probe_ent) { 360 if (!probe_ent) {
356 printk(KERN_ERR DRV_NAME "(%s): out of memory\n", 361 dev_printk(KERN_ERR, &pdev->dev, "out of memory\n");
357 pci_name(pdev));
358 rc = -ENOMEM; 362 rc = -ENOMEM;
359 goto err_out_regions; 363 goto err_out_regions;
360 } 364 }
diff --git a/drivers/scsi/sata_vsc.c b/drivers/scsi/sata_vsc.c
index 5af05fdf8544..bb84ba0c7e83 100644
--- a/drivers/scsi/sata_vsc.c
+++ b/drivers/scsi/sata_vsc.c
@@ -42,6 +42,7 @@
42#include <linux/delay.h> 42#include <linux/delay.h>
43#include <linux/interrupt.h> 43#include <linux/interrupt.h>
44#include <linux/dma-mapping.h> 44#include <linux/dma-mapping.h>
45#include <linux/device.h>
45#include "scsi.h" 46#include "scsi.h"
46#include <scsi/scsi_host.h> 47#include <scsi/scsi_host.h>
47#include <linux/libata.h> 48#include <linux/libata.h>
@@ -153,16 +154,24 @@ static void vsc_sata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
153static void vsc_sata_tf_read(struct ata_port *ap, struct ata_taskfile *tf) 154static void vsc_sata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
154{ 155{
155 struct ata_ioports *ioaddr = &ap->ioaddr; 156 struct ata_ioports *ioaddr = &ap->ioaddr;
156 u16 nsect, lbal, lbam, lbah; 157 u16 nsect, lbal, lbam, lbah, feature;
157 158
158 nsect = tf->nsect = readw(ioaddr->nsect_addr); 159 tf->command = ata_check_status(ap);
159 lbal = tf->lbal = readw(ioaddr->lbal_addr);
160 lbam = tf->lbam = readw(ioaddr->lbam_addr);
161 lbah = tf->lbah = readw(ioaddr->lbah_addr);
162 tf->device = readw(ioaddr->device_addr); 160 tf->device = readw(ioaddr->device_addr);
161 feature = readw(ioaddr->error_addr);
162 nsect = readw(ioaddr->nsect_addr);
163 lbal = readw(ioaddr->lbal_addr);
164 lbam = readw(ioaddr->lbam_addr);
165 lbah = readw(ioaddr->lbah_addr);
166
167 tf->feature = feature;
168 tf->nsect = nsect;
169 tf->lbal = lbal;
170 tf->lbam = lbam;
171 tf->lbah = lbah;
163 172
164 if (tf->flags & ATA_TFLAG_LBA48) { 173 if (tf->flags & ATA_TFLAG_LBA48) {
165 tf->hob_feature = readb(ioaddr->error_addr); 174 tf->hob_feature = feature >> 8;
166 tf->hob_nsect = nsect >> 8; 175 tf->hob_nsect = nsect >> 8;
167 tf->hob_lbal = lbal >> 8; 176 tf->hob_lbal = lbal >> 8;
168 tf->hob_lbam = lbam >> 8; 177 tf->hob_lbam = lbam >> 8;
@@ -287,7 +296,7 @@ static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_d
287 int rc; 296 int rc;
288 297
289 if (!printed_version++) 298 if (!printed_version++)
290 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 299 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
291 300
292 rc = pci_enable_device(pdev); 301 rc = pci_enable_device(pdev);
293 if (rc) 302 if (rc)
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 771e97ef136e..b856e140e65f 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -26,6 +26,7 @@
26 */ 26 */
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/sched.h> /* workqueue stuff, HZ */
29#include <scsi/scsi_device.h> 30#include <scsi/scsi_device.h>
30#include <scsi/scsi_host.h> 31#include <scsi/scsi_host.h>
31#include <scsi/scsi_transport.h> 32#include <scsi/scsi_transport.h>
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 8bb8222ea589..d2caa35059d9 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -19,6 +19,9 @@
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */ 20 */
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/string.h>
23#include <linux/slab.h>
24
22#include <scsi/scsi.h> 25#include <scsi/scsi.h>
23#include <scsi/scsi_host.h> 26#include <scsi/scsi_host.h>
24#include <scsi/scsi_device.h> 27#include <scsi/scsi_device.h>
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 861e51375d70..d86d5c26061d 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -49,6 +49,7 @@ static int sg_version_num = 30533; /* 2 digits for each component */
49#include <linux/seq_file.h> 49#include <linux/seq_file.h>
50#include <linux/blkdev.h> 50#include <linux/blkdev.h>
51#include <linux/delay.h> 51#include <linux/delay.h>
52#include <linux/scatterlist.h>
52 53
53#include "scsi.h" 54#include "scsi.h"
54#include <scsi/scsi_dbg.h> 55#include <scsi/scsi_dbg.h>
@@ -1886,13 +1887,17 @@ st_unmap_user_pages(struct scatterlist *sgl, const unsigned int nr_pages,
1886 int i; 1887 int i;
1887 1888
1888 for (i=0; i < nr_pages; i++) { 1889 for (i=0; i < nr_pages; i++) {
1889 if (dirtied && !PageReserved(sgl[i].page)) 1890 struct page *page = sgl[i].page;
1890 SetPageDirty(sgl[i].page); 1891
1891 /* unlock_page(sgl[i].page); */ 1892 /* XXX: just for debug. Remove when PageReserved is removed */
1893 BUG_ON(PageReserved(page));
1894 if (dirtied)
1895 SetPageDirty(page);
1896 /* unlock_page(page); */
1892 /* FIXME: cache flush missing for rw==READ 1897 /* FIXME: cache flush missing for rw==READ
1893 * FIXME: call the correct reference counting function 1898 * FIXME: call the correct reference counting function
1894 */ 1899 */
1895 page_cache_release(sgl[i].page); 1900 page_cache_release(page);
1896 } 1901 }
1897 1902
1898 return 0; 1903 return 0;
@@ -1992,9 +1997,7 @@ sg_build_indirect(Sg_scatter_hold * schp, Sg_fd * sfp, int buff_size)
1992 if (!p) 1997 if (!p)
1993 break; 1998 break;
1994 } 1999 }
1995 sclp->page = virt_to_page(p); 2000 sg_set_buf(sclp, p, ret_sz);
1996 sclp->offset = offset_in_page(p);
1997 sclp->length = ret_sz;
1998 2001
1999 SCSI_LOG_TIMEOUT(5, printk("sg_build_build: k=%d, a=0x%p, len=%d\n", 2002 SCSI_LOG_TIMEOUT(5, printk("sg_build_build: k=%d, a=0x%p, len=%d\n",
2000 k, sg_scatg2virt(sclp), ret_sz)); 2003 k, sg_scatg2virt(sclp), ret_sz));
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 5eb54d8019b4..da9766283bd7 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -4526,12 +4526,16 @@ static int sgl_unmap_user_pages(struct scatterlist *sgl, const unsigned int nr_p
4526 int i; 4526 int i;
4527 4527
4528 for (i=0; i < nr_pages; i++) { 4528 for (i=0; i < nr_pages; i++) {
4529 if (dirtied && !PageReserved(sgl[i].page)) 4529 struct page *page = sgl[i].page;
4530 SetPageDirty(sgl[i].page); 4530
4531 /* XXX: just for debug. Remove when PageReserved is removed */
4532 BUG_ON(PageReserved(page));
4533 if (dirtied)
4534 SetPageDirty(page);
4531 /* FIXME: cache flush missing for rw==READ 4535 /* FIXME: cache flush missing for rw==READ
4532 * FIXME: call the correct reference counting function 4536 * FIXME: call the correct reference counting function
4533 */ 4537 */
4534 page_cache_release(sgl[i].page); 4538 page_cache_release(page);
4535 } 4539 }
4536 4540
4537 return 0; 4541 return 0;
diff --git a/drivers/scsi/sym53c8xx_2/sym_hipd.c b/drivers/scsi/sym53c8xx_2/sym_hipd.c
index e753ba27dc59..a1a58e1d5ad3 100644
--- a/drivers/scsi/sym53c8xx_2/sym_hipd.c
+++ b/drivers/scsi/sym53c8xx_2/sym_hipd.c
@@ -37,6 +37,9 @@
37 * along with this program; if not, write to the Free Software 37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 38 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 */ 39 */
40
41#include <linux/slab.h>
42
40#include "sym_glue.h" 43#include "sym_glue.h"
41#include "sym_nvram.h" 44#include "sym_nvram.h"
42 45
diff --git a/drivers/scsi/sym53c8xx_2/sym_hipd.h b/drivers/scsi/sym53c8xx_2/sym_hipd.h
index 3131a6bf7ab7..3a264a408216 100644
--- a/drivers/scsi/sym53c8xx_2/sym_hipd.h
+++ b/drivers/scsi/sym53c8xx_2/sym_hipd.h
@@ -37,6 +37,8 @@
37 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 37 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 */ 38 */
39 39
40#include <linux/gfp.h>
41
40#ifndef SYM_HIPD_H 42#ifndef SYM_HIPD_H
41#define SYM_HIPD_H 43#define SYM_HIPD_H
42 44