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 u64 sts_data
= le64_to_cpu(desc
->status_desc_data
);
1074 int index
= netxen_get_sts_refhandle(sts_data
);
1075 struct netxen_recv_context
*recv_ctx
= &(adapter
->recv_ctx
[ctxid
]);
1076 struct netxen_rx_buffer
*buffer
;
1077 struct sk_buff
*skb
;
1078 u32 length
= netxen_get_sts_totallength(sts_data
);
1080 struct netxen_rcv_desc_ctx
*rcv_desc
;
1083 desc_ctx
= netxen_get_sts_type(sts_data
);
1084 if (unlikely(desc_ctx
>= NUM_RCV_DESC_RINGS
)) {
1085 printk("%s: %s Bad Rcv descriptor ring\n",
1086 netxen_nic_driver_name
, netdev
->name
);
1090 rcv_desc
= &recv_ctx
->rcv_desc
[desc_ctx
];
1091 if (unlikely(index
> rcv_desc
->max_rx_desc_count
)) {
1092 DPRINTK(ERR
, "Got a buffer index:%x Max is %x\n",
1093 index
, rcv_desc
->max_rx_desc_count
);
1096 buffer
= &rcv_desc
->rx_buf_arr
[index
];
1097 if (desc_ctx
== RCV_DESC_LRO_CTXID
) {
1098 buffer
->lro_current_frags
++;
1099 if (netxen_get_sts_desc_lro_last_frag(desc
)) {
1100 buffer
->lro_expected_frags
=
1101 netxen_get_sts_desc_lro_cnt(desc
);
1102 buffer
->lro_length
= length
;
1104 if (buffer
->lro_current_frags
!= buffer
->lro_expected_frags
) {
1105 if (buffer
->lro_expected_frags
!= 0) {
1106 printk("LRO: (refhandle:%x) recv frag."
1107 "wait for last. flags: %x expected:%d"
1109 netxen_get_sts_desc_lro_last_frag(desc
),
1110 buffer
->lro_expected_frags
,
1111 buffer
->lro_current_frags
);
1117 pci_unmap_single(pdev
, buffer
->dma
, rcv_desc
->dma_size
,
1118 PCI_DMA_FROMDEVICE
);
1120 skb
= (struct sk_buff
*)buffer
->skb
;
1122 if (likely(adapter
->rx_csum
&&
1123 netxen_get_sts_status(sts_data
) == STATUS_CKSUM_OK
)) {
1124 adapter
->stats
.csummed
++;
1125 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1127 skb
->ip_summed
= CHECKSUM_NONE
;
1130 if (desc_ctx
== RCV_DESC_LRO_CTXID
) {
1131 /* True length was only available on the last pkt */
1132 skb_put(skb
, buffer
->lro_length
);
1134 skb_put(skb
, length
);
1137 skb
->protocol
= eth_type_trans(skb
, netdev
);
1139 ret
= netif_receive_skb(skb
);
1142 * RH: Do we need these stats on a regular basis. Can we get it from
1146 case NET_RX_SUCCESS
:
1147 adapter
->stats
.uphappy
++;
1151 adapter
->stats
.uplcong
++;
1155 adapter
->stats
.upmcong
++;
1158 case NET_RX_CN_HIGH
:
1159 adapter
->stats
.uphcong
++;
1163 adapter
->stats
.updropped
++;
1167 adapter
->stats
.updunno
++;
1171 netdev
->last_rx
= jiffies
;
1173 rcv_desc
->rcv_free
++;
1174 rcv_desc
->rcv_pending
--;
1177 * We just consumed one buffer so post a buffer.
1180 buffer
->state
= NETXEN_BUFFER_FREE
;
1181 buffer
->lro_current_frags
= 0;
1182 buffer
->lro_expected_frags
= 0;
1184 adapter
->stats
.no_rcv
++;
1185 adapter
->stats
.rxbytes
+= length
;
1188 /* Process Receive status ring */
1189 u32
netxen_process_rcv_ring(struct netxen_adapter
*adapter
, int ctxid
, int max
)
1191 struct netxen_recv_context
*recv_ctx
= &(adapter
->recv_ctx
[ctxid
]);
1192 struct status_desc
*desc_head
= recv_ctx
->rcv_status_desc_head
;
1193 struct status_desc
*desc
; /* used to read status desc here */
1194 u32 consumer
= recv_ctx
->status_rx_consumer
;
1196 int count
= 0, ring
;
1198 DPRINTK(INFO
, "procesing receive\n");
1200 * we assume in this case that there is only one port and that is
1201 * port #1...changes need to be done in firmware to indicate port
1202 * number as part of the descriptor. This way we will be able to get
1203 * the netdev which is associated with that device.
1205 while (count
< max
) {
1206 desc
= &desc_head
[consumer
];
1207 if (!(netxen_get_sts_owner(desc
) & STATUS_OWNER_HOST
)) {
1208 DPRINTK(ERR
, "desc %p ownedby %x\n", desc
,
1209 netxen_get_sts_owner(desc
));
1212 netxen_process_rcv(adapter
, ctxid
, desc
);
1213 netxen_set_sts_owner(desc
, STATUS_OWNER_PHANTOM
);
1214 consumer
= (consumer
+ 1) & (adapter
->max_rx_desc_count
- 1);
1218 for (ring
= 0; ring
< NUM_RCV_DESC_RINGS
; ring
++) {
1219 netxen_post_rx_buffers_nodb(adapter
, ctxid
, ring
);
1223 /* update the consumer index in phantom */
1225 recv_ctx
->status_rx_consumer
= consumer
;
1226 recv_ctx
->status_rx_producer
= producer
;
1230 NETXEN_CRB_NORMALIZE(adapter
,
1231 recv_crb_registers
[adapter
->portnum
].
1232 crb_rcv_status_consumer
));
1239 /* Process Command status ring */
1240 int netxen_process_cmd_ring(unsigned long data
)
1244 struct netxen_adapter
*adapter
= (struct netxen_adapter
*)data
;
1247 struct netxen_cmd_buffer
*buffer
;
1248 struct pci_dev
*pdev
;
1249 struct netxen_skb_frag
*frag
;
1253 spin_lock(&adapter
->tx_lock
);
1254 last_consumer
= adapter
->last_cmd_consumer
;
1255 DPRINTK(INFO
, "procesing xmit complete\n");
1256 /* we assume in this case that there is only one port and that is
1257 * port #1...changes need to be done in firmware to indicate port
1258 * number as part of the descriptor. This way we will be able to get
1259 * the netdev which is associated with that device.
1262 consumer
= le32_to_cpu(*(adapter
->cmd_consumer
));
1263 if (last_consumer
== consumer
) { /* Ring is empty */
1264 DPRINTK(INFO
, "last_consumer %d == consumer %d\n",
1265 last_consumer
, consumer
);
1266 spin_unlock(&adapter
->tx_lock
);
1270 adapter
->proc_cmd_buf_counter
++;
1272 * Not needed - does not seem to be used anywhere.
1273 * adapter->cmd_consumer = consumer;
1275 spin_unlock(&adapter
->tx_lock
);
1277 while ((last_consumer
!= consumer
) && (count1
< MAX_STATUS_HANDLE
)) {
1278 buffer
= &adapter
->cmd_buf_arr
[last_consumer
];
1279 pdev
= adapter
->pdev
;
1281 frag
= &buffer
->frag_array
[0];
1282 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
1285 for (i
= 1; i
< buffer
->frag_count
; i
++) {
1286 DPRINTK(INFO
, "getting fragment no %d\n", i
);
1287 frag
++; /* Get the next frag */
1288 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
1293 adapter
->stats
.skbfreed
++;
1294 dev_kfree_skb_any(buffer
->skb
);
1296 } else if (adapter
->proc_cmd_buf_counter
== 1) {
1297 adapter
->stats
.txnullskb
++;
1299 if (unlikely(netif_queue_stopped(adapter
->netdev
)
1300 && netif_carrier_ok(adapter
->netdev
))
1301 && ((jiffies
- adapter
->netdev
->trans_start
) >
1302 adapter
->netdev
->watchdog_timeo
)) {
1303 SCHEDULE_WORK(&adapter
->tx_timeout_task
);
1306 last_consumer
= get_next_index(last_consumer
,
1307 adapter
->max_tx_desc_count
);
1312 spin_lock(&adapter
->tx_lock
);
1313 if ((--adapter
->proc_cmd_buf_counter
) == 0) {
1314 adapter
->last_cmd_consumer
= last_consumer
;
1315 while ((adapter
->last_cmd_consumer
!= consumer
)
1316 && (count2
< MAX_STATUS_HANDLE
)) {
1318 &adapter
->cmd_buf_arr
[adapter
->last_cmd_consumer
];
1323 adapter
->last_cmd_consumer
=
1324 get_next_index(adapter
->last_cmd_consumer
,
1325 adapter
->max_tx_desc_count
);
1328 if (count1
|| count2
) {
1329 if (netif_queue_stopped(adapter
->netdev
)
1330 && (adapter
->flags
& NETXEN_NETDEV_STATUS
)) {
1331 netif_wake_queue(adapter
->netdev
);
1332 adapter
->flags
&= ~NETXEN_NETDEV_STATUS
;
1336 * If everything is freed up to consumer then check if the ring is full
1337 * If the ring is full then check if more needs to be freed and
1338 * schedule the call back again.
1340 * This happens when there are 2 CPUs. One could be freeing and the
1341 * other filling it. If the ring is full when we get out of here and
1342 * the card has already interrupted the host then the host can miss the
1345 * There is still a possible race condition and the host could miss an
1346 * interrupt. The card has to take care of this.
1348 if (adapter
->last_cmd_consumer
== consumer
&&
1349 (((adapter
->cmd_producer
+ 1) %
1350 adapter
->max_tx_desc_count
) == adapter
->last_cmd_consumer
)) {
1351 consumer
= le32_to_cpu(*(adapter
->cmd_consumer
));
1353 done
= (adapter
->last_cmd_consumer
== consumer
);
1355 spin_unlock(&adapter
->tx_lock
);
1356 DPRINTK(INFO
, "last consumer is %d in %s\n", last_consumer
,
1362 * netxen_post_rx_buffers puts buffer in the Phantom memory
1364 void netxen_post_rx_buffers(struct netxen_adapter
*adapter
, u32 ctx
, u32 ringid
)
1366 struct pci_dev
*pdev
= adapter
->ahw
.pdev
;
1367 struct sk_buff
*skb
;
1368 struct netxen_recv_context
*recv_ctx
= &(adapter
->recv_ctx
[ctx
]);
1369 struct netxen_rcv_desc_ctx
*rcv_desc
= NULL
;
1371 struct rcv_desc
*pdesc
;
1372 struct netxen_rx_buffer
*buffer
;
1375 netxen_ctx_msg msg
= 0;
1378 rcv_desc
= &recv_ctx
->rcv_desc
[ringid
];
1380 producer
= rcv_desc
->producer
;
1381 index
= rcv_desc
->begin_alloc
;
1382 buffer
= &rcv_desc
->rx_buf_arr
[index
];
1383 /* We can start writing rx descriptors into the phantom memory. */
1384 while (buffer
->state
== NETXEN_BUFFER_FREE
) {
1385 skb
= dev_alloc_skb(rcv_desc
->skb_size
);
1386 if (unlikely(!skb
)) {
1389 * We need to schedule the posting of buffers to the pegs.
1391 rcv_desc
->begin_alloc
= index
;
1392 DPRINTK(ERR
, "netxen_post_rx_buffers: "
1393 " allocated only %d buffers\n", count
);
1397 count
++; /* now there should be no failure */
1398 pdesc
= &rcv_desc
->desc_head
[producer
];
1400 #if defined(XGB_DEBUG)
1401 *(unsigned long *)(skb
->head
) = 0xc0debabe;
1402 if (skb_is_nonlinear(skb
)) {
1403 printk("Allocated SKB @%p is nonlinear\n");
1406 skb_reserve(skb
, 2);
1407 /* This will be setup when we receive the
1408 * buffer after it has been filled FSL TBD TBD
1409 * skb->dev = netdev;
1411 dma
= pci_map_single(pdev
, skb
->data
, rcv_desc
->dma_size
,
1412 PCI_DMA_FROMDEVICE
);
1413 pdesc
->addr_buffer
= cpu_to_le64(dma
);
1415 buffer
->state
= NETXEN_BUFFER_BUSY
;
1417 /* make a rcv descriptor */
1418 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1419 pdesc
->buffer_length
= cpu_to_le32(rcv_desc
->dma_size
);
1420 DPRINTK(INFO
, "done writing descripter\n");
1422 get_next_index(producer
, rcv_desc
->max_rx_desc_count
);
1423 index
= get_next_index(index
, rcv_desc
->max_rx_desc_count
);
1424 buffer
= &rcv_desc
->rx_buf_arr
[index
];
1426 /* if we did allocate buffers, then write the count to Phantom */
1428 rcv_desc
->begin_alloc
= index
;
1429 rcv_desc
->rcv_pending
+= count
;
1430 rcv_desc
->producer
= producer
;
1431 if (rcv_desc
->rcv_free
>= 32) {
1432 rcv_desc
->rcv_free
= 0;
1434 writel((producer
- 1) &
1435 (rcv_desc
->max_rx_desc_count
- 1),
1436 NETXEN_CRB_NORMALIZE(adapter
,
1439 rcv_desc_crb
[ringid
].
1440 crb_rcv_producer_offset
));
1442 * Write a doorbell msg to tell phanmon of change in
1443 * receive ring producer
1445 netxen_set_msg_peg_id(msg
, NETXEN_RCV_PEG_DB_ID
);
1446 netxen_set_msg_privid(msg
);
1447 netxen_set_msg_count(msg
,
1450 max_rx_desc_count
- 1)));
1451 netxen_set_msg_ctxid(msg
, adapter
->portnum
);
1452 netxen_set_msg_opcode(msg
, NETXEN_RCV_PRODUCER(ringid
));
1454 DB_NORMALIZE(adapter
,
1455 NETXEN_RCV_PRODUCER_OFFSET
));
1461 void netxen_post_rx_buffers_nodb(struct netxen_adapter
*adapter
, uint32_t ctx
,
1464 struct pci_dev
*pdev
= adapter
->ahw
.pdev
;
1465 struct sk_buff
*skb
;
1466 struct netxen_recv_context
*recv_ctx
= &(adapter
->recv_ctx
[ctx
]);
1467 struct netxen_rcv_desc_ctx
*rcv_desc
= NULL
;
1469 struct rcv_desc
*pdesc
;
1470 struct netxen_rx_buffer
*buffer
;
1474 rcv_desc
= &recv_ctx
->rcv_desc
[ringid
];
1476 producer
= rcv_desc
->producer
;
1477 index
= rcv_desc
->begin_alloc
;
1478 buffer
= &rcv_desc
->rx_buf_arr
[index
];
1479 /* We can start writing rx descriptors into the phantom memory. */
1480 while (buffer
->state
== NETXEN_BUFFER_FREE
) {
1481 skb
= dev_alloc_skb(rcv_desc
->skb_size
);
1482 if (unlikely(!skb
)) {
1484 * We need to schedule the posting of buffers to the pegs.
1486 rcv_desc
->begin_alloc
= index
;
1487 DPRINTK(ERR
, "netxen_post_rx_buffers_nodb: "
1488 " allocated only %d buffers\n", count
);
1491 count
++; /* now there should be no failure */
1492 pdesc
= &rcv_desc
->desc_head
[producer
];
1493 skb_reserve(skb
, 2);
1495 * This will be setup when we receive the
1496 * buffer after it has been filled
1497 * skb->dev = netdev;
1500 buffer
->state
= NETXEN_BUFFER_BUSY
;
1501 buffer
->dma
= pci_map_single(pdev
, skb
->data
,
1503 PCI_DMA_FROMDEVICE
);
1505 /* make a rcv descriptor */
1506 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1507 pdesc
->buffer_length
= cpu_to_le32(rcv_desc
->dma_size
);
1508 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1509 DPRINTK(INFO
, "done writing descripter\n");
1511 get_next_index(producer
, rcv_desc
->max_rx_desc_count
);
1512 index
= get_next_index(index
, rcv_desc
->max_rx_desc_count
);
1513 buffer
= &rcv_desc
->rx_buf_arr
[index
];
1516 /* if we did allocate buffers, then write the count to Phantom */
1518 rcv_desc
->begin_alloc
= index
;
1519 rcv_desc
->rcv_pending
+= count
;
1520 rcv_desc
->producer
= producer
;
1521 if (rcv_desc
->rcv_free
>= 32) {
1522 rcv_desc
->rcv_free
= 0;
1524 writel((producer
- 1) &
1525 (rcv_desc
->max_rx_desc_count
- 1),
1526 NETXEN_CRB_NORMALIZE(adapter
,
1529 rcv_desc_crb
[ringid
].
1530 crb_rcv_producer_offset
));
1536 int netxen_nic_tx_has_work(struct netxen_adapter
*adapter
)
1538 if (find_diff_among(adapter
->last_cmd_consumer
,
1539 adapter
->cmd_producer
,
1540 adapter
->max_tx_desc_count
) > 0)
1547 void netxen_nic_clear_stats(struct netxen_adapter
*adapter
)
1549 memset(&adapter
->stats
, 0, sizeof(adapter
->stats
));