Netdev List
 help / color / mirror / Atom feed
From: Dhananjay Phadke <dhananjay@netxen.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, ameen.rahman@qlogic.com
Subject: [PATCH NEXT 3/5] netxen: annotate register windowing code
Date: Tue, 13 Oct 2009 08:31:43 -0700	[thread overview]
Message-ID: <1255447905-29805-4-git-send-email-dhananjay@netxen.com> (raw)
In-Reply-To: <1255447905-29805-1-git-send-email-dhananjay@netxen.com>

Use common variables crb_win, ocm_win for all revisions of chip.

Signed-off-by: Dhananjay Phadke <dhananjay@netxen.com>
---
 drivers/net/netxen/netxen_nic.h      |    4 +-
 drivers/net/netxen/netxen_nic_hw.c   |  100 ++++++++++++++++------------------
 drivers/net/netxen/netxen_nic_main.c |    4 +-
 3 files changed, 51 insertions(+), 57 deletions(-)

diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h
index eef9e66..2a42132 100644
--- a/drivers/net/netxen/netxen_nic.h
+++ b/drivers/net/netxen/netxen_nic.h
@@ -549,7 +549,7 @@ struct netxen_hardware_context {
 	unsigned long pci_len0;
 
 	u32 ocm_win;
-	u32 resv1;
+	u32 crb_win;
 
 	u8 cut_through;
 	u8 revision_id;
@@ -1115,8 +1115,6 @@ struct netxen_adapter {
 	struct pci_dev *pdev;
 	struct list_head mac_list;
 
-	u32 curr_window;
-	u32 crb_win;
 	rwlock_t adapter_lock;
 
 	spinlock_t tx_clean_lock;
diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c
index f677752..37f4766 100644
--- a/drivers/net/netxen/netxen_nic_hw.c
+++ b/drivers/net/netxen/netxen_nic_hw.c
@@ -1046,46 +1046,34 @@ int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, __le64 *mac)
  * Changes the CRB window to the specified window.
  */
 static void
-netxen_nic_pci_change_crbwindow_128M(struct netxen_adapter *adapter, u32 wndw)
+netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter,
+		u32 window)
 {
 	void __iomem *offset;
-	u32 tmp;
-	int count = 0;
-	uint8_t func = adapter->ahw.pci_func;
+	int count = 10;
+	u8 func = adapter->ahw.pci_func;
 
-	if (adapter->curr_window == wndw)
+	if (adapter->ahw.crb_win == window)
 		return;
-	/*
-	 * Move the CRB window.
-	 * We need to write to the "direct access" region of PCI
-	 * to avoid a race condition where the window register has
-	 * not been successfully written across CRB before the target
-	 * register address is received by PCI. The direct region bypasses
-	 * the CRB bus.
-	 */
+
 	offset = PCI_OFFSET_SECOND_RANGE(adapter,
 			NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
 
-	if (wndw & 0x1)
-		wndw = NETXEN_WINDOW_ONE;
+	writel(window, offset);
+	do {
+		if (window == readl(offset))
+			break;
 
-	writel(wndw, offset);
+		if (printk_ratelimit())
+			dev_warn(&adapter->pdev->dev,
+					"failed to set CRB window to %d\n",
+					(window == NETXEN_WINDOW_ONE));
+		udelay(1);
 
-	/* MUST make sure window is set before we forge on... */
-	while ((tmp = readl(offset)) != wndw) {
-		printk(KERN_WARNING "%s: %s WARNING: CRB window value not "
-		       "registered properly: 0x%08x.\n",
-		       netxen_nic_driver_name, __func__, tmp);
-		mdelay(1);
-		if (count >= 10)
-			break;
-		count++;
-	}
+	} while (--count > 0);
 
-	if (wndw == NETXEN_WINDOW_ONE)
-		adapter->curr_window = 1;
-	else
-		adapter->curr_window = 0;
+	if (count > 0)
+		adapter->ahw.crb_win = window;
 }
 
 /*
@@ -1140,20 +1128,24 @@ netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, ulong *off)
 static void
 netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong *off)
 {
-	u32 win_read;
+	u32 window;
+	void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M;
 
-	adapter->crb_win = CRB_HI(*off);
-	writel(adapter->crb_win, (adapter->ahw.pci_base0 + CRB_WINDOW_2M));
-	/*
-	 * Read back value to make sure write has gone through before trying
-	 * to use it.
-	 */
-	win_read = readl(adapter->ahw.pci_base0 + CRB_WINDOW_2M);
-	if (win_read != adapter->crb_win) {
-		printk(KERN_ERR "%s: Written crbwin (0x%x) != "
-				"Read crbwin (0x%x), off=0x%lx\n",
-				__func__, adapter->crb_win, win_read, *off);
+	window = CRB_HI(*off);
+
+	if (adapter->ahw.crb_win == window)
+		goto done;
+
+	writel(window, addr);
+	if (readl(addr) != window) {
+		if (printk_ratelimit())
+			dev_warn(&adapter->pdev->dev,
+				"failed to set CRB window to %d off 0x%lx\n",
+				window, *off);
 	}
+	adapter->ahw.crb_win = window;
+
+done:
 	*off = (*off & MASK(16)) + CRB_INDIRECT_2M +
 		(ulong)adapter->ahw.pci_base0;
 }
@@ -1178,9 +1170,10 @@ netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data)
 	} else {		/* Window 0 */
 		write_lock_irqsave(&adapter->adapter_lock, flags);
 		addr = pci_base_offset(adapter, off);
-		netxen_nic_pci_change_crbwindow_128M(adapter, 0);
+		netxen_nic_pci_set_crbwindow_128M(adapter, 0);
 		writel(data, addr);
-		netxen_nic_pci_change_crbwindow_128M(adapter, 1);
+		netxen_nic_pci_set_crbwindow_128M(adapter,
+				NETXEN_WINDOW_ONE);
 		write_unlock_irqrestore(&adapter->adapter_lock, flags);
 	}
 
@@ -1207,9 +1200,10 @@ netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off)
 		read_unlock(&adapter->adapter_lock);
 	} else {		/* Window 0 */
 		write_lock_irqsave(&adapter->adapter_lock, flags);
-		netxen_nic_pci_change_crbwindow_128M(adapter, 0);
+		netxen_nic_pci_set_crbwindow_128M(adapter, 0);
 		data = readl(addr);
-		netxen_nic_pci_change_crbwindow_128M(adapter, 1);
+		netxen_nic_pci_set_crbwindow_128M(adapter,
+				NETXEN_WINDOW_ONE);
 		write_unlock_irqrestore(&adapter->adapter_lock, flags);
 	}
 
@@ -1460,7 +1454,7 @@ netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
 
 correct:
 	write_lock_irqsave(&adapter->adapter_lock, flags);
-	netxen_nic_pci_change_crbwindow_128M(adapter, 0);
+	netxen_nic_pci_set_crbwindow_128M(adapter, 0);
 
 	writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
 	writel(off_hi, (mem_crb + addr_hi));
@@ -1484,7 +1478,7 @@ correct:
 	} else
 		ret = 0;
 
-	netxen_nic_pci_change_crbwindow_128M(adapter, 1);
+	netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
 	write_unlock_irqrestore(&adapter->adapter_lock, flags);
 	return ret;
 }
@@ -1539,7 +1533,7 @@ netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
 
 correct:
 	write_lock_irqsave(&adapter->adapter_lock, flags);
-	netxen_nic_pci_change_crbwindow_128M(adapter, 0);
+	netxen_nic_pci_set_crbwindow_128M(adapter, 0);
 
 	writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
 	writel(off_hi, (mem_crb + addr_hi));
@@ -1566,7 +1560,7 @@ correct:
 		ret = 0;
 	}
 
-	netxen_nic_pci_change_crbwindow_128M(adapter, 1);
+	netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
 	write_unlock_irqrestore(&adapter->adapter_lock, flags);
 
 	return ret;
@@ -1664,8 +1658,10 @@ netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
 		goto correct;
 	}
 
-	if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX))
-		return netxen_nic_pci_mem_access_direct(adapter, off, data, 0);
+	if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
+		return netxen_nic_pci_mem_access_direct(adapter,
+				off, data, 0);
+	}
 
 	return -EIO;
 
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index 3e96c5e..2b4c682 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -607,7 +607,7 @@ netxen_setup_pci_map(struct netxen_adapter *adapter)
 	 * Set the CRB window to invalid. If any register in window 0 is
 	 * accessed it should set the window to 0 and then reset it to 1.
 	 */
-	adapter->curr_window = 255;
+	adapter->ahw.crb_win = -1;
 	adapter->ahw.ocm_win = -1;
 
 	/* remap phys address */
@@ -1438,7 +1438,7 @@ netxen_nic_resume(struct pci_dev *pdev)
 	if (err)
 		return err;
 
-	adapter->curr_window = 255;
+	adapter->ahw.crb_win = -1;
 	adapter->ahw.ocm_win = -1;
 
 	err = netxen_start_firmware(adapter);
-- 
1.6.0.2


  parent reply	other threads:[~2009-10-13 15:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-13 15:31 [PATCH 0/5] netxen: add diagnostic tools support Dhananjay Phadke
2009-10-13 15:31 ` [PATCH NEXT 1/5] netxen: remove sub 64-bit mem accesses Dhananjay Phadke
2009-10-13 15:31 ` [PATCH NEXT 2/5] netxen: add access to on chip memory for tools Dhananjay Phadke
2009-10-13 15:31 ` Dhananjay Phadke [this message]
2009-10-13 15:31 ` [PATCH NEXT 4/5] netxen: separate register and memory access lock Dhananjay Phadke
2009-10-13 15:31 ` [PATCH NEXT 5/5] netxen: add sysfs entries for diag tools Dhananjay Phadke
2009-10-13 18:53 ` [PATCH 0/5] netxen: add diagnostic tools support 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=1255447905-29805-4-git-send-email-dhananjay@netxen.com \
    --to=dhananjay@netxen.com \
    --cc=ameen.rahman@qlogic.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.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