blob: dba8e6b29ff3d5c45264de95588d1db4bc821573 [file] [log] [blame]
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001/*
2 * Copyright (C) 2003 - 2006 NetXen, Inc.
3 * All rights reserved.
Amit S. Kale80922fb2006-12-04 09:18:00 -08004 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -04005 * 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.
Amit S. Kale80922fb2006-12-04 09:18:00 -08009 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040010 * 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.
Amit S. Kale80922fb2006-12-04 09:18:00 -080014 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040015 * 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.
Amit S. Kale80922fb2006-12-04 09:18:00 -080019 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040020 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
Amit S. Kale80922fb2006-12-04 09:18:00 -080022 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040023 * 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
Amit S. Kalecb8011a2006-11-29 09:00:10 -080034#include <linux/vmalloc.h>
Amit S. Kaleed25ffa2006-12-04 09:23:25 -080035#include <linux/highmem.h>
Amit S. Kale3d396eb2006-10-21 15:33:03 -040036#include "netxen_nic_hw.h"
37
38#include "netxen_nic.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040039#include "netxen_nic_phan_reg.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040040
Jeff Garzik1494a812006-11-07 05:12:16 -050041#include <linux/dma-mapping.h>
42#include <linux/vmalloc.h>
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030043#include <net/ip.h>
Jeff Garzik1494a812006-11-07 05:12:16 -050044
Amit S. Kale3d396eb2006-10-21 15:33:03 -040045MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
46MODULE_LICENSE("GPL");
47MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
48
Amit S. Kaleed25ffa2006-12-04 09:23:25 -080049char netxen_nic_driver_name[] = "netxen-nic";
Amit S. Kale3d396eb2006-10-21 15:33:03 -040050static char netxen_nic_driver_string[] = "NetXen Network Driver version "
Amit S. Kalecb8011a2006-11-29 09:00:10 -080051 NETXEN_NIC_LINUX_VERSIONID;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040052
53#define NETXEN_NETDEV_WEIGHT 120
54#define NETXEN_ADAPTER_UP_MAGIC 777
Amit S. Kalecb8011a2006-11-29 09:00:10 -080055#define NETXEN_NIC_PEG_TUNE 0
Amit S. Kale3d396eb2006-10-21 15:33:03 -040056
Amit S. Kaleed25ffa2006-12-04 09:23:25 -080057u8 nx_p2_id = NX_P2_C0;
58
59#define DMA_32BIT_MASK 0x00000000ffffffffULL
60#define DMA_35BIT_MASK 0x00000007ffffffffULL
61
Amit S. Kale3d396eb2006-10-21 15:33:03 -040062/* Local functions to NetXen NIC driver */
63static int __devinit netxen_nic_probe(struct pci_dev *pdev,
64 const struct pci_device_id *ent);
65static void __devexit netxen_nic_remove(struct pci_dev *pdev);
66static int netxen_nic_open(struct net_device *netdev);
67static int netxen_nic_close(struct net_device *netdev);
68static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *);
69static void netxen_tx_timeout(struct net_device *netdev);
David Howells6d5aefb2006-12-05 19:36:26 +000070static void netxen_tx_timeout_task(struct work_struct *work);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040071static void netxen_watchdog(unsigned long);
72static int netxen_handle_int(struct netxen_adapter *, struct net_device *);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040073static int netxen_nic_poll(struct net_device *dev, int *budget);
74#ifdef CONFIG_NET_POLL_CONTROLLER
75static void netxen_nic_poll_controller(struct net_device *netdev);
76#endif
Jeff Garzik1494a812006-11-07 05:12:16 -050077static irqreturn_t netxen_intr(int irq, void *data);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040078
Mithlesh Thukral6c80b182007-04-20 07:55:26 -070079int physical_port[] = {0, 1, 2, 3};
80
Amit S. Kale3d396eb2006-10-21 15:33:03 -040081/* PCI Device ID Table */
82static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
83 {PCI_DEVICE(0x4040, 0x0001)},
84 {PCI_DEVICE(0x4040, 0x0002)},
85 {PCI_DEVICE(0x4040, 0x0003)},
86 {PCI_DEVICE(0x4040, 0x0004)},
87 {PCI_DEVICE(0x4040, 0x0005)},
Amit S. Kale0d390732006-12-18 05:50:59 -080088 {PCI_DEVICE(0x4040, 0x0024)},
89 {PCI_DEVICE(0x4040, 0x0025)},
Amit S. Kale3d396eb2006-10-21 15:33:03 -040090 {0,}
91};
92
93MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
94
Amit S. Kaleed25ffa2006-12-04 09:23:25 -080095struct workqueue_struct *netxen_workq;
96static void netxen_watchdog(unsigned long);
97
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070098static inline void netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
99 uint32_t crb_producer)
100{
101 switch (adapter->portnum) {
102 case 0:
103 writel(crb_producer, NETXEN_CRB_NORMALIZE
104 (adapter, CRB_CMD_PRODUCER_OFFSET));
105 return;
106 case 1:
107 writel(crb_producer, NETXEN_CRB_NORMALIZE
108 (adapter, CRB_CMD_PRODUCER_OFFSET_1));
109 return;
110 case 2:
111 writel(crb_producer, NETXEN_CRB_NORMALIZE
112 (adapter, CRB_CMD_PRODUCER_OFFSET_2));
113 return;
114 case 3:
115 writel(crb_producer, NETXEN_CRB_NORMALIZE
116 (adapter, CRB_CMD_PRODUCER_OFFSET_3));
117 return;
118 default:
119 printk(KERN_WARNING "We tried to update "
120 "CRB_CMD_PRODUCER_OFFSET for invalid "
121 "PCI function id %d\n",
122 adapter->portnum);
123 return;
124 }
125}
126
127static inline void netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
128 u32 crb_consumer)
129{
130 switch (adapter->portnum) {
131 case 0:
132 writel(crb_consumer, NETXEN_CRB_NORMALIZE
133 (adapter, CRB_CMD_CONSUMER_OFFSET));
134 return;
135 case 1:
136 writel(crb_consumer, NETXEN_CRB_NORMALIZE
137 (adapter, CRB_CMD_CONSUMER_OFFSET_1));
138 return;
139 case 2:
140 writel(crb_consumer, NETXEN_CRB_NORMALIZE
141 (adapter, CRB_CMD_CONSUMER_OFFSET_2));
142 return;
143 case 3:
144 writel(crb_consumer, NETXEN_CRB_NORMALIZE
145 (adapter, CRB_CMD_CONSUMER_OFFSET_3));
146 return;
147 default:
148 printk(KERN_WARNING "We tried to update "
149 "CRB_CMD_PRODUCER_OFFSET for invalid "
150 "PCI function id %d\n",
151 adapter->portnum);
152 return;
153 }
154}
155
156#define ADAPTER_LIST_SIZE 12
157int netxen_cards_found;
158
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400159/*
160 * netxen_nic_probe()
161 *
162 * The Linux system will invoke this after identifying the vendor ID and
163 * device Id in the pci_tbl supported by this module.
164 *
165 * A quad port card has one operational PCI config space, (function 0),
166 * which is used to access all four ports.
167 *
168 * This routine will initialize the adapter, and setup the global parameters
169 * along with the port's specific structure.
170 */
171static int __devinit
172netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
173{
174 struct net_device *netdev = NULL;
175 struct netxen_adapter *adapter = NULL;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800176 void __iomem *mem_ptr0 = NULL;
177 void __iomem *mem_ptr1 = NULL;
178 void __iomem *mem_ptr2 = NULL;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700179 unsigned long first_page_group_end;
180 unsigned long first_page_group_start;
181
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800182
Al Viroa608ab9c2007-01-02 10:39:10 +0000183 u8 __iomem *db_ptr = NULL;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800184 unsigned long mem_base, mem_len, db_base, db_len;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700185 int pci_using_dac, i = 0, err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400186 int ring;
187 struct netxen_recv_context *recv_ctx = NULL;
188 struct netxen_rcv_desc_ctx *rcv_desc = NULL;
189 struct netxen_cmd_buffer *cmd_buf_arr = NULL;
190 u64 mac_addr[FLASH_NUM_PORTS + 1];
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700191 int valid_mac = 0;
192 u32 val;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700193 int pci_func_id = PCI_FUNC(pdev->devfn);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400194
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800195 printk(KERN_INFO "%s \n", netxen_nic_driver_string);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700196
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700197 if (pdev->class != 0x020000) {
198 printk(KERN_ERR"NetXen function %d, class %x will not"
199 "be enabled.\n",pci_func_id, pdev->class);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800200 return -ENODEV;
201 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400202 if ((err = pci_enable_device(pdev)))
203 return err;
204 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
205 err = -ENODEV;
206 goto err_out_disable_pdev;
207 }
208
209 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
210 goto err_out_disable_pdev;
211
212 pci_set_master(pdev);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800213 pci_read_config_byte(pdev, PCI_REVISION_ID, &nx_p2_id);
214 if (nx_p2_id == NX_P2_C1 &&
215 (pci_set_dma_mask(pdev, DMA_35BIT_MASK) == 0) &&
216 (pci_set_consistent_dma_mask(pdev, DMA_35BIT_MASK) == 0)) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400217 pci_using_dac = 1;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800218 } else {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400219 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) ||
220 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK)))
221 goto err_out_free_res;
222
223 pci_using_dac = 0;
224 }
225
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700226
227 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
228 if(!netdev) {
229 printk(KERN_ERR"%s: Failed to allocate memory for the "
230 "device block.Check system memory resource"
231 " usage.\n", netxen_nic_driver_name);
232 goto err_out_free_res;
233 }
234
235 SET_MODULE_OWNER(netdev);
236 SET_NETDEV_DEV(netdev, &pdev->dev);
237
238 adapter = netdev->priv;
239 memset(adapter, 0 , sizeof(struct netxen_adapter));
240
241 adapter->ahw.pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700242 adapter->ahw.pci_func = pci_func_id;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700243 spin_lock_init(&adapter->tx_lock);
244 spin_lock_init(&adapter->lock);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700245
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400246 /* remap phys address */
247 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
248 mem_len = pci_resource_len(pdev, 0);
249
250 /* 128 Meg of memory */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700251 if (mem_len == NETXEN_PCI_128MB_SIZE) {
252 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
253 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
254 SECOND_PAGE_GROUP_SIZE);
255 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
256 THIRD_PAGE_GROUP_SIZE);
257 first_page_group_start = FIRST_PAGE_GROUP_START;
258 first_page_group_end = FIRST_PAGE_GROUP_END;
259 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
260 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
261 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
262 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
263 first_page_group_start = 0;
264 first_page_group_end = 0;
265 } else {
266 err = -EIO;
267 goto err_out_free_netdev;
268 }
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800269
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700270 if (((mem_ptr0 == 0UL) && (mem_len == NETXEN_PCI_128MB_SIZE)) ||
271 (mem_ptr1 == 0UL) || (mem_ptr2 == 0UL)) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800272 DPRINTK(ERR,
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800273 "Cannot remap adapter memory aborting.:"
274 "0 -> %p, 1 -> %p, 2 -> %p\n",
275 mem_ptr0, mem_ptr1, mem_ptr2);
276
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400277 err = -EIO;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800278 goto err_out_iounmap;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400279 }
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800280 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
281 db_len = pci_resource_len(pdev, 4);
282
283 if (db_len == 0) {
284 printk(KERN_ERR "%s: doorbell is disabled\n",
285 netxen_nic_driver_name);
286 err = -EIO;
287 goto err_out_iounmap;
288 }
289 DPRINTK(INFO, "doorbell ioremap from %lx a size of %lx\n", db_base,
290 db_len);
291
292 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
Al Viroa608ab9c2007-01-02 10:39:10 +0000293 if (!db_ptr) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800294 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
295 netxen_nic_driver_name);
296 err = -EIO;
297 goto err_out_iounmap;
298 }
299 DPRINTK(INFO, "doorbell ioremaped at %p\n", db_ptr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400300
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700301 adapter->ahw.pci_base0 = mem_ptr0;
302 adapter->ahw.first_page_group_start = first_page_group_start;
303 adapter->ahw.first_page_group_end = first_page_group_end;
304 adapter->ahw.pci_base1 = mem_ptr1;
305 adapter->ahw.pci_base2 = mem_ptr2;
306 adapter->ahw.db_base = db_ptr;
307 adapter->ahw.db_len = db_len;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400308
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700309 adapter->netdev = netdev;
310 adapter->pdev = pdev;
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +0530311
312 /* this will be read from FW later */
313 adapter->intr_scheme = -1;
314
315 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700316 adapter->portnum = pci_func_id;
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +0530317 adapter->status &= ~NETXEN_NETDEV_STATUS;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700318
319 netdev->open = netxen_nic_open;
320 netdev->stop = netxen_nic_close;
321 netdev->hard_start_xmit = netxen_nic_xmit_frame;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700322 netdev->get_stats = netxen_nic_get_stats;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700323 netdev->set_multicast_list = netxen_nic_set_multi;
324 netdev->set_mac_address = netxen_nic_set_mac;
325 netdev->change_mtu = netxen_nic_change_mtu;
326 netdev->tx_timeout = netxen_tx_timeout;
327 netdev->watchdog_timeo = HZ;
328
329 netxen_nic_change_mtu(netdev, netdev->mtu);
330
331 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
332 netdev->poll = netxen_nic_poll;
333 netdev->weight = NETXEN_NETDEV_WEIGHT;
334#ifdef CONFIG_NET_POLL_CONTROLLER
335 netdev->poll_controller = netxen_nic_poll_controller;
336#endif
337 /* ScatterGather support */
338 netdev->features = NETIF_F_SG;
339 netdev->features |= NETIF_F_IP_CSUM;
340 netdev->features |= NETIF_F_TSO;
341
342 if (pci_using_dac)
343 netdev->features |= NETIF_F_HIGHDMA;
344
dhananjay.phadke@gmail.com644caee2007-07-02 00:25:59 +0530345 if (pci_enable_msi(pdev))
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700346 adapter->flags &= ~NETXEN_NIC_MSI_ENABLED;
dhananjay.phadke@gmail.com644caee2007-07-02 00:25:59 +0530347 else
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700348 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
349
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700350 netdev->irq = pdev->irq;
351 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
352
353 /*
354 * Set the CRB window to invalid. If any register in window 0 is
355 * accessed it should set the window to 0 and then reset it to 1.
356 */
357 adapter->curr_window = 255;
358
359 /* initialize the adapter */
360 netxen_initialize_adapter_hw(adapter);
361
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700362 /*
363 * Adapter in our case is quad port so initialize it before
364 * initializing the ports
365 */
366
367 netxen_initialize_adapter_ops(adapter);
368
369 adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS_HOST;
370 if ((adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB35_4G) ||
371 (adapter->ahw.boardcfg.board_type ==
372 NETXEN_BRDTYPE_P2_SB31_2G))
373 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
374 else
375 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS;
376 adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS;
377 adapter->max_lro_rx_desc_count = MAX_LRO_RCV_DESCRIPTORS;
378
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400379 cmd_buf_arr = (struct netxen_cmd_buffer *)vmalloc(TX_RINGSIZE);
380 if (cmd_buf_arr == NULL) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800381 printk(KERN_ERR
382 "%s: Could not allocate cmd_buf_arr memory:%d\n",
383 netxen_nic_driver_name, (int)TX_RINGSIZE);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400384 err = -ENOMEM;
385 goto err_out_free_adapter;
386 }
387 memset(cmd_buf_arr, 0, TX_RINGSIZE);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700388 adapter->cmd_buf_arr = cmd_buf_arr;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400389
390 for (i = 0; i < MAX_RCV_CTX; ++i) {
391 recv_ctx = &adapter->recv_ctx[i];
392 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
393 rcv_desc = &recv_ctx->rcv_desc[ring];
394 switch (RCV_DESC_TYPE(ring)) {
395 case RCV_DESC_NORMAL:
396 rcv_desc->max_rx_desc_count =
397 adapter->max_rx_desc_count;
398 rcv_desc->flags = RCV_DESC_NORMAL;
399 rcv_desc->dma_size = RX_DMA_MAP_LEN;
400 rcv_desc->skb_size = MAX_RX_BUFFER_LENGTH;
401 break;
402
403 case RCV_DESC_JUMBO:
404 rcv_desc->max_rx_desc_count =
405 adapter->max_jumbo_rx_desc_count;
406 rcv_desc->flags = RCV_DESC_JUMBO;
407 rcv_desc->dma_size = RX_JUMBO_DMA_MAP_LEN;
408 rcv_desc->skb_size = MAX_RX_JUMBO_BUFFER_LENGTH;
409 break;
410
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800411 case RCV_RING_LRO:
412 rcv_desc->max_rx_desc_count =
413 adapter->max_lro_rx_desc_count;
414 rcv_desc->flags = RCV_DESC_LRO;
415 rcv_desc->dma_size = RX_LRO_DMA_MAP_LEN;
416 rcv_desc->skb_size = MAX_RX_LRO_BUFFER_LENGTH;
417 break;
418
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400419 }
420 rcv_desc->rx_buf_arr = (struct netxen_rx_buffer *)
421 vmalloc(RCV_BUFFSIZE);
422
423 if (rcv_desc->rx_buf_arr == NULL) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800424 printk(KERN_ERR "%s: Could not allocate"
425 "rcv_desc->rx_buf_arr memory:%d\n",
426 netxen_nic_driver_name,
427 (int)RCV_BUFFSIZE);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400428 err = -ENOMEM;
429 goto err_out_free_rx_buffer;
430 }
431 memset(rcv_desc->rx_buf_arr, 0, RCV_BUFFSIZE);
432 }
433
434 }
435
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800436 netxen_initialize_adapter_sw(adapter); /* initialize the buffers in adapter */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700437
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700438 /* Mezz cards have PCI function 0,2,3 enabled */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700439 if ((adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ)
440 && (pci_func_id >= 2))
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700441 adapter->portnum = pci_func_id - 2;
442
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800443#ifdef CONFIG_IA64
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700444 if(adapter->portnum == 0) {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700445 netxen_pinit_from_rom(adapter, 0);
446 udelay(500);
447 netxen_load_firmware(adapter);
448 }
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800449#endif
450
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400451 init_timer(&adapter->watchdog_timer);
452 adapter->ahw.xg_linkup = 0;
453 adapter->watchdog_timer.function = &netxen_watchdog;
454 adapter->watchdog_timer.data = (unsigned long)adapter;
David Howells6d5aefb2006-12-05 19:36:26 +0000455 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400456 adapter->ahw.pdev = pdev;
457 adapter->proc_cmd_buf_counter = 0;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800458 adapter->ahw.revision_id = nx_p2_id;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400459
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700460 /* make sure Window == 1 */
461 netxen_nic_pci_change_crbwindow(adapter, 1);
462
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700463 netxen_nic_update_cmd_producer(adapter, 0);
464 netxen_nic_update_cmd_consumer(adapter, 0);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700465 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_HOST_CMD_ADDR_LO));
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400466
467 if (netxen_is_flash_supported(adapter) == 0 &&
468 netxen_get_flash_mac_addr(adapter, mac_addr) == 0)
469 valid_mac = 1;
470 else
471 valid_mac = 0;
472
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700473 if (valid_mac) {
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700474 unsigned char *p = (unsigned char *)&mac_addr[adapter->portnum];
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700475 netdev->dev_addr[0] = *(p + 5);
476 netdev->dev_addr[1] = *(p + 4);
477 netdev->dev_addr[2] = *(p + 3);
478 netdev->dev_addr[3] = *(p + 2);
479 netdev->dev_addr[4] = *(p + 1);
480 netdev->dev_addr[5] = *(p + 0);
481
482 memcpy(netdev->perm_addr, netdev->dev_addr,
483 netdev->addr_len);
484 if (!is_valid_ether_addr(netdev->perm_addr)) {
485 printk(KERN_ERR "%s: Bad MAC address "
486 "%02x:%02x:%02x:%02x:%02x:%02x.\n",
487 netxen_nic_driver_name,
488 netdev->dev_addr[0],
489 netdev->dev_addr[1],
490 netdev->dev_addr[2],
491 netdev->dev_addr[3],
492 netdev->dev_addr[4],
493 netdev->dev_addr[5]);
494 } else {
495 if (adapter->macaddr_set)
496 adapter->macaddr_set(adapter,
497 netdev->dev_addr);
498 }
499 }
500
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700501 if (adapter->portnum == 0) {
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700502 err = netxen_initialize_adapter_offload(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700503 if (err)
504 goto err_out_free_rx_buffer;
505 val = readl(NETXEN_CRB_NORMALIZE(adapter,
506 NETXEN_CAM_RAM(0x1fc)));
507 if (val == 0x55555555) {
508 /* This is the first boot after power up */
dhananjay.phadke@gmail.com644caee2007-07-02 00:25:59 +0530509 netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(0x4), &val);
510 if (!(val & 0x4)) {
511 val |= 0x4;
512 netxen_nic_write_w0(adapter, NETXEN_PCIE_REG(0x4), val);
513 netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(0x4), &val);
514 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700515 val = readl(NETXEN_CRB_NORMALIZE(adapter,
516 NETXEN_ROMUSB_GLB_SW_RESET));
517 printk(KERN_INFO"NetXen: read 0x%08x for reset reg.\n",val);
518 if (val != 0x80000f) {
519 /* clear the register for future unloads/loads */
dhananjay.phadke@gmail.com644caee2007-07-02 00:25:59 +0530520 writel(0, NETXEN_CRB_NORMALIZE(adapter,
521 NETXEN_CAM_RAM(0x1fc)));
522 printk(KERN_ERR "ERROR in NetXen HW init sequence.\n");
523 err = -ENODEV;
524 goto err_out_free_dev;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700525 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700526
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700527 /* clear the register for future unloads/loads */
528 writel(0, NETXEN_CRB_NORMALIZE(adapter,
529 NETXEN_CAM_RAM(0x1fc)));
530 }
531 printk(KERN_INFO "State: 0x%0x\n",
532 readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)));
533
534 /*
535 * Tell the hardware our version number.
536 */
537 i = (_NETXEN_NIC_LINUX_MAJOR << 16)
538 | ((_NETXEN_NIC_LINUX_MINOR << 8))
539 | (_NETXEN_NIC_LINUX_SUBVERSION);
540 writel(i, NETXEN_CRB_NORMALIZE(adapter, CRB_DRIVER_VERSION));
541
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700542 /* Unlock the HW, prompting the boot sequence */
543 writel(1,
544 NETXEN_CRB_NORMALIZE(adapter,
545 NETXEN_ROMUSB_GLB_PEGTUNE_DONE));
546 /* Handshake with the card before we register the devices. */
547 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
Mithlesh Thukral3e2face2007-06-07 04:33:02 -0700548
549 /* leave the hw in the same state as reboot */
550 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
551 netxen_pinit_from_rom(adapter, 0);
552 udelay(500);
553 netxen_load_firmware(adapter);
554 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800555 }
556
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400557 /*
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700558 * See if the firmware gave us a virtual-physical port mapping.
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400559 */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700560 i = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_V2P(adapter->portnum)));
561 if (i != 0x55555555)
562 physical_port[adapter->portnum] = i;
563
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700564 netif_carrier_off(netdev);
565 netif_stop_queue(netdev);
566
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700567 if ((err = register_netdev(netdev))) {
568 printk(KERN_ERR "%s: register_netdev failed port #%d"
569 " aborting\n", netxen_nic_driver_name,
570 adapter->portnum);
571 err = -EIO;
572 goto err_out_free_dev;
573 }
574
575 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400576
577 switch (adapter->ahw.board_type) {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700578 case NETXEN_NIC_GBE:
579 printk(KERN_INFO "%s: QUAD GbE board initialized\n",
580 netxen_nic_driver_name);
581 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400582
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700583 case NETXEN_NIC_XGBE:
584 printk(KERN_INFO "%s: XGbE board initialized\n",
585 netxen_nic_driver_name);
586 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400587 }
588
589 adapter->driver_mismatch = 0;
590
591 return 0;
592
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700593err_out_free_dev:
594 if (adapter->portnum == 0)
595 netxen_free_adapter_offload(adapter);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700596
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700597err_out_free_rx_buffer:
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400598 for (i = 0; i < MAX_RCV_CTX; ++i) {
599 recv_ctx = &adapter->recv_ctx[i];
600 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
601 rcv_desc = &recv_ctx->rcv_desc[ring];
602 if (rcv_desc->rx_buf_arr != NULL) {
603 vfree(rcv_desc->rx_buf_arr);
604 rcv_desc->rx_buf_arr = NULL;
605 }
606 }
607 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400608 vfree(cmd_buf_arr);
609
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700610err_out_free_adapter:
611 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
612 pci_disable_msi(pdev);
613
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400614 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400615
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800616 if (db_ptr)
617 iounmap(db_ptr);
618
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700619err_out_iounmap:
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800620 if (mem_ptr0)
621 iounmap(mem_ptr0);
622 if (mem_ptr1)
623 iounmap(mem_ptr1);
624 if (mem_ptr2)
625 iounmap(mem_ptr2);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800626
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700627err_out_free_netdev:
628 free_netdev(netdev);
629
630err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400631 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700632
633err_out_disable_pdev:
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400634 pci_disable_device(pdev);
635 return err;
636}
637
638static void __devexit netxen_nic_remove(struct pci_dev *pdev)
639{
640 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700641 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400642 struct netxen_rx_buffer *buffer;
643 struct netxen_recv_context *recv_ctx;
644 struct netxen_rcv_desc_ctx *rcv_desc;
645 int i;
646 int ctxid, ring;
647
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700648 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400649 if (adapter == NULL)
650 return;
651
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700652 netdev = adapter->netdev;
653
654 netxen_nic_disable_int(adapter);
655 if (adapter->irq)
656 free_irq(adapter->irq, adapter);
657
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700658 if (adapter->stop_port)
659 adapter->stop_port(adapter);
660
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700661 if ((adapter->flags & NETXEN_NIC_MSI_ENABLED))
662 pci_disable_msi(pdev);
663
664 if (adapter->portnum == 0)
665 netxen_free_adapter_offload(adapter);
666
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -0700667 if(adapter->portnum == 0) {
668 /* leave the hw in the same state as reboot */
669 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
670 netxen_pinit_from_rom(adapter, 0);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700671 udelay(500);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -0700672 netxen_load_firmware(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700673 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -0700674 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400675
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400676 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
677 netxen_free_hw_resources(adapter);
678
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400679 for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) {
680 recv_ctx = &adapter->recv_ctx[ctxid];
681 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
682 rcv_desc = &recv_ctx->rcv_desc[ring];
683 for (i = 0; i < rcv_desc->max_rx_desc_count; ++i) {
684 buffer = &(rcv_desc->rx_buf_arr[i]);
685 if (buffer->state == NETXEN_BUFFER_FREE)
686 continue;
687 pci_unmap_single(pdev, buffer->dma,
688 rcv_desc->dma_size,
689 PCI_DMA_FROMDEVICE);
690 if (buffer->skb != NULL)
691 dev_kfree_skb_any(buffer->skb);
692 }
693 vfree(rcv_desc->rx_buf_arr);
694 }
695 }
696
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -0700697 unregister_netdev(netdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700698
699 vfree(adapter->cmd_buf_arr);
700
701 iounmap(adapter->ahw.db_base);
702 iounmap(adapter->ahw.pci_base0);
703 iounmap(adapter->ahw.pci_base1);
704 iounmap(adapter->ahw.pci_base2);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -0700705
706 pci_release_regions(pdev);
707 pci_disable_device(pdev);
708 pci_set_drvdata(pdev, NULL);
709
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700710 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400711}
712
713/*
714 * Called when a network interface is made active
715 * @returns 0 on success, negative value on failure
716 */
717static int netxen_nic_open(struct net_device *netdev)
718{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700719 struct netxen_adapter *adapter = (struct netxen_adapter *)netdev->priv;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400720 int err = 0;
721 int ctx, ring;
722
723 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) {
724 err = netxen_init_firmware(adapter);
725 if (err != 0) {
726 printk(KERN_ERR "Failed to init firmware\n");
727 return -EIO;
728 }
729 netxen_nic_flash_print(adapter);
730
731 /* setup all the resources for the Phantom... */
732 /* this include the descriptors for rcv, tx, and status */
733 netxen_nic_clear_stats(adapter);
734 err = netxen_nic_hw_resources(adapter);
735 if (err) {
736 printk(KERN_ERR "Error in setting hw resources:%d\n",
737 err);
738 return err;
739 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400740 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800741 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400742 netxen_post_rx_buffers(adapter, ctx, ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400743 }
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800744 adapter->irq = adapter->ahw.pdev->irq;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700745 err = request_irq(adapter->ahw.pdev->irq, netxen_intr,
Andrew Morton1c8e0392007-05-10 22:53:00 -0700746 IRQF_SHARED|IRQF_SAMPLE_RANDOM, netdev->name,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700747 adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400748 if (err) {
749 printk(KERN_ERR "request_irq failed with: %d\n", err);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800750 netxen_free_hw_resources(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400751 return err;
752 }
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800753
754 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
755 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700756 if (!adapter->driver_mismatch)
757 mod_timer(&adapter->watchdog_timer, jiffies);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400758
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700759 netxen_nic_enable_int(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400760
761 /* Done here again so that even if phantom sw overwrote it,
762 * we set it */
Amit S. Kale80922fb2006-12-04 09:18:00 -0800763 if (adapter->macaddr_set)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700764 adapter->macaddr_set(adapter, netdev->dev_addr);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -0700765 if (adapter->init_port
766 && adapter->init_port(adapter, adapter->portnum) != 0) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700767 del_timer_sync(&adapter->watchdog_timer);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -0700768 printk(KERN_ERR "%s: Failed to initialize port %d\n",
769 netxen_nic_driver_name, adapter->portnum);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -0700770 return -EIO;
771 }
772
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700773 netxen_nic_set_link_parameters(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400774
775 netxen_nic_set_multi(netdev);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800776 if (adapter->set_mtu)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700777 adapter->set_mtu(adapter, netdev->mtu);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800778
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400779 if (!adapter->driver_mismatch)
780 netif_start_queue(netdev);
781
782 return 0;
783}
784
785/*
786 * netxen_nic_close - Disables a network interface entry point
787 */
788static int netxen_nic_close(struct net_device *netdev)
789{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700790 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400791 int i, j;
792 struct netxen_cmd_buffer *cmd_buff;
793 struct netxen_skb_frag *buffrag;
794
795 netif_carrier_off(netdev);
796 netif_stop_queue(netdev);
797
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700798 cmd_buff = adapter->cmd_buf_arr;
799 for (i = 0; i < adapter->max_tx_desc_count; i++) {
800 buffrag = cmd_buff->frag_array;
801 if (buffrag->dma) {
802 pci_unmap_single(adapter->pdev, buffrag->dma,
803 buffrag->length, PCI_DMA_TODEVICE);
804 buffrag->dma = (u64) NULL;
805 }
806 for (j = 0; j < cmd_buff->frag_count; j++) {
807 buffrag++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400808 if (buffrag->dma) {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700809 pci_unmap_page(adapter->pdev, buffrag->dma,
810 buffrag->length,
811 PCI_DMA_TODEVICE);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400812 buffrag->dma = (u64) NULL;
813 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400814 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700815 /* Free the skb we received in netxen_nic_xmit_frame */
816 if (cmd_buff->skb) {
817 dev_kfree_skb_any(cmd_buff->skb);
818 cmd_buff->skb = NULL;
819 }
820 cmd_buff++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400821 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700822 FLUSH_SCHEDULED_WORK();
823 del_timer_sync(&adapter->watchdog_timer);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400824
825 return 0;
826}
827
828static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
829{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700830 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400831 struct netxen_hardware_context *hw = &adapter->ahw;
832 unsigned int first_seg_len = skb->len - skb->data_len;
833 struct netxen_skb_frag *buffrag;
834 unsigned int i;
835
836 u32 producer = 0;
837 u32 saved_producer = 0;
838 struct cmd_desc_type0 *hwdesc;
839 int k;
840 struct netxen_cmd_buffer *pbuf = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400841 static int dropped_packet = 0;
842 int frag_count;
843 u32 local_producer = 0;
844 u32 max_tx_desc_count = 0;
845 u32 last_cmd_consumer = 0;
846 int no_of_desc;
847
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700848 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400849 frag_count = skb_shinfo(skb)->nr_frags + 1;
850
851 if (unlikely(skb->len <= 0)) {
852 dev_kfree_skb_any(skb);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700853 adapter->stats.badskblen++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400854 return NETDEV_TX_OK;
855 }
856
857 if (frag_count > MAX_BUFFERS_PER_CMD) {
858 printk("%s: %s netxen_nic_xmit_frame: frag_count (%d)"
859 "too large, can handle only %d frags\n",
860 netxen_nic_driver_name, netdev->name,
861 frag_count, MAX_BUFFERS_PER_CMD);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700862 adapter->stats.txdropped++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400863 if ((++dropped_packet & 0xff) == 0xff)
864 printk("%s: %s droppped packets = %d\n",
865 netxen_nic_driver_name, netdev->name,
866 dropped_packet);
867
868 return NETDEV_TX_OK;
869 }
870
871 /*
872 * Everything is set up. Now, we just need to transmit it out.
873 * Note that we have to copy the contents of buffer over to
874 * right place. Later on, this can be optimized out by de-coupling the
875 * producer index from the buffer index.
876 */
877 retry_getting_window:
878 spin_lock_bh(&adapter->tx_lock);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700879 if (adapter->total_threads >= MAX_XMIT_PRODUCERS) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400880 spin_unlock_bh(&adapter->tx_lock);
881 /*
882 * Yield CPU
883 */
884 if (!in_atomic())
885 schedule();
886 else {
887 for (i = 0; i < 20; i++)
888 cpu_relax(); /*This a nop instr on i386 */
889 }
890 goto retry_getting_window;
891 }
892 local_producer = adapter->cmd_producer;
893 /* There 4 fragments per descriptor */
894 no_of_desc = (frag_count + 3) >> 2;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800895 if (netdev->features & NETIF_F_TSO) {
896 if (skb_shinfo(skb)->gso_size > 0) {
897
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400898 no_of_desc++;
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -0700899 if ((ip_hdrlen(skb) + tcp_hdrlen(skb) +
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -0300900 sizeof(struct ethhdr)) >
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800901 (sizeof(struct cmd_desc_type0) - 2)) {
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800902 no_of_desc++;
903 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400904 }
905 }
906 k = adapter->cmd_producer;
907 max_tx_desc_count = adapter->max_tx_desc_count;
908 last_cmd_consumer = adapter->last_cmd_consumer;
909 if ((k + no_of_desc) >=
910 ((last_cmd_consumer <= k) ? last_cmd_consumer + max_tx_desc_count :
911 last_cmd_consumer)) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800912 netif_stop_queue(netdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700913 adapter->flags |= NETXEN_NETDEV_STATUS;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800914 spin_unlock_bh(&adapter->tx_lock);
915 return NETDEV_TX_BUSY;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400916 }
917 k = get_index_range(k, max_tx_desc_count, no_of_desc);
918 adapter->cmd_producer = k;
919 adapter->total_threads++;
920 adapter->num_threads++;
921
922 spin_unlock_bh(&adapter->tx_lock);
923 /* Copy the descriptors into the hardware */
924 producer = local_producer;
925 saved_producer = producer;
926 hwdesc = &hw->cmd_desc_head[producer];
927 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
928 /* Take skb->data itself */
929 pbuf = &adapter->cmd_buf_arr[producer];
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800930 if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) {
Al Viroa608ab9c2007-01-02 10:39:10 +0000931 pbuf->mss = skb_shinfo(skb)->gso_size;
Amit S. Kaleed33ebe2006-12-18 05:53:59 -0800932 hwdesc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400933 } else {
934 pbuf->mss = 0;
935 hwdesc->mss = 0;
936 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400937 pbuf->total_length = skb->len;
938 pbuf->skb = skb;
939 pbuf->cmd = TX_ETHER_PKT;
940 pbuf->frag_count = frag_count;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700941 pbuf->port = adapter->portnum;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400942 buffrag = &pbuf->frag_array[0];
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700943 buffrag->dma = pci_map_single(adapter->pdev, skb->data, first_seg_len,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400944 PCI_DMA_TODEVICE);
945 buffrag->length = first_seg_len;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800946 netxen_set_cmd_desc_totallength(hwdesc, skb->len);
947 netxen_set_cmd_desc_num_of_buff(hwdesc, frag_count);
948 netxen_set_cmd_desc_opcode(hwdesc, TX_ETHER_PKT);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400949
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700950 netxen_set_cmd_desc_port(hwdesc, adapter->portnum);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700951 netxen_set_cmd_desc_ctxid(hwdesc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400952 hwdesc->buffer1_length = cpu_to_le16(first_seg_len);
953 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
954
955 for (i = 1, k = 1; i < frag_count; i++, k++) {
956 struct skb_frag_struct *frag;
957 int len, temp_len;
958 unsigned long offset;
959 dma_addr_t temp_dma;
960
961 /* move to next desc. if there is a need */
962 if ((i & 0x3) == 0) {
963 k = 0;
964 producer = get_next_index(producer,
965 adapter->max_tx_desc_count);
966 hwdesc = &hw->cmd_desc_head[producer];
967 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
968 }
969 frag = &skb_shinfo(skb)->frags[i - 1];
970 len = frag->size;
971 offset = frag->page_offset;
972
973 temp_len = len;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700974 temp_dma = pci_map_page(adapter->pdev, frag->page, offset,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400975 len, PCI_DMA_TODEVICE);
976
977 buffrag++;
978 buffrag->dma = temp_dma;
979 buffrag->length = temp_len;
980
981 DPRINTK(INFO, "for loop. i=%d k=%d\n", i, k);
982 switch (k) {
983 case 0:
984 hwdesc->buffer1_length = cpu_to_le16(temp_len);
985 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
986 break;
987 case 1:
988 hwdesc->buffer2_length = cpu_to_le16(temp_len);
989 hwdesc->addr_buffer2 = cpu_to_le64(temp_dma);
990 break;
991 case 2:
992 hwdesc->buffer3_length = cpu_to_le16(temp_len);
993 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
994 break;
995 case 3:
Al Viroa608ab9c2007-01-02 10:39:10 +0000996 hwdesc->buffer4_length = cpu_to_le16(temp_len);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400997 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
998 break;
999 }
1000 frag++;
1001 }
1002 producer = get_next_index(producer, adapter->max_tx_desc_count);
1003
1004 /* might change opcode to TX_TCP_LSO */
1005 netxen_tso_check(adapter, &hw->cmd_desc_head[saved_producer], skb);
1006
1007 /* For LSO, we need to copy the MAC/IP/TCP headers into
1008 * the descriptor ring
1009 */
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001010 if (netxen_get_cmd_desc_opcode(&hw->cmd_desc_head[saved_producer])
1011 == TX_TCP_LSO) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001012 int hdr_len, first_hdr_len, more_hdr;
1013 hdr_len = hw->cmd_desc_head[saved_producer].total_hdr_length;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001014 if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) {
1015 first_hdr_len = sizeof(struct cmd_desc_type0) - 2;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001016 more_hdr = 1;
1017 } else {
1018 first_hdr_len = hdr_len;
1019 more_hdr = 0;
1020 }
1021 /* copy the MAC/IP/TCP headers to the cmd descriptor list */
1022 hwdesc = &hw->cmd_desc_head[producer];
1023
1024 /* copy the first 64 bytes */
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001025 memcpy(((void *)hwdesc) + 2,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001026 (void *)(skb->data), first_hdr_len);
1027 producer = get_next_index(producer, max_tx_desc_count);
1028
1029 if (more_hdr) {
1030 hwdesc = &hw->cmd_desc_head[producer];
1031 /* copy the next 64 bytes - should be enough except
1032 * for pathological case
1033 */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001034 skb_copy_from_linear_data_offset(skb, first_hdr_len,
1035 hwdesc,
1036 (hdr_len -
1037 first_hdr_len));
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001038 producer = get_next_index(producer, max_tx_desc_count);
1039 }
1040 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001041
1042 i = netxen_get_cmd_desc_totallength(&hw->cmd_desc_head[saved_producer]);
1043
1044 hw->cmd_desc_head[saved_producer].flags_opcode =
1045 cpu_to_le16(hw->cmd_desc_head[saved_producer].flags_opcode);
1046 hw->cmd_desc_head[saved_producer].num_of_buffers_total_length =
1047 cpu_to_le32(hw->cmd_desc_head[saved_producer].
1048 num_of_buffers_total_length);
1049
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001050 spin_lock_bh(&adapter->tx_lock);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001051 adapter->stats.txbytes += i;
1052
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001053 /* Code to update the adapter considering how many producer threads
1054 are currently working */
1055 if ((--adapter->num_threads) == 0) {
1056 /* This is the last thread */
1057 u32 crb_producer = adapter->cmd_producer;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001058 netxen_nic_update_cmd_producer(adapter, crb_producer);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001059 wmb();
1060 adapter->total_threads = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001061 }
1062
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001063 adapter->stats.xmitfinished++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001064 spin_unlock_bh(&adapter->tx_lock);
1065
1066 netdev->trans_start = jiffies;
1067
1068 DPRINTK(INFO, "wrote CMD producer %x to phantom\n", producer);
1069
1070 DPRINTK(INFO, "Done. Send\n");
1071 return NETDEV_TX_OK;
1072}
1073
1074static void netxen_watchdog(unsigned long v)
1075{
1076 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001077
1078 SCHEDULE_WORK(&adapter->watchdog_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001079}
1080
1081static void netxen_tx_timeout(struct net_device *netdev)
1082{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001083 struct netxen_adapter *adapter = (struct netxen_adapter *)
1084 netdev_priv(netdev);
1085 SCHEDULE_WORK(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001086}
1087
David Howells6d5aefb2006-12-05 19:36:26 +00001088static void netxen_tx_timeout_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001089{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001090 struct netxen_adapter *adapter =
1091 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001092 unsigned long flags;
1093
1094 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001095 netxen_nic_driver_name, adapter->netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001096
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001097 spin_lock_irqsave(&adapter->lock, flags);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001098 netxen_nic_close(adapter->netdev);
1099 netxen_nic_open(adapter->netdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001100 spin_unlock_irqrestore(&adapter->lock, flags);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001101 adapter->netdev->trans_start = jiffies;
1102 netif_wake_queue(adapter->netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001103}
1104
1105static int
1106netxen_handle_int(struct netxen_adapter *adapter, struct net_device *netdev)
1107{
1108 u32 ret = 0;
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +05301109 u32 our_int = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001110
1111 DPRINTK(INFO, "Entered handle ISR\n");
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001112 adapter->stats.ints++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001113
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001114 if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001115 our_int = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR));
1116 /* not our interrupt */
1117 if ((our_int & (0x80 << adapter->portnum)) == 0)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001118 return ret;
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +05301119 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001120
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +05301121 netxen_nic_disable_int(adapter);
1122
1123 if (adapter->intr_scheme == INTR_SCHEME_PERPORT) {
1124 /* claim interrupt */
1125 if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) {
1126 writel(our_int & ~((u32)(0x80 << adapter->portnum)),
1127 NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR));
1128 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001129 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001130
1131 if (netxen_nic_rx_has_work(adapter) || netxen_nic_tx_has_work(adapter)) {
1132 if (netif_rx_schedule_prep(netdev)) {
1133 /*
1134 * Interrupts are already disabled.
1135 */
1136 __netif_rx_schedule(netdev);
1137 } else {
1138 static unsigned int intcount = 0;
1139 if ((++intcount & 0xfff) == 0xfff)
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +05301140 DPRINTK(KERN_ERR
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001141 "%s: %s interrupt %d while in poll\n",
1142 netxen_nic_driver_name, netdev->name,
1143 intcount);
1144 }
1145 ret = 1;
1146 }
1147
1148 if (ret == 0) {
1149 netxen_nic_enable_int(adapter);
1150 }
1151
1152 return ret;
1153}
1154
1155/*
1156 * netxen_intr - Interrupt Handler
1157 * @irq: interrupt number
1158 * data points to adapter stucture (which may be handling more than 1 port
1159 */
Jeff Garzik1494a812006-11-07 05:12:16 -05001160irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001161{
1162 struct netxen_adapter *adapter;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001163 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001164
1165 if (unlikely(!irq)) {
1166 return IRQ_NONE; /* Not our interrupt */
1167 }
1168
1169 adapter = (struct netxen_adapter *)data;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001170 netdev = adapter->netdev;
1171 /* process our status queue (for all 4 ports) */
1172 if (netif_running(netdev))
1173 netxen_handle_int(adapter, netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001174
1175 return IRQ_HANDLED;
1176}
1177
1178static int netxen_nic_poll(struct net_device *netdev, int *budget)
1179{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001180 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001181 int work_to_do = min(*budget, netdev->quota);
1182 int done = 1;
1183 int ctx;
1184 int this_work_done;
Amit S. Kale80922fb2006-12-04 09:18:00 -08001185 int work_done = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001186
1187 DPRINTK(INFO, "polling for %d descriptors\n", *budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001188
Amit S. Kale80922fb2006-12-04 09:18:00 -08001189 work_done = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001190 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
1191 /*
1192 * Fairness issue. This will give undue weight to the
1193 * receive context 0.
1194 */
1195
1196 /*
1197 * To avoid starvation, we give each of our receivers,
1198 * a fraction of the quota. Sometimes, it might happen that we
1199 * have enough quota to process every packet, but since all the
1200 * packets are on one context, it gets only half of the quota,
1201 * and ends up not processing it.
1202 */
1203 this_work_done = netxen_process_rcv_ring(adapter, ctx,
1204 work_to_do /
1205 MAX_RCV_CTX);
Amit S. Kale80922fb2006-12-04 09:18:00 -08001206 work_done += this_work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001207 }
1208
Amit S. Kale80922fb2006-12-04 09:18:00 -08001209 netdev->quota -= work_done;
1210 *budget -= work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001211
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001212 if (work_done >= work_to_do && netxen_nic_rx_has_work(adapter) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001213 done = 0;
1214
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001215 if (netxen_process_cmd_ring((unsigned long)adapter) == 0)
1216 done = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001217
1218 DPRINTK(INFO, "new work_done: %d work_to_do: %d\n",
Amit S. Kale80922fb2006-12-04 09:18:00 -08001219 work_done, work_to_do);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001220 if (done) {
1221 netif_rx_complete(netdev);
1222 netxen_nic_enable_int(adapter);
1223 }
1224
Amit S. Kaleedf90162006-11-29 08:58:11 -08001225 return !done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001226}
1227
1228#ifdef CONFIG_NET_POLL_CONTROLLER
1229static void netxen_nic_poll_controller(struct net_device *netdev)
1230{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001231 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001232 disable_irq(adapter->irq);
Jeff Garzik1494a812006-11-07 05:12:16 -05001233 netxen_intr(adapter->irq, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001234 enable_irq(adapter->irq);
1235}
1236#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001237
1238static struct pci_driver netxen_driver = {
1239 .name = netxen_nic_driver_name,
1240 .id_table = netxen_pci_tbl,
1241 .probe = netxen_nic_probe,
1242 .remove = __devexit_p(netxen_nic_remove)
1243};
1244
1245/* Driver Registration on NetXen card */
1246
1247static int __init netxen_init_module(void)
1248{
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001249 if ((netxen_workq = create_singlethread_workqueue("netxen")) == 0)
1250 return -ENOMEM;
1251
Amit S. Kale184231b2007-01-22 06:52:53 -08001252 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001253}
1254
1255module_init(netxen_init_module);
1256
1257static void __exit netxen_exit_module(void)
1258{
1259 /*
1260 * Wait for some time to allow the dma to drain, if any.
1261 */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001262 pci_unregister_driver(&netxen_driver);
Amit S. Kale9de06612007-02-21 06:37:06 -08001263 destroy_workqueue(netxen_workq);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001264}
1265
1266module_exit(netxen_exit_module);