diff options
author | Jeff Garzik <jgarzik@pobox.com> | 2005-10-09 09:44:07 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@pobox.com> | 2005-10-09 09:44:07 -0400 |
commit | f58f8be7f65312f602f7970e7da47a6413e692b0 (patch) | |
tree | f60cc040deebceea1b44082dc713e95687d8527f /drivers/scsi/libata-core.c | |
parent | c71c18576d0d8aa4db876c737c3c597c724cf02f (diff) | |
parent | e710245bb0f980adfb1dfe850e43761a8117c6be (diff) |
Merge branch 'upstream'
Diffstat (limited to 'drivers/scsi/libata-core.c')
-rw-r--r-- | drivers/scsi/libata-core.c | 213 |
1 files changed, 104 insertions, 109 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c index ff291b365108..2c9275e30cb9 100644 --- a/drivers/scsi/libata-core.c +++ b/drivers/scsi/libata-core.c | |||
@@ -48,6 +48,7 @@ | |||
48 | #include <linux/completion.h> | 48 | #include <linux/completion.h> |
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 <scsi/scsi.h> | 52 | #include <scsi/scsi.h> |
52 | #include "scsi.h" | 53 | #include "scsi.h" |
53 | #include "scsi_priv.h" | 54 | #include "scsi_priv.h" |
@@ -70,7 +71,6 @@ static int fgb(u32 bitmap); | |||
70 | static int ata_choose_xfer_mode(struct ata_port *ap, | 71 | static int ata_choose_xfer_mode(struct ata_port *ap, |
71 | u8 *xfer_mode_out, | 72 | u8 *xfer_mode_out, |
72 | unsigned int *xfer_shift_out); | 73 | unsigned int *xfer_shift_out); |
73 | static int ata_qc_complete_noop(struct ata_queued_cmd *qc, u8 drv_stat); | ||
74 | static void __ata_qc_complete(struct ata_queued_cmd *qc); | 74 | static void __ata_qc_complete(struct ata_queued_cmd *qc); |
75 | 75 | ||
76 | static unsigned int ata_unique_id = 1; | 76 | static unsigned int ata_unique_id = 1; |
@@ -3132,52 +3132,6 @@ fsm_start: | |||
3132 | goto fsm_start; | 3132 | goto fsm_start; |
3133 | } | 3133 | } |
3134 | 3134 | ||
3135 | static void atapi_request_sense(struct ata_port *ap, struct ata_device *dev, | ||
3136 | struct scsi_cmnd *cmd) | ||
3137 | { | ||
3138 | DECLARE_COMPLETION(wait); | ||
3139 | struct ata_queued_cmd *qc; | ||
3140 | unsigned long flags; | ||
3141 | int rc; | ||
3142 | |||
3143 | DPRINTK("ATAPI request sense\n"); | ||
3144 | |||
3145 | qc = ata_qc_new_init(ap, dev); | ||
3146 | BUG_ON(qc == NULL); | ||
3147 | |||
3148 | /* FIXME: is this needed? */ | ||
3149 | memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer)); | ||
3150 | |||
3151 | ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer)); | ||
3152 | qc->dma_dir = DMA_FROM_DEVICE; | ||
3153 | |||
3154 | memset(&qc->cdb, 0, ap->cdb_len); | ||
3155 | qc->cdb[0] = REQUEST_SENSE; | ||
3156 | qc->cdb[4] = SCSI_SENSE_BUFFERSIZE; | ||
3157 | |||
3158 | qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; | ||
3159 | qc->tf.command = ATA_CMD_PACKET; | ||
3160 | |||
3161 | qc->tf.protocol = ATA_PROT_ATAPI; | ||
3162 | qc->tf.lbam = (8 * 1024) & 0xff; | ||
3163 | qc->tf.lbah = (8 * 1024) >> 8; | ||
3164 | qc->nbytes = SCSI_SENSE_BUFFERSIZE; | ||
3165 | |||
3166 | qc->waiting = &wait; | ||
3167 | qc->complete_fn = ata_qc_complete_noop; | ||
3168 | |||
3169 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
3170 | rc = ata_qc_issue(qc); | ||
3171 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
3172 | |||
3173 | if (rc) | ||
3174 | ata_port_disable(ap); | ||
3175 | else | ||
3176 | wait_for_completion(&wait); | ||
3177 | |||
3178 | DPRINTK("EXIT\n"); | ||
3179 | } | ||
3180 | |||
3181 | /** | 3135 | /** |
3182 | * ata_qc_timeout - Handle timeout of queued command | 3136 | * ata_qc_timeout - Handle timeout of queued command |
3183 | * @qc: Command that timed out | 3137 | * @qc: Command that timed out |
@@ -3297,14 +3251,14 @@ void ata_eng_timeout(struct ata_port *ap) | |||
3297 | DPRINTK("ENTER\n"); | 3251 | DPRINTK("ENTER\n"); |
3298 | 3252 | ||
3299 | qc = ata_qc_from_tag(ap, ap->active_tag); | 3253 | qc = ata_qc_from_tag(ap, ap->active_tag); |
3300 | if (!qc) { | 3254 | if (qc) |
3255 | ata_qc_timeout(qc); | ||
3256 | else { | ||
3301 | printk(KERN_ERR "ata%u: BUG: timeout without command\n", | 3257 | printk(KERN_ERR "ata%u: BUG: timeout without command\n", |
3302 | ap->id); | 3258 | ap->id); |
3303 | goto out; | 3259 | goto out; |
3304 | } | 3260 | } |
3305 | 3261 | ||
3306 | ata_qc_timeout(qc); | ||
3307 | |||
3308 | out: | 3262 | out: |
3309 | DPRINTK("EXIT\n"); | 3263 | DPRINTK("EXIT\n"); |
3310 | } | 3264 | } |
@@ -3373,7 +3327,7 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, | |||
3373 | return qc; | 3327 | return qc; |
3374 | } | 3328 | } |
3375 | 3329 | ||
3376 | static int ata_qc_complete_noop(struct ata_queued_cmd *qc, u8 drv_stat) | 3330 | int ata_qc_complete_noop(struct ata_queued_cmd *qc, u8 drv_stat) |
3377 | { | 3331 | { |
3378 | return 0; | 3332 | return 0; |
3379 | } | 3333 | } |
@@ -4409,7 +4363,7 @@ int ata_device_add(struct ata_probe_ent *ent) | |||
4409 | for (i = 0; i < count; i++) { | 4363 | for (i = 0; i < count; i++) { |
4410 | struct ata_port *ap = host_set->ports[i]; | 4364 | struct ata_port *ap = host_set->ports[i]; |
4411 | 4365 | ||
4412 | scsi_scan_host(ap->host); | 4366 | ata_scsi_scan_host(ap); |
4413 | } | 4367 | } |
4414 | 4368 | ||
4415 | dev_set_drvdata(dev, host_set); | 4369 | dev_set_drvdata(dev, host_set); |
@@ -4569,85 +4523,87 @@ void ata_pci_host_stop (struct ata_host_set *host_set) | |||
4569 | * ata_pci_init_native_mode - Initialize native-mode driver | 4523 | * ata_pci_init_native_mode - Initialize native-mode driver |
4570 | * @pdev: pci device to be initialized | 4524 | * @pdev: pci device to be initialized |
4571 | * @port: array[2] of pointers to port info structures. | 4525 | * @port: array[2] of pointers to port info structures. |
4526 | * @ports: bitmap of ports present | ||
4572 | * | 4527 | * |
4573 | * Utility function which allocates and initializes an | 4528 | * Utility function which allocates and initializes an |
4574 | * ata_probe_ent structure for a standard dual-port | 4529 | * ata_probe_ent structure for a standard dual-port |
4575 | * PIO-based IDE controller. The returned ata_probe_ent | 4530 | * PIO-based IDE controller. The returned ata_probe_ent |
4576 | * structure can be passed to ata_device_add(). The returned | 4531 | * structure can be passed to ata_device_add(). The returned |
4577 | * ata_probe_ent structure should then be freed with kfree(). | 4532 | * ata_probe_ent structure should then be freed with kfree(). |
4533 | * | ||
4534 | * The caller need only pass the address of the primary port, the | ||
4535 | * secondary will be deduced automatically. If the device has non | ||
4536 | * standard secondary port mappings this function can be called twice, | ||
4537 | * once for each interface. | ||
4578 | */ | 4538 | */ |
4579 | 4539 | ||
4580 | struct ata_probe_ent * | 4540 | struct ata_probe_ent * |
4581 | ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port) | 4541 | ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int ports) |
4582 | { | 4542 | { |
4583 | struct ata_probe_ent *probe_ent = | 4543 | struct ata_probe_ent *probe_ent = |
4584 | ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); | 4544 | ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); |
4545 | int p = 0; | ||
4546 | |||
4585 | if (!probe_ent) | 4547 | if (!probe_ent) |
4586 | return NULL; | 4548 | return NULL; |
4587 | 4549 | ||
4588 | probe_ent->n_ports = 2; | ||
4589 | probe_ent->irq = pdev->irq; | 4550 | probe_ent->irq = pdev->irq; |
4590 | probe_ent->irq_flags = SA_SHIRQ; | 4551 | probe_ent->irq_flags = SA_SHIRQ; |
4591 | 4552 | ||
4592 | probe_ent->port[0].cmd_addr = pci_resource_start(pdev, 0); | 4553 | if (ports & ATA_PORT_PRIMARY) { |
4593 | probe_ent->port[0].altstatus_addr = | 4554 | probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 0); |
4594 | probe_ent->port[0].ctl_addr = | 4555 | probe_ent->port[p].altstatus_addr = |
4595 | pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS; | 4556 | probe_ent->port[p].ctl_addr = |
4596 | probe_ent->port[0].bmdma_addr = pci_resource_start(pdev, 4); | 4557 | pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS; |
4597 | 4558 | probe_ent->port[p].bmdma_addr = pci_resource_start(pdev, 4); | |
4598 | probe_ent->port[1].cmd_addr = pci_resource_start(pdev, 2); | 4559 | ata_std_ports(&probe_ent->port[p]); |
4599 | probe_ent->port[1].altstatus_addr = | 4560 | p++; |
4600 | probe_ent->port[1].ctl_addr = | 4561 | } |
4601 | pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS; | ||
4602 | probe_ent->port[1].bmdma_addr = pci_resource_start(pdev, 4) + 8; | ||
4603 | 4562 | ||
4604 | ata_std_ports(&probe_ent->port[0]); | 4563 | if (ports & ATA_PORT_SECONDARY) { |
4605 | ata_std_ports(&probe_ent->port[1]); | 4564 | probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 2); |
4565 | probe_ent->port[p].altstatus_addr = | ||
4566 | probe_ent->port[p].ctl_addr = | ||
4567 | pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS; | ||
4568 | probe_ent->port[p].bmdma_addr = pci_resource_start(pdev, 4) + 8; | ||
4569 | ata_std_ports(&probe_ent->port[p]); | ||
4570 | p++; | ||
4571 | } | ||
4606 | 4572 | ||
4573 | probe_ent->n_ports = p; | ||
4607 | return probe_ent; | 4574 | return probe_ent; |
4608 | } | 4575 | } |
4609 | 4576 | ||
4610 | static struct ata_probe_ent * | 4577 | static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev, struct ata_port_info **port, int port_num) |
4611 | ata_pci_init_legacy_mode(struct pci_dev *pdev, struct ata_port_info **port, | ||
4612 | struct ata_probe_ent **ppe2) | ||
4613 | { | 4578 | { |
4614 | struct ata_probe_ent *probe_ent, *probe_ent2; | 4579 | struct ata_probe_ent *probe_ent; |
4615 | 4580 | ||
4616 | probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); | 4581 | probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); |
4617 | if (!probe_ent) | 4582 | if (!probe_ent) |
4618 | return NULL; | 4583 | return NULL; |
4619 | probe_ent2 = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[1]); | ||
4620 | if (!probe_ent2) { | ||
4621 | kfree(probe_ent); | ||
4622 | return NULL; | ||
4623 | } | ||
4624 | |||
4625 | probe_ent->n_ports = 1; | ||
4626 | probe_ent->irq = 14; | ||
4627 | 4584 | ||
4628 | probe_ent->hard_port_no = 0; | 4585 | |
4629 | probe_ent->legacy_mode = 1; | 4586 | probe_ent->legacy_mode = 1; |
4630 | 4587 | probe_ent->n_ports = 1; | |
4631 | probe_ent2->n_ports = 1; | 4588 | probe_ent->hard_port_no = port_num; |
4632 | probe_ent2->irq = 15; | 4589 | |
4633 | 4590 | switch(port_num) | |
4634 | probe_ent2->hard_port_no = 1; | 4591 | { |
4635 | probe_ent2->legacy_mode = 1; | 4592 | case 0: |
4636 | 4593 | probe_ent->irq = 14; | |
4637 | probe_ent->port[0].cmd_addr = 0x1f0; | 4594 | probe_ent->port[0].cmd_addr = 0x1f0; |
4638 | probe_ent->port[0].altstatus_addr = | 4595 | probe_ent->port[0].altstatus_addr = |
4639 | probe_ent->port[0].ctl_addr = 0x3f6; | 4596 | probe_ent->port[0].ctl_addr = 0x3f6; |
4640 | probe_ent->port[0].bmdma_addr = pci_resource_start(pdev, 4); | 4597 | break; |
4641 | 4598 | case 1: | |
4642 | probe_ent2->port[0].cmd_addr = 0x170; | 4599 | probe_ent->irq = 15; |
4643 | probe_ent2->port[0].altstatus_addr = | 4600 | probe_ent->port[0].cmd_addr = 0x170; |
4644 | probe_ent2->port[0].ctl_addr = 0x376; | 4601 | probe_ent->port[0].altstatus_addr = |
4645 | probe_ent2->port[0].bmdma_addr = pci_resource_start(pdev, 4)+8; | 4602 | probe_ent->port[0].ctl_addr = 0x376; |
4646 | 4603 | break; | |
4604 | } | ||
4605 | probe_ent->port[0].bmdma_addr = pci_resource_start(pdev, 4) + 8 * port_num; | ||
4647 | ata_std_ports(&probe_ent->port[0]); | 4606 | ata_std_ports(&probe_ent->port[0]); |
4648 | ata_std_ports(&probe_ent2->port[0]); | ||
4649 | |||
4650 | *ppe2 = probe_ent2; | ||
4651 | return probe_ent; | 4607 | return probe_ent; |
4652 | } | 4608 | } |
4653 | 4609 | ||
@@ -4676,7 +4632,7 @@ ata_pci_init_legacy_mode(struct pci_dev *pdev, struct ata_port_info **port, | |||
4676 | int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, | 4632 | int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, |
4677 | unsigned int n_ports) | 4633 | unsigned int n_ports) |
4678 | { | 4634 | { |
4679 | struct ata_probe_ent *probe_ent, *probe_ent2 = NULL; | 4635 | struct ata_probe_ent *probe_ent = NULL, *probe_ent2 = NULL; |
4680 | struct ata_port_info *port[2]; | 4636 | struct ata_port_info *port[2]; |
4681 | u8 tmp8, mask; | 4637 | u8 tmp8, mask; |
4682 | unsigned int legacy_mode = 0; | 4638 | unsigned int legacy_mode = 0; |
@@ -4693,7 +4649,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, | |||
4693 | 4649 | ||
4694 | if ((port[0]->host_flags & ATA_FLAG_NO_LEGACY) == 0 | 4650 | if ((port[0]->host_flags & ATA_FLAG_NO_LEGACY) == 0 |
4695 | && (pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) { | 4651 | && (pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) { |
4696 | /* TODO: support transitioning to native mode? */ | 4652 | /* TODO: What if one channel is in native mode ... */ |
4697 | pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8); | 4653 | pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8); |
4698 | mask = (1 << 2) | (1 << 0); | 4654 | mask = (1 << 2) | (1 << 0); |
4699 | if ((tmp8 & mask) != mask) | 4655 | if ((tmp8 & mask) != mask) |
@@ -4701,11 +4657,20 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, | |||
4701 | } | 4657 | } |
4702 | 4658 | ||
4703 | /* FIXME... */ | 4659 | /* FIXME... */ |
4704 | if ((!legacy_mode) && (n_ports > 1)) { | 4660 | if ((!legacy_mode) && (n_ports > 2)) { |
4705 | printk(KERN_ERR "ata: BUG: native mode, n_ports > 1\n"); | 4661 | printk(KERN_ERR "ata: BUG: native mode, n_ports > 2\n"); |
4706 | return -EINVAL; | 4662 | n_ports = 2; |
4663 | /* For now */ | ||
4707 | } | 4664 | } |
4708 | 4665 | ||
4666 | /* FIXME: Really for ATA it isn't safe because the device may be | ||
4667 | multi-purpose and we want to leave it alone if it was already | ||
4668 | enabled. Secondly for shared use as Arjan says we want refcounting | ||
4669 | |||
4670 | Checking dev->is_enabled is insufficient as this is not set at | ||
4671 | boot for the primary video which is BIOS enabled | ||
4672 | */ | ||
4673 | |||
4709 | rc = pci_enable_device(pdev); | 4674 | rc = pci_enable_device(pdev); |
4710 | if (rc) | 4675 | if (rc) |
4711 | return rc; | 4676 | return rc; |
@@ -4716,6 +4681,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, | |||
4716 | goto err_out; | 4681 | goto err_out; |
4717 | } | 4682 | } |
4718 | 4683 | ||
4684 | /* FIXME: Should use platform specific mappers for legacy port ranges */ | ||
4719 | if (legacy_mode) { | 4685 | if (legacy_mode) { |
4720 | if (!request_region(0x1f0, 8, "libata")) { | 4686 | if (!request_region(0x1f0, 8, "libata")) { |
4721 | struct resource *conflict, res; | 4687 | struct resource *conflict, res; |
@@ -4760,10 +4726,17 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, | |||
4760 | goto err_out_regions; | 4726 | goto err_out_regions; |
4761 | 4727 | ||
4762 | if (legacy_mode) { | 4728 | if (legacy_mode) { |
4763 | probe_ent = ata_pci_init_legacy_mode(pdev, port, &probe_ent2); | 4729 | if (legacy_mode & (1 << 0)) |
4764 | } else | 4730 | probe_ent = ata_pci_init_legacy_port(pdev, port, 0); |
4765 | probe_ent = ata_pci_init_native_mode(pdev, port); | 4731 | if (legacy_mode & (1 << 1)) |
4766 | if (!probe_ent) { | 4732 | probe_ent2 = ata_pci_init_legacy_port(pdev, port, 1); |
4733 | } else { | ||
4734 | if (n_ports == 2) | ||
4735 | probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); | ||
4736 | else | ||
4737 | probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY); | ||
4738 | } | ||
4739 | if (!probe_ent && !probe_ent2) { | ||
4767 | rc = -ENOMEM; | 4740 | rc = -ENOMEM; |
4768 | goto err_out_regions; | 4741 | goto err_out_regions; |
4769 | } | 4742 | } |
@@ -4875,6 +4848,27 @@ static void __exit ata_exit(void) | |||
4875 | module_init(ata_init); | 4848 | module_init(ata_init); |
4876 | module_exit(ata_exit); | 4849 | module_exit(ata_exit); |
4877 | 4850 | ||
4851 | static unsigned long ratelimit_time; | ||
4852 | static spinlock_t ata_ratelimit_lock = SPIN_LOCK_UNLOCKED; | ||
4853 | |||
4854 | int ata_ratelimit(void) | ||
4855 | { | ||
4856 | int rc; | ||
4857 | unsigned long flags; | ||
4858 | |||
4859 | spin_lock_irqsave(&ata_ratelimit_lock, flags); | ||
4860 | |||
4861 | if (time_after(jiffies, ratelimit_time)) { | ||
4862 | rc = 1; | ||
4863 | ratelimit_time = jiffies + (HZ/5); | ||
4864 | } else | ||
4865 | rc = 0; | ||
4866 | |||
4867 | spin_unlock_irqrestore(&ata_ratelimit_lock, flags); | ||
4868 | |||
4869 | return rc; | ||
4870 | } | ||
4871 | |||
4878 | /* | 4872 | /* |
4879 | * libata is essentially a library of internal helper functions for | 4873 | * libata is essentially a library of internal helper functions for |
4880 | * low-level ATA host controller drivers. As such, the API/ABI is | 4874 | * low-level ATA host controller drivers. As such, the API/ABI is |
@@ -4916,6 +4910,7 @@ EXPORT_SYMBOL_GPL(sata_phy_reset); | |||
4916 | EXPORT_SYMBOL_GPL(__sata_phy_reset); | 4910 | EXPORT_SYMBOL_GPL(__sata_phy_reset); |
4917 | EXPORT_SYMBOL_GPL(ata_bus_reset); | 4911 | EXPORT_SYMBOL_GPL(ata_bus_reset); |
4918 | EXPORT_SYMBOL_GPL(ata_port_disable); | 4912 | EXPORT_SYMBOL_GPL(ata_port_disable); |
4913 | EXPORT_SYMBOL_GPL(ata_ratelimit); | ||
4919 | EXPORT_SYMBOL_GPL(ata_scsi_ioctl); | 4914 | EXPORT_SYMBOL_GPL(ata_scsi_ioctl); |
4920 | EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); | 4915 | EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); |
4921 | EXPORT_SYMBOL_GPL(ata_scsi_error); | 4916 | EXPORT_SYMBOL_GPL(ata_scsi_error); |