blob: 4fe20ecdbc6b075194d3f15aa50d8a904883c920 [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>
Dhananjay Phadke391587c2009-01-14 20:48:11 -080042#include <linux/if_vlan.h>
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030043#include <net/ip.h>
Dhananjay Phadke00977782009-01-16 11:03:25 -080044#include <linux/ipv6.h>
Jeff Garzik1494a812006-11-07 05:12:16 -050045
Amit S. Kale3d396eb2006-10-21 15:33:03 -040046MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
47MODULE_LICENSE("GPL");
48MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
49
dhananjay@netxen.comceded322007-07-19 14:41:09 +053050char netxen_nic_driver_name[] = "netxen_nic";
Amit S. Kale3d396eb2006-10-21 15:33:03 -040051static char netxen_nic_driver_string[] = "NetXen Network Driver version "
Amit S. Kalecb8011a2006-11-29 09:00:10 -080052 NETXEN_NIC_LINUX_VERSIONID;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040053
Dhananjay Phadke29566402008-07-21 19:44:04 -070054static int port_mode = NETXEN_PORT_MODE_AUTO_NEG;
55
56/* Default to restricted 1G auto-neg mode */
57static int wol_port_mode = 5;
58
59static int use_msi = 1;
60
61static int use_msi_x = 1;
62
Amit S. Kale3d396eb2006-10-21 15:33:03 -040063/* Local functions to NetXen NIC driver */
64static int __devinit netxen_nic_probe(struct pci_dev *pdev,
Dhananjay Phadke29566402008-07-21 19:44:04 -070065 const struct pci_device_id *ent);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040066static void __devexit netxen_nic_remove(struct pci_dev *pdev);
67static int netxen_nic_open(struct net_device *netdev);
68static int netxen_nic_close(struct net_device *netdev);
69static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *);
70static void netxen_tx_timeout(struct net_device *netdev);
David Howells6d5aefb2006-12-05 19:36:26 +000071static void netxen_tx_timeout_task(struct work_struct *work);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040072static void netxen_watchdog(unsigned long);
Stephen Hemmingerbea33482007-10-03 16:41:36 -070073static int netxen_nic_poll(struct napi_struct *napi, int budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040074#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);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -070078static irqreturn_t netxen_msi_intr(int irq, void *data);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -080079static irqreturn_t netxen_msix_intr(int irq, void *data);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040080
81/* PCI Device ID Table */
Al Viro70081ac2008-06-23 02:04:50 +010082#define ENTRY(device) \
Dhananjay Phadke040dec32008-09-12 06:55:14 -070083 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
Al Viro70081ac2008-06-23 02:04:50 +010084 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
85
Amit S. Kale3d396eb2006-10-21 15:33:03 -040086static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
Dhananjay Phadke040dec32008-09-12 06:55:14 -070087 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR),
88 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4),
89 ENTRY(PCI_DEVICE_ID_NX2031_4GCU),
90 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ),
91 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ),
92 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT),
93 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2),
94 ENTRY(PCI_DEVICE_ID_NX3031),
Amit S. Kale3d396eb2006-10-21 15:33:03 -040095 {0,}
96};
97
98MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
99
Adrian Bunkb15551302008-03-31 02:22:18 +0300100/*
101 * In netxen_nic_down(), we must wait for any pending callback requests into
102 * netxen_watchdog_task() to complete; eg otherwise the watchdog_timer could be
103 * reenabled right after it is deleted in netxen_nic_down().
104 * FLUSH_SCHEDULED_WORK() does this synchronization.
105 *
106 * Normally, schedule_work()/flush_scheduled_work() could have worked, but
107 * netxen_nic_close() is invoked with kernel rtnl lock held. netif_carrier_off()
108 * call in netxen_nic_close() triggers a schedule_work(&linkwatch_work), and a
109 * subsequent call to flush_scheduled_work() in netxen_nic_down() would cause
110 * linkwatch_event() to be executed which also attempts to acquire the rtnl
111 * lock thus causing a deadlock.
112 */
113
114static struct workqueue_struct *netxen_workq;
115#define SCHEDULE_WORK(tp) queue_work(netxen_workq, tp)
116#define FLUSH_SCHEDULED_WORK() flush_workqueue(netxen_workq)
117
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800118static void netxen_watchdog(unsigned long);
119
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700120static uint32_t crb_cmd_producer[4] = {
121 CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1,
122 CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3
123};
124
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700125void
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700126netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
127 uint32_t crb_producer)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700128{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700129 adapter->pci_write_normalize(adapter,
130 adapter->crb_addr_cmd_producer, crb_producer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700131}
132
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700133static uint32_t crb_cmd_consumer[4] = {
134 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
135 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
136};
137
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700138static inline void
139netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
140 u32 crb_consumer)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700141{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700142 adapter->pci_write_normalize(adapter,
143 adapter->crb_addr_cmd_consumer, crb_consumer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700144}
145
Dhananjay Phadke29566402008-07-21 19:44:04 -0700146static uint32_t msi_tgt_status[8] = {
Dhananjay Phadke443be792008-03-17 19:59:48 -0700147 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700148 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
149 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
150 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
Dhananjay Phadke443be792008-03-17 19:59:48 -0700151};
152
Dhananjay Phadke29566402008-07-21 19:44:04 -0700153static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
154
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700155static inline void netxen_nic_disable_int(struct netxen_adapter *adapter)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700156{
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700157 adapter->pci_write_normalize(adapter, adapter->crb_intr_mask, 0);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700158}
159
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700160static inline void netxen_nic_enable_int(struct netxen_adapter *adapter)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700161{
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700162 adapter->pci_write_normalize(adapter, adapter->crb_intr_mask, 0x1);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700163
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700164 if (!NETXEN_IS_MSI_FAMILY(adapter))
165 adapter->pci_write_immediate(adapter,
166 adapter->legacy_intr.tgt_mask_reg, 0xfbff);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700167}
168
Dhananjay Phadke29566402008-07-21 19:44:04 -0700169static int nx_set_dma_mask(struct netxen_adapter *adapter, uint8_t revision_id)
170{
171 struct pci_dev *pdev = adapter->pdev;
172 int err;
173 uint64_t mask;
174
175#ifdef CONFIG_IA64
176 adapter->dma_mask = DMA_32BIT_MASK;
177#else
178 if (revision_id >= NX_P3_B0) {
179 /* should go to DMA_64BIT_MASK */
180 adapter->dma_mask = DMA_39BIT_MASK;
181 mask = DMA_39BIT_MASK;
182 } else if (revision_id == NX_P3_A2) {
183 adapter->dma_mask = DMA_39BIT_MASK;
184 mask = DMA_39BIT_MASK;
185 } else if (revision_id == NX_P2_C1) {
186 adapter->dma_mask = DMA_35BIT_MASK;
187 mask = DMA_35BIT_MASK;
188 } else {
189 adapter->dma_mask = DMA_32BIT_MASK;
190 mask = DMA_32BIT_MASK;
191 goto set_32_bit_mask;
192 }
193
194 /*
195 * Consistent DMA mask is set to 32 bit because it cannot be set to
196 * 35 bits. For P3 also leave it at 32 bits for now. Only the rings
197 * come off this pool.
198 */
199 if (pci_set_dma_mask(pdev, mask) == 0 &&
200 pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK) == 0) {
201 adapter->pci_using_dac = 1;
202 return 0;
203 }
Yang Hongyang354b45f2009-02-12 16:57:12 -0800204set_32_bit_mask:
Dhananjay Phadke29566402008-07-21 19:44:04 -0700205#endif /* CONFIG_IA64 */
206
Dhananjay Phadke29566402008-07-21 19:44:04 -0700207 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
208 if (!err)
209 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
210 if (err) {
211 DPRINTK(ERR, "No usable DMA configuration, aborting:%d\n", err);
212 return err;
213 }
214
215 adapter->pci_using_dac = 0;
216 return 0;
217}
218
219static void netxen_check_options(struct netxen_adapter *adapter)
220{
221 switch (adapter->ahw.boardcfg.board_type) {
222 case NETXEN_BRDTYPE_P3_HMEZ:
223 case NETXEN_BRDTYPE_P3_XG_LOM:
224 case NETXEN_BRDTYPE_P3_10G_CX4:
225 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
226 case NETXEN_BRDTYPE_P3_IMEZ:
227 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
Dhananjay Phadkea70f9392008-08-01 03:14:56 -0700228 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
229 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
Dhananjay Phadke29566402008-07-21 19:44:04 -0700230 case NETXEN_BRDTYPE_P3_10G_XFP:
231 case NETXEN_BRDTYPE_P3_10000_BASE_T:
232 adapter->msix_supported = !!use_msi_x;
233 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
234 break;
235
236 case NETXEN_BRDTYPE_P2_SB31_10G:
237 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
238 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
239 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
240 adapter->msix_supported = 0;
241 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
242 break;
243
244 case NETXEN_BRDTYPE_P3_REF_QG:
245 case NETXEN_BRDTYPE_P3_4_GB:
246 case NETXEN_BRDTYPE_P3_4_GB_MM:
Dhananjay Phadkeec68db62008-08-20 13:52:48 -0700247 adapter->msix_supported = !!use_msi_x;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800248 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
Dhananjay Phadkea70f9392008-08-01 03:14:56 -0700249 break;
250
Dhananjay Phadke29566402008-07-21 19:44:04 -0700251 case NETXEN_BRDTYPE_P2_SB35_4G:
252 case NETXEN_BRDTYPE_P2_SB31_2G:
253 adapter->msix_supported = 0;
254 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
255 break;
256
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800257 case NETXEN_BRDTYPE_P3_10G_TP:
258 adapter->msix_supported = !!use_msi_x;
259 if (adapter->ahw.board_type == NETXEN_NIC_XGBE)
260 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
261 else
262 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
263 break;
264
Dhananjay Phadke29566402008-07-21 19:44:04 -0700265 default:
266 adapter->msix_supported = 0;
267 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
268
269 printk(KERN_WARNING "Unknown board type(0x%x)\n",
270 adapter->ahw.boardcfg.board_type);
271 break;
272 }
273
274 adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS_HOST;
275 adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS;
276 adapter->max_lro_rx_desc_count = MAX_LRO_RCV_DESCRIPTORS;
277
278 adapter->max_possible_rss_rings = 1;
279 return;
280}
281
282static int
283netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
284{
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800285 u32 val, timeout;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700286
287 if (first_boot == 0x55555555) {
288 /* This is the first boot after power up */
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800289 adapter->pci_write_normalize(adapter,
290 NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
291
292 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
293 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700294
295 /* PCI bus master workaround */
296 adapter->hw_read_wx(adapter,
297 NETXEN_PCIE_REG(0x4), &first_boot, 4);
298 if (!(first_boot & 0x4)) {
299 first_boot |= 0x4;
300 adapter->hw_write_wx(adapter,
301 NETXEN_PCIE_REG(0x4), &first_boot, 4);
302 adapter->hw_read_wx(adapter,
303 NETXEN_PCIE_REG(0x4), &first_boot, 4);
304 }
305
306 /* This is the first boot after power up */
307 adapter->hw_read_wx(adapter,
308 NETXEN_ROMUSB_GLB_SW_RESET, &first_boot, 4);
309 if (first_boot != 0x80000f) {
310 /* clear the register for future unloads/loads */
311 adapter->pci_write_normalize(adapter,
312 NETXEN_CAM_RAM(0x1fc), 0);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800313 return -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700314 }
315
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800316 /* Start P2 boot loader */
317 val = adapter->pci_read_normalize(adapter,
318 NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
319 adapter->pci_write_normalize(adapter,
320 NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
321 timeout = 0;
322 do {
323 msleep(1);
324 val = adapter->pci_read_normalize(adapter,
325 NETXEN_CAM_RAM(0x1fc));
326
327 if (++timeout > 5000)
328 return -EIO;
329
330 } while (val == NETXEN_BDINFO_MAGIC);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700331 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800332 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700333}
334
335static void netxen_set_port_mode(struct netxen_adapter *adapter)
336{
337 u32 val, data;
338
339 val = adapter->ahw.boardcfg.board_type;
340 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
341 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
342 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
343 data = NETXEN_PORT_MODE_802_3_AP;
344 adapter->hw_write_wx(adapter,
345 NETXEN_PORT_MODE_ADDR, &data, 4);
346 } else if (port_mode == NETXEN_PORT_MODE_XG) {
347 data = NETXEN_PORT_MODE_XG;
348 adapter->hw_write_wx(adapter,
349 NETXEN_PORT_MODE_ADDR, &data, 4);
350 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
351 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
352 adapter->hw_write_wx(adapter,
353 NETXEN_PORT_MODE_ADDR, &data, 4);
354 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
355 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
356 adapter->hw_write_wx(adapter,
357 NETXEN_PORT_MODE_ADDR, &data, 4);
358 } else {
359 data = NETXEN_PORT_MODE_AUTO_NEG;
360 adapter->hw_write_wx(adapter,
361 NETXEN_PORT_MODE_ADDR, &data, 4);
362 }
363
364 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
365 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
366 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
367 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
368 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
369 }
370 adapter->hw_write_wx(adapter, NETXEN_WOL_PORT_MODE,
371 &wol_port_mode, 4);
372 }
373}
374
Dhananjay Phadke29566402008-07-21 19:44:04 -0700375static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
376{
377 u32 control;
378 int pos;
379
380 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
381 if (pos) {
382 pci_read_config_dword(pdev, pos, &control);
383 if (enable)
384 control |= PCI_MSIX_FLAGS_ENABLE;
385 else
386 control = 0;
387 pci_write_config_dword(pdev, pos, control);
388 }
389}
390
391static void netxen_init_msix_entries(struct netxen_adapter *adapter)
392{
393 int i;
394
395 for (i = 0; i < MSIX_ENTRIES_PER_ADAPTER; i++)
396 adapter->msix_entries[i].entry = i;
397}
398
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700399static int
400netxen_read_mac_addr(struct netxen_adapter *adapter)
401{
402 int i;
403 unsigned char *p;
404 __le64 mac_addr;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700405 struct net_device *netdev = adapter->netdev;
406 struct pci_dev *pdev = adapter->pdev;
407
408 if (netxen_is_flash_supported(adapter) != 0)
409 return -EIO;
410
411 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
412 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
413 return -EIO;
414 } else {
415 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
416 return -EIO;
417 }
418
419 p = (unsigned char *)&mac_addr;
420 for (i = 0; i < 6; i++)
421 netdev->dev_addr[i] = *(p + 5 - i);
422
423 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
424
425 /* set station address */
426
Johannes Berge1749612008-10-27 15:59:26 -0700427 if (!is_valid_ether_addr(netdev->perm_addr))
428 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
429 else
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700430 adapter->macaddr_set(adapter, netdev->dev_addr);
431
432 return 0;
433}
434
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800435static void netxen_set_multicast_list(struct net_device *dev)
436{
437 struct netxen_adapter *adapter = netdev_priv(dev);
438
439 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
440 netxen_p3_nic_set_multi(dev);
441 else
442 netxen_p2_nic_set_multi(dev);
443}
444
445static const struct net_device_ops netxen_netdev_ops = {
446 .ndo_open = netxen_nic_open,
447 .ndo_stop = netxen_nic_close,
448 .ndo_start_xmit = netxen_nic_xmit_frame,
449 .ndo_get_stats = netxen_nic_get_stats,
450 .ndo_validate_addr = eth_validate_addr,
451 .ndo_set_multicast_list = netxen_set_multicast_list,
452 .ndo_set_mac_address = netxen_nic_set_mac,
453 .ndo_change_mtu = netxen_nic_change_mtu,
454 .ndo_tx_timeout = netxen_tx_timeout,
455#ifdef CONFIG_NET_POLL_CONTROLLER
456 .ndo_poll_controller = netxen_nic_poll_controller,
457#endif
458};
459
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400460/*
461 * netxen_nic_probe()
462 *
463 * The Linux system will invoke this after identifying the vendor ID and
464 * device Id in the pci_tbl supported by this module.
465 *
466 * A quad port card has one operational PCI config space, (function 0),
467 * which is used to access all four ports.
468 *
469 * This routine will initialize the adapter, and setup the global parameters
470 * along with the port's specific structure.
471 */
472static int __devinit
473netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
474{
475 struct net_device *netdev = NULL;
476 struct netxen_adapter *adapter = NULL;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800477 void __iomem *mem_ptr0 = NULL;
478 void __iomem *mem_ptr1 = NULL;
479 void __iomem *mem_ptr2 = NULL;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700480 unsigned long first_page_group_end;
481 unsigned long first_page_group_start;
482
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800483
Al Viroa608ab9c2007-01-02 10:39:10 +0000484 u8 __iomem *db_ptr = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700485 unsigned long mem_base, mem_len, db_base, db_len, pci_len0 = 0;
486 int i = 0, err;
487 int first_driver, first_boot;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700488 u32 val;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700489 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700490 struct netxen_legacy_intr_set *legacy_intrp;
491 uint8_t revision_id;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400492
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700493 if (pci_func_id == 0)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700494 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700495
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700496 if (pdev->class != 0x020000) {
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700497 printk(KERN_DEBUG "NetXen function %d, class %x will not "
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700498 "be enabled.\n",pci_func_id, pdev->class);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800499 return -ENODEV;
500 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700501
Dhananjay Phadke11d89d62008-08-08 00:08:45 -0700502 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
503 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
504 "will not be enabled.\n",
505 NX_P3_A0, NX_P3_B1);
506 return -ENODEV;
507 }
508
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400509 if ((err = pci_enable_device(pdev)))
510 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700511
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400512 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
513 err = -ENODEV;
514 goto err_out_disable_pdev;
515 }
516
517 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
518 goto err_out_disable_pdev;
519
520 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700521
522 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
523 if(!netdev) {
524 printk(KERN_ERR"%s: Failed to allocate memory for the "
525 "device block.Check system memory resource"
526 " usage.\n", netxen_nic_driver_name);
527 goto err_out_free_res;
528 }
529
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700530 SET_NETDEV_DEV(netdev, &pdev->dev);
531
Wang Chen4cf16532008-11-12 23:38:14 -0800532 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700533 adapter->netdev = netdev;
534 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700535 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700536
537 revision_id = pdev->revision;
538 adapter->ahw.revision_id = revision_id;
539
540 err = nx_set_dma_mask(adapter, revision_id);
541 if (err)
542 goto err_out_free_netdev;
543
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700544 rwlock_init(&adapter->adapter_lock);
545 adapter->ahw.qdr_sn_window = -1;
546 adapter->ahw.ddr_mn_window = -1;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700547
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400548 /* remap phys address */
549 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
550 mem_len = pci_resource_len(pdev, 0);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700551 pci_len0 = 0;
552
553 adapter->hw_write_wx = netxen_nic_hw_write_wx_128M;
554 adapter->hw_read_wx = netxen_nic_hw_read_wx_128M;
555 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_128M;
556 adapter->pci_write_immediate = netxen_nic_pci_write_immediate_128M;
557 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_128M;
558 adapter->pci_write_normalize = netxen_nic_pci_write_normalize_128M;
559 adapter->pci_set_window = netxen_nic_pci_set_window_128M;
560 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M;
561 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400562
563 /* 128 Meg of memory */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700564 if (mem_len == NETXEN_PCI_128MB_SIZE) {
565 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
566 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
567 SECOND_PAGE_GROUP_SIZE);
568 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
569 THIRD_PAGE_GROUP_SIZE);
570 first_page_group_start = FIRST_PAGE_GROUP_START;
571 first_page_group_end = FIRST_PAGE_GROUP_END;
572 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
573 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
574 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
575 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
576 first_page_group_start = 0;
577 first_page_group_end = 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700578 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
579 adapter->hw_write_wx = netxen_nic_hw_write_wx_2M;
580 adapter->hw_read_wx = netxen_nic_hw_read_wx_2M;
581 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_2M;
582 adapter->pci_write_immediate =
583 netxen_nic_pci_write_immediate_2M;
584 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_2M;
585 adapter->pci_write_normalize =
586 netxen_nic_pci_write_normalize_2M;
587 adapter->pci_set_window = netxen_nic_pci_set_window_2M;
588 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M;
589 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M;
590
591 mem_ptr0 = ioremap(mem_base, mem_len);
592 pci_len0 = mem_len;
593 first_page_group_start = 0;
594 first_page_group_end = 0;
595
596 adapter->ahw.ddr_mn_window = 0;
597 adapter->ahw.qdr_sn_window = 0;
598
599 adapter->ahw.mn_win_crb = 0x100000 + PCIX_MN_WINDOW +
600 (pci_func_id * 0x20);
601 adapter->ahw.ms_win_crb = 0x100000 + PCIX_SN_WINDOW;
602 if (pci_func_id < 4)
603 adapter->ahw.ms_win_crb += (pci_func_id * 0x20);
604 else
605 adapter->ahw.ms_win_crb +=
606 0xA0 + ((pci_func_id - 4) * 0x10);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700607 } else {
Jeff Garzik47906542007-11-23 21:23:36 -0500608 err = -EIO;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700609 goto err_out_free_netdev;
610 }
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800611
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700612 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800613
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800614 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
615 db_len = pci_resource_len(pdev, 4);
616
617 if (db_len == 0) {
618 printk(KERN_ERR "%s: doorbell is disabled\n",
Dhananjay Phadke29566402008-07-21 19:44:04 -0700619 netxen_nic_driver_name);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800620 err = -EIO;
621 goto err_out_iounmap;
622 }
623 DPRINTK(INFO, "doorbell ioremap from %lx a size of %lx\n", db_base,
624 db_len);
625
626 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
Al Viroa608ab9c2007-01-02 10:39:10 +0000627 if (!db_ptr) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800628 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
Dhananjay Phadke29566402008-07-21 19:44:04 -0700629 netxen_nic_driver_name);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800630 err = -EIO;
631 goto err_out_iounmap;
632 }
633 DPRINTK(INFO, "doorbell ioremaped at %p\n", db_ptr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400634
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700635 adapter->ahw.pci_base0 = mem_ptr0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700636 adapter->ahw.pci_len0 = pci_len0;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700637 adapter->ahw.first_page_group_start = first_page_group_start;
638 adapter->ahw.first_page_group_end = first_page_group_end;
639 adapter->ahw.pci_base1 = mem_ptr1;
640 adapter->ahw.pci_base2 = mem_ptr2;
641 adapter->ahw.db_base = db_ptr;
642 adapter->ahw.db_len = db_len;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400643
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700644 netif_napi_add(netdev, &adapter->napi,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700645 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
646
647 if (revision_id >= NX_P3_B0)
648 legacy_intrp = &legacy_intr[pci_func_id];
649 else
650 legacy_intrp = &legacy_intr[0];
651
652 adapter->legacy_intr.int_vec_bit = legacy_intrp->int_vec_bit;
653 adapter->legacy_intr.tgt_status_reg = legacy_intrp->tgt_status_reg;
654 adapter->legacy_intr.tgt_mask_reg = legacy_intrp->tgt_mask_reg;
655 adapter->legacy_intr.pci_int_reg = legacy_intrp->pci_int_reg;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700656
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +0530657 /* this will be read from FW later */
658 adapter->intr_scheme = -1;
Dhananjay Phadke443be792008-03-17 19:59:48 -0700659 adapter->msi_mode = -1;
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +0530660
661 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700662 adapter->portnum = pci_func_id;
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +0530663 adapter->status &= ~NETXEN_NETDEV_STATUS;
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530664 adapter->rx_csum = 1;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700665 adapter->mc_enabled = 0;
Dhananjay Phadke83821a02008-08-01 03:14:58 -0700666 if (NX_IS_REVISION_P3(revision_id))
Dhananjay Phadke29566402008-07-21 19:44:04 -0700667 adapter->max_mc_count = 38;
Dhananjay Phadke83821a02008-08-01 03:14:58 -0700668 else
Dhananjay Phadke29566402008-07-21 19:44:04 -0700669 adapter->max_mc_count = 16;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700670
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800671 netdev->netdev_ops = &netxen_netdev_ops;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -0700672 netdev->watchdog_timeo = 2*HZ;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700673
674 netxen_nic_change_mtu(netdev, netdev->mtu);
675
676 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800677
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800678 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
679 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
680
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700681 if (NX_IS_REVISION_P3(revision_id)) {
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800682 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
683 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700684 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700685
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800686 if (adapter->pci_using_dac) {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700687 netdev->features |= NETIF_F_HIGHDMA;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800688 netdev->vlan_features |= NETIF_F_HIGHDMA;
689 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700690
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700691 /*
692 * Set the CRB window to invalid. If any register in window 0 is
693 * accessed it should set the window to 0 and then reset it to 1.
694 */
695 adapter->curr_window = 255;
696
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700697 if (netxen_nic_get_board_info(adapter) != 0) {
698 printk("%s: Error getting board config info.\n",
Dhananjay Phadke29566402008-07-21 19:44:04 -0700699 netxen_nic_driver_name);
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700700 err = -EIO;
701 goto err_out_iounmap;
702 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700703
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700704 netxen_initialize_adapter_ops(adapter);
705
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700706 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadkedc515f22008-06-15 22:59:43 -0700707 switch (adapter->ahw.boardcfg.board_type) {
708 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
709 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
710 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700711 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -0700712 break;
713 default:
714 break;
715 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700716
Dhananjay Phadke29566402008-07-21 19:44:04 -0700717 /*
718 * This call will setup various max rx/tx counts.
719 * It must be done before any buffer/ring allocations.
720 */
721 netxen_check_options(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400722
Dhananjay Phadke29566402008-07-21 19:44:04 -0700723 first_driver = 0;
724 if (NX_IS_REVISION_P3(revision_id)) {
725 if (adapter->ahw.pci_func == 0)
726 first_driver = 1;
727 } else {
728 if (adapter->portnum == 0)
729 first_driver = 1;
730 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400731
Dhananjay Phadke29566402008-07-21 19:44:04 -0700732 if (first_driver) {
733 first_boot = adapter->pci_read_normalize(adapter,
734 NETXEN_CAM_RAM(0x1fc));
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400735
Dhananjay Phadke29566402008-07-21 19:44:04 -0700736 err = netxen_check_hw_init(adapter, first_boot);
737 if (err) {
738 printk(KERN_ERR "%s: error in init HW init sequence\n",
739 netxen_nic_driver_name);
740 goto err_out_iounmap;
741 }
742
743 if (NX_IS_REVISION_P3(revision_id))
744 netxen_set_port_mode(adapter);
745
746 if (first_boot != 0x55555555) {
747 adapter->pci_write_normalize(adapter,
748 CRB_CMDPEG_STATE, 0);
749 netxen_pinit_from_rom(adapter, 0);
750 msleep(1);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700751 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800752 netxen_load_firmware(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700753
Dhananjay Phadke29566402008-07-21 19:44:04 -0700754 if (NX_IS_REVISION_P2(revision_id)) {
755
756 /* Initialize multicast addr pool owners */
757 val = 0x7654;
758 if (adapter->ahw.board_type == NETXEN_NIC_XGBE)
759 val |= 0x0f000000;
760 netxen_crb_writelit_adapter(adapter,
761 NETXEN_MAC_ADDR_CNTL_REG, val);
762
763 }
764
Dhananjay Phadke29566402008-07-21 19:44:04 -0700765 err = netxen_initialize_adapter_offload(adapter);
766 if (err)
767 goto err_out_iounmap;
768
769 /*
770 * Tell the hardware our version number.
771 */
772 i = (_NETXEN_NIC_LINUX_MAJOR << 16)
773 | ((_NETXEN_NIC_LINUX_MINOR << 8))
774 | (_NETXEN_NIC_LINUX_SUBVERSION);
775 adapter->pci_write_normalize(adapter, CRB_DRIVER_VERSION, i);
776
777 /* Handshake with the card before we register the devices. */
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800778 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
779 if (err)
780 goto err_out_free_offload;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700781
Dhananjay Phadke29566402008-07-21 19:44:04 -0700782 } /* first_driver */
783
784 netxen_nic_flash_print(adapter);
785
Dhananjay Phadked9e651b2008-07-21 19:44:08 -0700786 if (NX_IS_REVISION_P3(revision_id)) {
787 adapter->hw_read_wx(adapter,
788 NETXEN_MIU_MN_CONTROL, &val, 4);
789 adapter->ahw.cut_through = (val & 0x4) ? 1 : 0;
790 dev_info(&pdev->dev, "firmware running in %s mode\n",
791 adapter->ahw.cut_through ? "cut through" : "legacy");
792 }
793
Dhananjay Phadke29566402008-07-21 19:44:04 -0700794 /*
795 * See if the firmware gave us a virtual-physical port mapping.
796 */
797 adapter->physical_port = adapter->portnum;
798 i = adapter->pci_read_normalize(adapter, CRB_V2P(adapter->portnum));
799 if (i != 0x55555555)
800 adapter->physical_port = i;
801
802 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
803
804 netxen_set_msix_bit(pdev, 0);
805
806 if (NX_IS_REVISION_P3(revision_id)) {
807 if ((mem_len != NETXEN_PCI_128MB_SIZE) &&
808 mem_len != NETXEN_PCI_2MB_SIZE)
809 adapter->msix_supported = 0;
810 }
811
812 if (adapter->msix_supported) {
813
814 netxen_init_msix_entries(adapter);
815
816 if (pci_enable_msix(pdev, adapter->msix_entries,
817 MSIX_ENTRIES_PER_ADAPTER))
818 goto request_msi;
819
820 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
821 netxen_set_msix_bit(pdev, 1);
822 dev_info(&pdev->dev, "using msi-x interrupts\n");
823
824 } else {
825request_msi:
826 if (use_msi && !pci_enable_msi(pdev)) {
827 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
828 dev_info(&pdev->dev, "using msi interrupts\n");
829 } else
830 dev_info(&pdev->dev, "using legacy interrupts\n");
831 }
832
833 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
834 netdev->irq = adapter->msix_entries[0].vector;
835 else
836 netdev->irq = pdev->irq;
837
838 err = netxen_receive_peg_ready(adapter);
839 if (err)
840 goto err_out_disable_msi;
841
842 init_timer(&adapter->watchdog_timer);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700843 adapter->watchdog_timer.function = &netxen_watchdog;
844 adapter->watchdog_timer.data = (unsigned long)adapter;
845 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
846 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
847
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700848 err = netxen_read_mac_addr(adapter);
849 if (err)
850 dev_warn(&pdev->dev, "failed to read mac addr\n");
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700851
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700852 netif_carrier_off(netdev);
853 netif_stop_queue(netdev);
854
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700855 if ((err = register_netdev(netdev))) {
856 printk(KERN_ERR "%s: register_netdev failed port #%d"
857 " aborting\n", netxen_nic_driver_name,
858 adapter->portnum);
859 err = -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700860 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700861 }
862
863 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400864
Dhananjay Phadke29566402008-07-21 19:44:04 -0700865 switch (adapter->ahw.board_type) {
866 case NETXEN_NIC_GBE:
867 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
868 adapter->netdev->name);
869 break;
870 case NETXEN_NIC_XGBE:
871 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
872 adapter->netdev->name);
873 break;
874 }
875
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400876 return 0;
877
Dhananjay Phadke29566402008-07-21 19:44:04 -0700878err_out_disable_msi:
879 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
880 pci_disable_msix(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700881 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
882 pci_disable_msi(pdev);
883
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800884err_out_free_offload:
Dhananjay Phadke29566402008-07-21 19:44:04 -0700885 if (first_driver)
886 netxen_free_adapter_offload(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400887
Dhananjay Phadke29566402008-07-21 19:44:04 -0700888err_out_iounmap:
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800889 if (db_ptr)
890 iounmap(db_ptr);
891
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800892 if (mem_ptr0)
893 iounmap(mem_ptr0);
894 if (mem_ptr1)
895 iounmap(mem_ptr1);
896 if (mem_ptr2)
897 iounmap(mem_ptr2);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800898
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700899err_out_free_netdev:
900 free_netdev(netdev);
901
902err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400903 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700904
905err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -0700906 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400907 pci_disable_device(pdev);
908 return err;
909}
910
911static void __devexit netxen_nic_remove(struct pci_dev *pdev)
912{
913 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700914 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400915
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700916 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400917 if (adapter == NULL)
918 return;
919
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700920 netdev = adapter->netdev;
921
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530922 unregister_netdev(netdev);
923
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530924 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400925 netxen_free_hw_resources(adapter);
Dhananjay Phadke9e410772008-08-08 00:08:40 -0700926 netxen_release_rx_buffers(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700927 netxen_free_sw_resources(adapter);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800928
929 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
930 netxen_p3_free_mac_list(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530931 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400932
Dhananjay Phadke439b4542008-06-15 22:59:46 -0700933 if (adapter->portnum == 0)
934 netxen_free_adapter_offload(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530935
dhananjay@netxen.com30522462007-08-28 17:23:26 +0530936 if (adapter->irq)
937 free_irq(adapter->irq, adapter);
938
Dhananjay Phadke29566402008-07-21 19:44:04 -0700939 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
940 pci_disable_msix(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +0530941 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
942 pci_disable_msi(pdev);
943
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700944 iounmap(adapter->ahw.db_base);
945 iounmap(adapter->ahw.pci_base0);
Dhananjay Phadke3bfafd62009-01-16 11:03:01 -0800946 if (adapter->ahw.pci_base1 != NULL)
947 iounmap(adapter->ahw.pci_base1);
948 if (adapter->ahw.pci_base2 != NULL)
949 iounmap(adapter->ahw.pci_base2);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -0700950
951 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +0530952 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -0700953 pci_set_drvdata(pdev, NULL);
954
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700955 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400956}
957
958/*
959 * Called when a network interface is made active
960 * @returns 0 on success, negative value on failure
961 */
962static int netxen_nic_open(struct net_device *netdev)
963{
Wang Chen4cf16532008-11-12 23:38:14 -0800964 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400965 int err = 0;
966 int ctx, ring;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -0700967 irq_handler_t handler;
968 unsigned long flags = IRQF_SAMPLE_RANDOM;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400969
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700970 if (adapter->driver_mismatch)
971 return -EIO;
972
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400973 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) {
974 err = netxen_init_firmware(adapter);
975 if (err != 0) {
976 printk(KERN_ERR "Failed to init firmware\n");
977 return -EIO;
978 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400979
Dhananjay Phadke83821a02008-08-01 03:14:58 -0700980 if (adapter->fw_major < 4)
981 adapter->max_rds_rings = 3;
982 else
983 adapter->max_rds_rings = 2;
984
Dhananjay Phadke29566402008-07-21 19:44:04 -0700985 err = netxen_alloc_sw_resources(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400986 if (err) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700987 printk(KERN_ERR "%s: Error in setting sw resources\n",
988 netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400989 return err;
990 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700991
992 netxen_nic_clear_stats(adapter);
993
994 err = netxen_alloc_hw_resources(adapter);
995 if (err) {
996 printk(KERN_ERR "%s: Error in setting hw resources\n",
997 netdev->name);
998 goto err_out_free_sw;
999 }
1000
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001001 if ((adapter->msi_mode != MSI_MODE_MULTIFUNC) ||
1002 (adapter->intr_scheme != INTR_SCHEME_PERPORT)) {
1003 printk(KERN_ERR "%s: Firmware interrupt scheme is "
1004 "incompatible with driver\n",
1005 netdev->name);
1006 adapter->driver_mismatch = 1;
1007 goto err_out_free_hw;
1008 }
1009
Dhananjay Phadke29566402008-07-21 19:44:04 -07001010 if (adapter->fw_major < 4) {
1011 adapter->crb_addr_cmd_producer =
1012 crb_cmd_producer[adapter->portnum];
1013 adapter->crb_addr_cmd_consumer =
1014 crb_cmd_consumer[adapter->portnum];
Dhananjay Phadke29566402008-07-21 19:44:04 -07001015
Dhananjay Phadke83821a02008-08-01 03:14:58 -07001016 netxen_nic_update_cmd_producer(adapter, 0);
1017 netxen_nic_update_cmd_consumer(adapter, 0);
1018 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001019
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001020 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001021 for (ring = 0; ring < adapter->max_rds_rings; ring++)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001022 netxen_post_rx_buffers(adapter, ctx, ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001023 }
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001024 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
1025 handler = netxen_msix_intr;
1026 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001027 handler = netxen_msi_intr;
1028 else {
1029 flags |= IRQF_SHARED;
1030 handler = netxen_intr;
1031 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001032 adapter->irq = netdev->irq;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001033 err = request_irq(adapter->irq, handler,
1034 flags, netdev->name, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001035 if (err) {
1036 printk(KERN_ERR "request_irq failed with: %d\n", err);
Dhananjay Phadke9e410772008-08-08 00:08:40 -07001037 goto err_out_free_rxbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001038 }
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001039
1040 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1041 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001042
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001043 /* Done here again so that even if phantom sw overwrote it,
1044 * we set it */
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001045 err = adapter->init_port(adapter, adapter->physical_port);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001046 if (err) {
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001047 printk(KERN_ERR "%s: Failed to initialize port %d\n",
1048 netxen_nic_driver_name, adapter->portnum);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001049 goto err_out_free_irq;
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001050 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001051 adapter->macaddr_set(adapter, netdev->dev_addr);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001052
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001053 netxen_nic_set_link_parameters(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001054
Stephen Hemminger1abd2662008-11-21 17:32:15 -08001055 netxen_set_multicast_list(netdev);
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001056 if (adapter->set_mtu)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001057 adapter->set_mtu(adapter, netdev->mtu);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001058
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001059 adapter->ahw.linkup = 0;
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001060 mod_timer(&adapter->watchdog_timer, jiffies);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001061
1062 napi_enable(&adapter->napi);
1063 netxen_nic_enable_int(adapter);
1064
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001065 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001066
1067 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001068
1069err_out_free_irq:
1070 free_irq(adapter->irq, adapter);
Dhananjay Phadke9e410772008-08-08 00:08:40 -07001071err_out_free_rxbuf:
1072 netxen_release_rx_buffers(adapter);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001073err_out_free_hw:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001074 netxen_free_hw_resources(adapter);
1075err_out_free_sw:
1076 netxen_free_sw_resources(adapter);
1077 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001078}
1079
1080/*
1081 * netxen_nic_close - Disables a network interface entry point
1082 */
1083static int netxen_nic_close(struct net_device *netdev)
1084{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001085 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001086
1087 netif_carrier_off(netdev);
1088 netif_stop_queue(netdev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001089 napi_disable(&adapter->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001090
dhananjay@netxen.com72b0a7a2007-12-26 10:23:56 -08001091 if (adapter->stop_port)
1092 adapter->stop_port(adapter);
1093
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301094 netxen_nic_disable_int(adapter);
1095
Dhananjay Phadke29566402008-07-21 19:44:04 -07001096 netxen_release_tx_buffers(adapter);
1097
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001098 FLUSH_SCHEDULED_WORK();
1099 del_timer_sync(&adapter->watchdog_timer);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001100
1101 return 0;
1102}
1103
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001104static bool netxen_tso_check(struct net_device *netdev,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001105 struct cmd_desc_type0 *desc, struct sk_buff *skb)
1106{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001107 bool tso = false;
1108 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001109 __be16 protocol = skb->protocol;
1110 u16 flags = 0;
1111
Harvey Harrison09640e62009-02-01 00:45:17 -08001112 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001113 struct vlan_ethhdr *vh = (struct vlan_ethhdr *)skb->data;
1114 protocol = vh->h_vlan_encapsulated_proto;
1115 flags = FLAGS_VLAN_TAGGED;
1116 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001117
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001118 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1119 skb_shinfo(skb)->gso_size > 0) {
1120
1121 desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1122 desc->total_hdr_length =
1123 skb_transport_offset(skb) + tcp_hdrlen(skb);
1124
Harvey Harrison09640e62009-02-01 00:45:17 -08001125 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001126 TX_TCP_LSO6 : TX_TCP_LSO;
1127 tso = true;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001128
1129 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001130 u8 l4proto;
1131
Harvey Harrison09640e62009-02-01 00:45:17 -08001132 if (protocol == cpu_to_be16(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001133 l4proto = ip_hdr(skb)->protocol;
1134
1135 if (l4proto == IPPROTO_TCP)
1136 opcode = TX_TCP_PKT;
1137 else if(l4proto == IPPROTO_UDP)
1138 opcode = TX_UDP_PKT;
Harvey Harrison09640e62009-02-01 00:45:17 -08001139 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001140 l4proto = ipv6_hdr(skb)->nexthdr;
1141
1142 if (l4proto == IPPROTO_TCP)
1143 opcode = TX_TCPV6_PKT;
1144 else if(l4proto == IPPROTO_UDP)
1145 opcode = TX_UDPV6_PKT;
1146 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001147 }
1148 desc->tcp_hdr_offset = skb_transport_offset(skb);
1149 desc->ip_hdr_offset = skb_network_offset(skb);
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001150 netxen_set_tx_flags_opcode(desc, flags, opcode);
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001151 return tso;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001152}
1153
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001154static void
1155netxen_clean_tx_dma_mapping(struct pci_dev *pdev,
1156 struct netxen_cmd_buffer *pbuf, int last)
1157{
1158 int k;
1159 struct netxen_skb_frag *buffrag;
1160
1161 buffrag = &pbuf->frag_array[0];
1162 pci_unmap_single(pdev, buffrag->dma,
1163 buffrag->length, PCI_DMA_TODEVICE);
1164
1165 for (k = 1; k < last; k++) {
1166 buffrag = &pbuf->frag_array[k];
1167 pci_unmap_page(pdev, buffrag->dma,
1168 buffrag->length, PCI_DMA_TODEVICE);
1169 }
1170}
1171
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001172static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1173{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001174 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001175 struct netxen_hardware_context *hw = &adapter->ahw;
1176 unsigned int first_seg_len = skb->len - skb->data_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001177 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001178 struct netxen_skb_frag *buffrag;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001179 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001180 struct pci_dev *pdev = adapter->pdev;
1181 dma_addr_t temp_dma;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001182 int i, k;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001183
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001184 u32 producer, consumer;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001185 int frag_count, no_of_desc;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001186 u32 num_txd = adapter->max_tx_desc_count;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001187 bool is_tso = false;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001188
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001189 frag_count = skb_shinfo(skb)->nr_frags + 1;
1190
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001191 /* There 4 fragments per descriptor */
1192 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001193
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001194 producer = adapter->cmd_producer;
1195 smp_mb();
1196 consumer = adapter->last_cmd_consumer;
1197 if ((no_of_desc+2) > find_diff_among(producer, consumer, num_txd)) {
1198 netif_stop_queue(netdev);
1199 smp_mb();
1200 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001201 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001202
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001203 /* Copy the descriptors into the hardware */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001204 hwdesc = &hw->cmd_desc_head[producer];
1205 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
1206 /* Take skb->data itself */
1207 pbuf = &adapter->cmd_buf_arr[producer];
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001208
1209 is_tso = netxen_tso_check(netdev, hwdesc, skb);
1210
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001211 pbuf->skb = skb;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001212 pbuf->frag_count = frag_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001213 buffrag = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001214 temp_dma = pci_map_single(pdev, skb->data, first_seg_len,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001215 PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001216 if (pci_dma_mapping_error(pdev, temp_dma))
1217 goto drop_packet;
1218
1219 buffrag->dma = temp_dma;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001220 buffrag->length = first_seg_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001221 netxen_set_tx_frags_len(hwdesc, frag_count, skb->len);
1222 netxen_set_tx_port(hwdesc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001223
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001224 hwdesc->buffer1_length = cpu_to_le16(first_seg_len);
1225 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
1226
1227 for (i = 1, k = 1; i < frag_count; i++, k++) {
1228 struct skb_frag_struct *frag;
1229 int len, temp_len;
1230 unsigned long offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001231
1232 /* move to next desc. if there is a need */
1233 if ((i & 0x3) == 0) {
1234 k = 0;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001235 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001236 hwdesc = &hw->cmd_desc_head[producer];
1237 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001238 pbuf = &adapter->cmd_buf_arr[producer];
1239 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001240 }
1241 frag = &skb_shinfo(skb)->frags[i - 1];
1242 len = frag->size;
1243 offset = frag->page_offset;
1244
1245 temp_len = len;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001246 temp_dma = pci_map_page(pdev, frag->page, offset,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001247 len, PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001248 if (pci_dma_mapping_error(pdev, temp_dma)) {
1249 netxen_clean_tx_dma_mapping(pdev, pbuf, i);
1250 goto drop_packet;
1251 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001252
1253 buffrag++;
1254 buffrag->dma = temp_dma;
1255 buffrag->length = temp_len;
1256
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001257 switch (k) {
1258 case 0:
1259 hwdesc->buffer1_length = cpu_to_le16(temp_len);
1260 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
1261 break;
1262 case 1:
1263 hwdesc->buffer2_length = cpu_to_le16(temp_len);
1264 hwdesc->addr_buffer2 = cpu_to_le64(temp_dma);
1265 break;
1266 case 2:
1267 hwdesc->buffer3_length = cpu_to_le16(temp_len);
1268 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
1269 break;
1270 case 3:
Al Viroa608ab9c2007-01-02 10:39:10 +00001271 hwdesc->buffer4_length = cpu_to_le16(temp_len);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001272 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
1273 break;
1274 }
1275 frag++;
1276 }
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001277 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001278
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001279 /* For LSO, we need to copy the MAC/IP/TCP headers into
1280 * the descriptor ring
1281 */
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001282 if (is_tso) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001283 int hdr_len, first_hdr_len, more_hdr;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001284 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001285 if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) {
1286 first_hdr_len = sizeof(struct cmd_desc_type0) - 2;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001287 more_hdr = 1;
1288 } else {
1289 first_hdr_len = hdr_len;
1290 more_hdr = 0;
1291 }
1292 /* copy the MAC/IP/TCP headers to the cmd descriptor list */
1293 hwdesc = &hw->cmd_desc_head[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001294 pbuf = &adapter->cmd_buf_arr[producer];
1295 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001296
1297 /* copy the first 64 bytes */
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001298 memcpy(((void *)hwdesc) + 2,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001299 (void *)(skb->data), first_hdr_len);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001300 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001301
1302 if (more_hdr) {
1303 hwdesc = &hw->cmd_desc_head[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001304 pbuf = &adapter->cmd_buf_arr[producer];
1305 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001306 /* copy the next 64 bytes - should be enough except
1307 * for pathological case
1308 */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001309 skb_copy_from_linear_data_offset(skb, first_hdr_len,
1310 hwdesc,
1311 (hdr_len -
1312 first_hdr_len));
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001313 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001314 }
1315 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001316
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001317 adapter->cmd_producer = producer;
Dhananjay Phadke5dc16262007-12-31 10:08:57 -08001318 adapter->stats.txbytes += skb->len;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001319
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001320 netxen_nic_update_cmd_producer(adapter, adapter->cmd_producer);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001321
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001322 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001323 netdev->trans_start = jiffies;
1324
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001325 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001326
1327drop_packet:
1328 adapter->stats.txdropped++;
1329 dev_kfree_skb_any(skb);
1330 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001331}
1332
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001333static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1334{
1335 struct net_device *netdev = adapter->netdev;
1336 uint32_t temp, temp_state, temp_val;
1337 int rv = 0;
1338
1339 temp = adapter->pci_read_normalize(adapter, CRB_TEMP_STATE);
1340
1341 temp_state = nx_get_temp_state(temp);
1342 temp_val = nx_get_temp_val(temp);
1343
1344 if (temp_state == NX_TEMP_PANIC) {
1345 printk(KERN_ALERT
1346 "%s: Device temperature %d degrees C exceeds"
1347 " maximum allowed. Hardware has been shut down.\n",
1348 netxen_nic_driver_name, temp_val);
1349
1350 netif_carrier_off(netdev);
1351 netif_stop_queue(netdev);
1352 rv = 1;
1353 } else if (temp_state == NX_TEMP_WARN) {
1354 if (adapter->temp == NX_TEMP_NORMAL) {
1355 printk(KERN_ALERT
1356 "%s: Device temperature %d degrees C "
1357 "exceeds operating range."
1358 " Immediate action needed.\n",
1359 netxen_nic_driver_name, temp_val);
1360 }
1361 } else {
1362 if (adapter->temp == NX_TEMP_WARN) {
1363 printk(KERN_INFO
1364 "%s: Device temperature is now %d degrees C"
1365 " in normal range.\n", netxen_nic_driver_name,
1366 temp_val);
1367 }
1368 }
1369 adapter->temp = temp_state;
1370 return rv;
1371}
1372
1373static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1374{
1375 struct net_device *netdev = adapter->netdev;
1376 u32 val, port, linkup;
1377
1378 port = adapter->physical_port;
1379
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001380 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1381 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE_P3);
1382 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1383 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001384 } else {
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001385 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
1386 if (adapter->ahw.board_type == NETXEN_NIC_GBE)
1387 linkup = (val >> port) & 1;
1388 else {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001389 val = (val >> port*8) & 0xff;
1390 linkup = (val == XG_LINK_UP);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001391 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001392 }
1393
1394 if (adapter->ahw.linkup && !linkup) {
1395 printk(KERN_INFO "%s: %s NIC Link is down\n",
1396 netxen_nic_driver_name, netdev->name);
1397 adapter->ahw.linkup = 0;
1398 if (netif_running(netdev)) {
1399 netif_carrier_off(netdev);
1400 netif_stop_queue(netdev);
1401 }
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001402
1403 netxen_nic_set_link_parameters(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001404 } else if (!adapter->ahw.linkup && linkup) {
1405 printk(KERN_INFO "%s: %s NIC Link is up\n",
1406 netxen_nic_driver_name, netdev->name);
1407 adapter->ahw.linkup = 1;
1408 if (netif_running(netdev)) {
1409 netif_carrier_on(netdev);
1410 netif_wake_queue(netdev);
1411 }
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001412
1413 netxen_nic_set_link_parameters(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001414 }
1415}
1416
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001417static void netxen_watchdog(unsigned long v)
1418{
1419 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001420
1421 SCHEDULE_WORK(&adapter->watchdog_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001422}
1423
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001424void netxen_watchdog_task(struct work_struct *work)
1425{
1426 struct netxen_adapter *adapter =
1427 container_of(work, struct netxen_adapter, watchdog_task);
1428
1429 if ((adapter->portnum == 0) && netxen_nic_check_temp(adapter))
1430 return;
1431
1432 netxen_nic_handle_phy_intr(adapter);
1433
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001434 if (netif_running(adapter->netdev))
1435 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001436}
1437
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001438static void netxen_tx_timeout(struct net_device *netdev)
1439{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001440 struct netxen_adapter *adapter = (struct netxen_adapter *)
1441 netdev_priv(netdev);
1442 SCHEDULE_WORK(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001443}
1444
David Howells6d5aefb2006-12-05 19:36:26 +00001445static void netxen_tx_timeout_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001446{
Jeff Garzik47906542007-11-23 21:23:36 -05001447 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001448 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001449
1450 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001451 netxen_nic_driver_name, adapter->netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001452
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001453 netxen_nic_disable_int(adapter);
1454 napi_disable(&adapter->napi);
1455
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001456 adapter->netdev->trans_start = jiffies;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001457
1458 napi_enable(&adapter->napi);
1459 netxen_nic_enable_int(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001460 netif_wake_queue(adapter->netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001461}
1462
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001463/*
1464 * netxen_nic_get_stats - Get System Network Statistics
1465 * @netdev: network interface device structure
1466 */
1467struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1468{
1469 struct netxen_adapter *adapter = netdev_priv(netdev);
1470 struct net_device_stats *stats = &adapter->net_stats;
1471
1472 memset(stats, 0, sizeof(*stats));
1473
1474 /* total packets received */
1475 stats->rx_packets = adapter->stats.no_rcv;
1476 /* total packets transmitted */
1477 stats->tx_packets = adapter->stats.xmitedframes +
1478 adapter->stats.xmitfinished;
1479 /* total bytes received */
1480 stats->rx_bytes = adapter->stats.rxbytes;
1481 /* total bytes transmitted */
1482 stats->tx_bytes = adapter->stats.txbytes;
1483 /* bad packets received */
1484 stats->rx_errors = adapter->stats.rcvdbadskb;
1485 /* packet transmit problems */
1486 stats->tx_errors = adapter->stats.nocmddescriptor;
1487 /* no space in linux buffers */
1488 stats->rx_dropped = adapter->stats.rxdropped;
1489 /* no space available in linux */
1490 stats->tx_dropped = adapter->stats.txdropped;
1491
1492 return stats;
1493}
1494
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001495static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001496{
Jeff Garzik1daec862007-10-19 03:14:03 -04001497 struct netxen_adapter *adapter = data;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001498 u32 status = 0;
1499
1500 status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1501
1502 if (!(status & adapter->legacy_intr.int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001503 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301504
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001505 if (adapter->ahw.revision_id >= NX_P3_B1) {
1506 /* check interrupt state machine, to be sure */
1507 status = adapter->pci_read_immediate(adapter,
1508 ISR_INT_STATE_REG);
1509 if (!ISR_LEGACY_INT_TRIGGERED(status))
1510 return IRQ_NONE;
1511
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001512 } else {
1513 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001514
1515 our_int = adapter->pci_read_normalize(adapter, CRB_INT_VECTOR);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001516
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001517 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001518 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001519 return IRQ_NONE;
1520
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001521 /* claim interrupt */
1522 adapter->pci_write_normalize(adapter,
1523 CRB_INT_VECTOR, (our_int & 0xffffffff));
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301524 }
1525
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001526 /* clear interrupt */
1527 if (adapter->fw_major < 4)
1528 netxen_nic_disable_int(adapter);
1529
1530 adapter->pci_write_immediate(adapter,
1531 adapter->legacy_intr.tgt_status_reg,
1532 0xffffffff);
1533 /* read twice to ensure write is flushed */
1534 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1535 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1536
1537 napi_schedule(&adapter->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001538
1539 return IRQ_HANDLED;
1540}
1541
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001542static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001543{
1544 struct netxen_adapter *adapter = data;
1545
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001546 /* clear interrupt */
1547 adapter->pci_write_immediate(adapter,
1548 msi_tgt_status[adapter->ahw.pci_func], 0xffffffff);
1549
1550 napi_schedule(&adapter->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001551 return IRQ_HANDLED;
1552}
1553
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001554static irqreturn_t netxen_msix_intr(int irq, void *data)
1555{
1556 struct netxen_adapter *adapter = data;
1557
1558 napi_schedule(&adapter->napi);
1559 return IRQ_HANDLED;
1560}
1561
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001562static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001563{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001564 struct netxen_adapter *adapter = container_of(napi, struct netxen_adapter, napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001565 int tx_complete;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001566 int ctx;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001567 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001568
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001569 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001570
Amit S. Kale80922fb2006-12-04 09:18:00 -08001571 work_done = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001572 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
1573 /*
1574 * Fairness issue. This will give undue weight to the
1575 * receive context 0.
1576 */
1577
1578 /*
1579 * To avoid starvation, we give each of our receivers,
1580 * a fraction of the quota. Sometimes, it might happen that we
1581 * have enough quota to process every packet, but since all the
1582 * packets are on one context, it gets only half of the quota,
1583 * and ends up not processing it.
1584 */
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001585 work_done += netxen_process_rcv_ring(adapter, ctx,
1586 budget / MAX_RCV_CTX);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001587 }
1588
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001589 if ((work_done < budget) && tx_complete) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001590 napi_complete(&adapter->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001591 netxen_nic_enable_int(adapter);
1592 }
1593
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001594 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001595}
1596
1597#ifdef CONFIG_NET_POLL_CONTROLLER
1598static void netxen_nic_poll_controller(struct net_device *netdev)
1599{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001600 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001601 disable_irq(adapter->irq);
Jeff Garzik1494a812006-11-07 05:12:16 -05001602 netxen_intr(adapter->irq, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001603 enable_irq(adapter->irq);
1604}
1605#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001606
1607static struct pci_driver netxen_driver = {
1608 .name = netxen_nic_driver_name,
1609 .id_table = netxen_pci_tbl,
1610 .probe = netxen_nic_probe,
1611 .remove = __devexit_p(netxen_nic_remove)
1612};
1613
1614/* Driver Registration on NetXen card */
1615
1616static int __init netxen_init_module(void)
1617{
Al Viro79ea13c2008-01-24 02:06:46 -08001618 if ((netxen_workq = create_singlethread_workqueue("netxen")) == NULL)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001619 return -ENOMEM;
1620
Amit S. Kale184231b2007-01-22 06:52:53 -08001621 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001622}
1623
1624module_init(netxen_init_module);
1625
1626static void __exit netxen_exit_module(void)
1627{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001628 pci_unregister_driver(&netxen_driver);
Amit S. Kale9de06612007-02-21 06:37:06 -08001629 destroy_workqueue(netxen_workq);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001630}
1631
1632module_exit(netxen_exit_module);