aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-04-17 10:44:07 -0400
committerJeff Garzik <jeff@garzik.org>2007-04-28 14:16:03 -0400
commitf31871951b38daf2d7ca17daad59fdb735062da3 (patch)
tree4286402eaf679b6fb73e893d8e51bb693559091d /drivers/ata
parentecef7253235e7a9365afe08a508e11bed91c1c11 (diff)
libata: separate out ata_host_alloc() and ata_host_register()
Reorganize ata_host_alloc() and its subroutines into the following three functions. * ata_host_alloc() : allocates host and its ports. shost is not registered automatically. * ata_scsi_add_hosts() : allocates and adds shosts associated with an ATA host. Used by ata_host_register(). * ata_host_register() : takes a fully initialized ata_host structure and registers it to libata layer and probes it. Only ata_host_alloc() and ata_host_register() are exported. ata_device_add() is rewritten using the above functions. This patch does not introduce any observable behavior change. Things worth mentioning. * print_id is assigned at registration time and LLDs are allowed to overallocate ports and reduce host->n_ports during initialization. ata_host_register() will throw away unused ports automatically. * All SCSI host initialization stuff now resides in ata_scsi_add_hosts() in libata-scsi.c, where it should be. * ipr is now the only user of ata_host_init(). Either kill it by converting ipr to use ata_host_alloc() and friends or rename and move it to libata-scsi.c Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/ata')
-rw-r--r--drivers/ata/libata-core.c471
-rw-r--r--drivers/ata/libata-scsi.c68
-rw-r--r--drivers/ata/libata.h8
3 files changed, 323 insertions, 224 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index aea766a48e05..b23f35a4ee6b 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -72,7 +72,7 @@ static unsigned int ata_dev_init_params(struct ata_device *dev,
72static unsigned int ata_dev_set_xfermode(struct ata_device *dev); 72static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
73static void ata_dev_xfermask(struct ata_device *dev); 73static void ata_dev_xfermask(struct ata_device *dev);
74 74
75static unsigned int ata_print_id = 1; 75unsigned int ata_print_id = 1;
76static struct workqueue_struct *ata_wq; 76static struct workqueue_struct *ata_wq;
77 77
78struct workqueue_struct *ata_aux_wq; 78struct workqueue_struct *ata_aux_wq;
@@ -5666,42 +5666,35 @@ void ata_dev_init(struct ata_device *dev)
5666} 5666}
5667 5667
5668/** 5668/**
5669 * ata_port_init - Initialize an ata_port structure 5669 * ata_port_alloc - allocate and initialize basic ATA port resources
5670 * @ap: Structure to initialize 5670 * @host: ATA host this allocated port belongs to
5671 * @host: Collection of hosts to which @ap belongs
5672 * @ent: Probe information provided by low-level driver
5673 * @port_no: Port number associated with this ata_port
5674 * 5671 *
5675 * Initialize a new ata_port structure. 5672 * Allocate and initialize basic ATA port resources.
5673 *
5674 * RETURNS:
5675 * Allocate ATA port on success, NULL on failure.
5676 * 5676 *
5677 * LOCKING: 5677 * LOCKING:
5678 * Inherited from caller. 5678 * Inherited from calling layer (may sleep).
5679 */ 5679 */
5680void ata_port_init(struct ata_port *ap, struct ata_host *host, 5680struct ata_port *ata_port_alloc(struct ata_host *host)
5681 const struct ata_probe_ent *ent, unsigned int port_no)
5682{ 5681{
5682 struct ata_port *ap;
5683 unsigned int i; 5683 unsigned int i;
5684 5684
5685 DPRINTK("ENTER\n");
5686
5687 ap = kzalloc(sizeof(*ap), GFP_KERNEL);
5688 if (!ap)
5689 return NULL;
5690
5685 ap->lock = &host->lock; 5691 ap->lock = &host->lock;
5686 ap->flags = ATA_FLAG_DISABLED; 5692 ap->flags = ATA_FLAG_DISABLED;
5687 ap->print_id = ata_print_id++; 5693 ap->print_id = -1;
5688 ap->ctl = ATA_DEVCTL_OBS; 5694 ap->ctl = ATA_DEVCTL_OBS;
5689 ap->host = host; 5695 ap->host = host;
5690 ap->dev = ent->dev; 5696 ap->dev = host->dev;
5691 ap->port_no = port_no; 5697
5692 if (port_no == 1 && ent->pinfo2) {
5693 ap->pio_mask = ent->pinfo2->pio_mask;
5694 ap->mwdma_mask = ent->pinfo2->mwdma_mask;
5695 ap->udma_mask = ent->pinfo2->udma_mask;
5696 ap->flags |= ent->pinfo2->flags;
5697 ap->ops = ent->pinfo2->port_ops;
5698 } else {
5699 ap->pio_mask = ent->pio_mask;
5700 ap->mwdma_mask = ent->mwdma_mask;
5701 ap->udma_mask = ent->udma_mask;
5702 ap->flags |= ent->port_flags;
5703 ap->ops = ent->port_ops;
5704 }
5705 ap->hw_sata_spd_limit = UINT_MAX; 5698 ap->hw_sata_spd_limit = UINT_MAX;
5706 ap->active_tag = ATA_TAG_POISON; 5699 ap->active_tag = ATA_TAG_POISON;
5707 ap->last_ctl = 0xFF; 5700 ap->last_ctl = 0xFF;
@@ -5721,10 +5714,7 @@ void ata_port_init(struct ata_port *ap, struct ata_host *host,
5721 INIT_LIST_HEAD(&ap->eh_done_q); 5714 INIT_LIST_HEAD(&ap->eh_done_q);
5722 init_waitqueue_head(&ap->eh_wait_q); 5715 init_waitqueue_head(&ap->eh_wait_q);
5723 5716
5724 /* set cable type */
5725 ap->cbl = ATA_CBL_NONE; 5717 ap->cbl = ATA_CBL_NONE;
5726 if (ap->flags & ATA_FLAG_SATA)
5727 ap->cbl = ATA_CBL_SATA;
5728 5718
5729 for (i = 0; i < ATA_MAX_DEVICES; i++) { 5719 for (i = 0; i < ATA_MAX_DEVICES; i++) {
5730 struct ata_device *dev = &ap->device[i]; 5720 struct ata_device *dev = &ap->device[i];
@@ -5737,77 +5727,6 @@ void ata_port_init(struct ata_port *ap, struct ata_host *host,
5737 ap->stats.unhandled_irq = 1; 5727 ap->stats.unhandled_irq = 1;
5738 ap->stats.idle_irq = 1; 5728 ap->stats.idle_irq = 1;
5739#endif 5729#endif
5740
5741 memcpy(&ap->ioaddr, &ent->port[port_no], sizeof(struct ata_ioports));
5742}
5743
5744/**
5745 * ata_port_init_shost - Initialize SCSI host associated with ATA port
5746 * @ap: ATA port to initialize SCSI host for
5747 * @shost: SCSI host associated with @ap
5748 *
5749 * Initialize SCSI host @shost associated with ATA port @ap.
5750 *
5751 * LOCKING:
5752 * Inherited from caller.
5753 */
5754static void ata_port_init_shost(struct ata_port *ap, struct Scsi_Host *shost)
5755{
5756 ap->scsi_host = shost;
5757
5758 shost->unique_id = ap->print_id;
5759 shost->max_id = 16;
5760 shost->max_lun = 1;
5761 shost->max_channel = 1;
5762 shost->max_cmd_len = 16;
5763}
5764
5765/**
5766 * ata_port_add - Attach low-level ATA driver to system
5767 * @ent: Information provided by low-level driver
5768 * @host: Collections of ports to which we add
5769 * @port_no: Port number associated with this host
5770 *
5771 * Attach low-level ATA driver to system.
5772 *
5773 * LOCKING:
5774 * PCI/etc. bus probe sem.
5775 *
5776 * RETURNS:
5777 * New ata_port on success, for NULL on error.
5778 */
5779static struct ata_port * ata_port_add(const struct ata_probe_ent *ent,
5780 struct ata_host *host,
5781 unsigned int port_no)
5782{
5783 struct Scsi_Host *shost;
5784 struct ata_port *ap;
5785
5786 DPRINTK("ENTER\n");
5787
5788 if (!ent->port_ops->error_handler &&
5789 !(ent->port_flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST))) {
5790 printk(KERN_ERR "ata%u: no reset mechanism available\n",
5791 port_no);
5792 return NULL;
5793 }
5794
5795 ap = kzalloc(sizeof(struct ata_port), GFP_KERNEL);
5796 if (!ap)
5797 return NULL;
5798
5799 shost = scsi_host_alloc(ent->sht, sizeof(struct ata_port *));
5800 if (!shost) {
5801 kfree(ap);
5802 return NULL;
5803 }
5804
5805 *(struct ata_port **)&shost->hostdata[0] = ap;
5806 shost->transportt = &ata_scsi_transport_template;
5807
5808 ata_port_init(ap, host, ent, port_no);
5809 ata_port_init_shost(ap, shost);
5810
5811 return ap; 5730 return ap;
5812} 5731}
5813 5732
@@ -5846,13 +5765,79 @@ static void ata_host_release(struct device *gendev, void *res)
5846} 5765}
5847 5766
5848/** 5767/**
5768 * ata_host_alloc - allocate and init basic ATA host resources
5769 * @dev: generic device this host is associated with
5770 * @max_ports: maximum number of ATA ports associated with this host
5771 *
5772 * Allocate and initialize basic ATA host resources. LLD calls
5773 * this function to allocate a host, initializes it fully and
5774 * attaches it using ata_host_register().
5775 *
5776 * @max_ports ports are allocated and host->n_ports is
5777 * initialized to @max_ports. The caller is allowed to decrease
5778 * host->n_ports before calling ata_host_register(). The unused
5779 * ports will be automatically freed on registration.
5780 *
5781 * RETURNS:
5782 * Allocate ATA host on success, NULL on failure.
5783 *
5784 * LOCKING:
5785 * Inherited from calling layer (may sleep).
5786 */
5787struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
5788{
5789 struct ata_host *host;
5790 size_t sz;
5791 int i;
5792
5793 DPRINTK("ENTER\n");
5794
5795 if (!devres_open_group(dev, NULL, GFP_KERNEL))
5796 return NULL;
5797
5798 /* alloc a container for our list of ATA ports (buses) */
5799 sz = sizeof(struct ata_host) + (max_ports + 1) * sizeof(void *);
5800 /* alloc a container for our list of ATA ports (buses) */
5801 host = devres_alloc(ata_host_release, sz, GFP_KERNEL);
5802 if (!host)
5803 goto err_out;
5804
5805 devres_add(dev, host);
5806 dev_set_drvdata(dev, host);
5807
5808 spin_lock_init(&host->lock);
5809 host->dev = dev;
5810 host->n_ports = max_ports;
5811
5812 /* allocate ports bound to this host */
5813 for (i = 0; i < max_ports; i++) {
5814 struct ata_port *ap;
5815
5816 ap = ata_port_alloc(host);
5817 if (!ap)
5818 goto err_out;
5819
5820 ap->port_no = i;
5821 host->ports[i] = ap;
5822 }
5823
5824 devres_remove_group(dev, NULL);
5825 return host;
5826
5827 err_out:
5828 devres_release_group(dev, NULL);
5829 return NULL;
5830}
5831
5832/**
5849 * ata_host_start - start and freeze ports of an ATA host 5833 * ata_host_start - start and freeze ports of an ATA host
5850 * @host: ATA host to start ports for 5834 * @host: ATA host to start ports for
5851 * 5835 *
5852 * Start and then freeze ports of @host. Started status is 5836 * Start and then freeze ports of @host. Started status is
5853 * recorded in host->flags, so this function can be called 5837 * recorded in host->flags, so this function can be called
5854 * multiple times. Ports are guaranteed to get started only 5838 * multiple times. Ports are guaranteed to get started only
5855 * once. 5839 * once. If host->ops isn't initialized yet, its set to the
5840 * first non-dummy port ops.
5856 * 5841 *
5857 * LOCKING: 5842 * LOCKING:
5858 * Inherited from calling layer (may sleep). 5843 * Inherited from calling layer (may sleep).
@@ -5870,6 +5855,9 @@ int ata_host_start(struct ata_host *host)
5870 for (i = 0; i < host->n_ports; i++) { 5855 for (i = 0; i < host->n_ports; i++) {
5871 struct ata_port *ap = host->ports[i]; 5856 struct ata_port *ap = host->ports[i];
5872 5857
5858 if (!host->ops && !ata_port_is_dummy(ap))
5859 host->ops = ap->ops;
5860
5873 if (ap->ops->port_start) { 5861 if (ap->ops->port_start) {
5874 rc = ap->ops->port_start(ap); 5862 rc = ap->ops->port_start(ap);
5875 if (rc) { 5863 if (rc) {
@@ -5906,7 +5894,7 @@ int ata_host_start(struct ata_host *host)
5906 * PCI/etc. bus probe sem. 5894 * PCI/etc. bus probe sem.
5907 * 5895 *
5908 */ 5896 */
5909 5897/* KILLME - the only user left is ipr */
5910void ata_host_init(struct ata_host *host, struct device *dev, 5898void ata_host_init(struct ata_host *host, struct device *dev,
5911 unsigned long flags, const struct ata_port_operations *ops) 5899 unsigned long flags, const struct ata_port_operations *ops)
5912{ 5900{
@@ -5917,6 +5905,143 @@ void ata_host_init(struct ata_host *host, struct device *dev,
5917} 5905}
5918 5906
5919/** 5907/**
5908 * ata_host_register - register initialized ATA host
5909 * @host: ATA host to register
5910 * @sht: template for SCSI host
5911 *
5912 * Register initialized ATA host. @host is allocated using
5913 * ata_host_alloc() and fully initialized by LLD. This function
5914 * starts ports, registers @host with ATA and SCSI layers and
5915 * probe registered devices.
5916 *
5917 * LOCKING:
5918 * Inherited from calling layer (may sleep).
5919 *
5920 * RETURNS:
5921 * 0 on success, -errno otherwise.
5922 */
5923int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
5924{
5925 int i, rc;
5926
5927 /* host must have been started */
5928 if (!(host->flags & ATA_HOST_STARTED)) {
5929 dev_printk(KERN_ERR, host->dev,
5930 "BUG: trying to register unstarted host\n");
5931 WARN_ON(1);
5932 return -EINVAL;
5933 }
5934
5935 /* Blow away unused ports. This happens when LLD can't
5936 * determine the exact number of ports to allocate at
5937 * allocation time.
5938 */
5939 for (i = host->n_ports; host->ports[i]; i++)
5940 kfree(host->ports[i]);
5941
5942 /* give ports names and add SCSI hosts */
5943 for (i = 0; i < host->n_ports; i++)
5944 host->ports[i]->print_id = ata_print_id++;
5945
5946 rc = ata_scsi_add_hosts(host, sht);
5947 if (rc)
5948 return rc;
5949
5950 /* set cable, sata_spd_limit and report */
5951 for (i = 0; i < host->n_ports; i++) {
5952 struct ata_port *ap = host->ports[i];
5953 int irq_line;
5954 u32 scontrol;
5955 unsigned long xfer_mask;
5956
5957 /* set SATA cable type if still unset */
5958 if (ap->cbl == ATA_CBL_NONE && (ap->flags & ATA_FLAG_SATA))
5959 ap->cbl = ATA_CBL_SATA;
5960
5961 /* init sata_spd_limit to the current value */
5962 if (sata_scr_read(ap, SCR_CONTROL, &scontrol) == 0) {
5963 int spd = (scontrol >> 4) & 0xf;
5964 ap->hw_sata_spd_limit &= (1 << spd) - 1;
5965 }
5966 ap->sata_spd_limit = ap->hw_sata_spd_limit;
5967
5968 /* report the secondary IRQ for second channel legacy */
5969 irq_line = host->irq;
5970 if (i == 1 && host->irq2)
5971 irq_line = host->irq2;
5972
5973 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask,
5974 ap->udma_mask);
5975
5976 /* print per-port info to dmesg */
5977 if (!ata_port_is_dummy(ap))
5978 ata_port_printk(ap, KERN_INFO, "%cATA max %s cmd 0x%p "
5979 "ctl 0x%p bmdma 0x%p irq %d\n",
5980 ap->cbl == ATA_CBL_SATA ? 'S' : 'P',
5981 ata_mode_string(xfer_mask),
5982 ap->ioaddr.cmd_addr,
5983 ap->ioaddr.ctl_addr,
5984 ap->ioaddr.bmdma_addr,
5985 irq_line);
5986 else
5987 ata_port_printk(ap, KERN_INFO, "DUMMY\n");
5988 }
5989
5990 /* perform each probe synchronously */
5991 DPRINTK("probe begin\n");
5992 for (i = 0; i < host->n_ports; i++) {
5993 struct ata_port *ap = host->ports[i];
5994 int rc;
5995
5996 /* probe */
5997 if (ap->ops->error_handler) {
5998 struct ata_eh_info *ehi = &ap->eh_info;
5999 unsigned long flags;
6000
6001 ata_port_probe(ap);
6002
6003 /* kick EH for boot probing */
6004 spin_lock_irqsave(ap->lock, flags);
6005
6006 ehi->probe_mask = (1 << ATA_MAX_DEVICES) - 1;
6007 ehi->action |= ATA_EH_SOFTRESET;
6008 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET;
6009
6010 ap->pflags |= ATA_PFLAG_LOADING;
6011 ata_port_schedule_eh(ap);
6012
6013 spin_unlock_irqrestore(ap->lock, flags);
6014
6015 /* wait for EH to finish */
6016 ata_port_wait_eh(ap);
6017 } else {
6018 DPRINTK("ata%u: bus probe begin\n", ap->print_id);
6019 rc = ata_bus_probe(ap);
6020 DPRINTK("ata%u: bus probe end\n", ap->print_id);
6021
6022 if (rc) {
6023 /* FIXME: do something useful here?
6024 * Current libata behavior will
6025 * tear down everything when
6026 * the module is removed
6027 * or the h/w is unplugged.
6028 */
6029 }
6030 }
6031 }
6032
6033 /* probes are done, now scan each port's disk(s) */
6034 DPRINTK("host probe begin\n");
6035 for (i = 0; i < host->n_ports; i++) {
6036 struct ata_port *ap = host->ports[i];
6037
6038 ata_scsi_scan_host(ap);
6039 }
6040
6041 return 0;
6042}
6043
6044/**
5920 * ata_device_add - Register hardware device with ATA and SCSI layers 6045 * ata_device_add - Register hardware device with ATA and SCSI layers
5921 * @ent: Probe information describing hardware device to be registered 6046 * @ent: Probe information describing hardware device to be registered
5922 * 6047 *
@@ -5948,62 +6073,53 @@ int ata_device_add(const struct ata_probe_ent *ent)
5948 return 0; 6073 return 0;
5949 } 6074 }
5950 6075
6076 if (!ent->port_ops->error_handler &&
6077 !(ent->port_flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST))) {
6078 dev_printk(KERN_ERR, dev, "no reset mechanism available\n");
6079 return 0;
6080 }
6081
5951 if (!devres_open_group(dev, ata_device_add, GFP_KERNEL)) 6082 if (!devres_open_group(dev, ata_device_add, GFP_KERNEL))
5952 return 0; 6083 return 0;
5953 6084
5954 /* alloc a container for our list of ATA ports (buses) */ 6085 /* allocate host */
5955 host = devres_alloc(ata_host_release, sizeof(struct ata_host) + 6086 host = ata_host_alloc(dev, ent->n_ports);
5956 (ent->n_ports * sizeof(void *)), GFP_KERNEL);
5957 if (!host)
5958 goto err_out;
5959 devres_add(dev, host);
5960 dev_set_drvdata(dev, host);
5961 6087
5962 ata_host_init(host, dev, ent->_host_flags, ent->port_ops);
5963 host->n_ports = ent->n_ports;
5964 host->irq = ent->irq; 6088 host->irq = ent->irq;
5965 host->irq2 = ent->irq2; 6089 host->irq2 = ent->irq2;
5966 host->iomap = ent->iomap; 6090 host->iomap = ent->iomap;
5967 host->private_data = ent->private_data; 6091 host->private_data = ent->private_data;
6092 host->ops = ent->port_ops;
6093 host->flags = ent->_host_flags;
5968 6094
5969 /* register each port bound to this device */
5970 for (i = 0; i < host->n_ports; i++) { 6095 for (i = 0; i < host->n_ports; i++) {
5971 struct ata_port *ap; 6096 struct ata_port *ap = host->ports[i];
5972 unsigned long xfer_mode_mask;
5973 int irq_line = ent->irq;
5974
5975 ap = ata_port_add(ent, host, i);
5976 host->ports[i] = ap;
5977 if (!ap)
5978 goto err_out;
5979 6097
5980 /* dummy? */ 6098 /* dummy? */
5981 if (ent->dummy_port_mask & (1 << i)) { 6099 if (ent->dummy_port_mask & (1 << i)) {
5982 ata_port_printk(ap, KERN_INFO, "DUMMY\n");
5983 ap->ops = &ata_dummy_port_ops; 6100 ap->ops = &ata_dummy_port_ops;
5984 continue; 6101 continue;
5985 } 6102 }
5986 6103
5987 /* Report the secondary IRQ for second channel legacy */ 6104 if (ap->port_no == 1 && ent->pinfo2) {
5988 if (i == 1 && ent->irq2) 6105 ap->pio_mask = ent->pinfo2->pio_mask;
5989 irq_line = ent->irq2; 6106 ap->mwdma_mask = ent->pinfo2->mwdma_mask;
5990 6107 ap->udma_mask = ent->pinfo2->udma_mask;
5991 xfer_mode_mask =(ap->udma_mask << ATA_SHIFT_UDMA) | 6108 ap->flags |= ent->pinfo2->flags;
5992 (ap->mwdma_mask << ATA_SHIFT_MWDMA) | 6109 ap->ops = ent->pinfo2->port_ops;
5993 (ap->pio_mask << ATA_SHIFT_PIO); 6110 } else {
6111 ap->pio_mask = ent->pio_mask;
6112 ap->mwdma_mask = ent->mwdma_mask;
6113 ap->udma_mask = ent->udma_mask;
6114 ap->flags |= ent->port_flags;
6115 ap->ops = ent->port_ops;
6116 }
5994 6117
5995 /* print per-port info to dmesg */ 6118 memcpy(&ap->ioaddr, &ent->port[ap->port_no],
5996 ata_port_printk(ap, KERN_INFO, "%cATA max %s cmd 0x%p " 6119 sizeof(struct ata_ioports));
5997 "ctl 0x%p bmdma 0x%p irq %d\n",
5998 ap->flags & ATA_FLAG_SATA ? 'S' : 'P',
5999 ata_mode_string(xfer_mode_mask),
6000 ap->ioaddr.cmd_addr,
6001 ap->ioaddr.ctl_addr,
6002 ap->ioaddr.bmdma_addr,
6003 irq_line);
6004 } 6120 }
6005 6121
6006 /* start ports */ 6122 /* start and freeze ports before requesting IRQ */
6007 rc = ata_host_start(host); 6123 rc = ata_host_start(host);
6008 if (rc) 6124 if (rc)
6009 goto err_out; 6125 goto err_out;
@@ -6036,80 +6152,17 @@ int ata_device_add(const struct ata_probe_ent *ent)
6036 /* resource acquisition complete */ 6152 /* resource acquisition complete */
6037 devres_remove_group(dev, ata_device_add); 6153 devres_remove_group(dev, ata_device_add);
6038 6154
6039 /* perform each probe synchronously */ 6155 /* register */
6040 DPRINTK("probe begin\n"); 6156 rc = ata_host_register(host, ent->sht);
6041 for (i = 0; i < host->n_ports; i++) { 6157 if (rc)
6042 struct ata_port *ap = host->ports[i]; 6158 goto err_out;
6043 u32 scontrol;
6044 int rc;
6045
6046 /* init sata_spd_limit to the current value */
6047 if (sata_scr_read(ap, SCR_CONTROL, &scontrol) == 0) {
6048 int spd = (scontrol >> 4) & 0xf;
6049 ap->hw_sata_spd_limit &= (1 << spd) - 1;
6050 }
6051 ap->sata_spd_limit = ap->hw_sata_spd_limit;
6052
6053 rc = scsi_add_host(ap->scsi_host, dev);
6054 if (rc) {
6055 ata_port_printk(ap, KERN_ERR, "scsi_add_host failed\n");
6056 /* FIXME: do something useful here */
6057 /* FIXME: handle unconditional calls to
6058 * scsi_scan_host and ata_host_remove, below,
6059 * at the very least
6060 */
6061 }
6062
6063 if (ap->ops->error_handler) {
6064 struct ata_eh_info *ehi = &ap->eh_info;
6065 unsigned long flags;
6066
6067 ata_port_probe(ap);
6068
6069 /* kick EH for boot probing */
6070 spin_lock_irqsave(ap->lock, flags);
6071
6072 ehi->probe_mask = (1 << ATA_MAX_DEVICES) - 1;
6073 ehi->action |= ATA_EH_SOFTRESET;
6074 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET;
6075
6076 ap->pflags |= ATA_PFLAG_LOADING;
6077 ata_port_schedule_eh(ap);
6078
6079 spin_unlock_irqrestore(ap->lock, flags);
6080
6081 /* wait for EH to finish */
6082 ata_port_wait_eh(ap);
6083 } else {
6084 DPRINTK("ata%u: bus probe begin\n", ap->print_id);
6085 rc = ata_bus_probe(ap);
6086 DPRINTK("ata%u: bus probe end\n", ap->print_id);
6087
6088 if (rc) {
6089 /* FIXME: do something useful here?
6090 * Current libata behavior will
6091 * tear down everything when
6092 * the module is removed
6093 * or the h/w is unplugged.
6094 */
6095 }
6096 }
6097 }
6098
6099 /* probes are done, now scan each port's disk(s) */
6100 DPRINTK("host probe begin\n");
6101 for (i = 0; i < host->n_ports; i++) {
6102 struct ata_port *ap = host->ports[i];
6103
6104 ata_scsi_scan_host(ap);
6105 }
6106 6159
6107 VPRINTK("EXIT, returning %u\n", ent->n_ports); 6160 VPRINTK("EXIT, returning %u\n", host->n_ports);
6108 return ent->n_ports; /* success */ 6161 return host->n_ports; /* success */
6109 6162
6110 err_out: 6163 err_out:
6111 devres_release_group(dev, ata_device_add); 6164 devres_release_group(dev, ata_device_add);
6112 VPRINTK("EXIT, returning %d\n", rc); 6165 VPRINTK("EXIT, returning 0\n");
6113 return 0; 6166 return 0;
6114} 6167}
6115 6168
@@ -6493,7 +6546,9 @@ EXPORT_SYMBOL_GPL(ata_dummy_port_ops);
6493EXPORT_SYMBOL_GPL(ata_std_bios_param); 6546EXPORT_SYMBOL_GPL(ata_std_bios_param);
6494EXPORT_SYMBOL_GPL(ata_std_ports); 6547EXPORT_SYMBOL_GPL(ata_std_ports);
6495EXPORT_SYMBOL_GPL(ata_host_init); 6548EXPORT_SYMBOL_GPL(ata_host_init);
6549EXPORT_SYMBOL_GPL(ata_host_alloc);
6496EXPORT_SYMBOL_GPL(ata_host_start); 6550EXPORT_SYMBOL_GPL(ata_host_start);
6551EXPORT_SYMBOL_GPL(ata_host_register);
6497EXPORT_SYMBOL_GPL(ata_device_add); 6552EXPORT_SYMBOL_GPL(ata_device_add);
6498EXPORT_SYMBOL_GPL(ata_host_detach); 6553EXPORT_SYMBOL_GPL(ata_host_detach);
6499EXPORT_SYMBOL_GPL(ata_sg_init); 6554EXPORT_SYMBOL_GPL(ata_sg_init);
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 563ef0bfb038..9afba2ba489e 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -104,7 +104,7 @@ static const u8 def_control_mpage[CONTROL_MPAGE_LEN] = {
104 * libata transport template. libata doesn't do real transport stuff. 104 * libata transport template. libata doesn't do real transport stuff.
105 * It just needs the eh_timed_out hook. 105 * It just needs the eh_timed_out hook.
106 */ 106 */
107struct scsi_transport_template ata_scsi_transport_template = { 107static struct scsi_transport_template ata_scsi_transport_template = {
108 .eh_strategy_handler = ata_scsi_error, 108 .eh_strategy_handler = ata_scsi_error,
109 .eh_timed_out = ata_scsi_timed_out, 109 .eh_timed_out = ata_scsi_timed_out,
110 .user_scan = ata_scsi_user_scan, 110 .user_scan = ata_scsi_user_scan,
@@ -2961,6 +2961,48 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
2961 } 2961 }
2962} 2962}
2963 2963
2964int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht)
2965{
2966 int i, rc;
2967
2968 for (i = 0; i < host->n_ports; i++) {
2969 struct ata_port *ap = host->ports[i];
2970 struct Scsi_Host *shost;
2971
2972 rc = -ENOMEM;
2973 shost = scsi_host_alloc(sht, sizeof(struct ata_port *));
2974 if (!shost)
2975 goto err_alloc;
2976
2977 *(struct ata_port **)&shost->hostdata[0] = ap;
2978 ap->scsi_host = shost;
2979
2980 shost->transportt = &ata_scsi_transport_template;
2981 shost->unique_id = ap->print_id;
2982 shost->max_id = 16;
2983 shost->max_lun = 1;
2984 shost->max_channel = 1;
2985 shost->max_cmd_len = 16;
2986
2987 rc = scsi_add_host(ap->scsi_host, ap->host->dev);
2988 if (rc)
2989 goto err_add;
2990 }
2991
2992 return 0;
2993
2994 err_add:
2995 scsi_host_put(host->ports[i]->scsi_host);
2996 err_alloc:
2997 while (--i >= 0) {
2998 struct Scsi_Host *shost = host->ports[i]->scsi_host;
2999
3000 scsi_remove_host(shost);
3001 scsi_host_put(shost);
3002 }
3003 return rc;
3004}
3005
2964void ata_scsi_scan_host(struct ata_port *ap) 3006void ata_scsi_scan_host(struct ata_port *ap)
2965{ 3007{
2966 unsigned int i; 3008 unsigned int i;
@@ -3237,21 +3279,21 @@ struct ata_port *ata_sas_port_alloc(struct ata_host *host,
3237 struct ata_port_info *port_info, 3279 struct ata_port_info *port_info,
3238 struct Scsi_Host *shost) 3280 struct Scsi_Host *shost)
3239{ 3281{
3240 struct ata_port *ap = kzalloc(sizeof(*ap), GFP_KERNEL); 3282 struct ata_port *ap;
3241 struct ata_probe_ent *ent;
3242 3283
3284 ap = ata_port_alloc(host);
3243 if (!ap) 3285 if (!ap)
3244 return NULL; 3286 return NULL;
3245 3287
3246 ent = ata_probe_ent_alloc(host->dev, port_info); 3288 ap->port_no = 0;
3247 if (!ent) {
3248 kfree(ap);
3249 return NULL;
3250 }
3251
3252 ata_port_init(ap, host, ent, 0);
3253 ap->lock = shost->host_lock; 3289 ap->lock = shost->host_lock;
3254 devm_kfree(host->dev, ent); 3290 ap->pio_mask = port_info->pio_mask;
3291 ap->mwdma_mask = port_info->mwdma_mask;
3292 ap->udma_mask = port_info->udma_mask;
3293 ap->flags |= port_info->flags;
3294 ap->ops = port_info->port_ops;
3295 ap->cbl = ATA_CBL_SATA;
3296
3255 return ap; 3297 return ap;
3256} 3298}
3257EXPORT_SYMBOL_GPL(ata_sas_port_alloc); 3299EXPORT_SYMBOL_GPL(ata_sas_port_alloc);
@@ -3307,8 +3349,10 @@ int ata_sas_port_init(struct ata_port *ap)
3307{ 3349{
3308 int rc = ap->ops->port_start(ap); 3350 int rc = ap->ops->port_start(ap);
3309 3351
3310 if (!rc) 3352 if (!rc) {
3353 ap->print_id = ata_print_id++;
3311 rc = ata_bus_probe(ap); 3354 rc = ata_bus_probe(ap);
3355 }
3312 3356
3313 return rc; 3357 return rc;
3314} 3358}
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 1f1e3a51f859..b4d5253d627a 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -52,6 +52,7 @@ enum {
52 ATA_DNXFER_QUIET = (1 << 31), 52 ATA_DNXFER_QUIET = (1 << 31),
53}; 53};
54 54
55extern unsigned int ata_print_id;
55extern struct workqueue_struct *ata_aux_wq; 56extern struct workqueue_struct *ata_aux_wq;
56extern int atapi_enabled; 57extern int atapi_enabled;
57extern int atapi_dmadir; 58extern int atapi_dmadir;
@@ -92,10 +93,9 @@ extern int ata_flush_cache(struct ata_device *dev);
92extern void ata_dev_init(struct ata_device *dev); 93extern void ata_dev_init(struct ata_device *dev);
93extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg); 94extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg);
94extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg); 95extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg);
95extern void ata_port_init(struct ata_port *ap, struct ata_host *host,
96 const struct ata_probe_ent *ent, unsigned int port_no);
97extern struct ata_probe_ent *ata_probe_ent_alloc(struct device *dev, 96extern struct ata_probe_ent *ata_probe_ent_alloc(struct device *dev,
98 const struct ata_port_info *port); 97 const struct ata_port_info *port);
98extern struct ata_port *ata_port_alloc(struct ata_host *host);
99 99
100/* libata-acpi.c */ 100/* libata-acpi.c */
101#ifdef CONFIG_SATA_ACPI 101#ifdef CONFIG_SATA_ACPI
@@ -113,8 +113,8 @@ static inline int ata_acpi_push_id(struct ata_port *ap, unsigned int ix)
113#endif 113#endif
114 114
115/* libata-scsi.c */ 115/* libata-scsi.c */
116extern struct scsi_transport_template ata_scsi_transport_template; 116extern int ata_scsi_add_hosts(struct ata_host *host,
117 117 struct scsi_host_template *sht);
118extern void ata_scsi_scan_host(struct ata_port *ap); 118extern void ata_scsi_scan_host(struct ata_port *ap);
119extern int ata_scsi_offline_dev(struct ata_device *dev); 119extern int ata_scsi_offline_dev(struct ata_device *dev);
120extern void ata_scsi_hotplug(struct work_struct *work); 120extern void ata_scsi_hotplug(struct work_struct *work);