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 resource_size_t mem_base
, db_base
;
599 unsigned long mem_len
, db_len
= 0, pci_len0
= 0;
601 struct pci_dev
*pdev
= adapter
->pdev
;
602 int pci_func
= adapter
->ahw
.pci_func
;
607 * Set the CRB window to invalid. If any register in window 0 is
608 * accessed it should set the window to 0 and then reset it to 1.
610 adapter
->curr_window
= 255;
611 adapter
->ahw
.qdr_sn_window
= -1;
612 adapter
->ahw
.ddr_mn_window
= -1;
614 /* remap phys address */
615 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
616 mem_len
= pci_resource_len(pdev
, 0);
619 /* 128 Meg of memory */
620 if (mem_len
== NETXEN_PCI_128MB_SIZE
) {
621 mem_ptr0
= ioremap(mem_base
, FIRST_PAGE_GROUP_SIZE
);
622 mem_ptr1
= ioremap(mem_base
+ SECOND_PAGE_GROUP_START
,
623 SECOND_PAGE_GROUP_SIZE
);
624 mem_ptr2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
,
625 THIRD_PAGE_GROUP_SIZE
);
626 } else if (mem_len
== NETXEN_PCI_32MB_SIZE
) {
627 mem_ptr1
= ioremap(mem_base
, SECOND_PAGE_GROUP_SIZE
);
628 mem_ptr2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
-
629 SECOND_PAGE_GROUP_START
, THIRD_PAGE_GROUP_SIZE
);
630 } else if (mem_len
== NETXEN_PCI_2MB_SIZE
) {
632 mem_ptr0
= pci_ioremap_bar(pdev
, 0);
633 if (mem_ptr0
== NULL
) {
634 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
639 adapter
->ahw
.ddr_mn_window
= 0;
640 adapter
->ahw
.qdr_sn_window
= 0;
642 adapter
->ahw
.mn_win_crb
= NETXEN_PCI_CRBSPACE
+
643 0x100000 + PCIX_MN_WINDOW
+ (pci_func
* 0x20);
644 adapter
->ahw
.ms_win_crb
= NETXEN_PCI_CRBSPACE
+
645 0x100000 + PCIX_SN_WINDOW
;
647 adapter
->ahw
.ms_win_crb
+= (pci_func
* 0x20);
649 adapter
->ahw
.ms_win_crb
+=
650 0xA0 + ((pci_func
- 4) * 0x10);
655 netxen_setup_hwops(adapter
);
657 dev_info(&pdev
->dev
, "%dMB memory map\n", (int)(mem_len
>>20));
659 adapter
->ahw
.pci_base0
= mem_ptr0
;
660 adapter
->ahw
.pci_len0
= pci_len0
;
661 adapter
->ahw
.pci_base1
= mem_ptr1
;
662 adapter
->ahw
.pci_base2
= mem_ptr2
;
664 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
667 db_base
= pci_resource_start(pdev
, 4); /* doorbell is on bar 4 */
668 db_len
= pci_resource_len(pdev
, 4);
671 printk(KERN_ERR
"%s: doorbell is disabled\n",
672 netxen_nic_driver_name
);
677 db_ptr
= ioremap(db_base
, NETXEN_DB_MAPSIZE_BYTES
);
679 printk(KERN_ERR
"%s: Failed to allocate doorbell map.",
680 netxen_nic_driver_name
);
686 adapter
->ahw
.db_base
= db_ptr
;
687 adapter
->ahw
.db_len
= db_len
;
691 netxen_cleanup_pci_map(adapter
);
696 netxen_check_options(struct netxen_adapter
*adapter
)
698 u32 fw_major
, fw_minor
, fw_build
;
699 char brd_name
[NETXEN_MAX_SHORT_NAME
];
703 struct pci_dev
*pdev
= adapter
->pdev
;
705 adapter
->driver_mismatch
= 0;
707 ptr32
= (int *)&serial_num
;
708 offset
= NX_FW_SERIAL_NUM_OFFSET
;
709 for (i
= 0; i
< 8; i
++) {
710 if (netxen_rom_fast_read(adapter
, offset
, &val
) == -1) {
711 dev_err(&pdev
->dev
, "error reading board info\n");
712 adapter
->driver_mismatch
= 1;
715 ptr32
[i
] = cpu_to_le32(val
);
716 offset
+= sizeof(u32
);
719 fw_major
= NXRD32(adapter
, NETXEN_FW_VERSION_MAJOR
);
720 fw_minor
= NXRD32(adapter
, NETXEN_FW_VERSION_MINOR
);
721 fw_build
= NXRD32(adapter
, NETXEN_FW_VERSION_SUB
);
723 adapter
->fw_version
= NETXEN_VERSION_CODE(fw_major
, fw_minor
, fw_build
);
725 if (adapter
->portnum
== 0) {
726 get_brd_name_by_type(adapter
->ahw
.board_type
, brd_name
);
728 printk(KERN_INFO
"NetXen %s Board S/N %s Chip rev 0x%x\n",
729 brd_name
, serial_num
, adapter
->ahw
.revision_id
);
732 if (adapter
->fw_version
< NETXEN_VERSION_CODE(3, 4, 216)) {
733 adapter
->driver_mismatch
= 1;
734 dev_warn(&pdev
->dev
, "firmware version %d.%d.%d unsupported\n",
735 fw_major
, fw_minor
, fw_build
);
739 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
740 i
= NXRD32(adapter
, NETXEN_SRE_MISC
);
741 adapter
->ahw
.cut_through
= (i
& 0x8000) ? 1 : 0;
744 dev_info(&pdev
->dev
, "firmware v%d.%d.%d [%s]\n",
745 fw_major
, fw_minor
, fw_build
,
746 adapter
->ahw
.cut_through
? "cut-through" : "legacy");
748 if (adapter
->fw_version
>= NETXEN_VERSION_CODE(4, 0, 222))
749 adapter
->capabilities
= NXRD32(adapter
, CRB_FW_CAPABILITIES_1
);
751 adapter
->flags
&= ~NETXEN_NIC_LRO_ENABLED
;
753 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
754 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
755 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
756 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
757 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
758 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
761 adapter
->msix_supported
= 0;
762 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
763 adapter
->msix_supported
= !!use_msi_x
;
764 adapter
->rss_supported
= !!use_msi_x
;
765 } else if (adapter
->fw_version
>= NETXEN_VERSION_CODE(3, 4, 336)) {
766 switch (adapter
->ahw
.board_type
) {
767 case NETXEN_BRDTYPE_P2_SB31_10G
:
768 case NETXEN_BRDTYPE_P2_SB31_10G_CX4
:
769 adapter
->msix_supported
= !!use_msi_x
;
770 adapter
->rss_supported
= !!use_msi_x
;
777 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
779 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
780 adapter
->num_lro_rxd
= MAX_LRO_RCV_DESCRIPTORS
;
781 adapter
->max_rds_rings
= 3;
783 adapter
->num_lro_rxd
= 0;
784 adapter
->max_rds_rings
= 2;
789 netxen_start_firmware(struct netxen_adapter
*adapter
)
791 int val
, err
, first_boot
;
792 struct pci_dev
*pdev
= adapter
->pdev
;
794 /* required for NX2031 dummy dma */
795 err
= nx_set_dma_mask(adapter
);
799 if (!netxen_can_start_firmware(adapter
))
802 first_boot
= NXRD32(adapter
, NETXEN_CAM_RAM(0x1fc));
804 err
= netxen_check_hw_init(adapter
, first_boot
);
806 dev_err(&pdev
->dev
, "error in init HW init sequence\n");
810 netxen_request_firmware(adapter
);
812 err
= netxen_need_fw_reset(adapter
);
818 if (first_boot
!= 0x55555555) {
819 NXWR32(adapter
, CRB_CMDPEG_STATE
, 0);
820 netxen_pinit_from_rom(adapter
, 0);
824 NXWR32(adapter
, CRB_DMA_SHIFT
, 0x55555555);
825 NXWR32(adapter
, NETXEN_PEG_HALT_STATUS1
, 0);
826 NXWR32(adapter
, NETXEN_PEG_HALT_STATUS2
, 0);
828 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
829 netxen_set_port_mode(adapter
);
831 err
= netxen_load_firmware(adapter
);
835 netxen_release_firmware(adapter
);
837 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
839 /* Initialize multicast addr pool owners */
841 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
)
843 NXWR32(adapter
, NETXEN_MAC_ADDR_CNTL_REG
, val
);
847 err
= netxen_init_dummy_dma(adapter
);
852 * Tell the hardware our version number.
854 val
= (_NETXEN_NIC_LINUX_MAJOR
<< 16)
855 | ((_NETXEN_NIC_LINUX_MINOR
<< 8))
856 | (_NETXEN_NIC_LINUX_SUBVERSION
);
857 NXWR32(adapter
, CRB_DRIVER_VERSION
, val
);
860 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_READY
);
863 /* Handshake with the card before we register the devices. */
864 err
= netxen_phantom_init(adapter
, NETXEN_NIC_PEG_TUNE
);
866 netxen_free_dummy_dma(adapter
);
870 nx_update_dma_mask(adapter
);
872 netxen_check_options(adapter
);
874 adapter
->need_fw_reset
= 0;
876 /* fall through and release firmware */
879 netxen_release_firmware(adapter
);
884 netxen_nic_request_irq(struct netxen_adapter
*adapter
)
886 irq_handler_t handler
;
887 struct nx_host_sds_ring
*sds_ring
;
890 unsigned long flags
= IRQF_SAMPLE_RANDOM
;
891 struct net_device
*netdev
= adapter
->netdev
;
892 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
894 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
895 handler
= netxen_msix_intr
;
896 else if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
897 handler
= netxen_msi_intr
;
899 flags
|= IRQF_SHARED
;
900 handler
= netxen_intr
;
902 adapter
->irq
= netdev
->irq
;
904 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
905 sds_ring
= &recv_ctx
->sds_rings
[ring
];
906 sprintf(sds_ring
->name
, "%s[%d]", netdev
->name
, ring
);
907 err
= request_irq(sds_ring
->irq
, handler
,
908 flags
, sds_ring
->name
, sds_ring
);
917 netxen_nic_free_irq(struct netxen_adapter
*adapter
)
920 struct nx_host_sds_ring
*sds_ring
;
922 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
924 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
925 sds_ring
= &recv_ctx
->sds_rings
[ring
];
926 free_irq(sds_ring
->irq
, sds_ring
);
931 netxen_nic_init_coalesce_defaults(struct netxen_adapter
*adapter
)
933 adapter
->coal
.flags
= NETXEN_NIC_INTR_DEFAULT
;
934 adapter
->coal
.normal
.data
.rx_time_us
=
935 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US
;
936 adapter
->coal
.normal
.data
.rx_packets
=
937 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS
;
938 adapter
->coal
.normal
.data
.tx_time_us
=
939 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US
;
940 adapter
->coal
.normal
.data
.tx_packets
=
941 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS
;
945 netxen_nic_up(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
949 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
952 err
= adapter
->init_port(adapter
, adapter
->physical_port
);
954 printk(KERN_ERR
"%s: Failed to initialize port %d\n",
955 netxen_nic_driver_name
, adapter
->portnum
);
958 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
959 adapter
->macaddr_set(adapter
, netdev
->dev_addr
);
961 adapter
->set_multi(netdev
);
962 adapter
->set_mtu(adapter
, netdev
->mtu
);
964 adapter
->ahw
.linkup
= 0;
966 if (adapter
->max_sds_rings
> 1)
967 netxen_config_rss(adapter
, 1);
969 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
970 netxen_config_intr_coalesce(adapter
);
972 if (adapter
->capabilities
& NX_FW_CAPABILITY_HW_LRO
)
973 netxen_config_hw_lro(adapter
, NETXEN_NIC_LRO_ENABLED
);
975 netxen_napi_enable(adapter
);
977 if (adapter
->capabilities
& NX_FW_CAPABILITY_LINK_NOTIFICATION
)
978 netxen_linkevent_request(adapter
, 1);
980 netxen_nic_set_link_parameters(adapter
);
982 set_bit(__NX_DEV_UP
, &adapter
->state
);
987 netxen_nic_down(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
989 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
992 clear_bit(__NX_DEV_UP
, &adapter
->state
);
994 spin_lock(&adapter
->tx_clean_lock
);
995 netif_carrier_off(netdev
);
996 netif_tx_disable(netdev
);
998 if (adapter
->stop_port
)
999 adapter
->stop_port(adapter
);
1001 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1002 netxen_p3_free_mac_list(adapter
);
1004 adapter
->set_promisc(adapter
, NETXEN_NIU_NON_PROMISC_MODE
);
1006 netxen_napi_disable(adapter
);
1008 netxen_release_tx_buffers(adapter
);
1009 spin_unlock(&adapter
->tx_clean_lock
);
1014 netxen_nic_attach(struct netxen_adapter
*adapter
)
1016 struct net_device
*netdev
= adapter
->netdev
;
1017 struct pci_dev
*pdev
= adapter
->pdev
;
1019 struct nx_host_rds_ring
*rds_ring
;
1020 struct nx_host_tx_ring
*tx_ring
;
1022 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
)
1025 err
= netxen_init_firmware(adapter
);
1029 err
= netxen_napi_add(adapter
, netdev
);
1033 err
= netxen_alloc_sw_resources(adapter
);
1035 printk(KERN_ERR
"%s: Error in setting sw resources\n",
1040 err
= netxen_alloc_hw_resources(adapter
);
1042 printk(KERN_ERR
"%s: Error in setting hw resources\n",
1044 goto err_out_free_sw
;
1047 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1048 tx_ring
= adapter
->tx_ring
;
1049 tx_ring
->crb_cmd_producer
= netxen_get_ioaddr(adapter
,
1050 crb_cmd_producer
[adapter
->portnum
]);
1051 tx_ring
->crb_cmd_consumer
= netxen_get_ioaddr(adapter
,
1052 crb_cmd_consumer
[adapter
->portnum
]);
1054 tx_ring
->producer
= 0;
1055 tx_ring
->sw_consumer
= 0;
1057 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
1058 netxen_nic_update_cmd_consumer(adapter
, tx_ring
);
1061 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1062 rds_ring
= &adapter
->recv_ctx
.rds_rings
[ring
];
1063 netxen_post_rx_buffers(adapter
, ring
, rds_ring
);
1066 err
= netxen_nic_request_irq(adapter
);
1068 dev_err(&pdev
->dev
, "%s: failed to setup interrupt\n",
1070 goto err_out_free_rxbuf
;
1073 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1074 netxen_nic_init_coalesce_defaults(adapter
);
1076 netxen_create_sysfs_entries(adapter
);
1078 adapter
->is_up
= NETXEN_ADAPTER_UP_MAGIC
;
1082 netxen_release_rx_buffers(adapter
);
1083 netxen_free_hw_resources(adapter
);
1085 netxen_free_sw_resources(adapter
);
1090 netxen_nic_detach(struct netxen_adapter
*adapter
)
1092 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1095 netxen_remove_sysfs_entries(adapter
);
1097 netxen_free_hw_resources(adapter
);
1098 netxen_release_rx_buffers(adapter
);
1099 netxen_nic_free_irq(adapter
);
1100 netxen_napi_del(adapter
);
1101 netxen_free_sw_resources(adapter
);
1107 netxen_nic_reset_context(struct netxen_adapter
*adapter
)
1110 struct net_device
*netdev
= adapter
->netdev
;
1112 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
1115 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
) {
1117 netif_device_detach(netdev
);
1119 if (netif_running(netdev
))
1120 netxen_nic_down(adapter
, netdev
);
1122 netxen_nic_detach(adapter
);
1124 if (netif_running(netdev
)) {
1125 err
= netxen_nic_attach(adapter
);
1127 err
= netxen_nic_up(adapter
, netdev
);
1133 netif_device_attach(netdev
);
1137 clear_bit(__NX_RESETTING
, &adapter
->state
);
1142 netxen_setup_netdev(struct netxen_adapter
*adapter
,
1143 struct net_device
*netdev
)
1146 struct pci_dev
*pdev
= adapter
->pdev
;
1148 adapter
->rx_csum
= 1;
1149 adapter
->mc_enabled
= 0;
1150 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1151 adapter
->max_mc_count
= 38;
1153 adapter
->max_mc_count
= 16;
1155 netdev
->netdev_ops
= &netxen_netdev_ops
;
1156 netdev
->watchdog_timeo
= 2*HZ
;
1158 netxen_nic_change_mtu(netdev
, netdev
->mtu
);
1160 SET_ETHTOOL_OPS(netdev
, &netxen_nic_ethtool_ops
);
1162 netdev
->features
|= (NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_TSO
);
1163 netdev
->features
|= (NETIF_F_GRO
);
1164 netdev
->vlan_features
|= (NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_TSO
);
1166 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
1167 netdev
->features
|= (NETIF_F_IPV6_CSUM
| NETIF_F_TSO6
);
1168 netdev
->vlan_features
|= (NETIF_F_IPV6_CSUM
| NETIF_F_TSO6
);
1171 if (adapter
->pci_using_dac
) {
1172 netdev
->features
|= NETIF_F_HIGHDMA
;
1173 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
1176 if (adapter
->capabilities
& NX_FW_CAPABILITY_FVLANTX
)
1177 netdev
->features
|= (NETIF_F_HW_VLAN_TX
);
1179 if (adapter
->capabilities
& NX_FW_CAPABILITY_HW_LRO
)
1180 netdev
->features
|= NETIF_F_LRO
;
1182 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1184 INIT_WORK(&adapter
->tx_timeout_task
, netxen_tx_timeout_task
);
1186 if (netxen_read_mac_addr(adapter
))
1187 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1189 netif_carrier_off(netdev
);
1190 netif_stop_queue(netdev
);
1192 err
= register_netdev(netdev
);
1194 dev_err(&pdev
->dev
, "failed to register net device\n");
1201 static int __devinit
1202 netxen_nic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1204 struct net_device
*netdev
= NULL
;
1205 struct netxen_adapter
*adapter
= NULL
;
1207 int pci_func_id
= PCI_FUNC(pdev
->devfn
);
1208 uint8_t revision_id
;
1210 if (pdev
->class != 0x020000) {
1211 printk(KERN_DEBUG
"NetXen function %d, class %x will not "
1212 "be enabled.\n",pci_func_id
, pdev
->class);
1216 if (pdev
->revision
>= NX_P3_A0
&& pdev
->revision
< NX_P3_B1
) {
1217 printk(KERN_WARNING
"NetXen chip revisions between 0x%x-0x%x"
1218 "will not be enabled.\n",
1219 NX_P3_A0
, NX_P3_B1
);
1223 if ((err
= pci_enable_device(pdev
)))
1226 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1228 goto err_out_disable_pdev
;
1231 if ((err
= pci_request_regions(pdev
, netxen_nic_driver_name
)))
1232 goto err_out_disable_pdev
;
1234 pci_set_master(pdev
);
1236 netdev
= alloc_etherdev(sizeof(struct netxen_adapter
));
1238 dev_err(&pdev
->dev
, "failed to allocate net_device\n");
1240 goto err_out_free_res
;
1243 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1245 adapter
= netdev_priv(netdev
);
1246 adapter
->netdev
= netdev
;
1247 adapter
->pdev
= pdev
;
1248 adapter
->ahw
.pci_func
= pci_func_id
;
1250 revision_id
= pdev
->revision
;
1251 adapter
->ahw
.revision_id
= revision_id
;
1253 rwlock_init(&adapter
->adapter_lock
);
1254 spin_lock_init(&adapter
->tx_clean_lock
);
1255 INIT_LIST_HEAD(&adapter
->mac_list
);
1257 err
= netxen_setup_pci_map(adapter
);
1259 goto err_out_free_netdev
;
1261 /* This will be reset for mezz cards */
1262 adapter
->portnum
= pci_func_id
;
1264 err
= netxen_nic_get_board_info(adapter
);
1266 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1267 goto err_out_iounmap
;
1270 /* Mezz cards have PCI function 0,2,3 enabled */
1271 switch (adapter
->ahw
.board_type
) {
1272 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
1273 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
1274 if (pci_func_id
>= 2)
1275 adapter
->portnum
= pci_func_id
- 2;
1281 err
= netxen_start_firmware(adapter
);
1283 goto err_out_iounmap
;
1286 * See if the firmware gave us a virtual-physical port mapping.
1288 adapter
->physical_port
= adapter
->portnum
;
1289 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1290 i
= NXRD32(adapter
, CRB_V2P(adapter
->portnum
));
1291 if (i
!= 0x55555555)
1292 adapter
->physical_port
= i
;
1295 netxen_nic_clear_stats(adapter
);
1297 netxen_setup_intr(adapter
);
1299 err
= netxen_setup_netdev(adapter
, netdev
);
1301 goto err_out_disable_msi
;
1303 pci_set_drvdata(pdev
, adapter
);
1305 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1307 switch (adapter
->ahw
.port_type
) {
1308 case NETXEN_NIC_GBE
:
1309 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1310 adapter
->netdev
->name
);
1312 case NETXEN_NIC_XGBE
:
1313 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1314 adapter
->netdev
->name
);
1320 err_out_disable_msi
:
1321 netxen_teardown_intr(adapter
);
1323 netxen_free_dummy_dma(adapter
);
1325 nx_decr_dev_ref_cnt(adapter
);
1328 netxen_cleanup_pci_map(adapter
);
1330 err_out_free_netdev
:
1331 free_netdev(netdev
);
1334 pci_release_regions(pdev
);
1336 err_out_disable_pdev
:
1337 pci_set_drvdata(pdev
, NULL
);
1338 pci_disable_device(pdev
);
1342 static void __devexit
netxen_nic_remove(struct pci_dev
*pdev
)
1344 struct netxen_adapter
*adapter
;
1345 struct net_device
*netdev
;
1347 adapter
= pci_get_drvdata(pdev
);
1348 if (adapter
== NULL
)
1351 netdev
= adapter
->netdev
;
1353 netxen_cancel_fw_work(adapter
);
1355 unregister_netdev(netdev
);
1357 cancel_work_sync(&adapter
->tx_timeout_task
);
1359 netxen_nic_detach(adapter
);
1361 nx_decr_dev_ref_cnt(adapter
);
1363 if (adapter
->portnum
== 0)
1364 netxen_free_dummy_dma(adapter
);
1366 clear_bit(__NX_RESETTING
, &adapter
->state
);
1368 netxen_teardown_intr(adapter
);
1370 netxen_cleanup_pci_map(adapter
);
1372 netxen_release_firmware(adapter
);
1374 pci_release_regions(pdev
);
1375 pci_disable_device(pdev
);
1376 pci_set_drvdata(pdev
, NULL
);
1378 free_netdev(netdev
);
1380 static int __netxen_nic_shutdown(struct pci_dev
*pdev
)
1382 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1383 struct net_device
*netdev
= adapter
->netdev
;
1386 netif_device_detach(netdev
);
1388 netxen_cancel_fw_work(adapter
);
1390 if (netif_running(netdev
))
1391 netxen_nic_down(adapter
, netdev
);
1393 cancel_work_sync(&adapter
->tx_timeout_task
);
1395 netxen_nic_detach(adapter
);
1397 if (adapter
->portnum
== 0)
1398 netxen_free_dummy_dma(adapter
);
1400 nx_decr_dev_ref_cnt(adapter
);
1402 clear_bit(__NX_RESETTING
, &adapter
->state
);
1404 retval
= pci_save_state(pdev
);
1408 if (netxen_nic_wol_supported(adapter
)) {
1409 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1410 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1413 pci_disable_device(pdev
);
1417 static void netxen_nic_shutdown(struct pci_dev
*pdev
)
1419 if (__netxen_nic_shutdown(pdev
))
1424 netxen_nic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1428 retval
= __netxen_nic_shutdown(pdev
);
1432 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1437 netxen_nic_resume(struct pci_dev
*pdev
)
1439 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1440 struct net_device
*netdev
= adapter
->netdev
;
1443 pci_set_power_state(pdev
, PCI_D0
);
1444 pci_restore_state(pdev
);
1446 err
= pci_enable_device(pdev
);
1450 adapter
->curr_window
= 255;
1452 err
= netxen_start_firmware(adapter
);
1454 dev_err(&pdev
->dev
, "failed to start firmware\n");
1458 if (netif_running(netdev
)) {
1459 err
= netxen_nic_attach(adapter
);
1463 err
= netxen_nic_up(adapter
, netdev
);
1465 goto err_out_detach
;
1467 netif_device_attach(netdev
);
1469 netxen_config_indev_addr(netdev
, NETDEV_UP
);
1472 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1476 netxen_nic_detach(adapter
);
1478 nx_decr_dev_ref_cnt(adapter
);
1483 static int netxen_nic_open(struct net_device
*netdev
)
1485 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1488 if (adapter
->driver_mismatch
)
1491 err
= netxen_nic_attach(adapter
);
1495 err
= netxen_nic_up(adapter
, netdev
);
1499 netif_start_queue(netdev
);
1504 netxen_nic_detach(adapter
);
1509 * netxen_nic_close - Disables a network interface entry point
1511 static int netxen_nic_close(struct net_device
*netdev
)
1513 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1515 netxen_nic_down(adapter
, netdev
);
1520 netxen_tso_check(struct net_device
*netdev
,
1521 struct nx_host_tx_ring
*tx_ring
,
1522 struct cmd_desc_type0
*first_desc
,
1523 struct sk_buff
*skb
)
1525 u8 opcode
= TX_ETHER_PKT
;
1526 __be16 protocol
= skb
->protocol
;
1527 u16 flags
= 0, vid
= 0;
1529 int copied
, offset
, copy_len
, hdr_len
= 0, tso
= 0, vlan_oob
= 0;
1530 struct cmd_desc_type0
*hwdesc
;
1531 struct vlan_ethhdr
*vh
;
1533 if (protocol
== cpu_to_be16(ETH_P_8021Q
)) {
1535 vh
= (struct vlan_ethhdr
*)skb
->data
;
1536 protocol
= vh
->h_vlan_encapsulated_proto
;
1537 flags
= FLAGS_VLAN_TAGGED
;
1539 } else if (vlan_tx_tag_present(skb
)) {
1541 flags
= FLAGS_VLAN_OOB
;
1542 vid
= vlan_tx_tag_get(skb
);
1543 netxen_set_tx_vlan_tci(first_desc
, vid
);
1547 if ((netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
1548 skb_shinfo(skb
)->gso_size
> 0) {
1550 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
1552 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
1553 first_desc
->total_hdr_length
= hdr_len
;
1555 first_desc
->total_hdr_length
+= VLAN_HLEN
;
1556 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
1557 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
1558 /* Only in case of TSO on vlan device */
1559 flags
|= FLAGS_VLAN_TAGGED
;
1562 opcode
= (protocol
== cpu_to_be16(ETH_P_IPV6
)) ?
1563 TX_TCP_LSO6
: TX_TCP_LSO
;
1566 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1569 if (protocol
== cpu_to_be16(ETH_P_IP
)) {
1570 l4proto
= ip_hdr(skb
)->protocol
;
1572 if (l4proto
== IPPROTO_TCP
)
1573 opcode
= TX_TCP_PKT
;
1574 else if(l4proto
== IPPROTO_UDP
)
1575 opcode
= TX_UDP_PKT
;
1576 } else if (protocol
== cpu_to_be16(ETH_P_IPV6
)) {
1577 l4proto
= ipv6_hdr(skb
)->nexthdr
;
1579 if (l4proto
== IPPROTO_TCP
)
1580 opcode
= TX_TCPV6_PKT
;
1581 else if(l4proto
== IPPROTO_UDP
)
1582 opcode
= TX_UDPV6_PKT
;
1586 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
1587 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
1588 netxen_set_tx_flags_opcode(first_desc
, flags
, opcode
);
1593 /* For LSO, we need to copy the MAC/IP/TCP headers into
1594 * the descriptor ring
1596 producer
= tx_ring
->producer
;
1601 /* Create a TSO vlan header template for firmware */
1603 hwdesc
= &tx_ring
->desc_head
[producer
];
1604 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1606 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1607 hdr_len
+ VLAN_HLEN
);
1609 vh
= (struct vlan_ethhdr
*)((char *)hwdesc
+ 2);
1610 skb_copy_from_linear_data(skb
, vh
, 12);
1611 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
1612 vh
->h_vlan_TCI
= htons(vid
);
1613 skb_copy_from_linear_data_offset(skb
, 12,
1614 (char *)vh
+ 16, copy_len
- 16);
1616 copied
= copy_len
- VLAN_HLEN
;
1619 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1622 while (copied
< hdr_len
) {
1624 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1625 (hdr_len
- copied
));
1627 hwdesc
= &tx_ring
->desc_head
[producer
];
1628 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1630 skb_copy_from_linear_data_offset(skb
, copied
,
1631 (char *)hwdesc
+ offset
, copy_len
);
1636 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1639 tx_ring
->producer
= producer
;
1644 netxen_map_tx_skb(struct pci_dev
*pdev
,
1645 struct sk_buff
*skb
, struct netxen_cmd_buffer
*pbuf
)
1647 struct netxen_skb_frag
*nf
;
1648 struct skb_frag_struct
*frag
;
1652 nr_frags
= skb_shinfo(skb
)->nr_frags
;
1653 nf
= &pbuf
->frag_array
[0];
1655 map
= pci_map_single(pdev
, skb
->data
,
1656 skb_headlen(skb
), PCI_DMA_TODEVICE
);
1657 if (pci_dma_mapping_error(pdev
, map
))
1661 nf
->length
= skb_headlen(skb
);
1663 for (i
= 0; i
< nr_frags
; i
++) {
1664 frag
= &skb_shinfo(skb
)->frags
[i
];
1665 nf
= &pbuf
->frag_array
[i
+1];
1667 map
= pci_map_page(pdev
, frag
->page
, frag
->page_offset
,
1668 frag
->size
, PCI_DMA_TODEVICE
);
1669 if (pci_dma_mapping_error(pdev
, map
))
1673 nf
->length
= frag
->size
;
1680 nf
= &pbuf
->frag_array
[i
+1];
1681 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
1684 nf
= &pbuf
->frag_array
[0];
1685 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
1692 netxen_clear_cmddesc(u64
*desc
)
1699 netxen_nic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
1701 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1702 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1703 struct netxen_cmd_buffer
*pbuf
;
1704 struct netxen_skb_frag
*buffrag
;
1705 struct cmd_desc_type0
*hwdesc
, *first_desc
;
1706 struct pci_dev
*pdev
;
1710 int frag_count
, no_of_desc
;
1711 u32 num_txd
= tx_ring
->num_desc
;
1713 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
1715 /* 4 fragments per cmd des */
1716 no_of_desc
= (frag_count
+ 3) >> 2;
1718 if (unlikely(no_of_desc
+ 2 > netxen_tx_avail(tx_ring
))) {
1719 netif_stop_queue(netdev
);
1720 return NETDEV_TX_BUSY
;
1723 producer
= tx_ring
->producer
;
1724 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
1726 pdev
= adapter
->pdev
;
1728 if (netxen_map_tx_skb(pdev
, skb
, pbuf
))
1732 pbuf
->frag_count
= frag_count
;
1734 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
1735 netxen_clear_cmddesc((u64
*)hwdesc
);
1737 netxen_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
1738 netxen_set_tx_port(first_desc
, adapter
->portnum
);
1740 for (i
= 0; i
< frag_count
; i
++) {
1744 if ((k
== 0) && (i
> 0)) {
1745 /* move to next desc.*/
1746 producer
= get_next_index(producer
, num_txd
);
1747 hwdesc
= &tx_ring
->desc_head
[producer
];
1748 netxen_clear_cmddesc((u64
*)hwdesc
);
1749 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1752 buffrag
= &pbuf
->frag_array
[i
];
1754 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
1757 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
1760 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
1763 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
1766 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
1771 tx_ring
->producer
= get_next_index(producer
, num_txd
);
1773 netxen_tso_check(netdev
, tx_ring
, first_desc
, skb
);
1775 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
1777 adapter
->stats
.txbytes
+= skb
->len
;
1778 adapter
->stats
.xmitcalled
++;
1780 return NETDEV_TX_OK
;
1783 adapter
->stats
.txdropped
++;
1784 dev_kfree_skb_any(skb
);
1785 return NETDEV_TX_OK
;
1788 static int netxen_nic_check_temp(struct netxen_adapter
*adapter
)
1790 struct net_device
*netdev
= adapter
->netdev
;
1791 uint32_t temp
, temp_state
, temp_val
;
1794 temp
= NXRD32(adapter
, CRB_TEMP_STATE
);
1796 temp_state
= nx_get_temp_state(temp
);
1797 temp_val
= nx_get_temp_val(temp
);
1799 if (temp_state
== NX_TEMP_PANIC
) {
1801 "%s: Device temperature %d degrees C exceeds"
1802 " maximum allowed. Hardware has been shut down.\n",
1803 netdev
->name
, temp_val
);
1805 } else if (temp_state
== NX_TEMP_WARN
) {
1806 if (adapter
->temp
== NX_TEMP_NORMAL
) {
1808 "%s: Device temperature %d degrees C "
1809 "exceeds operating range."
1810 " Immediate action needed.\n",
1811 netdev
->name
, temp_val
);
1814 if (adapter
->temp
== NX_TEMP_WARN
) {
1816 "%s: Device temperature is now %d degrees C"
1817 " in normal range.\n", netdev
->name
,
1821 adapter
->temp
= temp_state
;
1825 void netxen_advert_link_change(struct netxen_adapter
*adapter
, int linkup
)
1827 struct net_device
*netdev
= adapter
->netdev
;
1829 if (adapter
->ahw
.linkup
&& !linkup
) {
1830 printk(KERN_INFO
"%s: %s NIC Link is down\n",
1831 netxen_nic_driver_name
, netdev
->name
);
1832 adapter
->ahw
.linkup
= 0;
1833 if (netif_running(netdev
)) {
1834 netif_carrier_off(netdev
);
1835 netif_stop_queue(netdev
);
1837 adapter
->link_changed
= !adapter
->has_link_events
;
1838 } else if (!adapter
->ahw
.linkup
&& linkup
) {
1839 printk(KERN_INFO
"%s: %s NIC Link is up\n",
1840 netxen_nic_driver_name
, netdev
->name
);
1841 adapter
->ahw
.linkup
= 1;
1842 if (netif_running(netdev
)) {
1843 netif_carrier_on(netdev
);
1844 netif_wake_queue(netdev
);
1846 adapter
->link_changed
= !adapter
->has_link_events
;
1850 static void netxen_nic_handle_phy_intr(struct netxen_adapter
*adapter
)
1852 u32 val
, port
, linkup
;
1854 port
= adapter
->physical_port
;
1856 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
1857 val
= NXRD32(adapter
, CRB_XG_STATE_P3
);
1858 val
= XG_LINK_STATE_P3(adapter
->ahw
.pci_func
, val
);
1859 linkup
= (val
== XG_LINK_UP_P3
);
1861 val
= NXRD32(adapter
, CRB_XG_STATE
);
1862 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
)
1863 linkup
= (val
>> port
) & 1;
1865 val
= (val
>> port
*8) & 0xff;
1866 linkup
= (val
== XG_LINK_UP
);
1870 netxen_advert_link_change(adapter
, linkup
);
1873 static void netxen_tx_timeout(struct net_device
*netdev
)
1875 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1877 if (test_bit(__NX_RESETTING
, &adapter
->state
))
1880 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
1881 schedule_work(&adapter
->tx_timeout_task
);
1884 static void netxen_tx_timeout_task(struct work_struct
*work
)
1886 struct netxen_adapter
*adapter
=
1887 container_of(work
, struct netxen_adapter
, tx_timeout_task
);
1889 if (!netif_running(adapter
->netdev
))
1892 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
1895 if (++adapter
->tx_timeo_cnt
>= NX_MAX_TX_TIMEOUTS
)
1898 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1899 /* try to scrub interrupt */
1900 netxen_napi_disable(adapter
);
1902 adapter
->netdev
->trans_start
= jiffies
;
1904 netxen_napi_enable(adapter
);
1906 netif_wake_queue(adapter
->netdev
);
1908 clear_bit(__NX_RESETTING
, &adapter
->state
);
1911 clear_bit(__NX_RESETTING
, &adapter
->state
);
1912 if (!netxen_nic_reset_context(adapter
)) {
1913 adapter
->netdev
->trans_start
= jiffies
;
1917 /* context reset failed, fall through for fw reset */
1921 adapter
->need_fw_reset
= 1;
1924 struct net_device_stats
*netxen_nic_get_stats(struct net_device
*netdev
)
1926 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1927 struct net_device_stats
*stats
= &adapter
->net_stats
;
1929 memset(stats
, 0, sizeof(*stats
));
1931 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
1932 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
1933 stats
->rx_bytes
= adapter
->stats
.rxbytes
;
1934 stats
->tx_bytes
= adapter
->stats
.txbytes
;
1935 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
1936 stats
->tx_dropped
= adapter
->stats
.txdropped
;
1941 static irqreturn_t
netxen_intr(int irq
, void *data
)
1943 struct nx_host_sds_ring
*sds_ring
= data
;
1944 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
1947 status
= readl(adapter
->isr_int_vec
);
1949 if (!(status
& adapter
->int_vec_bit
))
1952 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
1953 /* check interrupt state machine, to be sure */
1954 status
= readl(adapter
->crb_int_state_reg
);
1955 if (!ISR_LEGACY_INT_TRIGGERED(status
))
1959 unsigned long our_int
= 0;
1961 our_int
= readl(adapter
->crb_int_state_reg
);
1963 /* not our interrupt */
1964 if (!test_and_clear_bit((7 + adapter
->portnum
), &our_int
))
1967 /* claim interrupt */
1968 writel((our_int
& 0xffffffff), adapter
->crb_int_state_reg
);
1970 /* clear interrupt */
1971 netxen_nic_disable_int(sds_ring
);
1974 writel(0xffffffff, adapter
->tgt_status_reg
);
1975 /* read twice to ensure write is flushed */
1976 readl(adapter
->isr_int_vec
);
1977 readl(adapter
->isr_int_vec
);
1979 napi_schedule(&sds_ring
->napi
);
1984 static irqreturn_t
netxen_msi_intr(int irq
, void *data
)
1986 struct nx_host_sds_ring
*sds_ring
= data
;
1987 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
1989 /* clear interrupt */
1990 writel(0xffffffff, adapter
->tgt_status_reg
);
1992 napi_schedule(&sds_ring
->napi
);
1996 static irqreturn_t
netxen_msix_intr(int irq
, void *data
)
1998 struct nx_host_sds_ring
*sds_ring
= data
;
2000 napi_schedule(&sds_ring
->napi
);
2004 static int netxen_nic_poll(struct napi_struct
*napi
, int budget
)
2006 struct nx_host_sds_ring
*sds_ring
=
2007 container_of(napi
, struct nx_host_sds_ring
, napi
);
2009 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2014 tx_complete
= netxen_process_cmd_ring(adapter
);
2016 work_done
= netxen_process_rcv_ring(sds_ring
, budget
);
2018 if ((work_done
< budget
) && tx_complete
) {
2019 napi_complete(&sds_ring
->napi
);
2020 if (netif_running(adapter
->netdev
))
2021 netxen_nic_enable_int(sds_ring
);
2027 #ifdef CONFIG_NET_POLL_CONTROLLER
2028 static void netxen_nic_poll_controller(struct net_device
*netdev
)
2030 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2031 disable_irq(adapter
->irq
);
2032 netxen_intr(adapter
->irq
, adapter
);
2033 enable_irq(adapter
->irq
);
2038 nx_incr_dev_ref_cnt(struct netxen_adapter
*adapter
)
2041 if (netxen_api_lock(adapter
))
2044 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2046 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, ++count
);
2048 netxen_api_unlock(adapter
);
2053 nx_decr_dev_ref_cnt(struct netxen_adapter
*adapter
)
2056 if (netxen_api_lock(adapter
))
2059 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2060 WARN_ON(count
== 0);
2062 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, --count
);
2065 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_COLD
);
2067 netxen_api_unlock(adapter
);
2072 nx_dev_request_reset(struct netxen_adapter
*adapter
)
2076 if (netxen_api_lock(adapter
))
2079 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2081 if (state
!= NX_DEV_INITALIZING
)
2082 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_NEED_RESET
);
2084 netxen_api_unlock(adapter
);
2088 netxen_can_start_firmware(struct netxen_adapter
*adapter
)
2093 if (netxen_api_lock(adapter
))
2096 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2098 if ((count
< 0) || (count
>= NX_MAX_PCI_FUNC
))
2103 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_INITALIZING
);
2106 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, ++count
);
2108 netxen_api_unlock(adapter
);
2114 netxen_schedule_work(struct netxen_adapter
*adapter
,
2115 work_func_t func
, int delay
)
2117 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
2118 schedule_delayed_work(&adapter
->fw_work
, delay
);
2122 netxen_cancel_fw_work(struct netxen_adapter
*adapter
)
2124 while (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2127 cancel_delayed_work_sync(&adapter
->fw_work
);
2131 netxen_attach_work(struct work_struct
*work
)
2133 struct netxen_adapter
*adapter
= container_of(work
,
2134 struct netxen_adapter
, fw_work
.work
);
2135 struct net_device
*netdev
= adapter
->netdev
;
2138 if (netif_running(netdev
)) {
2139 err
= netxen_nic_attach(adapter
);
2143 err
= netxen_nic_up(adapter
, netdev
);
2145 netxen_nic_detach(adapter
);
2149 netxen_config_indev_addr(netdev
, NETDEV_UP
);
2152 netif_device_attach(netdev
);
2155 adapter
->fw_fail_cnt
= 0;
2156 clear_bit(__NX_RESETTING
, &adapter
->state
);
2157 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
2161 netxen_fwinit_work(struct work_struct
*work
)
2163 struct netxen_adapter
*adapter
= container_of(work
,
2164 struct netxen_adapter
, fw_work
.work
);
2167 dev_state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2169 switch (dev_state
) {
2172 if (!netxen_start_firmware(adapter
)) {
2173 netxen_schedule_work(adapter
, netxen_attach_work
, 0);
2178 case NX_DEV_INITALIZING
:
2179 if (++adapter
->fw_wait_cnt
< FW_POLL_THRESH
) {
2180 netxen_schedule_work(adapter
,
2181 netxen_fwinit_work
, 2 * FW_POLL_DELAY
);
2191 nx_incr_dev_ref_cnt(adapter
);
2192 clear_bit(__NX_RESETTING
, &adapter
->state
);
2196 netxen_detach_work(struct work_struct
*work
)
2198 struct netxen_adapter
*adapter
= container_of(work
,
2199 struct netxen_adapter
, fw_work
.work
);
2200 struct net_device
*netdev
= adapter
->netdev
;
2204 netif_device_detach(netdev
);
2206 if (netif_running(netdev
))
2207 netxen_nic_down(adapter
, netdev
);
2209 netxen_nic_detach(adapter
);
2211 status
= NXRD32(adapter
, NETXEN_PEG_HALT_STATUS1
);
2213 ref_cnt
= nx_decr_dev_ref_cnt(adapter
);
2215 if (status
& NX_RCODE_FATAL_ERROR
)
2218 if (adapter
->temp
== NX_TEMP_PANIC
)
2221 delay
= (ref_cnt
== 0) ? 0 : (2 * FW_POLL_DELAY
);
2223 adapter
->fw_wait_cnt
= 0;
2224 netxen_schedule_work(adapter
, netxen_fwinit_work
, delay
);
2228 netxen_check_health(struct netxen_adapter
*adapter
)
2230 u32 state
, heartbit
;
2231 struct net_device
*netdev
= adapter
->netdev
;
2233 if (netxen_nic_check_temp(adapter
))
2236 if (adapter
->need_fw_reset
) {
2237 nx_dev_request_reset(adapter
);
2241 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2242 if (state
== NX_DEV_NEED_RESET
)
2245 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2248 heartbit
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
2249 if (heartbit
!= adapter
->heartbit
) {
2250 adapter
->heartbit
= heartbit
;
2251 adapter
->fw_fail_cnt
= 0;
2255 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
2258 clear_bit(__NX_FW_ATTACHED
, &adapter
->state
);
2260 dev_info(&netdev
->dev
, "firmware hang detected\n");
2263 if (!test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2264 netxen_schedule_work(adapter
, netxen_detach_work
, 0);
2269 netxen_fw_poll_work(struct work_struct
*work
)
2271 struct netxen_adapter
*adapter
= container_of(work
,
2272 struct netxen_adapter
, fw_work
.work
);
2274 if (test_bit(__NX_RESETTING
, &adapter
->state
))
2277 if (test_bit(__NX_DEV_UP
, &adapter
->state
)) {
2278 if (!adapter
->has_link_events
) {
2280 netxen_nic_handle_phy_intr(adapter
);
2282 if (adapter
->link_changed
)
2283 netxen_nic_set_link_parameters(adapter
);
2287 if (netxen_check_health(adapter
))
2291 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
2295 netxen_store_bridged_mode(struct device
*dev
,
2296 struct device_attribute
*attr
, const char *buf
, size_t len
)
2298 struct net_device
*net
= to_net_dev(dev
);
2299 struct netxen_adapter
*adapter
= netdev_priv(net
);
2303 if (!(adapter
->capabilities
& NX_FW_CAPABILITY_BDG
))
2306 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
2309 if (strict_strtoul(buf
, 2, &new))
2312 if (!netxen_config_bridged_mode(adapter
, !!new))
2320 netxen_show_bridged_mode(struct device
*dev
,
2321 struct device_attribute
*attr
, char *buf
)
2323 struct net_device
*net
= to_net_dev(dev
);
2324 struct netxen_adapter
*adapter
;
2325 int bridged_mode
= 0;
2327 adapter
= netdev_priv(net
);
2329 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
2330 bridged_mode
= !!(adapter
->flags
& NETXEN_NIC_BRIDGE_ENABLED
);
2332 return sprintf(buf
, "%d\n", bridged_mode
);
2335 static struct device_attribute dev_attr_bridged_mode
= {
2336 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2337 .show
= netxen_show_bridged_mode
,
2338 .store
= netxen_store_bridged_mode
,
2342 netxen_create_sysfs_entries(struct netxen_adapter
*adapter
)
2344 struct net_device
*netdev
= adapter
->netdev
;
2345 struct device
*dev
= &netdev
->dev
;
2347 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
) {
2348 /* bridged_mode control */
2349 if (device_create_file(dev
, &dev_attr_bridged_mode
)) {
2350 dev_warn(&netdev
->dev
,
2351 "failed to create bridged_mode sysfs entry\n");
2357 netxen_remove_sysfs_entries(struct netxen_adapter
*adapter
)
2359 struct net_device
*netdev
= adapter
->netdev
;
2360 struct device
*dev
= &netdev
->dev
;
2362 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
2363 device_remove_file(dev
, &dev_attr_bridged_mode
);
2368 #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2371 netxen_destip_supported(struct netxen_adapter
*adapter
)
2373 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2376 if (adapter
->ahw
.cut_through
)
2383 netxen_config_indev_addr(struct net_device
*dev
, unsigned long event
)
2385 struct in_device
*indev
;
2386 struct netxen_adapter
*adapter
= netdev_priv(dev
);
2388 if (!netxen_destip_supported(adapter
))
2391 indev
= in_dev_get(dev
);
2398 netxen_config_ipaddr(adapter
,
2399 ifa
->ifa_address
, NX_IP_UP
);
2402 netxen_config_ipaddr(adapter
,
2403 ifa
->ifa_address
, NX_IP_DOWN
);
2408 } endfor_ifa(indev
);
2414 static int netxen_netdev_event(struct notifier_block
*this,
2415 unsigned long event
, void *ptr
)
2417 struct netxen_adapter
*adapter
;
2418 struct net_device
*dev
= (struct net_device
*)ptr
;
2424 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
2425 dev
= vlan_dev_real_dev(dev
);
2429 if (!is_netxen_netdev(dev
))
2432 adapter
= netdev_priv(dev
);
2437 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
2440 netxen_config_indev_addr(dev
, event
);
2446 netxen_inetaddr_event(struct notifier_block
*this,
2447 unsigned long event
, void *ptr
)
2449 struct netxen_adapter
*adapter
;
2450 struct net_device
*dev
;
2452 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
2454 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
2457 if (dev
== NULL
|| !netif_running(dev
))
2460 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
2461 dev
= vlan_dev_real_dev(dev
);
2465 if (!is_netxen_netdev(dev
))
2468 adapter
= netdev_priv(dev
);
2470 if (!adapter
|| !netxen_destip_supported(adapter
))
2473 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
2478 netxen_config_ipaddr(adapter
, ifa
->ifa_address
, NX_IP_UP
);
2481 netxen_config_ipaddr(adapter
, ifa
->ifa_address
, NX_IP_DOWN
);
2491 static struct notifier_block netxen_netdev_cb
= {
2492 .notifier_call
= netxen_netdev_event
,
2495 static struct notifier_block netxen_inetaddr_cb
= {
2496 .notifier_call
= netxen_inetaddr_event
,
2500 netxen_config_indev_addr(struct net_device
*dev
, unsigned long event
)
2504 static struct pci_driver netxen_driver
= {
2505 .name
= netxen_nic_driver_name
,
2506 .id_table
= netxen_pci_tbl
,
2507 .probe
= netxen_nic_probe
,
2508 .remove
= __devexit_p(netxen_nic_remove
),
2510 .suspend
= netxen_nic_suspend
,
2511 .resume
= netxen_nic_resume
,
2513 .shutdown
= netxen_nic_shutdown
2516 static int __init
netxen_init_module(void)
2518 printk(KERN_INFO
"%s\n", netxen_nic_driver_string
);
2521 register_netdevice_notifier(&netxen_netdev_cb
);
2522 register_inetaddr_notifier(&netxen_inetaddr_cb
);
2525 return pci_register_driver(&netxen_driver
);
2528 module_init(netxen_init_module
);
2530 static void __exit
netxen_exit_module(void)
2532 pci_unregister_driver(&netxen_driver
);
2535 unregister_inetaddr_notifier(&netxen_inetaddr_cb
);
2536 unregister_netdevice_notifier(&netxen_netdev_cb
);
2540 module_exit(netxen_exit_module
);