blob: 3b17a79361478fa29fdd75107254ee49986cc9ea [file] [log] [blame]
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001/*
2 * Copyright (C) 2003 - 2006 NetXen, Inc.
3 * All rights reserved.
Amit S. Kale80922fb2006-12-04 09:18:00 -08004 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -04005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
Amit S. Kale80922fb2006-12-04 09:18:00 -08009 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040010 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Amit S. Kale80922fb2006-12-04 09:18:00 -080014 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040015 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 * MA 02111-1307, USA.
Amit S. Kale80922fb2006-12-04 09:18:00 -080019 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040020 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
Amit S. Kale80922fb2006-12-04 09:18:00 -080022 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040023 * Contact Information:
24 * info@netxen.com
25 * NetXen,
26 * 3965 Freedom Circle, Fourth floor,
27 * Santa Clara, CA 95054
28 *
29 *
30 * Main source file for NetXen NIC Driver on Linux
31 *
32 */
33
Amit S. Kalecb8011a2006-11-29 09:00:10 -080034#include <linux/vmalloc.h>
Amit S. Kaleed25ffa2006-12-04 09:23:25 -080035#include <linux/highmem.h>
Amit S. Kale3d396eb2006-10-21 15:33:03 -040036#include "netxen_nic_hw.h"
37
38#include "netxen_nic.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040039#include "netxen_nic_phan_reg.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040040
Jeff Garzik1494a812006-11-07 05:12:16 -050041#include <linux/dma-mapping.h>
Dhananjay Phadke391587c2009-01-14 20:48:11 -080042#include <linux/if_vlan.h>
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030043#include <net/ip.h>
Dhananjay Phadke00977782009-01-16 11:03:25 -080044#include <linux/ipv6.h>
Jeff Garzik1494a812006-11-07 05:12:16 -050045
Amit S. Kale3d396eb2006-10-21 15:33:03 -040046MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
47MODULE_LICENSE("GPL");
48MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
49
dhananjay@netxen.comceded322007-07-19 14:41:09 +053050char netxen_nic_driver_name[] = "netxen_nic";
Amit S. Kale3d396eb2006-10-21 15:33:03 -040051static char netxen_nic_driver_string[] = "NetXen Network Driver version "
Amit S. Kalecb8011a2006-11-29 09:00:10 -080052 NETXEN_NIC_LINUX_VERSIONID;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040053
Dhananjay Phadke29566402008-07-21 19:44:04 -070054static int port_mode = NETXEN_PORT_MODE_AUTO_NEG;
55
56/* Default to restricted 1G auto-neg mode */
57static int wol_port_mode = 5;
58
59static int use_msi = 1;
60
61static int use_msi_x = 1;
62
Amit S. Kale3d396eb2006-10-21 15:33:03 -040063/* Local functions to NetXen NIC driver */
64static int __devinit netxen_nic_probe(struct pci_dev *pdev,
Dhananjay Phadke29566402008-07-21 19:44:04 -070065 const struct pci_device_id *ent);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040066static void __devexit netxen_nic_remove(struct pci_dev *pdev);
67static int netxen_nic_open(struct net_device *netdev);
68static int netxen_nic_close(struct net_device *netdev);
69static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *);
70static void netxen_tx_timeout(struct net_device *netdev);
David Howells6d5aefb2006-12-05 19:36:26 +000071static void netxen_tx_timeout_task(struct work_struct *work);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040072static void netxen_watchdog(unsigned long);
Stephen Hemmingerbea33482007-10-03 16:41:36 -070073static int netxen_nic_poll(struct napi_struct *napi, int budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040074#ifdef CONFIG_NET_POLL_CONTROLLER
75static void netxen_nic_poll_controller(struct net_device *netdev);
76#endif
Jeff Garzik1494a812006-11-07 05:12:16 -050077static irqreturn_t netxen_intr(int irq, void *data);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -070078static irqreturn_t netxen_msi_intr(int irq, void *data);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -080079static irqreturn_t netxen_msix_intr(int irq, void *data);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040080
81/* PCI Device ID Table */
Al Viro70081ac2008-06-23 02:04:50 +010082#define ENTRY(device) \
Dhananjay Phadke040dec32008-09-12 06:55:14 -070083 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
Al Viro70081ac2008-06-23 02:04:50 +010084 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
85
Amit S. Kale3d396eb2006-10-21 15:33:03 -040086static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
Dhananjay Phadke040dec32008-09-12 06:55:14 -070087 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR),
88 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4),
89 ENTRY(PCI_DEVICE_ID_NX2031_4GCU),
90 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ),
91 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ),
92 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT),
93 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2),
94 ENTRY(PCI_DEVICE_ID_NX3031),
Amit S. Kale3d396eb2006-10-21 15:33:03 -040095 {0,}
96};
97
98MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
99
Adrian Bunkb15551302008-03-31 02:22:18 +0300100/*
101 * In netxen_nic_down(), we must wait for any pending callback requests into
102 * netxen_watchdog_task() to complete; eg otherwise the watchdog_timer could be
103 * reenabled right after it is deleted in netxen_nic_down().
104 * FLUSH_SCHEDULED_WORK() does this synchronization.
105 *
106 * Normally, schedule_work()/flush_scheduled_work() could have worked, but
107 * netxen_nic_close() is invoked with kernel rtnl lock held. netif_carrier_off()
108 * call in netxen_nic_close() triggers a schedule_work(&linkwatch_work), and a
109 * subsequent call to flush_scheduled_work() in netxen_nic_down() would cause
110 * linkwatch_event() to be executed which also attempts to acquire the rtnl
111 * lock thus causing a deadlock.
112 */
113
114static struct workqueue_struct *netxen_workq;
115#define SCHEDULE_WORK(tp) queue_work(netxen_workq, tp)
116#define FLUSH_SCHEDULED_WORK() flush_workqueue(netxen_workq)
117
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800118static void netxen_watchdog(unsigned long);
119
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700120static uint32_t crb_cmd_producer[4] = {
121 CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1,
122 CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3
123};
124
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700125void
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700126netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
127 uint32_t crb_producer)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700128{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700129 adapter->pci_write_normalize(adapter,
130 adapter->crb_addr_cmd_producer, crb_producer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700131}
132
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700133static uint32_t crb_cmd_consumer[4] = {
134 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
135 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
136};
137
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700138static inline void
139netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
140 u32 crb_consumer)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700141{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700142 adapter->pci_write_normalize(adapter,
143 adapter->crb_addr_cmd_consumer, crb_consumer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700144}
145
Dhananjay Phadke29566402008-07-21 19:44:04 -0700146static uint32_t msi_tgt_status[8] = {
Dhananjay Phadke443be792008-03-17 19:59:48 -0700147 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700148 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
149 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
150 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
Dhananjay Phadke443be792008-03-17 19:59:48 -0700151};
152
Dhananjay Phadke29566402008-07-21 19:44:04 -0700153static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
154
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700155static inline void netxen_nic_disable_int(struct netxen_adapter *adapter)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700156{
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700157 adapter->pci_write_normalize(adapter, adapter->crb_intr_mask, 0);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700158}
159
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700160static inline void netxen_nic_enable_int(struct netxen_adapter *adapter)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700161{
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700162 adapter->pci_write_normalize(adapter, adapter->crb_intr_mask, 0x1);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700163
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700164 if (!NETXEN_IS_MSI_FAMILY(adapter))
165 adapter->pci_write_immediate(adapter,
166 adapter->legacy_intr.tgt_mask_reg, 0xfbff);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700167}
168
Dhananjay Phadke29566402008-07-21 19:44:04 -0700169static int nx_set_dma_mask(struct netxen_adapter *adapter, uint8_t revision_id)
170{
171 struct pci_dev *pdev = adapter->pdev;
172 int err;
173 uint64_t mask;
174
175#ifdef CONFIG_IA64
176 adapter->dma_mask = DMA_32BIT_MASK;
177#else
178 if (revision_id >= NX_P3_B0) {
179 /* should go to DMA_64BIT_MASK */
180 adapter->dma_mask = DMA_39BIT_MASK;
181 mask = DMA_39BIT_MASK;
182 } else if (revision_id == NX_P3_A2) {
183 adapter->dma_mask = DMA_39BIT_MASK;
184 mask = DMA_39BIT_MASK;
185 } else if (revision_id == NX_P2_C1) {
186 adapter->dma_mask = DMA_35BIT_MASK;
187 mask = DMA_35BIT_MASK;
188 } else {
189 adapter->dma_mask = DMA_32BIT_MASK;
190 mask = DMA_32BIT_MASK;
191 goto set_32_bit_mask;
192 }
193
194 /*
195 * Consistent DMA mask is set to 32 bit because it cannot be set to
196 * 35 bits. For P3 also leave it at 32 bits for now. Only the rings
197 * come off this pool.
198 */
199 if (pci_set_dma_mask(pdev, mask) == 0 &&
200 pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK) == 0) {
201 adapter->pci_using_dac = 1;
202 return 0;
203 }
204#endif /* CONFIG_IA64 */
205
206set_32_bit_mask:
207 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
208 if (!err)
209 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
210 if (err) {
211 DPRINTK(ERR, "No usable DMA configuration, aborting:%d\n", err);
212 return err;
213 }
214
215 adapter->pci_using_dac = 0;
216 return 0;
217}
218
219static void netxen_check_options(struct netxen_adapter *adapter)
220{
221 switch (adapter->ahw.boardcfg.board_type) {
222 case NETXEN_BRDTYPE_P3_HMEZ:
223 case NETXEN_BRDTYPE_P3_XG_LOM:
224 case NETXEN_BRDTYPE_P3_10G_CX4:
225 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
226 case NETXEN_BRDTYPE_P3_IMEZ:
227 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
Dhananjay Phadkea70f9392008-08-01 03:14:56 -0700228 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
229 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
Dhananjay Phadke29566402008-07-21 19:44:04 -0700230 case NETXEN_BRDTYPE_P3_10G_XFP:
231 case NETXEN_BRDTYPE_P3_10000_BASE_T:
232 adapter->msix_supported = !!use_msi_x;
233 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
234 break;
235
236 case NETXEN_BRDTYPE_P2_SB31_10G:
237 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
238 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
239 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
240 adapter->msix_supported = 0;
241 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
242 break;
243
244 case NETXEN_BRDTYPE_P3_REF_QG:
245 case NETXEN_BRDTYPE_P3_4_GB:
246 case NETXEN_BRDTYPE_P3_4_GB_MM:
Dhananjay Phadkeec68db62008-08-20 13:52:48 -0700247 adapter->msix_supported = !!use_msi_x;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800248 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
Dhananjay Phadkea70f9392008-08-01 03:14:56 -0700249 break;
250
Dhananjay Phadke29566402008-07-21 19:44:04 -0700251 case NETXEN_BRDTYPE_P2_SB35_4G:
252 case NETXEN_BRDTYPE_P2_SB31_2G:
253 adapter->msix_supported = 0;
254 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
255 break;
256
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800257 case NETXEN_BRDTYPE_P3_10G_TP:
258 adapter->msix_supported = !!use_msi_x;
259 if (adapter->ahw.board_type == NETXEN_NIC_XGBE)
260 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G;
261 else
262 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
263 break;
264
Dhananjay Phadke29566402008-07-21 19:44:04 -0700265 default:
266 adapter->msix_supported = 0;
267 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G;
268
269 printk(KERN_WARNING "Unknown board type(0x%x)\n",
270 adapter->ahw.boardcfg.board_type);
271 break;
272 }
273
274 adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS_HOST;
275 adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS;
276 adapter->max_lro_rx_desc_count = MAX_LRO_RCV_DESCRIPTORS;
277
278 adapter->max_possible_rss_rings = 1;
279 return;
280}
281
282static int
283netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
284{
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800285 u32 val, timeout;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700286
287 if (first_boot == 0x55555555) {
288 /* This is the first boot after power up */
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800289 adapter->pci_write_normalize(adapter,
290 NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
291
292 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
293 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700294
295 /* PCI bus master workaround */
296 adapter->hw_read_wx(adapter,
297 NETXEN_PCIE_REG(0x4), &first_boot, 4);
298 if (!(first_boot & 0x4)) {
299 first_boot |= 0x4;
300 adapter->hw_write_wx(adapter,
301 NETXEN_PCIE_REG(0x4), &first_boot, 4);
302 adapter->hw_read_wx(adapter,
303 NETXEN_PCIE_REG(0x4), &first_boot, 4);
304 }
305
306 /* This is the first boot after power up */
307 adapter->hw_read_wx(adapter,
308 NETXEN_ROMUSB_GLB_SW_RESET, &first_boot, 4);
309 if (first_boot != 0x80000f) {
310 /* clear the register for future unloads/loads */
311 adapter->pci_write_normalize(adapter,
312 NETXEN_CAM_RAM(0x1fc), 0);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800313 return -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700314 }
315
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800316 /* Start P2 boot loader */
317 val = adapter->pci_read_normalize(adapter,
318 NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
319 adapter->pci_write_normalize(adapter,
320 NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
321 timeout = 0;
322 do {
323 msleep(1);
324 val = adapter->pci_read_normalize(adapter,
325 NETXEN_CAM_RAM(0x1fc));
326
327 if (++timeout > 5000)
328 return -EIO;
329
330 } while (val == NETXEN_BDINFO_MAGIC);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700331 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800332 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700333}
334
335static void netxen_set_port_mode(struct netxen_adapter *adapter)
336{
337 u32 val, data;
338
339 val = adapter->ahw.boardcfg.board_type;
340 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
341 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
342 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
343 data = NETXEN_PORT_MODE_802_3_AP;
344 adapter->hw_write_wx(adapter,
345 NETXEN_PORT_MODE_ADDR, &data, 4);
346 } else if (port_mode == NETXEN_PORT_MODE_XG) {
347 data = NETXEN_PORT_MODE_XG;
348 adapter->hw_write_wx(adapter,
349 NETXEN_PORT_MODE_ADDR, &data, 4);
350 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
351 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
352 adapter->hw_write_wx(adapter,
353 NETXEN_PORT_MODE_ADDR, &data, 4);
354 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
355 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
356 adapter->hw_write_wx(adapter,
357 NETXEN_PORT_MODE_ADDR, &data, 4);
358 } else {
359 data = NETXEN_PORT_MODE_AUTO_NEG;
360 adapter->hw_write_wx(adapter,
361 NETXEN_PORT_MODE_ADDR, &data, 4);
362 }
363
364 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
365 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
366 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
367 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
368 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
369 }
370 adapter->hw_write_wx(adapter, NETXEN_WOL_PORT_MODE,
371 &wol_port_mode, 4);
372 }
373}
374
375#define PCI_CAP_ID_GEN 0x10
376
377static void netxen_pcie_strap_init(struct netxen_adapter *adapter)
378{
379 u32 pdevfuncsave;
380 u32 c8c9value = 0;
381 u32 chicken = 0;
382 u32 control = 0;
383 int i, pos;
384 struct pci_dev *pdev;
385
Dhananjay Phadke29566402008-07-21 19:44:04 -0700386 pdev = adapter->pdev;
387
388 adapter->hw_read_wx(adapter,
389 NETXEN_PCIE_REG(PCIE_CHICKEN3), &chicken, 4);
390 /* clear chicken3.25:24 */
391 chicken &= 0xFCFFFFFF;
392 /*
393 * if gen1 and B0, set F1020 - if gen 2, do nothing
394 * if gen2 set to F1000
395 */
396 pos = pci_find_capability(pdev, PCI_CAP_ID_GEN);
397 if (pos == 0xC0) {
398 pci_read_config_dword(pdev, pos + 0x10, &control);
399 if ((control & 0x000F0000) != 0x00020000) {
400 /* set chicken3.24 if gen1 */
401 chicken |= 0x01000000;
402 }
403 printk(KERN_INFO "%s Gen2 strapping detected\n",
404 netxen_nic_driver_name);
405 c8c9value = 0xF1000;
406 } else {
407 /* set chicken3.24 if gen1 */
408 chicken |= 0x01000000;
409 printk(KERN_INFO "%s Gen1 strapping detected\n",
410 netxen_nic_driver_name);
411 if (adapter->ahw.revision_id == NX_P3_B0)
412 c8c9value = 0xF1020;
413 else
414 c8c9value = 0;
415
416 }
417 adapter->hw_write_wx(adapter,
418 NETXEN_PCIE_REG(PCIE_CHICKEN3), &chicken, 4);
419
420 if (!c8c9value)
421 return;
422
423 pdevfuncsave = pdev->devfn;
424 if (pdevfuncsave & 0x07)
425 return;
426
427 for (i = 0; i < 8; i++) {
428 pci_read_config_dword(pdev, pos + 8, &control);
429 pci_read_config_dword(pdev, pos + 8, &control);
430 pci_write_config_dword(pdev, pos + 8, c8c9value);
431 pdev->devfn++;
432 }
433 pdev->devfn = pdevfuncsave;
434}
435
436static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
437{
438 u32 control;
439 int pos;
440
441 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
442 if (pos) {
443 pci_read_config_dword(pdev, pos, &control);
444 if (enable)
445 control |= PCI_MSIX_FLAGS_ENABLE;
446 else
447 control = 0;
448 pci_write_config_dword(pdev, pos, control);
449 }
450}
451
452static void netxen_init_msix_entries(struct netxen_adapter *adapter)
453{
454 int i;
455
456 for (i = 0; i < MSIX_ENTRIES_PER_ADAPTER; i++)
457 adapter->msix_entries[i].entry = i;
458}
459
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700460static int
461netxen_read_mac_addr(struct netxen_adapter *adapter)
462{
463 int i;
464 unsigned char *p;
465 __le64 mac_addr;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700466 struct net_device *netdev = adapter->netdev;
467 struct pci_dev *pdev = adapter->pdev;
468
469 if (netxen_is_flash_supported(adapter) != 0)
470 return -EIO;
471
472 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
473 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
474 return -EIO;
475 } else {
476 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
477 return -EIO;
478 }
479
480 p = (unsigned char *)&mac_addr;
481 for (i = 0; i < 6; i++)
482 netdev->dev_addr[i] = *(p + 5 - i);
483
484 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
485
486 /* set station address */
487
Johannes Berge1749612008-10-27 15:59:26 -0700488 if (!is_valid_ether_addr(netdev->perm_addr))
489 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
490 else
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700491 adapter->macaddr_set(adapter, netdev->dev_addr);
492
493 return 0;
494}
495
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800496static void netxen_set_multicast_list(struct net_device *dev)
497{
498 struct netxen_adapter *adapter = netdev_priv(dev);
499
500 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
501 netxen_p3_nic_set_multi(dev);
502 else
503 netxen_p2_nic_set_multi(dev);
504}
505
506static const struct net_device_ops netxen_netdev_ops = {
507 .ndo_open = netxen_nic_open,
508 .ndo_stop = netxen_nic_close,
509 .ndo_start_xmit = netxen_nic_xmit_frame,
510 .ndo_get_stats = netxen_nic_get_stats,
511 .ndo_validate_addr = eth_validate_addr,
512 .ndo_set_multicast_list = netxen_set_multicast_list,
513 .ndo_set_mac_address = netxen_nic_set_mac,
514 .ndo_change_mtu = netxen_nic_change_mtu,
515 .ndo_tx_timeout = netxen_tx_timeout,
516#ifdef CONFIG_NET_POLL_CONTROLLER
517 .ndo_poll_controller = netxen_nic_poll_controller,
518#endif
519};
520
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400521/*
522 * netxen_nic_probe()
523 *
524 * The Linux system will invoke this after identifying the vendor ID and
525 * device Id in the pci_tbl supported by this module.
526 *
527 * A quad port card has one operational PCI config space, (function 0),
528 * which is used to access all four ports.
529 *
530 * This routine will initialize the adapter, and setup the global parameters
531 * along with the port's specific structure.
532 */
533static int __devinit
534netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
535{
536 struct net_device *netdev = NULL;
537 struct netxen_adapter *adapter = NULL;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800538 void __iomem *mem_ptr0 = NULL;
539 void __iomem *mem_ptr1 = NULL;
540 void __iomem *mem_ptr2 = NULL;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700541 unsigned long first_page_group_end;
542 unsigned long first_page_group_start;
543
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800544
Al Viroa608ab9c2007-01-02 10:39:10 +0000545 u8 __iomem *db_ptr = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700546 unsigned long mem_base, mem_len, db_base, db_len, pci_len0 = 0;
547 int i = 0, err;
548 int first_driver, first_boot;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700549 u32 val;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700550 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700551 struct netxen_legacy_intr_set *legacy_intrp;
552 uint8_t revision_id;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400553
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700554 if (pci_func_id == 0)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700555 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700556
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700557 if (pdev->class != 0x020000) {
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700558 printk(KERN_DEBUG "NetXen function %d, class %x will not "
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700559 "be enabled.\n",pci_func_id, pdev->class);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800560 return -ENODEV;
561 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700562
Dhananjay Phadke11d89d62008-08-08 00:08:45 -0700563 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
564 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
565 "will not be enabled.\n",
566 NX_P3_A0, NX_P3_B1);
567 return -ENODEV;
568 }
569
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400570 if ((err = pci_enable_device(pdev)))
571 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700572
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400573 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
574 err = -ENODEV;
575 goto err_out_disable_pdev;
576 }
577
578 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
579 goto err_out_disable_pdev;
580
581 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700582
583 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
584 if(!netdev) {
585 printk(KERN_ERR"%s: Failed to allocate memory for the "
586 "device block.Check system memory resource"
587 " usage.\n", netxen_nic_driver_name);
588 goto err_out_free_res;
589 }
590
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700591 SET_NETDEV_DEV(netdev, &pdev->dev);
592
Wang Chen4cf16532008-11-12 23:38:14 -0800593 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700594 adapter->netdev = netdev;
595 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700596 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700597
598 revision_id = pdev->revision;
599 adapter->ahw.revision_id = revision_id;
600
601 err = nx_set_dma_mask(adapter, revision_id);
602 if (err)
603 goto err_out_free_netdev;
604
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700605 rwlock_init(&adapter->adapter_lock);
606 adapter->ahw.qdr_sn_window = -1;
607 adapter->ahw.ddr_mn_window = -1;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700608
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400609 /* remap phys address */
610 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
611 mem_len = pci_resource_len(pdev, 0);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700612 pci_len0 = 0;
613
614 adapter->hw_write_wx = netxen_nic_hw_write_wx_128M;
615 adapter->hw_read_wx = netxen_nic_hw_read_wx_128M;
616 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_128M;
617 adapter->pci_write_immediate = netxen_nic_pci_write_immediate_128M;
618 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_128M;
619 adapter->pci_write_normalize = netxen_nic_pci_write_normalize_128M;
620 adapter->pci_set_window = netxen_nic_pci_set_window_128M;
621 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M;
622 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400623
624 /* 128 Meg of memory */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700625 if (mem_len == NETXEN_PCI_128MB_SIZE) {
626 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
627 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
628 SECOND_PAGE_GROUP_SIZE);
629 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
630 THIRD_PAGE_GROUP_SIZE);
631 first_page_group_start = FIRST_PAGE_GROUP_START;
632 first_page_group_end = FIRST_PAGE_GROUP_END;
633 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
634 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
635 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
636 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
637 first_page_group_start = 0;
638 first_page_group_end = 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700639 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
640 adapter->hw_write_wx = netxen_nic_hw_write_wx_2M;
641 adapter->hw_read_wx = netxen_nic_hw_read_wx_2M;
642 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_2M;
643 adapter->pci_write_immediate =
644 netxen_nic_pci_write_immediate_2M;
645 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_2M;
646 adapter->pci_write_normalize =
647 netxen_nic_pci_write_normalize_2M;
648 adapter->pci_set_window = netxen_nic_pci_set_window_2M;
649 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M;
650 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M;
651
652 mem_ptr0 = ioremap(mem_base, mem_len);
653 pci_len0 = mem_len;
654 first_page_group_start = 0;
655 first_page_group_end = 0;
656
657 adapter->ahw.ddr_mn_window = 0;
658 adapter->ahw.qdr_sn_window = 0;
659
660 adapter->ahw.mn_win_crb = 0x100000 + PCIX_MN_WINDOW +
661 (pci_func_id * 0x20);
662 adapter->ahw.ms_win_crb = 0x100000 + PCIX_SN_WINDOW;
663 if (pci_func_id < 4)
664 adapter->ahw.ms_win_crb += (pci_func_id * 0x20);
665 else
666 adapter->ahw.ms_win_crb +=
667 0xA0 + ((pci_func_id - 4) * 0x10);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700668 } else {
Jeff Garzik47906542007-11-23 21:23:36 -0500669 err = -EIO;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700670 goto err_out_free_netdev;
671 }
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800672
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700673 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800674
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800675 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
676 db_len = pci_resource_len(pdev, 4);
677
678 if (db_len == 0) {
679 printk(KERN_ERR "%s: doorbell is disabled\n",
Dhananjay Phadke29566402008-07-21 19:44:04 -0700680 netxen_nic_driver_name);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800681 err = -EIO;
682 goto err_out_iounmap;
683 }
684 DPRINTK(INFO, "doorbell ioremap from %lx a size of %lx\n", db_base,
685 db_len);
686
687 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
Al Viroa608ab9c2007-01-02 10:39:10 +0000688 if (!db_ptr) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800689 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
Dhananjay Phadke29566402008-07-21 19:44:04 -0700690 netxen_nic_driver_name);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800691 err = -EIO;
692 goto err_out_iounmap;
693 }
694 DPRINTK(INFO, "doorbell ioremaped at %p\n", db_ptr);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400695
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700696 adapter->ahw.pci_base0 = mem_ptr0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700697 adapter->ahw.pci_len0 = pci_len0;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700698 adapter->ahw.first_page_group_start = first_page_group_start;
699 adapter->ahw.first_page_group_end = first_page_group_end;
700 adapter->ahw.pci_base1 = mem_ptr1;
701 adapter->ahw.pci_base2 = mem_ptr2;
702 adapter->ahw.db_base = db_ptr;
703 adapter->ahw.db_len = db_len;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400704
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700705 netif_napi_add(netdev, &adapter->napi,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700706 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
707
708 if (revision_id >= NX_P3_B0)
709 legacy_intrp = &legacy_intr[pci_func_id];
710 else
711 legacy_intrp = &legacy_intr[0];
712
713 adapter->legacy_intr.int_vec_bit = legacy_intrp->int_vec_bit;
714 adapter->legacy_intr.tgt_status_reg = legacy_intrp->tgt_status_reg;
715 adapter->legacy_intr.tgt_mask_reg = legacy_intrp->tgt_mask_reg;
716 adapter->legacy_intr.pci_int_reg = legacy_intrp->pci_int_reg;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700717
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +0530718 /* this will be read from FW later */
719 adapter->intr_scheme = -1;
Dhananjay Phadke443be792008-03-17 19:59:48 -0700720 adapter->msi_mode = -1;
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +0530721
722 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700723 adapter->portnum = pci_func_id;
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +0530724 adapter->status &= ~NETXEN_NETDEV_STATUS;
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530725 adapter->rx_csum = 1;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700726 adapter->mc_enabled = 0;
Dhananjay Phadke83821a02008-08-01 03:14:58 -0700727 if (NX_IS_REVISION_P3(revision_id))
Dhananjay Phadke29566402008-07-21 19:44:04 -0700728 adapter->max_mc_count = 38;
Dhananjay Phadke83821a02008-08-01 03:14:58 -0700729 else
Dhananjay Phadke29566402008-07-21 19:44:04 -0700730 adapter->max_mc_count = 16;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700731
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800732 netdev->netdev_ops = &netxen_netdev_ops;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -0700733 netdev->watchdog_timeo = 2*HZ;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700734
735 netxen_nic_change_mtu(netdev, netdev->mtu);
736
737 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800738
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800739 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
740 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
741
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700742 if (NX_IS_REVISION_P3(revision_id)) {
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800743 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
744 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700745 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700746
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800747 if (adapter->pci_using_dac) {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700748 netdev->features |= NETIF_F_HIGHDMA;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800749 netdev->vlan_features |= NETIF_F_HIGHDMA;
750 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700751
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700752 /*
753 * Set the CRB window to invalid. If any register in window 0 is
754 * accessed it should set the window to 0 and then reset it to 1.
755 */
756 adapter->curr_window = 255;
757
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700758 if (netxen_nic_get_board_info(adapter) != 0) {
759 printk("%s: Error getting board config info.\n",
Dhananjay Phadke29566402008-07-21 19:44:04 -0700760 netxen_nic_driver_name);
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700761 err = -EIO;
762 goto err_out_iounmap;
763 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700764
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700765 netxen_initialize_adapter_ops(adapter);
766
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700767 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadkedc515f22008-06-15 22:59:43 -0700768 switch (adapter->ahw.boardcfg.board_type) {
769 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
770 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
771 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700772 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -0700773 break;
774 default:
775 break;
776 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700777
Dhananjay Phadke29566402008-07-21 19:44:04 -0700778 /*
779 * This call will setup various max rx/tx counts.
780 * It must be done before any buffer/ring allocations.
781 */
782 netxen_check_options(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400783
Dhananjay Phadke29566402008-07-21 19:44:04 -0700784 first_driver = 0;
785 if (NX_IS_REVISION_P3(revision_id)) {
786 if (adapter->ahw.pci_func == 0)
787 first_driver = 1;
788 } else {
789 if (adapter->portnum == 0)
790 first_driver = 1;
791 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400792
Dhananjay Phadke29566402008-07-21 19:44:04 -0700793 if (first_driver) {
794 first_boot = adapter->pci_read_normalize(adapter,
795 NETXEN_CAM_RAM(0x1fc));
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400796
Dhananjay Phadke29566402008-07-21 19:44:04 -0700797 err = netxen_check_hw_init(adapter, first_boot);
798 if (err) {
799 printk(KERN_ERR "%s: error in init HW init sequence\n",
800 netxen_nic_driver_name);
801 goto err_out_iounmap;
802 }
803
804 if (NX_IS_REVISION_P3(revision_id))
805 netxen_set_port_mode(adapter);
806
807 if (first_boot != 0x55555555) {
808 adapter->pci_write_normalize(adapter,
809 CRB_CMDPEG_STATE, 0);
810 netxen_pinit_from_rom(adapter, 0);
811 msleep(1);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700812 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800813 netxen_load_firmware(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700814
815 if (NX_IS_REVISION_P3(revision_id))
816 netxen_pcie_strap_init(adapter);
817
818 if (NX_IS_REVISION_P2(revision_id)) {
819
820 /* Initialize multicast addr pool owners */
821 val = 0x7654;
822 if (adapter->ahw.board_type == NETXEN_NIC_XGBE)
823 val |= 0x0f000000;
824 netxen_crb_writelit_adapter(adapter,
825 NETXEN_MAC_ADDR_CNTL_REG, val);
826
827 }
828
Dhananjay Phadke29566402008-07-21 19:44:04 -0700829 err = netxen_initialize_adapter_offload(adapter);
830 if (err)
831 goto err_out_iounmap;
832
833 /*
834 * Tell the hardware our version number.
835 */
836 i = (_NETXEN_NIC_LINUX_MAJOR << 16)
837 | ((_NETXEN_NIC_LINUX_MINOR << 8))
838 | (_NETXEN_NIC_LINUX_SUBVERSION);
839 adapter->pci_write_normalize(adapter, CRB_DRIVER_VERSION, i);
840
841 /* Handshake with the card before we register the devices. */
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800842 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
843 if (err)
844 goto err_out_free_offload;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700845
Dhananjay Phadke29566402008-07-21 19:44:04 -0700846 } /* first_driver */
847
848 netxen_nic_flash_print(adapter);
849
Dhananjay Phadked9e651b2008-07-21 19:44:08 -0700850 if (NX_IS_REVISION_P3(revision_id)) {
851 adapter->hw_read_wx(adapter,
852 NETXEN_MIU_MN_CONTROL, &val, 4);
853 adapter->ahw.cut_through = (val & 0x4) ? 1 : 0;
854 dev_info(&pdev->dev, "firmware running in %s mode\n",
855 adapter->ahw.cut_through ? "cut through" : "legacy");
856 }
857
Dhananjay Phadke29566402008-07-21 19:44:04 -0700858 /*
859 * See if the firmware gave us a virtual-physical port mapping.
860 */
861 adapter->physical_port = adapter->portnum;
862 i = adapter->pci_read_normalize(adapter, CRB_V2P(adapter->portnum));
863 if (i != 0x55555555)
864 adapter->physical_port = i;
865
866 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
867
868 netxen_set_msix_bit(pdev, 0);
869
870 if (NX_IS_REVISION_P3(revision_id)) {
871 if ((mem_len != NETXEN_PCI_128MB_SIZE) &&
872 mem_len != NETXEN_PCI_2MB_SIZE)
873 adapter->msix_supported = 0;
874 }
875
876 if (adapter->msix_supported) {
877
878 netxen_init_msix_entries(adapter);
879
880 if (pci_enable_msix(pdev, adapter->msix_entries,
881 MSIX_ENTRIES_PER_ADAPTER))
882 goto request_msi;
883
884 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
885 netxen_set_msix_bit(pdev, 1);
886 dev_info(&pdev->dev, "using msi-x interrupts\n");
887
888 } else {
889request_msi:
890 if (use_msi && !pci_enable_msi(pdev)) {
891 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
892 dev_info(&pdev->dev, "using msi interrupts\n");
893 } else
894 dev_info(&pdev->dev, "using legacy interrupts\n");
895 }
896
897 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
898 netdev->irq = adapter->msix_entries[0].vector;
899 else
900 netdev->irq = pdev->irq;
901
902 err = netxen_receive_peg_ready(adapter);
903 if (err)
904 goto err_out_disable_msi;
905
906 init_timer(&adapter->watchdog_timer);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700907 adapter->watchdog_timer.function = &netxen_watchdog;
908 adapter->watchdog_timer.data = (unsigned long)adapter;
909 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
910 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
911
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700912 err = netxen_read_mac_addr(adapter);
913 if (err)
914 dev_warn(&pdev->dev, "failed to read mac addr\n");
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700915
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700916 netif_carrier_off(netdev);
917 netif_stop_queue(netdev);
918
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700919 if ((err = register_netdev(netdev))) {
920 printk(KERN_ERR "%s: register_netdev failed port #%d"
921 " aborting\n", netxen_nic_driver_name,
922 adapter->portnum);
923 err = -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700924 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700925 }
926
927 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400928
Dhananjay Phadke29566402008-07-21 19:44:04 -0700929 switch (adapter->ahw.board_type) {
930 case NETXEN_NIC_GBE:
931 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
932 adapter->netdev->name);
933 break;
934 case NETXEN_NIC_XGBE:
935 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
936 adapter->netdev->name);
937 break;
938 }
939
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400940 return 0;
941
Dhananjay Phadke29566402008-07-21 19:44:04 -0700942err_out_disable_msi:
943 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
944 pci_disable_msix(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700945 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
946 pci_disable_msi(pdev);
947
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800948err_out_free_offload:
Dhananjay Phadke29566402008-07-21 19:44:04 -0700949 if (first_driver)
950 netxen_free_adapter_offload(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400951
Dhananjay Phadke29566402008-07-21 19:44:04 -0700952err_out_iounmap:
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800953 if (db_ptr)
954 iounmap(db_ptr);
955
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800956 if (mem_ptr0)
957 iounmap(mem_ptr0);
958 if (mem_ptr1)
959 iounmap(mem_ptr1);
960 if (mem_ptr2)
961 iounmap(mem_ptr2);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800962
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700963err_out_free_netdev:
964 free_netdev(netdev);
965
966err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400967 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700968
969err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -0700970 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400971 pci_disable_device(pdev);
972 return err;
973}
974
975static void __devexit netxen_nic_remove(struct pci_dev *pdev)
976{
977 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700978 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400979
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700980 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400981 if (adapter == NULL)
982 return;
983
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700984 netdev = adapter->netdev;
985
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530986 unregister_netdev(netdev);
987
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530988 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400989 netxen_free_hw_resources(adapter);
Dhananjay Phadke9e410772008-08-08 00:08:40 -0700990 netxen_release_rx_buffers(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700991 netxen_free_sw_resources(adapter);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -0800992
993 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
994 netxen_p3_free_mac_list(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530995 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400996
Dhananjay Phadke439b4542008-06-15 22:59:46 -0700997 if (adapter->portnum == 0)
998 netxen_free_adapter_offload(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +0530999
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301000 if (adapter->irq)
1001 free_irq(adapter->irq, adapter);
1002
Dhananjay Phadke29566402008-07-21 19:44:04 -07001003 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
1004 pci_disable_msix(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301005 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
1006 pci_disable_msi(pdev);
1007
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001008 iounmap(adapter->ahw.db_base);
1009 iounmap(adapter->ahw.pci_base0);
Dhananjay Phadke3bfafd62009-01-16 11:03:01 -08001010 if (adapter->ahw.pci_base1 != NULL)
1011 iounmap(adapter->ahw.pci_base1);
1012 if (adapter->ahw.pci_base2 != NULL)
1013 iounmap(adapter->ahw.pci_base2);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001014
1015 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301016 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001017 pci_set_drvdata(pdev, NULL);
1018
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001019 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001020}
1021
1022/*
1023 * Called when a network interface is made active
1024 * @returns 0 on success, negative value on failure
1025 */
1026static int netxen_nic_open(struct net_device *netdev)
1027{
Wang Chen4cf16532008-11-12 23:38:14 -08001028 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001029 int err = 0;
1030 int ctx, ring;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001031 irq_handler_t handler;
1032 unsigned long flags = IRQF_SAMPLE_RANDOM;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001033
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001034 if (adapter->driver_mismatch)
1035 return -EIO;
1036
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001037 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) {
1038 err = netxen_init_firmware(adapter);
1039 if (err != 0) {
1040 printk(KERN_ERR "Failed to init firmware\n");
1041 return -EIO;
1042 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001043
Dhananjay Phadke83821a02008-08-01 03:14:58 -07001044 if (adapter->fw_major < 4)
1045 adapter->max_rds_rings = 3;
1046 else
1047 adapter->max_rds_rings = 2;
1048
Dhananjay Phadke29566402008-07-21 19:44:04 -07001049 err = netxen_alloc_sw_resources(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001050 if (err) {
Dhananjay Phadke29566402008-07-21 19:44:04 -07001051 printk(KERN_ERR "%s: Error in setting sw resources\n",
1052 netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001053 return err;
1054 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001055
1056 netxen_nic_clear_stats(adapter);
1057
1058 err = netxen_alloc_hw_resources(adapter);
1059 if (err) {
1060 printk(KERN_ERR "%s: Error in setting hw resources\n",
1061 netdev->name);
1062 goto err_out_free_sw;
1063 }
1064
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001065 if ((adapter->msi_mode != MSI_MODE_MULTIFUNC) ||
1066 (adapter->intr_scheme != INTR_SCHEME_PERPORT)) {
1067 printk(KERN_ERR "%s: Firmware interrupt scheme is "
1068 "incompatible with driver\n",
1069 netdev->name);
1070 adapter->driver_mismatch = 1;
1071 goto err_out_free_hw;
1072 }
1073
Dhananjay Phadke29566402008-07-21 19:44:04 -07001074 if (adapter->fw_major < 4) {
1075 adapter->crb_addr_cmd_producer =
1076 crb_cmd_producer[adapter->portnum];
1077 adapter->crb_addr_cmd_consumer =
1078 crb_cmd_consumer[adapter->portnum];
Dhananjay Phadke29566402008-07-21 19:44:04 -07001079
Dhananjay Phadke83821a02008-08-01 03:14:58 -07001080 netxen_nic_update_cmd_producer(adapter, 0);
1081 netxen_nic_update_cmd_consumer(adapter, 0);
1082 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001083
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001084 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001085 for (ring = 0; ring < adapter->max_rds_rings; ring++)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001086 netxen_post_rx_buffers(adapter, ctx, ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001087 }
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001088 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
1089 handler = netxen_msix_intr;
1090 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001091 handler = netxen_msi_intr;
1092 else {
1093 flags |= IRQF_SHARED;
1094 handler = netxen_intr;
1095 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001096 adapter->irq = netdev->irq;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001097 err = request_irq(adapter->irq, handler,
1098 flags, netdev->name, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001099 if (err) {
1100 printk(KERN_ERR "request_irq failed with: %d\n", err);
Dhananjay Phadke9e410772008-08-08 00:08:40 -07001101 goto err_out_free_rxbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001102 }
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001103
1104 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1105 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001106
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001107 /* Done here again so that even if phantom sw overwrote it,
1108 * we set it */
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001109 err = adapter->init_port(adapter, adapter->physical_port);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001110 if (err) {
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001111 printk(KERN_ERR "%s: Failed to initialize port %d\n",
1112 netxen_nic_driver_name, adapter->portnum);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001113 goto err_out_free_irq;
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001114 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001115 adapter->macaddr_set(adapter, netdev->dev_addr);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001116
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001117 netxen_nic_set_link_parameters(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001118
Stephen Hemminger1abd2662008-11-21 17:32:15 -08001119 netxen_set_multicast_list(netdev);
Dhananjay Phadke9ad27642008-08-01 03:14:59 -07001120 if (adapter->set_mtu)
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001121 adapter->set_mtu(adapter, netdev->mtu);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001122
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001123 adapter->ahw.linkup = 0;
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001124 mod_timer(&adapter->watchdog_timer, jiffies);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001125
1126 napi_enable(&adapter->napi);
1127 netxen_nic_enable_int(adapter);
1128
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001129 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001130
1131 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001132
1133err_out_free_irq:
1134 free_irq(adapter->irq, adapter);
Dhananjay Phadke9e410772008-08-08 00:08:40 -07001135err_out_free_rxbuf:
1136 netxen_release_rx_buffers(adapter);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001137err_out_free_hw:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001138 netxen_free_hw_resources(adapter);
1139err_out_free_sw:
1140 netxen_free_sw_resources(adapter);
1141 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001142}
1143
1144/*
1145 * netxen_nic_close - Disables a network interface entry point
1146 */
1147static int netxen_nic_close(struct net_device *netdev)
1148{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001149 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001150
1151 netif_carrier_off(netdev);
1152 netif_stop_queue(netdev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001153 napi_disable(&adapter->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001154
dhananjay@netxen.com72b0a7a2007-12-26 10:23:56 -08001155 if (adapter->stop_port)
1156 adapter->stop_port(adapter);
1157
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301158 netxen_nic_disable_int(adapter);
1159
Dhananjay Phadke29566402008-07-21 19:44:04 -07001160 netxen_release_tx_buffers(adapter);
1161
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001162 FLUSH_SCHEDULED_WORK();
1163 del_timer_sync(&adapter->watchdog_timer);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001164
1165 return 0;
1166}
1167
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001168static bool netxen_tso_check(struct net_device *netdev,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001169 struct cmd_desc_type0 *desc, struct sk_buff *skb)
1170{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001171 bool tso = false;
1172 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001173 __be16 protocol = skb->protocol;
1174 u16 flags = 0;
1175
1176 if (protocol == __constant_htons(ETH_P_8021Q)) {
1177 struct vlan_ethhdr *vh = (struct vlan_ethhdr *)skb->data;
1178 protocol = vh->h_vlan_encapsulated_proto;
1179 flags = FLAGS_VLAN_TAGGED;
1180 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001181
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001182 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1183 skb_shinfo(skb)->gso_size > 0) {
1184
1185 desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1186 desc->total_hdr_length =
1187 skb_transport_offset(skb) + tcp_hdrlen(skb);
1188
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001189 opcode = (protocol == __constant_htons(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001190 TX_TCP_LSO6 : TX_TCP_LSO;
1191 tso = true;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001192
1193 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001194 u8 l4proto;
1195
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001196 if (protocol == __constant_htons(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001197 l4proto = ip_hdr(skb)->protocol;
1198
1199 if (l4proto == IPPROTO_TCP)
1200 opcode = TX_TCP_PKT;
1201 else if(l4proto == IPPROTO_UDP)
1202 opcode = TX_UDP_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001203 } else if (protocol == __constant_htons(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001204 l4proto = ipv6_hdr(skb)->nexthdr;
1205
1206 if (l4proto == IPPROTO_TCP)
1207 opcode = TX_TCPV6_PKT;
1208 else if(l4proto == IPPROTO_UDP)
1209 opcode = TX_UDPV6_PKT;
1210 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001211 }
1212 desc->tcp_hdr_offset = skb_transport_offset(skb);
1213 desc->ip_hdr_offset = skb_network_offset(skb);
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001214 netxen_set_tx_flags_opcode(desc, flags, opcode);
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001215 return tso;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001216}
1217
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001218static void
1219netxen_clean_tx_dma_mapping(struct pci_dev *pdev,
1220 struct netxen_cmd_buffer *pbuf, int last)
1221{
1222 int k;
1223 struct netxen_skb_frag *buffrag;
1224
1225 buffrag = &pbuf->frag_array[0];
1226 pci_unmap_single(pdev, buffrag->dma,
1227 buffrag->length, PCI_DMA_TODEVICE);
1228
1229 for (k = 1; k < last; k++) {
1230 buffrag = &pbuf->frag_array[k];
1231 pci_unmap_page(pdev, buffrag->dma,
1232 buffrag->length, PCI_DMA_TODEVICE);
1233 }
1234}
1235
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001236static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1237{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001238 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001239 struct netxen_hardware_context *hw = &adapter->ahw;
1240 unsigned int first_seg_len = skb->len - skb->data_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001241 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001242 struct netxen_skb_frag *buffrag;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001243 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001244 struct pci_dev *pdev = adapter->pdev;
1245 dma_addr_t temp_dma;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001246 int i, k;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001247
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001248 u32 producer, consumer;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001249 int frag_count, no_of_desc;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001250 u32 num_txd = adapter->max_tx_desc_count;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001251 bool is_tso = false;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001252
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001253 frag_count = skb_shinfo(skb)->nr_frags + 1;
1254
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001255 /* There 4 fragments per descriptor */
1256 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001257
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001258 producer = adapter->cmd_producer;
1259 smp_mb();
1260 consumer = adapter->last_cmd_consumer;
1261 if ((no_of_desc+2) > find_diff_among(producer, consumer, num_txd)) {
1262 netif_stop_queue(netdev);
1263 smp_mb();
1264 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001265 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001266
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001267 /* Copy the descriptors into the hardware */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001268 hwdesc = &hw->cmd_desc_head[producer];
1269 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
1270 /* Take skb->data itself */
1271 pbuf = &adapter->cmd_buf_arr[producer];
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001272
1273 is_tso = netxen_tso_check(netdev, hwdesc, skb);
1274
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001275 pbuf->skb = skb;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001276 pbuf->frag_count = frag_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001277 buffrag = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001278 temp_dma = pci_map_single(pdev, skb->data, first_seg_len,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001279 PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001280 if (pci_dma_mapping_error(pdev, temp_dma))
1281 goto drop_packet;
1282
1283 buffrag->dma = temp_dma;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001284 buffrag->length = first_seg_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001285 netxen_set_tx_frags_len(hwdesc, frag_count, skb->len);
1286 netxen_set_tx_port(hwdesc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001287
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001288 hwdesc->buffer1_length = cpu_to_le16(first_seg_len);
1289 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
1290
1291 for (i = 1, k = 1; i < frag_count; i++, k++) {
1292 struct skb_frag_struct *frag;
1293 int len, temp_len;
1294 unsigned long offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001295
1296 /* move to next desc. if there is a need */
1297 if ((i & 0x3) == 0) {
1298 k = 0;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001299 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001300 hwdesc = &hw->cmd_desc_head[producer];
1301 memset(hwdesc, 0, sizeof(struct cmd_desc_type0));
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001302 pbuf = &adapter->cmd_buf_arr[producer];
1303 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001304 }
1305 frag = &skb_shinfo(skb)->frags[i - 1];
1306 len = frag->size;
1307 offset = frag->page_offset;
1308
1309 temp_len = len;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001310 temp_dma = pci_map_page(pdev, frag->page, offset,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001311 len, PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001312 if (pci_dma_mapping_error(pdev, temp_dma)) {
1313 netxen_clean_tx_dma_mapping(pdev, pbuf, i);
1314 goto drop_packet;
1315 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001316
1317 buffrag++;
1318 buffrag->dma = temp_dma;
1319 buffrag->length = temp_len;
1320
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001321 switch (k) {
1322 case 0:
1323 hwdesc->buffer1_length = cpu_to_le16(temp_len);
1324 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
1325 break;
1326 case 1:
1327 hwdesc->buffer2_length = cpu_to_le16(temp_len);
1328 hwdesc->addr_buffer2 = cpu_to_le64(temp_dma);
1329 break;
1330 case 2:
1331 hwdesc->buffer3_length = cpu_to_le16(temp_len);
1332 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
1333 break;
1334 case 3:
Al Viroa608ab9c2007-01-02 10:39:10 +00001335 hwdesc->buffer4_length = cpu_to_le16(temp_len);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001336 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
1337 break;
1338 }
1339 frag++;
1340 }
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001341 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001342
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001343 /* For LSO, we need to copy the MAC/IP/TCP headers into
1344 * the descriptor ring
1345 */
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001346 if (is_tso) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001347 int hdr_len, first_hdr_len, more_hdr;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001348 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001349 if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) {
1350 first_hdr_len = sizeof(struct cmd_desc_type0) - 2;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001351 more_hdr = 1;
1352 } else {
1353 first_hdr_len = hdr_len;
1354 more_hdr = 0;
1355 }
1356 /* copy the MAC/IP/TCP headers to the cmd descriptor list */
1357 hwdesc = &hw->cmd_desc_head[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001358 pbuf = &adapter->cmd_buf_arr[producer];
1359 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001360
1361 /* copy the first 64 bytes */
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001362 memcpy(((void *)hwdesc) + 2,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001363 (void *)(skb->data), first_hdr_len);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001364 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001365
1366 if (more_hdr) {
1367 hwdesc = &hw->cmd_desc_head[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001368 pbuf = &adapter->cmd_buf_arr[producer];
1369 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001370 /* copy the next 64 bytes - should be enough except
1371 * for pathological case
1372 */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001373 skb_copy_from_linear_data_offset(skb, first_hdr_len,
1374 hwdesc,
1375 (hdr_len -
1376 first_hdr_len));
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001377 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001378 }
1379 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001380
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001381 adapter->cmd_producer = producer;
Dhananjay Phadke5dc16262007-12-31 10:08:57 -08001382 adapter->stats.txbytes += skb->len;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001383
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001384 netxen_nic_update_cmd_producer(adapter, adapter->cmd_producer);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001385
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001386 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001387 netdev->trans_start = jiffies;
1388
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001389 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001390
1391drop_packet:
1392 adapter->stats.txdropped++;
1393 dev_kfree_skb_any(skb);
1394 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001395}
1396
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001397static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1398{
1399 struct net_device *netdev = adapter->netdev;
1400 uint32_t temp, temp_state, temp_val;
1401 int rv = 0;
1402
1403 temp = adapter->pci_read_normalize(adapter, CRB_TEMP_STATE);
1404
1405 temp_state = nx_get_temp_state(temp);
1406 temp_val = nx_get_temp_val(temp);
1407
1408 if (temp_state == NX_TEMP_PANIC) {
1409 printk(KERN_ALERT
1410 "%s: Device temperature %d degrees C exceeds"
1411 " maximum allowed. Hardware has been shut down.\n",
1412 netxen_nic_driver_name, temp_val);
1413
1414 netif_carrier_off(netdev);
1415 netif_stop_queue(netdev);
1416 rv = 1;
1417 } else if (temp_state == NX_TEMP_WARN) {
1418 if (adapter->temp == NX_TEMP_NORMAL) {
1419 printk(KERN_ALERT
1420 "%s: Device temperature %d degrees C "
1421 "exceeds operating range."
1422 " Immediate action needed.\n",
1423 netxen_nic_driver_name, temp_val);
1424 }
1425 } else {
1426 if (adapter->temp == NX_TEMP_WARN) {
1427 printk(KERN_INFO
1428 "%s: Device temperature is now %d degrees C"
1429 " in normal range.\n", netxen_nic_driver_name,
1430 temp_val);
1431 }
1432 }
1433 adapter->temp = temp_state;
1434 return rv;
1435}
1436
1437static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1438{
1439 struct net_device *netdev = adapter->netdev;
1440 u32 val, port, linkup;
1441
1442 port = adapter->physical_port;
1443
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001444 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1445 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE_P3);
1446 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1447 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001448 } else {
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001449 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
1450 if (adapter->ahw.board_type == NETXEN_NIC_GBE)
1451 linkup = (val >> port) & 1;
1452 else {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001453 val = (val >> port*8) & 0xff;
1454 linkup = (val == XG_LINK_UP);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001455 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001456 }
1457
1458 if (adapter->ahw.linkup && !linkup) {
1459 printk(KERN_INFO "%s: %s NIC Link is down\n",
1460 netxen_nic_driver_name, netdev->name);
1461 adapter->ahw.linkup = 0;
1462 if (netif_running(netdev)) {
1463 netif_carrier_off(netdev);
1464 netif_stop_queue(netdev);
1465 }
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001466
1467 netxen_nic_set_link_parameters(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001468 } else if (!adapter->ahw.linkup && linkup) {
1469 printk(KERN_INFO "%s: %s NIC Link is up\n",
1470 netxen_nic_driver_name, netdev->name);
1471 adapter->ahw.linkup = 1;
1472 if (netif_running(netdev)) {
1473 netif_carrier_on(netdev);
1474 netif_wake_queue(netdev);
1475 }
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001476
1477 netxen_nic_set_link_parameters(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001478 }
1479}
1480
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001481static void netxen_watchdog(unsigned long v)
1482{
1483 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001484
1485 SCHEDULE_WORK(&adapter->watchdog_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001486}
1487
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001488void netxen_watchdog_task(struct work_struct *work)
1489{
1490 struct netxen_adapter *adapter =
1491 container_of(work, struct netxen_adapter, watchdog_task);
1492
1493 if ((adapter->portnum == 0) && netxen_nic_check_temp(adapter))
1494 return;
1495
1496 netxen_nic_handle_phy_intr(adapter);
1497
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001498 if (netif_running(adapter->netdev))
1499 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001500}
1501
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001502static void netxen_tx_timeout(struct net_device *netdev)
1503{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001504 struct netxen_adapter *adapter = (struct netxen_adapter *)
1505 netdev_priv(netdev);
1506 SCHEDULE_WORK(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001507}
1508
David Howells6d5aefb2006-12-05 19:36:26 +00001509static void netxen_tx_timeout_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001510{
Jeff Garzik47906542007-11-23 21:23:36 -05001511 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001512 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001513
1514 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001515 netxen_nic_driver_name, adapter->netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001516
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001517 netxen_nic_disable_int(adapter);
1518 napi_disable(&adapter->napi);
1519
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001520 adapter->netdev->trans_start = jiffies;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001521
1522 napi_enable(&adapter->napi);
1523 netxen_nic_enable_int(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001524 netif_wake_queue(adapter->netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001525}
1526
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001527/*
1528 * netxen_nic_get_stats - Get System Network Statistics
1529 * @netdev: network interface device structure
1530 */
1531struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1532{
1533 struct netxen_adapter *adapter = netdev_priv(netdev);
1534 struct net_device_stats *stats = &adapter->net_stats;
1535
1536 memset(stats, 0, sizeof(*stats));
1537
1538 /* total packets received */
1539 stats->rx_packets = adapter->stats.no_rcv;
1540 /* total packets transmitted */
1541 stats->tx_packets = adapter->stats.xmitedframes +
1542 adapter->stats.xmitfinished;
1543 /* total bytes received */
1544 stats->rx_bytes = adapter->stats.rxbytes;
1545 /* total bytes transmitted */
1546 stats->tx_bytes = adapter->stats.txbytes;
1547 /* bad packets received */
1548 stats->rx_errors = adapter->stats.rcvdbadskb;
1549 /* packet transmit problems */
1550 stats->tx_errors = adapter->stats.nocmddescriptor;
1551 /* no space in linux buffers */
1552 stats->rx_dropped = adapter->stats.rxdropped;
1553 /* no space available in linux */
1554 stats->tx_dropped = adapter->stats.txdropped;
1555
1556 return stats;
1557}
1558
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001559static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001560{
Jeff Garzik1daec862007-10-19 03:14:03 -04001561 struct netxen_adapter *adapter = data;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001562 u32 status = 0;
1563
1564 status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1565
1566 if (!(status & adapter->legacy_intr.int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001567 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301568
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001569 if (adapter->ahw.revision_id >= NX_P3_B1) {
1570 /* check interrupt state machine, to be sure */
1571 status = adapter->pci_read_immediate(adapter,
1572 ISR_INT_STATE_REG);
1573 if (!ISR_LEGACY_INT_TRIGGERED(status))
1574 return IRQ_NONE;
1575
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001576 } else {
1577 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001578
1579 our_int = adapter->pci_read_normalize(adapter, CRB_INT_VECTOR);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001580
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001581 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001582 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001583 return IRQ_NONE;
1584
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001585 /* claim interrupt */
1586 adapter->pci_write_normalize(adapter,
1587 CRB_INT_VECTOR, (our_int & 0xffffffff));
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301588 }
1589
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001590 /* clear interrupt */
1591 if (adapter->fw_major < 4)
1592 netxen_nic_disable_int(adapter);
1593
1594 adapter->pci_write_immediate(adapter,
1595 adapter->legacy_intr.tgt_status_reg,
1596 0xffffffff);
1597 /* read twice to ensure write is flushed */
1598 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1599 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1600
1601 napi_schedule(&adapter->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001602
1603 return IRQ_HANDLED;
1604}
1605
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001606static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001607{
1608 struct netxen_adapter *adapter = data;
1609
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001610 /* clear interrupt */
1611 adapter->pci_write_immediate(adapter,
1612 msi_tgt_status[adapter->ahw.pci_func], 0xffffffff);
1613
1614 napi_schedule(&adapter->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001615 return IRQ_HANDLED;
1616}
1617
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001618static irqreturn_t netxen_msix_intr(int irq, void *data)
1619{
1620 struct netxen_adapter *adapter = data;
1621
1622 napi_schedule(&adapter->napi);
1623 return IRQ_HANDLED;
1624}
1625
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001626static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001627{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001628 struct netxen_adapter *adapter = container_of(napi, struct netxen_adapter, napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001629 int tx_complete;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001630 int ctx;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001631 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001632
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001633 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001634
Amit S. Kale80922fb2006-12-04 09:18:00 -08001635 work_done = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001636 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
1637 /*
1638 * Fairness issue. This will give undue weight to the
1639 * receive context 0.
1640 */
1641
1642 /*
1643 * To avoid starvation, we give each of our receivers,
1644 * a fraction of the quota. Sometimes, it might happen that we
1645 * have enough quota to process every packet, but since all the
1646 * packets are on one context, it gets only half of the quota,
1647 * and ends up not processing it.
1648 */
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001649 work_done += netxen_process_rcv_ring(adapter, ctx,
1650 budget / MAX_RCV_CTX);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001651 }
1652
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001653 if ((work_done < budget) && tx_complete) {
Neil Horman908a7a12008-12-22 20:43:12 -08001654 netif_rx_complete(&adapter->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001655 netxen_nic_enable_int(adapter);
1656 }
1657
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001658 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001659}
1660
1661#ifdef CONFIG_NET_POLL_CONTROLLER
1662static void netxen_nic_poll_controller(struct net_device *netdev)
1663{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001664 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001665 disable_irq(adapter->irq);
Jeff Garzik1494a812006-11-07 05:12:16 -05001666 netxen_intr(adapter->irq, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001667 enable_irq(adapter->irq);
1668}
1669#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001670
1671static struct pci_driver netxen_driver = {
1672 .name = netxen_nic_driver_name,
1673 .id_table = netxen_pci_tbl,
1674 .probe = netxen_nic_probe,
1675 .remove = __devexit_p(netxen_nic_remove)
1676};
1677
1678/* Driver Registration on NetXen card */
1679
1680static int __init netxen_init_module(void)
1681{
Al Viro79ea13c2008-01-24 02:06:46 -08001682 if ((netxen_workq = create_singlethread_workqueue("netxen")) == NULL)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001683 return -ENOMEM;
1684
Amit S. Kale184231b2007-01-22 06:52:53 -08001685 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001686}
1687
1688module_init(netxen_init_module);
1689
1690static void __exit netxen_exit_module(void)
1691{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001692 pci_unregister_driver(&netxen_driver);
Amit S. Kale9de06612007-02-21 06:37:06 -08001693 destroy_workqueue(netxen_workq);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001694}
1695
1696module_exit(netxen_exit_module);