blob: 29d7b93d0493be12e4a5def185282371b5cd400d [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
322int
323netxen_pcie_sem_lock(struct netxen_adapter *adapter, int sem, u32 id_reg)
324{
325 int done = 0, timeout = 0;
326
327 while (!done) {
328 done = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_LOCK(sem)));
329 if (done == 1)
330 break;
331 if (++timeout >= NETXEN_PCIE_SEM_TIMEOUT)
Dhananjay Phadke7cecdca12009-10-16 15:50:10 +0000332 return -EIO;
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000333 msleep(1);
334 }
335
336 if (id_reg)
337 NXWR32(adapter, id_reg, adapter->portnum);
338
339 return 0;
340}
341
342void
343netxen_pcie_sem_unlock(struct netxen_adapter *adapter, int sem)
344{
Amit Kumar Salecha581e8ae2010-01-07 22:10:15 +0000345 NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_UNLOCK(sem)));
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000346}
347
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000348int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port)
349{
350 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
351 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_1+(0x10000*port), 0x1447);
352 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0+(0x10000*port), 0x5);
353 }
354
355 return 0;
356}
357
358/* Disable an XG interface */
359int netxen_niu_disable_xg_port(struct netxen_adapter *adapter)
360{
361 __u32 mac_cfg;
362 u32 port = adapter->physical_port;
363
364 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
365 return 0;
366
367 if (port > NETXEN_NIU_MAX_XG_PORTS)
368 return -EINVAL;
369
370 mac_cfg = 0;
371 if (NXWR32(adapter,
372 NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg))
373 return -EIO;
374 return 0;
375}
376
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700377#define NETXEN_UNICAST_ADDR(port, index) \
378 (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8))
379#define NETXEN_MCAST_ADDR(port, index) \
380 (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8))
381#define MAC_HI(addr) \
382 ((addr[2] << 16) | (addr[1] << 8) | (addr[0]))
383#define MAC_LO(addr) \
384 ((addr[5] << 16) | (addr[4] << 8) | (addr[3]))
385
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000386int netxen_p2_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
387{
Narender Kumara7483b02009-11-20 15:09:33 +0000388 u32 mac_cfg;
389 u32 cnt = 0;
390 __u32 reg = 0x0200;
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000391 u32 port = adapter->physical_port;
Narender Kumara7483b02009-11-20 15:09:33 +0000392 u16 board_type = adapter->ahw.board_type;
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000393
394 if (port > NETXEN_NIU_MAX_XG_PORTS)
395 return -EINVAL;
396
Narender Kumara7483b02009-11-20 15:09:33 +0000397 mac_cfg = NXRD32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port));
398 mac_cfg &= ~0x4;
399 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg);
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000400
Narender Kumara7483b02009-11-20 15:09:33 +0000401 if ((board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) ||
402 (board_type == NETXEN_BRDTYPE_P2_SB31_10G_HMEZ))
403 reg = (0x20 << port);
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000404
Narender Kumara7483b02009-11-20 15:09:33 +0000405 NXWR32(adapter, NETXEN_NIU_FRAME_COUNT_SELECT, reg);
406
407 mdelay(10);
408
409 while (NXRD32(adapter, NETXEN_NIU_FRAME_COUNT) && ++cnt < 20)
410 mdelay(10);
411
412 if (cnt < 20) {
413
414 reg = NXRD32(adapter,
415 NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port));
416
417 if (mode == NETXEN_NIU_PROMISC_MODE)
418 reg = (reg | 0x2000UL);
419 else
420 reg = (reg & ~0x2000UL);
421
422 if (mode == NETXEN_NIU_ALLMULTI_MODE)
423 reg = (reg | 0x1000UL);
424 else
425 reg = (reg & ~0x1000UL);
426
427 NXWR32(adapter,
428 NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), reg);
429 }
430
431 mac_cfg |= 0x4;
432 NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg);
Dhananjay Phadke3ad44672009-08-24 19:23:27 +0000433
434 return 0;
435}
436
437int netxen_p2_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr)
438{
439 u32 mac_hi, mac_lo;
440 u32 reg_hi, reg_lo;
441
442 u8 phy = adapter->physical_port;
443
444 if (phy >= NETXEN_NIU_MAX_XG_PORTS)
445 return -EINVAL;
446
447 mac_lo = ((u32)addr[0] << 16) | ((u32)addr[1] << 24);
448 mac_hi = addr[2] | ((u32)addr[3] << 8) |
449 ((u32)addr[4] << 16) | ((u32)addr[5] << 24);
450
451 reg_lo = NETXEN_NIU_XGE_STATION_ADDR_0_1 + (0x10000 * phy);
452 reg_hi = NETXEN_NIU_XGE_STATION_ADDR_0_HI + (0x10000 * phy);
453
454 /* write twice to flush */
455 if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi))
456 return -EIO;
457 if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi))
458 return -EIO;
459
460 return 0;
461}
462
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700463static int
464netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter)
465{
466 u32 val = 0;
467 u16 port = adapter->physical_port;
Narender Kumar5d09e532009-11-20 22:08:57 +0000468 u8 *addr = adapter->mac_addr;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700469
470 if (adapter->mc_enabled)
471 return 0;
472
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000473 val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700474 val |= (1UL << (28+port));
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000475 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700476
477 /* add broadcast addr to filter */
478 val = 0xffffff;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000479 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
480 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700481
482 /* add station addr to filter */
483 val = MAC_HI(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000484 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700485 val = MAC_LO(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000486 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700487
488 adapter->mc_enabled = 1;
489 return 0;
490}
491
492static int
493netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter)
494{
495 u32 val = 0;
496 u16 port = adapter->physical_port;
Narender Kumar5d09e532009-11-20 22:08:57 +0000497 u8 *addr = adapter->mac_addr;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700498
499 if (!adapter->mc_enabled)
500 return 0;
501
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000502 val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700503 val &= ~(1UL << (28+port));
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000504 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700505
506 val = MAC_HI(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000507 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700508 val = MAC_LO(addr);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000509 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700510
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000511 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), 0);
512 NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700513
514 adapter->mc_enabled = 0;
515 return 0;
516}
517
518static int
519netxen_nic_set_mcast_addr(struct netxen_adapter *adapter,
520 int index, u8 *addr)
521{
522 u32 hi = 0, lo = 0;
523 u16 port = adapter->physical_port;
524
525 lo = MAC_LO(addr);
526 hi = MAC_HI(addr);
527
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000528 NXWR32(adapter, NETXEN_MCAST_ADDR(port, index), hi);
529 NXWR32(adapter, NETXEN_MCAST_ADDR(port, index)+4, lo);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700530
531 return 0;
532}
533
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700534void netxen_p2_nic_set_multi(struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400535{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700536 struct netxen_adapter *adapter = netdev_priv(netdev);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000537 struct netdev_hw_addr *ha;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700538 u8 null_addr[6];
Jiri Pirkof9dcbcc2010-02-23 09:19:49 +0000539 int i;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400540
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700541 memset(null_addr, 0, 6);
542
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400543 if (netdev->flags & IFF_PROMISC) {
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700544
545 adapter->set_promisc(adapter,
546 NETXEN_NIU_PROMISC_MODE);
547
548 /* Full promiscuous mode */
549 netxen_nic_disable_mcast_filter(adapter);
550
551 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400552 }
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700553
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000554 if (netdev_mc_empty(netdev)) {
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700555 adapter->set_promisc(adapter,
556 NETXEN_NIU_NON_PROMISC_MODE);
557 netxen_nic_disable_mcast_filter(adapter);
558 return;
559 }
560
561 adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE);
562 if (netdev->flags & IFF_ALLMULTI ||
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000563 netdev_mc_count(netdev) > adapter->max_mc_count) {
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700564 netxen_nic_disable_mcast_filter(adapter);
565 return;
566 }
567
568 netxen_nic_enable_mcast_filter(adapter);
569
Jiri Pirkof9dcbcc2010-02-23 09:19:49 +0000570 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +0000571 netdev_for_each_mc_addr(ha, netdev)
572 netxen_nic_set_mcast_addr(adapter, i++, ha->addr);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700573
574 /* Clear out remaining addresses */
Jiri Pirkof9dcbcc2010-02-23 09:19:49 +0000575 while (i < adapter->max_mc_count)
576 netxen_nic_set_mcast_addr(adapter, i++, null_addr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400577}
578
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700579static int
580netxen_send_cmd_descs(struct netxen_adapter *adapter,
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000581 struct cmd_desc_type0 *cmd_desc_arr, int nr_desc)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700582{
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000583 u32 i, producer, consumer;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700584 struct netxen_cmd_buffer *pbuf;
585 struct cmd_desc_type0 *cmd_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000586 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700587
588 i = 0;
589
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000590 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
591 return -EIO;
592
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000593 tx_ring = adapter->tx_ring;
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000594 __netif_tx_lock_bh(tx_ring->txq);
Dhananjay Phadke03e678e2009-01-14 20:49:43 -0800595
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000596 producer = tx_ring->producer;
597 consumer = tx_ring->sw_consumer;
598
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000599 if (nr_desc >= netxen_tx_avail(tx_ring)) {
600 netif_tx_stop_queue(tx_ring->txq);
601 __netif_tx_unlock_bh(tx_ring->txq);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000602 return -EBUSY;
603 }
604
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700605 do {
606 cmd_desc = &cmd_desc_arr[i];
607
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000608 pbuf = &tx_ring->cmd_buf_arr[producer];
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700609 pbuf->skb = NULL;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700610 pbuf->frag_count = 0;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700611
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000612 memcpy(&tx_ring->desc_head[producer],
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700613 &cmd_desc_arr[i], sizeof(struct cmd_desc_type0));
614
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000615 producer = get_next_index(producer, tx_ring->num_desc);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700616 i++;
617
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000618 } while (i != nr_desc);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700619
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000620 tx_ring->producer = producer;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700621
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000622 netxen_nic_update_cmd_producer(adapter, tx_ring);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700623
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000624 __netif_tx_unlock_bh(tx_ring->txq);
Dhananjay Phadke03e678e2009-01-14 20:49:43 -0800625
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700626 return 0;
627}
628
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000629static int
630nx_p3_sre_macaddr_change(struct netxen_adapter *adapter, u8 *addr, unsigned op)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700631{
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700632 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800633 nx_mac_req_t *mac_req;
634 u64 word;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700635
636 memset(&req, 0, sizeof(nx_nic_req_t));
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800637 req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23);
638
639 word = NX_MAC_EVENT | ((u64)adapter->portnum << 16);
640 req.req_hdr = cpu_to_le64(word);
641
642 mac_req = (nx_mac_req_t *)&req.words[0];
643 mac_req->op = op;
644 memcpy(mac_req->mac_addr, addr, 6);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700645
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000646 return netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
647}
648
649static int nx_p3_nic_add_mac(struct netxen_adapter *adapter,
650 u8 *addr, struct list_head *del_list)
651{
652 struct list_head *head;
653 nx_mac_list_t *cur;
654
655 /* look up if already exists */
656 list_for_each(head, del_list) {
657 cur = list_entry(head, nx_mac_list_t, list);
658
659 if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) {
660 list_move_tail(head, &adapter->mac_list);
661 return 0;
662 }
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700663 }
664
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000665 cur = kzalloc(sizeof(nx_mac_list_t), GFP_ATOMIC);
666 if (cur == NULL) {
667 printk(KERN_ERR "%s: failed to add mac address filter\n",
668 adapter->netdev->name);
669 return -ENOMEM;
670 }
671 memcpy(cur->mac_addr, addr, ETH_ALEN);
672 list_add_tail(&cur->list, &adapter->mac_list);
673 return nx_p3_sre_macaddr_change(adapter,
674 cur->mac_addr, NETXEN_MAC_ADD);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700675}
676
677void netxen_p3_nic_set_multi(struct net_device *netdev)
678{
679 struct netxen_adapter *adapter = netdev_priv(netdev);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000680 struct netdev_hw_addr *ha;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700681 u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700682 u32 mode = VPORT_MISS_MODE_DROP;
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000683 LIST_HEAD(del_list);
684 struct list_head *head;
685 nx_mac_list_t *cur;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700686
Amit Kumar Salechad49c9642010-01-07 22:10:16 +0000687 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
688 return;
689
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000690 list_splice_tail_init(&adapter->mac_list, &del_list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700691
Narender Kumar5d09e532009-11-20 22:08:57 +0000692 nx_p3_nic_add_mac(adapter, adapter->mac_addr, &del_list);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000693 nx_p3_nic_add_mac(adapter, bcast_addr, &del_list);
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700694
695 if (netdev->flags & IFF_PROMISC) {
696 mode = VPORT_MISS_MODE_ACCEPT_ALL;
697 goto send_fw_cmd;
698 }
699
700 if ((netdev->flags & IFF_ALLMULTI) ||
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000701 (netdev_mc_count(netdev) > adapter->max_mc_count)) {
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700702 mode = VPORT_MISS_MODE_ACCEPT_MULTI;
703 goto send_fw_cmd;
704 }
705
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000706 if (!netdev_mc_empty(netdev)) {
Jiri Pirko22bedad32010-04-01 21:22:57 +0000707 netdev_for_each_mc_addr(ha, netdev)
708 nx_p3_nic_add_mac(adapter, ha->addr, &del_list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700709 }
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700710
711send_fw_cmd:
712 adapter->set_promisc(adapter, mode);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000713 head = &del_list;
714 while (!list_empty(head)) {
715 cur = list_entry(head->next, nx_mac_list_t, list);
716
717 nx_p3_sre_macaddr_change(adapter,
718 cur->mac_addr, NETXEN_MAC_DEL);
719 list_del(&cur->list);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700720 kfree(cur);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700721 }
722}
723
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700724int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
725{
726 nx_nic_req_t req;
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800727 u64 word;
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700728
729 memset(&req, 0, sizeof(nx_nic_req_t));
730
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800731 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
732
733 word = NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE |
734 ((u64)adapter->portnum << 16);
735 req.req_hdr = cpu_to_le64(word);
736
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700737 req.words[0] = cpu_to_le64(mode);
738
739 return netxen_send_cmd_descs(adapter,
740 (struct cmd_desc_type0 *)&req, 1);
741}
742
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800743void netxen_p3_free_mac_list(struct netxen_adapter *adapter)
744{
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000745 nx_mac_list_t *cur;
746 struct list_head *head = &adapter->mac_list;
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800747
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000748 while (!list_empty(head)) {
749 cur = list_entry(head->next, nx_mac_list_t, list);
750 nx_p3_sre_macaddr_change(adapter,
751 cur->mac_addr, NETXEN_MAC_DEL);
752 list_del(&cur->list);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800753 kfree(cur);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800754 }
755}
756
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000757int netxen_p3_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr)
758{
759 /* assuming caller has already copied new addr to netdev */
760 netxen_p3_nic_set_multi(adapter->netdev);
761 return 0;
762}
763
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700764#define NETXEN_CONFIG_INTR_COALESCE 3
765
766/*
767 * Send the interrupt coalescing parameter set by ethtool to the card.
768 */
769int netxen_config_intr_coalesce(struct netxen_adapter *adapter)
770{
771 nx_nic_req_t req;
Amit Kumar Salechac0703952010-01-14 01:53:22 +0000772 u64 word[6];
773 int rv, i;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700774
775 memset(&req, 0, sizeof(nx_nic_req_t));
Amit Kumar Salechac0703952010-01-14 01:53:22 +0000776 memset(word, 0, sizeof(word));
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700777
Narender Kumar1bb482f2009-08-23 08:35:09 +0000778 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
Dhananjay Phadke2edbb452009-01-14 20:47:30 -0800779
Amit Kumar Salechac0703952010-01-14 01:53:22 +0000780 word[0] = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16);
781 req.req_hdr = cpu_to_le64(word[0]);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700782
Amit Kumar Salechac0703952010-01-14 01:53:22 +0000783 memcpy(&word[0], &adapter->coal, sizeof(adapter->coal));
784 for (i = 0; i < 6; i++)
785 req.words[i] = cpu_to_le64(word[i]);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700786
787 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
788 if (rv != 0) {
789 printk(KERN_ERR "ERROR. Could not send "
790 "interrupt coalescing parameters\n");
791 }
792
793 return rv;
794}
795
Narender Kumar1bb482f2009-08-23 08:35:09 +0000796int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable)
797{
798 nx_nic_req_t req;
799 u64 word;
800 int rv = 0;
801
802 if ((adapter->flags & NETXEN_NIC_LRO_ENABLED) == enable)
803 return 0;
804
805 memset(&req, 0, sizeof(nx_nic_req_t));
806
807 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
808
809 word = NX_NIC_H2C_OPCODE_CONFIG_HW_LRO | ((u64)adapter->portnum << 16);
810 req.req_hdr = cpu_to_le64(word);
811
812 req.words[0] = cpu_to_le64(enable);
813
814 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
815 if (rv != 0) {
816 printk(KERN_ERR "ERROR. Could not send "
817 "configure hw lro request\n");
818 }
819
820 adapter->flags ^= NETXEN_NIC_LRO_ENABLED;
821
822 return rv;
823}
824
Narender Kumarfa3ce352009-08-24 19:23:28 +0000825int netxen_config_bridged_mode(struct netxen_adapter *adapter, int enable)
826{
827 nx_nic_req_t req;
828 u64 word;
829 int rv = 0;
830
831 if (!!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED) == enable)
832 return rv;
833
834 memset(&req, 0, sizeof(nx_nic_req_t));
835
836 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
837
838 word = NX_NIC_H2C_OPCODE_CONFIG_BRIDGING |
839 ((u64)adapter->portnum << 16);
840 req.req_hdr = cpu_to_le64(word);
841
842 req.words[0] = cpu_to_le64(enable);
843
844 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
845 if (rv != 0) {
846 printk(KERN_ERR "ERROR. Could not send "
847 "configure bridge mode request\n");
848 }
849
850 adapter->flags ^= NETXEN_NIC_BRIDGE_ENABLED;
851
852 return rv;
853}
854
855
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000856#define RSS_HASHTYPE_IP_TCP 0x3
857
858int netxen_config_rss(struct netxen_adapter *adapter, int enable)
859{
860 nx_nic_req_t req;
861 u64 word;
862 int i, rv;
863
864 u64 key[] = { 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL,
865 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
866 0x255b0ec26d5a56daULL };
867
868
869 memset(&req, 0, sizeof(nx_nic_req_t));
870 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
871
872 word = NX_NIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16);
873 req.req_hdr = cpu_to_le64(word);
874
875 /*
876 * RSS request:
877 * bits 3-0: hash_method
878 * 5-4: hash_type_ipv4
879 * 7-6: hash_type_ipv6
880 * 8: enable
881 * 9: use indirection table
882 * 47-10: reserved
883 * 63-48: indirection table mask
884 */
885 word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) |
886 ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) |
887 ((u64)(enable & 0x1) << 8) |
888 ((0x7ULL) << 48);
889 req.words[0] = cpu_to_le64(word);
890 for (i = 0; i < 5; i++)
891 req.words[i+1] = cpu_to_le64(key[i]);
892
893
894 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
895 if (rv != 0) {
896 printk(KERN_ERR "%s: could not configure RSS\n",
897 adapter->netdev->name);
898 }
899
900 return rv;
901}
902
Dhananjay Phadke6598b162009-07-26 20:07:37 +0000903int netxen_config_ipaddr(struct netxen_adapter *adapter, u32 ip, int cmd)
904{
905 nx_nic_req_t req;
906 u64 word;
907 int rv;
908
909 memset(&req, 0, sizeof(nx_nic_req_t));
910 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
911
912 word = NX_NIC_H2C_OPCODE_CONFIG_IPADDR | ((u64)adapter->portnum << 16);
913 req.req_hdr = cpu_to_le64(word);
914
915 req.words[0] = cpu_to_le64(cmd);
916 req.words[1] = cpu_to_le64(ip);
917
918 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
919 if (rv != 0) {
920 printk(KERN_ERR "%s: could not notify %s IP 0x%x reuqest\n",
921 adapter->netdev->name,
922 (cmd == NX_IP_UP) ? "Add" : "Remove", ip);
923 }
924 return rv;
925}
926
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000927int netxen_linkevent_request(struct netxen_adapter *adapter, int enable)
928{
929 nx_nic_req_t req;
930 u64 word;
931 int rv;
932
933 memset(&req, 0, sizeof(nx_nic_req_t));
934 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
935
936 word = NX_NIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16);
937 req.req_hdr = cpu_to_le64(word);
Dhananjay Phadke22527862009-05-05 19:05:06 +0000938 req.words[0] = cpu_to_le64(enable | (enable << 8));
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000939
940 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
941 if (rv != 0) {
942 printk(KERN_ERR "%s: could not configure link notification\n",
943 adapter->netdev->name);
944 }
945
946 return rv;
947}
948
Narender Kumar1bb482f2009-08-23 08:35:09 +0000949int netxen_send_lro_cleanup(struct netxen_adapter *adapter)
950{
951 nx_nic_req_t req;
952 u64 word;
953 int rv;
954
955 memset(&req, 0, sizeof(nx_nic_req_t));
956 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
957
958 word = NX_NIC_H2C_OPCODE_LRO_REQUEST |
959 ((u64)adapter->portnum << 16) |
960 ((u64)NX_NIC_LRO_REQUEST_CLEANUP << 56) ;
961
962 req.req_hdr = cpu_to_le64(word);
963
964 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
965 if (rv != 0) {
966 printk(KERN_ERR "%s: could not cleanup lro flows\n",
967 adapter->netdev->name);
968 }
969 return rv;
970}
971
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400972/*
973 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
974 * @returns 0 on success, negative on failure
975 */
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700976
977#define MTU_FUDGE_FACTOR 100
978
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400979int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
980{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700981 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700982 int max_mtu;
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700983 int rc = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400984
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700985 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
986 max_mtu = P3_MAX_MTU;
987 else
988 max_mtu = P2_MAX_MTU;
989
990 if (mtu > max_mtu) {
991 printk(KERN_ERR "%s: mtu > %d bytes unsupported\n",
992 netdev->name, max_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400993 return -EINVAL;
994 }
995
Amit S. Kale80922fb2006-12-04 09:18:00 -0800996 if (adapter->set_mtu)
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700997 rc = adapter->set_mtu(adapter, mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400998
Dhananjay Phadke9ad27642008-08-01 03:14:59 -0700999 if (!rc)
1000 netdev->mtu = mtu;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001001
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001002 return rc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001003}
1004
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001005static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
Al Virof305f782007-12-22 19:44:00 +00001006 int size, __le32 * buf)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001007{
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001008 int i, v, addr;
Al Virof305f782007-12-22 19:44:00 +00001009 __le32 *ptr32;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001010
1011 addr = base;
1012 ptr32 = buf;
1013 for (i = 0; i < size / sizeof(u32); i++) {
Al Virof305f782007-12-22 19:44:00 +00001014 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001015 return -1;
Al Virof305f782007-12-22 19:44:00 +00001016 *ptr32 = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001017 ptr32++;
1018 addr += sizeof(u32);
1019 }
1020 if ((char *)buf + size > (char *)ptr32) {
Al Virof305f782007-12-22 19:44:00 +00001021 __le32 local;
1022 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001023 return -1;
Al Virof305f782007-12-22 19:44:00 +00001024 local = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001025 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
1026 }
1027
1028 return 0;
1029}
1030
Amit Kumar Salechaa03d2452010-01-14 01:53:21 +00001031int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 *mac)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001032{
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001033 __le32 *pmac = (__le32 *) mac;
1034 u32 offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001035
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001036 offset = NX_FW_MAC_ADDR_OFFSET + (adapter->portnum * sizeof(u64));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001037
1038 if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001039 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001040
Al Virof305f782007-12-22 19:44:00 +00001041 if (*mac == cpu_to_le64(~0ULL)) {
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001042
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001043 offset = NX_OLD_MAC_ADDR_OFFSET +
1044 (adapter->portnum * sizeof(u64));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001045
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001046 if (netxen_get_flash_block(adapter,
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001047 offset, sizeof(u64), pmac) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001048 return -1;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001049
Al Virof305f782007-12-22 19:44:00 +00001050 if (*mac == cpu_to_le64(~0ULL))
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001051 return -1;
1052 }
1053 return 0;
1054}
1055
Amit Kumar Salechaa03d2452010-01-14 01:53:21 +00001056int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, u64 *mac)
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001057{
1058 uint32_t crbaddr, mac_hi, mac_lo;
1059 int pci_func = adapter->ahw.pci_func;
1060
1061 crbaddr = CRB_MAC_BLOCK_START +
1062 (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1));
1063
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001064 mac_lo = NXRD32(adapter, crbaddr);
1065 mac_hi = NXRD32(adapter, crbaddr+4);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001066
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001067 if (pci_func & 1)
Dhananjay Phadke2edbb452009-01-14 20:47:30 -08001068 *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001069 else
Dhananjay Phadke2edbb452009-01-14 20:47:30 -08001070 *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32));
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001071
1072 return 0;
1073}
1074
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001075/*
1076 * Changes the CRB window to the specified window.
1077 */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001078static void
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001079netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter,
1080 u32 window)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001081{
1082 void __iomem *offset;
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001083 int count = 10;
1084 u8 func = adapter->ahw.pci_func;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001085
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001086 if (adapter->ahw.crb_win == window)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001087 return;
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001088
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001089 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1090 NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001091
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001092 writel(window, offset);
1093 do {
1094 if (window == readl(offset))
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001095 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001096
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001097 if (printk_ratelimit())
1098 dev_warn(&adapter->pdev->dev,
1099 "failed to set CRB window to %d\n",
1100 (window == NETXEN_WINDOW_ONE));
1101 udelay(1);
1102
1103 } while (--count > 0);
1104
1105 if (count > 0)
1106 adapter->ahw.crb_win = window;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001107}
1108
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001109/*
Dhananjay Phadke7cecdca12009-10-16 15:50:10 +00001110 * Returns < 0 if off is not valid,
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001111 * 1 if window access is needed. 'off' is set to offset from
1112 * CRB space in 128M pci map
1113 * 0 if no window access is needed. 'off' is set to 2M addr
1114 * In: 'off' is offset from base in 128M pci map
1115 */
1116static int
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001117netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter,
1118 ulong off, void __iomem **addr)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001119{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001120 crb_128M_2M_sub_block_map_t *m;
1121
1122
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001123 if ((off >= NETXEN_CRB_MAX) || (off < NETXEN_PCI_CRBSPACE))
Dhananjay Phadke7cecdca12009-10-16 15:50:10 +00001124 return -EINVAL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001125
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001126 off -= NETXEN_PCI_CRBSPACE;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001127
1128 /*
1129 * Try direct map
1130 */
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001131 m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)];
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001132
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001133 if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) {
1134 *addr = adapter->ahw.pci_base0 + m->start_2M +
1135 (off - m->start_128M);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001136 return 0;
1137 }
1138
1139 /*
1140 * Not in direct map, use crb window
1141 */
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001142 *addr = adapter->ahw.pci_base0 + CRB_INDIRECT_2M +
1143 (off & MASK(16));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001144 return 1;
1145}
1146
1147/*
1148 * In: 'off' is offset from CRB space in 128M pci map
1149 * Out: 'off' is 2M pci map addr
1150 * side effect: lock crb window
1151 */
1152static void
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001153netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001154{
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001155 u32 window;
1156 void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001157
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001158 off -= NETXEN_PCI_CRBSPACE;
1159
1160 window = CRB_HI(off);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001161
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001162 writel(window, addr);
1163 if (readl(addr) != window) {
1164 if (printk_ratelimit())
1165 dev_warn(&adapter->pdev->dev,
1166 "failed to set CRB window to %d off 0x%lx\n",
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001167 window, off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001168 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001169}
1170
Narender Kumarf58dbd72009-12-02 15:46:18 +00001171static void __iomem *
1172netxen_nic_map_indirect_address_128M(struct netxen_adapter *adapter,
1173 ulong win_off, void __iomem **mem_ptr)
1174{
1175 ulong off = win_off;
1176 void __iomem *addr;
1177 resource_size_t mem_base;
1178
1179 if (ADDR_IN_WINDOW1(win_off))
1180 off = NETXEN_CRB_NORMAL(win_off);
1181
1182 addr = pci_base_offset(adapter, off);
1183 if (addr)
1184 return addr;
1185
1186 if (adapter->ahw.pci_len0 == 0)
1187 off -= NETXEN_PCI_CRBSPACE;
1188
1189 mem_base = pci_resource_start(adapter->pdev, 0);
1190 *mem_ptr = ioremap(mem_base + (off & PAGE_MASK), PAGE_SIZE);
1191 if (*mem_ptr)
1192 addr = *mem_ptr + (off & (PAGE_SIZE - 1));
1193
1194 return addr;
1195}
1196
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001197static int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001198netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001199{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001200 unsigned long flags;
Narender Kumarf58dbd72009-12-02 15:46:18 +00001201 void __iomem *addr, *mem_ptr = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001202
Narender Kumarf58dbd72009-12-02 15:46:18 +00001203 addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
1204 if (!addr)
1205 return -EIO;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001206
Narender Kumarf58dbd72009-12-02 15:46:18 +00001207 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001208 netxen_nic_io_write_128M(adapter, addr, data);
Narender Kumarf58dbd72009-12-02 15:46:18 +00001209 } else { /* Window 0 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001210 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001211 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001212 writel(data, addr);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001213 netxen_nic_pci_set_crbwindow_128M(adapter,
1214 NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001215 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001216 }
1217
Narender Kumarf58dbd72009-12-02 15:46:18 +00001218 if (mem_ptr)
1219 iounmap(mem_ptr);
1220
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001221 return 0;
1222}
1223
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001224static u32
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001225netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001226{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001227 unsigned long flags;
Narender Kumarf58dbd72009-12-02 15:46:18 +00001228 void __iomem *addr, *mem_ptr = NULL;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001229 u32 data;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001230
Narender Kumarf58dbd72009-12-02 15:46:18 +00001231 addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
1232 if (!addr)
1233 return -EIO;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001234
Narender Kumarf58dbd72009-12-02 15:46:18 +00001235 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001236 data = netxen_nic_io_read_128M(adapter, addr);
Narender Kumarf58dbd72009-12-02 15:46:18 +00001237 } else { /* Window 0 */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001238 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001239 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001240 data = readl(addr);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001241 netxen_nic_pci_set_crbwindow_128M(adapter,
1242 NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001243 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001244 }
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001245
Narender Kumarf58dbd72009-12-02 15:46:18 +00001246 if (mem_ptr)
1247 iounmap(mem_ptr);
1248
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001249 return data;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001250}
1251
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001252static int
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001253netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001254{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001255 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001256 int rv;
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001257 void __iomem *addr = NULL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001258
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001259 rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001260
Dhananjay Phadke7cecdca12009-10-16 15:50:10 +00001261 if (rv == 0) {
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001262 writel(data, addr);
Dhananjay Phadke7cecdca12009-10-16 15:50:10 +00001263 return 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001264 }
1265
Dhananjay Phadke7cecdca12009-10-16 15:50:10 +00001266 if (rv > 0) {
1267 /* indirect access */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001268 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001269 crb_win_lock(adapter);
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001270 netxen_nic_pci_set_crbwindow_2M(adapter, off);
1271 writel(data, addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001272 crb_win_unlock(adapter);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001273 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke7cecdca12009-10-16 15:50:10 +00001274 return 0;
1275 }
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001276
Dhananjay Phadke7cecdca12009-10-16 15:50:10 +00001277 dev_err(&adapter->pdev->dev,
1278 "%s: invalid offset: 0x%016lx\n", __func__, off);
1279 dump_stack();
1280 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001281}
1282
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001283static u32
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001284netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001285{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001286 unsigned long flags;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001287 int rv;
Dhananjay Phadke1fbe6322009-04-07 22:50:44 +00001288 u32 data;
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001289 void __iomem *addr = NULL;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001290
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001291 rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001292
Dhananjay Phadke7cecdca12009-10-16 15:50:10 +00001293 if (rv == 0)
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001294 return readl(addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001295
Dhananjay Phadke7cecdca12009-10-16 15:50:10 +00001296 if (rv > 0) {
1297 /* indirect access */
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001298 write_lock_irqsave(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001299 crb_win_lock(adapter);
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001300 netxen_nic_pci_set_crbwindow_2M(adapter, off);
1301 data = readl(addr);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001302 crb_win_unlock(adapter);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001303 write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
Dhananjay Phadke7cecdca12009-10-16 15:50:10 +00001304 return data;
1305 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001306
Dhananjay Phadke7cecdca12009-10-16 15:50:10 +00001307 dev_err(&adapter->pdev->dev,
1308 "%s: invalid offset: 0x%016lx\n", __func__, off);
1309 dump_stack();
1310 return -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001311}
1312
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001313/* window 1 registers only */
1314static void netxen_nic_io_write_128M(struct netxen_adapter *adapter,
1315 void __iomem *addr, u32 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001316{
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001317 read_lock(&adapter->ahw.crb_lock);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001318 writel(data, addr);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001319 read_unlock(&adapter->ahw.crb_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001320}
1321
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001322static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter,
1323 void __iomem *addr)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001324{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001325 u32 val;
1326
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001327 read_lock(&adapter->ahw.crb_lock);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001328 val = readl(addr);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001329 read_unlock(&adapter->ahw.crb_lock);
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001330
1331 return val;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001332}
1333
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001334static void netxen_nic_io_write_2M(struct netxen_adapter *adapter,
1335 void __iomem *addr, u32 data)
1336{
1337 writel(data, addr);
1338}
1339
1340static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter,
1341 void __iomem *addr)
1342{
1343 return readl(addr);
1344}
1345
1346void __iomem *
1347netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset)
1348{
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001349 void __iomem *addr = NULL;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001350
1351 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001352 if ((offset < NETXEN_CRB_PCIX_HOST2) &&
1353 (offset > NETXEN_CRB_PCIX_HOST))
1354 addr = PCI_OFFSET_SECOND_RANGE(adapter, offset);
1355 else
1356 addr = NETXEN_CRB_NORMALIZE(adapter, offset);
1357 } else {
1358 WARN_ON(netxen_nic_pci_get_crb_addr_2M(adapter,
1359 offset, &addr));
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001360 }
1361
Dhananjay Phadkea9ac07d2009-10-24 16:03:59 +00001362 return addr;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001363}
1364
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001365static int
1366netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
1367 u64 addr, u32 *start)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001368{
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001369 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1370 *start = (addr - NETXEN_ADDR_OCM0 + NETXEN_PCI_OCM0);
1371 return 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001372 } else if (ADDR_IN_RANGE(addr,
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001373 NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1374 *start = (addr - NETXEN_ADDR_OCM1 + NETXEN_PCI_OCM1);
1375 return 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001376 }
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001377
1378 return -EIO;
1379}
1380
1381static int
1382netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
1383 u64 addr, u32 *start)
1384{
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +00001385 u32 window;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001386
Sucheta Chakraborty14e2cfb2010-05-11 23:53:04 +00001387 window = OCM_WIN(addr);
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +00001388
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001389 writel(window, adapter->ahw.ocm_win_crb);
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +00001390 /* read back to flush */
1391 readl(adapter->ahw.ocm_win_crb);
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001392
1393 adapter->ahw.ocm_win = window;
1394 *start = NETXEN_PCI_OCM0_2M + GET_MEM_OFFS_2M(addr);
1395 return 0;
1396}
1397
1398static int
1399netxen_nic_pci_mem_access_direct(struct netxen_adapter *adapter, u64 off,
1400 u64 *data, int op)
1401{
1402 void __iomem *addr, *mem_ptr = NULL;
1403 resource_size_t mem_base;
Sucheta Chakraborty14e2cfb2010-05-11 23:53:04 +00001404 int ret;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001405 u32 start;
1406
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001407 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001408
1409 ret = adapter->pci_set_window(adapter, off, &start);
1410 if (ret != 0)
1411 goto unlock;
1412
Sucheta Chakraborty14e2cfb2010-05-11 23:53:04 +00001413 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1414 addr = adapter->ahw.pci_base0 + start;
1415 } else {
1416 addr = pci_base_offset(adapter, start);
1417 if (addr)
1418 goto noremap;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001419
Sucheta Chakraborty14e2cfb2010-05-11 23:53:04 +00001420 mem_base = pci_resource_start(adapter->pdev, 0) +
1421 (start & PAGE_MASK);
1422 mem_ptr = ioremap(mem_base, PAGE_SIZE);
1423 if (mem_ptr == NULL) {
1424 ret = -EIO;
1425 goto unlock;
1426 }
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001427
Sucheta Chakraborty14e2cfb2010-05-11 23:53:04 +00001428 addr = mem_ptr + (start & (PAGE_SIZE-1));
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001429 }
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001430noremap:
1431 if (op == 0) /* read */
1432 *data = readq(addr);
1433 else /* write */
1434 writeq(*data, addr);
1435
1436unlock:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001437 spin_unlock(&adapter->ahw.mem_lock);
1438
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001439 if (mem_ptr)
1440 iounmap(mem_ptr);
1441 return ret;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001442}
1443
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00001444void
1445netxen_pci_camqm_read_2M(struct netxen_adapter *adapter, u64 off, u64 *data)
1446{
1447 void __iomem *addr = adapter->ahw.pci_base0 +
1448 NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM);
1449
1450 spin_lock(&adapter->ahw.mem_lock);
1451 *data = readq(addr);
1452 spin_unlock(&adapter->ahw.mem_lock);
1453}
1454
1455void
1456netxen_pci_camqm_write_2M(struct netxen_adapter *adapter, u64 off, u64 data)
1457{
1458 void __iomem *addr = adapter->ahw.pci_base0 +
1459 NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM);
1460
1461 spin_lock(&adapter->ahw.mem_lock);
1462 writeq(data, addr);
1463 spin_unlock(&adapter->ahw.mem_lock);
1464}
1465
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001466#define MAX_CTL_CHECK 1000
1467
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001468static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001469netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001470 u64 off, u64 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001471{
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001472 int j, ret;
1473 u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001474 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001475
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001476 /* Only 64-bit aligned access */
1477 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001478 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001479
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001480 /* P2 has different SIU and MIU test agent base addr */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001481 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1482 NETXEN_ADDR_QDR_NET_MAX_P2)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001483 mem_crb = pci_base_offset(adapter,
1484 NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
1485 addr_hi = SIU_TEST_AGT_ADDR_HI;
1486 data_lo = SIU_TEST_AGT_WRDATA_LO;
1487 data_hi = SIU_TEST_AGT_WRDATA_HI;
1488 off_lo = off & SIU_TEST_AGT_ADDR_MASK;
1489 off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001490 goto correct;
1491 }
1492
1493 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001494 mem_crb = pci_base_offset(adapter,
1495 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
1496 addr_hi = MIU_TEST_AGT_ADDR_HI;
1497 data_lo = MIU_TEST_AGT_WRDATA_LO;
1498 data_hi = MIU_TEST_AGT_WRDATA_HI;
1499 off_lo = off & MIU_TEST_AGT_ADDR_MASK;
1500 off_hi = 0;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001501 goto correct;
1502 }
1503
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001504 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
1505 ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1506 if (adapter->ahw.pci_len0 != 0) {
1507 return netxen_nic_pci_mem_access_direct(adapter,
1508 off, &data, 1);
1509 }
1510 }
1511
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001512 return -EIO;
1513
1514correct:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001515 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001516 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001517
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001518 writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1519 writel(off_hi, (mem_crb + addr_hi));
1520 writel(data & 0xffffffff, (mem_crb + data_lo));
1521 writel((data >> 32) & 0xffffffff, (mem_crb + data_hi));
1522 writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
1523 writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
1524 (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001525
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001526 for (j = 0; j < MAX_CTL_CHECK; j++) {
1527 temp = readl((mem_crb + TEST_AGT_CTRL));
1528 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001529 break;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001530 }
1531
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001532 if (j >= MAX_CTL_CHECK) {
1533 if (printk_ratelimit())
1534 dev_err(&adapter->pdev->dev,
1535 "failed to write through agent\n");
1536 ret = -EIO;
1537 } else
1538 ret = 0;
1539
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001540 netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001541 spin_unlock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001542 return ret;
1543}
1544
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001545static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001546netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001547 u64 off, u64 *data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001548{
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001549 int j, ret;
1550 u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
1551 u64 val;
Dhananjay Phadked8313ce2009-02-17 20:26:44 -08001552 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001553
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001554 /* Only 64-bit aligned access */
1555 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001556 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001557
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001558 /* P2 has different SIU and MIU test agent base addr */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001559 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1560 NETXEN_ADDR_QDR_NET_MAX_P2)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001561 mem_crb = pci_base_offset(adapter,
1562 NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
1563 addr_hi = SIU_TEST_AGT_ADDR_HI;
1564 data_lo = SIU_TEST_AGT_RDDATA_LO;
1565 data_hi = SIU_TEST_AGT_RDDATA_HI;
1566 off_lo = off & SIU_TEST_AGT_ADDR_MASK;
1567 off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001568 goto correct;
1569 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001570
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001571 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001572 mem_crb = pci_base_offset(adapter,
1573 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
1574 addr_hi = MIU_TEST_AGT_ADDR_HI;
1575 data_lo = MIU_TEST_AGT_RDDATA_LO;
1576 data_hi = MIU_TEST_AGT_RDDATA_HI;
1577 off_lo = off & MIU_TEST_AGT_ADDR_MASK;
1578 off_hi = 0;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001579 goto correct;
1580 }
1581
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001582 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
1583 ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1584 if (adapter->ahw.pci_len0 != 0) {
1585 return netxen_nic_pci_mem_access_direct(adapter,
1586 off, data, 0);
1587 }
1588 }
1589
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001590 return -EIO;
1591
1592correct:
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001593 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001594 netxen_nic_pci_set_crbwindow_128M(adapter, 0);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001595
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001596 writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1597 writel(off_hi, (mem_crb + addr_hi));
1598 writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
1599 writel((TA_CTL_START|TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001600
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001601 for (j = 0; j < MAX_CTL_CHECK; j++) {
1602 temp = readl(mem_crb + TEST_AGT_CTRL);
1603 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001604 break;
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001605 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001606
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001607 if (j >= MAX_CTL_CHECK) {
1608 if (printk_ratelimit())
1609 dev_err(&adapter->pdev->dev,
1610 "failed to read through agent\n");
1611 ret = -EIO;
1612 } else {
1613
1614 temp = readl(mem_crb + data_hi);
1615 val = ((u64)temp << 32);
1616 val |= readl(mem_crb + data_lo);
1617 *data = val;
1618 ret = 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001619 }
1620
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001621 netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001622 spin_unlock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001623
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001624 return ret;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001625}
1626
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001627static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001628netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001629 u64 off, u64 data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001630{
Sucheta Chakraborty215387a2010-05-11 23:53:03 +00001631 int j, ret;
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001632 u32 temp, off8;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001633 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001634
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001635 /* Only 64-bit aligned access */
1636 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001637 return -EIO;
1638
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001639 /* P3 onward, test agent base for MIU and SIU is same */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001640 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1641 NETXEN_ADDR_QDR_NET_MAX_P3)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001642 mem_crb = netxen_get_ioaddr(adapter,
1643 NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001644 goto correct;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001645 }
1646
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001647 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001648 mem_crb = netxen_get_ioaddr(adapter,
1649 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001650 goto correct;
1651 }
1652
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001653 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX))
1654 return netxen_nic_pci_mem_access_direct(adapter, off, &data, 1);
1655
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001656 return -EIO;
1657
1658correct:
Sucheta Chakraborty215387a2010-05-11 23:53:03 +00001659 off8 = off & 0xfffffff8;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001660
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001661 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001662
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001663 writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1664 writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001665
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001666 writel(data & 0xffffffff,
Sucheta Chakraborty215387a2010-05-11 23:53:03 +00001667 mem_crb + MIU_TEST_AGT_WRDATA_LO);
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001668 writel((data >> 32) & 0xffffffff,
Sucheta Chakraborty215387a2010-05-11 23:53:03 +00001669 mem_crb + MIU_TEST_AGT_WRDATA_HI);
Amit Kumar Salechafb1f6a42009-10-16 15:50:07 +00001670
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001671 writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
1672 writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
1673 (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001674
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001675 for (j = 0; j < MAX_CTL_CHECK; j++) {
1676 temp = readl(mem_crb + TEST_AGT_CTRL);
1677 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001678 break;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001679 }
1680
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001681 if (j >= MAX_CTL_CHECK) {
1682 if (printk_ratelimit())
1683 dev_err(&adapter->pdev->dev,
1684 "failed to write through agent\n");
1685 ret = -EIO;
1686 } else
1687 ret = 0;
1688
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001689 spin_unlock(&adapter->ahw.mem_lock);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001690
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001691 return ret;
1692}
1693
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001694static int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001695netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001696 u64 off, u64 *data)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001697{
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001698 int j, ret;
1699 u32 temp, off8;
Sucheta Chakraborty215387a2010-05-11 23:53:03 +00001700 u64 val;
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001701 void __iomem *mem_crb;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001702
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001703 /* Only 64-bit aligned access */
1704 if (off & 7)
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001705 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001706
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001707 /* P3 onward, test agent base for MIU and SIU is same */
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001708 if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
1709 NETXEN_ADDR_QDR_NET_MAX_P3)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001710 mem_crb = netxen_get_ioaddr(adapter,
1711 NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001712 goto correct;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001713 }
1714
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001715 if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001716 mem_crb = netxen_get_ioaddr(adapter,
1717 NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001718 goto correct;
1719 }
1720
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001721 if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1722 return netxen_nic_pci_mem_access_direct(adapter,
1723 off, data, 0);
1724 }
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001725
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +00001726 return -EIO;
1727
1728correct:
Sucheta Chakraborty215387a2010-05-11 23:53:03 +00001729 off8 = off & 0xfffffff8;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001730
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001731 spin_lock(&adapter->ahw.mem_lock);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001732
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001733 writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
1734 writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
1735 writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
1736 writel((TA_CTL_START | TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001737
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001738 for (j = 0; j < MAX_CTL_CHECK; j++) {
1739 temp = readl(mem_crb + TEST_AGT_CTRL);
1740 if ((temp & TA_CTL_BUSY) == 0)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001741 break;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001742 }
1743
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001744 if (j >= MAX_CTL_CHECK) {
1745 if (printk_ratelimit())
1746 dev_err(&adapter->pdev->dev,
1747 "failed to read through agent\n");
1748 ret = -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001749 } else {
Sucheta Chakraborty215387a2010-05-11 23:53:03 +00001750 val = (u64)(readl(mem_crb + MIU_TEST_AGT_RDDATA_HI)) << 32;
1751 val |= readl(mem_crb + MIU_TEST_AGT_RDDATA_LO);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001752 *data = val;
1753 ret = 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001754 }
1755
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001756 spin_unlock(&adapter->ahw.mem_lock);
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +00001757
1758 return ret;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001759}
1760
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001761void
1762netxen_setup_hwops(struct netxen_adapter *adapter)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001763{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001764 adapter->init_port = netxen_niu_xg_init_port;
1765 adapter->stop_port = netxen_niu_disable_xg_port;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001766
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001767 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1768 adapter->crb_read = netxen_nic_hw_read_wx_128M,
1769 adapter->crb_write = netxen_nic_hw_write_wx_128M,
1770 adapter->pci_set_window = netxen_nic_pci_set_window_128M,
1771 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M,
1772 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M,
1773 adapter->io_read = netxen_nic_io_read_128M,
1774 adapter->io_write = netxen_nic_io_write_128M,
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001775
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001776 adapter->macaddr_set = netxen_p2_nic_set_mac_addr;
1777 adapter->set_multi = netxen_p2_nic_set_multi;
1778 adapter->set_mtu = netxen_nic_set_mtu_xgb;
1779 adapter->set_promisc = netxen_p2_nic_set_promisc;
1780
1781 } else {
1782 adapter->crb_read = netxen_nic_hw_read_wx_2M,
1783 adapter->crb_write = netxen_nic_hw_write_wx_2M,
1784 adapter->pci_set_window = netxen_nic_pci_set_window_2M,
1785 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M,
1786 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M,
1787 adapter->io_read = netxen_nic_io_read_2M,
1788 adapter->io_write = netxen_nic_io_write_2M,
1789
1790 adapter->set_mtu = nx_fw_cmd_set_mtu;
1791 adapter->set_promisc = netxen_p3_nic_set_promisc;
1792 adapter->macaddr_set = netxen_p3_nic_set_mac_addr;
1793 adapter->set_multi = netxen_p3_nic_set_multi;
1794
1795 adapter->phy_read = nx_fw_cmd_query_phy;
1796 adapter->phy_write = nx_fw_cmd_set_phy;
1797 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001798}
1799
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001800int netxen_nic_get_board_info(struct netxen_adapter *adapter)
1801{
Dhananjay Phadke0dc6d9c2009-10-21 19:39:03 +00001802 int offset, board_type, magic;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001803 struct pci_dev *pdev = adapter->pdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001804
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001805 offset = NX_FW_MAGIC_OFFSET;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001806 if (netxen_rom_fast_read(adapter, offset, &magic))
1807 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001808
Dhananjay Phadke0dc6d9c2009-10-21 19:39:03 +00001809 if (magic != NETXEN_BDINFO_MAGIC) {
1810 dev_err(&pdev->dev, "invalid board config, magic=%08x\n",
1811 magic);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001812 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001813 }
1814
Dhananjay Phadke06db58c2009-08-05 07:34:08 +00001815 offset = NX_BRDTYPE_OFFSET;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001816 if (netxen_rom_fast_read(adapter, offset, &board_type))
1817 return -EIO;
1818
1819 adapter->ahw.board_type = board_type;
1820
1821 if (board_type == NETXEN_BRDTYPE_P3_4_GB_MM) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001822 u32 gpio = NXRD32(adapter, NETXEN_ROMUSB_GLB_PAD_GPIO_I);
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001823 if ((gpio & 0x8000) == 0)
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001824 board_type = NETXEN_BRDTYPE_P3_10G_TP;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001825 }
1826
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00001827 switch (board_type) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001828 case NETXEN_BRDTYPE_P2_SB35_4G:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001829 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001830 break;
1831 case NETXEN_BRDTYPE_P2_SB31_10G:
1832 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1833 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1834 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001835 case NETXEN_BRDTYPE_P3_HMEZ:
1836 case NETXEN_BRDTYPE_P3_XG_LOM:
1837 case NETXEN_BRDTYPE_P3_10G_CX4:
1838 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
1839 case NETXEN_BRDTYPE_P3_IMEZ:
1840 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
Dhananjay Phadkea70f9392008-08-01 03:14:56 -07001841 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
1842 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001843 case NETXEN_BRDTYPE_P3_10G_XFP:
1844 case NETXEN_BRDTYPE_P3_10000_BASE_T:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001845 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001846 break;
1847 case NETXEN_BRDTYPE_P1_BD:
1848 case NETXEN_BRDTYPE_P1_SB:
1849 case NETXEN_BRDTYPE_P1_SMAX:
1850 case NETXEN_BRDTYPE_P1_SOCK:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001851 case NETXEN_BRDTYPE_P3_REF_QG:
1852 case NETXEN_BRDTYPE_P3_4_GB:
1853 case NETXEN_BRDTYPE_P3_4_GB_MM:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001854 adapter->ahw.port_type = NETXEN_NIC_GBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001855 break;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001856 case NETXEN_BRDTYPE_P3_10G_TP:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001857 adapter->ahw.port_type = (adapter->portnum < 2) ?
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001858 NETXEN_NIC_XGBE : NETXEN_NIC_GBE;
1859 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001860 default:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001861 dev_err(&pdev->dev, "unknown board type %x\n", board_type);
1862 adapter->ahw.port_type = NETXEN_NIC_XGBE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001863 break;
1864 }
1865
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001866 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001867}
1868
1869/* NIU access sections */
1870
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001871int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001872{
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001873 new_mtu += MTU_FUDGE_FACTOR;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001874 NXWR32(adapter, NETXEN_NIU_GB_MAX_FRAME_SIZE(adapter->physical_port),
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07001875 new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001876 return 0;
1877}
1878
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001879int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001880{
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001881 new_mtu += MTU_FUDGE_FACTOR;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07001882 if (adapter->physical_port == 0)
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001883 NXWR32(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu);
Jeff Garzik47906542007-11-23 21:23:36 -05001884 else
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001885 NXWR32(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001886 return 0;
1887}
1888
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001889void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001890{
Al Viroa608ab9c2007-01-02 10:39:10 +00001891 __u32 status;
1892 __u32 autoneg;
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001893 __u32 port_mode;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001894
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001895 if (!netif_carrier_ok(adapter->netdev)) {
1896 adapter->link_speed = 0;
1897 adapter->link_duplex = -1;
1898 adapter->link_autoneg = AUTONEG_ENABLE;
1899 return;
1900 }
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001901
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001902 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001903 port_mode = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001904 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
1905 adapter->link_speed = SPEED_1000;
1906 adapter->link_duplex = DUPLEX_FULL;
1907 adapter->link_autoneg = AUTONEG_DISABLE;
1908 return;
1909 }
1910
Joe Perches8e95a202009-12-03 07:58:21 +00001911 if (adapter->phy_read &&
1912 adapter->phy_read(adapter,
1913 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
1914 &status) == 0) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001915 if (netxen_get_phy_link(status)) {
1916 switch (netxen_get_phy_speed(status)) {
1917 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001918 adapter->link_speed = SPEED_10;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001919 break;
1920 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001921 adapter->link_speed = SPEED_100;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001922 break;
1923 case 2:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001924 adapter->link_speed = SPEED_1000;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001925 break;
1926 default:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001927 adapter->link_speed = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001928 break;
1929 }
1930 switch (netxen_get_phy_duplex(status)) {
1931 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001932 adapter->link_duplex = DUPLEX_HALF;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001933 break;
1934 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001935 adapter->link_duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001936 break;
1937 default:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001938 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001939 break;
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_AUTONEG,
1944 &autoneg) != 0)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001945 adapter->link_autoneg = autoneg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001946 } else
1947 goto link_down;
1948 } else {
1949 link_down:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001950 adapter->link_speed = 0;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001951 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001952 }
1953 }
1954}
1955
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001956int
1957netxen_nic_wol_supported(struct netxen_adapter *adapter)
1958{
1959 u32 wol_cfg;
1960
1961 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
1962 return 0;
1963
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001964 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001965 if (wol_cfg & (1UL << adapter->portnum)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001966 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001967 if (wol_cfg & (1 << adapter->portnum))
1968 return 1;
1969 }
1970
1971 return 0;
1972}