blob: 1a8ad62e12ee20d5c64f19b35e27105ceebacf93 [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"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040033
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030034#include <net/ip.h>
35
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070036#define MASK(n) ((1ULL<<(n))-1)
37#define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff))
38#define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff))
39#define MS_WIN(addr) (addr & 0x0ffc0000)
40
41#define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
42
43#define CRB_BLK(off) ((off >> 20) & 0x3f)
44#define CRB_SUBBLK(off) ((off >> 16) & 0xf)
45#define CRB_WINDOW_2M (0x130060)
46#define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000))
47#define CRB_INDIRECT_2M (0x1e0000UL)
48
Dhananjay Phadkee98e3352009-04-07 22:50:38 +000049#ifndef readq
50static inline u64 readq(void __iomem *addr)
51{
52 return readl(addr) | (((u64) readl(addr + 4)) << 32LL);
53}
54#endif
55
56#ifndef writeq
57static inline void writeq(u64 val, void __iomem *addr)
58{
59 writel(((u32) (val)), (addr));
60 writel(((u32) (val >> 32)), (addr + 4));
61}
62#endif
63
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +000064#define ADDR_IN_RANGE(addr, low, high) \
65 (((addr) < (high)) && ((addr) >= (low)))
66
67#define PCI_OFFSET_FIRST_RANGE(adapter, off) \
68 ((adapter)->ahw.pci_base0 + (off))
69#define PCI_OFFSET_SECOND_RANGE(adapter, off) \
70 ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START)
71#define PCI_OFFSET_THIRD_RANGE(adapter, off) \
72 ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START)
73
74static void __iomem *pci_base_offset(struct netxen_adapter *adapter,
75 unsigned long off)
76{
77 if (ADDR_IN_RANGE(off, FIRST_PAGE_GROUP_START, FIRST_PAGE_GROUP_END))
78 return PCI_OFFSET_FIRST_RANGE(adapter, off);
79
80 if (ADDR_IN_RANGE(off, SECOND_PAGE_GROUP_START, SECOND_PAGE_GROUP_END))
81 return PCI_OFFSET_SECOND_RANGE(adapter, off);
82
83 if (ADDR_IN_RANGE(off, THIRD_PAGE_GROUP_START, THIRD_PAGE_GROUP_END))
84 return PCI_OFFSET_THIRD_RANGE(adapter, off);
85
86 return NULL;
87}
88
Dhananjay Phadkeea7eaa32009-04-07 22:50:48 +000089static crb_128M_2M_block_map_t
90crb_128M_2M_map[64] __cacheline_aligned_in_smp = {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070091 {{{0, 0, 0, 0} } }, /* 0: PCI */
92 {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */
93 {1, 0x0110000, 0x0120000, 0x130000},
94 {1, 0x0120000, 0x0122000, 0x124000},
95 {1, 0x0130000, 0x0132000, 0x126000},
96 {1, 0x0140000, 0x0142000, 0x128000},
97 {1, 0x0150000, 0x0152000, 0x12a000},
98 {1, 0x0160000, 0x0170000, 0x110000},
99 {1, 0x0170000, 0x0172000, 0x12e000},
100 {0, 0x0000000, 0x0000000, 0x000000},
101 {0, 0x0000000, 0x0000000, 0x000000},
102 {0, 0x0000000, 0x0000000, 0x000000},
103 {0, 0x0000000, 0x0000000, 0x000000},
104 {0, 0x0000000, 0x0000000, 0x000000},
105 {0, 0x0000000, 0x0000000, 0x000000},
106 {1, 0x01e0000, 0x01e0800, 0x122000},
107 {0, 0x0000000, 0x0000000, 0x000000} } },
108 {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */
109 {{{0, 0, 0, 0} } }, /* 3: */
110 {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */
111 {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */
112 {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */
113 {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */
114 {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */
115 {0, 0x0000000, 0x0000000, 0x000000},
116 {0, 0x0000000, 0x0000000, 0x000000},
117 {0, 0x0000000, 0x0000000, 0x000000},
118 {0, 0x0000000, 0x0000000, 0x000000},
119 {0, 0x0000000, 0x0000000, 0x000000},
120 {0, 0x0000000, 0x0000000, 0x000000},
121 {0, 0x0000000, 0x0000000, 0x000000},
122 {0, 0x0000000, 0x0000000, 0x000000},
123 {0, 0x0000000, 0x0000000, 0x000000},
124 {0, 0x0000000, 0x0000000, 0x000000},
125 {0, 0x0000000, 0x0000000, 0x000000},
126 {0, 0x0000000, 0x0000000, 0x000000},
127 {0, 0x0000000, 0x0000000, 0x000000},
128 {0, 0x0000000, 0x0000000, 0x000000},
129 {1, 0x08f0000, 0x08f2000, 0x172000} } },
130 {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/
131 {0, 0x0000000, 0x0000000, 0x000000},
132 {0, 0x0000000, 0x0000000, 0x000000},
133 {0, 0x0000000, 0x0000000, 0x000000},
134 {0, 0x0000000, 0x0000000, 0x000000},
135 {0, 0x0000000, 0x0000000, 0x000000},
136 {0, 0x0000000, 0x0000000, 0x000000},
137 {0, 0x0000000, 0x0000000, 0x000000},
138 {0, 0x0000000, 0x0000000, 0x000000},
139 {0, 0x0000000, 0x0000000, 0x000000},
140 {0, 0x0000000, 0x0000000, 0x000000},
141 {0, 0x0000000, 0x0000000, 0x000000},
142 {0, 0x0000000, 0x0000000, 0x000000},
143 {0, 0x0000000, 0x0000000, 0x000000},
144 {0, 0x0000000, 0x0000000, 0x000000},
145 {1, 0x09f0000, 0x09f2000, 0x176000} } },
146 {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/
147 {0, 0x0000000, 0x0000000, 0x000000},
148 {0, 0x0000000, 0x0000000, 0x000000},
149 {0, 0x0000000, 0x0000000, 0x000000},
150 {0, 0x0000000, 0x0000000, 0x000000},
151 {0, 0x0000000, 0x0000000, 0x000000},
152 {0, 0x0000000, 0x0000000, 0x000000},
153 {0, 0x0000000, 0x0000000, 0x000000},
154 {0, 0x0000000, 0x0000000, 0x000000},
155 {0, 0x0000000, 0x0000000, 0x000000},
156 {0, 0x0000000, 0x0000000, 0x000000},
157 {0, 0x0000000, 0x0000000, 0x000000},
158 {0, 0x0000000, 0x0000000, 0x000000},
159 {0, 0x0000000, 0x0000000, 0x000000},
160 {0, 0x0000000, 0x0000000, 0x000000},
161 {1, 0x0af0000, 0x0af2000, 0x17a000} } },
162 {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/
163 {0, 0x0000000, 0x0000000, 0x000000},
164 {0, 0x0000000, 0x0000000, 0x000000},
165 {0, 0x0000000, 0x0000000, 0x000000},
166 {0, 0x0000000, 0x0000000, 0x000000},
167 {0, 0x0000000, 0x0000000, 0x000000},
168 {0, 0x0000000, 0x0000000, 0x000000},
169 {0, 0x0000000, 0x0000000, 0x000000},
170 {0, 0x0000000, 0x0000000, 0x000000},
171 {0, 0x0000000, 0x0000000, 0x000000},
172 {0, 0x0000000, 0x0000000, 0x000000},
173 {0, 0x0000000, 0x0000000, 0x000000},
174 {0, 0x0000000, 0x0000000, 0x000000},
175 {0, 0x0000000, 0x0000000, 0x000000},
176 {0, 0x0000000, 0x0000000, 0x000000},
177 {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
178 {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */
179 {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */
180 {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */
181 {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */
182 {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */
183 {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */
184 {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */
185 {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */
186 {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */
187 {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */
188 {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */
189 {{{0, 0, 0, 0} } }, /* 23: */
190 {{{0, 0, 0, 0} } }, /* 24: */
191 {{{0, 0, 0, 0} } }, /* 25: */
192 {{{0, 0, 0, 0} } }, /* 26: */
193 {{{0, 0, 0, 0} } }, /* 27: */
194 {{{0, 0, 0, 0} } }, /* 28: */
195 {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */
196 {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */
197 {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */
198 {{{0} } }, /* 32: PCI */
199 {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */
200 {1, 0x2110000, 0x2120000, 0x130000},
201 {1, 0x2120000, 0x2122000, 0x124000},
202 {1, 0x2130000, 0x2132000, 0x126000},
203 {1, 0x2140000, 0x2142000, 0x128000},
204 {1, 0x2150000, 0x2152000, 0x12a000},
205 {1, 0x2160000, 0x2170000, 0x110000},
206 {1, 0x2170000, 0x2172000, 0x12e000},
207 {0, 0x0000000, 0x0000000, 0x000000},
208 {0, 0x0000000, 0x0000000, 0x000000},
209 {0, 0x0000000, 0x0000000, 0x000000},
210 {0, 0x0000000, 0x0000000, 0x000000},
211 {0, 0x0000000, 0x0000000, 0x000000},
212 {0, 0x0000000, 0x0000000, 0x000000},
213 {0, 0x0000000, 0x0000000, 0x000000},
214 {0, 0x0000000, 0x0000000, 0x000000} } },
215 {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */
216 {{{0} } }, /* 35: */
217 {{{0} } }, /* 36: */
218 {{{0} } }, /* 37: */
219 {{{0} } }, /* 38: */
220 {{{0} } }, /* 39: */
221 {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */
222 {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */
223 {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */
224 {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */
225 {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */
226 {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */
227 {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */
228 {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */
229 {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */
230 {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */
231 {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */
232 {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */
233 {{{0} } }, /* 52: */
234 {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */
235 {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */
236 {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */
237 {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */
238 {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */
239 {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */
240 {{{0} } }, /* 59: I2C0 */
241 {{{0} } }, /* 60: I2C1 */
242 {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */
243 {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */
244 {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */
245};
246
247/*
248 * top 12 bits of crb internal address (hub, agent)
249 */
250static unsigned crb_hub_agt[64] =
251{
252 0,
253 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
254 NETXEN_HW_CRB_HUB_AGT_ADR_MN,
255 NETXEN_HW_CRB_HUB_AGT_ADR_MS,
256 0,
257 NETXEN_HW_CRB_HUB_AGT_ADR_SRE,
258 NETXEN_HW_CRB_HUB_AGT_ADR_NIU,
259 NETXEN_HW_CRB_HUB_AGT_ADR_QMN,
260 NETXEN_HW_CRB_HUB_AGT_ADR_SQN0,
261 NETXEN_HW_CRB_HUB_AGT_ADR_SQN1,
262 NETXEN_HW_CRB_HUB_AGT_ADR_SQN2,
263 NETXEN_HW_CRB_HUB_AGT_ADR_SQN3,
264 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
265 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
266 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
267 NETXEN_HW_CRB_HUB_AGT_ADR_PGN4,
268 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
269 NETXEN_HW_CRB_HUB_AGT_ADR_PGN0,
270 NETXEN_HW_CRB_HUB_AGT_ADR_PGN1,
271 NETXEN_HW_CRB_HUB_AGT_ADR_PGN2,
272 NETXEN_HW_CRB_HUB_AGT_ADR_PGN3,
273 NETXEN_HW_CRB_HUB_AGT_ADR_PGND,
274 NETXEN_HW_CRB_HUB_AGT_ADR_PGNI,
275 NETXEN_HW_CRB_HUB_AGT_ADR_PGS0,
276 NETXEN_HW_CRB_HUB_AGT_ADR_PGS1,
277 NETXEN_HW_CRB_HUB_AGT_ADR_PGS2,
278 NETXEN_HW_CRB_HUB_AGT_ADR_PGS3,
279 0,
280 NETXEN_HW_CRB_HUB_AGT_ADR_PGSI,
281 NETXEN_HW_CRB_HUB_AGT_ADR_SN,
282 0,
283 NETXEN_HW_CRB_HUB_AGT_ADR_EG,
284 0,
285 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
286 NETXEN_HW_CRB_HUB_AGT_ADR_CAM,
287 0,
288 0,
289 0,
290 0,
291 0,
292 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
293 0,
294 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1,
295 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2,
296 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3,
297 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4,
298 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5,
299 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6,
300 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7,
301 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
302 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
303 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
304 0,
305 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0,
306 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8,
307 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9,
308 NETXEN_HW_CRB_HUB_AGT_ADR_OCM0,
309 0,
310 NETXEN_HW_CRB_HUB_AGT_ADR_SMB,
311 NETXEN_HW_CRB_HUB_AGT_ADR_I2C0,
312 NETXEN_HW_CRB_HUB_AGT_ADR_I2C1,
313 0,
314 NETXEN_HW_CRB_HUB_AGT_ADR_PGNC,
315 0,
316};
317
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400318/* PCI Windowing for DDR regions. */
319
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700320#define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400321
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000322#define NETXEN_PCIE_SEM_TIMEOUT 10000
323
324int
325netxen_pcie_sem_lock(struct netxen_adapter *adapter, int sem, u32 id_reg)
326{
327 int done = 0, timeout = 0;
328
329 while (!done) {
330 done = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_LOCK(sem)));
331 if (done == 1)
332 break;
333 if (++timeout >= NETXEN_PCIE_SEM_TIMEOUT)
334 return -1;
335 msleep(1);
336 }
337
338 if (id_reg)
339 NXWR32(adapter, id_reg, adapter->portnum);
340
341 return 0;
342}
343
344void
345netxen_pcie_sem_unlock(struct netxen_adapter *adapter, int sem)
346{
347 int val;
348 val = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_UNLOCK(sem)));
349}
350
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000351int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port)
352{
353 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
354 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_1+(0x10000*port), 0x1447);
355 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0+(0x10000*port), 0x5);
356 }
357
358 return 0;
359}
360
361/* Disable an XG interface */
362int netxen_niu_disable_xg_port(struct netxen_adapter *adapter)
363{
364 __u32 mac_cfg;
365 u32 port = adapter->physical_port;
366
367 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
368 return 0;
369
370 if (port > NETXEN_NIU_MAX_XG_PORTS)
371 return -EINVAL;
372
373 mac_cfg = 0;
374 if (NXWR32(adapter,
375 NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg))
376 return -EIO;
377 return 0;
378}
379
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700380#define NETXEN_UNICAST_ADDR(port, index) \
381 (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8))
382#define NETXEN_MCAST_ADDR(port, index) \
383 (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8))
384#define MAC_HI(addr) \
385 ((addr[2] << 16) | (addr[1] << 8) | (addr[0]))
386#define MAC_LO(addr) \
387 ((addr[5] << 16) | (addr[4] << 8) | (addr[3]))
388
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000389int netxen_p2_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
390{
391 __u32 reg;
392 u32 port = adapter->physical_port;
393
394 if (port > NETXEN_NIU_MAX_XG_PORTS)
395 return -EINVAL;
396
397 reg = NXRD32(adapter, NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port));
398 if (mode == NETXEN_NIU_PROMISC_MODE)
399 reg = (reg | 0x2000UL);
400 else
401 reg = (reg & ~0x2000UL);
402
403 if (mode == NETXEN_NIU_ALLMULTI_MODE)
404 reg = (reg | 0x1000UL);
405 else
406 reg = (reg & ~0x1000UL);
407
408 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), reg);
409
410 return 0;
411}
412
413int netxen_p2_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr)
414{
415 u32 mac_hi, mac_lo;
416 u32 reg_hi, reg_lo;
417
418 u8 phy = adapter->physical_port;
419
420 if (phy >= NETXEN_NIU_MAX_XG_PORTS)
421 return -EINVAL;
422
423 mac_lo = ((u32)addr[0] << 16) | ((u32)addr[1] << 24);
424 mac_hi = addr[2] | ((u32)addr[3] << 8) |
425 ((u32)addr[4] << 16) | ((u32)addr[5] << 24);
426
427 reg_lo = NETXEN_NIU_XGE_STATION_ADDR_0_1 + (0x10000 * phy);
428 reg_hi = NETXEN_NIU_XGE_STATION_ADDR_0_HI + (0x10000 * phy);
429
430 /* write twice to flush */
431 if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi))
432 return -EIO;
433 if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi))
434 return -EIO;
435
436 return 0;
437}
438
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700439static int
440netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter)
441{
442 u32 val = 0;
443 u16 port = adapter->physical_port;
444 u8 *addr = adapter->netdev->dev_addr;
445
446 if (adapter->mc_enabled)
447 return 0;
448
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000449 val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700450 val |= (1UL << (28+port));
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000451 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700452
453 /* add broadcast addr to filter */
454 val = 0xffffff;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000455 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
456 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700457
458 /* add station addr to filter */
459 val = MAC_HI(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000460 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700461 val = MAC_LO(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000462 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700463
464 adapter->mc_enabled = 1;
465 return 0;
466}
467
468static int
469netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter)
470{
471 u32 val = 0;
472 u16 port = adapter->physical_port;
473 u8 *addr = adapter->netdev->dev_addr;
474
475 if (!adapter->mc_enabled)
476 return 0;
477
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000478 val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700479 val &= ~(1UL << (28+port));
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000480 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700481
482 val = MAC_HI(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000483 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700484 val = MAC_LO(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000485 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700486
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000487 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), 0);
488 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700489
490 adapter->mc_enabled = 0;
491 return 0;
492}
493
494static int
495netxen_nic_set_mcast_addr(struct netxen_adapter *adapter,
496 int index, u8 *addr)
497{
498 u32 hi = 0, lo = 0;
499 u16 port = adapter->physical_port;
500
501 lo = MAC_LO(addr);
502 hi = MAC_HI(addr);
503
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000504 NXWR32(adapter, NETXEN_MCAST_ADDR(port, index), hi);
505 NXWR32(adapter, NETXEN_MCAST_ADDR(port, index)+4, lo);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700506
507 return 0;
508}
509
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700510void netxen_p2_nic_set_multi(struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400511{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700512 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400513 struct dev_mc_list *mc_ptr;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700514 u8 null_addr[6];
515 int index = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400516
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700517 memset(null_addr, 0, 6);
518
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400519 if (netdev->flags & IFF_PROMISC) {
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700520
521 adapter->set_promisc(adapter,
522 NETXEN_NIU_PROMISC_MODE);
523
524 /* Full promiscuous mode */
525 netxen_nic_disable_mcast_filter(adapter);
526
527 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400528 }
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700529
530 if (netdev->mc_count == 0) {
531 adapter->set_promisc(adapter,
532 NETXEN_NIU_NON_PROMISC_MODE);
533 netxen_nic_disable_mcast_filter(adapter);
534 return;
535 }
536
537 adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE);
538 if (netdev->flags & IFF_ALLMULTI ||
539 netdev->mc_count > adapter->max_mc_count) {
540 netxen_nic_disable_mcast_filter(adapter);
541 return;
542 }
543
544 netxen_nic_enable_mcast_filter(adapter);
545
546 for (mc_ptr = netdev->mc_list; mc_ptr; mc_ptr = mc_ptr->next, index++)
547 netxen_nic_set_mcast_addr(adapter, index, mc_ptr->dmi_addr);
548
549 if (index != netdev->mc_count)
550 printk(KERN_WARNING "%s: %s multicast address count mismatch\n",
551 netxen_nic_driver_name, netdev->name);
552
553 /* Clear out remaining addresses */
554 for (; index < adapter->max_mc_count; index++)
555 netxen_nic_set_mcast_addr(adapter, index, null_addr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400556}
557
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700558static int
559netxen_send_cmd_descs(struct netxen_adapter *adapter,
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000560 struct cmd_desc_type0 *cmd_desc_arr, int nr_desc)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700561{
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000562 u32 i, producer, consumer;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700563 struct netxen_cmd_buffer *pbuf;
564 struct cmd_desc_type0 *cmd_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000565 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700566
567 i = 0;
568
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000569 tx_ring = adapter->tx_ring;
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000570 __netif_tx_lock_bh(tx_ring->txq);
Dhananjay Phadke03e678e2009-01-14 20:49:43 -0800571
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000572 producer = tx_ring->producer;
573 consumer = tx_ring->sw_consumer;
574
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000575 if (nr_desc >= netxen_tx_avail(tx_ring)) {
576 netif_tx_stop_queue(tx_ring->txq);
577 __netif_tx_unlock_bh(tx_ring->txq);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000578 return -EBUSY;
579 }
580
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700581 do {
582 cmd_desc = &cmd_desc_arr[i];
583
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000584 pbuf = &tx_ring->cmd_buf_arr[producer];
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700585 pbuf->skb = NULL;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700586 pbuf->frag_count = 0;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700587
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000588 memcpy(&tx_ring->desc_head[producer],
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700589 &cmd_desc_arr[i], sizeof(struct cmd_desc_type0));
590
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000591 producer = get_next_index(producer, tx_ring->num_desc);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700592 i++;
593
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000594 } while (i != nr_desc);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700595
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000596 tx_ring->producer = producer;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700597
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000598 netxen_nic_update_cmd_producer(adapter, tx_ring);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700599
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000600 __netif_tx_unlock_bh(tx_ring->txq);
Dhananjay Phadke03e678e2009-01-14 20:49:43 -0800601
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700602 return 0;
603}
604
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000605static int
606nx_p3_sre_macaddr_change(struct netxen_adapter *adapter, u8 *addr, unsigned op)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700607{
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700608 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800609 nx_mac_req_t *mac_req;
610 u64 word;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700611
612 memset(&req, 0, sizeof(nx_nic_req_t));
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800613 req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23);
614
615 word = NX_MAC_EVENT | ((u64)adapter->portnum << 16);
616 req.req_hdr = cpu_to_le64(word);
617
618 mac_req = (nx_mac_req_t *)&req.words[0];
619 mac_req->op = op;
620 memcpy(mac_req->mac_addr, addr, 6);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700621
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000622 return netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
623}
624
625static int nx_p3_nic_add_mac(struct netxen_adapter *adapter,
626 u8 *addr, struct list_head *del_list)
627{
628 struct list_head *head;
629 nx_mac_list_t *cur;
630
631 /* look up if already exists */
632 list_for_each(head, del_list) {
633 cur = list_entry(head, nx_mac_list_t, list);
634
635 if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) {
636 list_move_tail(head, &adapter->mac_list);
637 return 0;
638 }
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700639 }
640
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000641 cur = kzalloc(sizeof(nx_mac_list_t), GFP_ATOMIC);
642 if (cur == NULL) {
643 printk(KERN_ERR "%s: failed to add mac address filter\n",
644 adapter->netdev->name);
645 return -ENOMEM;
646 }
647 memcpy(cur->mac_addr, addr, ETH_ALEN);
648 list_add_tail(&cur->list, &adapter->mac_list);
649 return nx_p3_sre_macaddr_change(adapter,
650 cur->mac_addr, NETXEN_MAC_ADD);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700651}
652
653void netxen_p3_nic_set_multi(struct net_device *netdev)
654{
655 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700656 struct dev_mc_list *mc_ptr;
657 u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700658 u32 mode = VPORT_MISS_MODE_DROP;
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000659 LIST_HEAD(del_list);
660 struct list_head *head;
661 nx_mac_list_t *cur;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700662
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000663 list_splice_tail_init(&adapter->mac_list, &del_list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700664
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000665 nx_p3_nic_add_mac(adapter, netdev->dev_addr, &del_list);
666 nx_p3_nic_add_mac(adapter, bcast_addr, &del_list);
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700667
668 if (netdev->flags & IFF_PROMISC) {
669 mode = VPORT_MISS_MODE_ACCEPT_ALL;
670 goto send_fw_cmd;
671 }
672
673 if ((netdev->flags & IFF_ALLMULTI) ||
674 (netdev->mc_count > adapter->max_mc_count)) {
675 mode = VPORT_MISS_MODE_ACCEPT_MULTI;
676 goto send_fw_cmd;
677 }
678
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700679 if (netdev->mc_count > 0) {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700680 for (mc_ptr = netdev->mc_list; mc_ptr;
681 mc_ptr = mc_ptr->next) {
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000682 nx_p3_nic_add_mac(adapter, mc_ptr->dmi_addr, &del_list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700683 }
684 }
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700685
686send_fw_cmd:
687 adapter->set_promisc(adapter, mode);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000688 head = &del_list;
689 while (!list_empty(head)) {
690 cur = list_entry(head->next, nx_mac_list_t, list);
691
692 nx_p3_sre_macaddr_change(adapter,
693 cur->mac_addr, NETXEN_MAC_DEL);
694 list_del(&cur->list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700695 kfree(cur);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700696 }
697}
698
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700699int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
700{
701 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800702 u64 word;
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700703
704 memset(&req, 0, sizeof(nx_nic_req_t));
705
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800706 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
707
708 word = NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE |
709 ((u64)adapter->portnum << 16);
710 req.req_hdr = cpu_to_le64(word);
711
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700712 req.words[0] = cpu_to_le64(mode);
713
714 return netxen_send_cmd_descs(adapter,
715 (struct cmd_desc_type0 *)&req, 1);
716}
717
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800718void netxen_p3_free_mac_list(struct netxen_adapter *adapter)
719{
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000720 nx_mac_list_t *cur;
721 struct list_head *head = &adapter->mac_list;
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800722
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000723 while (!list_empty(head)) {
724 cur = list_entry(head->next, nx_mac_list_t, list);
725 nx_p3_sre_macaddr_change(adapter,
726 cur->mac_addr, NETXEN_MAC_DEL);
727 list_del(&cur->list);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800728 kfree(cur);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800729 }
730}
731
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000732int netxen_p3_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr)
733{
734 /* assuming caller has already copied new addr to netdev */
735 netxen_p3_nic_set_multi(adapter->netdev);
736 return 0;
737}
738
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700739#define NETXEN_CONFIG_INTR_COALESCE 3
740
741/*
742 * Send the interrupt coalescing parameter set by ethtool to the card.
743 */
744int netxen_config_intr_coalesce(struct netxen_adapter *adapter)
745{
746 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800747 u64 word;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700748 int rv;
749
750 memset(&req, 0, sizeof(nx_nic_req_t));
751
Narender Kumar1bb482f2009-08-23 08:35:09 +0000752 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800753
754 word = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16);
755 req.req_hdr = cpu_to_le64(word);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700756
757 memcpy(&req.words[0], &adapter->coal, sizeof(adapter->coal));
758
759 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
760 if (rv != 0) {
761 printk(KERN_ERR "ERROR. Could not send "
762 "interrupt coalescing parameters\n");
763 }
764
765 return rv;
766}
767
Narender Kumar1bb482f2009-08-23 08:35:09 +0000768int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable)
769{
770 nx_nic_req_t req;
771 u64 word;
772 int rv = 0;
773
774 if ((adapter->flags & NETXEN_NIC_LRO_ENABLED) == enable)
775 return 0;
776
777 memset(&req, 0, sizeof(nx_nic_req_t));
778
779 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
780
781 word = NX_NIC_H2C_OPCODE_CONFIG_HW_LRO | ((u64)adapter->portnum << 16);
782 req.req_hdr = cpu_to_le64(word);
783
784 req.words[0] = cpu_to_le64(enable);
785
786 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
787 if (rv != 0) {
788 printk(KERN_ERR "ERROR. Could not send "
789 "configure hw lro request\n");
790 }
791
792 adapter->flags ^= NETXEN_NIC_LRO_ENABLED;
793
794 return rv;
795}
796
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000797#define RSS_HASHTYPE_IP_TCP 0x3
798
799int netxen_config_rss(struct netxen_adapter *adapter, int enable)
800{
801 nx_nic_req_t req;
802 u64 word;
803 int i, rv;
804
805 u64 key[] = { 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL,
806 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
807 0x255b0ec26d5a56daULL };
808
809
810 memset(&req, 0, sizeof(nx_nic_req_t));
811 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
812
813 word = NX_NIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16);
814 req.req_hdr = cpu_to_le64(word);
815
816 /*
817 * RSS request:
818 * bits 3-0: hash_method
819 * 5-4: hash_type_ipv4
820 * 7-6: hash_type_ipv6
821 * 8: enable
822 * 9: use indirection table
823 * 47-10: reserved
824 * 63-48: indirection table mask
825 */
826 word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) |
827 ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) |
828 ((u64)(enable & 0x1) << 8) |
829 ((0x7ULL) << 48);
830 req.words[0] = cpu_to_le64(word);
831 for (i = 0; i < 5; i++)
832 req.words[i+1] = cpu_to_le64(key[i]);
833
834
835 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
836 if (rv != 0) {
837 printk(KERN_ERR "%s: could not configure RSS\n",
838 adapter->netdev->name);
839 }
840
841 return rv;
842}
843
Dhananjay Phadke6598b162009-07-26 20:07:37 +0000844int netxen_config_ipaddr(struct netxen_adapter *adapter, u32 ip, int cmd)
845{
846 nx_nic_req_t req;
847 u64 word;
848 int rv;
849
850 memset(&req, 0, sizeof(nx_nic_req_t));
851 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
852
853 word = NX_NIC_H2C_OPCODE_CONFIG_IPADDR | ((u64)adapter->portnum << 16);
854 req.req_hdr = cpu_to_le64(word);
855
856 req.words[0] = cpu_to_le64(cmd);
857 req.words[1] = cpu_to_le64(ip);
858
859 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
860 if (rv != 0) {
861 printk(KERN_ERR "%s: could not notify %s IP 0x%x reuqest\n",
862 adapter->netdev->name,
863 (cmd == NX_IP_UP) ? "Add" : "Remove", ip);
864 }
865 return rv;
866}
867
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000868int netxen_linkevent_request(struct netxen_adapter *adapter, int enable)
869{
870 nx_nic_req_t req;
871 u64 word;
872 int rv;
873
874 memset(&req, 0, sizeof(nx_nic_req_t));
875 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
876
877 word = NX_NIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16);
878 req.req_hdr = cpu_to_le64(word);
Dhananjay Phadke22527862009-05-05 19:05:06 +0000879 req.words[0] = cpu_to_le64(enable | (enable << 8));
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000880
881 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
882 if (rv != 0) {
883 printk(KERN_ERR "%s: could not configure link notification\n",
884 adapter->netdev->name);
885 }
886
887 return rv;
888}
889
Narender Kumar1bb482f2009-08-23 08:35:09 +0000890int netxen_send_lro_cleanup(struct netxen_adapter *adapter)
891{
892 nx_nic_req_t req;
893 u64 word;
894 int rv;
895
896 memset(&req, 0, sizeof(nx_nic_req_t));
897 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
898
899 word = NX_NIC_H2C_OPCODE_LRO_REQUEST |
900 ((u64)adapter->portnum << 16) |
901 ((u64)NX_NIC_LRO_REQUEST_CLEANUP << 56) ;
902
903 req.req_hdr = cpu_to_le64(word);
904
905 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
906 if (rv != 0) {
907 printk(KERN_ERR "%s: could not cleanup lro flows\n",
908 adapter->netdev->name);
909 }
910 return rv;
911}
912
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400913/*
914 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
915 * @returns 0 on success, negative on failure
916 */
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700917
918#define MTU_FUDGE_FACTOR 100
919
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400920int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
921{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700922 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700923 int max_mtu;
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700924 int rc = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400925
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700926 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
927 max_mtu = P3_MAX_MTU;
928 else
929 max_mtu = P2_MAX_MTU;
930
931 if (mtu > max_mtu) {
932 printk(KERN_ERR "%s: mtu > %d bytes unsupported\n",
933 netdev->name, max_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400934 return -EINVAL;
935 }
936
Amit S. Kale80922fb2006-12-04 09:18:00 -0800937 if (adapter->set_mtu)
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700938 rc = adapter->set_mtu(adapter, mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400939
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700940 if (!rc)
941 netdev->mtu = mtu;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700942
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700943 return rc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400944}
945
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400946static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
Al Virof305f782007-12-22 19:44:00 +0000947 int size, __le32 * buf)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400948{
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000949 int i, v, addr;
Al Virof305f782007-12-22 19:44:00 +0000950 __le32 *ptr32;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400951
952 addr = base;
953 ptr32 = buf;
954 for (i = 0; i < size / sizeof(u32); i++) {
Al Virof305f782007-12-22 19:44:00 +0000955 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400956 return -1;
Al Virof305f782007-12-22 19:44:00 +0000957 *ptr32 = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400958 ptr32++;
959 addr += sizeof(u32);
960 }
961 if ((char *)buf + size > (char *)ptr32) {
Al Virof305f782007-12-22 19:44:00 +0000962 __le32 local;
963 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400964 return -1;
Al Virof305f782007-12-22 19:44:00 +0000965 local = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400966 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
967 }
968
969 return 0;
970}
971
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700972int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 *mac)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400973{
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700974 __le32 *pmac = (__le32 *) mac;
975 u32 offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400976
Dhananjay Phadke06db58c2009-08-05 07:34:08 +0000977 offset = NX_FW_MAC_ADDR_OFFSET + (adapter->portnum * sizeof(u64));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700978
979 if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400980 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700981
Al Virof305f782007-12-22 19:44:00 +0000982 if (*mac == cpu_to_le64(~0ULL)) {
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700983
Dhananjay Phadke06db58c2009-08-05 07:34:08 +0000984 offset = NX_OLD_MAC_ADDR_OFFSET +
985 (adapter->portnum * sizeof(u64));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700986
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400987 if (netxen_get_flash_block(adapter,
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700988 offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400989 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700990
Al Virof305f782007-12-22 19:44:00 +0000991 if (*mac == cpu_to_le64(~0ULL))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400992 return -1;
993 }
994 return 0;
995}
996
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700997int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, __le64 *mac)
998{
999 uint32_t crbaddr, mac_hi, mac_lo;
1000 int pci_func = adapter->ahw.pci_func;
1001
1002 crbaddr = CRB_MAC_BLOCK_START +
1003 (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1));
1004
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001005 mac_lo = NXRD32(adapter, crbaddr);
1006 mac_hi = NXRD32(adapter, crbaddr+4);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001007
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001008 if (pci_func & 1)
Dhananjay Phadke2edbb452009-01-14 20:47:30 -08001009 *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001010 else
Dhananjay Phadke2edbb452009-01-14 20:47:30 -08001011 *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001012
1013 return 0;
1014}
1015
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001016/*
1017 * Changes the CRB window to the specified window.
1018 */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001019void
1020netxen_nic_pci_change_crbwindow_128M(struct netxen_adapter *adapter, u32 wndw)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001021{
1022 void __iomem *offset;
1023 u32 tmp;
1024 int count = 0;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001025 uint8_t func = adapter->ahw.pci_func;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001026
1027 if (adapter->curr_window == wndw)
1028 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001029 /*
1030 * Move the CRB window.
1031 * We need to write to the "direct access" region of PCI
1032 * to avoid a race condition where the window register has
1033 * not been successfully written across CRB before the target
1034 * register address is received by PCI. The direct region bypasses
1035 * the CRB bus.
1036 */
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001037 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1038 NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001039
1040 if (wndw & 0x1)
1041 wndw = NETXEN_WINDOW_ONE;
1042
1043 writel(wndw, offset);
1044
1045 /* MUST make sure window is set before we forge on... */
1046 while ((tmp = readl(offset)) != wndw) {
1047 printk(KERN_WARNING "%s: %s WARNING: CRB window value not "
1048 "registered properly: 0x%08x.\n",
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001049 netxen_nic_driver_name, __func__, tmp);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001050 mdelay(1);
1051 if (count >= 10)
1052 break;
1053 count++;
1054 }
1055
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001056 if (wndw == NETXEN_WINDOW_ONE)
1057 adapter->curr_window = 1;
1058 else
1059 adapter->curr_window = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001060}
1061
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001062/*
1063 * Return -1 if off is not valid,
1064 * 1 if window access is needed. 'off' is set to offset from
1065 * CRB space in 128M pci map
1066 * 0 if no window access is needed. 'off' is set to 2M addr
1067 * In: 'off' is offset from base in 128M pci map
1068 */
1069static int
Dhananjay Phadke23b6cc42009-05-08 22:02:30 +00001070netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, ulong *off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001071{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001072 crb_128M_2M_sub_block_map_t *m;
1073
1074
1075 if (*off >= NETXEN_CRB_MAX)
1076 return -1;
1077
Dhananjay Phadke23b6cc42009-05-08 22:02:30 +00001078 if (*off >= NETXEN_PCI_CAMQM && (*off < NETXEN_PCI_CAMQM_2M_END)) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001079 *off = (*off - NETXEN_PCI_CAMQM) + NETXEN_PCI_CAMQM_2M_BASE +
1080 (ulong)adapter->ahw.pci_base0;
1081 return 0;
1082 }
1083
1084 if (*off < NETXEN_PCI_CRBSPACE)
1085 return -1;
1086
1087 *off -= NETXEN_PCI_CRBSPACE;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001088
1089 /*
1090 * Try direct map
1091 */
1092 m = &crb_128M_2M_map[CRB_BLK(*off)].sub_block[CRB_SUBBLK(*off)];
1093
Dhananjay Phadke23b6cc42009-05-08 22:02:30 +00001094 if (m->valid && (m->start_128M <= *off) && (m->end_128M > *off)) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001095 *off = *off + m->start_2M - m->start_128M +
1096 (ulong)adapter->ahw.pci_base0;
1097 return 0;
1098 }
1099
1100 /*
1101 * Not in direct map, use crb window
1102 */
1103 return 1;
1104}
1105
1106/*
1107 * In: 'off' is offset from CRB space in 128M pci map
1108 * Out: 'off' is 2M pci map addr
1109 * side effect: lock crb window
1110 */
1111static void
1112netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong *off)
1113{
1114 u32 win_read;
1115
1116 adapter->crb_win = CRB_HI(*off);
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001117 writel(adapter->crb_win, (adapter->ahw.pci_base0 + CRB_WINDOW_2M));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001118 /*
1119 * Read back value to make sure write has gone through before trying
1120 * to use it.
1121 */
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001122 win_read = readl(adapter->ahw.pci_base0 + CRB_WINDOW_2M);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001123 if (win_read != adapter->crb_win) {
1124 printk(KERN_ERR "%s: Written crbwin (0x%x) != "
1125 "Read crbwin (0x%x), off=0x%lx\n",
1126 __func__, adapter->crb_win, win_read, *off);
1127 }
1128 *off = (*off & MASK(16)) + CRB_INDIRECT_2M +
1129 (ulong)adapter->ahw.pci_base0;
1130}
1131
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001132int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001133netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001134{
1135 void __iomem *addr;
1136
1137 if (ADDR_IN_WINDOW1(off)) {
1138 addr = NETXEN_CRB_NORMALIZE(adapter, off);
1139 } else { /* Window 0 */
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001140 addr = pci_base_offset(adapter, off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001141 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001142 }
1143
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001144 if (!addr) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001145 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001146 return 1;
1147 }
1148
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001149 writel(data, addr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001150
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001151 if (!ADDR_IN_WINDOW1(off))
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001152 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001153
1154 return 0;
1155}
1156
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001157u32
1158netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001159{
1160 void __iomem *addr;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001161 u32 data;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001162
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001163 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
1164 addr = NETXEN_CRB_NORMALIZE(adapter, off);
1165 } else { /* Window 0 */
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001166 addr = pci_base_offset(adapter, off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001167 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001168 }
1169
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001170 if (!addr) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001171 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001172 return 1;
1173 }
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001174
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001175 data = readl(addr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001176
1177 if (!ADDR_IN_WINDOW1(off))
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001178 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1179
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001180 return data;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001181}
1182
1183int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001184netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001185{
1186 unsigned long flags = 0;
1187 int rv;
1188
Dhananjay Phadke23b6cc42009-05-08 22:02:30 +00001189 rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001190
1191 if (rv == -1) {
1192 printk(KERN_ERR "%s: invalid offset: 0x%016lx\n",
1193 __func__, off);
1194 dump_stack();
1195 return -1;
1196 }
1197
1198 if (rv == 1) {
1199 write_lock_irqsave(&adapter->adapter_lock, flags);
1200 crb_win_lock(adapter);
1201 netxen_nic_pci_set_crbwindow_2M(adapter, &off);
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001202 writel(data, (void __iomem *)off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001203 crb_win_unlock(adapter);
1204 write_unlock_irqrestore(&adapter->adapter_lock, flags);
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001205 } else
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001206 writel(data, (void __iomem *)off);
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001207
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001208
1209 return 0;
1210}
1211
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001212u32
1213netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001214{
1215 unsigned long flags = 0;
1216 int rv;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001217 u32 data;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001218
Dhananjay Phadke23b6cc42009-05-08 22:02:30 +00001219 rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001220
1221 if (rv == -1) {
1222 printk(KERN_ERR "%s: invalid offset: 0x%016lx\n",
1223 __func__, off);
1224 dump_stack();
1225 return -1;
1226 }
1227
1228 if (rv == 1) {
1229 write_lock_irqsave(&adapter->adapter_lock, flags);
1230 crb_win_lock(adapter);
1231 netxen_nic_pci_set_crbwindow_2M(adapter, &off);
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001232 data = readl((void __iomem *)off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001233 crb_win_unlock(adapter);
1234 write_unlock_irqrestore(&adapter->adapter_lock, flags);
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001235 } else
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001236 data = readl((void __iomem *)off);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001237
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001238 return data;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001239}
1240
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001241/*
1242 * check memory access boundary.
1243 * used by test agent. support ddr access only for now
1244 */
1245static unsigned long
1246netxen_nic_pci_mem_bound_check(struct netxen_adapter *adapter,
1247 unsigned long long addr, int size)
1248{
1249 if (!ADDR_IN_RANGE(addr,
1250 NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX) ||
1251 !ADDR_IN_RANGE(addr+size-1,
1252 NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX) ||
1253 ((size != 1) && (size != 2) && (size != 4) && (size != 8))) {
1254 return 0;
1255 }
1256
1257 return 1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001258}
1259
Jeff Garzik47906542007-11-23 21:23:36 -05001260static int netxen_pci_set_window_warning_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001261
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001262unsigned long
1263netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
1264 unsigned long long addr)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001265{
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001266 void __iomem *offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001267 int window;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001268 unsigned long long qdr_max;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001269 uint8_t func = adapter->ahw.pci_func;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001270
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001271 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1272 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P2;
1273 } else {
1274 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P3;
1275 }
1276
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001277 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1278 /* DDR network side */
1279 addr -= NETXEN_ADDR_DDR_NET;
1280 window = (addr >> 25) & 0x3ff;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001281 if (adapter->ahw.ddr_mn_window != window) {
1282 adapter->ahw.ddr_mn_window = window;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001283 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1284 NETXEN_PCIX_PH_REG(PCIE_MN_WINDOW_REG(func)));
1285 writel(window, offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001286 /* MUST make sure window is set before we forge on... */
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001287 readl(offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001288 }
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001289 addr -= (window * NETXEN_WINDOW_ONE);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001290 addr += NETXEN_PCI_DDR_NET;
1291 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1292 addr -= NETXEN_ADDR_OCM0;
1293 addr += NETXEN_PCI_OCM0;
1294 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1295 addr -= NETXEN_ADDR_OCM1;
1296 addr += NETXEN_PCI_OCM1;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001297 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_QDR_NET, qdr_max)) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001298 /* QDR network side */
1299 addr -= NETXEN_ADDR_QDR_NET;
1300 window = (addr >> 22) & 0x3f;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001301 if (adapter->ahw.qdr_sn_window != window) {
1302 adapter->ahw.qdr_sn_window = window;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001303 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1304 NETXEN_PCIX_PH_REG(PCIE_SN_WINDOW_REG(func)));
1305 writel((window << 22), offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001306 /* MUST make sure window is set before we forge on... */
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001307 readl(offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001308 }
1309 addr -= (window * 0x400000);
1310 addr += NETXEN_PCI_QDR_NET;
1311 } else {
1312 /*
1313 * peg gdb frequently accesses memory that doesn't exist,
1314 * this limits the chit chat so debugging isn't slowed down.
1315 */
1316 if ((netxen_pci_set_window_warning_count++ < 8)
1317 || (netxen_pci_set_window_warning_count % 64 == 0))
1318 printk("%s: Warning:netxen_nic_pci_set_window()"
1319 " Unknown address range!\n",
1320 netxen_nic_driver_name);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001321 addr = -1UL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001322 }
1323 return addr;
1324}
1325
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001326/*
1327 * Note : only 32-bit writes!
1328 */
1329int netxen_nic_pci_write_immediate_128M(struct netxen_adapter *adapter,
1330 u64 off, u32 data)
1331{
1332 writel(data, (void __iomem *)(PCI_OFFSET_SECOND_RANGE(adapter, off)));
1333 return 0;
1334}
1335
1336u32 netxen_nic_pci_read_immediate_128M(struct netxen_adapter *adapter, u64 off)
1337{
1338 return readl((void __iomem *)(pci_base_offset(adapter, off)));
1339}
1340
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001341unsigned long
1342netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
1343 unsigned long long addr)
1344{
1345 int window;
1346 u32 win_read;
1347
1348 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1349 /* DDR network side */
1350 window = MN_WIN(addr);
1351 adapter->ahw.ddr_mn_window = window;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001352 NXWR32(adapter, adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001353 window);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001354 win_read = NXRD32(adapter,
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001355 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001356 if ((win_read << 17) != window) {
1357 printk(KERN_INFO "Written MNwin (0x%x) != "
1358 "Read MNwin (0x%x)\n", window, win_read);
1359 }
1360 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_DDR_NET;
1361 } else if (ADDR_IN_RANGE(addr,
1362 NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1363 if ((addr & 0x00ff800) == 0xff800) {
1364 printk("%s: QM access not handled.\n", __func__);
1365 addr = -1UL;
1366 }
1367
1368 window = OCM_WIN(addr);
1369 adapter->ahw.ddr_mn_window = window;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001370 NXWR32(adapter, adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001371 window);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001372 win_read = NXRD32(adapter,
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001373 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001374 if ((win_read >> 7) != window) {
1375 printk(KERN_INFO "%s: Written OCMwin (0x%x) != "
1376 "Read OCMwin (0x%x)\n",
1377 __func__, window, win_read);
1378 }
1379 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_OCM0_2M;
1380
1381 } else if (ADDR_IN_RANGE(addr,
1382 NETXEN_ADDR_QDR_NET, NETXEN_ADDR_QDR_NET_MAX_P3)) {
1383 /* QDR network side */
1384 window = MS_WIN(addr);
1385 adapter->ahw.qdr_sn_window = window;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001386 NXWR32(adapter, adapter->ahw.ms_win_crb | NETXEN_PCI_CRBSPACE,
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001387 window);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001388 win_read = NXRD32(adapter,
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001389 adapter->ahw.ms_win_crb | NETXEN_PCI_CRBSPACE);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001390 if (win_read != window) {
1391 printk(KERN_INFO "%s: Written MSwin (0x%x) != "
1392 "Read MSwin (0x%x)\n",
1393 __func__, window, win_read);
1394 }
1395 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_QDR_NET;
1396
1397 } else {
1398 /*
1399 * peg gdb frequently accesses memory that doesn't exist,
1400 * this limits the chit chat so debugging isn't slowed down.
1401 */
1402 if ((netxen_pci_set_window_warning_count++ < 8)
1403 || (netxen_pci_set_window_warning_count%64 == 0)) {
1404 printk("%s: Warning:%s Unknown address range!\n",
1405 __func__, netxen_nic_driver_name);
1406}
1407 addr = -1UL;
1408 }
1409 return addr;
1410}
1411
1412static int netxen_nic_pci_is_same_window(struct netxen_adapter *adapter,
1413 unsigned long long addr)
1414{
1415 int window;
1416 unsigned long long qdr_max;
1417
1418 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
1419 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P2;
1420 else
1421 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P3;
1422
1423 if (ADDR_IN_RANGE(addr,
1424 NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1425 /* DDR network side */
1426 BUG(); /* MN access can not come here */
1427 } else if (ADDR_IN_RANGE(addr,
1428 NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1429 return 1;
1430 } else if (ADDR_IN_RANGE(addr,
1431 NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1432 return 1;
1433 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_QDR_NET, qdr_max)) {
1434 /* QDR network side */
1435 window = ((addr - NETXEN_ADDR_QDR_NET) >> 22) & 0x3f;
1436 if (adapter->ahw.qdr_sn_window == window)
1437 return 1;
1438 }
1439
1440 return 0;
1441}
1442
1443static int netxen_nic_pci_mem_read_direct(struct netxen_adapter *adapter,
1444 u64 off, void *data, int size)
1445{
1446 unsigned long flags;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001447 void __iomem *addr, *mem_ptr = NULL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001448 int ret = 0;
1449 u64 start;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001450 unsigned long mem_base;
1451 unsigned long mem_page;
1452
1453 write_lock_irqsave(&adapter->adapter_lock, flags);
1454
1455 /*
1456 * If attempting to access unknown address or straddle hw windows,
1457 * do not access.
1458 */
1459 start = adapter->pci_set_window(adapter, off);
1460 if ((start == -1UL) ||
1461 (netxen_nic_pci_is_same_window(adapter, off+size-1) == 0)) {
1462 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1463 printk(KERN_ERR "%s out of bound pci memory access. "
Andrew Morton11a859e2008-07-30 12:50:12 -07001464 "offset is 0x%llx\n", netxen_nic_driver_name,
1465 (unsigned long long)off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001466 return -1;
1467 }
1468
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001469 addr = pci_base_offset(adapter, start);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001470 if (!addr) {
1471 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1472 mem_base = pci_resource_start(adapter->pdev, 0);
1473 mem_page = start & PAGE_MASK;
1474 /* Map two pages whenever user tries to access addresses in two
1475 consecutive pages.
1476 */
1477 if (mem_page != ((start + size - 1) & PAGE_MASK))
1478 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1479 else
1480 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
Hannes Ederf8057b72008-12-26 00:04:26 -08001481 if (mem_ptr == NULL) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001482 *(uint8_t *)data = 0;
1483 return -1;
1484 }
1485 addr = mem_ptr;
1486 addr += start & (PAGE_SIZE - 1);
1487 write_lock_irqsave(&adapter->adapter_lock, flags);
1488 }
1489
1490 switch (size) {
1491 case 1:
1492 *(uint8_t *)data = readb(addr);
1493 break;
1494 case 2:
1495 *(uint16_t *)data = readw(addr);
1496 break;
1497 case 4:
1498 *(uint32_t *)data = readl(addr);
1499 break;
1500 case 8:
1501 *(uint64_t *)data = readq(addr);
1502 break;
1503 default:
1504 ret = -1;
1505 break;
1506 }
1507 write_unlock_irqrestore(&adapter->adapter_lock, flags);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001508
1509 if (mem_ptr)
1510 iounmap(mem_ptr);
1511 return ret;
1512}
1513
1514static int
1515netxen_nic_pci_mem_write_direct(struct netxen_adapter *adapter, u64 off,
1516 void *data, int size)
1517{
1518 unsigned long flags;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001519 void __iomem *addr, *mem_ptr = NULL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001520 int ret = 0;
1521 u64 start;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001522 unsigned long mem_base;
1523 unsigned long mem_page;
1524
1525 write_lock_irqsave(&adapter->adapter_lock, flags);
1526
1527 /*
1528 * If attempting to access unknown address or straddle hw windows,
1529 * do not access.
1530 */
1531 start = adapter->pci_set_window(adapter, off);
1532 if ((start == -1UL) ||
1533 (netxen_nic_pci_is_same_window(adapter, off+size-1) == 0)) {
1534 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1535 printk(KERN_ERR "%s out of bound pci memory access. "
Andrew Morton11a859e2008-07-30 12:50:12 -07001536 "offset is 0x%llx\n", netxen_nic_driver_name,
1537 (unsigned long long)off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001538 return -1;
1539 }
1540
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001541 addr = pci_base_offset(adapter, start);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001542 if (!addr) {
1543 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1544 mem_base = pci_resource_start(adapter->pdev, 0);
1545 mem_page = start & PAGE_MASK;
1546 /* Map two pages whenever user tries to access addresses in two
1547 * consecutive pages.
1548 */
1549 if (mem_page != ((start + size - 1) & PAGE_MASK))
1550 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE*2);
1551 else
1552 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
Hannes Ederf8057b72008-12-26 00:04:26 -08001553 if (mem_ptr == NULL)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001554 return -1;
1555 addr = mem_ptr;
1556 addr += start & (PAGE_SIZE - 1);
1557 write_lock_irqsave(&adapter->adapter_lock, flags);
1558 }
1559
1560 switch (size) {
1561 case 1:
1562 writeb(*(uint8_t *)data, addr);
1563 break;
1564 case 2:
1565 writew(*(uint16_t *)data, addr);
1566 break;
1567 case 4:
1568 writel(*(uint32_t *)data, addr);
1569 break;
1570 case 8:
1571 writeq(*(uint64_t *)data, addr);
1572 break;
1573 default:
1574 ret = -1;
1575 break;
1576 }
1577 write_unlock_irqrestore(&adapter->adapter_lock, flags);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001578 if (mem_ptr)
1579 iounmap(mem_ptr);
1580 return ret;
1581}
1582
1583#define MAX_CTL_CHECK 1000
1584
1585int
1586netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
1587 u64 off, void *data, int size)
1588{
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001589 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001590 int i, j, ret = 0, loop, sz[2], off0;
1591 uint32_t temp;
1592 uint64_t off8, tmpw, word[2] = {0, 0};
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001593 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001594
1595 /*
1596 * If not MN, go check for MS or invalid.
1597 */
1598 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1599 return netxen_nic_pci_mem_write_direct(adapter,
1600 off, data, size);
1601
1602 off8 = off & 0xfffffff8;
1603 off0 = off & 0x7;
1604 sz[0] = (size < (8 - off0)) ? size : (8 - off0);
1605 sz[1] = size - sz[0];
1606 loop = ((off0 + size - 1) >> 3) + 1;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001607 mem_crb = pci_base_offset(adapter, NETXEN_CRB_DDR_NET);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001608
1609 if ((size != 8) || (off0 != 0)) {
1610 for (i = 0; i < loop; i++) {
1611 if (adapter->pci_mem_read(adapter,
1612 off8 + (i << 3), &word[i], 8))
1613 return -1;
1614 }
1615 }
1616
1617 switch (size) {
1618 case 1:
1619 tmpw = *((uint8_t *)data);
1620 break;
1621 case 2:
1622 tmpw = *((uint16_t *)data);
1623 break;
1624 case 4:
1625 tmpw = *((uint32_t *)data);
1626 break;
1627 case 8:
1628 default:
1629 tmpw = *((uint64_t *)data);
1630 break;
1631 }
1632 word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
1633 word[0] |= tmpw << (off0 * 8);
1634
1635 if (loop == 2) {
1636 word[1] &= ~(~0ULL << (sz[1] * 8));
1637 word[1] |= tmpw >> (sz[0] * 8);
1638 }
1639
1640 write_lock_irqsave(&adapter->adapter_lock, flags);
1641 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1642
1643 for (i = 0; i < loop; i++) {
1644 writel((uint32_t)(off8 + (i << 3)),
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001645 (mem_crb+MIU_TEST_AGT_ADDR_LO));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001646 writel(0,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001647 (mem_crb+MIU_TEST_AGT_ADDR_HI));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001648 writel(word[i] & 0xffffffff,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001649 (mem_crb+MIU_TEST_AGT_WRDATA_LO));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001650 writel((word[i] >> 32) & 0xffffffff,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001651 (mem_crb+MIU_TEST_AGT_WRDATA_HI));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001652 writel(MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001653 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001654 writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001655 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001656
1657 for (j = 0; j < MAX_CTL_CHECK; j++) {
1658 temp = readl(
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001659 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001660 if ((temp & MIU_TA_CTL_BUSY) == 0)
1661 break;
1662 }
1663
1664 if (j >= MAX_CTL_CHECK) {
Dhananjay Phadke39754f42009-02-17 20:27:02 -08001665 if (printk_ratelimit())
1666 dev_err(&adapter->pdev->dev,
1667 "failed to write through agent\n");
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001668 ret = -1;
1669 break;
1670 }
1671 }
1672
1673 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1674 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1675 return ret;
1676}
1677
1678int
1679netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
1680 u64 off, void *data, int size)
1681{
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001682 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001683 int i, j = 0, k, start, end, loop, sz[2], off0[2];
1684 uint32_t temp;
1685 uint64_t off8, val, word[2] = {0, 0};
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001686 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001687
1688
1689 /*
1690 * If not MN, go check for MS or invalid.
1691 */
1692 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1693 return netxen_nic_pci_mem_read_direct(adapter, off, data, size);
1694
1695 off8 = off & 0xfffffff8;
1696 off0[0] = off & 0x7;
1697 off0[1] = 0;
1698 sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]);
1699 sz[1] = size - sz[0];
1700 loop = ((off0[0] + size - 1) >> 3) + 1;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001701 mem_crb = pci_base_offset(adapter, NETXEN_CRB_DDR_NET);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001702
1703 write_lock_irqsave(&adapter->adapter_lock, flags);
1704 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1705
1706 for (i = 0; i < loop; i++) {
1707 writel((uint32_t)(off8 + (i << 3)),
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001708 (mem_crb+MIU_TEST_AGT_ADDR_LO));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001709 writel(0,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001710 (mem_crb+MIU_TEST_AGT_ADDR_HI));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001711 writel(MIU_TA_CTL_ENABLE,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001712 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001713 writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001714 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001715
1716 for (j = 0; j < MAX_CTL_CHECK; j++) {
1717 temp = readl(
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001718 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001719 if ((temp & MIU_TA_CTL_BUSY) == 0)
1720 break;
1721 }
1722
1723 if (j >= MAX_CTL_CHECK) {
Dhananjay Phadke39754f42009-02-17 20:27:02 -08001724 if (printk_ratelimit())
1725 dev_err(&adapter->pdev->dev,
1726 "failed to read through agent\n");
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001727 break;
1728 }
1729
1730 start = off0[i] >> 2;
1731 end = (off0[i] + sz[i] - 1) >> 2;
1732 for (k = start; k <= end; k++) {
1733 word[i] |= ((uint64_t) readl(
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001734 (mem_crb +
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001735 MIU_TEST_AGT_RDDATA(k))) << (32*k));
1736 }
1737 }
1738
1739 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1740 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1741
1742 if (j >= MAX_CTL_CHECK)
1743 return -1;
1744
1745 if (sz[0] == 8) {
1746 val = word[0];
1747 } else {
1748 val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
1749 ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
1750 }
1751
1752 switch (size) {
1753 case 1:
1754 *(uint8_t *)data = val;
1755 break;
1756 case 2:
1757 *(uint16_t *)data = val;
1758 break;
1759 case 4:
1760 *(uint32_t *)data = val;
1761 break;
1762 case 8:
1763 *(uint64_t *)data = val;
1764 break;
1765 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001766 return 0;
1767}
1768
1769int
1770netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
1771 u64 off, void *data, int size)
1772{
1773 int i, j, ret = 0, loop, sz[2], off0;
1774 uint32_t temp;
1775 uint64_t off8, mem_crb, tmpw, word[2] = {0, 0};
1776
1777 /*
1778 * If not MN, go check for MS or invalid.
1779 */
1780 if (off >= NETXEN_ADDR_QDR_NET && off <= NETXEN_ADDR_QDR_NET_MAX_P3)
1781 mem_crb = NETXEN_CRB_QDR_NET;
1782 else {
1783 mem_crb = NETXEN_CRB_DDR_NET;
1784 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1785 return netxen_nic_pci_mem_write_direct(adapter,
1786 off, data, size);
1787 }
1788
1789 off8 = off & 0xfffffff8;
1790 off0 = off & 0x7;
1791 sz[0] = (size < (8 - off0)) ? size : (8 - off0);
1792 sz[1] = size - sz[0];
1793 loop = ((off0 + size - 1) >> 3) + 1;
1794
1795 if ((size != 8) || (off0 != 0)) {
1796 for (i = 0; i < loop; i++) {
1797 if (adapter->pci_mem_read(adapter, off8 + (i << 3),
1798 &word[i], 8))
1799 return -1;
1800 }
1801 }
1802
1803 switch (size) {
1804 case 1:
1805 tmpw = *((uint8_t *)data);
1806 break;
1807 case 2:
1808 tmpw = *((uint16_t *)data);
1809 break;
1810 case 4:
1811 tmpw = *((uint32_t *)data);
1812 break;
1813 case 8:
1814 default:
1815 tmpw = *((uint64_t *)data);
1816 break;
1817 }
1818
1819 word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
1820 word[0] |= tmpw << (off0 * 8);
1821
1822 if (loop == 2) {
1823 word[1] &= ~(~0ULL << (sz[1] * 8));
1824 word[1] |= tmpw >> (sz[0] * 8);
1825 }
1826
1827 /*
1828 * don't lock here - write_wx gets the lock if each time
1829 * write_lock_irqsave(&adapter->adapter_lock, flags);
1830 * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1831 */
1832
1833 for (i = 0; i < loop; i++) {
1834 temp = off8 + (i << 3);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001835 NXWR32(adapter, mem_crb+MIU_TEST_AGT_ADDR_LO, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001836 temp = 0;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001837 NXWR32(adapter, mem_crb+MIU_TEST_AGT_ADDR_HI, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001838 temp = word[i] & 0xffffffff;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001839 NXWR32(adapter, mem_crb+MIU_TEST_AGT_WRDATA_LO, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001840 temp = (word[i] >> 32) & 0xffffffff;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001841 NXWR32(adapter, mem_crb+MIU_TEST_AGT_WRDATA_HI, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001842 temp = MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001843 NXWR32(adapter, mem_crb+MIU_TEST_AGT_CTRL, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001844 temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001845 NXWR32(adapter, mem_crb+MIU_TEST_AGT_CTRL, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001846
1847 for (j = 0; j < MAX_CTL_CHECK; j++) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001848 temp = NXRD32(adapter, mem_crb + MIU_TEST_AGT_CTRL);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001849 if ((temp & MIU_TA_CTL_BUSY) == 0)
1850 break;
1851 }
1852
1853 if (j >= MAX_CTL_CHECK) {
Dhananjay Phadke39754f42009-02-17 20:27:02 -08001854 if (printk_ratelimit())
1855 dev_err(&adapter->pdev->dev,
1856 "failed to write through agent\n");
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001857 ret = -1;
1858 break;
1859 }
1860 }
1861
1862 /*
1863 * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1864 * write_unlock_irqrestore(&adapter->adapter_lock, flags);
1865 */
1866 return ret;
1867}
1868
1869int
1870netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
1871 u64 off, void *data, int size)
1872{
1873 int i, j = 0, k, start, end, loop, sz[2], off0[2];
1874 uint32_t temp;
1875 uint64_t off8, val, mem_crb, word[2] = {0, 0};
1876
1877 /*
1878 * If not MN, go check for MS or invalid.
1879 */
1880
1881 if (off >= NETXEN_ADDR_QDR_NET && off <= NETXEN_ADDR_QDR_NET_MAX_P3)
1882 mem_crb = NETXEN_CRB_QDR_NET;
1883 else {
1884 mem_crb = NETXEN_CRB_DDR_NET;
1885 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1886 return netxen_nic_pci_mem_read_direct(adapter,
1887 off, data, size);
1888 }
1889
1890 off8 = off & 0xfffffff8;
1891 off0[0] = off & 0x7;
1892 off0[1] = 0;
1893 sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]);
1894 sz[1] = size - sz[0];
1895 loop = ((off0[0] + size - 1) >> 3) + 1;
1896
1897 /*
1898 * don't lock here - write_wx gets the lock if each time
1899 * write_lock_irqsave(&adapter->adapter_lock, flags);
1900 * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1901 */
1902
1903 for (i = 0; i < loop; i++) {
1904 temp = off8 + (i << 3);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001905 NXWR32(adapter, mem_crb + MIU_TEST_AGT_ADDR_LO, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001906 temp = 0;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001907 NXWR32(adapter, mem_crb + MIU_TEST_AGT_ADDR_HI, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001908 temp = MIU_TA_CTL_ENABLE;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001909 NXWR32(adapter, mem_crb + MIU_TEST_AGT_CTRL, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001910 temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001911 NXWR32(adapter, mem_crb + MIU_TEST_AGT_CTRL, temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001912
1913 for (j = 0; j < MAX_CTL_CHECK; j++) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001914 temp = NXRD32(adapter, mem_crb + MIU_TEST_AGT_CTRL);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001915 if ((temp & MIU_TA_CTL_BUSY) == 0)
1916 break;
1917 }
1918
1919 if (j >= MAX_CTL_CHECK) {
Dhananjay Phadke39754f42009-02-17 20:27:02 -08001920 if (printk_ratelimit())
1921 dev_err(&adapter->pdev->dev,
1922 "failed to read through agent\n");
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001923 break;
1924 }
1925
1926 start = off0[i] >> 2;
1927 end = (off0[i] + sz[i] - 1) >> 2;
1928 for (k = start; k <= end; k++) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001929 temp = NXRD32(adapter,
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001930 mem_crb + MIU_TEST_AGT_RDDATA(k));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001931 word[i] |= ((uint64_t)temp << (32 * k));
1932 }
1933 }
1934
1935 /*
1936 * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1937 * write_unlock_irqrestore(&adapter->adapter_lock, flags);
1938 */
1939
1940 if (j >= MAX_CTL_CHECK)
1941 return -1;
1942
1943 if (sz[0] == 8) {
1944 val = word[0];
1945 } else {
1946 val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
1947 ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
1948 }
1949
1950 switch (size) {
1951 case 1:
1952 *(uint8_t *)data = val;
1953 break;
1954 case 2:
1955 *(uint16_t *)data = val;
1956 break;
1957 case 4:
1958 *(uint32_t *)data = val;
1959 break;
1960 case 8:
1961 *(uint64_t *)data = val;
1962 break;
1963 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001964 return 0;
1965}
1966
1967/*
1968 * Note : only 32-bit writes!
1969 */
1970int netxen_nic_pci_write_immediate_2M(struct netxen_adapter *adapter,
1971 u64 off, u32 data)
1972{
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001973 NXWR32(adapter, off, data);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001974
1975 return 0;
1976}
1977
1978u32 netxen_nic_pci_read_immediate_2M(struct netxen_adapter *adapter, u64 off)
1979{
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001980 return NXRD32(adapter, off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001981}
1982
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001983int netxen_nic_get_board_info(struct netxen_adapter *adapter)
1984{
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001985 int offset, board_type, magic, header_version;
1986 struct pci_dev *pdev = adapter->pdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001987
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001988 offset = NX_FW_MAGIC_OFFSET;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001989 if (netxen_rom_fast_read(adapter, offset, &magic))
1990 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001991
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001992 offset = NX_HDR_VERSION_OFFSET;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001993 if (netxen_rom_fast_read(adapter, offset, &header_version))
1994 return -EIO;
1995
1996 if (magic != NETXEN_BDINFO_MAGIC ||
1997 header_version != NETXEN_BDINFO_VERSION) {
1998 dev_err(&pdev->dev,
1999 "invalid board config, magic=%08x, version=%08x\n",
2000 magic, header_version);
2001 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002002 }
2003
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00002004 offset = NX_BRDTYPE_OFFSET;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002005 if (netxen_rom_fast_read(adapter, offset, &board_type))
2006 return -EIO;
2007
2008 adapter->ahw.board_type = board_type;
2009
2010 if (board_type == NETXEN_BRDTYPE_P3_4_GB_MM) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002011 u32 gpio = NXRD32(adapter, NETXEN_ROMUSB_GLB_PAD_GPIO_I);
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002012 if ((gpio & 0x8000) == 0)
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002013 board_type = NETXEN_BRDTYPE_P3_10G_TP;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002014 }
2015
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00002016 switch (board_type) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002017 case NETXEN_BRDTYPE_P2_SB35_4G:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002018 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002019 break;
2020 case NETXEN_BRDTYPE_P2_SB31_10G:
2021 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
2022 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
2023 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07002024 case NETXEN_BRDTYPE_P3_HMEZ:
2025 case NETXEN_BRDTYPE_P3_XG_LOM:
2026 case NETXEN_BRDTYPE_P3_10G_CX4:
2027 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
2028 case NETXEN_BRDTYPE_P3_IMEZ:
2029 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
Dhananjay Phadkea70f9392008-08-01 03:14:56 -07002030 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
2031 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07002032 case NETXEN_BRDTYPE_P3_10G_XFP:
2033 case NETXEN_BRDTYPE_P3_10000_BASE_T:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002034 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002035 break;
2036 case NETXEN_BRDTYPE_P1_BD:
2037 case NETXEN_BRDTYPE_P1_SB:
2038 case NETXEN_BRDTYPE_P1_SMAX:
2039 case NETXEN_BRDTYPE_P1_SOCK:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07002040 case NETXEN_BRDTYPE_P3_REF_QG:
2041 case NETXEN_BRDTYPE_P3_4_GB:
2042 case NETXEN_BRDTYPE_P3_4_GB_MM:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002043 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002044 break;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002045 case NETXEN_BRDTYPE_P3_10G_TP:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002046 adapter->ahw.port_type = (adapter->portnum < 2) ?
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002047 NETXEN_NIC_XGBE : NETXEN_NIC_GBE;
2048 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002049 default:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002050 dev_err(&pdev->dev, "unknown board type %x\n", board_type);
2051 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002052 break;
2053 }
2054
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002055 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002056}
2057
2058/* NIU access sections */
2059
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002060int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002061{
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07002062 new_mtu += MTU_FUDGE_FACTOR;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002063 NXWR32(adapter, NETXEN_NIU_GB_MAX_FRAME_SIZE(adapter->physical_port),
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07002064 new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002065 return 0;
2066}
2067
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002068int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002069{
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07002070 new_mtu += MTU_FUDGE_FACTOR;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07002071 if (adapter->physical_port == 0)
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002072 NXWR32(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu);
Jeff Garzik47906542007-11-23 21:23:36 -05002073 else
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002074 NXWR32(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002075 return 0;
2076}
2077
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002078void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002079{
Al Viroa608ab9c2007-01-02 10:39:10 +00002080 __u32 status;
2081 __u32 autoneg;
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002082 __u32 port_mode;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002083
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002084 if (!netif_carrier_ok(adapter->netdev)) {
2085 adapter->link_speed = 0;
2086 adapter->link_duplex = -1;
2087 adapter->link_autoneg = AUTONEG_ENABLE;
2088 return;
2089 }
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002090
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002091 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002092 port_mode = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002093 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
2094 adapter->link_speed = SPEED_1000;
2095 adapter->link_duplex = DUPLEX_FULL;
2096 adapter->link_autoneg = AUTONEG_DISABLE;
2097 return;
2098 }
2099
Amit S. Kale80922fb2006-12-04 09:18:00 -08002100 if (adapter->phy_read
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002101 && adapter->phy_read(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002102 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
2103 &status) == 0) {
2104 if (netxen_get_phy_link(status)) {
2105 switch (netxen_get_phy_speed(status)) {
2106 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002107 adapter->link_speed = SPEED_10;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002108 break;
2109 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002110 adapter->link_speed = SPEED_100;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002111 break;
2112 case 2:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002113 adapter->link_speed = SPEED_1000;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002114 break;
2115 default:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002116 adapter->link_speed = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002117 break;
2118 }
2119 switch (netxen_get_phy_duplex(status)) {
2120 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002121 adapter->link_duplex = DUPLEX_HALF;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002122 break;
2123 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002124 adapter->link_duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002125 break;
2126 default:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002127 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002128 break;
2129 }
Amit S. Kale80922fb2006-12-04 09:18:00 -08002130 if (adapter->phy_read
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002131 && adapter->phy_read(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002132 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08002133 &autoneg) != 0)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002134 adapter->link_autoneg = autoneg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002135 } else
2136 goto link_down;
2137 } else {
2138 link_down:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002139 adapter->link_speed = 0;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002140 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002141 }
2142 }
2143}
2144
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002145void netxen_nic_get_firmware_info(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002146{
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002147 u32 fw_major, fw_minor, fw_build;
Amit S. Kalecb8011a2006-11-29 09:00:10 -08002148 char brd_name[NETXEN_MAX_SHORT_NAME];
Harvey Harrison8d748492008-04-22 11:48:35 -07002149 char serial_num[32];
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00002150 int i, offset, val;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08002151 int *ptr32;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002152 struct pci_dev *pdev = adapter->pdev;
Harvey Harrison8d748492008-04-22 11:48:35 -07002153
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002154 adapter->driver_mismatch = 0;
2155
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08002156 ptr32 = (int *)&serial_num;
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00002157 offset = NX_FW_SERIAL_NUM_OFFSET;
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002158 for (i = 0; i < 8; i++) {
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00002159 if (netxen_rom_fast_read(adapter, offset, &val) == -1) {
Dhananjay Phadkefbb52f22009-03-13 14:52:01 +00002160 dev_err(&pdev->dev, "error reading board info\n");
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002161 adapter->driver_mismatch = 1;
2162 return;
2163 }
Dhananjay Phadkefbb52f22009-03-13 14:52:01 +00002164 ptr32[i] = cpu_to_le32(val);
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00002165 offset += sizeof(u32);
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002166 }
2167
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002168 fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
2169 fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
2170 fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002171
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002172 adapter->fw_version = NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build);
Dhananjay Phadke29566402008-07-21 19:44:04 -07002173
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002174 if (adapter->portnum == 0) {
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002175 get_brd_name_by_type(adapter->ahw.board_type, brd_name);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08002176
Dhananjay Phadke11d89d62008-08-08 00:08:45 -07002177 printk(KERN_INFO "NetXen %s Board S/N %s Chip rev 0x%x\n",
2178 brd_name, serial_num, adapter->ahw.revision_id);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002179 }
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002180
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002181 if (adapter->fw_version < NETXEN_VERSION_CODE(3, 4, 216)) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002182 adapter->driver_mismatch = 1;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002183 dev_warn(&pdev->dev, "firmware version %d.%d.%d unsupported\n",
Dhananjay Phadke58735562008-07-21 19:44:10 -07002184 fw_major, fw_minor, fw_build);
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002185 return;
2186 }
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002187
2188 dev_info(&pdev->dev, "firmware version %d.%d.%d\n",
2189 fw_major, fw_minor, fw_build);
2190
2191 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadked1733462009-06-17 17:27:24 +00002192 i = NXRD32(adapter, NETXEN_SRE_MISC);
2193 adapter->ahw.cut_through = (i & 0x8000) ? 1 : 0;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002194 dev_info(&pdev->dev, "firmware running in %s mode\n",
2195 adapter->ahw.cut_through ? "cut-through" : "legacy");
2196 }
Dhananjay Phadke68b3cae2009-07-26 20:07:36 +00002197
2198 if (adapter->fw_version >= NETXEN_VERSION_CODE(4, 0, 222))
2199 adapter->capabilities = NXRD32(adapter, CRB_FW_CAPABILITIES_1);
Narender Kumar1bb482f2009-08-23 08:35:09 +00002200
2201 adapter->flags &= ~NETXEN_NIC_LRO_ENABLED;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002202}
2203
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002204int
2205netxen_nic_wol_supported(struct netxen_adapter *adapter)
2206{
2207 u32 wol_cfg;
2208
2209 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2210 return 0;
2211
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002212 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002213 if (wol_cfg & (1UL << adapter->portnum)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002214 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002215 if (wol_cfg & (1 << adapter->portnum))
2216 return 1;
2217 }
2218
2219 return 0;
2220}