blob: 9548e59673991af2a0604a3238fdbca113e19142 [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
Amit Kumar Salechad49c9642010-01-07 22:10:16 +0000693 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
694 return;
695
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000696 list_splice_tail_init(&adapter->mac_list, &del_list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700697
Narender Kumar5d09e532009-11-20 22:08:57 +0000698 nx_p3_nic_add_mac(adapter, adapter->mac_addr, &del_list);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000699 nx_p3_nic_add_mac(adapter, bcast_addr, &del_list);
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700700
701 if (netdev->flags & IFF_PROMISC) {
702 mode = VPORT_MISS_MODE_ACCEPT_ALL;
703 goto send_fw_cmd;
704 }
705
706 if ((netdev->flags & IFF_ALLMULTI) ||
707 (netdev->mc_count > adapter->max_mc_count)) {
708 mode = VPORT_MISS_MODE_ACCEPT_MULTI;
709 goto send_fw_cmd;
710 }
711
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700712 if (netdev->mc_count > 0) {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700713 for (mc_ptr = netdev->mc_list; mc_ptr;
714 mc_ptr = mc_ptr->next) {
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000715 nx_p3_nic_add_mac(adapter, mc_ptr->dmi_addr, &del_list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700716 }
717 }
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700718
719send_fw_cmd:
720 adapter->set_promisc(adapter, mode);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000721 head = &del_list;
722 while (!list_empty(head)) {
723 cur = list_entry(head->next, nx_mac_list_t, list);
724
725 nx_p3_sre_macaddr_change(adapter,
726 cur->mac_addr, NETXEN_MAC_DEL);
727 list_del(&cur->list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700728 kfree(cur);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700729 }
730}
731
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700732int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
733{
734 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800735 u64 word;
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700736
737 memset(&req, 0, sizeof(nx_nic_req_t));
738
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800739 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
740
741 word = NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE |
742 ((u64)adapter->portnum << 16);
743 req.req_hdr = cpu_to_le64(word);
744
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700745 req.words[0] = cpu_to_le64(mode);
746
747 return netxen_send_cmd_descs(adapter,
748 (struct cmd_desc_type0 *)&req, 1);
749}
750
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800751void netxen_p3_free_mac_list(struct netxen_adapter *adapter)
752{
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000753 nx_mac_list_t *cur;
754 struct list_head *head = &adapter->mac_list;
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800755
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000756 while (!list_empty(head)) {
757 cur = list_entry(head->next, nx_mac_list_t, list);
758 nx_p3_sre_macaddr_change(adapter,
759 cur->mac_addr, NETXEN_MAC_DEL);
760 list_del(&cur->list);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800761 kfree(cur);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800762 }
763}
764
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000765int netxen_p3_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr)
766{
767 /* assuming caller has already copied new addr to netdev */
768 netxen_p3_nic_set_multi(adapter->netdev);
769 return 0;
770}
771
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700772#define NETXEN_CONFIG_INTR_COALESCE 3
773
774/*
775 * Send the interrupt coalescing parameter set by ethtool to the card.
776 */
777int netxen_config_intr_coalesce(struct netxen_adapter *adapter)
778{
779 nx_nic_req_t req;
Amit Kumar Salechac0703952010-01-14 01:53:22 +0000780 u64 word[6];
781 int rv, i;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700782
783 memset(&req, 0, sizeof(nx_nic_req_t));
Amit Kumar Salechac0703952010-01-14 01:53:22 +0000784 memset(word, 0, sizeof(word));
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700785
Narender Kumar1bb482f2009-08-23 08:35:09 +0000786 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800787
Amit Kumar Salechac0703952010-01-14 01:53:22 +0000788 word[0] = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16);
789 req.req_hdr = cpu_to_le64(word[0]);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700790
Amit Kumar Salechac0703952010-01-14 01:53:22 +0000791 memcpy(&word[0], &adapter->coal, sizeof(adapter->coal));
792 for (i = 0; i < 6; i++)
793 req.words[i] = cpu_to_le64(word[i]);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700794
795 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
796 if (rv != 0) {
797 printk(KERN_ERR "ERROR. Could not send "
798 "interrupt coalescing parameters\n");
799 }
800
801 return rv;
802}
803
Narender Kumar1bb482f2009-08-23 08:35:09 +0000804int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable)
805{
806 nx_nic_req_t req;
807 u64 word;
808 int rv = 0;
809
810 if ((adapter->flags & NETXEN_NIC_LRO_ENABLED) == enable)
811 return 0;
812
813 memset(&req, 0, sizeof(nx_nic_req_t));
814
815 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
816
817 word = NX_NIC_H2C_OPCODE_CONFIG_HW_LRO | ((u64)adapter->portnum << 16);
818 req.req_hdr = cpu_to_le64(word);
819
820 req.words[0] = cpu_to_le64(enable);
821
822 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
823 if (rv != 0) {
824 printk(KERN_ERR "ERROR. Could not send "
825 "configure hw lro request\n");
826 }
827
828 adapter->flags ^= NETXEN_NIC_LRO_ENABLED;
829
830 return rv;
831}
832
Narender Kumarfa3ce352009-08-24 19:23:28 +0000833int netxen_config_bridged_mode(struct netxen_adapter *adapter, int enable)
834{
835 nx_nic_req_t req;
836 u64 word;
837 int rv = 0;
838
839 if (!!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED) == enable)
840 return rv;
841
842 memset(&req, 0, sizeof(nx_nic_req_t));
843
844 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
845
846 word = NX_NIC_H2C_OPCODE_CONFIG_BRIDGING |
847 ((u64)adapter->portnum << 16);
848 req.req_hdr = cpu_to_le64(word);
849
850 req.words[0] = cpu_to_le64(enable);
851
852 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
853 if (rv != 0) {
854 printk(KERN_ERR "ERROR. Could not send "
855 "configure bridge mode request\n");
856 }
857
858 adapter->flags ^= NETXEN_NIC_BRIDGE_ENABLED;
859
860 return rv;
861}
862
863
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000864#define RSS_HASHTYPE_IP_TCP 0x3
865
866int netxen_config_rss(struct netxen_adapter *adapter, int enable)
867{
868 nx_nic_req_t req;
869 u64 word;
870 int i, rv;
871
872 u64 key[] = { 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL,
873 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
874 0x255b0ec26d5a56daULL };
875
876
877 memset(&req, 0, sizeof(nx_nic_req_t));
878 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
879
880 word = NX_NIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16);
881 req.req_hdr = cpu_to_le64(word);
882
883 /*
884 * RSS request:
885 * bits 3-0: hash_method
886 * 5-4: hash_type_ipv4
887 * 7-6: hash_type_ipv6
888 * 8: enable
889 * 9: use indirection table
890 * 47-10: reserved
891 * 63-48: indirection table mask
892 */
893 word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) |
894 ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) |
895 ((u64)(enable & 0x1) << 8) |
896 ((0x7ULL) << 48);
897 req.words[0] = cpu_to_le64(word);
898 for (i = 0; i < 5; i++)
899 req.words[i+1] = cpu_to_le64(key[i]);
900
901
902 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
903 if (rv != 0) {
904 printk(KERN_ERR "%s: could not configure RSS\n",
905 adapter->netdev->name);
906 }
907
908 return rv;
909}
910
Dhananjay Phadke6598b162009-07-26 20:07:37 +0000911int netxen_config_ipaddr(struct netxen_adapter *adapter, u32 ip, int cmd)
912{
913 nx_nic_req_t req;
914 u64 word;
915 int rv;
916
917 memset(&req, 0, sizeof(nx_nic_req_t));
918 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
919
920 word = NX_NIC_H2C_OPCODE_CONFIG_IPADDR | ((u64)adapter->portnum << 16);
921 req.req_hdr = cpu_to_le64(word);
922
923 req.words[0] = cpu_to_le64(cmd);
924 req.words[1] = cpu_to_le64(ip);
925
926 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
927 if (rv != 0) {
928 printk(KERN_ERR "%s: could not notify %s IP 0x%x reuqest\n",
929 adapter->netdev->name,
930 (cmd == NX_IP_UP) ? "Add" : "Remove", ip);
931 }
932 return rv;
933}
934
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000935int netxen_linkevent_request(struct netxen_adapter *adapter, int enable)
936{
937 nx_nic_req_t req;
938 u64 word;
939 int rv;
940
941 memset(&req, 0, sizeof(nx_nic_req_t));
942 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
943
944 word = NX_NIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16);
945 req.req_hdr = cpu_to_le64(word);
Dhananjay Phadke22527862009-05-05 19:05:06 +0000946 req.words[0] = cpu_to_le64(enable | (enable << 8));
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000947
948 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
949 if (rv != 0) {
950 printk(KERN_ERR "%s: could not configure link notification\n",
951 adapter->netdev->name);
952 }
953
954 return rv;
955}
956
Narender Kumar1bb482f2009-08-23 08:35:09 +0000957int netxen_send_lro_cleanup(struct netxen_adapter *adapter)
958{
959 nx_nic_req_t req;
960 u64 word;
961 int rv;
962
963 memset(&req, 0, sizeof(nx_nic_req_t));
964 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
965
966 word = NX_NIC_H2C_OPCODE_LRO_REQUEST |
967 ((u64)adapter->portnum << 16) |
968 ((u64)NX_NIC_LRO_REQUEST_CLEANUP << 56) ;
969
970 req.req_hdr = cpu_to_le64(word);
971
972 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
973 if (rv != 0) {
974 printk(KERN_ERR "%s: could not cleanup lro flows\n",
975 adapter->netdev->name);
976 }
977 return rv;
978}
979
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400980/*
981 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
982 * @returns 0 on success, negative on failure
983 */
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700984
985#define MTU_FUDGE_FACTOR 100
986
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400987int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
988{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700989 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700990 int max_mtu;
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700991 int rc = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400992
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700993 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
994 max_mtu = P3_MAX_MTU;
995 else
996 max_mtu = P2_MAX_MTU;
997
998 if (mtu > max_mtu) {
999 printk(KERN_ERR "%s: mtu > %d bytes unsupported\n",
1000 netdev->name, max_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001001 return -EINVAL;
1002 }
1003
Amit S. Kale80922fb2006-12-04 09:18:00 -08001004 if (adapter->set_mtu)
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001005 rc = adapter->set_mtu(adapter, mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001006
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001007 if (!rc)
1008 netdev->mtu = mtu;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001009
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001010 return rc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001011}
1012
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001013static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
Al Virof305f782007-12-22 19:44:00 +00001014 int size, __le32 * buf)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001015{
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001016 int i, v, addr;
Al Virof305f782007-12-22 19:44:00 +00001017 __le32 *ptr32;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001018
1019 addr = base;
1020 ptr32 = buf;
1021 for (i = 0; i < size / sizeof(u32); i++) {
Al Virof305f782007-12-22 19:44:00 +00001022 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001023 return -1;
Al Virof305f782007-12-22 19:44:00 +00001024 *ptr32 = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001025 ptr32++;
1026 addr += sizeof(u32);
1027 }
1028 if ((char *)buf + size > (char *)ptr32) {
Al Virof305f782007-12-22 19:44:00 +00001029 __le32 local;
1030 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001031 return -1;
Al Virof305f782007-12-22 19:44:00 +00001032 local = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001033 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
1034 }
1035
1036 return 0;
1037}
1038
Amit Kumar Salechaa03d2452010-01-14 01:53:21 +00001039int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 *mac)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001040{
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001041 __le32 *pmac = (__le32 *) mac;
1042 u32 offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001043
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001044 offset = NX_FW_MAC_ADDR_OFFSET + (adapter->portnum * sizeof(u64));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001045
1046 if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001047 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001048
Al Virof305f782007-12-22 19:44:00 +00001049 if (*mac == cpu_to_le64(~0ULL)) {
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001050
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001051 offset = NX_OLD_MAC_ADDR_OFFSET +
1052 (adapter->portnum * sizeof(u64));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001053
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001054 if (netxen_get_flash_block(adapter,
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001055 offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001056 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001057
Al Virof305f782007-12-22 19:44:00 +00001058 if (*mac == cpu_to_le64(~0ULL))
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001059 return -1;
1060 }
1061 return 0;
1062}
1063
Amit Kumar Salechaa03d2452010-01-14 01:53:21 +00001064int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, u64 *mac)
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001065{
1066 uint32_t crbaddr, mac_hi, mac_lo;
1067 int pci_func = adapter->ahw.pci_func;
1068
1069 crbaddr = CRB_MAC_BLOCK_START +
1070 (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1));
1071
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001072 mac_lo = NXRD32(adapter, crbaddr);
1073 mac_hi = NXRD32(adapter, crbaddr+4);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001074
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001075 if (pci_func & 1)
Dhananjay Phadke2edbb452009-01-14 20:47:30 -08001076 *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001077 else
Dhananjay Phadke2edbb452009-01-14 20:47:30 -08001078 *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001079
1080 return 0;
1081}
1082
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001083/*
1084 * Changes the CRB window to the specified window.
1085 */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001086static void
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001087netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter,
1088 u32 window)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001089{
1090 void __iomem *offset;
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001091 int count = 10;
1092 u8 func = adapter->ahw.pci_func;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001093
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001094 if (adapter->ahw.crb_win == window)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001095 return;
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001096
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001097 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1098 NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001099
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001100 writel(window, offset);
1101 do {
1102 if (window == readl(offset))
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001103 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001104
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001105 if (printk_ratelimit())
1106 dev_warn(&adapter->pdev->dev,
1107 "failed to set CRB window to %d\n",
1108 (window == NETXEN_WINDOW_ONE));
1109 udelay(1);
1110
1111 } while (--count > 0);
1112
1113 if (count > 0)
1114 adapter->ahw.crb_win = window;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001115}
1116
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001117/*
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001118 * Returns < 0 if off is not valid,
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001119 * 1 if window access is needed. 'off' is set to offset from
1120 * CRB space in 128M pci map
1121 * 0 if no window access is needed. 'off' is set to 2M addr
1122 * In: 'off' is offset from base in 128M pci map
1123 */
1124static int
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001125netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter,
1126 ulong off, void __iomem **addr)
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
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001131 if ((off >= NETXEN_CRB_MAX) || (off < NETXEN_PCI_CRBSPACE))
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001132 return -EINVAL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001133
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001134 off -= NETXEN_PCI_CRBSPACE;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001135
1136 /*
1137 * Try direct map
1138 */
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001139 m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)];
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001140
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001141 if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) {
1142 *addr = adapter->ahw.pci_base0 + m->start_2M +
1143 (off - m->start_128M);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001144 return 0;
1145 }
1146
1147 /*
1148 * Not in direct map, use crb window
1149 */
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001150 *addr = adapter->ahw.pci_base0 + CRB_INDIRECT_2M +
1151 (off & MASK(16));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001152 return 1;
1153}
1154
1155/*
1156 * In: 'off' is offset from CRB space in 128M pci map
1157 * Out: 'off' is 2M pci map addr
1158 * side effect: lock crb window
1159 */
1160static void
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001161netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001162{
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001163 u32 window;
1164 void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001165
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001166 off -= NETXEN_PCI_CRBSPACE;
1167
1168 window = CRB_HI(off);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001169
1170 if (adapter->ahw.crb_win == window)
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001171 return;
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001172
1173 writel(window, addr);
1174 if (readl(addr) != window) {
1175 if (printk_ratelimit())
1176 dev_warn(&adapter->pdev->dev,
1177 "failed to set CRB window to %d off 0x%lx\n",
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001178 window, off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001179 }
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001180 adapter->ahw.crb_win = window;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001181}
1182
Narender Kumarf58dbd72009-12-02 15:46:18 +00001183static void __iomem *
1184netxen_nic_map_indirect_address_128M(struct netxen_adapter *adapter,
1185 ulong win_off, void __iomem **mem_ptr)
1186{
1187 ulong off = win_off;
1188 void __iomem *addr;
1189 resource_size_t mem_base;
1190
1191 if (ADDR_IN_WINDOW1(win_off))
1192 off = NETXEN_CRB_NORMAL(win_off);
1193
1194 addr = pci_base_offset(adapter, off);
1195 if (addr)
1196 return addr;
1197
1198 if (adapter->ahw.pci_len0 == 0)
1199 off -= NETXEN_PCI_CRBSPACE;
1200
1201 mem_base = pci_resource_start(adapter->pdev, 0);
1202 *mem_ptr = ioremap(mem_base + (off & PAGE_MASK), PAGE_SIZE);
1203 if (*mem_ptr)
1204 addr = *mem_ptr + (off & (PAGE_SIZE - 1));
1205
1206 return addr;
1207}
1208
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001209static int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001210netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001211{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001212 unsigned long flags;
Narender Kumarf58dbd72009-12-02 15:46:18 +00001213 void __iomem *addr, *mem_ptr = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001214
Narender Kumarf58dbd72009-12-02 15:46:18 +00001215 addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
1216 if (!addr)
1217 return -EIO;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001218
Narender Kumarf58dbd72009-12-02 15:46:18 +00001219 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001220 netxen_nic_io_write_128M(adapter, addr, data);
Narender Kumarf58dbd72009-12-02 15:46:18 +00001221 } else { /* Window 0 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001222 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001223 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001224 writel(data, addr);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001225 netxen_nic_pci_set_crbwindow_128M(adapter,
1226 NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001227 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001228 }
1229
Narender Kumarf58dbd72009-12-02 15:46:18 +00001230 if (mem_ptr)
1231 iounmap(mem_ptr);
1232
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001233 return 0;
1234}
1235
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001236static u32
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001237netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001238{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001239 unsigned long flags;
Narender Kumarf58dbd72009-12-02 15:46:18 +00001240 void __iomem *addr, *mem_ptr = NULL;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001241 u32 data;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001242
Narender Kumarf58dbd72009-12-02 15:46:18 +00001243 addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
1244 if (!addr)
1245 return -EIO;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001246
Narender Kumarf58dbd72009-12-02 15:46:18 +00001247 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001248 data = netxen_nic_io_read_128M(adapter, addr);
Narender Kumarf58dbd72009-12-02 15:46:18 +00001249 } else { /* Window 0 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001250 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001251 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001252 data = readl(addr);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001253 netxen_nic_pci_set_crbwindow_128M(adapter,
1254 NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001255 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001256 }
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001257
Narender Kumarf58dbd72009-12-02 15:46:18 +00001258 if (mem_ptr)
1259 iounmap(mem_ptr);
1260
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001261 return data;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001262}
1263
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001264static int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001265netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001266{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001267 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001268 int rv;
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001269 void __iomem *addr = NULL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001270
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001271 rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001272
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001273 if (rv == 0) {
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001274 writel(data, addr);
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001275 return 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001276 }
1277
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001278 if (rv > 0) {
1279 /* indirect access */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001280 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001281 crb_win_lock(adapter);
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001282 netxen_nic_pci_set_crbwindow_2M(adapter, off);
1283 writel(data, addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001284 crb_win_unlock(adapter);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001285 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001286 return 0;
1287 }
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001288
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001289 dev_err(&adapter->pdev->dev,
1290 "%s: invalid offset: 0x%016lx\n", __func__, off);
1291 dump_stack();
1292 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001293}
1294
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001295static u32
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001296netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001297{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001298 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001299 int rv;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001300 u32 data;
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001301 void __iomem *addr = NULL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001302
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001303 rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001304
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001305 if (rv == 0)
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001306 return readl(addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001307
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001308 if (rv > 0) {
1309 /* indirect access */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001310 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001311 crb_win_lock(adapter);
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001312 netxen_nic_pci_set_crbwindow_2M(adapter, off);
1313 data = readl(addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001314 crb_win_unlock(adapter);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001315 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001316 return data;
1317 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001318
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001319 dev_err(&adapter->pdev->dev,
1320 "%s: invalid offset: 0x%016lx\n", __func__, off);
1321 dump_stack();
1322 return -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001323}
1324
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001325/* window 1 registers only */
1326static void netxen_nic_io_write_128M(struct netxen_adapter *adapter,
1327 void __iomem *addr, u32 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001328{
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001329 read_lock(&adapter->ahw.crb_lock);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001330 writel(data, addr);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001331 read_unlock(&adapter->ahw.crb_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001332}
1333
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001334static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter,
1335 void __iomem *addr)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001336{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001337 u32 val;
1338
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001339 read_lock(&adapter->ahw.crb_lock);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001340 val = readl(addr);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001341 read_unlock(&adapter->ahw.crb_lock);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001342
1343 return val;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001344}
1345
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001346static void netxen_nic_io_write_2M(struct netxen_adapter *adapter,
1347 void __iomem *addr, u32 data)
1348{
1349 writel(data, addr);
1350}
1351
1352static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter,
1353 void __iomem *addr)
1354{
1355 return readl(addr);
1356}
1357
1358void __iomem *
1359netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset)
1360{
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001361 void __iomem *addr = NULL;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001362
1363 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001364 if ((offset < NETXEN_CRB_PCIX_HOST2) &&
1365 (offset > NETXEN_CRB_PCIX_HOST))
1366 addr = PCI_OFFSET_SECOND_RANGE(adapter, offset);
1367 else
1368 addr = NETXEN_CRB_NORMALIZE(adapter, offset);
1369 } else {
1370 WARN_ON(netxen_nic_pci_get_crb_addr_2M(adapter,
1371 offset, &addr));
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001372 }
1373
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001374 return addr;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001375}
1376
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001377static int
1378netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
1379 u64 addr, u32 *start)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001380{
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001381 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1382 *start = (addr - NETXEN_ADDR_OCM0 + NETXEN_PCI_OCM0);
1383 return 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001384 } else if (ADDR_IN_RANGE(addr,
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001385 NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1386 *start = (addr - NETXEN_ADDR_OCM1 + NETXEN_PCI_OCM1);
1387 return 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001388 }
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001389
1390 return -EIO;
1391}
1392
1393static int
1394netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
1395 u64 addr, u32 *start)
1396{
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +00001397 u32 window;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001398 struct pci_dev *pdev = adapter->pdev;
1399
1400 if ((addr & 0x00ff800) == 0xff800) {
1401 if (printk_ratelimit())
1402 dev_warn(&pdev->dev, "QM access not handled\n");
1403 return -EIO;
1404 }
1405
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +00001406 if (NX_IS_REVISION_P3P(adapter->ahw.revision_id))
1407 window = OCM_WIN_P3P(addr);
1408 else
1409 window = OCM_WIN(addr);
1410
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001411 writel(window, adapter->ahw.ocm_win_crb);
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +00001412 /* read back to flush */
1413 readl(adapter->ahw.ocm_win_crb);
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001414
1415 adapter->ahw.ocm_win = window;
1416 *start = NETXEN_PCI_OCM0_2M + GET_MEM_OFFS_2M(addr);
1417 return 0;
1418}
1419
1420static int
1421netxen_nic_pci_mem_access_direct(struct netxen_adapter *adapter, u64 off,
1422 u64 *data, int op)
1423{
1424 void __iomem *addr, *mem_ptr = NULL;
1425 resource_size_t mem_base;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001426 int ret = -EIO;
1427 u32 start;
1428
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001429 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001430
1431 ret = adapter->pci_set_window(adapter, off, &start);
1432 if (ret != 0)
1433 goto unlock;
1434
1435 addr = pci_base_offset(adapter, start);
1436 if (addr)
1437 goto noremap;
1438
1439 mem_base = pci_resource_start(adapter->pdev, 0) + (start & PAGE_MASK);
1440
1441 mem_ptr = ioremap(mem_base, PAGE_SIZE);
1442 if (mem_ptr == NULL) {
1443 ret = -EIO;
1444 goto unlock;
1445 }
1446
1447 addr = mem_ptr + (start & (PAGE_SIZE - 1));
1448
1449noremap:
1450 if (op == 0) /* read */
1451 *data = readq(addr);
1452 else /* write */
1453 writeq(*data, addr);
1454
1455unlock:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001456 spin_unlock(&adapter->ahw.mem_lock);
1457
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001458 if (mem_ptr)
1459 iounmap(mem_ptr);
1460 return ret;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001461}
1462
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001463#define MAX_CTL_CHECK 1000
1464
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001465static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001466netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001467 u64 off, u64 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001468{
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001469 int j, ret;
1470 u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001471 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001472
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001473 /* Only 64-bit aligned access */
1474 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001475 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001476
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001477 /* P2 has different SIU and MIU test agent base addr */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001478 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1479 NETXEN_ADDR_QDR_NET_MAX_P2)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001480 mem_crb = pci_base_offset(adapter,
1481 NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
1482 addr_hi = SIU_TEST_AGT_ADDR_HI;
1483 data_lo = SIU_TEST_AGT_WRDATA_LO;
1484 data_hi = SIU_TEST_AGT_WRDATA_HI;
1485 off_lo = off & SIU_TEST_AGT_ADDR_MASK;
1486 off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001487 goto correct;
1488 }
1489
1490 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001491 mem_crb = pci_base_offset(adapter,
1492 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
1493 addr_hi = MIU_TEST_AGT_ADDR_HI;
1494 data_lo = MIU_TEST_AGT_WRDATA_LO;
1495 data_hi = MIU_TEST_AGT_WRDATA_HI;
1496 off_lo = off & MIU_TEST_AGT_ADDR_MASK;
1497 off_hi = 0;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001498 goto correct;
1499 }
1500
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001501 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
1502 ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1503 if (adapter->ahw.pci_len0 != 0) {
1504 return netxen_nic_pci_mem_access_direct(adapter,
1505 off, &data, 1);
1506 }
1507 }
1508
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001509 return -EIO;
1510
1511correct:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001512 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001513 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001514
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001515 writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1516 writel(off_hi, (mem_crb + addr_hi));
1517 writel(data & 0xffffffff, (mem_crb + data_lo));
1518 writel((data >> 32) & 0xffffffff, (mem_crb + data_hi));
1519 writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
1520 writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
1521 (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001522
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001523 for (j = 0; j < MAX_CTL_CHECK; j++) {
1524 temp = readl((mem_crb + TEST_AGT_CTRL));
1525 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001526 break;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001527 }
1528
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001529 if (j >= MAX_CTL_CHECK) {
1530 if (printk_ratelimit())
1531 dev_err(&adapter->pdev->dev,
1532 "failed to write through agent\n");
1533 ret = -EIO;
1534 } else
1535 ret = 0;
1536
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001537 netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001538 spin_unlock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001539 return ret;
1540}
1541
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001542static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001543netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001544 u64 off, u64 *data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001545{
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001546 int j, ret;
1547 u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
1548 u64 val;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001549 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001550
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001551 /* Only 64-bit aligned access */
1552 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001553 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001554
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001555 /* P2 has different SIU and MIU test agent base addr */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001556 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1557 NETXEN_ADDR_QDR_NET_MAX_P2)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001558 mem_crb = pci_base_offset(adapter,
1559 NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
1560 addr_hi = SIU_TEST_AGT_ADDR_HI;
1561 data_lo = SIU_TEST_AGT_RDDATA_LO;
1562 data_hi = SIU_TEST_AGT_RDDATA_HI;
1563 off_lo = off & SIU_TEST_AGT_ADDR_MASK;
1564 off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001565 goto correct;
1566 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001567
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001568 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001569 mem_crb = pci_base_offset(adapter,
1570 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
1571 addr_hi = MIU_TEST_AGT_ADDR_HI;
1572 data_lo = MIU_TEST_AGT_RDDATA_LO;
1573 data_hi = MIU_TEST_AGT_RDDATA_HI;
1574 off_lo = off & MIU_TEST_AGT_ADDR_MASK;
1575 off_hi = 0;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001576 goto correct;
1577 }
1578
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001579 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
1580 ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1581 if (adapter->ahw.pci_len0 != 0) {
1582 return netxen_nic_pci_mem_access_direct(adapter,
1583 off, data, 0);
1584 }
1585 }
1586
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001587 return -EIO;
1588
1589correct:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001590 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001591 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001592
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001593 writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1594 writel(off_hi, (mem_crb + addr_hi));
1595 writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
1596 writel((TA_CTL_START|TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001597
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001598 for (j = 0; j < MAX_CTL_CHECK; j++) {
1599 temp = readl(mem_crb + TEST_AGT_CTRL);
1600 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001601 break;
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001602 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001603
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001604 if (j >= MAX_CTL_CHECK) {
1605 if (printk_ratelimit())
1606 dev_err(&adapter->pdev->dev,
1607 "failed to read through agent\n");
1608 ret = -EIO;
1609 } else {
1610
1611 temp = readl(mem_crb + data_hi);
1612 val = ((u64)temp << 32);
1613 val |= readl(mem_crb + data_lo);
1614 *data = val;
1615 ret = 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001616 }
1617
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001618 netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001619 spin_unlock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001620
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001621 return ret;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001622}
1623
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001624static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001625netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001626 u64 off, u64 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001627{
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001628 int i, j, ret;
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001629 u32 temp, off8;
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001630 u64 stride;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001631 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001632
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001633 /* Only 64-bit aligned access */
1634 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001635 return -EIO;
1636
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001637 /* P3 onward, test agent base for MIU and SIU is same */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001638 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1639 NETXEN_ADDR_QDR_NET_MAX_P3)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001640 mem_crb = netxen_get_ioaddr(adapter,
1641 NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001642 goto correct;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001643 }
1644
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001645 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001646 mem_crb = netxen_get_ioaddr(adapter,
1647 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001648 goto correct;
1649 }
1650
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001651 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX))
1652 return netxen_nic_pci_mem_access_direct(adapter, off, &data, 1);
1653
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001654 return -EIO;
1655
1656correct:
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001657 stride = NX_IS_REVISION_P3P(adapter->ahw.revision_id) ? 16 : 8;
1658
1659 off8 = off & ~(stride-1);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001660
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001661 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001662
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001663 writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1664 writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001665
1666 i = 0;
1667 if (stride == 16) {
1668 writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
1669 writel((TA_CTL_START | TA_CTL_ENABLE),
1670 (mem_crb + TEST_AGT_CTRL));
1671
1672 for (j = 0; j < MAX_CTL_CHECK; j++) {
1673 temp = readl(mem_crb + TEST_AGT_CTRL);
1674 if ((temp & TA_CTL_BUSY) == 0)
1675 break;
1676 }
1677
1678 if (j >= MAX_CTL_CHECK) {
1679 ret = -EIO;
1680 goto done;
1681 }
1682
1683 i = (off & 0xf) ? 0 : 2;
1684 writel(readl(mem_crb + MIU_TEST_AGT_RDDATA(i)),
1685 mem_crb + MIU_TEST_AGT_WRDATA(i));
1686 writel(readl(mem_crb + MIU_TEST_AGT_RDDATA(i+1)),
1687 mem_crb + MIU_TEST_AGT_WRDATA(i+1));
1688 i = (off & 0xf) ? 2 : 0;
1689 }
1690
1691 writel(data & 0xffffffff,
1692 mem_crb + MIU_TEST_AGT_WRDATA(i));
1693 writel((data >> 32) & 0xffffffff,
1694 mem_crb + MIU_TEST_AGT_WRDATA(i+1));
1695
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001696 writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
1697 writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
1698 (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001699
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001700 for (j = 0; j < MAX_CTL_CHECK; j++) {
1701 temp = readl(mem_crb + TEST_AGT_CTRL);
1702 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001703 break;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001704 }
1705
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001706 if (j >= MAX_CTL_CHECK) {
1707 if (printk_ratelimit())
1708 dev_err(&adapter->pdev->dev,
1709 "failed to write through agent\n");
1710 ret = -EIO;
1711 } else
1712 ret = 0;
1713
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001714done:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001715 spin_unlock(&adapter->ahw.mem_lock);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001716
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001717 return ret;
1718}
1719
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001720static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001721netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001722 u64 off, u64 *data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001723{
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001724 int j, ret;
1725 u32 temp, off8;
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001726 u64 val, stride;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001727 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001728
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001729 /* Only 64-bit aligned access */
1730 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001731 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001732
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001733 /* P3 onward, test agent base for MIU and SIU is same */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001734 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1735 NETXEN_ADDR_QDR_NET_MAX_P3)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001736 mem_crb = netxen_get_ioaddr(adapter,
1737 NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001738 goto correct;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001739 }
1740
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001741 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001742 mem_crb = netxen_get_ioaddr(adapter,
1743 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001744 goto correct;
1745 }
1746
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001747 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1748 return netxen_nic_pci_mem_access_direct(adapter,
1749 off, data, 0);
1750 }
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001751
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001752 return -EIO;
1753
1754correct:
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001755 stride = NX_IS_REVISION_P3P(adapter->ahw.revision_id) ? 16 : 8;
1756
1757 off8 = off & ~(stride-1);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001758
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001759 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001760
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001761 writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1762 writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
1763 writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
1764 writel((TA_CTL_START | TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001765
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001766 for (j = 0; j < MAX_CTL_CHECK; j++) {
1767 temp = readl(mem_crb + TEST_AGT_CTRL);
1768 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001769 break;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001770 }
1771
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001772 if (j >= MAX_CTL_CHECK) {
1773 if (printk_ratelimit())
1774 dev_err(&adapter->pdev->dev,
1775 "failed to read through agent\n");
1776 ret = -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001777 } else {
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001778 off8 = MIU_TEST_AGT_RDDATA_LO;
1779 if ((stride == 16) && (off & 0xf))
1780 off8 = MIU_TEST_AGT_RDDATA_UPPER_LO;
1781
1782 temp = readl(mem_crb + off8 + 4);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001783 val = (u64)temp << 32;
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001784 val |= readl(mem_crb + off8);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001785 *data = val;
1786 ret = 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001787 }
1788
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001789 spin_unlock(&adapter->ahw.mem_lock);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001790
1791 return ret;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001792}
1793
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001794void
1795netxen_setup_hwops(struct netxen_adapter *adapter)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001796{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001797 adapter->init_port = netxen_niu_xg_init_port;
1798 adapter->stop_port = netxen_niu_disable_xg_port;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001799
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001800 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1801 adapter->crb_read = netxen_nic_hw_read_wx_128M,
1802 adapter->crb_write = netxen_nic_hw_write_wx_128M,
1803 adapter->pci_set_window = netxen_nic_pci_set_window_128M,
1804 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M,
1805 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M,
1806 adapter->io_read = netxen_nic_io_read_128M,
1807 adapter->io_write = netxen_nic_io_write_128M,
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001808
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001809 adapter->macaddr_set = netxen_p2_nic_set_mac_addr;
1810 adapter->set_multi = netxen_p2_nic_set_multi;
1811 adapter->set_mtu = netxen_nic_set_mtu_xgb;
1812 adapter->set_promisc = netxen_p2_nic_set_promisc;
1813
1814 } else {
1815 adapter->crb_read = netxen_nic_hw_read_wx_2M,
1816 adapter->crb_write = netxen_nic_hw_write_wx_2M,
1817 adapter->pci_set_window = netxen_nic_pci_set_window_2M,
1818 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M,
1819 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M,
1820 adapter->io_read = netxen_nic_io_read_2M,
1821 adapter->io_write = netxen_nic_io_write_2M,
1822
1823 adapter->set_mtu = nx_fw_cmd_set_mtu;
1824 adapter->set_promisc = netxen_p3_nic_set_promisc;
1825 adapter->macaddr_set = netxen_p3_nic_set_mac_addr;
1826 adapter->set_multi = netxen_p3_nic_set_multi;
1827
1828 adapter->phy_read = nx_fw_cmd_query_phy;
1829 adapter->phy_write = nx_fw_cmd_set_phy;
1830 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001831}
1832
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001833int netxen_nic_get_board_info(struct netxen_adapter *adapter)
1834{
Dhananjay Phadke0dc6d9c2009-10-21 19:39:03 +00001835 int offset, board_type, magic;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001836 struct pci_dev *pdev = adapter->pdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001837
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001838 offset = NX_FW_MAGIC_OFFSET;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001839 if (netxen_rom_fast_read(adapter, offset, &magic))
1840 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001841
Dhananjay Phadke0dc6d9c2009-10-21 19:39:03 +00001842 if (magic != NETXEN_BDINFO_MAGIC) {
1843 dev_err(&pdev->dev, "invalid board config, magic=%08x\n",
1844 magic);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001845 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001846 }
1847
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001848 offset = NX_BRDTYPE_OFFSET;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001849 if (netxen_rom_fast_read(adapter, offset, &board_type))
1850 return -EIO;
1851
1852 adapter->ahw.board_type = board_type;
1853
1854 if (board_type == NETXEN_BRDTYPE_P3_4_GB_MM) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001855 u32 gpio = NXRD32(adapter, NETXEN_ROMUSB_GLB_PAD_GPIO_I);
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001856 if ((gpio & 0x8000) == 0)
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001857 board_type = NETXEN_BRDTYPE_P3_10G_TP;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001858 }
1859
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00001860 switch (board_type) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001861 case NETXEN_BRDTYPE_P2_SB35_4G:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001862 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001863 break;
1864 case NETXEN_BRDTYPE_P2_SB31_10G:
1865 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1866 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1867 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001868 case NETXEN_BRDTYPE_P3_HMEZ:
1869 case NETXEN_BRDTYPE_P3_XG_LOM:
1870 case NETXEN_BRDTYPE_P3_10G_CX4:
1871 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
1872 case NETXEN_BRDTYPE_P3_IMEZ:
1873 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
Dhananjay Phadkea70f9392008-08-01 03:14:56 -07001874 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
1875 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001876 case NETXEN_BRDTYPE_P3_10G_XFP:
1877 case NETXEN_BRDTYPE_P3_10000_BASE_T:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001878 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001879 break;
1880 case NETXEN_BRDTYPE_P1_BD:
1881 case NETXEN_BRDTYPE_P1_SB:
1882 case NETXEN_BRDTYPE_P1_SMAX:
1883 case NETXEN_BRDTYPE_P1_SOCK:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001884 case NETXEN_BRDTYPE_P3_REF_QG:
1885 case NETXEN_BRDTYPE_P3_4_GB:
1886 case NETXEN_BRDTYPE_P3_4_GB_MM:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001887 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001888 break;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001889 case NETXEN_BRDTYPE_P3_10G_TP:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001890 adapter->ahw.port_type = (adapter->portnum < 2) ?
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001891 NETXEN_NIC_XGBE : NETXEN_NIC_GBE;
1892 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001893 default:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001894 dev_err(&pdev->dev, "unknown board type %x\n", board_type);
1895 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001896 break;
1897 }
1898
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001899 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001900}
1901
1902/* NIU access sections */
1903
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001904int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001905{
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001906 new_mtu += MTU_FUDGE_FACTOR;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001907 NXWR32(adapter, NETXEN_NIU_GB_MAX_FRAME_SIZE(adapter->physical_port),
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07001908 new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001909 return 0;
1910}
1911
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001912int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001913{
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001914 new_mtu += MTU_FUDGE_FACTOR;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07001915 if (adapter->physical_port == 0)
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001916 NXWR32(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu);
Jeff Garzik47906542007-11-23 21:23:36 -05001917 else
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001918 NXWR32(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001919 return 0;
1920}
1921
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001922void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001923{
Al Viroa608ab9c2007-01-02 10:39:10 +00001924 __u32 status;
1925 __u32 autoneg;
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001926 __u32 port_mode;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001927
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001928 if (!netif_carrier_ok(adapter->netdev)) {
1929 adapter->link_speed = 0;
1930 adapter->link_duplex = -1;
1931 adapter->link_autoneg = AUTONEG_ENABLE;
1932 return;
1933 }
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001934
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001935 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001936 port_mode = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001937 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
1938 adapter->link_speed = SPEED_1000;
1939 adapter->link_duplex = DUPLEX_FULL;
1940 adapter->link_autoneg = AUTONEG_DISABLE;
1941 return;
1942 }
1943
Joe Perches8e95a202009-12-03 07:58:21 +00001944 if (adapter->phy_read &&
1945 adapter->phy_read(adapter,
1946 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
1947 &status) == 0) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001948 if (netxen_get_phy_link(status)) {
1949 switch (netxen_get_phy_speed(status)) {
1950 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001951 adapter->link_speed = SPEED_10;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001952 break;
1953 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001954 adapter->link_speed = SPEED_100;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001955 break;
1956 case 2:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001957 adapter->link_speed = SPEED_1000;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001958 break;
1959 default:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001960 adapter->link_speed = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001961 break;
1962 }
1963 switch (netxen_get_phy_duplex(status)) {
1964 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001965 adapter->link_duplex = DUPLEX_HALF;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001966 break;
1967 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001968 adapter->link_duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001969 break;
1970 default:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001971 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001972 break;
1973 }
Joe Perches8e95a202009-12-03 07:58:21 +00001974 if (adapter->phy_read &&
1975 adapter->phy_read(adapter,
1976 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
1977 &autoneg) != 0)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001978 adapter->link_autoneg = autoneg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001979 } else
1980 goto link_down;
1981 } else {
1982 link_down:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001983 adapter->link_speed = 0;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001984 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001985 }
1986 }
1987}
1988
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001989int
1990netxen_nic_wol_supported(struct netxen_adapter *adapter)
1991{
1992 u32 wol_cfg;
1993
1994 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
1995 return 0;
1996
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001997 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001998 if (wol_cfg & (1UL << adapter->portnum)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001999 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002000 if (wol_cfg & (1 << adapter->portnum))
2001 return 1;
2002 }
2003
2004 return 0;
2005}