blob: cbd47ae694bace7221abb4d097bde8caf06f37a4 [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 Bunkb1555132008-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,
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000110 struct nx_host_tx_ring *tx_ring, u32 producer)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700111{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700112 adapter->pci_write_normalize(adapter,
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000113 tx_ring->crb_cmd_producer, 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,
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000123 struct nx_host_tx_ring *tx_ring, u32 consumer)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700124{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700125 adapter->pci_write_normalize(adapter,
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000126 tx_ring->crb_cmd_consumer, 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 Phadke71dcddb2009-04-07 22:50:43 +0000156static int
157netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count)
158{
159 int size = sizeof(struct nx_host_sds_ring) * count;
160
161 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
162
163 return (recv_ctx->sds_rings == NULL);
164}
165
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000166static void
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000167netxen_free_sds_rings(struct netxen_recv_context *recv_ctx)
168{
169 if (recv_ctx->sds_rings != NULL)
170 kfree(recv_ctx->sds_rings);
171}
172
173static int
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000174netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
175{
176 int ring;
177 struct nx_host_sds_ring *sds_ring;
178 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
179
180 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
181 adapter->max_sds_rings = (num_online_cpus() >= 4) ? 4 : 2;
182 else
183 adapter->max_sds_rings = 1;
184
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000185 if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
186 return 1;
187
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000188 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
189 sds_ring = &recv_ctx->sds_rings[ring];
190 netif_napi_add(netdev, &sds_ring->napi,
191 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
192 }
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000193
194 return 0;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000195}
196
197static void
198netxen_napi_enable(struct netxen_adapter *adapter)
199{
200 int ring;
201 struct nx_host_sds_ring *sds_ring;
202 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
203
204 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
205 sds_ring = &recv_ctx->sds_rings[ring];
206 napi_enable(&sds_ring->napi);
207 netxen_nic_enable_int(sds_ring);
208 }
209}
210
211static void
212netxen_napi_disable(struct netxen_adapter *adapter)
213{
214 int ring;
215 struct nx_host_sds_ring *sds_ring;
216 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
217
218 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
219 sds_ring = &recv_ctx->sds_rings[ring];
220 netxen_nic_disable_int(sds_ring);
221 napi_disable(&sds_ring->napi);
222 }
223}
224
Dhananjay Phadke29566402008-07-21 19:44:04 -0700225static int nx_set_dma_mask(struct netxen_adapter *adapter, uint8_t revision_id)
226{
227 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000228 uint64_t mask, cmask;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700229
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000230 adapter->pci_using_dac = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700231
Yang Hongyang6afd1422009-04-06 19:01:15 -0700232 mask = DMA_BIT_MASK(32);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700233 /*
234 * Consistent DMA mask is set to 32 bit because it cannot be set to
235 * 35 bits. For P3 also leave it at 32 bits for now. Only the rings
236 * come off this pool.
237 */
Yang Hongyang6afd1422009-04-06 19:01:15 -0700238 cmask = DMA_BIT_MASK(32);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000239
240#ifndef CONFIG_IA64
241 if (revision_id >= NX_P3_B0)
Yang Hongyang6afd1422009-04-06 19:01:15 -0700242 mask = DMA_BIT_MASK(39);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000243 else if (revision_id == NX_P2_C1)
Yang Hongyang6afd1422009-04-06 19:01:15 -0700244 mask = DMA_BIT_MASK(35);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000245#endif
Dhananjay Phadke29566402008-07-21 19:44:04 -0700246 if (pci_set_dma_mask(pdev, mask) == 0 &&
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000247 pci_set_consistent_dma_mask(pdev, cmask) == 0) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700248 adapter->pci_using_dac = 1;
249 return 0;
250 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700251
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000252 return -EIO;
253}
254
255/* Update addressable range if firmware supports it */
256static int
257nx_update_dma_mask(struct netxen_adapter *adapter)
258{
259 int change, shift, err;
260 uint64_t mask, old_mask;
261 struct pci_dev *pdev = adapter->pdev;
262
263 change = 0;
264
265 shift = netxen_nic_reg_read(adapter, CRB_DMA_SHIFT);
266 if (shift >= 32)
267 return 0;
268
269 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9))
270 change = 1;
271 else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4))
272 change = 1;
273
274 if (change) {
275 old_mask = pdev->dma_mask;
276 mask = (1ULL<<(32+shift)) - 1;
277
278 err = pci_set_dma_mask(pdev, mask);
279 if (err)
280 return pci_set_dma_mask(pdev, old_mask);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700281 }
282
Dhananjay Phadke29566402008-07-21 19:44:04 -0700283 return 0;
284}
285
286static void netxen_check_options(struct netxen_adapter *adapter)
287{
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000288 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
289 adapter->num_rxd = MAX_RCV_DESCRIPTORS_10G;
290 else if (adapter->ahw.port_type == NETXEN_NIC_GBE)
291 adapter->num_rxd = MAX_RCV_DESCRIPTORS_1G;
292
293 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
Dhananjay Phadke29566402008-07-21 19:44:04 -0700294 adapter->msix_supported = !!use_msi_x;
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000295 else
Dhananjay Phadke29566402008-07-21 19:44:04 -0700296 adapter->msix_supported = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700297
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000298 adapter->num_txd = MAX_CMD_DESCRIPTORS_HOST;
299 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS;
300 adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700301
Dhananjay Phadke29566402008-07-21 19:44:04 -0700302 return;
303}
304
305static int
306netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
307{
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800308 u32 val, timeout;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700309
310 if (first_boot == 0x55555555) {
311 /* This is the first boot after power up */
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800312 adapter->pci_write_normalize(adapter,
313 NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
314
315 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
316 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700317
318 /* PCI bus master workaround */
319 adapter->hw_read_wx(adapter,
320 NETXEN_PCIE_REG(0x4), &first_boot, 4);
321 if (!(first_boot & 0x4)) {
322 first_boot |= 0x4;
323 adapter->hw_write_wx(adapter,
324 NETXEN_PCIE_REG(0x4), &first_boot, 4);
325 adapter->hw_read_wx(adapter,
326 NETXEN_PCIE_REG(0x4), &first_boot, 4);
327 }
328
329 /* This is the first boot after power up */
330 adapter->hw_read_wx(adapter,
331 NETXEN_ROMUSB_GLB_SW_RESET, &first_boot, 4);
332 if (first_boot != 0x80000f) {
333 /* clear the register for future unloads/loads */
334 adapter->pci_write_normalize(adapter,
335 NETXEN_CAM_RAM(0x1fc), 0);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800336 return -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700337 }
338
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800339 /* Start P2 boot loader */
340 val = adapter->pci_read_normalize(adapter,
341 NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
342 adapter->pci_write_normalize(adapter,
343 NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
344 timeout = 0;
345 do {
346 msleep(1);
347 val = adapter->pci_read_normalize(adapter,
348 NETXEN_CAM_RAM(0x1fc));
349
350 if (++timeout > 5000)
351 return -EIO;
352
353 } while (val == NETXEN_BDINFO_MAGIC);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700354 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800355 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700356}
357
358static void netxen_set_port_mode(struct netxen_adapter *adapter)
359{
360 u32 val, data;
361
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000362 val = adapter->ahw.board_type;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700363 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
364 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
365 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
366 data = NETXEN_PORT_MODE_802_3_AP;
367 adapter->hw_write_wx(adapter,
368 NETXEN_PORT_MODE_ADDR, &data, 4);
369 } else if (port_mode == NETXEN_PORT_MODE_XG) {
370 data = NETXEN_PORT_MODE_XG;
371 adapter->hw_write_wx(adapter,
372 NETXEN_PORT_MODE_ADDR, &data, 4);
373 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
374 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
375 adapter->hw_write_wx(adapter,
376 NETXEN_PORT_MODE_ADDR, &data, 4);
377 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
378 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
379 adapter->hw_write_wx(adapter,
380 NETXEN_PORT_MODE_ADDR, &data, 4);
381 } else {
382 data = NETXEN_PORT_MODE_AUTO_NEG;
383 adapter->hw_write_wx(adapter,
384 NETXEN_PORT_MODE_ADDR, &data, 4);
385 }
386
387 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
388 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
389 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
390 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
391 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
392 }
393 adapter->hw_write_wx(adapter, NETXEN_WOL_PORT_MODE,
394 &wol_port_mode, 4);
395 }
396}
397
Dhananjay Phadke29566402008-07-21 19:44:04 -0700398static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
399{
400 u32 control;
401 int pos;
402
403 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
404 if (pos) {
405 pci_read_config_dword(pdev, pos, &control);
406 if (enable)
407 control |= PCI_MSIX_FLAGS_ENABLE;
408 else
409 control = 0;
410 pci_write_config_dword(pdev, pos, control);
411 }
412}
413
414static void netxen_init_msix_entries(struct netxen_adapter *adapter)
415{
416 int i;
417
418 for (i = 0; i < MSIX_ENTRIES_PER_ADAPTER; i++)
419 adapter->msix_entries[i].entry = i;
420}
421
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700422static int
423netxen_read_mac_addr(struct netxen_adapter *adapter)
424{
425 int i;
426 unsigned char *p;
427 __le64 mac_addr;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700428 struct net_device *netdev = adapter->netdev;
429 struct pci_dev *pdev = adapter->pdev;
430
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700431 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
432 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
433 return -EIO;
434 } else {
435 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
436 return -EIO;
437 }
438
439 p = (unsigned char *)&mac_addr;
440 for (i = 0; i < 6; i++)
441 netdev->dev_addr[i] = *(p + 5 - i);
442
443 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
444
445 /* set station address */
446
Johannes Berge1749612008-10-27 15:59:26 -0700447 if (!is_valid_ether_addr(netdev->perm_addr))
448 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
449 else
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700450 adapter->macaddr_set(adapter, netdev->dev_addr);
451
452 return 0;
453}
454
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800455static void netxen_set_multicast_list(struct net_device *dev)
456{
457 struct netxen_adapter *adapter = netdev_priv(dev);
458
459 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
460 netxen_p3_nic_set_multi(dev);
461 else
462 netxen_p2_nic_set_multi(dev);
463}
464
465static const struct net_device_ops netxen_netdev_ops = {
466 .ndo_open = netxen_nic_open,
467 .ndo_stop = netxen_nic_close,
468 .ndo_start_xmit = netxen_nic_xmit_frame,
469 .ndo_get_stats = netxen_nic_get_stats,
470 .ndo_validate_addr = eth_validate_addr,
471 .ndo_set_multicast_list = netxen_set_multicast_list,
472 .ndo_set_mac_address = netxen_nic_set_mac,
473 .ndo_change_mtu = netxen_nic_change_mtu,
474 .ndo_tx_timeout = netxen_tx_timeout,
475#ifdef CONFIG_NET_POLL_CONTROLLER
476 .ndo_poll_controller = netxen_nic_poll_controller,
477#endif
478};
479
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800480static void
481netxen_setup_intr(struct netxen_adapter *adapter)
482{
483 struct netxen_legacy_intr_set *legacy_intrp;
484 struct pci_dev *pdev = adapter->pdev;
485
486 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800487
488 if (adapter->ahw.revision_id >= NX_P3_B0)
489 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
490 else
491 legacy_intrp = &legacy_intr[0];
492 adapter->legacy_intr.int_vec_bit = legacy_intrp->int_vec_bit;
493 adapter->legacy_intr.tgt_status_reg = legacy_intrp->tgt_status_reg;
494 adapter->legacy_intr.tgt_mask_reg = legacy_intrp->tgt_mask_reg;
495 adapter->legacy_intr.pci_int_reg = legacy_intrp->pci_int_reg;
496
497 netxen_set_msix_bit(pdev, 0);
498
499 if (adapter->msix_supported) {
500
501 netxen_init_msix_entries(adapter);
502 if (pci_enable_msix(pdev, adapter->msix_entries,
503 MSIX_ENTRIES_PER_ADAPTER))
504 goto request_msi;
505
506 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
507 netxen_set_msix_bit(pdev, 1);
508 dev_info(&pdev->dev, "using msi-x interrupts\n");
509
510 } else {
511request_msi:
512 if (use_msi && !pci_enable_msi(pdev)) {
513 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
514 dev_info(&pdev->dev, "using msi interrupts\n");
515 } else
516 dev_info(&pdev->dev, "using legacy interrupts\n");
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000517 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800518 }
519}
520
521static void
522netxen_teardown_intr(struct netxen_adapter *adapter)
523{
524 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
525 pci_disable_msix(adapter->pdev);
526 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
527 pci_disable_msi(adapter->pdev);
528}
529
530static void
531netxen_cleanup_pci_map(struct netxen_adapter *adapter)
532{
533 if (adapter->ahw.db_base != NULL)
534 iounmap(adapter->ahw.db_base);
535 if (adapter->ahw.pci_base0 != NULL)
536 iounmap(adapter->ahw.pci_base0);
537 if (adapter->ahw.pci_base1 != NULL)
538 iounmap(adapter->ahw.pci_base1);
539 if (adapter->ahw.pci_base2 != NULL)
540 iounmap(adapter->ahw.pci_base2);
541}
542
543static int
544netxen_setup_pci_map(struct netxen_adapter *adapter)
545{
546 void __iomem *mem_ptr0 = NULL;
547 void __iomem *mem_ptr1 = NULL;
548 void __iomem *mem_ptr2 = NULL;
549 void __iomem *db_ptr = NULL;
550
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800551 unsigned long mem_base, mem_len, db_base, db_len = 0, pci_len0 = 0;
552
553 struct pci_dev *pdev = adapter->pdev;
554 int pci_func = adapter->ahw.pci_func;
555
556 int err = 0;
557
558 /*
559 * Set the CRB window to invalid. If any register in window 0 is
560 * accessed it should set the window to 0 and then reset it to 1.
561 */
562 adapter->curr_window = 255;
563 adapter->ahw.qdr_sn_window = -1;
564 adapter->ahw.ddr_mn_window = -1;
565
566 /* remap phys address */
567 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
568 mem_len = pci_resource_len(pdev, 0);
569 pci_len0 = 0;
570
571 adapter->hw_write_wx = netxen_nic_hw_write_wx_128M;
572 adapter->hw_read_wx = netxen_nic_hw_read_wx_128M;
573 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_128M;
574 adapter->pci_write_immediate = netxen_nic_pci_write_immediate_128M;
575 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_128M;
576 adapter->pci_write_normalize = netxen_nic_pci_write_normalize_128M;
577 adapter->pci_set_window = netxen_nic_pci_set_window_128M;
578 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M;
579 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M;
580
581 /* 128 Meg of memory */
582 if (mem_len == NETXEN_PCI_128MB_SIZE) {
583 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
584 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
585 SECOND_PAGE_GROUP_SIZE);
586 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
587 THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800588 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
589 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
590 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
591 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800592 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
593 adapter->hw_write_wx = netxen_nic_hw_write_wx_2M;
594 adapter->hw_read_wx = netxen_nic_hw_read_wx_2M;
595 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_2M;
596 adapter->pci_write_immediate =
597 netxen_nic_pci_write_immediate_2M;
598 adapter->pci_read_normalize = netxen_nic_pci_read_normalize_2M;
599 adapter->pci_write_normalize =
600 netxen_nic_pci_write_normalize_2M;
601 adapter->pci_set_window = netxen_nic_pci_set_window_2M;
602 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M;
603 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M;
604
605 mem_ptr0 = pci_ioremap_bar(pdev, 0);
606 if (mem_ptr0 == NULL) {
607 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
608 return -EIO;
609 }
610 pci_len0 = mem_len;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800611
612 adapter->ahw.ddr_mn_window = 0;
613 adapter->ahw.qdr_sn_window = 0;
614
615 adapter->ahw.mn_win_crb = 0x100000 + PCIX_MN_WINDOW +
616 (pci_func * 0x20);
617 adapter->ahw.ms_win_crb = 0x100000 + PCIX_SN_WINDOW;
618 if (pci_func < 4)
619 adapter->ahw.ms_win_crb += (pci_func * 0x20);
620 else
621 adapter->ahw.ms_win_crb +=
622 0xA0 + ((pci_func - 4) * 0x10);
623 } else {
624 return -EIO;
625 }
626
627 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
628
629 adapter->ahw.pci_base0 = mem_ptr0;
630 adapter->ahw.pci_len0 = pci_len0;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800631 adapter->ahw.pci_base1 = mem_ptr1;
632 adapter->ahw.pci_base2 = mem_ptr2;
633
634 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
635 goto skip_doorbell;
636
637 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
638 db_len = pci_resource_len(pdev, 4);
639
640 if (db_len == 0) {
641 printk(KERN_ERR "%s: doorbell is disabled\n",
642 netxen_nic_driver_name);
643 err = -EIO;
644 goto err_out;
645 }
646
647 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
648 if (!db_ptr) {
649 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
650 netxen_nic_driver_name);
651 err = -EIO;
652 goto err_out;
653 }
654
655skip_doorbell:
656 adapter->ahw.db_base = db_ptr;
657 adapter->ahw.db_len = db_len;
658 return 0;
659
660err_out:
661 netxen_cleanup_pci_map(adapter);
662 return err;
663}
664
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800665static int
666netxen_start_firmware(struct netxen_adapter *adapter)
667{
668 int val, err, first_boot;
669 struct pci_dev *pdev = adapter->pdev;
670
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000671 int first_driver = 0;
672 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
673 if (adapter->ahw.pci_func == 0)
674 first_driver = 1;
675 } else {
676 if (adapter->portnum == 0)
677 first_driver = 1;
678 }
679
680 if (!first_driver)
681 return 0;
682
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800683 first_boot = adapter->pci_read_normalize(adapter,
684 NETXEN_CAM_RAM(0x1fc));
685
686 err = netxen_check_hw_init(adapter, first_boot);
687 if (err) {
688 dev_err(&pdev->dev, "error in init HW init sequence\n");
689 return err;
690 }
691
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800692 if (first_boot != 0x55555555) {
693 adapter->pci_write_normalize(adapter,
694 CRB_CMDPEG_STATE, 0);
695 netxen_pinit_from_rom(adapter, 0);
696 msleep(1);
697 }
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000698
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000699 netxen_nic_reg_write(adapter, CRB_DMA_SHIFT, 0x55555555);
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000700 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
701 netxen_set_port_mode(adapter);
702
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800703 netxen_load_firmware(adapter);
704
705 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
706
707 /* Initialize multicast addr pool owners */
708 val = 0x7654;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000709 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800710 val |= 0x0f000000;
711 netxen_crb_writelit_adapter(adapter,
712 NETXEN_MAC_ADDR_CNTL_REG, val);
713
714 }
715
716 err = netxen_initialize_adapter_offload(adapter);
717 if (err)
718 return err;
719
720 /*
721 * Tell the hardware our version number.
722 */
723 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
724 | ((_NETXEN_NIC_LINUX_MINOR << 8))
725 | (_NETXEN_NIC_LINUX_SUBVERSION);
726 adapter->pci_write_normalize(adapter, CRB_DRIVER_VERSION, val);
727
728 /* Handshake with the card before we register the devices. */
729 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
730 if (err) {
731 netxen_free_adapter_offload(adapter);
732 return err;
733 }
734
735 return 0;
736}
737
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000738static int
739netxen_nic_request_irq(struct netxen_adapter *adapter)
740{
741 irq_handler_t handler;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000742 struct nx_host_sds_ring *sds_ring;
743 int err, ring;
744
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000745 unsigned long flags = IRQF_SAMPLE_RANDOM;
746 struct net_device *netdev = adapter->netdev;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000747 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000748
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000749 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
750 handler = netxen_msix_intr;
751 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
752 handler = netxen_msi_intr;
753 else {
754 flags |= IRQF_SHARED;
755 handler = netxen_intr;
756 }
757 adapter->irq = netdev->irq;
758
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000759 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
760 sds_ring = &recv_ctx->sds_rings[ring];
761 sprintf(sds_ring->name, "%16s[%d]", netdev->name, ring);
762 err = request_irq(sds_ring->irq, handler,
763 flags, sds_ring->name, sds_ring);
764 if (err)
765 return err;
766 }
767
768 return 0;
769}
770
771static void
772netxen_nic_free_irq(struct netxen_adapter *adapter)
773{
774 int ring;
775 struct nx_host_sds_ring *sds_ring;
776
777 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
778
779 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
780 sds_ring = &recv_ctx->sds_rings[ring];
781 free_irq(sds_ring->irq, sds_ring);
782 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000783}
784
785static int
786netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
787{
788 int err;
789
790 err = adapter->init_port(adapter, adapter->physical_port);
791 if (err) {
792 printk(KERN_ERR "%s: Failed to initialize port %d\n",
793 netxen_nic_driver_name, adapter->portnum);
794 return err;
795 }
796 adapter->macaddr_set(adapter, netdev->dev_addr);
797
798 netxen_nic_set_link_parameters(adapter);
799
800 netxen_set_multicast_list(netdev);
801 if (adapter->set_mtu)
802 adapter->set_mtu(adapter, netdev->mtu);
803
804 adapter->ahw.linkup = 0;
805 mod_timer(&adapter->watchdog_timer, jiffies);
806
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000807 netxen_napi_enable(adapter);
808
809 if (adapter->max_sds_rings > 1)
810 netxen_config_rss(adapter, 1);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000811
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000812 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
813 netxen_linkevent_request(adapter, 1);
814
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000815 return 0;
816}
817
818static void
819netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
820{
821 netif_carrier_off(netdev);
822 netif_stop_queue(netdev);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000823 netxen_napi_disable(adapter);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000824
825 if (adapter->stop_port)
826 adapter->stop_port(adapter);
827
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000828 netxen_release_tx_buffers(adapter);
829
830 FLUSH_SCHEDULED_WORK();
831 del_timer_sync(&adapter->watchdog_timer);
832}
833
834
835static int
836netxen_nic_attach(struct netxen_adapter *adapter)
837{
838 struct net_device *netdev = adapter->netdev;
839 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000840 int err, ring;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000841 struct nx_host_rds_ring *rds_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000842 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000843
844 err = netxen_init_firmware(adapter);
845 if (err != 0) {
846 printk(KERN_ERR "Failed to init firmware\n");
847 return -EIO;
848 }
849
850 if (adapter->fw_major < 4)
851 adapter->max_rds_rings = 3;
852 else
853 adapter->max_rds_rings = 2;
854
855 err = netxen_alloc_sw_resources(adapter);
856 if (err) {
857 printk(KERN_ERR "%s: Error in setting sw resources\n",
858 netdev->name);
859 return err;
860 }
861
862 netxen_nic_clear_stats(adapter);
863
864 err = netxen_alloc_hw_resources(adapter);
865 if (err) {
866 printk(KERN_ERR "%s: Error in setting hw resources\n",
867 netdev->name);
868 goto err_out_free_sw;
869 }
870
871 if (adapter->fw_major < 4) {
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000872 tx_ring = &adapter->tx_ring;
873 tx_ring->crb_cmd_producer = crb_cmd_producer[adapter->portnum];
874 tx_ring->crb_cmd_consumer = crb_cmd_consumer[adapter->portnum];
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000875
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000876 netxen_nic_update_cmd_producer(adapter, tx_ring, 0);
877 netxen_nic_update_cmd_consumer(adapter, tx_ring, 0);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000878 }
879
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000880 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
881 rds_ring = &adapter->recv_ctx.rds_rings[ring];
882 netxen_post_rx_buffers(adapter, ring, rds_ring);
883 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000884
885 err = netxen_nic_request_irq(adapter);
886 if (err) {
887 dev_err(&pdev->dev, "%s: failed to setup interrupt\n",
888 netdev->name);
889 goto err_out_free_rxbuf;
890 }
891
892 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
893 return 0;
894
895err_out_free_rxbuf:
896 netxen_release_rx_buffers(adapter);
897 netxen_free_hw_resources(adapter);
898err_out_free_sw:
899 netxen_free_sw_resources(adapter);
900 return err;
901}
902
903static void
904netxen_nic_detach(struct netxen_adapter *adapter)
905{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000906 netxen_nic_free_irq(adapter);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000907
908 netxen_release_rx_buffers(adapter);
909 netxen_free_hw_resources(adapter);
910 netxen_free_sw_resources(adapter);
911
912 adapter->is_up = 0;
913}
914
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400915static int __devinit
916netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
917{
918 struct net_device *netdev = NULL;
919 struct netxen_adapter *adapter = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700920 int i = 0, err;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700921 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700922 uint8_t revision_id;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400923
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700924 if (pdev->class != 0x020000) {
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700925 printk(KERN_DEBUG "NetXen function %d, class %x will not "
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700926 "be enabled.\n",pci_func_id, pdev->class);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800927 return -ENODEV;
928 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700929
Dhananjay Phadke11d89d62008-08-08 00:08:45 -0700930 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
931 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
932 "will not be enabled.\n",
933 NX_P3_A0, NX_P3_B1);
934 return -ENODEV;
935 }
936
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400937 if ((err = pci_enable_device(pdev)))
938 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700939
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400940 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
941 err = -ENODEV;
942 goto err_out_disable_pdev;
943 }
944
945 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
946 goto err_out_disable_pdev;
947
948 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700949
950 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
951 if(!netdev) {
952 printk(KERN_ERR"%s: Failed to allocate memory for the "
953 "device block.Check system memory resource"
954 " usage.\n", netxen_nic_driver_name);
955 goto err_out_free_res;
956 }
957
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700958 SET_NETDEV_DEV(netdev, &pdev->dev);
959
Wang Chen4cf16532008-11-12 23:38:14 -0800960 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700961 adapter->netdev = netdev;
962 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700963 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700964
965 revision_id = pdev->revision;
966 adapter->ahw.revision_id = revision_id;
967
968 err = nx_set_dma_mask(adapter, revision_id);
969 if (err)
970 goto err_out_free_netdev;
971
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700972 rwlock_init(&adapter->adapter_lock);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000973 spin_lock_init(&adapter->tx_clean_lock);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700974
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800975 err = netxen_setup_pci_map(adapter);
976 if (err)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700977 goto err_out_free_netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400978
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +0530979 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700980 adapter->portnum = pci_func_id;
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530981 adapter->rx_csum = 1;
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700982 adapter->mc_enabled = 0;
Dhananjay Phadke83821a02008-08-01 03:14:58 -0700983 if (NX_IS_REVISION_P3(revision_id))
Dhananjay Phadke29566402008-07-21 19:44:04 -0700984 adapter->max_mc_count = 38;
Dhananjay Phadke83821a02008-08-01 03:14:58 -0700985 else
Dhananjay Phadke29566402008-07-21 19:44:04 -0700986 adapter->max_mc_count = 16;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700987
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800988 netdev->netdev_ops = &netxen_netdev_ops;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -0700989 netdev->watchdog_timeo = 2*HZ;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700990
991 netxen_nic_change_mtu(netdev, netdev->mtu);
992
993 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800994
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800995 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
996 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
997
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700998 if (NX_IS_REVISION_P3(revision_id)) {
Dhananjay Phadkecdff1032009-01-26 12:34:57 -0800999 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1000 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001001 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001002
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001003 if (adapter->pci_using_dac) {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001004 netdev->features |= NETIF_F_HIGHDMA;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001005 netdev->vlan_features |= NETIF_F_HIGHDMA;
1006 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001007
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001008 if (netxen_nic_get_board_info(adapter) != 0) {
1009 printk("%s: Error getting board config info.\n",
Dhananjay Phadke29566402008-07-21 19:44:04 -07001010 netxen_nic_driver_name);
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001011 err = -EIO;
1012 goto err_out_iounmap;
1013 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001014
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001015 netxen_initialize_adapter_ops(adapter);
1016
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001017 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001018 switch (adapter->ahw.board_type) {
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001019 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1020 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1021 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001022 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001023 break;
1024 default:
1025 break;
1026 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001027
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001028 err = netxen_start_firmware(adapter);
1029 if (err)
1030 goto err_out_iounmap;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001031
Dhananjay Phadke1f434f62009-03-02 16:02:16 +00001032 nx_update_dma_mask(adapter);
1033
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001034 netxen_nic_get_firmware_info(adapter);
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001035
Dhananjay Phadke29566402008-07-21 19:44:04 -07001036 /*
1037 * See if the firmware gave us a virtual-physical port mapping.
1038 */
1039 adapter->physical_port = adapter->portnum;
Dhananjay Phadke044fad02009-02-24 03:42:59 -08001040 if (adapter->fw_major < 4) {
1041 i = adapter->pci_read_normalize(adapter,
1042 CRB_V2P(adapter->portnum));
1043 if (i != 0x55555555)
1044 adapter->physical_port = i;
1045 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001046
Dhananjay Phadke438627c2009-03-13 14:52:03 +00001047 netxen_check_options(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001048
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001049 netxen_setup_intr(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001050
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001051 netdev->irq = adapter->msix_entries[0].vector;
1052
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +00001053 if (netxen_napi_add(adapter, netdev))
1054 goto err_out_disable_msi;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001055
Dhananjay Phadke29566402008-07-21 19:44:04 -07001056 init_timer(&adapter->watchdog_timer);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001057 adapter->watchdog_timer.function = &netxen_watchdog;
1058 adapter->watchdog_timer.data = (unsigned long)adapter;
1059 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
1060 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
1061
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001062 err = netxen_read_mac_addr(adapter);
1063 if (err)
1064 dev_warn(&pdev->dev, "failed to read mac addr\n");
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001065
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001066 netif_carrier_off(netdev);
1067 netif_stop_queue(netdev);
1068
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001069 if ((err = register_netdev(netdev))) {
1070 printk(KERN_ERR "%s: register_netdev failed port #%d"
1071 " aborting\n", netxen_nic_driver_name,
1072 adapter->portnum);
1073 err = -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001074 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001075 }
1076
1077 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001078
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001079 switch (adapter->ahw.port_type) {
Dhananjay Phadke29566402008-07-21 19:44:04 -07001080 case NETXEN_NIC_GBE:
1081 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1082 adapter->netdev->name);
1083 break;
1084 case NETXEN_NIC_XGBE:
1085 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1086 adapter->netdev->name);
1087 break;
1088 }
1089
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001090 return 0;
1091
Dhananjay Phadke29566402008-07-21 19:44:04 -07001092err_out_disable_msi:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001093 netxen_teardown_intr(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001094
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001095 netxen_free_adapter_offload(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001096
Dhananjay Phadke29566402008-07-21 19:44:04 -07001097err_out_iounmap:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001098 netxen_cleanup_pci_map(adapter);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001099
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001100err_out_free_netdev:
1101 free_netdev(netdev);
1102
1103err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001104 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001105
1106err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001107 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001108 pci_disable_device(pdev);
1109 return err;
1110}
1111
1112static void __devexit netxen_nic_remove(struct pci_dev *pdev)
1113{
1114 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001115 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001116
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001117 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001118 if (adapter == NULL)
1119 return;
1120
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001121 netdev = adapter->netdev;
1122
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301123 unregister_netdev(netdev);
1124
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301125 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001126 netxen_nic_detach(adapter);
Dhananjay Phadke06e9d9f2009-01-14 20:49:22 -08001127
1128 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1129 netxen_p3_free_mac_list(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301130 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001131
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001132 if (adapter->portnum == 0)
1133 netxen_free_adapter_offload(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301134
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001135 netxen_teardown_intr(adapter);
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +00001136 netxen_free_sds_rings(&adapter->recv_ctx);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301137
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001138 netxen_cleanup_pci_map(adapter);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001139
1140 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301141 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001142 pci_set_drvdata(pdev, NULL);
1143
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001144 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001145}
1146
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001147static int
1148netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
1149{
1150
1151 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1152 struct net_device *netdev = adapter->netdev;
1153
1154 netif_device_detach(netdev);
1155
1156 if (netif_running(netdev))
1157 netxen_nic_down(adapter, netdev);
1158
1159 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
1160 netxen_nic_detach(adapter);
1161
1162 pci_save_state(pdev);
1163
1164 if (netxen_nic_wol_supported(adapter)) {
1165 pci_enable_wake(pdev, PCI_D3cold, 1);
1166 pci_enable_wake(pdev, PCI_D3hot, 1);
1167 }
1168
1169 pci_disable_device(pdev);
1170 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1171
1172 return 0;
1173}
1174
1175static int
1176netxen_nic_resume(struct pci_dev *pdev)
1177{
1178 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1179 struct net_device *netdev = adapter->netdev;
1180 int err;
1181
1182 pci_set_power_state(pdev, PCI_D0);
1183 pci_restore_state(pdev);
1184
1185 err = pci_enable_device(pdev);
1186 if (err)
1187 return err;
1188
1189 adapter->curr_window = 255;
1190
1191 err = netxen_start_firmware(adapter);
1192 if (err) {
1193 dev_err(&pdev->dev, "failed to start firmware\n");
1194 return err;
1195 }
1196
1197 if (netif_running(netdev)) {
1198 err = netxen_nic_attach(adapter);
1199 if (err)
1200 return err;
1201
1202 err = netxen_nic_up(adapter, netdev);
1203 if (err)
1204 return err;
1205
1206 netif_device_attach(netdev);
1207 }
1208
1209 return 0;
1210}
1211
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001212static int netxen_nic_open(struct net_device *netdev)
1213{
Wang Chen4cf16532008-11-12 23:38:14 -08001214 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001215 int err = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001216
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001217 if (adapter->driver_mismatch)
1218 return -EIO;
1219
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001220 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) {
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001221 err = netxen_nic_attach(adapter);
1222 if (err)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001223 return err;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001224 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001225
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001226 err = netxen_nic_up(adapter, netdev);
1227 if (err)
1228 goto err_out;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001229
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001230 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001231
1232 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001233
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001234err_out:
1235 netxen_nic_detach(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001236 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001237}
1238
1239/*
1240 * netxen_nic_close - Disables a network interface entry point
1241 */
1242static int netxen_nic_close(struct net_device *netdev)
1243{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001244 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001245
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001246 netxen_nic_down(adapter, netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001247 return 0;
1248}
1249
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001250static bool netxen_tso_check(struct net_device *netdev,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001251 struct cmd_desc_type0 *desc, struct sk_buff *skb)
1252{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001253 bool tso = false;
1254 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001255 __be16 protocol = skb->protocol;
1256 u16 flags = 0;
1257
Harvey Harrison09640e62009-02-01 00:45:17 -08001258 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001259 struct vlan_ethhdr *vh = (struct vlan_ethhdr *)skb->data;
1260 protocol = vh->h_vlan_encapsulated_proto;
1261 flags = FLAGS_VLAN_TAGGED;
1262 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001263
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001264 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1265 skb_shinfo(skb)->gso_size > 0) {
1266
1267 desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1268 desc->total_hdr_length =
1269 skb_transport_offset(skb) + tcp_hdrlen(skb);
1270
Harvey Harrison09640e62009-02-01 00:45:17 -08001271 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001272 TX_TCP_LSO6 : TX_TCP_LSO;
1273 tso = true;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001274
1275 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001276 u8 l4proto;
1277
Harvey Harrison09640e62009-02-01 00:45:17 -08001278 if (protocol == cpu_to_be16(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001279 l4proto = ip_hdr(skb)->protocol;
1280
1281 if (l4proto == IPPROTO_TCP)
1282 opcode = TX_TCP_PKT;
1283 else if(l4proto == IPPROTO_UDP)
1284 opcode = TX_UDP_PKT;
Harvey Harrison09640e62009-02-01 00:45:17 -08001285 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001286 l4proto = ipv6_hdr(skb)->nexthdr;
1287
1288 if (l4proto == IPPROTO_TCP)
1289 opcode = TX_TCPV6_PKT;
1290 else if(l4proto == IPPROTO_UDP)
1291 opcode = TX_UDPV6_PKT;
1292 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001293 }
1294 desc->tcp_hdr_offset = skb_transport_offset(skb);
1295 desc->ip_hdr_offset = skb_network_offset(skb);
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001296 netxen_set_tx_flags_opcode(desc, flags, opcode);
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001297 return tso;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001298}
1299
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001300static void
1301netxen_clean_tx_dma_mapping(struct pci_dev *pdev,
1302 struct netxen_cmd_buffer *pbuf, int last)
1303{
1304 int k;
1305 struct netxen_skb_frag *buffrag;
1306
1307 buffrag = &pbuf->frag_array[0];
1308 pci_unmap_single(pdev, buffrag->dma,
1309 buffrag->length, PCI_DMA_TODEVICE);
1310
1311 for (k = 1; k < last; k++) {
1312 buffrag = &pbuf->frag_array[k];
1313 pci_unmap_page(pdev, buffrag->dma,
1314 buffrag->length, PCI_DMA_TODEVICE);
1315 }
1316}
1317
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001318static inline void
1319netxen_clear_cmddesc(u64 *desc)
1320{
1321 int i;
1322 for (i = 0; i < 8; i++)
1323 desc[i] = 0ULL;
1324}
1325
1326static int
1327netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001328{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001329 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001330 struct nx_host_tx_ring *tx_ring = &adapter->tx_ring;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001331 unsigned int first_seg_len = skb->len - skb->data_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001332 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001333 struct netxen_skb_frag *buffrag;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001334 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001335 struct pci_dev *pdev = adapter->pdev;
1336 dma_addr_t temp_dma;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001337 int i, k;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001338
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001339 u32 producer, consumer;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001340 int frag_count, no_of_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001341 u32 num_txd = tx_ring->num_desc;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001342 bool is_tso = false;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001343
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001344 frag_count = skb_shinfo(skb)->nr_frags + 1;
1345
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001346 /* 4 fragments per cmd des */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001347 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001348
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001349 producer = tx_ring->producer;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001350 smp_mb();
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001351 consumer = tx_ring->sw_consumer;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001352 if ((no_of_desc+2) > find_diff_among(producer, consumer, num_txd)) {
1353 netif_stop_queue(netdev);
1354 smp_mb();
1355 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001356 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001357
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001358 hwdesc = &tx_ring->desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001359 netxen_clear_cmddesc((u64 *)hwdesc);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001360 pbuf = &tx_ring->cmd_buf_arr[producer];
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001361
1362 is_tso = netxen_tso_check(netdev, hwdesc, skb);
1363
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001364 pbuf->skb = skb;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001365 pbuf->frag_count = frag_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001366 buffrag = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001367 temp_dma = pci_map_single(pdev, skb->data, first_seg_len,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001368 PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001369 if (pci_dma_mapping_error(pdev, temp_dma))
1370 goto drop_packet;
1371
1372 buffrag->dma = temp_dma;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001373 buffrag->length = first_seg_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001374 netxen_set_tx_frags_len(hwdesc, frag_count, skb->len);
1375 netxen_set_tx_port(hwdesc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001376
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001377 hwdesc->buffer_length[0] = cpu_to_le16(first_seg_len);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001378 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
1379
1380 for (i = 1, k = 1; i < frag_count; i++, k++) {
1381 struct skb_frag_struct *frag;
1382 int len, temp_len;
1383 unsigned long offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001384
1385 /* move to next desc. if there is a need */
1386 if ((i & 0x3) == 0) {
1387 k = 0;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001388 producer = get_next_index(producer, num_txd);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001389 hwdesc = &tx_ring->desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001390 netxen_clear_cmddesc((u64 *)hwdesc);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001391 pbuf = &tx_ring->cmd_buf_arr[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001392 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001393 }
1394 frag = &skb_shinfo(skb)->frags[i - 1];
1395 len = frag->size;
1396 offset = frag->page_offset;
1397
1398 temp_len = len;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001399 temp_dma = pci_map_page(pdev, frag->page, offset,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001400 len, PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001401 if (pci_dma_mapping_error(pdev, temp_dma)) {
1402 netxen_clean_tx_dma_mapping(pdev, pbuf, i);
1403 goto drop_packet;
1404 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001405
1406 buffrag++;
1407 buffrag->dma = temp_dma;
1408 buffrag->length = temp_len;
1409
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001410 hwdesc->buffer_length[k] = cpu_to_le16(temp_len);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001411 switch (k) {
1412 case 0:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001413 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
1414 break;
1415 case 1:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001416 hwdesc->addr_buffer2 = cpu_to_le64(temp_dma);
1417 break;
1418 case 2:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001419 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
1420 break;
1421 case 3:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001422 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
1423 break;
1424 }
1425 frag++;
1426 }
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001427 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001428
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001429 /* For LSO, we need to copy the MAC/IP/TCP headers into
1430 * the descriptor ring
1431 */
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001432 if (is_tso) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001433 int hdr_len, first_hdr_len, more_hdr;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001434 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001435 if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) {
1436 first_hdr_len = sizeof(struct cmd_desc_type0) - 2;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001437 more_hdr = 1;
1438 } else {
1439 first_hdr_len = hdr_len;
1440 more_hdr = 0;
1441 }
1442 /* copy the MAC/IP/TCP headers to the cmd descriptor list */
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001443 hwdesc = &tx_ring->desc_head[producer];
1444 pbuf = &tx_ring->cmd_buf_arr[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001445 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001446
1447 /* copy the first 64 bytes */
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001448 memcpy(((void *)hwdesc) + 2,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001449 (void *)(skb->data), first_hdr_len);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001450 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001451
1452 if (more_hdr) {
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001453 hwdesc = &tx_ring->desc_head[producer];
1454 pbuf = &tx_ring->cmd_buf_arr[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001455 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001456 /* copy the next 64 bytes - should be enough except
1457 * for pathological case
1458 */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001459 skb_copy_from_linear_data_offset(skb, first_hdr_len,
1460 hwdesc,
1461 (hdr_len -
1462 first_hdr_len));
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001463 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001464 }
1465 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001466
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001467 tx_ring->producer = producer;
Dhananjay Phadke5dc16262007-12-31 10:08:57 -08001468 adapter->stats.txbytes += skb->len;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001469
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001470 netxen_nic_update_cmd_producer(adapter, tx_ring, producer);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001471
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001472 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001473 netdev->trans_start = jiffies;
1474
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001475 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001476
1477drop_packet:
1478 adapter->stats.txdropped++;
1479 dev_kfree_skb_any(skb);
1480 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001481}
1482
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001483static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1484{
1485 struct net_device *netdev = adapter->netdev;
1486 uint32_t temp, temp_state, temp_val;
1487 int rv = 0;
1488
1489 temp = adapter->pci_read_normalize(adapter, CRB_TEMP_STATE);
1490
1491 temp_state = nx_get_temp_state(temp);
1492 temp_val = nx_get_temp_val(temp);
1493
1494 if (temp_state == NX_TEMP_PANIC) {
1495 printk(KERN_ALERT
1496 "%s: Device temperature %d degrees C exceeds"
1497 " maximum allowed. Hardware has been shut down.\n",
1498 netxen_nic_driver_name, temp_val);
1499
1500 netif_carrier_off(netdev);
1501 netif_stop_queue(netdev);
1502 rv = 1;
1503 } else if (temp_state == NX_TEMP_WARN) {
1504 if (adapter->temp == NX_TEMP_NORMAL) {
1505 printk(KERN_ALERT
1506 "%s: Device temperature %d degrees C "
1507 "exceeds operating range."
1508 " Immediate action needed.\n",
1509 netxen_nic_driver_name, temp_val);
1510 }
1511 } else {
1512 if (adapter->temp == NX_TEMP_WARN) {
1513 printk(KERN_INFO
1514 "%s: Device temperature is now %d degrees C"
1515 " in normal range.\n", netxen_nic_driver_name,
1516 temp_val);
1517 }
1518 }
1519 adapter->temp = temp_state;
1520 return rv;
1521}
1522
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001523void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup)
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001524{
1525 struct net_device *netdev = adapter->netdev;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001526
1527 if (adapter->ahw.linkup && !linkup) {
1528 printk(KERN_INFO "%s: %s NIC Link is down\n",
1529 netxen_nic_driver_name, netdev->name);
1530 adapter->ahw.linkup = 0;
1531 if (netif_running(netdev)) {
1532 netif_carrier_off(netdev);
1533 netif_stop_queue(netdev);
1534 }
1535
1536 if (!adapter->has_link_events)
1537 netxen_nic_set_link_parameters(adapter);
1538
1539 } else if (!adapter->ahw.linkup && linkup) {
1540 printk(KERN_INFO "%s: %s NIC Link is up\n",
1541 netxen_nic_driver_name, netdev->name);
1542 adapter->ahw.linkup = 1;
1543 if (netif_running(netdev)) {
1544 netif_carrier_on(netdev);
1545 netif_wake_queue(netdev);
1546 }
1547
1548 if (!adapter->has_link_events)
1549 netxen_nic_set_link_parameters(adapter);
1550 }
1551}
1552
1553static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1554{
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001555 u32 val, port, linkup;
1556
1557 port = adapter->physical_port;
1558
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001559 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1560 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE_P3);
1561 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1562 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001563 } else {
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001564 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001565 if (adapter->ahw.port_type == NETXEN_NIC_GBE)
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001566 linkup = (val >> port) & 1;
1567 else {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001568 val = (val >> port*8) & 0xff;
1569 linkup = (val == XG_LINK_UP);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001570 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001571 }
1572
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001573 netxen_advert_link_change(adapter, linkup);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001574}
1575
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001576static void netxen_watchdog(unsigned long v)
1577{
1578 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001579
1580 SCHEDULE_WORK(&adapter->watchdog_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001581}
1582
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001583void netxen_watchdog_task(struct work_struct *work)
1584{
1585 struct netxen_adapter *adapter =
1586 container_of(work, struct netxen_adapter, watchdog_task);
1587
1588 if ((adapter->portnum == 0) && netxen_nic_check_temp(adapter))
1589 return;
1590
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001591 if (!adapter->has_link_events)
1592 netxen_nic_handle_phy_intr(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001593
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001594 if (netif_running(adapter->netdev))
1595 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001596}
1597
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001598static void netxen_tx_timeout(struct net_device *netdev)
1599{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001600 struct netxen_adapter *adapter = (struct netxen_adapter *)
1601 netdev_priv(netdev);
1602 SCHEDULE_WORK(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001603}
1604
David Howells6d5aefb2006-12-05 19:36:26 +00001605static void netxen_tx_timeout_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001606{
Jeff Garzik47906542007-11-23 21:23:36 -05001607 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001608 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001609
1610 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001611 netxen_nic_driver_name, adapter->netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001612
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001613 netxen_napi_disable(adapter);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001614
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001615 adapter->netdev->trans_start = jiffies;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001616
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001617 netxen_napi_enable(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001618 netif_wake_queue(adapter->netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001619}
1620
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001621struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1622{
1623 struct netxen_adapter *adapter = netdev_priv(netdev);
1624 struct net_device_stats *stats = &adapter->net_stats;
1625
1626 memset(stats, 0, sizeof(*stats));
1627
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001628 stats->rx_packets = adapter->stats.no_rcv;
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00001629 stats->tx_packets = adapter->stats.xmitfinished;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001630 stats->rx_bytes = adapter->stats.rxbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001631 stats->tx_bytes = adapter->stats.txbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001632 stats->rx_dropped = adapter->stats.rxdropped;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001633 stats->tx_dropped = adapter->stats.txdropped;
1634
1635 return stats;
1636}
1637
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001638static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001639{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001640 struct nx_host_sds_ring *sds_ring = data;
1641 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001642 u32 status = 0;
1643
1644 status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1645
1646 if (!(status & adapter->legacy_intr.int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001647 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301648
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001649 if (adapter->ahw.revision_id >= NX_P3_B1) {
1650 /* check interrupt state machine, to be sure */
1651 status = adapter->pci_read_immediate(adapter,
1652 ISR_INT_STATE_REG);
1653 if (!ISR_LEGACY_INT_TRIGGERED(status))
1654 return IRQ_NONE;
1655
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001656 } else {
1657 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001658
1659 our_int = adapter->pci_read_normalize(adapter, CRB_INT_VECTOR);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001660
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001661 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001662 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001663 return IRQ_NONE;
1664
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001665 /* claim interrupt */
1666 adapter->pci_write_normalize(adapter,
1667 CRB_INT_VECTOR, (our_int & 0xffffffff));
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301668 }
1669
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001670 /* clear interrupt */
1671 if (adapter->fw_major < 4)
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001672 netxen_nic_disable_int(sds_ring);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001673
1674 adapter->pci_write_immediate(adapter,
1675 adapter->legacy_intr.tgt_status_reg,
1676 0xffffffff);
1677 /* read twice to ensure write is flushed */
1678 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1679 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1680
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001681 napi_schedule(&sds_ring->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001682
1683 return IRQ_HANDLED;
1684}
1685
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001686static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001687{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001688 struct nx_host_sds_ring *sds_ring = data;
1689 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001690
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001691 /* clear interrupt */
1692 adapter->pci_write_immediate(adapter,
1693 msi_tgt_status[adapter->ahw.pci_func], 0xffffffff);
1694
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001695 napi_schedule(&sds_ring->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001696 return IRQ_HANDLED;
1697}
1698
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001699static irqreturn_t netxen_msix_intr(int irq, void *data)
1700{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001701 struct nx_host_sds_ring *sds_ring = data;
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001702
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001703 napi_schedule(&sds_ring->napi);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001704 return IRQ_HANDLED;
1705}
1706
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001707static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001708{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001709 struct nx_host_sds_ring *sds_ring =
1710 container_of(napi, struct nx_host_sds_ring, napi);
1711
1712 struct netxen_adapter *adapter = sds_ring->adapter;
1713
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001714 int tx_complete;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001715 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001716
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001717 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001718
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001719 work_done = netxen_process_rcv_ring(sds_ring, budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001720
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001721 if ((work_done < budget) && tx_complete) {
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001722 napi_complete(&sds_ring->napi);
1723 netxen_nic_enable_int(sds_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001724 }
1725
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001726 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001727}
1728
1729#ifdef CONFIG_NET_POLL_CONTROLLER
1730static void netxen_nic_poll_controller(struct net_device *netdev)
1731{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001732 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001733 disable_irq(adapter->irq);
Jeff Garzik1494a812006-11-07 05:12:16 -05001734 netxen_intr(adapter->irq, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001735 enable_irq(adapter->irq);
1736}
1737#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001738
1739static struct pci_driver netxen_driver = {
1740 .name = netxen_nic_driver_name,
1741 .id_table = netxen_pci_tbl,
1742 .probe = netxen_nic_probe,
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001743 .remove = __devexit_p(netxen_nic_remove),
1744 .suspend = netxen_nic_suspend,
1745 .resume = netxen_nic_resume
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001746};
1747
1748/* Driver Registration on NetXen card */
1749
1750static int __init netxen_init_module(void)
1751{
Dhananjay Phadkeff4fbd42009-03-13 14:52:06 +00001752 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
1753
Al Viro79ea13c2008-01-24 02:06:46 -08001754 if ((netxen_workq = create_singlethread_workqueue("netxen")) == NULL)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001755 return -ENOMEM;
1756
Amit S. Kale184231b2007-01-22 06:52:53 -08001757 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001758}
1759
1760module_init(netxen_init_module);
1761
1762static void __exit netxen_exit_module(void)
1763{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001764 pci_unregister_driver(&netxen_driver);
Amit S. Kale9de06612007-02-21 06:37:06 -08001765 destroy_workqueue(netxen_workq);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001766}
1767
1768module_exit(netxen_exit_module);