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>
44 MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
45 MODULE_LICENSE("GPL");
46 MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
48 char netxen_nic_driver_name[] = "netxen_nic";
49 static char netxen_nic_driver_string[] = "NetXen Network Driver version "
50 NETXEN_NIC_LINUX_VERSIONID;
52 static int port_mode = NETXEN_PORT_MODE_AUTO_NEG;
54 /* Default to restricted 1G auto-neg mode */
55 static int wol_port_mode = 5;
57 static int use_msi = 1;
59 static int use_msi_x = 1;
61 /* Local functions to NetXen NIC driver */
62 static int __devinit netxen_nic_probe(struct pci_dev *pdev,
63 const struct pci_device_id *ent);
64 static void __devexit netxen_nic_remove(struct pci_dev *pdev);
65 static int netxen_nic_open(struct net_device *netdev);
66 static int netxen_nic_close(struct net_device *netdev);
67 static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *);
68 static void netxen_tx_timeout(struct net_device *netdev);
69 static void netxen_tx_timeout_task(struct work_struct *work);
70 static void netxen_watchdog(unsigned long);
71 static int netxen_nic_poll(struct napi_struct *napi, int budget);
72 #ifdef CONFIG_NET_POLL_CONTROLLER
73 static void netxen_nic_poll_controller(struct net_device *netdev);
75 static irqreturn_t netxen_intr(int irq, void *data);
76 static irqreturn_t netxen_msi_intr(int irq, void *data);
78 /* PCI Device ID Table */
79 #define ENTRY(device) \
80 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
81 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
83 static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
84 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR),
85 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4),
86 ENTRY(PCI_DEVICE_ID_NX2031_4GCU),
87 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ),
88 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ),
89 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT),
90 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2),
91 ENTRY(PCI_DEVICE_ID_NX3031),
95 MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
98 * In netxen_nic_down(), we must wait for any pending callback requests into
99 * netxen_watchdog_task() to complete; eg otherwise the watchdog_timer could be
100 * reenabled right after it is deleted in netxen_nic_down().
101 * FLUSH_SCHEDULED_WORK() does this synchronization.
103 * Normally, schedule_work()/flush_scheduled_work() could have worked, but
104 * netxen_nic_close() is invoked with kernel rtnl lock held. netif_carrier_off()
105 * call in netxen_nic_close() triggers a schedule_work(&linkwatch_work), and a
106 * subsequent call to flush_scheduled_work() in netxen_nic_down() would cause
107 * linkwatch_event() to be executed which also attempts to acquire the rtnl
108 * lock thus causing a deadlock.
111 static struct workqueue_struct *netxen_workq;
112 #define SCHEDULE_WORK(tp) queue_work(netxen_workq, tp)
113 #define FLUSH_SCHEDULED_WORK() flush_workqueue(netxen_workq)
115 static void netxen_watchdog(unsigned long);
117 static uint32_t crb_cmd_producer[4] = {
118 CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1,
119 CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3
123 netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
124 uint32_t crb_producer)
126 adapter->pci_write_normalize(adapter,
127 adapter->crb_addr_cmd_producer, crb_producer);
130 static uint32_t crb_cmd_consumer[4] = {
131 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
132 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
136 netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
139 adapter->pci_write_normalize(adapter,
140 adapter->crb_addr_cmd_consumer, crb_consumer);
143 static uint32_t msi_tgt_status[8] = {
144 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
145 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
146 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
147 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
150 static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
152 static inline void netxen_nic_disable_int(struct netxen_adapter *adapter)
154 adapter->pci_write_normalize(adapter, adapter->crb_intr_mask, 0);
157 static inline void netxen_nic_enable_int(struct netxen_adapter *adapter)
159 adapter->pci_write_normalize(adapter, adapter->crb_intr_mask, 0x1);
161 if (!NETXEN_IS_MSI_FAMILY(adapter))
162 adapter->pci_write_immediate(adapter,
163 adapter->legacy_intr.tgt_mask_reg, 0xfbff);
166 static int nx_set_dma_mask(struct netxen_adapter *adapter, uint8_t revision_id)
168 struct pci_dev *pdev = adapter->pdev;
173 adapter->dma_mask = DMA_32BIT_MASK;
175 if (revision_id >= NX_P3_B0) {
176 /* should go to DMA_64BIT_MASK */
177 adapter->dma_mask = DMA_39BIT_MASK;
178 mask = DMA_39BIT_MASK;
179 } else if (revision_id == NX_P3_A2) {
180 adapter->dma_mask = DMA_39BIT_MASK;
181 mask = DMA_39BIT_MASK;
182 } else if (revision_id == NX_P2_C1) {
183 adapter->dma_mask = DMA_35BIT_MASK;
184 mask = DMA_35BIT_MASK;
186 adapter->dma_mask = DMA_32BIT_MASK;
187 mask = DMA_32BIT_MASK;
188 goto set_32_bit_mask;
192 * Consistent DMA mask is set to 32 bit because it cannot be set to
193 * 35 bits. For P3 also leave it at 32 bits for now. Only the rings
194 * come off this pool.
196 if (pci_set_dma_mask(pdev, mask) == 0 &&
197 pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK) == 0) {
198 adapter->pci_using_dac = 1;
201 #endif /* CONFIG_IA64 */
204 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
206 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
208 DPRINTK(ERR, "No usable DMA configuration, aborting:%d\n", err);
212 adapter->pci_using_dac = 0;
216 static void netxen_check_options(struct netxen_adapter *adapter)
218 switch (adapter->ahw.boardcfg.board_type) {
219 case NETXEN_BRDTYPE_P3_HMEZ:
220 case NETXEN_BRDTYPE_P3_XG_LOM:
221 case NETXEN_BRDTYPE_P3_10G_CX4:
222 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
223 case NETXEN_BRDTYPE_P3_IMEZ:
224 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
225 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
226 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
227 case NETXEN_BRDTYPE_P3_10G_XFP:
228 case NETXEN_BRDTYPE_P3_10000_BASE_T:
229 adapter->msix_supported = !!use_msi_x;
230 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
233 case NETXEN_BRDTYPE_P2_SB31_10G:
234 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
235 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
236 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
237 adapter->msix_supported = 0;
238 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
241 case NETXEN_BRDTYPE_P3_REF_QG:
242 case NETXEN_BRDTYPE_P3_4_GB:
243 case NETXEN_BRDTYPE_P3_4_GB_MM:
244 adapter->msix_supported = !!use_msi_x;
245 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
248 case NETXEN_BRDTYPE_P2_SB35_4G:
249 case NETXEN_BRDTYPE_P2_SB31_2G:
250 adapter->msix_supported = 0;
251 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
255 adapter->msix_supported = 0;
256 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
258 printk(KERN_WARNING "Unknown board type(0x%x)\n",
259 adapter->ahw.boardcfg.board_type);
263 adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS_HOST;
264 adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS;
265 adapter->max_lro_rx_desc_count = MAX_LRO_RCV_DESCRIPTORS;
267 adapter->max_possible_rss_rings = 1;
272 netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
276 if (first_boot == 0x55555555) {
277 /* This is the first boot after power up */
279 /* PCI bus master workaround */
280 adapter->hw_read_wx(adapter,
281 NETXEN_PCIE_REG(0x4), &first_boot, 4);
282 if (!(first_boot & 0x4)) {
284 adapter->hw_write_wx(adapter,
285 NETXEN_PCIE_REG(0x4), &first_boot, 4);
286 adapter->hw_read_wx(adapter,
287 NETXEN_PCIE_REG(0x4), &first_boot, 4);
290 /* This is the first boot after power up */
291 adapter->hw_read_wx(adapter,
292 NETXEN_ROMUSB_GLB_SW_RESET, &first_boot, 4);
293 if (first_boot != 0x80000f) {
294 /* clear the register for future unloads/loads */
295 adapter->pci_write_normalize(adapter,
296 NETXEN_CAM_RAM(0x1fc), 0);
300 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
301 /* Start P2 boot loader */
302 adapter->pci_write_normalize(adapter,
303 NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
304 adapter->pci_write_normalize(adapter,
305 NETXEN_ROMUSB_GLB_PEGTUNE_DONE, 1);
311 static void netxen_set_port_mode(struct netxen_adapter *adapter)
315 val = adapter->ahw.boardcfg.board_type;
316 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
317 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
318 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
319 data = NETXEN_PORT_MODE_802_3_AP;
320 adapter->hw_write_wx(adapter,
321 NETXEN_PORT_MODE_ADDR, &data, 4);
322 } else if (port_mode == NETXEN_PORT_MODE_XG) {
323 data = NETXEN_PORT_MODE_XG;
324 adapter->hw_write_wx(adapter,
325 NETXEN_PORT_MODE_ADDR, &data, 4);
326 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
327 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
328 adapter->hw_write_wx(adapter,
329 NETXEN_PORT_MODE_ADDR, &data, 4);
330 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
331 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
332 adapter->hw_write_wx(adapter,
333 NETXEN_PORT_MODE_ADDR, &data, 4);
335 data = NETXEN_PORT_MODE_AUTO_NEG;
336 adapter->hw_write_wx(adapter,
337 NETXEN_PORT_MODE_ADDR, &data, 4);
340 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
341 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
342 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
343 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
344 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
346 adapter->hw_write_wx(adapter, NETXEN_WOL_PORT_MODE,
351 #define PCI_CAP_ID_GEN 0x10
353 static void netxen_pcie_strap_init(struct netxen_adapter *adapter)
360 struct pci_dev *pdev;
362 pdev = adapter->pdev;
364 adapter->hw_read_wx(adapter,
365 NETXEN_PCIE_REG(PCIE_CHICKEN3), &chicken, 4);
366 /* clear chicken3.25:24 */
367 chicken &= 0xFCFFFFFF;
369 * if gen1 and B0, set F1020 - if gen 2, do nothing
370 * if gen2 set to F1000
372 pos = pci_find_capability(pdev, PCI_CAP_ID_GEN);
374 pci_read_config_dword(pdev, pos + 0x10, &control);
375 if ((control & 0x000F0000) != 0x00020000) {
376 /* set chicken3.24 if gen1 */
377 chicken |= 0x01000000;
379 printk(KERN_INFO "%s Gen2 strapping detected\n",
380 netxen_nic_driver_name);
383 /* set chicken3.24 if gen1 */
384 chicken |= 0x01000000;
385 printk(KERN_INFO "%s Gen1 strapping detected\n",
386 netxen_nic_driver_name);
387 if (adapter->ahw.revision_id == NX_P3_B0)
393 adapter->hw_write_wx(adapter,
394 NETXEN_PCIE_REG(PCIE_CHICKEN3), &chicken, 4);
399 pdevfuncsave = pdev->devfn;
400 if (pdevfuncsave & 0x07)
403 for (i = 0; i < 8; i++) {
404 pci_read_config_dword(pdev, pos + 8, &control);
405 pci_read_config_dword(pdev, pos + 8, &control);
406 pci_write_config_dword(pdev, pos + 8, c8c9value);
409 pdev->devfn = pdevfuncsave;
412 static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
417 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
419 pci_read_config_dword(pdev, pos, &control);
421 control |= PCI_MSIX_FLAGS_ENABLE;
424 pci_write_config_dword(pdev, pos, control);
428 static void netxen_init_msix_entries(struct netxen_adapter *adapter)
432 for (i = 0; i < MSIX_ENTRIES_PER_ADAPTER; i++)
433 adapter->msix_entries[i].entry = i;
437 netxen_read_mac_addr(struct netxen_adapter *adapter)
442 struct net_device *netdev = adapter->netdev;
443 struct pci_dev *pdev = adapter->pdev;
445 if (netxen_is_flash_supported(adapter) != 0)
448 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
449 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
452 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
456 p = (unsigned char *)&mac_addr;
457 for (i = 0; i < 6; i++)
458 netdev->dev_addr[i] = *(p + 5 - i);
460 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
462 /* set station address */
464 if (!is_valid_ether_addr(netdev->perm_addr))
465 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
467 adapter->macaddr_set(adapter, netdev->dev_addr);
472 static void netxen_set_multicast_list(struct net_device *dev)
474 struct netxen_adapter *adapter = netdev_priv(dev);
476 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
477 netxen_p3_nic_set_multi(dev);
479 netxen_p2_nic_set_multi(dev);
482 static const struct net_device_ops netxen_netdev_ops = {
483 .ndo_open = netxen_nic_open,
484 .ndo_stop = netxen_nic_close,
485 .ndo_start_xmit = netxen_nic_xmit_frame,
486 .ndo_get_stats = netxen_nic_get_stats,
487 .ndo_validate_addr = eth_validate_addr,
488 .ndo_set_multicast_list = netxen_set_multicast_list,
489 .ndo_set_mac_address = netxen_nic_set_mac,
490 .ndo_change_mtu = netxen_nic_change_mtu,
491 .ndo_tx_timeout = netxen_tx_timeout,
492 #ifdef CONFIG_NET_POLL_CONTROLLER
493 .ndo_poll_controller = netxen_nic_poll_controller,
500 * The Linux system will invoke this after identifying the vendor ID and
501 * device Id in the pci_tbl supported by this module.
503 * A quad port card has one operational PCI config space, (function 0),
504 * which is used to access all four ports.
506 * This routine will initialize the adapter, and setup the global parameters
507 * along with the port's specific structure.
510 netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
512 struct net_device *netdev = NULL;
513 struct netxen_adapter *adapter = NULL;
514 void __iomem *mem_ptr0 = NULL;
515 void __iomem *mem_ptr1 = NULL;
516 void __iomem *mem_ptr2 = NULL;
517 unsigned long first_page_group_end;
518 unsigned long first_page_group_start;
521 u8 __iomem *db_ptr = NULL;
522 unsigned long mem_base, mem_len, db_base, db_len, pci_len0 = 0;
524 int first_driver, first_boot;
526 int pci_func_id = PCI_FUNC(pdev->devfn);
527 struct netxen_legacy_intr_set *legacy_intrp;
530 if (pci_func_id == 0)
531 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
533 if (pdev->class != 0x020000) {
534 printk(KERN_DEBUG "NetXen function %d, class %x will not "
535 "be enabled.\n",pci_func_id, pdev->class);
539 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
540 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
541 "will not be enabled.\n",
546 if ((err = pci_enable_device(pdev)))
549 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
551 goto err_out_disable_pdev;
554 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
555 goto err_out_disable_pdev;
557 pci_set_master(pdev);
559 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
561 printk(KERN_ERR"%s: Failed to allocate memory for the "
562 "device block.Check system memory resource"
563 " usage.\n", netxen_nic_driver_name);
564 goto err_out_free_res;
567 SET_NETDEV_DEV(netdev, &pdev->dev);
569 adapter = netdev_priv(netdev);
570 adapter->netdev = netdev;
571 adapter->pdev = pdev;
572 adapter->ahw.pci_func = pci_func_id;
574 revision_id = pdev->revision;
575 adapter->ahw.revision_id = revision_id;
577 err = nx_set_dma_mask(adapter, revision_id);
579 goto err_out_free_netdev;
581 rwlock_init(&adapter->adapter_lock);
582 adapter->ahw.qdr_sn_window = -1;
583 adapter->ahw.ddr_mn_window = -1;
585 /* remap phys address */
586 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
587 mem_len = pci_resource_len(pdev, 0);
590 adapter->hw_write_wx = netxen_nic_hw_write_wx_128M;
591 adapter->hw_read_wx = netxen_nic_hw_read_wx_128M;
592 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_128M;
593 adapter->pci_write_immediate = netxen_nic_pci_write_immediate_128M;
594 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_128M;
595 adapter->pci_write_normalize = netxen_nic_pci_write_normalize_128M;
596 adapter->pci_set_window = netxen_nic_pci_set_window_128M;
597 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M;
598 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M;
600 /* 128 Meg of memory */
601 if (mem_len == NETXEN_PCI_128MB_SIZE) {
602 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
603 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
604 SECOND_PAGE_GROUP_SIZE);
605 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
606 THIRD_PAGE_GROUP_SIZE);
607 first_page_group_start = FIRST_PAGE_GROUP_START;
608 first_page_group_end = FIRST_PAGE_GROUP_END;
609 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
610 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
611 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
612 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
613 first_page_group_start = 0;
614 first_page_group_end = 0;
615 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
616 adapter->hw_write_wx = netxen_nic_hw_write_wx_2M;
617 adapter->hw_read_wx = netxen_nic_hw_read_wx_2M;
618 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_2M;
619 adapter->pci_write_immediate =
620 netxen_nic_pci_write_immediate_2M;
621 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_2M;
622 adapter->pci_write_normalize =
623 netxen_nic_pci_write_normalize_2M;
624 adapter->pci_set_window = netxen_nic_pci_set_window_2M;
625 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M;
626 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M;
628 mem_ptr0 = ioremap(mem_base, mem_len);
630 first_page_group_start = 0;
631 first_page_group_end = 0;
633 adapter->ahw.ddr_mn_window = 0;
634 adapter->ahw.qdr_sn_window = 0;
636 adapter->ahw.mn_win_crb = 0x100000 + PCIX_MN_WINDOW +
637 (pci_func_id * 0x20);
638 adapter->ahw.ms_win_crb = 0x100000 + PCIX_SN_WINDOW;
640 adapter->ahw.ms_win_crb += (pci_func_id * 0x20);
642 adapter->ahw.ms_win_crb +=
643 0xA0 + ((pci_func_id - 4) * 0x10);
646 goto err_out_free_netdev;
649 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
651 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
652 db_len = pci_resource_len(pdev, 4);
655 printk(KERN_ERR "%s: doorbell is disabled\n",
656 netxen_nic_driver_name);
658 goto err_out_iounmap;
660 DPRINTK(INFO, "doorbell ioremap from %lx a size of %lx\n", db_base,
663 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
665 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
666 netxen_nic_driver_name);
668 goto err_out_iounmap;
670 DPRINTK(INFO, "doorbell ioremaped at %p\n", db_ptr);
672 adapter->ahw.pci_base0 = mem_ptr0;
673 adapter->ahw.pci_len0 = pci_len0;
674 adapter->ahw.first_page_group_start = first_page_group_start;
675 adapter->ahw.first_page_group_end = first_page_group_end;
676 adapter->ahw.pci_base1 = mem_ptr1;
677 adapter->ahw.pci_base2 = mem_ptr2;
678 adapter->ahw.db_base = db_ptr;
679 adapter->ahw.db_len = db_len;
681 netif_napi_add(netdev, &adapter->napi,
682 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
684 if (revision_id >= NX_P3_B0)
685 legacy_intrp = &legacy_intr[pci_func_id];
687 legacy_intrp = &legacy_intr[0];
689 adapter->legacy_intr.int_vec_bit = legacy_intrp->int_vec_bit;
690 adapter->legacy_intr.tgt_status_reg = legacy_intrp->tgt_status_reg;
691 adapter->legacy_intr.tgt_mask_reg = legacy_intrp->tgt_mask_reg;
692 adapter->legacy_intr.pci_int_reg = legacy_intrp->pci_int_reg;
694 /* this will be read from FW later */
695 adapter->intr_scheme = -1;
696 adapter->msi_mode = -1;
698 /* This will be reset for mezz cards */
699 adapter->portnum = pci_func_id;
700 adapter->status &= ~NETXEN_NETDEV_STATUS;
701 adapter->rx_csum = 1;
702 adapter->mc_enabled = 0;
703 if (NX_IS_REVISION_P3(revision_id))
704 adapter->max_mc_count = 38;
706 adapter->max_mc_count = 16;
708 netdev->netdev_ops = &netxen_netdev_ops;
709 netdev->watchdog_timeo = 2*HZ;
711 netxen_nic_change_mtu(netdev, netdev->mtu);
713 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
715 /* ScatterGather support */
716 netdev->features = NETIF_F_SG;
717 netdev->features |= NETIF_F_IP_CSUM;
718 netdev->features |= NETIF_F_TSO;
719 if (NX_IS_REVISION_P3(revision_id)) {
720 netdev->features |= NETIF_F_IPV6_CSUM;
721 netdev->features |= NETIF_F_TSO6;
724 if (adapter->pci_using_dac)
725 netdev->features |= NETIF_F_HIGHDMA;
728 * Set the CRB window to invalid. If any register in window 0 is
729 * accessed it should set the window to 0 and then reset it to 1.
731 adapter->curr_window = 255;
733 if (netxen_nic_get_board_info(adapter) != 0) {
734 printk("%s: Error getting board config info.\n",
735 netxen_nic_driver_name);
737 goto err_out_iounmap;
740 netxen_initialize_adapter_ops(adapter);
742 /* Mezz cards have PCI function 0,2,3 enabled */
743 switch (adapter->ahw.boardcfg.board_type) {
744 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
745 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
746 if (pci_func_id >= 2)
747 adapter->portnum = pci_func_id - 2;
754 * This call will setup various max rx/tx counts.
755 * It must be done before any buffer/ring allocations.
757 netxen_check_options(adapter);
760 if (NX_IS_REVISION_P3(revision_id)) {
761 if (adapter->ahw.pci_func == 0)
764 if (adapter->portnum == 0)
769 first_boot = adapter->pci_read_normalize(adapter,
770 NETXEN_CAM_RAM(0x1fc));
772 err = netxen_check_hw_init(adapter, first_boot);
774 printk(KERN_ERR "%s: error in init HW init sequence\n",
775 netxen_nic_driver_name);
776 goto err_out_iounmap;
779 if (NX_IS_REVISION_P3(revision_id))
780 netxen_set_port_mode(adapter);
782 if (first_boot != 0x55555555) {
783 adapter->pci_write_normalize(adapter,
784 CRB_CMDPEG_STATE, 0);
785 netxen_pinit_from_rom(adapter, 0);
787 netxen_load_firmware(adapter);
790 if (NX_IS_REVISION_P3(revision_id))
791 netxen_pcie_strap_init(adapter);
793 if (NX_IS_REVISION_P2(revision_id)) {
795 /* Initialize multicast addr pool owners */
797 if (adapter->ahw.board_type == NETXEN_NIC_XGBE)
799 netxen_crb_writelit_adapter(adapter,
800 NETXEN_MAC_ADDR_CNTL_REG, val);
804 if ((first_boot == 0x55555555) &&
805 (NX_IS_REVISION_P2(revision_id))) {
806 /* Unlock the HW, prompting the boot sequence */
807 adapter->pci_write_normalize(adapter,
808 NETXEN_ROMUSB_GLB_PEGTUNE_DONE, 1);
811 err = netxen_initialize_adapter_offload(adapter);
813 goto err_out_iounmap;
816 * Tell the hardware our version number.
818 i = (_NETXEN_NIC_LINUX_MAJOR << 16)
819 | ((_NETXEN_NIC_LINUX_MINOR << 8))
820 | (_NETXEN_NIC_LINUX_SUBVERSION);
821 adapter->pci_write_normalize(adapter, CRB_DRIVER_VERSION, i);
823 /* Handshake with the card before we register the devices. */
824 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
828 netxen_nic_flash_print(adapter);
830 if (NX_IS_REVISION_P3(revision_id)) {
831 adapter->hw_read_wx(adapter,
832 NETXEN_MIU_MN_CONTROL, &val, 4);
833 adapter->ahw.cut_through = (val & 0x4) ? 1 : 0;
834 dev_info(&pdev->dev, "firmware running in %s mode\n",
835 adapter->ahw.cut_through ? "cut through" : "legacy");
839 * See if the firmware gave us a virtual-physical port mapping.
841 adapter->physical_port = adapter->portnum;
842 i = adapter->pci_read_normalize(adapter, CRB_V2P(adapter->portnum));
844 adapter->physical_port = i;
846 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
848 netxen_set_msix_bit(pdev, 0);
850 if (NX_IS_REVISION_P3(revision_id)) {
851 if ((mem_len != NETXEN_PCI_128MB_SIZE) &&
852 mem_len != NETXEN_PCI_2MB_SIZE)
853 adapter->msix_supported = 0;
856 if (adapter->msix_supported) {
858 netxen_init_msix_entries(adapter);
860 if (pci_enable_msix(pdev, adapter->msix_entries,
861 MSIX_ENTRIES_PER_ADAPTER))
864 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
865 netxen_set_msix_bit(pdev, 1);
866 dev_info(&pdev->dev, "using msi-x interrupts\n");
870 if (use_msi && !pci_enable_msi(pdev)) {
871 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
872 dev_info(&pdev->dev, "using msi interrupts\n");
874 dev_info(&pdev->dev, "using legacy interrupts\n");
877 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
878 netdev->irq = adapter->msix_entries[0].vector;
880 netdev->irq = pdev->irq;
882 err = netxen_receive_peg_ready(adapter);
884 goto err_out_disable_msi;
886 init_timer(&adapter->watchdog_timer);
887 adapter->watchdog_timer.function = &netxen_watchdog;
888 adapter->watchdog_timer.data = (unsigned long)adapter;
889 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
890 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
892 err = netxen_read_mac_addr(adapter);
894 dev_warn(&pdev->dev, "failed to read mac addr\n");
896 netif_carrier_off(netdev);
897 netif_stop_queue(netdev);
899 if ((err = register_netdev(netdev))) {
900 printk(KERN_ERR "%s: register_netdev failed port #%d"
901 " aborting\n", netxen_nic_driver_name,
904 goto err_out_disable_msi;
907 pci_set_drvdata(pdev, adapter);
909 switch (adapter->ahw.board_type) {
911 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
912 adapter->netdev->name);
914 case NETXEN_NIC_XGBE:
915 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
916 adapter->netdev->name);
923 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
924 pci_disable_msix(pdev);
925 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
926 pci_disable_msi(pdev);
929 netxen_free_adapter_offload(adapter);
946 pci_release_regions(pdev);
948 err_out_disable_pdev:
949 pci_set_drvdata(pdev, NULL);
950 pci_disable_device(pdev);
954 static void __devexit netxen_nic_remove(struct pci_dev *pdev)
956 struct netxen_adapter *adapter;
957 struct net_device *netdev;
959 adapter = pci_get_drvdata(pdev);
963 netdev = adapter->netdev;
965 unregister_netdev(netdev);
967 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
968 netxen_free_hw_resources(adapter);
969 netxen_release_rx_buffers(adapter);
970 netxen_free_sw_resources(adapter);
973 if (adapter->portnum == 0)
974 netxen_free_adapter_offload(adapter);
977 free_irq(adapter->irq, adapter);
979 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
980 pci_disable_msix(pdev);
981 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
982 pci_disable_msi(pdev);
984 iounmap(adapter->ahw.db_base);
985 iounmap(adapter->ahw.pci_base0);
986 iounmap(adapter->ahw.pci_base1);
987 iounmap(adapter->ahw.pci_base2);
989 pci_release_regions(pdev);
990 pci_disable_device(pdev);
991 pci_set_drvdata(pdev, NULL);
997 * Called when a network interface is made active
998 * @returns 0 on success, negative value on failure
1000 static int netxen_nic_open(struct net_device *netdev)
1002 struct netxen_adapter *adapter = netdev_priv(netdev);
1005 irq_handler_t handler;
1006 unsigned long flags = IRQF_SAMPLE_RANDOM;
1008 if (adapter->driver_mismatch)
1011 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) {
1012 err = netxen_init_firmware(adapter);
1014 printk(KERN_ERR "Failed to init firmware\n");
1018 if (adapter->fw_major < 4)
1019 adapter->max_rds_rings = 3;
1021 adapter->max_rds_rings = 2;
1023 err = netxen_alloc_sw_resources(adapter);
1025 printk(KERN_ERR "%s: Error in setting sw resources\n",
1030 netxen_nic_clear_stats(adapter);
1032 err = netxen_alloc_hw_resources(adapter);
1034 printk(KERN_ERR "%s: Error in setting hw resources\n",
1036 goto err_out_free_sw;
1039 if ((adapter->msi_mode != MSI_MODE_MULTIFUNC) ||
1040 (adapter->intr_scheme != INTR_SCHEME_PERPORT)) {
1041 printk(KERN_ERR "%s: Firmware interrupt scheme is "
1042 "incompatible with driver\n",
1044 adapter->driver_mismatch = 1;
1045 goto err_out_free_hw;
1048 if (adapter->fw_major < 4) {
1049 adapter->crb_addr_cmd_producer =
1050 crb_cmd_producer[adapter->portnum];
1051 adapter->crb_addr_cmd_consumer =
1052 crb_cmd_consumer[adapter->portnum];
1054 netxen_nic_update_cmd_producer(adapter, 0);
1055 netxen_nic_update_cmd_consumer(adapter, 0);
1058 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
1059 for (ring = 0; ring < adapter->max_rds_rings; ring++)
1060 netxen_post_rx_buffers(adapter, ctx, ring);
1062 if (NETXEN_IS_MSI_FAMILY(adapter))
1063 handler = netxen_msi_intr;
1065 flags |= IRQF_SHARED;
1066 handler = netxen_intr;
1068 adapter->irq = netdev->irq;
1069 err = request_irq(adapter->irq, handler,
1070 flags, netdev->name, adapter);
1072 printk(KERN_ERR "request_irq failed with: %d\n", err);
1073 goto err_out_free_rxbuf;
1076 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1079 /* Done here again so that even if phantom sw overwrote it,
1081 err = adapter->init_port(adapter, adapter->physical_port);
1083 printk(KERN_ERR "%s: Failed to initialize port %d\n",
1084 netxen_nic_driver_name, adapter->portnum);
1085 goto err_out_free_irq;
1087 adapter->macaddr_set(adapter, netdev->dev_addr);
1089 netxen_nic_set_link_parameters(adapter);
1091 netxen_set_multicast_list(netdev);
1092 if (adapter->set_mtu)
1093 adapter->set_mtu(adapter, netdev->mtu);
1095 adapter->ahw.linkup = 0;
1096 mod_timer(&adapter->watchdog_timer, jiffies);
1098 napi_enable(&adapter->napi);
1099 netxen_nic_enable_int(adapter);
1101 netif_start_queue(netdev);
1106 free_irq(adapter->irq, adapter);
1108 netxen_release_rx_buffers(adapter);
1110 netxen_free_hw_resources(adapter);
1112 netxen_free_sw_resources(adapter);
1117 * netxen_nic_close - Disables a network interface entry point
1119 static int netxen_nic_close(struct net_device *netdev)
1121 struct netxen_adapter *adapter = netdev_priv(netdev);
1123 netif_carrier_off(netdev);
1124 netif_stop_queue(netdev);
1125 napi_disable(&adapter->napi);
1127 if (adapter->stop_port)
1128 adapter->stop_port(adapter);
1130 netxen_nic_disable_int(adapter);
1132 netxen_release_tx_buffers(adapter);
1134 FLUSH_SCHEDULED_WORK();
1135 del_timer_sync(&adapter->watchdog_timer);
1140 void netxen_tso_check(struct netxen_adapter *adapter,
1141 struct cmd_desc_type0 *desc, struct sk_buff *skb)
1144 desc->total_hdr_length = (sizeof(struct ethhdr) +
1145 ip_hdrlen(skb) + tcp_hdrlen(skb));
1147 if ((NX_IS_REVISION_P3(adapter->ahw.revision_id)) &&
1148 (skb->protocol == htons(ETH_P_IPV6)))
1149 netxen_set_cmd_desc_opcode(desc, TX_TCP_LSO6);
1151 netxen_set_cmd_desc_opcode(desc, TX_TCP_LSO);
1153 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
1154 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
1155 netxen_set_cmd_desc_opcode(desc, TX_TCP_PKT);
1156 else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
1157 netxen_set_cmd_desc_opcode(desc, TX_UDP_PKT);
1161 desc->tcp_hdr_offset = skb_transport_offset(skb);
1162 desc->ip_hdr_offset = skb_network_offset(skb);
1165 static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1167 struct netxen_adapter *adapter = netdev_priv(netdev);
1168 struct netxen_hardware_context *hw = &adapter->ahw;
1169 unsigned int first_seg_len = skb->len - skb->data_len;
1170 struct netxen_skb_frag *buffrag;
1173 u32 producer, consumer;
1174 u32 saved_producer = 0;
1175 struct cmd_desc_type0 *hwdesc;
1177 struct netxen_cmd_buffer *pbuf = NULL;
1180 u32 num_txd = adapter->max_tx_desc_count;
1182 frag_count = skb_shinfo(skb)->nr_frags + 1;
1184 /* There 4 fragments per descriptor */
1185 no_of_desc = (frag_count + 3) >> 2;
1186 if (netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) {
1187 if (skb_shinfo(skb)->gso_size > 0) {
1190 if ((ip_hdrlen(skb) + tcp_hdrlen(skb) +
1191 sizeof(struct ethhdr)) >
1192 (sizeof(struct cmd_desc_type0) - 2)) {
1198 producer = adapter->cmd_producer;
1200 consumer = adapter->last_cmd_consumer;
1201 if ((no_of_desc+2) > find_diff_among(producer, consumer, num_txd)) {
1202 netif_stop_queue(netdev);
1204 return NETDEV_TX_BUSY;
1207 /* Copy the descriptors into the hardware */
1208 saved_producer = producer;
1209 hwdesc = &hw->cmd_desc_head[producer];
1210 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
1211 /* Take skb->data itself */
1212 pbuf = &adapter->cmd_buf_arr[producer];
1213 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1214 skb_shinfo(skb)->gso_size > 0) {
1215 pbuf->mss = skb_shinfo(skb)->gso_size;
1216 hwdesc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1221 pbuf->total_length = skb->len;
1223 pbuf->cmd = TX_ETHER_PKT;
1224 pbuf->frag_count = frag_count;
1225 pbuf->port = adapter->portnum;
1226 buffrag = &pbuf->frag_array[0];
1227 buffrag->dma = pci_map_single(adapter->pdev, skb->data, first_seg_len,
1229 buffrag->length = first_seg_len;
1230 netxen_set_cmd_desc_totallength(hwdesc, skb->len);
1231 netxen_set_cmd_desc_num_of_buff(hwdesc, frag_count);
1232 netxen_set_cmd_desc_opcode(hwdesc, TX_ETHER_PKT);
1234 netxen_set_cmd_desc_port(hwdesc, adapter->portnum);
1235 netxen_set_cmd_desc_ctxid(hwdesc, adapter->portnum);
1236 hwdesc->buffer1_length = cpu_to_le16(first_seg_len);
1237 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
1239 for (i = 1, k = 1; i < frag_count; i++, k++) {
1240 struct skb_frag_struct *frag;
1242 unsigned long offset;
1243 dma_addr_t temp_dma;
1245 /* move to next desc. if there is a need */
1246 if ((i & 0x3) == 0) {
1248 producer = get_next_index(producer, num_txd);
1249 hwdesc = &hw->cmd_desc_head[producer];
1250 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
1251 pbuf = &adapter->cmd_buf_arr[producer];
1254 frag = &skb_shinfo(skb)->frags[i - 1];
1256 offset = frag->page_offset;
1259 temp_dma = pci_map_page(adapter->pdev, frag->page, offset,
1260 len, PCI_DMA_TODEVICE);
1263 buffrag->dma = temp_dma;
1264 buffrag->length = temp_len;
1268 hwdesc->buffer1_length = cpu_to_le16(temp_len);
1269 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
1272 hwdesc->buffer2_length = cpu_to_le16(temp_len);
1273 hwdesc->addr_buffer2 = cpu_to_le64(temp_dma);
1276 hwdesc->buffer3_length = cpu_to_le16(temp_len);
1277 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
1280 hwdesc->buffer4_length = cpu_to_le16(temp_len);
1281 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
1286 producer = get_next_index(producer, num_txd);
1288 /* might change opcode to TX_TCP_LSO */
1289 netxen_tso_check(adapter, &hw->cmd_desc_head[saved_producer], skb);
1291 /* For LSO, we need to copy the MAC/IP/TCP headers into
1292 * the descriptor ring
1294 if (netxen_get_cmd_desc_opcode(&hw->cmd_desc_head[saved_producer])
1296 int hdr_len, first_hdr_len, more_hdr;
1297 hdr_len = hw->cmd_desc_head[saved_producer].total_hdr_length;
1298 if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) {
1299 first_hdr_len = sizeof(struct cmd_desc_type0) - 2;
1302 first_hdr_len = hdr_len;
1305 /* copy the MAC/IP/TCP headers to the cmd descriptor list */
1306 hwdesc = &hw->cmd_desc_head[producer];
1307 pbuf = &adapter->cmd_buf_arr[producer];
1310 /* copy the first 64 bytes */
1311 memcpy(((void *)hwdesc) + 2,
1312 (void *)(skb->data), first_hdr_len);
1313 producer = get_next_index(producer, num_txd);
1316 hwdesc = &hw->cmd_desc_head[producer];
1317 pbuf = &adapter->cmd_buf_arr[producer];
1319 /* copy the next 64 bytes - should be enough except
1320 * for pathological case
1322 skb_copy_from_linear_data_offset(skb, first_hdr_len,
1326 producer = get_next_index(producer, num_txd);
1330 adapter->cmd_producer = producer;
1331 adapter->stats.txbytes += skb->len;
1333 netxen_nic_update_cmd_producer(adapter, adapter->cmd_producer);
1335 adapter->stats.xmitcalled++;
1336 netdev->trans_start = jiffies;
1338 return NETDEV_TX_OK;
1341 static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1343 struct net_device *netdev = adapter->netdev;
1344 uint32_t temp, temp_state, temp_val;
1347 temp = adapter->pci_read_normalize(adapter, CRB_TEMP_STATE);
1349 temp_state = nx_get_temp_state(temp);
1350 temp_val = nx_get_temp_val(temp);
1352 if (temp_state == NX_TEMP_PANIC) {
1354 "%s: Device temperature %d degrees C exceeds"
1355 " maximum allowed. Hardware has been shut down.\n",
1356 netxen_nic_driver_name, temp_val);
1358 netif_carrier_off(netdev);
1359 netif_stop_queue(netdev);
1361 } else if (temp_state == NX_TEMP_WARN) {
1362 if (adapter->temp == NX_TEMP_NORMAL) {
1364 "%s: Device temperature %d degrees C "
1365 "exceeds operating range."
1366 " Immediate action needed.\n",
1367 netxen_nic_driver_name, temp_val);
1370 if (adapter->temp == NX_TEMP_WARN) {
1372 "%s: Device temperature is now %d degrees C"
1373 " in normal range.\n", netxen_nic_driver_name,
1377 adapter->temp = temp_state;
1381 static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1383 struct net_device *netdev = adapter->netdev;
1384 u32 val, port, linkup;
1386 port = adapter->physical_port;
1388 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1389 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE_P3);
1390 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1391 linkup = (val == XG_LINK_UP_P3);
1393 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
1394 if (adapter->ahw.board_type == NETXEN_NIC_GBE)
1395 linkup = (val >> port) & 1;
1397 val = (val >> port*8) & 0xff;
1398 linkup = (val == XG_LINK_UP);
1402 if (adapter->ahw.linkup && !linkup) {
1403 printk(KERN_INFO "%s: %s NIC Link is down\n",
1404 netxen_nic_driver_name, netdev->name);
1405 adapter->ahw.linkup = 0;
1406 if (netif_running(netdev)) {
1407 netif_carrier_off(netdev);
1408 netif_stop_queue(netdev);
1410 } else if (!adapter->ahw.linkup && linkup) {
1411 printk(KERN_INFO "%s: %s NIC Link is up\n",
1412 netxen_nic_driver_name, netdev->name);
1413 adapter->ahw.linkup = 1;
1414 if (netif_running(netdev)) {
1415 netif_carrier_on(netdev);
1416 netif_wake_queue(netdev);
1421 static void netxen_watchdog(unsigned long v)
1423 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
1425 SCHEDULE_WORK(&adapter->watchdog_task);
1428 void netxen_watchdog_task(struct work_struct *work)
1430 struct netxen_adapter *adapter =
1431 container_of(work, struct netxen_adapter, watchdog_task);
1433 if ((adapter->portnum == 0) && netxen_nic_check_temp(adapter))
1436 netxen_nic_handle_phy_intr(adapter);
1438 if (netif_running(adapter->netdev))
1439 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1442 static void netxen_tx_timeout(struct net_device *netdev)
1444 struct netxen_adapter *adapter = (struct netxen_adapter *)
1445 netdev_priv(netdev);
1446 SCHEDULE_WORK(&adapter->tx_timeout_task);
1449 static void netxen_tx_timeout_task(struct work_struct *work)
1451 struct netxen_adapter *adapter =
1452 container_of(work, struct netxen_adapter, tx_timeout_task);
1454 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
1455 netxen_nic_driver_name, adapter->netdev->name);
1457 netxen_nic_disable_int(adapter);
1458 napi_disable(&adapter->napi);
1460 adapter->netdev->trans_start = jiffies;
1462 napi_enable(&adapter->napi);
1463 netxen_nic_enable_int(adapter);
1464 netif_wake_queue(adapter->netdev);
1468 * netxen_nic_get_stats - Get System Network Statistics
1469 * @netdev: network interface device structure
1471 struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1473 struct netxen_adapter *adapter = netdev_priv(netdev);
1474 struct net_device_stats *stats = &adapter->net_stats;
1476 memset(stats, 0, sizeof(*stats));
1478 /* total packets received */
1479 stats->rx_packets = adapter->stats.no_rcv;
1480 /* total packets transmitted */
1481 stats->tx_packets = adapter->stats.xmitedframes +
1482 adapter->stats.xmitfinished;
1483 /* total bytes received */
1484 stats->rx_bytes = adapter->stats.rxbytes;
1485 /* total bytes transmitted */
1486 stats->tx_bytes = adapter->stats.txbytes;
1487 /* bad packets received */
1488 stats->rx_errors = adapter->stats.rcvdbadskb;
1489 /* packet transmit problems */
1490 stats->tx_errors = adapter->stats.nocmddescriptor;
1491 /* no space in linux buffers */
1492 stats->rx_dropped = adapter->stats.rxdropped;
1493 /* no space available in linux */
1494 stats->tx_dropped = adapter->stats.txdropped;
1499 static irqreturn_t netxen_intr(int irq, void *data)
1501 struct netxen_adapter *adapter = data;
1504 status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1506 if (!(status & adapter->legacy_intr.int_vec_bit))
1509 if (adapter->ahw.revision_id >= NX_P3_B1) {
1510 /* check interrupt state machine, to be sure */
1511 status = adapter->pci_read_immediate(adapter,
1513 if (!ISR_LEGACY_INT_TRIGGERED(status))
1517 unsigned long our_int = 0;
1519 our_int = adapter->pci_read_normalize(adapter, CRB_INT_VECTOR);
1521 /* not our interrupt */
1522 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
1525 /* claim interrupt */
1526 adapter->pci_write_normalize(adapter,
1527 CRB_INT_VECTOR, (our_int & 0xffffffff));
1530 /* clear interrupt */
1531 if (adapter->fw_major < 4)
1532 netxen_nic_disable_int(adapter);
1534 adapter->pci_write_immediate(adapter,
1535 adapter->legacy_intr.tgt_status_reg,
1537 /* read twice to ensure write is flushed */
1538 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1539 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1541 napi_schedule(&adapter->napi);
1546 static irqreturn_t netxen_msi_intr(int irq, void *data)
1548 struct netxen_adapter *adapter = data;
1550 /* clear interrupt */
1551 adapter->pci_write_immediate(adapter,
1552 msi_tgt_status[adapter->ahw.pci_func], 0xffffffff);
1554 napi_schedule(&adapter->napi);
1558 static int netxen_nic_poll(struct napi_struct *napi, int budget)
1560 struct netxen_adapter *adapter = container_of(napi, struct netxen_adapter, napi);
1565 tx_complete = netxen_process_cmd_ring(adapter);
1568 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
1570 * Fairness issue. This will give undue weight to the
1571 * receive context 0.
1575 * To avoid starvation, we give each of our receivers,
1576 * a fraction of the quota. Sometimes, it might happen that we
1577 * have enough quota to process every packet, but since all the
1578 * packets are on one context, it gets only half of the quota,
1579 * and ends up not processing it.
1581 work_done += netxen_process_rcv_ring(adapter, ctx,
1582 budget / MAX_RCV_CTX);
1585 if ((work_done < budget) && tx_complete) {
1586 netif_rx_complete(adapter->netdev, &adapter->napi);
1587 netxen_nic_enable_int(adapter);
1593 #ifdef CONFIG_NET_POLL_CONTROLLER
1594 static void netxen_nic_poll_controller(struct net_device *netdev)
1596 struct netxen_adapter *adapter = netdev_priv(netdev);
1597 disable_irq(adapter->irq);
1598 netxen_intr(adapter->irq, adapter);
1599 enable_irq(adapter->irq);
1603 static struct pci_driver netxen_driver = {
1604 .name = netxen_nic_driver_name,
1605 .id_table = netxen_pci_tbl,
1606 .probe = netxen_nic_probe,
1607 .remove = __devexit_p(netxen_nic_remove)
1610 /* Driver Registration on NetXen card */
1612 static int __init netxen_init_module(void)
1614 if ((netxen_workq = create_singlethread_workqueue("netxen")) == NULL)
1617 return pci_register_driver(&netxen_driver);
1620 module_init(netxen_init_module);
1622 static void __exit netxen_exit_module(void)
1624 pci_unregister_driver(&netxen_driver);
1625 destroy_workqueue(netxen_workq);
1628 module_exit(netxen_exit_module);