blob: 853dee8057d95e90b0305b615aaa555d15d30e6b [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>
Dhananjay Phadkee98e3352009-04-07 22:50:38 +000032#include <linux/interrupt.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 +030097static struct workqueue_struct *netxen_workq;
98#define SCHEDULE_WORK(tp) queue_work(netxen_workq, tp)
99#define FLUSH_SCHEDULED_WORK() flush_workqueue(netxen_workq)
100
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800101static void netxen_watchdog(unsigned long);
102
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700103static uint32_t crb_cmd_producer[4] = {
104 CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1,
105 CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3
106};
107
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700108void
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700109netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
110 uint32_t crb_producer)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700111{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700112 adapter->pci_write_normalize(adapter,
113 adapter->crb_addr_cmd_producer, crb_producer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700114}
115
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700116static uint32_t crb_cmd_consumer[4] = {
117 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
118 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
119};
120
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700121static inline void
122netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
123 u32 crb_consumer)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700124{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700125 adapter->pci_write_normalize(adapter,
126 adapter->crb_addr_cmd_consumer, crb_consumer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700127}
128
Dhananjay Phadke29566402008-07-21 19:44:04 -0700129static uint32_t msi_tgt_status[8] = {
Dhananjay Phadke443be792008-03-17 19:59:48 -0700130 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700131 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
132 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
133 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
Dhananjay Phadke443be792008-03-17 19:59:48 -0700134};
135
Dhananjay Phadke29566402008-07-21 19:44:04 -0700136static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
137
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000138static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700139{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000140 struct netxen_adapter *adapter = sds_ring->adapter;
141
142 adapter->pci_write_normalize(adapter, sds_ring->crb_intr_mask, 0);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700143}
144
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000145static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700146{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000147 struct netxen_adapter *adapter = sds_ring->adapter;
148
149 adapter->pci_write_normalize(adapter, sds_ring->crb_intr_mask, 0x1);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700150
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700151 if (!NETXEN_IS_MSI_FAMILY(adapter))
152 adapter->pci_write_immediate(adapter,
153 adapter->legacy_intr.tgt_mask_reg, 0xfbff);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700154}
155
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000156static void
157netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
158{
159 int ring;
160 struct nx_host_sds_ring *sds_ring;
161 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
162
163 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
164 adapter->max_sds_rings = (num_online_cpus() >= 4) ? 4 : 2;
165 else
166 adapter->max_sds_rings = 1;
167
168 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
169 sds_ring = &recv_ctx->sds_rings[ring];
170 netif_napi_add(netdev, &sds_ring->napi,
171 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
172 }
173}
174
175static void
176netxen_napi_enable(struct netxen_adapter *adapter)
177{
178 int ring;
179 struct nx_host_sds_ring *sds_ring;
180 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
181
182 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
183 sds_ring = &recv_ctx->sds_rings[ring];
184 napi_enable(&sds_ring->napi);
185 netxen_nic_enable_int(sds_ring);
186 }
187}
188
189static void
190netxen_napi_disable(struct netxen_adapter *adapter)
191{
192 int ring;
193 struct nx_host_sds_ring *sds_ring;
194 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
195
196 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
197 sds_ring = &recv_ctx->sds_rings[ring];
198 netxen_nic_disable_int(sds_ring);
199 napi_disable(&sds_ring->napi);
200 }
201}
202
Dhananjay Phadke29566402008-07-21 19:44:04 -0700203static int nx_set_dma_mask(struct netxen_adapter *adapter, uint8_t revision_id)
204{
205 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000206 uint64_t mask, cmask;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700207
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000208 adapter->pci_using_dac = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700209
Yang Hongyang6afd1422009-04-06 19:01:15 -0700210 mask = DMA_BIT_MASK(32);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700211 /*
212 * Consistent DMA mask is set to 32 bit because it cannot be set to
213 * 35 bits. For P3 also leave it at 32 bits for now. Only the rings
214 * come off this pool.
215 */
Yang Hongyang6afd1422009-04-06 19:01:15 -0700216 cmask = DMA_BIT_MASK(32);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000217
218#ifndef CONFIG_IA64
219 if (revision_id >= NX_P3_B0)
Yang Hongyang6afd1422009-04-06 19:01:15 -0700220 mask = DMA_BIT_MASK(39);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000221 else if (revision_id == NX_P2_C1)
Yang Hongyang6afd1422009-04-06 19:01:15 -0700222 mask = DMA_BIT_MASK(35);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000223#endif
Dhananjay Phadke29566402008-07-21 19:44:04 -0700224 if (pci_set_dma_mask(pdev, mask) == 0 &&
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000225 pci_set_consistent_dma_mask(pdev, cmask) == 0) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700226 adapter->pci_using_dac = 1;
227 return 0;
228 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700229
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000230 return -EIO;
231}
232
233/* Update addressable range if firmware supports it */
234static int
235nx_update_dma_mask(struct netxen_adapter *adapter)
236{
237 int change, shift, err;
238 uint64_t mask, old_mask;
239 struct pci_dev *pdev = adapter->pdev;
240
241 change = 0;
242
243 shift = netxen_nic_reg_read(adapter, CRB_DMA_SHIFT);
244 if (shift >= 32)
245 return 0;
246
247 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9))
248 change = 1;
249 else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4))
250 change = 1;
251
252 if (change) {
253 old_mask = pdev->dma_mask;
254 mask = (1ULL<<(32+shift)) - 1;
255
256 err = pci_set_dma_mask(pdev, mask);
257 if (err)
258 return pci_set_dma_mask(pdev, old_mask);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700259 }
260
Dhananjay Phadke29566402008-07-21 19:44:04 -0700261 return 0;
262}
263
264static void netxen_check_options(struct netxen_adapter *adapter)
265{
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000266 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
267 adapter->num_rxd = MAX_RCV_DESCRIPTORS_10G;
268 else if (adapter->ahw.port_type == NETXEN_NIC_GBE)
269 adapter->num_rxd = MAX_RCV_DESCRIPTORS_1G;
270
271 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
Dhananjay Phadke29566402008-07-21 19:44:04 -0700272 adapter->msix_supported = !!use_msi_x;
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000273 else
Dhananjay Phadke29566402008-07-21 19:44:04 -0700274 adapter->msix_supported = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700275
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000276 adapter->num_txd = MAX_CMD_DESCRIPTORS_HOST;
277 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS;
278 adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700279
Dhananjay Phadke29566402008-07-21 19:44:04 -0700280 return;
281}
282
283static int
284netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
285{
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800286 u32 val, timeout;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700287
288 if (first_boot == 0x55555555) {
289 /* This is the first boot after power up */
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800290 adapter->pci_write_normalize(adapter,
291 NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
292
293 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
294 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700295
296 /* PCI bus master workaround */
297 adapter->hw_read_wx(adapter,
298 NETXEN_PCIE_REG(0x4), &first_boot, 4);
299 if (!(first_boot & 0x4)) {
300 first_boot |= 0x4;
301 adapter->hw_write_wx(adapter,
302 NETXEN_PCIE_REG(0x4), &first_boot, 4);
303 adapter->hw_read_wx(adapter,
304 NETXEN_PCIE_REG(0x4), &first_boot, 4);
305 }
306
307 /* This is the first boot after power up */
308 adapter->hw_read_wx(adapter,
309 NETXEN_ROMUSB_GLB_SW_RESET, &first_boot, 4);
310 if (first_boot != 0x80000f) {
311 /* clear the register for future unloads/loads */
312 adapter->pci_write_normalize(adapter,
313 NETXEN_CAM_RAM(0x1fc), 0);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800314 return -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700315 }
316
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800317 /* Start P2 boot loader */
318 val = adapter->pci_read_normalize(adapter,
319 NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
320 adapter->pci_write_normalize(adapter,
321 NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
322 timeout = 0;
323 do {
324 msleep(1);
325 val = adapter->pci_read_normalize(adapter,
326 NETXEN_CAM_RAM(0x1fc));
327
328 if (++timeout > 5000)
329 return -EIO;
330
331 } while (val == NETXEN_BDINFO_MAGIC);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700332 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800333 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700334}
335
336static void netxen_set_port_mode(struct netxen_adapter *adapter)
337{
338 u32 val, data;
339
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000340 val = adapter->ahw.board_type;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700341 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
342 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
343 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
344 data = NETXEN_PORT_MODE_802_3_AP;
345 adapter->hw_write_wx(adapter,
346 NETXEN_PORT_MODE_ADDR, &data, 4);
347 } else if (port_mode == NETXEN_PORT_MODE_XG) {
348 data = NETXEN_PORT_MODE_XG;
349 adapter->hw_write_wx(adapter,
350 NETXEN_PORT_MODE_ADDR, &data, 4);
351 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
352 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
353 adapter->hw_write_wx(adapter,
354 NETXEN_PORT_MODE_ADDR, &data, 4);
355 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
356 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
357 adapter->hw_write_wx(adapter,
358 NETXEN_PORT_MODE_ADDR, &data, 4);
359 } else {
360 data = NETXEN_PORT_MODE_AUTO_NEG;
361 adapter->hw_write_wx(adapter,
362 NETXEN_PORT_MODE_ADDR, &data, 4);
363 }
364
365 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
366 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
367 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
368 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
369 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
370 }
371 adapter->hw_write_wx(adapter, NETXEN_WOL_PORT_MODE,
372 &wol_port_mode, 4);
373 }
374}
375
Dhananjay Phadke29566402008-07-21 19:44:04 -0700376static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
377{
378 u32 control;
379 int pos;
380
381 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
382 if (pos) {
383 pci_read_config_dword(pdev, pos, &control);
384 if (enable)
385 control |= PCI_MSIX_FLAGS_ENABLE;
386 else
387 control = 0;
388 pci_write_config_dword(pdev, pos, control);
389 }
390}
391
392static void netxen_init_msix_entries(struct netxen_adapter *adapter)
393{
394 int i;
395
396 for (i = 0; i < MSIX_ENTRIES_PER_ADAPTER; i++)
397 adapter->msix_entries[i].entry = i;
398}
399
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700400static int
401netxen_read_mac_addr(struct netxen_adapter *adapter)
402{
403 int i;
404 unsigned char *p;
405 __le64 mac_addr;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700406 struct net_device *netdev = adapter->netdev;
407 struct pci_dev *pdev = adapter->pdev;
408
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700409 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
410 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
411 return -EIO;
412 } else {
413 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
414 return -EIO;
415 }
416
417 p = (unsigned char *)&mac_addr;
418 for (i = 0; i < 6; i++)
419 netdev->dev_addr[i] = *(p + 5 - i);
420
421 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
422
423 /* set station address */
424
Johannes Berge1749612008-10-27 15:59:26 -0700425 if (!is_valid_ether_addr(netdev->perm_addr))
426 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
427 else
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700428 adapter->macaddr_set(adapter, netdev->dev_addr);
429
430 return 0;
431}
432
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800433static void netxen_set_multicast_list(struct net_device *dev)
434{
435 struct netxen_adapter *adapter = netdev_priv(dev);
436
437 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
438 netxen_p3_nic_set_multi(dev);
439 else
440 netxen_p2_nic_set_multi(dev);
441}
442
443static const struct net_device_ops netxen_netdev_ops = {
444 .ndo_open = netxen_nic_open,
445 .ndo_stop = netxen_nic_close,
446 .ndo_start_xmit = netxen_nic_xmit_frame,
447 .ndo_get_stats = netxen_nic_get_stats,
448 .ndo_validate_addr = eth_validate_addr,
449 .ndo_set_multicast_list = netxen_set_multicast_list,
450 .ndo_set_mac_address = netxen_nic_set_mac,
451 .ndo_change_mtu = netxen_nic_change_mtu,
452 .ndo_tx_timeout = netxen_tx_timeout,
453#ifdef CONFIG_NET_POLL_CONTROLLER
454 .ndo_poll_controller = netxen_nic_poll_controller,
455#endif
456};
457
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800458static void
459netxen_setup_intr(struct netxen_adapter *adapter)
460{
461 struct netxen_legacy_intr_set *legacy_intrp;
462 struct pci_dev *pdev = adapter->pdev;
463
464 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800465
466 if (adapter->ahw.revision_id >= NX_P3_B0)
467 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
468 else
469 legacy_intrp = &legacy_intr[0];
470 adapter->legacy_intr.int_vec_bit = legacy_intrp->int_vec_bit;
471 adapter->legacy_intr.tgt_status_reg = legacy_intrp->tgt_status_reg;
472 adapter->legacy_intr.tgt_mask_reg = legacy_intrp->tgt_mask_reg;
473 adapter->legacy_intr.pci_int_reg = legacy_intrp->pci_int_reg;
474
475 netxen_set_msix_bit(pdev, 0);
476
477 if (adapter->msix_supported) {
478
479 netxen_init_msix_entries(adapter);
480 if (pci_enable_msix(pdev, adapter->msix_entries,
481 MSIX_ENTRIES_PER_ADAPTER))
482 goto request_msi;
483
484 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
485 netxen_set_msix_bit(pdev, 1);
486 dev_info(&pdev->dev, "using msi-x interrupts\n");
487
488 } else {
489request_msi:
490 if (use_msi && !pci_enable_msi(pdev)) {
491 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
492 dev_info(&pdev->dev, "using msi interrupts\n");
493 } else
494 dev_info(&pdev->dev, "using legacy interrupts\n");
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000495 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800496 }
497}
498
499static void
500netxen_teardown_intr(struct netxen_adapter *adapter)
501{
502 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
503 pci_disable_msix(adapter->pdev);
504 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
505 pci_disable_msi(adapter->pdev);
506}
507
508static void
509netxen_cleanup_pci_map(struct netxen_adapter *adapter)
510{
511 if (adapter->ahw.db_base != NULL)
512 iounmap(adapter->ahw.db_base);
513 if (adapter->ahw.pci_base0 != NULL)
514 iounmap(adapter->ahw.pci_base0);
515 if (adapter->ahw.pci_base1 != NULL)
516 iounmap(adapter->ahw.pci_base1);
517 if (adapter->ahw.pci_base2 != NULL)
518 iounmap(adapter->ahw.pci_base2);
519}
520
521static int
522netxen_setup_pci_map(struct netxen_adapter *adapter)
523{
524 void __iomem *mem_ptr0 = NULL;
525 void __iomem *mem_ptr1 = NULL;
526 void __iomem *mem_ptr2 = NULL;
527 void __iomem *db_ptr = NULL;
528
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800529 unsigned long mem_base, mem_len, db_base, db_len = 0, pci_len0 = 0;
530
531 struct pci_dev *pdev = adapter->pdev;
532 int pci_func = adapter->ahw.pci_func;
533
534 int err = 0;
535
536 /*
537 * Set the CRB window to invalid. If any register in window 0 is
538 * accessed it should set the window to 0 and then reset it to 1.
539 */
540 adapter->curr_window = 255;
541 adapter->ahw.qdr_sn_window = -1;
542 adapter->ahw.ddr_mn_window = -1;
543
544 /* remap phys address */
545 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
546 mem_len = pci_resource_len(pdev, 0);
547 pci_len0 = 0;
548
549 adapter->hw_write_wx = netxen_nic_hw_write_wx_128M;
550 adapter->hw_read_wx = netxen_nic_hw_read_wx_128M;
551 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_128M;
552 adapter->pci_write_immediate = netxen_nic_pci_write_immediate_128M;
553 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_128M;
554 adapter->pci_write_normalize = netxen_nic_pci_write_normalize_128M;
555 adapter->pci_set_window = netxen_nic_pci_set_window_128M;
556 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M;
557 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M;
558
559 /* 128 Meg of memory */
560 if (mem_len == NETXEN_PCI_128MB_SIZE) {
561 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
562 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
563 SECOND_PAGE_GROUP_SIZE);
564 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
565 THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800566 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
567 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
568 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
569 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800570 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
571 adapter->hw_write_wx = netxen_nic_hw_write_wx_2M;
572 adapter->hw_read_wx = netxen_nic_hw_read_wx_2M;
573 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_2M;
574 adapter->pci_write_immediate =
575 netxen_nic_pci_write_immediate_2M;
576 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_2M;
577 adapter->pci_write_normalize =
578 netxen_nic_pci_write_normalize_2M;
579 adapter->pci_set_window = netxen_nic_pci_set_window_2M;
580 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M;
581 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M;
582
583 mem_ptr0 = pci_ioremap_bar(pdev, 0);
584 if (mem_ptr0 == NULL) {
585 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
586 return -EIO;
587 }
588 pci_len0 = mem_len;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800589
590 adapter->ahw.ddr_mn_window = 0;
591 adapter->ahw.qdr_sn_window = 0;
592
593 adapter->ahw.mn_win_crb = 0x100000 + PCIX_MN_WINDOW +
594 (pci_func * 0x20);
595 adapter->ahw.ms_win_crb = 0x100000 + PCIX_SN_WINDOW;
596 if (pci_func < 4)
597 adapter->ahw.ms_win_crb += (pci_func * 0x20);
598 else
599 adapter->ahw.ms_win_crb +=
600 0xA0 + ((pci_func - 4) * 0x10);
601 } else {
602 return -EIO;
603 }
604
605 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
606
607 adapter->ahw.pci_base0 = mem_ptr0;
608 adapter->ahw.pci_len0 = pci_len0;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800609 adapter->ahw.pci_base1 = mem_ptr1;
610 adapter->ahw.pci_base2 = mem_ptr2;
611
612 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
613 goto skip_doorbell;
614
615 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
616 db_len = pci_resource_len(pdev, 4);
617
618 if (db_len == 0) {
619 printk(KERN_ERR "%s: doorbell is disabled\n",
620 netxen_nic_driver_name);
621 err = -EIO;
622 goto err_out;
623 }
624
625 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
626 if (!db_ptr) {
627 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
628 netxen_nic_driver_name);
629 err = -EIO;
630 goto err_out;
631 }
632
633skip_doorbell:
634 adapter->ahw.db_base = db_ptr;
635 adapter->ahw.db_len = db_len;
636 return 0;
637
638err_out:
639 netxen_cleanup_pci_map(adapter);
640 return err;
641}
642
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800643static int
644netxen_start_firmware(struct netxen_adapter *adapter)
645{
646 int val, err, first_boot;
647 struct pci_dev *pdev = adapter->pdev;
648
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000649 int first_driver = 0;
650 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
651 if (adapter->ahw.pci_func == 0)
652 first_driver = 1;
653 } else {
654 if (adapter->portnum == 0)
655 first_driver = 1;
656 }
657
658 if (!first_driver)
659 return 0;
660
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800661 first_boot = adapter->pci_read_normalize(adapter,
662 NETXEN_CAM_RAM(0x1fc));
663
664 err = netxen_check_hw_init(adapter, first_boot);
665 if (err) {
666 dev_err(&pdev->dev, "error in init HW init sequence\n");
667 return err;
668 }
669
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800670 if (first_boot != 0x55555555) {
671 adapter->pci_write_normalize(adapter,
672 CRB_CMDPEG_STATE, 0);
673 netxen_pinit_from_rom(adapter, 0);
674 msleep(1);
675 }
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000676
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000677 netxen_nic_reg_write(adapter, CRB_DMA_SHIFT, 0x55555555);
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000678 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
679 netxen_set_port_mode(adapter);
680
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800681 netxen_load_firmware(adapter);
682
683 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
684
685 /* Initialize multicast addr pool owners */
686 val = 0x7654;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000687 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800688 val |= 0x0f000000;
689 netxen_crb_writelit_adapter(adapter,
690 NETXEN_MAC_ADDR_CNTL_REG, val);
691
692 }
693
694 err = netxen_initialize_adapter_offload(adapter);
695 if (err)
696 return err;
697
698 /*
699 * Tell the hardware our version number.
700 */
701 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
702 | ((_NETXEN_NIC_LINUX_MINOR << 8))
703 | (_NETXEN_NIC_LINUX_SUBVERSION);
704 adapter->pci_write_normalize(adapter, CRB_DRIVER_VERSION, val);
705
706 /* Handshake with the card before we register the devices. */
707 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
708 if (err) {
709 netxen_free_adapter_offload(adapter);
710 return err;
711 }
712
713 return 0;
714}
715
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000716static int
717netxen_nic_request_irq(struct netxen_adapter *adapter)
718{
719 irq_handler_t handler;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000720 struct nx_host_sds_ring *sds_ring;
721 int err, ring;
722
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000723 unsigned long flags = IRQF_SAMPLE_RANDOM;
724 struct net_device *netdev = adapter->netdev;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000725 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000726
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000727 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
728 handler = netxen_msix_intr;
729 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
730 handler = netxen_msi_intr;
731 else {
732 flags |= IRQF_SHARED;
733 handler = netxen_intr;
734 }
735 adapter->irq = netdev->irq;
736
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000737 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
738 sds_ring = &recv_ctx->sds_rings[ring];
739 sprintf(sds_ring->name, "%16s[%d]", netdev->name, ring);
740 err = request_irq(sds_ring->irq, handler,
741 flags, sds_ring->name, sds_ring);
742 if (err)
743 return err;
744 }
745
746 return 0;
747}
748
749static void
750netxen_nic_free_irq(struct netxen_adapter *adapter)
751{
752 int ring;
753 struct nx_host_sds_ring *sds_ring;
754
755 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
756
757 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
758 sds_ring = &recv_ctx->sds_rings[ring];
759 free_irq(sds_ring->irq, sds_ring);
760 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000761}
762
763static int
764netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
765{
766 int err;
767
768 err = adapter->init_port(adapter, adapter->physical_port);
769 if (err) {
770 printk(KERN_ERR "%s: Failed to initialize port %d\n",
771 netxen_nic_driver_name, adapter->portnum);
772 return err;
773 }
774 adapter->macaddr_set(adapter, netdev->dev_addr);
775
776 netxen_nic_set_link_parameters(adapter);
777
778 netxen_set_multicast_list(netdev);
779 if (adapter->set_mtu)
780 adapter->set_mtu(adapter, netdev->mtu);
781
782 adapter->ahw.linkup = 0;
783 mod_timer(&adapter->watchdog_timer, jiffies);
784
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000785 netxen_napi_enable(adapter);
786
787 if (adapter->max_sds_rings > 1)
788 netxen_config_rss(adapter, 1);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000789
790 return 0;
791}
792
793static void
794netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
795{
796 netif_carrier_off(netdev);
797 netif_stop_queue(netdev);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000798 netxen_napi_disable(adapter);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000799
800 if (adapter->stop_port)
801 adapter->stop_port(adapter);
802
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000803 netxen_release_tx_buffers(adapter);
804
805 FLUSH_SCHEDULED_WORK();
806 del_timer_sync(&adapter->watchdog_timer);
807}
808
809
810static int
811netxen_nic_attach(struct netxen_adapter *adapter)
812{
813 struct net_device *netdev = adapter->netdev;
814 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000815 int err, ring;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000816 struct nx_host_rds_ring *rds_ring;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000817
818 err = netxen_init_firmware(adapter);
819 if (err != 0) {
820 printk(KERN_ERR "Failed to init firmware\n");
821 return -EIO;
822 }
823
824 if (adapter->fw_major < 4)
825 adapter->max_rds_rings = 3;
826 else
827 adapter->max_rds_rings = 2;
828
829 err = netxen_alloc_sw_resources(adapter);
830 if (err) {
831 printk(KERN_ERR "%s: Error in setting sw resources\n",
832 netdev->name);
833 return err;
834 }
835
836 netxen_nic_clear_stats(adapter);
837
838 err = netxen_alloc_hw_resources(adapter);
839 if (err) {
840 printk(KERN_ERR "%s: Error in setting hw resources\n",
841 netdev->name);
842 goto err_out_free_sw;
843 }
844
845 if (adapter->fw_major < 4) {
846 adapter->crb_addr_cmd_producer =
847 crb_cmd_producer[adapter->portnum];
848 adapter->crb_addr_cmd_consumer =
849 crb_cmd_consumer[adapter->portnum];
850
851 netxen_nic_update_cmd_producer(adapter, 0);
852 netxen_nic_update_cmd_consumer(adapter, 0);
853 }
854
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000855 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
856 rds_ring = &adapter->recv_ctx.rds_rings[ring];
857 netxen_post_rx_buffers(adapter, ring, rds_ring);
858 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000859
860 err = netxen_nic_request_irq(adapter);
861 if (err) {
862 dev_err(&pdev->dev, "%s: failed to setup interrupt\n",
863 netdev->name);
864 goto err_out_free_rxbuf;
865 }
866
867 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
868 return 0;
869
870err_out_free_rxbuf:
871 netxen_release_rx_buffers(adapter);
872 netxen_free_hw_resources(adapter);
873err_out_free_sw:
874 netxen_free_sw_resources(adapter);
875 return err;
876}
877
878static void
879netxen_nic_detach(struct netxen_adapter *adapter)
880{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000881 netxen_nic_free_irq(adapter);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000882
883 netxen_release_rx_buffers(adapter);
884 netxen_free_hw_resources(adapter);
885 netxen_free_sw_resources(adapter);
886
887 adapter->is_up = 0;
888}
889
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400890static int __devinit
891netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
892{
893 struct net_device *netdev = NULL;
894 struct netxen_adapter *adapter = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700895 int i = 0, err;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700896 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700897 uint8_t revision_id;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400898
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700899 if (pdev->class != 0x020000) {
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700900 printk(KERN_DEBUG "NetXen function %d, class %x will not "
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700901 "be enabled.\n",pci_func_id, pdev->class);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800902 return -ENODEV;
903 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700904
Dhananjay Phadke11d89d62008-08-08 00:08:45 -0700905 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
906 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
907 "will not be enabled.\n",
908 NX_P3_A0, NX_P3_B1);
909 return -ENODEV;
910 }
911
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400912 if ((err = pci_enable_device(pdev)))
913 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700914
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400915 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
916 err = -ENODEV;
917 goto err_out_disable_pdev;
918 }
919
920 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
921 goto err_out_disable_pdev;
922
923 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700924
925 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
926 if(!netdev) {
927 printk(KERN_ERR"%s: Failed to allocate memory for the "
928 "device block.Check system memory resource"
929 " usage.\n", netxen_nic_driver_name);
930 goto err_out_free_res;
931 }
932
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700933 SET_NETDEV_DEV(netdev, &pdev->dev);
934
Wang Chen4cf16532008-11-12 23:38:14 -0800935 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700936 adapter->netdev = netdev;
937 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700938 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700939
940 revision_id = pdev->revision;
941 adapter->ahw.revision_id = revision_id;
942
943 err = nx_set_dma_mask(adapter, revision_id);
944 if (err)
945 goto err_out_free_netdev;
946
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700947 rwlock_init(&adapter->adapter_lock);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000948 spin_lock_init(&adapter->tx_clean_lock);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700949
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800950 err = netxen_setup_pci_map(adapter);
951 if (err)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700952 goto err_out_free_netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400953
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +0530954 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700955 adapter->portnum = pci_func_id;
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530956 adapter->rx_csum = 1;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700957 adapter->mc_enabled = 0;
Dhananjay Phadke83821a02008-08-01 03:14:58 -0700958 if (NX_IS_REVISION_P3(revision_id))
Dhananjay Phadke29566402008-07-21 19:44:04 -0700959 adapter->max_mc_count = 38;
Dhananjay Phadke83821a02008-08-01 03:14:58 -0700960 else
Dhananjay Phadke29566402008-07-21 19:44:04 -0700961 adapter->max_mc_count = 16;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700962
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800963 netdev->netdev_ops = &netxen_netdev_ops;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -0700964 netdev->watchdog_timeo = 2*HZ;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700965
966 netxen_nic_change_mtu(netdev, netdev->mtu);
967
968 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800969
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800970 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
971 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
972
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700973 if (NX_IS_REVISION_P3(revision_id)) {
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800974 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
975 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700976 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700977
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800978 if (adapter->pci_using_dac) {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700979 netdev->features |= NETIF_F_HIGHDMA;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800980 netdev->vlan_features |= NETIF_F_HIGHDMA;
981 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700982
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700983 if (netxen_nic_get_board_info(adapter) != 0) {
984 printk("%s: Error getting board config info.\n",
Dhananjay Phadke29566402008-07-21 19:44:04 -0700985 netxen_nic_driver_name);
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700986 err = -EIO;
987 goto err_out_iounmap;
988 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700989
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700990 netxen_initialize_adapter_ops(adapter);
991
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700992 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000993 switch (adapter->ahw.board_type) {
Dhananjay Phadkedc515f22008-06-15 22:59:43 -0700994 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
995 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
996 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700997 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -0700998 break;
999 default:
1000 break;
1001 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001002
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001003 err = netxen_start_firmware(adapter);
1004 if (err)
1005 goto err_out_iounmap;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001006
Dhananjay Phadke1f434f62009-03-02 16:02:16 +00001007 nx_update_dma_mask(adapter);
1008
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001009 netxen_nic_get_firmware_info(adapter);
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001010
Dhananjay Phadke29566402008-07-21 19:44:04 -07001011 /*
1012 * See if the firmware gave us a virtual-physical port mapping.
1013 */
1014 adapter->physical_port = adapter->portnum;
Dhananjay Phadke044fad02009-02-24 03:42:59 -08001015 if (adapter->fw_major < 4) {
1016 i = adapter->pci_read_normalize(adapter,
1017 CRB_V2P(adapter->portnum));
1018 if (i != 0x55555555)
1019 adapter->physical_port = i;
1020 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001021
Dhananjay Phadke438627c2009-03-13 14:52:03 +00001022 netxen_check_options(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001023
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001024 netxen_setup_intr(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001025
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001026 netdev->irq = adapter->msix_entries[0].vector;
1027
1028 netxen_napi_add(adapter, netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001029
1030 err = netxen_receive_peg_ready(adapter);
1031 if (err)
1032 goto err_out_disable_msi;
1033
1034 init_timer(&adapter->watchdog_timer);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001035 adapter->watchdog_timer.function = &netxen_watchdog;
1036 adapter->watchdog_timer.data = (unsigned long)adapter;
1037 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
1038 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
1039
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001040 err = netxen_read_mac_addr(adapter);
1041 if (err)
1042 dev_warn(&pdev->dev, "failed to read mac addr\n");
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001043
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001044 netif_carrier_off(netdev);
1045 netif_stop_queue(netdev);
1046
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001047 if ((err = register_netdev(netdev))) {
1048 printk(KERN_ERR "%s: register_netdev failed port #%d"
1049 " aborting\n", netxen_nic_driver_name,
1050 adapter->portnum);
1051 err = -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001052 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001053 }
1054
1055 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001056
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001057 switch (adapter->ahw.port_type) {
Dhananjay Phadke29566402008-07-21 19:44:04 -07001058 case NETXEN_NIC_GBE:
1059 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1060 adapter->netdev->name);
1061 break;
1062 case NETXEN_NIC_XGBE:
1063 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1064 adapter->netdev->name);
1065 break;
1066 }
1067
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001068 return 0;
1069
Dhananjay Phadke29566402008-07-21 19:44:04 -07001070err_out_disable_msi:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001071 netxen_teardown_intr(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001072
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001073 netxen_free_adapter_offload(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001074
Dhananjay Phadke29566402008-07-21 19:44:04 -07001075err_out_iounmap:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001076 netxen_cleanup_pci_map(adapter);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001077
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001078err_out_free_netdev:
1079 free_netdev(netdev);
1080
1081err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001082 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001083
1084err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001085 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001086 pci_disable_device(pdev);
1087 return err;
1088}
1089
1090static void __devexit netxen_nic_remove(struct pci_dev *pdev)
1091{
1092 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001093 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001094
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001095 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001096 if (adapter == NULL)
1097 return;
1098
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001099 netdev = adapter->netdev;
1100
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301101 unregister_netdev(netdev);
1102
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301103 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001104 netxen_nic_detach(adapter);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -08001105
1106 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1107 netxen_p3_free_mac_list(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301108 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001109
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001110 if (adapter->portnum == 0)
1111 netxen_free_adapter_offload(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301112
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001113 netxen_teardown_intr(adapter);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301114
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001115 netxen_cleanup_pci_map(adapter);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001116
1117 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301118 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001119 pci_set_drvdata(pdev, NULL);
1120
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001121 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001122}
1123
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001124static int
1125netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
1126{
1127
1128 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1129 struct net_device *netdev = adapter->netdev;
1130
1131 netif_device_detach(netdev);
1132
1133 if (netif_running(netdev))
1134 netxen_nic_down(adapter, netdev);
1135
1136 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
1137 netxen_nic_detach(adapter);
1138
1139 pci_save_state(pdev);
1140
1141 if (netxen_nic_wol_supported(adapter)) {
1142 pci_enable_wake(pdev, PCI_D3cold, 1);
1143 pci_enable_wake(pdev, PCI_D3hot, 1);
1144 }
1145
1146 pci_disable_device(pdev);
1147 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1148
1149 return 0;
1150}
1151
1152static int
1153netxen_nic_resume(struct pci_dev *pdev)
1154{
1155 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1156 struct net_device *netdev = adapter->netdev;
1157 int err;
1158
1159 pci_set_power_state(pdev, PCI_D0);
1160 pci_restore_state(pdev);
1161
1162 err = pci_enable_device(pdev);
1163 if (err)
1164 return err;
1165
1166 adapter->curr_window = 255;
1167
1168 err = netxen_start_firmware(adapter);
1169 if (err) {
1170 dev_err(&pdev->dev, "failed to start firmware\n");
1171 return err;
1172 }
1173
1174 if (netif_running(netdev)) {
1175 err = netxen_nic_attach(adapter);
1176 if (err)
1177 return err;
1178
1179 err = netxen_nic_up(adapter, netdev);
1180 if (err)
1181 return err;
1182
1183 netif_device_attach(netdev);
1184 }
1185
1186 return 0;
1187}
1188
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001189static int netxen_nic_open(struct net_device *netdev)
1190{
Wang Chen4cf16532008-11-12 23:38:14 -08001191 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001192 int err = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001193
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001194 if (adapter->driver_mismatch)
1195 return -EIO;
1196
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001197 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) {
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001198 err = netxen_nic_attach(adapter);
1199 if (err)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001200 return err;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001201 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001202
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001203 err = netxen_nic_up(adapter, netdev);
1204 if (err)
1205 goto err_out;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001206
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001207 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001208
1209 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001210
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001211err_out:
1212 netxen_nic_detach(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001213 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001214}
1215
1216/*
1217 * netxen_nic_close - Disables a network interface entry point
1218 */
1219static int netxen_nic_close(struct net_device *netdev)
1220{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001221 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001222
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001223 netxen_nic_down(adapter, netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001224 return 0;
1225}
1226
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001227static bool netxen_tso_check(struct net_device *netdev,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001228 struct cmd_desc_type0 *desc, struct sk_buff *skb)
1229{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001230 bool tso = false;
1231 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001232 __be16 protocol = skb->protocol;
1233 u16 flags = 0;
1234
Harvey Harrison09640e62009-02-01 00:45:17 -08001235 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001236 struct vlan_ethhdr *vh = (struct vlan_ethhdr *)skb->data;
1237 protocol = vh->h_vlan_encapsulated_proto;
1238 flags = FLAGS_VLAN_TAGGED;
1239 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001240
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001241 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1242 skb_shinfo(skb)->gso_size > 0) {
1243
1244 desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1245 desc->total_hdr_length =
1246 skb_transport_offset(skb) + tcp_hdrlen(skb);
1247
Harvey Harrison09640e62009-02-01 00:45:17 -08001248 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001249 TX_TCP_LSO6 : TX_TCP_LSO;
1250 tso = true;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001251
1252 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001253 u8 l4proto;
1254
Harvey Harrison09640e62009-02-01 00:45:17 -08001255 if (protocol == cpu_to_be16(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001256 l4proto = ip_hdr(skb)->protocol;
1257
1258 if (l4proto == IPPROTO_TCP)
1259 opcode = TX_TCP_PKT;
1260 else if(l4proto == IPPROTO_UDP)
1261 opcode = TX_UDP_PKT;
Harvey Harrison09640e62009-02-01 00:45:17 -08001262 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001263 l4proto = ipv6_hdr(skb)->nexthdr;
1264
1265 if (l4proto == IPPROTO_TCP)
1266 opcode = TX_TCPV6_PKT;
1267 else if(l4proto == IPPROTO_UDP)
1268 opcode = TX_UDPV6_PKT;
1269 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001270 }
1271 desc->tcp_hdr_offset = skb_transport_offset(skb);
1272 desc->ip_hdr_offset = skb_network_offset(skb);
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001273 netxen_set_tx_flags_opcode(desc, flags, opcode);
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001274 return tso;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001275}
1276
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001277static void
1278netxen_clean_tx_dma_mapping(struct pci_dev *pdev,
1279 struct netxen_cmd_buffer *pbuf, int last)
1280{
1281 int k;
1282 struct netxen_skb_frag *buffrag;
1283
1284 buffrag = &pbuf->frag_array[0];
1285 pci_unmap_single(pdev, buffrag->dma,
1286 buffrag->length, PCI_DMA_TODEVICE);
1287
1288 for (k = 1; k < last; k++) {
1289 buffrag = &pbuf->frag_array[k];
1290 pci_unmap_page(pdev, buffrag->dma,
1291 buffrag->length, PCI_DMA_TODEVICE);
1292 }
1293}
1294
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001295static inline void
1296netxen_clear_cmddesc(u64 *desc)
1297{
1298 int i;
1299 for (i = 0; i < 8; i++)
1300 desc[i] = 0ULL;
1301}
1302
1303static int
1304netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001305{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001306 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001307 struct netxen_hardware_context *hw = &adapter->ahw;
1308 unsigned int first_seg_len = skb->len - skb->data_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001309 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001310 struct netxen_skb_frag *buffrag;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001311 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001312 struct pci_dev *pdev = adapter->pdev;
1313 dma_addr_t temp_dma;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001314 int i, k;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001315
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001316 u32 producer, consumer;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001317 int frag_count, no_of_desc;
Dhananjay Phadke438627c2009-03-13 14:52:03 +00001318 u32 num_txd = adapter->num_txd;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001319 bool is_tso = false;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001320
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001321 frag_count = skb_shinfo(skb)->nr_frags + 1;
1322
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001323 /* There 4 fragments per descriptor */
1324 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001325
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001326 producer = adapter->cmd_producer;
1327 smp_mb();
1328 consumer = adapter->last_cmd_consumer;
1329 if ((no_of_desc+2) > find_diff_among(producer, consumer, num_txd)) {
1330 netif_stop_queue(netdev);
1331 smp_mb();
1332 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001333 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001334
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001335 /* Copy the descriptors into the hardware */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001336 hwdesc = &hw->cmd_desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001337 netxen_clear_cmddesc((u64 *)hwdesc);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001338 /* Take skb->data itself */
1339 pbuf = &adapter->cmd_buf_arr[producer];
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001340
1341 is_tso = netxen_tso_check(netdev, hwdesc, skb);
1342
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001343 pbuf->skb = skb;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001344 pbuf->frag_count = frag_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001345 buffrag = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001346 temp_dma = pci_map_single(pdev, skb->data, first_seg_len,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001347 PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001348 if (pci_dma_mapping_error(pdev, temp_dma))
1349 goto drop_packet;
1350
1351 buffrag->dma = temp_dma;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001352 buffrag->length = first_seg_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001353 netxen_set_tx_frags_len(hwdesc, frag_count, skb->len);
1354 netxen_set_tx_port(hwdesc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001355
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001356 hwdesc->buffer_length[0] = cpu_to_le16(first_seg_len);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001357 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
1358
1359 for (i = 1, k = 1; i < frag_count; i++, k++) {
1360 struct skb_frag_struct *frag;
1361 int len, temp_len;
1362 unsigned long offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001363
1364 /* move to next desc. if there is a need */
1365 if ((i & 0x3) == 0) {
1366 k = 0;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001367 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001368 hwdesc = &hw->cmd_desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001369 netxen_clear_cmddesc((u64 *)hwdesc);
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001370 pbuf = &adapter->cmd_buf_arr[producer];
1371 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001372 }
1373 frag = &skb_shinfo(skb)->frags[i - 1];
1374 len = frag->size;
1375 offset = frag->page_offset;
1376
1377 temp_len = len;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001378 temp_dma = pci_map_page(pdev, frag->page, offset,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001379 len, PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001380 if (pci_dma_mapping_error(pdev, temp_dma)) {
1381 netxen_clean_tx_dma_mapping(pdev, pbuf, i);
1382 goto drop_packet;
1383 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001384
1385 buffrag++;
1386 buffrag->dma = temp_dma;
1387 buffrag->length = temp_len;
1388
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001389 hwdesc->buffer_length[k] = cpu_to_le16(temp_len);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001390 switch (k) {
1391 case 0:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001392 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
1393 break;
1394 case 1:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001395 hwdesc->addr_buffer2 = cpu_to_le64(temp_dma);
1396 break;
1397 case 2:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001398 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
1399 break;
1400 case 3:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001401 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
1402 break;
1403 }
1404 frag++;
1405 }
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001406 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001407
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001408 /* For LSO, we need to copy the MAC/IP/TCP headers into
1409 * the descriptor ring
1410 */
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001411 if (is_tso) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001412 int hdr_len, first_hdr_len, more_hdr;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001413 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001414 if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) {
1415 first_hdr_len = sizeof(struct cmd_desc_type0) - 2;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001416 more_hdr = 1;
1417 } else {
1418 first_hdr_len = hdr_len;
1419 more_hdr = 0;
1420 }
1421 /* copy the MAC/IP/TCP headers to the cmd descriptor list */
1422 hwdesc = &hw->cmd_desc_head[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001423 pbuf = &adapter->cmd_buf_arr[producer];
1424 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001425
1426 /* copy the first 64 bytes */
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001427 memcpy(((void *)hwdesc) + 2,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001428 (void *)(skb->data), first_hdr_len);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001429 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001430
1431 if (more_hdr) {
1432 hwdesc = &hw->cmd_desc_head[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001433 pbuf = &adapter->cmd_buf_arr[producer];
1434 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001435 /* copy the next 64 bytes - should be enough except
1436 * for pathological case
1437 */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001438 skb_copy_from_linear_data_offset(skb, first_hdr_len,
1439 hwdesc,
1440 (hdr_len -
1441 first_hdr_len));
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001442 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001443 }
1444 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001445
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001446 adapter->cmd_producer = producer;
Dhananjay Phadke5dc16262007-12-31 10:08:57 -08001447 adapter->stats.txbytes += skb->len;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001448
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001449 netxen_nic_update_cmd_producer(adapter, adapter->cmd_producer);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001450
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001451 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001452 netdev->trans_start = jiffies;
1453
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001454 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001455
1456drop_packet:
1457 adapter->stats.txdropped++;
1458 dev_kfree_skb_any(skb);
1459 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001460}
1461
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001462static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1463{
1464 struct net_device *netdev = adapter->netdev;
1465 uint32_t temp, temp_state, temp_val;
1466 int rv = 0;
1467
1468 temp = adapter->pci_read_normalize(adapter, CRB_TEMP_STATE);
1469
1470 temp_state = nx_get_temp_state(temp);
1471 temp_val = nx_get_temp_val(temp);
1472
1473 if (temp_state == NX_TEMP_PANIC) {
1474 printk(KERN_ALERT
1475 "%s: Device temperature %d degrees C exceeds"
1476 " maximum allowed. Hardware has been shut down.\n",
1477 netxen_nic_driver_name, temp_val);
1478
1479 netif_carrier_off(netdev);
1480 netif_stop_queue(netdev);
1481 rv = 1;
1482 } else if (temp_state == NX_TEMP_WARN) {
1483 if (adapter->temp == NX_TEMP_NORMAL) {
1484 printk(KERN_ALERT
1485 "%s: Device temperature %d degrees C "
1486 "exceeds operating range."
1487 " Immediate action needed.\n",
1488 netxen_nic_driver_name, temp_val);
1489 }
1490 } else {
1491 if (adapter->temp == NX_TEMP_WARN) {
1492 printk(KERN_INFO
1493 "%s: Device temperature is now %d degrees C"
1494 " in normal range.\n", netxen_nic_driver_name,
1495 temp_val);
1496 }
1497 }
1498 adapter->temp = temp_state;
1499 return rv;
1500}
1501
1502static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1503{
1504 struct net_device *netdev = adapter->netdev;
1505 u32 val, port, linkup;
1506
1507 port = adapter->physical_port;
1508
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001509 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1510 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE_P3);
1511 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1512 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001513 } else {
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001514 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001515 if (adapter->ahw.port_type == NETXEN_NIC_GBE)
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001516 linkup = (val >> port) & 1;
1517 else {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001518 val = (val >> port*8) & 0xff;
1519 linkup = (val == XG_LINK_UP);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001520 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001521 }
1522
1523 if (adapter->ahw.linkup && !linkup) {
1524 printk(KERN_INFO "%s: %s NIC Link is down\n",
1525 netxen_nic_driver_name, netdev->name);
1526 adapter->ahw.linkup = 0;
1527 if (netif_running(netdev)) {
1528 netif_carrier_off(netdev);
1529 netif_stop_queue(netdev);
1530 }
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001531
1532 netxen_nic_set_link_parameters(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001533 } else if (!adapter->ahw.linkup && linkup) {
1534 printk(KERN_INFO "%s: %s NIC Link is up\n",
1535 netxen_nic_driver_name, netdev->name);
1536 adapter->ahw.linkup = 1;
1537 if (netif_running(netdev)) {
1538 netif_carrier_on(netdev);
1539 netif_wake_queue(netdev);
1540 }
Dhananjay Phadkec7860a22009-01-14 20:48:32 -08001541
1542 netxen_nic_set_link_parameters(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001543 }
1544}
1545
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001546static void netxen_watchdog(unsigned long v)
1547{
1548 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001549
1550 SCHEDULE_WORK(&adapter->watchdog_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001551}
1552
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001553void netxen_watchdog_task(struct work_struct *work)
1554{
1555 struct netxen_adapter *adapter =
1556 container_of(work, struct netxen_adapter, watchdog_task);
1557
1558 if ((adapter->portnum == 0) && netxen_nic_check_temp(adapter))
1559 return;
1560
1561 netxen_nic_handle_phy_intr(adapter);
1562
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001563 if (netif_running(adapter->netdev))
1564 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001565}
1566
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001567static void netxen_tx_timeout(struct net_device *netdev)
1568{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001569 struct netxen_adapter *adapter = (struct netxen_adapter *)
1570 netdev_priv(netdev);
1571 SCHEDULE_WORK(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001572}
1573
David Howells6d5aefb2006-12-05 19:36:26 +00001574static void netxen_tx_timeout_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001575{
Jeff Garzik47906542007-11-23 21:23:36 -05001576 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001577 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001578
1579 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001580 netxen_nic_driver_name, adapter->netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001581
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001582 netxen_napi_disable(adapter);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001583
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001584 adapter->netdev->trans_start = jiffies;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001585
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001586 netxen_napi_enable(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001587 netif_wake_queue(adapter->netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001588}
1589
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001590struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1591{
1592 struct netxen_adapter *adapter = netdev_priv(netdev);
1593 struct net_device_stats *stats = &adapter->net_stats;
1594
1595 memset(stats, 0, sizeof(*stats));
1596
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001597 stats->rx_packets = adapter->stats.no_rcv;
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00001598 stats->tx_packets = adapter->stats.xmitfinished;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001599 stats->rx_bytes = adapter->stats.rxbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001600 stats->tx_bytes = adapter->stats.txbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001601 stats->rx_dropped = adapter->stats.rxdropped;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001602 stats->tx_dropped = adapter->stats.txdropped;
1603
1604 return stats;
1605}
1606
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001607static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001608{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001609 struct nx_host_sds_ring *sds_ring = data;
1610 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001611 u32 status = 0;
1612
1613 status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1614
1615 if (!(status & adapter->legacy_intr.int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001616 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301617
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001618 if (adapter->ahw.revision_id >= NX_P3_B1) {
1619 /* check interrupt state machine, to be sure */
1620 status = adapter->pci_read_immediate(adapter,
1621 ISR_INT_STATE_REG);
1622 if (!ISR_LEGACY_INT_TRIGGERED(status))
1623 return IRQ_NONE;
1624
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001625 } else {
1626 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001627
1628 our_int = adapter->pci_read_normalize(adapter, CRB_INT_VECTOR);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001629
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001630 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001631 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001632 return IRQ_NONE;
1633
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001634 /* claim interrupt */
1635 adapter->pci_write_normalize(adapter,
1636 CRB_INT_VECTOR, (our_int & 0xffffffff));
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301637 }
1638
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001639 /* clear interrupt */
1640 if (adapter->fw_major < 4)
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001641 netxen_nic_disable_int(sds_ring);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001642
1643 adapter->pci_write_immediate(adapter,
1644 adapter->legacy_intr.tgt_status_reg,
1645 0xffffffff);
1646 /* read twice to ensure write is flushed */
1647 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1648 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1649
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001650 napi_schedule(&sds_ring->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001651
1652 return IRQ_HANDLED;
1653}
1654
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001655static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001656{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001657 struct nx_host_sds_ring *sds_ring = data;
1658 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001659
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001660 /* clear interrupt */
1661 adapter->pci_write_immediate(adapter,
1662 msi_tgt_status[adapter->ahw.pci_func], 0xffffffff);
1663
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001664 napi_schedule(&sds_ring->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001665 return IRQ_HANDLED;
1666}
1667
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001668static irqreturn_t netxen_msix_intr(int irq, void *data)
1669{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001670 struct nx_host_sds_ring *sds_ring = data;
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001671
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001672 napi_schedule(&sds_ring->napi);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001673 return IRQ_HANDLED;
1674}
1675
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001676static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001677{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001678 struct nx_host_sds_ring *sds_ring =
1679 container_of(napi, struct nx_host_sds_ring, napi);
1680
1681 struct netxen_adapter *adapter = sds_ring->adapter;
1682
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001683 int tx_complete;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001684 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001685
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001686 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001687
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001688 work_done = netxen_process_rcv_ring(sds_ring, budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001689
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001690 if ((work_done < budget) && tx_complete) {
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001691 napi_complete(&sds_ring->napi);
1692 netxen_nic_enable_int(sds_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001693 }
1694
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001695 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001696}
1697
1698#ifdef CONFIG_NET_POLL_CONTROLLER
1699static void netxen_nic_poll_controller(struct net_device *netdev)
1700{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001701 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001702 disable_irq(adapter->irq);
Jeff Garzik1494a812006-11-07 05:12:16 -05001703 netxen_intr(adapter->irq, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001704 enable_irq(adapter->irq);
1705}
1706#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001707
1708static struct pci_driver netxen_driver = {
1709 .name = netxen_nic_driver_name,
1710 .id_table = netxen_pci_tbl,
1711 .probe = netxen_nic_probe,
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001712 .remove = __devexit_p(netxen_nic_remove),
1713 .suspend = netxen_nic_suspend,
1714 .resume = netxen_nic_resume
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001715};
1716
1717/* Driver Registration on NetXen card */
1718
1719static int __init netxen_init_module(void)
1720{
Dhananjay Phadkeff4fbd42009-03-13 14:52:06 +00001721 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
1722
Al Viro79ea13c2008-01-24 02:06:46 -08001723 if ((netxen_workq = create_singlethread_workqueue("netxen")) == NULL)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001724 return -ENOMEM;
1725
Amit S. Kale184231b2007-01-22 06:52:53 -08001726 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001727}
1728
1729module_init(netxen_init_module);
1730
1731static void __exit netxen_exit_module(void)
1732{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001733 pci_unregister_driver(&netxen_driver);
Amit S. Kale9de06612007-02-21 06:37:06 -08001734 destroy_workqueue(netxen_workq);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001735}
1736
1737module_exit(netxen_exit_module);