blob: 52a3798d8d947a9992762dab2987df158b6252bd [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.
Dhananjay Phadke13af7a62009-09-11 11:28:15 +00003 * Copyright (C) 2009 - QLogic Corporation.
Amit S. Kale3d396eb2006-10-21 15:33:03 -04004 * All rights reserved.
Amit S. Kale80922fb2006-12-04 09:18:00 -08005 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -04006 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
Amit S. Kalecb8011a2006-11-29 09:00:10 -080010 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040011 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Amit S. Kalecb8011a2006-11-29 09:00:10 -080015 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040016 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
Amit S. Kale80922fb2006-12-04 09:18:00 -080020 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040021 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.
Amit S. Kale80922fb2006-12-04 09:18:00 -080023 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040024 */
25
26#include "netxen_nic.h"
27#include "netxen_nic_hw.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040028
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030029#include <net/ip.h>
30
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070031#define MASK(n) ((1ULL<<(n))-1)
32#define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff))
33#define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff))
34#define MS_WIN(addr) (addr & 0x0ffc0000)
35
36#define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
37
38#define CRB_BLK(off) ((off >> 20) & 0x3f)
39#define CRB_SUBBLK(off) ((off >> 16) & 0xf)
40#define CRB_WINDOW_2M (0x130060)
41#define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000))
42#define CRB_INDIRECT_2M (0x1e0000UL)
43
Dhananjay Phadkee98e3352009-04-07 22:50:38 +000044#ifndef readq
45static inline u64 readq(void __iomem *addr)
46{
47 return readl(addr) | (((u64) readl(addr + 4)) << 32LL);
48}
49#endif
50
51#ifndef writeq
52static inline void writeq(u64 val, void __iomem *addr)
53{
54 writel(((u32) (val)), (addr));
55 writel(((u32) (val >> 32)), (addr + 4));
56}
57#endif
58
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +000059#define ADDR_IN_RANGE(addr, low, high) \
60 (((addr) < (high)) && ((addr) >= (low)))
61
62#define PCI_OFFSET_FIRST_RANGE(adapter, off) \
63 ((adapter)->ahw.pci_base0 + (off))
64#define PCI_OFFSET_SECOND_RANGE(adapter, off) \
65 ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START)
66#define PCI_OFFSET_THIRD_RANGE(adapter, off) \
67 ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START)
68
69static void __iomem *pci_base_offset(struct netxen_adapter *adapter,
70 unsigned long off)
71{
72 if (ADDR_IN_RANGE(off, FIRST_PAGE_GROUP_START, FIRST_PAGE_GROUP_END))
73 return PCI_OFFSET_FIRST_RANGE(adapter, off);
74
75 if (ADDR_IN_RANGE(off, SECOND_PAGE_GROUP_START, SECOND_PAGE_GROUP_END))
76 return PCI_OFFSET_SECOND_RANGE(adapter, off);
77
78 if (ADDR_IN_RANGE(off, THIRD_PAGE_GROUP_START, THIRD_PAGE_GROUP_END))
79 return PCI_OFFSET_THIRD_RANGE(adapter, off);
80
81 return NULL;
82}
83
Dhananjay Phadkeea7eaa32009-04-07 22:50:48 +000084static crb_128M_2M_block_map_t
85crb_128M_2M_map[64] __cacheline_aligned_in_smp = {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070086 {{{0, 0, 0, 0} } }, /* 0: PCI */
87 {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */
88 {1, 0x0110000, 0x0120000, 0x130000},
89 {1, 0x0120000, 0x0122000, 0x124000},
90 {1, 0x0130000, 0x0132000, 0x126000},
91 {1, 0x0140000, 0x0142000, 0x128000},
92 {1, 0x0150000, 0x0152000, 0x12a000},
93 {1, 0x0160000, 0x0170000, 0x110000},
94 {1, 0x0170000, 0x0172000, 0x12e000},
95 {0, 0x0000000, 0x0000000, 0x000000},
96 {0, 0x0000000, 0x0000000, 0x000000},
97 {0, 0x0000000, 0x0000000, 0x000000},
98 {0, 0x0000000, 0x0000000, 0x000000},
99 {0, 0x0000000, 0x0000000, 0x000000},
100 {0, 0x0000000, 0x0000000, 0x000000},
101 {1, 0x01e0000, 0x01e0800, 0x122000},
102 {0, 0x0000000, 0x0000000, 0x000000} } },
103 {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */
104 {{{0, 0, 0, 0} } }, /* 3: */
105 {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */
106 {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */
107 {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */
108 {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */
109 {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */
110 {0, 0x0000000, 0x0000000, 0x000000},
111 {0, 0x0000000, 0x0000000, 0x000000},
112 {0, 0x0000000, 0x0000000, 0x000000},
113 {0, 0x0000000, 0x0000000, 0x000000},
114 {0, 0x0000000, 0x0000000, 0x000000},
115 {0, 0x0000000, 0x0000000, 0x000000},
116 {0, 0x0000000, 0x0000000, 0x000000},
117 {0, 0x0000000, 0x0000000, 0x000000},
118 {0, 0x0000000, 0x0000000, 0x000000},
119 {0, 0x0000000, 0x0000000, 0x000000},
120 {0, 0x0000000, 0x0000000, 0x000000},
121 {0, 0x0000000, 0x0000000, 0x000000},
122 {0, 0x0000000, 0x0000000, 0x000000},
123 {0, 0x0000000, 0x0000000, 0x000000},
124 {1, 0x08f0000, 0x08f2000, 0x172000} } },
125 {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/
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 {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 {1, 0x09f0000, 0x09f2000, 0x176000} } },
141 {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/
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 {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 {1, 0x0af0000, 0x0af2000, 0x17a000} } },
157 {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/
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 {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 {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
173 {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */
174 {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */
175 {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */
176 {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */
177 {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */
178 {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */
179 {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */
180 {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */
181 {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */
182 {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */
183 {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */
184 {{{0, 0, 0, 0} } }, /* 23: */
185 {{{0, 0, 0, 0} } }, /* 24: */
186 {{{0, 0, 0, 0} } }, /* 25: */
187 {{{0, 0, 0, 0} } }, /* 26: */
188 {{{0, 0, 0, 0} } }, /* 27: */
189 {{{0, 0, 0, 0} } }, /* 28: */
190 {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */
191 {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */
192 {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */
193 {{{0} } }, /* 32: PCI */
194 {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */
195 {1, 0x2110000, 0x2120000, 0x130000},
196 {1, 0x2120000, 0x2122000, 0x124000},
197 {1, 0x2130000, 0x2132000, 0x126000},
198 {1, 0x2140000, 0x2142000, 0x128000},
199 {1, 0x2150000, 0x2152000, 0x12a000},
200 {1, 0x2160000, 0x2170000, 0x110000},
201 {1, 0x2170000, 0x2172000, 0x12e000},
202 {0, 0x0000000, 0x0000000, 0x000000},
203 {0, 0x0000000, 0x0000000, 0x000000},
204 {0, 0x0000000, 0x0000000, 0x000000},
205 {0, 0x0000000, 0x0000000, 0x000000},
206 {0, 0x0000000, 0x0000000, 0x000000},
207 {0, 0x0000000, 0x0000000, 0x000000},
208 {0, 0x0000000, 0x0000000, 0x000000},
209 {0, 0x0000000, 0x0000000, 0x000000} } },
210 {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */
211 {{{0} } }, /* 35: */
212 {{{0} } }, /* 36: */
213 {{{0} } }, /* 37: */
214 {{{0} } }, /* 38: */
215 {{{0} } }, /* 39: */
216 {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */
217 {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */
218 {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */
219 {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */
220 {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */
221 {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */
222 {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */
223 {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */
224 {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */
225 {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */
226 {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */
227 {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */
228 {{{0} } }, /* 52: */
229 {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */
230 {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */
231 {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */
232 {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */
233 {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */
234 {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */
235 {{{0} } }, /* 59: I2C0 */
236 {{{0} } }, /* 60: I2C1 */
237 {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */
238 {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */
239 {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */
240};
241
242/*
243 * top 12 bits of crb internal address (hub, agent)
244 */
245static unsigned crb_hub_agt[64] =
246{
247 0,
248 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
249 NETXEN_HW_CRB_HUB_AGT_ADR_MN,
250 NETXEN_HW_CRB_HUB_AGT_ADR_MS,
251 0,
252 NETXEN_HW_CRB_HUB_AGT_ADR_SRE,
253 NETXEN_HW_CRB_HUB_AGT_ADR_NIU,
254 NETXEN_HW_CRB_HUB_AGT_ADR_QMN,
255 NETXEN_HW_CRB_HUB_AGT_ADR_SQN0,
256 NETXEN_HW_CRB_HUB_AGT_ADR_SQN1,
257 NETXEN_HW_CRB_HUB_AGT_ADR_SQN2,
258 NETXEN_HW_CRB_HUB_AGT_ADR_SQN3,
259 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
260 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
261 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
262 NETXEN_HW_CRB_HUB_AGT_ADR_PGN4,
263 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
264 NETXEN_HW_CRB_HUB_AGT_ADR_PGN0,
265 NETXEN_HW_CRB_HUB_AGT_ADR_PGN1,
266 NETXEN_HW_CRB_HUB_AGT_ADR_PGN2,
267 NETXEN_HW_CRB_HUB_AGT_ADR_PGN3,
268 NETXEN_HW_CRB_HUB_AGT_ADR_PGND,
269 NETXEN_HW_CRB_HUB_AGT_ADR_PGNI,
270 NETXEN_HW_CRB_HUB_AGT_ADR_PGS0,
271 NETXEN_HW_CRB_HUB_AGT_ADR_PGS1,
272 NETXEN_HW_CRB_HUB_AGT_ADR_PGS2,
273 NETXEN_HW_CRB_HUB_AGT_ADR_PGS3,
274 0,
275 NETXEN_HW_CRB_HUB_AGT_ADR_PGSI,
276 NETXEN_HW_CRB_HUB_AGT_ADR_SN,
277 0,
278 NETXEN_HW_CRB_HUB_AGT_ADR_EG,
279 0,
280 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
281 NETXEN_HW_CRB_HUB_AGT_ADR_CAM,
282 0,
283 0,
284 0,
285 0,
286 0,
287 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
288 0,
289 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1,
290 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2,
291 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3,
292 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4,
293 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5,
294 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6,
295 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7,
296 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
297 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
298 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
299 0,
300 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0,
301 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8,
302 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9,
303 NETXEN_HW_CRB_HUB_AGT_ADR_OCM0,
304 0,
305 NETXEN_HW_CRB_HUB_AGT_ADR_SMB,
306 NETXEN_HW_CRB_HUB_AGT_ADR_I2C0,
307 NETXEN_HW_CRB_HUB_AGT_ADR_I2C1,
308 0,
309 NETXEN_HW_CRB_HUB_AGT_ADR_PGNC,
310 0,
311};
312
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400313/* PCI Windowing for DDR regions. */
314
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700315#define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400316
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000317#define NETXEN_PCIE_SEM_TIMEOUT 10000
318
319int
320netxen_pcie_sem_lock(struct netxen_adapter *adapter, int sem, u32 id_reg)
321{
322 int done = 0, timeout = 0;
323
324 while (!done) {
325 done = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_LOCK(sem)));
326 if (done == 1)
327 break;
328 if (++timeout >= NETXEN_PCIE_SEM_TIMEOUT)
329 return -1;
330 msleep(1);
331 }
332
333 if (id_reg)
334 NXWR32(adapter, id_reg, adapter->portnum);
335
336 return 0;
337}
338
339void
340netxen_pcie_sem_unlock(struct netxen_adapter *adapter, int sem)
341{
342 int val;
343 val = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_UNLOCK(sem)));
344}
345
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000346int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port)
347{
348 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
349 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_1+(0x10000*port), 0x1447);
350 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0+(0x10000*port), 0x5);
351 }
352
353 return 0;
354}
355
356/* Disable an XG interface */
357int netxen_niu_disable_xg_port(struct netxen_adapter *adapter)
358{
359 __u32 mac_cfg;
360 u32 port = adapter->physical_port;
361
362 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
363 return 0;
364
365 if (port > NETXEN_NIU_MAX_XG_PORTS)
366 return -EINVAL;
367
368 mac_cfg = 0;
369 if (NXWR32(adapter,
370 NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg))
371 return -EIO;
372 return 0;
373}
374
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700375#define NETXEN_UNICAST_ADDR(port, index) \
376 (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8))
377#define NETXEN_MCAST_ADDR(port, index) \
378 (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8))
379#define MAC_HI(addr) \
380 ((addr[2] << 16) | (addr[1] << 8) | (addr[0]))
381#define MAC_LO(addr) \
382 ((addr[5] << 16) | (addr[4] << 8) | (addr[3]))
383
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000384int netxen_p2_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
385{
Narender Kumara7483b02009-11-20 15:09:33 +0000386 u32 mac_cfg;
387 u32 cnt = 0;
388 __u32 reg = 0x0200;
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000389 u32 port = adapter->physical_port;
Narender Kumara7483b02009-11-20 15:09:33 +0000390 u16 board_type = adapter->ahw.board_type;
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000391
392 if (port > NETXEN_NIU_MAX_XG_PORTS)
393 return -EINVAL;
394
Narender Kumara7483b02009-11-20 15:09:33 +0000395 mac_cfg = NXRD32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port));
396 mac_cfg &= ~0x4;
397 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg);
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000398
Narender Kumara7483b02009-11-20 15:09:33 +0000399 if ((board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) ||
400 (board_type == NETXEN_BRDTYPE_P2_SB31_10G_HMEZ))
401 reg = (0x20 << port);
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000402
Narender Kumara7483b02009-11-20 15:09:33 +0000403 NXWR32(adapter, NETXEN_NIU_FRAME_COUNT_SELECT, reg);
404
405 mdelay(10);
406
407 while (NXRD32(adapter, NETXEN_NIU_FRAME_COUNT) && ++cnt < 20)
408 mdelay(10);
409
410 if (cnt < 20) {
411
412 reg = NXRD32(adapter,
413 NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port));
414
415 if (mode == NETXEN_NIU_PROMISC_MODE)
416 reg = (reg | 0x2000UL);
417 else
418 reg = (reg & ~0x2000UL);
419
420 if (mode == NETXEN_NIU_ALLMULTI_MODE)
421 reg = (reg | 0x1000UL);
422 else
423 reg = (reg & ~0x1000UL);
424
425 NXWR32(adapter,
426 NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), reg);
427 }
428
429 mac_cfg |= 0x4;
430 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg);
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000431
432 return 0;
433}
434
435int netxen_p2_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr)
436{
437 u32 mac_hi, mac_lo;
438 u32 reg_hi, reg_lo;
439
440 u8 phy = adapter->physical_port;
441
442 if (phy >= NETXEN_NIU_MAX_XG_PORTS)
443 return -EINVAL;
444
445 mac_lo = ((u32)addr[0] << 16) | ((u32)addr[1] << 24);
446 mac_hi = addr[2] | ((u32)addr[3] << 8) |
447 ((u32)addr[4] << 16) | ((u32)addr[5] << 24);
448
449 reg_lo = NETXEN_NIU_XGE_STATION_ADDR_0_1 + (0x10000 * phy);
450 reg_hi = NETXEN_NIU_XGE_STATION_ADDR_0_HI + (0x10000 * phy);
451
452 /* write twice to flush */
453 if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi))
454 return -EIO;
455 if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi))
456 return -EIO;
457
458 return 0;
459}
460
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700461static int
462netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter)
463{
464 u32 val = 0;
465 u16 port = adapter->physical_port;
Narender Kumar5d09e532009-11-20 22:08:57 +0000466 u8 *addr = adapter->mac_addr;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700467
468 if (adapter->mc_enabled)
469 return 0;
470
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000471 val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700472 val |= (1UL << (28+port));
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000473 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700474
475 /* add broadcast addr to filter */
476 val = 0xffffff;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000477 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
478 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700479
480 /* add station addr to filter */
481 val = MAC_HI(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000482 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700483 val = MAC_LO(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000484 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700485
486 adapter->mc_enabled = 1;
487 return 0;
488}
489
490static int
491netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter)
492{
493 u32 val = 0;
494 u16 port = adapter->physical_port;
Narender Kumar5d09e532009-11-20 22:08:57 +0000495 u8 *addr = adapter->mac_addr;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700496
497 if (!adapter->mc_enabled)
498 return 0;
499
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000500 val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700501 val &= ~(1UL << (28+port));
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000502 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700503
504 val = MAC_HI(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000505 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700506 val = MAC_LO(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000507 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700508
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000509 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), 0);
510 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700511
512 adapter->mc_enabled = 0;
513 return 0;
514}
515
516static int
517netxen_nic_set_mcast_addr(struct netxen_adapter *adapter,
518 int index, u8 *addr)
519{
520 u32 hi = 0, lo = 0;
521 u16 port = adapter->physical_port;
522
523 lo = MAC_LO(addr);
524 hi = MAC_HI(addr);
525
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000526 NXWR32(adapter, NETXEN_MCAST_ADDR(port, index), hi);
527 NXWR32(adapter, NETXEN_MCAST_ADDR(port, index)+4, lo);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700528
529 return 0;
530}
531
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700532void netxen_p2_nic_set_multi(struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400533{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700534 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400535 struct dev_mc_list *mc_ptr;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700536 u8 null_addr[6];
537 int index = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400538
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700539 memset(null_addr, 0, 6);
540
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400541 if (netdev->flags & IFF_PROMISC) {
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700542
543 adapter->set_promisc(adapter,
544 NETXEN_NIU_PROMISC_MODE);
545
546 /* Full promiscuous mode */
547 netxen_nic_disable_mcast_filter(adapter);
548
549 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400550 }
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700551
552 if (netdev->mc_count == 0) {
553 adapter->set_promisc(adapter,
554 NETXEN_NIU_NON_PROMISC_MODE);
555 netxen_nic_disable_mcast_filter(adapter);
556 return;
557 }
558
559 adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE);
560 if (netdev->flags & IFF_ALLMULTI ||
561 netdev->mc_count > adapter->max_mc_count) {
562 netxen_nic_disable_mcast_filter(adapter);
563 return;
564 }
565
566 netxen_nic_enable_mcast_filter(adapter);
567
568 for (mc_ptr = netdev->mc_list; mc_ptr; mc_ptr = mc_ptr->next, index++)
569 netxen_nic_set_mcast_addr(adapter, index, mc_ptr->dmi_addr);
570
571 if (index != netdev->mc_count)
572 printk(KERN_WARNING "%s: %s multicast address count mismatch\n",
573 netxen_nic_driver_name, netdev->name);
574
575 /* Clear out remaining addresses */
576 for (; index < adapter->max_mc_count; index++)
577 netxen_nic_set_mcast_addr(adapter, index, null_addr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400578}
579
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700580static int
581netxen_send_cmd_descs(struct netxen_adapter *adapter,
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000582 struct cmd_desc_type0 *cmd_desc_arr, int nr_desc)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700583{
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000584 u32 i, producer, consumer;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700585 struct netxen_cmd_buffer *pbuf;
586 struct cmd_desc_type0 *cmd_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000587 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700588
589 i = 0;
590
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000591 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
592 return -EIO;
593
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000594 tx_ring = adapter->tx_ring;
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000595 __netif_tx_lock_bh(tx_ring->txq);
Dhananjay Phadke03e678e2009-01-14 20:49:43 -0800596
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000597 producer = tx_ring->producer;
598 consumer = tx_ring->sw_consumer;
599
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000600 if (nr_desc >= netxen_tx_avail(tx_ring)) {
601 netif_tx_stop_queue(tx_ring->txq);
602 __netif_tx_unlock_bh(tx_ring->txq);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000603 return -EBUSY;
604 }
605
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700606 do {
607 cmd_desc = &cmd_desc_arr[i];
608
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000609 pbuf = &tx_ring->cmd_buf_arr[producer];
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700610 pbuf->skb = NULL;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700611 pbuf->frag_count = 0;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700612
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000613 memcpy(&tx_ring->desc_head[producer],
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700614 &cmd_desc_arr[i], sizeof(struct cmd_desc_type0));
615
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000616 producer = get_next_index(producer, tx_ring->num_desc);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700617 i++;
618
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000619 } while (i != nr_desc);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700620
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000621 tx_ring->producer = producer;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700622
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000623 netxen_nic_update_cmd_producer(adapter, tx_ring);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700624
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000625 __netif_tx_unlock_bh(tx_ring->txq);
Dhananjay Phadke03e678e2009-01-14 20:49:43 -0800626
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700627 return 0;
628}
629
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000630static int
631nx_p3_sre_macaddr_change(struct netxen_adapter *adapter, u8 *addr, unsigned op)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700632{
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700633 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800634 nx_mac_req_t *mac_req;
635 u64 word;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700636
637 memset(&req, 0, sizeof(nx_nic_req_t));
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800638 req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23);
639
640 word = NX_MAC_EVENT | ((u64)adapter->portnum << 16);
641 req.req_hdr = cpu_to_le64(word);
642
643 mac_req = (nx_mac_req_t *)&req.words[0];
644 mac_req->op = op;
645 memcpy(mac_req->mac_addr, addr, 6);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700646
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000647 return netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
648}
649
650static int nx_p3_nic_add_mac(struct netxen_adapter *adapter,
651 u8 *addr, struct list_head *del_list)
652{
653 struct list_head *head;
654 nx_mac_list_t *cur;
655
656 /* look up if already exists */
657 list_for_each(head, del_list) {
658 cur = list_entry(head, nx_mac_list_t, list);
659
660 if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) {
661 list_move_tail(head, &adapter->mac_list);
662 return 0;
663 }
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700664 }
665
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000666 cur = kzalloc(sizeof(nx_mac_list_t), GFP_ATOMIC);
667 if (cur == NULL) {
668 printk(KERN_ERR "%s: failed to add mac address filter\n",
669 adapter->netdev->name);
670 return -ENOMEM;
671 }
672 memcpy(cur->mac_addr, addr, ETH_ALEN);
673 list_add_tail(&cur->list, &adapter->mac_list);
674 return nx_p3_sre_macaddr_change(adapter,
675 cur->mac_addr, NETXEN_MAC_ADD);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700676}
677
678void netxen_p3_nic_set_multi(struct net_device *netdev)
679{
680 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700681 struct dev_mc_list *mc_ptr;
682 u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700683 u32 mode = VPORT_MISS_MODE_DROP;
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000684 LIST_HEAD(del_list);
685 struct list_head *head;
686 nx_mac_list_t *cur;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700687
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000688 list_splice_tail_init(&adapter->mac_list, &del_list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700689
Narender Kumar5d09e532009-11-20 22:08:57 +0000690 nx_p3_nic_add_mac(adapter, adapter->mac_addr, &del_list);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000691 nx_p3_nic_add_mac(adapter, bcast_addr, &del_list);
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700692
693 if (netdev->flags & IFF_PROMISC) {
694 mode = VPORT_MISS_MODE_ACCEPT_ALL;
695 goto send_fw_cmd;
696 }
697
698 if ((netdev->flags & IFF_ALLMULTI) ||
699 (netdev->mc_count > adapter->max_mc_count)) {
700 mode = VPORT_MISS_MODE_ACCEPT_MULTI;
701 goto send_fw_cmd;
702 }
703
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700704 if (netdev->mc_count > 0) {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700705 for (mc_ptr = netdev->mc_list; mc_ptr;
706 mc_ptr = mc_ptr->next) {
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000707 nx_p3_nic_add_mac(adapter, mc_ptr->dmi_addr, &del_list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700708 }
709 }
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700710
711send_fw_cmd:
712 adapter->set_promisc(adapter, mode);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000713 head = &del_list;
714 while (!list_empty(head)) {
715 cur = list_entry(head->next, nx_mac_list_t, list);
716
717 nx_p3_sre_macaddr_change(adapter,
718 cur->mac_addr, NETXEN_MAC_DEL);
719 list_del(&cur->list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700720 kfree(cur);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700721 }
722}
723
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700724int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
725{
726 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800727 u64 word;
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700728
729 memset(&req, 0, sizeof(nx_nic_req_t));
730
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800731 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
732
733 word = NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE |
734 ((u64)adapter->portnum << 16);
735 req.req_hdr = cpu_to_le64(word);
736
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700737 req.words[0] = cpu_to_le64(mode);
738
739 return netxen_send_cmd_descs(adapter,
740 (struct cmd_desc_type0 *)&req, 1);
741}
742
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800743void netxen_p3_free_mac_list(struct netxen_adapter *adapter)
744{
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000745 nx_mac_list_t *cur;
746 struct list_head *head = &adapter->mac_list;
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800747
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000748 while (!list_empty(head)) {
749 cur = list_entry(head->next, nx_mac_list_t, list);
750 nx_p3_sre_macaddr_change(adapter,
751 cur->mac_addr, NETXEN_MAC_DEL);
752 list_del(&cur->list);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800753 kfree(cur);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800754 }
755}
756
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000757int netxen_p3_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr)
758{
759 /* assuming caller has already copied new addr to netdev */
760 netxen_p3_nic_set_multi(adapter->netdev);
761 return 0;
762}
763
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700764#define NETXEN_CONFIG_INTR_COALESCE 3
765
766/*
767 * Send the interrupt coalescing parameter set by ethtool to the card.
768 */
769int netxen_config_intr_coalesce(struct netxen_adapter *adapter)
770{
771 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800772 u64 word;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700773 int rv;
774
775 memset(&req, 0, sizeof(nx_nic_req_t));
776
Narender Kumar1bb482f2009-08-23 08:35:09 +0000777 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800778
779 word = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16);
780 req.req_hdr = cpu_to_le64(word);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700781
782 memcpy(&req.words[0], &adapter->coal, sizeof(adapter->coal));
783
784 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
785 if (rv != 0) {
786 printk(KERN_ERR "ERROR. Could not send "
787 "interrupt coalescing parameters\n");
788 }
789
790 return rv;
791}
792
Narender Kumar1bb482f2009-08-23 08:35:09 +0000793int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable)
794{
795 nx_nic_req_t req;
796 u64 word;
797 int rv = 0;
798
799 if ((adapter->flags & NETXEN_NIC_LRO_ENABLED) == enable)
800 return 0;
801
802 memset(&req, 0, sizeof(nx_nic_req_t));
803
804 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
805
806 word = NX_NIC_H2C_OPCODE_CONFIG_HW_LRO | ((u64)adapter->portnum << 16);
807 req.req_hdr = cpu_to_le64(word);
808
809 req.words[0] = cpu_to_le64(enable);
810
811 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
812 if (rv != 0) {
813 printk(KERN_ERR "ERROR. Could not send "
814 "configure hw lro request\n");
815 }
816
817 adapter->flags ^= NETXEN_NIC_LRO_ENABLED;
818
819 return rv;
820}
821
Narender Kumarfa3ce352009-08-24 19:23:28 +0000822int netxen_config_bridged_mode(struct netxen_adapter *adapter, int enable)
823{
824 nx_nic_req_t req;
825 u64 word;
826 int rv = 0;
827
828 if (!!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED) == enable)
829 return rv;
830
831 memset(&req, 0, sizeof(nx_nic_req_t));
832
833 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
834
835 word = NX_NIC_H2C_OPCODE_CONFIG_BRIDGING |
836 ((u64)adapter->portnum << 16);
837 req.req_hdr = cpu_to_le64(word);
838
839 req.words[0] = cpu_to_le64(enable);
840
841 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
842 if (rv != 0) {
843 printk(KERN_ERR "ERROR. Could not send "
844 "configure bridge mode request\n");
845 }
846
847 adapter->flags ^= NETXEN_NIC_BRIDGE_ENABLED;
848
849 return rv;
850}
851
852
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000853#define RSS_HASHTYPE_IP_TCP 0x3
854
855int netxen_config_rss(struct netxen_adapter *adapter, int enable)
856{
857 nx_nic_req_t req;
858 u64 word;
859 int i, rv;
860
861 u64 key[] = { 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL,
862 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
863 0x255b0ec26d5a56daULL };
864
865
866 memset(&req, 0, sizeof(nx_nic_req_t));
867 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
868
869 word = NX_NIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16);
870 req.req_hdr = cpu_to_le64(word);
871
872 /*
873 * RSS request:
874 * bits 3-0: hash_method
875 * 5-4: hash_type_ipv4
876 * 7-6: hash_type_ipv6
877 * 8: enable
878 * 9: use indirection table
879 * 47-10: reserved
880 * 63-48: indirection table mask
881 */
882 word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) |
883 ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) |
884 ((u64)(enable & 0x1) << 8) |
885 ((0x7ULL) << 48);
886 req.words[0] = cpu_to_le64(word);
887 for (i = 0; i < 5; i++)
888 req.words[i+1] = cpu_to_le64(key[i]);
889
890
891 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
892 if (rv != 0) {
893 printk(KERN_ERR "%s: could not configure RSS\n",
894 adapter->netdev->name);
895 }
896
897 return rv;
898}
899
Dhananjay Phadke6598b162009-07-26 20:07:37 +0000900int netxen_config_ipaddr(struct netxen_adapter *adapter, u32 ip, int cmd)
901{
902 nx_nic_req_t req;
903 u64 word;
904 int rv;
905
906 memset(&req, 0, sizeof(nx_nic_req_t));
907 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
908
909 word = NX_NIC_H2C_OPCODE_CONFIG_IPADDR | ((u64)adapter->portnum << 16);
910 req.req_hdr = cpu_to_le64(word);
911
912 req.words[0] = cpu_to_le64(cmd);
913 req.words[1] = cpu_to_le64(ip);
914
915 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
916 if (rv != 0) {
917 printk(KERN_ERR "%s: could not notify %s IP 0x%x reuqest\n",
918 adapter->netdev->name,
919 (cmd == NX_IP_UP) ? "Add" : "Remove", ip);
920 }
921 return rv;
922}
923
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000924int netxen_linkevent_request(struct netxen_adapter *adapter, int enable)
925{
926 nx_nic_req_t req;
927 u64 word;
928 int rv;
929
930 memset(&req, 0, sizeof(nx_nic_req_t));
931 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
932
933 word = NX_NIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16);
934 req.req_hdr = cpu_to_le64(word);
Dhananjay Phadke22527862009-05-05 19:05:06 +0000935 req.words[0] = cpu_to_le64(enable | (enable << 8));
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000936
937 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
938 if (rv != 0) {
939 printk(KERN_ERR "%s: could not configure link notification\n",
940 adapter->netdev->name);
941 }
942
943 return rv;
944}
945
Narender Kumar1bb482f2009-08-23 08:35:09 +0000946int netxen_send_lro_cleanup(struct netxen_adapter *adapter)
947{
948 nx_nic_req_t req;
949 u64 word;
950 int rv;
951
952 memset(&req, 0, sizeof(nx_nic_req_t));
953 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
954
955 word = NX_NIC_H2C_OPCODE_LRO_REQUEST |
956 ((u64)adapter->portnum << 16) |
957 ((u64)NX_NIC_LRO_REQUEST_CLEANUP << 56) ;
958
959 req.req_hdr = cpu_to_le64(word);
960
961 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
962 if (rv != 0) {
963 printk(KERN_ERR "%s: could not cleanup lro flows\n",
964 adapter->netdev->name);
965 }
966 return rv;
967}
968
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400969/*
970 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
971 * @returns 0 on success, negative on failure
972 */
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700973
974#define MTU_FUDGE_FACTOR 100
975
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400976int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
977{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700978 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700979 int max_mtu;
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700980 int rc = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400981
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700982 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
983 max_mtu = P3_MAX_MTU;
984 else
985 max_mtu = P2_MAX_MTU;
986
987 if (mtu > max_mtu) {
988 printk(KERN_ERR "%s: mtu > %d bytes unsupported\n",
989 netdev->name, max_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400990 return -EINVAL;
991 }
992
Amit S. Kale80922fb2006-12-04 09:18:00 -0800993 if (adapter->set_mtu)
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700994 rc = adapter->set_mtu(adapter, mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400995
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700996 if (!rc)
997 netdev->mtu = mtu;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700998
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700999 return rc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001000}
1001
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001002static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
Al Virof305f782007-12-22 19:44:00 +00001003 int size, __le32 * buf)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001004{
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001005 int i, v, addr;
Al Virof305f782007-12-22 19:44:00 +00001006 __le32 *ptr32;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001007
1008 addr = base;
1009 ptr32 = buf;
1010 for (i = 0; i < size / sizeof(u32); i++) {
Al Virof305f782007-12-22 19:44:00 +00001011 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001012 return -1;
Al Virof305f782007-12-22 19:44:00 +00001013 *ptr32 = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001014 ptr32++;
1015 addr += sizeof(u32);
1016 }
1017 if ((char *)buf + size > (char *)ptr32) {
Al Virof305f782007-12-22 19:44:00 +00001018 __le32 local;
1019 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001020 return -1;
Al Virof305f782007-12-22 19:44:00 +00001021 local = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001022 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
1023 }
1024
1025 return 0;
1026}
1027
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001028int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 *mac)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001029{
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001030 __le32 *pmac = (__le32 *) mac;
1031 u32 offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001032
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001033 offset = NX_FW_MAC_ADDR_OFFSET + (adapter->portnum * sizeof(u64));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001034
1035 if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001036 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001037
Al Virof305f782007-12-22 19:44:00 +00001038 if (*mac == cpu_to_le64(~0ULL)) {
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001039
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001040 offset = NX_OLD_MAC_ADDR_OFFSET +
1041 (adapter->portnum * sizeof(u64));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001042
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001043 if (netxen_get_flash_block(adapter,
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001044 offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001045 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001046
Al Virof305f782007-12-22 19:44:00 +00001047 if (*mac == cpu_to_le64(~0ULL))
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001048 return -1;
1049 }
1050 return 0;
1051}
1052
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001053int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, __le64 *mac)
1054{
1055 uint32_t crbaddr, mac_hi, mac_lo;
1056 int pci_func = adapter->ahw.pci_func;
1057
1058 crbaddr = CRB_MAC_BLOCK_START +
1059 (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1));
1060
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001061 mac_lo = NXRD32(adapter, crbaddr);
1062 mac_hi = NXRD32(adapter, crbaddr+4);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001063
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001064 if (pci_func & 1)
Dhananjay Phadke2edbb452009-01-14 20:47:30 -08001065 *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001066 else
Dhananjay Phadke2edbb452009-01-14 20:47:30 -08001067 *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001068
1069 return 0;
1070}
1071
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001072/*
1073 * Changes the CRB window to the specified window.
1074 */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001075static void
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001076netxen_nic_pci_change_crbwindow_128M(struct netxen_adapter *adapter, u32 wndw)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001077{
1078 void __iomem *offset;
1079 u32 tmp;
1080 int count = 0;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001081 uint8_t func = adapter->ahw.pci_func;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001082
1083 if (adapter->curr_window == wndw)
1084 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001085 /*
1086 * Move the CRB window.
1087 * We need to write to the "direct access" region of PCI
1088 * to avoid a race condition where the window register has
1089 * not been successfully written across CRB before the target
1090 * register address is received by PCI. The direct region bypasses
1091 * the CRB bus.
1092 */
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001093 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1094 NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001095
1096 if (wndw & 0x1)
1097 wndw = NETXEN_WINDOW_ONE;
1098
1099 writel(wndw, offset);
1100
1101 /* MUST make sure window is set before we forge on... */
1102 while ((tmp = readl(offset)) != wndw) {
1103 printk(KERN_WARNING "%s: %s WARNING: CRB window value not "
1104 "registered properly: 0x%08x.\n",
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001105 netxen_nic_driver_name, __func__, tmp);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001106 mdelay(1);
1107 if (count >= 10)
1108 break;
1109 count++;
1110 }
1111
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001112 if (wndw == NETXEN_WINDOW_ONE)
1113 adapter->curr_window = 1;
1114 else
1115 adapter->curr_window = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001116}
1117
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001118/*
1119 * Return -1 if off is not valid,
1120 * 1 if window access is needed. 'off' is set to offset from
1121 * CRB space in 128M pci map
1122 * 0 if no window access is needed. 'off' is set to 2M addr
1123 * In: 'off' is offset from base in 128M pci map
1124 */
1125static int
Dhananjay Phadke23b6cc42009-05-08 22:02:30 +00001126netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, ulong *off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001127{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001128 crb_128M_2M_sub_block_map_t *m;
1129
1130
1131 if (*off >= NETXEN_CRB_MAX)
1132 return -1;
1133
Dhananjay Phadke23b6cc42009-05-08 22:02:30 +00001134 if (*off >= NETXEN_PCI_CAMQM && (*off < NETXEN_PCI_CAMQM_2M_END)) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001135 *off = (*off - NETXEN_PCI_CAMQM) + NETXEN_PCI_CAMQM_2M_BASE +
1136 (ulong)adapter->ahw.pci_base0;
1137 return 0;
1138 }
1139
1140 if (*off < NETXEN_PCI_CRBSPACE)
1141 return -1;
1142
1143 *off -= NETXEN_PCI_CRBSPACE;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001144
1145 /*
1146 * Try direct map
1147 */
1148 m = &crb_128M_2M_map[CRB_BLK(*off)].sub_block[CRB_SUBBLK(*off)];
1149
Dhananjay Phadke23b6cc42009-05-08 22:02:30 +00001150 if (m->valid && (m->start_128M <= *off) && (m->end_128M > *off)) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001151 *off = *off + m->start_2M - m->start_128M +
1152 (ulong)adapter->ahw.pci_base0;
1153 return 0;
1154 }
1155
1156 /*
1157 * Not in direct map, use crb window
1158 */
1159 return 1;
1160}
1161
1162/*
1163 * In: 'off' is offset from CRB space in 128M pci map
1164 * Out: 'off' is 2M pci map addr
1165 * side effect: lock crb window
1166 */
1167static void
1168netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong *off)
1169{
1170 u32 win_read;
1171
1172 adapter->crb_win = CRB_HI(*off);
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001173 writel(adapter->crb_win, (adapter->ahw.pci_base0 + CRB_WINDOW_2M));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001174 /*
1175 * Read back value to make sure write has gone through before trying
1176 * to use it.
1177 */
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001178 win_read = readl(adapter->ahw.pci_base0 + CRB_WINDOW_2M);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001179 if (win_read != adapter->crb_win) {
1180 printk(KERN_ERR "%s: Written crbwin (0x%x) != "
1181 "Read crbwin (0x%x), off=0x%lx\n",
1182 __func__, adapter->crb_win, win_read, *off);
1183 }
1184 *off = (*off & MASK(16)) + CRB_INDIRECT_2M +
1185 (ulong)adapter->ahw.pci_base0;
1186}
1187
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001188static int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001189netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001190{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001191 unsigned long flags;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001192 void __iomem *addr;
1193
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001194 if (ADDR_IN_WINDOW1(off))
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001195 addr = NETXEN_CRB_NORMALIZE(adapter, off);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001196 else
1197 addr = pci_base_offset(adapter, off);
1198
1199 BUG_ON(!addr);
1200
1201 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
1202 read_lock(&adapter->adapter_lock);
1203 writel(data, addr);
1204 read_unlock(&adapter->adapter_lock);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001205 } else { /* Window 0 */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001206 write_lock_irqsave(&adapter->adapter_lock, flags);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001207 addr = pci_base_offset(adapter, off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001208 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001209 writel(data, addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001210 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001211 write_unlock_irqrestore(&adapter->adapter_lock, flags);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001212 }
1213
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001214 return 0;
1215}
1216
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001217static u32
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001218netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001219{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001220 unsigned long flags;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001221 void __iomem *addr;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001222 u32 data;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001223
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001224 if (ADDR_IN_WINDOW1(off))
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001225 addr = NETXEN_CRB_NORMALIZE(adapter, off);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001226 else
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001227 addr = pci_base_offset(adapter, off);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001228
1229 BUG_ON(!addr);
1230
1231 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
1232 read_lock(&adapter->adapter_lock);
1233 data = readl(addr);
1234 read_unlock(&adapter->adapter_lock);
1235 } else { /* Window 0 */
1236 write_lock_irqsave(&adapter->adapter_lock, flags);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001237 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001238 data = readl(addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001239 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001240 write_unlock_irqrestore(&adapter->adapter_lock, flags);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001241 }
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001242
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001243 return data;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001244}
1245
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001246static int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001247netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001248{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001249 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001250 int rv;
1251
Dhananjay Phadke23b6cc42009-05-08 22:02:30 +00001252 rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001253
1254 if (rv == -1) {
1255 printk(KERN_ERR "%s: invalid offset: 0x%016lx\n",
1256 __func__, off);
1257 dump_stack();
1258 return -1;
1259 }
1260
1261 if (rv == 1) {
1262 write_lock_irqsave(&adapter->adapter_lock, flags);
1263 crb_win_lock(adapter);
1264 netxen_nic_pci_set_crbwindow_2M(adapter, &off);
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001265 writel(data, (void __iomem *)off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001266 crb_win_unlock(adapter);
1267 write_unlock_irqrestore(&adapter->adapter_lock, flags);
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001268 } else
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001269 writel(data, (void __iomem *)off);
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001270
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001271
1272 return 0;
1273}
1274
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001275static u32
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001276netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001277{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001278 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001279 int rv;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001280 u32 data;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001281
Dhananjay Phadke23b6cc42009-05-08 22:02:30 +00001282 rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001283
1284 if (rv == -1) {
1285 printk(KERN_ERR "%s: invalid offset: 0x%016lx\n",
1286 __func__, off);
1287 dump_stack();
1288 return -1;
1289 }
1290
1291 if (rv == 1) {
1292 write_lock_irqsave(&adapter->adapter_lock, flags);
1293 crb_win_lock(adapter);
1294 netxen_nic_pci_set_crbwindow_2M(adapter, &off);
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001295 data = readl((void __iomem *)off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001296 crb_win_unlock(adapter);
1297 write_unlock_irqrestore(&adapter->adapter_lock, flags);
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001298 } else
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001299 data = readl((void __iomem *)off);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001300
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001301 return data;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001302}
1303
Jeff Garzik47906542007-11-23 21:23:36 -05001304static int netxen_pci_set_window_warning_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001305
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001306static unsigned long
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001307netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
1308 unsigned long long addr)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001309{
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001310 void __iomem *offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001311 int window;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001312 unsigned long long qdr_max;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001313 uint8_t func = adapter->ahw.pci_func;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001314
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001315 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1316 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P2;
1317 } else {
1318 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P3;
1319 }
1320
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001321 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1322 /* DDR network side */
1323 addr -= NETXEN_ADDR_DDR_NET;
1324 window = (addr >> 25) & 0x3ff;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001325 if (adapter->ahw.ddr_mn_window != window) {
1326 adapter->ahw.ddr_mn_window = window;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001327 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1328 NETXEN_PCIX_PH_REG(PCIE_MN_WINDOW_REG(func)));
1329 writel(window, offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001330 /* MUST make sure window is set before we forge on... */
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001331 readl(offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001332 }
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001333 addr -= (window * NETXEN_WINDOW_ONE);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001334 addr += NETXEN_PCI_DDR_NET;
1335 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1336 addr -= NETXEN_ADDR_OCM0;
1337 addr += NETXEN_PCI_OCM0;
1338 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1339 addr -= NETXEN_ADDR_OCM1;
1340 addr += NETXEN_PCI_OCM1;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001341 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_QDR_NET, qdr_max)) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001342 /* QDR network side */
1343 addr -= NETXEN_ADDR_QDR_NET;
1344 window = (addr >> 22) & 0x3f;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001345 if (adapter->ahw.qdr_sn_window != window) {
1346 adapter->ahw.qdr_sn_window = window;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001347 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1348 NETXEN_PCIX_PH_REG(PCIE_SN_WINDOW_REG(func)));
1349 writel((window << 22), offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001350 /* MUST make sure window is set before we forge on... */
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001351 readl(offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001352 }
1353 addr -= (window * 0x400000);
1354 addr += NETXEN_PCI_QDR_NET;
1355 } else {
1356 /*
1357 * peg gdb frequently accesses memory that doesn't exist,
1358 * this limits the chit chat so debugging isn't slowed down.
1359 */
1360 if ((netxen_pci_set_window_warning_count++ < 8)
1361 || (netxen_pci_set_window_warning_count % 64 == 0))
1362 printk("%s: Warning:netxen_nic_pci_set_window()"
1363 " Unknown address range!\n",
1364 netxen_nic_driver_name);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001365 addr = -1UL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001366 }
1367 return addr;
1368}
1369
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001370/* window 1 registers only */
1371static void netxen_nic_io_write_128M(struct netxen_adapter *adapter,
1372 void __iomem *addr, u32 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001373{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001374 read_lock(&adapter->adapter_lock);
1375 writel(data, addr);
1376 read_unlock(&adapter->adapter_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001377}
1378
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001379static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter,
1380 void __iomem *addr)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001381{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001382 u32 val;
1383
1384 read_lock(&adapter->adapter_lock);
1385 val = readl(addr);
1386 read_unlock(&adapter->adapter_lock);
1387
1388 return val;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001389}
1390
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001391static void netxen_nic_io_write_2M(struct netxen_adapter *adapter,
1392 void __iomem *addr, u32 data)
1393{
1394 writel(data, addr);
1395}
1396
1397static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter,
1398 void __iomem *addr)
1399{
1400 return readl(addr);
1401}
1402
1403void __iomem *
1404netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset)
1405{
1406 ulong off = offset;
1407
1408 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1409 if (offset < NETXEN_CRB_PCIX_HOST2 &&
1410 offset > NETXEN_CRB_PCIX_HOST)
1411 return PCI_OFFSET_SECOND_RANGE(adapter, offset);
1412 return NETXEN_CRB_NORMALIZE(adapter, offset);
1413 }
1414
1415 BUG_ON(netxen_nic_pci_get_crb_addr_2M(adapter, &off));
1416 return (void __iomem *)off;
1417}
1418
1419static unsigned long
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001420netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
1421 unsigned long long addr)
1422{
1423 int window;
1424 u32 win_read;
1425
1426 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1427 /* DDR network side */
1428 window = MN_WIN(addr);
1429 adapter->ahw.ddr_mn_window = window;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001430 NXWR32(adapter, adapter->ahw.mn_win_crb, window);
1431 win_read = NXRD32(adapter, adapter->ahw.mn_win_crb);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001432 if ((win_read << 17) != window) {
1433 printk(KERN_INFO "Written MNwin (0x%x) != "
1434 "Read MNwin (0x%x)\n", window, win_read);
1435 }
1436 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_DDR_NET;
1437 } else if (ADDR_IN_RANGE(addr,
1438 NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1439 if ((addr & 0x00ff800) == 0xff800) {
1440 printk("%s: QM access not handled.\n", __func__);
1441 addr = -1UL;
1442 }
1443
1444 window = OCM_WIN(addr);
1445 adapter->ahw.ddr_mn_window = window;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001446 NXWR32(adapter, adapter->ahw.mn_win_crb, window);
1447 win_read = NXRD32(adapter, adapter->ahw.mn_win_crb);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001448 if ((win_read >> 7) != window) {
1449 printk(KERN_INFO "%s: Written OCMwin (0x%x) != "
1450 "Read OCMwin (0x%x)\n",
1451 __func__, window, win_read);
1452 }
1453 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_OCM0_2M;
1454
1455 } else if (ADDR_IN_RANGE(addr,
1456 NETXEN_ADDR_QDR_NET, NETXEN_ADDR_QDR_NET_MAX_P3)) {
1457 /* QDR network side */
1458 window = MS_WIN(addr);
1459 adapter->ahw.qdr_sn_window = window;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001460 NXWR32(adapter, adapter->ahw.ms_win_crb, window);
1461 win_read = NXRD32(adapter, adapter->ahw.ms_win_crb);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001462 if (win_read != window) {
1463 printk(KERN_INFO "%s: Written MSwin (0x%x) != "
1464 "Read MSwin (0x%x)\n",
1465 __func__, window, win_read);
1466 }
1467 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_QDR_NET;
1468
1469 } else {
1470 /*
1471 * peg gdb frequently accesses memory that doesn't exist,
1472 * this limits the chit chat so debugging isn't slowed down.
1473 */
1474 if ((netxen_pci_set_window_warning_count++ < 8)
1475 || (netxen_pci_set_window_warning_count%64 == 0)) {
1476 printk("%s: Warning:%s Unknown address range!\n",
1477 __func__, netxen_nic_driver_name);
1478}
1479 addr = -1UL;
1480 }
1481 return addr;
1482}
1483
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001484#define MAX_CTL_CHECK 1000
1485
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001486static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001487netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
1488 u64 off, void *data, int size)
1489{
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001490 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001491 int i, j, ret = 0, loop, sz[2], off0;
1492 uint32_t temp;
1493 uint64_t off8, tmpw, word[2] = {0, 0};
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001494 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001495
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001496 if (size != 8)
1497 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001498
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001499 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1500 NETXEN_ADDR_QDR_NET_MAX_P2)) {
1501 mem_crb = pci_base_offset(adapter, NETXEN_CRB_QDR_NET);
1502 goto correct;
1503 }
1504
1505 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1506 mem_crb = pci_base_offset(adapter, NETXEN_CRB_DDR_NET);
1507 goto correct;
1508 }
1509
1510 return -EIO;
1511
1512correct:
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001513 off8 = off & 0xfffffff8;
1514 off0 = off & 0x7;
1515 sz[0] = (size < (8 - off0)) ? size : (8 - off0);
1516 sz[1] = size - sz[0];
1517 loop = ((off0 + size - 1) >> 3) + 1;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001518
1519 if ((size != 8) || (off0 != 0)) {
1520 for (i = 0; i < loop; i++) {
1521 if (adapter->pci_mem_read(adapter,
1522 off8 + (i << 3), &word[i], 8))
1523 return -1;
1524 }
1525 }
1526
1527 switch (size) {
1528 case 1:
1529 tmpw = *((uint8_t *)data);
1530 break;
1531 case 2:
1532 tmpw = *((uint16_t *)data);
1533 break;
1534 case 4:
1535 tmpw = *((uint32_t *)data);
1536 break;
1537 case 8:
1538 default:
1539 tmpw = *((uint64_t *)data);
1540 break;
1541 }
1542 word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
1543 word[0] |= tmpw << (off0 * 8);
1544
1545 if (loop == 2) {
1546 word[1] &= ~(~0ULL << (sz[1] * 8));
1547 word[1] |= tmpw >> (sz[0] * 8);
1548 }
1549
1550 write_lock_irqsave(&adapter->adapter_lock, flags);
1551 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1552
1553 for (i = 0; i < loop; i++) {
1554 writel((uint32_t)(off8 + (i << 3)),
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001555 (mem_crb+MIU_TEST_AGT_ADDR_LO));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001556 writel(0,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001557 (mem_crb+MIU_TEST_AGT_ADDR_HI));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001558 writel(word[i] & 0xffffffff,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001559 (mem_crb+MIU_TEST_AGT_WRDATA_LO));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001560 writel((word[i] >> 32) & 0xffffffff,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001561 (mem_crb+MIU_TEST_AGT_WRDATA_HI));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001562 writel(MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001563 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001564 writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001565 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001566
1567 for (j = 0; j < MAX_CTL_CHECK; j++) {
1568 temp = readl(
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001569 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001570 if ((temp & MIU_TA_CTL_BUSY) == 0)
1571 break;
1572 }
1573
1574 if (j >= MAX_CTL_CHECK) {
Dhananjay Phadke39754f42009-02-17 20:27:02 -08001575 if (printk_ratelimit())
1576 dev_err(&adapter->pdev->dev,
1577 "failed to write through agent\n");
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001578 ret = -1;
1579 break;
1580 }
1581 }
1582
1583 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1584 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1585 return ret;
1586}
1587
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001588static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001589netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
1590 u64 off, void *data, int size)
1591{
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001592 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001593 int i, j = 0, k, start, end, loop, sz[2], off0[2];
1594 uint32_t temp;
1595 uint64_t off8, val, word[2] = {0, 0};
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001596 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001597
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001598 if (size != 8)
1599 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001600
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001601 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1602 NETXEN_ADDR_QDR_NET_MAX_P2)) {
1603 mem_crb = pci_base_offset(adapter, NETXEN_CRB_QDR_NET);
1604 goto correct;
1605 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001606
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001607 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1608 mem_crb = pci_base_offset(adapter, NETXEN_CRB_DDR_NET);
1609 goto correct;
1610 }
1611
1612 return -EIO;
1613
1614correct:
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001615 off8 = off & 0xfffffff8;
1616 off0[0] = off & 0x7;
1617 off0[1] = 0;
1618 sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]);
1619 sz[1] = size - sz[0];
1620 loop = ((off0[0] + size - 1) >> 3) + 1;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001621
1622 write_lock_irqsave(&adapter->adapter_lock, flags);
1623 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1624
1625 for (i = 0; i < loop; i++) {
1626 writel((uint32_t)(off8 + (i << 3)),
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001627 (mem_crb+MIU_TEST_AGT_ADDR_LO));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001628 writel(0,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001629 (mem_crb+MIU_TEST_AGT_ADDR_HI));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001630 writel(MIU_TA_CTL_ENABLE,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001631 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001632 writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE,
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001633 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001634
1635 for (j = 0; j < MAX_CTL_CHECK; j++) {
1636 temp = readl(
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001637 (mem_crb+MIU_TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001638 if ((temp & MIU_TA_CTL_BUSY) == 0)
1639 break;
1640 }
1641
1642 if (j >= MAX_CTL_CHECK) {
Dhananjay Phadke39754f42009-02-17 20:27:02 -08001643 if (printk_ratelimit())
1644 dev_err(&adapter->pdev->dev,
1645 "failed to read through agent\n");
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001646 break;
1647 }
1648
1649 start = off0[i] >> 2;
1650 end = (off0[i] + sz[i] - 1) >> 2;
1651 for (k = start; k <= end; k++) {
1652 word[i] |= ((uint64_t) readl(
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001653 (mem_crb +
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001654 MIU_TEST_AGT_RDDATA(k))) << (32*k));
1655 }
1656 }
1657
1658 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1659 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1660
1661 if (j >= MAX_CTL_CHECK)
1662 return -1;
1663
1664 if (sz[0] == 8) {
1665 val = word[0];
1666 } else {
1667 val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
1668 ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
1669 }
1670
1671 switch (size) {
1672 case 1:
1673 *(uint8_t *)data = val;
1674 break;
1675 case 2:
1676 *(uint16_t *)data = val;
1677 break;
1678 case 4:
1679 *(uint32_t *)data = val;
1680 break;
1681 case 8:
1682 *(uint64_t *)data = val;
1683 break;
1684 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001685 return 0;
1686}
1687
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001688static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001689netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
1690 u64 off, void *data, int size)
1691{
1692 int i, j, ret = 0, loop, sz[2], off0;
1693 uint32_t temp;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001694 uint64_t off8, tmpw, word[2] = {0, 0};
1695 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001696
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001697 if (size != 8)
1698 return -EIO;
1699
1700 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1701 NETXEN_ADDR_QDR_NET_MAX_P3)) {
1702 mem_crb = netxen_get_ioaddr(adapter, NETXEN_CRB_QDR_NET);
1703 goto correct;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001704 }
1705
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001706 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1707 mem_crb = netxen_get_ioaddr(adapter, NETXEN_CRB_DDR_NET);
1708 goto correct;
1709 }
1710
1711 return -EIO;
1712
1713correct:
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001714 off8 = off & 0xfffffff8;
1715 off0 = off & 0x7;
1716 sz[0] = (size < (8 - off0)) ? size : (8 - off0);
1717 sz[1] = size - sz[0];
1718 loop = ((off0 + size - 1) >> 3) + 1;
1719
1720 if ((size != 8) || (off0 != 0)) {
1721 for (i = 0; i < loop; i++) {
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001722 if (adapter->pci_mem_read(adapter,
1723 off8 + (i << 3), &word[i], 8))
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001724 return -1;
1725 }
1726 }
1727
1728 switch (size) {
1729 case 1:
1730 tmpw = *((uint8_t *)data);
1731 break;
1732 case 2:
1733 tmpw = *((uint16_t *)data);
1734 break;
1735 case 4:
1736 tmpw = *((uint32_t *)data);
1737 break;
1738 case 8:
1739 default:
1740 tmpw = *((uint64_t *)data);
1741 break;
1742 }
1743
1744 word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
1745 word[0] |= tmpw << (off0 * 8);
1746
1747 if (loop == 2) {
1748 word[1] &= ~(~0ULL << (sz[1] * 8));
1749 word[1] |= tmpw >> (sz[0] * 8);
1750 }
1751
1752 /*
1753 * don't lock here - write_wx gets the lock if each time
1754 * write_lock_irqsave(&adapter->adapter_lock, flags);
1755 * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1756 */
1757
1758 for (i = 0; i < loop; i++) {
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001759 writel(off8 + (i << 3), mem_crb+MIU_TEST_AGT_ADDR_LO);
1760 writel(0, mem_crb+MIU_TEST_AGT_ADDR_HI);
1761 writel(word[i] & 0xffffffff, mem_crb+MIU_TEST_AGT_WRDATA_LO);
1762 writel((word[i] >> 32) & 0xffffffff,
1763 mem_crb+MIU_TEST_AGT_WRDATA_HI);
1764 writel((MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE),
1765 mem_crb+MIU_TEST_AGT_CTRL);
1766 writel(MIU_TA_CTL_START | MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE,
1767 mem_crb+MIU_TEST_AGT_CTRL);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001768
1769 for (j = 0; j < MAX_CTL_CHECK; j++) {
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001770 temp = readl(mem_crb + MIU_TEST_AGT_CTRL);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001771 if ((temp & MIU_TA_CTL_BUSY) == 0)
1772 break;
1773 }
1774
1775 if (j >= MAX_CTL_CHECK) {
Dhananjay Phadke39754f42009-02-17 20:27:02 -08001776 if (printk_ratelimit())
1777 dev_err(&adapter->pdev->dev,
1778 "failed to write through agent\n");
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001779 ret = -1;
1780 break;
1781 }
1782 }
1783
1784 /*
1785 * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1786 * write_unlock_irqrestore(&adapter->adapter_lock, flags);
1787 */
1788 return ret;
1789}
1790
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001791static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001792netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
1793 u64 off, void *data, int size)
1794{
1795 int i, j = 0, k, start, end, loop, sz[2], off0[2];
1796 uint32_t temp;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001797 uint64_t off8, val, word[2] = {0, 0};
1798 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001799
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001800 if (size != 8)
1801 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001802
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001803 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1804 NETXEN_ADDR_QDR_NET_MAX_P3)) {
1805 mem_crb = netxen_get_ioaddr(adapter, NETXEN_CRB_QDR_NET);
1806 goto correct;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001807 }
1808
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001809 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1810 mem_crb = netxen_get_ioaddr(adapter, NETXEN_CRB_DDR_NET);
1811 goto correct;
1812 }
1813
1814 return -EIO;
1815
1816correct:
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001817 off8 = off & 0xfffffff8;
1818 off0[0] = off & 0x7;
1819 off0[1] = 0;
1820 sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]);
1821 sz[1] = size - sz[0];
1822 loop = ((off0[0] + size - 1) >> 3) + 1;
1823
1824 /*
1825 * don't lock here - write_wx gets the lock if each time
1826 * write_lock_irqsave(&adapter->adapter_lock, flags);
1827 * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1828 */
1829
1830 for (i = 0; i < loop; i++) {
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001831 writel(off8 + (i << 3), mem_crb + MIU_TEST_AGT_ADDR_LO);
1832 writel(0, mem_crb + MIU_TEST_AGT_ADDR_HI);
1833 writel(MIU_TA_CTL_ENABLE, mem_crb + MIU_TEST_AGT_CTRL);
1834 writel(MIU_TA_CTL_START | MIU_TA_CTL_ENABLE,
1835 mem_crb + MIU_TEST_AGT_CTRL);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001836
1837 for (j = 0; j < MAX_CTL_CHECK; j++) {
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001838 temp = readl(mem_crb + MIU_TEST_AGT_CTRL);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001839 if ((temp & MIU_TA_CTL_BUSY) == 0)
1840 break;
1841 }
1842
1843 if (j >= MAX_CTL_CHECK) {
Dhananjay Phadke39754f42009-02-17 20:27:02 -08001844 if (printk_ratelimit())
1845 dev_err(&adapter->pdev->dev,
1846 "failed to read through agent\n");
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001847 break;
1848 }
1849
1850 start = off0[i] >> 2;
1851 end = (off0[i] + sz[i] - 1) >> 2;
1852 for (k = start; k <= end; k++) {
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001853 temp = readl(mem_crb + MIU_TEST_AGT_RDDATA(k));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001854 word[i] |= ((uint64_t)temp << (32 * k));
1855 }
1856 }
1857
1858 /*
1859 * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1860 * write_unlock_irqrestore(&adapter->adapter_lock, flags);
1861 */
1862
1863 if (j >= MAX_CTL_CHECK)
1864 return -1;
1865
1866 if (sz[0] == 8) {
1867 val = word[0];
1868 } else {
1869 val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
1870 ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
1871 }
1872
1873 switch (size) {
1874 case 1:
1875 *(uint8_t *)data = val;
1876 break;
1877 case 2:
1878 *(uint16_t *)data = val;
1879 break;
1880 case 4:
1881 *(uint32_t *)data = val;
1882 break;
1883 case 8:
1884 *(uint64_t *)data = val;
1885 break;
1886 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001887 return 0;
1888}
1889
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001890void
1891netxen_setup_hwops(struct netxen_adapter *adapter)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001892{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001893 adapter->init_port = netxen_niu_xg_init_port;
1894 adapter->stop_port = netxen_niu_disable_xg_port;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001895
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001896 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1897 adapter->crb_read = netxen_nic_hw_read_wx_128M,
1898 adapter->crb_write = netxen_nic_hw_write_wx_128M,
1899 adapter->pci_set_window = netxen_nic_pci_set_window_128M,
1900 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M,
1901 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M,
1902 adapter->io_read = netxen_nic_io_read_128M,
1903 adapter->io_write = netxen_nic_io_write_128M,
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001904
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001905 adapter->macaddr_set = netxen_p2_nic_set_mac_addr;
1906 adapter->set_multi = netxen_p2_nic_set_multi;
1907 adapter->set_mtu = netxen_nic_set_mtu_xgb;
1908 adapter->set_promisc = netxen_p2_nic_set_promisc;
1909
1910 } else {
1911 adapter->crb_read = netxen_nic_hw_read_wx_2M,
1912 adapter->crb_write = netxen_nic_hw_write_wx_2M,
1913 adapter->pci_set_window = netxen_nic_pci_set_window_2M,
1914 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M,
1915 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M,
1916 adapter->io_read = netxen_nic_io_read_2M,
1917 adapter->io_write = netxen_nic_io_write_2M,
1918
1919 adapter->set_mtu = nx_fw_cmd_set_mtu;
1920 adapter->set_promisc = netxen_p3_nic_set_promisc;
1921 adapter->macaddr_set = netxen_p3_nic_set_mac_addr;
1922 adapter->set_multi = netxen_p3_nic_set_multi;
1923
1924 adapter->phy_read = nx_fw_cmd_query_phy;
1925 adapter->phy_write = nx_fw_cmd_set_phy;
1926 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001927}
1928
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001929int netxen_nic_get_board_info(struct netxen_adapter *adapter)
1930{
Dhananjay Phadke0dc6d9c2009-10-21 19:39:03 +00001931 int offset, board_type, magic;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001932 struct pci_dev *pdev = adapter->pdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001933
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001934 offset = NX_FW_MAGIC_OFFSET;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001935 if (netxen_rom_fast_read(adapter, offset, &magic))
1936 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001937
Dhananjay Phadke0dc6d9c2009-10-21 19:39:03 +00001938 if (magic != NETXEN_BDINFO_MAGIC) {
1939 dev_err(&pdev->dev, "invalid board config, magic=%08x\n",
1940 magic);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001941 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001942 }
1943
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001944 offset = NX_BRDTYPE_OFFSET;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001945 if (netxen_rom_fast_read(adapter, offset, &board_type))
1946 return -EIO;
1947
1948 adapter->ahw.board_type = board_type;
1949
1950 if (board_type == NETXEN_BRDTYPE_P3_4_GB_MM) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001951 u32 gpio = NXRD32(adapter, NETXEN_ROMUSB_GLB_PAD_GPIO_I);
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001952 if ((gpio & 0x8000) == 0)
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001953 board_type = NETXEN_BRDTYPE_P3_10G_TP;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001954 }
1955
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00001956 switch (board_type) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001957 case NETXEN_BRDTYPE_P2_SB35_4G:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001958 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001959 break;
1960 case NETXEN_BRDTYPE_P2_SB31_10G:
1961 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1962 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1963 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001964 case NETXEN_BRDTYPE_P3_HMEZ:
1965 case NETXEN_BRDTYPE_P3_XG_LOM:
1966 case NETXEN_BRDTYPE_P3_10G_CX4:
1967 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
1968 case NETXEN_BRDTYPE_P3_IMEZ:
1969 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
Dhananjay Phadkea70f9392008-08-01 03:14:56 -07001970 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
1971 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001972 case NETXEN_BRDTYPE_P3_10G_XFP:
1973 case NETXEN_BRDTYPE_P3_10000_BASE_T:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001974 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001975 break;
1976 case NETXEN_BRDTYPE_P1_BD:
1977 case NETXEN_BRDTYPE_P1_SB:
1978 case NETXEN_BRDTYPE_P1_SMAX:
1979 case NETXEN_BRDTYPE_P1_SOCK:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001980 case NETXEN_BRDTYPE_P3_REF_QG:
1981 case NETXEN_BRDTYPE_P3_4_GB:
1982 case NETXEN_BRDTYPE_P3_4_GB_MM:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001983 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001984 break;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001985 case NETXEN_BRDTYPE_P3_10G_TP:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001986 adapter->ahw.port_type = (adapter->portnum < 2) ?
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001987 NETXEN_NIC_XGBE : NETXEN_NIC_GBE;
1988 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001989 default:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001990 dev_err(&pdev->dev, "unknown board type %x\n", board_type);
1991 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001992 break;
1993 }
1994
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001995 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001996}
1997
1998/* NIU access sections */
1999
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002000int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002001{
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07002002 new_mtu += MTU_FUDGE_FACTOR;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002003 NXWR32(adapter, NETXEN_NIU_GB_MAX_FRAME_SIZE(adapter->physical_port),
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07002004 new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002005 return 0;
2006}
2007
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002008int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002009{
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07002010 new_mtu += MTU_FUDGE_FACTOR;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07002011 if (adapter->physical_port == 0)
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002012 NXWR32(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu);
Jeff Garzik47906542007-11-23 21:23:36 -05002013 else
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002014 NXWR32(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002015 return 0;
2016}
2017
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002018void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002019{
Al Viroa608ab9c2007-01-02 10:39:10 +00002020 __u32 status;
2021 __u32 autoneg;
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002022 __u32 port_mode;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002023
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002024 if (!netif_carrier_ok(adapter->netdev)) {
2025 adapter->link_speed = 0;
2026 adapter->link_duplex = -1;
2027 adapter->link_autoneg = AUTONEG_ENABLE;
2028 return;
2029 }
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002030
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00002031 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002032 port_mode = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002033 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
2034 adapter->link_speed = SPEED_1000;
2035 adapter->link_duplex = DUPLEX_FULL;
2036 adapter->link_autoneg = AUTONEG_DISABLE;
2037 return;
2038 }
2039
Amit S. Kale80922fb2006-12-04 09:18:00 -08002040 if (adapter->phy_read
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002041 && adapter->phy_read(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002042 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
2043 &status) == 0) {
2044 if (netxen_get_phy_link(status)) {
2045 switch (netxen_get_phy_speed(status)) {
2046 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002047 adapter->link_speed = SPEED_10;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002048 break;
2049 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002050 adapter->link_speed = SPEED_100;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002051 break;
2052 case 2:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002053 adapter->link_speed = SPEED_1000;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002054 break;
2055 default:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002056 adapter->link_speed = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002057 break;
2058 }
2059 switch (netxen_get_phy_duplex(status)) {
2060 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002061 adapter->link_duplex = DUPLEX_HALF;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002062 break;
2063 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002064 adapter->link_duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002065 break;
2066 default:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002067 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002068 break;
2069 }
Amit S. Kale80922fb2006-12-04 09:18:00 -08002070 if (adapter->phy_read
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002071 && adapter->phy_read(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002072 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08002073 &autoneg) != 0)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002074 adapter->link_autoneg = autoneg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002075 } else
2076 goto link_down;
2077 } else {
2078 link_down:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08002079 adapter->link_speed = 0;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002080 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002081 }
2082 }
2083}
2084
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002085int
2086netxen_nic_wol_supported(struct netxen_adapter *adapter)
2087{
2088 u32 wol_cfg;
2089
2090 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2091 return 0;
2092
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002093 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002094 if (wol_cfg & (1UL << adapter->portnum)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002095 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002096 if (wol_cfg & (1 << adapter->portnum))
2097 return 1;
2098 }
2099
2100 return 0;
2101}