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 "netxen_nic.h"
29 #include "netxen_nic_hw.h"
31 struct crb_addr_pair
{
36 #define NETXEN_MAX_CRB_XFORM 60
37 static unsigned int crb_addr_xform
[NETXEN_MAX_CRB_XFORM
];
38 #define NETXEN_ADDR_ERROR (0xffffffff)
40 #define crb_addr_transform(name) \
41 crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \
42 NETXEN_HW_CRB_HUB_AGT_ADR_##name << 20
44 #define NETXEN_NIC_XDMA_RESET 0x8000ff
47 netxen_post_rx_buffers_nodb(struct netxen_adapter
*adapter
,
48 struct nx_host_rds_ring
*rds_ring
);
49 static int netxen_p3_has_mn(struct netxen_adapter
*adapter
);
51 static void crb_addr_transform_setup(void)
53 crb_addr_transform(XDMA
);
54 crb_addr_transform(TIMR
);
55 crb_addr_transform(SRE
);
56 crb_addr_transform(SQN3
);
57 crb_addr_transform(SQN2
);
58 crb_addr_transform(SQN1
);
59 crb_addr_transform(SQN0
);
60 crb_addr_transform(SQS3
);
61 crb_addr_transform(SQS2
);
62 crb_addr_transform(SQS1
);
63 crb_addr_transform(SQS0
);
64 crb_addr_transform(RPMX7
);
65 crb_addr_transform(RPMX6
);
66 crb_addr_transform(RPMX5
);
67 crb_addr_transform(RPMX4
);
68 crb_addr_transform(RPMX3
);
69 crb_addr_transform(RPMX2
);
70 crb_addr_transform(RPMX1
);
71 crb_addr_transform(RPMX0
);
72 crb_addr_transform(ROMUSB
);
73 crb_addr_transform(SN
);
74 crb_addr_transform(QMN
);
75 crb_addr_transform(QMS
);
76 crb_addr_transform(PGNI
);
77 crb_addr_transform(PGND
);
78 crb_addr_transform(PGN3
);
79 crb_addr_transform(PGN2
);
80 crb_addr_transform(PGN1
);
81 crb_addr_transform(PGN0
);
82 crb_addr_transform(PGSI
);
83 crb_addr_transform(PGSD
);
84 crb_addr_transform(PGS3
);
85 crb_addr_transform(PGS2
);
86 crb_addr_transform(PGS1
);
87 crb_addr_transform(PGS0
);
88 crb_addr_transform(PS
);
89 crb_addr_transform(PH
);
90 crb_addr_transform(NIU
);
91 crb_addr_transform(I2Q
);
92 crb_addr_transform(EG
);
93 crb_addr_transform(MN
);
94 crb_addr_transform(MS
);
95 crb_addr_transform(CAS2
);
96 crb_addr_transform(CAS1
);
97 crb_addr_transform(CAS0
);
98 crb_addr_transform(CAM
);
99 crb_addr_transform(C2C1
);
100 crb_addr_transform(C2C0
);
101 crb_addr_transform(SMB
);
102 crb_addr_transform(OCM0
);
103 crb_addr_transform(I2C0
);
106 void netxen_release_rx_buffers(struct netxen_adapter
*adapter
)
108 struct netxen_recv_context
*recv_ctx
;
109 struct nx_host_rds_ring
*rds_ring
;
110 struct netxen_rx_buffer
*rx_buf
;
113 recv_ctx
= &adapter
->recv_ctx
;
114 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
115 rds_ring
= &recv_ctx
->rds_rings
[ring
];
116 for (i
= 0; i
< rds_ring
->num_desc
; ++i
) {
117 rx_buf
= &(rds_ring
->rx_buf_arr
[i
]);
118 if (rx_buf
->state
== NETXEN_BUFFER_FREE
)
120 pci_unmap_single(adapter
->pdev
,
124 if (rx_buf
->skb
!= NULL
)
125 dev_kfree_skb_any(rx_buf
->skb
);
130 void netxen_release_tx_buffers(struct netxen_adapter
*adapter
)
132 struct netxen_cmd_buffer
*cmd_buf
;
133 struct netxen_skb_frag
*buffrag
;
135 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
137 cmd_buf
= tx_ring
->cmd_buf_arr
;
138 for (i
= 0; i
< tx_ring
->num_desc
; i
++) {
139 buffrag
= cmd_buf
->frag_array
;
141 pci_unmap_single(adapter
->pdev
, buffrag
->dma
,
142 buffrag
->length
, PCI_DMA_TODEVICE
);
145 for (j
= 0; j
< cmd_buf
->frag_count
; j
++) {
148 pci_unmap_page(adapter
->pdev
, buffrag
->dma
,
155 dev_kfree_skb_any(cmd_buf
->skb
);
162 void netxen_free_sw_resources(struct netxen_adapter
*adapter
)
164 struct netxen_recv_context
*recv_ctx
;
165 struct nx_host_rds_ring
*rds_ring
;
166 struct nx_host_tx_ring
*tx_ring
;
169 recv_ctx
= &adapter
->recv_ctx
;
171 if (recv_ctx
->rds_rings
== NULL
)
174 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
175 rds_ring
= &recv_ctx
->rds_rings
[ring
];
176 vfree(rds_ring
->rx_buf_arr
);
177 rds_ring
->rx_buf_arr
= NULL
;
179 kfree(recv_ctx
->rds_rings
);
182 if (adapter
->tx_ring
== NULL
)
185 tx_ring
= adapter
->tx_ring
;
186 vfree(tx_ring
->cmd_buf_arr
);
188 adapter
->tx_ring
= NULL
;
191 int netxen_alloc_sw_resources(struct netxen_adapter
*adapter
)
193 struct netxen_recv_context
*recv_ctx
;
194 struct nx_host_rds_ring
*rds_ring
;
195 struct nx_host_sds_ring
*sds_ring
;
196 struct nx_host_tx_ring
*tx_ring
;
197 struct netxen_rx_buffer
*rx_buf
;
200 struct netxen_cmd_buffer
*cmd_buf_arr
;
201 struct net_device
*netdev
= adapter
->netdev
;
202 struct pci_dev
*pdev
= adapter
->pdev
;
204 size
= sizeof(struct nx_host_tx_ring
);
205 tx_ring
= kzalloc(size
, GFP_KERNEL
);
206 if (tx_ring
== NULL
) {
207 dev_err(&pdev
->dev
, "%s: failed to allocate tx ring struct\n",
211 adapter
->tx_ring
= tx_ring
;
213 tx_ring
->num_desc
= adapter
->num_txd
;
214 tx_ring
->txq
= netdev_get_tx_queue(netdev
, 0);
216 cmd_buf_arr
= vmalloc(TX_BUFF_RINGSIZE(tx_ring
));
217 if (cmd_buf_arr
== NULL
) {
218 dev_err(&pdev
->dev
, "%s: failed to allocate cmd buffer ring\n",
222 memset(cmd_buf_arr
, 0, TX_BUFF_RINGSIZE(tx_ring
));
223 tx_ring
->cmd_buf_arr
= cmd_buf_arr
;
225 recv_ctx
= &adapter
->recv_ctx
;
227 size
= adapter
->max_rds_rings
* sizeof (struct nx_host_rds_ring
);
228 rds_ring
= kzalloc(size
, GFP_KERNEL
);
229 if (rds_ring
== NULL
) {
230 dev_err(&pdev
->dev
, "%s: failed to allocate rds ring struct\n",
234 recv_ctx
->rds_rings
= rds_ring
;
236 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
237 rds_ring
= &recv_ctx
->rds_rings
[ring
];
239 case RCV_RING_NORMAL
:
240 rds_ring
->num_desc
= adapter
->num_rxd
;
241 if (adapter
->ahw
.cut_through
) {
243 NX_CT_DEFAULT_RX_BUF_LEN
;
245 NX_CT_DEFAULT_RX_BUF_LEN
;
247 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
249 NX_P3_RX_BUF_MAX_LEN
;
252 NX_P2_RX_BUF_MAX_LEN
;
254 rds_ring
->dma_size
+ NET_IP_ALIGN
;
259 rds_ring
->num_desc
= adapter
->num_jumbo_rxd
;
260 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
262 NX_P3_RX_JUMBO_BUF_MAX_LEN
;
265 NX_P2_RX_JUMBO_BUF_MAX_LEN
;
267 if (adapter
->capabilities
& NX_CAP0_HW_LRO
)
268 rds_ring
->dma_size
+= NX_LRO_BUFFER_EXTRA
;
271 rds_ring
->dma_size
+ NET_IP_ALIGN
;
275 rds_ring
->num_desc
= adapter
->num_lro_rxd
;
276 rds_ring
->dma_size
= NX_RX_LRO_BUFFER_LENGTH
;
277 rds_ring
->skb_size
= rds_ring
->dma_size
+ NET_IP_ALIGN
;
281 rds_ring
->rx_buf_arr
= (struct netxen_rx_buffer
*)
282 vmalloc(RCV_BUFF_RINGSIZE(rds_ring
));
283 if (rds_ring
->rx_buf_arr
== NULL
) {
284 printk(KERN_ERR
"%s: Failed to allocate "
285 "rx buffer ring %d\n",
287 /* free whatever was already allocated */
290 memset(rds_ring
->rx_buf_arr
, 0, RCV_BUFF_RINGSIZE(rds_ring
));
291 INIT_LIST_HEAD(&rds_ring
->free_list
);
293 * Now go through all of them, set reference handles
294 * and put them in the queues.
296 rx_buf
= rds_ring
->rx_buf_arr
;
297 for (i
= 0; i
< rds_ring
->num_desc
; i
++) {
298 list_add_tail(&rx_buf
->list
,
299 &rds_ring
->free_list
);
300 rx_buf
->ref_handle
= i
;
301 rx_buf
->state
= NETXEN_BUFFER_FREE
;
304 spin_lock_init(&rds_ring
->lock
);
307 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
308 sds_ring
= &recv_ctx
->sds_rings
[ring
];
309 sds_ring
->irq
= adapter
->msix_entries
[ring
].vector
;
310 sds_ring
->adapter
= adapter
;
311 sds_ring
->num_desc
= adapter
->num_rxd
;
313 for (i
= 0; i
< NUM_RCV_DESC_RINGS
; i
++)
314 INIT_LIST_HEAD(&sds_ring
->free_list
[i
]);
320 netxen_free_sw_resources(adapter
);
325 * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB
326 * address to external PCI CRB address.
328 static u32
netxen_decode_crb_addr(u32 addr
)
331 u32 base_addr
, offset
, pci_base
;
333 crb_addr_transform_setup();
335 pci_base
= NETXEN_ADDR_ERROR
;
336 base_addr
= addr
& 0xfff00000;
337 offset
= addr
& 0x000fffff;
339 for (i
= 0; i
< NETXEN_MAX_CRB_XFORM
; i
++) {
340 if (crb_addr_xform
[i
] == base_addr
) {
345 if (pci_base
== NETXEN_ADDR_ERROR
)
348 return (pci_base
+ offset
);
351 #define NETXEN_MAX_ROM_WAIT_USEC 100
353 static int netxen_wait_rom_done(struct netxen_adapter
*adapter
)
361 done
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_STATUS
);
363 if (++timeout
>= NETXEN_MAX_ROM_WAIT_USEC
) {
364 dev_err(&adapter
->pdev
->dev
,
365 "Timeout reached waiting for rom done");
373 static int do_rom_fast_read(struct netxen_adapter
*adapter
,
376 NXWR32(adapter
, NETXEN_ROMUSB_ROM_ADDRESS
, addr
);
377 NXWR32(adapter
, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
378 NXWR32(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 3);
379 NXWR32(adapter
, NETXEN_ROMUSB_ROM_INSTR_OPCODE
, 0xb);
380 if (netxen_wait_rom_done(adapter
)) {
381 printk("Error waiting for rom done\n");
384 /* reset abyte_cnt and dummy_byte_cnt */
385 NXWR32(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 0);
387 NXWR32(adapter
, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
389 *valp
= NXRD32(adapter
, NETXEN_ROMUSB_ROM_RDATA
);
393 static int do_rom_fast_read_words(struct netxen_adapter
*adapter
, int addr
,
394 u8
*bytes
, size_t size
)
399 for (addridx
= addr
; addridx
< (addr
+ size
); addridx
+= 4) {
401 ret
= do_rom_fast_read(adapter
, addridx
, &v
);
404 *(__le32
*)bytes
= cpu_to_le32(v
);
412 netxen_rom_fast_read_words(struct netxen_adapter
*adapter
, int addr
,
413 u8
*bytes
, size_t size
)
417 ret
= netxen_rom_lock(adapter
);
421 ret
= do_rom_fast_read_words(adapter
, addr
, bytes
, size
);
423 netxen_rom_unlock(adapter
);
427 int netxen_rom_fast_read(struct netxen_adapter
*adapter
, int addr
, int *valp
)
431 if (netxen_rom_lock(adapter
) != 0)
434 ret
= do_rom_fast_read(adapter
, addr
, valp
);
435 netxen_rom_unlock(adapter
);
439 #define NETXEN_BOARDTYPE 0x4008
440 #define NETXEN_BOARDNUM 0x400c
441 #define NETXEN_CHIPNUM 0x4010
443 int netxen_pinit_from_rom(struct netxen_adapter
*adapter
)
446 int i
, n
, init_delay
= 0;
447 struct crb_addr_pair
*buf
;
452 netxen_rom_lock(adapter
);
453 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, 0xffffffff);
454 netxen_rom_unlock(adapter
);
456 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
457 if (netxen_rom_fast_read(adapter
, 0, &n
) != 0 ||
459 netxen_rom_fast_read(adapter
, 4, &n
) != 0) {
460 printk(KERN_ERR
"%s: ERROR Reading crb_init area: "
461 "n: %08x\n", netxen_nic_driver_name
, n
);
464 offset
= n
& 0xffffU
;
465 n
= (n
>> 16) & 0xffffU
;
467 if (netxen_rom_fast_read(adapter
, 0, &n
) != 0 ||
469 printk(KERN_ERR
"%s: ERROR Reading crb_init area: "
470 "n: %08x\n", netxen_nic_driver_name
, n
);
478 printk(KERN_ERR
"%s:n=0x%x Error! NetXen card flash not"
479 " initialized.\n", __func__
, n
);
483 buf
= kcalloc(n
, sizeof(struct crb_addr_pair
), GFP_KERNEL
);
485 printk("%s: netxen_pinit_from_rom: Unable to calloc memory.\n",
486 netxen_nic_driver_name
);
490 for (i
= 0; i
< n
; i
++) {
491 if (netxen_rom_fast_read(adapter
, 8*i
+ 4*offset
, &val
) != 0 ||
492 netxen_rom_fast_read(adapter
, 8*i
+ 4*offset
+ 4, &addr
) != 0) {
502 for (i
= 0; i
< n
; i
++) {
504 off
= netxen_decode_crb_addr(buf
[i
].addr
);
505 if (off
== NETXEN_ADDR_ERROR
) {
506 printk(KERN_ERR
"CRB init value out of range %x\n",
510 off
+= NETXEN_PCI_CRBSPACE
;
515 /* skipping cold reboot MAGIC */
516 if (off
== NETXEN_CAM_RAM(0x1fc))
519 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
520 if (off
== (NETXEN_CRB_I2C0
+ 0x1c))
522 /* do not reset PCI */
523 if (off
== (ROMUSB_GLB
+ 0xbc))
525 if (off
== (ROMUSB_GLB
+ 0xa8))
527 if (off
== (ROMUSB_GLB
+ 0xc8)) /* core clock */
529 if (off
== (ROMUSB_GLB
+ 0x24)) /* MN clock */
531 if (off
== (ROMUSB_GLB
+ 0x1c)) /* MS clock */
533 if ((off
& 0x0ff00000) == NETXEN_CRB_DDR_NET
)
535 if (off
== (NETXEN_CRB_PEG_NET_1
+ 0x18) &&
536 !NX_IS_REVISION_P3P(adapter
->ahw
.revision_id
))
537 buf
[i
].data
= 0x1020;
538 /* skip the function enable register */
539 if (off
== NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION
))
541 if (off
== NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION2
))
543 if ((off
& 0x0ff00000) == NETXEN_CRB_SMB
)
548 /* After writing this register, HW needs time for CRB */
549 /* to quiet down (else crb_window returns 0xffffffff) */
550 if (off
== NETXEN_ROMUSB_GLB_SW_RESET
) {
552 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
553 /* hold xdma in reset also */
554 buf
[i
].data
= NETXEN_NIC_XDMA_RESET
;
555 buf
[i
].data
= 0x8000ff;
559 NXWR32(adapter
, off
, buf
[i
].data
);
565 /* disable_peg_cache_all */
567 /* unreset_net_cache */
568 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
569 val
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
);
570 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, (val
& 0xffffff0f));
573 /* p2dn replyCount */
574 NXWR32(adapter
, NETXEN_CRB_PEG_NET_D
+ 0xec, 0x1e);
575 /* disable_peg_cache 0 */
576 NXWR32(adapter
, NETXEN_CRB_PEG_NET_D
+ 0x4c, 8);
577 /* disable_peg_cache 1 */
578 NXWR32(adapter
, NETXEN_CRB_PEG_NET_I
+ 0x4c, 8);
583 NXWR32(adapter
, NETXEN_CRB_PEG_NET_0
+ 0x8, 0);
584 NXWR32(adapter
, NETXEN_CRB_PEG_NET_0
+ 0xc, 0);
586 NXWR32(adapter
, NETXEN_CRB_PEG_NET_1
+ 0x8, 0);
587 NXWR32(adapter
, NETXEN_CRB_PEG_NET_1
+ 0xc, 0);
589 NXWR32(adapter
, NETXEN_CRB_PEG_NET_2
+ 0x8, 0);
590 NXWR32(adapter
, NETXEN_CRB_PEG_NET_2
+ 0xc, 0);
592 NXWR32(adapter
, NETXEN_CRB_PEG_NET_3
+ 0x8, 0);
593 NXWR32(adapter
, NETXEN_CRB_PEG_NET_3
+ 0xc, 0);
597 static struct uni_table_desc
*nx_get_table_desc(const u8
*unirom
, int section
)
600 struct uni_table_desc
*directory
= (struct uni_table_desc
*) &unirom
[0];
601 __le32 entries
= cpu_to_le32(directory
->num_entries
);
603 for (i
= 0; i
< entries
; i
++) {
605 __le32 offs
= cpu_to_le32(directory
->findex
) +
606 (i
* cpu_to_le32(directory
->entry_size
));
607 __le32 tab_type
= cpu_to_le32(*((u32
*)&unirom
[offs
] + 8));
609 if (tab_type
== section
)
610 return (struct uni_table_desc
*) &unirom
[offs
];
617 nx_set_product_offs(struct netxen_adapter
*adapter
)
619 struct uni_table_desc
*ptab_descr
;
620 const u8
*unirom
= adapter
->fw
->data
;
624 int mn_present
= (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) ?
625 1 : netxen_p3_has_mn(adapter
);
627 ptab_descr
= nx_get_table_desc(unirom
, NX_UNI_DIR_SECT_PRODUCT_TBL
);
628 if (ptab_descr
== NULL
)
631 entries
= cpu_to_le32(ptab_descr
->num_entries
);
634 for (i
= 0; i
< entries
; i
++) {
636 __le32 flags
, file_chiprev
, offs
;
637 u8 chiprev
= adapter
->ahw
.revision_id
;
640 offs
= cpu_to_le32(ptab_descr
->findex
) +
641 (i
* cpu_to_le32(ptab_descr
->entry_size
));
642 flags
= cpu_to_le32(*((int *)&unirom
[offs
] + NX_UNI_FLAGS_OFF
));
643 file_chiprev
= cpu_to_le32(*((int *)&unirom
[offs
] +
644 NX_UNI_CHIP_REV_OFF
));
646 flagbit
= mn_present
? 1 : 2;
648 if ((chiprev
== file_chiprev
) &&
649 ((1ULL << flagbit
) & flags
)) {
650 adapter
->file_prd_off
= offs
;
655 if (mn_present
&& NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
664 static struct uni_data_desc
*nx_get_data_desc(struct netxen_adapter
*adapter
,
665 u32 section
, u32 idx_offset
)
667 const u8
*unirom
= adapter
->fw
->data
;
668 int idx
= cpu_to_le32(*((int *)&unirom
[adapter
->file_prd_off
] +
670 struct uni_table_desc
*tab_desc
;
673 tab_desc
= nx_get_table_desc(unirom
, section
);
675 if (tab_desc
== NULL
)
678 offs
= cpu_to_le32(tab_desc
->findex
) +
679 (cpu_to_le32(tab_desc
->entry_size
) * idx
);
681 return (struct uni_data_desc
*)&unirom
[offs
];
685 nx_get_bootld_offs(struct netxen_adapter
*adapter
)
687 u32 offs
= NETXEN_BOOTLD_START
;
689 if (adapter
->fw_type
== NX_UNIFIED_ROMIMAGE
)
690 offs
= cpu_to_le32((nx_get_data_desc(adapter
,
691 NX_UNI_DIR_SECT_BOOTLD
,
692 NX_UNI_BOOTLD_IDX_OFF
))->findex
);
694 return (u8
*)&adapter
->fw
->data
[offs
];
698 nx_get_fw_offs(struct netxen_adapter
*adapter
)
700 u32 offs
= NETXEN_IMAGE_START
;
702 if (adapter
->fw_type
== NX_UNIFIED_ROMIMAGE
)
703 offs
= cpu_to_le32((nx_get_data_desc(adapter
,
705 NX_UNI_FIRMWARE_IDX_OFF
))->findex
);
707 return (u8
*)&adapter
->fw
->data
[offs
];
711 nx_get_fw_size(struct netxen_adapter
*adapter
)
713 if (adapter
->fw_type
== NX_UNIFIED_ROMIMAGE
)
714 return cpu_to_le32((nx_get_data_desc(adapter
,
716 NX_UNI_FIRMWARE_IDX_OFF
))->size
);
719 *(u32
*)&adapter
->fw
->data
[NX_FW_SIZE_OFFSET
]);
723 nx_get_fw_version(struct netxen_adapter
*adapter
)
725 struct uni_data_desc
*fw_data_desc
;
726 const struct firmware
*fw
= adapter
->fw
;
727 __le32 major
, minor
, sub
;
731 if (adapter
->fw_type
== NX_UNIFIED_ROMIMAGE
) {
733 fw_data_desc
= nx_get_data_desc(adapter
,
734 NX_UNI_DIR_SECT_FW
, NX_UNI_FIRMWARE_IDX_OFF
);
735 ver_str
= fw
->data
+ cpu_to_le32(fw_data_desc
->findex
) +
736 cpu_to_le32(fw_data_desc
->size
) - 17;
738 for (i
= 0; i
< 12; i
++) {
739 if (!strncmp(&ver_str
[i
], "REV=", 4)) {
740 ret
= sscanf(&ver_str
[i
+4], "%u.%u.%u ",
741 &major
, &minor
, &sub
);
749 return major
+ (minor
<< 8) + (sub
<< 16);
752 return cpu_to_le32(*(u32
*)&fw
->data
[NX_FW_VERSION_OFFSET
]);
756 nx_get_bios_version(struct netxen_adapter
*adapter
)
758 const struct firmware
*fw
= adapter
->fw
;
759 __le32 bios_ver
, prd_off
= adapter
->file_prd_off
;
761 if (adapter
->fw_type
== NX_UNIFIED_ROMIMAGE
) {
762 bios_ver
= cpu_to_le32(*((u32
*) (&fw
->data
[prd_off
])
763 + NX_UNI_BIOS_VERSION_OFF
));
764 return (bios_ver
<< 16) + ((bios_ver
>> 8) & 0xff00) +
767 return cpu_to_le32(*(u32
*)&fw
->data
[NX_BIOS_VERSION_OFFSET
]);
772 netxen_need_fw_reset(struct netxen_adapter
*adapter
)
774 u32 count
, old_count
;
775 u32 val
, version
, major
, minor
, build
;
779 /* NX2031 firmware doesn't support heartbit */
780 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
783 if (adapter
->need_fw_reset
)
786 /* last attempt had failed */
787 if (NXRD32(adapter
, CRB_CMDPEG_STATE
) == PHAN_INITIALIZE_FAILED
)
790 old_count
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
792 for (i
= 0; i
< 10; i
++) {
794 timeout
= msleep_interruptible(200);
796 NXWR32(adapter
, CRB_CMDPEG_STATE
,
797 PHAN_INITIALIZE_FAILED
);
801 count
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
802 if (count
!= old_count
)
806 /* firmware is dead */
807 if (count
== old_count
)
810 /* check if we have got newer or different file firmware */
813 val
= nx_get_fw_version(adapter
);
815 version
= NETXEN_DECODE_VERSION(val
);
817 major
= NXRD32(adapter
, NETXEN_FW_VERSION_MAJOR
);
818 minor
= NXRD32(adapter
, NETXEN_FW_VERSION_MINOR
);
819 build
= NXRD32(adapter
, NETXEN_FW_VERSION_SUB
);
821 if (version
> NETXEN_VERSION_CODE(major
, minor
, build
))
824 if (version
== NETXEN_VERSION_CODE(major
, minor
, build
) &&
825 adapter
->fw_type
!= NX_UNIFIED_ROMIMAGE
) {
827 val
= NXRD32(adapter
, NETXEN_MIU_MN_CONTROL
);
828 fw_type
= (val
& 0x4) ?
829 NX_P3_CT_ROMIMAGE
: NX_P3_MN_ROMIMAGE
;
831 if (adapter
->fw_type
!= fw_type
)
839 static char *fw_name
[] = {
840 NX_P2_MN_ROMIMAGE_NAME
,
841 NX_P3_CT_ROMIMAGE_NAME
,
842 NX_P3_MN_ROMIMAGE_NAME
,
843 NX_UNIFIED_ROMIMAGE_NAME
,
844 NX_FLASH_ROMIMAGE_NAME
,
848 netxen_load_firmware(struct netxen_adapter
*adapter
)
851 u32 i
, flashaddr
, size
;
852 const struct firmware
*fw
= adapter
->fw
;
853 struct pci_dev
*pdev
= adapter
->pdev
;
855 dev_info(&pdev
->dev
, "loading firmware from %s\n",
856 fw_name
[adapter
->fw_type
]);
858 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
859 NXWR32(adapter
, NETXEN_ROMUSB_GLB_CAS_RST
, 1);
864 size
= (NETXEN_IMAGE_START
- NETXEN_BOOTLD_START
) / 8;
866 ptr64
= (u64
*)nx_get_bootld_offs(adapter
);
867 flashaddr
= NETXEN_BOOTLD_START
;
869 for (i
= 0; i
< size
; i
++) {
870 data
= cpu_to_le64(ptr64
[i
]);
872 if (adapter
->pci_mem_write(adapter
, flashaddr
, data
))
878 size
= (__force u32
)nx_get_fw_size(adapter
) / 8;
880 ptr64
= (u64
*)nx_get_fw_offs(adapter
);
881 flashaddr
= NETXEN_IMAGE_START
;
883 for (i
= 0; i
< size
; i
++) {
884 data
= cpu_to_le64(ptr64
[i
]);
886 if (adapter
->pci_mem_write(adapter
,
896 size
= (NETXEN_IMAGE_START
- NETXEN_BOOTLD_START
) / 8;
897 flashaddr
= NETXEN_BOOTLD_START
;
899 for (i
= 0; i
< size
; i
++) {
900 if (netxen_rom_fast_read(adapter
,
901 flashaddr
, (int *)&lo
) != 0)
903 if (netxen_rom_fast_read(adapter
,
904 flashaddr
+ 4, (int *)&hi
) != 0)
907 /* hi, lo are already in host endian byteorder */
908 data
= (((u64
)hi
<< 32) | lo
);
910 if (adapter
->pci_mem_write(adapter
,
919 if (NX_IS_REVISION_P3P(adapter
->ahw
.revision_id
)) {
920 NXWR32(adapter
, NETXEN_CRB_PEG_NET_0
+ 0x18, 0x1020);
921 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, 0x80001e);
922 } else if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
923 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, 0x80001d);
925 NXWR32(adapter
, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL
, 0x3fff);
926 NXWR32(adapter
, NETXEN_ROMUSB_GLB_CAS_RST
, 0);
933 netxen_validate_firmware(struct netxen_adapter
*adapter
)
936 u32 ver
, min_ver
, bios
, min_size
;
937 struct pci_dev
*pdev
= adapter
->pdev
;
938 const struct firmware
*fw
= adapter
->fw
;
939 u8 fw_type
= adapter
->fw_type
;
941 if (fw_type
== NX_UNIFIED_ROMIMAGE
) {
942 if (nx_set_product_offs(adapter
))
945 min_size
= NX_UNI_FW_MIN_SIZE
;
947 val
= cpu_to_le32(*(u32
*)&fw
->data
[NX_FW_MAGIC_OFFSET
]);
948 if ((__force u32
)val
!= NETXEN_BDINFO_MAGIC
)
951 min_size
= NX_FW_MIN_SIZE
;
954 if (fw
->size
< min_size
)
957 val
= nx_get_fw_version(adapter
);
959 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
960 min_ver
= NETXEN_VERSION_CODE(4, 0, 216);
962 min_ver
= NETXEN_VERSION_CODE(3, 4, 216);
964 ver
= NETXEN_DECODE_VERSION(val
);
966 if ((_major(ver
) > _NETXEN_NIC_LINUX_MAJOR
) || (ver
< min_ver
)) {
968 "%s: firmware version %d.%d.%d unsupported\n",
969 fw_name
[fw_type
], _major(ver
), _minor(ver
), _build(ver
));
973 val
= nx_get_bios_version(adapter
);
974 netxen_rom_fast_read(adapter
, NX_BIOS_VERSION_OFFSET
, (int *)&bios
);
975 if ((__force u32
)val
!= bios
) {
976 dev_err(&pdev
->dev
, "%s: firmware bios is incompatible\n",
981 /* check if flashed firmware is newer */
982 if (netxen_rom_fast_read(adapter
,
983 NX_FW_VERSION_OFFSET
, (int *)&val
))
985 val
= NETXEN_DECODE_VERSION(val
);
987 dev_info(&pdev
->dev
, "%s: firmware is older than flash\n",
992 NXWR32(adapter
, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC
);
997 nx_get_next_fwtype(struct netxen_adapter
*adapter
)
1001 switch (adapter
->fw_type
) {
1002 case NX_UNKNOWN_ROMIMAGE
:
1003 fw_type
= NX_UNIFIED_ROMIMAGE
;
1006 case NX_UNIFIED_ROMIMAGE
:
1007 if (NX_IS_REVISION_P3P(adapter
->ahw
.revision_id
))
1008 fw_type
= NX_FLASH_ROMIMAGE
;
1009 else if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1010 fw_type
= NX_P2_MN_ROMIMAGE
;
1011 else if (netxen_p3_has_mn(adapter
))
1012 fw_type
= NX_P3_MN_ROMIMAGE
;
1014 fw_type
= NX_P3_CT_ROMIMAGE
;
1017 case NX_P3_MN_ROMIMAGE
:
1018 fw_type
= NX_P3_CT_ROMIMAGE
;
1021 case NX_P2_MN_ROMIMAGE
:
1022 case NX_P3_CT_ROMIMAGE
:
1024 fw_type
= NX_FLASH_ROMIMAGE
;
1028 adapter
->fw_type
= fw_type
;
1032 netxen_p3_has_mn(struct netxen_adapter
*adapter
)
1034 u32 capability
, flashed_ver
;
1037 /* NX2031 always had MN */
1038 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1041 netxen_rom_fast_read(adapter
,
1042 NX_FW_VERSION_OFFSET
, (int *)&flashed_ver
);
1043 flashed_ver
= NETXEN_DECODE_VERSION(flashed_ver
);
1045 if (flashed_ver
>= NETXEN_VERSION_CODE(4, 0, 220)) {
1047 capability
= NXRD32(adapter
, NX_PEG_TUNE_CAPABILITY
);
1048 if (capability
& NX_PEG_TUNE_MN_PRESENT
)
1054 void netxen_request_firmware(struct netxen_adapter
*adapter
)
1056 struct pci_dev
*pdev
= adapter
->pdev
;
1059 adapter
->fw_type
= NX_UNKNOWN_ROMIMAGE
;
1062 nx_get_next_fwtype(adapter
);
1064 if (adapter
->fw_type
== NX_FLASH_ROMIMAGE
) {
1067 rc
= request_firmware(&adapter
->fw
,
1068 fw_name
[adapter
->fw_type
], &pdev
->dev
);
1072 rc
= netxen_validate_firmware(adapter
);
1074 release_firmware(adapter
->fw
);
1083 netxen_release_firmware(struct netxen_adapter
*adapter
)
1086 release_firmware(adapter
->fw
);
1090 int netxen_init_dummy_dma(struct netxen_adapter
*adapter
)
1095 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1098 adapter
->dummy_dma
.addr
= pci_alloc_consistent(adapter
->pdev
,
1099 NETXEN_HOST_DUMMY_DMA_SIZE
,
1100 &adapter
->dummy_dma
.phys_addr
);
1101 if (adapter
->dummy_dma
.addr
== NULL
) {
1102 dev_err(&adapter
->pdev
->dev
,
1103 "ERROR: Could not allocate dummy DMA memory\n");
1107 addr
= (uint64_t) adapter
->dummy_dma
.phys_addr
;
1108 hi
= (addr
>> 32) & 0xffffffff;
1109 lo
= addr
& 0xffffffff;
1111 NXWR32(adapter
, CRB_HOST_DUMMY_BUF_ADDR_HI
, hi
);
1112 NXWR32(adapter
, CRB_HOST_DUMMY_BUF_ADDR_LO
, lo
);
1118 * NetXen DMA watchdog control:
1120 * Bit 0 : enabled => R/O: 1 watchdog active, 0 inactive
1121 * Bit 1 : disable_request => 1 req disable dma watchdog
1122 * Bit 2 : enable_request => 1 req enable dma watchdog
1125 void netxen_free_dummy_dma(struct netxen_adapter
*adapter
)
1130 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1133 if (!adapter
->dummy_dma
.addr
)
1136 ctrl
= NXRD32(adapter
, NETXEN_DMA_WATCHDOG_CTRL
);
1137 if ((ctrl
& 0x1) != 0) {
1138 NXWR32(adapter
, NETXEN_DMA_WATCHDOG_CTRL
, (ctrl
| 0x2));
1140 while ((ctrl
& 0x1) != 0) {
1144 ctrl
= NXRD32(adapter
, NETXEN_DMA_WATCHDOG_CTRL
);
1152 pci_free_consistent(adapter
->pdev
,
1153 NETXEN_HOST_DUMMY_DMA_SIZE
,
1154 adapter
->dummy_dma
.addr
,
1155 adapter
->dummy_dma
.phys_addr
);
1156 adapter
->dummy_dma
.addr
= NULL
;
1158 dev_err(&adapter
->pdev
->dev
, "dma_watchdog_shutdown failed\n");
1161 int netxen_phantom_init(struct netxen_adapter
*adapter
, int pegtune_val
)
1170 val
= NXRD32(adapter
, CRB_CMDPEG_STATE
);
1173 case PHAN_INITIALIZE_COMPLETE
:
1174 case PHAN_INITIALIZE_ACK
:
1176 case PHAN_INITIALIZE_FAILED
:
1184 } while (--retries
);
1186 NXWR32(adapter
, CRB_CMDPEG_STATE
, PHAN_INITIALIZE_FAILED
);
1189 dev_warn(&adapter
->pdev
->dev
, "firmware init failed\n");
1194 netxen_receive_peg_ready(struct netxen_adapter
*adapter
)
1200 val
= NXRD32(adapter
, CRB_RCVPEG_STATE
);
1202 if (val
== PHAN_PEG_RCV_INITIALIZED
)
1207 } while (--retries
);
1210 printk(KERN_ERR
"Receive Peg initialization not "
1211 "complete, state: 0x%x.\n", val
);
1218 int netxen_init_firmware(struct netxen_adapter
*adapter
)
1222 err
= netxen_receive_peg_ready(adapter
);
1226 NXWR32(adapter
, CRB_NIC_CAPABILITIES_HOST
, INTR_SCHEME_PERPORT
);
1227 NXWR32(adapter
, CRB_NIC_MSI_MODE_HOST
, MSI_MODE_MULTIFUNC
);
1228 NXWR32(adapter
, CRB_MPORT_MODE
, MPORT_MULTI_FUNCTION_MODE
);
1229 NXWR32(adapter
, CRB_CMDPEG_STATE
, PHAN_INITIALIZE_ACK
);
1235 netxen_handle_linkevent(struct netxen_adapter
*adapter
, nx_fw_msg_t
*msg
)
1240 u8 link_status
, module
, duplex
, autoneg
;
1241 struct net_device
*netdev
= adapter
->netdev
;
1243 adapter
->has_link_events
= 1;
1245 cable_OUI
= msg
->body
[1] & 0xffffffff;
1246 cable_len
= (msg
->body
[1] >> 32) & 0xffff;
1247 link_speed
= (msg
->body
[1] >> 48) & 0xffff;
1249 link_status
= msg
->body
[2] & 0xff;
1250 duplex
= (msg
->body
[2] >> 16) & 0xff;
1251 autoneg
= (msg
->body
[2] >> 24) & 0xff;
1253 module
= (msg
->body
[2] >> 8) & 0xff;
1254 if (module
== LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE
) {
1255 printk(KERN_INFO
"%s: unsupported cable: OUI 0x%x, length %d\n",
1256 netdev
->name
, cable_OUI
, cable_len
);
1257 } else if (module
== LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN
) {
1258 printk(KERN_INFO
"%s: unsupported cable length %d\n",
1259 netdev
->name
, cable_len
);
1262 netxen_advert_link_change(adapter
, link_status
);
1264 /* update link parameters */
1265 if (duplex
== LINKEVENT_FULL_DUPLEX
)
1266 adapter
->link_duplex
= DUPLEX_FULL
;
1268 adapter
->link_duplex
= DUPLEX_HALF
;
1269 adapter
->module_type
= module
;
1270 adapter
->link_autoneg
= autoneg
;
1271 adapter
->link_speed
= link_speed
;
1275 netxen_handle_fw_message(int desc_cnt
, int index
,
1276 struct nx_host_sds_ring
*sds_ring
)
1279 struct status_desc
*desc
;
1282 while (desc_cnt
> 0 && i
< 8) {
1283 desc
= &sds_ring
->desc_head
[index
];
1284 msg
.words
[i
++] = le64_to_cpu(desc
->status_desc_data
[0]);
1285 msg
.words
[i
++] = le64_to_cpu(desc
->status_desc_data
[1]);
1287 index
= get_next_index(index
, sds_ring
->num_desc
);
1291 opcode
= netxen_get_nic_msg_opcode(msg
.body
[0]);
1293 case NX_NIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE
:
1294 netxen_handle_linkevent(sds_ring
->adapter
, &msg
);
1302 netxen_alloc_rx_skb(struct netxen_adapter
*adapter
,
1303 struct nx_host_rds_ring
*rds_ring
,
1304 struct netxen_rx_buffer
*buffer
)
1306 struct sk_buff
*skb
;
1308 struct pci_dev
*pdev
= adapter
->pdev
;
1310 buffer
->skb
= dev_alloc_skb(rds_ring
->skb_size
);
1316 if (!adapter
->ahw
.cut_through
)
1317 skb_reserve(skb
, 2);
1319 dma
= pci_map_single(pdev
, skb
->data
,
1320 rds_ring
->dma_size
, PCI_DMA_FROMDEVICE
);
1322 if (pci_dma_mapping_error(pdev
, dma
)) {
1323 dev_kfree_skb_any(skb
);
1330 buffer
->state
= NETXEN_BUFFER_BUSY
;
1335 static struct sk_buff
*netxen_process_rxbuf(struct netxen_adapter
*adapter
,
1336 struct nx_host_rds_ring
*rds_ring
, u16 index
, u16 cksum
)
1338 struct netxen_rx_buffer
*buffer
;
1339 struct sk_buff
*skb
;
1341 buffer
= &rds_ring
->rx_buf_arr
[index
];
1343 pci_unmap_single(adapter
->pdev
, buffer
->dma
, rds_ring
->dma_size
,
1344 PCI_DMA_FROMDEVICE
);
1350 if (likely(adapter
->rx_csum
&& cksum
== STATUS_CKSUM_OK
)) {
1351 adapter
->stats
.csummed
++;
1352 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1354 skb
->ip_summed
= CHECKSUM_NONE
;
1356 skb
->dev
= adapter
->netdev
;
1360 buffer
->state
= NETXEN_BUFFER_FREE
;
1364 static struct netxen_rx_buffer
*
1365 netxen_process_rcv(struct netxen_adapter
*adapter
,
1366 struct nx_host_sds_ring
*sds_ring
,
1367 int ring
, u64 sts_data0
)
1369 struct net_device
*netdev
= adapter
->netdev
;
1370 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1371 struct netxen_rx_buffer
*buffer
;
1372 struct sk_buff
*skb
;
1373 struct nx_host_rds_ring
*rds_ring
;
1374 int index
, length
, cksum
, pkt_offset
;
1376 if (unlikely(ring
>= adapter
->max_rds_rings
))
1379 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1381 index
= netxen_get_sts_refhandle(sts_data0
);
1382 if (unlikely(index
>= rds_ring
->num_desc
))
1385 buffer
= &rds_ring
->rx_buf_arr
[index
];
1387 length
= netxen_get_sts_totallength(sts_data0
);
1388 cksum
= netxen_get_sts_status(sts_data0
);
1389 pkt_offset
= netxen_get_sts_pkt_offset(sts_data0
);
1391 skb
= netxen_process_rxbuf(adapter
, rds_ring
, index
, cksum
);
1395 if (length
> rds_ring
->skb_size
)
1396 skb_put(skb
, rds_ring
->skb_size
);
1398 skb_put(skb
, length
);
1402 skb_pull(skb
, pkt_offset
);
1404 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
);
1405 skb
->protocol
= eth_type_trans(skb
, netdev
);
1407 napi_gro_receive(&sds_ring
->napi
, skb
);
1409 adapter
->stats
.rx_pkts
++;
1410 adapter
->stats
.rxbytes
+= length
;
1415 #define TCP_HDR_SIZE 20
1416 #define TCP_TS_OPTION_SIZE 12
1417 #define TCP_TS_HDR_SIZE (TCP_HDR_SIZE + TCP_TS_OPTION_SIZE)
1419 static struct netxen_rx_buffer
*
1420 netxen_process_lro(struct netxen_adapter
*adapter
,
1421 struct nx_host_sds_ring
*sds_ring
,
1422 int ring
, u64 sts_data0
, u64 sts_data1
)
1424 struct net_device
*netdev
= adapter
->netdev
;
1425 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1426 struct netxen_rx_buffer
*buffer
;
1427 struct sk_buff
*skb
;
1428 struct nx_host_rds_ring
*rds_ring
;
1431 bool push
, timestamp
;
1432 int l2_hdr_offset
, l4_hdr_offset
;
1434 u16 lro_length
, length
, data_offset
;
1437 if (unlikely(ring
> adapter
->max_rds_rings
))
1440 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1442 index
= netxen_get_lro_sts_refhandle(sts_data0
);
1443 if (unlikely(index
> rds_ring
->num_desc
))
1446 buffer
= &rds_ring
->rx_buf_arr
[index
];
1448 timestamp
= netxen_get_lro_sts_timestamp(sts_data0
);
1449 lro_length
= netxen_get_lro_sts_length(sts_data0
);
1450 l2_hdr_offset
= netxen_get_lro_sts_l2_hdr_offset(sts_data0
);
1451 l4_hdr_offset
= netxen_get_lro_sts_l4_hdr_offset(sts_data0
);
1452 push
= netxen_get_lro_sts_push_flag(sts_data0
);
1453 seq_number
= netxen_get_lro_sts_seq_number(sts_data1
);
1455 skb
= netxen_process_rxbuf(adapter
, rds_ring
, index
, STATUS_CKSUM_OK
);
1460 data_offset
= l4_hdr_offset
+ TCP_TS_HDR_SIZE
;
1462 data_offset
= l4_hdr_offset
+ TCP_HDR_SIZE
;
1464 skb_put(skb
, lro_length
+ data_offset
);
1466 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
) + skb_headroom(skb
);
1468 skb_pull(skb
, l2_hdr_offset
);
1469 skb
->protocol
= eth_type_trans(skb
, netdev
);
1471 iph
= (struct iphdr
*)skb
->data
;
1472 th
= (struct tcphdr
*)(skb
->data
+ (iph
->ihl
<< 2));
1474 length
= (iph
->ihl
<< 2) + (th
->doff
<< 2) + lro_length
;
1475 iph
->tot_len
= htons(length
);
1477 iph
->check
= ip_fast_csum((unsigned char *)iph
, iph
->ihl
);
1479 th
->seq
= htonl(seq_number
);
1483 netif_receive_skb(skb
);
1485 adapter
->stats
.lro_pkts
++;
1486 adapter
->stats
.rxbytes
+= length
;
1491 #define netxen_merge_rx_buffers(list, head) \
1492 do { list_splice_tail_init(list, head); } while (0);
1495 netxen_process_rcv_ring(struct nx_host_sds_ring
*sds_ring
, int max
)
1497 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
1499 struct list_head
*cur
;
1501 struct status_desc
*desc
;
1502 struct netxen_rx_buffer
*rxbuf
;
1504 u32 consumer
= sds_ring
->consumer
;
1507 u64 sts_data0
, sts_data1
;
1508 int opcode
, ring
= 0, desc_cnt
;
1510 while (count
< max
) {
1511 desc
= &sds_ring
->desc_head
[consumer
];
1512 sts_data0
= le64_to_cpu(desc
->status_desc_data
[0]);
1514 if (!(sts_data0
& STATUS_OWNER_HOST
))
1517 desc_cnt
= netxen_get_sts_desc_cnt(sts_data0
);
1519 opcode
= netxen_get_sts_opcode(sts_data0
);
1522 case NETXEN_NIC_RXPKT_DESC
:
1523 case NETXEN_OLD_RXPKT_DESC
:
1524 case NETXEN_NIC_SYN_OFFLOAD
:
1525 ring
= netxen_get_sts_type(sts_data0
);
1526 rxbuf
= netxen_process_rcv(adapter
, sds_ring
,
1529 case NETXEN_NIC_LRO_DESC
:
1530 ring
= netxen_get_lro_sts_type(sts_data0
);
1531 sts_data1
= le64_to_cpu(desc
->status_desc_data
[1]);
1532 rxbuf
= netxen_process_lro(adapter
, sds_ring
,
1533 ring
, sts_data0
, sts_data1
);
1535 case NETXEN_NIC_RESPONSE_DESC
:
1536 netxen_handle_fw_message(desc_cnt
, consumer
, sds_ring
);
1541 WARN_ON(desc_cnt
> 1);
1544 list_add_tail(&rxbuf
->list
, &sds_ring
->free_list
[ring
]);
1547 for (; desc_cnt
> 0; desc_cnt
--) {
1548 desc
= &sds_ring
->desc_head
[consumer
];
1549 desc
->status_desc_data
[0] =
1550 cpu_to_le64(STATUS_OWNER_PHANTOM
);
1551 consumer
= get_next_index(consumer
, sds_ring
->num_desc
);
1556 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1557 struct nx_host_rds_ring
*rds_ring
=
1558 &adapter
->recv_ctx
.rds_rings
[ring
];
1560 if (!list_empty(&sds_ring
->free_list
[ring
])) {
1561 list_for_each(cur
, &sds_ring
->free_list
[ring
]) {
1562 rxbuf
= list_entry(cur
,
1563 struct netxen_rx_buffer
, list
);
1564 netxen_alloc_rx_skb(adapter
, rds_ring
, rxbuf
);
1566 spin_lock(&rds_ring
->lock
);
1567 netxen_merge_rx_buffers(&sds_ring
->free_list
[ring
],
1568 &rds_ring
->free_list
);
1569 spin_unlock(&rds_ring
->lock
);
1572 netxen_post_rx_buffers_nodb(adapter
, rds_ring
);
1576 sds_ring
->consumer
= consumer
;
1577 NXWRIO(adapter
, sds_ring
->crb_sts_consumer
, consumer
);
1583 /* Process Command status ring */
1584 int netxen_process_cmd_ring(struct netxen_adapter
*adapter
)
1586 u32 sw_consumer
, hw_consumer
;
1588 struct netxen_cmd_buffer
*buffer
;
1589 struct pci_dev
*pdev
= adapter
->pdev
;
1590 struct net_device
*netdev
= adapter
->netdev
;
1591 struct netxen_skb_frag
*frag
;
1593 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1595 if (!spin_trylock(&adapter
->tx_clean_lock
))
1598 sw_consumer
= tx_ring
->sw_consumer
;
1599 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
1601 while (sw_consumer
!= hw_consumer
) {
1602 buffer
= &tx_ring
->cmd_buf_arr
[sw_consumer
];
1604 frag
= &buffer
->frag_array
[0];
1605 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
1608 for (i
= 1; i
< buffer
->frag_count
; i
++) {
1609 frag
++; /* Get the next frag */
1610 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
1615 adapter
->stats
.xmitfinished
++;
1616 dev_kfree_skb_any(buffer
->skb
);
1620 sw_consumer
= get_next_index(sw_consumer
, tx_ring
->num_desc
);
1621 if (++count
>= MAX_STATUS_HANDLE
)
1625 if (count
&& netif_running(netdev
)) {
1626 tx_ring
->sw_consumer
= sw_consumer
;
1630 if (netif_queue_stopped(netdev
) && netif_carrier_ok(netdev
)) {
1631 __netif_tx_lock(tx_ring
->txq
, smp_processor_id());
1632 if (netxen_tx_avail(tx_ring
) > TX_STOP_THRESH
) {
1633 netif_wake_queue(netdev
);
1634 adapter
->tx_timeo_cnt
= 0;
1636 __netif_tx_unlock(tx_ring
->txq
);
1640 * If everything is freed up to consumer then check if the ring is full
1641 * If the ring is full then check if more needs to be freed and
1642 * schedule the call back again.
1644 * This happens when there are 2 CPUs. One could be freeing and the
1645 * other filling it. If the ring is full when we get out of here and
1646 * the card has already interrupted the host then the host can miss the
1649 * There is still a possible race condition and the host could miss an
1650 * interrupt. The card has to take care of this.
1652 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
1653 done
= (sw_consumer
== hw_consumer
);
1654 spin_unlock(&adapter
->tx_clean_lock
);
1660 netxen_post_rx_buffers(struct netxen_adapter
*adapter
, u32 ringid
,
1661 struct nx_host_rds_ring
*rds_ring
)
1663 struct rcv_desc
*pdesc
;
1664 struct netxen_rx_buffer
*buffer
;
1665 int producer
, count
= 0;
1666 netxen_ctx_msg msg
= 0;
1667 struct list_head
*head
;
1669 producer
= rds_ring
->producer
;
1671 spin_lock(&rds_ring
->lock
);
1672 head
= &rds_ring
->free_list
;
1673 while (!list_empty(head
)) {
1675 buffer
= list_entry(head
->next
, struct netxen_rx_buffer
, list
);
1678 if (netxen_alloc_rx_skb(adapter
, rds_ring
, buffer
))
1683 list_del(&buffer
->list
);
1685 /* make a rcv descriptor */
1686 pdesc
= &rds_ring
->desc_head
[producer
];
1687 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1688 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1689 pdesc
->buffer_length
= cpu_to_le32(rds_ring
->dma_size
);
1691 producer
= get_next_index(producer
, rds_ring
->num_desc
);
1693 spin_unlock(&rds_ring
->lock
);
1696 rds_ring
->producer
= producer
;
1697 NXWRIO(adapter
, rds_ring
->crb_rcv_producer
,
1698 (producer
-1) & (rds_ring
->num_desc
-1));
1700 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1702 * Write a doorbell msg to tell phanmon of change in
1703 * receive ring producer
1704 * Only for firmware version < 4.0.0
1706 netxen_set_msg_peg_id(msg
, NETXEN_RCV_PEG_DB_ID
);
1707 netxen_set_msg_privid(msg
);
1708 netxen_set_msg_count(msg
,
1710 (rds_ring
->num_desc
- 1)));
1711 netxen_set_msg_ctxid(msg
, adapter
->portnum
);
1712 netxen_set_msg_opcode(msg
, NETXEN_RCV_PRODUCER(ringid
));
1713 NXWRIO(adapter
, DB_NORMALIZE(adapter
,
1714 NETXEN_RCV_PRODUCER_OFFSET
), msg
);
1720 netxen_post_rx_buffers_nodb(struct netxen_adapter
*adapter
,
1721 struct nx_host_rds_ring
*rds_ring
)
1723 struct rcv_desc
*pdesc
;
1724 struct netxen_rx_buffer
*buffer
;
1725 int producer
, count
= 0;
1726 struct list_head
*head
;
1728 producer
= rds_ring
->producer
;
1729 if (!spin_trylock(&rds_ring
->lock
))
1732 head
= &rds_ring
->free_list
;
1733 while (!list_empty(head
)) {
1735 buffer
= list_entry(head
->next
, struct netxen_rx_buffer
, list
);
1738 if (netxen_alloc_rx_skb(adapter
, rds_ring
, buffer
))
1743 list_del(&buffer
->list
);
1745 /* make a rcv descriptor */
1746 pdesc
= &rds_ring
->desc_head
[producer
];
1747 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1748 pdesc
->buffer_length
= cpu_to_le32(rds_ring
->dma_size
);
1749 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1751 producer
= get_next_index(producer
, rds_ring
->num_desc
);
1755 rds_ring
->producer
= producer
;
1756 NXWRIO(adapter
, rds_ring
->crb_rcv_producer
,
1757 (producer
- 1) & (rds_ring
->num_desc
- 1));
1759 spin_unlock(&rds_ring
->lock
);
1762 void netxen_nic_clear_stats(struct netxen_adapter
*adapter
)
1764 memset(&adapter
->stats
, 0, sizeof(adapter
->stats
));