aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/ahci.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-06-18 16:08:39 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-06-18 16:08:39 -0400
commit43fde784a698aff26de0fc1dbd84aa075b8cfb5f (patch)
tree948ad7acecc67e1e13acc7895a3028cdfb2a6560 /drivers/scsi/ahci.c
parentc2a0f5943d8935766a42b2d0870aa4c645e3423d (diff)
parentf9d1fe9630b94007902987c39d19f04dc6256eac (diff)
Merge 'upstream-2.6.13' branch of rsync://rsync.kernel.org/pub/scm/linux/kernel/git/jgarzik/libata-dev
Diffstat (limited to 'drivers/scsi/ahci.c')
-rw-r--r--drivers/scsi/ahci.c100
1 files changed, 75 insertions, 25 deletions
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index fc5263c6b102..9a547ca9c864 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -39,7 +39,7 @@
39#include <asm/io.h> 39#include <asm/io.h>
40 40
41#define DRV_NAME "ahci" 41#define DRV_NAME "ahci"
42#define DRV_VERSION "1.00" 42#define DRV_VERSION "1.01"
43 43
44 44
45enum { 45enum {
@@ -50,6 +50,7 @@ enum {
50 AHCI_CMD_SLOT_SZ = 32 * 32, 50 AHCI_CMD_SLOT_SZ = 32 * 32,
51 AHCI_RX_FIS_SZ = 256, 51 AHCI_RX_FIS_SZ = 256,
52 AHCI_CMD_TBL_HDR = 0x80, 52 AHCI_CMD_TBL_HDR = 0x80,
53 AHCI_CMD_TBL_CDB = 0x40,
53 AHCI_CMD_TBL_SZ = AHCI_CMD_TBL_HDR + (AHCI_MAX_SG * 16), 54 AHCI_CMD_TBL_SZ = AHCI_CMD_TBL_HDR + (AHCI_MAX_SG * 16),
54 AHCI_PORT_PRIV_DMA_SZ = AHCI_CMD_SLOT_SZ + AHCI_CMD_TBL_SZ + 55 AHCI_PORT_PRIV_DMA_SZ = AHCI_CMD_SLOT_SZ + AHCI_CMD_TBL_SZ +
55 AHCI_RX_FIS_SZ, 56 AHCI_RX_FIS_SZ,
@@ -134,6 +135,9 @@ enum {
134 PORT_CMD_ICC_ACTIVE = (0x1 << 28), /* Put i/f in active state */ 135 PORT_CMD_ICC_ACTIVE = (0x1 << 28), /* Put i/f in active state */
135 PORT_CMD_ICC_PARTIAL = (0x2 << 28), /* Put i/f in partial state */ 136 PORT_CMD_ICC_PARTIAL = (0x2 << 28), /* Put i/f in partial state */
136 PORT_CMD_ICC_SLUMBER = (0x6 << 28), /* Put i/f in slumber state */ 137 PORT_CMD_ICC_SLUMBER = (0x6 << 28), /* Put i/f in slumber state */
138
139 /* hpriv->flags bits */
140 AHCI_FLAG_MSI = (1 << 0),
137}; 141};
138 142
139struct ahci_cmd_hdr { 143struct ahci_cmd_hdr {
@@ -183,6 +187,7 @@ static void ahci_qc_prep(struct ata_queued_cmd *qc);
183static u8 ahci_check_status(struct ata_port *ap); 187static u8 ahci_check_status(struct ata_port *ap);
184static u8 ahci_check_err(struct ata_port *ap); 188static u8 ahci_check_err(struct ata_port *ap);
185static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc); 189static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc);
190static void ahci_remove_one (struct pci_dev *pdev);
186 191
187static Scsi_Host_Template ahci_sht = { 192static Scsi_Host_Template ahci_sht = {
188 .module = THIS_MODULE, 193 .module = THIS_MODULE,
@@ -272,7 +277,7 @@ static struct pci_driver ahci_pci_driver = {
272 .name = DRV_NAME, 277 .name = DRV_NAME,
273 .id_table = ahci_pci_tbl, 278 .id_table = ahci_pci_tbl,
274 .probe = ahci_init_one, 279 .probe = ahci_init_one,
275 .remove = ata_pci_remove_one, 280 .remove = ahci_remove_one,
276}; 281};
277 282
278 283
@@ -506,7 +511,8 @@ static void ahci_fill_sg(struct ata_queued_cmd *qc)
506 511
507static void ahci_qc_prep(struct ata_queued_cmd *qc) 512static void ahci_qc_prep(struct ata_queued_cmd *qc)
508{ 513{
509 struct ahci_port_priv *pp = qc->ap->private_data; 514 struct ata_port *ap = qc->ap;
515 struct ahci_port_priv *pp = ap->private_data;
510 u32 opts; 516 u32 opts;
511 const u32 cmd_fis_len = 5; /* five dwords */ 517 const u32 cmd_fis_len = 5; /* five dwords */
512 518
@@ -518,18 +524,8 @@ static void ahci_qc_prep(struct ata_queued_cmd *qc)
518 opts = (qc->n_elem << 16) | cmd_fis_len; 524 opts = (qc->n_elem << 16) | cmd_fis_len;
519 if (qc->tf.flags & ATA_TFLAG_WRITE) 525 if (qc->tf.flags & ATA_TFLAG_WRITE)
520 opts |= AHCI_CMD_WRITE; 526 opts |= AHCI_CMD_WRITE;
521 527 if (is_atapi_taskfile(&qc->tf))
522 switch (qc->tf.protocol) {
523 case ATA_PROT_ATAPI:
524 case ATA_PROT_ATAPI_NODATA:
525 case ATA_PROT_ATAPI_DMA:
526 opts |= AHCI_CMD_ATAPI; 528 opts |= AHCI_CMD_ATAPI;
527 break;
528
529 default:
530 /* do nothing */
531 break;
532 }
533 529
534 pp->cmd_slot[0].opts = cpu_to_le32(opts); 530 pp->cmd_slot[0].opts = cpu_to_le32(opts);
535 pp->cmd_slot[0].status = 0; 531 pp->cmd_slot[0].status = 0;
@@ -541,6 +537,10 @@ static void ahci_qc_prep(struct ata_queued_cmd *qc)
541 * a SATA Register - Host to Device command FIS. 537 * a SATA Register - Host to Device command FIS.
542 */ 538 */
543 ata_tf_to_fis(&qc->tf, pp->cmd_tbl, 0); 539 ata_tf_to_fis(&qc->tf, pp->cmd_tbl, 0);
540 if (opts & AHCI_CMD_ATAPI) {
541 memset(pp->cmd_tbl + AHCI_CMD_TBL_CDB, 0, 32);
542 memcpy(pp->cmd_tbl + AHCI_CMD_TBL_CDB, qc->cdb, ap->cdb_len);
543 }
544 544
545 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) 545 if (!(qc->flags & ATA_QCFLAG_DMAMAP))
546 return; 546 return;
@@ -795,8 +795,6 @@ static int ahci_host_init(struct ata_probe_ent *probe_ent)
795 return rc; 795 return rc;
796 } 796 }
797 } 797 }
798
799 hpriv->flags |= HOST_CAP_64;
800 } else { 798 } else {
801 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 799 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
802 if (rc) { 800 if (rc) {
@@ -879,15 +877,19 @@ static int ahci_host_init(struct ata_probe_ent *probe_ent)
879} 877}
880 878
881/* move to PCI layer, integrate w/ MSI stuff */ 879/* move to PCI layer, integrate w/ MSI stuff */
882static void pci_enable_intx(struct pci_dev *pdev) 880static void pci_intx(struct pci_dev *pdev, int enable)
883{ 881{
884 u16 pci_command; 882 u16 pci_command, new;
885 883
886 pci_read_config_word(pdev, PCI_COMMAND, &pci_command); 884 pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
887 if (pci_command & PCI_COMMAND_INTX_DISABLE) { 885
888 pci_command &= ~PCI_COMMAND_INTX_DISABLE; 886 if (enable)
887 new = pci_command & ~PCI_COMMAND_INTX_DISABLE;
888 else
889 new = pci_command | PCI_COMMAND_INTX_DISABLE;
890
891 if (new != pci_command)
889 pci_write_config_word(pdev, PCI_COMMAND, pci_command); 892 pci_write_config_word(pdev, PCI_COMMAND, pci_command);
890 }
891} 893}
892 894
893static void ahci_print_info(struct ata_probe_ent *probe_ent) 895static void ahci_print_info(struct ata_probe_ent *probe_ent)
@@ -969,7 +971,7 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
969 unsigned long base; 971 unsigned long base;
970 void *mmio_base; 972 void *mmio_base;
971 unsigned int board_idx = (unsigned int) ent->driver_data; 973 unsigned int board_idx = (unsigned int) ent->driver_data;
972 int pci_dev_busy = 0; 974 int have_msi, pci_dev_busy = 0;
973 int rc; 975 int rc;
974 976
975 VPRINTK("ENTER\n"); 977 VPRINTK("ENTER\n");
@@ -987,12 +989,17 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
987 goto err_out; 989 goto err_out;
988 } 990 }
989 991
990 pci_enable_intx(pdev); 992 if (pci_enable_msi(pdev) == 0)
993 have_msi = 1;
994 else {
995 pci_intx(pdev, 1);
996 have_msi = 0;
997 }
991 998
992 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 999 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL);
993 if (probe_ent == NULL) { 1000 if (probe_ent == NULL) {
994 rc = -ENOMEM; 1001 rc = -ENOMEM;
995 goto err_out_regions; 1002 goto err_out_msi;
996 } 1003 }
997 1004
998 memset(probe_ent, 0, sizeof(*probe_ent)); 1005 memset(probe_ent, 0, sizeof(*probe_ent));
@@ -1025,6 +1032,9 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1025 probe_ent->mmio_base = mmio_base; 1032 probe_ent->mmio_base = mmio_base;
1026 probe_ent->private_data = hpriv; 1033 probe_ent->private_data = hpriv;
1027 1034
1035 if (have_msi)
1036 hpriv->flags |= AHCI_FLAG_MSI;
1037
1028 /* initialize adapter */ 1038 /* initialize adapter */
1029 rc = ahci_host_init(probe_ent); 1039 rc = ahci_host_init(probe_ent);
1030 if (rc) 1040 if (rc)
@@ -1044,7 +1054,11 @@ err_out_iounmap:
1044 iounmap(mmio_base); 1054 iounmap(mmio_base);
1045err_out_free_ent: 1055err_out_free_ent:
1046 kfree(probe_ent); 1056 kfree(probe_ent);
1047err_out_regions: 1057err_out_msi:
1058 if (have_msi)
1059 pci_disable_msi(pdev);
1060 else
1061 pci_intx(pdev, 0);
1048 pci_release_regions(pdev); 1062 pci_release_regions(pdev);
1049err_out: 1063err_out:
1050 if (!pci_dev_busy) 1064 if (!pci_dev_busy)
@@ -1052,6 +1066,42 @@ err_out:
1052 return rc; 1066 return rc;
1053} 1067}
1054 1068
1069static void ahci_remove_one (struct pci_dev *pdev)
1070{
1071 struct device *dev = pci_dev_to_dev(pdev);
1072 struct ata_host_set *host_set = dev_get_drvdata(dev);
1073 struct ahci_host_priv *hpriv = host_set->private_data;
1074 struct ata_port *ap;
1075 unsigned int i;
1076 int have_msi;
1077
1078 for (i = 0; i < host_set->n_ports; i++) {
1079 ap = host_set->ports[i];
1080
1081 scsi_remove_host(ap->host);
1082 }
1083
1084 have_msi = hpriv->flags & AHCI_FLAG_MSI;
1085 free_irq(host_set->irq, host_set);
1086
1087 for (i = 0; i < host_set->n_ports; i++) {
1088 ap = host_set->ports[i];
1089
1090 ata_scsi_release(ap->host);
1091 scsi_host_put(ap->host);
1092 }
1093
1094 host_set->ops->host_stop(host_set);
1095 kfree(host_set);
1096
1097 if (have_msi)
1098 pci_disable_msi(pdev);
1099 else
1100 pci_intx(pdev, 0);
1101 pci_release_regions(pdev);
1102 pci_disable_device(pdev);
1103 dev_set_drvdata(dev, NULL);
1104}
1055 1105
1056static int __init ahci_init(void) 1106static int __init ahci_init(void)
1057{ 1107{