Chinese: add translation of oops-tracing.txt
[pv_ops_mirror.git] / drivers / net / netxen / netxen_nic_main.c
blob263b55e36c7a1b0d477bfd6e1e3892fb54097bcc
1 /*
2 * Copyright (C) 2003 - 2006 NetXen, Inc.
3 * All rights reserved.
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,
18 * MA 02111-1307, USA.
20 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
23 * Contact Information:
24 * info@netxen.com
25 * NetXen,
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 <net/ip.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 #define NETXEN_NETDEV_WEIGHT 120
53 #define NETXEN_ADAPTER_UP_MAGIC 777
54 #define NETXEN_NIC_PEG_TUNE 0
56 /* Local functions to NetXen NIC driver */
57 static int __devinit netxen_nic_probe(struct pci_dev *pdev,
58 const struct pci_device_id *ent);
59 static void __devexit netxen_nic_remove(struct pci_dev *pdev);
60 static int netxen_nic_open(struct net_device *netdev);
61 static int netxen_nic_close(struct net_device *netdev);
62 static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *);
63 static void netxen_tx_timeout(struct net_device *netdev);
64 static void netxen_tx_timeout_task(struct work_struct *work);
65 static void netxen_watchdog(unsigned long);
66 static int netxen_handle_int(struct netxen_adapter *, struct net_device *);
67 static int netxen_nic_poll(struct napi_struct *napi, int budget);
68 #ifdef CONFIG_NET_POLL_CONTROLLER
69 static void netxen_nic_poll_controller(struct net_device *netdev);
70 #endif
71 static irqreturn_t netxen_intr(int irq, void *data);
73 int physical_port[] = {0, 1, 2, 3};
75 /* PCI Device ID Table */
76 static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
77 {PCI_DEVICE(0x4040, 0x0001)},
78 {PCI_DEVICE(0x4040, 0x0002)},
79 {PCI_DEVICE(0x4040, 0x0003)},
80 {PCI_DEVICE(0x4040, 0x0004)},
81 {PCI_DEVICE(0x4040, 0x0005)},
82 {PCI_DEVICE(0x4040, 0x0024)},
83 {PCI_DEVICE(0x4040, 0x0025)},
84 {0,}
87 MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
89 struct workqueue_struct *netxen_workq;
90 static void netxen_watchdog(unsigned long);
92 static inline void netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
93 uint32_t crb_producer)
95 switch (adapter->portnum) {
96 case 0:
97 writel(crb_producer, NETXEN_CRB_NORMALIZE
98 (adapter, CRB_CMD_PRODUCER_OFFSET));
99 return;
100 case 1:
101 writel(crb_producer, NETXEN_CRB_NORMALIZE
102 (adapter, CRB_CMD_PRODUCER_OFFSET_1));
103 return;
104 case 2:
105 writel(crb_producer, NETXEN_CRB_NORMALIZE
106 (adapter, CRB_CMD_PRODUCER_OFFSET_2));
107 return;
108 case 3:
109 writel(crb_producer, NETXEN_CRB_NORMALIZE
110 (adapter, CRB_CMD_PRODUCER_OFFSET_3));
111 return;
112 default:
113 printk(KERN_WARNING "We tried to update "
114 "CRB_CMD_PRODUCER_OFFSET for invalid "
115 "PCI function id %d\n",
116 adapter->portnum);
117 return;
121 static inline void netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
122 u32 crb_consumer)
124 switch (adapter->portnum) {
125 case 0:
126 writel(crb_consumer, NETXEN_CRB_NORMALIZE
127 (adapter, CRB_CMD_CONSUMER_OFFSET));
128 return;
129 case 1:
130 writel(crb_consumer, NETXEN_CRB_NORMALIZE
131 (adapter, CRB_CMD_CONSUMER_OFFSET_1));
132 return;
133 case 2:
134 writel(crb_consumer, NETXEN_CRB_NORMALIZE
135 (adapter, CRB_CMD_CONSUMER_OFFSET_2));
136 return;
137 case 3:
138 writel(crb_consumer, NETXEN_CRB_NORMALIZE
139 (adapter, CRB_CMD_CONSUMER_OFFSET_3));
140 return;
141 default:
142 printk(KERN_WARNING "We tried to update "
143 "CRB_CMD_PRODUCER_OFFSET for invalid "
144 "PCI function id %d\n",
145 adapter->portnum);
146 return;
150 #define ADAPTER_LIST_SIZE 12
151 int netxen_cards_found;
153 static void netxen_nic_disable_int(struct netxen_adapter *adapter)
155 uint32_t mask = 0x7ff;
156 int retries = 32;
158 DPRINTK(1, INFO, "Entered ISR Disable \n");
160 switch (adapter->portnum) {
161 case 0:
162 writel(0x0, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_0));
163 break;
164 case 1:
165 writel(0x0, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_1));
166 break;
167 case 2:
168 writel(0x0, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_2));
169 break;
170 case 3:
171 writel(0x0, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_3));
172 break;
175 if (adapter->intr_scheme != -1 &&
176 adapter->intr_scheme != INTR_SCHEME_PERPORT)
177 writel(mask,PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_MASK));
179 /* Window = 0 or 1 */
180 if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) {
181 do {
182 writel(0xffffffff,
183 PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_TARGET_STATUS));
184 mask = readl(pci_base_offset(adapter, ISR_INT_VECTOR));
185 if (!(mask & 0x80))
186 break;
187 udelay(10);
188 } while (--retries);
190 if (!retries) {
191 printk(KERN_NOTICE "%s: Failed to disable interrupt completely\n",
192 netxen_nic_driver_name);
196 DPRINTK(1, INFO, "Done with Disable Int\n");
199 static void netxen_nic_enable_int(struct netxen_adapter *adapter)
201 u32 mask;
203 DPRINTK(1, INFO, "Entered ISR Enable \n");
205 if (adapter->intr_scheme != -1 &&
206 adapter->intr_scheme != INTR_SCHEME_PERPORT) {
207 switch (adapter->ahw.board_type) {
208 case NETXEN_NIC_GBE:
209 mask = 0x77b;
210 break;
211 case NETXEN_NIC_XGBE:
212 mask = 0x77f;
213 break;
214 default:
215 mask = 0x7ff;
216 break;
219 writel(mask, PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_MASK));
222 switch (adapter->portnum) {
223 case 0:
224 writel(0x1, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_0));
225 break;
226 case 1:
227 writel(0x1, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_1));
228 break;
229 case 2:
230 writel(0x1, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_2));
231 break;
232 case 3:
233 writel(0x1, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_3));
234 break;
237 if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) {
238 mask = 0xbff;
239 if (adapter->intr_scheme != -1 &&
240 adapter->intr_scheme != INTR_SCHEME_PERPORT) {
241 writel(0X0, NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR));
243 writel(mask,
244 PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_TARGET_MASK));
247 DPRINTK(1, INFO, "Done with enable Int\n");
251 * netxen_nic_probe()
253 * The Linux system will invoke this after identifying the vendor ID and
254 * device Id in the pci_tbl supported by this module.
256 * A quad port card has one operational PCI config space, (function 0),
257 * which is used to access all four ports.
259 * This routine will initialize the adapter, and setup the global parameters
260 * along with the port's specific structure.
262 static int __devinit
263 netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
265 struct net_device *netdev = NULL;
266 struct netxen_adapter *adapter = NULL;
267 void __iomem *mem_ptr0 = NULL;
268 void __iomem *mem_ptr1 = NULL;
269 void __iomem *mem_ptr2 = NULL;
270 unsigned long first_page_group_end;
271 unsigned long first_page_group_start;
274 u8 __iomem *db_ptr = NULL;
275 unsigned long mem_base, mem_len, db_base, db_len;
276 int pci_using_dac, i = 0, err;
277 int ring;
278 struct netxen_recv_context *recv_ctx = NULL;
279 struct netxen_rcv_desc_ctx *rcv_desc = NULL;
280 struct netxen_cmd_buffer *cmd_buf_arr = NULL;
281 u64 mac_addr[FLASH_NUM_PORTS + 1];
282 int valid_mac = 0;
283 u32 val;
284 int pci_func_id = PCI_FUNC(pdev->devfn);
285 DECLARE_MAC_BUF(mac);
287 printk(KERN_INFO "%s \n", netxen_nic_driver_string);
289 if (pdev->class != 0x020000) {
290 printk(KERN_ERR"NetXen function %d, class %x will not"
291 "be enabled.\n",pci_func_id, pdev->class);
292 return -ENODEV;
294 if ((err = pci_enable_device(pdev)))
295 return err;
296 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
297 err = -ENODEV;
298 goto err_out_disable_pdev;
301 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
302 goto err_out_disable_pdev;
304 pci_set_master(pdev);
305 if (pdev->revision == NX_P2_C1 &&
306 (pci_set_dma_mask(pdev, DMA_35BIT_MASK) == 0) &&
307 (pci_set_consistent_dma_mask(pdev, DMA_35BIT_MASK) == 0)) {
308 pci_using_dac = 1;
309 } else {
310 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) ||
311 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK)))
312 goto err_out_free_res;
314 pci_using_dac = 0;
318 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
319 if(!netdev) {
320 printk(KERN_ERR"%s: Failed to allocate memory for the "
321 "device block.Check system memory resource"
322 " usage.\n", netxen_nic_driver_name);
323 goto err_out_free_res;
326 SET_NETDEV_DEV(netdev, &pdev->dev);
328 adapter = netdev->priv;
330 adapter->ahw.pdev = pdev;
331 adapter->ahw.pci_func = pci_func_id;
332 spin_lock_init(&adapter->tx_lock);
334 /* remap phys address */
335 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
336 mem_len = pci_resource_len(pdev, 0);
338 /* 128 Meg of memory */
339 if (mem_len == NETXEN_PCI_128MB_SIZE) {
340 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
341 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
342 SECOND_PAGE_GROUP_SIZE);
343 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
344 THIRD_PAGE_GROUP_SIZE);
345 first_page_group_start = FIRST_PAGE_GROUP_START;
346 first_page_group_end = FIRST_PAGE_GROUP_END;
347 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
348 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
349 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
350 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
351 first_page_group_start = 0;
352 first_page_group_end = 0;
353 } else {
354 err = -EIO;
355 goto err_out_free_netdev;
358 if (((mem_ptr0 == 0UL) && (mem_len == NETXEN_PCI_128MB_SIZE)) ||
359 (mem_ptr1 == 0UL) || (mem_ptr2 == 0UL)) {
360 DPRINTK(ERR,
361 "Cannot remap adapter memory aborting.:"
362 "0 -> %p, 1 -> %p, 2 -> %p\n",
363 mem_ptr0, mem_ptr1, mem_ptr2);
365 err = -EIO;
366 goto err_out_iounmap;
368 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
369 db_len = pci_resource_len(pdev, 4);
371 if (db_len == 0) {
372 printk(KERN_ERR "%s: doorbell is disabled\n",
373 netxen_nic_driver_name);
374 err = -EIO;
375 goto err_out_iounmap;
377 DPRINTK(INFO, "doorbell ioremap from %lx a size of %lx\n", db_base,
378 db_len);
380 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
381 if (!db_ptr) {
382 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
383 netxen_nic_driver_name);
384 err = -EIO;
385 goto err_out_iounmap;
387 DPRINTK(INFO, "doorbell ioremaped at %p\n", db_ptr);
389 adapter->ahw.pci_base0 = mem_ptr0;
390 adapter->ahw.first_page_group_start = first_page_group_start;
391 adapter->ahw.first_page_group_end = first_page_group_end;
392 adapter->ahw.pci_base1 = mem_ptr1;
393 adapter->ahw.pci_base2 = mem_ptr2;
394 adapter->ahw.db_base = db_ptr;
395 adapter->ahw.db_len = db_len;
397 adapter->netdev = netdev;
398 adapter->pdev = pdev;
400 netif_napi_add(netdev, &adapter->napi,
401 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
403 /* this will be read from FW later */
404 adapter->intr_scheme = -1;
406 /* This will be reset for mezz cards */
407 adapter->portnum = pci_func_id;
408 adapter->status &= ~NETXEN_NETDEV_STATUS;
409 adapter->rx_csum = 1;
411 netdev->open = netxen_nic_open;
412 netdev->stop = netxen_nic_close;
413 netdev->hard_start_xmit = netxen_nic_xmit_frame;
414 netdev->get_stats = netxen_nic_get_stats;
415 netdev->set_multicast_list = netxen_nic_set_multi;
416 netdev->set_mac_address = netxen_nic_set_mac;
417 netdev->change_mtu = netxen_nic_change_mtu;
418 netdev->tx_timeout = netxen_tx_timeout;
419 netdev->watchdog_timeo = HZ;
421 netxen_nic_change_mtu(netdev, netdev->mtu);
423 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
424 #ifdef CONFIG_NET_POLL_CONTROLLER
425 netdev->poll_controller = netxen_nic_poll_controller;
426 #endif
427 /* ScatterGather support */
428 netdev->features = NETIF_F_SG;
429 netdev->features |= NETIF_F_IP_CSUM;
430 netdev->features |= NETIF_F_TSO;
432 if (pci_using_dac)
433 netdev->features |= NETIF_F_HIGHDMA;
435 if (pci_enable_msi(pdev))
436 adapter->flags &= ~NETXEN_NIC_MSI_ENABLED;
437 else
438 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
440 netdev->irq = pdev->irq;
441 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
444 * Set the CRB window to invalid. If any register in window 0 is
445 * accessed it should set the window to 0 and then reset it to 1.
447 adapter->curr_window = 255;
449 /* initialize the adapter */
450 netxen_initialize_adapter_hw(adapter);
453 * Adapter in our case is quad port so initialize it before
454 * initializing the ports
457 netxen_initialize_adapter_ops(adapter);
459 adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS_HOST;
460 if ((adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB35_4G) ||
461 (adapter->ahw.boardcfg.board_type ==
462 NETXEN_BRDTYPE_P2_SB31_2G))
463 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
464 else
465 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS;
466 adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS;
467 adapter->max_lro_rx_desc_count = MAX_LRO_RCV_DESCRIPTORS;
469 cmd_buf_arr = (struct netxen_cmd_buffer *)vmalloc(TX_RINGSIZE);
470 if (cmd_buf_arr == NULL) {
471 printk(KERN_ERR
472 "%s: Could not allocate cmd_buf_arr memory:%d\n",
473 netxen_nic_driver_name, (int)TX_RINGSIZE);
474 err = -ENOMEM;
475 goto err_out_free_adapter;
477 memset(cmd_buf_arr, 0, TX_RINGSIZE);
478 adapter->cmd_buf_arr = cmd_buf_arr;
480 for (i = 0; i < MAX_RCV_CTX; ++i) {
481 recv_ctx = &adapter->recv_ctx[i];
482 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
483 rcv_desc = &recv_ctx->rcv_desc[ring];
484 switch (RCV_DESC_TYPE(ring)) {
485 case RCV_DESC_NORMAL:
486 rcv_desc->max_rx_desc_count =
487 adapter->max_rx_desc_count;
488 rcv_desc->flags = RCV_DESC_NORMAL;
489 rcv_desc->dma_size = RX_DMA_MAP_LEN;
490 rcv_desc->skb_size = MAX_RX_BUFFER_LENGTH;
491 break;
493 case RCV_DESC_JUMBO:
494 rcv_desc->max_rx_desc_count =
495 adapter->max_jumbo_rx_desc_count;
496 rcv_desc->flags = RCV_DESC_JUMBO;
497 rcv_desc->dma_size = RX_JUMBO_DMA_MAP_LEN;
498 rcv_desc->skb_size = MAX_RX_JUMBO_BUFFER_LENGTH;
499 break;
501 case RCV_RING_LRO:
502 rcv_desc->max_rx_desc_count =
503 adapter->max_lro_rx_desc_count;
504 rcv_desc->flags = RCV_DESC_LRO;
505 rcv_desc->dma_size = RX_LRO_DMA_MAP_LEN;
506 rcv_desc->skb_size = MAX_RX_LRO_BUFFER_LENGTH;
507 break;
510 rcv_desc->rx_buf_arr = (struct netxen_rx_buffer *)
511 vmalloc(RCV_BUFFSIZE);
513 if (rcv_desc->rx_buf_arr == NULL) {
514 printk(KERN_ERR "%s: Could not allocate"
515 "rcv_desc->rx_buf_arr memory:%d\n",
516 netxen_nic_driver_name,
517 (int)RCV_BUFFSIZE);
518 err = -ENOMEM;
519 goto err_out_free_rx_buffer;
521 memset(rcv_desc->rx_buf_arr, 0, RCV_BUFFSIZE);
526 netxen_initialize_adapter_sw(adapter); /* initialize the buffers in adapter */
528 /* Mezz cards have PCI function 0,2,3 enabled */
529 if ((adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ)
530 && (pci_func_id >= 2))
531 adapter->portnum = pci_func_id - 2;
533 #ifdef CONFIG_IA64
534 if(adapter->portnum == 0) {
535 netxen_pinit_from_rom(adapter, 0);
536 udelay(500);
537 netxen_load_firmware(adapter);
539 #endif
541 init_timer(&adapter->watchdog_timer);
542 adapter->ahw.xg_linkup = 0;
543 adapter->watchdog_timer.function = &netxen_watchdog;
544 adapter->watchdog_timer.data = (unsigned long)adapter;
545 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
546 adapter->ahw.pdev = pdev;
547 adapter->proc_cmd_buf_counter = 0;
548 adapter->ahw.revision_id = pdev->revision;
550 /* make sure Window == 1 */
551 netxen_nic_pci_change_crbwindow(adapter, 1);
553 netxen_nic_update_cmd_producer(adapter, 0);
554 netxen_nic_update_cmd_consumer(adapter, 0);
555 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_HOST_CMD_ADDR_LO));
557 if (netxen_is_flash_supported(adapter) == 0 &&
558 netxen_get_flash_mac_addr(adapter, mac_addr) == 0)
559 valid_mac = 1;
560 else
561 valid_mac = 0;
563 if (valid_mac) {
564 unsigned char *p = (unsigned char *)&mac_addr[adapter->portnum];
565 netdev->dev_addr[0] = *(p + 5);
566 netdev->dev_addr[1] = *(p + 4);
567 netdev->dev_addr[2] = *(p + 3);
568 netdev->dev_addr[3] = *(p + 2);
569 netdev->dev_addr[4] = *(p + 1);
570 netdev->dev_addr[5] = *(p + 0);
572 memcpy(netdev->perm_addr, netdev->dev_addr,
573 netdev->addr_len);
574 if (!is_valid_ether_addr(netdev->perm_addr)) {
575 printk(KERN_ERR "%s: Bad MAC address %s.\n",
576 netxen_nic_driver_name,
577 print_mac(mac, netdev->dev_addr));
578 } else {
579 if (adapter->macaddr_set)
580 adapter->macaddr_set(adapter,
581 netdev->dev_addr);
585 if (adapter->portnum == 0) {
586 err = netxen_initialize_adapter_offload(adapter);
587 if (err)
588 goto err_out_free_rx_buffer;
589 val = readl(NETXEN_CRB_NORMALIZE(adapter,
590 NETXEN_CAM_RAM(0x1fc)));
591 if (val == 0x55555555) {
592 /* This is the first boot after power up */
593 netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(0x4), &val);
594 if (!(val & 0x4)) {
595 val |= 0x4;
596 netxen_nic_write_w0(adapter, NETXEN_PCIE_REG(0x4), val);
597 netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(0x4), &val);
598 if (!(val & 0x4))
599 printk(KERN_ERR "%s: failed to set MSI bit in PCI-e reg\n",
600 netxen_nic_driver_name);
602 val = readl(NETXEN_CRB_NORMALIZE(adapter,
603 NETXEN_ROMUSB_GLB_SW_RESET));
604 printk(KERN_INFO"NetXen: read 0x%08x for reset reg.\n",val);
605 if (val != 0x80000f) {
606 /* clear the register for future unloads/loads */
607 writel(0, NETXEN_CRB_NORMALIZE(adapter,
608 NETXEN_CAM_RAM(0x1fc)));
609 printk(KERN_ERR "ERROR in NetXen HW init sequence.\n");
610 err = -ENODEV;
611 goto err_out_free_dev;
615 /* clear the register for future unloads/loads */
616 writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc)));
617 printk(KERN_INFO "State: 0x%0x\n",
618 readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)));
621 * Tell the hardware our version number.
623 i = (_NETXEN_NIC_LINUX_MAJOR << 16)
624 | ((_NETXEN_NIC_LINUX_MINOR << 8))
625 | (_NETXEN_NIC_LINUX_SUBVERSION);
626 writel(i, NETXEN_CRB_NORMALIZE(adapter, CRB_DRIVER_VERSION));
628 /* Unlock the HW, prompting the boot sequence */
629 writel(1,
630 NETXEN_CRB_NORMALIZE(adapter,
631 NETXEN_ROMUSB_GLB_PEGTUNE_DONE));
632 /* Handshake with the card before we register the devices. */
633 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
637 * See if the firmware gave us a virtual-physical port mapping.
639 i = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_V2P(adapter->portnum)));
640 if (i != 0x55555555)
641 physical_port[adapter->portnum] = i;
643 netif_carrier_off(netdev);
644 netif_stop_queue(netdev);
646 if ((err = register_netdev(netdev))) {
647 printk(KERN_ERR "%s: register_netdev failed port #%d"
648 " aborting\n", netxen_nic_driver_name,
649 adapter->portnum);
650 err = -EIO;
651 goto err_out_free_dev;
654 pci_set_drvdata(pdev, adapter);
656 switch (adapter->ahw.board_type) {
657 case NETXEN_NIC_GBE:
658 printk(KERN_INFO "%s: QUAD GbE board initialized\n",
659 netxen_nic_driver_name);
660 break;
662 case NETXEN_NIC_XGBE:
663 printk(KERN_INFO "%s: XGbE board initialized\n",
664 netxen_nic_driver_name);
665 break;
668 adapter->driver_mismatch = 0;
670 return 0;
672 err_out_free_dev:
673 if (adapter->portnum == 0)
674 netxen_free_adapter_offload(adapter);
676 err_out_free_rx_buffer:
677 for (i = 0; i < MAX_RCV_CTX; ++i) {
678 recv_ctx = &adapter->recv_ctx[i];
679 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
680 rcv_desc = &recv_ctx->rcv_desc[ring];
681 if (rcv_desc->rx_buf_arr != NULL) {
682 vfree(rcv_desc->rx_buf_arr);
683 rcv_desc->rx_buf_arr = NULL;
687 vfree(cmd_buf_arr);
689 err_out_free_adapter:
690 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
691 pci_disable_msi(pdev);
693 pci_set_drvdata(pdev, NULL);
695 if (db_ptr)
696 iounmap(db_ptr);
698 err_out_iounmap:
699 if (mem_ptr0)
700 iounmap(mem_ptr0);
701 if (mem_ptr1)
702 iounmap(mem_ptr1);
703 if (mem_ptr2)
704 iounmap(mem_ptr2);
706 err_out_free_netdev:
707 free_netdev(netdev);
709 err_out_free_res:
710 pci_release_regions(pdev);
712 err_out_disable_pdev:
713 pci_disable_device(pdev);
714 return err;
717 static void __devexit netxen_nic_remove(struct pci_dev *pdev)
719 struct netxen_adapter *adapter;
720 struct net_device *netdev;
721 struct netxen_rx_buffer *buffer;
722 struct netxen_recv_context *recv_ctx;
723 struct netxen_rcv_desc_ctx *rcv_desc;
724 int i, ctxid, ring;
725 static int init_firmware_done = 0;
727 adapter = pci_get_drvdata(pdev);
728 if (adapter == NULL)
729 return;
731 netdev = adapter->netdev;
733 unregister_netdev(netdev);
735 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
736 init_firmware_done++;
737 netxen_free_hw_resources(adapter);
740 for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) {
741 recv_ctx = &adapter->recv_ctx[ctxid];
742 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
743 rcv_desc = &recv_ctx->rcv_desc[ring];
744 for (i = 0; i < rcv_desc->max_rx_desc_count; ++i) {
745 buffer = &(rcv_desc->rx_buf_arr[i]);
746 if (buffer->state == NETXEN_BUFFER_FREE)
747 continue;
748 pci_unmap_single(pdev, buffer->dma,
749 rcv_desc->dma_size,
750 PCI_DMA_FROMDEVICE);
751 if (buffer->skb != NULL)
752 dev_kfree_skb_any(buffer->skb);
754 vfree(rcv_desc->rx_buf_arr);
758 vfree(adapter->cmd_buf_arr);
760 if (adapter->portnum == 0) {
761 if (init_firmware_done) {
762 i = 100;
763 do {
764 if (dma_watchdog_shutdown_request(adapter) == 1)
765 break;
766 msleep(100);
767 if (dma_watchdog_shutdown_poll_result(adapter) == 1)
768 break;
769 } while (--i);
771 if (i == 0)
772 printk(KERN_ERR "%s: dma_watchdog_shutdown failed\n",
773 netdev->name);
775 /* clear the register for future unloads/loads */
776 writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc)));
777 printk(KERN_INFO "State: 0x%0x\n",
778 readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)));
780 /* leave the hw in the same state as reboot */
781 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
782 netxen_pinit_from_rom(adapter, 0);
783 msleep(1);
784 netxen_load_firmware(adapter);
785 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
788 /* clear the register for future unloads/loads */
789 writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc)));
790 printk(KERN_INFO "State: 0x%0x\n",
791 readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)));
793 i = 100;
794 do {
795 if (dma_watchdog_shutdown_request(adapter) == 1)
796 break;
797 msleep(100);
798 if (dma_watchdog_shutdown_poll_result(adapter) == 1)
799 break;
800 } while (--i);
802 if (i) {
803 netxen_free_adapter_offload(adapter);
804 } else {
805 printk(KERN_ERR "%s: dma_watchdog_shutdown failed\n",
806 netdev->name);
810 if (adapter->irq)
811 free_irq(adapter->irq, adapter);
813 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
814 pci_disable_msi(pdev);
816 iounmap(adapter->ahw.db_base);
817 iounmap(adapter->ahw.pci_base0);
818 iounmap(adapter->ahw.pci_base1);
819 iounmap(adapter->ahw.pci_base2);
821 pci_release_regions(pdev);
822 pci_disable_device(pdev);
823 pci_set_drvdata(pdev, NULL);
825 free_netdev(netdev);
829 * Called when a network interface is made active
830 * @returns 0 on success, negative value on failure
832 static int netxen_nic_open(struct net_device *netdev)
834 struct netxen_adapter *adapter = (struct netxen_adapter *)netdev->priv;
835 int err = 0;
836 int ctx, ring;
838 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) {
839 err = netxen_init_firmware(adapter);
840 if (err != 0) {
841 printk(KERN_ERR "Failed to init firmware\n");
842 return -EIO;
844 netxen_nic_flash_print(adapter);
846 /* setup all the resources for the Phantom... */
847 /* this include the descriptors for rcv, tx, and status */
848 netxen_nic_clear_stats(adapter);
849 err = netxen_nic_hw_resources(adapter);
850 if (err) {
851 printk(KERN_ERR "Error in setting hw resources:%d\n",
852 err);
853 return err;
855 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
856 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++)
857 netxen_post_rx_buffers(adapter, ctx, ring);
859 adapter->irq = adapter->ahw.pdev->irq;
860 err = request_irq(adapter->ahw.pdev->irq, netxen_intr,
861 IRQF_SHARED|IRQF_SAMPLE_RANDOM, netdev->name,
862 adapter);
863 if (err) {
864 printk(KERN_ERR "request_irq failed with: %d\n", err);
865 netxen_free_hw_resources(adapter);
866 return err;
869 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
871 if (!adapter->driver_mismatch)
872 mod_timer(&adapter->watchdog_timer, jiffies);
874 napi_enable(&adapter->napi);
876 netxen_nic_enable_int(adapter);
878 /* Done here again so that even if phantom sw overwrote it,
879 * we set it */
880 if (adapter->init_port
881 && adapter->init_port(adapter, adapter->portnum) != 0) {
882 del_timer_sync(&adapter->watchdog_timer);
883 printk(KERN_ERR "%s: Failed to initialize port %d\n",
884 netxen_nic_driver_name, adapter->portnum);
885 napi_disable(&adapter->napi);
886 return -EIO;
888 if (adapter->macaddr_set)
889 adapter->macaddr_set(adapter, netdev->dev_addr);
891 netxen_nic_set_link_parameters(adapter);
893 netxen_nic_set_multi(netdev);
894 if (adapter->set_mtu)
895 adapter->set_mtu(adapter, netdev->mtu);
897 if (!adapter->driver_mismatch)
898 netif_start_queue(netdev);
900 return 0;
904 * netxen_nic_close - Disables a network interface entry point
906 static int netxen_nic_close(struct net_device *netdev)
908 struct netxen_adapter *adapter = netdev_priv(netdev);
909 int i, j;
910 struct netxen_cmd_buffer *cmd_buff;
911 struct netxen_skb_frag *buffrag;
913 netif_carrier_off(netdev);
914 netif_stop_queue(netdev);
915 napi_disable(&adapter->napi);
917 if (adapter->stop_port)
918 adapter->stop_port(adapter);
920 netxen_nic_disable_int(adapter);
922 cmd_buff = adapter->cmd_buf_arr;
923 for (i = 0; i < adapter->max_tx_desc_count; i++) {
924 buffrag = cmd_buff->frag_array;
925 if (buffrag->dma) {
926 pci_unmap_single(adapter->pdev, buffrag->dma,
927 buffrag->length, PCI_DMA_TODEVICE);
928 buffrag->dma = 0ULL;
930 for (j = 0; j < cmd_buff->frag_count; j++) {
931 buffrag++;
932 if (buffrag->dma) {
933 pci_unmap_page(adapter->pdev, buffrag->dma,
934 buffrag->length,
935 PCI_DMA_TODEVICE);
936 buffrag->dma = 0ULL;
939 /* Free the skb we received in netxen_nic_xmit_frame */
940 if (cmd_buff->skb) {
941 dev_kfree_skb_any(cmd_buff->skb);
942 cmd_buff->skb = NULL;
944 cmd_buff++;
946 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
947 FLUSH_SCHEDULED_WORK();
948 del_timer_sync(&adapter->watchdog_timer);
951 return 0;
954 static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
956 struct netxen_adapter *adapter = netdev_priv(netdev);
957 struct netxen_hardware_context *hw = &adapter->ahw;
958 unsigned int first_seg_len = skb->len - skb->data_len;
959 struct netxen_skb_frag *buffrag;
960 unsigned int i;
962 u32 producer = 0;
963 u32 saved_producer = 0;
964 struct cmd_desc_type0 *hwdesc;
965 int k;
966 struct netxen_cmd_buffer *pbuf = NULL;
967 static int dropped_packet = 0;
968 int frag_count;
969 u32 local_producer = 0;
970 u32 max_tx_desc_count = 0;
971 u32 last_cmd_consumer = 0;
972 int no_of_desc;
974 adapter->stats.xmitcalled++;
975 frag_count = skb_shinfo(skb)->nr_frags + 1;
977 if (unlikely(skb->len <= 0)) {
978 dev_kfree_skb_any(skb);
979 adapter->stats.badskblen++;
980 return NETDEV_TX_OK;
983 if (frag_count > MAX_BUFFERS_PER_CMD) {
984 printk("%s: %s netxen_nic_xmit_frame: frag_count (%d)"
985 "too large, can handle only %d frags\n",
986 netxen_nic_driver_name, netdev->name,
987 frag_count, MAX_BUFFERS_PER_CMD);
988 adapter->stats.txdropped++;
989 if ((++dropped_packet & 0xff) == 0xff)
990 printk("%s: %s droppped packets = %d\n",
991 netxen_nic_driver_name, netdev->name,
992 dropped_packet);
994 return NETDEV_TX_OK;
997 /* There 4 fragments per descriptor */
998 no_of_desc = (frag_count + 3) >> 2;
999 if (netdev->features & NETIF_F_TSO) {
1000 if (skb_shinfo(skb)->gso_size > 0) {
1002 no_of_desc++;
1003 if ((ip_hdrlen(skb) + tcp_hdrlen(skb) +
1004 sizeof(struct ethhdr)) >
1005 (sizeof(struct cmd_desc_type0) - 2)) {
1006 no_of_desc++;
1011 spin_lock_bh(&adapter->tx_lock);
1012 if (adapter->total_threads >= MAX_XMIT_PRODUCERS) {
1013 goto out_requeue;
1015 local_producer = adapter->cmd_producer;
1016 k = adapter->cmd_producer;
1017 max_tx_desc_count = adapter->max_tx_desc_count;
1018 last_cmd_consumer = adapter->last_cmd_consumer;
1019 if ((k + no_of_desc) >=
1020 ((last_cmd_consumer <= k) ? last_cmd_consumer + max_tx_desc_count :
1021 last_cmd_consumer)) {
1022 goto out_requeue;
1024 k = get_index_range(k, max_tx_desc_count, no_of_desc);
1025 adapter->cmd_producer = k;
1026 adapter->total_threads++;
1027 adapter->num_threads++;
1029 spin_unlock_bh(&adapter->tx_lock);
1030 /* Copy the descriptors into the hardware */
1031 producer = local_producer;
1032 saved_producer = producer;
1033 hwdesc = &hw->cmd_desc_head[producer];
1034 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
1035 /* Take skb->data itself */
1036 pbuf = &adapter->cmd_buf_arr[producer];
1037 if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) {
1038 pbuf->mss = skb_shinfo(skb)->gso_size;
1039 hwdesc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1040 } else {
1041 pbuf->mss = 0;
1042 hwdesc->mss = 0;
1044 pbuf->total_length = skb->len;
1045 pbuf->skb = skb;
1046 pbuf->cmd = TX_ETHER_PKT;
1047 pbuf->frag_count = frag_count;
1048 pbuf->port = adapter->portnum;
1049 buffrag = &pbuf->frag_array[0];
1050 buffrag->dma = pci_map_single(adapter->pdev, skb->data, first_seg_len,
1051 PCI_DMA_TODEVICE);
1052 buffrag->length = first_seg_len;
1053 netxen_set_cmd_desc_totallength(hwdesc, skb->len);
1054 netxen_set_cmd_desc_num_of_buff(hwdesc, frag_count);
1055 netxen_set_cmd_desc_opcode(hwdesc, TX_ETHER_PKT);
1057 netxen_set_cmd_desc_port(hwdesc, adapter->portnum);
1058 netxen_set_cmd_desc_ctxid(hwdesc, adapter->portnum);
1059 hwdesc->buffer1_length = cpu_to_le16(first_seg_len);
1060 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
1062 for (i = 1, k = 1; i < frag_count; i++, k++) {
1063 struct skb_frag_struct *frag;
1064 int len, temp_len;
1065 unsigned long offset;
1066 dma_addr_t temp_dma;
1068 /* move to next desc. if there is a need */
1069 if ((i & 0x3) == 0) {
1070 k = 0;
1071 producer = get_next_index(producer,
1072 adapter->max_tx_desc_count);
1073 hwdesc = &hw->cmd_desc_head[producer];
1074 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
1075 pbuf = &adapter->cmd_buf_arr[producer];
1076 pbuf->skb = NULL;
1078 frag = &skb_shinfo(skb)->frags[i - 1];
1079 len = frag->size;
1080 offset = frag->page_offset;
1082 temp_len = len;
1083 temp_dma = pci_map_page(adapter->pdev, frag->page, offset,
1084 len, PCI_DMA_TODEVICE);
1086 buffrag++;
1087 buffrag->dma = temp_dma;
1088 buffrag->length = temp_len;
1090 DPRINTK(INFO, "for loop. i=%d k=%d\n", i, k);
1091 switch (k) {
1092 case 0:
1093 hwdesc->buffer1_length = cpu_to_le16(temp_len);
1094 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
1095 break;
1096 case 1:
1097 hwdesc->buffer2_length = cpu_to_le16(temp_len);
1098 hwdesc->addr_buffer2 = cpu_to_le64(temp_dma);
1099 break;
1100 case 2:
1101 hwdesc->buffer3_length = cpu_to_le16(temp_len);
1102 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
1103 break;
1104 case 3:
1105 hwdesc->buffer4_length = cpu_to_le16(temp_len);
1106 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
1107 break;
1109 frag++;
1111 producer = get_next_index(producer, adapter->max_tx_desc_count);
1113 /* might change opcode to TX_TCP_LSO */
1114 netxen_tso_check(adapter, &hw->cmd_desc_head[saved_producer], skb);
1116 /* For LSO, we need to copy the MAC/IP/TCP headers into
1117 * the descriptor ring
1119 if (netxen_get_cmd_desc_opcode(&hw->cmd_desc_head[saved_producer])
1120 == TX_TCP_LSO) {
1121 int hdr_len, first_hdr_len, more_hdr;
1122 hdr_len = hw->cmd_desc_head[saved_producer].total_hdr_length;
1123 if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) {
1124 first_hdr_len = sizeof(struct cmd_desc_type0) - 2;
1125 more_hdr = 1;
1126 } else {
1127 first_hdr_len = hdr_len;
1128 more_hdr = 0;
1130 /* copy the MAC/IP/TCP headers to the cmd descriptor list */
1131 hwdesc = &hw->cmd_desc_head[producer];
1132 pbuf = &adapter->cmd_buf_arr[producer];
1133 pbuf->skb = NULL;
1135 /* copy the first 64 bytes */
1136 memcpy(((void *)hwdesc) + 2,
1137 (void *)(skb->data), first_hdr_len);
1138 producer = get_next_index(producer, max_tx_desc_count);
1140 if (more_hdr) {
1141 hwdesc = &hw->cmd_desc_head[producer];
1142 pbuf = &adapter->cmd_buf_arr[producer];
1143 pbuf->skb = NULL;
1144 /* copy the next 64 bytes - should be enough except
1145 * for pathological case
1147 skb_copy_from_linear_data_offset(skb, first_hdr_len,
1148 hwdesc,
1149 (hdr_len -
1150 first_hdr_len));
1151 producer = get_next_index(producer, max_tx_desc_count);
1155 spin_lock_bh(&adapter->tx_lock);
1156 adapter->stats.txbytes += skb->len;
1158 /* Code to update the adapter considering how many producer threads
1159 are currently working */
1160 if ((--adapter->num_threads) == 0) {
1161 /* This is the last thread */
1162 u32 crb_producer = adapter->cmd_producer;
1163 netxen_nic_update_cmd_producer(adapter, crb_producer);
1164 wmb();
1165 adapter->total_threads = 0;
1168 adapter->stats.xmitfinished++;
1169 netdev->trans_start = jiffies;
1171 spin_unlock_bh(&adapter->tx_lock);
1172 return NETDEV_TX_OK;
1174 out_requeue:
1175 netif_stop_queue(netdev);
1176 adapter->flags |= NETXEN_NETDEV_STATUS;
1178 spin_unlock_bh(&adapter->tx_lock);
1179 return NETDEV_TX_BUSY;
1182 static void netxen_watchdog(unsigned long v)
1184 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
1186 SCHEDULE_WORK(&adapter->watchdog_task);
1189 static void netxen_tx_timeout(struct net_device *netdev)
1191 struct netxen_adapter *adapter = (struct netxen_adapter *)
1192 netdev_priv(netdev);
1193 SCHEDULE_WORK(&adapter->tx_timeout_task);
1196 static void netxen_tx_timeout_task(struct work_struct *work)
1198 struct netxen_adapter *adapter =
1199 container_of(work, struct netxen_adapter, tx_timeout_task);
1201 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
1202 netxen_nic_driver_name, adapter->netdev->name);
1204 netxen_nic_close(adapter->netdev);
1205 netxen_nic_open(adapter->netdev);
1206 adapter->netdev->trans_start = jiffies;
1207 netif_wake_queue(adapter->netdev);
1210 static int
1211 netxen_handle_int(struct netxen_adapter *adapter, struct net_device *netdev)
1213 u32 ret = 0;
1215 DPRINTK(INFO, "Entered handle ISR\n");
1216 adapter->stats.ints++;
1218 netxen_nic_disable_int(adapter);
1220 if (netxen_nic_rx_has_work(adapter) || netxen_nic_tx_has_work(adapter)) {
1221 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
1223 * Interrupts are already disabled.
1225 __netif_rx_schedule(netdev, &adapter->napi);
1226 } else {
1227 static unsigned int intcount = 0;
1228 if ((++intcount & 0xfff) == 0xfff)
1229 DPRINTK(KERN_ERR
1230 "%s: %s interrupt %d while in poll\n",
1231 netxen_nic_driver_name, netdev->name,
1232 intcount);
1234 ret = 1;
1237 if (ret == 0) {
1238 netxen_nic_enable_int(adapter);
1241 return ret;
1245 * netxen_intr - Interrupt Handler
1246 * @irq: interrupt number
1247 * data points to adapter stucture (which may be handling more than 1 port
1249 irqreturn_t netxen_intr(int irq, void *data)
1251 struct netxen_adapter *adapter = data;
1252 struct net_device *netdev = adapter->netdev;
1253 u32 our_int = 0;
1255 if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) {
1256 our_int = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR));
1257 /* not our interrupt */
1258 if ((our_int & (0x80 << adapter->portnum)) == 0)
1259 return IRQ_NONE;
1262 if (adapter->intr_scheme == INTR_SCHEME_PERPORT) {
1263 /* claim interrupt */
1264 if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) {
1265 writel(our_int & ~((u32)(0x80 << adapter->portnum)),
1266 NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR));
1270 if (netif_running(netdev))
1271 netxen_handle_int(adapter, netdev);
1273 return IRQ_HANDLED;
1276 static int netxen_nic_poll(struct napi_struct *napi, int budget)
1278 struct netxen_adapter *adapter = container_of(napi, struct netxen_adapter, napi);
1279 struct net_device *netdev = adapter->netdev;
1280 int done = 1;
1281 int ctx;
1282 int work_done;
1284 DPRINTK(INFO, "polling for %d descriptors\n", *budget);
1286 work_done = 0;
1287 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
1289 * Fairness issue. This will give undue weight to the
1290 * receive context 0.
1294 * To avoid starvation, we give each of our receivers,
1295 * a fraction of the quota. Sometimes, it might happen that we
1296 * have enough quota to process every packet, but since all the
1297 * packets are on one context, it gets only half of the quota,
1298 * and ends up not processing it.
1300 work_done += netxen_process_rcv_ring(adapter, ctx,
1301 budget / MAX_RCV_CTX);
1304 if (work_done >= budget)
1305 done = 0;
1307 if (netxen_process_cmd_ring((unsigned long)adapter) == 0)
1308 done = 0;
1310 DPRINTK(INFO, "new work_done: %d work_to_do: %d\n",
1311 work_done, work_to_do);
1312 if (done) {
1313 netif_rx_complete(netdev, napi);
1314 netxen_nic_enable_int(adapter);
1317 return work_done;
1320 #ifdef CONFIG_NET_POLL_CONTROLLER
1321 static void netxen_nic_poll_controller(struct net_device *netdev)
1323 struct netxen_adapter *adapter = netdev_priv(netdev);
1324 disable_irq(adapter->irq);
1325 netxen_intr(adapter->irq, adapter);
1326 enable_irq(adapter->irq);
1328 #endif
1330 static struct pci_driver netxen_driver = {
1331 .name = netxen_nic_driver_name,
1332 .id_table = netxen_pci_tbl,
1333 .probe = netxen_nic_probe,
1334 .remove = __devexit_p(netxen_nic_remove)
1337 /* Driver Registration on NetXen card */
1339 static int __init netxen_init_module(void)
1341 if ((netxen_workq = create_singlethread_workqueue("netxen")) == 0)
1342 return -ENOMEM;
1344 return pci_register_driver(&netxen_driver);
1347 module_init(netxen_init_module);
1349 static void __exit netxen_exit_module(void)
1352 * Wait for some time to allow the dma to drain, if any.
1354 msleep(100);
1355 pci_unregister_driver(&netxen_driver);
1356 destroy_workqueue(netxen_workq);
1359 module_exit(netxen_exit_module);