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/netdevice.h>
27 #include <linux/delay.h>
28 #include <linux/slab.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
= 0; 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
;
203 struct pci_dev
*pdev
= adapter
->pdev
;
205 size
= sizeof(struct nx_host_tx_ring
);
206 tx_ring
= kzalloc(size
, GFP_KERNEL
);
207 if (tx_ring
== NULL
) {
208 dev_err(&pdev
->dev
, "%s: failed to allocate tx ring struct\n",
212 adapter
->tx_ring
= tx_ring
;
214 tx_ring
->num_desc
= adapter
->num_txd
;
215 tx_ring
->txq
= netdev_get_tx_queue(netdev
, 0);
217 cmd_buf_arr
= vmalloc(TX_BUFF_RINGSIZE(tx_ring
));
218 if (cmd_buf_arr
== NULL
) {
219 dev_err(&pdev
->dev
, "%s: failed to allocate cmd buffer ring\n",
223 memset(cmd_buf_arr
, 0, TX_BUFF_RINGSIZE(tx_ring
));
224 tx_ring
->cmd_buf_arr
= cmd_buf_arr
;
226 recv_ctx
= &adapter
->recv_ctx
;
228 size
= adapter
->max_rds_rings
* sizeof (struct nx_host_rds_ring
);
229 rds_ring
= kzalloc(size
, GFP_KERNEL
);
230 if (rds_ring
== NULL
) {
231 dev_err(&pdev
->dev
, "%s: failed to allocate rds ring struct\n",
235 recv_ctx
->rds_rings
= rds_ring
;
237 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
238 rds_ring
= &recv_ctx
->rds_rings
[ring
];
240 case RCV_RING_NORMAL
:
241 rds_ring
->num_desc
= adapter
->num_rxd
;
242 if (adapter
->ahw
.cut_through
) {
244 NX_CT_DEFAULT_RX_BUF_LEN
;
246 NX_CT_DEFAULT_RX_BUF_LEN
;
248 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
250 NX_P3_RX_BUF_MAX_LEN
;
253 NX_P2_RX_BUF_MAX_LEN
;
255 rds_ring
->dma_size
+ NET_IP_ALIGN
;
260 rds_ring
->num_desc
= adapter
->num_jumbo_rxd
;
261 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
263 NX_P3_RX_JUMBO_BUF_MAX_LEN
;
266 NX_P2_RX_JUMBO_BUF_MAX_LEN
;
268 if (adapter
->capabilities
& NX_CAP0_HW_LRO
)
269 rds_ring
->dma_size
+= NX_LRO_BUFFER_EXTRA
;
272 rds_ring
->dma_size
+ NET_IP_ALIGN
;
276 rds_ring
->num_desc
= adapter
->num_lro_rxd
;
277 rds_ring
->dma_size
= NX_RX_LRO_BUFFER_LENGTH
;
278 rds_ring
->skb_size
= rds_ring
->dma_size
+ NET_IP_ALIGN
;
282 rds_ring
->rx_buf_arr
= (struct netxen_rx_buffer
*)
283 vmalloc(RCV_BUFF_RINGSIZE(rds_ring
));
284 if (rds_ring
->rx_buf_arr
== NULL
) {
285 printk(KERN_ERR
"%s: Failed to allocate "
286 "rx buffer ring %d\n",
288 /* free whatever was already allocated */
291 memset(rds_ring
->rx_buf_arr
, 0, RCV_BUFF_RINGSIZE(rds_ring
));
292 INIT_LIST_HEAD(&rds_ring
->free_list
);
294 * Now go through all of them, set reference handles
295 * and put them in the queues.
297 rx_buf
= rds_ring
->rx_buf_arr
;
298 for (i
= 0; i
< rds_ring
->num_desc
; i
++) {
299 list_add_tail(&rx_buf
->list
,
300 &rds_ring
->free_list
);
301 rx_buf
->ref_handle
= i
;
302 rx_buf
->state
= NETXEN_BUFFER_FREE
;
305 spin_lock_init(&rds_ring
->lock
);
308 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
309 sds_ring
= &recv_ctx
->sds_rings
[ring
];
310 sds_ring
->irq
= adapter
->msix_entries
[ring
].vector
;
311 sds_ring
->adapter
= adapter
;
312 sds_ring
->num_desc
= adapter
->num_rxd
;
314 for (i
= 0; i
< NUM_RCV_DESC_RINGS
; i
++)
315 INIT_LIST_HEAD(&sds_ring
->free_list
[i
]);
321 netxen_free_sw_resources(adapter
);
326 * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB
327 * address to external PCI CRB address.
329 static u32
netxen_decode_crb_addr(u32 addr
)
332 u32 base_addr
, offset
, pci_base
;
334 crb_addr_transform_setup();
336 pci_base
= NETXEN_ADDR_ERROR
;
337 base_addr
= addr
& 0xfff00000;
338 offset
= addr
& 0x000fffff;
340 for (i
= 0; i
< NETXEN_MAX_CRB_XFORM
; i
++) {
341 if (crb_addr_xform
[i
] == base_addr
) {
346 if (pci_base
== NETXEN_ADDR_ERROR
)
349 return (pci_base
+ offset
);
352 #define NETXEN_MAX_ROM_WAIT_USEC 100
354 static int netxen_wait_rom_done(struct netxen_adapter
*adapter
)
362 done
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_STATUS
);
364 if (++timeout
>= NETXEN_MAX_ROM_WAIT_USEC
) {
365 dev_err(&adapter
->pdev
->dev
,
366 "Timeout reached waiting for rom done");
374 static int do_rom_fast_read(struct netxen_adapter
*adapter
,
377 NXWR32(adapter
, NETXEN_ROMUSB_ROM_ADDRESS
, addr
);
378 NXWR32(adapter
, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
379 NXWR32(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 3);
380 NXWR32(adapter
, NETXEN_ROMUSB_ROM_INSTR_OPCODE
, 0xb);
381 if (netxen_wait_rom_done(adapter
)) {
382 printk("Error waiting for rom done\n");
385 /* reset abyte_cnt and dummy_byte_cnt */
386 NXWR32(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 0);
388 NXWR32(adapter
, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
390 *valp
= NXRD32(adapter
, NETXEN_ROMUSB_ROM_RDATA
);
394 static int do_rom_fast_read_words(struct netxen_adapter
*adapter
, int addr
,
395 u8
*bytes
, size_t size
)
400 for (addridx
= addr
; addridx
< (addr
+ size
); addridx
+= 4) {
402 ret
= do_rom_fast_read(adapter
, addridx
, &v
);
405 *(__le32
*)bytes
= cpu_to_le32(v
);
413 netxen_rom_fast_read_words(struct netxen_adapter
*adapter
, int addr
,
414 u8
*bytes
, size_t size
)
418 ret
= netxen_rom_lock(adapter
);
422 ret
= do_rom_fast_read_words(adapter
, addr
, bytes
, size
);
424 netxen_rom_unlock(adapter
);
428 int netxen_rom_fast_read(struct netxen_adapter
*adapter
, int addr
, int *valp
)
432 if (netxen_rom_lock(adapter
) != 0)
435 ret
= do_rom_fast_read(adapter
, addr
, valp
);
436 netxen_rom_unlock(adapter
);
440 #define NETXEN_BOARDTYPE 0x4008
441 #define NETXEN_BOARDNUM 0x400c
442 #define NETXEN_CHIPNUM 0x4010
444 int netxen_pinit_from_rom(struct netxen_adapter
*adapter
)
447 int i
, n
, init_delay
= 0;
448 struct crb_addr_pair
*buf
;
453 netxen_rom_lock(adapter
);
454 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, 0xffffffff);
455 netxen_rom_unlock(adapter
);
457 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
458 if (netxen_rom_fast_read(adapter
, 0, &n
) != 0 ||
460 netxen_rom_fast_read(adapter
, 4, &n
) != 0) {
461 printk(KERN_ERR
"%s: ERROR Reading crb_init area: "
462 "n: %08x\n", netxen_nic_driver_name
, n
);
465 offset
= n
& 0xffffU
;
466 n
= (n
>> 16) & 0xffffU
;
468 if (netxen_rom_fast_read(adapter
, 0, &n
) != 0 ||
470 printk(KERN_ERR
"%s: ERROR Reading crb_init area: "
471 "n: %08x\n", netxen_nic_driver_name
, n
);
479 printk(KERN_ERR
"%s:n=0x%x Error! NetXen card flash not"
480 " initialized.\n", __func__
, n
);
484 buf
= kcalloc(n
, sizeof(struct crb_addr_pair
), GFP_KERNEL
);
486 printk("%s: netxen_pinit_from_rom: Unable to calloc memory.\n",
487 netxen_nic_driver_name
);
491 for (i
= 0; i
< n
; i
++) {
492 if (netxen_rom_fast_read(adapter
, 8*i
+ 4*offset
, &val
) != 0 ||
493 netxen_rom_fast_read(adapter
, 8*i
+ 4*offset
+ 4, &addr
) != 0) {
503 for (i
= 0; i
< n
; i
++) {
505 off
= netxen_decode_crb_addr(buf
[i
].addr
);
506 if (off
== NETXEN_ADDR_ERROR
) {
507 printk(KERN_ERR
"CRB init value out of range %x\n",
511 off
+= NETXEN_PCI_CRBSPACE
;
516 /* skipping cold reboot MAGIC */
517 if (off
== NETXEN_CAM_RAM(0x1fc))
520 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
521 if (off
== (NETXEN_CRB_I2C0
+ 0x1c))
523 /* do not reset PCI */
524 if (off
== (ROMUSB_GLB
+ 0xbc))
526 if (off
== (ROMUSB_GLB
+ 0xa8))
528 if (off
== (ROMUSB_GLB
+ 0xc8)) /* core clock */
530 if (off
== (ROMUSB_GLB
+ 0x24)) /* MN clock */
532 if (off
== (ROMUSB_GLB
+ 0x1c)) /* MS clock */
534 if ((off
& 0x0ff00000) == NETXEN_CRB_DDR_NET
)
536 if (off
== (NETXEN_CRB_PEG_NET_1
+ 0x18) &&
537 !NX_IS_REVISION_P3P(adapter
->ahw
.revision_id
))
538 buf
[i
].data
= 0x1020;
539 /* skip the function enable register */
540 if (off
== NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION
))
542 if (off
== NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION2
))
544 if ((off
& 0x0ff00000) == NETXEN_CRB_SMB
)
549 /* After writing this register, HW needs time for CRB */
550 /* to quiet down (else crb_window returns 0xffffffff) */
551 if (off
== NETXEN_ROMUSB_GLB_SW_RESET
) {
553 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
554 /* hold xdma in reset also */
555 buf
[i
].data
= NETXEN_NIC_XDMA_RESET
;
556 buf
[i
].data
= 0x8000ff;
560 NXWR32(adapter
, off
, buf
[i
].data
);
566 /* disable_peg_cache_all */
568 /* unreset_net_cache */
569 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
570 val
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
);
571 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, (val
& 0xffffff0f));
574 /* p2dn replyCount */
575 NXWR32(adapter
, NETXEN_CRB_PEG_NET_D
+ 0xec, 0x1e);
576 /* disable_peg_cache 0 */
577 NXWR32(adapter
, NETXEN_CRB_PEG_NET_D
+ 0x4c, 8);
578 /* disable_peg_cache 1 */
579 NXWR32(adapter
, NETXEN_CRB_PEG_NET_I
+ 0x4c, 8);
584 NXWR32(adapter
, NETXEN_CRB_PEG_NET_0
+ 0x8, 0);
585 NXWR32(adapter
, NETXEN_CRB_PEG_NET_0
+ 0xc, 0);
587 NXWR32(adapter
, NETXEN_CRB_PEG_NET_1
+ 0x8, 0);
588 NXWR32(adapter
, NETXEN_CRB_PEG_NET_1
+ 0xc, 0);
590 NXWR32(adapter
, NETXEN_CRB_PEG_NET_2
+ 0x8, 0);
591 NXWR32(adapter
, NETXEN_CRB_PEG_NET_2
+ 0xc, 0);
593 NXWR32(adapter
, NETXEN_CRB_PEG_NET_3
+ 0x8, 0);
594 NXWR32(adapter
, NETXEN_CRB_PEG_NET_3
+ 0xc, 0);
598 static struct uni_table_desc
*nx_get_table_desc(const u8
*unirom
, int section
)
601 struct uni_table_desc
*directory
= (struct uni_table_desc
*) &unirom
[0];
602 __le32 entries
= cpu_to_le32(directory
->num_entries
);
604 for (i
= 0; i
< entries
; i
++) {
606 __le32 offs
= cpu_to_le32(directory
->findex
) +
607 (i
* cpu_to_le32(directory
->entry_size
));
608 __le32 tab_type
= cpu_to_le32(*((u32
*)&unirom
[offs
] + 8));
610 if (tab_type
== section
)
611 return (struct uni_table_desc
*) &unirom
[offs
];
617 #define QLCNIC_FILEHEADER_SIZE (14 * 4)
620 netxen_nic_validate_header(struct netxen_adapter
*adapter
)
622 const u8
*unirom
= adapter
->fw
->data
;
623 struct uni_table_desc
*directory
= (struct uni_table_desc
*) &unirom
[0];
624 u32 fw_file_size
= adapter
->fw
->size
;
629 if (fw_file_size
< QLCNIC_FILEHEADER_SIZE
)
632 entries
= cpu_to_le32(directory
->num_entries
);
633 entry_size
= cpu_to_le32(directory
->entry_size
);
634 tab_size
= cpu_to_le32(directory
->findex
) + (entries
* entry_size
);
636 if (fw_file_size
< tab_size
)
643 netxen_nic_validate_bootld(struct netxen_adapter
*adapter
)
645 struct uni_table_desc
*tab_desc
;
646 struct uni_data_desc
*descr
;
647 const u8
*unirom
= adapter
->fw
->data
;
648 __le32 idx
= cpu_to_le32(*((int *)&unirom
[adapter
->file_prd_off
] +
649 NX_UNI_BOOTLD_IDX_OFF
));
654 tab_desc
= nx_get_table_desc(unirom
, NX_UNI_DIR_SECT_BOOTLD
);
659 tab_size
= cpu_to_le32(tab_desc
->findex
) +
660 (cpu_to_le32(tab_desc
->entry_size
) * (idx
+ 1));
662 if (adapter
->fw
->size
< tab_size
)
665 offs
= cpu_to_le32(tab_desc
->findex
) +
666 (cpu_to_le32(tab_desc
->entry_size
) * (idx
));
667 descr
= (struct uni_data_desc
*)&unirom
[offs
];
669 data_size
= cpu_to_le32(descr
->findex
) + cpu_to_le32(descr
->size
);
671 if (adapter
->fw
->size
< data_size
)
678 netxen_nic_validate_fw(struct netxen_adapter
*adapter
)
680 struct uni_table_desc
*tab_desc
;
681 struct uni_data_desc
*descr
;
682 const u8
*unirom
= adapter
->fw
->data
;
683 __le32 idx
= cpu_to_le32(*((int *)&unirom
[adapter
->file_prd_off
] +
684 NX_UNI_FIRMWARE_IDX_OFF
));
689 tab_desc
= nx_get_table_desc(unirom
, NX_UNI_DIR_SECT_FW
);
694 tab_size
= cpu_to_le32(tab_desc
->findex
) +
695 (cpu_to_le32(tab_desc
->entry_size
) * (idx
+ 1));
697 if (adapter
->fw
->size
< tab_size
)
700 offs
= cpu_to_le32(tab_desc
->findex
) +
701 (cpu_to_le32(tab_desc
->entry_size
) * (idx
));
702 descr
= (struct uni_data_desc
*)&unirom
[offs
];
703 data_size
= cpu_to_le32(descr
->findex
) + cpu_to_le32(descr
->size
);
705 if (adapter
->fw
->size
< data_size
)
713 netxen_nic_validate_product_offs(struct netxen_adapter
*adapter
)
715 struct uni_table_desc
*ptab_descr
;
716 const u8
*unirom
= adapter
->fw
->data
;
717 int mn_present
= (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) ?
718 1 : netxen_p3_has_mn(adapter
);
724 ptab_descr
= nx_get_table_desc(unirom
, NX_UNI_DIR_SECT_PRODUCT_TBL
);
725 if (ptab_descr
== NULL
)
728 entries
= cpu_to_le32(ptab_descr
->num_entries
);
729 entry_size
= cpu_to_le32(ptab_descr
->entry_size
);
730 tab_size
= cpu_to_le32(ptab_descr
->findex
) + (entries
* entry_size
);
732 if (adapter
->fw
->size
< tab_size
)
736 for (i
= 0; i
< entries
; i
++) {
738 __le32 flags
, file_chiprev
, offs
;
739 u8 chiprev
= adapter
->ahw
.revision_id
;
742 offs
= cpu_to_le32(ptab_descr
->findex
) +
743 (i
* cpu_to_le32(ptab_descr
->entry_size
));
744 flags
= cpu_to_le32(*((int *)&unirom
[offs
] + NX_UNI_FLAGS_OFF
));
745 file_chiprev
= cpu_to_le32(*((int *)&unirom
[offs
] +
746 NX_UNI_CHIP_REV_OFF
));
748 flagbit
= mn_present
? 1 : 2;
750 if ((chiprev
== file_chiprev
) &&
751 ((1ULL << flagbit
) & flags
)) {
752 adapter
->file_prd_off
= offs
;
757 if (mn_present
&& NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
766 netxen_nic_validate_unified_romimage(struct netxen_adapter
*adapter
)
768 if (netxen_nic_validate_header(adapter
)) {
769 dev_err(&adapter
->pdev
->dev
,
770 "unified image: header validation failed\n");
774 if (netxen_nic_validate_product_offs(adapter
)) {
775 dev_err(&adapter
->pdev
->dev
,
776 "unified image: product validation failed\n");
780 if (netxen_nic_validate_bootld(adapter
)) {
781 dev_err(&adapter
->pdev
->dev
,
782 "unified image: bootld validation failed\n");
786 if (netxen_nic_validate_fw(adapter
)) {
787 dev_err(&adapter
->pdev
->dev
,
788 "unified image: firmware validation failed\n");
795 static struct uni_data_desc
*nx_get_data_desc(struct netxen_adapter
*adapter
,
796 u32 section
, u32 idx_offset
)
798 const u8
*unirom
= adapter
->fw
->data
;
799 int idx
= cpu_to_le32(*((int *)&unirom
[adapter
->file_prd_off
] +
801 struct uni_table_desc
*tab_desc
;
804 tab_desc
= nx_get_table_desc(unirom
, section
);
806 if (tab_desc
== NULL
)
809 offs
= cpu_to_le32(tab_desc
->findex
) +
810 (cpu_to_le32(tab_desc
->entry_size
) * idx
);
812 return (struct uni_data_desc
*)&unirom
[offs
];
816 nx_get_bootld_offs(struct netxen_adapter
*adapter
)
818 u32 offs
= NETXEN_BOOTLD_START
;
820 if (adapter
->fw_type
== NX_UNIFIED_ROMIMAGE
)
821 offs
= cpu_to_le32((nx_get_data_desc(adapter
,
822 NX_UNI_DIR_SECT_BOOTLD
,
823 NX_UNI_BOOTLD_IDX_OFF
))->findex
);
825 return (u8
*)&adapter
->fw
->data
[offs
];
829 nx_get_fw_offs(struct netxen_adapter
*adapter
)
831 u32 offs
= NETXEN_IMAGE_START
;
833 if (adapter
->fw_type
== NX_UNIFIED_ROMIMAGE
)
834 offs
= cpu_to_le32((nx_get_data_desc(adapter
,
836 NX_UNI_FIRMWARE_IDX_OFF
))->findex
);
838 return (u8
*)&adapter
->fw
->data
[offs
];
842 nx_get_fw_size(struct netxen_adapter
*adapter
)
844 if (adapter
->fw_type
== NX_UNIFIED_ROMIMAGE
)
845 return cpu_to_le32((nx_get_data_desc(adapter
,
847 NX_UNI_FIRMWARE_IDX_OFF
))->size
);
850 *(u32
*)&adapter
->fw
->data
[NX_FW_SIZE_OFFSET
]);
854 nx_get_fw_version(struct netxen_adapter
*adapter
)
856 struct uni_data_desc
*fw_data_desc
;
857 const struct firmware
*fw
= adapter
->fw
;
858 __le32 major
, minor
, sub
;
862 if (adapter
->fw_type
== NX_UNIFIED_ROMIMAGE
) {
864 fw_data_desc
= nx_get_data_desc(adapter
,
865 NX_UNI_DIR_SECT_FW
, NX_UNI_FIRMWARE_IDX_OFF
);
866 ver_str
= fw
->data
+ cpu_to_le32(fw_data_desc
->findex
) +
867 cpu_to_le32(fw_data_desc
->size
) - 17;
869 for (i
= 0; i
< 12; i
++) {
870 if (!strncmp(&ver_str
[i
], "REV=", 4)) {
871 ret
= sscanf(&ver_str
[i
+4], "%u.%u.%u ",
872 &major
, &minor
, &sub
);
880 return major
+ (minor
<< 8) + (sub
<< 16);
883 return cpu_to_le32(*(u32
*)&fw
->data
[NX_FW_VERSION_OFFSET
]);
887 nx_get_bios_version(struct netxen_adapter
*adapter
)
889 const struct firmware
*fw
= adapter
->fw
;
890 __le32 bios_ver
, prd_off
= adapter
->file_prd_off
;
892 if (adapter
->fw_type
== NX_UNIFIED_ROMIMAGE
) {
893 bios_ver
= cpu_to_le32(*((u32
*) (&fw
->data
[prd_off
])
894 + NX_UNI_BIOS_VERSION_OFF
));
895 return (bios_ver
<< 16) + ((bios_ver
>> 8) & 0xff00) +
898 return cpu_to_le32(*(u32
*)&fw
->data
[NX_BIOS_VERSION_OFFSET
]);
903 netxen_need_fw_reset(struct netxen_adapter
*adapter
)
905 u32 count
, old_count
;
906 u32 val
, version
, major
, minor
, build
;
910 /* NX2031 firmware doesn't support heartbit */
911 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
914 if (adapter
->need_fw_reset
)
917 /* last attempt had failed */
918 if (NXRD32(adapter
, CRB_CMDPEG_STATE
) == PHAN_INITIALIZE_FAILED
)
921 old_count
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
923 for (i
= 0; i
< 10; i
++) {
925 timeout
= msleep_interruptible(200);
927 NXWR32(adapter
, CRB_CMDPEG_STATE
,
928 PHAN_INITIALIZE_FAILED
);
932 count
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
933 if (count
!= old_count
)
937 /* firmware is dead */
938 if (count
== old_count
)
941 /* check if we have got newer or different file firmware */
944 val
= nx_get_fw_version(adapter
);
946 version
= NETXEN_DECODE_VERSION(val
);
948 major
= NXRD32(adapter
, NETXEN_FW_VERSION_MAJOR
);
949 minor
= NXRD32(adapter
, NETXEN_FW_VERSION_MINOR
);
950 build
= NXRD32(adapter
, NETXEN_FW_VERSION_SUB
);
952 if (version
> NETXEN_VERSION_CODE(major
, minor
, build
))
955 if (version
== NETXEN_VERSION_CODE(major
, minor
, build
) &&
956 adapter
->fw_type
!= NX_UNIFIED_ROMIMAGE
) {
958 val
= NXRD32(adapter
, NETXEN_MIU_MN_CONTROL
);
959 fw_type
= (val
& 0x4) ?
960 NX_P3_CT_ROMIMAGE
: NX_P3_MN_ROMIMAGE
;
962 if (adapter
->fw_type
!= fw_type
)
970 static char *fw_name
[] = {
971 NX_P2_MN_ROMIMAGE_NAME
,
972 NX_P3_CT_ROMIMAGE_NAME
,
973 NX_P3_MN_ROMIMAGE_NAME
,
974 NX_UNIFIED_ROMIMAGE_NAME
,
975 NX_FLASH_ROMIMAGE_NAME
,
979 netxen_load_firmware(struct netxen_adapter
*adapter
)
982 u32 i
, flashaddr
, size
;
983 const struct firmware
*fw
= adapter
->fw
;
984 struct pci_dev
*pdev
= adapter
->pdev
;
986 dev_info(&pdev
->dev
, "loading firmware from %s\n",
987 fw_name
[adapter
->fw_type
]);
989 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
990 NXWR32(adapter
, NETXEN_ROMUSB_GLB_CAS_RST
, 1);
995 size
= (NETXEN_IMAGE_START
- NETXEN_BOOTLD_START
) / 8;
997 ptr64
= (u64
*)nx_get_bootld_offs(adapter
);
998 flashaddr
= NETXEN_BOOTLD_START
;
1000 for (i
= 0; i
< size
; i
++) {
1001 data
= cpu_to_le64(ptr64
[i
]);
1003 if (adapter
->pci_mem_write(adapter
, flashaddr
, data
))
1009 size
= (__force u32
)nx_get_fw_size(adapter
) / 8;
1011 ptr64
= (u64
*)nx_get_fw_offs(adapter
);
1012 flashaddr
= NETXEN_IMAGE_START
;
1014 for (i
= 0; i
< size
; i
++) {
1015 data
= cpu_to_le64(ptr64
[i
]);
1017 if (adapter
->pci_mem_write(adapter
,
1024 size
= (__force u32
)nx_get_fw_size(adapter
) % 8;
1026 data
= cpu_to_le64(ptr64
[i
]);
1028 if (adapter
->pci_mem_write(adapter
,
1037 size
= (NETXEN_IMAGE_START
- NETXEN_BOOTLD_START
) / 8;
1038 flashaddr
= NETXEN_BOOTLD_START
;
1040 for (i
= 0; i
< size
; i
++) {
1041 if (netxen_rom_fast_read(adapter
,
1042 flashaddr
, (int *)&lo
) != 0)
1044 if (netxen_rom_fast_read(adapter
,
1045 flashaddr
+ 4, (int *)&hi
) != 0)
1048 /* hi, lo are already in host endian byteorder */
1049 data
= (((u64
)hi
<< 32) | lo
);
1051 if (adapter
->pci_mem_write(adapter
,
1060 if (NX_IS_REVISION_P3P(adapter
->ahw
.revision_id
)) {
1061 NXWR32(adapter
, NETXEN_CRB_PEG_NET_0
+ 0x18, 0x1020);
1062 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, 0x80001e);
1063 } else if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1064 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, 0x80001d);
1066 NXWR32(adapter
, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL
, 0x3fff);
1067 NXWR32(adapter
, NETXEN_ROMUSB_GLB_CAS_RST
, 0);
1074 netxen_validate_firmware(struct netxen_adapter
*adapter
)
1077 u32 ver
, min_ver
, bios
;
1078 struct pci_dev
*pdev
= adapter
->pdev
;
1079 const struct firmware
*fw
= adapter
->fw
;
1080 u8 fw_type
= adapter
->fw_type
;
1082 if (fw_type
== NX_UNIFIED_ROMIMAGE
) {
1083 if (netxen_nic_validate_unified_romimage(adapter
))
1086 val
= cpu_to_le32(*(u32
*)&fw
->data
[NX_FW_MAGIC_OFFSET
]);
1087 if ((__force u32
)val
!= NETXEN_BDINFO_MAGIC
)
1090 if (fw
->size
< NX_FW_MIN_SIZE
)
1094 val
= nx_get_fw_version(adapter
);
1096 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1097 min_ver
= NETXEN_VERSION_CODE(4, 0, 216);
1099 min_ver
= NETXEN_VERSION_CODE(3, 4, 216);
1101 ver
= NETXEN_DECODE_VERSION(val
);
1103 if ((_major(ver
) > _NETXEN_NIC_LINUX_MAJOR
) || (ver
< min_ver
)) {
1105 "%s: firmware version %d.%d.%d unsupported\n",
1106 fw_name
[fw_type
], _major(ver
), _minor(ver
), _build(ver
));
1110 val
= nx_get_bios_version(adapter
);
1111 netxen_rom_fast_read(adapter
, NX_BIOS_VERSION_OFFSET
, (int *)&bios
);
1112 if ((__force u32
)val
!= bios
) {
1113 dev_err(&pdev
->dev
, "%s: firmware bios is incompatible\n",
1118 /* check if flashed firmware is newer */
1119 if (netxen_rom_fast_read(adapter
,
1120 NX_FW_VERSION_OFFSET
, (int *)&val
))
1122 val
= NETXEN_DECODE_VERSION(val
);
1124 dev_info(&pdev
->dev
, "%s: firmware is older than flash\n",
1129 NXWR32(adapter
, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC
);
1134 nx_get_next_fwtype(struct netxen_adapter
*adapter
)
1138 switch (adapter
->fw_type
) {
1139 case NX_UNKNOWN_ROMIMAGE
:
1140 fw_type
= NX_UNIFIED_ROMIMAGE
;
1143 case NX_UNIFIED_ROMIMAGE
:
1144 if (NX_IS_REVISION_P3P(adapter
->ahw
.revision_id
))
1145 fw_type
= NX_FLASH_ROMIMAGE
;
1146 else if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1147 fw_type
= NX_P2_MN_ROMIMAGE
;
1148 else if (netxen_p3_has_mn(adapter
))
1149 fw_type
= NX_P3_MN_ROMIMAGE
;
1151 fw_type
= NX_P3_CT_ROMIMAGE
;
1154 case NX_P3_MN_ROMIMAGE
:
1155 fw_type
= NX_P3_CT_ROMIMAGE
;
1158 case NX_P2_MN_ROMIMAGE
:
1159 case NX_P3_CT_ROMIMAGE
:
1161 fw_type
= NX_FLASH_ROMIMAGE
;
1165 adapter
->fw_type
= fw_type
;
1169 netxen_p3_has_mn(struct netxen_adapter
*adapter
)
1171 u32 capability
, flashed_ver
;
1174 /* NX2031 always had MN */
1175 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1178 netxen_rom_fast_read(adapter
,
1179 NX_FW_VERSION_OFFSET
, (int *)&flashed_ver
);
1180 flashed_ver
= NETXEN_DECODE_VERSION(flashed_ver
);
1182 if (flashed_ver
>= NETXEN_VERSION_CODE(4, 0, 220)) {
1184 capability
= NXRD32(adapter
, NX_PEG_TUNE_CAPABILITY
);
1185 if (capability
& NX_PEG_TUNE_MN_PRESENT
)
1191 void netxen_request_firmware(struct netxen_adapter
*adapter
)
1193 struct pci_dev
*pdev
= adapter
->pdev
;
1196 adapter
->fw_type
= NX_UNKNOWN_ROMIMAGE
;
1199 nx_get_next_fwtype(adapter
);
1201 if (adapter
->fw_type
== NX_FLASH_ROMIMAGE
) {
1204 rc
= request_firmware(&adapter
->fw
,
1205 fw_name
[adapter
->fw_type
], &pdev
->dev
);
1209 rc
= netxen_validate_firmware(adapter
);
1211 release_firmware(adapter
->fw
);
1220 netxen_release_firmware(struct netxen_adapter
*adapter
)
1223 release_firmware(adapter
->fw
);
1227 int netxen_init_dummy_dma(struct netxen_adapter
*adapter
)
1232 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1235 adapter
->dummy_dma
.addr
= pci_alloc_consistent(adapter
->pdev
,
1236 NETXEN_HOST_DUMMY_DMA_SIZE
,
1237 &adapter
->dummy_dma
.phys_addr
);
1238 if (adapter
->dummy_dma
.addr
== NULL
) {
1239 dev_err(&adapter
->pdev
->dev
,
1240 "ERROR: Could not allocate dummy DMA memory\n");
1244 addr
= (uint64_t) adapter
->dummy_dma
.phys_addr
;
1245 hi
= (addr
>> 32) & 0xffffffff;
1246 lo
= addr
& 0xffffffff;
1248 NXWR32(adapter
, CRB_HOST_DUMMY_BUF_ADDR_HI
, hi
);
1249 NXWR32(adapter
, CRB_HOST_DUMMY_BUF_ADDR_LO
, lo
);
1255 * NetXen DMA watchdog control:
1257 * Bit 0 : enabled => R/O: 1 watchdog active, 0 inactive
1258 * Bit 1 : disable_request => 1 req disable dma watchdog
1259 * Bit 2 : enable_request => 1 req enable dma watchdog
1262 void netxen_free_dummy_dma(struct netxen_adapter
*adapter
)
1267 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1270 if (!adapter
->dummy_dma
.addr
)
1273 ctrl
= NXRD32(adapter
, NETXEN_DMA_WATCHDOG_CTRL
);
1274 if ((ctrl
& 0x1) != 0) {
1275 NXWR32(adapter
, NETXEN_DMA_WATCHDOG_CTRL
, (ctrl
| 0x2));
1277 while ((ctrl
& 0x1) != 0) {
1281 ctrl
= NXRD32(adapter
, NETXEN_DMA_WATCHDOG_CTRL
);
1289 pci_free_consistent(adapter
->pdev
,
1290 NETXEN_HOST_DUMMY_DMA_SIZE
,
1291 adapter
->dummy_dma
.addr
,
1292 adapter
->dummy_dma
.phys_addr
);
1293 adapter
->dummy_dma
.addr
= NULL
;
1295 dev_err(&adapter
->pdev
->dev
, "dma_watchdog_shutdown failed\n");
1298 int netxen_phantom_init(struct netxen_adapter
*adapter
, int pegtune_val
)
1307 val
= NXRD32(adapter
, CRB_CMDPEG_STATE
);
1310 case PHAN_INITIALIZE_COMPLETE
:
1311 case PHAN_INITIALIZE_ACK
:
1313 case PHAN_INITIALIZE_FAILED
:
1321 } while (--retries
);
1323 NXWR32(adapter
, CRB_CMDPEG_STATE
, PHAN_INITIALIZE_FAILED
);
1326 dev_warn(&adapter
->pdev
->dev
, "firmware init failed\n");
1331 netxen_receive_peg_ready(struct netxen_adapter
*adapter
)
1337 val
= NXRD32(adapter
, CRB_RCVPEG_STATE
);
1339 if (val
== PHAN_PEG_RCV_INITIALIZED
)
1344 } while (--retries
);
1347 printk(KERN_ERR
"Receive Peg initialization not "
1348 "complete, state: 0x%x.\n", val
);
1355 int netxen_init_firmware(struct netxen_adapter
*adapter
)
1359 err
= netxen_receive_peg_ready(adapter
);
1363 NXWR32(adapter
, CRB_NIC_CAPABILITIES_HOST
, INTR_SCHEME_PERPORT
);
1364 NXWR32(adapter
, CRB_MPORT_MODE
, MPORT_MULTI_FUNCTION_MODE
);
1365 NXWR32(adapter
, CRB_CMDPEG_STATE
, PHAN_INITIALIZE_ACK
);
1367 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1368 NXWR32(adapter
, CRB_NIC_MSI_MODE_HOST
, MSI_MODE_MULTIFUNC
);
1374 netxen_handle_linkevent(struct netxen_adapter
*adapter
, nx_fw_msg_t
*msg
)
1379 u8 link_status
, module
, duplex
, autoneg
;
1380 struct net_device
*netdev
= adapter
->netdev
;
1382 adapter
->has_link_events
= 1;
1384 cable_OUI
= msg
->body
[1] & 0xffffffff;
1385 cable_len
= (msg
->body
[1] >> 32) & 0xffff;
1386 link_speed
= (msg
->body
[1] >> 48) & 0xffff;
1388 link_status
= msg
->body
[2] & 0xff;
1389 duplex
= (msg
->body
[2] >> 16) & 0xff;
1390 autoneg
= (msg
->body
[2] >> 24) & 0xff;
1392 module
= (msg
->body
[2] >> 8) & 0xff;
1393 if (module
== LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE
) {
1394 printk(KERN_INFO
"%s: unsupported cable: OUI 0x%x, length %d\n",
1395 netdev
->name
, cable_OUI
, cable_len
);
1396 } else if (module
== LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN
) {
1397 printk(KERN_INFO
"%s: unsupported cable length %d\n",
1398 netdev
->name
, cable_len
);
1401 netxen_advert_link_change(adapter
, link_status
);
1403 /* update link parameters */
1404 if (duplex
== LINKEVENT_FULL_DUPLEX
)
1405 adapter
->link_duplex
= DUPLEX_FULL
;
1407 adapter
->link_duplex
= DUPLEX_HALF
;
1408 adapter
->module_type
= module
;
1409 adapter
->link_autoneg
= autoneg
;
1410 adapter
->link_speed
= link_speed
;
1414 netxen_handle_fw_message(int desc_cnt
, int index
,
1415 struct nx_host_sds_ring
*sds_ring
)
1418 struct status_desc
*desc
;
1421 while (desc_cnt
> 0 && i
< 8) {
1422 desc
= &sds_ring
->desc_head
[index
];
1423 msg
.words
[i
++] = le64_to_cpu(desc
->status_desc_data
[0]);
1424 msg
.words
[i
++] = le64_to_cpu(desc
->status_desc_data
[1]);
1426 index
= get_next_index(index
, sds_ring
->num_desc
);
1430 opcode
= netxen_get_nic_msg_opcode(msg
.body
[0]);
1432 case NX_NIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE
:
1433 netxen_handle_linkevent(sds_ring
->adapter
, &msg
);
1441 netxen_alloc_rx_skb(struct netxen_adapter
*adapter
,
1442 struct nx_host_rds_ring
*rds_ring
,
1443 struct netxen_rx_buffer
*buffer
)
1445 struct sk_buff
*skb
;
1447 struct pci_dev
*pdev
= adapter
->pdev
;
1449 buffer
->skb
= dev_alloc_skb(rds_ring
->skb_size
);
1455 if (!adapter
->ahw
.cut_through
)
1456 skb_reserve(skb
, 2);
1458 dma
= pci_map_single(pdev
, skb
->data
,
1459 rds_ring
->dma_size
, PCI_DMA_FROMDEVICE
);
1461 if (pci_dma_mapping_error(pdev
, dma
)) {
1462 dev_kfree_skb_any(skb
);
1469 buffer
->state
= NETXEN_BUFFER_BUSY
;
1474 static struct sk_buff
*netxen_process_rxbuf(struct netxen_adapter
*adapter
,
1475 struct nx_host_rds_ring
*rds_ring
, u16 index
, u16 cksum
)
1477 struct netxen_rx_buffer
*buffer
;
1478 struct sk_buff
*skb
;
1480 buffer
= &rds_ring
->rx_buf_arr
[index
];
1482 pci_unmap_single(adapter
->pdev
, buffer
->dma
, rds_ring
->dma_size
,
1483 PCI_DMA_FROMDEVICE
);
1489 if (likely(adapter
->rx_csum
&& cksum
== STATUS_CKSUM_OK
)) {
1490 adapter
->stats
.csummed
++;
1491 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1493 skb
->ip_summed
= CHECKSUM_NONE
;
1495 skb
->dev
= adapter
->netdev
;
1499 buffer
->state
= NETXEN_BUFFER_FREE
;
1503 static struct netxen_rx_buffer
*
1504 netxen_process_rcv(struct netxen_adapter
*adapter
,
1505 struct nx_host_sds_ring
*sds_ring
,
1506 int ring
, u64 sts_data0
)
1508 struct net_device
*netdev
= adapter
->netdev
;
1509 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1510 struct netxen_rx_buffer
*buffer
;
1511 struct sk_buff
*skb
;
1512 struct nx_host_rds_ring
*rds_ring
;
1513 int index
, length
, cksum
, pkt_offset
;
1515 if (unlikely(ring
>= adapter
->max_rds_rings
))
1518 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1520 index
= netxen_get_sts_refhandle(sts_data0
);
1521 if (unlikely(index
>= rds_ring
->num_desc
))
1524 buffer
= &rds_ring
->rx_buf_arr
[index
];
1526 length
= netxen_get_sts_totallength(sts_data0
);
1527 cksum
= netxen_get_sts_status(sts_data0
);
1528 pkt_offset
= netxen_get_sts_pkt_offset(sts_data0
);
1530 skb
= netxen_process_rxbuf(adapter
, rds_ring
, index
, cksum
);
1534 if (length
> rds_ring
->skb_size
)
1535 skb_put(skb
, rds_ring
->skb_size
);
1537 skb_put(skb
, length
);
1541 skb_pull(skb
, pkt_offset
);
1543 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
);
1544 skb
->protocol
= eth_type_trans(skb
, netdev
);
1546 napi_gro_receive(&sds_ring
->napi
, skb
);
1548 adapter
->stats
.rx_pkts
++;
1549 adapter
->stats
.rxbytes
+= length
;
1554 #define TCP_HDR_SIZE 20
1555 #define TCP_TS_OPTION_SIZE 12
1556 #define TCP_TS_HDR_SIZE (TCP_HDR_SIZE + TCP_TS_OPTION_SIZE)
1558 static struct netxen_rx_buffer
*
1559 netxen_process_lro(struct netxen_adapter
*adapter
,
1560 struct nx_host_sds_ring
*sds_ring
,
1561 int ring
, u64 sts_data0
, u64 sts_data1
)
1563 struct net_device
*netdev
= adapter
->netdev
;
1564 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1565 struct netxen_rx_buffer
*buffer
;
1566 struct sk_buff
*skb
;
1567 struct nx_host_rds_ring
*rds_ring
;
1570 bool push
, timestamp
;
1571 int l2_hdr_offset
, l4_hdr_offset
;
1573 u16 lro_length
, length
, data_offset
;
1576 if (unlikely(ring
> adapter
->max_rds_rings
))
1579 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1581 index
= netxen_get_lro_sts_refhandle(sts_data0
);
1582 if (unlikely(index
> rds_ring
->num_desc
))
1585 buffer
= &rds_ring
->rx_buf_arr
[index
];
1587 timestamp
= netxen_get_lro_sts_timestamp(sts_data0
);
1588 lro_length
= netxen_get_lro_sts_length(sts_data0
);
1589 l2_hdr_offset
= netxen_get_lro_sts_l2_hdr_offset(sts_data0
);
1590 l4_hdr_offset
= netxen_get_lro_sts_l4_hdr_offset(sts_data0
);
1591 push
= netxen_get_lro_sts_push_flag(sts_data0
);
1592 seq_number
= netxen_get_lro_sts_seq_number(sts_data1
);
1594 skb
= netxen_process_rxbuf(adapter
, rds_ring
, index
, STATUS_CKSUM_OK
);
1599 data_offset
= l4_hdr_offset
+ TCP_TS_HDR_SIZE
;
1601 data_offset
= l4_hdr_offset
+ TCP_HDR_SIZE
;
1603 skb_put(skb
, lro_length
+ data_offset
);
1605 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
) + skb_headroom(skb
);
1607 skb_pull(skb
, l2_hdr_offset
);
1608 skb
->protocol
= eth_type_trans(skb
, netdev
);
1610 iph
= (struct iphdr
*)skb
->data
;
1611 th
= (struct tcphdr
*)(skb
->data
+ (iph
->ihl
<< 2));
1613 length
= (iph
->ihl
<< 2) + (th
->doff
<< 2) + lro_length
;
1614 iph
->tot_len
= htons(length
);
1616 iph
->check
= ip_fast_csum((unsigned char *)iph
, iph
->ihl
);
1618 th
->seq
= htonl(seq_number
);
1622 netif_receive_skb(skb
);
1624 adapter
->stats
.lro_pkts
++;
1625 adapter
->stats
.rxbytes
+= length
;
1630 #define netxen_merge_rx_buffers(list, head) \
1631 do { list_splice_tail_init(list, head); } while (0);
1634 netxen_process_rcv_ring(struct nx_host_sds_ring
*sds_ring
, int max
)
1636 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
1638 struct list_head
*cur
;
1640 struct status_desc
*desc
;
1641 struct netxen_rx_buffer
*rxbuf
;
1643 u32 consumer
= sds_ring
->consumer
;
1646 u64 sts_data0
, sts_data1
;
1647 int opcode
, ring
= 0, desc_cnt
;
1649 while (count
< max
) {
1650 desc
= &sds_ring
->desc_head
[consumer
];
1651 sts_data0
= le64_to_cpu(desc
->status_desc_data
[0]);
1653 if (!(sts_data0
& STATUS_OWNER_HOST
))
1656 desc_cnt
= netxen_get_sts_desc_cnt(sts_data0
);
1658 opcode
= netxen_get_sts_opcode(sts_data0
);
1661 case NETXEN_NIC_RXPKT_DESC
:
1662 case NETXEN_OLD_RXPKT_DESC
:
1663 case NETXEN_NIC_SYN_OFFLOAD
:
1664 ring
= netxen_get_sts_type(sts_data0
);
1665 rxbuf
= netxen_process_rcv(adapter
, sds_ring
,
1668 case NETXEN_NIC_LRO_DESC
:
1669 ring
= netxen_get_lro_sts_type(sts_data0
);
1670 sts_data1
= le64_to_cpu(desc
->status_desc_data
[1]);
1671 rxbuf
= netxen_process_lro(adapter
, sds_ring
,
1672 ring
, sts_data0
, sts_data1
);
1674 case NETXEN_NIC_RESPONSE_DESC
:
1675 netxen_handle_fw_message(desc_cnt
, consumer
, sds_ring
);
1680 WARN_ON(desc_cnt
> 1);
1683 list_add_tail(&rxbuf
->list
, &sds_ring
->free_list
[ring
]);
1686 for (; desc_cnt
> 0; desc_cnt
--) {
1687 desc
= &sds_ring
->desc_head
[consumer
];
1688 desc
->status_desc_data
[0] =
1689 cpu_to_le64(STATUS_OWNER_PHANTOM
);
1690 consumer
= get_next_index(consumer
, sds_ring
->num_desc
);
1695 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1696 struct nx_host_rds_ring
*rds_ring
=
1697 &adapter
->recv_ctx
.rds_rings
[ring
];
1699 if (!list_empty(&sds_ring
->free_list
[ring
])) {
1700 list_for_each(cur
, &sds_ring
->free_list
[ring
]) {
1701 rxbuf
= list_entry(cur
,
1702 struct netxen_rx_buffer
, list
);
1703 netxen_alloc_rx_skb(adapter
, rds_ring
, rxbuf
);
1705 spin_lock(&rds_ring
->lock
);
1706 netxen_merge_rx_buffers(&sds_ring
->free_list
[ring
],
1707 &rds_ring
->free_list
);
1708 spin_unlock(&rds_ring
->lock
);
1711 netxen_post_rx_buffers_nodb(adapter
, rds_ring
);
1715 sds_ring
->consumer
= consumer
;
1716 NXWRIO(adapter
, sds_ring
->crb_sts_consumer
, consumer
);
1722 /* Process Command status ring */
1723 int netxen_process_cmd_ring(struct netxen_adapter
*adapter
)
1725 u32 sw_consumer
, hw_consumer
;
1727 struct netxen_cmd_buffer
*buffer
;
1728 struct pci_dev
*pdev
= adapter
->pdev
;
1729 struct net_device
*netdev
= adapter
->netdev
;
1730 struct netxen_skb_frag
*frag
;
1732 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1734 if (!spin_trylock(&adapter
->tx_clean_lock
))
1737 sw_consumer
= tx_ring
->sw_consumer
;
1738 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
1740 while (sw_consumer
!= hw_consumer
) {
1741 buffer
= &tx_ring
->cmd_buf_arr
[sw_consumer
];
1743 frag
= &buffer
->frag_array
[0];
1744 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
1747 for (i
= 1; i
< buffer
->frag_count
; i
++) {
1748 frag
++; /* Get the next frag */
1749 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
1754 adapter
->stats
.xmitfinished
++;
1755 dev_kfree_skb_any(buffer
->skb
);
1759 sw_consumer
= get_next_index(sw_consumer
, tx_ring
->num_desc
);
1760 if (++count
>= MAX_STATUS_HANDLE
)
1764 if (count
&& netif_running(netdev
)) {
1765 tx_ring
->sw_consumer
= sw_consumer
;
1769 if (netif_queue_stopped(netdev
) && netif_carrier_ok(netdev
)) {
1770 __netif_tx_lock(tx_ring
->txq
, smp_processor_id());
1771 if (netxen_tx_avail(tx_ring
) > TX_STOP_THRESH
) {
1772 netif_wake_queue(netdev
);
1773 adapter
->tx_timeo_cnt
= 0;
1775 __netif_tx_unlock(tx_ring
->txq
);
1779 * If everything is freed up to consumer then check if the ring is full
1780 * If the ring is full then check if more needs to be freed and
1781 * schedule the call back again.
1783 * This happens when there are 2 CPUs. One could be freeing and the
1784 * other filling it. If the ring is full when we get out of here and
1785 * the card has already interrupted the host then the host can miss the
1788 * There is still a possible race condition and the host could miss an
1789 * interrupt. The card has to take care of this.
1791 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
1792 done
= (sw_consumer
== hw_consumer
);
1793 spin_unlock(&adapter
->tx_clean_lock
);
1799 netxen_post_rx_buffers(struct netxen_adapter
*adapter
, u32 ringid
,
1800 struct nx_host_rds_ring
*rds_ring
)
1802 struct rcv_desc
*pdesc
;
1803 struct netxen_rx_buffer
*buffer
;
1804 int producer
, count
= 0;
1805 netxen_ctx_msg msg
= 0;
1806 struct list_head
*head
;
1808 producer
= rds_ring
->producer
;
1810 head
= &rds_ring
->free_list
;
1811 while (!list_empty(head
)) {
1813 buffer
= list_entry(head
->next
, struct netxen_rx_buffer
, list
);
1816 if (netxen_alloc_rx_skb(adapter
, rds_ring
, buffer
))
1821 list_del(&buffer
->list
);
1823 /* make a rcv descriptor */
1824 pdesc
= &rds_ring
->desc_head
[producer
];
1825 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1826 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1827 pdesc
->buffer_length
= cpu_to_le32(rds_ring
->dma_size
);
1829 producer
= get_next_index(producer
, rds_ring
->num_desc
);
1833 rds_ring
->producer
= producer
;
1834 NXWRIO(adapter
, rds_ring
->crb_rcv_producer
,
1835 (producer
-1) & (rds_ring
->num_desc
-1));
1837 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1839 * Write a doorbell msg to tell phanmon of change in
1840 * receive ring producer
1841 * Only for firmware version < 4.0.0
1843 netxen_set_msg_peg_id(msg
, NETXEN_RCV_PEG_DB_ID
);
1844 netxen_set_msg_privid(msg
);
1845 netxen_set_msg_count(msg
,
1847 (rds_ring
->num_desc
- 1)));
1848 netxen_set_msg_ctxid(msg
, adapter
->portnum
);
1849 netxen_set_msg_opcode(msg
, NETXEN_RCV_PRODUCER(ringid
));
1850 NXWRIO(adapter
, DB_NORMALIZE(adapter
,
1851 NETXEN_RCV_PRODUCER_OFFSET
), msg
);
1857 netxen_post_rx_buffers_nodb(struct netxen_adapter
*adapter
,
1858 struct nx_host_rds_ring
*rds_ring
)
1860 struct rcv_desc
*pdesc
;
1861 struct netxen_rx_buffer
*buffer
;
1862 int producer
, count
= 0;
1863 struct list_head
*head
;
1865 if (!spin_trylock(&rds_ring
->lock
))
1868 producer
= rds_ring
->producer
;
1870 head
= &rds_ring
->free_list
;
1871 while (!list_empty(head
)) {
1873 buffer
= list_entry(head
->next
, struct netxen_rx_buffer
, list
);
1876 if (netxen_alloc_rx_skb(adapter
, rds_ring
, buffer
))
1881 list_del(&buffer
->list
);
1883 /* make a rcv descriptor */
1884 pdesc
= &rds_ring
->desc_head
[producer
];
1885 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1886 pdesc
->buffer_length
= cpu_to_le32(rds_ring
->dma_size
);
1887 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1889 producer
= get_next_index(producer
, rds_ring
->num_desc
);
1893 rds_ring
->producer
= producer
;
1894 NXWRIO(adapter
, rds_ring
->crb_rcv_producer
,
1895 (producer
- 1) & (rds_ring
->num_desc
- 1));
1897 spin_unlock(&rds_ring
->lock
);
1900 void netxen_nic_clear_stats(struct netxen_adapter
*adapter
)
1902 memset(&adapter
->stats
, 0, sizeof(adapter
->stats
));