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 DEFINE_PCI_DEVICE_TABLE(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 if (recv_ctx
->sds_rings
!= NULL
)
180 kfree(recv_ctx
->sds_rings
);
182 recv_ctx
->sds_rings
= NULL
;
186 netxen_napi_add(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
189 struct nx_host_sds_ring
*sds_ring
;
190 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
192 if (netxen_alloc_sds_rings(recv_ctx
, adapter
->max_sds_rings
))
195 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
196 sds_ring
= &recv_ctx
->sds_rings
[ring
];
197 netif_napi_add(netdev
, &sds_ring
->napi
,
198 netxen_nic_poll
, NAPI_POLL_WEIGHT
);
205 netxen_napi_del(struct netxen_adapter
*adapter
)
208 struct nx_host_sds_ring
*sds_ring
;
209 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
211 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
212 sds_ring
= &recv_ctx
->sds_rings
[ring
];
213 netif_napi_del(&sds_ring
->napi
);
216 netxen_free_sds_rings(&adapter
->recv_ctx
);
220 netxen_napi_enable(struct netxen_adapter
*adapter
)
223 struct nx_host_sds_ring
*sds_ring
;
224 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
226 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
227 sds_ring
= &recv_ctx
->sds_rings
[ring
];
228 napi_enable(&sds_ring
->napi
);
229 netxen_nic_enable_int(sds_ring
);
234 netxen_napi_disable(struct netxen_adapter
*adapter
)
237 struct nx_host_sds_ring
*sds_ring
;
238 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
240 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
241 sds_ring
= &recv_ctx
->sds_rings
[ring
];
242 netxen_nic_disable_int(sds_ring
);
243 napi_synchronize(&sds_ring
->napi
);
244 napi_disable(&sds_ring
->napi
);
248 static int nx_set_dma_mask(struct netxen_adapter
*adapter
)
250 struct pci_dev
*pdev
= adapter
->pdev
;
251 uint64_t mask
, cmask
;
253 adapter
->pci_using_dac
= 0;
255 mask
= DMA_BIT_MASK(32);
256 cmask
= DMA_BIT_MASK(32);
258 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
260 mask
= DMA_BIT_MASK(35);
263 mask
= DMA_BIT_MASK(39);
267 if (pci_set_dma_mask(pdev
, mask
) == 0 &&
268 pci_set_consistent_dma_mask(pdev
, cmask
) == 0) {
269 adapter
->pci_using_dac
= 1;
276 /* Update addressable range if firmware supports it */
278 nx_update_dma_mask(struct netxen_adapter
*adapter
)
280 int change
, shift
, err
;
281 uint64_t mask
, old_mask
, old_cmask
;
282 struct pci_dev
*pdev
= adapter
->pdev
;
286 shift
= NXRD32(adapter
, CRB_DMA_SHIFT
);
290 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) && (shift
> 9))
292 else if ((adapter
->ahw
.revision_id
== NX_P2_C1
) && (shift
<= 4))
296 old_mask
= pdev
->dma_mask
;
297 old_cmask
= pdev
->dev
.coherent_dma_mask
;
299 mask
= DMA_BIT_MASK(32+shift
);
301 err
= pci_set_dma_mask(pdev
, mask
);
305 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
307 err
= pci_set_consistent_dma_mask(pdev
, mask
);
311 dev_info(&pdev
->dev
, "using %d-bit dma mask\n", 32+shift
);
317 pci_set_dma_mask(pdev
, old_mask
);
318 pci_set_consistent_dma_mask(pdev
, old_cmask
);
323 netxen_check_hw_init(struct netxen_adapter
*adapter
, int first_boot
)
327 if (first_boot
== 0x55555555) {
328 /* This is the first boot after power up */
329 NXWR32(adapter
, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC
);
331 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
334 /* PCI bus master workaround */
335 first_boot
= NXRD32(adapter
, NETXEN_PCIE_REG(0x4));
336 if (!(first_boot
& 0x4)) {
338 NXWR32(adapter
, NETXEN_PCIE_REG(0x4), first_boot
);
339 NXRD32(adapter
, NETXEN_PCIE_REG(0x4));
342 /* This is the first boot after power up */
343 first_boot
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
);
344 if (first_boot
!= 0x80000f) {
345 /* clear the register for future unloads/loads */
346 NXWR32(adapter
, NETXEN_CAM_RAM(0x1fc), 0);
350 /* Start P2 boot loader */
351 val
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_PEGTUNE_DONE
);
352 NXWR32(adapter
, NETXEN_ROMUSB_GLB_PEGTUNE_DONE
, val
| 0x1);
356 val
= NXRD32(adapter
, NETXEN_CAM_RAM(0x1fc));
358 if (++timeout
> 5000)
361 } while (val
== NETXEN_BDINFO_MAGIC
);
366 static void netxen_set_port_mode(struct netxen_adapter
*adapter
)
370 val
= adapter
->ahw
.board_type
;
371 if ((val
== NETXEN_BRDTYPE_P3_HMEZ
) ||
372 (val
== NETXEN_BRDTYPE_P3_XG_LOM
)) {
373 if (port_mode
== NETXEN_PORT_MODE_802_3_AP
) {
374 data
= NETXEN_PORT_MODE_802_3_AP
;
375 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
376 } else if (port_mode
== NETXEN_PORT_MODE_XG
) {
377 data
= NETXEN_PORT_MODE_XG
;
378 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
379 } else if (port_mode
== NETXEN_PORT_MODE_AUTO_NEG_1G
) {
380 data
= NETXEN_PORT_MODE_AUTO_NEG_1G
;
381 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
382 } else if (port_mode
== NETXEN_PORT_MODE_AUTO_NEG_XG
) {
383 data
= NETXEN_PORT_MODE_AUTO_NEG_XG
;
384 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
386 data
= NETXEN_PORT_MODE_AUTO_NEG
;
387 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
390 if ((wol_port_mode
!= NETXEN_PORT_MODE_802_3_AP
) &&
391 (wol_port_mode
!= NETXEN_PORT_MODE_XG
) &&
392 (wol_port_mode
!= NETXEN_PORT_MODE_AUTO_NEG_1G
) &&
393 (wol_port_mode
!= NETXEN_PORT_MODE_AUTO_NEG_XG
)) {
394 wol_port_mode
= NETXEN_PORT_MODE_AUTO_NEG
;
396 NXWR32(adapter
, NETXEN_WOL_PORT_MODE
, wol_port_mode
);
400 #define PCI_CAP_ID_GEN 0x10
402 static void netxen_pcie_strap_init(struct netxen_adapter
*adapter
)
409 struct pci_dev
*pdev
;
411 pdev
= adapter
->pdev
;
413 chicken
= NXRD32(adapter
, NETXEN_PCIE_REG(PCIE_CHICKEN3
));
414 /* clear chicken3.25:24 */
415 chicken
&= 0xFCFFFFFF;
417 * if gen1 and B0, set F1020 - if gen 2, do nothing
418 * if gen2 set to F1000
420 pos
= pci_find_capability(pdev
, PCI_CAP_ID_GEN
);
422 pci_read_config_dword(pdev
, pos
+ 0x10, &control
);
423 if ((control
& 0x000F0000) != 0x00020000) {
424 /* set chicken3.24 if gen1 */
425 chicken
|= 0x01000000;
427 dev_info(&adapter
->pdev
->dev
, "Gen2 strapping detected\n");
430 /* set chicken3.24 if gen1 */
431 chicken
|= 0x01000000;
432 dev_info(&adapter
->pdev
->dev
, "Gen1 strapping detected\n");
433 if (adapter
->ahw
.revision_id
== NX_P3_B0
)
439 NXWR32(adapter
, NETXEN_PCIE_REG(PCIE_CHICKEN3
), chicken
);
444 pdevfuncsave
= pdev
->devfn
;
445 if (pdevfuncsave
& 0x07)
448 for (i
= 0; i
< 8; i
++) {
449 pci_read_config_dword(pdev
, pos
+ 8, &control
);
450 pci_read_config_dword(pdev
, pos
+ 8, &control
);
451 pci_write_config_dword(pdev
, pos
+ 8, c8c9value
);
454 pdev
->devfn
= pdevfuncsave
;
457 static void netxen_set_msix_bit(struct pci_dev
*pdev
, int enable
)
461 if (pdev
->msix_cap
) {
462 pci_read_config_dword(pdev
, pdev
->msix_cap
, &control
);
464 control
|= PCI_MSIX_FLAGS_ENABLE
;
467 pci_write_config_dword(pdev
, pdev
->msix_cap
, control
);
471 static void netxen_init_msix_entries(struct netxen_adapter
*adapter
, int count
)
475 for (i
= 0; i
< count
; i
++)
476 adapter
->msix_entries
[i
].entry
= i
;
480 netxen_read_mac_addr(struct netxen_adapter
*adapter
)
485 struct net_device
*netdev
= adapter
->netdev
;
486 struct pci_dev
*pdev
= adapter
->pdev
;
488 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
489 if (netxen_p3_get_mac_addr(adapter
, &mac_addr
) != 0)
492 if (netxen_get_flash_mac_addr(adapter
, &mac_addr
) != 0)
496 p
= (unsigned char *)&mac_addr
;
497 for (i
= 0; i
< 6; i
++)
498 netdev
->dev_addr
[i
] = *(p
+ 5 - i
);
500 memcpy(adapter
->mac_addr
, netdev
->dev_addr
, netdev
->addr_len
);
502 /* set station address */
504 if (!is_valid_ether_addr(netdev
->dev_addr
))
505 dev_warn(&pdev
->dev
, "Bad MAC address %pM.\n", netdev
->dev_addr
);
510 static int netxen_nic_set_mac(struct net_device
*netdev
, void *p
)
512 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
513 struct sockaddr
*addr
= p
;
515 if (!is_valid_ether_addr(addr
->sa_data
))
516 return -EADDRNOTAVAIL
;
518 if (netif_running(netdev
)) {
519 netif_device_detach(netdev
);
520 netxen_napi_disable(adapter
);
523 memcpy(adapter
->mac_addr
, addr
->sa_data
, netdev
->addr_len
);
524 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
525 adapter
->macaddr_set(adapter
, addr
->sa_data
);
527 if (netif_running(netdev
)) {
528 netif_device_attach(netdev
);
529 netxen_napi_enable(adapter
);
534 static void netxen_set_multicast_list(struct net_device
*dev
)
536 struct netxen_adapter
*adapter
= netdev_priv(dev
);
538 adapter
->set_multi(dev
);
541 static netdev_features_t
netxen_fix_features(struct net_device
*dev
,
542 netdev_features_t features
)
544 if (!(features
& NETIF_F_RXCSUM
)) {
545 netdev_info(dev
, "disabling LRO as RXCSUM is off\n");
547 features
&= ~NETIF_F_LRO
;
553 static int netxen_set_features(struct net_device
*dev
,
554 netdev_features_t features
)
556 struct netxen_adapter
*adapter
= netdev_priv(dev
);
559 if (!((dev
->features
^ features
) & NETIF_F_LRO
))
562 hw_lro
= (features
& NETIF_F_LRO
) ? NETXEN_NIC_LRO_ENABLED
563 : NETXEN_NIC_LRO_DISABLED
;
565 if (netxen_config_hw_lro(adapter
, hw_lro
))
568 if (!(features
& NETIF_F_LRO
) && netxen_send_lro_cleanup(adapter
))
574 static const struct net_device_ops netxen_netdev_ops
= {
575 .ndo_open
= netxen_nic_open
,
576 .ndo_stop
= netxen_nic_close
,
577 .ndo_start_xmit
= netxen_nic_xmit_frame
,
578 .ndo_get_stats64
= netxen_nic_get_stats
,
579 .ndo_validate_addr
= eth_validate_addr
,
580 .ndo_set_rx_mode
= netxen_set_multicast_list
,
581 .ndo_set_mac_address
= netxen_nic_set_mac
,
582 .ndo_change_mtu
= netxen_nic_change_mtu
,
583 .ndo_tx_timeout
= netxen_tx_timeout
,
584 .ndo_fix_features
= netxen_fix_features
,
585 .ndo_set_features
= netxen_set_features
,
586 #ifdef CONFIG_NET_POLL_CONTROLLER
587 .ndo_poll_controller
= netxen_nic_poll_controller
,
591 static inline bool netxen_function_zero(struct pci_dev
*pdev
)
593 return (PCI_FUNC(pdev
->devfn
) == 0) ? true : false;
596 static inline void netxen_set_interrupt_mode(struct netxen_adapter
*adapter
,
599 NXWR32(adapter
, NETXEN_INTR_MODE_REG
, mode
);
602 static inline u32
netxen_get_interrupt_mode(struct netxen_adapter
*adapter
)
604 return NXRD32(adapter
, NETXEN_INTR_MODE_REG
);
608 netxen_initialize_interrupt_registers(struct netxen_adapter
*adapter
)
610 struct netxen_legacy_intr_set
*legacy_intrp
;
611 u32 tgt_status_reg
, int_state_reg
;
613 if (adapter
->ahw
.revision_id
>= NX_P3_B0
)
614 legacy_intrp
= &legacy_intr
[adapter
->ahw
.pci_func
];
616 legacy_intrp
= &legacy_intr
[0];
618 tgt_status_reg
= legacy_intrp
->tgt_status_reg
;
619 int_state_reg
= ISR_INT_STATE_REG
;
621 adapter
->int_vec_bit
= legacy_intrp
->int_vec_bit
;
622 adapter
->tgt_status_reg
= netxen_get_ioaddr(adapter
, tgt_status_reg
);
623 adapter
->tgt_mask_reg
= netxen_get_ioaddr(adapter
,
624 legacy_intrp
->tgt_mask_reg
);
625 adapter
->pci_int_reg
= netxen_get_ioaddr(adapter
,
626 legacy_intrp
->pci_int_reg
);
627 adapter
->isr_int_vec
= netxen_get_ioaddr(adapter
, ISR_INT_VECTOR
);
629 if (adapter
->ahw
.revision_id
>= NX_P3_B1
)
630 adapter
->crb_int_state_reg
= netxen_get_ioaddr(adapter
,
633 adapter
->crb_int_state_reg
= netxen_get_ioaddr(adapter
,
637 static int netxen_setup_msi_interrupts(struct netxen_adapter
*adapter
,
640 struct pci_dev
*pdev
= adapter
->pdev
;
644 if (adapter
->msix_supported
) {
645 netxen_init_msix_entries(adapter
, num_msix
);
646 err
= pci_enable_msix(pdev
, adapter
->msix_entries
, num_msix
);
648 adapter
->flags
|= NETXEN_NIC_MSIX_ENABLED
;
649 netxen_set_msix_bit(pdev
, 1);
651 if (adapter
->rss_supported
)
652 adapter
->max_sds_rings
= num_msix
;
654 dev_info(&pdev
->dev
, "using msi-x interrupts\n");
657 /* fall through for msi */
660 if (use_msi
&& !pci_enable_msi(pdev
)) {
661 value
= msi_tgt_status
[adapter
->ahw
.pci_func
];
662 adapter
->flags
|= NETXEN_NIC_MSI_ENABLED
;
663 adapter
->tgt_status_reg
= netxen_get_ioaddr(adapter
, value
);
664 adapter
->msix_entries
[0].vector
= pdev
->irq
;
665 dev_info(&pdev
->dev
, "using msi interrupts\n");
669 dev_err(&pdev
->dev
, "Failed to acquire MSI-X/MSI interrupt vector\n");
673 static int netxen_setup_intr(struct netxen_adapter
*adapter
)
675 struct pci_dev
*pdev
= adapter
->pdev
;
678 if (adapter
->rss_supported
)
679 num_msix
= (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER
) ?
680 MSIX_ENTRIES_PER_ADAPTER
: 2;
684 adapter
->max_sds_rings
= 1;
685 adapter
->flags
&= ~(NETXEN_NIC_MSI_ENABLED
| NETXEN_NIC_MSIX_ENABLED
);
687 netxen_initialize_interrupt_registers(adapter
);
688 netxen_set_msix_bit(pdev
, 0);
690 if (netxen_function_zero(pdev
)) {
691 if (!netxen_setup_msi_interrupts(adapter
, num_msix
))
692 netxen_set_interrupt_mode(adapter
, NETXEN_MSI_MODE
);
694 netxen_set_interrupt_mode(adapter
, NETXEN_INTX_MODE
);
696 if (netxen_get_interrupt_mode(adapter
) == NETXEN_MSI_MODE
&&
697 netxen_setup_msi_interrupts(adapter
, num_msix
)) {
698 dev_err(&pdev
->dev
, "Co-existence of MSI-X/MSI and INTx interrupts is not supported\n");
703 if (!NETXEN_IS_MSI_FAMILY(adapter
)) {
704 adapter
->msix_entries
[0].vector
= pdev
->irq
;
705 dev_info(&pdev
->dev
, "using legacy interrupts\n");
711 netxen_teardown_intr(struct netxen_adapter
*adapter
)
713 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
714 pci_disable_msix(adapter
->pdev
);
715 if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
716 pci_disable_msi(adapter
->pdev
);
720 netxen_cleanup_pci_map(struct netxen_adapter
*adapter
)
722 if (adapter
->ahw
.db_base
!= NULL
)
723 iounmap(adapter
->ahw
.db_base
);
724 if (adapter
->ahw
.pci_base0
!= NULL
)
725 iounmap(adapter
->ahw
.pci_base0
);
726 if (adapter
->ahw
.pci_base1
!= NULL
)
727 iounmap(adapter
->ahw
.pci_base1
);
728 if (adapter
->ahw
.pci_base2
!= NULL
)
729 iounmap(adapter
->ahw
.pci_base2
);
733 netxen_setup_pci_map(struct netxen_adapter
*adapter
)
735 void __iomem
*db_ptr
= NULL
;
737 resource_size_t mem_base
, db_base
;
738 unsigned long mem_len
, db_len
= 0;
740 struct pci_dev
*pdev
= adapter
->pdev
;
741 int pci_func
= adapter
->ahw
.pci_func
;
742 struct netxen_hardware_context
*ahw
= &adapter
->ahw
;
747 * Set the CRB window to invalid. If any register in window 0 is
748 * accessed it should set the window to 0 and then reset it to 1.
750 adapter
->ahw
.crb_win
= -1;
751 adapter
->ahw
.ocm_win
= -1;
753 /* remap phys address */
754 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
755 mem_len
= pci_resource_len(pdev
, 0);
757 /* 128 Meg of memory */
758 if (mem_len
== NETXEN_PCI_128MB_SIZE
) {
760 ahw
->pci_base0
= ioremap(mem_base
, FIRST_PAGE_GROUP_SIZE
);
761 ahw
->pci_base1
= ioremap(mem_base
+ SECOND_PAGE_GROUP_START
,
762 SECOND_PAGE_GROUP_SIZE
);
763 ahw
->pci_base2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
,
764 THIRD_PAGE_GROUP_SIZE
);
765 if (ahw
->pci_base0
== NULL
|| ahw
->pci_base1
== NULL
||
766 ahw
->pci_base2
== NULL
) {
767 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
772 ahw
->pci_len0
= FIRST_PAGE_GROUP_SIZE
;
774 } else if (mem_len
== NETXEN_PCI_32MB_SIZE
) {
776 ahw
->pci_base1
= ioremap(mem_base
, SECOND_PAGE_GROUP_SIZE
);
777 ahw
->pci_base2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
-
778 SECOND_PAGE_GROUP_START
, THIRD_PAGE_GROUP_SIZE
);
779 if (ahw
->pci_base1
== NULL
|| ahw
->pci_base2
== NULL
) {
780 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
785 } else if (mem_len
== NETXEN_PCI_2MB_SIZE
) {
787 ahw
->pci_base0
= pci_ioremap_bar(pdev
, 0);
788 if (ahw
->pci_base0
== NULL
) {
789 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
792 ahw
->pci_len0
= mem_len
;
797 netxen_setup_hwops(adapter
);
799 dev_info(&pdev
->dev
, "%dMB memory map\n", (int)(mem_len
>>20));
801 if (NX_IS_REVISION_P3P(adapter
->ahw
.revision_id
)) {
802 adapter
->ahw
.ocm_win_crb
= netxen_get_ioaddr(adapter
,
803 NETXEN_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(pci_func
)));
805 } else if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
806 adapter
->ahw
.ocm_win_crb
= netxen_get_ioaddr(adapter
,
807 NETXEN_PCIX_PS_REG(PCIE_MN_WINDOW_REG(pci_func
)));
810 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
813 db_base
= pci_resource_start(pdev
, 4); /* doorbell is on bar 4 */
814 db_len
= pci_resource_len(pdev
, 4);
817 printk(KERN_ERR
"%s: doorbell is disabled\n",
818 netxen_nic_driver_name
);
823 db_ptr
= ioremap(db_base
, NETXEN_DB_MAPSIZE_BYTES
);
825 printk(KERN_ERR
"%s: Failed to allocate doorbell map.",
826 netxen_nic_driver_name
);
832 adapter
->ahw
.db_base
= db_ptr
;
833 adapter
->ahw
.db_len
= db_len
;
837 netxen_cleanup_pci_map(adapter
);
842 netxen_check_options(struct netxen_adapter
*adapter
)
844 u32 fw_major
, fw_minor
, fw_build
, prev_fw_version
;
845 char brd_name
[NETXEN_MAX_SHORT_NAME
];
847 int i
, offset
, val
, err
;
849 struct pci_dev
*pdev
= adapter
->pdev
;
851 adapter
->driver_mismatch
= 0;
853 ptr32
= (__le32
*)&serial_num
;
854 offset
= NX_FW_SERIAL_NUM_OFFSET
;
855 for (i
= 0; i
< 8; i
++) {
856 if (netxen_rom_fast_read(adapter
, offset
, &val
) == -1) {
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 spin_lock(&adapter
->tx_clean_lock
);
1189 netif_carrier_off(netdev
);
1190 netif_tx_disable(netdev
);
1192 if (adapter
->capabilities
& NX_FW_CAPABILITY_LINK_NOTIFICATION
)
1193 netxen_linkevent_request(adapter
, 0);
1195 if (adapter
->stop_port
)
1196 adapter
->stop_port(adapter
);
1198 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1199 netxen_p3_free_mac_list(adapter
);
1201 adapter
->set_promisc(adapter
, NETXEN_NIU_NON_PROMISC_MODE
);
1203 netxen_napi_disable(adapter
);
1205 netxen_release_tx_buffers(adapter
);
1206 spin_unlock(&adapter
->tx_clean_lock
);
1209 /* Usage: During suspend and firmware recovery module */
1212 netxen_nic_down(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1215 if (netif_running(netdev
))
1216 __netxen_nic_down(adapter
, netdev
);
1222 netxen_nic_attach(struct netxen_adapter
*adapter
)
1224 struct net_device
*netdev
= adapter
->netdev
;
1225 struct pci_dev
*pdev
= adapter
->pdev
;
1227 struct nx_host_rds_ring
*rds_ring
;
1228 struct nx_host_tx_ring
*tx_ring
;
1231 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
)
1234 err
= netxen_init_firmware(adapter
);
1238 adapter
->flags
&= ~NETXEN_FW_MSS_CAP
;
1239 if (adapter
->capabilities
& NX_FW_CAPABILITY_MORE_CAPS
) {
1240 capab2
= NXRD32(adapter
, CRB_FW_CAPABILITIES_2
);
1241 if (capab2
& NX_FW_CAPABILITY_2_LRO_MAX_TCP_SEG
)
1242 adapter
->flags
|= NETXEN_FW_MSS_CAP
;
1245 err
= netxen_napi_add(adapter
, netdev
);
1249 err
= netxen_alloc_sw_resources(adapter
);
1251 printk(KERN_ERR
"%s: Error in setting sw resources\n",
1256 err
= netxen_alloc_hw_resources(adapter
);
1258 printk(KERN_ERR
"%s: Error in setting hw resources\n",
1260 goto err_out_free_sw
;
1263 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1264 tx_ring
= adapter
->tx_ring
;
1265 tx_ring
->crb_cmd_producer
= netxen_get_ioaddr(adapter
,
1266 crb_cmd_producer
[adapter
->portnum
]);
1267 tx_ring
->crb_cmd_consumer
= netxen_get_ioaddr(adapter
,
1268 crb_cmd_consumer
[adapter
->portnum
]);
1270 tx_ring
->producer
= 0;
1271 tx_ring
->sw_consumer
= 0;
1273 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
1274 netxen_nic_update_cmd_consumer(adapter
, tx_ring
);
1277 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1278 rds_ring
= &adapter
->recv_ctx
.rds_rings
[ring
];
1279 netxen_post_rx_buffers(adapter
, ring
, rds_ring
);
1282 err
= netxen_nic_request_irq(adapter
);
1284 dev_err(&pdev
->dev
, "%s: failed to setup interrupt\n",
1286 goto err_out_free_rxbuf
;
1289 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1290 netxen_nic_init_coalesce_defaults(adapter
);
1292 netxen_create_sysfs_entries(adapter
);
1294 adapter
->is_up
= NETXEN_ADAPTER_UP_MAGIC
;
1298 netxen_release_rx_buffers(adapter
);
1299 netxen_free_hw_resources(adapter
);
1301 netxen_free_sw_resources(adapter
);
1306 netxen_nic_detach(struct netxen_adapter
*adapter
)
1308 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1311 netxen_remove_sysfs_entries(adapter
);
1313 netxen_free_hw_resources(adapter
);
1314 netxen_release_rx_buffers(adapter
);
1315 netxen_nic_free_irq(adapter
);
1316 netxen_napi_del(adapter
);
1317 netxen_free_sw_resources(adapter
);
1323 netxen_nic_reset_context(struct netxen_adapter
*adapter
)
1326 struct net_device
*netdev
= adapter
->netdev
;
1328 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
1331 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
) {
1333 netif_device_detach(netdev
);
1335 if (netif_running(netdev
))
1336 __netxen_nic_down(adapter
, netdev
);
1338 netxen_nic_detach(adapter
);
1340 if (netif_running(netdev
)) {
1341 err
= netxen_nic_attach(adapter
);
1343 err
= __netxen_nic_up(adapter
, netdev
);
1349 netif_device_attach(netdev
);
1353 clear_bit(__NX_RESETTING
, &adapter
->state
);
1358 netxen_setup_netdev(struct netxen_adapter
*adapter
,
1359 struct net_device
*netdev
)
1362 struct pci_dev
*pdev
= adapter
->pdev
;
1364 adapter
->mc_enabled
= 0;
1365 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1366 adapter
->max_mc_count
= 38;
1368 adapter
->max_mc_count
= 16;
1370 netdev
->netdev_ops
= &netxen_netdev_ops
;
1371 netdev
->watchdog_timeo
= 5*HZ
;
1373 netxen_nic_change_mtu(netdev
, netdev
->mtu
);
1375 SET_ETHTOOL_OPS(netdev
, &netxen_nic_ethtool_ops
);
1377 netdev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_TSO
|
1380 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1381 netdev
->hw_features
|= NETIF_F_IPV6_CSUM
| NETIF_F_TSO6
;
1383 netdev
->vlan_features
|= netdev
->hw_features
;
1385 if (adapter
->pci_using_dac
) {
1386 netdev
->features
|= NETIF_F_HIGHDMA
;
1387 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
1390 if (adapter
->capabilities
& NX_FW_CAPABILITY_FVLANTX
)
1391 netdev
->hw_features
|= NETIF_F_HW_VLAN_CTAG_TX
;
1393 if (adapter
->capabilities
& NX_FW_CAPABILITY_HW_LRO
)
1394 netdev
->hw_features
|= NETIF_F_LRO
;
1396 netdev
->features
|= netdev
->hw_features
;
1398 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1400 INIT_WORK(&adapter
->tx_timeout_task
, netxen_tx_timeout_task
);
1402 if (netxen_read_mac_addr(adapter
))
1403 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1405 netif_carrier_off(netdev
);
1407 err
= register_netdev(netdev
);
1409 dev_err(&pdev
->dev
, "failed to register net device\n");
1416 #define NETXEN_ULA_ADAPTER_KEY (0xdaddad01)
1417 #define NETXEN_NON_ULA_ADAPTER_KEY (0xdaddad00)
1419 static void netxen_read_ula_info(struct netxen_adapter
*adapter
)
1423 /* Print ULA info only once for an adapter */
1424 if (adapter
->portnum
!= 0)
1427 temp
= NXRD32(adapter
, NETXEN_ULA_KEY
);
1429 case NETXEN_ULA_ADAPTER_KEY
:
1430 dev_info(&adapter
->pdev
->dev
, "ULA adapter");
1432 case NETXEN_NON_ULA_ADAPTER_KEY
:
1433 dev_info(&adapter
->pdev
->dev
, "non ULA adapter");
1442 #ifdef CONFIG_PCIEAER
1443 static void netxen_mask_aer_correctable(struct netxen_adapter
*adapter
)
1445 struct pci_dev
*pdev
= adapter
->pdev
;
1446 struct pci_dev
*root
= pdev
->bus
->self
;
1453 if (adapter
->ahw
.board_type
!= NETXEN_BRDTYPE_P3_4_GB_MM
&&
1454 adapter
->ahw
.board_type
!= NETXEN_BRDTYPE_P3_10G_TP
)
1457 if (pci_pcie_type(root
) != PCI_EXP_TYPE_ROOT_PORT
)
1460 aer_pos
= pci_find_ext_capability(root
, PCI_EXT_CAP_ID_ERR
);
1464 pci_write_config_dword(root
, aer_pos
+ PCI_ERR_COR_MASK
, 0xffff);
1469 netxen_nic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1471 struct net_device
*netdev
= NULL
;
1472 struct netxen_adapter
*adapter
= NULL
;
1474 int pci_func_id
= PCI_FUNC(pdev
->devfn
);
1475 uint8_t revision_id
;
1478 if (pdev
->revision
>= NX_P3_A0
&& pdev
->revision
<= NX_P3_B1
) {
1479 pr_warning("%s: chip revisions between 0x%x-0x%x "
1480 "will not be enabled.\n",
1481 module_name(THIS_MODULE
), NX_P3_A0
, NX_P3_B1
);
1485 if ((err
= pci_enable_device(pdev
)))
1488 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1490 goto err_out_disable_pdev
;
1493 if ((err
= pci_request_regions(pdev
, netxen_nic_driver_name
)))
1494 goto err_out_disable_pdev
;
1496 if (NX_IS_REVISION_P3(pdev
->revision
))
1497 pci_enable_pcie_error_reporting(pdev
);
1499 pci_set_master(pdev
);
1501 netdev
= alloc_etherdev(sizeof(struct netxen_adapter
));
1504 goto err_out_free_res
;
1507 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1509 adapter
= netdev_priv(netdev
);
1510 adapter
->netdev
= netdev
;
1511 adapter
->pdev
= pdev
;
1512 adapter
->ahw
.pci_func
= pci_func_id
;
1514 revision_id
= pdev
->revision
;
1515 adapter
->ahw
.revision_id
= revision_id
;
1517 rwlock_init(&adapter
->ahw
.crb_lock
);
1518 spin_lock_init(&adapter
->ahw
.mem_lock
);
1520 spin_lock_init(&adapter
->tx_clean_lock
);
1521 INIT_LIST_HEAD(&adapter
->mac_list
);
1522 INIT_LIST_HEAD(&adapter
->ip_list
);
1524 err
= netxen_setup_pci_map(adapter
);
1526 goto err_out_free_netdev
;
1528 /* This will be reset for mezz cards */
1529 adapter
->portnum
= pci_func_id
;
1531 err
= netxen_nic_get_board_info(adapter
);
1533 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1534 goto err_out_iounmap
;
1537 #ifdef CONFIG_PCIEAER
1538 netxen_mask_aer_correctable(adapter
);
1541 /* Mezz cards have PCI function 0,2,3 enabled */
1542 switch (adapter
->ahw
.board_type
) {
1543 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
1544 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
1545 if (pci_func_id
>= 2)
1546 adapter
->portnum
= pci_func_id
- 2;
1552 err
= netxen_check_flash_fw_compatibility(adapter
);
1554 goto err_out_iounmap
;
1556 if (adapter
->portnum
== 0) {
1557 val
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
1558 if (val
!= 0xffffffff && val
!= 0) {
1559 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, 0);
1560 adapter
->need_fw_reset
= 1;
1564 err
= netxen_start_firmware(adapter
);
1566 goto err_out_decr_ref
;
1569 * See if the firmware gave us a virtual-physical port mapping.
1571 adapter
->physical_port
= adapter
->portnum
;
1572 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1573 i
= NXRD32(adapter
, CRB_V2P(adapter
->portnum
));
1574 if (i
!= 0x55555555)
1575 adapter
->physical_port
= i
;
1578 netxen_nic_clear_stats(adapter
);
1580 err
= netxen_setup_intr(adapter
);
1583 dev_err(&adapter
->pdev
->dev
,
1584 "Failed to setup interrupts, error = %d\n", err
);
1585 goto err_out_disable_msi
;
1588 netxen_read_ula_info(adapter
);
1590 err
= netxen_setup_netdev(adapter
, netdev
);
1592 goto err_out_disable_msi
;
1594 pci_set_drvdata(pdev
, adapter
);
1596 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1598 switch (adapter
->ahw
.port_type
) {
1599 case NETXEN_NIC_GBE
:
1600 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1601 adapter
->netdev
->name
);
1603 case NETXEN_NIC_XGBE
:
1604 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1605 adapter
->netdev
->name
);
1609 netxen_create_diag_entries(adapter
);
1613 err_out_disable_msi
:
1614 netxen_teardown_intr(adapter
);
1616 netxen_free_dummy_dma(adapter
);
1619 nx_decr_dev_ref_cnt(adapter
);
1622 netxen_cleanup_pci_map(adapter
);
1624 err_out_free_netdev
:
1625 free_netdev(netdev
);
1628 pci_release_regions(pdev
);
1630 err_out_disable_pdev
:
1631 pci_disable_device(pdev
);
1636 void netxen_cleanup_minidump(struct netxen_adapter
*adapter
)
1638 kfree(adapter
->mdump
.md_template
);
1639 adapter
->mdump
.md_template
= NULL
;
1641 if (adapter
->mdump
.md_capture_buff
) {
1642 vfree(adapter
->mdump
.md_capture_buff
);
1643 adapter
->mdump
.md_capture_buff
= NULL
;
1647 static void netxen_nic_remove(struct pci_dev
*pdev
)
1649 struct netxen_adapter
*adapter
;
1650 struct net_device
*netdev
;
1652 adapter
= pci_get_drvdata(pdev
);
1653 if (adapter
== NULL
)
1656 netdev
= adapter
->netdev
;
1658 netxen_cancel_fw_work(adapter
);
1660 unregister_netdev(netdev
);
1662 cancel_work_sync(&adapter
->tx_timeout_task
);
1664 netxen_free_ip_list(adapter
, false);
1665 netxen_nic_detach(adapter
);
1667 nx_decr_dev_ref_cnt(adapter
);
1669 if (adapter
->portnum
== 0)
1670 netxen_free_dummy_dma(adapter
);
1672 clear_bit(__NX_RESETTING
, &adapter
->state
);
1674 netxen_teardown_intr(adapter
);
1675 netxen_set_interrupt_mode(adapter
, 0);
1676 netxen_remove_diag_entries(adapter
);
1678 netxen_cleanup_pci_map(adapter
);
1680 netxen_release_firmware(adapter
);
1682 if (NX_IS_REVISION_P3(pdev
->revision
)) {
1683 netxen_cleanup_minidump(adapter
);
1684 pci_disable_pcie_error_reporting(pdev
);
1687 pci_release_regions(pdev
);
1688 pci_disable_device(pdev
);
1690 free_netdev(netdev
);
1693 static void netxen_nic_detach_func(struct netxen_adapter
*adapter
)
1695 struct net_device
*netdev
= adapter
->netdev
;
1697 netif_device_detach(netdev
);
1699 netxen_cancel_fw_work(adapter
);
1701 if (netif_running(netdev
))
1702 netxen_nic_down(adapter
, netdev
);
1704 cancel_work_sync(&adapter
->tx_timeout_task
);
1706 netxen_nic_detach(adapter
);
1708 if (adapter
->portnum
== 0)
1709 netxen_free_dummy_dma(adapter
);
1711 nx_decr_dev_ref_cnt(adapter
);
1713 clear_bit(__NX_RESETTING
, &adapter
->state
);
1716 static int netxen_nic_attach_func(struct pci_dev
*pdev
)
1718 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1719 struct net_device
*netdev
= adapter
->netdev
;
1722 err
= pci_enable_device(pdev
);
1726 pci_set_power_state(pdev
, PCI_D0
);
1727 pci_set_master(pdev
);
1728 pci_restore_state(pdev
);
1730 adapter
->ahw
.crb_win
= -1;
1731 adapter
->ahw
.ocm_win
= -1;
1733 err
= netxen_start_firmware(adapter
);
1735 dev_err(&pdev
->dev
, "failed to start firmware\n");
1739 if (netif_running(netdev
)) {
1740 err
= netxen_nic_attach(adapter
);
1744 err
= netxen_nic_up(adapter
, netdev
);
1746 goto err_out_detach
;
1748 netxen_restore_indev_addr(netdev
, NETDEV_UP
);
1751 netif_device_attach(netdev
);
1752 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1756 netxen_nic_detach(adapter
);
1758 nx_decr_dev_ref_cnt(adapter
);
1762 static pci_ers_result_t
netxen_io_error_detected(struct pci_dev
*pdev
,
1763 pci_channel_state_t state
)
1765 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1767 if (state
== pci_channel_io_perm_failure
)
1768 return PCI_ERS_RESULT_DISCONNECT
;
1770 if (nx_dev_request_aer(adapter
))
1771 return PCI_ERS_RESULT_RECOVERED
;
1773 netxen_nic_detach_func(adapter
);
1775 pci_disable_device(pdev
);
1777 return PCI_ERS_RESULT_NEED_RESET
;
1780 static pci_ers_result_t
netxen_io_slot_reset(struct pci_dev
*pdev
)
1784 err
= netxen_nic_attach_func(pdev
);
1786 return err
? PCI_ERS_RESULT_DISCONNECT
: PCI_ERS_RESULT_RECOVERED
;
1789 static void netxen_io_resume(struct pci_dev
*pdev
)
1791 pci_cleanup_aer_uncorrect_error_status(pdev
);
1794 static void netxen_nic_shutdown(struct pci_dev
*pdev
)
1796 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1798 netxen_nic_detach_func(adapter
);
1800 if (pci_save_state(pdev
))
1803 if (netxen_nic_wol_supported(adapter
)) {
1804 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1805 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1808 pci_disable_device(pdev
);
1813 netxen_nic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1815 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1818 netxen_nic_detach_func(adapter
);
1820 retval
= pci_save_state(pdev
);
1824 if (netxen_nic_wol_supported(adapter
)) {
1825 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1826 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1829 pci_disable_device(pdev
);
1830 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1836 netxen_nic_resume(struct pci_dev
*pdev
)
1838 return netxen_nic_attach_func(pdev
);
1842 static int netxen_nic_open(struct net_device
*netdev
)
1844 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1847 if (adapter
->driver_mismatch
)
1850 err
= netxen_nic_attach(adapter
);
1854 err
= __netxen_nic_up(adapter
, netdev
);
1858 netif_start_queue(netdev
);
1863 netxen_nic_detach(adapter
);
1868 * netxen_nic_close - Disables a network interface entry point
1870 static int netxen_nic_close(struct net_device
*netdev
)
1872 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1874 __netxen_nic_down(adapter
, netdev
);
1879 netxen_tso_check(struct net_device
*netdev
,
1880 struct nx_host_tx_ring
*tx_ring
,
1881 struct cmd_desc_type0
*first_desc
,
1882 struct sk_buff
*skb
)
1884 u8 opcode
= TX_ETHER_PKT
;
1885 __be16 protocol
= skb
->protocol
;
1886 u16 flags
= 0, vid
= 0;
1888 int copied
, offset
, copy_len
, hdr_len
= 0, tso
= 0, vlan_oob
= 0;
1889 struct cmd_desc_type0
*hwdesc
;
1890 struct vlan_ethhdr
*vh
;
1892 if (protocol
== cpu_to_be16(ETH_P_8021Q
)) {
1894 vh
= (struct vlan_ethhdr
*)skb
->data
;
1895 protocol
= vh
->h_vlan_encapsulated_proto
;
1896 flags
= FLAGS_VLAN_TAGGED
;
1898 } else if (vlan_tx_tag_present(skb
)) {
1899 flags
= FLAGS_VLAN_OOB
;
1900 vid
= vlan_tx_tag_get(skb
);
1901 netxen_set_tx_vlan_tci(first_desc
, vid
);
1905 if ((netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
1906 skb_shinfo(skb
)->gso_size
> 0) {
1908 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
1910 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
1911 first_desc
->total_hdr_length
= hdr_len
;
1913 first_desc
->total_hdr_length
+= VLAN_HLEN
;
1914 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
1915 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
1916 /* Only in case of TSO on vlan device */
1917 flags
|= FLAGS_VLAN_TAGGED
;
1920 opcode
= (protocol
== cpu_to_be16(ETH_P_IPV6
)) ?
1921 TX_TCP_LSO6
: TX_TCP_LSO
;
1924 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1927 if (protocol
== cpu_to_be16(ETH_P_IP
)) {
1928 l4proto
= ip_hdr(skb
)->protocol
;
1930 if (l4proto
== IPPROTO_TCP
)
1931 opcode
= TX_TCP_PKT
;
1932 else if(l4proto
== IPPROTO_UDP
)
1933 opcode
= TX_UDP_PKT
;
1934 } else if (protocol
== cpu_to_be16(ETH_P_IPV6
)) {
1935 l4proto
= ipv6_hdr(skb
)->nexthdr
;
1937 if (l4proto
== IPPROTO_TCP
)
1938 opcode
= TX_TCPV6_PKT
;
1939 else if(l4proto
== IPPROTO_UDP
)
1940 opcode
= TX_UDPV6_PKT
;
1944 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
1945 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
1946 netxen_set_tx_flags_opcode(first_desc
, flags
, opcode
);
1951 /* For LSO, we need to copy the MAC/IP/TCP headers into
1952 * the descriptor ring
1954 producer
= tx_ring
->producer
;
1959 /* Create a TSO vlan header template for firmware */
1961 hwdesc
= &tx_ring
->desc_head
[producer
];
1962 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1964 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1965 hdr_len
+ VLAN_HLEN
);
1967 vh
= (struct vlan_ethhdr
*)((char *)hwdesc
+ 2);
1968 skb_copy_from_linear_data(skb
, vh
, 12);
1969 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
1970 vh
->h_vlan_TCI
= htons(vid
);
1971 skb_copy_from_linear_data_offset(skb
, 12,
1972 (char *)vh
+ 16, copy_len
- 16);
1974 copied
= copy_len
- VLAN_HLEN
;
1977 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1980 while (copied
< hdr_len
) {
1982 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1983 (hdr_len
- copied
));
1985 hwdesc
= &tx_ring
->desc_head
[producer
];
1986 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1988 skb_copy_from_linear_data_offset(skb
, copied
,
1989 (char *)hwdesc
+ offset
, copy_len
);
1994 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1997 tx_ring
->producer
= producer
;
2002 netxen_map_tx_skb(struct pci_dev
*pdev
,
2003 struct sk_buff
*skb
, struct netxen_cmd_buffer
*pbuf
)
2005 struct netxen_skb_frag
*nf
;
2006 struct skb_frag_struct
*frag
;
2010 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2011 nf
= &pbuf
->frag_array
[0];
2013 map
= pci_map_single(pdev
, skb
->data
,
2014 skb_headlen(skb
), PCI_DMA_TODEVICE
);
2015 if (pci_dma_mapping_error(pdev
, map
))
2019 nf
->length
= skb_headlen(skb
);
2021 for (i
= 0; i
< nr_frags
; i
++) {
2022 frag
= &skb_shinfo(skb
)->frags
[i
];
2023 nf
= &pbuf
->frag_array
[i
+1];
2025 map
= skb_frag_dma_map(&pdev
->dev
, frag
, 0, skb_frag_size(frag
),
2027 if (dma_mapping_error(&pdev
->dev
, map
))
2031 nf
->length
= skb_frag_size(frag
);
2038 nf
= &pbuf
->frag_array
[i
+1];
2039 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
2043 nf
= &pbuf
->frag_array
[0];
2044 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
2052 netxen_clear_cmddesc(u64
*desc
)
2059 netxen_nic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2061 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2062 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2063 struct netxen_cmd_buffer
*pbuf
;
2064 struct netxen_skb_frag
*buffrag
;
2065 struct cmd_desc_type0
*hwdesc
, *first_desc
;
2066 struct pci_dev
*pdev
;
2069 struct skb_frag_struct
*frag
;
2072 int frag_count
, no_of_desc
;
2073 u32 num_txd
= tx_ring
->num_desc
;
2075 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
2077 /* 14 frags supported for normal packet and
2078 * 32 frags supported for TSO packet
2080 if (!skb_is_gso(skb
) && frag_count
> NETXEN_MAX_FRAGS_PER_TX
) {
2082 for (i
= 0; i
< (frag_count
- NETXEN_MAX_FRAGS_PER_TX
); i
++) {
2083 frag
= &skb_shinfo(skb
)->frags
[i
];
2084 delta
+= skb_frag_size(frag
);
2087 if (!__pskb_pull_tail(skb
, delta
))
2090 frag_count
= 1 + skb_shinfo(skb
)->nr_frags
;
2092 /* 4 fragments per cmd des */
2093 no_of_desc
= (frag_count
+ 3) >> 2;
2095 if (unlikely(netxen_tx_avail(tx_ring
) <= TX_STOP_THRESH
)) {
2096 netif_stop_queue(netdev
);
2098 if (netxen_tx_avail(tx_ring
) > TX_STOP_THRESH
)
2099 netif_start_queue(netdev
);
2101 return NETDEV_TX_BUSY
;
2104 producer
= tx_ring
->producer
;
2105 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
2107 pdev
= adapter
->pdev
;
2109 if (netxen_map_tx_skb(pdev
, skb
, pbuf
))
2113 pbuf
->frag_count
= frag_count
;
2115 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
2116 netxen_clear_cmddesc((u64
*)hwdesc
);
2118 netxen_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
2119 netxen_set_tx_port(first_desc
, adapter
->portnum
);
2121 for (i
= 0; i
< frag_count
; i
++) {
2125 if ((k
== 0) && (i
> 0)) {
2126 /* move to next desc.*/
2127 producer
= get_next_index(producer
, num_txd
);
2128 hwdesc
= &tx_ring
->desc_head
[producer
];
2129 netxen_clear_cmddesc((u64
*)hwdesc
);
2130 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2133 buffrag
= &pbuf
->frag_array
[i
];
2135 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
2138 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
2141 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
2144 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
2147 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
2152 tx_ring
->producer
= get_next_index(producer
, num_txd
);
2154 netxen_tso_check(netdev
, tx_ring
, first_desc
, skb
);
2156 adapter
->stats
.txbytes
+= skb
->len
;
2157 adapter
->stats
.xmitcalled
++;
2159 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
2161 return NETDEV_TX_OK
;
2164 adapter
->stats
.txdropped
++;
2165 dev_kfree_skb_any(skb
);
2166 return NETDEV_TX_OK
;
2169 static int netxen_nic_check_temp(struct netxen_adapter
*adapter
)
2171 struct net_device
*netdev
= adapter
->netdev
;
2172 uint32_t temp
, temp_state
, temp_val
;
2175 temp
= NXRD32(adapter
, CRB_TEMP_STATE
);
2177 temp_state
= nx_get_temp_state(temp
);
2178 temp_val
= nx_get_temp_val(temp
);
2180 if (temp_state
== NX_TEMP_PANIC
) {
2182 "%s: Device temperature %d degrees C exceeds"
2183 " maximum allowed. Hardware has been shut down.\n",
2184 netdev
->name
, temp_val
);
2186 } else if (temp_state
== NX_TEMP_WARN
) {
2187 if (adapter
->temp
== NX_TEMP_NORMAL
) {
2189 "%s: Device temperature %d degrees C "
2190 "exceeds operating range."
2191 " Immediate action needed.\n",
2192 netdev
->name
, temp_val
);
2195 if (adapter
->temp
== NX_TEMP_WARN
) {
2197 "%s: Device temperature is now %d degrees C"
2198 " in normal range.\n", netdev
->name
,
2202 adapter
->temp
= temp_state
;
2206 void netxen_advert_link_change(struct netxen_adapter
*adapter
, int linkup
)
2208 struct net_device
*netdev
= adapter
->netdev
;
2210 if (adapter
->ahw
.linkup
&& !linkup
) {
2211 printk(KERN_INFO
"%s: %s NIC Link is down\n",
2212 netxen_nic_driver_name
, netdev
->name
);
2213 adapter
->ahw
.linkup
= 0;
2214 if (netif_running(netdev
)) {
2215 netif_carrier_off(netdev
);
2216 netif_stop_queue(netdev
);
2218 adapter
->link_changed
= !adapter
->has_link_events
;
2219 } else if (!adapter
->ahw
.linkup
&& linkup
) {
2220 printk(KERN_INFO
"%s: %s NIC Link is up\n",
2221 netxen_nic_driver_name
, netdev
->name
);
2222 adapter
->ahw
.linkup
= 1;
2223 if (netif_running(netdev
)) {
2224 netif_carrier_on(netdev
);
2225 netif_wake_queue(netdev
);
2227 adapter
->link_changed
= !adapter
->has_link_events
;
2231 static void netxen_nic_handle_phy_intr(struct netxen_adapter
*adapter
)
2233 u32 val
, port
, linkup
;
2235 port
= adapter
->physical_port
;
2237 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
2238 val
= NXRD32(adapter
, CRB_XG_STATE_P3
);
2239 val
= XG_LINK_STATE_P3(adapter
->ahw
.pci_func
, val
);
2240 linkup
= (val
== XG_LINK_UP_P3
);
2242 val
= NXRD32(adapter
, CRB_XG_STATE
);
2243 val
= (val
>> port
*8) & 0xff;
2244 linkup
= (val
== XG_LINK_UP
);
2247 netxen_advert_link_change(adapter
, linkup
);
2250 static void netxen_tx_timeout(struct net_device
*netdev
)
2252 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2254 if (test_bit(__NX_RESETTING
, &adapter
->state
))
2257 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
2258 schedule_work(&adapter
->tx_timeout_task
);
2261 static void netxen_tx_timeout_task(struct work_struct
*work
)
2263 struct netxen_adapter
*adapter
=
2264 container_of(work
, struct netxen_adapter
, tx_timeout_task
);
2266 if (!netif_running(adapter
->netdev
))
2269 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2272 if (++adapter
->tx_timeo_cnt
>= NX_MAX_TX_TIMEOUTS
)
2276 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
2277 /* try to scrub interrupt */
2278 netxen_napi_disable(adapter
);
2280 netxen_napi_enable(adapter
);
2282 netif_wake_queue(adapter
->netdev
);
2284 clear_bit(__NX_RESETTING
, &adapter
->state
);
2286 clear_bit(__NX_RESETTING
, &adapter
->state
);
2287 if (netxen_nic_reset_context(adapter
)) {
2292 adapter
->netdev
->trans_start
= jiffies
;
2297 adapter
->need_fw_reset
= 1;
2298 clear_bit(__NX_RESETTING
, &adapter
->state
);
2301 static struct rtnl_link_stats64
*netxen_nic_get_stats(struct net_device
*netdev
,
2302 struct rtnl_link_stats64
*stats
)
2304 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2306 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
2307 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
2308 stats
->rx_bytes
= adapter
->stats
.rxbytes
;
2309 stats
->tx_bytes
= adapter
->stats
.txbytes
;
2310 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
2311 stats
->tx_dropped
= adapter
->stats
.txdropped
;
2316 static irqreturn_t
netxen_intr(int irq
, void *data
)
2318 struct nx_host_sds_ring
*sds_ring
= data
;
2319 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2322 status
= readl(adapter
->isr_int_vec
);
2324 if (!(status
& adapter
->int_vec_bit
))
2327 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
2328 /* check interrupt state machine, to be sure */
2329 status
= readl(adapter
->crb_int_state_reg
);
2330 if (!ISR_LEGACY_INT_TRIGGERED(status
))
2334 unsigned long our_int
= 0;
2336 our_int
= readl(adapter
->crb_int_state_reg
);
2338 /* not our interrupt */
2339 if (!test_and_clear_bit((7 + adapter
->portnum
), &our_int
))
2342 /* claim interrupt */
2343 writel((our_int
& 0xffffffff), adapter
->crb_int_state_reg
);
2345 /* clear interrupt */
2346 netxen_nic_disable_int(sds_ring
);
2349 writel(0xffffffff, adapter
->tgt_status_reg
);
2350 /* read twice to ensure write is flushed */
2351 readl(adapter
->isr_int_vec
);
2352 readl(adapter
->isr_int_vec
);
2354 napi_schedule(&sds_ring
->napi
);
2359 static irqreturn_t
netxen_msi_intr(int irq
, void *data
)
2361 struct nx_host_sds_ring
*sds_ring
= data
;
2362 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2364 /* clear interrupt */
2365 writel(0xffffffff, adapter
->tgt_status_reg
);
2367 napi_schedule(&sds_ring
->napi
);
2371 static irqreturn_t
netxen_msix_intr(int irq
, void *data
)
2373 struct nx_host_sds_ring
*sds_ring
= data
;
2375 napi_schedule(&sds_ring
->napi
);
2379 static int netxen_nic_poll(struct napi_struct
*napi
, int budget
)
2381 struct nx_host_sds_ring
*sds_ring
=
2382 container_of(napi
, struct nx_host_sds_ring
, napi
);
2384 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2389 tx_complete
= netxen_process_cmd_ring(adapter
);
2391 work_done
= netxen_process_rcv_ring(sds_ring
, budget
);
2393 if ((work_done
< budget
) && tx_complete
) {
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 if (!adapter
->has_link_events
) {
2770 netxen_nic_handle_phy_intr(adapter
);
2772 if (adapter
->link_changed
)
2773 netxen_nic_set_link_parameters(adapter
);
2777 if (netxen_check_health(adapter
))
2781 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
2785 netxen_store_bridged_mode(struct device
*dev
,
2786 struct device_attribute
*attr
, const char *buf
, size_t len
)
2788 struct net_device
*net
= to_net_dev(dev
);
2789 struct netxen_adapter
*adapter
= netdev_priv(net
);
2793 if (!(adapter
->capabilities
& NX_FW_CAPABILITY_BDG
))
2796 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
2799 if (kstrtoul(buf
, 2, &new))
2802 if (!netxen_config_bridged_mode(adapter
, !!new))
2810 netxen_show_bridged_mode(struct device
*dev
,
2811 struct device_attribute
*attr
, char *buf
)
2813 struct net_device
*net
= to_net_dev(dev
);
2814 struct netxen_adapter
*adapter
;
2815 int bridged_mode
= 0;
2817 adapter
= netdev_priv(net
);
2819 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
2820 bridged_mode
= !!(adapter
->flags
& NETXEN_NIC_BRIDGE_ENABLED
);
2822 return sprintf(buf
, "%d\n", bridged_mode
);
2825 static struct device_attribute dev_attr_bridged_mode
= {
2826 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2827 .show
= netxen_show_bridged_mode
,
2828 .store
= netxen_store_bridged_mode
,
2832 netxen_store_diag_mode(struct device
*dev
,
2833 struct device_attribute
*attr
, const char *buf
, size_t len
)
2835 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2838 if (kstrtoul(buf
, 2, &new))
2841 if (!!new != !!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2842 adapter
->flags
^= NETXEN_NIC_DIAG_ENABLED
;
2848 netxen_show_diag_mode(struct device
*dev
,
2849 struct device_attribute
*attr
, char *buf
)
2851 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2853 return sprintf(buf
, "%d\n",
2854 !!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
));
2857 static struct device_attribute dev_attr_diag_mode
= {
2858 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2859 .show
= netxen_show_diag_mode
,
2860 .store
= netxen_store_diag_mode
,
2864 netxen_sysfs_validate_crb(struct netxen_adapter
*adapter
,
2865 loff_t offset
, size_t size
)
2867 size_t crb_size
= 4;
2869 if (!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2872 if (offset
< NETXEN_PCI_CRBSPACE
) {
2873 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2876 if (ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2877 NETXEN_PCI_CAMQM_2M_END
))
2883 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
2890 netxen_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
2891 struct bin_attribute
*attr
,
2892 char *buf
, loff_t offset
, size_t size
)
2894 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2895 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2900 ret
= netxen_sysfs_validate_crb(adapter
, offset
, size
);
2904 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) &&
2905 ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2906 NETXEN_PCI_CAMQM_2M_END
)) {
2907 netxen_pci_camqm_read_2M(adapter
, offset
, &qmdata
);
2908 memcpy(buf
, &qmdata
, size
);
2910 data
= NXRD32(adapter
, offset
);
2911 memcpy(buf
, &data
, size
);
2918 netxen_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
2919 struct bin_attribute
*attr
,
2920 char *buf
, loff_t offset
, size_t size
)
2922 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2923 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2928 ret
= netxen_sysfs_validate_crb(adapter
, offset
, size
);
2932 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) &&
2933 ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2934 NETXEN_PCI_CAMQM_2M_END
)) {
2935 memcpy(&qmdata
, buf
, size
);
2936 netxen_pci_camqm_write_2M(adapter
, offset
, qmdata
);
2938 memcpy(&data
, buf
, size
);
2939 NXWR32(adapter
, offset
, data
);
2946 netxen_sysfs_validate_mem(struct netxen_adapter
*adapter
,
2947 loff_t offset
, size_t size
)
2949 if (!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2952 if ((size
!= 8) || (offset
& 0x7))
2959 netxen_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
2960 struct bin_attribute
*attr
,
2961 char *buf
, loff_t offset
, size_t size
)
2963 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2964 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2968 ret
= netxen_sysfs_validate_mem(adapter
, offset
, size
);
2972 if (adapter
->pci_mem_read(adapter
, offset
, &data
))
2975 memcpy(buf
, &data
, size
);
2980 static ssize_t
netxen_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
2981 struct bin_attribute
*attr
, char *buf
,
2982 loff_t offset
, size_t size
)
2984 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2985 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2989 ret
= netxen_sysfs_validate_mem(adapter
, offset
, size
);
2993 memcpy(&data
, buf
, size
);
2995 if (adapter
->pci_mem_write(adapter
, offset
, data
))
3002 static struct bin_attribute bin_attr_crb
= {
3003 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
3005 .read
= netxen_sysfs_read_crb
,
3006 .write
= netxen_sysfs_write_crb
,
3009 static struct bin_attribute bin_attr_mem
= {
3010 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
3012 .read
= netxen_sysfs_read_mem
,
3013 .write
= netxen_sysfs_write_mem
,
3017 netxen_sysfs_read_dimm(struct file
*filp
, struct kobject
*kobj
,
3018 struct bin_attribute
*attr
,
3019 char *buf
, loff_t offset
, size_t size
)
3021 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3022 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
3023 struct net_device
*netdev
= adapter
->netdev
;
3024 struct netxen_dimm_cfg dimm
;
3025 u8 dw
, rows
, cols
, banks
, ranks
;
3028 if (size
!= sizeof(struct netxen_dimm_cfg
)) {
3029 netdev_err(netdev
, "Invalid size\n");
3033 memset(&dimm
, 0, sizeof(struct netxen_dimm_cfg
));
3034 val
= NXRD32(adapter
, NETXEN_DIMM_CAPABILITY
);
3036 /* Checks if DIMM info is valid. */
3037 if (val
& NETXEN_DIMM_VALID_FLAG
) {
3038 netdev_err(netdev
, "Invalid DIMM flag\n");
3039 dimm
.presence
= 0xff;
3043 rows
= NETXEN_DIMM_NUMROWS(val
);
3044 cols
= NETXEN_DIMM_NUMCOLS(val
);
3045 ranks
= NETXEN_DIMM_NUMRANKS(val
);
3046 banks
= NETXEN_DIMM_NUMBANKS(val
);
3047 dw
= NETXEN_DIMM_DATAWIDTH(val
);
3049 dimm
.presence
= (val
& NETXEN_DIMM_PRESENT
);
3051 /* Checks if DIMM info is present. */
3052 if (!dimm
.presence
) {
3053 netdev_err(netdev
, "DIMM not present\n");
3057 dimm
.dimm_type
= NETXEN_DIMM_TYPE(val
);
3059 switch (dimm
.dimm_type
) {
3060 case NETXEN_DIMM_TYPE_RDIMM
:
3061 case NETXEN_DIMM_TYPE_UDIMM
:
3062 case NETXEN_DIMM_TYPE_SO_DIMM
:
3063 case NETXEN_DIMM_TYPE_Micro_DIMM
:
3064 case NETXEN_DIMM_TYPE_Mini_RDIMM
:
3065 case NETXEN_DIMM_TYPE_Mini_UDIMM
:
3068 netdev_err(netdev
, "Invalid DIMM type %x\n", dimm
.dimm_type
);
3072 if (val
& NETXEN_DIMM_MEMTYPE_DDR2_SDRAM
)
3073 dimm
.mem_type
= NETXEN_DIMM_MEM_DDR2_SDRAM
;
3075 dimm
.mem_type
= NETXEN_DIMM_MEMTYPE(val
);
3077 if (val
& NETXEN_DIMM_SIZE
) {
3078 dimm
.size
= NETXEN_DIMM_STD_MEM_SIZE
;
3083 netdev_err(netdev
, "Invalid no of rows %x\n", rows
);
3088 netdev_err(netdev
, "Invalid no of columns %x\n", cols
);
3093 netdev_err(netdev
, "Invalid no of banks %x\n", banks
);
3125 netdev_err(netdev
, "Invalid data-width %x\n", dw
);
3129 dimm
.size
= ((1 << rows
) * (1 << cols
) * dw
* banks
* ranks
) / 8;
3130 /* Size returned in MB. */
3131 dimm
.size
= (dimm
.size
) / 0x100000;
3133 memcpy(buf
, &dimm
, sizeof(struct netxen_dimm_cfg
));
3134 return sizeof(struct netxen_dimm_cfg
);
3138 static struct bin_attribute bin_attr_dimm
= {
3139 .attr
= { .name
= "dimm", .mode
= (S_IRUGO
| S_IWUSR
) },
3141 .read
= netxen_sysfs_read_dimm
,
3146 netxen_create_sysfs_entries(struct netxen_adapter
*adapter
)
3148 struct device
*dev
= &adapter
->pdev
->dev
;
3150 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
) {
3151 /* bridged_mode control */
3152 if (device_create_file(dev
, &dev_attr_bridged_mode
)) {
3154 "failed to create bridged_mode sysfs entry\n");
3160 netxen_remove_sysfs_entries(struct netxen_adapter
*adapter
)
3162 struct device
*dev
= &adapter
->pdev
->dev
;
3164 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
3165 device_remove_file(dev
, &dev_attr_bridged_mode
);
3169 netxen_create_diag_entries(struct netxen_adapter
*adapter
)
3171 struct pci_dev
*pdev
= adapter
->pdev
;
3175 if (device_create_file(dev
, &dev_attr_diag_mode
))
3176 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
3177 if (device_create_bin_file(dev
, &bin_attr_crb
))
3178 dev_info(dev
, "failed to create crb sysfs entry\n");
3179 if (device_create_bin_file(dev
, &bin_attr_mem
))
3180 dev_info(dev
, "failed to create mem sysfs entry\n");
3181 if (device_create_bin_file(dev
, &bin_attr_dimm
))
3182 dev_info(dev
, "failed to create dimm sysfs entry\n");
3187 netxen_remove_diag_entries(struct netxen_adapter
*adapter
)
3189 struct pci_dev
*pdev
= adapter
->pdev
;
3190 struct device
*dev
= &pdev
->dev
;
3192 device_remove_file(dev
, &dev_attr_diag_mode
);
3193 device_remove_bin_file(dev
, &bin_attr_crb
);
3194 device_remove_bin_file(dev
, &bin_attr_mem
);
3195 device_remove_bin_file(dev
, &bin_attr_dimm
);
3200 #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
3203 netxen_destip_supported(struct netxen_adapter
*adapter
)
3205 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
3208 if (adapter
->ahw
.cut_through
)
3215 netxen_free_ip_list(struct netxen_adapter
*adapter
, bool master
)
3217 struct nx_ip_list
*cur
, *tmp_cur
;
3219 list_for_each_entry_safe(cur
, tmp_cur
, &adapter
->ip_list
, list
) {
3222 netxen_config_ipaddr(adapter
, cur
->ip_addr
,
3224 list_del(&cur
->list
);
3228 netxen_config_ipaddr(adapter
, cur
->ip_addr
, NX_IP_DOWN
);
3229 list_del(&cur
->list
);
3236 netxen_list_config_ip(struct netxen_adapter
*adapter
,
3237 struct in_ifaddr
*ifa
, unsigned long event
)
3239 struct net_device
*dev
;
3240 struct nx_ip_list
*cur
, *tmp_cur
;
3241 struct list_head
*head
;
3244 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
3251 list_for_each(head
, &adapter
->ip_list
) {
3252 cur
= list_entry(head
, struct nx_ip_list
, list
);
3254 if (cur
->ip_addr
== ifa
->ifa_address
)
3258 cur
= kzalloc(sizeof(struct nx_ip_list
), GFP_ATOMIC
);
3261 if (dev
->priv_flags
& IFF_802_1Q_VLAN
)
3262 dev
= vlan_dev_real_dev(dev
);
3263 cur
->master
= !!netif_is_bond_master(dev
);
3264 cur
->ip_addr
= ifa
->ifa_address
;
3265 list_add_tail(&cur
->list
, &adapter
->ip_list
);
3266 netxen_config_ipaddr(adapter
, ifa
->ifa_address
, NX_IP_UP
);
3270 list_for_each_entry_safe(cur
, tmp_cur
,
3271 &adapter
->ip_list
, list
) {
3272 if (cur
->ip_addr
== ifa
->ifa_address
) {
3273 list_del(&cur
->list
);
3275 netxen_config_ipaddr(adapter
, ifa
->ifa_address
,
3287 netxen_config_indev_addr(struct netxen_adapter
*adapter
,
3288 struct net_device
*dev
, unsigned long event
)
3290 struct in_device
*indev
;
3292 if (!netxen_destip_supported(adapter
))
3295 indev
= in_dev_get(dev
);
3302 netxen_list_config_ip(adapter
, ifa
, NX_IP_UP
);
3305 netxen_list_config_ip(adapter
, ifa
, NX_IP_DOWN
);
3310 } endfor_ifa(indev
);
3316 netxen_restore_indev_addr(struct net_device
*netdev
, unsigned long event
)
3319 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
3320 struct nx_ip_list
*pos
, *tmp_pos
;
3321 unsigned long ip_event
;
3323 ip_event
= (event
== NETDEV_UP
) ? NX_IP_UP
: NX_IP_DOWN
;
3324 netxen_config_indev_addr(adapter
, netdev
, event
);
3326 list_for_each_entry_safe(pos
, tmp_pos
, &adapter
->ip_list
, list
) {
3327 netxen_config_ipaddr(adapter
, pos
->ip_addr
, ip_event
);
3332 netxen_config_checkdev(struct net_device
*dev
)
3334 struct netxen_adapter
*adapter
;
3336 if (!is_netxen_netdev(dev
))
3338 adapter
= netdev_priv(dev
);
3341 if (!netxen_destip_supported(adapter
))
3343 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
3350 * netxen_config_master - configure addresses based on master
3351 * @dev: netxen device
3352 * @event: netdev event
3354 static void netxen_config_master(struct net_device
*dev
, unsigned long event
)
3356 struct net_device
*master
, *slave
;
3357 struct netxen_adapter
*adapter
= netdev_priv(dev
);
3360 master
= netdev_master_upper_dev_get_rcu(dev
);
3362 * This is the case where the netxen nic is being
3363 * enslaved and is dev_open()ed in bond_enslave()
3364 * Now we should program the bond's (and its vlans')
3365 * addresses in the netxen NIC.
3367 if (master
&& netif_is_bond_master(master
) &&
3368 !netif_is_bond_slave(dev
)) {
3369 netxen_config_indev_addr(adapter
, master
, event
);
3370 for_each_netdev_rcu(&init_net
, slave
)
3371 if (slave
->priv_flags
& IFF_802_1Q_VLAN
&&
3372 vlan_dev_real_dev(slave
) == master
)
3373 netxen_config_indev_addr(adapter
, slave
, event
);
3377 * This is the case where the netxen nic is being
3378 * released and is dev_close()ed in bond_release()
3379 * just before IFF_BONDING is stripped.
3381 if (!master
&& dev
->priv_flags
& IFF_BONDING
)
3382 netxen_free_ip_list(adapter
, true);
3385 static int netxen_netdev_event(struct notifier_block
*this,
3386 unsigned long event
, void *ptr
)
3388 struct netxen_adapter
*adapter
;
3389 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
3390 struct net_device
*orig_dev
= dev
;
3391 struct net_device
*slave
;
3397 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3398 dev
= vlan_dev_real_dev(dev
);
3401 if (event
== NETDEV_UP
|| event
== NETDEV_DOWN
) {
3402 /* If this is a bonding device, look for netxen-based slaves*/
3403 if (netif_is_bond_master(dev
)) {
3405 for_each_netdev_in_bond_rcu(dev
, slave
) {
3406 if (!netxen_config_checkdev(slave
))
3408 adapter
= netdev_priv(slave
);
3409 netxen_config_indev_addr(adapter
,
3414 if (!netxen_config_checkdev(dev
))
3416 adapter
= netdev_priv(dev
);
3417 /* Act only if the actual netxen is the target */
3418 if (orig_dev
== dev
)
3419 netxen_config_master(dev
, event
);
3420 netxen_config_indev_addr(adapter
, orig_dev
, event
);
3428 netxen_inetaddr_event(struct notifier_block
*this,
3429 unsigned long event
, void *ptr
)
3431 struct netxen_adapter
*adapter
;
3432 struct net_device
*dev
, *slave
;
3433 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
3434 unsigned long ip_event
;
3436 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
3437 ip_event
= (event
== NETDEV_UP
) ? NX_IP_UP
: NX_IP_DOWN
;
3442 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3443 dev
= vlan_dev_real_dev(dev
);
3446 if (event
== NETDEV_UP
|| event
== NETDEV_DOWN
) {
3447 /* If this is a bonding device, look for netxen-based slaves*/
3448 if (netif_is_bond_master(dev
)) {
3450 for_each_netdev_in_bond_rcu(dev
, slave
) {
3451 if (!netxen_config_checkdev(slave
))
3453 adapter
= netdev_priv(slave
);
3454 netxen_list_config_ip(adapter
, ifa
, ip_event
);
3458 if (!netxen_config_checkdev(dev
))
3460 adapter
= netdev_priv(dev
);
3461 netxen_list_config_ip(adapter
, ifa
, ip_event
);
3468 static struct notifier_block netxen_netdev_cb
= {
3469 .notifier_call
= netxen_netdev_event
,
3472 static struct notifier_block netxen_inetaddr_cb
= {
3473 .notifier_call
= netxen_inetaddr_event
,
3477 netxen_restore_indev_addr(struct net_device
*dev
, unsigned long event
)
3480 netxen_free_ip_list(struct netxen_adapter
*adapter
, bool master
)
3484 static const struct pci_error_handlers netxen_err_handler
= {
3485 .error_detected
= netxen_io_error_detected
,
3486 .slot_reset
= netxen_io_slot_reset
,
3487 .resume
= netxen_io_resume
,
3490 static struct pci_driver netxen_driver
= {
3491 .name
= netxen_nic_driver_name
,
3492 .id_table
= netxen_pci_tbl
,
3493 .probe
= netxen_nic_probe
,
3494 .remove
= netxen_nic_remove
,
3496 .suspend
= netxen_nic_suspend
,
3497 .resume
= netxen_nic_resume
,
3499 .shutdown
= netxen_nic_shutdown
,
3500 .err_handler
= &netxen_err_handler
3503 static int __init
netxen_init_module(void)
3505 printk(KERN_INFO
"%s\n", netxen_nic_driver_string
);
3508 register_netdevice_notifier(&netxen_netdev_cb
);
3509 register_inetaddr_notifier(&netxen_inetaddr_cb
);
3511 return pci_register_driver(&netxen_driver
);
3514 module_init(netxen_init_module
);
3516 static void __exit
netxen_exit_module(void)
3518 pci_unregister_driver(&netxen_driver
);
3521 unregister_inetaddr_notifier(&netxen_inetaddr_cb
);
3522 unregister_netdevice_notifier(&netxen_netdev_cb
);
3526 module_exit(netxen_exit_module
);