Skip to contentSkip to conversation

ahci: Add support for non-PCI devices

RFC PATCH In review Anton Vorontsov 4 participants 23 messages Mar 2, 2010 – Mar 3, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ahci: Add support for non-PCI devices

Hi all,

This patch set refactors AHCI code to make it more generic, plus adds a new platform driver to support AHCI interfaces integrated into System-On-Chip devices.

The patches should apply on top of v2.6.33 (soon will be rebased on top of linux-next).

I don't have any PCI AHCI handy (yet, but I plan to find one), so PCI AHCI was only compile-tested.

Thanks!

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#1 lore raw

PATCH 1/12 ahci: Fix some sparse warnings

Following warnings were fixed:

ahci.c:359:1: warning: symbol 'dev_attr_ahci_host_caps' was not declared. Should it be static? ahci.c:360:1: warning: symbol 'dev_attr_ahci_host_cap2' was not declared. Should it be static? ahci.c:361:1: warning: symbol 'dev_attr_ahci_host_version' was not declared. Should it be static? ahci.c:362:1: warning: symbol 'dev_attr_ahci_port_cmd' was not declared. Should it be static?

This was left over:

ahci.c:382:9: warning: Initializer entry defined twice
ahci.c:383:10: also defined here

---
 drivers/ata/ahci.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/ata/ahci.c +4 -4
index a6a736a..ef7949a 100644
@@ -356,10 +356,10 @@ static ssize_t ahci_show_host_version(struct device *dev,
 static ssize_t ahci_show_port_cmd(struct device *dev,
 				  struct device_attribute *attr, char *buf);
 
-DEVICE_ATTR(ahci_host_caps, S_IRUGO, ahci_show_host_caps, NULL);
-DEVICE_ATTR(ahci_host_cap2, S_IRUGO, ahci_show_host_cap2, NULL);
-DEVICE_ATTR(ahci_host_version, S_IRUGO, ahci_show_host_version, NULL);
-DEVICE_ATTR(ahci_port_cmd, S_IRUGO, ahci_show_port_cmd, NULL);
+static DEVICE_ATTR(ahci_host_caps, S_IRUGO, ahci_show_host_caps, NULL);
+static DEVICE_ATTR(ahci_host_cap2, S_IRUGO, ahci_show_host_cap2, NULL);
+static DEVICE_ATTR(ahci_host_version, S_IRUGO, ahci_show_host_version, NULL);
+static DEVICE_ATTR(ahci_port_cmd, S_IRUGO, ahci_show_port_cmd, NULL);
 
 static struct device_attribute *ahci_shost_attrs[] = {
 	&dev_attr_link_power_management_policy,
Signature · 1 line
1.7.0
#2 lore raw

PATCH 2/12 ahci: Get rid of host->iomap usage

In reply to Anton Vorontsov

Currently the driver uses host->iomap to store all the iomapped BARs of a PCI device (while AHCI devices actually use just a single memory window).

We're going to teach AHCI to work with non-PCI buses, so there are two options to make this work:

1. "fake" host->iomap array for non-PCI devices, and place the needed address at iomap[AHCI_PCI_BAR];
2. Get rid of host->iomap usage, instead introduce a private mmio field.

This patch implements the second option.

---
 drivers/ata/ahci.c |   34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)
drivers/ata/ahci.c +20 -14
index ef7949a..4f00aea 100644
@@ -281,6 +281,7 @@ struct ahci_em_priv {
 };
 
 struct ahci_host_priv {
+	void __iomem *		mmio;		/* bus-independant mem map */
 	unsigned int		flags;		/* AHCI_HFLAG_* */
 	u32			cap;		/* cap to use */
 	u32			cap2;		/* cap2 to use */
@@ -719,7 +720,8 @@ static inline int ahci_nr_ports(u32 cap)
 static inline void __iomem *__ahci_port_base(struct ata_host *host,
 					     unsigned int port_no)
 {
-	void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
+	struct ahci_host_priv *hpriv = host->private_data;
+	void __iomem *mmio = hpriv->mmio;
 
 	return mmio + 0x100 + (port_no * 0x80);
 }
@@ -779,7 +781,8 @@ static ssize_t ahci_show_host_version(struct device *dev,
 {
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct ata_port *ap = ata_shost_to_port(shost);
-	void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
+	struct ahci_host_priv *hpriv = ap->host->private_data;
+	void __iomem *mmio = hpriv->mmio;
 
 	return sprintf(buf, "%x\n", readl(mmio + HOST_VERSION));
 }
@@ -812,7 +815,7 @@ static ssize_t ahci_show_port_cmd(struct device *dev,
 static void ahci_save_initial_config(struct pci_dev *pdev,
 				     struct ahci_host_priv *hpriv)
 {
-	void __iomem *mmio = pcim_iomap_table(pdev)[AHCI_PCI_BAR];
+	void __iomem *mmio = hpriv->mmio;
 	u32 cap, cap2, vers, port_map;
 	int i;
 	int mv;
@@ -941,7 +944,7 @@ static void ahci_save_initial_config(struct pci_dev *pdev,
 static void ahci_restore_initial_config(struct ata_host *host)
 {
 	struct ahci_host_priv *hpriv = host->private_data;
-	void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
+	void __iomem *mmio = hpriv->mmio;
 
 	writel(hpriv->saved_cap, mmio + HOST_CAP);
 	if (hpriv->saved_cap2)
@@ -1300,7 +1303,7 @@ static int ahci_reset_controller(struct ata_host *host)
 {
 	struct pci_dev *pdev = to_pci_dev(host->dev);
 	struct ahci_host_priv *hpriv = host->private_data;
-	void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
+	void __iomem *mmio = hpriv->mmio;
 	u32 tmp;
 
 	/* we must be in AHCI mode, before using anything
@@ -1431,7 +1434,8 @@ static void ahci_init_sw_activity(struct ata_link *link)
 
 static int ahci_reset_em(struct ata_host *host)
 {
-	void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
+	struct ahci_host_priv *hpriv = host->private_data;
+	void __iomem *mmio = hpriv->mmio;
 	u32 em_ctl;
 
 	em_ctl = readl(mmio + HOST_EM_CTL);
@@ -1447,7 +1451,7 @@ static ssize_t ahci_transmit_led_message(struct ata_port *ap, u32 state,
 {
 	struct ahci_host_priv *hpriv = ap->host->private_data;
 	struct ahci_port_priv *pp = ap->private_data;
-	void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
+	void __iomem *mmio = hpriv->mmio;
 	u32 em_ctl;
 	u32 message[] = {0, 0};
 	unsigned long flags;
@@ -1615,7 +1619,7 @@ static void ahci_init_controller(struct ata_host *host)
 {
 	struct ahci_host_priv *hpriv = host->private_data;
 	struct pci_dev *pdev = to_pci_dev(host->dev);
-	void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
+	void __iomem *mmio = hpriv->mmio;
 	int i;
 	void __iomem *port_mmio;
 	u32 tmp;
@@ -2258,7 +2262,7 @@ static irqreturn_t ahci_interrupt(int irq, void *dev_instance)
 	VPRINTK("ENTER\n");
 
 	hpriv = host->private_data;
-	mmio = host->iomap[AHCI_PCI_BAR];
+	mmio = hpriv->mmio;
 
 	/* sigh.  0xffffffff is a valid return from h/w */
 	irq_stat = readl(mmio + HOST_IRQ_STAT);
@@ -2347,7 +2351,8 @@ static void ahci_freeze(struct ata_port *ap)
 
 static void ahci_thaw(struct ata_port *ap)
 {
-	void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
+	struct ahci_host_priv *hpriv = ap->host->private_data;
+	void __iomem *mmio = hpriv->mmio;
 	void __iomem *port_mmio = ahci_port_base(ap);
 	u32 tmp;
 	struct ahci_port_priv *pp = ap->private_data;
@@ -2443,7 +2448,7 @@ static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
 {
 	struct ata_host *host = dev_get_drvdata(&pdev->dev);
 	struct ahci_host_priv *hpriv = host->private_data;
-	void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
+	void __iomem *mmio = hpriv->mmio;
 	u32 ctl;
 
 	if (mesg.event & PM_EVENT_SUSPEND &&
@@ -2592,7 +2597,7 @@ static void ahci_print_info(struct ata_host *host)
 {
 	struct ahci_host_priv *hpriv = host->private_data;
 	struct pci_dev *pdev = to_pci_dev(host->dev);
-	void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
+	void __iomem *mmio = hpriv->mmio;
 	u32 vers, cap, cap2, impl, speed;
 	const char *speed_s;
 	u16 cc;
@@ -3078,6 +3083,8 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if ((hpriv->flags & AHCI_HFLAG_NO_MSI) || pci_enable_msi(pdev))
 		pci_intx(pdev, 1);
 
+	hpriv->mmio = pcim_iomap_table(pdev)[AHCI_PCI_BAR];
+
 	/* save initial config */
 	ahci_save_initial_config(pdev, hpriv);
 
@@ -3098,7 +3105,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	if (ahci_em_messages && (hpriv->cap & HOST_CAP_EMS)) {
 		u8 messages;
-		void __iomem *mmio = pcim_iomap_table(pdev)[AHCI_PCI_BAR];
+		void __iomem *mmio = hpriv->mmio;
 		u32 em_loc = readl(mmio + HOST_EM_LOC);
 		u32 em_ctl = readl(mmio + HOST_EM_CTL);
 
@@ -3142,7 +3149,6 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
 	if (!host)
 		return -ENOMEM;
-	host->iomap = pcim_iomap_table(pdev);
 	host->private_data = hpriv;
 
 	if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
Signature · 1 line
1.7.0
#3 lore raw

PATCH 3/12 ahci: Factor out PCI specifics from ahci_save_initial_config()

In reply to Anton Vorontsov

Make ahci_save_initial_config() a bit more generic by introducing force_port_map and mask_port_map arguments.

Move PCI stuff into ahci_pci_save_initial_config().

---
 drivers/ata/ahci.c |   66 +++++++++++++++++++++++++++++++++-------------------
 1 files changed, 42 insertions(+), 24 deletions(-)
drivers/ata/ahci.c +42 -24
index 4f00aea..aba800d 100644
@@ -801,6 +801,8 @@ static ssize_t ahci_show_port_cmd(struct device *dev,
  *	ahci_save_initial_config - Save and fixup initial config values
  *	@pdev: target PCI device
  *	@hpriv: host private area to store config values
+ *	@force_port_map: force port map to a specified value
+ *	@mask_port_map: mask out particular bits from port map
  *
  *	Some registers containing configuration info might be setup by
  *	BIOS and might be cleared on reset.  This function saves the
@@ -813,12 +815,13 @@ static ssize_t ahci_show_port_cmd(struct device *dev,
  *	None.
  */
 static void ahci_save_initial_config(struct pci_dev *pdev,
-				     struct ahci_host_priv *hpriv)
+				     struct ahci_host_priv *hpriv,
+				     unsigned int force_port_map,
+				     unsigned int mask_port_map)
 {
 	void __iomem *mmio = hpriv->mmio;
 	u32 cap, cap2, vers, port_map;
 	int i;
-	int mv;
 
 	/* make sure AHCI mode is enabled before accessing CAP */
 	ahci_enable_ahci(mmio);
@@ -868,32 +871,19 @@ static void ahci_save_initial_config(struct pci_dev *pdev,
 		cap &= ~HOST_CAP_SNTF;
 	}
 
-	if (pdev->vendor == PCI_VENDOR_ID_JMICRON && pdev->device == 0x2361 &&
-	    port_map != 1) {
+	if (force_port_map && port_map != force_port_map) {
 		dev_printk(KERN_INFO, &pdev->dev,
-			   "JMB361 has only one port, port_map 0x%x -> 0x%x\n",
-			   port_map, 1);
-		port_map = 1;
+			   "forcing port_map 0x%x -> 0x%x\n",
+			   port_map, force_port_map);
+		port_map = force_port_map;
 	}
 
-	/*
-	 * Temporary Marvell 6145 hack: PATA port presence
-	 * is asserted through the standard AHCI port
-	 * presence register, as bit 4 (counting from 0)
-	 */
-	if (hpriv->flags & AHCI_HFLAG_MV_PATA) {
-		if (pdev->device == 0x6121)
-			mv = 0x3;
-		else
-			mv = 0xf;
+	if (mask_port_map) {
 		dev_printk(KERN_ERR, &pdev->dev,
-			   "MV_AHCI HACK: port_map %x -> %x\n",
+			   "masking port_map 0x%x -> 0x%x\n",
 			   port_map,
-			   port_map & mv);
-		dev_printk(KERN_ERR, &pdev->dev,
-			  "Disabling your PATA port. Use the boot option 'ahci.marvell_enable=0' to avoid this.\n");
-
-		port_map &= mv;
+			   port_map & mask_port_map);
+		port_map &= mask_port_map;
 	}
 
 	/* cross check port_map and cap.n_ports */
@@ -932,6 +922,34 @@ static void ahci_save_initial_config(struct pci_dev *pdev,
 	hpriv->port_map = port_map;
 }
 
+static void ahci_pci_save_initial_config(struct pci_dev *pdev,
+					 struct ahci_host_priv *hpriv)
+{
+	unsigned int force_port_map = 0;
+	unsigned int mask_port_map = 0;
+
+	if (pdev->vendor == PCI_VENDOR_ID_JMICRON && pdev->device == 0x2361) {
+		dev_info(&pdev->dev, "JMB361 has only one port\n");
+		force_port_map = 1;
+	}
+
+	/*
+	 * Temporary Marvell 6145 hack: PATA port presence
+	 * is asserted through the standard AHCI port
+	 * presence register, as bit 4 (counting from 0)
+	 */
+	if (hpriv->flags & AHCI_HFLAG_MV_PATA) {
+		if (pdev->device == 0x6121)
+			mask_port_map = 0x3;
+		else
+			mask_port_map = 0xf;
+		dev_info(&pdev->dev,
+			  "Disabling your PATA port. Use the boot option 'ahci.marvell_enable=0' to avoid this.\n");
+	}
+
+	ahci_save_initial_config(pdev, hpriv, force_port_map, mask_port_map);
+}
+
 /**
  *	ahci_restore_initial_config - Restore initial config
  *	@host: target ATA host
@@ -3086,7 +3104,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	hpriv->mmio = pcim_iomap_table(pdev)[AHCI_PCI_BAR];
 
 	/* save initial config */
-	ahci_save_initial_config(pdev, hpriv);
+	ahci_pci_save_initial_config(pdev, hpriv);
 
 	/* prepare host */
 	if (hpriv->cap & HOST_CAP_NCQ) {
Signature · 1 line
1.7.0
#4 lore raw

PATCH 4/12 ahci: Get rid of pci_dev argument in ahci_save_initial_config()

In reply to Anton Vorontsov

To make the function generic we have to get rid of "struct pci_dev *", so let's pass just a "struct devce *".

---
 drivers/ata/ahci.c |   27 +++++++++++++--------------
 1 files changed, 13 insertions(+), 14 deletions(-)
drivers/ata/ahci.c +13 -14
index aba800d..acfdcb5 100644
@@ -799,7 +799,7 @@ static ssize_t ahci_show_port_cmd(struct device *dev,
 
 /**
  *	ahci_save_initial_config - Save and fixup initial config values
- *	@pdev: target PCI device
+ *	@dev: target AHCI device
  *	@hpriv: host private area to store config values
  *	@force_port_map: force port map to a specified value
  *	@mask_port_map: mask out particular bits from port map
@@ -814,7 +814,7 @@ static ssize_t ahci_show_port_cmd(struct device *dev,
  *	LOCKING:
  *	None.
  */
-static void ahci_save_initial_config(struct pci_dev *pdev,
+static void ahci_save_initial_config(struct device *dev,
 				     struct ahci_host_priv *hpriv,
 				     unsigned int force_port_map,
 				     unsigned int mask_port_map)
@@ -842,45 +842,43 @@ static void ahci_save_initial_config(struct pci_dev *pdev,
 
 	/* some chips have errata preventing 64bit use */
 	if ((cap & HOST_CAP_64) && (hpriv->flags & AHCI_HFLAG_32BIT_ONLY)) {
-		dev_printk(KERN_INFO, &pdev->dev,
+		dev_printk(KERN_INFO, dev,
 			   "controller can't do 64bit DMA, forcing 32bit\n");
 		cap &= ~HOST_CAP_64;
 	}
 
 	if ((cap & HOST_CAP_NCQ) && (hpriv->flags & AHCI_HFLAG_NO_NCQ)) {
-		dev_printk(KERN_INFO, &pdev->dev,
+		dev_printk(KERN_INFO, dev,
 			   "controller can't do NCQ, turning off CAP_NCQ\n");
 		cap &= ~HOST_CAP_NCQ;
 	}
 
 	if (!(cap & HOST_CAP_NCQ) && (hpriv->flags & AHCI_HFLAG_YES_NCQ)) {
-		dev_printk(KERN_INFO, &pdev->dev,
+		dev_printk(KERN_INFO, dev,
 			   "controller can do NCQ, turning on CAP_NCQ\n");
 		cap |= HOST_CAP_NCQ;
 	}
 
 	if ((cap & HOST_CAP_PMP) && (hpriv->flags & AHCI_HFLAG_NO_PMP)) {
-		dev_printk(KERN_INFO, &pdev->dev,
+		dev_printk(KERN_INFO, dev,
 			   "controller can't do PMP, turning off CAP_PMP\n");
 		cap &= ~HOST_CAP_PMP;
 	}
 
 	if ((cap & HOST_CAP_SNTF) && (hpriv->flags & AHCI_HFLAG_NO_SNTF)) {
-		dev_printk(KERN_INFO, &pdev->dev,
+		dev_printk(KERN_INFO, dev,
 			   "controller can't do SNTF, turning off CAP_SNTF\n");
 		cap &= ~HOST_CAP_SNTF;
 	}
 
 	if (force_port_map && port_map != force_port_map) {
-		dev_printk(KERN_INFO, &pdev->dev,
-			   "forcing port_map 0x%x -> 0x%x\n",
+		dev_printk(KERN_INFO, dev, "forcing port_map 0x%x -> 0x%x\n",
 			   port_map, force_port_map);
 		port_map = force_port_map;
 	}
 
 	if (mask_port_map) {
-		dev_printk(KERN_ERR, &pdev->dev,
-			   "masking port_map 0x%x -> 0x%x\n",
+		dev_printk(KERN_ERR, dev, "masking port_map 0x%x -> 0x%x\n",
 			   port_map,
 			   port_map & mask_port_map);
 		port_map &= mask_port_map;
@@ -898,7 +896,7 @@ static void ahci_save_initial_config(struct pci_dev *pdev,
 		 * port_map and let it be generated from n_ports.
 		 */
 		if (map_ports > ahci_nr_ports(cap)) {
-			dev_printk(KERN_WARNING, &pdev->dev,
+			dev_printk(KERN_WARNING, dev,
 				   "implemented port map (0x%x) contains more "
 				   "ports than nr_ports (%u), using nr_ports\n",
 				   port_map, ahci_nr_ports(cap));
@@ -909,7 +907,7 @@ static void ahci_save_initial_config(struct pci_dev *pdev,
 	/* fabricate port_map from cap.nr_ports */
 	if (!port_map) {
 		port_map = (1 << ahci_nr_ports(cap)) - 1;
-		dev_printk(KERN_WARNING, &pdev->dev,
+		dev_printk(KERN_WARNING, dev,
 			   "forcing PORTS_IMPL to 0x%x\n", port_map);
 
 		/* write the fixed up value to the PI register */
@@ -947,7 +945,8 @@ static void ahci_pci_save_initial_config(struct pci_dev *pdev,
 			  "Disabling your PATA port. Use the boot option 'ahci.marvell_enable=0' to avoid this.\n");
 	}
 
-	ahci_save_initial_config(pdev, hpriv, force_port_map, mask_port_map);
+	ahci_save_initial_config(&pdev->dev, hpriv, force_port_map,
+				 mask_port_map);
 }
 
 /**
Signature · 1 line
1.7.0
#5 lore raw

PATCH 5/12 ahci: Factor out PCI specifics from ahci_reset_controller()

In reply to Anton Vorontsov

Move PCI stuff into ahci_pci_reset_controller().

---
 drivers/ata/ahci.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
drivers/ata/ahci.c +12 -3
index acfdcb5..c46a064 100644
@@ -1318,7 +1318,6 @@ static int ahci_deinit_port(struct ata_port *ap, const char **emsg)
 
 static int ahci_reset_controller(struct ata_host *host)
 {
-	struct pci_dev *pdev = to_pci_dev(host->dev);
 	struct ahci_host_priv *hpriv = host->private_data;
 	void __iomem *mmio = hpriv->mmio;
 	u32 tmp;
@@ -1362,7 +1361,17 @@ static int ahci_reset_controller(struct ata_host *host)
 		dev_printk(KERN_INFO, host->dev,
 			   "skipping global host reset\n");
 
+	return 0;
+}
+
+static int ahci_pci_reset_controller(struct ata_host *host)
+{
+	struct pci_dev *pdev = to_pci_dev(host->dev);
+
+	ahci_reset_controller(host);
+
 	if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
+		struct ahci_host_priv *hpriv = host->private_data;
 		u16 tmp16;
 
 		/* configure PCS */
@@ -2499,7 +2508,7 @@ static int ahci_pci_device_resume(struct pci_dev *pdev)
 		return rc;
 
 	if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
-		rc = ahci_reset_controller(host);
+		rc = ahci_pci_reset_controller(host);
 		if (rc)
 			return rc;
 
@@ -3207,7 +3216,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (rc)
 		return rc;
 
-	rc = ahci_reset_controller(host);
+	rc = ahci_pci_reset_controller(host);
 	if (rc)
 		return rc;
 
Signature · 1 line
1.7.0
#6 lore raw

PATCH 6/12 ahci: Get rid of pci_dev argument in ahci_port_init()

In reply to Anton Vorontsov

To make the function bus-independand we have to get rid of "struct pci_dev *", so let's pass just "struct devce *".

---
 drivers/ata/ahci.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
drivers/ata/ahci.c +3 -4
index c46a064..1afb35e 100644
@@ -1613,7 +1613,7 @@ static ssize_t ahci_activity_show(struct ata_device *dev, char *buf)
 	return sprintf(buf, "%d\n", emp->blink_policy);
 }
 
-static void ahci_port_init(struct pci_dev *pdev, struct ata_port *ap,
+static void ahci_port_init(struct device *dev, struct ata_port *ap,
 			   int port_no, void __iomem *mmio,
 			   void __iomem *port_mmio)
 {
@@ -1624,8 +1624,7 @@ static void ahci_port_init(struct pci_dev *pdev, struct ata_port *ap,
 	/* make sure port is not active */
 	rc = ahci_deinit_port(ap, &emsg);
 	if (rc)
-		dev_printk(KERN_WARNING, &pdev->dev,
-			   "%s (%d)\n", emsg, rc);
+		dev_warn(dev, "%s (%d)\n", emsg, rc);
 
 	/* clear SError */
 	tmp = readl(port_mmio + PORT_SCR_ERR);
@@ -1674,7 +1673,7 @@ static void ahci_init_controller(struct ata_host *host)
 		if (ata_port_is_dummy(ap))
 			continue;
 
-		ahci_port_init(pdev, ap, i, mmio, port_mmio);
+		ahci_port_init(host->dev, ap, i, mmio, port_mmio);
 	}
 
 	tmp = readl(mmio + HOST_CTL);
Signature · 1 line
1.7.0
#7 lore raw

PATCH 7/12 ahci: Factor out PCI specifics from ahci_init_controller()

In reply to Anton Vorontsov

Move PCI stuff into ahci_pci_init_controller().

---
 drivers/ata/ahci.c |   45 +++++++++++++++++++++++++++------------------
 1 files changed, 27 insertions(+), 18 deletions(-)
drivers/ata/ahci.c +27 -18
index 1afb35e..aaeac15 100644
@@ -1643,11 +1643,34 @@ static void ahci_port_init(struct device *dev, struct ata_port *ap,
 static void ahci_init_controller(struct ata_host *host)
 {
 	struct ahci_host_priv *hpriv = host->private_data;
-	struct pci_dev *pdev = to_pci_dev(host->dev);
 	void __iomem *mmio = hpriv->mmio;
 	int i;
 	void __iomem *port_mmio;
 	u32 tmp;
+
+	for (i = 0; i < host->n_ports; i++) {
+		struct ata_port *ap = host->ports[i];
+
+		port_mmio = ahci_port_base(ap);
+		if (ata_port_is_dummy(ap))
+			continue;
+
+		ahci_port_init(host->dev, ap, i, mmio, port_mmio);
+	}
+
+	tmp = readl(mmio + HOST_CTL);
+	VPRINTK("HOST_CTL 0x%x\n", tmp);
+	writel(tmp | HOST_IRQ_EN, mmio + HOST_CTL);
+	tmp = readl(mmio + HOST_CTL);
+	VPRINTK("HOST_CTL 0x%x\n", tmp);
+}
+
+static void ahci_pci_init_controller(struct ata_host *host)
+{
+	struct ahci_host_priv *hpriv = host->private_data;
+	struct pci_dev *pdev = to_pci_dev(host->dev);
+	void __iomem *port_mmio;
+	u32 tmp;
 	int mv;
 
 	if (hpriv->flags & AHCI_HFLAG_MV_PATA) {
@@ -1666,21 +1689,7 @@ static void ahci_init_controller(struct ata_host *host)
 			writel(tmp, port_mmio + PORT_IRQ_STAT);
 	}
 
-	for (i = 0; i < host->n_ports; i++) {
-		struct ata_port *ap = host->ports[i];
-
-		port_mmio = ahci_port_base(ap);
-		if (ata_port_is_dummy(ap))
-			continue;
-
-		ahci_port_init(host->dev, ap, i, mmio, port_mmio);
-	}
-
-	tmp = readl(mmio + HOST_CTL);
-	VPRINTK("HOST_CTL 0x%x\n", tmp);
-	writel(tmp | HOST_IRQ_EN, mmio + HOST_CTL);
-	tmp = readl(mmio + HOST_CTL);
-	VPRINTK("HOST_CTL 0x%x\n", tmp);
+	ahci_init_controller(host);
 }
 
 static void ahci_dev_config(struct ata_device *dev)
@@ -2511,7 +2520,7 @@ static int ahci_pci_device_resume(struct pci_dev *pdev)
 		if (rc)
 			return rc;
 
-		ahci_init_controller(host);
+		ahci_pci_init_controller(host);
 	}
 
 	ata_host_resume(host);
@@ -3219,7 +3228,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (rc)
 		return rc;
 
-	ahci_init_controller(host);
+	ahci_pci_init_controller(host);
 	ahci_print_info(host);
 
 	pci_set_master(pdev);
Signature · 1 line
1.7.0
#8 lore raw

PATCH 8/12 ahci: Factor out PCI specifics from ahci_print_info()

In reply to Anton Vorontsov

Introduce ahci_pci_print_info() that now handles PCI stuff.

---
 drivers/ata/ahci.c |   40 +++++++++++++++++++++++-----------------
 1 files changed, 23 insertions(+), 17 deletions(-)
drivers/ata/ahci.c +23 -17
index aaeac15..18443e9 100644
@@ -2627,15 +2627,12 @@ static int ahci_configure_dma_masks(struct pci_dev *pdev, int using_dac)
 	return 0;
 }
 
-static void ahci_print_info(struct ata_host *host)
+static void ahci_print_info(struct ata_host *host, const char *scc_s)
 {
 	struct ahci_host_priv *hpriv = host->private_data;
-	struct pci_dev *pdev = to_pci_dev(host->dev);
 	void __iomem *mmio = hpriv->mmio;
 	u32 vers, cap, cap2, impl, speed;
 	const char *speed_s;
-	u16 cc;
-	const char *scc_s;
 
 	vers = readl(mmio + HOST_VERSION);
 	cap = hpriv->cap;
@@ -2652,17 +2649,7 @@ static void ahci_print_info(struct ata_host *host)
 	else
 		speed_s = "?";
 
-	pci_read_config_word(pdev, 0x0a, &cc);
-	if (cc == PCI_CLASS_STORAGE_IDE)
-		scc_s = "IDE";
-	else if (cc == PCI_CLASS_STORAGE_SATA)
-		scc_s = "SATA";
-	else if (cc == PCI_CLASS_STORAGE_RAID)
-		scc_s = "RAID";
-	else
-		scc_s = "unknown";
-
-	dev_printk(KERN_INFO, &pdev->dev,
+	dev_info(host->dev,
 		"AHCI %02x%02x.%02x%02x "
 		"%u slots %u ports %s Gbps 0x%x impl %s mode\n"
 		,
@@ -2678,7 +2665,7 @@ static void ahci_print_info(struct ata_host *host)
 		impl,
 		scc_s);
 
-	dev_printk(KERN_INFO, &pdev->dev,
+	dev_info(host->dev,
 		"flags: "
 		"%s%s%s%s%s%s%s"
 		"%s%s%s%s%s%s%s"
@@ -2708,6 +2695,25 @@ static void ahci_print_info(struct ata_host *host)
 		);
 }
 
+static void ahci_pci_print_info(struct ata_host *host)
+{
+	struct pci_dev *pdev = to_pci_dev(host->dev);
+	u16 cc;
+	const char *scc_s;
+
+	pci_read_config_word(pdev, 0x0a, &cc);
+	if (cc == PCI_CLASS_STORAGE_IDE)
+		scc_s = "IDE";
+	else if (cc == PCI_CLASS_STORAGE_SATA)
+		scc_s = "SATA";
+	else if (cc == PCI_CLASS_STORAGE_RAID)
+		scc_s = "RAID";
+	else
+		scc_s = "unknown";
+
+	ahci_print_info(host, scc_s);
+}
+
 /* On ASUS P5W DH Deluxe, the second port of PCI device 00:1f.2 is
  * hardwired to on-board SIMG 4726.  The chipset is ICH8 and doesn't
  * support PMP and the 4726 either directly exports the device
@@ -3229,7 +3235,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		return rc;
 
 	ahci_pci_init_controller(host);
-	ahci_print_info(host);
+	ahci_pci_print_info(host);
 
 	pci_set_master(pdev);
 	return ata_host_activate(host, pdev->irq, ahci_interrupt, IRQF_SHARED,
Signature · 1 line
1.7.0
#9 lore raw

PATCH 9/12 ahci: Introduce ahci_set_em_messages()

In reply to Anton Vorontsov

Factor out some ahci_em_messages handling code from ahci_init_one(). We would like to reuse it for non-PCI devices.

---
 drivers/ata/ahci.c |   41 ++++++++++++++++++++++++-----------------
 1 files changed, 24 insertions(+), 17 deletions(-)
drivers/ata/ahci.c +24 -17
index 18443e9..6694b17 100644
@@ -3040,6 +3040,29 @@ static inline void ahci_gtf_filter_workaround(struct ata_host *host)
 {}
 #endif
 
+static void ahci_set_em_messages(struct ahci_host_priv *hpriv,
+				 struct ata_port_info *pi)
+{
+	u8 messages;
+	void __iomem *mmio = hpriv->mmio;
+	u32 em_loc = readl(mmio + HOST_EM_LOC);
+	u32 em_ctl = readl(mmio + HOST_EM_CTL);
+
+	if (!ahci_em_messages || !(hpriv->cap & HOST_CAP_EMS))
+		return;
+
+	messages = (em_ctl & EM_CTRL_MSG_TYPE) >> 16;
+
+	/* we only support LED message type right now */
+	if ((messages & 0x01) && (ahci_em_messages == 1)) {
+		/* store em_loc */
+		hpriv->em_loc = ((em_loc >> 16) * 4);
+		pi->flags |= ATA_FLAG_EM;
+		if (!(em_ctl & EM_CTL_ALHD))
+			pi->flags |= ATA_FLAG_SW_ACTIVITY;
+	}
+}
+
 static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	static int printed_version;
@@ -3143,23 +3166,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (hpriv->cap & HOST_CAP_PMP)
 		pi.flags |= ATA_FLAG_PMP;
 
-	if (ahci_em_messages && (hpriv->cap & HOST_CAP_EMS)) {
-		u8 messages;
-		void __iomem *mmio = hpriv->mmio;
-		u32 em_loc = readl(mmio + HOST_EM_LOC);
-		u32 em_ctl = readl(mmio + HOST_EM_CTL);
-
-		messages = (em_ctl & EM_CTRL_MSG_TYPE) >> 16;
-
-		/* we only support LED message type right now */
-		if ((messages & 0x01) && (ahci_em_messages == 1)) {
-			/* store em_loc */
-			hpriv->em_loc = ((em_loc >> 16) * 4);
-			pi.flags |= ATA_FLAG_EM;
-			if (!(em_ctl & EM_CTL_ALHD))
-				pi.flags |= ATA_FLAG_SW_ACTIVITY;
-		}
-	}
+	ahci_set_em_messages(hpriv, &pi);
 
 	if (ahci_broken_system_poweroff(pdev)) {
 		pi.flags |= ATA_FLAG_NO_POWEROFF_SPINDOWN;
Signature · 1 line
1.7.0
#10 lore raw

Re: [PATCH 09/12] ahci: Introduce ahci_set_em_messages()

Hello.

Quoted 24 lines · Anton Vorontsov

Factor out some ahci_em_messages handling code from ahci_init_one(). We would like to reuse it for non-PCI devices.

---
 drivers/ata/ahci.c |   41 ++++++++++++++++++++++++-----------------
 1 files changed, 24 insertions(+), 17 deletions(-)
drivers/ata/ahci.c +8 -0
index 18443e9..6694b17 100644
@@ -3040,6 +3040,29 @@ static inline void ahci_gtf_filter_workaround(struct ata_host *host)
 {}
 #endif
 
+static void ahci_set_em_messages(struct ahci_host_priv *hpriv,
+				 struct ata_port_info *pi)
+{
+	u8 messages;
+	void __iomem *mmio = hpriv->mmio;
+	u32 em_loc = readl(mmio + HOST_EM_LOC);
+	u32 em_ctl = readl(mmio + HOST_EM_CTL);
+

drivers/ata/ahci.c static inline void ahci_gtf_filter_workaround(struct ata_host *host) · line 3060

Quoted 10 lines
drivers/ata/ahci.c +9 -0
+	if (!ahci_em_messages || !(hpriv->cap & HOST_CAP_EMS))
+		return;
+
+	messages = (em_ctl & EM_CTRL_MSG_TYPE) >> 16;
+
+	/* we only support LED message type right now */
+	if ((messages & 0x01) && (ahci_em_messages == 1)) {
+		/* store em_loc */
+		hpriv->em_loc = ((em_loc >> 16) * 4);
 

Could drop unneeded parens, while at it...

MBR, Sergei

#11 lore raw

Re: [PATCH 09/12] ahci: Introduce ahci_set_em_messages()

Quoted 32 lines · Sergei Shtylyov

Hello.

Quoted 28 lines · Anton Vorontsov

Factor out some ahci_em_messages handling code from ahci_init_one(). We would like to reuse it for non-PCI devices.

---
drivers/ata/ahci.c | 41 ++++++++++++++++++++++++-----------------

1 files changed, 24 insertions(+), 17 deletions(-)
drivers/ata/ahci.c +11 -0
index 18443e9..6694b17 100644
@@ -3040,6 +3040,29 @@ static inline void
 ahci_gtf_filter_workaround(struct ata_host *host)
 {}
 #endif
 
+static void ahci_set_em_messages(struct ahci_host_priv *hpriv,
+ struct ata_port_info *pi)
+{
+ u8 messages;
+ void __iomem *mmio = hpriv->mmio;
+ u32 em_loc = readl(mmio + HOST_EM_LOC);
+ u32 em_ctl = readl(mmio + HOST_EM_CTL);
+
+ if (!ahci_em_messages || !(hpriv->cap & HOST_CAP_EMS))
+ return;
+
Quoted 8 lines

drivers/ata/ahci.c static inline void ahci_gtf_filter_workaround(struct ata_host *host) · line 3059

Quoted 6 lines
drivers/ata/ahci.c +6 -0
+ messages = (em_ctl & EM_CTRL_MSG_TYPE) >> 16;
+
+ /* we only support LED message type right now */
+ if ((messages & 0x01) && (ahci_em_messages == 1)) {
+ /* store em_loc */
+ hpriv->em_loc = ((em_loc >> 16) * 4);

Could drop unneeded parens, while at it...

While not strictly necessary, parens often help with readability. I think the above code looks fine as-is. If the reader has to waste a few seconds recalling C's operator precedence, that detracts from the easy reading of the code. Not everyone is like me and has worked on a C compiler, you know ;-)

Jeff

#12 lore raw

Re: [PATCH 09/12] ahci: Introduce ahci_set_em_messages()

Hello.

Quoted 37 lines · Jeff Garzik
Quoted 28 lines
Quoted 28 lines

Factor out some ahci_em_messages handling code from ahci_init_one(). We would like to reuse it for non-PCI devices.

---
drivers/ata/ahci.c | 41 ++++++++++++++++++++++++-----------------

1 files changed, 24 insertions(+), 17 deletions(-)
drivers/ata/ahci.c +11 -0
index 18443e9..6694b17 100644
@@ -3040,6 +3040,29 @@ static inline void
 ahci_gtf_filter_workaround(struct ata_host *host)
 {}
 #endif
 
+static void ahci_set_em_messages(struct ahci_host_priv *hpriv,
+ struct ata_port_info *pi)
+{
+ u8 messages;
+ void __iomem *mmio = hpriv->mmio;
+ u32 em_loc = readl(mmio + HOST_EM_LOC);
+ u32 em_ctl = readl(mmio + HOST_EM_CTL);
+
+ if (!ahci_em_messages || !(hpriv->cap & HOST_CAP_EMS))
+ return;
+
Quoted 8 lines

drivers/ata/ahci.c static inline void ahci_gtf_filter_workaround(struct ata_host *host) · line 3059

Quoted 6 lines
drivers/ata/ahci.c +6 -0
+ messages = (em_ctl & EM_CTRL_MSG_TYPE) >> 16;
+
+ /* we only support LED message type right now */
+ if ((messages & 0x01) && (ahci_em_messages == 1)) {
+ /* store em_loc */
+ hpriv->em_loc = ((em_loc >> 16) * 4);

Could drop unneeded parens, while at it...

Quoted 1 line

While not strictly necessary, parens often help with readability. I think the above code looks fine as-is. If the reader has to waste a few seconds recalling C's operator precedence, that detracts from the easy reading of the code. Not everyone is like me and has worked on a C compiler, you know ;-)

Come on, parens around the right arg of = are pretty
counter-intuitive and so don't add to the readability. :-)

Quoted 1 line

Jeff

MBR, Sergei

#13 lore raw

Re: [PATCH 09/12] ahci: Introduce ahci_set_em_messages()

Quoted 41 lines · Sergei Shtylyov

Hello.

Quoted 37 lines · Jeff Garzik
Quoted 36 lines
Quoted 24 lines

Factor out some ahci_em_messages handling code from ahci_init_one(). We would like to reuse it for non-PCI devices.

---
drivers/ata/ahci.c | 41 ++++++++++++++++++++++++-----------------

1 files changed, 24 insertions(+), 17 deletions(-)
drivers/ata/ahci.c +7 -0
index 18443e9..6694b17 100644
@@ -3040,6 +3040,29 @@ static inline void
 ahci_gtf_filter_workaround(struct ata_host *host)
 {}
 #endif
 
+static void ahci_set_em_messages(struct ahci_host_priv *hpriv,
+ struct ata_port_info *pi)
+{
+ u8 messages;
+ void __iomem *mmio = hpriv->mmio;
+ u32 em_loc = readl(mmio + HOST_EM_LOC);
+ u32 em_ctl = readl(mmio + HOST_EM_CTL);

drivers/ata/ahci.c static inline void · line 3060

Quoted 10 lines
drivers/ata/ahci.c +10 -0
+
+ if (!ahci_em_messages || !(hpriv->cap & HOST_CAP_EMS))
+ return;
+
+ messages = (em_ctl & EM_CTRL_MSG_TYPE) >> 16;
+
+ /* we only support LED message type right now */
+ if ((messages & 0x01) && (ahci_em_messages == 1)) {
+ /* store em_loc */
+ hpriv->em_loc = ((em_loc >> 16) * 4);

Could drop unneeded parens, while at it...

Quoted 8 lines
Quoted 5 lines

While not strictly necessary, parens often help with readability. I think the above code looks fine as-is. If the reader has to waste a few seconds recalling C's operator precedence, that detracts from the easy reading of the code. Not everyone is like me and has worked on a C compiler, you know ;-)

Come on, parens around the right arg of = are pretty counter-intuitive and so don't add to the readability. :-)

<shrug> I respectfully disagree. It is wasteful but does not detract from readability at all, IMO.

Jeff

#14 lore raw

Re: [PATCH 09/12] ahci: Introduce ahci_set_em_messages()

Quoted 49 lines · Jeff Garzik
Quoted 48 lines · Sergei Shtylyov

Hello.

Quoted 42 lines · Jeff Garzik
Quoted 28 lines
Quoted 28 lines

Factor out some ahci_em_messages handling code from ahci_init_one(). We would like to reuse it for non-PCI devices.

---
drivers/ata/ahci.c | 41 ++++++++++++++++++++++++-----------------

1 files changed, 24 insertions(+), 17 deletions(-)
drivers/ata/ahci.c +11 -0
index 18443e9..6694b17 100644
@@ -3040,6 +3040,29 @@ static inline void
 ahci_gtf_filter_workaround(struct ata_host *host)
 {}
 #endif
 
+static void ahci_set_em_messages(struct ahci_host_priv *hpriv,
+ struct ata_port_info *pi)
+{
+ u8 messages;
+ void __iomem *mmio = hpriv->mmio;
+ u32 em_loc = readl(mmio + HOST_EM_LOC);
+ u32 em_ctl = readl(mmio + HOST_EM_CTL);
+
+ if (!ahci_em_messages || !(hpriv->cap & HOST_CAP_EMS))
+ return;
+
Quoted 8 lines

drivers/ata/ahci.c static inline void ahci_gtf_filter_workaround(struct ata_host *host) · line 3059

Quoted 6 lines
drivers/ata/ahci.c +6 -0
+ messages = (em_ctl & EM_CTRL_MSG_TYPE) >> 16;
+
+ /* we only support LED message type right now */
+ if ((messages & 0x01) && (ahci_em_messages == 1)) {
+ /* store em_loc */
+ hpriv->em_loc = ((em_loc >> 16) * 4);

Could drop unneeded parens, while at it...

While not strictly necessary, parens often help with readability. I think the above code looks fine as-is. If the reader has to waste a few seconds recalling C's operator precedence, that detracts from the easy reading of the code. Not everyone is like me and has worked on a C compiler, you know ;-)

Quoted 7 lines
Quoted 2 lines

Come on, parens around the right arg of = are pretty counter-intuitive and so don't add to the readability. :-)

<shrug>  I respectfully disagree.  It is wasteful but does not detract from readability at all, IMO.

       Jeff

Re: hpriv->em_loc = ((em_loc >> 16) * 4);

I think the way it is leaves the reader wondering what used to be there. ie. It makes me think there used to be a function call that was removed, but the parens left in place.

I agree with Sergei that it is a readability issue because it sends the readers brain off into tangents.

Greg

#15 lore raw

PATCH 10/12 ahci: Move PCI code into ahci_pci.c

In reply to Anton Vorontsov

This patch should contain no functional changes, just moves code around.

Currently ahci.c and ahci_pci.c are built into a single module, so there is no need for EXPORT_SYMBOL_GPL()s, yet. Exports will be added in a subsequent patch.

---
 drivers/ata/Kconfig    |    8 +-
 drivers/ata/Makefile   |    3 +-
 drivers/ata/ahci.c     | 1426 +-----------------------------------------------
 drivers/ata/ahci.h     |  277 ++++++++++
 drivers/ata/ahci_pci.c | 1175 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 1484 insertions(+), 1405 deletions(-)
 create mode 100644 drivers/ata/ahci.h
 create mode 100644 drivers/ata/ahci_pci.c
drivers/ata/Kconfig +7 -1
index b17c57f..4656782 100644
@@ -49,12 +49,18 @@ config SATA_PMP
 
 config SATA_AHCI
 	tristate "AHCI SATA support"
-	depends on PCI
 	help
 	  This option enables support for AHCI Serial ATA.
 
 	  If unsure, say N.
 
+config SATA_AHCI_PCI
+	tristate "PCI AHCI SATA support"
+	depends on SATA_AHCI && PCI
+	default y
+	help
+	  This option enables support for PCI AHCI Serial ATA controllers.
+
 config SATA_SIL24
 	tristate "Silicon Image 3124/3132 SATA support"
 	depends on PCI
drivers/ata/Makefile +2 -1
index b7d4923..0ab4c52 100644
@@ -1,7 +1,8 @@
 
 obj-$(CONFIG_ATA)		+= libata.o
 
-obj-$(CONFIG_SATA_AHCI)		+= ahci.o
+ahci-pci-objs			+= ahci.o ahci_pci.o
+obj-$(CONFIG_SATA_AHCI_PCI)	+= ahci-pci.o
 obj-$(CONFIG_SATA_SVW)		+= sata_svw.o
 obj-$(CONFIG_ATA_PIIX)		+= ata_piix.o
 obj-$(CONFIG_SATA_PROMISE)	+= sata_promise.o
drivers/ata/ahci.c +23 -1403

1,601 lines not on this page · raw message

drivers/ata/ahci.h new file +277 -0

277 lines not on this page · raw message

drivers/ata/ahci_pci.c new file +1175 -0

1,094 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.0

Part of the diff is not shown here. View the raw message.

#16 lore raw

PATCH 11/12 ahci: Export generic AHCI symbols

In reply to Anton Vorontsov

This is needed for non-PCI drivers that will be added soon.

Since the symbols are exported now, ahci and ahci_pci can be built as a separate modules.

---
 drivers/ata/Makefile |    4 ++--
 drivers/ata/ahci.c   |   20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)
drivers/ata/Makefile +2 -2
index 0ab4c52..a220e90 100644
@@ -1,8 +1,8 @@
 
 obj-$(CONFIG_ATA)		+= libata.o
 
-ahci-pci-objs			+= ahci.o ahci_pci.o
-obj-$(CONFIG_SATA_AHCI_PCI)	+= ahci-pci.o
+obj-$(CONFIG_SATA_AHCI)		+= ahci.o
+obj-$(CONFIG_SATA_AHCI_PCI)	+= ahci_pci.o
 obj-$(CONFIG_SATA_SVW)		+= sata_svw.o
 obj-$(CONFIG_ATA_PIIX)		+= ata_piix.o
 obj-$(CONFIG_SATA_PROMISE)	+= sata_promise.o
drivers/ata/ahci.c +20 -0
index ce08bc6..23e3060 100644
@@ -47,6 +47,7 @@
 
 static int ahci_skip_host_reset;
 int ahci_ignore_sss;
+EXPORT_SYMBOL_GPL(ahci_ignore_sss);
 
 module_param_named(skip_host_reset, ahci_skip_host_reset, int, 0444);
 MODULE_PARM_DESC(skip_host_reset, "skip global host reset (0=don't skip, 1=skip)");
@@ -134,6 +135,7 @@ struct scsi_host_template ahci_sht = {
 	.shost_attrs		= ahci_shost_attrs,
 	.sdev_attrs		= ahci_sdev_attrs,
 };
+EXPORT_SYMBOL_GPL(ahci_sht);
 
 struct ata_port_operations ahci_ops = {
 	.inherits		= &sata_pmp_port_ops,
@@ -171,8 +173,10 @@ struct ata_port_operations ahci_ops = {
 	.port_start		= ahci_port_start,
 	.port_stop		= ahci_port_stop,
 };
+EXPORT_SYMBOL_GPL(ahci_ops);
 
 int ahci_em_messages = 1;
+EXPORT_SYMBOL_GPL(ahci_em_messages);
 module_param(ahci_em_messages, int, 0444);
 /* add other LED protocol types when they become supported */
 MODULE_PARM_DESC(ahci_em_messages,
@@ -366,6 +370,7 @@ void ahci_save_initial_config(struct device *dev,
 	hpriv->cap2 = cap2;
 	hpriv->port_map = port_map;
 }
+EXPORT_SYMBOL_GPL(ahci_save_initial_config);
 
 /**
  *	ahci_restore_initial_config - Restore initial config
@@ -440,6 +445,7 @@ void ahci_start_engine(struct ata_port *ap)
 	writel(tmp, port_mmio + PORT_CMD);
 	readl(port_mmio + PORT_CMD); /* flush */
 }
+EXPORT_SYMBOL_GPL(ahci_start_engine);
 
 int ahci_stop_engine(struct ata_port *ap)
 {
@@ -464,6 +470,7 @@ int ahci_stop_engine(struct ata_port *ap)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(ahci_stop_engine);
 
 static void ahci_start_fis_rx(struct ata_port *ap)
 {
@@ -781,6 +788,7 @@ int ahci_reset_controller(struct ata_host *host)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(ahci_reset_controller);
 
 static void ahci_sw_activity(struct ata_link *link)
 {
@@ -868,6 +876,7 @@ int ahci_reset_em(struct ata_host *host)
 	writel(em_ctl | EM_CTL_RST, mmio + HOST_EM_CTL);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(ahci_reset_em);
 
 static ssize_t ahci_transmit_led_message(struct ata_port *ap, u32 state,
 					ssize_t size)
@@ -1061,6 +1070,7 @@ void ahci_init_controller(struct ata_host *host)
 	tmp = readl(mmio + HOST_CTL);
 	VPRINTK("HOST_CTL 0x%x\n", tmp);
 }
+EXPORT_SYMBOL_GPL(ahci_init_controller);
 
 static void ahci_dev_config(struct ata_device *dev)
 {
@@ -1144,6 +1154,7 @@ int ahci_kick_engine(struct ata_port *ap)
 	ahci_start_engine(ap);
 	return rc;
 }
+EXPORT_SYMBOL_GPL(ahci_kick_engine);
 
 static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
 				struct ata_taskfile *tf, int is_cmd, u16 flags,
@@ -1250,6 +1261,7 @@ int ahci_check_ready(struct ata_link *link)
 
 	return ata_check_ready(status);
 }
+EXPORT_SYMBOL_GPL(ahci_check_ready);
 
 static int ahci_softreset(struct ata_link *link, unsigned int *class,
 			  unsigned long deadline)
@@ -1260,6 +1272,7 @@ static int ahci_softreset(struct ata_link *link, unsigned int *class,
 
 	return ahci_do_softreset(link, class, pmp, deadline, ahci_check_ready);
 }
+EXPORT_SYMBOL_GPL(ahci_do_softreset);
 
 static int ahci_hardreset(struct ata_link *link, unsigned int *class,
 			  unsigned long deadline)
@@ -1597,6 +1610,7 @@ irqreturn_t ahci_interrupt(int irq, void *dev_instance)
 
 	return IRQ_RETVAL(handled);
 }
+EXPORT_SYMBOL_GPL(ahci_interrupt);
 
 static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc)
 {
@@ -1865,6 +1879,7 @@ void ahci_print_info(struct ata_host *host, const char *scc_s)
 		cap2 & HOST_CAP2_BOH ? "boh " : ""
 		);
 }
+EXPORT_SYMBOL_GPL(ahci_print_info);
 
 void ahci_set_em_messages(struct ahci_host_priv *hpriv,
 			  struct ata_port_info *pi)
@@ -1888,3 +1903,8 @@ void ahci_set_em_messages(struct ahci_host_priv *hpriv,
 			pi->flags |= ATA_FLAG_SW_ACTIVITY;
 	}
 }
+EXPORT_SYMBOL_GPL(ahci_set_em_messages);
+
+MODULE_AUTHOR("Jeff Garzik");
+MODULE_DESCRIPTION("AHCI SATA low-level routines");
+MODULE_LICENSE("GPL");
Signature · 1 line
1.7.0
#17 lore raw

PATCH 12/12 ahci: Add platform driver

In reply to Anton Vorontsov

This can be used for AHCI-compatible interfaces implemented inside a System-On-Chip solutions, or AHCI devices connected via localbus.

---
 drivers/ata/Kconfig         |    9 ++
 drivers/ata/Makefile        |    1 +
 drivers/ata/ahci_platform.c |  196 +++++++++++++++++++++++++++++++++++++++++++
 drivers/ata/ahci_platform.h |   29 +++++++
 4 files changed, 235 insertions(+), 0 deletions(-)
 create mode 100644 drivers/ata/ahci_platform.c
 create mode 100644 drivers/ata/ahci_platform.h
drivers/ata/Kconfig +9 -0
index 4656782..a81013d 100644
@@ -61,6 +61,15 @@ config SATA_AHCI_PCI
 	help
 	  This option enables support for PCI AHCI Serial ATA controllers.
 
+config SATA_AHCI_PLATFORM
+	tristate "Platform AHCI SATA support"
+	depends on SATA_AHCI
+	help
+	  This option enables support for Platform AHCI Serial ATA
+	  controllers.
+
+	  If unsure, say N.
+
 config SATA_SIL24
 	tristate "Silicon Image 3124/3132 SATA support"
 	depends on PCI
drivers/ata/Makefile +1 -0
index a220e90..c734c75 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_ATA)		+= libata.o
 
 obj-$(CONFIG_SATA_AHCI)		+= ahci.o
 obj-$(CONFIG_SATA_AHCI_PCI)	+= ahci_pci.o
+obj-$(CONFIG_SATA_AHCI_PLATFORM)+= ahci_platform.o
 obj-$(CONFIG_SATA_SVW)		+= sata_svw.o
 obj-$(CONFIG_ATA_PIIX)		+= ata_piix.o
 obj-$(CONFIG_SATA_PROMISE)	+= sata_promise.o
drivers/ata/ahci_platform.c new file +196 -0

196 lines not on this page · raw message

drivers/ata/ahci_platform.h new file +29 -0
new file mode 100644
index 0000000..f7dd576
@@ -0,0 +1,29 @@
+/*
+ * AHCI SATA platform driver
+ *
+ * Copyright 2004-2005  Red Hat, Inc.
+ *   Jeff Garzik <[email protected]>
+ * Copyright 2010  MontaVista Software, LLC.
+ *   Anton Vorontsov <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ */
+
+#ifndef _AHCI_PLATFORM_H
+#define _AHCI_PLATFORM_H
+
+struct device;
+struct ata_port_info;
+
+struct ahci_platform_data {
+	int (*init)(struct device *dev);
+	void (*exit)(struct device *dev);
+	const struct ata_port_info *ata_port_info;
+	unsigned int force_port_map;
+	unsigned int mask_port_map;
+};
+
+#endif /* _AHCI_PLATFORM_H */
Signature · 1 line
1.7.0
#18 lore raw

Re: [PATCH 12/12] ahci: Add platform driver

Hello.

Quoted 4 lines · Anton Vorontsov

This can be used for AHCI-compatible interfaces implemented inside a System-On-Chip solutions, or AHCI devices connected via localbus.

[...]

Quoted 22 lines
drivers/ata/ahci_platform.c new file +15 -0
new file mode 100644
index 0000000..f3f96d6
@@ -0,0 +1,196 @@
+/*
+ * AHCI SATA platform driver
+ *
+ * Copyright 2004-2005  Red Hat, Inc.
+ *   Jeff Garzik <[email protected]>
+ * Copyright 2010  MontaVista Software, LLC.
+ *   Anton Vorontsov <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ */
+
+#include <linux/kernel.h>

drivers/ata/ahci_platform.c line 25

Quoted 10 lines
drivers/ata/ahci_platform.c new file +10 -0
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/device.h>
+#include <linux/libata.h>
+#include <linux/platform_device.h>
+#include "ahci.h"
+#include "ahci_platform.h"
+
+static int __devinit ahci_probe(struct platform_device *pdev)

Does it make sense to make this driver hotplug capable?

Quoted 9 lines
drivers/ata/ahci_platform.c new file +8 -0
+{
+	struct device *dev = &pdev->dev;
+	struct ahci_platform_data *pdata = pdev->dev.platform_data;
+	struct ata_port_info pi = {
+		.flags		= AHCI_FLAG_COMMON,
+		.pio_mask	= ATA_PIO4,
+		.udma_mask	= ATA_UDMA6,
+		.port_ops	= &ahci_ops,

drivers/ata/ahci_platform.c line 43

Quoted 10 lines
drivers/ata/ahci_platform.c new file +10 -0
+	};
+	const struct ata_port_info *ppi[] = { &pi, NULL };
+	struct ahci_host_priv *hpriv;
+	struct ata_host *host;
+	struct resource *res;
+	int n_ports;
+	int i;
+	int rc;
+
+	WARN_ON(ATA_MAX_QUEUE > AHCI_MAX_CMDS);

Hm...

drivers/ata/ahci_platform.c line 89

Quoted 4 lines
drivers/ata/ahci_platform.c new file +3 -0
+	ahci_set_em_messages(hpriv, &pi);
+
+

Extra newline?

drivers/ata/ahci_platform.c line 48

Quoted 3 lines
drivers/ata/ahci_platform.c new file +2 -0
+
+

Another one?

Quoted 4 lines
drivers/ata/ahci_platform.c new file +3 -0
+		/* disabled/not-implemented port */
+		if (!(hpriv->port_map & (1 << i)))
+			ap->ops = &ata_dummy_port_ops;

drivers/ata/ahci_platform.c line 139

Quoted 10 lines
drivers/ata/ahci_platform.c new file +10 -0
+	}
+
+	rc = ahci_reset_controller(host);
+	if (rc)
+		goto err0;
+
+	ahci_init_controller(host);
+	ahci_print_info(host, "platform");
+
+	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);

Could also use platform_get_irq()...

drivers/ata/ahci_platform.h

Quoted 6 lines
drivers/ata/ahci_platform.h new file +0 -0
new file mode 100644
index 0000000..f7dd576

I doubt that it's good place for declaring the platform data which
will be used by the platform code. This file should be somewhere in include/linux/, don't you think?

Quoted 21 lines
drivers/ata/ahci_platform.h new file +19 -0
@@ -0,0 +1,29 @@
+/*
+ * AHCI SATA platform driver
+ *
+ * Copyright 2004-2005  Red Hat, Inc.
+ *   Jeff Garzik <[email protected]>
+ * Copyright 2010  MontaVista Software, LLC.
+ *   Anton Vorontsov <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ */
+
+#ifndef _AHCI_PLATFORM_H
+#define _AHCI_PLATFORM_H
+
+struct device;
+struct ata_port_info;

drivers/ata/ahci_platform.h line 29

Quoted 10 lines
drivers/ata/ahci_platform.h new file +10 -0
+
+struct ahci_platform_data {
+	int (*init)(struct device *dev);
+	void (*exit)(struct device *dev);
+	const struct ata_port_info *ata_port_info;
+	unsigned int force_port_map;
+	unsigned int mask_port_map;
+};
+
+#endif /* _AHCI_PLATFORM_H */

MBR, Sergei

#19 lore raw

Re: [PATCH 12/12] ahci: Add platform driver

On Tue, Mar 02, 2010 at 10:41:04PM +0300, Sergei Shtylyov wrote:
[...]

Quoted 3 lines
Quoted 1 line

+static int __devinit ahci_probe(struct platform_device *pdev)

Does it make sense to make this driver hotplug capable?

Probably not, at least for now. Will correct.

[...]

Quoted 3 lines

drivers/ata/ahci_platform.c line 43

Quoted 1 line
drivers/ata/ahci_platform.c new file +1 -0
+	WARN_ON(ATA_MAX_QUEUE > AHCI_MAX_CMDS);

Hm...

That was copied from the PCI driver.

Quoted 5 lines

drivers/ata/ahci_platform.c line 89

Quoted 3 lines
drivers/ata/ahci_platform.c new file +3 -0
+	ahci_set_em_messages(hpriv, &pi);
+
+

Extra newline?

Yeah, that's all directly copied from the PCI driver. Will correct.

[...]

Quoted 3 lines

drivers/ata/ahci_platform.c line 139

Quoted 1 line
drivers/ata/ahci_platform.c new file +1 -0
+	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);

Could also use platform_get_irq()...

OK.

Quoted 9 lines

drivers/ata/ahci_platform.h

Quoted 5 lines
drivers/ata/ahci_platform.h new file +0 -0
new file mode 100644
index 0000000..f7dd576

I doubt that it's good place for declaring the platform data which
will be used by the platform code. This file should be somewhere in include/linux/, don't you think?

Will change.

Thanks!

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#20 lore raw
In reply to Anton Vorontsov
Quoted 11 lines · Anton Vorontsov

Hi all,

This patch set refactors AHCI code to make it more generic, plus adds a new platform driver to support AHCI interfaces integrated into System-On-Chip devices.

The patches should apply on top of v2.6.33 (soon will be rebased on top of linux-next).

I don't have any PCI AHCI handy (yet, but I plan to find one), so PCI AHCI was only compile-tested.

As demonstrated in libata-dev.git#libahci, I think the best route is to move generic code into libahci. In #libahci you will see

	libahci -> common code
	ahci -> standard PCI driver, req's libahci
	mv-ahci -> Marvell AHCI driver, req's libahci
	acard-ahci -> ACard AHCI driver, req's libahci

and to this we could easily add

	platform-ahci -> platform AHCI driver, req's libahci

WARNING: #libahci should not be used directly, it is meant for illustration purposes only. It has not been properly updated for several recent ahci.c changes upstream, which implies that the trivial-and-obvious task of moving generic code from ahci.c to libahci.c must be redone.

Jeff

P.S. Please use the email addresses in MAINTAINERS,

M: Jeff Garzik <[email protected]>
L: [email protected]

The redhat.com email address is only used for legal (sign-off) purposes, not normal use.

#21 lore raw

On Tue, Mar 02, 2010 at 04:34:39PM -0500, Jeff Garzik wrote:
[...]

Quoted 10 lines

As demonstrated in libata-dev.git#libahci, I think the best route is to move generic code into libahci. In #libahci you will see

	libahci -> common code
	ahci -> standard PCI driver, req's libahci
	mv-ahci -> Marvell AHCI driver, req's libahci
	acard-ahci -> ACard AHCI driver, req's libahci

and to this we could easily add

Quoted 7 lines
	platform-ahci -> platform AHCI driver, req's libahci

WARNING: #libahci should not be used directly, it is meant for illustration purposes only. It has not been properly updated for several recent ahci.c changes upstream, which implies that the trivial-and-obvious task of moving generic code from ahci.c to libahci.c must be redone.

Well, do I understand correctly that the only issue is the file names? I.e. in my patches, instead of keeping the library code in ahci.c, I should move the library code into libahci.c, and keep the PCI code in ahci.c?

Because, as far as I can see, the result of my patches is pretty much the same as in #libahci, except the file names and more things that can be reused (i.e. ahci_sht, ahci_ops -- I kept all this in the library part, since we want to share it with the platform driver).

Also, I don't export function that aren't currently used by PCI or platform drivers, but in #libahci there are all exported. Should I keep it my way, or should I export all the functions (even if there are no any users of these)?

Quoted 7 lines

P.S. Please use the email addresses in MAINTAINERS,

M: Jeff Garzik <[email protected]>
L: [email protected]

The redhat.com email address is only used for legal (sign-off) purposes, not normal use.

Got it, thanks!

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#22 lore raw
Quoted 31 lines · Anton Vorontsov

On Tue, Mar 02, 2010 at 04:34:39PM -0500, Jeff Garzik wrote:
[...]

Quoted 10 lines

As demonstrated in libata-dev.git#libahci, I think the best route is to move generic code into libahci. In #libahci you will see

	libahci ->  common code
	ahci ->  standard PCI driver, req's libahci
	mv-ahci ->  Marvell AHCI driver, req's libahci
	acard-ahci ->  ACard AHCI driver, req's libahci

and to this we could easily add

Quoted 7 lines
	platform-ahci ->  platform AHCI driver, req's libahci

WARNING: #libahci should not be used directly, it is meant for illustration purposes only. It has not been properly updated for several recent ahci.c changes upstream, which implies that the trivial-and-obvious task of moving generic code from ahci.c to libahci.c must be redone.

Well, do I understand correctly that the only issue is the file names? I.e. in my patches, instead of keeping the library code in ahci.c, I should move the library code into libahci.c, and keep the PCI code in ahci.c?

Because, as far as I can see, the result of my patches is pretty much the same as in #libahci, except the file names and more things that can be reused (i.e. ahci_sht, ahci_ops -- I kept all this in the library part, since we want to share it with the platform driver).

Quoted 4 lines

Also, I don't export function that aren't currently used by PCI or platform drivers, but in #libahci there are all exported. Should I keep it my way, or should I export all the functions (even if there are no any users of these)?

Well, the general idea is to have a kernel module libahci.ko, upon which ahci.ko, mv-ahci.ko, acard-ahci.ko and platform-ahci.ko depends. That would imply a bunch of exports, when the library code is moved from ahci.c to libahci.c, because libahci should be a separate kernel module.

I'm not overly picky about file naming. However, in existing installations, people, scripts, knowledgebase articles and configuration files expect "ahci" to be the driver for PCI AHCI devices. We don't want to break that if we can avoid it. Simply using a different name avoids any breakage related to name changes.

Jeff