blob: e8a4b66559999b2fef6e375fb568abfa8f663786 [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.
Dhananjay Phadke13af7a62009-09-11 11:28:15 +00003 * Copyright (C) 2009 - QLogic Corporation.
Amit S. Kale3d396eb2006-10-21 15:33:03 -04004 * All rights reserved.
Amit S. Kale80922fb2006-12-04 09:18:00 -08005 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -04006 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
Amit S. Kale80922fb2006-12-04 09:18:00 -080010 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040011 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Amit S. Kale80922fb2006-12-04 09:18:00 -080015 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040016 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
Amit S. Kale80922fb2006-12-04 09:18:00 -080020 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040021 * The full GNU General Public License is included in this distribution
Amit Kumar Salecha4d21fef2010-01-14 01:53:23 +000022 * in the file called "COPYING".
Amit S. Kale80922fb2006-12-04 09:18:00 -080023 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040024 */
25
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Amit S. Kalecb8011a2006-11-29 09:00:10 -080027#include <linux/vmalloc.h>
Dhananjay Phadkee98e3352009-04-07 22:50:38 +000028#include <linux/interrupt.h>
Amit S. Kale3d396eb2006-10-21 15:33:03 -040029#include "netxen_nic_hw.h"
30
31#include "netxen_nic.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040032
Jeff Garzik1494a812006-11-07 05:12:16 -050033#include <linux/dma-mapping.h>
Dhananjay Phadke391587c2009-01-14 20:48:11 -080034#include <linux/if_vlan.h>
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030035#include <net/ip.h>
Dhananjay Phadke00977782009-01-16 11:03:25 -080036#include <linux/ipv6.h>
Dhananjay Phadke6598b162009-07-26 20:07:37 +000037#include <linux/inetdevice.h>
Randy Dunlap0531d7b82009-10-26 12:09:45 +000038#include <linux/sysfs.h>
Amit Kumar Salechae87ad552009-12-08 20:40:56 +000039#include <linux/aer.h>
Jeff Garzik1494a812006-11-07 05:12:16 -050040
Amit Kumar Salecha0438a1b2010-12-31 10:55:38 -080041MODULE_DESCRIPTION("QLogic/NetXen (1/10) GbE Intelligent Ethernet Driver");
Amit S. Kale3d396eb2006-10-21 15:33:03 -040042MODULE_LICENSE("GPL");
43MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
Dhananjay Phadke7e8e5d92009-10-24 16:04:02 +000044MODULE_FIRMWARE(NX_UNIFIED_ROMIMAGE_NAME);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040045
dhananjay@netxen.comceded322007-07-19 14:41:09 +053046char netxen_nic_driver_name[] = "netxen_nic";
Dhananjay Phadkec25c0b92009-10-28 04:11:04 -070047static char netxen_nic_driver_string[] = "QLogic/NetXen Network Driver v"
Amit S. Kalecb8011a2006-11-29 09:00:10 -080048 NETXEN_NIC_LINUX_VERSIONID;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040049
Dhananjay Phadke29566402008-07-21 19:44:04 -070050static int port_mode = NETXEN_PORT_MODE_AUTO_NEG;
51
52/* Default to restricted 1G auto-neg mode */
53static int wol_port_mode = 5;
54
55static int use_msi = 1;
56
57static int use_msi_x = 1;
58
Stephen Hemmingerafdafff2009-12-18 20:13:35 -080059static int auto_fw_reset = AUTO_FW_RESET_ENABLED;
60module_param(auto_fw_reset, int, 0644);
61MODULE_PARM_DESC(auto_fw_reset,"Auto firmware reset (0=disabled, 1=enabled");
Narender Kumarcaa2dd52009-10-16 15:50:11 +000062
Amit S. Kale3d396eb2006-10-21 15:33:03 -040063static int __devinit netxen_nic_probe(struct pci_dev *pdev,
Dhananjay Phadke29566402008-07-21 19:44:04 -070064 const struct pci_device_id *ent);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040065static void __devexit netxen_nic_remove(struct pci_dev *pdev);
66static int netxen_nic_open(struct net_device *netdev);
67static int netxen_nic_close(struct net_device *netdev);
Stephen Hemminger613573252009-08-31 19:50:58 +000068static netdev_tx_t netxen_nic_xmit_frame(struct sk_buff *,
69 struct net_device *);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040070static void netxen_tx_timeout(struct net_device *netdev);
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +000071static void netxen_tx_timeout_task(struct work_struct *work);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +000072static void netxen_fw_poll_work(struct work_struct *work);
73static void netxen_schedule_work(struct netxen_adapter *adapter,
74 work_func_t func, int delay);
75static void netxen_cancel_fw_work(struct netxen_adapter *adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -070076static int netxen_nic_poll(struct napi_struct *napi, int budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040077#ifdef CONFIG_NET_POLL_CONTROLLER
78static void netxen_nic_poll_controller(struct net_device *netdev);
79#endif
Narender Kumarfa3ce352009-08-24 19:23:28 +000080
81static void netxen_create_sysfs_entries(struct netxen_adapter *adapter);
82static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter);
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +000083static void netxen_create_diag_entries(struct netxen_adapter *adapter);
84static void netxen_remove_diag_entries(struct netxen_adapter *adapter);
Narender Kumarfa3ce352009-08-24 19:23:28 +000085
Amit Kumar Salechae87ad552009-12-08 20:40:56 +000086static int nx_dev_request_aer(struct netxen_adapter *adapter);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +000087static int nx_decr_dev_ref_cnt(struct netxen_adapter *adapter);
88static int netxen_can_start_firmware(struct netxen_adapter *adapter);
89
Jeff Garzik1494a812006-11-07 05:12:16 -050090static irqreturn_t netxen_intr(int irq, void *data);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -070091static irqreturn_t netxen_msi_intr(int irq, void *data);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -080092static irqreturn_t netxen_msix_intr(int irq, void *data);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040093
Amit Kumar Salechad0725e42009-09-05 17:43:09 +000094static void netxen_config_indev_addr(struct net_device *dev, unsigned long);
stephen hemminger7e12bb0a2010-10-18 17:40:10 +000095static struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev);
96static int netxen_nic_set_mac(struct net_device *netdev, void *p);
Amit Kumar Salechad0725e42009-09-05 17:43:09 +000097
Amit S. Kale3d396eb2006-10-21 15:33:03 -040098/* PCI Device ID Table */
Al Viro70081ac2008-06-23 02:04:50 +010099#define ENTRY(device) \
Dhananjay Phadke040dec32008-09-12 06:55:14 -0700100 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
Al Viro70081ac2008-06-23 02:04:50 +0100101 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
102
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000103static DEFINE_PCI_DEVICE_TABLE(netxen_pci_tbl) = {
Dhananjay Phadke040dec32008-09-12 06:55:14 -0700104 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR),
105 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4),
106 ENTRY(PCI_DEVICE_ID_NX2031_4GCU),
107 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ),
108 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ),
109 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT),
110 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2),
111 ENTRY(PCI_DEVICE_ID_NX3031),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400112 {0,}
113};
114
115MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
116
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700117static uint32_t crb_cmd_producer[4] = {
118 CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1,
119 CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3
120};
121
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700122void
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700123netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000124 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700125{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000126 NXWRIO(adapter, tx_ring->crb_cmd_producer, tx_ring->producer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700127}
128
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700129static uint32_t crb_cmd_consumer[4] = {
130 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
131 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
132};
133
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700134static inline void
135netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000136 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700137{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000138 NXWRIO(adapter, tx_ring->crb_cmd_consumer, tx_ring->sw_consumer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700139}
140
Dhananjay Phadke29566402008-07-21 19:44:04 -0700141static uint32_t msi_tgt_status[8] = {
Dhananjay Phadke443be792008-03-17 19:59:48 -0700142 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700143 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
144 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
145 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
Dhananjay Phadke443be792008-03-17 19:59:48 -0700146};
147
Dhananjay Phadke29566402008-07-21 19:44:04 -0700148static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
149
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000150static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700151{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000152 struct netxen_adapter *adapter = sds_ring->adapter;
153
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000154 NXWRIO(adapter, sds_ring->crb_intr_mask, 0);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700155}
156
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000157static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700158{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000159 struct netxen_adapter *adapter = sds_ring->adapter;
160
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000161 NXWRIO(adapter, sds_ring->crb_intr_mask, 0x1);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700162
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700163 if (!NETXEN_IS_MSI_FAMILY(adapter))
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000164 NXWRIO(adapter, adapter->tgt_mask_reg, 0xfbff);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700165}
166
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000167static int
168netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count)
169{
170 int size = sizeof(struct nx_host_sds_ring) * count;
171
172 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
173
Eric Dumazet807540b2010-09-23 05:40:09 +0000174 return recv_ctx->sds_rings == NULL;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000175}
176
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000177static void
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000178netxen_free_sds_rings(struct netxen_recv_context *recv_ctx)
179{
180 if (recv_ctx->sds_rings != NULL)
181 kfree(recv_ctx->sds_rings);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000182
183 recv_ctx->sds_rings = NULL;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000184}
185
186static int
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000187netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
188{
189 int ring;
190 struct nx_host_sds_ring *sds_ring;
191 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
192
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000193 if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
Dhananjay Phadkef17443f2009-07-26 20:07:43 +0000194 return -ENOMEM;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000195
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000196 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
197 sds_ring = &recv_ctx->sds_rings[ring];
198 netif_napi_add(netdev, &sds_ring->napi,
199 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
200 }
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000201
202 return 0;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000203}
204
205static void
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000206netxen_napi_del(struct netxen_adapter *adapter)
207{
208 int ring;
209 struct nx_host_sds_ring *sds_ring;
210 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
211
212 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
213 sds_ring = &recv_ctx->sds_rings[ring];
214 netif_napi_del(&sds_ring->napi);
215 }
216
217 netxen_free_sds_rings(&adapter->recv_ctx);
218}
219
220static void
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000221netxen_napi_enable(struct netxen_adapter *adapter)
222{
223 int ring;
224 struct nx_host_sds_ring *sds_ring;
225 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
226
227 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
228 sds_ring = &recv_ctx->sds_rings[ring];
229 napi_enable(&sds_ring->napi);
230 netxen_nic_enable_int(sds_ring);
231 }
232}
233
234static void
235netxen_napi_disable(struct netxen_adapter *adapter)
236{
237 int ring;
238 struct nx_host_sds_ring *sds_ring;
239 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
240
241 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
242 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000243 netxen_nic_disable_int(sds_ring);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000244 napi_synchronize(&sds_ring->napi);
245 napi_disable(&sds_ring->napi);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000246 }
247}
248
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000249static int nx_set_dma_mask(struct netxen_adapter *adapter)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700250{
251 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000252 uint64_t mask, cmask;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700253
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000254 adapter->pci_using_dac = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700255
Yang Hongyang6afd1422009-04-06 19:01:15 -0700256 mask = DMA_BIT_MASK(32);
Yang Hongyang6afd1422009-04-06 19:01:15 -0700257 cmask = DMA_BIT_MASK(32);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000258
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000259 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000260#ifndef CONFIG_IA64
Yang Hongyang6afd1422009-04-06 19:01:15 -0700261 mask = DMA_BIT_MASK(35);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000262#endif
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000263 } else {
264 mask = DMA_BIT_MASK(39);
265 cmask = mask;
266 }
267
Dhananjay Phadke29566402008-07-21 19:44:04 -0700268 if (pci_set_dma_mask(pdev, mask) == 0 &&
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000269 pci_set_consistent_dma_mask(pdev, cmask) == 0) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700270 adapter->pci_using_dac = 1;
271 return 0;
272 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700273
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000274 return -EIO;
275}
276
277/* Update addressable range if firmware supports it */
278static int
279nx_update_dma_mask(struct netxen_adapter *adapter)
280{
281 int change, shift, err;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000282 uint64_t mask, old_mask, old_cmask;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000283 struct pci_dev *pdev = adapter->pdev;
284
285 change = 0;
286
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000287 shift = NXRD32(adapter, CRB_DMA_SHIFT);
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000288 if (shift > 32)
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000289 return 0;
290
291 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9))
292 change = 1;
293 else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4))
294 change = 1;
295
296 if (change) {
297 old_mask = pdev->dma_mask;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000298 old_cmask = pdev->dev.coherent_dma_mask;
299
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000300 mask = DMA_BIT_MASK(32+shift);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000301
302 err = pci_set_dma_mask(pdev, mask);
303 if (err)
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000304 goto err_out;
305
306 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
307
308 err = pci_set_consistent_dma_mask(pdev, mask);
309 if (err)
310 goto err_out;
311 }
312 dev_info(&pdev->dev, "using %d-bit dma mask\n", 32+shift);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700313 }
314
Dhananjay Phadke29566402008-07-21 19:44:04 -0700315 return 0;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000316
317err_out:
318 pci_set_dma_mask(pdev, old_mask);
319 pci_set_consistent_dma_mask(pdev, old_cmask);
320 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700321}
322
Dhananjay Phadke29566402008-07-21 19:44:04 -0700323static int
324netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
325{
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800326 u32 val, timeout;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700327
328 if (first_boot == 0x55555555) {
329 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000330 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800331
332 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
333 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700334
335 /* PCI bus master workaround */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000336 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700337 if (!(first_boot & 0x4)) {
338 first_boot |= 0x4;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000339 NXWR32(adapter, NETXEN_PCIE_REG(0x4), first_boot);
Amit Kumar Salecha581e8ae2010-01-07 22:10:15 +0000340 NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700341 }
342
343 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000344 first_boot = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700345 if (first_boot != 0x80000f) {
346 /* clear the register for future unloads/loads */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000347 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), 0);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800348 return -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700349 }
350
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800351 /* Start P2 boot loader */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000352 val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
353 NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800354 timeout = 0;
355 do {
356 msleep(1);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000357 val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800358
359 if (++timeout > 5000)
360 return -EIO;
361
362 } while (val == NETXEN_BDINFO_MAGIC);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700363 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800364 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700365}
366
367static void netxen_set_port_mode(struct netxen_adapter *adapter)
368{
369 u32 val, data;
370
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000371 val = adapter->ahw.board_type;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700372 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
373 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
374 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
375 data = NETXEN_PORT_MODE_802_3_AP;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000376 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700377 } else if (port_mode == NETXEN_PORT_MODE_XG) {
378 data = NETXEN_PORT_MODE_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000379 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700380 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
381 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000382 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700383 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
384 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000385 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700386 } else {
387 data = NETXEN_PORT_MODE_AUTO_NEG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000388 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700389 }
390
391 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
392 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
393 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
394 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
395 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
396 }
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000397 NXWR32(adapter, NETXEN_WOL_PORT_MODE, wol_port_mode);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700398 }
399}
400
Dhananjay Phadke29566402008-07-21 19:44:04 -0700401static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
402{
403 u32 control;
404 int pos;
405
406 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
407 if (pos) {
408 pci_read_config_dword(pdev, pos, &control);
409 if (enable)
410 control |= PCI_MSIX_FLAGS_ENABLE;
411 else
412 control = 0;
413 pci_write_config_dword(pdev, pos, control);
414 }
415}
416
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000417static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700418{
419 int i;
420
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000421 for (i = 0; i < count; i++)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700422 adapter->msix_entries[i].entry = i;
423}
424
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700425static int
426netxen_read_mac_addr(struct netxen_adapter *adapter)
427{
428 int i;
429 unsigned char *p;
Amit Kumar Salechaa03d2452010-01-14 01:53:21 +0000430 u64 mac_addr;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700431 struct net_device *netdev = adapter->netdev;
432 struct pci_dev *pdev = adapter->pdev;
433
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700434 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
435 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
436 return -EIO;
437 } else {
438 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
439 return -EIO;
440 }
441
442 p = (unsigned char *)&mac_addr;
443 for (i = 0; i < 6; i++)
444 netdev->dev_addr[i] = *(p + 5 - i);
445
446 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
Narender Kumar5d09e532009-11-20 22:08:57 +0000447 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700448
449 /* set station address */
450
Johannes Berge1749612008-10-27 15:59:26 -0700451 if (!is_valid_ether_addr(netdev->perm_addr))
452 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700453
454 return 0;
455}
456
stephen hemminger7e12bb0a2010-10-18 17:40:10 +0000457static int netxen_nic_set_mac(struct net_device *netdev, void *p)
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000458{
459 struct netxen_adapter *adapter = netdev_priv(netdev);
460 struct sockaddr *addr = p;
461
462 if (!is_valid_ether_addr(addr->sa_data))
463 return -EINVAL;
464
465 if (netif_running(netdev)) {
466 netif_device_detach(netdev);
467 netxen_napi_disable(adapter);
468 }
469
Narender Kumar5d09e532009-11-20 22:08:57 +0000470 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000471 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
472 adapter->macaddr_set(adapter, addr->sa_data);
473
474 if (netif_running(netdev)) {
475 netif_device_attach(netdev);
476 netxen_napi_enable(adapter);
477 }
478 return 0;
479}
480
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800481static void netxen_set_multicast_list(struct net_device *dev)
482{
483 struct netxen_adapter *adapter = netdev_priv(dev);
484
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000485 adapter->set_multi(dev);
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800486}
487
488static const struct net_device_ops netxen_netdev_ops = {
489 .ndo_open = netxen_nic_open,
490 .ndo_stop = netxen_nic_close,
491 .ndo_start_xmit = netxen_nic_xmit_frame,
492 .ndo_get_stats = netxen_nic_get_stats,
493 .ndo_validate_addr = eth_validate_addr,
494 .ndo_set_multicast_list = netxen_set_multicast_list,
495 .ndo_set_mac_address = netxen_nic_set_mac,
496 .ndo_change_mtu = netxen_nic_change_mtu,
497 .ndo_tx_timeout = netxen_tx_timeout,
498#ifdef CONFIG_NET_POLL_CONTROLLER
499 .ndo_poll_controller = netxen_nic_poll_controller,
500#endif
501};
502
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800503static void
504netxen_setup_intr(struct netxen_adapter *adapter)
505{
506 struct netxen_legacy_intr_set *legacy_intrp;
507 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000508 int err, num_msix;
509
510 if (adapter->rss_supported) {
511 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
512 MSIX_ENTRIES_PER_ADAPTER : 2;
513 } else
514 num_msix = 1;
515
516 adapter->max_sds_rings = 1;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800517
518 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800519
520 if (adapter->ahw.revision_id >= NX_P3_B0)
521 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
522 else
523 legacy_intrp = &legacy_intr[0];
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000524
525 adapter->int_vec_bit = legacy_intrp->int_vec_bit;
526 adapter->tgt_status_reg = netxen_get_ioaddr(adapter,
527 legacy_intrp->tgt_status_reg);
528 adapter->tgt_mask_reg = netxen_get_ioaddr(adapter,
529 legacy_intrp->tgt_mask_reg);
530 adapter->pci_int_reg = netxen_get_ioaddr(adapter,
531 legacy_intrp->pci_int_reg);
532 adapter->isr_int_vec = netxen_get_ioaddr(adapter, ISR_INT_VECTOR);
533
534 if (adapter->ahw.revision_id >= NX_P3_B1)
535 adapter->crb_int_state_reg = netxen_get_ioaddr(adapter,
536 ISR_INT_STATE_REG);
537 else
538 adapter->crb_int_state_reg = netxen_get_ioaddr(adapter,
539 CRB_INT_VECTOR);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800540
541 netxen_set_msix_bit(pdev, 0);
542
543 if (adapter->msix_supported) {
544
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000545 netxen_init_msix_entries(adapter, num_msix);
546 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
547 if (err == 0) {
548 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
549 netxen_set_msix_bit(pdev, 1);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800550
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000551 if (adapter->rss_supported)
552 adapter->max_sds_rings = num_msix;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800553
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000554 dev_info(&pdev->dev, "using msi-x interrupts\n");
555 return;
556 }
557
558 if (err > 0)
559 pci_disable_msix(pdev);
560
561 /* fall through for msi */
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800562 }
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000563
564 if (use_msi && !pci_enable_msi(pdev)) {
565 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000566 adapter->tgt_status_reg = netxen_get_ioaddr(adapter,
567 msi_tgt_status[adapter->ahw.pci_func]);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000568 dev_info(&pdev->dev, "using msi interrupts\n");
Dhananjay Phadkef67f3402009-05-18 21:46:40 -0700569 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000570 return;
571 }
572
573 dev_info(&pdev->dev, "using legacy interrupts\n");
574 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800575}
576
577static void
578netxen_teardown_intr(struct netxen_adapter *adapter)
579{
580 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
581 pci_disable_msix(adapter->pdev);
582 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
583 pci_disable_msi(adapter->pdev);
584}
585
586static void
587netxen_cleanup_pci_map(struct netxen_adapter *adapter)
588{
589 if (adapter->ahw.db_base != NULL)
590 iounmap(adapter->ahw.db_base);
591 if (adapter->ahw.pci_base0 != NULL)
592 iounmap(adapter->ahw.pci_base0);
593 if (adapter->ahw.pci_base1 != NULL)
594 iounmap(adapter->ahw.pci_base1);
595 if (adapter->ahw.pci_base2 != NULL)
596 iounmap(adapter->ahw.pci_base2);
597}
598
599static int
600netxen_setup_pci_map(struct netxen_adapter *adapter)
601{
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800602 void __iomem *db_ptr = NULL;
603
Dhananjay Phadke71fb62f2009-10-13 00:26:04 -0700604 resource_size_t mem_base, db_base;
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000605 unsigned long mem_len, db_len = 0;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800606
607 struct pci_dev *pdev = adapter->pdev;
608 int pci_func = adapter->ahw.pci_func;
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000609 struct netxen_hardware_context *ahw = &adapter->ahw;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800610
611 int err = 0;
612
613 /*
614 * Set the CRB window to invalid. If any register in window 0 is
615 * accessed it should set the window to 0 and then reset it to 1.
616 */
Dhananjay Phadke907fa122009-10-13 05:31:43 +0000617 adapter->ahw.crb_win = -1;
Dhananjay Phadke47abe352009-10-13 05:31:42 +0000618 adapter->ahw.ocm_win = -1;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800619
620 /* remap phys address */
621 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
622 mem_len = pci_resource_len(pdev, 0);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800623
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800624 /* 128 Meg of memory */
625 if (mem_len == NETXEN_PCI_128MB_SIZE) {
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000626
627 ahw->pci_base0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
628 ahw->pci_base1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800629 SECOND_PAGE_GROUP_SIZE);
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000630 ahw->pci_base2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800631 THIRD_PAGE_GROUP_SIZE);
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000632 if (ahw->pci_base0 == NULL || ahw->pci_base1 == NULL ||
633 ahw->pci_base2 == NULL) {
634 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
635 err = -EIO;
636 goto err_out;
637 }
638
639 ahw->pci_len0 = FIRST_PAGE_GROUP_SIZE;
640
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800641 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000642
643 ahw->pci_base1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
644 ahw->pci_base2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800645 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000646 if (ahw->pci_base1 == NULL || ahw->pci_base2 == NULL) {
647 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
648 err = -EIO;
649 goto err_out;
650 }
651
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800652 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800653
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000654 ahw->pci_base0 = pci_ioremap_bar(pdev, 0);
655 if (ahw->pci_base0 == NULL) {
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800656 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
657 return -EIO;
658 }
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000659 ahw->pci_len0 = mem_len;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800660 } else {
661 return -EIO;
662 }
663
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000664 netxen_setup_hwops(adapter);
665
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800666 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
667
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +0000668 if (NX_IS_REVISION_P3P(adapter->ahw.revision_id)) {
669 adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter,
670 NETXEN_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(pci_func)));
671
672 } else if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadke47abe352009-10-13 05:31:42 +0000673 adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter,
674 NETXEN_PCIX_PS_REG(PCIE_MN_WINDOW_REG(pci_func)));
675 }
676
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800677 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
678 goto skip_doorbell;
679
680 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
681 db_len = pci_resource_len(pdev, 4);
682
683 if (db_len == 0) {
684 printk(KERN_ERR "%s: doorbell is disabled\n",
685 netxen_nic_driver_name);
686 err = -EIO;
687 goto err_out;
688 }
689
690 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
691 if (!db_ptr) {
692 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
693 netxen_nic_driver_name);
694 err = -EIO;
695 goto err_out;
696 }
697
698skip_doorbell:
699 adapter->ahw.db_base = db_ptr;
700 adapter->ahw.db_len = db_len;
701 return 0;
702
703err_out:
704 netxen_cleanup_pci_map(adapter);
705 return err;
706}
707
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000708static void
709netxen_check_options(struct netxen_adapter *adapter)
710{
711 u32 fw_major, fw_minor, fw_build;
712 char brd_name[NETXEN_MAX_SHORT_NAME];
713 char serial_num[32];
714 int i, offset, val;
715 int *ptr32;
716 struct pci_dev *pdev = adapter->pdev;
717
718 adapter->driver_mismatch = 0;
719
720 ptr32 = (int *)&serial_num;
721 offset = NX_FW_SERIAL_NUM_OFFSET;
722 for (i = 0; i < 8; i++) {
723 if (netxen_rom_fast_read(adapter, offset, &val) == -1) {
724 dev_err(&pdev->dev, "error reading board info\n");
725 adapter->driver_mismatch = 1;
726 return;
727 }
728 ptr32[i] = cpu_to_le32(val);
729 offset += sizeof(u32);
730 }
731
732 fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
733 fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
734 fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
735
736 adapter->fw_version = NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build);
737
738 if (adapter->portnum == 0) {
739 get_brd_name_by_type(adapter->ahw.board_type, brd_name);
740
Dhananjay Phadkec25c0b92009-10-28 04:11:04 -0700741 pr_info("%s: %s Board S/N %s Chip rev 0x%x\n",
742 module_name(THIS_MODULE),
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000743 brd_name, serial_num, adapter->ahw.revision_id);
744 }
745
746 if (adapter->fw_version < NETXEN_VERSION_CODE(3, 4, 216)) {
747 adapter->driver_mismatch = 1;
748 dev_warn(&pdev->dev, "firmware version %d.%d.%d unsupported\n",
749 fw_major, fw_minor, fw_build);
750 return;
751 }
752
753 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
754 i = NXRD32(adapter, NETXEN_SRE_MISC);
755 adapter->ahw.cut_through = (i & 0x8000) ? 1 : 0;
756 }
757
758 dev_info(&pdev->dev, "firmware v%d.%d.%d [%s]\n",
759 fw_major, fw_minor, fw_build,
760 adapter->ahw.cut_through ? "cut-through" : "legacy");
761
762 if (adapter->fw_version >= NETXEN_VERSION_CODE(4, 0, 222))
763 adapter->capabilities = NXRD32(adapter, CRB_FW_CAPABILITIES_1);
764
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000765 if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
766 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
767 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
768 } else if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
769 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
770 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
771 }
772
773 adapter->msix_supported = 0;
774 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
775 adapter->msix_supported = !!use_msi_x;
776 adapter->rss_supported = !!use_msi_x;
Amit Kumar Salecha083ba272010-03-29 02:43:45 +0000777 } else {
778 u32 flashed_ver = 0;
779 netxen_rom_fast_read(adapter,
780 NX_FW_VERSION_OFFSET, (int *)&flashed_ver);
781 flashed_ver = NETXEN_DECODE_VERSION(flashed_ver);
782
783 if (flashed_ver >= NETXEN_VERSION_CODE(3, 4, 336)) {
784 switch (adapter->ahw.board_type) {
785 case NETXEN_BRDTYPE_P2_SB31_10G:
786 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
787 adapter->msix_supported = !!use_msi_x;
788 adapter->rss_supported = !!use_msi_x;
789 break;
790 default:
791 break;
792 }
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000793 }
794 }
795
796 adapter->num_txd = MAX_CMD_DESCRIPTORS;
797
798 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
799 adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS;
800 adapter->max_rds_rings = 3;
801 } else {
802 adapter->num_lro_rxd = 0;
803 adapter->max_rds_rings = 2;
804 }
805}
806
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800807static int
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000808netxen_start_firmware(struct netxen_adapter *adapter)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800809{
810 int val, err, first_boot;
811 struct pci_dev *pdev = adapter->pdev;
812
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000813 /* required for NX2031 dummy dma */
814 err = nx_set_dma_mask(adapter);
815 if (err)
816 return err;
817
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000818 if (!netxen_can_start_firmware(adapter))
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000819 goto wait_init;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000820
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000821 first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800822
823 err = netxen_check_hw_init(adapter, first_boot);
824 if (err) {
825 dev_err(&pdev->dev, "error in init HW init sequence\n");
826 return err;
827 }
828
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000829 netxen_request_firmware(adapter);
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000830
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000831 err = netxen_need_fw_reset(adapter);
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000832 if (err < 0)
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000833 goto err_out;
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000834 if (err == 0)
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +0000835 goto wait_init;
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000836
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800837 if (first_boot != 0x55555555) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000838 NXWR32(adapter, CRB_CMDPEG_STATE, 0);
Amit Kumar Salecha0be367b2009-10-16 15:50:08 +0000839 netxen_pinit_from_rom(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800840 msleep(1);
841 }
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000842
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000843 NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000844 NXWR32(adapter, NETXEN_PEG_HALT_STATUS1, 0);
845 NXWR32(adapter, NETXEN_PEG_HALT_STATUS2, 0);
846
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000847 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
848 netxen_set_port_mode(adapter);
849
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000850 err = netxen_load_firmware(adapter);
851 if (err)
852 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800853
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000854 netxen_release_firmware(adapter);
855
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800856 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
857
858 /* Initialize multicast addr pool owners */
859 val = 0x7654;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000860 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800861 val |= 0x0f000000;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000862 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800863
864 }
865
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000866 err = netxen_init_dummy_dma(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800867 if (err)
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000868 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800869
870 /*
871 * Tell the hardware our version number.
872 */
873 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
874 | ((_NETXEN_NIC_LINUX_MINOR << 8))
875 | (_NETXEN_NIC_LINUX_SUBVERSION);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000876 NXWR32(adapter, CRB_DRIVER_VERSION, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800877
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000878wait_init:
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800879 /* Handshake with the card before we register the devices. */
880 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
881 if (err) {
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000882 netxen_free_dummy_dma(adapter);
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000883 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800884 }
885
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +0000886 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_READY);
887
Dhananjay Phadke68b3cae2009-07-26 20:07:36 +0000888 nx_update_dma_mask(adapter);
889
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000890 netxen_check_options(adapter);
Dhananjay Phadke68b3cae2009-07-26 20:07:36 +0000891
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +0000892 adapter->need_fw_reset = 0;
893
Dhananjay Phadkeec5c50c2009-09-11 11:28:13 +0000894 /* fall through and release firmware */
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000895
896err_out:
897 netxen_release_firmware(adapter);
898 return err;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800899}
900
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000901static int
902netxen_nic_request_irq(struct netxen_adapter *adapter)
903{
904 irq_handler_t handler;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000905 struct nx_host_sds_ring *sds_ring;
906 int err, ring;
907
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000908 unsigned long flags = IRQF_SAMPLE_RANDOM;
909 struct net_device *netdev = adapter->netdev;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000910 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000911
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000912 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
913 handler = netxen_msix_intr;
914 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
915 handler = netxen_msi_intr;
916 else {
917 flags |= IRQF_SHARED;
918 handler = netxen_intr;
919 }
920 adapter->irq = netdev->irq;
921
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000922 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
923 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000924 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000925 err = request_irq(sds_ring->irq, handler,
926 flags, sds_ring->name, sds_ring);
927 if (err)
928 return err;
929 }
930
931 return 0;
932}
933
934static void
935netxen_nic_free_irq(struct netxen_adapter *adapter)
936{
937 int ring;
938 struct nx_host_sds_ring *sds_ring;
939
940 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
941
942 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
943 sds_ring = &recv_ctx->sds_rings[ring];
944 free_irq(sds_ring->irq, sds_ring);
945 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000946}
947
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000948static void
949netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter)
950{
951 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
952 adapter->coal.normal.data.rx_time_us =
953 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
954 adapter->coal.normal.data.rx_packets =
955 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
956 adapter->coal.normal.data.tx_time_us =
957 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US;
958 adapter->coal.normal.data.tx_packets =
959 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS;
960}
961
Amit Kumar Salecha6f771412009-12-05 12:23:54 +0000962/* with rtnl_lock */
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000963static int
Amit Kumar Salecha6f771412009-12-05 12:23:54 +0000964__netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000965{
966 int err;
967
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000968 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
969 return -EIO;
970
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000971 err = adapter->init_port(adapter, adapter->physical_port);
972 if (err) {
973 printk(KERN_ERR "%s: Failed to initialize port %d\n",
974 netxen_nic_driver_name, adapter->portnum);
975 return err;
976 }
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000977 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
Narender Kumar5d09e532009-11-20 22:08:57 +0000978 adapter->macaddr_set(adapter, adapter->mac_addr);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000979
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000980 adapter->set_multi(netdev);
981 adapter->set_mtu(adapter, netdev->mtu);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000982
983 adapter->ahw.linkup = 0;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000984
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000985 if (adapter->max_sds_rings > 1)
986 netxen_config_rss(adapter, 1);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000987
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000988 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
989 netxen_config_intr_coalesce(adapter);
990
Sucheta Chakrabortye4baaf72011-01-02 21:58:44 +0000991 if (netdev->features & NETIF_F_LRO)
Narender Kumar1bb482f2009-08-23 08:35:09 +0000992 netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED);
993
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000994 netxen_napi_enable(adapter);
995
Dhananjay Phadke5103c9f2009-04-28 15:29:09 +0000996 if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000997 netxen_linkevent_request(adapter, 1);
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000998 else
999 netxen_nic_set_link_parameters(adapter);
1000
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001001 set_bit(__NX_DEV_UP, &adapter->state);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001002 return 0;
1003}
1004
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001005/* Usage: During resume and firmware recovery module.*/
1006
1007static inline int
1008netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
1009{
1010 int err = 0;
1011
1012 rtnl_lock();
1013 if (netif_running(netdev))
1014 err = __netxen_nic_up(adapter, netdev);
1015 rtnl_unlock();
1016
1017 return err;
1018}
1019
1020/* with rtnl_lock */
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001021static void
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001022__netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001023{
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +00001024 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1025 return;
1026
Amit Kumar Salechaf2251f62009-12-05 12:23:55 +00001027 if (!test_and_clear_bit(__NX_DEV_UP, &adapter->state))
1028 return;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001029
Amit Kumar Salechaf2251f62009-12-05 12:23:55 +00001030 smp_mb();
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001031 spin_lock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001032 netif_carrier_off(netdev);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001033 netif_tx_disable(netdev);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001034
Sony Chackod478af02011-03-10 23:50:02 +00001035 if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)
1036 netxen_linkevent_request(adapter, 0);
1037
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001038 if (adapter->stop_port)
1039 adapter->stop_port(adapter);
1040
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +00001041 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1042 netxen_p3_free_mac_list(adapter);
1043
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001044 adapter->set_promisc(adapter, NETXEN_NIU_NON_PROMISC_MODE);
1045
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +00001046 netxen_napi_disable(adapter);
1047
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001048 netxen_release_tx_buffers(adapter);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001049 spin_unlock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001050}
1051
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001052/* Usage: During suspend and firmware recovery module */
1053
1054static inline void
1055netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
1056{
1057 rtnl_lock();
1058 if (netif_running(netdev))
1059 __netxen_nic_down(adapter, netdev);
1060 rtnl_unlock();
1061
1062}
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001063
1064static int
1065netxen_nic_attach(struct netxen_adapter *adapter)
1066{
1067 struct net_device *netdev = adapter->netdev;
1068 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +00001069 int err, ring;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001070 struct nx_host_rds_ring *rds_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001071 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001072
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001073 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
1074 return 0;
1075
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001076 err = netxen_init_firmware(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +00001077 if (err)
1078 return err;
1079
1080 err = netxen_napi_add(adapter, netdev);
1081 if (err)
1082 return err;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001083
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001084 err = netxen_alloc_sw_resources(adapter);
1085 if (err) {
1086 printk(KERN_ERR "%s: Error in setting sw resources\n",
1087 netdev->name);
1088 return err;
1089 }
1090
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001091 err = netxen_alloc_hw_resources(adapter);
1092 if (err) {
1093 printk(KERN_ERR "%s: Error in setting hw resources\n",
1094 netdev->name);
1095 goto err_out_free_sw;
1096 }
1097
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001098 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001099 tx_ring = adapter->tx_ring;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001100 tx_ring->crb_cmd_producer = netxen_get_ioaddr(adapter,
1101 crb_cmd_producer[adapter->portnum]);
1102 tx_ring->crb_cmd_consumer = netxen_get_ioaddr(adapter,
1103 crb_cmd_consumer[adapter->portnum]);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001104
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001105 tx_ring->producer = 0;
1106 tx_ring->sw_consumer = 0;
1107
1108 netxen_nic_update_cmd_producer(adapter, tx_ring);
1109 netxen_nic_update_cmd_consumer(adapter, tx_ring);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001110 }
1111
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001112 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1113 rds_ring = &adapter->recv_ctx.rds_rings[ring];
1114 netxen_post_rx_buffers(adapter, ring, rds_ring);
1115 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001116
1117 err = netxen_nic_request_irq(adapter);
1118 if (err) {
1119 dev_err(&pdev->dev, "%s: failed to setup interrupt\n",
1120 netdev->name);
1121 goto err_out_free_rxbuf;
1122 }
1123
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +00001124 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1125 netxen_nic_init_coalesce_defaults(adapter);
1126
Narender Kumarfa3ce352009-08-24 19:23:28 +00001127 netxen_create_sysfs_entries(adapter);
1128
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001129 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1130 return 0;
1131
1132err_out_free_rxbuf:
1133 netxen_release_rx_buffers(adapter);
1134 netxen_free_hw_resources(adapter);
1135err_out_free_sw:
1136 netxen_free_sw_resources(adapter);
1137 return err;
1138}
1139
1140static void
1141netxen_nic_detach(struct netxen_adapter *adapter)
1142{
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001143 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1144 return;
1145
Narender Kumarfa3ce352009-08-24 19:23:28 +00001146 netxen_remove_sysfs_entries(adapter);
1147
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001148 netxen_free_hw_resources(adapter);
Dhananjay Phadkecf981ff2009-07-17 15:27:06 +00001149 netxen_release_rx_buffers(adapter);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +00001150 netxen_nic_free_irq(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +00001151 netxen_napi_del(adapter);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001152 netxen_free_sw_resources(adapter);
1153
1154 adapter->is_up = 0;
1155}
1156
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001157int
1158netxen_nic_reset_context(struct netxen_adapter *adapter)
1159{
1160 int err = 0;
1161 struct net_device *netdev = adapter->netdev;
1162
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001163 if (test_and_set_bit(__NX_RESETTING, &adapter->state))
1164 return -EBUSY;
1165
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001166 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
1167
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001168 netif_device_detach(netdev);
1169
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001170 if (netif_running(netdev))
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001171 __netxen_nic_down(adapter, netdev);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001172
1173 netxen_nic_detach(adapter);
1174
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001175 if (netif_running(netdev)) {
1176 err = netxen_nic_attach(adapter);
1177 if (!err)
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001178 err = __netxen_nic_up(adapter, netdev);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001179
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001180 if (err)
1181 goto done;
1182 }
1183
1184 netif_device_attach(netdev);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001185 }
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001186
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001187done:
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001188 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001189 return err;
1190}
1191
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001192static int
1193netxen_setup_netdev(struct netxen_adapter *adapter,
1194 struct net_device *netdev)
1195{
1196 int err = 0;
1197 struct pci_dev *pdev = adapter->pdev;
1198
1199 adapter->rx_csum = 1;
1200 adapter->mc_enabled = 0;
1201 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1202 adapter->max_mc_count = 38;
1203 else
1204 adapter->max_mc_count = 16;
1205
1206 netdev->netdev_ops = &netxen_netdev_ops;
Rajesh Borundia7a9905e2010-10-18 02:03:41 +00001207 netdev->watchdog_timeo = 5*HZ;
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001208
1209 netxen_nic_change_mtu(netdev, netdev->mtu);
1210
1211 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
1212
1213 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1214 netdev->features |= (NETIF_F_GRO);
1215 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1216
1217 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1218 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1219 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1220 }
1221
1222 if (adapter->pci_using_dac) {
1223 netdev->features |= NETIF_F_HIGHDMA;
1224 netdev->vlan_features |= NETIF_F_HIGHDMA;
1225 }
1226
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001227 if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX)
1228 netdev->features |= (NETIF_F_HW_VLAN_TX);
1229
Narender Kumar1bb482f2009-08-23 08:35:09 +00001230 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
1231 netdev->features |= NETIF_F_LRO;
1232
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001233 netdev->irq = adapter->msix_entries[0].vector;
1234
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001235 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001236
1237 if (netxen_read_mac_addr(adapter))
1238 dev_warn(&pdev->dev, "failed to read mac addr\n");
1239
1240 netif_carrier_off(netdev);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001241
1242 err = register_netdev(netdev);
1243 if (err) {
1244 dev_err(&pdev->dev, "failed to register net device\n");
1245 return err;
1246 }
1247
1248 return 0;
1249}
1250
amit salechadce87b92010-10-18 02:03:42 +00001251#ifdef CONFIG_PCIEAER
1252static void netxen_mask_aer_correctable(struct netxen_adapter *adapter)
1253{
1254 struct pci_dev *pdev = adapter->pdev;
1255 struct pci_dev *root = pdev->bus->self;
1256 u32 aer_pos;
1257
1258 if (adapter->ahw.board_type != NETXEN_BRDTYPE_P3_4_GB_MM &&
1259 adapter->ahw.board_type != NETXEN_BRDTYPE_P3_10G_TP)
1260 return;
1261
1262 if (root->pcie_type != PCI_EXP_TYPE_ROOT_PORT)
1263 return;
1264
1265 aer_pos = pci_find_ext_capability(root, PCI_EXT_CAP_ID_ERR);
1266 if (!aer_pos)
1267 return;
1268
1269 pci_write_config_dword(root, aer_pos + PCI_ERR_COR_MASK, 0xffff);
1270}
1271#endif
1272
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001273static int __devinit
1274netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1275{
1276 struct net_device *netdev = NULL;
1277 struct netxen_adapter *adapter = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001278 int i = 0, err;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001279 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001280 uint8_t revision_id;
Rajesh Borundia5a6f95e2010-11-23 03:08:27 +00001281 u32 val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001282
Eric W. Biederman688328c2010-03-17 22:24:39 +00001283 if (pdev->revision >= NX_P3_A0 && pdev->revision <= NX_P3_B1) {
1284 pr_warning("%s: chip revisions between 0x%x-0x%x "
Dhananjay Phadke11d89d62008-08-08 00:08:45 -07001285 "will not be enabled.\n",
Dhananjay Phadkec25c0b92009-10-28 04:11:04 -07001286 module_name(THIS_MODULE), NX_P3_A0, NX_P3_B1);
Dhananjay Phadke11d89d62008-08-08 00:08:45 -07001287 return -ENODEV;
1288 }
1289
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001290 if ((err = pci_enable_device(pdev)))
1291 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001292
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001293 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1294 err = -ENODEV;
1295 goto err_out_disable_pdev;
1296 }
1297
1298 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
1299 goto err_out_disable_pdev;
1300
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00001301 if (NX_IS_REVISION_P3(pdev->revision))
1302 pci_enable_pcie_error_reporting(pdev);
1303
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001304 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001305
1306 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
1307 if(!netdev) {
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001308 dev_err(&pdev->dev, "failed to allocate net_device\n");
1309 err = -ENOMEM;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001310 goto err_out_free_res;
1311 }
1312
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001313 SET_NETDEV_DEV(netdev, &pdev->dev);
1314
Wang Chen4cf16532008-11-12 23:38:14 -08001315 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001316 adapter->netdev = netdev;
1317 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001318 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001319
1320 revision_id = pdev->revision;
1321 adapter->ahw.revision_id = revision_id;
1322
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001323 rwlock_init(&adapter->ahw.crb_lock);
1324 spin_lock_init(&adapter->ahw.mem_lock);
1325
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001326 spin_lock_init(&adapter->tx_clean_lock);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +00001327 INIT_LIST_HEAD(&adapter->mac_list);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001328
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001329 err = netxen_setup_pci_map(adapter);
1330 if (err)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001331 goto err_out_free_netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001332
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +05301333 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001334 adapter->portnum = pci_func_id;
1335
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001336 err = netxen_nic_get_board_info(adapter);
1337 if (err) {
1338 dev_err(&pdev->dev, "Error getting board config info.\n");
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001339 goto err_out_iounmap;
1340 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001341
amit salechadce87b92010-10-18 02:03:42 +00001342#ifdef CONFIG_PCIEAER
1343 netxen_mask_aer_correctable(adapter);
1344#endif
1345
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001346 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001347 switch (adapter->ahw.board_type) {
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001348 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1349 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1350 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001351 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001352 break;
1353 default:
1354 break;
1355 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001356
Rajesh Borundia5a6f95e2010-11-23 03:08:27 +00001357 if (adapter->portnum == 0) {
1358 val = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
1359 if (val != 0xffffffff && val != 0) {
Rajesh Borundia683b65f2010-10-26 22:51:50 +00001360 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, 0);
1361 adapter->need_fw_reset = 1;
1362 }
1363 }
1364
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001365 err = netxen_start_firmware(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001366 if (err)
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00001367 goto err_out_decr_ref;
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001368
Dhananjay Phadke29566402008-07-21 19:44:04 -07001369 /*
1370 * See if the firmware gave us a virtual-physical port mapping.
1371 */
1372 adapter->physical_port = adapter->portnum;
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001373 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001374 i = NXRD32(adapter, CRB_V2P(adapter->portnum));
Dhananjay Phadke044fad02009-02-24 03:42:59 -08001375 if (i != 0x55555555)
1376 adapter->physical_port = i;
1377 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001378
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001379 netxen_nic_clear_stats(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001380
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001381 netxen_setup_intr(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001382
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001383 err = netxen_setup_netdev(adapter, netdev);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001384 if (err)
Dhananjay Phadke29566402008-07-21 19:44:04 -07001385 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001386
1387 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001388
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001389 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
1390
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001391 switch (adapter->ahw.port_type) {
Dhananjay Phadke29566402008-07-21 19:44:04 -07001392 case NETXEN_NIC_GBE:
1393 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1394 adapter->netdev->name);
1395 break;
1396 case NETXEN_NIC_XGBE:
1397 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1398 adapter->netdev->name);
1399 break;
1400 }
1401
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00001402 netxen_create_diag_entries(adapter);
1403
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001404 return 0;
1405
Dhananjay Phadke29566402008-07-21 19:44:04 -07001406err_out_disable_msi:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001407 netxen_teardown_intr(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001408
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001409 netxen_free_dummy_dma(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001410
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00001411err_out_decr_ref:
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001412 nx_decr_dev_ref_cnt(adapter);
1413
Dhananjay Phadke29566402008-07-21 19:44:04 -07001414err_out_iounmap:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001415 netxen_cleanup_pci_map(adapter);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001416
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001417err_out_free_netdev:
1418 free_netdev(netdev);
1419
1420err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001421 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001422
1423err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001424 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001425 pci_disable_device(pdev);
1426 return err;
1427}
1428
1429static void __devexit netxen_nic_remove(struct pci_dev *pdev)
1430{
1431 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001432 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001433
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001434 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001435 if (adapter == NULL)
1436 return;
1437
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001438 netdev = adapter->netdev;
1439
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001440 netxen_cancel_fw_work(adapter);
1441
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301442 unregister_netdev(netdev);
1443
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001444 cancel_work_sync(&adapter->tx_timeout_task);
1445
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001446 netxen_nic_detach(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001447
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001448 nx_decr_dev_ref_cnt(adapter);
1449
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001450 if (adapter->portnum == 0)
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001451 netxen_free_dummy_dma(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301452
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001453 clear_bit(__NX_RESETTING, &adapter->state);
1454
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001455 netxen_teardown_intr(adapter);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301456
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00001457 netxen_remove_diag_entries(adapter);
1458
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001459 netxen_cleanup_pci_map(adapter);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001460
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001461 netxen_release_firmware(adapter);
1462
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00001463 if (NX_IS_REVISION_P3(pdev->revision))
1464 pci_disable_pcie_error_reporting(pdev);
1465
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001466 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301467 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001468 pci_set_drvdata(pdev, NULL);
1469
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001470 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001471}
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00001472
1473static void netxen_nic_detach_func(struct netxen_adapter *adapter)
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001474{
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001475 struct net_device *netdev = adapter->netdev;
1476
1477 netif_device_detach(netdev);
1478
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001479 netxen_cancel_fw_work(adapter);
1480
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001481 if (netif_running(netdev))
1482 netxen_nic_down(adapter, netdev);
1483
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001484 cancel_work_sync(&adapter->tx_timeout_task);
1485
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001486 netxen_nic_detach(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001487
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001488 if (adapter->portnum == 0)
1489 netxen_free_dummy_dma(adapter);
1490
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001491 nx_decr_dev_ref_cnt(adapter);
1492
1493 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001494}
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001495
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00001496static int netxen_nic_attach_func(struct pci_dev *pdev)
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001497{
1498 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1499 struct net_device *netdev = adapter->netdev;
1500 int err;
1501
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001502 err = pci_enable_device(pdev);
1503 if (err)
1504 return err;
1505
Amit Kumar Salechabc86fcb2009-12-08 20:40:54 +00001506 pci_set_power_state(pdev, PCI_D0);
1507 pci_set_master(pdev);
1508 pci_restore_state(pdev);
1509
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001510 adapter->ahw.crb_win = -1;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001511 adapter->ahw.ocm_win = -1;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001512
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001513 err = netxen_start_firmware(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001514 if (err) {
1515 dev_err(&pdev->dev, "failed to start firmware\n");
1516 return err;
1517 }
1518
1519 if (netif_running(netdev)) {
1520 err = netxen_nic_attach(adapter);
1521 if (err)
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001522 goto err_out;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001523
1524 err = netxen_nic_up(adapter, netdev);
1525 if (err)
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001526 goto err_out_detach;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001527
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00001528 netxen_config_indev_addr(netdev, NETDEV_UP);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001529 }
1530
Amit Kumar Salechabc86fcb2009-12-08 20:40:54 +00001531 netif_device_attach(netdev);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001532 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
Dhananjay Phadke07653aa2009-09-20 19:20:39 +00001533 return 0;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001534
1535err_out_detach:
1536 netxen_nic_detach(adapter);
1537err_out:
1538 nx_decr_dev_ref_cnt(adapter);
1539 return err;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001540}
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00001541
1542static pci_ers_result_t netxen_io_error_detected(struct pci_dev *pdev,
1543 pci_channel_state_t state)
1544{
1545 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1546
1547 if (state == pci_channel_io_perm_failure)
1548 return PCI_ERS_RESULT_DISCONNECT;
1549
1550 if (nx_dev_request_aer(adapter))
1551 return PCI_ERS_RESULT_RECOVERED;
1552
1553 netxen_nic_detach_func(adapter);
1554
1555 pci_disable_device(pdev);
1556
1557 return PCI_ERS_RESULT_NEED_RESET;
1558}
1559
1560static pci_ers_result_t netxen_io_slot_reset(struct pci_dev *pdev)
1561{
1562 int err = 0;
1563
1564 err = netxen_nic_attach_func(pdev);
1565
1566 return err ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED;
1567}
1568
1569static void netxen_io_resume(struct pci_dev *pdev)
1570{
1571 pci_cleanup_aer_uncorrect_error_status(pdev);
1572}
1573
1574static void netxen_nic_shutdown(struct pci_dev *pdev)
1575{
1576 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1577
1578 netxen_nic_detach_func(adapter);
1579
1580 if (pci_save_state(pdev))
1581 return;
1582
1583 if (netxen_nic_wol_supported(adapter)) {
1584 pci_enable_wake(pdev, PCI_D3cold, 1);
1585 pci_enable_wake(pdev, PCI_D3hot, 1);
1586 }
1587
1588 pci_disable_device(pdev);
1589}
1590
1591#ifdef CONFIG_PM
1592static int
1593netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
1594{
1595 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1596 int retval;
1597
1598 netxen_nic_detach_func(adapter);
1599
1600 retval = pci_save_state(pdev);
1601 if (retval)
1602 return retval;
1603
1604 if (netxen_nic_wol_supported(adapter)) {
1605 pci_enable_wake(pdev, PCI_D3cold, 1);
1606 pci_enable_wake(pdev, PCI_D3hot, 1);
1607 }
1608
1609 pci_disable_device(pdev);
1610 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1611
1612 return 0;
1613}
1614
1615static int
1616netxen_nic_resume(struct pci_dev *pdev)
1617{
1618 return netxen_nic_attach_func(pdev);
1619}
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00001620#endif
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001621
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001622static int netxen_nic_open(struct net_device *netdev)
1623{
Wang Chen4cf16532008-11-12 23:38:14 -08001624 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001625 int err = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001626
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001627 if (adapter->driver_mismatch)
1628 return -EIO;
1629
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001630 err = netxen_nic_attach(adapter);
1631 if (err)
1632 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001633
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001634 err = __netxen_nic_up(adapter, netdev);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001635 if (err)
1636 goto err_out;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001637
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001638 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001639
1640 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001641
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001642err_out:
1643 netxen_nic_detach(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001644 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001645}
1646
1647/*
1648 * netxen_nic_close - Disables a network interface entry point
1649 */
1650static int netxen_nic_close(struct net_device *netdev)
1651{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001652 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001653
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001654 __netxen_nic_down(adapter, netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001655 return 0;
1656}
1657
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001658static void
1659netxen_tso_check(struct net_device *netdev,
1660 struct nx_host_tx_ring *tx_ring,
1661 struct cmd_desc_type0 *first_desc,
1662 struct sk_buff *skb)
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001663{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001664 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001665 __be16 protocol = skb->protocol;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001666 u16 flags = 0, vid = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001667 u32 producer;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001668 int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001669 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001670 struct vlan_ethhdr *vh;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001671
Harvey Harrison09640e62009-02-01 00:45:17 -08001672 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001673
1674 vh = (struct vlan_ethhdr *)skb->data;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001675 protocol = vh->h_vlan_encapsulated_proto;
1676 flags = FLAGS_VLAN_TAGGED;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001677
1678 } else if (vlan_tx_tag_present(skb)) {
1679
1680 flags = FLAGS_VLAN_OOB;
1681 vid = vlan_tx_tag_get(skb);
1682 netxen_set_tx_vlan_tci(first_desc, vid);
1683 vlan_oob = 1;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001684 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001685
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001686 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1687 skb_shinfo(skb)->gso_size > 0) {
1688
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001689 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1690
1691 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1692 first_desc->total_hdr_length = hdr_len;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001693 if (vlan_oob) {
1694 first_desc->total_hdr_length += VLAN_HLEN;
1695 first_desc->tcp_hdr_offset = VLAN_HLEN;
1696 first_desc->ip_hdr_offset = VLAN_HLEN;
1697 /* Only in case of TSO on vlan device */
1698 flags |= FLAGS_VLAN_TAGGED;
1699 }
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001700
Harvey Harrison09640e62009-02-01 00:45:17 -08001701 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001702 TX_TCP_LSO6 : TX_TCP_LSO;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001703 tso = 1;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001704
1705 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001706 u8 l4proto;
1707
Harvey Harrison09640e62009-02-01 00:45:17 -08001708 if (protocol == cpu_to_be16(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001709 l4proto = ip_hdr(skb)->protocol;
1710
1711 if (l4proto == IPPROTO_TCP)
1712 opcode = TX_TCP_PKT;
1713 else if(l4proto == IPPROTO_UDP)
1714 opcode = TX_UDP_PKT;
Harvey Harrison09640e62009-02-01 00:45:17 -08001715 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001716 l4proto = ipv6_hdr(skb)->nexthdr;
1717
1718 if (l4proto == IPPROTO_TCP)
1719 opcode = TX_TCPV6_PKT;
1720 else if(l4proto == IPPROTO_UDP)
1721 opcode = TX_UDPV6_PKT;
1722 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001723 }
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001724
1725 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
1726 first_desc->ip_hdr_offset += skb_network_offset(skb);
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001727 netxen_set_tx_flags_opcode(first_desc, flags, opcode);
1728
1729 if (!tso)
1730 return;
1731
1732 /* For LSO, we need to copy the MAC/IP/TCP headers into
1733 * the descriptor ring
1734 */
1735 producer = tx_ring->producer;
1736 copied = 0;
1737 offset = 2;
1738
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001739 if (vlan_oob) {
1740 /* Create a TSO vlan header template for firmware */
1741
1742 hwdesc = &tx_ring->desc_head[producer];
1743 tx_ring->cmd_buf_arr[producer].skb = NULL;
1744
1745 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1746 hdr_len + VLAN_HLEN);
1747
1748 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2);
1749 skb_copy_from_linear_data(skb, vh, 12);
1750 vh->h_vlan_proto = htons(ETH_P_8021Q);
1751 vh->h_vlan_TCI = htons(vid);
1752 skb_copy_from_linear_data_offset(skb, 12,
1753 (char *)vh + 16, copy_len - 16);
1754
Dhananjay Phadke545eb372009-08-05 07:34:07 +00001755 copied = copy_len - VLAN_HLEN;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001756 offset = 0;
1757
1758 producer = get_next_index(producer, tx_ring->num_desc);
1759 }
1760
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001761 while (copied < hdr_len) {
1762
1763 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1764 (hdr_len - copied));
1765
1766 hwdesc = &tx_ring->desc_head[producer];
1767 tx_ring->cmd_buf_arr[producer].skb = NULL;
1768
1769 skb_copy_from_linear_data_offset(skb, copied,
1770 (char *)hwdesc + offset, copy_len);
1771
1772 copied += copy_len;
1773 offset = 0;
1774
1775 producer = get_next_index(producer, tx_ring->num_desc);
1776 }
1777
1778 tx_ring->producer = producer;
1779 barrier();
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001780}
1781
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001782static int
1783netxen_map_tx_skb(struct pci_dev *pdev,
1784 struct sk_buff *skb, struct netxen_cmd_buffer *pbuf)
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001785{
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001786 struct netxen_skb_frag *nf;
1787 struct skb_frag_struct *frag;
1788 int i, nr_frags;
1789 dma_addr_t map;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001790
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001791 nr_frags = skb_shinfo(skb)->nr_frags;
1792 nf = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001793
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001794 map = pci_map_single(pdev, skb->data,
1795 skb_headlen(skb), PCI_DMA_TODEVICE);
1796 if (pci_dma_mapping_error(pdev, map))
1797 goto out_err;
1798
1799 nf->dma = map;
1800 nf->length = skb_headlen(skb);
1801
1802 for (i = 0; i < nr_frags; i++) {
1803 frag = &skb_shinfo(skb)->frags[i];
1804 nf = &pbuf->frag_array[i+1];
1805
1806 map = pci_map_page(pdev, frag->page, frag->page_offset,
1807 frag->size, PCI_DMA_TODEVICE);
1808 if (pci_dma_mapping_error(pdev, map))
1809 goto unwind;
1810
1811 nf->dma = map;
1812 nf->length = frag->size;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001813 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001814
1815 return 0;
1816
1817unwind:
Dhananjay Phadkecf503e82009-09-03 13:10:55 +00001818 while (--i >= 0) {
1819 nf = &pbuf->frag_array[i+1];
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001820 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
1821 }
1822
1823 nf = &pbuf->frag_array[0];
1824 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
1825
1826out_err:
1827 return -ENOMEM;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001828}
1829
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001830static inline void
1831netxen_clear_cmddesc(u64 *desc)
1832{
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001833 desc[0] = 0ULL;
1834 desc[2] = 0ULL;
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001835}
1836
Stephen Hemminger613573252009-08-31 19:50:58 +00001837static netdev_tx_t
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001838netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001839{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001840 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001841 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001842 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001843 struct netxen_skb_frag *buffrag;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001844 struct cmd_desc_type0 *hwdesc, *first_desc;
1845 struct pci_dev *pdev;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001846 int i, k;
amit salechac968bdf2011-04-11 02:10:22 +00001847 int delta = 0;
1848 struct skb_frag_struct *frag;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001849
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001850 u32 producer;
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001851 int frag_count, no_of_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001852 u32 num_txd = tx_ring->num_desc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001853
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001854 frag_count = skb_shinfo(skb)->nr_frags + 1;
1855
amit salechac968bdf2011-04-11 02:10:22 +00001856 /* 14 frags supported for normal packet and
1857 * 32 frags supported for TSO packet
1858 */
1859 if (!skb_is_gso(skb) && frag_count > NETXEN_MAX_FRAGS_PER_TX) {
1860
1861 for (i = 0; i < (frag_count - NETXEN_MAX_FRAGS_PER_TX); i++) {
1862 frag = &skb_shinfo(skb)->frags[i];
1863 delta += frag->size;
1864 }
1865
1866 if (!__pskb_pull_tail(skb, delta))
1867 goto drop_packet;
1868
1869 frag_count = 1 + skb_shinfo(skb)->nr_frags;
1870 }
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001871 /* 4 fragments per cmd des */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001872 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001873
Rajesh Borundia7a9905e2010-10-18 02:03:41 +00001874 if (unlikely(netxen_tx_avail(tx_ring) <= TX_STOP_THRESH)) {
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001875 netif_stop_queue(netdev);
Rajesh Borundia7a9905e2010-10-18 02:03:41 +00001876 smp_mb();
1877 if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH)
1878 netif_start_queue(netdev);
1879 else
1880 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001881 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001882
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001883 producer = tx_ring->producer;
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001884 pbuf = &tx_ring->cmd_buf_arr[producer];
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001885
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001886 pdev = adapter->pdev;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001887
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001888 if (netxen_map_tx_skb(pdev, skb, pbuf))
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001889 goto drop_packet;
1890
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001891 pbuf->skb = skb;
1892 pbuf->frag_count = frag_count;
1893
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001894 first_desc = hwdesc = &tx_ring->desc_head[producer];
1895 netxen_clear_cmddesc((u64 *)hwdesc);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001896
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001897 netxen_set_tx_frags_len(first_desc, frag_count, skb->len);
1898 netxen_set_tx_port(first_desc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001899
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001900 for (i = 0; i < frag_count; i++) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001901
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001902 k = i % 4;
1903
1904 if ((k == 0) && (i > 0)) {
1905 /* move to next desc.*/
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001906 producer = get_next_index(producer, num_txd);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001907 hwdesc = &tx_ring->desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001908 netxen_clear_cmddesc((u64 *)hwdesc);
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001909 tx_ring->cmd_buf_arr[producer].skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001910 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001911
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001912 buffrag = &pbuf->frag_array[i];
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001913
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001914 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001915 switch (k) {
1916 case 0:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001917 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001918 break;
1919 case 1:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001920 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001921 break;
1922 case 2:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001923 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001924 break;
1925 case 3:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001926 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001927 break;
1928 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001929 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001930
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001931 tx_ring->producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001932
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001933 netxen_tso_check(netdev, tx_ring, first_desc, skb);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001934
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001935 netxen_nic_update_cmd_producer(adapter, tx_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001936
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001937 adapter->stats.txbytes += skb->len;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001938 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001939
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001940 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001941
1942drop_packet:
1943 adapter->stats.txdropped++;
1944 dev_kfree_skb_any(skb);
1945 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001946}
1947
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001948static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1949{
1950 struct net_device *netdev = adapter->netdev;
1951 uint32_t temp, temp_state, temp_val;
1952 int rv = 0;
1953
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001954 temp = NXRD32(adapter, CRB_TEMP_STATE);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001955
1956 temp_state = nx_get_temp_state(temp);
1957 temp_val = nx_get_temp_val(temp);
1958
1959 if (temp_state == NX_TEMP_PANIC) {
1960 printk(KERN_ALERT
1961 "%s: Device temperature %d degrees C exceeds"
1962 " maximum allowed. Hardware has been shut down.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001963 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001964 rv = 1;
1965 } else if (temp_state == NX_TEMP_WARN) {
1966 if (adapter->temp == NX_TEMP_NORMAL) {
1967 printk(KERN_ALERT
1968 "%s: Device temperature %d degrees C "
1969 "exceeds operating range."
1970 " Immediate action needed.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001971 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001972 }
1973 } else {
1974 if (adapter->temp == NX_TEMP_WARN) {
1975 printk(KERN_INFO
1976 "%s: Device temperature is now %d degrees C"
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001977 " in normal range.\n", netdev->name,
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001978 temp_val);
1979 }
1980 }
1981 adapter->temp = temp_state;
1982 return rv;
1983}
1984
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001985void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup)
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001986{
1987 struct net_device *netdev = adapter->netdev;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001988
1989 if (adapter->ahw.linkup && !linkup) {
1990 printk(KERN_INFO "%s: %s NIC Link is down\n",
1991 netxen_nic_driver_name, netdev->name);
1992 adapter->ahw.linkup = 0;
1993 if (netif_running(netdev)) {
1994 netif_carrier_off(netdev);
1995 netif_stop_queue(netdev);
1996 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001997 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001998 } else if (!adapter->ahw.linkup && linkup) {
1999 printk(KERN_INFO "%s: %s NIC Link is up\n",
2000 netxen_nic_driver_name, netdev->name);
2001 adapter->ahw.linkup = 1;
2002 if (netif_running(netdev)) {
2003 netif_carrier_on(netdev);
2004 netif_wake_queue(netdev);
2005 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00002006 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00002007 }
2008}
2009
2010static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
2011{
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002012 u32 val, port, linkup;
2013
2014 port = adapter->physical_port;
2015
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002016 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002017 val = NXRD32(adapter, CRB_XG_STATE_P3);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002018 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
2019 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07002020 } else {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002021 val = NXRD32(adapter, CRB_XG_STATE);
Sucheta Chakrabortya4b751d2010-01-02 03:25:19 +00002022 val = (val >> port*8) & 0xff;
2023 linkup = (val == XG_LINK_UP);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002024 }
2025
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00002026 netxen_advert_link_change(adapter, linkup);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002027}
2028
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002029static void netxen_tx_timeout(struct net_device *netdev)
2030{
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00002031 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00002032
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002033 if (test_bit(__NX_RESETTING, &adapter->state))
2034 return;
2035
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00002036 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00002037 schedule_work(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002038}
2039
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002040static void netxen_tx_timeout_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002041{
Jeff Garzik47906542007-11-23 21:23:36 -05002042 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002043 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002044
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00002045 if (!netif_running(adapter->netdev))
2046 return;
2047
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002048 if (test_and_set_bit(__NX_RESETTING, &adapter->state))
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002049 return;
2050
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002051 if (++adapter->tx_timeo_cnt >= NX_MAX_TX_TIMEOUTS)
2052 goto request_reset;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07002053
Amit Kumar Salecha16d884b2010-08-07 23:05:23 -07002054 rtnl_lock();
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002055 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
2056 /* try to scrub interrupt */
2057 netxen_napi_disable(adapter);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07002058
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002059 netxen_napi_enable(adapter);
2060
2061 netif_wake_queue(adapter->netdev);
2062
Dhananjay Phadkea598ae12009-09-20 19:20:38 +00002063 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002064 } else {
Dhananjay Phadkea598ae12009-09-20 19:20:38 +00002065 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha16d884b2010-08-07 23:05:23 -07002066 if (netxen_nic_reset_context(adapter)) {
2067 rtnl_unlock();
2068 goto request_reset;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002069 }
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002070 }
Amit Kumar Salecha16d884b2010-08-07 23:05:23 -07002071 adapter->netdev->trans_start = jiffies;
2072 rtnl_unlock();
2073 return;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002074
2075request_reset:
2076 adapter->need_fw_reset = 1;
Amit Kumar Salechaff8a3062009-10-21 19:39:02 +00002077 clear_bit(__NX_RESETTING, &adapter->state);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002078}
2079
stephen hemminger7e12bb0a2010-10-18 17:40:10 +00002080static struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002081{
2082 struct netxen_adapter *adapter = netdev_priv(netdev);
Ajit Khaparde5a4d6312009-10-07 02:45:34 +00002083 struct net_device_stats *stats = &netdev->stats;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002084
Narender Kumar1bb482f2009-08-23 08:35:09 +00002085 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00002086 stats->tx_packets = adapter->stats.xmitfinished;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002087 stats->rx_bytes = adapter->stats.rxbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002088 stats->tx_bytes = adapter->stats.txbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002089 stats->rx_dropped = adapter->stats.rxdropped;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002090 stats->tx_dropped = adapter->stats.txdropped;
2091
2092 return stats;
2093}
2094
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07002095static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002096{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002097 struct nx_host_sds_ring *sds_ring = data;
2098 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002099 u32 status = 0;
2100
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002101 status = readl(adapter->isr_int_vec);
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002102
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002103 if (!(status & adapter->int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002104 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05302105
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002106 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002107 /* check interrupt state machine, to be sure */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002108 status = readl(adapter->crb_int_state_reg);
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002109 if (!ISR_LEGACY_INT_TRIGGERED(status))
2110 return IRQ_NONE;
2111
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002112 } else {
2113 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002114
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002115 our_int = readl(adapter->crb_int_state_reg);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002116
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002117 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002118 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002119 return IRQ_NONE;
2120
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002121 /* claim interrupt */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002122 writel((our_int & 0xffffffff), adapter->crb_int_state_reg);
2123
2124 /* clear interrupt */
2125 netxen_nic_disable_int(sds_ring);
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05302126 }
2127
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002128 writel(0xffffffff, adapter->tgt_status_reg);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002129 /* read twice to ensure write is flushed */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002130 readl(adapter->isr_int_vec);
2131 readl(adapter->isr_int_vec);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002132
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002133 napi_schedule(&sds_ring->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002134
2135 return IRQ_HANDLED;
2136}
2137
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07002138static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002139{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002140 struct nx_host_sds_ring *sds_ring = data;
2141 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002142
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002143 /* clear interrupt */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002144 writel(0xffffffff, adapter->tgt_status_reg);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002145
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002146 napi_schedule(&sds_ring->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002147 return IRQ_HANDLED;
2148}
2149
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08002150static irqreturn_t netxen_msix_intr(int irq, void *data)
2151{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002152 struct nx_host_sds_ring *sds_ring = data;
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08002153
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002154 napi_schedule(&sds_ring->napi);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08002155 return IRQ_HANDLED;
2156}
2157
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002158static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002159{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002160 struct nx_host_sds_ring *sds_ring =
2161 container_of(napi, struct nx_host_sds_ring, napi);
2162
2163 struct netxen_adapter *adapter = sds_ring->adapter;
2164
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002165 int tx_complete;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002166 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002167
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002168 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002169
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002170 work_done = netxen_process_rcv_ring(sds_ring, budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002171
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002172 if ((work_done < budget) && tx_complete) {
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002173 napi_complete(&sds_ring->napi);
Amit Kumar Salechaf2251f62009-12-05 12:23:55 +00002174 if (test_bit(__NX_DEV_UP, &adapter->state))
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00002175 netxen_nic_enable_int(sds_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002176 }
2177
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002178 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002179}
2180
2181#ifdef CONFIG_NET_POLL_CONTROLLER
2182static void netxen_nic_poll_controller(struct net_device *netdev)
2183{
Yinglin Luan7b589a32010-08-22 21:56:19 +00002184 int ring;
2185 struct nx_host_sds_ring *sds_ring;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002186 struct netxen_adapter *adapter = netdev_priv(netdev);
Yinglin Luan7b589a32010-08-22 21:56:19 +00002187 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
2188
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002189 disable_irq(adapter->irq);
Yinglin Luan7b589a32010-08-22 21:56:19 +00002190 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
2191 sds_ring = &recv_ctx->sds_rings[ring];
2192 netxen_intr(adapter->irq, sds_ring);
2193 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002194 enable_irq(adapter->irq);
2195}
2196#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002197
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002198static int
2199nx_incr_dev_ref_cnt(struct netxen_adapter *adapter)
2200{
2201 int count;
2202 if (netxen_api_lock(adapter))
2203 return -EIO;
2204
2205 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2206
2207 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2208
2209 netxen_api_unlock(adapter);
2210 return count;
2211}
2212
2213static int
2214nx_decr_dev_ref_cnt(struct netxen_adapter *adapter)
2215{
2216 int count;
2217 if (netxen_api_lock(adapter))
2218 return -EIO;
2219
2220 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2221 WARN_ON(count == 0);
2222
2223 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, --count);
2224
2225 if (count == 0)
2226 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_COLD);
2227
2228 netxen_api_unlock(adapter);
2229 return count;
2230}
2231
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002232static int
2233nx_dev_request_aer(struct netxen_adapter *adapter)
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002234{
2235 u32 state;
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002236 int ret = -EINVAL;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002237
2238 if (netxen_api_lock(adapter))
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002239 return ret;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002240
2241 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2242
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002243 if (state == NX_DEV_NEED_AER)
2244 ret = 0;
2245 else if (state == NX_DEV_READY) {
2246 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_AER);
2247 ret = 0;
2248 }
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002249
2250 netxen_api_unlock(adapter);
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002251 return ret;
2252}
2253
2254static int
2255nx_dev_request_reset(struct netxen_adapter *adapter)
2256{
2257 u32 state;
2258 int ret = -EINVAL;
2259
2260 if (netxen_api_lock(adapter))
2261 return ret;
2262
2263 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2264
2265 if (state == NX_DEV_NEED_RESET)
2266 ret = 0;
2267 else if (state != NX_DEV_INITALIZING && state != NX_DEV_NEED_AER) {
2268 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_RESET);
2269 ret = 0;
2270 }
2271
2272 netxen_api_unlock(adapter);
2273
2274 return ret;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002275}
2276
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002277static int
2278netxen_can_start_firmware(struct netxen_adapter *adapter)
2279{
2280 int count;
2281 int can_start = 0;
2282
2283 if (netxen_api_lock(adapter))
2284 return 0;
2285
2286 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2287
2288 if ((count < 0) || (count >= NX_MAX_PCI_FUNC))
2289 count = 0;
2290
2291 if (count == 0) {
2292 can_start = 1;
2293 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_INITALIZING);
2294 }
2295
2296 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2297
2298 netxen_api_unlock(adapter);
2299
2300 return can_start;
2301}
2302
2303static void
2304netxen_schedule_work(struct netxen_adapter *adapter,
2305 work_func_t func, int delay)
2306{
2307 INIT_DELAYED_WORK(&adapter->fw_work, func);
2308 schedule_delayed_work(&adapter->fw_work, delay);
2309}
2310
2311static void
2312netxen_cancel_fw_work(struct netxen_adapter *adapter)
2313{
2314 while (test_and_set_bit(__NX_RESETTING, &adapter->state))
2315 msleep(10);
2316
2317 cancel_delayed_work_sync(&adapter->fw_work);
2318}
2319
2320static void
2321netxen_attach_work(struct work_struct *work)
2322{
2323 struct netxen_adapter *adapter = container_of(work,
2324 struct netxen_adapter, fw_work.work);
2325 struct net_device *netdev = adapter->netdev;
2326 int err = 0;
2327
2328 if (netif_running(netdev)) {
2329 err = netxen_nic_attach(adapter);
2330 if (err)
2331 goto done;
2332
2333 err = netxen_nic_up(adapter, netdev);
2334 if (err) {
2335 netxen_nic_detach(adapter);
2336 goto done;
2337 }
2338
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002339 netxen_config_indev_addr(netdev, NETDEV_UP);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002340 }
2341
2342 netif_device_attach(netdev);
2343
2344done:
2345 adapter->fw_fail_cnt = 0;
2346 clear_bit(__NX_RESETTING, &adapter->state);
2347 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
2348}
2349
2350static void
2351netxen_fwinit_work(struct work_struct *work)
2352{
2353 struct netxen_adapter *adapter = container_of(work,
2354 struct netxen_adapter, fw_work.work);
2355 int dev_state;
2356
2357 dev_state = NXRD32(adapter, NX_CRB_DEV_STATE);
2358
2359 switch (dev_state) {
2360 case NX_DEV_COLD:
2361 case NX_DEV_READY:
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002362 if (!netxen_start_firmware(adapter)) {
2363 netxen_schedule_work(adapter, netxen_attach_work, 0);
2364 return;
2365 }
2366 break;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002367
Amit Kumar Salecha6b50ea152010-03-29 02:43:42 +00002368 case NX_DEV_NEED_RESET:
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002369 case NX_DEV_INITALIZING:
2370 if (++adapter->fw_wait_cnt < FW_POLL_THRESH) {
2371 netxen_schedule_work(adapter,
2372 netxen_fwinit_work, 2 * FW_POLL_DELAY);
2373 return;
2374 }
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002375
2376 case NX_DEV_FAILED:
2377 default:
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00002378 nx_incr_dev_ref_cnt(adapter);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002379 break;
2380 }
2381
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002382 clear_bit(__NX_RESETTING, &adapter->state);
2383}
2384
2385static void
2386netxen_detach_work(struct work_struct *work)
2387{
2388 struct netxen_adapter *adapter = container_of(work,
2389 struct netxen_adapter, fw_work.work);
2390 struct net_device *netdev = adapter->netdev;
2391 int ref_cnt, delay;
2392 u32 status;
2393
2394 netif_device_detach(netdev);
2395
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00002396 netxen_nic_down(adapter, netdev);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002397
Amit Kumar Salechae15eec22010-02-02 04:16:21 +00002398 rtnl_lock();
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002399 netxen_nic_detach(adapter);
Amit Kumar Salechae15eec22010-02-02 04:16:21 +00002400 rtnl_unlock();
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002401
2402 status = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1);
2403
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002404 if (status & NX_RCODE_FATAL_ERROR)
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00002405 goto err_ret;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002406
2407 if (adapter->temp == NX_TEMP_PANIC)
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00002408 goto err_ret;
2409
2410 ref_cnt = nx_decr_dev_ref_cnt(adapter);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002411
Amit Kumar Salecha6b50ea152010-03-29 02:43:42 +00002412 if (ref_cnt == -EIO)
2413 goto err_ret;
2414
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002415 delay = (ref_cnt == 0) ? 0 : (2 * FW_POLL_DELAY);
2416
2417 adapter->fw_wait_cnt = 0;
2418 netxen_schedule_work(adapter, netxen_fwinit_work, delay);
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00002419
2420 return;
2421
2422err_ret:
2423 clear_bit(__NX_RESETTING, &adapter->state);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002424}
2425
2426static int
2427netxen_check_health(struct netxen_adapter *adapter)
2428{
2429 u32 state, heartbit;
2430 struct net_device *netdev = adapter->netdev;
2431
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002432 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2433 if (state == NX_DEV_NEED_AER)
2434 return 0;
2435
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002436 if (netxen_nic_check_temp(adapter))
2437 goto detach;
2438
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002439 if (adapter->need_fw_reset) {
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002440 if (nx_dev_request_reset(adapter))
2441 return 0;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002442 goto detach;
2443 }
2444
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002445 /* NX_DEV_NEED_RESET, this state can be marked in two cases
2446 * 1. Tx timeout 2. Fw hang
2447 * Send request to destroy context in case of tx timeout only
2448 * and doesn't required in case of Fw hang
2449 */
Amit Kumar Salecha6a808c62009-12-08 20:40:55 +00002450 if (state == NX_DEV_NEED_RESET) {
2451 adapter->need_fw_reset = 1;
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002452 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2453 goto detach;
Amit Kumar Salecha6a808c62009-12-08 20:40:55 +00002454 }
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002455
2456 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2457 return 0;
2458
2459 heartbit = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER);
2460 if (heartbit != adapter->heartbit) {
2461 adapter->heartbit = heartbit;
2462 adapter->fw_fail_cnt = 0;
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002463 if (adapter->need_fw_reset)
2464 goto detach;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002465 return 0;
2466 }
2467
2468 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2469 return 0;
2470
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002471 if (nx_dev_request_reset(adapter))
2472 return 0;
2473
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002474 clear_bit(__NX_FW_ATTACHED, &adapter->state);
2475
2476 dev_info(&netdev->dev, "firmware hang detected\n");
2477
2478detach:
Narender Kumarcaa2dd52009-10-16 15:50:11 +00002479 if ((auto_fw_reset == AUTO_FW_RESET_ENABLED) &&
2480 !test_and_set_bit(__NX_RESETTING, &adapter->state))
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002481 netxen_schedule_work(adapter, netxen_detach_work, 0);
2482 return 1;
2483}
2484
2485static void
2486netxen_fw_poll_work(struct work_struct *work)
2487{
2488 struct netxen_adapter *adapter = container_of(work,
2489 struct netxen_adapter, fw_work.work);
2490
2491 if (test_bit(__NX_RESETTING, &adapter->state))
2492 goto reschedule;
2493
2494 if (test_bit(__NX_DEV_UP, &adapter->state)) {
2495 if (!adapter->has_link_events) {
2496
2497 netxen_nic_handle_phy_intr(adapter);
2498
2499 if (adapter->link_changed)
2500 netxen_nic_set_link_parameters(adapter);
2501 }
2502 }
2503
2504 if (netxen_check_health(adapter))
2505 return;
2506
2507reschedule:
2508 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
2509}
2510
Narender Kumarfa3ce352009-08-24 19:23:28 +00002511static ssize_t
2512netxen_store_bridged_mode(struct device *dev,
2513 struct device_attribute *attr, const char *buf, size_t len)
2514{
2515 struct net_device *net = to_net_dev(dev);
2516 struct netxen_adapter *adapter = netdev_priv(net);
2517 unsigned long new;
2518 int ret = -EINVAL;
2519
2520 if (!(adapter->capabilities & NX_FW_CAPABILITY_BDG))
2521 goto err_out;
2522
2523 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2524 goto err_out;
2525
2526 if (strict_strtoul(buf, 2, &new))
2527 goto err_out;
2528
2529 if (!netxen_config_bridged_mode(adapter, !!new))
2530 ret = len;
2531
2532err_out:
2533 return ret;
2534}
2535
2536static ssize_t
2537netxen_show_bridged_mode(struct device *dev,
2538 struct device_attribute *attr, char *buf)
2539{
2540 struct net_device *net = to_net_dev(dev);
2541 struct netxen_adapter *adapter;
2542 int bridged_mode = 0;
2543
2544 adapter = netdev_priv(net);
2545
2546 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2547 bridged_mode = !!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED);
2548
2549 return sprintf(buf, "%d\n", bridged_mode);
2550}
2551
2552static struct device_attribute dev_attr_bridged_mode = {
2553 .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
2554 .show = netxen_show_bridged_mode,
2555 .store = netxen_store_bridged_mode,
2556};
2557
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002558static ssize_t
2559netxen_store_diag_mode(struct device *dev,
2560 struct device_attribute *attr, const char *buf, size_t len)
2561{
2562 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2563 unsigned long new;
2564
2565 if (strict_strtoul(buf, 2, &new))
2566 return -EINVAL;
2567
2568 if (!!new != !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2569 adapter->flags ^= NETXEN_NIC_DIAG_ENABLED;
2570
2571 return len;
2572}
2573
2574static ssize_t
2575netxen_show_diag_mode(struct device *dev,
2576 struct device_attribute *attr, char *buf)
2577{
2578 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2579
2580 return sprintf(buf, "%d\n",
2581 !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED));
2582}
2583
2584static struct device_attribute dev_attr_diag_mode = {
2585 .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)},
2586 .show = netxen_show_diag_mode,
2587 .store = netxen_store_diag_mode,
2588};
2589
2590static int
2591netxen_sysfs_validate_crb(struct netxen_adapter *adapter,
2592 loff_t offset, size_t size)
2593{
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002594 size_t crb_size = 4;
2595
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002596 if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2597 return -EIO;
2598
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002599 if (offset < NETXEN_PCI_CRBSPACE) {
2600 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2601 return -EINVAL;
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002602
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002603 if (ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM,
2604 NETXEN_PCI_CAMQM_2M_END))
2605 crb_size = 8;
2606 else
2607 return -EINVAL;
2608 }
2609
2610 if ((size != crb_size) || (offset & (crb_size-1)))
2611 return -EINVAL;
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002612
2613 return 0;
2614}
2615
2616static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002617netxen_sysfs_read_crb(struct file *filp, struct kobject *kobj,
2618 struct bin_attribute *attr,
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002619 char *buf, loff_t offset, size_t size)
2620{
2621 struct device *dev = container_of(kobj, struct device, kobj);
2622 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2623 u32 data;
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002624 u64 qmdata;
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002625 int ret;
2626
2627 ret = netxen_sysfs_validate_crb(adapter, offset, size);
2628 if (ret != 0)
2629 return ret;
2630
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002631 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) &&
2632 ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM,
2633 NETXEN_PCI_CAMQM_2M_END)) {
2634 netxen_pci_camqm_read_2M(adapter, offset, &qmdata);
2635 memcpy(buf, &qmdata, size);
2636 } else {
2637 data = NXRD32(adapter, offset);
2638 memcpy(buf, &data, size);
2639 }
2640
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002641 return size;
2642}
2643
2644static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002645netxen_sysfs_write_crb(struct file *filp, struct kobject *kobj,
2646 struct bin_attribute *attr,
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002647 char *buf, loff_t offset, size_t size)
2648{
2649 struct device *dev = container_of(kobj, struct device, kobj);
2650 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2651 u32 data;
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002652 u64 qmdata;
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002653 int ret;
2654
2655 ret = netxen_sysfs_validate_crb(adapter, offset, size);
2656 if (ret != 0)
2657 return ret;
2658
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002659 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) &&
2660 ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM,
2661 NETXEN_PCI_CAMQM_2M_END)) {
2662 memcpy(&qmdata, buf, size);
2663 netxen_pci_camqm_write_2M(adapter, offset, qmdata);
2664 } else {
2665 memcpy(&data, buf, size);
2666 NXWR32(adapter, offset, data);
2667 }
2668
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002669 return size;
2670}
2671
2672static int
2673netxen_sysfs_validate_mem(struct netxen_adapter *adapter,
2674 loff_t offset, size_t size)
2675{
2676 if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2677 return -EIO;
2678
2679 if ((size != 8) || (offset & 0x7))
2680 return -EIO;
2681
2682 return 0;
2683}
2684
2685static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002686netxen_sysfs_read_mem(struct file *filp, struct kobject *kobj,
2687 struct bin_attribute *attr,
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002688 char *buf, loff_t offset, size_t size)
2689{
2690 struct device *dev = container_of(kobj, struct device, kobj);
2691 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2692 u64 data;
2693 int ret;
2694
2695 ret = netxen_sysfs_validate_mem(adapter, offset, size);
2696 if (ret != 0)
2697 return ret;
2698
2699 if (adapter->pci_mem_read(adapter, offset, &data))
2700 return -EIO;
2701
2702 memcpy(buf, &data, size);
2703
2704 return size;
2705}
2706
Chris Wright2c3c8be2010-05-12 18:28:57 -07002707static ssize_t netxen_sysfs_write_mem(struct file *filp, struct kobject *kobj,
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002708 struct bin_attribute *attr, char *buf,
2709 loff_t offset, size_t size)
2710{
2711 struct device *dev = container_of(kobj, struct device, kobj);
2712 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2713 u64 data;
2714 int ret;
2715
2716 ret = netxen_sysfs_validate_mem(adapter, offset, size);
2717 if (ret != 0)
2718 return ret;
2719
2720 memcpy(&data, buf, size);
2721
2722 if (adapter->pci_mem_write(adapter, offset, data))
2723 return -EIO;
2724
2725 return size;
2726}
2727
2728
2729static struct bin_attribute bin_attr_crb = {
2730 .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)},
2731 .size = 0,
2732 .read = netxen_sysfs_read_crb,
2733 .write = netxen_sysfs_write_crb,
2734};
2735
2736static struct bin_attribute bin_attr_mem = {
2737 .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)},
2738 .size = 0,
2739 .read = netxen_sysfs_read_mem,
2740 .write = netxen_sysfs_write_mem,
2741};
2742
Narender Kumarcaa2dd52009-10-16 15:50:11 +00002743
Narender Kumarfa3ce352009-08-24 19:23:28 +00002744static void
2745netxen_create_sysfs_entries(struct netxen_adapter *adapter)
2746{
2747 struct net_device *netdev = adapter->netdev;
2748 struct device *dev = &netdev->dev;
2749
2750 if (adapter->capabilities & NX_FW_CAPABILITY_BDG) {
2751 /* bridged_mode control */
2752 if (device_create_file(dev, &dev_attr_bridged_mode)) {
2753 dev_warn(&netdev->dev,
2754 "failed to create bridged_mode sysfs entry\n");
2755 }
2756 }
2757}
2758
2759static void
2760netxen_remove_sysfs_entries(struct netxen_adapter *adapter)
2761{
2762 struct net_device *netdev = adapter->netdev;
2763 struct device *dev = &netdev->dev;
2764
2765 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2766 device_remove_file(dev, &dev_attr_bridged_mode);
2767}
2768
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002769static void
2770netxen_create_diag_entries(struct netxen_adapter *adapter)
2771{
2772 struct pci_dev *pdev = adapter->pdev;
2773 struct device *dev;
2774
2775 dev = &pdev->dev;
2776 if (device_create_file(dev, &dev_attr_diag_mode))
2777 dev_info(dev, "failed to create diag_mode sysfs entry\n");
2778 if (device_create_bin_file(dev, &bin_attr_crb))
2779 dev_info(dev, "failed to create crb sysfs entry\n");
2780 if (device_create_bin_file(dev, &bin_attr_mem))
2781 dev_info(dev, "failed to create mem sysfs entry\n");
2782}
2783
2784
2785static void
2786netxen_remove_diag_entries(struct netxen_adapter *adapter)
2787{
2788 struct pci_dev *pdev = adapter->pdev;
2789 struct device *dev = &pdev->dev;
2790
2791 device_remove_file(dev, &dev_attr_diag_mode);
2792 device_remove_bin_file(dev, &bin_attr_crb);
2793 device_remove_bin_file(dev, &bin_attr_mem);
2794}
2795
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002796#ifdef CONFIG_INET
2797
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002798#define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2799
2800static int
2801netxen_destip_supported(struct netxen_adapter *adapter)
2802{
2803 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2804 return 0;
2805
2806 if (adapter->ahw.cut_through)
2807 return 0;
2808
2809 return 1;
2810}
2811
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002812static void
2813netxen_config_indev_addr(struct net_device *dev, unsigned long event)
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002814{
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002815 struct in_device *indev;
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002816 struct netxen_adapter *adapter = netdev_priv(dev);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002817
Amit Kumar Salecha3db76752009-09-09 18:12:37 -07002818 if (!netxen_destip_supported(adapter))
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002819 return;
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002820
2821 indev = in_dev_get(dev);
2822 if (!indev)
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002823 return;
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002824
2825 for_ifa(indev) {
2826 switch (event) {
2827 case NETDEV_UP:
2828 netxen_config_ipaddr(adapter,
2829 ifa->ifa_address, NX_IP_UP);
2830 break;
2831 case NETDEV_DOWN:
2832 netxen_config_ipaddr(adapter,
2833 ifa->ifa_address, NX_IP_DOWN);
2834 break;
2835 default:
2836 break;
2837 }
2838 } endfor_ifa(indev);
2839
2840 in_dev_put(indev);
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002841}
2842
2843static int netxen_netdev_event(struct notifier_block *this,
2844 unsigned long event, void *ptr)
2845{
2846 struct netxen_adapter *adapter;
2847 struct net_device *dev = (struct net_device *)ptr;
2848
2849recheck:
2850 if (dev == NULL)
2851 goto done;
2852
2853 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2854 dev = vlan_dev_real_dev(dev);
2855 goto recheck;
2856 }
2857
2858 if (!is_netxen_netdev(dev))
2859 goto done;
2860
2861 adapter = netdev_priv(dev);
2862
2863 if (!adapter)
2864 goto done;
2865
2866 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2867 goto done;
2868
2869 netxen_config_indev_addr(dev, event);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002870done:
2871 return NOTIFY_DONE;
2872}
2873
2874static int
2875netxen_inetaddr_event(struct notifier_block *this,
2876 unsigned long event, void *ptr)
2877{
2878 struct netxen_adapter *adapter;
2879 struct net_device *dev;
2880
2881 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
2882
2883 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
2884
2885recheck:
2886 if (dev == NULL || !netif_running(dev))
2887 goto done;
2888
2889 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2890 dev = vlan_dev_real_dev(dev);
2891 goto recheck;
2892 }
2893
2894 if (!is_netxen_netdev(dev))
2895 goto done;
2896
2897 adapter = netdev_priv(dev);
2898
2899 if (!adapter || !netxen_destip_supported(adapter))
2900 goto done;
2901
2902 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2903 goto done;
2904
2905 switch (event) {
2906 case NETDEV_UP:
2907 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP);
2908 break;
2909 case NETDEV_DOWN:
2910 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN);
2911 break;
2912 default:
2913 break;
2914 }
2915
2916done:
2917 return NOTIFY_DONE;
2918}
2919
2920static struct notifier_block netxen_netdev_cb = {
2921 .notifier_call = netxen_netdev_event,
2922};
2923
2924static struct notifier_block netxen_inetaddr_cb = {
2925 .notifier_call = netxen_inetaddr_event,
2926};
Randy Dunlap9feae562009-09-11 12:41:04 +00002927#else
2928static void
2929netxen_config_indev_addr(struct net_device *dev, unsigned long event)
2930{ }
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002931#endif
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002932
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002933static struct pci_error_handlers netxen_err_handler = {
2934 .error_detected = netxen_io_error_detected,
2935 .slot_reset = netxen_io_slot_reset,
2936 .resume = netxen_io_resume,
2937};
2938
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002939static struct pci_driver netxen_driver = {
2940 .name = netxen_nic_driver_name,
2941 .id_table = netxen_pci_tbl,
2942 .probe = netxen_nic_probe,
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002943 .remove = __devexit_p(netxen_nic_remove),
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002944#ifdef CONFIG_PM
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002945 .suspend = netxen_nic_suspend,
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00002946 .resume = netxen_nic_resume,
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002947#endif
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002948 .shutdown = netxen_nic_shutdown,
2949 .err_handler = &netxen_err_handler
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002950};
2951
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002952static int __init netxen_init_module(void)
2953{
Dhananjay Phadkeff4fbd42009-03-13 14:52:06 +00002954 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
2955
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002956#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002957 register_netdevice_notifier(&netxen_netdev_cb);
2958 register_inetaddr_notifier(&netxen_inetaddr_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002959#endif
Amit S. Kale184231b2007-01-22 06:52:53 -08002960 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002961}
2962
2963module_init(netxen_init_module);
2964
2965static void __exit netxen_exit_module(void)
2966{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002967 pci_unregister_driver(&netxen_driver);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002968
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002969#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002970 unregister_inetaddr_notifier(&netxen_inetaddr_cb);
2971 unregister_netdevice_notifier(&netxen_netdev_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002972#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002973}
2974
2975module_exit(netxen_exit_module);