blob: 5cef718fe35f2425bc7afcfc859b9e0008fadac2 [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
Amit Kumar Salecha4d21fef2010-01-14 01:53:23 +000022 * in the file called "COPYING".
Amit S. Kale80922fb2006-12-04 09:18:00 -080023 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040024 */
25
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Amit S. Kale3d396eb2006-10-21 15:33:03 -040027#include "netxen_nic.h"
28#include "netxen_nic_hw.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040029
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030030#include <net/ip.h>
31
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070032#define MASK(n) ((1ULL<<(n))-1)
33#define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff))
34#define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff))
35#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 PCI_OFFSET_FIRST_RANGE(adapter, off) \
66 ((adapter)->ahw.pci_base0 + (off))
67#define PCI_OFFSET_SECOND_RANGE(adapter, off) \
68 ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START)
69#define PCI_OFFSET_THIRD_RANGE(adapter, off) \
70 ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START)
71
72static void __iomem *pci_base_offset(struct netxen_adapter *adapter,
73 unsigned long off)
74{
75 if (ADDR_IN_RANGE(off, FIRST_PAGE_GROUP_START, FIRST_PAGE_GROUP_END))
76 return PCI_OFFSET_FIRST_RANGE(adapter, off);
77
78 if (ADDR_IN_RANGE(off, SECOND_PAGE_GROUP_START, SECOND_PAGE_GROUP_END))
79 return PCI_OFFSET_SECOND_RANGE(adapter, off);
80
81 if (ADDR_IN_RANGE(off, THIRD_PAGE_GROUP_START, THIRD_PAGE_GROUP_END))
82 return PCI_OFFSET_THIRD_RANGE(adapter, off);
83
84 return NULL;
85}
86
Dhananjay Phadkeea7eaa32009-04-07 22:50:48 +000087static crb_128M_2M_block_map_t
88crb_128M_2M_map[64] __cacheline_aligned_in_smp = {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070089 {{{0, 0, 0, 0} } }, /* 0: PCI */
90 {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */
91 {1, 0x0110000, 0x0120000, 0x130000},
92 {1, 0x0120000, 0x0122000, 0x124000},
93 {1, 0x0130000, 0x0132000, 0x126000},
94 {1, 0x0140000, 0x0142000, 0x128000},
95 {1, 0x0150000, 0x0152000, 0x12a000},
96 {1, 0x0160000, 0x0170000, 0x110000},
97 {1, 0x0170000, 0x0172000, 0x12e000},
98 {0, 0x0000000, 0x0000000, 0x000000},
99 {0, 0x0000000, 0x0000000, 0x000000},
100 {0, 0x0000000, 0x0000000, 0x000000},
101 {0, 0x0000000, 0x0000000, 0x000000},
102 {0, 0x0000000, 0x0000000, 0x000000},
103 {0, 0x0000000, 0x0000000, 0x000000},
104 {1, 0x01e0000, 0x01e0800, 0x122000},
105 {0, 0x0000000, 0x0000000, 0x000000} } },
106 {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */
107 {{{0, 0, 0, 0} } }, /* 3: */
108 {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */
109 {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */
110 {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */
111 {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */
112 {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */
113 {0, 0x0000000, 0x0000000, 0x000000},
114 {0, 0x0000000, 0x0000000, 0x000000},
115 {0, 0x0000000, 0x0000000, 0x000000},
116 {0, 0x0000000, 0x0000000, 0x000000},
117 {0, 0x0000000, 0x0000000, 0x000000},
118 {0, 0x0000000, 0x0000000, 0x000000},
119 {0, 0x0000000, 0x0000000, 0x000000},
120 {0, 0x0000000, 0x0000000, 0x000000},
121 {0, 0x0000000, 0x0000000, 0x000000},
122 {0, 0x0000000, 0x0000000, 0x000000},
123 {0, 0x0000000, 0x0000000, 0x000000},
124 {0, 0x0000000, 0x0000000, 0x000000},
125 {0, 0x0000000, 0x0000000, 0x000000},
126 {0, 0x0000000, 0x0000000, 0x000000},
127 {1, 0x08f0000, 0x08f2000, 0x172000} } },
128 {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/
129 {0, 0x0000000, 0x0000000, 0x000000},
130 {0, 0x0000000, 0x0000000, 0x000000},
131 {0, 0x0000000, 0x0000000, 0x000000},
132 {0, 0x0000000, 0x0000000, 0x000000},
133 {0, 0x0000000, 0x0000000, 0x000000},
134 {0, 0x0000000, 0x0000000, 0x000000},
135 {0, 0x0000000, 0x0000000, 0x000000},
136 {0, 0x0000000, 0x0000000, 0x000000},
137 {0, 0x0000000, 0x0000000, 0x000000},
138 {0, 0x0000000, 0x0000000, 0x000000},
139 {0, 0x0000000, 0x0000000, 0x000000},
140 {0, 0x0000000, 0x0000000, 0x000000},
141 {0, 0x0000000, 0x0000000, 0x000000},
142 {0, 0x0000000, 0x0000000, 0x000000},
143 {1, 0x09f0000, 0x09f2000, 0x176000} } },
144 {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/
145 {0, 0x0000000, 0x0000000, 0x000000},
146 {0, 0x0000000, 0x0000000, 0x000000},
147 {0, 0x0000000, 0x0000000, 0x000000},
148 {0, 0x0000000, 0x0000000, 0x000000},
149 {0, 0x0000000, 0x0000000, 0x000000},
150 {0, 0x0000000, 0x0000000, 0x000000},
151 {0, 0x0000000, 0x0000000, 0x000000},
152 {0, 0x0000000, 0x0000000, 0x000000},
153 {0, 0x0000000, 0x0000000, 0x000000},
154 {0, 0x0000000, 0x0000000, 0x000000},
155 {0, 0x0000000, 0x0000000, 0x000000},
156 {0, 0x0000000, 0x0000000, 0x000000},
157 {0, 0x0000000, 0x0000000, 0x000000},
158 {0, 0x0000000, 0x0000000, 0x000000},
159 {1, 0x0af0000, 0x0af2000, 0x17a000} } },
160 {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/
161 {0, 0x0000000, 0x0000000, 0x000000},
162 {0, 0x0000000, 0x0000000, 0x000000},
163 {0, 0x0000000, 0x0000000, 0x000000},
164 {0, 0x0000000, 0x0000000, 0x000000},
165 {0, 0x0000000, 0x0000000, 0x000000},
166 {0, 0x0000000, 0x0000000, 0x000000},
167 {0, 0x0000000, 0x0000000, 0x000000},
168 {0, 0x0000000, 0x0000000, 0x000000},
169 {0, 0x0000000, 0x0000000, 0x000000},
170 {0, 0x0000000, 0x0000000, 0x000000},
171 {0, 0x0000000, 0x0000000, 0x000000},
172 {0, 0x0000000, 0x0000000, 0x000000},
173 {0, 0x0000000, 0x0000000, 0x000000},
174 {0, 0x0000000, 0x0000000, 0x000000},
175 {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
176 {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */
177 {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */
178 {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */
179 {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */
180 {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */
181 {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */
182 {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */
183 {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */
184 {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */
185 {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */
186 {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */
187 {{{0, 0, 0, 0} } }, /* 23: */
188 {{{0, 0, 0, 0} } }, /* 24: */
189 {{{0, 0, 0, 0} } }, /* 25: */
190 {{{0, 0, 0, 0} } }, /* 26: */
191 {{{0, 0, 0, 0} } }, /* 27: */
192 {{{0, 0, 0, 0} } }, /* 28: */
193 {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */
194 {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */
195 {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */
196 {{{0} } }, /* 32: PCI */
197 {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */
198 {1, 0x2110000, 0x2120000, 0x130000},
199 {1, 0x2120000, 0x2122000, 0x124000},
200 {1, 0x2130000, 0x2132000, 0x126000},
201 {1, 0x2140000, 0x2142000, 0x128000},
202 {1, 0x2150000, 0x2152000, 0x12a000},
203 {1, 0x2160000, 0x2170000, 0x110000},
204 {1, 0x2170000, 0x2172000, 0x12e000},
205 {0, 0x0000000, 0x0000000, 0x000000},
206 {0, 0x0000000, 0x0000000, 0x000000},
207 {0, 0x0000000, 0x0000000, 0x000000},
208 {0, 0x0000000, 0x0000000, 0x000000},
209 {0, 0x0000000, 0x0000000, 0x000000},
210 {0, 0x0000000, 0x0000000, 0x000000},
211 {0, 0x0000000, 0x0000000, 0x000000},
212 {0, 0x0000000, 0x0000000, 0x000000} } },
213 {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */
214 {{{0} } }, /* 35: */
215 {{{0} } }, /* 36: */
216 {{{0} } }, /* 37: */
217 {{{0} } }, /* 38: */
218 {{{0} } }, /* 39: */
219 {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */
220 {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */
221 {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */
222 {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */
223 {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */
224 {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */
225 {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */
226 {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */
227 {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */
228 {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */
229 {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */
230 {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */
231 {{{0} } }, /* 52: */
232 {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */
233 {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */
234 {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */
235 {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */
236 {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */
237 {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */
238 {{{0} } }, /* 59: I2C0 */
239 {{{0} } }, /* 60: I2C1 */
240 {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */
241 {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */
242 {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */
243};
244
245/*
246 * top 12 bits of crb internal address (hub, agent)
247 */
248static unsigned crb_hub_agt[64] =
249{
250 0,
251 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
252 NETXEN_HW_CRB_HUB_AGT_ADR_MN,
253 NETXEN_HW_CRB_HUB_AGT_ADR_MS,
254 0,
255 NETXEN_HW_CRB_HUB_AGT_ADR_SRE,
256 NETXEN_HW_CRB_HUB_AGT_ADR_NIU,
257 NETXEN_HW_CRB_HUB_AGT_ADR_QMN,
258 NETXEN_HW_CRB_HUB_AGT_ADR_SQN0,
259 NETXEN_HW_CRB_HUB_AGT_ADR_SQN1,
260 NETXEN_HW_CRB_HUB_AGT_ADR_SQN2,
261 NETXEN_HW_CRB_HUB_AGT_ADR_SQN3,
262 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
263 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
264 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
265 NETXEN_HW_CRB_HUB_AGT_ADR_PGN4,
266 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
267 NETXEN_HW_CRB_HUB_AGT_ADR_PGN0,
268 NETXEN_HW_CRB_HUB_AGT_ADR_PGN1,
269 NETXEN_HW_CRB_HUB_AGT_ADR_PGN2,
270 NETXEN_HW_CRB_HUB_AGT_ADR_PGN3,
271 NETXEN_HW_CRB_HUB_AGT_ADR_PGND,
272 NETXEN_HW_CRB_HUB_AGT_ADR_PGNI,
273 NETXEN_HW_CRB_HUB_AGT_ADR_PGS0,
274 NETXEN_HW_CRB_HUB_AGT_ADR_PGS1,
275 NETXEN_HW_CRB_HUB_AGT_ADR_PGS2,
276 NETXEN_HW_CRB_HUB_AGT_ADR_PGS3,
277 0,
278 NETXEN_HW_CRB_HUB_AGT_ADR_PGSI,
279 NETXEN_HW_CRB_HUB_AGT_ADR_SN,
280 0,
281 NETXEN_HW_CRB_HUB_AGT_ADR_EG,
282 0,
283 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
284 NETXEN_HW_CRB_HUB_AGT_ADR_CAM,
285 0,
286 0,
287 0,
288 0,
289 0,
290 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
291 0,
292 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1,
293 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2,
294 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3,
295 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4,
296 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5,
297 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6,
298 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7,
299 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
300 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
301 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
302 0,
303 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0,
304 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8,
305 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9,
306 NETXEN_HW_CRB_HUB_AGT_ADR_OCM0,
307 0,
308 NETXEN_HW_CRB_HUB_AGT_ADR_SMB,
309 NETXEN_HW_CRB_HUB_AGT_ADR_I2C0,
310 NETXEN_HW_CRB_HUB_AGT_ADR_I2C1,
311 0,
312 NETXEN_HW_CRB_HUB_AGT_ADR_PGNC,
313 0,
314};
315
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400316/* PCI Windowing for DDR regions. */
317
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700318#define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400319
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000320#define NETXEN_PCIE_SEM_TIMEOUT 10000
321
stephen hemminger7e12bb02010-10-18 17:40:10 +0000322static int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu);
323
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000324int
325netxen_pcie_sem_lock(struct netxen_adapter *adapter, int sem, u32 id_reg)
326{
327 int done = 0, timeout = 0;
328
329 while (!done) {
330 done = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_LOCK(sem)));
331 if (done == 1)
332 break;
333 if (++timeout >= NETXEN_PCIE_SEM_TIMEOUT)
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +0000334 return -EIO;
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000335 msleep(1);
336 }
337
338 if (id_reg)
339 NXWR32(adapter, id_reg, adapter->portnum);
340
341 return 0;
342}
343
344void
345netxen_pcie_sem_unlock(struct netxen_adapter *adapter, int sem)
346{
Amit Kumar Salecha581e8ae2010-01-07 22:10:15 +0000347 NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_UNLOCK(sem)));
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000348}
349
stephen hemminger7e12bb02010-10-18 17:40:10 +0000350static int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port)
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000351{
352 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
353 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_1+(0x10000*port), 0x1447);
354 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0+(0x10000*port), 0x5);
355 }
356
357 return 0;
358}
359
360/* Disable an XG interface */
stephen hemminger7e12bb02010-10-18 17:40:10 +0000361static int netxen_niu_disable_xg_port(struct netxen_adapter *adapter)
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000362{
363 __u32 mac_cfg;
364 u32 port = adapter->physical_port;
365
366 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
367 return 0;
368
369 if (port > NETXEN_NIU_MAX_XG_PORTS)
370 return -EINVAL;
371
372 mac_cfg = 0;
373 if (NXWR32(adapter,
374 NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg))
375 return -EIO;
376 return 0;
377}
378
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700379#define NETXEN_UNICAST_ADDR(port, index) \
380 (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8))
381#define NETXEN_MCAST_ADDR(port, index) \
382 (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8))
383#define MAC_HI(addr) \
384 ((addr[2] << 16) | (addr[1] << 8) | (addr[0]))
385#define MAC_LO(addr) \
386 ((addr[5] << 16) | (addr[4] << 8) | (addr[3]))
387
stephen hemminger7e12bb02010-10-18 17:40:10 +0000388static int netxen_p2_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000389{
Narender Kumara7483b02009-11-20 15:09:33 +0000390 u32 mac_cfg;
391 u32 cnt = 0;
392 __u32 reg = 0x0200;
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000393 u32 port = adapter->physical_port;
Narender Kumara7483b02009-11-20 15:09:33 +0000394 u16 board_type = adapter->ahw.board_type;
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000395
396 if (port > NETXEN_NIU_MAX_XG_PORTS)
397 return -EINVAL;
398
Narender Kumara7483b02009-11-20 15:09:33 +0000399 mac_cfg = NXRD32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port));
400 mac_cfg &= ~0x4;
401 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg);
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000402
Narender Kumara7483b02009-11-20 15:09:33 +0000403 if ((board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) ||
404 (board_type == NETXEN_BRDTYPE_P2_SB31_10G_HMEZ))
405 reg = (0x20 << port);
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000406
Narender Kumara7483b02009-11-20 15:09:33 +0000407 NXWR32(adapter, NETXEN_NIU_FRAME_COUNT_SELECT, reg);
408
409 mdelay(10);
410
411 while (NXRD32(adapter, NETXEN_NIU_FRAME_COUNT) && ++cnt < 20)
412 mdelay(10);
413
414 if (cnt < 20) {
415
416 reg = NXRD32(adapter,
417 NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port));
418
419 if (mode == NETXEN_NIU_PROMISC_MODE)
420 reg = (reg | 0x2000UL);
421 else
422 reg = (reg & ~0x2000UL);
423
424 if (mode == NETXEN_NIU_ALLMULTI_MODE)
425 reg = (reg | 0x1000UL);
426 else
427 reg = (reg & ~0x1000UL);
428
429 NXWR32(adapter,
430 NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), reg);
431 }
432
433 mac_cfg |= 0x4;
434 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg);
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000435
436 return 0;
437}
438
stephen hemminger7e12bb02010-10-18 17:40:10 +0000439static int netxen_p2_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr)
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000440{
441 u32 mac_hi, mac_lo;
442 u32 reg_hi, reg_lo;
443
444 u8 phy = adapter->physical_port;
445
446 if (phy >= NETXEN_NIU_MAX_XG_PORTS)
447 return -EINVAL;
448
449 mac_lo = ((u32)addr[0] << 16) | ((u32)addr[1] << 24);
450 mac_hi = addr[2] | ((u32)addr[3] << 8) |
451 ((u32)addr[4] << 16) | ((u32)addr[5] << 24);
452
453 reg_lo = NETXEN_NIU_XGE_STATION_ADDR_0_1 + (0x10000 * phy);
454 reg_hi = NETXEN_NIU_XGE_STATION_ADDR_0_HI + (0x10000 * phy);
455
456 /* write twice to flush */
457 if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi))
458 return -EIO;
459 if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi))
460 return -EIO;
461
462 return 0;
463}
464
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700465static int
466netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter)
467{
468 u32 val = 0;
469 u16 port = adapter->physical_port;
Narender Kumar5d09e532009-11-20 22:08:57 +0000470 u8 *addr = adapter->mac_addr;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700471
472 if (adapter->mc_enabled)
473 return 0;
474
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000475 val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700476 val |= (1UL << (28+port));
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000477 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700478
479 /* add broadcast addr to filter */
480 val = 0xffffff;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000481 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
482 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700483
484 /* add station addr to filter */
485 val = MAC_HI(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000486 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700487 val = MAC_LO(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000488 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700489
490 adapter->mc_enabled = 1;
491 return 0;
492}
493
494static int
495netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter)
496{
497 u32 val = 0;
498 u16 port = adapter->physical_port;
Narender Kumar5d09e532009-11-20 22:08:57 +0000499 u8 *addr = adapter->mac_addr;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700500
501 if (!adapter->mc_enabled)
502 return 0;
503
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000504 val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700505 val &= ~(1UL << (28+port));
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000506 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700507
508 val = MAC_HI(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000509 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700510 val = MAC_LO(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000511 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700512
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000513 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), 0);
514 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700515
516 adapter->mc_enabled = 0;
517 return 0;
518}
519
520static int
521netxen_nic_set_mcast_addr(struct netxen_adapter *adapter,
522 int index, u8 *addr)
523{
524 u32 hi = 0, lo = 0;
525 u16 port = adapter->physical_port;
526
527 lo = MAC_LO(addr);
528 hi = MAC_HI(addr);
529
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000530 NXWR32(adapter, NETXEN_MCAST_ADDR(port, index), hi);
531 NXWR32(adapter, NETXEN_MCAST_ADDR(port, index)+4, lo);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700532
533 return 0;
534}
535
stephen hemminger7e12bb02010-10-18 17:40:10 +0000536static void netxen_p2_nic_set_multi(struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400537{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700538 struct netxen_adapter *adapter = netdev_priv(netdev);
Jiri Pirko22bedad2010-04-01 21:22:57 +0000539 struct netdev_hw_addr *ha;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700540 u8 null_addr[6];
Jiri Pirkof9dcbcc2010-02-23 09:19:49 +0000541 int i;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400542
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700543 memset(null_addr, 0, 6);
544
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400545 if (netdev->flags & IFF_PROMISC) {
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700546
547 adapter->set_promisc(adapter,
548 NETXEN_NIU_PROMISC_MODE);
549
550 /* Full promiscuous mode */
551 netxen_nic_disable_mcast_filter(adapter);
552
553 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400554 }
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700555
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000556 if (netdev_mc_empty(netdev)) {
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700557 adapter->set_promisc(adapter,
558 NETXEN_NIU_NON_PROMISC_MODE);
559 netxen_nic_disable_mcast_filter(adapter);
560 return;
561 }
562
563 adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE);
564 if (netdev->flags & IFF_ALLMULTI ||
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000565 netdev_mc_count(netdev) > adapter->max_mc_count) {
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700566 netxen_nic_disable_mcast_filter(adapter);
567 return;
568 }
569
570 netxen_nic_enable_mcast_filter(adapter);
571
Jiri Pirkof9dcbcc2010-02-23 09:19:49 +0000572 i = 0;
Jiri Pirko22bedad2010-04-01 21:22:57 +0000573 netdev_for_each_mc_addr(ha, netdev)
574 netxen_nic_set_mcast_addr(adapter, i++, ha->addr);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700575
576 /* Clear out remaining addresses */
Jiri Pirkof9dcbcc2010-02-23 09:19:49 +0000577 while (i < adapter->max_mc_count)
578 netxen_nic_set_mcast_addr(adapter, i++, null_addr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400579}
580
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700581static int
582netxen_send_cmd_descs(struct netxen_adapter *adapter,
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000583 struct cmd_desc_type0 *cmd_desc_arr, int nr_desc)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700584{
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000585 u32 i, producer, consumer;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700586 struct netxen_cmd_buffer *pbuf;
587 struct cmd_desc_type0 *cmd_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000588 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700589
590 i = 0;
591
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000592 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
593 return -EIO;
594
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000595 tx_ring = adapter->tx_ring;
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000596 __netif_tx_lock_bh(tx_ring->txq);
Dhananjay Phadke03e678e2009-01-14 20:49:43 -0800597
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000598 producer = tx_ring->producer;
599 consumer = tx_ring->sw_consumer;
600
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000601 if (nr_desc >= netxen_tx_avail(tx_ring)) {
602 netif_tx_stop_queue(tx_ring->txq);
Rajesh Borundia7a9905e2010-10-18 02:03:41 +0000603 smp_mb();
604 if (netxen_tx_avail(tx_ring) > nr_desc) {
605 if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH)
606 netif_tx_wake_queue(tx_ring->txq);
607 } else {
608 __netif_tx_unlock_bh(tx_ring->txq);
609 return -EBUSY;
610 }
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000611 }
612
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700613 do {
614 cmd_desc = &cmd_desc_arr[i];
615
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000616 pbuf = &tx_ring->cmd_buf_arr[producer];
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700617 pbuf->skb = NULL;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700618 pbuf->frag_count = 0;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700619
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000620 memcpy(&tx_ring->desc_head[producer],
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700621 &cmd_desc_arr[i], sizeof(struct cmd_desc_type0));
622
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000623 producer = get_next_index(producer, tx_ring->num_desc);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700624 i++;
625
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000626 } while (i != nr_desc);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700627
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000628 tx_ring->producer = producer;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700629
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000630 netxen_nic_update_cmd_producer(adapter, tx_ring);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700631
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000632 __netif_tx_unlock_bh(tx_ring->txq);
Dhananjay Phadke03e678e2009-01-14 20:49:43 -0800633
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700634 return 0;
635}
636
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000637static int
638nx_p3_sre_macaddr_change(struct netxen_adapter *adapter, u8 *addr, unsigned op)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700639{
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700640 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800641 nx_mac_req_t *mac_req;
642 u64 word;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700643
644 memset(&req, 0, sizeof(nx_nic_req_t));
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800645 req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23);
646
647 word = NX_MAC_EVENT | ((u64)adapter->portnum << 16);
648 req.req_hdr = cpu_to_le64(word);
649
650 mac_req = (nx_mac_req_t *)&req.words[0];
651 mac_req->op = op;
652 memcpy(mac_req->mac_addr, addr, 6);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700653
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000654 return netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
655}
656
657static int nx_p3_nic_add_mac(struct netxen_adapter *adapter,
Joe Perches215faf92010-12-21 02:16:10 -0800658 const u8 *addr, struct list_head *del_list)
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000659{
660 struct list_head *head;
661 nx_mac_list_t *cur;
662
663 /* look up if already exists */
664 list_for_each(head, del_list) {
665 cur = list_entry(head, nx_mac_list_t, list);
666
667 if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) {
668 list_move_tail(head, &adapter->mac_list);
669 return 0;
670 }
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700671 }
672
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000673 cur = kzalloc(sizeof(nx_mac_list_t), GFP_ATOMIC);
674 if (cur == NULL) {
675 printk(KERN_ERR "%s: failed to add mac address filter\n",
676 adapter->netdev->name);
677 return -ENOMEM;
678 }
679 memcpy(cur->mac_addr, addr, ETH_ALEN);
680 list_add_tail(&cur->list, &adapter->mac_list);
681 return nx_p3_sre_macaddr_change(adapter,
682 cur->mac_addr, NETXEN_MAC_ADD);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700683}
684
stephen hemminger7e12bb02010-10-18 17:40:10 +0000685static void netxen_p3_nic_set_multi(struct net_device *netdev)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700686{
687 struct netxen_adapter *adapter = netdev_priv(netdev);
Jiri Pirko22bedad2010-04-01 21:22:57 +0000688 struct netdev_hw_addr *ha;
Joe Perches215faf92010-12-21 02:16:10 -0800689 static const u8 bcast_addr[ETH_ALEN] = {
690 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
691 };
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700692 u32 mode = VPORT_MISS_MODE_DROP;
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000693 LIST_HEAD(del_list);
694 struct list_head *head;
695 nx_mac_list_t *cur;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700696
Amit Kumar Salechad49c9642010-01-07 22:10:16 +0000697 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
698 return;
699
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000700 list_splice_tail_init(&adapter->mac_list, &del_list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700701
Narender Kumar5d09e532009-11-20 22:08:57 +0000702 nx_p3_nic_add_mac(adapter, adapter->mac_addr, &del_list);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000703 nx_p3_nic_add_mac(adapter, bcast_addr, &del_list);
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700704
705 if (netdev->flags & IFF_PROMISC) {
706 mode = VPORT_MISS_MODE_ACCEPT_ALL;
707 goto send_fw_cmd;
708 }
709
710 if ((netdev->flags & IFF_ALLMULTI) ||
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000711 (netdev_mc_count(netdev) > adapter->max_mc_count)) {
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700712 mode = VPORT_MISS_MODE_ACCEPT_MULTI;
713 goto send_fw_cmd;
714 }
715
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000716 if (!netdev_mc_empty(netdev)) {
Jiri Pirko22bedad2010-04-01 21:22:57 +0000717 netdev_for_each_mc_addr(ha, netdev)
718 nx_p3_nic_add_mac(adapter, ha->addr, &del_list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700719 }
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700720
721send_fw_cmd:
722 adapter->set_promisc(adapter, mode);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000723 head = &del_list;
724 while (!list_empty(head)) {
725 cur = list_entry(head->next, nx_mac_list_t, list);
726
727 nx_p3_sre_macaddr_change(adapter,
728 cur->mac_addr, NETXEN_MAC_DEL);
729 list_del(&cur->list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700730 kfree(cur);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700731 }
732}
733
stephen hemminger7e12bb02010-10-18 17:40:10 +0000734static int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700735{
736 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800737 u64 word;
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700738
739 memset(&req, 0, sizeof(nx_nic_req_t));
740
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800741 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
742
743 word = NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE |
744 ((u64)adapter->portnum << 16);
745 req.req_hdr = cpu_to_le64(word);
746
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700747 req.words[0] = cpu_to_le64(mode);
748
749 return netxen_send_cmd_descs(adapter,
750 (struct cmd_desc_type0 *)&req, 1);
751}
752
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800753void netxen_p3_free_mac_list(struct netxen_adapter *adapter)
754{
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000755 nx_mac_list_t *cur;
756 struct list_head *head = &adapter->mac_list;
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800757
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000758 while (!list_empty(head)) {
759 cur = list_entry(head->next, nx_mac_list_t, list);
760 nx_p3_sre_macaddr_change(adapter,
761 cur->mac_addr, NETXEN_MAC_DEL);
762 list_del(&cur->list);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800763 kfree(cur);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800764 }
765}
766
stephen hemminger7e12bb02010-10-18 17:40:10 +0000767static int netxen_p3_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr)
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000768{
769 /* assuming caller has already copied new addr to netdev */
770 netxen_p3_nic_set_multi(adapter->netdev);
771 return 0;
772}
773
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700774#define NETXEN_CONFIG_INTR_COALESCE 3
775
776/*
777 * Send the interrupt coalescing parameter set by ethtool to the card.
778 */
779int netxen_config_intr_coalesce(struct netxen_adapter *adapter)
780{
781 nx_nic_req_t req;
Amit Kumar Salechac0703952010-01-14 01:53:22 +0000782 u64 word[6];
783 int rv, i;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700784
785 memset(&req, 0, sizeof(nx_nic_req_t));
Amit Kumar Salechac0703952010-01-14 01:53:22 +0000786 memset(word, 0, sizeof(word));
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700787
Narender Kumar1bb482f2009-08-23 08:35:09 +0000788 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800789
Amit Kumar Salechac0703952010-01-14 01:53:22 +0000790 word[0] = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16);
791 req.req_hdr = cpu_to_le64(word[0]);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700792
Amit Kumar Salechac0703952010-01-14 01:53:22 +0000793 memcpy(&word[0], &adapter->coal, sizeof(adapter->coal));
794 for (i = 0; i < 6; i++)
795 req.words[i] = cpu_to_le64(word[i]);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700796
797 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
798 if (rv != 0) {
799 printk(KERN_ERR "ERROR. Could not send "
800 "interrupt coalescing parameters\n");
801 }
802
803 return rv;
804}
805
Narender Kumar1bb482f2009-08-23 08:35:09 +0000806int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable)
807{
808 nx_nic_req_t req;
809 u64 word;
810 int rv = 0;
811
Narender Kumar1bb482f2009-08-23 08:35:09 +0000812 memset(&req, 0, sizeof(nx_nic_req_t));
813
814 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
815
816 word = NX_NIC_H2C_OPCODE_CONFIG_HW_LRO | ((u64)adapter->portnum << 16);
817 req.req_hdr = cpu_to_le64(word);
818
819 req.words[0] = cpu_to_le64(enable);
820
821 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
822 if (rv != 0) {
823 printk(KERN_ERR "ERROR. Could not send "
824 "configure hw lro request\n");
825 }
826
Narender Kumar1bb482f2009-08-23 08:35:09 +0000827 return rv;
828}
829
Narender Kumarfa3ce352009-08-24 19:23:28 +0000830int netxen_config_bridged_mode(struct netxen_adapter *adapter, int enable)
831{
832 nx_nic_req_t req;
833 u64 word;
834 int rv = 0;
835
836 if (!!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED) == enable)
837 return rv;
838
839 memset(&req, 0, sizeof(nx_nic_req_t));
840
841 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
842
843 word = NX_NIC_H2C_OPCODE_CONFIG_BRIDGING |
844 ((u64)adapter->portnum << 16);
845 req.req_hdr = cpu_to_le64(word);
846
847 req.words[0] = cpu_to_le64(enable);
848
849 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
850 if (rv != 0) {
851 printk(KERN_ERR "ERROR. Could not send "
852 "configure bridge mode request\n");
853 }
854
855 adapter->flags ^= NETXEN_NIC_BRIDGE_ENABLED;
856
857 return rv;
858}
859
860
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000861#define RSS_HASHTYPE_IP_TCP 0x3
862
863int netxen_config_rss(struct netxen_adapter *adapter, int enable)
864{
865 nx_nic_req_t req;
866 u64 word;
867 int i, rv;
868
Joe Perches215faf92010-12-21 02:16:10 -0800869 static const u64 key[] = {
870 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL,
871 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
872 0x255b0ec26d5a56daULL
873 };
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000874
875
876 memset(&req, 0, sizeof(nx_nic_req_t));
877 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
878
879 word = NX_NIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16);
880 req.req_hdr = cpu_to_le64(word);
881
882 /*
883 * RSS request:
884 * bits 3-0: hash_method
885 * 5-4: hash_type_ipv4
886 * 7-6: hash_type_ipv6
887 * 8: enable
888 * 9: use indirection table
889 * 47-10: reserved
890 * 63-48: indirection table mask
891 */
892 word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) |
893 ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) |
894 ((u64)(enable & 0x1) << 8) |
895 ((0x7ULL) << 48);
896 req.words[0] = cpu_to_le64(word);
Joe Perches215faf92010-12-21 02:16:10 -0800897 for (i = 0; i < ARRAY_SIZE(key); i++)
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000898 req.words[i+1] = cpu_to_le64(key[i]);
899
900
901 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
902 if (rv != 0) {
903 printk(KERN_ERR "%s: could not configure RSS\n",
904 adapter->netdev->name);
905 }
906
907 return rv;
908}
909
Dhananjay Phadke6598b162009-07-26 20:07:37 +0000910int netxen_config_ipaddr(struct netxen_adapter *adapter, u32 ip, int cmd)
911{
912 nx_nic_req_t req;
913 u64 word;
914 int rv;
915
916 memset(&req, 0, sizeof(nx_nic_req_t));
917 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
918
919 word = NX_NIC_H2C_OPCODE_CONFIG_IPADDR | ((u64)adapter->portnum << 16);
920 req.req_hdr = cpu_to_le64(word);
921
922 req.words[0] = cpu_to_le64(cmd);
923 req.words[1] = cpu_to_le64(ip);
924
925 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
926 if (rv != 0) {
927 printk(KERN_ERR "%s: could not notify %s IP 0x%x reuqest\n",
928 adapter->netdev->name,
929 (cmd == NX_IP_UP) ? "Add" : "Remove", ip);
930 }
931 return rv;
932}
933
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000934int netxen_linkevent_request(struct netxen_adapter *adapter, int enable)
935{
936 nx_nic_req_t req;
937 u64 word;
938 int rv;
939
940 memset(&req, 0, sizeof(nx_nic_req_t));
941 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
942
943 word = NX_NIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16);
944 req.req_hdr = cpu_to_le64(word);
Dhananjay Phadke22527862009-05-05 19:05:06 +0000945 req.words[0] = cpu_to_le64(enable | (enable << 8));
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000946
947 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
948 if (rv != 0) {
949 printk(KERN_ERR "%s: could not configure link notification\n",
950 adapter->netdev->name);
951 }
952
953 return rv;
954}
955
Narender Kumar1bb482f2009-08-23 08:35:09 +0000956int netxen_send_lro_cleanup(struct netxen_adapter *adapter)
957{
958 nx_nic_req_t req;
959 u64 word;
960 int rv;
961
962 memset(&req, 0, sizeof(nx_nic_req_t));
963 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
964
965 word = NX_NIC_H2C_OPCODE_LRO_REQUEST |
966 ((u64)adapter->portnum << 16) |
967 ((u64)NX_NIC_LRO_REQUEST_CLEANUP << 56) ;
968
969 req.req_hdr = cpu_to_le64(word);
970
971 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
972 if (rv != 0) {
973 printk(KERN_ERR "%s: could not cleanup lro flows\n",
974 adapter->netdev->name);
975 }
976 return rv;
977}
978
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400979/*
980 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
981 * @returns 0 on success, negative on failure
982 */
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700983
984#define MTU_FUDGE_FACTOR 100
985
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400986int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
987{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700988 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700989 int max_mtu;
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700990 int rc = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400991
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700992 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
993 max_mtu = P3_MAX_MTU;
994 else
995 max_mtu = P2_MAX_MTU;
996
997 if (mtu > max_mtu) {
998 printk(KERN_ERR "%s: mtu > %d bytes unsupported\n",
999 netdev->name, max_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001000 return -EINVAL;
1001 }
1002
Amit S. Kale80922fb2006-12-04 09:18:00 -08001003 if (adapter->set_mtu)
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001004 rc = adapter->set_mtu(adapter, mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001005
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001006 if (!rc)
1007 netdev->mtu = mtu;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001008
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001009 return rc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001010}
1011
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001012static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
Al Virof305f782007-12-22 19:44:00 +00001013 int size, __le32 * buf)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001014{
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001015 int i, v, addr;
Al Virof305f782007-12-22 19:44:00 +00001016 __le32 *ptr32;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001017
1018 addr = base;
1019 ptr32 = buf;
1020 for (i = 0; i < size / sizeof(u32); i++) {
Al Virof305f782007-12-22 19:44:00 +00001021 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001022 return -1;
Al Virof305f782007-12-22 19:44:00 +00001023 *ptr32 = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001024 ptr32++;
1025 addr += sizeof(u32);
1026 }
1027 if ((char *)buf + size > (char *)ptr32) {
Al Virof305f782007-12-22 19:44:00 +00001028 __le32 local;
1029 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001030 return -1;
Al Virof305f782007-12-22 19:44:00 +00001031 local = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001032 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
1033 }
1034
1035 return 0;
1036}
1037
Amit Kumar Salechaa03d2452010-01-14 01:53:21 +00001038int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 *mac)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001039{
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001040 __le32 *pmac = (__le32 *) mac;
1041 u32 offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001042
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001043 offset = NX_FW_MAC_ADDR_OFFSET + (adapter->portnum * sizeof(u64));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001044
1045 if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001046 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001047
Al Virof305f782007-12-22 19:44:00 +00001048 if (*mac == cpu_to_le64(~0ULL)) {
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001049
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001050 offset = NX_OLD_MAC_ADDR_OFFSET +
1051 (adapter->portnum * sizeof(u64));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001052
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001053 if (netxen_get_flash_block(adapter,
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001054 offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001055 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001056
Al Virof305f782007-12-22 19:44:00 +00001057 if (*mac == cpu_to_le64(~0ULL))
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001058 return -1;
1059 }
1060 return 0;
1061}
1062
Amit Kumar Salechaa03d2452010-01-14 01:53:21 +00001063int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, u64 *mac)
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001064{
1065 uint32_t crbaddr, mac_hi, mac_lo;
1066 int pci_func = adapter->ahw.pci_func;
1067
1068 crbaddr = CRB_MAC_BLOCK_START +
1069 (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1));
1070
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001071 mac_lo = NXRD32(adapter, crbaddr);
1072 mac_hi = NXRD32(adapter, crbaddr+4);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001073
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001074 if (pci_func & 1)
Dhananjay Phadke2edbb452009-01-14 20:47:30 -08001075 *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001076 else
Dhananjay Phadke2edbb452009-01-14 20:47:30 -08001077 *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001078
1079 return 0;
1080}
1081
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001082/*
1083 * Changes the CRB window to the specified window.
1084 */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001085static void
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001086netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter,
1087 u32 window)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001088{
1089 void __iomem *offset;
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001090 int count = 10;
1091 u8 func = adapter->ahw.pci_func;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001092
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001093 if (adapter->ahw.crb_win == window)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001094 return;
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001095
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001096 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1097 NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001098
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001099 writel(window, offset);
1100 do {
1101 if (window == readl(offset))
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001102 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001103
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001104 if (printk_ratelimit())
1105 dev_warn(&adapter->pdev->dev,
1106 "failed to set CRB window to %d\n",
1107 (window == NETXEN_WINDOW_ONE));
1108 udelay(1);
1109
1110 } while (--count > 0);
1111
1112 if (count > 0)
1113 adapter->ahw.crb_win = window;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001114}
1115
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001116/*
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001117 * Returns < 0 if off is not valid,
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001118 * 1 if window access is needed. 'off' is set to offset from
1119 * CRB space in 128M pci map
1120 * 0 if no window access is needed. 'off' is set to 2M addr
1121 * In: 'off' is offset from base in 128M pci map
1122 */
1123static int
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001124netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter,
1125 ulong off, void __iomem **addr)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001126{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001127 crb_128M_2M_sub_block_map_t *m;
1128
1129
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001130 if ((off >= NETXEN_CRB_MAX) || (off < NETXEN_PCI_CRBSPACE))
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001131 return -EINVAL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001132
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001133 off -= NETXEN_PCI_CRBSPACE;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001134
1135 /*
1136 * Try direct map
1137 */
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001138 m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)];
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001139
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001140 if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) {
1141 *addr = adapter->ahw.pci_base0 + m->start_2M +
1142 (off - m->start_128M);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001143 return 0;
1144 }
1145
1146 /*
1147 * Not in direct map, use crb window
1148 */
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001149 *addr = adapter->ahw.pci_base0 + CRB_INDIRECT_2M +
1150 (off & MASK(16));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001151 return 1;
1152}
1153
1154/*
1155 * In: 'off' is offset from CRB space in 128M pci map
1156 * Out: 'off' is 2M pci map addr
1157 * side effect: lock crb window
1158 */
1159static void
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001160netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001161{
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001162 u32 window;
1163 void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001164
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001165 off -= NETXEN_PCI_CRBSPACE;
1166
1167 window = CRB_HI(off);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001168
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001169 writel(window, addr);
1170 if (readl(addr) != window) {
1171 if (printk_ratelimit())
1172 dev_warn(&adapter->pdev->dev,
1173 "failed to set CRB window to %d off 0x%lx\n",
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001174 window, off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001175 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001176}
1177
Narender Kumarf58dbd72009-12-02 15:46:18 +00001178static void __iomem *
1179netxen_nic_map_indirect_address_128M(struct netxen_adapter *adapter,
1180 ulong win_off, void __iomem **mem_ptr)
1181{
1182 ulong off = win_off;
1183 void __iomem *addr;
1184 resource_size_t mem_base;
1185
1186 if (ADDR_IN_WINDOW1(win_off))
1187 off = NETXEN_CRB_NORMAL(win_off);
1188
1189 addr = pci_base_offset(adapter, off);
1190 if (addr)
1191 return addr;
1192
1193 if (adapter->ahw.pci_len0 == 0)
1194 off -= NETXEN_PCI_CRBSPACE;
1195
1196 mem_base = pci_resource_start(adapter->pdev, 0);
1197 *mem_ptr = ioremap(mem_base + (off & PAGE_MASK), PAGE_SIZE);
1198 if (*mem_ptr)
1199 addr = *mem_ptr + (off & (PAGE_SIZE - 1));
1200
1201 return addr;
1202}
1203
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001204static int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001205netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001206{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001207 unsigned long flags;
Narender Kumarf58dbd72009-12-02 15:46:18 +00001208 void __iomem *addr, *mem_ptr = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001209
Narender Kumarf58dbd72009-12-02 15:46:18 +00001210 addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
1211 if (!addr)
1212 return -EIO;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001213
Narender Kumarf58dbd72009-12-02 15:46:18 +00001214 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001215 netxen_nic_io_write_128M(adapter, addr, data);
Narender Kumarf58dbd72009-12-02 15:46:18 +00001216 } else { /* Window 0 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001217 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001218 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001219 writel(data, addr);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001220 netxen_nic_pci_set_crbwindow_128M(adapter,
1221 NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001222 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001223 }
1224
Narender Kumarf58dbd72009-12-02 15:46:18 +00001225 if (mem_ptr)
1226 iounmap(mem_ptr);
1227
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001228 return 0;
1229}
1230
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001231static u32
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001232netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001233{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001234 unsigned long flags;
Narender Kumarf58dbd72009-12-02 15:46:18 +00001235 void __iomem *addr, *mem_ptr = NULL;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001236 u32 data;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001237
Narender Kumarf58dbd72009-12-02 15:46:18 +00001238 addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
1239 if (!addr)
1240 return -EIO;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001241
Narender Kumarf58dbd72009-12-02 15:46:18 +00001242 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001243 data = netxen_nic_io_read_128M(adapter, addr);
Narender Kumarf58dbd72009-12-02 15:46:18 +00001244 } else { /* Window 0 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001245 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001246 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001247 data = readl(addr);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001248 netxen_nic_pci_set_crbwindow_128M(adapter,
1249 NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001250 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001251 }
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001252
Narender Kumarf58dbd72009-12-02 15:46:18 +00001253 if (mem_ptr)
1254 iounmap(mem_ptr);
1255
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001256 return data;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001257}
1258
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001259static int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001260netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001261{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001262 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001263 int rv;
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001264 void __iomem *addr = NULL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001265
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001266 rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001267
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001268 if (rv == 0) {
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001269 writel(data, addr);
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001270 return 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001271 }
1272
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001273 if (rv > 0) {
1274 /* indirect access */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001275 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001276 crb_win_lock(adapter);
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001277 netxen_nic_pci_set_crbwindow_2M(adapter, off);
1278 writel(data, addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001279 crb_win_unlock(adapter);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001280 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001281 return 0;
1282 }
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001283
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001284 dev_err(&adapter->pdev->dev,
1285 "%s: invalid offset: 0x%016lx\n", __func__, off);
1286 dump_stack();
1287 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001288}
1289
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001290static u32
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001291netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001292{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001293 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001294 int rv;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001295 u32 data;
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001296 void __iomem *addr = NULL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001297
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001298 rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001299
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001300 if (rv == 0)
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001301 return readl(addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001302
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001303 if (rv > 0) {
1304 /* indirect access */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001305 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001306 crb_win_lock(adapter);
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001307 netxen_nic_pci_set_crbwindow_2M(adapter, off);
1308 data = readl(addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001309 crb_win_unlock(adapter);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001310 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001311 return data;
1312 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001313
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001314 dev_err(&adapter->pdev->dev,
1315 "%s: invalid offset: 0x%016lx\n", __func__, off);
1316 dump_stack();
1317 return -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001318}
1319
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001320/* window 1 registers only */
1321static void netxen_nic_io_write_128M(struct netxen_adapter *adapter,
1322 void __iomem *addr, u32 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001323{
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001324 read_lock(&adapter->ahw.crb_lock);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001325 writel(data, addr);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001326 read_unlock(&adapter->ahw.crb_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001327}
1328
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001329static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter,
1330 void __iomem *addr)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001331{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001332 u32 val;
1333
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001334 read_lock(&adapter->ahw.crb_lock);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001335 val = readl(addr);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001336 read_unlock(&adapter->ahw.crb_lock);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001337
1338 return val;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001339}
1340
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001341static void netxen_nic_io_write_2M(struct netxen_adapter *adapter,
1342 void __iomem *addr, u32 data)
1343{
1344 writel(data, addr);
1345}
1346
1347static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter,
1348 void __iomem *addr)
1349{
1350 return readl(addr);
1351}
1352
1353void __iomem *
1354netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset)
1355{
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001356 void __iomem *addr = NULL;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001357
1358 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001359 if ((offset < NETXEN_CRB_PCIX_HOST2) &&
1360 (offset > NETXEN_CRB_PCIX_HOST))
1361 addr = PCI_OFFSET_SECOND_RANGE(adapter, offset);
1362 else
1363 addr = NETXEN_CRB_NORMALIZE(adapter, offset);
1364 } else {
1365 WARN_ON(netxen_nic_pci_get_crb_addr_2M(adapter,
1366 offset, &addr));
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001367 }
1368
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001369 return addr;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001370}
1371
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001372static int
1373netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
1374 u64 addr, u32 *start)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001375{
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001376 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1377 *start = (addr - NETXEN_ADDR_OCM0 + NETXEN_PCI_OCM0);
1378 return 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001379 } else if (ADDR_IN_RANGE(addr,
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001380 NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1381 *start = (addr - NETXEN_ADDR_OCM1 + NETXEN_PCI_OCM1);
1382 return 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001383 }
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001384
1385 return -EIO;
1386}
1387
1388static int
1389netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
1390 u64 addr, u32 *start)
1391{
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +00001392 u32 window;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001393
Sucheta Chakraborty14e2cfb2010-05-11 23:53:04 +00001394 window = OCM_WIN(addr);
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +00001395
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001396 writel(window, adapter->ahw.ocm_win_crb);
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +00001397 /* read back to flush */
1398 readl(adapter->ahw.ocm_win_crb);
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001399
1400 adapter->ahw.ocm_win = window;
1401 *start = NETXEN_PCI_OCM0_2M + GET_MEM_OFFS_2M(addr);
1402 return 0;
1403}
1404
1405static int
1406netxen_nic_pci_mem_access_direct(struct netxen_adapter *adapter, u64 off,
1407 u64 *data, int op)
1408{
1409 void __iomem *addr, *mem_ptr = NULL;
1410 resource_size_t mem_base;
Sucheta Chakraborty14e2cfb2010-05-11 23:53:04 +00001411 int ret;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001412 u32 start;
1413
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001414 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001415
1416 ret = adapter->pci_set_window(adapter, off, &start);
1417 if (ret != 0)
1418 goto unlock;
1419
Sucheta Chakraborty14e2cfb2010-05-11 23:53:04 +00001420 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1421 addr = adapter->ahw.pci_base0 + start;
1422 } else {
1423 addr = pci_base_offset(adapter, start);
1424 if (addr)
1425 goto noremap;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001426
Sucheta Chakraborty14e2cfb2010-05-11 23:53:04 +00001427 mem_base = pci_resource_start(adapter->pdev, 0) +
1428 (start & PAGE_MASK);
1429 mem_ptr = ioremap(mem_base, PAGE_SIZE);
1430 if (mem_ptr == NULL) {
1431 ret = -EIO;
1432 goto unlock;
1433 }
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001434
Sucheta Chakraborty14e2cfb2010-05-11 23:53:04 +00001435 addr = mem_ptr + (start & (PAGE_SIZE-1));
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001436 }
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001437noremap:
1438 if (op == 0) /* read */
1439 *data = readq(addr);
1440 else /* write */
1441 writeq(*data, addr);
1442
1443unlock:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001444 spin_unlock(&adapter->ahw.mem_lock);
1445
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001446 if (mem_ptr)
1447 iounmap(mem_ptr);
1448 return ret;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001449}
1450
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00001451void
1452netxen_pci_camqm_read_2M(struct netxen_adapter *adapter, u64 off, u64 *data)
1453{
1454 void __iomem *addr = adapter->ahw.pci_base0 +
1455 NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM);
1456
1457 spin_lock(&adapter->ahw.mem_lock);
1458 *data = readq(addr);
1459 spin_unlock(&adapter->ahw.mem_lock);
1460}
1461
1462void
1463netxen_pci_camqm_write_2M(struct netxen_adapter *adapter, u64 off, u64 data)
1464{
1465 void __iomem *addr = adapter->ahw.pci_base0 +
1466 NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM);
1467
1468 spin_lock(&adapter->ahw.mem_lock);
1469 writeq(data, addr);
1470 spin_unlock(&adapter->ahw.mem_lock);
1471}
1472
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001473#define MAX_CTL_CHECK 1000
1474
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001475static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001476netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001477 u64 off, u64 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001478{
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001479 int j, ret;
1480 u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001481 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001482
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001483 /* Only 64-bit aligned access */
1484 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001485 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001486
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001487 /* P2 has different SIU and MIU test agent base addr */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001488 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1489 NETXEN_ADDR_QDR_NET_MAX_P2)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001490 mem_crb = pci_base_offset(adapter,
1491 NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
1492 addr_hi = SIU_TEST_AGT_ADDR_HI;
1493 data_lo = SIU_TEST_AGT_WRDATA_LO;
1494 data_hi = SIU_TEST_AGT_WRDATA_HI;
1495 off_lo = off & SIU_TEST_AGT_ADDR_MASK;
1496 off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001497 goto correct;
1498 }
1499
1500 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001501 mem_crb = pci_base_offset(adapter,
1502 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
1503 addr_hi = MIU_TEST_AGT_ADDR_HI;
1504 data_lo = MIU_TEST_AGT_WRDATA_LO;
1505 data_hi = MIU_TEST_AGT_WRDATA_HI;
1506 off_lo = off & MIU_TEST_AGT_ADDR_MASK;
1507 off_hi = 0;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001508 goto correct;
1509 }
1510
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001511 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
1512 ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1513 if (adapter->ahw.pci_len0 != 0) {
1514 return netxen_nic_pci_mem_access_direct(adapter,
1515 off, &data, 1);
1516 }
1517 }
1518
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001519 return -EIO;
1520
1521correct:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001522 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001523 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001524
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001525 writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1526 writel(off_hi, (mem_crb + addr_hi));
1527 writel(data & 0xffffffff, (mem_crb + data_lo));
1528 writel((data >> 32) & 0xffffffff, (mem_crb + data_hi));
1529 writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
1530 writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
1531 (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001532
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001533 for (j = 0; j < MAX_CTL_CHECK; j++) {
1534 temp = readl((mem_crb + TEST_AGT_CTRL));
1535 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001536 break;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001537 }
1538
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001539 if (j >= MAX_CTL_CHECK) {
1540 if (printk_ratelimit())
1541 dev_err(&adapter->pdev->dev,
1542 "failed to write through agent\n");
1543 ret = -EIO;
1544 } else
1545 ret = 0;
1546
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001547 netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001548 spin_unlock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001549 return ret;
1550}
1551
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001552static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001553netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001554 u64 off, u64 *data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001555{
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001556 int j, ret;
1557 u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
1558 u64 val;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001559 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001560
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001561 /* Only 64-bit aligned access */
1562 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001563 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001564
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001565 /* P2 has different SIU and MIU test agent base addr */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001566 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1567 NETXEN_ADDR_QDR_NET_MAX_P2)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001568 mem_crb = pci_base_offset(adapter,
1569 NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
1570 addr_hi = SIU_TEST_AGT_ADDR_HI;
1571 data_lo = SIU_TEST_AGT_RDDATA_LO;
1572 data_hi = SIU_TEST_AGT_RDDATA_HI;
1573 off_lo = off & SIU_TEST_AGT_ADDR_MASK;
1574 off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001575 goto correct;
1576 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001577
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001578 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001579 mem_crb = pci_base_offset(adapter,
1580 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
1581 addr_hi = MIU_TEST_AGT_ADDR_HI;
1582 data_lo = MIU_TEST_AGT_RDDATA_LO;
1583 data_hi = MIU_TEST_AGT_RDDATA_HI;
1584 off_lo = off & MIU_TEST_AGT_ADDR_MASK;
1585 off_hi = 0;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001586 goto correct;
1587 }
1588
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001589 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
1590 ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1591 if (adapter->ahw.pci_len0 != 0) {
1592 return netxen_nic_pci_mem_access_direct(adapter,
1593 off, data, 0);
1594 }
1595 }
1596
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001597 return -EIO;
1598
1599correct:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001600 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001601 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001602
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001603 writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1604 writel(off_hi, (mem_crb + addr_hi));
1605 writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
1606 writel((TA_CTL_START|TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001607
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001608 for (j = 0; j < MAX_CTL_CHECK; j++) {
1609 temp = readl(mem_crb + TEST_AGT_CTRL);
1610 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001611 break;
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001612 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001613
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001614 if (j >= MAX_CTL_CHECK) {
1615 if (printk_ratelimit())
1616 dev_err(&adapter->pdev->dev,
1617 "failed to read through agent\n");
1618 ret = -EIO;
1619 } else {
1620
1621 temp = readl(mem_crb + data_hi);
1622 val = ((u64)temp << 32);
1623 val |= readl(mem_crb + data_lo);
1624 *data = val;
1625 ret = 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001626 }
1627
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001628 netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001629 spin_unlock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001630
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001631 return ret;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001632}
1633
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001634static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001635netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001636 u64 off, u64 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001637{
Sucheta Chakraborty215387a2010-05-11 23:53:03 +00001638 int j, ret;
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001639 u32 temp, off8;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001640 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001641
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001642 /* Only 64-bit aligned access */
1643 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001644 return -EIO;
1645
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001646 /* P3 onward, test agent base for MIU and SIU is same */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001647 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1648 NETXEN_ADDR_QDR_NET_MAX_P3)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001649 mem_crb = netxen_get_ioaddr(adapter,
1650 NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001651 goto correct;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001652 }
1653
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001654 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001655 mem_crb = netxen_get_ioaddr(adapter,
1656 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001657 goto correct;
1658 }
1659
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001660 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX))
1661 return netxen_nic_pci_mem_access_direct(adapter, off, &data, 1);
1662
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001663 return -EIO;
1664
1665correct:
Sucheta Chakraborty215387a2010-05-11 23:53:03 +00001666 off8 = off & 0xfffffff8;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001667
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001668 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001669
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001670 writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1671 writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001672
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001673 writel(data & 0xffffffff,
Sucheta Chakraborty215387a2010-05-11 23:53:03 +00001674 mem_crb + MIU_TEST_AGT_WRDATA_LO);
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001675 writel((data >> 32) & 0xffffffff,
Sucheta Chakraborty215387a2010-05-11 23:53:03 +00001676 mem_crb + MIU_TEST_AGT_WRDATA_HI);
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001677
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001678 writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
1679 writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
1680 (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001681
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001682 for (j = 0; j < MAX_CTL_CHECK; j++) {
1683 temp = readl(mem_crb + TEST_AGT_CTRL);
1684 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001685 break;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001686 }
1687
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001688 if (j >= MAX_CTL_CHECK) {
1689 if (printk_ratelimit())
1690 dev_err(&adapter->pdev->dev,
1691 "failed to write through agent\n");
1692 ret = -EIO;
1693 } else
1694 ret = 0;
1695
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001696 spin_unlock(&adapter->ahw.mem_lock);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001697
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001698 return ret;
1699}
1700
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001701static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001702netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001703 u64 off, u64 *data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001704{
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001705 int j, ret;
1706 u32 temp, off8;
Sucheta Chakraborty215387a2010-05-11 23:53:03 +00001707 u64 val;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001708 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001709
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001710 /* Only 64-bit aligned access */
1711 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001712 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001713
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001714 /* P3 onward, test agent base for MIU and SIU is same */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001715 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1716 NETXEN_ADDR_QDR_NET_MAX_P3)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001717 mem_crb = netxen_get_ioaddr(adapter,
1718 NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001719 goto correct;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001720 }
1721
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001722 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001723 mem_crb = netxen_get_ioaddr(adapter,
1724 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001725 goto correct;
1726 }
1727
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001728 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1729 return netxen_nic_pci_mem_access_direct(adapter,
1730 off, data, 0);
1731 }
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001732
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001733 return -EIO;
1734
1735correct:
Sucheta Chakraborty215387a2010-05-11 23:53:03 +00001736 off8 = off & 0xfffffff8;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001737
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001738 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001739
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001740 writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1741 writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
1742 writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
1743 writel((TA_CTL_START | TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001744
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001745 for (j = 0; j < MAX_CTL_CHECK; j++) {
1746 temp = readl(mem_crb + TEST_AGT_CTRL);
1747 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001748 break;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001749 }
1750
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001751 if (j >= MAX_CTL_CHECK) {
1752 if (printk_ratelimit())
1753 dev_err(&adapter->pdev->dev,
1754 "failed to read through agent\n");
1755 ret = -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001756 } else {
Sucheta Chakraborty215387a2010-05-11 23:53:03 +00001757 val = (u64)(readl(mem_crb + MIU_TEST_AGT_RDDATA_HI)) << 32;
1758 val |= readl(mem_crb + MIU_TEST_AGT_RDDATA_LO);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001759 *data = val;
1760 ret = 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001761 }
1762
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001763 spin_unlock(&adapter->ahw.mem_lock);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001764
1765 return ret;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001766}
1767
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001768void
1769netxen_setup_hwops(struct netxen_adapter *adapter)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001770{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001771 adapter->init_port = netxen_niu_xg_init_port;
1772 adapter->stop_port = netxen_niu_disable_xg_port;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001773
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001774 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1775 adapter->crb_read = netxen_nic_hw_read_wx_128M,
1776 adapter->crb_write = netxen_nic_hw_write_wx_128M,
1777 adapter->pci_set_window = netxen_nic_pci_set_window_128M,
1778 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M,
1779 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M,
1780 adapter->io_read = netxen_nic_io_read_128M,
1781 adapter->io_write = netxen_nic_io_write_128M,
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001782
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001783 adapter->macaddr_set = netxen_p2_nic_set_mac_addr;
1784 adapter->set_multi = netxen_p2_nic_set_multi;
1785 adapter->set_mtu = netxen_nic_set_mtu_xgb;
1786 adapter->set_promisc = netxen_p2_nic_set_promisc;
1787
1788 } else {
1789 adapter->crb_read = netxen_nic_hw_read_wx_2M,
1790 adapter->crb_write = netxen_nic_hw_write_wx_2M,
1791 adapter->pci_set_window = netxen_nic_pci_set_window_2M,
1792 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M,
1793 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M,
1794 adapter->io_read = netxen_nic_io_read_2M,
1795 adapter->io_write = netxen_nic_io_write_2M,
1796
1797 adapter->set_mtu = nx_fw_cmd_set_mtu;
1798 adapter->set_promisc = netxen_p3_nic_set_promisc;
1799 adapter->macaddr_set = netxen_p3_nic_set_mac_addr;
1800 adapter->set_multi = netxen_p3_nic_set_multi;
1801
1802 adapter->phy_read = nx_fw_cmd_query_phy;
1803 adapter->phy_write = nx_fw_cmd_set_phy;
1804 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001805}
1806
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001807int netxen_nic_get_board_info(struct netxen_adapter *adapter)
1808{
Dhananjay Phadke0dc6d9c2009-10-21 19:39:03 +00001809 int offset, board_type, magic;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001810 struct pci_dev *pdev = adapter->pdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001811
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001812 offset = NX_FW_MAGIC_OFFSET;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001813 if (netxen_rom_fast_read(adapter, offset, &magic))
1814 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001815
Dhananjay Phadke0dc6d9c2009-10-21 19:39:03 +00001816 if (magic != NETXEN_BDINFO_MAGIC) {
1817 dev_err(&pdev->dev, "invalid board config, magic=%08x\n",
1818 magic);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001819 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001820 }
1821
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001822 offset = NX_BRDTYPE_OFFSET;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001823 if (netxen_rom_fast_read(adapter, offset, &board_type))
1824 return -EIO;
1825
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001826 if (board_type == NETXEN_BRDTYPE_P3_4_GB_MM) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001827 u32 gpio = NXRD32(adapter, NETXEN_ROMUSB_GLB_PAD_GPIO_I);
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001828 if ((gpio & 0x8000) == 0)
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001829 board_type = NETXEN_BRDTYPE_P3_10G_TP;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001830 }
1831
amit salechadce87b92010-10-18 02:03:42 +00001832 adapter->ahw.board_type = board_type;
1833
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00001834 switch (board_type) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001835 case NETXEN_BRDTYPE_P2_SB35_4G:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001836 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001837 break;
1838 case NETXEN_BRDTYPE_P2_SB31_10G:
1839 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1840 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1841 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001842 case NETXEN_BRDTYPE_P3_HMEZ:
1843 case NETXEN_BRDTYPE_P3_XG_LOM:
1844 case NETXEN_BRDTYPE_P3_10G_CX4:
1845 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
1846 case NETXEN_BRDTYPE_P3_IMEZ:
1847 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
Dhananjay Phadkea70f9392008-08-01 03:14:56 -07001848 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
1849 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001850 case NETXEN_BRDTYPE_P3_10G_XFP:
1851 case NETXEN_BRDTYPE_P3_10000_BASE_T:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001852 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001853 break;
1854 case NETXEN_BRDTYPE_P1_BD:
1855 case NETXEN_BRDTYPE_P1_SB:
1856 case NETXEN_BRDTYPE_P1_SMAX:
1857 case NETXEN_BRDTYPE_P1_SOCK:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001858 case NETXEN_BRDTYPE_P3_REF_QG:
1859 case NETXEN_BRDTYPE_P3_4_GB:
1860 case NETXEN_BRDTYPE_P3_4_GB_MM:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001861 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001862 break;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001863 case NETXEN_BRDTYPE_P3_10G_TP:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001864 adapter->ahw.port_type = (adapter->portnum < 2) ?
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001865 NETXEN_NIC_XGBE : NETXEN_NIC_GBE;
1866 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001867 default:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001868 dev_err(&pdev->dev, "unknown board type %x\n", board_type);
1869 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001870 break;
1871 }
1872
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001873 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001874}
1875
1876/* NIU access sections */
stephen hemminger7e12bb02010-10-18 17:40:10 +00001877static int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001878{
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001879 new_mtu += MTU_FUDGE_FACTOR;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07001880 if (adapter->physical_port == 0)
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001881 NXWR32(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu);
Jeff Garzik47906542007-11-23 21:23:36 -05001882 else
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001883 NXWR32(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001884 return 0;
1885}
1886
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001887void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001888{
Al Viroa608ab92007-01-02 10:39:10 +00001889 __u32 status;
1890 __u32 autoneg;
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001891 __u32 port_mode;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001892
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001893 if (!netif_carrier_ok(adapter->netdev)) {
1894 adapter->link_speed = 0;
1895 adapter->link_duplex = -1;
1896 adapter->link_autoneg = AUTONEG_ENABLE;
1897 return;
1898 }
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001899
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001900 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001901 port_mode = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001902 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
1903 adapter->link_speed = SPEED_1000;
1904 adapter->link_duplex = DUPLEX_FULL;
1905 adapter->link_autoneg = AUTONEG_DISABLE;
1906 return;
1907 }
1908
Joe Perches8e95a202009-12-03 07:58:21 +00001909 if (adapter->phy_read &&
1910 adapter->phy_read(adapter,
1911 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
1912 &status) == 0) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001913 if (netxen_get_phy_link(status)) {
1914 switch (netxen_get_phy_speed(status)) {
1915 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001916 adapter->link_speed = SPEED_10;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001917 break;
1918 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001919 adapter->link_speed = SPEED_100;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001920 break;
1921 case 2:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001922 adapter->link_speed = SPEED_1000;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001923 break;
1924 default:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001925 adapter->link_speed = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001926 break;
1927 }
1928 switch (netxen_get_phy_duplex(status)) {
1929 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001930 adapter->link_duplex = DUPLEX_HALF;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001931 break;
1932 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001933 adapter->link_duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001934 break;
1935 default:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001936 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001937 break;
1938 }
Joe Perches8e95a202009-12-03 07:58:21 +00001939 if (adapter->phy_read &&
1940 adapter->phy_read(adapter,
1941 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
1942 &autoneg) != 0)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001943 adapter->link_autoneg = autoneg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001944 } else
1945 goto link_down;
1946 } else {
1947 link_down:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001948 adapter->link_speed = 0;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001949 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001950 }
1951 }
1952}
1953
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001954int
1955netxen_nic_wol_supported(struct netxen_adapter *adapter)
1956{
1957 u32 wol_cfg;
1958
1959 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
1960 return 0;
1961
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001962 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001963 if (wol_cfg & (1UL << adapter->portnum)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001964 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001965 if (wol_cfg & (1 << adapter->portnum))
1966 return 1;
1967 }
1968
1969 return 0;
1970}