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

netxen: refactor indirect register access

Refactor code to calculate and set indirect access
window for control registers in 2MB address space
(NX3031 or newer). Use void __iomem * data type for
absolute pci addresses.
Signed-off-by: default avatarDhananjay Phadke <dhananjay@netxen.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f50330f9
...@@ -1090,39 +1090,33 @@ netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter, ...@@ -1090,39 +1090,33 @@ netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter,
* In: 'off' is offset from base in 128M pci map * In: 'off' is offset from base in 128M pci map
*/ */
static int static int
netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, ulong *off) netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter,
ulong off, void __iomem **addr)
{ {
crb_128M_2M_sub_block_map_t *m; crb_128M_2M_sub_block_map_t *m;
if (*off >= NETXEN_CRB_MAX) if ((off >= NETXEN_CRB_MAX) || (off < NETXEN_PCI_CRBSPACE))
return -EINVAL; return -EINVAL;
if (*off >= NETXEN_PCI_CAMQM && (*off < NETXEN_PCI_CAMQM_2M_END)) { off -= NETXEN_PCI_CRBSPACE;
*off = (*off - NETXEN_PCI_CAMQM) + NETXEN_PCI_CAMQM_2M_BASE +
(ulong)adapter->ahw.pci_base0;
return 0;
}
if (*off < NETXEN_PCI_CRBSPACE)
return -EINVAL;
*off -= NETXEN_PCI_CRBSPACE;
/* /*
* Try direct map * Try direct map
*/ */
m = &crb_128M_2M_map[CRB_BLK(*off)].sub_block[CRB_SUBBLK(*off)]; m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)];
if (m->valid && (m->start_128M <= *off) && (m->end_128M > *off)) { if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) {
*off = *off + m->start_2M - m->start_128M + *addr = adapter->ahw.pci_base0 + m->start_2M +
(ulong)adapter->ahw.pci_base0; (off - m->start_128M);
return 0; return 0;
} }
/* /*
* Not in direct map, use crb window * Not in direct map, use crb window
*/ */
*addr = adapter->ahw.pci_base0 + CRB_INDIRECT_2M +
(off & MASK(16));
return 1; return 1;
} }
...@@ -1132,28 +1126,26 @@ netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, ulong *off) ...@@ -1132,28 +1126,26 @@ netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, ulong *off)
* side effect: lock crb window * side effect: lock crb window
*/ */
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 window; u32 window;
void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M; void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M;
window = CRB_HI(*off); off -= NETXEN_PCI_CRBSPACE;
window = CRB_HI(off);
if (adapter->ahw.crb_win == window) if (adapter->ahw.crb_win == window)
goto done; return;
writel(window, addr); writel(window, addr);
if (readl(addr) != window) { if (readl(addr) != window) {
if (printk_ratelimit()) if (printk_ratelimit())
dev_warn(&adapter->pdev->dev, dev_warn(&adapter->pdev->dev,
"failed to set CRB window to %d off 0x%lx\n", "failed to set CRB window to %d off 0x%lx\n",
window, *off); window, off);
} }
adapter->ahw.crb_win = window; adapter->ahw.crb_win = window;
done:
*off = (*off & MASK(16)) + CRB_INDIRECT_2M +
(ulong)adapter->ahw.pci_base0;
} }
static int static int
...@@ -1217,11 +1209,12 @@ netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data) ...@@ -1217,11 +1209,12 @@ netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data)
{ {
unsigned long flags; unsigned long flags;
int rv; int rv;
void __iomem *addr = NULL;
rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off); rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
if (rv == 0) { if (rv == 0) {
writel(data, (void __iomem *)off); writel(data, addr);
return 0; return 0;
} }
...@@ -1229,8 +1222,8 @@ netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data) ...@@ -1229,8 +1222,8 @@ netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data)
/* indirect access */ /* indirect access */
write_lock_irqsave(&adapter->ahw.crb_lock, flags); write_lock_irqsave(&adapter->ahw.crb_lock, flags);
crb_win_lock(adapter); crb_win_lock(adapter);
netxen_nic_pci_set_crbwindow_2M(adapter, &off); netxen_nic_pci_set_crbwindow_2M(adapter, off);
writel(data, (void __iomem *)off); writel(data, addr);
crb_win_unlock(adapter); crb_win_unlock(adapter);
write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
return 0; return 0;
...@@ -1248,18 +1241,19 @@ netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off) ...@@ -1248,18 +1241,19 @@ netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off)
unsigned long flags; unsigned long flags;
int rv; int rv;
u32 data; u32 data;
void __iomem *addr = NULL;
rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off); rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
if (rv == 0) if (rv == 0)
return readl((void __iomem *)off); return readl(addr);
if (rv > 0) { if (rv > 0) {
/* indirect access */ /* indirect access */
write_lock_irqsave(&adapter->ahw.crb_lock, flags); write_lock_irqsave(&adapter->ahw.crb_lock, flags);
crb_win_lock(adapter); crb_win_lock(adapter);
netxen_nic_pci_set_crbwindow_2M(adapter, &off); netxen_nic_pci_set_crbwindow_2M(adapter, off);
data = readl((void __iomem *)off); data = readl(addr);
crb_win_unlock(adapter); crb_win_unlock(adapter);
write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
return data; return data;
...@@ -1307,17 +1301,20 @@ static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter, ...@@ -1307,17 +1301,20 @@ static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter,
void __iomem * void __iomem *
netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset) netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset)
{ {
ulong off = offset; void __iomem *addr = NULL;
if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
if (offset < NETXEN_CRB_PCIX_HOST2 && if ((offset < NETXEN_CRB_PCIX_HOST2) &&
offset > NETXEN_CRB_PCIX_HOST) (offset > NETXEN_CRB_PCIX_HOST))
return PCI_OFFSET_SECOND_RANGE(adapter, offset); addr = PCI_OFFSET_SECOND_RANGE(adapter, offset);
return NETXEN_CRB_NORMALIZE(adapter, offset); else
addr = NETXEN_CRB_NORMALIZE(adapter, offset);
} else {
WARN_ON(netxen_nic_pci_get_crb_addr_2M(adapter,
offset, &addr));
} }
BUG_ON(netxen_nic_pci_get_crb_addr_2M(adapter, &off)); return addr;
return (void __iomem *)off;
} }
static int static int
......
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