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 "COPYING".
26 #include <linux/slab.h>
27 #include <linux/vmalloc.h>
28 #include <linux/interrupt.h>
29 #include "netxen_nic_hw.h"
31 #include "netxen_nic.h"
33 #include <linux/dma-mapping.h>
34 #include <linux/if_vlan.h>
36 #include <linux/ipv6.h>
37 #include <linux/inetdevice.h>
38 #include <linux/sysfs.h>
39 #include <linux/aer.h>
41 MODULE_DESCRIPTION("QLogic/NetXen (1/10) GbE Intelligent Ethernet Driver");
42 MODULE_LICENSE("GPL");
43 MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID
);
44 MODULE_FIRMWARE(NX_UNIFIED_ROMIMAGE_NAME
);
46 char netxen_nic_driver_name
[] = "netxen_nic";
47 static char netxen_nic_driver_string
[] = "QLogic/NetXen Network Driver v"
48 NETXEN_NIC_LINUX_VERSIONID
;
50 static int port_mode
= NETXEN_PORT_MODE_AUTO_NEG
;
52 /* Default to restricted 1G auto-neg mode */
53 static int wol_port_mode
= 5;
55 static int use_msi
= 1;
57 static int use_msi_x
= 1;
59 static int auto_fw_reset
= AUTO_FW_RESET_ENABLED
;
60 module_param(auto_fw_reset
, int, 0644);
61 MODULE_PARM_DESC(auto_fw_reset
,"Auto firmware reset (0=disabled, 1=enabled");
63 static int __devinit
netxen_nic_probe(struct pci_dev
*pdev
,
64 const struct pci_device_id
*ent
);
65 static void __devexit
netxen_nic_remove(struct pci_dev
*pdev
);
66 static int netxen_nic_open(struct net_device
*netdev
);
67 static int netxen_nic_close(struct net_device
*netdev
);
68 static netdev_tx_t
netxen_nic_xmit_frame(struct sk_buff
*,
70 static void netxen_tx_timeout(struct net_device
*netdev
);
71 static void netxen_tx_timeout_task(struct work_struct
*work
);
72 static void netxen_fw_poll_work(struct work_struct
*work
);
73 static void netxen_schedule_work(struct netxen_adapter
*adapter
,
74 work_func_t func
, int delay
);
75 static void netxen_cancel_fw_work(struct netxen_adapter
*adapter
);
76 static int netxen_nic_poll(struct napi_struct
*napi
, int budget
);
77 #ifdef CONFIG_NET_POLL_CONTROLLER
78 static void netxen_nic_poll_controller(struct net_device
*netdev
);
81 static void netxen_create_sysfs_entries(struct netxen_adapter
*adapter
);
82 static void netxen_remove_sysfs_entries(struct netxen_adapter
*adapter
);
83 static void netxen_create_diag_entries(struct netxen_adapter
*adapter
);
84 static void netxen_remove_diag_entries(struct netxen_adapter
*adapter
);
86 static int nx_dev_request_aer(struct netxen_adapter
*adapter
);
87 static int nx_decr_dev_ref_cnt(struct netxen_adapter
*adapter
);
88 static int netxen_can_start_firmware(struct netxen_adapter
*adapter
);
90 static irqreturn_t
netxen_intr(int irq
, void *data
);
91 static irqreturn_t
netxen_msi_intr(int irq
, void *data
);
92 static irqreturn_t
netxen_msix_intr(int irq
, void *data
);
94 static void netxen_free_vlan_ip_list(struct netxen_adapter
*);
95 static void netxen_restore_indev_addr(struct net_device
*dev
, unsigned long);
96 static struct rtnl_link_stats64
*netxen_nic_get_stats(struct net_device
*dev
,
97 struct rtnl_link_stats64
*stats
);
98 static int netxen_nic_set_mac(struct net_device
*netdev
, void *p
);
100 /* PCI Device ID Table */
101 #define ENTRY(device) \
102 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
103 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
105 static DEFINE_PCI_DEVICE_TABLE(netxen_pci_tbl
) = {
106 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR
),
107 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4
),
108 ENTRY(PCI_DEVICE_ID_NX2031_4GCU
),
109 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ
),
110 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ
),
111 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT
),
112 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2
),
113 ENTRY(PCI_DEVICE_ID_NX3031
),
117 MODULE_DEVICE_TABLE(pci
, netxen_pci_tbl
);
119 static uint32_t crb_cmd_producer
[4] = {
120 CRB_CMD_PRODUCER_OFFSET
, CRB_CMD_PRODUCER_OFFSET_1
,
121 CRB_CMD_PRODUCER_OFFSET_2
, CRB_CMD_PRODUCER_OFFSET_3
125 netxen_nic_update_cmd_producer(struct netxen_adapter
*adapter
,
126 struct nx_host_tx_ring
*tx_ring
)
128 NXWRIO(adapter
, tx_ring
->crb_cmd_producer
, tx_ring
->producer
);
131 static uint32_t crb_cmd_consumer
[4] = {
132 CRB_CMD_CONSUMER_OFFSET
, CRB_CMD_CONSUMER_OFFSET_1
,
133 CRB_CMD_CONSUMER_OFFSET_2
, CRB_CMD_CONSUMER_OFFSET_3
137 netxen_nic_update_cmd_consumer(struct netxen_adapter
*adapter
,
138 struct nx_host_tx_ring
*tx_ring
)
140 NXWRIO(adapter
, tx_ring
->crb_cmd_consumer
, tx_ring
->sw_consumer
);
143 static uint32_t msi_tgt_status
[8] = {
144 ISR_INT_TARGET_STATUS
, ISR_INT_TARGET_STATUS_F1
,
145 ISR_INT_TARGET_STATUS_F2
, ISR_INT_TARGET_STATUS_F3
,
146 ISR_INT_TARGET_STATUS_F4
, ISR_INT_TARGET_STATUS_F5
,
147 ISR_INT_TARGET_STATUS_F6
, ISR_INT_TARGET_STATUS_F7
150 static struct netxen_legacy_intr_set legacy_intr
[] = NX_LEGACY_INTR_CONFIG
;
152 static inline void netxen_nic_disable_int(struct nx_host_sds_ring
*sds_ring
)
154 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
156 NXWRIO(adapter
, sds_ring
->crb_intr_mask
, 0);
159 static inline void netxen_nic_enable_int(struct nx_host_sds_ring
*sds_ring
)
161 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
163 NXWRIO(adapter
, sds_ring
->crb_intr_mask
, 0x1);
165 if (!NETXEN_IS_MSI_FAMILY(adapter
))
166 NXWRIO(adapter
, adapter
->tgt_mask_reg
, 0xfbff);
170 netxen_alloc_sds_rings(struct netxen_recv_context
*recv_ctx
, int count
)
172 int size
= sizeof(struct nx_host_sds_ring
) * count
;
174 recv_ctx
->sds_rings
= kzalloc(size
, GFP_KERNEL
);
176 return recv_ctx
->sds_rings
== NULL
;
180 netxen_free_sds_rings(struct netxen_recv_context
*recv_ctx
)
182 if (recv_ctx
->sds_rings
!= NULL
)
183 kfree(recv_ctx
->sds_rings
);
185 recv_ctx
->sds_rings
= NULL
;
189 netxen_napi_add(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
192 struct nx_host_sds_ring
*sds_ring
;
193 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
195 if (netxen_alloc_sds_rings(recv_ctx
, adapter
->max_sds_rings
))
198 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
199 sds_ring
= &recv_ctx
->sds_rings
[ring
];
200 netif_napi_add(netdev
, &sds_ring
->napi
,
201 netxen_nic_poll
, NETXEN_NETDEV_WEIGHT
);
208 netxen_napi_del(struct netxen_adapter
*adapter
)
211 struct nx_host_sds_ring
*sds_ring
;
212 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
214 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
215 sds_ring
= &recv_ctx
->sds_rings
[ring
];
216 netif_napi_del(&sds_ring
->napi
);
219 netxen_free_sds_rings(&adapter
->recv_ctx
);
223 netxen_napi_enable(struct netxen_adapter
*adapter
)
226 struct nx_host_sds_ring
*sds_ring
;
227 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
229 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
230 sds_ring
= &recv_ctx
->sds_rings
[ring
];
231 napi_enable(&sds_ring
->napi
);
232 netxen_nic_enable_int(sds_ring
);
237 netxen_napi_disable(struct netxen_adapter
*adapter
)
240 struct nx_host_sds_ring
*sds_ring
;
241 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
243 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
244 sds_ring
= &recv_ctx
->sds_rings
[ring
];
245 netxen_nic_disable_int(sds_ring
);
246 napi_synchronize(&sds_ring
->napi
);
247 napi_disable(&sds_ring
->napi
);
251 static int nx_set_dma_mask(struct netxen_adapter
*adapter
)
253 struct pci_dev
*pdev
= adapter
->pdev
;
254 uint64_t mask
, cmask
;
256 adapter
->pci_using_dac
= 0;
258 mask
= DMA_BIT_MASK(32);
259 cmask
= DMA_BIT_MASK(32);
261 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
263 mask
= DMA_BIT_MASK(35);
266 mask
= DMA_BIT_MASK(39);
270 if (pci_set_dma_mask(pdev
, mask
) == 0 &&
271 pci_set_consistent_dma_mask(pdev
, cmask
) == 0) {
272 adapter
->pci_using_dac
= 1;
279 /* Update addressable range if firmware supports it */
281 nx_update_dma_mask(struct netxen_adapter
*adapter
)
283 int change
, shift
, err
;
284 uint64_t mask
, old_mask
, old_cmask
;
285 struct pci_dev
*pdev
= adapter
->pdev
;
289 shift
= NXRD32(adapter
, CRB_DMA_SHIFT
);
293 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) && (shift
> 9))
295 else if ((adapter
->ahw
.revision_id
== NX_P2_C1
) && (shift
<= 4))
299 old_mask
= pdev
->dma_mask
;
300 old_cmask
= pdev
->dev
.coherent_dma_mask
;
302 mask
= DMA_BIT_MASK(32+shift
);
304 err
= pci_set_dma_mask(pdev
, mask
);
308 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
310 err
= pci_set_consistent_dma_mask(pdev
, mask
);
314 dev_info(&pdev
->dev
, "using %d-bit dma mask\n", 32+shift
);
320 pci_set_dma_mask(pdev
, old_mask
);
321 pci_set_consistent_dma_mask(pdev
, old_cmask
);
326 netxen_check_hw_init(struct netxen_adapter
*adapter
, int first_boot
)
330 if (first_boot
== 0x55555555) {
331 /* This is the first boot after power up */
332 NXWR32(adapter
, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC
);
334 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
337 /* PCI bus master workaround */
338 first_boot
= NXRD32(adapter
, NETXEN_PCIE_REG(0x4));
339 if (!(first_boot
& 0x4)) {
341 NXWR32(adapter
, NETXEN_PCIE_REG(0x4), first_boot
);
342 NXRD32(adapter
, NETXEN_PCIE_REG(0x4));
345 /* This is the first boot after power up */
346 first_boot
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
);
347 if (first_boot
!= 0x80000f) {
348 /* clear the register for future unloads/loads */
349 NXWR32(adapter
, NETXEN_CAM_RAM(0x1fc), 0);
353 /* Start P2 boot loader */
354 val
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_PEGTUNE_DONE
);
355 NXWR32(adapter
, NETXEN_ROMUSB_GLB_PEGTUNE_DONE
, val
| 0x1);
359 val
= NXRD32(adapter
, NETXEN_CAM_RAM(0x1fc));
361 if (++timeout
> 5000)
364 } while (val
== NETXEN_BDINFO_MAGIC
);
369 static void netxen_set_port_mode(struct netxen_adapter
*adapter
)
373 val
= adapter
->ahw
.board_type
;
374 if ((val
== NETXEN_BRDTYPE_P3_HMEZ
) ||
375 (val
== NETXEN_BRDTYPE_P3_XG_LOM
)) {
376 if (port_mode
== NETXEN_PORT_MODE_802_3_AP
) {
377 data
= NETXEN_PORT_MODE_802_3_AP
;
378 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
379 } else if (port_mode
== NETXEN_PORT_MODE_XG
) {
380 data
= NETXEN_PORT_MODE_XG
;
381 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
382 } else if (port_mode
== NETXEN_PORT_MODE_AUTO_NEG_1G
) {
383 data
= NETXEN_PORT_MODE_AUTO_NEG_1G
;
384 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
385 } else if (port_mode
== NETXEN_PORT_MODE_AUTO_NEG_XG
) {
386 data
= NETXEN_PORT_MODE_AUTO_NEG_XG
;
387 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
389 data
= NETXEN_PORT_MODE_AUTO_NEG
;
390 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
393 if ((wol_port_mode
!= NETXEN_PORT_MODE_802_3_AP
) &&
394 (wol_port_mode
!= NETXEN_PORT_MODE_XG
) &&
395 (wol_port_mode
!= NETXEN_PORT_MODE_AUTO_NEG_1G
) &&
396 (wol_port_mode
!= NETXEN_PORT_MODE_AUTO_NEG_XG
)) {
397 wol_port_mode
= NETXEN_PORT_MODE_AUTO_NEG
;
399 NXWR32(adapter
, NETXEN_WOL_PORT_MODE
, wol_port_mode
);
403 static void netxen_set_msix_bit(struct pci_dev
*pdev
, int enable
)
408 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
410 pci_read_config_dword(pdev
, pos
, &control
);
412 control
|= PCI_MSIX_FLAGS_ENABLE
;
415 pci_write_config_dword(pdev
, pos
, control
);
419 static void netxen_init_msix_entries(struct netxen_adapter
*adapter
, int count
)
423 for (i
= 0; i
< count
; i
++)
424 adapter
->msix_entries
[i
].entry
= i
;
428 netxen_read_mac_addr(struct netxen_adapter
*adapter
)
433 struct net_device
*netdev
= adapter
->netdev
;
434 struct pci_dev
*pdev
= adapter
->pdev
;
436 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
437 if (netxen_p3_get_mac_addr(adapter
, &mac_addr
) != 0)
440 if (netxen_get_flash_mac_addr(adapter
, &mac_addr
) != 0)
444 p
= (unsigned char *)&mac_addr
;
445 for (i
= 0; i
< 6; i
++)
446 netdev
->dev_addr
[i
] = *(p
+ 5 - i
);
448 memcpy(netdev
->perm_addr
, netdev
->dev_addr
, netdev
->addr_len
);
449 memcpy(adapter
->mac_addr
, netdev
->dev_addr
, netdev
->addr_len
);
451 /* set station address */
453 if (!is_valid_ether_addr(netdev
->perm_addr
))
454 dev_warn(&pdev
->dev
, "Bad MAC address %pM.\n", netdev
->dev_addr
);
459 static int netxen_nic_set_mac(struct net_device
*netdev
, void *p
)
461 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
462 struct sockaddr
*addr
= p
;
464 if (!is_valid_ether_addr(addr
->sa_data
))
467 if (netif_running(netdev
)) {
468 netif_device_detach(netdev
);
469 netxen_napi_disable(adapter
);
472 memcpy(adapter
->mac_addr
, addr
->sa_data
, netdev
->addr_len
);
473 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
474 adapter
->macaddr_set(adapter
, addr
->sa_data
);
476 if (netif_running(netdev
)) {
477 netif_device_attach(netdev
);
478 netxen_napi_enable(adapter
);
483 static void netxen_set_multicast_list(struct net_device
*dev
)
485 struct netxen_adapter
*adapter
= netdev_priv(dev
);
487 adapter
->set_multi(dev
);
490 static u32
netxen_fix_features(struct net_device
*dev
, u32 features
)
492 if (!(features
& NETIF_F_RXCSUM
)) {
493 netdev_info(dev
, "disabling LRO as RXCSUM is off\n");
495 features
&= ~NETIF_F_LRO
;
501 static int netxen_set_features(struct net_device
*dev
, u32 features
)
503 struct netxen_adapter
*adapter
= netdev_priv(dev
);
506 if (!((dev
->features
^ features
) & NETIF_F_LRO
))
509 hw_lro
= (features
& NETIF_F_LRO
) ? NETXEN_NIC_LRO_ENABLED
510 : NETXEN_NIC_LRO_DISABLED
;
512 if (netxen_config_hw_lro(adapter
, hw_lro
))
515 if (!(features
& NETIF_F_LRO
) && netxen_send_lro_cleanup(adapter
))
521 static const struct net_device_ops netxen_netdev_ops
= {
522 .ndo_open
= netxen_nic_open
,
523 .ndo_stop
= netxen_nic_close
,
524 .ndo_start_xmit
= netxen_nic_xmit_frame
,
525 .ndo_get_stats64
= netxen_nic_get_stats
,
526 .ndo_validate_addr
= eth_validate_addr
,
527 .ndo_set_rx_mode
= netxen_set_multicast_list
,
528 .ndo_set_mac_address
= netxen_nic_set_mac
,
529 .ndo_change_mtu
= netxen_nic_change_mtu
,
530 .ndo_tx_timeout
= netxen_tx_timeout
,
531 .ndo_fix_features
= netxen_fix_features
,
532 .ndo_set_features
= netxen_set_features
,
533 #ifdef CONFIG_NET_POLL_CONTROLLER
534 .ndo_poll_controller
= netxen_nic_poll_controller
,
539 netxen_setup_intr(struct netxen_adapter
*adapter
)
541 struct netxen_legacy_intr_set
*legacy_intrp
;
542 struct pci_dev
*pdev
= adapter
->pdev
;
545 if (adapter
->rss_supported
) {
546 num_msix
= (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER
) ?
547 MSIX_ENTRIES_PER_ADAPTER
: 2;
551 adapter
->max_sds_rings
= 1;
553 adapter
->flags
&= ~(NETXEN_NIC_MSI_ENABLED
| NETXEN_NIC_MSIX_ENABLED
);
555 if (adapter
->ahw
.revision_id
>= NX_P3_B0
)
556 legacy_intrp
= &legacy_intr
[adapter
->ahw
.pci_func
];
558 legacy_intrp
= &legacy_intr
[0];
560 adapter
->int_vec_bit
= legacy_intrp
->int_vec_bit
;
561 adapter
->tgt_status_reg
= netxen_get_ioaddr(adapter
,
562 legacy_intrp
->tgt_status_reg
);
563 adapter
->tgt_mask_reg
= netxen_get_ioaddr(adapter
,
564 legacy_intrp
->tgt_mask_reg
);
565 adapter
->pci_int_reg
= netxen_get_ioaddr(adapter
,
566 legacy_intrp
->pci_int_reg
);
567 adapter
->isr_int_vec
= netxen_get_ioaddr(adapter
, ISR_INT_VECTOR
);
569 if (adapter
->ahw
.revision_id
>= NX_P3_B1
)
570 adapter
->crb_int_state_reg
= netxen_get_ioaddr(adapter
,
573 adapter
->crb_int_state_reg
= netxen_get_ioaddr(adapter
,
576 netxen_set_msix_bit(pdev
, 0);
578 if (adapter
->msix_supported
) {
580 netxen_init_msix_entries(adapter
, num_msix
);
581 err
= pci_enable_msix(pdev
, adapter
->msix_entries
, num_msix
);
583 adapter
->flags
|= NETXEN_NIC_MSIX_ENABLED
;
584 netxen_set_msix_bit(pdev
, 1);
586 if (adapter
->rss_supported
)
587 adapter
->max_sds_rings
= num_msix
;
589 dev_info(&pdev
->dev
, "using msi-x interrupts\n");
594 pci_disable_msix(pdev
);
596 /* fall through for msi */
599 if (use_msi
&& !pci_enable_msi(pdev
)) {
600 adapter
->flags
|= NETXEN_NIC_MSI_ENABLED
;
601 adapter
->tgt_status_reg
= netxen_get_ioaddr(adapter
,
602 msi_tgt_status
[adapter
->ahw
.pci_func
]);
603 dev_info(&pdev
->dev
, "using msi interrupts\n");
604 adapter
->msix_entries
[0].vector
= pdev
->irq
;
608 dev_info(&pdev
->dev
, "using legacy interrupts\n");
609 adapter
->msix_entries
[0].vector
= pdev
->irq
;
613 netxen_teardown_intr(struct netxen_adapter
*adapter
)
615 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
616 pci_disable_msix(adapter
->pdev
);
617 if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
618 pci_disable_msi(adapter
->pdev
);
622 netxen_cleanup_pci_map(struct netxen_adapter
*adapter
)
624 if (adapter
->ahw
.db_base
!= NULL
)
625 iounmap(adapter
->ahw
.db_base
);
626 if (adapter
->ahw
.pci_base0
!= NULL
)
627 iounmap(adapter
->ahw
.pci_base0
);
628 if (adapter
->ahw
.pci_base1
!= NULL
)
629 iounmap(adapter
->ahw
.pci_base1
);
630 if (adapter
->ahw
.pci_base2
!= NULL
)
631 iounmap(adapter
->ahw
.pci_base2
);
635 netxen_setup_pci_map(struct netxen_adapter
*adapter
)
637 void __iomem
*db_ptr
= NULL
;
639 resource_size_t mem_base
, db_base
;
640 unsigned long mem_len
, db_len
= 0;
642 struct pci_dev
*pdev
= adapter
->pdev
;
643 int pci_func
= adapter
->ahw
.pci_func
;
644 struct netxen_hardware_context
*ahw
= &adapter
->ahw
;
649 * Set the CRB window to invalid. If any register in window 0 is
650 * accessed it should set the window to 0 and then reset it to 1.
652 adapter
->ahw
.crb_win
= -1;
653 adapter
->ahw
.ocm_win
= -1;
655 /* remap phys address */
656 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
657 mem_len
= pci_resource_len(pdev
, 0);
659 /* 128 Meg of memory */
660 if (mem_len
== NETXEN_PCI_128MB_SIZE
) {
662 ahw
->pci_base0
= ioremap(mem_base
, FIRST_PAGE_GROUP_SIZE
);
663 ahw
->pci_base1
= ioremap(mem_base
+ SECOND_PAGE_GROUP_START
,
664 SECOND_PAGE_GROUP_SIZE
);
665 ahw
->pci_base2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
,
666 THIRD_PAGE_GROUP_SIZE
);
667 if (ahw
->pci_base0
== NULL
|| ahw
->pci_base1
== NULL
||
668 ahw
->pci_base2
== NULL
) {
669 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
674 ahw
->pci_len0
= FIRST_PAGE_GROUP_SIZE
;
676 } else if (mem_len
== NETXEN_PCI_32MB_SIZE
) {
678 ahw
->pci_base1
= ioremap(mem_base
, SECOND_PAGE_GROUP_SIZE
);
679 ahw
->pci_base2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
-
680 SECOND_PAGE_GROUP_START
, THIRD_PAGE_GROUP_SIZE
);
681 if (ahw
->pci_base1
== NULL
|| ahw
->pci_base2
== NULL
) {
682 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
687 } else if (mem_len
== NETXEN_PCI_2MB_SIZE
) {
689 ahw
->pci_base0
= pci_ioremap_bar(pdev
, 0);
690 if (ahw
->pci_base0
== NULL
) {
691 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
694 ahw
->pci_len0
= mem_len
;
699 netxen_setup_hwops(adapter
);
701 dev_info(&pdev
->dev
, "%dMB memory map\n", (int)(mem_len
>>20));
703 if (NX_IS_REVISION_P3P(adapter
->ahw
.revision_id
)) {
704 adapter
->ahw
.ocm_win_crb
= netxen_get_ioaddr(adapter
,
705 NETXEN_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(pci_func
)));
707 } else if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
708 adapter
->ahw
.ocm_win_crb
= netxen_get_ioaddr(adapter
,
709 NETXEN_PCIX_PS_REG(PCIE_MN_WINDOW_REG(pci_func
)));
712 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
715 db_base
= pci_resource_start(pdev
, 4); /* doorbell is on bar 4 */
716 db_len
= pci_resource_len(pdev
, 4);
719 printk(KERN_ERR
"%s: doorbell is disabled\n",
720 netxen_nic_driver_name
);
725 db_ptr
= ioremap(db_base
, NETXEN_DB_MAPSIZE_BYTES
);
727 printk(KERN_ERR
"%s: Failed to allocate doorbell map.",
728 netxen_nic_driver_name
);
734 adapter
->ahw
.db_base
= db_ptr
;
735 adapter
->ahw
.db_len
= db_len
;
739 netxen_cleanup_pci_map(adapter
);
744 netxen_check_options(struct netxen_adapter
*adapter
)
746 u32 fw_major
, fw_minor
, fw_build
;
747 char brd_name
[NETXEN_MAX_SHORT_NAME
];
751 struct pci_dev
*pdev
= adapter
->pdev
;
753 adapter
->driver_mismatch
= 0;
755 ptr32
= (int *)&serial_num
;
756 offset
= NX_FW_SERIAL_NUM_OFFSET
;
757 for (i
= 0; i
< 8; i
++) {
758 if (netxen_rom_fast_read(adapter
, offset
, &val
) == -1) {
759 dev_err(&pdev
->dev
, "error reading board info\n");
760 adapter
->driver_mismatch
= 1;
763 ptr32
[i
] = cpu_to_le32(val
);
764 offset
+= sizeof(u32
);
767 fw_major
= NXRD32(adapter
, NETXEN_FW_VERSION_MAJOR
);
768 fw_minor
= NXRD32(adapter
, NETXEN_FW_VERSION_MINOR
);
769 fw_build
= NXRD32(adapter
, NETXEN_FW_VERSION_SUB
);
771 adapter
->fw_version
= NETXEN_VERSION_CODE(fw_major
, fw_minor
, fw_build
);
773 if (adapter
->portnum
== 0) {
774 get_brd_name_by_type(adapter
->ahw
.board_type
, brd_name
);
776 pr_info("%s: %s Board S/N %s Chip rev 0x%x\n",
777 module_name(THIS_MODULE
),
778 brd_name
, serial_num
, adapter
->ahw
.revision_id
);
781 if (adapter
->fw_version
< NETXEN_VERSION_CODE(3, 4, 216)) {
782 adapter
->driver_mismatch
= 1;
783 dev_warn(&pdev
->dev
, "firmware version %d.%d.%d unsupported\n",
784 fw_major
, fw_minor
, fw_build
);
788 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
789 i
= NXRD32(adapter
, NETXEN_SRE_MISC
);
790 adapter
->ahw
.cut_through
= (i
& 0x8000) ? 1 : 0;
793 dev_info(&pdev
->dev
, "firmware v%d.%d.%d [%s]\n",
794 fw_major
, fw_minor
, fw_build
,
795 adapter
->ahw
.cut_through
? "cut-through" : "legacy");
797 if (adapter
->fw_version
>= NETXEN_VERSION_CODE(4, 0, 222))
798 adapter
->capabilities
= NXRD32(adapter
, CRB_FW_CAPABILITIES_1
);
800 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
801 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
802 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
803 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
804 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
805 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
808 adapter
->msix_supported
= 0;
809 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
810 adapter
->msix_supported
= !!use_msi_x
;
811 adapter
->rss_supported
= !!use_msi_x
;
814 netxen_rom_fast_read(adapter
,
815 NX_FW_VERSION_OFFSET
, (int *)&flashed_ver
);
816 flashed_ver
= NETXEN_DECODE_VERSION(flashed_ver
);
818 if (flashed_ver
>= NETXEN_VERSION_CODE(3, 4, 336)) {
819 switch (adapter
->ahw
.board_type
) {
820 case NETXEN_BRDTYPE_P2_SB31_10G
:
821 case NETXEN_BRDTYPE_P2_SB31_10G_CX4
:
822 adapter
->msix_supported
= !!use_msi_x
;
823 adapter
->rss_supported
= !!use_msi_x
;
831 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
833 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
834 adapter
->num_lro_rxd
= MAX_LRO_RCV_DESCRIPTORS
;
835 adapter
->max_rds_rings
= 3;
837 adapter
->num_lro_rxd
= 0;
838 adapter
->max_rds_rings
= 2;
843 netxen_start_firmware(struct netxen_adapter
*adapter
)
845 int val
, err
, first_boot
;
846 struct pci_dev
*pdev
= adapter
->pdev
;
848 /* required for NX2031 dummy dma */
849 err
= nx_set_dma_mask(adapter
);
853 if (!netxen_can_start_firmware(adapter
))
856 first_boot
= NXRD32(adapter
, NETXEN_CAM_RAM(0x1fc));
858 err
= netxen_check_hw_init(adapter
, first_boot
);
860 dev_err(&pdev
->dev
, "error in init HW init sequence\n");
864 netxen_request_firmware(adapter
);
866 err
= netxen_need_fw_reset(adapter
);
872 if (first_boot
!= 0x55555555) {
873 NXWR32(adapter
, CRB_CMDPEG_STATE
, 0);
874 netxen_pinit_from_rom(adapter
);
878 NXWR32(adapter
, CRB_DMA_SHIFT
, 0x55555555);
879 NXWR32(adapter
, NETXEN_PEG_HALT_STATUS1
, 0);
880 NXWR32(adapter
, NETXEN_PEG_HALT_STATUS2
, 0);
882 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
883 netxen_set_port_mode(adapter
);
885 err
= netxen_load_firmware(adapter
);
889 netxen_release_firmware(adapter
);
891 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
893 /* Initialize multicast addr pool owners */
895 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
)
897 NXWR32(adapter
, NETXEN_MAC_ADDR_CNTL_REG
, val
);
901 err
= netxen_init_dummy_dma(adapter
);
906 * Tell the hardware our version number.
908 val
= (_NETXEN_NIC_LINUX_MAJOR
<< 16)
909 | ((_NETXEN_NIC_LINUX_MINOR
<< 8))
910 | (_NETXEN_NIC_LINUX_SUBVERSION
);
911 NXWR32(adapter
, CRB_DRIVER_VERSION
, val
);
914 /* Handshake with the card before we register the devices. */
915 err
= netxen_phantom_init(adapter
, NETXEN_NIC_PEG_TUNE
);
917 netxen_free_dummy_dma(adapter
);
921 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_READY
);
923 nx_update_dma_mask(adapter
);
925 netxen_check_options(adapter
);
927 adapter
->need_fw_reset
= 0;
929 /* fall through and release firmware */
932 netxen_release_firmware(adapter
);
937 netxen_nic_request_irq(struct netxen_adapter
*adapter
)
939 irq_handler_t handler
;
940 struct nx_host_sds_ring
*sds_ring
;
943 unsigned long flags
= 0;
944 struct net_device
*netdev
= adapter
->netdev
;
945 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
947 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
948 handler
= netxen_msix_intr
;
949 else if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
950 handler
= netxen_msi_intr
;
952 flags
|= IRQF_SHARED
;
953 handler
= netxen_intr
;
955 adapter
->irq
= netdev
->irq
;
957 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
958 sds_ring
= &recv_ctx
->sds_rings
[ring
];
959 sprintf(sds_ring
->name
, "%s[%d]", netdev
->name
, ring
);
960 err
= request_irq(sds_ring
->irq
, handler
,
961 flags
, sds_ring
->name
, sds_ring
);
970 netxen_nic_free_irq(struct netxen_adapter
*adapter
)
973 struct nx_host_sds_ring
*sds_ring
;
975 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
977 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
978 sds_ring
= &recv_ctx
->sds_rings
[ring
];
979 free_irq(sds_ring
->irq
, sds_ring
);
984 netxen_nic_init_coalesce_defaults(struct netxen_adapter
*adapter
)
986 adapter
->coal
.flags
= NETXEN_NIC_INTR_DEFAULT
;
987 adapter
->coal
.normal
.data
.rx_time_us
=
988 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US
;
989 adapter
->coal
.normal
.data
.rx_packets
=
990 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS
;
991 adapter
->coal
.normal
.data
.tx_time_us
=
992 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US
;
993 adapter
->coal
.normal
.data
.tx_packets
=
994 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS
;
999 __netxen_nic_up(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1003 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1006 err
= adapter
->init_port(adapter
, adapter
->physical_port
);
1008 printk(KERN_ERR
"%s: Failed to initialize port %d\n",
1009 netxen_nic_driver_name
, adapter
->portnum
);
1012 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1013 adapter
->macaddr_set(adapter
, adapter
->mac_addr
);
1015 adapter
->set_multi(netdev
);
1016 adapter
->set_mtu(adapter
, netdev
->mtu
);
1018 adapter
->ahw
.linkup
= 0;
1020 if (adapter
->max_sds_rings
> 1)
1021 netxen_config_rss(adapter
, 1);
1023 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1024 netxen_config_intr_coalesce(adapter
);
1026 if (netdev
->features
& NETIF_F_LRO
)
1027 netxen_config_hw_lro(adapter
, NETXEN_NIC_LRO_ENABLED
);
1029 netxen_napi_enable(adapter
);
1031 if (adapter
->capabilities
& NX_FW_CAPABILITY_LINK_NOTIFICATION
)
1032 netxen_linkevent_request(adapter
, 1);
1034 netxen_nic_set_link_parameters(adapter
);
1036 set_bit(__NX_DEV_UP
, &adapter
->state
);
1040 /* Usage: During resume and firmware recovery module.*/
1043 netxen_nic_up(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1048 if (netif_running(netdev
))
1049 err
= __netxen_nic_up(adapter
, netdev
);
1055 /* with rtnl_lock */
1057 __netxen_nic_down(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1059 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1062 if (!test_and_clear_bit(__NX_DEV_UP
, &adapter
->state
))
1066 spin_lock(&adapter
->tx_clean_lock
);
1067 netif_carrier_off(netdev
);
1068 netif_tx_disable(netdev
);
1070 if (adapter
->capabilities
& NX_FW_CAPABILITY_LINK_NOTIFICATION
)
1071 netxen_linkevent_request(adapter
, 0);
1073 if (adapter
->stop_port
)
1074 adapter
->stop_port(adapter
);
1076 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1077 netxen_p3_free_mac_list(adapter
);
1079 adapter
->set_promisc(adapter
, NETXEN_NIU_NON_PROMISC_MODE
);
1081 netxen_napi_disable(adapter
);
1083 netxen_release_tx_buffers(adapter
);
1084 spin_unlock(&adapter
->tx_clean_lock
);
1087 /* Usage: During suspend and firmware recovery module */
1090 netxen_nic_down(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1093 if (netif_running(netdev
))
1094 __netxen_nic_down(adapter
, netdev
);
1100 netxen_nic_attach(struct netxen_adapter
*adapter
)
1102 struct net_device
*netdev
= adapter
->netdev
;
1103 struct pci_dev
*pdev
= adapter
->pdev
;
1105 struct nx_host_rds_ring
*rds_ring
;
1106 struct nx_host_tx_ring
*tx_ring
;
1108 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
)
1111 err
= netxen_init_firmware(adapter
);
1115 err
= netxen_napi_add(adapter
, netdev
);
1119 err
= netxen_alloc_sw_resources(adapter
);
1121 printk(KERN_ERR
"%s: Error in setting sw resources\n",
1126 err
= netxen_alloc_hw_resources(adapter
);
1128 printk(KERN_ERR
"%s: Error in setting hw resources\n",
1130 goto err_out_free_sw
;
1133 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1134 tx_ring
= adapter
->tx_ring
;
1135 tx_ring
->crb_cmd_producer
= netxen_get_ioaddr(adapter
,
1136 crb_cmd_producer
[adapter
->portnum
]);
1137 tx_ring
->crb_cmd_consumer
= netxen_get_ioaddr(adapter
,
1138 crb_cmd_consumer
[adapter
->portnum
]);
1140 tx_ring
->producer
= 0;
1141 tx_ring
->sw_consumer
= 0;
1143 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
1144 netxen_nic_update_cmd_consumer(adapter
, tx_ring
);
1147 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1148 rds_ring
= &adapter
->recv_ctx
.rds_rings
[ring
];
1149 netxen_post_rx_buffers(adapter
, ring
, rds_ring
);
1152 err
= netxen_nic_request_irq(adapter
);
1154 dev_err(&pdev
->dev
, "%s: failed to setup interrupt\n",
1156 goto err_out_free_rxbuf
;
1159 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1160 netxen_nic_init_coalesce_defaults(adapter
);
1162 netxen_create_sysfs_entries(adapter
);
1164 adapter
->is_up
= NETXEN_ADAPTER_UP_MAGIC
;
1168 netxen_release_rx_buffers(adapter
);
1169 netxen_free_hw_resources(adapter
);
1171 netxen_free_sw_resources(adapter
);
1176 netxen_nic_detach(struct netxen_adapter
*adapter
)
1178 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1181 netxen_remove_sysfs_entries(adapter
);
1183 netxen_free_hw_resources(adapter
);
1184 netxen_release_rx_buffers(adapter
);
1185 netxen_nic_free_irq(adapter
);
1186 netxen_napi_del(adapter
);
1187 netxen_free_sw_resources(adapter
);
1193 netxen_nic_reset_context(struct netxen_adapter
*adapter
)
1196 struct net_device
*netdev
= adapter
->netdev
;
1198 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
1201 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
) {
1203 netif_device_detach(netdev
);
1205 if (netif_running(netdev
))
1206 __netxen_nic_down(adapter
, netdev
);
1208 netxen_nic_detach(adapter
);
1210 if (netif_running(netdev
)) {
1211 err
= netxen_nic_attach(adapter
);
1213 err
= __netxen_nic_up(adapter
, netdev
);
1219 netif_device_attach(netdev
);
1223 clear_bit(__NX_RESETTING
, &adapter
->state
);
1228 netxen_setup_netdev(struct netxen_adapter
*adapter
,
1229 struct net_device
*netdev
)
1232 struct pci_dev
*pdev
= adapter
->pdev
;
1234 adapter
->mc_enabled
= 0;
1235 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1236 adapter
->max_mc_count
= 38;
1238 adapter
->max_mc_count
= 16;
1240 netdev
->netdev_ops
= &netxen_netdev_ops
;
1241 netdev
->watchdog_timeo
= 5*HZ
;
1243 netxen_nic_change_mtu(netdev
, netdev
->mtu
);
1245 SET_ETHTOOL_OPS(netdev
, &netxen_nic_ethtool_ops
);
1247 netdev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_TSO
|
1250 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1251 netdev
->hw_features
|= NETIF_F_IPV6_CSUM
| NETIF_F_TSO6
;
1253 netdev
->vlan_features
|= netdev
->hw_features
;
1255 if (adapter
->pci_using_dac
) {
1256 netdev
->features
|= NETIF_F_HIGHDMA
;
1257 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
1260 if (adapter
->capabilities
& NX_FW_CAPABILITY_FVLANTX
)
1261 netdev
->hw_features
|= NETIF_F_HW_VLAN_TX
;
1263 if (adapter
->capabilities
& NX_FW_CAPABILITY_HW_LRO
)
1264 netdev
->hw_features
|= NETIF_F_LRO
;
1266 netdev
->features
|= netdev
->hw_features
;
1268 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1270 INIT_WORK(&adapter
->tx_timeout_task
, netxen_tx_timeout_task
);
1272 if (netxen_read_mac_addr(adapter
))
1273 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1275 netif_carrier_off(netdev
);
1277 err
= register_netdev(netdev
);
1279 dev_err(&pdev
->dev
, "failed to register net device\n");
1286 #ifdef CONFIG_PCIEAER
1287 static void netxen_mask_aer_correctable(struct netxen_adapter
*adapter
)
1289 struct pci_dev
*pdev
= adapter
->pdev
;
1290 struct pci_dev
*root
= pdev
->bus
->self
;
1293 if (adapter
->ahw
.board_type
!= NETXEN_BRDTYPE_P3_4_GB_MM
&&
1294 adapter
->ahw
.board_type
!= NETXEN_BRDTYPE_P3_10G_TP
)
1297 if (root
->pcie_type
!= PCI_EXP_TYPE_ROOT_PORT
)
1300 aer_pos
= pci_find_ext_capability(root
, PCI_EXT_CAP_ID_ERR
);
1304 pci_write_config_dword(root
, aer_pos
+ PCI_ERR_COR_MASK
, 0xffff);
1308 static int __devinit
1309 netxen_nic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1311 struct net_device
*netdev
= NULL
;
1312 struct netxen_adapter
*adapter
= NULL
;
1314 int pci_func_id
= PCI_FUNC(pdev
->devfn
);
1315 uint8_t revision_id
;
1318 if (pdev
->revision
>= NX_P3_A0
&& pdev
->revision
<= NX_P3_B1
) {
1319 pr_warning("%s: chip revisions between 0x%x-0x%x "
1320 "will not be enabled.\n",
1321 module_name(THIS_MODULE
), NX_P3_A0
, NX_P3_B1
);
1325 if ((err
= pci_enable_device(pdev
)))
1328 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1330 goto err_out_disable_pdev
;
1333 if ((err
= pci_request_regions(pdev
, netxen_nic_driver_name
)))
1334 goto err_out_disable_pdev
;
1336 if (NX_IS_REVISION_P3(pdev
->revision
))
1337 pci_enable_pcie_error_reporting(pdev
);
1339 pci_set_master(pdev
);
1341 netdev
= alloc_etherdev(sizeof(struct netxen_adapter
));
1343 dev_err(&pdev
->dev
, "failed to allocate net_device\n");
1345 goto err_out_free_res
;
1348 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1350 adapter
= netdev_priv(netdev
);
1351 adapter
->netdev
= netdev
;
1352 adapter
->pdev
= pdev
;
1353 adapter
->ahw
.pci_func
= pci_func_id
;
1355 revision_id
= pdev
->revision
;
1356 adapter
->ahw
.revision_id
= revision_id
;
1358 rwlock_init(&adapter
->ahw
.crb_lock
);
1359 spin_lock_init(&adapter
->ahw
.mem_lock
);
1361 spin_lock_init(&adapter
->tx_clean_lock
);
1362 INIT_LIST_HEAD(&adapter
->mac_list
);
1363 INIT_LIST_HEAD(&adapter
->vlan_ip_list
);
1365 err
= netxen_setup_pci_map(adapter
);
1367 goto err_out_free_netdev
;
1369 /* This will be reset for mezz cards */
1370 adapter
->portnum
= pci_func_id
;
1372 err
= netxen_nic_get_board_info(adapter
);
1374 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1375 goto err_out_iounmap
;
1378 #ifdef CONFIG_PCIEAER
1379 netxen_mask_aer_correctable(adapter
);
1382 /* Mezz cards have PCI function 0,2,3 enabled */
1383 switch (adapter
->ahw
.board_type
) {
1384 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
1385 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
1386 if (pci_func_id
>= 2)
1387 adapter
->portnum
= pci_func_id
- 2;
1393 err
= netxen_check_flash_fw_compatibility(adapter
);
1395 goto err_out_iounmap
;
1397 if (adapter
->portnum
== 0) {
1398 val
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
1399 if (val
!= 0xffffffff && val
!= 0) {
1400 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, 0);
1401 adapter
->need_fw_reset
= 1;
1405 err
= netxen_start_firmware(adapter
);
1407 goto err_out_decr_ref
;
1410 * See if the firmware gave us a virtual-physical port mapping.
1412 adapter
->physical_port
= adapter
->portnum
;
1413 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1414 i
= NXRD32(adapter
, CRB_V2P(adapter
->portnum
));
1415 if (i
!= 0x55555555)
1416 adapter
->physical_port
= i
;
1419 netxen_nic_clear_stats(adapter
);
1421 netxen_setup_intr(adapter
);
1423 err
= netxen_setup_netdev(adapter
, netdev
);
1425 goto err_out_disable_msi
;
1427 pci_set_drvdata(pdev
, adapter
);
1429 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1431 switch (adapter
->ahw
.port_type
) {
1432 case NETXEN_NIC_GBE
:
1433 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1434 adapter
->netdev
->name
);
1436 case NETXEN_NIC_XGBE
:
1437 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1438 adapter
->netdev
->name
);
1442 netxen_create_diag_entries(adapter
);
1446 err_out_disable_msi
:
1447 netxen_teardown_intr(adapter
);
1449 netxen_free_dummy_dma(adapter
);
1452 nx_decr_dev_ref_cnt(adapter
);
1455 netxen_cleanup_pci_map(adapter
);
1457 err_out_free_netdev
:
1458 free_netdev(netdev
);
1461 pci_release_regions(pdev
);
1463 err_out_disable_pdev
:
1464 pci_set_drvdata(pdev
, NULL
);
1465 pci_disable_device(pdev
);
1469 static void __devexit
netxen_nic_remove(struct pci_dev
*pdev
)
1471 struct netxen_adapter
*adapter
;
1472 struct net_device
*netdev
;
1474 adapter
= pci_get_drvdata(pdev
);
1475 if (adapter
== NULL
)
1478 netdev
= adapter
->netdev
;
1480 netxen_cancel_fw_work(adapter
);
1482 unregister_netdev(netdev
);
1484 cancel_work_sync(&adapter
->tx_timeout_task
);
1486 netxen_free_vlan_ip_list(adapter
);
1487 netxen_nic_detach(adapter
);
1489 nx_decr_dev_ref_cnt(adapter
);
1491 if (adapter
->portnum
== 0)
1492 netxen_free_dummy_dma(adapter
);
1494 clear_bit(__NX_RESETTING
, &adapter
->state
);
1496 netxen_teardown_intr(adapter
);
1498 netxen_remove_diag_entries(adapter
);
1500 netxen_cleanup_pci_map(adapter
);
1502 netxen_release_firmware(adapter
);
1504 if (NX_IS_REVISION_P3(pdev
->revision
))
1505 pci_disable_pcie_error_reporting(pdev
);
1507 pci_release_regions(pdev
);
1508 pci_disable_device(pdev
);
1509 pci_set_drvdata(pdev
, NULL
);
1511 free_netdev(netdev
);
1514 static void netxen_nic_detach_func(struct netxen_adapter
*adapter
)
1516 struct net_device
*netdev
= adapter
->netdev
;
1518 netif_device_detach(netdev
);
1520 netxen_cancel_fw_work(adapter
);
1522 if (netif_running(netdev
))
1523 netxen_nic_down(adapter
, netdev
);
1525 cancel_work_sync(&adapter
->tx_timeout_task
);
1527 netxen_nic_detach(adapter
);
1529 if (adapter
->portnum
== 0)
1530 netxen_free_dummy_dma(adapter
);
1532 nx_decr_dev_ref_cnt(adapter
);
1534 clear_bit(__NX_RESETTING
, &adapter
->state
);
1537 static int netxen_nic_attach_func(struct pci_dev
*pdev
)
1539 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1540 struct net_device
*netdev
= adapter
->netdev
;
1543 err
= pci_enable_device(pdev
);
1547 pci_set_power_state(pdev
, PCI_D0
);
1548 pci_set_master(pdev
);
1549 pci_restore_state(pdev
);
1551 adapter
->ahw
.crb_win
= -1;
1552 adapter
->ahw
.ocm_win
= -1;
1554 err
= netxen_start_firmware(adapter
);
1556 dev_err(&pdev
->dev
, "failed to start firmware\n");
1560 if (netif_running(netdev
)) {
1561 err
= netxen_nic_attach(adapter
);
1565 err
= netxen_nic_up(adapter
, netdev
);
1567 goto err_out_detach
;
1569 netxen_restore_indev_addr(netdev
, NETDEV_UP
);
1572 netif_device_attach(netdev
);
1573 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1577 netxen_nic_detach(adapter
);
1579 nx_decr_dev_ref_cnt(adapter
);
1583 static pci_ers_result_t
netxen_io_error_detected(struct pci_dev
*pdev
,
1584 pci_channel_state_t state
)
1586 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1588 if (state
== pci_channel_io_perm_failure
)
1589 return PCI_ERS_RESULT_DISCONNECT
;
1591 if (nx_dev_request_aer(adapter
))
1592 return PCI_ERS_RESULT_RECOVERED
;
1594 netxen_nic_detach_func(adapter
);
1596 pci_disable_device(pdev
);
1598 return PCI_ERS_RESULT_NEED_RESET
;
1601 static pci_ers_result_t
netxen_io_slot_reset(struct pci_dev
*pdev
)
1605 err
= netxen_nic_attach_func(pdev
);
1607 return err
? PCI_ERS_RESULT_DISCONNECT
: PCI_ERS_RESULT_RECOVERED
;
1610 static void netxen_io_resume(struct pci_dev
*pdev
)
1612 pci_cleanup_aer_uncorrect_error_status(pdev
);
1615 static void netxen_nic_shutdown(struct pci_dev
*pdev
)
1617 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1619 netxen_nic_detach_func(adapter
);
1621 if (pci_save_state(pdev
))
1624 if (netxen_nic_wol_supported(adapter
)) {
1625 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1626 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1629 pci_disable_device(pdev
);
1634 netxen_nic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1636 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1639 netxen_nic_detach_func(adapter
);
1641 retval
= pci_save_state(pdev
);
1645 if (netxen_nic_wol_supported(adapter
)) {
1646 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1647 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1650 pci_disable_device(pdev
);
1651 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1657 netxen_nic_resume(struct pci_dev
*pdev
)
1659 return netxen_nic_attach_func(pdev
);
1663 static int netxen_nic_open(struct net_device
*netdev
)
1665 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1668 if (adapter
->driver_mismatch
)
1671 err
= netxen_nic_attach(adapter
);
1675 err
= __netxen_nic_up(adapter
, netdev
);
1679 netif_start_queue(netdev
);
1684 netxen_nic_detach(adapter
);
1689 * netxen_nic_close - Disables a network interface entry point
1691 static int netxen_nic_close(struct net_device
*netdev
)
1693 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1695 __netxen_nic_down(adapter
, netdev
);
1700 netxen_tso_check(struct net_device
*netdev
,
1701 struct nx_host_tx_ring
*tx_ring
,
1702 struct cmd_desc_type0
*first_desc
,
1703 struct sk_buff
*skb
)
1705 u8 opcode
= TX_ETHER_PKT
;
1706 __be16 protocol
= skb
->protocol
;
1707 u16 flags
= 0, vid
= 0;
1709 int copied
, offset
, copy_len
, hdr_len
= 0, tso
= 0, vlan_oob
= 0;
1710 struct cmd_desc_type0
*hwdesc
;
1711 struct vlan_ethhdr
*vh
;
1713 if (protocol
== cpu_to_be16(ETH_P_8021Q
)) {
1715 vh
= (struct vlan_ethhdr
*)skb
->data
;
1716 protocol
= vh
->h_vlan_encapsulated_proto
;
1717 flags
= FLAGS_VLAN_TAGGED
;
1719 } else if (vlan_tx_tag_present(skb
)) {
1721 flags
= FLAGS_VLAN_OOB
;
1722 vid
= vlan_tx_tag_get(skb
);
1723 netxen_set_tx_vlan_tci(first_desc
, vid
);
1727 if ((netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
1728 skb_shinfo(skb
)->gso_size
> 0) {
1730 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
1732 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
1733 first_desc
->total_hdr_length
= hdr_len
;
1735 first_desc
->total_hdr_length
+= VLAN_HLEN
;
1736 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
1737 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
1738 /* Only in case of TSO on vlan device */
1739 flags
|= FLAGS_VLAN_TAGGED
;
1742 opcode
= (protocol
== cpu_to_be16(ETH_P_IPV6
)) ?
1743 TX_TCP_LSO6
: TX_TCP_LSO
;
1746 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1749 if (protocol
== cpu_to_be16(ETH_P_IP
)) {
1750 l4proto
= ip_hdr(skb
)->protocol
;
1752 if (l4proto
== IPPROTO_TCP
)
1753 opcode
= TX_TCP_PKT
;
1754 else if(l4proto
== IPPROTO_UDP
)
1755 opcode
= TX_UDP_PKT
;
1756 } else if (protocol
== cpu_to_be16(ETH_P_IPV6
)) {
1757 l4proto
= ipv6_hdr(skb
)->nexthdr
;
1759 if (l4proto
== IPPROTO_TCP
)
1760 opcode
= TX_TCPV6_PKT
;
1761 else if(l4proto
== IPPROTO_UDP
)
1762 opcode
= TX_UDPV6_PKT
;
1766 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
1767 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
1768 netxen_set_tx_flags_opcode(first_desc
, flags
, opcode
);
1773 /* For LSO, we need to copy the MAC/IP/TCP headers into
1774 * the descriptor ring
1776 producer
= tx_ring
->producer
;
1781 /* Create a TSO vlan header template for firmware */
1783 hwdesc
= &tx_ring
->desc_head
[producer
];
1784 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1786 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1787 hdr_len
+ VLAN_HLEN
);
1789 vh
= (struct vlan_ethhdr
*)((char *)hwdesc
+ 2);
1790 skb_copy_from_linear_data(skb
, vh
, 12);
1791 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
1792 vh
->h_vlan_TCI
= htons(vid
);
1793 skb_copy_from_linear_data_offset(skb
, 12,
1794 (char *)vh
+ 16, copy_len
- 16);
1796 copied
= copy_len
- VLAN_HLEN
;
1799 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1802 while (copied
< hdr_len
) {
1804 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1805 (hdr_len
- copied
));
1807 hwdesc
= &tx_ring
->desc_head
[producer
];
1808 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1810 skb_copy_from_linear_data_offset(skb
, copied
,
1811 (char *)hwdesc
+ offset
, copy_len
);
1816 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1819 tx_ring
->producer
= producer
;
1824 netxen_map_tx_skb(struct pci_dev
*pdev
,
1825 struct sk_buff
*skb
, struct netxen_cmd_buffer
*pbuf
)
1827 struct netxen_skb_frag
*nf
;
1828 struct skb_frag_struct
*frag
;
1832 nr_frags
= skb_shinfo(skb
)->nr_frags
;
1833 nf
= &pbuf
->frag_array
[0];
1835 map
= pci_map_single(pdev
, skb
->data
,
1836 skb_headlen(skb
), PCI_DMA_TODEVICE
);
1837 if (pci_dma_mapping_error(pdev
, map
))
1841 nf
->length
= skb_headlen(skb
);
1843 for (i
= 0; i
< nr_frags
; i
++) {
1844 frag
= &skb_shinfo(skb
)->frags
[i
];
1845 nf
= &pbuf
->frag_array
[i
+1];
1847 map
= pci_map_page(pdev
, frag
->page
, frag
->page_offset
,
1848 frag
->size
, PCI_DMA_TODEVICE
);
1849 if (pci_dma_mapping_error(pdev
, map
))
1853 nf
->length
= frag
->size
;
1860 nf
= &pbuf
->frag_array
[i
+1];
1861 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
1864 nf
= &pbuf
->frag_array
[0];
1865 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
1872 netxen_clear_cmddesc(u64
*desc
)
1879 netxen_nic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
1881 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1882 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1883 struct netxen_cmd_buffer
*pbuf
;
1884 struct netxen_skb_frag
*buffrag
;
1885 struct cmd_desc_type0
*hwdesc
, *first_desc
;
1886 struct pci_dev
*pdev
;
1889 struct skb_frag_struct
*frag
;
1892 int frag_count
, no_of_desc
;
1893 u32 num_txd
= tx_ring
->num_desc
;
1895 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
1897 /* 14 frags supported for normal packet and
1898 * 32 frags supported for TSO packet
1900 if (!skb_is_gso(skb
) && frag_count
> NETXEN_MAX_FRAGS_PER_TX
) {
1902 for (i
= 0; i
< (frag_count
- NETXEN_MAX_FRAGS_PER_TX
); i
++) {
1903 frag
= &skb_shinfo(skb
)->frags
[i
];
1904 delta
+= frag
->size
;
1907 if (!__pskb_pull_tail(skb
, delta
))
1910 frag_count
= 1 + skb_shinfo(skb
)->nr_frags
;
1912 /* 4 fragments per cmd des */
1913 no_of_desc
= (frag_count
+ 3) >> 2;
1915 if (unlikely(netxen_tx_avail(tx_ring
) <= TX_STOP_THRESH
)) {
1916 netif_stop_queue(netdev
);
1918 if (netxen_tx_avail(tx_ring
) > TX_STOP_THRESH
)
1919 netif_start_queue(netdev
);
1921 return NETDEV_TX_BUSY
;
1924 producer
= tx_ring
->producer
;
1925 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
1927 pdev
= adapter
->pdev
;
1929 if (netxen_map_tx_skb(pdev
, skb
, pbuf
))
1933 pbuf
->frag_count
= frag_count
;
1935 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
1936 netxen_clear_cmddesc((u64
*)hwdesc
);
1938 netxen_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
1939 netxen_set_tx_port(first_desc
, adapter
->portnum
);
1941 for (i
= 0; i
< frag_count
; i
++) {
1945 if ((k
== 0) && (i
> 0)) {
1946 /* move to next desc.*/
1947 producer
= get_next_index(producer
, num_txd
);
1948 hwdesc
= &tx_ring
->desc_head
[producer
];
1949 netxen_clear_cmddesc((u64
*)hwdesc
);
1950 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1953 buffrag
= &pbuf
->frag_array
[i
];
1955 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
1958 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
1961 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
1964 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
1967 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
1972 tx_ring
->producer
= get_next_index(producer
, num_txd
);
1974 netxen_tso_check(netdev
, tx_ring
, first_desc
, skb
);
1976 adapter
->stats
.txbytes
+= skb
->len
;
1977 adapter
->stats
.xmitcalled
++;
1979 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
1981 return NETDEV_TX_OK
;
1984 adapter
->stats
.txdropped
++;
1985 dev_kfree_skb_any(skb
);
1986 return NETDEV_TX_OK
;
1989 static int netxen_nic_check_temp(struct netxen_adapter
*adapter
)
1991 struct net_device
*netdev
= adapter
->netdev
;
1992 uint32_t temp
, temp_state
, temp_val
;
1995 temp
= NXRD32(adapter
, CRB_TEMP_STATE
);
1997 temp_state
= nx_get_temp_state(temp
);
1998 temp_val
= nx_get_temp_val(temp
);
2000 if (temp_state
== NX_TEMP_PANIC
) {
2002 "%s: Device temperature %d degrees C exceeds"
2003 " maximum allowed. Hardware has been shut down.\n",
2004 netdev
->name
, temp_val
);
2006 } else if (temp_state
== NX_TEMP_WARN
) {
2007 if (adapter
->temp
== NX_TEMP_NORMAL
) {
2009 "%s: Device temperature %d degrees C "
2010 "exceeds operating range."
2011 " Immediate action needed.\n",
2012 netdev
->name
, temp_val
);
2015 if (adapter
->temp
== NX_TEMP_WARN
) {
2017 "%s: Device temperature is now %d degrees C"
2018 " in normal range.\n", netdev
->name
,
2022 adapter
->temp
= temp_state
;
2026 void netxen_advert_link_change(struct netxen_adapter
*adapter
, int linkup
)
2028 struct net_device
*netdev
= adapter
->netdev
;
2030 if (adapter
->ahw
.linkup
&& !linkup
) {
2031 printk(KERN_INFO
"%s: %s NIC Link is down\n",
2032 netxen_nic_driver_name
, netdev
->name
);
2033 adapter
->ahw
.linkup
= 0;
2034 if (netif_running(netdev
)) {
2035 netif_carrier_off(netdev
);
2036 netif_stop_queue(netdev
);
2038 adapter
->link_changed
= !adapter
->has_link_events
;
2039 } else if (!adapter
->ahw
.linkup
&& linkup
) {
2040 printk(KERN_INFO
"%s: %s NIC Link is up\n",
2041 netxen_nic_driver_name
, netdev
->name
);
2042 adapter
->ahw
.linkup
= 1;
2043 if (netif_running(netdev
)) {
2044 netif_carrier_on(netdev
);
2045 netif_wake_queue(netdev
);
2047 adapter
->link_changed
= !adapter
->has_link_events
;
2051 static void netxen_nic_handle_phy_intr(struct netxen_adapter
*adapter
)
2053 u32 val
, port
, linkup
;
2055 port
= adapter
->physical_port
;
2057 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
2058 val
= NXRD32(adapter
, CRB_XG_STATE_P3
);
2059 val
= XG_LINK_STATE_P3(adapter
->ahw
.pci_func
, val
);
2060 linkup
= (val
== XG_LINK_UP_P3
);
2062 val
= NXRD32(adapter
, CRB_XG_STATE
);
2063 val
= (val
>> port
*8) & 0xff;
2064 linkup
= (val
== XG_LINK_UP
);
2067 netxen_advert_link_change(adapter
, linkup
);
2070 static void netxen_tx_timeout(struct net_device
*netdev
)
2072 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2074 if (test_bit(__NX_RESETTING
, &adapter
->state
))
2077 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
2078 schedule_work(&adapter
->tx_timeout_task
);
2081 static void netxen_tx_timeout_task(struct work_struct
*work
)
2083 struct netxen_adapter
*adapter
=
2084 container_of(work
, struct netxen_adapter
, tx_timeout_task
);
2086 if (!netif_running(adapter
->netdev
))
2089 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2092 if (++adapter
->tx_timeo_cnt
>= NX_MAX_TX_TIMEOUTS
)
2096 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
2097 /* try to scrub interrupt */
2098 netxen_napi_disable(adapter
);
2100 netxen_napi_enable(adapter
);
2102 netif_wake_queue(adapter
->netdev
);
2104 clear_bit(__NX_RESETTING
, &adapter
->state
);
2106 clear_bit(__NX_RESETTING
, &adapter
->state
);
2107 if (netxen_nic_reset_context(adapter
)) {
2112 adapter
->netdev
->trans_start
= jiffies
;
2117 adapter
->need_fw_reset
= 1;
2118 clear_bit(__NX_RESETTING
, &adapter
->state
);
2121 static struct rtnl_link_stats64
*netxen_nic_get_stats(struct net_device
*netdev
,
2122 struct rtnl_link_stats64
*stats
)
2124 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2126 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
2127 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
2128 stats
->rx_bytes
= adapter
->stats
.rxbytes
;
2129 stats
->tx_bytes
= adapter
->stats
.txbytes
;
2130 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
2131 stats
->tx_dropped
= adapter
->stats
.txdropped
;
2136 static irqreturn_t
netxen_intr(int irq
, void *data
)
2138 struct nx_host_sds_ring
*sds_ring
= data
;
2139 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2142 status
= readl(adapter
->isr_int_vec
);
2144 if (!(status
& adapter
->int_vec_bit
))
2147 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
2148 /* check interrupt state machine, to be sure */
2149 status
= readl(adapter
->crb_int_state_reg
);
2150 if (!ISR_LEGACY_INT_TRIGGERED(status
))
2154 unsigned long our_int
= 0;
2156 our_int
= readl(adapter
->crb_int_state_reg
);
2158 /* not our interrupt */
2159 if (!test_and_clear_bit((7 + adapter
->portnum
), &our_int
))
2162 /* claim interrupt */
2163 writel((our_int
& 0xffffffff), adapter
->crb_int_state_reg
);
2165 /* clear interrupt */
2166 netxen_nic_disable_int(sds_ring
);
2169 writel(0xffffffff, adapter
->tgt_status_reg
);
2170 /* read twice to ensure write is flushed */
2171 readl(adapter
->isr_int_vec
);
2172 readl(adapter
->isr_int_vec
);
2174 napi_schedule(&sds_ring
->napi
);
2179 static irqreturn_t
netxen_msi_intr(int irq
, void *data
)
2181 struct nx_host_sds_ring
*sds_ring
= data
;
2182 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2184 /* clear interrupt */
2185 writel(0xffffffff, adapter
->tgt_status_reg
);
2187 napi_schedule(&sds_ring
->napi
);
2191 static irqreturn_t
netxen_msix_intr(int irq
, void *data
)
2193 struct nx_host_sds_ring
*sds_ring
= data
;
2195 napi_schedule(&sds_ring
->napi
);
2199 static int netxen_nic_poll(struct napi_struct
*napi
, int budget
)
2201 struct nx_host_sds_ring
*sds_ring
=
2202 container_of(napi
, struct nx_host_sds_ring
, napi
);
2204 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2209 tx_complete
= netxen_process_cmd_ring(adapter
);
2211 work_done
= netxen_process_rcv_ring(sds_ring
, budget
);
2213 if ((work_done
< budget
) && tx_complete
) {
2214 napi_complete(&sds_ring
->napi
);
2215 if (test_bit(__NX_DEV_UP
, &adapter
->state
))
2216 netxen_nic_enable_int(sds_ring
);
2222 #ifdef CONFIG_NET_POLL_CONTROLLER
2223 static void netxen_nic_poll_controller(struct net_device
*netdev
)
2226 struct nx_host_sds_ring
*sds_ring
;
2227 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2228 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
2230 disable_irq(adapter
->irq
);
2231 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
2232 sds_ring
= &recv_ctx
->sds_rings
[ring
];
2233 netxen_intr(adapter
->irq
, sds_ring
);
2235 enable_irq(adapter
->irq
);
2240 nx_incr_dev_ref_cnt(struct netxen_adapter
*adapter
)
2243 if (netxen_api_lock(adapter
))
2246 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2248 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, ++count
);
2250 netxen_api_unlock(adapter
);
2255 nx_decr_dev_ref_cnt(struct netxen_adapter
*adapter
)
2258 if (netxen_api_lock(adapter
))
2261 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2262 WARN_ON(count
== 0);
2264 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, --count
);
2267 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_COLD
);
2269 netxen_api_unlock(adapter
);
2274 nx_dev_request_aer(struct netxen_adapter
*adapter
)
2279 if (netxen_api_lock(adapter
))
2282 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2284 if (state
== NX_DEV_NEED_AER
)
2286 else if (state
== NX_DEV_READY
) {
2287 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_NEED_AER
);
2291 netxen_api_unlock(adapter
);
2296 nx_dev_request_reset(struct netxen_adapter
*adapter
)
2301 if (netxen_api_lock(adapter
))
2304 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2306 if (state
== NX_DEV_NEED_RESET
)
2308 else if (state
!= NX_DEV_INITALIZING
&& state
!= NX_DEV_NEED_AER
) {
2309 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_NEED_RESET
);
2313 netxen_api_unlock(adapter
);
2319 netxen_can_start_firmware(struct netxen_adapter
*adapter
)
2324 if (netxen_api_lock(adapter
))
2327 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2329 if ((count
< 0) || (count
>= NX_MAX_PCI_FUNC
))
2334 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_INITALIZING
);
2337 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, ++count
);
2339 netxen_api_unlock(adapter
);
2345 netxen_schedule_work(struct netxen_adapter
*adapter
,
2346 work_func_t func
, int delay
)
2348 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
2349 schedule_delayed_work(&adapter
->fw_work
, delay
);
2353 netxen_cancel_fw_work(struct netxen_adapter
*adapter
)
2355 while (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2358 cancel_delayed_work_sync(&adapter
->fw_work
);
2362 netxen_attach_work(struct work_struct
*work
)
2364 struct netxen_adapter
*adapter
= container_of(work
,
2365 struct netxen_adapter
, fw_work
.work
);
2366 struct net_device
*netdev
= adapter
->netdev
;
2369 if (netif_running(netdev
)) {
2370 err
= netxen_nic_attach(adapter
);
2374 err
= netxen_nic_up(adapter
, netdev
);
2376 netxen_nic_detach(adapter
);
2380 netxen_restore_indev_addr(netdev
, NETDEV_UP
);
2383 netif_device_attach(netdev
);
2386 adapter
->fw_fail_cnt
= 0;
2387 clear_bit(__NX_RESETTING
, &adapter
->state
);
2388 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
2392 netxen_fwinit_work(struct work_struct
*work
)
2394 struct netxen_adapter
*adapter
= container_of(work
,
2395 struct netxen_adapter
, fw_work
.work
);
2398 dev_state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2400 switch (dev_state
) {
2403 if (!netxen_start_firmware(adapter
)) {
2404 netxen_schedule_work(adapter
, netxen_attach_work
, 0);
2409 case NX_DEV_NEED_RESET
:
2410 case NX_DEV_INITALIZING
:
2411 if (++adapter
->fw_wait_cnt
< FW_POLL_THRESH
) {
2412 netxen_schedule_work(adapter
,
2413 netxen_fwinit_work
, 2 * FW_POLL_DELAY
);
2419 nx_incr_dev_ref_cnt(adapter
);
2423 clear_bit(__NX_RESETTING
, &adapter
->state
);
2427 netxen_detach_work(struct work_struct
*work
)
2429 struct netxen_adapter
*adapter
= container_of(work
,
2430 struct netxen_adapter
, fw_work
.work
);
2431 struct net_device
*netdev
= adapter
->netdev
;
2435 netif_device_detach(netdev
);
2437 netxen_nic_down(adapter
, netdev
);
2440 netxen_nic_detach(adapter
);
2443 status
= NXRD32(adapter
, NETXEN_PEG_HALT_STATUS1
);
2445 if (status
& NX_RCODE_FATAL_ERROR
)
2448 if (adapter
->temp
== NX_TEMP_PANIC
)
2451 ref_cnt
= nx_decr_dev_ref_cnt(adapter
);
2453 if (ref_cnt
== -EIO
)
2456 delay
= (ref_cnt
== 0) ? 0 : (2 * FW_POLL_DELAY
);
2458 adapter
->fw_wait_cnt
= 0;
2459 netxen_schedule_work(adapter
, netxen_fwinit_work
, delay
);
2464 clear_bit(__NX_RESETTING
, &adapter
->state
);
2468 netxen_check_health(struct netxen_adapter
*adapter
)
2470 u32 state
, heartbit
;
2471 struct net_device
*netdev
= adapter
->netdev
;
2473 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2474 if (state
== NX_DEV_NEED_AER
)
2477 if (netxen_nic_check_temp(adapter
))
2480 if (adapter
->need_fw_reset
) {
2481 if (nx_dev_request_reset(adapter
))
2486 /* NX_DEV_NEED_RESET, this state can be marked in two cases
2487 * 1. Tx timeout 2. Fw hang
2488 * Send request to destroy context in case of tx timeout only
2489 * and doesn't required in case of Fw hang
2491 if (state
== NX_DEV_NEED_RESET
) {
2492 adapter
->need_fw_reset
= 1;
2493 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2497 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2500 heartbit
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
2501 if (heartbit
!= adapter
->heartbit
) {
2502 adapter
->heartbit
= heartbit
;
2503 adapter
->fw_fail_cnt
= 0;
2504 if (adapter
->need_fw_reset
)
2509 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
2512 if (nx_dev_request_reset(adapter
))
2515 clear_bit(__NX_FW_ATTACHED
, &adapter
->state
);
2517 dev_info(&netdev
->dev
, "firmware hang detected\n");
2520 if ((auto_fw_reset
== AUTO_FW_RESET_ENABLED
) &&
2521 !test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2522 netxen_schedule_work(adapter
, netxen_detach_work
, 0);
2527 netxen_fw_poll_work(struct work_struct
*work
)
2529 struct netxen_adapter
*adapter
= container_of(work
,
2530 struct netxen_adapter
, fw_work
.work
);
2532 if (test_bit(__NX_RESETTING
, &adapter
->state
))
2535 if (test_bit(__NX_DEV_UP
, &adapter
->state
)) {
2536 if (!adapter
->has_link_events
) {
2538 netxen_nic_handle_phy_intr(adapter
);
2540 if (adapter
->link_changed
)
2541 netxen_nic_set_link_parameters(adapter
);
2545 if (netxen_check_health(adapter
))
2549 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
2553 netxen_store_bridged_mode(struct device
*dev
,
2554 struct device_attribute
*attr
, const char *buf
, size_t len
)
2556 struct net_device
*net
= to_net_dev(dev
);
2557 struct netxen_adapter
*adapter
= netdev_priv(net
);
2561 if (!(adapter
->capabilities
& NX_FW_CAPABILITY_BDG
))
2564 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
2567 if (strict_strtoul(buf
, 2, &new))
2570 if (!netxen_config_bridged_mode(adapter
, !!new))
2578 netxen_show_bridged_mode(struct device
*dev
,
2579 struct device_attribute
*attr
, char *buf
)
2581 struct net_device
*net
= to_net_dev(dev
);
2582 struct netxen_adapter
*adapter
;
2583 int bridged_mode
= 0;
2585 adapter
= netdev_priv(net
);
2587 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
2588 bridged_mode
= !!(adapter
->flags
& NETXEN_NIC_BRIDGE_ENABLED
);
2590 return sprintf(buf
, "%d\n", bridged_mode
);
2593 static struct device_attribute dev_attr_bridged_mode
= {
2594 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2595 .show
= netxen_show_bridged_mode
,
2596 .store
= netxen_store_bridged_mode
,
2600 netxen_store_diag_mode(struct device
*dev
,
2601 struct device_attribute
*attr
, const char *buf
, size_t len
)
2603 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2606 if (strict_strtoul(buf
, 2, &new))
2609 if (!!new != !!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2610 adapter
->flags
^= NETXEN_NIC_DIAG_ENABLED
;
2616 netxen_show_diag_mode(struct device
*dev
,
2617 struct device_attribute
*attr
, char *buf
)
2619 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2621 return sprintf(buf
, "%d\n",
2622 !!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
));
2625 static struct device_attribute dev_attr_diag_mode
= {
2626 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2627 .show
= netxen_show_diag_mode
,
2628 .store
= netxen_store_diag_mode
,
2632 netxen_sysfs_validate_crb(struct netxen_adapter
*adapter
,
2633 loff_t offset
, size_t size
)
2635 size_t crb_size
= 4;
2637 if (!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2640 if (offset
< NETXEN_PCI_CRBSPACE
) {
2641 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2644 if (ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2645 NETXEN_PCI_CAMQM_2M_END
))
2651 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
2658 netxen_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
2659 struct bin_attribute
*attr
,
2660 char *buf
, loff_t offset
, size_t size
)
2662 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2663 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2668 ret
= netxen_sysfs_validate_crb(adapter
, offset
, size
);
2672 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) &&
2673 ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2674 NETXEN_PCI_CAMQM_2M_END
)) {
2675 netxen_pci_camqm_read_2M(adapter
, offset
, &qmdata
);
2676 memcpy(buf
, &qmdata
, size
);
2678 data
= NXRD32(adapter
, offset
);
2679 memcpy(buf
, &data
, size
);
2686 netxen_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
2687 struct bin_attribute
*attr
,
2688 char *buf
, loff_t offset
, size_t size
)
2690 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2691 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2696 ret
= netxen_sysfs_validate_crb(adapter
, offset
, size
);
2700 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) &&
2701 ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2702 NETXEN_PCI_CAMQM_2M_END
)) {
2703 memcpy(&qmdata
, buf
, size
);
2704 netxen_pci_camqm_write_2M(adapter
, offset
, qmdata
);
2706 memcpy(&data
, buf
, size
);
2707 NXWR32(adapter
, offset
, data
);
2714 netxen_sysfs_validate_mem(struct netxen_adapter
*adapter
,
2715 loff_t offset
, size_t size
)
2717 if (!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2720 if ((size
!= 8) || (offset
& 0x7))
2727 netxen_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
2728 struct bin_attribute
*attr
,
2729 char *buf
, loff_t offset
, size_t size
)
2731 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2732 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2736 ret
= netxen_sysfs_validate_mem(adapter
, offset
, size
);
2740 if (adapter
->pci_mem_read(adapter
, offset
, &data
))
2743 memcpy(buf
, &data
, size
);
2748 static ssize_t
netxen_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
2749 struct bin_attribute
*attr
, char *buf
,
2750 loff_t offset
, size_t size
)
2752 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2753 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2757 ret
= netxen_sysfs_validate_mem(adapter
, offset
, size
);
2761 memcpy(&data
, buf
, size
);
2763 if (adapter
->pci_mem_write(adapter
, offset
, data
))
2770 static struct bin_attribute bin_attr_crb
= {
2771 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
2773 .read
= netxen_sysfs_read_crb
,
2774 .write
= netxen_sysfs_write_crb
,
2777 static struct bin_attribute bin_attr_mem
= {
2778 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
2780 .read
= netxen_sysfs_read_mem
,
2781 .write
= netxen_sysfs_write_mem
,
2786 netxen_create_sysfs_entries(struct netxen_adapter
*adapter
)
2788 struct net_device
*netdev
= adapter
->netdev
;
2789 struct device
*dev
= &netdev
->dev
;
2791 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
) {
2792 /* bridged_mode control */
2793 if (device_create_file(dev
, &dev_attr_bridged_mode
)) {
2794 dev_warn(&netdev
->dev
,
2795 "failed to create bridged_mode sysfs entry\n");
2801 netxen_remove_sysfs_entries(struct netxen_adapter
*adapter
)
2803 struct net_device
*netdev
= adapter
->netdev
;
2804 struct device
*dev
= &netdev
->dev
;
2806 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
2807 device_remove_file(dev
, &dev_attr_bridged_mode
);
2811 netxen_create_diag_entries(struct netxen_adapter
*adapter
)
2813 struct pci_dev
*pdev
= adapter
->pdev
;
2817 if (device_create_file(dev
, &dev_attr_diag_mode
))
2818 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
2819 if (device_create_bin_file(dev
, &bin_attr_crb
))
2820 dev_info(dev
, "failed to create crb sysfs entry\n");
2821 if (device_create_bin_file(dev
, &bin_attr_mem
))
2822 dev_info(dev
, "failed to create mem sysfs entry\n");
2827 netxen_remove_diag_entries(struct netxen_adapter
*adapter
)
2829 struct pci_dev
*pdev
= adapter
->pdev
;
2830 struct device
*dev
= &pdev
->dev
;
2832 device_remove_file(dev
, &dev_attr_diag_mode
);
2833 device_remove_bin_file(dev
, &bin_attr_crb
);
2834 device_remove_bin_file(dev
, &bin_attr_mem
);
2839 #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2842 netxen_destip_supported(struct netxen_adapter
*adapter
)
2844 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2847 if (adapter
->ahw
.cut_through
)
2854 netxen_free_vlan_ip_list(struct netxen_adapter
*adapter
)
2856 struct nx_vlan_ip_list
*cur
;
2857 struct list_head
*head
= &adapter
->vlan_ip_list
;
2859 while (!list_empty(head
)) {
2860 cur
= list_entry(head
->next
, struct nx_vlan_ip_list
, list
);
2861 netxen_config_ipaddr(adapter
, cur
->ip_addr
, NX_IP_DOWN
);
2862 list_del(&cur
->list
);
2868 netxen_list_config_vlan_ip(struct netxen_adapter
*adapter
,
2869 struct in_ifaddr
*ifa
, unsigned long event
)
2871 struct net_device
*dev
;
2872 struct nx_vlan_ip_list
*cur
, *tmp_cur
;
2873 struct list_head
*head
;
2875 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
2880 if (!is_vlan_dev(dev
))
2885 list_for_each(head
, &adapter
->vlan_ip_list
) {
2886 cur
= list_entry(head
, struct nx_vlan_ip_list
, list
);
2888 if (cur
->ip_addr
== ifa
->ifa_address
)
2892 cur
= kzalloc(sizeof(struct nx_vlan_ip_list
), GFP_ATOMIC
);
2894 printk(KERN_ERR
"%s: failed to add vlan ip to list\n",
2895 adapter
->netdev
->name
);
2899 cur
->ip_addr
= ifa
->ifa_address
;
2900 list_add_tail(&cur
->list
, &adapter
->vlan_ip_list
);
2903 list_for_each_entry_safe(cur
, tmp_cur
,
2904 &adapter
->vlan_ip_list
, list
) {
2905 if (cur
->ip_addr
== ifa
->ifa_address
) {
2906 list_del(&cur
->list
);
2914 netxen_config_indev_addr(struct netxen_adapter
*adapter
,
2915 struct net_device
*dev
, unsigned long event
)
2917 struct in_device
*indev
;
2919 if (!netxen_destip_supported(adapter
))
2922 indev
= in_dev_get(dev
);
2929 netxen_config_ipaddr(adapter
,
2930 ifa
->ifa_address
, NX_IP_UP
);
2931 netxen_list_config_vlan_ip(adapter
, ifa
, NX_IP_UP
);
2934 netxen_config_ipaddr(adapter
,
2935 ifa
->ifa_address
, NX_IP_DOWN
);
2936 netxen_list_config_vlan_ip(adapter
, ifa
, NX_IP_DOWN
);
2941 } endfor_ifa(indev
);
2947 netxen_restore_indev_addr(struct net_device
*netdev
, unsigned long event
)
2950 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2951 struct nx_vlan_ip_list
*pos
, *tmp_pos
;
2952 unsigned long ip_event
;
2954 ip_event
= (event
== NETDEV_UP
) ? NX_IP_UP
: NX_IP_DOWN
;
2955 netxen_config_indev_addr(adapter
, netdev
, event
);
2957 list_for_each_entry_safe(pos
, tmp_pos
, &adapter
->vlan_ip_list
, list
) {
2958 netxen_config_ipaddr(adapter
, pos
->ip_addr
, ip_event
);
2962 static int netxen_netdev_event(struct notifier_block
*this,
2963 unsigned long event
, void *ptr
)
2965 struct netxen_adapter
*adapter
;
2966 struct net_device
*dev
= (struct net_device
*)ptr
;
2967 struct net_device
*orig_dev
= dev
;
2973 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
2974 dev
= vlan_dev_real_dev(dev
);
2978 if (!is_netxen_netdev(dev
))
2981 adapter
= netdev_priv(dev
);
2986 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
2989 netxen_config_indev_addr(adapter
, orig_dev
, event
);
2995 netxen_inetaddr_event(struct notifier_block
*this,
2996 unsigned long event
, void *ptr
)
2998 struct netxen_adapter
*adapter
;
2999 struct net_device
*dev
;
3001 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
3003 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
3009 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3010 dev
= vlan_dev_real_dev(dev
);
3014 if (!is_netxen_netdev(dev
))
3017 adapter
= netdev_priv(dev
);
3019 if (!adapter
|| !netxen_destip_supported(adapter
))
3022 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
3027 netxen_config_ipaddr(adapter
, ifa
->ifa_address
, NX_IP_UP
);
3028 netxen_list_config_vlan_ip(adapter
, ifa
, NX_IP_UP
);
3031 netxen_config_ipaddr(adapter
, ifa
->ifa_address
, NX_IP_DOWN
);
3032 netxen_list_config_vlan_ip(adapter
, ifa
, NX_IP_DOWN
);
3042 static struct notifier_block netxen_netdev_cb
= {
3043 .notifier_call
= netxen_netdev_event
,
3046 static struct notifier_block netxen_inetaddr_cb
= {
3047 .notifier_call
= netxen_inetaddr_event
,
3051 netxen_restore_indev_addr(struct net_device
*dev
, unsigned long event
)
3054 netxen_free_vlan_ip_list(struct netxen_adapter
*adapter
)
3058 static struct pci_error_handlers netxen_err_handler
= {
3059 .error_detected
= netxen_io_error_detected
,
3060 .slot_reset
= netxen_io_slot_reset
,
3061 .resume
= netxen_io_resume
,
3064 static struct pci_driver netxen_driver
= {
3065 .name
= netxen_nic_driver_name
,
3066 .id_table
= netxen_pci_tbl
,
3067 .probe
= netxen_nic_probe
,
3068 .remove
= __devexit_p(netxen_nic_remove
),
3070 .suspend
= netxen_nic_suspend
,
3071 .resume
= netxen_nic_resume
,
3073 .shutdown
= netxen_nic_shutdown
,
3074 .err_handler
= &netxen_err_handler
3077 static int __init
netxen_init_module(void)
3079 printk(KERN_INFO
"%s\n", netxen_nic_driver_string
);
3082 register_netdevice_notifier(&netxen_netdev_cb
);
3083 register_inetaddr_notifier(&netxen_inetaddr_cb
);
3085 return pci_register_driver(&netxen_driver
);
3088 module_init(netxen_init_module
);
3090 static void __exit
netxen_exit_module(void)
3092 pci_unregister_driver(&netxen_driver
);
3095 unregister_inetaddr_notifier(&netxen_inetaddr_cb
);
3096 unregister_netdevice_notifier(&netxen_netdev_cb
);
3100 module_exit(netxen_exit_module
);