blob: 2919a2d12bf40c5327f4979059eed3ea1de78878 [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,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000110 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700111{
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000112 NXWR32(adapter, tx_ring->crb_cmd_producer, tx_ring->producer);
113
114 if (netxen_tx_avail(tx_ring) <= TX_STOP_THRESH) {
115 netif_stop_queue(adapter->netdev);
116 smp_mb();
117 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700118}
119
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700120static uint32_t crb_cmd_consumer[4] = {
121 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
122 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
123};
124
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700125static inline void
126netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000127 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700128{
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000129 NXWR32(adapter, tx_ring->crb_cmd_consumer, tx_ring->sw_consumer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700130}
131
Dhananjay Phadke29566402008-07-21 19:44:04 -0700132static uint32_t msi_tgt_status[8] = {
Dhananjay Phadke443be792008-03-17 19:59:48 -0700133 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700134 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
135 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
136 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
Dhananjay Phadke443be792008-03-17 19:59:48 -0700137};
138
Dhananjay Phadke29566402008-07-21 19:44:04 -0700139static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
140
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000141static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700142{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000143 struct netxen_adapter *adapter = sds_ring->adapter;
144
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000145 NXWR32(adapter, sds_ring->crb_intr_mask, 0);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700146}
147
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000148static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700149{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000150 struct netxen_adapter *adapter = sds_ring->adapter;
151
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000152 NXWR32(adapter, sds_ring->crb_intr_mask, 0x1);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700153
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700154 if (!NETXEN_IS_MSI_FAMILY(adapter))
155 adapter->pci_write_immediate(adapter,
156 adapter->legacy_intr.tgt_mask_reg, 0xfbff);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700157}
158
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000159static int
160netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count)
161{
162 int size = sizeof(struct nx_host_sds_ring) * count;
163
164 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
165
166 return (recv_ctx->sds_rings == NULL);
167}
168
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000169static void
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000170netxen_free_sds_rings(struct netxen_recv_context *recv_ctx)
171{
172 if (recv_ctx->sds_rings != NULL)
173 kfree(recv_ctx->sds_rings);
174}
175
176static int
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000177netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
178{
179 int ring;
180 struct nx_host_sds_ring *sds_ring;
181 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
182
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000183 if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
184 return 1;
185
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000186 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
187 sds_ring = &recv_ctx->sds_rings[ring];
188 netif_napi_add(netdev, &sds_ring->napi,
189 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
190 }
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000191
192 return 0;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000193}
194
195static void
196netxen_napi_enable(struct netxen_adapter *adapter)
197{
198 int ring;
199 struct nx_host_sds_ring *sds_ring;
200 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
201
202 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
203 sds_ring = &recv_ctx->sds_rings[ring];
204 napi_enable(&sds_ring->napi);
205 netxen_nic_enable_int(sds_ring);
206 }
207}
208
209static void
210netxen_napi_disable(struct netxen_adapter *adapter)
211{
212 int ring;
213 struct nx_host_sds_ring *sds_ring;
214 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
215
216 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
217 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000218 napi_disable(&sds_ring->napi);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000219 netxen_nic_disable_int(sds_ring);
220 synchronize_irq(sds_ring->irq);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000221 }
222}
223
Dhananjay Phadke29566402008-07-21 19:44:04 -0700224static int nx_set_dma_mask(struct netxen_adapter *adapter, uint8_t revision_id)
225{
226 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000227 uint64_t mask, cmask;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700228
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000229 adapter->pci_using_dac = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700230
Yang Hongyang6afd1422009-04-06 19:01:15 -0700231 mask = DMA_BIT_MASK(32);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700232 /*
233 * Consistent DMA mask is set to 32 bit because it cannot be set to
234 * 35 bits. For P3 also leave it at 32 bits for now. Only the rings
235 * come off this pool.
236 */
Yang Hongyang6afd1422009-04-06 19:01:15 -0700237 cmask = DMA_BIT_MASK(32);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000238
239#ifndef CONFIG_IA64
240 if (revision_id >= NX_P3_B0)
Yang Hongyang6afd1422009-04-06 19:01:15 -0700241 mask = DMA_BIT_MASK(39);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000242 else if (revision_id == NX_P2_C1)
Yang Hongyang6afd1422009-04-06 19:01:15 -0700243 mask = DMA_BIT_MASK(35);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000244#endif
Dhananjay Phadke29566402008-07-21 19:44:04 -0700245 if (pci_set_dma_mask(pdev, mask) == 0 &&
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000246 pci_set_consistent_dma_mask(pdev, cmask) == 0) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700247 adapter->pci_using_dac = 1;
248 return 0;
249 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700250
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000251 return -EIO;
252}
253
254/* Update addressable range if firmware supports it */
255static int
256nx_update_dma_mask(struct netxen_adapter *adapter)
257{
258 int change, shift, err;
259 uint64_t mask, old_mask;
260 struct pci_dev *pdev = adapter->pdev;
261
262 change = 0;
263
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000264 shift = NXRD32(adapter, CRB_DMA_SHIFT);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000265 if (shift >= 32)
266 return 0;
267
268 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9))
269 change = 1;
270 else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4))
271 change = 1;
272
273 if (change) {
274 old_mask = pdev->dma_mask;
275 mask = (1ULL<<(32+shift)) - 1;
276
277 err = pci_set_dma_mask(pdev, mask);
278 if (err)
279 return pci_set_dma_mask(pdev, old_mask);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700280 }
281
Dhananjay Phadke29566402008-07-21 19:44:04 -0700282 return 0;
283}
284
285static void netxen_check_options(struct netxen_adapter *adapter)
286{
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000287 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
288 adapter->num_rxd = MAX_RCV_DESCRIPTORS_10G;
289 else if (adapter->ahw.port_type == NETXEN_NIC_GBE)
290 adapter->num_rxd = MAX_RCV_DESCRIPTORS_1G;
291
Dhananjay Phadkef6d21f42009-04-07 22:50:46 +0000292 adapter->msix_supported = 0;
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 Phadkef6d21f42009-04-07 22:50:46 +0000295 adapter->rss_supported = !!use_msi_x;
296 } else if (adapter->fw_version >= NETXEN_VERSION_CODE(3, 4, 336)) {
297 switch (adapter->ahw.board_type) {
298 case NETXEN_BRDTYPE_P2_SB31_10G:
299 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkef6d21f42009-04-07 22:50:46 +0000300 adapter->msix_supported = !!use_msi_x;
301 adapter->rss_supported = !!use_msi_x;
302 break;
303 default:
304 break;
305 }
306 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700307
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000308 adapter->num_txd = MAX_CMD_DESCRIPTORS_HOST;
309 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS;
310 adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700311
Dhananjay Phadke29566402008-07-21 19:44:04 -0700312 return;
313}
314
315static int
316netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
317{
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800318 u32 val, timeout;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700319
320 if (first_boot == 0x55555555) {
321 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000322 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800323
324 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
325 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700326
327 /* PCI bus master workaround */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000328 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700329 if (!(first_boot & 0x4)) {
330 first_boot |= 0x4;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000331 NXWR32(adapter, NETXEN_PCIE_REG(0x4), first_boot);
332 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700333 }
334
335 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000336 first_boot = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700337 if (first_boot != 0x80000f) {
338 /* clear the register for future unloads/loads */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000339 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), 0);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800340 return -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700341 }
342
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800343 /* Start P2 boot loader */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000344 val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
345 NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800346 timeout = 0;
347 do {
348 msleep(1);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000349 val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800350
351 if (++timeout > 5000)
352 return -EIO;
353
354 } while (val == NETXEN_BDINFO_MAGIC);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700355 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800356 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700357}
358
359static void netxen_set_port_mode(struct netxen_adapter *adapter)
360{
361 u32 val, data;
362
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000363 val = adapter->ahw.board_type;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700364 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
365 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
366 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
367 data = NETXEN_PORT_MODE_802_3_AP;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000368 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700369 } else if (port_mode == NETXEN_PORT_MODE_XG) {
370 data = NETXEN_PORT_MODE_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000371 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700372 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
373 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000374 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700375 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
376 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000377 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700378 } else {
379 data = NETXEN_PORT_MODE_AUTO_NEG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000380 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700381 }
382
383 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
384 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
385 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
386 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
387 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
388 }
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000389 NXWR32(adapter, NETXEN_WOL_PORT_MODE, wol_port_mode);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700390 }
391}
392
Dhananjay Phadke29566402008-07-21 19:44:04 -0700393static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
394{
395 u32 control;
396 int pos;
397
398 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
399 if (pos) {
400 pci_read_config_dword(pdev, pos, &control);
401 if (enable)
402 control |= PCI_MSIX_FLAGS_ENABLE;
403 else
404 control = 0;
405 pci_write_config_dword(pdev, pos, control);
406 }
407}
408
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000409static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700410{
411 int i;
412
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000413 for (i = 0; i < count; i++)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700414 adapter->msix_entries[i].entry = i;
415}
416
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700417static int
418netxen_read_mac_addr(struct netxen_adapter *adapter)
419{
420 int i;
421 unsigned char *p;
422 __le64 mac_addr;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700423 struct net_device *netdev = adapter->netdev;
424 struct pci_dev *pdev = adapter->pdev;
425
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700426 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
427 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
428 return -EIO;
429 } else {
430 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
431 return -EIO;
432 }
433
434 p = (unsigned char *)&mac_addr;
435 for (i = 0; i < 6; i++)
436 netdev->dev_addr[i] = *(p + 5 - i);
437
438 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
439
440 /* set station address */
441
Johannes Berge1749612008-10-27 15:59:26 -0700442 if (!is_valid_ether_addr(netdev->perm_addr))
443 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700444
445 return 0;
446}
447
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000448int netxen_nic_set_mac(struct net_device *netdev, void *p)
449{
450 struct netxen_adapter *adapter = netdev_priv(netdev);
451 struct sockaddr *addr = p;
452
453 if (!is_valid_ether_addr(addr->sa_data))
454 return -EINVAL;
455
456 if (netif_running(netdev)) {
457 netif_device_detach(netdev);
458 netxen_napi_disable(adapter);
459 }
460
461 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
462 adapter->macaddr_set(adapter, addr->sa_data);
463
464 if (netif_running(netdev)) {
465 netif_device_attach(netdev);
466 netxen_napi_enable(adapter);
467 }
468 return 0;
469}
470
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800471static void netxen_set_multicast_list(struct net_device *dev)
472{
473 struct netxen_adapter *adapter = netdev_priv(dev);
474
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000475 adapter->set_multi(dev);
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800476}
477
478static const struct net_device_ops netxen_netdev_ops = {
479 .ndo_open = netxen_nic_open,
480 .ndo_stop = netxen_nic_close,
481 .ndo_start_xmit = netxen_nic_xmit_frame,
482 .ndo_get_stats = netxen_nic_get_stats,
483 .ndo_validate_addr = eth_validate_addr,
484 .ndo_set_multicast_list = netxen_set_multicast_list,
485 .ndo_set_mac_address = netxen_nic_set_mac,
486 .ndo_change_mtu = netxen_nic_change_mtu,
487 .ndo_tx_timeout = netxen_tx_timeout,
488#ifdef CONFIG_NET_POLL_CONTROLLER
489 .ndo_poll_controller = netxen_nic_poll_controller,
490#endif
491};
492
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800493static void
494netxen_setup_intr(struct netxen_adapter *adapter)
495{
496 struct netxen_legacy_intr_set *legacy_intrp;
497 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000498 int err, num_msix;
499
500 if (adapter->rss_supported) {
501 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
502 MSIX_ENTRIES_PER_ADAPTER : 2;
503 } else
504 num_msix = 1;
505
506 adapter->max_sds_rings = 1;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800507
508 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800509
510 if (adapter->ahw.revision_id >= NX_P3_B0)
511 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
512 else
513 legacy_intrp = &legacy_intr[0];
514 adapter->legacy_intr.int_vec_bit = legacy_intrp->int_vec_bit;
515 adapter->legacy_intr.tgt_status_reg = legacy_intrp->tgt_status_reg;
516 adapter->legacy_intr.tgt_mask_reg = legacy_intrp->tgt_mask_reg;
517 adapter->legacy_intr.pci_int_reg = legacy_intrp->pci_int_reg;
518
519 netxen_set_msix_bit(pdev, 0);
520
521 if (adapter->msix_supported) {
522
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000523 netxen_init_msix_entries(adapter, num_msix);
524 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
525 if (err == 0) {
526 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
527 netxen_set_msix_bit(pdev, 1);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800528
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000529 if (adapter->rss_supported)
530 adapter->max_sds_rings = num_msix;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800531
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000532 dev_info(&pdev->dev, "using msi-x interrupts\n");
533 return;
534 }
535
536 if (err > 0)
537 pci_disable_msix(pdev);
538
539 /* fall through for msi */
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800540 }
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000541
542 if (use_msi && !pci_enable_msi(pdev)) {
543 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
544 adapter->msi_tgt_status =
545 msi_tgt_status[adapter->ahw.pci_func];
546 dev_info(&pdev->dev, "using msi interrupts\n");
Dhananjay Phadkef67f3402009-05-18 21:46:40 -0700547 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000548 return;
549 }
550
551 dev_info(&pdev->dev, "using legacy interrupts\n");
552 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800553}
554
555static void
556netxen_teardown_intr(struct netxen_adapter *adapter)
557{
558 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
559 pci_disable_msix(adapter->pdev);
560 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
561 pci_disable_msi(adapter->pdev);
562}
563
564static void
565netxen_cleanup_pci_map(struct netxen_adapter *adapter)
566{
567 if (adapter->ahw.db_base != NULL)
568 iounmap(adapter->ahw.db_base);
569 if (adapter->ahw.pci_base0 != NULL)
570 iounmap(adapter->ahw.pci_base0);
571 if (adapter->ahw.pci_base1 != NULL)
572 iounmap(adapter->ahw.pci_base1);
573 if (adapter->ahw.pci_base2 != NULL)
574 iounmap(adapter->ahw.pci_base2);
575}
576
577static int
578netxen_setup_pci_map(struct netxen_adapter *adapter)
579{
580 void __iomem *mem_ptr0 = NULL;
581 void __iomem *mem_ptr1 = NULL;
582 void __iomem *mem_ptr2 = NULL;
583 void __iomem *db_ptr = NULL;
584
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800585 unsigned long mem_base, mem_len, db_base, db_len = 0, pci_len0 = 0;
586
587 struct pci_dev *pdev = adapter->pdev;
588 int pci_func = adapter->ahw.pci_func;
589
590 int err = 0;
591
592 /*
593 * Set the CRB window to invalid. If any register in window 0 is
594 * accessed it should set the window to 0 and then reset it to 1.
595 */
596 adapter->curr_window = 255;
597 adapter->ahw.qdr_sn_window = -1;
598 adapter->ahw.ddr_mn_window = -1;
599
600 /* remap phys address */
601 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
602 mem_len = pci_resource_len(pdev, 0);
603 pci_len0 = 0;
604
605 adapter->hw_write_wx = netxen_nic_hw_write_wx_128M;
606 adapter->hw_read_wx = netxen_nic_hw_read_wx_128M;
607 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_128M;
608 adapter->pci_write_immediate = netxen_nic_pci_write_immediate_128M;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800609 adapter->pci_set_window = netxen_nic_pci_set_window_128M;
610 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M;
611 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M;
612
613 /* 128 Meg of memory */
614 if (mem_len == NETXEN_PCI_128MB_SIZE) {
615 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
616 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
617 SECOND_PAGE_GROUP_SIZE);
618 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
619 THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800620 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
621 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
622 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
623 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800624 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
625 adapter->hw_write_wx = netxen_nic_hw_write_wx_2M;
626 adapter->hw_read_wx = netxen_nic_hw_read_wx_2M;
627 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_2M;
628 adapter->pci_write_immediate =
629 netxen_nic_pci_write_immediate_2M;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800630 adapter->pci_set_window = netxen_nic_pci_set_window_2M;
631 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M;
632 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M;
633
634 mem_ptr0 = pci_ioremap_bar(pdev, 0);
635 if (mem_ptr0 == NULL) {
636 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
637 return -EIO;
638 }
639 pci_len0 = mem_len;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800640
641 adapter->ahw.ddr_mn_window = 0;
642 adapter->ahw.qdr_sn_window = 0;
643
644 adapter->ahw.mn_win_crb = 0x100000 + PCIX_MN_WINDOW +
645 (pci_func * 0x20);
646 adapter->ahw.ms_win_crb = 0x100000 + PCIX_SN_WINDOW;
647 if (pci_func < 4)
648 adapter->ahw.ms_win_crb += (pci_func * 0x20);
649 else
650 adapter->ahw.ms_win_crb +=
651 0xA0 + ((pci_func - 4) * 0x10);
652 } else {
653 return -EIO;
654 }
655
656 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
657
658 adapter->ahw.pci_base0 = mem_ptr0;
659 adapter->ahw.pci_len0 = pci_len0;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800660 adapter->ahw.pci_base1 = mem_ptr1;
661 adapter->ahw.pci_base2 = mem_ptr2;
662
663 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
664 goto skip_doorbell;
665
666 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
667 db_len = pci_resource_len(pdev, 4);
668
669 if (db_len == 0) {
670 printk(KERN_ERR "%s: doorbell is disabled\n",
671 netxen_nic_driver_name);
672 err = -EIO;
673 goto err_out;
674 }
675
676 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
677 if (!db_ptr) {
678 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
679 netxen_nic_driver_name);
680 err = -EIO;
681 goto err_out;
682 }
683
684skip_doorbell:
685 adapter->ahw.db_base = db_ptr;
686 adapter->ahw.db_len = db_len;
687 return 0;
688
689err_out:
690 netxen_cleanup_pci_map(adapter);
691 return err;
692}
693
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800694static int
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000695netxen_start_firmware(struct netxen_adapter *adapter, int request_fw)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800696{
697 int val, err, first_boot;
698 struct pci_dev *pdev = adapter->pdev;
699
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000700 int first_driver = 0;
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000701
702 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
703 first_driver = (adapter->portnum == 0);
704 else
705 first_driver = (adapter->ahw.pci_func == 0);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000706
707 if (!first_driver)
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000708 goto wait_init;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000709
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000710 first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800711
712 err = netxen_check_hw_init(adapter, first_boot);
713 if (err) {
714 dev_err(&pdev->dev, "error in init HW init sequence\n");
715 return err;
716 }
717
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000718 if (request_fw)
719 netxen_request_firmware(adapter);
720
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800721 if (first_boot != 0x55555555) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000722 NXWR32(adapter, CRB_CMDPEG_STATE, 0);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800723 netxen_pinit_from_rom(adapter, 0);
724 msleep(1);
725 }
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000726
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000727 NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555);
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000728 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
729 netxen_set_port_mode(adapter);
730
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800731 netxen_load_firmware(adapter);
732
733 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
734
735 /* Initialize multicast addr pool owners */
736 val = 0x7654;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000737 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800738 val |= 0x0f000000;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000739 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800740
741 }
742
743 err = netxen_initialize_adapter_offload(adapter);
744 if (err)
745 return err;
746
747 /*
748 * Tell the hardware our version number.
749 */
750 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
751 | ((_NETXEN_NIC_LINUX_MINOR << 8))
752 | (_NETXEN_NIC_LINUX_SUBVERSION);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000753 NXWR32(adapter, CRB_DRIVER_VERSION, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800754
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000755wait_init:
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800756 /* Handshake with the card before we register the devices. */
757 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
758 if (err) {
759 netxen_free_adapter_offload(adapter);
760 return err;
761 }
762
763 return 0;
764}
765
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000766static int
767netxen_nic_request_irq(struct netxen_adapter *adapter)
768{
769 irq_handler_t handler;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000770 struct nx_host_sds_ring *sds_ring;
771 int err, ring;
772
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000773 unsigned long flags = IRQF_SAMPLE_RANDOM;
774 struct net_device *netdev = adapter->netdev;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000775 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000776
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000777 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
778 handler = netxen_msix_intr;
779 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
780 handler = netxen_msi_intr;
781 else {
782 flags |= IRQF_SHARED;
783 handler = netxen_intr;
784 }
785 adapter->irq = netdev->irq;
786
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000787 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
788 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000789 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000790 err = request_irq(sds_ring->irq, handler,
791 flags, sds_ring->name, sds_ring);
792 if (err)
793 return err;
794 }
795
796 return 0;
797}
798
799static void
800netxen_nic_free_irq(struct netxen_adapter *adapter)
801{
802 int ring;
803 struct nx_host_sds_ring *sds_ring;
804
805 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
806
807 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
808 sds_ring = &recv_ctx->sds_rings[ring];
809 free_irq(sds_ring->irq, sds_ring);
810 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000811}
812
813static int
814netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
815{
816 int err;
817
818 err = adapter->init_port(adapter, adapter->physical_port);
819 if (err) {
820 printk(KERN_ERR "%s: Failed to initialize port %d\n",
821 netxen_nic_driver_name, adapter->portnum);
822 return err;
823 }
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000824 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
825 adapter->macaddr_set(adapter, netdev->dev_addr);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000826
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000827 adapter->set_multi(netdev);
828 adapter->set_mtu(adapter, netdev->mtu);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000829
830 adapter->ahw.linkup = 0;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000831
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000832 netxen_napi_enable(adapter);
833
834 if (adapter->max_sds_rings > 1)
835 netxen_config_rss(adapter, 1);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000836
Dhananjay Phadke5103c9f2009-04-28 15:29:09 +0000837 if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000838 netxen_linkevent_request(adapter, 1);
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000839 else
840 netxen_nic_set_link_parameters(adapter);
841
842 mod_timer(&adapter->watchdog_timer, jiffies);
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000843
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000844 return 0;
845}
846
847static void
848netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
849{
850 netif_carrier_off(netdev);
851 netif_stop_queue(netdev);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000852
853 if (adapter->stop_port)
854 adapter->stop_port(adapter);
855
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000856 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
857 netxen_p3_free_mac_list(adapter);
858
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000859 netxen_napi_disable(adapter);
860
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000861 netxen_release_tx_buffers(adapter);
862
863 FLUSH_SCHEDULED_WORK();
864 del_timer_sync(&adapter->watchdog_timer);
865}
866
867
868static int
869netxen_nic_attach(struct netxen_adapter *adapter)
870{
871 struct net_device *netdev = adapter->netdev;
872 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000873 int err, ring;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000874 struct nx_host_rds_ring *rds_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000875 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000876
877 err = netxen_init_firmware(adapter);
878 if (err != 0) {
879 printk(KERN_ERR "Failed to init firmware\n");
880 return -EIO;
881 }
882
883 if (adapter->fw_major < 4)
884 adapter->max_rds_rings = 3;
885 else
886 adapter->max_rds_rings = 2;
887
888 err = netxen_alloc_sw_resources(adapter);
889 if (err) {
890 printk(KERN_ERR "%s: Error in setting sw resources\n",
891 netdev->name);
892 return err;
893 }
894
895 netxen_nic_clear_stats(adapter);
896
897 err = netxen_alloc_hw_resources(adapter);
898 if (err) {
899 printk(KERN_ERR "%s: Error in setting hw resources\n",
900 netdev->name);
901 goto err_out_free_sw;
902 }
903
904 if (adapter->fw_major < 4) {
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000905 tx_ring = adapter->tx_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000906 tx_ring->crb_cmd_producer = crb_cmd_producer[adapter->portnum];
907 tx_ring->crb_cmd_consumer = crb_cmd_consumer[adapter->portnum];
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000908
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000909 tx_ring->producer = 0;
910 tx_ring->sw_consumer = 0;
911
912 netxen_nic_update_cmd_producer(adapter, tx_ring);
913 netxen_nic_update_cmd_consumer(adapter, tx_ring);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000914 }
915
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000916 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
917 rds_ring = &adapter->recv_ctx.rds_rings[ring];
918 netxen_post_rx_buffers(adapter, ring, rds_ring);
919 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000920
921 err = netxen_nic_request_irq(adapter);
922 if (err) {
923 dev_err(&pdev->dev, "%s: failed to setup interrupt\n",
924 netdev->name);
925 goto err_out_free_rxbuf;
926 }
927
928 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
929 return 0;
930
931err_out_free_rxbuf:
932 netxen_release_rx_buffers(adapter);
933 netxen_free_hw_resources(adapter);
934err_out_free_sw:
935 netxen_free_sw_resources(adapter);
936 return err;
937}
938
939static void
940netxen_nic_detach(struct netxen_adapter *adapter)
941{
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000942 netxen_release_rx_buffers(adapter);
943 netxen_free_hw_resources(adapter);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000944 netxen_nic_free_irq(adapter);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000945 netxen_free_sw_resources(adapter);
946
947 adapter->is_up = 0;
948}
949
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400950static int __devinit
951netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
952{
953 struct net_device *netdev = NULL;
954 struct netxen_adapter *adapter = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700955 int i = 0, err;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700956 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700957 uint8_t revision_id;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400958
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700959 if (pdev->class != 0x020000) {
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700960 printk(KERN_DEBUG "NetXen function %d, class %x will not "
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700961 "be enabled.\n",pci_func_id, pdev->class);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800962 return -ENODEV;
963 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700964
Dhananjay Phadke11d89d62008-08-08 00:08:45 -0700965 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
966 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
967 "will not be enabled.\n",
968 NX_P3_A0, NX_P3_B1);
969 return -ENODEV;
970 }
971
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400972 if ((err = pci_enable_device(pdev)))
973 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700974
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400975 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
976 err = -ENODEV;
977 goto err_out_disable_pdev;
978 }
979
980 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
981 goto err_out_disable_pdev;
982
983 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700984
985 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
986 if(!netdev) {
987 printk(KERN_ERR"%s: Failed to allocate memory for the "
988 "device block.Check system memory resource"
989 " usage.\n", netxen_nic_driver_name);
990 goto err_out_free_res;
991 }
992
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700993 SET_NETDEV_DEV(netdev, &pdev->dev);
994
Wang Chen4cf16532008-11-12 23:38:14 -0800995 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700996 adapter->netdev = netdev;
997 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700998 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700999
1000 revision_id = pdev->revision;
1001 adapter->ahw.revision_id = revision_id;
1002
1003 err = nx_set_dma_mask(adapter, revision_id);
1004 if (err)
1005 goto err_out_free_netdev;
1006
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001007 rwlock_init(&adapter->adapter_lock);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001008 spin_lock_init(&adapter->tx_clean_lock);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +00001009 INIT_LIST_HEAD(&adapter->mac_list);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001010
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001011 err = netxen_setup_pci_map(adapter);
1012 if (err)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001013 goto err_out_free_netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001014
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +05301015 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001016 adapter->portnum = pci_func_id;
Dhananjay Phadke200eef22007-09-03 10:33:35 +05301017 adapter->rx_csum = 1;
Dhananjay Phadke623621b2008-07-21 19:44:01 -07001018 adapter->mc_enabled = 0;
Dhananjay Phadke83821a02008-08-01 03:14:58 -07001019 if (NX_IS_REVISION_P3(revision_id))
Dhananjay Phadke29566402008-07-21 19:44:04 -07001020 adapter->max_mc_count = 38;
Dhananjay Phadke83821a02008-08-01 03:14:58 -07001021 else
Dhananjay Phadke29566402008-07-21 19:44:04 -07001022 adapter->max_mc_count = 16;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001023
Stephen Hemminger1abd2662008-11-21 17:32:15 -08001024 netdev->netdev_ops = &netxen_netdev_ops;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001025 netdev->watchdog_timeo = 2*HZ;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001026
1027 netxen_nic_change_mtu(netdev, netdev->mtu);
1028
1029 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
Stephen Hemminger1abd2662008-11-21 17:32:15 -08001030
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001031 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
Amit Kumar Salechaa92e9e62009-04-07 22:50:47 +00001032 netdev->features |= (NETIF_F_GRO);
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001033 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1034
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001035 if (NX_IS_REVISION_P3(revision_id)) {
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001036 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1037 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001038 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001039
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001040 if (adapter->pci_using_dac) {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001041 netdev->features |= NETIF_F_HIGHDMA;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001042 netdev->vlan_features |= NETIF_F_HIGHDMA;
1043 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001044
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001045 if (netxen_nic_get_board_info(adapter) != 0) {
1046 printk("%s: Error getting board config info.\n",
Dhananjay Phadke29566402008-07-21 19:44:04 -07001047 netxen_nic_driver_name);
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001048 err = -EIO;
1049 goto err_out_iounmap;
1050 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001051
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001052 netxen_initialize_adapter_ops(adapter);
1053
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001054 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001055 switch (adapter->ahw.board_type) {
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001056 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1057 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1058 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001059 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001060 break;
1061 default:
1062 break;
1063 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001064
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001065 err = netxen_start_firmware(adapter, 1);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001066 if (err)
1067 goto err_out_iounmap;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001068
Dhananjay Phadke1f434f62009-03-02 16:02:16 +00001069 nx_update_dma_mask(adapter);
1070
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001071 netxen_nic_get_firmware_info(adapter);
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001072
Dhananjay Phadke29566402008-07-21 19:44:04 -07001073 /*
1074 * See if the firmware gave us a virtual-physical port mapping.
1075 */
1076 adapter->physical_port = adapter->portnum;
Dhananjay Phadke044fad02009-02-24 03:42:59 -08001077 if (adapter->fw_major < 4) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001078 i = NXRD32(adapter, CRB_V2P(adapter->portnum));
Dhananjay Phadke044fad02009-02-24 03:42:59 -08001079 if (i != 0x55555555)
1080 adapter->physical_port = i;
1081 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001082
Dhananjay Phadke438627c2009-03-13 14:52:03 +00001083 netxen_check_options(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001084
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001085 netxen_setup_intr(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001086
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001087 netdev->irq = adapter->msix_entries[0].vector;
1088
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +00001089 if (netxen_napi_add(adapter, netdev))
1090 goto err_out_disable_msi;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001091
Dhananjay Phadke29566402008-07-21 19:44:04 -07001092 init_timer(&adapter->watchdog_timer);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001093 adapter->watchdog_timer.function = &netxen_watchdog;
1094 adapter->watchdog_timer.data = (unsigned long)adapter;
1095 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
1096 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
1097
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001098 err = netxen_read_mac_addr(adapter);
1099 if (err)
1100 dev_warn(&pdev->dev, "failed to read mac addr\n");
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001101
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001102 netif_carrier_off(netdev);
1103 netif_stop_queue(netdev);
1104
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001105 if ((err = register_netdev(netdev))) {
1106 printk(KERN_ERR "%s: register_netdev failed port #%d"
1107 " aborting\n", netxen_nic_driver_name,
1108 adapter->portnum);
1109 err = -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001110 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001111 }
1112
1113 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001114
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001115 switch (adapter->ahw.port_type) {
Dhananjay Phadke29566402008-07-21 19:44:04 -07001116 case NETXEN_NIC_GBE:
1117 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1118 adapter->netdev->name);
1119 break;
1120 case NETXEN_NIC_XGBE:
1121 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1122 adapter->netdev->name);
1123 break;
1124 }
1125
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001126 return 0;
1127
Dhananjay Phadke29566402008-07-21 19:44:04 -07001128err_out_disable_msi:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001129 netxen_teardown_intr(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001130
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001131 netxen_free_adapter_offload(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001132
Dhananjay Phadke29566402008-07-21 19:44:04 -07001133err_out_iounmap:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001134 netxen_cleanup_pci_map(adapter);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001135
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001136err_out_free_netdev:
1137 free_netdev(netdev);
1138
1139err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001140 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001141
1142err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001143 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001144 pci_disable_device(pdev);
1145 return err;
1146}
1147
1148static void __devexit netxen_nic_remove(struct pci_dev *pdev)
1149{
1150 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001151 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001152
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001153 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001154 if (adapter == NULL)
1155 return;
1156
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001157 netdev = adapter->netdev;
1158
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301159 unregister_netdev(netdev);
1160
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301161 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001162 netxen_nic_detach(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301163 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001164
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001165 if (adapter->portnum == 0)
1166 netxen_free_adapter_offload(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301167
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001168 netxen_teardown_intr(adapter);
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +00001169 netxen_free_sds_rings(&adapter->recv_ctx);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301170
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001171 netxen_cleanup_pci_map(adapter);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001172
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001173 netxen_release_firmware(adapter);
1174
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001175 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301176 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001177 pci_set_drvdata(pdev, NULL);
1178
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001179 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001180}
1181
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00001182#ifdef CONFIG_PM
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001183static int
1184netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
1185{
1186
1187 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1188 struct net_device *netdev = adapter->netdev;
1189
1190 netif_device_detach(netdev);
1191
1192 if (netif_running(netdev))
1193 netxen_nic_down(adapter, netdev);
1194
1195 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
1196 netxen_nic_detach(adapter);
1197
1198 pci_save_state(pdev);
1199
1200 if (netxen_nic_wol_supported(adapter)) {
1201 pci_enable_wake(pdev, PCI_D3cold, 1);
1202 pci_enable_wake(pdev, PCI_D3hot, 1);
1203 }
1204
1205 pci_disable_device(pdev);
1206 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1207
1208 return 0;
1209}
1210
1211static int
1212netxen_nic_resume(struct pci_dev *pdev)
1213{
1214 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1215 struct net_device *netdev = adapter->netdev;
1216 int err;
1217
1218 pci_set_power_state(pdev, PCI_D0);
1219 pci_restore_state(pdev);
1220
1221 err = pci_enable_device(pdev);
1222 if (err)
1223 return err;
1224
1225 adapter->curr_window = 255;
1226
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001227 err = netxen_start_firmware(adapter, 0);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001228 if (err) {
1229 dev_err(&pdev->dev, "failed to start firmware\n");
1230 return err;
1231 }
1232
1233 if (netif_running(netdev)) {
1234 err = netxen_nic_attach(adapter);
1235 if (err)
1236 return err;
1237
1238 err = netxen_nic_up(adapter, netdev);
1239 if (err)
1240 return err;
1241
1242 netif_device_attach(netdev);
1243 }
1244
1245 return 0;
1246}
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00001247#endif
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001248
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001249static int netxen_nic_open(struct net_device *netdev)
1250{
Wang Chen4cf16532008-11-12 23:38:14 -08001251 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001252 int err = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001253
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001254 if (adapter->driver_mismatch)
1255 return -EIO;
1256
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001257 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) {
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001258 err = netxen_nic_attach(adapter);
1259 if (err)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001260 return err;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001261 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001262
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001263 err = netxen_nic_up(adapter, netdev);
1264 if (err)
1265 goto err_out;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001266
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001267 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001268
1269 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001270
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001271err_out:
1272 netxen_nic_detach(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001273 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001274}
1275
1276/*
1277 * netxen_nic_close - Disables a network interface entry point
1278 */
1279static int netxen_nic_close(struct net_device *netdev)
1280{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001281 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001282
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001283 netxen_nic_down(adapter, netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001284 return 0;
1285}
1286
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001287static bool netxen_tso_check(struct net_device *netdev,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001288 struct cmd_desc_type0 *desc, struct sk_buff *skb)
1289{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001290 bool tso = false;
1291 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001292 __be16 protocol = skb->protocol;
1293 u16 flags = 0;
1294
Harvey Harrison09640e632009-02-01 00:45:17 -08001295 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001296 struct vlan_ethhdr *vh = (struct vlan_ethhdr *)skb->data;
1297 protocol = vh->h_vlan_encapsulated_proto;
1298 flags = FLAGS_VLAN_TAGGED;
1299 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001300
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001301 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1302 skb_shinfo(skb)->gso_size > 0) {
1303
1304 desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1305 desc->total_hdr_length =
1306 skb_transport_offset(skb) + tcp_hdrlen(skb);
1307
Harvey Harrison09640e632009-02-01 00:45:17 -08001308 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001309 TX_TCP_LSO6 : TX_TCP_LSO;
1310 tso = true;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001311
1312 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001313 u8 l4proto;
1314
Harvey Harrison09640e632009-02-01 00:45:17 -08001315 if (protocol == cpu_to_be16(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001316 l4proto = ip_hdr(skb)->protocol;
1317
1318 if (l4proto == IPPROTO_TCP)
1319 opcode = TX_TCP_PKT;
1320 else if(l4proto == IPPROTO_UDP)
1321 opcode = TX_UDP_PKT;
Harvey Harrison09640e632009-02-01 00:45:17 -08001322 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001323 l4proto = ipv6_hdr(skb)->nexthdr;
1324
1325 if (l4proto == IPPROTO_TCP)
1326 opcode = TX_TCPV6_PKT;
1327 else if(l4proto == IPPROTO_UDP)
1328 opcode = TX_UDPV6_PKT;
1329 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001330 }
1331 desc->tcp_hdr_offset = skb_transport_offset(skb);
1332 desc->ip_hdr_offset = skb_network_offset(skb);
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001333 netxen_set_tx_flags_opcode(desc, flags, opcode);
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001334 return tso;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001335}
1336
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001337static void
1338netxen_clean_tx_dma_mapping(struct pci_dev *pdev,
1339 struct netxen_cmd_buffer *pbuf, int last)
1340{
1341 int k;
1342 struct netxen_skb_frag *buffrag;
1343
1344 buffrag = &pbuf->frag_array[0];
1345 pci_unmap_single(pdev, buffrag->dma,
1346 buffrag->length, PCI_DMA_TODEVICE);
1347
1348 for (k = 1; k < last; k++) {
1349 buffrag = &pbuf->frag_array[k];
1350 pci_unmap_page(pdev, buffrag->dma,
1351 buffrag->length, PCI_DMA_TODEVICE);
1352 }
1353}
1354
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001355static inline void
1356netxen_clear_cmddesc(u64 *desc)
1357{
1358 int i;
1359 for (i = 0; i < 8; i++)
1360 desc[i] = 0ULL;
1361}
1362
1363static int
1364netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001365{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001366 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001367 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001368 unsigned int first_seg_len = skb->len - skb->data_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001369 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001370 struct netxen_skb_frag *buffrag;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001371 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001372 struct pci_dev *pdev = adapter->pdev;
1373 dma_addr_t temp_dma;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001374 int i, k;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001375
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001376 u32 producer;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001377 int frag_count, no_of_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001378 u32 num_txd = tx_ring->num_desc;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001379 bool is_tso = false;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001380
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001381 frag_count = skb_shinfo(skb)->nr_frags + 1;
1382
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001383 /* 4 fragments per cmd des */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001384 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001385
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001386 if (unlikely(no_of_desc + 2) > netxen_tx_avail(tx_ring)) {
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001387 netif_stop_queue(netdev);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001388 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001389 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001390
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001391 producer = tx_ring->producer;
1392
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001393 hwdesc = &tx_ring->desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001394 netxen_clear_cmddesc((u64 *)hwdesc);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001395 pbuf = &tx_ring->cmd_buf_arr[producer];
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001396
1397 is_tso = netxen_tso_check(netdev, hwdesc, skb);
1398
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001399 pbuf->skb = skb;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001400 pbuf->frag_count = frag_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001401 buffrag = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001402 temp_dma = pci_map_single(pdev, skb->data, first_seg_len,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001403 PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001404 if (pci_dma_mapping_error(pdev, temp_dma))
1405 goto drop_packet;
1406
1407 buffrag->dma = temp_dma;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001408 buffrag->length = first_seg_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001409 netxen_set_tx_frags_len(hwdesc, frag_count, skb->len);
1410 netxen_set_tx_port(hwdesc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001411
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001412 hwdesc->buffer_length[0] = cpu_to_le16(first_seg_len);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001413 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
1414
1415 for (i = 1, k = 1; i < frag_count; i++, k++) {
1416 struct skb_frag_struct *frag;
1417 int len, temp_len;
1418 unsigned long offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001419
1420 /* move to next desc. if there is a need */
1421 if ((i & 0x3) == 0) {
1422 k = 0;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001423 producer = get_next_index(producer, num_txd);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001424 hwdesc = &tx_ring->desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001425 netxen_clear_cmddesc((u64 *)hwdesc);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001426 pbuf = &tx_ring->cmd_buf_arr[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001427 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001428 }
1429 frag = &skb_shinfo(skb)->frags[i - 1];
1430 len = frag->size;
1431 offset = frag->page_offset;
1432
1433 temp_len = len;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001434 temp_dma = pci_map_page(pdev, frag->page, offset,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001435 len, PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001436 if (pci_dma_mapping_error(pdev, temp_dma)) {
1437 netxen_clean_tx_dma_mapping(pdev, pbuf, i);
1438 goto drop_packet;
1439 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001440
1441 buffrag++;
1442 buffrag->dma = temp_dma;
1443 buffrag->length = temp_len;
1444
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001445 hwdesc->buffer_length[k] = cpu_to_le16(temp_len);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001446 switch (k) {
1447 case 0:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001448 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
1449 break;
1450 case 1:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001451 hwdesc->addr_buffer2 = cpu_to_le64(temp_dma);
1452 break;
1453 case 2:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001454 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
1455 break;
1456 case 3:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001457 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
1458 break;
1459 }
1460 frag++;
1461 }
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001462 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001463
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001464 /* For LSO, we need to copy the MAC/IP/TCP headers into
1465 * the descriptor ring
1466 */
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001467 if (is_tso) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001468 int hdr_len, first_hdr_len, more_hdr;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001469 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001470 if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) {
1471 first_hdr_len = sizeof(struct cmd_desc_type0) - 2;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001472 more_hdr = 1;
1473 } else {
1474 first_hdr_len = hdr_len;
1475 more_hdr = 0;
1476 }
1477 /* copy the MAC/IP/TCP headers to the cmd descriptor list */
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001478 hwdesc = &tx_ring->desc_head[producer];
1479 pbuf = &tx_ring->cmd_buf_arr[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001480 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001481
1482 /* copy the first 64 bytes */
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001483 memcpy(((void *)hwdesc) + 2,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001484 (void *)(skb->data), first_hdr_len);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001485 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001486
1487 if (more_hdr) {
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001488 hwdesc = &tx_ring->desc_head[producer];
1489 pbuf = &tx_ring->cmd_buf_arr[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001490 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001491 /* copy the next 64 bytes - should be enough except
1492 * for pathological case
1493 */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001494 skb_copy_from_linear_data_offset(skb, first_hdr_len,
1495 hwdesc,
1496 (hdr_len -
1497 first_hdr_len));
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001498 producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001499 }
1500 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001501
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001502 tx_ring->producer = producer;
Dhananjay Phadke5dc16262007-12-31 10:08:57 -08001503 adapter->stats.txbytes += skb->len;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001504
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001505 netxen_nic_update_cmd_producer(adapter, tx_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001506
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001507 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001508
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001509 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001510
1511drop_packet:
1512 adapter->stats.txdropped++;
1513 dev_kfree_skb_any(skb);
1514 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001515}
1516
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001517static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1518{
1519 struct net_device *netdev = adapter->netdev;
1520 uint32_t temp, temp_state, temp_val;
1521 int rv = 0;
1522
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001523 temp = NXRD32(adapter, CRB_TEMP_STATE);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001524
1525 temp_state = nx_get_temp_state(temp);
1526 temp_val = nx_get_temp_val(temp);
1527
1528 if (temp_state == NX_TEMP_PANIC) {
1529 printk(KERN_ALERT
1530 "%s: Device temperature %d degrees C exceeds"
1531 " maximum allowed. Hardware has been shut down.\n",
1532 netxen_nic_driver_name, temp_val);
1533
1534 netif_carrier_off(netdev);
1535 netif_stop_queue(netdev);
1536 rv = 1;
1537 } else if (temp_state == NX_TEMP_WARN) {
1538 if (adapter->temp == NX_TEMP_NORMAL) {
1539 printk(KERN_ALERT
1540 "%s: Device temperature %d degrees C "
1541 "exceeds operating range."
1542 " Immediate action needed.\n",
1543 netxen_nic_driver_name, temp_val);
1544 }
1545 } else {
1546 if (adapter->temp == NX_TEMP_WARN) {
1547 printk(KERN_INFO
1548 "%s: Device temperature is now %d degrees C"
1549 " in normal range.\n", netxen_nic_driver_name,
1550 temp_val);
1551 }
1552 }
1553 adapter->temp = temp_state;
1554 return rv;
1555}
1556
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001557void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup)
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001558{
1559 struct net_device *netdev = adapter->netdev;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001560
1561 if (adapter->ahw.linkup && !linkup) {
1562 printk(KERN_INFO "%s: %s NIC Link is down\n",
1563 netxen_nic_driver_name, netdev->name);
1564 adapter->ahw.linkup = 0;
1565 if (netif_running(netdev)) {
1566 netif_carrier_off(netdev);
1567 netif_stop_queue(netdev);
1568 }
1569
1570 if (!adapter->has_link_events)
1571 netxen_nic_set_link_parameters(adapter);
1572
1573 } else if (!adapter->ahw.linkup && linkup) {
1574 printk(KERN_INFO "%s: %s NIC Link is up\n",
1575 netxen_nic_driver_name, netdev->name);
1576 adapter->ahw.linkup = 1;
1577 if (netif_running(netdev)) {
1578 netif_carrier_on(netdev);
1579 netif_wake_queue(netdev);
1580 }
1581
1582 if (!adapter->has_link_events)
1583 netxen_nic_set_link_parameters(adapter);
1584 }
1585}
1586
1587static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1588{
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001589 u32 val, port, linkup;
1590
1591 port = adapter->physical_port;
1592
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001593 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001594 val = NXRD32(adapter, CRB_XG_STATE_P3);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001595 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1596 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001597 } else {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001598 val = NXRD32(adapter, CRB_XG_STATE);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001599 if (adapter->ahw.port_type == NETXEN_NIC_GBE)
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001600 linkup = (val >> port) & 1;
1601 else {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001602 val = (val >> port*8) & 0xff;
1603 linkup = (val == XG_LINK_UP);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001604 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001605 }
1606
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001607 netxen_advert_link_change(adapter, linkup);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001608}
1609
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001610static void netxen_watchdog(unsigned long v)
1611{
1612 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001613
1614 SCHEDULE_WORK(&adapter->watchdog_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001615}
1616
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001617void netxen_watchdog_task(struct work_struct *work)
1618{
1619 struct netxen_adapter *adapter =
1620 container_of(work, struct netxen_adapter, watchdog_task);
1621
1622 if ((adapter->portnum == 0) && netxen_nic_check_temp(adapter))
1623 return;
1624
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001625 if (!adapter->has_link_events)
1626 netxen_nic_handle_phy_intr(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001627
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001628 if (netif_running(adapter->netdev))
1629 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001630}
1631
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001632static void netxen_tx_timeout(struct net_device *netdev)
1633{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001634 struct netxen_adapter *adapter = (struct netxen_adapter *)
1635 netdev_priv(netdev);
1636 SCHEDULE_WORK(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001637}
1638
David Howells6d5aefb2006-12-05 19:36:26 +00001639static void netxen_tx_timeout_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001640{
Jeff Garzik47906542007-11-23 21:23:36 -05001641 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001642 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001643
1644 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001645 netxen_nic_driver_name, adapter->netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001646
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001647 netxen_napi_disable(adapter);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001648
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001649 adapter->netdev->trans_start = jiffies;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001650
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001651 netxen_napi_enable(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001652 netif_wake_queue(adapter->netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001653}
1654
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001655struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1656{
1657 struct netxen_adapter *adapter = netdev_priv(netdev);
1658 struct net_device_stats *stats = &adapter->net_stats;
1659
1660 memset(stats, 0, sizeof(*stats));
1661
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001662 stats->rx_packets = adapter->stats.no_rcv;
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00001663 stats->tx_packets = adapter->stats.xmitfinished;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001664 stats->rx_bytes = adapter->stats.rxbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001665 stats->tx_bytes = adapter->stats.txbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001666 stats->rx_dropped = adapter->stats.rxdropped;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001667 stats->tx_dropped = adapter->stats.txdropped;
1668
1669 return stats;
1670}
1671
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001672static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001673{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001674 struct nx_host_sds_ring *sds_ring = data;
1675 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001676 u32 status = 0;
1677
1678 status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1679
1680 if (!(status & adapter->legacy_intr.int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001681 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301682
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001683 if (adapter->ahw.revision_id >= NX_P3_B1) {
1684 /* check interrupt state machine, to be sure */
1685 status = adapter->pci_read_immediate(adapter,
1686 ISR_INT_STATE_REG);
1687 if (!ISR_LEGACY_INT_TRIGGERED(status))
1688 return IRQ_NONE;
1689
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001690 } else {
1691 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001692
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001693 our_int = NXRD32(adapter, CRB_INT_VECTOR);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001694
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001695 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001696 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001697 return IRQ_NONE;
1698
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001699 /* claim interrupt */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001700 NXWR32(adapter, CRB_INT_VECTOR, (our_int & 0xffffffff));
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301701 }
1702
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001703 /* clear interrupt */
1704 if (adapter->fw_major < 4)
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001705 netxen_nic_disable_int(sds_ring);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001706
1707 adapter->pci_write_immediate(adapter,
1708 adapter->legacy_intr.tgt_status_reg,
1709 0xffffffff);
1710 /* read twice to ensure write is flushed */
1711 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1712 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1713
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001714 napi_schedule(&sds_ring->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001715
1716 return IRQ_HANDLED;
1717}
1718
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001719static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001720{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001721 struct nx_host_sds_ring *sds_ring = data;
1722 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001723
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001724 /* clear interrupt */
1725 adapter->pci_write_immediate(adapter,
Dhananjay Phadke7a2469c2009-05-08 22:02:27 +00001726 adapter->msi_tgt_status, 0xffffffff);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001727
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001728 napi_schedule(&sds_ring->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001729 return IRQ_HANDLED;
1730}
1731
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001732static irqreturn_t netxen_msix_intr(int irq, void *data)
1733{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001734 struct nx_host_sds_ring *sds_ring = data;
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001735
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001736 napi_schedule(&sds_ring->napi);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001737 return IRQ_HANDLED;
1738}
1739
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001740static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001741{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001742 struct nx_host_sds_ring *sds_ring =
1743 container_of(napi, struct nx_host_sds_ring, napi);
1744
1745 struct netxen_adapter *adapter = sds_ring->adapter;
1746
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001747 int tx_complete;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001748 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001749
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001750 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001751
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001752 work_done = netxen_process_rcv_ring(sds_ring, budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001753
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001754 if ((work_done < budget) && tx_complete) {
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001755 napi_complete(&sds_ring->napi);
1756 netxen_nic_enable_int(sds_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001757 }
1758
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001759 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001760}
1761
1762#ifdef CONFIG_NET_POLL_CONTROLLER
1763static void netxen_nic_poll_controller(struct net_device *netdev)
1764{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001765 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001766 disable_irq(adapter->irq);
Jeff Garzik1494a812006-11-07 05:12:16 -05001767 netxen_intr(adapter->irq, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001768 enable_irq(adapter->irq);
1769}
1770#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001771
1772static struct pci_driver netxen_driver = {
1773 .name = netxen_nic_driver_name,
1774 .id_table = netxen_pci_tbl,
1775 .probe = netxen_nic_probe,
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001776 .remove = __devexit_p(netxen_nic_remove),
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00001777#ifdef CONFIG_PM
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001778 .suspend = netxen_nic_suspend,
1779 .resume = netxen_nic_resume
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00001780#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001781};
1782
1783/* Driver Registration on NetXen card */
1784
1785static int __init netxen_init_module(void)
1786{
Dhananjay Phadkeff4fbd42009-03-13 14:52:06 +00001787 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
1788
Al Viro79ea13c2008-01-24 02:06:46 -08001789 if ((netxen_workq = create_singlethread_workqueue("netxen")) == NULL)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001790 return -ENOMEM;
1791
Amit S. Kale184231b2007-01-22 06:52:53 -08001792 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001793}
1794
1795module_init(netxen_init_module);
1796
1797static void __exit netxen_exit_module(void)
1798{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001799 pci_unregister_driver(&netxen_driver);
Amit S. Kale9de06612007-02-21 06:37:06 -08001800 destroy_workqueue(netxen_workq);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001801}
1802
1803module_exit(netxen_exit_module);