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 * Main source file for NetXen NIC Driver on Linux
34 #include <linux/vmalloc.h>
35 #include <linux/highmem.h>
36 #include "netxen_nic_hw.h"
38 #include "netxen_nic.h"
39 #include "netxen_nic_phan_reg.h"
41 #include <linux/dma-mapping.h>
44 MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
45 MODULE_LICENSE("GPL");
46 MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID
);
48 char netxen_nic_driver_name
[] = "netxen_nic";
49 static char netxen_nic_driver_string
[] = "NetXen Network Driver version "
50 NETXEN_NIC_LINUX_VERSIONID
;
52 static int port_mode
= NETXEN_PORT_MODE_AUTO_NEG
;
54 /* Default to restricted 1G auto-neg mode */
55 static int wol_port_mode
= 5;
57 static int use_msi
= 1;
59 static int use_msi_x
= 1;
61 /* Local functions to NetXen NIC driver */
62 static int __devinit
netxen_nic_probe(struct pci_dev
*pdev
,
63 const struct pci_device_id
*ent
);
64 static void __devexit
netxen_nic_remove(struct pci_dev
*pdev
);
65 static int netxen_nic_open(struct net_device
*netdev
);
66 static int netxen_nic_close(struct net_device
*netdev
);
67 static int netxen_nic_xmit_frame(struct sk_buff
*, struct net_device
*);
68 static void netxen_tx_timeout(struct net_device
*netdev
);
69 static void netxen_tx_timeout_task(struct work_struct
*work
);
70 static void netxen_watchdog(unsigned long);
71 static int netxen_nic_poll(struct napi_struct
*napi
, int budget
);
72 #ifdef CONFIG_NET_POLL_CONTROLLER
73 static void netxen_nic_poll_controller(struct net_device
*netdev
);
75 static irqreturn_t
netxen_intr(int irq
, void *data
);
76 static irqreturn_t
netxen_msi_intr(int irq
, void *data
);
78 /* PCI Device ID Table */
79 #define ENTRY(device) \
80 {PCI_DEVICE(0x4040, (device)), \
81 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
83 static struct pci_device_id netxen_pci_tbl
[] __devinitdata
= {
95 MODULE_DEVICE_TABLE(pci
, netxen_pci_tbl
);
98 * In netxen_nic_down(), we must wait for any pending callback requests into
99 * netxen_watchdog_task() to complete; eg otherwise the watchdog_timer could be
100 * reenabled right after it is deleted in netxen_nic_down().
101 * FLUSH_SCHEDULED_WORK() does this synchronization.
103 * Normally, schedule_work()/flush_scheduled_work() could have worked, but
104 * netxen_nic_close() is invoked with kernel rtnl lock held. netif_carrier_off()
105 * call in netxen_nic_close() triggers a schedule_work(&linkwatch_work), and a
106 * subsequent call to flush_scheduled_work() in netxen_nic_down() would cause
107 * linkwatch_event() to be executed which also attempts to acquire the rtnl
108 * lock thus causing a deadlock.
111 static struct workqueue_struct
*netxen_workq
;
112 #define SCHEDULE_WORK(tp) queue_work(netxen_workq, tp)
113 #define FLUSH_SCHEDULED_WORK() flush_workqueue(netxen_workq)
115 static void netxen_watchdog(unsigned long);
117 static uint32_t crb_cmd_producer
[4] = {
118 CRB_CMD_PRODUCER_OFFSET
, CRB_CMD_PRODUCER_OFFSET_1
,
119 CRB_CMD_PRODUCER_OFFSET_2
, CRB_CMD_PRODUCER_OFFSET_3
123 netxen_nic_update_cmd_producer(struct netxen_adapter
*adapter
,
124 uint32_t crb_producer
)
126 adapter
->pci_write_normalize(adapter
,
127 adapter
->crb_addr_cmd_producer
, crb_producer
);
130 static uint32_t crb_cmd_consumer
[4] = {
131 CRB_CMD_CONSUMER_OFFSET
, CRB_CMD_CONSUMER_OFFSET_1
,
132 CRB_CMD_CONSUMER_OFFSET_2
, CRB_CMD_CONSUMER_OFFSET_3
136 netxen_nic_update_cmd_consumer(struct netxen_adapter
*adapter
,
139 adapter
->pci_write_normalize(adapter
,
140 adapter
->crb_addr_cmd_consumer
, crb_consumer
);
143 static uint32_t msi_tgt_status
[8] = {
144 ISR_INT_TARGET_STATUS
, ISR_INT_TARGET_STATUS_F1
,
145 ISR_INT_TARGET_STATUS_F2
, ISR_INT_TARGET_STATUS_F3
,
146 ISR_INT_TARGET_STATUS_F4
, ISR_INT_TARGET_STATUS_F5
,
147 ISR_INT_TARGET_STATUS_F6
, ISR_INT_TARGET_STATUS_F7
150 static struct netxen_legacy_intr_set legacy_intr
[] = NX_LEGACY_INTR_CONFIG
;
152 static void netxen_nic_disable_int(struct netxen_adapter
*adapter
)
156 int pci_fn
= adapter
->ahw
.pci_func
;
158 if (adapter
->msi_mode
!= MSI_MODE_MULTIFUNC
)
159 adapter
->pci_write_normalize(adapter
,
160 adapter
->crb_intr_mask
, 0);
162 if (adapter
->intr_scheme
!= -1 &&
163 adapter
->intr_scheme
!= INTR_SCHEME_PERPORT
)
164 adapter
->pci_write_immediate(adapter
, ISR_INT_MASK
, mask
);
166 if (!NETXEN_IS_MSI_FAMILY(adapter
)) {
168 adapter
->pci_write_immediate(adapter
,
169 ISR_INT_TARGET_STATUS
, 0xffffffff);
170 mask
= adapter
->pci_read_immediate(adapter
,
178 printk(KERN_NOTICE
"%s: Failed to disable interrupt completely\n",
179 netxen_nic_driver_name
);
182 if (adapter
->msi_mode
== MSI_MODE_MULTIFUNC
) {
183 adapter
->pci_write_immediate(adapter
,
184 msi_tgt_status
[pci_fn
], 0xffffffff);
189 static void netxen_nic_enable_int(struct netxen_adapter
*adapter
)
193 DPRINTK(1, INFO
, "Entered ISR Enable \n");
195 if (adapter
->intr_scheme
!= -1 &&
196 adapter
->intr_scheme
!= INTR_SCHEME_PERPORT
) {
197 switch (adapter
->ahw
.board_type
) {
201 case NETXEN_NIC_XGBE
:
209 adapter
->pci_write_immediate(adapter
, ISR_INT_MASK
, mask
);
212 adapter
->pci_write_normalize(adapter
, adapter
->crb_intr_mask
, 0x1);
214 if (!NETXEN_IS_MSI_FAMILY(adapter
)) {
216 if (adapter
->intr_scheme
!= -1 &&
217 adapter
->intr_scheme
!= INTR_SCHEME_PERPORT
) {
218 adapter
->pci_write_normalize(adapter
,
221 adapter
->pci_write_immediate(adapter
,
222 ISR_INT_TARGET_MASK
, mask
);
225 DPRINTK(1, INFO
, "Done with enable Int\n");
228 static int nx_set_dma_mask(struct netxen_adapter
*adapter
, uint8_t revision_id
)
230 struct pci_dev
*pdev
= adapter
->pdev
;
235 adapter
->dma_mask
= DMA_32BIT_MASK
;
237 if (revision_id
>= NX_P3_B0
) {
238 /* should go to DMA_64BIT_MASK */
239 adapter
->dma_mask
= DMA_39BIT_MASK
;
240 mask
= DMA_39BIT_MASK
;
241 } else if (revision_id
== NX_P3_A2
) {
242 adapter
->dma_mask
= DMA_39BIT_MASK
;
243 mask
= DMA_39BIT_MASK
;
244 } else if (revision_id
== NX_P2_C1
) {
245 adapter
->dma_mask
= DMA_35BIT_MASK
;
246 mask
= DMA_35BIT_MASK
;
248 adapter
->dma_mask
= DMA_32BIT_MASK
;
249 mask
= DMA_32BIT_MASK
;
250 goto set_32_bit_mask
;
254 * Consistent DMA mask is set to 32 bit because it cannot be set to
255 * 35 bits. For P3 also leave it at 32 bits for now. Only the rings
256 * come off this pool.
258 if (pci_set_dma_mask(pdev
, mask
) == 0 &&
259 pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
) == 0) {
260 adapter
->pci_using_dac
= 1;
263 #endif /* CONFIG_IA64 */
266 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
268 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
270 DPRINTK(ERR
, "No usable DMA configuration, aborting:%d\n", err
);
274 adapter
->pci_using_dac
= 0;
278 static void netxen_check_options(struct netxen_adapter
*adapter
)
280 switch (adapter
->ahw
.boardcfg
.board_type
) {
281 case NETXEN_BRDTYPE_P3_HMEZ
:
282 case NETXEN_BRDTYPE_P3_XG_LOM
:
283 case NETXEN_BRDTYPE_P3_10G_CX4
:
284 case NETXEN_BRDTYPE_P3_10G_CX4_LP
:
285 case NETXEN_BRDTYPE_P3_IMEZ
:
286 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS
:
287 case NETXEN_BRDTYPE_P3_10G_XFP
:
288 case NETXEN_BRDTYPE_P3_10000_BASE_T
:
289 adapter
->msix_supported
= !!use_msi_x
;
290 adapter
->max_rx_desc_count
= MAX_RCV_DESCRIPTORS_10G
;
293 case NETXEN_BRDTYPE_P2_SB31_10G
:
294 case NETXEN_BRDTYPE_P2_SB31_10G_CX4
:
295 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
296 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
297 adapter
->msix_supported
= 0;
298 adapter
->max_rx_desc_count
= MAX_RCV_DESCRIPTORS_10G
;
301 case NETXEN_BRDTYPE_P3_REF_QG
:
302 case NETXEN_BRDTYPE_P3_4_GB
:
303 case NETXEN_BRDTYPE_P3_4_GB_MM
:
304 case NETXEN_BRDTYPE_P2_SB35_4G
:
305 case NETXEN_BRDTYPE_P2_SB31_2G
:
306 adapter
->msix_supported
= 0;
307 adapter
->max_rx_desc_count
= MAX_RCV_DESCRIPTORS_1G
;
311 adapter
->msix_supported
= 0;
312 adapter
->max_rx_desc_count
= MAX_RCV_DESCRIPTORS_1G
;
314 printk(KERN_WARNING
"Unknown board type(0x%x)\n",
315 adapter
->ahw
.boardcfg
.board_type
);
319 adapter
->max_tx_desc_count
= MAX_CMD_DESCRIPTORS_HOST
;
320 adapter
->max_jumbo_rx_desc_count
= MAX_JUMBO_RCV_DESCRIPTORS
;
321 adapter
->max_lro_rx_desc_count
= MAX_LRO_RCV_DESCRIPTORS
;
323 adapter
->max_possible_rss_rings
= 1;
328 netxen_check_hw_init(struct netxen_adapter
*adapter
, int first_boot
)
332 if (first_boot
== 0x55555555) {
333 /* This is the first boot after power up */
335 /* PCI bus master workaround */
336 adapter
->hw_read_wx(adapter
,
337 NETXEN_PCIE_REG(0x4), &first_boot
, 4);
338 if (!(first_boot
& 0x4)) {
340 adapter
->hw_write_wx(adapter
,
341 NETXEN_PCIE_REG(0x4), &first_boot
, 4);
342 adapter
->hw_read_wx(adapter
,
343 NETXEN_PCIE_REG(0x4), &first_boot
, 4);
346 /* This is the first boot after power up */
347 adapter
->hw_read_wx(adapter
,
348 NETXEN_ROMUSB_GLB_SW_RESET
, &first_boot
, 4);
349 if (first_boot
!= 0x80000f) {
350 /* clear the register for future unloads/loads */
351 adapter
->pci_write_normalize(adapter
,
352 NETXEN_CAM_RAM(0x1fc), 0);
356 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
357 /* Start P2 boot loader */
358 adapter
->pci_write_normalize(adapter
,
359 NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC
);
360 adapter
->pci_write_normalize(adapter
,
361 NETXEN_ROMUSB_GLB_PEGTUNE_DONE
, 1);
367 static void netxen_set_port_mode(struct netxen_adapter
*adapter
)
371 val
= adapter
->ahw
.boardcfg
.board_type
;
372 if ((val
== NETXEN_BRDTYPE_P3_HMEZ
) ||
373 (val
== NETXEN_BRDTYPE_P3_XG_LOM
)) {
374 if (port_mode
== NETXEN_PORT_MODE_802_3_AP
) {
375 data
= NETXEN_PORT_MODE_802_3_AP
;
376 adapter
->hw_write_wx(adapter
,
377 NETXEN_PORT_MODE_ADDR
, &data
, 4);
378 } else if (port_mode
== NETXEN_PORT_MODE_XG
) {
379 data
= NETXEN_PORT_MODE_XG
;
380 adapter
->hw_write_wx(adapter
,
381 NETXEN_PORT_MODE_ADDR
, &data
, 4);
382 } else if (port_mode
== NETXEN_PORT_MODE_AUTO_NEG_1G
) {
383 data
= NETXEN_PORT_MODE_AUTO_NEG_1G
;
384 adapter
->hw_write_wx(adapter
,
385 NETXEN_PORT_MODE_ADDR
, &data
, 4);
386 } else if (port_mode
== NETXEN_PORT_MODE_AUTO_NEG_XG
) {
387 data
= NETXEN_PORT_MODE_AUTO_NEG_XG
;
388 adapter
->hw_write_wx(adapter
,
389 NETXEN_PORT_MODE_ADDR
, &data
, 4);
391 data
= NETXEN_PORT_MODE_AUTO_NEG
;
392 adapter
->hw_write_wx(adapter
,
393 NETXEN_PORT_MODE_ADDR
, &data
, 4);
396 if ((wol_port_mode
!= NETXEN_PORT_MODE_802_3_AP
) &&
397 (wol_port_mode
!= NETXEN_PORT_MODE_XG
) &&
398 (wol_port_mode
!= NETXEN_PORT_MODE_AUTO_NEG_1G
) &&
399 (wol_port_mode
!= NETXEN_PORT_MODE_AUTO_NEG_XG
)) {
400 wol_port_mode
= NETXEN_PORT_MODE_AUTO_NEG
;
402 adapter
->hw_write_wx(adapter
, NETXEN_WOL_PORT_MODE
,
407 #define PCI_CAP_ID_GEN 0x10
409 static void netxen_pcie_strap_init(struct netxen_adapter
*adapter
)
416 struct pci_dev
*pdev
;
418 pdev
= pci_get_device(0x1166, 0x0140, NULL
);
421 adapter
->hw_read_wx(adapter
,
422 NETXEN_PCIE_REG(PCIE_TGT_SPLIT_CHICKEN
), &chicken
, 4);
424 adapter
->hw_write_wx(adapter
,
425 NETXEN_PCIE_REG(PCIE_TGT_SPLIT_CHICKEN
), &chicken
, 4);
428 pdev
= adapter
->pdev
;
430 adapter
->hw_read_wx(adapter
,
431 NETXEN_PCIE_REG(PCIE_CHICKEN3
), &chicken
, 4);
432 /* clear chicken3.25:24 */
433 chicken
&= 0xFCFFFFFF;
435 * if gen1 and B0, set F1020 - if gen 2, do nothing
436 * if gen2 set to F1000
438 pos
= pci_find_capability(pdev
, PCI_CAP_ID_GEN
);
440 pci_read_config_dword(pdev
, pos
+ 0x10, &control
);
441 if ((control
& 0x000F0000) != 0x00020000) {
442 /* set chicken3.24 if gen1 */
443 chicken
|= 0x01000000;
445 printk(KERN_INFO
"%s Gen2 strapping detected\n",
446 netxen_nic_driver_name
);
449 /* set chicken3.24 if gen1 */
450 chicken
|= 0x01000000;
451 printk(KERN_INFO
"%s Gen1 strapping detected\n",
452 netxen_nic_driver_name
);
453 if (adapter
->ahw
.revision_id
== NX_P3_B0
)
459 adapter
->hw_write_wx(adapter
,
460 NETXEN_PCIE_REG(PCIE_CHICKEN3
), &chicken
, 4);
465 pdevfuncsave
= pdev
->devfn
;
466 if (pdevfuncsave
& 0x07)
469 for (i
= 0; i
< 8; i
++) {
470 pci_read_config_dword(pdev
, pos
+ 8, &control
);
471 pci_read_config_dword(pdev
, pos
+ 8, &control
);
472 pci_write_config_dword(pdev
, pos
+ 8, c8c9value
);
475 pdev
->devfn
= pdevfuncsave
;
478 static void netxen_set_msix_bit(struct pci_dev
*pdev
, int enable
)
483 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
485 pci_read_config_dword(pdev
, pos
, &control
);
487 control
|= PCI_MSIX_FLAGS_ENABLE
;
490 pci_write_config_dword(pdev
, pos
, control
);
494 static void netxen_init_msix_entries(struct netxen_adapter
*adapter
)
498 for (i
= 0; i
< MSIX_ENTRIES_PER_ADAPTER
; i
++)
499 adapter
->msix_entries
[i
].entry
= i
;
505 * The Linux system will invoke this after identifying the vendor ID and
506 * device Id in the pci_tbl supported by this module.
508 * A quad port card has one operational PCI config space, (function 0),
509 * which is used to access all four ports.
511 * This routine will initialize the adapter, and setup the global parameters
512 * along with the port's specific structure.
515 netxen_nic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
517 struct net_device
*netdev
= NULL
;
518 struct netxen_adapter
*adapter
= NULL
;
519 void __iomem
*mem_ptr0
= NULL
;
520 void __iomem
*mem_ptr1
= NULL
;
521 void __iomem
*mem_ptr2
= NULL
;
522 unsigned long first_page_group_end
;
523 unsigned long first_page_group_start
;
526 u8 __iomem
*db_ptr
= NULL
;
527 unsigned long mem_base
, mem_len
, db_base
, db_len
, pci_len0
= 0;
529 int first_driver
, first_boot
;
530 __le64 mac_addr
[FLASH_NUM_PORTS
+ 1];
532 int pci_func_id
= PCI_FUNC(pdev
->devfn
);
533 DECLARE_MAC_BUF(mac
);
534 struct netxen_legacy_intr_set
*legacy_intrp
;
537 if (pci_func_id
== 0)
538 printk(KERN_INFO
"%s\n", netxen_nic_driver_string
);
540 if (pdev
->class != 0x020000) {
541 printk(KERN_DEBUG
"NetXen function %d, class %x will not "
542 "be enabled.\n",pci_func_id
, pdev
->class);
546 if ((err
= pci_enable_device(pdev
)))
549 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
551 goto err_out_disable_pdev
;
554 if ((err
= pci_request_regions(pdev
, netxen_nic_driver_name
)))
555 goto err_out_disable_pdev
;
557 pci_set_master(pdev
);
559 netdev
= alloc_etherdev(sizeof(struct netxen_adapter
));
561 printk(KERN_ERR
"%s: Failed to allocate memory for the "
562 "device block.Check system memory resource"
563 " usage.\n", netxen_nic_driver_name
);
564 goto err_out_free_res
;
567 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
569 adapter
= netdev
->priv
;
570 adapter
->netdev
= netdev
;
571 adapter
->pdev
= pdev
;
572 adapter
->ahw
.pci_func
= pci_func_id
;
574 revision_id
= pdev
->revision
;
575 adapter
->ahw
.revision_id
= revision_id
;
577 err
= nx_set_dma_mask(adapter
, revision_id
);
579 goto err_out_free_netdev
;
581 rwlock_init(&adapter
->adapter_lock
);
582 adapter
->ahw
.qdr_sn_window
= -1;
583 adapter
->ahw
.ddr_mn_window
= -1;
585 /* remap phys address */
586 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
587 mem_len
= pci_resource_len(pdev
, 0);
590 adapter
->hw_write_wx
= netxen_nic_hw_write_wx_128M
;
591 adapter
->hw_read_wx
= netxen_nic_hw_read_wx_128M
;
592 adapter
->pci_read_immediate
= netxen_nic_pci_read_immediate_128M
;
593 adapter
->pci_write_immediate
= netxen_nic_pci_write_immediate_128M
;
594 adapter
->pci_read_normalize
= netxen_nic_pci_read_normalize_128M
;
595 adapter
->pci_write_normalize
= netxen_nic_pci_write_normalize_128M
;
596 adapter
->pci_set_window
= netxen_nic_pci_set_window_128M
;
597 adapter
->pci_mem_read
= netxen_nic_pci_mem_read_128M
;
598 adapter
->pci_mem_write
= netxen_nic_pci_mem_write_128M
;
600 /* 128 Meg of memory */
601 if (mem_len
== NETXEN_PCI_128MB_SIZE
) {
602 mem_ptr0
= ioremap(mem_base
, FIRST_PAGE_GROUP_SIZE
);
603 mem_ptr1
= ioremap(mem_base
+ SECOND_PAGE_GROUP_START
,
604 SECOND_PAGE_GROUP_SIZE
);
605 mem_ptr2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
,
606 THIRD_PAGE_GROUP_SIZE
);
607 first_page_group_start
= FIRST_PAGE_GROUP_START
;
608 first_page_group_end
= FIRST_PAGE_GROUP_END
;
609 } else if (mem_len
== NETXEN_PCI_32MB_SIZE
) {
610 mem_ptr1
= ioremap(mem_base
, SECOND_PAGE_GROUP_SIZE
);
611 mem_ptr2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
-
612 SECOND_PAGE_GROUP_START
, THIRD_PAGE_GROUP_SIZE
);
613 first_page_group_start
= 0;
614 first_page_group_end
= 0;
615 } else if (mem_len
== NETXEN_PCI_2MB_SIZE
) {
616 adapter
->hw_write_wx
= netxen_nic_hw_write_wx_2M
;
617 adapter
->hw_read_wx
= netxen_nic_hw_read_wx_2M
;
618 adapter
->pci_read_immediate
= netxen_nic_pci_read_immediate_2M
;
619 adapter
->pci_write_immediate
=
620 netxen_nic_pci_write_immediate_2M
;
621 adapter
->pci_read_normalize
= netxen_nic_pci_read_normalize_2M
;
622 adapter
->pci_write_normalize
=
623 netxen_nic_pci_write_normalize_2M
;
624 adapter
->pci_set_window
= netxen_nic_pci_set_window_2M
;
625 adapter
->pci_mem_read
= netxen_nic_pci_mem_read_2M
;
626 adapter
->pci_mem_write
= netxen_nic_pci_mem_write_2M
;
628 mem_ptr0
= ioremap(mem_base
, mem_len
);
630 first_page_group_start
= 0;
631 first_page_group_end
= 0;
633 adapter
->ahw
.ddr_mn_window
= 0;
634 adapter
->ahw
.qdr_sn_window
= 0;
636 adapter
->ahw
.mn_win_crb
= 0x100000 + PCIX_MN_WINDOW
+
637 (pci_func_id
* 0x20);
638 adapter
->ahw
.ms_win_crb
= 0x100000 + PCIX_SN_WINDOW
;
640 adapter
->ahw
.ms_win_crb
+= (pci_func_id
* 0x20);
642 adapter
->ahw
.ms_win_crb
+=
643 0xA0 + ((pci_func_id
- 4) * 0x10);
646 goto err_out_free_netdev
;
649 dev_info(&pdev
->dev
, "%dMB memory map\n", (int)(mem_len
>>20));
651 db_base
= pci_resource_start(pdev
, 4); /* doorbell is on bar 4 */
652 db_len
= pci_resource_len(pdev
, 4);
655 printk(KERN_ERR
"%s: doorbell is disabled\n",
656 netxen_nic_driver_name
);
658 goto err_out_iounmap
;
660 DPRINTK(INFO
, "doorbell ioremap from %lx a size of %lx\n", db_base
,
663 db_ptr
= ioremap(db_base
, NETXEN_DB_MAPSIZE_BYTES
);
665 printk(KERN_ERR
"%s: Failed to allocate doorbell map.",
666 netxen_nic_driver_name
);
668 goto err_out_iounmap
;
670 DPRINTK(INFO
, "doorbell ioremaped at %p\n", db_ptr
);
672 adapter
->ahw
.pci_base0
= mem_ptr0
;
673 adapter
->ahw
.pci_len0
= pci_len0
;
674 adapter
->ahw
.first_page_group_start
= first_page_group_start
;
675 adapter
->ahw
.first_page_group_end
= first_page_group_end
;
676 adapter
->ahw
.pci_base1
= mem_ptr1
;
677 adapter
->ahw
.pci_base2
= mem_ptr2
;
678 adapter
->ahw
.db_base
= db_ptr
;
679 adapter
->ahw
.db_len
= db_len
;
681 netif_napi_add(netdev
, &adapter
->napi
,
682 netxen_nic_poll
, NETXEN_NETDEV_WEIGHT
);
684 if (revision_id
>= NX_P3_B0
)
685 legacy_intrp
= &legacy_intr
[pci_func_id
];
687 legacy_intrp
= &legacy_intr
[0];
689 adapter
->legacy_intr
.int_vec_bit
= legacy_intrp
->int_vec_bit
;
690 adapter
->legacy_intr
.tgt_status_reg
= legacy_intrp
->tgt_status_reg
;
691 adapter
->legacy_intr
.tgt_mask_reg
= legacy_intrp
->tgt_mask_reg
;
692 adapter
->legacy_intr
.pci_int_reg
= legacy_intrp
->pci_int_reg
;
694 /* this will be read from FW later */
695 adapter
->intr_scheme
= -1;
696 adapter
->msi_mode
= -1;
698 /* This will be reset for mezz cards */
699 adapter
->portnum
= pci_func_id
;
700 adapter
->status
&= ~NETXEN_NETDEV_STATUS
;
701 adapter
->rx_csum
= 1;
702 adapter
->mc_enabled
= 0;
703 if (NX_IS_REVISION_P3(revision_id
)) {
704 adapter
->max_mc_count
= 38;
705 adapter
->max_rds_rings
= 2;
707 adapter
->max_mc_count
= 16;
708 adapter
->max_rds_rings
= 3;
711 netdev
->open
= netxen_nic_open
;
712 netdev
->stop
= netxen_nic_close
;
713 netdev
->hard_start_xmit
= netxen_nic_xmit_frame
;
714 netdev
->get_stats
= netxen_nic_get_stats
;
715 if (NX_IS_REVISION_P3(revision_id
))
716 netdev
->set_multicast_list
= netxen_p3_nic_set_multi
;
718 netdev
->set_multicast_list
= netxen_p2_nic_set_multi
;
719 netdev
->set_mac_address
= netxen_nic_set_mac
;
720 netdev
->change_mtu
= netxen_nic_change_mtu
;
721 netdev
->tx_timeout
= netxen_tx_timeout
;
722 netdev
->watchdog_timeo
= 2*HZ
;
724 netxen_nic_change_mtu(netdev
, netdev
->mtu
);
726 SET_ETHTOOL_OPS(netdev
, &netxen_nic_ethtool_ops
);
727 #ifdef CONFIG_NET_POLL_CONTROLLER
728 netdev
->poll_controller
= netxen_nic_poll_controller
;
730 /* ScatterGather support */
731 netdev
->features
= NETIF_F_SG
;
732 netdev
->features
|= NETIF_F_IP_CSUM
;
733 netdev
->features
|= NETIF_F_TSO
;
734 if (NX_IS_REVISION_P3(revision_id
)) {
735 netdev
->features
|= NETIF_F_IPV6_CSUM
;
736 netdev
->features
|= NETIF_F_TSO6
;
739 if (adapter
->pci_using_dac
)
740 netdev
->features
|= NETIF_F_HIGHDMA
;
743 * Set the CRB window to invalid. If any register in window 0 is
744 * accessed it should set the window to 0 and then reset it to 1.
746 adapter
->curr_window
= 255;
748 if (netxen_nic_get_board_info(adapter
) != 0) {
749 printk("%s: Error getting board config info.\n",
750 netxen_nic_driver_name
);
752 goto err_out_iounmap
;
755 netxen_initialize_adapter_ops(adapter
);
757 /* Mezz cards have PCI function 0,2,3 enabled */
758 switch (adapter
->ahw
.boardcfg
.board_type
) {
759 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
760 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
761 if (pci_func_id
>= 2)
762 adapter
->portnum
= pci_func_id
- 2;
769 * This call will setup various max rx/tx counts.
770 * It must be done before any buffer/ring allocations.
772 netxen_check_options(adapter
);
775 if (NX_IS_REVISION_P3(revision_id
)) {
776 if (adapter
->ahw
.pci_func
== 0)
779 if (adapter
->portnum
== 0)
782 adapter
->crb_addr_cmd_producer
= crb_cmd_producer
[adapter
->portnum
];
783 adapter
->crb_addr_cmd_consumer
= crb_cmd_consumer
[adapter
->portnum
];
784 netxen_nic_update_cmd_producer(adapter
, 0);
785 netxen_nic_update_cmd_consumer(adapter
, 0);
788 first_boot
= adapter
->pci_read_normalize(adapter
,
789 NETXEN_CAM_RAM(0x1fc));
791 err
= netxen_check_hw_init(adapter
, first_boot
);
793 printk(KERN_ERR
"%s: error in init HW init sequence\n",
794 netxen_nic_driver_name
);
795 goto err_out_iounmap
;
798 if (NX_IS_REVISION_P3(revision_id
))
799 netxen_set_port_mode(adapter
);
801 if (first_boot
!= 0x55555555) {
802 adapter
->pci_write_normalize(adapter
,
803 CRB_CMDPEG_STATE
, 0);
804 netxen_pinit_from_rom(adapter
, 0);
806 netxen_load_firmware(adapter
);
809 if (NX_IS_REVISION_P3(revision_id
))
810 netxen_pcie_strap_init(adapter
);
812 if (NX_IS_REVISION_P2(revision_id
)) {
814 /* Initialize multicast addr pool owners */
816 if (adapter
->ahw
.board_type
== NETXEN_NIC_XGBE
)
818 netxen_crb_writelit_adapter(adapter
,
819 NETXEN_MAC_ADDR_CNTL_REG
, val
);
823 if ((first_boot
== 0x55555555) &&
824 (NX_IS_REVISION_P2(revision_id
))) {
825 /* Unlock the HW, prompting the boot sequence */
826 adapter
->pci_write_normalize(adapter
,
827 NETXEN_ROMUSB_GLB_PEGTUNE_DONE
, 1);
830 err
= netxen_initialize_adapter_offload(adapter
);
832 goto err_out_iounmap
;
835 * Tell the hardware our version number.
837 i
= (_NETXEN_NIC_LINUX_MAJOR
<< 16)
838 | ((_NETXEN_NIC_LINUX_MINOR
<< 8))
839 | (_NETXEN_NIC_LINUX_SUBVERSION
);
840 adapter
->pci_write_normalize(adapter
, CRB_DRIVER_VERSION
, i
);
842 /* Handshake with the card before we register the devices. */
843 netxen_phantom_init(adapter
, NETXEN_NIC_PEG_TUNE
);
847 netxen_nic_flash_print(adapter
);
849 if (NX_IS_REVISION_P3(revision_id
)) {
850 adapter
->hw_read_wx(adapter
,
851 NETXEN_MIU_MN_CONTROL
, &val
, 4);
852 adapter
->ahw
.cut_through
= (val
& 0x4) ? 1 : 0;
853 dev_info(&pdev
->dev
, "firmware running in %s mode\n",
854 adapter
->ahw
.cut_through
? "cut through" : "legacy");
858 * See if the firmware gave us a virtual-physical port mapping.
860 adapter
->physical_port
= adapter
->portnum
;
861 i
= adapter
->pci_read_normalize(adapter
, CRB_V2P(adapter
->portnum
));
863 adapter
->physical_port
= i
;
865 adapter
->flags
&= ~(NETXEN_NIC_MSI_ENABLED
| NETXEN_NIC_MSIX_ENABLED
);
867 netxen_set_msix_bit(pdev
, 0);
869 if (NX_IS_REVISION_P3(revision_id
)) {
870 if ((mem_len
!= NETXEN_PCI_128MB_SIZE
) &&
871 mem_len
!= NETXEN_PCI_2MB_SIZE
)
872 adapter
->msix_supported
= 0;
875 if (adapter
->msix_supported
) {
877 netxen_init_msix_entries(adapter
);
879 if (pci_enable_msix(pdev
, adapter
->msix_entries
,
880 MSIX_ENTRIES_PER_ADAPTER
))
883 adapter
->flags
|= NETXEN_NIC_MSIX_ENABLED
;
884 netxen_set_msix_bit(pdev
, 1);
885 dev_info(&pdev
->dev
, "using msi-x interrupts\n");
889 if (use_msi
&& !pci_enable_msi(pdev
)) {
890 adapter
->flags
|= NETXEN_NIC_MSI_ENABLED
;
891 dev_info(&pdev
->dev
, "using msi interrupts\n");
893 dev_info(&pdev
->dev
, "using legacy interrupts\n");
896 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
897 netdev
->irq
= adapter
->msix_entries
[0].vector
;
899 netdev
->irq
= pdev
->irq
;
901 err
= netxen_receive_peg_ready(adapter
);
903 goto err_out_disable_msi
;
905 init_timer(&adapter
->watchdog_timer
);
906 adapter
->ahw
.linkup
= 0;
907 adapter
->watchdog_timer
.function
= &netxen_watchdog
;
908 adapter
->watchdog_timer
.data
= (unsigned long)adapter
;
909 INIT_WORK(&adapter
->watchdog_task
, netxen_watchdog_task
);
910 INIT_WORK(&adapter
->tx_timeout_task
, netxen_tx_timeout_task
);
912 if (netxen_is_flash_supported(adapter
) == 0 &&
913 netxen_get_flash_mac_addr(adapter
, mac_addr
) == 0) {
916 p
= (unsigned char *)&mac_addr
[adapter
->portnum
];
917 netdev
->dev_addr
[0] = *(p
+ 5);
918 netdev
->dev_addr
[1] = *(p
+ 4);
919 netdev
->dev_addr
[2] = *(p
+ 3);
920 netdev
->dev_addr
[3] = *(p
+ 2);
921 netdev
->dev_addr
[4] = *(p
+ 1);
922 netdev
->dev_addr
[5] = *(p
+ 0);
924 memcpy(netdev
->perm_addr
, netdev
->dev_addr
,
926 if (!is_valid_ether_addr(netdev
->perm_addr
)) {
927 printk(KERN_ERR
"%s: Bad MAC address %s.\n",
928 netxen_nic_driver_name
,
929 print_mac(mac
, netdev
->dev_addr
));
931 adapter
->macaddr_set(adapter
, netdev
->dev_addr
);
935 netif_carrier_off(netdev
);
936 netif_stop_queue(netdev
);
938 if ((err
= register_netdev(netdev
))) {
939 printk(KERN_ERR
"%s: register_netdev failed port #%d"
940 " aborting\n", netxen_nic_driver_name
,
943 goto err_out_disable_msi
;
946 pci_set_drvdata(pdev
, adapter
);
948 switch (adapter
->ahw
.board_type
) {
950 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
951 adapter
->netdev
->name
);
953 case NETXEN_NIC_XGBE
:
954 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
955 adapter
->netdev
->name
);
962 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
963 pci_disable_msix(pdev
);
964 if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
965 pci_disable_msi(pdev
);
968 netxen_free_adapter_offload(adapter
);
985 pci_release_regions(pdev
);
987 err_out_disable_pdev
:
988 pci_set_drvdata(pdev
, NULL
);
989 pci_disable_device(pdev
);
993 static void __devexit
netxen_nic_remove(struct pci_dev
*pdev
)
995 struct netxen_adapter
*adapter
;
996 struct net_device
*netdev
;
998 adapter
= pci_get_drvdata(pdev
);
1002 netdev
= adapter
->netdev
;
1004 unregister_netdev(netdev
);
1006 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
) {
1007 netxen_free_hw_resources(adapter
);
1008 netxen_free_sw_resources(adapter
);
1011 if (adapter
->portnum
== 0)
1012 netxen_free_adapter_offload(adapter
);
1015 free_irq(adapter
->irq
, adapter
);
1017 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
1018 pci_disable_msix(pdev
);
1019 if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
1020 pci_disable_msi(pdev
);
1022 iounmap(adapter
->ahw
.db_base
);
1023 iounmap(adapter
->ahw
.pci_base0
);
1024 iounmap(adapter
->ahw
.pci_base1
);
1025 iounmap(adapter
->ahw
.pci_base2
);
1027 pci_release_regions(pdev
);
1028 pci_disable_device(pdev
);
1029 pci_set_drvdata(pdev
, NULL
);
1031 free_netdev(netdev
);
1035 * Called when a network interface is made active
1036 * @returns 0 on success, negative value on failure
1038 static int netxen_nic_open(struct net_device
*netdev
)
1040 struct netxen_adapter
*adapter
= (struct netxen_adapter
*)netdev
->priv
;
1043 irq_handler_t handler
;
1044 unsigned long flags
= IRQF_SAMPLE_RANDOM
;
1046 if (adapter
->driver_mismatch
)
1049 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
) {
1050 err
= netxen_init_firmware(adapter
);
1052 printk(KERN_ERR
"Failed to init firmware\n");
1056 err
= netxen_alloc_sw_resources(adapter
);
1058 printk(KERN_ERR
"%s: Error in setting sw resources\n",
1063 netxen_nic_clear_stats(adapter
);
1065 err
= netxen_alloc_hw_resources(adapter
);
1067 printk(KERN_ERR
"%s: Error in setting hw resources\n",
1069 goto err_out_free_sw
;
1072 if (adapter
->fw_major
< 4) {
1073 adapter
->crb_addr_cmd_producer
=
1074 crb_cmd_producer
[adapter
->portnum
];
1075 adapter
->crb_addr_cmd_consumer
=
1076 crb_cmd_consumer
[adapter
->portnum
];
1079 netxen_nic_update_cmd_producer(adapter
, 0);
1080 netxen_nic_update_cmd_consumer(adapter
, 0);
1082 for (ctx
= 0; ctx
< MAX_RCV_CTX
; ++ctx
) {
1083 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++)
1084 netxen_post_rx_buffers(adapter
, ctx
, ring
);
1086 if (NETXEN_IS_MSI_FAMILY(adapter
))
1087 handler
= netxen_msi_intr
;
1089 flags
|= IRQF_SHARED
;
1090 handler
= netxen_intr
;
1092 adapter
->irq
= netdev
->irq
;
1093 err
= request_irq(adapter
->irq
, handler
,
1094 flags
, netdev
->name
, adapter
);
1096 printk(KERN_ERR
"request_irq failed with: %d\n", err
);
1097 goto err_out_free_hw
;
1100 adapter
->is_up
= NETXEN_ADAPTER_UP_MAGIC
;
1103 /* Done here again so that even if phantom sw overwrote it,
1105 err
= adapter
->init_port(adapter
, adapter
->physical_port
);
1107 printk(KERN_ERR
"%s: Failed to initialize port %d\n",
1108 netxen_nic_driver_name
, adapter
->portnum
);
1109 goto err_out_free_irq
;
1111 adapter
->macaddr_set(adapter
, netdev
->dev_addr
);
1113 netxen_nic_set_link_parameters(adapter
);
1115 netdev
->set_multicast_list(netdev
);
1116 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1117 nx_fw_cmd_set_mtu(adapter
, netdev
->mtu
);
1119 adapter
->set_mtu(adapter
, netdev
->mtu
);
1121 mod_timer(&adapter
->watchdog_timer
, jiffies
);
1123 napi_enable(&adapter
->napi
);
1124 netxen_nic_enable_int(adapter
);
1126 netif_start_queue(netdev
);
1131 free_irq(adapter
->irq
, adapter
);
1133 netxen_free_hw_resources(adapter
);
1135 netxen_free_sw_resources(adapter
);
1140 * netxen_nic_close - Disables a network interface entry point
1142 static int netxen_nic_close(struct net_device
*netdev
)
1144 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1146 netif_carrier_off(netdev
);
1147 netif_stop_queue(netdev
);
1148 napi_disable(&adapter
->napi
);
1150 if (adapter
->stop_port
)
1151 adapter
->stop_port(adapter
);
1153 netxen_nic_disable_int(adapter
);
1155 netxen_release_tx_buffers(adapter
);
1157 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
) {
1158 FLUSH_SCHEDULED_WORK();
1159 del_timer_sync(&adapter
->watchdog_timer
);
1165 void netxen_tso_check(struct netxen_adapter
*adapter
,
1166 struct cmd_desc_type0
*desc
, struct sk_buff
*skb
)
1169 desc
->total_hdr_length
= (sizeof(struct ethhdr
) +
1170 ip_hdrlen(skb
) + tcp_hdrlen(skb
));
1172 if ((NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) &&
1173 (skb
->protocol
== htons(ETH_P_IPV6
)))
1174 netxen_set_cmd_desc_opcode(desc
, TX_TCP_LSO6
);
1176 netxen_set_cmd_desc_opcode(desc
, TX_TCP_LSO
);
1178 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1179 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
1180 netxen_set_cmd_desc_opcode(desc
, TX_TCP_PKT
);
1181 else if (ip_hdr(skb
)->protocol
== IPPROTO_UDP
)
1182 netxen_set_cmd_desc_opcode(desc
, TX_UDP_PKT
);
1186 desc
->tcp_hdr_offset
= skb_transport_offset(skb
);
1187 desc
->ip_hdr_offset
= skb_network_offset(skb
);
1190 static int netxen_nic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
1192 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1193 struct netxen_hardware_context
*hw
= &adapter
->ahw
;
1194 unsigned int first_seg_len
= skb
->len
- skb
->data_len
;
1195 struct netxen_skb_frag
*buffrag
;
1198 u32 producer
, consumer
;
1199 u32 saved_producer
= 0;
1200 struct cmd_desc_type0
*hwdesc
;
1202 struct netxen_cmd_buffer
*pbuf
= NULL
;
1205 u32 num_txd
= adapter
->max_tx_desc_count
;
1207 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
1209 /* There 4 fragments per descriptor */
1210 no_of_desc
= (frag_count
+ 3) >> 2;
1211 if (netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) {
1212 if (skb_shinfo(skb
)->gso_size
> 0) {
1215 if ((ip_hdrlen(skb
) + tcp_hdrlen(skb
) +
1216 sizeof(struct ethhdr
)) >
1217 (sizeof(struct cmd_desc_type0
) - 2)) {
1223 producer
= adapter
->cmd_producer
;
1225 consumer
= adapter
->last_cmd_consumer
;
1226 if ((no_of_desc
+2) > find_diff_among(producer
, consumer
, num_txd
)) {
1227 netif_stop_queue(netdev
);
1229 return NETDEV_TX_BUSY
;
1232 /* Copy the descriptors into the hardware */
1233 saved_producer
= producer
;
1234 hwdesc
= &hw
->cmd_desc_head
[producer
];
1235 memset(hwdesc
, 0, sizeof(struct cmd_desc_type0
));
1236 /* Take skb->data itself */
1237 pbuf
= &adapter
->cmd_buf_arr
[producer
];
1238 if ((netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
1239 skb_shinfo(skb
)->gso_size
> 0) {
1240 pbuf
->mss
= skb_shinfo(skb
)->gso_size
;
1241 hwdesc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
1246 pbuf
->total_length
= skb
->len
;
1248 pbuf
->cmd
= TX_ETHER_PKT
;
1249 pbuf
->frag_count
= frag_count
;
1250 pbuf
->port
= adapter
->portnum
;
1251 buffrag
= &pbuf
->frag_array
[0];
1252 buffrag
->dma
= pci_map_single(adapter
->pdev
, skb
->data
, first_seg_len
,
1254 buffrag
->length
= first_seg_len
;
1255 netxen_set_cmd_desc_totallength(hwdesc
, skb
->len
);
1256 netxen_set_cmd_desc_num_of_buff(hwdesc
, frag_count
);
1257 netxen_set_cmd_desc_opcode(hwdesc
, TX_ETHER_PKT
);
1259 netxen_set_cmd_desc_port(hwdesc
, adapter
->portnum
);
1260 netxen_set_cmd_desc_ctxid(hwdesc
, adapter
->portnum
);
1261 hwdesc
->buffer1_length
= cpu_to_le16(first_seg_len
);
1262 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
1264 for (i
= 1, k
= 1; i
< frag_count
; i
++, k
++) {
1265 struct skb_frag_struct
*frag
;
1267 unsigned long offset
;
1268 dma_addr_t temp_dma
;
1270 /* move to next desc. if there is a need */
1271 if ((i
& 0x3) == 0) {
1273 producer
= get_next_index(producer
, num_txd
);
1274 hwdesc
= &hw
->cmd_desc_head
[producer
];
1275 memset(hwdesc
, 0, sizeof(struct cmd_desc_type0
));
1276 pbuf
= &adapter
->cmd_buf_arr
[producer
];
1279 frag
= &skb_shinfo(skb
)->frags
[i
- 1];
1281 offset
= frag
->page_offset
;
1284 temp_dma
= pci_map_page(adapter
->pdev
, frag
->page
, offset
,
1285 len
, PCI_DMA_TODEVICE
);
1288 buffrag
->dma
= temp_dma
;
1289 buffrag
->length
= temp_len
;
1293 hwdesc
->buffer1_length
= cpu_to_le16(temp_len
);
1294 hwdesc
->addr_buffer1
= cpu_to_le64(temp_dma
);
1297 hwdesc
->buffer2_length
= cpu_to_le16(temp_len
);
1298 hwdesc
->addr_buffer2
= cpu_to_le64(temp_dma
);
1301 hwdesc
->buffer3_length
= cpu_to_le16(temp_len
);
1302 hwdesc
->addr_buffer3
= cpu_to_le64(temp_dma
);
1305 hwdesc
->buffer4_length
= cpu_to_le16(temp_len
);
1306 hwdesc
->addr_buffer4
= cpu_to_le64(temp_dma
);
1311 producer
= get_next_index(producer
, num_txd
);
1313 /* might change opcode to TX_TCP_LSO */
1314 netxen_tso_check(adapter
, &hw
->cmd_desc_head
[saved_producer
], skb
);
1316 /* For LSO, we need to copy the MAC/IP/TCP headers into
1317 * the descriptor ring
1319 if (netxen_get_cmd_desc_opcode(&hw
->cmd_desc_head
[saved_producer
])
1321 int hdr_len
, first_hdr_len
, more_hdr
;
1322 hdr_len
= hw
->cmd_desc_head
[saved_producer
].total_hdr_length
;
1323 if (hdr_len
> (sizeof(struct cmd_desc_type0
) - 2)) {
1324 first_hdr_len
= sizeof(struct cmd_desc_type0
) - 2;
1327 first_hdr_len
= hdr_len
;
1330 /* copy the MAC/IP/TCP headers to the cmd descriptor list */
1331 hwdesc
= &hw
->cmd_desc_head
[producer
];
1332 pbuf
= &adapter
->cmd_buf_arr
[producer
];
1335 /* copy the first 64 bytes */
1336 memcpy(((void *)hwdesc
) + 2,
1337 (void *)(skb
->data
), first_hdr_len
);
1338 producer
= get_next_index(producer
, num_txd
);
1341 hwdesc
= &hw
->cmd_desc_head
[producer
];
1342 pbuf
= &adapter
->cmd_buf_arr
[producer
];
1344 /* copy the next 64 bytes - should be enough except
1345 * for pathological case
1347 skb_copy_from_linear_data_offset(skb
, first_hdr_len
,
1351 producer
= get_next_index(producer
, num_txd
);
1355 adapter
->cmd_producer
= producer
;
1356 adapter
->stats
.txbytes
+= skb
->len
;
1358 netxen_nic_update_cmd_producer(adapter
, adapter
->cmd_producer
);
1360 adapter
->stats
.xmitcalled
++;
1361 netdev
->trans_start
= jiffies
;
1363 return NETDEV_TX_OK
;
1366 static int netxen_nic_check_temp(struct netxen_adapter
*adapter
)
1368 struct net_device
*netdev
= adapter
->netdev
;
1369 uint32_t temp
, temp_state
, temp_val
;
1372 temp
= adapter
->pci_read_normalize(adapter
, CRB_TEMP_STATE
);
1374 temp_state
= nx_get_temp_state(temp
);
1375 temp_val
= nx_get_temp_val(temp
);
1377 if (temp_state
== NX_TEMP_PANIC
) {
1379 "%s: Device temperature %d degrees C exceeds"
1380 " maximum allowed. Hardware has been shut down.\n",
1381 netxen_nic_driver_name
, temp_val
);
1383 netif_carrier_off(netdev
);
1384 netif_stop_queue(netdev
);
1386 } else if (temp_state
== NX_TEMP_WARN
) {
1387 if (adapter
->temp
== NX_TEMP_NORMAL
) {
1389 "%s: Device temperature %d degrees C "
1390 "exceeds operating range."
1391 " Immediate action needed.\n",
1392 netxen_nic_driver_name
, temp_val
);
1395 if (adapter
->temp
== NX_TEMP_WARN
) {
1397 "%s: Device temperature is now %d degrees C"
1398 " in normal range.\n", netxen_nic_driver_name
,
1402 adapter
->temp
= temp_state
;
1406 static void netxen_nic_handle_phy_intr(struct netxen_adapter
*adapter
)
1408 struct net_device
*netdev
= adapter
->netdev
;
1409 u32 val
, port
, linkup
;
1411 port
= adapter
->physical_port
;
1413 if (adapter
->ahw
.board_type
== NETXEN_NIC_GBE
) {
1414 val
= adapter
->pci_read_normalize(adapter
, CRB_XG_STATE
);
1415 linkup
= (val
>> port
) & 1;
1417 if (adapter
->fw_major
< 4) {
1418 val
= adapter
->pci_read_normalize(adapter
,
1420 val
= (val
>> port
*8) & 0xff;
1421 linkup
= (val
== XG_LINK_UP
);
1423 val
= adapter
->pci_read_normalize(adapter
,
1425 val
= XG_LINK_STATE_P3(adapter
->ahw
.pci_func
, val
);
1426 linkup
= (val
== XG_LINK_UP_P3
);
1430 if (adapter
->ahw
.linkup
&& !linkup
) {
1431 printk(KERN_INFO
"%s: %s NIC Link is down\n",
1432 netxen_nic_driver_name
, netdev
->name
);
1433 adapter
->ahw
.linkup
= 0;
1434 if (netif_running(netdev
)) {
1435 netif_carrier_off(netdev
);
1436 netif_stop_queue(netdev
);
1438 } else if (!adapter
->ahw
.linkup
&& linkup
) {
1439 printk(KERN_INFO
"%s: %s NIC Link is up\n",
1440 netxen_nic_driver_name
, netdev
->name
);
1441 adapter
->ahw
.linkup
= 1;
1442 if (netif_running(netdev
)) {
1443 netif_carrier_on(netdev
);
1444 netif_wake_queue(netdev
);
1449 static void netxen_watchdog(unsigned long v
)
1451 struct netxen_adapter
*adapter
= (struct netxen_adapter
*)v
;
1453 SCHEDULE_WORK(&adapter
->watchdog_task
);
1456 void netxen_watchdog_task(struct work_struct
*work
)
1458 struct netxen_adapter
*adapter
=
1459 container_of(work
, struct netxen_adapter
, watchdog_task
);
1461 if ((adapter
->portnum
== 0) && netxen_nic_check_temp(adapter
))
1464 netxen_nic_handle_phy_intr(adapter
);
1466 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 2 * HZ
);
1469 static void netxen_tx_timeout(struct net_device
*netdev
)
1471 struct netxen_adapter
*adapter
= (struct netxen_adapter
*)
1472 netdev_priv(netdev
);
1473 SCHEDULE_WORK(&adapter
->tx_timeout_task
);
1476 static void netxen_tx_timeout_task(struct work_struct
*work
)
1478 struct netxen_adapter
*adapter
=
1479 container_of(work
, struct netxen_adapter
, tx_timeout_task
);
1481 printk(KERN_ERR
"%s %s: transmit timeout, resetting.\n",
1482 netxen_nic_driver_name
, adapter
->netdev
->name
);
1484 netxen_nic_disable_int(adapter
);
1485 napi_disable(&adapter
->napi
);
1487 adapter
->netdev
->trans_start
= jiffies
;
1489 napi_enable(&adapter
->napi
);
1490 netxen_nic_enable_int(adapter
);
1491 netif_wake_queue(adapter
->netdev
);
1495 * netxen_nic_get_stats - Get System Network Statistics
1496 * @netdev: network interface device structure
1498 struct net_device_stats
*netxen_nic_get_stats(struct net_device
*netdev
)
1500 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1501 struct net_device_stats
*stats
= &adapter
->net_stats
;
1503 memset(stats
, 0, sizeof(*stats
));
1505 /* total packets received */
1506 stats
->rx_packets
= adapter
->stats
.no_rcv
;
1507 /* total packets transmitted */
1508 stats
->tx_packets
= adapter
->stats
.xmitedframes
+
1509 adapter
->stats
.xmitfinished
;
1510 /* total bytes received */
1511 stats
->rx_bytes
= adapter
->stats
.rxbytes
;
1512 /* total bytes transmitted */
1513 stats
->tx_bytes
= adapter
->stats
.txbytes
;
1514 /* bad packets received */
1515 stats
->rx_errors
= adapter
->stats
.rcvdbadskb
;
1516 /* packet transmit problems */
1517 stats
->tx_errors
= adapter
->stats
.nocmddescriptor
;
1518 /* no space in linux buffers */
1519 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
1520 /* no space available in linux */
1521 stats
->tx_dropped
= adapter
->stats
.txdropped
;
1527 netxen_handle_int(struct netxen_adapter
*adapter
)
1529 netxen_nic_disable_int(adapter
);
1530 napi_schedule(&adapter
->napi
);
1533 static irqreturn_t
netxen_intr(int irq
, void *data
)
1535 struct netxen_adapter
*adapter
= data
;
1538 our_int
= adapter
->pci_read_normalize(adapter
, CRB_INT_VECTOR
);
1539 /* not our interrupt */
1540 if ((our_int
& (0x80 << adapter
->portnum
)) == 0)
1543 if (adapter
->intr_scheme
== INTR_SCHEME_PERPORT
) {
1544 /* claim interrupt */
1545 adapter
->pci_write_normalize(adapter
, CRB_INT_VECTOR
,
1546 our_int
& ~((u32
)(0x80 << adapter
->portnum
)));
1549 netxen_handle_int(adapter
);
1554 static irqreturn_t
netxen_msi_intr(int irq
, void *data
)
1556 struct netxen_adapter
*adapter
= data
;
1558 netxen_handle_int(adapter
);
1562 static int netxen_nic_poll(struct napi_struct
*napi
, int budget
)
1564 struct netxen_adapter
*adapter
= container_of(napi
, struct netxen_adapter
, napi
);
1569 tx_complete
= netxen_process_cmd_ring(adapter
);
1572 for (ctx
= 0; ctx
< MAX_RCV_CTX
; ++ctx
) {
1574 * Fairness issue. This will give undue weight to the
1575 * receive context 0.
1579 * To avoid starvation, we give each of our receivers,
1580 * a fraction of the quota. Sometimes, it might happen that we
1581 * have enough quota to process every packet, but since all the
1582 * packets are on one context, it gets only half of the quota,
1583 * and ends up not processing it.
1585 work_done
+= netxen_process_rcv_ring(adapter
, ctx
,
1586 budget
/ MAX_RCV_CTX
);
1589 if ((work_done
< budget
) && tx_complete
) {
1590 netif_rx_complete(adapter
->netdev
, &adapter
->napi
);
1591 netxen_nic_enable_int(adapter
);
1597 #ifdef CONFIG_NET_POLL_CONTROLLER
1598 static void netxen_nic_poll_controller(struct net_device
*netdev
)
1600 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1601 disable_irq(adapter
->irq
);
1602 netxen_intr(adapter
->irq
, adapter
);
1603 enable_irq(adapter
->irq
);
1607 static struct pci_driver netxen_driver
= {
1608 .name
= netxen_nic_driver_name
,
1609 .id_table
= netxen_pci_tbl
,
1610 .probe
= netxen_nic_probe
,
1611 .remove
= __devexit_p(netxen_nic_remove
)
1614 /* Driver Registration on NetXen card */
1616 static int __init
netxen_init_module(void)
1618 if ((netxen_workq
= create_singlethread_workqueue("netxen")) == NULL
)
1621 return pci_register_driver(&netxen_driver
);
1624 module_init(netxen_init_module
);
1626 static void __exit
netxen_exit_module(void)
1628 pci_unregister_driver(&netxen_driver
);
1629 destroy_workqueue(netxen_workq
);
1632 module_exit(netxen_exit_module
);