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 netdev_features_t
netxen_fix_features(struct net_device
*dev
,
548 netdev_features_t features
)
550 if (!(features
& NETIF_F_RXCSUM
)) {
551 netdev_info(dev
, "disabling LRO as RXCSUM is off\n");
553 features
&= ~NETIF_F_LRO
;
559 static int netxen_set_features(struct net_device
*dev
,
560 netdev_features_t features
)
562 struct netxen_adapter
*adapter
= netdev_priv(dev
);
565 if (!((dev
->features
^ features
) & NETIF_F_LRO
))
568 hw_lro
= (features
& NETIF_F_LRO
) ? NETXEN_NIC_LRO_ENABLED
569 : NETXEN_NIC_LRO_DISABLED
;
571 if (netxen_config_hw_lro(adapter
, hw_lro
))
574 if (!(features
& NETIF_F_LRO
) && netxen_send_lro_cleanup(adapter
))
580 static const struct net_device_ops netxen_netdev_ops
= {
581 .ndo_open
= netxen_nic_open
,
582 .ndo_stop
= netxen_nic_close
,
583 .ndo_start_xmit
= netxen_nic_xmit_frame
,
584 .ndo_get_stats64
= netxen_nic_get_stats
,
585 .ndo_validate_addr
= eth_validate_addr
,
586 .ndo_set_rx_mode
= netxen_set_multicast_list
,
587 .ndo_set_mac_address
= netxen_nic_set_mac
,
588 .ndo_change_mtu
= netxen_nic_change_mtu
,
589 .ndo_tx_timeout
= netxen_tx_timeout
,
590 .ndo_fix_features
= netxen_fix_features
,
591 .ndo_set_features
= netxen_set_features
,
592 #ifdef CONFIG_NET_POLL_CONTROLLER
593 .ndo_poll_controller
= netxen_nic_poll_controller
,
598 netxen_setup_intr(struct netxen_adapter
*adapter
)
600 struct netxen_legacy_intr_set
*legacy_intrp
;
601 struct pci_dev
*pdev
= adapter
->pdev
;
604 if (adapter
->rss_supported
) {
605 num_msix
= (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER
) ?
606 MSIX_ENTRIES_PER_ADAPTER
: 2;
610 adapter
->max_sds_rings
= 1;
612 adapter
->flags
&= ~(NETXEN_NIC_MSI_ENABLED
| NETXEN_NIC_MSIX_ENABLED
);
614 if (adapter
->ahw
.revision_id
>= NX_P3_B0
)
615 legacy_intrp
= &legacy_intr
[adapter
->ahw
.pci_func
];
617 legacy_intrp
= &legacy_intr
[0];
619 adapter
->int_vec_bit
= legacy_intrp
->int_vec_bit
;
620 adapter
->tgt_status_reg
= netxen_get_ioaddr(adapter
,
621 legacy_intrp
->tgt_status_reg
);
622 adapter
->tgt_mask_reg
= netxen_get_ioaddr(adapter
,
623 legacy_intrp
->tgt_mask_reg
);
624 adapter
->pci_int_reg
= netxen_get_ioaddr(adapter
,
625 legacy_intrp
->pci_int_reg
);
626 adapter
->isr_int_vec
= netxen_get_ioaddr(adapter
, ISR_INT_VECTOR
);
628 if (adapter
->ahw
.revision_id
>= NX_P3_B1
)
629 adapter
->crb_int_state_reg
= netxen_get_ioaddr(adapter
,
632 adapter
->crb_int_state_reg
= netxen_get_ioaddr(adapter
,
635 netxen_set_msix_bit(pdev
, 0);
637 if (adapter
->msix_supported
) {
639 netxen_init_msix_entries(adapter
, num_msix
);
640 err
= pci_enable_msix(pdev
, adapter
->msix_entries
, num_msix
);
642 adapter
->flags
|= NETXEN_NIC_MSIX_ENABLED
;
643 netxen_set_msix_bit(pdev
, 1);
645 if (adapter
->rss_supported
)
646 adapter
->max_sds_rings
= num_msix
;
648 dev_info(&pdev
->dev
, "using msi-x interrupts\n");
653 pci_disable_msix(pdev
);
655 /* fall through for msi */
658 if (use_msi
&& !pci_enable_msi(pdev
)) {
659 adapter
->flags
|= NETXEN_NIC_MSI_ENABLED
;
660 adapter
->tgt_status_reg
= netxen_get_ioaddr(adapter
,
661 msi_tgt_status
[adapter
->ahw
.pci_func
]);
662 dev_info(&pdev
->dev
, "using msi interrupts\n");
663 adapter
->msix_entries
[0].vector
= pdev
->irq
;
667 dev_info(&pdev
->dev
, "using legacy interrupts\n");
668 adapter
->msix_entries
[0].vector
= pdev
->irq
;
672 netxen_teardown_intr(struct netxen_adapter
*adapter
)
674 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
675 pci_disable_msix(adapter
->pdev
);
676 if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
677 pci_disable_msi(adapter
->pdev
);
681 netxen_cleanup_pci_map(struct netxen_adapter
*adapter
)
683 if (adapter
->ahw
.db_base
!= NULL
)
684 iounmap(adapter
->ahw
.db_base
);
685 if (adapter
->ahw
.pci_base0
!= NULL
)
686 iounmap(adapter
->ahw
.pci_base0
);
687 if (adapter
->ahw
.pci_base1
!= NULL
)
688 iounmap(adapter
->ahw
.pci_base1
);
689 if (adapter
->ahw
.pci_base2
!= NULL
)
690 iounmap(adapter
->ahw
.pci_base2
);
694 netxen_setup_pci_map(struct netxen_adapter
*adapter
)
696 void __iomem
*db_ptr
= NULL
;
698 resource_size_t mem_base
, db_base
;
699 unsigned long mem_len
, db_len
= 0;
701 struct pci_dev
*pdev
= adapter
->pdev
;
702 int pci_func
= adapter
->ahw
.pci_func
;
703 struct netxen_hardware_context
*ahw
= &adapter
->ahw
;
708 * Set the CRB window to invalid. If any register in window 0 is
709 * accessed it should set the window to 0 and then reset it to 1.
711 adapter
->ahw
.crb_win
= -1;
712 adapter
->ahw
.ocm_win
= -1;
714 /* remap phys address */
715 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
716 mem_len
= pci_resource_len(pdev
, 0);
718 /* 128 Meg of memory */
719 if (mem_len
== NETXEN_PCI_128MB_SIZE
) {
721 ahw
->pci_base0
= ioremap(mem_base
, FIRST_PAGE_GROUP_SIZE
);
722 ahw
->pci_base1
= ioremap(mem_base
+ SECOND_PAGE_GROUP_START
,
723 SECOND_PAGE_GROUP_SIZE
);
724 ahw
->pci_base2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
,
725 THIRD_PAGE_GROUP_SIZE
);
726 if (ahw
->pci_base0
== NULL
|| ahw
->pci_base1
== NULL
||
727 ahw
->pci_base2
== NULL
) {
728 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
733 ahw
->pci_len0
= FIRST_PAGE_GROUP_SIZE
;
735 } else if (mem_len
== NETXEN_PCI_32MB_SIZE
) {
737 ahw
->pci_base1
= ioremap(mem_base
, SECOND_PAGE_GROUP_SIZE
);
738 ahw
->pci_base2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
-
739 SECOND_PAGE_GROUP_START
, THIRD_PAGE_GROUP_SIZE
);
740 if (ahw
->pci_base1
== NULL
|| ahw
->pci_base2
== NULL
) {
741 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
746 } else if (mem_len
== NETXEN_PCI_2MB_SIZE
) {
748 ahw
->pci_base0
= pci_ioremap_bar(pdev
, 0);
749 if (ahw
->pci_base0
== NULL
) {
750 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
753 ahw
->pci_len0
= mem_len
;
758 netxen_setup_hwops(adapter
);
760 dev_info(&pdev
->dev
, "%dMB memory map\n", (int)(mem_len
>>20));
762 if (NX_IS_REVISION_P3P(adapter
->ahw
.revision_id
)) {
763 adapter
->ahw
.ocm_win_crb
= netxen_get_ioaddr(adapter
,
764 NETXEN_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(pci_func
)));
766 } else if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
767 adapter
->ahw
.ocm_win_crb
= netxen_get_ioaddr(adapter
,
768 NETXEN_PCIX_PS_REG(PCIE_MN_WINDOW_REG(pci_func
)));
771 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
774 db_base
= pci_resource_start(pdev
, 4); /* doorbell is on bar 4 */
775 db_len
= pci_resource_len(pdev
, 4);
778 printk(KERN_ERR
"%s: doorbell is disabled\n",
779 netxen_nic_driver_name
);
784 db_ptr
= ioremap(db_base
, NETXEN_DB_MAPSIZE_BYTES
);
786 printk(KERN_ERR
"%s: Failed to allocate doorbell map.",
787 netxen_nic_driver_name
);
793 adapter
->ahw
.db_base
= db_ptr
;
794 adapter
->ahw
.db_len
= db_len
;
798 netxen_cleanup_pci_map(adapter
);
803 netxen_check_options(struct netxen_adapter
*adapter
)
805 u32 fw_major
, fw_minor
, fw_build
;
806 char brd_name
[NETXEN_MAX_SHORT_NAME
];
810 struct pci_dev
*pdev
= adapter
->pdev
;
812 adapter
->driver_mismatch
= 0;
814 ptr32
= (int *)&serial_num
;
815 offset
= NX_FW_SERIAL_NUM_OFFSET
;
816 for (i
= 0; i
< 8; i
++) {
817 if (netxen_rom_fast_read(adapter
, offset
, &val
) == -1) {
818 dev_err(&pdev
->dev
, "error reading board info\n");
819 adapter
->driver_mismatch
= 1;
822 ptr32
[i
] = cpu_to_le32(val
);
823 offset
+= sizeof(u32
);
826 fw_major
= NXRD32(adapter
, NETXEN_FW_VERSION_MAJOR
);
827 fw_minor
= NXRD32(adapter
, NETXEN_FW_VERSION_MINOR
);
828 fw_build
= NXRD32(adapter
, NETXEN_FW_VERSION_SUB
);
830 adapter
->fw_version
= NETXEN_VERSION_CODE(fw_major
, fw_minor
, fw_build
);
832 if (adapter
->portnum
== 0) {
833 get_brd_name_by_type(adapter
->ahw
.board_type
, brd_name
);
835 pr_info("%s: %s Board S/N %s Chip rev 0x%x\n",
836 module_name(THIS_MODULE
),
837 brd_name
, serial_num
, adapter
->ahw
.revision_id
);
840 if (adapter
->fw_version
< NETXEN_VERSION_CODE(3, 4, 216)) {
841 adapter
->driver_mismatch
= 1;
842 dev_warn(&pdev
->dev
, "firmware version %d.%d.%d unsupported\n",
843 fw_major
, fw_minor
, fw_build
);
847 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
848 i
= NXRD32(adapter
, NETXEN_SRE_MISC
);
849 adapter
->ahw
.cut_through
= (i
& 0x8000) ? 1 : 0;
852 dev_info(&pdev
->dev
, "firmware v%d.%d.%d [%s]\n",
853 fw_major
, fw_minor
, fw_build
,
854 adapter
->ahw
.cut_through
? "cut-through" : "legacy");
856 if (adapter
->fw_version
>= NETXEN_VERSION_CODE(4, 0, 222))
857 adapter
->capabilities
= NXRD32(adapter
, CRB_FW_CAPABILITIES_1
);
859 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
860 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
861 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
862 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
863 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
864 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
867 adapter
->msix_supported
= 0;
868 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
869 adapter
->msix_supported
= !!use_msi_x
;
870 adapter
->rss_supported
= !!use_msi_x
;
873 netxen_rom_fast_read(adapter
,
874 NX_FW_VERSION_OFFSET
, (int *)&flashed_ver
);
875 flashed_ver
= NETXEN_DECODE_VERSION(flashed_ver
);
877 if (flashed_ver
>= NETXEN_VERSION_CODE(3, 4, 336)) {
878 switch (adapter
->ahw
.board_type
) {
879 case NETXEN_BRDTYPE_P2_SB31_10G
:
880 case NETXEN_BRDTYPE_P2_SB31_10G_CX4
:
881 adapter
->msix_supported
= !!use_msi_x
;
882 adapter
->rss_supported
= !!use_msi_x
;
890 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
892 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
893 adapter
->num_lro_rxd
= MAX_LRO_RCV_DESCRIPTORS
;
894 adapter
->max_rds_rings
= 3;
896 adapter
->num_lro_rxd
= 0;
897 adapter
->max_rds_rings
= 2;
902 netxen_start_firmware(struct netxen_adapter
*adapter
)
904 int val
, err
, first_boot
;
905 struct pci_dev
*pdev
= adapter
->pdev
;
907 /* required for NX2031 dummy dma */
908 err
= nx_set_dma_mask(adapter
);
912 if (!netxen_can_start_firmware(adapter
))
915 first_boot
= NXRD32(adapter
, NETXEN_CAM_RAM(0x1fc));
917 err
= netxen_check_hw_init(adapter
, first_boot
);
919 dev_err(&pdev
->dev
, "error in init HW init sequence\n");
923 netxen_request_firmware(adapter
);
925 err
= netxen_need_fw_reset(adapter
);
929 goto pcie_strap_init
;
931 if (first_boot
!= 0x55555555) {
932 NXWR32(adapter
, CRB_CMDPEG_STATE
, 0);
933 netxen_pinit_from_rom(adapter
);
937 NXWR32(adapter
, CRB_DMA_SHIFT
, 0x55555555);
938 NXWR32(adapter
, NETXEN_PEG_HALT_STATUS1
, 0);
939 NXWR32(adapter
, NETXEN_PEG_HALT_STATUS2
, 0);
941 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
942 netxen_set_port_mode(adapter
);
944 err
= netxen_load_firmware(adapter
);
948 netxen_release_firmware(adapter
);
950 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
952 /* Initialize multicast addr pool owners */
954 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
)
956 NXWR32(adapter
, NETXEN_MAC_ADDR_CNTL_REG
, val
);
960 err
= netxen_init_dummy_dma(adapter
);
965 * Tell the hardware our version number.
967 val
= (_NETXEN_NIC_LINUX_MAJOR
<< 16)
968 | ((_NETXEN_NIC_LINUX_MINOR
<< 8))
969 | (_NETXEN_NIC_LINUX_SUBVERSION
);
970 NXWR32(adapter
, CRB_DRIVER_VERSION
, val
);
973 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
974 netxen_pcie_strap_init(adapter
);
977 /* Handshake with the card before we register the devices. */
978 err
= netxen_phantom_init(adapter
, NETXEN_NIC_PEG_TUNE
);
980 netxen_free_dummy_dma(adapter
);
984 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_READY
);
986 nx_update_dma_mask(adapter
);
988 netxen_check_options(adapter
);
990 adapter
->need_fw_reset
= 0;
992 /* fall through and release firmware */
995 netxen_release_firmware(adapter
);
1000 netxen_nic_request_irq(struct netxen_adapter
*adapter
)
1002 irq_handler_t handler
;
1003 struct nx_host_sds_ring
*sds_ring
;
1006 unsigned long flags
= 0;
1007 struct net_device
*netdev
= adapter
->netdev
;
1008 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1010 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
1011 handler
= netxen_msix_intr
;
1012 else if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
1013 handler
= netxen_msi_intr
;
1015 flags
|= IRQF_SHARED
;
1016 handler
= netxen_intr
;
1018 adapter
->irq
= netdev
->irq
;
1020 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1021 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1022 sprintf(sds_ring
->name
, "%s[%d]", netdev
->name
, ring
);
1023 err
= request_irq(sds_ring
->irq
, handler
,
1024 flags
, sds_ring
->name
, sds_ring
);
1033 netxen_nic_free_irq(struct netxen_adapter
*adapter
)
1036 struct nx_host_sds_ring
*sds_ring
;
1038 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1040 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1041 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1042 free_irq(sds_ring
->irq
, sds_ring
);
1047 netxen_nic_init_coalesce_defaults(struct netxen_adapter
*adapter
)
1049 adapter
->coal
.flags
= NETXEN_NIC_INTR_DEFAULT
;
1050 adapter
->coal
.normal
.data
.rx_time_us
=
1051 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US
;
1052 adapter
->coal
.normal
.data
.rx_packets
=
1053 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS
;
1054 adapter
->coal
.normal
.data
.tx_time_us
=
1055 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US
;
1056 adapter
->coal
.normal
.data
.tx_packets
=
1057 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS
;
1060 /* with rtnl_lock */
1062 __netxen_nic_up(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1066 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1069 err
= adapter
->init_port(adapter
, adapter
->physical_port
);
1071 printk(KERN_ERR
"%s: Failed to initialize port %d\n",
1072 netxen_nic_driver_name
, adapter
->portnum
);
1075 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1076 adapter
->macaddr_set(adapter
, adapter
->mac_addr
);
1078 adapter
->set_multi(netdev
);
1079 adapter
->set_mtu(adapter
, netdev
->mtu
);
1081 adapter
->ahw
.linkup
= 0;
1083 if (adapter
->max_sds_rings
> 1)
1084 netxen_config_rss(adapter
, 1);
1086 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1087 netxen_config_intr_coalesce(adapter
);
1089 if (netdev
->features
& NETIF_F_LRO
)
1090 netxen_config_hw_lro(adapter
, NETXEN_NIC_LRO_ENABLED
);
1092 netxen_napi_enable(adapter
);
1094 if (adapter
->capabilities
& NX_FW_CAPABILITY_LINK_NOTIFICATION
)
1095 netxen_linkevent_request(adapter
, 1);
1097 netxen_nic_set_link_parameters(adapter
);
1099 set_bit(__NX_DEV_UP
, &adapter
->state
);
1103 /* Usage: During resume and firmware recovery module.*/
1106 netxen_nic_up(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1111 if (netif_running(netdev
))
1112 err
= __netxen_nic_up(adapter
, netdev
);
1118 /* with rtnl_lock */
1120 __netxen_nic_down(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1122 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1125 if (!test_and_clear_bit(__NX_DEV_UP
, &adapter
->state
))
1129 spin_lock(&adapter
->tx_clean_lock
);
1130 netif_carrier_off(netdev
);
1131 netif_tx_disable(netdev
);
1133 if (adapter
->capabilities
& NX_FW_CAPABILITY_LINK_NOTIFICATION
)
1134 netxen_linkevent_request(adapter
, 0);
1136 if (adapter
->stop_port
)
1137 adapter
->stop_port(adapter
);
1139 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1140 netxen_p3_free_mac_list(adapter
);
1142 adapter
->set_promisc(adapter
, NETXEN_NIU_NON_PROMISC_MODE
);
1144 netxen_napi_disable(adapter
);
1146 netxen_release_tx_buffers(adapter
);
1147 spin_unlock(&adapter
->tx_clean_lock
);
1150 /* Usage: During suspend and firmware recovery module */
1153 netxen_nic_down(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1156 if (netif_running(netdev
))
1157 __netxen_nic_down(adapter
, netdev
);
1163 netxen_nic_attach(struct netxen_adapter
*adapter
)
1165 struct net_device
*netdev
= adapter
->netdev
;
1166 struct pci_dev
*pdev
= adapter
->pdev
;
1168 struct nx_host_rds_ring
*rds_ring
;
1169 struct nx_host_tx_ring
*tx_ring
;
1171 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
)
1174 err
= netxen_init_firmware(adapter
);
1178 err
= netxen_napi_add(adapter
, netdev
);
1182 err
= netxen_alloc_sw_resources(adapter
);
1184 printk(KERN_ERR
"%s: Error in setting sw resources\n",
1189 err
= netxen_alloc_hw_resources(adapter
);
1191 printk(KERN_ERR
"%s: Error in setting hw resources\n",
1193 goto err_out_free_sw
;
1196 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1197 tx_ring
= adapter
->tx_ring
;
1198 tx_ring
->crb_cmd_producer
= netxen_get_ioaddr(adapter
,
1199 crb_cmd_producer
[adapter
->portnum
]);
1200 tx_ring
->crb_cmd_consumer
= netxen_get_ioaddr(adapter
,
1201 crb_cmd_consumer
[adapter
->portnum
]);
1203 tx_ring
->producer
= 0;
1204 tx_ring
->sw_consumer
= 0;
1206 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
1207 netxen_nic_update_cmd_consumer(adapter
, tx_ring
);
1210 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1211 rds_ring
= &adapter
->recv_ctx
.rds_rings
[ring
];
1212 netxen_post_rx_buffers(adapter
, ring
, rds_ring
);
1215 err
= netxen_nic_request_irq(adapter
);
1217 dev_err(&pdev
->dev
, "%s: failed to setup interrupt\n",
1219 goto err_out_free_rxbuf
;
1222 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1223 netxen_nic_init_coalesce_defaults(adapter
);
1225 netxen_create_sysfs_entries(adapter
);
1227 adapter
->is_up
= NETXEN_ADAPTER_UP_MAGIC
;
1231 netxen_release_rx_buffers(adapter
);
1232 netxen_free_hw_resources(adapter
);
1234 netxen_free_sw_resources(adapter
);
1239 netxen_nic_detach(struct netxen_adapter
*adapter
)
1241 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1244 netxen_remove_sysfs_entries(adapter
);
1246 netxen_free_hw_resources(adapter
);
1247 netxen_release_rx_buffers(adapter
);
1248 netxen_nic_free_irq(adapter
);
1249 netxen_napi_del(adapter
);
1250 netxen_free_sw_resources(adapter
);
1256 netxen_nic_reset_context(struct netxen_adapter
*adapter
)
1259 struct net_device
*netdev
= adapter
->netdev
;
1261 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
1264 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
) {
1266 netif_device_detach(netdev
);
1268 if (netif_running(netdev
))
1269 __netxen_nic_down(adapter
, netdev
);
1271 netxen_nic_detach(adapter
);
1273 if (netif_running(netdev
)) {
1274 err
= netxen_nic_attach(adapter
);
1276 err
= __netxen_nic_up(adapter
, netdev
);
1282 netif_device_attach(netdev
);
1286 clear_bit(__NX_RESETTING
, &adapter
->state
);
1291 netxen_setup_netdev(struct netxen_adapter
*adapter
,
1292 struct net_device
*netdev
)
1295 struct pci_dev
*pdev
= adapter
->pdev
;
1297 adapter
->mc_enabled
= 0;
1298 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1299 adapter
->max_mc_count
= 38;
1301 adapter
->max_mc_count
= 16;
1303 netdev
->netdev_ops
= &netxen_netdev_ops
;
1304 netdev
->watchdog_timeo
= 5*HZ
;
1306 netxen_nic_change_mtu(netdev
, netdev
->mtu
);
1308 SET_ETHTOOL_OPS(netdev
, &netxen_nic_ethtool_ops
);
1310 netdev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_TSO
|
1313 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1314 netdev
->hw_features
|= NETIF_F_IPV6_CSUM
| NETIF_F_TSO6
;
1316 netdev
->vlan_features
|= netdev
->hw_features
;
1318 if (adapter
->pci_using_dac
) {
1319 netdev
->features
|= NETIF_F_HIGHDMA
;
1320 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
1323 if (adapter
->capabilities
& NX_FW_CAPABILITY_FVLANTX
)
1324 netdev
->hw_features
|= NETIF_F_HW_VLAN_TX
;
1326 if (adapter
->capabilities
& NX_FW_CAPABILITY_HW_LRO
)
1327 netdev
->hw_features
|= NETIF_F_LRO
;
1329 netdev
->features
|= netdev
->hw_features
;
1331 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1333 INIT_WORK(&adapter
->tx_timeout_task
, netxen_tx_timeout_task
);
1335 if (netxen_read_mac_addr(adapter
))
1336 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1338 netif_carrier_off(netdev
);
1340 err
= register_netdev(netdev
);
1342 dev_err(&pdev
->dev
, "failed to register net device\n");
1349 #ifdef CONFIG_PCIEAER
1350 static void netxen_mask_aer_correctable(struct netxen_adapter
*adapter
)
1352 struct pci_dev
*pdev
= adapter
->pdev
;
1353 struct pci_dev
*root
= pdev
->bus
->self
;
1356 if (adapter
->ahw
.board_type
!= NETXEN_BRDTYPE_P3_4_GB_MM
&&
1357 adapter
->ahw
.board_type
!= NETXEN_BRDTYPE_P3_10G_TP
)
1360 if (root
->pcie_type
!= PCI_EXP_TYPE_ROOT_PORT
)
1363 aer_pos
= pci_find_ext_capability(root
, PCI_EXT_CAP_ID_ERR
);
1367 pci_write_config_dword(root
, aer_pos
+ PCI_ERR_COR_MASK
, 0xffff);
1371 static int __devinit
1372 netxen_nic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1374 struct net_device
*netdev
= NULL
;
1375 struct netxen_adapter
*adapter
= NULL
;
1377 int pci_func_id
= PCI_FUNC(pdev
->devfn
);
1378 uint8_t revision_id
;
1381 if (pdev
->revision
>= NX_P3_A0
&& pdev
->revision
<= NX_P3_B1
) {
1382 pr_warning("%s: chip revisions between 0x%x-0x%x "
1383 "will not be enabled.\n",
1384 module_name(THIS_MODULE
), NX_P3_A0
, NX_P3_B1
);
1388 if ((err
= pci_enable_device(pdev
)))
1391 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1393 goto err_out_disable_pdev
;
1396 if ((err
= pci_request_regions(pdev
, netxen_nic_driver_name
)))
1397 goto err_out_disable_pdev
;
1399 if (NX_IS_REVISION_P3(pdev
->revision
))
1400 pci_enable_pcie_error_reporting(pdev
);
1402 pci_set_master(pdev
);
1404 netdev
= alloc_etherdev(sizeof(struct netxen_adapter
));
1406 dev_err(&pdev
->dev
, "failed to allocate net_device\n");
1408 goto err_out_free_res
;
1411 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1413 adapter
= netdev_priv(netdev
);
1414 adapter
->netdev
= netdev
;
1415 adapter
->pdev
= pdev
;
1416 adapter
->ahw
.pci_func
= pci_func_id
;
1418 revision_id
= pdev
->revision
;
1419 adapter
->ahw
.revision_id
= revision_id
;
1421 rwlock_init(&adapter
->ahw
.crb_lock
);
1422 spin_lock_init(&adapter
->ahw
.mem_lock
);
1424 spin_lock_init(&adapter
->tx_clean_lock
);
1425 INIT_LIST_HEAD(&adapter
->mac_list
);
1426 INIT_LIST_HEAD(&adapter
->vlan_ip_list
);
1428 err
= netxen_setup_pci_map(adapter
);
1430 goto err_out_free_netdev
;
1432 /* This will be reset for mezz cards */
1433 adapter
->portnum
= pci_func_id
;
1435 err
= netxen_nic_get_board_info(adapter
);
1437 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1438 goto err_out_iounmap
;
1441 #ifdef CONFIG_PCIEAER
1442 netxen_mask_aer_correctable(adapter
);
1445 /* Mezz cards have PCI function 0,2,3 enabled */
1446 switch (adapter
->ahw
.board_type
) {
1447 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
1448 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
1449 if (pci_func_id
>= 2)
1450 adapter
->portnum
= pci_func_id
- 2;
1456 err
= netxen_check_flash_fw_compatibility(adapter
);
1458 goto err_out_iounmap
;
1460 if (adapter
->portnum
== 0) {
1461 val
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
1462 if (val
!= 0xffffffff && val
!= 0) {
1463 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, 0);
1464 adapter
->need_fw_reset
= 1;
1468 err
= netxen_start_firmware(adapter
);
1470 goto err_out_decr_ref
;
1473 * See if the firmware gave us a virtual-physical port mapping.
1475 adapter
->physical_port
= adapter
->portnum
;
1476 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1477 i
= NXRD32(adapter
, CRB_V2P(adapter
->portnum
));
1478 if (i
!= 0x55555555)
1479 adapter
->physical_port
= i
;
1482 netxen_nic_clear_stats(adapter
);
1484 netxen_setup_intr(adapter
);
1486 err
= netxen_setup_netdev(adapter
, netdev
);
1488 goto err_out_disable_msi
;
1490 pci_set_drvdata(pdev
, adapter
);
1492 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1494 switch (adapter
->ahw
.port_type
) {
1495 case NETXEN_NIC_GBE
:
1496 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1497 adapter
->netdev
->name
);
1499 case NETXEN_NIC_XGBE
:
1500 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1501 adapter
->netdev
->name
);
1505 netxen_create_diag_entries(adapter
);
1509 err_out_disable_msi
:
1510 netxen_teardown_intr(adapter
);
1512 netxen_free_dummy_dma(adapter
);
1515 nx_decr_dev_ref_cnt(adapter
);
1518 netxen_cleanup_pci_map(adapter
);
1520 err_out_free_netdev
:
1521 free_netdev(netdev
);
1524 pci_release_regions(pdev
);
1526 err_out_disable_pdev
:
1527 pci_set_drvdata(pdev
, NULL
);
1528 pci_disable_device(pdev
);
1532 static void __devexit
netxen_nic_remove(struct pci_dev
*pdev
)
1534 struct netxen_adapter
*adapter
;
1535 struct net_device
*netdev
;
1537 adapter
= pci_get_drvdata(pdev
);
1538 if (adapter
== NULL
)
1541 netdev
= adapter
->netdev
;
1543 netxen_cancel_fw_work(adapter
);
1545 unregister_netdev(netdev
);
1547 cancel_work_sync(&adapter
->tx_timeout_task
);
1549 netxen_free_vlan_ip_list(adapter
);
1550 netxen_nic_detach(adapter
);
1552 nx_decr_dev_ref_cnt(adapter
);
1554 if (adapter
->portnum
== 0)
1555 netxen_free_dummy_dma(adapter
);
1557 clear_bit(__NX_RESETTING
, &adapter
->state
);
1559 netxen_teardown_intr(adapter
);
1561 netxen_remove_diag_entries(adapter
);
1563 netxen_cleanup_pci_map(adapter
);
1565 netxen_release_firmware(adapter
);
1567 if (NX_IS_REVISION_P3(pdev
->revision
))
1568 pci_disable_pcie_error_reporting(pdev
);
1570 pci_release_regions(pdev
);
1571 pci_disable_device(pdev
);
1572 pci_set_drvdata(pdev
, NULL
);
1574 free_netdev(netdev
);
1577 static void netxen_nic_detach_func(struct netxen_adapter
*adapter
)
1579 struct net_device
*netdev
= adapter
->netdev
;
1581 netif_device_detach(netdev
);
1583 netxen_cancel_fw_work(adapter
);
1585 if (netif_running(netdev
))
1586 netxen_nic_down(adapter
, netdev
);
1588 cancel_work_sync(&adapter
->tx_timeout_task
);
1590 netxen_nic_detach(adapter
);
1592 if (adapter
->portnum
== 0)
1593 netxen_free_dummy_dma(adapter
);
1595 nx_decr_dev_ref_cnt(adapter
);
1597 clear_bit(__NX_RESETTING
, &adapter
->state
);
1600 static int netxen_nic_attach_func(struct pci_dev
*pdev
)
1602 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1603 struct net_device
*netdev
= adapter
->netdev
;
1606 err
= pci_enable_device(pdev
);
1610 pci_set_power_state(pdev
, PCI_D0
);
1611 pci_set_master(pdev
);
1612 pci_restore_state(pdev
);
1614 adapter
->ahw
.crb_win
= -1;
1615 adapter
->ahw
.ocm_win
= -1;
1617 err
= netxen_start_firmware(adapter
);
1619 dev_err(&pdev
->dev
, "failed to start firmware\n");
1623 if (netif_running(netdev
)) {
1624 err
= netxen_nic_attach(adapter
);
1628 err
= netxen_nic_up(adapter
, netdev
);
1630 goto err_out_detach
;
1632 netxen_restore_indev_addr(netdev
, NETDEV_UP
);
1635 netif_device_attach(netdev
);
1636 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1640 netxen_nic_detach(adapter
);
1642 nx_decr_dev_ref_cnt(adapter
);
1646 static pci_ers_result_t
netxen_io_error_detected(struct pci_dev
*pdev
,
1647 pci_channel_state_t state
)
1649 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1651 if (state
== pci_channel_io_perm_failure
)
1652 return PCI_ERS_RESULT_DISCONNECT
;
1654 if (nx_dev_request_aer(adapter
))
1655 return PCI_ERS_RESULT_RECOVERED
;
1657 netxen_nic_detach_func(adapter
);
1659 pci_disable_device(pdev
);
1661 return PCI_ERS_RESULT_NEED_RESET
;
1664 static pci_ers_result_t
netxen_io_slot_reset(struct pci_dev
*pdev
)
1668 err
= netxen_nic_attach_func(pdev
);
1670 return err
? PCI_ERS_RESULT_DISCONNECT
: PCI_ERS_RESULT_RECOVERED
;
1673 static void netxen_io_resume(struct pci_dev
*pdev
)
1675 pci_cleanup_aer_uncorrect_error_status(pdev
);
1678 static void netxen_nic_shutdown(struct pci_dev
*pdev
)
1680 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1682 netxen_nic_detach_func(adapter
);
1684 if (pci_save_state(pdev
))
1687 if (netxen_nic_wol_supported(adapter
)) {
1688 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1689 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1692 pci_disable_device(pdev
);
1697 netxen_nic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1699 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1702 netxen_nic_detach_func(adapter
);
1704 retval
= pci_save_state(pdev
);
1708 if (netxen_nic_wol_supported(adapter
)) {
1709 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1710 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1713 pci_disable_device(pdev
);
1714 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1720 netxen_nic_resume(struct pci_dev
*pdev
)
1722 return netxen_nic_attach_func(pdev
);
1726 static int netxen_nic_open(struct net_device
*netdev
)
1728 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1731 if (adapter
->driver_mismatch
)
1734 err
= netxen_nic_attach(adapter
);
1738 err
= __netxen_nic_up(adapter
, netdev
);
1742 netif_start_queue(netdev
);
1747 netxen_nic_detach(adapter
);
1752 * netxen_nic_close - Disables a network interface entry point
1754 static int netxen_nic_close(struct net_device
*netdev
)
1756 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1758 __netxen_nic_down(adapter
, netdev
);
1763 netxen_tso_check(struct net_device
*netdev
,
1764 struct nx_host_tx_ring
*tx_ring
,
1765 struct cmd_desc_type0
*first_desc
,
1766 struct sk_buff
*skb
)
1768 u8 opcode
= TX_ETHER_PKT
;
1769 __be16 protocol
= skb
->protocol
;
1770 u16 flags
= 0, vid
= 0;
1772 int copied
, offset
, copy_len
, hdr_len
= 0, tso
= 0, vlan_oob
= 0;
1773 struct cmd_desc_type0
*hwdesc
;
1774 struct vlan_ethhdr
*vh
;
1776 if (protocol
== cpu_to_be16(ETH_P_8021Q
)) {
1778 vh
= (struct vlan_ethhdr
*)skb
->data
;
1779 protocol
= vh
->h_vlan_encapsulated_proto
;
1780 flags
= FLAGS_VLAN_TAGGED
;
1782 } else if (vlan_tx_tag_present(skb
)) {
1784 flags
= FLAGS_VLAN_OOB
;
1785 vid
= vlan_tx_tag_get(skb
);
1786 netxen_set_tx_vlan_tci(first_desc
, vid
);
1790 if ((netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
1791 skb_shinfo(skb
)->gso_size
> 0) {
1793 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
1795 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
1796 first_desc
->total_hdr_length
= hdr_len
;
1798 first_desc
->total_hdr_length
+= VLAN_HLEN
;
1799 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
1800 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
1801 /* Only in case of TSO on vlan device */
1802 flags
|= FLAGS_VLAN_TAGGED
;
1805 opcode
= (protocol
== cpu_to_be16(ETH_P_IPV6
)) ?
1806 TX_TCP_LSO6
: TX_TCP_LSO
;
1809 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1812 if (protocol
== cpu_to_be16(ETH_P_IP
)) {
1813 l4proto
= ip_hdr(skb
)->protocol
;
1815 if (l4proto
== IPPROTO_TCP
)
1816 opcode
= TX_TCP_PKT
;
1817 else if(l4proto
== IPPROTO_UDP
)
1818 opcode
= TX_UDP_PKT
;
1819 } else if (protocol
== cpu_to_be16(ETH_P_IPV6
)) {
1820 l4proto
= ipv6_hdr(skb
)->nexthdr
;
1822 if (l4proto
== IPPROTO_TCP
)
1823 opcode
= TX_TCPV6_PKT
;
1824 else if(l4proto
== IPPROTO_UDP
)
1825 opcode
= TX_UDPV6_PKT
;
1829 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
1830 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
1831 netxen_set_tx_flags_opcode(first_desc
, flags
, opcode
);
1836 /* For LSO, we need to copy the MAC/IP/TCP headers into
1837 * the descriptor ring
1839 producer
= tx_ring
->producer
;
1844 /* Create a TSO vlan header template for firmware */
1846 hwdesc
= &tx_ring
->desc_head
[producer
];
1847 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1849 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1850 hdr_len
+ VLAN_HLEN
);
1852 vh
= (struct vlan_ethhdr
*)((char *)hwdesc
+ 2);
1853 skb_copy_from_linear_data(skb
, vh
, 12);
1854 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
1855 vh
->h_vlan_TCI
= htons(vid
);
1856 skb_copy_from_linear_data_offset(skb
, 12,
1857 (char *)vh
+ 16, copy_len
- 16);
1859 copied
= copy_len
- VLAN_HLEN
;
1862 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1865 while (copied
< hdr_len
) {
1867 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1868 (hdr_len
- copied
));
1870 hwdesc
= &tx_ring
->desc_head
[producer
];
1871 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1873 skb_copy_from_linear_data_offset(skb
, copied
,
1874 (char *)hwdesc
+ offset
, copy_len
);
1879 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1882 tx_ring
->producer
= producer
;
1887 netxen_map_tx_skb(struct pci_dev
*pdev
,
1888 struct sk_buff
*skb
, struct netxen_cmd_buffer
*pbuf
)
1890 struct netxen_skb_frag
*nf
;
1891 struct skb_frag_struct
*frag
;
1895 nr_frags
= skb_shinfo(skb
)->nr_frags
;
1896 nf
= &pbuf
->frag_array
[0];
1898 map
= pci_map_single(pdev
, skb
->data
,
1899 skb_headlen(skb
), PCI_DMA_TODEVICE
);
1900 if (pci_dma_mapping_error(pdev
, map
))
1904 nf
->length
= skb_headlen(skb
);
1906 for (i
= 0; i
< nr_frags
; i
++) {
1907 frag
= &skb_shinfo(skb
)->frags
[i
];
1908 nf
= &pbuf
->frag_array
[i
+1];
1910 map
= skb_frag_dma_map(&pdev
->dev
, frag
, 0, skb_frag_size(frag
),
1912 if (dma_mapping_error(&pdev
->dev
, map
))
1916 nf
->length
= skb_frag_size(frag
);
1923 nf
= &pbuf
->frag_array
[i
+1];
1924 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
1927 nf
= &pbuf
->frag_array
[0];
1928 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
1935 netxen_clear_cmddesc(u64
*desc
)
1942 netxen_nic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
1944 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1945 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1946 struct netxen_cmd_buffer
*pbuf
;
1947 struct netxen_skb_frag
*buffrag
;
1948 struct cmd_desc_type0
*hwdesc
, *first_desc
;
1949 struct pci_dev
*pdev
;
1952 struct skb_frag_struct
*frag
;
1955 int frag_count
, no_of_desc
;
1956 u32 num_txd
= tx_ring
->num_desc
;
1958 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
1960 /* 14 frags supported for normal packet and
1961 * 32 frags supported for TSO packet
1963 if (!skb_is_gso(skb
) && frag_count
> NETXEN_MAX_FRAGS_PER_TX
) {
1965 for (i
= 0; i
< (frag_count
- NETXEN_MAX_FRAGS_PER_TX
); i
++) {
1966 frag
= &skb_shinfo(skb
)->frags
[i
];
1967 delta
+= skb_frag_size(frag
);
1970 if (!__pskb_pull_tail(skb
, delta
))
1973 frag_count
= 1 + skb_shinfo(skb
)->nr_frags
;
1975 /* 4 fragments per cmd des */
1976 no_of_desc
= (frag_count
+ 3) >> 2;
1978 if (unlikely(netxen_tx_avail(tx_ring
) <= TX_STOP_THRESH
)) {
1979 netif_stop_queue(netdev
);
1981 if (netxen_tx_avail(tx_ring
) > TX_STOP_THRESH
)
1982 netif_start_queue(netdev
);
1984 return NETDEV_TX_BUSY
;
1987 producer
= tx_ring
->producer
;
1988 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
1990 pdev
= adapter
->pdev
;
1992 if (netxen_map_tx_skb(pdev
, skb
, pbuf
))
1996 pbuf
->frag_count
= frag_count
;
1998 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
1999 netxen_clear_cmddesc((u64
*)hwdesc
);
2001 netxen_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
2002 netxen_set_tx_port(first_desc
, adapter
->portnum
);
2004 for (i
= 0; i
< frag_count
; i
++) {
2008 if ((k
== 0) && (i
> 0)) {
2009 /* move to next desc.*/
2010 producer
= get_next_index(producer
, num_txd
);
2011 hwdesc
= &tx_ring
->desc_head
[producer
];
2012 netxen_clear_cmddesc((u64
*)hwdesc
);
2013 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2016 buffrag
= &pbuf
->frag_array
[i
];
2018 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
2021 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
2024 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
2027 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
2030 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
2035 tx_ring
->producer
= get_next_index(producer
, num_txd
);
2037 netxen_tso_check(netdev
, tx_ring
, first_desc
, skb
);
2039 adapter
->stats
.txbytes
+= skb
->len
;
2040 adapter
->stats
.xmitcalled
++;
2042 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
2044 return NETDEV_TX_OK
;
2047 adapter
->stats
.txdropped
++;
2048 dev_kfree_skb_any(skb
);
2049 return NETDEV_TX_OK
;
2052 static int netxen_nic_check_temp(struct netxen_adapter
*adapter
)
2054 struct net_device
*netdev
= adapter
->netdev
;
2055 uint32_t temp
, temp_state
, temp_val
;
2058 temp
= NXRD32(adapter
, CRB_TEMP_STATE
);
2060 temp_state
= nx_get_temp_state(temp
);
2061 temp_val
= nx_get_temp_val(temp
);
2063 if (temp_state
== NX_TEMP_PANIC
) {
2065 "%s: Device temperature %d degrees C exceeds"
2066 " maximum allowed. Hardware has been shut down.\n",
2067 netdev
->name
, temp_val
);
2069 } else if (temp_state
== NX_TEMP_WARN
) {
2070 if (adapter
->temp
== NX_TEMP_NORMAL
) {
2072 "%s: Device temperature %d degrees C "
2073 "exceeds operating range."
2074 " Immediate action needed.\n",
2075 netdev
->name
, temp_val
);
2078 if (adapter
->temp
== NX_TEMP_WARN
) {
2080 "%s: Device temperature is now %d degrees C"
2081 " in normal range.\n", netdev
->name
,
2085 adapter
->temp
= temp_state
;
2089 void netxen_advert_link_change(struct netxen_adapter
*adapter
, int linkup
)
2091 struct net_device
*netdev
= adapter
->netdev
;
2093 if (adapter
->ahw
.linkup
&& !linkup
) {
2094 printk(KERN_INFO
"%s: %s NIC Link is down\n",
2095 netxen_nic_driver_name
, netdev
->name
);
2096 adapter
->ahw
.linkup
= 0;
2097 if (netif_running(netdev
)) {
2098 netif_carrier_off(netdev
);
2099 netif_stop_queue(netdev
);
2101 adapter
->link_changed
= !adapter
->has_link_events
;
2102 } else if (!adapter
->ahw
.linkup
&& linkup
) {
2103 printk(KERN_INFO
"%s: %s NIC Link is up\n",
2104 netxen_nic_driver_name
, netdev
->name
);
2105 adapter
->ahw
.linkup
= 1;
2106 if (netif_running(netdev
)) {
2107 netif_carrier_on(netdev
);
2108 netif_wake_queue(netdev
);
2110 adapter
->link_changed
= !adapter
->has_link_events
;
2114 static void netxen_nic_handle_phy_intr(struct netxen_adapter
*adapter
)
2116 u32 val
, port
, linkup
;
2118 port
= adapter
->physical_port
;
2120 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
2121 val
= NXRD32(adapter
, CRB_XG_STATE_P3
);
2122 val
= XG_LINK_STATE_P3(adapter
->ahw
.pci_func
, val
);
2123 linkup
= (val
== XG_LINK_UP_P3
);
2125 val
= NXRD32(adapter
, CRB_XG_STATE
);
2126 val
= (val
>> port
*8) & 0xff;
2127 linkup
= (val
== XG_LINK_UP
);
2130 netxen_advert_link_change(adapter
, linkup
);
2133 static void netxen_tx_timeout(struct net_device
*netdev
)
2135 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2137 if (test_bit(__NX_RESETTING
, &adapter
->state
))
2140 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
2141 schedule_work(&adapter
->tx_timeout_task
);
2144 static void netxen_tx_timeout_task(struct work_struct
*work
)
2146 struct netxen_adapter
*adapter
=
2147 container_of(work
, struct netxen_adapter
, tx_timeout_task
);
2149 if (!netif_running(adapter
->netdev
))
2152 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2155 if (++adapter
->tx_timeo_cnt
>= NX_MAX_TX_TIMEOUTS
)
2159 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
2160 /* try to scrub interrupt */
2161 netxen_napi_disable(adapter
);
2163 netxen_napi_enable(adapter
);
2165 netif_wake_queue(adapter
->netdev
);
2167 clear_bit(__NX_RESETTING
, &adapter
->state
);
2169 clear_bit(__NX_RESETTING
, &adapter
->state
);
2170 if (netxen_nic_reset_context(adapter
)) {
2175 adapter
->netdev
->trans_start
= jiffies
;
2180 adapter
->need_fw_reset
= 1;
2181 clear_bit(__NX_RESETTING
, &adapter
->state
);
2184 static struct rtnl_link_stats64
*netxen_nic_get_stats(struct net_device
*netdev
,
2185 struct rtnl_link_stats64
*stats
)
2187 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2189 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
2190 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
2191 stats
->rx_bytes
= adapter
->stats
.rxbytes
;
2192 stats
->tx_bytes
= adapter
->stats
.txbytes
;
2193 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
2194 stats
->tx_dropped
= adapter
->stats
.txdropped
;
2199 static irqreturn_t
netxen_intr(int irq
, void *data
)
2201 struct nx_host_sds_ring
*sds_ring
= data
;
2202 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2205 status
= readl(adapter
->isr_int_vec
);
2207 if (!(status
& adapter
->int_vec_bit
))
2210 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
2211 /* check interrupt state machine, to be sure */
2212 status
= readl(adapter
->crb_int_state_reg
);
2213 if (!ISR_LEGACY_INT_TRIGGERED(status
))
2217 unsigned long our_int
= 0;
2219 our_int
= readl(adapter
->crb_int_state_reg
);
2221 /* not our interrupt */
2222 if (!test_and_clear_bit((7 + adapter
->portnum
), &our_int
))
2225 /* claim interrupt */
2226 writel((our_int
& 0xffffffff), adapter
->crb_int_state_reg
);
2228 /* clear interrupt */
2229 netxen_nic_disable_int(sds_ring
);
2232 writel(0xffffffff, adapter
->tgt_status_reg
);
2233 /* read twice to ensure write is flushed */
2234 readl(adapter
->isr_int_vec
);
2235 readl(adapter
->isr_int_vec
);
2237 napi_schedule(&sds_ring
->napi
);
2242 static irqreturn_t
netxen_msi_intr(int irq
, void *data
)
2244 struct nx_host_sds_ring
*sds_ring
= data
;
2245 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2247 /* clear interrupt */
2248 writel(0xffffffff, adapter
->tgt_status_reg
);
2250 napi_schedule(&sds_ring
->napi
);
2254 static irqreturn_t
netxen_msix_intr(int irq
, void *data
)
2256 struct nx_host_sds_ring
*sds_ring
= data
;
2258 napi_schedule(&sds_ring
->napi
);
2262 static int netxen_nic_poll(struct napi_struct
*napi
, int budget
)
2264 struct nx_host_sds_ring
*sds_ring
=
2265 container_of(napi
, struct nx_host_sds_ring
, napi
);
2267 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2272 tx_complete
= netxen_process_cmd_ring(adapter
);
2274 work_done
= netxen_process_rcv_ring(sds_ring
, budget
);
2276 if ((work_done
< budget
) && tx_complete
) {
2277 napi_complete(&sds_ring
->napi
);
2278 if (test_bit(__NX_DEV_UP
, &adapter
->state
))
2279 netxen_nic_enable_int(sds_ring
);
2285 #ifdef CONFIG_NET_POLL_CONTROLLER
2286 static void netxen_nic_poll_controller(struct net_device
*netdev
)
2289 struct nx_host_sds_ring
*sds_ring
;
2290 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2291 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
2293 disable_irq(adapter
->irq
);
2294 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
2295 sds_ring
= &recv_ctx
->sds_rings
[ring
];
2296 netxen_intr(adapter
->irq
, sds_ring
);
2298 enable_irq(adapter
->irq
);
2303 nx_incr_dev_ref_cnt(struct netxen_adapter
*adapter
)
2306 if (netxen_api_lock(adapter
))
2309 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2311 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, ++count
);
2313 netxen_api_unlock(adapter
);
2318 nx_decr_dev_ref_cnt(struct netxen_adapter
*adapter
)
2321 if (netxen_api_lock(adapter
))
2324 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2325 WARN_ON(count
== 0);
2327 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, --count
);
2330 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_COLD
);
2332 netxen_api_unlock(adapter
);
2337 nx_dev_request_aer(struct netxen_adapter
*adapter
)
2342 if (netxen_api_lock(adapter
))
2345 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2347 if (state
== NX_DEV_NEED_AER
)
2349 else if (state
== NX_DEV_READY
) {
2350 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_NEED_AER
);
2354 netxen_api_unlock(adapter
);
2359 nx_dev_request_reset(struct netxen_adapter
*adapter
)
2364 if (netxen_api_lock(adapter
))
2367 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2369 if (state
== NX_DEV_NEED_RESET
)
2371 else if (state
!= NX_DEV_INITALIZING
&& state
!= NX_DEV_NEED_AER
) {
2372 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_NEED_RESET
);
2376 netxen_api_unlock(adapter
);
2382 netxen_can_start_firmware(struct netxen_adapter
*adapter
)
2387 if (netxen_api_lock(adapter
))
2390 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2392 if ((count
< 0) || (count
>= NX_MAX_PCI_FUNC
))
2397 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_INITALIZING
);
2400 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, ++count
);
2402 netxen_api_unlock(adapter
);
2408 netxen_schedule_work(struct netxen_adapter
*adapter
,
2409 work_func_t func
, int delay
)
2411 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
2412 schedule_delayed_work(&adapter
->fw_work
, delay
);
2416 netxen_cancel_fw_work(struct netxen_adapter
*adapter
)
2418 while (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2421 cancel_delayed_work_sync(&adapter
->fw_work
);
2425 netxen_attach_work(struct work_struct
*work
)
2427 struct netxen_adapter
*adapter
= container_of(work
,
2428 struct netxen_adapter
, fw_work
.work
);
2429 struct net_device
*netdev
= adapter
->netdev
;
2432 if (netif_running(netdev
)) {
2433 err
= netxen_nic_attach(adapter
);
2437 err
= netxen_nic_up(adapter
, netdev
);
2439 netxen_nic_detach(adapter
);
2443 netxen_restore_indev_addr(netdev
, NETDEV_UP
);
2446 netif_device_attach(netdev
);
2449 adapter
->fw_fail_cnt
= 0;
2450 clear_bit(__NX_RESETTING
, &adapter
->state
);
2451 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
2455 netxen_fwinit_work(struct work_struct
*work
)
2457 struct netxen_adapter
*adapter
= container_of(work
,
2458 struct netxen_adapter
, fw_work
.work
);
2461 dev_state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2463 switch (dev_state
) {
2466 if (!netxen_start_firmware(adapter
)) {
2467 netxen_schedule_work(adapter
, netxen_attach_work
, 0);
2472 case NX_DEV_NEED_RESET
:
2473 case NX_DEV_INITALIZING
:
2474 if (++adapter
->fw_wait_cnt
< FW_POLL_THRESH
) {
2475 netxen_schedule_work(adapter
,
2476 netxen_fwinit_work
, 2 * FW_POLL_DELAY
);
2482 nx_incr_dev_ref_cnt(adapter
);
2486 clear_bit(__NX_RESETTING
, &adapter
->state
);
2490 netxen_detach_work(struct work_struct
*work
)
2492 struct netxen_adapter
*adapter
= container_of(work
,
2493 struct netxen_adapter
, fw_work
.work
);
2494 struct net_device
*netdev
= adapter
->netdev
;
2498 netif_device_detach(netdev
);
2500 netxen_nic_down(adapter
, netdev
);
2503 netxen_nic_detach(adapter
);
2506 status
= NXRD32(adapter
, NETXEN_PEG_HALT_STATUS1
);
2508 if (status
& NX_RCODE_FATAL_ERROR
)
2511 if (adapter
->temp
== NX_TEMP_PANIC
)
2514 ref_cnt
= nx_decr_dev_ref_cnt(adapter
);
2516 if (ref_cnt
== -EIO
)
2519 delay
= (ref_cnt
== 0) ? 0 : (2 * FW_POLL_DELAY
);
2521 adapter
->fw_wait_cnt
= 0;
2522 netxen_schedule_work(adapter
, netxen_fwinit_work
, delay
);
2527 clear_bit(__NX_RESETTING
, &adapter
->state
);
2531 netxen_check_health(struct netxen_adapter
*adapter
)
2533 u32 state
, heartbit
;
2534 struct net_device
*netdev
= adapter
->netdev
;
2536 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2537 if (state
== NX_DEV_NEED_AER
)
2540 if (netxen_nic_check_temp(adapter
))
2543 if (adapter
->need_fw_reset
) {
2544 if (nx_dev_request_reset(adapter
))
2549 /* NX_DEV_NEED_RESET, this state can be marked in two cases
2550 * 1. Tx timeout 2. Fw hang
2551 * Send request to destroy context in case of tx timeout only
2552 * and doesn't required in case of Fw hang
2554 if (state
== NX_DEV_NEED_RESET
) {
2555 adapter
->need_fw_reset
= 1;
2556 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2560 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2563 heartbit
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
2564 if (heartbit
!= adapter
->heartbit
) {
2565 adapter
->heartbit
= heartbit
;
2566 adapter
->fw_fail_cnt
= 0;
2567 if (adapter
->need_fw_reset
)
2572 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
2575 if (nx_dev_request_reset(adapter
))
2578 clear_bit(__NX_FW_ATTACHED
, &adapter
->state
);
2580 dev_info(&netdev
->dev
, "firmware hang detected\n");
2583 if ((auto_fw_reset
== AUTO_FW_RESET_ENABLED
) &&
2584 !test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2585 netxen_schedule_work(adapter
, netxen_detach_work
, 0);
2590 netxen_fw_poll_work(struct work_struct
*work
)
2592 struct netxen_adapter
*adapter
= container_of(work
,
2593 struct netxen_adapter
, fw_work
.work
);
2595 if (test_bit(__NX_RESETTING
, &adapter
->state
))
2598 if (test_bit(__NX_DEV_UP
, &adapter
->state
)) {
2599 if (!adapter
->has_link_events
) {
2601 netxen_nic_handle_phy_intr(adapter
);
2603 if (adapter
->link_changed
)
2604 netxen_nic_set_link_parameters(adapter
);
2608 if (netxen_check_health(adapter
))
2612 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
2616 netxen_store_bridged_mode(struct device
*dev
,
2617 struct device_attribute
*attr
, const char *buf
, size_t len
)
2619 struct net_device
*net
= to_net_dev(dev
);
2620 struct netxen_adapter
*adapter
= netdev_priv(net
);
2624 if (!(adapter
->capabilities
& NX_FW_CAPABILITY_BDG
))
2627 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
2630 if (strict_strtoul(buf
, 2, &new))
2633 if (!netxen_config_bridged_mode(adapter
, !!new))
2641 netxen_show_bridged_mode(struct device
*dev
,
2642 struct device_attribute
*attr
, char *buf
)
2644 struct net_device
*net
= to_net_dev(dev
);
2645 struct netxen_adapter
*adapter
;
2646 int bridged_mode
= 0;
2648 adapter
= netdev_priv(net
);
2650 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
2651 bridged_mode
= !!(adapter
->flags
& NETXEN_NIC_BRIDGE_ENABLED
);
2653 return sprintf(buf
, "%d\n", bridged_mode
);
2656 static struct device_attribute dev_attr_bridged_mode
= {
2657 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2658 .show
= netxen_show_bridged_mode
,
2659 .store
= netxen_store_bridged_mode
,
2663 netxen_store_diag_mode(struct device
*dev
,
2664 struct device_attribute
*attr
, const char *buf
, size_t len
)
2666 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2669 if (strict_strtoul(buf
, 2, &new))
2672 if (!!new != !!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2673 adapter
->flags
^= NETXEN_NIC_DIAG_ENABLED
;
2679 netxen_show_diag_mode(struct device
*dev
,
2680 struct device_attribute
*attr
, char *buf
)
2682 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2684 return sprintf(buf
, "%d\n",
2685 !!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
));
2688 static struct device_attribute dev_attr_diag_mode
= {
2689 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2690 .show
= netxen_show_diag_mode
,
2691 .store
= netxen_store_diag_mode
,
2695 netxen_sysfs_validate_crb(struct netxen_adapter
*adapter
,
2696 loff_t offset
, size_t size
)
2698 size_t crb_size
= 4;
2700 if (!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2703 if (offset
< NETXEN_PCI_CRBSPACE
) {
2704 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2707 if (ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2708 NETXEN_PCI_CAMQM_2M_END
))
2714 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
2721 netxen_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
2722 struct bin_attribute
*attr
,
2723 char *buf
, loff_t offset
, size_t size
)
2725 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2726 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2731 ret
= netxen_sysfs_validate_crb(adapter
, offset
, size
);
2735 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) &&
2736 ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2737 NETXEN_PCI_CAMQM_2M_END
)) {
2738 netxen_pci_camqm_read_2M(adapter
, offset
, &qmdata
);
2739 memcpy(buf
, &qmdata
, size
);
2741 data
= NXRD32(adapter
, offset
);
2742 memcpy(buf
, &data
, size
);
2749 netxen_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
2750 struct bin_attribute
*attr
,
2751 char *buf
, loff_t offset
, size_t size
)
2753 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2754 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2759 ret
= netxen_sysfs_validate_crb(adapter
, offset
, size
);
2763 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) &&
2764 ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2765 NETXEN_PCI_CAMQM_2M_END
)) {
2766 memcpy(&qmdata
, buf
, size
);
2767 netxen_pci_camqm_write_2M(adapter
, offset
, qmdata
);
2769 memcpy(&data
, buf
, size
);
2770 NXWR32(adapter
, offset
, data
);
2777 netxen_sysfs_validate_mem(struct netxen_adapter
*adapter
,
2778 loff_t offset
, size_t size
)
2780 if (!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2783 if ((size
!= 8) || (offset
& 0x7))
2790 netxen_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
2791 struct bin_attribute
*attr
,
2792 char *buf
, loff_t offset
, size_t size
)
2794 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2795 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2799 ret
= netxen_sysfs_validate_mem(adapter
, offset
, size
);
2803 if (adapter
->pci_mem_read(adapter
, offset
, &data
))
2806 memcpy(buf
, &data
, size
);
2811 static ssize_t
netxen_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
2812 struct bin_attribute
*attr
, char *buf
,
2813 loff_t offset
, size_t size
)
2815 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2816 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2820 ret
= netxen_sysfs_validate_mem(adapter
, offset
, size
);
2824 memcpy(&data
, buf
, size
);
2826 if (adapter
->pci_mem_write(adapter
, offset
, data
))
2833 static struct bin_attribute bin_attr_crb
= {
2834 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
2836 .read
= netxen_sysfs_read_crb
,
2837 .write
= netxen_sysfs_write_crb
,
2840 static struct bin_attribute bin_attr_mem
= {
2841 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
2843 .read
= netxen_sysfs_read_mem
,
2844 .write
= netxen_sysfs_write_mem
,
2849 netxen_create_sysfs_entries(struct netxen_adapter
*adapter
)
2851 struct net_device
*netdev
= adapter
->netdev
;
2852 struct device
*dev
= &netdev
->dev
;
2854 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
) {
2855 /* bridged_mode control */
2856 if (device_create_file(dev
, &dev_attr_bridged_mode
)) {
2857 dev_warn(&netdev
->dev
,
2858 "failed to create bridged_mode sysfs entry\n");
2864 netxen_remove_sysfs_entries(struct netxen_adapter
*adapter
)
2866 struct net_device
*netdev
= adapter
->netdev
;
2867 struct device
*dev
= &netdev
->dev
;
2869 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
2870 device_remove_file(dev
, &dev_attr_bridged_mode
);
2874 netxen_create_diag_entries(struct netxen_adapter
*adapter
)
2876 struct pci_dev
*pdev
= adapter
->pdev
;
2880 if (device_create_file(dev
, &dev_attr_diag_mode
))
2881 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
2882 if (device_create_bin_file(dev
, &bin_attr_crb
))
2883 dev_info(dev
, "failed to create crb sysfs entry\n");
2884 if (device_create_bin_file(dev
, &bin_attr_mem
))
2885 dev_info(dev
, "failed to create mem sysfs entry\n");
2890 netxen_remove_diag_entries(struct netxen_adapter
*adapter
)
2892 struct pci_dev
*pdev
= adapter
->pdev
;
2893 struct device
*dev
= &pdev
->dev
;
2895 device_remove_file(dev
, &dev_attr_diag_mode
);
2896 device_remove_bin_file(dev
, &bin_attr_crb
);
2897 device_remove_bin_file(dev
, &bin_attr_mem
);
2902 #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2905 netxen_destip_supported(struct netxen_adapter
*adapter
)
2907 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2910 if (adapter
->ahw
.cut_through
)
2917 netxen_free_vlan_ip_list(struct netxen_adapter
*adapter
)
2919 struct nx_vlan_ip_list
*cur
;
2920 struct list_head
*head
= &adapter
->vlan_ip_list
;
2922 while (!list_empty(head
)) {
2923 cur
= list_entry(head
->next
, struct nx_vlan_ip_list
, list
);
2924 netxen_config_ipaddr(adapter
, cur
->ip_addr
, NX_IP_DOWN
);
2925 list_del(&cur
->list
);
2931 netxen_list_config_vlan_ip(struct netxen_adapter
*adapter
,
2932 struct in_ifaddr
*ifa
, unsigned long event
)
2934 struct net_device
*dev
;
2935 struct nx_vlan_ip_list
*cur
, *tmp_cur
;
2936 struct list_head
*head
;
2938 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
2943 if (!is_vlan_dev(dev
))
2948 list_for_each(head
, &adapter
->vlan_ip_list
) {
2949 cur
= list_entry(head
, struct nx_vlan_ip_list
, list
);
2951 if (cur
->ip_addr
== ifa
->ifa_address
)
2955 cur
= kzalloc(sizeof(struct nx_vlan_ip_list
), GFP_ATOMIC
);
2957 printk(KERN_ERR
"%s: failed to add vlan ip to list\n",
2958 adapter
->netdev
->name
);
2962 cur
->ip_addr
= ifa
->ifa_address
;
2963 list_add_tail(&cur
->list
, &adapter
->vlan_ip_list
);
2966 list_for_each_entry_safe(cur
, tmp_cur
,
2967 &adapter
->vlan_ip_list
, list
) {
2968 if (cur
->ip_addr
== ifa
->ifa_address
) {
2969 list_del(&cur
->list
);
2977 netxen_config_indev_addr(struct netxen_adapter
*adapter
,
2978 struct net_device
*dev
, unsigned long event
)
2980 struct in_device
*indev
;
2982 if (!netxen_destip_supported(adapter
))
2985 indev
= in_dev_get(dev
);
2992 netxen_config_ipaddr(adapter
,
2993 ifa
->ifa_address
, NX_IP_UP
);
2994 netxen_list_config_vlan_ip(adapter
, ifa
, NX_IP_UP
);
2997 netxen_config_ipaddr(adapter
,
2998 ifa
->ifa_address
, NX_IP_DOWN
);
2999 netxen_list_config_vlan_ip(adapter
, ifa
, NX_IP_DOWN
);
3004 } endfor_ifa(indev
);
3010 netxen_restore_indev_addr(struct net_device
*netdev
, unsigned long event
)
3013 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
3014 struct nx_vlan_ip_list
*pos
, *tmp_pos
;
3015 unsigned long ip_event
;
3017 ip_event
= (event
== NETDEV_UP
) ? NX_IP_UP
: NX_IP_DOWN
;
3018 netxen_config_indev_addr(adapter
, netdev
, event
);
3020 list_for_each_entry_safe(pos
, tmp_pos
, &adapter
->vlan_ip_list
, list
) {
3021 netxen_config_ipaddr(adapter
, pos
->ip_addr
, ip_event
);
3025 static int netxen_netdev_event(struct notifier_block
*this,
3026 unsigned long event
, void *ptr
)
3028 struct netxen_adapter
*adapter
;
3029 struct net_device
*dev
= (struct net_device
*)ptr
;
3030 struct net_device
*orig_dev
= dev
;
3036 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3037 dev
= vlan_dev_real_dev(dev
);
3041 if (!is_netxen_netdev(dev
))
3044 adapter
= netdev_priv(dev
);
3049 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
3052 netxen_config_indev_addr(adapter
, orig_dev
, event
);
3058 netxen_inetaddr_event(struct notifier_block
*this,
3059 unsigned long event
, void *ptr
)
3061 struct netxen_adapter
*adapter
;
3062 struct net_device
*dev
;
3064 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
3066 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
3072 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3073 dev
= vlan_dev_real_dev(dev
);
3077 if (!is_netxen_netdev(dev
))
3080 adapter
= netdev_priv(dev
);
3082 if (!adapter
|| !netxen_destip_supported(adapter
))
3085 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
3090 netxen_config_ipaddr(adapter
, ifa
->ifa_address
, NX_IP_UP
);
3091 netxen_list_config_vlan_ip(adapter
, ifa
, NX_IP_UP
);
3094 netxen_config_ipaddr(adapter
, ifa
->ifa_address
, NX_IP_DOWN
);
3095 netxen_list_config_vlan_ip(adapter
, ifa
, NX_IP_DOWN
);
3105 static struct notifier_block netxen_netdev_cb
= {
3106 .notifier_call
= netxen_netdev_event
,
3109 static struct notifier_block netxen_inetaddr_cb
= {
3110 .notifier_call
= netxen_inetaddr_event
,
3114 netxen_restore_indev_addr(struct net_device
*dev
, unsigned long event
)
3117 netxen_free_vlan_ip_list(struct netxen_adapter
*adapter
)
3121 static struct pci_error_handlers netxen_err_handler
= {
3122 .error_detected
= netxen_io_error_detected
,
3123 .slot_reset
= netxen_io_slot_reset
,
3124 .resume
= netxen_io_resume
,
3127 static struct pci_driver netxen_driver
= {
3128 .name
= netxen_nic_driver_name
,
3129 .id_table
= netxen_pci_tbl
,
3130 .probe
= netxen_nic_probe
,
3131 .remove
= __devexit_p(netxen_nic_remove
),
3133 .suspend
= netxen_nic_suspend
,
3134 .resume
= netxen_nic_resume
,
3136 .shutdown
= netxen_nic_shutdown
,
3137 .err_handler
= &netxen_err_handler
3140 static int __init
netxen_init_module(void)
3142 printk(KERN_INFO
"%s\n", netxen_nic_driver_string
);
3145 register_netdevice_notifier(&netxen_netdev_cb
);
3146 register_inetaddr_notifier(&netxen_inetaddr_cb
);
3148 return pci_register_driver(&netxen_driver
);
3151 module_init(netxen_init_module
);
3153 static void __exit
netxen_exit_module(void)
3155 pci_unregister_driver(&netxen_driver
);
3158 unregister_inetaddr_notifier(&netxen_inetaddr_cb
);
3159 unregister_netdevice_notifier(&netxen_netdev_cb
);
3163 module_exit(netxen_exit_module
);