proc: use seq_puts()/seq_putc() where possible
[linux-2.6/next.git] / drivers / net / netxen / netxen_nic_main.c
blob33fac32e0d9fd9dce1333b6f2ad7a7d4d615121a
1 /*
2 * Copyright (C) 2003 - 2009 NetXen, Inc.
3 * Copyright (C) 2009 - QLogic Corporation.
4 * All rights reserved.
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,
19 * MA 02111-1307, USA.
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>
35 #include <net/ip.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 *,
69 struct net_device *);
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);
79 #endif
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),
112 {0,}
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
122 void
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
134 static inline void
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);
167 static int
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;
177 static void
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;
186 static int
187 netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
189 int ring;
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))
194 return -ENOMEM;
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);
202 return 0;
205 static void
206 netxen_napi_del(struct netxen_adapter *adapter)
208 int ring;
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);
220 static void
221 netxen_napi_enable(struct netxen_adapter *adapter)
223 int ring;
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);
234 static void
235 netxen_napi_disable(struct netxen_adapter *adapter)
237 int ring;
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)) {
260 #ifndef CONFIG_IA64
261 mask = DMA_BIT_MASK(35);
262 #endif
263 } else {
264 mask = DMA_BIT_MASK(39);
265 cmask = mask;
268 if (pci_set_dma_mask(pdev, mask) == 0 &&
269 pci_set_consistent_dma_mask(pdev, cmask) == 0) {
270 adapter->pci_using_dac = 1;
271 return 0;
274 return -EIO;
277 /* Update addressable range if firmware supports it */
278 static int
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;
285 change = 0;
287 shift = NXRD32(adapter, CRB_DMA_SHIFT);
288 if (shift > 32)
289 return 0;
291 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9))
292 change = 1;
293 else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4))
294 change = 1;
296 if (change) {
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);
303 if (err)
304 goto err_out;
306 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
308 err = pci_set_consistent_dma_mask(pdev, mask);
309 if (err)
310 goto err_out;
312 dev_info(&pdev->dev, "using %d-bit dma mask\n", 32+shift);
315 return 0;
317 err_out:
318 pci_set_dma_mask(pdev, old_mask);
319 pci_set_consistent_dma_mask(pdev, old_cmask);
320 return err;
323 static int
324 netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
326 u32 val, timeout;
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))
333 return 0;
335 /* PCI bus master workaround */
336 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
337 if (!(first_boot & 0x4)) {
338 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);
348 return -EIO;
351 /* Start P2 boot loader */
352 val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
353 NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
354 timeout = 0;
355 do {
356 msleep(1);
357 val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
359 if (++timeout > 5000)
360 return -EIO;
362 } while (val == NETXEN_BDINFO_MAGIC);
364 return 0;
367 static void netxen_set_port_mode(struct netxen_adapter *adapter)
369 u32 val, data;
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);
386 } else {
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)
403 u32 control;
404 int pos;
406 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
407 if (pos) {
408 pci_read_config_dword(pdev, pos, &control);
409 if (enable)
410 control |= PCI_MSIX_FLAGS_ENABLE;
411 else
412 control = 0;
413 pci_write_config_dword(pdev, pos, control);
417 static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count)
419 int i;
421 for (i = 0; i < count; i++)
422 adapter->msix_entries[i].entry = i;
425 static int
426 netxen_read_mac_addr(struct netxen_adapter *adapter)
428 int i;
429 unsigned char *p;
430 u64 mac_addr;
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)
436 return -EIO;
437 } else {
438 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
439 return -EIO;
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);
454 return 0;
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))
463 return -EINVAL;
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);
478 return 0;
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,
500 #endif
503 static void
504 netxen_setup_intr(struct netxen_adapter *adapter)
506 struct netxen_legacy_intr_set *legacy_intrp;
507 struct pci_dev *pdev = adapter->pdev;
508 int err, num_msix;
510 if (adapter->rss_supported) {
511 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
512 MSIX_ENTRIES_PER_ADAPTER : 2;
513 } else
514 num_msix = 1;
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];
522 else
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,
536 ISR_INT_STATE_REG);
537 else
538 adapter->crb_int_state_reg = netxen_get_ioaddr(adapter,
539 CRB_INT_VECTOR);
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);
547 if (err == 0) {
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");
555 return;
558 if (err > 0)
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;
570 return;
573 dev_info(&pdev->dev, "using legacy interrupts\n");
574 adapter->msix_entries[0].vector = pdev->irq;
577 static void
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);
586 static void
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);
599 static int
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;
611 int err = 0;
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");
635 err = -EIO;
636 goto err_out;
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");
648 err = -EIO;
649 goto err_out;
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");
657 return -EIO;
659 ahw->pci_len0 = mem_len;
660 } else {
661 return -EIO;
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))
678 goto skip_doorbell;
680 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
681 db_len = pci_resource_len(pdev, 4);
683 if (db_len == 0) {
684 printk(KERN_ERR "%s: doorbell is disabled\n",
685 netxen_nic_driver_name);
686 err = -EIO;
687 goto err_out;
690 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
691 if (!db_ptr) {
692 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
693 netxen_nic_driver_name);
694 err = -EIO;
695 goto err_out;
698 skip_doorbell:
699 adapter->ahw.db_base = db_ptr;
700 adapter->ahw.db_len = db_len;
701 return 0;
703 err_out:
704 netxen_cleanup_pci_map(adapter);
705 return err;
708 static void
709 netxen_check_options(struct netxen_adapter *adapter)
711 u32 fw_major, fw_minor, fw_build;
712 char brd_name[NETXEN_MAX_SHORT_NAME];
713 char serial_num[32];
714 int i, offset, val;
715 int *ptr32;
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;
726 return;
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);
750 return;
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;
777 } else {
778 u32 flashed_ver = 0;
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;
789 break;
790 default:
791 break;
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;
801 } else {
802 adapter->num_lro_rxd = 0;
803 adapter->max_rds_rings = 2;
807 static int
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);
815 if (err)
816 return err;
818 if (!netxen_can_start_firmware(adapter))
819 goto wait_init;
821 first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
823 err = netxen_check_hw_init(adapter, first_boot);
824 if (err) {
825 dev_err(&pdev->dev, "error in init HW init sequence\n");
826 return err;
829 netxen_request_firmware(adapter);
831 err = netxen_need_fw_reset(adapter);
832 if (err < 0)
833 goto err_out;
834 if (err == 0)
835 goto wait_init;
837 if (first_boot != 0x55555555) {
838 NXWR32(adapter, CRB_CMDPEG_STATE, 0);
839 netxen_pinit_from_rom(adapter);
840 msleep(1);
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);
851 if (err)
852 goto err_out;
854 netxen_release_firmware(adapter);
856 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
858 /* Initialize multicast addr pool owners */
859 val = 0x7654;
860 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
861 val |= 0x0f000000;
862 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
866 err = netxen_init_dummy_dma(adapter);
867 if (err)
868 goto err_out;
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);
878 wait_init:
879 /* Handshake with the card before we register the devices. */
880 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
881 if (err) {
882 netxen_free_dummy_dma(adapter);
883 goto err_out;
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 */
896 err_out:
897 netxen_release_firmware(adapter);
898 return err;
901 static int
902 netxen_nic_request_irq(struct netxen_adapter *adapter)
904 irq_handler_t handler;
905 struct nx_host_sds_ring *sds_ring;
906 int err, 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;
916 else {
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);
927 if (err)
928 return err;
931 return 0;
934 static void
935 netxen_nic_free_irq(struct netxen_adapter *adapter)
937 int ring;
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);
948 static void
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;
962 /* with rtnl_lock */
963 static int
964 __netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
966 int err;
968 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
969 return -EIO;
971 err = adapter->init_port(adapter, adapter->physical_port);
972 if (err) {
973 printk(KERN_ERR "%s: Failed to initialize port %d\n",
974 netxen_nic_driver_name, adapter->portnum);
975 return err;
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);
998 else
999 netxen_nic_set_link_parameters(adapter);
1001 set_bit(__NX_DEV_UP, &adapter->state);
1002 return 0;
1005 /* Usage: During resume and firmware recovery module.*/
1007 static inline int
1008 netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
1010 int err = 0;
1012 rtnl_lock();
1013 if (netif_running(netdev))
1014 err = __netxen_nic_up(adapter, netdev);
1015 rtnl_unlock();
1017 return err;
1020 /* with rtnl_lock */
1021 static void
1022 __netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
1024 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1025 return;
1027 if (!test_and_clear_bit(__NX_DEV_UP, &adapter->state))
1028 return;
1030 smp_mb();
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 */
1051 static inline void
1052 netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
1054 rtnl_lock();
1055 if (netif_running(netdev))
1056 __netxen_nic_down(adapter, netdev);
1057 rtnl_unlock();
1061 static int
1062 netxen_nic_attach(struct netxen_adapter *adapter)
1064 struct net_device *netdev = adapter->netdev;
1065 struct pci_dev *pdev = adapter->pdev;
1066 int err, ring;
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)
1071 return 0;
1073 err = netxen_init_firmware(adapter);
1074 if (err)
1075 return err;
1077 err = netxen_napi_add(adapter, netdev);
1078 if (err)
1079 return err;
1081 err = netxen_alloc_sw_resources(adapter);
1082 if (err) {
1083 printk(KERN_ERR "%s: Error in setting sw resources\n",
1084 netdev->name);
1085 return err;
1088 err = netxen_alloc_hw_resources(adapter);
1089 if (err) {
1090 printk(KERN_ERR "%s: Error in setting hw resources\n",
1091 netdev->name);
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);
1115 if (err) {
1116 dev_err(&pdev->dev, "%s: failed to setup interrupt\n",
1117 netdev->name);
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;
1127 return 0;
1129 err_out_free_rxbuf:
1130 netxen_release_rx_buffers(adapter);
1131 netxen_free_hw_resources(adapter);
1132 err_out_free_sw:
1133 netxen_free_sw_resources(adapter);
1134 return err;
1137 static void
1138 netxen_nic_detach(struct netxen_adapter *adapter)
1140 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1141 return;
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);
1151 adapter->is_up = 0;
1155 netxen_nic_reset_context(struct netxen_adapter *adapter)
1157 int err = 0;
1158 struct net_device *netdev = adapter->netdev;
1160 if (test_and_set_bit(__NX_RESETTING, &adapter->state))
1161 return -EBUSY;
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);
1174 if (!err)
1175 err = __netxen_nic_up(adapter, netdev);
1177 if (err)
1178 goto done;
1181 netif_device_attach(netdev);
1184 done:
1185 clear_bit(__NX_RESETTING, &adapter->state);
1186 return err;
1189 static int
1190 netxen_setup_netdev(struct netxen_adapter *adapter,
1191 struct net_device *netdev)
1193 int err = 0;
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;
1200 else
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);
1240 if (err) {
1241 dev_err(&pdev->dev, "failed to register net device\n");
1242 return err;
1245 return 0;
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;
1253 u32 aer_pos;
1255 if (adapter->ahw.board_type != NETXEN_BRDTYPE_P3_4_GB_MM &&
1256 adapter->ahw.board_type != NETXEN_BRDTYPE_P3_10G_TP)
1257 return;
1259 if (root->pcie_type != PCI_EXP_TYPE_ROOT_PORT)
1260 return;
1262 aer_pos = pci_find_ext_capability(root, PCI_EXT_CAP_ID_ERR);
1263 if (!aer_pos)
1264 return;
1266 pci_write_config_dword(root, aer_pos + PCI_ERR_COR_MASK, 0xffff);
1268 #endif
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;
1275 int i = 0, err;
1276 int pci_func_id = PCI_FUNC(pdev->devfn);
1277 uint8_t revision_id;
1278 u32 val;
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);
1284 return -ENODEV;
1287 if ((err = pci_enable_device(pdev)))
1288 return err;
1290 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1291 err = -ENODEV;
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));
1304 if(!netdev) {
1305 dev_err(&pdev->dev, "failed to allocate net_device\n");
1306 err = -ENOMEM;
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);
1327 if (err)
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);
1334 if (err) {
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);
1341 #endif
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;
1349 break;
1350 default:
1351 break;
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);
1363 if (err)
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);
1381 if (err)
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);
1392 break;
1393 case NETXEN_NIC_XGBE:
1394 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1395 adapter->netdev->name);
1396 break;
1399 netxen_create_diag_entries(adapter);
1401 return 0;
1403 err_out_disable_msi:
1404 netxen_teardown_intr(adapter);
1406 netxen_free_dummy_dma(adapter);
1408 err_out_decr_ref:
1409 nx_decr_dev_ref_cnt(adapter);
1411 err_out_iounmap:
1412 netxen_cleanup_pci_map(adapter);
1414 err_out_free_netdev:
1415 free_netdev(netdev);
1417 err_out_free_res:
1418 pci_release_regions(pdev);
1420 err_out_disable_pdev:
1421 pci_set_drvdata(pdev, NULL);
1422 pci_disable_device(pdev);
1423 return err;
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)
1433 return;
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;
1497 int err;
1499 err = pci_enable_device(pdev);
1500 if (err)
1501 return err;
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);
1511 if (err) {
1512 dev_err(&pdev->dev, "failed to start firmware\n");
1513 return err;
1516 if (netif_running(netdev)) {
1517 err = netxen_nic_attach(adapter);
1518 if (err)
1519 goto err_out;
1521 err = netxen_nic_up(adapter, netdev);
1522 if (err)
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);
1530 return 0;
1532 err_out_detach:
1533 netxen_nic_detach(adapter);
1534 err_out:
1535 nx_decr_dev_ref_cnt(adapter);
1536 return err;
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)
1559 int err = 0;
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))
1578 return;
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);
1588 #ifdef CONFIG_PM
1589 static int
1590 netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
1592 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1593 int retval;
1595 netxen_nic_detach_func(adapter);
1597 retval = pci_save_state(pdev);
1598 if (retval)
1599 return retval;
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));
1609 return 0;
1612 static int
1613 netxen_nic_resume(struct pci_dev *pdev)
1615 return netxen_nic_attach_func(pdev);
1617 #endif
1619 static int netxen_nic_open(struct net_device *netdev)
1621 struct netxen_adapter *adapter = netdev_priv(netdev);
1622 int err = 0;
1624 if (adapter->driver_mismatch)
1625 return -EIO;
1627 err = netxen_nic_attach(adapter);
1628 if (err)
1629 return err;
1631 err = __netxen_nic_up(adapter, netdev);
1632 if (err)
1633 goto err_out;
1635 netif_start_queue(netdev);
1637 return 0;
1639 err_out:
1640 netxen_nic_detach(adapter);
1641 return err;
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);
1652 return 0;
1655 static void
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;
1664 u32 producer;
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);
1680 vlan_oob = 1;
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;
1690 if (vlan_oob) {
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;
1700 tso = 1;
1702 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
1703 u8 l4proto;
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);
1726 if (!tso)
1727 return;
1729 /* For LSO, we need to copy the MAC/IP/TCP headers into
1730 * the descriptor ring
1732 producer = tx_ring->producer;
1733 copied = 0;
1734 offset = 2;
1736 if (vlan_oob) {
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;
1753 offset = 0;
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);
1769 copied += copy_len;
1770 offset = 0;
1772 producer = get_next_index(producer, tx_ring->num_desc);
1775 tx_ring->producer = producer;
1776 barrier();
1779 static int
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;
1785 int i, nr_frags;
1786 dma_addr_t map;
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))
1794 goto out_err;
1796 nf->dma = 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))
1806 goto unwind;
1808 nf->dma = map;
1809 nf->length = frag->size;
1812 return 0;
1814 unwind:
1815 while (--i >= 0) {
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);
1823 out_err:
1824 return -ENOMEM;
1827 static inline void
1828 netxen_clear_cmddesc(u64 *desc)
1830 desc[0] = 0ULL;
1831 desc[2] = 0ULL;
1834 static netdev_tx_t
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;
1843 int i, k;
1845 u32 producer;
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);
1856 smp_mb();
1857 if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH)
1858 netif_start_queue(netdev);
1859 else
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))
1869 goto drop_packet;
1871 pbuf->skb = skb;
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++) {
1882 k = i % 4;
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);
1895 switch (k) {
1896 case 0:
1897 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
1898 break;
1899 case 1:
1900 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
1901 break;
1902 case 2:
1903 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
1904 break;
1905 case 3:
1906 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
1907 break;
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;
1922 drop_packet:
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;
1932 int rv = 0;
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) {
1940 printk(KERN_ALERT
1941 "%s: Device temperature %d degrees C exceeds"
1942 " maximum allowed. Hardware has been shut down.\n",
1943 netdev->name, temp_val);
1944 rv = 1;
1945 } else if (temp_state == NX_TEMP_WARN) {
1946 if (adapter->temp == NX_TEMP_NORMAL) {
1947 printk(KERN_ALERT
1948 "%s: Device temperature %d degrees C "
1949 "exceeds operating range."
1950 " Immediate action needed.\n",
1951 netdev->name, temp_val);
1953 } else {
1954 if (adapter->temp == NX_TEMP_WARN) {
1955 printk(KERN_INFO
1956 "%s: Device temperature is now %d degrees C"
1957 " in normal range.\n", netdev->name,
1958 temp_val);
1961 adapter->temp = temp_state;
1962 return rv;
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);
2000 } else {
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))
2014 return;
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))
2026 return;
2028 if (test_and_set_bit(__NX_RESETTING, &adapter->state))
2029 return;
2031 if (++adapter->tx_timeo_cnt >= NX_MAX_TX_TIMEOUTS)
2032 goto request_reset;
2034 rtnl_lock();
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);
2044 } else {
2045 clear_bit(__NX_RESETTING, &adapter->state);
2046 if (netxen_nic_reset_context(adapter)) {
2047 rtnl_unlock();
2048 goto request_reset;
2051 adapter->netdev->trans_start = jiffies;
2052 rtnl_unlock();
2053 return;
2055 request_reset:
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;
2072 return stats;
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;
2079 u32 status = 0;
2081 status = readl(adapter->isr_int_vec);
2083 if (!(status & adapter->int_vec_bit))
2084 return IRQ_NONE;
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))
2090 return IRQ_NONE;
2092 } else {
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))
2099 return IRQ_NONE;
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);
2115 return IRQ_HANDLED;
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);
2127 return IRQ_HANDLED;
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);
2135 return IRQ_HANDLED;
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;
2145 int tx_complete;
2146 int work_done;
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);
2158 return work_done;
2161 #ifdef CONFIG_NET_POLL_CONTROLLER
2162 static void netxen_nic_poll_controller(struct net_device *netdev)
2164 int ring;
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);
2176 #endif
2178 static int
2179 nx_incr_dev_ref_cnt(struct netxen_adapter *adapter)
2181 int count;
2182 if (netxen_api_lock(adapter))
2183 return -EIO;
2185 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2187 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2189 netxen_api_unlock(adapter);
2190 return count;
2193 static int
2194 nx_decr_dev_ref_cnt(struct netxen_adapter *adapter)
2196 int count;
2197 if (netxen_api_lock(adapter))
2198 return -EIO;
2200 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2201 WARN_ON(count == 0);
2203 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, --count);
2205 if (count == 0)
2206 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_COLD);
2208 netxen_api_unlock(adapter);
2209 return count;
2212 static int
2213 nx_dev_request_aer(struct netxen_adapter *adapter)
2215 u32 state;
2216 int ret = -EINVAL;
2218 if (netxen_api_lock(adapter))
2219 return ret;
2221 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2223 if (state == NX_DEV_NEED_AER)
2224 ret = 0;
2225 else if (state == NX_DEV_READY) {
2226 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_AER);
2227 ret = 0;
2230 netxen_api_unlock(adapter);
2231 return ret;
2234 static int
2235 nx_dev_request_reset(struct netxen_adapter *adapter)
2237 u32 state;
2238 int ret = -EINVAL;
2240 if (netxen_api_lock(adapter))
2241 return ret;
2243 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2245 if (state == NX_DEV_NEED_RESET)
2246 ret = 0;
2247 else if (state != NX_DEV_INITALIZING && state != NX_DEV_NEED_AER) {
2248 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_RESET);
2249 ret = 0;
2252 netxen_api_unlock(adapter);
2254 return ret;
2257 static int
2258 netxen_can_start_firmware(struct netxen_adapter *adapter)
2260 int count;
2261 int can_start = 0;
2263 if (netxen_api_lock(adapter))
2264 return 0;
2266 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2268 if ((count < 0) || (count >= NX_MAX_PCI_FUNC))
2269 count = 0;
2271 if (count == 0) {
2272 can_start = 1;
2273 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_INITALIZING);
2276 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2278 netxen_api_unlock(adapter);
2280 return can_start;
2283 static void
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);
2291 static void
2292 netxen_cancel_fw_work(struct netxen_adapter *adapter)
2294 while (test_and_set_bit(__NX_RESETTING, &adapter->state))
2295 msleep(10);
2297 cancel_delayed_work_sync(&adapter->fw_work);
2300 static void
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;
2306 int err = 0;
2308 if (netif_running(netdev)) {
2309 err = netxen_nic_attach(adapter);
2310 if (err)
2311 goto done;
2313 err = netxen_nic_up(adapter, netdev);
2314 if (err) {
2315 netxen_nic_detach(adapter);
2316 goto done;
2319 netxen_config_indev_addr(netdev, NETDEV_UP);
2322 netif_device_attach(netdev);
2324 done:
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);
2330 static void
2331 netxen_fwinit_work(struct work_struct *work)
2333 struct netxen_adapter *adapter = container_of(work,
2334 struct netxen_adapter, fw_work.work);
2335 int dev_state;
2337 dev_state = NXRD32(adapter, NX_CRB_DEV_STATE);
2339 switch (dev_state) {
2340 case NX_DEV_COLD:
2341 case NX_DEV_READY:
2342 if (!netxen_start_firmware(adapter)) {
2343 netxen_schedule_work(adapter, netxen_attach_work, 0);
2344 return;
2346 break;
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);
2353 return;
2356 case NX_DEV_FAILED:
2357 default:
2358 nx_incr_dev_ref_cnt(adapter);
2359 break;
2362 clear_bit(__NX_RESETTING, &adapter->state);
2365 static void
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;
2371 int ref_cnt, delay;
2372 u32 status;
2374 netif_device_detach(netdev);
2376 netxen_nic_down(adapter, netdev);
2378 rtnl_lock();
2379 netxen_nic_detach(adapter);
2380 rtnl_unlock();
2382 status = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1);
2384 if (status & NX_RCODE_FATAL_ERROR)
2385 goto err_ret;
2387 if (adapter->temp == NX_TEMP_PANIC)
2388 goto err_ret;
2390 ref_cnt = nx_decr_dev_ref_cnt(adapter);
2392 if (ref_cnt == -EIO)
2393 goto err_ret;
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);
2400 return;
2402 err_ret:
2403 clear_bit(__NX_RESETTING, &adapter->state);
2406 static int
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)
2414 return 0;
2416 if (netxen_nic_check_temp(adapter))
2417 goto detach;
2419 if (adapter->need_fw_reset) {
2420 if (nx_dev_request_reset(adapter))
2421 return 0;
2422 goto detach;
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))
2433 goto detach;
2436 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2437 return 0;
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)
2444 goto detach;
2445 return 0;
2448 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2449 return 0;
2451 if (nx_dev_request_reset(adapter))
2452 return 0;
2454 clear_bit(__NX_FW_ATTACHED, &adapter->state);
2456 dev_info(&netdev->dev, "firmware hang detected\n");
2458 detach:
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);
2462 return 1;
2465 static void
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))
2472 goto reschedule;
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))
2485 return;
2487 reschedule:
2488 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
2491 static ssize_t
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);
2497 unsigned long new;
2498 int ret = -EINVAL;
2500 if (!(adapter->capabilities & NX_FW_CAPABILITY_BDG))
2501 goto err_out;
2503 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2504 goto err_out;
2506 if (strict_strtoul(buf, 2, &new))
2507 goto err_out;
2509 if (!netxen_config_bridged_mode(adapter, !!new))
2510 ret = len;
2512 err_out:
2513 return ret;
2516 static ssize_t
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,
2538 static ssize_t
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);
2543 unsigned long new;
2545 if (strict_strtoul(buf, 2, &new))
2546 return -EINVAL;
2548 if (!!new != !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2549 adapter->flags ^= NETXEN_NIC_DIAG_ENABLED;
2551 return len;
2554 static ssize_t
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,
2570 static int
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))
2577 return -EIO;
2579 if (offset < NETXEN_PCI_CRBSPACE) {
2580 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2581 return -EINVAL;
2583 if (ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM,
2584 NETXEN_PCI_CAMQM_2M_END))
2585 crb_size = 8;
2586 else
2587 return -EINVAL;
2590 if ((size != crb_size) || (offset & (crb_size-1)))
2591 return -EINVAL;
2593 return 0;
2596 static ssize_t
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);
2603 u32 data;
2604 u64 qmdata;
2605 int ret;
2607 ret = netxen_sysfs_validate_crb(adapter, offset, size);
2608 if (ret != 0)
2609 return ret;
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);
2616 } else {
2617 data = NXRD32(adapter, offset);
2618 memcpy(buf, &data, size);
2621 return size;
2624 static ssize_t
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);
2631 u32 data;
2632 u64 qmdata;
2633 int ret;
2635 ret = netxen_sysfs_validate_crb(adapter, offset, size);
2636 if (ret != 0)
2637 return ret;
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);
2644 } else {
2645 memcpy(&data, buf, size);
2646 NXWR32(adapter, offset, data);
2649 return size;
2652 static int
2653 netxen_sysfs_validate_mem(struct netxen_adapter *adapter,
2654 loff_t offset, size_t size)
2656 if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2657 return -EIO;
2659 if ((size != 8) || (offset & 0x7))
2660 return -EIO;
2662 return 0;
2665 static ssize_t
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);
2672 u64 data;
2673 int ret;
2675 ret = netxen_sysfs_validate_mem(adapter, offset, size);
2676 if (ret != 0)
2677 return ret;
2679 if (adapter->pci_mem_read(adapter, offset, &data))
2680 return -EIO;
2682 memcpy(buf, &data, size);
2684 return 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);
2693 u64 data;
2694 int ret;
2696 ret = netxen_sysfs_validate_mem(adapter, offset, size);
2697 if (ret != 0)
2698 return ret;
2700 memcpy(&data, buf, size);
2702 if (adapter->pci_mem_write(adapter, offset, data))
2703 return -EIO;
2705 return size;
2709 static struct bin_attribute bin_attr_crb = {
2710 .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)},
2711 .size = 0,
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)},
2718 .size = 0,
2719 .read = netxen_sysfs_read_mem,
2720 .write = netxen_sysfs_write_mem,
2724 static void
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");
2739 static void
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);
2749 static void
2750 netxen_create_diag_entries(struct netxen_adapter *adapter)
2752 struct pci_dev *pdev = adapter->pdev;
2753 struct device *dev;
2755 dev = &pdev->dev;
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");
2765 static void
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);
2776 #ifdef CONFIG_INET
2778 #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2780 static int
2781 netxen_destip_supported(struct netxen_adapter *adapter)
2783 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2784 return 0;
2786 if (adapter->ahw.cut_through)
2787 return 0;
2789 return 1;
2792 static void
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))
2799 return;
2801 indev = in_dev_get(dev);
2802 if (!indev)
2803 return;
2805 for_ifa(indev) {
2806 switch (event) {
2807 case NETDEV_UP:
2808 netxen_config_ipaddr(adapter,
2809 ifa->ifa_address, NX_IP_UP);
2810 break;
2811 case NETDEV_DOWN:
2812 netxen_config_ipaddr(adapter,
2813 ifa->ifa_address, NX_IP_DOWN);
2814 break;
2815 default:
2816 break;
2818 } endfor_ifa(indev);
2820 in_dev_put(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;
2829 recheck:
2830 if (dev == NULL)
2831 goto done;
2833 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2834 dev = vlan_dev_real_dev(dev);
2835 goto recheck;
2838 if (!is_netxen_netdev(dev))
2839 goto done;
2841 adapter = netdev_priv(dev);
2843 if (!adapter)
2844 goto done;
2846 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2847 goto done;
2849 netxen_config_indev_addr(dev, event);
2850 done:
2851 return NOTIFY_DONE;
2854 static int
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;
2865 recheck:
2866 if (dev == NULL || !netif_running(dev))
2867 goto done;
2869 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2870 dev = vlan_dev_real_dev(dev);
2871 goto recheck;
2874 if (!is_netxen_netdev(dev))
2875 goto done;
2877 adapter = netdev_priv(dev);
2879 if (!adapter || !netxen_destip_supported(adapter))
2880 goto done;
2882 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2883 goto done;
2885 switch (event) {
2886 case NETDEV_UP:
2887 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP);
2888 break;
2889 case NETDEV_DOWN:
2890 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN);
2891 break;
2892 default:
2893 break;
2896 done:
2897 return NOTIFY_DONE;
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,
2907 #else
2908 static void
2909 netxen_config_indev_addr(struct net_device *dev, unsigned long event)
2911 #endif
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),
2924 #ifdef CONFIG_PM
2925 .suspend = netxen_nic_suspend,
2926 .resume = netxen_nic_resume,
2927 #endif
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);
2936 #ifdef CONFIG_INET
2937 register_netdevice_notifier(&netxen_netdev_cb);
2938 register_inetaddr_notifier(&netxen_inetaddr_cb);
2939 #endif
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);
2949 #ifdef CONFIG_INET
2950 unregister_inetaddr_notifier(&netxen_inetaddr_cb);
2951 unregister_netdevice_notifier(&netxen_netdev_cb);
2952 #endif
2955 module_exit(netxen_exit_module);