2 * Copyright (C) 2003 - 2006 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:
26 * 3965 Freedom Circle, Fourth floor,
27 * Santa Clara, CA 95054
30 * Source file for NIC routines to access the Phantom hardware
34 #include "netxen_nic.h"
35 #include "netxen_nic_hw.h"
36 #include "netxen_nic_phan_reg.h"
41 #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)
46 #define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
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)
54 #define CRB_WIN_LOCK_TIMEOUT 100000000
55 static 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 */
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 */
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 */
213 * top 12 bits of crb internal address (hub, agent)
215 static unsigned crb_hub_agt[64] =
218 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
219 NETXEN_HW_CRB_HUB_AGT_ADR_MN,
220 NETXEN_HW_CRB_HUB_AGT_ADR_MS,
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,
245 NETXEN_HW_CRB_HUB_AGT_ADR_PGSI,
246 NETXEN_HW_CRB_HUB_AGT_ADR_SN,
248 NETXEN_HW_CRB_HUB_AGT_ADR_EG,
250 NETXEN_HW_CRB_HUB_AGT_ADR_PS,
251 NETXEN_HW_CRB_HUB_AGT_ADR_CAM,
257 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
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,
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,
275 NETXEN_HW_CRB_HUB_AGT_ADR_SMB,
276 NETXEN_HW_CRB_HUB_AGT_ADR_I2C0,
277 NETXEN_HW_CRB_HUB_AGT_ADR_I2C1,
279 NETXEN_HW_CRB_HUB_AGT_ADR_PGNC,
283 /* PCI Windowing for DDR regions. */
285 #define ADDR_IN_RANGE(addr, low, high) \
286 (((addr) <= (high)) && ((addr) >= (low)))
288 #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
290 #define NETXEN_NIC_ZERO_PAUSE_ADDR 0ULL
291 #define NETXEN_NIC_UNIT_PAUSE_ADDR 0x200ULL
292 #define NETXEN_NIC_EPG_PAUSE_ADDR1 0x2200010000c28001ULL
293 #define NETXEN_NIC_EPG_PAUSE_ADDR2 0x0100088866554433ULL
295 #define NETXEN_NIC_WINDOW_MARGIN 0x100000
297 int netxen_nic_set_mac(struct net_device *netdev, void *p)
299 struct netxen_adapter *adapter = netdev_priv(netdev);
300 struct sockaddr *addr = p;
302 if (netif_running(netdev))
305 if (!is_valid_ether_addr(addr->sa_data))
306 return -EADDRNOTAVAIL;
308 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
310 /* For P3, MAC addr is not set in NIU */
311 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
312 if (adapter->macaddr_set)
313 adapter->macaddr_set(adapter, addr->sa_data);
318 #define NETXEN_UNICAST_ADDR(port, index) \
319 (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8))
320 #define NETXEN_MCAST_ADDR(port, index) \
321 (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8))
322 #define MAC_HI(addr) \
323 ((addr[2] << 16) | (addr[1] << 8) | (addr[0]))
324 #define MAC_LO(addr) \
325 ((addr[5] << 16) | (addr[4] << 8) | (addr[3]))
328 netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter)
331 u16 port = adapter->physical_port;
332 u8 *addr = adapter->netdev->dev_addr;
334 if (adapter->mc_enabled)
337 adapter->hw_read_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
338 val |= (1UL << (28+port));
339 adapter->hw_write_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
341 /* add broadcast addr to filter */
343 netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
344 netxen_crb_writelit_adapter(adapter,
345 NETXEN_UNICAST_ADDR(port, 0)+4, val);
347 /* add station addr to filter */
349 netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 1), val);
351 netxen_crb_writelit_adapter(adapter,
352 NETXEN_UNICAST_ADDR(port, 1)+4, val);
354 adapter->mc_enabled = 1;
359 netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter)
362 u16 port = adapter->physical_port;
363 u8 *addr = adapter->netdev->dev_addr;
365 if (!adapter->mc_enabled)
368 adapter->hw_read_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
369 val &= ~(1UL << (28+port));
370 adapter->hw_write_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
373 netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
375 netxen_crb_writelit_adapter(adapter,
376 NETXEN_UNICAST_ADDR(port, 0)+4, val);
378 netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 1), 0);
379 netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0);
381 adapter->mc_enabled = 0;
386 netxen_nic_set_mcast_addr(struct netxen_adapter *adapter,
390 u16 port = adapter->physical_port;
395 netxen_crb_writelit_adapter(adapter,
396 NETXEN_MCAST_ADDR(port, index), hi);
397 netxen_crb_writelit_adapter(adapter,
398 NETXEN_MCAST_ADDR(port, index)+4, lo);
403 void netxen_p2_nic_set_multi(struct net_device *netdev)
405 struct netxen_adapter *adapter = netdev_priv(netdev);
406 struct dev_mc_list *mc_ptr;
410 memset(null_addr, 0, 6);
412 if (netdev->flags & IFF_PROMISC) {
414 adapter->set_promisc(adapter,
415 NETXEN_NIU_PROMISC_MODE);
417 /* Full promiscuous mode */
418 netxen_nic_disable_mcast_filter(adapter);
423 if (netdev->mc_count == 0) {
424 adapter->set_promisc(adapter,
425 NETXEN_NIU_NON_PROMISC_MODE);
426 netxen_nic_disable_mcast_filter(adapter);
430 adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE);
431 if (netdev->flags & IFF_ALLMULTI ||
432 netdev->mc_count > adapter->max_mc_count) {
433 netxen_nic_disable_mcast_filter(adapter);
437 netxen_nic_enable_mcast_filter(adapter);
439 for (mc_ptr = netdev->mc_list; mc_ptr; mc_ptr = mc_ptr->next, index++)
440 netxen_nic_set_mcast_addr(adapter, index, mc_ptr->dmi_addr);
442 if (index != netdev->mc_count)
443 printk(KERN_WARNING "%s: %s multicast address count mismatch\n",
444 netxen_nic_driver_name, netdev->name);
446 /* Clear out remaining addresses */
447 for (; index < adapter->max_mc_count; index++)
448 netxen_nic_set_mcast_addr(adapter, index, null_addr);
451 static int nx_p3_nic_add_mac(struct netxen_adapter *adapter,
452 u8 *addr, nx_mac_list_t **add_list, nx_mac_list_t **del_list)
454 nx_mac_list_t *cur, *prev;
456 /* if in del_list, move it to adapter->mac_list */
457 for (cur = *del_list, prev = NULL; cur;) {
458 if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) {
460 *del_list = cur->next;
462 prev->next = cur->next;
463 cur->next = adapter->mac_list;
464 adapter->mac_list = cur;
471 /* make sure to add each mac address only once */
472 for (cur = adapter->mac_list; cur; cur = cur->next) {
473 if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0)
476 /* not in del_list, create new entry and add to add_list */
477 cur = kmalloc(sizeof(*cur), in_atomic()? GFP_ATOMIC : GFP_KERNEL);
479 printk(KERN_ERR "%s: cannot allocate memory. MAC filtering may"
480 "not work properly from now.\n", __func__);
484 memcpy(cur->mac_addr, addr, ETH_ALEN);
485 cur->next = *add_list;
491 netxen_send_cmd_descs(struct netxen_adapter *adapter,
492 struct cmd_desc_type0 *cmd_desc_arr, int nr_elements)
494 uint32_t i, producer;
495 struct netxen_cmd_buffer *pbuf;
496 struct cmd_desc_type0 *cmd_desc;
498 if (nr_elements > MAX_PENDING_DESC_BLOCK_SIZE || nr_elements == 0) {
499 printk(KERN_WARNING "%s: Too many command descriptors in a "
500 "request\n", __func__);
506 producer = adapter->cmd_producer;
508 cmd_desc = &cmd_desc_arr[i];
510 pbuf = &adapter->cmd_buf_arr[producer];
512 pbuf->total_length = 0;
515 pbuf->frag_count = 0;
518 /* adapter->ahw.cmd_desc_head[producer] = *cmd_desc; */
519 memcpy(&adapter->ahw.cmd_desc_head[producer],
520 &cmd_desc_arr[i], sizeof(struct cmd_desc_type0));
522 producer = get_next_index(producer,
523 adapter->max_tx_desc_count);
526 } while (i != nr_elements);
528 adapter->cmd_producer = producer;
530 /* write producer index to start the xmit */
532 netxen_nic_update_cmd_producer(adapter, adapter->cmd_producer);
537 static int nx_p3_sre_macaddr_change(struct net_device *dev,
538 u8 *addr, unsigned op)
540 struct netxen_adapter *adapter = (struct netxen_adapter *)dev->priv;
542 nx_mac_req_t mac_req;
545 memset(&req, 0, sizeof(nx_nic_req_t));
546 req.qhdr |= (NX_NIC_REQUEST << 23);
547 req.req_hdr |= NX_MAC_EVENT;
548 req.req_hdr |= ((u64)adapter->portnum << 16);
550 memcpy(&mac_req.mac_addr, addr, 6);
551 req.words[0] = cpu_to_le64(*(u64 *)&mac_req);
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)
616 memset(&req, 0, sizeof(nx_nic_req_t));
618 req.qhdr |= (NX_HOST_REQUEST << 23);
619 req.req_hdr |= NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE;
620 req.req_hdr |= ((u64)adapter->portnum << 16);
621 req.words[0] = cpu_to_le64(mode);
623 return netxen_send_cmd_descs(adapter,
624 (struct cmd_desc_type0 *)&req, 1);
627 #define NETXEN_CONFIG_INTR_COALESCE 3
630 * Send the interrupt coalescing parameter set by ethtool to the card.
632 int netxen_config_intr_coalesce(struct netxen_adapter *adapter)
637 memset(&req, 0, sizeof(nx_nic_req_t));
639 req.qhdr |= (NX_NIC_REQUEST << 23);
640 req.req_hdr |= NETXEN_CONFIG_INTR_COALESCE;
641 req.req_hdr |= ((u64)adapter->portnum << 16);
643 memcpy(&req.words[0], &adapter->coal, sizeof(adapter->coal));
645 rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
647 printk(KERN_ERR "ERROR. Could not send "
648 "interrupt coalescing parameters\n");
655 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
656 * @returns 0 on success, negative on failure
659 #define MTU_FUDGE_FACTOR 100
661 int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
663 struct netxen_adapter *adapter = netdev_priv(netdev);
667 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
668 max_mtu = P3_MAX_MTU;
670 max_mtu = P2_MAX_MTU;
673 printk(KERN_ERR "%s: mtu > %d bytes unsupported\n",
674 netdev->name, max_mtu);
678 if (adapter->set_mtu)
679 rc = adapter->set_mtu(adapter, mtu);
687 int netxen_is_flash_supported(struct netxen_adapter *adapter)
689 const int locs[] = { 0, 0x4, 0x100, 0x4000, 0x4128 };
690 int addr, val01, val02, i, j;
692 /* if the flash size less than 4Mb, make huge war cry and die */
693 for (j = 1; j < 4; j++) {
694 addr = j * NETXEN_NIC_WINDOW_MARGIN;
695 for (i = 0; i < ARRAY_SIZE(locs); i++) {
696 if (netxen_rom_fast_read(adapter, locs[i], &val01) == 0
697 && netxen_rom_fast_read(adapter, (addr + locs[i]),
709 static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
710 int size, __le32 * buf)
718 for (i = 0; i < size / sizeof(u32); i++) {
719 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
721 *ptr32 = cpu_to_le32(v);
725 if ((char *)buf + size > (char *)ptr32) {
727 if (netxen_rom_fast_read(adapter, addr, &v) == -1)
729 local = cpu_to_le32(v);
730 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
736 int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 mac[])
738 __le32 *pmac = (__le32 *) & mac[0];
740 if (netxen_get_flash_block(adapter,
742 offsetof(struct netxen_new_user_info,
744 FLASH_NUM_PORTS * sizeof(u64), pmac) == -1) {
747 if (*mac == cpu_to_le64(~0ULL)) {
748 if (netxen_get_flash_block(adapter,
749 NETXEN_USER_START_OLD +
750 offsetof(struct netxen_user_old_info,
752 FLASH_NUM_PORTS * sizeof(u64),
755 if (*mac == cpu_to_le64(~0ULL))
761 #define CRB_WIN_LOCK_TIMEOUT 100000000
763 static int crb_win_lock(struct netxen_adapter *adapter)
765 int done = 0, timeout = 0;
768 /* acquire semaphore3 from PCI HW block */
769 adapter->hw_read_wx(adapter,
770 NETXEN_PCIE_REG(PCIE_SEM7_LOCK), &done, 4);
773 if (timeout >= CRB_WIN_LOCK_TIMEOUT)
778 netxen_crb_writelit_adapter(adapter,
779 NETXEN_CRB_WIN_LOCK_ID, adapter->portnum);
783 static void crb_win_unlock(struct netxen_adapter *adapter)
787 adapter->hw_read_wx(adapter,
788 NETXEN_PCIE_REG(PCIE_SEM7_UNLOCK), &val, 4);
792 * Changes the CRB window to the specified window.
795 netxen_nic_pci_change_crbwindow_128M(struct netxen_adapter *adapter, u32 wndw)
797 void __iomem *offset;
800 uint8_t func = adapter->ahw.pci_func;
802 if (adapter->curr_window == wndw)
805 * Move the CRB window.
806 * We need to write to the "direct access" region of PCI
807 * to avoid a race condition where the window register has
808 * not been successfully written across CRB before the target
809 * register address is received by PCI. The direct region bypasses
812 offset = PCI_OFFSET_SECOND_RANGE(adapter,
813 NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
816 wndw = NETXEN_WINDOW_ONE;
818 writel(wndw, offset);
820 /* MUST make sure window is set before we forge on... */
821 while ((tmp = readl(offset)) != wndw) {
822 printk(KERN_WARNING "%s: %s WARNING: CRB window value not "
823 "registered properly: 0x%08x.\n",
824 netxen_nic_driver_name, __func__, tmp);
831 if (wndw == NETXEN_WINDOW_ONE)
832 adapter->curr_window = 1;
834 adapter->curr_window = 0;
838 * Return -1 if off is not valid,
839 * 1 if window access is needed. 'off' is set to offset from
840 * CRB space in 128M pci map
841 * 0 if no window access is needed. 'off' is set to 2M addr
842 * In: 'off' is offset from base in 128M pci map
845 netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter,
848 unsigned long end = *off + len;
849 crb_128M_2M_sub_block_map_t *m;
852 if (*off >= NETXEN_CRB_MAX)
855 if (*off >= NETXEN_PCI_CAMQM && (end <= NETXEN_PCI_CAMQM_2M_END)) {
856 *off = (*off - NETXEN_PCI_CAMQM) + NETXEN_PCI_CAMQM_2M_BASE +
857 (ulong)adapter->ahw.pci_base0;
861 if (*off < NETXEN_PCI_CRBSPACE)
864 *off -= NETXEN_PCI_CRBSPACE;
870 m = &crb_128M_2M_map[CRB_BLK(*off)].sub_block[CRB_SUBBLK(*off)];
872 if (m->valid && (m->start_128M <= *off) && (m->end_128M >= end)) {
873 *off = *off + m->start_2M - m->start_128M +
874 (ulong)adapter->ahw.pci_base0;
879 * Not in direct map, use crb window
885 * In: 'off' is offset from CRB space in 128M pci map
886 * Out: 'off' is 2M pci map addr
887 * side effect: lock crb window
890 netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong *off)
894 adapter->crb_win = CRB_HI(*off);
895 writel(adapter->crb_win, (void *)(CRB_WINDOW_2M +
896 adapter->ahw.pci_base0));
898 * Read back value to make sure write has gone through before trying
901 win_read = readl((void *)(CRB_WINDOW_2M + adapter->ahw.pci_base0));
902 if (win_read != adapter->crb_win) {
903 printk(KERN_ERR "%s: Written crbwin (0x%x) != "
904 "Read crbwin (0x%x), off=0x%lx\n",
905 __func__, adapter->crb_win, win_read, *off);
907 *off = (*off & MASK(16)) + CRB_INDIRECT_2M +
908 (ulong)adapter->ahw.pci_base0;
911 int netxen_load_firmware(struct netxen_adapter *adapter)
915 u32 flashaddr = NETXEN_BOOTLD_START, memaddr = NETXEN_BOOTLD_START;
917 size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START)/4;
919 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
920 adapter->pci_write_normalize(adapter,
921 NETXEN_ROMUSB_GLB_CAS_RST, 1);
923 for (i = 0; i < size; i++) {
924 if (netxen_rom_fast_read(adapter, flashaddr, (int *)&data) != 0)
927 adapter->pci_mem_write(adapter, memaddr, &data, 4);
934 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
935 adapter->pci_write_normalize(adapter,
936 NETXEN_ROMUSB_GLB_SW_RESET, 0x80001d);
938 adapter->pci_write_normalize(adapter,
939 NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL, 0x3fff);
940 adapter->pci_write_normalize(adapter,
941 NETXEN_ROMUSB_GLB_CAS_RST, 0);
948 netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter,
949 ulong off, void *data, int len)
953 if (ADDR_IN_WINDOW1(off)) {
954 addr = NETXEN_CRB_NORMALIZE(adapter, off);
955 } else { /* Window 0 */
956 addr = pci_base_offset(adapter, off);
957 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
960 DPRINTK(INFO, "writing to base %lx offset %llx addr %p"
961 " data %llx len %d\n",
962 pci_base(adapter, off), off, addr,
963 *(unsigned long long *)data, len);
965 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
971 writeb(*(u8 *) data, addr);
974 writew(*(u16 *) data, addr);
977 writel(*(u32 *) data, addr);
980 writeq(*(u64 *) data, addr);
984 "writing data %lx to offset %llx, num words=%d\n",
985 *(unsigned long *)data, off, (len >> 3));
987 netxen_nic_hw_block_write64((u64 __iomem *) data, addr,
991 if (!ADDR_IN_WINDOW1(off))
992 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
998 netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter,
999 ulong off, void *data, int len)
1003 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
1004 addr = NETXEN_CRB_NORMALIZE(adapter, off);
1005 } else { /* Window 0 */
1006 addr = pci_base_offset(adapter, off);
1007 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1010 DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n",
1011 pci_base(adapter, off), off, addr);
1013 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1018 *(u8 *) data = readb(addr);
1021 *(u16 *) data = readw(addr);
1024 *(u32 *) data = readl(addr);
1027 *(u64 *) data = readq(addr);
1030 netxen_nic_hw_block_read64((u64 __iomem *) data, addr,
1034 DPRINTK(INFO, "read %lx\n", *(unsigned long *)data);
1036 if (!ADDR_IN_WINDOW1(off))
1037 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1043 netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter,
1044 ulong off, void *data, int len)
1046 unsigned long flags = 0;
1049 rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off, len);
1052 printk(KERN_ERR "%s: invalid offset: 0x%016lx\n",
1059 write_lock_irqsave(&adapter->adapter_lock, flags);
1060 crb_win_lock(adapter);
1061 netxen_nic_pci_set_crbwindow_2M(adapter, &off);
1064 DPRINTK(1, INFO, "write data %lx to offset %llx, len=%d\n",
1065 *(unsigned long *)data, off, len);
1069 writeb(*(uint8_t *)data, (void *)off);
1072 writew(*(uint16_t *)data, (void *)off);
1075 writel(*(uint32_t *)data, (void *)off);
1078 writeq(*(uint64_t *)data, (void *)off);
1082 "writing data %lx to offset %llx, num words=%d\n",
1083 *(unsigned long *)data, off, (len>>3));
1087 crb_win_unlock(adapter);
1088 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1095 netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter,
1096 ulong off, void *data, int len)
1098 unsigned long flags = 0;
1101 rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off, len);
1104 printk(KERN_ERR "%s: invalid offset: 0x%016lx\n",
1111 write_lock_irqsave(&adapter->adapter_lock, flags);
1112 crb_win_lock(adapter);
1113 netxen_nic_pci_set_crbwindow_2M(adapter, &off);
1116 DPRINTK(1, INFO, "read from offset %lx, len=%d\n", off, len);
1120 *(uint8_t *)data = readb((void *)off);
1123 *(uint16_t *)data = readw((void *)off);
1126 *(uint32_t *)data = readl((void *)off);
1129 *(uint64_t *)data = readq((void *)off);
1135 DPRINTK(1, INFO, "read %lx\n", *(unsigned long *)data);
1138 crb_win_unlock(adapter);
1139 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1145 void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val)
1147 adapter->hw_write_wx(adapter, off, &val, 4);
1150 int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off)
1153 adapter->hw_read_wx(adapter, off, &val, 4);
1157 /* Change the window to 0, write and change back to window 1. */
1158 void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value)
1160 adapter->hw_write_wx(adapter, index, &value, 4);
1163 /* Change the window to 0, read and change back to window 1. */
1164 void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 *value)
1166 adapter->hw_read_wx(adapter, index, value, 4);
1169 void netxen_nic_write_w1(struct netxen_adapter *adapter, u32 index, u32 value)
1171 adapter->hw_write_wx(adapter, index, &value, 4);
1174 void netxen_nic_read_w1(struct netxen_adapter *adapter, u32 index, u32 *value)
1176 adapter->hw_read_wx(adapter, index, value, 4);
1180 * check memory access boundary.
1181 * used by test agent. support ddr access only for now
1183 static unsigned long
1184 netxen_nic_pci_mem_bound_check(struct netxen_adapter *adapter,
1185 unsigned long long addr, int size)
1187 if (!ADDR_IN_RANGE(addr,
1188 NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX) ||
1189 !ADDR_IN_RANGE(addr+size-1,
1190 NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX) ||
1191 ((size != 1) && (size != 2) && (size != 4) && (size != 8))) {
1198 static int netxen_pci_set_window_warning_count;
1201 netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
1202 unsigned long long addr)
1204 void __iomem *offset;
1206 unsigned long long qdr_max;
1207 uint8_t func = adapter->ahw.pci_func;
1209 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1210 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P2;
1212 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P3;
1215 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1216 /* DDR network side */
1217 addr -= NETXEN_ADDR_DDR_NET;
1218 window = (addr >> 25) & 0x3ff;
1219 if (adapter->ahw.ddr_mn_window != window) {
1220 adapter->ahw.ddr_mn_window = window;
1221 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1222 NETXEN_PCIX_PH_REG(PCIE_MN_WINDOW_REG(func)));
1223 writel(window, offset);
1224 /* MUST make sure window is set before we forge on... */
1227 addr -= (window * NETXEN_WINDOW_ONE);
1228 addr += NETXEN_PCI_DDR_NET;
1229 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1230 addr -= NETXEN_ADDR_OCM0;
1231 addr += NETXEN_PCI_OCM0;
1232 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1233 addr -= NETXEN_ADDR_OCM1;
1234 addr += NETXEN_PCI_OCM1;
1235 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_QDR_NET, qdr_max)) {
1236 /* QDR network side */
1237 addr -= NETXEN_ADDR_QDR_NET;
1238 window = (addr >> 22) & 0x3f;
1239 if (adapter->ahw.qdr_sn_window != window) {
1240 adapter->ahw.qdr_sn_window = window;
1241 offset = PCI_OFFSET_SECOND_RANGE(adapter,
1242 NETXEN_PCIX_PH_REG(PCIE_SN_WINDOW_REG(func)));
1243 writel((window << 22), offset);
1244 /* MUST make sure window is set before we forge on... */
1247 addr -= (window * 0x400000);
1248 addr += NETXEN_PCI_QDR_NET;
1251 * peg gdb frequently accesses memory that doesn't exist,
1252 * this limits the chit chat so debugging isn't slowed down.
1254 if ((netxen_pci_set_window_warning_count++ < 8)
1255 || (netxen_pci_set_window_warning_count % 64 == 0))
1256 printk("%s: Warning:netxen_nic_pci_set_window()"
1257 " Unknown address range!\n",
1258 netxen_nic_driver_name);
1265 * Note : only 32-bit writes!
1267 int netxen_nic_pci_write_immediate_128M(struct netxen_adapter *adapter,
1270 writel(data, (void __iomem *)(PCI_OFFSET_SECOND_RANGE(adapter, off)));
1274 u32 netxen_nic_pci_read_immediate_128M(struct netxen_adapter *adapter, u64 off)
1276 return readl((void __iomem *)(pci_base_offset(adapter, off)));
1279 void netxen_nic_pci_write_normalize_128M(struct netxen_adapter *adapter,
1282 writel(data, NETXEN_CRB_NORMALIZE(adapter, off));
1285 u32 netxen_nic_pci_read_normalize_128M(struct netxen_adapter *adapter, u64 off)
1287 return readl(NETXEN_CRB_NORMALIZE(adapter, off));
1291 netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
1292 unsigned long long addr)
1297 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1298 /* DDR network side */
1299 window = MN_WIN(addr);
1300 adapter->ahw.ddr_mn_window = window;
1301 adapter->hw_write_wx(adapter,
1302 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
1304 adapter->hw_read_wx(adapter,
1305 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
1307 if ((win_read << 17) != window) {
1308 printk(KERN_INFO "Written MNwin (0x%x) != "
1309 "Read MNwin (0x%x)\n", window, win_read);
1311 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_DDR_NET;
1312 } else if (ADDR_IN_RANGE(addr,
1313 NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1314 if ((addr & 0x00ff800) == 0xff800) {
1315 printk("%s: QM access not handled.\n", __func__);
1319 window = OCM_WIN(addr);
1320 adapter->ahw.ddr_mn_window = window;
1321 adapter->hw_write_wx(adapter,
1322 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
1324 adapter->hw_read_wx(adapter,
1325 adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
1327 if ((win_read >> 7) != window) {
1328 printk(KERN_INFO "%s: Written OCMwin (0x%x) != "
1329 "Read OCMwin (0x%x)\n",
1330 __func__, window, win_read);
1332 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_OCM0_2M;
1334 } else if (ADDR_IN_RANGE(addr,
1335 NETXEN_ADDR_QDR_NET, NETXEN_ADDR_QDR_NET_MAX_P3)) {
1336 /* QDR network side */
1337 window = MS_WIN(addr);
1338 adapter->ahw.qdr_sn_window = window;
1339 adapter->hw_write_wx(adapter,
1340 adapter->ahw.ms_win_crb | NETXEN_PCI_CRBSPACE,
1342 adapter->hw_read_wx(adapter,
1343 adapter->ahw.ms_win_crb | NETXEN_PCI_CRBSPACE,
1345 if (win_read != window) {
1346 printk(KERN_INFO "%s: Written MSwin (0x%x) != "
1347 "Read MSwin (0x%x)\n",
1348 __func__, window, win_read);
1350 addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_QDR_NET;
1354 * peg gdb frequently accesses memory that doesn't exist,
1355 * this limits the chit chat so debugging isn't slowed down.
1357 if ((netxen_pci_set_window_warning_count++ < 8)
1358 || (netxen_pci_set_window_warning_count%64 == 0)) {
1359 printk("%s: Warning:%s Unknown address range!\n",
1360 __func__, netxen_nic_driver_name);
1367 static int netxen_nic_pci_is_same_window(struct netxen_adapter *adapter,
1368 unsigned long long addr)
1371 unsigned long long qdr_max;
1373 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
1374 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P2;
1376 qdr_max = NETXEN_ADDR_QDR_NET_MAX_P3;
1378 if (ADDR_IN_RANGE(addr,
1379 NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
1380 /* DDR network side */
1381 BUG(); /* MN access can not come here */
1382 } else if (ADDR_IN_RANGE(addr,
1383 NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
1385 } else if (ADDR_IN_RANGE(addr,
1386 NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
1388 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_QDR_NET, qdr_max)) {
1389 /* QDR network side */
1390 window = ((addr - NETXEN_ADDR_QDR_NET) >> 22) & 0x3f;
1391 if (adapter->ahw.qdr_sn_window == window)
1398 static int netxen_nic_pci_mem_read_direct(struct netxen_adapter *adapter,
1399 u64 off, void *data, int size)
1401 unsigned long flags;
1405 uint8_t *mem_ptr = NULL;
1406 unsigned long mem_base;
1407 unsigned long mem_page;
1409 write_lock_irqsave(&adapter->adapter_lock, flags);
1412 * If attempting to access unknown address or straddle hw windows,
1415 start = adapter->pci_set_window(adapter, off);
1416 if ((start == -1UL) ||
1417 (netxen_nic_pci_is_same_window(adapter, off+size-1) == 0)) {
1418 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1419 printk(KERN_ERR "%s out of bound pci memory access. "
1420 "offset is 0x%llx\n", netxen_nic_driver_name,
1421 (unsigned long long)off);
1425 addr = (void *)(pci_base_offset(adapter, start));
1427 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1428 mem_base = pci_resource_start(adapter->pdev, 0);
1429 mem_page = start & PAGE_MASK;
1430 /* Map two pages whenever user tries to access addresses in two
1433 if (mem_page != ((start + size - 1) & PAGE_MASK))
1434 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1436 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
1437 if (mem_ptr == 0UL) {
1438 *(uint8_t *)data = 0;
1442 addr += start & (PAGE_SIZE - 1);
1443 write_lock_irqsave(&adapter->adapter_lock, flags);
1448 *(uint8_t *)data = readb(addr);
1451 *(uint16_t *)data = readw(addr);
1454 *(uint32_t *)data = readl(addr);
1457 *(uint64_t *)data = readq(addr);
1463 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1464 DPRINTK(1, INFO, "read %llx\n", *(unsigned long long *)data);
1472 netxen_nic_pci_mem_write_direct(struct netxen_adapter *adapter, u64 off,
1473 void *data, int size)
1475 unsigned long flags;
1479 uint8_t *mem_ptr = NULL;
1480 unsigned long mem_base;
1481 unsigned long mem_page;
1483 write_lock_irqsave(&adapter->adapter_lock, flags);
1486 * If attempting to access unknown address or straddle hw windows,
1489 start = adapter->pci_set_window(adapter, off);
1490 if ((start == -1UL) ||
1491 (netxen_nic_pci_is_same_window(adapter, off+size-1) == 0)) {
1492 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1493 printk(KERN_ERR "%s out of bound pci memory access. "
1494 "offset is 0x%llx\n", netxen_nic_driver_name,
1495 (unsigned long long)off);
1499 addr = (void *)(pci_base_offset(adapter, start));
1501 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1502 mem_base = pci_resource_start(adapter->pdev, 0);
1503 mem_page = start & PAGE_MASK;
1504 /* Map two pages whenever user tries to access addresses in two
1505 * consecutive pages.
1507 if (mem_page != ((start + size - 1) & PAGE_MASK))
1508 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE*2);
1510 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
1514 addr += start & (PAGE_SIZE - 1);
1515 write_lock_irqsave(&adapter->adapter_lock, flags);
1520 writeb(*(uint8_t *)data, addr);
1523 writew(*(uint16_t *)data, addr);
1526 writel(*(uint32_t *)data, addr);
1529 writeq(*(uint64_t *)data, addr);
1535 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1536 DPRINTK(1, INFO, "writing data %llx to offset %llx\n",
1537 *(unsigned long long *)data, start);
1543 #define MAX_CTL_CHECK 1000
1546 netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
1547 u64 off, void *data, int size)
1549 unsigned long flags, mem_crb;
1550 int i, j, ret = 0, loop, sz[2], off0;
1552 uint64_t off8, tmpw, word[2] = {0, 0};
1555 * If not MN, go check for MS or invalid.
1557 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1558 return netxen_nic_pci_mem_write_direct(adapter,
1561 off8 = off & 0xfffffff8;
1563 sz[0] = (size < (8 - off0)) ? size : (8 - off0);
1564 sz[1] = size - sz[0];
1565 loop = ((off0 + size - 1) >> 3) + 1;
1566 mem_crb = (unsigned long)pci_base_offset(adapter, NETXEN_CRB_DDR_NET);
1568 if ((size != 8) || (off0 != 0)) {
1569 for (i = 0; i < loop; i++) {
1570 if (adapter->pci_mem_read(adapter,
1571 off8 + (i << 3), &word[i], 8))
1578 tmpw = *((uint8_t *)data);
1581 tmpw = *((uint16_t *)data);
1584 tmpw = *((uint32_t *)data);
1588 tmpw = *((uint64_t *)data);
1591 word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
1592 word[0] |= tmpw << (off0 * 8);
1595 word[1] &= ~(~0ULL << (sz[1] * 8));
1596 word[1] |= tmpw >> (sz[0] * 8);
1599 write_lock_irqsave(&adapter->adapter_lock, flags);
1600 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1602 for (i = 0; i < loop; i++) {
1603 writel((uint32_t)(off8 + (i << 3)),
1604 (void *)(mem_crb+MIU_TEST_AGT_ADDR_LO));
1606 (void *)(mem_crb+MIU_TEST_AGT_ADDR_HI));
1607 writel(word[i] & 0xffffffff,
1608 (void *)(mem_crb+MIU_TEST_AGT_WRDATA_LO));
1609 writel((word[i] >> 32) & 0xffffffff,
1610 (void *)(mem_crb+MIU_TEST_AGT_WRDATA_HI));
1611 writel(MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE,
1612 (void *)(mem_crb+MIU_TEST_AGT_CTRL));
1613 writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE,
1614 (void *)(mem_crb+MIU_TEST_AGT_CTRL));
1616 for (j = 0; j < MAX_CTL_CHECK; j++) {
1618 (void *)(mem_crb+MIU_TEST_AGT_CTRL));
1619 if ((temp & MIU_TA_CTL_BUSY) == 0)
1623 if (j >= MAX_CTL_CHECK) {
1624 printk("%s: %s Fail to write through agent\n",
1625 __func__, netxen_nic_driver_name);
1631 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1632 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1637 netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
1638 u64 off, void *data, int size)
1640 unsigned long flags, mem_crb;
1641 int i, j = 0, k, start, end, loop, sz[2], off0[2];
1643 uint64_t off8, val, word[2] = {0, 0};
1647 * If not MN, go check for MS or invalid.
1649 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1650 return netxen_nic_pci_mem_read_direct(adapter, off, data, size);
1652 off8 = off & 0xfffffff8;
1653 off0[0] = off & 0x7;
1655 sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]);
1656 sz[1] = size - sz[0];
1657 loop = ((off0[0] + size - 1) >> 3) + 1;
1658 mem_crb = (unsigned long)pci_base_offset(adapter, NETXEN_CRB_DDR_NET);
1660 write_lock_irqsave(&adapter->adapter_lock, flags);
1661 netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1663 for (i = 0; i < loop; i++) {
1664 writel((uint32_t)(off8 + (i << 3)),
1665 (void *)(mem_crb+MIU_TEST_AGT_ADDR_LO));
1667 (void *)(mem_crb+MIU_TEST_AGT_ADDR_HI));
1668 writel(MIU_TA_CTL_ENABLE,
1669 (void *)(mem_crb+MIU_TEST_AGT_CTRL));
1670 writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE,
1671 (void *)(mem_crb+MIU_TEST_AGT_CTRL));
1673 for (j = 0; j < MAX_CTL_CHECK; j++) {
1675 (void *)(mem_crb+MIU_TEST_AGT_CTRL));
1676 if ((temp & MIU_TA_CTL_BUSY) == 0)
1680 if (j >= MAX_CTL_CHECK) {
1681 printk(KERN_ERR "%s: %s Fail to read through agent\n",
1682 __func__, netxen_nic_driver_name);
1686 start = off0[i] >> 2;
1687 end = (off0[i] + sz[i] - 1) >> 2;
1688 for (k = start; k <= end; k++) {
1689 word[i] |= ((uint64_t) readl(
1691 MIU_TEST_AGT_RDDATA(k))) << (32*k));
1695 netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1696 write_unlock_irqrestore(&adapter->adapter_lock, flags);
1698 if (j >= MAX_CTL_CHECK)
1704 val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
1705 ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
1710 *(uint8_t *)data = val;
1713 *(uint16_t *)data = val;
1716 *(uint32_t *)data = val;
1719 *(uint64_t *)data = val;
1722 DPRINTK(1, INFO, "read %llx\n", *(unsigned long long *)data);
1727 netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
1728 u64 off, void *data, int size)
1730 int i, j, ret = 0, loop, sz[2], off0;
1732 uint64_t off8, mem_crb, tmpw, word[2] = {0, 0};
1735 * If not MN, go check for MS or invalid.
1737 if (off >= NETXEN_ADDR_QDR_NET && off <= NETXEN_ADDR_QDR_NET_MAX_P3)
1738 mem_crb = NETXEN_CRB_QDR_NET;
1740 mem_crb = NETXEN_CRB_DDR_NET;
1741 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1742 return netxen_nic_pci_mem_write_direct(adapter,
1746 off8 = off & 0xfffffff8;
1748 sz[0] = (size < (8 - off0)) ? size : (8 - off0);
1749 sz[1] = size - sz[0];
1750 loop = ((off0 + size - 1) >> 3) + 1;
1752 if ((size != 8) || (off0 != 0)) {
1753 for (i = 0; i < loop; i++) {
1754 if (adapter->pci_mem_read(adapter, off8 + (i << 3),
1762 tmpw = *((uint8_t *)data);
1765 tmpw = *((uint16_t *)data);
1768 tmpw = *((uint32_t *)data);
1772 tmpw = *((uint64_t *)data);
1776 word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
1777 word[0] |= tmpw << (off0 * 8);
1780 word[1] &= ~(~0ULL << (sz[1] * 8));
1781 word[1] |= tmpw >> (sz[0] * 8);
1785 * don't lock here - write_wx gets the lock if each time
1786 * write_lock_irqsave(&adapter->adapter_lock, flags);
1787 * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1790 for (i = 0; i < loop; i++) {
1791 temp = off8 + (i << 3);
1792 adapter->hw_write_wx(adapter,
1793 mem_crb+MIU_TEST_AGT_ADDR_LO, &temp, 4);
1795 adapter->hw_write_wx(adapter,
1796 mem_crb+MIU_TEST_AGT_ADDR_HI, &temp, 4);
1797 temp = word[i] & 0xffffffff;
1798 adapter->hw_write_wx(adapter,
1799 mem_crb+MIU_TEST_AGT_WRDATA_LO, &temp, 4);
1800 temp = (word[i] >> 32) & 0xffffffff;
1801 adapter->hw_write_wx(adapter,
1802 mem_crb+MIU_TEST_AGT_WRDATA_HI, &temp, 4);
1803 temp = MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE;
1804 adapter->hw_write_wx(adapter,
1805 mem_crb+MIU_TEST_AGT_CTRL, &temp, 4);
1806 temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE;
1807 adapter->hw_write_wx(adapter,
1808 mem_crb+MIU_TEST_AGT_CTRL, &temp, 4);
1810 for (j = 0; j < MAX_CTL_CHECK; j++) {
1811 adapter->hw_read_wx(adapter,
1812 mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
1813 if ((temp & MIU_TA_CTL_BUSY) == 0)
1817 if (j >= MAX_CTL_CHECK) {
1818 printk(KERN_ERR "%s: Fail to write through agent\n",
1819 netxen_nic_driver_name);
1826 * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1827 * write_unlock_irqrestore(&adapter->adapter_lock, flags);
1833 netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
1834 u64 off, void *data, int size)
1836 int i, j = 0, k, start, end, loop, sz[2], off0[2];
1838 uint64_t off8, val, mem_crb, word[2] = {0, 0};
1841 * If not MN, go check for MS or invalid.
1844 if (off >= NETXEN_ADDR_QDR_NET && off <= NETXEN_ADDR_QDR_NET_MAX_P3)
1845 mem_crb = NETXEN_CRB_QDR_NET;
1847 mem_crb = NETXEN_CRB_DDR_NET;
1848 if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
1849 return netxen_nic_pci_mem_read_direct(adapter,
1853 off8 = off & 0xfffffff8;
1854 off0[0] = off & 0x7;
1856 sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]);
1857 sz[1] = size - sz[0];
1858 loop = ((off0[0] + size - 1) >> 3) + 1;
1861 * don't lock here - write_wx gets the lock if each time
1862 * write_lock_irqsave(&adapter->adapter_lock, flags);
1863 * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1866 for (i = 0; i < loop; i++) {
1867 temp = off8 + (i << 3);
1868 adapter->hw_write_wx(adapter,
1869 mem_crb + MIU_TEST_AGT_ADDR_LO, &temp, 4);
1871 adapter->hw_write_wx(adapter,
1872 mem_crb + MIU_TEST_AGT_ADDR_HI, &temp, 4);
1873 temp = MIU_TA_CTL_ENABLE;
1874 adapter->hw_write_wx(adapter,
1875 mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
1876 temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE;
1877 adapter->hw_write_wx(adapter,
1878 mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
1880 for (j = 0; j < MAX_CTL_CHECK; j++) {
1881 adapter->hw_read_wx(adapter,
1882 mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
1883 if ((temp & MIU_TA_CTL_BUSY) == 0)
1887 if (j >= MAX_CTL_CHECK) {
1888 printk(KERN_ERR "%s: Fail to read through agent\n",
1889 netxen_nic_driver_name);
1893 start = off0[i] >> 2;
1894 end = (off0[i] + sz[i] - 1) >> 2;
1895 for (k = start; k <= end; k++) {
1896 adapter->hw_read_wx(adapter,
1897 mem_crb + MIU_TEST_AGT_RDDATA(k), &temp, 4);
1898 word[i] |= ((uint64_t)temp << (32 * k));
1903 * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1904 * write_unlock_irqrestore(&adapter->adapter_lock, flags);
1907 if (j >= MAX_CTL_CHECK)
1913 val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
1914 ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
1919 *(uint8_t *)data = val;
1922 *(uint16_t *)data = val;
1925 *(uint32_t *)data = val;
1928 *(uint64_t *)data = val;
1931 DPRINTK(1, INFO, "read %llx\n", *(unsigned long long *)data);
1936 * Note : only 32-bit writes!
1938 int netxen_nic_pci_write_immediate_2M(struct netxen_adapter *adapter,
1941 adapter->hw_write_wx(adapter, off, &data, 4);
1946 u32 netxen_nic_pci_read_immediate_2M(struct netxen_adapter *adapter, u64 off)
1949 adapter->hw_read_wx(adapter, off, &temp, 4);
1953 void netxen_nic_pci_write_normalize_2M(struct netxen_adapter *adapter,
1956 adapter->hw_write_wx(adapter, off, &data, 4);
1959 u32 netxen_nic_pci_read_normalize_2M(struct netxen_adapter *adapter, u64 off)
1962 adapter->hw_read_wx(adapter, off, &temp, 4);
1968 netxen_nic_erase_pxe(struct netxen_adapter *adapter)
1970 if (netxen_rom_fast_write(adapter, NETXEN_PXE_START, 0) == -1) {
1971 printk(KERN_ERR "%s: erase pxe failed\n",
1972 netxen_nic_driver_name);
1979 int netxen_nic_get_board_info(struct netxen_adapter *adapter)
1982 int addr = NETXEN_BRDCFG_START;
1983 struct netxen_board_info *boardinfo;
1987 boardinfo = &adapter->ahw.boardcfg;
1988 ptr32 = (u32 *) boardinfo;
1990 for (index = 0; index < sizeof(struct netxen_board_info) / sizeof(u32);
1992 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
1996 addr += sizeof(u32);
1998 if (boardinfo->magic != NETXEN_BDINFO_MAGIC) {
1999 printk("%s: ERROR reading %s board config."
2000 " Read %x, expected %x\n", netxen_nic_driver_name,
2001 netxen_nic_driver_name,
2002 boardinfo->magic, NETXEN_BDINFO_MAGIC);
2005 if (boardinfo->header_version != NETXEN_BDINFO_VERSION) {
2006 printk("%s: Unknown board config version."
2007 " Read %x, expected %x\n", netxen_nic_driver_name,
2008 boardinfo->header_version, NETXEN_BDINFO_VERSION);
2012 DPRINTK(INFO, "Discovered board type:0x%x ", boardinfo->board_type);
2013 switch ((netxen_brdtype_t) boardinfo->board_type) {
2014 case NETXEN_BRDTYPE_P2_SB35_4G:
2015 adapter->ahw.board_type = NETXEN_NIC_GBE;
2017 case NETXEN_BRDTYPE_P2_SB31_10G:
2018 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
2019 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
2020 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
2021 case NETXEN_BRDTYPE_P3_HMEZ:
2022 case NETXEN_BRDTYPE_P3_XG_LOM:
2023 case NETXEN_BRDTYPE_P3_10G_CX4:
2024 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
2025 case NETXEN_BRDTYPE_P3_IMEZ:
2026 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
2027 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
2028 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
2029 case NETXEN_BRDTYPE_P3_10G_XFP:
2030 case NETXEN_BRDTYPE_P3_10000_BASE_T:
2032 adapter->ahw.board_type = NETXEN_NIC_XGBE;
2034 case NETXEN_BRDTYPE_P1_BD:
2035 case NETXEN_BRDTYPE_P1_SB:
2036 case NETXEN_BRDTYPE_P1_SMAX:
2037 case NETXEN_BRDTYPE_P1_SOCK:
2038 case NETXEN_BRDTYPE_P3_REF_QG:
2039 case NETXEN_BRDTYPE_P3_4_GB:
2040 case NETXEN_BRDTYPE_P3_4_GB_MM:
2042 adapter->ahw.board_type = NETXEN_NIC_GBE;
2045 printk("%s: Unknown(%x)\n", netxen_nic_driver_name,
2046 boardinfo->board_type);
2054 /* NIU access sections */
2056 int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu)
2058 new_mtu += MTU_FUDGE_FACTOR;
2059 netxen_nic_write_w0(adapter,
2060 NETXEN_NIU_GB_MAX_FRAME_SIZE(adapter->physical_port),
2065 int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
2067 new_mtu += MTU_FUDGE_FACTOR;
2068 if (adapter->physical_port == 0)
2069 netxen_nic_write_w0(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE,
2072 netxen_nic_write_w0(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE,
2078 netxen_crb_writelit_adapter(struct netxen_adapter *adapter,
2079 unsigned long off, int data)
2081 adapter->hw_write_wx(adapter, off, &data, 4);
2084 void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
2091 netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode);
2092 if (netxen_get_niu_enable_ge(mode)) { /* Gb 10/100/1000 Mbps mode */
2094 adapter->hw_read_wx(adapter,
2095 NETXEN_PORT_MODE_ADDR, &port_mode, 4);
2096 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
2097 adapter->link_speed = SPEED_1000;
2098 adapter->link_duplex = DUPLEX_FULL;
2099 adapter->link_autoneg = AUTONEG_DISABLE;
2103 if (adapter->phy_read
2104 && adapter->phy_read(adapter,
2105 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
2107 if (netxen_get_phy_link(status)) {
2108 switch (netxen_get_phy_speed(status)) {
2110 adapter->link_speed = SPEED_10;
2113 adapter->link_speed = SPEED_100;
2116 adapter->link_speed = SPEED_1000;
2119 adapter->link_speed = -1;
2122 switch (netxen_get_phy_duplex(status)) {
2124 adapter->link_duplex = DUPLEX_HALF;
2127 adapter->link_duplex = DUPLEX_FULL;
2130 adapter->link_duplex = -1;
2133 if (adapter->phy_read
2134 && adapter->phy_read(adapter,
2135 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
2137 adapter->link_autoneg = autoneg;
2142 adapter->link_speed = -1;
2143 adapter->link_duplex = -1;
2148 void netxen_nic_flash_print(struct netxen_adapter *adapter)
2153 char brd_name[NETXEN_MAX_SHORT_NAME];
2154 char serial_num[32];
2158 struct netxen_board_info *board_info = &(adapter->ahw.boardcfg);
2160 adapter->driver_mismatch = 0;
2162 ptr32 = (u32 *)&serial_num;
2163 addr = NETXEN_USER_START +
2164 offsetof(struct netxen_new_user_info, serial_num);
2165 for (i = 0; i < 8; i++) {
2166 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
2167 printk("%s: ERROR reading %s board userarea.\n",
2168 netxen_nic_driver_name,
2169 netxen_nic_driver_name);
2170 adapter->driver_mismatch = 1;
2174 addr += sizeof(u32);
2177 adapter->hw_read_wx(adapter, NETXEN_FW_VERSION_MAJOR, &fw_major, 4);
2178 adapter->hw_read_wx(adapter, NETXEN_FW_VERSION_MINOR, &fw_minor, 4);
2179 adapter->hw_read_wx(adapter, NETXEN_FW_VERSION_SUB, &fw_build, 4);
2181 adapter->fw_major = fw_major;
2183 if (adapter->portnum == 0) {
2184 get_brd_name_by_type(board_info->board_type, brd_name);
2186 printk("NetXen %s Board S/N %s Chip id 0x%x\n",
2187 brd_name, serial_num, board_info->chip_id);
2188 printk("NetXen Firmware version %d.%d.%d\n", fw_major,
2189 fw_minor, fw_build);
2192 if (NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build) <
2193 NETXEN_VERSION_CODE(3, 4, 216)) {
2194 adapter->driver_mismatch = 1;
2195 printk(KERN_ERR "%s: firmware version %d.%d.%d unsupported\n",
2196 netxen_nic_driver_name,
2197 fw_major, fw_minor, fw_build);