blob: 0db36f190ba2ce0479e36241c8f7c77d1933fe08 [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;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800780 u64 word;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700781 int rv;
782
783 memset(&req, 0, sizeof(nx_nic_req_t));
784
Narender Kumar1bb482f2009-08-23 08:35:09 +0000785 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800786
787 word = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16);
788 req.req_hdr = cpu_to_le64(word);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700789
790 memcpy(&req.words[0], &adapter->coal, sizeof(adapter->coal));
791
792 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
793 if (rv != 0) {
794 printk(KERN_ERR "ERROR. Could not send "
795 "interrupt coalescing parameters\n");
796 }
797
798 return rv;
799}
800
Narender Kumar1bb482f2009-08-23 08:35:09 +0000801int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable)
802{
803 nx_nic_req_t req;
804 u64 word;
805 int rv = 0;
806
807 if ((adapter->flags & NETXEN_NIC_LRO_ENABLED) == enable)
808 return 0;
809
810 memset(&req, 0, sizeof(nx_nic_req_t));
811
812 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
813
814 word = NX_NIC_H2C_OPCODE_CONFIG_HW_LRO | ((u64)adapter->portnum << 16);
815 req.req_hdr = cpu_to_le64(word);
816
817 req.words[0] = cpu_to_le64(enable);
818
819 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
820 if (rv != 0) {
821 printk(KERN_ERR "ERROR. Could not send "
822 "configure hw lro request\n");
823 }
824
825 adapter->flags ^= NETXEN_NIC_LRO_ENABLED;
826
827 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
869 u64 key[] = { 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL,
870 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
871 0x255b0ec26d5a56daULL };
872
873
874 memset(&req, 0, sizeof(nx_nic_req_t));
875 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
876
877 word = NX_NIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16);
878 req.req_hdr = cpu_to_le64(word);
879
880 /*
881 * RSS request:
882 * bits 3-0: hash_method
883 * 5-4: hash_type_ipv4
884 * 7-6: hash_type_ipv6
885 * 8: enable
886 * 9: use indirection table
887 * 47-10: reserved
888 * 63-48: indirection table mask
889 */
890 word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) |
891 ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) |
892 ((u64)(enable & 0x1) << 8) |
893 ((0x7ULL) << 48);
894 req.words[0] = cpu_to_le64(word);
895 for (i = 0; i < 5; i++)
896 req.words[i+1] = cpu_to_le64(key[i]);
897
898
899 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
900 if (rv != 0) {
901 printk(KERN_ERR "%s: could not configure RSS\n",
902 adapter->netdev->name);
903 }
904
905 return rv;
906}
907
Dhananjay Phadke6598b162009-07-26 20:07:37 +0000908int netxen_config_ipaddr(struct netxen_adapter *adapter, u32 ip, int cmd)
909{
910 nx_nic_req_t req;
911 u64 word;
912 int rv;
913
914 memset(&req, 0, sizeof(nx_nic_req_t));
915 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
916
917 word = NX_NIC_H2C_OPCODE_CONFIG_IPADDR | ((u64)adapter->portnum << 16);
918 req.req_hdr = cpu_to_le64(word);
919
920 req.words[0] = cpu_to_le64(cmd);
921 req.words[1] = cpu_to_le64(ip);
922
923 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
924 if (rv != 0) {
925 printk(KERN_ERR "%s: could not notify %s IP 0x%x reuqest\n",
926 adapter->netdev->name,
927 (cmd == NX_IP_UP) ? "Add" : "Remove", ip);
928 }
929 return rv;
930}
931
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000932int netxen_linkevent_request(struct netxen_adapter *adapter, int enable)
933{
934 nx_nic_req_t req;
935 u64 word;
936 int rv;
937
938 memset(&req, 0, sizeof(nx_nic_req_t));
939 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
940
941 word = NX_NIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16);
942 req.req_hdr = cpu_to_le64(word);
Dhananjay Phadke22527862009-05-05 19:05:06 +0000943 req.words[0] = cpu_to_le64(enable | (enable << 8));
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000944
945 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
946 if (rv != 0) {
947 printk(KERN_ERR "%s: could not configure link notification\n",
948 adapter->netdev->name);
949 }
950
951 return rv;
952}
953
Narender Kumar1bb482f2009-08-23 08:35:09 +0000954int netxen_send_lro_cleanup(struct netxen_adapter *adapter)
955{
956 nx_nic_req_t req;
957 u64 word;
958 int rv;
959
960 memset(&req, 0, sizeof(nx_nic_req_t));
961 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
962
963 word = NX_NIC_H2C_OPCODE_LRO_REQUEST |
964 ((u64)adapter->portnum << 16) |
965 ((u64)NX_NIC_LRO_REQUEST_CLEANUP << 56) ;
966
967 req.req_hdr = cpu_to_le64(word);
968
969 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
970 if (rv != 0) {
971 printk(KERN_ERR "%s: could not cleanup lro flows\n",
972 adapter->netdev->name);
973 }
974 return rv;
975}
976
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400977/*
978 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
979 * @returns 0 on success, negative on failure
980 */
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700981
982#define MTU_FUDGE_FACTOR 100
983
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400984int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
985{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700986 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700987 int max_mtu;
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700988 int rc = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400989
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700990 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
991 max_mtu = P3_MAX_MTU;
992 else
993 max_mtu = P2_MAX_MTU;
994
995 if (mtu > max_mtu) {
996 printk(KERN_ERR "%s: mtu > %d bytes unsupported\n",
997 netdev->name, max_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400998 return -EINVAL;
999 }
1000
Amit S. Kale80922fb2006-12-04 09:18:00 -08001001 if (adapter->set_mtu)
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001002 rc = adapter->set_mtu(adapter, mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001003
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001004 if (!rc)
1005 netdev->mtu = mtu;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001006
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001007 return rc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001008}
1009
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001010static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
Al Virof305f782007-12-22 19:44:00 +00001011 int size, __le32 * buf)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001012{
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001013 int i, v, addr;
Al Virof305f782007-12-22 19:44:00 +00001014 __le32 *ptr32;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001015
1016 addr = base;
1017 ptr32 = buf;
1018 for (i = 0; i < size / sizeof(u32); i++) {
Al Virof305f782007-12-22 19:44:00 +00001019 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001020 return -1;
Al Virof305f782007-12-22 19:44:00 +00001021 *ptr32 = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001022 ptr32++;
1023 addr += sizeof(u32);
1024 }
1025 if ((char *)buf + size > (char *)ptr32) {
Al Virof305f782007-12-22 19:44:00 +00001026 __le32 local;
1027 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001028 return -1;
Al Virof305f782007-12-22 19:44:00 +00001029 local = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001030 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
1031 }
1032
1033 return 0;
1034}
1035
Amit Kumar Salechaa03d2452010-01-14 01:53:21 +00001036int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 *mac)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001037{
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001038 __le32 *pmac = (__le32 *) mac;
1039 u32 offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001040
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001041 offset = NX_FW_MAC_ADDR_OFFSET + (adapter->portnum * sizeof(u64));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001042
1043 if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001044 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001045
Al Virof305f782007-12-22 19:44:00 +00001046 if (*mac == cpu_to_le64(~0ULL)) {
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001047
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001048 offset = NX_OLD_MAC_ADDR_OFFSET +
1049 (adapter->portnum * sizeof(u64));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001050
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001051 if (netxen_get_flash_block(adapter,
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001052 offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001053 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001054
Al Virof305f782007-12-22 19:44:00 +00001055 if (*mac == cpu_to_le64(~0ULL))
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001056 return -1;
1057 }
1058 return 0;
1059}
1060
Amit Kumar Salechaa03d2452010-01-14 01:53:21 +00001061int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, u64 *mac)
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001062{
1063 uint32_t crbaddr, mac_hi, mac_lo;
1064 int pci_func = adapter->ahw.pci_func;
1065
1066 crbaddr = CRB_MAC_BLOCK_START +
1067 (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1));
1068
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001069 mac_lo = NXRD32(adapter, crbaddr);
1070 mac_hi = NXRD32(adapter, crbaddr+4);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001071
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001072 if (pci_func & 1)
Dhananjay Phadke2edbb452009-01-14 20:47:30 -08001073 *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001074 else
Dhananjay Phadke2edbb452009-01-14 20:47:30 -08001075 *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001076
1077 return 0;
1078}
1079
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001080/*
1081 * Changes the CRB window to the specified window.
1082 */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001083static void
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001084netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter,
1085 u32 window)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001086{
1087 void __iomem *offset;
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001088 int count = 10;
1089 u8 func = adapter->ahw.pci_func;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001090
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001091 if (adapter->ahw.crb_win == window)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001092 return;
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001093
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001094 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1095 NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001096
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001097 writel(window, offset);
1098 do {
1099 if (window == readl(offset))
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001100 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001101
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001102 if (printk_ratelimit())
1103 dev_warn(&adapter->pdev->dev,
1104 "failed to set CRB window to %d\n",
1105 (window == NETXEN_WINDOW_ONE));
1106 udelay(1);
1107
1108 } while (--count > 0);
1109
1110 if (count > 0)
1111 adapter->ahw.crb_win = window;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001112}
1113
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001114/*
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001115 * Returns < 0 if off is not valid,
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001116 * 1 if window access is needed. 'off' is set to offset from
1117 * CRB space in 128M pci map
1118 * 0 if no window access is needed. 'off' is set to 2M addr
1119 * In: 'off' is offset from base in 128M pci map
1120 */
1121static int
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001122netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter,
1123 ulong off, void __iomem **addr)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001124{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001125 crb_128M_2M_sub_block_map_t *m;
1126
1127
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001128 if ((off >= NETXEN_CRB_MAX) || (off < NETXEN_PCI_CRBSPACE))
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001129 return -EINVAL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001130
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001131 off -= NETXEN_PCI_CRBSPACE;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001132
1133 /*
1134 * Try direct map
1135 */
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001136 m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)];
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001137
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001138 if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) {
1139 *addr = adapter->ahw.pci_base0 + m->start_2M +
1140 (off - m->start_128M);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001141 return 0;
1142 }
1143
1144 /*
1145 * Not in direct map, use crb window
1146 */
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001147 *addr = adapter->ahw.pci_base0 + CRB_INDIRECT_2M +
1148 (off & MASK(16));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001149 return 1;
1150}
1151
1152/*
1153 * In: 'off' is offset from CRB space in 128M pci map
1154 * Out: 'off' is 2M pci map addr
1155 * side effect: lock crb window
1156 */
1157static void
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001158netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001159{
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001160 u32 window;
1161 void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001162
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001163 off -= NETXEN_PCI_CRBSPACE;
1164
1165 window = CRB_HI(off);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001166
1167 if (adapter->ahw.crb_win == window)
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001168 return;
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001169
1170 writel(window, addr);
1171 if (readl(addr) != window) {
1172 if (printk_ratelimit())
1173 dev_warn(&adapter->pdev->dev,
1174 "failed to set CRB window to %d off 0x%lx\n",
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001175 window, off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001176 }
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001177 adapter->ahw.crb_win = window;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001178}
1179
Narender Kumarf58dbd72009-12-02 15:46:18 +00001180static void __iomem *
1181netxen_nic_map_indirect_address_128M(struct netxen_adapter *adapter,
1182 ulong win_off, void __iomem **mem_ptr)
1183{
1184 ulong off = win_off;
1185 void __iomem *addr;
1186 resource_size_t mem_base;
1187
1188 if (ADDR_IN_WINDOW1(win_off))
1189 off = NETXEN_CRB_NORMAL(win_off);
1190
1191 addr = pci_base_offset(adapter, off);
1192 if (addr)
1193 return addr;
1194
1195 if (adapter->ahw.pci_len0 == 0)
1196 off -= NETXEN_PCI_CRBSPACE;
1197
1198 mem_base = pci_resource_start(adapter->pdev, 0);
1199 *mem_ptr = ioremap(mem_base + (off & PAGE_MASK), PAGE_SIZE);
1200 if (*mem_ptr)
1201 addr = *mem_ptr + (off & (PAGE_SIZE - 1));
1202
1203 return addr;
1204}
1205
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001206static int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001207netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001208{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001209 unsigned long flags;
Narender Kumarf58dbd72009-12-02 15:46:18 +00001210 void __iomem *addr, *mem_ptr = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001211
Narender Kumarf58dbd72009-12-02 15:46:18 +00001212 addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
1213 if (!addr)
1214 return -EIO;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001215
Narender Kumarf58dbd72009-12-02 15:46:18 +00001216 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001217 netxen_nic_io_write_128M(adapter, addr, data);
Narender Kumarf58dbd72009-12-02 15:46:18 +00001218 } else { /* Window 0 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001219 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001220 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001221 writel(data, addr);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001222 netxen_nic_pci_set_crbwindow_128M(adapter,
1223 NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001224 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001225 }
1226
Narender Kumarf58dbd72009-12-02 15:46:18 +00001227 if (mem_ptr)
1228 iounmap(mem_ptr);
1229
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001230 return 0;
1231}
1232
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001233static u32
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001234netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001235{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001236 unsigned long flags;
Narender Kumarf58dbd72009-12-02 15:46:18 +00001237 void __iomem *addr, *mem_ptr = NULL;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001238 u32 data;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001239
Narender Kumarf58dbd72009-12-02 15:46:18 +00001240 addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
1241 if (!addr)
1242 return -EIO;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001243
Narender Kumarf58dbd72009-12-02 15:46:18 +00001244 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001245 data = netxen_nic_io_read_128M(adapter, addr);
Narender Kumarf58dbd72009-12-02 15:46:18 +00001246 } else { /* Window 0 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001247 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001248 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001249 data = readl(addr);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001250 netxen_nic_pci_set_crbwindow_128M(adapter,
1251 NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001252 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001253 }
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001254
Narender Kumarf58dbd72009-12-02 15:46:18 +00001255 if (mem_ptr)
1256 iounmap(mem_ptr);
1257
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001258 return data;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001259}
1260
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001261static int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001262netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001263{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001264 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001265 int rv;
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001266 void __iomem *addr = NULL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001267
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001268 rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001269
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001270 if (rv == 0) {
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001271 writel(data, addr);
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001272 return 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001273 }
1274
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001275 if (rv > 0) {
1276 /* indirect access */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001277 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001278 crb_win_lock(adapter);
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001279 netxen_nic_pci_set_crbwindow_2M(adapter, off);
1280 writel(data, addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001281 crb_win_unlock(adapter);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001282 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001283 return 0;
1284 }
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001285
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001286 dev_err(&adapter->pdev->dev,
1287 "%s: invalid offset: 0x%016lx\n", __func__, off);
1288 dump_stack();
1289 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001290}
1291
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001292static u32
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001293netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001294{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001295 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001296 int rv;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001297 u32 data;
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001298 void __iomem *addr = NULL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001299
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001300 rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001301
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001302 if (rv == 0)
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001303 return readl(addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001304
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001305 if (rv > 0) {
1306 /* indirect access */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001307 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001308 crb_win_lock(adapter);
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001309 netxen_nic_pci_set_crbwindow_2M(adapter, off);
1310 data = readl(addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001311 crb_win_unlock(adapter);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001312 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001313 return data;
1314 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001315
Dhananjay Phadke7cecdca2009-10-16 15:50:10 +00001316 dev_err(&adapter->pdev->dev,
1317 "%s: invalid offset: 0x%016lx\n", __func__, off);
1318 dump_stack();
1319 return -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001320}
1321
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001322/* window 1 registers only */
1323static void netxen_nic_io_write_128M(struct netxen_adapter *adapter,
1324 void __iomem *addr, u32 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001325{
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001326 read_lock(&adapter->ahw.crb_lock);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001327 writel(data, addr);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001328 read_unlock(&adapter->ahw.crb_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001329}
1330
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001331static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter,
1332 void __iomem *addr)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001333{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001334 u32 val;
1335
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001336 read_lock(&adapter->ahw.crb_lock);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001337 val = readl(addr);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001338 read_unlock(&adapter->ahw.crb_lock);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001339
1340 return val;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001341}
1342
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001343static void netxen_nic_io_write_2M(struct netxen_adapter *adapter,
1344 void __iomem *addr, u32 data)
1345{
1346 writel(data, addr);
1347}
1348
1349static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter,
1350 void __iomem *addr)
1351{
1352 return readl(addr);
1353}
1354
1355void __iomem *
1356netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset)
1357{
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001358 void __iomem *addr = NULL;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001359
1360 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001361 if ((offset < NETXEN_CRB_PCIX_HOST2) &&
1362 (offset > NETXEN_CRB_PCIX_HOST))
1363 addr = PCI_OFFSET_SECOND_RANGE(adapter, offset);
1364 else
1365 addr = NETXEN_CRB_NORMALIZE(adapter, offset);
1366 } else {
1367 WARN_ON(netxen_nic_pci_get_crb_addr_2M(adapter,
1368 offset, &addr));
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001369 }
1370
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001371 return addr;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001372}
1373
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001374static int
1375netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
1376 u64 addr, u32 *start)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001377{
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001378 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1379 *start = (addr - NETXEN_ADDR_OCM0 + NETXEN_PCI_OCM0);
1380 return 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001381 } else if (ADDR_IN_RANGE(addr,
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001382 NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1383 *start = (addr - NETXEN_ADDR_OCM1 + NETXEN_PCI_OCM1);
1384 return 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001385 }
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001386
1387 return -EIO;
1388}
1389
1390static int
1391netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
1392 u64 addr, u32 *start)
1393{
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +00001394 u32 window;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001395 struct pci_dev *pdev = adapter->pdev;
1396
1397 if ((addr & 0x00ff800) == 0xff800) {
1398 if (printk_ratelimit())
1399 dev_warn(&pdev->dev, "QM access not handled\n");
1400 return -EIO;
1401 }
1402
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +00001403 if (NX_IS_REVISION_P3P(adapter->ahw.revision_id))
1404 window = OCM_WIN_P3P(addr);
1405 else
1406 window = OCM_WIN(addr);
1407
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001408 writel(window, adapter->ahw.ocm_win_crb);
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +00001409 /* read back to flush */
1410 readl(adapter->ahw.ocm_win_crb);
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001411
1412 adapter->ahw.ocm_win = window;
1413 *start = NETXEN_PCI_OCM0_2M + GET_MEM_OFFS_2M(addr);
1414 return 0;
1415}
1416
1417static int
1418netxen_nic_pci_mem_access_direct(struct netxen_adapter *adapter, u64 off,
1419 u64 *data, int op)
1420{
1421 void __iomem *addr, *mem_ptr = NULL;
1422 resource_size_t mem_base;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001423 int ret = -EIO;
1424 u32 start;
1425
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001426 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001427
1428 ret = adapter->pci_set_window(adapter, off, &start);
1429 if (ret != 0)
1430 goto unlock;
1431
1432 addr = pci_base_offset(adapter, start);
1433 if (addr)
1434 goto noremap;
1435
1436 mem_base = pci_resource_start(adapter->pdev, 0) + (start & PAGE_MASK);
1437
1438 mem_ptr = ioremap(mem_base, PAGE_SIZE);
1439 if (mem_ptr == NULL) {
1440 ret = -EIO;
1441 goto unlock;
1442 }
1443
1444 addr = mem_ptr + (start & (PAGE_SIZE - 1));
1445
1446noremap:
1447 if (op == 0) /* read */
1448 *data = readq(addr);
1449 else /* write */
1450 writeq(*data, addr);
1451
1452unlock:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001453 spin_unlock(&adapter->ahw.mem_lock);
1454
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001455 if (mem_ptr)
1456 iounmap(mem_ptr);
1457 return ret;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001458}
1459
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001460#define MAX_CTL_CHECK 1000
1461
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001462static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001463netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001464 u64 off, u64 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001465{
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001466 int j, ret;
1467 u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001468 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001469
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001470 /* Only 64-bit aligned access */
1471 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001472 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001473
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001474 /* P2 has different SIU and MIU test agent base addr */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001475 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1476 NETXEN_ADDR_QDR_NET_MAX_P2)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001477 mem_crb = pci_base_offset(adapter,
1478 NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
1479 addr_hi = SIU_TEST_AGT_ADDR_HI;
1480 data_lo = SIU_TEST_AGT_WRDATA_LO;
1481 data_hi = SIU_TEST_AGT_WRDATA_HI;
1482 off_lo = off & SIU_TEST_AGT_ADDR_MASK;
1483 off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001484 goto correct;
1485 }
1486
1487 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001488 mem_crb = pci_base_offset(adapter,
1489 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
1490 addr_hi = MIU_TEST_AGT_ADDR_HI;
1491 data_lo = MIU_TEST_AGT_WRDATA_LO;
1492 data_hi = MIU_TEST_AGT_WRDATA_HI;
1493 off_lo = off & MIU_TEST_AGT_ADDR_MASK;
1494 off_hi = 0;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001495 goto correct;
1496 }
1497
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001498 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
1499 ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1500 if (adapter->ahw.pci_len0 != 0) {
1501 return netxen_nic_pci_mem_access_direct(adapter,
1502 off, &data, 1);
1503 }
1504 }
1505
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001506 return -EIO;
1507
1508correct:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001509 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001510 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001511
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001512 writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1513 writel(off_hi, (mem_crb + addr_hi));
1514 writel(data & 0xffffffff, (mem_crb + data_lo));
1515 writel((data >> 32) & 0xffffffff, (mem_crb + data_hi));
1516 writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
1517 writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
1518 (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001519
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001520 for (j = 0; j < MAX_CTL_CHECK; j++) {
1521 temp = readl((mem_crb + TEST_AGT_CTRL));
1522 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001523 break;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001524 }
1525
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001526 if (j >= MAX_CTL_CHECK) {
1527 if (printk_ratelimit())
1528 dev_err(&adapter->pdev->dev,
1529 "failed to write through agent\n");
1530 ret = -EIO;
1531 } else
1532 ret = 0;
1533
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001534 netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001535 spin_unlock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001536 return ret;
1537}
1538
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001539static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001540netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001541 u64 off, u64 *data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001542{
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001543 int j, ret;
1544 u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
1545 u64 val;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001546 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001547
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001548 /* Only 64-bit aligned access */
1549 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001550 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001551
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001552 /* P2 has different SIU and MIU test agent base addr */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001553 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1554 NETXEN_ADDR_QDR_NET_MAX_P2)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001555 mem_crb = pci_base_offset(adapter,
1556 NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
1557 addr_hi = SIU_TEST_AGT_ADDR_HI;
1558 data_lo = SIU_TEST_AGT_RDDATA_LO;
1559 data_hi = SIU_TEST_AGT_RDDATA_HI;
1560 off_lo = off & SIU_TEST_AGT_ADDR_MASK;
1561 off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001562 goto correct;
1563 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001564
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001565 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001566 mem_crb = pci_base_offset(adapter,
1567 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
1568 addr_hi = MIU_TEST_AGT_ADDR_HI;
1569 data_lo = MIU_TEST_AGT_RDDATA_LO;
1570 data_hi = MIU_TEST_AGT_RDDATA_HI;
1571 off_lo = off & MIU_TEST_AGT_ADDR_MASK;
1572 off_hi = 0;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001573 goto correct;
1574 }
1575
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001576 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
1577 ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1578 if (adapter->ahw.pci_len0 != 0) {
1579 return netxen_nic_pci_mem_access_direct(adapter,
1580 off, data, 0);
1581 }
1582 }
1583
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001584 return -EIO;
1585
1586correct:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001587 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001588 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001589
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001590 writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1591 writel(off_hi, (mem_crb + addr_hi));
1592 writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
1593 writel((TA_CTL_START|TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001594
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001595 for (j = 0; j < MAX_CTL_CHECK; j++) {
1596 temp = readl(mem_crb + TEST_AGT_CTRL);
1597 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001598 break;
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001599 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001600
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001601 if (j >= MAX_CTL_CHECK) {
1602 if (printk_ratelimit())
1603 dev_err(&adapter->pdev->dev,
1604 "failed to read through agent\n");
1605 ret = -EIO;
1606 } else {
1607
1608 temp = readl(mem_crb + data_hi);
1609 val = ((u64)temp << 32);
1610 val |= readl(mem_crb + data_lo);
1611 *data = val;
1612 ret = 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001613 }
1614
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001615 netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001616 spin_unlock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001617
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001618 return ret;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001619}
1620
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001621static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001622netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001623 u64 off, u64 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001624{
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001625 int i, j, ret;
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001626 u32 temp, off8;
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001627 u64 stride;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001628 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001629
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001630 /* Only 64-bit aligned access */
1631 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001632 return -EIO;
1633
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001634 /* P3 onward, test agent base for MIU and SIU is same */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001635 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1636 NETXEN_ADDR_QDR_NET_MAX_P3)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001637 mem_crb = netxen_get_ioaddr(adapter,
1638 NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001639 goto correct;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001640 }
1641
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001642 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001643 mem_crb = netxen_get_ioaddr(adapter,
1644 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001645 goto correct;
1646 }
1647
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001648 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX))
1649 return netxen_nic_pci_mem_access_direct(adapter, off, &data, 1);
1650
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001651 return -EIO;
1652
1653correct:
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001654 stride = NX_IS_REVISION_P3P(adapter->ahw.revision_id) ? 16 : 8;
1655
1656 off8 = off & ~(stride-1);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001657
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001658 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001659
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001660 writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1661 writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001662
1663 i = 0;
1664 if (stride == 16) {
1665 writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
1666 writel((TA_CTL_START | TA_CTL_ENABLE),
1667 (mem_crb + TEST_AGT_CTRL));
1668
1669 for (j = 0; j < MAX_CTL_CHECK; j++) {
1670 temp = readl(mem_crb + TEST_AGT_CTRL);
1671 if ((temp & TA_CTL_BUSY) == 0)
1672 break;
1673 }
1674
1675 if (j >= MAX_CTL_CHECK) {
1676 ret = -EIO;
1677 goto done;
1678 }
1679
1680 i = (off & 0xf) ? 0 : 2;
1681 writel(readl(mem_crb + MIU_TEST_AGT_RDDATA(i)),
1682 mem_crb + MIU_TEST_AGT_WRDATA(i));
1683 writel(readl(mem_crb + MIU_TEST_AGT_RDDATA(i+1)),
1684 mem_crb + MIU_TEST_AGT_WRDATA(i+1));
1685 i = (off & 0xf) ? 2 : 0;
1686 }
1687
1688 writel(data & 0xffffffff,
1689 mem_crb + MIU_TEST_AGT_WRDATA(i));
1690 writel((data >> 32) & 0xffffffff,
1691 mem_crb + MIU_TEST_AGT_WRDATA(i+1));
1692
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001693 writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
1694 writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
1695 (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001696
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001697 for (j = 0; j < MAX_CTL_CHECK; j++) {
1698 temp = readl(mem_crb + TEST_AGT_CTRL);
1699 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001700 break;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001701 }
1702
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001703 if (j >= MAX_CTL_CHECK) {
1704 if (printk_ratelimit())
1705 dev_err(&adapter->pdev->dev,
1706 "failed to write through agent\n");
1707 ret = -EIO;
1708 } else
1709 ret = 0;
1710
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001711done:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001712 spin_unlock(&adapter->ahw.mem_lock);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001713
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001714 return ret;
1715}
1716
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001717static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001718netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001719 u64 off, u64 *data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001720{
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001721 int j, ret;
1722 u32 temp, off8;
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001723 u64 val, stride;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001724 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001725
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001726 /* Only 64-bit aligned access */
1727 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001728 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001729
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001730 /* P3 onward, test agent base for MIU and SIU is same */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001731 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1732 NETXEN_ADDR_QDR_NET_MAX_P3)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001733 mem_crb = netxen_get_ioaddr(adapter,
1734 NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001735 goto correct;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001736 }
1737
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001738 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001739 mem_crb = netxen_get_ioaddr(adapter,
1740 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001741 goto correct;
1742 }
1743
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001744 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1745 return netxen_nic_pci_mem_access_direct(adapter,
1746 off, data, 0);
1747 }
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001748
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001749 return -EIO;
1750
1751correct:
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001752 stride = NX_IS_REVISION_P3P(adapter->ahw.revision_id) ? 16 : 8;
1753
1754 off8 = off & ~(stride-1);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001755
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001756 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001757
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001758 writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1759 writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
1760 writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
1761 writel((TA_CTL_START | TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001762
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001763 for (j = 0; j < MAX_CTL_CHECK; j++) {
1764 temp = readl(mem_crb + TEST_AGT_CTRL);
1765 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001766 break;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001767 }
1768
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001769 if (j >= MAX_CTL_CHECK) {
1770 if (printk_ratelimit())
1771 dev_err(&adapter->pdev->dev,
1772 "failed to read through agent\n");
1773 ret = -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001774 } else {
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001775 off8 = MIU_TEST_AGT_RDDATA_LO;
1776 if ((stride == 16) && (off & 0xf))
1777 off8 = MIU_TEST_AGT_RDDATA_UPPER_LO;
1778
1779 temp = readl(mem_crb + off8 + 4);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001780 val = (u64)temp << 32;
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001781 val |= readl(mem_crb + off8);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001782 *data = val;
1783 ret = 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001784 }
1785
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001786 spin_unlock(&adapter->ahw.mem_lock);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001787
1788 return ret;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001789}
1790
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001791void
1792netxen_setup_hwops(struct netxen_adapter *adapter)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001793{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001794 adapter->init_port = netxen_niu_xg_init_port;
1795 adapter->stop_port = netxen_niu_disable_xg_port;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001796
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001797 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1798 adapter->crb_read = netxen_nic_hw_read_wx_128M,
1799 adapter->crb_write = netxen_nic_hw_write_wx_128M,
1800 adapter->pci_set_window = netxen_nic_pci_set_window_128M,
1801 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M,
1802 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M,
1803 adapter->io_read = netxen_nic_io_read_128M,
1804 adapter->io_write = netxen_nic_io_write_128M,
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001805
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001806 adapter->macaddr_set = netxen_p2_nic_set_mac_addr;
1807 adapter->set_multi = netxen_p2_nic_set_multi;
1808 adapter->set_mtu = netxen_nic_set_mtu_xgb;
1809 adapter->set_promisc = netxen_p2_nic_set_promisc;
1810
1811 } else {
1812 adapter->crb_read = netxen_nic_hw_read_wx_2M,
1813 adapter->crb_write = netxen_nic_hw_write_wx_2M,
1814 adapter->pci_set_window = netxen_nic_pci_set_window_2M,
1815 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M,
1816 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M,
1817 adapter->io_read = netxen_nic_io_read_2M,
1818 adapter->io_write = netxen_nic_io_write_2M,
1819
1820 adapter->set_mtu = nx_fw_cmd_set_mtu;
1821 adapter->set_promisc = netxen_p3_nic_set_promisc;
1822 adapter->macaddr_set = netxen_p3_nic_set_mac_addr;
1823 adapter->set_multi = netxen_p3_nic_set_multi;
1824
1825 adapter->phy_read = nx_fw_cmd_query_phy;
1826 adapter->phy_write = nx_fw_cmd_set_phy;
1827 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001828}
1829
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001830int netxen_nic_get_board_info(struct netxen_adapter *adapter)
1831{
Dhananjay Phadke0dc6d9c2009-10-21 19:39:03 +00001832 int offset, board_type, magic;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001833 struct pci_dev *pdev = adapter->pdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001834
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001835 offset = NX_FW_MAGIC_OFFSET;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001836 if (netxen_rom_fast_read(adapter, offset, &magic))
1837 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001838
Dhananjay Phadke0dc6d9c2009-10-21 19:39:03 +00001839 if (magic != NETXEN_BDINFO_MAGIC) {
1840 dev_err(&pdev->dev, "invalid board config, magic=%08x\n",
1841 magic);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001842 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001843 }
1844
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001845 offset = NX_BRDTYPE_OFFSET;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001846 if (netxen_rom_fast_read(adapter, offset, &board_type))
1847 return -EIO;
1848
1849 adapter->ahw.board_type = board_type;
1850
1851 if (board_type == NETXEN_BRDTYPE_P3_4_GB_MM) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001852 u32 gpio = NXRD32(adapter, NETXEN_ROMUSB_GLB_PAD_GPIO_I);
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001853 if ((gpio & 0x8000) == 0)
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001854 board_type = NETXEN_BRDTYPE_P3_10G_TP;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001855 }
1856
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00001857 switch (board_type) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001858 case NETXEN_BRDTYPE_P2_SB35_4G:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001859 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001860 break;
1861 case NETXEN_BRDTYPE_P2_SB31_10G:
1862 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1863 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1864 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001865 case NETXEN_BRDTYPE_P3_HMEZ:
1866 case NETXEN_BRDTYPE_P3_XG_LOM:
1867 case NETXEN_BRDTYPE_P3_10G_CX4:
1868 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
1869 case NETXEN_BRDTYPE_P3_IMEZ:
1870 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
Dhananjay Phadkea70f9392008-08-01 03:14:56 -07001871 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
1872 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001873 case NETXEN_BRDTYPE_P3_10G_XFP:
1874 case NETXEN_BRDTYPE_P3_10000_BASE_T:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001875 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001876 break;
1877 case NETXEN_BRDTYPE_P1_BD:
1878 case NETXEN_BRDTYPE_P1_SB:
1879 case NETXEN_BRDTYPE_P1_SMAX:
1880 case NETXEN_BRDTYPE_P1_SOCK:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001881 case NETXEN_BRDTYPE_P3_REF_QG:
1882 case NETXEN_BRDTYPE_P3_4_GB:
1883 case NETXEN_BRDTYPE_P3_4_GB_MM:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001884 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001885 break;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001886 case NETXEN_BRDTYPE_P3_10G_TP:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001887 adapter->ahw.port_type = (adapter->portnum < 2) ?
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001888 NETXEN_NIC_XGBE : NETXEN_NIC_GBE;
1889 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001890 default:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001891 dev_err(&pdev->dev, "unknown board type %x\n", board_type);
1892 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001893 break;
1894 }
1895
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001896 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001897}
1898
1899/* NIU access sections */
1900
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001901int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001902{
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001903 new_mtu += MTU_FUDGE_FACTOR;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001904 NXWR32(adapter, NETXEN_NIU_GB_MAX_FRAME_SIZE(adapter->physical_port),
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07001905 new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001906 return 0;
1907}
1908
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001909int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001910{
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001911 new_mtu += MTU_FUDGE_FACTOR;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07001912 if (adapter->physical_port == 0)
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001913 NXWR32(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu);
Jeff Garzik47906542007-11-23 21:23:36 -05001914 else
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001915 NXWR32(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001916 return 0;
1917}
1918
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001919void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001920{
Al Viroa608ab9c2007-01-02 10:39:10 +00001921 __u32 status;
1922 __u32 autoneg;
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001923 __u32 port_mode;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001924
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001925 if (!netif_carrier_ok(adapter->netdev)) {
1926 adapter->link_speed = 0;
1927 adapter->link_duplex = -1;
1928 adapter->link_autoneg = AUTONEG_ENABLE;
1929 return;
1930 }
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001931
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001932 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001933 port_mode = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001934 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
1935 adapter->link_speed = SPEED_1000;
1936 adapter->link_duplex = DUPLEX_FULL;
1937 adapter->link_autoneg = AUTONEG_DISABLE;
1938 return;
1939 }
1940
Joe Perches8e95a202009-12-03 07:58:21 +00001941 if (adapter->phy_read &&
1942 adapter->phy_read(adapter,
1943 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
1944 &status) == 0) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001945 if (netxen_get_phy_link(status)) {
1946 switch (netxen_get_phy_speed(status)) {
1947 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001948 adapter->link_speed = SPEED_10;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001949 break;
1950 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001951 adapter->link_speed = SPEED_100;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001952 break;
1953 case 2:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001954 adapter->link_speed = SPEED_1000;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001955 break;
1956 default:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001957 adapter->link_speed = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001958 break;
1959 }
1960 switch (netxen_get_phy_duplex(status)) {
1961 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001962 adapter->link_duplex = DUPLEX_HALF;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001963 break;
1964 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001965 adapter->link_duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001966 break;
1967 default:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001968 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001969 break;
1970 }
Joe Perches8e95a202009-12-03 07:58:21 +00001971 if (adapter->phy_read &&
1972 adapter->phy_read(adapter,
1973 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
1974 &autoneg) != 0)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001975 adapter->link_autoneg = autoneg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001976 } else
1977 goto link_down;
1978 } else {
1979 link_down:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001980 adapter->link_speed = 0;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001981 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001982 }
1983 }
1984}
1985
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001986int
1987netxen_nic_wol_supported(struct netxen_adapter *adapter)
1988{
1989 u32 wol_cfg;
1990
1991 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
1992 return 0;
1993
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001994 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001995 if (wol_cfg & (1UL << adapter->portnum)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001996 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001997 if (wol_cfg & (1 << adapter->portnum))
1998 return 1;
1999 }
2000
2001 return 0;
2002}