Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1626aeb8 authored by Tejun Heo's avatar Tejun Heo Committed by Jeff Garzik
Browse files

libata: clean up SFF init mess



The intention of using port_mask in SFF init helpers was to eventually
support exoctic configurations such as combination of legacy and
native port on the same controller.  This never became actually
necessary and the related code always has been subtly broken one way
or the other.  Now that new init model is in place, there is no reason
to make common helpers capable of handling all corner cases.  Exotic
cases can simply dealt within LLDs as necessary.

This patch removes port_mask handling in SFF init helpers.  SFF init
helpers don't take n_ports argument and interpret it into port_mask
anymore.  All information is carried via port_info.  n_ports argument
is dropped and always two ports are allocated.  LLD can tell SFF to
skip certain port by marking it dummy.  Note that SFF code has been
treating unuvailable ports this way for a long time until recent
breakage fix from Linus and is consistent with how other drivers
handle with unavailable ports.

This fixes 1-port legacy host handling still broken after the recent
native mode fix and simplifies SFF init logic.  The following changes
are made...

* ata_pci_init_native_host() and ata_init_legacy_host() both now try
  to initialized whatever they can and mark failed ports dummy.  They
  return 0 if any port is successfully initialized.

* ata_pci_prepare_native_host() and ata_pci_init_one() now doesn't
  take n_ports argument.  All info should be specified via port_info
  array.  Always two ports are allocated.

* ata_pci_init_bmdma() exported to be used by LLDs in exotic cases.

* port_info handling in all LLDs are standardized - all port_info
  arrays are const stack variable named ppi.  Unless the second port
  is different from the first, its port_info is specified as NULL
  (tells libata that it's identical to the last non-NULL port_info).

* pata_hpt37x/hpt3x2n: don't modify static variable directly.  Make an
  on-stack copy instead as ata_piix does.

* pata_uli: It has 4 ports instead of 2.  Don't use
  ata_pci_prepare_native_host().  Allocate the host explicitly and use
  init helpers.  It's simple enough.

Signed-off-by: default avatarTejun Heo <htejun@gmail.com>
Signed-off-by: default avatarJeff Garzik <jeff@garzik.org>
parent 920a4b10
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ static int all_generic_ide; /* Set to claim all devices */
static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id *id)
{
	u16 command;
	static struct ata_port_info info = {
	static const struct ata_port_info info = {
		.sht = &generic_sht,
		.flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
		.pio_mask = 0x1f,
@@ -149,7 +149,7 @@ static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id
		.udma_mask = 0x3f,
		.port_ops = &generic_port_ops
	};
	static struct ata_port_info *port_info[2] = { &info, &info };
	const struct ata_port_info *ppi[] = { &info, NULL };

	/* Don't use the generic entry unless instructed to do so */
	if (id->driver_data == 1 && all_generic_ide == 0)
@@ -175,7 +175,7 @@ static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id
	if (dev->vendor == PCI_VENDOR_ID_AL)
	    	ata_pci_clear_simplex(dev);

	return ata_pci_init_one(dev, port_info, 2);
	return ata_pci_init_one(dev, ppi);
}

static struct pci_device_id ata_generic[] = {
+2 −2
Original line number Diff line number Diff line
@@ -1030,7 +1030,7 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
	static int printed_version;
	struct device *dev = &pdev->dev;
	struct ata_port_info port_info[2];
	struct ata_port_info *ppinfo[2] = { &port_info[0], &port_info[1] };
	const struct ata_port_info *ppi[] = { &port_info[0], &port_info[1] };
	struct piix_host_priv *hpriv;
	unsigned long port_flags;

@@ -1089,7 +1089,7 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
		port_info[1].mwdma_mask = 0;
		port_info[1].udma_mask = 0;
	}
	return ata_pci_init_one(pdev, ppinfo, 2);
	return ata_pci_init_one(pdev, ppi);
}

static int __init piix_init(void)
+1 −0
Original line number Diff line number Diff line
@@ -6856,6 +6856,7 @@ EXPORT_SYMBOL_GPL(ata_timing_merge);
#ifdef CONFIG_PCI
EXPORT_SYMBOL_GPL(pci_test_config_bits);
EXPORT_SYMBOL_GPL(ata_pci_init_native_host);
EXPORT_SYMBOL_GPL(ata_pci_init_bmdma);
EXPORT_SYMBOL_GPL(ata_pci_prepare_native_host);
EXPORT_SYMBOL_GPL(ata_pci_init_one);
EXPORT_SYMBOL_GPL(ata_pci_remove_one);
+83 −79
Original line number Diff line number Diff line
@@ -544,7 +544,7 @@ static int ata_resources_present(struct pci_dev *pdev, int port)
 *	RETURNS:
 *	0 on success, -errno otherwise.
 */
static int ata_pci_init_bmdma(struct ata_host *host)
int ata_pci_init_bmdma(struct ata_host *host)
{
	struct device *gdev = host->dev;
	struct pci_dev *pdev = to_pci_dev(gdev);
@@ -566,7 +566,7 @@ static int ata_pci_init_bmdma(struct ata_host *host)
	}
	host->iomap = pcim_iomap_table(pdev);

	for (i = 0; i < host->n_ports; i++) {
	for (i = 0; i < 2; i++) {
		struct ata_port *ap = host->ports[i];
		void __iomem *bmdma = host->iomap[4] + 8 * i;

@@ -585,54 +585,52 @@ static int ata_pci_init_bmdma(struct ata_host *host)
/**
 *	ata_pci_init_native_host - acquire native ATA resources and init host
 *	@host: target ATA host
 *	@port_mask: ports to consider
 *
 *	Acquire native PCI ATA resources for @host and initialize
 *	@host accordoingly.
 *	Acquire native PCI ATA resources for @host and initialize the
 *	first two ports of @host accordingly.  Ports marked dummy are
 *	skipped and allocation failure makes the port dummy.
 *
 *	LOCKING:
 *	Inherited from calling layer (may sleep).
 *
 *	RETURNS:
 *	0 on success, -errno otherwise.
 *	0 if at least one port is initialized, -ENODEV if no port is
 *	available.
 */
int ata_pci_init_native_host(struct ata_host *host, unsigned int port_mask)
int ata_pci_init_native_host(struct ata_host *host)
{
	struct device *gdev = host->dev;
	struct pci_dev *pdev = to_pci_dev(gdev);
	unsigned int mask = 0;
	int i, rc;

	/* Discard disabled ports.  Some controllers show their unused
	 * channels this way.  Disabled ports are made dummy.
	 */
	for (i = 0; i < 2; i++) {
		if ((port_mask & (1 << i)) && !ata_resources_present(pdev, i)) {
			host->ports[i]->ops = &ata_dummy_port_ops;
			port_mask &= ~(1 << i);
		}
	}

	if (!port_mask) {
		dev_printk(KERN_ERR, gdev, "no available port\n");
		return -ENODEV;
	}

	/* request, iomap BARs and init port addresses accordingly */
	for (i = 0; i < 2; i++) {
		struct ata_port *ap = host->ports[i];
		int base = i * 2;
		void __iomem * const *iomap;

		if (!(port_mask & (1 << i)))
		if (ata_port_is_dummy(ap))
			continue;

		/* Discard disabled ports.  Some controllers show
		 * their unused channels this way.  Disabled ports are
		 * made dummy.
		 */
		if (!ata_resources_present(pdev, i)) {
			ap->ops = &ata_dummy_port_ops;
			continue;
		}

		rc = pcim_iomap_regions(pdev, 0x3 << base, DRV_NAME);
		if (rc) {
			dev_printk(KERN_ERR, gdev, "failed to request/iomap "
				   "BARs for port %d (errno=%d)\n", i, rc);
			dev_printk(KERN_WARNING, gdev,
				   "failed to request/iomap BARs for port %d "
				   "(errno=%d)\n", i, rc);
			if (rc == -EBUSY)
				pcim_pin_device(pdev);
			return rc;
			ap->ops = &ata_dummy_port_ops;
			continue;
		}
		host->iomap = iomap = pcim_iomap_table(pdev);

@@ -641,6 +639,13 @@ int ata_pci_init_native_host(struct ata_host *host, unsigned int port_mask)
		ap->ioaddr.ctl_addr = (void __iomem *)
			((unsigned long)iomap[base + 1] | ATA_PCI_CTL_OFS);
		ata_std_ports(&ap->ioaddr);

		mask |= 1 << i;
	}

	if (!mask) {
		dev_printk(KERN_ERR, gdev, "no available native port\n");
		return -ENODEV;
	}

	return 0;
@@ -649,8 +654,7 @@ int ata_pci_init_native_host(struct ata_host *host, unsigned int port_mask)
/**
 *	ata_pci_prepare_native_host - helper to prepare native PCI ATA host
 *	@pdev: target PCI device
 *	@ppi: array of port_info
 *	@n_ports: number of ports to allocate
 *	@ppi: array of port_info, must be enough for two ports
 *	@r_host: out argument for the initialized ATA host
 *
 *	Helper to allocate ATA host for @pdev, acquire all native PCI
@@ -664,10 +668,9 @@ int ata_pci_init_native_host(struct ata_host *host, unsigned int port_mask)
 */
int ata_pci_prepare_native_host(struct pci_dev *pdev,
				const struct ata_port_info * const * ppi,
				int n_ports, struct ata_host **r_host)
				struct ata_host **r_host)
{
	struct ata_host *host;
	unsigned int port_mask;
	int rc;

	if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
@@ -681,11 +684,7 @@ int ata_pci_prepare_native_host(struct pci_dev *pdev,
		goto err_out;
	}

	port_mask = ATA_PORT_PRIMARY;
	if (n_ports > 1)
		port_mask |= ATA_PORT_SECONDARY;

	rc = ata_pci_init_native_host(host, port_mask);
	rc = ata_pci_init_native_host(host);
	if (rc)
		goto err_out;

@@ -777,8 +776,11 @@ static int ata_init_legacy_port(struct ata_port *ap,
	/* iomap cmd and ctl ports */
	legacy_dr->cmd_addr[port_no] = ioport_map(cmd_port, 8);
	legacy_dr->ctl_addr[port_no] = ioport_map(ctl_port, 1);
	if (!legacy_dr->cmd_addr[port_no] || !legacy_dr->ctl_addr[port_no])
	if (!legacy_dr->cmd_addr[port_no] || !legacy_dr->ctl_addr[port_no]) {
		dev_printk(KERN_WARNING, host->dev,
			   "failed to map cmd/ctl ports\n");
		return -ENOMEM;
	}

	/* init IO addresses */
	ap->ioaddr.cmd_addr = legacy_dr->cmd_addr[port_no];
@@ -792,19 +794,20 @@ static int ata_init_legacy_port(struct ata_port *ap,
/**
 *	ata_init_legacy_host - acquire legacy ATA resources and init ATA host
 *	@host: target ATA host
 *	@legacy_mask: out parameter, mask indicating ports is in legacy mode
 *	@was_busy: out parameter, indicates whether any port was busy
 *
 *	Acquire legacy ATA resources for ports.
 *	Acquire legacy ATA resources for the first two ports of @host
 *	and initialize it accordingly.  Ports marked dummy are skipped
 *	and resource acquistion failure makes the port dummy.
 *
 *	LOCKING:
 *	Inherited from calling layer (may sleep).
 *
 *	RETURNS:
 *	0 on success, -errno otherwise.
 *	0 if at least one port is initialized, -ENODEV if no port is
 *	available.
 */
static int ata_init_legacy_host(struct ata_host *host,
				unsigned int *legacy_mask, int *was_busy)
static int ata_init_legacy_host(struct ata_host *host, int *was_busy)
{
	struct device *gdev = host->dev;
	struct ata_legacy_devres *legacy_dr;
@@ -821,22 +824,23 @@ static int ata_init_legacy_host(struct ata_host *host,
	devres_add(gdev, legacy_dr);

	for (i = 0; i < 2; i++) {
		*legacy_mask &= ~(1 << i);
		if (ata_port_is_dummy(host->ports[i]))
			continue;

		rc = ata_init_legacy_port(host->ports[i], legacy_dr);
		if (rc == 0)
			legacy_dr->mask |= 1 << i;
		else if (rc == -EBUSY)
		else {
			if (rc == -EBUSY)
				(*was_busy)++;
	}

	if (!legacy_dr->mask)
		return -EBUSY;

	for (i = 0; i < 2; i++)
		if (!(legacy_dr->mask & (1 << i)))
			host->ports[i]->ops = &ata_dummy_port_ops;
		}
	}

	*legacy_mask |= legacy_dr->mask;
	if (!legacy_dr->mask) {
		dev_printk(KERN_ERR, gdev, "no available legacy port\n");
		return -ENODEV;
	}

	devres_remove_group(gdev, NULL);
	return 0;
@@ -875,7 +879,7 @@ static int ata_request_legacy_irqs(struct ata_host *host,
	legacy_dr = devres_find(host->dev, ata_legacy_release, NULL, NULL);
	BUG_ON(!legacy_dr);

	for (i = 0; i < host->n_ports; i++) {
	for (i = 0; i < 2; i++) {
		unsigned int irq;

		/* FIXME: ATA_*_IRQ() should take generic device not pci_dev */
@@ -923,8 +927,7 @@ static int ata_request_legacy_irqs(struct ata_host *host,
/**
 *	ata_pci_init_one - Initialize/register PCI IDE host controller
 *	@pdev: Controller to be initialized
 *	@port_info: Information from low-level host driver
 *	@n_ports: Number of ports attached to host controller
 *	@ppi: array of port_info, must be enough for two ports
 *
 *	This is a helper function which can be called from a driver's
 *	xxx_init_one() probe function if the hardware uses traditional
@@ -944,26 +947,34 @@ static int ata_request_legacy_irqs(struct ata_host *host,
 *	RETURNS:
 *	Zero on success, negative on errno-based value on error.
 */

int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
		      unsigned int n_ports)
int ata_pci_init_one(struct pci_dev *pdev,
		     const struct ata_port_info * const * ppi)
{
	struct device *dev = &pdev->dev;
	const struct ata_port_info *pi = NULL;
	struct ata_host *host = NULL;
	const struct ata_port_info *port[2];
	u8 mask;
	unsigned int legacy_mode = 0;
	int rc;
	int legacy_mode = 0;
	int i, rc;

	DPRINTK("ENTER\n");

	if (!devres_open_group(dev, NULL, GFP_KERNEL))
		return -ENOMEM;
	/* look up the first valid port_info */
	for (i = 0; i < 2 && ppi[i]; i++) {
		if (ppi[i]->port_ops != &ata_dummy_port_ops) {
			pi = ppi[i];
			break;
		}
	}

	BUG_ON(n_ports < 1 || n_ports > 2);
	if (!pi) {
		dev_printk(KERN_ERR, &pdev->dev,
			   "no valid port_info specified\n");
		return -EINVAL;
	}

	port[0] = port_info[0];
	port[1] = (n_ports > 1) ? port_info[1] : NULL;
	if (!devres_open_group(dev, NULL, GFP_KERNEL))
		return -ENOMEM;

	/* FIXME: Really for ATA it isn't safe because the device may be
	   multi-purpose and we want to leave it alone if it was already
@@ -984,7 +995,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
		pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8);
		mask = (1 << 2) | (1 << 0);
		if ((tmp8 & mask) != mask)
			legacy_mode = (1 << 3);
			legacy_mode = 1;
#if defined(CONFIG_NO_ATA_LEGACY)
		/* Some platforms with PCI limits cannot address compat
		   port space. In that case we punt if their firmware has
@@ -998,7 +1009,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
	}

	/* alloc and init host */
	host = ata_host_alloc_pinfo(dev, port, n_ports);
	host = ata_host_alloc_pinfo(dev, ppi, 2);
	if (!host) {
		dev_printk(KERN_ERR, &pdev->dev,
			   "failed to allocate ATA host\n");
@@ -1007,19 +1018,13 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
	}

	if (!legacy_mode) {
		unsigned int port_mask;

		port_mask = ATA_PORT_PRIMARY;
		if (n_ports > 1)
			port_mask |= ATA_PORT_SECONDARY;

		rc = ata_pci_init_native_host(host, port_mask);
		rc = ata_pci_init_native_host(host);
		if (rc)
			goto err_out;
	} else {
		int was_busy = 0;

		rc = ata_init_legacy_host(host, &legacy_mode, &was_busy);
		rc = ata_init_legacy_host(host, &was_busy);
		if (was_busy)
			pcim_pin_device(pdev);
		if (rc)
@@ -1040,8 +1045,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
		goto err_out;

	if (!legacy_mode)
		rc = devm_request_irq(dev, pdev->irq,
				      port_info[0]->port_ops->irq_handler,
		rc = devm_request_irq(dev, pdev->irq, pi->port_ops->irq_handler,
				      IRQF_SHARED, DRV_NAME, host);
	else {
		irq_handler_t handler[2] = { host->ops->irq_handler,
@@ -1055,7 +1059,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
		goto err_out;

	/* register */
	rc = ata_host_register(host, port_info[0]->sht);
	rc = ata_host_register(host, pi->sht);
	if (rc)
		goto err_out;

+16 −16
Original line number Diff line number Diff line
@@ -518,14 +518,14 @@ static void ali_init_chipset(struct pci_dev *pdev)

static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
{
	static struct ata_port_info info_early = {
	static const struct ata_port_info info_early = {
		.sht = &ali_sht,
		.flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
		.pio_mask = 0x1f,
		.port_ops = &ali_early_port_ops
	};
	/* Revision 0x20 added DMA */
	static struct ata_port_info info_20 = {
	static const struct ata_port_info info_20 = {
		.sht = &ali_sht,
		.flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
		.pio_mask = 0x1f,
@@ -533,7 +533,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
		.port_ops = &ali_20_port_ops
	};
	/* Revision 0x20 with support logic added UDMA */
	static struct ata_port_info info_20_udma = {
	static const struct ata_port_info info_20_udma = {
		.sht = &ali_sht,
		.flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
		.pio_mask = 0x1f,
@@ -542,7 +542,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
		.port_ops = &ali_20_port_ops
	};
	/* Revision 0xC2 adds UDMA66 */
	static struct ata_port_info info_c2 = {
	static const struct ata_port_info info_c2 = {
		.sht = &ali_sht,
		.flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
		.pio_mask = 0x1f,
@@ -551,7 +551,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
		.port_ops = &ali_c2_port_ops
	};
	/* Revision 0xC3 is UDMA100 */
	static struct ata_port_info info_c3 = {
	static const struct ata_port_info info_c3 = {
		.sht = &ali_sht,
		.flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
		.pio_mask = 0x1f,
@@ -560,7 +560,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
		.port_ops = &ali_c2_port_ops
	};
	/* Revision 0xC4 is UDMA133 */
	static struct ata_port_info info_c4 = {
	static const struct ata_port_info info_c4 = {
		.sht = &ali_sht,
		.flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
		.pio_mask = 0x1f,
@@ -569,7 +569,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
		.port_ops = &ali_c2_port_ops
	};
	/* Revision 0xC5 is UDMA133 with LBA48 DMA */
	static struct ata_port_info info_c5 = {
	static const struct ata_port_info info_c5 = {
		.sht = &ali_sht,
		.flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
		.pio_mask = 0x1f,
@@ -578,7 +578,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
		.port_ops = &ali_c5_port_ops
	};

	static struct ata_port_info *port_info[2];
	const struct ata_port_info *ppi[] = { NULL, NULL };
	u8 rev, tmp;
	struct pci_dev *isa_bridge;

@@ -590,17 +590,17 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
	 */

	if (rev < 0x20) {
		port_info[0] = port_info[1] = &info_early;
		ppi[0] = &info_early;
	} else if (rev < 0xC2) {
        	port_info[0] = port_info[1] = &info_20;
        	ppi[0] = &info_20;
	} else if (rev == 0xC2) {
        	port_info[0] = port_info[1] = &info_c2;
        	ppi[0] = &info_c2;
	} else if (rev == 0xC3) {
        	port_info[0] = port_info[1] = &info_c3;
        	ppi[0] = &info_c3;
	} else if (rev == 0xC4) {
        	port_info[0] = port_info[1] = &info_c4;
        	ppi[0] = &info_c4;
	} else
        	port_info[0] = port_info[1] = &info_c5;
        	ppi[0] = &info_c5;

	ali_init_chipset(pdev);

@@ -609,10 +609,10 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
		/* Are we paired with a UDMA capable chip */
		pci_read_config_byte(isa_bridge, 0x5E, &tmp);
		if ((tmp & 0x1E) == 0x12)
	        	port_info[0] = port_info[1] = &info_20_udma;
	        	ppi[0] = &info_20_udma;
		pci_dev_put(isa_bridge);
	}
	return ata_pci_init_one(pdev, port_info, 2);
	return ata_pci_init_one(pdev, ppi);
}

#ifdef CONFIG_PM
Loading