]>
Commit | Line | Data |
---|---|---|
3d396eb1 | 1 | /* |
5d242f1c | 2 | * Copyright (C) 2003 - 2009 NetXen, Inc. |
13af7a6e | 3 | * Copyright (C) 2009 - QLogic Corporation. |
3d396eb1 | 4 | * All rights reserved. |
80922fbc | 5 | * |
3d396eb1 AK |
6 | * This program is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version 2 | |
9 | * of the License, or (at your option) any later version. | |
cb8011ad | 10 | * |
3d396eb1 AK |
11 | * This program is distributed in the hope that it will be useful, but |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
cb8011ad | 15 | * |
3d396eb1 AK |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |
19 | * MA 02111-1307, USA. | |
80922fbc | 20 | * |
3d396eb1 | 21 | * The full GNU General Public License is included in this distribution |
4d21fef4 | 22 | * in the file called "COPYING". |
80922fbc | 23 | * |
3d396eb1 AK |
24 | */ |
25 | ||
5a0e3ad6 | 26 | #include <linux/slab.h> |
3d396eb1 AK |
27 | #include "netxen_nic.h" |
28 | #include "netxen_nic_hw.h" | |
3d396eb1 | 29 | |
c9bdd4b5 ACM |
30 | #include <net/ip.h> |
31 | ||
3ce06a32 DP |
32 | #define MASK(n) ((1ULL<<(n))-1) |
33 | #define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff)) | |
34 | #define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff)) | |
35 | #define MS_WIN(addr) (addr & 0x0ffc0000) | |
36 | ||
37 | #define GET_MEM_OFFS_2M(addr) (addr & MASK(18)) | |
38 | ||
39 | #define CRB_BLK(off) ((off >> 20) & 0x3f) | |
40 | #define CRB_SUBBLK(off) ((off >> 16) & 0xf) | |
41 | #define CRB_WINDOW_2M (0x130060) | |
42 | #define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000)) | |
43 | #define CRB_INDIRECT_2M (0x1e0000UL) | |
44 | ||
f03b0ebd DP |
45 | static void netxen_nic_io_write_128M(struct netxen_adapter *adapter, |
46 | void __iomem *addr, u32 data); | |
47 | static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter, | |
48 | void __iomem *addr); | |
49 | ||
e98e3350 DP |
50 | #ifndef readq |
51 | static inline u64 readq(void __iomem *addr) | |
52 | { | |
53 | return readl(addr) | (((u64) readl(addr + 4)) << 32LL); | |
54 | } | |
55 | #endif | |
56 | ||
57 | #ifndef writeq | |
58 | static inline void writeq(u64 val, void __iomem *addr) | |
59 | { | |
60 | writel(((u32) (val)), (addr)); | |
61 | writel(((u32) (val >> 32)), (addr + 4)); | |
62 | } | |
63 | #endif | |
64 | ||
1fbe6323 DP |
65 | #define PCI_OFFSET_FIRST_RANGE(adapter, off) \ |
66 | ((adapter)->ahw.pci_base0 + (off)) | |
67 | #define PCI_OFFSET_SECOND_RANGE(adapter, off) \ | |
68 | ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START) | |
69 | #define PCI_OFFSET_THIRD_RANGE(adapter, off) \ | |
70 | ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START) | |
71 | ||
72 | static void __iomem *pci_base_offset(struct netxen_adapter *adapter, | |
73 | unsigned long off) | |
74 | { | |
75 | if (ADDR_IN_RANGE(off, FIRST_PAGE_GROUP_START, FIRST_PAGE_GROUP_END)) | |
76 | return PCI_OFFSET_FIRST_RANGE(adapter, off); | |
77 | ||
78 | if (ADDR_IN_RANGE(off, SECOND_PAGE_GROUP_START, SECOND_PAGE_GROUP_END)) | |
79 | return PCI_OFFSET_SECOND_RANGE(adapter, off); | |
80 | ||
81 | if (ADDR_IN_RANGE(off, THIRD_PAGE_GROUP_START, THIRD_PAGE_GROUP_END)) | |
82 | return PCI_OFFSET_THIRD_RANGE(adapter, off); | |
83 | ||
84 | return NULL; | |
85 | } | |
86 | ||
ea7eaa39 DP |
87 | static crb_128M_2M_block_map_t |
88 | crb_128M_2M_map[64] __cacheline_aligned_in_smp = { | |
3ce06a32 DP |
89 | {{{0, 0, 0, 0} } }, /* 0: PCI */ |
90 | {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */ | |
91 | {1, 0x0110000, 0x0120000, 0x130000}, | |
92 | {1, 0x0120000, 0x0122000, 0x124000}, | |
93 | {1, 0x0130000, 0x0132000, 0x126000}, | |
94 | {1, 0x0140000, 0x0142000, 0x128000}, | |
95 | {1, 0x0150000, 0x0152000, 0x12a000}, | |
96 | {1, 0x0160000, 0x0170000, 0x110000}, | |
97 | {1, 0x0170000, 0x0172000, 0x12e000}, | |
98 | {0, 0x0000000, 0x0000000, 0x000000}, | |
99 | {0, 0x0000000, 0x0000000, 0x000000}, | |
100 | {0, 0x0000000, 0x0000000, 0x000000}, | |
101 | {0, 0x0000000, 0x0000000, 0x000000}, | |
102 | {0, 0x0000000, 0x0000000, 0x000000}, | |
103 | {0, 0x0000000, 0x0000000, 0x000000}, | |
104 | {1, 0x01e0000, 0x01e0800, 0x122000}, | |
105 | {0, 0x0000000, 0x0000000, 0x000000} } }, | |
106 | {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */ | |
107 | {{{0, 0, 0, 0} } }, /* 3: */ | |
108 | {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */ | |
109 | {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */ | |
110 | {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */ | |
111 | {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */ | |
112 | {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */ | |
113 | {0, 0x0000000, 0x0000000, 0x000000}, | |
114 | {0, 0x0000000, 0x0000000, 0x000000}, | |
115 | {0, 0x0000000, 0x0000000, 0x000000}, | |
116 | {0, 0x0000000, 0x0000000, 0x000000}, | |
117 | {0, 0x0000000, 0x0000000, 0x000000}, | |
118 | {0, 0x0000000, 0x0000000, 0x000000}, | |
119 | {0, 0x0000000, 0x0000000, 0x000000}, | |
120 | {0, 0x0000000, 0x0000000, 0x000000}, | |
121 | {0, 0x0000000, 0x0000000, 0x000000}, | |
122 | {0, 0x0000000, 0x0000000, 0x000000}, | |
123 | {0, 0x0000000, 0x0000000, 0x000000}, | |
124 | {0, 0x0000000, 0x0000000, 0x000000}, | |
125 | {0, 0x0000000, 0x0000000, 0x000000}, | |
126 | {0, 0x0000000, 0x0000000, 0x000000}, | |
127 | {1, 0x08f0000, 0x08f2000, 0x172000} } }, | |
128 | {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/ | |
129 | {0, 0x0000000, 0x0000000, 0x000000}, | |
130 | {0, 0x0000000, 0x0000000, 0x000000}, | |
131 | {0, 0x0000000, 0x0000000, 0x000000}, | |
132 | {0, 0x0000000, 0x0000000, 0x000000}, | |
133 | {0, 0x0000000, 0x0000000, 0x000000}, | |
134 | {0, 0x0000000, 0x0000000, 0x000000}, | |
135 | {0, 0x0000000, 0x0000000, 0x000000}, | |
136 | {0, 0x0000000, 0x0000000, 0x000000}, | |
137 | {0, 0x0000000, 0x0000000, 0x000000}, | |
138 | {0, 0x0000000, 0x0000000, 0x000000}, | |
139 | {0, 0x0000000, 0x0000000, 0x000000}, | |
140 | {0, 0x0000000, 0x0000000, 0x000000}, | |
141 | {0, 0x0000000, 0x0000000, 0x000000}, | |
142 | {0, 0x0000000, 0x0000000, 0x000000}, | |
143 | {1, 0x09f0000, 0x09f2000, 0x176000} } }, | |
144 | {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/ | |
145 | {0, 0x0000000, 0x0000000, 0x000000}, | |
146 | {0, 0x0000000, 0x0000000, 0x000000}, | |
147 | {0, 0x0000000, 0x0000000, 0x000000}, | |
148 | {0, 0x0000000, 0x0000000, 0x000000}, | |
149 | {0, 0x0000000, 0x0000000, 0x000000}, | |
150 | {0, 0x0000000, 0x0000000, 0x000000}, | |
151 | {0, 0x0000000, 0x0000000, 0x000000}, | |
152 | {0, 0x0000000, 0x0000000, 0x000000}, | |
153 | {0, 0x0000000, 0x0000000, 0x000000}, | |
154 | {0, 0x0000000, 0x0000000, 0x000000}, | |
155 | {0, 0x0000000, 0x0000000, 0x000000}, | |
156 | {0, 0x0000000, 0x0000000, 0x000000}, | |
157 | {0, 0x0000000, 0x0000000, 0x000000}, | |
158 | {0, 0x0000000, 0x0000000, 0x000000}, | |
159 | {1, 0x0af0000, 0x0af2000, 0x17a000} } }, | |
160 | {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/ | |
161 | {0, 0x0000000, 0x0000000, 0x000000}, | |
162 | {0, 0x0000000, 0x0000000, 0x000000}, | |
163 | {0, 0x0000000, 0x0000000, 0x000000}, | |
164 | {0, 0x0000000, 0x0000000, 0x000000}, | |
165 | {0, 0x0000000, 0x0000000, 0x000000}, | |
166 | {0, 0x0000000, 0x0000000, 0x000000}, | |
167 | {0, 0x0000000, 0x0000000, 0x000000}, | |
168 | {0, 0x0000000, 0x0000000, 0x000000}, | |
169 | {0, 0x0000000, 0x0000000, 0x000000}, | |
170 | {0, 0x0000000, 0x0000000, 0x000000}, | |
171 | {0, 0x0000000, 0x0000000, 0x000000}, | |
172 | {0, 0x0000000, 0x0000000, 0x000000}, | |
173 | {0, 0x0000000, 0x0000000, 0x000000}, | |
174 | {0, 0x0000000, 0x0000000, 0x000000}, | |
175 | {1, 0x0bf0000, 0x0bf2000, 0x17e000} } }, | |
176 | {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */ | |
177 | {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */ | |
178 | {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */ | |
179 | {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */ | |
180 | {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */ | |
181 | {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */ | |
182 | {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */ | |
183 | {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */ | |
184 | {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */ | |
185 | {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */ | |
186 | {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */ | |
187 | {{{0, 0, 0, 0} } }, /* 23: */ | |
188 | {{{0, 0, 0, 0} } }, /* 24: */ | |
189 | {{{0, 0, 0, 0} } }, /* 25: */ | |
190 | {{{0, 0, 0, 0} } }, /* 26: */ | |
191 | {{{0, 0, 0, 0} } }, /* 27: */ | |
192 | {{{0, 0, 0, 0} } }, /* 28: */ | |
193 | {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */ | |
194 | {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */ | |
195 | {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */ | |
196 | {{{0} } }, /* 32: PCI */ | |
197 | {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */ | |
198 | {1, 0x2110000, 0x2120000, 0x130000}, | |
199 | {1, 0x2120000, 0x2122000, 0x124000}, | |
200 | {1, 0x2130000, 0x2132000, 0x126000}, | |
201 | {1, 0x2140000, 0x2142000, 0x128000}, | |
202 | {1, 0x2150000, 0x2152000, 0x12a000}, | |
203 | {1, 0x2160000, 0x2170000, 0x110000}, | |
204 | {1, 0x2170000, 0x2172000, 0x12e000}, | |
205 | {0, 0x0000000, 0x0000000, 0x000000}, | |
206 | {0, 0x0000000, 0x0000000, 0x000000}, | |
207 | {0, 0x0000000, 0x0000000, 0x000000}, | |
208 | {0, 0x0000000, 0x0000000, 0x000000}, | |
209 | {0, 0x0000000, 0x0000000, 0x000000}, | |
210 | {0, 0x0000000, 0x0000000, 0x000000}, | |
211 | {0, 0x0000000, 0x0000000, 0x000000}, | |
212 | {0, 0x0000000, 0x0000000, 0x000000} } }, | |
213 | {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */ | |
214 | {{{0} } }, /* 35: */ | |
215 | {{{0} } }, /* 36: */ | |
216 | {{{0} } }, /* 37: */ | |
217 | {{{0} } }, /* 38: */ | |
218 | {{{0} } }, /* 39: */ | |
219 | {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */ | |
220 | {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */ | |
221 | {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */ | |
222 | {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */ | |
223 | {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */ | |
224 | {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */ | |
225 | {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */ | |
226 | {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */ | |
227 | {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */ | |
228 | {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */ | |
229 | {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */ | |
230 | {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */ | |
231 | {{{0} } }, /* 52: */ | |
232 | {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */ | |
233 | {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */ | |
234 | {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */ | |
235 | {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */ | |
236 | {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */ | |
237 | {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */ | |
238 | {{{0} } }, /* 59: I2C0 */ | |
239 | {{{0} } }, /* 60: I2C1 */ | |
240 | {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */ | |
241 | {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */ | |
242 | {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */ | |
243 | }; | |
244 | ||
245 | /* | |
246 | * top 12 bits of crb internal address (hub, agent) | |
247 | */ | |
248 | static unsigned crb_hub_agt[64] = | |
249 | { | |
250 | 0, | |
251 | NETXEN_HW_CRB_HUB_AGT_ADR_PS, | |
252 | NETXEN_HW_CRB_HUB_AGT_ADR_MN, | |
253 | NETXEN_HW_CRB_HUB_AGT_ADR_MS, | |
254 | 0, | |
255 | NETXEN_HW_CRB_HUB_AGT_ADR_SRE, | |
256 | NETXEN_HW_CRB_HUB_AGT_ADR_NIU, | |
257 | NETXEN_HW_CRB_HUB_AGT_ADR_QMN, | |
258 | NETXEN_HW_CRB_HUB_AGT_ADR_SQN0, | |
259 | NETXEN_HW_CRB_HUB_AGT_ADR_SQN1, | |
260 | NETXEN_HW_CRB_HUB_AGT_ADR_SQN2, | |
261 | NETXEN_HW_CRB_HUB_AGT_ADR_SQN3, | |
262 | NETXEN_HW_CRB_HUB_AGT_ADR_I2Q, | |
263 | NETXEN_HW_CRB_HUB_AGT_ADR_TIMR, | |
264 | NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB, | |
265 | NETXEN_HW_CRB_HUB_AGT_ADR_PGN4, | |
266 | NETXEN_HW_CRB_HUB_AGT_ADR_XDMA, | |
267 | NETXEN_HW_CRB_HUB_AGT_ADR_PGN0, | |
268 | NETXEN_HW_CRB_HUB_AGT_ADR_PGN1, | |
269 | NETXEN_HW_CRB_HUB_AGT_ADR_PGN2, | |
270 | NETXEN_HW_CRB_HUB_AGT_ADR_PGN3, | |
271 | NETXEN_HW_CRB_HUB_AGT_ADR_PGND, | |
272 | NETXEN_HW_CRB_HUB_AGT_ADR_PGNI, | |
273 | NETXEN_HW_CRB_HUB_AGT_ADR_PGS0, | |
274 | NETXEN_HW_CRB_HUB_AGT_ADR_PGS1, | |
275 | NETXEN_HW_CRB_HUB_AGT_ADR_PGS2, | |
276 | NETXEN_HW_CRB_HUB_AGT_ADR_PGS3, | |
277 | 0, | |
278 | NETXEN_HW_CRB_HUB_AGT_ADR_PGSI, | |
279 | NETXEN_HW_CRB_HUB_AGT_ADR_SN, | |
280 | 0, | |
281 | NETXEN_HW_CRB_HUB_AGT_ADR_EG, | |
282 | 0, | |
283 | NETXEN_HW_CRB_HUB_AGT_ADR_PS, | |
284 | NETXEN_HW_CRB_HUB_AGT_ADR_CAM, | |
285 | 0, | |
286 | 0, | |
287 | 0, | |
288 | 0, | |
289 | 0, | |
290 | NETXEN_HW_CRB_HUB_AGT_ADR_TIMR, | |
291 | 0, | |
292 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1, | |
293 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2, | |
294 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3, | |
295 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4, | |
296 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5, | |
297 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6, | |
298 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7, | |
299 | NETXEN_HW_CRB_HUB_AGT_ADR_XDMA, | |
300 | NETXEN_HW_CRB_HUB_AGT_ADR_I2Q, | |
301 | NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB, | |
302 | 0, | |
303 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0, | |
304 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8, | |
305 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9, | |
306 | NETXEN_HW_CRB_HUB_AGT_ADR_OCM0, | |
307 | 0, | |
308 | NETXEN_HW_CRB_HUB_AGT_ADR_SMB, | |
309 | NETXEN_HW_CRB_HUB_AGT_ADR_I2C0, | |
310 | NETXEN_HW_CRB_HUB_AGT_ADR_I2C1, | |
311 | 0, | |
312 | NETXEN_HW_CRB_HUB_AGT_ADR_PGNC, | |
313 | 0, | |
314 | }; | |
315 | ||
3d396eb1 AK |
316 | /* PCI Windowing for DDR regions. */ |
317 | ||
3ce06a32 | 318 | #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */ |
3d396eb1 | 319 | |
c9517e58 DP |
320 | #define NETXEN_PCIE_SEM_TIMEOUT 10000 |
321 | ||
322 | int | |
323 | netxen_pcie_sem_lock(struct netxen_adapter *adapter, int sem, u32 id_reg) | |
324 | { | |
325 | int done = 0, timeout = 0; | |
326 | ||
327 | while (!done) { | |
328 | done = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_LOCK(sem))); | |
329 | if (done == 1) | |
330 | break; | |
331 | if (++timeout >= NETXEN_PCIE_SEM_TIMEOUT) | |
7cecdca1 | 332 | return -EIO; |
c9517e58 DP |
333 | msleep(1); |
334 | } | |
335 | ||
336 | if (id_reg) | |
337 | NXWR32(adapter, id_reg, adapter->portnum); | |
338 | ||
339 | return 0; | |
340 | } | |
341 | ||
342 | void | |
343 | netxen_pcie_sem_unlock(struct netxen_adapter *adapter, int sem) | |
344 | { | |
581e8ae4 | 345 | NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_UNLOCK(sem))); |
c9517e58 DP |
346 | } |
347 | ||
3ad4467c DP |
348 | int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port) |
349 | { | |
350 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | |
351 | NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_1+(0x10000*port), 0x1447); | |
352 | NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0+(0x10000*port), 0x5); | |
353 | } | |
354 | ||
355 | return 0; | |
356 | } | |
357 | ||
358 | /* Disable an XG interface */ | |
359 | int netxen_niu_disable_xg_port(struct netxen_adapter *adapter) | |
360 | { | |
361 | __u32 mac_cfg; | |
362 | u32 port = adapter->physical_port; | |
363 | ||
364 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | |
365 | return 0; | |
366 | ||
367 | if (port > NETXEN_NIU_MAX_XG_PORTS) | |
368 | return -EINVAL; | |
369 | ||
370 | mac_cfg = 0; | |
371 | if (NXWR32(adapter, | |
372 | NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg)) | |
373 | return -EIO; | |
374 | return 0; | |
375 | } | |
376 | ||
623621b0 DP |
377 | #define NETXEN_UNICAST_ADDR(port, index) \ |
378 | (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8)) | |
379 | #define NETXEN_MCAST_ADDR(port, index) \ | |
380 | (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8)) | |
381 | #define MAC_HI(addr) \ | |
382 | ((addr[2] << 16) | (addr[1] << 8) | (addr[0])) | |
383 | #define MAC_LO(addr) \ | |
384 | ((addr[5] << 16) | (addr[4] << 8) | (addr[3])) | |
385 | ||
3ad4467c DP |
386 | int netxen_p2_nic_set_promisc(struct netxen_adapter *adapter, u32 mode) |
387 | { | |
a7483b0a NK |
388 | u32 mac_cfg; |
389 | u32 cnt = 0; | |
390 | __u32 reg = 0x0200; | |
3ad4467c | 391 | u32 port = adapter->physical_port; |
a7483b0a | 392 | u16 board_type = adapter->ahw.board_type; |
3ad4467c DP |
393 | |
394 | if (port > NETXEN_NIU_MAX_XG_PORTS) | |
395 | return -EINVAL; | |
396 | ||
a7483b0a NK |
397 | mac_cfg = NXRD32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port)); |
398 | mac_cfg &= ~0x4; | |
399 | NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg); | |
3ad4467c | 400 | |
a7483b0a NK |
401 | if ((board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) || |
402 | (board_type == NETXEN_BRDTYPE_P2_SB31_10G_HMEZ)) | |
403 | reg = (0x20 << port); | |
3ad4467c | 404 | |
a7483b0a NK |
405 | NXWR32(adapter, NETXEN_NIU_FRAME_COUNT_SELECT, reg); |
406 | ||
407 | mdelay(10); | |
408 | ||
409 | while (NXRD32(adapter, NETXEN_NIU_FRAME_COUNT) && ++cnt < 20) | |
410 | mdelay(10); | |
411 | ||
412 | if (cnt < 20) { | |
413 | ||
414 | reg = NXRD32(adapter, | |
415 | NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port)); | |
416 | ||
417 | if (mode == NETXEN_NIU_PROMISC_MODE) | |
418 | reg = (reg | 0x2000UL); | |
419 | else | |
420 | reg = (reg & ~0x2000UL); | |
421 | ||
422 | if (mode == NETXEN_NIU_ALLMULTI_MODE) | |
423 | reg = (reg | 0x1000UL); | |
424 | else | |
425 | reg = (reg & ~0x1000UL); | |
426 | ||
427 | NXWR32(adapter, | |
428 | NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), reg); | |
429 | } | |
430 | ||
431 | mac_cfg |= 0x4; | |
432 | NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg); | |
3ad4467c DP |
433 | |
434 | return 0; | |
435 | } | |
436 | ||
437 | int netxen_p2_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr) | |
438 | { | |
439 | u32 mac_hi, mac_lo; | |
440 | u32 reg_hi, reg_lo; | |
441 | ||
442 | u8 phy = adapter->physical_port; | |
443 | ||
444 | if (phy >= NETXEN_NIU_MAX_XG_PORTS) | |
445 | return -EINVAL; | |
446 | ||
447 | mac_lo = ((u32)addr[0] << 16) | ((u32)addr[1] << 24); | |
448 | mac_hi = addr[2] | ((u32)addr[3] << 8) | | |
449 | ((u32)addr[4] << 16) | ((u32)addr[5] << 24); | |
450 | ||
451 | reg_lo = NETXEN_NIU_XGE_STATION_ADDR_0_1 + (0x10000 * phy); | |
452 | reg_hi = NETXEN_NIU_XGE_STATION_ADDR_0_HI + (0x10000 * phy); | |
453 | ||
454 | /* write twice to flush */ | |
455 | if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi)) | |
456 | return -EIO; | |
457 | if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi)) | |
458 | return -EIO; | |
459 | ||
460 | return 0; | |
461 | } | |
462 | ||
623621b0 DP |
463 | static int |
464 | netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter) | |
465 | { | |
466 | u32 val = 0; | |
467 | u16 port = adapter->physical_port; | |
5d09e534 | 468 | u8 *addr = adapter->mac_addr; |
623621b0 DP |
469 | |
470 | if (adapter->mc_enabled) | |
471 | return 0; | |
472 | ||
f98a9f69 | 473 | val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG); |
623621b0 | 474 | val |= (1UL << (28+port)); |
f98a9f69 | 475 | NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val); |
623621b0 DP |
476 | |
477 | /* add broadcast addr to filter */ | |
478 | val = 0xffffff; | |
f98a9f69 DP |
479 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val); |
480 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val); | |
623621b0 DP |
481 | |
482 | /* add station addr to filter */ | |
483 | val = MAC_HI(addr); | |
f98a9f69 | 484 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), val); |
623621b0 | 485 | val = MAC_LO(addr); |
f98a9f69 | 486 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, val); |
623621b0 DP |
487 | |
488 | adapter->mc_enabled = 1; | |
489 | return 0; | |
490 | } | |
491 | ||
492 | static int | |
493 | netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter) | |
494 | { | |
495 | u32 val = 0; | |
496 | u16 port = adapter->physical_port; | |
5d09e534 | 497 | u8 *addr = adapter->mac_addr; |
623621b0 DP |
498 | |
499 | if (!adapter->mc_enabled) | |
500 | return 0; | |
501 | ||
f98a9f69 | 502 | val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG); |
623621b0 | 503 | val &= ~(1UL << (28+port)); |
f98a9f69 | 504 | NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val); |
623621b0 DP |
505 | |
506 | val = MAC_HI(addr); | |
f98a9f69 | 507 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val); |
623621b0 | 508 | val = MAC_LO(addr); |
f98a9f69 | 509 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val); |
623621b0 | 510 | |
f98a9f69 DP |
511 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), 0); |
512 | NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0); | |
623621b0 DP |
513 | |
514 | adapter->mc_enabled = 0; | |
515 | return 0; | |
516 | } | |
517 | ||
518 | static int | |
519 | netxen_nic_set_mcast_addr(struct netxen_adapter *adapter, | |
520 | int index, u8 *addr) | |
521 | { | |
522 | u32 hi = 0, lo = 0; | |
523 | u16 port = adapter->physical_port; | |
524 | ||
525 | lo = MAC_LO(addr); | |
526 | hi = MAC_HI(addr); | |
527 | ||
f98a9f69 DP |
528 | NXWR32(adapter, NETXEN_MCAST_ADDR(port, index), hi); |
529 | NXWR32(adapter, NETXEN_MCAST_ADDR(port, index)+4, lo); | |
623621b0 DP |
530 | |
531 | return 0; | |
532 | } | |
533 | ||
c9fc891f | 534 | void netxen_p2_nic_set_multi(struct net_device *netdev) |
3d396eb1 | 535 | { |
3176ff3e | 536 | struct netxen_adapter *adapter = netdev_priv(netdev); |
22bedad3 | 537 | struct netdev_hw_addr *ha; |
623621b0 | 538 | u8 null_addr[6]; |
f9dcbcc9 | 539 | int i; |
623621b0 DP |
540 | |
541 | memset(null_addr, 0, 6); | |
3d396eb1 | 542 | |
3d396eb1 | 543 | if (netdev->flags & IFF_PROMISC) { |
623621b0 DP |
544 | |
545 | adapter->set_promisc(adapter, | |
546 | NETXEN_NIU_PROMISC_MODE); | |
547 | ||
548 | /* Full promiscuous mode */ | |
549 | netxen_nic_disable_mcast_filter(adapter); | |
550 | ||
551 | return; | |
552 | } | |
553 | ||
4cd24eaf | 554 | if (netdev_mc_empty(netdev)) { |
623621b0 DP |
555 | adapter->set_promisc(adapter, |
556 | NETXEN_NIU_NON_PROMISC_MODE); | |
557 | netxen_nic_disable_mcast_filter(adapter); | |
558 | return; | |
559 | } | |
560 | ||
561 | adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE); | |
562 | if (netdev->flags & IFF_ALLMULTI || | |
4cd24eaf | 563 | netdev_mc_count(netdev) > adapter->max_mc_count) { |
623621b0 DP |
564 | netxen_nic_disable_mcast_filter(adapter); |
565 | return; | |
3d396eb1 | 566 | } |
623621b0 DP |
567 | |
568 | netxen_nic_enable_mcast_filter(adapter); | |
569 | ||
f9dcbcc9 | 570 | i = 0; |
22bedad3 JP |
571 | netdev_for_each_mc_addr(ha, netdev) |
572 | netxen_nic_set_mcast_addr(adapter, i++, ha->addr); | |
623621b0 DP |
573 | |
574 | /* Clear out remaining addresses */ | |
f9dcbcc9 JP |
575 | while (i < adapter->max_mc_count) |
576 | netxen_nic_set_mcast_addr(adapter, i++, null_addr); | |
3d396eb1 AK |
577 | } |
578 | ||
c9fc891f DP |
579 | static int |
580 | netxen_send_cmd_descs(struct netxen_adapter *adapter, | |
d877f1e3 | 581 | struct cmd_desc_type0 *cmd_desc_arr, int nr_desc) |
c9fc891f | 582 | { |
d877f1e3 | 583 | u32 i, producer, consumer; |
c9fc891f DP |
584 | struct netxen_cmd_buffer *pbuf; |
585 | struct cmd_desc_type0 *cmd_desc; | |
d877f1e3 | 586 | struct nx_host_tx_ring *tx_ring; |
c9fc891f DP |
587 | |
588 | i = 0; | |
589 | ||
db4cfd8a DP |
590 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) |
591 | return -EIO; | |
592 | ||
4ea528a1 | 593 | tx_ring = adapter->tx_ring; |
b2af9cb0 | 594 | __netif_tx_lock_bh(tx_ring->txq); |
03e678ee | 595 | |
d877f1e3 DP |
596 | producer = tx_ring->producer; |
597 | consumer = tx_ring->sw_consumer; | |
598 | ||
b2af9cb0 DP |
599 | if (nr_desc >= netxen_tx_avail(tx_ring)) { |
600 | netif_tx_stop_queue(tx_ring->txq); | |
601 | __netif_tx_unlock_bh(tx_ring->txq); | |
d877f1e3 DP |
602 | return -EBUSY; |
603 | } | |
604 | ||
c9fc891f DP |
605 | do { |
606 | cmd_desc = &cmd_desc_arr[i]; | |
607 | ||
d877f1e3 | 608 | pbuf = &tx_ring->cmd_buf_arr[producer]; |
c9fc891f | 609 | pbuf->skb = NULL; |
c9fc891f | 610 | pbuf->frag_count = 0; |
c9fc891f | 611 | |
d877f1e3 | 612 | memcpy(&tx_ring->desc_head[producer], |
c9fc891f DP |
613 | &cmd_desc_arr[i], sizeof(struct cmd_desc_type0)); |
614 | ||
d877f1e3 | 615 | producer = get_next_index(producer, tx_ring->num_desc); |
c9fc891f DP |
616 | i++; |
617 | ||
d877f1e3 | 618 | } while (i != nr_desc); |
c9fc891f | 619 | |
d877f1e3 | 620 | tx_ring->producer = producer; |
c9fc891f | 621 | |
cb2107be | 622 | netxen_nic_update_cmd_producer(adapter, tx_ring); |
c9fc891f | 623 | |
b2af9cb0 | 624 | __netif_tx_unlock_bh(tx_ring->txq); |
03e678ee | 625 | |
c9fc891f DP |
626 | return 0; |
627 | } | |
628 | ||
5cf4d323 DP |
629 | static int |
630 | nx_p3_sre_macaddr_change(struct netxen_adapter *adapter, u8 *addr, unsigned op) | |
c9fc891f | 631 | { |
c9fc891f | 632 | nx_nic_req_t req; |
2edbb454 DP |
633 | nx_mac_req_t *mac_req; |
634 | u64 word; | |
c9fc891f DP |
635 | |
636 | memset(&req, 0, sizeof(nx_nic_req_t)); | |
2edbb454 DP |
637 | req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23); |
638 | ||
639 | word = NX_MAC_EVENT | ((u64)adapter->portnum << 16); | |
640 | req.req_hdr = cpu_to_le64(word); | |
641 | ||
642 | mac_req = (nx_mac_req_t *)&req.words[0]; | |
643 | mac_req->op = op; | |
644 | memcpy(mac_req->mac_addr, addr, 6); | |
c9fc891f | 645 | |
5cf4d323 DP |
646 | return netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); |
647 | } | |
648 | ||
649 | static int nx_p3_nic_add_mac(struct netxen_adapter *adapter, | |
650 | u8 *addr, struct list_head *del_list) | |
651 | { | |
652 | struct list_head *head; | |
653 | nx_mac_list_t *cur; | |
654 | ||
655 | /* look up if already exists */ | |
656 | list_for_each(head, del_list) { | |
657 | cur = list_entry(head, nx_mac_list_t, list); | |
658 | ||
659 | if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) { | |
660 | list_move_tail(head, &adapter->mac_list); | |
661 | return 0; | |
662 | } | |
c9fc891f DP |
663 | } |
664 | ||
5cf4d323 DP |
665 | cur = kzalloc(sizeof(nx_mac_list_t), GFP_ATOMIC); |
666 | if (cur == NULL) { | |
667 | printk(KERN_ERR "%s: failed to add mac address filter\n", | |
668 | adapter->netdev->name); | |
669 | return -ENOMEM; | |
670 | } | |
671 | memcpy(cur->mac_addr, addr, ETH_ALEN); | |
672 | list_add_tail(&cur->list, &adapter->mac_list); | |
673 | return nx_p3_sre_macaddr_change(adapter, | |
674 | cur->mac_addr, NETXEN_MAC_ADD); | |
c9fc891f DP |
675 | } |
676 | ||
677 | void netxen_p3_nic_set_multi(struct net_device *netdev) | |
678 | { | |
679 | struct netxen_adapter *adapter = netdev_priv(netdev); | |
22bedad3 | 680 | struct netdev_hw_addr *ha; |
c9fc891f | 681 | u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
9ad27643 | 682 | u32 mode = VPORT_MISS_MODE_DROP; |
5cf4d323 DP |
683 | LIST_HEAD(del_list); |
684 | struct list_head *head; | |
685 | nx_mac_list_t *cur; | |
c9fc891f | 686 | |
d49c9640 AKS |
687 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) |
688 | return; | |
689 | ||
5cf4d323 | 690 | list_splice_tail_init(&adapter->mac_list, &del_list); |
c9fc891f | 691 | |
5d09e534 | 692 | nx_p3_nic_add_mac(adapter, adapter->mac_addr, &del_list); |
5cf4d323 | 693 | nx_p3_nic_add_mac(adapter, bcast_addr, &del_list); |
9ad27643 DP |
694 | |
695 | if (netdev->flags & IFF_PROMISC) { | |
696 | mode = VPORT_MISS_MODE_ACCEPT_ALL; | |
697 | goto send_fw_cmd; | |
698 | } | |
699 | ||
700 | if ((netdev->flags & IFF_ALLMULTI) || | |
4cd24eaf | 701 | (netdev_mc_count(netdev) > adapter->max_mc_count)) { |
9ad27643 DP |
702 | mode = VPORT_MISS_MODE_ACCEPT_MULTI; |
703 | goto send_fw_cmd; | |
704 | } | |
705 | ||
4cd24eaf | 706 | if (!netdev_mc_empty(netdev)) { |
22bedad3 JP |
707 | netdev_for_each_mc_addr(ha, netdev) |
708 | nx_p3_nic_add_mac(adapter, ha->addr, &del_list); | |
c9fc891f | 709 | } |
9ad27643 DP |
710 | |
711 | send_fw_cmd: | |
712 | adapter->set_promisc(adapter, mode); | |
5cf4d323 DP |
713 | head = &del_list; |
714 | while (!list_empty(head)) { | |
715 | cur = list_entry(head->next, nx_mac_list_t, list); | |
716 | ||
717 | nx_p3_sre_macaddr_change(adapter, | |
718 | cur->mac_addr, NETXEN_MAC_DEL); | |
719 | list_del(&cur->list); | |
c9fc891f | 720 | kfree(cur); |
c9fc891f DP |
721 | } |
722 | } | |
723 | ||
9ad27643 DP |
724 | int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode) |
725 | { | |
726 | nx_nic_req_t req; | |
2edbb454 | 727 | u64 word; |
9ad27643 DP |
728 | |
729 | memset(&req, 0, sizeof(nx_nic_req_t)); | |
730 | ||
2edbb454 DP |
731 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); |
732 | ||
733 | word = NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE | | |
734 | ((u64)adapter->portnum << 16); | |
735 | req.req_hdr = cpu_to_le64(word); | |
736 | ||
9ad27643 DP |
737 | req.words[0] = cpu_to_le64(mode); |
738 | ||
739 | return netxen_send_cmd_descs(adapter, | |
740 | (struct cmd_desc_type0 *)&req, 1); | |
741 | } | |
742 | ||
06e9d9f9 DP |
743 | void netxen_p3_free_mac_list(struct netxen_adapter *adapter) |
744 | { | |
5cf4d323 DP |
745 | nx_mac_list_t *cur; |
746 | struct list_head *head = &adapter->mac_list; | |
747 | ||
748 | while (!list_empty(head)) { | |
749 | cur = list_entry(head->next, nx_mac_list_t, list); | |
750 | nx_p3_sre_macaddr_change(adapter, | |
751 | cur->mac_addr, NETXEN_MAC_DEL); | |
752 | list_del(&cur->list); | |
06e9d9f9 | 753 | kfree(cur); |
06e9d9f9 DP |
754 | } |
755 | } | |
756 | ||
3d0a3cc9 DP |
757 | int netxen_p3_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr) |
758 | { | |
759 | /* assuming caller has already copied new addr to netdev */ | |
760 | netxen_p3_nic_set_multi(adapter->netdev); | |
761 | return 0; | |
762 | } | |
763 | ||
cd1f8160 DP |
764 | #define NETXEN_CONFIG_INTR_COALESCE 3 |
765 | ||
766 | /* | |
767 | * Send the interrupt coalescing parameter set by ethtool to the card. | |
768 | */ | |
769 | int netxen_config_intr_coalesce(struct netxen_adapter *adapter) | |
770 | { | |
771 | nx_nic_req_t req; | |
c0703950 AKS |
772 | u64 word[6]; |
773 | int rv, i; | |
cd1f8160 DP |
774 | |
775 | memset(&req, 0, sizeof(nx_nic_req_t)); | |
c0703950 | 776 | memset(word, 0, sizeof(word)); |
cd1f8160 | 777 | |
1bb482f8 | 778 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); |
2edbb454 | 779 | |
c0703950 AKS |
780 | word[0] = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16); |
781 | req.req_hdr = cpu_to_le64(word[0]); | |
cd1f8160 | 782 | |
c0703950 AKS |
783 | memcpy(&word[0], &adapter->coal, sizeof(adapter->coal)); |
784 | for (i = 0; i < 6; i++) | |
785 | req.words[i] = cpu_to_le64(word[i]); | |
cd1f8160 DP |
786 | |
787 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); | |
788 | if (rv != 0) { | |
789 | printk(KERN_ERR "ERROR. Could not send " | |
790 | "interrupt coalescing parameters\n"); | |
791 | } | |
792 | ||
793 | return rv; | |
794 | } | |
795 | ||
1bb482f8 NK |
796 | int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable) |
797 | { | |
798 | nx_nic_req_t req; | |
799 | u64 word; | |
800 | int rv = 0; | |
801 | ||
802 | if ((adapter->flags & NETXEN_NIC_LRO_ENABLED) == enable) | |
803 | return 0; | |
804 | ||
805 | memset(&req, 0, sizeof(nx_nic_req_t)); | |
806 | ||
807 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); | |
808 | ||
809 | word = NX_NIC_H2C_OPCODE_CONFIG_HW_LRO | ((u64)adapter->portnum << 16); | |
810 | req.req_hdr = cpu_to_le64(word); | |
811 | ||
812 | req.words[0] = cpu_to_le64(enable); | |
813 | ||
814 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); | |
815 | if (rv != 0) { | |
816 | printk(KERN_ERR "ERROR. Could not send " | |
817 | "configure hw lro request\n"); | |
818 | } | |
819 | ||
820 | adapter->flags ^= NETXEN_NIC_LRO_ENABLED; | |
821 | ||
822 | return rv; | |
823 | } | |
824 | ||
fa3ce355 NK |
825 | int netxen_config_bridged_mode(struct netxen_adapter *adapter, int enable) |
826 | { | |
827 | nx_nic_req_t req; | |
828 | u64 word; | |
829 | int rv = 0; | |
830 | ||
831 | if (!!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED) == enable) | |
832 | return rv; | |
833 | ||
834 | memset(&req, 0, sizeof(nx_nic_req_t)); | |
835 | ||
836 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); | |
837 | ||
838 | word = NX_NIC_H2C_OPCODE_CONFIG_BRIDGING | | |
839 | ((u64)adapter->portnum << 16); | |
840 | req.req_hdr = cpu_to_le64(word); | |
841 | ||
842 | req.words[0] = cpu_to_le64(enable); | |
843 | ||
844 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); | |
845 | if (rv != 0) { | |
846 | printk(KERN_ERR "ERROR. Could not send " | |
847 | "configure bridge mode request\n"); | |
848 | } | |
849 | ||
850 | adapter->flags ^= NETXEN_NIC_BRIDGE_ENABLED; | |
851 | ||
852 | return rv; | |
853 | } | |
854 | ||
855 | ||
d8b100c5 DP |
856 | #define RSS_HASHTYPE_IP_TCP 0x3 |
857 | ||
858 | int netxen_config_rss(struct netxen_adapter *adapter, int enable) | |
859 | { | |
860 | nx_nic_req_t req; | |
861 | u64 word; | |
862 | int i, rv; | |
863 | ||
864 | u64 key[] = { 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL, | |
865 | 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL, | |
866 | 0x255b0ec26d5a56daULL }; | |
867 | ||
868 | ||
869 | memset(&req, 0, sizeof(nx_nic_req_t)); | |
870 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); | |
871 | ||
872 | word = NX_NIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16); | |
873 | req.req_hdr = cpu_to_le64(word); | |
874 | ||
875 | /* | |
876 | * RSS request: | |
877 | * bits 3-0: hash_method | |
878 | * 5-4: hash_type_ipv4 | |
879 | * 7-6: hash_type_ipv6 | |
880 | * 8: enable | |
881 | * 9: use indirection table | |
882 | * 47-10: reserved | |
883 | * 63-48: indirection table mask | |
884 | */ | |
885 | word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) | | |
886 | ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) | | |
887 | ((u64)(enable & 0x1) << 8) | | |
888 | ((0x7ULL) << 48); | |
889 | req.words[0] = cpu_to_le64(word); | |
890 | for (i = 0; i < 5; i++) | |
891 | req.words[i+1] = cpu_to_le64(key[i]); | |
892 | ||
893 | ||
894 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); | |
895 | if (rv != 0) { | |
896 | printk(KERN_ERR "%s: could not configure RSS\n", | |
897 | adapter->netdev->name); | |
898 | } | |
899 | ||
900 | return rv; | |
901 | } | |
902 | ||
6598b169 DP |
903 | int netxen_config_ipaddr(struct netxen_adapter *adapter, u32 ip, int cmd) |
904 | { | |
905 | nx_nic_req_t req; | |
906 | u64 word; | |
907 | int rv; | |
908 | ||
909 | memset(&req, 0, sizeof(nx_nic_req_t)); | |
910 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); | |
911 | ||
912 | word = NX_NIC_H2C_OPCODE_CONFIG_IPADDR | ((u64)adapter->portnum << 16); | |
913 | req.req_hdr = cpu_to_le64(word); | |
914 | ||
915 | req.words[0] = cpu_to_le64(cmd); | |
916 | req.words[1] = cpu_to_le64(ip); | |
917 | ||
918 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); | |
919 | if (rv != 0) { | |
920 | printk(KERN_ERR "%s: could not notify %s IP 0x%x reuqest\n", | |
921 | adapter->netdev->name, | |
922 | (cmd == NX_IP_UP) ? "Add" : "Remove", ip); | |
923 | } | |
924 | return rv; | |
925 | } | |
926 | ||
3bf26ce3 DP |
927 | int netxen_linkevent_request(struct netxen_adapter *adapter, int enable) |
928 | { | |
929 | nx_nic_req_t req; | |
930 | u64 word; | |
931 | int rv; | |
932 | ||
933 | memset(&req, 0, sizeof(nx_nic_req_t)); | |
934 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); | |
935 | ||
936 | word = NX_NIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16); | |
937 | req.req_hdr = cpu_to_le64(word); | |
22527864 | 938 | req.words[0] = cpu_to_le64(enable | (enable << 8)); |
3bf26ce3 DP |
939 | |
940 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); | |
941 | if (rv != 0) { | |
942 | printk(KERN_ERR "%s: could not configure link notification\n", | |
943 | adapter->netdev->name); | |
944 | } | |
945 | ||
946 | return rv; | |
947 | } | |
948 | ||
1bb482f8 NK |
949 | int netxen_send_lro_cleanup(struct netxen_adapter *adapter) |
950 | { | |
951 | nx_nic_req_t req; | |
952 | u64 word; | |
953 | int rv; | |
954 | ||
955 | memset(&req, 0, sizeof(nx_nic_req_t)); | |
956 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); | |
957 | ||
958 | word = NX_NIC_H2C_OPCODE_LRO_REQUEST | | |
959 | ((u64)adapter->portnum << 16) | | |
960 | ((u64)NX_NIC_LRO_REQUEST_CLEANUP << 56) ; | |
961 | ||
962 | req.req_hdr = cpu_to_le64(word); | |
963 | ||
964 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); | |
965 | if (rv != 0) { | |
966 | printk(KERN_ERR "%s: could not cleanup lro flows\n", | |
967 | adapter->netdev->name); | |
968 | } | |
969 | return rv; | |
970 | } | |
971 | ||
3d396eb1 AK |
972 | /* |
973 | * netxen_nic_change_mtu - Change the Maximum Transfer Unit | |
974 | * @returns 0 on success, negative on failure | |
975 | */ | |
c9fc891f DP |
976 | |
977 | #define MTU_FUDGE_FACTOR 100 | |
978 | ||
3d396eb1 AK |
979 | int netxen_nic_change_mtu(struct net_device *netdev, int mtu) |
980 | { | |
3176ff3e | 981 | struct netxen_adapter *adapter = netdev_priv(netdev); |
c9fc891f | 982 | int max_mtu; |
9ad27643 | 983 | int rc = 0; |
3d396eb1 | 984 | |
c9fc891f DP |
985 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
986 | max_mtu = P3_MAX_MTU; | |
987 | else | |
988 | max_mtu = P2_MAX_MTU; | |
989 | ||
990 | if (mtu > max_mtu) { | |
991 | printk(KERN_ERR "%s: mtu > %d bytes unsupported\n", | |
992 | netdev->name, max_mtu); | |
3d396eb1 AK |
993 | return -EINVAL; |
994 | } | |
995 | ||
80922fbc | 996 | if (adapter->set_mtu) |
9ad27643 | 997 | rc = adapter->set_mtu(adapter, mtu); |
3d396eb1 | 998 | |
9ad27643 DP |
999 | if (!rc) |
1000 | netdev->mtu = mtu; | |
c9fc891f | 1001 | |
9ad27643 | 1002 | return rc; |
3d396eb1 AK |
1003 | } |
1004 | ||
3d396eb1 | 1005 | static int netxen_get_flash_block(struct netxen_adapter *adapter, int base, |
f305f789 | 1006 | int size, __le32 * buf) |
3d396eb1 | 1007 | { |
1e2d0059 | 1008 | int i, v, addr; |
f305f789 | 1009 | __le32 *ptr32; |
3d396eb1 AK |
1010 | |
1011 | addr = base; | |
1012 | ptr32 = buf; | |
1013 | for (i = 0; i < size / sizeof(u32); i++) { | |
f305f789 | 1014 | if (netxen_rom_fast_read(adapter, addr, &v) == -1) |
3d396eb1 | 1015 | return -1; |
f305f789 | 1016 | *ptr32 = cpu_to_le32(v); |
3d396eb1 AK |
1017 | ptr32++; |
1018 | addr += sizeof(u32); | |
1019 | } | |
1020 | if ((char *)buf + size > (char *)ptr32) { | |
f305f789 AV |
1021 | __le32 local; |
1022 | if (netxen_rom_fast_read(adapter, addr, &v) == -1) | |
3d396eb1 | 1023 | return -1; |
f305f789 | 1024 | local = cpu_to_le32(v); |
3d396eb1 AK |
1025 | memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32); |
1026 | } | |
1027 | ||
1028 | return 0; | |
1029 | } | |
1030 | ||
a03d2451 | 1031 | int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 *mac) |
3d396eb1 | 1032 | { |
9dc28efe DP |
1033 | __le32 *pmac = (__le32 *) mac; |
1034 | u32 offset; | |
3d396eb1 | 1035 | |
06db58c0 | 1036 | offset = NX_FW_MAC_ADDR_OFFSET + (adapter->portnum * sizeof(u64)); |
9dc28efe DP |
1037 | |
1038 | if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1) | |
3d396eb1 | 1039 | return -1; |
9dc28efe | 1040 | |
f305f789 | 1041 | if (*mac == cpu_to_le64(~0ULL)) { |
9dc28efe | 1042 | |
06db58c0 DP |
1043 | offset = NX_OLD_MAC_ADDR_OFFSET + |
1044 | (adapter->portnum * sizeof(u64)); | |
9dc28efe | 1045 | |
3d396eb1 | 1046 | if (netxen_get_flash_block(adapter, |
9dc28efe | 1047 | offset, sizeof(u64), pmac) == -1) |
3d396eb1 | 1048 | return -1; |
9dc28efe | 1049 | |
f305f789 | 1050 | if (*mac == cpu_to_le64(~0ULL)) |
3d396eb1 AK |
1051 | return -1; |
1052 | } | |
1053 | return 0; | |
1054 | } | |
1055 | ||
a03d2451 | 1056 | int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, u64 *mac) |
9dc28efe DP |
1057 | { |
1058 | uint32_t crbaddr, mac_hi, mac_lo; | |
1059 | int pci_func = adapter->ahw.pci_func; | |
1060 | ||
1061 | crbaddr = CRB_MAC_BLOCK_START + | |
1062 | (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1)); | |
1063 | ||
f98a9f69 DP |
1064 | mac_lo = NXRD32(adapter, crbaddr); |
1065 | mac_hi = NXRD32(adapter, crbaddr+4); | |
9dc28efe | 1066 | |
9dc28efe | 1067 | if (pci_func & 1) |
2edbb454 | 1068 | *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16)); |
9dc28efe | 1069 | else |
2edbb454 | 1070 | *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32)); |
9dc28efe DP |
1071 | |
1072 | return 0; | |
1073 | } | |
1074 | ||
3d396eb1 AK |
1075 | /* |
1076 | * Changes the CRB window to the specified window. | |
1077 | */ | |
195c5f98 | 1078 | static void |
907fa120 DP |
1079 | netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter, |
1080 | u32 window) | |
3d396eb1 AK |
1081 | { |
1082 | void __iomem *offset; | |
907fa120 DP |
1083 | int count = 10; |
1084 | u8 func = adapter->ahw.pci_func; | |
3d396eb1 | 1085 | |
907fa120 | 1086 | if (adapter->ahw.crb_win == window) |
3d396eb1 | 1087 | return; |
907fa120 | 1088 | |
e4c93c81 DP |
1089 | offset = PCI_OFFSET_SECOND_RANGE(adapter, |
1090 | NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func))); | |
3d396eb1 | 1091 | |
907fa120 DP |
1092 | writel(window, offset); |
1093 | do { | |
1094 | if (window == readl(offset)) | |
1095 | break; | |
3d396eb1 | 1096 | |
907fa120 DP |
1097 | if (printk_ratelimit()) |
1098 | dev_warn(&adapter->pdev->dev, | |
1099 | "failed to set CRB window to %d\n", | |
1100 | (window == NETXEN_WINDOW_ONE)); | |
1101 | udelay(1); | |
3d396eb1 | 1102 | |
907fa120 | 1103 | } while (--count > 0); |
3d396eb1 | 1104 | |
907fa120 DP |
1105 | if (count > 0) |
1106 | adapter->ahw.crb_win = window; | |
3d396eb1 AK |
1107 | } |
1108 | ||
3ce06a32 | 1109 | /* |
7cecdca1 | 1110 | * Returns < 0 if off is not valid, |
3ce06a32 DP |
1111 | * 1 if window access is needed. 'off' is set to offset from |
1112 | * CRB space in 128M pci map | |
1113 | * 0 if no window access is needed. 'off' is set to 2M addr | |
1114 | * In: 'off' is offset from base in 128M pci map | |
1115 | */ | |
1116 | static int | |
a9ac07de DP |
1117 | netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, |
1118 | ulong off, void __iomem **addr) | |
3ce06a32 | 1119 | { |
3ce06a32 DP |
1120 | crb_128M_2M_sub_block_map_t *m; |
1121 | ||
1122 | ||
a9ac07de | 1123 | if ((off >= NETXEN_CRB_MAX) || (off < NETXEN_PCI_CRBSPACE)) |
7cecdca1 | 1124 | return -EINVAL; |
3ce06a32 | 1125 | |
a9ac07de | 1126 | off -= NETXEN_PCI_CRBSPACE; |
3ce06a32 DP |
1127 | |
1128 | /* | |
1129 | * Try direct map | |
1130 | */ | |
a9ac07de | 1131 | m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)]; |
3ce06a32 | 1132 | |
a9ac07de DP |
1133 | if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) { |
1134 | *addr = adapter->ahw.pci_base0 + m->start_2M + | |
1135 | (off - m->start_128M); | |
3ce06a32 DP |
1136 | return 0; |
1137 | } | |
1138 | ||
1139 | /* | |
1140 | * Not in direct map, use crb window | |
1141 | */ | |
a9ac07de DP |
1142 | *addr = adapter->ahw.pci_base0 + CRB_INDIRECT_2M + |
1143 | (off & MASK(16)); | |
3ce06a32 DP |
1144 | return 1; |
1145 | } | |
1146 | ||
1147 | /* | |
1148 | * In: 'off' is offset from CRB space in 128M pci map | |
1149 | * Out: 'off' is 2M pci map addr | |
1150 | * side effect: lock crb window | |
1151 | */ | |
1152 | static void | |
a9ac07de | 1153 | netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong off) |
3ce06a32 | 1154 | { |
907fa120 DP |
1155 | u32 window; |
1156 | void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M; | |
3ce06a32 | 1157 | |
a9ac07de DP |
1158 | off -= NETXEN_PCI_CRBSPACE; |
1159 | ||
1160 | window = CRB_HI(off); | |
907fa120 | 1161 | |
907fa120 DP |
1162 | writel(window, addr); |
1163 | if (readl(addr) != window) { | |
1164 | if (printk_ratelimit()) | |
1165 | dev_warn(&adapter->pdev->dev, | |
1166 | "failed to set CRB window to %d off 0x%lx\n", | |
a9ac07de | 1167 | window, off); |
3ce06a32 | 1168 | } |
3ce06a32 DP |
1169 | } |
1170 | ||
f58dbd73 NK |
1171 | static void __iomem * |
1172 | netxen_nic_map_indirect_address_128M(struct netxen_adapter *adapter, | |
1173 | ulong win_off, void __iomem **mem_ptr) | |
1174 | { | |
1175 | ulong off = win_off; | |
1176 | void __iomem *addr; | |
1177 | resource_size_t mem_base; | |
1178 | ||
1179 | if (ADDR_IN_WINDOW1(win_off)) | |
1180 | off = NETXEN_CRB_NORMAL(win_off); | |
1181 | ||
1182 | addr = pci_base_offset(adapter, off); | |
1183 | if (addr) | |
1184 | return addr; | |
1185 | ||
1186 | if (adapter->ahw.pci_len0 == 0) | |
1187 | off -= NETXEN_PCI_CRBSPACE; | |
1188 | ||
1189 | mem_base = pci_resource_start(adapter->pdev, 0); | |
1190 | *mem_ptr = ioremap(mem_base + (off & PAGE_MASK), PAGE_SIZE); | |
1191 | if (*mem_ptr) | |
1192 | addr = *mem_ptr + (off & (PAGE_SIZE - 1)); | |
1193 | ||
1194 | return addr; | |
1195 | } | |
1196 | ||
195c5f98 | 1197 | static int |
1fbe6323 | 1198 | netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data) |
3d396eb1 | 1199 | { |
195c5f98 | 1200 | unsigned long flags; |
f58dbd73 | 1201 | void __iomem *addr, *mem_ptr = NULL; |
3d396eb1 | 1202 | |
f58dbd73 NK |
1203 | addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr); |
1204 | if (!addr) | |
1205 | return -EIO; | |
195c5f98 | 1206 | |
f58dbd73 | 1207 | if (ADDR_IN_WINDOW1(off)) { /* Window 1 */ |
f03b0ebd | 1208 | netxen_nic_io_write_128M(adapter, addr, data); |
f58dbd73 | 1209 | } else { /* Window 0 */ |
f03b0ebd | 1210 | write_lock_irqsave(&adapter->ahw.crb_lock, flags); |
907fa120 | 1211 | netxen_nic_pci_set_crbwindow_128M(adapter, 0); |
195c5f98 | 1212 | writel(data, addr); |
907fa120 DP |
1213 | netxen_nic_pci_set_crbwindow_128M(adapter, |
1214 | NETXEN_WINDOW_ONE); | |
f03b0ebd | 1215 | write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); |
cb8011ad AK |
1216 | } |
1217 | ||
f58dbd73 NK |
1218 | if (mem_ptr) |
1219 | iounmap(mem_ptr); | |
1220 | ||
3d396eb1 AK |
1221 | return 0; |
1222 | } | |
1223 | ||
195c5f98 | 1224 | static u32 |
1fbe6323 | 1225 | netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off) |
3d396eb1 | 1226 | { |
195c5f98 | 1227 | unsigned long flags; |
f58dbd73 | 1228 | void __iomem *addr, *mem_ptr = NULL; |
1fbe6323 | 1229 | u32 data; |
d8313ce0 | 1230 | |
f58dbd73 NK |
1231 | addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr); |
1232 | if (!addr) | |
1233 | return -EIO; | |
3d396eb1 | 1234 | |
f58dbd73 | 1235 | if (ADDR_IN_WINDOW1(off)) { /* Window 1 */ |
f03b0ebd | 1236 | data = netxen_nic_io_read_128M(adapter, addr); |
f58dbd73 | 1237 | } else { /* Window 0 */ |
f03b0ebd | 1238 | write_lock_irqsave(&adapter->ahw.crb_lock, flags); |
907fa120 | 1239 | netxen_nic_pci_set_crbwindow_128M(adapter, 0); |
195c5f98 | 1240 | data = readl(addr); |
907fa120 DP |
1241 | netxen_nic_pci_set_crbwindow_128M(adapter, |
1242 | NETXEN_WINDOW_ONE); | |
f03b0ebd | 1243 | write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); |
195c5f98 | 1244 | } |
3d396eb1 | 1245 | |
f58dbd73 NK |
1246 | if (mem_ptr) |
1247 | iounmap(mem_ptr); | |
1248 | ||
1fbe6323 | 1249 | return data; |
3d396eb1 AK |
1250 | } |
1251 | ||
195c5f98 | 1252 | static int |
1fbe6323 | 1253 | netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data) |
3ce06a32 | 1254 | { |
195c5f98 | 1255 | unsigned long flags; |
3ce06a32 | 1256 | int rv; |
a9ac07de | 1257 | void __iomem *addr = NULL; |
3d396eb1 | 1258 | |
a9ac07de | 1259 | rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr); |
3d396eb1 | 1260 | |
7cecdca1 | 1261 | if (rv == 0) { |
a9ac07de | 1262 | writel(data, addr); |
7cecdca1 | 1263 | return 0; |
3ce06a32 DP |
1264 | } |
1265 | ||
7cecdca1 DP |
1266 | if (rv > 0) { |
1267 | /* indirect access */ | |
f03b0ebd | 1268 | write_lock_irqsave(&adapter->ahw.crb_lock, flags); |
3ce06a32 | 1269 | crb_win_lock(adapter); |
a9ac07de DP |
1270 | netxen_nic_pci_set_crbwindow_2M(adapter, off); |
1271 | writel(data, addr); | |
3ce06a32 | 1272 | crb_win_unlock(adapter); |
f03b0ebd | 1273 | write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); |
7cecdca1 DP |
1274 | return 0; |
1275 | } | |
3ce06a32 | 1276 | |
7cecdca1 DP |
1277 | dev_err(&adapter->pdev->dev, |
1278 | "%s: invalid offset: 0x%016lx\n", __func__, off); | |
1279 | dump_stack(); | |
1280 | return -EIO; | |
3d396eb1 AK |
1281 | } |
1282 | ||
195c5f98 | 1283 | static u32 |
1fbe6323 | 1284 | netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off) |
3ce06a32 | 1285 | { |
195c5f98 | 1286 | unsigned long flags; |
3ce06a32 | 1287 | int rv; |
1fbe6323 | 1288 | u32 data; |
a9ac07de | 1289 | void __iomem *addr = NULL; |
3d396eb1 | 1290 | |
a9ac07de | 1291 | rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr); |
3ce06a32 | 1292 | |
7cecdca1 | 1293 | if (rv == 0) |
a9ac07de | 1294 | return readl(addr); |
3ce06a32 | 1295 | |
7cecdca1 DP |
1296 | if (rv > 0) { |
1297 | /* indirect access */ | |
f03b0ebd | 1298 | write_lock_irqsave(&adapter->ahw.crb_lock, flags); |
3ce06a32 | 1299 | crb_win_lock(adapter); |
a9ac07de DP |
1300 | netxen_nic_pci_set_crbwindow_2M(adapter, off); |
1301 | data = readl(addr); | |
3ce06a32 | 1302 | crb_win_unlock(adapter); |
f03b0ebd | 1303 | write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); |
7cecdca1 DP |
1304 | return data; |
1305 | } | |
3ce06a32 | 1306 | |
7cecdca1 DP |
1307 | dev_err(&adapter->pdev->dev, |
1308 | "%s: invalid offset: 0x%016lx\n", __func__, off); | |
1309 | dump_stack(); | |
1310 | return -1; | |
3ce06a32 DP |
1311 | } |
1312 | ||
195c5f98 AKS |
1313 | /* window 1 registers only */ |
1314 | static void netxen_nic_io_write_128M(struct netxen_adapter *adapter, | |
1315 | void __iomem *addr, u32 data) | |
3ce06a32 | 1316 | { |
f03b0ebd | 1317 | read_lock(&adapter->ahw.crb_lock); |
195c5f98 | 1318 | writel(data, addr); |
f03b0ebd | 1319 | read_unlock(&adapter->ahw.crb_lock); |
195c5f98 AKS |
1320 | } |
1321 | ||
1322 | static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter, | |
1323 | void __iomem *addr) | |
1324 | { | |
1325 | u32 val; | |
1326 | ||
f03b0ebd | 1327 | read_lock(&adapter->ahw.crb_lock); |
195c5f98 | 1328 | val = readl(addr); |
f03b0ebd | 1329 | read_unlock(&adapter->ahw.crb_lock); |
195c5f98 AKS |
1330 | |
1331 | return val; | |
3ce06a32 DP |
1332 | } |
1333 | ||
195c5f98 AKS |
1334 | static void netxen_nic_io_write_2M(struct netxen_adapter *adapter, |
1335 | void __iomem *addr, u32 data) | |
3ce06a32 | 1336 | { |
195c5f98 AKS |
1337 | writel(data, addr); |
1338 | } | |
1339 | ||
1340 | static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter, | |
1341 | void __iomem *addr) | |
1342 | { | |
1343 | return readl(addr); | |
1344 | } | |
1345 | ||
1346 | void __iomem * | |
1347 | netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset) | |
1348 | { | |
a9ac07de | 1349 | void __iomem *addr = NULL; |
195c5f98 AKS |
1350 | |
1351 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | |
a9ac07de DP |
1352 | if ((offset < NETXEN_CRB_PCIX_HOST2) && |
1353 | (offset > NETXEN_CRB_PCIX_HOST)) | |
1354 | addr = PCI_OFFSET_SECOND_RANGE(adapter, offset); | |
1355 | else | |
1356 | addr = NETXEN_CRB_NORMALIZE(adapter, offset); | |
1357 | } else { | |
1358 | WARN_ON(netxen_nic_pci_get_crb_addr_2M(adapter, | |
1359 | offset, &addr)); | |
195c5f98 AKS |
1360 | } |
1361 | ||
a9ac07de | 1362 | return addr; |
3ce06a32 DP |
1363 | } |
1364 | ||
47abe356 DP |
1365 | static int |
1366 | netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter, | |
1367 | u64 addr, u32 *start) | |
3ce06a32 | 1368 | { |
47abe356 DP |
1369 | if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) { |
1370 | *start = (addr - NETXEN_ADDR_OCM0 + NETXEN_PCI_OCM0); | |
1371 | return 0; | |
3ce06a32 | 1372 | } else if (ADDR_IN_RANGE(addr, |
47abe356 DP |
1373 | NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { |
1374 | *start = (addr - NETXEN_ADDR_OCM1 + NETXEN_PCI_OCM1); | |
1375 | return 0; | |
1376 | } | |
3ce06a32 | 1377 | |
47abe356 DP |
1378 | return -EIO; |
1379 | } | |
3ce06a32 | 1380 | |
47abe356 DP |
1381 | static int |
1382 | netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter, | |
1383 | u64 addr, u32 *start) | |
1384 | { | |
6abb4b83 | 1385 | u32 window; |
3ce06a32 | 1386 | |
14e2cfbb | 1387 | window = OCM_WIN(addr); |
6abb4b83 | 1388 | |
47abe356 | 1389 | writel(window, adapter->ahw.ocm_win_crb); |
6abb4b83 AKS |
1390 | /* read back to flush */ |
1391 | readl(adapter->ahw.ocm_win_crb); | |
47abe356 DP |
1392 | |
1393 | adapter->ahw.ocm_win = window; | |
1394 | *start = NETXEN_PCI_OCM0_2M + GET_MEM_OFFS_2M(addr); | |
1395 | return 0; | |
3ce06a32 | 1396 | } |
47abe356 DP |
1397 | |
1398 | static int | |
1399 | netxen_nic_pci_mem_access_direct(struct netxen_adapter *adapter, u64 off, | |
1400 | u64 *data, int op) | |
1401 | { | |
1402 | void __iomem *addr, *mem_ptr = NULL; | |
1403 | resource_size_t mem_base; | |
14e2cfbb | 1404 | int ret; |
47abe356 DP |
1405 | u32 start; |
1406 | ||
f03b0ebd | 1407 | spin_lock(&adapter->ahw.mem_lock); |
47abe356 DP |
1408 | |
1409 | ret = adapter->pci_set_window(adapter, off, &start); | |
1410 | if (ret != 0) | |
1411 | goto unlock; | |
1412 | ||
14e2cfbb SC |
1413 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
1414 | addr = adapter->ahw.pci_base0 + start; | |
1415 | } else { | |
1416 | addr = pci_base_offset(adapter, start); | |
1417 | if (addr) | |
1418 | goto noremap; | |
1419 | ||
1420 | mem_base = pci_resource_start(adapter->pdev, 0) + | |
1421 | (start & PAGE_MASK); | |
1422 | mem_ptr = ioremap(mem_base, PAGE_SIZE); | |
1423 | if (mem_ptr == NULL) { | |
1424 | ret = -EIO; | |
1425 | goto unlock; | |
1426 | } | |
47abe356 | 1427 | |
14e2cfbb | 1428 | addr = mem_ptr + (start & (PAGE_SIZE-1)); |
3d396eb1 | 1429 | } |
47abe356 DP |
1430 | noremap: |
1431 | if (op == 0) /* read */ | |
1432 | *data = readq(addr); | |
1433 | else /* write */ | |
1434 | writeq(*data, addr); | |
1435 | ||
1436 | unlock: | |
f03b0ebd DP |
1437 | spin_unlock(&adapter->ahw.mem_lock); |
1438 | ||
47abe356 DP |
1439 | if (mem_ptr) |
1440 | iounmap(mem_ptr); | |
1441 | return ret; | |
3d396eb1 AK |
1442 | } |
1443 | ||
0b9715e6 AKS |
1444 | void |
1445 | netxen_pci_camqm_read_2M(struct netxen_adapter *adapter, u64 off, u64 *data) | |
1446 | { | |
1447 | void __iomem *addr = adapter->ahw.pci_base0 + | |
1448 | NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM); | |
1449 | ||
1450 | spin_lock(&adapter->ahw.mem_lock); | |
1451 | *data = readq(addr); | |
1452 | spin_unlock(&adapter->ahw.mem_lock); | |
1453 | } | |
1454 | ||
1455 | void | |
1456 | netxen_pci_camqm_write_2M(struct netxen_adapter *adapter, u64 off, u64 data) | |
1457 | { | |
1458 | void __iomem *addr = adapter->ahw.pci_base0 + | |
1459 | NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM); | |
1460 | ||
1461 | spin_lock(&adapter->ahw.mem_lock); | |
1462 | writeq(data, addr); | |
1463 | spin_unlock(&adapter->ahw.mem_lock); | |
1464 | } | |
1465 | ||
3ce06a32 DP |
1466 | #define MAX_CTL_CHECK 1000 |
1467 | ||
195c5f98 | 1468 | static int |
3ce06a32 | 1469 | netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter, |
1f5e055d | 1470 | u64 off, u64 data) |
3ce06a32 | 1471 | { |
1f5e055d AKS |
1472 | int j, ret; |
1473 | u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo; | |
d8313ce0 | 1474 | void __iomem *mem_crb; |
3ce06a32 | 1475 | |
1f5e055d AKS |
1476 | /* Only 64-bit aligned access */ |
1477 | if (off & 7) | |
ea6828b8 DP |
1478 | return -EIO; |
1479 | ||
1f5e055d | 1480 | /* P2 has different SIU and MIU test agent base addr */ |
ea6828b8 DP |
1481 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, |
1482 | NETXEN_ADDR_QDR_NET_MAX_P2)) { | |
1f5e055d AKS |
1483 | mem_crb = pci_base_offset(adapter, |
1484 | NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE); | |
1485 | addr_hi = SIU_TEST_AGT_ADDR_HI; | |
1486 | data_lo = SIU_TEST_AGT_WRDATA_LO; | |
1487 | data_hi = SIU_TEST_AGT_WRDATA_HI; | |
1488 | off_lo = off & SIU_TEST_AGT_ADDR_MASK; | |
1489 | off_hi = SIU_TEST_AGT_UPPER_ADDR(off); | |
ea6828b8 DP |
1490 | goto correct; |
1491 | } | |
3ce06a32 | 1492 | |
ea6828b8 | 1493 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { |
1f5e055d AKS |
1494 | mem_crb = pci_base_offset(adapter, |
1495 | NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); | |
1496 | addr_hi = MIU_TEST_AGT_ADDR_HI; | |
1497 | data_lo = MIU_TEST_AGT_WRDATA_LO; | |
1498 | data_hi = MIU_TEST_AGT_WRDATA_HI; | |
1499 | off_lo = off & MIU_TEST_AGT_ADDR_MASK; | |
1500 | off_hi = 0; | |
ea6828b8 DP |
1501 | goto correct; |
1502 | } | |
1503 | ||
47abe356 DP |
1504 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) || |
1505 | ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { | |
1506 | if (adapter->ahw.pci_len0 != 0) { | |
1507 | return netxen_nic_pci_mem_access_direct(adapter, | |
1508 | off, &data, 1); | |
1509 | } | |
1510 | } | |
1511 | ||
ea6828b8 DP |
1512 | return -EIO; |
1513 | ||
1514 | correct: | |
f03b0ebd | 1515 | spin_lock(&adapter->ahw.mem_lock); |
907fa120 | 1516 | netxen_nic_pci_set_crbwindow_128M(adapter, 0); |
3ce06a32 | 1517 | |
1f5e055d AKS |
1518 | writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO)); |
1519 | writel(off_hi, (mem_crb + addr_hi)); | |
1520 | writel(data & 0xffffffff, (mem_crb + data_lo)); | |
1521 | writel((data >> 32) & 0xffffffff, (mem_crb + data_hi)); | |
1522 | writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL)); | |
1523 | writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE), | |
1524 | (mem_crb + TEST_AGT_CTRL)); | |
1525 | ||
1526 | for (j = 0; j < MAX_CTL_CHECK; j++) { | |
1527 | temp = readl((mem_crb + TEST_AGT_CTRL)); | |
1528 | if ((temp & TA_CTL_BUSY) == 0) | |
3ce06a32 | 1529 | break; |
3ce06a32 DP |
1530 | } |
1531 | ||
1f5e055d AKS |
1532 | if (j >= MAX_CTL_CHECK) { |
1533 | if (printk_ratelimit()) | |
1534 | dev_err(&adapter->pdev->dev, | |
1535 | "failed to write through agent\n"); | |
1536 | ret = -EIO; | |
1537 | } else | |
1538 | ret = 0; | |
1539 | ||
907fa120 | 1540 | netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE); |
f03b0ebd | 1541 | spin_unlock(&adapter->ahw.mem_lock); |
3ce06a32 DP |
1542 | return ret; |
1543 | } | |
1544 | ||
195c5f98 | 1545 | static int |
3ce06a32 | 1546 | netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter, |
1f5e055d | 1547 | u64 off, u64 *data) |
3ce06a32 | 1548 | { |
1f5e055d AKS |
1549 | int j, ret; |
1550 | u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo; | |
1551 | u64 val; | |
d8313ce0 | 1552 | void __iomem *mem_crb; |
3ce06a32 | 1553 | |
1f5e055d AKS |
1554 | /* Only 64-bit aligned access */ |
1555 | if (off & 7) | |
ea6828b8 DP |
1556 | return -EIO; |
1557 | ||
1f5e055d | 1558 | /* P2 has different SIU and MIU test agent base addr */ |
ea6828b8 DP |
1559 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, |
1560 | NETXEN_ADDR_QDR_NET_MAX_P2)) { | |
1f5e055d AKS |
1561 | mem_crb = pci_base_offset(adapter, |
1562 | NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE); | |
1563 | addr_hi = SIU_TEST_AGT_ADDR_HI; | |
1564 | data_lo = SIU_TEST_AGT_RDDATA_LO; | |
1565 | data_hi = SIU_TEST_AGT_RDDATA_HI; | |
1566 | off_lo = off & SIU_TEST_AGT_ADDR_MASK; | |
1567 | off_hi = SIU_TEST_AGT_UPPER_ADDR(off); | |
ea6828b8 DP |
1568 | goto correct; |
1569 | } | |
3ce06a32 | 1570 | |
ea6828b8 | 1571 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { |
1f5e055d AKS |
1572 | mem_crb = pci_base_offset(adapter, |
1573 | NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); | |
1574 | addr_hi = MIU_TEST_AGT_ADDR_HI; | |
1575 | data_lo = MIU_TEST_AGT_RDDATA_LO; | |
1576 | data_hi = MIU_TEST_AGT_RDDATA_HI; | |
1577 | off_lo = off & MIU_TEST_AGT_ADDR_MASK; | |
1578 | off_hi = 0; | |
ea6828b8 DP |
1579 | goto correct; |
1580 | } | |
1581 | ||
47abe356 DP |
1582 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) || |
1583 | ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { | |
1584 | if (adapter->ahw.pci_len0 != 0) { | |
1585 | return netxen_nic_pci_mem_access_direct(adapter, | |
1586 | off, data, 0); | |
1587 | } | |
1588 | } | |
1589 | ||
ea6828b8 | 1590 | return -EIO; |
3ce06a32 | 1591 | |
ea6828b8 | 1592 | correct: |
f03b0ebd | 1593 | spin_lock(&adapter->ahw.mem_lock); |
907fa120 | 1594 | netxen_nic_pci_set_crbwindow_128M(adapter, 0); |
3ce06a32 | 1595 | |
1f5e055d AKS |
1596 | writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO)); |
1597 | writel(off_hi, (mem_crb + addr_hi)); | |
1598 | writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL)); | |
1599 | writel((TA_CTL_START|TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL)); | |
3ce06a32 | 1600 | |
1f5e055d AKS |
1601 | for (j = 0; j < MAX_CTL_CHECK; j++) { |
1602 | temp = readl(mem_crb + TEST_AGT_CTRL); | |
1603 | if ((temp & TA_CTL_BUSY) == 0) | |
3ce06a32 | 1604 | break; |
1f5e055d | 1605 | } |
3ce06a32 | 1606 | |
1f5e055d AKS |
1607 | if (j >= MAX_CTL_CHECK) { |
1608 | if (printk_ratelimit()) | |
1609 | dev_err(&adapter->pdev->dev, | |
1610 | "failed to read through agent\n"); | |
1611 | ret = -EIO; | |
1612 | } else { | |
1613 | ||
1614 | temp = readl(mem_crb + data_hi); | |
1615 | val = ((u64)temp << 32); | |
1616 | val |= readl(mem_crb + data_lo); | |
1617 | *data = val; | |
1618 | ret = 0; | |
3ce06a32 DP |
1619 | } |
1620 | ||
907fa120 | 1621 | netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE); |
f03b0ebd | 1622 | spin_unlock(&adapter->ahw.mem_lock); |
3ce06a32 | 1623 | |
1f5e055d | 1624 | return ret; |
3ce06a32 DP |
1625 | } |
1626 | ||
195c5f98 | 1627 | static int |
3ce06a32 | 1628 | netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter, |
1f5e055d | 1629 | u64 off, u64 data) |
3ce06a32 | 1630 | { |
215387a4 | 1631 | int j, ret; |
1f5e055d | 1632 | u32 temp, off8; |
ea6828b8 | 1633 | void __iomem *mem_crb; |
3ce06a32 | 1634 | |
1f5e055d AKS |
1635 | /* Only 64-bit aligned access */ |
1636 | if (off & 7) | |
ea6828b8 DP |
1637 | return -EIO; |
1638 | ||
1f5e055d | 1639 | /* P3 onward, test agent base for MIU and SIU is same */ |
ea6828b8 DP |
1640 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, |
1641 | NETXEN_ADDR_QDR_NET_MAX_P3)) { | |
1f5e055d AKS |
1642 | mem_crb = netxen_get_ioaddr(adapter, |
1643 | NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE); | |
ea6828b8 DP |
1644 | goto correct; |
1645 | } | |
1646 | ||
1647 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { | |
1f5e055d AKS |
1648 | mem_crb = netxen_get_ioaddr(adapter, |
1649 | NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); | |
ea6828b8 | 1650 | goto correct; |
3ce06a32 DP |
1651 | } |
1652 | ||
47abe356 DP |
1653 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) |
1654 | return netxen_nic_pci_mem_access_direct(adapter, off, &data, 1); | |
1655 | ||
ea6828b8 DP |
1656 | return -EIO; |
1657 | ||
1658 | correct: | |
215387a4 | 1659 | off8 = off & 0xfffffff8; |
3ce06a32 | 1660 | |
f03b0ebd | 1661 | spin_lock(&adapter->ahw.mem_lock); |
3ce06a32 | 1662 | |
1f5e055d AKS |
1663 | writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO)); |
1664 | writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI)); | |
fb1f6a43 | 1665 | |
fb1f6a43 | 1666 | writel(data & 0xffffffff, |
215387a4 | 1667 | mem_crb + MIU_TEST_AGT_WRDATA_LO); |
fb1f6a43 | 1668 | writel((data >> 32) & 0xffffffff, |
215387a4 | 1669 | mem_crb + MIU_TEST_AGT_WRDATA_HI); |
fb1f6a43 | 1670 | |
1f5e055d AKS |
1671 | writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL)); |
1672 | writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE), | |
1673 | (mem_crb + TEST_AGT_CTRL)); | |
1674 | ||
1675 | for (j = 0; j < MAX_CTL_CHECK; j++) { | |
1676 | temp = readl(mem_crb + TEST_AGT_CTRL); | |
1677 | if ((temp & TA_CTL_BUSY) == 0) | |
1678 | break; | |
3ce06a32 DP |
1679 | } |
1680 | ||
1f5e055d AKS |
1681 | if (j >= MAX_CTL_CHECK) { |
1682 | if (printk_ratelimit()) | |
1683 | dev_err(&adapter->pdev->dev, | |
39754f44 | 1684 | "failed to write through agent\n"); |
1f5e055d AKS |
1685 | ret = -EIO; |
1686 | } else | |
1687 | ret = 0; | |
1688 | ||
f03b0ebd | 1689 | spin_unlock(&adapter->ahw.mem_lock); |
3ce06a32 | 1690 | |
3ce06a32 DP |
1691 | return ret; |
1692 | } | |
1693 | ||
195c5f98 | 1694 | static int |
3ce06a32 | 1695 | netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter, |
1f5e055d | 1696 | u64 off, u64 *data) |
3ce06a32 | 1697 | { |
1f5e055d AKS |
1698 | int j, ret; |
1699 | u32 temp, off8; | |
215387a4 | 1700 | u64 val; |
ea6828b8 | 1701 | void __iomem *mem_crb; |
3ce06a32 | 1702 | |
1f5e055d AKS |
1703 | /* Only 64-bit aligned access */ |
1704 | if (off & 7) | |
ea6828b8 | 1705 | return -EIO; |
3ce06a32 | 1706 | |
1f5e055d | 1707 | /* P3 onward, test agent base for MIU and SIU is same */ |
ea6828b8 DP |
1708 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, |
1709 | NETXEN_ADDR_QDR_NET_MAX_P3)) { | |
1f5e055d AKS |
1710 | mem_crb = netxen_get_ioaddr(adapter, |
1711 | NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE); | |
ea6828b8 | 1712 | goto correct; |
3ce06a32 DP |
1713 | } |
1714 | ||
ea6828b8 | 1715 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { |
1f5e055d AKS |
1716 | mem_crb = netxen_get_ioaddr(adapter, |
1717 | NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); | |
ea6828b8 DP |
1718 | goto correct; |
1719 | } | |
1720 | ||
907fa120 DP |
1721 | if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) { |
1722 | return netxen_nic_pci_mem_access_direct(adapter, | |
1723 | off, data, 0); | |
1724 | } | |
47abe356 | 1725 | |
ea6828b8 DP |
1726 | return -EIO; |
1727 | ||
1728 | correct: | |
215387a4 | 1729 | off8 = off & 0xfffffff8; |
3ce06a32 | 1730 | |
f03b0ebd | 1731 | spin_lock(&adapter->ahw.mem_lock); |
3ce06a32 | 1732 | |
1f5e055d AKS |
1733 | writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO)); |
1734 | writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI)); | |
1735 | writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL)); | |
1736 | writel((TA_CTL_START | TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL)); | |
3ce06a32 | 1737 | |
1f5e055d AKS |
1738 | for (j = 0; j < MAX_CTL_CHECK; j++) { |
1739 | temp = readl(mem_crb + TEST_AGT_CTRL); | |
1740 | if ((temp & TA_CTL_BUSY) == 0) | |
3ce06a32 | 1741 | break; |
3ce06a32 DP |
1742 | } |
1743 | ||
1f5e055d AKS |
1744 | if (j >= MAX_CTL_CHECK) { |
1745 | if (printk_ratelimit()) | |
1746 | dev_err(&adapter->pdev->dev, | |
1747 | "failed to read through agent\n"); | |
1748 | ret = -EIO; | |
3ce06a32 | 1749 | } else { |
215387a4 SC |
1750 | val = (u64)(readl(mem_crb + MIU_TEST_AGT_RDDATA_HI)) << 32; |
1751 | val |= readl(mem_crb + MIU_TEST_AGT_RDDATA_LO); | |
1f5e055d AKS |
1752 | *data = val; |
1753 | ret = 0; | |
3ce06a32 DP |
1754 | } |
1755 | ||
f03b0ebd | 1756 | spin_unlock(&adapter->ahw.mem_lock); |
1f5e055d AKS |
1757 | |
1758 | return ret; | |
3ce06a32 DP |
1759 | } |
1760 | ||
195c5f98 AKS |
1761 | void |
1762 | netxen_setup_hwops(struct netxen_adapter *adapter) | |
3ce06a32 | 1763 | { |
195c5f98 AKS |
1764 | adapter->init_port = netxen_niu_xg_init_port; |
1765 | adapter->stop_port = netxen_niu_disable_xg_port; | |
3ce06a32 | 1766 | |
195c5f98 AKS |
1767 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
1768 | adapter->crb_read = netxen_nic_hw_read_wx_128M, | |
1769 | adapter->crb_write = netxen_nic_hw_write_wx_128M, | |
1770 | adapter->pci_set_window = netxen_nic_pci_set_window_128M, | |
1771 | adapter->pci_mem_read = netxen_nic_pci_mem_read_128M, | |
1772 | adapter->pci_mem_write = netxen_nic_pci_mem_write_128M, | |
1773 | adapter->io_read = netxen_nic_io_read_128M, | |
1774 | adapter->io_write = netxen_nic_io_write_128M, | |
1775 | ||
1776 | adapter->macaddr_set = netxen_p2_nic_set_mac_addr; | |
1777 | adapter->set_multi = netxen_p2_nic_set_multi; | |
1778 | adapter->set_mtu = netxen_nic_set_mtu_xgb; | |
1779 | adapter->set_promisc = netxen_p2_nic_set_promisc; | |
3ce06a32 | 1780 | |
195c5f98 AKS |
1781 | } else { |
1782 | adapter->crb_read = netxen_nic_hw_read_wx_2M, | |
1783 | adapter->crb_write = netxen_nic_hw_write_wx_2M, | |
1784 | adapter->pci_set_window = netxen_nic_pci_set_window_2M, | |
1785 | adapter->pci_mem_read = netxen_nic_pci_mem_read_2M, | |
1786 | adapter->pci_mem_write = netxen_nic_pci_mem_write_2M, | |
1787 | adapter->io_read = netxen_nic_io_read_2M, | |
1788 | adapter->io_write = netxen_nic_io_write_2M, | |
1789 | ||
1790 | adapter->set_mtu = nx_fw_cmd_set_mtu; | |
1791 | adapter->set_promisc = netxen_p3_nic_set_promisc; | |
1792 | adapter->macaddr_set = netxen_p3_nic_set_mac_addr; | |
1793 | adapter->set_multi = netxen_p3_nic_set_multi; | |
1794 | ||
1795 | adapter->phy_read = nx_fw_cmd_query_phy; | |
1796 | adapter->phy_write = nx_fw_cmd_set_phy; | |
1797 | } | |
3ce06a32 DP |
1798 | } |
1799 | ||
3d396eb1 AK |
1800 | int netxen_nic_get_board_info(struct netxen_adapter *adapter) |
1801 | { | |
0dc6d9cb | 1802 | int offset, board_type, magic; |
1e2d0059 | 1803 | struct pci_dev *pdev = adapter->pdev; |
3d396eb1 | 1804 | |
06db58c0 | 1805 | offset = NX_FW_MAGIC_OFFSET; |
1e2d0059 DP |
1806 | if (netxen_rom_fast_read(adapter, offset, &magic)) |
1807 | return -EIO; | |
3d396eb1 | 1808 | |
0dc6d9cb DP |
1809 | if (magic != NETXEN_BDINFO_MAGIC) { |
1810 | dev_err(&pdev->dev, "invalid board config, magic=%08x\n", | |
1811 | magic); | |
1e2d0059 | 1812 | return -EIO; |
3d396eb1 AK |
1813 | } |
1814 | ||
06db58c0 | 1815 | offset = NX_BRDTYPE_OFFSET; |
1e2d0059 DP |
1816 | if (netxen_rom_fast_read(adapter, offset, &board_type)) |
1817 | return -EIO; | |
1818 | ||
1819 | adapter->ahw.board_type = board_type; | |
1820 | ||
1821 | if (board_type == NETXEN_BRDTYPE_P3_4_GB_MM) { | |
f98a9f69 | 1822 | u32 gpio = NXRD32(adapter, NETXEN_ROMUSB_GLB_PAD_GPIO_I); |
c7860a2a | 1823 | if ((gpio & 0x8000) == 0) |
1e2d0059 | 1824 | board_type = NETXEN_BRDTYPE_P3_10G_TP; |
c7860a2a DP |
1825 | } |
1826 | ||
e98e3350 | 1827 | switch (board_type) { |
3d396eb1 | 1828 | case NETXEN_BRDTYPE_P2_SB35_4G: |
1e2d0059 | 1829 | adapter->ahw.port_type = NETXEN_NIC_GBE; |
3d396eb1 AK |
1830 | break; |
1831 | case NETXEN_BRDTYPE_P2_SB31_10G: | |
1832 | case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: | |
1833 | case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: | |
1834 | case NETXEN_BRDTYPE_P2_SB31_10G_CX4: | |
e4c93c81 DP |
1835 | case NETXEN_BRDTYPE_P3_HMEZ: |
1836 | case NETXEN_BRDTYPE_P3_XG_LOM: | |
1837 | case NETXEN_BRDTYPE_P3_10G_CX4: | |
1838 | case NETXEN_BRDTYPE_P3_10G_CX4_LP: | |
1839 | case NETXEN_BRDTYPE_P3_IMEZ: | |
1840 | case NETXEN_BRDTYPE_P3_10G_SFP_PLUS: | |
a70f9393 DP |
1841 | case NETXEN_BRDTYPE_P3_10G_SFP_CT: |
1842 | case NETXEN_BRDTYPE_P3_10G_SFP_QT: | |
e4c93c81 DP |
1843 | case NETXEN_BRDTYPE_P3_10G_XFP: |
1844 | case NETXEN_BRDTYPE_P3_10000_BASE_T: | |
1e2d0059 | 1845 | adapter->ahw.port_type = NETXEN_NIC_XGBE; |
3d396eb1 AK |
1846 | break; |
1847 | case NETXEN_BRDTYPE_P1_BD: | |
1848 | case NETXEN_BRDTYPE_P1_SB: | |
1849 | case NETXEN_BRDTYPE_P1_SMAX: | |
1850 | case NETXEN_BRDTYPE_P1_SOCK: | |
e4c93c81 DP |
1851 | case NETXEN_BRDTYPE_P3_REF_QG: |
1852 | case NETXEN_BRDTYPE_P3_4_GB: | |
1853 | case NETXEN_BRDTYPE_P3_4_GB_MM: | |
1e2d0059 | 1854 | adapter->ahw.port_type = NETXEN_NIC_GBE; |
3d396eb1 | 1855 | break; |
c7860a2a | 1856 | case NETXEN_BRDTYPE_P3_10G_TP: |
1e2d0059 | 1857 | adapter->ahw.port_type = (adapter->portnum < 2) ? |
c7860a2a DP |
1858 | NETXEN_NIC_XGBE : NETXEN_NIC_GBE; |
1859 | break; | |
3d396eb1 | 1860 | default: |
1e2d0059 DP |
1861 | dev_err(&pdev->dev, "unknown board type %x\n", board_type); |
1862 | adapter->ahw.port_type = NETXEN_NIC_XGBE; | |
3d396eb1 AK |
1863 | break; |
1864 | } | |
1865 | ||
1e2d0059 | 1866 | return 0; |
3d396eb1 AK |
1867 | } |
1868 | ||
1869 | /* NIU access sections */ | |
1870 | ||
3176ff3e | 1871 | int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu) |
3d396eb1 | 1872 | { |
9ad27643 | 1873 | new_mtu += MTU_FUDGE_FACTOR; |
f98a9f69 | 1874 | NXWR32(adapter, NETXEN_NIU_GB_MAX_FRAME_SIZE(adapter->physical_port), |
3276fbad | 1875 | new_mtu); |
3d396eb1 AK |
1876 | return 0; |
1877 | } | |
1878 | ||
3176ff3e | 1879 | int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu) |
3d396eb1 | 1880 | { |
9ad27643 | 1881 | new_mtu += MTU_FUDGE_FACTOR; |
3276fbad | 1882 | if (adapter->physical_port == 0) |
f98a9f69 | 1883 | NXWR32(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu); |
4790654c | 1884 | else |
f98a9f69 | 1885 | NXWR32(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu); |
3d396eb1 AK |
1886 | return 0; |
1887 | } | |
1888 | ||
3176ff3e | 1889 | void netxen_nic_set_link_parameters(struct netxen_adapter *adapter) |
3d396eb1 | 1890 | { |
a608ab9c AV |
1891 | __u32 status; |
1892 | __u32 autoneg; | |
24a7a455 | 1893 | __u32 port_mode; |
3d396eb1 | 1894 | |
c7860a2a DP |
1895 | if (!netif_carrier_ok(adapter->netdev)) { |
1896 | adapter->link_speed = 0; | |
1897 | adapter->link_duplex = -1; | |
1898 | adapter->link_autoneg = AUTONEG_ENABLE; | |
1899 | return; | |
1900 | } | |
24a7a455 | 1901 | |
1e2d0059 | 1902 | if (adapter->ahw.port_type == NETXEN_NIC_GBE) { |
f98a9f69 | 1903 | port_mode = NXRD32(adapter, NETXEN_PORT_MODE_ADDR); |
24a7a455 DP |
1904 | if (port_mode == NETXEN_PORT_MODE_802_3_AP) { |
1905 | adapter->link_speed = SPEED_1000; | |
1906 | adapter->link_duplex = DUPLEX_FULL; | |
1907 | adapter->link_autoneg = AUTONEG_DISABLE; | |
1908 | return; | |
1909 | } | |
1910 | ||
8e95a202 JP |
1911 | if (adapter->phy_read && |
1912 | adapter->phy_read(adapter, | |
1913 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, | |
1914 | &status) == 0) { | |
3d396eb1 AK |
1915 | if (netxen_get_phy_link(status)) { |
1916 | switch (netxen_get_phy_speed(status)) { | |
1917 | case 0: | |
3176ff3e | 1918 | adapter->link_speed = SPEED_10; |
3d396eb1 AK |
1919 | break; |
1920 | case 1: | |
3176ff3e | 1921 | adapter->link_speed = SPEED_100; |
3d396eb1 AK |
1922 | break; |
1923 | case 2: | |
3176ff3e | 1924 | adapter->link_speed = SPEED_1000; |
3d396eb1 AK |
1925 | break; |
1926 | default: | |
c7860a2a | 1927 | adapter->link_speed = 0; |
3d396eb1 AK |
1928 | break; |
1929 | } | |
1930 | switch (netxen_get_phy_duplex(status)) { | |
1931 | case 0: | |
3176ff3e | 1932 | adapter->link_duplex = DUPLEX_HALF; |
3d396eb1 AK |
1933 | break; |
1934 | case 1: | |
3176ff3e | 1935 | adapter->link_duplex = DUPLEX_FULL; |
3d396eb1 AK |
1936 | break; |
1937 | default: | |
3176ff3e | 1938 | adapter->link_duplex = -1; |
3d396eb1 AK |
1939 | break; |
1940 | } | |
8e95a202 JP |
1941 | if (adapter->phy_read && |
1942 | adapter->phy_read(adapter, | |
1943 | NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG, | |
1944 | &autoneg) != 0) | |
3176ff3e | 1945 | adapter->link_autoneg = autoneg; |
3d396eb1 AK |
1946 | } else |
1947 | goto link_down; | |
1948 | } else { | |
1949 | link_down: | |
c7860a2a | 1950 | adapter->link_speed = 0; |
3176ff3e | 1951 | adapter->link_duplex = -1; |
3d396eb1 AK |
1952 | } |
1953 | } | |
1954 | } | |
1955 | ||
0b72e659 DP |
1956 | int |
1957 | netxen_nic_wol_supported(struct netxen_adapter *adapter) | |
1958 | { | |
1959 | u32 wol_cfg; | |
1960 | ||
1961 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | |
1962 | return 0; | |
1963 | ||
f98a9f69 | 1964 | wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV); |
0b72e659 | 1965 | if (wol_cfg & (1UL << adapter->portnum)) { |
f98a9f69 | 1966 | wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG); |
0b72e659 DP |
1967 | if (wol_cfg & (1 << adapter->portnum)) |
1968 | return 1; | |
1969 | } | |
1970 | ||
1971 | return 0; | |
1972 | } |