2 * Copyright (C) 2003 - 2009 NetXen, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
23 * Contact Information:
27 * Cupertino, CA 95014-0701
31 #include <linux/vmalloc.h>
32 #include <linux/interrupt.h>
33 #include "netxen_nic_hw.h"
35 #include "netxen_nic.h"
37 #include <linux/dma-mapping.h>
38 #include <linux/if_vlan.h>
40 #include <linux/ipv6.h>
41 #include <linux/inetdevice.h>
43 MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
44 MODULE_LICENSE("GPL");
45 MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
47 char netxen_nic_driver_name[] = "netxen_nic";
48 static char netxen_nic_driver_string[] = "NetXen Network Driver version "
49 NETXEN_NIC_LINUX_VERSIONID;
51 static int port_mode = NETXEN_PORT_MODE_AUTO_NEG;
53 /* Default to restricted 1G auto-neg mode */
54 static int wol_port_mode = 5;
56 static int use_msi = 1;
58 static int use_msi_x = 1;
60 /* Local functions to NetXen NIC driver */
61 static int __devinit netxen_nic_probe(struct pci_dev *pdev,
62 const struct pci_device_id *ent);
63 static void __devexit netxen_nic_remove(struct pci_dev *pdev);
64 static int netxen_nic_open(struct net_device *netdev);
65 static int netxen_nic_close(struct net_device *netdev);
66 static netdev_tx_t netxen_nic_xmit_frame(struct sk_buff *,
68 static void netxen_tx_timeout(struct net_device *netdev);
69 static void netxen_reset_task(struct work_struct *work);
70 static void netxen_fw_poll_work(struct work_struct *work);
71 static void netxen_schedule_work(struct netxen_adapter *adapter,
72 work_func_t func, int delay);
73 static void netxen_cancel_fw_work(struct netxen_adapter *adapter);
74 static int netxen_nic_poll(struct napi_struct *napi, int budget);
75 #ifdef CONFIG_NET_POLL_CONTROLLER
76 static void netxen_nic_poll_controller(struct net_device *netdev);
79 static void netxen_create_sysfs_entries(struct netxen_adapter *adapter);
80 static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter);
82 static int nx_decr_dev_ref_cnt(struct netxen_adapter *adapter);
83 static int netxen_can_start_firmware(struct netxen_adapter *adapter);
85 static irqreturn_t netxen_intr(int irq, void *data);
86 static irqreturn_t netxen_msi_intr(int irq, void *data);
87 static irqreturn_t netxen_msix_intr(int irq, void *data);
89 static void netxen_config_indev_addr(struct net_device *dev, unsigned long);
91 /* PCI Device ID Table */
92 #define ENTRY(device) \
93 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
94 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
96 static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
97 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR),
98 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4),
99 ENTRY(PCI_DEVICE_ID_NX2031_4GCU),
100 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ),
101 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ),
102 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT),
103 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2),
104 ENTRY(PCI_DEVICE_ID_NX3031),
108 MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
110 static uint32_t crb_cmd_producer[4] = {
111 CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1,
112 CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3
116 netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
117 struct nx_host_tx_ring *tx_ring)
119 NXWRIO(adapter, tx_ring->crb_cmd_producer, tx_ring->producer);
121 if (netxen_tx_avail(tx_ring) <= TX_STOP_THRESH) {
122 netif_stop_queue(adapter->netdev);
127 static uint32_t crb_cmd_consumer[4] = {
128 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
129 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
133 netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
134 struct nx_host_tx_ring *tx_ring)
136 NXWRIO(adapter, tx_ring->crb_cmd_consumer, tx_ring->sw_consumer);
139 static uint32_t msi_tgt_status[8] = {
140 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
141 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
142 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
143 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
146 static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
148 static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring)
150 struct netxen_adapter *adapter = sds_ring->adapter;
152 NXWRIO(adapter, sds_ring->crb_intr_mask, 0);
155 static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring)
157 struct netxen_adapter *adapter = sds_ring->adapter;
159 NXWRIO(adapter, sds_ring->crb_intr_mask, 0x1);
161 if (!NETXEN_IS_MSI_FAMILY(adapter))
162 NXWRIO(adapter, adapter->tgt_mask_reg, 0xfbff);
166 netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count)
168 int size = sizeof(struct nx_host_sds_ring) * count;
170 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
172 return (recv_ctx->sds_rings == NULL);
176 netxen_free_sds_rings(struct netxen_recv_context *recv_ctx)
178 if (recv_ctx->sds_rings != NULL)
179 kfree(recv_ctx->sds_rings);
181 recv_ctx->sds_rings = NULL;
185 netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
188 struct nx_host_sds_ring *sds_ring;
189 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
191 if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
194 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
195 sds_ring = &recv_ctx->sds_rings[ring];
196 netif_napi_add(netdev, &sds_ring->napi,
197 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
204 netxen_napi_del(struct netxen_adapter *adapter)
207 struct nx_host_sds_ring *sds_ring;
208 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
210 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
211 sds_ring = &recv_ctx->sds_rings[ring];
212 netif_napi_del(&sds_ring->napi);
215 netxen_free_sds_rings(&adapter->recv_ctx);
219 netxen_napi_enable(struct netxen_adapter *adapter)
222 struct nx_host_sds_ring *sds_ring;
223 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
225 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
226 sds_ring = &recv_ctx->sds_rings[ring];
227 napi_enable(&sds_ring->napi);
228 netxen_nic_enable_int(sds_ring);
233 netxen_napi_disable(struct netxen_adapter *adapter)
236 struct nx_host_sds_ring *sds_ring;
237 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
239 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
240 sds_ring = &recv_ctx->sds_rings[ring];
241 netxen_nic_disable_int(sds_ring);
242 napi_synchronize(&sds_ring->napi);
243 napi_disable(&sds_ring->napi);
247 static int nx_set_dma_mask(struct netxen_adapter *adapter)
249 struct pci_dev *pdev = adapter->pdev;
250 uint64_t mask, cmask;
252 adapter->pci_using_dac = 0;
254 mask = DMA_BIT_MASK(32);
255 cmask = DMA_BIT_MASK(32);
257 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
259 mask = DMA_BIT_MASK(35);
262 mask = DMA_BIT_MASK(39);
266 if (pci_set_dma_mask(pdev, mask) == 0 &&
267 pci_set_consistent_dma_mask(pdev, cmask) == 0) {
268 adapter->pci_using_dac = 1;
275 /* Update addressable range if firmware supports it */
277 nx_update_dma_mask(struct netxen_adapter *adapter)
279 int change, shift, err;
280 uint64_t mask, old_mask, old_cmask;
281 struct pci_dev *pdev = adapter->pdev;
285 shift = NXRD32(adapter, CRB_DMA_SHIFT);
289 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9))
291 else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4))
295 old_mask = pdev->dma_mask;
296 old_cmask = pdev->dev.coherent_dma_mask;
298 mask = DMA_BIT_MASK(32+shift);
300 err = pci_set_dma_mask(pdev, mask);
304 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
306 err = pci_set_consistent_dma_mask(pdev, mask);
310 dev_info(&pdev->dev, "using %d-bit dma mask\n", 32+shift);
316 pci_set_dma_mask(pdev, old_mask);
317 pci_set_consistent_dma_mask(pdev, old_cmask);
322 netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
326 if (first_boot == 0x55555555) {
327 /* This is the first boot after power up */
328 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
330 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
333 /* PCI bus master workaround */
334 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
335 if (!(first_boot & 0x4)) {
337 NXWR32(adapter, NETXEN_PCIE_REG(0x4), first_boot);
338 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
341 /* This is the first boot after power up */
342 first_boot = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET);
343 if (first_boot != 0x80000f) {
344 /* clear the register for future unloads/loads */
345 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), 0);
349 /* Start P2 boot loader */
350 val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
351 NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
355 val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
357 if (++timeout > 5000)
360 } while (val == NETXEN_BDINFO_MAGIC);
365 static void netxen_set_port_mode(struct netxen_adapter *adapter)
369 val = adapter->ahw.board_type;
370 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
371 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
372 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
373 data = NETXEN_PORT_MODE_802_3_AP;
374 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
375 } else if (port_mode == NETXEN_PORT_MODE_XG) {
376 data = NETXEN_PORT_MODE_XG;
377 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
378 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
379 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
380 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
381 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
382 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
383 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
385 data = NETXEN_PORT_MODE_AUTO_NEG;
386 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
389 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
390 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
391 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
392 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
393 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
395 NXWR32(adapter, NETXEN_WOL_PORT_MODE, wol_port_mode);
399 static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
404 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
406 pci_read_config_dword(pdev, pos, &control);
408 control |= PCI_MSIX_FLAGS_ENABLE;
411 pci_write_config_dword(pdev, pos, control);
415 static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count)
419 for (i = 0; i < count; i++)
420 adapter->msix_entries[i].entry = i;
424 netxen_read_mac_addr(struct netxen_adapter *adapter)
429 struct net_device *netdev = adapter->netdev;
430 struct pci_dev *pdev = adapter->pdev;
432 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
433 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
436 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
440 p = (unsigned char *)&mac_addr;
441 for (i = 0; i < 6; i++)
442 netdev->dev_addr[i] = *(p + 5 - i);
444 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
446 /* set station address */
448 if (!is_valid_ether_addr(netdev->perm_addr))
449 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
454 int netxen_nic_set_mac(struct net_device *netdev, void *p)
456 struct netxen_adapter *adapter = netdev_priv(netdev);
457 struct sockaddr *addr = p;
459 if (!is_valid_ether_addr(addr->sa_data))
462 if (netif_running(netdev)) {
463 netif_device_detach(netdev);
464 netxen_napi_disable(adapter);
467 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
468 adapter->macaddr_set(adapter, addr->sa_data);
470 if (netif_running(netdev)) {
471 netif_device_attach(netdev);
472 netxen_napi_enable(adapter);
477 static void netxen_set_multicast_list(struct net_device *dev)
479 struct netxen_adapter *adapter = netdev_priv(dev);
481 adapter->set_multi(dev);
484 static const struct net_device_ops netxen_netdev_ops = {
485 .ndo_open = netxen_nic_open,
486 .ndo_stop = netxen_nic_close,
487 .ndo_start_xmit = netxen_nic_xmit_frame,
488 .ndo_get_stats = netxen_nic_get_stats,
489 .ndo_validate_addr = eth_validate_addr,
490 .ndo_set_multicast_list = netxen_set_multicast_list,
491 .ndo_set_mac_address = netxen_nic_set_mac,
492 .ndo_change_mtu = netxen_nic_change_mtu,
493 .ndo_tx_timeout = netxen_tx_timeout,
494 #ifdef CONFIG_NET_POLL_CONTROLLER
495 .ndo_poll_controller = netxen_nic_poll_controller,
500 netxen_setup_intr(struct netxen_adapter *adapter)
502 struct netxen_legacy_intr_set *legacy_intrp;
503 struct pci_dev *pdev = adapter->pdev;
506 if (adapter->rss_supported) {
507 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
508 MSIX_ENTRIES_PER_ADAPTER : 2;
512 adapter->max_sds_rings = 1;
514 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
516 if (adapter->ahw.revision_id >= NX_P3_B0)
517 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
519 legacy_intrp = &legacy_intr[0];
521 adapter->int_vec_bit = legacy_intrp->int_vec_bit;
522 adapter->tgt_status_reg = netxen_get_ioaddr(adapter,
523 legacy_intrp->tgt_status_reg);
524 adapter->tgt_mask_reg = netxen_get_ioaddr(adapter,
525 legacy_intrp->tgt_mask_reg);
526 adapter->pci_int_reg = netxen_get_ioaddr(adapter,
527 legacy_intrp->pci_int_reg);
528 adapter->isr_int_vec = netxen_get_ioaddr(adapter, ISR_INT_VECTOR);
530 if (adapter->ahw.revision_id >= NX_P3_B1)
531 adapter->crb_int_state_reg = netxen_get_ioaddr(adapter,
534 adapter->crb_int_state_reg = netxen_get_ioaddr(adapter,
537 netxen_set_msix_bit(pdev, 0);
539 if (adapter->msix_supported) {
541 netxen_init_msix_entries(adapter, num_msix);
542 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
544 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
545 netxen_set_msix_bit(pdev, 1);
547 if (adapter->rss_supported)
548 adapter->max_sds_rings = num_msix;
550 dev_info(&pdev->dev, "using msi-x interrupts\n");
555 pci_disable_msix(pdev);
557 /* fall through for msi */
560 if (use_msi && !pci_enable_msi(pdev)) {
561 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
562 adapter->tgt_status_reg = netxen_get_ioaddr(adapter,
563 msi_tgt_status[adapter->ahw.pci_func]);
564 dev_info(&pdev->dev, "using msi interrupts\n");
565 adapter->msix_entries[0].vector = pdev->irq;
569 dev_info(&pdev->dev, "using legacy interrupts\n");
570 adapter->msix_entries[0].vector = pdev->irq;
574 netxen_teardown_intr(struct netxen_adapter *adapter)
576 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
577 pci_disable_msix(adapter->pdev);
578 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
579 pci_disable_msi(adapter->pdev);
583 netxen_cleanup_pci_map(struct netxen_adapter *adapter)
585 if (adapter->ahw.db_base != NULL)
586 iounmap(adapter->ahw.db_base);
587 if (adapter->ahw.pci_base0 != NULL)
588 iounmap(adapter->ahw.pci_base0);
589 if (adapter->ahw.pci_base1 != NULL)
590 iounmap(adapter->ahw.pci_base1);
591 if (adapter->ahw.pci_base2 != NULL)
592 iounmap(adapter->ahw.pci_base2);
596 netxen_setup_pci_map(struct netxen_adapter *adapter)
598 void __iomem *mem_ptr0 = NULL;
599 void __iomem *mem_ptr1 = NULL;
600 void __iomem *mem_ptr2 = NULL;
601 void __iomem *db_ptr = NULL;
603 unsigned long mem_base, mem_len, db_base, db_len = 0, pci_len0 = 0;
605 struct pci_dev *pdev = adapter->pdev;
606 int pci_func = adapter->ahw.pci_func;
611 * Set the CRB window to invalid. If any register in window 0 is
612 * accessed it should set the window to 0 and then reset it to 1.
614 adapter->curr_window = 255;
615 adapter->ahw.qdr_sn_window = -1;
616 adapter->ahw.ddr_mn_window = -1;
618 /* remap phys address */
619 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
620 mem_len = pci_resource_len(pdev, 0);
623 /* 128 Meg of memory */
624 if (mem_len == NETXEN_PCI_128MB_SIZE) {
625 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
626 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
627 SECOND_PAGE_GROUP_SIZE);
628 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
629 THIRD_PAGE_GROUP_SIZE);
630 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
631 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
632 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
633 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
634 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
636 mem_ptr0 = pci_ioremap_bar(pdev, 0);
637 if (mem_ptr0 == NULL) {
638 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
643 adapter->ahw.ddr_mn_window = 0;
644 adapter->ahw.qdr_sn_window = 0;
646 adapter->ahw.mn_win_crb = 0x100000 + PCIX_MN_WINDOW +
648 adapter->ahw.ms_win_crb = 0x100000 + PCIX_SN_WINDOW;
650 adapter->ahw.ms_win_crb += (pci_func * 0x20);
652 adapter->ahw.ms_win_crb +=
653 0xA0 + ((pci_func - 4) * 0x10);
658 netxen_setup_hwops(adapter);
660 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
662 adapter->ahw.pci_base0 = mem_ptr0;
663 adapter->ahw.pci_len0 = pci_len0;
664 adapter->ahw.pci_base1 = mem_ptr1;
665 adapter->ahw.pci_base2 = mem_ptr2;
667 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
670 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
671 db_len = pci_resource_len(pdev, 4);
674 printk(KERN_ERR "%s: doorbell is disabled\n",
675 netxen_nic_driver_name);
680 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
682 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
683 netxen_nic_driver_name);
689 adapter->ahw.db_base = db_ptr;
690 adapter->ahw.db_len = db_len;
694 netxen_cleanup_pci_map(adapter);
699 netxen_check_options(struct netxen_adapter *adapter)
701 u32 fw_major, fw_minor, fw_build;
702 char brd_name[NETXEN_MAX_SHORT_NAME];
706 struct pci_dev *pdev = adapter->pdev;
708 adapter->driver_mismatch = 0;
710 ptr32 = (int *)&serial_num;
711 offset = NX_FW_SERIAL_NUM_OFFSET;
712 for (i = 0; i < 8; i++) {
713 if (netxen_rom_fast_read(adapter, offset, &val) == -1) {
714 dev_err(&pdev->dev, "error reading board info\n");
715 adapter->driver_mismatch = 1;
718 ptr32[i] = cpu_to_le32(val);
719 offset += sizeof(u32);
722 fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
723 fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
724 fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
726 adapter->fw_version = NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build);
728 if (adapter->portnum == 0) {
729 get_brd_name_by_type(adapter->ahw.board_type, brd_name);
731 printk(KERN_INFO "NetXen %s Board S/N %s Chip rev 0x%x\n",
732 brd_name, serial_num, adapter->ahw.revision_id);
735 if (adapter->fw_version < NETXEN_VERSION_CODE(3, 4, 216)) {
736 adapter->driver_mismatch = 1;
737 dev_warn(&pdev->dev, "firmware version %d.%d.%d unsupported\n",
738 fw_major, fw_minor, fw_build);
742 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
743 i = NXRD32(adapter, NETXEN_SRE_MISC);
744 adapter->ahw.cut_through = (i & 0x8000) ? 1 : 0;
747 dev_info(&pdev->dev, "firmware v%d.%d.%d [%s]\n",
748 fw_major, fw_minor, fw_build,
749 adapter->ahw.cut_through ? "cut-through" : "legacy");
751 if (adapter->fw_version >= NETXEN_VERSION_CODE(4, 0, 222))
752 adapter->capabilities = NXRD32(adapter, CRB_FW_CAPABILITIES_1);
754 adapter->flags &= ~NETXEN_NIC_LRO_ENABLED;
756 if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
757 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
758 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
759 } else if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
760 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
761 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
764 adapter->msix_supported = 0;
765 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
766 adapter->msix_supported = !!use_msi_x;
767 adapter->rss_supported = !!use_msi_x;
768 } else if (adapter->fw_version >= NETXEN_VERSION_CODE(3, 4, 336)) {
769 switch (adapter->ahw.board_type) {
770 case NETXEN_BRDTYPE_P2_SB31_10G:
771 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
772 adapter->msix_supported = !!use_msi_x;
773 adapter->rss_supported = !!use_msi_x;
780 adapter->num_txd = MAX_CMD_DESCRIPTORS;
782 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
783 adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS;
784 adapter->max_rds_rings = 3;
786 adapter->num_lro_rxd = 0;
787 adapter->max_rds_rings = 2;
792 netxen_start_firmware(struct netxen_adapter *adapter)
794 int val, err, first_boot;
795 struct pci_dev *pdev = adapter->pdev;
797 /* required for NX2031 dummy dma */
798 err = nx_set_dma_mask(adapter);
802 if (!netxen_can_start_firmware(adapter))
805 first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
807 err = netxen_check_hw_init(adapter, first_boot);
809 dev_err(&pdev->dev, "error in init HW init sequence\n");
813 netxen_request_firmware(adapter);
815 err = netxen_need_fw_reset(adapter);
821 if (first_boot != 0x55555555) {
822 NXWR32(adapter, CRB_CMDPEG_STATE, 0);
823 netxen_pinit_from_rom(adapter, 0);
827 NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555);
828 NXWR32(adapter, NETXEN_PEG_HALT_STATUS1, 0);
829 NXWR32(adapter, NETXEN_PEG_HALT_STATUS2, 0);
831 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
832 netxen_set_port_mode(adapter);
834 err = netxen_load_firmware(adapter);
838 netxen_release_firmware(adapter);
840 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
842 /* Initialize multicast addr pool owners */
844 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
846 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
850 err = netxen_init_dummy_dma(adapter);
855 * Tell the hardware our version number.
857 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
858 | ((_NETXEN_NIC_LINUX_MINOR << 8))
859 | (_NETXEN_NIC_LINUX_SUBVERSION);
860 NXWR32(adapter, CRB_DRIVER_VERSION, val);
862 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_READY);
865 /* Handshake with the card before we register the devices. */
866 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
868 netxen_free_dummy_dma(adapter);
872 nx_update_dma_mask(adapter);
874 netxen_check_options(adapter);
879 netxen_release_firmware(adapter);
884 netxen_nic_request_irq(struct netxen_adapter *adapter)
886 irq_handler_t handler;
887 struct nx_host_sds_ring *sds_ring;
890 unsigned long flags = IRQF_SAMPLE_RANDOM;
891 struct net_device *netdev = adapter->netdev;
892 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
894 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
895 handler = netxen_msix_intr;
896 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
897 handler = netxen_msi_intr;
899 flags |= IRQF_SHARED;
900 handler = netxen_intr;
902 adapter->irq = netdev->irq;
904 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
905 sds_ring = &recv_ctx->sds_rings[ring];
906 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
907 err = request_irq(sds_ring->irq, handler,
908 flags, sds_ring->name, sds_ring);
917 netxen_nic_free_irq(struct netxen_adapter *adapter)
920 struct nx_host_sds_ring *sds_ring;
922 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
924 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
925 sds_ring = &recv_ctx->sds_rings[ring];
926 free_irq(sds_ring->irq, sds_ring);
931 netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter)
933 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
934 adapter->coal.normal.data.rx_time_us =
935 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
936 adapter->coal.normal.data.rx_packets =
937 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
938 adapter->coal.normal.data.tx_time_us =
939 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US;
940 adapter->coal.normal.data.tx_packets =
941 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS;
945 netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
949 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
952 err = adapter->init_port(adapter, adapter->physical_port);
954 printk(KERN_ERR "%s: Failed to initialize port %d\n",
955 netxen_nic_driver_name, adapter->portnum);
958 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
959 adapter->macaddr_set(adapter, netdev->dev_addr);
961 adapter->set_multi(netdev);
962 adapter->set_mtu(adapter, netdev->mtu);
964 adapter->ahw.linkup = 0;
966 if (adapter->max_sds_rings > 1)
967 netxen_config_rss(adapter, 1);
969 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
970 netxen_config_intr_coalesce(adapter);
972 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
973 netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED);
975 netxen_napi_enable(adapter);
977 if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)
978 netxen_linkevent_request(adapter, 1);
980 netxen_nic_set_link_parameters(adapter);
982 set_bit(__NX_DEV_UP, &adapter->state);
987 netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
989 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
992 clear_bit(__NX_DEV_UP, &adapter->state);
994 spin_lock(&adapter->tx_clean_lock);
995 netif_carrier_off(netdev);
996 netif_tx_disable(netdev);
998 if (adapter->stop_port)
999 adapter->stop_port(adapter);
1001 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1002 netxen_p3_free_mac_list(adapter);
1004 adapter->set_promisc(adapter, NETXEN_NIU_NON_PROMISC_MODE);
1006 netxen_napi_disable(adapter);
1008 netxen_release_tx_buffers(adapter);
1009 spin_unlock(&adapter->tx_clean_lock);
1014 netxen_nic_attach(struct netxen_adapter *adapter)
1016 struct net_device *netdev = adapter->netdev;
1017 struct pci_dev *pdev = adapter->pdev;
1019 struct nx_host_rds_ring *rds_ring;
1020 struct nx_host_tx_ring *tx_ring;
1022 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
1025 err = netxen_init_firmware(adapter);
1029 err = netxen_napi_add(adapter, netdev);
1033 err = netxen_alloc_sw_resources(adapter);
1035 printk(KERN_ERR "%s: Error in setting sw resources\n",
1040 err = netxen_alloc_hw_resources(adapter);
1042 printk(KERN_ERR "%s: Error in setting hw resources\n",
1044 goto err_out_free_sw;
1047 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1048 tx_ring = adapter->tx_ring;
1049 tx_ring->crb_cmd_producer = netxen_get_ioaddr(adapter,
1050 crb_cmd_producer[adapter->portnum]);
1051 tx_ring->crb_cmd_consumer = netxen_get_ioaddr(adapter,
1052 crb_cmd_consumer[adapter->portnum]);
1054 tx_ring->producer = 0;
1055 tx_ring->sw_consumer = 0;
1057 netxen_nic_update_cmd_producer(adapter, tx_ring);
1058 netxen_nic_update_cmd_consumer(adapter, tx_ring);
1061 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1062 rds_ring = &adapter->recv_ctx.rds_rings[ring];
1063 netxen_post_rx_buffers(adapter, ring, rds_ring);
1066 err = netxen_nic_request_irq(adapter);
1068 dev_err(&pdev->dev, "%s: failed to setup interrupt\n",
1070 goto err_out_free_rxbuf;
1073 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1074 netxen_nic_init_coalesce_defaults(adapter);
1076 netxen_create_sysfs_entries(adapter);
1078 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1082 netxen_release_rx_buffers(adapter);
1083 netxen_free_hw_resources(adapter);
1085 netxen_free_sw_resources(adapter);
1090 netxen_nic_detach(struct netxen_adapter *adapter)
1092 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1095 netxen_remove_sysfs_entries(adapter);
1097 netxen_free_hw_resources(adapter);
1098 netxen_release_rx_buffers(adapter);
1099 netxen_nic_free_irq(adapter);
1100 netxen_napi_del(adapter);
1101 netxen_free_sw_resources(adapter);
1107 netxen_nic_reset_context(struct netxen_adapter *adapter)
1110 struct net_device *netdev = adapter->netdev;
1112 if (test_and_set_bit(__NX_RESETTING, &adapter->state))
1115 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
1117 netif_device_detach(netdev);
1119 if (netif_running(netdev))
1120 netxen_nic_down(adapter, netdev);
1122 netxen_nic_detach(adapter);
1124 if (netif_running(netdev)) {
1125 err = netxen_nic_attach(adapter);
1127 err = netxen_nic_up(adapter, netdev);
1133 netif_device_attach(netdev);
1137 clear_bit(__NX_RESETTING, &adapter->state);
1142 netxen_setup_netdev(struct netxen_adapter *adapter,
1143 struct net_device *netdev)
1146 struct pci_dev *pdev = adapter->pdev;
1148 adapter->rx_csum = 1;
1149 adapter->mc_enabled = 0;
1150 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1151 adapter->max_mc_count = 38;
1153 adapter->max_mc_count = 16;
1155 netdev->netdev_ops = &netxen_netdev_ops;
1156 netdev->watchdog_timeo = 2*HZ;
1158 netxen_nic_change_mtu(netdev, netdev->mtu);
1160 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
1162 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1163 netdev->features |= (NETIF_F_GRO);
1164 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1166 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1167 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1168 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1171 if (adapter->pci_using_dac) {
1172 netdev->features |= NETIF_F_HIGHDMA;
1173 netdev->vlan_features |= NETIF_F_HIGHDMA;
1176 if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX)
1177 netdev->features |= (NETIF_F_HW_VLAN_TX);
1179 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
1180 netdev->features |= NETIF_F_LRO;
1182 netdev->irq = adapter->msix_entries[0].vector;
1184 INIT_WORK(&adapter->tx_timeout_task, netxen_reset_task);
1186 if (netxen_read_mac_addr(adapter))
1187 dev_warn(&pdev->dev, "failed to read mac addr\n");
1189 netif_carrier_off(netdev);
1190 netif_stop_queue(netdev);
1192 err = register_netdev(netdev);
1194 dev_err(&pdev->dev, "failed to register net device\n");
1201 static int __devinit
1202 netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1204 struct net_device *netdev = NULL;
1205 struct netxen_adapter *adapter = NULL;
1207 int pci_func_id = PCI_FUNC(pdev->devfn);
1208 uint8_t revision_id;
1210 if (pdev->class != 0x020000) {
1211 printk(KERN_DEBUG "NetXen function %d, class %x will not "
1212 "be enabled.\n",pci_func_id, pdev->class);
1216 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
1217 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
1218 "will not be enabled.\n",
1219 NX_P3_A0, NX_P3_B1);
1223 if ((err = pci_enable_device(pdev)))
1226 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1228 goto err_out_disable_pdev;
1231 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
1232 goto err_out_disable_pdev;
1234 pci_set_master(pdev);
1236 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
1238 dev_err(&pdev->dev, "failed to allocate net_device\n");
1240 goto err_out_free_res;
1243 SET_NETDEV_DEV(netdev, &pdev->dev);
1245 adapter = netdev_priv(netdev);
1246 adapter->netdev = netdev;
1247 adapter->pdev = pdev;
1248 adapter->ahw.pci_func = pci_func_id;
1250 revision_id = pdev->revision;
1251 adapter->ahw.revision_id = revision_id;
1253 rwlock_init(&adapter->adapter_lock);
1254 spin_lock_init(&adapter->tx_clean_lock);
1255 INIT_LIST_HEAD(&adapter->mac_list);
1257 err = netxen_setup_pci_map(adapter);
1259 goto err_out_free_netdev;
1261 /* This will be reset for mezz cards */
1262 adapter->portnum = pci_func_id;
1264 err = netxen_nic_get_board_info(adapter);
1266 dev_err(&pdev->dev, "Error getting board config info.\n");
1267 goto err_out_iounmap;
1270 /* Mezz cards have PCI function 0,2,3 enabled */
1271 switch (adapter->ahw.board_type) {
1272 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1273 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1274 if (pci_func_id >= 2)
1275 adapter->portnum = pci_func_id - 2;
1281 err = netxen_start_firmware(adapter);
1283 goto err_out_iounmap;
1286 * See if the firmware gave us a virtual-physical port mapping.
1288 adapter->physical_port = adapter->portnum;
1289 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1290 i = NXRD32(adapter, CRB_V2P(adapter->portnum));
1291 if (i != 0x55555555)
1292 adapter->physical_port = i;
1295 netxen_nic_clear_stats(adapter);
1297 netxen_setup_intr(adapter);
1299 err = netxen_setup_netdev(adapter, netdev);
1301 goto err_out_disable_msi;
1303 pci_set_drvdata(pdev, adapter);
1305 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
1307 switch (adapter->ahw.port_type) {
1308 case NETXEN_NIC_GBE:
1309 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1310 adapter->netdev->name);
1312 case NETXEN_NIC_XGBE:
1313 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1314 adapter->netdev->name);
1320 err_out_disable_msi:
1321 netxen_teardown_intr(adapter);
1323 netxen_free_dummy_dma(adapter);
1325 nx_decr_dev_ref_cnt(adapter);
1328 netxen_cleanup_pci_map(adapter);
1330 err_out_free_netdev:
1331 free_netdev(netdev);
1334 pci_release_regions(pdev);
1336 err_out_disable_pdev:
1337 pci_set_drvdata(pdev, NULL);
1338 pci_disable_device(pdev);
1342 static void __devexit netxen_nic_remove(struct pci_dev *pdev)
1344 struct netxen_adapter *adapter;
1345 struct net_device *netdev;
1347 adapter = pci_get_drvdata(pdev);
1348 if (adapter == NULL)
1351 netdev = adapter->netdev;
1353 netxen_cancel_fw_work(adapter);
1355 unregister_netdev(netdev);
1357 cancel_work_sync(&adapter->tx_timeout_task);
1359 netxen_nic_detach(adapter);
1361 nx_decr_dev_ref_cnt(adapter);
1363 if (adapter->portnum == 0)
1364 netxen_free_dummy_dma(adapter);
1366 clear_bit(__NX_RESETTING, &adapter->state);
1368 netxen_teardown_intr(adapter);
1370 netxen_cleanup_pci_map(adapter);
1372 netxen_release_firmware(adapter);
1374 pci_release_regions(pdev);
1375 pci_disable_device(pdev);
1376 pci_set_drvdata(pdev, NULL);
1378 free_netdev(netdev);
1380 static int __netxen_nic_shutdown(struct pci_dev *pdev)
1382 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1383 struct net_device *netdev = adapter->netdev;
1386 netif_device_detach(netdev);
1388 netxen_cancel_fw_work(adapter);
1390 if (netif_running(netdev))
1391 netxen_nic_down(adapter, netdev);
1393 cancel_work_sync(&adapter->tx_timeout_task);
1395 netxen_nic_detach(adapter);
1397 if (adapter->portnum == 0)
1398 netxen_free_dummy_dma(adapter);
1400 nx_decr_dev_ref_cnt(adapter);
1402 clear_bit(__NX_RESETTING, &adapter->state);
1404 retval = pci_save_state(pdev);
1408 if (netxen_nic_wol_supported(adapter)) {
1409 pci_enable_wake(pdev, PCI_D3cold, 1);
1410 pci_enable_wake(pdev, PCI_D3hot, 1);
1413 pci_disable_device(pdev);
1417 static void netxen_nic_shutdown(struct pci_dev *pdev)
1419 if (__netxen_nic_shutdown(pdev))
1424 netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
1428 retval = __netxen_nic_shutdown(pdev);
1432 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1437 netxen_nic_resume(struct pci_dev *pdev)
1439 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1440 struct net_device *netdev = adapter->netdev;
1443 pci_set_power_state(pdev, PCI_D0);
1444 pci_restore_state(pdev);
1446 err = pci_enable_device(pdev);
1450 adapter->curr_window = 255;
1452 err = netxen_start_firmware(adapter);
1454 dev_err(&pdev->dev, "failed to start firmware\n");
1458 if (netif_running(netdev)) {
1459 err = netxen_nic_attach(adapter);
1463 err = netxen_nic_up(adapter, netdev);
1465 goto err_out_detach;
1467 netif_device_attach(netdev);
1469 netxen_config_indev_addr(netdev, NETDEV_UP);
1472 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
1475 netxen_nic_detach(adapter);
1477 nx_decr_dev_ref_cnt(adapter);
1482 static int netxen_nic_open(struct net_device *netdev)
1484 struct netxen_adapter *adapter = netdev_priv(netdev);
1487 if (adapter->driver_mismatch)
1490 err = netxen_nic_attach(adapter);
1494 err = netxen_nic_up(adapter, netdev);
1498 netif_start_queue(netdev);
1503 netxen_nic_detach(adapter);
1508 * netxen_nic_close - Disables a network interface entry point
1510 static int netxen_nic_close(struct net_device *netdev)
1512 struct netxen_adapter *adapter = netdev_priv(netdev);
1514 netxen_nic_down(adapter, netdev);
1519 netxen_tso_check(struct net_device *netdev,
1520 struct nx_host_tx_ring *tx_ring,
1521 struct cmd_desc_type0 *first_desc,
1522 struct sk_buff *skb)
1524 u8 opcode = TX_ETHER_PKT;
1525 __be16 protocol = skb->protocol;
1526 u16 flags = 0, vid = 0;
1528 int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0;
1529 struct cmd_desc_type0 *hwdesc;
1530 struct vlan_ethhdr *vh;
1532 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
1534 vh = (struct vlan_ethhdr *)skb->data;
1535 protocol = vh->h_vlan_encapsulated_proto;
1536 flags = FLAGS_VLAN_TAGGED;
1538 } else if (vlan_tx_tag_present(skb)) {
1540 flags = FLAGS_VLAN_OOB;
1541 vid = vlan_tx_tag_get(skb);
1542 netxen_set_tx_vlan_tci(first_desc, vid);
1546 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1547 skb_shinfo(skb)->gso_size > 0) {
1549 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1551 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1552 first_desc->total_hdr_length = hdr_len;
1554 first_desc->total_hdr_length += VLAN_HLEN;
1555 first_desc->tcp_hdr_offset = VLAN_HLEN;
1556 first_desc->ip_hdr_offset = VLAN_HLEN;
1557 /* Only in case of TSO on vlan device */
1558 flags |= FLAGS_VLAN_TAGGED;
1561 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
1562 TX_TCP_LSO6 : TX_TCP_LSO;
1565 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
1568 if (protocol == cpu_to_be16(ETH_P_IP)) {
1569 l4proto = ip_hdr(skb)->protocol;
1571 if (l4proto == IPPROTO_TCP)
1572 opcode = TX_TCP_PKT;
1573 else if(l4proto == IPPROTO_UDP)
1574 opcode = TX_UDP_PKT;
1575 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
1576 l4proto = ipv6_hdr(skb)->nexthdr;
1578 if (l4proto == IPPROTO_TCP)
1579 opcode = TX_TCPV6_PKT;
1580 else if(l4proto == IPPROTO_UDP)
1581 opcode = TX_UDPV6_PKT;
1585 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
1586 first_desc->ip_hdr_offset += skb_network_offset(skb);
1587 netxen_set_tx_flags_opcode(first_desc, flags, opcode);
1592 /* For LSO, we need to copy the MAC/IP/TCP headers into
1593 * the descriptor ring
1595 producer = tx_ring->producer;
1600 /* Create a TSO vlan header template for firmware */
1602 hwdesc = &tx_ring->desc_head[producer];
1603 tx_ring->cmd_buf_arr[producer].skb = NULL;
1605 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1606 hdr_len + VLAN_HLEN);
1608 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2);
1609 skb_copy_from_linear_data(skb, vh, 12);
1610 vh->h_vlan_proto = htons(ETH_P_8021Q);
1611 vh->h_vlan_TCI = htons(vid);
1612 skb_copy_from_linear_data_offset(skb, 12,
1613 (char *)vh + 16, copy_len - 16);
1615 copied = copy_len - VLAN_HLEN;
1618 producer = get_next_index(producer, tx_ring->num_desc);
1621 while (copied < hdr_len) {
1623 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1624 (hdr_len - copied));
1626 hwdesc = &tx_ring->desc_head[producer];
1627 tx_ring->cmd_buf_arr[producer].skb = NULL;
1629 skb_copy_from_linear_data_offset(skb, copied,
1630 (char *)hwdesc + offset, copy_len);
1635 producer = get_next_index(producer, tx_ring->num_desc);
1638 tx_ring->producer = producer;
1643 netxen_map_tx_skb(struct pci_dev *pdev,
1644 struct sk_buff *skb, struct netxen_cmd_buffer *pbuf)
1646 struct netxen_skb_frag *nf;
1647 struct skb_frag_struct *frag;
1651 nr_frags = skb_shinfo(skb)->nr_frags;
1652 nf = &pbuf->frag_array[0];
1654 map = pci_map_single(pdev, skb->data,
1655 skb_headlen(skb), PCI_DMA_TODEVICE);
1656 if (pci_dma_mapping_error(pdev, map))
1660 nf->length = skb_headlen(skb);
1662 for (i = 0; i < nr_frags; i++) {
1663 frag = &skb_shinfo(skb)->frags[i];
1664 nf = &pbuf->frag_array[i+1];
1666 map = pci_map_page(pdev, frag->page, frag->page_offset,
1667 frag->size, PCI_DMA_TODEVICE);
1668 if (pci_dma_mapping_error(pdev, map))
1672 nf->length = frag->size;
1679 nf = &pbuf->frag_array[i+1];
1680 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
1683 nf = &pbuf->frag_array[0];
1684 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
1691 netxen_clear_cmddesc(u64 *desc)
1698 netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1700 struct netxen_adapter *adapter = netdev_priv(netdev);
1701 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
1702 struct netxen_cmd_buffer *pbuf;
1703 struct netxen_skb_frag *buffrag;
1704 struct cmd_desc_type0 *hwdesc, *first_desc;
1705 struct pci_dev *pdev;
1709 int frag_count, no_of_desc;
1710 u32 num_txd = tx_ring->num_desc;
1712 frag_count = skb_shinfo(skb)->nr_frags + 1;
1714 /* 4 fragments per cmd des */
1715 no_of_desc = (frag_count + 3) >> 2;
1717 if (unlikely(no_of_desc + 2) > netxen_tx_avail(tx_ring)) {
1718 netif_stop_queue(netdev);
1719 return NETDEV_TX_BUSY;
1722 producer = tx_ring->producer;
1723 pbuf = &tx_ring->cmd_buf_arr[producer];
1725 pdev = adapter->pdev;
1727 if (netxen_map_tx_skb(pdev, skb, pbuf))
1731 pbuf->frag_count = frag_count;
1733 first_desc = hwdesc = &tx_ring->desc_head[producer];
1734 netxen_clear_cmddesc((u64 *)hwdesc);
1736 netxen_set_tx_frags_len(first_desc, frag_count, skb->len);
1737 netxen_set_tx_port(first_desc, adapter->portnum);
1739 for (i = 0; i < frag_count; i++) {
1743 if ((k == 0) && (i > 0)) {
1744 /* move to next desc.*/
1745 producer = get_next_index(producer, num_txd);
1746 hwdesc = &tx_ring->desc_head[producer];
1747 netxen_clear_cmddesc((u64 *)hwdesc);
1748 tx_ring->cmd_buf_arr[producer].skb = NULL;
1751 buffrag = &pbuf->frag_array[i];
1753 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
1756 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
1759 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
1762 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
1765 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
1770 tx_ring->producer = get_next_index(producer, num_txd);
1772 netxen_tso_check(netdev, tx_ring, first_desc, skb);
1774 netxen_nic_update_cmd_producer(adapter, tx_ring);
1776 adapter->stats.txbytes += skb->len;
1777 adapter->stats.xmitcalled++;
1779 return NETDEV_TX_OK;
1782 adapter->stats.txdropped++;
1783 dev_kfree_skb_any(skb);
1784 return NETDEV_TX_OK;
1787 static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1789 struct net_device *netdev = adapter->netdev;
1790 uint32_t temp, temp_state, temp_val;
1793 temp = NXRD32(adapter, CRB_TEMP_STATE);
1795 temp_state = nx_get_temp_state(temp);
1796 temp_val = nx_get_temp_val(temp);
1798 if (temp_state == NX_TEMP_PANIC) {
1800 "%s: Device temperature %d degrees C exceeds"
1801 " maximum allowed. Hardware has been shut down.\n",
1802 netdev->name, temp_val);
1804 } else if (temp_state == NX_TEMP_WARN) {
1805 if (adapter->temp == NX_TEMP_NORMAL) {
1807 "%s: Device temperature %d degrees C "
1808 "exceeds operating range."
1809 " Immediate action needed.\n",
1810 netdev->name, temp_val);
1813 if (adapter->temp == NX_TEMP_WARN) {
1815 "%s: Device temperature is now %d degrees C"
1816 " in normal range.\n", netdev->name,
1820 adapter->temp = temp_state;
1824 void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup)
1826 struct net_device *netdev = adapter->netdev;
1828 if (adapter->ahw.linkup && !linkup) {
1829 printk(KERN_INFO "%s: %s NIC Link is down\n",
1830 netxen_nic_driver_name, netdev->name);
1831 adapter->ahw.linkup = 0;
1832 if (netif_running(netdev)) {
1833 netif_carrier_off(netdev);
1834 netif_stop_queue(netdev);
1836 adapter->link_changed = !adapter->has_link_events;
1837 } else if (!adapter->ahw.linkup && linkup) {
1838 printk(KERN_INFO "%s: %s NIC Link is up\n",
1839 netxen_nic_driver_name, netdev->name);
1840 adapter->ahw.linkup = 1;
1841 if (netif_running(netdev)) {
1842 netif_carrier_on(netdev);
1843 netif_wake_queue(netdev);
1845 adapter->link_changed = !adapter->has_link_events;
1849 static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1851 u32 val, port, linkup;
1853 port = adapter->physical_port;
1855 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1856 val = NXRD32(adapter, CRB_XG_STATE_P3);
1857 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1858 linkup = (val == XG_LINK_UP_P3);
1860 val = NXRD32(adapter, CRB_XG_STATE);
1861 if (adapter->ahw.port_type == NETXEN_NIC_GBE)
1862 linkup = (val >> port) & 1;
1864 val = (val >> port*8) & 0xff;
1865 linkup = (val == XG_LINK_UP);
1869 netxen_advert_link_change(adapter, linkup);
1872 static void netxen_tx_timeout(struct net_device *netdev)
1874 struct netxen_adapter *adapter = netdev_priv(netdev);
1876 if (test_bit(__NX_RESETTING, &adapter->state))
1879 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
1880 schedule_work(&adapter->tx_timeout_task);
1883 static void netxen_reset_task(struct work_struct *work)
1885 struct netxen_adapter *adapter =
1886 container_of(work, struct netxen_adapter, tx_timeout_task);
1888 if (!netif_running(adapter->netdev))
1891 if (test_bit(__NX_RESETTING, &adapter->state))
1894 netxen_napi_disable(adapter);
1896 adapter->netdev->trans_start = jiffies;
1898 netxen_napi_enable(adapter);
1899 netif_wake_queue(adapter->netdev);
1902 struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1904 struct netxen_adapter *adapter = netdev_priv(netdev);
1905 struct net_device_stats *stats = &adapter->net_stats;
1907 memset(stats, 0, sizeof(*stats));
1909 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
1910 stats->tx_packets = adapter->stats.xmitfinished;
1911 stats->rx_bytes = adapter->stats.rxbytes;
1912 stats->tx_bytes = adapter->stats.txbytes;
1913 stats->rx_dropped = adapter->stats.rxdropped;
1914 stats->tx_dropped = adapter->stats.txdropped;
1919 static irqreturn_t netxen_intr(int irq, void *data)
1921 struct nx_host_sds_ring *sds_ring = data;
1922 struct netxen_adapter *adapter = sds_ring->adapter;
1925 status = readl(adapter->isr_int_vec);
1927 if (!(status & adapter->int_vec_bit))
1930 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1931 /* check interrupt state machine, to be sure */
1932 status = readl(adapter->crb_int_state_reg);
1933 if (!ISR_LEGACY_INT_TRIGGERED(status))
1937 unsigned long our_int = 0;
1939 our_int = readl(adapter->crb_int_state_reg);
1941 /* not our interrupt */
1942 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
1945 /* claim interrupt */
1946 writel((our_int & 0xffffffff), adapter->crb_int_state_reg);
1948 /* clear interrupt */
1949 netxen_nic_disable_int(sds_ring);
1952 writel(0xffffffff, adapter->tgt_status_reg);
1953 /* read twice to ensure write is flushed */
1954 readl(adapter->isr_int_vec);
1955 readl(adapter->isr_int_vec);
1957 napi_schedule(&sds_ring->napi);
1962 static irqreturn_t netxen_msi_intr(int irq, void *data)
1964 struct nx_host_sds_ring *sds_ring = data;
1965 struct netxen_adapter *adapter = sds_ring->adapter;
1967 /* clear interrupt */
1968 writel(0xffffffff, adapter->tgt_status_reg);
1970 napi_schedule(&sds_ring->napi);
1974 static irqreturn_t netxen_msix_intr(int irq, void *data)
1976 struct nx_host_sds_ring *sds_ring = data;
1978 napi_schedule(&sds_ring->napi);
1982 static int netxen_nic_poll(struct napi_struct *napi, int budget)
1984 struct nx_host_sds_ring *sds_ring =
1985 container_of(napi, struct nx_host_sds_ring, napi);
1987 struct netxen_adapter *adapter = sds_ring->adapter;
1992 tx_complete = netxen_process_cmd_ring(adapter);
1994 work_done = netxen_process_rcv_ring(sds_ring, budget);
1996 if ((work_done < budget) && tx_complete) {
1997 napi_complete(&sds_ring->napi);
1998 if (netif_running(adapter->netdev))
1999 netxen_nic_enable_int(sds_ring);
2005 #ifdef CONFIG_NET_POLL_CONTROLLER
2006 static void netxen_nic_poll_controller(struct net_device *netdev)
2008 struct netxen_adapter *adapter = netdev_priv(netdev);
2009 disable_irq(adapter->irq);
2010 netxen_intr(adapter->irq, adapter);
2011 enable_irq(adapter->irq);
2016 nx_incr_dev_ref_cnt(struct netxen_adapter *adapter)
2019 if (netxen_api_lock(adapter))
2022 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2024 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2026 netxen_api_unlock(adapter);
2031 nx_decr_dev_ref_cnt(struct netxen_adapter *adapter)
2034 if (netxen_api_lock(adapter))
2037 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2038 WARN_ON(count == 0);
2040 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, --count);
2043 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_COLD);
2045 netxen_api_unlock(adapter);
2050 netxen_can_start_firmware(struct netxen_adapter *adapter)
2055 if (netxen_api_lock(adapter))
2058 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2060 if ((count < 0) || (count >= NX_MAX_PCI_FUNC))
2065 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_INITALIZING);
2068 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2070 netxen_api_unlock(adapter);
2076 netxen_schedule_work(struct netxen_adapter *adapter,
2077 work_func_t func, int delay)
2079 INIT_DELAYED_WORK(&adapter->fw_work, func);
2080 schedule_delayed_work(&adapter->fw_work, delay);
2084 netxen_cancel_fw_work(struct netxen_adapter *adapter)
2086 while (test_and_set_bit(__NX_RESETTING, &adapter->state))
2089 cancel_delayed_work_sync(&adapter->fw_work);
2093 netxen_attach_work(struct work_struct *work)
2095 struct netxen_adapter *adapter = container_of(work,
2096 struct netxen_adapter, fw_work.work);
2097 struct net_device *netdev = adapter->netdev;
2100 if (netif_running(netdev)) {
2101 err = netxen_nic_attach(adapter);
2105 err = netxen_nic_up(adapter, netdev);
2107 netxen_nic_detach(adapter);
2111 netxen_config_indev_addr(netdev, NETDEV_UP);
2114 netif_device_attach(netdev);
2117 adapter->fw_fail_cnt = 0;
2118 clear_bit(__NX_RESETTING, &adapter->state);
2119 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
2123 netxen_fwinit_work(struct work_struct *work)
2125 struct netxen_adapter *adapter = container_of(work,
2126 struct netxen_adapter, fw_work.work);
2129 dev_state = NXRD32(adapter, NX_CRB_DEV_STATE);
2131 switch (dev_state) {
2134 netxen_start_firmware(adapter);
2135 netxen_schedule_work(adapter, netxen_attach_work, 0);
2138 case NX_DEV_INITALIZING:
2139 if (++adapter->fw_wait_cnt < FW_POLL_THRESH) {
2140 netxen_schedule_work(adapter,
2141 netxen_fwinit_work, 2 * FW_POLL_DELAY);
2151 nx_incr_dev_ref_cnt(adapter);
2152 clear_bit(__NX_RESETTING, &adapter->state);
2156 netxen_detach_work(struct work_struct *work)
2158 struct netxen_adapter *adapter = container_of(work,
2159 struct netxen_adapter, fw_work.work);
2160 struct net_device *netdev = adapter->netdev;
2164 netif_device_detach(netdev);
2166 if (netif_running(netdev))
2167 netxen_nic_down(adapter, netdev);
2169 netxen_nic_detach(adapter);
2171 status = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1);
2173 ref_cnt = nx_decr_dev_ref_cnt(adapter);
2175 if (status & NX_RCODE_FATAL_ERROR)
2178 if (adapter->temp == NX_TEMP_PANIC)
2181 delay = (ref_cnt == 0) ? 0 : (2 * FW_POLL_DELAY);
2183 adapter->fw_wait_cnt = 0;
2184 netxen_schedule_work(adapter, netxen_fwinit_work, delay);
2188 netxen_check_health(struct netxen_adapter *adapter)
2190 u32 state, heartbit;
2191 struct net_device *netdev = adapter->netdev;
2193 if (netxen_nic_check_temp(adapter))
2196 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2197 if (state == NX_DEV_NEED_RESET)
2200 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2203 heartbit = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER);
2204 if (heartbit != adapter->heartbit) {
2205 adapter->heartbit = heartbit;
2206 adapter->fw_fail_cnt = 0;
2210 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2213 clear_bit(__NX_FW_ATTACHED, &adapter->state);
2215 dev_info(&netdev->dev, "firmware hang detected\n");
2218 if (!test_and_set_bit(__NX_RESETTING, &adapter->state))
2219 netxen_schedule_work(adapter, netxen_detach_work, 0);
2224 netxen_fw_poll_work(struct work_struct *work)
2226 struct netxen_adapter *adapter = container_of(work,
2227 struct netxen_adapter, fw_work.work);
2229 if (test_bit(__NX_RESETTING, &adapter->state))
2232 if (test_bit(__NX_DEV_UP, &adapter->state)) {
2233 if (!adapter->has_link_events) {
2235 netxen_nic_handle_phy_intr(adapter);
2237 if (adapter->link_changed)
2238 netxen_nic_set_link_parameters(adapter);
2242 if (netxen_check_health(adapter))
2246 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
2250 netxen_store_bridged_mode(struct device *dev,
2251 struct device_attribute *attr, const char *buf, size_t len)
2253 struct net_device *net = to_net_dev(dev);
2254 struct netxen_adapter *adapter = netdev_priv(net);
2258 if (!(adapter->capabilities & NX_FW_CAPABILITY_BDG))
2261 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2264 if (strict_strtoul(buf, 2, &new))
2267 if (!netxen_config_bridged_mode(adapter, !!new))
2275 netxen_show_bridged_mode(struct device *dev,
2276 struct device_attribute *attr, char *buf)
2278 struct net_device *net = to_net_dev(dev);
2279 struct netxen_adapter *adapter;
2280 int bridged_mode = 0;
2282 adapter = netdev_priv(net);
2284 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2285 bridged_mode = !!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED);
2287 return sprintf(buf, "%d\n", bridged_mode);
2290 static struct device_attribute dev_attr_bridged_mode = {
2291 .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
2292 .show = netxen_show_bridged_mode,
2293 .store = netxen_store_bridged_mode,
2297 netxen_create_sysfs_entries(struct netxen_adapter *adapter)
2299 struct net_device *netdev = adapter->netdev;
2300 struct device *dev = &netdev->dev;
2302 if (adapter->capabilities & NX_FW_CAPABILITY_BDG) {
2303 /* bridged_mode control */
2304 if (device_create_file(dev, &dev_attr_bridged_mode)) {
2305 dev_warn(&netdev->dev,
2306 "failed to create bridged_mode sysfs entry\n");
2312 netxen_remove_sysfs_entries(struct netxen_adapter *adapter)
2314 struct net_device *netdev = adapter->netdev;
2315 struct device *dev = &netdev->dev;
2317 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2318 device_remove_file(dev, &dev_attr_bridged_mode);
2323 #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2326 netxen_destip_supported(struct netxen_adapter *adapter)
2328 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2331 if (adapter->ahw.cut_through)
2338 netxen_config_indev_addr(struct net_device *dev, unsigned long event)
2340 struct in_device *indev;
2341 struct netxen_adapter *adapter = netdev_priv(dev);
2343 if (!netxen_destip_supported(adapter))
2346 indev = in_dev_get(dev);
2353 netxen_config_ipaddr(adapter,
2354 ifa->ifa_address, NX_IP_UP);
2357 netxen_config_ipaddr(adapter,
2358 ifa->ifa_address, NX_IP_DOWN);
2363 } endfor_ifa(indev);
2369 static int netxen_netdev_event(struct notifier_block *this,
2370 unsigned long event, void *ptr)
2372 struct netxen_adapter *adapter;
2373 struct net_device *dev = (struct net_device *)ptr;
2379 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2380 dev = vlan_dev_real_dev(dev);
2384 if (!is_netxen_netdev(dev))
2387 adapter = netdev_priv(dev);
2392 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2395 netxen_config_indev_addr(dev, event);
2401 netxen_inetaddr_event(struct notifier_block *this,
2402 unsigned long event, void *ptr)
2404 struct netxen_adapter *adapter;
2405 struct net_device *dev;
2407 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
2409 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
2412 if (dev == NULL || !netif_running(dev))
2415 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2416 dev = vlan_dev_real_dev(dev);
2420 if (!is_netxen_netdev(dev))
2423 adapter = netdev_priv(dev);
2425 if (!adapter || !netxen_destip_supported(adapter))
2428 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2433 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP);
2436 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN);
2446 static struct notifier_block netxen_netdev_cb = {
2447 .notifier_call = netxen_netdev_event,
2450 static struct notifier_block netxen_inetaddr_cb = {
2451 .notifier_call = netxen_inetaddr_event,
2455 static struct pci_driver netxen_driver = {
2456 .name = netxen_nic_driver_name,
2457 .id_table = netxen_pci_tbl,
2458 .probe = netxen_nic_probe,
2459 .remove = __devexit_p(netxen_nic_remove),
2461 .suspend = netxen_nic_suspend,
2462 .resume = netxen_nic_resume,
2464 .shutdown = netxen_nic_shutdown
2467 static int __init netxen_init_module(void)
2469 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
2472 register_netdevice_notifier(&netxen_netdev_cb);
2473 register_inetaddr_notifier(&netxen_inetaddr_cb);
2476 return pci_register_driver(&netxen_driver);
2479 module_init(netxen_init_module);
2481 static void __exit netxen_exit_module(void)
2483 pci_unregister_driver(&netxen_driver);
2486 unregister_inetaddr_notifier(&netxen_inetaddr_cb);
2487 unregister_netdevice_notifier(&netxen_netdev_cb);
2491 module_exit(netxen_exit_module);