[ALSA] oxygen: more initialization
[zen-stable.git] / drivers / net / netxen / netxen_nic_main.c
blob9737eae5ef111f265345e1747d008cad953fb7db
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 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 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
152 static void netxen_nic_disable_int(struct netxen_adapter *adapter)
154 uint32_t mask = 0x7ff;
155 int retries = 32;
157 DPRINTK(1, INFO, "Entered ISR Disable \n");
159 switch (adapter->portnum) {
160 case 0:
161 writel(0x0, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_0));
162 break;
163 case 1:
164 writel(0x0, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_1));
165 break;
166 case 2:
167 writel(0x0, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_2));
168 break;
169 case 3:
170 writel(0x0, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_3));
171 break;
174 if (adapter->intr_scheme != -1 &&
175 adapter->intr_scheme != INTR_SCHEME_PERPORT)
176 writel(mask,PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_MASK));
178 /* Window = 0 or 1 */
179 if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) {
180 do {
181 writel(0xffffffff,
182 PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_TARGET_STATUS));
183 mask = readl(pci_base_offset(adapter, ISR_INT_VECTOR));
184 if (!(mask & 0x80))
185 break;
186 udelay(10);
187 } while (--retries);
189 if (!retries) {
190 printk(KERN_NOTICE "%s: Failed to disable interrupt completely\n",
191 netxen_nic_driver_name);
195 DPRINTK(1, INFO, "Done with Disable Int\n");
198 static void netxen_nic_enable_int(struct netxen_adapter *adapter)
200 u32 mask;
202 DPRINTK(1, INFO, "Entered ISR Enable \n");
204 if (adapter->intr_scheme != -1 &&
205 adapter->intr_scheme != INTR_SCHEME_PERPORT) {
206 switch (adapter->ahw.board_type) {
207 case NETXEN_NIC_GBE:
208 mask = 0x77b;
209 break;
210 case NETXEN_NIC_XGBE:
211 mask = 0x77f;
212 break;
213 default:
214 mask = 0x7ff;
215 break;
218 writel(mask, PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_MASK));
221 switch (adapter->portnum) {
222 case 0:
223 writel(0x1, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_0));
224 break;
225 case 1:
226 writel(0x1, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_1));
227 break;
228 case 2:
229 writel(0x1, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_2));
230 break;
231 case 3:
232 writel(0x1, NETXEN_CRB_NORMALIZE(adapter, CRB_SW_INT_MASK_3));
233 break;
236 if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) {
237 mask = 0xbff;
238 if (adapter->intr_scheme != -1 &&
239 adapter->intr_scheme != INTR_SCHEME_PERPORT) {
240 writel(0X0, NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR));
242 writel(mask,
243 PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_TARGET_MASK));
246 DPRINTK(1, INFO, "Done with enable Int\n");
250 * netxen_nic_probe()
252 * The Linux system will invoke this after identifying the vendor ID and
253 * device Id in the pci_tbl supported by this module.
255 * A quad port card has one operational PCI config space, (function 0),
256 * which is used to access all four ports.
258 * This routine will initialize the adapter, and setup the global parameters
259 * along with the port's specific structure.
261 static int __devinit
262 netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
264 struct net_device *netdev = NULL;
265 struct netxen_adapter *adapter = NULL;
266 void __iomem *mem_ptr0 = NULL;
267 void __iomem *mem_ptr1 = NULL;
268 void __iomem *mem_ptr2 = NULL;
269 unsigned long first_page_group_end;
270 unsigned long first_page_group_start;
273 u8 __iomem *db_ptr = NULL;
274 unsigned long mem_base, mem_len, db_base, db_len;
275 int pci_using_dac, i = 0, err;
276 int ring;
277 struct netxen_recv_context *recv_ctx = NULL;
278 struct netxen_rcv_desc_ctx *rcv_desc = NULL;
279 struct netxen_cmd_buffer *cmd_buf_arr = NULL;
280 __le64 mac_addr[FLASH_NUM_PORTS + 1];
281 int valid_mac = 0;
282 u32 val;
283 int pci_func_id = PCI_FUNC(pdev->devfn);
284 DECLARE_MAC_BUF(mac);
286 printk(KERN_INFO "%s \n", netxen_nic_driver_string);
288 if (pdev->class != 0x020000) {
289 printk(KERN_ERR"NetXen function %d, class %x will not "
290 "be enabled.\n",pci_func_id, pdev->class);
291 return -ENODEV;
293 if ((err = pci_enable_device(pdev)))
294 return err;
295 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
296 err = -ENODEV;
297 goto err_out_disable_pdev;
300 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
301 goto err_out_disable_pdev;
303 pci_set_master(pdev);
304 if (pdev->revision == NX_P2_C1 &&
305 (pci_set_dma_mask(pdev, DMA_35BIT_MASK) == 0) &&
306 (pci_set_consistent_dma_mask(pdev, DMA_35BIT_MASK) == 0)) {
307 pci_using_dac = 1;
308 } else {
309 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) ||
310 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK)))
311 goto err_out_free_res;
313 pci_using_dac = 0;
317 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
318 if(!netdev) {
319 printk(KERN_ERR"%s: Failed to allocate memory for the "
320 "device block.Check system memory resource"
321 " usage.\n", netxen_nic_driver_name);
322 goto err_out_free_res;
325 SET_NETDEV_DEV(netdev, &pdev->dev);
327 adapter = netdev->priv;
329 adapter->ahw.pdev = pdev;
330 adapter->ahw.pci_func = pci_func_id;
331 spin_lock_init(&adapter->tx_lock);
333 /* remap phys address */
334 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
335 mem_len = pci_resource_len(pdev, 0);
337 /* 128 Meg of memory */
338 if (mem_len == NETXEN_PCI_128MB_SIZE) {
339 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
340 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
341 SECOND_PAGE_GROUP_SIZE);
342 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
343 THIRD_PAGE_GROUP_SIZE);
344 first_page_group_start = FIRST_PAGE_GROUP_START;
345 first_page_group_end = FIRST_PAGE_GROUP_END;
346 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
347 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
348 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
349 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
350 first_page_group_start = 0;
351 first_page_group_end = 0;
352 } else {
353 err = -EIO;
354 goto err_out_free_netdev;
357 if ((!mem_ptr0 && mem_len == NETXEN_PCI_128MB_SIZE) ||
358 !mem_ptr1 || !mem_ptr2) {
359 DPRINTK(ERR,
360 "Cannot remap adapter memory aborting.:"
361 "0 -> %p, 1 -> %p, 2 -> %p\n",
362 mem_ptr0, mem_ptr1, mem_ptr2);
364 err = -EIO;
365 goto err_out_iounmap;
367 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
368 db_len = pci_resource_len(pdev, 4);
370 if (db_len == 0) {
371 printk(KERN_ERR "%s: doorbell is disabled\n",
372 netxen_nic_driver_name);
373 err = -EIO;
374 goto err_out_iounmap;
376 DPRINTK(INFO, "doorbell ioremap from %lx a size of %lx\n", db_base,
377 db_len);
379 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
380 if (!db_ptr) {
381 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
382 netxen_nic_driver_name);
383 err = -EIO;
384 goto err_out_iounmap;
386 DPRINTK(INFO, "doorbell ioremaped at %p\n", db_ptr);
388 adapter->ahw.pci_base0 = mem_ptr0;
389 adapter->ahw.first_page_group_start = first_page_group_start;
390 adapter->ahw.first_page_group_end = first_page_group_end;
391 adapter->ahw.pci_base1 = mem_ptr1;
392 adapter->ahw.pci_base2 = mem_ptr2;
393 adapter->ahw.db_base = db_ptr;
394 adapter->ahw.db_len = db_len;
396 adapter->netdev = netdev;
397 adapter->pdev = pdev;
399 netif_napi_add(netdev, &adapter->napi,
400 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
402 /* this will be read from FW later */
403 adapter->intr_scheme = -1;
405 /* This will be reset for mezz cards */
406 adapter->portnum = pci_func_id;
407 adapter->status &= ~NETXEN_NETDEV_STATUS;
408 adapter->rx_csum = 1;
410 netdev->open = netxen_nic_open;
411 netdev->stop = netxen_nic_close;
412 netdev->hard_start_xmit = netxen_nic_xmit_frame;
413 netdev->get_stats = netxen_nic_get_stats;
414 netdev->set_multicast_list = netxen_nic_set_multi;
415 netdev->set_mac_address = netxen_nic_set_mac;
416 netdev->change_mtu = netxen_nic_change_mtu;
417 netdev->tx_timeout = netxen_tx_timeout;
418 netdev->watchdog_timeo = HZ;
420 netxen_nic_change_mtu(netdev, netdev->mtu);
422 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
423 #ifdef CONFIG_NET_POLL_CONTROLLER
424 netdev->poll_controller = netxen_nic_poll_controller;
425 #endif
426 /* ScatterGather support */
427 netdev->features = NETIF_F_SG;
428 netdev->features |= NETIF_F_IP_CSUM;
429 netdev->features |= NETIF_F_TSO;
431 if (pci_using_dac)
432 netdev->features |= NETIF_F_HIGHDMA;
434 if (pci_enable_msi(pdev))
435 adapter->flags &= ~NETXEN_NIC_MSI_ENABLED;
436 else
437 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
439 netdev->irq = pdev->irq;
440 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
443 * Set the CRB window to invalid. If any register in window 0 is
444 * accessed it should set the window to 0 and then reset it to 1.
446 adapter->curr_window = 255;
448 /* initialize the adapter */
449 netxen_initialize_adapter_hw(adapter);
452 * Adapter in our case is quad port so initialize it before
453 * initializing the ports
456 netxen_initialize_adapter_ops(adapter);
458 adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS_HOST;
459 if ((adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB35_4G) ||
460 (adapter->ahw.boardcfg.board_type ==
461 NETXEN_BRDTYPE_P2_SB31_2G))
462 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
463 else
464 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS;
465 adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS;
466 adapter->max_lro_rx_desc_count = MAX_LRO_RCV_DESCRIPTORS;
468 cmd_buf_arr = (struct netxen_cmd_buffer *)vmalloc(TX_RINGSIZE);
469 if (cmd_buf_arr == NULL) {
470 printk(KERN_ERR
471 "%s: Could not allocate cmd_buf_arr memory:%d\n",
472 netxen_nic_driver_name, (int)TX_RINGSIZE);
473 err = -ENOMEM;
474 goto err_out_free_adapter;
476 memset(cmd_buf_arr, 0, TX_RINGSIZE);
477 adapter->cmd_buf_arr = cmd_buf_arr;
479 for (i = 0; i < MAX_RCV_CTX; ++i) {
480 recv_ctx = &adapter->recv_ctx[i];
481 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
482 rcv_desc = &recv_ctx->rcv_desc[ring];
483 switch (RCV_DESC_TYPE(ring)) {
484 case RCV_DESC_NORMAL:
485 rcv_desc->max_rx_desc_count =
486 adapter->max_rx_desc_count;
487 rcv_desc->flags = RCV_DESC_NORMAL;
488 rcv_desc->dma_size = RX_DMA_MAP_LEN;
489 rcv_desc->skb_size = MAX_RX_BUFFER_LENGTH;
490 break;
492 case RCV_DESC_JUMBO:
493 rcv_desc->max_rx_desc_count =
494 adapter->max_jumbo_rx_desc_count;
495 rcv_desc->flags = RCV_DESC_JUMBO;
496 rcv_desc->dma_size = RX_JUMBO_DMA_MAP_LEN;
497 rcv_desc->skb_size = MAX_RX_JUMBO_BUFFER_LENGTH;
498 break;
500 case RCV_RING_LRO:
501 rcv_desc->max_rx_desc_count =
502 adapter->max_lro_rx_desc_count;
503 rcv_desc->flags = RCV_DESC_LRO;
504 rcv_desc->dma_size = RX_LRO_DMA_MAP_LEN;
505 rcv_desc->skb_size = MAX_RX_LRO_BUFFER_LENGTH;
506 break;
509 rcv_desc->rx_buf_arr = (struct netxen_rx_buffer *)
510 vmalloc(RCV_BUFFSIZE);
512 if (rcv_desc->rx_buf_arr == NULL) {
513 printk(KERN_ERR "%s: Could not allocate "
514 "rcv_desc->rx_buf_arr memory:%d\n",
515 netxen_nic_driver_name,
516 (int)RCV_BUFFSIZE);
517 err = -ENOMEM;
518 goto err_out_free_rx_buffer;
520 memset(rcv_desc->rx_buf_arr, 0, RCV_BUFFSIZE);
525 netxen_initialize_adapter_sw(adapter); /* initialize the buffers in adapter */
527 /* Mezz cards have PCI function 0,2,3 enabled */
528 if ((adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ)
529 && (pci_func_id >= 2))
530 adapter->portnum = pci_func_id - 2;
532 #ifdef CONFIG_IA64
533 if(adapter->portnum == 0) {
534 netxen_pinit_from_rom(adapter, 0);
535 udelay(500);
536 netxen_load_firmware(adapter);
538 #endif
540 init_timer(&adapter->watchdog_timer);
541 adapter->ahw.xg_linkup = 0;
542 adapter->watchdog_timer.function = &netxen_watchdog;
543 adapter->watchdog_timer.data = (unsigned long)adapter;
544 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
545 adapter->ahw.pdev = pdev;
546 adapter->proc_cmd_buf_counter = 0;
547 adapter->ahw.revision_id = pdev->revision;
549 /* make sure Window == 1 */
550 netxen_nic_pci_change_crbwindow(adapter, 1);
552 netxen_nic_update_cmd_producer(adapter, 0);
553 netxen_nic_update_cmd_consumer(adapter, 0);
554 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_HOST_CMD_ADDR_LO));
556 if (netxen_is_flash_supported(adapter) == 0 &&
557 netxen_get_flash_mac_addr(adapter, mac_addr) == 0)
558 valid_mac = 1;
559 else
560 valid_mac = 0;
562 if (valid_mac) {
563 unsigned char *p = (unsigned char *)&mac_addr[adapter->portnum];
564 netdev->dev_addr[0] = *(p + 5);
565 netdev->dev_addr[1] = *(p + 4);
566 netdev->dev_addr[2] = *(p + 3);
567 netdev->dev_addr[3] = *(p + 2);
568 netdev->dev_addr[4] = *(p + 1);
569 netdev->dev_addr[5] = *(p + 0);
571 memcpy(netdev->perm_addr, netdev->dev_addr,
572 netdev->addr_len);
573 if (!is_valid_ether_addr(netdev->perm_addr)) {
574 printk(KERN_ERR "%s: Bad MAC address %s.\n",
575 netxen_nic_driver_name,
576 print_mac(mac, netdev->dev_addr));
577 } else {
578 if (adapter->macaddr_set)
579 adapter->macaddr_set(adapter,
580 netdev->dev_addr);
584 if (adapter->portnum == 0) {
585 err = netxen_initialize_adapter_offload(adapter);
586 if (err)
587 goto err_out_free_rx_buffer;
588 val = readl(NETXEN_CRB_NORMALIZE(adapter,
589 NETXEN_CAM_RAM(0x1fc)));
590 if (val == 0x55555555) {
591 /* This is the first boot after power up */
592 netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(0x4), &val);
593 if (!(val & 0x4)) {
594 val |= 0x4;
595 netxen_nic_write_w0(adapter, NETXEN_PCIE_REG(0x4), val);
596 netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(0x4), &val);
597 if (!(val & 0x4))
598 printk(KERN_ERR "%s: failed to set MSI bit in PCI-e reg\n",
599 netxen_nic_driver_name);
601 val = readl(NETXEN_CRB_NORMALIZE(adapter,
602 NETXEN_ROMUSB_GLB_SW_RESET));
603 printk(KERN_INFO"NetXen: read 0x%08x for reset reg.\n",val);
604 if (val != 0x80000f) {
605 /* clear the register for future unloads/loads */
606 writel(0, NETXEN_CRB_NORMALIZE(adapter,
607 NETXEN_CAM_RAM(0x1fc)));
608 printk(KERN_ERR "ERROR in NetXen HW init sequence.\n");
609 err = -ENODEV;
610 goto err_out_free_dev;
614 /* clear the register for future unloads/loads */
615 writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc)));
616 printk(KERN_INFO "State: 0x%0x\n",
617 readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)));
620 * Tell the hardware our version number.
622 i = (_NETXEN_NIC_LINUX_MAJOR << 16)
623 | ((_NETXEN_NIC_LINUX_MINOR << 8))
624 | (_NETXEN_NIC_LINUX_SUBVERSION);
625 writel(i, NETXEN_CRB_NORMALIZE(adapter, CRB_DRIVER_VERSION));
627 /* Unlock the HW, prompting the boot sequence */
628 writel(1,
629 NETXEN_CRB_NORMALIZE(adapter,
630 NETXEN_ROMUSB_GLB_PEGTUNE_DONE));
631 /* Handshake with the card before we register the devices. */
632 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
636 * See if the firmware gave us a virtual-physical port mapping.
638 i = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_V2P(adapter->portnum)));
639 if (i != 0x55555555)
640 physical_port[adapter->portnum] = i;
642 netif_carrier_off(netdev);
643 netif_stop_queue(netdev);
645 if ((err = register_netdev(netdev))) {
646 printk(KERN_ERR "%s: register_netdev failed port #%d"
647 " aborting\n", netxen_nic_driver_name,
648 adapter->portnum);
649 err = -EIO;
650 goto err_out_free_dev;
653 pci_set_drvdata(pdev, adapter);
655 switch (adapter->ahw.board_type) {
656 case NETXEN_NIC_GBE:
657 printk(KERN_INFO "%s: QUAD GbE board initialized\n",
658 netxen_nic_driver_name);
659 break;
661 case NETXEN_NIC_XGBE:
662 printk(KERN_INFO "%s: XGbE board initialized\n",
663 netxen_nic_driver_name);
664 break;
667 adapter->driver_mismatch = 0;
669 return 0;
671 err_out_free_dev:
672 if (adapter->portnum == 0)
673 netxen_free_adapter_offload(adapter);
675 err_out_free_rx_buffer:
676 for (i = 0; i < MAX_RCV_CTX; ++i) {
677 recv_ctx = &adapter->recv_ctx[i];
678 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
679 rcv_desc = &recv_ctx->rcv_desc[ring];
680 if (rcv_desc->rx_buf_arr != NULL) {
681 vfree(rcv_desc->rx_buf_arr);
682 rcv_desc->rx_buf_arr = NULL;
686 vfree(cmd_buf_arr);
688 err_out_free_adapter:
689 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
690 pci_disable_msi(pdev);
692 pci_set_drvdata(pdev, NULL);
694 if (db_ptr)
695 iounmap(db_ptr);
697 err_out_iounmap:
698 if (mem_ptr0)
699 iounmap(mem_ptr0);
700 if (mem_ptr1)
701 iounmap(mem_ptr1);
702 if (mem_ptr2)
703 iounmap(mem_ptr2);
705 err_out_free_netdev:
706 free_netdev(netdev);
708 err_out_free_res:
709 pci_release_regions(pdev);
711 err_out_disable_pdev:
712 pci_disable_device(pdev);
713 return err;
716 static void __devexit netxen_nic_remove(struct pci_dev *pdev)
718 struct netxen_adapter *adapter;
719 struct net_device *netdev;
720 struct netxen_rx_buffer *buffer;
721 struct netxen_recv_context *recv_ctx;
722 struct netxen_rcv_desc_ctx *rcv_desc;
723 int i, ctxid, ring;
724 static int init_firmware_done = 0;
726 adapter = pci_get_drvdata(pdev);
727 if (adapter == NULL)
728 return;
730 netdev = adapter->netdev;
732 unregister_netdev(netdev);
734 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
735 init_firmware_done++;
736 netxen_free_hw_resources(adapter);
739 for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) {
740 recv_ctx = &adapter->recv_ctx[ctxid];
741 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
742 rcv_desc = &recv_ctx->rcv_desc[ring];
743 for (i = 0; i < rcv_desc->max_rx_desc_count; ++i) {
744 buffer = &(rcv_desc->rx_buf_arr[i]);
745 if (buffer->state == NETXEN_BUFFER_FREE)
746 continue;
747 pci_unmap_single(pdev, buffer->dma,
748 rcv_desc->dma_size,
749 PCI_DMA_FROMDEVICE);
750 if (buffer->skb != NULL)
751 dev_kfree_skb_any(buffer->skb);
753 vfree(rcv_desc->rx_buf_arr);
757 vfree(adapter->cmd_buf_arr);
759 if (adapter->portnum == 0) {
760 if (init_firmware_done) {
761 i = 100;
762 do {
763 if (dma_watchdog_shutdown_request(adapter) == 1)
764 break;
765 msleep(100);
766 if (dma_watchdog_shutdown_poll_result(adapter) == 1)
767 break;
768 } while (--i);
770 if (i == 0)
771 printk(KERN_ERR "%s: dma_watchdog_shutdown failed\n",
772 netdev->name);
774 /* clear the register for future unloads/loads */
775 writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc)));
776 printk(KERN_INFO "State: 0x%0x\n",
777 readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)));
779 /* leave the hw in the same state as reboot */
780 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
781 netxen_pinit_from_rom(adapter, 0);
782 msleep(1);
783 netxen_load_firmware(adapter);
784 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
787 /* clear the register for future unloads/loads */
788 writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc)));
789 printk(KERN_INFO "State: 0x%0x\n",
790 readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)));
792 i = 100;
793 do {
794 if (dma_watchdog_shutdown_request(adapter) == 1)
795 break;
796 msleep(100);
797 if (dma_watchdog_shutdown_poll_result(adapter) == 1)
798 break;
799 } while (--i);
801 if (i) {
802 netxen_free_adapter_offload(adapter);
803 } else {
804 printk(KERN_ERR "%s: dma_watchdog_shutdown failed\n",
805 netdev->name);
809 if (adapter->irq)
810 free_irq(adapter->irq, adapter);
812 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
813 pci_disable_msi(pdev);
815 iounmap(adapter->ahw.db_base);
816 iounmap(adapter->ahw.pci_base0);
817 iounmap(adapter->ahw.pci_base1);
818 iounmap(adapter->ahw.pci_base2);
820 pci_release_regions(pdev);
821 pci_disable_device(pdev);
822 pci_set_drvdata(pdev, NULL);
824 free_netdev(netdev);
828 * Called when a network interface is made active
829 * @returns 0 on success, negative value on failure
831 static int netxen_nic_open(struct net_device *netdev)
833 struct netxen_adapter *adapter = (struct netxen_adapter *)netdev->priv;
834 int err = 0;
835 int ctx, ring;
837 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) {
838 err = netxen_init_firmware(adapter);
839 if (err != 0) {
840 printk(KERN_ERR "Failed to init firmware\n");
841 return -EIO;
843 netxen_nic_flash_print(adapter);
845 /* setup all the resources for the Phantom... */
846 /* this include the descriptors for rcv, tx, and status */
847 netxen_nic_clear_stats(adapter);
848 err = netxen_nic_hw_resources(adapter);
849 if (err) {
850 printk(KERN_ERR "Error in setting hw resources:%d\n",
851 err);
852 return err;
854 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
855 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++)
856 netxen_post_rx_buffers(adapter, ctx, ring);
858 adapter->irq = adapter->ahw.pdev->irq;
859 err = request_irq(adapter->ahw.pdev->irq, netxen_intr,
860 IRQF_SHARED|IRQF_SAMPLE_RANDOM, netdev->name,
861 adapter);
862 if (err) {
863 printk(KERN_ERR "request_irq failed with: %d\n", err);
864 netxen_free_hw_resources(adapter);
865 return err;
868 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
870 if (!adapter->driver_mismatch)
871 mod_timer(&adapter->watchdog_timer, jiffies);
873 napi_enable(&adapter->napi);
875 netxen_nic_enable_int(adapter);
877 /* Done here again so that even if phantom sw overwrote it,
878 * we set it */
879 if (adapter->init_port
880 && adapter->init_port(adapter, adapter->portnum) != 0) {
881 del_timer_sync(&adapter->watchdog_timer);
882 printk(KERN_ERR "%s: Failed to initialize port %d\n",
883 netxen_nic_driver_name, adapter->portnum);
884 napi_disable(&adapter->napi);
885 return -EIO;
887 if (adapter->macaddr_set)
888 adapter->macaddr_set(adapter, netdev->dev_addr);
890 netxen_nic_set_link_parameters(adapter);
892 netxen_nic_set_multi(netdev);
893 if (adapter->set_mtu)
894 adapter->set_mtu(adapter, netdev->mtu);
896 if (!adapter->driver_mismatch)
897 netif_start_queue(netdev);
899 return 0;
903 * netxen_nic_close - Disables a network interface entry point
905 static int netxen_nic_close(struct net_device *netdev)
907 struct netxen_adapter *adapter = netdev_priv(netdev);
908 int i, j;
909 struct netxen_cmd_buffer *cmd_buff;
910 struct netxen_skb_frag *buffrag;
912 netif_carrier_off(netdev);
913 netif_stop_queue(netdev);
914 napi_disable(&adapter->napi);
916 if (adapter->stop_port)
917 adapter->stop_port(adapter);
919 netxen_nic_disable_int(adapter);
921 cmd_buff = adapter->cmd_buf_arr;
922 for (i = 0; i < adapter->max_tx_desc_count; i++) {
923 buffrag = cmd_buff->frag_array;
924 if (buffrag->dma) {
925 pci_unmap_single(adapter->pdev, buffrag->dma,
926 buffrag->length, PCI_DMA_TODEVICE);
927 buffrag->dma = 0ULL;
929 for (j = 0; j < cmd_buff->frag_count; j++) {
930 buffrag++;
931 if (buffrag->dma) {
932 pci_unmap_page(adapter->pdev, buffrag->dma,
933 buffrag->length,
934 PCI_DMA_TODEVICE);
935 buffrag->dma = 0ULL;
938 /* Free the skb we received in netxen_nic_xmit_frame */
939 if (cmd_buff->skb) {
940 dev_kfree_skb_any(cmd_buff->skb);
941 cmd_buff->skb = NULL;
943 cmd_buff++;
945 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
946 FLUSH_SCHEDULED_WORK();
947 del_timer_sync(&adapter->watchdog_timer);
950 return 0;
953 static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
955 struct netxen_adapter *adapter = netdev_priv(netdev);
956 struct netxen_hardware_context *hw = &adapter->ahw;
957 unsigned int first_seg_len = skb->len - skb->data_len;
958 struct netxen_skb_frag *buffrag;
959 unsigned int i;
961 u32 producer = 0;
962 u32 saved_producer = 0;
963 struct cmd_desc_type0 *hwdesc;
964 int k;
965 struct netxen_cmd_buffer *pbuf = NULL;
966 static int dropped_packet = 0;
967 int frag_count;
968 u32 local_producer = 0;
969 u32 max_tx_desc_count = 0;
970 u32 last_cmd_consumer = 0;
971 int no_of_desc;
973 adapter->stats.xmitcalled++;
974 frag_count = skb_shinfo(skb)->nr_frags + 1;
976 if (unlikely(skb->len <= 0)) {
977 dev_kfree_skb_any(skb);
978 adapter->stats.badskblen++;
979 return NETDEV_TX_OK;
982 if (frag_count > MAX_BUFFERS_PER_CMD) {
983 printk("%s: %s netxen_nic_xmit_frame: frag_count (%d) "
984 "too large, can handle only %d frags\n",
985 netxen_nic_driver_name, netdev->name,
986 frag_count, MAX_BUFFERS_PER_CMD);
987 adapter->stats.txdropped++;
988 if ((++dropped_packet & 0xff) == 0xff)
989 printk("%s: %s droppped packets = %d\n",
990 netxen_nic_driver_name, netdev->name,
991 dropped_packet);
993 return NETDEV_TX_OK;
996 /* There 4 fragments per descriptor */
997 no_of_desc = (frag_count + 3) >> 2;
998 if (netdev->features & NETIF_F_TSO) {
999 if (skb_shinfo(skb)->gso_size > 0) {
1001 no_of_desc++;
1002 if ((ip_hdrlen(skb) + tcp_hdrlen(skb) +
1003 sizeof(struct ethhdr)) >
1004 (sizeof(struct cmd_desc_type0) - 2)) {
1005 no_of_desc++;
1010 spin_lock_bh(&adapter->tx_lock);
1011 if (adapter->total_threads >= MAX_XMIT_PRODUCERS) {
1012 goto out_requeue;
1014 local_producer = adapter->cmd_producer;
1015 k = adapter->cmd_producer;
1016 max_tx_desc_count = adapter->max_tx_desc_count;
1017 last_cmd_consumer = adapter->last_cmd_consumer;
1018 if ((k + no_of_desc) >=
1019 ((last_cmd_consumer <= k) ? last_cmd_consumer + max_tx_desc_count :
1020 last_cmd_consumer)) {
1021 goto out_requeue;
1023 k = get_index_range(k, max_tx_desc_count, no_of_desc);
1024 adapter->cmd_producer = k;
1025 adapter->total_threads++;
1026 adapter->num_threads++;
1028 spin_unlock_bh(&adapter->tx_lock);
1029 /* Copy the descriptors into the hardware */
1030 producer = local_producer;
1031 saved_producer = producer;
1032 hwdesc = &hw->cmd_desc_head[producer];
1033 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
1034 /* Take skb->data itself */
1035 pbuf = &adapter->cmd_buf_arr[producer];
1036 if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) {
1037 pbuf->mss = skb_shinfo(skb)->gso_size;
1038 hwdesc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1039 } else {
1040 pbuf->mss = 0;
1041 hwdesc->mss = 0;
1043 pbuf->total_length = skb->len;
1044 pbuf->skb = skb;
1045 pbuf->cmd = TX_ETHER_PKT;
1046 pbuf->frag_count = frag_count;
1047 pbuf->port = adapter->portnum;
1048 buffrag = &pbuf->frag_array[0];
1049 buffrag->dma = pci_map_single(adapter->pdev, skb->data, first_seg_len,
1050 PCI_DMA_TODEVICE);
1051 buffrag->length = first_seg_len;
1052 netxen_set_cmd_desc_totallength(hwdesc, skb->len);
1053 netxen_set_cmd_desc_num_of_buff(hwdesc, frag_count);
1054 netxen_set_cmd_desc_opcode(hwdesc, TX_ETHER_PKT);
1056 netxen_set_cmd_desc_port(hwdesc, adapter->portnum);
1057 netxen_set_cmd_desc_ctxid(hwdesc, adapter->portnum);
1058 hwdesc->buffer1_length = cpu_to_le16(first_seg_len);
1059 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
1061 for (i = 1, k = 1; i < frag_count; i++, k++) {
1062 struct skb_frag_struct *frag;
1063 int len, temp_len;
1064 unsigned long offset;
1065 dma_addr_t temp_dma;
1067 /* move to next desc. if there is a need */
1068 if ((i & 0x3) == 0) {
1069 k = 0;
1070 producer = get_next_index(producer,
1071 adapter->max_tx_desc_count);
1072 hwdesc = &hw->cmd_desc_head[producer];
1073 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
1074 pbuf = &adapter->cmd_buf_arr[producer];
1075 pbuf->skb = NULL;
1077 frag = &skb_shinfo(skb)->frags[i - 1];
1078 len = frag->size;
1079 offset = frag->page_offset;
1081 temp_len = len;
1082 temp_dma = pci_map_page(adapter->pdev, frag->page, offset,
1083 len, PCI_DMA_TODEVICE);
1085 buffrag++;
1086 buffrag->dma = temp_dma;
1087 buffrag->length = temp_len;
1089 DPRINTK(INFO, "for loop. i=%d k=%d\n", i, k);
1090 switch (k) {
1091 case 0:
1092 hwdesc->buffer1_length = cpu_to_le16(temp_len);
1093 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
1094 break;
1095 case 1:
1096 hwdesc->buffer2_length = cpu_to_le16(temp_len);
1097 hwdesc->addr_buffer2 = cpu_to_le64(temp_dma);
1098 break;
1099 case 2:
1100 hwdesc->buffer3_length = cpu_to_le16(temp_len);
1101 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
1102 break;
1103 case 3:
1104 hwdesc->buffer4_length = cpu_to_le16(temp_len);
1105 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
1106 break;
1108 frag++;
1110 producer = get_next_index(producer, adapter->max_tx_desc_count);
1112 /* might change opcode to TX_TCP_LSO */
1113 netxen_tso_check(adapter, &hw->cmd_desc_head[saved_producer], skb);
1115 /* For LSO, we need to copy the MAC/IP/TCP headers into
1116 * the descriptor ring
1118 if (netxen_get_cmd_desc_opcode(&hw->cmd_desc_head[saved_producer])
1119 == TX_TCP_LSO) {
1120 int hdr_len, first_hdr_len, more_hdr;
1121 hdr_len = hw->cmd_desc_head[saved_producer].total_hdr_length;
1122 if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) {
1123 first_hdr_len = sizeof(struct cmd_desc_type0) - 2;
1124 more_hdr = 1;
1125 } else {
1126 first_hdr_len = hdr_len;
1127 more_hdr = 0;
1129 /* copy the MAC/IP/TCP headers to the cmd descriptor list */
1130 hwdesc = &hw->cmd_desc_head[producer];
1131 pbuf = &adapter->cmd_buf_arr[producer];
1132 pbuf->skb = NULL;
1134 /* copy the first 64 bytes */
1135 memcpy(((void *)hwdesc) + 2,
1136 (void *)(skb->data), first_hdr_len);
1137 producer = get_next_index(producer, max_tx_desc_count);
1139 if (more_hdr) {
1140 hwdesc = &hw->cmd_desc_head[producer];
1141 pbuf = &adapter->cmd_buf_arr[producer];
1142 pbuf->skb = NULL;
1143 /* copy the next 64 bytes - should be enough except
1144 * for pathological case
1146 skb_copy_from_linear_data_offset(skb, first_hdr_len,
1147 hwdesc,
1148 (hdr_len -
1149 first_hdr_len));
1150 producer = get_next_index(producer, max_tx_desc_count);
1154 spin_lock_bh(&adapter->tx_lock);
1155 adapter->stats.txbytes += skb->len;
1157 /* Code to update the adapter considering how many producer threads
1158 are currently working */
1159 if ((--adapter->num_threads) == 0) {
1160 /* This is the last thread */
1161 u32 crb_producer = adapter->cmd_producer;
1162 netxen_nic_update_cmd_producer(adapter, crb_producer);
1163 wmb();
1164 adapter->total_threads = 0;
1167 adapter->stats.xmitfinished++;
1168 netdev->trans_start = jiffies;
1170 spin_unlock_bh(&adapter->tx_lock);
1171 return NETDEV_TX_OK;
1173 out_requeue:
1174 netif_stop_queue(netdev);
1175 adapter->flags |= NETXEN_NETDEV_STATUS;
1177 spin_unlock_bh(&adapter->tx_lock);
1178 return NETDEV_TX_BUSY;
1181 static void netxen_watchdog(unsigned long v)
1183 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
1185 SCHEDULE_WORK(&adapter->watchdog_task);
1188 static void netxen_tx_timeout(struct net_device *netdev)
1190 struct netxen_adapter *adapter = (struct netxen_adapter *)
1191 netdev_priv(netdev);
1192 SCHEDULE_WORK(&adapter->tx_timeout_task);
1195 static void netxen_tx_timeout_task(struct work_struct *work)
1197 struct netxen_adapter *adapter =
1198 container_of(work, struct netxen_adapter, tx_timeout_task);
1200 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
1201 netxen_nic_driver_name, adapter->netdev->name);
1203 netxen_nic_close(adapter->netdev);
1204 netxen_nic_open(adapter->netdev);
1205 adapter->netdev->trans_start = jiffies;
1206 netif_wake_queue(adapter->netdev);
1209 static int
1210 netxen_handle_int(struct netxen_adapter *adapter, struct net_device *netdev)
1212 u32 ret = 0;
1214 DPRINTK(INFO, "Entered handle ISR\n");
1215 adapter->stats.ints++;
1217 netxen_nic_disable_int(adapter);
1219 if (netxen_nic_rx_has_work(adapter) || netxen_nic_tx_has_work(adapter)) {
1220 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
1222 * Interrupts are already disabled.
1224 __netif_rx_schedule(netdev, &adapter->napi);
1225 } else {
1226 static unsigned int intcount = 0;
1227 if ((++intcount & 0xfff) == 0xfff)
1228 DPRINTK(KERN_ERR
1229 "%s: %s interrupt %d while in poll\n",
1230 netxen_nic_driver_name, netdev->name,
1231 intcount);
1233 ret = 1;
1236 if (ret == 0) {
1237 netxen_nic_enable_int(adapter);
1240 return ret;
1244 * netxen_intr - Interrupt Handler
1245 * @irq: interrupt number
1246 * data points to adapter stucture (which may be handling more than 1 port
1248 irqreturn_t netxen_intr(int irq, void *data)
1250 struct netxen_adapter *adapter = data;
1251 struct net_device *netdev = adapter->netdev;
1252 u32 our_int = 0;
1254 if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) {
1255 our_int = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR));
1256 /* not our interrupt */
1257 if ((our_int & (0x80 << adapter->portnum)) == 0)
1258 return IRQ_NONE;
1261 if (adapter->intr_scheme == INTR_SCHEME_PERPORT) {
1262 /* claim interrupt */
1263 if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) {
1264 writel(our_int & ~((u32)(0x80 << adapter->portnum)),
1265 NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR));
1269 if (netif_running(netdev))
1270 netxen_handle_int(adapter, netdev);
1272 return IRQ_HANDLED;
1275 static int netxen_nic_poll(struct napi_struct *napi, int budget)
1277 struct netxen_adapter *adapter = container_of(napi, struct netxen_adapter, napi);
1278 struct net_device *netdev = adapter->netdev;
1279 int done = 1;
1280 int ctx;
1281 int work_done;
1283 DPRINTK(INFO, "polling for %d descriptors\n", *budget);
1285 work_done = 0;
1286 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
1288 * Fairness issue. This will give undue weight to the
1289 * receive context 0.
1293 * To avoid starvation, we give each of our receivers,
1294 * a fraction of the quota. Sometimes, it might happen that we
1295 * have enough quota to process every packet, but since all the
1296 * packets are on one context, it gets only half of the quota,
1297 * and ends up not processing it.
1299 work_done += netxen_process_rcv_ring(adapter, ctx,
1300 budget / MAX_RCV_CTX);
1303 if (work_done >= budget)
1304 done = 0;
1306 if (netxen_process_cmd_ring((unsigned long)adapter) == 0)
1307 done = 0;
1309 DPRINTK(INFO, "new work_done: %d work_to_do: %d\n",
1310 work_done, work_to_do);
1311 if (done) {
1312 netif_rx_complete(netdev, napi);
1313 netxen_nic_enable_int(adapter);
1316 return work_done;
1319 #ifdef CONFIG_NET_POLL_CONTROLLER
1320 static void netxen_nic_poll_controller(struct net_device *netdev)
1322 struct netxen_adapter *adapter = netdev_priv(netdev);
1323 disable_irq(adapter->irq);
1324 netxen_intr(adapter->irq, adapter);
1325 enable_irq(adapter->irq);
1327 #endif
1329 static struct pci_driver netxen_driver = {
1330 .name = netxen_nic_driver_name,
1331 .id_table = netxen_pci_tbl,
1332 .probe = netxen_nic_probe,
1333 .remove = __devexit_p(netxen_nic_remove)
1336 /* Driver Registration on NetXen card */
1338 static int __init netxen_init_module(void)
1340 if ((netxen_workq = create_singlethread_workqueue("netxen")) == NULL)
1341 return -ENOMEM;
1343 return pci_register_driver(&netxen_driver);
1346 module_init(netxen_init_module);
1348 static void __exit netxen_exit_module(void)
1351 * Wait for some time to allow the dma to drain, if any.
1353 msleep(100);
1354 pci_unregister_driver(&netxen_driver);
1355 destroy_workqueue(netxen_workq);
1358 module_exit(netxen_exit_module);