]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/netxen/netxen_nic_main.c
netxen: fix legacy interrupts
[mirror_ubuntu-artful-kernel.git] / drivers / net / netxen / netxen_nic_main.c
CommitLineData
3d396eb1
AK
1/*
2 * Copyright (C) 2003 - 2006 NetXen, Inc.
3 * All rights reserved.
80922fbc 4 *
3d396eb1
AK
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.
80922fbc 9 *
3d396eb1
AK
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.
80922fbc 14 *
3d396eb1
AK
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.
80922fbc 19 *
3d396eb1
AK
20 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
80922fbc 22 *
3d396eb1
AK
23 * Contact Information:
24 * info@netxen.com
25 * NetXen,
26 * 3965 Freedom Circle, Fourth floor,
27 * Santa Clara, CA 95054
28 *
29 *
30 * Main source file for NetXen NIC Driver on Linux
31 *
32 */
33
cb8011ad 34#include <linux/vmalloc.h>
ed25ffa1 35#include <linux/highmem.h>
3d396eb1
AK
36#include "netxen_nic_hw.h"
37
38#include "netxen_nic.h"
3d396eb1 39#include "netxen_nic_phan_reg.h"
3d396eb1 40
1494a814 41#include <linux/dma-mapping.h>
c9bdd4b5 42#include <net/ip.h>
1494a814 43
3d396eb1
AK
44MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
45MODULE_LICENSE("GPL");
46MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
47
ceded32f 48char netxen_nic_driver_name[] = "netxen_nic";
3d396eb1 49static char netxen_nic_driver_string[] = "NetXen Network Driver version "
cb8011ad 50 NETXEN_NIC_LINUX_VERSIONID;
3d396eb1 51
2956640d
DP
52static int port_mode = NETXEN_PORT_MODE_AUTO_NEG;
53
54/* Default to restricted 1G auto-neg mode */
55static int wol_port_mode = 5;
56
57static int use_msi = 1;
58
59static int use_msi_x = 1;
60
3d396eb1
AK
61/* Local functions to NetXen NIC driver */
62static int __devinit netxen_nic_probe(struct pci_dev *pdev,
2956640d 63 const struct pci_device_id *ent);
3d396eb1
AK
64static void __devexit netxen_nic_remove(struct pci_dev *pdev);
65static int netxen_nic_open(struct net_device *netdev);
66static int netxen_nic_close(struct net_device *netdev);
67static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *);
68static void netxen_tx_timeout(struct net_device *netdev);
6d5aefb8 69static void netxen_tx_timeout_task(struct work_struct *work);
3d396eb1 70static void netxen_watchdog(unsigned long);
bea3348e 71static int netxen_nic_poll(struct napi_struct *napi, int budget);
3d396eb1
AK
72#ifdef CONFIG_NET_POLL_CONTROLLER
73static void netxen_nic_poll_controller(struct net_device *netdev);
74#endif
1494a814 75static irqreturn_t netxen_intr(int irq, void *data);
05aaa02d 76static irqreturn_t netxen_msi_intr(int irq, void *data);
3d396eb1
AK
77
78/* PCI Device ID Table */
70081ac5
AV
79#define ENTRY(device) \
80 {PCI_DEVICE(0x4040, (device)), \
81 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
82
3d396eb1 83static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
70081ac5
AV
84 ENTRY(0x0001),
85 ENTRY(0x0002),
86 ENTRY(0x0003),
87 ENTRY(0x0004),
88 ENTRY(0x0005),
89 ENTRY(0x0024),
90 ENTRY(0x0025),
e4c93c81 91 ENTRY(0x0100),
3d396eb1
AK
92 {0,}
93};
94
95MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
96
b1555130
AB
97/*
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.
102 *
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.
109 */
110
111static struct workqueue_struct *netxen_workq;
112#define SCHEDULE_WORK(tp) queue_work(netxen_workq, tp)
113#define FLUSH_SCHEDULED_WORK() flush_workqueue(netxen_workq)
114
ed25ffa1
AK
115static void netxen_watchdog(unsigned long);
116
7830b22c
DP
117static 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
120};
121
c9fc891f 122void
3ce06a32
DP
123netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
124 uint32_t crb_producer)
3176ff3e 125{
3ce06a32
DP
126 adapter->pci_write_normalize(adapter,
127 adapter->crb_addr_cmd_producer, crb_producer);
3176ff3e
MT
128}
129
7830b22c
DP
130static 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
133};
134
3ce06a32
DP
135static inline void
136netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
137 u32 crb_consumer)
3176ff3e 138{
3ce06a32
DP
139 adapter->pci_write_normalize(adapter,
140 adapter->crb_addr_cmd_consumer, crb_consumer);
3176ff3e
MT
141}
142
2956640d 143static uint32_t msi_tgt_status[8] = {
443be796 144 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
2956640d
DP
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
443be796
DP
148};
149
2956640d
DP
150static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
151
4638aef1
SH
152static void netxen_nic_disable_int(struct netxen_adapter *adapter)
153{
443be796 154 u32 mask = 0x7ff;
4638aef1 155 int retries = 32;
443be796 156 int pci_fn = adapter->ahw.pci_func;
4638aef1 157
f0c88f9c 158 if (adapter->msi_mode != MSI_MODE_MULTIFUNC)
48bfd1e0
DP
159 adapter->pci_write_normalize(adapter,
160 adapter->crb_intr_mask, 0);
4638aef1
SH
161
162 if (adapter->intr_scheme != -1 &&
163 adapter->intr_scheme != INTR_SCHEME_PERPORT)
3ce06a32 164 adapter->pci_write_immediate(adapter, ISR_INT_MASK, mask);
4638aef1 165
2956640d 166 if (!NETXEN_IS_MSI_FAMILY(adapter)) {
4638aef1 167 do {
3ce06a32 168 adapter->pci_write_immediate(adapter,
d71e1be8
DP
169 adapter->legacy_intr.tgt_status_reg,
170 0xffffffff);
3ce06a32
DP
171 mask = adapter->pci_read_immediate(adapter,
172 ISR_INT_VECTOR);
4638aef1
SH
173 if (!(mask & 0x80))
174 break;
175 udelay(10);
176 } while (--retries);
177
178 if (!retries) {
d71e1be8 179 printk(KERN_NOTICE "%s: Failed to disable interrupt\n",
4638aef1
SH
180 netxen_nic_driver_name);
181 }
443be796
DP
182 } else {
183 if (adapter->msi_mode == MSI_MODE_MULTIFUNC) {
3ce06a32
DP
184 adapter->pci_write_immediate(adapter,
185 msi_tgt_status[pci_fn], 0xffffffff);
443be796 186 }
4638aef1 187 }
4638aef1
SH
188}
189
190static void netxen_nic_enable_int(struct netxen_adapter *adapter)
191{
192 u32 mask;
193
4638aef1
SH
194 if (adapter->intr_scheme != -1 &&
195 adapter->intr_scheme != INTR_SCHEME_PERPORT) {
196 switch (adapter->ahw.board_type) {
197 case NETXEN_NIC_GBE:
198 mask = 0x77b;
199 break;
200 case NETXEN_NIC_XGBE:
201 mask = 0x77f;
202 break;
203 default:
204 mask = 0x7ff;
205 break;
206 }
207
3ce06a32 208 adapter->pci_write_immediate(adapter, ISR_INT_MASK, mask);
4638aef1
SH
209 }
210
48bfd1e0 211 adapter->pci_write_normalize(adapter, adapter->crb_intr_mask, 0x1);
4638aef1 212
2956640d 213 if (!NETXEN_IS_MSI_FAMILY(adapter)) {
4638aef1 214 mask = 0xbff;
d71e1be8
DP
215 if (adapter->intr_scheme == INTR_SCHEME_PERPORT)
216 adapter->pci_write_immediate(adapter,
217 adapter->legacy_intr.tgt_mask_reg, mask);
218 else
3ce06a32
DP
219 adapter->pci_write_normalize(adapter,
220 CRB_INT_VECTOR, 0);
4638aef1 221 }
4638aef1
SH
222}
223
2956640d
DP
224static int nx_set_dma_mask(struct netxen_adapter *adapter, uint8_t revision_id)
225{
226 struct pci_dev *pdev = adapter->pdev;
227 int err;
228 uint64_t mask;
229
230#ifdef CONFIG_IA64
231 adapter->dma_mask = DMA_32BIT_MASK;
232#else
233 if (revision_id >= NX_P3_B0) {
234 /* should go to DMA_64BIT_MASK */
235 adapter->dma_mask = DMA_39BIT_MASK;
236 mask = DMA_39BIT_MASK;
237 } else if (revision_id == NX_P3_A2) {
238 adapter->dma_mask = DMA_39BIT_MASK;
239 mask = DMA_39BIT_MASK;
240 } else if (revision_id == NX_P2_C1) {
241 adapter->dma_mask = DMA_35BIT_MASK;
242 mask = DMA_35BIT_MASK;
243 } else {
244 adapter->dma_mask = DMA_32BIT_MASK;
245 mask = DMA_32BIT_MASK;
246 goto set_32_bit_mask;
247 }
248
249 /*
250 * Consistent DMA mask is set to 32 bit because it cannot be set to
251 * 35 bits. For P3 also leave it at 32 bits for now. Only the rings
252 * come off this pool.
253 */
254 if (pci_set_dma_mask(pdev, mask) == 0 &&
255 pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK) == 0) {
256 adapter->pci_using_dac = 1;
257 return 0;
258 }
259#endif /* CONFIG_IA64 */
260
261set_32_bit_mask:
262 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
263 if (!err)
264 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
265 if (err) {
266 DPRINTK(ERR, "No usable DMA configuration, aborting:%d\n", err);
267 return err;
268 }
269
270 adapter->pci_using_dac = 0;
271 return 0;
272}
273
274static void netxen_check_options(struct netxen_adapter *adapter)
275{
276 switch (adapter->ahw.boardcfg.board_type) {
277 case NETXEN_BRDTYPE_P3_HMEZ:
278 case NETXEN_BRDTYPE_P3_XG_LOM:
279 case NETXEN_BRDTYPE_P3_10G_CX4:
280 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
281 case NETXEN_BRDTYPE_P3_IMEZ:
282 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
a70f9393
DP
283 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
284 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
2956640d
DP
285 case NETXEN_BRDTYPE_P3_10G_XFP:
286 case NETXEN_BRDTYPE_P3_10000_BASE_T:
287 adapter->msix_supported = !!use_msi_x;
288 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
289 break;
290
291 case NETXEN_BRDTYPE_P2_SB31_10G:
292 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
293 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
294 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
295 adapter->msix_supported = 0;
296 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
297 break;
298
299 case NETXEN_BRDTYPE_P3_REF_QG:
300 case NETXEN_BRDTYPE_P3_4_GB:
301 case NETXEN_BRDTYPE_P3_4_GB_MM:
a70f9393
DP
302 adapter->msix_supported = 0;
303 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
304 break;
305
2956640d
DP
306 case NETXEN_BRDTYPE_P2_SB35_4G:
307 case NETXEN_BRDTYPE_P2_SB31_2G:
308 adapter->msix_supported = 0;
309 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
310 break;
311
312 default:
313 adapter->msix_supported = 0;
314 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
315
316 printk(KERN_WARNING "Unknown board type(0x%x)\n",
317 adapter->ahw.boardcfg.board_type);
318 break;
319 }
320
321 adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS_HOST;
322 adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS;
323 adapter->max_lro_rx_desc_count = MAX_LRO_RCV_DESCRIPTORS;
324
325 adapter->max_possible_rss_rings = 1;
326 return;
327}
328
329static int
330netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
331{
332 int ret = 0;
333
334 if (first_boot == 0x55555555) {
335 /* This is the first boot after power up */
336
337 /* PCI bus master workaround */
338 adapter->hw_read_wx(adapter,
339 NETXEN_PCIE_REG(0x4), &first_boot, 4);
340 if (!(first_boot & 0x4)) {
341 first_boot |= 0x4;
342 adapter->hw_write_wx(adapter,
343 NETXEN_PCIE_REG(0x4), &first_boot, 4);
344 adapter->hw_read_wx(adapter,
345 NETXEN_PCIE_REG(0x4), &first_boot, 4);
346 }
347
348 /* This is the first boot after power up */
349 adapter->hw_read_wx(adapter,
350 NETXEN_ROMUSB_GLB_SW_RESET, &first_boot, 4);
351 if (first_boot != 0x80000f) {
352 /* clear the register for future unloads/loads */
353 adapter->pci_write_normalize(adapter,
354 NETXEN_CAM_RAM(0x1fc), 0);
355 ret = -1;
356 }
357
358 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
359 /* Start P2 boot loader */
360 adapter->pci_write_normalize(adapter,
361 NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
362 adapter->pci_write_normalize(adapter,
363 NETXEN_ROMUSB_GLB_PEGTUNE_DONE, 1);
364 }
365 }
366 return ret;
367}
368
369static void netxen_set_port_mode(struct netxen_adapter *adapter)
370{
371 u32 val, data;
372
373 val = adapter->ahw.boardcfg.board_type;
374 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
375 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
376 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
377 data = NETXEN_PORT_MODE_802_3_AP;
378 adapter->hw_write_wx(adapter,
379 NETXEN_PORT_MODE_ADDR, &data, 4);
380 } else if (port_mode == NETXEN_PORT_MODE_XG) {
381 data = NETXEN_PORT_MODE_XG;
382 adapter->hw_write_wx(adapter,
383 NETXEN_PORT_MODE_ADDR, &data, 4);
384 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
385 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
386 adapter->hw_write_wx(adapter,
387 NETXEN_PORT_MODE_ADDR, &data, 4);
388 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
389 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
390 adapter->hw_write_wx(adapter,
391 NETXEN_PORT_MODE_ADDR, &data, 4);
392 } else {
393 data = NETXEN_PORT_MODE_AUTO_NEG;
394 adapter->hw_write_wx(adapter,
395 NETXEN_PORT_MODE_ADDR, &data, 4);
396 }
397
398 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
399 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
400 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
401 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
402 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
403 }
404 adapter->hw_write_wx(adapter, NETXEN_WOL_PORT_MODE,
405 &wol_port_mode, 4);
406 }
407}
408
409#define PCI_CAP_ID_GEN 0x10
410
411static void netxen_pcie_strap_init(struct netxen_adapter *adapter)
412{
413 u32 pdevfuncsave;
414 u32 c8c9value = 0;
415 u32 chicken = 0;
416 u32 control = 0;
417 int i, pos;
418 struct pci_dev *pdev;
419
420 pdev = pci_get_device(0x1166, 0x0140, NULL);
421 if (pdev) {
422 pci_dev_put(pdev);
423 adapter->hw_read_wx(adapter,
424 NETXEN_PCIE_REG(PCIE_TGT_SPLIT_CHICKEN), &chicken, 4);
425 chicken |= 0x4000;
426 adapter->hw_write_wx(adapter,
427 NETXEN_PCIE_REG(PCIE_TGT_SPLIT_CHICKEN), &chicken, 4);
428 }
429
430 pdev = adapter->pdev;
431
432 adapter->hw_read_wx(adapter,
433 NETXEN_PCIE_REG(PCIE_CHICKEN3), &chicken, 4);
434 /* clear chicken3.25:24 */
435 chicken &= 0xFCFFFFFF;
436 /*
437 * if gen1 and B0, set F1020 - if gen 2, do nothing
438 * if gen2 set to F1000
439 */
440 pos = pci_find_capability(pdev, PCI_CAP_ID_GEN);
441 if (pos == 0xC0) {
442 pci_read_config_dword(pdev, pos + 0x10, &control);
443 if ((control & 0x000F0000) != 0x00020000) {
444 /* set chicken3.24 if gen1 */
445 chicken |= 0x01000000;
446 }
447 printk(KERN_INFO "%s Gen2 strapping detected\n",
448 netxen_nic_driver_name);
449 c8c9value = 0xF1000;
450 } else {
451 /* set chicken3.24 if gen1 */
452 chicken |= 0x01000000;
453 printk(KERN_INFO "%s Gen1 strapping detected\n",
454 netxen_nic_driver_name);
455 if (adapter->ahw.revision_id == NX_P3_B0)
456 c8c9value = 0xF1020;
457 else
458 c8c9value = 0;
459
460 }
461 adapter->hw_write_wx(adapter,
462 NETXEN_PCIE_REG(PCIE_CHICKEN3), &chicken, 4);
463
464 if (!c8c9value)
465 return;
466
467 pdevfuncsave = pdev->devfn;
468 if (pdevfuncsave & 0x07)
469 return;
470
471 for (i = 0; i < 8; i++) {
472 pci_read_config_dword(pdev, pos + 8, &control);
473 pci_read_config_dword(pdev, pos + 8, &control);
474 pci_write_config_dword(pdev, pos + 8, c8c9value);
475 pdev->devfn++;
476 }
477 pdev->devfn = pdevfuncsave;
478}
479
480static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
481{
482 u32 control;
483 int pos;
484
485 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
486 if (pos) {
487 pci_read_config_dword(pdev, pos, &control);
488 if (enable)
489 control |= PCI_MSIX_FLAGS_ENABLE;
490 else
491 control = 0;
492 pci_write_config_dword(pdev, pos, control);
493 }
494}
495
496static void netxen_init_msix_entries(struct netxen_adapter *adapter)
497{
498 int i;
499
500 for (i = 0; i < MSIX_ENTRIES_PER_ADAPTER; i++)
501 adapter->msix_entries[i].entry = i;
502}
503
3d396eb1
AK
504/*
505 * netxen_nic_probe()
506 *
507 * The Linux system will invoke this after identifying the vendor ID and
508 * device Id in the pci_tbl supported by this module.
509 *
510 * A quad port card has one operational PCI config space, (function 0),
511 * which is used to access all four ports.
512 *
513 * This routine will initialize the adapter, and setup the global parameters
514 * along with the port's specific structure.
515 */
516static int __devinit
517netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
518{
519 struct net_device *netdev = NULL;
520 struct netxen_adapter *adapter = NULL;
ed25ffa1
AK
521 void __iomem *mem_ptr0 = NULL;
522 void __iomem *mem_ptr1 = NULL;
523 void __iomem *mem_ptr2 = NULL;
6c80b18d
MT
524 unsigned long first_page_group_end;
525 unsigned long first_page_group_start;
526
cb8011ad 527
a608ab9c 528 u8 __iomem *db_ptr = NULL;
2956640d
DP
529 unsigned long mem_base, mem_len, db_base, db_len, pci_len0 = 0;
530 int i = 0, err;
531 int first_driver, first_boot;
f305f789 532 __le64 mac_addr[FLASH_NUM_PORTS + 1];
6c80b18d 533 u32 val;
3176ff3e 534 int pci_func_id = PCI_FUNC(pdev->devfn);
0795af57 535 DECLARE_MAC_BUF(mac);
2956640d
DP
536 struct netxen_legacy_intr_set *legacy_intrp;
537 uint8_t revision_id;
3d396eb1 538
dcd56fdb 539 if (pci_func_id == 0)
2956640d 540 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
6c80b18d 541
3176ff3e 542 if (pdev->class != 0x020000) {
dcd56fdb 543 printk(KERN_DEBUG "NetXen function %d, class %x will not "
3176ff3e 544 "be enabled.\n",pci_func_id, pdev->class);
ed25ffa1
AK
545 return -ENODEV;
546 }
2956640d 547
3d396eb1
AK
548 if ((err = pci_enable_device(pdev)))
549 return err;
2956640d 550
3d396eb1
AK
551 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
552 err = -ENODEV;
553 goto err_out_disable_pdev;
554 }
555
556 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
557 goto err_out_disable_pdev;
558
559 pci_set_master(pdev);
3176ff3e
MT
560
561 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
562 if(!netdev) {
563 printk(KERN_ERR"%s: Failed to allocate memory for the "
564 "device block.Check system memory resource"
565 " usage.\n", netxen_nic_driver_name);
566 goto err_out_free_res;
567 }
568
3176ff3e
MT
569 SET_NETDEV_DEV(netdev, &pdev->dev);
570
571 adapter = netdev->priv;
2956640d
DP
572 adapter->netdev = netdev;
573 adapter->pdev = pdev;
13ba9c77 574 adapter->ahw.pci_func = pci_func_id;
2956640d
DP
575
576 revision_id = pdev->revision;
577 adapter->ahw.revision_id = revision_id;
578
579 err = nx_set_dma_mask(adapter, revision_id);
580 if (err)
581 goto err_out_free_netdev;
582
3ce06a32
DP
583 rwlock_init(&adapter->adapter_lock);
584 adapter->ahw.qdr_sn_window = -1;
585 adapter->ahw.ddr_mn_window = -1;
13ba9c77 586
3d396eb1
AK
587 /* remap phys address */
588 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
589 mem_len = pci_resource_len(pdev, 0);
3ce06a32
DP
590 pci_len0 = 0;
591
592 adapter->hw_write_wx = netxen_nic_hw_write_wx_128M;
593 adapter->hw_read_wx = netxen_nic_hw_read_wx_128M;
594 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_128M;
595 adapter->pci_write_immediate = netxen_nic_pci_write_immediate_128M;
596 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_128M;
597 adapter->pci_write_normalize = netxen_nic_pci_write_normalize_128M;
598 adapter->pci_set_window = netxen_nic_pci_set_window_128M;
599 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M;
600 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M;
3d396eb1
AK
601
602 /* 128 Meg of memory */
6c80b18d
MT
603 if (mem_len == NETXEN_PCI_128MB_SIZE) {
604 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
605 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
606 SECOND_PAGE_GROUP_SIZE);
607 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
608 THIRD_PAGE_GROUP_SIZE);
609 first_page_group_start = FIRST_PAGE_GROUP_START;
610 first_page_group_end = FIRST_PAGE_GROUP_END;
611 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
612 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
613 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
614 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
615 first_page_group_start = 0;
616 first_page_group_end = 0;
3ce06a32
DP
617 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
618 adapter->hw_write_wx = netxen_nic_hw_write_wx_2M;
619 adapter->hw_read_wx = netxen_nic_hw_read_wx_2M;
620 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_2M;
621 adapter->pci_write_immediate =
622 netxen_nic_pci_write_immediate_2M;
623 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_2M;
624 adapter->pci_write_normalize =
625 netxen_nic_pci_write_normalize_2M;
626 adapter->pci_set_window = netxen_nic_pci_set_window_2M;
627 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M;
628 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M;
629
630 mem_ptr0 = ioremap(mem_base, mem_len);
631 pci_len0 = mem_len;
632 first_page_group_start = 0;
633 first_page_group_end = 0;
634
635 adapter->ahw.ddr_mn_window = 0;
636 adapter->ahw.qdr_sn_window = 0;
637
638 adapter->ahw.mn_win_crb = 0x100000 + PCIX_MN_WINDOW +
639 (pci_func_id * 0x20);
640 adapter->ahw.ms_win_crb = 0x100000 + PCIX_SN_WINDOW;
641 if (pci_func_id < 4)
642 adapter->ahw.ms_win_crb += (pci_func_id * 0x20);
643 else
644 adapter->ahw.ms_win_crb +=
645 0xA0 + ((pci_func_id - 4) * 0x10);
6c80b18d 646 } else {
4790654c 647 err = -EIO;
6c80b18d
MT
648 goto err_out_free_netdev;
649 }
cb8011ad 650
3ce06a32 651 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
cb8011ad 652
ed25ffa1
AK
653 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
654 db_len = pci_resource_len(pdev, 4);
655
656 if (db_len == 0) {
657 printk(KERN_ERR "%s: doorbell is disabled\n",
2956640d 658 netxen_nic_driver_name);
ed25ffa1
AK
659 err = -EIO;
660 goto err_out_iounmap;
661 }
662 DPRINTK(INFO, "doorbell ioremap from %lx a size of %lx\n", db_base,
663 db_len);
664
665 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
a608ab9c 666 if (!db_ptr) {
ed25ffa1 667 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
2956640d 668 netxen_nic_driver_name);
ed25ffa1
AK
669 err = -EIO;
670 goto err_out_iounmap;
3d396eb1 671 }
ed25ffa1 672 DPRINTK(INFO, "doorbell ioremaped at %p\n", db_ptr);
3d396eb1 673
6c80b18d 674 adapter->ahw.pci_base0 = mem_ptr0;
3ce06a32 675 adapter->ahw.pci_len0 = pci_len0;
6c80b18d
MT
676 adapter->ahw.first_page_group_start = first_page_group_start;
677 adapter->ahw.first_page_group_end = first_page_group_end;
678 adapter->ahw.pci_base1 = mem_ptr1;
679 adapter->ahw.pci_base2 = mem_ptr2;
680 adapter->ahw.db_base = db_ptr;
681 adapter->ahw.db_len = db_len;
3d396eb1 682
bea3348e 683 netif_napi_add(netdev, &adapter->napi,
2956640d
DP
684 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
685
686 if (revision_id >= NX_P3_B0)
687 legacy_intrp = &legacy_intr[pci_func_id];
688 else
689 legacy_intrp = &legacy_intr[0];
690
691 adapter->legacy_intr.int_vec_bit = legacy_intrp->int_vec_bit;
692 adapter->legacy_intr.tgt_status_reg = legacy_intrp->tgt_status_reg;
693 adapter->legacy_intr.tgt_mask_reg = legacy_intrp->tgt_mask_reg;
694 adapter->legacy_intr.pci_int_reg = legacy_intrp->pci_int_reg;
bea3348e 695
2d1a3bbd 696 /* this will be read from FW later */
697 adapter->intr_scheme = -1;
443be796 698 adapter->msi_mode = -1;
2d1a3bbd 699
700 /* This will be reset for mezz cards */
3176ff3e 701 adapter->portnum = pci_func_id;
2d1a3bbd 702 adapter->status &= ~NETXEN_NETDEV_STATUS;
200eef20 703 adapter->rx_csum = 1;
623621b0 704 adapter->mc_enabled = 0;
48bfd1e0 705 if (NX_IS_REVISION_P3(revision_id)) {
2956640d 706 adapter->max_mc_count = 38;
48bfd1e0
DP
707 adapter->max_rds_rings = 2;
708 } else {
2956640d 709 adapter->max_mc_count = 16;
48bfd1e0
DP
710 adapter->max_rds_rings = 3;
711 }
3176ff3e
MT
712
713 netdev->open = netxen_nic_open;
714 netdev->stop = netxen_nic_close;
715 netdev->hard_start_xmit = netxen_nic_xmit_frame;
4790654c 716 netdev->get_stats = netxen_nic_get_stats;
c9fc891f
DP
717 if (NX_IS_REVISION_P3(revision_id))
718 netdev->set_multicast_list = netxen_p3_nic_set_multi;
719 else
720 netdev->set_multicast_list = netxen_p2_nic_set_multi;
3176ff3e
MT
721 netdev->set_mac_address = netxen_nic_set_mac;
722 netdev->change_mtu = netxen_nic_change_mtu;
723 netdev->tx_timeout = netxen_tx_timeout;
05aaa02d 724 netdev->watchdog_timeo = 2*HZ;
3176ff3e
MT
725
726 netxen_nic_change_mtu(netdev, netdev->mtu);
727
728 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
3176ff3e
MT
729#ifdef CONFIG_NET_POLL_CONTROLLER
730 netdev->poll_controller = netxen_nic_poll_controller;
731#endif
732 /* ScatterGather support */
733 netdev->features = NETIF_F_SG;
734 netdev->features |= NETIF_F_IP_CSUM;
735 netdev->features |= NETIF_F_TSO;
cd1f8160
DP
736 if (NX_IS_REVISION_P3(revision_id)) {
737 netdev->features |= NETIF_F_IPV6_CSUM;
2956640d 738 netdev->features |= NETIF_F_TSO6;
cd1f8160 739 }
3176ff3e 740
2956640d 741 if (adapter->pci_using_dac)
3176ff3e
MT
742 netdev->features |= NETIF_F_HIGHDMA;
743
6c80b18d
MT
744 /*
745 * Set the CRB window to invalid. If any register in window 0 is
746 * accessed it should set the window to 0 and then reset it to 1.
747 */
748 adapter->curr_window = 255;
749
dcd56fdb
DP
750 if (netxen_nic_get_board_info(adapter) != 0) {
751 printk("%s: Error getting board config info.\n",
2956640d 752 netxen_nic_driver_name);
dcd56fdb
DP
753 err = -EIO;
754 goto err_out_iounmap;
755 }
6c80b18d 756
6c80b18d
MT
757 netxen_initialize_adapter_ops(adapter);
758
13ba9c77 759 /* Mezz cards have PCI function 0,2,3 enabled */
dc515f2e
DP
760 switch (adapter->ahw.boardcfg.board_type) {
761 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
762 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
763 if (pci_func_id >= 2)
13ba9c77 764 adapter->portnum = pci_func_id - 2;
dc515f2e
DP
765 break;
766 default:
767 break;
768 }
13ba9c77 769
2956640d
DP
770 /*
771 * This call will setup various max rx/tx counts.
772 * It must be done before any buffer/ring allocations.
773 */
774 netxen_check_options(adapter);
3d396eb1 775
2956640d
DP
776 first_driver = 0;
777 if (NX_IS_REVISION_P3(revision_id)) {
778 if (adapter->ahw.pci_func == 0)
779 first_driver = 1;
780 } else {
781 if (adapter->portnum == 0)
782 first_driver = 1;
783 }
7830b22c
DP
784 adapter->crb_addr_cmd_producer = crb_cmd_producer[adapter->portnum];
785 adapter->crb_addr_cmd_consumer = crb_cmd_consumer[adapter->portnum];
3176ff3e
MT
786 netxen_nic_update_cmd_producer(adapter, 0);
787 netxen_nic_update_cmd_consumer(adapter, 0);
3d396eb1 788
2956640d
DP
789 if (first_driver) {
790 first_boot = adapter->pci_read_normalize(adapter,
791 NETXEN_CAM_RAM(0x1fc));
3176ff3e 792
2956640d
DP
793 err = netxen_check_hw_init(adapter, first_boot);
794 if (err) {
795 printk(KERN_ERR "%s: error in init HW init sequence\n",
796 netxen_nic_driver_name);
797 goto err_out_iounmap;
3176ff3e 798 }
3176ff3e 799
2956640d
DP
800 if (NX_IS_REVISION_P3(revision_id))
801 netxen_set_port_mode(adapter);
802
803 if (first_boot != 0x55555555) {
3ce06a32
DP
804 adapter->pci_write_normalize(adapter,
805 CRB_CMDPEG_STATE, 0);
439b454e
DP
806 netxen_pinit_from_rom(adapter, 0);
807 msleep(1);
808 netxen_load_firmware(adapter);
2956640d
DP
809 }
810
811 if (NX_IS_REVISION_P3(revision_id))
812 netxen_pcie_strap_init(adapter);
813
814 if (NX_IS_REVISION_P2(revision_id)) {
623621b0
DP
815
816 /* Initialize multicast addr pool owners */
817 val = 0x7654;
818 if (adapter->ahw.board_type == NETXEN_NIC_XGBE)
819 val |= 0x0f000000;
820 netxen_crb_writelit_adapter(adapter,
821 NETXEN_MAC_ADDR_CNTL_REG, val);
822
6c80b18d 823 }
96acb6eb 824
2956640d
DP
825 if ((first_boot == 0x55555555) &&
826 (NX_IS_REVISION_P2(revision_id))) {
827 /* Unlock the HW, prompting the boot sequence */
828 adapter->pci_write_normalize(adapter,
829 NETXEN_ROMUSB_GLB_PEGTUNE_DONE, 1);
830 }
831
832 err = netxen_initialize_adapter_offload(adapter);
833 if (err)
834 goto err_out_iounmap;
6c80b18d
MT
835
836 /*
837 * Tell the hardware our version number.
838 */
4790654c 839 i = (_NETXEN_NIC_LINUX_MAJOR << 16)
6c80b18d
MT
840 | ((_NETXEN_NIC_LINUX_MINOR << 8))
841 | (_NETXEN_NIC_LINUX_SUBVERSION);
3ce06a32 842 adapter->pci_write_normalize(adapter, CRB_DRIVER_VERSION, i);
3d396eb1 843
3176ff3e
MT
844 /* Handshake with the card before we register the devices. */
845 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
2956640d 846
2956640d
DP
847 } /* first_driver */
848
849 netxen_nic_flash_print(adapter);
3d396eb1 850
d9e651bc
DP
851 if (NX_IS_REVISION_P3(revision_id)) {
852 adapter->hw_read_wx(adapter,
853 NETXEN_MIU_MN_CONTROL, &val, 4);
854 adapter->ahw.cut_through = (val & 0x4) ? 1 : 0;
855 dev_info(&pdev->dev, "firmware running in %s mode\n",
856 adapter->ahw.cut_through ? "cut through" : "legacy");
857 }
858
3d396eb1 859 /*
6c80b18d 860 * See if the firmware gave us a virtual-physical port mapping.
3d396eb1 861 */
dcd56fdb 862 adapter->physical_port = adapter->portnum;
3ce06a32 863 i = adapter->pci_read_normalize(adapter, CRB_V2P(adapter->portnum));
6c80b18d 864 if (i != 0x55555555)
3276fbad 865 adapter->physical_port = i;
6c80b18d 866
2956640d
DP
867 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
868
869 netxen_set_msix_bit(pdev, 0);
870
871 if (NX_IS_REVISION_P3(revision_id)) {
872 if ((mem_len != NETXEN_PCI_128MB_SIZE) &&
873 mem_len != NETXEN_PCI_2MB_SIZE)
874 adapter->msix_supported = 0;
875 }
876
877 if (adapter->msix_supported) {
878
879 netxen_init_msix_entries(adapter);
880
881 if (pci_enable_msix(pdev, adapter->msix_entries,
882 MSIX_ENTRIES_PER_ADAPTER))
883 goto request_msi;
884
885 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
886 netxen_set_msix_bit(pdev, 1);
887 dev_info(&pdev->dev, "using msi-x interrupts\n");
888
889 } else {
890request_msi:
891 if (use_msi && !pci_enable_msi(pdev)) {
892 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
893 dev_info(&pdev->dev, "using msi interrupts\n");
894 } else
895 dev_info(&pdev->dev, "using legacy interrupts\n");
896 }
897
898 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
899 netdev->irq = adapter->msix_entries[0].vector;
900 else
901 netdev->irq = pdev->irq;
902
903 err = netxen_receive_peg_ready(adapter);
904 if (err)
905 goto err_out_disable_msi;
906
907 init_timer(&adapter->watchdog_timer);
a97342f9 908 adapter->ahw.linkup = 0;
2956640d
DP
909 adapter->watchdog_timer.function = &netxen_watchdog;
910 adapter->watchdog_timer.data = (unsigned long)adapter;
911 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
912 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
913
914 if (netxen_is_flash_supported(adapter) == 0 &&
915 netxen_get_flash_mac_addr(adapter, mac_addr) == 0) {
916 unsigned char *p;
917
918 p = (unsigned char *)&mac_addr[adapter->portnum];
919 netdev->dev_addr[0] = *(p + 5);
920 netdev->dev_addr[1] = *(p + 4);
921 netdev->dev_addr[2] = *(p + 3);
922 netdev->dev_addr[3] = *(p + 2);
923 netdev->dev_addr[4] = *(p + 1);
924 netdev->dev_addr[5] = *(p + 0);
925
926 memcpy(netdev->perm_addr, netdev->dev_addr,
927 netdev->addr_len);
928 if (!is_valid_ether_addr(netdev->perm_addr)) {
929 printk(KERN_ERR "%s: Bad MAC address %s.\n",
930 netxen_nic_driver_name,
931 print_mac(mac, netdev->dev_addr));
932 } else {
933 adapter->macaddr_set(adapter, netdev->dev_addr);
934 }
935 }
936
3176ff3e
MT
937 netif_carrier_off(netdev);
938 netif_stop_queue(netdev);
939
6c80b18d
MT
940 if ((err = register_netdev(netdev))) {
941 printk(KERN_ERR "%s: register_netdev failed port #%d"
942 " aborting\n", netxen_nic_driver_name,
943 adapter->portnum);
944 err = -EIO;
2956640d 945 goto err_out_disable_msi;
6c80b18d
MT
946 }
947
948 pci_set_drvdata(pdev, adapter);
3d396eb1 949
2956640d
DP
950 switch (adapter->ahw.board_type) {
951 case NETXEN_NIC_GBE:
952 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
953 adapter->netdev->name);
954 break;
955 case NETXEN_NIC_XGBE:
956 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
957 adapter->netdev->name);
958 break;
3d396eb1 959 }
3d396eb1 960
2956640d
DP
961 return 0;
962
963err_out_disable_msi:
964 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
965 pci_disable_msix(pdev);
6c80b18d
MT
966 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
967 pci_disable_msi(pdev);
968
2956640d
DP
969 if (first_driver)
970 netxen_free_adapter_offload(adapter);
3d396eb1 971
2956640d 972err_out_iounmap:
ed25ffa1
AK
973 if (db_ptr)
974 iounmap(db_ptr);
975
ed25ffa1
AK
976 if (mem_ptr0)
977 iounmap(mem_ptr0);
978 if (mem_ptr1)
979 iounmap(mem_ptr1);
980 if (mem_ptr2)
981 iounmap(mem_ptr2);
cb8011ad 982
6c80b18d
MT
983err_out_free_netdev:
984 free_netdev(netdev);
985
986err_out_free_res:
3d396eb1 987 pci_release_regions(pdev);
6c80b18d
MT
988
989err_out_disable_pdev:
2956640d 990 pci_set_drvdata(pdev, NULL);
3d396eb1
AK
991 pci_disable_device(pdev);
992 return err;
993}
994
995static void __devexit netxen_nic_remove(struct pci_dev *pdev)
996{
997 struct netxen_adapter *adapter;
3176ff3e 998 struct net_device *netdev;
3d396eb1 999
6c80b18d 1000 adapter = pci_get_drvdata(pdev);
3d396eb1
AK
1001 if (adapter == NULL)
1002 return;
1003
6c80b18d
MT
1004 netdev = adapter->netdev;
1005
96acb6eb
DP
1006 unregister_netdev(netdev);
1007
96acb6eb 1008 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
3d396eb1 1009 netxen_free_hw_resources(adapter);
2956640d 1010 netxen_free_sw_resources(adapter);
96acb6eb 1011 }
3d396eb1 1012
439b454e
DP
1013 if (adapter->portnum == 0)
1014 netxen_free_adapter_offload(adapter);
96acb6eb 1015
3052246c 1016 if (adapter->irq)
1017 free_irq(adapter->irq, adapter);
1018
2956640d
DP
1019 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
1020 pci_disable_msix(pdev);
3052246c 1021 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
1022 pci_disable_msi(pdev);
1023
6c80b18d
MT
1024 iounmap(adapter->ahw.db_base);
1025 iounmap(adapter->ahw.pci_base0);
1026 iounmap(adapter->ahw.pci_base1);
1027 iounmap(adapter->ahw.pci_base2);
595e3fb8
MT
1028
1029 pci_release_regions(pdev);
3052246c 1030 pci_disable_device(pdev);
595e3fb8
MT
1031 pci_set_drvdata(pdev, NULL);
1032
6c80b18d 1033 free_netdev(netdev);
3d396eb1
AK
1034}
1035
1036/*
1037 * Called when a network interface is made active
1038 * @returns 0 on success, negative value on failure
1039 */
1040static int netxen_nic_open(struct net_device *netdev)
1041{
3176ff3e 1042 struct netxen_adapter *adapter = (struct netxen_adapter *)netdev->priv;
3d396eb1
AK
1043 int err = 0;
1044 int ctx, ring;
05aaa02d
DP
1045 irq_handler_t handler;
1046 unsigned long flags = IRQF_SAMPLE_RANDOM;
3d396eb1 1047
dcd56fdb
DP
1048 if (adapter->driver_mismatch)
1049 return -EIO;
1050
3d396eb1
AK
1051 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) {
1052 err = netxen_init_firmware(adapter);
1053 if (err != 0) {
1054 printk(KERN_ERR "Failed to init firmware\n");
1055 return -EIO;
1056 }
3d396eb1 1057
2956640d 1058 err = netxen_alloc_sw_resources(adapter);
3d396eb1 1059 if (err) {
2956640d
DP
1060 printk(KERN_ERR "%s: Error in setting sw resources\n",
1061 netdev->name);
3d396eb1
AK
1062 return err;
1063 }
2956640d
DP
1064
1065 netxen_nic_clear_stats(adapter);
1066
1067 err = netxen_alloc_hw_resources(adapter);
1068 if (err) {
1069 printk(KERN_ERR "%s: Error in setting hw resources\n",
1070 netdev->name);
1071 goto err_out_free_sw;
1072 }
1073
1074 if (adapter->fw_major < 4) {
1075 adapter->crb_addr_cmd_producer =
1076 crb_cmd_producer[adapter->portnum];
1077 adapter->crb_addr_cmd_consumer =
1078 crb_cmd_consumer[adapter->portnum];
1079 }
1080
1081 netxen_nic_update_cmd_producer(adapter, 0);
1082 netxen_nic_update_cmd_consumer(adapter, 0);
1083
3d396eb1 1084 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
48bfd1e0 1085 for (ring = 0; ring < adapter->max_rds_rings; ring++)
3d396eb1 1086 netxen_post_rx_buffers(adapter, ctx, ring);
3d396eb1 1087 }
2956640d 1088 if (NETXEN_IS_MSI_FAMILY(adapter))
05aaa02d
DP
1089 handler = netxen_msi_intr;
1090 else {
1091 flags |= IRQF_SHARED;
1092 handler = netxen_intr;
1093 }
2956640d 1094 adapter->irq = netdev->irq;
05aaa02d
DP
1095 err = request_irq(adapter->irq, handler,
1096 flags, netdev->name, adapter);
3d396eb1
AK
1097 if (err) {
1098 printk(KERN_ERR "request_irq failed with: %d\n", err);
2956640d 1099 goto err_out_free_hw;
3d396eb1 1100 }
ed25ffa1
AK
1101
1102 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1103 }
2956640d 1104
3d396eb1
AK
1105 /* Done here again so that even if phantom sw overwrote it,
1106 * we set it */
c9fc891f 1107 err = adapter->init_port(adapter, adapter->physical_port);
2956640d 1108 if (err) {
595e3fb8
MT
1109 printk(KERN_ERR "%s: Failed to initialize port %d\n",
1110 netxen_nic_driver_name, adapter->portnum);
2956640d 1111 goto err_out_free_irq;
595e3fb8 1112 }
2956640d 1113 adapter->macaddr_set(adapter, netdev->dev_addr);
595e3fb8 1114
3176ff3e 1115 netxen_nic_set_link_parameters(adapter);
3d396eb1 1116
c9fc891f
DP
1117 netdev->set_multicast_list(netdev);
1118 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1119 nx_fw_cmd_set_mtu(adapter, netdev->mtu);
1120 else
1121 adapter->set_mtu(adapter, netdev->mtu);
ed25ffa1 1122
dcd56fdb 1123 mod_timer(&adapter->watchdog_timer, jiffies);
05aaa02d
DP
1124
1125 napi_enable(&adapter->napi);
1126 netxen_nic_enable_int(adapter);
1127
dcd56fdb 1128 netif_start_queue(netdev);
3d396eb1
AK
1129
1130 return 0;
2956640d
DP
1131
1132err_out_free_irq:
1133 free_irq(adapter->irq, adapter);
1134err_out_free_hw:
1135 netxen_free_hw_resources(adapter);
1136err_out_free_sw:
1137 netxen_free_sw_resources(adapter);
1138 return err;
3d396eb1
AK
1139}
1140
1141/*
1142 * netxen_nic_close - Disables a network interface entry point
1143 */
1144static int netxen_nic_close(struct net_device *netdev)
1145{
3176ff3e 1146 struct netxen_adapter *adapter = netdev_priv(netdev);
3d396eb1
AK
1147
1148 netif_carrier_off(netdev);
1149 netif_stop_queue(netdev);
bea3348e 1150 napi_disable(&adapter->napi);
3d396eb1 1151
72b0a7a8 1152 if (adapter->stop_port)
1153 adapter->stop_port(adapter);
1154
e01872af 1155 netxen_nic_disable_int(adapter);
1156
2956640d
DP
1157 netxen_release_tx_buffers(adapter);
1158
96acb6eb
DP
1159 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
1160 FLUSH_SCHEDULED_WORK();
1161 del_timer_sync(&adapter->watchdog_timer);
1162 }
3d396eb1
AK
1163
1164 return 0;
1165}
1166
cd1f8160
DP
1167void netxen_tso_check(struct netxen_adapter *adapter,
1168 struct cmd_desc_type0 *desc, struct sk_buff *skb)
1169{
1170 if (desc->mss) {
1171 desc->total_hdr_length = (sizeof(struct ethhdr) +
1172 ip_hdrlen(skb) + tcp_hdrlen(skb));
1173
1174 if ((NX_IS_REVISION_P3(adapter->ahw.revision_id)) &&
1175 (skb->protocol == htons(ETH_P_IPV6)))
1176 netxen_set_cmd_desc_opcode(desc, TX_TCP_LSO6);
1177 else
1178 netxen_set_cmd_desc_opcode(desc, TX_TCP_LSO);
1179
1180 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
1181 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
1182 netxen_set_cmd_desc_opcode(desc, TX_TCP_PKT);
1183 else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
1184 netxen_set_cmd_desc_opcode(desc, TX_UDP_PKT);
1185 else
1186 return;
1187 }
1188 desc->tcp_hdr_offset = skb_transport_offset(skb);
1189 desc->ip_hdr_offset = skb_network_offset(skb);
1190}
1191
3d396eb1
AK
1192static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1193{
3176ff3e 1194 struct netxen_adapter *adapter = netdev_priv(netdev);
3d396eb1
AK
1195 struct netxen_hardware_context *hw = &adapter->ahw;
1196 unsigned int first_seg_len = skb->len - skb->data_len;
1197 struct netxen_skb_frag *buffrag;
1198 unsigned int i;
1199
ba53e6b4 1200 u32 producer, consumer;
3d396eb1
AK
1201 u32 saved_producer = 0;
1202 struct cmd_desc_type0 *hwdesc;
1203 int k;
1204 struct netxen_cmd_buffer *pbuf = NULL;
3d396eb1 1205 int frag_count;
3d396eb1 1206 int no_of_desc;
ba53e6b4 1207 u32 num_txd = adapter->max_tx_desc_count;
3d396eb1 1208
3d396eb1
AK
1209 frag_count = skb_shinfo(skb)->nr_frags + 1;
1210
3d396eb1
AK
1211 /* There 4 fragments per descriptor */
1212 no_of_desc = (frag_count + 3) >> 2;
cd1f8160 1213 if (netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) {
cb8011ad
AK
1214 if (skb_shinfo(skb)->gso_size > 0) {
1215
3d396eb1 1216 no_of_desc++;
ab6a5bb6 1217 if ((ip_hdrlen(skb) + tcp_hdrlen(skb) +
c9bdd4b5 1218 sizeof(struct ethhdr)) >
ed25ffa1 1219 (sizeof(struct cmd_desc_type0) - 2)) {
cb8011ad
AK
1220 no_of_desc++;
1221 }
3d396eb1
AK
1222 }
1223 }
53a01e00 1224
ba53e6b4
DP
1225 producer = adapter->cmd_producer;
1226 smp_mb();
1227 consumer = adapter->last_cmd_consumer;
1228 if ((no_of_desc+2) > find_diff_among(producer, consumer, num_txd)) {
1229 netif_stop_queue(netdev);
1230 smp_mb();
1231 return NETDEV_TX_BUSY;
53a01e00 1232 }
3d396eb1 1233
3d396eb1 1234 /* Copy the descriptors into the hardware */
3d396eb1
AK
1235 saved_producer = producer;
1236 hwdesc = &hw->cmd_desc_head[producer];
1237 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
1238 /* Take skb->data itself */
1239 pbuf = &adapter->cmd_buf_arr[producer];
cd1f8160
DP
1240 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1241 skb_shinfo(skb)->gso_size > 0) {
a608ab9c 1242 pbuf->mss = skb_shinfo(skb)->gso_size;
ed33ebe4 1243 hwdesc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
3d396eb1
AK
1244 } else {
1245 pbuf->mss = 0;
1246 hwdesc->mss = 0;
1247 }
3d396eb1
AK
1248 pbuf->total_length = skb->len;
1249 pbuf->skb = skb;
1250 pbuf->cmd = TX_ETHER_PKT;
1251 pbuf->frag_count = frag_count;
3176ff3e 1252 pbuf->port = adapter->portnum;
3d396eb1 1253 buffrag = &pbuf->frag_array[0];
3176ff3e 1254 buffrag->dma = pci_map_single(adapter->pdev, skb->data, first_seg_len,
3d396eb1
AK
1255 PCI_DMA_TODEVICE);
1256 buffrag->length = first_seg_len;
ed25ffa1
AK
1257 netxen_set_cmd_desc_totallength(hwdesc, skb->len);
1258 netxen_set_cmd_desc_num_of_buff(hwdesc, frag_count);
1259 netxen_set_cmd_desc_opcode(hwdesc, TX_ETHER_PKT);
3d396eb1 1260
3176ff3e 1261 netxen_set_cmd_desc_port(hwdesc, adapter->portnum);
6c80b18d 1262 netxen_set_cmd_desc_ctxid(hwdesc, adapter->portnum);
3d396eb1
AK
1263 hwdesc->buffer1_length = cpu_to_le16(first_seg_len);
1264 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
1265
1266 for (i = 1, k = 1; i < frag_count; i++, k++) {
1267 struct skb_frag_struct *frag;
1268 int len, temp_len;
1269 unsigned long offset;
1270 dma_addr_t temp_dma;
1271
1272 /* move to next desc. if there is a need */
1273 if ((i & 0x3) == 0) {
1274 k = 0;
ba53e6b4 1275 producer = get_next_index(producer, num_txd);
3d396eb1
AK
1276 hwdesc = &hw->cmd_desc_head[producer];
1277 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
53a01e00 1278 pbuf = &adapter->cmd_buf_arr[producer];
1279 pbuf->skb = NULL;
3d396eb1
AK
1280 }
1281 frag = &skb_shinfo(skb)->frags[i - 1];
1282 len = frag->size;
1283 offset = frag->page_offset;
1284
1285 temp_len = len;
3176ff3e 1286 temp_dma = pci_map_page(adapter->pdev, frag->page, offset,
3d396eb1
AK
1287 len, PCI_DMA_TODEVICE);
1288
1289 buffrag++;
1290 buffrag->dma = temp_dma;
1291 buffrag->length = temp_len;
1292
3d396eb1
AK
1293 switch (k) {
1294 case 0:
1295 hwdesc->buffer1_length = cpu_to_le16(temp_len);
1296 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
1297 break;
1298 case 1:
1299 hwdesc->buffer2_length = cpu_to_le16(temp_len);
1300 hwdesc->addr_buffer2 = cpu_to_le64(temp_dma);
1301 break;
1302 case 2:
1303 hwdesc->buffer3_length = cpu_to_le16(temp_len);
1304 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
1305 break;
1306 case 3:
a608ab9c 1307 hwdesc->buffer4_length = cpu_to_le16(temp_len);
3d396eb1
AK
1308 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
1309 break;
1310 }
1311 frag++;
1312 }
ba53e6b4 1313 producer = get_next_index(producer, num_txd);
3d396eb1
AK
1314
1315 /* might change opcode to TX_TCP_LSO */
1316 netxen_tso_check(adapter, &hw->cmd_desc_head[saved_producer], skb);
1317
1318 /* For LSO, we need to copy the MAC/IP/TCP headers into
1319 * the descriptor ring
1320 */
ed25ffa1
AK
1321 if (netxen_get_cmd_desc_opcode(&hw->cmd_desc_head[saved_producer])
1322 == TX_TCP_LSO) {
3d396eb1
AK
1323 int hdr_len, first_hdr_len, more_hdr;
1324 hdr_len = hw->cmd_desc_head[saved_producer].total_hdr_length;
ed25ffa1
AK
1325 if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) {
1326 first_hdr_len = sizeof(struct cmd_desc_type0) - 2;
3d396eb1
AK
1327 more_hdr = 1;
1328 } else {
1329 first_hdr_len = hdr_len;
1330 more_hdr = 0;
1331 }
1332 /* copy the MAC/IP/TCP headers to the cmd descriptor list */
1333 hwdesc = &hw->cmd_desc_head[producer];
53a01e00 1334 pbuf = &adapter->cmd_buf_arr[producer];
1335 pbuf->skb = NULL;
3d396eb1
AK
1336
1337 /* copy the first 64 bytes */
ed25ffa1 1338 memcpy(((void *)hwdesc) + 2,
3d396eb1 1339 (void *)(skb->data), first_hdr_len);
ba53e6b4 1340 producer = get_next_index(producer, num_txd);
3d396eb1
AK
1341
1342 if (more_hdr) {
1343 hwdesc = &hw->cmd_desc_head[producer];
53a01e00 1344 pbuf = &adapter->cmd_buf_arr[producer];
1345 pbuf->skb = NULL;
3d396eb1
AK
1346 /* copy the next 64 bytes - should be enough except
1347 * for pathological case
1348 */
d626f62b
ACM
1349 skb_copy_from_linear_data_offset(skb, first_hdr_len,
1350 hwdesc,
1351 (hdr_len -
1352 first_hdr_len));
ba53e6b4 1353 producer = get_next_index(producer, num_txd);
3d396eb1
AK
1354 }
1355 }
6c80b18d 1356
ba53e6b4 1357 adapter->cmd_producer = producer;
5dc16268 1358 adapter->stats.txbytes += skb->len;
6c80b18d 1359
ba53e6b4 1360 netxen_nic_update_cmd_producer(adapter, adapter->cmd_producer);
3d396eb1 1361
ba53e6b4 1362 adapter->stats.xmitcalled++;
3d396eb1
AK
1363 netdev->trans_start = jiffies;
1364
3d396eb1
AK
1365 return NETDEV_TX_OK;
1366}
1367
a97342f9
DP
1368static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1369{
1370 struct net_device *netdev = adapter->netdev;
1371 uint32_t temp, temp_state, temp_val;
1372 int rv = 0;
1373
1374 temp = adapter->pci_read_normalize(adapter, CRB_TEMP_STATE);
1375
1376 temp_state = nx_get_temp_state(temp);
1377 temp_val = nx_get_temp_val(temp);
1378
1379 if (temp_state == NX_TEMP_PANIC) {
1380 printk(KERN_ALERT
1381 "%s: Device temperature %d degrees C exceeds"
1382 " maximum allowed. Hardware has been shut down.\n",
1383 netxen_nic_driver_name, temp_val);
1384
1385 netif_carrier_off(netdev);
1386 netif_stop_queue(netdev);
1387 rv = 1;
1388 } else if (temp_state == NX_TEMP_WARN) {
1389 if (adapter->temp == NX_TEMP_NORMAL) {
1390 printk(KERN_ALERT
1391 "%s: Device temperature %d degrees C "
1392 "exceeds operating range."
1393 " Immediate action needed.\n",
1394 netxen_nic_driver_name, temp_val);
1395 }
1396 } else {
1397 if (adapter->temp == NX_TEMP_WARN) {
1398 printk(KERN_INFO
1399 "%s: Device temperature is now %d degrees C"
1400 " in normal range.\n", netxen_nic_driver_name,
1401 temp_val);
1402 }
1403 }
1404 adapter->temp = temp_state;
1405 return rv;
1406}
1407
1408static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1409{
1410 struct net_device *netdev = adapter->netdev;
1411 u32 val, port, linkup;
1412
1413 port = adapter->physical_port;
1414
24a7a455
DP
1415 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1416 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE_P3);
1417 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1418 linkup = (val == XG_LINK_UP_P3);
c9fc891f 1419 } else {
24a7a455
DP
1420 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
1421 if (adapter->ahw.board_type == NETXEN_NIC_GBE)
1422 linkup = (val >> port) & 1;
1423 else {
c9fc891f
DP
1424 val = (val >> port*8) & 0xff;
1425 linkup = (val == XG_LINK_UP);
c9fc891f 1426 }
a97342f9
DP
1427 }
1428
1429 if (adapter->ahw.linkup && !linkup) {
1430 printk(KERN_INFO "%s: %s NIC Link is down\n",
1431 netxen_nic_driver_name, netdev->name);
1432 adapter->ahw.linkup = 0;
1433 if (netif_running(netdev)) {
1434 netif_carrier_off(netdev);
1435 netif_stop_queue(netdev);
1436 }
1437 } else if (!adapter->ahw.linkup && linkup) {
1438 printk(KERN_INFO "%s: %s NIC Link is up\n",
1439 netxen_nic_driver_name, netdev->name);
1440 adapter->ahw.linkup = 1;
1441 if (netif_running(netdev)) {
1442 netif_carrier_on(netdev);
1443 netif_wake_queue(netdev);
1444 }
1445 }
1446}
1447
3d396eb1
AK
1448static void netxen_watchdog(unsigned long v)
1449{
1450 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
ed25ffa1
AK
1451
1452 SCHEDULE_WORK(&adapter->watchdog_task);
3d396eb1
AK
1453}
1454
a97342f9
DP
1455void netxen_watchdog_task(struct work_struct *work)
1456{
1457 struct netxen_adapter *adapter =
1458 container_of(work, struct netxen_adapter, watchdog_task);
1459
1460 if ((adapter->portnum == 0) && netxen_nic_check_temp(adapter))
1461 return;
1462
1463 netxen_nic_handle_phy_intr(adapter);
1464
1465 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1466}
1467
3d396eb1
AK
1468static void netxen_tx_timeout(struct net_device *netdev)
1469{
3176ff3e
MT
1470 struct netxen_adapter *adapter = (struct netxen_adapter *)
1471 netdev_priv(netdev);
1472 SCHEDULE_WORK(&adapter->tx_timeout_task);
3d396eb1
AK
1473}
1474
6d5aefb8 1475static void netxen_tx_timeout_task(struct work_struct *work)
3d396eb1 1476{
4790654c 1477 struct netxen_adapter *adapter =
3176ff3e 1478 container_of(work, struct netxen_adapter, tx_timeout_task);
3d396eb1
AK
1479
1480 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
6c80b18d 1481 netxen_nic_driver_name, adapter->netdev->name);
3d396eb1 1482
ba53e6b4
DP
1483 netxen_nic_disable_int(adapter);
1484 napi_disable(&adapter->napi);
1485
6c80b18d 1486 adapter->netdev->trans_start = jiffies;
ba53e6b4
DP
1487
1488 napi_enable(&adapter->napi);
1489 netxen_nic_enable_int(adapter);
6c80b18d 1490 netif_wake_queue(adapter->netdev);
3d396eb1
AK
1491}
1492
a97342f9
DP
1493/*
1494 * netxen_nic_get_stats - Get System Network Statistics
1495 * @netdev: network interface device structure
1496 */
1497struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1498{
1499 struct netxen_adapter *adapter = netdev_priv(netdev);
1500 struct net_device_stats *stats = &adapter->net_stats;
1501
1502 memset(stats, 0, sizeof(*stats));
1503
1504 /* total packets received */
1505 stats->rx_packets = adapter->stats.no_rcv;
1506 /* total packets transmitted */
1507 stats->tx_packets = adapter->stats.xmitedframes +
1508 adapter->stats.xmitfinished;
1509 /* total bytes received */
1510 stats->rx_bytes = adapter->stats.rxbytes;
1511 /* total bytes transmitted */
1512 stats->tx_bytes = adapter->stats.txbytes;
1513 /* bad packets received */
1514 stats->rx_errors = adapter->stats.rcvdbadskb;
1515 /* packet transmit problems */
1516 stats->tx_errors = adapter->stats.nocmddescriptor;
1517 /* no space in linux buffers */
1518 stats->rx_dropped = adapter->stats.rxdropped;
1519 /* no space available in linux */
1520 stats->tx_dropped = adapter->stats.txdropped;
1521
1522 return stats;
1523}
1524
05aaa02d
DP
1525static inline void
1526netxen_handle_int(struct netxen_adapter *adapter)
3d396eb1 1527{
2d1a3bbd 1528 netxen_nic_disable_int(adapter);
05aaa02d 1529 napi_schedule(&adapter->napi);
3d396eb1
AK
1530}
1531
e4c93c81 1532static irqreturn_t netxen_intr(int irq, void *data)
3d396eb1 1533{
1daec86a 1534 struct netxen_adapter *adapter = data;
e01872af 1535 u32 our_int = 0;
3d396eb1 1536
d71e1be8
DP
1537 u32 status = 0;
1538
1539 status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1540
1541 if (!(status & adapter->legacy_intr.int_vec_bit))
05aaa02d 1542 return IRQ_NONE;
e01872af 1543
d71e1be8
DP
1544 if (adapter->ahw.revision_id >= NX_P3_B1) {
1545 /* check interrupt state machine, to be sure */
1546 status = adapter->pci_read_immediate(adapter,
1547 ISR_INT_STATE_REG);
1548 if (!ISR_LEGACY_INT_TRIGGERED(status))
1549 return IRQ_NONE;
1550
1551 } else if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1552
1553 our_int = adapter->pci_read_normalize(adapter, CRB_INT_VECTOR);
1554 /* not our interrupt */
1555 if ((our_int & (0x80 << adapter->portnum)) == 0)
1556 return IRQ_NONE;
1557
1558 if (adapter->intr_scheme == INTR_SCHEME_PERPORT) {
1559 /* claim interrupt */
1560 adapter->pci_write_normalize(adapter,
1561 CRB_INT_VECTOR,
3ce06a32 1562 our_int & ~((u32)(0x80 << adapter->portnum)));
d71e1be8 1563 }
e01872af 1564 }
1565
05aaa02d 1566 netxen_handle_int(adapter);
3d396eb1
AK
1567
1568 return IRQ_HANDLED;
1569}
1570
e4c93c81 1571static irqreturn_t netxen_msi_intr(int irq, void *data)
05aaa02d
DP
1572{
1573 struct netxen_adapter *adapter = data;
1574
1575 netxen_handle_int(adapter);
1576 return IRQ_HANDLED;
1577}
1578
bea3348e 1579static int netxen_nic_poll(struct napi_struct *napi, int budget)
3d396eb1 1580{
bea3348e 1581 struct netxen_adapter *adapter = container_of(napi, struct netxen_adapter, napi);
05aaa02d 1582 int tx_complete;
3d396eb1 1583 int ctx;
bea3348e 1584 int work_done;
3d396eb1 1585
05aaa02d 1586 tx_complete = netxen_process_cmd_ring(adapter);
3d396eb1 1587
80922fbc 1588 work_done = 0;
3d396eb1
AK
1589 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
1590 /*
1591 * Fairness issue. This will give undue weight to the
1592 * receive context 0.
1593 */
1594
1595 /*
1596 * To avoid starvation, we give each of our receivers,
1597 * a fraction of the quota. Sometimes, it might happen that we
1598 * have enough quota to process every packet, but since all the
1599 * packets are on one context, it gets only half of the quota,
1600 * and ends up not processing it.
1601 */
bea3348e
SH
1602 work_done += netxen_process_rcv_ring(adapter, ctx,
1603 budget / MAX_RCV_CTX);
3d396eb1
AK
1604 }
1605
05aaa02d
DP
1606 if ((work_done < budget) && tx_complete) {
1607 netif_rx_complete(adapter->netdev, &adapter->napi);
3d396eb1
AK
1608 netxen_nic_enable_int(adapter);
1609 }
1610
bea3348e 1611 return work_done;
3d396eb1
AK
1612}
1613
1614#ifdef CONFIG_NET_POLL_CONTROLLER
1615static void netxen_nic_poll_controller(struct net_device *netdev)
1616{
3176ff3e 1617 struct netxen_adapter *adapter = netdev_priv(netdev);
3d396eb1 1618 disable_irq(adapter->irq);
1494a814 1619 netxen_intr(adapter->irq, adapter);
3d396eb1
AK
1620 enable_irq(adapter->irq);
1621}
1622#endif
3d396eb1
AK
1623
1624static struct pci_driver netxen_driver = {
1625 .name = netxen_nic_driver_name,
1626 .id_table = netxen_pci_tbl,
1627 .probe = netxen_nic_probe,
1628 .remove = __devexit_p(netxen_nic_remove)
1629};
1630
1631/* Driver Registration on NetXen card */
1632
1633static int __init netxen_init_module(void)
1634{
79ea13ce 1635 if ((netxen_workq = create_singlethread_workqueue("netxen")) == NULL)
ed25ffa1
AK
1636 return -ENOMEM;
1637
184231bd 1638 return pci_register_driver(&netxen_driver);
3d396eb1
AK
1639}
1640
1641module_init(netxen_init_module);
1642
1643static void __exit netxen_exit_module(void)
1644{
3d396eb1 1645 pci_unregister_driver(&netxen_driver);
9de06610 1646 destroy_workqueue(netxen_workq);
3d396eb1
AK
1647}
1648
1649module_exit(netxen_exit_module);