blob: 398dfd46b8c18a53d5fc1eb6a8351a2e8cf4d8f0 [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))
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +000034#define OCM_WIN_P3P(addr) (addr & 0xffc0000)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070035#define MS_WIN(addr) (addr & 0x0ffc0000)
36
37#define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
38
39#define CRB_BLK(off) ((off >> 20) & 0x3f)
40#define CRB_SUBBLK(off) ((off >> 16) & 0xf)
41#define CRB_WINDOW_2M (0x130060)
42#define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000))
43#define CRB_INDIRECT_2M (0x1e0000UL)
44
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +000045static void netxen_nic_io_write_128M(struct netxen_adapter *adapter,
46 void __iomem *addr, u32 data);
47static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter,
48 void __iomem *addr);
49
Dhananjay Phadkee98e3352009-04-07 22:50:38 +000050#ifndef readq
51static inline u64 readq(void __iomem *addr)
52{
53 return readl(addr) | (((u64) readl(addr + 4)) << 32LL);
54}
55#endif
56
57#ifndef writeq
58static inline void writeq(u64 val, void __iomem *addr)
59{
60 writel(((u32) (val)), (addr));
61 writel(((u32) (val >> 32)), (addr + 4));
62}
63#endif
64
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +000065#define ADDR_IN_RANGE(addr, low, high) \
66 (((addr) < (high)) && ((addr) >= (low)))
67
68#define PCI_OFFSET_FIRST_RANGE(adapter, off) \
69 ((adapter)->ahw.pci_base0 + (off))
70#define PCI_OFFSET_SECOND_RANGE(adapter, off) \
71 ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START)
72#define PCI_OFFSET_THIRD_RANGE(adapter, off) \
73 ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START)
74
75static void __iomem *pci_base_offset(struct netxen_adapter *adapter,
76 unsigned long off)
77{
78 if (ADDR_IN_RANGE(off, FIRST_PAGE_GROUP_START, FIRST_PAGE_GROUP_END))
79 return PCI_OFFSET_FIRST_RANGE(adapter, off);
80
81 if (ADDR_IN_RANGE(off, SECOND_PAGE_GROUP_START, SECOND_PAGE_GROUP_END))
82 return PCI_OFFSET_SECOND_RANGE(adapter, off);
83
84 if (ADDR_IN_RANGE(off, THIRD_PAGE_GROUP_START, THIRD_PAGE_GROUP_END))
85 return PCI_OFFSET_THIRD_RANGE(adapter, off);
86
87 return NULL;
88}
89
Dhananjay Phadkeea7eaa32009-04-07 22:50:48 +000090static crb_128M_2M_block_map_t
91crb_128M_2M_map[64] __cacheline_aligned_in_smp = {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070092 {{{0, 0, 0, 0} } }, /* 0: PCI */
93 {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */
94 {1, 0x0110000, 0x0120000, 0x130000},
95 {1, 0x0120000, 0x0122000, 0x124000},
96 {1, 0x0130000, 0x0132000, 0x126000},
97 {1, 0x0140000, 0x0142000, 0x128000},
98 {1, 0x0150000, 0x0152000, 0x12a000},
99 {1, 0x0160000, 0x0170000, 0x110000},
100 {1, 0x0170000, 0x0172000, 0x12e000},
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 {0, 0x0000000, 0x0000000, 0x000000},
107 {1, 0x01e0000, 0x01e0800, 0x122000},
108 {0, 0x0000000, 0x0000000, 0x000000} } },
109 {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */
110 {{{0, 0, 0, 0} } }, /* 3: */
111 {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */
112 {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */
113 {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */
114 {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */
115 {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */
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 {0, 0x0000000, 0x0000000, 0x000000},
130 {1, 0x08f0000, 0x08f2000, 0x172000} } },
131 {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/
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 {0, 0x0000000, 0x0000000, 0x000000},
146 {1, 0x09f0000, 0x09f2000, 0x176000} } },
147 {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/
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 {0, 0x0000000, 0x0000000, 0x000000},
162 {1, 0x0af0000, 0x0af2000, 0x17a000} } },
163 {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/
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 {0, 0x0000000, 0x0000000, 0x000000},
178 {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
179 {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */
180 {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */
181 {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */
182 {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */
183 {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */
184 {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */
185 {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */
186 {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */
187 {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */
188 {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */
189 {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */
190 {{{0, 0, 0, 0} } }, /* 23: */
191 {{{0, 0, 0, 0} } }, /* 24: */
192 {{{0, 0, 0, 0} } }, /* 25: */
193 {{{0, 0, 0, 0} } }, /* 26: */
194 {{{0, 0, 0, 0} } }, /* 27: */
195 {{{0, 0, 0, 0} } }, /* 28: */
196 {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */
197 {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */
198 {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */
199 {{{0} } }, /* 32: PCI */
200 {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */
201 {1, 0x2110000, 0x2120000, 0x130000},
202 {1, 0x2120000, 0x2122000, 0x124000},
203 {1, 0x2130000, 0x2132000, 0x126000},
204 {1, 0x2140000, 0x2142000, 0x128000},
205 {1, 0x2150000, 0x2152000, 0x12a000},
206 {1, 0x2160000, 0x2170000, 0x110000},
207 {1, 0x2170000, 0x2172000, 0x12e000},
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 {0, 0x0000000, 0x0000000, 0x000000} } },
216 {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */
217 {{{0} } }, /* 35: */
218 {{{0} } }, /* 36: */
219 {{{0} } }, /* 37: */
220 {{{0} } }, /* 38: */
221 {{{0} } }, /* 39: */
222 {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */
223 {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */
224 {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */
225 {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */
226 {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */
227 {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */
228 {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */
229 {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */
230 {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */
231 {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */
232 {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */
233 {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */
234 {{{0} } }, /* 52: */
235 {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */
236 {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */
237 {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */
238 {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */
239 {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */
240 {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */
241 {{{0} } }, /* 59: I2C0 */
242 {{{0} } }, /* 60: I2C1 */
243 {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */
244 {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */
245 {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */
246};
247
248/*
249 * top 12 bits of crb internal address (hub, agent)
250 */
251static unsigned crb_hub_agt[64] =
252{
253 0,
254 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
255 NETXEN_HW_CRB_HUB_AGT_ADR_MN,
256 NETXEN_HW_CRB_HUB_AGT_ADR_MS,
257 0,
258 NETXEN_HW_CRB_HUB_AGT_ADR_SRE,
259 NETXEN_HW_CRB_HUB_AGT_ADR_NIU,
260 NETXEN_HW_CRB_HUB_AGT_ADR_QMN,
261 NETXEN_HW_CRB_HUB_AGT_ADR_SQN0,
262 NETXEN_HW_CRB_HUB_AGT_ADR_SQN1,
263 NETXEN_HW_CRB_HUB_AGT_ADR_SQN2,
264 NETXEN_HW_CRB_HUB_AGT_ADR_SQN3,
265 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
266 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
267 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
268 NETXEN_HW_CRB_HUB_AGT_ADR_PGN4,
269 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
270 NETXEN_HW_CRB_HUB_AGT_ADR_PGN0,
271 NETXEN_HW_CRB_HUB_AGT_ADR_PGN1,
272 NETXEN_HW_CRB_HUB_AGT_ADR_PGN2,
273 NETXEN_HW_CRB_HUB_AGT_ADR_PGN3,
274 NETXEN_HW_CRB_HUB_AGT_ADR_PGND,
275 NETXEN_HW_CRB_HUB_AGT_ADR_PGNI,
276 NETXEN_HW_CRB_HUB_AGT_ADR_PGS0,
277 NETXEN_HW_CRB_HUB_AGT_ADR_PGS1,
278 NETXEN_HW_CRB_HUB_AGT_ADR_PGS2,
279 NETXEN_HW_CRB_HUB_AGT_ADR_PGS3,
280 0,
281 NETXEN_HW_CRB_HUB_AGT_ADR_PGSI,
282 NETXEN_HW_CRB_HUB_AGT_ADR_SN,
283 0,
284 NETXEN_HW_CRB_HUB_AGT_ADR_EG,
285 0,
286 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
287 NETXEN_HW_CRB_HUB_AGT_ADR_CAM,
288 0,
289 0,
290 0,
291 0,
292 0,
293 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
294 0,
295 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1,
296 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2,
297 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3,
298 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4,
299 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5,
300 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6,
301 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7,
302 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
303 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
304 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
305 0,
306 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0,
307 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8,
308 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9,
309 NETXEN_HW_CRB_HUB_AGT_ADR_OCM0,
310 0,
311 NETXEN_HW_CRB_HUB_AGT_ADR_SMB,
312 NETXEN_HW_CRB_HUB_AGT_ADR_I2C0,
313 NETXEN_HW_CRB_HUB_AGT_ADR_I2C1,
314 0,
315 NETXEN_HW_CRB_HUB_AGT_ADR_PGNC,
316 0,
317};
318
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400319/* PCI Windowing for DDR regions. */
320
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700321#define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400322
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000323#define NETXEN_PCIE_SEM_TIMEOUT 10000
324
325int
326netxen_pcie_sem_lock(struct netxen_adapter *adapter, int sem, u32 id_reg)
327{
328 int done = 0, timeout = 0;
329
330 while (!done) {
331 done = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_LOCK(sem)));
332 if (done == 1)
333 break;
334 if (++timeout >= NETXEN_PCIE_SEM_TIMEOUT)
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +0000335 return -EIO;
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000336 msleep(1);
337 }
338
339 if (id_reg)
340 NXWR32(adapter, id_reg, adapter->portnum);
341
342 return 0;
343}
344
345void
346netxen_pcie_sem_unlock(struct netxen_adapter *adapter, int sem)
347{
Amit Kumar Salecha581e8ae2010-01-07 22:10:15 +0000348 NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_UNLOCK(sem)));
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000349}
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{
Narender Kumara7483b02009-11-20 15:09:33 +0000391 u32 mac_cfg;
392 u32 cnt = 0;
393 __u32 reg = 0x0200;
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000394 u32 port = adapter->physical_port;
Narender Kumara7483b02009-11-20 15:09:33 +0000395 u16 board_type = adapter->ahw.board_type;
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000396
397 if (port > NETXEN_NIU_MAX_XG_PORTS)
398 return -EINVAL;
399
Narender Kumara7483b02009-11-20 15:09:33 +0000400 mac_cfg = NXRD32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port));
401 mac_cfg &= ~0x4;
402 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg);
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000403
Narender Kumara7483b02009-11-20 15:09:33 +0000404 if ((board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) ||
405 (board_type == NETXEN_BRDTYPE_P2_SB31_10G_HMEZ))
406 reg = (0x20 << port);
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000407
Narender Kumara7483b02009-11-20 15:09:33 +0000408 NXWR32(adapter, NETXEN_NIU_FRAME_COUNT_SELECT, reg);
409
410 mdelay(10);
411
412 while (NXRD32(adapter, NETXEN_NIU_FRAME_COUNT) && ++cnt < 20)
413 mdelay(10);
414
415 if (cnt < 20) {
416
417 reg = NXRD32(adapter,
418 NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port));
419
420 if (mode == NETXEN_NIU_PROMISC_MODE)
421 reg = (reg | 0x2000UL);
422 else
423 reg = (reg & ~0x2000UL);
424
425 if (mode == NETXEN_NIU_ALLMULTI_MODE)
426 reg = (reg | 0x1000UL);
427 else
428 reg = (reg & ~0x1000UL);
429
430 NXWR32(adapter,
431 NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), reg);
432 }
433
434 mac_cfg |= 0x4;
435 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg);
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000436
437 return 0;
438}
439
440int netxen_p2_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr)
441{
442 u32 mac_hi, mac_lo;
443 u32 reg_hi, reg_lo;
444
445 u8 phy = adapter->physical_port;
446
447 if (phy >= NETXEN_NIU_MAX_XG_PORTS)
448 return -EINVAL;
449
450 mac_lo = ((u32)addr[0] << 16) | ((u32)addr[1] << 24);
451 mac_hi = addr[2] | ((u32)addr[3] << 8) |
452 ((u32)addr[4] << 16) | ((u32)addr[5] << 24);
453
454 reg_lo = NETXEN_NIU_XGE_STATION_ADDR_0_1 + (0x10000 * phy);
455 reg_hi = NETXEN_NIU_XGE_STATION_ADDR_0_HI + (0x10000 * phy);
456
457 /* write twice to flush */
458 if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi))
459 return -EIO;
460 if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi))
461 return -EIO;
462
463 return 0;
464}
465
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700466static int
467netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter)
468{
469 u32 val = 0;
470 u16 port = adapter->physical_port;
Narender Kumar5d09e532009-11-20 22:08:57 +0000471 u8 *addr = adapter->mac_addr;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700472
473 if (adapter->mc_enabled)
474 return 0;
475
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000476 val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700477 val |= (1UL << (28+port));
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000478 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700479
480 /* add broadcast addr to filter */
481 val = 0xffffff;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000482 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
483 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700484
485 /* add station addr to filter */
486 val = MAC_HI(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000487 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700488 val = MAC_LO(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000489 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700490
491 adapter->mc_enabled = 1;
492 return 0;
493}
494
495static int
496netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter)
497{
498 u32 val = 0;
499 u16 port = adapter->physical_port;
Narender Kumar5d09e532009-11-20 22:08:57 +0000500 u8 *addr = adapter->mac_addr;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700501
502 if (!adapter->mc_enabled)
503 return 0;
504
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000505 val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700506 val &= ~(1UL << (28+port));
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000507 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700508
509 val = MAC_HI(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000510 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700511 val = MAC_LO(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000512 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700513
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000514 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), 0);
515 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700516
517 adapter->mc_enabled = 0;
518 return 0;
519}
520
521static int
522netxen_nic_set_mcast_addr(struct netxen_adapter *adapter,
523 int index, u8 *addr)
524{
525 u32 hi = 0, lo = 0;
526 u16 port = adapter->physical_port;
527
528 lo = MAC_LO(addr);
529 hi = MAC_HI(addr);
530
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000531 NXWR32(adapter, NETXEN_MCAST_ADDR(port, index), hi);
532 NXWR32(adapter, NETXEN_MCAST_ADDR(port, index)+4, lo);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700533
534 return 0;
535}
536
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700537void netxen_p2_nic_set_multi(struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400538{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700539 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400540 struct dev_mc_list *mc_ptr;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700541 u8 null_addr[6];
542 int index = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400543
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700544 memset(null_addr, 0, 6);
545
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400546 if (netdev->flags & IFF_PROMISC) {
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700547
548 adapter->set_promisc(adapter,
549 NETXEN_NIU_PROMISC_MODE);
550
551 /* Full promiscuous mode */
552 netxen_nic_disable_mcast_filter(adapter);
553
554 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400555 }
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700556
557 if (netdev->mc_count == 0) {
558 adapter->set_promisc(adapter,
559 NETXEN_NIU_NON_PROMISC_MODE);
560 netxen_nic_disable_mcast_filter(adapter);
561 return;
562 }
563
564 adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE);
565 if (netdev->flags & IFF_ALLMULTI ||
566 netdev->mc_count > adapter->max_mc_count) {
567 netxen_nic_disable_mcast_filter(adapter);
568 return;
569 }
570
571 netxen_nic_enable_mcast_filter(adapter);
572
573 for (mc_ptr = netdev->mc_list; mc_ptr; mc_ptr = mc_ptr->next, index++)
574 netxen_nic_set_mcast_addr(adapter, index, mc_ptr->dmi_addr);
575
576 if (index != netdev->mc_count)
577 printk(KERN_WARNING "%s: %s multicast address count mismatch\n",
578 netxen_nic_driver_name, netdev->name);
579
580 /* Clear out remaining addresses */
581 for (; index < adapter->max_mc_count; index++)
582 netxen_nic_set_mcast_addr(adapter, index, null_addr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400583}
584
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700585static int
586netxen_send_cmd_descs(struct netxen_adapter *adapter,
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000587 struct cmd_desc_type0 *cmd_desc_arr, int nr_desc)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700588{
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000589 u32 i, producer, consumer;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700590 struct netxen_cmd_buffer *pbuf;
591 struct cmd_desc_type0 *cmd_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000592 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700593
594 i = 0;
595
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000596 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
597 return -EIO;
598
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000599 tx_ring = adapter->tx_ring;
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000600 __netif_tx_lock_bh(tx_ring->txq);
Dhananjay Phadke03e678e2009-01-14 20:49:43 -0800601
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000602 producer = tx_ring->producer;
603 consumer = tx_ring->sw_consumer;
604
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000605 if (nr_desc >= netxen_tx_avail(tx_ring)) {
606 netif_tx_stop_queue(tx_ring->txq);
607 __netif_tx_unlock_bh(tx_ring->txq);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000608 return -EBUSY;
609 }
610
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700611 do {
612 cmd_desc = &cmd_desc_arr[i];
613
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000614 pbuf = &tx_ring->cmd_buf_arr[producer];
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700615 pbuf->skb = NULL;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700616 pbuf->frag_count = 0;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700617
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000618 memcpy(&tx_ring->desc_head[producer],
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700619 &cmd_desc_arr[i], sizeof(struct cmd_desc_type0));
620
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000621 producer = get_next_index(producer, tx_ring->num_desc);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700622 i++;
623
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000624 } while (i != nr_desc);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700625
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000626 tx_ring->producer = producer;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700627
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000628 netxen_nic_update_cmd_producer(adapter, tx_ring);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700629
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000630 __netif_tx_unlock_bh(tx_ring->txq);
Dhananjay Phadke03e678e2009-01-14 20:49:43 -0800631
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700632 return 0;
633}
634
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000635static int
636nx_p3_sre_macaddr_change(struct netxen_adapter *adapter, u8 *addr, unsigned op)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700637{
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700638 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800639 nx_mac_req_t *mac_req;
640 u64 word;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700641
642 memset(&req, 0, sizeof(nx_nic_req_t));
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800643 req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23);
644
645 word = NX_MAC_EVENT | ((u64)adapter->portnum << 16);
646 req.req_hdr = cpu_to_le64(word);
647
648 mac_req = (nx_mac_req_t *)&req.words[0];
649 mac_req->op = op;
650 memcpy(mac_req->mac_addr, addr, 6);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700651
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000652 return netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
653}
654
655static int nx_p3_nic_add_mac(struct netxen_adapter *adapter,
656 u8 *addr, struct list_head *del_list)
657{
658 struct list_head *head;
659 nx_mac_list_t *cur;
660
661 /* look up if already exists */
662 list_for_each(head, del_list) {
663 cur = list_entry(head, nx_mac_list_t, list);
664
665 if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) {
666 list_move_tail(head, &adapter->mac_list);
667 return 0;
668 }
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700669 }
670
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000671 cur = kzalloc(sizeof(nx_mac_list_t), GFP_ATOMIC);
672 if (cur == NULL) {
673 printk(KERN_ERR "%s: failed to add mac address filter\n",
674 adapter->netdev->name);
675 return -ENOMEM;
676 }
677 memcpy(cur->mac_addr, addr, ETH_ALEN);
678 list_add_tail(&cur->list, &adapter->mac_list);
679 return nx_p3_sre_macaddr_change(adapter,
680 cur->mac_addr, NETXEN_MAC_ADD);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700681}
682
683void netxen_p3_nic_set_multi(struct net_device *netdev)
684{
685 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700686 struct dev_mc_list *mc_ptr;
687 u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700688 u32 mode = VPORT_MISS_MODE_DROP;
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000689 LIST_HEAD(del_list);
690 struct list_head *head;
691 nx_mac_list_t *cur;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700692
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000693 list_splice_tail_init(&adapter->mac_list, &del_list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700694
Narender Kumar5d09e532009-11-20 22:08:57 +0000695 nx_p3_nic_add_mac(adapter, adapter->mac_addr, &del_list);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000696 nx_p3_nic_add_mac(adapter, bcast_addr, &del_list);
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700697
698 if (netdev->flags & IFF_PROMISC) {
699 mode = VPORT_MISS_MODE_ACCEPT_ALL;
700 goto send_fw_cmd;
701 }
702
703 if ((netdev->flags & IFF_ALLMULTI) ||
704 (netdev->mc_count > adapter->max_mc_count)) {
705 mode = VPORT_MISS_MODE_ACCEPT_MULTI;
706 goto send_fw_cmd;
707 }
708
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700709 if (netdev->mc_count > 0) {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700710 for (mc_ptr = netdev->mc_list; mc_ptr;
711 mc_ptr = mc_ptr->next) {
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000712 nx_p3_nic_add_mac(adapter, mc_ptr->dmi_addr, &del_list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700713 }
714 }
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700715
716send_fw_cmd:
717 adapter->set_promisc(adapter, mode);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000718 head = &del_list;
719 while (!list_empty(head)) {
720 cur = list_entry(head->next, nx_mac_list_t, list);
721
722 nx_p3_sre_macaddr_change(adapter,
723 cur->mac_addr, NETXEN_MAC_DEL);
724 list_del(&cur->list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700725 kfree(cur);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700726 }
727}
728
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700729int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
730{
731 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800732 u64 word;
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700733
734 memset(&req, 0, sizeof(nx_nic_req_t));
735
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800736 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
737
738 word = NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE |
739 ((u64)adapter->portnum << 16);
740 req.req_hdr = cpu_to_le64(word);
741
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700742 req.words[0] = cpu_to_le64(mode);
743
744 return netxen_send_cmd_descs(adapter,
745 (struct cmd_desc_type0 *)&req, 1);
746}
747
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800748void netxen_p3_free_mac_list(struct netxen_adapter *adapter)
749{
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000750 nx_mac_list_t *cur;
751 struct list_head *head = &adapter->mac_list;
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800752
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000753 while (!list_empty(head)) {
754 cur = list_entry(head->next, nx_mac_list_t, list);
755 nx_p3_sre_macaddr_change(adapter,
756 cur->mac_addr, NETXEN_MAC_DEL);
757 list_del(&cur->list);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800758 kfree(cur);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800759 }
760}
761
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000762int netxen_p3_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr)
763{
764 /* assuming caller has already copied new addr to netdev */
765 netxen_p3_nic_set_multi(adapter->netdev);
766 return 0;
767}
768
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700769#define NETXEN_CONFIG_INTR_COALESCE 3
770
771/*
772 * Send the interrupt coalescing parameter set by ethtool to the card.
773 */
774int netxen_config_intr_coalesce(struct netxen_adapter *adapter)
775{
776 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800777 u64 word;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700778 int rv;
779
780 memset(&req, 0, sizeof(nx_nic_req_t));
781
Narender Kumar1bb482f2009-08-23 08:35:09 +0000782 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800783
784 word = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16);
785 req.req_hdr = cpu_to_le64(word);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700786
787 memcpy(&req.words[0], &adapter->coal, sizeof(adapter->coal));
788
789 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
790 if (rv != 0) {
791 printk(KERN_ERR "ERROR. Could not send "
792 "interrupt coalescing parameters\n");
793 }
794
795 return rv;
796}
797
Narender Kumar1bb482f2009-08-23 08:35:09 +0000798int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable)
799{
800 nx_nic_req_t req;
801 u64 word;
802 int rv = 0;
803
804 if ((adapter->flags & NETXEN_NIC_LRO_ENABLED) == enable)
805 return 0;
806
807 memset(&req, 0, sizeof(nx_nic_req_t));
808
809 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
810
811 word = NX_NIC_H2C_OPCODE_CONFIG_HW_LRO | ((u64)adapter->portnum << 16);
812 req.req_hdr = cpu_to_le64(word);
813
814 req.words[0] = cpu_to_le64(enable);
815
816 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
817 if (rv != 0) {
818 printk(KERN_ERR "ERROR. Could not send "
819 "configure hw lro request\n");
820 }
821
822 adapter->flags ^= NETXEN_NIC_LRO_ENABLED;
823
824 return rv;
825}
826
Narender Kumarfa3ce352009-08-24 19:23:28 +0000827int netxen_config_bridged_mode(struct netxen_adapter *adapter, int enable)
828{
829 nx_nic_req_t req;
830 u64 word;
831 int rv = 0;
832
833 if (!!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED) == enable)
834 return rv;
835
836 memset(&req, 0, sizeof(nx_nic_req_t));
837
838 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
839
840 word = NX_NIC_H2C_OPCODE_CONFIG_BRIDGING |
841 ((u64)adapter->portnum << 16);
842 req.req_hdr = cpu_to_le64(word);
843
844 req.words[0] = cpu_to_le64(enable);
845
846 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
847 if (rv != 0) {
848 printk(KERN_ERR "ERROR. Could not send "
849 "configure bridge mode request\n");
850 }
851
852 adapter->flags ^= NETXEN_NIC_BRIDGE_ENABLED;
853
854 return rv;
855}
856
857
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000858#define RSS_HASHTYPE_IP_TCP 0x3
859
860int netxen_config_rss(struct netxen_adapter *adapter, int enable)
861{
862 nx_nic_req_t req;
863 u64 word;
864 int i, rv;
865
866 u64 key[] = { 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL,
867 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
868 0x255b0ec26d5a56daULL };
869
870
871 memset(&req, 0, sizeof(nx_nic_req_t));
872 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
873
874 word = NX_NIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16);
875 req.req_hdr = cpu_to_le64(word);
876
877 /*
878 * RSS request:
879 * bits 3-0: hash_method
880 * 5-4: hash_type_ipv4
881 * 7-6: hash_type_ipv6
882 * 8: enable
883 * 9: use indirection table
884 * 47-10: reserved
885 * 63-48: indirection table mask
886 */
887 word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) |
888 ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) |
889 ((u64)(enable & 0x1) << 8) |
890 ((0x7ULL) << 48);
891 req.words[0] = cpu_to_le64(word);
892 for (i = 0; i < 5; i++)
893 req.words[i+1] = cpu_to_le64(key[i]);
894
895
896 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
897 if (rv != 0) {
898 printk(KERN_ERR "%s: could not configure RSS\n",
899 adapter->netdev->name);
900 }
901
902 return rv;
903}
904
Dhananjay Phadke6598b162009-07-26 20:07:37 +0000905int netxen_config_ipaddr(struct netxen_adapter *adapter, u32 ip, int cmd)
906{
907 nx_nic_req_t req;
908 u64 word;
909 int rv;
910
911 memset(&req, 0, sizeof(nx_nic_req_t));
912 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
913
914 word = NX_NIC_H2C_OPCODE_CONFIG_IPADDR | ((u64)adapter->portnum << 16);
915 req.req_hdr = cpu_to_le64(word);
916
917 req.words[0] = cpu_to_le64(cmd);
918 req.words[1] = cpu_to_le64(ip);
919
920 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
921 if (rv != 0) {
922 printk(KERN_ERR "%s: could not notify %s IP 0x%x reuqest\n",
923 adapter->netdev->name,
924 (cmd == NX_IP_UP) ? "Add" : "Remove", ip);
925 }
926 return rv;
927}
928
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000929int netxen_linkevent_request(struct netxen_adapter *adapter, int enable)
930{
931 nx_nic_req_t req;
932 u64 word;
933 int rv;
934
935 memset(&req, 0, sizeof(nx_nic_req_t));
936 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
937
938 word = NX_NIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16);
939 req.req_hdr = cpu_to_le64(word);
Dhananjay Phadke22527862009-05-05 19:05:06 +0000940 req.words[0] = cpu_to_le64(enable | (enable << 8));
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000941
942 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
943 if (rv != 0) {
944 printk(KERN_ERR "%s: could not configure link notification\n",
945 adapter->netdev->name);
946 }
947
948 return rv;
949}
950
Narender Kumar1bb482f2009-08-23 08:35:09 +0000951int netxen_send_lro_cleanup(struct netxen_adapter *adapter)
952{
953 nx_nic_req_t req;
954 u64 word;
955 int rv;
956
957 memset(&req, 0, sizeof(nx_nic_req_t));
958 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
959
960 word = NX_NIC_H2C_OPCODE_LRO_REQUEST |
961 ((u64)adapter->portnum << 16) |
962 ((u64)NX_NIC_LRO_REQUEST_CLEANUP << 56) ;
963
964 req.req_hdr = cpu_to_le64(word);
965
966 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
967 if (rv != 0) {
968 printk(KERN_ERR "%s: could not cleanup lro flows\n",
969 adapter->netdev->name);
970 }
971 return rv;
972}
973
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400974/*
975 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
976 * @returns 0 on success, negative on failure
977 */
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700978
979#define MTU_FUDGE_FACTOR 100
980
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400981int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
982{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700983 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700984 int max_mtu;
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700985 int rc = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400986
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700987 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
988 max_mtu = P3_MAX_MTU;
989 else
990 max_mtu = P2_MAX_MTU;
991
992 if (mtu > max_mtu) {
993 printk(KERN_ERR "%s: mtu > %d bytes unsupported\n",
994 netdev->name, max_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400995 return -EINVAL;
996 }
997
Amit S. Kale80922fb2006-12-04 09:18:00 -0800998 if (adapter->set_mtu)
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700999 rc = adapter->set_mtu(adapter, mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001000
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001001 if (!rc)
1002 netdev->mtu = mtu;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001003
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001004 return rc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001005}
1006
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001007static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
Al Virof305f782007-12-22 19:44:00 +00001008 int size, __le32 * buf)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001009{
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001010 int i, v, addr;
Al Virof305f782007-12-22 19:44:00 +00001011 __le32 *ptr32;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001012
1013 addr = base;
1014 ptr32 = buf;
1015 for (i = 0; i < size / sizeof(u32); i++) {
Al Virof305f782007-12-22 19:44:00 +00001016 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001017 return -1;
Al Virof305f782007-12-22 19:44:00 +00001018 *ptr32 = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001019 ptr32++;
1020 addr += sizeof(u32);
1021 }
1022 if ((char *)buf + size > (char *)ptr32) {
Al Virof305f782007-12-22 19:44:00 +00001023 __le32 local;
1024 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001025 return -1;
Al Virof305f782007-12-22 19:44:00 +00001026 local = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001027 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
1028 }
1029
1030 return 0;
1031}
1032
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001033int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 *mac)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001034{
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001035 __le32 *pmac = (__le32 *) mac;
1036 u32 offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001037
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001038 offset = NX_FW_MAC_ADDR_OFFSET + (adapter->portnum * sizeof(u64));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001039
1040 if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001041 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001042
Al Virof305f782007-12-22 19:44:00 +00001043 if (*mac == cpu_to_le64(~0ULL)) {
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001044
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001045 offset = NX_OLD_MAC_ADDR_OFFSET +
1046 (adapter->portnum * sizeof(u64));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001047
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001048 if (netxen_get_flash_block(adapter,
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001049 offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001050 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001051
Al Virof305f782007-12-22 19:44:00 +00001052 if (*mac == cpu_to_le64(~0ULL))
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001053 return -1;
1054 }
1055 return 0;
1056}
1057
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001058int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, __le64 *mac)
1059{
1060 uint32_t crbaddr, mac_hi, mac_lo;
1061 int pci_func = adapter->ahw.pci_func;
1062
1063 crbaddr = CRB_MAC_BLOCK_START +
1064 (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1));
1065
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001066 mac_lo = NXRD32(adapter, crbaddr);
1067 mac_hi = NXRD32(adapter, crbaddr+4);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001068
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001069 if (pci_func & 1)
Dhananjay Phadke2edbb452009-01-14 20:47:30 -08001070 *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001071 else
Dhananjay Phadke2edbb452009-01-14 20:47:30 -08001072 *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001073
1074 return 0;
1075}
1076
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001077/*
1078 * Changes the CRB window to the specified window.
1079 */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001080static void
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001081netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter,
1082 u32 window)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001083{
1084 void __iomem *offset;
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001085 int count = 10;
1086 u8 func = adapter->ahw.pci_func;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001087
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001088 if (adapter->ahw.crb_win == window)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001089 return;
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001090
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001091 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1092 NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001093
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001094 writel(window, offset);
1095 do {
1096 if (window == readl(offset))
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001097 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001098
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001099 if (printk_ratelimit())
1100 dev_warn(&adapter->pdev->dev,
1101 "failed to set CRB window to %d\n",
1102 (window == NETXEN_WINDOW_ONE));
1103 udelay(1);
1104
1105 } while (--count > 0);
1106
1107 if (count > 0)
1108 adapter->ahw.crb_win = window;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001109}
1110
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001111/*
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001112 * Returns < 0 if off is not valid,
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001113 * 1 if window access is needed. 'off' is set to offset from
1114 * CRB space in 128M pci map
1115 * 0 if no window access is needed. 'off' is set to 2M addr
1116 * In: 'off' is offset from base in 128M pci map
1117 */
1118static int
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001119netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter,
1120 ulong off, void __iomem **addr)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001121{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001122 crb_128M_2M_sub_block_map_t *m;
1123
1124
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001125 if ((off >= NETXEN_CRB_MAX) || (off < NETXEN_PCI_CRBSPACE))
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001126 return -EINVAL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001127
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001128 off -= NETXEN_PCI_CRBSPACE;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001129
1130 /*
1131 * Try direct map
1132 */
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001133 m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)];
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001134
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001135 if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) {
1136 *addr = adapter->ahw.pci_base0 + m->start_2M +
1137 (off - m->start_128M);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001138 return 0;
1139 }
1140
1141 /*
1142 * Not in direct map, use crb window
1143 */
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001144 *addr = adapter->ahw.pci_base0 + CRB_INDIRECT_2M +
1145 (off & MASK(16));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001146 return 1;
1147}
1148
1149/*
1150 * In: 'off' is offset from CRB space in 128M pci map
1151 * Out: 'off' is 2M pci map addr
1152 * side effect: lock crb window
1153 */
1154static void
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001155netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001156{
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001157 u32 window;
1158 void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001159
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001160 off -= NETXEN_PCI_CRBSPACE;
1161
1162 window = CRB_HI(off);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001163
1164 if (adapter->ahw.crb_win == window)
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001165 return;
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001166
1167 writel(window, addr);
1168 if (readl(addr) != window) {
1169 if (printk_ratelimit())
1170 dev_warn(&adapter->pdev->dev,
1171 "failed to set CRB window to %d off 0x%lx\n",
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001172 window, off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001173 }
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001174 adapter->ahw.crb_win = window;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001175}
1176
Narender Kumarf58dbd72009-12-02 15:46:18 +00001177static void __iomem *
1178netxen_nic_map_indirect_address_128M(struct netxen_adapter *adapter,
1179 ulong win_off, void __iomem **mem_ptr)
1180{
1181 ulong off = win_off;
1182 void __iomem *addr;
1183 resource_size_t mem_base;
1184
1185 if (ADDR_IN_WINDOW1(win_off))
1186 off = NETXEN_CRB_NORMAL(win_off);
1187
1188 addr = pci_base_offset(adapter, off);
1189 if (addr)
1190 return addr;
1191
1192 if (adapter->ahw.pci_len0 == 0)
1193 off -= NETXEN_PCI_CRBSPACE;
1194
1195 mem_base = pci_resource_start(adapter->pdev, 0);
1196 *mem_ptr = ioremap(mem_base + (off & PAGE_MASK), PAGE_SIZE);
1197 if (*mem_ptr)
1198 addr = *mem_ptr + (off & (PAGE_SIZE - 1));
1199
1200 return addr;
1201}
1202
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001203static int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001204netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001205{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001206 unsigned long flags;
Narender Kumarf58dbd72009-12-02 15:46:18 +00001207 void __iomem *addr, *mem_ptr = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001208
Narender Kumarf58dbd72009-12-02 15:46:18 +00001209 addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
1210 if (!addr)
1211 return -EIO;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001212
Narender Kumarf58dbd72009-12-02 15:46:18 +00001213 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001214 netxen_nic_io_write_128M(adapter, addr, data);
Narender Kumarf58dbd72009-12-02 15:46:18 +00001215 } else { /* Window 0 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001216 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001217 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001218 writel(data, addr);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001219 netxen_nic_pci_set_crbwindow_128M(adapter,
1220 NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001221 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001222 }
1223
Narender Kumarf58dbd72009-12-02 15:46:18 +00001224 if (mem_ptr)
1225 iounmap(mem_ptr);
1226
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001227 return 0;
1228}
1229
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001230static u32
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001231netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001232{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001233 unsigned long flags;
Narender Kumarf58dbd72009-12-02 15:46:18 +00001234 void __iomem *addr, *mem_ptr = NULL;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001235 u32 data;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001236
Narender Kumarf58dbd72009-12-02 15:46:18 +00001237 addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
1238 if (!addr)
1239 return -EIO;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001240
Narender Kumarf58dbd72009-12-02 15:46:18 +00001241 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001242 data = netxen_nic_io_read_128M(adapter, addr);
Narender Kumarf58dbd72009-12-02 15:46:18 +00001243 } else { /* Window 0 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001244 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001245 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001246 data = readl(addr);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001247 netxen_nic_pci_set_crbwindow_128M(adapter,
1248 NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001249 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001250 }
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001251
Narender Kumarf58dbd72009-12-02 15:46:18 +00001252 if (mem_ptr)
1253 iounmap(mem_ptr);
1254
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001255 return data;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001256}
1257
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001258static int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001259netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001260{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001261 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001262 int rv;
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001263 void __iomem *addr = NULL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001264
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001265 rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001266
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001267 if (rv == 0) {
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001268 writel(data, addr);
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001269 return 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001270 }
1271
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001272 if (rv > 0) {
1273 /* indirect access */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001274 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001275 crb_win_lock(adapter);
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001276 netxen_nic_pci_set_crbwindow_2M(adapter, off);
1277 writel(data, addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001278 crb_win_unlock(adapter);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001279 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001280 return 0;
1281 }
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001282
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001283 dev_err(&adapter->pdev->dev,
1284 "%s: invalid offset: 0x%016lx\n", __func__, off);
1285 dump_stack();
1286 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001287}
1288
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001289static u32
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001290netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001291{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001292 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001293 int rv;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001294 u32 data;
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001295 void __iomem *addr = NULL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001296
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001297 rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001298
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001299 if (rv == 0)
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001300 return readl(addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001301
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001302 if (rv > 0) {
1303 /* indirect access */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001304 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001305 crb_win_lock(adapter);
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001306 netxen_nic_pci_set_crbwindow_2M(adapter, off);
1307 data = readl(addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001308 crb_win_unlock(adapter);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001309 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001310 return data;
1311 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001312
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001313 dev_err(&adapter->pdev->dev,
1314 "%s: invalid offset: 0x%016lx\n", __func__, off);
1315 dump_stack();
1316 return -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001317}
1318
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001319/* window 1 registers only */
1320static void netxen_nic_io_write_128M(struct netxen_adapter *adapter,
1321 void __iomem *addr, u32 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001322{
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001323 read_lock(&adapter->ahw.crb_lock);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001324 writel(data, addr);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001325 read_unlock(&adapter->ahw.crb_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001326}
1327
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001328static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter,
1329 void __iomem *addr)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001330{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001331 u32 val;
1332
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001333 read_lock(&adapter->ahw.crb_lock);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001334 val = readl(addr);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001335 read_unlock(&adapter->ahw.crb_lock);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001336
1337 return val;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001338}
1339
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001340static void netxen_nic_io_write_2M(struct netxen_adapter *adapter,
1341 void __iomem *addr, u32 data)
1342{
1343 writel(data, addr);
1344}
1345
1346static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter,
1347 void __iomem *addr)
1348{
1349 return readl(addr);
1350}
1351
1352void __iomem *
1353netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset)
1354{
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001355 void __iomem *addr = NULL;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001356
1357 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001358 if ((offset < NETXEN_CRB_PCIX_HOST2) &&
1359 (offset > NETXEN_CRB_PCIX_HOST))
1360 addr = PCI_OFFSET_SECOND_RANGE(adapter, offset);
1361 else
1362 addr = NETXEN_CRB_NORMALIZE(adapter, offset);
1363 } else {
1364 WARN_ON(netxen_nic_pci_get_crb_addr_2M(adapter,
1365 offset, &addr));
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001366 }
1367
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001368 return addr;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001369}
1370
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001371static int
1372netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
1373 u64 addr, u32 *start)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001374{
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001375 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1376 *start = (addr - NETXEN_ADDR_OCM0 + NETXEN_PCI_OCM0);
1377 return 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001378 } else if (ADDR_IN_RANGE(addr,
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001379 NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1380 *start = (addr - NETXEN_ADDR_OCM1 + NETXEN_PCI_OCM1);
1381 return 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001382 }
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001383
1384 return -EIO;
1385}
1386
1387static int
1388netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
1389 u64 addr, u32 *start)
1390{
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +00001391 u32 window;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001392 struct pci_dev *pdev = adapter->pdev;
1393
1394 if ((addr & 0x00ff800) == 0xff800) {
1395 if (printk_ratelimit())
1396 dev_warn(&pdev->dev, "QM access not handled\n");
1397 return -EIO;
1398 }
1399
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +00001400 if (NX_IS_REVISION_P3P(adapter->ahw.revision_id))
1401 window = OCM_WIN_P3P(addr);
1402 else
1403 window = OCM_WIN(addr);
1404
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001405 writel(window, adapter->ahw.ocm_win_crb);
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +00001406 /* read back to flush */
1407 readl(adapter->ahw.ocm_win_crb);
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001408
1409 adapter->ahw.ocm_win = window;
1410 *start = NETXEN_PCI_OCM0_2M + GET_MEM_OFFS_2M(addr);
1411 return 0;
1412}
1413
1414static int
1415netxen_nic_pci_mem_access_direct(struct netxen_adapter *adapter, u64 off,
1416 u64 *data, int op)
1417{
1418 void __iomem *addr, *mem_ptr = NULL;
1419 resource_size_t mem_base;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001420 int ret = -EIO;
1421 u32 start;
1422
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001423 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001424
1425 ret = adapter->pci_set_window(adapter, off, &start);
1426 if (ret != 0)
1427 goto unlock;
1428
1429 addr = pci_base_offset(adapter, start);
1430 if (addr)
1431 goto noremap;
1432
1433 mem_base = pci_resource_start(adapter->pdev, 0) + (start & PAGE_MASK);
1434
1435 mem_ptr = ioremap(mem_base, PAGE_SIZE);
1436 if (mem_ptr == NULL) {
1437 ret = -EIO;
1438 goto unlock;
1439 }
1440
1441 addr = mem_ptr + (start & (PAGE_SIZE - 1));
1442
1443noremap:
1444 if (op == 0) /* read */
1445 *data = readq(addr);
1446 else /* write */
1447 writeq(*data, addr);
1448
1449unlock:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001450 spin_unlock(&adapter->ahw.mem_lock);
1451
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001452 if (mem_ptr)
1453 iounmap(mem_ptr);
1454 return ret;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001455}
1456
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001457#define MAX_CTL_CHECK 1000
1458
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001459static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001460netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001461 u64 off, u64 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001462{
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001463 int j, ret;
1464 u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001465 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001466
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001467 /* Only 64-bit aligned access */
1468 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001469 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001470
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001471 /* P2 has different SIU and MIU test agent base addr */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001472 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1473 NETXEN_ADDR_QDR_NET_MAX_P2)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001474 mem_crb = pci_base_offset(adapter,
1475 NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
1476 addr_hi = SIU_TEST_AGT_ADDR_HI;
1477 data_lo = SIU_TEST_AGT_WRDATA_LO;
1478 data_hi = SIU_TEST_AGT_WRDATA_HI;
1479 off_lo = off & SIU_TEST_AGT_ADDR_MASK;
1480 off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001481 goto correct;
1482 }
1483
1484 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001485 mem_crb = pci_base_offset(adapter,
1486 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
1487 addr_hi = MIU_TEST_AGT_ADDR_HI;
1488 data_lo = MIU_TEST_AGT_WRDATA_LO;
1489 data_hi = MIU_TEST_AGT_WRDATA_HI;
1490 off_lo = off & MIU_TEST_AGT_ADDR_MASK;
1491 off_hi = 0;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001492 goto correct;
1493 }
1494
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001495 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
1496 ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1497 if (adapter->ahw.pci_len0 != 0) {
1498 return netxen_nic_pci_mem_access_direct(adapter,
1499 off, &data, 1);
1500 }
1501 }
1502
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001503 return -EIO;
1504
1505correct:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001506 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001507 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001508
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001509 writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1510 writel(off_hi, (mem_crb + addr_hi));
1511 writel(data & 0xffffffff, (mem_crb + data_lo));
1512 writel((data >> 32) & 0xffffffff, (mem_crb + data_hi));
1513 writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
1514 writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
1515 (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001516
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001517 for (j = 0; j < MAX_CTL_CHECK; j++) {
1518 temp = readl((mem_crb + TEST_AGT_CTRL));
1519 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001520 break;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001521 }
1522
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001523 if (j >= MAX_CTL_CHECK) {
1524 if (printk_ratelimit())
1525 dev_err(&adapter->pdev->dev,
1526 "failed to write through agent\n");
1527 ret = -EIO;
1528 } else
1529 ret = 0;
1530
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001531 netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001532 spin_unlock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001533 return ret;
1534}
1535
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001536static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001537netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001538 u64 off, u64 *data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001539{
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001540 int j, ret;
1541 u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
1542 u64 val;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001543 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001544
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001545 /* Only 64-bit aligned access */
1546 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001547 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001548
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001549 /* P2 has different SIU and MIU test agent base addr */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001550 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1551 NETXEN_ADDR_QDR_NET_MAX_P2)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001552 mem_crb = pci_base_offset(adapter,
1553 NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
1554 addr_hi = SIU_TEST_AGT_ADDR_HI;
1555 data_lo = SIU_TEST_AGT_RDDATA_LO;
1556 data_hi = SIU_TEST_AGT_RDDATA_HI;
1557 off_lo = off & SIU_TEST_AGT_ADDR_MASK;
1558 off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001559 goto correct;
1560 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001561
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001562 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001563 mem_crb = pci_base_offset(adapter,
1564 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
1565 addr_hi = MIU_TEST_AGT_ADDR_HI;
1566 data_lo = MIU_TEST_AGT_RDDATA_LO;
1567 data_hi = MIU_TEST_AGT_RDDATA_HI;
1568 off_lo = off & MIU_TEST_AGT_ADDR_MASK;
1569 off_hi = 0;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001570 goto correct;
1571 }
1572
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001573 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
1574 ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1575 if (adapter->ahw.pci_len0 != 0) {
1576 return netxen_nic_pci_mem_access_direct(adapter,
1577 off, data, 0);
1578 }
1579 }
1580
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001581 return -EIO;
1582
1583correct:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001584 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001585 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001586
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001587 writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1588 writel(off_hi, (mem_crb + addr_hi));
1589 writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
1590 writel((TA_CTL_START|TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001591
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001592 for (j = 0; j < MAX_CTL_CHECK; j++) {
1593 temp = readl(mem_crb + TEST_AGT_CTRL);
1594 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001595 break;
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001596 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001597
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001598 if (j >= MAX_CTL_CHECK) {
1599 if (printk_ratelimit())
1600 dev_err(&adapter->pdev->dev,
1601 "failed to read through agent\n");
1602 ret = -EIO;
1603 } else {
1604
1605 temp = readl(mem_crb + data_hi);
1606 val = ((u64)temp << 32);
1607 val |= readl(mem_crb + data_lo);
1608 *data = val;
1609 ret = 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001610 }
1611
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001612 netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001613 spin_unlock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001614
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001615 return ret;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001616}
1617
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001618static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001619netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001620 u64 off, u64 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001621{
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001622 int i, j, ret;
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001623 u32 temp, off8;
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001624 u64 stride;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001625 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001626
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001627 /* Only 64-bit aligned access */
1628 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001629 return -EIO;
1630
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001631 /* P3 onward, test agent base for MIU and SIU is same */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001632 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1633 NETXEN_ADDR_QDR_NET_MAX_P3)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001634 mem_crb = netxen_get_ioaddr(adapter,
1635 NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001636 goto correct;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001637 }
1638
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001639 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001640 mem_crb = netxen_get_ioaddr(adapter,
1641 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001642 goto correct;
1643 }
1644
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001645 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX))
1646 return netxen_nic_pci_mem_access_direct(adapter, off, &data, 1);
1647
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001648 return -EIO;
1649
1650correct:
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001651 stride = NX_IS_REVISION_P3P(adapter->ahw.revision_id) ? 16 : 8;
1652
1653 off8 = off & ~(stride-1);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001654
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001655 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001656
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001657 writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1658 writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001659
1660 i = 0;
1661 if (stride == 16) {
1662 writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
1663 writel((TA_CTL_START | TA_CTL_ENABLE),
1664 (mem_crb + TEST_AGT_CTRL));
1665
1666 for (j = 0; j < MAX_CTL_CHECK; j++) {
1667 temp = readl(mem_crb + TEST_AGT_CTRL);
1668 if ((temp & TA_CTL_BUSY) == 0)
1669 break;
1670 }
1671
1672 if (j >= MAX_CTL_CHECK) {
1673 ret = -EIO;
1674 goto done;
1675 }
1676
1677 i = (off & 0xf) ? 0 : 2;
1678 writel(readl(mem_crb + MIU_TEST_AGT_RDDATA(i)),
1679 mem_crb + MIU_TEST_AGT_WRDATA(i));
1680 writel(readl(mem_crb + MIU_TEST_AGT_RDDATA(i+1)),
1681 mem_crb + MIU_TEST_AGT_WRDATA(i+1));
1682 i = (off & 0xf) ? 2 : 0;
1683 }
1684
1685 writel(data & 0xffffffff,
1686 mem_crb + MIU_TEST_AGT_WRDATA(i));
1687 writel((data >> 32) & 0xffffffff,
1688 mem_crb + MIU_TEST_AGT_WRDATA(i+1));
1689
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001690 writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
1691 writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
1692 (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001693
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001694 for (j = 0; j < MAX_CTL_CHECK; j++) {
1695 temp = readl(mem_crb + TEST_AGT_CTRL);
1696 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001697 break;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001698 }
1699
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001700 if (j >= MAX_CTL_CHECK) {
1701 if (printk_ratelimit())
1702 dev_err(&adapter->pdev->dev,
1703 "failed to write through agent\n");
1704 ret = -EIO;
1705 } else
1706 ret = 0;
1707
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001708done:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001709 spin_unlock(&adapter->ahw.mem_lock);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001710
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001711 return ret;
1712}
1713
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001714static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001715netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001716 u64 off, u64 *data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001717{
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001718 int j, ret;
1719 u32 temp, off8;
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001720 u64 val, stride;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001721 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001722
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001723 /* Only 64-bit aligned access */
1724 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001725 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001726
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001727 /* P3 onward, test agent base for MIU and SIU is same */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001728 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1729 NETXEN_ADDR_QDR_NET_MAX_P3)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001730 mem_crb = netxen_get_ioaddr(adapter,
1731 NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001732 goto correct;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001733 }
1734
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001735 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001736 mem_crb = netxen_get_ioaddr(adapter,
1737 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001738 goto correct;
1739 }
1740
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001741 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1742 return netxen_nic_pci_mem_access_direct(adapter,
1743 off, data, 0);
1744 }
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001745
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001746 return -EIO;
1747
1748correct:
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001749 stride = NX_IS_REVISION_P3P(adapter->ahw.revision_id) ? 16 : 8;
1750
1751 off8 = off & ~(stride-1);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001752
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001753 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001754
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001755 writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1756 writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
1757 writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
1758 writel((TA_CTL_START | TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001759
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001760 for (j = 0; j < MAX_CTL_CHECK; j++) {
1761 temp = readl(mem_crb + TEST_AGT_CTRL);
1762 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001763 break;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001764 }
1765
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001766 if (j >= MAX_CTL_CHECK) {
1767 if (printk_ratelimit())
1768 dev_err(&adapter->pdev->dev,
1769 "failed to read through agent\n");
1770 ret = -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001771 } else {
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001772 off8 = MIU_TEST_AGT_RDDATA_LO;
1773 if ((stride == 16) && (off & 0xf))
1774 off8 = MIU_TEST_AGT_RDDATA_UPPER_LO;
1775
1776 temp = readl(mem_crb + off8 + 4);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001777 val = (u64)temp << 32;
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001778 val |= readl(mem_crb + off8);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001779 *data = val;
1780 ret = 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001781 }
1782
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001783 spin_unlock(&adapter->ahw.mem_lock);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001784
1785 return ret;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001786}
1787
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001788void
1789netxen_setup_hwops(struct netxen_adapter *adapter)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001790{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001791 adapter->init_port = netxen_niu_xg_init_port;
1792 adapter->stop_port = netxen_niu_disable_xg_port;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001793
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001794 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1795 adapter->crb_read = netxen_nic_hw_read_wx_128M,
1796 adapter->crb_write = netxen_nic_hw_write_wx_128M,
1797 adapter->pci_set_window = netxen_nic_pci_set_window_128M,
1798 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M,
1799 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M,
1800 adapter->io_read = netxen_nic_io_read_128M,
1801 adapter->io_write = netxen_nic_io_write_128M,
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001802
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001803 adapter->macaddr_set = netxen_p2_nic_set_mac_addr;
1804 adapter->set_multi = netxen_p2_nic_set_multi;
1805 adapter->set_mtu = netxen_nic_set_mtu_xgb;
1806 adapter->set_promisc = netxen_p2_nic_set_promisc;
1807
1808 } else {
1809 adapter->crb_read = netxen_nic_hw_read_wx_2M,
1810 adapter->crb_write = netxen_nic_hw_write_wx_2M,
1811 adapter->pci_set_window = netxen_nic_pci_set_window_2M,
1812 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M,
1813 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M,
1814 adapter->io_read = netxen_nic_io_read_2M,
1815 adapter->io_write = netxen_nic_io_write_2M,
1816
1817 adapter->set_mtu = nx_fw_cmd_set_mtu;
1818 adapter->set_promisc = netxen_p3_nic_set_promisc;
1819 adapter->macaddr_set = netxen_p3_nic_set_mac_addr;
1820 adapter->set_multi = netxen_p3_nic_set_multi;
1821
1822 adapter->phy_read = nx_fw_cmd_query_phy;
1823 adapter->phy_write = nx_fw_cmd_set_phy;
1824 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001825}
1826
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001827int netxen_nic_get_board_info(struct netxen_adapter *adapter)
1828{
Dhananjay Phadke0dc6d9c2009-10-21 19:39:03 +00001829 int offset, board_type, magic;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001830 struct pci_dev *pdev = adapter->pdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001831
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001832 offset = NX_FW_MAGIC_OFFSET;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001833 if (netxen_rom_fast_read(adapter, offset, &magic))
1834 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001835
Dhananjay Phadke0dc6d9c2009-10-21 19:39:03 +00001836 if (magic != NETXEN_BDINFO_MAGIC) {
1837 dev_err(&pdev->dev, "invalid board config, magic=%08x\n",
1838 magic);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001839 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001840 }
1841
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001842 offset = NX_BRDTYPE_OFFSET;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001843 if (netxen_rom_fast_read(adapter, offset, &board_type))
1844 return -EIO;
1845
1846 adapter->ahw.board_type = board_type;
1847
1848 if (board_type == NETXEN_BRDTYPE_P3_4_GB_MM) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001849 u32 gpio = NXRD32(adapter, NETXEN_ROMUSB_GLB_PAD_GPIO_I);
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001850 if ((gpio & 0x8000) == 0)
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001851 board_type = NETXEN_BRDTYPE_P3_10G_TP;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001852 }
1853
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00001854 switch (board_type) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001855 case NETXEN_BRDTYPE_P2_SB35_4G:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001856 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001857 break;
1858 case NETXEN_BRDTYPE_P2_SB31_10G:
1859 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1860 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1861 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001862 case NETXEN_BRDTYPE_P3_HMEZ:
1863 case NETXEN_BRDTYPE_P3_XG_LOM:
1864 case NETXEN_BRDTYPE_P3_10G_CX4:
1865 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
1866 case NETXEN_BRDTYPE_P3_IMEZ:
1867 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
Dhananjay Phadkea70f9392008-08-01 03:14:56 -07001868 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
1869 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001870 case NETXEN_BRDTYPE_P3_10G_XFP:
1871 case NETXEN_BRDTYPE_P3_10000_BASE_T:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001872 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001873 break;
1874 case NETXEN_BRDTYPE_P1_BD:
1875 case NETXEN_BRDTYPE_P1_SB:
1876 case NETXEN_BRDTYPE_P1_SMAX:
1877 case NETXEN_BRDTYPE_P1_SOCK:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001878 case NETXEN_BRDTYPE_P3_REF_QG:
1879 case NETXEN_BRDTYPE_P3_4_GB:
1880 case NETXEN_BRDTYPE_P3_4_GB_MM:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001881 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001882 break;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001883 case NETXEN_BRDTYPE_P3_10G_TP:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001884 adapter->ahw.port_type = (adapter->portnum < 2) ?
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001885 NETXEN_NIC_XGBE : NETXEN_NIC_GBE;
1886 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001887 default:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001888 dev_err(&pdev->dev, "unknown board type %x\n", board_type);
1889 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001890 break;
1891 }
1892
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001893 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001894}
1895
1896/* NIU access sections */
1897
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001898int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001899{
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001900 new_mtu += MTU_FUDGE_FACTOR;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001901 NXWR32(adapter, NETXEN_NIU_GB_MAX_FRAME_SIZE(adapter->physical_port),
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07001902 new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001903 return 0;
1904}
1905
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001906int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001907{
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001908 new_mtu += MTU_FUDGE_FACTOR;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07001909 if (adapter->physical_port == 0)
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001910 NXWR32(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu);
Jeff Garzik47906542007-11-23 21:23:36 -05001911 else
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001912 NXWR32(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001913 return 0;
1914}
1915
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001916void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001917{
Al Viroa608ab9c2007-01-02 10:39:10 +00001918 __u32 status;
1919 __u32 autoneg;
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001920 __u32 port_mode;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001921
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001922 if (!netif_carrier_ok(adapter->netdev)) {
1923 adapter->link_speed = 0;
1924 adapter->link_duplex = -1;
1925 adapter->link_autoneg = AUTONEG_ENABLE;
1926 return;
1927 }
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001928
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001929 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001930 port_mode = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001931 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
1932 adapter->link_speed = SPEED_1000;
1933 adapter->link_duplex = DUPLEX_FULL;
1934 adapter->link_autoneg = AUTONEG_DISABLE;
1935 return;
1936 }
1937
Joe Perches8e95a202009-12-03 07:58:21 +00001938 if (adapter->phy_read &&
1939 adapter->phy_read(adapter,
1940 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
1941 &status) == 0) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001942 if (netxen_get_phy_link(status)) {
1943 switch (netxen_get_phy_speed(status)) {
1944 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001945 adapter->link_speed = SPEED_10;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001946 break;
1947 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001948 adapter->link_speed = SPEED_100;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001949 break;
1950 case 2:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001951 adapter->link_speed = SPEED_1000;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001952 break;
1953 default:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001954 adapter->link_speed = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001955 break;
1956 }
1957 switch (netxen_get_phy_duplex(status)) {
1958 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001959 adapter->link_duplex = DUPLEX_HALF;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001960 break;
1961 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001962 adapter->link_duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001963 break;
1964 default:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001965 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001966 break;
1967 }
Joe Perches8e95a202009-12-03 07:58:21 +00001968 if (adapter->phy_read &&
1969 adapter->phy_read(adapter,
1970 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
1971 &autoneg) != 0)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001972 adapter->link_autoneg = autoneg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001973 } else
1974 goto link_down;
1975 } else {
1976 link_down:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001977 adapter->link_speed = 0;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001978 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001979 }
1980 }
1981}
1982
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001983int
1984netxen_nic_wol_supported(struct netxen_adapter *adapter)
1985{
1986 u32 wol_cfg;
1987
1988 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
1989 return 0;
1990
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001991 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001992 if (wol_cfg & (1UL << adapter->portnum)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001993 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001994 if (wol_cfg & (1 << adapter->portnum))
1995 return 1;
1996 }
1997
1998 return 0;
1999}