blob: 47aede622035dad9d153db328160ade2cf09d148 [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
Jeff Garzik1494a812006-11-07 05:12:16 -050037#include <linux/dma-mapping.h>
Dhananjay Phadke391587c2009-01-14 20:48:11 -080038#include <linux/if_vlan.h>
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030039#include <net/ip.h>
Dhananjay Phadke00977782009-01-16 11:03:25 -080040#include <linux/ipv6.h>
Dhananjay Phadke6598b162009-07-26 20:07:37 +000041#include <linux/inetdevice.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);
Stephen Hemminger613573252009-08-31 19:50:58 +000066static netdev_tx_t netxen_nic_xmit_frame(struct sk_buff *,
67 struct net_device *);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040068static void netxen_tx_timeout(struct net_device *netdev);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +000069static void netxen_reset_task(struct work_struct *work);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040070static void netxen_watchdog(unsigned long);
Stephen Hemmingerbea33482007-10-03 16:41:36 -070071static int netxen_nic_poll(struct napi_struct *napi, int budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040072#ifdef CONFIG_NET_POLL_CONTROLLER
73static void netxen_nic_poll_controller(struct net_device *netdev);
74#endif
Narender Kumarfa3ce352009-08-24 19:23:28 +000075
76static void netxen_create_sysfs_entries(struct netxen_adapter *adapter);
77static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter);
78
Jeff Garzik1494a812006-11-07 05:12:16 -050079static irqreturn_t netxen_intr(int irq, void *data);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -070080static irqreturn_t netxen_msi_intr(int irq, void *data);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -080081static irqreturn_t netxen_msix_intr(int irq, void *data);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040082
83/* PCI Device ID Table */
Al Viro70081ac2008-06-23 02:04:50 +010084#define ENTRY(device) \
Dhananjay Phadke040dec32008-09-12 06:55:14 -070085 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
Al Viro70081ac2008-06-23 02:04:50 +010086 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
87
Amit S. Kale3d396eb2006-10-21 15:33:03 -040088static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
Dhananjay Phadke040dec32008-09-12 06:55:14 -070089 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR),
90 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4),
91 ENTRY(PCI_DEVICE_ID_NX2031_4GCU),
92 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ),
93 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ),
94 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT),
95 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2),
96 ENTRY(PCI_DEVICE_ID_NX3031),
Amit S. Kale3d396eb2006-10-21 15:33:03 -040097 {0,}
98};
99
100MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
101
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700102static uint32_t crb_cmd_producer[4] = {
103 CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1,
104 CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3
105};
106
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700107void
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700108netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000109 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700110{
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000111 NXWR32(adapter, tx_ring->crb_cmd_producer, tx_ring->producer);
112
113 if (netxen_tx_avail(tx_ring) <= TX_STOP_THRESH) {
114 netif_stop_queue(adapter->netdev);
115 smp_mb();
116 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700117}
118
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700119static uint32_t crb_cmd_consumer[4] = {
120 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
121 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
122};
123
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700124static inline void
125netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000126 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700127{
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000128 NXWR32(adapter, tx_ring->crb_cmd_consumer, tx_ring->sw_consumer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700129}
130
Dhananjay Phadke29566402008-07-21 19:44:04 -0700131static uint32_t msi_tgt_status[8] = {
Dhananjay Phadke443be792008-03-17 19:59:48 -0700132 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700133 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
134 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
135 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
Dhananjay Phadke443be792008-03-17 19:59:48 -0700136};
137
Dhananjay Phadke29566402008-07-21 19:44:04 -0700138static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
139
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000140static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700141{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000142 struct netxen_adapter *adapter = sds_ring->adapter;
143
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000144 NXWR32(adapter, sds_ring->crb_intr_mask, 0);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700145}
146
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000147static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700148{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000149 struct netxen_adapter *adapter = sds_ring->adapter;
150
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000151 NXWR32(adapter, sds_ring->crb_intr_mask, 0x1);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700152
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700153 if (!NETXEN_IS_MSI_FAMILY(adapter))
154 adapter->pci_write_immediate(adapter,
155 adapter->legacy_intr.tgt_mask_reg, 0xfbff);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700156}
157
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000158static int
159netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count)
160{
161 int size = sizeof(struct nx_host_sds_ring) * count;
162
163 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
164
165 return (recv_ctx->sds_rings == NULL);
166}
167
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000168static void
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000169netxen_free_sds_rings(struct netxen_recv_context *recv_ctx)
170{
171 if (recv_ctx->sds_rings != NULL)
172 kfree(recv_ctx->sds_rings);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000173
174 recv_ctx->sds_rings = NULL;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000175}
176
177static int
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000178netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
179{
180 int ring;
181 struct nx_host_sds_ring *sds_ring;
182 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
183
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000184 if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
Dhananjay Phadkef17443f2009-07-26 20:07:43 +0000185 return -ENOMEM;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000186
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000187 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
188 sds_ring = &recv_ctx->sds_rings[ring];
189 netif_napi_add(netdev, &sds_ring->napi,
190 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
191 }
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000192
193 return 0;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000194}
195
196static void
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000197netxen_napi_del(struct netxen_adapter *adapter)
198{
199 int ring;
200 struct nx_host_sds_ring *sds_ring;
201 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
202
203 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
204 sds_ring = &recv_ctx->sds_rings[ring];
205 netif_napi_del(&sds_ring->napi);
206 }
207
208 netxen_free_sds_rings(&adapter->recv_ctx);
209}
210
211static void
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000212netxen_napi_enable(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 napi_enable(&sds_ring->napi);
221 netxen_nic_enable_int(sds_ring);
222 }
223}
224
225static void
226netxen_napi_disable(struct netxen_adapter *adapter)
227{
228 int ring;
229 struct nx_host_sds_ring *sds_ring;
230 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
231
232 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
233 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000234 netxen_nic_disable_int(sds_ring);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000235 napi_synchronize(&sds_ring->napi);
236 napi_disable(&sds_ring->napi);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000237 }
238}
239
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000240static int nx_set_dma_mask(struct netxen_adapter *adapter)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700241{
242 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000243 uint64_t mask, cmask;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700244
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000245 adapter->pci_using_dac = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700246
Yang Hongyang6afd1422009-04-06 19:01:15 -0700247 mask = DMA_BIT_MASK(32);
Yang Hongyang6afd1422009-04-06 19:01:15 -0700248 cmask = DMA_BIT_MASK(32);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000249
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000250 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000251#ifndef CONFIG_IA64
Yang Hongyang6afd1422009-04-06 19:01:15 -0700252 mask = DMA_BIT_MASK(35);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000253#endif
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000254 } else {
255 mask = DMA_BIT_MASK(39);
256 cmask = mask;
257 }
258
Dhananjay Phadke29566402008-07-21 19:44:04 -0700259 if (pci_set_dma_mask(pdev, mask) == 0 &&
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000260 pci_set_consistent_dma_mask(pdev, cmask) == 0) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700261 adapter->pci_using_dac = 1;
262 return 0;
263 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700264
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000265 return -EIO;
266}
267
268/* Update addressable range if firmware supports it */
269static int
270nx_update_dma_mask(struct netxen_adapter *adapter)
271{
272 int change, shift, err;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000273 uint64_t mask, old_mask, old_cmask;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000274 struct pci_dev *pdev = adapter->pdev;
275
276 change = 0;
277
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000278 shift = NXRD32(adapter, CRB_DMA_SHIFT);
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000279 if (shift > 32)
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000280 return 0;
281
282 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9))
283 change = 1;
284 else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4))
285 change = 1;
286
287 if (change) {
288 old_mask = pdev->dma_mask;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000289 old_cmask = pdev->dev.coherent_dma_mask;
290
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000291 mask = DMA_BIT_MASK(32+shift);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000292
293 err = pci_set_dma_mask(pdev, mask);
294 if (err)
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000295 goto err_out;
296
297 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
298
299 err = pci_set_consistent_dma_mask(pdev, mask);
300 if (err)
301 goto err_out;
302 }
303 dev_info(&pdev->dev, "using %d-bit dma mask\n", 32+shift);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700304 }
305
Dhananjay Phadke29566402008-07-21 19:44:04 -0700306 return 0;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000307
308err_out:
309 pci_set_dma_mask(pdev, old_mask);
310 pci_set_consistent_dma_mask(pdev, old_cmask);
311 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700312}
313
Dhananjay Phadke24767ab2009-07-27 11:08:00 -0700314static void
315netxen_check_options(struct netxen_adapter *adapter)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700316{
Dhananjay Phadke24767ab2009-07-27 11:08:00 -0700317 if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
318 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
319 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
320 } else if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
321 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
322 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
323 }
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000324
Dhananjay Phadkef6d21f42009-04-07 22:50:46 +0000325 adapter->msix_supported = 0;
326 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700327 adapter->msix_supported = !!use_msi_x;
Dhananjay Phadkef6d21f42009-04-07 22:50:46 +0000328 adapter->rss_supported = !!use_msi_x;
329 } else if (adapter->fw_version >= NETXEN_VERSION_CODE(3, 4, 336)) {
330 switch (adapter->ahw.board_type) {
331 case NETXEN_BRDTYPE_P2_SB31_10G:
332 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkef6d21f42009-04-07 22:50:46 +0000333 adapter->msix_supported = !!use_msi_x;
334 adapter->rss_supported = !!use_msi_x;
335 break;
336 default:
337 break;
338 }
339 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700340
Dhananjay Phadke24767ab2009-07-27 11:08:00 -0700341 adapter->num_txd = MAX_CMD_DESCRIPTORS;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700342
Dhananjay Phadke24767ab2009-07-27 11:08:00 -0700343 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
344 adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS;
345 adapter->max_rds_rings = 3;
346 } else {
347 adapter->num_lro_rxd = 0;
348 adapter->max_rds_rings = 2;
349 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700350}
351
352static int
353netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
354{
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800355 u32 val, timeout;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700356
357 if (first_boot == 0x55555555) {
358 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000359 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800360
361 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
362 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700363
364 /* PCI bus master workaround */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000365 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700366 if (!(first_boot & 0x4)) {
367 first_boot |= 0x4;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000368 NXWR32(adapter, NETXEN_PCIE_REG(0x4), first_boot);
369 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700370 }
371
372 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000373 first_boot = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700374 if (first_boot != 0x80000f) {
375 /* clear the register for future unloads/loads */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000376 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), 0);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800377 return -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700378 }
379
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800380 /* Start P2 boot loader */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000381 val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
382 NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800383 timeout = 0;
384 do {
385 msleep(1);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000386 val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800387
388 if (++timeout > 5000)
389 return -EIO;
390
391 } while (val == NETXEN_BDINFO_MAGIC);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700392 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800393 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700394}
395
396static void netxen_set_port_mode(struct netxen_adapter *adapter)
397{
398 u32 val, data;
399
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000400 val = adapter->ahw.board_type;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700401 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
402 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
403 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
404 data = NETXEN_PORT_MODE_802_3_AP;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000405 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700406 } else if (port_mode == NETXEN_PORT_MODE_XG) {
407 data = NETXEN_PORT_MODE_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000408 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700409 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
410 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000411 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700412 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
413 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000414 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700415 } else {
416 data = NETXEN_PORT_MODE_AUTO_NEG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000417 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700418 }
419
420 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
421 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
422 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
423 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
424 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
425 }
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000426 NXWR32(adapter, NETXEN_WOL_PORT_MODE, wol_port_mode);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700427 }
428}
429
Dhananjay Phadke29566402008-07-21 19:44:04 -0700430static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
431{
432 u32 control;
433 int pos;
434
435 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
436 if (pos) {
437 pci_read_config_dword(pdev, pos, &control);
438 if (enable)
439 control |= PCI_MSIX_FLAGS_ENABLE;
440 else
441 control = 0;
442 pci_write_config_dword(pdev, pos, control);
443 }
444}
445
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000446static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700447{
448 int i;
449
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000450 for (i = 0; i < count; i++)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700451 adapter->msix_entries[i].entry = i;
452}
453
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700454static int
455netxen_read_mac_addr(struct netxen_adapter *adapter)
456{
457 int i;
458 unsigned char *p;
459 __le64 mac_addr;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700460 struct net_device *netdev = adapter->netdev;
461 struct pci_dev *pdev = adapter->pdev;
462
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700463 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
464 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
465 return -EIO;
466 } else {
467 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
468 return -EIO;
469 }
470
471 p = (unsigned char *)&mac_addr;
472 for (i = 0; i < 6; i++)
473 netdev->dev_addr[i] = *(p + 5 - i);
474
475 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
476
477 /* set station address */
478
Johannes Berge1749612008-10-27 15:59:26 -0700479 if (!is_valid_ether_addr(netdev->perm_addr))
480 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700481
482 return 0;
483}
484
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000485int netxen_nic_set_mac(struct net_device *netdev, void *p)
486{
487 struct netxen_adapter *adapter = netdev_priv(netdev);
488 struct sockaddr *addr = p;
489
490 if (!is_valid_ether_addr(addr->sa_data))
491 return -EINVAL;
492
493 if (netif_running(netdev)) {
494 netif_device_detach(netdev);
495 netxen_napi_disable(adapter);
496 }
497
498 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
499 adapter->macaddr_set(adapter, addr->sa_data);
500
501 if (netif_running(netdev)) {
502 netif_device_attach(netdev);
503 netxen_napi_enable(adapter);
504 }
505 return 0;
506}
507
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800508static void netxen_set_multicast_list(struct net_device *dev)
509{
510 struct netxen_adapter *adapter = netdev_priv(dev);
511
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000512 adapter->set_multi(dev);
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800513}
514
515static const struct net_device_ops netxen_netdev_ops = {
516 .ndo_open = netxen_nic_open,
517 .ndo_stop = netxen_nic_close,
518 .ndo_start_xmit = netxen_nic_xmit_frame,
519 .ndo_get_stats = netxen_nic_get_stats,
520 .ndo_validate_addr = eth_validate_addr,
521 .ndo_set_multicast_list = netxen_set_multicast_list,
522 .ndo_set_mac_address = netxen_nic_set_mac,
523 .ndo_change_mtu = netxen_nic_change_mtu,
524 .ndo_tx_timeout = netxen_tx_timeout,
525#ifdef CONFIG_NET_POLL_CONTROLLER
526 .ndo_poll_controller = netxen_nic_poll_controller,
527#endif
528};
529
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800530static void
531netxen_setup_intr(struct netxen_adapter *adapter)
532{
533 struct netxen_legacy_intr_set *legacy_intrp;
534 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000535 int err, num_msix;
536
537 if (adapter->rss_supported) {
538 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
539 MSIX_ENTRIES_PER_ADAPTER : 2;
540 } else
541 num_msix = 1;
542
543 adapter->max_sds_rings = 1;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800544
545 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800546
547 if (adapter->ahw.revision_id >= NX_P3_B0)
548 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
549 else
550 legacy_intrp = &legacy_intr[0];
551 adapter->legacy_intr.int_vec_bit = legacy_intrp->int_vec_bit;
552 adapter->legacy_intr.tgt_status_reg = legacy_intrp->tgt_status_reg;
553 adapter->legacy_intr.tgt_mask_reg = legacy_intrp->tgt_mask_reg;
554 adapter->legacy_intr.pci_int_reg = legacy_intrp->pci_int_reg;
555
556 netxen_set_msix_bit(pdev, 0);
557
558 if (adapter->msix_supported) {
559
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000560 netxen_init_msix_entries(adapter, num_msix);
561 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
562 if (err == 0) {
563 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
564 netxen_set_msix_bit(pdev, 1);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800565
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000566 if (adapter->rss_supported)
567 adapter->max_sds_rings = num_msix;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800568
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000569 dev_info(&pdev->dev, "using msi-x interrupts\n");
570 return;
571 }
572
573 if (err > 0)
574 pci_disable_msix(pdev);
575
576 /* fall through for msi */
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800577 }
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000578
579 if (use_msi && !pci_enable_msi(pdev)) {
580 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
581 adapter->msi_tgt_status =
582 msi_tgt_status[adapter->ahw.pci_func];
583 dev_info(&pdev->dev, "using msi interrupts\n");
Dhananjay Phadkef67f3402009-05-18 21:46:40 -0700584 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000585 return;
586 }
587
588 dev_info(&pdev->dev, "using legacy interrupts\n");
589 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800590}
591
592static void
593netxen_teardown_intr(struct netxen_adapter *adapter)
594{
595 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
596 pci_disable_msix(adapter->pdev);
597 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
598 pci_disable_msi(adapter->pdev);
599}
600
601static void
602netxen_cleanup_pci_map(struct netxen_adapter *adapter)
603{
604 if (adapter->ahw.db_base != NULL)
605 iounmap(adapter->ahw.db_base);
606 if (adapter->ahw.pci_base0 != NULL)
607 iounmap(adapter->ahw.pci_base0);
608 if (adapter->ahw.pci_base1 != NULL)
609 iounmap(adapter->ahw.pci_base1);
610 if (adapter->ahw.pci_base2 != NULL)
611 iounmap(adapter->ahw.pci_base2);
612}
613
614static int
615netxen_setup_pci_map(struct netxen_adapter *adapter)
616{
617 void __iomem *mem_ptr0 = NULL;
618 void __iomem *mem_ptr1 = NULL;
619 void __iomem *mem_ptr2 = NULL;
620 void __iomem *db_ptr = NULL;
621
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800622 unsigned long mem_base, mem_len, db_base, db_len = 0, pci_len0 = 0;
623
624 struct pci_dev *pdev = adapter->pdev;
625 int pci_func = adapter->ahw.pci_func;
626
627 int err = 0;
628
629 /*
630 * Set the CRB window to invalid. If any register in window 0 is
631 * accessed it should set the window to 0 and then reset it to 1.
632 */
633 adapter->curr_window = 255;
634 adapter->ahw.qdr_sn_window = -1;
635 adapter->ahw.ddr_mn_window = -1;
636
637 /* remap phys address */
638 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
639 mem_len = pci_resource_len(pdev, 0);
640 pci_len0 = 0;
641
642 adapter->hw_write_wx = netxen_nic_hw_write_wx_128M;
643 adapter->hw_read_wx = netxen_nic_hw_read_wx_128M;
644 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_128M;
645 adapter->pci_write_immediate = netxen_nic_pci_write_immediate_128M;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800646 adapter->pci_set_window = netxen_nic_pci_set_window_128M;
647 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M;
648 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M;
649
650 /* 128 Meg of memory */
651 if (mem_len == NETXEN_PCI_128MB_SIZE) {
652 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
653 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
654 SECOND_PAGE_GROUP_SIZE);
655 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
656 THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800657 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
658 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
659 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
660 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800661 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
662 adapter->hw_write_wx = netxen_nic_hw_write_wx_2M;
663 adapter->hw_read_wx = netxen_nic_hw_read_wx_2M;
664 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_2M;
665 adapter->pci_write_immediate =
666 netxen_nic_pci_write_immediate_2M;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800667 adapter->pci_set_window = netxen_nic_pci_set_window_2M;
668 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M;
669 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M;
670
671 mem_ptr0 = pci_ioremap_bar(pdev, 0);
672 if (mem_ptr0 == NULL) {
673 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
674 return -EIO;
675 }
676 pci_len0 = mem_len;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800677
678 adapter->ahw.ddr_mn_window = 0;
679 adapter->ahw.qdr_sn_window = 0;
680
681 adapter->ahw.mn_win_crb = 0x100000 + PCIX_MN_WINDOW +
682 (pci_func * 0x20);
683 adapter->ahw.ms_win_crb = 0x100000 + PCIX_SN_WINDOW;
684 if (pci_func < 4)
685 adapter->ahw.ms_win_crb += (pci_func * 0x20);
686 else
687 adapter->ahw.ms_win_crb +=
688 0xA0 + ((pci_func - 4) * 0x10);
689 } else {
690 return -EIO;
691 }
692
693 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
694
695 adapter->ahw.pci_base0 = mem_ptr0;
696 adapter->ahw.pci_len0 = pci_len0;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800697 adapter->ahw.pci_base1 = mem_ptr1;
698 adapter->ahw.pci_base2 = mem_ptr2;
699
700 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
701 goto skip_doorbell;
702
703 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
704 db_len = pci_resource_len(pdev, 4);
705
706 if (db_len == 0) {
707 printk(KERN_ERR "%s: doorbell is disabled\n",
708 netxen_nic_driver_name);
709 err = -EIO;
710 goto err_out;
711 }
712
713 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
714 if (!db_ptr) {
715 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
716 netxen_nic_driver_name);
717 err = -EIO;
718 goto err_out;
719 }
720
721skip_doorbell:
722 adapter->ahw.db_base = db_ptr;
723 adapter->ahw.db_len = db_len;
724 return 0;
725
726err_out:
727 netxen_cleanup_pci_map(adapter);
728 return err;
729}
730
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800731static int
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000732netxen_start_firmware(struct netxen_adapter *adapter, int request_fw)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800733{
734 int val, err, first_boot;
735 struct pci_dev *pdev = adapter->pdev;
736
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000737 int first_driver = 0;
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000738
739 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
740 first_driver = (adapter->portnum == 0);
741 else
742 first_driver = (adapter->ahw.pci_func == 0);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000743
744 if (!first_driver)
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000745 goto wait_init;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000746
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000747 first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800748
749 err = netxen_check_hw_init(adapter, first_boot);
750 if (err) {
751 dev_err(&pdev->dev, "error in init HW init sequence\n");
752 return err;
753 }
754
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000755 if (request_fw)
756 netxen_request_firmware(adapter);
757
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000758 err = netxen_need_fw_reset(adapter);
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000759 if (err < 0)
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000760 goto err_out;
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000761 if (err == 0)
762 goto wait_init;
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000763
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800764 if (first_boot != 0x55555555) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000765 NXWR32(adapter, CRB_CMDPEG_STATE, 0);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800766 netxen_pinit_from_rom(adapter, 0);
767 msleep(1);
768 }
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000769
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000770 NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555);
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000771 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
772 netxen_set_port_mode(adapter);
773
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000774 err = netxen_load_firmware(adapter);
775 if (err)
776 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800777
778 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
779
780 /* Initialize multicast addr pool owners */
781 val = 0x7654;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000782 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800783 val |= 0x0f000000;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000784 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800785
786 }
787
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000788 err = netxen_init_dummy_dma(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800789 if (err)
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000790 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800791
792 /*
793 * Tell the hardware our version number.
794 */
795 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
796 | ((_NETXEN_NIC_LINUX_MINOR << 8))
797 | (_NETXEN_NIC_LINUX_SUBVERSION);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000798 NXWR32(adapter, CRB_DRIVER_VERSION, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800799
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000800wait_init:
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800801 /* Handshake with the card before we register the devices. */
802 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
803 if (err) {
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000804 netxen_free_dummy_dma(adapter);
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000805 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800806 }
807
Dhananjay Phadke68b3cae2009-07-26 20:07:36 +0000808 nx_update_dma_mask(adapter);
809
810 netxen_nic_get_firmware_info(adapter);
811
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800812 return 0;
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000813
814err_out:
815 netxen_release_firmware(adapter);
816 return err;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800817}
818
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000819static int
820netxen_nic_request_irq(struct netxen_adapter *adapter)
821{
822 irq_handler_t handler;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000823 struct nx_host_sds_ring *sds_ring;
824 int err, ring;
825
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000826 unsigned long flags = IRQF_SAMPLE_RANDOM;
827 struct net_device *netdev = adapter->netdev;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000828 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000829
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000830 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
831 handler = netxen_msix_intr;
832 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
833 handler = netxen_msi_intr;
834 else {
835 flags |= IRQF_SHARED;
836 handler = netxen_intr;
837 }
838 adapter->irq = netdev->irq;
839
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000840 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
841 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000842 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000843 err = request_irq(sds_ring->irq, handler,
844 flags, sds_ring->name, sds_ring);
845 if (err)
846 return err;
847 }
848
849 return 0;
850}
851
852static void
853netxen_nic_free_irq(struct netxen_adapter *adapter)
854{
855 int ring;
856 struct nx_host_sds_ring *sds_ring;
857
858 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
859
860 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
861 sds_ring = &recv_ctx->sds_rings[ring];
862 free_irq(sds_ring->irq, sds_ring);
863 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000864}
865
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000866static void
867netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter)
868{
869 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
870 adapter->coal.normal.data.rx_time_us =
871 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
872 adapter->coal.normal.data.rx_packets =
873 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
874 adapter->coal.normal.data.tx_time_us =
875 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US;
876 adapter->coal.normal.data.tx_packets =
877 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS;
878}
879
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000880static int
881netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
882{
883 int err;
884
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000885 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
886 return -EIO;
887
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000888 err = adapter->init_port(adapter, adapter->physical_port);
889 if (err) {
890 printk(KERN_ERR "%s: Failed to initialize port %d\n",
891 netxen_nic_driver_name, adapter->portnum);
892 return err;
893 }
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000894 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
895 adapter->macaddr_set(adapter, netdev->dev_addr);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000896
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000897 adapter->set_multi(netdev);
898 adapter->set_mtu(adapter, netdev->mtu);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000899
900 adapter->ahw.linkup = 0;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000901
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000902 if (adapter->max_sds_rings > 1)
903 netxen_config_rss(adapter, 1);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000904
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000905 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
906 netxen_config_intr_coalesce(adapter);
907
Narender Kumar1bb482f2009-08-23 08:35:09 +0000908 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
909 netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED);
910
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000911 netxen_napi_enable(adapter);
912
Dhananjay Phadke5103c9f2009-04-28 15:29:09 +0000913 if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000914 netxen_linkevent_request(adapter, 1);
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000915 else
916 netxen_nic_set_link_parameters(adapter);
917
918 mod_timer(&adapter->watchdog_timer, jiffies);
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000919
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000920 return 0;
921}
922
923static void
924netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
925{
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000926 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
927 return;
928
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000929 spin_lock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000930 netif_carrier_off(netdev);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000931 netif_tx_disable(netdev);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000932
933 if (adapter->stop_port)
934 adapter->stop_port(adapter);
935
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000936 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
937 netxen_p3_free_mac_list(adapter);
938
Amit Kumar Salecha22b57942009-08-23 08:35:12 +0000939 adapter->set_promisc(adapter, NETXEN_NIU_NON_PROMISC_MODE);
940
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000941 netxen_napi_disable(adapter);
942
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000943 netxen_release_tx_buffers(adapter);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000944 spin_unlock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000945
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000946 del_timer_sync(&adapter->watchdog_timer);
947}
948
949
950static int
951netxen_nic_attach(struct netxen_adapter *adapter)
952{
953 struct net_device *netdev = adapter->netdev;
954 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000955 int err, ring;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000956 struct nx_host_rds_ring *rds_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000957 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000958
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -0700959 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
960 return 0;
961
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000962 err = netxen_init_firmware(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000963 if (err)
964 return err;
965
966 err = netxen_napi_add(adapter, netdev);
967 if (err)
968 return err;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000969
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000970 err = netxen_alloc_sw_resources(adapter);
971 if (err) {
972 printk(KERN_ERR "%s: Error in setting sw resources\n",
973 netdev->name);
974 return err;
975 }
976
977 netxen_nic_clear_stats(adapter);
978
979 err = netxen_alloc_hw_resources(adapter);
980 if (err) {
981 printk(KERN_ERR "%s: Error in setting hw resources\n",
982 netdev->name);
983 goto err_out_free_sw;
984 }
985
Dhananjay Phadke4f96b982009-07-26 20:07:42 +0000986 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000987 tx_ring = adapter->tx_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000988 tx_ring->crb_cmd_producer = crb_cmd_producer[adapter->portnum];
989 tx_ring->crb_cmd_consumer = crb_cmd_consumer[adapter->portnum];
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000990
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000991 tx_ring->producer = 0;
992 tx_ring->sw_consumer = 0;
993
994 netxen_nic_update_cmd_producer(adapter, tx_ring);
995 netxen_nic_update_cmd_consumer(adapter, tx_ring);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000996 }
997
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000998 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
999 rds_ring = &adapter->recv_ctx.rds_rings[ring];
1000 netxen_post_rx_buffers(adapter, ring, rds_ring);
1001 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001002
1003 err = netxen_nic_request_irq(adapter);
1004 if (err) {
1005 dev_err(&pdev->dev, "%s: failed to setup interrupt\n",
1006 netdev->name);
1007 goto err_out_free_rxbuf;
1008 }
1009
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +00001010 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1011 netxen_nic_init_coalesce_defaults(adapter);
1012
Narender Kumarfa3ce352009-08-24 19:23:28 +00001013 netxen_create_sysfs_entries(adapter);
1014
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001015 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1016 return 0;
1017
1018err_out_free_rxbuf:
1019 netxen_release_rx_buffers(adapter);
1020 netxen_free_hw_resources(adapter);
1021err_out_free_sw:
1022 netxen_free_sw_resources(adapter);
1023 return err;
1024}
1025
1026static void
1027netxen_nic_detach(struct netxen_adapter *adapter)
1028{
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001029 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1030 return;
1031
Narender Kumarfa3ce352009-08-24 19:23:28 +00001032 netxen_remove_sysfs_entries(adapter);
1033
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001034 netxen_free_hw_resources(adapter);
Dhananjay Phadkecf981ff2009-07-17 15:27:06 +00001035 netxen_release_rx_buffers(adapter);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +00001036 netxen_nic_free_irq(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +00001037 netxen_napi_del(adapter);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001038 netxen_free_sw_resources(adapter);
1039
1040 adapter->is_up = 0;
1041}
1042
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001043int
1044netxen_nic_reset_context(struct netxen_adapter *adapter)
1045{
1046 int err = 0;
1047 struct net_device *netdev = adapter->netdev;
1048
1049 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
1050
1051 if (netif_running(netdev))
1052 netxen_nic_down(adapter, netdev);
1053
1054 netxen_nic_detach(adapter);
1055
1056 err = netxen_nic_attach(adapter);
1057 if (err)
1058 goto done;
1059
1060 if (netif_running(netdev))
1061 err = netxen_nic_up(adapter, netdev);
1062 }
1063done:
1064 return err;
1065}
1066
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001067static int
1068netxen_setup_netdev(struct netxen_adapter *adapter,
1069 struct net_device *netdev)
1070{
1071 int err = 0;
1072 struct pci_dev *pdev = adapter->pdev;
1073
1074 adapter->rx_csum = 1;
1075 adapter->mc_enabled = 0;
1076 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1077 adapter->max_mc_count = 38;
1078 else
1079 adapter->max_mc_count = 16;
1080
1081 netdev->netdev_ops = &netxen_netdev_ops;
1082 netdev->watchdog_timeo = 2*HZ;
1083
1084 netxen_nic_change_mtu(netdev, netdev->mtu);
1085
1086 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
1087
1088 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1089 netdev->features |= (NETIF_F_GRO);
1090 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1091
1092 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1093 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1094 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1095 }
1096
1097 if (adapter->pci_using_dac) {
1098 netdev->features |= NETIF_F_HIGHDMA;
1099 netdev->vlan_features |= NETIF_F_HIGHDMA;
1100 }
1101
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001102 if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX)
1103 netdev->features |= (NETIF_F_HW_VLAN_TX);
1104
Narender Kumar1bb482f2009-08-23 08:35:09 +00001105 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
1106 netdev->features |= NETIF_F_LRO;
1107
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001108 netdev->irq = adapter->msix_entries[0].vector;
1109
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001110 init_timer(&adapter->watchdog_timer);
1111 adapter->watchdog_timer.function = &netxen_watchdog;
1112 adapter->watchdog_timer.data = (unsigned long)adapter;
1113 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
1114 INIT_WORK(&adapter->tx_timeout_task, netxen_reset_task);
1115
1116 if (netxen_read_mac_addr(adapter))
1117 dev_warn(&pdev->dev, "failed to read mac addr\n");
1118
1119 netif_carrier_off(netdev);
1120 netif_stop_queue(netdev);
1121
1122 err = register_netdev(netdev);
1123 if (err) {
1124 dev_err(&pdev->dev, "failed to register net device\n");
1125 return err;
1126 }
1127
1128 return 0;
1129}
1130
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001131static int __devinit
1132netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1133{
1134 struct net_device *netdev = NULL;
1135 struct netxen_adapter *adapter = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001136 int i = 0, err;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001137 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001138 uint8_t revision_id;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001139
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001140 if (pdev->class != 0x020000) {
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001141 printk(KERN_DEBUG "NetXen function %d, class %x will not "
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001142 "be enabled.\n",pci_func_id, pdev->class);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001143 return -ENODEV;
1144 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001145
Dhananjay Phadke11d89d62008-08-08 00:08:45 -07001146 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
1147 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
1148 "will not be enabled.\n",
1149 NX_P3_A0, NX_P3_B1);
1150 return -ENODEV;
1151 }
1152
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001153 if ((err = pci_enable_device(pdev)))
1154 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001155
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001156 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1157 err = -ENODEV;
1158 goto err_out_disable_pdev;
1159 }
1160
1161 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
1162 goto err_out_disable_pdev;
1163
1164 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001165
1166 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
1167 if(!netdev) {
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001168 dev_err(&pdev->dev, "failed to allocate net_device\n");
1169 err = -ENOMEM;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001170 goto err_out_free_res;
1171 }
1172
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001173 SET_NETDEV_DEV(netdev, &pdev->dev);
1174
Wang Chen4cf16532008-11-12 23:38:14 -08001175 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001176 adapter->netdev = netdev;
1177 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001178 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001179
1180 revision_id = pdev->revision;
1181 adapter->ahw.revision_id = revision_id;
1182
Dhananjay Phadke50c643e2009-08-01 21:36:16 +00001183 err = nx_set_dma_mask(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001184 if (err)
1185 goto err_out_free_netdev;
1186
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001187 rwlock_init(&adapter->adapter_lock);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001188 spin_lock_init(&adapter->tx_clean_lock);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +00001189 INIT_LIST_HEAD(&adapter->mac_list);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001190
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001191 err = netxen_setup_pci_map(adapter);
1192 if (err)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001193 goto err_out_free_netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001194
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +05301195 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001196 adapter->portnum = pci_func_id;
1197
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001198 err = netxen_nic_get_board_info(adapter);
1199 if (err) {
1200 dev_err(&pdev->dev, "Error getting board config info.\n");
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001201 goto err_out_iounmap;
1202 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001203
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001204 netxen_initialize_adapter_ops(adapter);
1205
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001206 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001207 switch (adapter->ahw.board_type) {
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001208 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1209 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1210 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001211 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001212 break;
1213 default:
1214 break;
1215 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001216
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001217 err = netxen_start_firmware(adapter, 1);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001218 if (err)
1219 goto err_out_iounmap;
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001220
Dhananjay Phadke29566402008-07-21 19:44:04 -07001221 /*
1222 * See if the firmware gave us a virtual-physical port mapping.
1223 */
1224 adapter->physical_port = adapter->portnum;
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001225 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001226 i = NXRD32(adapter, CRB_V2P(adapter->portnum));
Dhananjay Phadke044fad02009-02-24 03:42:59 -08001227 if (i != 0x55555555)
1228 adapter->physical_port = i;
1229 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001230
Dhananjay Phadke438627c2009-03-13 14:52:03 +00001231 netxen_check_options(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001232
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001233 netxen_setup_intr(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001234
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001235 err = netxen_setup_netdev(adapter, netdev);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001236 if (err)
Dhananjay Phadke29566402008-07-21 19:44:04 -07001237 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001238
1239 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001240
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001241 switch (adapter->ahw.port_type) {
Dhananjay Phadke29566402008-07-21 19:44:04 -07001242 case NETXEN_NIC_GBE:
1243 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1244 adapter->netdev->name);
1245 break;
1246 case NETXEN_NIC_XGBE:
1247 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1248 adapter->netdev->name);
1249 break;
1250 }
1251
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001252 return 0;
1253
Dhananjay Phadke29566402008-07-21 19:44:04 -07001254err_out_disable_msi:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001255 netxen_teardown_intr(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001256
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001257 netxen_free_dummy_dma(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001258
Dhananjay Phadke29566402008-07-21 19:44:04 -07001259err_out_iounmap:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001260 netxen_cleanup_pci_map(adapter);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001261
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001262err_out_free_netdev:
1263 free_netdev(netdev);
1264
1265err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001266 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001267
1268err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001269 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001270 pci_disable_device(pdev);
1271 return err;
1272}
1273
1274static void __devexit netxen_nic_remove(struct pci_dev *pdev)
1275{
1276 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001277 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001278
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001279 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001280 if (adapter == NULL)
1281 return;
1282
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001283 netdev = adapter->netdev;
1284
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301285 unregister_netdev(netdev);
1286
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001287 cancel_work_sync(&adapter->watchdog_task);
1288 cancel_work_sync(&adapter->tx_timeout_task);
1289
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001290 netxen_nic_detach(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001291
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001292 if (adapter->portnum == 0)
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001293 netxen_free_dummy_dma(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301294
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001295 netxen_teardown_intr(adapter);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301296
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001297 netxen_cleanup_pci_map(adapter);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001298
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001299 netxen_release_firmware(adapter);
1300
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001301 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301302 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001303 pci_set_drvdata(pdev, NULL);
1304
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001305 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001306}
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001307static int __netxen_nic_shutdown(struct pci_dev *pdev)
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001308{
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001309 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1310 struct net_device *netdev = adapter->netdev;
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001311 int retval;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001312
1313 netif_device_detach(netdev);
1314
1315 if (netif_running(netdev))
1316 netxen_nic_down(adapter, netdev);
1317
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001318 cancel_work_sync(&adapter->watchdog_task);
1319 cancel_work_sync(&adapter->tx_timeout_task);
1320
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001321 netxen_nic_detach(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001322
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001323 if (adapter->portnum == 0)
1324 netxen_free_dummy_dma(adapter);
1325
1326 retval = pci_save_state(pdev);
1327 if (retval)
1328 return retval;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001329
1330 if (netxen_nic_wol_supported(adapter)) {
1331 pci_enable_wake(pdev, PCI_D3cold, 1);
1332 pci_enable_wake(pdev, PCI_D3hot, 1);
1333 }
1334
1335 pci_disable_device(pdev);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001336
1337 return 0;
1338}
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001339static void netxen_nic_shutdown(struct pci_dev *pdev)
1340{
1341 if (__netxen_nic_shutdown(pdev))
1342 return;
1343}
1344#ifdef CONFIG_PM
1345static int
1346netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
1347{
1348 int retval;
1349
1350 retval = __netxen_nic_shutdown(pdev);
1351 if (retval)
1352 return retval;
1353
1354 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1355 return 0;
1356}
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001357
1358static int
1359netxen_nic_resume(struct pci_dev *pdev)
1360{
1361 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1362 struct net_device *netdev = adapter->netdev;
1363 int err;
1364
1365 pci_set_power_state(pdev, PCI_D0);
1366 pci_restore_state(pdev);
1367
1368 err = pci_enable_device(pdev);
1369 if (err)
1370 return err;
1371
1372 adapter->curr_window = 255;
1373
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001374 err = netxen_start_firmware(adapter, 0);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001375 if (err) {
1376 dev_err(&pdev->dev, "failed to start firmware\n");
1377 return err;
1378 }
1379
1380 if (netif_running(netdev)) {
1381 err = netxen_nic_attach(adapter);
1382 if (err)
1383 return err;
1384
1385 err = netxen_nic_up(adapter, netdev);
1386 if (err)
1387 return err;
1388
1389 netif_device_attach(netdev);
1390 }
1391
1392 return 0;
1393}
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00001394#endif
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001395
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001396static int netxen_nic_open(struct net_device *netdev)
1397{
Wang Chen4cf16532008-11-12 23:38:14 -08001398 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001399 int err = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001400
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001401 if (adapter->driver_mismatch)
1402 return -EIO;
1403
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001404 err = netxen_nic_attach(adapter);
1405 if (err)
1406 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001407
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001408 err = netxen_nic_up(adapter, netdev);
1409 if (err)
1410 goto err_out;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001411
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001412 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001413
1414 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001415
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001416err_out:
1417 netxen_nic_detach(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001418 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001419}
1420
1421/*
1422 * netxen_nic_close - Disables a network interface entry point
1423 */
1424static int netxen_nic_close(struct net_device *netdev)
1425{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001426 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001427
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001428 netxen_nic_down(adapter, netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001429 return 0;
1430}
1431
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001432static void
1433netxen_tso_check(struct net_device *netdev,
1434 struct nx_host_tx_ring *tx_ring,
1435 struct cmd_desc_type0 *first_desc,
1436 struct sk_buff *skb)
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001437{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001438 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001439 __be16 protocol = skb->protocol;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001440 u16 flags = 0, vid = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001441 u32 producer;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001442 int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001443 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001444 struct vlan_ethhdr *vh;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001445
Harvey Harrison09640e62009-02-01 00:45:17 -08001446 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001447
1448 vh = (struct vlan_ethhdr *)skb->data;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001449 protocol = vh->h_vlan_encapsulated_proto;
1450 flags = FLAGS_VLAN_TAGGED;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001451
1452 } else if (vlan_tx_tag_present(skb)) {
1453
1454 flags = FLAGS_VLAN_OOB;
1455 vid = vlan_tx_tag_get(skb);
1456 netxen_set_tx_vlan_tci(first_desc, vid);
1457 vlan_oob = 1;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001458 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001459
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001460 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1461 skb_shinfo(skb)->gso_size > 0) {
1462
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001463 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1464
1465 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1466 first_desc->total_hdr_length = hdr_len;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001467 if (vlan_oob) {
1468 first_desc->total_hdr_length += VLAN_HLEN;
1469 first_desc->tcp_hdr_offset = VLAN_HLEN;
1470 first_desc->ip_hdr_offset = VLAN_HLEN;
1471 /* Only in case of TSO on vlan device */
1472 flags |= FLAGS_VLAN_TAGGED;
1473 }
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001474
Harvey Harrison09640e62009-02-01 00:45:17 -08001475 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001476 TX_TCP_LSO6 : TX_TCP_LSO;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001477 tso = 1;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001478
1479 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001480 u8 l4proto;
1481
Harvey Harrison09640e62009-02-01 00:45:17 -08001482 if (protocol == cpu_to_be16(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001483 l4proto = ip_hdr(skb)->protocol;
1484
1485 if (l4proto == IPPROTO_TCP)
1486 opcode = TX_TCP_PKT;
1487 else if(l4proto == IPPROTO_UDP)
1488 opcode = TX_UDP_PKT;
Harvey Harrison09640e62009-02-01 00:45:17 -08001489 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001490 l4proto = ipv6_hdr(skb)->nexthdr;
1491
1492 if (l4proto == IPPROTO_TCP)
1493 opcode = TX_TCPV6_PKT;
1494 else if(l4proto == IPPROTO_UDP)
1495 opcode = TX_UDPV6_PKT;
1496 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001497 }
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001498
1499 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
1500 first_desc->ip_hdr_offset += skb_network_offset(skb);
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001501 netxen_set_tx_flags_opcode(first_desc, flags, opcode);
1502
1503 if (!tso)
1504 return;
1505
1506 /* For LSO, we need to copy the MAC/IP/TCP headers into
1507 * the descriptor ring
1508 */
1509 producer = tx_ring->producer;
1510 copied = 0;
1511 offset = 2;
1512
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001513 if (vlan_oob) {
1514 /* Create a TSO vlan header template for firmware */
1515
1516 hwdesc = &tx_ring->desc_head[producer];
1517 tx_ring->cmd_buf_arr[producer].skb = NULL;
1518
1519 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1520 hdr_len + VLAN_HLEN);
1521
1522 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2);
1523 skb_copy_from_linear_data(skb, vh, 12);
1524 vh->h_vlan_proto = htons(ETH_P_8021Q);
1525 vh->h_vlan_TCI = htons(vid);
1526 skb_copy_from_linear_data_offset(skb, 12,
1527 (char *)vh + 16, copy_len - 16);
1528
Dhananjay Phadke545eb372009-08-05 07:34:07 +00001529 copied = copy_len - VLAN_HLEN;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001530 offset = 0;
1531
1532 producer = get_next_index(producer, tx_ring->num_desc);
1533 }
1534
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001535 while (copied < hdr_len) {
1536
1537 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1538 (hdr_len - copied));
1539
1540 hwdesc = &tx_ring->desc_head[producer];
1541 tx_ring->cmd_buf_arr[producer].skb = NULL;
1542
1543 skb_copy_from_linear_data_offset(skb, copied,
1544 (char *)hwdesc + offset, copy_len);
1545
1546 copied += copy_len;
1547 offset = 0;
1548
1549 producer = get_next_index(producer, tx_ring->num_desc);
1550 }
1551
1552 tx_ring->producer = producer;
1553 barrier();
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001554}
1555
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001556static int
1557netxen_map_tx_skb(struct pci_dev *pdev,
1558 struct sk_buff *skb, struct netxen_cmd_buffer *pbuf)
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001559{
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001560 struct netxen_skb_frag *nf;
1561 struct skb_frag_struct *frag;
1562 int i, nr_frags;
1563 dma_addr_t map;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001564
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001565 nr_frags = skb_shinfo(skb)->nr_frags;
1566 nf = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001567
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001568 map = pci_map_single(pdev, skb->data,
1569 skb_headlen(skb), PCI_DMA_TODEVICE);
1570 if (pci_dma_mapping_error(pdev, map))
1571 goto out_err;
1572
1573 nf->dma = map;
1574 nf->length = skb_headlen(skb);
1575
1576 for (i = 0; i < nr_frags; i++) {
1577 frag = &skb_shinfo(skb)->frags[i];
1578 nf = &pbuf->frag_array[i+1];
1579
1580 map = pci_map_page(pdev, frag->page, frag->page_offset,
1581 frag->size, PCI_DMA_TODEVICE);
1582 if (pci_dma_mapping_error(pdev, map))
1583 goto unwind;
1584
1585 nf->dma = map;
1586 nf->length = frag->size;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001587 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001588
1589 return 0;
1590
1591unwind:
Dhananjay Phadkecf503e82009-09-03 13:10:55 +00001592 while (--i >= 0) {
1593 nf = &pbuf->frag_array[i+1];
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001594 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
1595 }
1596
1597 nf = &pbuf->frag_array[0];
1598 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
1599
1600out_err:
1601 return -ENOMEM;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001602}
1603
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001604static inline void
1605netxen_clear_cmddesc(u64 *desc)
1606{
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001607 desc[0] = 0ULL;
1608 desc[2] = 0ULL;
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001609}
1610
Stephen Hemminger613573252009-08-31 19:50:58 +00001611static netdev_tx_t
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001612netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001613{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001614 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001615 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001616 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001617 struct netxen_skb_frag *buffrag;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001618 struct cmd_desc_type0 *hwdesc, *first_desc;
1619 struct pci_dev *pdev;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001620 int i, k;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001621
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001622 u32 producer;
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001623 int frag_count, no_of_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001624 u32 num_txd = tx_ring->num_desc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001625
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001626 frag_count = skb_shinfo(skb)->nr_frags + 1;
1627
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001628 /* 4 fragments per cmd des */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001629 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001630
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001631 if (unlikely(no_of_desc + 2) > netxen_tx_avail(tx_ring)) {
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001632 netif_stop_queue(netdev);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001633 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001634 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001635
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001636 producer = tx_ring->producer;
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001637 pbuf = &tx_ring->cmd_buf_arr[producer];
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001638
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001639 pdev = adapter->pdev;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001640
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001641 if (netxen_map_tx_skb(pdev, skb, pbuf))
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001642 goto drop_packet;
1643
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001644 pbuf->skb = skb;
1645 pbuf->frag_count = frag_count;
1646
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001647 first_desc = hwdesc = &tx_ring->desc_head[producer];
1648 netxen_clear_cmddesc((u64 *)hwdesc);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001649
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001650 netxen_set_tx_frags_len(first_desc, frag_count, skb->len);
1651 netxen_set_tx_port(first_desc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001652
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001653 for (i = 0; i < frag_count; i++) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001654
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001655 k = i % 4;
1656
1657 if ((k == 0) && (i > 0)) {
1658 /* move to next desc.*/
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001659 producer = get_next_index(producer, num_txd);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001660 hwdesc = &tx_ring->desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001661 netxen_clear_cmddesc((u64 *)hwdesc);
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001662 tx_ring->cmd_buf_arr[producer].skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001663 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001664
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001665 buffrag = &pbuf->frag_array[i];
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001666
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001667 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001668 switch (k) {
1669 case 0:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001670 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001671 break;
1672 case 1:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001673 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001674 break;
1675 case 2:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001676 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001677 break;
1678 case 3:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001679 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001680 break;
1681 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001682 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001683
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001684 tx_ring->producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001685
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001686 netxen_tso_check(netdev, tx_ring, first_desc, skb);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001687
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001688 netxen_nic_update_cmd_producer(adapter, tx_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001689
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001690 adapter->stats.txbytes += skb->len;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001691 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001692
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001693 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001694
1695drop_packet:
1696 adapter->stats.txdropped++;
1697 dev_kfree_skb_any(skb);
1698 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001699}
1700
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001701static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1702{
1703 struct net_device *netdev = adapter->netdev;
1704 uint32_t temp, temp_state, temp_val;
1705 int rv = 0;
1706
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001707 temp = NXRD32(adapter, CRB_TEMP_STATE);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001708
1709 temp_state = nx_get_temp_state(temp);
1710 temp_val = nx_get_temp_val(temp);
1711
1712 if (temp_state == NX_TEMP_PANIC) {
1713 printk(KERN_ALERT
1714 "%s: Device temperature %d degrees C exceeds"
1715 " maximum allowed. Hardware has been shut down.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001716 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001717 rv = 1;
1718 } else if (temp_state == NX_TEMP_WARN) {
1719 if (adapter->temp == NX_TEMP_NORMAL) {
1720 printk(KERN_ALERT
1721 "%s: Device temperature %d degrees C "
1722 "exceeds operating range."
1723 " Immediate action needed.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001724 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001725 }
1726 } else {
1727 if (adapter->temp == NX_TEMP_WARN) {
1728 printk(KERN_INFO
1729 "%s: Device temperature is now %d degrees C"
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001730 " in normal range.\n", netdev->name,
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001731 temp_val);
1732 }
1733 }
1734 adapter->temp = temp_state;
1735 return rv;
1736}
1737
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001738void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup)
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001739{
1740 struct net_device *netdev = adapter->netdev;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001741
1742 if (adapter->ahw.linkup && !linkup) {
1743 printk(KERN_INFO "%s: %s NIC Link is down\n",
1744 netxen_nic_driver_name, netdev->name);
1745 adapter->ahw.linkup = 0;
1746 if (netif_running(netdev)) {
1747 netif_carrier_off(netdev);
1748 netif_stop_queue(netdev);
1749 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001750 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001751 } else if (!adapter->ahw.linkup && linkup) {
1752 printk(KERN_INFO "%s: %s NIC Link is up\n",
1753 netxen_nic_driver_name, netdev->name);
1754 adapter->ahw.linkup = 1;
1755 if (netif_running(netdev)) {
1756 netif_carrier_on(netdev);
1757 netif_wake_queue(netdev);
1758 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001759 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001760 }
1761}
1762
1763static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1764{
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001765 u32 val, port, linkup;
1766
1767 port = adapter->physical_port;
1768
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001769 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001770 val = NXRD32(adapter, CRB_XG_STATE_P3);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001771 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1772 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001773 } else {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001774 val = NXRD32(adapter, CRB_XG_STATE);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001775 if (adapter->ahw.port_type == NETXEN_NIC_GBE)
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001776 linkup = (val >> port) & 1;
1777 else {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001778 val = (val >> port*8) & 0xff;
1779 linkup = (val == XG_LINK_UP);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001780 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001781 }
1782
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001783 netxen_advert_link_change(adapter, linkup);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001784}
1785
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001786static void netxen_nic_thermal_shutdown(struct netxen_adapter *adapter)
1787{
1788 struct net_device *netdev = adapter->netdev;
1789
1790 netif_device_detach(netdev);
1791 netxen_nic_down(adapter, netdev);
1792 netxen_nic_detach(adapter);
1793}
1794
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001795static void netxen_watchdog(unsigned long v)
1796{
1797 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001798
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001799 if (netxen_nic_check_temp(adapter))
1800 goto do_sched;
1801
1802 if (!adapter->has_link_events) {
1803 netxen_nic_handle_phy_intr(adapter);
1804
1805 if (adapter->link_changed)
1806 goto do_sched;
1807 }
1808
1809 if (netif_running(adapter->netdev))
1810 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1811
1812 return;
1813
1814do_sched:
1815 schedule_work(&adapter->watchdog_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001816}
1817
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001818void netxen_watchdog_task(struct work_struct *work)
1819{
1820 struct netxen_adapter *adapter =
1821 container_of(work, struct netxen_adapter, watchdog_task);
1822
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001823 if (adapter->temp == NX_TEMP_PANIC) {
1824 netxen_nic_thermal_shutdown(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001825 return;
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001826 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001827
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001828 if (adapter->link_changed)
1829 netxen_nic_set_link_parameters(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001830
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001831 if (netif_running(adapter->netdev))
1832 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001833}
1834
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001835static void netxen_tx_timeout(struct net_device *netdev)
1836{
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001837 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001838
1839 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001840 schedule_work(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001841}
1842
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001843static void netxen_reset_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001844{
Jeff Garzik47906542007-11-23 21:23:36 -05001845 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001846 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001847
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001848 if (!netif_running(adapter->netdev))
1849 return;
1850
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001851 netxen_napi_disable(adapter);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001852
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001853 adapter->netdev->trans_start = jiffies;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001854
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001855 netxen_napi_enable(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001856 netif_wake_queue(adapter->netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001857}
1858
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001859struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1860{
1861 struct netxen_adapter *adapter = netdev_priv(netdev);
1862 struct net_device_stats *stats = &adapter->net_stats;
1863
1864 memset(stats, 0, sizeof(*stats));
1865
Narender Kumar1bb482f2009-08-23 08:35:09 +00001866 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00001867 stats->tx_packets = adapter->stats.xmitfinished;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001868 stats->rx_bytes = adapter->stats.rxbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001869 stats->tx_bytes = adapter->stats.txbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001870 stats->rx_dropped = adapter->stats.rxdropped;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001871 stats->tx_dropped = adapter->stats.txdropped;
1872
1873 return stats;
1874}
1875
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001876static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001877{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001878 struct nx_host_sds_ring *sds_ring = data;
1879 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001880 u32 status = 0;
1881
1882 status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1883
1884 if (!(status & adapter->legacy_intr.int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001885 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301886
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001887 if (adapter->ahw.revision_id >= NX_P3_B1) {
1888 /* check interrupt state machine, to be sure */
1889 status = adapter->pci_read_immediate(adapter,
1890 ISR_INT_STATE_REG);
1891 if (!ISR_LEGACY_INT_TRIGGERED(status))
1892 return IRQ_NONE;
1893
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001894 } else {
1895 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001896
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001897 our_int = NXRD32(adapter, CRB_INT_VECTOR);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001898
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001899 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001900 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001901 return IRQ_NONE;
1902
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001903 /* claim interrupt */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001904 NXWR32(adapter, CRB_INT_VECTOR, (our_int & 0xffffffff));
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301905 }
1906
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001907 /* clear interrupt */
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001908 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001909 netxen_nic_disable_int(sds_ring);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001910
1911 adapter->pci_write_immediate(adapter,
1912 adapter->legacy_intr.tgt_status_reg,
1913 0xffffffff);
1914 /* read twice to ensure write is flushed */
1915 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1916 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1917
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001918 napi_schedule(&sds_ring->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001919
1920 return IRQ_HANDLED;
1921}
1922
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001923static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001924{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001925 struct nx_host_sds_ring *sds_ring = data;
1926 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001927
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001928 /* clear interrupt */
1929 adapter->pci_write_immediate(adapter,
Dhananjay Phadke7a2469c2009-05-08 22:02:27 +00001930 adapter->msi_tgt_status, 0xffffffff);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001931
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001932 napi_schedule(&sds_ring->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001933 return IRQ_HANDLED;
1934}
1935
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001936static irqreturn_t netxen_msix_intr(int irq, void *data)
1937{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001938 struct nx_host_sds_ring *sds_ring = data;
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001939
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001940 napi_schedule(&sds_ring->napi);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001941 return IRQ_HANDLED;
1942}
1943
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001944static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001945{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001946 struct nx_host_sds_ring *sds_ring =
1947 container_of(napi, struct nx_host_sds_ring, napi);
1948
1949 struct netxen_adapter *adapter = sds_ring->adapter;
1950
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001951 int tx_complete;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001952 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001953
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001954 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001955
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001956 work_done = netxen_process_rcv_ring(sds_ring, budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001957
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001958 if ((work_done < budget) && tx_complete) {
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001959 napi_complete(&sds_ring->napi);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001960 if (netif_running(adapter->netdev))
1961 netxen_nic_enable_int(sds_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001962 }
1963
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001964 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001965}
1966
1967#ifdef CONFIG_NET_POLL_CONTROLLER
1968static void netxen_nic_poll_controller(struct net_device *netdev)
1969{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001970 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001971 disable_irq(adapter->irq);
Jeff Garzik1494a812006-11-07 05:12:16 -05001972 netxen_intr(adapter->irq, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001973 enable_irq(adapter->irq);
1974}
1975#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001976
Narender Kumarfa3ce352009-08-24 19:23:28 +00001977static ssize_t
1978netxen_store_bridged_mode(struct device *dev,
1979 struct device_attribute *attr, const char *buf, size_t len)
1980{
1981 struct net_device *net = to_net_dev(dev);
1982 struct netxen_adapter *adapter = netdev_priv(net);
1983 unsigned long new;
1984 int ret = -EINVAL;
1985
1986 if (!(adapter->capabilities & NX_FW_CAPABILITY_BDG))
1987 goto err_out;
1988
1989 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1990 goto err_out;
1991
1992 if (strict_strtoul(buf, 2, &new))
1993 goto err_out;
1994
1995 if (!netxen_config_bridged_mode(adapter, !!new))
1996 ret = len;
1997
1998err_out:
1999 return ret;
2000}
2001
2002static ssize_t
2003netxen_show_bridged_mode(struct device *dev,
2004 struct device_attribute *attr, char *buf)
2005{
2006 struct net_device *net = to_net_dev(dev);
2007 struct netxen_adapter *adapter;
2008 int bridged_mode = 0;
2009
2010 adapter = netdev_priv(net);
2011
2012 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2013 bridged_mode = !!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED);
2014
2015 return sprintf(buf, "%d\n", bridged_mode);
2016}
2017
2018static struct device_attribute dev_attr_bridged_mode = {
2019 .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
2020 .show = netxen_show_bridged_mode,
2021 .store = netxen_store_bridged_mode,
2022};
2023
2024static void
2025netxen_create_sysfs_entries(struct netxen_adapter *adapter)
2026{
2027 struct net_device *netdev = adapter->netdev;
2028 struct device *dev = &netdev->dev;
2029
2030 if (adapter->capabilities & NX_FW_CAPABILITY_BDG) {
2031 /* bridged_mode control */
2032 if (device_create_file(dev, &dev_attr_bridged_mode)) {
2033 dev_warn(&netdev->dev,
2034 "failed to create bridged_mode sysfs entry\n");
2035 }
2036 }
2037}
2038
2039static void
2040netxen_remove_sysfs_entries(struct netxen_adapter *adapter)
2041{
2042 struct net_device *netdev = adapter->netdev;
2043 struct device *dev = &netdev->dev;
2044
2045 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2046 device_remove_file(dev, &dev_attr_bridged_mode);
2047}
2048
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002049#ifdef CONFIG_INET
2050
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002051#define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2052
2053static int
2054netxen_destip_supported(struct netxen_adapter *adapter)
2055{
2056 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2057 return 0;
2058
2059 if (adapter->ahw.cut_through)
2060 return 0;
2061
2062 return 1;
2063}
2064
2065static int netxen_netdev_event(struct notifier_block *this,
2066 unsigned long event, void *ptr)
2067{
2068 struct netxen_adapter *adapter;
2069 struct net_device *dev = (struct net_device *)ptr;
2070 struct in_device *indev;
2071
2072recheck:
2073 if (dev == NULL)
2074 goto done;
2075
2076 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2077 dev = vlan_dev_real_dev(dev);
2078 goto recheck;
2079 }
2080
2081 if (!is_netxen_netdev(dev))
2082 goto done;
2083
2084 adapter = netdev_priv(dev);
2085
2086 if (!adapter || !netxen_destip_supported(adapter))
2087 goto done;
2088
2089 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2090 goto done;
2091
2092 indev = in_dev_get(dev);
2093 if (!indev)
2094 goto done;
2095
2096 for_ifa(indev) {
2097 switch (event) {
2098 case NETDEV_UP:
2099 netxen_config_ipaddr(adapter,
2100 ifa->ifa_address, NX_IP_UP);
2101 break;
2102 case NETDEV_DOWN:
2103 netxen_config_ipaddr(adapter,
2104 ifa->ifa_address, NX_IP_DOWN);
2105 break;
2106 default:
2107 break;
2108 }
2109 } endfor_ifa(indev);
2110
2111 in_dev_put(indev);
2112done:
2113 return NOTIFY_DONE;
2114}
2115
2116static int
2117netxen_inetaddr_event(struct notifier_block *this,
2118 unsigned long event, void *ptr)
2119{
2120 struct netxen_adapter *adapter;
2121 struct net_device *dev;
2122
2123 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
2124
2125 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
2126
2127recheck:
2128 if (dev == NULL || !netif_running(dev))
2129 goto done;
2130
2131 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2132 dev = vlan_dev_real_dev(dev);
2133 goto recheck;
2134 }
2135
2136 if (!is_netxen_netdev(dev))
2137 goto done;
2138
2139 adapter = netdev_priv(dev);
2140
2141 if (!adapter || !netxen_destip_supported(adapter))
2142 goto done;
2143
2144 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2145 goto done;
2146
2147 switch (event) {
2148 case NETDEV_UP:
2149 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP);
2150 break;
2151 case NETDEV_DOWN:
2152 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN);
2153 break;
2154 default:
2155 break;
2156 }
2157
2158done:
2159 return NOTIFY_DONE;
2160}
2161
2162static struct notifier_block netxen_netdev_cb = {
2163 .notifier_call = netxen_netdev_event,
2164};
2165
2166static struct notifier_block netxen_inetaddr_cb = {
2167 .notifier_call = netxen_inetaddr_event,
2168};
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002169#endif
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002170
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002171static struct pci_driver netxen_driver = {
2172 .name = netxen_nic_driver_name,
2173 .id_table = netxen_pci_tbl,
2174 .probe = netxen_nic_probe,
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002175 .remove = __devexit_p(netxen_nic_remove),
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002176#ifdef CONFIG_PM
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002177 .suspend = netxen_nic_suspend,
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00002178 .resume = netxen_nic_resume,
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002179#endif
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00002180 .shutdown = netxen_nic_shutdown
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002181};
2182
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002183static int __init netxen_init_module(void)
2184{
Dhananjay Phadkeff4fbd42009-03-13 14:52:06 +00002185 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
2186
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002187#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002188 register_netdevice_notifier(&netxen_netdev_cb);
2189 register_inetaddr_notifier(&netxen_inetaddr_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002190#endif
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002191
Amit S. Kale184231b2007-01-22 06:52:53 -08002192 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002193}
2194
2195module_init(netxen_init_module);
2196
2197static void __exit netxen_exit_module(void)
2198{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002199 pci_unregister_driver(&netxen_driver);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002200
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002201#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002202 unregister_inetaddr_notifier(&netxen_inetaddr_cb);
2203 unregister_netdevice_notifier(&netxen_netdev_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002204#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002205}
2206
2207module_exit(netxen_exit_module);