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 #define PCI_CAP_ID_GEN 0x10
405 static void netxen_pcie_strap_init(struct netxen_adapter
*adapter
)
412 struct pci_dev
*pdev
;
414 pdev
= adapter
->pdev
;
416 chicken
= NXRD32(adapter
, NETXEN_PCIE_REG(PCIE_CHICKEN3
));
417 /* clear chicken3.25:24 */
418 chicken
&= 0xFCFFFFFF;
420 * if gen1 and B0, set F1020 - if gen 2, do nothing
421 * if gen2 set to F1000
423 pos
= pci_find_capability(pdev
, PCI_CAP_ID_GEN
);
425 pci_read_config_dword(pdev
, pos
+ 0x10, &control
);
426 if ((control
& 0x000F0000) != 0x00020000) {
427 /* set chicken3.24 if gen1 */
428 chicken
|= 0x01000000;
430 dev_info(&adapter
->pdev
->dev
, "Gen2 strapping detected\n");
433 /* set chicken3.24 if gen1 */
434 chicken
|= 0x01000000;
435 dev_info(&adapter
->pdev
->dev
, "Gen1 strapping detected\n");
436 if (adapter
->ahw
.revision_id
== NX_P3_B0
)
442 NXWR32(adapter
, NETXEN_PCIE_REG(PCIE_CHICKEN3
), chicken
);
447 pdevfuncsave
= pdev
->devfn
;
448 if (pdevfuncsave
& 0x07)
451 for (i
= 0; i
< 8; i
++) {
452 pci_read_config_dword(pdev
, pos
+ 8, &control
);
453 pci_read_config_dword(pdev
, pos
+ 8, &control
);
454 pci_write_config_dword(pdev
, pos
+ 8, c8c9value
);
457 pdev
->devfn
= pdevfuncsave
;
460 static void netxen_set_msix_bit(struct pci_dev
*pdev
, int enable
)
465 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
467 pci_read_config_dword(pdev
, pos
, &control
);
469 control
|= PCI_MSIX_FLAGS_ENABLE
;
472 pci_write_config_dword(pdev
, pos
, control
);
476 static void netxen_init_msix_entries(struct netxen_adapter
*adapter
, int count
)
480 for (i
= 0; i
< count
; i
++)
481 adapter
->msix_entries
[i
].entry
= i
;
485 netxen_read_mac_addr(struct netxen_adapter
*adapter
)
490 struct net_device
*netdev
= adapter
->netdev
;
491 struct pci_dev
*pdev
= adapter
->pdev
;
493 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
494 if (netxen_p3_get_mac_addr(adapter
, &mac_addr
) != 0)
497 if (netxen_get_flash_mac_addr(adapter
, &mac_addr
) != 0)
501 p
= (unsigned char *)&mac_addr
;
502 for (i
= 0; i
< 6; i
++)
503 netdev
->dev_addr
[i
] = *(p
+ 5 - i
);
505 memcpy(netdev
->perm_addr
, netdev
->dev_addr
, netdev
->addr_len
);
506 memcpy(adapter
->mac_addr
, netdev
->dev_addr
, netdev
->addr_len
);
508 /* set station address */
510 if (!is_valid_ether_addr(netdev
->perm_addr
))
511 dev_warn(&pdev
->dev
, "Bad MAC address %pM.\n", netdev
->dev_addr
);
516 static int netxen_nic_set_mac(struct net_device
*netdev
, void *p
)
518 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
519 struct sockaddr
*addr
= p
;
521 if (!is_valid_ether_addr(addr
->sa_data
))
524 if (netif_running(netdev
)) {
525 netif_device_detach(netdev
);
526 netxen_napi_disable(adapter
);
529 memcpy(adapter
->mac_addr
, addr
->sa_data
, netdev
->addr_len
);
530 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
531 adapter
->macaddr_set(adapter
, addr
->sa_data
);
533 if (netif_running(netdev
)) {
534 netif_device_attach(netdev
);
535 netxen_napi_enable(adapter
);
540 static void netxen_set_multicast_list(struct net_device
*dev
)
542 struct netxen_adapter
*adapter
= netdev_priv(dev
);
544 adapter
->set_multi(dev
);
547 static u32
netxen_fix_features(struct net_device
*dev
, u32 features
)
549 if (!(features
& NETIF_F_RXCSUM
)) {
550 netdev_info(dev
, "disabling LRO as RXCSUM is off\n");
552 features
&= ~NETIF_F_LRO
;
558 static int netxen_set_features(struct net_device
*dev
, u32 features
)
560 struct netxen_adapter
*adapter
= netdev_priv(dev
);
563 if (!((dev
->features
^ features
) & NETIF_F_LRO
))
566 hw_lro
= (features
& NETIF_F_LRO
) ? NETXEN_NIC_LRO_ENABLED
567 : NETXEN_NIC_LRO_DISABLED
;
569 if (netxen_config_hw_lro(adapter
, hw_lro
))
572 if (!(features
& NETIF_F_LRO
) && netxen_send_lro_cleanup(adapter
))
578 static const struct net_device_ops netxen_netdev_ops
= {
579 .ndo_open
= netxen_nic_open
,
580 .ndo_stop
= netxen_nic_close
,
581 .ndo_start_xmit
= netxen_nic_xmit_frame
,
582 .ndo_get_stats64
= netxen_nic_get_stats
,
583 .ndo_validate_addr
= eth_validate_addr
,
584 .ndo_set_rx_mode
= netxen_set_multicast_list
,
585 .ndo_set_mac_address
= netxen_nic_set_mac
,
586 .ndo_change_mtu
= netxen_nic_change_mtu
,
587 .ndo_tx_timeout
= netxen_tx_timeout
,
588 .ndo_fix_features
= netxen_fix_features
,
589 .ndo_set_features
= netxen_set_features
,
590 #ifdef CONFIG_NET_POLL_CONTROLLER
591 .ndo_poll_controller
= netxen_nic_poll_controller
,
596 netxen_setup_intr(struct netxen_adapter
*adapter
)
598 struct netxen_legacy_intr_set
*legacy_intrp
;
599 struct pci_dev
*pdev
= adapter
->pdev
;
602 if (adapter
->rss_supported
) {
603 num_msix
= (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER
) ?
604 MSIX_ENTRIES_PER_ADAPTER
: 2;
608 adapter
->max_sds_rings
= 1;
610 adapter
->flags
&= ~(NETXEN_NIC_MSI_ENABLED
| NETXEN_NIC_MSIX_ENABLED
);
612 if (adapter
->ahw
.revision_id
>= NX_P3_B0
)
613 legacy_intrp
= &legacy_intr
[adapter
->ahw
.pci_func
];
615 legacy_intrp
= &legacy_intr
[0];
617 adapter
->int_vec_bit
= legacy_intrp
->int_vec_bit
;
618 adapter
->tgt_status_reg
= netxen_get_ioaddr(adapter
,
619 legacy_intrp
->tgt_status_reg
);
620 adapter
->tgt_mask_reg
= netxen_get_ioaddr(adapter
,
621 legacy_intrp
->tgt_mask_reg
);
622 adapter
->pci_int_reg
= netxen_get_ioaddr(adapter
,
623 legacy_intrp
->pci_int_reg
);
624 adapter
->isr_int_vec
= netxen_get_ioaddr(adapter
, ISR_INT_VECTOR
);
626 if (adapter
->ahw
.revision_id
>= NX_P3_B1
)
627 adapter
->crb_int_state_reg
= netxen_get_ioaddr(adapter
,
630 adapter
->crb_int_state_reg
= netxen_get_ioaddr(adapter
,
633 netxen_set_msix_bit(pdev
, 0);
635 if (adapter
->msix_supported
) {
637 netxen_init_msix_entries(adapter
, num_msix
);
638 err
= pci_enable_msix(pdev
, adapter
->msix_entries
, num_msix
);
640 adapter
->flags
|= NETXEN_NIC_MSIX_ENABLED
;
641 netxen_set_msix_bit(pdev
, 1);
643 if (adapter
->rss_supported
)
644 adapter
->max_sds_rings
= num_msix
;
646 dev_info(&pdev
->dev
, "using msi-x interrupts\n");
651 pci_disable_msix(pdev
);
653 /* fall through for msi */
656 if (use_msi
&& !pci_enable_msi(pdev
)) {
657 adapter
->flags
|= NETXEN_NIC_MSI_ENABLED
;
658 adapter
->tgt_status_reg
= netxen_get_ioaddr(adapter
,
659 msi_tgt_status
[adapter
->ahw
.pci_func
]);
660 dev_info(&pdev
->dev
, "using msi interrupts\n");
661 adapter
->msix_entries
[0].vector
= pdev
->irq
;
665 dev_info(&pdev
->dev
, "using legacy interrupts\n");
666 adapter
->msix_entries
[0].vector
= pdev
->irq
;
670 netxen_teardown_intr(struct netxen_adapter
*adapter
)
672 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
673 pci_disable_msix(adapter
->pdev
);
674 if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
675 pci_disable_msi(adapter
->pdev
);
679 netxen_cleanup_pci_map(struct netxen_adapter
*adapter
)
681 if (adapter
->ahw
.db_base
!= NULL
)
682 iounmap(adapter
->ahw
.db_base
);
683 if (adapter
->ahw
.pci_base0
!= NULL
)
684 iounmap(adapter
->ahw
.pci_base0
);
685 if (adapter
->ahw
.pci_base1
!= NULL
)
686 iounmap(adapter
->ahw
.pci_base1
);
687 if (adapter
->ahw
.pci_base2
!= NULL
)
688 iounmap(adapter
->ahw
.pci_base2
);
692 netxen_setup_pci_map(struct netxen_adapter
*adapter
)
694 void __iomem
*db_ptr
= NULL
;
696 resource_size_t mem_base
, db_base
;
697 unsigned long mem_len
, db_len
= 0;
699 struct pci_dev
*pdev
= adapter
->pdev
;
700 int pci_func
= adapter
->ahw
.pci_func
;
701 struct netxen_hardware_context
*ahw
= &adapter
->ahw
;
706 * Set the CRB window to invalid. If any register in window 0 is
707 * accessed it should set the window to 0 and then reset it to 1.
709 adapter
->ahw
.crb_win
= -1;
710 adapter
->ahw
.ocm_win
= -1;
712 /* remap phys address */
713 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
714 mem_len
= pci_resource_len(pdev
, 0);
716 /* 128 Meg of memory */
717 if (mem_len
== NETXEN_PCI_128MB_SIZE
) {
719 ahw
->pci_base0
= ioremap(mem_base
, FIRST_PAGE_GROUP_SIZE
);
720 ahw
->pci_base1
= ioremap(mem_base
+ SECOND_PAGE_GROUP_START
,
721 SECOND_PAGE_GROUP_SIZE
);
722 ahw
->pci_base2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
,
723 THIRD_PAGE_GROUP_SIZE
);
724 if (ahw
->pci_base0
== NULL
|| ahw
->pci_base1
== NULL
||
725 ahw
->pci_base2
== NULL
) {
726 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
731 ahw
->pci_len0
= FIRST_PAGE_GROUP_SIZE
;
733 } else if (mem_len
== NETXEN_PCI_32MB_SIZE
) {
735 ahw
->pci_base1
= ioremap(mem_base
, SECOND_PAGE_GROUP_SIZE
);
736 ahw
->pci_base2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
-
737 SECOND_PAGE_GROUP_START
, THIRD_PAGE_GROUP_SIZE
);
738 if (ahw
->pci_base1
== NULL
|| ahw
->pci_base2
== NULL
) {
739 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
744 } else if (mem_len
== NETXEN_PCI_2MB_SIZE
) {
746 ahw
->pci_base0
= pci_ioremap_bar(pdev
, 0);
747 if (ahw
->pci_base0
== NULL
) {
748 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
751 ahw
->pci_len0
= mem_len
;
756 netxen_setup_hwops(adapter
);
758 dev_info(&pdev
->dev
, "%dMB memory map\n", (int)(mem_len
>>20));
760 if (NX_IS_REVISION_P3P(adapter
->ahw
.revision_id
)) {
761 adapter
->ahw
.ocm_win_crb
= netxen_get_ioaddr(adapter
,
762 NETXEN_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(pci_func
)));
764 } else if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
765 adapter
->ahw
.ocm_win_crb
= netxen_get_ioaddr(adapter
,
766 NETXEN_PCIX_PS_REG(PCIE_MN_WINDOW_REG(pci_func
)));
769 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
772 db_base
= pci_resource_start(pdev
, 4); /* doorbell is on bar 4 */
773 db_len
= pci_resource_len(pdev
, 4);
776 printk(KERN_ERR
"%s: doorbell is disabled\n",
777 netxen_nic_driver_name
);
782 db_ptr
= ioremap(db_base
, NETXEN_DB_MAPSIZE_BYTES
);
784 printk(KERN_ERR
"%s: Failed to allocate doorbell map.",
785 netxen_nic_driver_name
);
791 adapter
->ahw
.db_base
= db_ptr
;
792 adapter
->ahw
.db_len
= db_len
;
796 netxen_cleanup_pci_map(adapter
);
801 netxen_check_options(struct netxen_adapter
*adapter
)
803 u32 fw_major
, fw_minor
, fw_build
;
804 char brd_name
[NETXEN_MAX_SHORT_NAME
];
808 struct pci_dev
*pdev
= adapter
->pdev
;
810 adapter
->driver_mismatch
= 0;
812 ptr32
= (int *)&serial_num
;
813 offset
= NX_FW_SERIAL_NUM_OFFSET
;
814 for (i
= 0; i
< 8; i
++) {
815 if (netxen_rom_fast_read(adapter
, offset
, &val
) == -1) {
816 dev_err(&pdev
->dev
, "error reading board info\n");
817 adapter
->driver_mismatch
= 1;
820 ptr32
[i
] = cpu_to_le32(val
);
821 offset
+= sizeof(u32
);
824 fw_major
= NXRD32(adapter
, NETXEN_FW_VERSION_MAJOR
);
825 fw_minor
= NXRD32(adapter
, NETXEN_FW_VERSION_MINOR
);
826 fw_build
= NXRD32(adapter
, NETXEN_FW_VERSION_SUB
);
828 adapter
->fw_version
= NETXEN_VERSION_CODE(fw_major
, fw_minor
, fw_build
);
830 if (adapter
->portnum
== 0) {
831 get_brd_name_by_type(adapter
->ahw
.board_type
, brd_name
);
833 pr_info("%s: %s Board S/N %s Chip rev 0x%x\n",
834 module_name(THIS_MODULE
),
835 brd_name
, serial_num
, adapter
->ahw
.revision_id
);
838 if (adapter
->fw_version
< NETXEN_VERSION_CODE(3, 4, 216)) {
839 adapter
->driver_mismatch
= 1;
840 dev_warn(&pdev
->dev
, "firmware version %d.%d.%d unsupported\n",
841 fw_major
, fw_minor
, fw_build
);
845 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
846 i
= NXRD32(adapter
, NETXEN_SRE_MISC
);
847 adapter
->ahw
.cut_through
= (i
& 0x8000) ? 1 : 0;
850 dev_info(&pdev
->dev
, "firmware v%d.%d.%d [%s]\n",
851 fw_major
, fw_minor
, fw_build
,
852 adapter
->ahw
.cut_through
? "cut-through" : "legacy");
854 if (adapter
->fw_version
>= NETXEN_VERSION_CODE(4, 0, 222))
855 adapter
->capabilities
= NXRD32(adapter
, CRB_FW_CAPABILITIES_1
);
857 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
858 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
859 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
860 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
861 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
862 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
865 adapter
->msix_supported
= 0;
866 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
867 adapter
->msix_supported
= !!use_msi_x
;
868 adapter
->rss_supported
= !!use_msi_x
;
871 netxen_rom_fast_read(adapter
,
872 NX_FW_VERSION_OFFSET
, (int *)&flashed_ver
);
873 flashed_ver
= NETXEN_DECODE_VERSION(flashed_ver
);
875 if (flashed_ver
>= NETXEN_VERSION_CODE(3, 4, 336)) {
876 switch (adapter
->ahw
.board_type
) {
877 case NETXEN_BRDTYPE_P2_SB31_10G
:
878 case NETXEN_BRDTYPE_P2_SB31_10G_CX4
:
879 adapter
->msix_supported
= !!use_msi_x
;
880 adapter
->rss_supported
= !!use_msi_x
;
888 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
890 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
891 adapter
->num_lro_rxd
= MAX_LRO_RCV_DESCRIPTORS
;
892 adapter
->max_rds_rings
= 3;
894 adapter
->num_lro_rxd
= 0;
895 adapter
->max_rds_rings
= 2;
900 netxen_start_firmware(struct netxen_adapter
*adapter
)
902 int val
, err
, first_boot
;
903 struct pci_dev
*pdev
= adapter
->pdev
;
905 /* required for NX2031 dummy dma */
906 err
= nx_set_dma_mask(adapter
);
910 if (!netxen_can_start_firmware(adapter
))
913 first_boot
= NXRD32(adapter
, NETXEN_CAM_RAM(0x1fc));
915 err
= netxen_check_hw_init(adapter
, first_boot
);
917 dev_err(&pdev
->dev
, "error in init HW init sequence\n");
921 netxen_request_firmware(adapter
);
923 err
= netxen_need_fw_reset(adapter
);
927 goto pcie_strap_init
;
929 if (first_boot
!= 0x55555555) {
930 NXWR32(adapter
, CRB_CMDPEG_STATE
, 0);
931 netxen_pinit_from_rom(adapter
);
935 NXWR32(adapter
, CRB_DMA_SHIFT
, 0x55555555);
936 NXWR32(adapter
, NETXEN_PEG_HALT_STATUS1
, 0);
937 NXWR32(adapter
, NETXEN_PEG_HALT_STATUS2
, 0);
939 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
940 netxen_set_port_mode(adapter
);
942 err
= netxen_load_firmware(adapter
);
946 netxen_release_firmware(adapter
);
948 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
950 /* Initialize multicast addr pool owners */
952 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
)
954 NXWR32(adapter
, NETXEN_MAC_ADDR_CNTL_REG
, val
);
958 err
= netxen_init_dummy_dma(adapter
);
963 * Tell the hardware our version number.
965 val
= (_NETXEN_NIC_LINUX_MAJOR
<< 16)
966 | ((_NETXEN_NIC_LINUX_MINOR
<< 8))
967 | (_NETXEN_NIC_LINUX_SUBVERSION
);
968 NXWR32(adapter
, CRB_DRIVER_VERSION
, val
);
971 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
972 netxen_pcie_strap_init(adapter
);
975 /* Handshake with the card before we register the devices. */
976 err
= netxen_phantom_init(adapter
, NETXEN_NIC_PEG_TUNE
);
978 netxen_free_dummy_dma(adapter
);
982 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_READY
);
984 nx_update_dma_mask(adapter
);
986 netxen_check_options(adapter
);
988 adapter
->need_fw_reset
= 0;
990 /* fall through and release firmware */
993 netxen_release_firmware(adapter
);
998 netxen_nic_request_irq(struct netxen_adapter
*adapter
)
1000 irq_handler_t handler
;
1001 struct nx_host_sds_ring
*sds_ring
;
1004 unsigned long flags
= 0;
1005 struct net_device
*netdev
= adapter
->netdev
;
1006 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1008 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
1009 handler
= netxen_msix_intr
;
1010 else if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
1011 handler
= netxen_msi_intr
;
1013 flags
|= IRQF_SHARED
;
1014 handler
= netxen_intr
;
1016 adapter
->irq
= netdev
->irq
;
1018 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1019 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1020 sprintf(sds_ring
->name
, "%s[%d]", netdev
->name
, ring
);
1021 err
= request_irq(sds_ring
->irq
, handler
,
1022 flags
, sds_ring
->name
, sds_ring
);
1031 netxen_nic_free_irq(struct netxen_adapter
*adapter
)
1034 struct nx_host_sds_ring
*sds_ring
;
1036 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1038 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1039 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1040 free_irq(sds_ring
->irq
, sds_ring
);
1045 netxen_nic_init_coalesce_defaults(struct netxen_adapter
*adapter
)
1047 adapter
->coal
.flags
= NETXEN_NIC_INTR_DEFAULT
;
1048 adapter
->coal
.normal
.data
.rx_time_us
=
1049 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US
;
1050 adapter
->coal
.normal
.data
.rx_packets
=
1051 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS
;
1052 adapter
->coal
.normal
.data
.tx_time_us
=
1053 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US
;
1054 adapter
->coal
.normal
.data
.tx_packets
=
1055 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS
;
1058 /* with rtnl_lock */
1060 __netxen_nic_up(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1064 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1067 err
= adapter
->init_port(adapter
, adapter
->physical_port
);
1069 printk(KERN_ERR
"%s: Failed to initialize port %d\n",
1070 netxen_nic_driver_name
, adapter
->portnum
);
1073 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1074 adapter
->macaddr_set(adapter
, adapter
->mac_addr
);
1076 adapter
->set_multi(netdev
);
1077 adapter
->set_mtu(adapter
, netdev
->mtu
);
1079 adapter
->ahw
.linkup
= 0;
1081 if (adapter
->max_sds_rings
> 1)
1082 netxen_config_rss(adapter
, 1);
1084 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1085 netxen_config_intr_coalesce(adapter
);
1087 if (netdev
->features
& NETIF_F_LRO
)
1088 netxen_config_hw_lro(adapter
, NETXEN_NIC_LRO_ENABLED
);
1090 netxen_napi_enable(adapter
);
1092 if (adapter
->capabilities
& NX_FW_CAPABILITY_LINK_NOTIFICATION
)
1093 netxen_linkevent_request(adapter
, 1);
1095 netxen_nic_set_link_parameters(adapter
);
1097 set_bit(__NX_DEV_UP
, &adapter
->state
);
1101 /* Usage: During resume and firmware recovery module.*/
1104 netxen_nic_up(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1109 if (netif_running(netdev
))
1110 err
= __netxen_nic_up(adapter
, netdev
);
1116 /* with rtnl_lock */
1118 __netxen_nic_down(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1120 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1123 if (!test_and_clear_bit(__NX_DEV_UP
, &adapter
->state
))
1127 spin_lock(&adapter
->tx_clean_lock
);
1128 netif_carrier_off(netdev
);
1129 netif_tx_disable(netdev
);
1131 if (adapter
->capabilities
& NX_FW_CAPABILITY_LINK_NOTIFICATION
)
1132 netxen_linkevent_request(adapter
, 0);
1134 if (adapter
->stop_port
)
1135 adapter
->stop_port(adapter
);
1137 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1138 netxen_p3_free_mac_list(adapter
);
1140 adapter
->set_promisc(adapter
, NETXEN_NIU_NON_PROMISC_MODE
);
1142 netxen_napi_disable(adapter
);
1144 netxen_release_tx_buffers(adapter
);
1145 spin_unlock(&adapter
->tx_clean_lock
);
1148 /* Usage: During suspend and firmware recovery module */
1151 netxen_nic_down(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1154 if (netif_running(netdev
))
1155 __netxen_nic_down(adapter
, netdev
);
1161 netxen_nic_attach(struct netxen_adapter
*adapter
)
1163 struct net_device
*netdev
= adapter
->netdev
;
1164 struct pci_dev
*pdev
= adapter
->pdev
;
1166 struct nx_host_rds_ring
*rds_ring
;
1167 struct nx_host_tx_ring
*tx_ring
;
1169 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
)
1172 err
= netxen_init_firmware(adapter
);
1176 err
= netxen_napi_add(adapter
, netdev
);
1180 err
= netxen_alloc_sw_resources(adapter
);
1182 printk(KERN_ERR
"%s: Error in setting sw resources\n",
1187 err
= netxen_alloc_hw_resources(adapter
);
1189 printk(KERN_ERR
"%s: Error in setting hw resources\n",
1191 goto err_out_free_sw
;
1194 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1195 tx_ring
= adapter
->tx_ring
;
1196 tx_ring
->crb_cmd_producer
= netxen_get_ioaddr(adapter
,
1197 crb_cmd_producer
[adapter
->portnum
]);
1198 tx_ring
->crb_cmd_consumer
= netxen_get_ioaddr(adapter
,
1199 crb_cmd_consumer
[adapter
->portnum
]);
1201 tx_ring
->producer
= 0;
1202 tx_ring
->sw_consumer
= 0;
1204 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
1205 netxen_nic_update_cmd_consumer(adapter
, tx_ring
);
1208 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1209 rds_ring
= &adapter
->recv_ctx
.rds_rings
[ring
];
1210 netxen_post_rx_buffers(adapter
, ring
, rds_ring
);
1213 err
= netxen_nic_request_irq(adapter
);
1215 dev_err(&pdev
->dev
, "%s: failed to setup interrupt\n",
1217 goto err_out_free_rxbuf
;
1220 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1221 netxen_nic_init_coalesce_defaults(adapter
);
1223 netxen_create_sysfs_entries(adapter
);
1225 adapter
->is_up
= NETXEN_ADAPTER_UP_MAGIC
;
1229 netxen_release_rx_buffers(adapter
);
1230 netxen_free_hw_resources(adapter
);
1232 netxen_free_sw_resources(adapter
);
1237 netxen_nic_detach(struct netxen_adapter
*adapter
)
1239 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1242 netxen_remove_sysfs_entries(adapter
);
1244 netxen_free_hw_resources(adapter
);
1245 netxen_release_rx_buffers(adapter
);
1246 netxen_nic_free_irq(adapter
);
1247 netxen_napi_del(adapter
);
1248 netxen_free_sw_resources(adapter
);
1254 netxen_nic_reset_context(struct netxen_adapter
*adapter
)
1257 struct net_device
*netdev
= adapter
->netdev
;
1259 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
1262 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
) {
1264 netif_device_detach(netdev
);
1266 if (netif_running(netdev
))
1267 __netxen_nic_down(adapter
, netdev
);
1269 netxen_nic_detach(adapter
);
1271 if (netif_running(netdev
)) {
1272 err
= netxen_nic_attach(adapter
);
1274 err
= __netxen_nic_up(adapter
, netdev
);
1280 netif_device_attach(netdev
);
1284 clear_bit(__NX_RESETTING
, &adapter
->state
);
1289 netxen_setup_netdev(struct netxen_adapter
*adapter
,
1290 struct net_device
*netdev
)
1293 struct pci_dev
*pdev
= adapter
->pdev
;
1295 adapter
->mc_enabled
= 0;
1296 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1297 adapter
->max_mc_count
= 38;
1299 adapter
->max_mc_count
= 16;
1301 netdev
->netdev_ops
= &netxen_netdev_ops
;
1302 netdev
->watchdog_timeo
= 5*HZ
;
1304 netxen_nic_change_mtu(netdev
, netdev
->mtu
);
1306 SET_ETHTOOL_OPS(netdev
, &netxen_nic_ethtool_ops
);
1308 netdev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_TSO
|
1311 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1312 netdev
->hw_features
|= NETIF_F_IPV6_CSUM
| NETIF_F_TSO6
;
1314 netdev
->vlan_features
|= netdev
->hw_features
;
1316 if (adapter
->pci_using_dac
) {
1317 netdev
->features
|= NETIF_F_HIGHDMA
;
1318 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
1321 if (adapter
->capabilities
& NX_FW_CAPABILITY_FVLANTX
)
1322 netdev
->hw_features
|= NETIF_F_HW_VLAN_TX
;
1324 if (adapter
->capabilities
& NX_FW_CAPABILITY_HW_LRO
)
1325 netdev
->hw_features
|= NETIF_F_LRO
;
1327 netdev
->features
|= netdev
->hw_features
;
1329 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1331 INIT_WORK(&adapter
->tx_timeout_task
, netxen_tx_timeout_task
);
1333 if (netxen_read_mac_addr(adapter
))
1334 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1336 netif_carrier_off(netdev
);
1338 err
= register_netdev(netdev
);
1340 dev_err(&pdev
->dev
, "failed to register net device\n");
1347 #ifdef CONFIG_PCIEAER
1348 static void netxen_mask_aer_correctable(struct netxen_adapter
*adapter
)
1350 struct pci_dev
*pdev
= adapter
->pdev
;
1351 struct pci_dev
*root
= pdev
->bus
->self
;
1354 if (adapter
->ahw
.board_type
!= NETXEN_BRDTYPE_P3_4_GB_MM
&&
1355 adapter
->ahw
.board_type
!= NETXEN_BRDTYPE_P3_10G_TP
)
1358 if (root
->pcie_type
!= PCI_EXP_TYPE_ROOT_PORT
)
1361 aer_pos
= pci_find_ext_capability(root
, PCI_EXT_CAP_ID_ERR
);
1365 pci_write_config_dword(root
, aer_pos
+ PCI_ERR_COR_MASK
, 0xffff);
1369 static int __devinit
1370 netxen_nic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1372 struct net_device
*netdev
= NULL
;
1373 struct netxen_adapter
*adapter
= NULL
;
1375 int pci_func_id
= PCI_FUNC(pdev
->devfn
);
1376 uint8_t revision_id
;
1379 if (pdev
->revision
>= NX_P3_A0
&& pdev
->revision
<= NX_P3_B1
) {
1380 pr_warning("%s: chip revisions between 0x%x-0x%x "
1381 "will not be enabled.\n",
1382 module_name(THIS_MODULE
), NX_P3_A0
, NX_P3_B1
);
1386 if ((err
= pci_enable_device(pdev
)))
1389 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1391 goto err_out_disable_pdev
;
1394 if ((err
= pci_request_regions(pdev
, netxen_nic_driver_name
)))
1395 goto err_out_disable_pdev
;
1397 if (NX_IS_REVISION_P3(pdev
->revision
))
1398 pci_enable_pcie_error_reporting(pdev
);
1400 pci_set_master(pdev
);
1402 netdev
= alloc_etherdev(sizeof(struct netxen_adapter
));
1404 dev_err(&pdev
->dev
, "failed to allocate net_device\n");
1406 goto err_out_free_res
;
1409 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1411 adapter
= netdev_priv(netdev
);
1412 adapter
->netdev
= netdev
;
1413 adapter
->pdev
= pdev
;
1414 adapter
->ahw
.pci_func
= pci_func_id
;
1416 revision_id
= pdev
->revision
;
1417 adapter
->ahw
.revision_id
= revision_id
;
1419 rwlock_init(&adapter
->ahw
.crb_lock
);
1420 spin_lock_init(&adapter
->ahw
.mem_lock
);
1422 spin_lock_init(&adapter
->tx_clean_lock
);
1423 INIT_LIST_HEAD(&adapter
->mac_list
);
1424 INIT_LIST_HEAD(&adapter
->vlan_ip_list
);
1426 err
= netxen_setup_pci_map(adapter
);
1428 goto err_out_free_netdev
;
1430 /* This will be reset for mezz cards */
1431 adapter
->portnum
= pci_func_id
;
1433 err
= netxen_nic_get_board_info(adapter
);
1435 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1436 goto err_out_iounmap
;
1439 #ifdef CONFIG_PCIEAER
1440 netxen_mask_aer_correctable(adapter
);
1443 /* Mezz cards have PCI function 0,2,3 enabled */
1444 switch (adapter
->ahw
.board_type
) {
1445 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
1446 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
1447 if (pci_func_id
>= 2)
1448 adapter
->portnum
= pci_func_id
- 2;
1454 err
= netxen_check_flash_fw_compatibility(adapter
);
1456 goto err_out_iounmap
;
1458 if (adapter
->portnum
== 0) {
1459 val
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
1460 if (val
!= 0xffffffff && val
!= 0) {
1461 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, 0);
1462 adapter
->need_fw_reset
= 1;
1466 err
= netxen_start_firmware(adapter
);
1468 goto err_out_decr_ref
;
1471 * See if the firmware gave us a virtual-physical port mapping.
1473 adapter
->physical_port
= adapter
->portnum
;
1474 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1475 i
= NXRD32(adapter
, CRB_V2P(adapter
->portnum
));
1476 if (i
!= 0x55555555)
1477 adapter
->physical_port
= i
;
1480 netxen_nic_clear_stats(adapter
);
1482 netxen_setup_intr(adapter
);
1484 err
= netxen_setup_netdev(adapter
, netdev
);
1486 goto err_out_disable_msi
;
1488 pci_set_drvdata(pdev
, adapter
);
1490 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1492 switch (adapter
->ahw
.port_type
) {
1493 case NETXEN_NIC_GBE
:
1494 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1495 adapter
->netdev
->name
);
1497 case NETXEN_NIC_XGBE
:
1498 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1499 adapter
->netdev
->name
);
1503 netxen_create_diag_entries(adapter
);
1507 err_out_disable_msi
:
1508 netxen_teardown_intr(adapter
);
1510 netxen_free_dummy_dma(adapter
);
1513 nx_decr_dev_ref_cnt(adapter
);
1516 netxen_cleanup_pci_map(adapter
);
1518 err_out_free_netdev
:
1519 free_netdev(netdev
);
1522 pci_release_regions(pdev
);
1524 err_out_disable_pdev
:
1525 pci_set_drvdata(pdev
, NULL
);
1526 pci_disable_device(pdev
);
1530 static void __devexit
netxen_nic_remove(struct pci_dev
*pdev
)
1532 struct netxen_adapter
*adapter
;
1533 struct net_device
*netdev
;
1535 adapter
= pci_get_drvdata(pdev
);
1536 if (adapter
== NULL
)
1539 netdev
= adapter
->netdev
;
1541 netxen_cancel_fw_work(adapter
);
1543 unregister_netdev(netdev
);
1545 cancel_work_sync(&adapter
->tx_timeout_task
);
1547 netxen_free_vlan_ip_list(adapter
);
1548 netxen_nic_detach(adapter
);
1550 nx_decr_dev_ref_cnt(adapter
);
1552 if (adapter
->portnum
== 0)
1553 netxen_free_dummy_dma(adapter
);
1555 clear_bit(__NX_RESETTING
, &adapter
->state
);
1557 netxen_teardown_intr(adapter
);
1559 netxen_remove_diag_entries(adapter
);
1561 netxen_cleanup_pci_map(adapter
);
1563 netxen_release_firmware(adapter
);
1565 if (NX_IS_REVISION_P3(pdev
->revision
))
1566 pci_disable_pcie_error_reporting(pdev
);
1568 pci_release_regions(pdev
);
1569 pci_disable_device(pdev
);
1570 pci_set_drvdata(pdev
, NULL
);
1572 free_netdev(netdev
);
1575 static void netxen_nic_detach_func(struct netxen_adapter
*adapter
)
1577 struct net_device
*netdev
= adapter
->netdev
;
1579 netif_device_detach(netdev
);
1581 netxen_cancel_fw_work(adapter
);
1583 if (netif_running(netdev
))
1584 netxen_nic_down(adapter
, netdev
);
1586 cancel_work_sync(&adapter
->tx_timeout_task
);
1588 netxen_nic_detach(adapter
);
1590 if (adapter
->portnum
== 0)
1591 netxen_free_dummy_dma(adapter
);
1593 nx_decr_dev_ref_cnt(adapter
);
1595 clear_bit(__NX_RESETTING
, &adapter
->state
);
1598 static int netxen_nic_attach_func(struct pci_dev
*pdev
)
1600 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1601 struct net_device
*netdev
= adapter
->netdev
;
1604 err
= pci_enable_device(pdev
);
1608 pci_set_power_state(pdev
, PCI_D0
);
1609 pci_set_master(pdev
);
1610 pci_restore_state(pdev
);
1612 adapter
->ahw
.crb_win
= -1;
1613 adapter
->ahw
.ocm_win
= -1;
1615 err
= netxen_start_firmware(adapter
);
1617 dev_err(&pdev
->dev
, "failed to start firmware\n");
1621 if (netif_running(netdev
)) {
1622 err
= netxen_nic_attach(adapter
);
1626 err
= netxen_nic_up(adapter
, netdev
);
1628 goto err_out_detach
;
1630 netxen_restore_indev_addr(netdev
, NETDEV_UP
);
1633 netif_device_attach(netdev
);
1634 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1638 netxen_nic_detach(adapter
);
1640 nx_decr_dev_ref_cnt(adapter
);
1644 static pci_ers_result_t
netxen_io_error_detected(struct pci_dev
*pdev
,
1645 pci_channel_state_t state
)
1647 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1649 if (state
== pci_channel_io_perm_failure
)
1650 return PCI_ERS_RESULT_DISCONNECT
;
1652 if (nx_dev_request_aer(adapter
))
1653 return PCI_ERS_RESULT_RECOVERED
;
1655 netxen_nic_detach_func(adapter
);
1657 pci_disable_device(pdev
);
1659 return PCI_ERS_RESULT_NEED_RESET
;
1662 static pci_ers_result_t
netxen_io_slot_reset(struct pci_dev
*pdev
)
1666 err
= netxen_nic_attach_func(pdev
);
1668 return err
? PCI_ERS_RESULT_DISCONNECT
: PCI_ERS_RESULT_RECOVERED
;
1671 static void netxen_io_resume(struct pci_dev
*pdev
)
1673 pci_cleanup_aer_uncorrect_error_status(pdev
);
1676 static void netxen_nic_shutdown(struct pci_dev
*pdev
)
1678 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1680 netxen_nic_detach_func(adapter
);
1682 if (pci_save_state(pdev
))
1685 if (netxen_nic_wol_supported(adapter
)) {
1686 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1687 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1690 pci_disable_device(pdev
);
1695 netxen_nic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1697 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1700 netxen_nic_detach_func(adapter
);
1702 retval
= pci_save_state(pdev
);
1706 if (netxen_nic_wol_supported(adapter
)) {
1707 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1708 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1711 pci_disable_device(pdev
);
1712 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1718 netxen_nic_resume(struct pci_dev
*pdev
)
1720 return netxen_nic_attach_func(pdev
);
1724 static int netxen_nic_open(struct net_device
*netdev
)
1726 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1729 if (adapter
->driver_mismatch
)
1732 err
= netxen_nic_attach(adapter
);
1736 err
= __netxen_nic_up(adapter
, netdev
);
1740 netif_start_queue(netdev
);
1745 netxen_nic_detach(adapter
);
1750 * netxen_nic_close - Disables a network interface entry point
1752 static int netxen_nic_close(struct net_device
*netdev
)
1754 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1756 __netxen_nic_down(adapter
, netdev
);
1761 netxen_tso_check(struct net_device
*netdev
,
1762 struct nx_host_tx_ring
*tx_ring
,
1763 struct cmd_desc_type0
*first_desc
,
1764 struct sk_buff
*skb
)
1766 u8 opcode
= TX_ETHER_PKT
;
1767 __be16 protocol
= skb
->protocol
;
1768 u16 flags
= 0, vid
= 0;
1770 int copied
, offset
, copy_len
, hdr_len
= 0, tso
= 0, vlan_oob
= 0;
1771 struct cmd_desc_type0
*hwdesc
;
1772 struct vlan_ethhdr
*vh
;
1774 if (protocol
== cpu_to_be16(ETH_P_8021Q
)) {
1776 vh
= (struct vlan_ethhdr
*)skb
->data
;
1777 protocol
= vh
->h_vlan_encapsulated_proto
;
1778 flags
= FLAGS_VLAN_TAGGED
;
1780 } else if (vlan_tx_tag_present(skb
)) {
1782 flags
= FLAGS_VLAN_OOB
;
1783 vid
= vlan_tx_tag_get(skb
);
1784 netxen_set_tx_vlan_tci(first_desc
, vid
);
1788 if ((netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
1789 skb_shinfo(skb
)->gso_size
> 0) {
1791 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
1793 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
1794 first_desc
->total_hdr_length
= hdr_len
;
1796 first_desc
->total_hdr_length
+= VLAN_HLEN
;
1797 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
1798 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
1799 /* Only in case of TSO on vlan device */
1800 flags
|= FLAGS_VLAN_TAGGED
;
1803 opcode
= (protocol
== cpu_to_be16(ETH_P_IPV6
)) ?
1804 TX_TCP_LSO6
: TX_TCP_LSO
;
1807 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1810 if (protocol
== cpu_to_be16(ETH_P_IP
)) {
1811 l4proto
= ip_hdr(skb
)->protocol
;
1813 if (l4proto
== IPPROTO_TCP
)
1814 opcode
= TX_TCP_PKT
;
1815 else if(l4proto
== IPPROTO_UDP
)
1816 opcode
= TX_UDP_PKT
;
1817 } else if (protocol
== cpu_to_be16(ETH_P_IPV6
)) {
1818 l4proto
= ipv6_hdr(skb
)->nexthdr
;
1820 if (l4proto
== IPPROTO_TCP
)
1821 opcode
= TX_TCPV6_PKT
;
1822 else if(l4proto
== IPPROTO_UDP
)
1823 opcode
= TX_UDPV6_PKT
;
1827 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
1828 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
1829 netxen_set_tx_flags_opcode(first_desc
, flags
, opcode
);
1834 /* For LSO, we need to copy the MAC/IP/TCP headers into
1835 * the descriptor ring
1837 producer
= tx_ring
->producer
;
1842 /* Create a TSO vlan header template for firmware */
1844 hwdesc
= &tx_ring
->desc_head
[producer
];
1845 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1847 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1848 hdr_len
+ VLAN_HLEN
);
1850 vh
= (struct vlan_ethhdr
*)((char *)hwdesc
+ 2);
1851 skb_copy_from_linear_data(skb
, vh
, 12);
1852 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
1853 vh
->h_vlan_TCI
= htons(vid
);
1854 skb_copy_from_linear_data_offset(skb
, 12,
1855 (char *)vh
+ 16, copy_len
- 16);
1857 copied
= copy_len
- VLAN_HLEN
;
1860 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1863 while (copied
< hdr_len
) {
1865 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1866 (hdr_len
- copied
));
1868 hwdesc
= &tx_ring
->desc_head
[producer
];
1869 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1871 skb_copy_from_linear_data_offset(skb
, copied
,
1872 (char *)hwdesc
+ offset
, copy_len
);
1877 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1880 tx_ring
->producer
= producer
;
1885 netxen_map_tx_skb(struct pci_dev
*pdev
,
1886 struct sk_buff
*skb
, struct netxen_cmd_buffer
*pbuf
)
1888 struct netxen_skb_frag
*nf
;
1889 struct skb_frag_struct
*frag
;
1893 nr_frags
= skb_shinfo(skb
)->nr_frags
;
1894 nf
= &pbuf
->frag_array
[0];
1896 map
= pci_map_single(pdev
, skb
->data
,
1897 skb_headlen(skb
), PCI_DMA_TODEVICE
);
1898 if (pci_dma_mapping_error(pdev
, map
))
1902 nf
->length
= skb_headlen(skb
);
1904 for (i
= 0; i
< nr_frags
; i
++) {
1905 frag
= &skb_shinfo(skb
)->frags
[i
];
1906 nf
= &pbuf
->frag_array
[i
+1];
1908 map
= skb_frag_dma_map(&pdev
->dev
, frag
, 0, skb_frag_size(frag
),
1910 if (dma_mapping_error(&pdev
->dev
, map
))
1914 nf
->length
= skb_frag_size(frag
);
1921 nf
= &pbuf
->frag_array
[i
+1];
1922 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
1925 nf
= &pbuf
->frag_array
[0];
1926 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
1933 netxen_clear_cmddesc(u64
*desc
)
1940 netxen_nic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
1942 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1943 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1944 struct netxen_cmd_buffer
*pbuf
;
1945 struct netxen_skb_frag
*buffrag
;
1946 struct cmd_desc_type0
*hwdesc
, *first_desc
;
1947 struct pci_dev
*pdev
;
1950 struct skb_frag_struct
*frag
;
1953 int frag_count
, no_of_desc
;
1954 u32 num_txd
= tx_ring
->num_desc
;
1956 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
1958 /* 14 frags supported for normal packet and
1959 * 32 frags supported for TSO packet
1961 if (!skb_is_gso(skb
) && frag_count
> NETXEN_MAX_FRAGS_PER_TX
) {
1963 for (i
= 0; i
< (frag_count
- NETXEN_MAX_FRAGS_PER_TX
); i
++) {
1964 frag
= &skb_shinfo(skb
)->frags
[i
];
1965 delta
+= skb_frag_size(frag
);
1968 if (!__pskb_pull_tail(skb
, delta
))
1971 frag_count
= 1 + skb_shinfo(skb
)->nr_frags
;
1973 /* 4 fragments per cmd des */
1974 no_of_desc
= (frag_count
+ 3) >> 2;
1976 if (unlikely(netxen_tx_avail(tx_ring
) <= TX_STOP_THRESH
)) {
1977 netif_stop_queue(netdev
);
1979 if (netxen_tx_avail(tx_ring
) > TX_STOP_THRESH
)
1980 netif_start_queue(netdev
);
1982 return NETDEV_TX_BUSY
;
1985 producer
= tx_ring
->producer
;
1986 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
1988 pdev
= adapter
->pdev
;
1990 if (netxen_map_tx_skb(pdev
, skb
, pbuf
))
1994 pbuf
->frag_count
= frag_count
;
1996 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
1997 netxen_clear_cmddesc((u64
*)hwdesc
);
1999 netxen_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
2000 netxen_set_tx_port(first_desc
, adapter
->portnum
);
2002 for (i
= 0; i
< frag_count
; i
++) {
2006 if ((k
== 0) && (i
> 0)) {
2007 /* move to next desc.*/
2008 producer
= get_next_index(producer
, num_txd
);
2009 hwdesc
= &tx_ring
->desc_head
[producer
];
2010 netxen_clear_cmddesc((u64
*)hwdesc
);
2011 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2014 buffrag
= &pbuf
->frag_array
[i
];
2016 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
2019 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
2022 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
2025 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
2028 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
2033 tx_ring
->producer
= get_next_index(producer
, num_txd
);
2035 netxen_tso_check(netdev
, tx_ring
, first_desc
, skb
);
2037 adapter
->stats
.txbytes
+= skb
->len
;
2038 adapter
->stats
.xmitcalled
++;
2040 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
2042 return NETDEV_TX_OK
;
2045 adapter
->stats
.txdropped
++;
2046 dev_kfree_skb_any(skb
);
2047 return NETDEV_TX_OK
;
2050 static int netxen_nic_check_temp(struct netxen_adapter
*adapter
)
2052 struct net_device
*netdev
= adapter
->netdev
;
2053 uint32_t temp
, temp_state
, temp_val
;
2056 temp
= NXRD32(adapter
, CRB_TEMP_STATE
);
2058 temp_state
= nx_get_temp_state(temp
);
2059 temp_val
= nx_get_temp_val(temp
);
2061 if (temp_state
== NX_TEMP_PANIC
) {
2063 "%s: Device temperature %d degrees C exceeds"
2064 " maximum allowed. Hardware has been shut down.\n",
2065 netdev
->name
, temp_val
);
2067 } else if (temp_state
== NX_TEMP_WARN
) {
2068 if (adapter
->temp
== NX_TEMP_NORMAL
) {
2070 "%s: Device temperature %d degrees C "
2071 "exceeds operating range."
2072 " Immediate action needed.\n",
2073 netdev
->name
, temp_val
);
2076 if (adapter
->temp
== NX_TEMP_WARN
) {
2078 "%s: Device temperature is now %d degrees C"
2079 " in normal range.\n", netdev
->name
,
2083 adapter
->temp
= temp_state
;
2087 void netxen_advert_link_change(struct netxen_adapter
*adapter
, int linkup
)
2089 struct net_device
*netdev
= adapter
->netdev
;
2091 if (adapter
->ahw
.linkup
&& !linkup
) {
2092 printk(KERN_INFO
"%s: %s NIC Link is down\n",
2093 netxen_nic_driver_name
, netdev
->name
);
2094 adapter
->ahw
.linkup
= 0;
2095 if (netif_running(netdev
)) {
2096 netif_carrier_off(netdev
);
2097 netif_stop_queue(netdev
);
2099 adapter
->link_changed
= !adapter
->has_link_events
;
2100 } else if (!adapter
->ahw
.linkup
&& linkup
) {
2101 printk(KERN_INFO
"%s: %s NIC Link is up\n",
2102 netxen_nic_driver_name
, netdev
->name
);
2103 adapter
->ahw
.linkup
= 1;
2104 if (netif_running(netdev
)) {
2105 netif_carrier_on(netdev
);
2106 netif_wake_queue(netdev
);
2108 adapter
->link_changed
= !adapter
->has_link_events
;
2112 static void netxen_nic_handle_phy_intr(struct netxen_adapter
*adapter
)
2114 u32 val
, port
, linkup
;
2116 port
= adapter
->physical_port
;
2118 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
2119 val
= NXRD32(adapter
, CRB_XG_STATE_P3
);
2120 val
= XG_LINK_STATE_P3(adapter
->ahw
.pci_func
, val
);
2121 linkup
= (val
== XG_LINK_UP_P3
);
2123 val
= NXRD32(adapter
, CRB_XG_STATE
);
2124 val
= (val
>> port
*8) & 0xff;
2125 linkup
= (val
== XG_LINK_UP
);
2128 netxen_advert_link_change(adapter
, linkup
);
2131 static void netxen_tx_timeout(struct net_device
*netdev
)
2133 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2135 if (test_bit(__NX_RESETTING
, &adapter
->state
))
2138 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
2139 schedule_work(&adapter
->tx_timeout_task
);
2142 static void netxen_tx_timeout_task(struct work_struct
*work
)
2144 struct netxen_adapter
*adapter
=
2145 container_of(work
, struct netxen_adapter
, tx_timeout_task
);
2147 if (!netif_running(adapter
->netdev
))
2150 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2153 if (++adapter
->tx_timeo_cnt
>= NX_MAX_TX_TIMEOUTS
)
2157 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
2158 /* try to scrub interrupt */
2159 netxen_napi_disable(adapter
);
2161 netxen_napi_enable(adapter
);
2163 netif_wake_queue(adapter
->netdev
);
2165 clear_bit(__NX_RESETTING
, &adapter
->state
);
2167 clear_bit(__NX_RESETTING
, &adapter
->state
);
2168 if (netxen_nic_reset_context(adapter
)) {
2173 adapter
->netdev
->trans_start
= jiffies
;
2178 adapter
->need_fw_reset
= 1;
2179 clear_bit(__NX_RESETTING
, &adapter
->state
);
2182 static struct rtnl_link_stats64
*netxen_nic_get_stats(struct net_device
*netdev
,
2183 struct rtnl_link_stats64
*stats
)
2185 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2187 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
2188 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
2189 stats
->rx_bytes
= adapter
->stats
.rxbytes
;
2190 stats
->tx_bytes
= adapter
->stats
.txbytes
;
2191 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
2192 stats
->tx_dropped
= adapter
->stats
.txdropped
;
2197 static irqreturn_t
netxen_intr(int irq
, void *data
)
2199 struct nx_host_sds_ring
*sds_ring
= data
;
2200 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2203 status
= readl(adapter
->isr_int_vec
);
2205 if (!(status
& adapter
->int_vec_bit
))
2208 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
2209 /* check interrupt state machine, to be sure */
2210 status
= readl(adapter
->crb_int_state_reg
);
2211 if (!ISR_LEGACY_INT_TRIGGERED(status
))
2215 unsigned long our_int
= 0;
2217 our_int
= readl(adapter
->crb_int_state_reg
);
2219 /* not our interrupt */
2220 if (!test_and_clear_bit((7 + adapter
->portnum
), &our_int
))
2223 /* claim interrupt */
2224 writel((our_int
& 0xffffffff), adapter
->crb_int_state_reg
);
2226 /* clear interrupt */
2227 netxen_nic_disable_int(sds_ring
);
2230 writel(0xffffffff, adapter
->tgt_status_reg
);
2231 /* read twice to ensure write is flushed */
2232 readl(adapter
->isr_int_vec
);
2233 readl(adapter
->isr_int_vec
);
2235 napi_schedule(&sds_ring
->napi
);
2240 static irqreturn_t
netxen_msi_intr(int irq
, void *data
)
2242 struct nx_host_sds_ring
*sds_ring
= data
;
2243 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2245 /* clear interrupt */
2246 writel(0xffffffff, adapter
->tgt_status_reg
);
2248 napi_schedule(&sds_ring
->napi
);
2252 static irqreturn_t
netxen_msix_intr(int irq
, void *data
)
2254 struct nx_host_sds_ring
*sds_ring
= data
;
2256 napi_schedule(&sds_ring
->napi
);
2260 static int netxen_nic_poll(struct napi_struct
*napi
, int budget
)
2262 struct nx_host_sds_ring
*sds_ring
=
2263 container_of(napi
, struct nx_host_sds_ring
, napi
);
2265 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2270 tx_complete
= netxen_process_cmd_ring(adapter
);
2272 work_done
= netxen_process_rcv_ring(sds_ring
, budget
);
2274 if ((work_done
< budget
) && tx_complete
) {
2275 napi_complete(&sds_ring
->napi
);
2276 if (test_bit(__NX_DEV_UP
, &adapter
->state
))
2277 netxen_nic_enable_int(sds_ring
);
2283 #ifdef CONFIG_NET_POLL_CONTROLLER
2284 static void netxen_nic_poll_controller(struct net_device
*netdev
)
2287 struct nx_host_sds_ring
*sds_ring
;
2288 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2289 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
2291 disable_irq(adapter
->irq
);
2292 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
2293 sds_ring
= &recv_ctx
->sds_rings
[ring
];
2294 netxen_intr(adapter
->irq
, sds_ring
);
2296 enable_irq(adapter
->irq
);
2301 nx_incr_dev_ref_cnt(struct netxen_adapter
*adapter
)
2304 if (netxen_api_lock(adapter
))
2307 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2309 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, ++count
);
2311 netxen_api_unlock(adapter
);
2316 nx_decr_dev_ref_cnt(struct netxen_adapter
*adapter
)
2319 if (netxen_api_lock(adapter
))
2322 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2323 WARN_ON(count
== 0);
2325 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, --count
);
2328 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_COLD
);
2330 netxen_api_unlock(adapter
);
2335 nx_dev_request_aer(struct netxen_adapter
*adapter
)
2340 if (netxen_api_lock(adapter
))
2343 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2345 if (state
== NX_DEV_NEED_AER
)
2347 else if (state
== NX_DEV_READY
) {
2348 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_NEED_AER
);
2352 netxen_api_unlock(adapter
);
2357 nx_dev_request_reset(struct netxen_adapter
*adapter
)
2362 if (netxen_api_lock(adapter
))
2365 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2367 if (state
== NX_DEV_NEED_RESET
)
2369 else if (state
!= NX_DEV_INITALIZING
&& state
!= NX_DEV_NEED_AER
) {
2370 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_NEED_RESET
);
2374 netxen_api_unlock(adapter
);
2380 netxen_can_start_firmware(struct netxen_adapter
*adapter
)
2385 if (netxen_api_lock(adapter
))
2388 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2390 if ((count
< 0) || (count
>= NX_MAX_PCI_FUNC
))
2395 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_INITALIZING
);
2398 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, ++count
);
2400 netxen_api_unlock(adapter
);
2406 netxen_schedule_work(struct netxen_adapter
*adapter
,
2407 work_func_t func
, int delay
)
2409 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
2410 schedule_delayed_work(&adapter
->fw_work
, delay
);
2414 netxen_cancel_fw_work(struct netxen_adapter
*adapter
)
2416 while (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2419 cancel_delayed_work_sync(&adapter
->fw_work
);
2423 netxen_attach_work(struct work_struct
*work
)
2425 struct netxen_adapter
*adapter
= container_of(work
,
2426 struct netxen_adapter
, fw_work
.work
);
2427 struct net_device
*netdev
= adapter
->netdev
;
2430 if (netif_running(netdev
)) {
2431 err
= netxen_nic_attach(adapter
);
2435 err
= netxen_nic_up(adapter
, netdev
);
2437 netxen_nic_detach(adapter
);
2441 netxen_restore_indev_addr(netdev
, NETDEV_UP
);
2444 netif_device_attach(netdev
);
2447 adapter
->fw_fail_cnt
= 0;
2448 clear_bit(__NX_RESETTING
, &adapter
->state
);
2449 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
2453 netxen_fwinit_work(struct work_struct
*work
)
2455 struct netxen_adapter
*adapter
= container_of(work
,
2456 struct netxen_adapter
, fw_work
.work
);
2459 dev_state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2461 switch (dev_state
) {
2464 if (!netxen_start_firmware(adapter
)) {
2465 netxen_schedule_work(adapter
, netxen_attach_work
, 0);
2470 case NX_DEV_NEED_RESET
:
2471 case NX_DEV_INITALIZING
:
2472 if (++adapter
->fw_wait_cnt
< FW_POLL_THRESH
) {
2473 netxen_schedule_work(adapter
,
2474 netxen_fwinit_work
, 2 * FW_POLL_DELAY
);
2480 nx_incr_dev_ref_cnt(adapter
);
2484 clear_bit(__NX_RESETTING
, &adapter
->state
);
2488 netxen_detach_work(struct work_struct
*work
)
2490 struct netxen_adapter
*adapter
= container_of(work
,
2491 struct netxen_adapter
, fw_work
.work
);
2492 struct net_device
*netdev
= adapter
->netdev
;
2496 netif_device_detach(netdev
);
2498 netxen_nic_down(adapter
, netdev
);
2501 netxen_nic_detach(adapter
);
2504 status
= NXRD32(adapter
, NETXEN_PEG_HALT_STATUS1
);
2506 if (status
& NX_RCODE_FATAL_ERROR
)
2509 if (adapter
->temp
== NX_TEMP_PANIC
)
2512 ref_cnt
= nx_decr_dev_ref_cnt(adapter
);
2514 if (ref_cnt
== -EIO
)
2517 delay
= (ref_cnt
== 0) ? 0 : (2 * FW_POLL_DELAY
);
2519 adapter
->fw_wait_cnt
= 0;
2520 netxen_schedule_work(adapter
, netxen_fwinit_work
, delay
);
2525 clear_bit(__NX_RESETTING
, &adapter
->state
);
2529 netxen_check_health(struct netxen_adapter
*adapter
)
2531 u32 state
, heartbit
;
2532 struct net_device
*netdev
= adapter
->netdev
;
2534 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2535 if (state
== NX_DEV_NEED_AER
)
2538 if (netxen_nic_check_temp(adapter
))
2541 if (adapter
->need_fw_reset
) {
2542 if (nx_dev_request_reset(adapter
))
2547 /* NX_DEV_NEED_RESET, this state can be marked in two cases
2548 * 1. Tx timeout 2. Fw hang
2549 * Send request to destroy context in case of tx timeout only
2550 * and doesn't required in case of Fw hang
2552 if (state
== NX_DEV_NEED_RESET
) {
2553 adapter
->need_fw_reset
= 1;
2554 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2558 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2561 heartbit
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
2562 if (heartbit
!= adapter
->heartbit
) {
2563 adapter
->heartbit
= heartbit
;
2564 adapter
->fw_fail_cnt
= 0;
2565 if (adapter
->need_fw_reset
)
2570 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
2573 if (nx_dev_request_reset(adapter
))
2576 clear_bit(__NX_FW_ATTACHED
, &adapter
->state
);
2578 dev_info(&netdev
->dev
, "firmware hang detected\n");
2581 if ((auto_fw_reset
== AUTO_FW_RESET_ENABLED
) &&
2582 !test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2583 netxen_schedule_work(adapter
, netxen_detach_work
, 0);
2588 netxen_fw_poll_work(struct work_struct
*work
)
2590 struct netxen_adapter
*adapter
= container_of(work
,
2591 struct netxen_adapter
, fw_work
.work
);
2593 if (test_bit(__NX_RESETTING
, &adapter
->state
))
2596 if (test_bit(__NX_DEV_UP
, &adapter
->state
)) {
2597 if (!adapter
->has_link_events
) {
2599 netxen_nic_handle_phy_intr(adapter
);
2601 if (adapter
->link_changed
)
2602 netxen_nic_set_link_parameters(adapter
);
2606 if (netxen_check_health(adapter
))
2610 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
2614 netxen_store_bridged_mode(struct device
*dev
,
2615 struct device_attribute
*attr
, const char *buf
, size_t len
)
2617 struct net_device
*net
= to_net_dev(dev
);
2618 struct netxen_adapter
*adapter
= netdev_priv(net
);
2622 if (!(adapter
->capabilities
& NX_FW_CAPABILITY_BDG
))
2625 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
2628 if (strict_strtoul(buf
, 2, &new))
2631 if (!netxen_config_bridged_mode(adapter
, !!new))
2639 netxen_show_bridged_mode(struct device
*dev
,
2640 struct device_attribute
*attr
, char *buf
)
2642 struct net_device
*net
= to_net_dev(dev
);
2643 struct netxen_adapter
*adapter
;
2644 int bridged_mode
= 0;
2646 adapter
= netdev_priv(net
);
2648 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
2649 bridged_mode
= !!(adapter
->flags
& NETXEN_NIC_BRIDGE_ENABLED
);
2651 return sprintf(buf
, "%d\n", bridged_mode
);
2654 static struct device_attribute dev_attr_bridged_mode
= {
2655 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2656 .show
= netxen_show_bridged_mode
,
2657 .store
= netxen_store_bridged_mode
,
2661 netxen_store_diag_mode(struct device
*dev
,
2662 struct device_attribute
*attr
, const char *buf
, size_t len
)
2664 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2667 if (strict_strtoul(buf
, 2, &new))
2670 if (!!new != !!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2671 adapter
->flags
^= NETXEN_NIC_DIAG_ENABLED
;
2677 netxen_show_diag_mode(struct device
*dev
,
2678 struct device_attribute
*attr
, char *buf
)
2680 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2682 return sprintf(buf
, "%d\n",
2683 !!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
));
2686 static struct device_attribute dev_attr_diag_mode
= {
2687 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2688 .show
= netxen_show_diag_mode
,
2689 .store
= netxen_store_diag_mode
,
2693 netxen_sysfs_validate_crb(struct netxen_adapter
*adapter
,
2694 loff_t offset
, size_t size
)
2696 size_t crb_size
= 4;
2698 if (!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2701 if (offset
< NETXEN_PCI_CRBSPACE
) {
2702 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2705 if (ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2706 NETXEN_PCI_CAMQM_2M_END
))
2712 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
2719 netxen_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
2720 struct bin_attribute
*attr
,
2721 char *buf
, loff_t offset
, size_t size
)
2723 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2724 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2729 ret
= netxen_sysfs_validate_crb(adapter
, offset
, size
);
2733 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) &&
2734 ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2735 NETXEN_PCI_CAMQM_2M_END
)) {
2736 netxen_pci_camqm_read_2M(adapter
, offset
, &qmdata
);
2737 memcpy(buf
, &qmdata
, size
);
2739 data
= NXRD32(adapter
, offset
);
2740 memcpy(buf
, &data
, size
);
2747 netxen_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
2748 struct bin_attribute
*attr
,
2749 char *buf
, loff_t offset
, size_t size
)
2751 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2752 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2757 ret
= netxen_sysfs_validate_crb(adapter
, offset
, size
);
2761 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) &&
2762 ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2763 NETXEN_PCI_CAMQM_2M_END
)) {
2764 memcpy(&qmdata
, buf
, size
);
2765 netxen_pci_camqm_write_2M(adapter
, offset
, qmdata
);
2767 memcpy(&data
, buf
, size
);
2768 NXWR32(adapter
, offset
, data
);
2775 netxen_sysfs_validate_mem(struct netxen_adapter
*adapter
,
2776 loff_t offset
, size_t size
)
2778 if (!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2781 if ((size
!= 8) || (offset
& 0x7))
2788 netxen_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
2789 struct bin_attribute
*attr
,
2790 char *buf
, loff_t offset
, size_t size
)
2792 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2793 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2797 ret
= netxen_sysfs_validate_mem(adapter
, offset
, size
);
2801 if (adapter
->pci_mem_read(adapter
, offset
, &data
))
2804 memcpy(buf
, &data
, size
);
2809 static ssize_t
netxen_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
2810 struct bin_attribute
*attr
, char *buf
,
2811 loff_t offset
, size_t size
)
2813 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2814 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2818 ret
= netxen_sysfs_validate_mem(adapter
, offset
, size
);
2822 memcpy(&data
, buf
, size
);
2824 if (adapter
->pci_mem_write(adapter
, offset
, data
))
2831 static struct bin_attribute bin_attr_crb
= {
2832 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
2834 .read
= netxen_sysfs_read_crb
,
2835 .write
= netxen_sysfs_write_crb
,
2838 static struct bin_attribute bin_attr_mem
= {
2839 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
2841 .read
= netxen_sysfs_read_mem
,
2842 .write
= netxen_sysfs_write_mem
,
2847 netxen_create_sysfs_entries(struct netxen_adapter
*adapter
)
2849 struct net_device
*netdev
= adapter
->netdev
;
2850 struct device
*dev
= &netdev
->dev
;
2852 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
) {
2853 /* bridged_mode control */
2854 if (device_create_file(dev
, &dev_attr_bridged_mode
)) {
2855 dev_warn(&netdev
->dev
,
2856 "failed to create bridged_mode sysfs entry\n");
2862 netxen_remove_sysfs_entries(struct netxen_adapter
*adapter
)
2864 struct net_device
*netdev
= adapter
->netdev
;
2865 struct device
*dev
= &netdev
->dev
;
2867 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
2868 device_remove_file(dev
, &dev_attr_bridged_mode
);
2872 netxen_create_diag_entries(struct netxen_adapter
*adapter
)
2874 struct pci_dev
*pdev
= adapter
->pdev
;
2878 if (device_create_file(dev
, &dev_attr_diag_mode
))
2879 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
2880 if (device_create_bin_file(dev
, &bin_attr_crb
))
2881 dev_info(dev
, "failed to create crb sysfs entry\n");
2882 if (device_create_bin_file(dev
, &bin_attr_mem
))
2883 dev_info(dev
, "failed to create mem sysfs entry\n");
2888 netxen_remove_diag_entries(struct netxen_adapter
*adapter
)
2890 struct pci_dev
*pdev
= adapter
->pdev
;
2891 struct device
*dev
= &pdev
->dev
;
2893 device_remove_file(dev
, &dev_attr_diag_mode
);
2894 device_remove_bin_file(dev
, &bin_attr_crb
);
2895 device_remove_bin_file(dev
, &bin_attr_mem
);
2900 #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2903 netxen_destip_supported(struct netxen_adapter
*adapter
)
2905 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2908 if (adapter
->ahw
.cut_through
)
2915 netxen_free_vlan_ip_list(struct netxen_adapter
*adapter
)
2917 struct nx_vlan_ip_list
*cur
;
2918 struct list_head
*head
= &adapter
->vlan_ip_list
;
2920 while (!list_empty(head
)) {
2921 cur
= list_entry(head
->next
, struct nx_vlan_ip_list
, list
);
2922 netxen_config_ipaddr(adapter
, cur
->ip_addr
, NX_IP_DOWN
);
2923 list_del(&cur
->list
);
2929 netxen_list_config_vlan_ip(struct netxen_adapter
*adapter
,
2930 struct in_ifaddr
*ifa
, unsigned long event
)
2932 struct net_device
*dev
;
2933 struct nx_vlan_ip_list
*cur
, *tmp_cur
;
2934 struct list_head
*head
;
2936 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
2941 if (!is_vlan_dev(dev
))
2946 list_for_each(head
, &adapter
->vlan_ip_list
) {
2947 cur
= list_entry(head
, struct nx_vlan_ip_list
, list
);
2949 if (cur
->ip_addr
== ifa
->ifa_address
)
2953 cur
= kzalloc(sizeof(struct nx_vlan_ip_list
), GFP_ATOMIC
);
2955 printk(KERN_ERR
"%s: failed to add vlan ip to list\n",
2956 adapter
->netdev
->name
);
2960 cur
->ip_addr
= ifa
->ifa_address
;
2961 list_add_tail(&cur
->list
, &adapter
->vlan_ip_list
);
2964 list_for_each_entry_safe(cur
, tmp_cur
,
2965 &adapter
->vlan_ip_list
, list
) {
2966 if (cur
->ip_addr
== ifa
->ifa_address
) {
2967 list_del(&cur
->list
);
2975 netxen_config_indev_addr(struct netxen_adapter
*adapter
,
2976 struct net_device
*dev
, unsigned long event
)
2978 struct in_device
*indev
;
2980 if (!netxen_destip_supported(adapter
))
2983 indev
= in_dev_get(dev
);
2990 netxen_config_ipaddr(adapter
,
2991 ifa
->ifa_address
, NX_IP_UP
);
2992 netxen_list_config_vlan_ip(adapter
, ifa
, NX_IP_UP
);
2995 netxen_config_ipaddr(adapter
,
2996 ifa
->ifa_address
, NX_IP_DOWN
);
2997 netxen_list_config_vlan_ip(adapter
, ifa
, NX_IP_DOWN
);
3002 } endfor_ifa(indev
);
3008 netxen_restore_indev_addr(struct net_device
*netdev
, unsigned long event
)
3011 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
3012 struct nx_vlan_ip_list
*pos
, *tmp_pos
;
3013 unsigned long ip_event
;
3015 ip_event
= (event
== NETDEV_UP
) ? NX_IP_UP
: NX_IP_DOWN
;
3016 netxen_config_indev_addr(adapter
, netdev
, event
);
3018 list_for_each_entry_safe(pos
, tmp_pos
, &adapter
->vlan_ip_list
, list
) {
3019 netxen_config_ipaddr(adapter
, pos
->ip_addr
, ip_event
);
3023 static int netxen_netdev_event(struct notifier_block
*this,
3024 unsigned long event
, void *ptr
)
3026 struct netxen_adapter
*adapter
;
3027 struct net_device
*dev
= (struct net_device
*)ptr
;
3028 struct net_device
*orig_dev
= dev
;
3034 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3035 dev
= vlan_dev_real_dev(dev
);
3039 if (!is_netxen_netdev(dev
))
3042 adapter
= netdev_priv(dev
);
3047 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
3050 netxen_config_indev_addr(adapter
, orig_dev
, event
);
3056 netxen_inetaddr_event(struct notifier_block
*this,
3057 unsigned long event
, void *ptr
)
3059 struct netxen_adapter
*adapter
;
3060 struct net_device
*dev
;
3062 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
3064 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
3070 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3071 dev
= vlan_dev_real_dev(dev
);
3075 if (!is_netxen_netdev(dev
))
3078 adapter
= netdev_priv(dev
);
3080 if (!adapter
|| !netxen_destip_supported(adapter
))
3083 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
3088 netxen_config_ipaddr(adapter
, ifa
->ifa_address
, NX_IP_UP
);
3089 netxen_list_config_vlan_ip(adapter
, ifa
, NX_IP_UP
);
3092 netxen_config_ipaddr(adapter
, ifa
->ifa_address
, NX_IP_DOWN
);
3093 netxen_list_config_vlan_ip(adapter
, ifa
, NX_IP_DOWN
);
3103 static struct notifier_block netxen_netdev_cb
= {
3104 .notifier_call
= netxen_netdev_event
,
3107 static struct notifier_block netxen_inetaddr_cb
= {
3108 .notifier_call
= netxen_inetaddr_event
,
3112 netxen_restore_indev_addr(struct net_device
*dev
, unsigned long event
)
3115 netxen_free_vlan_ip_list(struct netxen_adapter
*adapter
)
3119 static struct pci_error_handlers netxen_err_handler
= {
3120 .error_detected
= netxen_io_error_detected
,
3121 .slot_reset
= netxen_io_slot_reset
,
3122 .resume
= netxen_io_resume
,
3125 static struct pci_driver netxen_driver
= {
3126 .name
= netxen_nic_driver_name
,
3127 .id_table
= netxen_pci_tbl
,
3128 .probe
= netxen_nic_probe
,
3129 .remove
= __devexit_p(netxen_nic_remove
),
3131 .suspend
= netxen_nic_suspend
,
3132 .resume
= netxen_nic_resume
,
3134 .shutdown
= netxen_nic_shutdown
,
3135 .err_handler
= &netxen_err_handler
3138 static int __init
netxen_init_module(void)
3140 printk(KERN_INFO
"%s\n", netxen_nic_driver_string
);
3143 register_netdevice_notifier(&netxen_netdev_cb
);
3144 register_inetaddr_notifier(&netxen_inetaddr_cb
);
3146 return pci_register_driver(&netxen_driver
);
3149 module_init(netxen_init_module
);
3151 static void __exit
netxen_exit_module(void)
3153 pci_unregister_driver(&netxen_driver
);
3156 unregister_inetaddr_notifier(&netxen_inetaddr_cb
);
3157 unregister_netdevice_notifier(&netxen_netdev_cb
);
3161 module_exit(netxen_exit_module
);