blob: db53d9cfad07e4ef767421a2b707897f21148190 [file] [log] [blame]
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001/*
Dhananjay Phadke5d242f12009-02-25 15:57:56 +00002 * Copyright (C) 2003 - 2009 NetXen, Inc.
Amit S. Kale3d396eb2006-10-21 15:33:03 -04003 * All rights reserved.
Amit S. Kale80922fb2006-12-04 09:18:00 -08004 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -04005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
Amit S. Kalecb8011a2006-11-29 09:00:10 -08009 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040010 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Amit S. Kalecb8011a2006-11-29 09:00:10 -080014 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040015 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 * MA 02111-1307, USA.
Amit S. Kale80922fb2006-12-04 09:18:00 -080019 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040020 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
Amit S. Kale80922fb2006-12-04 09:18:00 -080022 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040023 * Contact Information:
24 * info@netxen.com
Dhananjay Phadke5d242f12009-02-25 15:57:56 +000025 * NetXen Inc,
26 * 18922 Forge Drive
27 * Cupertino, CA 95014-0701
Amit S. Kale3d396eb2006-10-21 15:33:03 -040028 *
29 */
30
31#include "netxen_nic.h"
32#include "netxen_nic_hw.h"
33#include "netxen_nic_phan_reg.h"
34
Dhananjay Phadkeba599d42009-02-24 16:38:22 -080035#include <linux/firmware.h>
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030036#include <net/ip.h>
37
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070038#define MASK(n) ((1ULL<<(n))-1)
39#define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff))
40#define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff))
41#define MS_WIN(addr) (addr & 0x0ffc0000)
42
43#define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
44
45#define CRB_BLK(off) ((off >> 20) & 0x3f)
46#define CRB_SUBBLK(off) ((off >> 16) & 0xf)
47#define CRB_WINDOW_2M (0x130060)
48#define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000))
49#define CRB_INDIRECT_2M (0x1e0000UL)
50
Dhananjay Phadkee98e3352009-04-07 22:50:38 +000051#ifndef readq
52static inline u64 readq(void __iomem *addr)
53{
54 return readl(addr) | (((u64) readl(addr + 4)) << 32LL);
55}
56#endif
57
58#ifndef writeq
59static inline void writeq(u64 val, void __iomem *addr)
60{
61 writel(((u32) (val)), (addr));
62 writel(((u32) (val >> 32)), (addr + 4));
63}
64#endif
65
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +000066#define ADDR_IN_RANGE(addr, low, high) \
67 (((addr) < (high)) && ((addr) >= (low)))
68
69#define PCI_OFFSET_FIRST_RANGE(adapter, off) \
70 ((adapter)->ahw.pci_base0 + (off))
71#define PCI_OFFSET_SECOND_RANGE(adapter, off) \
72 ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START)
73#define PCI_OFFSET_THIRD_RANGE(adapter, off) \
74 ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START)
75
76static void __iomem *pci_base_offset(struct netxen_adapter *adapter,
77 unsigned long off)
78{
79 if (ADDR_IN_RANGE(off, FIRST_PAGE_GROUP_START, FIRST_PAGE_GROUP_END))
80 return PCI_OFFSET_FIRST_RANGE(adapter, off);
81
82 if (ADDR_IN_RANGE(off, SECOND_PAGE_GROUP_START, SECOND_PAGE_GROUP_END))
83 return PCI_OFFSET_SECOND_RANGE(adapter, off);
84
85 if (ADDR_IN_RANGE(off, THIRD_PAGE_GROUP_START, THIRD_PAGE_GROUP_END))
86 return PCI_OFFSET_THIRD_RANGE(adapter, off);
87
88 return NULL;
89}
90
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070091#define CRB_WIN_LOCK_TIMEOUT 100000000
Dhananjay Phadkeea7eaa32009-04-07 22:50:48 +000092static crb_128M_2M_block_map_t
93crb_128M_2M_map[64] __cacheline_aligned_in_smp = {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070094 {{{0, 0, 0, 0} } }, /* 0: PCI */
95 {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */
96 {1, 0x0110000, 0x0120000, 0x130000},
97 {1, 0x0120000, 0x0122000, 0x124000},
98 {1, 0x0130000, 0x0132000, 0x126000},
99 {1, 0x0140000, 0x0142000, 0x128000},
100 {1, 0x0150000, 0x0152000, 0x12a000},
101 {1, 0x0160000, 0x0170000, 0x110000},
102 {1, 0x0170000, 0x0172000, 0x12e000},
103 {0, 0x0000000, 0x0000000, 0x000000},
104 {0, 0x0000000, 0x0000000, 0x000000},
105 {0, 0x0000000, 0x0000000, 0x000000},
106 {0, 0x0000000, 0x0000000, 0x000000},
107 {0, 0x0000000, 0x0000000, 0x000000},
108 {0, 0x0000000, 0x0000000, 0x000000},
109 {1, 0x01e0000, 0x01e0800, 0x122000},
110 {0, 0x0000000, 0x0000000, 0x000000} } },
111 {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */
112 {{{0, 0, 0, 0} } }, /* 3: */
113 {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */
114 {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */
115 {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */
116 {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */
117 {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */
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 {0, 0x0000000, 0x0000000, 0x000000},
128 {0, 0x0000000, 0x0000000, 0x000000},
129 {0, 0x0000000, 0x0000000, 0x000000},
130 {0, 0x0000000, 0x0000000, 0x000000},
131 {0, 0x0000000, 0x0000000, 0x000000},
132 {1, 0x08f0000, 0x08f2000, 0x172000} } },
133 {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/
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 {0, 0x0000000, 0x0000000, 0x000000},
144 {0, 0x0000000, 0x0000000, 0x000000},
145 {0, 0x0000000, 0x0000000, 0x000000},
146 {0, 0x0000000, 0x0000000, 0x000000},
147 {0, 0x0000000, 0x0000000, 0x000000},
148 {1, 0x09f0000, 0x09f2000, 0x176000} } },
149 {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/
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 {0, 0x0000000, 0x0000000, 0x000000},
160 {0, 0x0000000, 0x0000000, 0x000000},
161 {0, 0x0000000, 0x0000000, 0x000000},
162 {0, 0x0000000, 0x0000000, 0x000000},
163 {0, 0x0000000, 0x0000000, 0x000000},
164 {1, 0x0af0000, 0x0af2000, 0x17a000} } },
165 {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/
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 {0, 0x0000000, 0x0000000, 0x000000},
176 {0, 0x0000000, 0x0000000, 0x000000},
177 {0, 0x0000000, 0x0000000, 0x000000},
178 {0, 0x0000000, 0x0000000, 0x000000},
179 {0, 0x0000000, 0x0000000, 0x000000},
180 {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
181 {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */
182 {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */
183 {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */
184 {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */
185 {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */
186 {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */
187 {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */
188 {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */
189 {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */
190 {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */
191 {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */
192 {{{0, 0, 0, 0} } }, /* 23: */
193 {{{0, 0, 0, 0} } }, /* 24: */
194 {{{0, 0, 0, 0} } }, /* 25: */
195 {{{0, 0, 0, 0} } }, /* 26: */
196 {{{0, 0, 0, 0} } }, /* 27: */
197 {{{0, 0, 0, 0} } }, /* 28: */
198 {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */
199 {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */
200 {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */
201 {{{0} } }, /* 32: PCI */
202 {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */
203 {1, 0x2110000, 0x2120000, 0x130000},
204 {1, 0x2120000, 0x2122000, 0x124000},
205 {1, 0x2130000, 0x2132000, 0x126000},
206 {1, 0x2140000, 0x2142000, 0x128000},
207 {1, 0x2150000, 0x2152000, 0x12a000},
208 {1, 0x2160000, 0x2170000, 0x110000},
209 {1, 0x2170000, 0x2172000, 0x12e000},
210 {0, 0x0000000, 0x0000000, 0x000000},
211 {0, 0x0000000, 0x0000000, 0x000000},
212 {0, 0x0000000, 0x0000000, 0x000000},
213 {0, 0x0000000, 0x0000000, 0x000000},
214 {0, 0x0000000, 0x0000000, 0x000000},
215 {0, 0x0000000, 0x0000000, 0x000000},
216 {0, 0x0000000, 0x0000000, 0x000000},
217 {0, 0x0000000, 0x0000000, 0x000000} } },
218 {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */
219 {{{0} } }, /* 35: */
220 {{{0} } }, /* 36: */
221 {{{0} } }, /* 37: */
222 {{{0} } }, /* 38: */
223 {{{0} } }, /* 39: */
224 {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */
225 {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */
226 {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */
227 {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */
228 {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */
229 {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */
230 {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */
231 {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */
232 {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */
233 {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */
234 {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */
235 {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */
236 {{{0} } }, /* 52: */
237 {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */
238 {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */
239 {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */
240 {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */
241 {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */
242 {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */
243 {{{0} } }, /* 59: I2C0 */
244 {{{0} } }, /* 60: I2C1 */
245 {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */
246 {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */
247 {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */
248};
249
250/*
251 * top 12 bits of crb internal address (hub, agent)
252 */
253static unsigned crb_hub_agt[64] =
254{
255 0,
256 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
257 NETXEN_HW_CRB_HUB_AGT_ADR_MN,
258 NETXEN_HW_CRB_HUB_AGT_ADR_MS,
259 0,
260 NETXEN_HW_CRB_HUB_AGT_ADR_SRE,
261 NETXEN_HW_CRB_HUB_AGT_ADR_NIU,
262 NETXEN_HW_CRB_HUB_AGT_ADR_QMN,
263 NETXEN_HW_CRB_HUB_AGT_ADR_SQN0,
264 NETXEN_HW_CRB_HUB_AGT_ADR_SQN1,
265 NETXEN_HW_CRB_HUB_AGT_ADR_SQN2,
266 NETXEN_HW_CRB_HUB_AGT_ADR_SQN3,
267 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
268 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
269 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
270 NETXEN_HW_CRB_HUB_AGT_ADR_PGN4,
271 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
272 NETXEN_HW_CRB_HUB_AGT_ADR_PGN0,
273 NETXEN_HW_CRB_HUB_AGT_ADR_PGN1,
274 NETXEN_HW_CRB_HUB_AGT_ADR_PGN2,
275 NETXEN_HW_CRB_HUB_AGT_ADR_PGN3,
276 NETXEN_HW_CRB_HUB_AGT_ADR_PGND,
277 NETXEN_HW_CRB_HUB_AGT_ADR_PGNI,
278 NETXEN_HW_CRB_HUB_AGT_ADR_PGS0,
279 NETXEN_HW_CRB_HUB_AGT_ADR_PGS1,
280 NETXEN_HW_CRB_HUB_AGT_ADR_PGS2,
281 NETXEN_HW_CRB_HUB_AGT_ADR_PGS3,
282 0,
283 NETXEN_HW_CRB_HUB_AGT_ADR_PGSI,
284 NETXEN_HW_CRB_HUB_AGT_ADR_SN,
285 0,
286 NETXEN_HW_CRB_HUB_AGT_ADR_EG,
287 0,
288 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
289 NETXEN_HW_CRB_HUB_AGT_ADR_CAM,
290 0,
291 0,
292 0,
293 0,
294 0,
295 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
296 0,
297 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1,
298 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2,
299 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3,
300 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4,
301 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5,
302 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6,
303 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7,
304 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
305 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
306 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
307 0,
308 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0,
309 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8,
310 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9,
311 NETXEN_HW_CRB_HUB_AGT_ADR_OCM0,
312 0,
313 NETXEN_HW_CRB_HUB_AGT_ADR_SMB,
314 NETXEN_HW_CRB_HUB_AGT_ADR_I2C0,
315 NETXEN_HW_CRB_HUB_AGT_ADR_I2C1,
316 0,
317 NETXEN_HW_CRB_HUB_AGT_ADR_PGNC,
318 0,
319};
320
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400321/* PCI Windowing for DDR regions. */
322
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700323#define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400324
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400325int netxen_nic_set_mac(struct net_device *netdev, void *p)
326{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700327 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400328 struct sockaddr *addr = p;
329
330 if (netif_running(netdev))
331 return -EBUSY;
332
333 if (!is_valid_ether_addr(addr->sa_data))
334 return -EADDRNOTAVAIL;
335
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400336 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
337
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700338 /* For P3, MAC addr is not set in NIU */
339 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
340 if (adapter->macaddr_set)
341 adapter->macaddr_set(adapter, addr->sa_data);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400342
343 return 0;
344}
345
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700346#define NETXEN_UNICAST_ADDR(port, index) \
347 (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8))
348#define NETXEN_MCAST_ADDR(port, index) \
349 (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8))
350#define MAC_HI(addr) \
351 ((addr[2] << 16) | (addr[1] << 8) | (addr[0]))
352#define MAC_LO(addr) \
353 ((addr[5] << 16) | (addr[4] << 8) | (addr[3]))
354
355static int
356netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter)
357{
358 u32 val = 0;
359 u16 port = adapter->physical_port;
360 u8 *addr = adapter->netdev->dev_addr;
361
362 if (adapter->mc_enabled)
363 return 0;
364
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000365 val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700366 val |= (1UL << (28+port));
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000367 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700368
369 /* add broadcast addr to filter */
370 val = 0xffffff;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000371 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
372 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700373
374 /* add station addr to filter */
375 val = MAC_HI(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000376 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700377 val = MAC_LO(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000378 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700379
380 adapter->mc_enabled = 1;
381 return 0;
382}
383
384static int
385netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter)
386{
387 u32 val = 0;
388 u16 port = adapter->physical_port;
389 u8 *addr = adapter->netdev->dev_addr;
390
391 if (!adapter->mc_enabled)
392 return 0;
393
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000394 val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700395 val &= ~(1UL << (28+port));
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000396 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700397
398 val = MAC_HI(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000399 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700400 val = MAC_LO(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000401 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700402
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000403 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), 0);
404 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700405
406 adapter->mc_enabled = 0;
407 return 0;
408}
409
410static int
411netxen_nic_set_mcast_addr(struct netxen_adapter *adapter,
412 int index, u8 *addr)
413{
414 u32 hi = 0, lo = 0;
415 u16 port = adapter->physical_port;
416
417 lo = MAC_LO(addr);
418 hi = MAC_HI(addr);
419
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000420 NXWR32(adapter, NETXEN_MCAST_ADDR(port, index), hi);
421 NXWR32(adapter, NETXEN_MCAST_ADDR(port, index)+4, lo);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700422
423 return 0;
424}
425
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700426void netxen_p2_nic_set_multi(struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400427{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700428 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400429 struct dev_mc_list *mc_ptr;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700430 u8 null_addr[6];
431 int index = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400432
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700433 memset(null_addr, 0, 6);
434
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400435 if (netdev->flags & IFF_PROMISC) {
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700436
437 adapter->set_promisc(adapter,
438 NETXEN_NIU_PROMISC_MODE);
439
440 /* Full promiscuous mode */
441 netxen_nic_disable_mcast_filter(adapter);
442
443 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400444 }
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700445
446 if (netdev->mc_count == 0) {
447 adapter->set_promisc(adapter,
448 NETXEN_NIU_NON_PROMISC_MODE);
449 netxen_nic_disable_mcast_filter(adapter);
450 return;
451 }
452
453 adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE);
454 if (netdev->flags & IFF_ALLMULTI ||
455 netdev->mc_count > adapter->max_mc_count) {
456 netxen_nic_disable_mcast_filter(adapter);
457 return;
458 }
459
460 netxen_nic_enable_mcast_filter(adapter);
461
462 for (mc_ptr = netdev->mc_list; mc_ptr; mc_ptr = mc_ptr->next, index++)
463 netxen_nic_set_mcast_addr(adapter, index, mc_ptr->dmi_addr);
464
465 if (index != netdev->mc_count)
466 printk(KERN_WARNING "%s: %s multicast address count mismatch\n",
467 netxen_nic_driver_name, netdev->name);
468
469 /* Clear out remaining addresses */
470 for (; index < adapter->max_mc_count; index++)
471 netxen_nic_set_mcast_addr(adapter, index, null_addr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400472}
473
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700474static int nx_p3_nic_add_mac(struct netxen_adapter *adapter,
475 u8 *addr, nx_mac_list_t **add_list, nx_mac_list_t **del_list)
476{
477 nx_mac_list_t *cur, *prev;
478
479 /* if in del_list, move it to adapter->mac_list */
480 for (cur = *del_list, prev = NULL; cur;) {
481 if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) {
482 if (prev == NULL)
483 *del_list = cur->next;
484 else
485 prev->next = cur->next;
486 cur->next = adapter->mac_list;
487 adapter->mac_list = cur;
488 return 0;
489 }
490 prev = cur;
491 cur = cur->next;
492 }
493
494 /* make sure to add each mac address only once */
495 for (cur = adapter->mac_list; cur; cur = cur->next) {
496 if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0)
497 return 0;
498 }
499 /* not in del_list, create new entry and add to add_list */
500 cur = kmalloc(sizeof(*cur), in_atomic()? GFP_ATOMIC : GFP_KERNEL);
501 if (cur == NULL) {
502 printk(KERN_ERR "%s: cannot allocate memory. MAC filtering may"
503 "not work properly from now.\n", __func__);
504 return -1;
505 }
506
507 memcpy(cur->mac_addr, addr, ETH_ALEN);
508 cur->next = *add_list;
509 *add_list = cur;
510 return 0;
511}
512
513static int
514netxen_send_cmd_descs(struct netxen_adapter *adapter,
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000515 struct cmd_desc_type0 *cmd_desc_arr, int nr_desc)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700516{
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000517 u32 i, producer, consumer;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700518 struct netxen_cmd_buffer *pbuf;
519 struct cmd_desc_type0 *cmd_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000520 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700521
522 i = 0;
523
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000524 tx_ring = adapter->tx_ring;
Dhananjay Phadke03e678e2009-01-14 20:49:43 -0800525 netif_tx_lock_bh(adapter->netdev);
526
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000527 producer = tx_ring->producer;
528 consumer = tx_ring->sw_consumer;
529
530 if (nr_desc > find_diff_among(producer, consumer, tx_ring->num_desc)) {
531 netif_tx_unlock_bh(adapter->netdev);
532 return -EBUSY;
533 }
534
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700535 do {
536 cmd_desc = &cmd_desc_arr[i];
537
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000538 pbuf = &tx_ring->cmd_buf_arr[producer];
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700539 pbuf->skb = NULL;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700540 pbuf->frag_count = 0;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700541
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000542 memcpy(&tx_ring->desc_head[producer],
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700543 &cmd_desc_arr[i], sizeof(struct cmd_desc_type0));
544
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000545 producer = get_next_index(producer, tx_ring->num_desc);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700546 i++;
547
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000548 } while (i != nr_desc);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700549
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000550 tx_ring->producer = producer;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700551
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000552 netxen_nic_update_cmd_producer(adapter, tx_ring, producer);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700553
Dhananjay Phadke03e678e2009-01-14 20:49:43 -0800554 netif_tx_unlock_bh(adapter->netdev);
555
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700556 return 0;
557}
558
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700559static int nx_p3_sre_macaddr_change(struct net_device *dev,
560 u8 *addr, unsigned op)
561{
Wang Chen4cf16532008-11-12 23:38:14 -0800562 struct netxen_adapter *adapter = netdev_priv(dev);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700563 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800564 nx_mac_req_t *mac_req;
565 u64 word;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700566 int rv;
567
568 memset(&req, 0, sizeof(nx_nic_req_t));
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800569 req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23);
570
571 word = NX_MAC_EVENT | ((u64)adapter->portnum << 16);
572 req.req_hdr = cpu_to_le64(word);
573
574 mac_req = (nx_mac_req_t *)&req.words[0];
575 mac_req->op = op;
576 memcpy(mac_req->mac_addr, addr, 6);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700577
578 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
579 if (rv != 0) {
580 printk(KERN_ERR "ERROR. Could not send mac update\n");
581 return rv;
582 }
583
584 return 0;
585}
586
587void netxen_p3_nic_set_multi(struct net_device *netdev)
588{
589 struct netxen_adapter *adapter = netdev_priv(netdev);
590 nx_mac_list_t *cur, *next, *del_list, *add_list = NULL;
591 struct dev_mc_list *mc_ptr;
592 u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700593 u32 mode = VPORT_MISS_MODE_DROP;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700594
595 del_list = adapter->mac_list;
596 adapter->mac_list = NULL;
597
598 nx_p3_nic_add_mac(adapter, netdev->dev_addr, &add_list, &del_list);
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700599 nx_p3_nic_add_mac(adapter, bcast_addr, &add_list, &del_list);
600
601 if (netdev->flags & IFF_PROMISC) {
602 mode = VPORT_MISS_MODE_ACCEPT_ALL;
603 goto send_fw_cmd;
604 }
605
606 if ((netdev->flags & IFF_ALLMULTI) ||
607 (netdev->mc_count > adapter->max_mc_count)) {
608 mode = VPORT_MISS_MODE_ACCEPT_MULTI;
609 goto send_fw_cmd;
610 }
611
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700612 if (netdev->mc_count > 0) {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700613 for (mc_ptr = netdev->mc_list; mc_ptr;
614 mc_ptr = mc_ptr->next) {
615 nx_p3_nic_add_mac(adapter, mc_ptr->dmi_addr,
616 &add_list, &del_list);
617 }
618 }
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700619
620send_fw_cmd:
621 adapter->set_promisc(adapter, mode);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700622 for (cur = del_list; cur;) {
623 nx_p3_sre_macaddr_change(netdev, cur->mac_addr, NETXEN_MAC_DEL);
624 next = cur->next;
625 kfree(cur);
626 cur = next;
627 }
628 for (cur = add_list; cur;) {
629 nx_p3_sre_macaddr_change(netdev, cur->mac_addr, NETXEN_MAC_ADD);
630 next = cur->next;
631 cur->next = adapter->mac_list;
632 adapter->mac_list = cur;
633 cur = next;
634 }
635}
636
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700637int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
638{
639 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800640 u64 word;
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700641
642 memset(&req, 0, sizeof(nx_nic_req_t));
643
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800644 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
645
646 word = NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE |
647 ((u64)adapter->portnum << 16);
648 req.req_hdr = cpu_to_le64(word);
649
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700650 req.words[0] = cpu_to_le64(mode);
651
652 return netxen_send_cmd_descs(adapter,
653 (struct cmd_desc_type0 *)&req, 1);
654}
655
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800656void netxen_p3_free_mac_list(struct netxen_adapter *adapter)
657{
658 nx_mac_list_t *cur, *next;
659
660 cur = adapter->mac_list;
661
662 while (cur) {
663 next = cur->next;
664 kfree(cur);
665 cur = next;
666 }
667}
668
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700669#define NETXEN_CONFIG_INTR_COALESCE 3
670
671/*
672 * Send the interrupt coalescing parameter set by ethtool to the card.
673 */
674int netxen_config_intr_coalesce(struct netxen_adapter *adapter)
675{
676 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800677 u64 word;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700678 int rv;
679
680 memset(&req, 0, sizeof(nx_nic_req_t));
681
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800682 req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23);
683
684 word = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16);
685 req.req_hdr = cpu_to_le64(word);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700686
687 memcpy(&req.words[0], &adapter->coal, sizeof(adapter->coal));
688
689 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
690 if (rv != 0) {
691 printk(KERN_ERR "ERROR. Could not send "
692 "interrupt coalescing parameters\n");
693 }
694
695 return rv;
696}
697
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000698#define RSS_HASHTYPE_IP_TCP 0x3
699
700int netxen_config_rss(struct netxen_adapter *adapter, int enable)
701{
702 nx_nic_req_t req;
703 u64 word;
704 int i, rv;
705
706 u64 key[] = { 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL,
707 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
708 0x255b0ec26d5a56daULL };
709
710
711 memset(&req, 0, sizeof(nx_nic_req_t));
712 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
713
714 word = NX_NIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16);
715 req.req_hdr = cpu_to_le64(word);
716
717 /*
718 * RSS request:
719 * bits 3-0: hash_method
720 * 5-4: hash_type_ipv4
721 * 7-6: hash_type_ipv6
722 * 8: enable
723 * 9: use indirection table
724 * 47-10: reserved
725 * 63-48: indirection table mask
726 */
727 word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) |
728 ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) |
729 ((u64)(enable & 0x1) << 8) |
730 ((0x7ULL) << 48);
731 req.words[0] = cpu_to_le64(word);
732 for (i = 0; i < 5; i++)
733 req.words[i+1] = cpu_to_le64(key[i]);
734
735
736 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
737 if (rv != 0) {
738 printk(KERN_ERR "%s: could not configure RSS\n",
739 adapter->netdev->name);
740 }
741
742 return rv;
743}
744
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000745int netxen_linkevent_request(struct netxen_adapter *adapter, int enable)
746{
747 nx_nic_req_t req;
748 u64 word;
749 int rv;
750
751 memset(&req, 0, sizeof(nx_nic_req_t));
752 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
753
754 word = NX_NIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16);
755 req.req_hdr = cpu_to_le64(word);
756 req.words[0] = cpu_to_le64(enable);
757
758 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
759 if (rv != 0) {
760 printk(KERN_ERR "%s: could not configure link notification\n",
761 adapter->netdev->name);
762 }
763
764 return rv;
765}
766
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400767/*
768 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
769 * @returns 0 on success, negative on failure
770 */
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700771
772#define MTU_FUDGE_FACTOR 100
773
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400774int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
775{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700776 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700777 int max_mtu;
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700778 int rc = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400779
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700780 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
781 max_mtu = P3_MAX_MTU;
782 else
783 max_mtu = P2_MAX_MTU;
784
785 if (mtu > max_mtu) {
786 printk(KERN_ERR "%s: mtu > %d bytes unsupported\n",
787 netdev->name, max_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400788 return -EINVAL;
789 }
790
Amit S. Kale80922fb2006-12-04 09:18:00 -0800791 if (adapter->set_mtu)
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700792 rc = adapter->set_mtu(adapter, mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400793
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700794 if (!rc)
795 netdev->mtu = mtu;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700796
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700797 return rc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400798}
799
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400800static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
Al Virof305f782007-12-22 19:44:00 +0000801 int size, __le32 * buf)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400802{
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000803 int i, v, addr;
Al Virof305f782007-12-22 19:44:00 +0000804 __le32 *ptr32;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400805
806 addr = base;
807 ptr32 = buf;
808 for (i = 0; i < size / sizeof(u32); i++) {
Al Virof305f782007-12-22 19:44:00 +0000809 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400810 return -1;
Al Virof305f782007-12-22 19:44:00 +0000811 *ptr32 = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400812 ptr32++;
813 addr += sizeof(u32);
814 }
815 if ((char *)buf + size > (char *)ptr32) {
Al Virof305f782007-12-22 19:44:00 +0000816 __le32 local;
817 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400818 return -1;
Al Virof305f782007-12-22 19:44:00 +0000819 local = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400820 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
821 }
822
823 return 0;
824}
825
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700826int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 *mac)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400827{
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700828 __le32 *pmac = (__le32 *) mac;
829 u32 offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400830
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700831 offset = NETXEN_USER_START +
832 offsetof(struct netxen_new_user_info, mac_addr) +
833 adapter->portnum * sizeof(u64);
834
835 if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400836 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700837
Al Virof305f782007-12-22 19:44:00 +0000838 if (*mac == cpu_to_le64(~0ULL)) {
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700839
840 offset = NETXEN_USER_START_OLD +
841 offsetof(struct netxen_user_old_info, mac_addr) +
842 adapter->portnum * sizeof(u64);
843
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400844 if (netxen_get_flash_block(adapter,
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700845 offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400846 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700847
Al Virof305f782007-12-22 19:44:00 +0000848 if (*mac == cpu_to_le64(~0ULL))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400849 return -1;
850 }
851 return 0;
852}
853
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700854int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, __le64 *mac)
855{
856 uint32_t crbaddr, mac_hi, mac_lo;
857 int pci_func = adapter->ahw.pci_func;
858
859 crbaddr = CRB_MAC_BLOCK_START +
860 (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1));
861
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000862 mac_lo = NXRD32(adapter, crbaddr);
863 mac_hi = NXRD32(adapter, crbaddr+4);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700864
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700865 if (pci_func & 1)
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800866 *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700867 else
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800868 *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700869
870 return 0;
871}
872
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700873#define CRB_WIN_LOCK_TIMEOUT 100000000
874
875static int crb_win_lock(struct netxen_adapter *adapter)
876{
877 int done = 0, timeout = 0;
878
879 while (!done) {
880 /* acquire semaphore3 from PCI HW block */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000881 done = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM7_LOCK));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700882 if (done == 1)
883 break;
884 if (timeout >= CRB_WIN_LOCK_TIMEOUT)
885 return -1;
886 timeout++;
887 udelay(1);
888 }
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000889 NXWR32(adapter, NETXEN_CRB_WIN_LOCK_ID, adapter->portnum);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700890 return 0;
891}
892
893static void crb_win_unlock(struct netxen_adapter *adapter)
894{
895 int val;
896
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000897 val = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM7_UNLOCK));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700898}
899
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400900/*
901 * Changes the CRB window to the specified window.
902 */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700903void
904netxen_nic_pci_change_crbwindow_128M(struct netxen_adapter *adapter, u32 wndw)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400905{
906 void __iomem *offset;
907 u32 tmp;
908 int count = 0;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700909 uint8_t func = adapter->ahw.pci_func;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400910
911 if (adapter->curr_window == wndw)
912 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400913 /*
914 * Move the CRB window.
915 * We need to write to the "direct access" region of PCI
916 * to avoid a race condition where the window register has
917 * not been successfully written across CRB before the target
918 * register address is received by PCI. The direct region bypasses
919 * the CRB bus.
920 */
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700921 offset = PCI_OFFSET_SECOND_RANGE(adapter,
922 NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400923
924 if (wndw & 0x1)
925 wndw = NETXEN_WINDOW_ONE;
926
927 writel(wndw, offset);
928
929 /* MUST make sure window is set before we forge on... */
930 while ((tmp = readl(offset)) != wndw) {
931 printk(KERN_WARNING "%s: %s WARNING: CRB window value not "
932 "registered properly: 0x%08x.\n",
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700933 netxen_nic_driver_name, __func__, tmp);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400934 mdelay(1);
935 if (count >= 10)
936 break;
937 count++;
938 }
939
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700940 if (wndw == NETXEN_WINDOW_ONE)
941 adapter->curr_window = 1;
942 else
943 adapter->curr_window = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400944}
945
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700946/*
947 * Return -1 if off is not valid,
948 * 1 if window access is needed. 'off' is set to offset from
949 * CRB space in 128M pci map
950 * 0 if no window access is needed. 'off' is set to 2M addr
951 * In: 'off' is offset from base in 128M pci map
952 */
953static int
954netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter,
955 ulong *off, int len)
956{
957 unsigned long end = *off + len;
958 crb_128M_2M_sub_block_map_t *m;
959
960
961 if (*off >= NETXEN_CRB_MAX)
962 return -1;
963
964 if (*off >= NETXEN_PCI_CAMQM && (end <= NETXEN_PCI_CAMQM_2M_END)) {
965 *off = (*off - NETXEN_PCI_CAMQM) + NETXEN_PCI_CAMQM_2M_BASE +
966 (ulong)adapter->ahw.pci_base0;
967 return 0;
968 }
969
970 if (*off < NETXEN_PCI_CRBSPACE)
971 return -1;
972
973 *off -= NETXEN_PCI_CRBSPACE;
974 end = *off + len;
975
976 /*
977 * Try direct map
978 */
979 m = &crb_128M_2M_map[CRB_BLK(*off)].sub_block[CRB_SUBBLK(*off)];
980
981 if (m->valid && (m->start_128M <= *off) && (m->end_128M >= end)) {
982 *off = *off + m->start_2M - m->start_128M +
983 (ulong)adapter->ahw.pci_base0;
984 return 0;
985 }
986
987 /*
988 * Not in direct map, use crb window
989 */
990 return 1;
991}
992
993/*
994 * In: 'off' is offset from CRB space in 128M pci map
995 * Out: 'off' is 2M pci map addr
996 * side effect: lock crb window
997 */
998static void
999netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong *off)
1000{
1001 u32 win_read;
1002
1003 adapter->crb_win = CRB_HI(*off);
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001004 writel(adapter->crb_win, (adapter->ahw.pci_base0 + CRB_WINDOW_2M));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001005 /*
1006 * Read back value to make sure write has gone through before trying
1007 * to use it.
1008 */
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001009 win_read = readl(adapter->ahw.pci_base0 + CRB_WINDOW_2M);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001010 if (win_read != adapter->crb_win) {
1011 printk(KERN_ERR "%s: Written crbwin (0x%x) != "
1012 "Read crbwin (0x%x), off=0x%lx\n",
1013 __func__, adapter->crb_win, win_read, *off);
1014 }
1015 *off = (*off & MASK(16)) + CRB_INDIRECT_2M +
1016 (ulong)adapter->ahw.pci_base0;
1017}
1018
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001019static int
1020netxen_do_load_firmware(struct netxen_adapter *adapter, const char *fwname,
1021 const struct firmware *fw)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001022{
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001023 u64 *ptr64;
1024 u32 i, flashaddr, size;
1025 struct pci_dev *pdev = adapter->pdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001026
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001027 if (fw)
1028 dev_info(&pdev->dev, "loading firmware from file %s\n", fwname);
1029 else
1030 dev_info(&pdev->dev, "loading firmware from flash\n");
Dhananjay Phadke29566402008-07-21 19:44:04 -07001031
1032 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001033 NXWR32(adapter, NETXEN_ROMUSB_GLB_CAS_RST, 1);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001034
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001035 if (fw) {
1036 __le64 data;
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301037
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001038 size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 8;
1039
1040 ptr64 = (u64 *)&fw->data[NETXEN_BOOTLD_START];
1041 flashaddr = NETXEN_BOOTLD_START;
1042
1043 for (i = 0; i < size; i++) {
1044 data = cpu_to_le64(ptr64[i]);
1045 adapter->pci_mem_write(adapter, flashaddr, &data, 8);
1046 flashaddr += 8;
1047 }
1048
1049 size = *(u32 *)&fw->data[NX_FW_SIZE_OFFSET];
1050 size = (__force u32)cpu_to_le32(size) / 8;
1051
1052 ptr64 = (u64 *)&fw->data[NETXEN_IMAGE_START];
1053 flashaddr = NETXEN_IMAGE_START;
1054
1055 for (i = 0; i < size; i++) {
1056 data = cpu_to_le64(ptr64[i]);
1057
1058 if (adapter->pci_mem_write(adapter,
1059 flashaddr, &data, 8))
1060 return -EIO;
1061
1062 flashaddr += 8;
1063 }
1064 } else {
1065 u32 data;
1066
1067 size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 4;
1068 flashaddr = NETXEN_BOOTLD_START;
1069
1070 for (i = 0; i < size; i++) {
1071 if (netxen_rom_fast_read(adapter,
1072 flashaddr, (int *)&data) != 0)
1073 return -EIO;
1074
1075 if (adapter->pci_mem_write(adapter,
1076 flashaddr, &data, 4))
1077 return -EIO;
1078
1079 flashaddr += 4;
1080 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001081 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001082 msleep(1);
1083
1084 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001085 NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0x80001d);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001086 else {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001087 NXWR32(adapter, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL, 0x3fff);
1088 NXWR32(adapter, NETXEN_ROMUSB_GLB_CAS_RST, 0);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001089 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001090
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301091 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001092}
1093
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001094static int
1095netxen_validate_firmware(struct netxen_adapter *adapter, const char *fwname,
1096 const struct firmware *fw)
1097{
1098 __le32 val;
1099 u32 major, minor, build, ver, min_ver, bios;
1100 struct pci_dev *pdev = adapter->pdev;
1101
1102 if (fw->size < NX_FW_MIN_SIZE)
1103 return -EINVAL;
1104
1105 val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_MAGIC_OFFSET]);
1106 if ((__force u32)val != NETXEN_BDINFO_MAGIC)
1107 return -EINVAL;
1108
1109 val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_VERSION_OFFSET]);
1110 major = (__force u32)val & 0xff;
1111 minor = ((__force u32)val >> 8) & 0xff;
1112 build = (__force u32)val >> 16;
1113
1114 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1115 min_ver = NETXEN_VERSION_CODE(4, 0, 216);
1116 else
1117 min_ver = NETXEN_VERSION_CODE(3, 4, 216);
1118
1119 ver = NETXEN_VERSION_CODE(major, minor, build);
1120
1121 if ((major > _NETXEN_NIC_LINUX_MAJOR) || (ver < min_ver)) {
1122 dev_err(&pdev->dev,
1123 "%s: firmware version %d.%d.%d unsupported\n",
1124 fwname, major, minor, build);
1125 return -EINVAL;
1126 }
1127
1128 val = cpu_to_le32(*(u32 *)&fw->data[NX_BIOS_VERSION_OFFSET]);
1129 netxen_rom_fast_read(adapter, NX_BIOS_VERSION_OFFSET, (int *)&bios);
1130 if ((__force u32)val != bios) {
1131 dev_err(&pdev->dev, "%s: firmware bios is incompatible\n",
1132 fwname);
1133 return -EINVAL;
1134 }
1135
Dhananjay Phadke567c6c42009-03-02 16:02:17 +00001136 /* check if flashed firmware is newer */
1137 if (netxen_rom_fast_read(adapter,
1138 NX_FW_VERSION_OFFSET, (int *)&val))
1139 return -EIO;
1140 major = (__force u32)val & 0xff;
1141 minor = ((__force u32)val >> 8) & 0xff;
1142 build = (__force u32)val >> 16;
1143 if (NETXEN_VERSION_CODE(major, minor, build) > ver)
1144 return -EINVAL;
1145
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001146 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001147 return 0;
1148}
1149
Dhananjay Phadkebd257ed2009-03-17 13:14:22 -07001150static char *fw_name[] = { "nxromimg.bin", "nx3fwct.bin", "nx3fwmn.bin" };
1151
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001152int netxen_load_firmware(struct netxen_adapter *adapter)
1153{
1154 u32 capability, flashed_ver;
1155 const struct firmware *fw;
Dhananjay Phadkebd257ed2009-03-17 13:14:22 -07001156 int fw_type;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001157 struct pci_dev *pdev = adapter->pdev;
1158 int rc = 0;
1159
1160 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkebd257ed2009-03-17 13:14:22 -07001161 fw_type = NX_P2_MN_ROMIMAGE;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001162 goto request_fw;
Dhananjay Phadkebd257ed2009-03-17 13:14:22 -07001163 } else {
1164 fw_type = NX_P3_CT_ROMIMAGE;
Dhananjay Phadke567c6c42009-03-02 16:02:17 +00001165 goto request_fw;
1166 }
1167
1168request_mn:
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001169 capability = 0;
1170
1171 netxen_rom_fast_read(adapter,
1172 NX_FW_VERSION_OFFSET, (int *)&flashed_ver);
1173 if (flashed_ver >= NETXEN_VERSION_CODE(4, 0, 220)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001174 capability = NXRD32(adapter, NX_PEG_TUNE_CAPABILITY);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001175 if (capability & NX_PEG_TUNE_MN_PRESENT) {
Dhananjay Phadkebd257ed2009-03-17 13:14:22 -07001176 fw_type = NX_P3_MN_ROMIMAGE;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001177 goto request_fw;
1178 }
1179 }
1180
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001181request_fw:
Dhananjay Phadkebd257ed2009-03-17 13:14:22 -07001182 rc = request_firmware(&fw, fw_name[fw_type], &pdev->dev);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001183 if (rc != 0) {
Dhananjay Phadkebd257ed2009-03-17 13:14:22 -07001184 if (fw_type == NX_P3_CT_ROMIMAGE) {
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001185 msleep(1);
Dhananjay Phadke567c6c42009-03-02 16:02:17 +00001186 goto request_mn;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001187 }
1188
1189 fw = NULL;
1190 goto load_fw;
1191 }
1192
Dhananjay Phadkebd257ed2009-03-17 13:14:22 -07001193 rc = netxen_validate_firmware(adapter, fw_name[fw_type], fw);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001194 if (rc != 0) {
1195 release_firmware(fw);
1196
Dhananjay Phadkebd257ed2009-03-17 13:14:22 -07001197 if (fw_type == NX_P3_CT_ROMIMAGE) {
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001198 msleep(1);
Dhananjay Phadke567c6c42009-03-02 16:02:17 +00001199 goto request_mn;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001200 }
1201
1202 fw = NULL;
1203 }
1204
1205load_fw:
Dhananjay Phadkebd257ed2009-03-17 13:14:22 -07001206 rc = netxen_do_load_firmware(adapter, fw_name[fw_type], fw);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -08001207
1208 if (fw)
1209 release_firmware(fw);
1210 return rc;
1211}
1212
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001213int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001214netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001215{
1216 void __iomem *addr;
1217
1218 if (ADDR_IN_WINDOW1(off)) {
1219 addr = NETXEN_CRB_NORMALIZE(adapter, off);
1220 } else { /* Window 0 */
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001221 addr = pci_base_offset(adapter, off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001222 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001223 }
1224
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001225 if (!addr) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001226 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001227 return 1;
1228 }
1229
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001230 writel(data, addr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001231
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001232 if (!ADDR_IN_WINDOW1(off))
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001233 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001234
1235 return 0;
1236}
1237
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001238u32
1239netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001240{
1241 void __iomem *addr;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001242 u32 data;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001243
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001244 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
1245 addr = NETXEN_CRB_NORMALIZE(adapter, off);
1246 } else { /* Window 0 */
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001247 addr = pci_base_offset(adapter, off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001248 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001249 }
1250
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001251 if (!addr) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001252 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001253 return 1;
1254 }
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001255
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001256 data = readl(addr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001257
1258 if (!ADDR_IN_WINDOW1(off))
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001259 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1260
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001261 return data;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001262}
1263
1264int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001265netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001266{
1267 unsigned long flags = 0;
1268 int rv;
1269
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001270 rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off, 4);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001271
1272 if (rv == -1) {
1273 printk(KERN_ERR "%s: invalid offset: 0x%016lx\n",
1274 __func__, off);
1275 dump_stack();
1276 return -1;
1277 }
1278
1279 if (rv == 1) {
1280 write_lock_irqsave(&adapter->adapter_lock, flags);
1281 crb_win_lock(adapter);
1282 netxen_nic_pci_set_crbwindow_2M(adapter, &off);
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001283 writel(data, (void __iomem *)off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001284 crb_win_unlock(adapter);
1285 write_unlock_irqrestore(&adapter->adapter_lock, flags);
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001286 } else
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001287 writel(data, (void __iomem *)off);
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001288
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001289
1290 return 0;
1291}
1292
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001293u32
1294netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001295{
1296 unsigned long flags = 0;
1297 int rv;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001298 u32 data;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001299
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001300 rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off, 4);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001301
1302 if (rv == -1) {
1303 printk(KERN_ERR "%s: invalid offset: 0x%016lx\n",
1304 __func__, off);
1305 dump_stack();
1306 return -1;
1307 }
1308
1309 if (rv == 1) {
1310 write_lock_irqsave(&adapter->adapter_lock, flags);
1311 crb_win_lock(adapter);
1312 netxen_nic_pci_set_crbwindow_2M(adapter, &off);
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001313 data = readl((void __iomem *)off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001314 crb_win_unlock(adapter);
1315 write_unlock_irqrestore(&adapter->adapter_lock, flags);
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001316 } else
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001317 data = readl((void __iomem *)off);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001318
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001319 return data;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001320}
1321
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001322/*
1323 * check memory access boundary.
1324 * used by test agent. support ddr access only for now
1325 */
1326static unsigned long
1327netxen_nic_pci_mem_bound_check(struct netxen_adapter *adapter,
1328 unsigned long long addr, int size)
1329{
1330 if (!ADDR_IN_RANGE(addr,
1331 NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX) ||
1332 !ADDR_IN_RANGE(addr+size-1,
1333 NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX) ||
1334 ((size != 1) && (size != 2) && (size != 4) && (size != 8))) {
1335 return 0;
1336 }
1337
1338 return 1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001339}
1340
Jeff Garzik47906542007-11-23 21:23:36 -05001341static int netxen_pci_set_window_warning_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001342
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001343unsigned long
1344netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
1345 unsigned long long addr)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001346{
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001347 void __iomem *offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001348 int window;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001349 unsigned long long qdr_max;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001350 uint8_t func = adapter->ahw.pci_func;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001351
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001352 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1353 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P2;
1354 } else {
1355 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P3;
1356 }
1357
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001358 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1359 /* DDR network side */
1360 addr -= NETXEN_ADDR_DDR_NET;
1361 window = (addr >> 25) & 0x3ff;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001362 if (adapter->ahw.ddr_mn_window != window) {
1363 adapter->ahw.ddr_mn_window = window;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001364 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1365 NETXEN_PCIX_PH_REG(PCIE_MN_WINDOW_REG(func)));
1366 writel(window, offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001367 /* MUST make sure window is set before we forge on... */
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001368 readl(offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001369 }
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001370 addr -= (window * NETXEN_WINDOW_ONE);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001371 addr += NETXEN_PCI_DDR_NET;
1372 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1373 addr -= NETXEN_ADDR_OCM0;
1374 addr += NETXEN_PCI_OCM0;
1375 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1376 addr -= NETXEN_ADDR_OCM1;
1377 addr += NETXEN_PCI_OCM1;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001378 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_QDR_NET, qdr_max)) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001379 /* QDR network side */
1380 addr -= NETXEN_ADDR_QDR_NET;
1381 window = (addr >> 22) & 0x3f;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001382 if (adapter->ahw.qdr_sn_window != window) {
1383 adapter->ahw.qdr_sn_window = window;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001384 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1385 NETXEN_PCIX_PH_REG(PCIE_SN_WINDOW_REG(func)));
1386 writel((window << 22), offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001387 /* MUST make sure window is set before we forge on... */
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001388 readl(offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001389 }
1390 addr -= (window * 0x400000);
1391 addr += NETXEN_PCI_QDR_NET;
1392 } else {
1393 /*
1394 * peg gdb frequently accesses memory that doesn't exist,
1395 * this limits the chit chat so debugging isn't slowed down.
1396 */
1397 if ((netxen_pci_set_window_warning_count++ < 8)
1398 || (netxen_pci_set_window_warning_count % 64 == 0))
1399 printk("%s: Warning:netxen_nic_pci_set_window()"
1400 " Unknown address range!\n",
1401 netxen_nic_driver_name);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001402 addr = -1UL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001403 }
1404 return addr;
1405}
1406
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001407/*
1408 * Note : only 32-bit writes!
1409 */
1410int netxen_nic_pci_write_immediate_128M(struct netxen_adapter *adapter,
1411 u64 off, u32 data)
1412{
1413 writel(data, (void __iomem *)(PCI_OFFSET_SECOND_RANGE(adapter, off)));
1414 return 0;
1415}
1416
1417u32 netxen_nic_pci_read_immediate_128M(struct netxen_adapter *adapter, u64 off)
1418{
1419 return readl((void __iomem *)(pci_base_offset(adapter, off)));
1420}
1421
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001422unsigned long
1423netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
1424 unsigned long long addr)
1425{
1426 int window;
1427 u32 win_read;
1428
1429 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1430 /* DDR network side */
1431 window = MN_WIN(addr);
1432 adapter->ahw.ddr_mn_window = window;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001433 NXWR32(adapter, adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001434 window);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001435 win_read = NXRD32(adapter,
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001436 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001437 if ((win_read << 17) != window) {
1438 printk(KERN_INFO "Written MNwin (0x%x) != "
1439 "Read MNwin (0x%x)\n", window, win_read);
1440 }
1441 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_DDR_NET;
1442 } else if (ADDR_IN_RANGE(addr,
1443 NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1444 if ((addr & 0x00ff800) == 0xff800) {
1445 printk("%s: QM access not handled.\n", __func__);
1446 addr = -1UL;
1447 }
1448
1449 window = OCM_WIN(addr);
1450 adapter->ahw.ddr_mn_window = window;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001451 NXWR32(adapter, adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001452 window);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001453 win_read = NXRD32(adapter,
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001454 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001455 if ((win_read >> 7) != window) {
1456 printk(KERN_INFO "%s: Written OCMwin (0x%x) != "
1457 "Read OCMwin (0x%x)\n",
1458 __func__, window, win_read);
1459 }
1460 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_OCM0_2M;
1461
1462 } else if (ADDR_IN_RANGE(addr,
1463 NETXEN_ADDR_QDR_NET, NETXEN_ADDR_QDR_NET_MAX_P3)) {
1464 /* QDR network side */
1465 window = MS_WIN(addr);
1466 adapter->ahw.qdr_sn_window = window;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001467 NXWR32(adapter, adapter->ahw.ms_win_crb | NETXEN_PCI_CRBSPACE,
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001468 window);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001469 win_read = NXRD32(adapter,
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001470 adapter->ahw.ms_win_crb | NETXEN_PCI_CRBSPACE);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001471 if (win_read != window) {
1472 printk(KERN_INFO "%s: Written MSwin (0x%x) != "
1473 "Read MSwin (0x%x)\n",
1474 __func__, window, win_read);
1475 }
1476 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_QDR_NET;
1477
1478 } else {
1479 /*
1480 * peg gdb frequently accesses memory that doesn't exist,
1481 * this limits the chit chat so debugging isn't slowed down.
1482 */
1483 if ((netxen_pci_set_window_warning_count++ < 8)
1484 || (netxen_pci_set_window_warning_count%64 == 0)) {
1485 printk("%s: Warning:%s Unknown address range!\n",
1486 __func__, netxen_nic_driver_name);
1487}
1488 addr = -1UL;
1489 }
1490 return addr;
1491}
1492
1493static int netxen_nic_pci_is_same_window(struct netxen_adapter *adapter,
1494 unsigned long long addr)
1495{
1496 int window;
1497 unsigned long long qdr_max;
1498
1499 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
1500 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P2;
1501 else
1502 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P3;
1503
1504 if (ADDR_IN_RANGE(addr,
1505 NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1506 /* DDR network side */
1507 BUG(); /* MN access can not come here */
1508 } else if (ADDR_IN_RANGE(addr,
1509 NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1510 return 1;
1511 } else if (ADDR_IN_RANGE(addr,
1512 NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1513 return 1;
1514 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_QDR_NET, qdr_max)) {
1515 /* QDR network side */
1516 window = ((addr - NETXEN_ADDR_QDR_NET) >> 22) & 0x3f;
1517 if (adapter->ahw.qdr_sn_window == window)
1518 return 1;
1519 }
1520
1521 return 0;
1522}
1523
1524static int netxen_nic_pci_mem_read_direct(struct netxen_adapter *adapter,
1525 u64 off, void *data, int size)
1526{
1527 unsigned long flags;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001528 void __iomem *addr, *mem_ptr = NULL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001529 int ret = 0;
1530 u64 start;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001531 unsigned long mem_base;
1532 unsigned long mem_page;
1533
1534 write_lock_irqsave(&adapter->adapter_lock, flags);
1535
1536 /*
1537 * If attempting to access unknown address or straddle hw windows,
1538 * do not access.
1539 */
1540 start = adapter->pci_set_window(adapter, off);
1541 if ((start == -1UL) ||
1542 (netxen_nic_pci_is_same_window(adapter, off+size-1) == 0)) {
1543 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1544 printk(KERN_ERR "%s out of bound pci memory access. "
Andrew Morton11a859e2008-07-30 12:50:12 -07001545 "offset is 0x%llx\n", netxen_nic_driver_name,
1546 (unsigned long long)off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001547 return -1;
1548 }
1549
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001550 addr = pci_base_offset(adapter, start);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001551 if (!addr) {
1552 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1553 mem_base = pci_resource_start(adapter->pdev, 0);
1554 mem_page = start & PAGE_MASK;
1555 /* Map two pages whenever user tries to access addresses in two
1556 consecutive pages.
1557 */
1558 if (mem_page != ((start + size - 1) & PAGE_MASK))
1559 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1560 else
1561 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
Hannes Ederf8057b72008-12-26 00:04:26 -08001562 if (mem_ptr == NULL) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001563 *(uint8_t *)data = 0;
1564 return -1;
1565 }
1566 addr = mem_ptr;
1567 addr += start & (PAGE_SIZE - 1);
1568 write_lock_irqsave(&adapter->adapter_lock, flags);
1569 }
1570
1571 switch (size) {
1572 case 1:
1573 *(uint8_t *)data = readb(addr);
1574 break;
1575 case 2:
1576 *(uint16_t *)data = readw(addr);
1577 break;
1578 case 4:
1579 *(uint32_t *)data = readl(addr);
1580 break;
1581 case 8:
1582 *(uint64_t *)data = readq(addr);
1583 break;
1584 default:
1585 ret = -1;
1586 break;
1587 }
1588 write_unlock_irqrestore(&adapter->adapter_lock, flags);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001589
1590 if (mem_ptr)
1591 iounmap(mem_ptr);
1592 return ret;
1593}
1594
1595static int
1596netxen_nic_pci_mem_write_direct(struct netxen_adapter *adapter, u64 off,
1597 void *data, int size)
1598{
1599 unsigned long flags;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001600 void __iomem *addr, *mem_ptr = NULL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001601 int ret = 0;
1602 u64 start;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001603 unsigned long mem_base;
1604 unsigned long mem_page;
1605
1606 write_lock_irqsave(&adapter->adapter_lock, flags);
1607
1608 /*
1609 * If attempting to access unknown address or straddle hw windows,
1610 * do not access.
1611 */
1612 start = adapter->pci_set_window(adapter, off);
1613 if ((start == -1UL) ||
1614 (netxen_nic_pci_is_same_window(adapter, off+size-1) == 0)) {
1615 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1616 printk(KERN_ERR "%s out of bound pci memory access. "
Andrew Morton11a859e2008-07-30 12:50:12 -07001617 "offset is 0x%llx\n", netxen_nic_driver_name,
1618 (unsigned long long)off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001619 return -1;
1620 }
1621
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001622 addr = pci_base_offset(adapter, start);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001623 if (!addr) {
1624 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1625 mem_base = pci_resource_start(adapter->pdev, 0);
1626 mem_page = start & PAGE_MASK;
1627 /* Map two pages whenever user tries to access addresses in two
1628 * consecutive pages.
1629 */
1630 if (mem_page != ((start + size - 1) & PAGE_MASK))
1631 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE*2);
1632 else
1633 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
Hannes Ederf8057b72008-12-26 00:04:26 -08001634 if (mem_ptr == NULL)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001635 return -1;
1636 addr = mem_ptr;
1637 addr += start & (PAGE_SIZE - 1);
1638 write_lock_irqsave(&adapter->adapter_lock, flags);
1639 }
1640
1641 switch (size) {
1642 case 1:
1643 writeb(*(uint8_t *)data, addr);
1644 break;
1645 case 2:
1646 writew(*(uint16_t *)data, addr);
1647 break;
1648 case 4:
1649 writel(*(uint32_t *)data, addr);
1650 break;
1651 case 8:
1652 writeq(*(uint64_t *)data, addr);
1653 break;
1654 default:
1655 ret = -1;
1656 break;
1657 }
1658 write_unlock_irqrestore(&adapter->adapter_lock, flags);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001659 if (mem_ptr)
1660 iounmap(mem_ptr);
1661 return ret;
1662}
1663
1664#define MAX_CTL_CHECK 1000
1665
1666int
1667netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
1668 u64 off, void *data, int size)
1669{
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001670 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001671 int i, j, ret = 0, loop, sz[2], off0;
1672 uint32_t temp;
1673 uint64_t off8, tmpw, word[2] = {0, 0};
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001674 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001675
1676 /*
1677 * If not MN, go check for MS or invalid.
1678 */
1679 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1680 return netxen_nic_pci_mem_write_direct(adapter,
1681 off, data, size);
1682
1683 off8 = off & 0xfffffff8;
1684 off0 = off & 0x7;
1685 sz[0] = (size < (8 - off0)) ? size : (8 - off0);
1686 sz[1] = size - sz[0];
1687 loop = ((off0 + size - 1) >> 3) + 1;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001688 mem_crb = pci_base_offset(adapter, NETXEN_CRB_DDR_NET);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001689
1690 if ((size != 8) || (off0 != 0)) {
1691 for (i = 0; i < loop; i++) {
1692 if (adapter->pci_mem_read(adapter,
1693 off8 + (i << 3), &word[i], 8))
1694 return -1;
1695 }
1696 }
1697
1698 switch (size) {
1699 case 1:
1700 tmpw = *((uint8_t *)data);
1701 break;
1702 case 2:
1703 tmpw = *((uint16_t *)data);
1704 break;
1705 case 4:
1706 tmpw = *((uint32_t *)data);
1707 break;
1708 case 8:
1709 default:
1710 tmpw = *((uint64_t *)data);
1711 break;
1712 }
1713 word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
1714 word[0] |= tmpw << (off0 * 8);
1715
1716 if (loop == 2) {
1717 word[1] &= ~(~0ULL << (sz[1] * 8));
1718 word[1] |= tmpw >> (sz[0] * 8);
1719 }
1720
1721 write_lock_irqsave(&adapter->adapter_lock, flags);
1722 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1723
1724 for (i = 0; i < loop; i++) {
1725 writel((uint32_t)(off8 + (i << 3)),
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001726 (mem_crb+MIU_TEST_AGT_ADDR_LO));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001727 writel(0,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001728 (mem_crb+MIU_TEST_AGT_ADDR_HI));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001729 writel(word[i] & 0xffffffff,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001730 (mem_crb+MIU_TEST_AGT_WRDATA_LO));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001731 writel((word[i] >> 32) & 0xffffffff,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001732 (mem_crb+MIU_TEST_AGT_WRDATA_HI));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001733 writel(MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001734 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001735 writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001736 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001737
1738 for (j = 0; j < MAX_CTL_CHECK; j++) {
1739 temp = readl(
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001740 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001741 if ((temp & MIU_TA_CTL_BUSY) == 0)
1742 break;
1743 }
1744
1745 if (j >= MAX_CTL_CHECK) {
Dhananjay Phadke39754f42009-02-17 20:27:02 -08001746 if (printk_ratelimit())
1747 dev_err(&adapter->pdev->dev,
1748 "failed to write through agent\n");
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001749 ret = -1;
1750 break;
1751 }
1752 }
1753
1754 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1755 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1756 return ret;
1757}
1758
1759int
1760netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
1761 u64 off, void *data, int size)
1762{
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001763 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001764 int i, j = 0, k, start, end, loop, sz[2], off0[2];
1765 uint32_t temp;
1766 uint64_t off8, val, word[2] = {0, 0};
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001767 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001768
1769
1770 /*
1771 * If not MN, go check for MS or invalid.
1772 */
1773 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1774 return netxen_nic_pci_mem_read_direct(adapter, off, data, size);
1775
1776 off8 = off & 0xfffffff8;
1777 off0[0] = off & 0x7;
1778 off0[1] = 0;
1779 sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]);
1780 sz[1] = size - sz[0];
1781 loop = ((off0[0] + size - 1) >> 3) + 1;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001782 mem_crb = pci_base_offset(adapter, NETXEN_CRB_DDR_NET);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001783
1784 write_lock_irqsave(&adapter->adapter_lock, flags);
1785 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1786
1787 for (i = 0; i < loop; i++) {
1788 writel((uint32_t)(off8 + (i << 3)),
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001789 (mem_crb+MIU_TEST_AGT_ADDR_LO));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001790 writel(0,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001791 (mem_crb+MIU_TEST_AGT_ADDR_HI));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001792 writel(MIU_TA_CTL_ENABLE,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001793 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001794 writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001795 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001796
1797 for (j = 0; j < MAX_CTL_CHECK; j++) {
1798 temp = readl(
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001799 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001800 if ((temp & MIU_TA_CTL_BUSY) == 0)
1801 break;
1802 }
1803
1804 if (j >= MAX_CTL_CHECK) {
Dhananjay Phadke39754f42009-02-17 20:27:02 -08001805 if (printk_ratelimit())
1806 dev_err(&adapter->pdev->dev,
1807 "failed to read through agent\n");
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001808 break;
1809 }
1810
1811 start = off0[i] >> 2;
1812 end = (off0[i] + sz[i] - 1) >> 2;
1813 for (k = start; k <= end; k++) {
1814 word[i] |= ((uint64_t) readl(
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001815 (mem_crb +
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001816 MIU_TEST_AGT_RDDATA(k))) << (32*k));
1817 }
1818 }
1819
1820 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1821 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1822
1823 if (j >= MAX_CTL_CHECK)
1824 return -1;
1825
1826 if (sz[0] == 8) {
1827 val = word[0];
1828 } else {
1829 val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
1830 ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
1831 }
1832
1833 switch (size) {
1834 case 1:
1835 *(uint8_t *)data = val;
1836 break;
1837 case 2:
1838 *(uint16_t *)data = val;
1839 break;
1840 case 4:
1841 *(uint32_t *)data = val;
1842 break;
1843 case 8:
1844 *(uint64_t *)data = val;
1845 break;
1846 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001847 return 0;
1848}
1849
1850int
1851netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
1852 u64 off, void *data, int size)
1853{
1854 int i, j, ret = 0, loop, sz[2], off0;
1855 uint32_t temp;
1856 uint64_t off8, mem_crb, tmpw, word[2] = {0, 0};
1857
1858 /*
1859 * If not MN, go check for MS or invalid.
1860 */
1861 if (off >= NETXEN_ADDR_QDR_NET && off <= NETXEN_ADDR_QDR_NET_MAX_P3)
1862 mem_crb = NETXEN_CRB_QDR_NET;
1863 else {
1864 mem_crb = NETXEN_CRB_DDR_NET;
1865 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1866 return netxen_nic_pci_mem_write_direct(adapter,
1867 off, data, size);
1868 }
1869
1870 off8 = off & 0xfffffff8;
1871 off0 = off & 0x7;
1872 sz[0] = (size < (8 - off0)) ? size : (8 - off0);
1873 sz[1] = size - sz[0];
1874 loop = ((off0 + size - 1) >> 3) + 1;
1875
1876 if ((size != 8) || (off0 != 0)) {
1877 for (i = 0; i < loop; i++) {
1878 if (adapter->pci_mem_read(adapter, off8 + (i << 3),
1879 &word[i], 8))
1880 return -1;
1881 }
1882 }
1883
1884 switch (size) {
1885 case 1:
1886 tmpw = *((uint8_t *)data);
1887 break;
1888 case 2:
1889 tmpw = *((uint16_t *)data);
1890 break;
1891 case 4:
1892 tmpw = *((uint32_t *)data);
1893 break;
1894 case 8:
1895 default:
1896 tmpw = *((uint64_t *)data);
1897 break;
1898 }
1899
1900 word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
1901 word[0] |= tmpw << (off0 * 8);
1902
1903 if (loop == 2) {
1904 word[1] &= ~(~0ULL << (sz[1] * 8));
1905 word[1] |= tmpw >> (sz[0] * 8);
1906 }
1907
1908 /*
1909 * don't lock here - write_wx gets the lock if each time
1910 * write_lock_irqsave(&adapter->adapter_lock, flags);
1911 * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1912 */
1913
1914 for (i = 0; i < loop; i++) {
1915 temp = off8 + (i << 3);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001916 NXWR32(adapter, mem_crb+MIU_TEST_AGT_ADDR_LO, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001917 temp = 0;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001918 NXWR32(adapter, mem_crb+MIU_TEST_AGT_ADDR_HI, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001919 temp = word[i] & 0xffffffff;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001920 NXWR32(adapter, mem_crb+MIU_TEST_AGT_WRDATA_LO, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001921 temp = (word[i] >> 32) & 0xffffffff;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001922 NXWR32(adapter, mem_crb+MIU_TEST_AGT_WRDATA_HI, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001923 temp = MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001924 NXWR32(adapter, mem_crb+MIU_TEST_AGT_CTRL, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001925 temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001926 NXWR32(adapter, mem_crb+MIU_TEST_AGT_CTRL, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001927
1928 for (j = 0; j < MAX_CTL_CHECK; j++) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001929 temp = NXRD32(adapter, mem_crb + MIU_TEST_AGT_CTRL);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001930 if ((temp & MIU_TA_CTL_BUSY) == 0)
1931 break;
1932 }
1933
1934 if (j >= MAX_CTL_CHECK) {
Dhananjay Phadke39754f42009-02-17 20:27:02 -08001935 if (printk_ratelimit())
1936 dev_err(&adapter->pdev->dev,
1937 "failed to write through agent\n");
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001938 ret = -1;
1939 break;
1940 }
1941 }
1942
1943 /*
1944 * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1945 * write_unlock_irqrestore(&adapter->adapter_lock, flags);
1946 */
1947 return ret;
1948}
1949
1950int
1951netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
1952 u64 off, void *data, int size)
1953{
1954 int i, j = 0, k, start, end, loop, sz[2], off0[2];
1955 uint32_t temp;
1956 uint64_t off8, val, mem_crb, word[2] = {0, 0};
1957
1958 /*
1959 * If not MN, go check for MS or invalid.
1960 */
1961
1962 if (off >= NETXEN_ADDR_QDR_NET && off <= NETXEN_ADDR_QDR_NET_MAX_P3)
1963 mem_crb = NETXEN_CRB_QDR_NET;
1964 else {
1965 mem_crb = NETXEN_CRB_DDR_NET;
1966 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1967 return netxen_nic_pci_mem_read_direct(adapter,
1968 off, data, size);
1969 }
1970
1971 off8 = off & 0xfffffff8;
1972 off0[0] = off & 0x7;
1973 off0[1] = 0;
1974 sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]);
1975 sz[1] = size - sz[0];
1976 loop = ((off0[0] + size - 1) >> 3) + 1;
1977
1978 /*
1979 * don't lock here - write_wx gets the lock if each time
1980 * write_lock_irqsave(&adapter->adapter_lock, flags);
1981 * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1982 */
1983
1984 for (i = 0; i < loop; i++) {
1985 temp = off8 + (i << 3);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001986 NXWR32(adapter, mem_crb + MIU_TEST_AGT_ADDR_LO, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001987 temp = 0;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001988 NXWR32(adapter, mem_crb + MIU_TEST_AGT_ADDR_HI, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001989 temp = MIU_TA_CTL_ENABLE;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001990 NXWR32(adapter, mem_crb + MIU_TEST_AGT_CTRL, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001991 temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001992 NXWR32(adapter, mem_crb + MIU_TEST_AGT_CTRL, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001993
1994 for (j = 0; j < MAX_CTL_CHECK; j++) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001995 temp = NXRD32(adapter, mem_crb + MIU_TEST_AGT_CTRL);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001996 if ((temp & MIU_TA_CTL_BUSY) == 0)
1997 break;
1998 }
1999
2000 if (j >= MAX_CTL_CHECK) {
Dhananjay Phadke39754f42009-02-17 20:27:02 -08002001 if (printk_ratelimit())
2002 dev_err(&adapter->pdev->dev,
2003 "failed to read through agent\n");
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07002004 break;
2005 }
2006
2007 start = off0[i] >> 2;
2008 end = (off0[i] + sz[i] - 1) >> 2;
2009 for (k = start; k <= end; k++) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002010 temp = NXRD32(adapter,
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00002011 mem_crb + MIU_TEST_AGT_RDDATA(k));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07002012 word[i] |= ((uint64_t)temp << (32 * k));
2013 }
2014 }
2015
2016 /*
2017 * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
2018 * write_unlock_irqrestore(&adapter->adapter_lock, flags);
2019 */
2020
2021 if (j >= MAX_CTL_CHECK)
2022 return -1;
2023
2024 if (sz[0] == 8) {
2025 val = word[0];
2026 } else {
2027 val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
2028 ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
2029 }
2030
2031 switch (size) {
2032 case 1:
2033 *(uint8_t *)data = val;
2034 break;
2035 case 2:
2036 *(uint16_t *)data = val;
2037 break;
2038 case 4:
2039 *(uint32_t *)data = val;
2040 break;
2041 case 8:
2042 *(uint64_t *)data = val;
2043 break;
2044 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07002045 return 0;
2046}
2047
2048/*
2049 * Note : only 32-bit writes!
2050 */
2051int netxen_nic_pci_write_immediate_2M(struct netxen_adapter *adapter,
2052 u64 off, u32 data)
2053{
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002054 NXWR32(adapter, off, data);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07002055
2056 return 0;
2057}
2058
2059u32 netxen_nic_pci_read_immediate_2M(struct netxen_adapter *adapter, u64 off)
2060{
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002061 return NXRD32(adapter, off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07002062}
2063
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002064int netxen_nic_get_board_info(struct netxen_adapter *adapter)
2065{
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002066 int offset, board_type, magic, header_version;
2067 struct pci_dev *pdev = adapter->pdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002068
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002069 offset = NETXEN_BRDCFG_START +
2070 offsetof(struct netxen_board_info, magic);
2071 if (netxen_rom_fast_read(adapter, offset, &magic))
2072 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002073
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002074 offset = NETXEN_BRDCFG_START +
2075 offsetof(struct netxen_board_info, header_version);
2076 if (netxen_rom_fast_read(adapter, offset, &header_version))
2077 return -EIO;
2078
2079 if (magic != NETXEN_BDINFO_MAGIC ||
2080 header_version != NETXEN_BDINFO_VERSION) {
2081 dev_err(&pdev->dev,
2082 "invalid board config, magic=%08x, version=%08x\n",
2083 magic, header_version);
2084 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002085 }
2086
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002087 offset = NETXEN_BRDCFG_START +
2088 offsetof(struct netxen_board_info, board_type);
2089 if (netxen_rom_fast_read(adapter, offset, &board_type))
2090 return -EIO;
2091
2092 adapter->ahw.board_type = board_type;
2093
2094 if (board_type == NETXEN_BRDTYPE_P3_4_GB_MM) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002095 u32 gpio = NXRD32(adapter, NETXEN_ROMUSB_GLB_PAD_GPIO_I);
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002096 if ((gpio & 0x8000) == 0)
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002097 board_type = NETXEN_BRDTYPE_P3_10G_TP;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002098 }
2099
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00002100 switch (board_type) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002101 case NETXEN_BRDTYPE_P2_SB35_4G:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002102 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002103 break;
2104 case NETXEN_BRDTYPE_P2_SB31_10G:
2105 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
2106 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
2107 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07002108 case NETXEN_BRDTYPE_P3_HMEZ:
2109 case NETXEN_BRDTYPE_P3_XG_LOM:
2110 case NETXEN_BRDTYPE_P3_10G_CX4:
2111 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
2112 case NETXEN_BRDTYPE_P3_IMEZ:
2113 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
Dhananjay Phadkea70f9392008-08-01 03:14:56 -07002114 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
2115 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07002116 case NETXEN_BRDTYPE_P3_10G_XFP:
2117 case NETXEN_BRDTYPE_P3_10000_BASE_T:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002118 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002119 break;
2120 case NETXEN_BRDTYPE_P1_BD:
2121 case NETXEN_BRDTYPE_P1_SB:
2122 case NETXEN_BRDTYPE_P1_SMAX:
2123 case NETXEN_BRDTYPE_P1_SOCK:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07002124 case NETXEN_BRDTYPE_P3_REF_QG:
2125 case NETXEN_BRDTYPE_P3_4_GB:
2126 case NETXEN_BRDTYPE_P3_4_GB_MM:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002127 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002128 break;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002129 case NETXEN_BRDTYPE_P3_10G_TP:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002130 adapter->ahw.port_type = (adapter->portnum < 2) ?
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002131 NETXEN_NIC_XGBE : NETXEN_NIC_GBE;
2132 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002133 default:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002134 dev_err(&pdev->dev, "unknown board type %x\n", board_type);
2135 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002136 break;
2137 }
2138
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002139 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002140}
2141
2142/* NIU access sections */
2143
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002144int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002145{
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07002146 new_mtu += MTU_FUDGE_FACTOR;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002147 NXWR32(adapter, NETXEN_NIU_GB_MAX_FRAME_SIZE(adapter->physical_port),
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07002148 new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002149 return 0;
2150}
2151
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002152int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002153{
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07002154 new_mtu += MTU_FUDGE_FACTOR;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07002155 if (adapter->physical_port == 0)
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002156 NXWR32(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu);
Jeff Garzik47906542007-11-23 21:23:36 -05002157 else
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002158 NXWR32(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002159 return 0;
2160}
2161
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002162void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002163{
Al Viroa608ab92007-01-02 10:39:10 +00002164 __u32 status;
2165 __u32 autoneg;
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002166 __u32 port_mode;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002167
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002168 if (!netif_carrier_ok(adapter->netdev)) {
2169 adapter->link_speed = 0;
2170 adapter->link_duplex = -1;
2171 adapter->link_autoneg = AUTONEG_ENABLE;
2172 return;
2173 }
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002174
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002175 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002176 port_mode = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002177 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
2178 adapter->link_speed = SPEED_1000;
2179 adapter->link_duplex = DUPLEX_FULL;
2180 adapter->link_autoneg = AUTONEG_DISABLE;
2181 return;
2182 }
2183
Amit S. Kale80922fb2006-12-04 09:18:00 -08002184 if (adapter->phy_read
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002185 && adapter->phy_read(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002186 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
2187 &status) == 0) {
2188 if (netxen_get_phy_link(status)) {
2189 switch (netxen_get_phy_speed(status)) {
2190 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002191 adapter->link_speed = SPEED_10;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002192 break;
2193 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002194 adapter->link_speed = SPEED_100;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002195 break;
2196 case 2:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002197 adapter->link_speed = SPEED_1000;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002198 break;
2199 default:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002200 adapter->link_speed = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002201 break;
2202 }
2203 switch (netxen_get_phy_duplex(status)) {
2204 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002205 adapter->link_duplex = DUPLEX_HALF;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002206 break;
2207 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002208 adapter->link_duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002209 break;
2210 default:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002211 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002212 break;
2213 }
Amit S. Kale80922fb2006-12-04 09:18:00 -08002214 if (adapter->phy_read
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002215 && adapter->phy_read(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002216 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08002217 &autoneg) != 0)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002218 adapter->link_autoneg = autoneg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002219 } else
2220 goto link_down;
2221 } else {
2222 link_down:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002223 adapter->link_speed = 0;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002224 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002225 }
2226 }
2227}
2228
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002229void netxen_nic_get_firmware_info(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002230{
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002231 u32 fw_major, fw_minor, fw_build;
Amit S. Kalecb8011a2006-11-29 09:00:10 -08002232 char brd_name[NETXEN_MAX_SHORT_NAME];
Harvey Harrison8d748492008-04-22 11:48:35 -07002233 char serial_num[32];
Dhananjay Phadkefbb52f22009-03-13 14:52:01 +00002234 int i, addr, val;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08002235 int *ptr32;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002236 struct pci_dev *pdev = adapter->pdev;
Harvey Harrison8d748492008-04-22 11:48:35 -07002237
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002238 adapter->driver_mismatch = 0;
2239
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08002240 ptr32 = (int *)&serial_num;
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002241 addr = NETXEN_USER_START +
2242 offsetof(struct netxen_new_user_info, serial_num);
2243 for (i = 0; i < 8; i++) {
Dhananjay Phadkefbb52f22009-03-13 14:52:01 +00002244 if (netxen_rom_fast_read(adapter, addr, &val) == -1) {
2245 dev_err(&pdev->dev, "error reading board info\n");
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002246 adapter->driver_mismatch = 1;
2247 return;
2248 }
Dhananjay Phadkefbb52f22009-03-13 14:52:01 +00002249 ptr32[i] = cpu_to_le32(val);
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002250 addr += sizeof(u32);
2251 }
2252
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002253 fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
2254 fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
2255 fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002256
Dhananjay Phadke29566402008-07-21 19:44:04 -07002257 adapter->fw_major = fw_major;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002258 adapter->fw_version = NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build);
Dhananjay Phadke29566402008-07-21 19:44:04 -07002259
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002260 if (adapter->portnum == 0) {
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002261 get_brd_name_by_type(adapter->ahw.board_type, brd_name);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08002262
Dhananjay Phadke11d89d62008-08-08 00:08:45 -07002263 printk(KERN_INFO "NetXen %s Board S/N %s Chip rev 0x%x\n",
2264 brd_name, serial_num, adapter->ahw.revision_id);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002265 }
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002266
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002267 if (adapter->fw_version < NETXEN_VERSION_CODE(3, 4, 216)) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002268 adapter->driver_mismatch = 1;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002269 dev_warn(&pdev->dev, "firmware version %d.%d.%d unsupported\n",
Dhananjay Phadke58735562008-07-21 19:44:10 -07002270 fw_major, fw_minor, fw_build);
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002271 return;
2272 }
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002273
2274 dev_info(&pdev->dev, "firmware version %d.%d.%d\n",
2275 fw_major, fw_minor, fw_build);
2276
2277 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002278 i = NXRD32(adapter, NETXEN_MIU_MN_CONTROL);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002279 adapter->ahw.cut_through = (i & 0x4) ? 1 : 0;
2280 dev_info(&pdev->dev, "firmware running in %s mode\n",
2281 adapter->ahw.cut_through ? "cut-through" : "legacy");
2282 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002283}
2284
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002285int
2286netxen_nic_wol_supported(struct netxen_adapter *adapter)
2287{
2288 u32 wol_cfg;
2289
2290 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2291 return 0;
2292
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002293 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002294 if (wol_cfg & (1UL << adapter->portnum)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002295 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002296 if (wol_cfg & (1 << adapter->portnum))
2297 return 1;
2298 }
2299
2300 return 0;
2301}