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 "COPYING".
26 #include <linux/slab.h>
27 #include "netxen_nic.h"
28 #include "netxen_nic_hw.h"
32 #define MASK(n) ((1ULL<<(n))-1)
33 #define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff))
34 #define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff))
35 #define MS_WIN(addr) (addr & 0x0ffc0000)
37 #define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
39 #define CRB_BLK(off) ((off >> 20) & 0x3f)
40 #define CRB_SUBBLK(off) ((off >> 16) & 0xf)
41 #define CRB_WINDOW_2M (0x130060)
42 #define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000))
43 #define CRB_INDIRECT_2M (0x1e0000UL)
45 static void netxen_nic_io_write_128M(struct netxen_adapter
*adapter
,
46 void __iomem
*addr
, u32 data
);
47 static u32
netxen_nic_io_read_128M(struct netxen_adapter
*adapter
,
50 static inline u64
readq(void __iomem
*addr
)
52 return readl(addr
) | (((u64
) readl(addr
+ 4)) << 32LL);
57 static inline void writeq(u64 val
, void __iomem
*addr
)
59 writel(((u32
) (val
)), (addr
));
60 writel(((u32
) (val
>> 32)), (addr
+ 4));
64 #define PCI_OFFSET_FIRST_RANGE(adapter, off) \
65 ((adapter)->ahw.pci_base0 + (off))
66 #define PCI_OFFSET_SECOND_RANGE(adapter, off) \
67 ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START)
68 #define PCI_OFFSET_THIRD_RANGE(adapter, off) \
69 ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START)
71 static void __iomem
*pci_base_offset(struct netxen_adapter
*adapter
,
74 if (ADDR_IN_RANGE(off
, FIRST_PAGE_GROUP_START
, FIRST_PAGE_GROUP_END
))
75 return PCI_OFFSET_FIRST_RANGE(adapter
, off
);
77 if (ADDR_IN_RANGE(off
, SECOND_PAGE_GROUP_START
, SECOND_PAGE_GROUP_END
))
78 return PCI_OFFSET_SECOND_RANGE(adapter
, off
);
80 if (ADDR_IN_RANGE(off
, THIRD_PAGE_GROUP_START
, THIRD_PAGE_GROUP_END
))
81 return PCI_OFFSET_THIRD_RANGE(adapter
, off
);
86 static crb_128M_2M_block_map_t
87 crb_128M_2M_map
[64] __cacheline_aligned_in_smp
= {
88 {{{0, 0, 0, 0} } }, /* 0: PCI */
89 {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */
90 {1, 0x0110000, 0x0120000, 0x130000},
91 {1, 0x0120000, 0x0122000, 0x124000},
92 {1, 0x0130000, 0x0132000, 0x126000},
93 {1, 0x0140000, 0x0142000, 0x128000},
94 {1, 0x0150000, 0x0152000, 0x12a000},
95 {1, 0x0160000, 0x0170000, 0x110000},
96 {1, 0x0170000, 0x0172000, 0x12e000},
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 {1, 0x01e0000, 0x01e0800, 0x122000},
104 {0, 0x0000000, 0x0000000, 0x000000} } },
105 {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */
106 {{{0, 0, 0, 0} } }, /* 3: */
107 {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */
108 {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */
109 {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */
110 {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */
111 {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */
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, 0x08f0000, 0x08f2000, 0x172000} } },
127 {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/
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, 0x09f0000, 0x09f2000, 0x176000} } },
143 {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/
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 {0, 0x0000000, 0x0000000, 0x000000},
157 {0, 0x0000000, 0x0000000, 0x000000},
158 {1, 0x0af0000, 0x0af2000, 0x17a000} } },
159 {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/
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 {0, 0x0000000, 0x0000000, 0x000000},
173 {0, 0x0000000, 0x0000000, 0x000000},
174 {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
175 {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */
176 {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */
177 {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */
178 {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */
179 {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */
180 {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */
181 {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */
182 {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */
183 {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */
184 {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */
185 {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */
186 {{{0, 0, 0, 0} } }, /* 23: */
187 {{{0, 0, 0, 0} } }, /* 24: */
188 {{{0, 0, 0, 0} } }, /* 25: */
189 {{{0, 0, 0, 0} } }, /* 26: */
190 {{{0, 0, 0, 0} } }, /* 27: */
191 {{{0, 0, 0, 0} } }, /* 28: */
192 {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */
193 {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */
194 {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */
195 {{{0} } }, /* 32: PCI */
196 {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */
197 {1, 0x2110000, 0x2120000, 0x130000},
198 {1, 0x2120000, 0x2122000, 0x124000},
199 {1, 0x2130000, 0x2132000, 0x126000},
200 {1, 0x2140000, 0x2142000, 0x128000},
201 {1, 0x2150000, 0x2152000, 0x12a000},
202 {1, 0x2160000, 0x2170000, 0x110000},
203 {1, 0x2170000, 0x2172000, 0x12e000},
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 {0, 0x0000000, 0x0000000, 0x000000},
211 {0, 0x0000000, 0x0000000, 0x000000} } },
212 {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */
218 {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */
219 {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */
220 {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */
221 {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */
222 {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */
223 {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */
224 {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */
225 {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */
226 {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */
227 {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */
228 {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */
229 {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */
231 {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */
232 {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */
233 {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */
234 {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */
235 {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */
236 {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */
237 {{{0} } }, /* 59: I2C0 */
238 {{{0} } }, /* 60: I2C1 */
239 {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */
240 {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */
241 {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */
245 * top 12 bits of crb internal address (hub, agent)
247 static unsigned crb_hub_agt
[64] =
250 NETXEN_HW_CRB_HUB_AGT_ADR_PS
,
251 NETXEN_HW_CRB_HUB_AGT_ADR_MN
,
252 NETXEN_HW_CRB_HUB_AGT_ADR_MS
,
254 NETXEN_HW_CRB_HUB_AGT_ADR_SRE
,
255 NETXEN_HW_CRB_HUB_AGT_ADR_NIU
,
256 NETXEN_HW_CRB_HUB_AGT_ADR_QMN
,
257 NETXEN_HW_CRB_HUB_AGT_ADR_SQN0
,
258 NETXEN_HW_CRB_HUB_AGT_ADR_SQN1
,
259 NETXEN_HW_CRB_HUB_AGT_ADR_SQN2
,
260 NETXEN_HW_CRB_HUB_AGT_ADR_SQN3
,
261 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q
,
262 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR
,
263 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB
,
264 NETXEN_HW_CRB_HUB_AGT_ADR_PGN4
,
265 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA
,
266 NETXEN_HW_CRB_HUB_AGT_ADR_PGN0
,
267 NETXEN_HW_CRB_HUB_AGT_ADR_PGN1
,
268 NETXEN_HW_CRB_HUB_AGT_ADR_PGN2
,
269 NETXEN_HW_CRB_HUB_AGT_ADR_PGN3
,
270 NETXEN_HW_CRB_HUB_AGT_ADR_PGND
,
271 NETXEN_HW_CRB_HUB_AGT_ADR_PGNI
,
272 NETXEN_HW_CRB_HUB_AGT_ADR_PGS0
,
273 NETXEN_HW_CRB_HUB_AGT_ADR_PGS1
,
274 NETXEN_HW_CRB_HUB_AGT_ADR_PGS2
,
275 NETXEN_HW_CRB_HUB_AGT_ADR_PGS3
,
277 NETXEN_HW_CRB_HUB_AGT_ADR_PGSI
,
278 NETXEN_HW_CRB_HUB_AGT_ADR_SN
,
280 NETXEN_HW_CRB_HUB_AGT_ADR_EG
,
282 NETXEN_HW_CRB_HUB_AGT_ADR_PS
,
283 NETXEN_HW_CRB_HUB_AGT_ADR_CAM
,
289 NETXEN_HW_CRB_HUB_AGT_ADR_TIMR
,
291 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1
,
292 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2
,
293 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3
,
294 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4
,
295 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5
,
296 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6
,
297 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7
,
298 NETXEN_HW_CRB_HUB_AGT_ADR_XDMA
,
299 NETXEN_HW_CRB_HUB_AGT_ADR_I2Q
,
300 NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB
,
302 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0
,
303 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8
,
304 NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9
,
305 NETXEN_HW_CRB_HUB_AGT_ADR_OCM0
,
307 NETXEN_HW_CRB_HUB_AGT_ADR_SMB
,
308 NETXEN_HW_CRB_HUB_AGT_ADR_I2C0
,
309 NETXEN_HW_CRB_HUB_AGT_ADR_I2C1
,
311 NETXEN_HW_CRB_HUB_AGT_ADR_PGNC
,
315 /* PCI Windowing for DDR regions. */
317 #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
319 #define NETXEN_PCIE_SEM_TIMEOUT 10000
321 static int netxen_nic_set_mtu_xgb(struct netxen_adapter
*adapter
, int new_mtu
);
324 netxen_pcie_sem_lock(struct netxen_adapter
*adapter
, int sem
, u32 id_reg
)
326 int done
= 0, timeout
= 0;
329 done
= NXRD32(adapter
, NETXEN_PCIE_REG(PCIE_SEM_LOCK(sem
)));
332 if (++timeout
>= NETXEN_PCIE_SEM_TIMEOUT
)
338 NXWR32(adapter
, id_reg
, adapter
->portnum
);
344 netxen_pcie_sem_unlock(struct netxen_adapter
*adapter
, int sem
)
346 NXRD32(adapter
, NETXEN_PCIE_REG(PCIE_SEM_UNLOCK(sem
)));
349 static int netxen_niu_xg_init_port(struct netxen_adapter
*adapter
, int port
)
351 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
352 NXWR32(adapter
, NETXEN_NIU_XGE_CONFIG_1
+(0x10000*port
), 0x1447);
353 NXWR32(adapter
, NETXEN_NIU_XGE_CONFIG_0
+(0x10000*port
), 0x5);
359 /* Disable an XG interface */
360 static int netxen_niu_disable_xg_port(struct netxen_adapter
*adapter
)
363 u32 port
= adapter
->physical_port
;
365 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
368 if (port
>= NETXEN_NIU_MAX_XG_PORTS
)
373 NETXEN_NIU_XGE_CONFIG_0
+ (0x10000 * port
), mac_cfg
))
378 #define NETXEN_UNICAST_ADDR(port, index) \
379 (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8))
380 #define NETXEN_MCAST_ADDR(port, index) \
381 (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8))
382 #define MAC_HI(addr) \
383 ((addr[2] << 16) | (addr[1] << 8) | (addr[0]))
384 #define MAC_LO(addr) \
385 ((addr[5] << 16) | (addr[4] << 8) | (addr[3]))
387 static int netxen_p2_nic_set_promisc(struct netxen_adapter
*adapter
, u32 mode
)
392 u32 port
= adapter
->physical_port
;
393 u16 board_type
= adapter
->ahw
.board_type
;
395 if (port
>= NETXEN_NIU_MAX_XG_PORTS
)
398 mac_cfg
= NXRD32(adapter
, NETXEN_NIU_XGE_CONFIG_0
+ (0x10000 * port
));
400 NXWR32(adapter
, NETXEN_NIU_XGE_CONFIG_0
+ (0x10000 * port
), mac_cfg
);
402 if ((board_type
== NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
) ||
403 (board_type
== NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
))
404 reg
= (0x20 << port
);
406 NXWR32(adapter
, NETXEN_NIU_FRAME_COUNT_SELECT
, reg
);
410 while (NXRD32(adapter
, NETXEN_NIU_FRAME_COUNT
) && ++cnt
< 20)
415 reg
= NXRD32(adapter
,
416 NETXEN_NIU_XGE_CONFIG_1
+ (0x10000 * port
));
418 if (mode
== NETXEN_NIU_PROMISC_MODE
)
419 reg
= (reg
| 0x2000UL
);
421 reg
= (reg
& ~0x2000UL
);
423 if (mode
== NETXEN_NIU_ALLMULTI_MODE
)
424 reg
= (reg
| 0x1000UL
);
426 reg
= (reg
& ~0x1000UL
);
429 NETXEN_NIU_XGE_CONFIG_1
+ (0x10000 * port
), reg
);
433 NXWR32(adapter
, NETXEN_NIU_XGE_CONFIG_0
+ (0x10000 * port
), mac_cfg
);
438 static int netxen_p2_nic_set_mac_addr(struct netxen_adapter
*adapter
, u8
*addr
)
443 u8 phy
= adapter
->physical_port
;
445 if (phy
>= NETXEN_NIU_MAX_XG_PORTS
)
448 mac_lo
= ((u32
)addr
[0] << 16) | ((u32
)addr
[1] << 24);
449 mac_hi
= addr
[2] | ((u32
)addr
[3] << 8) |
450 ((u32
)addr
[4] << 16) | ((u32
)addr
[5] << 24);
452 reg_lo
= NETXEN_NIU_XGE_STATION_ADDR_0_1
+ (0x10000 * phy
);
453 reg_hi
= NETXEN_NIU_XGE_STATION_ADDR_0_HI
+ (0x10000 * phy
);
455 /* write twice to flush */
456 if (NXWR32(adapter
, reg_lo
, mac_lo
) || NXWR32(adapter
, reg_hi
, mac_hi
))
458 if (NXWR32(adapter
, reg_lo
, mac_lo
) || NXWR32(adapter
, reg_hi
, mac_hi
))
465 netxen_nic_enable_mcast_filter(struct netxen_adapter
*adapter
)
468 u16 port
= adapter
->physical_port
;
469 u8
*addr
= adapter
->mac_addr
;
471 if (adapter
->mc_enabled
)
474 val
= NXRD32(adapter
, NETXEN_MAC_ADDR_CNTL_REG
);
475 val
|= (1UL << (28+port
));
476 NXWR32(adapter
, NETXEN_MAC_ADDR_CNTL_REG
, val
);
478 /* add broadcast addr to filter */
480 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 0), val
);
481 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 0)+4, val
);
483 /* add station addr to filter */
485 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 1), val
);
487 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 1)+4, val
);
489 adapter
->mc_enabled
= 1;
494 netxen_nic_disable_mcast_filter(struct netxen_adapter
*adapter
)
497 u16 port
= adapter
->physical_port
;
498 u8
*addr
= adapter
->mac_addr
;
500 if (!adapter
->mc_enabled
)
503 val
= NXRD32(adapter
, NETXEN_MAC_ADDR_CNTL_REG
);
504 val
&= ~(1UL << (28+port
));
505 NXWR32(adapter
, NETXEN_MAC_ADDR_CNTL_REG
, val
);
508 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 0), val
);
510 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 0)+4, val
);
512 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 1), 0);
513 NXWR32(adapter
, NETXEN_UNICAST_ADDR(port
, 1)+4, 0);
515 adapter
->mc_enabled
= 0;
520 netxen_nic_set_mcast_addr(struct netxen_adapter
*adapter
,
524 u16 port
= adapter
->physical_port
;
529 NXWR32(adapter
, NETXEN_MCAST_ADDR(port
, index
), hi
);
530 NXWR32(adapter
, NETXEN_MCAST_ADDR(port
, index
)+4, lo
);
535 static void netxen_p2_nic_set_multi(struct net_device
*netdev
)
537 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
538 struct netdev_hw_addr
*ha
;
539 u8 null_addr
[ETH_ALEN
];
542 memset(null_addr
, 0, ETH_ALEN
);
544 if (netdev
->flags
& IFF_PROMISC
) {
546 adapter
->set_promisc(adapter
,
547 NETXEN_NIU_PROMISC_MODE
);
549 /* Full promiscuous mode */
550 netxen_nic_disable_mcast_filter(adapter
);
555 if (netdev_mc_empty(netdev
)) {
556 adapter
->set_promisc(adapter
,
557 NETXEN_NIU_NON_PROMISC_MODE
);
558 netxen_nic_disable_mcast_filter(adapter
);
562 adapter
->set_promisc(adapter
, NETXEN_NIU_ALLMULTI_MODE
);
563 if (netdev
->flags
& IFF_ALLMULTI
||
564 netdev_mc_count(netdev
) > adapter
->max_mc_count
) {
565 netxen_nic_disable_mcast_filter(adapter
);
569 netxen_nic_enable_mcast_filter(adapter
);
572 netdev_for_each_mc_addr(ha
, netdev
)
573 netxen_nic_set_mcast_addr(adapter
, i
++, ha
->addr
);
575 /* Clear out remaining addresses */
576 while (i
< adapter
->max_mc_count
)
577 netxen_nic_set_mcast_addr(adapter
, i
++, null_addr
);
581 netxen_send_cmd_descs(struct netxen_adapter
*adapter
,
582 struct cmd_desc_type0
*cmd_desc_arr
, int nr_desc
)
584 u32 i
, producer
, consumer
;
585 struct netxen_cmd_buffer
*pbuf
;
586 struct cmd_desc_type0
*cmd_desc
;
587 struct nx_host_tx_ring
*tx_ring
;
591 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
594 tx_ring
= adapter
->tx_ring
;
595 __netif_tx_lock_bh(tx_ring
->txq
);
597 producer
= tx_ring
->producer
;
598 consumer
= tx_ring
->sw_consumer
;
600 if (nr_desc
>= netxen_tx_avail(tx_ring
)) {
601 netif_tx_stop_queue(tx_ring
->txq
);
603 if (netxen_tx_avail(tx_ring
) > nr_desc
) {
604 if (netxen_tx_avail(tx_ring
) > TX_STOP_THRESH
)
605 netif_tx_wake_queue(tx_ring
->txq
);
607 __netif_tx_unlock_bh(tx_ring
->txq
);
613 cmd_desc
= &cmd_desc_arr
[i
];
615 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
617 pbuf
->frag_count
= 0;
619 memcpy(&tx_ring
->desc_head
[producer
],
620 &cmd_desc_arr
[i
], sizeof(struct cmd_desc_type0
));
622 producer
= get_next_index(producer
, tx_ring
->num_desc
);
625 } while (i
!= nr_desc
);
627 tx_ring
->producer
= producer
;
629 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
631 __netif_tx_unlock_bh(tx_ring
->txq
);
637 nx_p3_sre_macaddr_change(struct netxen_adapter
*adapter
, u8
*addr
, unsigned op
)
640 nx_mac_req_t
*mac_req
;
643 memset(&req
, 0, sizeof(nx_nic_req_t
));
644 req
.qhdr
= cpu_to_le64(NX_NIC_REQUEST
<< 23);
646 word
= NX_MAC_EVENT
| ((u64
)adapter
->portnum
<< 16);
647 req
.req_hdr
= cpu_to_le64(word
);
649 mac_req
= (nx_mac_req_t
*)&req
.words
[0];
651 memcpy(mac_req
->mac_addr
, addr
, 6);
653 return netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
656 static int nx_p3_nic_add_mac(struct netxen_adapter
*adapter
,
657 const u8
*addr
, struct list_head
*del_list
)
659 struct list_head
*head
;
662 /* look up if already exists */
663 list_for_each(head
, del_list
) {
664 cur
= list_entry(head
, nx_mac_list_t
, list
);
666 if (memcmp(addr
, cur
->mac_addr
, ETH_ALEN
) == 0) {
667 list_move_tail(head
, &adapter
->mac_list
);
672 cur
= kzalloc(sizeof(nx_mac_list_t
), GFP_ATOMIC
);
676 memcpy(cur
->mac_addr
, addr
, ETH_ALEN
);
677 list_add_tail(&cur
->list
, &adapter
->mac_list
);
678 return nx_p3_sre_macaddr_change(adapter
,
679 cur
->mac_addr
, NETXEN_MAC_ADD
);
682 static void netxen_p3_nic_set_multi(struct net_device
*netdev
)
684 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
685 struct netdev_hw_addr
*ha
;
686 static const u8 bcast_addr
[ETH_ALEN
] = {
687 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
689 u32 mode
= VPORT_MISS_MODE_DROP
;
691 struct list_head
*head
;
694 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
697 list_splice_tail_init(&adapter
->mac_list
, &del_list
);
699 nx_p3_nic_add_mac(adapter
, adapter
->mac_addr
, &del_list
);
700 nx_p3_nic_add_mac(adapter
, bcast_addr
, &del_list
);
702 if (netdev
->flags
& IFF_PROMISC
) {
703 mode
= VPORT_MISS_MODE_ACCEPT_ALL
;
707 if ((netdev
->flags
& IFF_ALLMULTI
) ||
708 (netdev_mc_count(netdev
) > adapter
->max_mc_count
)) {
709 mode
= VPORT_MISS_MODE_ACCEPT_MULTI
;
713 if (!netdev_mc_empty(netdev
)) {
714 netdev_for_each_mc_addr(ha
, netdev
)
715 nx_p3_nic_add_mac(adapter
, ha
->addr
, &del_list
);
719 adapter
->set_promisc(adapter
, mode
);
721 while (!list_empty(head
)) {
722 cur
= list_entry(head
->next
, nx_mac_list_t
, list
);
724 nx_p3_sre_macaddr_change(adapter
,
725 cur
->mac_addr
, NETXEN_MAC_DEL
);
726 list_del(&cur
->list
);
731 static int netxen_p3_nic_set_promisc(struct netxen_adapter
*adapter
, u32 mode
)
736 memset(&req
, 0, sizeof(nx_nic_req_t
));
738 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
740 word
= NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE
|
741 ((u64
)adapter
->portnum
<< 16);
742 req
.req_hdr
= cpu_to_le64(word
);
744 req
.words
[0] = cpu_to_le64(mode
);
746 return netxen_send_cmd_descs(adapter
,
747 (struct cmd_desc_type0
*)&req
, 1);
750 void netxen_p3_free_mac_list(struct netxen_adapter
*adapter
)
753 struct list_head
*head
= &adapter
->mac_list
;
755 while (!list_empty(head
)) {
756 cur
= list_entry(head
->next
, nx_mac_list_t
, list
);
757 nx_p3_sre_macaddr_change(adapter
,
758 cur
->mac_addr
, NETXEN_MAC_DEL
);
759 list_del(&cur
->list
);
764 static int netxen_p3_nic_set_mac_addr(struct netxen_adapter
*adapter
, u8
*addr
)
766 /* assuming caller has already copied new addr to netdev */
767 netxen_p3_nic_set_multi(adapter
->netdev
);
771 #define NETXEN_CONFIG_INTR_COALESCE 3
774 * Send the interrupt coalescing parameter set by ethtool to the card.
776 int netxen_config_intr_coalesce(struct netxen_adapter
*adapter
)
782 memset(&req
, 0, sizeof(nx_nic_req_t
));
783 memset(word
, 0, sizeof(word
));
785 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
787 word
[0] = NETXEN_CONFIG_INTR_COALESCE
| ((u64
)adapter
->portnum
<< 16);
788 req
.req_hdr
= cpu_to_le64(word
[0]);
790 memcpy(&word
[0], &adapter
->coal
, sizeof(adapter
->coal
));
791 for (i
= 0; i
< 6; i
++)
792 req
.words
[i
] = cpu_to_le64(word
[i
]);
794 rv
= netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
796 printk(KERN_ERR
"ERROR. Could not send "
797 "interrupt coalescing parameters\n");
803 int netxen_config_hw_lro(struct netxen_adapter
*adapter
, int enable
)
809 if (!test_bit(__NX_FW_ATTACHED
, &adapter
->state
))
812 memset(&req
, 0, sizeof(nx_nic_req_t
));
814 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
816 word
= NX_NIC_H2C_OPCODE_CONFIG_HW_LRO
| ((u64
)adapter
->portnum
<< 16);
817 req
.req_hdr
= cpu_to_le64(word
);
819 req
.words
[0] = cpu_to_le64(enable
);
821 rv
= netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
823 printk(KERN_ERR
"ERROR. Could not send "
824 "configure hw lro request\n");
830 int netxen_config_bridged_mode(struct netxen_adapter
*adapter
, int enable
)
836 if (!!(adapter
->flags
& NETXEN_NIC_BRIDGE_ENABLED
) == enable
)
839 memset(&req
, 0, sizeof(nx_nic_req_t
));
841 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
843 word
= NX_NIC_H2C_OPCODE_CONFIG_BRIDGING
|
844 ((u64
)adapter
->portnum
<< 16);
845 req
.req_hdr
= cpu_to_le64(word
);
847 req
.words
[0] = cpu_to_le64(enable
);
849 rv
= netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
851 printk(KERN_ERR
"ERROR. Could not send "
852 "configure bridge mode request\n");
855 adapter
->flags
^= NETXEN_NIC_BRIDGE_ENABLED
;
861 #define RSS_HASHTYPE_IP_TCP 0x3
863 int netxen_config_rss(struct netxen_adapter
*adapter
, int enable
)
869 static const u64 key
[] = {
870 0xbeac01fa6a42b73bULL
, 0x8030f20c77cb2da3ULL
,
871 0xae7b30b4d0ca2bcbULL
, 0x43a38fb04167253dULL
,
872 0x255b0ec26d5a56daULL
876 memset(&req
, 0, sizeof(nx_nic_req_t
));
877 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
879 word
= NX_NIC_H2C_OPCODE_CONFIG_RSS
| ((u64
)adapter
->portnum
<< 16);
880 req
.req_hdr
= cpu_to_le64(word
);
884 * bits 3-0: hash_method
885 * 5-4: hash_type_ipv4
886 * 7-6: hash_type_ipv6
888 * 9: use indirection table
890 * 63-48: indirection table mask
892 word
= ((u64
)(RSS_HASHTYPE_IP_TCP
& 0x3) << 4) |
893 ((u64
)(RSS_HASHTYPE_IP_TCP
& 0x3) << 6) |
894 ((u64
)(enable
& 0x1) << 8) |
896 req
.words
[0] = cpu_to_le64(word
);
897 for (i
= 0; i
< ARRAY_SIZE(key
); i
++)
898 req
.words
[i
+1] = cpu_to_le64(key
[i
]);
901 rv
= netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
903 printk(KERN_ERR
"%s: could not configure RSS\n",
904 adapter
->netdev
->name
);
910 int netxen_config_ipaddr(struct netxen_adapter
*adapter
, __be32 ip
, int cmd
)
916 memset(&req
, 0, sizeof(nx_nic_req_t
));
917 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
919 word
= NX_NIC_H2C_OPCODE_CONFIG_IPADDR
| ((u64
)adapter
->portnum
<< 16);
920 req
.req_hdr
= cpu_to_le64(word
);
922 req
.words
[0] = cpu_to_le64(cmd
);
923 memcpy(&req
.words
[1], &ip
, sizeof(u32
));
925 rv
= netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
927 printk(KERN_ERR
"%s: could not notify %s IP 0x%x reuqest\n",
928 adapter
->netdev
->name
,
929 (cmd
== NX_IP_UP
) ? "Add" : "Remove", ip
);
934 int netxen_linkevent_request(struct netxen_adapter
*adapter
, int enable
)
940 memset(&req
, 0, sizeof(nx_nic_req_t
));
941 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
943 word
= NX_NIC_H2C_OPCODE_GET_LINKEVENT
| ((u64
)adapter
->portnum
<< 16);
944 req
.req_hdr
= cpu_to_le64(word
);
945 req
.words
[0] = cpu_to_le64(enable
| (enable
<< 8));
947 rv
= netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
949 printk(KERN_ERR
"%s: could not configure link notification\n",
950 adapter
->netdev
->name
);
956 int netxen_send_lro_cleanup(struct netxen_adapter
*adapter
)
962 if (!test_bit(__NX_FW_ATTACHED
, &adapter
->state
))
965 memset(&req
, 0, sizeof(nx_nic_req_t
));
966 req
.qhdr
= cpu_to_le64(NX_HOST_REQUEST
<< 23);
968 word
= NX_NIC_H2C_OPCODE_LRO_REQUEST
|
969 ((u64
)adapter
->portnum
<< 16) |
970 ((u64
)NX_NIC_LRO_REQUEST_CLEANUP
<< 56) ;
972 req
.req_hdr
= cpu_to_le64(word
);
974 rv
= netxen_send_cmd_descs(adapter
, (struct cmd_desc_type0
*)&req
, 1);
976 printk(KERN_ERR
"%s: could not cleanup lro flows\n",
977 adapter
->netdev
->name
);
983 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
984 * @returns 0 on success, negative on failure
987 #define MTU_FUDGE_FACTOR 100
989 int netxen_nic_change_mtu(struct net_device
*netdev
, int mtu
)
991 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
995 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
996 max_mtu
= P3_MAX_MTU
;
998 max_mtu
= P2_MAX_MTU
;
1000 if (mtu
> max_mtu
) {
1001 printk(KERN_ERR
"%s: mtu > %d bytes unsupported\n",
1002 netdev
->name
, max_mtu
);
1006 if (adapter
->set_mtu
)
1007 rc
= adapter
->set_mtu(adapter
, mtu
);
1015 static int netxen_get_flash_block(struct netxen_adapter
*adapter
, int base
,
1016 int size
, __le32
* buf
)
1023 for (i
= 0; i
< size
/ sizeof(u32
); i
++) {
1024 if (netxen_rom_fast_read(adapter
, addr
, &v
) == -1)
1026 *ptr32
= cpu_to_le32(v
);
1028 addr
+= sizeof(u32
);
1030 if ((char *)buf
+ size
> (char *)ptr32
) {
1032 if (netxen_rom_fast_read(adapter
, addr
, &v
) == -1)
1034 local
= cpu_to_le32(v
);
1035 memcpy(ptr32
, &local
, (char *)buf
+ size
- (char *)ptr32
);
1041 int netxen_get_flash_mac_addr(struct netxen_adapter
*adapter
, u64
*mac
)
1043 __le32
*pmac
= (__le32
*) mac
;
1046 offset
= NX_FW_MAC_ADDR_OFFSET
+ (adapter
->portnum
* sizeof(u64
));
1048 if (netxen_get_flash_block(adapter
, offset
, sizeof(u64
), pmac
) == -1)
1051 if (*mac
== ~0ULL) {
1053 offset
= NX_OLD_MAC_ADDR_OFFSET
+
1054 (adapter
->portnum
* sizeof(u64
));
1056 if (netxen_get_flash_block(adapter
,
1057 offset
, sizeof(u64
), pmac
) == -1)
1066 int netxen_p3_get_mac_addr(struct netxen_adapter
*adapter
, u64
*mac
)
1068 uint32_t crbaddr
, mac_hi
, mac_lo
;
1069 int pci_func
= adapter
->ahw
.pci_func
;
1071 crbaddr
= CRB_MAC_BLOCK_START
+
1072 (4 * ((pci_func
/2) * 3)) + (4 * (pci_func
& 1));
1074 mac_lo
= NXRD32(adapter
, crbaddr
);
1075 mac_hi
= NXRD32(adapter
, crbaddr
+4);
1078 *mac
= le64_to_cpu((mac_lo
>> 16) | ((u64
)mac_hi
<< 16));
1080 *mac
= le64_to_cpu((u64
)mac_lo
| ((u64
)mac_hi
<< 32));
1086 * Changes the CRB window to the specified window.
1089 netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter
*adapter
,
1092 void __iomem
*offset
;
1094 u8 func
= adapter
->ahw
.pci_func
;
1096 if (adapter
->ahw
.crb_win
== window
)
1099 offset
= PCI_OFFSET_SECOND_RANGE(adapter
,
1100 NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func
)));
1102 writel(window
, offset
);
1104 if (window
== readl(offset
))
1107 if (printk_ratelimit())
1108 dev_warn(&adapter
->pdev
->dev
,
1109 "failed to set CRB window to %d\n",
1110 (window
== NETXEN_WINDOW_ONE
));
1113 } while (--count
> 0);
1116 adapter
->ahw
.crb_win
= window
;
1120 * Returns < 0 if off is not valid,
1121 * 1 if window access is needed. 'off' is set to offset from
1122 * CRB space in 128M pci map
1123 * 0 if no window access is needed. 'off' is set to 2M addr
1124 * In: 'off' is offset from base in 128M pci map
1127 netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter
*adapter
,
1128 ulong off
, void __iomem
**addr
)
1130 crb_128M_2M_sub_block_map_t
*m
;
1133 if ((off
>= NETXEN_CRB_MAX
) || (off
< NETXEN_PCI_CRBSPACE
))
1136 off
-= NETXEN_PCI_CRBSPACE
;
1141 m
= &crb_128M_2M_map
[CRB_BLK(off
)].sub_block
[CRB_SUBBLK(off
)];
1143 if (m
->valid
&& (m
->start_128M
<= off
) && (m
->end_128M
> off
)) {
1144 *addr
= adapter
->ahw
.pci_base0
+ m
->start_2M
+
1145 (off
- m
->start_128M
);
1150 * Not in direct map, use crb window
1152 *addr
= adapter
->ahw
.pci_base0
+ CRB_INDIRECT_2M
+
1158 * In: 'off' is offset from CRB space in 128M pci map
1159 * Out: 'off' is 2M pci map addr
1160 * side effect: lock crb window
1163 netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter
*adapter
, ulong off
)
1166 void __iomem
*addr
= adapter
->ahw
.pci_base0
+ CRB_WINDOW_2M
;
1168 off
-= NETXEN_PCI_CRBSPACE
;
1170 window
= CRB_HI(off
);
1172 writel(window
, addr
);
1173 if (readl(addr
) != window
) {
1174 if (printk_ratelimit())
1175 dev_warn(&adapter
->pdev
->dev
,
1176 "failed to set CRB window to %d off 0x%lx\n",
1181 static void __iomem
*
1182 netxen_nic_map_indirect_address_128M(struct netxen_adapter
*adapter
,
1183 ulong win_off
, void __iomem
**mem_ptr
)
1185 ulong off
= win_off
;
1187 resource_size_t mem_base
;
1189 if (ADDR_IN_WINDOW1(win_off
))
1190 off
= NETXEN_CRB_NORMAL(win_off
);
1192 addr
= pci_base_offset(adapter
, off
);
1196 if (adapter
->ahw
.pci_len0
== 0)
1197 off
-= NETXEN_PCI_CRBSPACE
;
1199 mem_base
= pci_resource_start(adapter
->pdev
, 0);
1200 *mem_ptr
= ioremap(mem_base
+ (off
& PAGE_MASK
), PAGE_SIZE
);
1202 addr
= *mem_ptr
+ (off
& (PAGE_SIZE
- 1));
1208 netxen_nic_hw_write_wx_128M(struct netxen_adapter
*adapter
, ulong off
, u32 data
)
1210 unsigned long flags
;
1211 void __iomem
*addr
, *mem_ptr
= NULL
;
1213 addr
= netxen_nic_map_indirect_address_128M(adapter
, off
, &mem_ptr
);
1217 if (ADDR_IN_WINDOW1(off
)) { /* Window 1 */
1218 netxen_nic_io_write_128M(adapter
, addr
, data
);
1219 } else { /* Window 0 */
1220 write_lock_irqsave(&adapter
->ahw
.crb_lock
, flags
);
1221 netxen_nic_pci_set_crbwindow_128M(adapter
, 0);
1223 netxen_nic_pci_set_crbwindow_128M(adapter
,
1225 write_unlock_irqrestore(&adapter
->ahw
.crb_lock
, flags
);
1235 netxen_nic_hw_read_wx_128M(struct netxen_adapter
*adapter
, ulong off
)
1237 unsigned long flags
;
1238 void __iomem
*addr
, *mem_ptr
= NULL
;
1241 addr
= netxen_nic_map_indirect_address_128M(adapter
, off
, &mem_ptr
);
1245 if (ADDR_IN_WINDOW1(off
)) { /* Window 1 */
1246 data
= netxen_nic_io_read_128M(adapter
, addr
);
1247 } else { /* Window 0 */
1248 write_lock_irqsave(&adapter
->ahw
.crb_lock
, flags
);
1249 netxen_nic_pci_set_crbwindow_128M(adapter
, 0);
1251 netxen_nic_pci_set_crbwindow_128M(adapter
,
1253 write_unlock_irqrestore(&adapter
->ahw
.crb_lock
, flags
);
1263 netxen_nic_hw_write_wx_2M(struct netxen_adapter
*adapter
, ulong off
, u32 data
)
1265 unsigned long flags
;
1267 void __iomem
*addr
= NULL
;
1269 rv
= netxen_nic_pci_get_crb_addr_2M(adapter
, off
, &addr
);
1277 /* indirect access */
1278 write_lock_irqsave(&adapter
->ahw
.crb_lock
, flags
);
1279 crb_win_lock(adapter
);
1280 netxen_nic_pci_set_crbwindow_2M(adapter
, off
);
1282 crb_win_unlock(adapter
);
1283 write_unlock_irqrestore(&adapter
->ahw
.crb_lock
, flags
);
1287 dev_err(&adapter
->pdev
->dev
,
1288 "%s: invalid offset: 0x%016lx\n", __func__
, off
);
1294 netxen_nic_hw_read_wx_2M(struct netxen_adapter
*adapter
, ulong off
)
1296 unsigned long flags
;
1299 void __iomem
*addr
= NULL
;
1301 rv
= netxen_nic_pci_get_crb_addr_2M(adapter
, off
, &addr
);
1307 /* indirect access */
1308 write_lock_irqsave(&adapter
->ahw
.crb_lock
, flags
);
1309 crb_win_lock(adapter
);
1310 netxen_nic_pci_set_crbwindow_2M(adapter
, off
);
1312 crb_win_unlock(adapter
);
1313 write_unlock_irqrestore(&adapter
->ahw
.crb_lock
, flags
);
1317 dev_err(&adapter
->pdev
->dev
,
1318 "%s: invalid offset: 0x%016lx\n", __func__
, off
);
1323 /* window 1 registers only */
1324 static void netxen_nic_io_write_128M(struct netxen_adapter
*adapter
,
1325 void __iomem
*addr
, u32 data
)
1327 read_lock(&adapter
->ahw
.crb_lock
);
1329 read_unlock(&adapter
->ahw
.crb_lock
);
1332 static u32
netxen_nic_io_read_128M(struct netxen_adapter
*adapter
,
1337 read_lock(&adapter
->ahw
.crb_lock
);
1339 read_unlock(&adapter
->ahw
.crb_lock
);
1344 static void netxen_nic_io_write_2M(struct netxen_adapter
*adapter
,
1345 void __iomem
*addr
, u32 data
)
1350 static u32
netxen_nic_io_read_2M(struct netxen_adapter
*adapter
,
1357 netxen_get_ioaddr(struct netxen_adapter
*adapter
, u32 offset
)
1359 void __iomem
*addr
= NULL
;
1361 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1362 if ((offset
< NETXEN_CRB_PCIX_HOST2
) &&
1363 (offset
> NETXEN_CRB_PCIX_HOST
))
1364 addr
= PCI_OFFSET_SECOND_RANGE(adapter
, offset
);
1366 addr
= NETXEN_CRB_NORMALIZE(adapter
, offset
);
1368 WARN_ON(netxen_nic_pci_get_crb_addr_2M(adapter
,
1376 netxen_nic_pci_set_window_128M(struct netxen_adapter
*adapter
,
1377 u64 addr
, u32
*start
)
1379 if (ADDR_IN_RANGE(addr
, NETXEN_ADDR_OCM0
, NETXEN_ADDR_OCM0_MAX
)) {
1380 *start
= (addr
- NETXEN_ADDR_OCM0
+ NETXEN_PCI_OCM0
);
1382 } else if (ADDR_IN_RANGE(addr
,
1383 NETXEN_ADDR_OCM1
, NETXEN_ADDR_OCM1_MAX
)) {
1384 *start
= (addr
- NETXEN_ADDR_OCM1
+ NETXEN_PCI_OCM1
);
1392 netxen_nic_pci_set_window_2M(struct netxen_adapter
*adapter
,
1393 u64 addr
, u32
*start
)
1397 window
= OCM_WIN(addr
);
1399 writel(window
, adapter
->ahw
.ocm_win_crb
);
1400 /* read back to flush */
1401 readl(adapter
->ahw
.ocm_win_crb
);
1403 adapter
->ahw
.ocm_win
= window
;
1404 *start
= NETXEN_PCI_OCM0_2M
+ GET_MEM_OFFS_2M(addr
);
1409 netxen_nic_pci_mem_access_direct(struct netxen_adapter
*adapter
, u64 off
,
1412 void __iomem
*addr
, *mem_ptr
= NULL
;
1413 resource_size_t mem_base
;
1417 spin_lock(&adapter
->ahw
.mem_lock
);
1419 ret
= adapter
->pci_set_window(adapter
, off
, &start
);
1423 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
1424 addr
= adapter
->ahw
.pci_base0
+ start
;
1426 addr
= pci_base_offset(adapter
, start
);
1430 mem_base
= pci_resource_start(adapter
->pdev
, 0) +
1431 (start
& PAGE_MASK
);
1432 mem_ptr
= ioremap(mem_base
, PAGE_SIZE
);
1433 if (mem_ptr
== NULL
) {
1438 addr
= mem_ptr
+ (start
& (PAGE_SIZE
-1));
1441 if (op
== 0) /* read */
1442 *data
= readq(addr
);
1444 writeq(*data
, addr
);
1447 spin_unlock(&adapter
->ahw
.mem_lock
);
1455 netxen_pci_camqm_read_2M(struct netxen_adapter
*adapter
, u64 off
, u64
*data
)
1457 void __iomem
*addr
= adapter
->ahw
.pci_base0
+
1458 NETXEN_PCI_CAMQM_2M_BASE
+ (off
- NETXEN_PCI_CAMQM
);
1460 spin_lock(&adapter
->ahw
.mem_lock
);
1461 *data
= readq(addr
);
1462 spin_unlock(&adapter
->ahw
.mem_lock
);
1466 netxen_pci_camqm_write_2M(struct netxen_adapter
*adapter
, u64 off
, u64 data
)
1468 void __iomem
*addr
= adapter
->ahw
.pci_base0
+
1469 NETXEN_PCI_CAMQM_2M_BASE
+ (off
- NETXEN_PCI_CAMQM
);
1471 spin_lock(&adapter
->ahw
.mem_lock
);
1473 spin_unlock(&adapter
->ahw
.mem_lock
);
1476 #define MAX_CTL_CHECK 1000
1479 netxen_nic_pci_mem_write_128M(struct netxen_adapter
*adapter
,
1483 u32 temp
, off_lo
, off_hi
, addr_hi
, data_hi
, data_lo
;
1484 void __iomem
*mem_crb
;
1486 /* Only 64-bit aligned access */
1490 /* P2 has different SIU and MIU test agent base addr */
1491 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_QDR_NET
,
1492 NETXEN_ADDR_QDR_NET_MAX_P2
)) {
1493 mem_crb
= pci_base_offset(adapter
,
1494 NETXEN_CRB_QDR_NET
+SIU_TEST_AGT_BASE
);
1495 addr_hi
= SIU_TEST_AGT_ADDR_HI
;
1496 data_lo
= SIU_TEST_AGT_WRDATA_LO
;
1497 data_hi
= SIU_TEST_AGT_WRDATA_HI
;
1498 off_lo
= off
& SIU_TEST_AGT_ADDR_MASK
;
1499 off_hi
= SIU_TEST_AGT_UPPER_ADDR(off
);
1503 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_DDR_NET
, NETXEN_ADDR_DDR_NET_MAX
)) {
1504 mem_crb
= pci_base_offset(adapter
,
1505 NETXEN_CRB_DDR_NET
+MIU_TEST_AGT_BASE
);
1506 addr_hi
= MIU_TEST_AGT_ADDR_HI
;
1507 data_lo
= MIU_TEST_AGT_WRDATA_LO
;
1508 data_hi
= MIU_TEST_AGT_WRDATA_HI
;
1509 off_lo
= off
& MIU_TEST_AGT_ADDR_MASK
;
1514 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_OCM0
, NETXEN_ADDR_OCM0_MAX
) ||
1515 ADDR_IN_RANGE(off
, NETXEN_ADDR_OCM1
, NETXEN_ADDR_OCM1_MAX
)) {
1516 if (adapter
->ahw
.pci_len0
!= 0) {
1517 return netxen_nic_pci_mem_access_direct(adapter
,
1525 spin_lock(&adapter
->ahw
.mem_lock
);
1526 netxen_nic_pci_set_crbwindow_128M(adapter
, 0);
1528 writel(off_lo
, (mem_crb
+ MIU_TEST_AGT_ADDR_LO
));
1529 writel(off_hi
, (mem_crb
+ addr_hi
));
1530 writel(data
& 0xffffffff, (mem_crb
+ data_lo
));
1531 writel((data
>> 32) & 0xffffffff, (mem_crb
+ data_hi
));
1532 writel((TA_CTL_ENABLE
| TA_CTL_WRITE
), (mem_crb
+ TEST_AGT_CTRL
));
1533 writel((TA_CTL_START
| TA_CTL_ENABLE
| TA_CTL_WRITE
),
1534 (mem_crb
+ TEST_AGT_CTRL
));
1536 for (j
= 0; j
< MAX_CTL_CHECK
; j
++) {
1537 temp
= readl((mem_crb
+ TEST_AGT_CTRL
));
1538 if ((temp
& TA_CTL_BUSY
) == 0)
1542 if (j
>= MAX_CTL_CHECK
) {
1543 if (printk_ratelimit())
1544 dev_err(&adapter
->pdev
->dev
,
1545 "failed to write through agent\n");
1550 netxen_nic_pci_set_crbwindow_128M(adapter
, NETXEN_WINDOW_ONE
);
1551 spin_unlock(&adapter
->ahw
.mem_lock
);
1556 netxen_nic_pci_mem_read_128M(struct netxen_adapter
*adapter
,
1560 u32 temp
, off_lo
, off_hi
, addr_hi
, data_hi
, data_lo
;
1562 void __iomem
*mem_crb
;
1564 /* Only 64-bit aligned access */
1568 /* P2 has different SIU and MIU test agent base addr */
1569 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_QDR_NET
,
1570 NETXEN_ADDR_QDR_NET_MAX_P2
)) {
1571 mem_crb
= pci_base_offset(adapter
,
1572 NETXEN_CRB_QDR_NET
+SIU_TEST_AGT_BASE
);
1573 addr_hi
= SIU_TEST_AGT_ADDR_HI
;
1574 data_lo
= SIU_TEST_AGT_RDDATA_LO
;
1575 data_hi
= SIU_TEST_AGT_RDDATA_HI
;
1576 off_lo
= off
& SIU_TEST_AGT_ADDR_MASK
;
1577 off_hi
= SIU_TEST_AGT_UPPER_ADDR(off
);
1581 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_DDR_NET
, NETXEN_ADDR_DDR_NET_MAX
)) {
1582 mem_crb
= pci_base_offset(adapter
,
1583 NETXEN_CRB_DDR_NET
+MIU_TEST_AGT_BASE
);
1584 addr_hi
= MIU_TEST_AGT_ADDR_HI
;
1585 data_lo
= MIU_TEST_AGT_RDDATA_LO
;
1586 data_hi
= MIU_TEST_AGT_RDDATA_HI
;
1587 off_lo
= off
& MIU_TEST_AGT_ADDR_MASK
;
1592 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_OCM0
, NETXEN_ADDR_OCM0_MAX
) ||
1593 ADDR_IN_RANGE(off
, NETXEN_ADDR_OCM1
, NETXEN_ADDR_OCM1_MAX
)) {
1594 if (adapter
->ahw
.pci_len0
!= 0) {
1595 return netxen_nic_pci_mem_access_direct(adapter
,
1603 spin_lock(&adapter
->ahw
.mem_lock
);
1604 netxen_nic_pci_set_crbwindow_128M(adapter
, 0);
1606 writel(off_lo
, (mem_crb
+ MIU_TEST_AGT_ADDR_LO
));
1607 writel(off_hi
, (mem_crb
+ addr_hi
));
1608 writel(TA_CTL_ENABLE
, (mem_crb
+ TEST_AGT_CTRL
));
1609 writel((TA_CTL_START
|TA_CTL_ENABLE
), (mem_crb
+ TEST_AGT_CTRL
));
1611 for (j
= 0; j
< MAX_CTL_CHECK
; j
++) {
1612 temp
= readl(mem_crb
+ TEST_AGT_CTRL
);
1613 if ((temp
& TA_CTL_BUSY
) == 0)
1617 if (j
>= MAX_CTL_CHECK
) {
1618 if (printk_ratelimit())
1619 dev_err(&adapter
->pdev
->dev
,
1620 "failed to read through agent\n");
1624 temp
= readl(mem_crb
+ data_hi
);
1625 val
= ((u64
)temp
<< 32);
1626 val
|= readl(mem_crb
+ data_lo
);
1631 netxen_nic_pci_set_crbwindow_128M(adapter
, NETXEN_WINDOW_ONE
);
1632 spin_unlock(&adapter
->ahw
.mem_lock
);
1638 netxen_nic_pci_mem_write_2M(struct netxen_adapter
*adapter
,
1643 void __iomem
*mem_crb
;
1645 /* Only 64-bit aligned access */
1649 /* P3 onward, test agent base for MIU and SIU is same */
1650 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_QDR_NET
,
1651 NETXEN_ADDR_QDR_NET_MAX_P3
)) {
1652 mem_crb
= netxen_get_ioaddr(adapter
,
1653 NETXEN_CRB_QDR_NET
+MIU_TEST_AGT_BASE
);
1657 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_DDR_NET
, NETXEN_ADDR_DDR_NET_MAX
)) {
1658 mem_crb
= netxen_get_ioaddr(adapter
,
1659 NETXEN_CRB_DDR_NET
+MIU_TEST_AGT_BASE
);
1663 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_OCM0
, NETXEN_ADDR_OCM0_MAX
))
1664 return netxen_nic_pci_mem_access_direct(adapter
, off
, &data
, 1);
1669 off8
= off
& 0xfffffff8;
1671 spin_lock(&adapter
->ahw
.mem_lock
);
1673 writel(off8
, (mem_crb
+ MIU_TEST_AGT_ADDR_LO
));
1674 writel(0, (mem_crb
+ MIU_TEST_AGT_ADDR_HI
));
1676 writel(data
& 0xffffffff,
1677 mem_crb
+ MIU_TEST_AGT_WRDATA_LO
);
1678 writel((data
>> 32) & 0xffffffff,
1679 mem_crb
+ MIU_TEST_AGT_WRDATA_HI
);
1681 writel((TA_CTL_ENABLE
| TA_CTL_WRITE
), (mem_crb
+ TEST_AGT_CTRL
));
1682 writel((TA_CTL_START
| TA_CTL_ENABLE
| TA_CTL_WRITE
),
1683 (mem_crb
+ TEST_AGT_CTRL
));
1685 for (j
= 0; j
< MAX_CTL_CHECK
; j
++) {
1686 temp
= readl(mem_crb
+ TEST_AGT_CTRL
);
1687 if ((temp
& TA_CTL_BUSY
) == 0)
1691 if (j
>= MAX_CTL_CHECK
) {
1692 if (printk_ratelimit())
1693 dev_err(&adapter
->pdev
->dev
,
1694 "failed to write through agent\n");
1699 spin_unlock(&adapter
->ahw
.mem_lock
);
1705 netxen_nic_pci_mem_read_2M(struct netxen_adapter
*adapter
,
1711 void __iomem
*mem_crb
;
1713 /* Only 64-bit aligned access */
1717 /* P3 onward, test agent base for MIU and SIU is same */
1718 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_QDR_NET
,
1719 NETXEN_ADDR_QDR_NET_MAX_P3
)) {
1720 mem_crb
= netxen_get_ioaddr(adapter
,
1721 NETXEN_CRB_QDR_NET
+MIU_TEST_AGT_BASE
);
1725 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_DDR_NET
, NETXEN_ADDR_DDR_NET_MAX
)) {
1726 mem_crb
= netxen_get_ioaddr(adapter
,
1727 NETXEN_CRB_DDR_NET
+MIU_TEST_AGT_BASE
);
1731 if (ADDR_IN_RANGE(off
, NETXEN_ADDR_OCM0
, NETXEN_ADDR_OCM0_MAX
)) {
1732 return netxen_nic_pci_mem_access_direct(adapter
,
1739 off8
= off
& 0xfffffff8;
1741 spin_lock(&adapter
->ahw
.mem_lock
);
1743 writel(off8
, (mem_crb
+ MIU_TEST_AGT_ADDR_LO
));
1744 writel(0, (mem_crb
+ MIU_TEST_AGT_ADDR_HI
));
1745 writel(TA_CTL_ENABLE
, (mem_crb
+ TEST_AGT_CTRL
));
1746 writel((TA_CTL_START
| TA_CTL_ENABLE
), (mem_crb
+ TEST_AGT_CTRL
));
1748 for (j
= 0; j
< MAX_CTL_CHECK
; j
++) {
1749 temp
= readl(mem_crb
+ TEST_AGT_CTRL
);
1750 if ((temp
& TA_CTL_BUSY
) == 0)
1754 if (j
>= MAX_CTL_CHECK
) {
1755 if (printk_ratelimit())
1756 dev_err(&adapter
->pdev
->dev
,
1757 "failed to read through agent\n");
1760 val
= (u64
)(readl(mem_crb
+ MIU_TEST_AGT_RDDATA_HI
)) << 32;
1761 val
|= readl(mem_crb
+ MIU_TEST_AGT_RDDATA_LO
);
1766 spin_unlock(&adapter
->ahw
.mem_lock
);
1772 netxen_setup_hwops(struct netxen_adapter
*adapter
)
1774 adapter
->init_port
= netxen_niu_xg_init_port
;
1775 adapter
->stop_port
= netxen_niu_disable_xg_port
;
1777 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1778 adapter
->crb_read
= netxen_nic_hw_read_wx_128M
,
1779 adapter
->crb_write
= netxen_nic_hw_write_wx_128M
,
1780 adapter
->pci_set_window
= netxen_nic_pci_set_window_128M
,
1781 adapter
->pci_mem_read
= netxen_nic_pci_mem_read_128M
,
1782 adapter
->pci_mem_write
= netxen_nic_pci_mem_write_128M
,
1783 adapter
->io_read
= netxen_nic_io_read_128M
,
1784 adapter
->io_write
= netxen_nic_io_write_128M
,
1786 adapter
->macaddr_set
= netxen_p2_nic_set_mac_addr
;
1787 adapter
->set_multi
= netxen_p2_nic_set_multi
;
1788 adapter
->set_mtu
= netxen_nic_set_mtu_xgb
;
1789 adapter
->set_promisc
= netxen_p2_nic_set_promisc
;
1792 adapter
->crb_read
= netxen_nic_hw_read_wx_2M
,
1793 adapter
->crb_write
= netxen_nic_hw_write_wx_2M
,
1794 adapter
->pci_set_window
= netxen_nic_pci_set_window_2M
,
1795 adapter
->pci_mem_read
= netxen_nic_pci_mem_read_2M
,
1796 adapter
->pci_mem_write
= netxen_nic_pci_mem_write_2M
,
1797 adapter
->io_read
= netxen_nic_io_read_2M
,
1798 adapter
->io_write
= netxen_nic_io_write_2M
,
1800 adapter
->set_mtu
= nx_fw_cmd_set_mtu
;
1801 adapter
->set_promisc
= netxen_p3_nic_set_promisc
;
1802 adapter
->macaddr_set
= netxen_p3_nic_set_mac_addr
;
1803 adapter
->set_multi
= netxen_p3_nic_set_multi
;
1805 adapter
->phy_read
= nx_fw_cmd_query_phy
;
1806 adapter
->phy_write
= nx_fw_cmd_set_phy
;
1810 int netxen_nic_get_board_info(struct netxen_adapter
*adapter
)
1812 int offset
, board_type
, magic
;
1813 struct pci_dev
*pdev
= adapter
->pdev
;
1815 offset
= NX_FW_MAGIC_OFFSET
;
1816 if (netxen_rom_fast_read(adapter
, offset
, &magic
))
1819 if (magic
!= NETXEN_BDINFO_MAGIC
) {
1820 dev_err(&pdev
->dev
, "invalid board config, magic=%08x\n",
1825 offset
= NX_BRDTYPE_OFFSET
;
1826 if (netxen_rom_fast_read(adapter
, offset
, &board_type
))
1829 if (board_type
== NETXEN_BRDTYPE_P3_4_GB_MM
) {
1830 u32 gpio
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_PAD_GPIO_I
);
1831 if ((gpio
& 0x8000) == 0)
1832 board_type
= NETXEN_BRDTYPE_P3_10G_TP
;
1835 adapter
->ahw
.board_type
= board_type
;
1837 switch (board_type
) {
1838 case NETXEN_BRDTYPE_P2_SB35_4G
:
1839 adapter
->ahw
.port_type
= NETXEN_NIC_GBE
;
1841 case NETXEN_BRDTYPE_P2_SB31_10G
:
1842 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
1843 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
1844 case NETXEN_BRDTYPE_P2_SB31_10G_CX4
:
1845 case NETXEN_BRDTYPE_P3_HMEZ
:
1846 case NETXEN_BRDTYPE_P3_XG_LOM
:
1847 case NETXEN_BRDTYPE_P3_10G_CX4
:
1848 case NETXEN_BRDTYPE_P3_10G_CX4_LP
:
1849 case NETXEN_BRDTYPE_P3_IMEZ
:
1850 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS
:
1851 case NETXEN_BRDTYPE_P3_10G_SFP_CT
:
1852 case NETXEN_BRDTYPE_P3_10G_SFP_QT
:
1853 case NETXEN_BRDTYPE_P3_10G_XFP
:
1854 case NETXEN_BRDTYPE_P3_10000_BASE_T
:
1855 adapter
->ahw
.port_type
= NETXEN_NIC_XGBE
;
1857 case NETXEN_BRDTYPE_P1_BD
:
1858 case NETXEN_BRDTYPE_P1_SB
:
1859 case NETXEN_BRDTYPE_P1_SMAX
:
1860 case NETXEN_BRDTYPE_P1_SOCK
:
1861 case NETXEN_BRDTYPE_P3_REF_QG
:
1862 case NETXEN_BRDTYPE_P3_4_GB
:
1863 case NETXEN_BRDTYPE_P3_4_GB_MM
:
1864 adapter
->ahw
.port_type
= NETXEN_NIC_GBE
;
1866 case NETXEN_BRDTYPE_P3_10G_TP
:
1867 adapter
->ahw
.port_type
= (adapter
->portnum
< 2) ?
1868 NETXEN_NIC_XGBE
: NETXEN_NIC_GBE
;
1871 dev_err(&pdev
->dev
, "unknown board type %x\n", board_type
);
1872 adapter
->ahw
.port_type
= NETXEN_NIC_XGBE
;
1879 /* NIU access sections */
1880 static int netxen_nic_set_mtu_xgb(struct netxen_adapter
*adapter
, int new_mtu
)
1882 new_mtu
+= MTU_FUDGE_FACTOR
;
1883 if (adapter
->physical_port
== 0)
1884 NXWR32(adapter
, NETXEN_NIU_XGE_MAX_FRAME_SIZE
, new_mtu
);
1886 NXWR32(adapter
, NETXEN_NIU_XG1_MAX_FRAME_SIZE
, new_mtu
);
1890 void netxen_nic_set_link_parameters(struct netxen_adapter
*adapter
)
1896 if (!netif_carrier_ok(adapter
->netdev
)) {
1897 adapter
->link_speed
= 0;
1898 adapter
->link_duplex
= -1;
1899 adapter
->link_autoneg
= AUTONEG_ENABLE
;
1903 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
1904 port_mode
= NXRD32(adapter
, NETXEN_PORT_MODE_ADDR
);
1905 if (port_mode
== NETXEN_PORT_MODE_802_3_AP
) {
1906 adapter
->link_speed
= SPEED_1000
;
1907 adapter
->link_duplex
= DUPLEX_FULL
;
1908 adapter
->link_autoneg
= AUTONEG_DISABLE
;
1912 if (adapter
->phy_read
&&
1913 adapter
->phy_read(adapter
,
1914 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS
,
1916 if (netxen_get_phy_link(status
)) {
1917 switch (netxen_get_phy_speed(status
)) {
1919 adapter
->link_speed
= SPEED_10
;
1922 adapter
->link_speed
= SPEED_100
;
1925 adapter
->link_speed
= SPEED_1000
;
1928 adapter
->link_speed
= 0;
1931 switch (netxen_get_phy_duplex(status
)) {
1933 adapter
->link_duplex
= DUPLEX_HALF
;
1936 adapter
->link_duplex
= DUPLEX_FULL
;
1939 adapter
->link_duplex
= -1;
1942 if (adapter
->phy_read
&&
1943 adapter
->phy_read(adapter
,
1944 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG
,
1946 adapter
->link_autoneg
= autoneg
;
1951 adapter
->link_speed
= 0;
1952 adapter
->link_duplex
= -1;
1958 netxen_nic_wol_supported(struct netxen_adapter
*adapter
)
1962 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1965 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG_NV
);
1966 if (wol_cfg
& (1UL << adapter
->portnum
)) {
1967 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG
);
1968 if (wol_cfg
& (1 << adapter
->portnum
))
1975 static u32
netxen_md_cntrl(struct netxen_adapter
*adapter
,
1976 struct netxen_minidump_template_hdr
*template_hdr
,
1977 struct netxen_minidump_entry_crb
*crtEntry
)
1979 int loop_cnt
, i
, rv
= 0, timeout_flag
;
1980 u32 op_count
, stride
;
1981 u32 opcode
, read_value
, addr
;
1982 unsigned long timeout
, timeout_jiffies
;
1983 addr
= crtEntry
->addr
;
1984 op_count
= crtEntry
->op_count
;
1985 stride
= crtEntry
->addr_stride
;
1987 for (loop_cnt
= 0; loop_cnt
< op_count
; loop_cnt
++) {
1988 for (i
= 0; i
< sizeof(crtEntry
->opcode
) * 8; i
++) {
1989 opcode
= (crtEntry
->opcode
& (0x1 << i
));
1993 NX_WR_DUMP_REG(addr
,
1994 adapter
->ahw
.pci_base0
,
1998 NX_RD_DUMP_REG(addr
,
1999 adapter
->ahw
.pci_base0
,
2001 NX_WR_DUMP_REG(addr
,
2002 adapter
->ahw
.pci_base0
,
2005 case NX_DUMP_ANDCRB
:
2006 NX_RD_DUMP_REG(addr
,
2007 adapter
->ahw
.pci_base0
,
2009 read_value
&= crtEntry
->value_2
;
2010 NX_WR_DUMP_REG(addr
,
2011 adapter
->ahw
.pci_base0
,
2015 NX_RD_DUMP_REG(addr
,
2016 adapter
->ahw
.pci_base0
,
2018 read_value
|= crtEntry
->value_3
;
2019 NX_WR_DUMP_REG(addr
,
2020 adapter
->ahw
.pci_base0
,
2023 case NX_DUMP_POLLCRB
:
2024 timeout
= crtEntry
->poll_timeout
;
2025 NX_RD_DUMP_REG(addr
,
2026 adapter
->ahw
.pci_base0
,
2029 msecs_to_jiffies(timeout
) + jiffies
;
2030 for (timeout_flag
= 0;
2032 && ((read_value
& crtEntry
->value_2
)
2033 != crtEntry
->value_1
);) {
2034 if (time_after(jiffies
,
2037 NX_RD_DUMP_REG(addr
,
2038 adapter
->ahw
.pci_base0
,
2043 dev_err(&adapter
->pdev
->dev
, "%s : "
2044 "Timeout in poll_crb control operation.\n"
2049 case NX_DUMP_RD_SAVE
:
2050 /* Decide which address to use */
2051 if (crtEntry
->state_index_a
)
2053 template_hdr
->saved_state_array
2054 [crtEntry
->state_index_a
];
2055 NX_RD_DUMP_REG(addr
,
2056 adapter
->ahw
.pci_base0
,
2058 template_hdr
->saved_state_array
2059 [crtEntry
->state_index_v
]
2062 case NX_DUMP_WRT_SAVED
:
2063 /* Decide which value to use */
2064 if (crtEntry
->state_index_v
)
2066 template_hdr
->saved_state_array
2067 [crtEntry
->state_index_v
];
2069 read_value
= crtEntry
->value_1
;
2071 /* Decide which address to use */
2072 if (crtEntry
->state_index_a
)
2074 template_hdr
->saved_state_array
2075 [crtEntry
->state_index_a
];
2077 NX_WR_DUMP_REG(addr
,
2078 adapter
->ahw
.pci_base0
,
2081 case NX_DUMP_MOD_SAVE_ST
:
2083 template_hdr
->saved_state_array
2084 [crtEntry
->state_index_v
];
2085 read_value
<<= crtEntry
->shl
;
2086 read_value
>>= crtEntry
->shr
;
2087 if (crtEntry
->value_2
)
2090 read_value
|= crtEntry
->value_3
;
2091 read_value
+= crtEntry
->value_1
;
2092 /* Write value back to state area.*/
2093 template_hdr
->saved_state_array
2094 [crtEntry
->state_index_v
]
2103 addr
= addr
+ stride
;
2108 /* Read memory or MN */
2110 netxen_md_rdmem(struct netxen_adapter
*adapter
,
2111 struct netxen_minidump_entry_rdmem
2112 *memEntry
, u64
*data_buff
)
2114 u64 addr
, value
= 0;
2115 int i
= 0, loop_cnt
;
2117 addr
= (u64
)memEntry
->read_addr
;
2118 loop_cnt
= memEntry
->read_data_size
; /* This is size in bytes */
2119 loop_cnt
/= sizeof(value
);
2121 for (i
= 0; i
< loop_cnt
; i
++) {
2122 if (netxen_nic_pci_mem_read_2M(adapter
, addr
, &value
))
2124 *data_buff
++ = value
;
2125 addr
+= sizeof(value
);
2128 return i
* sizeof(value
);
2131 /* Read CRB operation */
2132 static u32
netxen_md_rd_crb(struct netxen_adapter
*adapter
,
2133 struct netxen_minidump_entry_crb
2134 *crbEntry
, u32
*data_buff
)
2137 u32 op_count
, addr
, stride
, value
;
2139 addr
= crbEntry
->addr
;
2140 op_count
= crbEntry
->op_count
;
2141 stride
= crbEntry
->addr_stride
;
2143 for (loop_cnt
= 0; loop_cnt
< op_count
; loop_cnt
++) {
2144 NX_RD_DUMP_REG(addr
, adapter
->ahw
.pci_base0
, &value
);
2145 *data_buff
++ = addr
;
2146 *data_buff
++ = value
;
2147 addr
= addr
+ stride
;
2149 return loop_cnt
* (2 * sizeof(u32
));
2154 netxen_md_rdrom(struct netxen_adapter
*adapter
,
2155 struct netxen_minidump_entry_rdrom
2156 *romEntry
, __le32
*data_buff
)
2161 u32 fl_addr
, waddr
, raddr
;
2162 fl_addr
= romEntry
->read_addr
;
2163 size
= romEntry
->read_data_size
/4;
2165 lck_val
= readl((void __iomem
*)(adapter
->ahw
.pci_base0
+
2167 if (!lck_val
&& count
< MAX_CTL_CHECK
) {
2172 writel(adapter
->ahw
.pci_func
, (void __iomem
*)(adapter
->ahw
.pci_base0
+
2174 for (i
= 0; i
< size
; i
++) {
2175 waddr
= fl_addr
& 0xFFFF0000;
2176 NX_WR_DUMP_REG(FLASH_ROM_WINDOW
, adapter
->ahw
.pci_base0
, waddr
);
2177 raddr
= FLASH_ROM_DATA
+ (fl_addr
& 0x0000FFFF);
2178 NX_RD_DUMP_REG(raddr
, adapter
->ahw
.pci_base0
, &val
);
2179 *data_buff
++ = cpu_to_le32(val
);
2180 fl_addr
+= sizeof(val
);
2182 readl((void __iomem
*)(adapter
->ahw
.pci_base0
+ NX_FLASH_SEM2_ULK
));
2183 return romEntry
->read_data_size
;
2186 /* Handle L2 Cache */
2188 netxen_md_L2Cache(struct netxen_adapter
*adapter
,
2189 struct netxen_minidump_entry_cache
2190 *cacheEntry
, u32
*data_buff
)
2192 int loop_cnt
, i
, k
, timeout_flag
= 0;
2193 u32 addr
, read_addr
, read_value
, cntrl_addr
, tag_reg_addr
;
2194 u32 tag_value
, read_cnt
;
2195 u8 cntl_value_w
, cntl_value_r
;
2196 unsigned long timeout
, timeout_jiffies
;
2198 loop_cnt
= cacheEntry
->op_count
;
2199 read_addr
= cacheEntry
->read_addr
;
2200 cntrl_addr
= cacheEntry
->control_addr
;
2201 cntl_value_w
= (u32
) cacheEntry
->write_value
;
2202 tag_reg_addr
= cacheEntry
->tag_reg_addr
;
2203 tag_value
= cacheEntry
->init_tag_value
;
2204 read_cnt
= cacheEntry
->read_addr_cnt
;
2206 for (i
= 0; i
< loop_cnt
; i
++) {
2207 NX_WR_DUMP_REG(tag_reg_addr
, adapter
->ahw
.pci_base0
, tag_value
);
2209 NX_WR_DUMP_REG(cntrl_addr
, adapter
->ahw
.pci_base0
,
2211 if (cacheEntry
->poll_mask
) {
2212 timeout
= cacheEntry
->poll_wait
;
2213 NX_RD_DUMP_REG(cntrl_addr
, adapter
->ahw
.pci_base0
,
2215 timeout_jiffies
= msecs_to_jiffies(timeout
) + jiffies
;
2216 for (timeout_flag
= 0; !timeout_flag
&&
2217 ((cntl_value_r
& cacheEntry
->poll_mask
) != 0);) {
2218 if (time_after(jiffies
, timeout_jiffies
))
2220 NX_RD_DUMP_REG(cntrl_addr
,
2221 adapter
->ahw
.pci_base0
,
2225 dev_err(&adapter
->pdev
->dev
,
2226 "Timeout in processing L2 Tag poll.\n");
2231 for (k
= 0; k
< read_cnt
; k
++) {
2232 NX_RD_DUMP_REG(addr
, adapter
->ahw
.pci_base0
,
2234 *data_buff
++ = read_value
;
2235 addr
+= cacheEntry
->read_addr_stride
;
2237 tag_value
+= cacheEntry
->tag_value_stride
;
2239 return read_cnt
* loop_cnt
* sizeof(read_value
);
2243 /* Handle L1 Cache */
2244 static u32
netxen_md_L1Cache(struct netxen_adapter
*adapter
,
2245 struct netxen_minidump_entry_cache
2246 *cacheEntry
, u32
*data_buff
)
2249 u32 addr
, read_addr
, read_value
, cntrl_addr
, tag_reg_addr
;
2250 u32 tag_value
, read_cnt
;
2253 loop_cnt
= cacheEntry
->op_count
;
2254 read_addr
= cacheEntry
->read_addr
;
2255 cntrl_addr
= cacheEntry
->control_addr
;
2256 cntl_value_w
= (u32
) cacheEntry
->write_value
;
2257 tag_reg_addr
= cacheEntry
->tag_reg_addr
;
2258 tag_value
= cacheEntry
->init_tag_value
;
2259 read_cnt
= cacheEntry
->read_addr_cnt
;
2261 for (i
= 0; i
< loop_cnt
; i
++) {
2262 NX_WR_DUMP_REG(tag_reg_addr
, adapter
->ahw
.pci_base0
, tag_value
);
2263 NX_WR_DUMP_REG(cntrl_addr
, adapter
->ahw
.pci_base0
,
2264 (u32
) cntl_value_w
);
2266 for (k
= 0; k
< read_cnt
; k
++) {
2267 NX_RD_DUMP_REG(addr
,
2268 adapter
->ahw
.pci_base0
,
2270 *data_buff
++ = read_value
;
2271 addr
+= cacheEntry
->read_addr_stride
;
2273 tag_value
+= cacheEntry
->tag_value_stride
;
2275 return read_cnt
* loop_cnt
* sizeof(read_value
);
2278 /* Reading OCM memory */
2280 netxen_md_rdocm(struct netxen_adapter
*adapter
,
2281 struct netxen_minidump_entry_rdocm
2282 *ocmEntry
, u32
*data_buff
)
2287 addr
= (ocmEntry
->read_addr
+ adapter
->ahw
.pci_base0
);
2288 loop_cnt
= ocmEntry
->op_count
;
2290 for (i
= 0; i
< loop_cnt
; i
++) {
2291 value
= readl(addr
);
2292 *data_buff
++ = value
;
2293 addr
+= ocmEntry
->read_addr_stride
;
2295 return i
* sizeof(u32
);
2300 netxen_md_rdmux(struct netxen_adapter
*adapter
, struct netxen_minidump_entry_mux
2301 *muxEntry
, u32
*data_buff
)
2304 u32 read_addr
, read_value
, select_addr
, sel_value
;
2306 read_addr
= muxEntry
->read_addr
;
2307 sel_value
= muxEntry
->select_value
;
2308 select_addr
= muxEntry
->select_addr
;
2310 for (loop_cnt
= 0; loop_cnt
< muxEntry
->op_count
; loop_cnt
++) {
2311 NX_WR_DUMP_REG(select_addr
, adapter
->ahw
.pci_base0
, sel_value
);
2312 NX_RD_DUMP_REG(read_addr
, adapter
->ahw
.pci_base0
, &read_value
);
2313 *data_buff
++ = sel_value
;
2314 *data_buff
++ = read_value
;
2315 sel_value
+= muxEntry
->select_value_stride
;
2317 return loop_cnt
* (2 * sizeof(u32
));
2320 /* Handling Queue State Reads */
2322 netxen_md_rdqueue(struct netxen_adapter
*adapter
,
2323 struct netxen_minidump_entry_queue
2324 *queueEntry
, u32
*data_buff
)
2327 u32 queue_id
, read_addr
, read_value
, read_stride
, select_addr
, read_cnt
;
2329 read_cnt
= queueEntry
->read_addr_cnt
;
2330 read_stride
= queueEntry
->read_addr_stride
;
2331 select_addr
= queueEntry
->select_addr
;
2333 for (loop_cnt
= 0, queue_id
= 0; loop_cnt
< queueEntry
->op_count
;
2335 NX_WR_DUMP_REG(select_addr
, adapter
->ahw
.pci_base0
, queue_id
);
2336 read_addr
= queueEntry
->read_addr
;
2337 for (k
= 0; k
< read_cnt
; k
--) {
2338 NX_RD_DUMP_REG(read_addr
, adapter
->ahw
.pci_base0
,
2340 *data_buff
++ = read_value
;
2341 read_addr
+= read_stride
;
2343 queue_id
+= queueEntry
->queue_id_stride
;
2345 return loop_cnt
* (read_cnt
* sizeof(read_value
));
2350 * We catch an error where driver does not read
2351 * as much data as we expect from the entry.
2354 static int netxen_md_entry_err_chk(struct netxen_adapter
*adapter
,
2355 struct netxen_minidump_entry
*entry
, int esize
)
2358 entry
->hdr
.driver_flags
|= NX_DUMP_SKIP
;
2361 if (esize
!= entry
->hdr
.entry_capture_size
) {
2362 entry
->hdr
.entry_capture_size
= esize
;
2363 entry
->hdr
.driver_flags
|= NX_DUMP_SIZE_ERR
;
2364 dev_info(&adapter
->pdev
->dev
,
2365 "Invalidate dump, Type:%d\tMask:%d\tSize:%dCap_size:%d\n",
2366 entry
->hdr
.entry_type
, entry
->hdr
.entry_capture_mask
,
2367 esize
, entry
->hdr
.entry_capture_size
);
2368 dev_info(&adapter
->pdev
->dev
, "Aborting further dump capture\n");
2373 static int netxen_parse_md_template(struct netxen_adapter
*adapter
)
2375 int num_of_entries
, buff_level
, e_cnt
, esize
;
2376 int end_cnt
= 0, rv
= 0, sane_start
= 0, sane_end
= 0;
2378 void *template_buff
= adapter
->mdump
.md_template
;
2379 char *dump_buff
= adapter
->mdump
.md_capture_buff
;
2380 int capture_mask
= adapter
->mdump
.md_capture_mask
;
2381 struct netxen_minidump_template_hdr
*template_hdr
;
2382 struct netxen_minidump_entry
*entry
;
2384 if ((capture_mask
& 0x3) != 0x3) {
2385 dev_err(&adapter
->pdev
->dev
, "Capture mask %02x below minimum needed "
2386 "for valid firmware dump\n", capture_mask
);
2389 template_hdr
= (struct netxen_minidump_template_hdr
*) template_buff
;
2390 num_of_entries
= template_hdr
->num_of_entries
;
2391 entry
= (struct netxen_minidump_entry
*) ((char *) template_buff
+
2392 template_hdr
->first_entry_offset
);
2393 memcpy(dump_buff
, template_buff
, adapter
->mdump
.md_template_size
);
2394 dump_buff
= dump_buff
+ adapter
->mdump
.md_template_size
;
2396 if (template_hdr
->entry_type
== TLHDR
)
2399 for (e_cnt
= 0, buff_level
= 0; e_cnt
< num_of_entries
; e_cnt
++) {
2400 if (!(entry
->hdr
.entry_capture_mask
& capture_mask
)) {
2401 entry
->hdr
.driver_flags
|= NX_DUMP_SKIP
;
2402 entry
= (struct netxen_minidump_entry
*)
2403 ((char *) entry
+ entry
->hdr
.entry_size
);
2406 switch (entry
->hdr
.entry_type
) {
2408 entry
->hdr
.driver_flags
|= NX_DUMP_SKIP
;
2411 entry
->hdr
.driver_flags
|= NX_DUMP_SKIP
;
2417 rv
= netxen_md_cntrl(adapter
,
2418 template_hdr
, (void *)entry
);
2420 entry
->hdr
.driver_flags
|= NX_DUMP_SKIP
;
2423 dbuff
= dump_buff
+ buff_level
;
2424 esize
= netxen_md_rd_crb(adapter
,
2425 (void *) entry
, (void *) dbuff
);
2426 rv
= netxen_md_entry_err_chk
2427 (adapter
, entry
, esize
);
2430 buff_level
+= esize
;
2434 dbuff
= dump_buff
+ buff_level
;
2435 esize
= netxen_md_rdmem(adapter
,
2436 (void *) entry
, (void *) dbuff
);
2437 rv
= netxen_md_entry_err_chk
2438 (adapter
, entry
, esize
);
2441 buff_level
+= esize
;
2445 dbuff
= dump_buff
+ buff_level
;
2446 esize
= netxen_md_rdrom(adapter
,
2447 (void *) entry
, (void *) dbuff
);
2448 rv
= netxen_md_entry_err_chk
2449 (adapter
, entry
, esize
);
2452 buff_level
+= esize
;
2458 dbuff
= dump_buff
+ buff_level
;
2459 esize
= netxen_md_L2Cache(adapter
,
2460 (void *) entry
, (void *) dbuff
);
2461 rv
= netxen_md_entry_err_chk
2462 (adapter
, entry
, esize
);
2465 buff_level
+= esize
;
2469 dbuff
= dump_buff
+ buff_level
;
2470 esize
= netxen_md_L1Cache(adapter
,
2471 (void *) entry
, (void *) dbuff
);
2472 rv
= netxen_md_entry_err_chk
2473 (adapter
, entry
, esize
);
2476 buff_level
+= esize
;
2479 dbuff
= dump_buff
+ buff_level
;
2480 esize
= netxen_md_rdocm(adapter
,
2481 (void *) entry
, (void *) dbuff
);
2482 rv
= netxen_md_entry_err_chk
2483 (adapter
, entry
, esize
);
2486 buff_level
+= esize
;
2489 dbuff
= dump_buff
+ buff_level
;
2490 esize
= netxen_md_rdmux(adapter
,
2491 (void *) entry
, (void *) dbuff
);
2492 rv
= netxen_md_entry_err_chk
2493 (adapter
, entry
, esize
);
2496 buff_level
+= esize
;
2499 dbuff
= dump_buff
+ buff_level
;
2500 esize
= netxen_md_rdqueue(adapter
,
2501 (void *) entry
, (void *) dbuff
);
2502 rv
= netxen_md_entry_err_chk
2503 (adapter
, entry
, esize
);
2506 buff_level
+= esize
;
2509 entry
->hdr
.driver_flags
|= NX_DUMP_SKIP
;
2512 /* Next entry in the template */
2513 entry
= (struct netxen_minidump_entry
*)
2514 ((char *) entry
+ entry
->hdr
.entry_size
);
2516 if (!sane_start
|| sane_end
> 1) {
2517 dev_err(&adapter
->pdev
->dev
,
2518 "Firmware minidump template configuration error.\n");
2524 netxen_collect_minidump(struct netxen_adapter
*adapter
)
2527 struct netxen_minidump_template_hdr
*hdr
;
2528 struct timespec val
;
2529 hdr
= (struct netxen_minidump_template_hdr
*)
2530 adapter
->mdump
.md_template
;
2531 hdr
->driver_capture_mask
= adapter
->mdump
.md_capture_mask
;
2532 jiffies_to_timespec(jiffies
, &val
);
2533 hdr
->driver_timestamp
= (u32
) val
.tv_sec
;
2534 hdr
->driver_info_word2
= adapter
->fw_version
;
2535 hdr
->driver_info_word3
= NXRD32(adapter
, CRB_DRIVER_VERSION
);
2536 ret
= netxen_parse_md_template(adapter
);
2545 netxen_dump_fw(struct netxen_adapter
*adapter
)
2547 struct netxen_minidump_template_hdr
*hdr
;
2548 int i
, k
, data_size
= 0;
2550 hdr
= (struct netxen_minidump_template_hdr
*)
2551 adapter
->mdump
.md_template
;
2552 capture_mask
= adapter
->mdump
.md_capture_mask
;
2554 for (i
= 0x2, k
= 1; (i
& NX_DUMP_MASK_MAX
); i
<<= 1, k
++) {
2555 if (i
& capture_mask
)
2556 data_size
+= hdr
->capture_size_array
[k
];
2559 dev_err(&adapter
->pdev
->dev
,
2560 "Invalid cap sizes for capture_mask=0x%x\n",
2561 adapter
->mdump
.md_capture_mask
);
2564 adapter
->mdump
.md_capture_size
= data_size
;
2565 adapter
->mdump
.md_dump_size
= adapter
->mdump
.md_template_size
+
2566 adapter
->mdump
.md_capture_size
;
2567 if (!adapter
->mdump
.md_capture_buff
) {
2568 adapter
->mdump
.md_capture_buff
=
2569 vzalloc(adapter
->mdump
.md_dump_size
);
2570 if (!adapter
->mdump
.md_capture_buff
)
2573 if (netxen_collect_minidump(adapter
)) {
2574 adapter
->mdump
.has_valid_dump
= 0;
2575 adapter
->mdump
.md_dump_size
= 0;
2576 vfree(adapter
->mdump
.md_capture_buff
);
2577 adapter
->mdump
.md_capture_buff
= NULL
;
2578 dev_err(&adapter
->pdev
->dev
,
2579 "Error in collecting firmware minidump.\n");
2581 adapter
->mdump
.md_timestamp
= jiffies
;
2582 adapter
->mdump
.has_valid_dump
= 1;
2583 adapter
->fw_mdump_rdy
= 1;
2584 dev_info(&adapter
->pdev
->dev
, "%s Successfully "
2585 "collected fw dump.\n", adapter
->netdev
->name
);
2589 dev_info(&adapter
->pdev
->dev
,
2590 "Cannot overwrite previously collected "
2591 "firmware minidump.\n");
2592 adapter
->fw_mdump_rdy
= 1;