2 * Copyright (C) 2003 - 2009 NetXen, Inc.
5 * 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.
10 * 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.
15 * 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,
20 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
23 * Contact Information:
27 * Cupertino, CA 95014-0701
31 #include "netxen_nic.h"
32 #include "netxen_nic_hw.h"
33 #include "netxen_nic_phan_reg.h"
35 #include <linux/firmware.h>
38 #define MASK(n) ((1ULL<<(n))-1)
39 #define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff))
40 #define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff))
41 #define MS_WIN(addr) (addr & 0x0ffc0000)
43 #define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
45 #define CRB_BLK(off) ((off >> 20) & 0x3f)
46 #define CRB_SUBBLK(off) ((off >> 16) & 0xf)
47 #define CRB_WINDOW_2M (0x130060)
48 #define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000))
49 #define CRB_INDIRECT_2M (0x1e0000UL)
51 #define CRB_WIN_LOCK_TIMEOUT 100000000
52 static crb_128M_2M_block_map_t crb_128M_2M_map[64] = {
53 {{{0, 0, 0, 0} } }, /* 0: PCI */
54 {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */
55 {1, 0x0110000, 0x0120000, 0x130000},
56 {1, 0x0120000, 0x0122000, 0x124000},
57 {1, 0x0130000, 0x0132000, 0x126000},
58 {1, 0x0140000, 0x0142000, 0x128000},
59 {1, 0x0150000, 0x0152000, 0x12a000},
60 {1, 0x0160000, 0x0170000, 0x110000},
61 {1, 0x0170000, 0x0172000, 0x12e000},
62 {0, 0x0000000, 0x0000000, 0x000000},
63 {0, 0x0000000, 0x0000000, 0x000000},
64 {0, 0x0000000, 0x0000000, 0x000000},
65 {0, 0x0000000, 0x0000000, 0x000000},
66 {0, 0x0000000, 0x0000000, 0x000000},
67 {0, 0x0000000, 0x0000000, 0x000000},
68 {1, 0x01e0000, 0x01e0800, 0x122000},
69 {0, 0x0000000, 0x0000000, 0x000000} } },
70 {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */
71 {{{0, 0, 0, 0} } }, /* 3: */
72 {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */
73 {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */
74 {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */
75 {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */
76 {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */
77 {0, 0x0000000, 0x0000000, 0x000000},
78 {0, 0x0000000, 0x0000000, 0x000000},
79 {0, 0x0000000, 0x0000000, 0x000000},
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 {1, 0x08f0000, 0x08f2000, 0x172000} } },
92 {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/
93 {0, 0x0000000, 0x0000000, 0x000000},
94 {0, 0x0000000, 0x0000000, 0x000000},
95 {0, 0x0000000, 0x0000000, 0x000000},
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 {1, 0x09f0000, 0x09f2000, 0x176000} } },
108 {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/
109 {0, 0x0000000, 0x0000000, 0x000000},
110 {0, 0x0000000, 0x0000000, 0x000000},
111 {0, 0x0000000, 0x0000000, 0x000000},
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 {1, 0x0af0000, 0x0af2000, 0x17a000} } },
124 {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/
125 {0, 0x0000000, 0x0000000, 0x000000},
126 {0, 0x0000000, 0x0000000, 0x000000},
127 {0, 0x0000000, 0x0000000, 0x000000},
128 {0, 0x0000000, 0x0000000, 0x000000},
129 {0, 0x0000000, 0x0000000, 0x000000},
130 {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 {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
140 {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */
141 {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */
142 {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */
143 {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */
144 {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */
145 {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */
146 {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */
147 {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */
148 {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */
149 {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */
150 {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */
151 {{{0, 0, 0, 0} } }, /* 23: */
152 {{{0, 0, 0, 0} } }, /* 24: */
153 {{{0, 0, 0, 0} } }, /* 25: */
154 {{{0, 0, 0, 0} } }, /* 26: */
155 {{{0, 0, 0, 0} } }, /* 27: */
156 {{{0, 0, 0, 0} } }, /* 28: */
157 {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */
158 {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */
159 {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */
160 {{{0} } }, /* 32: PCI */
161 {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */
162 {1, 0x2110000, 0x2120000, 0x130000},
163 {1, 0x2120000, 0x2122000, 0x124000},
164 {1, 0x2130000, 0x2132000, 0x126000},
165 {1, 0x2140000, 0x2142000, 0x128000},
166 {1, 0x2150000, 0x2152000, 0x12a000},
167 {1, 0x2160000, 0x2170000, 0x110000},
168 {1, 0x2170000, 0x2172000, 0x12e000},
169 {0, 0x0000000, 0x0000000, 0x000000},
170 {0, 0x0000000, 0x0000000, 0x000000},
171 {0, 0x0000000, 0x0000000, 0x000000},
172 {0, 0x0000000, 0x0000000, 0x000000},
173 {0, 0x0000000, 0x0000000, 0x000000},
174 {0, 0x0000000, 0x0000000, 0x000000},
175 {0, 0x0000000, 0x0000000, 0x000000},
176 {0, 0x0000000, 0x0000000, 0x000000} } },
177 {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */
183 {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */
184 {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */
185 {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */
186 {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */
187 {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */
188 {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */
189 {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */
190 {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */
191 {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */
192 {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */
193 {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */
194 {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */
196 {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */
197 {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */
198 {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */
199 {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */
200 {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */
201 {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */
202 {{{0} } }, /* 59: I2C0 */
203 {{{0} } }, /* 60: I2C1 */
204 {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */
205 {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */
206 {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */
210 * top 12 bits of crb internal address (hub, agent)
212 static unsigned crb_hub_agt[64] =
215 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
216 NETXEN_HW_CRB_HUB_AGT_ADR_MN,
217 NETXEN_HW_CRB_HUB_AGT_ADR_MS,
219 NETXEN_HW_CRB_HUB_AGT_ADR_SRE,
220 NETXEN_HW_CRB_HUB_AGT_ADR_NIU,
221 NETXEN_HW_CRB_HUB_AGT_ADR_QMN,
222 NETXEN_HW_CRB_HUB_AGT_ADR_SQN0,
223 NETXEN_HW_CRB_HUB_AGT_ADR_SQN1,
224 NETXEN_HW_CRB_HUB_AGT_ADR_SQN2,
225 NETXEN_HW_CRB_HUB_AGT_ADR_SQN3,
226 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
227 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
228 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
229 NETXEN_HW_CRB_HUB_AGT_ADR_PGN4,
230 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
231 NETXEN_HW_CRB_HUB_AGT_ADR_PGN0,
232 NETXEN_HW_CRB_HUB_AGT_ADR_PGN1,
233 NETXEN_HW_CRB_HUB_AGT_ADR_PGN2,
234 NETXEN_HW_CRB_HUB_AGT_ADR_PGN3,
235 NETXEN_HW_CRB_HUB_AGT_ADR_PGND,
236 NETXEN_HW_CRB_HUB_AGT_ADR_PGNI,
237 NETXEN_HW_CRB_HUB_AGT_ADR_PGS0,
238 NETXEN_HW_CRB_HUB_AGT_ADR_PGS1,
239 NETXEN_HW_CRB_HUB_AGT_ADR_PGS2,
240 NETXEN_HW_CRB_HUB_AGT_ADR_PGS3,
242 NETXEN_HW_CRB_HUB_AGT_ADR_PGSI,
243 NETXEN_HW_CRB_HUB_AGT_ADR_SN,
245 NETXEN_HW_CRB_HUB_AGT_ADR_EG,
247 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
248 NETXEN_HW_CRB_HUB_AGT_ADR_CAM,
254 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
256 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1,
257 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2,
258 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3,
259 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4,
260 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5,
261 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6,
262 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7,
263 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
264 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
265 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
267 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0,
268 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8,
269 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9,
270 NETXEN_HW_CRB_HUB_AGT_ADR_OCM0,
272 NETXEN_HW_CRB_HUB_AGT_ADR_SMB,
273 NETXEN_HW_CRB_HUB_AGT_ADR_I2C0,
274 NETXEN_HW_CRB_HUB_AGT_ADR_I2C1,
276 NETXEN_HW_CRB_HUB_AGT_ADR_PGNC,
280 /* PCI Windowing for DDR regions. */
282 #define ADDR_IN_RANGE(addr, low, high) \
283 (((addr) <= (high)) && ((addr) >= (low)))
285 #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
287 #define NETXEN_NIC_ZERO_PAUSE_ADDR 0ULL
288 #define NETXEN_NIC_UNIT_PAUSE_ADDR 0x200ULL
289 #define NETXEN_NIC_EPG_PAUSE_ADDR1 0x2200010000c28001ULL
290 #define NETXEN_NIC_EPG_PAUSE_ADDR2 0x0100088866554433ULL
292 #define NETXEN_NIC_WINDOW_MARGIN 0x100000
294 int netxen_nic_set_mac(struct net_device *netdev, void *p)
296 struct netxen_adapter *adapter = netdev_priv(netdev);
297 struct sockaddr *addr = p;
299 if (netif_running(netdev))
302 if (!is_valid_ether_addr(addr->sa_data))
303 return -EADDRNOTAVAIL;
305 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
307 /* For P3, MAC addr is not set in NIU */
308 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
309 if (adapter->macaddr_set)
310 adapter->macaddr_set(adapter, addr->sa_data);
315 #define NETXEN_UNICAST_ADDR(port, index) \
316 (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8))
317 #define NETXEN_MCAST_ADDR(port, index) \
318 (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8))
319 #define MAC_HI(addr) \
320 ((addr[2] << 16) | (addr[1] << 8) | (addr[0]))
321 #define MAC_LO(addr) \
322 ((addr[5] << 16) | (addr[4] << 8) | (addr[3]))
325 netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter)
328 u16 port = adapter->physical_port;
329 u8 *addr = adapter->netdev->dev_addr;
331 if (adapter->mc_enabled)
334 adapter->hw_read_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
335 val |= (1UL << (28+port));
336 adapter->hw_write_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
338 /* add broadcast addr to filter */
340 netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
341 netxen_crb_writelit_adapter(adapter,
342 NETXEN_UNICAST_ADDR(port, 0)+4, val);
344 /* add station addr to filter */
346 netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 1), val);
348 netxen_crb_writelit_adapter(adapter,
349 NETXEN_UNICAST_ADDR(port, 1)+4, val);
351 adapter->mc_enabled = 1;
356 netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter)
359 u16 port = adapter->physical_port;
360 u8 *addr = adapter->netdev->dev_addr;
362 if (!adapter->mc_enabled)
365 adapter->hw_read_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
366 val &= ~(1UL << (28+port));
367 adapter->hw_write_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
370 netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
372 netxen_crb_writelit_adapter(adapter,
373 NETXEN_UNICAST_ADDR(port, 0)+4, val);
375 netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 1), 0);
376 netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0);
378 adapter->mc_enabled = 0;
383 netxen_nic_set_mcast_addr(struct netxen_adapter *adapter,
387 u16 port = adapter->physical_port;
392 netxen_crb_writelit_adapter(adapter,
393 NETXEN_MCAST_ADDR(port, index), hi);
394 netxen_crb_writelit_adapter(adapter,
395 NETXEN_MCAST_ADDR(port, index)+4, lo);
400 void netxen_p2_nic_set_multi(struct net_device *netdev)
402 struct netxen_adapter *adapter = netdev_priv(netdev);
403 struct dev_mc_list *mc_ptr;
407 memset(null_addr, 0, 6);
409 if (netdev->flags & IFF_PROMISC) {
411 adapter->set_promisc(adapter,
412 NETXEN_NIU_PROMISC_MODE);
414 /* Full promiscuous mode */
415 netxen_nic_disable_mcast_filter(adapter);
420 if (netdev->mc_count == 0) {
421 adapter->set_promisc(adapter,
422 NETXEN_NIU_NON_PROMISC_MODE);
423 netxen_nic_disable_mcast_filter(adapter);
427 adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE);
428 if (netdev->flags & IFF_ALLMULTI ||
429 netdev->mc_count > adapter->max_mc_count) {
430 netxen_nic_disable_mcast_filter(adapter);
434 netxen_nic_enable_mcast_filter(adapter);
436 for (mc_ptr = netdev->mc_list; mc_ptr; mc_ptr = mc_ptr->next, index++)
437 netxen_nic_set_mcast_addr(adapter, index, mc_ptr->dmi_addr);
439 if (index != netdev->mc_count)
440 printk(KERN_WARNING "%s: %s multicast address count mismatch\n",
441 netxen_nic_driver_name, netdev->name);
443 /* Clear out remaining addresses */
444 for (; index < adapter->max_mc_count; index++)
445 netxen_nic_set_mcast_addr(adapter, index, null_addr);
448 static int nx_p3_nic_add_mac(struct netxen_adapter *adapter,
449 u8 *addr, nx_mac_list_t **add_list, nx_mac_list_t **del_list)
451 nx_mac_list_t *cur, *prev;
453 /* if in del_list, move it to adapter->mac_list */
454 for (cur = *del_list, prev = NULL; cur;) {
455 if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) {
457 *del_list = cur->next;
459 prev->next = cur->next;
460 cur->next = adapter->mac_list;
461 adapter->mac_list = cur;
468 /* make sure to add each mac address only once */
469 for (cur = adapter->mac_list; cur; cur = cur->next) {
470 if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0)
473 /* not in del_list, create new entry and add to add_list */
474 cur = kmalloc(sizeof(*cur), in_atomic()? GFP_ATOMIC : GFP_KERNEL);
476 printk(KERN_ERR "%s: cannot allocate memory. MAC filtering may"
477 "not work properly from now.\n", __func__);
481 memcpy(cur->mac_addr, addr, ETH_ALEN);
482 cur->next = *add_list;
488 netxen_send_cmd_descs(struct netxen_adapter *adapter,
489 struct cmd_desc_type0 *cmd_desc_arr, int nr_elements)
491 uint32_t i, producer;
492 struct netxen_cmd_buffer *pbuf;
493 struct cmd_desc_type0 *cmd_desc;
495 if (nr_elements > MAX_PENDING_DESC_BLOCK_SIZE || nr_elements == 0) {
496 printk(KERN_WARNING "%s: Too many command descriptors in a "
497 "request\n", __func__);
503 netif_tx_lock_bh(adapter->netdev);
505 producer = adapter->cmd_producer;
507 cmd_desc = &cmd_desc_arr[i];
509 pbuf = &adapter->cmd_buf_arr[producer];
511 pbuf->frag_count = 0;
513 /* adapter->ahw.cmd_desc_head[producer] = *cmd_desc; */
514 memcpy(&adapter->ahw.cmd_desc_head[producer],
515 &cmd_desc_arr[i], sizeof(struct cmd_desc_type0));
517 producer = get_next_index(producer,
518 adapter->max_tx_desc_count);
521 } while (i != nr_elements);
523 adapter->cmd_producer = producer;
525 /* write producer index to start the xmit */
527 netxen_nic_update_cmd_producer(adapter, adapter->cmd_producer);
529 netif_tx_unlock_bh(adapter->netdev);
534 static int nx_p3_sre_macaddr_change(struct net_device *dev,
535 u8 *addr, unsigned op)
537 struct netxen_adapter *adapter = netdev_priv(dev);
539 nx_mac_req_t *mac_req;
543 memset(&req, 0, sizeof(nx_nic_req_t));
544 req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23);
546 word = NX_MAC_EVENT | ((u64)adapter->portnum << 16);
547 req.req_hdr = cpu_to_le64(word);
549 mac_req = (nx_mac_req_t *)&req.words[0];
551 memcpy(mac_req->mac_addr, addr, 6);
553 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
555 printk(KERN_ERR "ERROR. Could not send mac update\n");
562 void netxen_p3_nic_set_multi(struct net_device *netdev)
564 struct netxen_adapter *adapter = netdev_priv(netdev);
565 nx_mac_list_t *cur, *next, *del_list, *add_list = NULL;
566 struct dev_mc_list *mc_ptr;
567 u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
568 u32 mode = VPORT_MISS_MODE_DROP;
570 del_list = adapter->mac_list;
571 adapter->mac_list = NULL;
573 nx_p3_nic_add_mac(adapter, netdev->dev_addr, &add_list, &del_list);
574 nx_p3_nic_add_mac(adapter, bcast_addr, &add_list, &del_list);
576 if (netdev->flags & IFF_PROMISC) {
577 mode = VPORT_MISS_MODE_ACCEPT_ALL;
581 if ((netdev->flags & IFF_ALLMULTI) ||
582 (netdev->mc_count > adapter->max_mc_count)) {
583 mode = VPORT_MISS_MODE_ACCEPT_MULTI;
587 if (netdev->mc_count > 0) {
588 for (mc_ptr = netdev->mc_list; mc_ptr;
589 mc_ptr = mc_ptr->next) {
590 nx_p3_nic_add_mac(adapter, mc_ptr->dmi_addr,
591 &add_list, &del_list);
596 adapter->set_promisc(adapter, mode);
597 for (cur = del_list; cur;) {
598 nx_p3_sre_macaddr_change(netdev, cur->mac_addr, NETXEN_MAC_DEL);
603 for (cur = add_list; cur;) {
604 nx_p3_sre_macaddr_change(netdev, cur->mac_addr, NETXEN_MAC_ADD);
606 cur->next = adapter->mac_list;
607 adapter->mac_list = cur;
612 int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
617 memset(&req, 0, sizeof(nx_nic_req_t));
619 req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
621 word = NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE |
622 ((u64)adapter->portnum << 16);
623 req.req_hdr = cpu_to_le64(word);
625 req.words[0] = cpu_to_le64(mode);
627 return netxen_send_cmd_descs(adapter,
628 (struct cmd_desc_type0 *)&req, 1);
631 void netxen_p3_free_mac_list(struct netxen_adapter *adapter)
633 nx_mac_list_t *cur, *next;
635 cur = adapter->mac_list;
644 #define NETXEN_CONFIG_INTR_COALESCE 3
647 * Send the interrupt coalescing parameter set by ethtool to the card.
649 int netxen_config_intr_coalesce(struct netxen_adapter *adapter)
655 memset(&req, 0, sizeof(nx_nic_req_t));
657 req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23);
659 word = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16);
660 req.req_hdr = cpu_to_le64(word);
662 memcpy(&req.words[0], &adapter->coal, sizeof(adapter->coal));
664 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
666 printk(KERN_ERR "ERROR. Could not send "
667 "interrupt coalescing parameters\n");
674 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
675 * @returns 0 on success, negative on failure
678 #define MTU_FUDGE_FACTOR 100
680 int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
682 struct netxen_adapter *adapter = netdev_priv(netdev);
686 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
687 max_mtu = P3_MAX_MTU;
689 max_mtu = P2_MAX_MTU;
692 printk(KERN_ERR "%s: mtu > %d bytes unsupported\n",
693 netdev->name, max_mtu);
697 if (adapter->set_mtu)
698 rc = adapter->set_mtu(adapter, mtu);
706 int netxen_is_flash_supported(struct netxen_adapter *adapter)
708 const int locs[] = { 0, 0x4, 0x100, 0x4000, 0x4128 };
709 int addr, val01, val02, i, j;
711 /* if the flash size less than 4Mb, make huge war cry and die */
712 for (j = 1; j < 4; j++) {
713 addr = j * NETXEN_NIC_WINDOW_MARGIN;
714 for (i = 0; i < ARRAY_SIZE(locs); i++) {
715 if (netxen_rom_fast_read(adapter, locs[i], &val01) == 0
716 && netxen_rom_fast_read(adapter, (addr + locs[i]),
728 static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
729 int size, __le32 * buf)
737 for (i = 0; i < size / sizeof(u32); i++) {
738 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
740 *ptr32 = cpu_to_le32(v);
744 if ((char *)buf + size > (char *)ptr32) {
746 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
748 local = cpu_to_le32(v);
749 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
755 int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 *mac)
757 __le32 *pmac = (__le32 *) mac;
760 offset = NETXEN_USER_START +
761 offsetof(struct netxen_new_user_info, mac_addr) +
762 adapter->portnum * sizeof(u64);
764 if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1)
767 if (*mac == cpu_to_le64(~0ULL)) {
769 offset = NETXEN_USER_START_OLD +
770 offsetof(struct netxen_user_old_info, mac_addr) +
771 adapter->portnum * sizeof(u64);
773 if (netxen_get_flash_block(adapter,
774 offset, sizeof(u64), pmac) == -1)
777 if (*mac == cpu_to_le64(~0ULL))
783 int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, __le64 *mac)
785 uint32_t crbaddr, mac_hi, mac_lo;
786 int pci_func = adapter->ahw.pci_func;
788 crbaddr = CRB_MAC_BLOCK_START +
789 (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1));
791 adapter->hw_read_wx(adapter, crbaddr, &mac_lo, 4);
792 adapter->hw_read_wx(adapter, crbaddr+4, &mac_hi, 4);
795 *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16));
797 *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32));
802 #define CRB_WIN_LOCK_TIMEOUT 100000000
804 static int crb_win_lock(struct netxen_adapter *adapter)
806 int done = 0, timeout = 0;
809 /* acquire semaphore3 from PCI HW block */
810 adapter->hw_read_wx(adapter,
811 NETXEN_PCIE_REG(PCIE_SEM7_LOCK), &done, 4);
814 if (timeout >= CRB_WIN_LOCK_TIMEOUT)
819 netxen_crb_writelit_adapter(adapter,
820 NETXEN_CRB_WIN_LOCK_ID, adapter->portnum);
824 static void crb_win_unlock(struct netxen_adapter *adapter)
828 adapter->hw_read_wx(adapter,
829 NETXEN_PCIE_REG(PCIE_SEM7_UNLOCK), &val, 4);
833 * Changes the CRB window to the specified window.
836 netxen_nic_pci_change_crbwindow_128M(struct netxen_adapter *adapter, u32 wndw)
838 void __iomem *offset;
841 uint8_t func = adapter->ahw.pci_func;
843 if (adapter->curr_window == wndw)
846 * Move the CRB window.
847 * We need to write to the "direct access" region of PCI
848 * to avoid a race condition where the window register has
849 * not been successfully written across CRB before the target
850 * register address is received by PCI. The direct region bypasses
853 offset = PCI_OFFSET_SECOND_RANGE(adapter,
854 NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
857 wndw = NETXEN_WINDOW_ONE;
859 writel(wndw, offset);
861 /* MUST make sure window is set before we forge on... */
862 while ((tmp = readl(offset)) != wndw) {
863 printk(KERN_WARNING "%s: %s WARNING: CRB window value not "
864 "registered properly: 0x%08x.\n",
865 netxen_nic_driver_name, __func__, tmp);
872 if (wndw == NETXEN_WINDOW_ONE)
873 adapter->curr_window = 1;
875 adapter->curr_window = 0;
879 * Return -1 if off is not valid,
880 * 1 if window access is needed. 'off' is set to offset from
881 * CRB space in 128M pci map
882 * 0 if no window access is needed. 'off' is set to 2M addr
883 * In: 'off' is offset from base in 128M pci map
886 netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter,
889 unsigned long end = *off + len;
890 crb_128M_2M_sub_block_map_t *m;
893 if (*off >= NETXEN_CRB_MAX)
896 if (*off >= NETXEN_PCI_CAMQM && (end <= NETXEN_PCI_CAMQM_2M_END)) {
897 *off = (*off - NETXEN_PCI_CAMQM) + NETXEN_PCI_CAMQM_2M_BASE +
898 (ulong)adapter->ahw.pci_base0;
902 if (*off < NETXEN_PCI_CRBSPACE)
905 *off -= NETXEN_PCI_CRBSPACE;
911 m = &crb_128M_2M_map[CRB_BLK(*off)].sub_block[CRB_SUBBLK(*off)];
913 if (m->valid && (m->start_128M <= *off) && (m->end_128M >= end)) {
914 *off = *off + m->start_2M - m->start_128M +
915 (ulong)adapter->ahw.pci_base0;
920 * Not in direct map, use crb window
926 * In: 'off' is offset from CRB space in 128M pci map
927 * Out: 'off' is 2M pci map addr
928 * side effect: lock crb window
931 netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong *off)
935 adapter->crb_win = CRB_HI(*off);
936 writel(adapter->crb_win, (adapter->ahw.pci_base0 + CRB_WINDOW_2M));
938 * Read back value to make sure write has gone through before trying
941 win_read = readl(adapter->ahw.pci_base0 + CRB_WINDOW_2M);
942 if (win_read != adapter->crb_win) {
943 printk(KERN_ERR "%s: Written crbwin (0x%x) != "
944 "Read crbwin (0x%x), off=0x%lx\n",
945 __func__, adapter->crb_win, win_read, *off);
947 *off = (*off & MASK(16)) + CRB_INDIRECT_2M +
948 (ulong)adapter->ahw.pci_base0;
952 netxen_do_load_firmware(struct netxen_adapter *adapter, const char *fwname,
953 const struct firmware *fw)
956 u32 i, flashaddr, size;
957 struct pci_dev *pdev = adapter->pdev;
960 dev_info(&pdev->dev, "loading firmware from file %s\n", fwname);
962 dev_info(&pdev->dev, "loading firmware from flash\n");
964 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
965 adapter->pci_write_normalize(adapter,
966 NETXEN_ROMUSB_GLB_CAS_RST, 1);
971 size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 8;
973 ptr64 = (u64 *)&fw->data[NETXEN_BOOTLD_START];
974 flashaddr = NETXEN_BOOTLD_START;
976 for (i = 0; i < size; i++) {
977 data = cpu_to_le64(ptr64[i]);
978 adapter->pci_mem_write(adapter, flashaddr, &data, 8);
982 size = *(u32 *)&fw->data[NX_FW_SIZE_OFFSET];
983 size = (__force u32)cpu_to_le32(size) / 8;
985 ptr64 = (u64 *)&fw->data[NETXEN_IMAGE_START];
986 flashaddr = NETXEN_IMAGE_START;
988 for (i = 0; i < size; i++) {
989 data = cpu_to_le64(ptr64[i]);
991 if (adapter->pci_mem_write(adapter,
992 flashaddr, &data, 8))
1000 size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 4;
1001 flashaddr = NETXEN_BOOTLD_START;
1003 for (i = 0; i < size; i++) {
1004 if (netxen_rom_fast_read(adapter,
1005 flashaddr, (int *)&data) != 0)
1008 if (adapter->pci_mem_write(adapter,
1009 flashaddr, &data, 4))
1017 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1018 adapter->pci_write_normalize(adapter,
1019 NETXEN_ROMUSB_GLB_SW_RESET, 0x80001d);
1021 adapter->pci_write_normalize(adapter,
1022 NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL, 0x3fff);
1023 adapter->pci_write_normalize(adapter,
1024 NETXEN_ROMUSB_GLB_CAS_RST, 0);
1031 netxen_validate_firmware(struct netxen_adapter *adapter, const char *fwname,
1032 const struct firmware *fw)
1035 u32 major, minor, build, ver, min_ver, bios;
1036 struct pci_dev *pdev = adapter->pdev;
1038 if (fw->size < NX_FW_MIN_SIZE)
1041 val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_MAGIC_OFFSET]);
1042 if ((__force u32)val != NETXEN_BDINFO_MAGIC)
1045 val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_VERSION_OFFSET]);
1046 major = (__force u32)val & 0xff;
1047 minor = ((__force u32)val >> 8) & 0xff;
1048 build = (__force u32)val >> 16;
1050 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1051 min_ver = NETXEN_VERSION_CODE(4, 0, 216);
1053 min_ver = NETXEN_VERSION_CODE(3, 4, 216);
1055 ver = NETXEN_VERSION_CODE(major, minor, build);
1057 if ((major > _NETXEN_NIC_LINUX_MAJOR) || (ver < min_ver)) {
1059 "%s: firmware version %d.%d.%d unsupported\n",
1060 fwname, major, minor, build);
1064 val = cpu_to_le32(*(u32 *)&fw->data[NX_BIOS_VERSION_OFFSET]);
1065 netxen_rom_fast_read(adapter, NX_BIOS_VERSION_OFFSET, (int *)&bios);
1066 if ((__force u32)val != bios) {
1067 dev_err(&pdev->dev, "%s: firmware bios is incompatible\n",
1072 netxen_nic_reg_write(adapter, NETXEN_CAM_RAM(0x1fc),
1073 NETXEN_BDINFO_MAGIC);
1077 int netxen_load_firmware(struct netxen_adapter *adapter)
1079 u32 capability, flashed_ver;
1080 const struct firmware *fw;
1081 char *fw_name = NULL;
1082 struct pci_dev *pdev = adapter->pdev;
1085 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1086 fw_name = NX_P2_MN_ROMIMAGE;
1092 netxen_rom_fast_read(adapter,
1093 NX_FW_VERSION_OFFSET, (int *)&flashed_ver);
1094 if (flashed_ver >= NETXEN_VERSION_CODE(4, 0, 220)) {
1095 adapter->hw_read_wx(adapter,
1096 NX_PEG_TUNE_CAPABILITY, &capability, 4);
1097 if (capability & NX_PEG_TUNE_MN_PRESENT) {
1098 fw_name = NX_P3_MN_ROMIMAGE;
1104 fw_name = NX_P3_CT_ROMIMAGE;
1107 rc = request_firmware(&fw, fw_name, &pdev->dev);
1109 if (fw_name == NX_P3_MN_ROMIMAGE) {
1118 rc = netxen_validate_firmware(adapter, fw_name, fw);
1120 release_firmware(fw);
1122 if (fw_name == NX_P3_MN_ROMIMAGE) {
1131 rc = netxen_do_load_firmware(adapter, fw_name, fw);
1134 release_firmware(fw);
1139 netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter,
1140 ulong off, void *data, int len)
1146 if (ADDR_IN_WINDOW1(off)) {
1147 addr = NETXEN_CRB_NORMALIZE(adapter, off);
1148 } else { /* Window 0 */
1149 addr = pci_base_offset(adapter, off);
1150 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1154 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1158 writel(*(u32 *) data, addr);
1160 if (!ADDR_IN_WINDOW1(off))
1161 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1167 netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter,
1168 ulong off, void *data, int len)
1174 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
1175 addr = NETXEN_CRB_NORMALIZE(adapter, off);
1176 } else { /* Window 0 */
1177 addr = pci_base_offset(adapter, off);
1178 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1182 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1186 *(u32 *)data = readl(addr);
1188 if (!ADDR_IN_WINDOW1(off))
1189 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1195 netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter,
1196 ulong off, void *data, int len)
1198 unsigned long flags = 0;
1203 rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off, len);
1206 printk(KERN_ERR "%s: invalid offset: 0x%016lx\n",
1213 write_lock_irqsave(&adapter->adapter_lock, flags);
1214 crb_win_lock(adapter);
1215 netxen_nic_pci_set_crbwindow_2M(adapter, &off);
1216 writel(*(uint32_t *)data, (void __iomem *)off);
1217 crb_win_unlock(adapter);
1218 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1220 writel(*(uint32_t *)data, (void __iomem *)off);
1227 netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter,
1228 ulong off, void *data, int len)
1230 unsigned long flags = 0;
1235 rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off, len);
1238 printk(KERN_ERR "%s: invalid offset: 0x%016lx\n",
1245 write_lock_irqsave(&adapter->adapter_lock, flags);
1246 crb_win_lock(adapter);
1247 netxen_nic_pci_set_crbwindow_2M(adapter, &off);
1248 *(uint32_t *)data = readl((void __iomem *)off);
1249 crb_win_unlock(adapter);
1250 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1252 *(uint32_t *)data = readl((void __iomem *)off);
1257 void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val)
1259 adapter->hw_write_wx(adapter, off, &val, 4);
1262 int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off)
1265 adapter->hw_read_wx(adapter, off, &val, 4);
1269 /* Change the window to 0, write and change back to window 1. */
1270 void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value)
1272 adapter->hw_write_wx(adapter, index, &value, 4);
1275 /* Change the window to 0, read and change back to window 1. */
1276 void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 *value)
1278 adapter->hw_read_wx(adapter, index, value, 4);
1281 void netxen_nic_write_w1(struct netxen_adapter *adapter, u32 index, u32 value)
1283 adapter->hw_write_wx(adapter, index, &value, 4);
1286 void netxen_nic_read_w1(struct netxen_adapter *adapter, u32 index, u32 *value)
1288 adapter->hw_read_wx(adapter, index, value, 4);
1292 * check memory access boundary.
1293 * used by test agent. support ddr access only for now
1295 static unsigned long
1296 netxen_nic_pci_mem_bound_check(struct netxen_adapter *adapter,
1297 unsigned long long addr, int size)
1299 if (!ADDR_IN_RANGE(addr,
1300 NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX) ||
1301 !ADDR_IN_RANGE(addr+size-1,
1302 NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX) ||
1303 ((size != 1) && (size != 2) && (size != 4) && (size != 8))) {
1310 static int netxen_pci_set_window_warning_count;
1313 netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
1314 unsigned long long addr)
1316 void __iomem *offset;
1318 unsigned long long qdr_max;
1319 uint8_t func = adapter->ahw.pci_func;
1321 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1322 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P2;
1324 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P3;
1327 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1328 /* DDR network side */
1329 addr -= NETXEN_ADDR_DDR_NET;
1330 window = (addr >> 25) & 0x3ff;
1331 if (adapter->ahw.ddr_mn_window != window) {
1332 adapter->ahw.ddr_mn_window = window;
1333 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1334 NETXEN_PCIX_PH_REG(PCIE_MN_WINDOW_REG(func)));
1335 writel(window, offset);
1336 /* MUST make sure window is set before we forge on... */
1339 addr -= (window * NETXEN_WINDOW_ONE);
1340 addr += NETXEN_PCI_DDR_NET;
1341 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1342 addr -= NETXEN_ADDR_OCM0;
1343 addr += NETXEN_PCI_OCM0;
1344 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1345 addr -= NETXEN_ADDR_OCM1;
1346 addr += NETXEN_PCI_OCM1;
1347 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_QDR_NET, qdr_max)) {
1348 /* QDR network side */
1349 addr -= NETXEN_ADDR_QDR_NET;
1350 window = (addr >> 22) & 0x3f;
1351 if (adapter->ahw.qdr_sn_window != window) {
1352 adapter->ahw.qdr_sn_window = window;
1353 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1354 NETXEN_PCIX_PH_REG(PCIE_SN_WINDOW_REG(func)));
1355 writel((window << 22), offset);
1356 /* MUST make sure window is set before we forge on... */
1359 addr -= (window * 0x400000);
1360 addr += NETXEN_PCI_QDR_NET;
1363 * peg gdb frequently accesses memory that doesn't exist,
1364 * this limits the chit chat so debugging isn't slowed down.
1366 if ((netxen_pci_set_window_warning_count++ < 8)
1367 || (netxen_pci_set_window_warning_count % 64 == 0))
1368 printk("%s: Warning:netxen_nic_pci_set_window()"
1369 " Unknown address range!\n",
1370 netxen_nic_driver_name);
1377 * Note : only 32-bit writes!
1379 int netxen_nic_pci_write_immediate_128M(struct netxen_adapter *adapter,
1382 writel(data, (void __iomem *)(PCI_OFFSET_SECOND_RANGE(adapter, off)));
1386 u32 netxen_nic_pci_read_immediate_128M(struct netxen_adapter *adapter, u64 off)
1388 return readl((void __iomem *)(pci_base_offset(adapter, off)));
1391 void netxen_nic_pci_write_normalize_128M(struct netxen_adapter *adapter,
1394 writel(data, NETXEN_CRB_NORMALIZE(adapter, off));
1397 u32 netxen_nic_pci_read_normalize_128M(struct netxen_adapter *adapter, u64 off)
1399 return readl(NETXEN_CRB_NORMALIZE(adapter, off));
1403 netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
1404 unsigned long long addr)
1409 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1410 /* DDR network side */
1411 window = MN_WIN(addr);
1412 adapter->ahw.ddr_mn_window = window;
1413 adapter->hw_write_wx(adapter,
1414 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
1416 adapter->hw_read_wx(adapter,
1417 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
1419 if ((win_read << 17) != window) {
1420 printk(KERN_INFO "Written MNwin (0x%x) != "
1421 "Read MNwin (0x%x)\n", window, win_read);
1423 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_DDR_NET;
1424 } else if (ADDR_IN_RANGE(addr,
1425 NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1426 if ((addr & 0x00ff800) == 0xff800) {
1427 printk("%s: QM access not handled.\n", __func__);
1431 window = OCM_WIN(addr);
1432 adapter->ahw.ddr_mn_window = window;
1433 adapter->hw_write_wx(adapter,
1434 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
1436 adapter->hw_read_wx(adapter,
1437 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
1439 if ((win_read >> 7) != window) {
1440 printk(KERN_INFO "%s: Written OCMwin (0x%x) != "
1441 "Read OCMwin (0x%x)\n",
1442 __func__, window, win_read);
1444 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_OCM0_2M;
1446 } else if (ADDR_IN_RANGE(addr,
1447 NETXEN_ADDR_QDR_NET, NETXEN_ADDR_QDR_NET_MAX_P3)) {
1448 /* QDR network side */
1449 window = MS_WIN(addr);
1450 adapter->ahw.qdr_sn_window = window;
1451 adapter->hw_write_wx(adapter,
1452 adapter->ahw.ms_win_crb | NETXEN_PCI_CRBSPACE,
1454 adapter->hw_read_wx(adapter,
1455 adapter->ahw.ms_win_crb | NETXEN_PCI_CRBSPACE,
1457 if (win_read != window) {
1458 printk(KERN_INFO "%s: Written MSwin (0x%x) != "
1459 "Read MSwin (0x%x)\n",
1460 __func__, window, win_read);
1462 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_QDR_NET;
1466 * peg gdb frequently accesses memory that doesn't exist,
1467 * this limits the chit chat so debugging isn't slowed down.
1469 if ((netxen_pci_set_window_warning_count++ < 8)
1470 || (netxen_pci_set_window_warning_count%64 == 0)) {
1471 printk("%s: Warning:%s Unknown address range!\n",
1472 __func__, netxen_nic_driver_name);
1479 static int netxen_nic_pci_is_same_window(struct netxen_adapter *adapter,
1480 unsigned long long addr)
1483 unsigned long long qdr_max;
1485 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
1486 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P2;
1488 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P3;
1490 if (ADDR_IN_RANGE(addr,
1491 NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1492 /* DDR network side */
1493 BUG(); /* MN access can not come here */
1494 } else if (ADDR_IN_RANGE(addr,
1495 NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1497 } else if (ADDR_IN_RANGE(addr,
1498 NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1500 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_QDR_NET, qdr_max)) {
1501 /* QDR network side */
1502 window = ((addr - NETXEN_ADDR_QDR_NET) >> 22) & 0x3f;
1503 if (adapter->ahw.qdr_sn_window == window)
1510 static int netxen_nic_pci_mem_read_direct(struct netxen_adapter *adapter,
1511 u64 off, void *data, int size)
1513 unsigned long flags;
1514 void __iomem *addr, *mem_ptr = NULL;
1517 unsigned long mem_base;
1518 unsigned long mem_page;
1520 write_lock_irqsave(&adapter->adapter_lock, flags);
1523 * If attempting to access unknown address or straddle hw windows,
1526 start = adapter->pci_set_window(adapter, off);
1527 if ((start == -1UL) ||
1528 (netxen_nic_pci_is_same_window(adapter, off+size-1) == 0)) {
1529 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1530 printk(KERN_ERR "%s out of bound pci memory access. "
1531 "offset is 0x%llx\n", netxen_nic_driver_name,
1532 (unsigned long long)off);
1536 addr = pci_base_offset(adapter, start);
1538 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1539 mem_base = pci_resource_start(adapter->pdev, 0);
1540 mem_page = start & PAGE_MASK;
1541 /* Map two pages whenever user tries to access addresses in two
1544 if (mem_page != ((start + size - 1) & PAGE_MASK))
1545 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1547 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
1548 if (mem_ptr == NULL) {
1549 *(uint8_t *)data = 0;
1553 addr += start & (PAGE_SIZE - 1);
1554 write_lock_irqsave(&adapter->adapter_lock, flags);
1559 *(uint8_t *)data = readb(addr);
1562 *(uint16_t *)data = readw(addr);
1565 *(uint32_t *)data = readl(addr);
1568 *(uint64_t *)data = readq(addr);
1574 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1582 netxen_nic_pci_mem_write_direct(struct netxen_adapter *adapter, u64 off,
1583 void *data, int size)
1585 unsigned long flags;
1586 void __iomem *addr, *mem_ptr = NULL;
1589 unsigned long mem_base;
1590 unsigned long mem_page;
1592 write_lock_irqsave(&adapter->adapter_lock, flags);
1595 * If attempting to access unknown address or straddle hw windows,
1598 start = adapter->pci_set_window(adapter, off);
1599 if ((start == -1UL) ||
1600 (netxen_nic_pci_is_same_window(adapter, off+size-1) == 0)) {
1601 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1602 printk(KERN_ERR "%s out of bound pci memory access. "
1603 "offset is 0x%llx\n", netxen_nic_driver_name,
1604 (unsigned long long)off);
1608 addr = pci_base_offset(adapter, start);
1610 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1611 mem_base = pci_resource_start(adapter->pdev, 0);
1612 mem_page = start & PAGE_MASK;
1613 /* Map two pages whenever user tries to access addresses in two
1614 * consecutive pages.
1616 if (mem_page != ((start + size - 1) & PAGE_MASK))
1617 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE*2);
1619 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
1620 if (mem_ptr == NULL)
1623 addr += start & (PAGE_SIZE - 1);
1624 write_lock_irqsave(&adapter->adapter_lock, flags);
1629 writeb(*(uint8_t *)data, addr);
1632 writew(*(uint16_t *)data, addr);
1635 writel(*(uint32_t *)data, addr);
1638 writeq(*(uint64_t *)data, addr);
1644 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1650 #define MAX_CTL_CHECK 1000
1653 netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
1654 u64 off, void *data, int size)
1656 unsigned long flags;
1657 int i, j, ret = 0, loop, sz[2], off0;
1659 uint64_t off8, tmpw, word[2] = {0, 0};
1660 void __iomem *mem_crb;
1663 * If not MN, go check for MS or invalid.
1665 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1666 return netxen_nic_pci_mem_write_direct(adapter,
1669 off8 = off & 0xfffffff8;
1671 sz[0] = (size < (8 - off0)) ? size : (8 - off0);
1672 sz[1] = size - sz[0];
1673 loop = ((off0 + size - 1) >> 3) + 1;
1674 mem_crb = pci_base_offset(adapter, NETXEN_CRB_DDR_NET);
1676 if ((size != 8) || (off0 != 0)) {
1677 for (i = 0; i < loop; i++) {
1678 if (adapter->pci_mem_read(adapter,
1679 off8 + (i << 3), &word[i], 8))
1686 tmpw = *((uint8_t *)data);
1689 tmpw = *((uint16_t *)data);
1692 tmpw = *((uint32_t *)data);
1696 tmpw = *((uint64_t *)data);
1699 word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
1700 word[0] |= tmpw << (off0 * 8);
1703 word[1] &= ~(~0ULL << (sz[1] * 8));
1704 word[1] |= tmpw >> (sz[0] * 8);
1707 write_lock_irqsave(&adapter->adapter_lock, flags);
1708 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1710 for (i = 0; i < loop; i++) {
1711 writel((uint32_t)(off8 + (i << 3)),
1712 (mem_crb+MIU_TEST_AGT_ADDR_LO));
1714 (mem_crb+MIU_TEST_AGT_ADDR_HI));
1715 writel(word[i] & 0xffffffff,
1716 (mem_crb+MIU_TEST_AGT_WRDATA_LO));
1717 writel((word[i] >> 32) & 0xffffffff,
1718 (mem_crb+MIU_TEST_AGT_WRDATA_HI));
1719 writel(MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE,
1720 (mem_crb+MIU_TEST_AGT_CTRL));
1721 writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE,
1722 (mem_crb+MIU_TEST_AGT_CTRL));
1724 for (j = 0; j < MAX_CTL_CHECK; j++) {
1726 (mem_crb+MIU_TEST_AGT_CTRL));
1727 if ((temp & MIU_TA_CTL_BUSY) == 0)
1731 if (j >= MAX_CTL_CHECK) {
1732 if (printk_ratelimit())
1733 dev_err(&adapter->pdev->dev,
1734 "failed to write through agent\n");
1740 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1741 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1746 netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
1747 u64 off, void *data, int size)
1749 unsigned long flags;
1750 int i, j = 0, k, start, end, loop, sz[2], off0[2];
1752 uint64_t off8, val, word[2] = {0, 0};
1753 void __iomem *mem_crb;
1757 * If not MN, go check for MS or invalid.
1759 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1760 return netxen_nic_pci_mem_read_direct(adapter, off, data, size);
1762 off8 = off & 0xfffffff8;
1763 off0[0] = off & 0x7;
1765 sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]);
1766 sz[1] = size - sz[0];
1767 loop = ((off0[0] + size - 1) >> 3) + 1;
1768 mem_crb = pci_base_offset(adapter, NETXEN_CRB_DDR_NET);
1770 write_lock_irqsave(&adapter->adapter_lock, flags);
1771 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1773 for (i = 0; i < loop; i++) {
1774 writel((uint32_t)(off8 + (i << 3)),
1775 (mem_crb+MIU_TEST_AGT_ADDR_LO));
1777 (mem_crb+MIU_TEST_AGT_ADDR_HI));
1778 writel(MIU_TA_CTL_ENABLE,
1779 (mem_crb+MIU_TEST_AGT_CTRL));
1780 writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE,
1781 (mem_crb+MIU_TEST_AGT_CTRL));
1783 for (j = 0; j < MAX_CTL_CHECK; j++) {
1785 (mem_crb+MIU_TEST_AGT_CTRL));
1786 if ((temp & MIU_TA_CTL_BUSY) == 0)
1790 if (j >= MAX_CTL_CHECK) {
1791 if (printk_ratelimit())
1792 dev_err(&adapter->pdev->dev,
1793 "failed to read through agent\n");
1797 start = off0[i] >> 2;
1798 end = (off0[i] + sz[i] - 1) >> 2;
1799 for (k = start; k <= end; k++) {
1800 word[i] |= ((uint64_t) readl(
1802 MIU_TEST_AGT_RDDATA(k))) << (32*k));
1806 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1807 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1809 if (j >= MAX_CTL_CHECK)
1815 val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
1816 ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
1821 *(uint8_t *)data = val;
1824 *(uint16_t *)data = val;
1827 *(uint32_t *)data = val;
1830 *(uint64_t *)data = val;
1837 netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
1838 u64 off, void *data, int size)
1840 int i, j, ret = 0, loop, sz[2], off0;
1842 uint64_t off8, mem_crb, tmpw, word[2] = {0, 0};
1845 * If not MN, go check for MS or invalid.
1847 if (off >= NETXEN_ADDR_QDR_NET && off <= NETXEN_ADDR_QDR_NET_MAX_P3)
1848 mem_crb = NETXEN_CRB_QDR_NET;
1850 mem_crb = NETXEN_CRB_DDR_NET;
1851 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1852 return netxen_nic_pci_mem_write_direct(adapter,
1856 off8 = off & 0xfffffff8;
1858 sz[0] = (size < (8 - off0)) ? size : (8 - off0);
1859 sz[1] = size - sz[0];
1860 loop = ((off0 + size - 1) >> 3) + 1;
1862 if ((size != 8) || (off0 != 0)) {
1863 for (i = 0; i < loop; i++) {
1864 if (adapter->pci_mem_read(adapter, off8 + (i << 3),
1872 tmpw = *((uint8_t *)data);
1875 tmpw = *((uint16_t *)data);
1878 tmpw = *((uint32_t *)data);
1882 tmpw = *((uint64_t *)data);
1886 word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
1887 word[0] |= tmpw << (off0 * 8);
1890 word[1] &= ~(~0ULL << (sz[1] * 8));
1891 word[1] |= tmpw >> (sz[0] * 8);
1895 * don't lock here - write_wx gets the lock if each time
1896 * write_lock_irqsave(&adapter->adapter_lock, flags);
1897 * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1900 for (i = 0; i < loop; i++) {
1901 temp = off8 + (i << 3);
1902 adapter->hw_write_wx(adapter,
1903 mem_crb+MIU_TEST_AGT_ADDR_LO, &temp, 4);
1905 adapter->hw_write_wx(adapter,
1906 mem_crb+MIU_TEST_AGT_ADDR_HI, &temp, 4);
1907 temp = word[i] & 0xffffffff;
1908 adapter->hw_write_wx(adapter,
1909 mem_crb+MIU_TEST_AGT_WRDATA_LO, &temp, 4);
1910 temp = (word[i] >> 32) & 0xffffffff;
1911 adapter->hw_write_wx(adapter,
1912 mem_crb+MIU_TEST_AGT_WRDATA_HI, &temp, 4);
1913 temp = MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE;
1914 adapter->hw_write_wx(adapter,
1915 mem_crb+MIU_TEST_AGT_CTRL, &temp, 4);
1916 temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE;
1917 adapter->hw_write_wx(adapter,
1918 mem_crb+MIU_TEST_AGT_CTRL, &temp, 4);
1920 for (j = 0; j < MAX_CTL_CHECK; j++) {
1921 adapter->hw_read_wx(adapter,
1922 mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
1923 if ((temp & MIU_TA_CTL_BUSY) == 0)
1927 if (j >= MAX_CTL_CHECK) {
1928 if (printk_ratelimit())
1929 dev_err(&adapter->pdev->dev,
1930 "failed to write through agent\n");
1937 * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1938 * write_unlock_irqrestore(&adapter->adapter_lock, flags);
1944 netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
1945 u64 off, void *data, int size)
1947 int i, j = 0, k, start, end, loop, sz[2], off0[2];
1949 uint64_t off8, val, mem_crb, word[2] = {0, 0};
1952 * If not MN, go check for MS or invalid.
1955 if (off >= NETXEN_ADDR_QDR_NET && off <= NETXEN_ADDR_QDR_NET_MAX_P3)
1956 mem_crb = NETXEN_CRB_QDR_NET;
1958 mem_crb = NETXEN_CRB_DDR_NET;
1959 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1960 return netxen_nic_pci_mem_read_direct(adapter,
1964 off8 = off & 0xfffffff8;
1965 off0[0] = off & 0x7;
1967 sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]);
1968 sz[1] = size - sz[0];
1969 loop = ((off0[0] + size - 1) >> 3) + 1;
1972 * don't lock here - write_wx gets the lock if each time
1973 * write_lock_irqsave(&adapter->adapter_lock, flags);
1974 * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1977 for (i = 0; i < loop; i++) {
1978 temp = off8 + (i << 3);
1979 adapter->hw_write_wx(adapter,
1980 mem_crb + MIU_TEST_AGT_ADDR_LO, &temp, 4);
1982 adapter->hw_write_wx(adapter,
1983 mem_crb + MIU_TEST_AGT_ADDR_HI, &temp, 4);
1984 temp = MIU_TA_CTL_ENABLE;
1985 adapter->hw_write_wx(adapter,
1986 mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
1987 temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE;
1988 adapter->hw_write_wx(adapter,
1989 mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
1991 for (j = 0; j < MAX_CTL_CHECK; j++) {
1992 adapter->hw_read_wx(adapter,
1993 mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
1994 if ((temp & MIU_TA_CTL_BUSY) == 0)
1998 if (j >= MAX_CTL_CHECK) {
1999 if (printk_ratelimit())
2000 dev_err(&adapter->pdev->dev,
2001 "failed to read through agent\n");
2005 start = off0[i] >> 2;
2006 end = (off0[i] + sz[i] - 1) >> 2;
2007 for (k = start; k <= end; k++) {
2008 adapter->hw_read_wx(adapter,
2009 mem_crb + MIU_TEST_AGT_RDDATA(k), &temp, 4);
2010 word[i] |= ((uint64_t)temp << (32 * k));
2015 * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
2016 * write_unlock_irqrestore(&adapter->adapter_lock, flags);
2019 if (j >= MAX_CTL_CHECK)
2025 val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
2026 ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
2031 *(uint8_t *)data = val;
2034 *(uint16_t *)data = val;
2037 *(uint32_t *)data = val;
2040 *(uint64_t *)data = val;
2047 * Note : only 32-bit writes!
2049 int netxen_nic_pci_write_immediate_2M(struct netxen_adapter *adapter,
2052 adapter->hw_write_wx(adapter, off, &data, 4);
2057 u32 netxen_nic_pci_read_immediate_2M(struct netxen_adapter *adapter, u64 off)
2060 adapter->hw_read_wx(adapter, off, &temp, 4);
2064 void netxen_nic_pci_write_normalize_2M(struct netxen_adapter *adapter,
2067 adapter->hw_write_wx(adapter, off, &data, 4);
2070 u32 netxen_nic_pci_read_normalize_2M(struct netxen_adapter *adapter, u64 off)
2073 adapter->hw_read_wx(adapter, off, &temp, 4);
2077 int netxen_nic_get_board_info(struct netxen_adapter *adapter)
2080 int addr = NETXEN_BRDCFG_START;
2081 struct netxen_board_info *boardinfo;
2085 boardinfo = &adapter->ahw.boardcfg;
2086 ptr32 = (int *) boardinfo;
2088 for (index = 0; index < sizeof(struct netxen_board_info) / sizeof(u32);
2090 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
2094 addr += sizeof(u32);
2096 if (boardinfo->magic != NETXEN_BDINFO_MAGIC) {
2097 printk("%s: ERROR reading %s board config."
2098 " Read %x, expected %x\n", netxen_nic_driver_name,
2099 netxen_nic_driver_name,
2100 boardinfo->magic, NETXEN_BDINFO_MAGIC);
2103 if (boardinfo->header_version != NETXEN_BDINFO_VERSION) {
2104 printk("%s: Unknown board config version."
2105 " Read %x, expected %x\n", netxen_nic_driver_name,
2106 boardinfo->header_version, NETXEN_BDINFO_VERSION);
2110 if (boardinfo->board_type == NETXEN_BRDTYPE_P3_4_GB_MM) {
2111 u32 gpio = netxen_nic_reg_read(adapter,
2112 NETXEN_ROMUSB_GLB_PAD_GPIO_I);
2113 if ((gpio & 0x8000) == 0)
2114 boardinfo->board_type = NETXEN_BRDTYPE_P3_10G_TP;
2117 switch ((netxen_brdtype_t) boardinfo->board_type) {
2118 case NETXEN_BRDTYPE_P2_SB35_4G:
2119 adapter->ahw.board_type = NETXEN_NIC_GBE;
2121 case NETXEN_BRDTYPE_P2_SB31_10G:
2122 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
2123 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
2124 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
2125 case NETXEN_BRDTYPE_P3_HMEZ:
2126 case NETXEN_BRDTYPE_P3_XG_LOM:
2127 case NETXEN_BRDTYPE_P3_10G_CX4:
2128 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
2129 case NETXEN_BRDTYPE_P3_IMEZ:
2130 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
2131 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
2132 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
2133 case NETXEN_BRDTYPE_P3_10G_XFP:
2134 case NETXEN_BRDTYPE_P3_10000_BASE_T:
2135 adapter->ahw.board_type = NETXEN_NIC_XGBE;
2137 case NETXEN_BRDTYPE_P1_BD:
2138 case NETXEN_BRDTYPE_P1_SB:
2139 case NETXEN_BRDTYPE_P1_SMAX:
2140 case NETXEN_BRDTYPE_P1_SOCK:
2141 case NETXEN_BRDTYPE_P3_REF_QG:
2142 case NETXEN_BRDTYPE_P3_4_GB:
2143 case NETXEN_BRDTYPE_P3_4_GB_MM:
2144 adapter->ahw.board_type = NETXEN_NIC_GBE;
2146 case NETXEN_BRDTYPE_P3_10G_TP:
2147 adapter->ahw.board_type = (adapter->portnum < 2) ?
2148 NETXEN_NIC_XGBE : NETXEN_NIC_GBE;
2151 printk("%s: Unknown(%x)\n", netxen_nic_driver_name,
2152 boardinfo->board_type);
2160 /* NIU access sections */
2162 int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu)
2164 new_mtu += MTU_FUDGE_FACTOR;
2165 netxen_nic_write_w0(adapter,
2166 NETXEN_NIU_GB_MAX_FRAME_SIZE(adapter->physical_port),
2171 int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
2173 new_mtu += MTU_FUDGE_FACTOR;
2174 if (adapter->physical_port == 0)
2175 netxen_nic_write_w0(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE,
2178 netxen_nic_write_w0(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE,
2184 netxen_crb_writelit_adapter(struct netxen_adapter *adapter,
2185 unsigned long off, int data)
2187 adapter->hw_write_wx(adapter, off, &data, 4);
2190 void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
2196 if (!netif_carrier_ok(adapter->netdev)) {
2197 adapter->link_speed = 0;
2198 adapter->link_duplex = -1;
2199 adapter->link_autoneg = AUTONEG_ENABLE;
2203 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
2204 adapter->hw_read_wx(adapter,
2205 NETXEN_PORT_MODE_ADDR, &port_mode, 4);
2206 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
2207 adapter->link_speed = SPEED_1000;
2208 adapter->link_duplex = DUPLEX_FULL;
2209 adapter->link_autoneg = AUTONEG_DISABLE;
2213 if (adapter->phy_read
2214 && adapter->phy_read(adapter,
2215 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
2217 if (netxen_get_phy_link(status)) {
2218 switch (netxen_get_phy_speed(status)) {
2220 adapter->link_speed = SPEED_10;
2223 adapter->link_speed = SPEED_100;
2226 adapter->link_speed = SPEED_1000;
2229 adapter->link_speed = 0;
2232 switch (netxen_get_phy_duplex(status)) {
2234 adapter->link_duplex = DUPLEX_HALF;
2237 adapter->link_duplex = DUPLEX_FULL;
2240 adapter->link_duplex = -1;
2243 if (adapter->phy_read
2244 && adapter->phy_read(adapter,
2245 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
2247 adapter->link_autoneg = autoneg;
2252 adapter->link_speed = 0;
2253 adapter->link_duplex = -1;
2258 void netxen_nic_flash_print(struct netxen_adapter *adapter)
2263 char brd_name[NETXEN_MAX_SHORT_NAME];
2264 char serial_num[32];
2268 struct netxen_board_info *board_info = &(adapter->ahw.boardcfg);
2270 adapter->driver_mismatch = 0;
2272 ptr32 = (int *)&serial_num;
2273 addr = NETXEN_USER_START +
2274 offsetof(struct netxen_new_user_info, serial_num);
2275 for (i = 0; i < 8; i++) {
2276 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
2277 printk("%s: ERROR reading %s board userarea.\n",
2278 netxen_nic_driver_name,
2279 netxen_nic_driver_name);
2280 adapter->driver_mismatch = 1;
2284 addr += sizeof(u32);
2287 adapter->hw_read_wx(adapter, NETXEN_FW_VERSION_MAJOR, &fw_major, 4);
2288 adapter->hw_read_wx(adapter, NETXEN_FW_VERSION_MINOR, &fw_minor, 4);
2289 adapter->hw_read_wx(adapter, NETXEN_FW_VERSION_SUB, &fw_build, 4);
2291 adapter->fw_major = fw_major;
2293 if (adapter->portnum == 0) {
2294 get_brd_name_by_type(board_info->board_type, brd_name);
2296 printk(KERN_INFO "NetXen %s Board S/N %s Chip rev 0x%x\n",
2297 brd_name, serial_num, adapter->ahw.revision_id);
2298 printk(KERN_INFO "NetXen Firmware version %d.%d.%d\n",
2299 fw_major, fw_minor, fw_build);
2302 if (NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build) <
2303 NETXEN_VERSION_CODE(3, 4, 216)) {
2304 adapter->driver_mismatch = 1;
2305 printk(KERN_ERR "%s: firmware version %d.%d.%d unsupported\n",
2306 netxen_nic_driver_name,
2307 fw_major, fw_minor, fw_build);