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, see <http://www.gnu.org/licenses/>.
19 * The full GNU General Public License is included in this distribution
20 * in the file called "COPYING".
24 #include <linux/slab.h>
25 #include <linux/vmalloc.h>
26 #include <linux/interrupt.h>
27 #include "netxen_nic_hw.h"
29 #include "netxen_nic.h"
31 #include <linux/dma-mapping.h>
32 #include <linux/if_vlan.h>
34 #include <linux/ipv6.h>
35 #include <linux/inetdevice.h>
36 #include <linux/sysfs.h>
37 #include <linux/aer.h>
39 MODULE_DESCRIPTION("QLogic/NetXen (1/10) GbE Intelligent Ethernet Driver");
40 MODULE_LICENSE("GPL");
41 MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID
);
42 MODULE_FIRMWARE(NX_UNIFIED_ROMIMAGE_NAME
);
44 char netxen_nic_driver_name
[] = "netxen_nic";
45 static char netxen_nic_driver_string
[] = "QLogic/NetXen Network Driver v"
46 NETXEN_NIC_LINUX_VERSIONID
;
48 static int port_mode
= NETXEN_PORT_MODE_AUTO_NEG
;
50 /* Default to restricted 1G auto-neg mode */
51 static int wol_port_mode
= 5;
53 static int use_msi
= 1;
55 static int use_msi_x
= 1;
57 static int auto_fw_reset
= AUTO_FW_RESET_ENABLED
;
58 module_param(auto_fw_reset
, int, 0644);
59 MODULE_PARM_DESC(auto_fw_reset
,"Auto firmware reset (0=disabled, 1=enabled");
61 static int netxen_nic_probe(struct pci_dev
*pdev
,
62 const struct pci_device_id
*ent
);
63 static void netxen_nic_remove(struct pci_dev
*pdev
);
64 static int netxen_nic_open(struct net_device
*netdev
);
65 static int netxen_nic_close(struct net_device
*netdev
);
66 static netdev_tx_t
netxen_nic_xmit_frame(struct sk_buff
*,
68 static void netxen_tx_timeout(struct net_device
*netdev
);
69 static void netxen_tx_timeout_task(struct work_struct
*work
);
70 static void netxen_fw_poll_work(struct work_struct
*work
);
71 static void netxen_schedule_work(struct netxen_adapter
*adapter
,
72 work_func_t func
, int delay
);
73 static void netxen_cancel_fw_work(struct netxen_adapter
*adapter
);
74 static int netxen_nic_poll(struct napi_struct
*napi
, int budget
);
75 #ifdef CONFIG_NET_POLL_CONTROLLER
76 static void netxen_nic_poll_controller(struct net_device
*netdev
);
79 static void netxen_create_sysfs_entries(struct netxen_adapter
*adapter
);
80 static void netxen_remove_sysfs_entries(struct netxen_adapter
*adapter
);
81 static void netxen_create_diag_entries(struct netxen_adapter
*adapter
);
82 static void netxen_remove_diag_entries(struct netxen_adapter
*adapter
);
83 static int nx_dev_request_aer(struct netxen_adapter
*adapter
);
84 static int nx_decr_dev_ref_cnt(struct netxen_adapter
*adapter
);
85 static int netxen_can_start_firmware(struct netxen_adapter
*adapter
);
87 static irqreturn_t
netxen_intr(int irq
, void *data
);
88 static irqreturn_t
netxen_msi_intr(int irq
, void *data
);
89 static irqreturn_t
netxen_msix_intr(int irq
, void *data
);
91 static void netxen_free_ip_list(struct netxen_adapter
*, bool);
92 static void netxen_restore_indev_addr(struct net_device
*dev
, unsigned long);
93 static struct rtnl_link_stats64
*netxen_nic_get_stats(struct net_device
*dev
,
94 struct rtnl_link_stats64
*stats
);
95 static int netxen_nic_set_mac(struct net_device
*netdev
, void *p
);
97 /* PCI Device ID Table */
98 #define ENTRY(device) \
99 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
100 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
102 static const struct pci_device_id netxen_pci_tbl
[] = {
103 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR
),
104 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4
),
105 ENTRY(PCI_DEVICE_ID_NX2031_4GCU
),
106 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ
),
107 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ
),
108 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT
),
109 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2
),
110 ENTRY(PCI_DEVICE_ID_NX3031
),
114 MODULE_DEVICE_TABLE(pci
, netxen_pci_tbl
);
116 static uint32_t crb_cmd_producer
[4] = {
117 CRB_CMD_PRODUCER_OFFSET
, CRB_CMD_PRODUCER_OFFSET_1
,
118 CRB_CMD_PRODUCER_OFFSET_2
, CRB_CMD_PRODUCER_OFFSET_3
122 netxen_nic_update_cmd_producer(struct netxen_adapter
*adapter
,
123 struct nx_host_tx_ring
*tx_ring
)
125 NXWRIO(adapter
, tx_ring
->crb_cmd_producer
, tx_ring
->producer
);
128 static uint32_t crb_cmd_consumer
[4] = {
129 CRB_CMD_CONSUMER_OFFSET
, CRB_CMD_CONSUMER_OFFSET_1
,
130 CRB_CMD_CONSUMER_OFFSET_2
, CRB_CMD_CONSUMER_OFFSET_3
134 netxen_nic_update_cmd_consumer(struct netxen_adapter
*adapter
,
135 struct nx_host_tx_ring
*tx_ring
)
137 NXWRIO(adapter
, tx_ring
->crb_cmd_consumer
, tx_ring
->sw_consumer
);
140 static uint32_t msi_tgt_status
[8] = {
141 ISR_INT_TARGET_STATUS
, ISR_INT_TARGET_STATUS_F1
,
142 ISR_INT_TARGET_STATUS_F2
, ISR_INT_TARGET_STATUS_F3
,
143 ISR_INT_TARGET_STATUS_F4
, ISR_INT_TARGET_STATUS_F5
,
144 ISR_INT_TARGET_STATUS_F6
, ISR_INT_TARGET_STATUS_F7
147 static struct netxen_legacy_intr_set legacy_intr
[] = NX_LEGACY_INTR_CONFIG
;
149 static inline void netxen_nic_disable_int(struct nx_host_sds_ring
*sds_ring
)
151 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
153 NXWRIO(adapter
, sds_ring
->crb_intr_mask
, 0);
156 static inline void netxen_nic_enable_int(struct nx_host_sds_ring
*sds_ring
)
158 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
160 NXWRIO(adapter
, sds_ring
->crb_intr_mask
, 0x1);
162 if (!NETXEN_IS_MSI_FAMILY(adapter
))
163 NXWRIO(adapter
, adapter
->tgt_mask_reg
, 0xfbff);
167 netxen_alloc_sds_rings(struct netxen_recv_context
*recv_ctx
, int count
)
169 int size
= sizeof(struct nx_host_sds_ring
) * count
;
171 recv_ctx
->sds_rings
= kzalloc(size
, GFP_KERNEL
);
173 return recv_ctx
->sds_rings
== NULL
;
177 netxen_free_sds_rings(struct netxen_recv_context
*recv_ctx
)
179 kfree(recv_ctx
->sds_rings
);
180 recv_ctx
->sds_rings
= NULL
;
184 netxen_napi_add(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
187 struct nx_host_sds_ring
*sds_ring
;
188 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
190 if (netxen_alloc_sds_rings(recv_ctx
, adapter
->max_sds_rings
))
193 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
194 sds_ring
= &recv_ctx
->sds_rings
[ring
];
195 netif_napi_add(netdev
, &sds_ring
->napi
,
196 netxen_nic_poll
, NAPI_POLL_WEIGHT
);
203 netxen_napi_del(struct netxen_adapter
*adapter
)
206 struct nx_host_sds_ring
*sds_ring
;
207 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
209 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
210 sds_ring
= &recv_ctx
->sds_rings
[ring
];
211 netif_napi_del(&sds_ring
->napi
);
214 netxen_free_sds_rings(&adapter
->recv_ctx
);
218 netxen_napi_enable(struct netxen_adapter
*adapter
)
221 struct nx_host_sds_ring
*sds_ring
;
222 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
224 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
225 sds_ring
= &recv_ctx
->sds_rings
[ring
];
226 napi_enable(&sds_ring
->napi
);
227 netxen_nic_enable_int(sds_ring
);
232 netxen_napi_disable(struct netxen_adapter
*adapter
)
235 struct nx_host_sds_ring
*sds_ring
;
236 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
238 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
239 sds_ring
= &recv_ctx
->sds_rings
[ring
];
240 netxen_nic_disable_int(sds_ring
);
241 napi_synchronize(&sds_ring
->napi
);
242 napi_disable(&sds_ring
->napi
);
246 static int nx_set_dma_mask(struct netxen_adapter
*adapter
)
248 struct pci_dev
*pdev
= adapter
->pdev
;
249 uint64_t mask
, cmask
;
251 adapter
->pci_using_dac
= 0;
253 mask
= DMA_BIT_MASK(32);
254 cmask
= DMA_BIT_MASK(32);
256 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
258 mask
= DMA_BIT_MASK(35);
261 mask
= DMA_BIT_MASK(39);
265 if (pci_set_dma_mask(pdev
, mask
) == 0 &&
266 pci_set_consistent_dma_mask(pdev
, cmask
) == 0) {
267 adapter
->pci_using_dac
= 1;
274 /* Update addressable range if firmware supports it */
276 nx_update_dma_mask(struct netxen_adapter
*adapter
)
278 int change
, shift
, err
;
279 uint64_t mask
, old_mask
, old_cmask
;
280 struct pci_dev
*pdev
= adapter
->pdev
;
284 shift
= NXRD32(adapter
, CRB_DMA_SHIFT
);
288 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) && (shift
> 9))
290 else if ((adapter
->ahw
.revision_id
== NX_P2_C1
) && (shift
<= 4))
294 old_mask
= pdev
->dma_mask
;
295 old_cmask
= pdev
->dev
.coherent_dma_mask
;
297 mask
= DMA_BIT_MASK(32+shift
);
299 err
= pci_set_dma_mask(pdev
, mask
);
303 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
305 err
= pci_set_consistent_dma_mask(pdev
, mask
);
309 dev_info(&pdev
->dev
, "using %d-bit dma mask\n", 32+shift
);
315 pci_set_dma_mask(pdev
, old_mask
);
316 pci_set_consistent_dma_mask(pdev
, old_cmask
);
321 netxen_check_hw_init(struct netxen_adapter
*adapter
, int first_boot
)
325 if (first_boot
== 0x55555555) {
326 /* This is the first boot after power up */
327 NXWR32(adapter
, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC
);
329 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
332 /* PCI bus master workaround */
333 first_boot
= NXRD32(adapter
, NETXEN_PCIE_REG(0x4));
334 if (!(first_boot
& 0x4)) {
336 NXWR32(adapter
, NETXEN_PCIE_REG(0x4), first_boot
);
337 NXRD32(adapter
, NETXEN_PCIE_REG(0x4));
340 /* This is the first boot after power up */
341 first_boot
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
);
342 if (first_boot
!= 0x80000f) {
343 /* clear the register for future unloads/loads */
344 NXWR32(adapter
, NETXEN_CAM_RAM(0x1fc), 0);
348 /* Start P2 boot loader */
349 val
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_PEGTUNE_DONE
);
350 NXWR32(adapter
, NETXEN_ROMUSB_GLB_PEGTUNE_DONE
, val
| 0x1);
354 val
= NXRD32(adapter
, NETXEN_CAM_RAM(0x1fc));
356 if (++timeout
> 5000)
359 } while (val
== NETXEN_BDINFO_MAGIC
);
364 static void netxen_set_port_mode(struct netxen_adapter
*adapter
)
368 val
= adapter
->ahw
.board_type
;
369 if ((val
== NETXEN_BRDTYPE_P3_HMEZ
) ||
370 (val
== NETXEN_BRDTYPE_P3_XG_LOM
)) {
371 if (port_mode
== NETXEN_PORT_MODE_802_3_AP
) {
372 data
= NETXEN_PORT_MODE_802_3_AP
;
373 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
374 } else if (port_mode
== NETXEN_PORT_MODE_XG
) {
375 data
= NETXEN_PORT_MODE_XG
;
376 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
377 } else if (port_mode
== NETXEN_PORT_MODE_AUTO_NEG_1G
) {
378 data
= NETXEN_PORT_MODE_AUTO_NEG_1G
;
379 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
380 } else if (port_mode
== NETXEN_PORT_MODE_AUTO_NEG_XG
) {
381 data
= NETXEN_PORT_MODE_AUTO_NEG_XG
;
382 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
384 data
= NETXEN_PORT_MODE_AUTO_NEG
;
385 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
388 if ((wol_port_mode
!= NETXEN_PORT_MODE_802_3_AP
) &&
389 (wol_port_mode
!= NETXEN_PORT_MODE_XG
) &&
390 (wol_port_mode
!= NETXEN_PORT_MODE_AUTO_NEG_1G
) &&
391 (wol_port_mode
!= NETXEN_PORT_MODE_AUTO_NEG_XG
)) {
392 wol_port_mode
= NETXEN_PORT_MODE_AUTO_NEG
;
394 NXWR32(adapter
, NETXEN_WOL_PORT_MODE
, wol_port_mode
);
398 #define PCI_CAP_ID_GEN 0x10
400 static void netxen_pcie_strap_init(struct netxen_adapter
*adapter
)
407 struct pci_dev
*pdev
;
409 pdev
= adapter
->pdev
;
411 chicken
= NXRD32(adapter
, NETXEN_PCIE_REG(PCIE_CHICKEN3
));
412 /* clear chicken3.25:24 */
413 chicken
&= 0xFCFFFFFF;
415 * if gen1 and B0, set F1020 - if gen 2, do nothing
416 * if gen2 set to F1000
418 pos
= pci_find_capability(pdev
, PCI_CAP_ID_GEN
);
420 pci_read_config_dword(pdev
, pos
+ 0x10, &control
);
421 if ((control
& 0x000F0000) != 0x00020000) {
422 /* set chicken3.24 if gen1 */
423 chicken
|= 0x01000000;
425 dev_info(&adapter
->pdev
->dev
, "Gen2 strapping detected\n");
428 /* set chicken3.24 if gen1 */
429 chicken
|= 0x01000000;
430 dev_info(&adapter
->pdev
->dev
, "Gen1 strapping detected\n");
431 if (adapter
->ahw
.revision_id
== NX_P3_B0
)
437 NXWR32(adapter
, NETXEN_PCIE_REG(PCIE_CHICKEN3
), chicken
);
442 pdevfuncsave
= pdev
->devfn
;
443 if (pdevfuncsave
& 0x07)
446 for (i
= 0; i
< 8; i
++) {
447 pci_read_config_dword(pdev
, pos
+ 8, &control
);
448 pci_read_config_dword(pdev
, pos
+ 8, &control
);
449 pci_write_config_dword(pdev
, pos
+ 8, c8c9value
);
452 pdev
->devfn
= pdevfuncsave
;
455 static void netxen_set_msix_bit(struct pci_dev
*pdev
, int enable
)
459 if (pdev
->msix_cap
) {
460 pci_read_config_dword(pdev
, pdev
->msix_cap
, &control
);
462 control
|= PCI_MSIX_FLAGS_ENABLE
;
465 pci_write_config_dword(pdev
, pdev
->msix_cap
, control
);
469 static void netxen_init_msix_entries(struct netxen_adapter
*adapter
, int count
)
473 for (i
= 0; i
< count
; i
++)
474 adapter
->msix_entries
[i
].entry
= i
;
478 netxen_read_mac_addr(struct netxen_adapter
*adapter
)
483 struct net_device
*netdev
= adapter
->netdev
;
484 struct pci_dev
*pdev
= adapter
->pdev
;
486 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
487 if (netxen_p3_get_mac_addr(adapter
, &mac_addr
) != 0)
490 if (netxen_get_flash_mac_addr(adapter
, &mac_addr
) != 0)
494 p
= (unsigned char *)&mac_addr
;
495 for (i
= 0; i
< 6; i
++)
496 netdev
->dev_addr
[i
] = *(p
+ 5 - i
);
498 memcpy(adapter
->mac_addr
, netdev
->dev_addr
, netdev
->addr_len
);
500 /* set station address */
502 if (!is_valid_ether_addr(netdev
->dev_addr
))
503 dev_warn(&pdev
->dev
, "Bad MAC address %pM.\n", netdev
->dev_addr
);
508 static int netxen_nic_set_mac(struct net_device
*netdev
, void *p
)
510 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
511 struct sockaddr
*addr
= p
;
513 if (!is_valid_ether_addr(addr
->sa_data
))
514 return -EADDRNOTAVAIL
;
516 if (netif_running(netdev
)) {
517 netif_device_detach(netdev
);
518 netxen_napi_disable(adapter
);
521 memcpy(adapter
->mac_addr
, addr
->sa_data
, netdev
->addr_len
);
522 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
523 adapter
->macaddr_set(adapter
, addr
->sa_data
);
525 if (netif_running(netdev
)) {
526 netif_device_attach(netdev
);
527 netxen_napi_enable(adapter
);
532 static void netxen_set_multicast_list(struct net_device
*dev
)
534 struct netxen_adapter
*adapter
= netdev_priv(dev
);
536 adapter
->set_multi(dev
);
539 static netdev_features_t
netxen_fix_features(struct net_device
*dev
,
540 netdev_features_t features
)
542 if (!(features
& NETIF_F_RXCSUM
)) {
543 netdev_info(dev
, "disabling LRO as RXCSUM is off\n");
545 features
&= ~NETIF_F_LRO
;
551 static int netxen_set_features(struct net_device
*dev
,
552 netdev_features_t features
)
554 struct netxen_adapter
*adapter
= netdev_priv(dev
);
557 if (!((dev
->features
^ features
) & NETIF_F_LRO
))
560 hw_lro
= (features
& NETIF_F_LRO
) ? NETXEN_NIC_LRO_ENABLED
561 : NETXEN_NIC_LRO_DISABLED
;
563 if (netxen_config_hw_lro(adapter
, hw_lro
))
566 if (!(features
& NETIF_F_LRO
) && netxen_send_lro_cleanup(adapter
))
572 static const struct net_device_ops netxen_netdev_ops
= {
573 .ndo_open
= netxen_nic_open
,
574 .ndo_stop
= netxen_nic_close
,
575 .ndo_start_xmit
= netxen_nic_xmit_frame
,
576 .ndo_get_stats64
= netxen_nic_get_stats
,
577 .ndo_validate_addr
= eth_validate_addr
,
578 .ndo_set_rx_mode
= netxen_set_multicast_list
,
579 .ndo_set_mac_address
= netxen_nic_set_mac
,
580 .ndo_change_mtu
= netxen_nic_change_mtu
,
581 .ndo_tx_timeout
= netxen_tx_timeout
,
582 .ndo_fix_features
= netxen_fix_features
,
583 .ndo_set_features
= netxen_set_features
,
584 #ifdef CONFIG_NET_POLL_CONTROLLER
585 .ndo_poll_controller
= netxen_nic_poll_controller
,
589 static inline bool netxen_function_zero(struct pci_dev
*pdev
)
591 return (PCI_FUNC(pdev
->devfn
) == 0) ? true : false;
594 static inline void netxen_set_interrupt_mode(struct netxen_adapter
*adapter
,
597 NXWR32(adapter
, NETXEN_INTR_MODE_REG
, mode
);
600 static inline u32
netxen_get_interrupt_mode(struct netxen_adapter
*adapter
)
602 return NXRD32(adapter
, NETXEN_INTR_MODE_REG
);
606 netxen_initialize_interrupt_registers(struct netxen_adapter
*adapter
)
608 struct netxen_legacy_intr_set
*legacy_intrp
;
609 u32 tgt_status_reg
, int_state_reg
;
611 if (adapter
->ahw
.revision_id
>= NX_P3_B0
)
612 legacy_intrp
= &legacy_intr
[adapter
->ahw
.pci_func
];
614 legacy_intrp
= &legacy_intr
[0];
616 tgt_status_reg
= legacy_intrp
->tgt_status_reg
;
617 int_state_reg
= ISR_INT_STATE_REG
;
619 adapter
->int_vec_bit
= legacy_intrp
->int_vec_bit
;
620 adapter
->tgt_status_reg
= netxen_get_ioaddr(adapter
, tgt_status_reg
);
621 adapter
->tgt_mask_reg
= netxen_get_ioaddr(adapter
,
622 legacy_intrp
->tgt_mask_reg
);
623 adapter
->pci_int_reg
= netxen_get_ioaddr(adapter
,
624 legacy_intrp
->pci_int_reg
);
625 adapter
->isr_int_vec
= netxen_get_ioaddr(adapter
, ISR_INT_VECTOR
);
627 if (adapter
->ahw
.revision_id
>= NX_P3_B1
)
628 adapter
->crb_int_state_reg
= netxen_get_ioaddr(adapter
,
631 adapter
->crb_int_state_reg
= netxen_get_ioaddr(adapter
,
635 static int netxen_setup_msi_interrupts(struct netxen_adapter
*adapter
,
638 struct pci_dev
*pdev
= adapter
->pdev
;
642 if (adapter
->msix_supported
) {
643 netxen_init_msix_entries(adapter
, num_msix
);
644 err
= pci_enable_msix_range(pdev
, adapter
->msix_entries
,
647 adapter
->flags
|= NETXEN_NIC_MSIX_ENABLED
;
648 netxen_set_msix_bit(pdev
, 1);
650 if (adapter
->rss_supported
)
651 adapter
->max_sds_rings
= num_msix
;
653 dev_info(&pdev
->dev
, "using msi-x interrupts\n");
656 /* fall through for msi */
659 if (use_msi
&& !pci_enable_msi(pdev
)) {
660 value
= msi_tgt_status
[adapter
->ahw
.pci_func
];
661 adapter
->flags
|= NETXEN_NIC_MSI_ENABLED
;
662 adapter
->tgt_status_reg
= netxen_get_ioaddr(adapter
, value
);
663 adapter
->msix_entries
[0].vector
= pdev
->irq
;
664 dev_info(&pdev
->dev
, "using msi interrupts\n");
668 dev_err(&pdev
->dev
, "Failed to acquire MSI-X/MSI interrupt vector\n");
672 static int netxen_setup_intr(struct netxen_adapter
*adapter
)
674 struct pci_dev
*pdev
= adapter
->pdev
;
677 if (adapter
->rss_supported
)
678 num_msix
= (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER
) ?
679 MSIX_ENTRIES_PER_ADAPTER
: 2;
683 adapter
->max_sds_rings
= 1;
684 adapter
->flags
&= ~(NETXEN_NIC_MSI_ENABLED
| NETXEN_NIC_MSIX_ENABLED
);
686 netxen_initialize_interrupt_registers(adapter
);
687 netxen_set_msix_bit(pdev
, 0);
689 if (netxen_function_zero(pdev
)) {
690 if (!netxen_setup_msi_interrupts(adapter
, num_msix
))
691 netxen_set_interrupt_mode(adapter
, NETXEN_MSI_MODE
);
693 netxen_set_interrupt_mode(adapter
, NETXEN_INTX_MODE
);
695 if (netxen_get_interrupt_mode(adapter
) == NETXEN_MSI_MODE
&&
696 netxen_setup_msi_interrupts(adapter
, num_msix
)) {
697 dev_err(&pdev
->dev
, "Co-existence of MSI-X/MSI and INTx interrupts is not supported\n");
702 if (!NETXEN_IS_MSI_FAMILY(adapter
)) {
703 adapter
->msix_entries
[0].vector
= pdev
->irq
;
704 dev_info(&pdev
->dev
, "using legacy interrupts\n");
710 netxen_teardown_intr(struct netxen_adapter
*adapter
)
712 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
713 pci_disable_msix(adapter
->pdev
);
714 if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
715 pci_disable_msi(adapter
->pdev
);
719 netxen_cleanup_pci_map(struct netxen_adapter
*adapter
)
721 if (adapter
->ahw
.db_base
!= NULL
)
722 iounmap(adapter
->ahw
.db_base
);
723 if (adapter
->ahw
.pci_base0
!= NULL
)
724 iounmap(adapter
->ahw
.pci_base0
);
725 if (adapter
->ahw
.pci_base1
!= NULL
)
726 iounmap(adapter
->ahw
.pci_base1
);
727 if (adapter
->ahw
.pci_base2
!= NULL
)
728 iounmap(adapter
->ahw
.pci_base2
);
732 netxen_setup_pci_map(struct netxen_adapter
*adapter
)
734 void __iomem
*db_ptr
= NULL
;
736 resource_size_t mem_base
, db_base
;
737 unsigned long mem_len
, db_len
= 0;
739 struct pci_dev
*pdev
= adapter
->pdev
;
740 int pci_func
= adapter
->ahw
.pci_func
;
741 struct netxen_hardware_context
*ahw
= &adapter
->ahw
;
746 * Set the CRB window to invalid. If any register in window 0 is
747 * accessed it should set the window to 0 and then reset it to 1.
749 adapter
->ahw
.crb_win
= -1;
750 adapter
->ahw
.ocm_win
= -1;
752 /* remap phys address */
753 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
754 mem_len
= pci_resource_len(pdev
, 0);
756 /* 128 Meg of memory */
757 if (mem_len
== NETXEN_PCI_128MB_SIZE
) {
759 ahw
->pci_base0
= ioremap(mem_base
, FIRST_PAGE_GROUP_SIZE
);
760 ahw
->pci_base1
= ioremap(mem_base
+ SECOND_PAGE_GROUP_START
,
761 SECOND_PAGE_GROUP_SIZE
);
762 ahw
->pci_base2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
,
763 THIRD_PAGE_GROUP_SIZE
);
764 if (ahw
->pci_base0
== NULL
|| ahw
->pci_base1
== NULL
||
765 ahw
->pci_base2
== NULL
) {
766 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
771 ahw
->pci_len0
= FIRST_PAGE_GROUP_SIZE
;
773 } else if (mem_len
== NETXEN_PCI_32MB_SIZE
) {
775 ahw
->pci_base1
= ioremap(mem_base
, SECOND_PAGE_GROUP_SIZE
);
776 ahw
->pci_base2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
-
777 SECOND_PAGE_GROUP_START
, THIRD_PAGE_GROUP_SIZE
);
778 if (ahw
->pci_base1
== NULL
|| ahw
->pci_base2
== NULL
) {
779 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
784 } else if (mem_len
== NETXEN_PCI_2MB_SIZE
) {
786 ahw
->pci_base0
= pci_ioremap_bar(pdev
, 0);
787 if (ahw
->pci_base0
== NULL
) {
788 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
791 ahw
->pci_len0
= mem_len
;
796 netxen_setup_hwops(adapter
);
798 dev_info(&pdev
->dev
, "%dMB memory map\n", (int)(mem_len
>>20));
800 if (NX_IS_REVISION_P3P(adapter
->ahw
.revision_id
)) {
801 adapter
->ahw
.ocm_win_crb
= netxen_get_ioaddr(adapter
,
802 NETXEN_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(pci_func
)));
804 } else if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
805 adapter
->ahw
.ocm_win_crb
= netxen_get_ioaddr(adapter
,
806 NETXEN_PCIX_PS_REG(PCIE_MN_WINDOW_REG(pci_func
)));
809 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
812 db_base
= pci_resource_start(pdev
, 4); /* doorbell is on bar 4 */
813 db_len
= pci_resource_len(pdev
, 4);
816 printk(KERN_ERR
"%s: doorbell is disabled\n",
817 netxen_nic_driver_name
);
822 db_ptr
= ioremap(db_base
, NETXEN_DB_MAPSIZE_BYTES
);
824 printk(KERN_ERR
"%s: Failed to allocate doorbell map.",
825 netxen_nic_driver_name
);
831 adapter
->ahw
.db_base
= db_ptr
;
832 adapter
->ahw
.db_len
= db_len
;
836 netxen_cleanup_pci_map(adapter
);
841 netxen_check_options(struct netxen_adapter
*adapter
)
843 u32 fw_major
, fw_minor
, fw_build
, prev_fw_version
;
844 char brd_name
[NETXEN_MAX_SHORT_NAME
];
846 int i
, offset
, val
, err
;
848 struct pci_dev
*pdev
= adapter
->pdev
;
850 adapter
->driver_mismatch
= 0;
852 ptr32
= (__le32
*)&serial_num
;
853 offset
= NX_FW_SERIAL_NUM_OFFSET
;
854 for (i
= 0; i
< 8; i
++) {
855 err
= netxen_rom_fast_read(adapter
, offset
, &val
);
857 dev_err(&pdev
->dev
, "error reading board info\n");
858 adapter
->driver_mismatch
= 1;
861 ptr32
[i
] = cpu_to_le32(val
);
862 offset
+= sizeof(u32
);
865 fw_major
= NXRD32(adapter
, NETXEN_FW_VERSION_MAJOR
);
866 fw_minor
= NXRD32(adapter
, NETXEN_FW_VERSION_MINOR
);
867 fw_build
= NXRD32(adapter
, NETXEN_FW_VERSION_SUB
);
868 prev_fw_version
= adapter
->fw_version
;
869 adapter
->fw_version
= NETXEN_VERSION_CODE(fw_major
, fw_minor
, fw_build
);
871 /* Get FW Mini Coredump template and store it */
872 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
873 if (adapter
->mdump
.md_template
== NULL
||
874 adapter
->fw_version
> prev_fw_version
) {
875 kfree(adapter
->mdump
.md_template
);
876 adapter
->mdump
.md_template
= NULL
;
877 err
= netxen_setup_minidump(adapter
);
879 dev_err(&adapter
->pdev
->dev
,
880 "Failed to setup minidump rcode = %d\n", err
);
884 if (adapter
->portnum
== 0) {
885 if (netxen_nic_get_brd_name_by_type(adapter
->ahw
.board_type
,
887 strcpy(serial_num
, "Unknown");
889 pr_info("%s: %s Board S/N %s Chip rev 0x%x\n",
890 module_name(THIS_MODULE
),
891 brd_name
, serial_num
, adapter
->ahw
.revision_id
);
894 if (adapter
->fw_version
< NETXEN_VERSION_CODE(3, 4, 216)) {
895 adapter
->driver_mismatch
= 1;
896 dev_warn(&pdev
->dev
, "firmware version %d.%d.%d unsupported\n",
897 fw_major
, fw_minor
, fw_build
);
901 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
902 i
= NXRD32(adapter
, NETXEN_SRE_MISC
);
903 adapter
->ahw
.cut_through
= (i
& 0x8000) ? 1 : 0;
906 dev_info(&pdev
->dev
, "Driver v%s, firmware v%d.%d.%d [%s]\n",
907 NETXEN_NIC_LINUX_VERSIONID
, fw_major
, fw_minor
, fw_build
,
908 adapter
->ahw
.cut_through
? "cut-through" : "legacy");
910 if (adapter
->fw_version
>= NETXEN_VERSION_CODE(4, 0, 222))
911 adapter
->capabilities
= NXRD32(adapter
, CRB_FW_CAPABILITIES_1
);
913 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
914 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
915 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
916 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
917 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
918 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
921 adapter
->msix_supported
= 0;
922 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
923 adapter
->msix_supported
= !!use_msi_x
;
924 adapter
->rss_supported
= !!use_msi_x
;
927 netxen_rom_fast_read(adapter
,
928 NX_FW_VERSION_OFFSET
, (int *)&flashed_ver
);
929 flashed_ver
= NETXEN_DECODE_VERSION(flashed_ver
);
931 if (flashed_ver
>= NETXEN_VERSION_CODE(3, 4, 336)) {
932 switch (adapter
->ahw
.board_type
) {
933 case NETXEN_BRDTYPE_P2_SB31_10G
:
934 case NETXEN_BRDTYPE_P2_SB31_10G_CX4
:
935 adapter
->msix_supported
= !!use_msi_x
;
936 adapter
->rss_supported
= !!use_msi_x
;
944 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
946 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
947 adapter
->num_lro_rxd
= MAX_LRO_RCV_DESCRIPTORS
;
948 adapter
->max_rds_rings
= 3;
950 adapter
->num_lro_rxd
= 0;
951 adapter
->max_rds_rings
= 2;
956 netxen_start_firmware(struct netxen_adapter
*adapter
)
958 int val
, err
, first_boot
;
959 struct pci_dev
*pdev
= adapter
->pdev
;
961 /* required for NX2031 dummy dma */
962 err
= nx_set_dma_mask(adapter
);
966 err
= netxen_can_start_firmware(adapter
);
974 first_boot
= NXRD32(adapter
, NETXEN_CAM_RAM(0x1fc));
976 err
= netxen_check_hw_init(adapter
, first_boot
);
978 dev_err(&pdev
->dev
, "error in init HW init sequence\n");
982 netxen_request_firmware(adapter
);
984 err
= netxen_need_fw_reset(adapter
);
988 goto pcie_strap_init
;
990 if (first_boot
!= 0x55555555) {
991 NXWR32(adapter
, CRB_CMDPEG_STATE
, 0);
992 netxen_pinit_from_rom(adapter
);
996 NXWR32(adapter
, CRB_DMA_SHIFT
, 0x55555555);
997 NXWR32(adapter
, NETXEN_PEG_HALT_STATUS1
, 0);
998 NXWR32(adapter
, NETXEN_PEG_HALT_STATUS2
, 0);
1000 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1001 netxen_set_port_mode(adapter
);
1003 err
= netxen_load_firmware(adapter
);
1007 netxen_release_firmware(adapter
);
1009 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1011 /* Initialize multicast addr pool owners */
1013 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
)
1015 NXWR32(adapter
, NETXEN_MAC_ADDR_CNTL_REG
, val
);
1019 err
= netxen_init_dummy_dma(adapter
);
1024 * Tell the hardware our version number.
1026 val
= (_NETXEN_NIC_LINUX_MAJOR
<< 16)
1027 | ((_NETXEN_NIC_LINUX_MINOR
<< 8))
1028 | (_NETXEN_NIC_LINUX_SUBVERSION
);
1029 NXWR32(adapter
, CRB_DRIVER_VERSION
, val
);
1032 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1033 netxen_pcie_strap_init(adapter
);
1036 /* Handshake with the card before we register the devices. */
1037 err
= netxen_phantom_init(adapter
, NETXEN_NIC_PEG_TUNE
);
1039 netxen_free_dummy_dma(adapter
);
1043 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_READY
);
1045 nx_update_dma_mask(adapter
);
1047 netxen_check_options(adapter
);
1049 adapter
->need_fw_reset
= 0;
1051 /* fall through and release firmware */
1054 netxen_release_firmware(adapter
);
1059 netxen_nic_request_irq(struct netxen_adapter
*adapter
)
1061 irq_handler_t handler
;
1062 struct nx_host_sds_ring
*sds_ring
;
1065 unsigned long flags
= 0;
1066 struct net_device
*netdev
= adapter
->netdev
;
1067 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1069 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
1070 handler
= netxen_msix_intr
;
1071 else if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
1072 handler
= netxen_msi_intr
;
1074 flags
|= IRQF_SHARED
;
1075 handler
= netxen_intr
;
1077 adapter
->irq
= netdev
->irq
;
1079 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1080 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1081 sprintf(sds_ring
->name
, "%s[%d]", netdev
->name
, ring
);
1082 err
= request_irq(sds_ring
->irq
, handler
,
1083 flags
, sds_ring
->name
, sds_ring
);
1092 netxen_nic_free_irq(struct netxen_adapter
*adapter
)
1095 struct nx_host_sds_ring
*sds_ring
;
1097 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1099 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1100 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1101 free_irq(sds_ring
->irq
, sds_ring
);
1106 netxen_nic_init_coalesce_defaults(struct netxen_adapter
*adapter
)
1108 adapter
->coal
.flags
= NETXEN_NIC_INTR_DEFAULT
;
1109 adapter
->coal
.normal
.data
.rx_time_us
=
1110 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US
;
1111 adapter
->coal
.normal
.data
.rx_packets
=
1112 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS
;
1113 adapter
->coal
.normal
.data
.tx_time_us
=
1114 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US
;
1115 adapter
->coal
.normal
.data
.tx_packets
=
1116 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS
;
1119 /* with rtnl_lock */
1121 __netxen_nic_up(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1125 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1128 err
= adapter
->init_port(adapter
, adapter
->physical_port
);
1130 printk(KERN_ERR
"%s: Failed to initialize port %d\n",
1131 netxen_nic_driver_name
, adapter
->portnum
);
1134 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
1135 adapter
->macaddr_set(adapter
, adapter
->mac_addr
);
1137 adapter
->set_multi(netdev
);
1138 adapter
->set_mtu(adapter
, netdev
->mtu
);
1140 adapter
->ahw
.linkup
= 0;
1142 if (adapter
->max_sds_rings
> 1)
1143 netxen_config_rss(adapter
, 1);
1145 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1146 netxen_config_intr_coalesce(adapter
);
1148 if (netdev
->features
& NETIF_F_LRO
)
1149 netxen_config_hw_lro(adapter
, NETXEN_NIC_LRO_ENABLED
);
1151 netxen_napi_enable(adapter
);
1153 if (adapter
->capabilities
& NX_FW_CAPABILITY_LINK_NOTIFICATION
)
1154 netxen_linkevent_request(adapter
, 1);
1156 netxen_nic_set_link_parameters(adapter
);
1158 set_bit(__NX_DEV_UP
, &adapter
->state
);
1162 /* Usage: During resume and firmware recovery module.*/
1165 netxen_nic_up(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1170 if (netif_running(netdev
))
1171 err
= __netxen_nic_up(adapter
, netdev
);
1177 /* with rtnl_lock */
1179 __netxen_nic_down(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1181 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1184 if (!test_and_clear_bit(__NX_DEV_UP
, &adapter
->state
))
1188 netif_carrier_off(netdev
);
1189 netif_tx_disable(netdev
);
1191 if (adapter
->capabilities
& NX_FW_CAPABILITY_LINK_NOTIFICATION
)
1192 netxen_linkevent_request(adapter
, 0);
1194 if (adapter
->stop_port
)
1195 adapter
->stop_port(adapter
);
1197 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1198 netxen_p3_free_mac_list(adapter
);
1200 adapter
->set_promisc(adapter
, NETXEN_NIU_NON_PROMISC_MODE
);
1202 netxen_napi_disable(adapter
);
1204 netxen_release_tx_buffers(adapter
);
1207 /* Usage: During suspend and firmware recovery module */
1210 netxen_nic_down(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1213 if (netif_running(netdev
))
1214 __netxen_nic_down(adapter
, netdev
);
1220 netxen_nic_attach(struct netxen_adapter
*adapter
)
1222 struct net_device
*netdev
= adapter
->netdev
;
1223 struct pci_dev
*pdev
= adapter
->pdev
;
1225 struct nx_host_rds_ring
*rds_ring
;
1226 struct nx_host_tx_ring
*tx_ring
;
1229 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
)
1232 err
= netxen_init_firmware(adapter
);
1236 adapter
->flags
&= ~NETXEN_FW_MSS_CAP
;
1237 if (adapter
->capabilities
& NX_FW_CAPABILITY_MORE_CAPS
) {
1238 capab2
= NXRD32(adapter
, CRB_FW_CAPABILITIES_2
);
1239 if (capab2
& NX_FW_CAPABILITY_2_LRO_MAX_TCP_SEG
)
1240 adapter
->flags
|= NETXEN_FW_MSS_CAP
;
1243 err
= netxen_napi_add(adapter
, netdev
);
1247 err
= netxen_alloc_sw_resources(adapter
);
1249 printk(KERN_ERR
"%s: Error in setting sw resources\n",
1254 err
= netxen_alloc_hw_resources(adapter
);
1256 printk(KERN_ERR
"%s: Error in setting hw resources\n",
1258 goto err_out_free_sw
;
1261 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1262 tx_ring
= adapter
->tx_ring
;
1263 tx_ring
->crb_cmd_producer
= netxen_get_ioaddr(adapter
,
1264 crb_cmd_producer
[adapter
->portnum
]);
1265 tx_ring
->crb_cmd_consumer
= netxen_get_ioaddr(adapter
,
1266 crb_cmd_consumer
[adapter
->portnum
]);
1268 tx_ring
->producer
= 0;
1269 tx_ring
->sw_consumer
= 0;
1271 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
1272 netxen_nic_update_cmd_consumer(adapter
, tx_ring
);
1275 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1276 rds_ring
= &adapter
->recv_ctx
.rds_rings
[ring
];
1277 netxen_post_rx_buffers(adapter
, ring
, rds_ring
);
1280 err
= netxen_nic_request_irq(adapter
);
1282 dev_err(&pdev
->dev
, "%s: failed to setup interrupt\n",
1284 goto err_out_free_rxbuf
;
1287 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1288 netxen_nic_init_coalesce_defaults(adapter
);
1290 netxen_create_sysfs_entries(adapter
);
1292 adapter
->is_up
= NETXEN_ADAPTER_UP_MAGIC
;
1296 netxen_release_rx_buffers(adapter
);
1297 netxen_free_hw_resources(adapter
);
1299 netxen_free_sw_resources(adapter
);
1304 netxen_nic_detach(struct netxen_adapter
*adapter
)
1306 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1309 netxen_remove_sysfs_entries(adapter
);
1311 netxen_free_hw_resources(adapter
);
1312 netxen_release_rx_buffers(adapter
);
1313 netxen_nic_free_irq(adapter
);
1314 netxen_napi_del(adapter
);
1315 netxen_free_sw_resources(adapter
);
1321 netxen_nic_reset_context(struct netxen_adapter
*adapter
)
1324 struct net_device
*netdev
= adapter
->netdev
;
1326 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
1329 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
) {
1331 netif_device_detach(netdev
);
1333 if (netif_running(netdev
))
1334 __netxen_nic_down(adapter
, netdev
);
1336 netxen_nic_detach(adapter
);
1338 if (netif_running(netdev
)) {
1339 err
= netxen_nic_attach(adapter
);
1341 err
= __netxen_nic_up(adapter
, netdev
);
1347 netif_device_attach(netdev
);
1351 clear_bit(__NX_RESETTING
, &adapter
->state
);
1356 netxen_setup_netdev(struct netxen_adapter
*adapter
,
1357 struct net_device
*netdev
)
1360 struct pci_dev
*pdev
= adapter
->pdev
;
1362 adapter
->mc_enabled
= 0;
1363 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1364 adapter
->max_mc_count
= 38;
1366 adapter
->max_mc_count
= 16;
1368 netdev
->netdev_ops
= &netxen_netdev_ops
;
1369 netdev
->watchdog_timeo
= 5*HZ
;
1371 netxen_nic_change_mtu(netdev
, netdev
->mtu
);
1373 netdev
->ethtool_ops
= &netxen_nic_ethtool_ops
;
1375 netdev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_TSO
|
1378 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1379 netdev
->hw_features
|= NETIF_F_IPV6_CSUM
| NETIF_F_TSO6
;
1381 netdev
->vlan_features
|= netdev
->hw_features
;
1383 if (adapter
->pci_using_dac
) {
1384 netdev
->features
|= NETIF_F_HIGHDMA
;
1385 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
1388 if (adapter
->capabilities
& NX_FW_CAPABILITY_FVLANTX
)
1389 netdev
->hw_features
|= NETIF_F_HW_VLAN_CTAG_TX
;
1391 if (adapter
->capabilities
& NX_FW_CAPABILITY_HW_LRO
)
1392 netdev
->hw_features
|= NETIF_F_LRO
;
1394 netdev
->features
|= netdev
->hw_features
;
1396 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1398 INIT_WORK(&adapter
->tx_timeout_task
, netxen_tx_timeout_task
);
1400 if (netxen_read_mac_addr(adapter
))
1401 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1403 netif_carrier_off(netdev
);
1405 err
= register_netdev(netdev
);
1407 dev_err(&pdev
->dev
, "failed to register net device\n");
1414 #define NETXEN_ULA_ADAPTER_KEY (0xdaddad01)
1415 #define NETXEN_NON_ULA_ADAPTER_KEY (0xdaddad00)
1417 static void netxen_read_ula_info(struct netxen_adapter
*adapter
)
1421 /* Print ULA info only once for an adapter */
1422 if (adapter
->portnum
!= 0)
1425 temp
= NXRD32(adapter
, NETXEN_ULA_KEY
);
1427 case NETXEN_ULA_ADAPTER_KEY
:
1428 dev_info(&adapter
->pdev
->dev
, "ULA adapter");
1430 case NETXEN_NON_ULA_ADAPTER_KEY
:
1431 dev_info(&adapter
->pdev
->dev
, "non ULA adapter");
1440 #ifdef CONFIG_PCIEAER
1441 static void netxen_mask_aer_correctable(struct netxen_adapter
*adapter
)
1443 struct pci_dev
*pdev
= adapter
->pdev
;
1444 struct pci_dev
*root
= pdev
->bus
->self
;
1451 if (adapter
->ahw
.board_type
!= NETXEN_BRDTYPE_P3_4_GB_MM
&&
1452 adapter
->ahw
.board_type
!= NETXEN_BRDTYPE_P3_10G_TP
)
1455 if (pci_pcie_type(root
) != PCI_EXP_TYPE_ROOT_PORT
)
1458 aer_pos
= pci_find_ext_capability(root
, PCI_EXT_CAP_ID_ERR
);
1462 pci_write_config_dword(root
, aer_pos
+ PCI_ERR_COR_MASK
, 0xffff);
1467 netxen_nic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1469 struct net_device
*netdev
= NULL
;
1470 struct netxen_adapter
*adapter
= NULL
;
1472 int pci_func_id
= PCI_FUNC(pdev
->devfn
);
1473 uint8_t revision_id
;
1476 if (pdev
->revision
>= NX_P3_A0
&& pdev
->revision
<= NX_P3_B1
) {
1477 pr_warn("%s: chip revisions between 0x%x-0x%x will not be enabled\n",
1478 module_name(THIS_MODULE
), NX_P3_A0
, NX_P3_B1
);
1482 if ((err
= pci_enable_device(pdev
)))
1485 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1487 goto err_out_disable_pdev
;
1490 if ((err
= pci_request_regions(pdev
, netxen_nic_driver_name
)))
1491 goto err_out_disable_pdev
;
1493 if (NX_IS_REVISION_P3(pdev
->revision
))
1494 pci_enable_pcie_error_reporting(pdev
);
1496 pci_set_master(pdev
);
1498 netdev
= alloc_etherdev(sizeof(struct netxen_adapter
));
1501 goto err_out_free_res
;
1504 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1506 adapter
= netdev_priv(netdev
);
1507 adapter
->netdev
= netdev
;
1508 adapter
->pdev
= pdev
;
1509 adapter
->ahw
.pci_func
= pci_func_id
;
1511 revision_id
= pdev
->revision
;
1512 adapter
->ahw
.revision_id
= revision_id
;
1514 rwlock_init(&adapter
->ahw
.crb_lock
);
1515 spin_lock_init(&adapter
->ahw
.mem_lock
);
1517 spin_lock_init(&adapter
->tx_clean_lock
);
1518 INIT_LIST_HEAD(&adapter
->mac_list
);
1519 INIT_LIST_HEAD(&adapter
->ip_list
);
1521 err
= netxen_setup_pci_map(adapter
);
1523 goto err_out_free_netdev
;
1525 /* This will be reset for mezz cards */
1526 adapter
->portnum
= pci_func_id
;
1528 err
= netxen_nic_get_board_info(adapter
);
1530 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1531 goto err_out_iounmap
;
1534 #ifdef CONFIG_PCIEAER
1535 netxen_mask_aer_correctable(adapter
);
1538 /* Mezz cards have PCI function 0,2,3 enabled */
1539 switch (adapter
->ahw
.board_type
) {
1540 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
1541 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
1542 if (pci_func_id
>= 2)
1543 adapter
->portnum
= pci_func_id
- 2;
1549 err
= netxen_check_flash_fw_compatibility(adapter
);
1551 goto err_out_iounmap
;
1553 if (adapter
->portnum
== 0) {
1554 val
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
1555 if (val
!= 0xffffffff && val
!= 0) {
1556 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, 0);
1557 adapter
->need_fw_reset
= 1;
1561 err
= netxen_start_firmware(adapter
);
1563 goto err_out_decr_ref
;
1566 * See if the firmware gave us a virtual-physical port mapping.
1568 adapter
->physical_port
= adapter
->portnum
;
1569 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1570 i
= NXRD32(adapter
, CRB_V2P(adapter
->portnum
));
1571 if (i
!= 0x55555555)
1572 adapter
->physical_port
= i
;
1575 netxen_nic_clear_stats(adapter
);
1577 err
= netxen_setup_intr(adapter
);
1580 dev_err(&adapter
->pdev
->dev
,
1581 "Failed to setup interrupts, error = %d\n", err
);
1582 goto err_out_disable_msi
;
1585 netxen_read_ula_info(adapter
);
1587 err
= netxen_setup_netdev(adapter
, netdev
);
1589 goto err_out_disable_msi
;
1591 pci_set_drvdata(pdev
, adapter
);
1593 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1595 switch (adapter
->ahw
.port_type
) {
1596 case NETXEN_NIC_GBE
:
1597 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1598 adapter
->netdev
->name
);
1600 case NETXEN_NIC_XGBE
:
1601 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1602 adapter
->netdev
->name
);
1606 netxen_create_diag_entries(adapter
);
1610 err_out_disable_msi
:
1611 netxen_teardown_intr(adapter
);
1613 netxen_free_dummy_dma(adapter
);
1616 nx_decr_dev_ref_cnt(adapter
);
1619 netxen_cleanup_pci_map(adapter
);
1621 err_out_free_netdev
:
1622 free_netdev(netdev
);
1625 pci_release_regions(pdev
);
1627 err_out_disable_pdev
:
1628 pci_disable_device(pdev
);
1633 void netxen_cleanup_minidump(struct netxen_adapter
*adapter
)
1635 kfree(adapter
->mdump
.md_template
);
1636 adapter
->mdump
.md_template
= NULL
;
1638 if (adapter
->mdump
.md_capture_buff
) {
1639 vfree(adapter
->mdump
.md_capture_buff
);
1640 adapter
->mdump
.md_capture_buff
= NULL
;
1644 static void netxen_nic_remove(struct pci_dev
*pdev
)
1646 struct netxen_adapter
*adapter
;
1647 struct net_device
*netdev
;
1649 adapter
= pci_get_drvdata(pdev
);
1650 if (adapter
== NULL
)
1653 netdev
= adapter
->netdev
;
1655 netxen_cancel_fw_work(adapter
);
1657 unregister_netdev(netdev
);
1659 cancel_work_sync(&adapter
->tx_timeout_task
);
1661 netxen_free_ip_list(adapter
, false);
1662 netxen_nic_detach(adapter
);
1664 nx_decr_dev_ref_cnt(adapter
);
1666 if (adapter
->portnum
== 0)
1667 netxen_free_dummy_dma(adapter
);
1669 clear_bit(__NX_RESETTING
, &adapter
->state
);
1671 netxen_teardown_intr(adapter
);
1672 netxen_set_interrupt_mode(adapter
, 0);
1673 netxen_remove_diag_entries(adapter
);
1675 netxen_cleanup_pci_map(adapter
);
1677 netxen_release_firmware(adapter
);
1679 if (NX_IS_REVISION_P3(pdev
->revision
)) {
1680 netxen_cleanup_minidump(adapter
);
1681 pci_disable_pcie_error_reporting(pdev
);
1684 pci_release_regions(pdev
);
1685 pci_disable_device(pdev
);
1687 free_netdev(netdev
);
1690 static void netxen_nic_detach_func(struct netxen_adapter
*adapter
)
1692 struct net_device
*netdev
= adapter
->netdev
;
1694 netif_device_detach(netdev
);
1696 netxen_cancel_fw_work(adapter
);
1698 if (netif_running(netdev
))
1699 netxen_nic_down(adapter
, netdev
);
1701 cancel_work_sync(&adapter
->tx_timeout_task
);
1703 netxen_nic_detach(adapter
);
1705 if (adapter
->portnum
== 0)
1706 netxen_free_dummy_dma(adapter
);
1708 nx_decr_dev_ref_cnt(adapter
);
1710 clear_bit(__NX_RESETTING
, &adapter
->state
);
1713 static int netxen_nic_attach_func(struct pci_dev
*pdev
)
1715 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1716 struct net_device
*netdev
= adapter
->netdev
;
1719 err
= pci_enable_device(pdev
);
1723 pci_set_power_state(pdev
, PCI_D0
);
1724 pci_set_master(pdev
);
1725 pci_restore_state(pdev
);
1727 adapter
->ahw
.crb_win
= -1;
1728 adapter
->ahw
.ocm_win
= -1;
1730 err
= netxen_start_firmware(adapter
);
1732 dev_err(&pdev
->dev
, "failed to start firmware\n");
1736 if (netif_running(netdev
)) {
1737 err
= netxen_nic_attach(adapter
);
1741 err
= netxen_nic_up(adapter
, netdev
);
1743 goto err_out_detach
;
1745 netxen_restore_indev_addr(netdev
, NETDEV_UP
);
1748 netif_device_attach(netdev
);
1749 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1753 netxen_nic_detach(adapter
);
1755 nx_decr_dev_ref_cnt(adapter
);
1759 static pci_ers_result_t
netxen_io_error_detected(struct pci_dev
*pdev
,
1760 pci_channel_state_t state
)
1762 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1764 if (state
== pci_channel_io_perm_failure
)
1765 return PCI_ERS_RESULT_DISCONNECT
;
1767 if (nx_dev_request_aer(adapter
))
1768 return PCI_ERS_RESULT_RECOVERED
;
1770 netxen_nic_detach_func(adapter
);
1772 pci_disable_device(pdev
);
1774 return PCI_ERS_RESULT_NEED_RESET
;
1777 static pci_ers_result_t
netxen_io_slot_reset(struct pci_dev
*pdev
)
1781 err
= netxen_nic_attach_func(pdev
);
1783 return err
? PCI_ERS_RESULT_DISCONNECT
: PCI_ERS_RESULT_RECOVERED
;
1786 static void netxen_io_resume(struct pci_dev
*pdev
)
1788 pci_cleanup_aer_uncorrect_error_status(pdev
);
1791 static void netxen_nic_shutdown(struct pci_dev
*pdev
)
1793 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1795 netxen_nic_detach_func(adapter
);
1797 if (pci_save_state(pdev
))
1800 if (netxen_nic_wol_supported(adapter
)) {
1801 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1802 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1805 pci_disable_device(pdev
);
1810 netxen_nic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1812 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1815 netxen_nic_detach_func(adapter
);
1817 retval
= pci_save_state(pdev
);
1821 if (netxen_nic_wol_supported(adapter
)) {
1822 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1823 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1826 pci_disable_device(pdev
);
1827 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1833 netxen_nic_resume(struct pci_dev
*pdev
)
1835 return netxen_nic_attach_func(pdev
);
1839 static int netxen_nic_open(struct net_device
*netdev
)
1841 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1844 if (adapter
->driver_mismatch
)
1847 err
= netxen_nic_attach(adapter
);
1851 err
= __netxen_nic_up(adapter
, netdev
);
1855 netif_start_queue(netdev
);
1860 netxen_nic_detach(adapter
);
1865 * netxen_nic_close - Disables a network interface entry point
1867 static int netxen_nic_close(struct net_device
*netdev
)
1869 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1871 __netxen_nic_down(adapter
, netdev
);
1876 netxen_tso_check(struct net_device
*netdev
,
1877 struct nx_host_tx_ring
*tx_ring
,
1878 struct cmd_desc_type0
*first_desc
,
1879 struct sk_buff
*skb
)
1881 u8 opcode
= TX_ETHER_PKT
;
1882 __be16 protocol
= skb
->protocol
;
1883 u16 flags
= 0, vid
= 0;
1885 int copied
, offset
, copy_len
, hdr_len
= 0, tso
= 0, vlan_oob
= 0;
1886 struct cmd_desc_type0
*hwdesc
;
1887 struct vlan_ethhdr
*vh
;
1889 if (protocol
== cpu_to_be16(ETH_P_8021Q
)) {
1891 vh
= (struct vlan_ethhdr
*)skb
->data
;
1892 protocol
= vh
->h_vlan_encapsulated_proto
;
1893 flags
= FLAGS_VLAN_TAGGED
;
1895 } else if (skb_vlan_tag_present(skb
)) {
1896 flags
= FLAGS_VLAN_OOB
;
1897 vid
= skb_vlan_tag_get(skb
);
1898 netxen_set_tx_vlan_tci(first_desc
, vid
);
1902 if ((netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
1903 skb_shinfo(skb
)->gso_size
> 0) {
1905 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
1907 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
1908 first_desc
->total_hdr_length
= hdr_len
;
1910 first_desc
->total_hdr_length
+= VLAN_HLEN
;
1911 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
1912 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
1913 /* Only in case of TSO on vlan device */
1914 flags
|= FLAGS_VLAN_TAGGED
;
1917 opcode
= (protocol
== cpu_to_be16(ETH_P_IPV6
)) ?
1918 TX_TCP_LSO6
: TX_TCP_LSO
;
1921 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1924 if (protocol
== cpu_to_be16(ETH_P_IP
)) {
1925 l4proto
= ip_hdr(skb
)->protocol
;
1927 if (l4proto
== IPPROTO_TCP
)
1928 opcode
= TX_TCP_PKT
;
1929 else if(l4proto
== IPPROTO_UDP
)
1930 opcode
= TX_UDP_PKT
;
1931 } else if (protocol
== cpu_to_be16(ETH_P_IPV6
)) {
1932 l4proto
= ipv6_hdr(skb
)->nexthdr
;
1934 if (l4proto
== IPPROTO_TCP
)
1935 opcode
= TX_TCPV6_PKT
;
1936 else if(l4proto
== IPPROTO_UDP
)
1937 opcode
= TX_UDPV6_PKT
;
1941 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
1942 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
1943 netxen_set_tx_flags_opcode(first_desc
, flags
, opcode
);
1948 /* For LSO, we need to copy the MAC/IP/TCP headers into
1949 * the descriptor ring
1951 producer
= tx_ring
->producer
;
1956 /* Create a TSO vlan header template for firmware */
1958 hwdesc
= &tx_ring
->desc_head
[producer
];
1959 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1961 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1962 hdr_len
+ VLAN_HLEN
);
1964 vh
= (struct vlan_ethhdr
*)((char *)hwdesc
+ 2);
1965 skb_copy_from_linear_data(skb
, vh
, 12);
1966 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
1967 vh
->h_vlan_TCI
= htons(vid
);
1968 skb_copy_from_linear_data_offset(skb
, 12,
1969 (char *)vh
+ 16, copy_len
- 16);
1971 copied
= copy_len
- VLAN_HLEN
;
1974 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1977 while (copied
< hdr_len
) {
1979 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1980 (hdr_len
- copied
));
1982 hwdesc
= &tx_ring
->desc_head
[producer
];
1983 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1985 skb_copy_from_linear_data_offset(skb
, copied
,
1986 (char *)hwdesc
+ offset
, copy_len
);
1991 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1994 tx_ring
->producer
= producer
;
1999 netxen_map_tx_skb(struct pci_dev
*pdev
,
2000 struct sk_buff
*skb
, struct netxen_cmd_buffer
*pbuf
)
2002 struct netxen_skb_frag
*nf
;
2003 struct skb_frag_struct
*frag
;
2007 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2008 nf
= &pbuf
->frag_array
[0];
2010 map
= pci_map_single(pdev
, skb
->data
,
2011 skb_headlen(skb
), PCI_DMA_TODEVICE
);
2012 if (pci_dma_mapping_error(pdev
, map
))
2016 nf
->length
= skb_headlen(skb
);
2018 for (i
= 0; i
< nr_frags
; i
++) {
2019 frag
= &skb_shinfo(skb
)->frags
[i
];
2020 nf
= &pbuf
->frag_array
[i
+1];
2022 map
= skb_frag_dma_map(&pdev
->dev
, frag
, 0, skb_frag_size(frag
),
2024 if (dma_mapping_error(&pdev
->dev
, map
))
2028 nf
->length
= skb_frag_size(frag
);
2035 nf
= &pbuf
->frag_array
[i
+1];
2036 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
2040 nf
= &pbuf
->frag_array
[0];
2041 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
2049 netxen_clear_cmddesc(u64
*desc
)
2056 netxen_nic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2058 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2059 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2060 struct netxen_cmd_buffer
*pbuf
;
2061 struct netxen_skb_frag
*buffrag
;
2062 struct cmd_desc_type0
*hwdesc
, *first_desc
;
2063 struct pci_dev
*pdev
;
2066 struct skb_frag_struct
*frag
;
2069 int frag_count
, no_of_desc
;
2070 u32 num_txd
= tx_ring
->num_desc
;
2072 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
2074 /* 14 frags supported for normal packet and
2075 * 32 frags supported for TSO packet
2077 if (!skb_is_gso(skb
) && frag_count
> NETXEN_MAX_FRAGS_PER_TX
) {
2079 for (i
= 0; i
< (frag_count
- NETXEN_MAX_FRAGS_PER_TX
); i
++) {
2080 frag
= &skb_shinfo(skb
)->frags
[i
];
2081 delta
+= skb_frag_size(frag
);
2084 if (!__pskb_pull_tail(skb
, delta
))
2087 frag_count
= 1 + skb_shinfo(skb
)->nr_frags
;
2089 /* 4 fragments per cmd des */
2090 no_of_desc
= (frag_count
+ 3) >> 2;
2092 if (unlikely(netxen_tx_avail(tx_ring
) <= TX_STOP_THRESH
)) {
2093 netif_stop_queue(netdev
);
2095 if (netxen_tx_avail(tx_ring
) > TX_STOP_THRESH
)
2096 netif_start_queue(netdev
);
2098 return NETDEV_TX_BUSY
;
2101 producer
= tx_ring
->producer
;
2102 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
2104 pdev
= adapter
->pdev
;
2106 if (netxen_map_tx_skb(pdev
, skb
, pbuf
))
2110 pbuf
->frag_count
= frag_count
;
2112 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
2113 netxen_clear_cmddesc((u64
*)hwdesc
);
2115 netxen_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
2116 netxen_set_tx_port(first_desc
, adapter
->portnum
);
2118 for (i
= 0; i
< frag_count
; i
++) {
2122 if ((k
== 0) && (i
> 0)) {
2123 /* move to next desc.*/
2124 producer
= get_next_index(producer
, num_txd
);
2125 hwdesc
= &tx_ring
->desc_head
[producer
];
2126 netxen_clear_cmddesc((u64
*)hwdesc
);
2127 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2130 buffrag
= &pbuf
->frag_array
[i
];
2132 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
2135 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
2138 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
2141 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
2144 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
2149 tx_ring
->producer
= get_next_index(producer
, num_txd
);
2151 netxen_tso_check(netdev
, tx_ring
, first_desc
, skb
);
2153 adapter
->stats
.txbytes
+= skb
->len
;
2154 adapter
->stats
.xmitcalled
++;
2156 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
2158 return NETDEV_TX_OK
;
2161 adapter
->stats
.txdropped
++;
2162 dev_kfree_skb_any(skb
);
2163 return NETDEV_TX_OK
;
2166 static int netxen_nic_check_temp(struct netxen_adapter
*adapter
)
2168 struct net_device
*netdev
= adapter
->netdev
;
2169 uint32_t temp
, temp_state
, temp_val
;
2172 temp
= NXRD32(adapter
, CRB_TEMP_STATE
);
2174 temp_state
= nx_get_temp_state(temp
);
2175 temp_val
= nx_get_temp_val(temp
);
2177 if (temp_state
== NX_TEMP_PANIC
) {
2179 "%s: Device temperature %d degrees C exceeds"
2180 " maximum allowed. Hardware has been shut down.\n",
2181 netdev
->name
, temp_val
);
2183 } else if (temp_state
== NX_TEMP_WARN
) {
2184 if (adapter
->temp
== NX_TEMP_NORMAL
) {
2186 "%s: Device temperature %d degrees C "
2187 "exceeds operating range."
2188 " Immediate action needed.\n",
2189 netdev
->name
, temp_val
);
2192 if (adapter
->temp
== NX_TEMP_WARN
) {
2194 "%s: Device temperature is now %d degrees C"
2195 " in normal range.\n", netdev
->name
,
2199 adapter
->temp
= temp_state
;
2203 void netxen_advert_link_change(struct netxen_adapter
*adapter
, int linkup
)
2205 struct net_device
*netdev
= adapter
->netdev
;
2207 if (adapter
->ahw
.linkup
&& !linkup
) {
2208 printk(KERN_INFO
"%s: %s NIC Link is down\n",
2209 netxen_nic_driver_name
, netdev
->name
);
2210 adapter
->ahw
.linkup
= 0;
2211 if (netif_running(netdev
)) {
2212 netif_carrier_off(netdev
);
2213 netif_stop_queue(netdev
);
2215 adapter
->link_changed
= !adapter
->has_link_events
;
2216 } else if (!adapter
->ahw
.linkup
&& linkup
) {
2217 printk(KERN_INFO
"%s: %s NIC Link is up\n",
2218 netxen_nic_driver_name
, netdev
->name
);
2219 adapter
->ahw
.linkup
= 1;
2220 if (netif_running(netdev
)) {
2221 netif_carrier_on(netdev
);
2222 netif_wake_queue(netdev
);
2224 adapter
->link_changed
= !adapter
->has_link_events
;
2228 static void netxen_nic_handle_phy_intr(struct netxen_adapter
*adapter
)
2230 u32 val
, port
, linkup
;
2232 port
= adapter
->physical_port
;
2234 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
2235 val
= NXRD32(adapter
, CRB_XG_STATE_P3
);
2236 val
= XG_LINK_STATE_P3(adapter
->ahw
.pci_func
, val
);
2237 linkup
= (val
== XG_LINK_UP_P3
);
2239 val
= NXRD32(adapter
, CRB_XG_STATE
);
2240 val
= (val
>> port
*8) & 0xff;
2241 linkup
= (val
== XG_LINK_UP
);
2244 netxen_advert_link_change(adapter
, linkup
);
2247 static void netxen_tx_timeout(struct net_device
*netdev
)
2249 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2251 if (test_bit(__NX_RESETTING
, &adapter
->state
))
2254 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
2255 schedule_work(&adapter
->tx_timeout_task
);
2258 static void netxen_tx_timeout_task(struct work_struct
*work
)
2260 struct netxen_adapter
*adapter
=
2261 container_of(work
, struct netxen_adapter
, tx_timeout_task
);
2263 if (!netif_running(adapter
->netdev
))
2266 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2269 if (++adapter
->tx_timeo_cnt
>= NX_MAX_TX_TIMEOUTS
)
2273 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
2274 /* try to scrub interrupt */
2275 netxen_napi_disable(adapter
);
2277 netxen_napi_enable(adapter
);
2279 netif_wake_queue(adapter
->netdev
);
2281 clear_bit(__NX_RESETTING
, &adapter
->state
);
2283 clear_bit(__NX_RESETTING
, &adapter
->state
);
2284 if (netxen_nic_reset_context(adapter
)) {
2289 netif_trans_update(adapter
->netdev
);
2294 adapter
->need_fw_reset
= 1;
2295 clear_bit(__NX_RESETTING
, &adapter
->state
);
2298 static struct rtnl_link_stats64
*netxen_nic_get_stats(struct net_device
*netdev
,
2299 struct rtnl_link_stats64
*stats
)
2301 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2303 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
2304 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
2305 stats
->rx_bytes
= adapter
->stats
.rxbytes
;
2306 stats
->tx_bytes
= adapter
->stats
.txbytes
;
2307 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
2308 stats
->tx_dropped
= adapter
->stats
.txdropped
;
2313 static irqreturn_t
netxen_intr(int irq
, void *data
)
2315 struct nx_host_sds_ring
*sds_ring
= data
;
2316 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2319 status
= readl(adapter
->isr_int_vec
);
2321 if (!(status
& adapter
->int_vec_bit
))
2324 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
2325 /* check interrupt state machine, to be sure */
2326 status
= readl(adapter
->crb_int_state_reg
);
2327 if (!ISR_LEGACY_INT_TRIGGERED(status
))
2331 unsigned long our_int
= 0;
2333 our_int
= readl(adapter
->crb_int_state_reg
);
2335 /* not our interrupt */
2336 if (!test_and_clear_bit((7 + adapter
->portnum
), &our_int
))
2339 /* claim interrupt */
2340 writel((our_int
& 0xffffffff), adapter
->crb_int_state_reg
);
2342 /* clear interrupt */
2343 netxen_nic_disable_int(sds_ring
);
2346 writel(0xffffffff, adapter
->tgt_status_reg
);
2347 /* read twice to ensure write is flushed */
2348 readl(adapter
->isr_int_vec
);
2349 readl(adapter
->isr_int_vec
);
2351 napi_schedule(&sds_ring
->napi
);
2356 static irqreturn_t
netxen_msi_intr(int irq
, void *data
)
2358 struct nx_host_sds_ring
*sds_ring
= data
;
2359 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2361 /* clear interrupt */
2362 writel(0xffffffff, adapter
->tgt_status_reg
);
2364 napi_schedule(&sds_ring
->napi
);
2368 static irqreturn_t
netxen_msix_intr(int irq
, void *data
)
2370 struct nx_host_sds_ring
*sds_ring
= data
;
2372 napi_schedule(&sds_ring
->napi
);
2376 static int netxen_nic_poll(struct napi_struct
*napi
, int budget
)
2378 struct nx_host_sds_ring
*sds_ring
=
2379 container_of(napi
, struct nx_host_sds_ring
, napi
);
2381 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2386 tx_complete
= netxen_process_cmd_ring(adapter
);
2388 work_done
= netxen_process_rcv_ring(sds_ring
, budget
);
2393 if (work_done
< budget
) {
2394 napi_complete(&sds_ring
->napi
);
2395 if (test_bit(__NX_DEV_UP
, &adapter
->state
))
2396 netxen_nic_enable_int(sds_ring
);
2402 #ifdef CONFIG_NET_POLL_CONTROLLER
2403 static void netxen_nic_poll_controller(struct net_device
*netdev
)
2406 struct nx_host_sds_ring
*sds_ring
;
2407 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2408 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
2410 disable_irq(adapter
->irq
);
2411 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
2412 sds_ring
= &recv_ctx
->sds_rings
[ring
];
2413 netxen_intr(adapter
->irq
, sds_ring
);
2415 enable_irq(adapter
->irq
);
2420 nx_incr_dev_ref_cnt(struct netxen_adapter
*adapter
)
2423 if (netxen_api_lock(adapter
))
2426 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2428 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, ++count
);
2430 netxen_api_unlock(adapter
);
2435 nx_decr_dev_ref_cnt(struct netxen_adapter
*adapter
)
2438 if (netxen_api_lock(adapter
))
2441 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2442 WARN_ON(count
== 0);
2444 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, --count
);
2445 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2447 if (count
== 0 && state
!= NX_DEV_FAILED
)
2448 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_COLD
);
2450 netxen_api_unlock(adapter
);
2455 nx_dev_request_aer(struct netxen_adapter
*adapter
)
2460 if (netxen_api_lock(adapter
))
2463 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2465 if (state
== NX_DEV_NEED_AER
)
2467 else if (state
== NX_DEV_READY
) {
2468 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_NEED_AER
);
2472 netxen_api_unlock(adapter
);
2477 nx_dev_request_reset(struct netxen_adapter
*adapter
)
2482 if (netxen_api_lock(adapter
))
2485 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2487 if (state
== NX_DEV_NEED_RESET
|| state
== NX_DEV_FAILED
)
2489 else if (state
!= NX_DEV_INITALIZING
&& state
!= NX_DEV_NEED_AER
) {
2490 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_NEED_RESET
);
2491 adapter
->flags
|= NETXEN_FW_RESET_OWNER
;
2495 netxen_api_unlock(adapter
);
2501 netxen_can_start_firmware(struct netxen_adapter
*adapter
)
2506 if (netxen_api_lock(adapter
)) {
2507 nx_incr_dev_ref_cnt(adapter
);
2511 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2513 if ((count
< 0) || (count
>= NX_MAX_PCI_FUNC
))
2518 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_INITALIZING
);
2521 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, ++count
);
2523 netxen_api_unlock(adapter
);
2529 netxen_schedule_work(struct netxen_adapter
*adapter
,
2530 work_func_t func
, int delay
)
2532 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
2533 schedule_delayed_work(&adapter
->fw_work
, delay
);
2537 netxen_cancel_fw_work(struct netxen_adapter
*adapter
)
2539 while (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2542 cancel_delayed_work_sync(&adapter
->fw_work
);
2546 netxen_attach_work(struct work_struct
*work
)
2548 struct netxen_adapter
*adapter
= container_of(work
,
2549 struct netxen_adapter
, fw_work
.work
);
2550 struct net_device
*netdev
= adapter
->netdev
;
2553 if (netif_running(netdev
)) {
2554 err
= netxen_nic_attach(adapter
);
2558 err
= netxen_nic_up(adapter
, netdev
);
2560 netxen_nic_detach(adapter
);
2564 netxen_restore_indev_addr(netdev
, NETDEV_UP
);
2567 netif_device_attach(netdev
);
2570 adapter
->fw_fail_cnt
= 0;
2571 clear_bit(__NX_RESETTING
, &adapter
->state
);
2572 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
2576 netxen_fwinit_work(struct work_struct
*work
)
2578 struct netxen_adapter
*adapter
= container_of(work
,
2579 struct netxen_adapter
, fw_work
.work
);
2582 dev_state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2583 if (adapter
->flags
& NETXEN_FW_RESET_OWNER
) {
2584 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2585 WARN_ON(count
== 0);
2587 if (adapter
->mdump
.md_enabled
) {
2589 netxen_dump_fw(adapter
);
2592 adapter
->flags
&= ~NETXEN_FW_RESET_OWNER
;
2593 if (netxen_api_lock(adapter
)) {
2594 clear_bit(__NX_RESETTING
, &adapter
->state
);
2595 NXWR32(adapter
, NX_CRB_DEV_STATE
,
2599 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2600 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, --count
);
2601 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_COLD
);
2602 dev_state
= NX_DEV_COLD
;
2603 netxen_api_unlock(adapter
);
2607 switch (dev_state
) {
2610 if (!netxen_start_firmware(adapter
)) {
2611 netxen_schedule_work(adapter
, netxen_attach_work
, 0);
2616 case NX_DEV_NEED_RESET
:
2617 case NX_DEV_INITALIZING
:
2618 netxen_schedule_work(adapter
,
2619 netxen_fwinit_work
, 2 * FW_POLL_DELAY
);
2624 nx_incr_dev_ref_cnt(adapter
);
2628 if (netxen_api_lock(adapter
)) {
2629 clear_bit(__NX_RESETTING
, &adapter
->state
);
2632 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_FAILED
);
2633 netxen_api_unlock(adapter
);
2634 dev_err(&adapter
->pdev
->dev
, "%s: Device initialization Failed\n",
2635 adapter
->netdev
->name
);
2637 clear_bit(__NX_RESETTING
, &adapter
->state
);
2641 netxen_detach_work(struct work_struct
*work
)
2643 struct netxen_adapter
*adapter
= container_of(work
,
2644 struct netxen_adapter
, fw_work
.work
);
2645 struct net_device
*netdev
= adapter
->netdev
;
2646 int ref_cnt
= 0, delay
;
2649 netif_device_detach(netdev
);
2651 netxen_nic_down(adapter
, netdev
);
2654 netxen_nic_detach(adapter
);
2657 status
= NXRD32(adapter
, NETXEN_PEG_HALT_STATUS1
);
2659 if (status
& NX_RCODE_FATAL_ERROR
)
2662 if (adapter
->temp
== NX_TEMP_PANIC
)
2665 if (!(adapter
->flags
& NETXEN_FW_RESET_OWNER
))
2666 ref_cnt
= nx_decr_dev_ref_cnt(adapter
);
2668 if (ref_cnt
== -EIO
)
2671 delay
= (ref_cnt
== 0) ? 0 : (2 * FW_POLL_DELAY
);
2673 adapter
->fw_wait_cnt
= 0;
2674 netxen_schedule_work(adapter
, netxen_fwinit_work
, delay
);
2679 clear_bit(__NX_RESETTING
, &adapter
->state
);
2683 netxen_check_health(struct netxen_adapter
*adapter
)
2685 u32 state
, heartbit
;
2687 struct net_device
*netdev
= adapter
->netdev
;
2689 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2690 if (state
== NX_DEV_NEED_AER
)
2693 if (netxen_nic_check_temp(adapter
))
2696 if (adapter
->need_fw_reset
) {
2697 if (nx_dev_request_reset(adapter
))
2702 /* NX_DEV_NEED_RESET, this state can be marked in two cases
2703 * 1. Tx timeout 2. Fw hang
2704 * Send request to destroy context in case of tx timeout only
2705 * and doesn't required in case of Fw hang
2707 if (state
== NX_DEV_NEED_RESET
|| state
== NX_DEV_FAILED
) {
2708 adapter
->need_fw_reset
= 1;
2709 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2713 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2716 heartbit
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
2717 if (heartbit
!= adapter
->heartbit
) {
2718 adapter
->heartbit
= heartbit
;
2719 adapter
->fw_fail_cnt
= 0;
2720 if (adapter
->need_fw_reset
)
2725 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
2728 if (nx_dev_request_reset(adapter
))
2731 clear_bit(__NX_FW_ATTACHED
, &adapter
->state
);
2733 dev_err(&netdev
->dev
, "firmware hang detected\n");
2734 peg_status
= NXRD32(adapter
, NETXEN_PEG_HALT_STATUS1
);
2735 dev_err(&adapter
->pdev
->dev
, "Dumping hw/fw registers\n"
2736 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
2737 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
2738 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
2739 "PEG_NET_4_PC: 0x%x\n",
2741 NXRD32(adapter
, NETXEN_PEG_HALT_STATUS2
),
2742 NXRD32(adapter
, NETXEN_CRB_PEG_NET_0
+ 0x3c),
2743 NXRD32(adapter
, NETXEN_CRB_PEG_NET_1
+ 0x3c),
2744 NXRD32(adapter
, NETXEN_CRB_PEG_NET_2
+ 0x3c),
2745 NXRD32(adapter
, NETXEN_CRB_PEG_NET_3
+ 0x3c),
2746 NXRD32(adapter
, NETXEN_CRB_PEG_NET_4
+ 0x3c));
2747 if (NX_FWERROR_PEGSTAT1(peg_status
) == 0x67)
2748 dev_err(&adapter
->pdev
->dev
,
2749 "Firmware aborted with error code 0x00006700. "
2750 "Device is being reset.\n");
2752 if ((auto_fw_reset
== AUTO_FW_RESET_ENABLED
) &&
2753 !test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2754 netxen_schedule_work(adapter
, netxen_detach_work
, 0);
2759 netxen_fw_poll_work(struct work_struct
*work
)
2761 struct netxen_adapter
*adapter
= container_of(work
,
2762 struct netxen_adapter
, fw_work
.work
);
2764 if (test_bit(__NX_RESETTING
, &adapter
->state
))
2767 if (test_bit(__NX_DEV_UP
, &adapter
->state
) &&
2768 !(adapter
->capabilities
& NX_FW_CAPABILITY_LINK_NOTIFICATION
)) {
2769 if (!adapter
->has_link_events
) {
2771 netxen_nic_handle_phy_intr(adapter
);
2773 if (adapter
->link_changed
)
2774 netxen_nic_set_link_parameters(adapter
);
2778 if (netxen_check_health(adapter
))
2782 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
2786 netxen_store_bridged_mode(struct device
*dev
,
2787 struct device_attribute
*attr
, const char *buf
, size_t len
)
2789 struct net_device
*net
= to_net_dev(dev
);
2790 struct netxen_adapter
*adapter
= netdev_priv(net
);
2794 if (!(adapter
->capabilities
& NX_FW_CAPABILITY_BDG
))
2797 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
2800 if (kstrtoul(buf
, 2, &new))
2803 if (!netxen_config_bridged_mode(adapter
, !!new))
2811 netxen_show_bridged_mode(struct device
*dev
,
2812 struct device_attribute
*attr
, char *buf
)
2814 struct net_device
*net
= to_net_dev(dev
);
2815 struct netxen_adapter
*adapter
;
2816 int bridged_mode
= 0;
2818 adapter
= netdev_priv(net
);
2820 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
2821 bridged_mode
= !!(adapter
->flags
& NETXEN_NIC_BRIDGE_ENABLED
);
2823 return sprintf(buf
, "%d\n", bridged_mode
);
2826 static struct device_attribute dev_attr_bridged_mode
= {
2827 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2828 .show
= netxen_show_bridged_mode
,
2829 .store
= netxen_store_bridged_mode
,
2833 netxen_store_diag_mode(struct device
*dev
,
2834 struct device_attribute
*attr
, const char *buf
, size_t len
)
2836 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2839 if (kstrtoul(buf
, 2, &new))
2842 if (!!new != !!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2843 adapter
->flags
^= NETXEN_NIC_DIAG_ENABLED
;
2849 netxen_show_diag_mode(struct device
*dev
,
2850 struct device_attribute
*attr
, char *buf
)
2852 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2854 return sprintf(buf
, "%d\n",
2855 !!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
));
2858 static struct device_attribute dev_attr_diag_mode
= {
2859 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2860 .show
= netxen_show_diag_mode
,
2861 .store
= netxen_store_diag_mode
,
2865 netxen_sysfs_validate_crb(struct netxen_adapter
*adapter
,
2866 loff_t offset
, size_t size
)
2868 size_t crb_size
= 4;
2870 if (!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2873 if (offset
< NETXEN_PCI_CRBSPACE
) {
2874 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2877 if (ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2878 NETXEN_PCI_CAMQM_2M_END
))
2884 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
2891 netxen_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
2892 struct bin_attribute
*attr
,
2893 char *buf
, loff_t offset
, size_t size
)
2895 struct device
*dev
= kobj_to_dev(kobj
);
2896 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2901 ret
= netxen_sysfs_validate_crb(adapter
, offset
, size
);
2905 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) &&
2906 ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2907 NETXEN_PCI_CAMQM_2M_END
)) {
2908 netxen_pci_camqm_read_2M(adapter
, offset
, &qmdata
);
2909 memcpy(buf
, &qmdata
, size
);
2911 data
= NXRD32(adapter
, offset
);
2912 memcpy(buf
, &data
, size
);
2919 netxen_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
2920 struct bin_attribute
*attr
,
2921 char *buf
, loff_t offset
, size_t size
)
2923 struct device
*dev
= kobj_to_dev(kobj
);
2924 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2929 ret
= netxen_sysfs_validate_crb(adapter
, offset
, size
);
2933 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) &&
2934 ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2935 NETXEN_PCI_CAMQM_2M_END
)) {
2936 memcpy(&qmdata
, buf
, size
);
2937 netxen_pci_camqm_write_2M(adapter
, offset
, qmdata
);
2939 memcpy(&data
, buf
, size
);
2940 NXWR32(adapter
, offset
, data
);
2947 netxen_sysfs_validate_mem(struct netxen_adapter
*adapter
,
2948 loff_t offset
, size_t size
)
2950 if (!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2953 if ((size
!= 8) || (offset
& 0x7))
2960 netxen_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
2961 struct bin_attribute
*attr
,
2962 char *buf
, loff_t offset
, size_t size
)
2964 struct device
*dev
= kobj_to_dev(kobj
);
2965 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2969 ret
= netxen_sysfs_validate_mem(adapter
, offset
, size
);
2973 if (adapter
->pci_mem_read(adapter
, offset
, &data
))
2976 memcpy(buf
, &data
, size
);
2981 static ssize_t
netxen_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
2982 struct bin_attribute
*attr
, char *buf
,
2983 loff_t offset
, size_t size
)
2985 struct device
*dev
= kobj_to_dev(kobj
);
2986 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2990 ret
= netxen_sysfs_validate_mem(adapter
, offset
, size
);
2994 memcpy(&data
, buf
, size
);
2996 if (adapter
->pci_mem_write(adapter
, offset
, data
))
3003 static struct bin_attribute bin_attr_crb
= {
3004 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
3006 .read
= netxen_sysfs_read_crb
,
3007 .write
= netxen_sysfs_write_crb
,
3010 static struct bin_attribute bin_attr_mem
= {
3011 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
3013 .read
= netxen_sysfs_read_mem
,
3014 .write
= netxen_sysfs_write_mem
,
3018 netxen_sysfs_read_dimm(struct file
*filp
, struct kobject
*kobj
,
3019 struct bin_attribute
*attr
,
3020 char *buf
, loff_t offset
, size_t size
)
3022 struct device
*dev
= kobj_to_dev(kobj
);
3023 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
3024 struct net_device
*netdev
= adapter
->netdev
;
3025 struct netxen_dimm_cfg dimm
;
3026 u8 dw
, rows
, cols
, banks
, ranks
;
3029 if (size
< attr
->size
) {
3030 netdev_err(netdev
, "Invalid size\n");
3034 memset(&dimm
, 0, sizeof(struct netxen_dimm_cfg
));
3035 val
= NXRD32(adapter
, NETXEN_DIMM_CAPABILITY
);
3037 /* Checks if DIMM info is valid. */
3038 if (val
& NETXEN_DIMM_VALID_FLAG
) {
3039 netdev_err(netdev
, "Invalid DIMM flag\n");
3040 dimm
.presence
= 0xff;
3044 rows
= NETXEN_DIMM_NUMROWS(val
);
3045 cols
= NETXEN_DIMM_NUMCOLS(val
);
3046 ranks
= NETXEN_DIMM_NUMRANKS(val
);
3047 banks
= NETXEN_DIMM_NUMBANKS(val
);
3048 dw
= NETXEN_DIMM_DATAWIDTH(val
);
3050 dimm
.presence
= (val
& NETXEN_DIMM_PRESENT
);
3052 /* Checks if DIMM info is present. */
3053 if (!dimm
.presence
) {
3054 netdev_err(netdev
, "DIMM not present\n");
3058 dimm
.dimm_type
= NETXEN_DIMM_TYPE(val
);
3060 switch (dimm
.dimm_type
) {
3061 case NETXEN_DIMM_TYPE_RDIMM
:
3062 case NETXEN_DIMM_TYPE_UDIMM
:
3063 case NETXEN_DIMM_TYPE_SO_DIMM
:
3064 case NETXEN_DIMM_TYPE_Micro_DIMM
:
3065 case NETXEN_DIMM_TYPE_Mini_RDIMM
:
3066 case NETXEN_DIMM_TYPE_Mini_UDIMM
:
3069 netdev_err(netdev
, "Invalid DIMM type %x\n", dimm
.dimm_type
);
3073 if (val
& NETXEN_DIMM_MEMTYPE_DDR2_SDRAM
)
3074 dimm
.mem_type
= NETXEN_DIMM_MEM_DDR2_SDRAM
;
3076 dimm
.mem_type
= NETXEN_DIMM_MEMTYPE(val
);
3078 if (val
& NETXEN_DIMM_SIZE
) {
3079 dimm
.size
= NETXEN_DIMM_STD_MEM_SIZE
;
3084 netdev_err(netdev
, "Invalid no of rows %x\n", rows
);
3089 netdev_err(netdev
, "Invalid no of columns %x\n", cols
);
3094 netdev_err(netdev
, "Invalid no of banks %x\n", banks
);
3126 netdev_err(netdev
, "Invalid data-width %x\n", dw
);
3130 dimm
.size
= ((1 << rows
) * (1 << cols
) * dw
* banks
* ranks
) / 8;
3131 /* Size returned in MB. */
3132 dimm
.size
= (dimm
.size
) / 0x100000;
3134 memcpy(buf
, &dimm
, sizeof(struct netxen_dimm_cfg
));
3135 return sizeof(struct netxen_dimm_cfg
);
3139 static struct bin_attribute bin_attr_dimm
= {
3140 .attr
= { .name
= "dimm", .mode
= (S_IRUGO
| S_IWUSR
) },
3141 .size
= sizeof(struct netxen_dimm_cfg
),
3142 .read
= netxen_sysfs_read_dimm
,
3147 netxen_create_sysfs_entries(struct netxen_adapter
*adapter
)
3149 struct device
*dev
= &adapter
->pdev
->dev
;
3151 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
) {
3152 /* bridged_mode control */
3153 if (device_create_file(dev
, &dev_attr_bridged_mode
)) {
3155 "failed to create bridged_mode sysfs entry\n");
3161 netxen_remove_sysfs_entries(struct netxen_adapter
*adapter
)
3163 struct device
*dev
= &adapter
->pdev
->dev
;
3165 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
3166 device_remove_file(dev
, &dev_attr_bridged_mode
);
3170 netxen_create_diag_entries(struct netxen_adapter
*adapter
)
3172 struct pci_dev
*pdev
= adapter
->pdev
;
3176 if (device_create_file(dev
, &dev_attr_diag_mode
))
3177 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
3178 if (device_create_bin_file(dev
, &bin_attr_crb
))
3179 dev_info(dev
, "failed to create crb sysfs entry\n");
3180 if (device_create_bin_file(dev
, &bin_attr_mem
))
3181 dev_info(dev
, "failed to create mem sysfs entry\n");
3182 if (device_create_bin_file(dev
, &bin_attr_dimm
))
3183 dev_info(dev
, "failed to create dimm sysfs entry\n");
3188 netxen_remove_diag_entries(struct netxen_adapter
*adapter
)
3190 struct pci_dev
*pdev
= adapter
->pdev
;
3191 struct device
*dev
= &pdev
->dev
;
3193 device_remove_file(dev
, &dev_attr_diag_mode
);
3194 device_remove_bin_file(dev
, &bin_attr_crb
);
3195 device_remove_bin_file(dev
, &bin_attr_mem
);
3196 device_remove_bin_file(dev
, &bin_attr_dimm
);
3201 #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
3204 netxen_destip_supported(struct netxen_adapter
*adapter
)
3206 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
3209 if (adapter
->ahw
.cut_through
)
3216 netxen_free_ip_list(struct netxen_adapter
*adapter
, bool master
)
3218 struct nx_ip_list
*cur
, *tmp_cur
;
3220 list_for_each_entry_safe(cur
, tmp_cur
, &adapter
->ip_list
, list
) {
3223 netxen_config_ipaddr(adapter
, cur
->ip_addr
,
3225 list_del(&cur
->list
);
3229 netxen_config_ipaddr(adapter
, cur
->ip_addr
, NX_IP_DOWN
);
3230 list_del(&cur
->list
);
3237 netxen_list_config_ip(struct netxen_adapter
*adapter
,
3238 struct in_ifaddr
*ifa
, unsigned long event
)
3240 struct net_device
*dev
;
3241 struct nx_ip_list
*cur
, *tmp_cur
;
3242 struct list_head
*head
;
3245 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
3252 list_for_each(head
, &adapter
->ip_list
) {
3253 cur
= list_entry(head
, struct nx_ip_list
, list
);
3255 if (cur
->ip_addr
== ifa
->ifa_address
)
3259 cur
= kzalloc(sizeof(struct nx_ip_list
), GFP_ATOMIC
);
3262 if (dev
->priv_flags
& IFF_802_1Q_VLAN
)
3263 dev
= vlan_dev_real_dev(dev
);
3264 cur
->master
= !!netif_is_bond_master(dev
);
3265 cur
->ip_addr
= ifa
->ifa_address
;
3266 list_add_tail(&cur
->list
, &adapter
->ip_list
);
3267 netxen_config_ipaddr(adapter
, ifa
->ifa_address
, NX_IP_UP
);
3271 list_for_each_entry_safe(cur
, tmp_cur
,
3272 &adapter
->ip_list
, list
) {
3273 if (cur
->ip_addr
== ifa
->ifa_address
) {
3274 list_del(&cur
->list
);
3276 netxen_config_ipaddr(adapter
, ifa
->ifa_address
,
3288 netxen_config_indev_addr(struct netxen_adapter
*adapter
,
3289 struct net_device
*dev
, unsigned long event
)
3291 struct in_device
*indev
;
3293 if (!netxen_destip_supported(adapter
))
3296 indev
= in_dev_get(dev
);
3303 netxen_list_config_ip(adapter
, ifa
, NX_IP_UP
);
3306 netxen_list_config_ip(adapter
, ifa
, NX_IP_DOWN
);
3311 } endfor_ifa(indev
);
3317 netxen_restore_indev_addr(struct net_device
*netdev
, unsigned long event
)
3320 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
3321 struct nx_ip_list
*pos
, *tmp_pos
;
3322 unsigned long ip_event
;
3324 ip_event
= (event
== NETDEV_UP
) ? NX_IP_UP
: NX_IP_DOWN
;
3325 netxen_config_indev_addr(adapter
, netdev
, event
);
3327 list_for_each_entry_safe(pos
, tmp_pos
, &adapter
->ip_list
, list
) {
3328 netxen_config_ipaddr(adapter
, pos
->ip_addr
, ip_event
);
3333 netxen_config_checkdev(struct net_device
*dev
)
3335 struct netxen_adapter
*adapter
;
3337 if (!is_netxen_netdev(dev
))
3339 adapter
= netdev_priv(dev
);
3342 if (!netxen_destip_supported(adapter
))
3344 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
3351 * netxen_config_master - configure addresses based on master
3352 * @dev: netxen device
3353 * @event: netdev event
3355 static void netxen_config_master(struct net_device
*dev
, unsigned long event
)
3357 struct net_device
*master
, *slave
;
3358 struct netxen_adapter
*adapter
= netdev_priv(dev
);
3361 master
= netdev_master_upper_dev_get_rcu(dev
);
3363 * This is the case where the netxen nic is being
3364 * enslaved and is dev_open()ed in bond_enslave()
3365 * Now we should program the bond's (and its vlans')
3366 * addresses in the netxen NIC.
3368 if (master
&& netif_is_bond_master(master
) &&
3369 !netif_is_bond_slave(dev
)) {
3370 netxen_config_indev_addr(adapter
, master
, event
);
3371 for_each_netdev_rcu(&init_net
, slave
)
3372 if (slave
->priv_flags
& IFF_802_1Q_VLAN
&&
3373 vlan_dev_real_dev(slave
) == master
)
3374 netxen_config_indev_addr(adapter
, slave
, event
);
3378 * This is the case where the netxen nic is being
3379 * released and is dev_close()ed in bond_release()
3380 * just before IFF_BONDING is stripped.
3382 if (!master
&& dev
->priv_flags
& IFF_BONDING
)
3383 netxen_free_ip_list(adapter
, true);
3386 static int netxen_netdev_event(struct notifier_block
*this,
3387 unsigned long event
, void *ptr
)
3389 struct netxen_adapter
*adapter
;
3390 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
3391 struct net_device
*orig_dev
= dev
;
3392 struct net_device
*slave
;
3398 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3399 dev
= vlan_dev_real_dev(dev
);
3402 if (event
== NETDEV_UP
|| event
== NETDEV_DOWN
) {
3403 /* If this is a bonding device, look for netxen-based slaves*/
3404 if (netif_is_bond_master(dev
)) {
3406 for_each_netdev_in_bond_rcu(dev
, slave
) {
3407 if (!netxen_config_checkdev(slave
))
3409 adapter
= netdev_priv(slave
);
3410 netxen_config_indev_addr(adapter
,
3415 if (!netxen_config_checkdev(dev
))
3417 adapter
= netdev_priv(dev
);
3418 /* Act only if the actual netxen is the target */
3419 if (orig_dev
== dev
)
3420 netxen_config_master(dev
, event
);
3421 netxen_config_indev_addr(adapter
, orig_dev
, event
);
3429 netxen_inetaddr_event(struct notifier_block
*this,
3430 unsigned long event
, void *ptr
)
3432 struct netxen_adapter
*adapter
;
3433 struct net_device
*dev
, *slave
;
3434 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
3435 unsigned long ip_event
;
3437 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
3438 ip_event
= (event
== NETDEV_UP
) ? NX_IP_UP
: NX_IP_DOWN
;
3443 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3444 dev
= vlan_dev_real_dev(dev
);
3447 if (event
== NETDEV_UP
|| event
== NETDEV_DOWN
) {
3448 /* If this is a bonding device, look for netxen-based slaves*/
3449 if (netif_is_bond_master(dev
)) {
3451 for_each_netdev_in_bond_rcu(dev
, slave
) {
3452 if (!netxen_config_checkdev(slave
))
3454 adapter
= netdev_priv(slave
);
3455 netxen_list_config_ip(adapter
, ifa
, ip_event
);
3459 if (!netxen_config_checkdev(dev
))
3461 adapter
= netdev_priv(dev
);
3462 netxen_list_config_ip(adapter
, ifa
, ip_event
);
3469 static struct notifier_block netxen_netdev_cb
= {
3470 .notifier_call
= netxen_netdev_event
,
3473 static struct notifier_block netxen_inetaddr_cb
= {
3474 .notifier_call
= netxen_inetaddr_event
,
3478 netxen_restore_indev_addr(struct net_device
*dev
, unsigned long event
)
3481 netxen_free_ip_list(struct netxen_adapter
*adapter
, bool master
)
3485 static const struct pci_error_handlers netxen_err_handler
= {
3486 .error_detected
= netxen_io_error_detected
,
3487 .slot_reset
= netxen_io_slot_reset
,
3488 .resume
= netxen_io_resume
,
3491 static struct pci_driver netxen_driver
= {
3492 .name
= netxen_nic_driver_name
,
3493 .id_table
= netxen_pci_tbl
,
3494 .probe
= netxen_nic_probe
,
3495 .remove
= netxen_nic_remove
,
3497 .suspend
= netxen_nic_suspend
,
3498 .resume
= netxen_nic_resume
,
3500 .shutdown
= netxen_nic_shutdown
,
3501 .err_handler
= &netxen_err_handler
3504 static int __init
netxen_init_module(void)
3506 printk(KERN_INFO
"%s\n", netxen_nic_driver_string
);
3509 register_netdevice_notifier(&netxen_netdev_cb
);
3510 register_inetaddr_notifier(&netxen_inetaddr_cb
);
3512 return pci_register_driver(&netxen_driver
);
3515 module_init(netxen_init_module
);
3517 static void __exit
netxen_exit_module(void)
3519 pci_unregister_driver(&netxen_driver
);
3522 unregister_inetaddr_notifier(&netxen_inetaddr_cb
);
3523 unregister_netdevice_notifier(&netxen_netdev_cb
);
3527 module_exit(netxen_exit_module
);