blob: 0ce7cf0dc99ce844a36abd994c8c41468cdacb58 [file] [log] [blame]
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001/*
Dhananjay Phadke5d242f12009-02-25 15:57:56 +00002 * Copyright (C) 2003 - 2009 NetXen, Inc.
Amit S. Kale3d396eb2006-10-21 15:33:03 -04003 * 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
Dhananjay Phadke5d242f12009-02-25 15:57:56 +000025 * NetXen Inc,
26 * 18922 Forge Drive
27 * Cupertino, CA 95014-0701
Amit S. Kale3d396eb2006-10-21 15:33:03 -040028 *
29 */
30
Amit S. Kalecb8011a2006-11-29 09:00:10 -080031#include <linux/vmalloc.h>
Amit S. Kaleed25ffa2006-12-04 09:23:25 -080032#include <linux/highmem.h>
Amit S. Kale3d396eb2006-10-21 15:33:03 -040033#include "netxen_nic_hw.h"
34
35#include "netxen_nic.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040036#include "netxen_nic_phan_reg.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040037
Jeff Garzik1494a812006-11-07 05:12:16 -050038#include <linux/dma-mapping.h>
Dhananjay Phadke391587c2009-01-14 20:48:11 -080039#include <linux/if_vlan.h>
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030040#include <net/ip.h>
Dhananjay Phadke00977782009-01-16 11:03:25 -080041#include <linux/ipv6.h>
Jeff Garzik1494a812006-11-07 05:12:16 -050042
Amit S. Kale3d396eb2006-10-21 15:33:03 -040043MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
44MODULE_LICENSE("GPL");
45MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
46
dhananjay@netxen.comceded322007-07-19 14:41:09 +053047char netxen_nic_driver_name[] = "netxen_nic";
Amit S. Kale3d396eb2006-10-21 15:33:03 -040048static char netxen_nic_driver_string[] = "NetXen Network Driver version "
Amit S. Kalecb8011a2006-11-29 09:00:10 -080049 NETXEN_NIC_LINUX_VERSIONID;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040050
Dhananjay Phadke29566402008-07-21 19:44:04 -070051static int port_mode = NETXEN_PORT_MODE_AUTO_NEG;
52
53/* Default to restricted 1G auto-neg mode */
54static int wol_port_mode = 5;
55
56static int use_msi = 1;
57
58static int use_msi_x = 1;
59
Amit S. Kale3d396eb2006-10-21 15:33:03 -040060/* Local functions to NetXen NIC driver */
61static int __devinit netxen_nic_probe(struct pci_dev *pdev,
Dhananjay Phadke29566402008-07-21 19:44:04 -070062 const struct pci_device_id *ent);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040063static void __devexit netxen_nic_remove(struct pci_dev *pdev);
64static int netxen_nic_open(struct net_device *netdev);
65static int netxen_nic_close(struct net_device *netdev);
66static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *);
67static void netxen_tx_timeout(struct net_device *netdev);
David Howells6d5aefb2006-12-05 19:36:26 +000068static void netxen_tx_timeout_task(struct work_struct *work);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040069static void netxen_watchdog(unsigned long);
Stephen Hemmingerbea33482007-10-03 16:41:36 -070070static int netxen_nic_poll(struct napi_struct *napi, int budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040071#ifdef CONFIG_NET_POLL_CONTROLLER
72static void netxen_nic_poll_controller(struct net_device *netdev);
73#endif
Jeff Garzik1494a812006-11-07 05:12:16 -050074static irqreturn_t netxen_intr(int irq, void *data);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -070075static irqreturn_t netxen_msi_intr(int irq, void *data);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -080076static irqreturn_t netxen_msix_intr(int irq, void *data);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040077
78/* PCI Device ID Table */
Al Viro70081ac2008-06-23 02:04:50 +010079#define ENTRY(device) \
Dhananjay Phadke040dec32008-09-12 06:55:14 -070080 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
Al Viro70081ac2008-06-23 02:04:50 +010081 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
82
Amit S. Kale3d396eb2006-10-21 15:33:03 -040083static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
Dhananjay Phadke040dec32008-09-12 06:55:14 -070084 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR),
85 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4),
86 ENTRY(PCI_DEVICE_ID_NX2031_4GCU),
87 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ),
88 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ),
89 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT),
90 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2),
91 ENTRY(PCI_DEVICE_ID_NX3031),
Amit S. Kale3d396eb2006-10-21 15:33:03 -040092 {0,}
93};
94
95MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
96
Adrian Bunkb15551302008-03-31 02:22:18 +030097/*
98 * In netxen_nic_down(), we must wait for any pending callback requests into
99 * netxen_watchdog_task() to complete; eg otherwise the watchdog_timer could be
100 * reenabled right after it is deleted in netxen_nic_down().
101 * FLUSH_SCHEDULED_WORK() does this synchronization.
102 *
103 * Normally, schedule_work()/flush_scheduled_work() could have worked, but
104 * netxen_nic_close() is invoked with kernel rtnl lock held. netif_carrier_off()
105 * call in netxen_nic_close() triggers a schedule_work(&linkwatch_work), and a
106 * subsequent call to flush_scheduled_work() in netxen_nic_down() would cause
107 * linkwatch_event() to be executed which also attempts to acquire the rtnl
108 * lock thus causing a deadlock.
109 */
110
111static struct workqueue_struct *netxen_workq;
112#define SCHEDULE_WORK(tp) queue_work(netxen_workq, tp)
113#define FLUSH_SCHEDULED_WORK() flush_workqueue(netxen_workq)
114
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800115static void netxen_watchdog(unsigned long);
116
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700117static uint32_t crb_cmd_producer[4] = {
118 CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1,
119 CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3
120};
121
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700122void
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700123netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
124 uint32_t crb_producer)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700125{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700126 adapter->pci_write_normalize(adapter,
127 adapter->crb_addr_cmd_producer, crb_producer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700128}
129
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700130static uint32_t crb_cmd_consumer[4] = {
131 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
132 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
133};
134
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700135static inline void
136netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
137 u32 crb_consumer)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700138{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700139 adapter->pci_write_normalize(adapter,
140 adapter->crb_addr_cmd_consumer, crb_consumer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700141}
142
Dhananjay Phadke29566402008-07-21 19:44:04 -0700143static uint32_t msi_tgt_status[8] = {
Dhananjay Phadke443be792008-03-17 19:59:48 -0700144 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700145 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
146 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
147 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
Dhananjay Phadke443be792008-03-17 19:59:48 -0700148};
149
Dhananjay Phadke29566402008-07-21 19:44:04 -0700150static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
151
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700152static inline void netxen_nic_disable_int(struct netxen_adapter *adapter)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700153{
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700154 adapter->pci_write_normalize(adapter, adapter->crb_intr_mask, 0);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700155}
156
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700157static inline void netxen_nic_enable_int(struct netxen_adapter *adapter)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700158{
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700159 adapter->pci_write_normalize(adapter, adapter->crb_intr_mask, 0x1);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700160
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700161 if (!NETXEN_IS_MSI_FAMILY(adapter))
162 adapter->pci_write_immediate(adapter,
163 adapter->legacy_intr.tgt_mask_reg, 0xfbff);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700164}
165
Dhananjay Phadke29566402008-07-21 19:44:04 -0700166static int nx_set_dma_mask(struct netxen_adapter *adapter, uint8_t revision_id)
167{
168 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000169 uint64_t mask, cmask;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700170
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000171 adapter->pci_using_dac = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700172
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000173 mask = DMA_32BIT_MASK;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700174 /*
175 * Consistent DMA mask is set to 32 bit because it cannot be set to
176 * 35 bits. For P3 also leave it at 32 bits for now. Only the rings
177 * come off this pool.
178 */
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000179 cmask = DMA_32BIT_MASK;
180
181#ifndef CONFIG_IA64
182 if (revision_id >= NX_P3_B0)
183 mask = DMA_39BIT_MASK;
184 else if (revision_id == NX_P2_C1)
185 mask = DMA_35BIT_MASK;
186#endif
Dhananjay Phadke29566402008-07-21 19:44:04 -0700187 if (pci_set_dma_mask(pdev, mask) == 0 &&
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000188 pci_set_consistent_dma_mask(pdev, cmask) == 0) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700189 adapter->pci_using_dac = 1;
190 return 0;
191 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700192
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000193 return -EIO;
194}
195
196/* Update addressable range if firmware supports it */
197static int
198nx_update_dma_mask(struct netxen_adapter *adapter)
199{
200 int change, shift, err;
201 uint64_t mask, old_mask;
202 struct pci_dev *pdev = adapter->pdev;
203
204 change = 0;
205
206 shift = netxen_nic_reg_read(adapter, CRB_DMA_SHIFT);
207 if (shift >= 32)
208 return 0;
209
210 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9))
211 change = 1;
212 else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4))
213 change = 1;
214
215 if (change) {
216 old_mask = pdev->dma_mask;
217 mask = (1ULL<<(32+shift)) - 1;
218
219 err = pci_set_dma_mask(pdev, mask);
220 if (err)
221 return pci_set_dma_mask(pdev, old_mask);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700222 }
223
Dhananjay Phadke29566402008-07-21 19:44:04 -0700224 return 0;
225}
226
227static void netxen_check_options(struct netxen_adapter *adapter)
228{
229 switch (adapter->ahw.boardcfg.board_type) {
230 case NETXEN_BRDTYPE_P3_HMEZ:
231 case NETXEN_BRDTYPE_P3_XG_LOM:
232 case NETXEN_BRDTYPE_P3_10G_CX4:
233 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
234 case NETXEN_BRDTYPE_P3_IMEZ:
235 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
Dhananjay Phadkea70f9392008-08-01 03:14:56 -0700236 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
237 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
Dhananjay Phadke29566402008-07-21 19:44:04 -0700238 case NETXEN_BRDTYPE_P3_10G_XFP:
239 case NETXEN_BRDTYPE_P3_10000_BASE_T:
240 adapter->msix_supported = !!use_msi_x;
241 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
242 break;
243
244 case NETXEN_BRDTYPE_P2_SB31_10G:
245 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
246 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
247 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
248 adapter->msix_supported = 0;
249 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
250 break;
251
252 case NETXEN_BRDTYPE_P3_REF_QG:
253 case NETXEN_BRDTYPE_P3_4_GB:
254 case NETXEN_BRDTYPE_P3_4_GB_MM:
Dhananjay Phadkeec68db62008-08-20 13:52:48 -0700255 adapter->msix_supported = !!use_msi_x;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800256 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
Dhananjay Phadkea70f9392008-08-01 03:14:56 -0700257 break;
258
Dhananjay Phadke29566402008-07-21 19:44:04 -0700259 case NETXEN_BRDTYPE_P2_SB35_4G:
260 case NETXEN_BRDTYPE_P2_SB31_2G:
261 adapter->msix_supported = 0;
262 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
263 break;
264
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800265 case NETXEN_BRDTYPE_P3_10G_TP:
266 adapter->msix_supported = !!use_msi_x;
267 if (adapter->ahw.board_type == NETXEN_NIC_XGBE)
268 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
269 else
270 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
271 break;
272
Dhananjay Phadke29566402008-07-21 19:44:04 -0700273 default:
274 adapter->msix_supported = 0;
275 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
276
277 printk(KERN_WARNING "Unknown board type(0x%x)\n",
278 adapter->ahw.boardcfg.board_type);
279 break;
280 }
281
282 adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS_HOST;
283 adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS;
284 adapter->max_lro_rx_desc_count = MAX_LRO_RCV_DESCRIPTORS;
285
286 adapter->max_possible_rss_rings = 1;
287 return;
288}
289
290static int
291netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
292{
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800293 u32 val, timeout;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700294
295 if (first_boot == 0x55555555) {
296 /* This is the first boot after power up */
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800297 adapter->pci_write_normalize(adapter,
298 NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
299
300 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
301 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700302
303 /* PCI bus master workaround */
304 adapter->hw_read_wx(adapter,
305 NETXEN_PCIE_REG(0x4), &first_boot, 4);
306 if (!(first_boot & 0x4)) {
307 first_boot |= 0x4;
308 adapter->hw_write_wx(adapter,
309 NETXEN_PCIE_REG(0x4), &first_boot, 4);
310 adapter->hw_read_wx(adapter,
311 NETXEN_PCIE_REG(0x4), &first_boot, 4);
312 }
313
314 /* This is the first boot after power up */
315 adapter->hw_read_wx(adapter,
316 NETXEN_ROMUSB_GLB_SW_RESET, &first_boot, 4);
317 if (first_boot != 0x80000f) {
318 /* clear the register for future unloads/loads */
319 adapter->pci_write_normalize(adapter,
320 NETXEN_CAM_RAM(0x1fc), 0);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800321 return -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700322 }
323
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800324 /* Start P2 boot loader */
325 val = adapter->pci_read_normalize(adapter,
326 NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
327 adapter->pci_write_normalize(adapter,
328 NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
329 timeout = 0;
330 do {
331 msleep(1);
332 val = adapter->pci_read_normalize(adapter,
333 NETXEN_CAM_RAM(0x1fc));
334
335 if (++timeout > 5000)
336 return -EIO;
337
338 } while (val == NETXEN_BDINFO_MAGIC);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700339 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800340 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700341}
342
343static void netxen_set_port_mode(struct netxen_adapter *adapter)
344{
345 u32 val, data;
346
347 val = adapter->ahw.boardcfg.board_type;
348 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
349 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
350 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
351 data = NETXEN_PORT_MODE_802_3_AP;
352 adapter->hw_write_wx(adapter,
353 NETXEN_PORT_MODE_ADDR, &data, 4);
354 } else if (port_mode == NETXEN_PORT_MODE_XG) {
355 data = NETXEN_PORT_MODE_XG;
356 adapter->hw_write_wx(adapter,
357 NETXEN_PORT_MODE_ADDR, &data, 4);
358 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
359 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
360 adapter->hw_write_wx(adapter,
361 NETXEN_PORT_MODE_ADDR, &data, 4);
362 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
363 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
364 adapter->hw_write_wx(adapter,
365 NETXEN_PORT_MODE_ADDR, &data, 4);
366 } else {
367 data = NETXEN_PORT_MODE_AUTO_NEG;
368 adapter->hw_write_wx(adapter,
369 NETXEN_PORT_MODE_ADDR, &data, 4);
370 }
371
372 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
373 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
374 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
375 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
376 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
377 }
378 adapter->hw_write_wx(adapter, NETXEN_WOL_PORT_MODE,
379 &wol_port_mode, 4);
380 }
381}
382
Dhananjay Phadke29566402008-07-21 19:44:04 -0700383static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
384{
385 u32 control;
386 int pos;
387
388 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
389 if (pos) {
390 pci_read_config_dword(pdev, pos, &control);
391 if (enable)
392 control |= PCI_MSIX_FLAGS_ENABLE;
393 else
394 control = 0;
395 pci_write_config_dword(pdev, pos, control);
396 }
397}
398
399static void netxen_init_msix_entries(struct netxen_adapter *adapter)
400{
401 int i;
402
403 for (i = 0; i < MSIX_ENTRIES_PER_ADAPTER; i++)
404 adapter->msix_entries[i].entry = i;
405}
406
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700407static int
408netxen_read_mac_addr(struct netxen_adapter *adapter)
409{
410 int i;
411 unsigned char *p;
412 __le64 mac_addr;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700413 struct net_device *netdev = adapter->netdev;
414 struct pci_dev *pdev = adapter->pdev;
415
416 if (netxen_is_flash_supported(adapter) != 0)
417 return -EIO;
418
419 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
420 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
421 return -EIO;
422 } else {
423 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
424 return -EIO;
425 }
426
427 p = (unsigned char *)&mac_addr;
428 for (i = 0; i < 6; i++)
429 netdev->dev_addr[i] = *(p + 5 - i);
430
431 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
432
433 /* set station address */
434
Johannes Berge1749612008-10-27 15:59:26 -0700435 if (!is_valid_ether_addr(netdev->perm_addr))
436 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
437 else
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700438 adapter->macaddr_set(adapter, netdev->dev_addr);
439
440 return 0;
441}
442
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800443static void netxen_set_multicast_list(struct net_device *dev)
444{
445 struct netxen_adapter *adapter = netdev_priv(dev);
446
447 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
448 netxen_p3_nic_set_multi(dev);
449 else
450 netxen_p2_nic_set_multi(dev);
451}
452
453static const struct net_device_ops netxen_netdev_ops = {
454 .ndo_open = netxen_nic_open,
455 .ndo_stop = netxen_nic_close,
456 .ndo_start_xmit = netxen_nic_xmit_frame,
457 .ndo_get_stats = netxen_nic_get_stats,
458 .ndo_validate_addr = eth_validate_addr,
459 .ndo_set_multicast_list = netxen_set_multicast_list,
460 .ndo_set_mac_address = netxen_nic_set_mac,
461 .ndo_change_mtu = netxen_nic_change_mtu,
462 .ndo_tx_timeout = netxen_tx_timeout,
463#ifdef CONFIG_NET_POLL_CONTROLLER
464 .ndo_poll_controller = netxen_nic_poll_controller,
465#endif
466};
467
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800468static void
469netxen_setup_intr(struct netxen_adapter *adapter)
470{
471 struct netxen_legacy_intr_set *legacy_intrp;
472 struct pci_dev *pdev = adapter->pdev;
473
474 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
475 adapter->intr_scheme = -1;
476 adapter->msi_mode = -1;
477
478 if (adapter->ahw.revision_id >= NX_P3_B0)
479 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
480 else
481 legacy_intrp = &legacy_intr[0];
482 adapter->legacy_intr.int_vec_bit = legacy_intrp->int_vec_bit;
483 adapter->legacy_intr.tgt_status_reg = legacy_intrp->tgt_status_reg;
484 adapter->legacy_intr.tgt_mask_reg = legacy_intrp->tgt_mask_reg;
485 adapter->legacy_intr.pci_int_reg = legacy_intrp->pci_int_reg;
486
487 netxen_set_msix_bit(pdev, 0);
488
489 if (adapter->msix_supported) {
490
491 netxen_init_msix_entries(adapter);
492 if (pci_enable_msix(pdev, adapter->msix_entries,
493 MSIX_ENTRIES_PER_ADAPTER))
494 goto request_msi;
495
496 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
497 netxen_set_msix_bit(pdev, 1);
498 dev_info(&pdev->dev, "using msi-x interrupts\n");
499
500 } else {
501request_msi:
502 if (use_msi && !pci_enable_msi(pdev)) {
503 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
504 dev_info(&pdev->dev, "using msi interrupts\n");
505 } else
506 dev_info(&pdev->dev, "using legacy interrupts\n");
507 }
508}
509
510static void
511netxen_teardown_intr(struct netxen_adapter *adapter)
512{
513 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
514 pci_disable_msix(adapter->pdev);
515 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
516 pci_disable_msi(adapter->pdev);
517}
518
519static void
520netxen_cleanup_pci_map(struct netxen_adapter *adapter)
521{
522 if (adapter->ahw.db_base != NULL)
523 iounmap(adapter->ahw.db_base);
524 if (adapter->ahw.pci_base0 != NULL)
525 iounmap(adapter->ahw.pci_base0);
526 if (adapter->ahw.pci_base1 != NULL)
527 iounmap(adapter->ahw.pci_base1);
528 if (adapter->ahw.pci_base2 != NULL)
529 iounmap(adapter->ahw.pci_base2);
530}
531
532static int
533netxen_setup_pci_map(struct netxen_adapter *adapter)
534{
535 void __iomem *mem_ptr0 = NULL;
536 void __iomem *mem_ptr1 = NULL;
537 void __iomem *mem_ptr2 = NULL;
538 void __iomem *db_ptr = NULL;
539
540 unsigned long first_page_group_end;
541 unsigned long first_page_group_start;
542 unsigned long mem_base, mem_len, db_base, db_len = 0, pci_len0 = 0;
543
544 struct pci_dev *pdev = adapter->pdev;
545 int pci_func = adapter->ahw.pci_func;
546
547 int err = 0;
548
549 /*
550 * Set the CRB window to invalid. If any register in window 0 is
551 * accessed it should set the window to 0 and then reset it to 1.
552 */
553 adapter->curr_window = 255;
554 adapter->ahw.qdr_sn_window = -1;
555 adapter->ahw.ddr_mn_window = -1;
556
557 /* remap phys address */
558 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
559 mem_len = pci_resource_len(pdev, 0);
560 pci_len0 = 0;
561
562 adapter->hw_write_wx = netxen_nic_hw_write_wx_128M;
563 adapter->hw_read_wx = netxen_nic_hw_read_wx_128M;
564 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_128M;
565 adapter->pci_write_immediate = netxen_nic_pci_write_immediate_128M;
566 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_128M;
567 adapter->pci_write_normalize = netxen_nic_pci_write_normalize_128M;
568 adapter->pci_set_window = netxen_nic_pci_set_window_128M;
569 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M;
570 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M;
571
572 /* 128 Meg of memory */
573 if (mem_len == NETXEN_PCI_128MB_SIZE) {
574 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
575 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
576 SECOND_PAGE_GROUP_SIZE);
577 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
578 THIRD_PAGE_GROUP_SIZE);
579 first_page_group_start = FIRST_PAGE_GROUP_START;
580 first_page_group_end = FIRST_PAGE_GROUP_END;
581 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
582 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
583 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
584 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
585 first_page_group_start = 0;
586 first_page_group_end = 0;
587 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
588 adapter->hw_write_wx = netxen_nic_hw_write_wx_2M;
589 adapter->hw_read_wx = netxen_nic_hw_read_wx_2M;
590 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_2M;
591 adapter->pci_write_immediate =
592 netxen_nic_pci_write_immediate_2M;
593 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_2M;
594 adapter->pci_write_normalize =
595 netxen_nic_pci_write_normalize_2M;
596 adapter->pci_set_window = netxen_nic_pci_set_window_2M;
597 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M;
598 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M;
599
600 mem_ptr0 = pci_ioremap_bar(pdev, 0);
601 if (mem_ptr0 == NULL) {
602 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
603 return -EIO;
604 }
605 pci_len0 = mem_len;
606 first_page_group_start = 0;
607 first_page_group_end = 0;
608
609 adapter->ahw.ddr_mn_window = 0;
610 adapter->ahw.qdr_sn_window = 0;
611
612 adapter->ahw.mn_win_crb = 0x100000 + PCIX_MN_WINDOW +
613 (pci_func * 0x20);
614 adapter->ahw.ms_win_crb = 0x100000 + PCIX_SN_WINDOW;
615 if (pci_func < 4)
616 adapter->ahw.ms_win_crb += (pci_func * 0x20);
617 else
618 adapter->ahw.ms_win_crb +=
619 0xA0 + ((pci_func - 4) * 0x10);
620 } else {
621 return -EIO;
622 }
623
624 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
625
626 adapter->ahw.pci_base0 = mem_ptr0;
627 adapter->ahw.pci_len0 = pci_len0;
628 adapter->ahw.first_page_group_start = first_page_group_start;
629 adapter->ahw.first_page_group_end = first_page_group_end;
630 adapter->ahw.pci_base1 = mem_ptr1;
631 adapter->ahw.pci_base2 = mem_ptr2;
632
633 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
634 goto skip_doorbell;
635
636 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
637 db_len = pci_resource_len(pdev, 4);
638
639 if (db_len == 0) {
640 printk(KERN_ERR "%s: doorbell is disabled\n",
641 netxen_nic_driver_name);
642 err = -EIO;
643 goto err_out;
644 }
645
646 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
647 if (!db_ptr) {
648 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
649 netxen_nic_driver_name);
650 err = -EIO;
651 goto err_out;
652 }
653
654skip_doorbell:
655 adapter->ahw.db_base = db_ptr;
656 adapter->ahw.db_len = db_len;
657 return 0;
658
659err_out:
660 netxen_cleanup_pci_map(adapter);
661 return err;
662}
663
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800664static int
665netxen_start_firmware(struct netxen_adapter *adapter)
666{
667 int val, err, first_boot;
668 struct pci_dev *pdev = adapter->pdev;
669
670 first_boot = adapter->pci_read_normalize(adapter,
671 NETXEN_CAM_RAM(0x1fc));
672
673 err = netxen_check_hw_init(adapter, first_boot);
674 if (err) {
675 dev_err(&pdev->dev, "error in init HW init sequence\n");
676 return err;
677 }
678
679 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
680 netxen_set_port_mode(adapter);
681
682 if (first_boot != 0x55555555) {
683 adapter->pci_write_normalize(adapter,
684 CRB_CMDPEG_STATE, 0);
685 netxen_pinit_from_rom(adapter, 0);
686 msleep(1);
687 }
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000688 netxen_nic_reg_write(adapter, CRB_DMA_SHIFT, 0x55555555);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800689 netxen_load_firmware(adapter);
690
691 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
692
693 /* Initialize multicast addr pool owners */
694 val = 0x7654;
695 if (adapter->ahw.board_type == NETXEN_NIC_XGBE)
696 val |= 0x0f000000;
697 netxen_crb_writelit_adapter(adapter,
698 NETXEN_MAC_ADDR_CNTL_REG, val);
699
700 }
701
702 err = netxen_initialize_adapter_offload(adapter);
703 if (err)
704 return err;
705
706 /*
707 * Tell the hardware our version number.
708 */
709 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
710 | ((_NETXEN_NIC_LINUX_MINOR << 8))
711 | (_NETXEN_NIC_LINUX_SUBVERSION);
712 adapter->pci_write_normalize(adapter, CRB_DRIVER_VERSION, val);
713
714 /* Handshake with the card before we register the devices. */
715 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
716 if (err) {
717 netxen_free_adapter_offload(adapter);
718 return err;
719 }
720
721 return 0;
722}
723
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400724static int __devinit
725netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
726{
727 struct net_device *netdev = NULL;
728 struct netxen_adapter *adapter = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700729 int i = 0, err;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800730 int first_driver;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700731 u32 val;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700732 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700733 uint8_t revision_id;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400734
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700735 if (pci_func_id == 0)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700736 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700737
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700738 if (pdev->class != 0x020000) {
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700739 printk(KERN_DEBUG "NetXen function %d, class %x will not "
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700740 "be enabled.\n",pci_func_id, pdev->class);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800741 return -ENODEV;
742 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700743
Dhananjay Phadke11d89d62008-08-08 00:08:45 -0700744 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
745 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
746 "will not be enabled.\n",
747 NX_P3_A0, NX_P3_B1);
748 return -ENODEV;
749 }
750
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400751 if ((err = pci_enable_device(pdev)))
752 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700753
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400754 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
755 err = -ENODEV;
756 goto err_out_disable_pdev;
757 }
758
759 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
760 goto err_out_disable_pdev;
761
762 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700763
764 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
765 if(!netdev) {
766 printk(KERN_ERR"%s: Failed to allocate memory for the "
767 "device block.Check system memory resource"
768 " usage.\n", netxen_nic_driver_name);
769 goto err_out_free_res;
770 }
771
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700772 SET_NETDEV_DEV(netdev, &pdev->dev);
773
Wang Chen4cf16532008-11-12 23:38:14 -0800774 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700775 adapter->netdev = netdev;
776 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700777 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700778
779 revision_id = pdev->revision;
780 adapter->ahw.revision_id = revision_id;
781
782 err = nx_set_dma_mask(adapter, revision_id);
783 if (err)
784 goto err_out_free_netdev;
785
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700786 rwlock_init(&adapter->adapter_lock);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700787
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800788 err = netxen_setup_pci_map(adapter);
789 if (err)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700790 goto err_out_free_netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400791
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700792 netif_napi_add(netdev, &adapter->napi,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700793 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
794
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +0530795 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700796 adapter->portnum = pci_func_id;
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +0530797 adapter->status &= ~NETXEN_NETDEV_STATUS;
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530798 adapter->rx_csum = 1;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700799 adapter->mc_enabled = 0;
Dhananjay Phadke83821a02008-08-01 03:14:58 -0700800 if (NX_IS_REVISION_P3(revision_id))
Dhananjay Phadke29566402008-07-21 19:44:04 -0700801 adapter->max_mc_count = 38;
Dhananjay Phadke83821a02008-08-01 03:14:58 -0700802 else
Dhananjay Phadke29566402008-07-21 19:44:04 -0700803 adapter->max_mc_count = 16;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700804
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800805 netdev->netdev_ops = &netxen_netdev_ops;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -0700806 netdev->watchdog_timeo = 2*HZ;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700807
808 netxen_nic_change_mtu(netdev, netdev->mtu);
809
810 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800811
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800812 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
813 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
814
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700815 if (NX_IS_REVISION_P3(revision_id)) {
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800816 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
817 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700818 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700819
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800820 if (adapter->pci_using_dac) {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700821 netdev->features |= NETIF_F_HIGHDMA;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800822 netdev->vlan_features |= NETIF_F_HIGHDMA;
823 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700824
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700825 if (netxen_nic_get_board_info(adapter) != 0) {
826 printk("%s: Error getting board config info.\n",
Dhananjay Phadke29566402008-07-21 19:44:04 -0700827 netxen_nic_driver_name);
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700828 err = -EIO;
829 goto err_out_iounmap;
830 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700831
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700832 netxen_initialize_adapter_ops(adapter);
833
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700834 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadkedc515f22008-06-15 22:59:43 -0700835 switch (adapter->ahw.boardcfg.board_type) {
836 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
837 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
838 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700839 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -0700840 break;
841 default:
842 break;
843 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700844
Dhananjay Phadke29566402008-07-21 19:44:04 -0700845 /*
846 * This call will setup various max rx/tx counts.
847 * It must be done before any buffer/ring allocations.
848 */
849 netxen_check_options(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400850
Dhananjay Phadke29566402008-07-21 19:44:04 -0700851 first_driver = 0;
852 if (NX_IS_REVISION_P3(revision_id)) {
853 if (adapter->ahw.pci_func == 0)
854 first_driver = 1;
855 } else {
856 if (adapter->portnum == 0)
857 first_driver = 1;
858 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400859
Dhananjay Phadke29566402008-07-21 19:44:04 -0700860 if (first_driver) {
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800861 err = netxen_start_firmware(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700862 if (err)
863 goto err_out_iounmap;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800864 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700865
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000866 nx_update_dma_mask(adapter);
867
Dhananjay Phadke29566402008-07-21 19:44:04 -0700868 netxen_nic_flash_print(adapter);
869
Dhananjay Phadked9e651b2008-07-21 19:44:08 -0700870 if (NX_IS_REVISION_P3(revision_id)) {
871 adapter->hw_read_wx(adapter,
872 NETXEN_MIU_MN_CONTROL, &val, 4);
873 adapter->ahw.cut_through = (val & 0x4) ? 1 : 0;
874 dev_info(&pdev->dev, "firmware running in %s mode\n",
875 adapter->ahw.cut_through ? "cut through" : "legacy");
876 }
877
Dhananjay Phadke29566402008-07-21 19:44:04 -0700878 /*
879 * See if the firmware gave us a virtual-physical port mapping.
880 */
881 adapter->physical_port = adapter->portnum;
Dhananjay Phadke044fad02009-02-24 03:42:59 -0800882 if (adapter->fw_major < 4) {
883 i = adapter->pci_read_normalize(adapter,
884 CRB_V2P(adapter->portnum));
885 if (i != 0x55555555)
886 adapter->physical_port = i;
887 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700888
889 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
890
891 netxen_set_msix_bit(pdev, 0);
892
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800893 netxen_setup_intr(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700894
895 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
896 netdev->irq = adapter->msix_entries[0].vector;
897 else
898 netdev->irq = pdev->irq;
899
900 err = netxen_receive_peg_ready(adapter);
901 if (err)
902 goto err_out_disable_msi;
903
904 init_timer(&adapter->watchdog_timer);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700905 adapter->watchdog_timer.function = &netxen_watchdog;
906 adapter->watchdog_timer.data = (unsigned long)adapter;
907 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
908 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
909
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700910 err = netxen_read_mac_addr(adapter);
911 if (err)
912 dev_warn(&pdev->dev, "failed to read mac addr\n");
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700913
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700914 netif_carrier_off(netdev);
915 netif_stop_queue(netdev);
916
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700917 if ((err = register_netdev(netdev))) {
918 printk(KERN_ERR "%s: register_netdev failed port #%d"
919 " aborting\n", netxen_nic_driver_name,
920 adapter->portnum);
921 err = -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700922 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700923 }
924
925 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400926
Dhananjay Phadke29566402008-07-21 19:44:04 -0700927 switch (adapter->ahw.board_type) {
928 case NETXEN_NIC_GBE:
929 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
930 adapter->netdev->name);
931 break;
932 case NETXEN_NIC_XGBE:
933 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
934 adapter->netdev->name);
935 break;
936 }
937
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400938 return 0;
939
Dhananjay Phadke29566402008-07-21 19:44:04 -0700940err_out_disable_msi:
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800941 netxen_teardown_intr(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700942
Dhananjay Phadke29566402008-07-21 19:44:04 -0700943 if (first_driver)
944 netxen_free_adapter_offload(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400945
Dhananjay Phadke29566402008-07-21 19:44:04 -0700946err_out_iounmap:
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800947 netxen_cleanup_pci_map(adapter);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800948
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700949err_out_free_netdev:
950 free_netdev(netdev);
951
952err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400953 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700954
955err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -0700956 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400957 pci_disable_device(pdev);
958 return err;
959}
960
961static void __devexit netxen_nic_remove(struct pci_dev *pdev)
962{
963 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700964 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400965
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700966 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400967 if (adapter == NULL)
968 return;
969
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700970 netdev = adapter->netdev;
971
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530972 unregister_netdev(netdev);
973
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530974 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400975 netxen_free_hw_resources(adapter);
Dhananjay Phadke9e410772008-08-08 00:08:40 -0700976 netxen_release_rx_buffers(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700977 netxen_free_sw_resources(adapter);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800978
979 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
980 netxen_p3_free_mac_list(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530981 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400982
Dhananjay Phadke439b4542008-06-15 22:59:46 -0700983 if (adapter->portnum == 0)
984 netxen_free_adapter_offload(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530985
dhananjay@netxen.com30522462007-08-28 17:23:26 +0530986 if (adapter->irq)
987 free_irq(adapter->irq, adapter);
988
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800989 netxen_teardown_intr(adapter);
dhananjay@netxen.com30522462007-08-28 17:23:26 +0530990
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800991 netxen_cleanup_pci_map(adapter);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -0700992
993 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +0530994 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -0700995 pci_set_drvdata(pdev, NULL);
996
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700997 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400998}
999
1000/*
1001 * Called when a network interface is made active
1002 * @returns 0 on success, negative value on failure
1003 */
1004static int netxen_nic_open(struct net_device *netdev)
1005{
Wang Chen4cf16532008-11-12 23:38:14 -08001006 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001007 int err = 0;
1008 int ctx, ring;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001009 irq_handler_t handler;
1010 unsigned long flags = IRQF_SAMPLE_RANDOM;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001011
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001012 if (adapter->driver_mismatch)
1013 return -EIO;
1014
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001015 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) {
1016 err = netxen_init_firmware(adapter);
1017 if (err != 0) {
1018 printk(KERN_ERR "Failed to init firmware\n");
1019 return -EIO;
1020 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001021
Dhananjay Phadke83821a02008-08-01 03:14:58 -07001022 if (adapter->fw_major < 4)
1023 adapter->max_rds_rings = 3;
1024 else
1025 adapter->max_rds_rings = 2;
1026
Dhananjay Phadke29566402008-07-21 19:44:04 -07001027 err = netxen_alloc_sw_resources(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001028 if (err) {
Dhananjay Phadke29566402008-07-21 19:44:04 -07001029 printk(KERN_ERR "%s: Error in setting sw resources\n",
1030 netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001031 return err;
1032 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001033
1034 netxen_nic_clear_stats(adapter);
1035
1036 err = netxen_alloc_hw_resources(adapter);
1037 if (err) {
1038 printk(KERN_ERR "%s: Error in setting hw resources\n",
1039 netdev->name);
1040 goto err_out_free_sw;
1041 }
1042
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001043 if ((adapter->msi_mode != MSI_MODE_MULTIFUNC) ||
1044 (adapter->intr_scheme != INTR_SCHEME_PERPORT)) {
1045 printk(KERN_ERR "%s: Firmware interrupt scheme is "
1046 "incompatible with driver\n",
1047 netdev->name);
1048 adapter->driver_mismatch = 1;
1049 goto err_out_free_hw;
1050 }
1051
Dhananjay Phadke29566402008-07-21 19:44:04 -07001052 if (adapter->fw_major < 4) {
1053 adapter->crb_addr_cmd_producer =
1054 crb_cmd_producer[adapter->portnum];
1055 adapter->crb_addr_cmd_consumer =
1056 crb_cmd_consumer[adapter->portnum];
Dhananjay Phadke29566402008-07-21 19:44:04 -07001057
Dhananjay Phadke83821a02008-08-01 03:14:58 -07001058 netxen_nic_update_cmd_producer(adapter, 0);
1059 netxen_nic_update_cmd_consumer(adapter, 0);
1060 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001061
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001062 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001063 for (ring = 0; ring < adapter->max_rds_rings; ring++)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001064 netxen_post_rx_buffers(adapter, ctx, ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001065 }
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001066 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
1067 handler = netxen_msix_intr;
1068 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001069 handler = netxen_msi_intr;
1070 else {
1071 flags |= IRQF_SHARED;
1072 handler = netxen_intr;
1073 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001074 adapter->irq = netdev->irq;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001075 err = request_irq(adapter->irq, handler,
1076 flags, netdev->name, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001077 if (err) {
1078 printk(KERN_ERR "request_irq failed with: %d\n", err);
Dhananjay Phadke9e410772008-08-08 00:08:40 -07001079 goto err_out_free_rxbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001080 }
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001081
1082 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1083 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001084
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001085 /* Done here again so that even if phantom sw overwrote it,
1086 * we set it */
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001087 err = adapter->init_port(adapter, adapter->physical_port);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001088 if (err) {
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001089 printk(KERN_ERR "%s: Failed to initialize port %d\n",
1090 netxen_nic_driver_name, adapter->portnum);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001091 goto err_out_free_irq;
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001092 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001093 adapter->macaddr_set(adapter, netdev->dev_addr);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001094
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001095 netxen_nic_set_link_parameters(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001096
Stephen Hemminger1abd2662008-11-21 17:32:15 -08001097 netxen_set_multicast_list(netdev);
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001098 if (adapter->set_mtu)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001099 adapter->set_mtu(adapter, netdev->mtu);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001100
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001101 adapter->ahw.linkup = 0;
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001102 mod_timer(&adapter->watchdog_timer, jiffies);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001103
1104 napi_enable(&adapter->napi);
1105 netxen_nic_enable_int(adapter);
1106
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001107 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001108
1109 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001110
1111err_out_free_irq:
1112 free_irq(adapter->irq, adapter);
Dhananjay Phadke9e410772008-08-08 00:08:40 -07001113err_out_free_rxbuf:
1114 netxen_release_rx_buffers(adapter);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001115err_out_free_hw:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001116 netxen_free_hw_resources(adapter);
1117err_out_free_sw:
1118 netxen_free_sw_resources(adapter);
1119 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001120}
1121
1122/*
1123 * netxen_nic_close - Disables a network interface entry point
1124 */
1125static int netxen_nic_close(struct net_device *netdev)
1126{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001127 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001128
1129 netif_carrier_off(netdev);
1130 netif_stop_queue(netdev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001131 napi_disable(&adapter->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001132
dhananjay@netxen.com72b0a7a2007-12-26 10:23:56 -08001133 if (adapter->stop_port)
1134 adapter->stop_port(adapter);
1135
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301136 netxen_nic_disable_int(adapter);
1137
Dhananjay Phadke29566402008-07-21 19:44:04 -07001138 netxen_release_tx_buffers(adapter);
1139
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001140 FLUSH_SCHEDULED_WORK();
1141 del_timer_sync(&adapter->watchdog_timer);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001142
1143 return 0;
1144}
1145
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001146static bool netxen_tso_check(struct net_device *netdev,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001147 struct cmd_desc_type0 *desc, struct sk_buff *skb)
1148{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001149 bool tso = false;
1150 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001151 __be16 protocol = skb->protocol;
1152 u16 flags = 0;
1153
Harvey Harrison09640e632009-02-01 00:45:17 -08001154 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001155 struct vlan_ethhdr *vh = (struct vlan_ethhdr *)skb->data;
1156 protocol = vh->h_vlan_encapsulated_proto;
1157 flags = FLAGS_VLAN_TAGGED;
1158 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001159
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001160 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1161 skb_shinfo(skb)->gso_size > 0) {
1162
1163 desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1164 desc->total_hdr_length =
1165 skb_transport_offset(skb) + tcp_hdrlen(skb);
1166
Harvey Harrison09640e632009-02-01 00:45:17 -08001167 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001168 TX_TCP_LSO6 : TX_TCP_LSO;
1169 tso = true;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001170
1171 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001172 u8 l4proto;
1173
Harvey Harrison09640e632009-02-01 00:45:17 -08001174 if (protocol == cpu_to_be16(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001175 l4proto = ip_hdr(skb)->protocol;
1176
1177 if (l4proto == IPPROTO_TCP)
1178 opcode = TX_TCP_PKT;
1179 else if(l4proto == IPPROTO_UDP)
1180 opcode = TX_UDP_PKT;
Harvey Harrison09640e632009-02-01 00:45:17 -08001181 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001182 l4proto = ipv6_hdr(skb)->nexthdr;
1183
1184 if (l4proto == IPPROTO_TCP)
1185 opcode = TX_TCPV6_PKT;
1186 else if(l4proto == IPPROTO_UDP)
1187 opcode = TX_UDPV6_PKT;
1188 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001189 }
1190 desc->tcp_hdr_offset = skb_transport_offset(skb);
1191 desc->ip_hdr_offset = skb_network_offset(skb);
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001192 netxen_set_tx_flags_opcode(desc, flags, opcode);
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001193 return tso;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001194}
1195
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001196static void
1197netxen_clean_tx_dma_mapping(struct pci_dev *pdev,
1198 struct netxen_cmd_buffer *pbuf, int last)
1199{
1200 int k;
1201 struct netxen_skb_frag *buffrag;
1202
1203 buffrag = &pbuf->frag_array[0];
1204 pci_unmap_single(pdev, buffrag->dma,
1205 buffrag->length, PCI_DMA_TODEVICE);
1206
1207 for (k = 1; k < last; k++) {
1208 buffrag = &pbuf->frag_array[k];
1209 pci_unmap_page(pdev, buffrag->dma,
1210 buffrag->length, PCI_DMA_TODEVICE);
1211 }
1212}
1213
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001214static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1215{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001216 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001217 struct netxen_hardware_context *hw = &adapter->ahw;
1218 unsigned int first_seg_len = skb->len - skb->data_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001219 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001220 struct netxen_skb_frag *buffrag;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001221 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001222 struct pci_dev *pdev = adapter->pdev;
1223 dma_addr_t temp_dma;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001224 int i, k;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001225
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001226 u32 producer, consumer;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001227 int frag_count, no_of_desc;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001228 u32 num_txd = adapter->max_tx_desc_count;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001229 bool is_tso = false;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001230
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001231 frag_count = skb_shinfo(skb)->nr_frags + 1;
1232
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001233 /* There 4 fragments per descriptor */
1234 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001235
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001236 producer = adapter->cmd_producer;
1237 smp_mb();
1238 consumer = adapter->last_cmd_consumer;
1239 if ((no_of_desc+2) > find_diff_among(producer, consumer, num_txd)) {
1240 netif_stop_queue(netdev);
1241 smp_mb();
1242 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001243 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001244
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001245 /* Copy the descriptors into the hardware */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001246 hwdesc = &hw->cmd_desc_head[producer];
1247 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
1248 /* Take skb->data itself */
1249 pbuf = &adapter->cmd_buf_arr[producer];
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001250
1251 is_tso = netxen_tso_check(netdev, hwdesc, skb);
1252
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001253 pbuf->skb = skb;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001254 pbuf->frag_count = frag_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001255 buffrag = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001256 temp_dma = pci_map_single(pdev, skb->data, first_seg_len,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001257 PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001258 if (pci_dma_mapping_error(pdev, temp_dma))
1259 goto drop_packet;
1260
1261 buffrag->dma = temp_dma;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001262 buffrag->length = first_seg_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001263 netxen_set_tx_frags_len(hwdesc, frag_count, skb->len);
1264 netxen_set_tx_port(hwdesc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001265
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001266 hwdesc->buffer1_length = cpu_to_le16(first_seg_len);
1267 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
1268
1269 for (i = 1, k = 1; i < frag_count; i++, k++) {
1270 struct skb_frag_struct *frag;
1271 int len, temp_len;
1272 unsigned long offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001273
1274 /* move to next desc. if there is a need */
1275 if ((i & 0x3) == 0) {
1276 k = 0;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001277 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001278 hwdesc = &hw->cmd_desc_head[producer];
1279 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001280 pbuf = &adapter->cmd_buf_arr[producer];
1281 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001282 }
1283 frag = &skb_shinfo(skb)->frags[i - 1];
1284 len = frag->size;
1285 offset = frag->page_offset;
1286
1287 temp_len = len;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001288 temp_dma = pci_map_page(pdev, frag->page, offset,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001289 len, PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001290 if (pci_dma_mapping_error(pdev, temp_dma)) {
1291 netxen_clean_tx_dma_mapping(pdev, pbuf, i);
1292 goto drop_packet;
1293 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001294
1295 buffrag++;
1296 buffrag->dma = temp_dma;
1297 buffrag->length = temp_len;
1298
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001299 switch (k) {
1300 case 0:
1301 hwdesc->buffer1_length = cpu_to_le16(temp_len);
1302 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
1303 break;
1304 case 1:
1305 hwdesc->buffer2_length = cpu_to_le16(temp_len);
1306 hwdesc->addr_buffer2 = cpu_to_le64(temp_dma);
1307 break;
1308 case 2:
1309 hwdesc->buffer3_length = cpu_to_le16(temp_len);
1310 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
1311 break;
1312 case 3:
Al Viroa608ab9c2007-01-02 10:39:10 +00001313 hwdesc->buffer4_length = cpu_to_le16(temp_len);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001314 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
1315 break;
1316 }
1317 frag++;
1318 }
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001319 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001320
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001321 /* For LSO, we need to copy the MAC/IP/TCP headers into
1322 * the descriptor ring
1323 */
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001324 if (is_tso) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001325 int hdr_len, first_hdr_len, more_hdr;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001326 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001327 if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) {
1328 first_hdr_len = sizeof(struct cmd_desc_type0) - 2;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001329 more_hdr = 1;
1330 } else {
1331 first_hdr_len = hdr_len;
1332 more_hdr = 0;
1333 }
1334 /* copy the MAC/IP/TCP headers to the cmd descriptor list */
1335 hwdesc = &hw->cmd_desc_head[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001336 pbuf = &adapter->cmd_buf_arr[producer];
1337 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001338
1339 /* copy the first 64 bytes */
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001340 memcpy(((void *)hwdesc) + 2,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001341 (void *)(skb->data), first_hdr_len);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001342 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001343
1344 if (more_hdr) {
1345 hwdesc = &hw->cmd_desc_head[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001346 pbuf = &adapter->cmd_buf_arr[producer];
1347 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001348 /* copy the next 64 bytes - should be enough except
1349 * for pathological case
1350 */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001351 skb_copy_from_linear_data_offset(skb, first_hdr_len,
1352 hwdesc,
1353 (hdr_len -
1354 first_hdr_len));
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001355 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001356 }
1357 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001358
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001359 adapter->cmd_producer = producer;
Dhananjay Phadke5dc16262007-12-31 10:08:57 -08001360 adapter->stats.txbytes += skb->len;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001361
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001362 netxen_nic_update_cmd_producer(adapter, adapter->cmd_producer);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001363
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001364 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001365 netdev->trans_start = jiffies;
1366
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001367 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001368
1369drop_packet:
1370 adapter->stats.txdropped++;
1371 dev_kfree_skb_any(skb);
1372 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001373}
1374
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001375static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1376{
1377 struct net_device *netdev = adapter->netdev;
1378 uint32_t temp, temp_state, temp_val;
1379 int rv = 0;
1380
1381 temp = adapter->pci_read_normalize(adapter, CRB_TEMP_STATE);
1382
1383 temp_state = nx_get_temp_state(temp);
1384 temp_val = nx_get_temp_val(temp);
1385
1386 if (temp_state == NX_TEMP_PANIC) {
1387 printk(KERN_ALERT
1388 "%s: Device temperature %d degrees C exceeds"
1389 " maximum allowed. Hardware has been shut down.\n",
1390 netxen_nic_driver_name, temp_val);
1391
1392 netif_carrier_off(netdev);
1393 netif_stop_queue(netdev);
1394 rv = 1;
1395 } else if (temp_state == NX_TEMP_WARN) {
1396 if (adapter->temp == NX_TEMP_NORMAL) {
1397 printk(KERN_ALERT
1398 "%s: Device temperature %d degrees C "
1399 "exceeds operating range."
1400 " Immediate action needed.\n",
1401 netxen_nic_driver_name, temp_val);
1402 }
1403 } else {
1404 if (adapter->temp == NX_TEMP_WARN) {
1405 printk(KERN_INFO
1406 "%s: Device temperature is now %d degrees C"
1407 " in normal range.\n", netxen_nic_driver_name,
1408 temp_val);
1409 }
1410 }
1411 adapter->temp = temp_state;
1412 return rv;
1413}
1414
1415static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1416{
1417 struct net_device *netdev = adapter->netdev;
1418 u32 val, port, linkup;
1419
1420 port = adapter->physical_port;
1421
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001422 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1423 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE_P3);
1424 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1425 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001426 } else {
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001427 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
1428 if (adapter->ahw.board_type == NETXEN_NIC_GBE)
1429 linkup = (val >> port) & 1;
1430 else {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001431 val = (val >> port*8) & 0xff;
1432 linkup = (val == XG_LINK_UP);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001433 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001434 }
1435
1436 if (adapter->ahw.linkup && !linkup) {
1437 printk(KERN_INFO "%s: %s NIC Link is down\n",
1438 netxen_nic_driver_name, netdev->name);
1439 adapter->ahw.linkup = 0;
1440 if (netif_running(netdev)) {
1441 netif_carrier_off(netdev);
1442 netif_stop_queue(netdev);
1443 }
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001444
1445 netxen_nic_set_link_parameters(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001446 } else if (!adapter->ahw.linkup && linkup) {
1447 printk(KERN_INFO "%s: %s NIC Link is up\n",
1448 netxen_nic_driver_name, netdev->name);
1449 adapter->ahw.linkup = 1;
1450 if (netif_running(netdev)) {
1451 netif_carrier_on(netdev);
1452 netif_wake_queue(netdev);
1453 }
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001454
1455 netxen_nic_set_link_parameters(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001456 }
1457}
1458
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001459static void netxen_watchdog(unsigned long v)
1460{
1461 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001462
1463 SCHEDULE_WORK(&adapter->watchdog_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001464}
1465
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001466void netxen_watchdog_task(struct work_struct *work)
1467{
1468 struct netxen_adapter *adapter =
1469 container_of(work, struct netxen_adapter, watchdog_task);
1470
1471 if ((adapter->portnum == 0) && netxen_nic_check_temp(adapter))
1472 return;
1473
1474 netxen_nic_handle_phy_intr(adapter);
1475
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001476 if (netif_running(adapter->netdev))
1477 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001478}
1479
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001480static void netxen_tx_timeout(struct net_device *netdev)
1481{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001482 struct netxen_adapter *adapter = (struct netxen_adapter *)
1483 netdev_priv(netdev);
1484 SCHEDULE_WORK(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001485}
1486
David Howells6d5aefb2006-12-05 19:36:26 +00001487static void netxen_tx_timeout_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001488{
Jeff Garzik47906542007-11-23 21:23:36 -05001489 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001490 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001491
1492 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001493 netxen_nic_driver_name, adapter->netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001494
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001495 netxen_nic_disable_int(adapter);
1496 napi_disable(&adapter->napi);
1497
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001498 adapter->netdev->trans_start = jiffies;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001499
1500 napi_enable(&adapter->napi);
1501 netxen_nic_enable_int(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001502 netif_wake_queue(adapter->netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001503}
1504
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001505/*
1506 * netxen_nic_get_stats - Get System Network Statistics
1507 * @netdev: network interface device structure
1508 */
1509struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1510{
1511 struct netxen_adapter *adapter = netdev_priv(netdev);
1512 struct net_device_stats *stats = &adapter->net_stats;
1513
1514 memset(stats, 0, sizeof(*stats));
1515
1516 /* total packets received */
1517 stats->rx_packets = adapter->stats.no_rcv;
1518 /* total packets transmitted */
1519 stats->tx_packets = adapter->stats.xmitedframes +
1520 adapter->stats.xmitfinished;
1521 /* total bytes received */
1522 stats->rx_bytes = adapter->stats.rxbytes;
1523 /* total bytes transmitted */
1524 stats->tx_bytes = adapter->stats.txbytes;
1525 /* bad packets received */
1526 stats->rx_errors = adapter->stats.rcvdbadskb;
1527 /* packet transmit problems */
1528 stats->tx_errors = adapter->stats.nocmddescriptor;
1529 /* no space in linux buffers */
1530 stats->rx_dropped = adapter->stats.rxdropped;
1531 /* no space available in linux */
1532 stats->tx_dropped = adapter->stats.txdropped;
1533
1534 return stats;
1535}
1536
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001537static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001538{
Jeff Garzik1daec862007-10-19 03:14:03 -04001539 struct netxen_adapter *adapter = data;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001540 u32 status = 0;
1541
1542 status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1543
1544 if (!(status & adapter->legacy_intr.int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001545 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301546
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001547 if (adapter->ahw.revision_id >= NX_P3_B1) {
1548 /* check interrupt state machine, to be sure */
1549 status = adapter->pci_read_immediate(adapter,
1550 ISR_INT_STATE_REG);
1551 if (!ISR_LEGACY_INT_TRIGGERED(status))
1552 return IRQ_NONE;
1553
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001554 } else {
1555 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001556
1557 our_int = adapter->pci_read_normalize(adapter, CRB_INT_VECTOR);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001558
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001559 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001560 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001561 return IRQ_NONE;
1562
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001563 /* claim interrupt */
1564 adapter->pci_write_normalize(adapter,
1565 CRB_INT_VECTOR, (our_int & 0xffffffff));
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301566 }
1567
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001568 /* clear interrupt */
1569 if (adapter->fw_major < 4)
1570 netxen_nic_disable_int(adapter);
1571
1572 adapter->pci_write_immediate(adapter,
1573 adapter->legacy_intr.tgt_status_reg,
1574 0xffffffff);
1575 /* read twice to ensure write is flushed */
1576 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1577 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1578
1579 napi_schedule(&adapter->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001580
1581 return IRQ_HANDLED;
1582}
1583
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001584static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001585{
1586 struct netxen_adapter *adapter = data;
1587
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001588 /* clear interrupt */
1589 adapter->pci_write_immediate(adapter,
1590 msi_tgt_status[adapter->ahw.pci_func], 0xffffffff);
1591
1592 napi_schedule(&adapter->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001593 return IRQ_HANDLED;
1594}
1595
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001596static irqreturn_t netxen_msix_intr(int irq, void *data)
1597{
1598 struct netxen_adapter *adapter = data;
1599
1600 napi_schedule(&adapter->napi);
1601 return IRQ_HANDLED;
1602}
1603
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001604static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001605{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001606 struct netxen_adapter *adapter = container_of(napi, struct netxen_adapter, napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001607 int tx_complete;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001608 int ctx;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001609 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001610
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001611 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001612
Amit S. Kale80922fb2006-12-04 09:18:00 -08001613 work_done = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001614 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
1615 /*
1616 * Fairness issue. This will give undue weight to the
1617 * receive context 0.
1618 */
1619
1620 /*
1621 * To avoid starvation, we give each of our receivers,
1622 * a fraction of the quota. Sometimes, it might happen that we
1623 * have enough quota to process every packet, but since all the
1624 * packets are on one context, it gets only half of the quota,
1625 * and ends up not processing it.
1626 */
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001627 work_done += netxen_process_rcv_ring(adapter, ctx,
1628 budget / MAX_RCV_CTX);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001629 }
1630
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001631 if ((work_done < budget) && tx_complete) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001632 napi_complete(&adapter->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001633 netxen_nic_enable_int(adapter);
1634 }
1635
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001636 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001637}
1638
1639#ifdef CONFIG_NET_POLL_CONTROLLER
1640static void netxen_nic_poll_controller(struct net_device *netdev)
1641{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001642 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001643 disable_irq(adapter->irq);
Jeff Garzik1494a812006-11-07 05:12:16 -05001644 netxen_intr(adapter->irq, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001645 enable_irq(adapter->irq);
1646}
1647#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001648
1649static struct pci_driver netxen_driver = {
1650 .name = netxen_nic_driver_name,
1651 .id_table = netxen_pci_tbl,
1652 .probe = netxen_nic_probe,
1653 .remove = __devexit_p(netxen_nic_remove)
1654};
1655
1656/* Driver Registration on NetXen card */
1657
1658static int __init netxen_init_module(void)
1659{
Al Viro79ea13c2008-01-24 02:06:46 -08001660 if ((netxen_workq = create_singlethread_workqueue("netxen")) == NULL)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001661 return -ENOMEM;
1662
Amit S. Kale184231b2007-01-22 06:52:53 -08001663 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001664}
1665
1666module_init(netxen_init_module);
1667
1668static void __exit netxen_exit_module(void)
1669{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001670 pci_unregister_driver(&netxen_driver);
Amit S. Kale9de06612007-02-21 06:37:06 -08001671 destroy_workqueue(netxen_workq);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001672}
1673
1674module_exit(netxen_exit_module);