Commit 907fa120 authored by Dhananjay Phadke's avatar Dhananjay Phadke Committed by David S. Miller

netxen: annotate register windowing code

Use common variables crb_win, ocm_win for all revisions of chip.
Signed-off-by: default avatarDhananjay Phadke <dhananjay@netxen.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 47abe356
...@@ -549,7 +549,7 @@ struct netxen_hardware_context { ...@@ -549,7 +549,7 @@ struct netxen_hardware_context {
unsigned long pci_len0; unsigned long pci_len0;
u32 ocm_win; u32 ocm_win;
u32 resv1; u32 crb_win;
u8 cut_through; u8 cut_through;
u8 revision_id; u8 revision_id;
...@@ -1115,8 +1115,6 @@ struct netxen_adapter { ...@@ -1115,8 +1115,6 @@ struct netxen_adapter {
struct pci_dev *pdev; struct pci_dev *pdev;
struct list_head mac_list; struct list_head mac_list;
u32 curr_window;
u32 crb_win;
rwlock_t adapter_lock; rwlock_t adapter_lock;
spinlock_t tx_clean_lock; spinlock_t tx_clean_lock;
......
...@@ -1046,46 +1046,34 @@ int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, __le64 *mac) ...@@ -1046,46 +1046,34 @@ int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, __le64 *mac)
* Changes the CRB window to the specified window. * Changes the CRB window to the specified window.
*/ */
static void 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; void __iomem *offset;
u32 tmp; int count = 10;
int count = 0; u8 func = adapter->ahw.pci_func;
uint8_t func = adapter->ahw.pci_func;
if (adapter->curr_window == wndw) if (adapter->ahw.crb_win == window)
return; 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, offset = PCI_OFFSET_SECOND_RANGE(adapter,
NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func))); NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
if (wndw & 0x1) writel(window, offset);
wndw = NETXEN_WINDOW_ONE; 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 (--count > 0);
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++;
}
if (wndw == NETXEN_WINDOW_ONE) if (count > 0)
adapter->curr_window = 1; adapter->ahw.crb_win = window;
else
adapter->curr_window = 0;
} }
/* /*
...@@ -1140,20 +1128,24 @@ netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, ulong *off) ...@@ -1140,20 +1128,24 @@ netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, ulong *off)
static void static void
netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong *off) 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); window = CRB_HI(*off);
writel(adapter->crb_win, (adapter->ahw.pci_base0 + CRB_WINDOW_2M));
/* if (adapter->ahw.crb_win == window)
* Read back value to make sure write has gone through before trying goto done;
* to use it.
*/ writel(window, addr);
win_read = readl(adapter->ahw.pci_base0 + CRB_WINDOW_2M); if (readl(addr) != window) {
if (win_read != adapter->crb_win) { if (printk_ratelimit())
printk(KERN_ERR "%s: Written crbwin (0x%x) != " dev_warn(&adapter->pdev->dev,
"Read crbwin (0x%x), off=0x%lx\n", "failed to set CRB window to %d off 0x%lx\n",
__func__, adapter->crb_win, win_read, *off); window, *off);
} }
adapter->ahw.crb_win = window;
done:
*off = (*off & MASK(16)) + CRB_INDIRECT_2M + *off = (*off & MASK(16)) + CRB_INDIRECT_2M +
(ulong)adapter->ahw.pci_base0; (ulong)adapter->ahw.pci_base0;
} }
...@@ -1178,9 +1170,10 @@ netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data) ...@@ -1178,9 +1170,10 @@ netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data)
} else { /* Window 0 */ } else { /* Window 0 */
write_lock_irqsave(&adapter->adapter_lock, flags); write_lock_irqsave(&adapter->adapter_lock, flags);
addr = pci_base_offset(adapter, off); 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); 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); write_unlock_irqrestore(&adapter->adapter_lock, flags);
} }
...@@ -1207,9 +1200,10 @@ netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off) ...@@ -1207,9 +1200,10 @@ netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off)
read_unlock(&adapter->adapter_lock); read_unlock(&adapter->adapter_lock);
} else { /* Window 0 */ } else { /* Window 0 */
write_lock_irqsave(&adapter->adapter_lock, flags); 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); 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); write_unlock_irqrestore(&adapter->adapter_lock, flags);
} }
...@@ -1460,7 +1454,7 @@ netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter, ...@@ -1460,7 +1454,7 @@ netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
correct: correct:
write_lock_irqsave(&adapter->adapter_lock, flags); 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_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
writel(off_hi, (mem_crb + addr_hi)); writel(off_hi, (mem_crb + addr_hi));
...@@ -1484,7 +1478,7 @@ netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter, ...@@ -1484,7 +1478,7 @@ netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
} else } else
ret = 0; 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); write_unlock_irqrestore(&adapter->adapter_lock, flags);
return ret; return ret;
} }
...@@ -1539,7 +1533,7 @@ netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter, ...@@ -1539,7 +1533,7 @@ netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
correct: correct:
write_lock_irqsave(&adapter->adapter_lock, flags); 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_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
writel(off_hi, (mem_crb + addr_hi)); writel(off_hi, (mem_crb + addr_hi));
...@@ -1566,7 +1560,7 @@ netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter, ...@@ -1566,7 +1560,7 @@ netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
ret = 0; 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); write_unlock_irqrestore(&adapter->adapter_lock, flags);
return ret; return ret;
...@@ -1664,8 +1658,10 @@ netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter, ...@@ -1664,8 +1658,10 @@ netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
goto correct; goto correct;
} }
if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
return netxen_nic_pci_mem_access_direct(adapter, off, data, 0); return netxen_nic_pci_mem_access_direct(adapter,
off, data, 0);
}
return -EIO; return -EIO;
......
...@@ -606,7 +606,7 @@ netxen_setup_pci_map(struct netxen_adapter *adapter) ...@@ -606,7 +606,7 @@ netxen_setup_pci_map(struct netxen_adapter *adapter)
* Set the CRB window to invalid. If any register in window 0 is * 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. * 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; adapter->ahw.ocm_win = -1;
/* remap phys address */ /* remap phys address */
...@@ -1437,7 +1437,7 @@ netxen_nic_resume(struct pci_dev *pdev) ...@@ -1437,7 +1437,7 @@ netxen_nic_resume(struct pci_dev *pdev)
if (err) if (err)
return err; return err;
adapter->curr_window = 255; adapter->ahw.crb_win = -1;
adapter->ahw.ocm_win = -1; adapter->ahw.ocm_win = -1;
err = netxen_start_firmware(adapter); err = netxen_start_firmware(adapter);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment