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 LICENSE.
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
);
50 static void crb_addr_transform_setup(void)
52 crb_addr_transform(XDMA
);
53 crb_addr_transform(TIMR
);
54 crb_addr_transform(SRE
);
55 crb_addr_transform(SQN3
);
56 crb_addr_transform(SQN2
);
57 crb_addr_transform(SQN1
);
58 crb_addr_transform(SQN0
);
59 crb_addr_transform(SQS3
);
60 crb_addr_transform(SQS2
);
61 crb_addr_transform(SQS1
);
62 crb_addr_transform(SQS0
);
63 crb_addr_transform(RPMX7
);
64 crb_addr_transform(RPMX6
);
65 crb_addr_transform(RPMX5
);
66 crb_addr_transform(RPMX4
);
67 crb_addr_transform(RPMX3
);
68 crb_addr_transform(RPMX2
);
69 crb_addr_transform(RPMX1
);
70 crb_addr_transform(RPMX0
);
71 crb_addr_transform(ROMUSB
);
72 crb_addr_transform(SN
);
73 crb_addr_transform(QMN
);
74 crb_addr_transform(QMS
);
75 crb_addr_transform(PGNI
);
76 crb_addr_transform(PGND
);
77 crb_addr_transform(PGN3
);
78 crb_addr_transform(PGN2
);
79 crb_addr_transform(PGN1
);
80 crb_addr_transform(PGN0
);
81 crb_addr_transform(PGSI
);
82 crb_addr_transform(PGSD
);
83 crb_addr_transform(PGS3
);
84 crb_addr_transform(PGS2
);
85 crb_addr_transform(PGS1
);
86 crb_addr_transform(PGS0
);
87 crb_addr_transform(PS
);
88 crb_addr_transform(PH
);
89 crb_addr_transform(NIU
);
90 crb_addr_transform(I2Q
);
91 crb_addr_transform(EG
);
92 crb_addr_transform(MN
);
93 crb_addr_transform(MS
);
94 crb_addr_transform(CAS2
);
95 crb_addr_transform(CAS1
);
96 crb_addr_transform(CAS0
);
97 crb_addr_transform(CAM
);
98 crb_addr_transform(C2C1
);
99 crb_addr_transform(C2C0
);
100 crb_addr_transform(SMB
);
101 crb_addr_transform(OCM0
);
102 crb_addr_transform(I2C0
);
105 void netxen_release_rx_buffers(struct netxen_adapter
*adapter
)
107 struct netxen_recv_context
*recv_ctx
;
108 struct nx_host_rds_ring
*rds_ring
;
109 struct netxen_rx_buffer
*rx_buf
;
112 recv_ctx
= &adapter
->recv_ctx
;
113 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
114 rds_ring
= &recv_ctx
->rds_rings
[ring
];
115 for (i
= 0; i
< rds_ring
->num_desc
; ++i
) {
116 rx_buf
= &(rds_ring
->rx_buf_arr
[i
]);
117 if (rx_buf
->state
== NETXEN_BUFFER_FREE
)
119 pci_unmap_single(adapter
->pdev
,
123 if (rx_buf
->skb
!= NULL
)
124 dev_kfree_skb_any(rx_buf
->skb
);
129 void netxen_release_tx_buffers(struct netxen_adapter
*adapter
)
131 struct netxen_cmd_buffer
*cmd_buf
;
132 struct netxen_skb_frag
*buffrag
;
134 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
136 cmd_buf
= tx_ring
->cmd_buf_arr
;
137 for (i
= 0; i
< tx_ring
->num_desc
; i
++) {
138 buffrag
= cmd_buf
->frag_array
;
140 pci_unmap_single(adapter
->pdev
, buffrag
->dma
,
141 buffrag
->length
, PCI_DMA_TODEVICE
);
144 for (j
= 0; j
< cmd_buf
->frag_count
; j
++) {
147 pci_unmap_page(adapter
->pdev
, buffrag
->dma
,
154 dev_kfree_skb_any(cmd_buf
->skb
);
161 void netxen_free_sw_resources(struct netxen_adapter
*adapter
)
163 struct netxen_recv_context
*recv_ctx
;
164 struct nx_host_rds_ring
*rds_ring
;
165 struct nx_host_tx_ring
*tx_ring
;
168 recv_ctx
= &adapter
->recv_ctx
;
170 if (recv_ctx
->rds_rings
== NULL
)
173 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
174 rds_ring
= &recv_ctx
->rds_rings
[ring
];
175 vfree(rds_ring
->rx_buf_arr
);
176 rds_ring
->rx_buf_arr
= NULL
;
178 kfree(recv_ctx
->rds_rings
);
181 if (adapter
->tx_ring
== NULL
)
184 tx_ring
= adapter
->tx_ring
;
185 vfree(tx_ring
->cmd_buf_arr
);
188 int netxen_alloc_sw_resources(struct netxen_adapter
*adapter
)
190 struct netxen_recv_context
*recv_ctx
;
191 struct nx_host_rds_ring
*rds_ring
;
192 struct nx_host_sds_ring
*sds_ring
;
193 struct nx_host_tx_ring
*tx_ring
;
194 struct netxen_rx_buffer
*rx_buf
;
197 struct netxen_cmd_buffer
*cmd_buf_arr
;
198 struct net_device
*netdev
= adapter
->netdev
;
199 struct pci_dev
*pdev
= adapter
->pdev
;
201 size
= sizeof(struct nx_host_tx_ring
);
202 tx_ring
= kzalloc(size
, GFP_KERNEL
);
203 if (tx_ring
== NULL
) {
204 dev_err(&pdev
->dev
, "%s: failed to allocate tx ring struct\n",
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
= vmalloc(TX_BUFF_RINGSIZE(tx_ring
));
214 if (cmd_buf_arr
== NULL
) {
215 dev_err(&pdev
->dev
, "%s: failed to allocate cmd buffer ring\n",
219 memset(cmd_buf_arr
, 0, TX_BUFF_RINGSIZE(tx_ring
));
220 tx_ring
->cmd_buf_arr
= cmd_buf_arr
;
222 recv_ctx
= &adapter
->recv_ctx
;
224 size
= adapter
->max_rds_rings
* sizeof (struct nx_host_rds_ring
);
225 rds_ring
= kzalloc(size
, GFP_KERNEL
);
226 if (rds_ring
== NULL
) {
227 dev_err(&pdev
->dev
, "%s: failed to allocate rds ring struct\n",
231 recv_ctx
->rds_rings
= rds_ring
;
233 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
234 rds_ring
= &recv_ctx
->rds_rings
[ring
];
236 case RCV_RING_NORMAL
:
237 rds_ring
->num_desc
= adapter
->num_rxd
;
238 if (adapter
->ahw
.cut_through
) {
240 NX_CT_DEFAULT_RX_BUF_LEN
;
242 NX_CT_DEFAULT_RX_BUF_LEN
;
244 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
246 NX_P3_RX_BUF_MAX_LEN
;
249 NX_P2_RX_BUF_MAX_LEN
;
251 rds_ring
->dma_size
+ NET_IP_ALIGN
;
256 rds_ring
->num_desc
= adapter
->num_jumbo_rxd
;
257 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
259 NX_P3_RX_JUMBO_BUF_MAX_LEN
;
262 NX_P2_RX_JUMBO_BUF_MAX_LEN
;
264 if (adapter
->capabilities
& NX_CAP0_HW_LRO
)
265 rds_ring
->dma_size
+= NX_LRO_BUFFER_EXTRA
;
268 rds_ring
->dma_size
+ NET_IP_ALIGN
;
272 rds_ring
->num_desc
= adapter
->num_lro_rxd
;
273 rds_ring
->dma_size
= NX_RX_LRO_BUFFER_LENGTH
;
274 rds_ring
->skb_size
= rds_ring
->dma_size
+ NET_IP_ALIGN
;
278 rds_ring
->rx_buf_arr
= (struct netxen_rx_buffer
*)
279 vmalloc(RCV_BUFF_RINGSIZE(rds_ring
));
280 if (rds_ring
->rx_buf_arr
== NULL
) {
281 printk(KERN_ERR
"%s: Failed to allocate "
282 "rx buffer ring %d\n",
284 /* free whatever was already allocated */
287 memset(rds_ring
->rx_buf_arr
, 0, RCV_BUFF_RINGSIZE(rds_ring
));
288 INIT_LIST_HEAD(&rds_ring
->free_list
);
290 * Now go through all of them, set reference handles
291 * and put them in the queues.
293 rx_buf
= rds_ring
->rx_buf_arr
;
294 for (i
= 0; i
< rds_ring
->num_desc
; i
++) {
295 list_add_tail(&rx_buf
->list
,
296 &rds_ring
->free_list
);
297 rx_buf
->ref_handle
= i
;
298 rx_buf
->state
= NETXEN_BUFFER_FREE
;
301 spin_lock_init(&rds_ring
->lock
);
304 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
305 sds_ring
= &recv_ctx
->sds_rings
[ring
];
306 sds_ring
->irq
= adapter
->msix_entries
[ring
].vector
;
307 sds_ring
->adapter
= adapter
;
308 sds_ring
->num_desc
= adapter
->num_rxd
;
310 for (i
= 0; i
< NUM_RCV_DESC_RINGS
; i
++)
311 INIT_LIST_HEAD(&sds_ring
->free_list
[i
]);
317 netxen_free_sw_resources(adapter
);
322 * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB
323 * address to external PCI CRB address.
325 static u32
netxen_decode_crb_addr(u32 addr
)
328 u32 base_addr
, offset
, pci_base
;
330 crb_addr_transform_setup();
332 pci_base
= NETXEN_ADDR_ERROR
;
333 base_addr
= addr
& 0xfff00000;
334 offset
= addr
& 0x000fffff;
336 for (i
= 0; i
< NETXEN_MAX_CRB_XFORM
; i
++) {
337 if (crb_addr_xform
[i
] == base_addr
) {
342 if (pci_base
== NETXEN_ADDR_ERROR
)
345 return (pci_base
+ offset
);
348 #define NETXEN_MAX_ROM_WAIT_USEC 100
350 static int netxen_wait_rom_done(struct netxen_adapter
*adapter
)
358 done
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_STATUS
);
360 if (++timeout
>= NETXEN_MAX_ROM_WAIT_USEC
) {
361 dev_err(&adapter
->pdev
->dev
,
362 "Timeout reached waiting for rom done");
370 static int do_rom_fast_read(struct netxen_adapter
*adapter
,
373 NXWR32(adapter
, NETXEN_ROMUSB_ROM_ADDRESS
, addr
);
374 NXWR32(adapter
, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
375 NXWR32(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 3);
376 NXWR32(adapter
, NETXEN_ROMUSB_ROM_INSTR_OPCODE
, 0xb);
377 if (netxen_wait_rom_done(adapter
)) {
378 printk("Error waiting for rom done\n");
381 /* reset abyte_cnt and dummy_byte_cnt */
382 NXWR32(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 0);
384 NXWR32(adapter
, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
386 *valp
= NXRD32(adapter
, NETXEN_ROMUSB_ROM_RDATA
);
390 static int do_rom_fast_read_words(struct netxen_adapter
*adapter
, int addr
,
391 u8
*bytes
, size_t size
)
396 for (addridx
= addr
; addridx
< (addr
+ size
); addridx
+= 4) {
398 ret
= do_rom_fast_read(adapter
, addridx
, &v
);
401 *(__le32
*)bytes
= cpu_to_le32(v
);
409 netxen_rom_fast_read_words(struct netxen_adapter
*adapter
, int addr
,
410 u8
*bytes
, size_t size
)
414 ret
= netxen_rom_lock(adapter
);
418 ret
= do_rom_fast_read_words(adapter
, addr
, bytes
, size
);
420 netxen_rom_unlock(adapter
);
424 int netxen_rom_fast_read(struct netxen_adapter
*adapter
, int addr
, int *valp
)
428 if (netxen_rom_lock(adapter
) != 0)
431 ret
= do_rom_fast_read(adapter
, addr
, valp
);
432 netxen_rom_unlock(adapter
);
436 #define NETXEN_BOARDTYPE 0x4008
437 #define NETXEN_BOARDNUM 0x400c
438 #define NETXEN_CHIPNUM 0x4010
440 int netxen_pinit_from_rom(struct netxen_adapter
*adapter
, int verbose
)
443 int i
, n
, init_delay
= 0;
444 struct crb_addr_pair
*buf
;
449 netxen_rom_lock(adapter
);
450 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, 0xffffffff);
451 netxen_rom_unlock(adapter
);
454 if (netxen_rom_fast_read(adapter
, NETXEN_BOARDTYPE
, &val
) == 0)
455 printk("P2 ROM board type: 0x%08x\n", val
);
457 printk("Could not read board type\n");
458 if (netxen_rom_fast_read(adapter
, NETXEN_BOARDNUM
, &val
) == 0)
459 printk("P2 ROM board num: 0x%08x\n", val
);
461 printk("Could not read board number\n");
462 if (netxen_rom_fast_read(adapter
, NETXEN_CHIPNUM
, &val
) == 0)
463 printk("P2 ROM chip num: 0x%08x\n", val
);
465 printk("Could not read chip number\n");
468 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
469 if (netxen_rom_fast_read(adapter
, 0, &n
) != 0 ||
471 netxen_rom_fast_read(adapter
, 4, &n
) != 0) {
472 printk(KERN_ERR
"%s: ERROR Reading crb_init area: "
473 "n: %08x\n", netxen_nic_driver_name
, n
);
476 offset
= n
& 0xffffU
;
477 n
= (n
>> 16) & 0xffffU
;
479 if (netxen_rom_fast_read(adapter
, 0, &n
) != 0 ||
481 printk(KERN_ERR
"%s: ERROR Reading crb_init area: "
482 "n: %08x\n", netxen_nic_driver_name
, n
);
491 printk(KERN_DEBUG
"%s: %d CRB init values found"
492 " in ROM.\n", netxen_nic_driver_name
, n
);
494 printk(KERN_ERR
"%s:n=0x%x Error! NetXen card flash not"
495 " initialized.\n", __func__
, n
);
499 buf
= kcalloc(n
, sizeof(struct crb_addr_pair
), GFP_KERNEL
);
501 printk("%s: netxen_pinit_from_rom: Unable to calloc memory.\n",
502 netxen_nic_driver_name
);
505 for (i
= 0; i
< n
; i
++) {
506 if (netxen_rom_fast_read(adapter
, 8*i
+ 4*offset
, &val
) != 0 ||
507 netxen_rom_fast_read(adapter
, 8*i
+ 4*offset
+ 4, &addr
) != 0) {
516 printk(KERN_DEBUG
"%s: PCI: 0x%08x == 0x%08x\n",
517 netxen_nic_driver_name
,
518 (u32
)netxen_decode_crb_addr(addr
), val
);
520 for (i
= 0; i
< n
; i
++) {
522 off
= netxen_decode_crb_addr(buf
[i
].addr
);
523 if (off
== NETXEN_ADDR_ERROR
) {
524 printk(KERN_ERR
"CRB init value out of range %x\n",
528 off
+= NETXEN_PCI_CRBSPACE
;
529 /* skipping cold reboot MAGIC */
530 if (off
== NETXEN_CAM_RAM(0x1fc))
533 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
534 /* do not reset PCI */
535 if (off
== (ROMUSB_GLB
+ 0xbc))
537 if (off
== (ROMUSB_GLB
+ 0xa8))
539 if (off
== (ROMUSB_GLB
+ 0xc8)) /* core clock */
541 if (off
== (ROMUSB_GLB
+ 0x24)) /* MN clock */
543 if (off
== (ROMUSB_GLB
+ 0x1c)) /* MS clock */
545 if (off
== (NETXEN_CRB_PEG_NET_1
+ 0x18))
546 buf
[i
].data
= 0x1020;
547 /* skip the function enable register */
548 if (off
== NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION
))
550 if (off
== NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION2
))
552 if ((off
& 0x0ff00000) == NETXEN_CRB_SMB
)
556 if (off
== NETXEN_ADDR_ERROR
) {
557 printk(KERN_ERR
"%s: Err: Unknown addr: 0x%08x\n",
558 netxen_nic_driver_name
, buf
[i
].addr
);
563 /* After writing this register, HW needs time for CRB */
564 /* to quiet down (else crb_window returns 0xffffffff) */
565 if (off
== NETXEN_ROMUSB_GLB_SW_RESET
) {
567 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
568 /* hold xdma in reset also */
569 buf
[i
].data
= NETXEN_NIC_XDMA_RESET
;
570 buf
[i
].data
= 0x8000ff;
574 NXWR32(adapter
, off
, buf
[i
].data
);
580 /* disable_peg_cache_all */
582 /* unreset_net_cache */
583 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
584 val
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
);
585 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, (val
& 0xffffff0f));
588 /* p2dn replyCount */
589 NXWR32(adapter
, NETXEN_CRB_PEG_NET_D
+ 0xec, 0x1e);
590 /* disable_peg_cache 0 */
591 NXWR32(adapter
, NETXEN_CRB_PEG_NET_D
+ 0x4c, 8);
592 /* disable_peg_cache 1 */
593 NXWR32(adapter
, NETXEN_CRB_PEG_NET_I
+ 0x4c, 8);
598 NXWR32(adapter
, NETXEN_CRB_PEG_NET_0
+ 0x8, 0);
599 NXWR32(adapter
, NETXEN_CRB_PEG_NET_0
+ 0xc, 0);
601 NXWR32(adapter
, NETXEN_CRB_PEG_NET_1
+ 0x8, 0);
602 NXWR32(adapter
, NETXEN_CRB_PEG_NET_1
+ 0xc, 0);
604 NXWR32(adapter
, NETXEN_CRB_PEG_NET_2
+ 0x8, 0);
605 NXWR32(adapter
, NETXEN_CRB_PEG_NET_2
+ 0xc, 0);
607 NXWR32(adapter
, NETXEN_CRB_PEG_NET_3
+ 0x8, 0);
608 NXWR32(adapter
, NETXEN_CRB_PEG_NET_3
+ 0xc, 0);
613 netxen_need_fw_reset(struct netxen_adapter
*adapter
)
615 u32 count
, old_count
;
616 u32 val
, version
, major
, minor
, build
;
620 /* NX2031 firmware doesn't support heartbit */
621 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
624 /* last attempt had failed */
625 if (NXRD32(adapter
, CRB_CMDPEG_STATE
) == PHAN_INITIALIZE_FAILED
)
628 old_count
= count
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
630 for (i
= 0; i
< 10; i
++) {
632 timeout
= msleep_interruptible(200);
634 NXWR32(adapter
, CRB_CMDPEG_STATE
,
635 PHAN_INITIALIZE_FAILED
);
639 count
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
640 if (count
!= old_count
)
644 /* firmware is dead */
645 if (count
== old_count
)
648 /* check if we have got newer or different file firmware */
651 const struct firmware
*fw
= adapter
->fw
;
653 val
= cpu_to_le32(*(u32
*)&fw
->data
[NX_FW_VERSION_OFFSET
]);
654 version
= NETXEN_DECODE_VERSION(val
);
656 major
= NXRD32(adapter
, NETXEN_FW_VERSION_MAJOR
);
657 minor
= NXRD32(adapter
, NETXEN_FW_VERSION_MINOR
);
658 build
= NXRD32(adapter
, NETXEN_FW_VERSION_SUB
);
660 if (version
> NETXEN_VERSION_CODE(major
, minor
, build
))
663 if (version
== NETXEN_VERSION_CODE(major
, minor
, build
)) {
665 val
= NXRD32(adapter
, NETXEN_MIU_MN_CONTROL
);
666 fw_type
= (val
& 0x4) ?
667 NX_P3_CT_ROMIMAGE
: NX_P3_MN_ROMIMAGE
;
669 if (adapter
->fw_type
!= fw_type
)
677 static char *fw_name
[] = {
678 "nxromimg.bin", "nx3fwct.bin", "nx3fwmn.bin", "flash",
682 netxen_load_firmware(struct netxen_adapter
*adapter
)
685 u32 i
, flashaddr
, size
;
686 const struct firmware
*fw
= adapter
->fw
;
687 struct pci_dev
*pdev
= adapter
->pdev
;
689 dev_info(&pdev
->dev
, "loading firmware from %s\n",
690 fw_name
[adapter
->fw_type
]);
692 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
693 NXWR32(adapter
, NETXEN_ROMUSB_GLB_CAS_RST
, 1);
698 size
= (NETXEN_IMAGE_START
- NETXEN_BOOTLD_START
) / 8;
700 ptr64
= (u64
*)&fw
->data
[NETXEN_BOOTLD_START
];
701 flashaddr
= NETXEN_BOOTLD_START
;
703 for (i
= 0; i
< size
; i
++) {
704 data
= cpu_to_le64(ptr64
[i
]);
705 adapter
->pci_mem_write(adapter
, flashaddr
, &data
, 8);
709 size
= *(u32
*)&fw
->data
[NX_FW_SIZE_OFFSET
];
710 size
= (__force u32
)cpu_to_le32(size
) / 8;
712 ptr64
= (u64
*)&fw
->data
[NETXEN_IMAGE_START
];
713 flashaddr
= NETXEN_IMAGE_START
;
715 for (i
= 0; i
< size
; i
++) {
716 data
= cpu_to_le64(ptr64
[i
]);
718 if (adapter
->pci_mem_write(adapter
,
719 flashaddr
, &data
, 8))
728 size
= (NETXEN_IMAGE_START
- NETXEN_BOOTLD_START
) / 8;
729 flashaddr
= NETXEN_BOOTLD_START
;
731 for (i
= 0; i
< size
; i
++) {
732 if (netxen_rom_fast_read(adapter
,
733 flashaddr
, &lo
) != 0)
735 if (netxen_rom_fast_read(adapter
,
736 flashaddr
+ 4, &hi
) != 0)
739 /* hi, lo are already in host endian byteorder */
740 data
= (((u64
)hi
<< 32) | lo
);
742 if (adapter
->pci_mem_write(adapter
,
743 flashaddr
, &data
, 8))
751 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
752 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, 0x80001d);
754 NXWR32(adapter
, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL
, 0x3fff);
755 NXWR32(adapter
, NETXEN_ROMUSB_GLB_CAS_RST
, 0);
762 netxen_validate_firmware(struct netxen_adapter
*adapter
, const char *fwname
)
765 u32 ver
, min_ver
, bios
;
766 struct pci_dev
*pdev
= adapter
->pdev
;
767 const struct firmware
*fw
= adapter
->fw
;
769 if (fw
->size
< NX_FW_MIN_SIZE
)
772 val
= cpu_to_le32(*(u32
*)&fw
->data
[NX_FW_MAGIC_OFFSET
]);
773 if ((__force u32
)val
!= NETXEN_BDINFO_MAGIC
)
776 val
= cpu_to_le32(*(u32
*)&fw
->data
[NX_FW_VERSION_OFFSET
]);
778 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
779 min_ver
= NETXEN_VERSION_CODE(4, 0, 216);
781 min_ver
= NETXEN_VERSION_CODE(3, 4, 216);
783 ver
= NETXEN_DECODE_VERSION(val
);
785 if ((_major(ver
) > _NETXEN_NIC_LINUX_MAJOR
) || (ver
< min_ver
)) {
787 "%s: firmware version %d.%d.%d unsupported\n",
788 fwname
, _major(ver
), _minor(ver
), _build(ver
));
792 val
= cpu_to_le32(*(u32
*)&fw
->data
[NX_BIOS_VERSION_OFFSET
]);
793 netxen_rom_fast_read(adapter
, NX_BIOS_VERSION_OFFSET
, (int *)&bios
);
794 if ((__force u32
)val
!= bios
) {
795 dev_err(&pdev
->dev
, "%s: firmware bios is incompatible\n",
800 /* check if flashed firmware is newer */
801 if (netxen_rom_fast_read(adapter
,
802 NX_FW_VERSION_OFFSET
, (int *)&val
))
804 val
= NETXEN_DECODE_VERSION(val
);
806 dev_info(&pdev
->dev
, "%s: firmware is older than flash\n",
811 NXWR32(adapter
, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC
);
816 netxen_p3_has_mn(struct netxen_adapter
*adapter
)
818 u32 capability
, flashed_ver
;
821 netxen_rom_fast_read(adapter
,
822 NX_FW_VERSION_OFFSET
, (int *)&flashed_ver
);
823 flashed_ver
= NETXEN_DECODE_VERSION(flashed_ver
);
825 if (flashed_ver
>= NETXEN_VERSION_CODE(4, 0, 220)) {
827 capability
= NXRD32(adapter
, NX_PEG_TUNE_CAPABILITY
);
828 if (capability
& NX_PEG_TUNE_MN_PRESENT
)
834 void netxen_request_firmware(struct netxen_adapter
*adapter
)
837 struct pci_dev
*pdev
= adapter
->pdev
;
840 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
841 fw_type
= NX_P2_MN_ROMIMAGE
;
845 fw_type
= netxen_p3_has_mn(adapter
) ?
846 NX_P3_MN_ROMIMAGE
: NX_P3_CT_ROMIMAGE
;
849 rc
= request_firmware(&adapter
->fw
, fw_name
[fw_type
], &pdev
->dev
);
851 if (fw_type
== NX_P3_MN_ROMIMAGE
) {
853 fw_type
= NX_P3_CT_ROMIMAGE
;
857 fw_type
= NX_FLASH_ROMIMAGE
;
862 rc
= netxen_validate_firmware(adapter
, fw_name
[fw_type
]);
864 release_firmware(adapter
->fw
);
866 if (fw_type
== NX_P3_MN_ROMIMAGE
) {
868 fw_type
= NX_P3_CT_ROMIMAGE
;
872 fw_type
= NX_FLASH_ROMIMAGE
;
878 adapter
->fw_type
= fw_type
;
883 netxen_release_firmware(struct netxen_adapter
*adapter
)
886 release_firmware(adapter
->fw
);
890 int netxen_init_dummy_dma(struct netxen_adapter
*adapter
)
895 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
898 adapter
->dummy_dma
.addr
= pci_alloc_consistent(adapter
->pdev
,
899 NETXEN_HOST_DUMMY_DMA_SIZE
,
900 &adapter
->dummy_dma
.phys_addr
);
901 if (adapter
->dummy_dma
.addr
== NULL
) {
902 dev_err(&adapter
->pdev
->dev
,
903 "ERROR: Could not allocate dummy DMA memory\n");
907 addr
= (uint64_t) adapter
->dummy_dma
.phys_addr
;
908 hi
= (addr
>> 32) & 0xffffffff;
909 lo
= addr
& 0xffffffff;
911 NXWR32(adapter
, CRB_HOST_DUMMY_BUF_ADDR_HI
, hi
);
912 NXWR32(adapter
, CRB_HOST_DUMMY_BUF_ADDR_LO
, lo
);
918 * NetXen DMA watchdog control:
920 * Bit 0 : enabled => R/O: 1 watchdog active, 0 inactive
921 * Bit 1 : disable_request => 1 req disable dma watchdog
922 * Bit 2 : enable_request => 1 req enable dma watchdog
925 void netxen_free_dummy_dma(struct netxen_adapter
*adapter
)
930 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
933 if (!adapter
->dummy_dma
.addr
)
936 ctrl
= NXRD32(adapter
, NETXEN_DMA_WATCHDOG_CTRL
);
937 if ((ctrl
& 0x1) != 0) {
938 NXWR32(adapter
, NETXEN_DMA_WATCHDOG_CTRL
, (ctrl
| 0x2));
940 while ((ctrl
& 0x1) != 0) {
944 ctrl
= NXRD32(adapter
, NETXEN_DMA_WATCHDOG_CTRL
);
952 pci_free_consistent(adapter
->pdev
,
953 NETXEN_HOST_DUMMY_DMA_SIZE
,
954 adapter
->dummy_dma
.addr
,
955 adapter
->dummy_dma
.phys_addr
);
956 adapter
->dummy_dma
.addr
= NULL
;
958 dev_err(&adapter
->pdev
->dev
, "dma_watchdog_shutdown failed\n");
961 int netxen_phantom_init(struct netxen_adapter
*adapter
, int pegtune_val
)
970 val
= NXRD32(adapter
, CRB_CMDPEG_STATE
);
973 case PHAN_INITIALIZE_COMPLETE
:
974 case PHAN_INITIALIZE_ACK
:
976 case PHAN_INITIALIZE_FAILED
:
986 NXWR32(adapter
, CRB_CMDPEG_STATE
, PHAN_INITIALIZE_FAILED
);
989 dev_warn(&adapter
->pdev
->dev
, "firmware init failed\n");
994 netxen_receive_peg_ready(struct netxen_adapter
*adapter
)
1000 val
= NXRD32(adapter
, CRB_RCVPEG_STATE
);
1002 if (val
== PHAN_PEG_RCV_INITIALIZED
)
1007 } while (--retries
);
1010 printk(KERN_ERR
"Receive Peg initialization not "
1011 "complete, state: 0x%x.\n", val
);
1018 int netxen_init_firmware(struct netxen_adapter
*adapter
)
1022 err
= netxen_receive_peg_ready(adapter
);
1026 NXWR32(adapter
, CRB_NIC_CAPABILITIES_HOST
, INTR_SCHEME_PERPORT
);
1027 NXWR32(adapter
, CRB_NIC_MSI_MODE_HOST
, MSI_MODE_MULTIFUNC
);
1028 NXWR32(adapter
, CRB_MPORT_MODE
, MPORT_MULTI_FUNCTION_MODE
);
1029 NXWR32(adapter
, CRB_CMDPEG_STATE
, PHAN_INITIALIZE_ACK
);
1035 netxen_handle_linkevent(struct netxen_adapter
*adapter
, nx_fw_msg_t
*msg
)
1040 u8 link_status
, module
, duplex
, autoneg
;
1041 struct net_device
*netdev
= adapter
->netdev
;
1043 adapter
->has_link_events
= 1;
1045 cable_OUI
= msg
->body
[1] & 0xffffffff;
1046 cable_len
= (msg
->body
[1] >> 32) & 0xffff;
1047 link_speed
= (msg
->body
[1] >> 48) & 0xffff;
1049 link_status
= msg
->body
[2] & 0xff;
1050 duplex
= (msg
->body
[2] >> 16) & 0xff;
1051 autoneg
= (msg
->body
[2] >> 24) & 0xff;
1053 module
= (msg
->body
[2] >> 8) & 0xff;
1054 if (module
== LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE
) {
1055 printk(KERN_INFO
"%s: unsupported cable: OUI 0x%x, length %d\n",
1056 netdev
->name
, cable_OUI
, cable_len
);
1057 } else if (module
== LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN
) {
1058 printk(KERN_INFO
"%s: unsupported cable length %d\n",
1059 netdev
->name
, cable_len
);
1062 netxen_advert_link_change(adapter
, link_status
);
1064 /* update link parameters */
1065 if (duplex
== LINKEVENT_FULL_DUPLEX
)
1066 adapter
->link_duplex
= DUPLEX_FULL
;
1068 adapter
->link_duplex
= DUPLEX_HALF
;
1069 adapter
->module_type
= module
;
1070 adapter
->link_autoneg
= autoneg
;
1071 adapter
->link_speed
= link_speed
;
1075 netxen_handle_fw_message(int desc_cnt
, int index
,
1076 struct nx_host_sds_ring
*sds_ring
)
1079 struct status_desc
*desc
;
1082 while (desc_cnt
> 0 && i
< 8) {
1083 desc
= &sds_ring
->desc_head
[index
];
1084 msg
.words
[i
++] = le64_to_cpu(desc
->status_desc_data
[0]);
1085 msg
.words
[i
++] = le64_to_cpu(desc
->status_desc_data
[1]);
1087 index
= get_next_index(index
, sds_ring
->num_desc
);
1091 opcode
= netxen_get_nic_msg_opcode(msg
.body
[0]);
1093 case NX_NIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE
:
1094 netxen_handle_linkevent(sds_ring
->adapter
, &msg
);
1102 netxen_alloc_rx_skb(struct netxen_adapter
*adapter
,
1103 struct nx_host_rds_ring
*rds_ring
,
1104 struct netxen_rx_buffer
*buffer
)
1106 struct sk_buff
*skb
;
1108 struct pci_dev
*pdev
= adapter
->pdev
;
1110 buffer
->skb
= dev_alloc_skb(rds_ring
->skb_size
);
1116 if (!adapter
->ahw
.cut_through
)
1117 skb_reserve(skb
, 2);
1119 dma
= pci_map_single(pdev
, skb
->data
,
1120 rds_ring
->dma_size
, PCI_DMA_FROMDEVICE
);
1122 if (pci_dma_mapping_error(pdev
, dma
)) {
1123 dev_kfree_skb_any(skb
);
1130 buffer
->state
= NETXEN_BUFFER_BUSY
;
1135 static struct sk_buff
*netxen_process_rxbuf(struct netxen_adapter
*adapter
,
1136 struct nx_host_rds_ring
*rds_ring
, u16 index
, u16 cksum
)
1138 struct netxen_rx_buffer
*buffer
;
1139 struct sk_buff
*skb
;
1141 buffer
= &rds_ring
->rx_buf_arr
[index
];
1143 pci_unmap_single(adapter
->pdev
, buffer
->dma
, rds_ring
->dma_size
,
1144 PCI_DMA_FROMDEVICE
);
1150 if (likely(adapter
->rx_csum
&& cksum
== STATUS_CKSUM_OK
)) {
1151 adapter
->stats
.csummed
++;
1152 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1154 skb
->ip_summed
= CHECKSUM_NONE
;
1156 skb
->dev
= adapter
->netdev
;
1160 buffer
->state
= NETXEN_BUFFER_FREE
;
1164 static struct netxen_rx_buffer
*
1165 netxen_process_rcv(struct netxen_adapter
*adapter
,
1166 struct nx_host_sds_ring
*sds_ring
,
1167 int ring
, u64 sts_data0
)
1169 struct net_device
*netdev
= adapter
->netdev
;
1170 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1171 struct netxen_rx_buffer
*buffer
;
1172 struct sk_buff
*skb
;
1173 struct nx_host_rds_ring
*rds_ring
;
1174 int index
, length
, cksum
, pkt_offset
;
1176 if (unlikely(ring
>= adapter
->max_rds_rings
))
1179 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1181 index
= netxen_get_sts_refhandle(sts_data0
);
1182 if (unlikely(index
>= rds_ring
->num_desc
))
1185 buffer
= &rds_ring
->rx_buf_arr
[index
];
1187 length
= netxen_get_sts_totallength(sts_data0
);
1188 cksum
= netxen_get_sts_status(sts_data0
);
1189 pkt_offset
= netxen_get_sts_pkt_offset(sts_data0
);
1191 skb
= netxen_process_rxbuf(adapter
, rds_ring
, index
, cksum
);
1195 if (length
> rds_ring
->skb_size
)
1196 skb_put(skb
, rds_ring
->skb_size
);
1198 skb_put(skb
, length
);
1202 skb_pull(skb
, pkt_offset
);
1204 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
);
1205 skb
->protocol
= eth_type_trans(skb
, netdev
);
1207 napi_gro_receive(&sds_ring
->napi
, skb
);
1209 adapter
->stats
.rx_pkts
++;
1210 adapter
->stats
.rxbytes
+= length
;
1215 #define TCP_HDR_SIZE 20
1216 #define TCP_TS_OPTION_SIZE 12
1217 #define TCP_TS_HDR_SIZE (TCP_HDR_SIZE + TCP_TS_OPTION_SIZE)
1219 static struct netxen_rx_buffer
*
1220 netxen_process_lro(struct netxen_adapter
*adapter
,
1221 struct nx_host_sds_ring
*sds_ring
,
1222 int ring
, u64 sts_data0
, u64 sts_data1
)
1224 struct net_device
*netdev
= adapter
->netdev
;
1225 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1226 struct netxen_rx_buffer
*buffer
;
1227 struct sk_buff
*skb
;
1228 struct nx_host_rds_ring
*rds_ring
;
1231 bool push
, timestamp
;
1232 int l2_hdr_offset
, l4_hdr_offset
;
1234 u16 lro_length
, length
, data_offset
;
1237 if (unlikely(ring
> adapter
->max_rds_rings
))
1240 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1242 index
= netxen_get_lro_sts_refhandle(sts_data0
);
1243 if (unlikely(index
> rds_ring
->num_desc
))
1246 buffer
= &rds_ring
->rx_buf_arr
[index
];
1248 timestamp
= netxen_get_lro_sts_timestamp(sts_data0
);
1249 lro_length
= netxen_get_lro_sts_length(sts_data0
);
1250 l2_hdr_offset
= netxen_get_lro_sts_l2_hdr_offset(sts_data0
);
1251 l4_hdr_offset
= netxen_get_lro_sts_l4_hdr_offset(sts_data0
);
1252 push
= netxen_get_lro_sts_push_flag(sts_data0
);
1253 seq_number
= netxen_get_lro_sts_seq_number(sts_data1
);
1255 skb
= netxen_process_rxbuf(adapter
, rds_ring
, index
, STATUS_CKSUM_OK
);
1260 data_offset
= l4_hdr_offset
+ TCP_TS_HDR_SIZE
;
1262 data_offset
= l4_hdr_offset
+ TCP_HDR_SIZE
;
1264 skb_put(skb
, lro_length
+ data_offset
);
1266 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
) + skb_headroom(skb
);
1268 skb_pull(skb
, l2_hdr_offset
);
1269 skb
->protocol
= eth_type_trans(skb
, netdev
);
1271 iph
= (struct iphdr
*)skb
->data
;
1272 th
= (struct tcphdr
*)(skb
->data
+ (iph
->ihl
<< 2));
1274 length
= (iph
->ihl
<< 2) + (th
->doff
<< 2) + lro_length
;
1275 iph
->tot_len
= htons(length
);
1277 iph
->check
= ip_fast_csum((unsigned char *)iph
, iph
->ihl
);
1279 th
->seq
= htonl(seq_number
);
1283 netif_receive_skb(skb
);
1285 adapter
->stats
.lro_pkts
++;
1286 adapter
->stats
.rxbytes
+= length
;
1291 #define netxen_merge_rx_buffers(list, head) \
1292 do { list_splice_tail_init(list, head); } while (0);
1295 netxen_process_rcv_ring(struct nx_host_sds_ring
*sds_ring
, int max
)
1297 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
1299 struct list_head
*cur
;
1301 struct status_desc
*desc
;
1302 struct netxen_rx_buffer
*rxbuf
;
1304 u32 consumer
= sds_ring
->consumer
;
1307 u64 sts_data0
, sts_data1
;
1308 int opcode
, ring
= 0, desc_cnt
;
1310 while (count
< max
) {
1311 desc
= &sds_ring
->desc_head
[consumer
];
1312 sts_data0
= le64_to_cpu(desc
->status_desc_data
[0]);
1314 if (!(sts_data0
& STATUS_OWNER_HOST
))
1317 desc_cnt
= netxen_get_sts_desc_cnt(sts_data0
);
1319 opcode
= netxen_get_sts_opcode(sts_data0
);
1322 case NETXEN_NIC_RXPKT_DESC
:
1323 case NETXEN_OLD_RXPKT_DESC
:
1324 case NETXEN_NIC_SYN_OFFLOAD
:
1325 ring
= netxen_get_sts_type(sts_data0
);
1326 rxbuf
= netxen_process_rcv(adapter
, sds_ring
,
1329 case NETXEN_NIC_LRO_DESC
:
1330 ring
= netxen_get_lro_sts_type(sts_data0
);
1331 sts_data1
= le64_to_cpu(desc
->status_desc_data
[1]);
1332 rxbuf
= netxen_process_lro(adapter
, sds_ring
,
1333 ring
, sts_data0
, sts_data1
);
1335 case NETXEN_NIC_RESPONSE_DESC
:
1336 netxen_handle_fw_message(desc_cnt
, consumer
, sds_ring
);
1341 WARN_ON(desc_cnt
> 1);
1344 list_add_tail(&rxbuf
->list
, &sds_ring
->free_list
[ring
]);
1347 for (; desc_cnt
> 0; desc_cnt
--) {
1348 desc
= &sds_ring
->desc_head
[consumer
];
1349 desc
->status_desc_data
[0] =
1350 cpu_to_le64(STATUS_OWNER_PHANTOM
);
1351 consumer
= get_next_index(consumer
, sds_ring
->num_desc
);
1356 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1357 struct nx_host_rds_ring
*rds_ring
=
1358 &adapter
->recv_ctx
.rds_rings
[ring
];
1360 if (!list_empty(&sds_ring
->free_list
[ring
])) {
1361 list_for_each(cur
, &sds_ring
->free_list
[ring
]) {
1362 rxbuf
= list_entry(cur
,
1363 struct netxen_rx_buffer
, list
);
1364 netxen_alloc_rx_skb(adapter
, rds_ring
, rxbuf
);
1366 spin_lock(&rds_ring
->lock
);
1367 netxen_merge_rx_buffers(&sds_ring
->free_list
[ring
],
1368 &rds_ring
->free_list
);
1369 spin_unlock(&rds_ring
->lock
);
1372 netxen_post_rx_buffers_nodb(adapter
, rds_ring
);
1376 sds_ring
->consumer
= consumer
;
1377 NXWRIO(adapter
, sds_ring
->crb_sts_consumer
, consumer
);
1383 /* Process Command status ring */
1384 int netxen_process_cmd_ring(struct netxen_adapter
*adapter
)
1386 u32 sw_consumer
, hw_consumer
;
1388 struct netxen_cmd_buffer
*buffer
;
1389 struct pci_dev
*pdev
= adapter
->pdev
;
1390 struct net_device
*netdev
= adapter
->netdev
;
1391 struct netxen_skb_frag
*frag
;
1393 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1395 if (!spin_trylock(&adapter
->tx_clean_lock
))
1398 sw_consumer
= tx_ring
->sw_consumer
;
1399 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
1401 while (sw_consumer
!= hw_consumer
) {
1402 buffer
= &tx_ring
->cmd_buf_arr
[sw_consumer
];
1404 frag
= &buffer
->frag_array
[0];
1405 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
1408 for (i
= 1; i
< buffer
->frag_count
; i
++) {
1409 frag
++; /* Get the next frag */
1410 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
1415 adapter
->stats
.xmitfinished
++;
1416 dev_kfree_skb_any(buffer
->skb
);
1420 sw_consumer
= get_next_index(sw_consumer
, tx_ring
->num_desc
);
1421 if (++count
>= MAX_STATUS_HANDLE
)
1425 if (count
&& netif_running(netdev
)) {
1426 tx_ring
->sw_consumer
= sw_consumer
;
1430 if (netif_queue_stopped(netdev
) && netif_carrier_ok(netdev
)) {
1431 __netif_tx_lock(tx_ring
->txq
, smp_processor_id());
1432 if (netxen_tx_avail(tx_ring
) > TX_STOP_THRESH
) {
1433 netif_wake_queue(netdev
);
1434 adapter
->tx_timeo_cnt
= 0;
1436 __netif_tx_unlock(tx_ring
->txq
);
1440 * If everything is freed up to consumer then check if the ring is full
1441 * If the ring is full then check if more needs to be freed and
1442 * schedule the call back again.
1444 * This happens when there are 2 CPUs. One could be freeing and the
1445 * other filling it. If the ring is full when we get out of here and
1446 * the card has already interrupted the host then the host can miss the
1449 * There is still a possible race condition and the host could miss an
1450 * interrupt. The card has to take care of this.
1452 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
1453 done
= (sw_consumer
== hw_consumer
);
1454 spin_unlock(&adapter
->tx_clean_lock
);
1460 netxen_post_rx_buffers(struct netxen_adapter
*adapter
, u32 ringid
,
1461 struct nx_host_rds_ring
*rds_ring
)
1463 struct rcv_desc
*pdesc
;
1464 struct netxen_rx_buffer
*buffer
;
1465 int producer
, count
= 0;
1466 netxen_ctx_msg msg
= 0;
1467 struct list_head
*head
;
1469 producer
= rds_ring
->producer
;
1471 spin_lock(&rds_ring
->lock
);
1472 head
= &rds_ring
->free_list
;
1473 while (!list_empty(head
)) {
1475 buffer
= list_entry(head
->next
, struct netxen_rx_buffer
, list
);
1478 if (netxen_alloc_rx_skb(adapter
, rds_ring
, buffer
))
1483 list_del(&buffer
->list
);
1485 /* make a rcv descriptor */
1486 pdesc
= &rds_ring
->desc_head
[producer
];
1487 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1488 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1489 pdesc
->buffer_length
= cpu_to_le32(rds_ring
->dma_size
);
1491 producer
= get_next_index(producer
, rds_ring
->num_desc
);
1493 spin_unlock(&rds_ring
->lock
);
1496 rds_ring
->producer
= producer
;
1497 NXWRIO(adapter
, rds_ring
->crb_rcv_producer
,
1498 (producer
-1) & (rds_ring
->num_desc
-1));
1500 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1502 * Write a doorbell msg to tell phanmon of change in
1503 * receive ring producer
1504 * Only for firmware version < 4.0.0
1506 netxen_set_msg_peg_id(msg
, NETXEN_RCV_PEG_DB_ID
);
1507 netxen_set_msg_privid(msg
);
1508 netxen_set_msg_count(msg
,
1510 (rds_ring
->num_desc
- 1)));
1511 netxen_set_msg_ctxid(msg
, adapter
->portnum
);
1512 netxen_set_msg_opcode(msg
, NETXEN_RCV_PRODUCER(ringid
));
1513 read_lock(&adapter
->adapter_lock
);
1514 writel(msg
, DB_NORMALIZE(adapter
,
1515 NETXEN_RCV_PRODUCER_OFFSET
));
1516 read_unlock(&adapter
->adapter_lock
);
1522 netxen_post_rx_buffers_nodb(struct netxen_adapter
*adapter
,
1523 struct nx_host_rds_ring
*rds_ring
)
1525 struct rcv_desc
*pdesc
;
1526 struct netxen_rx_buffer
*buffer
;
1527 int producer
, count
= 0;
1528 struct list_head
*head
;
1530 producer
= rds_ring
->producer
;
1531 if (!spin_trylock(&rds_ring
->lock
))
1534 head
= &rds_ring
->free_list
;
1535 while (!list_empty(head
)) {
1537 buffer
= list_entry(head
->next
, struct netxen_rx_buffer
, list
);
1540 if (netxen_alloc_rx_skb(adapter
, rds_ring
, buffer
))
1545 list_del(&buffer
->list
);
1547 /* make a rcv descriptor */
1548 pdesc
= &rds_ring
->desc_head
[producer
];
1549 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1550 pdesc
->buffer_length
= cpu_to_le32(rds_ring
->dma_size
);
1551 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1553 producer
= get_next_index(producer
, rds_ring
->num_desc
);
1557 rds_ring
->producer
= producer
;
1558 NXWRIO(adapter
, rds_ring
->crb_rcv_producer
,
1559 (producer
- 1) & (rds_ring
->num_desc
- 1));
1561 spin_unlock(&rds_ring
->lock
);
1564 void netxen_nic_clear_stats(struct netxen_adapter
*adapter
)
1566 memset(&adapter
->stats
, 0, sizeof(adapter
->stats
));