2 * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/netdevice.h>
37 #include <linux/etherdevice.h>
38 #include <linux/ethtool.h>
39 #include <linux/mii.h>
40 #include <linux/if_vlan.h>
41 #include <linux/crc32.h>
44 #include <linux/tcp.h>
45 #include <linux/init.h>
49 #include <asm/byteorder.h>
55 static u16
nes_read16_eeprom(void __iomem
*addr
, u16 offset
);
61 * nes_read_eeprom_values -
63 int nes_read_eeprom_values(struct nes_device
*nesdev
, struct nes_adapter
*nesadapter
)
69 u16 next_section_address
;
74 /* TODO: deal with EEPROM endian issues */
75 if (nesadapter
->firmware_eeprom_offset
== 0) {
76 /* Read the EEPROM Parameters */
77 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, 0);
78 nes_debug(NES_DBG_HW
, "EEPROM Offset 0 = 0x%04X\n", eeprom_data
);
79 eeprom_offset
= 2 + (((eeprom_data
& 0x007f) << 3) <<
80 ((eeprom_data
& 0x0080) >> 7));
81 nes_debug(NES_DBG_HW
, "Firmware Offset = 0x%04X\n", eeprom_offset
);
82 nesadapter
->firmware_eeprom_offset
= eeprom_offset
;
83 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
+ 4);
84 if (eeprom_data
!= 0x5746) {
85 nes_debug(NES_DBG_HW
, "Not a valid Firmware Image = 0x%04X\n", eeprom_data
);
89 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
+ 2);
90 nes_debug(NES_DBG_HW
, "EEPROM Offset %u = 0x%04X\n",
91 eeprom_offset
+ 2, eeprom_data
);
92 eeprom_offset
+= ((eeprom_data
& 0x00ff) << 3) << ((eeprom_data
& 0x0100) >> 8);
93 nes_debug(NES_DBG_HW
, "Software Offset = 0x%04X\n", eeprom_offset
);
94 nesadapter
->software_eeprom_offset
= eeprom_offset
;
95 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
+ 4);
96 if (eeprom_data
!= 0x5753) {
97 printk("Not a valid Software Image = 0x%04X\n", eeprom_data
);
100 sw_section_ver
= nes_read16_eeprom(nesdev
->regs
, nesadapter
->software_eeprom_offset
+ 6);
101 nes_debug(NES_DBG_HW
, "Software section version number = 0x%04X\n",
104 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
+ 2);
105 nes_debug(NES_DBG_HW
, "EEPROM Offset %u (next section) = 0x%04X\n",
106 eeprom_offset
+ 2, eeprom_data
);
107 next_section_address
= eeprom_offset
+ (((eeprom_data
& 0x00ff) << 3) <<
108 ((eeprom_data
& 0x0100) >> 8));
109 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, next_section_address
+ 4);
110 if (eeprom_data
!= 0x414d) {
111 nes_debug(NES_DBG_HW
, "EEPROM Changed offset should be 0x414d but was 0x%04X\n",
115 eeprom_offset
= next_section_address
;
117 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
+ 2);
118 nes_debug(NES_DBG_HW
, "EEPROM Offset %u (next section) = 0x%04X\n",
119 eeprom_offset
+ 2, eeprom_data
);
120 next_section_address
= eeprom_offset
+ (((eeprom_data
& 0x00ff) << 3) <<
121 ((eeprom_data
& 0x0100) >> 8));
122 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, next_section_address
+ 4);
123 if (eeprom_data
!= 0x4f52) {
124 nes_debug(NES_DBG_HW
, "EEPROM Changed offset should be 0x4f52 but was 0x%04X\n",
128 eeprom_offset
= next_section_address
;
130 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
+ 2);
131 nes_debug(NES_DBG_HW
, "EEPROM Offset %u (next section) = 0x%04X\n",
132 eeprom_offset
+ 2, eeprom_data
);
133 next_section_address
= eeprom_offset
+ ((eeprom_data
& 0x00ff) << 3);
134 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, next_section_address
+ 4);
135 if (eeprom_data
!= 0x5746) {
136 nes_debug(NES_DBG_HW
, "EEPROM Changed offset should be 0x5746 but was 0x%04X\n",
140 eeprom_offset
= next_section_address
;
142 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
+ 2);
143 nes_debug(NES_DBG_HW
, "EEPROM Offset %u (next section) = 0x%04X\n",
144 eeprom_offset
+ 2, eeprom_data
);
145 next_section_address
= eeprom_offset
+ ((eeprom_data
& 0x00ff) << 3);
146 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, next_section_address
+ 4);
147 if (eeprom_data
!= 0x5753) {
148 nes_debug(NES_DBG_HW
, "EEPROM Changed offset should be 0x5753 but was 0x%04X\n",
152 eeprom_offset
= next_section_address
;
154 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
+ 2);
155 nes_debug(NES_DBG_HW
, "EEPROM Offset %u (next section) = 0x%04X\n",
156 eeprom_offset
+ 2, eeprom_data
);
157 next_section_address
= eeprom_offset
+ ((eeprom_data
& 0x00ff) << 3);
158 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, next_section_address
+ 4);
159 if (eeprom_data
!= 0x414d) {
160 nes_debug(NES_DBG_HW
, "EEPROM Changed offset should be 0x414d but was 0x%04X\n",
164 eeprom_offset
= next_section_address
;
166 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
+ 2);
167 nes_debug(NES_DBG_HW
, "EEPROM Offset %u (next section) = 0x%04X\n",
168 eeprom_offset
+ 2, eeprom_data
);
169 next_section_address
= eeprom_offset
+ ((eeprom_data
& 0x00ff) << 3);
170 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, next_section_address
+ 4);
171 if (eeprom_data
!= 0x464e) {
172 nes_debug(NES_DBG_HW
, "EEPROM Changed offset should be 0x464e but was 0x%04X\n",
176 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, next_section_address
+ 8);
177 printk(PFX
"Firmware version %u.%u\n", (u8
)(eeprom_data
>>8), (u8
)eeprom_data
);
178 major_ver
= (u8
)(eeprom_data
>> 8);
179 minor_ver
= (u8
)(eeprom_data
);
181 if (nes_drv_opt
& NES_DRV_OPT_DISABLE_VIRT_WQ
) {
182 nes_debug(NES_DBG_HW
, "Virtual WQs have been disabled\n");
183 } else if (((major_ver
== 2) && (minor_ver
> 21)) || ((major_ver
> 2) && (major_ver
!= 255))) {
184 nesadapter
->virtwq
= 1;
186 nesadapter
->firmware_version
= (((u32
)(u8
)(eeprom_data
>>8)) << 16) +
187 (u32
)((u8
)eeprom_data
);
190 /* eeprom is valid */
191 eeprom_offset
= nesadapter
->software_eeprom_offset
;
193 nesadapter
->netdev_max
= (u8
)nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
195 mac_addr_high
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
197 mac_addr_low
= (u32
)nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
200 mac_addr_low
+= (u32
)nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
201 nes_debug(NES_DBG_HW
, "Base MAC Address = 0x%04X%08X\n",
202 mac_addr_high
, mac_addr_low
);
203 nes_debug(NES_DBG_HW
, "MAC Address count = %u\n", nesadapter
->netdev_max
);
205 nesadapter
->mac_addr_low
= mac_addr_low
;
206 nesadapter
->mac_addr_high
= mac_addr_high
;
208 /* Read the Phy Type array */
210 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
211 nesadapter
->phy_type
[0] = (u8
)(eeprom_data
>> 8);
212 nesadapter
->phy_type
[1] = (u8
)eeprom_data
;
214 /* Read the port array */
216 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
217 nesadapter
->phy_type
[2] = (u8
)(eeprom_data
>> 8);
218 nesadapter
->phy_type
[3] = (u8
)eeprom_data
;
219 /* port_count is set by soft reset reg */
220 nes_debug(NES_DBG_HW
, "port_count = %u, port 0 -> %u, port 1 -> %u,"
221 " port 2 -> %u, port 3 -> %u\n",
222 nesadapter
->port_count
,
223 nesadapter
->phy_type
[0], nesadapter
->phy_type
[1],
224 nesadapter
->phy_type
[2], nesadapter
->phy_type
[3]);
226 /* Read PD config array */
228 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
229 nesadapter
->pd_config_size
[0] = eeprom_data
;
231 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
232 nesadapter
->pd_config_base
[0] = eeprom_data
;
233 nes_debug(NES_DBG_HW
, "PD0 config, size=0x%04x, base=0x%04x\n",
234 nesadapter
->pd_config_size
[0], nesadapter
->pd_config_base
[0]);
237 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
238 nesadapter
->pd_config_size
[1] = eeprom_data
;
240 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
241 nesadapter
->pd_config_base
[1] = eeprom_data
;
242 nes_debug(NES_DBG_HW
, "PD1 config, size=0x%04x, base=0x%04x\n",
243 nesadapter
->pd_config_size
[1], nesadapter
->pd_config_base
[1]);
246 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
247 nesadapter
->pd_config_size
[2] = eeprom_data
;
249 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
250 nesadapter
->pd_config_base
[2] = eeprom_data
;
251 nes_debug(NES_DBG_HW
, "PD2 config, size=0x%04x, base=0x%04x\n",
252 nesadapter
->pd_config_size
[2], nesadapter
->pd_config_base
[2]);
255 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
256 nesadapter
->pd_config_size
[3] = eeprom_data
;
258 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
259 nesadapter
->pd_config_base
[3] = eeprom_data
;
260 nes_debug(NES_DBG_HW
, "PD3 config, size=0x%04x, base=0x%04x\n",
261 nesadapter
->pd_config_size
[3], nesadapter
->pd_config_base
[3]);
263 /* Read Rx Pool Size */
264 eeprom_offset
+= 22; /* 46 */
265 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
267 nesadapter
->rx_pool_size
= (((u32
)eeprom_data
) << 16) +
268 nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
269 nes_debug(NES_DBG_HW
, "rx_pool_size = 0x%08X\n", nesadapter
->rx_pool_size
);
272 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
274 nesadapter
->tx_pool_size
= (((u32
)eeprom_data
) << 16) +
275 nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
276 nes_debug(NES_DBG_HW
, "tx_pool_size = 0x%08X\n", nesadapter
->tx_pool_size
);
279 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
281 nesadapter
->rx_threshold
= (((u32
)eeprom_data
) << 16) +
282 nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
283 nes_debug(NES_DBG_HW
, "rx_threshold = 0x%08X\n", nesadapter
->rx_threshold
);
286 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
288 nesadapter
->tcp_timer_core_clk_divisor
= (((u32
)eeprom_data
) << 16) +
289 nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
290 nes_debug(NES_DBG_HW
, "tcp_timer_core_clk_divisor = 0x%08X\n",
291 nesadapter
->tcp_timer_core_clk_divisor
);
294 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
296 nesadapter
->iwarp_config
= (((u32
)eeprom_data
) << 16) +
297 nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
298 nes_debug(NES_DBG_HW
, "iwarp_config = 0x%08X\n", nesadapter
->iwarp_config
);
301 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
303 nesadapter
->cm_config
= (((u32
)eeprom_data
) << 16) +
304 nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
305 nes_debug(NES_DBG_HW
, "cm_config = 0x%08X\n", nesadapter
->cm_config
);
308 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
310 nesadapter
->sws_timer_config
= (((u32
)eeprom_data
) << 16) +
311 nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
312 nes_debug(NES_DBG_HW
, "sws_timer_config = 0x%08X\n", nesadapter
->sws_timer_config
);
315 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
317 nesadapter
->tcp_config1
= (((u32
)eeprom_data
) << 16) +
318 nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
319 nes_debug(NES_DBG_HW
, "tcp_config1 = 0x%08X\n", nesadapter
->tcp_config1
);
322 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
324 nesadapter
->wqm_wat
= (((u32
)eeprom_data
) << 16) +
325 nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
326 nes_debug(NES_DBG_HW
, "wqm_wat = 0x%08X\n", nesadapter
->wqm_wat
);
329 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
331 nesadapter
->core_clock
= (((u32
)eeprom_data
) << 16) +
332 nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
333 nes_debug(NES_DBG_HW
, "core_clock = 0x%08X\n", nesadapter
->core_clock
);
335 if ((sw_section_ver
) && (nesadapter
->hw_rev
!= NE020_REV
)) {
337 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
338 nesadapter
->phy_index
[0] = (eeprom_data
& 0xff00)>>8;
339 nesadapter
->phy_index
[1] = eeprom_data
& 0x00ff;
341 eeprom_data
= nes_read16_eeprom(nesdev
->regs
, eeprom_offset
);
342 nesadapter
->phy_index
[2] = (eeprom_data
& 0xff00)>>8;
343 nesadapter
->phy_index
[3] = eeprom_data
& 0x00ff;
345 nesadapter
->phy_index
[0] = 4;
346 nesadapter
->phy_index
[1] = 5;
347 nesadapter
->phy_index
[2] = 6;
348 nesadapter
->phy_index
[3] = 7;
350 nes_debug(NES_DBG_HW
, "Phy address map = 0 > %u, 1 > %u, 2 > %u, 3 > %u\n",
351 nesadapter
->phy_index
[0],nesadapter
->phy_index
[1],
352 nesadapter
->phy_index
[2],nesadapter
->phy_index
[3]);
362 static u16
nes_read16_eeprom(void __iomem
*addr
, u16 offset
)
364 writel(NES_EEPROM_READ_REQUEST
+ (offset
>> 1),
365 (void __iomem
*)addr
+ NES_EEPROM_COMMAND
);
368 } while (readl((void __iomem
*)addr
+ NES_EEPROM_COMMAND
) &
369 NES_EEPROM_READ_REQUEST
);
371 return readw((void __iomem
*)addr
+ NES_EEPROM_DATA
);
376 * nes_write_1G_phy_reg
378 void nes_write_1G_phy_reg(struct nes_device
*nesdev
, u8 phy_reg
, u8 phy_addr
, u16 data
)
380 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
385 spin_lock_irqsave(&nesadapter
->phy_lock
, flags
);
387 nes_write_indexed(nesdev
, NES_IDX_MAC_MDIO_CONTROL
,
388 0x50020000 | data
| ((u32
)phy_reg
<< 18) | ((u32
)phy_addr
<< 23));
389 for (counter
= 0; counter
< 100 ; counter
++) {
391 u32temp
= nes_read_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
);
393 /* nes_debug(NES_DBG_PHY, "Phy interrupt status = 0x%X.\n", u32temp); */
394 nes_write_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
, 1);
399 nes_debug(NES_DBG_PHY
, "Phy is not responding. interrupt status = 0x%X.\n",
402 spin_unlock_irqrestore(&nesadapter
->phy_lock
, flags
);
407 * nes_read_1G_phy_reg
408 * This routine only issues the read, the data must be read
411 void nes_read_1G_phy_reg(struct nes_device
*nesdev
, u8 phy_reg
, u8 phy_addr
, u16
*data
)
413 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
418 /* nes_debug(NES_DBG_PHY, "phy addr = %d, mac_index = %d\n",
419 phy_addr, nesdev->mac_index); */
420 spin_lock_irqsave(&nesadapter
->phy_lock
, flags
);
422 nes_write_indexed(nesdev
, NES_IDX_MAC_MDIO_CONTROL
,
423 0x60020000 | ((u32
)phy_reg
<< 18) | ((u32
)phy_addr
<< 23));
424 for (counter
= 0; counter
< 100 ; counter
++) {
426 u32temp
= nes_read_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
);
428 /* nes_debug(NES_DBG_PHY, "Phy interrupt status = 0x%X.\n", u32temp); */
429 nes_write_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
, 1);
433 if (!(u32temp
& 1)) {
434 nes_debug(NES_DBG_PHY
, "Phy is not responding. interrupt status = 0x%X.\n",
438 *data
= (u16
)nes_read_indexed(nesdev
, NES_IDX_MAC_MDIO_CONTROL
);
440 spin_unlock_irqrestore(&nesadapter
->phy_lock
, flags
);
445 * nes_write_10G_phy_reg
447 void nes_write_10G_phy_reg(struct nes_device
*nesdev
, u16 phy_reg
,
448 u8 phy_addr
, u16 data
)
456 port_addr
= phy_addr
;
459 nes_write_indexed(nesdev
, NES_IDX_MAC_MDIO_CONTROL
,
460 0x00020000 | (u32
)phy_reg
| (((u32
)dev_addr
) << 18) | (((u32
)port_addr
) << 23));
461 for (counter
= 0; counter
< 100 ; counter
++) {
463 u32temp
= nes_read_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
);
465 nes_write_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
, 1);
470 nes_debug(NES_DBG_PHY
, "Phy is not responding. interrupt status = 0x%X.\n",
474 nes_write_indexed(nesdev
, NES_IDX_MAC_MDIO_CONTROL
,
475 0x10020000 | (u32
)data
| (((u32
)dev_addr
) << 18) | (((u32
)port_addr
) << 23));
476 for (counter
= 0; counter
< 100 ; counter
++) {
478 u32temp
= nes_read_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
);
480 nes_write_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
, 1);
485 nes_debug(NES_DBG_PHY
, "Phy is not responding. interrupt status = 0x%X.\n",
491 * nes_read_10G_phy_reg
492 * This routine only issues the read, the data must be read
495 void nes_read_10G_phy_reg(struct nes_device
*nesdev
, u16 phy_reg
, u8 phy_addr
)
503 port_addr
= phy_addr
;
506 nes_write_indexed(nesdev
, NES_IDX_MAC_MDIO_CONTROL
,
507 0x00020000 | (u32
)phy_reg
| (((u32
)dev_addr
) << 18) | (((u32
)port_addr
) << 23));
508 for (counter
= 0; counter
< 100 ; counter
++) {
510 u32temp
= nes_read_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
);
512 nes_write_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
, 1);
517 nes_debug(NES_DBG_PHY
, "Phy is not responding. interrupt status = 0x%X.\n",
521 nes_write_indexed(nesdev
, NES_IDX_MAC_MDIO_CONTROL
,
522 0x30020000 | (((u32
)dev_addr
) << 18) | (((u32
)port_addr
) << 23));
523 for (counter
= 0; counter
< 100 ; counter
++) {
525 u32temp
= nes_read_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
);
527 nes_write_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
, 1);
532 nes_debug(NES_DBG_PHY
, "Phy is not responding. interrupt status = 0x%X.\n",
538 * nes_get_cqp_request
540 struct nes_cqp_request
*nes_get_cqp_request(struct nes_device
*nesdev
)
543 struct nes_cqp_request
*cqp_request
= NULL
;
545 if (!list_empty(&nesdev
->cqp_avail_reqs
)) {
546 spin_lock_irqsave(&nesdev
->cqp
.lock
, flags
);
547 cqp_request
= list_entry(nesdev
->cqp_avail_reqs
.next
,
548 struct nes_cqp_request
, list
);
549 list_del_init(&cqp_request
->list
);
550 spin_unlock_irqrestore(&nesdev
->cqp
.lock
, flags
);
552 cqp_request
= kzalloc(sizeof(struct nes_cqp_request
), GFP_KERNEL
);
554 cqp_request
->dynamic
= 1;
555 INIT_LIST_HEAD(&cqp_request
->list
);
560 init_waitqueue_head(&cqp_request
->waitq
);
561 cqp_request
->waiting
= 0;
562 cqp_request
->request_done
= 0;
563 cqp_request
->callback
= 0;
564 init_waitqueue_head(&cqp_request
->waitq
);
565 nes_debug(NES_DBG_CQP
, "Got cqp request %p from the available list \n",
568 printk(KERN_ERR PFX
"%s: Could not allocated a CQP request.\n",
576 * nes_post_cqp_request
578 void nes_post_cqp_request(struct nes_device
*nesdev
,
579 struct nes_cqp_request
*cqp_request
, int ring_doorbell
)
581 struct nes_hw_cqp_wqe
*cqp_wqe
;
586 spin_lock_irqsave(&nesdev
->cqp
.lock
, flags
);
588 if (((((nesdev
->cqp
.sq_tail
+(nesdev
->cqp
.sq_size
*2))-nesdev
->cqp
.sq_head
) &
589 (nesdev
->cqp
.sq_size
- 1)) != 1)
590 && (list_empty(&nesdev
->cqp_pending_reqs
))) {
591 cqp_head
= nesdev
->cqp
.sq_head
++;
592 nesdev
->cqp
.sq_head
&= nesdev
->cqp
.sq_size
-1;
593 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
594 memcpy(cqp_wqe
, &cqp_request
->cqp_wqe
, sizeof(*cqp_wqe
));
596 u64temp
= (unsigned long)cqp_request
;
597 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_COMP_SCRATCH_LOW_IDX
,
599 nes_debug(NES_DBG_CQP
, "CQP request (opcode 0x%02X), line 1 = 0x%08X put on CQPs SQ,"
600 " request = %p, cqp_head = %u, cqp_tail = %u, cqp_size = %u,"
601 " waiting = %d, refcount = %d.\n",
602 le32_to_cpu(cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
])&0x3f,
603 le32_to_cpu(cqp_wqe
->wqe_words
[NES_CQP_WQE_ID_IDX
]), cqp_request
,
604 nesdev
->cqp
.sq_head
, nesdev
->cqp
.sq_tail
, nesdev
->cqp
.sq_size
,
605 cqp_request
->waiting
, atomic_read(&cqp_request
->refcount
));
608 /* Ring doorbell (1 WQEs) */
609 nes_write32(nesdev
->regs
+NES_WQE_ALLOC
, 0x01800000 | nesdev
->cqp
.qp_id
);
614 nes_debug(NES_DBG_CQP
, "CQP request %p (opcode 0x%02X), line 1 = 0x%08X"
615 " put on the pending queue.\n",
617 le32_to_cpu(cqp_request
->cqp_wqe
.wqe_words
[NES_CQP_WQE_OPCODE_IDX
])&0x3f,
618 le32_to_cpu(cqp_request
->cqp_wqe
.wqe_words
[NES_CQP_WQE_ID_IDX
]));
619 list_add_tail(&cqp_request
->list
, &nesdev
->cqp_pending_reqs
);
622 spin_unlock_irqrestore(&nesdev
->cqp
.lock
, flags
);
631 int nes_arp_table(struct nes_device
*nesdev
, u32 ip_addr
, u8
*mac_addr
, u32 action
)
633 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
637 for (arp_index
= 0; (u32
) arp_index
< nesadapter
->arp_table_size
; arp_index
++) {
638 if (nesadapter
->arp_table
[arp_index
].ip_addr
== ip_addr
)
642 if (action
== NES_ARP_ADD
) {
643 if (arp_index
!= nesadapter
->arp_table_size
) {
648 err
= nes_alloc_resource(nesadapter
, nesadapter
->allocated_arps
,
649 nesadapter
->arp_table_size
, (u32
*)&arp_index
, &nesadapter
->next_arp_index
);
651 nes_debug(NES_DBG_NETDEV
, "nes_alloc_resource returned error = %u\n", err
);
654 nes_debug(NES_DBG_NETDEV
, "ADD, arp_index=%d\n", arp_index
);
656 nesadapter
->arp_table
[arp_index
].ip_addr
= ip_addr
;
657 memcpy(nesadapter
->arp_table
[arp_index
].mac_addr
, mac_addr
, ETH_ALEN
);
661 /* DELETE or RESOLVE */
662 if (arp_index
== nesadapter
->arp_table_size
) {
663 nes_debug(NES_DBG_NETDEV
, "mac address not in ARP table - cannot delete or resolve\n");
667 if (action
== NES_ARP_RESOLVE
) {
668 nes_debug(NES_DBG_NETDEV
, "RESOLVE, arp_index=%d\n", arp_index
);
672 if (action
== NES_ARP_DELETE
) {
673 nes_debug(NES_DBG_NETDEV
, "DELETE, arp_index=%d\n", arp_index
);
674 nesadapter
->arp_table
[arp_index
].ip_addr
= 0;
675 memset(nesadapter
->arp_table
[arp_index
].mac_addr
, 0x00, ETH_ALEN
);
676 nes_free_resource(nesadapter
, nesadapter
->allocated_arps
, arp_index
);
687 void nes_mh_fix(unsigned long parm
)
690 struct nes_device
*nesdev
= (struct nes_device
*)parm
;
691 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
692 struct nes_vnic
*nesvnic
;
694 u32 temp_used_chunks_tx
;
695 u32 temp_last_used_chunks_tx
;
696 u32 used_chunks_mask
;
697 u32 mac_tx_frames_low
;
698 u32 mac_tx_frames_high
;
710 u32 chunks_tx_progress
= 0;
712 spin_lock_irqsave(&nesadapter
->phy_lock
, flags
);
713 if ((nesadapter
->mac_sw_state
[0] != NES_MAC_SW_IDLE
) || (nesadapter
->mac_link_down
[0])) {
714 spin_unlock_irqrestore(&nesadapter
->phy_lock
, flags
);
717 nesadapter
->mac_sw_state
[0] = NES_MAC_SW_MH
;
718 spin_unlock_irqrestore(&nesadapter
->phy_lock
, flags
);
720 mac_tx_frames_low
= nes_read_indexed(nesdev
, NES_IDX_MAC_TX_FRAMES_LOW
);
721 mac_tx_frames_high
= nes_read_indexed(nesdev
, NES_IDX_MAC_TX_FRAMES_HIGH
);
722 mac_tx_pauses
= nes_read_indexed(nesdev
, NES_IDX_MAC_TX_PAUSE_FRAMES
);
723 used_chunks_tx
= nes_read_indexed(nesdev
, NES_IDX_USED_CHUNKS_TX
);
724 nesdev
->mac_pause_frames_sent
+= mac_tx_pauses
;
725 used_chunks_mask
= 0;
726 temp_used_chunks_tx
= used_chunks_tx
;
727 temp_last_used_chunks_tx
= nesdev
->last_used_chunks_tx
;
729 if (nesdev
->netdev
[0]) {
730 nesvnic
= netdev_priv(nesdev
->netdev
[0]);
735 for (i
=0; i
<4; i
++) {
736 used_chunks_mask
<<= 8;
737 if (nesvnic
->qp_nic_index
[i
] != 0xff) {
738 used_chunks_mask
|= 0xff;
739 if ((temp_used_chunks_tx
&0xff)<(temp_last_used_chunks_tx
&0xff)) {
740 chunks_tx_progress
= 1;
743 temp_used_chunks_tx
>>= 8;
744 temp_last_used_chunks_tx
>>= 8;
746 if ((mac_tx_frames_low
) || (mac_tx_frames_high
) ||
747 (!(used_chunks_tx
&used_chunks_mask
)) ||
748 (!(nesdev
->last_used_chunks_tx
&used_chunks_mask
)) ||
749 (chunks_tx_progress
) ) {
750 nesdev
->last_used_chunks_tx
= used_chunks_tx
;
753 nesdev
->last_used_chunks_tx
= used_chunks_tx
;
756 nes_write_indexed(nesdev
, NES_IDX_MAC_TX_CONTROL
, 0x00000005);
758 mac_tx_pauses
= nes_read_indexed(nesdev
, NES_IDX_MAC_TX_PAUSE_FRAMES
);
760 nesdev
->mac_pause_frames_sent
+= mac_tx_pauses
;
764 tx_control
= nes_read_indexed(nesdev
, NES_IDX_MAC_TX_CONTROL
);
765 tx_config
= nes_read_indexed(nesdev
, NES_IDX_MAC_TX_CONFIG
);
766 tx_pause_quanta
= nes_read_indexed(nesdev
, NES_IDX_MAC_TX_PAUSE_QUANTA
);
767 rx_control
= nes_read_indexed(nesdev
, NES_IDX_MAC_RX_CONTROL
);
768 rx_config
= nes_read_indexed(nesdev
, NES_IDX_MAC_RX_CONFIG
);
769 mac_exact_match
= nes_read_indexed(nesdev
, NES_IDX_MAC_EXACT_MATCH_BOTTOM
);
770 mpp_debug
= nes_read_indexed(nesdev
, NES_IDX_MPP_DEBUG
);
772 /* one last ditch effort to avoid a false positive */
773 mac_tx_pauses
= nes_read_indexed(nesdev
, NES_IDX_MAC_TX_PAUSE_FRAMES
);
775 nesdev
->last_mac_tx_pauses
= nesdev
->mac_pause_frames_sent
;
776 nes_debug(NES_DBG_HW
, "failsafe caught slow outbound pause\n");
781 nes_write_indexed(nesdev
, NES_IDX_MAC_TX_CONTROL
, 0x00000000);
782 nes_write_indexed(nesdev
, NES_IDX_MAC_TX_CONFIG
, 0x00000000);
783 reset_value
= nes_read32(nesdev
->regs
+NES_SOFTWARE_RESET
);
785 nes_write32(nesdev
->regs
+NES_SOFTWARE_RESET
, reset_value
| 0x0000001d);
787 while (((nes_read32(nesdev
->regs
+NES_SOFTWARE_RESET
)
788 & 0x00000040) != 0x00000040) && (i
++ < 5000)) {
792 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_CONTROL0
, 0x00000008);
793 serdes_status
= nes_read_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_STATUS0
);
795 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_TX_EMP0
, 0x000bdef7);
796 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_TX_DRIVE0
, 0x9ce73000);
797 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_RX_MODE0
, 0x0ff00000);
798 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_RX_SIGDET0
, 0x00000000);
799 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_BYPASS0
, 0x00000000);
800 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_LOOPBACK_CONTROL0
, 0x00000000);
801 if (nesadapter
->OneG_Mode
) {
802 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0
, 0xf0182222);
804 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0
, 0xf0042222);
806 serdes_status
= nes_read_indexed(nesdev
, NES_IDX_ETH_SERDES_RX_EQ_STATUS0
);
807 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_CDR_CONTROL0
, 0x000000ff);
809 nes_write_indexed(nesdev
, NES_IDX_MAC_TX_CONTROL
, tx_control
);
810 nes_write_indexed(nesdev
, NES_IDX_MAC_TX_CONFIG
, tx_config
);
811 nes_write_indexed(nesdev
, NES_IDX_MAC_TX_PAUSE_QUANTA
, tx_pause_quanta
);
812 nes_write_indexed(nesdev
, NES_IDX_MAC_RX_CONTROL
, rx_control
);
813 nes_write_indexed(nesdev
, NES_IDX_MAC_RX_CONFIG
, rx_config
);
814 nes_write_indexed(nesdev
, NES_IDX_MAC_EXACT_MATCH_BOTTOM
, mac_exact_match
);
815 nes_write_indexed(nesdev
, NES_IDX_MPP_DEBUG
, mpp_debug
);
819 nesadapter
->mac_sw_state
[0] = NES_MAC_SW_IDLE
;
821 nesdev
->nesadapter
->mh_timer
.expires
= jiffies
+ (HZ
/5);
822 add_timer(&nesdev
->nesadapter
->mh_timer
);
828 void nes_clc(unsigned long parm
)
831 struct nes_device
*nesdev
= (struct nes_device
*)parm
;
832 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
834 spin_lock_irqsave(&nesadapter
->phy_lock
, flags
);
835 nesadapter
->link_interrupt_count
[0] = 0;
836 nesadapter
->link_interrupt_count
[1] = 0;
837 nesadapter
->link_interrupt_count
[2] = 0;
838 nesadapter
->link_interrupt_count
[3] = 0;
839 spin_unlock_irqrestore(&nesadapter
->phy_lock
, flags
);
841 nesadapter
->lc_timer
.expires
= jiffies
+ 3600 * HZ
; /* 1 hour */
842 add_timer(&nesadapter
->lc_timer
);
849 void nes_dump_mem(unsigned int dump_debug_level
, void *addr
, int length
)
851 char xlate
[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
852 'a', 'b', 'c', 'd', 'e', 'f'};
860 if (!(nes_debug_level
& dump_debug_level
)) {
865 if (length
> 0x100) {
866 nes_debug(dump_debug_level
, "Length truncated from %x to %x\n", length
, 0x100);
869 nes_debug(dump_debug_level
, "Address=0x%p, length=0x%x (%d)\n", ptr
, length
, length
);
871 memset(ascii_buf
, 0, 20);
872 memset(hex_buf
, 0, 80);
876 for (num_char
= 0; num_char
< length
; num_char
++) {
877 if (num_ascii
== 8) {
878 ascii_buf
[num_ascii
++] = ' ';
879 hex_buf
[num_hex
++] = '-';
880 hex_buf
[num_hex
++] = ' ';
883 if (*ptr
< 0x20 || *ptr
> 0x7e)
884 ascii_buf
[num_ascii
++] = '.';
886 ascii_buf
[num_ascii
++] = *ptr
;
887 hex_buf
[num_hex
++] = xlate
[((*ptr
& 0xf0) >> 4)];
888 hex_buf
[num_hex
++] = xlate
[*ptr
& 0x0f];
889 hex_buf
[num_hex
++] = ' ';
892 if (num_ascii
>= 17) {
893 /* output line and reset */
894 nes_debug(dump_debug_level
, " %s | %s\n", hex_buf
, ascii_buf
);
895 memset(ascii_buf
, 0, 20);
896 memset(hex_buf
, 0, 80);
902 /* output the rest */
904 while (num_ascii
< 17) {
905 if (num_ascii
== 8) {
906 hex_buf
[num_hex
++] = ' ';
907 hex_buf
[num_hex
++] = ' ';
909 hex_buf
[num_hex
++] = ' ';
910 hex_buf
[num_hex
++] = ' ';
911 hex_buf
[num_hex
++] = ' ';
915 nes_debug(dump_debug_level
, " %s | %s\n", hex_buf
, ascii_buf
);