netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Mohr <andi@lisas.de>
To: andim2@users.sf.net
Cc: Roger Luethi <rl@hellgate.ch>,
	netdev@vger.kernel.org, Francois Romieu <romieu@fr.zoreil.com>
Subject: [PATCH RFC 08/15] via-rhine: MMIO: move support decision (compile-time-only to runtime).
Date: Mon, 31 Dec 2012 16:25:42 +0100	[thread overview]
Message-ID: <1356967549-5056-9-git-send-email-andi@lisas.de> (raw)
In-Reply-To: <1356967549-5056-1-git-send-email-andi@lisas.de>

From: Andreas Mohr <andim2@users.sf.net>

Reduces ifdefs a bit in the process, too.

Signed-off-by: Andreas Mohr <andim2@users.sf.net>
---
 drivers/net/ethernet/via/via-rhine.c |   56 ++++++++++++++++++++-------------
 1 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
index a16e227..a4b8d84 100644
--- a/drivers/net/ethernet/via/via-rhine.c
+++ b/drivers/net/ethernet/via/via-rhine.c
@@ -36,6 +36,7 @@
 #define DRV_RELDATE	"2010-10-09"
 
 #include <linux/types.h>
+#include <linux/cache.h> /* __read_mostly */
 
 /* A few user-configurable values.
    These may be modified when a driver module is loaded. */
@@ -119,7 +120,12 @@ static const char version[] =
 /* This driver was written to use PCI memory space. Some early versions
    of the Rhine may only work correctly with I/O space accesses. */
 #ifdef CONFIG_VIA_RHINE_MMIO
-#define USE_MMIO
+#define IMPL_MMIO
+/* Hmm, I don't know whether we actually want to offer this
+ * as a publicly visible module parameter, with the likely ensuing confusion
+ * (does/doesn't this module build variant have it, and what is the default?).
+ */
+static bool use_mmio __read_mostly = 1;
 #else
 #endif
 
@@ -137,6 +143,9 @@ MODULE_PARM_DESC(avoid_D3, "Avoid power state D3 (work-around for broken BIOSes)
 #define MCAM_SIZE	32
 #define VCAM_SIZE	32
 
+#define VIA_PCIBAR_IO 0
+#define VIA_PCIBAR_MMIO 1
+
 /*
 		Theory of Operation
 
@@ -638,7 +647,7 @@ static void rhine_chip_reset(struct net_device *dev)
 		   "failed" : "succeeded");
 }
 
-#ifdef USE_MMIO
+#ifdef IMPL_MMIO
 static void enable_mmio(long pioaddr, u32 quirks)
 {
 	int n;
@@ -696,13 +705,14 @@ static void rhine_reload_eeprom(long pioaddr, struct net_device *dev)
 	if (i > 512)
 		pr_info("%4d cycles used @ %s:%d\n", i, __func__, __LINE__);
 
-#ifdef USE_MMIO
+#ifdef IMPL_MMIO
 	/*
 	 * Reloading from EEPROM overwrites ConfigA-D, so we must re-enable
 	 * MMIO. If reloading EEPROM was done first this could be avoided, but
 	 * it is not known if that still works with the "win98-reboot" problem.
 	 */
-	enable_mmio(pioaddr, rp->quirks);
+	if (use_mmio)
+		enable_mmio(pioaddr, rp->quirks);
 #endif
 
 	/* Turn off EEPROM-controlled wake-up (magic packet) */
@@ -890,14 +900,11 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	u32 quirks;
 	long pioaddr;
 	long memaddr;
+	long log_ioaddr; /* (non-)MMIO switch helper */
 	void __iomem *ioaddr;
 	int io_size, phy_id;
 	const char *name;
-#ifdef USE_MMIO
-	int bar = 1;
-#else
-	int bar = 0;
-#endif
+	int bar = VIA_PCIBAR_IO;
 
 /* when built into the kernel, we only print version if device is found */
 #ifndef MODULE
@@ -972,6 +979,10 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (rc)
 		goto err_out_free_netdev;
 
+#ifdef IMPL_MMIO
+	if (use_mmio)
+		bar = VIA_PCIBAR_MMIO;
+#endif
 	ioaddr = pci_iomap(pdev, bar, io_size);
 	if (!ioaddr) {
 		rc = -EIO;
@@ -983,14 +994,18 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	rp->base = ioaddr;
 
-#ifdef USE_MMIO
-	enable_mmio(rp->pioaddr, rp->quirks);
+	log_ioaddr = (long)ioaddr;
+#ifdef IMPL_MMIO
+	if (use_mmio) {
+		enable_mmio(rp->pioaddr, rp->quirks);
 
-	if (!mmio_verify_registers(pdev, pioaddr, ioaddr)) {
-		rc = -EIO;
-		goto err_out_unmap;
+		if (!mmio_verify_registers(pdev, pioaddr, ioaddr)) {
+			rc = -EIO;
+			goto err_out_unmap;
+		}
+		log_ioaddr = memaddr;
 	}
-#endif /* USE_MMIO */
+#endif /* IMPL_MMIO */
 
 	/* Get chip registers into a sane state */
 	rhine_power_init(dev);
@@ -1044,11 +1059,7 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	netdev_info(dev, "VIA %s at 0x%lx, %pM, IRQ %d\n",
 		    name,
-#ifdef USE_MMIO
-		    memaddr,
-#else
-		    (long)ioaddr,
-#endif
+		    log_ioaddr,
 		    dev->dev_addr, pdev->irq);
 
 	pci_set_drvdata(pdev, dev);
@@ -2362,8 +2373,9 @@ static int rhine_resume(struct device *device)
 	 * into a helper to be commonly called by both places.
 	 */
 
-#ifdef USE_MMIO
-	enable_mmio(rp->pioaddr, rp->quirks);
+#ifdef IMPL_MMIO
+	if (use_mmio)
+		enable_mmio(rp->pioaddr, rp->quirks);
 #endif
 	/*
 	 * FIXME: some power calls here are being done
-- 
1.7.2.5

  parent reply	other threads:[~2012-12-31 15:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-31 15:25 [PATCH RFC 00/15] via-rhine: fix resume, cleanup, eth ops (regs) Andreas Mohr
2012-12-31 15:25 ` [PATCH RFC 01/15] via-rhine: YARB: fix broken resume of ifdown case (NetworkManager) Andreas Mohr
2012-12-31 15:25 ` [PATCH RFC 02/15] via-rhine: some suspend/resume cleanup Andreas Mohr
2012-12-31 15:25 ` [PATCH RFC 03/15] via-rhine: small rhine_wait_bit() improvement Andreas Mohr
2012-12-31 15:25 ` [PATCH RFC 04/15] via-rhine: handle compile warnings (use PCI_VDEVICE macro) Andreas Mohr
2012-12-31 15:25 ` [PATCH RFC 05/15] via-rhine: Spelling/phrases cleanup Andreas Mohr
2012-12-31 15:25 ` [PATCH RFC 06/15] via-rhine: The Great Renaming Andreas Mohr
2012-12-31 15:25 ` [PATCH RFC 07/15] via-rhine: MMIO: move register verify into helper function Andreas Mohr
2012-12-31 15:25 ` Andreas Mohr [this message]
2012-12-31 15:25 ` [PATCH RFC 09/15] via-rhine: mark some variables as __read_mostly Andreas Mohr
2012-12-31 15:25 ` [PATCH RFC 10/15] via-rhine: WOL: remove duplication into a helper Andreas Mohr
2012-12-31 15:25 ` [PATCH RFC 11/15] via-rhine: WOL: separate WOL configuration (and its logging) Andreas Mohr
2012-12-31 15:25 ` [PATCH RFC 12/15] via-rhine: implement get_regs() ethtool ops Andreas Mohr
2012-12-31 15:25 ` [PATCH RFC 13/15] via-rhine: misc. cleanup Andreas Mohr
2012-12-31 15:25 ` [PATCH RFC 14/15] via-rhine: The Great Deduplication Andreas Mohr
2012-12-31 15:25 ` [PATCH RFC 15/15] via-rhine: add helper (reduce type-unsafe void * assignments) Andreas Mohr
2012-12-31 22:21   ` David Miller

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=1356967549-5056-9-git-send-email-andi@lisas.de \
    --to=andi@lisas.de \
    --cc=andim2@users.sf.net \
    --cc=netdev@vger.kernel.org \
    --cc=rl@hellgate.ch \
    --cc=romieu@fr.zoreil.com \
    /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).