2 * Copyright (C) 2003 - 2006 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:
26 * 3965 Freedom Circle, Fourth floor,
27 * Santa Clara, CA 95054
30 * Main source file for NetXen NIC Driver on Linux
34 #include <linux/vmalloc.h>
35 #include <linux/highmem.h>
36 #include "netxen_nic_hw.h"
38 #include "netxen_nic.h"
39 #include "netxen_nic_phan_reg.h"
41 #include <linux/dma-mapping.h>
42 #include <linux/if_vlan.h>
44 #include <linux/ipv6.h>
46 MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
47 MODULE_LICENSE("GPL");
48 MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
50 char netxen_nic_driver_name[] = "netxen_nic";
51 static char netxen_nic_driver_string[] = "NetXen Network Driver version "
52 NETXEN_NIC_LINUX_VERSIONID;
54 static int port_mode = NETXEN_PORT_MODE_AUTO_NEG;
56 /* Default to restricted 1G auto-neg mode */
57 static int wol_port_mode = 5;
59 static int use_msi = 1;
61 static int use_msi_x = 1;
63 /* Local functions to NetXen NIC driver */
64 static int __devinit netxen_nic_probe(struct pci_dev *pdev,
65 const struct pci_device_id *ent);
66 static void __devexit netxen_nic_remove(struct pci_dev *pdev);
67 static int netxen_nic_open(struct net_device *netdev);
68 static int netxen_nic_close(struct net_device *netdev);
69 static int netxen_nic_xmit_frame(struct sk_buff *, 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_watchdog(unsigned long);
73 static int netxen_nic_poll(struct napi_struct *napi, int budget);
74 #ifdef CONFIG_NET_POLL_CONTROLLER
75 static void netxen_nic_poll_controller(struct net_device *netdev);
77 static irqreturn_t netxen_intr(int irq, void *data);
78 static irqreturn_t netxen_msi_intr(int irq, void *data);
80 /* PCI Device ID Table */
81 #define ENTRY(device) \
82 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
83 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
85 static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
86 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR),
87 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4),
88 ENTRY(PCI_DEVICE_ID_NX2031_4GCU),
89 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ),
90 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ),
91 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT),
92 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2),
93 ENTRY(PCI_DEVICE_ID_NX3031),
97 MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
100 * In netxen_nic_down(), we must wait for any pending callback requests into
101 * netxen_watchdog_task() to complete; eg otherwise the watchdog_timer could be
102 * reenabled right after it is deleted in netxen_nic_down().
103 * FLUSH_SCHEDULED_WORK() does this synchronization.
105 * Normally, schedule_work()/flush_scheduled_work() could have worked, but
106 * netxen_nic_close() is invoked with kernel rtnl lock held. netif_carrier_off()
107 * call in netxen_nic_close() triggers a schedule_work(&linkwatch_work), and a
108 * subsequent call to flush_scheduled_work() in netxen_nic_down() would cause
109 * linkwatch_event() to be executed which also attempts to acquire the rtnl
110 * lock thus causing a deadlock.
113 static struct workqueue_struct *netxen_workq;
114 #define SCHEDULE_WORK(tp) queue_work(netxen_workq, tp)
115 #define FLUSH_SCHEDULED_WORK() flush_workqueue(netxen_workq)
117 static void netxen_watchdog(unsigned long);
119 static uint32_t crb_cmd_producer[4] = {
120 CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1,
121 CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3
125 netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
126 uint32_t crb_producer)
128 adapter->pci_write_normalize(adapter,
129 adapter->crb_addr_cmd_producer, crb_producer);
132 static uint32_t crb_cmd_consumer[4] = {
133 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
134 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
138 netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
141 adapter->pci_write_normalize(adapter,
142 adapter->crb_addr_cmd_consumer, crb_consumer);
145 static uint32_t msi_tgt_status[8] = {
146 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
147 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
148 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
149 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
152 static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
154 static inline void netxen_nic_disable_int(struct netxen_adapter *adapter)
156 adapter->pci_write_normalize(adapter, adapter->crb_intr_mask, 0);
159 static inline void netxen_nic_enable_int(struct netxen_adapter *adapter)
161 adapter->pci_write_normalize(adapter, adapter->crb_intr_mask, 0x1);
163 if (!NETXEN_IS_MSI_FAMILY(adapter))
164 adapter->pci_write_immediate(adapter,
165 adapter->legacy_intr.tgt_mask_reg, 0xfbff);
168 static int nx_set_dma_mask(struct netxen_adapter *adapter, uint8_t revision_id)
170 struct pci_dev *pdev = adapter->pdev;
175 adapter->dma_mask = DMA_32BIT_MASK;
177 if (revision_id >= NX_P3_B0) {
178 /* should go to DMA_64BIT_MASK */
179 adapter->dma_mask = DMA_39BIT_MASK;
180 mask = DMA_39BIT_MASK;
181 } else if (revision_id == NX_P3_A2) {
182 adapter->dma_mask = DMA_39BIT_MASK;
183 mask = DMA_39BIT_MASK;
184 } else if (revision_id == NX_P2_C1) {
185 adapter->dma_mask = DMA_35BIT_MASK;
186 mask = DMA_35BIT_MASK;
188 adapter->dma_mask = DMA_32BIT_MASK;
189 mask = DMA_32BIT_MASK;
190 goto set_32_bit_mask;
194 * Consistent DMA mask is set to 32 bit because it cannot be set to
195 * 35 bits. For P3 also leave it at 32 bits for now. Only the rings
196 * come off this pool.
198 if (pci_set_dma_mask(pdev, mask) == 0 &&
199 pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK) == 0) {
200 adapter->pci_using_dac = 1;
203 #endif /* CONFIG_IA64 */
206 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
208 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
210 DPRINTK(ERR, "No usable DMA configuration, aborting:%d\n", err);
214 adapter->pci_using_dac = 0;
218 static void netxen_check_options(struct netxen_adapter *adapter)
220 switch (adapter->ahw.boardcfg.board_type) {
221 case NETXEN_BRDTYPE_P3_HMEZ:
222 case NETXEN_BRDTYPE_P3_XG_LOM:
223 case NETXEN_BRDTYPE_P3_10G_CX4:
224 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
225 case NETXEN_BRDTYPE_P3_IMEZ:
226 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
227 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
228 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
229 case NETXEN_BRDTYPE_P3_10G_XFP:
230 case NETXEN_BRDTYPE_P3_10000_BASE_T:
231 adapter->msix_supported = !!use_msi_x;
232 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
235 case NETXEN_BRDTYPE_P2_SB31_10G:
236 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
237 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
238 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
239 adapter->msix_supported = 0;
240 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
243 case NETXEN_BRDTYPE_P3_REF_QG:
244 case NETXEN_BRDTYPE_P3_4_GB:
245 case NETXEN_BRDTYPE_P3_4_GB_MM:
246 adapter->msix_supported = !!use_msi_x;
247 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
250 case NETXEN_BRDTYPE_P2_SB35_4G:
251 case NETXEN_BRDTYPE_P2_SB31_2G:
252 adapter->msix_supported = 0;
253 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
256 case NETXEN_BRDTYPE_P3_10G_TP:
257 adapter->msix_supported = !!use_msi_x;
258 if (adapter->ahw.board_type == NETXEN_NIC_XGBE)
259 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
261 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
265 adapter->msix_supported = 0;
266 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
268 printk(KERN_WARNING "Unknown board type(0x%x)\n",
269 adapter->ahw.boardcfg.board_type);
273 adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS_HOST;
274 adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS;
275 adapter->max_lro_rx_desc_count = MAX_LRO_RCV_DESCRIPTORS;
277 adapter->max_possible_rss_rings = 1;
282 netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
286 if (first_boot == 0x55555555) {
287 /* This is the first boot after power up */
288 adapter->pci_write_normalize(adapter,
289 NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
291 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
294 /* PCI bus master workaround */
295 adapter->hw_read_wx(adapter,
296 NETXEN_PCIE_REG(0x4), &first_boot, 4);
297 if (!(first_boot & 0x4)) {
299 adapter->hw_write_wx(adapter,
300 NETXEN_PCIE_REG(0x4), &first_boot, 4);
301 adapter->hw_read_wx(adapter,
302 NETXEN_PCIE_REG(0x4), &first_boot, 4);
305 /* This is the first boot after power up */
306 adapter->hw_read_wx(adapter,
307 NETXEN_ROMUSB_GLB_SW_RESET, &first_boot, 4);
308 if (first_boot != 0x80000f) {
309 /* clear the register for future unloads/loads */
310 adapter->pci_write_normalize(adapter,
311 NETXEN_CAM_RAM(0x1fc), 0);
315 /* Start P2 boot loader */
316 val = adapter->pci_read_normalize(adapter,
317 NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
318 adapter->pci_write_normalize(adapter,
319 NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
323 val = adapter->pci_read_normalize(adapter,
324 NETXEN_CAM_RAM(0x1fc));
326 if (++timeout > 5000)
329 } while (val == NETXEN_BDINFO_MAGIC);
334 static void netxen_set_port_mode(struct netxen_adapter *adapter)
338 val = adapter->ahw.boardcfg.board_type;
339 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
340 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
341 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
342 data = NETXEN_PORT_MODE_802_3_AP;
343 adapter->hw_write_wx(adapter,
344 NETXEN_PORT_MODE_ADDR, &data, 4);
345 } else if (port_mode == NETXEN_PORT_MODE_XG) {
346 data = NETXEN_PORT_MODE_XG;
347 adapter->hw_write_wx(adapter,
348 NETXEN_PORT_MODE_ADDR, &data, 4);
349 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
350 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
351 adapter->hw_write_wx(adapter,
352 NETXEN_PORT_MODE_ADDR, &data, 4);
353 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
354 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
355 adapter->hw_write_wx(adapter,
356 NETXEN_PORT_MODE_ADDR, &data, 4);
358 data = NETXEN_PORT_MODE_AUTO_NEG;
359 adapter->hw_write_wx(adapter,
360 NETXEN_PORT_MODE_ADDR, &data, 4);
363 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
364 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
365 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
366 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
367 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
369 adapter->hw_write_wx(adapter, NETXEN_WOL_PORT_MODE,
374 #define PCI_CAP_ID_GEN 0x10
376 static void netxen_pcie_strap_init(struct netxen_adapter *adapter)
383 struct pci_dev *pdev;
385 pdev = adapter->pdev;
387 adapter->hw_read_wx(adapter,
388 NETXEN_PCIE_REG(PCIE_CHICKEN3), &chicken, 4);
389 /* clear chicken3.25:24 */
390 chicken &= 0xFCFFFFFF;
392 * if gen1 and B0, set F1020 - if gen 2, do nothing
393 * if gen2 set to F1000
395 pos = pci_find_capability(pdev, PCI_CAP_ID_GEN);
397 pci_read_config_dword(pdev, pos + 0x10, &control);
398 if ((control & 0x000F0000) != 0x00020000) {
399 /* set chicken3.24 if gen1 */
400 chicken |= 0x01000000;
402 printk(KERN_INFO "%s Gen2 strapping detected\n",
403 netxen_nic_driver_name);
406 /* set chicken3.24 if gen1 */
407 chicken |= 0x01000000;
408 printk(KERN_INFO "%s Gen1 strapping detected\n",
409 netxen_nic_driver_name);
410 if (adapter->ahw.revision_id == NX_P3_B0)
416 adapter->hw_write_wx(adapter,
417 NETXEN_PCIE_REG(PCIE_CHICKEN3), &chicken, 4);
422 pdevfuncsave = pdev->devfn;
423 if (pdevfuncsave & 0x07)
426 for (i = 0; i < 8; i++) {
427 pci_read_config_dword(pdev, pos + 8, &control);
428 pci_read_config_dword(pdev, pos + 8, &control);
429 pci_write_config_dword(pdev, pos + 8, c8c9value);
432 pdev->devfn = pdevfuncsave;
435 static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
440 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
442 pci_read_config_dword(pdev, pos, &control);
444 control |= PCI_MSIX_FLAGS_ENABLE;
447 pci_write_config_dword(pdev, pos, control);
451 static void netxen_init_msix_entries(struct netxen_adapter *adapter)
455 for (i = 0; i < MSIX_ENTRIES_PER_ADAPTER; i++)
456 adapter->msix_entries[i].entry = i;
460 netxen_read_mac_addr(struct netxen_adapter *adapter)
465 struct net_device *netdev = adapter->netdev;
466 struct pci_dev *pdev = adapter->pdev;
468 if (netxen_is_flash_supported(adapter) != 0)
471 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
472 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
475 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
479 p = (unsigned char *)&mac_addr;
480 for (i = 0; i < 6; i++)
481 netdev->dev_addr[i] = *(p + 5 - i);
483 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
485 /* set station address */
487 if (!is_valid_ether_addr(netdev->perm_addr))
488 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
490 adapter->macaddr_set(adapter, netdev->dev_addr);
495 static void netxen_set_multicast_list(struct net_device *dev)
497 struct netxen_adapter *adapter = netdev_priv(dev);
499 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
500 netxen_p3_nic_set_multi(dev);
502 netxen_p2_nic_set_multi(dev);
505 static const struct net_device_ops netxen_netdev_ops = {
506 .ndo_open = netxen_nic_open,
507 .ndo_stop = netxen_nic_close,
508 .ndo_start_xmit = netxen_nic_xmit_frame,
509 .ndo_get_stats = netxen_nic_get_stats,
510 .ndo_validate_addr = eth_validate_addr,
511 .ndo_set_multicast_list = netxen_set_multicast_list,
512 .ndo_set_mac_address = netxen_nic_set_mac,
513 .ndo_change_mtu = netxen_nic_change_mtu,
514 .ndo_tx_timeout = netxen_tx_timeout,
515 #ifdef CONFIG_NET_POLL_CONTROLLER
516 .ndo_poll_controller = netxen_nic_poll_controller,
523 * The Linux system will invoke this after identifying the vendor ID and
524 * device Id in the pci_tbl supported by this module.
526 * A quad port card has one operational PCI config space, (function 0),
527 * which is used to access all four ports.
529 * This routine will initialize the adapter, and setup the global parameters
530 * along with the port's specific structure.
533 netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
535 struct net_device *netdev = NULL;
536 struct netxen_adapter *adapter = NULL;
537 void __iomem *mem_ptr0 = NULL;
538 void __iomem *mem_ptr1 = NULL;
539 void __iomem *mem_ptr2 = NULL;
540 unsigned long first_page_group_end;
541 unsigned long first_page_group_start;
544 u8 __iomem *db_ptr = NULL;
545 unsigned long mem_base, mem_len, db_base, db_len, pci_len0 = 0;
547 int first_driver, first_boot;
549 int pci_func_id = PCI_FUNC(pdev->devfn);
550 struct netxen_legacy_intr_set *legacy_intrp;
553 if (pci_func_id == 0)
554 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
556 if (pdev->class != 0x020000) {
557 printk(KERN_DEBUG "NetXen function %d, class %x will not "
558 "be enabled.\n",pci_func_id, pdev->class);
562 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
563 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
564 "will not be enabled.\n",
569 if ((err = pci_enable_device(pdev)))
572 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
574 goto err_out_disable_pdev;
577 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
578 goto err_out_disable_pdev;
580 pci_set_master(pdev);
582 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
584 printk(KERN_ERR"%s: Failed to allocate memory for the "
585 "device block.Check system memory resource"
586 " usage.\n", netxen_nic_driver_name);
587 goto err_out_free_res;
590 SET_NETDEV_DEV(netdev, &pdev->dev);
592 adapter = netdev_priv(netdev);
593 adapter->netdev = netdev;
594 adapter->pdev = pdev;
595 adapter->ahw.pci_func = pci_func_id;
597 revision_id = pdev->revision;
598 adapter->ahw.revision_id = revision_id;
600 err = nx_set_dma_mask(adapter, revision_id);
602 goto err_out_free_netdev;
604 rwlock_init(&adapter->adapter_lock);
605 adapter->ahw.qdr_sn_window = -1;
606 adapter->ahw.ddr_mn_window = -1;
608 /* remap phys address */
609 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
610 mem_len = pci_resource_len(pdev, 0);
613 adapter->hw_write_wx = netxen_nic_hw_write_wx_128M;
614 adapter->hw_read_wx = netxen_nic_hw_read_wx_128M;
615 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_128M;
616 adapter->pci_write_immediate = netxen_nic_pci_write_immediate_128M;
617 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_128M;
618 adapter->pci_write_normalize = netxen_nic_pci_write_normalize_128M;
619 adapter->pci_set_window = netxen_nic_pci_set_window_128M;
620 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M;
621 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M;
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 first_page_group_start = FIRST_PAGE_GROUP_START;
631 first_page_group_end = FIRST_PAGE_GROUP_END;
632 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
633 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
634 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
635 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
636 first_page_group_start = 0;
637 first_page_group_end = 0;
638 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
639 adapter->hw_write_wx = netxen_nic_hw_write_wx_2M;
640 adapter->hw_read_wx = netxen_nic_hw_read_wx_2M;
641 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_2M;
642 adapter->pci_write_immediate =
643 netxen_nic_pci_write_immediate_2M;
644 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_2M;
645 adapter->pci_write_normalize =
646 netxen_nic_pci_write_normalize_2M;
647 adapter->pci_set_window = netxen_nic_pci_set_window_2M;
648 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M;
649 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M;
651 mem_ptr0 = ioremap(mem_base, mem_len);
653 first_page_group_start = 0;
654 first_page_group_end = 0;
656 adapter->ahw.ddr_mn_window = 0;
657 adapter->ahw.qdr_sn_window = 0;
659 adapter->ahw.mn_win_crb = 0x100000 + PCIX_MN_WINDOW +
660 (pci_func_id * 0x20);
661 adapter->ahw.ms_win_crb = 0x100000 + PCIX_SN_WINDOW;
663 adapter->ahw.ms_win_crb += (pci_func_id * 0x20);
665 adapter->ahw.ms_win_crb +=
666 0xA0 + ((pci_func_id - 4) * 0x10);
669 goto err_out_free_netdev;
672 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
674 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
675 db_len = pci_resource_len(pdev, 4);
678 printk(KERN_ERR "%s: doorbell is disabled\n",
679 netxen_nic_driver_name);
681 goto err_out_iounmap;
683 DPRINTK(INFO, "doorbell ioremap from %lx a size of %lx\n", db_base,
686 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
688 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
689 netxen_nic_driver_name);
691 goto err_out_iounmap;
693 DPRINTK(INFO, "doorbell ioremaped at %p\n", db_ptr);
695 adapter->ahw.pci_base0 = mem_ptr0;
696 adapter->ahw.pci_len0 = pci_len0;
697 adapter->ahw.first_page_group_start = first_page_group_start;
698 adapter->ahw.first_page_group_end = first_page_group_end;
699 adapter->ahw.pci_base1 = mem_ptr1;
700 adapter->ahw.pci_base2 = mem_ptr2;
701 adapter->ahw.db_base = db_ptr;
702 adapter->ahw.db_len = db_len;
704 netif_napi_add(netdev, &adapter->napi,
705 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
707 if (revision_id >= NX_P3_B0)
708 legacy_intrp = &legacy_intr[pci_func_id];
710 legacy_intrp = &legacy_intr[0];
712 adapter->legacy_intr.int_vec_bit = legacy_intrp->int_vec_bit;
713 adapter->legacy_intr.tgt_status_reg = legacy_intrp->tgt_status_reg;
714 adapter->legacy_intr.tgt_mask_reg = legacy_intrp->tgt_mask_reg;
715 adapter->legacy_intr.pci_int_reg = legacy_intrp->pci_int_reg;
717 /* this will be read from FW later */
718 adapter->intr_scheme = -1;
719 adapter->msi_mode = -1;
721 /* This will be reset for mezz cards */
722 adapter->portnum = pci_func_id;
723 adapter->status &= ~NETXEN_NETDEV_STATUS;
724 adapter->rx_csum = 1;
725 adapter->mc_enabled = 0;
726 if (NX_IS_REVISION_P3(revision_id))
727 adapter->max_mc_count = 38;
729 adapter->max_mc_count = 16;
731 netdev->netdev_ops = &netxen_netdev_ops;
732 netdev->watchdog_timeo = 2*HZ;
734 netxen_nic_change_mtu(netdev, netdev->mtu);
736 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
738 /* ScatterGather support */
739 netdev->features = NETIF_F_SG;
740 netdev->features |= NETIF_F_IP_CSUM;
741 netdev->features |= NETIF_F_TSO;
742 if (NX_IS_REVISION_P3(revision_id)) {
743 netdev->features |= NETIF_F_IPV6_CSUM;
744 netdev->features |= NETIF_F_TSO6;
747 if (adapter->pci_using_dac)
748 netdev->features |= NETIF_F_HIGHDMA;
751 * Set the CRB window to invalid. If any register in window 0 is
752 * accessed it should set the window to 0 and then reset it to 1.
754 adapter->curr_window = 255;
756 if (netxen_nic_get_board_info(adapter) != 0) {
757 printk("%s: Error getting board config info.\n",
758 netxen_nic_driver_name);
760 goto err_out_iounmap;
763 netxen_initialize_adapter_ops(adapter);
765 /* Mezz cards have PCI function 0,2,3 enabled */
766 switch (adapter->ahw.boardcfg.board_type) {
767 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
768 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
769 if (pci_func_id >= 2)
770 adapter->portnum = pci_func_id - 2;
777 * This call will setup various max rx/tx counts.
778 * It must be done before any buffer/ring allocations.
780 netxen_check_options(adapter);
783 if (NX_IS_REVISION_P3(revision_id)) {
784 if (adapter->ahw.pci_func == 0)
787 if (adapter->portnum == 0)
792 first_boot = adapter->pci_read_normalize(adapter,
793 NETXEN_CAM_RAM(0x1fc));
795 err = netxen_check_hw_init(adapter, first_boot);
797 printk(KERN_ERR "%s: error in init HW init sequence\n",
798 netxen_nic_driver_name);
799 goto err_out_iounmap;
802 if (NX_IS_REVISION_P3(revision_id))
803 netxen_set_port_mode(adapter);
805 if (first_boot != 0x55555555) {
806 adapter->pci_write_normalize(adapter,
807 CRB_CMDPEG_STATE, 0);
808 netxen_pinit_from_rom(adapter, 0);
811 netxen_load_firmware(adapter);
813 if (NX_IS_REVISION_P3(revision_id))
814 netxen_pcie_strap_init(adapter);
816 if (NX_IS_REVISION_P2(revision_id)) {
818 /* Initialize multicast addr pool owners */
820 if (adapter->ahw.board_type == NETXEN_NIC_XGBE)
822 netxen_crb_writelit_adapter(adapter,
823 NETXEN_MAC_ADDR_CNTL_REG, val);
827 err = netxen_initialize_adapter_offload(adapter);
829 goto err_out_iounmap;
832 * Tell the hardware our version number.
834 i = (_NETXEN_NIC_LINUX_MAJOR << 16)
835 | ((_NETXEN_NIC_LINUX_MINOR << 8))
836 | (_NETXEN_NIC_LINUX_SUBVERSION);
837 adapter->pci_write_normalize(adapter, CRB_DRIVER_VERSION, i);
839 /* Handshake with the card before we register the devices. */
840 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
842 goto err_out_free_offload;
846 netxen_nic_flash_print(adapter);
848 if (NX_IS_REVISION_P3(revision_id)) {
849 adapter->hw_read_wx(adapter,
850 NETXEN_MIU_MN_CONTROL, &val, 4);
851 adapter->ahw.cut_through = (val & 0x4) ? 1 : 0;
852 dev_info(&pdev->dev, "firmware running in %s mode\n",
853 adapter->ahw.cut_through ? "cut through" : "legacy");
857 * See if the firmware gave us a virtual-physical port mapping.
859 adapter->physical_port = adapter->portnum;
860 i = adapter->pci_read_normalize(adapter, CRB_V2P(adapter->portnum));
862 adapter->physical_port = i;
864 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
866 netxen_set_msix_bit(pdev, 0);
868 if (NX_IS_REVISION_P3(revision_id)) {
869 if ((mem_len != NETXEN_PCI_128MB_SIZE) &&
870 mem_len != NETXEN_PCI_2MB_SIZE)
871 adapter->msix_supported = 0;
874 if (adapter->msix_supported) {
876 netxen_init_msix_entries(adapter);
878 if (pci_enable_msix(pdev, adapter->msix_entries,
879 MSIX_ENTRIES_PER_ADAPTER))
882 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
883 netxen_set_msix_bit(pdev, 1);
884 dev_info(&pdev->dev, "using msi-x interrupts\n");
888 if (use_msi && !pci_enable_msi(pdev)) {
889 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
890 dev_info(&pdev->dev, "using msi interrupts\n");
892 dev_info(&pdev->dev, "using legacy interrupts\n");
895 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
896 netdev->irq = adapter->msix_entries[0].vector;
898 netdev->irq = pdev->irq;
900 err = netxen_receive_peg_ready(adapter);
902 goto err_out_disable_msi;
904 init_timer(&adapter->watchdog_timer);
905 adapter->watchdog_timer.function = &netxen_watchdog;
906 adapter->watchdog_timer.data = (unsigned long)adapter;
907 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
908 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
910 err = netxen_read_mac_addr(adapter);
912 dev_warn(&pdev->dev, "failed to read mac addr\n");
914 netif_carrier_off(netdev);
915 netif_stop_queue(netdev);
917 if ((err = register_netdev(netdev))) {
918 printk(KERN_ERR "%s: register_netdev failed port #%d"
919 " aborting\n", netxen_nic_driver_name,
922 goto err_out_disable_msi;
925 pci_set_drvdata(pdev, adapter);
927 switch (adapter->ahw.board_type) {
929 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
930 adapter->netdev->name);
932 case NETXEN_NIC_XGBE:
933 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
934 adapter->netdev->name);
941 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
942 pci_disable_msix(pdev);
943 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
944 pci_disable_msi(pdev);
946 err_out_free_offload:
948 netxen_free_adapter_offload(adapter);
965 pci_release_regions(pdev);
967 err_out_disable_pdev:
968 pci_set_drvdata(pdev, NULL);
969 pci_disable_device(pdev);
973 static void __devexit netxen_nic_remove(struct pci_dev *pdev)
975 struct netxen_adapter *adapter;
976 struct net_device *netdev;
978 adapter = pci_get_drvdata(pdev);
982 netdev = adapter->netdev;
984 unregister_netdev(netdev);
986 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
987 netxen_free_hw_resources(adapter);
988 netxen_release_rx_buffers(adapter);
989 netxen_free_sw_resources(adapter);
991 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
992 netxen_p3_free_mac_list(adapter);
995 if (adapter->portnum == 0)
996 netxen_free_adapter_offload(adapter);
999 free_irq(adapter->irq, adapter);
1001 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
1002 pci_disable_msix(pdev);
1003 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
1004 pci_disable_msi(pdev);
1006 iounmap(adapter->ahw.db_base);
1007 iounmap(adapter->ahw.pci_base0);
1008 if (adapter->ahw.pci_base1 != NULL)
1009 iounmap(adapter->ahw.pci_base1);
1010 if (adapter->ahw.pci_base2 != NULL)
1011 iounmap(adapter->ahw.pci_base2);
1013 pci_release_regions(pdev);
1014 pci_disable_device(pdev);
1015 pci_set_drvdata(pdev, NULL);
1017 free_netdev(netdev);
1021 * Called when a network interface is made active
1022 * @returns 0 on success, negative value on failure
1024 static int netxen_nic_open(struct net_device *netdev)
1026 struct netxen_adapter *adapter = netdev_priv(netdev);
1029 irq_handler_t handler;
1030 unsigned long flags = IRQF_SAMPLE_RANDOM;
1032 if (adapter->driver_mismatch)
1035 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) {
1036 err = netxen_init_firmware(adapter);
1038 printk(KERN_ERR "Failed to init firmware\n");
1042 if (adapter->fw_major < 4)
1043 adapter->max_rds_rings = 3;
1045 adapter->max_rds_rings = 2;
1047 err = netxen_alloc_sw_resources(adapter);
1049 printk(KERN_ERR "%s: Error in setting sw resources\n",
1054 netxen_nic_clear_stats(adapter);
1056 err = netxen_alloc_hw_resources(adapter);
1058 printk(KERN_ERR "%s: Error in setting hw resources\n",
1060 goto err_out_free_sw;
1063 if ((adapter->msi_mode != MSI_MODE_MULTIFUNC) ||
1064 (adapter->intr_scheme != INTR_SCHEME_PERPORT)) {
1065 printk(KERN_ERR "%s: Firmware interrupt scheme is "
1066 "incompatible with driver\n",
1068 adapter->driver_mismatch = 1;
1069 goto err_out_free_hw;
1072 if (adapter->fw_major < 4) {
1073 adapter->crb_addr_cmd_producer =
1074 crb_cmd_producer[adapter->portnum];
1075 adapter->crb_addr_cmd_consumer =
1076 crb_cmd_consumer[adapter->portnum];
1078 netxen_nic_update_cmd_producer(adapter, 0);
1079 netxen_nic_update_cmd_consumer(adapter, 0);
1082 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
1083 for (ring = 0; ring < adapter->max_rds_rings; ring++)
1084 netxen_post_rx_buffers(adapter, ctx, ring);
1086 if (NETXEN_IS_MSI_FAMILY(adapter))
1087 handler = netxen_msi_intr;
1089 flags |= IRQF_SHARED;
1090 handler = netxen_intr;
1092 adapter->irq = netdev->irq;
1093 err = request_irq(adapter->irq, handler,
1094 flags, netdev->name, adapter);
1096 printk(KERN_ERR "request_irq failed with: %d\n", err);
1097 goto err_out_free_rxbuf;
1100 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1103 /* Done here again so that even if phantom sw overwrote it,
1105 err = adapter->init_port(adapter, adapter->physical_port);
1107 printk(KERN_ERR "%s: Failed to initialize port %d\n",
1108 netxen_nic_driver_name, adapter->portnum);
1109 goto err_out_free_irq;
1111 adapter->macaddr_set(adapter, netdev->dev_addr);
1113 netxen_nic_set_link_parameters(adapter);
1115 netxen_set_multicast_list(netdev);
1116 if (adapter->set_mtu)
1117 adapter->set_mtu(adapter, netdev->mtu);
1119 adapter->ahw.linkup = 0;
1120 mod_timer(&adapter->watchdog_timer, jiffies);
1122 napi_enable(&adapter->napi);
1123 netxen_nic_enable_int(adapter);
1125 netif_start_queue(netdev);
1130 free_irq(adapter->irq, adapter);
1132 netxen_release_rx_buffers(adapter);
1134 netxen_free_hw_resources(adapter);
1136 netxen_free_sw_resources(adapter);
1141 * netxen_nic_close - Disables a network interface entry point
1143 static int netxen_nic_close(struct net_device *netdev)
1145 struct netxen_adapter *adapter = netdev_priv(netdev);
1147 netif_carrier_off(netdev);
1148 netif_stop_queue(netdev);
1149 napi_disable(&adapter->napi);
1151 if (adapter->stop_port)
1152 adapter->stop_port(adapter);
1154 netxen_nic_disable_int(adapter);
1156 netxen_release_tx_buffers(adapter);
1158 FLUSH_SCHEDULED_WORK();
1159 del_timer_sync(&adapter->watchdog_timer);
1164 static bool netxen_tso_check(struct net_device *netdev,
1165 struct cmd_desc_type0 *desc, struct sk_buff *skb)
1168 u8 opcode = TX_ETHER_PKT;
1170 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1171 skb_shinfo(skb)->gso_size > 0) {
1173 desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1174 desc->total_hdr_length =
1175 skb_transport_offset(skb) + tcp_hdrlen(skb);
1177 opcode = (skb->protocol == htons(ETH_P_IPV6)) ?
1178 TX_TCP_LSO6 : TX_TCP_LSO;
1181 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
1184 if (skb->protocol == htons(ETH_P_IP)) {
1185 l4proto = ip_hdr(skb)->protocol;
1187 if (l4proto == IPPROTO_TCP)
1188 opcode = TX_TCP_PKT;
1189 else if(l4proto == IPPROTO_UDP)
1190 opcode = TX_UDP_PKT;
1191 } else if (skb->protocol == htons(ETH_P_IPV6)) {
1192 l4proto = ipv6_hdr(skb)->nexthdr;
1194 if (l4proto == IPPROTO_TCP)
1195 opcode = TX_TCPV6_PKT;
1196 else if(l4proto == IPPROTO_UDP)
1197 opcode = TX_UDPV6_PKT;
1200 desc->tcp_hdr_offset = skb_transport_offset(skb);
1201 desc->ip_hdr_offset = skb_network_offset(skb);
1202 netxen_set_tx_flags_opcode(desc, 0, opcode);
1207 netxen_clean_tx_dma_mapping(struct pci_dev *pdev,
1208 struct netxen_cmd_buffer *pbuf, int last)
1211 struct netxen_skb_frag *buffrag;
1213 buffrag = &pbuf->frag_array[0];
1214 pci_unmap_single(pdev, buffrag->dma,
1215 buffrag->length, PCI_DMA_TODEVICE);
1217 for (k = 1; k < last; k++) {
1218 buffrag = &pbuf->frag_array[k];
1219 pci_unmap_page(pdev, buffrag->dma,
1220 buffrag->length, PCI_DMA_TODEVICE);
1224 static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1226 struct netxen_adapter *adapter = netdev_priv(netdev);
1227 struct netxen_hardware_context *hw = &adapter->ahw;
1228 unsigned int first_seg_len = skb->len - skb->data_len;
1229 struct netxen_cmd_buffer *pbuf;
1230 struct netxen_skb_frag *buffrag;
1231 struct cmd_desc_type0 *hwdesc;
1232 struct pci_dev *pdev = adapter->pdev;
1233 dma_addr_t temp_dma;
1236 u32 producer, consumer;
1237 int frag_count, no_of_desc;
1238 u32 num_txd = adapter->max_tx_desc_count;
1239 bool is_tso = false;
1241 frag_count = skb_shinfo(skb)->nr_frags + 1;
1243 /* There 4 fragments per descriptor */
1244 no_of_desc = (frag_count + 3) >> 2;
1246 producer = adapter->cmd_producer;
1248 consumer = adapter->last_cmd_consumer;
1249 if ((no_of_desc+2) > find_diff_among(producer, consumer, num_txd)) {
1250 netif_stop_queue(netdev);
1252 return NETDEV_TX_BUSY;
1255 /* Copy the descriptors into the hardware */
1256 hwdesc = &hw->cmd_desc_head[producer];
1257 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
1258 /* Take skb->data itself */
1259 pbuf = &adapter->cmd_buf_arr[producer];
1261 is_tso = netxen_tso_check(netdev, hwdesc, skb);
1264 pbuf->frag_count = frag_count;
1265 buffrag = &pbuf->frag_array[0];
1266 temp_dma = pci_map_single(pdev, skb->data, first_seg_len,
1268 if (pci_dma_mapping_error(pdev, temp_dma))
1271 buffrag->dma = temp_dma;
1272 buffrag->length = first_seg_len;
1273 netxen_set_tx_frags_len(hwdesc, frag_count, skb->len);
1274 netxen_set_tx_port(hwdesc, adapter->portnum);
1276 hwdesc->buffer1_length = cpu_to_le16(first_seg_len);
1277 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
1279 for (i = 1, k = 1; i < frag_count; i++, k++) {
1280 struct skb_frag_struct *frag;
1282 unsigned long offset;
1284 /* move to next desc. if there is a need */
1285 if ((i & 0x3) == 0) {
1287 producer = get_next_index(producer, num_txd);
1288 hwdesc = &hw->cmd_desc_head[producer];
1289 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
1290 pbuf = &adapter->cmd_buf_arr[producer];
1293 frag = &skb_shinfo(skb)->frags[i - 1];
1295 offset = frag->page_offset;
1298 temp_dma = pci_map_page(pdev, frag->page, offset,
1299 len, PCI_DMA_TODEVICE);
1300 if (pci_dma_mapping_error(pdev, temp_dma)) {
1301 netxen_clean_tx_dma_mapping(pdev, pbuf, i);
1306 buffrag->dma = temp_dma;
1307 buffrag->length = temp_len;
1311 hwdesc->buffer1_length = cpu_to_le16(temp_len);
1312 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
1315 hwdesc->buffer2_length = cpu_to_le16(temp_len);
1316 hwdesc->addr_buffer2 = cpu_to_le64(temp_dma);
1319 hwdesc->buffer3_length = cpu_to_le16(temp_len);
1320 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
1323 hwdesc->buffer4_length = cpu_to_le16(temp_len);
1324 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
1329 producer = get_next_index(producer, num_txd);
1331 /* For LSO, we need to copy the MAC/IP/TCP headers into
1332 * the descriptor ring
1335 int hdr_len, first_hdr_len, more_hdr;
1336 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1337 if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) {
1338 first_hdr_len = sizeof(struct cmd_desc_type0) - 2;
1341 first_hdr_len = hdr_len;
1344 /* copy the MAC/IP/TCP headers to the cmd descriptor list */
1345 hwdesc = &hw->cmd_desc_head[producer];
1346 pbuf = &adapter->cmd_buf_arr[producer];
1349 /* copy the first 64 bytes */
1350 memcpy(((void *)hwdesc) + 2,
1351 (void *)(skb->data), first_hdr_len);
1352 producer = get_next_index(producer, num_txd);
1355 hwdesc = &hw->cmd_desc_head[producer];
1356 pbuf = &adapter->cmd_buf_arr[producer];
1358 /* copy the next 64 bytes - should be enough except
1359 * for pathological case
1361 skb_copy_from_linear_data_offset(skb, first_hdr_len,
1365 producer = get_next_index(producer, num_txd);
1369 adapter->cmd_producer = producer;
1370 adapter->stats.txbytes += skb->len;
1372 netxen_nic_update_cmd_producer(adapter, adapter->cmd_producer);
1374 adapter->stats.xmitcalled++;
1375 netdev->trans_start = jiffies;
1377 return NETDEV_TX_OK;
1380 adapter->stats.txdropped++;
1381 dev_kfree_skb_any(skb);
1382 return NETDEV_TX_OK;
1385 static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1387 struct net_device *netdev = adapter->netdev;
1388 uint32_t temp, temp_state, temp_val;
1391 temp = adapter->pci_read_normalize(adapter, CRB_TEMP_STATE);
1393 temp_state = nx_get_temp_state(temp);
1394 temp_val = nx_get_temp_val(temp);
1396 if (temp_state == NX_TEMP_PANIC) {
1398 "%s: Device temperature %d degrees C exceeds"
1399 " maximum allowed. Hardware has been shut down.\n",
1400 netxen_nic_driver_name, temp_val);
1402 netif_carrier_off(netdev);
1403 netif_stop_queue(netdev);
1405 } else if (temp_state == NX_TEMP_WARN) {
1406 if (adapter->temp == NX_TEMP_NORMAL) {
1408 "%s: Device temperature %d degrees C "
1409 "exceeds operating range."
1410 " Immediate action needed.\n",
1411 netxen_nic_driver_name, temp_val);
1414 if (adapter->temp == NX_TEMP_WARN) {
1416 "%s: Device temperature is now %d degrees C"
1417 " in normal range.\n", netxen_nic_driver_name,
1421 adapter->temp = temp_state;
1425 static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1427 struct net_device *netdev = adapter->netdev;
1428 u32 val, port, linkup;
1430 port = adapter->physical_port;
1432 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1433 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE_P3);
1434 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1435 linkup = (val == XG_LINK_UP_P3);
1437 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
1438 if (adapter->ahw.board_type == NETXEN_NIC_GBE)
1439 linkup = (val >> port) & 1;
1441 val = (val >> port*8) & 0xff;
1442 linkup = (val == XG_LINK_UP);
1446 if (adapter->ahw.linkup && !linkup) {
1447 printk(KERN_INFO "%s: %s NIC Link is down\n",
1448 netxen_nic_driver_name, netdev->name);
1449 adapter->ahw.linkup = 0;
1450 if (netif_running(netdev)) {
1451 netif_carrier_off(netdev);
1452 netif_stop_queue(netdev);
1455 netxen_nic_set_link_parameters(adapter);
1456 } else if (!adapter->ahw.linkup && linkup) {
1457 printk(KERN_INFO "%s: %s NIC Link is up\n",
1458 netxen_nic_driver_name, netdev->name);
1459 adapter->ahw.linkup = 1;
1460 if (netif_running(netdev)) {
1461 netif_carrier_on(netdev);
1462 netif_wake_queue(netdev);
1465 netxen_nic_set_link_parameters(adapter);
1469 static void netxen_watchdog(unsigned long v)
1471 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
1473 SCHEDULE_WORK(&adapter->watchdog_task);
1476 void netxen_watchdog_task(struct work_struct *work)
1478 struct netxen_adapter *adapter =
1479 container_of(work, struct netxen_adapter, watchdog_task);
1481 if ((adapter->portnum == 0) && netxen_nic_check_temp(adapter))
1484 netxen_nic_handle_phy_intr(adapter);
1486 if (netif_running(adapter->netdev))
1487 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1490 static void netxen_tx_timeout(struct net_device *netdev)
1492 struct netxen_adapter *adapter = (struct netxen_adapter *)
1493 netdev_priv(netdev);
1494 SCHEDULE_WORK(&adapter->tx_timeout_task);
1497 static void netxen_tx_timeout_task(struct work_struct *work)
1499 struct netxen_adapter *adapter =
1500 container_of(work, struct netxen_adapter, tx_timeout_task);
1502 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
1503 netxen_nic_driver_name, adapter->netdev->name);
1505 netxen_nic_disable_int(adapter);
1506 napi_disable(&adapter->napi);
1508 adapter->netdev->trans_start = jiffies;
1510 napi_enable(&adapter->napi);
1511 netxen_nic_enable_int(adapter);
1512 netif_wake_queue(adapter->netdev);
1516 * netxen_nic_get_stats - Get System Network Statistics
1517 * @netdev: network interface device structure
1519 struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1521 struct netxen_adapter *adapter = netdev_priv(netdev);
1522 struct net_device_stats *stats = &adapter->net_stats;
1524 memset(stats, 0, sizeof(*stats));
1526 /* total packets received */
1527 stats->rx_packets = adapter->stats.no_rcv;
1528 /* total packets transmitted */
1529 stats->tx_packets = adapter->stats.xmitedframes +
1530 adapter->stats.xmitfinished;
1531 /* total bytes received */
1532 stats->rx_bytes = adapter->stats.rxbytes;
1533 /* total bytes transmitted */
1534 stats->tx_bytes = adapter->stats.txbytes;
1535 /* bad packets received */
1536 stats->rx_errors = adapter->stats.rcvdbadskb;
1537 /* packet transmit problems */
1538 stats->tx_errors = adapter->stats.nocmddescriptor;
1539 /* no space in linux buffers */
1540 stats->rx_dropped = adapter->stats.rxdropped;
1541 /* no space available in linux */
1542 stats->tx_dropped = adapter->stats.txdropped;
1547 static irqreturn_t netxen_intr(int irq, void *data)
1549 struct netxen_adapter *adapter = data;
1552 status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1554 if (!(status & adapter->legacy_intr.int_vec_bit))
1557 if (adapter->ahw.revision_id >= NX_P3_B1) {
1558 /* check interrupt state machine, to be sure */
1559 status = adapter->pci_read_immediate(adapter,
1561 if (!ISR_LEGACY_INT_TRIGGERED(status))
1565 unsigned long our_int = 0;
1567 our_int = adapter->pci_read_normalize(adapter, CRB_INT_VECTOR);
1569 /* not our interrupt */
1570 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
1573 /* claim interrupt */
1574 adapter->pci_write_normalize(adapter,
1575 CRB_INT_VECTOR, (our_int & 0xffffffff));
1578 /* clear interrupt */
1579 if (adapter->fw_major < 4)
1580 netxen_nic_disable_int(adapter);
1582 adapter->pci_write_immediate(adapter,
1583 adapter->legacy_intr.tgt_status_reg,
1585 /* read twice to ensure write is flushed */
1586 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1587 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1589 napi_schedule(&adapter->napi);
1594 static irqreturn_t netxen_msi_intr(int irq, void *data)
1596 struct netxen_adapter *adapter = data;
1598 /* clear interrupt */
1599 adapter->pci_write_immediate(adapter,
1600 msi_tgt_status[adapter->ahw.pci_func], 0xffffffff);
1602 napi_schedule(&adapter->napi);
1606 static int netxen_nic_poll(struct napi_struct *napi, int budget)
1608 struct netxen_adapter *adapter = container_of(napi, struct netxen_adapter, napi);
1613 tx_complete = netxen_process_cmd_ring(adapter);
1616 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
1618 * Fairness issue. This will give undue weight to the
1619 * receive context 0.
1623 * To avoid starvation, we give each of our receivers,
1624 * a fraction of the quota. Sometimes, it might happen that we
1625 * have enough quota to process every packet, but since all the
1626 * packets are on one context, it gets only half of the quota,
1627 * and ends up not processing it.
1629 work_done += netxen_process_rcv_ring(adapter, ctx,
1630 budget / MAX_RCV_CTX);
1633 if ((work_done < budget) && tx_complete) {
1634 napi_complete(&adapter->napi);
1635 netxen_nic_enable_int(adapter);
1641 #ifdef CONFIG_NET_POLL_CONTROLLER
1642 static void netxen_nic_poll_controller(struct net_device *netdev)
1644 struct netxen_adapter *adapter = netdev_priv(netdev);
1645 disable_irq(adapter->irq);
1646 netxen_intr(adapter->irq, adapter);
1647 enable_irq(adapter->irq);
1651 static struct pci_driver netxen_driver = {
1652 .name = netxen_nic_driver_name,
1653 .id_table = netxen_pci_tbl,
1654 .probe = netxen_nic_probe,
1655 .remove = __devexit_p(netxen_nic_remove)
1658 /* Driver Registration on NetXen card */
1660 static int __init netxen_init_module(void)
1662 if ((netxen_workq = create_singlethread_workqueue("netxen")) == NULL)
1665 return pci_register_driver(&netxen_driver);
1668 module_init(netxen_init_module);
1670 static void __exit netxen_exit_module(void)
1672 pci_unregister_driver(&netxen_driver);
1673 destroy_workqueue(netxen_workq);
1676 module_exit(netxen_exit_module);