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, see <http://www.gnu.org/licenses/>.
19 * The full GNU General Public License is included in this distribution
20 * in the file called "COPYING".
24 #include <linux/netdevice.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/if_vlan.h>
28 #include <net/checksum.h>
29 #include "netxen_nic.h"
30 #include "netxen_nic_hw.h"
32 struct crb_addr_pair
{
37 #define NETXEN_MAX_CRB_XFORM 60
38 static unsigned int crb_addr_xform
[NETXEN_MAX_CRB_XFORM
];
39 #define NETXEN_ADDR_ERROR (0xffffffff)
41 #define crb_addr_transform(name) \
42 crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \
43 NETXEN_HW_CRB_HUB_AGT_ADR_##name << 20
45 #define NETXEN_NIC_XDMA_RESET 0x8000ff
48 netxen_post_rx_buffers_nodb(struct netxen_adapter
*adapter
,
49 struct nx_host_rds_ring
*rds_ring
);
50 static int netxen_p3_has_mn(struct netxen_adapter
*adapter
);
52 static void crb_addr_transform_setup(void)
54 crb_addr_transform(XDMA
);
55 crb_addr_transform(TIMR
);
56 crb_addr_transform(SRE
);
57 crb_addr_transform(SQN3
);
58 crb_addr_transform(SQN2
);
59 crb_addr_transform(SQN1
);
60 crb_addr_transform(SQN0
);
61 crb_addr_transform(SQS3
);
62 crb_addr_transform(SQS2
);
63 crb_addr_transform(SQS1
);
64 crb_addr_transform(SQS0
);
65 crb_addr_transform(RPMX7
);
66 crb_addr_transform(RPMX6
);
67 crb_addr_transform(RPMX5
);
68 crb_addr_transform(RPMX4
);
69 crb_addr_transform(RPMX3
);
70 crb_addr_transform(RPMX2
);
71 crb_addr_transform(RPMX1
);
72 crb_addr_transform(RPMX0
);
73 crb_addr_transform(ROMUSB
);
74 crb_addr_transform(SN
);
75 crb_addr_transform(QMN
);
76 crb_addr_transform(QMS
);
77 crb_addr_transform(PGNI
);
78 crb_addr_transform(PGND
);
79 crb_addr_transform(PGN3
);
80 crb_addr_transform(PGN2
);
81 crb_addr_transform(PGN1
);
82 crb_addr_transform(PGN0
);
83 crb_addr_transform(PGSI
);
84 crb_addr_transform(PGSD
);
85 crb_addr_transform(PGS3
);
86 crb_addr_transform(PGS2
);
87 crb_addr_transform(PGS1
);
88 crb_addr_transform(PGS0
);
89 crb_addr_transform(PS
);
90 crb_addr_transform(PH
);
91 crb_addr_transform(NIU
);
92 crb_addr_transform(I2Q
);
93 crb_addr_transform(EG
);
94 crb_addr_transform(MN
);
95 crb_addr_transform(MS
);
96 crb_addr_transform(CAS2
);
97 crb_addr_transform(CAS1
);
98 crb_addr_transform(CAS0
);
99 crb_addr_transform(CAM
);
100 crb_addr_transform(C2C1
);
101 crb_addr_transform(C2C0
);
102 crb_addr_transform(SMB
);
103 crb_addr_transform(OCM0
);
104 crb_addr_transform(I2C0
);
107 void netxen_release_rx_buffers(struct netxen_adapter
*adapter
)
109 struct netxen_recv_context
*recv_ctx
;
110 struct nx_host_rds_ring
*rds_ring
;
111 struct netxen_rx_buffer
*rx_buf
;
114 recv_ctx
= &adapter
->recv_ctx
;
115 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
116 rds_ring
= &recv_ctx
->rds_rings
[ring
];
117 for (i
= 0; i
< rds_ring
->num_desc
; ++i
) {
118 rx_buf
= &(rds_ring
->rx_buf_arr
[i
]);
119 if (rx_buf
->state
== NETXEN_BUFFER_FREE
)
121 pci_unmap_single(adapter
->pdev
,
125 if (rx_buf
->skb
!= NULL
)
126 dev_kfree_skb_any(rx_buf
->skb
);
131 void netxen_release_tx_buffers(struct netxen_adapter
*adapter
)
133 struct netxen_cmd_buffer
*cmd_buf
;
134 struct netxen_skb_frag
*buffrag
;
136 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
138 cmd_buf
= tx_ring
->cmd_buf_arr
;
139 for (i
= 0; i
< tx_ring
->num_desc
; i
++) {
140 buffrag
= cmd_buf
->frag_array
;
142 pci_unmap_single(adapter
->pdev
, buffrag
->dma
,
143 buffrag
->length
, PCI_DMA_TODEVICE
);
146 for (j
= 1; j
< cmd_buf
->frag_count
; j
++) {
149 pci_unmap_page(adapter
->pdev
, buffrag
->dma
,
156 dev_kfree_skb_any(cmd_buf
->skb
);
163 void netxen_free_sw_resources(struct netxen_adapter
*adapter
)
165 struct netxen_recv_context
*recv_ctx
;
166 struct nx_host_rds_ring
*rds_ring
;
167 struct nx_host_tx_ring
*tx_ring
;
170 recv_ctx
= &adapter
->recv_ctx
;
172 if (recv_ctx
->rds_rings
== NULL
)
175 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
176 rds_ring
= &recv_ctx
->rds_rings
[ring
];
177 vfree(rds_ring
->rx_buf_arr
);
178 rds_ring
->rx_buf_arr
= NULL
;
180 kfree(recv_ctx
->rds_rings
);
183 if (adapter
->tx_ring
== NULL
)
186 tx_ring
= adapter
->tx_ring
;
187 vfree(tx_ring
->cmd_buf_arr
);
189 adapter
->tx_ring
= NULL
;
192 int netxen_alloc_sw_resources(struct netxen_adapter
*adapter
)
194 struct netxen_recv_context
*recv_ctx
;
195 struct nx_host_rds_ring
*rds_ring
;
196 struct nx_host_sds_ring
*sds_ring
;
197 struct nx_host_tx_ring
*tx_ring
;
198 struct netxen_rx_buffer
*rx_buf
;
201 struct netxen_cmd_buffer
*cmd_buf_arr
;
202 struct net_device
*netdev
= adapter
->netdev
;
204 tx_ring
= kzalloc(sizeof(struct nx_host_tx_ring
), GFP_KERNEL
);
208 adapter
->tx_ring
= tx_ring
;
210 tx_ring
->num_desc
= adapter
->num_txd
;
211 tx_ring
->txq
= netdev_get_tx_queue(netdev
, 0);
213 cmd_buf_arr
= vzalloc(TX_BUFF_RINGSIZE(tx_ring
));
214 if (cmd_buf_arr
== NULL
)
217 tx_ring
->cmd_buf_arr
= cmd_buf_arr
;
219 recv_ctx
= &adapter
->recv_ctx
;
221 rds_ring
= kcalloc(adapter
->max_rds_rings
,
222 sizeof(struct nx_host_rds_ring
), GFP_KERNEL
);
223 if (rds_ring
== NULL
)
226 recv_ctx
->rds_rings
= rds_ring
;
228 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
229 rds_ring
= &recv_ctx
->rds_rings
[ring
];
231 case RCV_RING_NORMAL
:
232 rds_ring
->num_desc
= adapter
->num_rxd
;
233 if (adapter
->ahw
.cut_through
) {
235 NX_CT_DEFAULT_RX_BUF_LEN
;
237 NX_CT_DEFAULT_RX_BUF_LEN
;
239 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
241 NX_P3_RX_BUF_MAX_LEN
;
244 NX_P2_RX_BUF_MAX_LEN
;
246 rds_ring
->dma_size
+ NET_IP_ALIGN
;
251 rds_ring
->num_desc
= adapter
->num_jumbo_rxd
;
252 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
254 NX_P3_RX_JUMBO_BUF_MAX_LEN
;
257 NX_P2_RX_JUMBO_BUF_MAX_LEN
;
259 if (adapter
->capabilities
& NX_CAP0_HW_LRO
)
260 rds_ring
->dma_size
+= NX_LRO_BUFFER_EXTRA
;
263 rds_ring
->dma_size
+ NET_IP_ALIGN
;
267 rds_ring
->num_desc
= adapter
->num_lro_rxd
;
268 rds_ring
->dma_size
= NX_RX_LRO_BUFFER_LENGTH
;
269 rds_ring
->skb_size
= rds_ring
->dma_size
+ NET_IP_ALIGN
;
273 rds_ring
->rx_buf_arr
= vzalloc(RCV_BUFF_RINGSIZE(rds_ring
));
274 if (rds_ring
->rx_buf_arr
== NULL
)
275 /* free whatever was already allocated */
278 INIT_LIST_HEAD(&rds_ring
->free_list
);
280 * Now go through all of them, set reference handles
281 * and put them in the queues.
283 rx_buf
= rds_ring
->rx_buf_arr
;
284 for (i
= 0; i
< rds_ring
->num_desc
; i
++) {
285 list_add_tail(&rx_buf
->list
,
286 &rds_ring
->free_list
);
287 rx_buf
->ref_handle
= i
;
288 rx_buf
->state
= NETXEN_BUFFER_FREE
;
291 spin_lock_init(&rds_ring
->lock
);
294 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
295 sds_ring
= &recv_ctx
->sds_rings
[ring
];
296 sds_ring
->irq
= adapter
->msix_entries
[ring
].vector
;
297 sds_ring
->adapter
= adapter
;
298 sds_ring
->num_desc
= adapter
->num_rxd
;
300 for (i
= 0; i
< NUM_RCV_DESC_RINGS
; i
++)
301 INIT_LIST_HEAD(&sds_ring
->free_list
[i
]);
307 netxen_free_sw_resources(adapter
);
312 * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB
313 * address to external PCI CRB address.
315 static u32
netxen_decode_crb_addr(u32 addr
)
318 u32 base_addr
, offset
, pci_base
;
320 crb_addr_transform_setup();
322 pci_base
= NETXEN_ADDR_ERROR
;
323 base_addr
= addr
& 0xfff00000;
324 offset
= addr
& 0x000fffff;
326 for (i
= 0; i
< NETXEN_MAX_CRB_XFORM
; i
++) {
327 if (crb_addr_xform
[i
] == base_addr
) {
332 if (pci_base
== NETXEN_ADDR_ERROR
)
335 return pci_base
+ offset
;
338 #define NETXEN_MAX_ROM_WAIT_USEC 100
340 static int netxen_wait_rom_done(struct netxen_adapter
*adapter
)
348 done
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_STATUS
);
350 if (++timeout
>= NETXEN_MAX_ROM_WAIT_USEC
) {
351 dev_err(&adapter
->pdev
->dev
,
352 "Timeout reached waiting for rom done");
360 static int do_rom_fast_read(struct netxen_adapter
*adapter
,
363 NXWR32(adapter
, NETXEN_ROMUSB_ROM_ADDRESS
, addr
);
364 NXWR32(adapter
, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
365 NXWR32(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 3);
366 NXWR32(adapter
, NETXEN_ROMUSB_ROM_INSTR_OPCODE
, 0xb);
367 if (netxen_wait_rom_done(adapter
)) {
368 printk("Error waiting for rom done\n");
371 /* reset abyte_cnt and dummy_byte_cnt */
372 NXWR32(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 0);
374 NXWR32(adapter
, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
376 *valp
= NXRD32(adapter
, NETXEN_ROMUSB_ROM_RDATA
);
380 static int do_rom_fast_read_words(struct netxen_adapter
*adapter
, int addr
,
381 u8
*bytes
, size_t size
)
386 for (addridx
= addr
; addridx
< (addr
+ size
); addridx
+= 4) {
388 ret
= do_rom_fast_read(adapter
, addridx
, &v
);
391 *(__le32
*)bytes
= cpu_to_le32(v
);
399 netxen_rom_fast_read_words(struct netxen_adapter
*adapter
, int addr
,
400 u8
*bytes
, size_t size
)
404 ret
= netxen_rom_lock(adapter
);
408 ret
= do_rom_fast_read_words(adapter
, addr
, bytes
, size
);
410 netxen_rom_unlock(adapter
);
414 int netxen_rom_fast_read(struct netxen_adapter
*adapter
, int addr
, int *valp
)
418 if (netxen_rom_lock(adapter
) != 0)
421 ret
= do_rom_fast_read(adapter
, addr
, valp
);
422 netxen_rom_unlock(adapter
);
426 #define NETXEN_BOARDTYPE 0x4008
427 #define NETXEN_BOARDNUM 0x400c
428 #define NETXEN_CHIPNUM 0x4010
430 int netxen_pinit_from_rom(struct netxen_adapter
*adapter
)
433 int i
, n
, init_delay
= 0;
434 struct crb_addr_pair
*buf
;
439 netxen_rom_lock(adapter
);
440 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, 0xfeffffff);
441 netxen_rom_unlock(adapter
);
443 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
444 if (netxen_rom_fast_read(adapter
, 0, &n
) != 0 ||
446 netxen_rom_fast_read(adapter
, 4, &n
) != 0) {
447 printk(KERN_ERR
"%s: ERROR Reading crb_init area: "
448 "n: %08x\n", netxen_nic_driver_name
, n
);
451 offset
= n
& 0xffffU
;
452 n
= (n
>> 16) & 0xffffU
;
454 if (netxen_rom_fast_read(adapter
, 0, &n
) != 0 ||
456 printk(KERN_ERR
"%s: ERROR Reading crb_init area: "
457 "n: %08x\n", netxen_nic_driver_name
, n
);
465 printk(KERN_ERR
"%s:n=0x%x Error! NetXen card flash not"
466 " initialized.\n", __func__
, n
);
470 buf
= kcalloc(n
, sizeof(struct crb_addr_pair
), GFP_KERNEL
);
474 for (i
= 0; i
< n
; i
++) {
475 if (netxen_rom_fast_read(adapter
, 8*i
+ 4*offset
, &val
) != 0 ||
476 netxen_rom_fast_read(adapter
, 8*i
+ 4*offset
+ 4, &addr
) != 0) {
486 for (i
= 0; i
< n
; i
++) {
488 off
= netxen_decode_crb_addr(buf
[i
].addr
);
489 if (off
== NETXEN_ADDR_ERROR
) {
490 printk(KERN_ERR
"CRB init value out of range %x\n",
494 off
+= NETXEN_PCI_CRBSPACE
;
499 /* skipping cold reboot MAGIC */
500 if (off
== NETXEN_CAM_RAM(0x1fc))
503 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
504 if (off
== (NETXEN_CRB_I2C0
+ 0x1c))
506 /* do not reset PCI */
507 if (off
== (ROMUSB_GLB
+ 0xbc))
509 if (off
== (ROMUSB_GLB
+ 0xa8))
511 if (off
== (ROMUSB_GLB
+ 0xc8)) /* core clock */
513 if (off
== (ROMUSB_GLB
+ 0x24)) /* MN clock */
515 if (off
== (ROMUSB_GLB
+ 0x1c)) /* MS clock */
517 if ((off
& 0x0ff00000) == NETXEN_CRB_DDR_NET
)
519 if (off
== (NETXEN_CRB_PEG_NET_1
+ 0x18) &&
520 !NX_IS_REVISION_P3P(adapter
->ahw
.revision_id
))
521 buf
[i
].data
= 0x1020;
522 /* skip the function enable register */
523 if (off
== NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION
))
525 if (off
== NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION2
))
527 if ((off
& 0x0ff00000) == NETXEN_CRB_SMB
)
532 /* After writing this register, HW needs time for CRB */
533 /* to quiet down (else crb_window returns 0xffffffff) */
534 if (off
== NETXEN_ROMUSB_GLB_SW_RESET
) {
536 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
537 /* hold xdma in reset also */
538 buf
[i
].data
= NETXEN_NIC_XDMA_RESET
;
539 buf
[i
].data
= 0x8000ff;
543 NXWR32(adapter
, off
, buf
[i
].data
);
549 /* disable_peg_cache_all */
551 /* unreset_net_cache */
552 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
553 val
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
);
554 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, (val
& 0xffffff0f));
557 /* p2dn replyCount */
558 NXWR32(adapter
, NETXEN_CRB_PEG_NET_D
+ 0xec, 0x1e);
559 /* disable_peg_cache 0 */
560 NXWR32(adapter
, NETXEN_CRB_PEG_NET_D
+ 0x4c, 8);
561 /* disable_peg_cache 1 */
562 NXWR32(adapter
, NETXEN_CRB_PEG_NET_I
+ 0x4c, 8);
567 NXWR32(adapter
, NETXEN_CRB_PEG_NET_0
+ 0x8, 0);
568 NXWR32(adapter
, NETXEN_CRB_PEG_NET_0
+ 0xc, 0);
570 NXWR32(adapter
, NETXEN_CRB_PEG_NET_1
+ 0x8, 0);
571 NXWR32(adapter
, NETXEN_CRB_PEG_NET_1
+ 0xc, 0);
573 NXWR32(adapter
, NETXEN_CRB_PEG_NET_2
+ 0x8, 0);
574 NXWR32(adapter
, NETXEN_CRB_PEG_NET_2
+ 0xc, 0);
576 NXWR32(adapter
, NETXEN_CRB_PEG_NET_3
+ 0x8, 0);
577 NXWR32(adapter
, NETXEN_CRB_PEG_NET_3
+ 0xc, 0);
581 static struct uni_table_desc
*nx_get_table_desc(const u8
*unirom
, int section
)
584 struct uni_table_desc
*directory
= (struct uni_table_desc
*) &unirom
[0];
585 __le32 entries
= cpu_to_le32(directory
->num_entries
);
587 for (i
= 0; i
< entries
; i
++) {
589 __le32 offs
= cpu_to_le32(directory
->findex
) +
590 (i
* cpu_to_le32(directory
->entry_size
));
591 __le32 tab_type
= cpu_to_le32(*((u32
*)&unirom
[offs
] + 8));
593 if (tab_type
== section
)
594 return (struct uni_table_desc
*) &unirom
[offs
];
600 #define QLCNIC_FILEHEADER_SIZE (14 * 4)
603 netxen_nic_validate_header(struct netxen_adapter
*adapter
)
605 const u8
*unirom
= adapter
->fw
->data
;
606 struct uni_table_desc
*directory
= (struct uni_table_desc
*) &unirom
[0];
607 u32 fw_file_size
= adapter
->fw
->size
;
612 if (fw_file_size
< QLCNIC_FILEHEADER_SIZE
)
615 entries
= cpu_to_le32(directory
->num_entries
);
616 entry_size
= cpu_to_le32(directory
->entry_size
);
617 tab_size
= cpu_to_le32(directory
->findex
) + (entries
* entry_size
);
619 if (fw_file_size
< tab_size
)
626 netxen_nic_validate_bootld(struct netxen_adapter
*adapter
)
628 struct uni_table_desc
*tab_desc
;
629 struct uni_data_desc
*descr
;
630 const u8
*unirom
= adapter
->fw
->data
;
631 __le32 idx
= cpu_to_le32(*((int *)&unirom
[adapter
->file_prd_off
] +
632 NX_UNI_BOOTLD_IDX_OFF
));
637 tab_desc
= nx_get_table_desc(unirom
, NX_UNI_DIR_SECT_BOOTLD
);
642 tab_size
= cpu_to_le32(tab_desc
->findex
) +
643 (cpu_to_le32(tab_desc
->entry_size
) * (idx
+ 1));
645 if (adapter
->fw
->size
< tab_size
)
648 offs
= cpu_to_le32(tab_desc
->findex
) +
649 (cpu_to_le32(tab_desc
->entry_size
) * (idx
));
650 descr
= (struct uni_data_desc
*)&unirom
[offs
];
652 data_size
= cpu_to_le32(descr
->findex
) + cpu_to_le32(descr
->size
);
654 if (adapter
->fw
->size
< data_size
)
661 netxen_nic_validate_fw(struct netxen_adapter
*adapter
)
663 struct uni_table_desc
*tab_desc
;
664 struct uni_data_desc
*descr
;
665 const u8
*unirom
= adapter
->fw
->data
;
666 __le32 idx
= cpu_to_le32(*((int *)&unirom
[adapter
->file_prd_off
] +
667 NX_UNI_FIRMWARE_IDX_OFF
));
672 tab_desc
= nx_get_table_desc(unirom
, NX_UNI_DIR_SECT_FW
);
677 tab_size
= cpu_to_le32(tab_desc
->findex
) +
678 (cpu_to_le32(tab_desc
->entry_size
) * (idx
+ 1));
680 if (adapter
->fw
->size
< tab_size
)
683 offs
= cpu_to_le32(tab_desc
->findex
) +
684 (cpu_to_le32(tab_desc
->entry_size
) * (idx
));
685 descr
= (struct uni_data_desc
*)&unirom
[offs
];
686 data_size
= cpu_to_le32(descr
->findex
) + cpu_to_le32(descr
->size
);
688 if (adapter
->fw
->size
< data_size
)
696 netxen_nic_validate_product_offs(struct netxen_adapter
*adapter
)
698 struct uni_table_desc
*ptab_descr
;
699 const u8
*unirom
= adapter
->fw
->data
;
700 int mn_present
= (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) ?
701 1 : netxen_p3_has_mn(adapter
);
707 ptab_descr
= nx_get_table_desc(unirom
, NX_UNI_DIR_SECT_PRODUCT_TBL
);
708 if (ptab_descr
== NULL
)
711 entries
= cpu_to_le32(ptab_descr
->num_entries
);
712 entry_size
= cpu_to_le32(ptab_descr
->entry_size
);
713 tab_size
= cpu_to_le32(ptab_descr
->findex
) + (entries
* entry_size
);
715 if (adapter
->fw
->size
< tab_size
)
719 for (i
= 0; i
< entries
; i
++) {
721 __le32 flags
, file_chiprev
, offs
;
722 u8 chiprev
= adapter
->ahw
.revision_id
;
725 offs
= cpu_to_le32(ptab_descr
->findex
) +
726 (i
* cpu_to_le32(ptab_descr
->entry_size
));
727 flags
= cpu_to_le32(*((int *)&unirom
[offs
] + NX_UNI_FLAGS_OFF
));
728 file_chiprev
= cpu_to_le32(*((int *)&unirom
[offs
] +
729 NX_UNI_CHIP_REV_OFF
));
731 flagbit
= mn_present
? 1 : 2;
733 if ((chiprev
== file_chiprev
) &&
734 ((1ULL << flagbit
) & flags
)) {
735 adapter
->file_prd_off
= offs
;
740 if (mn_present
&& NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
749 netxen_nic_validate_unified_romimage(struct netxen_adapter
*adapter
)
751 if (netxen_nic_validate_header(adapter
)) {
752 dev_err(&adapter
->pdev
->dev
,
753 "unified image: header validation failed\n");
757 if (netxen_nic_validate_product_offs(adapter
)) {
758 dev_err(&adapter
->pdev
->dev
,
759 "unified image: product validation failed\n");
763 if (netxen_nic_validate_bootld(adapter
)) {
764 dev_err(&adapter
->pdev
->dev
,
765 "unified image: bootld validation failed\n");
769 if (netxen_nic_validate_fw(adapter
)) {
770 dev_err(&adapter
->pdev
->dev
,
771 "unified image: firmware validation failed\n");
778 static struct uni_data_desc
*nx_get_data_desc(struct netxen_adapter
*adapter
,
779 u32 section
, u32 idx_offset
)
781 const u8
*unirom
= adapter
->fw
->data
;
782 int idx
= cpu_to_le32(*((int *)&unirom
[adapter
->file_prd_off
] +
784 struct uni_table_desc
*tab_desc
;
787 tab_desc
= nx_get_table_desc(unirom
, section
);
789 if (tab_desc
== NULL
)
792 offs
= cpu_to_le32(tab_desc
->findex
) +
793 (cpu_to_le32(tab_desc
->entry_size
) * idx
);
795 return (struct uni_data_desc
*)&unirom
[offs
];
799 nx_get_bootld_offs(struct netxen_adapter
*adapter
)
801 u32 offs
= NETXEN_BOOTLD_START
;
803 if (adapter
->fw_type
== NX_UNIFIED_ROMIMAGE
)
804 offs
= cpu_to_le32((nx_get_data_desc(adapter
,
805 NX_UNI_DIR_SECT_BOOTLD
,
806 NX_UNI_BOOTLD_IDX_OFF
))->findex
);
808 return (u8
*)&adapter
->fw
->data
[offs
];
812 nx_get_fw_offs(struct netxen_adapter
*adapter
)
814 u32 offs
= NETXEN_IMAGE_START
;
816 if (adapter
->fw_type
== NX_UNIFIED_ROMIMAGE
)
817 offs
= cpu_to_le32((nx_get_data_desc(adapter
,
819 NX_UNI_FIRMWARE_IDX_OFF
))->findex
);
821 return (u8
*)&adapter
->fw
->data
[offs
];
825 nx_get_fw_size(struct netxen_adapter
*adapter
)
827 if (adapter
->fw_type
== NX_UNIFIED_ROMIMAGE
)
828 return cpu_to_le32((nx_get_data_desc(adapter
,
830 NX_UNI_FIRMWARE_IDX_OFF
))->size
);
833 *(u32
*)&adapter
->fw
->data
[NX_FW_SIZE_OFFSET
]);
837 nx_get_fw_version(struct netxen_adapter
*adapter
)
839 struct uni_data_desc
*fw_data_desc
;
840 const struct firmware
*fw
= adapter
->fw
;
841 __le32 major
, minor
, sub
;
845 if (adapter
->fw_type
== NX_UNIFIED_ROMIMAGE
) {
847 fw_data_desc
= nx_get_data_desc(adapter
,
848 NX_UNI_DIR_SECT_FW
, NX_UNI_FIRMWARE_IDX_OFF
);
849 ver_str
= fw
->data
+ cpu_to_le32(fw_data_desc
->findex
) +
850 cpu_to_le32(fw_data_desc
->size
) - 17;
852 for (i
= 0; i
< 12; i
++) {
853 if (!strncmp(&ver_str
[i
], "REV=", 4)) {
854 ret
= sscanf(&ver_str
[i
+4], "%u.%u.%u ",
855 &major
, &minor
, &sub
);
863 return major
+ (minor
<< 8) + (sub
<< 16);
866 return cpu_to_le32(*(u32
*)&fw
->data
[NX_FW_VERSION_OFFSET
]);
870 nx_get_bios_version(struct netxen_adapter
*adapter
)
872 const struct firmware
*fw
= adapter
->fw
;
873 __le32 bios_ver
, prd_off
= adapter
->file_prd_off
;
875 if (adapter
->fw_type
== NX_UNIFIED_ROMIMAGE
) {
876 bios_ver
= cpu_to_le32(*((u32
*) (&fw
->data
[prd_off
])
877 + NX_UNI_BIOS_VERSION_OFF
));
878 return (bios_ver
<< 16) + ((bios_ver
>> 8) & 0xff00) +
881 return cpu_to_le32(*(u32
*)&fw
->data
[NX_BIOS_VERSION_OFFSET
]);
886 netxen_need_fw_reset(struct netxen_adapter
*adapter
)
888 u32 count
, old_count
;
889 u32 val
, version
, major
, minor
, build
;
893 /* NX2031 firmware doesn't support heartbit */
894 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
897 if (adapter
->need_fw_reset
)
900 /* last attempt had failed */
901 if (NXRD32(adapter
, CRB_CMDPEG_STATE
) == PHAN_INITIALIZE_FAILED
)
904 old_count
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
906 for (i
= 0; i
< 10; i
++) {
908 timeout
= msleep_interruptible(200);
910 NXWR32(adapter
, CRB_CMDPEG_STATE
,
911 PHAN_INITIALIZE_FAILED
);
915 count
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
916 if (count
!= old_count
)
920 /* firmware is dead */
921 if (count
== old_count
)
924 /* check if we have got newer or different file firmware */
927 val
= nx_get_fw_version(adapter
);
929 version
= NETXEN_DECODE_VERSION(val
);
931 major
= NXRD32(adapter
, NETXEN_FW_VERSION_MAJOR
);
932 minor
= NXRD32(adapter
, NETXEN_FW_VERSION_MINOR
);
933 build
= NXRD32(adapter
, NETXEN_FW_VERSION_SUB
);
935 if (version
> NETXEN_VERSION_CODE(major
, minor
, build
))
938 if (version
== NETXEN_VERSION_CODE(major
, minor
, build
) &&
939 adapter
->fw_type
!= NX_UNIFIED_ROMIMAGE
) {
941 val
= NXRD32(adapter
, NETXEN_MIU_MN_CONTROL
);
942 fw_type
= (val
& 0x4) ?
943 NX_P3_CT_ROMIMAGE
: NX_P3_MN_ROMIMAGE
;
945 if (adapter
->fw_type
!= fw_type
)
953 #define NETXEN_MIN_P3_FW_SUPP NETXEN_VERSION_CODE(4, 0, 505)
956 netxen_check_flash_fw_compatibility(struct netxen_adapter
*adapter
)
958 u32 flash_fw_ver
, min_fw_ver
;
960 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
963 if (netxen_rom_fast_read(adapter
,
964 NX_FW_VERSION_OFFSET
, (int *)&flash_fw_ver
)) {
965 dev_err(&adapter
->pdev
->dev
, "Unable to read flash fw"
970 flash_fw_ver
= NETXEN_DECODE_VERSION(flash_fw_ver
);
971 min_fw_ver
= NETXEN_MIN_P3_FW_SUPP
;
972 if (flash_fw_ver
>= min_fw_ver
)
975 dev_info(&adapter
->pdev
->dev
, "Flash fw[%d.%d.%d] is < min fw supported"
976 "[4.0.505]. Please update firmware on flash\n",
977 _major(flash_fw_ver
), _minor(flash_fw_ver
),
978 _build(flash_fw_ver
));
982 static char *fw_name
[] = {
983 NX_P2_MN_ROMIMAGE_NAME
,
984 NX_P3_CT_ROMIMAGE_NAME
,
985 NX_P3_MN_ROMIMAGE_NAME
,
986 NX_UNIFIED_ROMIMAGE_NAME
,
987 NX_FLASH_ROMIMAGE_NAME
,
991 netxen_load_firmware(struct netxen_adapter
*adapter
)
994 u32 i
, flashaddr
, size
;
995 const struct firmware
*fw
= adapter
->fw
;
996 struct pci_dev
*pdev
= adapter
->pdev
;
998 dev_info(&pdev
->dev
, "loading firmware from %s\n",
999 fw_name
[adapter
->fw_type
]);
1001 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1002 NXWR32(adapter
, NETXEN_ROMUSB_GLB_CAS_RST
, 1);
1007 size
= (NETXEN_IMAGE_START
- NETXEN_BOOTLD_START
) / 8;
1009 ptr64
= (u64
*)nx_get_bootld_offs(adapter
);
1010 flashaddr
= NETXEN_BOOTLD_START
;
1012 for (i
= 0; i
< size
; i
++) {
1013 data
= cpu_to_le64(ptr64
[i
]);
1015 if (adapter
->pci_mem_write(adapter
, flashaddr
, data
))
1021 size
= (__force u32
)nx_get_fw_size(adapter
) / 8;
1023 ptr64
= (u64
*)nx_get_fw_offs(adapter
);
1024 flashaddr
= NETXEN_IMAGE_START
;
1026 for (i
= 0; i
< size
; i
++) {
1027 data
= cpu_to_le64(ptr64
[i
]);
1029 if (adapter
->pci_mem_write(adapter
,
1036 size
= (__force u32
)nx_get_fw_size(adapter
) % 8;
1038 data
= cpu_to_le64(ptr64
[i
]);
1040 if (adapter
->pci_mem_write(adapter
,
1049 size
= (NETXEN_IMAGE_START
- NETXEN_BOOTLD_START
) / 8;
1050 flashaddr
= NETXEN_BOOTLD_START
;
1052 for (i
= 0; i
< size
; i
++) {
1053 if (netxen_rom_fast_read(adapter
,
1054 flashaddr
, (int *)&lo
) != 0)
1056 if (netxen_rom_fast_read(adapter
,
1057 flashaddr
+ 4, (int *)&hi
) != 0)
1060 /* hi, lo are already in host endian byteorder */
1061 data
= (((u64
)hi
<< 32) | lo
);
1063 if (adapter
->pci_mem_write(adapter
,
1072 if (NX_IS_REVISION_P3P(adapter
->ahw
.revision_id
)) {
1073 NXWR32(adapter
, NETXEN_CRB_PEG_NET_0
+ 0x18, 0x1020);
1074 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, 0x80001e);
1075 } else if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1076 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, 0x80001d);
1078 NXWR32(adapter
, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL
, 0x3fff);
1079 NXWR32(adapter
, NETXEN_ROMUSB_GLB_CAS_RST
, 0);
1086 netxen_validate_firmware(struct netxen_adapter
*adapter
)
1089 __le32 flash_fw_ver
;
1090 u32 file_fw_ver
, min_ver
, bios
;
1091 struct pci_dev
*pdev
= adapter
->pdev
;
1092 const struct firmware
*fw
= adapter
->fw
;
1093 u8 fw_type
= adapter
->fw_type
;
1096 if (fw_type
== NX_UNIFIED_ROMIMAGE
) {
1097 if (netxen_nic_validate_unified_romimage(adapter
))
1100 val
= cpu_to_le32(*(u32
*)&fw
->data
[NX_FW_MAGIC_OFFSET
]);
1101 if ((__force u32
)val
!= NETXEN_BDINFO_MAGIC
)
1104 if (fw
->size
< NX_FW_MIN_SIZE
)
1108 val
= nx_get_fw_version(adapter
);
1110 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1111 min_ver
= NETXEN_MIN_P3_FW_SUPP
;
1113 min_ver
= NETXEN_VERSION_CODE(3, 4, 216);
1115 file_fw_ver
= NETXEN_DECODE_VERSION(val
);
1117 if ((_major(file_fw_ver
) > _NETXEN_NIC_LINUX_MAJOR
) ||
1118 (file_fw_ver
< min_ver
)) {
1120 "%s: firmware version %d.%d.%d unsupported\n",
1121 fw_name
[fw_type
], _major(file_fw_ver
), _minor(file_fw_ver
),
1122 _build(file_fw_ver
));
1125 val
= nx_get_bios_version(adapter
);
1126 netxen_rom_fast_read(adapter
, NX_BIOS_VERSION_OFFSET
, (int *)&bios
);
1127 if ((__force u32
)val
!= bios
) {
1128 dev_err(&pdev
->dev
, "%s: firmware bios is incompatible\n",
1133 if (netxen_rom_fast_read(adapter
,
1134 NX_FW_VERSION_OFFSET
, (int *)&flash_fw_ver
)) {
1135 dev_err(&pdev
->dev
, "Unable to read flash fw version\n");
1138 flash_fw_ver
= NETXEN_DECODE_VERSION(flash_fw_ver
);
1140 /* New fw from file is not allowed, if fw on flash is < 4.0.554 */
1141 crbinit_fix_fw
= NETXEN_VERSION_CODE(4, 0, 554);
1142 if (file_fw_ver
>= crbinit_fix_fw
&& flash_fw_ver
< crbinit_fix_fw
&&
1143 NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
1144 dev_err(&pdev
->dev
, "Incompatibility detected between driver "
1145 "and firmware version on flash. This configuration "
1146 "is not recommended. Please update the firmware on "
1147 "flash immediately\n");
1151 /* check if flashed firmware is newer only for no-mn and P2 case*/
1152 if (!netxen_p3_has_mn(adapter
) ||
1153 NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1154 if (flash_fw_ver
> file_fw_ver
) {
1155 dev_info(&pdev
->dev
, "%s: firmware is older than flash\n",
1161 NXWR32(adapter
, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC
);
1166 nx_get_next_fwtype(struct netxen_adapter
*adapter
)
1170 switch (adapter
->fw_type
) {
1171 case NX_UNKNOWN_ROMIMAGE
:
1172 fw_type
= NX_UNIFIED_ROMIMAGE
;
1175 case NX_UNIFIED_ROMIMAGE
:
1176 if (NX_IS_REVISION_P3P(adapter
->ahw
.revision_id
))
1177 fw_type
= NX_FLASH_ROMIMAGE
;
1178 else if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1179 fw_type
= NX_P2_MN_ROMIMAGE
;
1180 else if (netxen_p3_has_mn(adapter
))
1181 fw_type
= NX_P3_MN_ROMIMAGE
;
1183 fw_type
= NX_P3_CT_ROMIMAGE
;
1186 case NX_P3_MN_ROMIMAGE
:
1187 fw_type
= NX_P3_CT_ROMIMAGE
;
1190 case NX_P2_MN_ROMIMAGE
:
1191 case NX_P3_CT_ROMIMAGE
:
1193 fw_type
= NX_FLASH_ROMIMAGE
;
1197 adapter
->fw_type
= fw_type
;
1201 netxen_p3_has_mn(struct netxen_adapter
*adapter
)
1203 u32 capability
, flashed_ver
;
1206 /* NX2031 always had MN */
1207 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1210 netxen_rom_fast_read(adapter
,
1211 NX_FW_VERSION_OFFSET
, (int *)&flashed_ver
);
1212 flashed_ver
= NETXEN_DECODE_VERSION(flashed_ver
);
1214 if (flashed_ver
>= NETXEN_VERSION_CODE(4, 0, 220)) {
1216 capability
= NXRD32(adapter
, NX_PEG_TUNE_CAPABILITY
);
1217 if (capability
& NX_PEG_TUNE_MN_PRESENT
)
1223 void netxen_request_firmware(struct netxen_adapter
*adapter
)
1225 struct pci_dev
*pdev
= adapter
->pdev
;
1228 adapter
->fw_type
= NX_UNKNOWN_ROMIMAGE
;
1231 nx_get_next_fwtype(adapter
);
1233 if (adapter
->fw_type
== NX_FLASH_ROMIMAGE
) {
1236 rc
= request_firmware(&adapter
->fw
,
1237 fw_name
[adapter
->fw_type
], &pdev
->dev
);
1241 rc
= netxen_validate_firmware(adapter
);
1243 release_firmware(adapter
->fw
);
1252 netxen_release_firmware(struct netxen_adapter
*adapter
)
1254 release_firmware(adapter
->fw
);
1258 int netxen_init_dummy_dma(struct netxen_adapter
*adapter
)
1263 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1266 adapter
->dummy_dma
.addr
= pci_alloc_consistent(adapter
->pdev
,
1267 NETXEN_HOST_DUMMY_DMA_SIZE
,
1268 &adapter
->dummy_dma
.phys_addr
);
1269 if (adapter
->dummy_dma
.addr
== NULL
) {
1270 dev_err(&adapter
->pdev
->dev
,
1271 "ERROR: Could not allocate dummy DMA memory\n");
1275 addr
= (uint64_t) adapter
->dummy_dma
.phys_addr
;
1276 hi
= (addr
>> 32) & 0xffffffff;
1277 lo
= addr
& 0xffffffff;
1279 NXWR32(adapter
, CRB_HOST_DUMMY_BUF_ADDR_HI
, hi
);
1280 NXWR32(adapter
, CRB_HOST_DUMMY_BUF_ADDR_LO
, lo
);
1286 * NetXen DMA watchdog control:
1288 * Bit 0 : enabled => R/O: 1 watchdog active, 0 inactive
1289 * Bit 1 : disable_request => 1 req disable dma watchdog
1290 * Bit 2 : enable_request => 1 req enable dma watchdog
1293 void netxen_free_dummy_dma(struct netxen_adapter
*adapter
)
1298 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1301 if (!adapter
->dummy_dma
.addr
)
1304 ctrl
= NXRD32(adapter
, NETXEN_DMA_WATCHDOG_CTRL
);
1305 if ((ctrl
& 0x1) != 0) {
1306 NXWR32(adapter
, NETXEN_DMA_WATCHDOG_CTRL
, (ctrl
| 0x2));
1308 while ((ctrl
& 0x1) != 0) {
1312 ctrl
= NXRD32(adapter
, NETXEN_DMA_WATCHDOG_CTRL
);
1320 pci_free_consistent(adapter
->pdev
,
1321 NETXEN_HOST_DUMMY_DMA_SIZE
,
1322 adapter
->dummy_dma
.addr
,
1323 adapter
->dummy_dma
.phys_addr
);
1324 adapter
->dummy_dma
.addr
= NULL
;
1326 dev_err(&adapter
->pdev
->dev
, "dma_watchdog_shutdown failed\n");
1329 int netxen_phantom_init(struct netxen_adapter
*adapter
, int pegtune_val
)
1338 val
= NXRD32(adapter
, CRB_CMDPEG_STATE
);
1340 case PHAN_INITIALIZE_COMPLETE
:
1341 case PHAN_INITIALIZE_ACK
:
1343 case PHAN_INITIALIZE_FAILED
:
1351 } while (--retries
);
1353 NXWR32(adapter
, CRB_CMDPEG_STATE
, PHAN_INITIALIZE_FAILED
);
1356 dev_warn(&adapter
->pdev
->dev
, "firmware init failed\n");
1361 netxen_receive_peg_ready(struct netxen_adapter
*adapter
)
1367 val
= NXRD32(adapter
, CRB_RCVPEG_STATE
);
1369 if (val
== PHAN_PEG_RCV_INITIALIZED
)
1374 } while (--retries
);
1377 printk(KERN_ERR
"Receive Peg initialization not "
1378 "complete, state: 0x%x.\n", val
);
1385 int netxen_init_firmware(struct netxen_adapter
*adapter
)
1389 err
= netxen_receive_peg_ready(adapter
);
1393 NXWR32(adapter
, CRB_NIC_CAPABILITIES_HOST
, INTR_SCHEME_PERPORT
);
1394 NXWR32(adapter
, CRB_MPORT_MODE
, MPORT_MULTI_FUNCTION_MODE
);
1395 NXWR32(adapter
, CRB_CMDPEG_STATE
, PHAN_INITIALIZE_ACK
);
1397 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1398 NXWR32(adapter
, CRB_NIC_MSI_MODE_HOST
, MSI_MODE_MULTIFUNC
);
1404 netxen_handle_linkevent(struct netxen_adapter
*adapter
, nx_fw_msg_t
*msg
)
1409 u8 link_status
, module
, duplex
, autoneg
;
1410 struct net_device
*netdev
= adapter
->netdev
;
1412 adapter
->has_link_events
= 1;
1414 cable_OUI
= msg
->body
[1] & 0xffffffff;
1415 cable_len
= (msg
->body
[1] >> 32) & 0xffff;
1416 link_speed
= (msg
->body
[1] >> 48) & 0xffff;
1418 link_status
= msg
->body
[2] & 0xff;
1419 duplex
= (msg
->body
[2] >> 16) & 0xff;
1420 autoneg
= (msg
->body
[2] >> 24) & 0xff;
1422 module
= (msg
->body
[2] >> 8) & 0xff;
1423 if (module
== LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE
) {
1424 printk(KERN_INFO
"%s: unsupported cable: OUI 0x%x, length %d\n",
1425 netdev
->name
, cable_OUI
, cable_len
);
1426 } else if (module
== LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN
) {
1427 printk(KERN_INFO
"%s: unsupported cable length %d\n",
1428 netdev
->name
, cable_len
);
1431 /* update link parameters */
1432 if (duplex
== LINKEVENT_FULL_DUPLEX
)
1433 adapter
->link_duplex
= DUPLEX_FULL
;
1435 adapter
->link_duplex
= DUPLEX_HALF
;
1436 adapter
->module_type
= module
;
1437 adapter
->link_autoneg
= autoneg
;
1438 adapter
->link_speed
= link_speed
;
1440 netxen_advert_link_change(adapter
, link_status
);
1444 netxen_handle_fw_message(int desc_cnt
, int index
,
1445 struct nx_host_sds_ring
*sds_ring
)
1448 struct status_desc
*desc
;
1451 while (desc_cnt
> 0 && i
< 8) {
1452 desc
= &sds_ring
->desc_head
[index
];
1453 msg
.words
[i
++] = le64_to_cpu(desc
->status_desc_data
[0]);
1454 msg
.words
[i
++] = le64_to_cpu(desc
->status_desc_data
[1]);
1456 index
= get_next_index(index
, sds_ring
->num_desc
);
1460 opcode
= netxen_get_nic_msg_opcode(msg
.body
[0]);
1462 case NX_NIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE
:
1463 netxen_handle_linkevent(sds_ring
->adapter
, &msg
);
1471 netxen_alloc_rx_skb(struct netxen_adapter
*adapter
,
1472 struct nx_host_rds_ring
*rds_ring
,
1473 struct netxen_rx_buffer
*buffer
)
1475 struct sk_buff
*skb
;
1477 struct pci_dev
*pdev
= adapter
->pdev
;
1479 buffer
->skb
= netdev_alloc_skb(adapter
->netdev
, rds_ring
->skb_size
);
1485 if (!adapter
->ahw
.cut_through
)
1486 skb_reserve(skb
, 2);
1488 dma
= pci_map_single(pdev
, skb
->data
,
1489 rds_ring
->dma_size
, PCI_DMA_FROMDEVICE
);
1491 if (pci_dma_mapping_error(pdev
, dma
)) {
1492 dev_kfree_skb_any(skb
);
1499 buffer
->state
= NETXEN_BUFFER_BUSY
;
1504 static struct sk_buff
*netxen_process_rxbuf(struct netxen_adapter
*adapter
,
1505 struct nx_host_rds_ring
*rds_ring
, u16 index
, u16 cksum
)
1507 struct netxen_rx_buffer
*buffer
;
1508 struct sk_buff
*skb
;
1510 buffer
= &rds_ring
->rx_buf_arr
[index
];
1512 pci_unmap_single(adapter
->pdev
, buffer
->dma
, rds_ring
->dma_size
,
1513 PCI_DMA_FROMDEVICE
);
1519 if (likely((adapter
->netdev
->features
& NETIF_F_RXCSUM
)
1520 && cksum
== STATUS_CKSUM_OK
)) {
1521 adapter
->stats
.csummed
++;
1522 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1524 skb
->ip_summed
= CHECKSUM_NONE
;
1528 buffer
->state
= NETXEN_BUFFER_FREE
;
1532 static struct netxen_rx_buffer
*
1533 netxen_process_rcv(struct netxen_adapter
*adapter
,
1534 struct nx_host_sds_ring
*sds_ring
,
1535 int ring
, u64 sts_data0
)
1537 struct net_device
*netdev
= adapter
->netdev
;
1538 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1539 struct netxen_rx_buffer
*buffer
;
1540 struct sk_buff
*skb
;
1541 struct nx_host_rds_ring
*rds_ring
;
1542 int index
, length
, cksum
, pkt_offset
;
1544 if (unlikely(ring
>= adapter
->max_rds_rings
))
1547 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1549 index
= netxen_get_sts_refhandle(sts_data0
);
1550 if (unlikely(index
>= rds_ring
->num_desc
))
1553 buffer
= &rds_ring
->rx_buf_arr
[index
];
1555 length
= netxen_get_sts_totallength(sts_data0
);
1556 cksum
= netxen_get_sts_status(sts_data0
);
1557 pkt_offset
= netxen_get_sts_pkt_offset(sts_data0
);
1559 skb
= netxen_process_rxbuf(adapter
, rds_ring
, index
, cksum
);
1563 if (length
> rds_ring
->skb_size
)
1564 skb_put(skb
, rds_ring
->skb_size
);
1566 skb_put(skb
, length
);
1570 skb_pull(skb
, pkt_offset
);
1572 skb
->protocol
= eth_type_trans(skb
, netdev
);
1574 napi_gro_receive(&sds_ring
->napi
, skb
);
1576 adapter
->stats
.rx_pkts
++;
1577 adapter
->stats
.rxbytes
+= length
;
1582 #define TCP_HDR_SIZE 20
1583 #define TCP_TS_OPTION_SIZE 12
1584 #define TCP_TS_HDR_SIZE (TCP_HDR_SIZE + TCP_TS_OPTION_SIZE)
1586 static struct netxen_rx_buffer
*
1587 netxen_process_lro(struct netxen_adapter
*adapter
,
1588 struct nx_host_sds_ring
*sds_ring
,
1589 int ring
, u64 sts_data0
, u64 sts_data1
)
1591 struct net_device
*netdev
= adapter
->netdev
;
1592 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1593 struct netxen_rx_buffer
*buffer
;
1594 struct sk_buff
*skb
;
1595 struct nx_host_rds_ring
*rds_ring
;
1598 bool push
, timestamp
;
1599 int l2_hdr_offset
, l4_hdr_offset
;
1601 u16 lro_length
, length
, data_offset
;
1605 if (unlikely(ring
>= adapter
->max_rds_rings
))
1608 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1610 index
= netxen_get_lro_sts_refhandle(sts_data0
);
1611 if (unlikely(index
>= rds_ring
->num_desc
))
1614 buffer
= &rds_ring
->rx_buf_arr
[index
];
1616 timestamp
= netxen_get_lro_sts_timestamp(sts_data0
);
1617 lro_length
= netxen_get_lro_sts_length(sts_data0
);
1618 l2_hdr_offset
= netxen_get_lro_sts_l2_hdr_offset(sts_data0
);
1619 l4_hdr_offset
= netxen_get_lro_sts_l4_hdr_offset(sts_data0
);
1620 push
= netxen_get_lro_sts_push_flag(sts_data0
);
1621 seq_number
= netxen_get_lro_sts_seq_number(sts_data1
);
1623 skb
= netxen_process_rxbuf(adapter
, rds_ring
, index
, STATUS_CKSUM_OK
);
1628 data_offset
= l4_hdr_offset
+ TCP_TS_HDR_SIZE
;
1630 data_offset
= l4_hdr_offset
+ TCP_HDR_SIZE
;
1632 skb_put(skb
, lro_length
+ data_offset
);
1634 skb_pull(skb
, l2_hdr_offset
);
1635 skb
->protocol
= eth_type_trans(skb
, netdev
);
1637 if (skb
->protocol
== htons(ETH_P_8021Q
))
1638 vhdr_len
= VLAN_HLEN
;
1639 iph
= (struct iphdr
*)(skb
->data
+ vhdr_len
);
1640 th
= (struct tcphdr
*)((skb
->data
+ vhdr_len
) + (iph
->ihl
<< 2));
1642 length
= (iph
->ihl
<< 2) + (th
->doff
<< 2) + lro_length
;
1643 csum_replace2(&iph
->check
, iph
->tot_len
, htons(length
));
1644 iph
->tot_len
= htons(length
);
1646 th
->seq
= htonl(seq_number
);
1650 if (adapter
->flags
& NETXEN_FW_MSS_CAP
)
1651 skb_shinfo(skb
)->gso_size
= netxen_get_lro_sts_mss(sts_data1
);
1653 netif_receive_skb(skb
);
1655 adapter
->stats
.lro_pkts
++;
1656 adapter
->stats
.rxbytes
+= length
;
1661 #define netxen_merge_rx_buffers(list, head) \
1662 do { list_splice_tail_init(list, head); } while (0);
1665 netxen_process_rcv_ring(struct nx_host_sds_ring
*sds_ring
, int max
)
1667 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
1669 struct list_head
*cur
;
1671 struct status_desc
*desc
;
1672 struct netxen_rx_buffer
*rxbuf
;
1674 u32 consumer
= sds_ring
->consumer
;
1677 u64 sts_data0
, sts_data1
;
1678 int opcode
, ring
= 0, desc_cnt
;
1680 while (count
< max
) {
1681 desc
= &sds_ring
->desc_head
[consumer
];
1682 sts_data0
= le64_to_cpu(desc
->status_desc_data
[0]);
1684 if (!(sts_data0
& STATUS_OWNER_HOST
))
1687 desc_cnt
= netxen_get_sts_desc_cnt(sts_data0
);
1689 opcode
= netxen_get_sts_opcode(sts_data0
);
1692 case NETXEN_NIC_RXPKT_DESC
:
1693 case NETXEN_OLD_RXPKT_DESC
:
1694 case NETXEN_NIC_SYN_OFFLOAD
:
1695 ring
= netxen_get_sts_type(sts_data0
);
1696 rxbuf
= netxen_process_rcv(adapter
, sds_ring
,
1699 case NETXEN_NIC_LRO_DESC
:
1700 ring
= netxen_get_lro_sts_type(sts_data0
);
1701 sts_data1
= le64_to_cpu(desc
->status_desc_data
[1]);
1702 rxbuf
= netxen_process_lro(adapter
, sds_ring
,
1703 ring
, sts_data0
, sts_data1
);
1705 case NETXEN_NIC_RESPONSE_DESC
:
1706 netxen_handle_fw_message(desc_cnt
, consumer
, sds_ring
);
1711 WARN_ON(desc_cnt
> 1);
1714 list_add_tail(&rxbuf
->list
, &sds_ring
->free_list
[ring
]);
1717 for (; desc_cnt
> 0; desc_cnt
--) {
1718 desc
= &sds_ring
->desc_head
[consumer
];
1719 desc
->status_desc_data
[0] =
1720 cpu_to_le64(STATUS_OWNER_PHANTOM
);
1721 consumer
= get_next_index(consumer
, sds_ring
->num_desc
);
1726 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1727 struct nx_host_rds_ring
*rds_ring
=
1728 &adapter
->recv_ctx
.rds_rings
[ring
];
1730 if (!list_empty(&sds_ring
->free_list
[ring
])) {
1731 list_for_each(cur
, &sds_ring
->free_list
[ring
]) {
1732 rxbuf
= list_entry(cur
,
1733 struct netxen_rx_buffer
, list
);
1734 netxen_alloc_rx_skb(adapter
, rds_ring
, rxbuf
);
1736 spin_lock(&rds_ring
->lock
);
1737 netxen_merge_rx_buffers(&sds_ring
->free_list
[ring
],
1738 &rds_ring
->free_list
);
1739 spin_unlock(&rds_ring
->lock
);
1742 netxen_post_rx_buffers_nodb(adapter
, rds_ring
);
1746 sds_ring
->consumer
= consumer
;
1747 NXWRIO(adapter
, sds_ring
->crb_sts_consumer
, consumer
);
1753 /* Process Command status ring */
1754 int netxen_process_cmd_ring(struct netxen_adapter
*adapter
)
1756 u32 sw_consumer
, hw_consumer
;
1758 struct netxen_cmd_buffer
*buffer
;
1759 struct pci_dev
*pdev
= adapter
->pdev
;
1760 struct net_device
*netdev
= adapter
->netdev
;
1761 struct netxen_skb_frag
*frag
;
1763 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1765 if (!spin_trylock(&adapter
->tx_clean_lock
))
1768 sw_consumer
= tx_ring
->sw_consumer
;
1769 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
1771 while (sw_consumer
!= hw_consumer
) {
1772 buffer
= &tx_ring
->cmd_buf_arr
[sw_consumer
];
1774 frag
= &buffer
->frag_array
[0];
1775 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
1778 for (i
= 1; i
< buffer
->frag_count
; i
++) {
1779 frag
++; /* Get the next frag */
1780 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
1785 adapter
->stats
.xmitfinished
++;
1786 dev_kfree_skb_any(buffer
->skb
);
1790 sw_consumer
= get_next_index(sw_consumer
, tx_ring
->num_desc
);
1791 if (++count
>= MAX_STATUS_HANDLE
)
1795 if (count
&& netif_running(netdev
)) {
1796 tx_ring
->sw_consumer
= sw_consumer
;
1800 if (netif_queue_stopped(netdev
) && netif_carrier_ok(netdev
))
1801 if (netxen_tx_avail(tx_ring
) > TX_STOP_THRESH
)
1802 netif_wake_queue(netdev
);
1803 adapter
->tx_timeo_cnt
= 0;
1806 * If everything is freed up to consumer then check if the ring is full
1807 * If the ring is full then check if more needs to be freed and
1808 * schedule the call back again.
1810 * This happens when there are 2 CPUs. One could be freeing and the
1811 * other filling it. If the ring is full when we get out of here and
1812 * the card has already interrupted the host then the host can miss the
1815 * There is still a possible race condition and the host could miss an
1816 * interrupt. The card has to take care of this.
1818 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
1819 done
= (sw_consumer
== hw_consumer
);
1820 spin_unlock(&adapter
->tx_clean_lock
);
1826 netxen_post_rx_buffers(struct netxen_adapter
*adapter
, u32 ringid
,
1827 struct nx_host_rds_ring
*rds_ring
)
1829 struct rcv_desc
*pdesc
;
1830 struct netxen_rx_buffer
*buffer
;
1831 int producer
, count
= 0;
1832 netxen_ctx_msg msg
= 0;
1833 struct list_head
*head
;
1835 producer
= rds_ring
->producer
;
1837 head
= &rds_ring
->free_list
;
1838 while (!list_empty(head
)) {
1840 buffer
= list_entry(head
->next
, struct netxen_rx_buffer
, list
);
1843 if (netxen_alloc_rx_skb(adapter
, rds_ring
, buffer
))
1848 list_del(&buffer
->list
);
1850 /* make a rcv descriptor */
1851 pdesc
= &rds_ring
->desc_head
[producer
];
1852 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1853 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1854 pdesc
->buffer_length
= cpu_to_le32(rds_ring
->dma_size
);
1856 producer
= get_next_index(producer
, rds_ring
->num_desc
);
1860 rds_ring
->producer
= producer
;
1861 NXWRIO(adapter
, rds_ring
->crb_rcv_producer
,
1862 (producer
-1) & (rds_ring
->num_desc
-1));
1864 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1866 * Write a doorbell msg to tell phanmon of change in
1867 * receive ring producer
1868 * Only for firmware version < 4.0.0
1870 netxen_set_msg_peg_id(msg
, NETXEN_RCV_PEG_DB_ID
);
1871 netxen_set_msg_privid(msg
);
1872 netxen_set_msg_count(msg
,
1874 (rds_ring
->num_desc
- 1)));
1875 netxen_set_msg_ctxid(msg
, adapter
->portnum
);
1876 netxen_set_msg_opcode(msg
, NETXEN_RCV_PRODUCER(ringid
));
1877 NXWRIO(adapter
, DB_NORMALIZE(adapter
,
1878 NETXEN_RCV_PRODUCER_OFFSET
), msg
);
1884 netxen_post_rx_buffers_nodb(struct netxen_adapter
*adapter
,
1885 struct nx_host_rds_ring
*rds_ring
)
1887 struct rcv_desc
*pdesc
;
1888 struct netxen_rx_buffer
*buffer
;
1889 int producer
, count
= 0;
1890 struct list_head
*head
;
1892 if (!spin_trylock(&rds_ring
->lock
))
1895 producer
= rds_ring
->producer
;
1897 head
= &rds_ring
->free_list
;
1898 while (!list_empty(head
)) {
1900 buffer
= list_entry(head
->next
, struct netxen_rx_buffer
, list
);
1903 if (netxen_alloc_rx_skb(adapter
, rds_ring
, buffer
))
1908 list_del(&buffer
->list
);
1910 /* make a rcv descriptor */
1911 pdesc
= &rds_ring
->desc_head
[producer
];
1912 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1913 pdesc
->buffer_length
= cpu_to_le32(rds_ring
->dma_size
);
1914 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1916 producer
= get_next_index(producer
, rds_ring
->num_desc
);
1920 rds_ring
->producer
= producer
;
1921 NXWRIO(adapter
, rds_ring
->crb_rcv_producer
,
1922 (producer
- 1) & (rds_ring
->num_desc
- 1));
1924 spin_unlock(&rds_ring
->lock
);
1927 void netxen_nic_clear_stats(struct netxen_adapter
*adapter
)
1929 memset(&adapter
->stats
, 0, sizeof(adapter
->stats
));