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 unsigned long last_schedule_time
;
47 #define NETXEN_MAX_CRB_XFORM 60
48 static unsigned int crb_addr_xform
[NETXEN_MAX_CRB_XFORM
];
49 #define NETXEN_ADDR_ERROR (0xffffffff)
51 #define crb_addr_transform(name) \
52 crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \
53 NETXEN_HW_CRB_HUB_AGT_ADR_##name << 20
55 #define NETXEN_NIC_XDMA_RESET 0x8000ff
58 netxen_nic_locked_write_reg(struct netxen_adapter
*adapter
,
59 unsigned long off
, int *data
)
61 void __iomem
*addr
= pci_base_offset(adapter
, off
);
65 static void crb_addr_transform_setup(void)
67 crb_addr_transform(XDMA
);
68 crb_addr_transform(TIMR
);
69 crb_addr_transform(SRE
);
70 crb_addr_transform(SQN3
);
71 crb_addr_transform(SQN2
);
72 crb_addr_transform(SQN1
);
73 crb_addr_transform(SQN0
);
74 crb_addr_transform(SQS3
);
75 crb_addr_transform(SQS2
);
76 crb_addr_transform(SQS1
);
77 crb_addr_transform(SQS0
);
78 crb_addr_transform(RPMX7
);
79 crb_addr_transform(RPMX6
);
80 crb_addr_transform(RPMX5
);
81 crb_addr_transform(RPMX4
);
82 crb_addr_transform(RPMX3
);
83 crb_addr_transform(RPMX2
);
84 crb_addr_transform(RPMX1
);
85 crb_addr_transform(RPMX0
);
86 crb_addr_transform(ROMUSB
);
87 crb_addr_transform(SN
);
88 crb_addr_transform(QMN
);
89 crb_addr_transform(QMS
);
90 crb_addr_transform(PGNI
);
91 crb_addr_transform(PGND
);
92 crb_addr_transform(PGN3
);
93 crb_addr_transform(PGN2
);
94 crb_addr_transform(PGN1
);
95 crb_addr_transform(PGN0
);
96 crb_addr_transform(PGSI
);
97 crb_addr_transform(PGSD
);
98 crb_addr_transform(PGS3
);
99 crb_addr_transform(PGS2
);
100 crb_addr_transform(PGS1
);
101 crb_addr_transform(PGS0
);
102 crb_addr_transform(PS
);
103 crb_addr_transform(PH
);
104 crb_addr_transform(NIU
);
105 crb_addr_transform(I2Q
);
106 crb_addr_transform(EG
);
107 crb_addr_transform(MN
);
108 crb_addr_transform(MS
);
109 crb_addr_transform(CAS2
);
110 crb_addr_transform(CAS1
);
111 crb_addr_transform(CAS0
);
112 crb_addr_transform(CAM
);
113 crb_addr_transform(C2C1
);
114 crb_addr_transform(C2C0
);
115 crb_addr_transform(SMB
);
118 int netxen_init_firmware(struct netxen_adapter
*adapter
)
120 u32 state
= 0, loops
= 0, err
= 0;
123 state
= readl(NETXEN_CRB_NORMALIZE(adapter
, CRB_CMDPEG_STATE
));
125 if (state
== PHAN_INITIALIZE_ACK
)
128 while (state
!= PHAN_INITIALIZE_COMPLETE
&& loops
< 2000) {
131 state
= readl(NETXEN_CRB_NORMALIZE(adapter
, CRB_CMDPEG_STATE
));
136 printk(KERN_ERR
"Cmd Peg initialization not complete:%x.\n",
142 writel(INTR_SCHEME_PERPORT
,
143 NETXEN_CRB_NORMALIZE(adapter
, CRB_NIC_CAPABILITIES_HOST
));
144 writel(MPORT_MULTI_FUNCTION_MODE
,
145 NETXEN_CRB_NORMALIZE(adapter
, CRB_MPORT_MODE
));
146 writel(PHAN_INITIALIZE_ACK
,
147 NETXEN_CRB_NORMALIZE(adapter
, CRB_CMDPEG_STATE
));
152 #define NETXEN_ADDR_LIMIT 0xffffffffULL
154 void *netxen_alloc(struct pci_dev
*pdev
, size_t sz
, dma_addr_t
* ptr
,
155 struct pci_dev
**used_dev
)
159 addr
= pci_alloc_consistent(pdev
, sz
, ptr
);
160 if ((unsigned long long)(*ptr
) < NETXEN_ADDR_LIMIT
) {
164 pci_free_consistent(pdev
, sz
, addr
, *ptr
);
165 addr
= pci_alloc_consistent(NULL
, sz
, ptr
);
170 void netxen_initialize_adapter_sw(struct netxen_adapter
*adapter
)
175 struct netxen_rcv_desc_ctx
*rcv_desc
;
177 DPRINTK(INFO
, "initializing some queues: %p\n", adapter
);
178 for (ctxid
= 0; ctxid
< MAX_RCV_CTX
; ++ctxid
) {
179 for (ring
= 0; ring
< NUM_RCV_DESC_RINGS
; ring
++) {
180 struct netxen_rx_buffer
*rx_buf
;
181 rcv_desc
= &adapter
->recv_ctx
[ctxid
].rcv_desc
[ring
];
182 rcv_desc
->rcv_free
= rcv_desc
->max_rx_desc_count
;
183 rcv_desc
->begin_alloc
= 0;
184 rx_buf
= rcv_desc
->rx_buf_arr
;
185 num_rx_bufs
= rcv_desc
->max_rx_desc_count
;
187 * Now go through all of them, set reference handles
188 * and put them in the queues.
190 for (i
= 0; i
< num_rx_bufs
; i
++) {
191 rx_buf
->ref_handle
= i
;
192 rx_buf
->state
= NETXEN_BUFFER_FREE
;
193 DPRINTK(INFO
, "Rx buf:ctx%d i(%d) rx_buf:"
194 "%p\n", ctxid
, i
, rx_buf
);
201 void netxen_initialize_adapter_hw(struct netxen_adapter
*adapter
)
204 struct netxen_board_info
*board_info
= &(adapter
->ahw
.boardcfg
);
206 if (netxen_nic_get_board_info(adapter
) != 0)
207 printk("%s: Error getting board config info.\n",
208 netxen_nic_driver_name
);
209 get_brd_port_by_type(board_info
->board_type
, &ports
);
211 printk(KERN_ERR
"%s: Unknown board type\n",
212 netxen_nic_driver_name
);
213 adapter
->ahw
.max_ports
= ports
;
216 void netxen_initialize_adapter_ops(struct netxen_adapter
*adapter
)
218 switch (adapter
->ahw
.board_type
) {
220 adapter
->enable_phy_interrupts
=
221 netxen_niu_gbe_enable_phy_interrupts
;
222 adapter
->disable_phy_interrupts
=
223 netxen_niu_gbe_disable_phy_interrupts
;
224 adapter
->handle_phy_intr
= netxen_nic_gbe_handle_phy_intr
;
225 adapter
->macaddr_set
= netxen_niu_macaddr_set
;
226 adapter
->set_mtu
= netxen_nic_set_mtu_gb
;
227 adapter
->set_promisc
= netxen_niu_set_promiscuous_mode
;
228 adapter
->unset_promisc
= netxen_niu_set_promiscuous_mode
;
229 adapter
->phy_read
= netxen_niu_gbe_phy_read
;
230 adapter
->phy_write
= netxen_niu_gbe_phy_write
;
231 adapter
->init_niu
= netxen_nic_init_niu_gb
;
232 adapter
->stop_port
= netxen_niu_disable_gbe_port
;
235 case NETXEN_NIC_XGBE
:
236 adapter
->enable_phy_interrupts
=
237 netxen_niu_xgbe_enable_phy_interrupts
;
238 adapter
->disable_phy_interrupts
=
239 netxen_niu_xgbe_disable_phy_interrupts
;
240 adapter
->handle_phy_intr
= netxen_nic_xgbe_handle_phy_intr
;
241 adapter
->macaddr_set
= netxen_niu_xg_macaddr_set
;
242 adapter
->set_mtu
= netxen_nic_set_mtu_xgb
;
243 adapter
->init_port
= netxen_niu_xg_init_port
;
244 adapter
->set_promisc
= netxen_niu_xg_set_promiscuous_mode
;
245 adapter
->unset_promisc
= netxen_niu_xg_set_promiscuous_mode
;
246 adapter
->stop_port
= netxen_niu_disable_xg_port
;
255 * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB
256 * address to external PCI CRB address.
258 u32
netxen_decode_crb_addr(u32 addr
)
261 u32 base_addr
, offset
, pci_base
;
263 crb_addr_transform_setup();
265 pci_base
= NETXEN_ADDR_ERROR
;
266 base_addr
= addr
& 0xfff00000;
267 offset
= addr
& 0x000fffff;
269 for (i
= 0; i
< NETXEN_MAX_CRB_XFORM
; i
++) {
270 if (crb_addr_xform
[i
] == base_addr
) {
275 if (pci_base
== NETXEN_ADDR_ERROR
)
278 return (pci_base
+ offset
);
281 static long rom_max_timeout
= 100;
282 static long rom_lock_timeout
= 10000;
283 static long rom_write_timeout
= 700;
285 static inline int rom_lock(struct netxen_adapter
*adapter
)
292 /* acquire semaphore2 from PCI HW block */
293 netxen_nic_read_w0(adapter
, NETXEN_PCIE_REG(PCIE_SEM2_LOCK
),
297 if (timeout
>= rom_lock_timeout
)
307 for (iter
= 0; iter
< 20; iter
++)
308 cpu_relax(); /*This a nop instr on i386 */
311 netxen_nic_reg_write(adapter
, NETXEN_ROM_LOCK_ID
, ROM_LOCK_DRIVER
);
315 int netxen_wait_rom_done(struct netxen_adapter
*adapter
)
321 done
= netxen_nic_reg_read(adapter
, NETXEN_ROMUSB_GLB_STATUS
);
324 if (timeout
>= rom_max_timeout
) {
325 printk("Timeout reached waiting for rom done");
332 static inline int netxen_rom_wren(struct netxen_adapter
*adapter
)
334 /* Set write enable latch in ROM status register */
335 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 0);
336 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_INSTR_OPCODE
,
338 if (netxen_wait_rom_done(adapter
)) {
344 static inline unsigned int netxen_rdcrbreg(struct netxen_adapter
*adapter
,
347 unsigned int data
= 0xdeaddead;
348 data
= netxen_nic_reg_read(adapter
, addr
);
352 static inline int netxen_do_rom_rdsr(struct netxen_adapter
*adapter
)
354 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_INSTR_OPCODE
,
356 if (netxen_wait_rom_done(adapter
)) {
359 return netxen_rdcrbreg(adapter
, NETXEN_ROMUSB_ROM_RDATA
);
362 static inline void netxen_rom_unlock(struct netxen_adapter
*adapter
)
366 /* release semaphore2 */
367 netxen_nic_read_w0(adapter
, NETXEN_PCIE_REG(PCIE_SEM2_UNLOCK
), &val
);
371 int netxen_rom_wip_poll(struct netxen_adapter
*adapter
)
376 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 0);
378 val
= netxen_do_rom_rdsr(adapter
);
381 if (timeout
> rom_max_timeout
) {
388 static inline int do_rom_fast_write(struct netxen_adapter
*adapter
, int addr
,
391 if (netxen_rom_wren(adapter
)) {
394 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_WDATA
, data
);
395 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ADDRESS
, addr
);
396 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 3);
397 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_INSTR_OPCODE
,
399 if (netxen_wait_rom_done(adapter
)) {
400 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 0);
404 return netxen_rom_wip_poll(adapter
);
408 do_rom_fast_read(struct netxen_adapter
*adapter
, int addr
, int *valp
)
412 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ADDRESS
, addr
);
413 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 3);
414 udelay(100); /* prevent bursting on CRB */
415 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
416 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_INSTR_OPCODE
, 0xb);
417 if (netxen_wait_rom_done(adapter
)) {
418 printk("Error waiting for rom done\n");
421 /* reset abyte_cnt and dummy_byte_cnt */
422 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 0);
423 udelay(100); /* prevent bursting on CRB */
424 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
426 *valp
= netxen_nic_reg_read(adapter
, NETXEN_ROMUSB_ROM_RDATA
);
431 do_rom_fast_read_words(struct netxen_adapter
*adapter
, int addr
,
432 u8
*bytes
, size_t size
)
437 for (addridx
= addr
; addridx
< (addr
+ size
); addridx
+= 4) {
438 ret
= do_rom_fast_read(adapter
, addridx
, (int *)bytes
);
441 *(int *)bytes
= cpu_to_le32(*(int *)bytes
);
449 netxen_rom_fast_read_words(struct netxen_adapter
*adapter
, int addr
,
450 u8
*bytes
, size_t size
)
454 ret
= rom_lock(adapter
);
458 ret
= do_rom_fast_read_words(adapter
, addr
, bytes
, size
);
460 netxen_rom_unlock(adapter
);
464 int netxen_rom_fast_read(struct netxen_adapter
*adapter
, int addr
, int *valp
)
468 if (rom_lock(adapter
) != 0)
471 ret
= do_rom_fast_read(adapter
, addr
, valp
);
472 netxen_rom_unlock(adapter
);
476 int netxen_rom_fast_write(struct netxen_adapter
*adapter
, int addr
, int data
)
480 if (rom_lock(adapter
) != 0) {
483 ret
= do_rom_fast_write(adapter
, addr
, data
);
484 netxen_rom_unlock(adapter
);
488 static inline int do_rom_fast_write_words(struct netxen_adapter
*adapter
,
489 int addr
, u8
*bytes
, size_t size
)
494 while (addridx
< (addr
+ size
)) {
495 int last_attempt
= 0;
499 data
= le32_to_cpu((*(u32
*)bytes
));
500 ret
= do_rom_fast_write(adapter
, addridx
, data
);
507 ret
= do_rom_fast_read(adapter
, addridx
, &data1
);
514 if (timeout
++ >= rom_write_timeout
) {
515 if (last_attempt
++ < 4) {
516 ret
= do_rom_fast_write(adapter
,
522 printk(KERN_INFO
"Data write did not "
523 "succeed at address 0x%x\n", addridx
);
536 int netxen_rom_fast_write_words(struct netxen_adapter
*adapter
, int addr
,
537 u8
*bytes
, size_t size
)
541 ret
= rom_lock(adapter
);
545 ret
= do_rom_fast_write_words(adapter
, addr
, bytes
, size
);
546 netxen_rom_unlock(adapter
);
551 int netxen_rom_wrsr(struct netxen_adapter
*adapter
, int data
)
555 ret
= netxen_rom_wren(adapter
);
559 netxen_crb_writelit_adapter(adapter
, NETXEN_ROMUSB_ROM_WDATA
, data
);
560 netxen_crb_writelit_adapter(adapter
,
561 NETXEN_ROMUSB_ROM_INSTR_OPCODE
, 0x1);
563 ret
= netxen_wait_rom_done(adapter
);
567 return netxen_rom_wip_poll(adapter
);
570 int netxen_rom_rdsr(struct netxen_adapter
*adapter
)
574 ret
= rom_lock(adapter
);
578 ret
= netxen_do_rom_rdsr(adapter
);
579 netxen_rom_unlock(adapter
);
583 int netxen_backup_crbinit(struct netxen_adapter
*adapter
)
585 int ret
= FLASH_SUCCESS
;
587 char *buffer
= kmalloc(NETXEN_FLASH_SECTOR_SIZE
, GFP_KERNEL
);
591 /* unlock sector 63 */
592 val
= netxen_rom_rdsr(adapter
);
594 ret
= netxen_rom_wrsr(adapter
, val
);
595 if (ret
!= FLASH_SUCCESS
)
598 ret
= netxen_rom_wip_poll(adapter
);
599 if (ret
!= FLASH_SUCCESS
)
602 /* copy sector 0 to sector 63 */
603 ret
= netxen_rom_fast_read_words(adapter
, NETXEN_CRBINIT_START
,
604 buffer
, NETXEN_FLASH_SECTOR_SIZE
);
605 if (ret
!= FLASH_SUCCESS
)
608 ret
= netxen_rom_fast_write_words(adapter
, NETXEN_FIXED_START
,
609 buffer
, NETXEN_FLASH_SECTOR_SIZE
);
610 if (ret
!= FLASH_SUCCESS
)
614 val
= netxen_rom_rdsr(adapter
);
618 if (netxen_rom_wrsr(adapter
, val
) == 0) {
619 ret
= netxen_rom_wip_poll(adapter
);
620 if (ret
!= FLASH_SUCCESS
)
624 ret
= netxen_rom_wip_poll(adapter
);
625 if (ret
!= FLASH_SUCCESS
)
635 int netxen_do_rom_se(struct netxen_adapter
*adapter
, int addr
)
637 netxen_rom_wren(adapter
);
638 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ADDRESS
, addr
);
639 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 3);
640 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_INSTR_OPCODE
,
642 if (netxen_wait_rom_done(adapter
)) {
643 netxen_nic_reg_write(adapter
, NETXEN_ROMUSB_ROM_ABYTE_CNT
, 0);
646 return netxen_rom_wip_poll(adapter
);
649 void check_erased_flash(struct netxen_adapter
*adapter
, int addr
)
653 int count
= 0, erased_errors
= 0;
656 range
= (addr
== NETXEN_USER_START
) ?
657 NETXEN_FIXED_START
: addr
+ NETXEN_FLASH_SECTOR_SIZE
;
659 for (i
= addr
; i
< range
; i
+= 4) {
660 netxen_rom_fast_read(adapter
, i
, &val
);
661 if (val
!= 0xffffffff)
667 printk(KERN_INFO
"0x%x out of 0x%x words fail to be erased "
668 "for sector address: %x\n", erased_errors
, count
, addr
);
671 int netxen_rom_se(struct netxen_adapter
*adapter
, int addr
)
674 if (rom_lock(adapter
) != 0) {
677 ret
= netxen_do_rom_se(adapter
, addr
);
678 netxen_rom_unlock(adapter
);
680 check_erased_flash(adapter
, addr
);
686 netxen_flash_erase_sections(struct netxen_adapter
*adapter
, int start
, int end
)
688 int ret
= FLASH_SUCCESS
;
691 for (i
= start
; i
< end
; i
++) {
692 ret
= netxen_rom_se(adapter
, i
* NETXEN_FLASH_SECTOR_SIZE
);
695 ret
= netxen_rom_wip_poll(adapter
);
704 netxen_flash_erase_secondary(struct netxen_adapter
*adapter
)
706 int ret
= FLASH_SUCCESS
;
709 start
= NETXEN_SECONDARY_START
/ NETXEN_FLASH_SECTOR_SIZE
;
710 end
= NETXEN_USER_START
/ NETXEN_FLASH_SECTOR_SIZE
;
711 ret
= netxen_flash_erase_sections(adapter
, start
, end
);
717 netxen_flash_erase_primary(struct netxen_adapter
*adapter
)
719 int ret
= FLASH_SUCCESS
;
722 start
= NETXEN_PRIMARY_START
/ NETXEN_FLASH_SECTOR_SIZE
;
723 end
= NETXEN_SECONDARY_START
/ NETXEN_FLASH_SECTOR_SIZE
;
724 ret
= netxen_flash_erase_sections(adapter
, start
, end
);
729 void netxen_halt_pegs(struct netxen_adapter
*adapter
)
731 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_0
+ 0x3c, 1);
732 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_1
+ 0x3c, 1);
733 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_2
+ 0x3c, 1);
734 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_3
+ 0x3c, 1);
737 int netxen_flash_unlock(struct netxen_adapter
*adapter
)
741 ret
= netxen_rom_wrsr(adapter
, 0);
745 ret
= netxen_rom_wren(adapter
);
752 #define NETXEN_BOARDTYPE 0x4008
753 #define NETXEN_BOARDNUM 0x400c
754 #define NETXEN_CHIPNUM 0x4010
755 #define NETXEN_ROMBUS_RESET 0xFFFFFFFF
756 #define NETXEN_ROM_FIRST_BARRIER 0x800000000ULL
757 #define NETXEN_ROM_FOUND_INIT 0x400
759 int netxen_pinit_from_rom(struct netxen_adapter
*adapter
, int verbose
)
761 int addr
, val
, status
;
764 struct crb_addr_pair
*buf
;
768 status
= netxen_nic_get_board_info(adapter
);
770 printk("%s: netxen_pinit_from_rom: Error getting board info\n",
771 netxen_nic_driver_name
);
773 netxen_crb_writelit_adapter(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
,
774 NETXEN_ROMBUS_RESET
);
778 if (netxen_rom_fast_read(adapter
, NETXEN_BOARDTYPE
, &val
) == 0)
779 printk("P2 ROM board type: 0x%08x\n", val
);
781 printk("Could not read board type\n");
782 if (netxen_rom_fast_read(adapter
, NETXEN_BOARDNUM
, &val
) == 0)
783 printk("P2 ROM board num: 0x%08x\n", val
);
785 printk("Could not read board number\n");
786 if (netxen_rom_fast_read(adapter
, NETXEN_CHIPNUM
, &val
) == 0)
787 printk("P2 ROM chip num: 0x%08x\n", val
);
789 printk("Could not read chip number\n");
792 if (netxen_rom_fast_read(adapter
, 0, &n
) == 0
793 && (n
& NETXEN_ROM_FIRST_BARRIER
)) {
794 n
&= ~NETXEN_ROM_ROUNDUP
;
795 if (n
< NETXEN_ROM_FOUND_INIT
) {
797 printk("%s: %d CRB init values found"
798 " in ROM.\n", netxen_nic_driver_name
, n
);
800 printk("%s:n=0x%x Error! NetXen card flash not"
801 " initialized.\n", __FUNCTION__
, n
);
804 buf
= kcalloc(n
, sizeof(struct crb_addr_pair
), GFP_KERNEL
);
806 printk("%s: netxen_pinit_from_rom: Unable to calloc "
807 "memory.\n", netxen_nic_driver_name
);
810 for (i
= 0; i
< n
; i
++) {
811 if (netxen_rom_fast_read(adapter
, 8 * i
+ 4, &val
) != 0
812 || netxen_rom_fast_read(adapter
, 8 * i
+ 8,
820 printk("%s: PCI: 0x%08x == 0x%08x\n",
821 netxen_nic_driver_name
, (unsigned int)
822 netxen_decode_crb_addr(addr
), val
);
824 for (i
= 0; i
< n
; i
++) {
826 off
= netxen_decode_crb_addr(buf
[i
].addr
);
827 if (off
== NETXEN_ADDR_ERROR
) {
828 printk(KERN_ERR
"CRB init value out of range %x\n",
832 off
+= NETXEN_PCI_CRBSPACE
;
833 /* skipping cold reboot MAGIC */
834 if (off
== NETXEN_CAM_RAM(0x1fc))
837 /* After writing this register, HW needs time for CRB */
838 /* to quiet down (else crb_window returns 0xffffffff) */
839 if (off
== NETXEN_ROMUSB_GLB_SW_RESET
) {
841 /* hold xdma in reset also */
842 buf
[i
].data
= NETXEN_NIC_XDMA_RESET
;
845 if (ADDR_IN_WINDOW1(off
)) {
847 NETXEN_CRB_NORMALIZE(adapter
, off
));
849 netxen_nic_pci_change_crbwindow(adapter
, 0);
851 pci_base_offset(adapter
, off
));
853 netxen_nic_pci_change_crbwindow(adapter
, 1);
855 if (init_delay
== 1) {
863 /* disable_peg_cache_all */
865 /* unreset_net_cache */
866 netxen_nic_hw_read_wx(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
, &val
,
868 netxen_crb_writelit_adapter(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
,
870 /* p2dn replyCount */
871 netxen_crb_writelit_adapter(adapter
,
872 NETXEN_CRB_PEG_NET_D
+ 0xec, 0x1e);
873 /* disable_peg_cache 0 */
874 netxen_crb_writelit_adapter(adapter
,
875 NETXEN_CRB_PEG_NET_D
+ 0x4c, 8);
876 /* disable_peg_cache 1 */
877 netxen_crb_writelit_adapter(adapter
,
878 NETXEN_CRB_PEG_NET_I
+ 0x4c, 8);
883 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_0
+ 0x8,
885 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_0
+ 0xc,
888 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_1
+ 0x8,
890 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_1
+ 0xc,
893 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_2
+ 0x8,
895 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_2
+ 0xc,
898 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_3
+ 0x8,
900 netxen_crb_writelit_adapter(adapter
, NETXEN_CRB_PEG_NET_3
+ 0xc,
906 int netxen_initialize_adapter_offload(struct netxen_adapter
*adapter
)
912 adapter
->dummy_dma
.addr
=
913 pci_alloc_consistent(adapter
->ahw
.pdev
,
914 NETXEN_HOST_DUMMY_DMA_SIZE
,
915 &adapter
->dummy_dma
.phys_addr
);
916 if (adapter
->dummy_dma
.addr
== NULL
) {
917 printk("%s: ERROR: Could not allocate dummy DMA memory\n",
922 addr
= (uint64_t) adapter
->dummy_dma
.phys_addr
;
923 hi
= (addr
>> 32) & 0xffffffff;
924 lo
= addr
& 0xffffffff;
926 writel(hi
, NETXEN_CRB_NORMALIZE(adapter
, CRB_HOST_DUMMY_BUF_ADDR_HI
));
927 writel(lo
, NETXEN_CRB_NORMALIZE(adapter
, CRB_HOST_DUMMY_BUF_ADDR_LO
));
932 void netxen_free_adapter_offload(struct netxen_adapter
*adapter
)
934 if (adapter
->dummy_dma
.addr
) {
935 pci_free_consistent(adapter
->ahw
.pdev
,
936 NETXEN_HOST_DUMMY_DMA_SIZE
,
937 adapter
->dummy_dma
.addr
,
938 adapter
->dummy_dma
.phys_addr
);
939 adapter
->dummy_dma
.addr
= NULL
;
943 int netxen_phantom_init(struct netxen_adapter
*adapter
, int pegtune_val
)
950 val
= readl(NETXEN_CRB_NORMALIZE
951 (adapter
, CRB_CMDPEG_STATE
));
952 pegtune_val
= readl(NETXEN_CRB_NORMALIZE
953 (adapter
, NETXEN_ROMUSB_GLB_PEGTUNE_DONE
));
955 if (val
== PHAN_INITIALIZE_COMPLETE
||
956 val
== PHAN_INITIALIZE_ACK
)
962 printk(KERN_WARNING
"netxen_phantom_init: init failed, "
963 "pegtune_val=%x\n", pegtune_val
);
971 int netxen_nic_rx_has_work(struct netxen_adapter
*adapter
)
975 for (ctx
= 0; ctx
< MAX_RCV_CTX
; ++ctx
) {
976 struct netxen_recv_context
*recv_ctx
=
977 &(adapter
->recv_ctx
[ctx
]);
979 struct status_desc
*desc_head
;
980 struct status_desc
*desc
;
982 consumer
= recv_ctx
->status_rx_consumer
;
983 desc_head
= recv_ctx
->rcv_status_desc_head
;
984 desc
= &desc_head
[consumer
];
986 if (netxen_get_sts_owner(desc
) & STATUS_OWNER_HOST
)
993 static inline int netxen_nic_check_temp(struct netxen_adapter
*adapter
)
995 struct net_device
*netdev
= adapter
->netdev
;
996 uint32_t temp
, temp_state
, temp_val
;
999 temp
= readl(NETXEN_CRB_NORMALIZE(adapter
, CRB_TEMP_STATE
));
1001 temp_state
= nx_get_temp_state(temp
);
1002 temp_val
= nx_get_temp_val(temp
);
1004 if (temp_state
== NX_TEMP_PANIC
) {
1006 "%s: Device temperature %d degrees C exceeds"
1007 " maximum allowed. Hardware has been shut down.\n",
1008 netxen_nic_driver_name
, temp_val
);
1010 netif_carrier_off(netdev
);
1011 netif_stop_queue(netdev
);
1013 } else if (temp_state
== NX_TEMP_WARN
) {
1014 if (adapter
->temp
== NX_TEMP_NORMAL
) {
1016 "%s: Device temperature %d degrees C "
1017 "exceeds operating range."
1018 " Immediate action needed.\n",
1019 netxen_nic_driver_name
, temp_val
);
1022 if (adapter
->temp
== NX_TEMP_WARN
) {
1024 "%s: Device temperature is now %d degrees C"
1025 " in normal range.\n", netxen_nic_driver_name
,
1029 adapter
->temp
= temp_state
;
1033 void netxen_watchdog_task(struct work_struct
*work
)
1035 struct net_device
*netdev
;
1036 struct netxen_adapter
*adapter
=
1037 container_of(work
, struct netxen_adapter
, watchdog_task
);
1039 if ((adapter
->portnum
== 0) && netxen_nic_check_temp(adapter
))
1042 if (adapter
->handle_phy_intr
)
1043 adapter
->handle_phy_intr(adapter
);
1045 netdev
= adapter
->netdev
;
1046 if ((netif_running(netdev
)) && !netif_carrier_ok(netdev
) &&
1047 netxen_nic_link_ok(adapter
) ) {
1048 printk(KERN_INFO
"%s %s (port %d), Link is up\n",
1049 netxen_nic_driver_name
, netdev
->name
, adapter
->portnum
);
1050 netif_carrier_on(netdev
);
1051 netif_wake_queue(netdev
);
1052 } else if(!(netif_running(netdev
)) && netif_carrier_ok(netdev
)) {
1053 printk(KERN_ERR
"%s %s Link is Down\n",
1054 netxen_nic_driver_name
, netdev
->name
);
1055 netif_carrier_off(netdev
);
1056 netif_stop_queue(netdev
);
1059 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 2 * HZ
);
1063 * netxen_process_rcv() send the received packet to the protocol stack.
1064 * and if the number of receives exceeds RX_BUFFERS_REFILL, then we
1065 * invoke the routine to send more rx buffers to the Phantom...
1068 netxen_process_rcv(struct netxen_adapter
*adapter
, int ctxid
,
1069 struct status_desc
*desc
)
1071 struct pci_dev
*pdev
= adapter
->pdev
;
1072 struct net_device
*netdev
= adapter
->netdev
;
1073 int index
= netxen_get_sts_refhandle(desc
);
1074 struct netxen_recv_context
*recv_ctx
= &(adapter
->recv_ctx
[ctxid
]);
1075 struct netxen_rx_buffer
*buffer
;
1076 struct sk_buff
*skb
;
1077 u32 length
= netxen_get_sts_totallength(desc
);
1079 struct netxen_rcv_desc_ctx
*rcv_desc
;
1082 desc_ctx
= netxen_get_sts_type(desc
);
1083 if (unlikely(desc_ctx
>= NUM_RCV_DESC_RINGS
)) {
1084 printk("%s: %s Bad Rcv descriptor ring\n",
1085 netxen_nic_driver_name
, netdev
->name
);
1089 rcv_desc
= &recv_ctx
->rcv_desc
[desc_ctx
];
1090 if (unlikely(index
> rcv_desc
->max_rx_desc_count
)) {
1091 DPRINTK(ERR
, "Got a buffer index:%x Max is %x\n",
1092 index
, rcv_desc
->max_rx_desc_count
);
1095 buffer
= &rcv_desc
->rx_buf_arr
[index
];
1096 if (desc_ctx
== RCV_DESC_LRO_CTXID
) {
1097 buffer
->lro_current_frags
++;
1098 if (netxen_get_sts_desc_lro_last_frag(desc
)) {
1099 buffer
->lro_expected_frags
=
1100 netxen_get_sts_desc_lro_cnt(desc
);
1101 buffer
->lro_length
= length
;
1103 if (buffer
->lro_current_frags
!= buffer
->lro_expected_frags
) {
1104 if (buffer
->lro_expected_frags
!= 0) {
1105 printk("LRO: (refhandle:%x) recv frag."
1106 "wait for last. flags: %x expected:%d"
1108 netxen_get_sts_desc_lro_last_frag(desc
),
1109 buffer
->lro_expected_frags
,
1110 buffer
->lro_current_frags
);
1116 pci_unmap_single(pdev
, buffer
->dma
, rcv_desc
->dma_size
,
1117 PCI_DMA_FROMDEVICE
);
1119 skb
= (struct sk_buff
*)buffer
->skb
;
1121 if (likely(netxen_get_sts_status(desc
) == STATUS_CKSUM_OK
)) {
1122 adapter
->stats
.csummed
++;
1123 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1126 if (desc_ctx
== RCV_DESC_LRO_CTXID
) {
1127 /* True length was only available on the last pkt */
1128 skb_put(skb
, buffer
->lro_length
);
1130 skb_put(skb
, length
);
1133 skb
->protocol
= eth_type_trans(skb
, netdev
);
1135 ret
= netif_receive_skb(skb
);
1138 * RH: Do we need these stats on a regular basis. Can we get it from
1142 case NET_RX_SUCCESS
:
1143 adapter
->stats
.uphappy
++;
1147 adapter
->stats
.uplcong
++;
1151 adapter
->stats
.upmcong
++;
1154 case NET_RX_CN_HIGH
:
1155 adapter
->stats
.uphcong
++;
1159 adapter
->stats
.updropped
++;
1163 adapter
->stats
.updunno
++;
1167 netdev
->last_rx
= jiffies
;
1169 rcv_desc
->rcv_free
++;
1170 rcv_desc
->rcv_pending
--;
1173 * We just consumed one buffer so post a buffer.
1176 buffer
->state
= NETXEN_BUFFER_FREE
;
1177 buffer
->lro_current_frags
= 0;
1178 buffer
->lro_expected_frags
= 0;
1180 adapter
->stats
.no_rcv
++;
1181 adapter
->stats
.rxbytes
+= length
;
1184 /* Process Receive status ring */
1185 u32
netxen_process_rcv_ring(struct netxen_adapter
*adapter
, int ctxid
, int max
)
1187 struct netxen_recv_context
*recv_ctx
= &(adapter
->recv_ctx
[ctxid
]);
1188 struct status_desc
*desc_head
= recv_ctx
->rcv_status_desc_head
;
1189 struct status_desc
*desc
; /* used to read status desc here */
1190 u32 consumer
= recv_ctx
->status_rx_consumer
;
1192 int count
= 0, ring
;
1194 DPRINTK(INFO
, "procesing receive\n");
1196 * we assume in this case that there is only one port and that is
1197 * port #1...changes need to be done in firmware to indicate port
1198 * number as part of the descriptor. This way we will be able to get
1199 * the netdev which is associated with that device.
1201 while (count
< max
) {
1202 desc
= &desc_head
[consumer
];
1203 if (!(netxen_get_sts_owner(desc
) & STATUS_OWNER_HOST
)) {
1204 DPRINTK(ERR
, "desc %p ownedby %x\n", desc
,
1205 netxen_get_sts_owner(desc
));
1208 netxen_process_rcv(adapter
, ctxid
, desc
);
1209 netxen_clear_sts_owner(desc
);
1210 netxen_set_sts_owner(desc
, STATUS_OWNER_PHANTOM
);
1211 consumer
= (consumer
+ 1) & (adapter
->max_rx_desc_count
- 1);
1215 for (ring
= 0; ring
< NUM_RCV_DESC_RINGS
; ring
++) {
1216 netxen_post_rx_buffers_nodb(adapter
, ctxid
, ring
);
1220 /* update the consumer index in phantom */
1222 recv_ctx
->status_rx_consumer
= consumer
;
1223 recv_ctx
->status_rx_producer
= producer
;
1227 NETXEN_CRB_NORMALIZE(adapter
,
1228 recv_crb_registers
[adapter
->portnum
].
1229 crb_rcv_status_consumer
));
1236 /* Process Command status ring */
1237 int netxen_process_cmd_ring(unsigned long data
)
1241 struct netxen_adapter
*adapter
= (struct netxen_adapter
*)data
;
1244 struct netxen_cmd_buffer
*buffer
;
1245 struct pci_dev
*pdev
;
1246 struct netxen_skb_frag
*frag
;
1248 struct sk_buff
*skb
= NULL
;
1251 spin_lock(&adapter
->tx_lock
);
1252 last_consumer
= adapter
->last_cmd_consumer
;
1253 DPRINTK(INFO
, "procesing xmit complete\n");
1254 /* we assume in this case that there is only one port and that is
1255 * port #1...changes need to be done in firmware to indicate port
1256 * number as part of the descriptor. This way we will be able to get
1257 * the netdev which is associated with that device.
1260 consumer
= le32_to_cpu(*(adapter
->cmd_consumer
));
1261 if (last_consumer
== consumer
) { /* Ring is empty */
1262 DPRINTK(INFO
, "last_consumer %d == consumer %d\n",
1263 last_consumer
, consumer
);
1264 spin_unlock(&adapter
->tx_lock
);
1268 adapter
->proc_cmd_buf_counter
++;
1270 * Not needed - does not seem to be used anywhere.
1271 * adapter->cmd_consumer = consumer;
1273 spin_unlock(&adapter
->tx_lock
);
1275 while ((last_consumer
!= consumer
) && (count1
< MAX_STATUS_HANDLE
)) {
1276 buffer
= &adapter
->cmd_buf_arr
[last_consumer
];
1277 pdev
= adapter
->pdev
;
1278 frag
= &buffer
->frag_array
[0];
1280 if (skb
&& (cmpxchg(&buffer
->skb
, skb
, 0) == skb
)) {
1281 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
1284 for (i
= 1; i
< buffer
->frag_count
; i
++) {
1285 DPRINTK(INFO
, "getting fragment no %d\n", i
);
1286 frag
++; /* Get the next frag */
1287 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
1292 adapter
->stats
.skbfreed
++;
1293 dev_kfree_skb_any(skb
);
1295 } else if (adapter
->proc_cmd_buf_counter
== 1) {
1296 adapter
->stats
.txnullskb
++;
1298 if (unlikely(netif_queue_stopped(adapter
->netdev
)
1299 && netif_carrier_ok(adapter
->netdev
))
1300 && ((jiffies
- adapter
->netdev
->trans_start
) >
1301 adapter
->netdev
->watchdog_timeo
)) {
1302 SCHEDULE_WORK(&adapter
->tx_timeout_task
);
1305 last_consumer
= get_next_index(last_consumer
,
1306 adapter
->max_tx_desc_count
);
1311 spin_lock(&adapter
->tx_lock
);
1312 if ((--adapter
->proc_cmd_buf_counter
) == 0) {
1313 adapter
->last_cmd_consumer
= last_consumer
;
1314 while ((adapter
->last_cmd_consumer
!= consumer
)
1315 && (count2
< MAX_STATUS_HANDLE
)) {
1317 &adapter
->cmd_buf_arr
[adapter
->last_cmd_consumer
];
1322 adapter
->last_cmd_consumer
=
1323 get_next_index(adapter
->last_cmd_consumer
,
1324 adapter
->max_tx_desc_count
);
1327 if (count1
|| count2
) {
1328 if (netif_queue_stopped(adapter
->netdev
)
1329 && (adapter
->flags
& NETXEN_NETDEV_STATUS
)) {
1330 netif_wake_queue(adapter
->netdev
);
1331 adapter
->flags
&= ~NETXEN_NETDEV_STATUS
;
1335 * If everything is freed up to consumer then check if the ring is full
1336 * If the ring is full then check if more needs to be freed and
1337 * schedule the call back again.
1339 * This happens when there are 2 CPUs. One could be freeing and the
1340 * other filling it. If the ring is full when we get out of here and
1341 * the card has already interrupted the host then the host can miss the
1344 * There is still a possible race condition and the host could miss an
1345 * interrupt. The card has to take care of this.
1347 if (adapter
->last_cmd_consumer
== consumer
&&
1348 (((adapter
->cmd_producer
+ 1) %
1349 adapter
->max_tx_desc_count
) == adapter
->last_cmd_consumer
)) {
1350 consumer
= le32_to_cpu(*(adapter
->cmd_consumer
));
1352 done
= (adapter
->last_cmd_consumer
== consumer
);
1354 spin_unlock(&adapter
->tx_lock
);
1355 DPRINTK(INFO
, "last consumer is %d in %s\n", last_consumer
,
1361 * netxen_post_rx_buffers puts buffer in the Phantom memory
1363 void netxen_post_rx_buffers(struct netxen_adapter
*adapter
, u32 ctx
, u32 ringid
)
1365 struct pci_dev
*pdev
= adapter
->ahw
.pdev
;
1366 struct sk_buff
*skb
;
1367 struct netxen_recv_context
*recv_ctx
= &(adapter
->recv_ctx
[ctx
]);
1368 struct netxen_rcv_desc_ctx
*rcv_desc
= NULL
;
1370 struct rcv_desc
*pdesc
;
1371 struct netxen_rx_buffer
*buffer
;
1374 netxen_ctx_msg msg
= 0;
1377 rcv_desc
= &recv_ctx
->rcv_desc
[ringid
];
1379 producer
= rcv_desc
->producer
;
1380 index
= rcv_desc
->begin_alloc
;
1381 buffer
= &rcv_desc
->rx_buf_arr
[index
];
1382 /* We can start writing rx descriptors into the phantom memory. */
1383 while (buffer
->state
== NETXEN_BUFFER_FREE
) {
1384 skb
= dev_alloc_skb(rcv_desc
->skb_size
);
1385 if (unlikely(!skb
)) {
1388 * We need to schedule the posting of buffers to the pegs.
1390 rcv_desc
->begin_alloc
= index
;
1391 DPRINTK(ERR
, "netxen_post_rx_buffers: "
1392 " allocated only %d buffers\n", count
);
1396 count
++; /* now there should be no failure */
1397 pdesc
= &rcv_desc
->desc_head
[producer
];
1399 #if defined(XGB_DEBUG)
1400 *(unsigned long *)(skb
->head
) = 0xc0debabe;
1401 if (skb_is_nonlinear(skb
)) {
1402 printk("Allocated SKB @%p is nonlinear\n");
1405 skb_reserve(skb
, 2);
1406 /* This will be setup when we receive the
1407 * buffer after it has been filled FSL TBD TBD
1408 * skb->dev = netdev;
1410 dma
= pci_map_single(pdev
, skb
->data
, rcv_desc
->dma_size
,
1411 PCI_DMA_FROMDEVICE
);
1412 pdesc
->addr_buffer
= cpu_to_le64(dma
);
1414 buffer
->state
= NETXEN_BUFFER_BUSY
;
1416 /* make a rcv descriptor */
1417 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1418 pdesc
->buffer_length
= cpu_to_le32(rcv_desc
->dma_size
);
1419 DPRINTK(INFO
, "done writing descripter\n");
1421 get_next_index(producer
, rcv_desc
->max_rx_desc_count
);
1422 index
= get_next_index(index
, rcv_desc
->max_rx_desc_count
);
1423 buffer
= &rcv_desc
->rx_buf_arr
[index
];
1425 /* if we did allocate buffers, then write the count to Phantom */
1427 rcv_desc
->begin_alloc
= index
;
1428 rcv_desc
->rcv_pending
+= count
;
1429 rcv_desc
->producer
= producer
;
1430 if (rcv_desc
->rcv_free
>= 32) {
1431 rcv_desc
->rcv_free
= 0;
1433 writel((producer
- 1) &
1434 (rcv_desc
->max_rx_desc_count
- 1),
1435 NETXEN_CRB_NORMALIZE(adapter
,
1438 rcv_desc_crb
[ringid
].
1439 crb_rcv_producer_offset
));
1441 * Write a doorbell msg to tell phanmon of change in
1442 * receive ring producer
1444 netxen_set_msg_peg_id(msg
, NETXEN_RCV_PEG_DB_ID
);
1445 netxen_set_msg_privid(msg
);
1446 netxen_set_msg_count(msg
,
1449 max_rx_desc_count
- 1)));
1450 netxen_set_msg_ctxid(msg
, adapter
->portnum
);
1451 netxen_set_msg_opcode(msg
, NETXEN_RCV_PRODUCER(ringid
));
1453 DB_NORMALIZE(adapter
,
1454 NETXEN_RCV_PRODUCER_OFFSET
));
1460 void netxen_post_rx_buffers_nodb(struct netxen_adapter
*adapter
, uint32_t ctx
,
1463 struct pci_dev
*pdev
= adapter
->ahw
.pdev
;
1464 struct sk_buff
*skb
;
1465 struct netxen_recv_context
*recv_ctx
= &(adapter
->recv_ctx
[ctx
]);
1466 struct netxen_rcv_desc_ctx
*rcv_desc
= NULL
;
1468 struct rcv_desc
*pdesc
;
1469 struct netxen_rx_buffer
*buffer
;
1473 rcv_desc
= &recv_ctx
->rcv_desc
[ringid
];
1475 producer
= rcv_desc
->producer
;
1476 index
= rcv_desc
->begin_alloc
;
1477 buffer
= &rcv_desc
->rx_buf_arr
[index
];
1478 /* We can start writing rx descriptors into the phantom memory. */
1479 while (buffer
->state
== NETXEN_BUFFER_FREE
) {
1480 skb
= dev_alloc_skb(rcv_desc
->skb_size
);
1481 if (unlikely(!skb
)) {
1483 * We need to schedule the posting of buffers to the pegs.
1485 rcv_desc
->begin_alloc
= index
;
1486 DPRINTK(ERR
, "netxen_post_rx_buffers_nodb: "
1487 " allocated only %d buffers\n", count
);
1490 count
++; /* now there should be no failure */
1491 pdesc
= &rcv_desc
->desc_head
[producer
];
1492 skb_reserve(skb
, 2);
1494 * This will be setup when we receive the
1495 * buffer after it has been filled
1496 * skb->dev = netdev;
1499 buffer
->state
= NETXEN_BUFFER_BUSY
;
1500 buffer
->dma
= pci_map_single(pdev
, skb
->data
,
1502 PCI_DMA_FROMDEVICE
);
1504 /* make a rcv descriptor */
1505 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1506 pdesc
->buffer_length
= cpu_to_le32(rcv_desc
->dma_size
);
1507 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1508 DPRINTK(INFO
, "done writing descripter\n");
1510 get_next_index(producer
, rcv_desc
->max_rx_desc_count
);
1511 index
= get_next_index(index
, rcv_desc
->max_rx_desc_count
);
1512 buffer
= &rcv_desc
->rx_buf_arr
[index
];
1515 /* if we did allocate buffers, then write the count to Phantom */
1517 rcv_desc
->begin_alloc
= index
;
1518 rcv_desc
->rcv_pending
+= count
;
1519 rcv_desc
->producer
= producer
;
1520 if (rcv_desc
->rcv_free
>= 32) {
1521 rcv_desc
->rcv_free
= 0;
1523 writel((producer
- 1) &
1524 (rcv_desc
->max_rx_desc_count
- 1),
1525 NETXEN_CRB_NORMALIZE(adapter
,
1528 rcv_desc_crb
[ringid
].
1529 crb_rcv_producer_offset
));
1535 int netxen_nic_tx_has_work(struct netxen_adapter
*adapter
)
1537 if (find_diff_among(adapter
->last_cmd_consumer
,
1538 adapter
->cmd_producer
,
1539 adapter
->max_tx_desc_count
) > 0)
1546 void netxen_nic_clear_stats(struct netxen_adapter
*adapter
)
1548 memset(&adapter
->stats
, 0, sizeof(adapter
->stats
));