2 * Copyright (C) 2003 - 2009 NetXen, Inc.
3 * Copyright (C) 2009 - QLogic Corporation.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.
26 #include <linux/vmalloc.h>
27 #include <linux/interrupt.h>
28 #include "netxen_nic_hw.h"
30 #include "netxen_nic.h"
32 #include <linux/dma-mapping.h>
33 #include <linux/if_vlan.h>
35 #include <linux/ipv6.h>
36 #include <linux/inetdevice.h>
38 MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
39 MODULE_LICENSE("GPL");
40 MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID
);
42 char netxen_nic_driver_name
[] = "netxen_nic";
43 static char netxen_nic_driver_string
[] = "NetXen Network Driver version "
44 NETXEN_NIC_LINUX_VERSIONID
;
46 static int port_mode
= NETXEN_PORT_MODE_AUTO_NEG
;
48 /* Default to restricted 1G auto-neg mode */
49 static int wol_port_mode
= 5;
51 static int use_msi
= 1;
53 static int use_msi_x
= 1;
55 /* Local functions to NetXen NIC driver */
56 static int __devinit
netxen_nic_probe(struct pci_dev
*pdev
,
57 const struct pci_device_id
*ent
);
58 static void __devexit
netxen_nic_remove(struct pci_dev
*pdev
);
59 static int netxen_nic_open(struct net_device
*netdev
);
60 static int netxen_nic_close(struct net_device
*netdev
);
61 static netdev_tx_t
netxen_nic_xmit_frame(struct sk_buff
*,
63 static void netxen_tx_timeout(struct net_device
*netdev
);
64 static void netxen_tx_timeout_task(struct work_struct
*work
);
65 static void netxen_fw_poll_work(struct work_struct
*work
);
66 static void netxen_schedule_work(struct netxen_adapter
*adapter
,
67 work_func_t func
, int delay
);
68 static void netxen_cancel_fw_work(struct netxen_adapter
*adapter
);
69 static int netxen_nic_poll(struct napi_struct
*napi
, int budget
);
70 #ifdef CONFIG_NET_POLL_CONTROLLER
71 static void netxen_nic_poll_controller(struct net_device
*netdev
);
74 static void netxen_create_sysfs_entries(struct netxen_adapter
*adapter
);
75 static void netxen_remove_sysfs_entries(struct netxen_adapter
*adapter
);
77 static int nx_decr_dev_ref_cnt(struct netxen_adapter
*adapter
);
78 static int netxen_can_start_firmware(struct netxen_adapter
*adapter
);
80 static irqreturn_t
netxen_intr(int irq
, void *data
);
81 static irqreturn_t
netxen_msi_intr(int irq
, void *data
);
82 static irqreturn_t
netxen_msix_intr(int irq
, void *data
);
84 static void netxen_config_indev_addr(struct net_device
*dev
, unsigned long);
86 /* PCI Device ID Table */
87 #define ENTRY(device) \
88 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
89 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
91 static struct pci_device_id netxen_pci_tbl
[] __devinitdata
= {
92 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR
),
93 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4
),
94 ENTRY(PCI_DEVICE_ID_NX2031_4GCU
),
95 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ
),
96 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ
),
97 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT
),
98 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2
),
99 ENTRY(PCI_DEVICE_ID_NX3031
),
103 MODULE_DEVICE_TABLE(pci
, netxen_pci_tbl
);
105 static uint32_t crb_cmd_producer
[4] = {
106 CRB_CMD_PRODUCER_OFFSET
, CRB_CMD_PRODUCER_OFFSET_1
,
107 CRB_CMD_PRODUCER_OFFSET_2
, CRB_CMD_PRODUCER_OFFSET_3
111 netxen_nic_update_cmd_producer(struct netxen_adapter
*adapter
,
112 struct nx_host_tx_ring
*tx_ring
)
114 NXWRIO(adapter
, tx_ring
->crb_cmd_producer
, tx_ring
->producer
);
116 if (netxen_tx_avail(tx_ring
) <= TX_STOP_THRESH
) {
117 netif_stop_queue(adapter
->netdev
);
122 static uint32_t crb_cmd_consumer
[4] = {
123 CRB_CMD_CONSUMER_OFFSET
, CRB_CMD_CONSUMER_OFFSET_1
,
124 CRB_CMD_CONSUMER_OFFSET_2
, CRB_CMD_CONSUMER_OFFSET_3
128 netxen_nic_update_cmd_consumer(struct netxen_adapter
*adapter
,
129 struct nx_host_tx_ring
*tx_ring
)
131 NXWRIO(adapter
, tx_ring
->crb_cmd_consumer
, tx_ring
->sw_consumer
);
134 static uint32_t msi_tgt_status
[8] = {
135 ISR_INT_TARGET_STATUS
, ISR_INT_TARGET_STATUS_F1
,
136 ISR_INT_TARGET_STATUS_F2
, ISR_INT_TARGET_STATUS_F3
,
137 ISR_INT_TARGET_STATUS_F4
, ISR_INT_TARGET_STATUS_F5
,
138 ISR_INT_TARGET_STATUS_F6
, ISR_INT_TARGET_STATUS_F7
141 static struct netxen_legacy_intr_set legacy_intr
[] = NX_LEGACY_INTR_CONFIG
;
143 static inline void netxen_nic_disable_int(struct nx_host_sds_ring
*sds_ring
)
145 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
147 NXWRIO(adapter
, sds_ring
->crb_intr_mask
, 0);
150 static inline void netxen_nic_enable_int(struct nx_host_sds_ring
*sds_ring
)
152 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
154 NXWRIO(adapter
, sds_ring
->crb_intr_mask
, 0x1);
156 if (!NETXEN_IS_MSI_FAMILY(adapter
))
157 NXWRIO(adapter
, adapter
->tgt_mask_reg
, 0xfbff);
161 netxen_alloc_sds_rings(struct netxen_recv_context
*recv_ctx
, int count
)
163 int size
= sizeof(struct nx_host_sds_ring
) * count
;
165 recv_ctx
->sds_rings
= kzalloc(size
, GFP_KERNEL
);
167 return (recv_ctx
->sds_rings
== NULL
);
171 netxen_free_sds_rings(struct netxen_recv_context
*recv_ctx
)
173 if (recv_ctx
->sds_rings
!= NULL
)
174 kfree(recv_ctx
->sds_rings
);
176 recv_ctx
->sds_rings
= NULL
;
180 netxen_napi_add(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
183 struct nx_host_sds_ring
*sds_ring
;
184 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
186 if (netxen_alloc_sds_rings(recv_ctx
, adapter
->max_sds_rings
))
189 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
190 sds_ring
= &recv_ctx
->sds_rings
[ring
];
191 netif_napi_add(netdev
, &sds_ring
->napi
,
192 netxen_nic_poll
, NETXEN_NETDEV_WEIGHT
);
199 netxen_napi_del(struct netxen_adapter
*adapter
)
202 struct nx_host_sds_ring
*sds_ring
;
203 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
205 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
206 sds_ring
= &recv_ctx
->sds_rings
[ring
];
207 netif_napi_del(&sds_ring
->napi
);
210 netxen_free_sds_rings(&adapter
->recv_ctx
);
214 netxen_napi_enable(struct netxen_adapter
*adapter
)
217 struct nx_host_sds_ring
*sds_ring
;
218 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
220 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
221 sds_ring
= &recv_ctx
->sds_rings
[ring
];
222 napi_enable(&sds_ring
->napi
);
223 netxen_nic_enable_int(sds_ring
);
228 netxen_napi_disable(struct netxen_adapter
*adapter
)
231 struct nx_host_sds_ring
*sds_ring
;
232 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
234 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
235 sds_ring
= &recv_ctx
->sds_rings
[ring
];
236 netxen_nic_disable_int(sds_ring
);
237 napi_synchronize(&sds_ring
->napi
);
238 napi_disable(&sds_ring
->napi
);
242 static int nx_set_dma_mask(struct netxen_adapter
*adapter
)
244 struct pci_dev
*pdev
= adapter
->pdev
;
245 uint64_t mask
, cmask
;
247 adapter
->pci_using_dac
= 0;
249 mask
= DMA_BIT_MASK(32);
250 cmask
= DMA_BIT_MASK(32);
252 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
254 mask
= DMA_BIT_MASK(35);
257 mask
= DMA_BIT_MASK(39);
261 if (pci_set_dma_mask(pdev
, mask
) == 0 &&
262 pci_set_consistent_dma_mask(pdev
, cmask
) == 0) {
263 adapter
->pci_using_dac
= 1;
270 /* Update addressable range if firmware supports it */
272 nx_update_dma_mask(struct netxen_adapter
*adapter
)
274 int change
, shift
, err
;
275 uint64_t mask
, old_mask
, old_cmask
;
276 struct pci_dev
*pdev
= adapter
->pdev
;
280 shift
= NXRD32(adapter
, CRB_DMA_SHIFT
);
284 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) && (shift
> 9))
286 else if ((adapter
->ahw
.revision_id
== NX_P2_C1
) && (shift
<= 4))
290 old_mask
= pdev
->dma_mask
;
291 old_cmask
= pdev
->dev
.coherent_dma_mask
;
293 mask
= DMA_BIT_MASK(32+shift
);
295 err
= pci_set_dma_mask(pdev
, mask
);
299 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
301 err
= pci_set_consistent_dma_mask(pdev
, mask
);
305 dev_info(&pdev
->dev
, "using %d-bit dma mask\n", 32+shift
);
311 pci_set_dma_mask(pdev
, old_mask
);
312 pci_set_consistent_dma_mask(pdev
, old_cmask
);
317 netxen_check_hw_init(struct netxen_adapter
*adapter
, int first_boot
)
321 if (first_boot
== 0x55555555) {
322 /* This is the first boot after power up */
323 NXWR32(adapter
, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC
);
325 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
328 /* PCI bus master workaround */
329 first_boot
= NXRD32(adapter
, NETXEN_PCIE_REG(0x4));
330 if (!(first_boot
& 0x4)) {
332 NXWR32(adapter
, NETXEN_PCIE_REG(0x4), first_boot
);
333 first_boot
= NXRD32(adapter
, NETXEN_PCIE_REG(0x4));
336 /* This is the first boot after power up */
337 first_boot
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
);
338 if (first_boot
!= 0x80000f) {
339 /* clear the register for future unloads/loads */
340 NXWR32(adapter
, NETXEN_CAM_RAM(0x1fc), 0);
344 /* Start P2 boot loader */
345 val
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_PEGTUNE_DONE
);
346 NXWR32(adapter
, NETXEN_ROMUSB_GLB_PEGTUNE_DONE
, val
| 0x1);
350 val
= NXRD32(adapter
, NETXEN_CAM_RAM(0x1fc));
352 if (++timeout
> 5000)
355 } while (val
== NETXEN_BDINFO_MAGIC
);
360 static void netxen_set_port_mode(struct netxen_adapter
*adapter
)
364 val
= adapter
->ahw
.board_type
;
365 if ((val
== NETXEN_BRDTYPE_P3_HMEZ
) ||
366 (val
== NETXEN_BRDTYPE_P3_XG_LOM
)) {
367 if (port_mode
== NETXEN_PORT_MODE_802_3_AP
) {
368 data
= NETXEN_PORT_MODE_802_3_AP
;
369 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
370 } else if (port_mode
== NETXEN_PORT_MODE_XG
) {
371 data
= NETXEN_PORT_MODE_XG
;
372 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
373 } else if (port_mode
== NETXEN_PORT_MODE_AUTO_NEG_1G
) {
374 data
= NETXEN_PORT_MODE_AUTO_NEG_1G
;
375 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
376 } else if (port_mode
== NETXEN_PORT_MODE_AUTO_NEG_XG
) {
377 data
= NETXEN_PORT_MODE_AUTO_NEG_XG
;
378 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
380 data
= NETXEN_PORT_MODE_AUTO_NEG
;
381 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
384 if ((wol_port_mode
!= NETXEN_PORT_MODE_802_3_AP
) &&
385 (wol_port_mode
!= NETXEN_PORT_MODE_XG
) &&
386 (wol_port_mode
!= NETXEN_PORT_MODE_AUTO_NEG_1G
) &&
387 (wol_port_mode
!= NETXEN_PORT_MODE_AUTO_NEG_XG
)) {
388 wol_port_mode
= NETXEN_PORT_MODE_AUTO_NEG
;
390 NXWR32(adapter
, NETXEN_WOL_PORT_MODE
, wol_port_mode
);
394 static void netxen_set_msix_bit(struct pci_dev
*pdev
, int enable
)
399 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
401 pci_read_config_dword(pdev
, pos
, &control
);
403 control
|= PCI_MSIX_FLAGS_ENABLE
;
406 pci_write_config_dword(pdev
, pos
, control
);
410 static void netxen_init_msix_entries(struct netxen_adapter
*adapter
, int count
)
414 for (i
= 0; i
< count
; i
++)
415 adapter
->msix_entries
[i
].entry
= i
;
419 netxen_read_mac_addr(struct netxen_adapter
*adapter
)
424 struct net_device
*netdev
= adapter
->netdev
;
425 struct pci_dev
*pdev
= adapter
->pdev
;
427 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
428 if (netxen_p3_get_mac_addr(adapter
, &mac_addr
) != 0)
431 if (netxen_get_flash_mac_addr(adapter
, &mac_addr
) != 0)
435 p
= (unsigned char *)&mac_addr
;
436 for (i
= 0; i
< 6; i
++)
437 netdev
->dev_addr
[i
] = *(p
+ 5 - i
);
439 memcpy(netdev
->perm_addr
, netdev
->dev_addr
, netdev
->addr_len
);
441 /* set station address */
443 if (!is_valid_ether_addr(netdev
->perm_addr
))
444 dev_warn(&pdev
->dev
, "Bad MAC address %pM.\n", netdev
->dev_addr
);
449 int netxen_nic_set_mac(struct net_device
*netdev
, void *p
)
451 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
452 struct sockaddr
*addr
= p
;
454 if (!is_valid_ether_addr(addr
->sa_data
))
457 if (netif_running(netdev
)) {
458 netif_device_detach(netdev
);
459 netxen_napi_disable(adapter
);
462 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
463 adapter
->macaddr_set(adapter
, addr
->sa_data
);
465 if (netif_running(netdev
)) {
466 netif_device_attach(netdev
);
467 netxen_napi_enable(adapter
);
472 static void netxen_set_multicast_list(struct net_device
*dev
)
474 struct netxen_adapter
*adapter
= netdev_priv(dev
);
476 adapter
->set_multi(dev
);
479 static const struct net_device_ops netxen_netdev_ops
= {
480 .ndo_open
= netxen_nic_open
,
481 .ndo_stop
= netxen_nic_close
,
482 .ndo_start_xmit
= netxen_nic_xmit_frame
,
483 .ndo_get_stats
= netxen_nic_get_stats
,
484 .ndo_validate_addr
= eth_validate_addr
,
485 .ndo_set_multicast_list
= netxen_set_multicast_list
,
486 .ndo_set_mac_address
= netxen_nic_set_mac
,
487 .ndo_change_mtu
= netxen_nic_change_mtu
,
488 .ndo_tx_timeout
= netxen_tx_timeout
,
489 #ifdef CONFIG_NET_POLL_CONTROLLER
490 .ndo_poll_controller
= netxen_nic_poll_controller
,
495 netxen_setup_intr(struct netxen_adapter
*adapter
)
497 struct netxen_legacy_intr_set
*legacy_intrp
;
498 struct pci_dev
*pdev
= adapter
->pdev
;
501 if (adapter
->rss_supported
) {
502 num_msix
= (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER
) ?
503 MSIX_ENTRIES_PER_ADAPTER
: 2;
507 adapter
->max_sds_rings
= 1;
509 adapter
->flags
&= ~(NETXEN_NIC_MSI_ENABLED
| NETXEN_NIC_MSIX_ENABLED
);
511 if (adapter
->ahw
.revision_id
>= NX_P3_B0
)
512 legacy_intrp
= &legacy_intr
[adapter
->ahw
.pci_func
];
514 legacy_intrp
= &legacy_intr
[0];
516 adapter
->int_vec_bit
= legacy_intrp
->int_vec_bit
;
517 adapter
->tgt_status_reg
= netxen_get_ioaddr(adapter
,
518 legacy_intrp
->tgt_status_reg
);
519 adapter
->tgt_mask_reg
= netxen_get_ioaddr(adapter
,
520 legacy_intrp
->tgt_mask_reg
);
521 adapter
->pci_int_reg
= netxen_get_ioaddr(adapter
,
522 legacy_intrp
->pci_int_reg
);
523 adapter
->isr_int_vec
= netxen_get_ioaddr(adapter
, ISR_INT_VECTOR
);
525 if (adapter
->ahw
.revision_id
>= NX_P3_B1
)
526 adapter
->crb_int_state_reg
= netxen_get_ioaddr(adapter
,
529 adapter
->crb_int_state_reg
= netxen_get_ioaddr(adapter
,
532 netxen_set_msix_bit(pdev
, 0);
534 if (adapter
->msix_supported
) {
536 netxen_init_msix_entries(adapter
, num_msix
);
537 err
= pci_enable_msix(pdev
, adapter
->msix_entries
, num_msix
);
539 adapter
->flags
|= NETXEN_NIC_MSIX_ENABLED
;
540 netxen_set_msix_bit(pdev
, 1);
542 if (adapter
->rss_supported
)
543 adapter
->max_sds_rings
= num_msix
;
545 dev_info(&pdev
->dev
, "using msi-x interrupts\n");
550 pci_disable_msix(pdev
);
552 /* fall through for msi */
555 if (use_msi
&& !pci_enable_msi(pdev
)) {
556 adapter
->flags
|= NETXEN_NIC_MSI_ENABLED
;
557 adapter
->tgt_status_reg
= netxen_get_ioaddr(adapter
,
558 msi_tgt_status
[adapter
->ahw
.pci_func
]);
559 dev_info(&pdev
->dev
, "using msi interrupts\n");
560 adapter
->msix_entries
[0].vector
= pdev
->irq
;
564 dev_info(&pdev
->dev
, "using legacy interrupts\n");
565 adapter
->msix_entries
[0].vector
= pdev
->irq
;
569 netxen_teardown_intr(struct netxen_adapter
*adapter
)
571 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
572 pci_disable_msix(adapter
->pdev
);
573 if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
574 pci_disable_msi(adapter
->pdev
);
578 netxen_cleanup_pci_map(struct netxen_adapter
*adapter
)
580 if (adapter
->ahw
.db_base
!= NULL
)
581 iounmap(adapter
->ahw
.db_base
);
582 if (adapter
->ahw
.pci_base0
!= NULL
)
583 iounmap(adapter
->ahw
.pci_base0
);
584 if (adapter
->ahw
.pci_base1
!= NULL
)
585 iounmap(adapter
->ahw
.pci_base1
);
586 if (adapter
->ahw
.pci_base2
!= NULL
)
587 iounmap(adapter
->ahw
.pci_base2
);
591 netxen_setup_pci_map(struct netxen_adapter
*adapter
)
593 void __iomem
*mem_ptr0
= NULL
;
594 void __iomem
*mem_ptr1
= NULL
;
595 void __iomem
*mem_ptr2
= NULL
;
596 void __iomem
*db_ptr
= NULL
;
598 unsigned long mem_base
, mem_len
, db_base
, db_len
= 0, pci_len0
= 0;
600 struct pci_dev
*pdev
= adapter
->pdev
;
601 int pci_func
= adapter
->ahw
.pci_func
;
606 * Set the CRB window to invalid. If any register in window 0 is
607 * accessed it should set the window to 0 and then reset it to 1.
609 adapter
->curr_window
= 255;
610 adapter
->ahw
.qdr_sn_window
= -1;
611 adapter
->ahw
.ddr_mn_window
= -1;
613 /* remap phys address */
614 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
615 mem_len
= pci_resource_len(pdev
, 0);
618 /* 128 Meg of memory */
619 if (mem_len
== NETXEN_PCI_128MB_SIZE
) {
620 mem_ptr0
= ioremap(mem_base
, FIRST_PAGE_GROUP_SIZE
);
621 mem_ptr1
= ioremap(mem_base
+ SECOND_PAGE_GROUP_START
,
622 SECOND_PAGE_GROUP_SIZE
);
623 mem_ptr2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
,
624 THIRD_PAGE_GROUP_SIZE
);
625 } else if (mem_len
== NETXEN_PCI_32MB_SIZE
) {
626 mem_ptr1
= ioremap(mem_base
, SECOND_PAGE_GROUP_SIZE
);
627 mem_ptr2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
-
628 SECOND_PAGE_GROUP_START
, THIRD_PAGE_GROUP_SIZE
);
629 } else if (mem_len
== NETXEN_PCI_2MB_SIZE
) {
631 mem_ptr0
= pci_ioremap_bar(pdev
, 0);
632 if (mem_ptr0
== NULL
) {
633 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
638 adapter
->ahw
.ddr_mn_window
= 0;
639 adapter
->ahw
.qdr_sn_window
= 0;
641 adapter
->ahw
.mn_win_crb
= NETXEN_PCI_CRBSPACE
+
642 0x100000 + PCIX_MN_WINDOW
+ (pci_func
* 0x20);
643 adapter
->ahw
.ms_win_crb
= NETXEN_PCI_CRBSPACE
+
644 0x100000 + PCIX_SN_WINDOW
;
646 adapter
->ahw
.ms_win_crb
+= (pci_func
* 0x20);
648 adapter
->ahw
.ms_win_crb
+=
649 0xA0 + ((pci_func
- 4) * 0x10);
654 netxen_setup_hwops(adapter
);
656 dev_info(&pdev
->dev
, "%dMB memory map\n", (int)(mem_len
>>20));
658 adapter
->ahw
.pci_base0
= mem_ptr0
;
659 adapter
->ahw
.pci_len0
= pci_len0
;
660 adapter
->ahw
.pci_base1
= mem_ptr1
;
661 adapter
->ahw
.pci_base2
= mem_ptr2
;
663 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
666 db_base
= pci_resource_start(pdev
, 4); /* doorbell is on bar 4 */
667 db_len
= pci_resource_len(pdev
, 4);
670 printk(KERN_ERR
"%s: doorbell is disabled\n",
671 netxen_nic_driver_name
);
676 db_ptr
= ioremap(db_base
, NETXEN_DB_MAPSIZE_BYTES
);
678 printk(KERN_ERR
"%s: Failed to allocate doorbell map.",
679 netxen_nic_driver_name
);
685 adapter
->ahw
.db_base
= db_ptr
;
686 adapter
->ahw
.db_len
= db_len
;
690 netxen_cleanup_pci_map(adapter
);
695 netxen_check_options(struct netxen_adapter
*adapter
)
697 u32 fw_major
, fw_minor
, fw_build
;
698 char brd_name
[NETXEN_MAX_SHORT_NAME
];
702 struct pci_dev
*pdev
= adapter
->pdev
;
704 adapter
->driver_mismatch
= 0;
706 ptr32
= (int *)&serial_num
;
707 offset
= NX_FW_SERIAL_NUM_OFFSET
;
708 for (i
= 0; i
< 8; i
++) {
709 if (netxen_rom_fast_read(adapter
, offset
, &val
) == -1) {
710 dev_err(&pdev
->dev
, "error reading board info\n");
711 adapter
->driver_mismatch
= 1;
714 ptr32
[i
] = cpu_to_le32(val
);
715 offset
+= sizeof(u32
);
718 fw_major
= NXRD32(adapter
, NETXEN_FW_VERSION_MAJOR
);
719 fw_minor
= NXRD32(adapter
, NETXEN_FW_VERSION_MINOR
);
720 fw_build
= NXRD32(adapter
, NETXEN_FW_VERSION_SUB
);
722 adapter
->fw_version
= NETXEN_VERSION_CODE(fw_major
, fw_minor
, fw_build
);
724 if (adapter
->portnum
== 0) {
725 get_brd_name_by_type(adapter
->ahw
.board_type
, brd_name
);
727 printk(KERN_INFO
"NetXen %s Board S/N %s Chip rev 0x%x\n",
728 brd_name
, serial_num
, adapter
->ahw
.revision_id
);
731 if (adapter
->fw_version
< NETXEN_VERSION_CODE(3, 4, 216)) {
732 adapter
->driver_mismatch
= 1;
733 dev_warn(&pdev
->dev
, "firmware version %d.%d.%d unsupported\n",
734 fw_major
, fw_minor
, fw_build
);
738 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
739 i
= NXRD32(adapter
, NETXEN_SRE_MISC
);
740 adapter
->ahw
.cut_through
= (i
& 0x8000) ? 1 : 0;
743 dev_info(&pdev
->dev
, "firmware v%d.%d.%d [%s]\n",
744 fw_major
, fw_minor
, fw_build
,
745 adapter
->ahw
.cut_through
? "cut-through" : "legacy");
747 if (adapter
->fw_version
>= NETXEN_VERSION_CODE(4, 0, 222))
748 adapter
->capabilities
= NXRD32(adapter
, CRB_FW_CAPABILITIES_1
);
750 adapter
->flags
&= ~NETXEN_NIC_LRO_ENABLED
;
752 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
753 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
754 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
755 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
756 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
757 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
760 adapter
->msix_supported
= 0;
761 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
762 adapter
->msix_supported
= !!use_msi_x
;
763 adapter
->rss_supported
= !!use_msi_x
;
764 } else if (adapter
->fw_version
>= NETXEN_VERSION_CODE(3, 4, 336)) {
765 switch (adapter
->ahw
.board_type
) {
766 case NETXEN_BRDTYPE_P2_SB31_10G
:
767 case NETXEN_BRDTYPE_P2_SB31_10G_CX4
:
768 adapter
->msix_supported
= !!use_msi_x
;
769 adapter
->rss_supported
= !!use_msi_x
;
776 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
778 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
779 adapter
->num_lro_rxd
= MAX_LRO_RCV_DESCRIPTORS
;
780 adapter
->max_rds_rings
= 3;
782 adapter
->num_lro_rxd
= 0;
783 adapter
->max_rds_rings
= 2;
788 netxen_start_firmware(struct netxen_adapter
*adapter
)
790 int val
, err
, first_boot
;
791 struct pci_dev
*pdev
= adapter
->pdev
;
793 /* required for NX2031 dummy dma */
794 err
= nx_set_dma_mask(adapter
);
798 if (!netxen_can_start_firmware(adapter
))
801 first_boot
= NXRD32(adapter
, NETXEN_CAM_RAM(0x1fc));
803 err
= netxen_check_hw_init(adapter
, first_boot
);
805 dev_err(&pdev
->dev
, "error in init HW init sequence\n");
809 netxen_request_firmware(adapter
);
811 err
= netxen_need_fw_reset(adapter
);
817 if (first_boot
!= 0x55555555) {
818 NXWR32(adapter
, CRB_CMDPEG_STATE
, 0);
819 netxen_pinit_from_rom(adapter
, 0);
823 NXWR32(adapter
, CRB_DMA_SHIFT
, 0x55555555);
824 NXWR32(adapter
, NETXEN_PEG_HALT_STATUS1
, 0);
825 NXWR32(adapter
, NETXEN_PEG_HALT_STATUS2
, 0);
827 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
828 netxen_set_port_mode(adapter
);
830 err
= netxen_load_firmware(adapter
);
834 netxen_release_firmware(adapter
);
836 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
838 /* Initialize multicast addr pool owners */
840 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
)
842 NXWR32(adapter
, NETXEN_MAC_ADDR_CNTL_REG
, val
);
846 err
= netxen_init_dummy_dma(adapter
);
851 * Tell the hardware our version number.
853 val
= (_NETXEN_NIC_LINUX_MAJOR
<< 16)
854 | ((_NETXEN_NIC_LINUX_MINOR
<< 8))
855 | (_NETXEN_NIC_LINUX_SUBVERSION
);
856 NXWR32(adapter
, CRB_DRIVER_VERSION
, val
);
859 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_READY
);
862 /* Handshake with the card before we register the devices. */
863 err
= netxen_phantom_init(adapter
, NETXEN_NIC_PEG_TUNE
);
865 netxen_free_dummy_dma(adapter
);
869 nx_update_dma_mask(adapter
);
871 netxen_check_options(adapter
);
873 adapter
->need_fw_reset
= 0;
875 /* fall through and release firmware */
878 netxen_release_firmware(adapter
);
883 netxen_nic_request_irq(struct netxen_adapter
*adapter
)
885 irq_handler_t handler
;
886 struct nx_host_sds_ring
*sds_ring
;
889 unsigned long flags
= IRQF_SAMPLE_RANDOM
;
890 struct net_device
*netdev
= adapter
->netdev
;
891 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
893 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
894 handler
= netxen_msix_intr
;
895 else if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
896 handler
= netxen_msi_intr
;
898 flags
|= IRQF_SHARED
;
899 handler
= netxen_intr
;
901 adapter
->irq
= netdev
->irq
;
903 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
904 sds_ring
= &recv_ctx
->sds_rings
[ring
];
905 sprintf(sds_ring
->name
, "%s[%d]", netdev
->name
, ring
);
906 err
= request_irq(sds_ring
->irq
, handler
,
907 flags
, sds_ring
->name
, sds_ring
);
916 netxen_nic_free_irq(struct netxen_adapter
*adapter
)
919 struct nx_host_sds_ring
*sds_ring
;
921 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
923 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
924 sds_ring
= &recv_ctx
->sds_rings
[ring
];
925 free_irq(sds_ring
->irq
, sds_ring
);
930 netxen_nic_init_coalesce_defaults(struct netxen_adapter
*adapter
)
932 adapter
->coal
.flags
= NETXEN_NIC_INTR_DEFAULT
;
933 adapter
->coal
.normal
.data
.rx_time_us
=
934 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US
;
935 adapter
->coal
.normal
.data
.rx_packets
=
936 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS
;
937 adapter
->coal
.normal
.data
.tx_time_us
=
938 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US
;
939 adapter
->coal
.normal
.data
.tx_packets
=
940 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS
;
944 netxen_nic_up(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
948 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
951 err
= adapter
->init_port(adapter
, adapter
->physical_port
);
953 printk(KERN_ERR
"%s: Failed to initialize port %d\n",
954 netxen_nic_driver_name
, adapter
->portnum
);
957 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
958 adapter
->macaddr_set(adapter
, netdev
->dev_addr
);
960 adapter
->set_multi(netdev
);
961 adapter
->set_mtu(adapter
, netdev
->mtu
);
963 adapter
->ahw
.linkup
= 0;
965 if (adapter
->max_sds_rings
> 1)
966 netxen_config_rss(adapter
, 1);
968 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
969 netxen_config_intr_coalesce(adapter
);
971 if (adapter
->capabilities
& NX_FW_CAPABILITY_HW_LRO
)
972 netxen_config_hw_lro(adapter
, NETXEN_NIC_LRO_ENABLED
);
974 netxen_napi_enable(adapter
);
976 if (adapter
->capabilities
& NX_FW_CAPABILITY_LINK_NOTIFICATION
)
977 netxen_linkevent_request(adapter
, 1);
979 netxen_nic_set_link_parameters(adapter
);
981 set_bit(__NX_DEV_UP
, &adapter
->state
);
986 netxen_nic_down(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
988 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
991 clear_bit(__NX_DEV_UP
, &adapter
->state
);
993 spin_lock(&adapter
->tx_clean_lock
);
994 netif_carrier_off(netdev
);
995 netif_tx_disable(netdev
);
997 if (adapter
->stop_port
)
998 adapter
->stop_port(adapter
);
1000 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1001 netxen_p3_free_mac_list(adapter
);
1003 adapter
->set_promisc(adapter
, NETXEN_NIU_NON_PROMISC_MODE
);
1005 netxen_napi_disable(adapter
);
1007 netxen_release_tx_buffers(adapter
);
1008 spin_unlock(&adapter
->tx_clean_lock
);
1013 netxen_nic_attach(struct netxen_adapter
*adapter
)
1015 struct net_device
*netdev
= adapter
->netdev
;
1016 struct pci_dev
*pdev
= adapter
->pdev
;
1018 struct nx_host_rds_ring
*rds_ring
;
1019 struct nx_host_tx_ring
*tx_ring
;
1021 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
)
1024 err
= netxen_init_firmware(adapter
);
1028 err
= netxen_napi_add(adapter
, netdev
);
1032 err
= netxen_alloc_sw_resources(adapter
);
1034 printk(KERN_ERR
"%s: Error in setting sw resources\n",
1039 err
= netxen_alloc_hw_resources(adapter
);
1041 printk(KERN_ERR
"%s: Error in setting hw resources\n",
1043 goto err_out_free_sw
;
1046 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1047 tx_ring
= adapter
->tx_ring
;
1048 tx_ring
->crb_cmd_producer
= netxen_get_ioaddr(adapter
,
1049 crb_cmd_producer
[adapter
->portnum
]);
1050 tx_ring
->crb_cmd_consumer
= netxen_get_ioaddr(adapter
,
1051 crb_cmd_consumer
[adapter
->portnum
]);
1053 tx_ring
->producer
= 0;
1054 tx_ring
->sw_consumer
= 0;
1056 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
1057 netxen_nic_update_cmd_consumer(adapter
, tx_ring
);
1060 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1061 rds_ring
= &adapter
->recv_ctx
.rds_rings
[ring
];
1062 netxen_post_rx_buffers(adapter
, ring
, rds_ring
);
1065 err
= netxen_nic_request_irq(adapter
);
1067 dev_err(&pdev
->dev
, "%s: failed to setup interrupt\n",
1069 goto err_out_free_rxbuf
;
1072 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1073 netxen_nic_init_coalesce_defaults(adapter
);
1075 netxen_create_sysfs_entries(adapter
);
1077 adapter
->is_up
= NETXEN_ADAPTER_UP_MAGIC
;
1081 netxen_release_rx_buffers(adapter
);
1082 netxen_free_hw_resources(adapter
);
1084 netxen_free_sw_resources(adapter
);
1089 netxen_nic_detach(struct netxen_adapter
*adapter
)
1091 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1094 netxen_remove_sysfs_entries(adapter
);
1096 netxen_free_hw_resources(adapter
);
1097 netxen_release_rx_buffers(adapter
);
1098 netxen_nic_free_irq(adapter
);
1099 netxen_napi_del(adapter
);
1100 netxen_free_sw_resources(adapter
);
1106 netxen_nic_reset_context(struct netxen_adapter
*adapter
)
1109 struct net_device
*netdev
= adapter
->netdev
;
1111 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
1114 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
) {
1116 netif_device_detach(netdev
);
1118 if (netif_running(netdev
))
1119 netxen_nic_down(adapter
, netdev
);
1121 netxen_nic_detach(adapter
);
1123 if (netif_running(netdev
)) {
1124 err
= netxen_nic_attach(adapter
);
1126 err
= netxen_nic_up(adapter
, netdev
);
1132 netif_device_attach(netdev
);
1136 clear_bit(__NX_RESETTING
, &adapter
->state
);
1141 netxen_setup_netdev(struct netxen_adapter
*adapter
,
1142 struct net_device
*netdev
)
1145 struct pci_dev
*pdev
= adapter
->pdev
;
1147 adapter
->rx_csum
= 1;
1148 adapter
->mc_enabled
= 0;
1149 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1150 adapter
->max_mc_count
= 38;
1152 adapter
->max_mc_count
= 16;
1154 netdev
->netdev_ops
= &netxen_netdev_ops
;
1155 netdev
->watchdog_timeo
= 2*HZ
;
1157 netxen_nic_change_mtu(netdev
, netdev
->mtu
);
1159 SET_ETHTOOL_OPS(netdev
, &netxen_nic_ethtool_ops
);
1161 netdev
->features
|= (NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_TSO
);
1162 netdev
->features
|= (NETIF_F_GRO
);
1163 netdev
->vlan_features
|= (NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_TSO
);
1165 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
1166 netdev
->features
|= (NETIF_F_IPV6_CSUM
| NETIF_F_TSO6
);
1167 netdev
->vlan_features
|= (NETIF_F_IPV6_CSUM
| NETIF_F_TSO6
);
1170 if (adapter
->pci_using_dac
) {
1171 netdev
->features
|= NETIF_F_HIGHDMA
;
1172 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
1175 if (adapter
->capabilities
& NX_FW_CAPABILITY_FVLANTX
)
1176 netdev
->features
|= (NETIF_F_HW_VLAN_TX
);
1178 if (adapter
->capabilities
& NX_FW_CAPABILITY_HW_LRO
)
1179 netdev
->features
|= NETIF_F_LRO
;
1181 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1183 INIT_WORK(&adapter
->tx_timeout_task
, netxen_tx_timeout_task
);
1185 if (netxen_read_mac_addr(adapter
))
1186 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1188 netif_carrier_off(netdev
);
1189 netif_stop_queue(netdev
);
1191 err
= register_netdev(netdev
);
1193 dev_err(&pdev
->dev
, "failed to register net device\n");
1200 static int __devinit
1201 netxen_nic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1203 struct net_device
*netdev
= NULL
;
1204 struct netxen_adapter
*adapter
= NULL
;
1206 int pci_func_id
= PCI_FUNC(pdev
->devfn
);
1207 uint8_t revision_id
;
1209 if (pdev
->class != 0x020000) {
1210 printk(KERN_DEBUG
"NetXen function %d, class %x will not "
1211 "be enabled.\n",pci_func_id
, pdev
->class);
1215 if (pdev
->revision
>= NX_P3_A0
&& pdev
->revision
< NX_P3_B1
) {
1216 printk(KERN_WARNING
"NetXen chip revisions between 0x%x-0x%x"
1217 "will not be enabled.\n",
1218 NX_P3_A0
, NX_P3_B1
);
1222 if ((err
= pci_enable_device(pdev
)))
1225 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1227 goto err_out_disable_pdev
;
1230 if ((err
= pci_request_regions(pdev
, netxen_nic_driver_name
)))
1231 goto err_out_disable_pdev
;
1233 pci_set_master(pdev
);
1235 netdev
= alloc_etherdev(sizeof(struct netxen_adapter
));
1237 dev_err(&pdev
->dev
, "failed to allocate net_device\n");
1239 goto err_out_free_res
;
1242 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1244 adapter
= netdev_priv(netdev
);
1245 adapter
->netdev
= netdev
;
1246 adapter
->pdev
= pdev
;
1247 adapter
->ahw
.pci_func
= pci_func_id
;
1249 revision_id
= pdev
->revision
;
1250 adapter
->ahw
.revision_id
= revision_id
;
1252 rwlock_init(&adapter
->adapter_lock
);
1253 spin_lock_init(&adapter
->tx_clean_lock
);
1254 INIT_LIST_HEAD(&adapter
->mac_list
);
1256 err
= netxen_setup_pci_map(adapter
);
1258 goto err_out_free_netdev
;
1260 /* This will be reset for mezz cards */
1261 adapter
->portnum
= pci_func_id
;
1263 err
= netxen_nic_get_board_info(adapter
);
1265 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1266 goto err_out_iounmap
;
1269 /* Mezz cards have PCI function 0,2,3 enabled */
1270 switch (adapter
->ahw
.board_type
) {
1271 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
1272 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
1273 if (pci_func_id
>= 2)
1274 adapter
->portnum
= pci_func_id
- 2;
1280 err
= netxen_start_firmware(adapter
);
1282 goto err_out_iounmap
;
1285 * See if the firmware gave us a virtual-physical port mapping.
1287 adapter
->physical_port
= adapter
->portnum
;
1288 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1289 i
= NXRD32(adapter
, CRB_V2P(adapter
->portnum
));
1290 if (i
!= 0x55555555)
1291 adapter
->physical_port
= i
;
1294 netxen_nic_clear_stats(adapter
);
1296 netxen_setup_intr(adapter
);
1298 err
= netxen_setup_netdev(adapter
, netdev
);
1300 goto err_out_disable_msi
;
1302 pci_set_drvdata(pdev
, adapter
);
1304 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1306 switch (adapter
->ahw
.port_type
) {
1307 case NETXEN_NIC_GBE
:
1308 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1309 adapter
->netdev
->name
);
1311 case NETXEN_NIC_XGBE
:
1312 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1313 adapter
->netdev
->name
);
1319 err_out_disable_msi
:
1320 netxen_teardown_intr(adapter
);
1322 netxen_free_dummy_dma(adapter
);
1324 nx_decr_dev_ref_cnt(adapter
);
1327 netxen_cleanup_pci_map(adapter
);
1329 err_out_free_netdev
:
1330 free_netdev(netdev
);
1333 pci_release_regions(pdev
);
1335 err_out_disable_pdev
:
1336 pci_set_drvdata(pdev
, NULL
);
1337 pci_disable_device(pdev
);
1341 static void __devexit
netxen_nic_remove(struct pci_dev
*pdev
)
1343 struct netxen_adapter
*adapter
;
1344 struct net_device
*netdev
;
1346 adapter
= pci_get_drvdata(pdev
);
1347 if (adapter
== NULL
)
1350 netdev
= adapter
->netdev
;
1352 netxen_cancel_fw_work(adapter
);
1354 unregister_netdev(netdev
);
1356 cancel_work_sync(&adapter
->tx_timeout_task
);
1358 netxen_nic_detach(adapter
);
1360 nx_decr_dev_ref_cnt(adapter
);
1362 if (adapter
->portnum
== 0)
1363 netxen_free_dummy_dma(adapter
);
1365 clear_bit(__NX_RESETTING
, &adapter
->state
);
1367 netxen_teardown_intr(adapter
);
1369 netxen_cleanup_pci_map(adapter
);
1371 netxen_release_firmware(adapter
);
1373 pci_release_regions(pdev
);
1374 pci_disable_device(pdev
);
1375 pci_set_drvdata(pdev
, NULL
);
1377 free_netdev(netdev
);
1379 static int __netxen_nic_shutdown(struct pci_dev
*pdev
)
1381 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1382 struct net_device
*netdev
= adapter
->netdev
;
1385 netif_device_detach(netdev
);
1387 netxen_cancel_fw_work(adapter
);
1389 if (netif_running(netdev
))
1390 netxen_nic_down(adapter
, netdev
);
1392 cancel_work_sync(&adapter
->tx_timeout_task
);
1394 netxen_nic_detach(adapter
);
1396 if (adapter
->portnum
== 0)
1397 netxen_free_dummy_dma(adapter
);
1399 nx_decr_dev_ref_cnt(adapter
);
1401 clear_bit(__NX_RESETTING
, &adapter
->state
);
1403 retval
= pci_save_state(pdev
);
1407 if (netxen_nic_wol_supported(adapter
)) {
1408 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1409 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1412 pci_disable_device(pdev
);
1416 static void netxen_nic_shutdown(struct pci_dev
*pdev
)
1418 if (__netxen_nic_shutdown(pdev
))
1423 netxen_nic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1427 retval
= __netxen_nic_shutdown(pdev
);
1431 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1436 netxen_nic_resume(struct pci_dev
*pdev
)
1438 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1439 struct net_device
*netdev
= adapter
->netdev
;
1442 pci_set_power_state(pdev
, PCI_D0
);
1443 pci_restore_state(pdev
);
1445 err
= pci_enable_device(pdev
);
1449 adapter
->curr_window
= 255;
1451 err
= netxen_start_firmware(adapter
);
1453 dev_err(&pdev
->dev
, "failed to start firmware\n");
1457 if (netif_running(netdev
)) {
1458 err
= netxen_nic_attach(adapter
);
1462 err
= netxen_nic_up(adapter
, netdev
);
1464 goto err_out_detach
;
1466 netif_device_attach(netdev
);
1468 netxen_config_indev_addr(netdev
, NETDEV_UP
);
1471 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1474 netxen_nic_detach(adapter
);
1476 nx_decr_dev_ref_cnt(adapter
);
1481 static int netxen_nic_open(struct net_device
*netdev
)
1483 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1486 if (adapter
->driver_mismatch
)
1489 err
= netxen_nic_attach(adapter
);
1493 err
= netxen_nic_up(adapter
, netdev
);
1497 netif_start_queue(netdev
);
1502 netxen_nic_detach(adapter
);
1507 * netxen_nic_close - Disables a network interface entry point
1509 static int netxen_nic_close(struct net_device
*netdev
)
1511 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1513 netxen_nic_down(adapter
, netdev
);
1518 netxen_tso_check(struct net_device
*netdev
,
1519 struct nx_host_tx_ring
*tx_ring
,
1520 struct cmd_desc_type0
*first_desc
,
1521 struct sk_buff
*skb
)
1523 u8 opcode
= TX_ETHER_PKT
;
1524 __be16 protocol
= skb
->protocol
;
1525 u16 flags
= 0, vid
= 0;
1527 int copied
, offset
, copy_len
, hdr_len
= 0, tso
= 0, vlan_oob
= 0;
1528 struct cmd_desc_type0
*hwdesc
;
1529 struct vlan_ethhdr
*vh
;
1531 if (protocol
== cpu_to_be16(ETH_P_8021Q
)) {
1533 vh
= (struct vlan_ethhdr
*)skb
->data
;
1534 protocol
= vh
->h_vlan_encapsulated_proto
;
1535 flags
= FLAGS_VLAN_TAGGED
;
1537 } else if (vlan_tx_tag_present(skb
)) {
1539 flags
= FLAGS_VLAN_OOB
;
1540 vid
= vlan_tx_tag_get(skb
);
1541 netxen_set_tx_vlan_tci(first_desc
, vid
);
1545 if ((netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
1546 skb_shinfo(skb
)->gso_size
> 0) {
1548 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
1550 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
1551 first_desc
->total_hdr_length
= hdr_len
;
1553 first_desc
->total_hdr_length
+= VLAN_HLEN
;
1554 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
1555 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
1556 /* Only in case of TSO on vlan device */
1557 flags
|= FLAGS_VLAN_TAGGED
;
1560 opcode
= (protocol
== cpu_to_be16(ETH_P_IPV6
)) ?
1561 TX_TCP_LSO6
: TX_TCP_LSO
;
1564 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1567 if (protocol
== cpu_to_be16(ETH_P_IP
)) {
1568 l4proto
= ip_hdr(skb
)->protocol
;
1570 if (l4proto
== IPPROTO_TCP
)
1571 opcode
= TX_TCP_PKT
;
1572 else if(l4proto
== IPPROTO_UDP
)
1573 opcode
= TX_UDP_PKT
;
1574 } else if (protocol
== cpu_to_be16(ETH_P_IPV6
)) {
1575 l4proto
= ipv6_hdr(skb
)->nexthdr
;
1577 if (l4proto
== IPPROTO_TCP
)
1578 opcode
= TX_TCPV6_PKT
;
1579 else if(l4proto
== IPPROTO_UDP
)
1580 opcode
= TX_UDPV6_PKT
;
1584 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
1585 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
1586 netxen_set_tx_flags_opcode(first_desc
, flags
, opcode
);
1591 /* For LSO, we need to copy the MAC/IP/TCP headers into
1592 * the descriptor ring
1594 producer
= tx_ring
->producer
;
1599 /* Create a TSO vlan header template for firmware */
1601 hwdesc
= &tx_ring
->desc_head
[producer
];
1602 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1604 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1605 hdr_len
+ VLAN_HLEN
);
1607 vh
= (struct vlan_ethhdr
*)((char *)hwdesc
+ 2);
1608 skb_copy_from_linear_data(skb
, vh
, 12);
1609 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
1610 vh
->h_vlan_TCI
= htons(vid
);
1611 skb_copy_from_linear_data_offset(skb
, 12,
1612 (char *)vh
+ 16, copy_len
- 16);
1614 copied
= copy_len
- VLAN_HLEN
;
1617 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1620 while (copied
< hdr_len
) {
1622 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1623 (hdr_len
- copied
));
1625 hwdesc
= &tx_ring
->desc_head
[producer
];
1626 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1628 skb_copy_from_linear_data_offset(skb
, copied
,
1629 (char *)hwdesc
+ offset
, copy_len
);
1634 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1637 tx_ring
->producer
= producer
;
1642 netxen_map_tx_skb(struct pci_dev
*pdev
,
1643 struct sk_buff
*skb
, struct netxen_cmd_buffer
*pbuf
)
1645 struct netxen_skb_frag
*nf
;
1646 struct skb_frag_struct
*frag
;
1650 nr_frags
= skb_shinfo(skb
)->nr_frags
;
1651 nf
= &pbuf
->frag_array
[0];
1653 map
= pci_map_single(pdev
, skb
->data
,
1654 skb_headlen(skb
), PCI_DMA_TODEVICE
);
1655 if (pci_dma_mapping_error(pdev
, map
))
1659 nf
->length
= skb_headlen(skb
);
1661 for (i
= 0; i
< nr_frags
; i
++) {
1662 frag
= &skb_shinfo(skb
)->frags
[i
];
1663 nf
= &pbuf
->frag_array
[i
+1];
1665 map
= pci_map_page(pdev
, frag
->page
, frag
->page_offset
,
1666 frag
->size
, PCI_DMA_TODEVICE
);
1667 if (pci_dma_mapping_error(pdev
, map
))
1671 nf
->length
= frag
->size
;
1678 nf
= &pbuf
->frag_array
[i
+1];
1679 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
1682 nf
= &pbuf
->frag_array
[0];
1683 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
1690 netxen_clear_cmddesc(u64
*desc
)
1697 netxen_nic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
1699 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1700 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1701 struct netxen_cmd_buffer
*pbuf
;
1702 struct netxen_skb_frag
*buffrag
;
1703 struct cmd_desc_type0
*hwdesc
, *first_desc
;
1704 struct pci_dev
*pdev
;
1708 int frag_count
, no_of_desc
;
1709 u32 num_txd
= tx_ring
->num_desc
;
1711 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
1713 /* 4 fragments per cmd des */
1714 no_of_desc
= (frag_count
+ 3) >> 2;
1716 if (unlikely(no_of_desc
+ 2) > netxen_tx_avail(tx_ring
)) {
1717 netif_stop_queue(netdev
);
1718 return NETDEV_TX_BUSY
;
1721 producer
= tx_ring
->producer
;
1722 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
1724 pdev
= adapter
->pdev
;
1726 if (netxen_map_tx_skb(pdev
, skb
, pbuf
))
1730 pbuf
->frag_count
= frag_count
;
1732 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
1733 netxen_clear_cmddesc((u64
*)hwdesc
);
1735 netxen_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
1736 netxen_set_tx_port(first_desc
, adapter
->portnum
);
1738 for (i
= 0; i
< frag_count
; i
++) {
1742 if ((k
== 0) && (i
> 0)) {
1743 /* move to next desc.*/
1744 producer
= get_next_index(producer
, num_txd
);
1745 hwdesc
= &tx_ring
->desc_head
[producer
];
1746 netxen_clear_cmddesc((u64
*)hwdesc
);
1747 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1750 buffrag
= &pbuf
->frag_array
[i
];
1752 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
1755 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
1758 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
1761 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
1764 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
1769 tx_ring
->producer
= get_next_index(producer
, num_txd
);
1771 netxen_tso_check(netdev
, tx_ring
, first_desc
, skb
);
1773 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
1775 adapter
->stats
.txbytes
+= skb
->len
;
1776 adapter
->stats
.xmitcalled
++;
1778 return NETDEV_TX_OK
;
1781 adapter
->stats
.txdropped
++;
1782 dev_kfree_skb_any(skb
);
1783 return NETDEV_TX_OK
;
1786 static int netxen_nic_check_temp(struct netxen_adapter
*adapter
)
1788 struct net_device
*netdev
= adapter
->netdev
;
1789 uint32_t temp
, temp_state
, temp_val
;
1792 temp
= NXRD32(adapter
, CRB_TEMP_STATE
);
1794 temp_state
= nx_get_temp_state(temp
);
1795 temp_val
= nx_get_temp_val(temp
);
1797 if (temp_state
== NX_TEMP_PANIC
) {
1799 "%s: Device temperature %d degrees C exceeds"
1800 " maximum allowed. Hardware has been shut down.\n",
1801 netdev
->name
, temp_val
);
1803 } else if (temp_state
== NX_TEMP_WARN
) {
1804 if (adapter
->temp
== NX_TEMP_NORMAL
) {
1806 "%s: Device temperature %d degrees C "
1807 "exceeds operating range."
1808 " Immediate action needed.\n",
1809 netdev
->name
, temp_val
);
1812 if (adapter
->temp
== NX_TEMP_WARN
) {
1814 "%s: Device temperature is now %d degrees C"
1815 " in normal range.\n", netdev
->name
,
1819 adapter
->temp
= temp_state
;
1823 void netxen_advert_link_change(struct netxen_adapter
*adapter
, int linkup
)
1825 struct net_device
*netdev
= adapter
->netdev
;
1827 if (adapter
->ahw
.linkup
&& !linkup
) {
1828 printk(KERN_INFO
"%s: %s NIC Link is down\n",
1829 netxen_nic_driver_name
, netdev
->name
);
1830 adapter
->ahw
.linkup
= 0;
1831 if (netif_running(netdev
)) {
1832 netif_carrier_off(netdev
);
1833 netif_stop_queue(netdev
);
1835 adapter
->link_changed
= !adapter
->has_link_events
;
1836 } else if (!adapter
->ahw
.linkup
&& linkup
) {
1837 printk(KERN_INFO
"%s: %s NIC Link is up\n",
1838 netxen_nic_driver_name
, netdev
->name
);
1839 adapter
->ahw
.linkup
= 1;
1840 if (netif_running(netdev
)) {
1841 netif_carrier_on(netdev
);
1842 netif_wake_queue(netdev
);
1844 adapter
->link_changed
= !adapter
->has_link_events
;
1848 static void netxen_nic_handle_phy_intr(struct netxen_adapter
*adapter
)
1850 u32 val
, port
, linkup
;
1852 port
= adapter
->physical_port
;
1854 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
1855 val
= NXRD32(adapter
, CRB_XG_STATE_P3
);
1856 val
= XG_LINK_STATE_P3(adapter
->ahw
.pci_func
, val
);
1857 linkup
= (val
== XG_LINK_UP_P3
);
1859 val
= NXRD32(adapter
, CRB_XG_STATE
);
1860 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
)
1861 linkup
= (val
>> port
) & 1;
1863 val
= (val
>> port
*8) & 0xff;
1864 linkup
= (val
== XG_LINK_UP
);
1868 netxen_advert_link_change(adapter
, linkup
);
1871 static void netxen_tx_timeout(struct net_device
*netdev
)
1873 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1875 if (test_bit(__NX_RESETTING
, &adapter
->state
))
1878 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
1879 schedule_work(&adapter
->tx_timeout_task
);
1882 static void netxen_tx_timeout_task(struct work_struct
*work
)
1884 struct netxen_adapter
*adapter
=
1885 container_of(work
, struct netxen_adapter
, tx_timeout_task
);
1887 if (!netif_running(adapter
->netdev
))
1890 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
1893 if (++adapter
->tx_timeo_cnt
>= NX_MAX_TX_TIMEOUTS
)
1896 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1897 /* try to scrub interrupt */
1898 netxen_napi_disable(adapter
);
1900 adapter
->netdev
->trans_start
= jiffies
;
1902 netxen_napi_enable(adapter
);
1904 netif_wake_queue(adapter
->netdev
);
1909 if (!netxen_nic_reset_context(adapter
)) {
1910 adapter
->netdev
->trans_start
= jiffies
;
1914 /* context reset failed, fall through for fw reset */
1918 adapter
->need_fw_reset
= 1;
1920 clear_bit(__NX_RESETTING
, &adapter
->state
);
1923 struct net_device_stats
*netxen_nic_get_stats(struct net_device
*netdev
)
1925 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1926 struct net_device_stats
*stats
= &adapter
->net_stats
;
1928 memset(stats
, 0, sizeof(*stats
));
1930 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
1931 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
1932 stats
->rx_bytes
= adapter
->stats
.rxbytes
;
1933 stats
->tx_bytes
= adapter
->stats
.txbytes
;
1934 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
1935 stats
->tx_dropped
= adapter
->stats
.txdropped
;
1940 static irqreturn_t
netxen_intr(int irq
, void *data
)
1942 struct nx_host_sds_ring
*sds_ring
= data
;
1943 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
1946 status
= readl(adapter
->isr_int_vec
);
1948 if (!(status
& adapter
->int_vec_bit
))
1951 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
1952 /* check interrupt state machine, to be sure */
1953 status
= readl(adapter
->crb_int_state_reg
);
1954 if (!ISR_LEGACY_INT_TRIGGERED(status
))
1958 unsigned long our_int
= 0;
1960 our_int
= readl(adapter
->crb_int_state_reg
);
1962 /* not our interrupt */
1963 if (!test_and_clear_bit((7 + adapter
->portnum
), &our_int
))
1966 /* claim interrupt */
1967 writel((our_int
& 0xffffffff), adapter
->crb_int_state_reg
);
1969 /* clear interrupt */
1970 netxen_nic_disable_int(sds_ring
);
1973 writel(0xffffffff, adapter
->tgt_status_reg
);
1974 /* read twice to ensure write is flushed */
1975 readl(adapter
->isr_int_vec
);
1976 readl(adapter
->isr_int_vec
);
1978 napi_schedule(&sds_ring
->napi
);
1983 static irqreturn_t
netxen_msi_intr(int irq
, void *data
)
1985 struct nx_host_sds_ring
*sds_ring
= data
;
1986 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
1988 /* clear interrupt */
1989 writel(0xffffffff, adapter
->tgt_status_reg
);
1991 napi_schedule(&sds_ring
->napi
);
1995 static irqreturn_t
netxen_msix_intr(int irq
, void *data
)
1997 struct nx_host_sds_ring
*sds_ring
= data
;
1999 napi_schedule(&sds_ring
->napi
);
2003 static int netxen_nic_poll(struct napi_struct
*napi
, int budget
)
2005 struct nx_host_sds_ring
*sds_ring
=
2006 container_of(napi
, struct nx_host_sds_ring
, napi
);
2008 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2013 tx_complete
= netxen_process_cmd_ring(adapter
);
2015 work_done
= netxen_process_rcv_ring(sds_ring
, budget
);
2017 if ((work_done
< budget
) && tx_complete
) {
2018 napi_complete(&sds_ring
->napi
);
2019 if (netif_running(adapter
->netdev
))
2020 netxen_nic_enable_int(sds_ring
);
2026 #ifdef CONFIG_NET_POLL_CONTROLLER
2027 static void netxen_nic_poll_controller(struct net_device
*netdev
)
2029 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2030 disable_irq(adapter
->irq
);
2031 netxen_intr(adapter
->irq
, adapter
);
2032 enable_irq(adapter
->irq
);
2037 nx_incr_dev_ref_cnt(struct netxen_adapter
*adapter
)
2040 if (netxen_api_lock(adapter
))
2043 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2045 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, ++count
);
2047 netxen_api_unlock(adapter
);
2052 nx_decr_dev_ref_cnt(struct netxen_adapter
*adapter
)
2055 if (netxen_api_lock(adapter
))
2058 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2059 WARN_ON(count
== 0);
2061 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, --count
);
2064 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_COLD
);
2066 netxen_api_unlock(adapter
);
2071 nx_dev_request_reset(struct netxen_adapter
*adapter
)
2075 if (netxen_api_lock(adapter
))
2078 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2080 if (state
!= NX_DEV_INITALIZING
)
2081 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_NEED_RESET
);
2083 netxen_api_unlock(adapter
);
2087 netxen_can_start_firmware(struct netxen_adapter
*adapter
)
2092 if (netxen_api_lock(adapter
))
2095 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2097 if ((count
< 0) || (count
>= NX_MAX_PCI_FUNC
))
2102 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_INITALIZING
);
2105 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, ++count
);
2107 netxen_api_unlock(adapter
);
2113 netxen_schedule_work(struct netxen_adapter
*adapter
,
2114 work_func_t func
, int delay
)
2116 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
2117 schedule_delayed_work(&adapter
->fw_work
, delay
);
2121 netxen_cancel_fw_work(struct netxen_adapter
*adapter
)
2123 while (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2126 cancel_delayed_work_sync(&adapter
->fw_work
);
2130 netxen_attach_work(struct work_struct
*work
)
2132 struct netxen_adapter
*adapter
= container_of(work
,
2133 struct netxen_adapter
, fw_work
.work
);
2134 struct net_device
*netdev
= adapter
->netdev
;
2137 if (netif_running(netdev
)) {
2138 err
= netxen_nic_attach(adapter
);
2142 err
= netxen_nic_up(adapter
, netdev
);
2144 netxen_nic_detach(adapter
);
2148 netxen_config_indev_addr(netdev
, NETDEV_UP
);
2151 netif_device_attach(netdev
);
2154 adapter
->fw_fail_cnt
= 0;
2155 clear_bit(__NX_RESETTING
, &adapter
->state
);
2156 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
2160 netxen_fwinit_work(struct work_struct
*work
)
2162 struct netxen_adapter
*adapter
= container_of(work
,
2163 struct netxen_adapter
, fw_work
.work
);
2166 dev_state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2168 switch (dev_state
) {
2171 if (!netxen_start_firmware(adapter
)) {
2172 netxen_schedule_work(adapter
, netxen_attach_work
, 0);
2177 case NX_DEV_INITALIZING
:
2178 if (++adapter
->fw_wait_cnt
< FW_POLL_THRESH
) {
2179 netxen_schedule_work(adapter
,
2180 netxen_fwinit_work
, 2 * FW_POLL_DELAY
);
2190 nx_incr_dev_ref_cnt(adapter
);
2191 clear_bit(__NX_RESETTING
, &adapter
->state
);
2195 netxen_detach_work(struct work_struct
*work
)
2197 struct netxen_adapter
*adapter
= container_of(work
,
2198 struct netxen_adapter
, fw_work
.work
);
2199 struct net_device
*netdev
= adapter
->netdev
;
2203 netif_device_detach(netdev
);
2205 if (netif_running(netdev
))
2206 netxen_nic_down(adapter
, netdev
);
2208 netxen_nic_detach(adapter
);
2210 status
= NXRD32(adapter
, NETXEN_PEG_HALT_STATUS1
);
2212 ref_cnt
= nx_decr_dev_ref_cnt(adapter
);
2214 if (status
& NX_RCODE_FATAL_ERROR
)
2217 if (adapter
->temp
== NX_TEMP_PANIC
)
2220 delay
= (ref_cnt
== 0) ? 0 : (2 * FW_POLL_DELAY
);
2222 adapter
->fw_wait_cnt
= 0;
2223 netxen_schedule_work(adapter
, netxen_fwinit_work
, delay
);
2227 netxen_check_health(struct netxen_adapter
*adapter
)
2229 u32 state
, heartbit
;
2230 struct net_device
*netdev
= adapter
->netdev
;
2232 if (netxen_nic_check_temp(adapter
))
2235 if (adapter
->need_fw_reset
) {
2236 nx_dev_request_reset(adapter
);
2240 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2241 if (state
== NX_DEV_NEED_RESET
)
2244 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2247 heartbit
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
2248 if (heartbit
!= adapter
->heartbit
) {
2249 adapter
->heartbit
= heartbit
;
2250 adapter
->fw_fail_cnt
= 0;
2254 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
2257 clear_bit(__NX_FW_ATTACHED
, &adapter
->state
);
2259 dev_info(&netdev
->dev
, "firmware hang detected\n");
2262 if (!test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2263 netxen_schedule_work(adapter
, netxen_detach_work
, 0);
2268 netxen_fw_poll_work(struct work_struct
*work
)
2270 struct netxen_adapter
*adapter
= container_of(work
,
2271 struct netxen_adapter
, fw_work
.work
);
2273 if (test_bit(__NX_RESETTING
, &adapter
->state
))
2276 if (test_bit(__NX_DEV_UP
, &adapter
->state
)) {
2277 if (!adapter
->has_link_events
) {
2279 netxen_nic_handle_phy_intr(adapter
);
2281 if (adapter
->link_changed
)
2282 netxen_nic_set_link_parameters(adapter
);
2286 if (netxen_check_health(adapter
))
2290 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
2294 netxen_store_bridged_mode(struct device
*dev
,
2295 struct device_attribute
*attr
, const char *buf
, size_t len
)
2297 struct net_device
*net
= to_net_dev(dev
);
2298 struct netxen_adapter
*adapter
= netdev_priv(net
);
2302 if (!(adapter
->capabilities
& NX_FW_CAPABILITY_BDG
))
2305 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
2308 if (strict_strtoul(buf
, 2, &new))
2311 if (!netxen_config_bridged_mode(adapter
, !!new))
2319 netxen_show_bridged_mode(struct device
*dev
,
2320 struct device_attribute
*attr
, char *buf
)
2322 struct net_device
*net
= to_net_dev(dev
);
2323 struct netxen_adapter
*adapter
;
2324 int bridged_mode
= 0;
2326 adapter
= netdev_priv(net
);
2328 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
2329 bridged_mode
= !!(adapter
->flags
& NETXEN_NIC_BRIDGE_ENABLED
);
2331 return sprintf(buf
, "%d\n", bridged_mode
);
2334 static struct device_attribute dev_attr_bridged_mode
= {
2335 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2336 .show
= netxen_show_bridged_mode
,
2337 .store
= netxen_store_bridged_mode
,
2341 netxen_create_sysfs_entries(struct netxen_adapter
*adapter
)
2343 struct net_device
*netdev
= adapter
->netdev
;
2344 struct device
*dev
= &netdev
->dev
;
2346 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
) {
2347 /* bridged_mode control */
2348 if (device_create_file(dev
, &dev_attr_bridged_mode
)) {
2349 dev_warn(&netdev
->dev
,
2350 "failed to create bridged_mode sysfs entry\n");
2356 netxen_remove_sysfs_entries(struct netxen_adapter
*adapter
)
2358 struct net_device
*netdev
= adapter
->netdev
;
2359 struct device
*dev
= &netdev
->dev
;
2361 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
2362 device_remove_file(dev
, &dev_attr_bridged_mode
);
2367 #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2370 netxen_destip_supported(struct netxen_adapter
*adapter
)
2372 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2375 if (adapter
->ahw
.cut_through
)
2382 netxen_config_indev_addr(struct net_device
*dev
, unsigned long event
)
2384 struct in_device
*indev
;
2385 struct netxen_adapter
*adapter
= netdev_priv(dev
);
2387 if (!netxen_destip_supported(adapter
))
2390 indev
= in_dev_get(dev
);
2397 netxen_config_ipaddr(adapter
,
2398 ifa
->ifa_address
, NX_IP_UP
);
2401 netxen_config_ipaddr(adapter
,
2402 ifa
->ifa_address
, NX_IP_DOWN
);
2407 } endfor_ifa(indev
);
2413 static int netxen_netdev_event(struct notifier_block
*this,
2414 unsigned long event
, void *ptr
)
2416 struct netxen_adapter
*adapter
;
2417 struct net_device
*dev
= (struct net_device
*)ptr
;
2423 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
2424 dev
= vlan_dev_real_dev(dev
);
2428 if (!is_netxen_netdev(dev
))
2431 adapter
= netdev_priv(dev
);
2436 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
2439 netxen_config_indev_addr(dev
, event
);
2445 netxen_inetaddr_event(struct notifier_block
*this,
2446 unsigned long event
, void *ptr
)
2448 struct netxen_adapter
*adapter
;
2449 struct net_device
*dev
;
2451 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
2453 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
2456 if (dev
== NULL
|| !netif_running(dev
))
2459 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
2460 dev
= vlan_dev_real_dev(dev
);
2464 if (!is_netxen_netdev(dev
))
2467 adapter
= netdev_priv(dev
);
2469 if (!adapter
|| !netxen_destip_supported(adapter
))
2472 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
2477 netxen_config_ipaddr(adapter
, ifa
->ifa_address
, NX_IP_UP
);
2480 netxen_config_ipaddr(adapter
, ifa
->ifa_address
, NX_IP_DOWN
);
2490 static struct notifier_block netxen_netdev_cb
= {
2491 .notifier_call
= netxen_netdev_event
,
2494 static struct notifier_block netxen_inetaddr_cb
= {
2495 .notifier_call
= netxen_inetaddr_event
,
2499 netxen_config_indev_addr(struct net_device
*dev
, unsigned long event
)
2503 static struct pci_driver netxen_driver
= {
2504 .name
= netxen_nic_driver_name
,
2505 .id_table
= netxen_pci_tbl
,
2506 .probe
= netxen_nic_probe
,
2507 .remove
= __devexit_p(netxen_nic_remove
),
2509 .suspend
= netxen_nic_suspend
,
2510 .resume
= netxen_nic_resume
,
2512 .shutdown
= netxen_nic_shutdown
2515 static int __init
netxen_init_module(void)
2517 printk(KERN_INFO
"%s\n", netxen_nic_driver_string
);
2520 register_netdevice_notifier(&netxen_netdev_cb
);
2521 register_inetaddr_notifier(&netxen_inetaddr_cb
);
2524 return pci_register_driver(&netxen_driver
);
2527 module_init(netxen_init_module
);
2529 static void __exit
netxen_exit_module(void)
2531 pci_unregister_driver(&netxen_driver
);
2534 unregister_inetaddr_notifier(&netxen_inetaddr_cb
);
2535 unregister_netdevice_notifier(&netxen_netdev_cb
);
2539 module_exit(netxen_exit_module
);