2 * Copyright (C) 2003 - 2009 NetXen, Inc.
3 * Copyright (C) 2009 - QLogic Corporation.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 * The full GNU General Public License is included in this distribution
22 * in the file called "COPYING".
26 #include <linux/slab.h>
27 #include <linux/vmalloc.h>
28 #include <linux/interrupt.h>
29 #include "netxen_nic_hw.h"
31 #include "netxen_nic.h"
33 #include <linux/dma-mapping.h>
34 #include <linux/if_vlan.h>
36 #include <linux/ipv6.h>
37 #include <linux/inetdevice.h>
38 #include <linux/sysfs.h>
39 #include <linux/aer.h>
41 MODULE_DESCRIPTION("QLogic/NetXen (1/10) GbE Intelligent Ethernet Driver");
42 MODULE_LICENSE("GPL");
43 MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID
);
44 MODULE_FIRMWARE(NX_UNIFIED_ROMIMAGE_NAME
);
46 char netxen_nic_driver_name
[] = "netxen_nic";
47 static char netxen_nic_driver_string
[] = "QLogic/NetXen Network Driver v"
48 NETXEN_NIC_LINUX_VERSIONID
;
50 static int port_mode
= NETXEN_PORT_MODE_AUTO_NEG
;
52 /* Default to restricted 1G auto-neg mode */
53 static int wol_port_mode
= 5;
55 static int use_msi
= 1;
57 static int use_msi_x
= 1;
59 static int auto_fw_reset
= AUTO_FW_RESET_ENABLED
;
60 module_param(auto_fw_reset
, int, 0644);
61 MODULE_PARM_DESC(auto_fw_reset
,"Auto firmware reset (0=disabled, 1=enabled");
63 static int __devinit
netxen_nic_probe(struct pci_dev
*pdev
,
64 const struct pci_device_id
*ent
);
65 static void __devexit
netxen_nic_remove(struct pci_dev
*pdev
);
66 static int netxen_nic_open(struct net_device
*netdev
);
67 static int netxen_nic_close(struct net_device
*netdev
);
68 static netdev_tx_t
netxen_nic_xmit_frame(struct sk_buff
*,
70 static void netxen_tx_timeout(struct net_device
*netdev
);
71 static void netxen_tx_timeout_task(struct work_struct
*work
);
72 static void netxen_fw_poll_work(struct work_struct
*work
);
73 static void netxen_schedule_work(struct netxen_adapter
*adapter
,
74 work_func_t func
, int delay
);
75 static void netxen_cancel_fw_work(struct netxen_adapter
*adapter
);
76 static int netxen_nic_poll(struct napi_struct
*napi
, int budget
);
77 #ifdef CONFIG_NET_POLL_CONTROLLER
78 static void netxen_nic_poll_controller(struct net_device
*netdev
);
81 static void netxen_create_sysfs_entries(struct netxen_adapter
*adapter
);
82 static void netxen_remove_sysfs_entries(struct netxen_adapter
*adapter
);
83 static void netxen_create_diag_entries(struct netxen_adapter
*adapter
);
84 static void netxen_remove_diag_entries(struct netxen_adapter
*adapter
);
86 static int nx_dev_request_aer(struct netxen_adapter
*adapter
);
87 static int nx_decr_dev_ref_cnt(struct netxen_adapter
*adapter
);
88 static int netxen_can_start_firmware(struct netxen_adapter
*adapter
);
90 static irqreturn_t
netxen_intr(int irq
, void *data
);
91 static irqreturn_t
netxen_msi_intr(int irq
, void *data
);
92 static irqreturn_t
netxen_msix_intr(int irq
, void *data
);
94 static void netxen_config_indev_addr(struct net_device
*dev
, unsigned long);
95 static struct net_device_stats
*netxen_nic_get_stats(struct net_device
*netdev
);
96 static int netxen_nic_set_mac(struct net_device
*netdev
, void *p
);
98 /* PCI Device ID Table */
99 #define ENTRY(device) \
100 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
101 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
103 static DEFINE_PCI_DEVICE_TABLE(netxen_pci_tbl
) = {
104 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR
),
105 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4
),
106 ENTRY(PCI_DEVICE_ID_NX2031_4GCU
),
107 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ
),
108 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ
),
109 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT
),
110 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2
),
111 ENTRY(PCI_DEVICE_ID_NX3031
),
115 MODULE_DEVICE_TABLE(pci
, netxen_pci_tbl
);
117 static uint32_t crb_cmd_producer
[4] = {
118 CRB_CMD_PRODUCER_OFFSET
, CRB_CMD_PRODUCER_OFFSET_1
,
119 CRB_CMD_PRODUCER_OFFSET_2
, CRB_CMD_PRODUCER_OFFSET_3
123 netxen_nic_update_cmd_producer(struct netxen_adapter
*adapter
,
124 struct nx_host_tx_ring
*tx_ring
)
126 NXWRIO(adapter
, tx_ring
->crb_cmd_producer
, tx_ring
->producer
);
129 static uint32_t crb_cmd_consumer
[4] = {
130 CRB_CMD_CONSUMER_OFFSET
, CRB_CMD_CONSUMER_OFFSET_1
,
131 CRB_CMD_CONSUMER_OFFSET_2
, CRB_CMD_CONSUMER_OFFSET_3
135 netxen_nic_update_cmd_consumer(struct netxen_adapter
*adapter
,
136 struct nx_host_tx_ring
*tx_ring
)
138 NXWRIO(adapter
, tx_ring
->crb_cmd_consumer
, tx_ring
->sw_consumer
);
141 static uint32_t msi_tgt_status
[8] = {
142 ISR_INT_TARGET_STATUS
, ISR_INT_TARGET_STATUS_F1
,
143 ISR_INT_TARGET_STATUS_F2
, ISR_INT_TARGET_STATUS_F3
,
144 ISR_INT_TARGET_STATUS_F4
, ISR_INT_TARGET_STATUS_F5
,
145 ISR_INT_TARGET_STATUS_F6
, ISR_INT_TARGET_STATUS_F7
148 static struct netxen_legacy_intr_set legacy_intr
[] = NX_LEGACY_INTR_CONFIG
;
150 static inline void netxen_nic_disable_int(struct nx_host_sds_ring
*sds_ring
)
152 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
154 NXWRIO(adapter
, sds_ring
->crb_intr_mask
, 0);
157 static inline void netxen_nic_enable_int(struct nx_host_sds_ring
*sds_ring
)
159 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
161 NXWRIO(adapter
, sds_ring
->crb_intr_mask
, 0x1);
163 if (!NETXEN_IS_MSI_FAMILY(adapter
))
164 NXWRIO(adapter
, adapter
->tgt_mask_reg
, 0xfbff);
168 netxen_alloc_sds_rings(struct netxen_recv_context
*recv_ctx
, int count
)
170 int size
= sizeof(struct nx_host_sds_ring
) * count
;
172 recv_ctx
->sds_rings
= kzalloc(size
, GFP_KERNEL
);
174 return recv_ctx
->sds_rings
== NULL
;
178 netxen_free_sds_rings(struct netxen_recv_context
*recv_ctx
)
180 if (recv_ctx
->sds_rings
!= NULL
)
181 kfree(recv_ctx
->sds_rings
);
183 recv_ctx
->sds_rings
= NULL
;
187 netxen_napi_add(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
190 struct nx_host_sds_ring
*sds_ring
;
191 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
193 if (netxen_alloc_sds_rings(recv_ctx
, adapter
->max_sds_rings
))
196 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
197 sds_ring
= &recv_ctx
->sds_rings
[ring
];
198 netif_napi_add(netdev
, &sds_ring
->napi
,
199 netxen_nic_poll
, NETXEN_NETDEV_WEIGHT
);
206 netxen_napi_del(struct netxen_adapter
*adapter
)
209 struct nx_host_sds_ring
*sds_ring
;
210 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
212 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
213 sds_ring
= &recv_ctx
->sds_rings
[ring
];
214 netif_napi_del(&sds_ring
->napi
);
217 netxen_free_sds_rings(&adapter
->recv_ctx
);
221 netxen_napi_enable(struct netxen_adapter
*adapter
)
224 struct nx_host_sds_ring
*sds_ring
;
225 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
227 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
228 sds_ring
= &recv_ctx
->sds_rings
[ring
];
229 napi_enable(&sds_ring
->napi
);
230 netxen_nic_enable_int(sds_ring
);
235 netxen_napi_disable(struct netxen_adapter
*adapter
)
238 struct nx_host_sds_ring
*sds_ring
;
239 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
241 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
242 sds_ring
= &recv_ctx
->sds_rings
[ring
];
243 netxen_nic_disable_int(sds_ring
);
244 napi_synchronize(&sds_ring
->napi
);
245 napi_disable(&sds_ring
->napi
);
249 static int nx_set_dma_mask(struct netxen_adapter
*adapter
)
251 struct pci_dev
*pdev
= adapter
->pdev
;
252 uint64_t mask
, cmask
;
254 adapter
->pci_using_dac
= 0;
256 mask
= DMA_BIT_MASK(32);
257 cmask
= DMA_BIT_MASK(32);
259 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
261 mask
= DMA_BIT_MASK(35);
264 mask
= DMA_BIT_MASK(39);
268 if (pci_set_dma_mask(pdev
, mask
) == 0 &&
269 pci_set_consistent_dma_mask(pdev
, cmask
) == 0) {
270 adapter
->pci_using_dac
= 1;
277 /* Update addressable range if firmware supports it */
279 nx_update_dma_mask(struct netxen_adapter
*adapter
)
281 int change
, shift
, err
;
282 uint64_t mask
, old_mask
, old_cmask
;
283 struct pci_dev
*pdev
= adapter
->pdev
;
287 shift
= NXRD32(adapter
, CRB_DMA_SHIFT
);
291 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) && (shift
> 9))
293 else if ((adapter
->ahw
.revision_id
== NX_P2_C1
) && (shift
<= 4))
297 old_mask
= pdev
->dma_mask
;
298 old_cmask
= pdev
->dev
.coherent_dma_mask
;
300 mask
= DMA_BIT_MASK(32+shift
);
302 err
= pci_set_dma_mask(pdev
, mask
);
306 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
308 err
= pci_set_consistent_dma_mask(pdev
, mask
);
312 dev_info(&pdev
->dev
, "using %d-bit dma mask\n", 32+shift
);
318 pci_set_dma_mask(pdev
, old_mask
);
319 pci_set_consistent_dma_mask(pdev
, old_cmask
);
324 netxen_check_hw_init(struct netxen_adapter
*adapter
, int first_boot
)
328 if (first_boot
== 0x55555555) {
329 /* This is the first boot after power up */
330 NXWR32(adapter
, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC
);
332 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
335 /* PCI bus master workaround */
336 first_boot
= NXRD32(adapter
, NETXEN_PCIE_REG(0x4));
337 if (!(first_boot
& 0x4)) {
339 NXWR32(adapter
, NETXEN_PCIE_REG(0x4), first_boot
);
340 NXRD32(adapter
, NETXEN_PCIE_REG(0x4));
343 /* This is the first boot after power up */
344 first_boot
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_SW_RESET
);
345 if (first_boot
!= 0x80000f) {
346 /* clear the register for future unloads/loads */
347 NXWR32(adapter
, NETXEN_CAM_RAM(0x1fc), 0);
351 /* Start P2 boot loader */
352 val
= NXRD32(adapter
, NETXEN_ROMUSB_GLB_PEGTUNE_DONE
);
353 NXWR32(adapter
, NETXEN_ROMUSB_GLB_PEGTUNE_DONE
, val
| 0x1);
357 val
= NXRD32(adapter
, NETXEN_CAM_RAM(0x1fc));
359 if (++timeout
> 5000)
362 } while (val
== NETXEN_BDINFO_MAGIC
);
367 static void netxen_set_port_mode(struct netxen_adapter
*adapter
)
371 val
= adapter
->ahw
.board_type
;
372 if ((val
== NETXEN_BRDTYPE_P3_HMEZ
) ||
373 (val
== NETXEN_BRDTYPE_P3_XG_LOM
)) {
374 if (port_mode
== NETXEN_PORT_MODE_802_3_AP
) {
375 data
= NETXEN_PORT_MODE_802_3_AP
;
376 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
377 } else if (port_mode
== NETXEN_PORT_MODE_XG
) {
378 data
= NETXEN_PORT_MODE_XG
;
379 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
380 } else if (port_mode
== NETXEN_PORT_MODE_AUTO_NEG_1G
) {
381 data
= NETXEN_PORT_MODE_AUTO_NEG_1G
;
382 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
383 } else if (port_mode
== NETXEN_PORT_MODE_AUTO_NEG_XG
) {
384 data
= NETXEN_PORT_MODE_AUTO_NEG_XG
;
385 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
387 data
= NETXEN_PORT_MODE_AUTO_NEG
;
388 NXWR32(adapter
, NETXEN_PORT_MODE_ADDR
, data
);
391 if ((wol_port_mode
!= NETXEN_PORT_MODE_802_3_AP
) &&
392 (wol_port_mode
!= NETXEN_PORT_MODE_XG
) &&
393 (wol_port_mode
!= NETXEN_PORT_MODE_AUTO_NEG_1G
) &&
394 (wol_port_mode
!= NETXEN_PORT_MODE_AUTO_NEG_XG
)) {
395 wol_port_mode
= NETXEN_PORT_MODE_AUTO_NEG
;
397 NXWR32(adapter
, NETXEN_WOL_PORT_MODE
, wol_port_mode
);
401 static void netxen_set_msix_bit(struct pci_dev
*pdev
, int enable
)
406 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
408 pci_read_config_dword(pdev
, pos
, &control
);
410 control
|= PCI_MSIX_FLAGS_ENABLE
;
413 pci_write_config_dword(pdev
, pos
, control
);
417 static void netxen_init_msix_entries(struct netxen_adapter
*adapter
, int count
)
421 for (i
= 0; i
< count
; i
++)
422 adapter
->msix_entries
[i
].entry
= i
;
426 netxen_read_mac_addr(struct netxen_adapter
*adapter
)
431 struct net_device
*netdev
= adapter
->netdev
;
432 struct pci_dev
*pdev
= adapter
->pdev
;
434 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
435 if (netxen_p3_get_mac_addr(adapter
, &mac_addr
) != 0)
438 if (netxen_get_flash_mac_addr(adapter
, &mac_addr
) != 0)
442 p
= (unsigned char *)&mac_addr
;
443 for (i
= 0; i
< 6; i
++)
444 netdev
->dev_addr
[i
] = *(p
+ 5 - i
);
446 memcpy(netdev
->perm_addr
, netdev
->dev_addr
, netdev
->addr_len
);
447 memcpy(adapter
->mac_addr
, netdev
->dev_addr
, netdev
->addr_len
);
449 /* set station address */
451 if (!is_valid_ether_addr(netdev
->perm_addr
))
452 dev_warn(&pdev
->dev
, "Bad MAC address %pM.\n", netdev
->dev_addr
);
457 static int netxen_nic_set_mac(struct net_device
*netdev
, void *p
)
459 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
460 struct sockaddr
*addr
= p
;
462 if (!is_valid_ether_addr(addr
->sa_data
))
465 if (netif_running(netdev
)) {
466 netif_device_detach(netdev
);
467 netxen_napi_disable(adapter
);
470 memcpy(adapter
->mac_addr
, addr
->sa_data
, netdev
->addr_len
);
471 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
472 adapter
->macaddr_set(adapter
, addr
->sa_data
);
474 if (netif_running(netdev
)) {
475 netif_device_attach(netdev
);
476 netxen_napi_enable(adapter
);
481 static void netxen_set_multicast_list(struct net_device
*dev
)
483 struct netxen_adapter
*adapter
= netdev_priv(dev
);
485 adapter
->set_multi(dev
);
488 static const struct net_device_ops netxen_netdev_ops
= {
489 .ndo_open
= netxen_nic_open
,
490 .ndo_stop
= netxen_nic_close
,
491 .ndo_start_xmit
= netxen_nic_xmit_frame
,
492 .ndo_get_stats
= netxen_nic_get_stats
,
493 .ndo_validate_addr
= eth_validate_addr
,
494 .ndo_set_multicast_list
= netxen_set_multicast_list
,
495 .ndo_set_mac_address
= netxen_nic_set_mac
,
496 .ndo_change_mtu
= netxen_nic_change_mtu
,
497 .ndo_tx_timeout
= netxen_tx_timeout
,
498 #ifdef CONFIG_NET_POLL_CONTROLLER
499 .ndo_poll_controller
= netxen_nic_poll_controller
,
504 netxen_setup_intr(struct netxen_adapter
*adapter
)
506 struct netxen_legacy_intr_set
*legacy_intrp
;
507 struct pci_dev
*pdev
= adapter
->pdev
;
510 if (adapter
->rss_supported
) {
511 num_msix
= (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER
) ?
512 MSIX_ENTRIES_PER_ADAPTER
: 2;
516 adapter
->max_sds_rings
= 1;
518 adapter
->flags
&= ~(NETXEN_NIC_MSI_ENABLED
| NETXEN_NIC_MSIX_ENABLED
);
520 if (adapter
->ahw
.revision_id
>= NX_P3_B0
)
521 legacy_intrp
= &legacy_intr
[adapter
->ahw
.pci_func
];
523 legacy_intrp
= &legacy_intr
[0];
525 adapter
->int_vec_bit
= legacy_intrp
->int_vec_bit
;
526 adapter
->tgt_status_reg
= netxen_get_ioaddr(adapter
,
527 legacy_intrp
->tgt_status_reg
);
528 adapter
->tgt_mask_reg
= netxen_get_ioaddr(adapter
,
529 legacy_intrp
->tgt_mask_reg
);
530 adapter
->pci_int_reg
= netxen_get_ioaddr(adapter
,
531 legacy_intrp
->pci_int_reg
);
532 adapter
->isr_int_vec
= netxen_get_ioaddr(adapter
, ISR_INT_VECTOR
);
534 if (adapter
->ahw
.revision_id
>= NX_P3_B1
)
535 adapter
->crb_int_state_reg
= netxen_get_ioaddr(adapter
,
538 adapter
->crb_int_state_reg
= netxen_get_ioaddr(adapter
,
541 netxen_set_msix_bit(pdev
, 0);
543 if (adapter
->msix_supported
) {
545 netxen_init_msix_entries(adapter
, num_msix
);
546 err
= pci_enable_msix(pdev
, adapter
->msix_entries
, num_msix
);
548 adapter
->flags
|= NETXEN_NIC_MSIX_ENABLED
;
549 netxen_set_msix_bit(pdev
, 1);
551 if (adapter
->rss_supported
)
552 adapter
->max_sds_rings
= num_msix
;
554 dev_info(&pdev
->dev
, "using msi-x interrupts\n");
559 pci_disable_msix(pdev
);
561 /* fall through for msi */
564 if (use_msi
&& !pci_enable_msi(pdev
)) {
565 adapter
->flags
|= NETXEN_NIC_MSI_ENABLED
;
566 adapter
->tgt_status_reg
= netxen_get_ioaddr(adapter
,
567 msi_tgt_status
[adapter
->ahw
.pci_func
]);
568 dev_info(&pdev
->dev
, "using msi interrupts\n");
569 adapter
->msix_entries
[0].vector
= pdev
->irq
;
573 dev_info(&pdev
->dev
, "using legacy interrupts\n");
574 adapter
->msix_entries
[0].vector
= pdev
->irq
;
578 netxen_teardown_intr(struct netxen_adapter
*adapter
)
580 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
581 pci_disable_msix(adapter
->pdev
);
582 if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
583 pci_disable_msi(adapter
->pdev
);
587 netxen_cleanup_pci_map(struct netxen_adapter
*adapter
)
589 if (adapter
->ahw
.db_base
!= NULL
)
590 iounmap(adapter
->ahw
.db_base
);
591 if (adapter
->ahw
.pci_base0
!= NULL
)
592 iounmap(adapter
->ahw
.pci_base0
);
593 if (adapter
->ahw
.pci_base1
!= NULL
)
594 iounmap(adapter
->ahw
.pci_base1
);
595 if (adapter
->ahw
.pci_base2
!= NULL
)
596 iounmap(adapter
->ahw
.pci_base2
);
600 netxen_setup_pci_map(struct netxen_adapter
*adapter
)
602 void __iomem
*db_ptr
= NULL
;
604 resource_size_t mem_base
, db_base
;
605 unsigned long mem_len
, db_len
= 0;
607 struct pci_dev
*pdev
= adapter
->pdev
;
608 int pci_func
= adapter
->ahw
.pci_func
;
609 struct netxen_hardware_context
*ahw
= &adapter
->ahw
;
614 * Set the CRB window to invalid. If any register in window 0 is
615 * accessed it should set the window to 0 and then reset it to 1.
617 adapter
->ahw
.crb_win
= -1;
618 adapter
->ahw
.ocm_win
= -1;
620 /* remap phys address */
621 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
622 mem_len
= pci_resource_len(pdev
, 0);
624 /* 128 Meg of memory */
625 if (mem_len
== NETXEN_PCI_128MB_SIZE
) {
627 ahw
->pci_base0
= ioremap(mem_base
, FIRST_PAGE_GROUP_SIZE
);
628 ahw
->pci_base1
= ioremap(mem_base
+ SECOND_PAGE_GROUP_START
,
629 SECOND_PAGE_GROUP_SIZE
);
630 ahw
->pci_base2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
,
631 THIRD_PAGE_GROUP_SIZE
);
632 if (ahw
->pci_base0
== NULL
|| ahw
->pci_base1
== NULL
||
633 ahw
->pci_base2
== NULL
) {
634 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
639 ahw
->pci_len0
= FIRST_PAGE_GROUP_SIZE
;
641 } else if (mem_len
== NETXEN_PCI_32MB_SIZE
) {
643 ahw
->pci_base1
= ioremap(mem_base
, SECOND_PAGE_GROUP_SIZE
);
644 ahw
->pci_base2
= ioremap(mem_base
+ THIRD_PAGE_GROUP_START
-
645 SECOND_PAGE_GROUP_START
, THIRD_PAGE_GROUP_SIZE
);
646 if (ahw
->pci_base1
== NULL
|| ahw
->pci_base2
== NULL
) {
647 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
652 } else if (mem_len
== NETXEN_PCI_2MB_SIZE
) {
654 ahw
->pci_base0
= pci_ioremap_bar(pdev
, 0);
655 if (ahw
->pci_base0
== NULL
) {
656 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
659 ahw
->pci_len0
= mem_len
;
664 netxen_setup_hwops(adapter
);
666 dev_info(&pdev
->dev
, "%dMB memory map\n", (int)(mem_len
>>20));
668 if (NX_IS_REVISION_P3P(adapter
->ahw
.revision_id
)) {
669 adapter
->ahw
.ocm_win_crb
= netxen_get_ioaddr(adapter
,
670 NETXEN_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(pci_func
)));
672 } else if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
673 adapter
->ahw
.ocm_win_crb
= netxen_get_ioaddr(adapter
,
674 NETXEN_PCIX_PS_REG(PCIE_MN_WINDOW_REG(pci_func
)));
677 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
680 db_base
= pci_resource_start(pdev
, 4); /* doorbell is on bar 4 */
681 db_len
= pci_resource_len(pdev
, 4);
684 printk(KERN_ERR
"%s: doorbell is disabled\n",
685 netxen_nic_driver_name
);
690 db_ptr
= ioremap(db_base
, NETXEN_DB_MAPSIZE_BYTES
);
692 printk(KERN_ERR
"%s: Failed to allocate doorbell map.",
693 netxen_nic_driver_name
);
699 adapter
->ahw
.db_base
= db_ptr
;
700 adapter
->ahw
.db_len
= db_len
;
704 netxen_cleanup_pci_map(adapter
);
709 netxen_check_options(struct netxen_adapter
*adapter
)
711 u32 fw_major
, fw_minor
, fw_build
;
712 char brd_name
[NETXEN_MAX_SHORT_NAME
];
716 struct pci_dev
*pdev
= adapter
->pdev
;
718 adapter
->driver_mismatch
= 0;
720 ptr32
= (int *)&serial_num
;
721 offset
= NX_FW_SERIAL_NUM_OFFSET
;
722 for (i
= 0; i
< 8; i
++) {
723 if (netxen_rom_fast_read(adapter
, offset
, &val
) == -1) {
724 dev_err(&pdev
->dev
, "error reading board info\n");
725 adapter
->driver_mismatch
= 1;
728 ptr32
[i
] = cpu_to_le32(val
);
729 offset
+= sizeof(u32
);
732 fw_major
= NXRD32(adapter
, NETXEN_FW_VERSION_MAJOR
);
733 fw_minor
= NXRD32(adapter
, NETXEN_FW_VERSION_MINOR
);
734 fw_build
= NXRD32(adapter
, NETXEN_FW_VERSION_SUB
);
736 adapter
->fw_version
= NETXEN_VERSION_CODE(fw_major
, fw_minor
, fw_build
);
738 if (adapter
->portnum
== 0) {
739 get_brd_name_by_type(adapter
->ahw
.board_type
, brd_name
);
741 pr_info("%s: %s Board S/N %s Chip rev 0x%x\n",
742 module_name(THIS_MODULE
),
743 brd_name
, serial_num
, adapter
->ahw
.revision_id
);
746 if (adapter
->fw_version
< NETXEN_VERSION_CODE(3, 4, 216)) {
747 adapter
->driver_mismatch
= 1;
748 dev_warn(&pdev
->dev
, "firmware version %d.%d.%d unsupported\n",
749 fw_major
, fw_minor
, fw_build
);
753 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
754 i
= NXRD32(adapter
, NETXEN_SRE_MISC
);
755 adapter
->ahw
.cut_through
= (i
& 0x8000) ? 1 : 0;
758 dev_info(&pdev
->dev
, "firmware v%d.%d.%d [%s]\n",
759 fw_major
, fw_minor
, fw_build
,
760 adapter
->ahw
.cut_through
? "cut-through" : "legacy");
762 if (adapter
->fw_version
>= NETXEN_VERSION_CODE(4, 0, 222))
763 adapter
->capabilities
= NXRD32(adapter
, CRB_FW_CAPABILITIES_1
);
765 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
766 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
767 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
768 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
769 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
770 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
773 adapter
->msix_supported
= 0;
774 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
775 adapter
->msix_supported
= !!use_msi_x
;
776 adapter
->rss_supported
= !!use_msi_x
;
779 netxen_rom_fast_read(adapter
,
780 NX_FW_VERSION_OFFSET
, (int *)&flashed_ver
);
781 flashed_ver
= NETXEN_DECODE_VERSION(flashed_ver
);
783 if (flashed_ver
>= NETXEN_VERSION_CODE(3, 4, 336)) {
784 switch (adapter
->ahw
.board_type
) {
785 case NETXEN_BRDTYPE_P2_SB31_10G
:
786 case NETXEN_BRDTYPE_P2_SB31_10G_CX4
:
787 adapter
->msix_supported
= !!use_msi_x
;
788 adapter
->rss_supported
= !!use_msi_x
;
796 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
798 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
799 adapter
->num_lro_rxd
= MAX_LRO_RCV_DESCRIPTORS
;
800 adapter
->max_rds_rings
= 3;
802 adapter
->num_lro_rxd
= 0;
803 adapter
->max_rds_rings
= 2;
808 netxen_start_firmware(struct netxen_adapter
*adapter
)
810 int val
, err
, first_boot
;
811 struct pci_dev
*pdev
= adapter
->pdev
;
813 /* required for NX2031 dummy dma */
814 err
= nx_set_dma_mask(adapter
);
818 if (!netxen_can_start_firmware(adapter
))
821 first_boot
= NXRD32(adapter
, NETXEN_CAM_RAM(0x1fc));
823 err
= netxen_check_hw_init(adapter
, first_boot
);
825 dev_err(&pdev
->dev
, "error in init HW init sequence\n");
829 netxen_request_firmware(adapter
);
831 err
= netxen_need_fw_reset(adapter
);
837 if (first_boot
!= 0x55555555) {
838 NXWR32(adapter
, CRB_CMDPEG_STATE
, 0);
839 netxen_pinit_from_rom(adapter
);
843 NXWR32(adapter
, CRB_DMA_SHIFT
, 0x55555555);
844 NXWR32(adapter
, NETXEN_PEG_HALT_STATUS1
, 0);
845 NXWR32(adapter
, NETXEN_PEG_HALT_STATUS2
, 0);
847 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
848 netxen_set_port_mode(adapter
);
850 err
= netxen_load_firmware(adapter
);
854 netxen_release_firmware(adapter
);
856 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
858 /* Initialize multicast addr pool owners */
860 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
)
862 NXWR32(adapter
, NETXEN_MAC_ADDR_CNTL_REG
, val
);
866 err
= netxen_init_dummy_dma(adapter
);
871 * Tell the hardware our version number.
873 val
= (_NETXEN_NIC_LINUX_MAJOR
<< 16)
874 | ((_NETXEN_NIC_LINUX_MINOR
<< 8))
875 | (_NETXEN_NIC_LINUX_SUBVERSION
);
876 NXWR32(adapter
, CRB_DRIVER_VERSION
, val
);
879 /* Handshake with the card before we register the devices. */
880 err
= netxen_phantom_init(adapter
, NETXEN_NIC_PEG_TUNE
);
882 netxen_free_dummy_dma(adapter
);
886 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_READY
);
888 nx_update_dma_mask(adapter
);
890 netxen_check_options(adapter
);
892 adapter
->need_fw_reset
= 0;
894 /* fall through and release firmware */
897 netxen_release_firmware(adapter
);
902 netxen_nic_request_irq(struct netxen_adapter
*adapter
)
904 irq_handler_t handler
;
905 struct nx_host_sds_ring
*sds_ring
;
908 unsigned long flags
= IRQF_SAMPLE_RANDOM
;
909 struct net_device
*netdev
= adapter
->netdev
;
910 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
912 if (adapter
->flags
& NETXEN_NIC_MSIX_ENABLED
)
913 handler
= netxen_msix_intr
;
914 else if (adapter
->flags
& NETXEN_NIC_MSI_ENABLED
)
915 handler
= netxen_msi_intr
;
917 flags
|= IRQF_SHARED
;
918 handler
= netxen_intr
;
920 adapter
->irq
= netdev
->irq
;
922 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
923 sds_ring
= &recv_ctx
->sds_rings
[ring
];
924 sprintf(sds_ring
->name
, "%s[%d]", netdev
->name
, ring
);
925 err
= request_irq(sds_ring
->irq
, handler
,
926 flags
, sds_ring
->name
, sds_ring
);
935 netxen_nic_free_irq(struct netxen_adapter
*adapter
)
938 struct nx_host_sds_ring
*sds_ring
;
940 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
942 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
943 sds_ring
= &recv_ctx
->sds_rings
[ring
];
944 free_irq(sds_ring
->irq
, sds_ring
);
949 netxen_nic_init_coalesce_defaults(struct netxen_adapter
*adapter
)
951 adapter
->coal
.flags
= NETXEN_NIC_INTR_DEFAULT
;
952 adapter
->coal
.normal
.data
.rx_time_us
=
953 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US
;
954 adapter
->coal
.normal
.data
.rx_packets
=
955 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS
;
956 adapter
->coal
.normal
.data
.tx_time_us
=
957 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US
;
958 adapter
->coal
.normal
.data
.tx_packets
=
959 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS
;
964 __netxen_nic_up(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
968 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
971 err
= adapter
->init_port(adapter
, adapter
->physical_port
);
973 printk(KERN_ERR
"%s: Failed to initialize port %d\n",
974 netxen_nic_driver_name
, adapter
->portnum
);
977 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
978 adapter
->macaddr_set(adapter
, adapter
->mac_addr
);
980 adapter
->set_multi(netdev
);
981 adapter
->set_mtu(adapter
, netdev
->mtu
);
983 adapter
->ahw
.linkup
= 0;
985 if (adapter
->max_sds_rings
> 1)
986 netxen_config_rss(adapter
, 1);
988 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
989 netxen_config_intr_coalesce(adapter
);
991 if (netdev
->features
& NETIF_F_LRO
)
992 netxen_config_hw_lro(adapter
, NETXEN_NIC_LRO_ENABLED
);
994 netxen_napi_enable(adapter
);
996 if (adapter
->capabilities
& NX_FW_CAPABILITY_LINK_NOTIFICATION
)
997 netxen_linkevent_request(adapter
, 1);
999 netxen_nic_set_link_parameters(adapter
);
1001 set_bit(__NX_DEV_UP
, &adapter
->state
);
1005 /* Usage: During resume and firmware recovery module.*/
1008 netxen_nic_up(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1013 if (netif_running(netdev
))
1014 err
= __netxen_nic_up(adapter
, netdev
);
1020 /* with rtnl_lock */
1022 __netxen_nic_down(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1024 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1027 if (!test_and_clear_bit(__NX_DEV_UP
, &adapter
->state
))
1031 spin_lock(&adapter
->tx_clean_lock
);
1032 netif_carrier_off(netdev
);
1033 netif_tx_disable(netdev
);
1035 if (adapter
->stop_port
)
1036 adapter
->stop_port(adapter
);
1038 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1039 netxen_p3_free_mac_list(adapter
);
1041 adapter
->set_promisc(adapter
, NETXEN_NIU_NON_PROMISC_MODE
);
1043 netxen_napi_disable(adapter
);
1045 netxen_release_tx_buffers(adapter
);
1046 spin_unlock(&adapter
->tx_clean_lock
);
1049 /* Usage: During suspend and firmware recovery module */
1052 netxen_nic_down(struct netxen_adapter
*adapter
, struct net_device
*netdev
)
1055 if (netif_running(netdev
))
1056 __netxen_nic_down(adapter
, netdev
);
1062 netxen_nic_attach(struct netxen_adapter
*adapter
)
1064 struct net_device
*netdev
= adapter
->netdev
;
1065 struct pci_dev
*pdev
= adapter
->pdev
;
1067 struct nx_host_rds_ring
*rds_ring
;
1068 struct nx_host_tx_ring
*tx_ring
;
1070 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
)
1073 err
= netxen_init_firmware(adapter
);
1077 err
= netxen_napi_add(adapter
, netdev
);
1081 err
= netxen_alloc_sw_resources(adapter
);
1083 printk(KERN_ERR
"%s: Error in setting sw resources\n",
1088 err
= netxen_alloc_hw_resources(adapter
);
1090 printk(KERN_ERR
"%s: Error in setting hw resources\n",
1092 goto err_out_free_sw
;
1095 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1096 tx_ring
= adapter
->tx_ring
;
1097 tx_ring
->crb_cmd_producer
= netxen_get_ioaddr(adapter
,
1098 crb_cmd_producer
[adapter
->portnum
]);
1099 tx_ring
->crb_cmd_consumer
= netxen_get_ioaddr(adapter
,
1100 crb_cmd_consumer
[adapter
->portnum
]);
1102 tx_ring
->producer
= 0;
1103 tx_ring
->sw_consumer
= 0;
1105 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
1106 netxen_nic_update_cmd_consumer(adapter
, tx_ring
);
1109 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1110 rds_ring
= &adapter
->recv_ctx
.rds_rings
[ring
];
1111 netxen_post_rx_buffers(adapter
, ring
, rds_ring
);
1114 err
= netxen_nic_request_irq(adapter
);
1116 dev_err(&pdev
->dev
, "%s: failed to setup interrupt\n",
1118 goto err_out_free_rxbuf
;
1121 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1122 netxen_nic_init_coalesce_defaults(adapter
);
1124 netxen_create_sysfs_entries(adapter
);
1126 adapter
->is_up
= NETXEN_ADAPTER_UP_MAGIC
;
1130 netxen_release_rx_buffers(adapter
);
1131 netxen_free_hw_resources(adapter
);
1133 netxen_free_sw_resources(adapter
);
1138 netxen_nic_detach(struct netxen_adapter
*adapter
)
1140 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
1143 netxen_remove_sysfs_entries(adapter
);
1145 netxen_free_hw_resources(adapter
);
1146 netxen_release_rx_buffers(adapter
);
1147 netxen_nic_free_irq(adapter
);
1148 netxen_napi_del(adapter
);
1149 netxen_free_sw_resources(adapter
);
1155 netxen_nic_reset_context(struct netxen_adapter
*adapter
)
1158 struct net_device
*netdev
= adapter
->netdev
;
1160 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
1163 if (adapter
->is_up
== NETXEN_ADAPTER_UP_MAGIC
) {
1165 netif_device_detach(netdev
);
1167 if (netif_running(netdev
))
1168 __netxen_nic_down(adapter
, netdev
);
1170 netxen_nic_detach(adapter
);
1172 if (netif_running(netdev
)) {
1173 err
= netxen_nic_attach(adapter
);
1175 err
= __netxen_nic_up(adapter
, netdev
);
1181 netif_device_attach(netdev
);
1185 clear_bit(__NX_RESETTING
, &adapter
->state
);
1190 netxen_setup_netdev(struct netxen_adapter
*adapter
,
1191 struct net_device
*netdev
)
1194 struct pci_dev
*pdev
= adapter
->pdev
;
1196 adapter
->rx_csum
= 1;
1197 adapter
->mc_enabled
= 0;
1198 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
1199 adapter
->max_mc_count
= 38;
1201 adapter
->max_mc_count
= 16;
1203 netdev
->netdev_ops
= &netxen_netdev_ops
;
1204 netdev
->watchdog_timeo
= 5*HZ
;
1206 netxen_nic_change_mtu(netdev
, netdev
->mtu
);
1208 SET_ETHTOOL_OPS(netdev
, &netxen_nic_ethtool_ops
);
1210 netdev
->features
|= (NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_TSO
);
1211 netdev
->features
|= (NETIF_F_GRO
);
1212 netdev
->vlan_features
|= (NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_TSO
);
1214 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
1215 netdev
->features
|= (NETIF_F_IPV6_CSUM
| NETIF_F_TSO6
);
1216 netdev
->vlan_features
|= (NETIF_F_IPV6_CSUM
| NETIF_F_TSO6
);
1219 if (adapter
->pci_using_dac
) {
1220 netdev
->features
|= NETIF_F_HIGHDMA
;
1221 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
1224 if (adapter
->capabilities
& NX_FW_CAPABILITY_FVLANTX
)
1225 netdev
->features
|= (NETIF_F_HW_VLAN_TX
);
1227 if (adapter
->capabilities
& NX_FW_CAPABILITY_HW_LRO
)
1228 netdev
->features
|= NETIF_F_LRO
;
1230 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1232 INIT_WORK(&adapter
->tx_timeout_task
, netxen_tx_timeout_task
);
1234 if (netxen_read_mac_addr(adapter
))
1235 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1237 netif_carrier_off(netdev
);
1239 err
= register_netdev(netdev
);
1241 dev_err(&pdev
->dev
, "failed to register net device\n");
1248 #ifdef CONFIG_PCIEAER
1249 static void netxen_mask_aer_correctable(struct netxen_adapter
*adapter
)
1251 struct pci_dev
*pdev
= adapter
->pdev
;
1252 struct pci_dev
*root
= pdev
->bus
->self
;
1255 if (adapter
->ahw
.board_type
!= NETXEN_BRDTYPE_P3_4_GB_MM
&&
1256 adapter
->ahw
.board_type
!= NETXEN_BRDTYPE_P3_10G_TP
)
1259 if (root
->pcie_type
!= PCI_EXP_TYPE_ROOT_PORT
)
1262 aer_pos
= pci_find_ext_capability(root
, PCI_EXT_CAP_ID_ERR
);
1266 pci_write_config_dword(root
, aer_pos
+ PCI_ERR_COR_MASK
, 0xffff);
1270 static int __devinit
1271 netxen_nic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1273 struct net_device
*netdev
= NULL
;
1274 struct netxen_adapter
*adapter
= NULL
;
1276 int pci_func_id
= PCI_FUNC(pdev
->devfn
);
1277 uint8_t revision_id
;
1280 if (pdev
->revision
>= NX_P3_A0
&& pdev
->revision
<= NX_P3_B1
) {
1281 pr_warning("%s: chip revisions between 0x%x-0x%x "
1282 "will not be enabled.\n",
1283 module_name(THIS_MODULE
), NX_P3_A0
, NX_P3_B1
);
1287 if ((err
= pci_enable_device(pdev
)))
1290 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1292 goto err_out_disable_pdev
;
1295 if ((err
= pci_request_regions(pdev
, netxen_nic_driver_name
)))
1296 goto err_out_disable_pdev
;
1298 if (NX_IS_REVISION_P3(pdev
->revision
))
1299 pci_enable_pcie_error_reporting(pdev
);
1301 pci_set_master(pdev
);
1303 netdev
= alloc_etherdev(sizeof(struct netxen_adapter
));
1305 dev_err(&pdev
->dev
, "failed to allocate net_device\n");
1307 goto err_out_free_res
;
1310 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1312 adapter
= netdev_priv(netdev
);
1313 adapter
->netdev
= netdev
;
1314 adapter
->pdev
= pdev
;
1315 adapter
->ahw
.pci_func
= pci_func_id
;
1317 revision_id
= pdev
->revision
;
1318 adapter
->ahw
.revision_id
= revision_id
;
1320 rwlock_init(&adapter
->ahw
.crb_lock
);
1321 spin_lock_init(&adapter
->ahw
.mem_lock
);
1323 spin_lock_init(&adapter
->tx_clean_lock
);
1324 INIT_LIST_HEAD(&adapter
->mac_list
);
1326 err
= netxen_setup_pci_map(adapter
);
1328 goto err_out_free_netdev
;
1330 /* This will be reset for mezz cards */
1331 adapter
->portnum
= pci_func_id
;
1333 err
= netxen_nic_get_board_info(adapter
);
1335 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1336 goto err_out_iounmap
;
1339 #ifdef CONFIG_PCIEAER
1340 netxen_mask_aer_correctable(adapter
);
1343 /* Mezz cards have PCI function 0,2,3 enabled */
1344 switch (adapter
->ahw
.board_type
) {
1345 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
1346 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
1347 if (pci_func_id
>= 2)
1348 adapter
->portnum
= pci_func_id
- 2;
1354 if (adapter
->portnum
== 0) {
1355 val
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
1356 if (val
!= 0xffffffff && val
!= 0) {
1357 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, 0);
1358 adapter
->need_fw_reset
= 1;
1362 err
= netxen_start_firmware(adapter
);
1364 goto err_out_decr_ref
;
1367 * See if the firmware gave us a virtual-physical port mapping.
1369 adapter
->physical_port
= adapter
->portnum
;
1370 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
1371 i
= NXRD32(adapter
, CRB_V2P(adapter
->portnum
));
1372 if (i
!= 0x55555555)
1373 adapter
->physical_port
= i
;
1376 netxen_nic_clear_stats(adapter
);
1378 netxen_setup_intr(adapter
);
1380 err
= netxen_setup_netdev(adapter
, netdev
);
1382 goto err_out_disable_msi
;
1384 pci_set_drvdata(pdev
, adapter
);
1386 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1388 switch (adapter
->ahw
.port_type
) {
1389 case NETXEN_NIC_GBE
:
1390 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1391 adapter
->netdev
->name
);
1393 case NETXEN_NIC_XGBE
:
1394 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1395 adapter
->netdev
->name
);
1399 netxen_create_diag_entries(adapter
);
1403 err_out_disable_msi
:
1404 netxen_teardown_intr(adapter
);
1406 netxen_free_dummy_dma(adapter
);
1409 nx_decr_dev_ref_cnt(adapter
);
1412 netxen_cleanup_pci_map(adapter
);
1414 err_out_free_netdev
:
1415 free_netdev(netdev
);
1418 pci_release_regions(pdev
);
1420 err_out_disable_pdev
:
1421 pci_set_drvdata(pdev
, NULL
);
1422 pci_disable_device(pdev
);
1426 static void __devexit
netxen_nic_remove(struct pci_dev
*pdev
)
1428 struct netxen_adapter
*adapter
;
1429 struct net_device
*netdev
;
1431 adapter
= pci_get_drvdata(pdev
);
1432 if (adapter
== NULL
)
1435 netdev
= adapter
->netdev
;
1437 netxen_cancel_fw_work(adapter
);
1439 unregister_netdev(netdev
);
1441 cancel_work_sync(&adapter
->tx_timeout_task
);
1443 netxen_nic_detach(adapter
);
1445 nx_decr_dev_ref_cnt(adapter
);
1447 if (adapter
->portnum
== 0)
1448 netxen_free_dummy_dma(adapter
);
1450 clear_bit(__NX_RESETTING
, &adapter
->state
);
1452 netxen_teardown_intr(adapter
);
1454 netxen_remove_diag_entries(adapter
);
1456 netxen_cleanup_pci_map(adapter
);
1458 netxen_release_firmware(adapter
);
1460 if (NX_IS_REVISION_P3(pdev
->revision
))
1461 pci_disable_pcie_error_reporting(pdev
);
1463 pci_release_regions(pdev
);
1464 pci_disable_device(pdev
);
1465 pci_set_drvdata(pdev
, NULL
);
1467 free_netdev(netdev
);
1470 static void netxen_nic_detach_func(struct netxen_adapter
*adapter
)
1472 struct net_device
*netdev
= adapter
->netdev
;
1474 netif_device_detach(netdev
);
1476 netxen_cancel_fw_work(adapter
);
1478 if (netif_running(netdev
))
1479 netxen_nic_down(adapter
, netdev
);
1481 cancel_work_sync(&adapter
->tx_timeout_task
);
1483 netxen_nic_detach(adapter
);
1485 if (adapter
->portnum
== 0)
1486 netxen_free_dummy_dma(adapter
);
1488 nx_decr_dev_ref_cnt(adapter
);
1490 clear_bit(__NX_RESETTING
, &adapter
->state
);
1493 static int netxen_nic_attach_func(struct pci_dev
*pdev
)
1495 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1496 struct net_device
*netdev
= adapter
->netdev
;
1499 err
= pci_enable_device(pdev
);
1503 pci_set_power_state(pdev
, PCI_D0
);
1504 pci_set_master(pdev
);
1505 pci_restore_state(pdev
);
1507 adapter
->ahw
.crb_win
= -1;
1508 adapter
->ahw
.ocm_win
= -1;
1510 err
= netxen_start_firmware(adapter
);
1512 dev_err(&pdev
->dev
, "failed to start firmware\n");
1516 if (netif_running(netdev
)) {
1517 err
= netxen_nic_attach(adapter
);
1521 err
= netxen_nic_up(adapter
, netdev
);
1523 goto err_out_detach
;
1525 netxen_config_indev_addr(netdev
, NETDEV_UP
);
1528 netif_device_attach(netdev
);
1529 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
1533 netxen_nic_detach(adapter
);
1535 nx_decr_dev_ref_cnt(adapter
);
1539 static pci_ers_result_t
netxen_io_error_detected(struct pci_dev
*pdev
,
1540 pci_channel_state_t state
)
1542 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1544 if (state
== pci_channel_io_perm_failure
)
1545 return PCI_ERS_RESULT_DISCONNECT
;
1547 if (nx_dev_request_aer(adapter
))
1548 return PCI_ERS_RESULT_RECOVERED
;
1550 netxen_nic_detach_func(adapter
);
1552 pci_disable_device(pdev
);
1554 return PCI_ERS_RESULT_NEED_RESET
;
1557 static pci_ers_result_t
netxen_io_slot_reset(struct pci_dev
*pdev
)
1561 err
= netxen_nic_attach_func(pdev
);
1563 return err
? PCI_ERS_RESULT_DISCONNECT
: PCI_ERS_RESULT_RECOVERED
;
1566 static void netxen_io_resume(struct pci_dev
*pdev
)
1568 pci_cleanup_aer_uncorrect_error_status(pdev
);
1571 static void netxen_nic_shutdown(struct pci_dev
*pdev
)
1573 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1575 netxen_nic_detach_func(adapter
);
1577 if (pci_save_state(pdev
))
1580 if (netxen_nic_wol_supported(adapter
)) {
1581 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1582 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1585 pci_disable_device(pdev
);
1590 netxen_nic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1592 struct netxen_adapter
*adapter
= pci_get_drvdata(pdev
);
1595 netxen_nic_detach_func(adapter
);
1597 retval
= pci_save_state(pdev
);
1601 if (netxen_nic_wol_supported(adapter
)) {
1602 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1603 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1606 pci_disable_device(pdev
);
1607 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1613 netxen_nic_resume(struct pci_dev
*pdev
)
1615 return netxen_nic_attach_func(pdev
);
1619 static int netxen_nic_open(struct net_device
*netdev
)
1621 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1624 if (adapter
->driver_mismatch
)
1627 err
= netxen_nic_attach(adapter
);
1631 err
= __netxen_nic_up(adapter
, netdev
);
1635 netif_start_queue(netdev
);
1640 netxen_nic_detach(adapter
);
1645 * netxen_nic_close - Disables a network interface entry point
1647 static int netxen_nic_close(struct net_device
*netdev
)
1649 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1651 __netxen_nic_down(adapter
, netdev
);
1656 netxen_tso_check(struct net_device
*netdev
,
1657 struct nx_host_tx_ring
*tx_ring
,
1658 struct cmd_desc_type0
*first_desc
,
1659 struct sk_buff
*skb
)
1661 u8 opcode
= TX_ETHER_PKT
;
1662 __be16 protocol
= skb
->protocol
;
1663 u16 flags
= 0, vid
= 0;
1665 int copied
, offset
, copy_len
, hdr_len
= 0, tso
= 0, vlan_oob
= 0;
1666 struct cmd_desc_type0
*hwdesc
;
1667 struct vlan_ethhdr
*vh
;
1669 if (protocol
== cpu_to_be16(ETH_P_8021Q
)) {
1671 vh
= (struct vlan_ethhdr
*)skb
->data
;
1672 protocol
= vh
->h_vlan_encapsulated_proto
;
1673 flags
= FLAGS_VLAN_TAGGED
;
1675 } else if (vlan_tx_tag_present(skb
)) {
1677 flags
= FLAGS_VLAN_OOB
;
1678 vid
= vlan_tx_tag_get(skb
);
1679 netxen_set_tx_vlan_tci(first_desc
, vid
);
1683 if ((netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
1684 skb_shinfo(skb
)->gso_size
> 0) {
1686 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
1688 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
1689 first_desc
->total_hdr_length
= hdr_len
;
1691 first_desc
->total_hdr_length
+= VLAN_HLEN
;
1692 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
1693 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
1694 /* Only in case of TSO on vlan device */
1695 flags
|= FLAGS_VLAN_TAGGED
;
1698 opcode
= (protocol
== cpu_to_be16(ETH_P_IPV6
)) ?
1699 TX_TCP_LSO6
: TX_TCP_LSO
;
1702 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1705 if (protocol
== cpu_to_be16(ETH_P_IP
)) {
1706 l4proto
= ip_hdr(skb
)->protocol
;
1708 if (l4proto
== IPPROTO_TCP
)
1709 opcode
= TX_TCP_PKT
;
1710 else if(l4proto
== IPPROTO_UDP
)
1711 opcode
= TX_UDP_PKT
;
1712 } else if (protocol
== cpu_to_be16(ETH_P_IPV6
)) {
1713 l4proto
= ipv6_hdr(skb
)->nexthdr
;
1715 if (l4proto
== IPPROTO_TCP
)
1716 opcode
= TX_TCPV6_PKT
;
1717 else if(l4proto
== IPPROTO_UDP
)
1718 opcode
= TX_UDPV6_PKT
;
1722 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
1723 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
1724 netxen_set_tx_flags_opcode(first_desc
, flags
, opcode
);
1729 /* For LSO, we need to copy the MAC/IP/TCP headers into
1730 * the descriptor ring
1732 producer
= tx_ring
->producer
;
1737 /* Create a TSO vlan header template for firmware */
1739 hwdesc
= &tx_ring
->desc_head
[producer
];
1740 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1742 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1743 hdr_len
+ VLAN_HLEN
);
1745 vh
= (struct vlan_ethhdr
*)((char *)hwdesc
+ 2);
1746 skb_copy_from_linear_data(skb
, vh
, 12);
1747 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
1748 vh
->h_vlan_TCI
= htons(vid
);
1749 skb_copy_from_linear_data_offset(skb
, 12,
1750 (char *)vh
+ 16, copy_len
- 16);
1752 copied
= copy_len
- VLAN_HLEN
;
1755 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1758 while (copied
< hdr_len
) {
1760 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1761 (hdr_len
- copied
));
1763 hwdesc
= &tx_ring
->desc_head
[producer
];
1764 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1766 skb_copy_from_linear_data_offset(skb
, copied
,
1767 (char *)hwdesc
+ offset
, copy_len
);
1772 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1775 tx_ring
->producer
= producer
;
1780 netxen_map_tx_skb(struct pci_dev
*pdev
,
1781 struct sk_buff
*skb
, struct netxen_cmd_buffer
*pbuf
)
1783 struct netxen_skb_frag
*nf
;
1784 struct skb_frag_struct
*frag
;
1788 nr_frags
= skb_shinfo(skb
)->nr_frags
;
1789 nf
= &pbuf
->frag_array
[0];
1791 map
= pci_map_single(pdev
, skb
->data
,
1792 skb_headlen(skb
), PCI_DMA_TODEVICE
);
1793 if (pci_dma_mapping_error(pdev
, map
))
1797 nf
->length
= skb_headlen(skb
);
1799 for (i
= 0; i
< nr_frags
; i
++) {
1800 frag
= &skb_shinfo(skb
)->frags
[i
];
1801 nf
= &pbuf
->frag_array
[i
+1];
1803 map
= pci_map_page(pdev
, frag
->page
, frag
->page_offset
,
1804 frag
->size
, PCI_DMA_TODEVICE
);
1805 if (pci_dma_mapping_error(pdev
, map
))
1809 nf
->length
= frag
->size
;
1816 nf
= &pbuf
->frag_array
[i
+1];
1817 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
1820 nf
= &pbuf
->frag_array
[0];
1821 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
1828 netxen_clear_cmddesc(u64
*desc
)
1835 netxen_nic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
1837 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
1838 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1839 struct netxen_cmd_buffer
*pbuf
;
1840 struct netxen_skb_frag
*buffrag
;
1841 struct cmd_desc_type0
*hwdesc
, *first_desc
;
1842 struct pci_dev
*pdev
;
1846 int frag_count
, no_of_desc
;
1847 u32 num_txd
= tx_ring
->num_desc
;
1849 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
1851 /* 4 fragments per cmd des */
1852 no_of_desc
= (frag_count
+ 3) >> 2;
1854 if (unlikely(netxen_tx_avail(tx_ring
) <= TX_STOP_THRESH
)) {
1855 netif_stop_queue(netdev
);
1857 if (netxen_tx_avail(tx_ring
) > TX_STOP_THRESH
)
1858 netif_start_queue(netdev
);
1860 return NETDEV_TX_BUSY
;
1863 producer
= tx_ring
->producer
;
1864 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
1866 pdev
= adapter
->pdev
;
1868 if (netxen_map_tx_skb(pdev
, skb
, pbuf
))
1872 pbuf
->frag_count
= frag_count
;
1874 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
1875 netxen_clear_cmddesc((u64
*)hwdesc
);
1877 netxen_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
1878 netxen_set_tx_port(first_desc
, adapter
->portnum
);
1880 for (i
= 0; i
< frag_count
; i
++) {
1884 if ((k
== 0) && (i
> 0)) {
1885 /* move to next desc.*/
1886 producer
= get_next_index(producer
, num_txd
);
1887 hwdesc
= &tx_ring
->desc_head
[producer
];
1888 netxen_clear_cmddesc((u64
*)hwdesc
);
1889 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1892 buffrag
= &pbuf
->frag_array
[i
];
1894 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
1897 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
1900 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
1903 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
1906 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
1911 tx_ring
->producer
= get_next_index(producer
, num_txd
);
1913 netxen_tso_check(netdev
, tx_ring
, first_desc
, skb
);
1915 netxen_nic_update_cmd_producer(adapter
, tx_ring
);
1917 adapter
->stats
.txbytes
+= skb
->len
;
1918 adapter
->stats
.xmitcalled
++;
1920 return NETDEV_TX_OK
;
1923 adapter
->stats
.txdropped
++;
1924 dev_kfree_skb_any(skb
);
1925 return NETDEV_TX_OK
;
1928 static int netxen_nic_check_temp(struct netxen_adapter
*adapter
)
1930 struct net_device
*netdev
= adapter
->netdev
;
1931 uint32_t temp
, temp_state
, temp_val
;
1934 temp
= NXRD32(adapter
, CRB_TEMP_STATE
);
1936 temp_state
= nx_get_temp_state(temp
);
1937 temp_val
= nx_get_temp_val(temp
);
1939 if (temp_state
== NX_TEMP_PANIC
) {
1941 "%s: Device temperature %d degrees C exceeds"
1942 " maximum allowed. Hardware has been shut down.\n",
1943 netdev
->name
, temp_val
);
1945 } else if (temp_state
== NX_TEMP_WARN
) {
1946 if (adapter
->temp
== NX_TEMP_NORMAL
) {
1948 "%s: Device temperature %d degrees C "
1949 "exceeds operating range."
1950 " Immediate action needed.\n",
1951 netdev
->name
, temp_val
);
1954 if (adapter
->temp
== NX_TEMP_WARN
) {
1956 "%s: Device temperature is now %d degrees C"
1957 " in normal range.\n", netdev
->name
,
1961 adapter
->temp
= temp_state
;
1965 void netxen_advert_link_change(struct netxen_adapter
*adapter
, int linkup
)
1967 struct net_device
*netdev
= adapter
->netdev
;
1969 if (adapter
->ahw
.linkup
&& !linkup
) {
1970 printk(KERN_INFO
"%s: %s NIC Link is down\n",
1971 netxen_nic_driver_name
, netdev
->name
);
1972 adapter
->ahw
.linkup
= 0;
1973 if (netif_running(netdev
)) {
1974 netif_carrier_off(netdev
);
1975 netif_stop_queue(netdev
);
1977 adapter
->link_changed
= !adapter
->has_link_events
;
1978 } else if (!adapter
->ahw
.linkup
&& linkup
) {
1979 printk(KERN_INFO
"%s: %s NIC Link is up\n",
1980 netxen_nic_driver_name
, netdev
->name
);
1981 adapter
->ahw
.linkup
= 1;
1982 if (netif_running(netdev
)) {
1983 netif_carrier_on(netdev
);
1984 netif_wake_queue(netdev
);
1986 adapter
->link_changed
= !adapter
->has_link_events
;
1990 static void netxen_nic_handle_phy_intr(struct netxen_adapter
*adapter
)
1992 u32 val
, port
, linkup
;
1994 port
= adapter
->physical_port
;
1996 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
1997 val
= NXRD32(adapter
, CRB_XG_STATE_P3
);
1998 val
= XG_LINK_STATE_P3(adapter
->ahw
.pci_func
, val
);
1999 linkup
= (val
== XG_LINK_UP_P3
);
2001 val
= NXRD32(adapter
, CRB_XG_STATE
);
2002 val
= (val
>> port
*8) & 0xff;
2003 linkup
= (val
== XG_LINK_UP
);
2006 netxen_advert_link_change(adapter
, linkup
);
2009 static void netxen_tx_timeout(struct net_device
*netdev
)
2011 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2013 if (test_bit(__NX_RESETTING
, &adapter
->state
))
2016 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
2017 schedule_work(&adapter
->tx_timeout_task
);
2020 static void netxen_tx_timeout_task(struct work_struct
*work
)
2022 struct netxen_adapter
*adapter
=
2023 container_of(work
, struct netxen_adapter
, tx_timeout_task
);
2025 if (!netif_running(adapter
->netdev
))
2028 if (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2031 if (++adapter
->tx_timeo_cnt
>= NX_MAX_TX_TIMEOUTS
)
2035 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
2036 /* try to scrub interrupt */
2037 netxen_napi_disable(adapter
);
2039 netxen_napi_enable(adapter
);
2041 netif_wake_queue(adapter
->netdev
);
2043 clear_bit(__NX_RESETTING
, &adapter
->state
);
2045 clear_bit(__NX_RESETTING
, &adapter
->state
);
2046 if (netxen_nic_reset_context(adapter
)) {
2051 adapter
->netdev
->trans_start
= jiffies
;
2056 adapter
->need_fw_reset
= 1;
2057 clear_bit(__NX_RESETTING
, &adapter
->state
);
2060 static struct net_device_stats
*netxen_nic_get_stats(struct net_device
*netdev
)
2062 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2063 struct net_device_stats
*stats
= &netdev
->stats
;
2065 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
2066 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
2067 stats
->rx_bytes
= adapter
->stats
.rxbytes
;
2068 stats
->tx_bytes
= adapter
->stats
.txbytes
;
2069 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
2070 stats
->tx_dropped
= adapter
->stats
.txdropped
;
2075 static irqreturn_t
netxen_intr(int irq
, void *data
)
2077 struct nx_host_sds_ring
*sds_ring
= data
;
2078 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2081 status
= readl(adapter
->isr_int_vec
);
2083 if (!(status
& adapter
->int_vec_bit
))
2086 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
2087 /* check interrupt state machine, to be sure */
2088 status
= readl(adapter
->crb_int_state_reg
);
2089 if (!ISR_LEGACY_INT_TRIGGERED(status
))
2093 unsigned long our_int
= 0;
2095 our_int
= readl(adapter
->crb_int_state_reg
);
2097 /* not our interrupt */
2098 if (!test_and_clear_bit((7 + adapter
->portnum
), &our_int
))
2101 /* claim interrupt */
2102 writel((our_int
& 0xffffffff), adapter
->crb_int_state_reg
);
2104 /* clear interrupt */
2105 netxen_nic_disable_int(sds_ring
);
2108 writel(0xffffffff, adapter
->tgt_status_reg
);
2109 /* read twice to ensure write is flushed */
2110 readl(adapter
->isr_int_vec
);
2111 readl(adapter
->isr_int_vec
);
2113 napi_schedule(&sds_ring
->napi
);
2118 static irqreturn_t
netxen_msi_intr(int irq
, void *data
)
2120 struct nx_host_sds_ring
*sds_ring
= data
;
2121 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2123 /* clear interrupt */
2124 writel(0xffffffff, adapter
->tgt_status_reg
);
2126 napi_schedule(&sds_ring
->napi
);
2130 static irqreturn_t
netxen_msix_intr(int irq
, void *data
)
2132 struct nx_host_sds_ring
*sds_ring
= data
;
2134 napi_schedule(&sds_ring
->napi
);
2138 static int netxen_nic_poll(struct napi_struct
*napi
, int budget
)
2140 struct nx_host_sds_ring
*sds_ring
=
2141 container_of(napi
, struct nx_host_sds_ring
, napi
);
2143 struct netxen_adapter
*adapter
= sds_ring
->adapter
;
2148 tx_complete
= netxen_process_cmd_ring(adapter
);
2150 work_done
= netxen_process_rcv_ring(sds_ring
, budget
);
2152 if ((work_done
< budget
) && tx_complete
) {
2153 napi_complete(&sds_ring
->napi
);
2154 if (test_bit(__NX_DEV_UP
, &adapter
->state
))
2155 netxen_nic_enable_int(sds_ring
);
2161 #ifdef CONFIG_NET_POLL_CONTROLLER
2162 static void netxen_nic_poll_controller(struct net_device
*netdev
)
2165 struct nx_host_sds_ring
*sds_ring
;
2166 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
2167 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
2169 disable_irq(adapter
->irq
);
2170 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
2171 sds_ring
= &recv_ctx
->sds_rings
[ring
];
2172 netxen_intr(adapter
->irq
, sds_ring
);
2174 enable_irq(adapter
->irq
);
2179 nx_incr_dev_ref_cnt(struct netxen_adapter
*adapter
)
2182 if (netxen_api_lock(adapter
))
2185 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2187 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, ++count
);
2189 netxen_api_unlock(adapter
);
2194 nx_decr_dev_ref_cnt(struct netxen_adapter
*adapter
)
2197 if (netxen_api_lock(adapter
))
2200 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2201 WARN_ON(count
== 0);
2203 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, --count
);
2206 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_COLD
);
2208 netxen_api_unlock(adapter
);
2213 nx_dev_request_aer(struct netxen_adapter
*adapter
)
2218 if (netxen_api_lock(adapter
))
2221 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2223 if (state
== NX_DEV_NEED_AER
)
2225 else if (state
== NX_DEV_READY
) {
2226 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_NEED_AER
);
2230 netxen_api_unlock(adapter
);
2235 nx_dev_request_reset(struct netxen_adapter
*adapter
)
2240 if (netxen_api_lock(adapter
))
2243 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2245 if (state
== NX_DEV_NEED_RESET
)
2247 else if (state
!= NX_DEV_INITALIZING
&& state
!= NX_DEV_NEED_AER
) {
2248 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_NEED_RESET
);
2252 netxen_api_unlock(adapter
);
2258 netxen_can_start_firmware(struct netxen_adapter
*adapter
)
2263 if (netxen_api_lock(adapter
))
2266 count
= NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
2268 if ((count
< 0) || (count
>= NX_MAX_PCI_FUNC
))
2273 NXWR32(adapter
, NX_CRB_DEV_STATE
, NX_DEV_INITALIZING
);
2276 NXWR32(adapter
, NX_CRB_DEV_REF_COUNT
, ++count
);
2278 netxen_api_unlock(adapter
);
2284 netxen_schedule_work(struct netxen_adapter
*adapter
,
2285 work_func_t func
, int delay
)
2287 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
2288 schedule_delayed_work(&adapter
->fw_work
, delay
);
2292 netxen_cancel_fw_work(struct netxen_adapter
*adapter
)
2294 while (test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2297 cancel_delayed_work_sync(&adapter
->fw_work
);
2301 netxen_attach_work(struct work_struct
*work
)
2303 struct netxen_adapter
*adapter
= container_of(work
,
2304 struct netxen_adapter
, fw_work
.work
);
2305 struct net_device
*netdev
= adapter
->netdev
;
2308 if (netif_running(netdev
)) {
2309 err
= netxen_nic_attach(adapter
);
2313 err
= netxen_nic_up(adapter
, netdev
);
2315 netxen_nic_detach(adapter
);
2319 netxen_config_indev_addr(netdev
, NETDEV_UP
);
2322 netif_device_attach(netdev
);
2325 adapter
->fw_fail_cnt
= 0;
2326 clear_bit(__NX_RESETTING
, &adapter
->state
);
2327 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
2331 netxen_fwinit_work(struct work_struct
*work
)
2333 struct netxen_adapter
*adapter
= container_of(work
,
2334 struct netxen_adapter
, fw_work
.work
);
2337 dev_state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2339 switch (dev_state
) {
2342 if (!netxen_start_firmware(adapter
)) {
2343 netxen_schedule_work(adapter
, netxen_attach_work
, 0);
2348 case NX_DEV_NEED_RESET
:
2349 case NX_DEV_INITALIZING
:
2350 if (++adapter
->fw_wait_cnt
< FW_POLL_THRESH
) {
2351 netxen_schedule_work(adapter
,
2352 netxen_fwinit_work
, 2 * FW_POLL_DELAY
);
2358 nx_incr_dev_ref_cnt(adapter
);
2362 clear_bit(__NX_RESETTING
, &adapter
->state
);
2366 netxen_detach_work(struct work_struct
*work
)
2368 struct netxen_adapter
*adapter
= container_of(work
,
2369 struct netxen_adapter
, fw_work
.work
);
2370 struct net_device
*netdev
= adapter
->netdev
;
2374 netif_device_detach(netdev
);
2376 netxen_nic_down(adapter
, netdev
);
2379 netxen_nic_detach(adapter
);
2382 status
= NXRD32(adapter
, NETXEN_PEG_HALT_STATUS1
);
2384 if (status
& NX_RCODE_FATAL_ERROR
)
2387 if (adapter
->temp
== NX_TEMP_PANIC
)
2390 ref_cnt
= nx_decr_dev_ref_cnt(adapter
);
2392 if (ref_cnt
== -EIO
)
2395 delay
= (ref_cnt
== 0) ? 0 : (2 * FW_POLL_DELAY
);
2397 adapter
->fw_wait_cnt
= 0;
2398 netxen_schedule_work(adapter
, netxen_fwinit_work
, delay
);
2403 clear_bit(__NX_RESETTING
, &adapter
->state
);
2407 netxen_check_health(struct netxen_adapter
*adapter
)
2409 u32 state
, heartbit
;
2410 struct net_device
*netdev
= adapter
->netdev
;
2412 state
= NXRD32(adapter
, NX_CRB_DEV_STATE
);
2413 if (state
== NX_DEV_NEED_AER
)
2416 if (netxen_nic_check_temp(adapter
))
2419 if (adapter
->need_fw_reset
) {
2420 if (nx_dev_request_reset(adapter
))
2425 /* NX_DEV_NEED_RESET, this state can be marked in two cases
2426 * 1. Tx timeout 2. Fw hang
2427 * Send request to destroy context in case of tx timeout only
2428 * and doesn't required in case of Fw hang
2430 if (state
== NX_DEV_NEED_RESET
) {
2431 adapter
->need_fw_reset
= 1;
2432 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2436 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2439 heartbit
= NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
2440 if (heartbit
!= adapter
->heartbit
) {
2441 adapter
->heartbit
= heartbit
;
2442 adapter
->fw_fail_cnt
= 0;
2443 if (adapter
->need_fw_reset
)
2448 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
2451 if (nx_dev_request_reset(adapter
))
2454 clear_bit(__NX_FW_ATTACHED
, &adapter
->state
);
2456 dev_info(&netdev
->dev
, "firmware hang detected\n");
2459 if ((auto_fw_reset
== AUTO_FW_RESET_ENABLED
) &&
2460 !test_and_set_bit(__NX_RESETTING
, &adapter
->state
))
2461 netxen_schedule_work(adapter
, netxen_detach_work
, 0);
2466 netxen_fw_poll_work(struct work_struct
*work
)
2468 struct netxen_adapter
*adapter
= container_of(work
,
2469 struct netxen_adapter
, fw_work
.work
);
2471 if (test_bit(__NX_RESETTING
, &adapter
->state
))
2474 if (test_bit(__NX_DEV_UP
, &adapter
->state
)) {
2475 if (!adapter
->has_link_events
) {
2477 netxen_nic_handle_phy_intr(adapter
);
2479 if (adapter
->link_changed
)
2480 netxen_nic_set_link_parameters(adapter
);
2484 if (netxen_check_health(adapter
))
2488 netxen_schedule_work(adapter
, netxen_fw_poll_work
, FW_POLL_DELAY
);
2492 netxen_store_bridged_mode(struct device
*dev
,
2493 struct device_attribute
*attr
, const char *buf
, size_t len
)
2495 struct net_device
*net
= to_net_dev(dev
);
2496 struct netxen_adapter
*adapter
= netdev_priv(net
);
2500 if (!(adapter
->capabilities
& NX_FW_CAPABILITY_BDG
))
2503 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
2506 if (strict_strtoul(buf
, 2, &new))
2509 if (!netxen_config_bridged_mode(adapter
, !!new))
2517 netxen_show_bridged_mode(struct device
*dev
,
2518 struct device_attribute
*attr
, char *buf
)
2520 struct net_device
*net
= to_net_dev(dev
);
2521 struct netxen_adapter
*adapter
;
2522 int bridged_mode
= 0;
2524 adapter
= netdev_priv(net
);
2526 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
2527 bridged_mode
= !!(adapter
->flags
& NETXEN_NIC_BRIDGE_ENABLED
);
2529 return sprintf(buf
, "%d\n", bridged_mode
);
2532 static struct device_attribute dev_attr_bridged_mode
= {
2533 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2534 .show
= netxen_show_bridged_mode
,
2535 .store
= netxen_store_bridged_mode
,
2539 netxen_store_diag_mode(struct device
*dev
,
2540 struct device_attribute
*attr
, const char *buf
, size_t len
)
2542 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2545 if (strict_strtoul(buf
, 2, &new))
2548 if (!!new != !!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2549 adapter
->flags
^= NETXEN_NIC_DIAG_ENABLED
;
2555 netxen_show_diag_mode(struct device
*dev
,
2556 struct device_attribute
*attr
, char *buf
)
2558 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2560 return sprintf(buf
, "%d\n",
2561 !!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
));
2564 static struct device_attribute dev_attr_diag_mode
= {
2565 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2566 .show
= netxen_show_diag_mode
,
2567 .store
= netxen_store_diag_mode
,
2571 netxen_sysfs_validate_crb(struct netxen_adapter
*adapter
,
2572 loff_t offset
, size_t size
)
2574 size_t crb_size
= 4;
2576 if (!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2579 if (offset
< NETXEN_PCI_CRBSPACE
) {
2580 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2583 if (ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2584 NETXEN_PCI_CAMQM_2M_END
))
2590 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
2597 netxen_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
2598 struct bin_attribute
*attr
,
2599 char *buf
, loff_t offset
, size_t size
)
2601 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2602 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2607 ret
= netxen_sysfs_validate_crb(adapter
, offset
, size
);
2611 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) &&
2612 ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2613 NETXEN_PCI_CAMQM_2M_END
)) {
2614 netxen_pci_camqm_read_2M(adapter
, offset
, &qmdata
);
2615 memcpy(buf
, &qmdata
, size
);
2617 data
= NXRD32(adapter
, offset
);
2618 memcpy(buf
, &data
, size
);
2625 netxen_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
2626 struct bin_attribute
*attr
,
2627 char *buf
, loff_t offset
, size_t size
)
2629 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2630 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2635 ret
= netxen_sysfs_validate_crb(adapter
, offset
, size
);
2639 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
) &&
2640 ADDR_IN_RANGE(offset
, NETXEN_PCI_CAMQM
,
2641 NETXEN_PCI_CAMQM_2M_END
)) {
2642 memcpy(&qmdata
, buf
, size
);
2643 netxen_pci_camqm_write_2M(adapter
, offset
, qmdata
);
2645 memcpy(&data
, buf
, size
);
2646 NXWR32(adapter
, offset
, data
);
2653 netxen_sysfs_validate_mem(struct netxen_adapter
*adapter
,
2654 loff_t offset
, size_t size
)
2656 if (!(adapter
->flags
& NETXEN_NIC_DIAG_ENABLED
))
2659 if ((size
!= 8) || (offset
& 0x7))
2666 netxen_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
2667 struct bin_attribute
*attr
,
2668 char *buf
, loff_t offset
, size_t size
)
2670 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2671 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2675 ret
= netxen_sysfs_validate_mem(adapter
, offset
, size
);
2679 if (adapter
->pci_mem_read(adapter
, offset
, &data
))
2682 memcpy(buf
, &data
, size
);
2687 static ssize_t
netxen_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
2688 struct bin_attribute
*attr
, char *buf
,
2689 loff_t offset
, size_t size
)
2691 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2692 struct netxen_adapter
*adapter
= dev_get_drvdata(dev
);
2696 ret
= netxen_sysfs_validate_mem(adapter
, offset
, size
);
2700 memcpy(&data
, buf
, size
);
2702 if (adapter
->pci_mem_write(adapter
, offset
, data
))
2709 static struct bin_attribute bin_attr_crb
= {
2710 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
2712 .read
= netxen_sysfs_read_crb
,
2713 .write
= netxen_sysfs_write_crb
,
2716 static struct bin_attribute bin_attr_mem
= {
2717 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
2719 .read
= netxen_sysfs_read_mem
,
2720 .write
= netxen_sysfs_write_mem
,
2725 netxen_create_sysfs_entries(struct netxen_adapter
*adapter
)
2727 struct net_device
*netdev
= adapter
->netdev
;
2728 struct device
*dev
= &netdev
->dev
;
2730 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
) {
2731 /* bridged_mode control */
2732 if (device_create_file(dev
, &dev_attr_bridged_mode
)) {
2733 dev_warn(&netdev
->dev
,
2734 "failed to create bridged_mode sysfs entry\n");
2740 netxen_remove_sysfs_entries(struct netxen_adapter
*adapter
)
2742 struct net_device
*netdev
= adapter
->netdev
;
2743 struct device
*dev
= &netdev
->dev
;
2745 if (adapter
->capabilities
& NX_FW_CAPABILITY_BDG
)
2746 device_remove_file(dev
, &dev_attr_bridged_mode
);
2750 netxen_create_diag_entries(struct netxen_adapter
*adapter
)
2752 struct pci_dev
*pdev
= adapter
->pdev
;
2756 if (device_create_file(dev
, &dev_attr_diag_mode
))
2757 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
2758 if (device_create_bin_file(dev
, &bin_attr_crb
))
2759 dev_info(dev
, "failed to create crb sysfs entry\n");
2760 if (device_create_bin_file(dev
, &bin_attr_mem
))
2761 dev_info(dev
, "failed to create mem sysfs entry\n");
2766 netxen_remove_diag_entries(struct netxen_adapter
*adapter
)
2768 struct pci_dev
*pdev
= adapter
->pdev
;
2769 struct device
*dev
= &pdev
->dev
;
2771 device_remove_file(dev
, &dev_attr_diag_mode
);
2772 device_remove_bin_file(dev
, &bin_attr_crb
);
2773 device_remove_bin_file(dev
, &bin_attr_mem
);
2778 #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2781 netxen_destip_supported(struct netxen_adapter
*adapter
)
2783 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
2786 if (adapter
->ahw
.cut_through
)
2793 netxen_config_indev_addr(struct net_device
*dev
, unsigned long event
)
2795 struct in_device
*indev
;
2796 struct netxen_adapter
*adapter
= netdev_priv(dev
);
2798 if (!netxen_destip_supported(adapter
))
2801 indev
= in_dev_get(dev
);
2808 netxen_config_ipaddr(adapter
,
2809 ifa
->ifa_address
, NX_IP_UP
);
2812 netxen_config_ipaddr(adapter
,
2813 ifa
->ifa_address
, NX_IP_DOWN
);
2818 } endfor_ifa(indev
);
2823 static int netxen_netdev_event(struct notifier_block
*this,
2824 unsigned long event
, void *ptr
)
2826 struct netxen_adapter
*adapter
;
2827 struct net_device
*dev
= (struct net_device
*)ptr
;
2833 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
2834 dev
= vlan_dev_real_dev(dev
);
2838 if (!is_netxen_netdev(dev
))
2841 adapter
= netdev_priv(dev
);
2846 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
2849 netxen_config_indev_addr(dev
, event
);
2855 netxen_inetaddr_event(struct notifier_block
*this,
2856 unsigned long event
, void *ptr
)
2858 struct netxen_adapter
*adapter
;
2859 struct net_device
*dev
;
2861 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
2863 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
2866 if (dev
== NULL
|| !netif_running(dev
))
2869 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
2870 dev
= vlan_dev_real_dev(dev
);
2874 if (!is_netxen_netdev(dev
))
2877 adapter
= netdev_priv(dev
);
2879 if (!adapter
|| !netxen_destip_supported(adapter
))
2882 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
2887 netxen_config_ipaddr(adapter
, ifa
->ifa_address
, NX_IP_UP
);
2890 netxen_config_ipaddr(adapter
, ifa
->ifa_address
, NX_IP_DOWN
);
2900 static struct notifier_block netxen_netdev_cb
= {
2901 .notifier_call
= netxen_netdev_event
,
2904 static struct notifier_block netxen_inetaddr_cb
= {
2905 .notifier_call
= netxen_inetaddr_event
,
2909 netxen_config_indev_addr(struct net_device
*dev
, unsigned long event
)
2913 static struct pci_error_handlers netxen_err_handler
= {
2914 .error_detected
= netxen_io_error_detected
,
2915 .slot_reset
= netxen_io_slot_reset
,
2916 .resume
= netxen_io_resume
,
2919 static struct pci_driver netxen_driver
= {
2920 .name
= netxen_nic_driver_name
,
2921 .id_table
= netxen_pci_tbl
,
2922 .probe
= netxen_nic_probe
,
2923 .remove
= __devexit_p(netxen_nic_remove
),
2925 .suspend
= netxen_nic_suspend
,
2926 .resume
= netxen_nic_resume
,
2928 .shutdown
= netxen_nic_shutdown
,
2929 .err_handler
= &netxen_err_handler
2932 static int __init
netxen_init_module(void)
2934 printk(KERN_INFO
"%s\n", netxen_nic_driver_string
);
2937 register_netdevice_notifier(&netxen_netdev_cb
);
2938 register_inetaddr_notifier(&netxen_inetaddr_cb
);
2940 return pci_register_driver(&netxen_driver
);
2943 module_init(netxen_init_module
);
2945 static void __exit
netxen_exit_module(void)
2947 pci_unregister_driver(&netxen_driver
);
2950 unregister_inetaddr_notifier(&netxen_inetaddr_cb
);
2951 unregister_netdevice_notifier(&netxen_netdev_cb
);
2955 module_exit(netxen_exit_module
);