2 * Copyright (C) 2003 - 2006 NetXen, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
23 * Contact Information:
26 * 3965 Freedom Circle, Fourth floor,
27 * Santa Clara, CA 95054
30 * Source file for NIC routines to initialize the Phantom Hardware
34 #include <linux/netdevice.h>
35 #include <linux/delay.h>
36 #include "netxen_nic.h"
37 #include "netxen_nic_hw.h"
38 #include "netxen_nic_phan_reg.h"
40 struct crb_addr_pair
{
45 #define NETXEN_MAX_CRB_XFORM 60
46 static unsigned int crb_addr_xform
[NETXEN_MAX_CRB_XFORM
];
47 #define NETXEN_ADDR_ERROR (0xffffffff)
49 #define crb_addr_transform(name) \
50 crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \
51 NETXEN_HW_CRB_HUB_AGT_ADR_##name << 20
53 #define NETXEN_NIC_XDMA_RESET 0x8000ff
55 static void netxen_post_rx_buffers_nodb(struct netxen_adapter
*adapter
,
56 uint32_t ctx
, uint32_t ringid
);
59 static void netxen_nic_locked_write_reg(struct netxen_adapter
*adapter
,
60 unsigned long off
, int *data
)
62 void __iomem
*addr
= pci_base_offset(adapter
, off
);
67 static void crb_addr_transform_setup(void)
69 crb_addr_transform(XDMA
);
70 crb_addr_transform(TIMR
);
71 crb_addr_transform(SRE
);
72 crb_addr_transform(SQN3
);
73 crb_addr_transform(SQN2
);
74 crb_addr_transform(SQN1
);
75 crb_addr_transform(SQN0
);
76 crb_addr_transform(SQS3
);
77 crb_addr_transform(SQS2
);
78 crb_addr_transform(SQS1
);
79 crb_addr_transform(SQS0
);
80 crb_addr_transform(RPMX7
);
81 crb_addr_transform(RPMX6
);
82 crb_addr_transform(RPMX5
);
83 crb_addr_transform(RPMX4
);
84 crb_addr_transform(RPMX3
);
85 crb_addr_transform(RPMX2
);
86 crb_addr_transform(RPMX1
);
87 crb_addr_transform(RPMX0
);
88 crb_addr_transform(ROMUSB
);
89 crb_addr_transform(SN
);
90 crb_addr_transform(QMN
);
91 crb_addr_transform(QMS
);
92 crb_addr_transform(PGNI
);
93 crb_addr_transform(PGND
);
94 crb_addr_transform(PGN3
);
95 crb_addr_transform(PGN2
);
96 crb_addr_transform(PGN1
);
97 crb_addr_transform(PGN0
);
98 crb_addr_transform(PGSI
);
99 crb_addr_transform(PGSD
);
100 crb_addr_transform(PGS3
);
101 crb_addr_transform(PGS2
);
102 crb_addr_transform(PGS1
);
103 crb_addr_transform(PGS0
);
104 crb_addr_transform(PS
);
105 crb_addr_transform(PH
);
106 crb_addr_transform(NIU
);
107 crb_addr_transform(I2Q
);
108 crb_addr_transform(EG
);
109 crb_addr_transform(MN
);
110 crb_addr_transform(MS
);
111 crb_addr_transform(CAS2
);
112 crb_addr_transform(CAS1
);
113 crb_addr_transform(CAS0
);
114 crb_addr_transform(CAM
);
115 crb_addr_transform(C2C1
);
116 crb_addr_transform(C2C0
);
117 crb_addr_transform(SMB
);
118 crb_addr_transform(OCM0
);
119 crb_addr_transform(I2C0
);
122 int netxen_init_firmware(struct netxen_adapter
*adapter
)
124 u32 state
= 0, loops
= 0, err
= 0;
127 state
= adapter
->pci_read_normalize(adapter
, CRB_CMDPEG_STATE
);
129 if (state
== PHAN_INITIALIZE_ACK
)
132 while (state
!= PHAN_INITIALIZE_COMPLETE
&& loops
< 2000) {
135 state
= adapter
->pci_read_normalize(adapter
, CRB_CMDPEG_STATE
);
140 printk(KERN_ERR
"Cmd Peg initialization not complete:%x.\n",
146 adapter
->pci_write_normalize(adapter
,
147 CRB_NIC_CAPABILITIES_HOST
, INTR_SCHEME_PERPORT
);
148 adapter
->pci_write_normalize(adapter
,
149 CRB_NIC_MSI_MODE_HOST
, MSI_MODE_MULTIFUNC
);
150 adapter
->pci_write_normalize(adapter
,
151 CRB_MPORT_MODE
, MPORT_MULTI_FUNCTION_MODE
);
152 adapter
->pci_write_normalize(adapter
,
153 CRB_CMDPEG_STATE
, PHAN_INITIALIZE_ACK
);
158 void netxen_release_rx_buffers(struct netxen_adapter
*adapter
)
160 struct netxen_recv_context
*recv_ctx
;
161 struct nx_host_rds_ring
*rds_ring
;
162 struct netxen_rx_buffer
*rx_buf
;
165 for (ctxid
= 0; ctxid
< MAX_RCV_CTX
; ++ctxid
) {
166 recv_ctx
= &adapter
->recv_ctx
[ctxid
];
167 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
168 rds_ring
= &recv_ctx
->rds_rings
[ring
];
169 for (i
= 0; i
< rds_ring
->max_rx_desc_count
; ++i
) {
170 rx_buf
= &(rds_ring
->rx_buf_arr
[i
]);
171 if (rx_buf
->state
== NETXEN_BUFFER_FREE
)
173 pci_unmap_single(adapter
->pdev
,
177 if (rx_buf
->skb
!= NULL
)
178 dev_kfree_skb_any(rx_buf
->skb
);
184 void netxen_release_tx_buffers(struct netxen_adapter
*adapter
)
186 struct netxen_cmd_buffer
*cmd_buf
;
187 struct netxen_skb_frag
*buffrag
;
190 cmd_buf
= adapter
->cmd_buf_arr
;
191 for (i
= 0; i
< adapter
->max_tx_desc_count
; i
++) {
192 buffrag
= cmd_buf
->frag_array
;
194 pci_unmap_single(adapter
->pdev
, buffrag
->dma
,
195 buffrag
->length
, PCI_DMA_TODEVICE
);
198 for (j
= 0; j
< cmd_buf
->frag_count
; j
++) {
201 pci_unmap_page(adapter
->pdev
, buffrag
->dma
,
207 /* Free the skb we received in netxen_nic_xmit_frame */
209 dev_kfree_skb_any(cmd_buf
->skb
);
216 void netxen_free_sw_resources(struct netxen_adapter
*adapter
)
218 struct netxen_recv_context
*recv_ctx
;
219 struct nx_host_rds_ring
*rds_ring
;
222 for (ctx
= 0; ctx
< MAX_RCV_CTX
; ctx
++) {
223 recv_ctx
= &adapter
->recv_ctx
[ctx
];
224 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
225 rds_ring
= &recv_ctx
->rds_rings
[ring
];
226 if (rds_ring
->rx_buf_arr
) {
227 vfree(rds_ring
->rx_buf_arr
);
228 rds_ring
->rx_buf_arr
= NULL
;
232 if (adapter
->cmd_buf_arr
)
233 vfree(adapter
->cmd_buf_arr
);
237 int netxen_alloc_sw_resources(struct netxen_adapter
*adapter
)
239 struct netxen_recv_context
*recv_ctx
;
240 struct nx_host_rds_ring
*rds_ring
;
241 struct netxen_rx_buffer
*rx_buf
;
242 int ctx
, ring
, i
, num_rx_bufs
;
244 struct netxen_cmd_buffer
*cmd_buf_arr
;
245 struct net_device
*netdev
= adapter
->netdev
;
247 cmd_buf_arr
= (struct netxen_cmd_buffer
*)vmalloc(TX_RINGSIZE
);
248 if (cmd_buf_arr
== NULL
) {
249 printk(KERN_ERR
"%s: Failed to allocate cmd buffer ring\n",
253 memset(cmd_buf_arr
, 0, TX_RINGSIZE
);
254 adapter
->cmd_buf_arr
= cmd_buf_arr
;
256 for (ctx
= 0; ctx
< MAX_RCV_CTX
; ctx
++) {
257 recv_ctx
= &adapter
->recv_ctx
[ctx
];
258 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
259 rds_ring
= &recv_ctx
->rds_rings
[ring
];
260 switch (RCV_DESC_TYPE(ring
)) {
261 case RCV_DESC_NORMAL
:
262 rds_ring
->max_rx_desc_count
=
263 adapter
->max_rx_desc_count
;
264 rds_ring
->flags
= RCV_DESC_NORMAL
;
265 if (adapter
->ahw
.cut_through
) {
267 NX_CT_DEFAULT_RX_BUF_LEN
;
269 NX_CT_DEFAULT_RX_BUF_LEN
;
271 rds_ring
->dma_size
= RX_DMA_MAP_LEN
;
273 MAX_RX_BUFFER_LENGTH
;
278 rds_ring
->max_rx_desc_count
=
279 adapter
->max_jumbo_rx_desc_count
;
280 rds_ring
->flags
= RCV_DESC_JUMBO
;
281 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
283 NX_P3_RX_JUMBO_BUF_MAX_LEN
;
286 NX_P2_RX_JUMBO_BUF_MAX_LEN
;
288 rds_ring
->dma_size
+ NET_IP_ALIGN
;
292 rds_ring
->max_rx_desc_count
=
293 adapter
->max_lro_rx_desc_count
;
294 rds_ring
->flags
= RCV_DESC_LRO
;
295 rds_ring
->dma_size
= RX_LRO_DMA_MAP_LEN
;
296 rds_ring
->skb_size
= MAX_RX_LRO_BUFFER_LENGTH
;
300 rds_ring
->rx_buf_arr
= (struct netxen_rx_buffer
*)
301 vmalloc(RCV_BUFFSIZE
);
302 if (rds_ring
->rx_buf_arr
== NULL
) {
303 printk(KERN_ERR
"%s: Failed to allocate "
304 "rx buffer ring %d\n",
306 /* free whatever was already allocated */
309 memset(rds_ring
->rx_buf_arr
, 0, RCV_BUFFSIZE
);
310 INIT_LIST_HEAD(&rds_ring
->free_list
);
311 rds_ring
->begin_alloc
= 0;
313 * Now go through all of them, set reference handles
314 * and put them in the queues.
316 num_rx_bufs
= rds_ring
->max_rx_desc_count
;
317 rx_buf
= rds_ring
->rx_buf_arr
;
318 for (i
= 0; i
< num_rx_bufs
; i
++) {
319 list_add_tail(&rx_buf
->list
,
320 &rds_ring
->free_list
);
321 rx_buf
->ref_handle
= i
;
322 rx_buf
->state
= NETXEN_BUFFER_FREE
;
331 netxen_free_sw_resources(adapter
);
335 void netxen_initialize_adapter_ops(struct netxen_adapter
*adapter
)
337 switch (adapter
->ahw
.board_type
) {
339 adapter
->enable_phy_interrupts
=
340 netxen_niu_gbe_enable_phy_interrupts
;
341 adapter
->disable_phy_interrupts
=
342 netxen_niu_gbe_disable_phy_interrupts
;
343 adapter
->macaddr_set
= netxen_niu_macaddr_set
;
344 adapter
->set_mtu
= netxen_nic_set_mtu_gb
;
345 adapter
->set_promisc
= netxen_niu_set_promiscuous_mode
;
346 adapter
->phy_read
= netxen_niu_gbe_phy_read
;
347 adapter
->phy_write
= netxen_niu_gbe_phy_write
;
348 adapter
->init_port
= netxen_niu_gbe_init_port
;
349 adapter
->stop_port
= netxen_niu_disable_gbe_port
;
352 case NETXEN_NIC_XGBE
:
353 adapter
->enable_phy_interrupts
=
354 netxen_niu_xgbe_enable_phy_interrupts
;
355 adapter
->disable_phy_interrupts
=
356 netxen_niu_xgbe_disable_phy_interrupts
;
357 adapter
->macaddr_set
= netxen_niu_xg_macaddr_set
;
358 adapter
->set_mtu
= netxen_nic_set_mtu_xgb
;
359 adapter
->init_port
= netxen_niu_xg_init_port
;
360 adapter
->set_promisc
= netxen_niu_xg_set_promiscuous_mode
;
361 adapter
->stop_port
= netxen_niu_disable_xg_port
;
368 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
369 adapter
->set_mtu
= nx_fw_cmd_set_mtu
;
370 adapter
->set_promisc
= netxen_p3_nic_set_promisc
;
375 * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB
376 * address to external PCI CRB address.
378 static u32
netxen_decode_crb_addr(u32 addr
)
381 u32 base_addr
, offset
, pci_base
;
383 crb_addr_transform_setup();
385 pci_base
= NETXEN_ADDR_ERROR
;
386 base_addr
= addr
& 0xfff00000;
387 offset
= addr
& 0x000fffff;
389 for (i
= 0; i
< NETXEN_MAX_CRB_XFORM
; i
++) {
390 if (crb_addr_xform
[i
] == base_addr
) {
395 if (pci_base
== NETXEN_ADDR_ERROR
)
398 return (pci_base
+ offset
);
401 static long rom_max_timeout
= 100;
402 static long rom_lock_timeout
= 10000;
404 static long rom_write_timeout
= 700;
407 static int rom_lock(struct netxen_adapter
*adapter
)
414 /* acquire semaphore2 from PCI HW block */
415 netxen_nic_read_w0(adapter
, NETXEN_PCIE_REG(PCIE_SEM2_LOCK
),
419 if (timeout
>= rom_lock_timeout
)
429 for (iter
= 0; iter
< 20; iter
++)
430 cpu_relax(); /*This a nop instr on i386 */
433 netxen_nic_reg_write(adapter
, NETXEN_ROM_LOCK_ID
, ROM_LOCK_DRIVER
);
437 static int netxen_wait_rom_done(struct netxen_adapter
*adapter
)
443 done
= netxen_nic_reg_read(adapter
, NETXEN_ROMUSB_GLB_STATUS
);
446 if (timeout
>= rom_max_timeout
) {
447 printk("Timeout reached waiting for rom done");
455 static int netxen_rom_wren(struct netxen_adapter
*adapter
)
457 /* Set write enable latch in ROM status register */
458 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 0);
459 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_INSTR_OPCODE
,
461 if (netxen_wait_rom_done(adapter
)) {
467 static unsigned int netxen_rdcrbreg(struct netxen_adapter
*adapter
,
470 unsigned int data
= 0xdeaddead;
471 data
= netxen_nic_reg_read(adapter
, addr
);
475 static int netxen_do_rom_rdsr(struct netxen_adapter
*adapter
)
477 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_INSTR_OPCODE
,
479 if (netxen_wait_rom_done(adapter
)) {
482 return netxen_rdcrbreg(adapter
, NETXEN_ROMUSB_ROM_RDATA
);
486 static void netxen_rom_unlock(struct netxen_adapter
*adapter
)
490 /* release semaphore2 */
491 netxen_nic_read_w0(adapter
, NETXEN_PCIE_REG(PCIE_SEM2_UNLOCK
), &val
);
496 static int netxen_rom_wip_poll(struct netxen_adapter
*adapter
)
501 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 0);
503 val
= netxen_do_rom_rdsr(adapter
);
506 if (timeout
> rom_max_timeout
) {
513 static int do_rom_fast_write(struct netxen_adapter
*adapter
, int addr
,
516 if (netxen_rom_wren(adapter
)) {
519 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_WDATA
, data
);
520 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ADDRESS
, addr
);
521 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 3);
522 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_INSTR_OPCODE
,
524 if (netxen_wait_rom_done(adapter
)) {
525 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 0);
529 return netxen_rom_wip_poll(adapter
);
533 static int do_rom_fast_read(struct netxen_adapter
*adapter
,
538 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ADDRESS
, addr
);
539 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 3);
540 udelay(100); /* prevent bursting on CRB */
541 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
542 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_INSTR_OPCODE
, 0xb);
543 if (netxen_wait_rom_done(adapter
)) {
544 printk("Error waiting for rom done\n");
547 /* reset abyte_cnt and dummy_byte_cnt */
548 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 0);
549 udelay(100); /* prevent bursting on CRB */
550 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
552 *valp
= netxen_nic_reg_read(adapter
, NETXEN_ROMUSB_ROM_RDATA
);
556 static int do_rom_fast_read_words(struct netxen_adapter
*adapter
, int addr
,
557 u8
*bytes
, size_t size
)
562 for (addridx
= addr
; addridx
< (addr
+ size
); addridx
+= 4) {
564 ret
= do_rom_fast_read(adapter
, addridx
, &v
);
567 *(__le32
*)bytes
= cpu_to_le32(v
);
575 netxen_rom_fast_read_words(struct netxen_adapter
*adapter
, int addr
,
576 u8
*bytes
, size_t size
)
580 ret
= rom_lock(adapter
);
584 ret
= do_rom_fast_read_words(adapter
, addr
, bytes
, size
);
586 netxen_rom_unlock(adapter
);
590 int netxen_rom_fast_read(struct netxen_adapter
*adapter
, int addr
, int *valp
)
594 if (rom_lock(adapter
) != 0)
597 ret
= do_rom_fast_read(adapter
, addr
, valp
);
598 netxen_rom_unlock(adapter
);
603 int netxen_rom_fast_write(struct netxen_adapter
*adapter
, int addr
, int data
)
607 if (rom_lock(adapter
) != 0) {
610 ret
= do_rom_fast_write(adapter
, addr
, data
);
611 netxen_rom_unlock(adapter
);
615 static int do_rom_fast_write_words(struct netxen_adapter
*adapter
,
616 int addr
, u8
*bytes
, size_t size
)
621 while (addridx
< (addr
+ size
)) {
622 int last_attempt
= 0;
626 data
= le32_to_cpu((*(__le32
*)bytes
));
627 ret
= do_rom_fast_write(adapter
, addridx
, data
);
634 ret
= do_rom_fast_read(adapter
, addridx
, &data1
);
641 if (timeout
++ >= rom_write_timeout
) {
642 if (last_attempt
++ < 4) {
643 ret
= do_rom_fast_write(adapter
,
649 printk(KERN_INFO
"Data write did not "
650 "succeed at address 0x%x\n", addridx
);
663 int netxen_rom_fast_write_words(struct netxen_adapter
*adapter
, int addr
,
664 u8
*bytes
, size_t size
)
668 ret
= rom_lock(adapter
);
672 ret
= do_rom_fast_write_words(adapter
, addr
, bytes
, size
);
673 netxen_rom_unlock(adapter
);
678 static int netxen_rom_wrsr(struct netxen_adapter
*adapter
, int data
)
682 ret
= netxen_rom_wren(adapter
);
686 netxen_crb_writelit_adapter(adapter
, NETXEN_ROMUSB_ROM_WDATA
, data
);
687 netxen_crb_writelit_adapter(adapter
,
688 NETXEN_ROMUSB_ROM_INSTR_OPCODE
, 0x1);
690 ret
= netxen_wait_rom_done(adapter
);
694 return netxen_rom_wip_poll(adapter
);
697 static int netxen_rom_rdsr(struct netxen_adapter
*adapter
)
701 ret
= rom_lock(adapter
);
705 ret
= netxen_do_rom_rdsr(adapter
);
706 netxen_rom_unlock(adapter
);
710 int netxen_backup_crbinit(struct netxen_adapter
*adapter
)
712 int ret
= FLASH_SUCCESS
;
714 char *buffer
= kmalloc(NETXEN_FLASH_SECTOR_SIZE
, GFP_KERNEL
);
718 /* unlock sector 63 */
719 val
= netxen_rom_rdsr(adapter
);
721 ret
= netxen_rom_wrsr(adapter
, val
);
722 if (ret
!= FLASH_SUCCESS
)
725 ret
= netxen_rom_wip_poll(adapter
);
726 if (ret
!= FLASH_SUCCESS
)
729 /* copy sector 0 to sector 63 */
730 ret
= netxen_rom_fast_read_words(adapter
, NETXEN_CRBINIT_START
,
731 buffer
, NETXEN_FLASH_SECTOR_SIZE
);
732 if (ret
!= FLASH_SUCCESS
)
735 ret
= netxen_rom_fast_write_words(adapter
, NETXEN_FIXED_START
,
736 buffer
, NETXEN_FLASH_SECTOR_SIZE
);
737 if (ret
!= FLASH_SUCCESS
)
741 val
= netxen_rom_rdsr(adapter
);
745 if (netxen_rom_wrsr(adapter
, val
) == 0) {
746 ret
= netxen_rom_wip_poll(adapter
);
747 if (ret
!= FLASH_SUCCESS
)
751 ret
= netxen_rom_wip_poll(adapter
);
752 if (ret
!= FLASH_SUCCESS
)
762 static int netxen_do_rom_se(struct netxen_adapter
*adapter
, int addr
)
764 netxen_rom_wren(adapter
);
765 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ADDRESS
, addr
);
766 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 3);
767 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_INSTR_OPCODE
,
769 if (netxen_wait_rom_done(adapter
)) {
770 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 0);
773 return netxen_rom_wip_poll(adapter
);
776 static void check_erased_flash(struct netxen_adapter
*adapter
, int addr
)
780 int count
= 0, erased_errors
= 0;
783 range
= (addr
== NETXEN_USER_START
) ?
784 NETXEN_FIXED_START
: addr
+ NETXEN_FLASH_SECTOR_SIZE
;
786 for (i
= addr
; i
< range
; i
+= 4) {
787 netxen_rom_fast_read(adapter
, i
, &val
);
788 if (val
!= 0xffffffff)
794 printk(KERN_INFO
"0x%x out of 0x%x words fail to be erased "
795 "for sector address: %x\n", erased_errors
, count
, addr
);
798 int netxen_rom_se(struct netxen_adapter
*adapter
, int addr
)
801 if (rom_lock(adapter
) != 0) {
804 ret
= netxen_do_rom_se(adapter
, addr
);
805 netxen_rom_unlock(adapter
);
807 check_erased_flash(adapter
, addr
);
812 static int netxen_flash_erase_sections(struct netxen_adapter
*adapter
,
815 int ret
= FLASH_SUCCESS
;
818 for (i
= start
; i
< end
; i
++) {
819 ret
= netxen_rom_se(adapter
, i
* NETXEN_FLASH_SECTOR_SIZE
);
822 ret
= netxen_rom_wip_poll(adapter
);
831 netxen_flash_erase_secondary(struct netxen_adapter
*adapter
)
833 int ret
= FLASH_SUCCESS
;
836 start
= NETXEN_SECONDARY_START
/ NETXEN_FLASH_SECTOR_SIZE
;
837 end
= NETXEN_USER_START
/ NETXEN_FLASH_SECTOR_SIZE
;
838 ret
= netxen_flash_erase_sections(adapter
, start
, end
);
844 netxen_flash_erase_primary(struct netxen_adapter
*adapter
)
846 int ret
= FLASH_SUCCESS
;
849 start
= NETXEN_PRIMARY_START
/ NETXEN_FLASH_SECTOR_SIZE
;
850 end
= NETXEN_SECONDARY_START
/ NETXEN_FLASH_SECTOR_SIZE
;
851 ret
= netxen_flash_erase_sections(adapter
, start
, end
);
856 void netxen_halt_pegs(struct netxen_adapter
*adapter
)
858 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_0
+ 0x3c, 1);
859 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_1
+ 0x3c, 1);
860 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_2
+ 0x3c, 1);
861 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_3
+ 0x3c, 1);
864 int netxen_flash_unlock(struct netxen_adapter
*adapter
)
868 ret
= netxen_rom_wrsr(adapter
, 0);
872 ret
= netxen_rom_wren(adapter
);
880 #define NETXEN_BOARDTYPE 0x4008
881 #define NETXEN_BOARDNUM 0x400c
882 #define NETXEN_CHIPNUM 0x4010
884 int netxen_pinit_from_rom(struct netxen_adapter
*adapter
, int verbose
)
887 int i
, init_delay
= 0;
888 struct crb_addr_pair
*buf
;
893 netxen_crb_writelit_adapter(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
,
897 if (netxen_rom_fast_read(adapter
, NETXEN_BOARDTYPE
, &val
) == 0)
898 printk("P2 ROM board type: 0x%08x\n", val
);
900 printk("Could not read board type\n");
901 if (netxen_rom_fast_read(adapter
, NETXEN_BOARDNUM
, &val
) == 0)
902 printk("P2 ROM board num: 0x%08x\n", val
);
904 printk("Could not read board number\n");
905 if (netxen_rom_fast_read(adapter
, NETXEN_CHIPNUM
, &val
) == 0)
906 printk("P2 ROM chip num: 0x%08x\n", val
);
908 printk("Could not read chip number\n");
911 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
912 if (netxen_rom_fast_read(adapter
, 0, &n
) != 0 ||
913 (n
!= 0xcafecafeUL
) ||
914 netxen_rom_fast_read(adapter
, 4, &n
) != 0) {
915 printk(KERN_ERR
"%s: ERROR Reading crb_init area: "
916 "n: %08x\n", netxen_nic_driver_name
, n
);
919 offset
= n
& 0xffffU
;
920 n
= (n
>> 16) & 0xffffU
;
922 if (netxen_rom_fast_read(adapter
, 0, &n
) != 0 ||
924 printk(KERN_ERR
"%s: ERROR Reading crb_init area: "
925 "n: %08x\n", netxen_nic_driver_name
, n
);
934 printk(KERN_DEBUG
"%s: %d CRB init values found"
935 " in ROM.\n", netxen_nic_driver_name
, n
);
937 printk(KERN_ERR
"%s:n=0x%x Error! NetXen card flash not"
938 " initialized.\n", __func__
, n
);
942 buf
= kcalloc(n
, sizeof(struct crb_addr_pair
), GFP_KERNEL
);
944 printk("%s: netxen_pinit_from_rom: Unable to calloc memory.\n",
945 netxen_nic_driver_name
);
948 for (i
= 0; i
< n
; i
++) {
949 if (netxen_rom_fast_read(adapter
, 8*i
+ 4*offset
, &val
) != 0 ||
950 netxen_rom_fast_read(adapter
, 8*i
+ 4*offset
+ 4, &addr
) != 0)
957 printk(KERN_DEBUG
"%s: PCI: 0x%08x == 0x%08x\n",
958 netxen_nic_driver_name
,
959 (u32
)netxen_decode_crb_addr(addr
), val
);
961 for (i
= 0; i
< n
; i
++) {
963 off
= netxen_decode_crb_addr(buf
[i
].addr
);
964 if (off
== NETXEN_ADDR_ERROR
) {
965 printk(KERN_ERR
"CRB init value out of range %x\n",
969 off
+= NETXEN_PCI_CRBSPACE
;
970 /* skipping cold reboot MAGIC */
971 if (off
== NETXEN_CAM_RAM(0x1fc))
974 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
975 /* do not reset PCI */
976 if (off
== (ROMUSB_GLB
+ 0xbc))
978 if (off
== (NETXEN_CRB_PEG_NET_1
+ 0x18))
979 buf
[i
].data
= 0x1020;
980 /* skip the function enable register */
981 if (off
== NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION
))
983 if (off
== NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION2
))
985 if ((off
& 0x0ff00000) == NETXEN_CRB_SMB
)
989 if (off
== NETXEN_ADDR_ERROR
) {
990 printk(KERN_ERR
"%s: Err: Unknown addr: 0x%08x\n",
991 netxen_nic_driver_name
, buf
[i
].addr
);
995 /* After writing this register, HW needs time for CRB */
996 /* to quiet down (else crb_window returns 0xffffffff) */
997 if (off
== NETXEN_ROMUSB_GLB_SW_RESET
) {
999 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1000 /* hold xdma in reset also */
1001 buf
[i
].data
= NETXEN_NIC_XDMA_RESET
;
1005 adapter
->hw_write_wx(adapter
, off
, &buf
[i
].data
, 4);
1007 if (init_delay
== 1) {
1015 /* disable_peg_cache_all */
1017 /* unreset_net_cache */
1018 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1019 adapter
->hw_read_wx(adapter
,
1020 NETXEN_ROMUSB_GLB_SW_RESET
, &val
, 4);
1021 netxen_crb_writelit_adapter(adapter
,
1022 NETXEN_ROMUSB_GLB_SW_RESET
, (val
& 0xffffff0f));
1025 /* p2dn replyCount */
1026 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_D
+ 0xec, 0x1e);
1027 /* disable_peg_cache 0 */
1028 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_D
+ 0x4c, 8);
1029 /* disable_peg_cache 1 */
1030 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_I
+ 0x4c, 8);
1035 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_0
+ 0x8, 0);
1036 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_0
+ 0xc, 0);
1038 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_1
+ 0x8, 0);
1039 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_1
+ 0xc, 0);
1041 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_2
+ 0x8, 0);
1042 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_2
+ 0xc, 0);
1044 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_3
+ 0x8, 0);
1045 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_3
+ 0xc, 0);
1049 int netxen_initialize_adapter_offload(struct netxen_adapter
*adapter
)
1055 adapter
->dummy_dma
.addr
=
1056 pci_alloc_consistent(adapter
->pdev
,
1057 NETXEN_HOST_DUMMY_DMA_SIZE
,
1058 &adapter
->dummy_dma
.phys_addr
);
1059 if (adapter
->dummy_dma
.addr
== NULL
) {
1060 printk("%s: ERROR: Could not allocate dummy DMA memory\n",
1065 addr
= (uint64_t) adapter
->dummy_dma
.phys_addr
;
1066 hi
= (addr
>> 32) & 0xffffffff;
1067 lo
= addr
& 0xffffffff;
1069 adapter
->pci_write_normalize(adapter
, CRB_HOST_DUMMY_BUF_ADDR_HI
, hi
);
1070 adapter
->pci_write_normalize(adapter
, CRB_HOST_DUMMY_BUF_ADDR_LO
, lo
);
1072 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
1074 adapter
->hw_write_wx(adapter
, CRB_HOST_DUMMY_BUF
, &temp
, 4);
1080 void netxen_free_adapter_offload(struct netxen_adapter
*adapter
)
1084 if (!adapter
->dummy_dma
.addr
)
1087 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1089 if (dma_watchdog_shutdown_request(adapter
) == 1)
1092 if (dma_watchdog_shutdown_poll_result(adapter
) == 1)
1098 pci_free_consistent(adapter
->pdev
,
1099 NETXEN_HOST_DUMMY_DMA_SIZE
,
1100 adapter
->dummy_dma
.addr
,
1101 adapter
->dummy_dma
.phys_addr
);
1102 adapter
->dummy_dma
.addr
= NULL
;
1104 printk(KERN_ERR
"%s: dma_watchdog_shutdown failed\n",
1105 adapter
->netdev
->name
);
1109 int netxen_phantom_init(struct netxen_adapter
*adapter
, int pegtune_val
)
1116 val
= adapter
->pci_read_normalize(adapter
,
1119 if (val
== PHAN_INITIALIZE_COMPLETE
||
1120 val
== PHAN_INITIALIZE_ACK
)
1125 } while (--retries
);
1128 pegtune_val
= adapter
->pci_read_normalize(adapter
,
1129 NETXEN_ROMUSB_GLB_PEGTUNE_DONE
);
1130 printk(KERN_WARNING
"netxen_phantom_init: init failed, "
1131 "pegtune_val=%x\n", pegtune_val
);
1139 int netxen_receive_peg_ready(struct netxen_adapter
*adapter
)
1145 val
= adapter
->pci_read_normalize(adapter
, CRB_RCVPEG_STATE
);
1147 if (val
== PHAN_PEG_RCV_INITIALIZED
)
1152 } while (--retries
);
1155 printk(KERN_ERR
"Receive Peg initialization not "
1156 "complete, state: 0x%x.\n", val
);
1163 static struct sk_buff
*netxen_process_rxbuf(struct netxen_adapter
*adapter
,
1164 struct nx_host_rds_ring
*rds_ring
, u16 index
, u16 cksum
)
1166 struct netxen_rx_buffer
*buffer
;
1167 struct sk_buff
*skb
;
1169 buffer
= &rds_ring
->rx_buf_arr
[index
];
1171 pci_unmap_single(adapter
->pdev
, buffer
->dma
, rds_ring
->dma_size
,
1172 PCI_DMA_FROMDEVICE
);
1178 if (likely(adapter
->rx_csum
&& cksum
== STATUS_CKSUM_OK
)) {
1179 adapter
->stats
.csummed
++;
1180 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1182 skb
->ip_summed
= CHECKSUM_NONE
;
1184 skb
->dev
= adapter
->netdev
;
1189 buffer
->state
= NETXEN_BUFFER_FREE
;
1190 buffer
->lro_current_frags
= 0;
1191 buffer
->lro_expected_frags
= 0;
1192 list_add_tail(&buffer
->list
, &rds_ring
->free_list
);
1197 * netxen_process_rcv() send the received packet to the protocol stack.
1198 * and if the number of receives exceeds RX_BUFFERS_REFILL, then we
1199 * invoke the routine to send more rx buffers to the Phantom...
1201 static void netxen_process_rcv(struct netxen_adapter
*adapter
, int ctxid
,
1202 struct status_desc
*desc
, struct status_desc
*frag_desc
)
1204 struct net_device
*netdev
= adapter
->netdev
;
1205 u64 sts_data
= le64_to_cpu(desc
->status_desc_data
);
1206 int index
= netxen_get_sts_refhandle(sts_data
);
1207 struct netxen_recv_context
*recv_ctx
= &(adapter
->recv_ctx
[ctxid
]);
1208 struct netxen_rx_buffer
*buffer
;
1209 struct sk_buff
*skb
;
1210 u32 length
= netxen_get_sts_totallength(sts_data
);
1212 u16 pkt_offset
= 0, cksum
;
1213 struct nx_host_rds_ring
*rds_ring
;
1215 desc_ctx
= netxen_get_sts_type(sts_data
);
1216 if (unlikely(desc_ctx
>= NUM_RCV_DESC_RINGS
)) {
1217 printk("%s: %s Bad Rcv descriptor ring\n",
1218 netxen_nic_driver_name
, netdev
->name
);
1222 rds_ring
= &recv_ctx
->rds_rings
[desc_ctx
];
1223 if (unlikely(index
> rds_ring
->max_rx_desc_count
)) {
1224 DPRINTK(ERR
, "Got a buffer index:%x Max is %x\n",
1225 index
, rds_ring
->max_rx_desc_count
);
1228 buffer
= &rds_ring
->rx_buf_arr
[index
];
1229 if (desc_ctx
== RCV_DESC_LRO_CTXID
) {
1230 buffer
->lro_current_frags
++;
1231 if (netxen_get_sts_desc_lro_last_frag(desc
)) {
1232 buffer
->lro_expected_frags
=
1233 netxen_get_sts_desc_lro_cnt(desc
);
1234 buffer
->lro_length
= length
;
1236 if (buffer
->lro_current_frags
!= buffer
->lro_expected_frags
) {
1237 if (buffer
->lro_expected_frags
!= 0) {
1238 printk("LRO: (refhandle:%x) recv frag. "
1239 "wait for last. flags: %x expected:%d "
1241 netxen_get_sts_desc_lro_last_frag(desc
),
1242 buffer
->lro_expected_frags
,
1243 buffer
->lro_current_frags
);
1249 cksum
= netxen_get_sts_status(sts_data
);
1251 skb
= netxen_process_rxbuf(adapter
, rds_ring
, index
, cksum
);
1255 if (desc_ctx
== RCV_DESC_LRO_CTXID
) {
1256 /* True length was only available on the last pkt */
1257 skb_put(skb
, buffer
->lro_length
);
1259 if (length
> rds_ring
->skb_size
)
1260 skb_put(skb
, rds_ring
->skb_size
);
1262 skb_put(skb
, length
);
1264 pkt_offset
= netxen_get_sts_pkt_offset(sts_data
);
1266 skb_pull(skb
, pkt_offset
);
1269 skb
->protocol
= eth_type_trans(skb
, netdev
);
1272 * rx buffer chaining is disabled, walk and free
1273 * any spurious rx buffer chain.
1276 u16 i
, nr_frags
= desc
->nr_frags
;
1278 dev_kfree_skb_any(skb
);
1279 for (i
= 0; i
< nr_frags
; i
++) {
1280 index
= frag_desc
->frag_handles
[i
];
1281 skb
= netxen_process_rxbuf(adapter
,
1282 rds_ring
, index
, cksum
);
1284 dev_kfree_skb_any(skb
);
1286 adapter
->stats
.rxdropped
++;
1288 netif_receive_skb(skb
);
1290 adapter
->stats
.no_rcv
++;
1291 adapter
->stats
.rxbytes
+= length
;
1295 /* Process Receive status ring */
1296 u32
netxen_process_rcv_ring(struct netxen_adapter
*adapter
, int ctxid
, int max
)
1298 struct netxen_recv_context
*recv_ctx
= &(adapter
->recv_ctx
[ctxid
]);
1299 struct status_desc
*desc_head
= recv_ctx
->rcv_status_desc_head
;
1300 struct status_desc
*desc
, *frag_desc
;
1301 u32 consumer
= recv_ctx
->status_rx_consumer
;
1302 int count
= 0, ring
;
1306 while (count
< max
) {
1307 desc
= &desc_head
[consumer
];
1308 if (!(netxen_get_sts_owner(desc
) & STATUS_OWNER_HOST
)) {
1309 DPRINTK(ERR
, "desc %p ownedby %x\n", desc
,
1310 netxen_get_sts_owner(desc
));
1314 sts_data
= le64_to_cpu(desc
->status_desc_data
);
1315 opcode
= netxen_get_sts_opcode(sts_data
);
1317 if (opcode
== NETXEN_NIC_RXPKT_DESC
) {
1318 if (desc
->nr_frags
) {
1319 consumer
= get_next_index(consumer
,
1320 adapter
->max_rx_desc_count
);
1321 frag_desc
= &desc_head
[consumer
];
1322 netxen_set_sts_owner(frag_desc
,
1323 STATUS_OWNER_PHANTOM
);
1327 netxen_process_rcv(adapter
, ctxid
, desc
, frag_desc
);
1329 netxen_set_sts_owner(desc
, STATUS_OWNER_PHANTOM
);
1331 consumer
= get_next_index(consumer
,
1332 adapter
->max_rx_desc_count
);
1335 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++)
1336 netxen_post_rx_buffers_nodb(adapter
, ctxid
, ring
);
1338 /* update the consumer index in phantom */
1340 recv_ctx
->status_rx_consumer
= consumer
;
1343 adapter
->pci_write_normalize(adapter
,
1344 recv_ctx
->crb_sts_consumer
, consumer
);
1350 /* Process Command status ring */
1351 int netxen_process_cmd_ring(struct netxen_adapter
*adapter
)
1353 u32 last_consumer
, consumer
;
1355 struct netxen_cmd_buffer
*buffer
;
1356 struct pci_dev
*pdev
= adapter
->pdev
;
1357 struct net_device
*netdev
= adapter
->netdev
;
1358 struct netxen_skb_frag
*frag
;
1361 last_consumer
= adapter
->last_cmd_consumer
;
1362 consumer
= le32_to_cpu(*(adapter
->cmd_consumer
));
1364 while (last_consumer
!= consumer
) {
1365 buffer
= &adapter
->cmd_buf_arr
[last_consumer
];
1367 frag
= &buffer
->frag_array
[0];
1368 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
1371 for (i
= 1; i
< buffer
->frag_count
; i
++) {
1372 frag
++; /* Get the next frag */
1373 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
1378 adapter
->stats
.xmitfinished
++;
1379 dev_kfree_skb_any(buffer
->skb
);
1383 last_consumer
= get_next_index(last_consumer
,
1384 adapter
->max_tx_desc_count
);
1385 if (++count
>= MAX_STATUS_HANDLE
)
1390 adapter
->last_cmd_consumer
= last_consumer
;
1392 if (netif_queue_stopped(netdev
) && netif_running(netdev
)) {
1393 netif_tx_lock(netdev
);
1394 netif_wake_queue(netdev
);
1396 netif_tx_unlock(netdev
);
1400 * If everything is freed up to consumer then check if the ring is full
1401 * If the ring is full then check if more needs to be freed and
1402 * schedule the call back again.
1404 * This happens when there are 2 CPUs. One could be freeing and the
1405 * other filling it. If the ring is full when we get out of here and
1406 * the card has already interrupted the host then the host can miss the
1409 * There is still a possible race condition and the host could miss an
1410 * interrupt. The card has to take care of this.
1412 consumer
= le32_to_cpu(*(adapter
->cmd_consumer
));
1413 done
= (last_consumer
== consumer
);
1419 * netxen_post_rx_buffers puts buffer in the Phantom memory
1421 void netxen_post_rx_buffers(struct netxen_adapter
*adapter
, u32 ctx
, u32 ringid
)
1423 struct pci_dev
*pdev
= adapter
->pdev
;
1424 struct sk_buff
*skb
;
1425 struct netxen_recv_context
*recv_ctx
= &(adapter
->recv_ctx
[ctx
]);
1426 struct nx_host_rds_ring
*rds_ring
= NULL
;
1428 struct rcv_desc
*pdesc
;
1429 struct netxen_rx_buffer
*buffer
;
1432 netxen_ctx_msg msg
= 0;
1434 struct list_head
*head
;
1436 rds_ring
= &recv_ctx
->rds_rings
[ringid
];
1438 producer
= rds_ring
->producer
;
1439 index
= rds_ring
->begin_alloc
;
1440 head
= &rds_ring
->free_list
;
1442 /* We can start writing rx descriptors into the phantom memory. */
1443 while (!list_empty(head
)) {
1445 skb
= dev_alloc_skb(rds_ring
->skb_size
);
1446 if (unlikely(!skb
)) {
1447 rds_ring
->begin_alloc
= index
;
1451 buffer
= list_entry(head
->next
, struct netxen_rx_buffer
, list
);
1452 list_del(&buffer
->list
);
1454 count
++; /* now there should be no failure */
1455 pdesc
= &rds_ring
->desc_head
[producer
];
1457 if (!adapter
->ahw
.cut_through
)
1458 skb_reserve(skb
, 2);
1459 /* This will be setup when we receive the
1460 * buffer after it has been filled FSL TBD TBD
1461 * skb->dev = netdev;
1463 dma
= pci_map_single(pdev
, skb
->data
, rds_ring
->dma_size
,
1464 PCI_DMA_FROMDEVICE
);
1465 pdesc
->addr_buffer
= cpu_to_le64(dma
);
1467 buffer
->state
= NETXEN_BUFFER_BUSY
;
1469 /* make a rcv descriptor */
1470 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1471 pdesc
->buffer_length
= cpu_to_le32(rds_ring
->dma_size
);
1472 DPRINTK(INFO
, "done writing descripter\n");
1474 get_next_index(producer
, rds_ring
->max_rx_desc_count
);
1475 index
= get_next_index(index
, rds_ring
->max_rx_desc_count
);
1477 /* if we did allocate buffers, then write the count to Phantom */
1479 rds_ring
->begin_alloc
= index
;
1480 rds_ring
->producer
= producer
;
1482 adapter
->pci_write_normalize(adapter
,
1483 rds_ring
->crb_rcv_producer
,
1484 (producer
-1) & (rds_ring
->max_rx_desc_count
-1));
1486 if (adapter
->fw_major
< 4) {
1488 * Write a doorbell msg to tell phanmon of change in
1489 * receive ring producer
1490 * Only for firmware version < 4.0.0
1492 netxen_set_msg_peg_id(msg
, NETXEN_RCV_PEG_DB_ID
);
1493 netxen_set_msg_privid(msg
);
1494 netxen_set_msg_count(msg
,
1497 max_rx_desc_count
- 1)));
1498 netxen_set_msg_ctxid(msg
, adapter
->portnum
);
1499 netxen_set_msg_opcode(msg
, NETXEN_RCV_PRODUCER(ringid
));
1501 DB_NORMALIZE(adapter
,
1502 NETXEN_RCV_PRODUCER_OFFSET
));
1507 static void netxen_post_rx_buffers_nodb(struct netxen_adapter
*adapter
,
1508 uint32_t ctx
, uint32_t ringid
)
1510 struct pci_dev
*pdev
= adapter
->pdev
;
1511 struct sk_buff
*skb
;
1512 struct netxen_recv_context
*recv_ctx
= &(adapter
->recv_ctx
[ctx
]);
1513 struct nx_host_rds_ring
*rds_ring
= NULL
;
1515 struct rcv_desc
*pdesc
;
1516 struct netxen_rx_buffer
*buffer
;
1519 struct list_head
*head
;
1521 rds_ring
= &recv_ctx
->rds_rings
[ringid
];
1523 producer
= rds_ring
->producer
;
1524 index
= rds_ring
->begin_alloc
;
1525 head
= &rds_ring
->free_list
;
1526 /* We can start writing rx descriptors into the phantom memory. */
1527 while (!list_empty(head
)) {
1529 skb
= dev_alloc_skb(rds_ring
->skb_size
);
1530 if (unlikely(!skb
)) {
1531 rds_ring
->begin_alloc
= index
;
1535 buffer
= list_entry(head
->next
, struct netxen_rx_buffer
, list
);
1536 list_del(&buffer
->list
);
1538 count
++; /* now there should be no failure */
1539 pdesc
= &rds_ring
->desc_head
[producer
];
1540 if (!adapter
->ahw
.cut_through
)
1541 skb_reserve(skb
, 2);
1543 buffer
->state
= NETXEN_BUFFER_BUSY
;
1544 buffer
->dma
= pci_map_single(pdev
, skb
->data
,
1546 PCI_DMA_FROMDEVICE
);
1548 /* make a rcv descriptor */
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 get_next_index(producer
, rds_ring
->max_rx_desc_count
);
1554 index
= get_next_index(index
, rds_ring
->max_rx_desc_count
);
1555 buffer
= &rds_ring
->rx_buf_arr
[index
];
1558 /* if we did allocate buffers, then write the count to Phantom */
1560 rds_ring
->begin_alloc
= index
;
1561 rds_ring
->producer
= producer
;
1563 adapter
->pci_write_normalize(adapter
,
1564 rds_ring
->crb_rcv_producer
,
1565 (producer
-1) & (rds_ring
->max_rx_desc_count
-1));
1570 void netxen_nic_clear_stats(struct netxen_adapter
*adapter
)
1572 memset(&adapter
->stats
, 0, sizeof(adapter
->stats
));