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 if (off
== (NETXEN_CRB_I2C0
+ 0x1c))
536 /* do not reset PCI */
537 if (off
== (ROMUSB_GLB
+ 0xbc))
539 if (off
== (ROMUSB_GLB
+ 0xa8))
541 if (off
== (ROMUSB_GLB
+ 0xc8)) /* core clock */
543 if (off
== (ROMUSB_GLB
+ 0x24)) /* MN clock */
545 if (off
== (ROMUSB_GLB
+ 0x1c)) /* MS clock */
547 if (off
== (NETXEN_CRB_PEG_NET_1
+ 0x18))
548 buf
[i
].data
= 0x1020;
549 /* skip the function enable register */
550 if (off
== NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION
))
552 if (off
== NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION2
))
554 if ((off
& 0x0ff00000) == NETXEN_CRB_SMB
)
559 /* After writing this register, HW needs time for CRB */
560 /* to quiet down (else crb_window returns 0xffffffff) */
561 if (off
== NETXEN_ROMUSB_GLB_SW_RESET
) {
563 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
564 /* hold xdma in reset also */
565 buf
[i
].data
= NETXEN_NIC_XDMA_RESET
;
566 buf
[i
].data
= 0x8000ff;
570 NXWR32(adapter
, off
, buf
[i
].data
);
576 /* disable_peg_cache_all */
578 /* unreset_net_cache */
579 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
580 val
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
);
581 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, (val
& 0xffffff0f));
584 /* p2dn replyCount */
585 NXWR32(adapter
, NETXEN_CRB_PEG_NET_D
+ 0xec, 0x1e);
586 /* disable_peg_cache 0 */
587 NXWR32(adapter
, NETXEN_CRB_PEG_NET_D
+ 0x4c, 8);
588 /* disable_peg_cache 1 */
589 NXWR32(adapter
, NETXEN_CRB_PEG_NET_I
+ 0x4c, 8);
594 NXWR32(adapter
, NETXEN_CRB_PEG_NET_0
+ 0x8, 0);
595 NXWR32(adapter
, NETXEN_CRB_PEG_NET_0
+ 0xc, 0);
597 NXWR32(adapter
, NETXEN_CRB_PEG_NET_1
+ 0x8, 0);
598 NXWR32(adapter
, NETXEN_CRB_PEG_NET_1
+ 0xc, 0);
600 NXWR32(adapter
, NETXEN_CRB_PEG_NET_2
+ 0x8, 0);
601 NXWR32(adapter
, NETXEN_CRB_PEG_NET_2
+ 0xc, 0);
603 NXWR32(adapter
, NETXEN_CRB_PEG_NET_3
+ 0x8, 0);
604 NXWR32(adapter
, NETXEN_CRB_PEG_NET_3
+ 0xc, 0);
609 netxen_need_fw_reset(struct netxen_adapter
*adapter
)
611 u32 count
, old_count
;
612 u32 val
, version
, major
, minor
, build
;
616 /* NX2031 firmware doesn't support heartbit */
617 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
620 /* last attempt had failed */
621 if (NXRD32(adapter
, CRB_CMDPEG_STATE
) == PHAN_INITIALIZE_FAILED
)
624 old_count
= count
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
626 for (i
= 0; i
< 10; i
++) {
628 timeout
= msleep_interruptible(200);
630 NXWR32(adapter
, CRB_CMDPEG_STATE
,
631 PHAN_INITIALIZE_FAILED
);
635 count
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
636 if (count
!= old_count
)
640 /* firmware is dead */
641 if (count
== old_count
)
644 /* check if we have got newer or different file firmware */
647 const struct firmware
*fw
= adapter
->fw
;
649 val
= cpu_to_le32(*(u32
*)&fw
->data
[NX_FW_VERSION_OFFSET
]);
650 version
= NETXEN_DECODE_VERSION(val
);
652 major
= NXRD32(adapter
, NETXEN_FW_VERSION_MAJOR
);
653 minor
= NXRD32(adapter
, NETXEN_FW_VERSION_MINOR
);
654 build
= NXRD32(adapter
, NETXEN_FW_VERSION_SUB
);
656 if (version
> NETXEN_VERSION_CODE(major
, minor
, build
))
659 if (version
== NETXEN_VERSION_CODE(major
, minor
, build
)) {
661 val
= NXRD32(adapter
, NETXEN_MIU_MN_CONTROL
);
662 fw_type
= (val
& 0x4) ?
663 NX_P3_CT_ROMIMAGE
: NX_P3_MN_ROMIMAGE
;
665 if (adapter
->fw_type
!= fw_type
)
673 static char *fw_name
[] = {
674 "nxromimg.bin", "nx3fwct.bin", "nx3fwmn.bin", "flash",
678 netxen_load_firmware(struct netxen_adapter
*adapter
)
681 u32 i
, flashaddr
, size
;
682 const struct firmware
*fw
= adapter
->fw
;
683 struct pci_dev
*pdev
= adapter
->pdev
;
685 dev_info(&pdev
->dev
, "loading firmware from %s\n",
686 fw_name
[adapter
->fw_type
]);
688 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
689 NXWR32(adapter
, NETXEN_ROMUSB_GLB_CAS_RST
, 1);
694 size
= (NETXEN_IMAGE_START
- NETXEN_BOOTLD_START
) / 8;
696 ptr64
= (u64
*)&fw
->data
[NETXEN_BOOTLD_START
];
697 flashaddr
= NETXEN_BOOTLD_START
;
699 for (i
= 0; i
< size
; i
++) {
700 data
= cpu_to_le64(ptr64
[i
]);
701 adapter
->pci_mem_write(adapter
, flashaddr
, &data
, 8);
705 size
= *(u32
*)&fw
->data
[NX_FW_SIZE_OFFSET
];
706 size
= (__force u32
)cpu_to_le32(size
) / 8;
708 ptr64
= (u64
*)&fw
->data
[NETXEN_IMAGE_START
];
709 flashaddr
= NETXEN_IMAGE_START
;
711 for (i
= 0; i
< size
; i
++) {
712 data
= cpu_to_le64(ptr64
[i
]);
714 if (adapter
->pci_mem_write(adapter
,
715 flashaddr
, &data
, 8))
724 size
= (NETXEN_IMAGE_START
- NETXEN_BOOTLD_START
) / 8;
725 flashaddr
= NETXEN_BOOTLD_START
;
727 for (i
= 0; i
< size
; i
++) {
728 if (netxen_rom_fast_read(adapter
,
729 flashaddr
, &lo
) != 0)
731 if (netxen_rom_fast_read(adapter
,
732 flashaddr
+ 4, &hi
) != 0)
735 /* hi, lo are already in host endian byteorder */
736 data
= (((u64
)hi
<< 32) | lo
);
738 if (adapter
->pci_mem_write(adapter
,
739 flashaddr
, &data
, 8))
747 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
748 NXWR32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, 0x80001d);
750 NXWR32(adapter
, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL
, 0x3fff);
751 NXWR32(adapter
, NETXEN_ROMUSB_GLB_CAS_RST
, 0);
758 netxen_validate_firmware(struct netxen_adapter
*adapter
, const char *fwname
)
761 u32 ver
, min_ver
, bios
;
762 struct pci_dev
*pdev
= adapter
->pdev
;
763 const struct firmware
*fw
= adapter
->fw
;
765 if (fw
->size
< NX_FW_MIN_SIZE
)
768 val
= cpu_to_le32(*(u32
*)&fw
->data
[NX_FW_MAGIC_OFFSET
]);
769 if ((__force u32
)val
!= NETXEN_BDINFO_MAGIC
)
772 val
= cpu_to_le32(*(u32
*)&fw
->data
[NX_FW_VERSION_OFFSET
]);
774 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
775 min_ver
= NETXEN_VERSION_CODE(4, 0, 216);
777 min_ver
= NETXEN_VERSION_CODE(3, 4, 216);
779 ver
= NETXEN_DECODE_VERSION(val
);
781 if ((_major(ver
) > _NETXEN_NIC_LINUX_MAJOR
) || (ver
< min_ver
)) {
783 "%s: firmware version %d.%d.%d unsupported\n",
784 fwname
, _major(ver
), _minor(ver
), _build(ver
));
788 val
= cpu_to_le32(*(u32
*)&fw
->data
[NX_BIOS_VERSION_OFFSET
]);
789 netxen_rom_fast_read(adapter
, NX_BIOS_VERSION_OFFSET
, (int *)&bios
);
790 if ((__force u32
)val
!= bios
) {
791 dev_err(&pdev
->dev
, "%s: firmware bios is incompatible\n",
796 /* check if flashed firmware is newer */
797 if (netxen_rom_fast_read(adapter
,
798 NX_FW_VERSION_OFFSET
, (int *)&val
))
800 val
= NETXEN_DECODE_VERSION(val
);
802 dev_info(&pdev
->dev
, "%s: firmware is older than flash\n",
807 NXWR32(adapter
, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC
);
812 netxen_p3_has_mn(struct netxen_adapter
*adapter
)
814 u32 capability
, flashed_ver
;
817 netxen_rom_fast_read(adapter
,
818 NX_FW_VERSION_OFFSET
, (int *)&flashed_ver
);
819 flashed_ver
= NETXEN_DECODE_VERSION(flashed_ver
);
821 if (flashed_ver
>= NETXEN_VERSION_CODE(4, 0, 220)) {
823 capability
= NXRD32(adapter
, NX_PEG_TUNE_CAPABILITY
);
824 if (capability
& NX_PEG_TUNE_MN_PRESENT
)
830 void netxen_request_firmware(struct netxen_adapter
*adapter
)
833 struct pci_dev
*pdev
= adapter
->pdev
;
836 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
837 fw_type
= NX_P2_MN_ROMIMAGE
;
841 fw_type
= netxen_p3_has_mn(adapter
) ?
842 NX_P3_MN_ROMIMAGE
: NX_P3_CT_ROMIMAGE
;
845 rc
= request_firmware(&adapter
->fw
, fw_name
[fw_type
], &pdev
->dev
);
847 if (fw_type
== NX_P3_MN_ROMIMAGE
) {
849 fw_type
= NX_P3_CT_ROMIMAGE
;
853 fw_type
= NX_FLASH_ROMIMAGE
;
858 rc
= netxen_validate_firmware(adapter
, fw_name
[fw_type
]);
860 release_firmware(adapter
->fw
);
862 if (fw_type
== NX_P3_MN_ROMIMAGE
) {
864 fw_type
= NX_P3_CT_ROMIMAGE
;
868 fw_type
= NX_FLASH_ROMIMAGE
;
874 adapter
->fw_type
= fw_type
;
879 netxen_release_firmware(struct netxen_adapter
*adapter
)
882 release_firmware(adapter
->fw
);
886 int netxen_init_dummy_dma(struct netxen_adapter
*adapter
)
891 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
894 adapter
->dummy_dma
.addr
= pci_alloc_consistent(adapter
->pdev
,
895 NETXEN_HOST_DUMMY_DMA_SIZE
,
896 &adapter
->dummy_dma
.phys_addr
);
897 if (adapter
->dummy_dma
.addr
== NULL
) {
898 dev_err(&adapter
->pdev
->dev
,
899 "ERROR: Could not allocate dummy DMA memory\n");
903 addr
= (uint64_t) adapter
->dummy_dma
.phys_addr
;
904 hi
= (addr
>> 32) & 0xffffffff;
905 lo
= addr
& 0xffffffff;
907 NXWR32(adapter
, CRB_HOST_DUMMY_BUF_ADDR_HI
, hi
);
908 NXWR32(adapter
, CRB_HOST_DUMMY_BUF_ADDR_LO
, lo
);
914 * NetXen DMA watchdog control:
916 * Bit 0 : enabled => R/O: 1 watchdog active, 0 inactive
917 * Bit 1 : disable_request => 1 req disable dma watchdog
918 * Bit 2 : enable_request => 1 req enable dma watchdog
921 void netxen_free_dummy_dma(struct netxen_adapter
*adapter
)
926 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
929 if (!adapter
->dummy_dma
.addr
)
932 ctrl
= NXRD32(adapter
, NETXEN_DMA_WATCHDOG_CTRL
);
933 if ((ctrl
& 0x1) != 0) {
934 NXWR32(adapter
, NETXEN_DMA_WATCHDOG_CTRL
, (ctrl
| 0x2));
936 while ((ctrl
& 0x1) != 0) {
940 ctrl
= NXRD32(adapter
, NETXEN_DMA_WATCHDOG_CTRL
);
948 pci_free_consistent(adapter
->pdev
,
949 NETXEN_HOST_DUMMY_DMA_SIZE
,
950 adapter
->dummy_dma
.addr
,
951 adapter
->dummy_dma
.phys_addr
);
952 adapter
->dummy_dma
.addr
= NULL
;
954 dev_err(&adapter
->pdev
->dev
, "dma_watchdog_shutdown failed\n");
957 int netxen_phantom_init(struct netxen_adapter
*adapter
, int pegtune_val
)
966 val
= NXRD32(adapter
, CRB_CMDPEG_STATE
);
969 case PHAN_INITIALIZE_COMPLETE
:
970 case PHAN_INITIALIZE_ACK
:
972 case PHAN_INITIALIZE_FAILED
:
982 NXWR32(adapter
, CRB_CMDPEG_STATE
, PHAN_INITIALIZE_FAILED
);
985 dev_warn(&adapter
->pdev
->dev
, "firmware init failed\n");
990 netxen_receive_peg_ready(struct netxen_adapter
*adapter
)
996 val
= NXRD32(adapter
, CRB_RCVPEG_STATE
);
998 if (val
== PHAN_PEG_RCV_INITIALIZED
)
1003 } while (--retries
);
1006 printk(KERN_ERR
"Receive Peg initialization not "
1007 "complete, state: 0x%x.\n", val
);
1014 int netxen_init_firmware(struct netxen_adapter
*adapter
)
1018 err
= netxen_receive_peg_ready(adapter
);
1022 NXWR32(adapter
, CRB_NIC_CAPABILITIES_HOST
, INTR_SCHEME_PERPORT
);
1023 NXWR32(adapter
, CRB_NIC_MSI_MODE_HOST
, MSI_MODE_MULTIFUNC
);
1024 NXWR32(adapter
, CRB_MPORT_MODE
, MPORT_MULTI_FUNCTION_MODE
);
1025 NXWR32(adapter
, CRB_CMDPEG_STATE
, PHAN_INITIALIZE_ACK
);
1031 netxen_handle_linkevent(struct netxen_adapter
*adapter
, nx_fw_msg_t
*msg
)
1036 u8 link_status
, module
, duplex
, autoneg
;
1037 struct net_device
*netdev
= adapter
->netdev
;
1039 adapter
->has_link_events
= 1;
1041 cable_OUI
= msg
->body
[1] & 0xffffffff;
1042 cable_len
= (msg
->body
[1] >> 32) & 0xffff;
1043 link_speed
= (msg
->body
[1] >> 48) & 0xffff;
1045 link_status
= msg
->body
[2] & 0xff;
1046 duplex
= (msg
->body
[2] >> 16) & 0xff;
1047 autoneg
= (msg
->body
[2] >> 24) & 0xff;
1049 module
= (msg
->body
[2] >> 8) & 0xff;
1050 if (module
== LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE
) {
1051 printk(KERN_INFO
"%s: unsupported cable: OUI 0x%x, length %d\n",
1052 netdev
->name
, cable_OUI
, cable_len
);
1053 } else if (module
== LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN
) {
1054 printk(KERN_INFO
"%s: unsupported cable length %d\n",
1055 netdev
->name
, cable_len
);
1058 netxen_advert_link_change(adapter
, link_status
);
1060 /* update link parameters */
1061 if (duplex
== LINKEVENT_FULL_DUPLEX
)
1062 adapter
->link_duplex
= DUPLEX_FULL
;
1064 adapter
->link_duplex
= DUPLEX_HALF
;
1065 adapter
->module_type
= module
;
1066 adapter
->link_autoneg
= autoneg
;
1067 adapter
->link_speed
= link_speed
;
1071 netxen_handle_fw_message(int desc_cnt
, int index
,
1072 struct nx_host_sds_ring
*sds_ring
)
1075 struct status_desc
*desc
;
1078 while (desc_cnt
> 0 && i
< 8) {
1079 desc
= &sds_ring
->desc_head
[index
];
1080 msg
.words
[i
++] = le64_to_cpu(desc
->status_desc_data
[0]);
1081 msg
.words
[i
++] = le64_to_cpu(desc
->status_desc_data
[1]);
1083 index
= get_next_index(index
, sds_ring
->num_desc
);
1087 opcode
= netxen_get_nic_msg_opcode(msg
.body
[0]);
1089 case NX_NIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE
:
1090 netxen_handle_linkevent(sds_ring
->adapter
, &msg
);
1098 netxen_alloc_rx_skb(struct netxen_adapter
*adapter
,
1099 struct nx_host_rds_ring
*rds_ring
,
1100 struct netxen_rx_buffer
*buffer
)
1102 struct sk_buff
*skb
;
1104 struct pci_dev
*pdev
= adapter
->pdev
;
1106 buffer
->skb
= dev_alloc_skb(rds_ring
->skb_size
);
1112 if (!adapter
->ahw
.cut_through
)
1113 skb_reserve(skb
, 2);
1115 dma
= pci_map_single(pdev
, skb
->data
,
1116 rds_ring
->dma_size
, PCI_DMA_FROMDEVICE
);
1118 if (pci_dma_mapping_error(pdev
, dma
)) {
1119 dev_kfree_skb_any(skb
);
1126 buffer
->state
= NETXEN_BUFFER_BUSY
;
1131 static struct sk_buff
*netxen_process_rxbuf(struct netxen_adapter
*adapter
,
1132 struct nx_host_rds_ring
*rds_ring
, u16 index
, u16 cksum
)
1134 struct netxen_rx_buffer
*buffer
;
1135 struct sk_buff
*skb
;
1137 buffer
= &rds_ring
->rx_buf_arr
[index
];
1139 pci_unmap_single(adapter
->pdev
, buffer
->dma
, rds_ring
->dma_size
,
1140 PCI_DMA_FROMDEVICE
);
1146 if (likely(adapter
->rx_csum
&& cksum
== STATUS_CKSUM_OK
)) {
1147 adapter
->stats
.csummed
++;
1148 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1150 skb
->ip_summed
= CHECKSUM_NONE
;
1152 skb
->dev
= adapter
->netdev
;
1156 buffer
->state
= NETXEN_BUFFER_FREE
;
1160 static struct netxen_rx_buffer
*
1161 netxen_process_rcv(struct netxen_adapter
*adapter
,
1162 struct nx_host_sds_ring
*sds_ring
,
1163 int ring
, u64 sts_data0
)
1165 struct net_device
*netdev
= adapter
->netdev
;
1166 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1167 struct netxen_rx_buffer
*buffer
;
1168 struct sk_buff
*skb
;
1169 struct nx_host_rds_ring
*rds_ring
;
1170 int index
, length
, cksum
, pkt_offset
;
1172 if (unlikely(ring
>= adapter
->max_rds_rings
))
1175 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1177 index
= netxen_get_sts_refhandle(sts_data0
);
1178 if (unlikely(index
>= rds_ring
->num_desc
))
1181 buffer
= &rds_ring
->rx_buf_arr
[index
];
1183 length
= netxen_get_sts_totallength(sts_data0
);
1184 cksum
= netxen_get_sts_status(sts_data0
);
1185 pkt_offset
= netxen_get_sts_pkt_offset(sts_data0
);
1187 skb
= netxen_process_rxbuf(adapter
, rds_ring
, index
, cksum
);
1191 if (length
> rds_ring
->skb_size
)
1192 skb_put(skb
, rds_ring
->skb_size
);
1194 skb_put(skb
, length
);
1198 skb_pull(skb
, pkt_offset
);
1200 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
);
1201 skb
->protocol
= eth_type_trans(skb
, netdev
);
1203 napi_gro_receive(&sds_ring
->napi
, skb
);
1205 adapter
->stats
.rx_pkts
++;
1206 adapter
->stats
.rxbytes
+= length
;
1211 #define TCP_HDR_SIZE 20
1212 #define TCP_TS_OPTION_SIZE 12
1213 #define TCP_TS_HDR_SIZE (TCP_HDR_SIZE + TCP_TS_OPTION_SIZE)
1215 static struct netxen_rx_buffer
*
1216 netxen_process_lro(struct netxen_adapter
*adapter
,
1217 struct nx_host_sds_ring
*sds_ring
,
1218 int ring
, u64 sts_data0
, u64 sts_data1
)
1220 struct net_device
*netdev
= adapter
->netdev
;
1221 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1222 struct netxen_rx_buffer
*buffer
;
1223 struct sk_buff
*skb
;
1224 struct nx_host_rds_ring
*rds_ring
;
1227 bool push
, timestamp
;
1228 int l2_hdr_offset
, l4_hdr_offset
;
1230 u16 lro_length
, length
, data_offset
;
1233 if (unlikely(ring
> adapter
->max_rds_rings
))
1236 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1238 index
= netxen_get_lro_sts_refhandle(sts_data0
);
1239 if (unlikely(index
> rds_ring
->num_desc
))
1242 buffer
= &rds_ring
->rx_buf_arr
[index
];
1244 timestamp
= netxen_get_lro_sts_timestamp(sts_data0
);
1245 lro_length
= netxen_get_lro_sts_length(sts_data0
);
1246 l2_hdr_offset
= netxen_get_lro_sts_l2_hdr_offset(sts_data0
);
1247 l4_hdr_offset
= netxen_get_lro_sts_l4_hdr_offset(sts_data0
);
1248 push
= netxen_get_lro_sts_push_flag(sts_data0
);
1249 seq_number
= netxen_get_lro_sts_seq_number(sts_data1
);
1251 skb
= netxen_process_rxbuf(adapter
, rds_ring
, index
, STATUS_CKSUM_OK
);
1256 data_offset
= l4_hdr_offset
+ TCP_TS_HDR_SIZE
;
1258 data_offset
= l4_hdr_offset
+ TCP_HDR_SIZE
;
1260 skb_put(skb
, lro_length
+ data_offset
);
1262 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
) + skb_headroom(skb
);
1264 skb_pull(skb
, l2_hdr_offset
);
1265 skb
->protocol
= eth_type_trans(skb
, netdev
);
1267 iph
= (struct iphdr
*)skb
->data
;
1268 th
= (struct tcphdr
*)(skb
->data
+ (iph
->ihl
<< 2));
1270 length
= (iph
->ihl
<< 2) + (th
->doff
<< 2) + lro_length
;
1271 iph
->tot_len
= htons(length
);
1273 iph
->check
= ip_fast_csum((unsigned char *)iph
, iph
->ihl
);
1275 th
->seq
= htonl(seq_number
);
1279 netif_receive_skb(skb
);
1281 adapter
->stats
.lro_pkts
++;
1282 adapter
->stats
.rxbytes
+= length
;
1287 #define netxen_merge_rx_buffers(list, head) \
1288 do { list_splice_tail_init(list, head); } while (0);
1291 netxen_process_rcv_ring(struct nx_host_sds_ring
*sds_ring
, int max
)
1293 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
1295 struct list_head
*cur
;
1297 struct status_desc
*desc
;
1298 struct netxen_rx_buffer
*rxbuf
;
1300 u32 consumer
= sds_ring
->consumer
;
1303 u64 sts_data0
, sts_data1
;
1304 int opcode
, ring
= 0, desc_cnt
;
1306 while (count
< max
) {
1307 desc
= &sds_ring
->desc_head
[consumer
];
1308 sts_data0
= le64_to_cpu(desc
->status_desc_data
[0]);
1310 if (!(sts_data0
& STATUS_OWNER_HOST
))
1313 desc_cnt
= netxen_get_sts_desc_cnt(sts_data0
);
1315 opcode
= netxen_get_sts_opcode(sts_data0
);
1318 case NETXEN_NIC_RXPKT_DESC
:
1319 case NETXEN_OLD_RXPKT_DESC
:
1320 case NETXEN_NIC_SYN_OFFLOAD
:
1321 ring
= netxen_get_sts_type(sts_data0
);
1322 rxbuf
= netxen_process_rcv(adapter
, sds_ring
,
1325 case NETXEN_NIC_LRO_DESC
:
1326 ring
= netxen_get_lro_sts_type(sts_data0
);
1327 sts_data1
= le64_to_cpu(desc
->status_desc_data
[1]);
1328 rxbuf
= netxen_process_lro(adapter
, sds_ring
,
1329 ring
, sts_data0
, sts_data1
);
1331 case NETXEN_NIC_RESPONSE_DESC
:
1332 netxen_handle_fw_message(desc_cnt
, consumer
, sds_ring
);
1337 WARN_ON(desc_cnt
> 1);
1340 list_add_tail(&rxbuf
->list
, &sds_ring
->free_list
[ring
]);
1343 for (; desc_cnt
> 0; desc_cnt
--) {
1344 desc
= &sds_ring
->desc_head
[consumer
];
1345 desc
->status_desc_data
[0] =
1346 cpu_to_le64(STATUS_OWNER_PHANTOM
);
1347 consumer
= get_next_index(consumer
, sds_ring
->num_desc
);
1352 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1353 struct nx_host_rds_ring
*rds_ring
=
1354 &adapter
->recv_ctx
.rds_rings
[ring
];
1356 if (!list_empty(&sds_ring
->free_list
[ring
])) {
1357 list_for_each(cur
, &sds_ring
->free_list
[ring
]) {
1358 rxbuf
= list_entry(cur
,
1359 struct netxen_rx_buffer
, list
);
1360 netxen_alloc_rx_skb(adapter
, rds_ring
, rxbuf
);
1362 spin_lock(&rds_ring
->lock
);
1363 netxen_merge_rx_buffers(&sds_ring
->free_list
[ring
],
1364 &rds_ring
->free_list
);
1365 spin_unlock(&rds_ring
->lock
);
1368 netxen_post_rx_buffers_nodb(adapter
, rds_ring
);
1372 sds_ring
->consumer
= consumer
;
1373 NXWRIO(adapter
, sds_ring
->crb_sts_consumer
, consumer
);
1379 /* Process Command status ring */
1380 int netxen_process_cmd_ring(struct netxen_adapter
*adapter
)
1382 u32 sw_consumer
, hw_consumer
;
1384 struct netxen_cmd_buffer
*buffer
;
1385 struct pci_dev
*pdev
= adapter
->pdev
;
1386 struct net_device
*netdev
= adapter
->netdev
;
1387 struct netxen_skb_frag
*frag
;
1389 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1391 if (!spin_trylock(&adapter
->tx_clean_lock
))
1394 sw_consumer
= tx_ring
->sw_consumer
;
1395 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
1397 while (sw_consumer
!= hw_consumer
) {
1398 buffer
= &tx_ring
->cmd_buf_arr
[sw_consumer
];
1400 frag
= &buffer
->frag_array
[0];
1401 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
1404 for (i
= 1; i
< buffer
->frag_count
; i
++) {
1405 frag
++; /* Get the next frag */
1406 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
1411 adapter
->stats
.xmitfinished
++;
1412 dev_kfree_skb_any(buffer
->skb
);
1416 sw_consumer
= get_next_index(sw_consumer
, tx_ring
->num_desc
);
1417 if (++count
>= MAX_STATUS_HANDLE
)
1421 if (count
&& netif_running(netdev
)) {
1422 tx_ring
->sw_consumer
= sw_consumer
;
1426 if (netif_queue_stopped(netdev
) && netif_carrier_ok(netdev
)) {
1427 __netif_tx_lock(tx_ring
->txq
, smp_processor_id());
1428 if (netxen_tx_avail(tx_ring
) > TX_STOP_THRESH
) {
1429 netif_wake_queue(netdev
);
1430 adapter
->tx_timeo_cnt
= 0;
1432 __netif_tx_unlock(tx_ring
->txq
);
1436 * If everything is freed up to consumer then check if the ring is full
1437 * If the ring is full then check if more needs to be freed and
1438 * schedule the call back again.
1440 * This happens when there are 2 CPUs. One could be freeing and the
1441 * other filling it. If the ring is full when we get out of here and
1442 * the card has already interrupted the host then the host can miss the
1445 * There is still a possible race condition and the host could miss an
1446 * interrupt. The card has to take care of this.
1448 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
1449 done
= (sw_consumer
== hw_consumer
);
1450 spin_unlock(&adapter
->tx_clean_lock
);
1456 netxen_post_rx_buffers(struct netxen_adapter
*adapter
, u32 ringid
,
1457 struct nx_host_rds_ring
*rds_ring
)
1459 struct rcv_desc
*pdesc
;
1460 struct netxen_rx_buffer
*buffer
;
1461 int producer
, count
= 0;
1462 netxen_ctx_msg msg
= 0;
1463 struct list_head
*head
;
1465 producer
= rds_ring
->producer
;
1467 spin_lock(&rds_ring
->lock
);
1468 head
= &rds_ring
->free_list
;
1469 while (!list_empty(head
)) {
1471 buffer
= list_entry(head
->next
, struct netxen_rx_buffer
, list
);
1474 if (netxen_alloc_rx_skb(adapter
, rds_ring
, buffer
))
1479 list_del(&buffer
->list
);
1481 /* make a rcv descriptor */
1482 pdesc
= &rds_ring
->desc_head
[producer
];
1483 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1484 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1485 pdesc
->buffer_length
= cpu_to_le32(rds_ring
->dma_size
);
1487 producer
= get_next_index(producer
, rds_ring
->num_desc
);
1489 spin_unlock(&rds_ring
->lock
);
1492 rds_ring
->producer
= producer
;
1493 NXWRIO(adapter
, rds_ring
->crb_rcv_producer
,
1494 (producer
-1) & (rds_ring
->num_desc
-1));
1496 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1498 * Write a doorbell msg to tell phanmon of change in
1499 * receive ring producer
1500 * Only for firmware version < 4.0.0
1502 netxen_set_msg_peg_id(msg
, NETXEN_RCV_PEG_DB_ID
);
1503 netxen_set_msg_privid(msg
);
1504 netxen_set_msg_count(msg
,
1506 (rds_ring
->num_desc
- 1)));
1507 netxen_set_msg_ctxid(msg
, adapter
->portnum
);
1508 netxen_set_msg_opcode(msg
, NETXEN_RCV_PRODUCER(ringid
));
1509 read_lock(&adapter
->adapter_lock
);
1510 writel(msg
, DB_NORMALIZE(adapter
,
1511 NETXEN_RCV_PRODUCER_OFFSET
));
1512 read_unlock(&adapter
->adapter_lock
);
1518 netxen_post_rx_buffers_nodb(struct netxen_adapter
*adapter
,
1519 struct nx_host_rds_ring
*rds_ring
)
1521 struct rcv_desc
*pdesc
;
1522 struct netxen_rx_buffer
*buffer
;
1523 int producer
, count
= 0;
1524 struct list_head
*head
;
1526 producer
= rds_ring
->producer
;
1527 if (!spin_trylock(&rds_ring
->lock
))
1530 head
= &rds_ring
->free_list
;
1531 while (!list_empty(head
)) {
1533 buffer
= list_entry(head
->next
, struct netxen_rx_buffer
, list
);
1536 if (netxen_alloc_rx_skb(adapter
, rds_ring
, buffer
))
1541 list_del(&buffer
->list
);
1543 /* make a rcv descriptor */
1544 pdesc
= &rds_ring
->desc_head
[producer
];
1545 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1546 pdesc
->buffer_length
= cpu_to_le32(rds_ring
->dma_size
);
1547 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1549 producer
= get_next_index(producer
, rds_ring
->num_desc
);
1553 rds_ring
->producer
= producer
;
1554 NXWRIO(adapter
, rds_ring
->crb_rcv_producer
,
1555 (producer
- 1) & (rds_ring
->num_desc
- 1));
1557 spin_unlock(&rds_ring
->lock
);
1560 void netxen_nic_clear_stats(struct netxen_adapter
*adapter
)
1562 memset(&adapter
->stats
, 0, sizeof(adapter
->stats
));