blob: c9519843f8cb9e4c1185aded96027706468531b9 [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
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800679 if (first_boot != 0x55555555) {
680 adapter->pci_write_normalize(adapter,
681 CRB_CMDPEG_STATE, 0);
682 netxen_pinit_from_rom(adapter, 0);
683 msleep(1);
684 }
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000685
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000686 netxen_nic_reg_write(adapter, CRB_DMA_SHIFT, 0x55555555);
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000687 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
688 netxen_set_port_mode(adapter);
689
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800690 netxen_load_firmware(adapter);
691
692 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
693
694 /* Initialize multicast addr pool owners */
695 val = 0x7654;
696 if (adapter->ahw.board_type == NETXEN_NIC_XGBE)
697 val |= 0x0f000000;
698 netxen_crb_writelit_adapter(adapter,
699 NETXEN_MAC_ADDR_CNTL_REG, val);
700
701 }
702
703 err = netxen_initialize_adapter_offload(adapter);
704 if (err)
705 return err;
706
707 /*
708 * Tell the hardware our version number.
709 */
710 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
711 | ((_NETXEN_NIC_LINUX_MINOR << 8))
712 | (_NETXEN_NIC_LINUX_SUBVERSION);
713 adapter->pci_write_normalize(adapter, CRB_DRIVER_VERSION, val);
714
715 /* Handshake with the card before we register the devices. */
716 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
717 if (err) {
718 netxen_free_adapter_offload(adapter);
719 return err;
720 }
721
722 return 0;
723}
724
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400725static int __devinit
726netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
727{
728 struct net_device *netdev = NULL;
729 struct netxen_adapter *adapter = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700730 int i = 0, err;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800731 int first_driver;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700732 u32 val;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700733 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700734 uint8_t revision_id;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400735
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700736 if (pci_func_id == 0)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700737 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700738
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700739 if (pdev->class != 0x020000) {
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700740 printk(KERN_DEBUG "NetXen function %d, class %x will not "
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700741 "be enabled.\n",pci_func_id, pdev->class);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800742 return -ENODEV;
743 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700744
Dhananjay Phadke11d89d62008-08-08 00:08:45 -0700745 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
746 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
747 "will not be enabled.\n",
748 NX_P3_A0, NX_P3_B1);
749 return -ENODEV;
750 }
751
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400752 if ((err = pci_enable_device(pdev)))
753 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700754
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400755 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
756 err = -ENODEV;
757 goto err_out_disable_pdev;
758 }
759
760 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
761 goto err_out_disable_pdev;
762
763 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700764
765 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
766 if(!netdev) {
767 printk(KERN_ERR"%s: Failed to allocate memory for the "
768 "device block.Check system memory resource"
769 " usage.\n", netxen_nic_driver_name);
770 goto err_out_free_res;
771 }
772
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700773 SET_NETDEV_DEV(netdev, &pdev->dev);
774
Wang Chen4cf16532008-11-12 23:38:14 -0800775 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700776 adapter->netdev = netdev;
777 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700778 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700779
780 revision_id = pdev->revision;
781 adapter->ahw.revision_id = revision_id;
782
783 err = nx_set_dma_mask(adapter, revision_id);
784 if (err)
785 goto err_out_free_netdev;
786
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700787 rwlock_init(&adapter->adapter_lock);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700788
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800789 err = netxen_setup_pci_map(adapter);
790 if (err)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700791 goto err_out_free_netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400792
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700793 netif_napi_add(netdev, &adapter->napi,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700794 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
795
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +0530796 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700797 adapter->portnum = pci_func_id;
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +0530798 adapter->status &= ~NETXEN_NETDEV_STATUS;
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530799 adapter->rx_csum = 1;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700800 adapter->mc_enabled = 0;
Dhananjay Phadke83821a02008-08-01 03:14:58 -0700801 if (NX_IS_REVISION_P3(revision_id))
Dhananjay Phadke29566402008-07-21 19:44:04 -0700802 adapter->max_mc_count = 38;
Dhananjay Phadke83821a02008-08-01 03:14:58 -0700803 else
Dhananjay Phadke29566402008-07-21 19:44:04 -0700804 adapter->max_mc_count = 16;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700805
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800806 netdev->netdev_ops = &netxen_netdev_ops;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -0700807 netdev->watchdog_timeo = 2*HZ;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700808
809 netxen_nic_change_mtu(netdev, netdev->mtu);
810
811 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800812
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800813 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
814 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
815
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700816 if (NX_IS_REVISION_P3(revision_id)) {
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800817 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
818 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700819 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700820
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800821 if (adapter->pci_using_dac) {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700822 netdev->features |= NETIF_F_HIGHDMA;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800823 netdev->vlan_features |= NETIF_F_HIGHDMA;
824 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700825
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700826 if (netxen_nic_get_board_info(adapter) != 0) {
827 printk("%s: Error getting board config info.\n",
Dhananjay Phadke29566402008-07-21 19:44:04 -0700828 netxen_nic_driver_name);
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700829 err = -EIO;
830 goto err_out_iounmap;
831 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700832
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700833 netxen_initialize_adapter_ops(adapter);
834
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700835 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadkedc515f22008-06-15 22:59:43 -0700836 switch (adapter->ahw.boardcfg.board_type) {
837 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
838 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
839 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700840 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -0700841 break;
842 default:
843 break;
844 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700845
Dhananjay Phadke29566402008-07-21 19:44:04 -0700846 /*
847 * This call will setup various max rx/tx counts.
848 * It must be done before any buffer/ring allocations.
849 */
850 netxen_check_options(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400851
Dhananjay Phadke29566402008-07-21 19:44:04 -0700852 first_driver = 0;
853 if (NX_IS_REVISION_P3(revision_id)) {
854 if (adapter->ahw.pci_func == 0)
855 first_driver = 1;
856 } else {
857 if (adapter->portnum == 0)
858 first_driver = 1;
859 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400860
Dhananjay Phadke29566402008-07-21 19:44:04 -0700861 if (first_driver) {
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800862 err = netxen_start_firmware(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700863 if (err)
864 goto err_out_iounmap;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800865 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700866
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000867 nx_update_dma_mask(adapter);
868
Dhananjay Phadke29566402008-07-21 19:44:04 -0700869 netxen_nic_flash_print(adapter);
870
Dhananjay Phadked9e651b2008-07-21 19:44:08 -0700871 if (NX_IS_REVISION_P3(revision_id)) {
872 adapter->hw_read_wx(adapter,
873 NETXEN_MIU_MN_CONTROL, &val, 4);
874 adapter->ahw.cut_through = (val & 0x4) ? 1 : 0;
875 dev_info(&pdev->dev, "firmware running in %s mode\n",
876 adapter->ahw.cut_through ? "cut through" : "legacy");
877 }
878
Dhananjay Phadke29566402008-07-21 19:44:04 -0700879 /*
880 * See if the firmware gave us a virtual-physical port mapping.
881 */
882 adapter->physical_port = adapter->portnum;
Dhananjay Phadke044fad02009-02-24 03:42:59 -0800883 if (adapter->fw_major < 4) {
884 i = adapter->pci_read_normalize(adapter,
885 CRB_V2P(adapter->portnum));
886 if (i != 0x55555555)
887 adapter->physical_port = i;
888 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700889
890 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
891
892 netxen_set_msix_bit(pdev, 0);
893
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800894 netxen_setup_intr(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700895
896 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
897 netdev->irq = adapter->msix_entries[0].vector;
898 else
899 netdev->irq = pdev->irq;
900
901 err = netxen_receive_peg_ready(adapter);
902 if (err)
903 goto err_out_disable_msi;
904
905 init_timer(&adapter->watchdog_timer);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700906 adapter->watchdog_timer.function = &netxen_watchdog;
907 adapter->watchdog_timer.data = (unsigned long)adapter;
908 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
909 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
910
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700911 err = netxen_read_mac_addr(adapter);
912 if (err)
913 dev_warn(&pdev->dev, "failed to read mac addr\n");
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700914
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700915 netif_carrier_off(netdev);
916 netif_stop_queue(netdev);
917
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700918 if ((err = register_netdev(netdev))) {
919 printk(KERN_ERR "%s: register_netdev failed port #%d"
920 " aborting\n", netxen_nic_driver_name,
921 adapter->portnum);
922 err = -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700923 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700924 }
925
926 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400927
Dhananjay Phadke29566402008-07-21 19:44:04 -0700928 switch (adapter->ahw.board_type) {
929 case NETXEN_NIC_GBE:
930 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
931 adapter->netdev->name);
932 break;
933 case NETXEN_NIC_XGBE:
934 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
935 adapter->netdev->name);
936 break;
937 }
938
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400939 return 0;
940
Dhananjay Phadke29566402008-07-21 19:44:04 -0700941err_out_disable_msi:
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800942 netxen_teardown_intr(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700943
Dhananjay Phadke29566402008-07-21 19:44:04 -0700944 if (first_driver)
945 netxen_free_adapter_offload(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400946
Dhananjay Phadke29566402008-07-21 19:44:04 -0700947err_out_iounmap:
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800948 netxen_cleanup_pci_map(adapter);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800949
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700950err_out_free_netdev:
951 free_netdev(netdev);
952
953err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400954 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700955
956err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -0700957 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400958 pci_disable_device(pdev);
959 return err;
960}
961
962static void __devexit netxen_nic_remove(struct pci_dev *pdev)
963{
964 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700965 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400966
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700967 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400968 if (adapter == NULL)
969 return;
970
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700971 netdev = adapter->netdev;
972
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530973 unregister_netdev(netdev);
974
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530975 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400976 netxen_free_hw_resources(adapter);
Dhananjay Phadke9e410772008-08-08 00:08:40 -0700977 netxen_release_rx_buffers(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700978 netxen_free_sw_resources(adapter);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800979
980 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
981 netxen_p3_free_mac_list(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530982 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400983
Dhananjay Phadke439b4542008-06-15 22:59:46 -0700984 if (adapter->portnum == 0)
985 netxen_free_adapter_offload(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530986
dhananjay@netxen.com30522462007-08-28 17:23:26 +0530987 if (adapter->irq)
988 free_irq(adapter->irq, adapter);
989
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800990 netxen_teardown_intr(adapter);
dhananjay@netxen.com30522462007-08-28 17:23:26 +0530991
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800992 netxen_cleanup_pci_map(adapter);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -0700993
994 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +0530995 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -0700996 pci_set_drvdata(pdev, NULL);
997
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700998 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400999}
1000
1001/*
1002 * Called when a network interface is made active
1003 * @returns 0 on success, negative value on failure
1004 */
1005static int netxen_nic_open(struct net_device *netdev)
1006{
Wang Chen4cf16532008-11-12 23:38:14 -08001007 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001008 int err = 0;
1009 int ctx, ring;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001010 irq_handler_t handler;
1011 unsigned long flags = IRQF_SAMPLE_RANDOM;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001012
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001013 if (adapter->driver_mismatch)
1014 return -EIO;
1015
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001016 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) {
1017 err = netxen_init_firmware(adapter);
1018 if (err != 0) {
1019 printk(KERN_ERR "Failed to init firmware\n");
1020 return -EIO;
1021 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001022
Dhananjay Phadke83821a02008-08-01 03:14:58 -07001023 if (adapter->fw_major < 4)
1024 adapter->max_rds_rings = 3;
1025 else
1026 adapter->max_rds_rings = 2;
1027
Dhananjay Phadke29566402008-07-21 19:44:04 -07001028 err = netxen_alloc_sw_resources(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001029 if (err) {
Dhananjay Phadke29566402008-07-21 19:44:04 -07001030 printk(KERN_ERR "%s: Error in setting sw resources\n",
1031 netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001032 return err;
1033 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001034
1035 netxen_nic_clear_stats(adapter);
1036
1037 err = netxen_alloc_hw_resources(adapter);
1038 if (err) {
1039 printk(KERN_ERR "%s: Error in setting hw resources\n",
1040 netdev->name);
1041 goto err_out_free_sw;
1042 }
1043
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001044 if ((adapter->msi_mode != MSI_MODE_MULTIFUNC) ||
1045 (adapter->intr_scheme != INTR_SCHEME_PERPORT)) {
1046 printk(KERN_ERR "%s: Firmware interrupt scheme is "
1047 "incompatible with driver\n",
1048 netdev->name);
1049 adapter->driver_mismatch = 1;
1050 goto err_out_free_hw;
1051 }
1052
Dhananjay Phadke29566402008-07-21 19:44:04 -07001053 if (adapter->fw_major < 4) {
1054 adapter->crb_addr_cmd_producer =
1055 crb_cmd_producer[adapter->portnum];
1056 adapter->crb_addr_cmd_consumer =
1057 crb_cmd_consumer[adapter->portnum];
Dhananjay Phadke29566402008-07-21 19:44:04 -07001058
Dhananjay Phadke83821a02008-08-01 03:14:58 -07001059 netxen_nic_update_cmd_producer(adapter, 0);
1060 netxen_nic_update_cmd_consumer(adapter, 0);
1061 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001062
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001063 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001064 for (ring = 0; ring < adapter->max_rds_rings; ring++)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001065 netxen_post_rx_buffers(adapter, ctx, ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001066 }
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001067 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
1068 handler = netxen_msix_intr;
1069 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001070 handler = netxen_msi_intr;
1071 else {
1072 flags |= IRQF_SHARED;
1073 handler = netxen_intr;
1074 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001075 adapter->irq = netdev->irq;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001076 err = request_irq(adapter->irq, handler,
1077 flags, netdev->name, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001078 if (err) {
1079 printk(KERN_ERR "request_irq failed with: %d\n", err);
Dhananjay Phadke9e410772008-08-08 00:08:40 -07001080 goto err_out_free_rxbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001081 }
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001082
1083 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1084 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001085
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001086 /* Done here again so that even if phantom sw overwrote it,
1087 * we set it */
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001088 err = adapter->init_port(adapter, adapter->physical_port);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001089 if (err) {
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001090 printk(KERN_ERR "%s: Failed to initialize port %d\n",
1091 netxen_nic_driver_name, adapter->portnum);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001092 goto err_out_free_irq;
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001093 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001094 adapter->macaddr_set(adapter, netdev->dev_addr);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001095
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001096 netxen_nic_set_link_parameters(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001097
Stephen Hemminger1abd2662008-11-21 17:32:15 -08001098 netxen_set_multicast_list(netdev);
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001099 if (adapter->set_mtu)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001100 adapter->set_mtu(adapter, netdev->mtu);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001101
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001102 adapter->ahw.linkup = 0;
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001103 mod_timer(&adapter->watchdog_timer, jiffies);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001104
1105 napi_enable(&adapter->napi);
1106 netxen_nic_enable_int(adapter);
1107
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001108 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001109
1110 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001111
1112err_out_free_irq:
1113 free_irq(adapter->irq, adapter);
Dhananjay Phadke9e410772008-08-08 00:08:40 -07001114err_out_free_rxbuf:
1115 netxen_release_rx_buffers(adapter);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001116err_out_free_hw:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001117 netxen_free_hw_resources(adapter);
1118err_out_free_sw:
1119 netxen_free_sw_resources(adapter);
1120 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001121}
1122
1123/*
1124 * netxen_nic_close - Disables a network interface entry point
1125 */
1126static int netxen_nic_close(struct net_device *netdev)
1127{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001128 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001129
1130 netif_carrier_off(netdev);
1131 netif_stop_queue(netdev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001132 napi_disable(&adapter->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001133
dhananjay@netxen.com72b0a7a2007-12-26 10:23:56 -08001134 if (adapter->stop_port)
1135 adapter->stop_port(adapter);
1136
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301137 netxen_nic_disable_int(adapter);
1138
Dhananjay Phadke29566402008-07-21 19:44:04 -07001139 netxen_release_tx_buffers(adapter);
1140
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001141 FLUSH_SCHEDULED_WORK();
1142 del_timer_sync(&adapter->watchdog_timer);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001143
1144 return 0;
1145}
1146
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001147static bool netxen_tso_check(struct net_device *netdev,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001148 struct cmd_desc_type0 *desc, struct sk_buff *skb)
1149{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001150 bool tso = false;
1151 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001152 __be16 protocol = skb->protocol;
1153 u16 flags = 0;
1154
Harvey Harrison09640e62009-02-01 00:45:17 -08001155 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001156 struct vlan_ethhdr *vh = (struct vlan_ethhdr *)skb->data;
1157 protocol = vh->h_vlan_encapsulated_proto;
1158 flags = FLAGS_VLAN_TAGGED;
1159 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001160
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001161 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1162 skb_shinfo(skb)->gso_size > 0) {
1163
1164 desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1165 desc->total_hdr_length =
1166 skb_transport_offset(skb) + tcp_hdrlen(skb);
1167
Harvey Harrison09640e62009-02-01 00:45:17 -08001168 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001169 TX_TCP_LSO6 : TX_TCP_LSO;
1170 tso = true;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001171
1172 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001173 u8 l4proto;
1174
Harvey Harrison09640e62009-02-01 00:45:17 -08001175 if (protocol == cpu_to_be16(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001176 l4proto = ip_hdr(skb)->protocol;
1177
1178 if (l4proto == IPPROTO_TCP)
1179 opcode = TX_TCP_PKT;
1180 else if(l4proto == IPPROTO_UDP)
1181 opcode = TX_UDP_PKT;
Harvey Harrison09640e62009-02-01 00:45:17 -08001182 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001183 l4proto = ipv6_hdr(skb)->nexthdr;
1184
1185 if (l4proto == IPPROTO_TCP)
1186 opcode = TX_TCPV6_PKT;
1187 else if(l4proto == IPPROTO_UDP)
1188 opcode = TX_UDPV6_PKT;
1189 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001190 }
1191 desc->tcp_hdr_offset = skb_transport_offset(skb);
1192 desc->ip_hdr_offset = skb_network_offset(skb);
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001193 netxen_set_tx_flags_opcode(desc, flags, opcode);
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001194 return tso;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001195}
1196
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001197static void
1198netxen_clean_tx_dma_mapping(struct pci_dev *pdev,
1199 struct netxen_cmd_buffer *pbuf, int last)
1200{
1201 int k;
1202 struct netxen_skb_frag *buffrag;
1203
1204 buffrag = &pbuf->frag_array[0];
1205 pci_unmap_single(pdev, buffrag->dma,
1206 buffrag->length, PCI_DMA_TODEVICE);
1207
1208 for (k = 1; k < last; k++) {
1209 buffrag = &pbuf->frag_array[k];
1210 pci_unmap_page(pdev, buffrag->dma,
1211 buffrag->length, PCI_DMA_TODEVICE);
1212 }
1213}
1214
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001215static inline void
1216netxen_clear_cmddesc(u64 *desc)
1217{
1218 int i;
1219 for (i = 0; i < 8; i++)
1220 desc[i] = 0ULL;
1221}
1222
1223static int
1224netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001225{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001226 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001227 struct netxen_hardware_context *hw = &adapter->ahw;
1228 unsigned int first_seg_len = skb->len - skb->data_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001229 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001230 struct netxen_skb_frag *buffrag;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001231 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001232 struct pci_dev *pdev = adapter->pdev;
1233 dma_addr_t temp_dma;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001234 int i, k;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001235
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001236 u32 producer, consumer;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001237 int frag_count, no_of_desc;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001238 u32 num_txd = adapter->max_tx_desc_count;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001239 bool is_tso = false;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001240
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001241 frag_count = skb_shinfo(skb)->nr_frags + 1;
1242
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001243 /* There 4 fragments per descriptor */
1244 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001245
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001246 producer = adapter->cmd_producer;
1247 smp_mb();
1248 consumer = adapter->last_cmd_consumer;
1249 if ((no_of_desc+2) > find_diff_among(producer, consumer, num_txd)) {
1250 netif_stop_queue(netdev);
1251 smp_mb();
1252 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001253 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001254
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001255 /* Copy the descriptors into the hardware */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001256 hwdesc = &hw->cmd_desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001257 netxen_clear_cmddesc((u64 *)hwdesc);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001258 /* Take skb->data itself */
1259 pbuf = &adapter->cmd_buf_arr[producer];
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001260
1261 is_tso = netxen_tso_check(netdev, hwdesc, skb);
1262
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001263 pbuf->skb = skb;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001264 pbuf->frag_count = frag_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001265 buffrag = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001266 temp_dma = pci_map_single(pdev, skb->data, first_seg_len,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001267 PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001268 if (pci_dma_mapping_error(pdev, temp_dma))
1269 goto drop_packet;
1270
1271 buffrag->dma = temp_dma;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001272 buffrag->length = first_seg_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001273 netxen_set_tx_frags_len(hwdesc, frag_count, skb->len);
1274 netxen_set_tx_port(hwdesc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001275
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001276 hwdesc->buffer_length[0] = cpu_to_le16(first_seg_len);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001277 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
1278
1279 for (i = 1, k = 1; i < frag_count; i++, k++) {
1280 struct skb_frag_struct *frag;
1281 int len, temp_len;
1282 unsigned long offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001283
1284 /* move to next desc. if there is a need */
1285 if ((i & 0x3) == 0) {
1286 k = 0;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001287 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001288 hwdesc = &hw->cmd_desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001289 netxen_clear_cmddesc((u64 *)hwdesc);
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001290 pbuf = &adapter->cmd_buf_arr[producer];
1291 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001292 }
1293 frag = &skb_shinfo(skb)->frags[i - 1];
1294 len = frag->size;
1295 offset = frag->page_offset;
1296
1297 temp_len = len;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001298 temp_dma = pci_map_page(pdev, frag->page, offset,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001299 len, PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001300 if (pci_dma_mapping_error(pdev, temp_dma)) {
1301 netxen_clean_tx_dma_mapping(pdev, pbuf, i);
1302 goto drop_packet;
1303 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001304
1305 buffrag++;
1306 buffrag->dma = temp_dma;
1307 buffrag->length = temp_len;
1308
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001309 hwdesc->buffer_length[k] = cpu_to_le16(temp_len);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001310 switch (k) {
1311 case 0:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001312 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
1313 break;
1314 case 1:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001315 hwdesc->addr_buffer2 = cpu_to_le64(temp_dma);
1316 break;
1317 case 2:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001318 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
1319 break;
1320 case 3:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001321 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
1322 break;
1323 }
1324 frag++;
1325 }
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001326 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001327
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001328 /* For LSO, we need to copy the MAC/IP/TCP headers into
1329 * the descriptor ring
1330 */
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001331 if (is_tso) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001332 int hdr_len, first_hdr_len, more_hdr;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001333 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001334 if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) {
1335 first_hdr_len = sizeof(struct cmd_desc_type0) - 2;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001336 more_hdr = 1;
1337 } else {
1338 first_hdr_len = hdr_len;
1339 more_hdr = 0;
1340 }
1341 /* copy the MAC/IP/TCP headers to the cmd descriptor list */
1342 hwdesc = &hw->cmd_desc_head[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001343 pbuf = &adapter->cmd_buf_arr[producer];
1344 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001345
1346 /* copy the first 64 bytes */
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001347 memcpy(((void *)hwdesc) + 2,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001348 (void *)(skb->data), first_hdr_len);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001349 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001350
1351 if (more_hdr) {
1352 hwdesc = &hw->cmd_desc_head[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001353 pbuf = &adapter->cmd_buf_arr[producer];
1354 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001355 /* copy the next 64 bytes - should be enough except
1356 * for pathological case
1357 */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001358 skb_copy_from_linear_data_offset(skb, first_hdr_len,
1359 hwdesc,
1360 (hdr_len -
1361 first_hdr_len));
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001362 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001363 }
1364 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001365
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001366 adapter->cmd_producer = producer;
Dhananjay Phadke5dc16262007-12-31 10:08:57 -08001367 adapter->stats.txbytes += skb->len;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001368
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001369 netxen_nic_update_cmd_producer(adapter, adapter->cmd_producer);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001370
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001371 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001372 netdev->trans_start = jiffies;
1373
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001374 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001375
1376drop_packet:
1377 adapter->stats.txdropped++;
1378 dev_kfree_skb_any(skb);
1379 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001380}
1381
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001382static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1383{
1384 struct net_device *netdev = adapter->netdev;
1385 uint32_t temp, temp_state, temp_val;
1386 int rv = 0;
1387
1388 temp = adapter->pci_read_normalize(adapter, CRB_TEMP_STATE);
1389
1390 temp_state = nx_get_temp_state(temp);
1391 temp_val = nx_get_temp_val(temp);
1392
1393 if (temp_state == NX_TEMP_PANIC) {
1394 printk(KERN_ALERT
1395 "%s: Device temperature %d degrees C exceeds"
1396 " maximum allowed. Hardware has been shut down.\n",
1397 netxen_nic_driver_name, temp_val);
1398
1399 netif_carrier_off(netdev);
1400 netif_stop_queue(netdev);
1401 rv = 1;
1402 } else if (temp_state == NX_TEMP_WARN) {
1403 if (adapter->temp == NX_TEMP_NORMAL) {
1404 printk(KERN_ALERT
1405 "%s: Device temperature %d degrees C "
1406 "exceeds operating range."
1407 " Immediate action needed.\n",
1408 netxen_nic_driver_name, temp_val);
1409 }
1410 } else {
1411 if (adapter->temp == NX_TEMP_WARN) {
1412 printk(KERN_INFO
1413 "%s: Device temperature is now %d degrees C"
1414 " in normal range.\n", netxen_nic_driver_name,
1415 temp_val);
1416 }
1417 }
1418 adapter->temp = temp_state;
1419 return rv;
1420}
1421
1422static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1423{
1424 struct net_device *netdev = adapter->netdev;
1425 u32 val, port, linkup;
1426
1427 port = adapter->physical_port;
1428
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001429 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1430 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE_P3);
1431 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1432 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001433 } else {
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001434 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
1435 if (adapter->ahw.board_type == NETXEN_NIC_GBE)
1436 linkup = (val >> port) & 1;
1437 else {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001438 val = (val >> port*8) & 0xff;
1439 linkup = (val == XG_LINK_UP);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001440 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001441 }
1442
1443 if (adapter->ahw.linkup && !linkup) {
1444 printk(KERN_INFO "%s: %s NIC Link is down\n",
1445 netxen_nic_driver_name, netdev->name);
1446 adapter->ahw.linkup = 0;
1447 if (netif_running(netdev)) {
1448 netif_carrier_off(netdev);
1449 netif_stop_queue(netdev);
1450 }
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001451
1452 netxen_nic_set_link_parameters(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001453 } else if (!adapter->ahw.linkup && linkup) {
1454 printk(KERN_INFO "%s: %s NIC Link is up\n",
1455 netxen_nic_driver_name, netdev->name);
1456 adapter->ahw.linkup = 1;
1457 if (netif_running(netdev)) {
1458 netif_carrier_on(netdev);
1459 netif_wake_queue(netdev);
1460 }
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001461
1462 netxen_nic_set_link_parameters(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001463 }
1464}
1465
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001466static void netxen_watchdog(unsigned long v)
1467{
1468 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001469
1470 SCHEDULE_WORK(&adapter->watchdog_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001471}
1472
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001473void netxen_watchdog_task(struct work_struct *work)
1474{
1475 struct netxen_adapter *adapter =
1476 container_of(work, struct netxen_adapter, watchdog_task);
1477
1478 if ((adapter->portnum == 0) && netxen_nic_check_temp(adapter))
1479 return;
1480
1481 netxen_nic_handle_phy_intr(adapter);
1482
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001483 if (netif_running(adapter->netdev))
1484 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001485}
1486
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001487static void netxen_tx_timeout(struct net_device *netdev)
1488{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001489 struct netxen_adapter *adapter = (struct netxen_adapter *)
1490 netdev_priv(netdev);
1491 SCHEDULE_WORK(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001492}
1493
David Howells6d5aefb2006-12-05 19:36:26 +00001494static void netxen_tx_timeout_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001495{
Jeff Garzik47906542007-11-23 21:23:36 -05001496 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001497 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001498
1499 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001500 netxen_nic_driver_name, adapter->netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001501
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001502 netxen_nic_disable_int(adapter);
1503 napi_disable(&adapter->napi);
1504
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001505 adapter->netdev->trans_start = jiffies;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001506
1507 napi_enable(&adapter->napi);
1508 netxen_nic_enable_int(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001509 netif_wake_queue(adapter->netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001510}
1511
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001512/*
1513 * netxen_nic_get_stats - Get System Network Statistics
1514 * @netdev: network interface device structure
1515 */
1516struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1517{
1518 struct netxen_adapter *adapter = netdev_priv(netdev);
1519 struct net_device_stats *stats = &adapter->net_stats;
1520
1521 memset(stats, 0, sizeof(*stats));
1522
1523 /* total packets received */
1524 stats->rx_packets = adapter->stats.no_rcv;
1525 /* total packets transmitted */
1526 stats->tx_packets = adapter->stats.xmitedframes +
1527 adapter->stats.xmitfinished;
1528 /* total bytes received */
1529 stats->rx_bytes = adapter->stats.rxbytes;
1530 /* total bytes transmitted */
1531 stats->tx_bytes = adapter->stats.txbytes;
1532 /* bad packets received */
1533 stats->rx_errors = adapter->stats.rcvdbadskb;
1534 /* packet transmit problems */
1535 stats->tx_errors = adapter->stats.nocmddescriptor;
1536 /* no space in linux buffers */
1537 stats->rx_dropped = adapter->stats.rxdropped;
1538 /* no space available in linux */
1539 stats->tx_dropped = adapter->stats.txdropped;
1540
1541 return stats;
1542}
1543
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001544static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001545{
Jeff Garzik1daec862007-10-19 03:14:03 -04001546 struct netxen_adapter *adapter = data;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001547 u32 status = 0;
1548
1549 status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1550
1551 if (!(status & adapter->legacy_intr.int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001552 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301553
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001554 if (adapter->ahw.revision_id >= NX_P3_B1) {
1555 /* check interrupt state machine, to be sure */
1556 status = adapter->pci_read_immediate(adapter,
1557 ISR_INT_STATE_REG);
1558 if (!ISR_LEGACY_INT_TRIGGERED(status))
1559 return IRQ_NONE;
1560
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001561 } else {
1562 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001563
1564 our_int = adapter->pci_read_normalize(adapter, CRB_INT_VECTOR);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001565
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001566 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001567 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001568 return IRQ_NONE;
1569
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001570 /* claim interrupt */
1571 adapter->pci_write_normalize(adapter,
1572 CRB_INT_VECTOR, (our_int & 0xffffffff));
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301573 }
1574
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001575 /* clear interrupt */
1576 if (adapter->fw_major < 4)
1577 netxen_nic_disable_int(adapter);
1578
1579 adapter->pci_write_immediate(adapter,
1580 adapter->legacy_intr.tgt_status_reg,
1581 0xffffffff);
1582 /* read twice to ensure write is flushed */
1583 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1584 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1585
1586 napi_schedule(&adapter->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001587
1588 return IRQ_HANDLED;
1589}
1590
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001591static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001592{
1593 struct netxen_adapter *adapter = data;
1594
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001595 /* clear interrupt */
1596 adapter->pci_write_immediate(adapter,
1597 msi_tgt_status[adapter->ahw.pci_func], 0xffffffff);
1598
1599 napi_schedule(&adapter->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001600 return IRQ_HANDLED;
1601}
1602
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001603static irqreturn_t netxen_msix_intr(int irq, void *data)
1604{
1605 struct netxen_adapter *adapter = data;
1606
1607 napi_schedule(&adapter->napi);
1608 return IRQ_HANDLED;
1609}
1610
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001611static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001612{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001613 struct netxen_adapter *adapter = container_of(napi, struct netxen_adapter, napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001614 int tx_complete;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001615 int ctx;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001616 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001617
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001618 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001619
Amit S. Kale80922fb2006-12-04 09:18:00 -08001620 work_done = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001621 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
1622 /*
1623 * Fairness issue. This will give undue weight to the
1624 * receive context 0.
1625 */
1626
1627 /*
1628 * To avoid starvation, we give each of our receivers,
1629 * a fraction of the quota. Sometimes, it might happen that we
1630 * have enough quota to process every packet, but since all the
1631 * packets are on one context, it gets only half of the quota,
1632 * and ends up not processing it.
1633 */
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001634 work_done += netxen_process_rcv_ring(adapter, ctx,
1635 budget / MAX_RCV_CTX);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001636 }
1637
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001638 if ((work_done < budget) && tx_complete) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001639 napi_complete(&adapter->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001640 netxen_nic_enable_int(adapter);
1641 }
1642
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001643 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001644}
1645
1646#ifdef CONFIG_NET_POLL_CONTROLLER
1647static void netxen_nic_poll_controller(struct net_device *netdev)
1648{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001649 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001650 disable_irq(adapter->irq);
Jeff Garzik1494a812006-11-07 05:12:16 -05001651 netxen_intr(adapter->irq, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001652 enable_irq(adapter->irq);
1653}
1654#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001655
1656static struct pci_driver netxen_driver = {
1657 .name = netxen_nic_driver_name,
1658 .id_table = netxen_pci_tbl,
1659 .probe = netxen_nic_probe,
1660 .remove = __devexit_p(netxen_nic_remove)
1661};
1662
1663/* Driver Registration on NetXen card */
1664
1665static int __init netxen_init_module(void)
1666{
Al Viro79ea13c2008-01-24 02:06:46 -08001667 if ((netxen_workq = create_singlethread_workqueue("netxen")) == NULL)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001668 return -ENOMEM;
1669
Amit S. Kale184231b2007-01-22 06:52:53 -08001670 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001671}
1672
1673module_init(netxen_init_module);
1674
1675static void __exit netxen_exit_module(void)
1676{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001677 pci_unregister_driver(&netxen_driver);
Amit S. Kale9de06612007-02-21 06:37:06 -08001678 destroy_workqueue(netxen_workq);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001679}
1680
1681module_exit(netxen_exit_module);