2 * Copyright (C) 2003 - 2009 NetXen, Inc.
3 * Copyright (C) 2009 - QLogic Corporation.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.
26 #include "netxen_nic.h"
27 #include "netxen_nic_hw.h"
31 #define MASK(n) ((1ULL<<(n))-1)
32 #define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff))
33 #define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff))
34 #define MS_WIN(addr) (addr & 0x0ffc0000)
36 #define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
38 #define CRB_BLK(off) ((off >> 20) & 0x3f)
39 #define CRB_SUBBLK(off) ((off >> 16) & 0xf)
40 #define CRB_WINDOW_2M (0x130060)
41 #define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000))
42 #define CRB_INDIRECT_2M (0x1e0000UL)
45 static inline u64
readq(void __iomem
*addr
)
47 return readl(addr
) | (((u64
) readl(addr
+ 4)) << 32LL);
52 static inline void writeq(u64 val
, void __iomem
*addr
)
54 writel(((u32
) (val
)), (addr
));
55 writel(((u32
) (val
>> 32)), (addr
+ 4));
59 #define ADDR_IN_RANGE(addr, low, high) \
60 (((addr) < (high)) && ((addr) >= (low)))
62 #define PCI_OFFSET_FIRST_RANGE(adapter, off) \
63 ((adapter)->ahw.pci_base0 + (off))
64 #define PCI_OFFSET_SECOND_RANGE(adapter, off) \
65 ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START)
66 #define PCI_OFFSET_THIRD_RANGE(adapter, off) \
67 ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START)
69 static void __iomem
*pci_base_offset(struct netxen_adapter
*adapter
,
72 if (ADDR_IN_RANGE(off
, FIRST_PAGE_GROUP_START
, FIRST_PAGE_GROUP_END
))
73 return PCI_OFFSET_FIRST_RANGE(adapter
, off
);
75 if (ADDR_IN_RANGE(off
, SECOND_PAGE_GROUP_START
, SECOND_PAGE_GROUP_END
))
76 return PCI_OFFSET_SECOND_RANGE(adapter
, off
);
78 if (ADDR_IN_RANGE(off
, THIRD_PAGE_GROUP_START
, THIRD_PAGE_GROUP_END
))
79 return PCI_OFFSET_THIRD_RANGE(adapter
, off
);
84 static crb_128M_2M_block_map_t
85 crb_128M_2M_map
[64] __cacheline_aligned_in_smp
= {
86 {{{0, 0, 0, 0} } }, /* 0: PCI */
87 {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */
88 {1, 0x0110000, 0x0120000, 0x130000},
89 {1, 0x0120000, 0x0122000, 0x124000},
90 {1, 0x0130000, 0x0132000, 0x126000},
91 {1, 0x0140000, 0x0142000, 0x128000},
92 {1, 0x0150000, 0x0152000, 0x12a000},
93 {1, 0x0160000, 0x0170000, 0x110000},
94 {1, 0x0170000, 0x0172000, 0x12e000},
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 {1, 0x01e0000, 0x01e0800, 0x122000},
102 {0, 0x0000000, 0x0000000, 0x000000} } },
103 {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */
104 {{{0, 0, 0, 0} } }, /* 3: */
105 {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */
106 {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */
107 {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */
108 {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */
109 {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */
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 {0, 0x0000000, 0x0000000, 0x000000},
124 {1, 0x08f0000, 0x08f2000, 0x172000} } },
125 {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/
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 {0, 0x0000000, 0x0000000, 0x000000},
140 {1, 0x09f0000, 0x09f2000, 0x176000} } },
141 {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/
142 {0, 0x0000000, 0x0000000, 0x000000},
143 {0, 0x0000000, 0x0000000, 0x000000},
144 {0, 0x0000000, 0x0000000, 0x000000},
145 {0, 0x0000000, 0x0000000, 0x000000},
146 {0, 0x0000000, 0x0000000, 0x000000},
147 {0, 0x0000000, 0x0000000, 0x000000},
148 {0, 0x0000000, 0x0000000, 0x000000},
149 {0, 0x0000000, 0x0000000, 0x000000},
150 {0, 0x0000000, 0x0000000, 0x000000},
151 {0, 0x0000000, 0x0000000, 0x000000},
152 {0, 0x0000000, 0x0000000, 0x000000},
153 {0, 0x0000000, 0x0000000, 0x000000},
154 {0, 0x0000000, 0x0000000, 0x000000},
155 {0, 0x0000000, 0x0000000, 0x000000},
156 {1, 0x0af0000, 0x0af2000, 0x17a000} } },
157 {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/
158 {0, 0x0000000, 0x0000000, 0x000000},
159 {0, 0x0000000, 0x0000000, 0x000000},
160 {0, 0x0000000, 0x0000000, 0x000000},
161 {0, 0x0000000, 0x0000000, 0x000000},
162 {0, 0x0000000, 0x0000000, 0x000000},
163 {0, 0x0000000, 0x0000000, 0x000000},
164 {0, 0x0000000, 0x0000000, 0x000000},
165 {0, 0x0000000, 0x0000000, 0x000000},
166 {0, 0x0000000, 0x0000000, 0x000000},
167 {0, 0x0000000, 0x0000000, 0x000000},
168 {0, 0x0000000, 0x0000000, 0x000000},
169 {0, 0x0000000, 0x0000000, 0x000000},
170 {0, 0x0000000, 0x0000000, 0x000000},
171 {0, 0x0000000, 0x0000000, 0x000000},
172 {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
173 {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */
174 {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */
175 {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */
176 {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */
177 {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */
178 {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */
179 {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */
180 {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */
181 {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */
182 {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */
183 {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */
184 {{{0, 0, 0, 0} } }, /* 23: */
185 {{{0, 0, 0, 0} } }, /* 24: */
186 {{{0, 0, 0, 0} } }, /* 25: */
187 {{{0, 0, 0, 0} } }, /* 26: */
188 {{{0, 0, 0, 0} } }, /* 27: */
189 {{{0, 0, 0, 0} } }, /* 28: */
190 {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */
191 {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */
192 {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */
193 {{{0} } }, /* 32: PCI */
194 {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */
195 {1, 0x2110000, 0x2120000, 0x130000},
196 {1, 0x2120000, 0x2122000, 0x124000},
197 {1, 0x2130000, 0x2132000, 0x126000},
198 {1, 0x2140000, 0x2142000, 0x128000},
199 {1, 0x2150000, 0x2152000, 0x12a000},
200 {1, 0x2160000, 0x2170000, 0x110000},
201 {1, 0x2170000, 0x2172000, 0x12e000},
202 {0, 0x0000000, 0x0000000, 0x000000},
203 {0, 0x0000000, 0x0000000, 0x000000},
204 {0, 0x0000000, 0x0000000, 0x000000},
205 {0, 0x0000000, 0x0000000, 0x000000},
206 {0, 0x0000000, 0x0000000, 0x000000},
207 {0, 0x0000000, 0x0000000, 0x000000},
208 {0, 0x0000000, 0x0000000, 0x000000},
209 {0, 0x0000000, 0x0000000, 0x000000} } },
210 {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */
216 {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */
217 {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */
218 {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */
219 {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */
220 {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */
221 {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */
222 {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */
223 {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */
224 {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */
225 {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */
226 {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */
227 {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */
229 {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */
230 {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */
231 {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */
232 {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */
233 {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */
234 {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */
235 {{{0} } }, /* 59: I2C0 */
236 {{{0} } }, /* 60: I2C1 */
237 {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */
238 {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */
239 {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */
243 * top 12 bits of crb internal address (hub, agent)
245 static unsigned crb_hub_agt
[64] =
248 NETXEN_HW_CRB_HUB_AGT_ADR_PS
,
249 NETXEN_HW_CRB_HUB_AGT_ADR_MN
,
250 NETXEN_HW_CRB_HUB_AGT_ADR_MS
,
252 NETXEN_HW_CRB_HUB_AGT_ADR_SRE
,
253 NETXEN_HW_CRB_HUB_AGT_ADR_NIU
,
254 NETXEN_HW_CRB_HUB_AGT_ADR_QMN
,
255 NETXEN_HW_CRB_HUB_AGT_ADR_SQN0
,
256 NETXEN_HW_CRB_HUB_AGT_ADR_SQN1
,
257 NETXEN_HW_CRB_HUB_AGT_ADR_SQN2
,
258 NETXEN_HW_CRB_HUB_AGT_ADR_SQN3
,
259 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q
,
260 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR
,
261 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB
,
262 NETXEN_HW_CRB_HUB_AGT_ADR_PGN4
,
263 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA
,
264 NETXEN_HW_CRB_HUB_AGT_ADR_PGN0
,
265 NETXEN_HW_CRB_HUB_AGT_ADR_PGN1
,
266 NETXEN_HW_CRB_HUB_AGT_ADR_PGN2
,
267 NETXEN_HW_CRB_HUB_AGT_ADR_PGN3
,
268 NETXEN_HW_CRB_HUB_AGT_ADR_PGND
,
269 NETXEN_HW_CRB_HUB_AGT_ADR_PGNI
,
270 NETXEN_HW_CRB_HUB_AGT_ADR_PGS0
,
271 NETXEN_HW_CRB_HUB_AGT_ADR_PGS1
,
272 NETXEN_HW_CRB_HUB_AGT_ADR_PGS2
,
273 NETXEN_HW_CRB_HUB_AGT_ADR_PGS3
,
275 NETXEN_HW_CRB_HUB_AGT_ADR_PGSI
,
276 NETXEN_HW_CRB_HUB_AGT_ADR_SN
,
278 NETXEN_HW_CRB_HUB_AGT_ADR_EG
,
280 NETXEN_HW_CRB_HUB_AGT_ADR_PS
,
281 NETXEN_HW_CRB_HUB_AGT_ADR_CAM
,
287 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR
,
289 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1
,
290 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2
,
291 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3
,
292 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4
,
293 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5
,
294 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6
,
295 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7
,
296 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA
,
297 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q
,
298 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB
,
300 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0
,
301 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8
,
302 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9
,
303 NETXEN_HW_CRB_HUB_AGT_ADR_OCM0
,
305 NETXEN_HW_CRB_HUB_AGT_ADR_SMB
,
306 NETXEN_HW_CRB_HUB_AGT_ADR_I2C0
,
307 NETXEN_HW_CRB_HUB_AGT_ADR_I2C1
,
309 NETXEN_HW_CRB_HUB_AGT_ADR_PGNC
,
313 /* PCI Windowing for DDR regions. */
315 #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
317 #define NETXEN_PCIE_SEM_TIMEOUT 10000
320 netxen_pcie_sem_lock(struct netxen_adapter
*adapter
, int sem
, u32 id_reg
)
322 int done
= 0, timeout
= 0;
325 done
= NXRD32(adapter
, NETXEN_PCIE_REG(PCIE_SEM_LOCK(sem
)));
328 if (++timeout
>= NETXEN_PCIE_SEM_TIMEOUT
)
334 NXWR32(adapter
, id_reg
, adapter
->portnum
);
340 netxen_pcie_sem_unlock(struct netxen_adapter
*adapter
, int sem
)
343 val
= NXRD32(adapter
, NETXEN_PCIE_REG(PCIE_SEM_UNLOCK(sem
)));
346 int netxen_niu_xg_init_port(struct netxen_adapter
*adapter
, int port
)
348 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
349 NXWR32(adapter
, NETXEN_NIU_XGE_CONFIG_1
+(0x10000*port
), 0x1447);
350 NXWR32(adapter
, NETXEN_NIU_XGE_CONFIG_0
+(0x10000*port
), 0x5);
356 /* Disable an XG interface */
357 int netxen_niu_disable_xg_port(struct netxen_adapter
*adapter
)
360 u32 port
= adapter
->physical_port
;
362 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
365 if (port
> NETXEN_NIU_MAX_XG_PORTS
)
370 NETXEN_NIU_XGE_CONFIG_0
+ (0x10000 * port
), mac_cfg
))
375 #define NETXEN_UNICAST_ADDR(port, index) \
376 (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8))
377 #define NETXEN_MCAST_ADDR(port, index) \
378 (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8))
379 #define MAC_HI(addr) \
380 ((addr[2] << 16) | (addr[1] << 8) | (addr[0]))
381 #define MAC_LO(addr) \
382 ((addr[5] << 16) | (addr[4] << 8) | (addr[3]))
384 int netxen_p2_nic_set_promisc(struct netxen_adapter
*adapter
, u32 mode
)
387 u32 port
= adapter
->physical_port
;
389 if (port
> NETXEN_NIU_MAX_XG_PORTS
)
392 reg
= NXRD32(adapter
, NETXEN_NIU_XGE_CONFIG_1
+ (0x10000 * port
));
393 if (mode
== NETXEN_NIU_PROMISC_MODE
)
394 reg
= (reg
| 0x2000UL
);
396 reg
= (reg
& ~0x2000UL
);
398 if (mode
== NETXEN_NIU_ALLMULTI_MODE
)
399 reg
= (reg
| 0x1000UL
);
401 reg
= (reg
& ~0x1000UL
);
403 NXWR32(adapter
, NETXEN_NIU_XGE_CONFIG_1
+ (0x10000 * port
), reg
);
408 int netxen_p2_nic_set_mac_addr(struct netxen_adapter
*adapter
, u8
*addr
)
413 u8 phy
= adapter
->physical_port
;
415 if (phy
>= NETXEN_NIU_MAX_XG_PORTS
)
418 mac_lo
= ((u32
)addr
[0] << 16) | ((u32
)addr
[1] << 24);
419 mac_hi
= addr
[2] | ((u32
)addr
[3] << 8) |
420 ((u32
)addr
[4] << 16) | ((u32
)addr
[5] << 24);
422 reg_lo
= NETXEN_NIU_XGE_STATION_ADDR_0_1
+ (0x10000 * phy
);
423 reg_hi
= NETXEN_NIU_XGE_STATION_ADDR_0_HI
+ (0x10000 * phy
);
425 /* write twice to flush */
426 if (NXWR32(adapter
, reg_lo
, mac_lo
) || NXWR32(adapter
, reg_hi
, mac_hi
))
428 if (NXWR32(adapter
, reg_lo
, mac_lo
) || NXWR32(adapter
, reg_hi
, mac_hi
))
435 netxen_nic_enable_mcast_filter(struct netxen_adapter
*adapter
)
438 u16 port
= adapter
->physical_port
;
439 u8
*addr
= adapter
->netdev
->dev_addr
;
441 if (adapter
->mc_enabled
)
444 val
= NXRD32(adapter
, NETXEN_MAC_ADDR_CNTL_REG
);
445 val
|= (1UL << (28+port
));
446 NXWR32(adapter
, NETXEN_MAC_ADDR_CNTL_REG
, val
);
448 /* add broadcast addr to filter */
450 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 0), val
);
451 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 0)+4, val
);
453 /* add station addr to filter */
455 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 1), val
);
457 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 1)+4, val
);
459 adapter
->mc_enabled
= 1;
464 netxen_nic_disable_mcast_filter(struct netxen_adapter
*adapter
)
467 u16 port
= adapter
->physical_port
;
468 u8
*addr
= adapter
->netdev
->dev_addr
;
470 if (!adapter
->mc_enabled
)
473 val
= NXRD32(adapter
, NETXEN_MAC_ADDR_CNTL_REG
);
474 val
&= ~(1UL << (28+port
));
475 NXWR32(adapter
, NETXEN_MAC_ADDR_CNTL_REG
, val
);
478 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 0), val
);
480 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 0)+4, val
);
482 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 1), 0);
483 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 1)+4, 0);
485 adapter
->mc_enabled
= 0;
490 netxen_nic_set_mcast_addr(struct netxen_adapter
*adapter
,
494 u16 port
= adapter
->physical_port
;
499 NXWR32(adapter
, NETXEN_MCAST_ADDR(port
, index
), hi
);
500 NXWR32(adapter
, NETXEN_MCAST_ADDR(port
, index
)+4, lo
);
505 void netxen_p2_nic_set_multi(struct net_device
*netdev
)
507 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
508 struct dev_mc_list
*mc_ptr
;
512 memset(null_addr
, 0, 6);
514 if (netdev
->flags
& IFF_PROMISC
) {
516 adapter
->set_promisc(adapter
,
517 NETXEN_NIU_PROMISC_MODE
);
519 /* Full promiscuous mode */
520 netxen_nic_disable_mcast_filter(adapter
);
525 if (netdev
->mc_count
== 0) {
526 adapter
->set_promisc(adapter
,
527 NETXEN_NIU_NON_PROMISC_MODE
);
528 netxen_nic_disable_mcast_filter(adapter
);
532 adapter
->set_promisc(adapter
, NETXEN_NIU_ALLMULTI_MODE
);
533 if (netdev
->flags
& IFF_ALLMULTI
||
534 netdev
->mc_count
> adapter
->max_mc_count
) {
535 netxen_nic_disable_mcast_filter(adapter
);
539 netxen_nic_enable_mcast_filter(adapter
);
541 for (mc_ptr
= netdev
->mc_list
; mc_ptr
; mc_ptr
= mc_ptr
->next
, index
++)
542 netxen_nic_set_mcast_addr(adapter
, index
, mc_ptr
->dmi_addr
);
544 if (index
!= netdev
->mc_count
)
545 printk(KERN_WARNING
"%s: %s multicast address count mismatch\n",
546 netxen_nic_driver_name
, netdev
->name
);
548 /* Clear out remaining addresses */
549 for (; index
< adapter
->max_mc_count
; index
++)
550 netxen_nic_set_mcast_addr(adapter
, index
, null_addr
);
554 netxen_send_cmd_descs(struct netxen_adapter
*adapter
,
555 struct cmd_desc_type0
*cmd_desc_arr
, int nr_desc
)
557 u32 i
, producer
, consumer
;
558 struct netxen_cmd_buffer
*pbuf
;
559 struct cmd_desc_type0
*cmd_desc
;
560 struct nx_host_tx_ring
*tx_ring
;
564 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
567 tx_ring
= adapter
->tx_ring
;
568 __netif_tx_lock_bh(tx_ring
->txq
);
570 producer
= tx_ring
->producer
;
571 consumer
= tx_ring
->sw_consumer
;
573 if (nr_desc
>= netxen_tx_avail(tx_ring
)) {
574 netif_tx_stop_queue(tx_ring
->txq
);
575 __netif_tx_unlock_bh(tx_ring
->txq
);
580 cmd_desc
= &cmd_desc_arr
[i
];
582 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
584 pbuf
->frag_count
= 0;
586 memcpy(&tx_ring
->desc_head
[producer
],
587 &cmd_desc_arr
[i
], sizeof(struct cmd_desc_type0
));
589 producer
= get_next_index(producer
, tx_ring
->num_desc
);
592 } while (i
!= nr_desc
);
594 tx_ring
->producer
= producer
;
596 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
598 __netif_tx_unlock_bh(tx_ring
->txq
);
604 nx_p3_sre_macaddr_change(struct netxen_adapter
*adapter
, u8
*addr
, unsigned op
)
607 nx_mac_req_t
*mac_req
;
610 memset(&req
, 0, sizeof(nx_nic_req_t
));
611 req
.qhdr
= cpu_to_le64(NX_NIC_REQUEST
<< 23);
613 word
= NX_MAC_EVENT
| ((u64
)adapter
->portnum
<< 16);
614 req
.req_hdr
= cpu_to_le64(word
);
616 mac_req
= (nx_mac_req_t
*)&req
.words
[0];
618 memcpy(mac_req
->mac_addr
, addr
, 6);
620 return netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
623 static int nx_p3_nic_add_mac(struct netxen_adapter
*adapter
,
624 u8
*addr
, struct list_head
*del_list
)
626 struct list_head
*head
;
629 /* look up if already exists */
630 list_for_each(head
, del_list
) {
631 cur
= list_entry(head
, nx_mac_list_t
, list
);
633 if (memcmp(addr
, cur
->mac_addr
, ETH_ALEN
) == 0) {
634 list_move_tail(head
, &adapter
->mac_list
);
639 cur
= kzalloc(sizeof(nx_mac_list_t
), GFP_ATOMIC
);
641 printk(KERN_ERR
"%s: failed to add mac address filter\n",
642 adapter
->netdev
->name
);
645 memcpy(cur
->mac_addr
, addr
, ETH_ALEN
);
646 list_add_tail(&cur
->list
, &adapter
->mac_list
);
647 return nx_p3_sre_macaddr_change(adapter
,
648 cur
->mac_addr
, NETXEN_MAC_ADD
);
651 void netxen_p3_nic_set_multi(struct net_device
*netdev
)
653 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
654 struct dev_mc_list
*mc_ptr
;
655 u8 bcast_addr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
656 u32 mode
= VPORT_MISS_MODE_DROP
;
658 struct list_head
*head
;
661 list_splice_tail_init(&adapter
->mac_list
, &del_list
);
663 nx_p3_nic_add_mac(adapter
, netdev
->dev_addr
, &del_list
);
664 nx_p3_nic_add_mac(adapter
, bcast_addr
, &del_list
);
666 if (netdev
->flags
& IFF_PROMISC
) {
667 mode
= VPORT_MISS_MODE_ACCEPT_ALL
;
671 if ((netdev
->flags
& IFF_ALLMULTI
) ||
672 (netdev
->mc_count
> adapter
->max_mc_count
)) {
673 mode
= VPORT_MISS_MODE_ACCEPT_MULTI
;
677 if (netdev
->mc_count
> 0) {
678 for (mc_ptr
= netdev
->mc_list
; mc_ptr
;
679 mc_ptr
= mc_ptr
->next
) {
680 nx_p3_nic_add_mac(adapter
, mc_ptr
->dmi_addr
, &del_list
);
685 adapter
->set_promisc(adapter
, mode
);
687 while (!list_empty(head
)) {
688 cur
= list_entry(head
->next
, nx_mac_list_t
, list
);
690 nx_p3_sre_macaddr_change(adapter
,
691 cur
->mac_addr
, NETXEN_MAC_DEL
);
692 list_del(&cur
->list
);
697 int netxen_p3_nic_set_promisc(struct netxen_adapter
*adapter
, u32 mode
)
702 memset(&req
, 0, sizeof(nx_nic_req_t
));
704 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
706 word
= NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE
|
707 ((u64
)adapter
->portnum
<< 16);
708 req
.req_hdr
= cpu_to_le64(word
);
710 req
.words
[0] = cpu_to_le64(mode
);
712 return netxen_send_cmd_descs(adapter
,
713 (struct cmd_desc_type0
*)&req
, 1);
716 void netxen_p3_free_mac_list(struct netxen_adapter
*adapter
)
719 struct list_head
*head
= &adapter
->mac_list
;
721 while (!list_empty(head
)) {
722 cur
= list_entry(head
->next
, nx_mac_list_t
, list
);
723 nx_p3_sre_macaddr_change(adapter
,
724 cur
->mac_addr
, NETXEN_MAC_DEL
);
725 list_del(&cur
->list
);
730 int netxen_p3_nic_set_mac_addr(struct netxen_adapter
*adapter
, u8
*addr
)
732 /* assuming caller has already copied new addr to netdev */
733 netxen_p3_nic_set_multi(adapter
->netdev
);
737 #define NETXEN_CONFIG_INTR_COALESCE 3
740 * Send the interrupt coalescing parameter set by ethtool to the card.
742 int netxen_config_intr_coalesce(struct netxen_adapter
*adapter
)
748 memset(&req
, 0, sizeof(nx_nic_req_t
));
750 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
752 word
= NETXEN_CONFIG_INTR_COALESCE
| ((u64
)adapter
->portnum
<< 16);
753 req
.req_hdr
= cpu_to_le64(word
);
755 memcpy(&req
.words
[0], &adapter
->coal
, sizeof(adapter
->coal
));
757 rv
= netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
759 printk(KERN_ERR
"ERROR. Could not send "
760 "interrupt coalescing parameters\n");
766 int netxen_config_hw_lro(struct netxen_adapter
*adapter
, int enable
)
772 if ((adapter
->flags
& NETXEN_NIC_LRO_ENABLED
) == enable
)
775 memset(&req
, 0, sizeof(nx_nic_req_t
));
777 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
779 word
= NX_NIC_H2C_OPCODE_CONFIG_HW_LRO
| ((u64
)adapter
->portnum
<< 16);
780 req
.req_hdr
= cpu_to_le64(word
);
782 req
.words
[0] = cpu_to_le64(enable
);
784 rv
= netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
786 printk(KERN_ERR
"ERROR. Could not send "
787 "configure hw lro request\n");
790 adapter
->flags
^= NETXEN_NIC_LRO_ENABLED
;
795 int netxen_config_bridged_mode(struct netxen_adapter
*adapter
, int enable
)
801 if (!!(adapter
->flags
& NETXEN_NIC_BRIDGE_ENABLED
) == enable
)
804 memset(&req
, 0, sizeof(nx_nic_req_t
));
806 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
808 word
= NX_NIC_H2C_OPCODE_CONFIG_BRIDGING
|
809 ((u64
)adapter
->portnum
<< 16);
810 req
.req_hdr
= cpu_to_le64(word
);
812 req
.words
[0] = cpu_to_le64(enable
);
814 rv
= netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
816 printk(KERN_ERR
"ERROR. Could not send "
817 "configure bridge mode request\n");
820 adapter
->flags
^= NETXEN_NIC_BRIDGE_ENABLED
;
826 #define RSS_HASHTYPE_IP_TCP 0x3
828 int netxen_config_rss(struct netxen_adapter
*adapter
, int enable
)
834 u64 key
[] = { 0xbeac01fa6a42b73bULL
, 0x8030f20c77cb2da3ULL
,
835 0xae7b30b4d0ca2bcbULL
, 0x43a38fb04167253dULL
,
836 0x255b0ec26d5a56daULL
};
839 memset(&req
, 0, sizeof(nx_nic_req_t
));
840 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
842 word
= NX_NIC_H2C_OPCODE_CONFIG_RSS
| ((u64
)adapter
->portnum
<< 16);
843 req
.req_hdr
= cpu_to_le64(word
);
847 * bits 3-0: hash_method
848 * 5-4: hash_type_ipv4
849 * 7-6: hash_type_ipv6
851 * 9: use indirection table
853 * 63-48: indirection table mask
855 word
= ((u64
)(RSS_HASHTYPE_IP_TCP
& 0x3) << 4) |
856 ((u64
)(RSS_HASHTYPE_IP_TCP
& 0x3) << 6) |
857 ((u64
)(enable
& 0x1) << 8) |
859 req
.words
[0] = cpu_to_le64(word
);
860 for (i
= 0; i
< 5; i
++)
861 req
.words
[i
+1] = cpu_to_le64(key
[i
]);
864 rv
= netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
866 printk(KERN_ERR
"%s: could not configure RSS\n",
867 adapter
->netdev
->name
);
873 int netxen_config_ipaddr(struct netxen_adapter
*adapter
, u32 ip
, int cmd
)
879 memset(&req
, 0, sizeof(nx_nic_req_t
));
880 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
882 word
= NX_NIC_H2C_OPCODE_CONFIG_IPADDR
| ((u64
)adapter
->portnum
<< 16);
883 req
.req_hdr
= cpu_to_le64(word
);
885 req
.words
[0] = cpu_to_le64(cmd
);
886 req
.words
[1] = cpu_to_le64(ip
);
888 rv
= netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
890 printk(KERN_ERR
"%s: could not notify %s IP 0x%x reuqest\n",
891 adapter
->netdev
->name
,
892 (cmd
== NX_IP_UP
) ? "Add" : "Remove", ip
);
897 int netxen_linkevent_request(struct netxen_adapter
*adapter
, int enable
)
903 memset(&req
, 0, sizeof(nx_nic_req_t
));
904 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
906 word
= NX_NIC_H2C_OPCODE_GET_LINKEVENT
| ((u64
)adapter
->portnum
<< 16);
907 req
.req_hdr
= cpu_to_le64(word
);
908 req
.words
[0] = cpu_to_le64(enable
| (enable
<< 8));
910 rv
= netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
912 printk(KERN_ERR
"%s: could not configure link notification\n",
913 adapter
->netdev
->name
);
919 int netxen_send_lro_cleanup(struct netxen_adapter
*adapter
)
925 memset(&req
, 0, sizeof(nx_nic_req_t
));
926 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
928 word
= NX_NIC_H2C_OPCODE_LRO_REQUEST
|
929 ((u64
)adapter
->portnum
<< 16) |
930 ((u64
)NX_NIC_LRO_REQUEST_CLEANUP
<< 56) ;
932 req
.req_hdr
= cpu_to_le64(word
);
934 rv
= netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
936 printk(KERN_ERR
"%s: could not cleanup lro flows\n",
937 adapter
->netdev
->name
);
943 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
944 * @returns 0 on success, negative on failure
947 #define MTU_FUDGE_FACTOR 100
949 int netxen_nic_change_mtu(struct net_device
*netdev
, int mtu
)
951 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
955 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
956 max_mtu
= P3_MAX_MTU
;
958 max_mtu
= P2_MAX_MTU
;
961 printk(KERN_ERR
"%s: mtu > %d bytes unsupported\n",
962 netdev
->name
, max_mtu
);
966 if (adapter
->set_mtu
)
967 rc
= adapter
->set_mtu(adapter
, mtu
);
975 static int netxen_get_flash_block(struct netxen_adapter
*adapter
, int base
,
976 int size
, __le32
* buf
)
983 for (i
= 0; i
< size
/ sizeof(u32
); i
++) {
984 if (netxen_rom_fast_read(adapter
, addr
, &v
) == -1)
986 *ptr32
= cpu_to_le32(v
);
990 if ((char *)buf
+ size
> (char *)ptr32
) {
992 if (netxen_rom_fast_read(adapter
, addr
, &v
) == -1)
994 local
= cpu_to_le32(v
);
995 memcpy(ptr32
, &local
, (char *)buf
+ size
- (char *)ptr32
);
1001 int netxen_get_flash_mac_addr(struct netxen_adapter
*adapter
, __le64
*mac
)
1003 __le32
*pmac
= (__le32
*) mac
;
1006 offset
= NX_FW_MAC_ADDR_OFFSET
+ (adapter
->portnum
* sizeof(u64
));
1008 if (netxen_get_flash_block(adapter
, offset
, sizeof(u64
), pmac
) == -1)
1011 if (*mac
== cpu_to_le64(~0ULL)) {
1013 offset
= NX_OLD_MAC_ADDR_OFFSET
+
1014 (adapter
->portnum
* sizeof(u64
));
1016 if (netxen_get_flash_block(adapter
,
1017 offset
, sizeof(u64
), pmac
) == -1)
1020 if (*mac
== cpu_to_le64(~0ULL))
1026 int netxen_p3_get_mac_addr(struct netxen_adapter
*adapter
, __le64
*mac
)
1028 uint32_t crbaddr
, mac_hi
, mac_lo
;
1029 int pci_func
= adapter
->ahw
.pci_func
;
1031 crbaddr
= CRB_MAC_BLOCK_START
+
1032 (4 * ((pci_func
/2) * 3)) + (4 * (pci_func
& 1));
1034 mac_lo
= NXRD32(adapter
, crbaddr
);
1035 mac_hi
= NXRD32(adapter
, crbaddr
+4);
1038 *mac
= le64_to_cpu((mac_lo
>> 16) | ((u64
)mac_hi
<< 16));
1040 *mac
= le64_to_cpu((u64
)mac_lo
| ((u64
)mac_hi
<< 32));
1046 * Changes the CRB window to the specified window.
1049 netxen_nic_pci_change_crbwindow_128M(struct netxen_adapter
*adapter
, u32 wndw
)
1051 void __iomem
*offset
;
1054 uint8_t func
= adapter
->ahw
.pci_func
;
1056 if (adapter
->curr_window
== wndw
)
1059 * Move the CRB window.
1060 * We need to write to the "direct access" region of PCI
1061 * to avoid a race condition where the window register has
1062 * not been successfully written across CRB before the target
1063 * register address is received by PCI. The direct region bypasses
1066 offset
= PCI_OFFSET_SECOND_RANGE(adapter
,
1067 NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func
)));
1070 wndw
= NETXEN_WINDOW_ONE
;
1072 writel(wndw
, offset
);
1074 /* MUST make sure window is set before we forge on... */
1075 while ((tmp
= readl(offset
)) != wndw
) {
1076 printk(KERN_WARNING
"%s: %s WARNING: CRB window value not "
1077 "registered properly: 0x%08x.\n",
1078 netxen_nic_driver_name
, __func__
, tmp
);
1085 if (wndw
== NETXEN_WINDOW_ONE
)
1086 adapter
->curr_window
= 1;
1088 adapter
->curr_window
= 0;
1092 * Return -1 if off is not valid,
1093 * 1 if window access is needed. 'off' is set to offset from
1094 * CRB space in 128M pci map
1095 * 0 if no window access is needed. 'off' is set to 2M addr
1096 * In: 'off' is offset from base in 128M pci map
1099 netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter
*adapter
, ulong
*off
)
1101 crb_128M_2M_sub_block_map_t
*m
;
1104 if (*off
>= NETXEN_CRB_MAX
)
1107 if (*off
>= NETXEN_PCI_CAMQM
&& (*off
< NETXEN_PCI_CAMQM_2M_END
)) {
1108 *off
= (*off
- NETXEN_PCI_CAMQM
) + NETXEN_PCI_CAMQM_2M_BASE
+
1109 (ulong
)adapter
->ahw
.pci_base0
;
1113 if (*off
< NETXEN_PCI_CRBSPACE
)
1116 *off
-= NETXEN_PCI_CRBSPACE
;
1121 m
= &crb_128M_2M_map
[CRB_BLK(*off
)].sub_block
[CRB_SUBBLK(*off
)];
1123 if (m
->valid
&& (m
->start_128M
<= *off
) && (m
->end_128M
> *off
)) {
1124 *off
= *off
+ m
->start_2M
- m
->start_128M
+
1125 (ulong
)adapter
->ahw
.pci_base0
;
1130 * Not in direct map, use crb window
1136 * In: 'off' is offset from CRB space in 128M pci map
1137 * Out: 'off' is 2M pci map addr
1138 * side effect: lock crb window
1141 netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter
*adapter
, ulong
*off
)
1145 adapter
->crb_win
= CRB_HI(*off
);
1146 writel(adapter
->crb_win
, (adapter
->ahw
.pci_base0
+ CRB_WINDOW_2M
));
1148 * Read back value to make sure write has gone through before trying
1151 win_read
= readl(adapter
->ahw
.pci_base0
+ CRB_WINDOW_2M
);
1152 if (win_read
!= adapter
->crb_win
) {
1153 printk(KERN_ERR
"%s: Written crbwin (0x%x) != "
1154 "Read crbwin (0x%x), off=0x%lx\n",
1155 __func__
, adapter
->crb_win
, win_read
, *off
);
1157 *off
= (*off
& MASK(16)) + CRB_INDIRECT_2M
+
1158 (ulong
)adapter
->ahw
.pci_base0
;
1162 netxen_nic_hw_write_wx_128M(struct netxen_adapter
*adapter
, ulong off
, u32 data
)
1164 unsigned long flags
;
1167 if (ADDR_IN_WINDOW1(off
))
1168 addr
= NETXEN_CRB_NORMALIZE(adapter
, off
);
1170 addr
= pci_base_offset(adapter
, off
);
1174 if (ADDR_IN_WINDOW1(off
)) { /* Window 1 */
1175 read_lock(&adapter
->adapter_lock
);
1177 read_unlock(&adapter
->adapter_lock
);
1178 } else { /* Window 0 */
1179 write_lock_irqsave(&adapter
->adapter_lock
, flags
);
1180 addr
= pci_base_offset(adapter
, off
);
1181 netxen_nic_pci_change_crbwindow_128M(adapter
, 0);
1183 netxen_nic_pci_change_crbwindow_128M(adapter
, 1);
1184 write_unlock_irqrestore(&adapter
->adapter_lock
, flags
);
1191 netxen_nic_hw_read_wx_128M(struct netxen_adapter
*adapter
, ulong off
)
1193 unsigned long flags
;
1197 if (ADDR_IN_WINDOW1(off
))
1198 addr
= NETXEN_CRB_NORMALIZE(adapter
, off
);
1200 addr
= pci_base_offset(adapter
, off
);
1204 if (ADDR_IN_WINDOW1(off
)) { /* Window 1 */
1205 read_lock(&adapter
->adapter_lock
);
1207 read_unlock(&adapter
->adapter_lock
);
1208 } else { /* Window 0 */
1209 write_lock_irqsave(&adapter
->adapter_lock
, flags
);
1210 netxen_nic_pci_change_crbwindow_128M(adapter
, 0);
1212 netxen_nic_pci_change_crbwindow_128M(adapter
, 1);
1213 write_unlock_irqrestore(&adapter
->adapter_lock
, flags
);
1220 netxen_nic_hw_write_wx_2M(struct netxen_adapter
*adapter
, ulong off
, u32 data
)
1222 unsigned long flags
;
1225 rv
= netxen_nic_pci_get_crb_addr_2M(adapter
, &off
);
1228 printk(KERN_ERR
"%s: invalid offset: 0x%016lx\n",
1235 write_lock_irqsave(&adapter
->adapter_lock
, flags
);
1236 crb_win_lock(adapter
);
1237 netxen_nic_pci_set_crbwindow_2M(adapter
, &off
);
1238 writel(data
, (void __iomem
*)off
);
1239 crb_win_unlock(adapter
);
1240 write_unlock_irqrestore(&adapter
->adapter_lock
, flags
);
1242 writel(data
, (void __iomem
*)off
);
1249 netxen_nic_hw_read_wx_2M(struct netxen_adapter
*adapter
, ulong off
)
1251 unsigned long flags
;
1255 rv
= netxen_nic_pci_get_crb_addr_2M(adapter
, &off
);
1258 printk(KERN_ERR
"%s: invalid offset: 0x%016lx\n",
1265 write_lock_irqsave(&adapter
->adapter_lock
, flags
);
1266 crb_win_lock(adapter
);
1267 netxen_nic_pci_set_crbwindow_2M(adapter
, &off
);
1268 data
= readl((void __iomem
*)off
);
1269 crb_win_unlock(adapter
);
1270 write_unlock_irqrestore(&adapter
->adapter_lock
, flags
);
1272 data
= readl((void __iomem
*)off
);
1277 static int netxen_pci_set_window_warning_count
;
1279 static unsigned long
1280 netxen_nic_pci_set_window_128M(struct netxen_adapter
*adapter
,
1281 unsigned long long addr
)
1283 void __iomem
*offset
;
1285 unsigned long long qdr_max
;
1286 uint8_t func
= adapter
->ahw
.pci_func
;
1288 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1289 qdr_max
= NETXEN_ADDR_QDR_NET_MAX_P2
;
1291 qdr_max
= NETXEN_ADDR_QDR_NET_MAX_P3
;
1294 if (ADDR_IN_RANGE(addr
, NETXEN_ADDR_DDR_NET
, NETXEN_ADDR_DDR_NET_MAX
)) {
1295 /* DDR network side */
1296 addr
-= NETXEN_ADDR_DDR_NET
;
1297 window
= (addr
>> 25) & 0x3ff;
1298 if (adapter
->ahw
.ddr_mn_window
!= window
) {
1299 adapter
->ahw
.ddr_mn_window
= window
;
1300 offset
= PCI_OFFSET_SECOND_RANGE(adapter
,
1301 NETXEN_PCIX_PH_REG(PCIE_MN_WINDOW_REG(func
)));
1302 writel(window
, offset
);
1303 /* MUST make sure window is set before we forge on... */
1306 addr
-= (window
* NETXEN_WINDOW_ONE
);
1307 addr
+= NETXEN_PCI_DDR_NET
;
1308 } else if (ADDR_IN_RANGE(addr
, NETXEN_ADDR_OCM0
, NETXEN_ADDR_OCM0_MAX
)) {
1309 addr
-= NETXEN_ADDR_OCM0
;
1310 addr
+= NETXEN_PCI_OCM0
;
1311 } else if (ADDR_IN_RANGE(addr
, NETXEN_ADDR_OCM1
, NETXEN_ADDR_OCM1_MAX
)) {
1312 addr
-= NETXEN_ADDR_OCM1
;
1313 addr
+= NETXEN_PCI_OCM1
;
1314 } else if (ADDR_IN_RANGE(addr
, NETXEN_ADDR_QDR_NET
, qdr_max
)) {
1315 /* QDR network side */
1316 addr
-= NETXEN_ADDR_QDR_NET
;
1317 window
= (addr
>> 22) & 0x3f;
1318 if (adapter
->ahw
.qdr_sn_window
!= window
) {
1319 adapter
->ahw
.qdr_sn_window
= window
;
1320 offset
= PCI_OFFSET_SECOND_RANGE(adapter
,
1321 NETXEN_PCIX_PH_REG(PCIE_SN_WINDOW_REG(func
)));
1322 writel((window
<< 22), offset
);
1323 /* MUST make sure window is set before we forge on... */
1326 addr
-= (window
* 0x400000);
1327 addr
+= NETXEN_PCI_QDR_NET
;
1330 * peg gdb frequently accesses memory that doesn't exist,
1331 * this limits the chit chat so debugging isn't slowed down.
1333 if ((netxen_pci_set_window_warning_count
++ < 8)
1334 || (netxen_pci_set_window_warning_count
% 64 == 0))
1335 printk("%s: Warning:netxen_nic_pci_set_window()"
1336 " Unknown address range!\n",
1337 netxen_nic_driver_name
);
1343 /* window 1 registers only */
1344 static void netxen_nic_io_write_128M(struct netxen_adapter
*adapter
,
1345 void __iomem
*addr
, u32 data
)
1347 read_lock(&adapter
->adapter_lock
);
1349 read_unlock(&adapter
->adapter_lock
);
1352 static u32
netxen_nic_io_read_128M(struct netxen_adapter
*adapter
,
1357 read_lock(&adapter
->adapter_lock
);
1359 read_unlock(&adapter
->adapter_lock
);
1364 static void netxen_nic_io_write_2M(struct netxen_adapter
*adapter
,
1365 void __iomem
*addr
, u32 data
)
1370 static u32
netxen_nic_io_read_2M(struct netxen_adapter
*adapter
,
1377 netxen_get_ioaddr(struct netxen_adapter
*adapter
, u32 offset
)
1381 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1382 if (offset
< NETXEN_CRB_PCIX_HOST2
&&
1383 offset
> NETXEN_CRB_PCIX_HOST
)
1384 return PCI_OFFSET_SECOND_RANGE(adapter
, offset
);
1385 return NETXEN_CRB_NORMALIZE(adapter
, offset
);
1388 BUG_ON(netxen_nic_pci_get_crb_addr_2M(adapter
, &off
));
1389 return (void __iomem
*)off
;
1392 static unsigned long
1393 netxen_nic_pci_set_window_2M(struct netxen_adapter
*adapter
,
1394 unsigned long long addr
)
1399 if (ADDR_IN_RANGE(addr
, NETXEN_ADDR_DDR_NET
, NETXEN_ADDR_DDR_NET_MAX
)) {
1400 /* DDR network side */
1401 window
= MN_WIN(addr
);
1402 adapter
->ahw
.ddr_mn_window
= window
;
1403 NXWR32(adapter
, adapter
->ahw
.mn_win_crb
, window
);
1404 win_read
= NXRD32(adapter
, adapter
->ahw
.mn_win_crb
);
1405 if ((win_read
<< 17) != window
) {
1406 printk(KERN_INFO
"Written MNwin (0x%x) != "
1407 "Read MNwin (0x%x)\n", window
, win_read
);
1409 addr
= GET_MEM_OFFS_2M(addr
) + NETXEN_PCI_DDR_NET
;
1410 } else if (ADDR_IN_RANGE(addr
,
1411 NETXEN_ADDR_OCM0
, NETXEN_ADDR_OCM0_MAX
)) {
1412 if ((addr
& 0x00ff800) == 0xff800) {
1413 printk("%s: QM access not handled.\n", __func__
);
1417 window
= OCM_WIN(addr
);
1418 adapter
->ahw
.ddr_mn_window
= window
;
1419 NXWR32(adapter
, adapter
->ahw
.mn_win_crb
, window
);
1420 win_read
= NXRD32(adapter
, adapter
->ahw
.mn_win_crb
);
1421 if ((win_read
>> 7) != window
) {
1422 printk(KERN_INFO
"%s: Written OCMwin (0x%x) != "
1423 "Read OCMwin (0x%x)\n",
1424 __func__
, window
, win_read
);
1426 addr
= GET_MEM_OFFS_2M(addr
) + NETXEN_PCI_OCM0_2M
;
1428 } else if (ADDR_IN_RANGE(addr
,
1429 NETXEN_ADDR_QDR_NET
, NETXEN_ADDR_QDR_NET_MAX_P3
)) {
1430 /* QDR network side */
1431 window
= MS_WIN(addr
);
1432 adapter
->ahw
.qdr_sn_window
= window
;
1433 NXWR32(adapter
, adapter
->ahw
.ms_win_crb
, window
);
1434 win_read
= NXRD32(adapter
, adapter
->ahw
.ms_win_crb
);
1435 if (win_read
!= window
) {
1436 printk(KERN_INFO
"%s: Written MSwin (0x%x) != "
1437 "Read MSwin (0x%x)\n",
1438 __func__
, window
, win_read
);
1440 addr
= GET_MEM_OFFS_2M(addr
) + NETXEN_PCI_QDR_NET
;
1444 * peg gdb frequently accesses memory that doesn't exist,
1445 * this limits the chit chat so debugging isn't slowed down.
1447 if ((netxen_pci_set_window_warning_count
++ < 8)
1448 || (netxen_pci_set_window_warning_count
%64 == 0)) {
1449 printk("%s: Warning:%s Unknown address range!\n",
1450 __func__
, netxen_nic_driver_name
);
1457 #define MAX_CTL_CHECK 1000
1460 netxen_nic_pci_mem_write_128M(struct netxen_adapter
*adapter
,
1461 u64 off
, void *data
, int size
)
1463 unsigned long flags
;
1464 int i
, j
, ret
= 0, loop
, sz
[2], off0
;
1466 uint64_t off8
, tmpw
, word
[2] = {0, 0};
1467 void __iomem
*mem_crb
;
1472 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_QDR_NET
,
1473 NETXEN_ADDR_QDR_NET_MAX_P2
)) {
1474 mem_crb
= pci_base_offset(adapter
, NETXEN_CRB_QDR_NET
);
1478 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_DDR_NET
, NETXEN_ADDR_DDR_NET_MAX
)) {
1479 mem_crb
= pci_base_offset(adapter
, NETXEN_CRB_DDR_NET
);
1486 off8
= off
& 0xfffffff8;
1488 sz
[0] = (size
< (8 - off0
)) ? size
: (8 - off0
);
1489 sz
[1] = size
- sz
[0];
1490 loop
= ((off0
+ size
- 1) >> 3) + 1;
1492 if ((size
!= 8) || (off0
!= 0)) {
1493 for (i
= 0; i
< loop
; i
++) {
1494 if (adapter
->pci_mem_read(adapter
,
1495 off8
+ (i
<< 3), &word
[i
], 8))
1502 tmpw
= *((uint8_t *)data
);
1505 tmpw
= *((uint16_t *)data
);
1508 tmpw
= *((uint32_t *)data
);
1512 tmpw
= *((uint64_t *)data
);
1515 word
[0] &= ~((~(~0ULL << (sz
[0] * 8))) << (off0
* 8));
1516 word
[0] |= tmpw
<< (off0
* 8);
1519 word
[1] &= ~(~0ULL << (sz
[1] * 8));
1520 word
[1] |= tmpw
>> (sz
[0] * 8);
1523 write_lock_irqsave(&adapter
->adapter_lock
, flags
);
1524 netxen_nic_pci_change_crbwindow_128M(adapter
, 0);
1526 for (i
= 0; i
< loop
; i
++) {
1527 writel((uint32_t)(off8
+ (i
<< 3)),
1528 (mem_crb
+MIU_TEST_AGT_ADDR_LO
));
1530 (mem_crb
+MIU_TEST_AGT_ADDR_HI
));
1531 writel(word
[i
] & 0xffffffff,
1532 (mem_crb
+MIU_TEST_AGT_WRDATA_LO
));
1533 writel((word
[i
] >> 32) & 0xffffffff,
1534 (mem_crb
+MIU_TEST_AGT_WRDATA_HI
));
1535 writel(MIU_TA_CTL_ENABLE
|MIU_TA_CTL_WRITE
,
1536 (mem_crb
+MIU_TEST_AGT_CTRL
));
1537 writel(MIU_TA_CTL_START
|MIU_TA_CTL_ENABLE
|MIU_TA_CTL_WRITE
,
1538 (mem_crb
+MIU_TEST_AGT_CTRL
));
1540 for (j
= 0; j
< MAX_CTL_CHECK
; j
++) {
1542 (mem_crb
+MIU_TEST_AGT_CTRL
));
1543 if ((temp
& MIU_TA_CTL_BUSY
) == 0)
1547 if (j
>= MAX_CTL_CHECK
) {
1548 if (printk_ratelimit())
1549 dev_err(&adapter
->pdev
->dev
,
1550 "failed to write through agent\n");
1556 netxen_nic_pci_change_crbwindow_128M(adapter
, 1);
1557 write_unlock_irqrestore(&adapter
->adapter_lock
, flags
);
1562 netxen_nic_pci_mem_read_128M(struct netxen_adapter
*adapter
,
1563 u64 off
, void *data
, int size
)
1565 unsigned long flags
;
1566 int i
, j
= 0, k
, start
, end
, loop
, sz
[2], off0
[2];
1568 uint64_t off8
, val
, word
[2] = {0, 0};
1569 void __iomem
*mem_crb
;
1574 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_QDR_NET
,
1575 NETXEN_ADDR_QDR_NET_MAX_P2
)) {
1576 mem_crb
= pci_base_offset(adapter
, NETXEN_CRB_QDR_NET
);
1580 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_DDR_NET
, NETXEN_ADDR_DDR_NET_MAX
)) {
1581 mem_crb
= pci_base_offset(adapter
, NETXEN_CRB_DDR_NET
);
1588 off8
= off
& 0xfffffff8;
1589 off0
[0] = off
& 0x7;
1591 sz
[0] = (size
< (8 - off0
[0])) ? size
: (8 - off0
[0]);
1592 sz
[1] = size
- sz
[0];
1593 loop
= ((off0
[0] + size
- 1) >> 3) + 1;
1595 write_lock_irqsave(&adapter
->adapter_lock
, flags
);
1596 netxen_nic_pci_change_crbwindow_128M(adapter
, 0);
1598 for (i
= 0; i
< loop
; i
++) {
1599 writel((uint32_t)(off8
+ (i
<< 3)),
1600 (mem_crb
+MIU_TEST_AGT_ADDR_LO
));
1602 (mem_crb
+MIU_TEST_AGT_ADDR_HI
));
1603 writel(MIU_TA_CTL_ENABLE
,
1604 (mem_crb
+MIU_TEST_AGT_CTRL
));
1605 writel(MIU_TA_CTL_START
|MIU_TA_CTL_ENABLE
,
1606 (mem_crb
+MIU_TEST_AGT_CTRL
));
1608 for (j
= 0; j
< MAX_CTL_CHECK
; j
++) {
1610 (mem_crb
+MIU_TEST_AGT_CTRL
));
1611 if ((temp
& MIU_TA_CTL_BUSY
) == 0)
1615 if (j
>= MAX_CTL_CHECK
) {
1616 if (printk_ratelimit())
1617 dev_err(&adapter
->pdev
->dev
,
1618 "failed to read through agent\n");
1622 start
= off0
[i
] >> 2;
1623 end
= (off0
[i
] + sz
[i
] - 1) >> 2;
1624 for (k
= start
; k
<= end
; k
++) {
1625 word
[i
] |= ((uint64_t) readl(
1627 MIU_TEST_AGT_RDDATA(k
))) << (32*k
));
1631 netxen_nic_pci_change_crbwindow_128M(adapter
, 1);
1632 write_unlock_irqrestore(&adapter
->adapter_lock
, flags
);
1634 if (j
>= MAX_CTL_CHECK
)
1640 val
= ((word
[0] >> (off0
[0] * 8)) & (~(~0ULL << (sz
[0] * 8)))) |
1641 ((word
[1] & (~(~0ULL << (sz
[1] * 8)))) << (sz
[0] * 8));
1646 *(uint8_t *)data
= val
;
1649 *(uint16_t *)data
= val
;
1652 *(uint32_t *)data
= val
;
1655 *(uint64_t *)data
= val
;
1662 netxen_nic_pci_mem_write_2M(struct netxen_adapter
*adapter
,
1663 u64 off
, void *data
, int size
)
1665 int i
, j
, ret
= 0, loop
, sz
[2], off0
;
1667 uint64_t off8
, tmpw
, word
[2] = {0, 0};
1668 void __iomem
*mem_crb
;
1673 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_QDR_NET
,
1674 NETXEN_ADDR_QDR_NET_MAX_P3
)) {
1675 mem_crb
= netxen_get_ioaddr(adapter
, NETXEN_CRB_QDR_NET
);
1679 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_DDR_NET
, NETXEN_ADDR_DDR_NET_MAX
)) {
1680 mem_crb
= netxen_get_ioaddr(adapter
, NETXEN_CRB_DDR_NET
);
1687 off8
= off
& 0xfffffff8;
1689 sz
[0] = (size
< (8 - off0
)) ? size
: (8 - off0
);
1690 sz
[1] = size
- sz
[0];
1691 loop
= ((off0
+ size
- 1) >> 3) + 1;
1693 if ((size
!= 8) || (off0
!= 0)) {
1694 for (i
= 0; i
< loop
; i
++) {
1695 if (adapter
->pci_mem_read(adapter
,
1696 off8
+ (i
<< 3), &word
[i
], 8))
1703 tmpw
= *((uint8_t *)data
);
1706 tmpw
= *((uint16_t *)data
);
1709 tmpw
= *((uint32_t *)data
);
1713 tmpw
= *((uint64_t *)data
);
1717 word
[0] &= ~((~(~0ULL << (sz
[0] * 8))) << (off0
* 8));
1718 word
[0] |= tmpw
<< (off0
* 8);
1721 word
[1] &= ~(~0ULL << (sz
[1] * 8));
1722 word
[1] |= tmpw
>> (sz
[0] * 8);
1726 * don't lock here - write_wx gets the lock if each time
1727 * write_lock_irqsave(&adapter->adapter_lock, flags);
1728 * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1731 for (i
= 0; i
< loop
; i
++) {
1732 writel(off8
+ (i
<< 3), mem_crb
+MIU_TEST_AGT_ADDR_LO
);
1733 writel(0, mem_crb
+MIU_TEST_AGT_ADDR_HI
);
1734 writel(word
[i
] & 0xffffffff, mem_crb
+MIU_TEST_AGT_WRDATA_LO
);
1735 writel((word
[i
] >> 32) & 0xffffffff,
1736 mem_crb
+MIU_TEST_AGT_WRDATA_HI
);
1737 writel((MIU_TA_CTL_ENABLE
| MIU_TA_CTL_WRITE
),
1738 mem_crb
+MIU_TEST_AGT_CTRL
);
1739 writel(MIU_TA_CTL_START
| MIU_TA_CTL_ENABLE
| MIU_TA_CTL_WRITE
,
1740 mem_crb
+MIU_TEST_AGT_CTRL
);
1742 for (j
= 0; j
< MAX_CTL_CHECK
; j
++) {
1743 temp
= readl(mem_crb
+ MIU_TEST_AGT_CTRL
);
1744 if ((temp
& MIU_TA_CTL_BUSY
) == 0)
1748 if (j
>= MAX_CTL_CHECK
) {
1749 if (printk_ratelimit())
1750 dev_err(&adapter
->pdev
->dev
,
1751 "failed to write through agent\n");
1758 * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1759 * write_unlock_irqrestore(&adapter->adapter_lock, flags);
1765 netxen_nic_pci_mem_read_2M(struct netxen_adapter
*adapter
,
1766 u64 off
, void *data
, int size
)
1768 int i
, j
= 0, k
, start
, end
, loop
, sz
[2], off0
[2];
1770 uint64_t off8
, val
, word
[2] = {0, 0};
1771 void __iomem
*mem_crb
;
1776 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_QDR_NET
,
1777 NETXEN_ADDR_QDR_NET_MAX_P3
)) {
1778 mem_crb
= netxen_get_ioaddr(adapter
, NETXEN_CRB_QDR_NET
);
1782 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_DDR_NET
, NETXEN_ADDR_DDR_NET_MAX
)) {
1783 mem_crb
= netxen_get_ioaddr(adapter
, NETXEN_CRB_DDR_NET
);
1790 off8
= off
& 0xfffffff8;
1791 off0
[0] = off
& 0x7;
1793 sz
[0] = (size
< (8 - off0
[0])) ? size
: (8 - off0
[0]);
1794 sz
[1] = size
- sz
[0];
1795 loop
= ((off0
[0] + size
- 1) >> 3) + 1;
1798 * don't lock here - write_wx gets the lock if each time
1799 * write_lock_irqsave(&adapter->adapter_lock, flags);
1800 * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
1803 for (i
= 0; i
< loop
; i
++) {
1804 writel(off8
+ (i
<< 3), mem_crb
+ MIU_TEST_AGT_ADDR_LO
);
1805 writel(0, mem_crb
+ MIU_TEST_AGT_ADDR_HI
);
1806 writel(MIU_TA_CTL_ENABLE
, mem_crb
+ MIU_TEST_AGT_CTRL
);
1807 writel(MIU_TA_CTL_START
| MIU_TA_CTL_ENABLE
,
1808 mem_crb
+ MIU_TEST_AGT_CTRL
);
1810 for (j
= 0; j
< MAX_CTL_CHECK
; j
++) {
1811 temp
= readl(mem_crb
+ MIU_TEST_AGT_CTRL
);
1812 if ((temp
& MIU_TA_CTL_BUSY
) == 0)
1816 if (j
>= MAX_CTL_CHECK
) {
1817 if (printk_ratelimit())
1818 dev_err(&adapter
->pdev
->dev
,
1819 "failed to read through agent\n");
1823 start
= off0
[i
] >> 2;
1824 end
= (off0
[i
] + sz
[i
] - 1) >> 2;
1825 for (k
= start
; k
<= end
; k
++) {
1826 temp
= readl(mem_crb
+ MIU_TEST_AGT_RDDATA(k
));
1827 word
[i
] |= ((uint64_t)temp
<< (32 * k
));
1832 * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
1833 * write_unlock_irqrestore(&adapter->adapter_lock, flags);
1836 if (j
>= MAX_CTL_CHECK
)
1842 val
= ((word
[0] >> (off0
[0] * 8)) & (~(~0ULL << (sz
[0] * 8)))) |
1843 ((word
[1] & (~(~0ULL << (sz
[1] * 8)))) << (sz
[0] * 8));
1848 *(uint8_t *)data
= val
;
1851 *(uint16_t *)data
= val
;
1854 *(uint32_t *)data
= val
;
1857 *(uint64_t *)data
= val
;
1864 netxen_setup_hwops(struct netxen_adapter
*adapter
)
1866 adapter
->init_port
= netxen_niu_xg_init_port
;
1867 adapter
->stop_port
= netxen_niu_disable_xg_port
;
1869 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1870 adapter
->crb_read
= netxen_nic_hw_read_wx_128M
,
1871 adapter
->crb_write
= netxen_nic_hw_write_wx_128M
,
1872 adapter
->pci_set_window
= netxen_nic_pci_set_window_128M
,
1873 adapter
->pci_mem_read
= netxen_nic_pci_mem_read_128M
,
1874 adapter
->pci_mem_write
= netxen_nic_pci_mem_write_128M
,
1875 adapter
->io_read
= netxen_nic_io_read_128M
,
1876 adapter
->io_write
= netxen_nic_io_write_128M
,
1878 adapter
->macaddr_set
= netxen_p2_nic_set_mac_addr
;
1879 adapter
->set_multi
= netxen_p2_nic_set_multi
;
1880 adapter
->set_mtu
= netxen_nic_set_mtu_xgb
;
1881 adapter
->set_promisc
= netxen_p2_nic_set_promisc
;
1884 adapter
->crb_read
= netxen_nic_hw_read_wx_2M
,
1885 adapter
->crb_write
= netxen_nic_hw_write_wx_2M
,
1886 adapter
->pci_set_window
= netxen_nic_pci_set_window_2M
,
1887 adapter
->pci_mem_read
= netxen_nic_pci_mem_read_2M
,
1888 adapter
->pci_mem_write
= netxen_nic_pci_mem_write_2M
,
1889 adapter
->io_read
= netxen_nic_io_read_2M
,
1890 adapter
->io_write
= netxen_nic_io_write_2M
,
1892 adapter
->set_mtu
= nx_fw_cmd_set_mtu
;
1893 adapter
->set_promisc
= netxen_p3_nic_set_promisc
;
1894 adapter
->macaddr_set
= netxen_p3_nic_set_mac_addr
;
1895 adapter
->set_multi
= netxen_p3_nic_set_multi
;
1897 adapter
->phy_read
= nx_fw_cmd_query_phy
;
1898 adapter
->phy_write
= nx_fw_cmd_set_phy
;
1902 int netxen_nic_get_board_info(struct netxen_adapter
*adapter
)
1904 int offset
, board_type
, magic
;
1905 struct pci_dev
*pdev
= adapter
->pdev
;
1907 offset
= NX_FW_MAGIC_OFFSET
;
1908 if (netxen_rom_fast_read(adapter
, offset
, &magic
))
1911 if (magic
!= NETXEN_BDINFO_MAGIC
) {
1912 dev_err(&pdev
->dev
, "invalid board config, magic=%08x\n",
1917 offset
= NX_BRDTYPE_OFFSET
;
1918 if (netxen_rom_fast_read(adapter
, offset
, &board_type
))
1921 adapter
->ahw
.board_type
= board_type
;
1923 if (board_type
== NETXEN_BRDTYPE_P3_4_GB_MM
) {
1924 u32 gpio
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_PAD_GPIO_I
);
1925 if ((gpio
& 0x8000) == 0)
1926 board_type
= NETXEN_BRDTYPE_P3_10G_TP
;
1929 switch (board_type
) {
1930 case NETXEN_BRDTYPE_P2_SB35_4G
:
1931 adapter
->ahw
.port_type
= NETXEN_NIC_GBE
;
1933 case NETXEN_BRDTYPE_P2_SB31_10G
:
1934 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
1935 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
1936 case NETXEN_BRDTYPE_P2_SB31_10G_CX4
:
1937 case NETXEN_BRDTYPE_P3_HMEZ
:
1938 case NETXEN_BRDTYPE_P3_XG_LOM
:
1939 case NETXEN_BRDTYPE_P3_10G_CX4
:
1940 case NETXEN_BRDTYPE_P3_10G_CX4_LP
:
1941 case NETXEN_BRDTYPE_P3_IMEZ
:
1942 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS
:
1943 case NETXEN_BRDTYPE_P3_10G_SFP_CT
:
1944 case NETXEN_BRDTYPE_P3_10G_SFP_QT
:
1945 case NETXEN_BRDTYPE_P3_10G_XFP
:
1946 case NETXEN_BRDTYPE_P3_10000_BASE_T
:
1947 adapter
->ahw
.port_type
= NETXEN_NIC_XGBE
;
1949 case NETXEN_BRDTYPE_P1_BD
:
1950 case NETXEN_BRDTYPE_P1_SB
:
1951 case NETXEN_BRDTYPE_P1_SMAX
:
1952 case NETXEN_BRDTYPE_P1_SOCK
:
1953 case NETXEN_BRDTYPE_P3_REF_QG
:
1954 case NETXEN_BRDTYPE_P3_4_GB
:
1955 case NETXEN_BRDTYPE_P3_4_GB_MM
:
1956 adapter
->ahw
.port_type
= NETXEN_NIC_GBE
;
1958 case NETXEN_BRDTYPE_P3_10G_TP
:
1959 adapter
->ahw
.port_type
= (adapter
->portnum
< 2) ?
1960 NETXEN_NIC_XGBE
: NETXEN_NIC_GBE
;
1963 dev_err(&pdev
->dev
, "unknown board type %x\n", board_type
);
1964 adapter
->ahw
.port_type
= NETXEN_NIC_XGBE
;
1971 /* NIU access sections */
1973 int netxen_nic_set_mtu_gb(struct netxen_adapter
*adapter
, int new_mtu
)
1975 new_mtu
+= MTU_FUDGE_FACTOR
;
1976 NXWR32(adapter
, NETXEN_NIU_GB_MAX_FRAME_SIZE(adapter
->physical_port
),
1981 int netxen_nic_set_mtu_xgb(struct netxen_adapter
*adapter
, int new_mtu
)
1983 new_mtu
+= MTU_FUDGE_FACTOR
;
1984 if (adapter
->physical_port
== 0)
1985 NXWR32(adapter
, NETXEN_NIU_XGE_MAX_FRAME_SIZE
, new_mtu
);
1987 NXWR32(adapter
, NETXEN_NIU_XG1_MAX_FRAME_SIZE
, new_mtu
);
1991 void netxen_nic_set_link_parameters(struct netxen_adapter
*adapter
)
1997 if (!netif_carrier_ok(adapter
->netdev
)) {
1998 adapter
->link_speed
= 0;
1999 adapter
->link_duplex
= -1;
2000 adapter
->link_autoneg
= AUTONEG_ENABLE
;
2004 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
2005 port_mode
= NXRD32(adapter
, NETXEN_PORT_MODE_ADDR
);
2006 if (port_mode
== NETXEN_PORT_MODE_802_3_AP
) {
2007 adapter
->link_speed
= SPEED_1000
;
2008 adapter
->link_duplex
= DUPLEX_FULL
;
2009 adapter
->link_autoneg
= AUTONEG_DISABLE
;
2013 if (adapter
->phy_read
2014 && adapter
->phy_read(adapter
,
2015 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS
,
2017 if (netxen_get_phy_link(status
)) {
2018 switch (netxen_get_phy_speed(status
)) {
2020 adapter
->link_speed
= SPEED_10
;
2023 adapter
->link_speed
= SPEED_100
;
2026 adapter
->link_speed
= SPEED_1000
;
2029 adapter
->link_speed
= 0;
2032 switch (netxen_get_phy_duplex(status
)) {
2034 adapter
->link_duplex
= DUPLEX_HALF
;
2037 adapter
->link_duplex
= DUPLEX_FULL
;
2040 adapter
->link_duplex
= -1;
2043 if (adapter
->phy_read
2044 && adapter
->phy_read(adapter
,
2045 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG
,
2047 adapter
->link_autoneg
= autoneg
;
2052 adapter
->link_speed
= 0;
2053 adapter
->link_duplex
= -1;
2059 netxen_nic_wol_supported(struct netxen_adapter
*adapter
)
2063 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2066 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG_NV
);
2067 if (wol_cfg
& (1UL << adapter
->portnum
)) {
2068 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG
);
2069 if (wol_cfg
& (1 << adapter
->portnum
))