34 #include <linux/module.h>
36 #include <linux/netdevice.h>
38 #include <linux/ethtool.h>
39 #include <linux/mii.h>
40 #include <linux/if_vlan.h>
41 #include <linux/slab.h>
45 #include <linux/tcp.h>
50 #include <asm/byteorder.h>
75 if (counter == NES_PAU_COUNTER) {
91 u16 next_section_address;
99 eeprom_data = nes_read16_eeprom(nesdev->
regs, 0);
101 eeprom_offset = 2 + (((eeprom_data & 0x007f) << 3) <<
102 ((eeprom_data & 0x0080) >> 7));
105 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset + 4);
106 if (eeprom_data != 0x5746) {
111 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset + 2);
113 eeprom_offset + 2, eeprom_data);
114 eeprom_offset += ((eeprom_data & 0x00ff) << 3) << ((eeprom_data & 0x0100) >> 8);
117 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset + 4);
118 if (eeprom_data != 0x5753) {
119 printk(
"Not a valid Software Image = 0x%04X\n", eeprom_data);
126 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset + 2);
128 eeprom_offset + 2, eeprom_data);
129 next_section_address = eeprom_offset + (((eeprom_data & 0x00ff) << 3) <<
130 ((eeprom_data & 0x0100) >> 8));
131 eeprom_data = nes_read16_eeprom(nesdev->
regs, next_section_address + 4);
132 if (eeprom_data != 0x414d) {
137 eeprom_offset = next_section_address;
139 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset + 2);
141 eeprom_offset + 2, eeprom_data);
142 next_section_address = eeprom_offset + (((eeprom_data & 0x00ff) << 3) <<
143 ((eeprom_data & 0x0100) >> 8));
144 eeprom_data = nes_read16_eeprom(nesdev->
regs, next_section_address + 4);
145 if (eeprom_data != 0x4f52) {
150 eeprom_offset = next_section_address;
152 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset + 2);
154 eeprom_offset + 2, eeprom_data);
155 next_section_address = eeprom_offset + ((eeprom_data & 0x00ff) << 3);
156 eeprom_data = nes_read16_eeprom(nesdev->
regs, next_section_address + 4);
157 if (eeprom_data != 0x5746) {
162 eeprom_offset = next_section_address;
164 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset + 2);
166 eeprom_offset + 2, eeprom_data);
167 next_section_address = eeprom_offset + ((eeprom_data & 0x00ff) << 3);
168 eeprom_data = nes_read16_eeprom(nesdev->
regs, next_section_address + 4);
169 if (eeprom_data != 0x5753) {
174 eeprom_offset = next_section_address;
176 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset + 2);
178 eeprom_offset + 2, eeprom_data);
179 next_section_address = eeprom_offset + ((eeprom_data & 0x00ff) << 3);
180 eeprom_data = nes_read16_eeprom(nesdev->
regs, next_section_address + 4);
181 if (eeprom_data != 0x414d) {
186 eeprom_offset = next_section_address;
188 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset + 2);
190 eeprom_offset + 2, eeprom_data);
191 next_section_address = eeprom_offset + ((eeprom_data & 0x00ff) << 3);
192 eeprom_data = nes_read16_eeprom(nesdev->
regs, next_section_address + 4);
193 if (eeprom_data != 0x464e) {
198 eeprom_data = nes_read16_eeprom(nesdev->
regs, next_section_address + 8);
199 printk(
PFX "Firmware version %u.%u\n", (
u8)(eeprom_data>>8), (
u8)eeprom_data);
200 major_ver = (
u8)(eeprom_data >> 8);
201 minor_ver = (
u8)(eeprom_data);
205 }
else if (((major_ver == 2) && (minor_ver > 21)) || ((major_ver > 2) && (major_ver != 255))) {
208 if (((major_ver == 3) && (minor_ver >= 16)) || (major_ver > 3))
212 if (!nes_set_pau(nesdev))
217 (
u32)((
u8)eeprom_data);
219 eeprom_data = nes_read16_eeprom(nesdev->
regs, next_section_address + 10);
220 printk(
PFX "EEPROM version %u.%u\n", (
u8)(eeprom_data>>8), (
u8)eeprom_data);
222 (
u32)((
u8)eeprom_data);
228 nesadapter->
netdev_max = (
u8)nes_read16_eeprom(nesdev->
regs, eeprom_offset);
230 mac_addr_high = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
232 mac_addr_low = (
u32)nes_read16_eeprom(nesdev->
regs, eeprom_offset);
235 mac_addr_low += (
u32)nes_read16_eeprom(nesdev->
regs, eeprom_offset);
237 mac_addr_high, mac_addr_low);
245 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
246 nesadapter->
phy_type[0] = (
u8)(eeprom_data >> 8);
251 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
252 nesadapter->
phy_type[2] = (
u8)(eeprom_data >> 8);
256 " port 2 -> %u, port 3 -> %u\n",
263 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
266 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
272 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
275 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
281 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
284 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
290 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
293 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
300 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
303 nes_read16_eeprom(nesdev->
regs, eeprom_offset);
307 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
310 nes_read16_eeprom(nesdev->
regs, eeprom_offset);
314 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
317 nes_read16_eeprom(nesdev->
regs, eeprom_offset);
321 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
324 nes_read16_eeprom(nesdev->
regs, eeprom_offset);
329 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
332 nes_read16_eeprom(nesdev->
regs, eeprom_offset);
336 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
339 nes_read16_eeprom(nesdev->
regs, eeprom_offset);
343 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
346 nes_read16_eeprom(nesdev->
regs, eeprom_offset);
350 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
353 nes_read16_eeprom(nesdev->
regs, eeprom_offset);
357 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
359 nesadapter->
wqm_wat = (((
u32)eeprom_data) << 16) +
360 nes_read16_eeprom(nesdev->
regs, eeprom_offset);
364 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
367 nes_read16_eeprom(nesdev->
regs, eeprom_offset);
372 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
373 nesadapter->
phy_index[0] = (eeprom_data & 0xff00)>>8;
374 nesadapter->
phy_index[1] = eeprom_data & 0x00ff;
376 eeprom_data = nes_read16_eeprom(nesdev->
regs, eeprom_offset);
377 nesadapter->
phy_index[2] = (eeprom_data & 0xff00)>>8;
378 nesadapter->
phy_index[3] = eeprom_data & 0x00ff;
419 0x50020000 | data | ((
u32)phy_reg << 18) | ((
u32)phy_addr << 23));
420 for (counter = 0; counter < 100 ; counter++) {
449 0x60020000 | ((
u32)phy_reg << 18) | ((
u32)phy_addr << 23));
450 for (counter = 0; counter < 100 ; counter++) {
459 if (!(u32temp & 1)) {
479 port_addr = phy_addr;
483 0x00020000 | (
u32)phy_reg | (((
u32)dev_addr) << 18) | (((
u32)port_addr) << 23));
484 for (counter = 0; counter < 100 ; counter++) {
498 0x10020000 | (
u32)data | (((
u32)dev_addr) << 18) | (((
u32)port_addr) << 23));
499 for (counter = 0; counter < 100 ; counter++) {
524 port_addr = phy_addr;
528 0x00020000 | (
u32)phy_reg | (((
u32)dev_addr) << 18) | (((
u32)port_addr) << 23));
529 for (counter = 0; counter < 100 ; counter++) {
543 0x30020000 | (((
u32)dev_addr) << 18) | (((
u32)port_addr) << 23));
544 for (counter = 0; counter < 100 ; counter++) {
571 list_del_init(&cqp_request->
list);
573 spin_unlock_irqrestore(&nesdev->
cqp.lock, flags);
575 if (cqp_request ==
NULL) {
579 INIT_LIST_HEAD(&cqp_request->
list);
612 spin_unlock_irqrestore(&nesdev->
cqp.lock, flags);
639 if (((((nesdev->
cqp.sq_tail+(nesdev->
cqp.sq_size*2))-nesdev->
cqp.sq_head) &
640 (nesdev->
cqp.sq_size - 1)) != 1)
642 cqp_head = nesdev->
cqp.sq_head++;
643 nesdev->
cqp.sq_head &= nesdev->
cqp.sq_size-1;
644 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
650 u64temp = (
unsigned long)cqp_request;
651 set_wqe_64bit_value(cqp_wqe->
wqe_words, ctx_index, u64temp);
653 " request = %p, cqp_head = %u, cqp_tail = %u, cqp_size = %u,"
654 " waiting = %d, refcount = %d.\n",
655 opcode & NES_CQP_OPCODE_MASK,
657 nesdev->
cqp.sq_head, nesdev->
cqp.sq_tail, nesdev->
cqp.sq_size,
668 " put on the pending queue.\n",
675 spin_unlock_irqrestore(&nesdev->
cqp.lock, flags);
691 if (nesadapter->
arp_table[arp_index].ip_addr == ip_addr)
729 nesadapter->
arp_table[arp_index].ip_addr = 0;
731 nes_free_resource(nesadapter, nesadapter->
allocated_arps, arp_index);
749 u32 temp_used_chunks_tx;
750 u32 temp_last_used_chunks_tx;
751 u32 used_chunks_mask;
752 u32 mac_tx_frames_low;
753 u32 mac_tx_frames_high;
765 u32 chunks_tx_progress = 0;
769 spin_unlock_irqrestore(&nesadapter->
phy_lock, flags);
773 spin_unlock_irqrestore(&nesadapter->
phy_lock, flags);
780 used_chunks_mask = 0;
781 temp_used_chunks_tx = used_chunks_tx;
785 nesvnic = netdev_priv(nesdev->
netdev[0]);
790 for (i=0; i<4; i++) {
791 used_chunks_mask <<= 8;
793 used_chunks_mask |= 0xff;
794 if ((temp_used_chunks_tx&0xff)<(temp_last_used_chunks_tx&0xff)) {
795 chunks_tx_progress = 1;
798 temp_used_chunks_tx >>= 8;
799 temp_last_used_chunks_tx >>= 8;
801 if ((mac_tx_frames_low) || (mac_tx_frames_high) ||
802 (!(used_chunks_tx&used_chunks_mask)) ||
804 (chunks_tx_progress) ) {
843 & 0x00000040) != 0x00000040) && (i++ < 5000)) {
894 spin_unlock_irqrestore(&nesadapter->
phy_lock, flags);
906 char xlate[] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
907 'a',
'b',
'c',
'd',
'e',
'f'};
920 if (length > 0x100) {
921 nes_debug(dump_debug_level,
"Length truncated from %x to %x\n", length, 0x100);
924 nes_debug(dump_debug_level,
"Address=0x%p, length=0x%x (%d)\n", ptr, length, length);
931 for (num_char = 0; num_char <
length; num_char++) {
932 if (num_ascii == 8) {
933 ascii_buf[num_ascii++] =
' ';
934 hex_buf[num_hex++] =
'-';
935 hex_buf[num_hex++] =
' ';
938 if (*ptr < 0x20 || *ptr > 0x7e)
939 ascii_buf[num_ascii++] =
'.';
941 ascii_buf[num_ascii++] = *
ptr;
942 hex_buf[num_hex++] = xlate[((*ptr & 0xf0) >> 4)];
943 hex_buf[num_hex++] = xlate[*ptr & 0x0f];
944 hex_buf[num_hex++] =
' ';
947 if (num_ascii >= 17) {
949 nes_debug(dump_debug_level,
" %s | %s\n", hex_buf, ascii_buf);
959 while (num_ascii < 17) {
960 if (num_ascii == 8) {
961 hex_buf[num_hex++] =
' ';
962 hex_buf[num_hex++] =
' ';
964 hex_buf[num_hex++] =
' ';
965 hex_buf[num_hex++] =
' ';
966 hex_buf[num_hex++] =
' ';
970 nes_debug(dump_debug_level,
" %s | %s\n", hex_buf, ascii_buf);