linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Olof Johansson <olof@lixom.net>
To: linuxppc-dev@ozlabs.org
Subject: [patch 07/35] pasemi_mac: stop using the pci config space accessors for register read/writes
Date: Thu, 05 Jul 2007 12:02:40 -0500	[thread overview]
Message-ID: <20070705170235.314700000@lixom.net> (raw)
In-Reply-To: 20070705170233.258351000@lixom.net

Move away from using the pci config access functions for simple register
access.  Our device has all of the registers in the config space (hey,
from the hardware point of view it looks reasonable :-), so we need to
somehow get to it. Newer firmwares have it in the device tree such that
we can just get it and ioremap it there (in case it ever moves in future
products). For now, provide a hardcoded fallback for older firmwares.


Signed-off-by: Olof Johansson <olof@lixom.net>


Index: netdev-2.6/drivers/net/pasemi_mac.c
===================================================================
--- netdev-2.6.orig/drivers/net/pasemi_mac.c
+++ netdev-2.6/drivers/net/pasemi_mac.c
@@ -81,46 +81,47 @@ MODULE_PARM_DESC(debug, "PA Semi MAC bit
 
 static struct pasdma_status *dma_status;
 
-static unsigned int read_iob_reg(struct pasemi_mac *mac, unsigned int reg)
+static inline unsigned int read_iob_reg(struct pasemi_mac *mac, unsigned int reg)
 {
 	unsigned int val;
 
-	pci_read_config_dword(mac->iob_pdev, reg, &val);
+	val = in_le32(mac->iob_regs+reg);
+
 	return val;
 }
 
-static void write_iob_reg(struct pasemi_mac *mac, unsigned int reg,
+static inline void write_iob_reg(struct pasemi_mac *mac, unsigned int reg,
 			  unsigned int val)
 {
-	pci_write_config_dword(mac->iob_pdev, reg, val);
+	out_le32(mac->iob_regs+reg, val);
 }
 
-static unsigned int read_mac_reg(struct pasemi_mac *mac, unsigned int reg)
+static inline unsigned int read_mac_reg(struct pasemi_mac *mac, unsigned int reg)
 {
 	unsigned int val;
 
-	pci_read_config_dword(mac->pdev, reg, &val);
+	val = in_le32(mac->regs+reg);
 	return val;
 }
 
-static void write_mac_reg(struct pasemi_mac *mac, unsigned int reg,
+static inline void write_mac_reg(struct pasemi_mac *mac, unsigned int reg,
 			  unsigned int val)
 {
-	pci_write_config_dword(mac->pdev, reg, val);
+	out_le32(mac->regs+reg, val);
 }
 
-static unsigned int read_dma_reg(struct pasemi_mac *mac, unsigned int reg)
+static inline unsigned int read_dma_reg(struct pasemi_mac *mac, unsigned int reg)
 {
 	unsigned int val;
 
-	pci_read_config_dword(mac->dma_pdev, reg, &val);
+	val = in_le32(mac->dma_regs+reg);
 	return val;
 }
 
-static void write_dma_reg(struct pasemi_mac *mac, unsigned int reg,
+static inline void write_dma_reg(struct pasemi_mac *mac, unsigned int reg,
 			  unsigned int val)
 {
-	pci_write_config_dword(mac->dma_pdev, reg, val);
+	out_le32(mac->dma_regs+reg, val);
 }
 
 static int pasemi_get_mac_addr(struct pasemi_mac *mac)
@@ -585,7 +586,6 @@ static int pasemi_mac_clean_tx(struct pa
 	}
 	mac->tx->next_to_clean += count;
 	spin_unlock_irqrestore(&mac->tx->lock, flags);
-
 	netif_wake_queue(mac->netdev);
 
 	return count;
@@ -1077,6 +1077,73 @@ static int pasemi_mac_poll(struct net_de
 	}
 }
 
+static inline void __iomem * __devinit map_onedev(struct pci_dev *p, int index)
+{
+	struct device_node *dn;
+	void __iomem *ret;
+
+	dn = pci_device_to_OF_node(p);
+	if (!dn)
+		goto fallback;
+
+	ret = of_iomap(dn, index);
+	if (!ret)
+		goto fallback;
+
+	return ret;
+fallback:
+	/* This is hardcoded and ugly, but we have some firmware versions
+	 * who don't provide the register space in the device tree. Luckily
+	 * they are at well-known locations so we can just do the math here.
+	 */
+	return ioremap(0xe0000000 + (p->devfn << 12), 0x1000);
+}
+
+static int __devinit pasemi_mac_map_regs(struct pasemi_mac *mac)
+{
+	struct resource res;
+	struct device_node *dn;
+	int err;
+
+	mac->dma_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa007, NULL);
+	if (!mac->dma_pdev) {
+		dev_err(&mac->pdev->dev, "Can't find DMA Controller\n");
+		return -ENODEV;
+	}
+
+	mac->iob_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
+	if (!mac->iob_pdev) {
+		dev_err(&mac->pdev->dev, "Can't find I/O Bridge\n");
+		return -ENODEV;
+	}
+
+	mac->regs = map_onedev(mac->pdev, 0);
+	mac->dma_regs = map_onedev(mac->dma_pdev, 0);
+	mac->iob_regs = map_onedev(mac->iob_pdev, 0);
+
+	if (!mac->regs || !mac->dma_regs || !mac->iob_regs) {
+		dev_err(&mac->pdev->dev, "Can't map registers\n");
+		return -ENODEV;
+	}
+
+	/* The dma status structure is located in the I/O bridge, and
+	 * is cache coherent.
+	 */
+	if (!dma_status) {
+		dn = pci_device_to_OF_node(mac->iob_pdev);
+		if (dn)
+			err = of_address_to_resource(dn, 1, &res);
+		if (!dn || err) {
+			/* Fallback for old firmware */
+			res.start = 0xfd800000;
+			res.end = res.start + 0x1000;
+		}
+		dma_status = __ioremap(res.start, res.end-res.start, 0);
+	}
+
+	return 0;
+}
+
 static int __devinit
 pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
@@ -1105,21 +1172,6 @@ pasemi_mac_probe(struct pci_dev *pdev, c
 
 	mac->pdev = pdev;
 	mac->netdev = dev;
-	mac->dma_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa007, NULL);
-
-	if (!mac->dma_pdev) {
-		dev_err(&pdev->dev, "Can't find DMA Controller\n");
-		err = -ENODEV;
-		goto out_free_netdev;
-	}
-
-	mac->iob_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
-
-	if (!mac->iob_pdev) {
-		dev_err(&pdev->dev, "Can't find I/O Bridge\n");
-		err = -ENODEV;
-		goto out_put_dma_pdev;
-	}
 
 	/* These should come out of the device tree eventually */
 	mac->dma_txch = index;
@@ -1162,12 +1214,9 @@ pasemi_mac_probe(struct pci_dev *pdev, c
 	dev->poll = pasemi_mac_poll;
 	dev->features = NETIF_F_HW_CSUM;
 
-	/* The dma status structure is located in the I/O bridge, and
-	 * is cache coherent.
-	 */
-	if (!dma_status)
-		/* XXXOJN This should come from the device tree */
-		dma_status = __ioremap(0xfd800000, 0x1000, 0);
+	err = pasemi_mac_map_regs(mac);
+	if (err)
+		goto out;
 
 	mac->rx_status = &dma_status->rx_sta[mac->dma_rxch];
 	mac->tx_status = &dma_status->tx_sta[mac->dma_txch];
@@ -1194,10 +1243,17 @@ pasemi_mac_probe(struct pci_dev *pdev, c
 	return err;
 
 out:
-	pci_dev_put(mac->iob_pdev);
-out_put_dma_pdev:
-	pci_dev_put(mac->dma_pdev);
-out_free_netdev:
+	if (mac->iob_pdev)
+		pci_dev_put(mac->iob_pdev);
+	if (mac->dma_pdev)
+		pci_dev_put(mac->dma_pdev);
+	if (mac->dma_regs)
+		iounmap(mac->dma_regs);
+	if (mac->iob_regs)
+		iounmap(mac->iob_regs);
+	if (mac->regs)
+		iounmap(mac->regs);
+
 	free_netdev(dev);
 out_disable_device:
 	pci_disable_device(pdev);
@@ -1221,6 +1277,10 @@ static void __devexit pasemi_mac_remove(
 	pci_dev_put(mac->dma_pdev);
 	pci_dev_put(mac->iob_pdev);
 
+	iounmap(mac->regs);
+	iounmap(mac->dma_regs);
+	iounmap(mac->iob_regs);
+
 	pci_set_drvdata(pdev, NULL);
 	free_netdev(netdev);
 }
Index: netdev-2.6/drivers/net/pasemi_mac.h
===================================================================
--- netdev-2.6.orig/drivers/net/pasemi_mac.h
+++ netdev-2.6/drivers/net/pasemi_mac.h
@@ -52,6 +52,9 @@ struct pasemi_mac_rxring {
 
 struct pasemi_mac {
 	struct net_device *netdev;
+	void __iomem *regs;
+	void __iomem *dma_regs;
+	void __iomem *iob_regs;
 	struct pci_dev *pdev;
 	struct pci_dev *dma_pdev;
 	struct pci_dev *iob_pdev;

--

  parent reply	other threads:[~2007-07-05 17:03 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-05 17:02 [patch 00/35] PA Semi patch set Olof Johansson
2007-07-05 17:02 ` [patch 01/35] pasemi: rename platform Olof Johansson
2007-07-08 23:52   ` Stephen Rothwell
2007-07-09  0:18     ` Olof Johansson
2007-07-09  7:23       ` Stephen Rothwell
2007-07-09 17:19         ` Olof Johansson
2007-07-09 17:21           ` Olof Johansson
2007-07-05 17:02 ` [patch 02/35] PA Semi EDAC driver Olof Johansson
2007-07-05 17:02 ` [patch 03/35] Change powerpc64 ioaddr_t to u_int Olof Johansson
2007-07-05 17:02 ` [patch 04/35] pasemi_mac: Fix TX interrupt threshold Olof Johansson
2007-07-05 17:02 ` [patch 05/35] pasemi_mac: Clean TX ring in poll Olof Johansson
2007-07-05 17:02 ` [patch 06/35] pasemi_mac: Abstract out register access Olof Johansson
2007-07-05 17:02 ` Olof Johansson [this message]
2007-07-26 21:25   ` [patch 07/35] pasemi_mac: stop using the pci config space accessors for register read/writes Marian Balakowicz
2007-07-28  8:35     ` Olof Johansson
2007-08-01  9:27       ` Marian Balakowicz
2007-07-05 17:02 ` [patch 08/35] pasemi_mac: Enable L2 caching of packet headers Olof Johansson
2007-07-05 17:02 ` [patch 09/35] pasemi_mac: Simplify memcpy for short receives Olof Johansson
2007-07-05 17:02 ` [patch 10/35] pasemi_mac: Minor performance tweaks Olof Johansson
2007-07-05 17:02 ` [patch 11/35] pasemi_mac: Reduce locking when cleaning TX ring Olof Johansson
2007-07-05 17:02 ` [patch 12/35] pasemi_mac: Enable LLTX Olof Johansson
2007-07-05 17:02 ` [patch 13/35] Cleanup marvell phy driver init Olof Johansson
2007-07-05 17:02 ` [patch 14/35] Add 88E1112 PHY ID to the marvell driver Olof Johansson
2007-07-05 17:02 ` [patch 15/35] Export HID registers via sysfs Olof Johansson
2007-07-05 17:02 ` [patch 16/35] Electra ide platform glue Olof Johansson
2007-07-05 17:02 ` [patch 17/35] CF driver for PA Semi Electra Olof Johansson
2007-07-05 17:02 ` [patch 18/35] Spread IRQs among cpus by default Olof Johansson
2007-07-05 17:02 ` [patch 19/35] Improve machine check output Olof Johansson
2007-07-05 17:02 ` [patch 20/35] Remove idle_spin function pointer Olof Johansson
2007-07-05 17:02 ` [patch 21/35] Use MSR_PMM to disable profiling of the idle loop Olof Johansson
2007-07-05 17:02 ` [patch 22/35] Work around errata 4111 Olof Johansson
2007-07-05 17:02 ` [patch 23/35] Work around UART erratas Olof Johansson
2007-07-05 17:02 ` [patch 24/35] Work around errata 4628 Olof Johansson
2007-07-05 17:02 ` [patch 25/35] Work around errata 4025 Olof Johansson
2007-07-05 17:02 ` [patch 26/35] Work around errata 4713 Olof Johansson
2007-07-05 17:03 ` [patch 27/35] Work around errata 4290 Olof Johansson
2007-07-05 18:50   ` Gabriel Paubert
2007-07-05 19:26     ` Olof Johansson
2007-07-05 17:03 ` [patch 28/35] Work around errata 4712 Olof Johansson
2007-07-05 17:03 ` [patch 29/35] Work around errata 4910 Olof Johansson
2007-07-05 17:03 ` [patch 30/35] Disable PURR on pa6t Olof Johansson
2007-07-05 17:03 ` [patch 31/35] Work around errata 4161 Olof Johansson
2007-07-05 17:03 ` [patch 32/35] Dont reset openpic on init Olof Johansson
2007-07-05 17:03 ` [patch 33/35] Work around errata 5667 Olof Johansson
2007-07-05 17:03 ` [patch 34/35] Work around errata 4505 Olof Johansson
2007-07-05 17:03 ` [patch 35/35] Work around errata 5652 Olof Johansson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070705170235.314700000@lixom.net \
    --to=olof@lixom.net \
    --cc=linuxppc-dev@ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).