blob: d46b4dff783dbd714d606e9b139b2f84420672e3 [file] [log] [blame]
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001/*
2 * Copyright (C) 2003 - 2006 NetXen, Inc.
3 * All rights reserved.
Amit S. Kale80922fb2006-12-04 09:18:00 -08004 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -04005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
Amit S. Kalecb8011a2006-11-29 09:00:10 -08009 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040010 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Amit S. Kalecb8011a2006-11-29 09:00:10 -080014 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040015 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 * MA 02111-1307, USA.
Amit S. Kale80922fb2006-12-04 09:18:00 -080019 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040020 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
Amit S. Kale80922fb2006-12-04 09:18:00 -080022 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040023 * Contact Information:
24 * info@netxen.com
25 * NetXen,
26 * 3965 Freedom Circle, Fourth floor,
27 * Santa Clara, CA 95054
28 *
29 *
30 * Source file for NIC routines to access the Phantom hardware
31 *
32 */
33
34#include "netxen_nic.h"
35#include "netxen_nic_hw.h"
36#include "netxen_nic_phan_reg.h"
37
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070038
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030039#include <net/ip.h>
40
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070041#define MASK(n) ((1ULL<<(n))-1)
42#define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff))
43#define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff))
44#define MS_WIN(addr) (addr & 0x0ffc0000)
45
46#define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
47
48#define CRB_BLK(off) ((off >> 20) & 0x3f)
49#define CRB_SUBBLK(off) ((off >> 16) & 0xf)
50#define CRB_WINDOW_2M (0x130060)
51#define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000))
52#define CRB_INDIRECT_2M (0x1e0000UL)
53
54#define CRB_WIN_LOCK_TIMEOUT 100000000
55static crb_128M_2M_block_map_t crb_128M_2M_map[64] = {
56 {{{0, 0, 0, 0} } }, /* 0: PCI */
57 {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */
58 {1, 0x0110000, 0x0120000, 0x130000},
59 {1, 0x0120000, 0x0122000, 0x124000},
60 {1, 0x0130000, 0x0132000, 0x126000},
61 {1, 0x0140000, 0x0142000, 0x128000},
62 {1, 0x0150000, 0x0152000, 0x12a000},
63 {1, 0x0160000, 0x0170000, 0x110000},
64 {1, 0x0170000, 0x0172000, 0x12e000},
65 {0, 0x0000000, 0x0000000, 0x000000},
66 {0, 0x0000000, 0x0000000, 0x000000},
67 {0, 0x0000000, 0x0000000, 0x000000},
68 {0, 0x0000000, 0x0000000, 0x000000},
69 {0, 0x0000000, 0x0000000, 0x000000},
70 {0, 0x0000000, 0x0000000, 0x000000},
71 {1, 0x01e0000, 0x01e0800, 0x122000},
72 {0, 0x0000000, 0x0000000, 0x000000} } },
73 {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */
74 {{{0, 0, 0, 0} } }, /* 3: */
75 {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */
76 {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */
77 {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */
78 {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */
79 {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */
80 {0, 0x0000000, 0x0000000, 0x000000},
81 {0, 0x0000000, 0x0000000, 0x000000},
82 {0, 0x0000000, 0x0000000, 0x000000},
83 {0, 0x0000000, 0x0000000, 0x000000},
84 {0, 0x0000000, 0x0000000, 0x000000},
85 {0, 0x0000000, 0x0000000, 0x000000},
86 {0, 0x0000000, 0x0000000, 0x000000},
87 {0, 0x0000000, 0x0000000, 0x000000},
88 {0, 0x0000000, 0x0000000, 0x000000},
89 {0, 0x0000000, 0x0000000, 0x000000},
90 {0, 0x0000000, 0x0000000, 0x000000},
91 {0, 0x0000000, 0x0000000, 0x000000},
92 {0, 0x0000000, 0x0000000, 0x000000},
93 {0, 0x0000000, 0x0000000, 0x000000},
94 {1, 0x08f0000, 0x08f2000, 0x172000} } },
95 {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/
96 {0, 0x0000000, 0x0000000, 0x000000},
97 {0, 0x0000000, 0x0000000, 0x000000},
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 {0, 0x0000000, 0x0000000, 0x000000},
105 {0, 0x0000000, 0x0000000, 0x000000},
106 {0, 0x0000000, 0x0000000, 0x000000},
107 {0, 0x0000000, 0x0000000, 0x000000},
108 {0, 0x0000000, 0x0000000, 0x000000},
109 {0, 0x0000000, 0x0000000, 0x000000},
110 {1, 0x09f0000, 0x09f2000, 0x176000} } },
111 {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/
112 {0, 0x0000000, 0x0000000, 0x000000},
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 {1, 0x0af0000, 0x0af2000, 0x17a000} } },
127 {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/
128 {0, 0x0000000, 0x0000000, 0x000000},
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 {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
143 {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */
144 {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */
145 {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */
146 {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */
147 {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */
148 {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */
149 {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */
150 {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */
151 {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */
152 {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */
153 {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */
154 {{{0, 0, 0, 0} } }, /* 23: */
155 {{{0, 0, 0, 0} } }, /* 24: */
156 {{{0, 0, 0, 0} } }, /* 25: */
157 {{{0, 0, 0, 0} } }, /* 26: */
158 {{{0, 0, 0, 0} } }, /* 27: */
159 {{{0, 0, 0, 0} } }, /* 28: */
160 {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */
161 {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */
162 {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */
163 {{{0} } }, /* 32: PCI */
164 {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */
165 {1, 0x2110000, 0x2120000, 0x130000},
166 {1, 0x2120000, 0x2122000, 0x124000},
167 {1, 0x2130000, 0x2132000, 0x126000},
168 {1, 0x2140000, 0x2142000, 0x128000},
169 {1, 0x2150000, 0x2152000, 0x12a000},
170 {1, 0x2160000, 0x2170000, 0x110000},
171 {1, 0x2170000, 0x2172000, 0x12e000},
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 {0, 0x0000000, 0x0000000, 0x000000},
179 {0, 0x0000000, 0x0000000, 0x000000} } },
180 {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */
181 {{{0} } }, /* 35: */
182 {{{0} } }, /* 36: */
183 {{{0} } }, /* 37: */
184 {{{0} } }, /* 38: */
185 {{{0} } }, /* 39: */
186 {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */
187 {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */
188 {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */
189 {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */
190 {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */
191 {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */
192 {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */
193 {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */
194 {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */
195 {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */
196 {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */
197 {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */
198 {{{0} } }, /* 52: */
199 {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */
200 {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */
201 {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */
202 {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */
203 {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */
204 {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */
205 {{{0} } }, /* 59: I2C0 */
206 {{{0} } }, /* 60: I2C1 */
207 {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */
208 {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */
209 {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */
210};
211
212/*
213 * top 12 bits of crb internal address (hub, agent)
214 */
215static unsigned crb_hub_agt[64] =
216{
217 0,
218 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
219 NETXEN_HW_CRB_HUB_AGT_ADR_MN,
220 NETXEN_HW_CRB_HUB_AGT_ADR_MS,
221 0,
222 NETXEN_HW_CRB_HUB_AGT_ADR_SRE,
223 NETXEN_HW_CRB_HUB_AGT_ADR_NIU,
224 NETXEN_HW_CRB_HUB_AGT_ADR_QMN,
225 NETXEN_HW_CRB_HUB_AGT_ADR_SQN0,
226 NETXEN_HW_CRB_HUB_AGT_ADR_SQN1,
227 NETXEN_HW_CRB_HUB_AGT_ADR_SQN2,
228 NETXEN_HW_CRB_HUB_AGT_ADR_SQN3,
229 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
230 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
231 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
232 NETXEN_HW_CRB_HUB_AGT_ADR_PGN4,
233 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
234 NETXEN_HW_CRB_HUB_AGT_ADR_PGN0,
235 NETXEN_HW_CRB_HUB_AGT_ADR_PGN1,
236 NETXEN_HW_CRB_HUB_AGT_ADR_PGN2,
237 NETXEN_HW_CRB_HUB_AGT_ADR_PGN3,
238 NETXEN_HW_CRB_HUB_AGT_ADR_PGND,
239 NETXEN_HW_CRB_HUB_AGT_ADR_PGNI,
240 NETXEN_HW_CRB_HUB_AGT_ADR_PGS0,
241 NETXEN_HW_CRB_HUB_AGT_ADR_PGS1,
242 NETXEN_HW_CRB_HUB_AGT_ADR_PGS2,
243 NETXEN_HW_CRB_HUB_AGT_ADR_PGS3,
244 0,
245 NETXEN_HW_CRB_HUB_AGT_ADR_PGSI,
246 NETXEN_HW_CRB_HUB_AGT_ADR_SN,
247 0,
248 NETXEN_HW_CRB_HUB_AGT_ADR_EG,
249 0,
250 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
251 NETXEN_HW_CRB_HUB_AGT_ADR_CAM,
252 0,
253 0,
254 0,
255 0,
256 0,
257 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
258 0,
259 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1,
260 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2,
261 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3,
262 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4,
263 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5,
264 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6,
265 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7,
266 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
267 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
268 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
269 0,
270 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0,
271 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8,
272 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9,
273 NETXEN_HW_CRB_HUB_AGT_ADR_OCM0,
274 0,
275 NETXEN_HW_CRB_HUB_AGT_ADR_SMB,
276 NETXEN_HW_CRB_HUB_AGT_ADR_I2C0,
277 NETXEN_HW_CRB_HUB_AGT_ADR_I2C1,
278 0,
279 NETXEN_HW_CRB_HUB_AGT_ADR_PGNC,
280 0,
281};
282
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400283/* PCI Windowing for DDR regions. */
284
285#define ADDR_IN_RANGE(addr, low, high) \
286 (((addr) <= (high)) && ((addr) >= (low)))
287
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800288#define NETXEN_MAX_MTU 8000 + NETXEN_ENET_HEADER_SIZE + NETXEN_ETH_FCS_SIZE
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800289#define NETXEN_MIN_MTU 64
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400290#define NETXEN_ETH_FCS_SIZE 4
291#define NETXEN_ENET_HEADER_SIZE 14
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700292#define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400293#define NETXEN_FIRMWARE_LEN ((16 * 1024) / 4)
294#define NETXEN_NIU_HDRSIZE (0x1 << 6)
295#define NETXEN_NIU_TLRSIZE (0x1 << 5)
296
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800297#define NETXEN_NIC_ZERO_PAUSE_ADDR 0ULL
298#define NETXEN_NIC_UNIT_PAUSE_ADDR 0x200ULL
299#define NETXEN_NIC_EPG_PAUSE_ADDR1 0x2200010000c28001ULL
300#define NETXEN_NIC_EPG_PAUSE_ADDR2 0x0100088866554433ULL
301
302#define NETXEN_NIC_WINDOW_MARGIN 0x100000
303
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400304int netxen_nic_set_mac(struct net_device *netdev, void *p)
305{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700306 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400307 struct sockaddr *addr = p;
308
309 if (netif_running(netdev))
310 return -EBUSY;
311
312 if (!is_valid_ether_addr(addr->sa_data))
313 return -EADDRNOTAVAIL;
314
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400315 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
316
Amit S. Kale80922fb2006-12-04 09:18:00 -0800317 if (adapter->macaddr_set)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700318 adapter->macaddr_set(adapter, addr->sa_data);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400319
320 return 0;
321}
322
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700323#define NETXEN_UNICAST_ADDR(port, index) \
324 (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8))
325#define NETXEN_MCAST_ADDR(port, index) \
326 (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8))
327#define MAC_HI(addr) \
328 ((addr[2] << 16) | (addr[1] << 8) | (addr[0]))
329#define MAC_LO(addr) \
330 ((addr[5] << 16) | (addr[4] << 8) | (addr[3]))
331
332static int
333netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter)
334{
335 u32 val = 0;
336 u16 port = adapter->physical_port;
337 u8 *addr = adapter->netdev->dev_addr;
338
339 if (adapter->mc_enabled)
340 return 0;
341
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700342 adapter->hw_read_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700343 val |= (1UL << (28+port));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700344 adapter->hw_write_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700345
346 /* add broadcast addr to filter */
347 val = 0xffffff;
348 netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
349 netxen_crb_writelit_adapter(adapter,
350 NETXEN_UNICAST_ADDR(port, 0)+4, val);
351
352 /* add station addr to filter */
353 val = MAC_HI(addr);
354 netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 1), val);
355 val = MAC_LO(addr);
356 netxen_crb_writelit_adapter(adapter,
357 NETXEN_UNICAST_ADDR(port, 1)+4, val);
358
359 adapter->mc_enabled = 1;
360 return 0;
361}
362
363static int
364netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter)
365{
366 u32 val = 0;
367 u16 port = adapter->physical_port;
368 u8 *addr = adapter->netdev->dev_addr;
369
370 if (!adapter->mc_enabled)
371 return 0;
372
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700373 adapter->hw_read_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700374 val &= ~(1UL << (28+port));
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700375 adapter->hw_write_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700376
377 val = MAC_HI(addr);
378 netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
379 val = MAC_LO(addr);
380 netxen_crb_writelit_adapter(adapter,
381 NETXEN_UNICAST_ADDR(port, 0)+4, val);
382
383 netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 1), 0);
384 netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0);
385
386 adapter->mc_enabled = 0;
387 return 0;
388}
389
390static int
391netxen_nic_set_mcast_addr(struct netxen_adapter *adapter,
392 int index, u8 *addr)
393{
394 u32 hi = 0, lo = 0;
395 u16 port = adapter->physical_port;
396
397 lo = MAC_LO(addr);
398 hi = MAC_HI(addr);
399
400 netxen_crb_writelit_adapter(adapter,
401 NETXEN_MCAST_ADDR(port, index), hi);
402 netxen_crb_writelit_adapter(adapter,
403 NETXEN_MCAST_ADDR(port, index)+4, lo);
404
405 return 0;
406}
407
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400408/*
409 * netxen_nic_set_multi - Multicast
410 */
411void netxen_nic_set_multi(struct net_device *netdev)
412{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700413 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400414 struct dev_mc_list *mc_ptr;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700415 u8 null_addr[6];
416 int index = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400417
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700418 memset(null_addr, 0, 6);
419
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400420 if (netdev->flags & IFF_PROMISC) {
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700421
422 adapter->set_promisc(adapter,
423 NETXEN_NIU_PROMISC_MODE);
424
425 /* Full promiscuous mode */
426 netxen_nic_disable_mcast_filter(adapter);
427
428 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400429 }
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700430
431 if (netdev->mc_count == 0) {
432 adapter->set_promisc(adapter,
433 NETXEN_NIU_NON_PROMISC_MODE);
434 netxen_nic_disable_mcast_filter(adapter);
435 return;
436 }
437
438 adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE);
439 if (netdev->flags & IFF_ALLMULTI ||
440 netdev->mc_count > adapter->max_mc_count) {
441 netxen_nic_disable_mcast_filter(adapter);
442 return;
443 }
444
445 netxen_nic_enable_mcast_filter(adapter);
446
447 for (mc_ptr = netdev->mc_list; mc_ptr; mc_ptr = mc_ptr->next, index++)
448 netxen_nic_set_mcast_addr(adapter, index, mc_ptr->dmi_addr);
449
450 if (index != netdev->mc_count)
451 printk(KERN_WARNING "%s: %s multicast address count mismatch\n",
452 netxen_nic_driver_name, netdev->name);
453
454 /* Clear out remaining addresses */
455 for (; index < adapter->max_mc_count; index++)
456 netxen_nic_set_mcast_addr(adapter, index, null_addr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400457}
458
459/*
460 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
461 * @returns 0 on success, negative on failure
462 */
463int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
464{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700465 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400466 int eff_mtu = mtu + NETXEN_ENET_HEADER_SIZE + NETXEN_ETH_FCS_SIZE;
467
468 if ((eff_mtu > NETXEN_MAX_MTU) || (eff_mtu < NETXEN_MIN_MTU)) {
469 printk(KERN_ERR "%s: %s %d is not supported.\n",
470 netxen_nic_driver_name, netdev->name, mtu);
471 return -EINVAL;
472 }
473
Amit S. Kale80922fb2006-12-04 09:18:00 -0800474 if (adapter->set_mtu)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700475 adapter->set_mtu(adapter, mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400476 netdev->mtu = mtu;
477
478 return 0;
479}
480
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400481void netxen_tso_check(struct netxen_adapter *adapter,
482 struct cmd_desc_type0 *desc, struct sk_buff *skb)
483{
484 if (desc->mss) {
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -0300485 desc->total_hdr_length = (sizeof(struct ethhdr) +
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -0700486 ip_hdrlen(skb) + tcp_hdrlen(skb));
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800487 netxen_set_cmd_desc_opcode(desc, TX_TCP_LSO);
Amit S. Kalec75e86b2006-12-18 05:51:58 -0800488 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700489 if (ip_hdr(skb)->protocol == IPPROTO_TCP) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800490 netxen_set_cmd_desc_opcode(desc, TX_TCP_PKT);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700491 } else if (ip_hdr(skb)->protocol == IPPROTO_UDP) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800492 netxen_set_cmd_desc_opcode(desc, TX_UDP_PKT);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400493 } else {
494 return;
495 }
496 }
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -0700497 desc->tcp_hdr_offset = skb_transport_offset(skb);
Arnaldo Carvalho de Melobbe735e2007-03-10 22:16:10 -0300498 desc->ip_hdr_offset = skb_network_offset(skb);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400499}
500
501int netxen_is_flash_supported(struct netxen_adapter *adapter)
502{
503 const int locs[] = { 0, 0x4, 0x100, 0x4000, 0x4128 };
504 int addr, val01, val02, i, j;
505
506 /* if the flash size less than 4Mb, make huge war cry and die */
507 for (j = 1; j < 4; j++) {
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800508 addr = j * NETXEN_NIC_WINDOW_MARGIN;
Denis Chengff8ac602007-09-02 18:30:18 +0800509 for (i = 0; i < ARRAY_SIZE(locs); i++) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400510 if (netxen_rom_fast_read(adapter, locs[i], &val01) == 0
511 && netxen_rom_fast_read(adapter, (addr + locs[i]),
512 &val02) == 0) {
513 if (val01 == val02)
514 return -1;
515 } else
516 return -1;
517 }
518 }
519
520 return 0;
521}
522
523static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
Al Virof305f782007-12-22 19:44:00 +0000524 int size, __le32 * buf)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400525{
526 int i, addr;
Al Virof305f782007-12-22 19:44:00 +0000527 __le32 *ptr32;
528 u32 v;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400529
530 addr = base;
531 ptr32 = buf;
532 for (i = 0; i < size / sizeof(u32); i++) {
Al Virof305f782007-12-22 19:44:00 +0000533 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400534 return -1;
Al Virof305f782007-12-22 19:44:00 +0000535 *ptr32 = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400536 ptr32++;
537 addr += sizeof(u32);
538 }
539 if ((char *)buf + size > (char *)ptr32) {
Al Virof305f782007-12-22 19:44:00 +0000540 __le32 local;
541 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400542 return -1;
Al Virof305f782007-12-22 19:44:00 +0000543 local = cpu_to_le32(v);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400544 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
545 }
546
547 return 0;
548}
549
Al Virof305f782007-12-22 19:44:00 +0000550int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 mac[])
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400551{
Al Virof305f782007-12-22 19:44:00 +0000552 __le32 *pmac = (__le32 *) & mac[0];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400553
554 if (netxen_get_flash_block(adapter,
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700555 NETXEN_USER_START +
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400556 offsetof(struct netxen_new_user_info,
557 mac_addr),
558 FLASH_NUM_PORTS * sizeof(u64), pmac) == -1) {
559 return -1;
560 }
Al Virof305f782007-12-22 19:44:00 +0000561 if (*mac == cpu_to_le64(~0ULL)) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400562 if (netxen_get_flash_block(adapter,
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700563 NETXEN_USER_START_OLD +
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400564 offsetof(struct netxen_user_old_info,
565 mac_addr),
566 FLASH_NUM_PORTS * sizeof(u64),
567 pmac) == -1)
568 return -1;
Al Virof305f782007-12-22 19:44:00 +0000569 if (*mac == cpu_to_le64(~0ULL))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400570 return -1;
571 }
572 return 0;
573}
574
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700575#define CRB_WIN_LOCK_TIMEOUT 100000000
576
577static int crb_win_lock(struct netxen_adapter *adapter)
578{
579 int done = 0, timeout = 0;
580
581 while (!done) {
582 /* acquire semaphore3 from PCI HW block */
583 adapter->hw_read_wx(adapter,
584 NETXEN_PCIE_REG(PCIE_SEM7_LOCK), &done, 4);
585 if (done == 1)
586 break;
587 if (timeout >= CRB_WIN_LOCK_TIMEOUT)
588 return -1;
589 timeout++;
590 udelay(1);
591 }
592 netxen_crb_writelit_adapter(adapter,
593 NETXEN_CRB_WIN_LOCK_ID, adapter->portnum);
594 return 0;
595}
596
597static void crb_win_unlock(struct netxen_adapter *adapter)
598{
599 int val;
600
601 adapter->hw_read_wx(adapter,
602 NETXEN_PCIE_REG(PCIE_SEM7_UNLOCK), &val, 4);
603}
604
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400605/*
606 * Changes the CRB window to the specified window.
607 */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700608void
609netxen_nic_pci_change_crbwindow_128M(struct netxen_adapter *adapter, u32 wndw)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400610{
611 void __iomem *offset;
612 u32 tmp;
613 int count = 0;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700614 uint8_t func = adapter->ahw.pci_func;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400615
616 if (adapter->curr_window == wndw)
617 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400618 /*
619 * Move the CRB window.
620 * We need to write to the "direct access" region of PCI
621 * to avoid a race condition where the window register has
622 * not been successfully written across CRB before the target
623 * register address is received by PCI. The direct region bypasses
624 * the CRB bus.
625 */
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700626 offset = PCI_OFFSET_SECOND_RANGE(adapter,
627 NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400628
629 if (wndw & 0x1)
630 wndw = NETXEN_WINDOW_ONE;
631
632 writel(wndw, offset);
633
634 /* MUST make sure window is set before we forge on... */
635 while ((tmp = readl(offset)) != wndw) {
636 printk(KERN_WARNING "%s: %s WARNING: CRB window value not "
637 "registered properly: 0x%08x.\n",
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700638 netxen_nic_driver_name, __func__, tmp);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400639 mdelay(1);
640 if (count >= 10)
641 break;
642 count++;
643 }
644
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700645 if (wndw == NETXEN_WINDOW_ONE)
646 adapter->curr_window = 1;
647 else
648 adapter->curr_window = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400649}
650
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700651/*
652 * Return -1 if off is not valid,
653 * 1 if window access is needed. 'off' is set to offset from
654 * CRB space in 128M pci map
655 * 0 if no window access is needed. 'off' is set to 2M addr
656 * In: 'off' is offset from base in 128M pci map
657 */
658static int
659netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter,
660 ulong *off, int len)
661{
662 unsigned long end = *off + len;
663 crb_128M_2M_sub_block_map_t *m;
664
665
666 if (*off >= NETXEN_CRB_MAX)
667 return -1;
668
669 if (*off >= NETXEN_PCI_CAMQM && (end <= NETXEN_PCI_CAMQM_2M_END)) {
670 *off = (*off - NETXEN_PCI_CAMQM) + NETXEN_PCI_CAMQM_2M_BASE +
671 (ulong)adapter->ahw.pci_base0;
672 return 0;
673 }
674
675 if (*off < NETXEN_PCI_CRBSPACE)
676 return -1;
677
678 *off -= NETXEN_PCI_CRBSPACE;
679 end = *off + len;
680
681 /*
682 * Try direct map
683 */
684 m = &crb_128M_2M_map[CRB_BLK(*off)].sub_block[CRB_SUBBLK(*off)];
685
686 if (m->valid && (m->start_128M <= *off) && (m->end_128M >= end)) {
687 *off = *off + m->start_2M - m->start_128M +
688 (ulong)adapter->ahw.pci_base0;
689 return 0;
690 }
691
692 /*
693 * Not in direct map, use crb window
694 */
695 return 1;
696}
697
698/*
699 * In: 'off' is offset from CRB space in 128M pci map
700 * Out: 'off' is 2M pci map addr
701 * side effect: lock crb window
702 */
703static void
704netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong *off)
705{
706 u32 win_read;
707
708 adapter->crb_win = CRB_HI(*off);
709 writel(adapter->crb_win, (void *)(CRB_WINDOW_2M +
710 adapter->ahw.pci_base0));
711 /*
712 * Read back value to make sure write has gone through before trying
713 * to use it.
714 */
715 win_read = readl((void *)(CRB_WINDOW_2M + adapter->ahw.pci_base0));
716 if (win_read != adapter->crb_win) {
717 printk(KERN_ERR "%s: Written crbwin (0x%x) != "
718 "Read crbwin (0x%x), off=0x%lx\n",
719 __func__, adapter->crb_win, win_read, *off);
720 }
721 *off = (*off & MASK(16)) + CRB_INDIRECT_2M +
722 (ulong)adapter->ahw.pci_base0;
723}
724
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530725int netxen_load_firmware(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400726{
727 int i;
Linsys Contractor Mithlesh Thukrale0e20a12007-02-28 05:16:40 -0800728 u32 data, size = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700729 u32 flashaddr = NETXEN_BOOTLD_START, memaddr = NETXEN_BOOTLD_START;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400730
Dhananjay Phadke29566402008-07-21 19:44:04 -0700731 size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START)/4;
732
733 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
734 adapter->pci_write_normalize(adapter,
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700735 NETXEN_ROMUSB_GLB_CAS_RST, 1);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400736
737 for (i = 0; i < size; i++) {
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530738 if (netxen_rom_fast_read(adapter, flashaddr, (int *)&data) != 0)
739 return -EIO;
740
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700741 adapter->pci_mem_write(adapter, memaddr, &data, 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400742 flashaddr += 4;
743 memaddr += 4;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700744 cond_resched();
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400745 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700746 msleep(1);
747
748 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
749 adapter->pci_write_normalize(adapter,
750 NETXEN_ROMUSB_GLB_SW_RESET, 0x80001d);
751 else {
752 adapter->pci_write_normalize(adapter,
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700753 NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL, 0x3fff);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700754 adapter->pci_write_normalize(adapter,
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700755 NETXEN_ROMUSB_GLB_CAS_RST, 0);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700756 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400757
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530758 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400759}
760
761int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700762netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter,
763 ulong off, void *data, int len)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400764{
765 void __iomem *addr;
766
767 if (ADDR_IN_WINDOW1(off)) {
768 addr = NETXEN_CRB_NORMALIZE(adapter, off);
769 } else { /* Window 0 */
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800770 addr = pci_base_offset(adapter, off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700771 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400772 }
773
774 DPRINTK(INFO, "writing to base %lx offset %llx addr %p"
775 " data %llx len %d\n",
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800776 pci_base(adapter, off), off, addr,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400777 *(unsigned long long *)data, len);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800778 if (!addr) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700779 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800780 return 1;
781 }
782
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400783 switch (len) {
784 case 1:
785 writeb(*(u8 *) data, addr);
786 break;
787 case 2:
788 writew(*(u16 *) data, addr);
789 break;
790 case 4:
791 writel(*(u32 *) data, addr);
792 break;
793 case 8:
794 writeq(*(u64 *) data, addr);
795 break;
796 default:
797 DPRINTK(INFO,
798 "writing data %lx to offset %llx, num words=%d\n",
799 *(unsigned long *)data, off, (len >> 3));
800
801 netxen_nic_hw_block_write64((u64 __iomem *) data, addr,
802 (len >> 3));
803 break;
804 }
805 if (!ADDR_IN_WINDOW1(off))
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700806 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400807
808 return 0;
809}
810
811int
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700812netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter,
813 ulong off, void *data, int len)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400814{
815 void __iomem *addr;
816
817 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
818 addr = NETXEN_CRB_NORMALIZE(adapter, off);
819 } else { /* Window 0 */
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800820 addr = pci_base_offset(adapter, off);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700821 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400822 }
823
824 DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n",
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800825 pci_base(adapter, off), off, addr);
826 if (!addr) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700827 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800828 return 1;
829 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400830 switch (len) {
831 case 1:
832 *(u8 *) data = readb(addr);
833 break;
834 case 2:
835 *(u16 *) data = readw(addr);
836 break;
837 case 4:
838 *(u32 *) data = readl(addr);
839 break;
840 case 8:
841 *(u64 *) data = readq(addr);
842 break;
843 default:
844 netxen_nic_hw_block_read64((u64 __iomem *) data, addr,
845 (len >> 3));
846 break;
847 }
848 DPRINTK(INFO, "read %lx\n", *(unsigned long *)data);
849
850 if (!ADDR_IN_WINDOW1(off))
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700851 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
852
853 return 0;
854}
855
856int
857netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter,
858 ulong off, void *data, int len)
859{
860 unsigned long flags = 0;
861 int rv;
862
863 rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off, len);
864
865 if (rv == -1) {
866 printk(KERN_ERR "%s: invalid offset: 0x%016lx\n",
867 __func__, off);
868 dump_stack();
869 return -1;
870 }
871
872 if (rv == 1) {
873 write_lock_irqsave(&adapter->adapter_lock, flags);
874 crb_win_lock(adapter);
875 netxen_nic_pci_set_crbwindow_2M(adapter, &off);
876 }
877
878 DPRINTK(1, INFO, "write data %lx to offset %llx, len=%d\n",
879 *(unsigned long *)data, off, len);
880
881 switch (len) {
882 case 1:
883 writeb(*(uint8_t *)data, (void *)off);
884 break;
885 case 2:
886 writew(*(uint16_t *)data, (void *)off);
887 break;
888 case 4:
889 writel(*(uint32_t *)data, (void *)off);
890 break;
891 case 8:
892 writeq(*(uint64_t *)data, (void *)off);
893 break;
894 default:
895 DPRINTK(1, INFO,
896 "writing data %lx to offset %llx, num words=%d\n",
897 *(unsigned long *)data, off, (len>>3));
898 break;
899 }
900 if (rv == 1) {
901 crb_win_unlock(adapter);
902 write_unlock_irqrestore(&adapter->adapter_lock, flags);
903 }
904
905 return 0;
906}
907
908int
909netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter,
910 ulong off, void *data, int len)
911{
912 unsigned long flags = 0;
913 int rv;
914
915 rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off, len);
916
917 if (rv == -1) {
918 printk(KERN_ERR "%s: invalid offset: 0x%016lx\n",
919 __func__, off);
920 dump_stack();
921 return -1;
922 }
923
924 if (rv == 1) {
925 write_lock_irqsave(&adapter->adapter_lock, flags);
926 crb_win_lock(adapter);
927 netxen_nic_pci_set_crbwindow_2M(adapter, &off);
928 }
929
930 DPRINTK(1, INFO, "read from offset %lx, len=%d\n", off, len);
931
932 switch (len) {
933 case 1:
934 *(uint8_t *)data = readb((void *)off);
935 break;
936 case 2:
937 *(uint16_t *)data = readw((void *)off);
938 break;
939 case 4:
940 *(uint32_t *)data = readl((void *)off);
941 break;
942 case 8:
943 *(uint64_t *)data = readq((void *)off);
944 break;
945 default:
946 break;
947 }
948
949 DPRINTK(1, INFO, "read %lx\n", *(unsigned long *)data);
950
951 if (rv == 1) {
952 crb_win_unlock(adapter);
953 write_unlock_irqrestore(&adapter->adapter_lock, flags);
954 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400955
956 return 0;
957}
958
959void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700960{
961 adapter->hw_write_wx(adapter, off, &val, 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400962}
963
964int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700965{
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400966 int val;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700967 adapter->hw_read_wx(adapter, off, &val, 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400968 return val;
969}
970
971/* Change the window to 0, write and change back to window 1. */
972void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value)
973{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700974 adapter->hw_write_wx(adapter, index, &value, 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400975}
976
977/* Change the window to 0, read and change back to window 1. */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700978void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 *value)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400979{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700980 adapter->hw_read_wx(adapter, index, value, 4);
981}
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400982
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700983void netxen_nic_write_w1(struct netxen_adapter *adapter, u32 index, u32 value)
984{
985 adapter->hw_write_wx(adapter, index, &value, 4);
986}
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400987
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700988void netxen_nic_read_w1(struct netxen_adapter *adapter, u32 index, u32 *value)
989{
990 adapter->hw_read_wx(adapter, index, value, 4);
991}
992
993/*
994 * check memory access boundary.
995 * used by test agent. support ddr access only for now
996 */
997static unsigned long
998netxen_nic_pci_mem_bound_check(struct netxen_adapter *adapter,
999 unsigned long long addr, int size)
1000{
1001 if (!ADDR_IN_RANGE(addr,
1002 NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX) ||
1003 !ADDR_IN_RANGE(addr+size-1,
1004 NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX) ||
1005 ((size != 1) && (size != 2) && (size != 4) && (size != 8))) {
1006 return 0;
1007 }
1008
1009 return 1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001010}
1011
Jeff Garzik47906542007-11-23 21:23:36 -05001012static int netxen_pci_set_window_warning_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001013
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001014unsigned long
1015netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
1016 unsigned long long addr)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001017{
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001018 void __iomem *offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001019 int window;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001020 unsigned long long qdr_max;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001021 uint8_t func = adapter->ahw.pci_func;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001022
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001023 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1024 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P2;
1025 } else {
1026 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P3;
1027 }
1028
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001029 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1030 /* DDR network side */
1031 addr -= NETXEN_ADDR_DDR_NET;
1032 window = (addr >> 25) & 0x3ff;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001033 if (adapter->ahw.ddr_mn_window != window) {
1034 adapter->ahw.ddr_mn_window = window;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001035 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1036 NETXEN_PCIX_PH_REG(PCIE_MN_WINDOW_REG(func)));
1037 writel(window, offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001038 /* MUST make sure window is set before we forge on... */
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001039 readl(offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001040 }
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001041 addr -= (window * NETXEN_WINDOW_ONE);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001042 addr += NETXEN_PCI_DDR_NET;
1043 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1044 addr -= NETXEN_ADDR_OCM0;
1045 addr += NETXEN_PCI_OCM0;
1046 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1047 addr -= NETXEN_ADDR_OCM1;
1048 addr += NETXEN_PCI_OCM1;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001049 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_QDR_NET, qdr_max)) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001050 /* QDR network side */
1051 addr -= NETXEN_ADDR_QDR_NET;
1052 window = (addr >> 22) & 0x3f;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001053 if (adapter->ahw.qdr_sn_window != window) {
1054 adapter->ahw.qdr_sn_window = window;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001055 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1056 NETXEN_PCIX_PH_REG(PCIE_SN_WINDOW_REG(func)));
1057 writel((window << 22), offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001058 /* MUST make sure window is set before we forge on... */
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001059 readl(offset);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001060 }
1061 addr -= (window * 0x400000);
1062 addr += NETXEN_PCI_QDR_NET;
1063 } else {
1064 /*
1065 * peg gdb frequently accesses memory that doesn't exist,
1066 * this limits the chit chat so debugging isn't slowed down.
1067 */
1068 if ((netxen_pci_set_window_warning_count++ < 8)
1069 || (netxen_pci_set_window_warning_count % 64 == 0))
1070 printk("%s: Warning:netxen_nic_pci_set_window()"
1071 " Unknown address range!\n",
1072 netxen_nic_driver_name);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001073 addr = -1UL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001074 }
1075 return addr;
1076}
1077
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001078/*
1079 * Note : only 32-bit writes!
1080 */
1081int netxen_nic_pci_write_immediate_128M(struct netxen_adapter *adapter,
1082 u64 off, u32 data)
1083{
1084 writel(data, (void __iomem *)(PCI_OFFSET_SECOND_RANGE(adapter, off)));
1085 return 0;
1086}
1087
1088u32 netxen_nic_pci_read_immediate_128M(struct netxen_adapter *adapter, u64 off)
1089{
1090 return readl((void __iomem *)(pci_base_offset(adapter, off)));
1091}
1092
1093void netxen_nic_pci_write_normalize_128M(struct netxen_adapter *adapter,
1094 u64 off, u32 data)
1095{
1096 writel(data, NETXEN_CRB_NORMALIZE(adapter, off));
1097}
1098
1099u32 netxen_nic_pci_read_normalize_128M(struct netxen_adapter *adapter, u64 off)
1100{
1101 return readl(NETXEN_CRB_NORMALIZE(adapter, off));
1102}
1103
1104unsigned long
1105netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
1106 unsigned long long addr)
1107{
1108 int window;
1109 u32 win_read;
1110
1111 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1112 /* DDR network side */
1113 window = MN_WIN(addr);
1114 adapter->ahw.ddr_mn_window = window;
1115 adapter->hw_write_wx(adapter,
1116 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
1117 &window, 4);
1118 adapter->hw_read_wx(adapter,
1119 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
1120 &win_read, 4);
1121 if ((win_read << 17) != window) {
1122 printk(KERN_INFO "Written MNwin (0x%x) != "
1123 "Read MNwin (0x%x)\n", window, win_read);
1124 }
1125 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_DDR_NET;
1126 } else if (ADDR_IN_RANGE(addr,
1127 NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1128 if ((addr & 0x00ff800) == 0xff800) {
1129 printk("%s: QM access not handled.\n", __func__);
1130 addr = -1UL;
1131 }
1132
1133 window = OCM_WIN(addr);
1134 adapter->ahw.ddr_mn_window = window;
1135 adapter->hw_write_wx(adapter,
1136 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
1137 &window, 4);
1138 adapter->hw_read_wx(adapter,
1139 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
1140 &win_read, 4);
1141 if ((win_read >> 7) != window) {
1142 printk(KERN_INFO "%s: Written OCMwin (0x%x) != "
1143 "Read OCMwin (0x%x)\n",
1144 __func__, window, win_read);
1145 }
1146 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_OCM0_2M;
1147
1148 } else if (ADDR_IN_RANGE(addr,
1149 NETXEN_ADDR_QDR_NET, NETXEN_ADDR_QDR_NET_MAX_P3)) {
1150 /* QDR network side */
1151 window = MS_WIN(addr);
1152 adapter->ahw.qdr_sn_window = window;
1153 adapter->hw_write_wx(adapter,
1154 adapter->ahw.ms_win_crb | NETXEN_PCI_CRBSPACE,
1155 &window, 4);
1156 adapter->hw_read_wx(adapter,
1157 adapter->ahw.ms_win_crb | NETXEN_PCI_CRBSPACE,
1158 &win_read, 4);
1159 if (win_read != window) {
1160 printk(KERN_INFO "%s: Written MSwin (0x%x) != "
1161 "Read MSwin (0x%x)\n",
1162 __func__, window, win_read);
1163 }
1164 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_QDR_NET;
1165
1166 } else {
1167 /*
1168 * peg gdb frequently accesses memory that doesn't exist,
1169 * this limits the chit chat so debugging isn't slowed down.
1170 */
1171 if ((netxen_pci_set_window_warning_count++ < 8)
1172 || (netxen_pci_set_window_warning_count%64 == 0)) {
1173 printk("%s: Warning:%s Unknown address range!\n",
1174 __func__, netxen_nic_driver_name);
1175}
1176 addr = -1UL;
1177 }
1178 return addr;
1179}
1180
1181static int netxen_nic_pci_is_same_window(struct netxen_adapter *adapter,
1182 unsigned long long addr)
1183{
1184 int window;
1185 unsigned long long qdr_max;
1186
1187 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
1188 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P2;
1189 else
1190 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P3;
1191
1192 if (ADDR_IN_RANGE(addr,
1193 NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1194 /* DDR network side */
1195 BUG(); /* MN access can not come here */
1196 } else if (ADDR_IN_RANGE(addr,
1197 NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1198 return 1;
1199 } else if (ADDR_IN_RANGE(addr,
1200 NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1201 return 1;
1202 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_QDR_NET, qdr_max)) {
1203 /* QDR network side */
1204 window = ((addr - NETXEN_ADDR_QDR_NET) >> 22) & 0x3f;
1205 if (adapter->ahw.qdr_sn_window == window)
1206 return 1;
1207 }
1208
1209 return 0;
1210}
1211
1212static int netxen_nic_pci_mem_read_direct(struct netxen_adapter *adapter,
1213 u64 off, void *data, int size)
1214{
1215 unsigned long flags;
1216 void *addr;
1217 int ret = 0;
1218 u64 start;
1219 uint8_t *mem_ptr = NULL;
1220 unsigned long mem_base;
1221 unsigned long mem_page;
1222
1223 write_lock_irqsave(&adapter->adapter_lock, flags);
1224
1225 /*
1226 * If attempting to access unknown address or straddle hw windows,
1227 * do not access.
1228 */
1229 start = adapter->pci_set_window(adapter, off);
1230 if ((start == -1UL) ||
1231 (netxen_nic_pci_is_same_window(adapter, off+size-1) == 0)) {
1232 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1233 printk(KERN_ERR "%s out of bound pci memory access. "
1234 "offset is 0x%llx\n", netxen_nic_driver_name, off);
1235 return -1;
1236 }
1237
1238 addr = (void *)(pci_base_offset(adapter, start));
1239 if (!addr) {
1240 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1241 mem_base = pci_resource_start(adapter->pdev, 0);
1242 mem_page = start & PAGE_MASK;
1243 /* Map two pages whenever user tries to access addresses in two
1244 consecutive pages.
1245 */
1246 if (mem_page != ((start + size - 1) & PAGE_MASK))
1247 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1248 else
1249 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
1250 if (mem_ptr == 0UL) {
1251 *(uint8_t *)data = 0;
1252 return -1;
1253 }
1254 addr = mem_ptr;
1255 addr += start & (PAGE_SIZE - 1);
1256 write_lock_irqsave(&adapter->adapter_lock, flags);
1257 }
1258
1259 switch (size) {
1260 case 1:
1261 *(uint8_t *)data = readb(addr);
1262 break;
1263 case 2:
1264 *(uint16_t *)data = readw(addr);
1265 break;
1266 case 4:
1267 *(uint32_t *)data = readl(addr);
1268 break;
1269 case 8:
1270 *(uint64_t *)data = readq(addr);
1271 break;
1272 default:
1273 ret = -1;
1274 break;
1275 }
1276 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1277 DPRINTK(1, INFO, "read %llx\n", *(unsigned long long *)data);
1278
1279 if (mem_ptr)
1280 iounmap(mem_ptr);
1281 return ret;
1282}
1283
1284static int
1285netxen_nic_pci_mem_write_direct(struct netxen_adapter *adapter, u64 off,
1286 void *data, int size)
1287{
1288 unsigned long flags;
1289 void *addr;
1290 int ret = 0;
1291 u64 start;
1292 uint8_t *mem_ptr = NULL;
1293 unsigned long mem_base;
1294 unsigned long mem_page;
1295
1296 write_lock_irqsave(&adapter->adapter_lock, flags);
1297
1298 /*
1299 * If attempting to access unknown address or straddle hw windows,
1300 * do not access.
1301 */
1302 start = adapter->pci_set_window(adapter, off);
1303 if ((start == -1UL) ||
1304 (netxen_nic_pci_is_same_window(adapter, off+size-1) == 0)) {
1305 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1306 printk(KERN_ERR "%s out of bound pci memory access. "
1307 "offset is 0x%llx\n", netxen_nic_driver_name, off);
1308 return -1;
1309 }
1310
1311 addr = (void *)(pci_base_offset(adapter, start));
1312 if (!addr) {
1313 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1314 mem_base = pci_resource_start(adapter->pdev, 0);
1315 mem_page = start & PAGE_MASK;
1316 /* Map two pages whenever user tries to access addresses in two
1317 * consecutive pages.
1318 */
1319 if (mem_page != ((start + size - 1) & PAGE_MASK))
1320 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE*2);
1321 else
1322 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
1323 if (mem_ptr == 0UL)
1324 return -1;
1325 addr = mem_ptr;
1326 addr += start & (PAGE_SIZE - 1);
1327 write_lock_irqsave(&adapter->adapter_lock, flags);
1328 }
1329
1330 switch (size) {
1331 case 1:
1332 writeb(*(uint8_t *)data, addr);
1333 break;
1334 case 2:
1335 writew(*(uint16_t *)data, addr);
1336 break;
1337 case 4:
1338 writel(*(uint32_t *)data, addr);
1339 break;
1340 case 8:
1341 writeq(*(uint64_t *)data, addr);
1342 break;
1343 default:
1344 ret = -1;
1345 break;
1346 }
1347 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1348 DPRINTK(1, INFO, "writing data %llx to offset %llx\n",
1349 *(unsigned long long *)data, start);
1350 if (mem_ptr)
1351 iounmap(mem_ptr);
1352 return ret;
1353}
1354
1355#define MAX_CTL_CHECK 1000
1356
1357int
1358netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
1359 u64 off, void *data, int size)
1360{
1361 unsigned long flags, mem_crb;
1362 int i, j, ret = 0, loop, sz[2], off0;
1363 uint32_t temp;
1364 uint64_t off8, tmpw, word[2] = {0, 0};
1365
1366 /*
1367 * If not MN, go check for MS or invalid.
1368 */
1369 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1370 return netxen_nic_pci_mem_write_direct(adapter,
1371 off, data, size);
1372
1373 off8 = off & 0xfffffff8;
1374 off0 = off & 0x7;
1375 sz[0] = (size < (8 - off0)) ? size : (8 - off0);
1376 sz[1] = size - sz[0];
1377 loop = ((off0 + size - 1) >> 3) + 1;
1378 mem_crb = (unsigned long)pci_base_offset(adapter, NETXEN_CRB_DDR_NET);
1379
1380 if ((size != 8) || (off0 != 0)) {
1381 for (i = 0; i < loop; i++) {
1382 if (adapter->pci_mem_read(adapter,
1383 off8 + (i << 3), &word[i], 8))
1384 return -1;
1385 }
1386 }
1387
1388 switch (size) {
1389 case 1:
1390 tmpw = *((uint8_t *)data);
1391 break;
1392 case 2:
1393 tmpw = *((uint16_t *)data);
1394 break;
1395 case 4:
1396 tmpw = *((uint32_t *)data);
1397 break;
1398 case 8:
1399 default:
1400 tmpw = *((uint64_t *)data);
1401 break;
1402 }
1403 word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
1404 word[0] |= tmpw << (off0 * 8);
1405
1406 if (loop == 2) {
1407 word[1] &= ~(~0ULL << (sz[1] * 8));
1408 word[1] |= tmpw >> (sz[0] * 8);
1409 }
1410
1411 write_lock_irqsave(&adapter->adapter_lock, flags);
1412 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1413
1414 for (i = 0; i < loop; i++) {
1415 writel((uint32_t)(off8 + (i << 3)),
1416 (void *)(mem_crb+MIU_TEST_AGT_ADDR_LO));
1417 writel(0,
1418 (void *)(mem_crb+MIU_TEST_AGT_ADDR_HI));
1419 writel(word[i] & 0xffffffff,
1420 (void *)(mem_crb+MIU_TEST_AGT_WRDATA_LO));
1421 writel((word[i] >> 32) & 0xffffffff,
1422 (void *)(mem_crb+MIU_TEST_AGT_WRDATA_HI));
1423 writel(MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE,
1424 (void *)(mem_crb+MIU_TEST_AGT_CTRL));
1425 writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE,
1426 (void *)(mem_crb+MIU_TEST_AGT_CTRL));
1427
1428 for (j = 0; j < MAX_CTL_CHECK; j++) {
1429 temp = readl(
1430 (void *)(mem_crb+MIU_TEST_AGT_CTRL));
1431 if ((temp & MIU_TA_CTL_BUSY) == 0)
1432 break;
1433 }
1434
1435 if (j >= MAX_CTL_CHECK) {
1436 printk("%s: %s Fail to write through agent\n",
1437 __func__, netxen_nic_driver_name);
1438 ret = -1;
1439 break;
1440 }
1441 }
1442
1443 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1444 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1445 return ret;
1446}
1447
1448int
1449netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
1450 u64 off, void *data, int size)
1451{
1452 unsigned long flags, mem_crb;
1453 int i, j = 0, k, start, end, loop, sz[2], off0[2];
1454 uint32_t temp;
1455 uint64_t off8, val, word[2] = {0, 0};
1456
1457
1458 /*
1459 * If not MN, go check for MS or invalid.
1460 */
1461 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1462 return netxen_nic_pci_mem_read_direct(adapter, off, data, size);
1463
1464 off8 = off & 0xfffffff8;
1465 off0[0] = off & 0x7;
1466 off0[1] = 0;
1467 sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]);
1468 sz[1] = size - sz[0];
1469 loop = ((off0[0] + size - 1) >> 3) + 1;
1470 mem_crb = (unsigned long)pci_base_offset(adapter, NETXEN_CRB_DDR_NET);
1471
1472 write_lock_irqsave(&adapter->adapter_lock, flags);
1473 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1474
1475 for (i = 0; i < loop; i++) {
1476 writel((uint32_t)(off8 + (i << 3)),
1477 (void *)(mem_crb+MIU_TEST_AGT_ADDR_LO));
1478 writel(0,
1479 (void *)(mem_crb+MIU_TEST_AGT_ADDR_HI));
1480 writel(MIU_TA_CTL_ENABLE,
1481 (void *)(mem_crb+MIU_TEST_AGT_CTRL));
1482 writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE,
1483 (void *)(mem_crb+MIU_TEST_AGT_CTRL));
1484
1485 for (j = 0; j < MAX_CTL_CHECK; j++) {
1486 temp = readl(
1487 (void *)(mem_crb+MIU_TEST_AGT_CTRL));
1488 if ((temp & MIU_TA_CTL_BUSY) == 0)
1489 break;
1490 }
1491
1492 if (j >= MAX_CTL_CHECK) {
1493 printk(KERN_ERR "%s: %s Fail to read through agent\n",
1494 __func__, netxen_nic_driver_name);
1495 break;
1496 }
1497
1498 start = off0[i] >> 2;
1499 end = (off0[i] + sz[i] - 1) >> 2;
1500 for (k = start; k <= end; k++) {
1501 word[i] |= ((uint64_t) readl(
1502 (void *)(mem_crb +
1503 MIU_TEST_AGT_RDDATA(k))) << (32*k));
1504 }
1505 }
1506
1507 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1508 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1509
1510 if (j >= MAX_CTL_CHECK)
1511 return -1;
1512
1513 if (sz[0] == 8) {
1514 val = word[0];
1515 } else {
1516 val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
1517 ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
1518 }
1519
1520 switch (size) {
1521 case 1:
1522 *(uint8_t *)data = val;
1523 break;
1524 case 2:
1525 *(uint16_t *)data = val;
1526 break;
1527 case 4:
1528 *(uint32_t *)data = val;
1529 break;
1530 case 8:
1531 *(uint64_t *)data = val;
1532 break;
1533 }
1534 DPRINTK(1, INFO, "read %llx\n", *(unsigned long long *)data);
1535 return 0;
1536}
1537
1538int
1539netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
1540 u64 off, void *data, int size)
1541{
1542 int i, j, ret = 0, loop, sz[2], off0;
1543 uint32_t temp;
1544 uint64_t off8, mem_crb, tmpw, word[2] = {0, 0};
1545
1546 /*
1547 * If not MN, go check for MS or invalid.
1548 */
1549 if (off >= NETXEN_ADDR_QDR_NET && off <= NETXEN_ADDR_QDR_NET_MAX_P3)
1550 mem_crb = NETXEN_CRB_QDR_NET;
1551 else {
1552 mem_crb = NETXEN_CRB_DDR_NET;
1553 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1554 return netxen_nic_pci_mem_write_direct(adapter,
1555 off, data, size);
1556 }
1557
1558 off8 = off & 0xfffffff8;
1559 off0 = off & 0x7;
1560 sz[0] = (size < (8 - off0)) ? size : (8 - off0);
1561 sz[1] = size - sz[0];
1562 loop = ((off0 + size - 1) >> 3) + 1;
1563
1564 if ((size != 8) || (off0 != 0)) {
1565 for (i = 0; i < loop; i++) {
1566 if (adapter->pci_mem_read(adapter, off8 + (i << 3),
1567 &word[i], 8))
1568 return -1;
1569 }
1570 }
1571
1572 switch (size) {
1573 case 1:
1574 tmpw = *((uint8_t *)data);
1575 break;
1576 case 2:
1577 tmpw = *((uint16_t *)data);
1578 break;
1579 case 4:
1580 tmpw = *((uint32_t *)data);
1581 break;
1582 case 8:
1583 default:
1584 tmpw = *((uint64_t *)data);
1585 break;
1586 }
1587
1588 word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
1589 word[0] |= tmpw << (off0 * 8);
1590
1591 if (loop == 2) {
1592 word[1] &= ~(~0ULL << (sz[1] * 8));
1593 word[1] |= tmpw >> (sz[0] * 8);
1594 }
1595
1596 /*
1597 * don't lock here - write_wx gets the lock if each time
1598 * write_lock_irqsave(&adapter->adapter_lock, flags);
1599 * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1600 */
1601
1602 for (i = 0; i < loop; i++) {
1603 temp = off8 + (i << 3);
1604 adapter->hw_write_wx(adapter,
1605 mem_crb+MIU_TEST_AGT_ADDR_LO, &temp, 4);
1606 temp = 0;
1607 adapter->hw_write_wx(adapter,
1608 mem_crb+MIU_TEST_AGT_ADDR_HI, &temp, 4);
1609 temp = word[i] & 0xffffffff;
1610 adapter->hw_write_wx(adapter,
1611 mem_crb+MIU_TEST_AGT_WRDATA_LO, &temp, 4);
1612 temp = (word[i] >> 32) & 0xffffffff;
1613 adapter->hw_write_wx(adapter,
1614 mem_crb+MIU_TEST_AGT_WRDATA_HI, &temp, 4);
1615 temp = MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE;
1616 adapter->hw_write_wx(adapter,
1617 mem_crb+MIU_TEST_AGT_CTRL, &temp, 4);
1618 temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE;
1619 adapter->hw_write_wx(adapter,
1620 mem_crb+MIU_TEST_AGT_CTRL, &temp, 4);
1621
1622 for (j = 0; j < MAX_CTL_CHECK; j++) {
1623 adapter->hw_read_wx(adapter,
1624 mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
1625 if ((temp & MIU_TA_CTL_BUSY) == 0)
1626 break;
1627 }
1628
1629 if (j >= MAX_CTL_CHECK) {
1630 printk(KERN_ERR "%s: Fail to write through agent\n",
1631 netxen_nic_driver_name);
1632 ret = -1;
1633 break;
1634 }
1635 }
1636
1637 /*
1638 * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1639 * write_unlock_irqrestore(&adapter->adapter_lock, flags);
1640 */
1641 return ret;
1642}
1643
1644int
1645netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
1646 u64 off, void *data, int size)
1647{
1648 int i, j = 0, k, start, end, loop, sz[2], off0[2];
1649 uint32_t temp;
1650 uint64_t off8, val, mem_crb, word[2] = {0, 0};
1651
1652 /*
1653 * If not MN, go check for MS or invalid.
1654 */
1655
1656 if (off >= NETXEN_ADDR_QDR_NET && off <= NETXEN_ADDR_QDR_NET_MAX_P3)
1657 mem_crb = NETXEN_CRB_QDR_NET;
1658 else {
1659 mem_crb = NETXEN_CRB_DDR_NET;
1660 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1661 return netxen_nic_pci_mem_read_direct(adapter,
1662 off, data, size);
1663 }
1664
1665 off8 = off & 0xfffffff8;
1666 off0[0] = off & 0x7;
1667 off0[1] = 0;
1668 sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]);
1669 sz[1] = size - sz[0];
1670 loop = ((off0[0] + size - 1) >> 3) + 1;
1671
1672 /*
1673 * don't lock here - write_wx gets the lock if each time
1674 * write_lock_irqsave(&adapter->adapter_lock, flags);
1675 * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1676 */
1677
1678 for (i = 0; i < loop; i++) {
1679 temp = off8 + (i << 3);
1680 adapter->hw_write_wx(adapter,
1681 mem_crb + MIU_TEST_AGT_ADDR_LO, &temp, 4);
1682 temp = 0;
1683 adapter->hw_write_wx(adapter,
1684 mem_crb + MIU_TEST_AGT_ADDR_HI, &temp, 4);
1685 temp = MIU_TA_CTL_ENABLE;
1686 adapter->hw_write_wx(adapter,
1687 mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
1688 temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE;
1689 adapter->hw_write_wx(adapter,
1690 mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
1691
1692 for (j = 0; j < MAX_CTL_CHECK; j++) {
1693 adapter->hw_read_wx(adapter,
1694 mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
1695 if ((temp & MIU_TA_CTL_BUSY) == 0)
1696 break;
1697 }
1698
1699 if (j >= MAX_CTL_CHECK) {
1700 printk(KERN_ERR "%s: Fail to read through agent\n",
1701 netxen_nic_driver_name);
1702 break;
1703 }
1704
1705 start = off0[i] >> 2;
1706 end = (off0[i] + sz[i] - 1) >> 2;
1707 for (k = start; k <= end; k++) {
1708 adapter->hw_read_wx(adapter,
1709 mem_crb + MIU_TEST_AGT_RDDATA(k), &temp, 4);
1710 word[i] |= ((uint64_t)temp << (32 * k));
1711 }
1712 }
1713
1714 /*
1715 * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1716 * write_unlock_irqrestore(&adapter->adapter_lock, flags);
1717 */
1718
1719 if (j >= MAX_CTL_CHECK)
1720 return -1;
1721
1722 if (sz[0] == 8) {
1723 val = word[0];
1724 } else {
1725 val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
1726 ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
1727 }
1728
1729 switch (size) {
1730 case 1:
1731 *(uint8_t *)data = val;
1732 break;
1733 case 2:
1734 *(uint16_t *)data = val;
1735 break;
1736 case 4:
1737 *(uint32_t *)data = val;
1738 break;
1739 case 8:
1740 *(uint64_t *)data = val;
1741 break;
1742 }
1743 DPRINTK(1, INFO, "read %llx\n", *(unsigned long long *)data);
1744 return 0;
1745}
1746
1747/*
1748 * Note : only 32-bit writes!
1749 */
1750int netxen_nic_pci_write_immediate_2M(struct netxen_adapter *adapter,
1751 u64 off, u32 data)
1752{
1753 adapter->hw_write_wx(adapter, off, &data, 4);
1754
1755 return 0;
1756}
1757
1758u32 netxen_nic_pci_read_immediate_2M(struct netxen_adapter *adapter, u64 off)
1759{
1760 u32 temp;
1761 adapter->hw_read_wx(adapter, off, &temp, 4);
1762 return temp;
1763}
1764
1765void netxen_nic_pci_write_normalize_2M(struct netxen_adapter *adapter,
1766 u64 off, u32 data)
1767{
1768 adapter->hw_write_wx(adapter, off, &data, 4);
1769}
1770
1771u32 netxen_nic_pci_read_normalize_2M(struct netxen_adapter *adapter, u64 off)
1772{
1773 u32 temp;
1774 adapter->hw_read_wx(adapter, off, &temp, 4);
1775 return temp;
1776}
1777
Adrian Bunk993fb902007-11-05 18:07:31 +01001778#if 0
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001779int
1780netxen_nic_erase_pxe(struct netxen_adapter *adapter)
1781{
Mithlesh Thukral0d047612007-06-07 04:36:36 -07001782 if (netxen_rom_fast_write(adapter, NETXEN_PXE_START, 0) == -1) {
Jeff Garzik47906542007-11-23 21:23:36 -05001783 printk(KERN_ERR "%s: erase pxe failed\n",
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001784 netxen_nic_driver_name);
1785 return -1;
1786 }
1787 return 0;
1788}
Adrian Bunk993fb902007-11-05 18:07:31 +01001789#endif /* 0 */
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001790
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001791int netxen_nic_get_board_info(struct netxen_adapter *adapter)
1792{
1793 int rv = 0;
Mithlesh Thukral0d047612007-06-07 04:36:36 -07001794 int addr = NETXEN_BRDCFG_START;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001795 struct netxen_board_info *boardinfo;
1796 int index;
1797 u32 *ptr32;
1798
1799 boardinfo = &adapter->ahw.boardcfg;
1800 ptr32 = (u32 *) boardinfo;
1801
1802 for (index = 0; index < sizeof(struct netxen_board_info) / sizeof(u32);
1803 index++) {
1804 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
1805 return -EIO;
1806 }
1807 ptr32++;
1808 addr += sizeof(u32);
1809 }
1810 if (boardinfo->magic != NETXEN_BDINFO_MAGIC) {
1811 printk("%s: ERROR reading %s board config."
1812 " Read %x, expected %x\n", netxen_nic_driver_name,
1813 netxen_nic_driver_name,
1814 boardinfo->magic, NETXEN_BDINFO_MAGIC);
1815 rv = -1;
1816 }
1817 if (boardinfo->header_version != NETXEN_BDINFO_VERSION) {
1818 printk("%s: Unknown board config version."
1819 " Read %x, expected %x\n", netxen_nic_driver_name,
1820 boardinfo->header_version, NETXEN_BDINFO_VERSION);
1821 rv = -1;
1822 }
1823
1824 DPRINTK(INFO, "Discovered board type:0x%x ", boardinfo->board_type);
1825 switch ((netxen_brdtype_t) boardinfo->board_type) {
1826 case NETXEN_BRDTYPE_P2_SB35_4G:
1827 adapter->ahw.board_type = NETXEN_NIC_GBE;
1828 break;
1829 case NETXEN_BRDTYPE_P2_SB31_10G:
1830 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1831 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1832 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001833 case NETXEN_BRDTYPE_P3_HMEZ:
1834 case NETXEN_BRDTYPE_P3_XG_LOM:
1835 case NETXEN_BRDTYPE_P3_10G_CX4:
1836 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
1837 case NETXEN_BRDTYPE_P3_IMEZ:
1838 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
1839 case NETXEN_BRDTYPE_P3_10G_XFP:
1840 case NETXEN_BRDTYPE_P3_10000_BASE_T:
1841
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001842 adapter->ahw.board_type = NETXEN_NIC_XGBE;
1843 break;
1844 case NETXEN_BRDTYPE_P1_BD:
1845 case NETXEN_BRDTYPE_P1_SB:
1846 case NETXEN_BRDTYPE_P1_SMAX:
1847 case NETXEN_BRDTYPE_P1_SOCK:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001848 case NETXEN_BRDTYPE_P3_REF_QG:
1849 case NETXEN_BRDTYPE_P3_4_GB:
1850 case NETXEN_BRDTYPE_P3_4_GB_MM:
1851
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001852 adapter->ahw.board_type = NETXEN_NIC_GBE;
1853 break;
1854 default:
1855 printk("%s: Unknown(%x)\n", netxen_nic_driver_name,
1856 boardinfo->board_type);
1857 break;
1858 }
1859
1860 return rv;
1861}
1862
1863/* NIU access sections */
1864
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001865int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001866{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001867 netxen_nic_write_w0(adapter,
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07001868 NETXEN_NIU_GB_MAX_FRAME_SIZE(adapter->physical_port),
1869 new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001870 return 0;
1871}
1872
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001873int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001874{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001875 new_mtu += NETXEN_NIU_HDRSIZE + NETXEN_NIU_TLRSIZE;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07001876 if (adapter->physical_port == 0)
Jeff Garzik47906542007-11-23 21:23:36 -05001877 netxen_nic_write_w0(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE,
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001878 new_mtu);
Jeff Garzik47906542007-11-23 21:23:36 -05001879 else
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001880 netxen_nic_write_w0(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE,
1881 new_mtu);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001882 return 0;
1883}
1884
1885void netxen_nic_init_niu_gb(struct netxen_adapter *adapter)
1886{
Dhananjay Phadke3276fba2008-06-15 22:59:44 -07001887 netxen_niu_gbe_init_port(adapter, adapter->physical_port);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001888}
1889
1890void
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001891netxen_crb_writelit_adapter(struct netxen_adapter *adapter,
1892 unsigned long off, int data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001893{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001894 adapter->hw_write_wx(adapter, off, &data, 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001895}
1896
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001897void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001898{
Al Viroa608ab92007-01-02 10:39:10 +00001899 __u32 status;
1900 __u32 autoneg;
1901 __u32 mode;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001902
1903 netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode);
1904 if (netxen_get_niu_enable_ge(mode)) { /* Gb 10/100/1000 Mbps mode */
Amit S. Kale80922fb2006-12-04 09:18:00 -08001905 if (adapter->phy_read
1906 && adapter->
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001907 phy_read(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001908 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
1909 &status) == 0) {
1910 if (netxen_get_phy_link(status)) {
1911 switch (netxen_get_phy_speed(status)) {
1912 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001913 adapter->link_speed = SPEED_10;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001914 break;
1915 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001916 adapter->link_speed = SPEED_100;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001917 break;
1918 case 2:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001919 adapter->link_speed = SPEED_1000;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001920 break;
1921 default:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001922 adapter->link_speed = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001923 break;
1924 }
1925 switch (netxen_get_phy_duplex(status)) {
1926 case 0:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001927 adapter->link_duplex = DUPLEX_HALF;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001928 break;
1929 case 1:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001930 adapter->link_duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001931 break;
1932 default:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001933 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001934 break;
1935 }
Amit S. Kale80922fb2006-12-04 09:18:00 -08001936 if (adapter->phy_read
1937 && adapter->
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001938 phy_read(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001939 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001940 &autoneg) != 0)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001941 adapter->link_autoneg = autoneg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001942 } else
1943 goto link_down;
1944 } else {
1945 link_down:
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001946 adapter->link_speed = -1;
1947 adapter->link_duplex = -1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001948 }
1949 }
1950}
1951
1952void netxen_nic_flash_print(struct netxen_adapter *adapter)
1953{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001954 u32 fw_major = 0;
1955 u32 fw_minor = 0;
1956 u32 fw_build = 0;
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001957 char brd_name[NETXEN_MAX_SHORT_NAME];
Harvey Harrison8d748492008-04-22 11:48:35 -07001958 char serial_num[32];
1959 int i, addr;
Mithlesh Thukral6d1495f2007-04-20 07:56:42 -07001960 __le32 *ptr32;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001961
1962 struct netxen_board_info *board_info = &(adapter->ahw.boardcfg);
Harvey Harrison8d748492008-04-22 11:48:35 -07001963
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001964 adapter->driver_mismatch = 0;
1965
1966 ptr32 = (u32 *)&serial_num;
1967 addr = NETXEN_USER_START +
1968 offsetof(struct netxen_new_user_info, serial_num);
1969 for (i = 0; i < 8; i++) {
1970 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
1971 printk("%s: ERROR reading %s board userarea.\n",
1972 netxen_nic_driver_name,
1973 netxen_nic_driver_name);
1974 adapter->driver_mismatch = 1;
1975 return;
1976 }
1977 ptr32++;
1978 addr += sizeof(u32);
1979 }
1980
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001981 adapter->hw_read_wx(adapter, NETXEN_FW_VERSION_MAJOR, &fw_major, 4);
1982 adapter->hw_read_wx(adapter, NETXEN_FW_VERSION_MINOR, &fw_minor, 4);
1983 adapter->hw_read_wx(adapter, NETXEN_FW_VERSION_SUB, &fw_build, 4);
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001984
Dhananjay Phadke29566402008-07-21 19:44:04 -07001985 adapter->fw_major = fw_major;
1986
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001987 if (adapter->portnum == 0) {
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001988 get_brd_name_by_type(board_info->board_type, brd_name);
1989
1990 printk("NetXen %s Board S/N %s Chip id 0x%x\n",
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001991 brd_name, serial_num, board_info->chip_id);
1992 printk("NetXen Firmware version %d.%d.%d\n", fw_major,
1993 fw_minor, fw_build);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001994 }
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001995
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001996 if (fw_major != _NETXEN_NIC_LINUX_MAJOR) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001997 adapter->driver_mismatch = 1;
1998 }
Amit S. Kale90f8b1d2007-01-22 06:38:05 -08001999 if (fw_minor != _NETXEN_NIC_LINUX_MINOR &&
2000 fw_minor != (_NETXEN_NIC_LINUX_MINOR + 1)) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002001 adapter->driver_mismatch = 1;
2002 }
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07002003 if (adapter->driver_mismatch) {
2004 printk(KERN_ERR "%s: driver and firmware version mismatch\n",
2005 adapter->netdev->name);
2006 return;
2007 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002008}
2009