diff options
author | Dhananjay Phadke <dhananjay@netxen.com> | 2009-10-24 12:03:59 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-10-28 07:10:17 -0400 |
commit | a9ac07deeb4b880aea3eaccf7ec913ac902aeef9 (patch) | |
tree | c87b51c895df99029557b383446803bd59fc86c2 /drivers/net/netxen/netxen_nic_hw.c | |
parent | f50330f90b9aa42b7058650ce66b85f1b443ab11 (diff) |
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: Dhananjay Phadke <dhananjay@netxen.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/netxen/netxen_nic_hw.c')
-rw-r--r-- | drivers/net/netxen/netxen_nic_hw.c | 75 |
1 files changed, 36 insertions, 39 deletions
diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c index 69205ace16eb..b3054c6cc608 100644 --- a/drivers/net/netxen/netxen_nic_hw.c +++ b/drivers/net/netxen/netxen_nic_hw.c | |||
@@ -1090,39 +1090,33 @@ netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter, | |||
1090 | * In: 'off' is offset from base in 128M pci map | 1090 | * In: 'off' is offset from base in 128M pci map |
1091 | */ | 1091 | */ |
1092 | static int | 1092 | static int |
1093 | netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, ulong *off) | 1093 | netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, |
1094 | ulong off, void __iomem **addr) | ||
1094 | { | 1095 | { |
1095 | crb_128M_2M_sub_block_map_t *m; | 1096 | crb_128M_2M_sub_block_map_t *m; |
1096 | 1097 | ||
1097 | 1098 | ||
1098 | if (*off >= NETXEN_CRB_MAX) | 1099 | if ((off >= NETXEN_CRB_MAX) || (off < NETXEN_PCI_CRBSPACE)) |
1099 | return -EINVAL; | 1100 | return -EINVAL; |
1100 | 1101 | ||
1101 | if (*off >= NETXEN_PCI_CAMQM && (*off < NETXEN_PCI_CAMQM_2M_END)) { | 1102 | off -= NETXEN_PCI_CRBSPACE; |
1102 | *off = (*off - NETXEN_PCI_CAMQM) + NETXEN_PCI_CAMQM_2M_BASE + | ||
1103 | (ulong)adapter->ahw.pci_base0; | ||
1104 | return 0; | ||
1105 | } | ||
1106 | |||
1107 | if (*off < NETXEN_PCI_CRBSPACE) | ||
1108 | return -EINVAL; | ||
1109 | |||
1110 | *off -= NETXEN_PCI_CRBSPACE; | ||
1111 | 1103 | ||
1112 | /* | 1104 | /* |
1113 | * Try direct map | 1105 | * Try direct map |
1114 | */ | 1106 | */ |
1115 | m = &crb_128M_2M_map[CRB_BLK(*off)].sub_block[CRB_SUBBLK(*off)]; | 1107 | m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)]; |
1116 | 1108 | ||
1117 | if (m->valid && (m->start_128M <= *off) && (m->end_128M > *off)) { | 1109 | if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) { |
1118 | *off = *off + m->start_2M - m->start_128M + | 1110 | *addr = adapter->ahw.pci_base0 + m->start_2M + |
1119 | (ulong)adapter->ahw.pci_base0; | 1111 | (off - m->start_128M); |
1120 | return 0; | 1112 | return 0; |
1121 | } | 1113 | } |
1122 | 1114 | ||
1123 | /* | 1115 | /* |
1124 | * Not in direct map, use crb window | 1116 | * Not in direct map, use crb window |
1125 | */ | 1117 | */ |
1118 | *addr = adapter->ahw.pci_base0 + CRB_INDIRECT_2M + | ||
1119 | (off & MASK(16)); | ||
1126 | return 1; | 1120 | return 1; |
1127 | } | 1121 | } |
1128 | 1122 | ||
@@ -1132,28 +1126,26 @@ netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, ulong *off) | |||
1132 | * side effect: lock crb window | 1126 | * side effect: lock crb window |
1133 | */ | 1127 | */ |
1134 | static void | 1128 | static void |
1135 | netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong *off) | 1129 | netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong off) |
1136 | { | 1130 | { |
1137 | u32 window; | 1131 | u32 window; |
1138 | void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M; | 1132 | void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M; |
1139 | 1133 | ||
1140 | window = CRB_HI(*off); | 1134 | off -= NETXEN_PCI_CRBSPACE; |
1135 | |||
1136 | window = CRB_HI(off); | ||
1141 | 1137 | ||
1142 | if (adapter->ahw.crb_win == window) | 1138 | if (adapter->ahw.crb_win == window) |
1143 | goto done; | 1139 | return; |
1144 | 1140 | ||
1145 | writel(window, addr); | 1141 | writel(window, addr); |
1146 | if (readl(addr) != window) { | 1142 | if (readl(addr) != window) { |
1147 | if (printk_ratelimit()) | 1143 | if (printk_ratelimit()) |
1148 | dev_warn(&adapter->pdev->dev, | 1144 | dev_warn(&adapter->pdev->dev, |
1149 | "failed to set CRB window to %d off 0x%lx\n", | 1145 | "failed to set CRB window to %d off 0x%lx\n", |
1150 | window, *off); | 1146 | window, off); |
1151 | } | 1147 | } |
1152 | adapter->ahw.crb_win = window; | 1148 | adapter->ahw.crb_win = window; |
1153 | |||
1154 | done: | ||
1155 | *off = (*off & MASK(16)) + CRB_INDIRECT_2M + | ||
1156 | (ulong)adapter->ahw.pci_base0; | ||
1157 | } | 1149 | } |
1158 | 1150 | ||
1159 | static int | 1151 | static int |
@@ -1217,11 +1209,12 @@ netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data) | |||
1217 | { | 1209 | { |
1218 | unsigned long flags; | 1210 | unsigned long flags; |
1219 | int rv; | 1211 | int rv; |
1212 | void __iomem *addr = NULL; | ||
1220 | 1213 | ||
1221 | rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off); | 1214 | rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr); |
1222 | 1215 | ||
1223 | if (rv == 0) { | 1216 | if (rv == 0) { |
1224 | writel(data, (void __iomem *)off); | 1217 | writel(data, addr); |
1225 | return 0; | 1218 | return 0; |
1226 | } | 1219 | } |
1227 | 1220 | ||
@@ -1229,8 +1222,8 @@ netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data) | |||
1229 | /* indirect access */ | 1222 | /* indirect access */ |
1230 | write_lock_irqsave(&adapter->ahw.crb_lock, flags); | 1223 | write_lock_irqsave(&adapter->ahw.crb_lock, flags); |
1231 | crb_win_lock(adapter); | 1224 | crb_win_lock(adapter); |
1232 | netxen_nic_pci_set_crbwindow_2M(adapter, &off); | 1225 | netxen_nic_pci_set_crbwindow_2M(adapter, off); |
1233 | writel(data, (void __iomem *)off); | 1226 | writel(data, addr); |
1234 | crb_win_unlock(adapter); | 1227 | crb_win_unlock(adapter); |
1235 | write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); | 1228 | write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); |
1236 | return 0; | 1229 | return 0; |
@@ -1248,18 +1241,19 @@ netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off) | |||
1248 | unsigned long flags; | 1241 | unsigned long flags; |
1249 | int rv; | 1242 | int rv; |
1250 | u32 data; | 1243 | u32 data; |
1244 | void __iomem *addr = NULL; | ||
1251 | 1245 | ||
1252 | rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off); | 1246 | rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr); |
1253 | 1247 | ||
1254 | if (rv == 0) | 1248 | if (rv == 0) |
1255 | return readl((void __iomem *)off); | 1249 | return readl(addr); |
1256 | 1250 | ||
1257 | if (rv > 0) { | 1251 | if (rv > 0) { |
1258 | /* indirect access */ | 1252 | /* indirect access */ |
1259 | write_lock_irqsave(&adapter->ahw.crb_lock, flags); | 1253 | write_lock_irqsave(&adapter->ahw.crb_lock, flags); |
1260 | crb_win_lock(adapter); | 1254 | crb_win_lock(adapter); |
1261 | netxen_nic_pci_set_crbwindow_2M(adapter, &off); | 1255 | netxen_nic_pci_set_crbwindow_2M(adapter, off); |
1262 | data = readl((void __iomem *)off); | 1256 | data = readl(addr); |
1263 | crb_win_unlock(adapter); | 1257 | crb_win_unlock(adapter); |
1264 | write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); | 1258 | write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); |
1265 | return data; | 1259 | return data; |
@@ -1307,17 +1301,20 @@ static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter, | |||
1307 | void __iomem * | 1301 | void __iomem * |
1308 | netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset) | 1302 | netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset) |
1309 | { | 1303 | { |
1310 | ulong off = offset; | 1304 | void __iomem *addr = NULL; |
1311 | 1305 | ||
1312 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | 1306 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
1313 | if (offset < NETXEN_CRB_PCIX_HOST2 && | 1307 | if ((offset < NETXEN_CRB_PCIX_HOST2) && |
1314 | offset > NETXEN_CRB_PCIX_HOST) | 1308 | (offset > NETXEN_CRB_PCIX_HOST)) |
1315 | return PCI_OFFSET_SECOND_RANGE(adapter, offset); | 1309 | addr = PCI_OFFSET_SECOND_RANGE(adapter, offset); |
1316 | return NETXEN_CRB_NORMALIZE(adapter, offset); | 1310 | else |
1311 | addr = NETXEN_CRB_NORMALIZE(adapter, offset); | ||
1312 | } else { | ||
1313 | WARN_ON(netxen_nic_pci_get_crb_addr_2M(adapter, | ||
1314 | offset, &addr)); | ||
1317 | } | 1315 | } |
1318 | 1316 | ||
1319 | BUG_ON(netxen_nic_pci_get_crb_addr_2M(adapter, &off)); | 1317 | return addr; |
1320 | return (void __iomem *)off; | ||
1321 | } | 1318 | } |
1322 | 1319 | ||
1323 | static int | 1320 | static int |