blob: 6ce6ce1df6d2c16eda31bbd8a48b07c162949e28 [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
Dhananjay Phadkec25c0b92009-10-28 04:11:04 -070041MODULE_DESCRIPTION("QLogic/NetXen (1/10) GbE Converged 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_P2_MN_ROMIMAGE_NAME);
45MODULE_FIRMWARE(NX_P3_CT_ROMIMAGE_NAME);
46MODULE_FIRMWARE(NX_P3_MN_ROMIMAGE_NAME);
47MODULE_FIRMWARE(NX_UNIFIED_ROMIMAGE_NAME);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040048
dhananjay@netxen.comceded322007-07-19 14:41:09 +053049char netxen_nic_driver_name[] = "netxen_nic";
Dhananjay Phadkec25c0b92009-10-28 04:11:04 -070050static char netxen_nic_driver_string[] = "QLogic/NetXen Network Driver v"
Amit S. Kalecb8011a2006-11-29 09:00:10 -080051 NETXEN_NIC_LINUX_VERSIONID;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040052
Dhananjay Phadke29566402008-07-21 19:44:04 -070053static int port_mode = NETXEN_PORT_MODE_AUTO_NEG;
54
55/* Default to restricted 1G auto-neg mode */
56static int wol_port_mode = 5;
57
58static int use_msi = 1;
59
60static int use_msi_x = 1;
61
Stephen Hemmingerafdafff2009-12-18 20:13:35 -080062static int auto_fw_reset = AUTO_FW_RESET_ENABLED;
63module_param(auto_fw_reset, int, 0644);
64MODULE_PARM_DESC(auto_fw_reset,"Auto firmware reset (0=disabled, 1=enabled");
Narender Kumarcaa2dd52009-10-16 15:50:11 +000065
Amit S. Kale3d396eb2006-10-21 15:33:03 -040066static int __devinit netxen_nic_probe(struct pci_dev *pdev,
Dhananjay Phadke29566402008-07-21 19:44:04 -070067 const struct pci_device_id *ent);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040068static void __devexit netxen_nic_remove(struct pci_dev *pdev);
69static int netxen_nic_open(struct net_device *netdev);
70static int netxen_nic_close(struct net_device *netdev);
Stephen Hemminger613573252009-08-31 19:50:58 +000071static netdev_tx_t netxen_nic_xmit_frame(struct sk_buff *,
72 struct net_device *);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040073static void netxen_tx_timeout(struct net_device *netdev);
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +000074static void netxen_tx_timeout_task(struct work_struct *work);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +000075static void netxen_fw_poll_work(struct work_struct *work);
76static void netxen_schedule_work(struct netxen_adapter *adapter,
77 work_func_t func, int delay);
78static void netxen_cancel_fw_work(struct netxen_adapter *adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -070079static int netxen_nic_poll(struct napi_struct *napi, int budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040080#ifdef CONFIG_NET_POLL_CONTROLLER
81static void netxen_nic_poll_controller(struct net_device *netdev);
82#endif
Narender Kumarfa3ce352009-08-24 19:23:28 +000083
84static void netxen_create_sysfs_entries(struct netxen_adapter *adapter);
85static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter);
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +000086static void netxen_create_diag_entries(struct netxen_adapter *adapter);
87static void netxen_remove_diag_entries(struct netxen_adapter *adapter);
Narender Kumarfa3ce352009-08-24 19:23:28 +000088
Amit Kumar Salechae87ad552009-12-08 20:40:56 +000089static int nx_dev_request_aer(struct netxen_adapter *adapter);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +000090static int nx_decr_dev_ref_cnt(struct netxen_adapter *adapter);
91static int netxen_can_start_firmware(struct netxen_adapter *adapter);
92
Jeff Garzik1494a812006-11-07 05:12:16 -050093static irqreturn_t netxen_intr(int irq, void *data);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -070094static irqreturn_t netxen_msi_intr(int irq, void *data);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -080095static irqreturn_t netxen_msix_intr(int irq, void *data);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040096
Amit Kumar Salechad0725e42009-09-05 17:43:09 +000097static void netxen_config_indev_addr(struct net_device *dev, unsigned long);
98
Amit S. Kale3d396eb2006-10-21 15:33:03 -040099/* PCI Device ID Table */
Al Viro70081ac2008-06-23 02:04:50 +0100100#define ENTRY(device) \
Dhananjay Phadke040dec32008-09-12 06:55:14 -0700101 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
Al Viro70081ac2008-06-23 02:04:50 +0100102 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
103
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000104static DEFINE_PCI_DEVICE_TABLE(netxen_pci_tbl) = {
Dhananjay Phadke040dec32008-09-12 06:55:14 -0700105 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR),
106 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4),
107 ENTRY(PCI_DEVICE_ID_NX2031_4GCU),
108 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ),
109 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ),
110 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT),
111 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2),
112 ENTRY(PCI_DEVICE_ID_NX3031),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400113 {0,}
114};
115
116MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
117
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700118static uint32_t crb_cmd_producer[4] = {
119 CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1,
120 CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3
121};
122
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700123void
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700124netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000125 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700126{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000127 NXWRIO(adapter, tx_ring->crb_cmd_producer, tx_ring->producer);
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000128
129 if (netxen_tx_avail(tx_ring) <= TX_STOP_THRESH) {
130 netif_stop_queue(adapter->netdev);
131 smp_mb();
132 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700133}
134
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700135static uint32_t crb_cmd_consumer[4] = {
136 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
137 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
138};
139
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700140static inline void
141netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000142 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700143{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000144 NXWRIO(adapter, tx_ring->crb_cmd_consumer, tx_ring->sw_consumer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700145}
146
Dhananjay Phadke29566402008-07-21 19:44:04 -0700147static uint32_t msi_tgt_status[8] = {
Dhananjay Phadke443be792008-03-17 19:59:48 -0700148 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700149 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
150 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
151 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
Dhananjay Phadke443be792008-03-17 19:59:48 -0700152};
153
Dhananjay Phadke29566402008-07-21 19:44:04 -0700154static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
155
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000156static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700157{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000158 struct netxen_adapter *adapter = sds_ring->adapter;
159
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000160 NXWRIO(adapter, sds_ring->crb_intr_mask, 0);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700161}
162
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000163static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700164{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000165 struct netxen_adapter *adapter = sds_ring->adapter;
166
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000167 NXWRIO(adapter, sds_ring->crb_intr_mask, 0x1);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700168
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700169 if (!NETXEN_IS_MSI_FAMILY(adapter))
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000170 NXWRIO(adapter, adapter->tgt_mask_reg, 0xfbff);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700171}
172
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000173static int
174netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count)
175{
176 int size = sizeof(struct nx_host_sds_ring) * count;
177
178 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
179
180 return (recv_ctx->sds_rings == NULL);
181}
182
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000183static void
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000184netxen_free_sds_rings(struct netxen_recv_context *recv_ctx)
185{
186 if (recv_ctx->sds_rings != NULL)
187 kfree(recv_ctx->sds_rings);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000188
189 recv_ctx->sds_rings = NULL;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000190}
191
192static int
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000193netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
194{
195 int ring;
196 struct nx_host_sds_ring *sds_ring;
197 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
198
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000199 if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
Dhananjay Phadkef17443f2009-07-26 20:07:43 +0000200 return -ENOMEM;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000201
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000202 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
203 sds_ring = &recv_ctx->sds_rings[ring];
204 netif_napi_add(netdev, &sds_ring->napi,
205 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
206 }
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000207
208 return 0;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000209}
210
211static void
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000212netxen_napi_del(struct netxen_adapter *adapter)
213{
214 int ring;
215 struct nx_host_sds_ring *sds_ring;
216 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
217
218 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
219 sds_ring = &recv_ctx->sds_rings[ring];
220 netif_napi_del(&sds_ring->napi);
221 }
222
223 netxen_free_sds_rings(&adapter->recv_ctx);
224}
225
226static void
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000227netxen_napi_enable(struct netxen_adapter *adapter)
228{
229 int ring;
230 struct nx_host_sds_ring *sds_ring;
231 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
232
233 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
234 sds_ring = &recv_ctx->sds_rings[ring];
235 napi_enable(&sds_ring->napi);
236 netxen_nic_enable_int(sds_ring);
237 }
238}
239
240static void
241netxen_napi_disable(struct netxen_adapter *adapter)
242{
243 int ring;
244 struct nx_host_sds_ring *sds_ring;
245 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
246
247 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
248 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000249 netxen_nic_disable_int(sds_ring);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000250 napi_synchronize(&sds_ring->napi);
251 napi_disable(&sds_ring->napi);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000252 }
253}
254
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000255static int nx_set_dma_mask(struct netxen_adapter *adapter)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700256{
257 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000258 uint64_t mask, cmask;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700259
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000260 adapter->pci_using_dac = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700261
Yang Hongyang6afd1422009-04-06 19:01:15 -0700262 mask = DMA_BIT_MASK(32);
Yang Hongyang6afd1422009-04-06 19:01:15 -0700263 cmask = DMA_BIT_MASK(32);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000264
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000265 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000266#ifndef CONFIG_IA64
Yang Hongyang6afd1422009-04-06 19:01:15 -0700267 mask = DMA_BIT_MASK(35);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000268#endif
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000269 } else {
270 mask = DMA_BIT_MASK(39);
271 cmask = mask;
272 }
273
Dhananjay Phadke29566402008-07-21 19:44:04 -0700274 if (pci_set_dma_mask(pdev, mask) == 0 &&
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000275 pci_set_consistent_dma_mask(pdev, cmask) == 0) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700276 adapter->pci_using_dac = 1;
277 return 0;
278 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700279
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000280 return -EIO;
281}
282
283/* Update addressable range if firmware supports it */
284static int
285nx_update_dma_mask(struct netxen_adapter *adapter)
286{
287 int change, shift, err;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000288 uint64_t mask, old_mask, old_cmask;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000289 struct pci_dev *pdev = adapter->pdev;
290
291 change = 0;
292
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000293 shift = NXRD32(adapter, CRB_DMA_SHIFT);
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000294 if (shift > 32)
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000295 return 0;
296
297 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9))
298 change = 1;
299 else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4))
300 change = 1;
301
302 if (change) {
303 old_mask = pdev->dma_mask;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000304 old_cmask = pdev->dev.coherent_dma_mask;
305
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000306 mask = DMA_BIT_MASK(32+shift);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000307
308 err = pci_set_dma_mask(pdev, mask);
309 if (err)
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000310 goto err_out;
311
312 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
313
314 err = pci_set_consistent_dma_mask(pdev, mask);
315 if (err)
316 goto err_out;
317 }
318 dev_info(&pdev->dev, "using %d-bit dma mask\n", 32+shift);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700319 }
320
Dhananjay Phadke29566402008-07-21 19:44:04 -0700321 return 0;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000322
323err_out:
324 pci_set_dma_mask(pdev, old_mask);
325 pci_set_consistent_dma_mask(pdev, old_cmask);
326 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700327}
328
Dhananjay Phadke29566402008-07-21 19:44:04 -0700329static int
330netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
331{
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800332 u32 val, timeout;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700333
334 if (first_boot == 0x55555555) {
335 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000336 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800337
338 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
339 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700340
341 /* PCI bus master workaround */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000342 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700343 if (!(first_boot & 0x4)) {
344 first_boot |= 0x4;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000345 NXWR32(adapter, NETXEN_PCIE_REG(0x4), first_boot);
Amit Kumar Salecha581e8ae2010-01-07 22:10:15 +0000346 NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700347 }
348
349 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000350 first_boot = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700351 if (first_boot != 0x80000f) {
352 /* clear the register for future unloads/loads */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000353 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), 0);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800354 return -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700355 }
356
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800357 /* Start P2 boot loader */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000358 val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
359 NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800360 timeout = 0;
361 do {
362 msleep(1);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000363 val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800364
365 if (++timeout > 5000)
366 return -EIO;
367
368 } while (val == NETXEN_BDINFO_MAGIC);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700369 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800370 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700371}
372
373static void netxen_set_port_mode(struct netxen_adapter *adapter)
374{
375 u32 val, data;
376
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000377 val = adapter->ahw.board_type;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700378 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
379 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
380 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
381 data = NETXEN_PORT_MODE_802_3_AP;
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_XG) {
384 data = NETXEN_PORT_MODE_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 if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
387 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000388 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700389 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
390 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000391 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700392 } else {
393 data = NETXEN_PORT_MODE_AUTO_NEG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000394 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700395 }
396
397 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
398 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
399 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
400 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
401 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
402 }
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000403 NXWR32(adapter, NETXEN_WOL_PORT_MODE, wol_port_mode);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700404 }
405}
406
Dhananjay Phadke29566402008-07-21 19:44:04 -0700407static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
408{
409 u32 control;
410 int pos;
411
412 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
413 if (pos) {
414 pci_read_config_dword(pdev, pos, &control);
415 if (enable)
416 control |= PCI_MSIX_FLAGS_ENABLE;
417 else
418 control = 0;
419 pci_write_config_dword(pdev, pos, control);
420 }
421}
422
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000423static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700424{
425 int i;
426
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000427 for (i = 0; i < count; i++)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700428 adapter->msix_entries[i].entry = i;
429}
430
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700431static int
432netxen_read_mac_addr(struct netxen_adapter *adapter)
433{
434 int i;
435 unsigned char *p;
Amit Kumar Salechaa03d2452010-01-14 01:53:21 +0000436 u64 mac_addr;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700437 struct net_device *netdev = adapter->netdev;
438 struct pci_dev *pdev = adapter->pdev;
439
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700440 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
441 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
442 return -EIO;
443 } else {
444 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
445 return -EIO;
446 }
447
448 p = (unsigned char *)&mac_addr;
449 for (i = 0; i < 6; i++)
450 netdev->dev_addr[i] = *(p + 5 - i);
451
452 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
Narender Kumar5d09e532009-11-20 22:08:57 +0000453 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700454
455 /* set station address */
456
Johannes Berge1749612008-10-27 15:59:26 -0700457 if (!is_valid_ether_addr(netdev->perm_addr))
458 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700459
460 return 0;
461}
462
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000463int netxen_nic_set_mac(struct net_device *netdev, void *p)
464{
465 struct netxen_adapter *adapter = netdev_priv(netdev);
466 struct sockaddr *addr = p;
467
468 if (!is_valid_ether_addr(addr->sa_data))
469 return -EINVAL;
470
471 if (netif_running(netdev)) {
472 netif_device_detach(netdev);
473 netxen_napi_disable(adapter);
474 }
475
Narender Kumar5d09e532009-11-20 22:08:57 +0000476 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000477 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
478 adapter->macaddr_set(adapter, addr->sa_data);
479
480 if (netif_running(netdev)) {
481 netif_device_attach(netdev);
482 netxen_napi_enable(adapter);
483 }
484 return 0;
485}
486
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800487static void netxen_set_multicast_list(struct net_device *dev)
488{
489 struct netxen_adapter *adapter = netdev_priv(dev);
490
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000491 adapter->set_multi(dev);
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800492}
493
494static const struct net_device_ops netxen_netdev_ops = {
495 .ndo_open = netxen_nic_open,
496 .ndo_stop = netxen_nic_close,
497 .ndo_start_xmit = netxen_nic_xmit_frame,
498 .ndo_get_stats = netxen_nic_get_stats,
499 .ndo_validate_addr = eth_validate_addr,
500 .ndo_set_multicast_list = netxen_set_multicast_list,
501 .ndo_set_mac_address = netxen_nic_set_mac,
502 .ndo_change_mtu = netxen_nic_change_mtu,
503 .ndo_tx_timeout = netxen_tx_timeout,
504#ifdef CONFIG_NET_POLL_CONTROLLER
505 .ndo_poll_controller = netxen_nic_poll_controller,
506#endif
507};
508
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800509static void
510netxen_setup_intr(struct netxen_adapter *adapter)
511{
512 struct netxen_legacy_intr_set *legacy_intrp;
513 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000514 int err, num_msix;
515
516 if (adapter->rss_supported) {
517 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
518 MSIX_ENTRIES_PER_ADAPTER : 2;
519 } else
520 num_msix = 1;
521
522 adapter->max_sds_rings = 1;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800523
524 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800525
526 if (adapter->ahw.revision_id >= NX_P3_B0)
527 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
528 else
529 legacy_intrp = &legacy_intr[0];
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000530
531 adapter->int_vec_bit = legacy_intrp->int_vec_bit;
532 adapter->tgt_status_reg = netxen_get_ioaddr(adapter,
533 legacy_intrp->tgt_status_reg);
534 adapter->tgt_mask_reg = netxen_get_ioaddr(adapter,
535 legacy_intrp->tgt_mask_reg);
536 adapter->pci_int_reg = netxen_get_ioaddr(adapter,
537 legacy_intrp->pci_int_reg);
538 adapter->isr_int_vec = netxen_get_ioaddr(adapter, ISR_INT_VECTOR);
539
540 if (adapter->ahw.revision_id >= NX_P3_B1)
541 adapter->crb_int_state_reg = netxen_get_ioaddr(adapter,
542 ISR_INT_STATE_REG);
543 else
544 adapter->crb_int_state_reg = netxen_get_ioaddr(adapter,
545 CRB_INT_VECTOR);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800546
547 netxen_set_msix_bit(pdev, 0);
548
549 if (adapter->msix_supported) {
550
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000551 netxen_init_msix_entries(adapter, num_msix);
552 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
553 if (err == 0) {
554 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
555 netxen_set_msix_bit(pdev, 1);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800556
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000557 if (adapter->rss_supported)
558 adapter->max_sds_rings = num_msix;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800559
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000560 dev_info(&pdev->dev, "using msi-x interrupts\n");
561 return;
562 }
563
564 if (err > 0)
565 pci_disable_msix(pdev);
566
567 /* fall through for msi */
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800568 }
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000569
570 if (use_msi && !pci_enable_msi(pdev)) {
571 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000572 adapter->tgt_status_reg = netxen_get_ioaddr(adapter,
573 msi_tgt_status[adapter->ahw.pci_func]);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000574 dev_info(&pdev->dev, "using msi interrupts\n");
Dhananjay Phadkef67f3402009-05-18 21:46:40 -0700575 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000576 return;
577 }
578
579 dev_info(&pdev->dev, "using legacy interrupts\n");
580 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800581}
582
583static void
584netxen_teardown_intr(struct netxen_adapter *adapter)
585{
586 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
587 pci_disable_msix(adapter->pdev);
588 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
589 pci_disable_msi(adapter->pdev);
590}
591
592static void
593netxen_cleanup_pci_map(struct netxen_adapter *adapter)
594{
595 if (adapter->ahw.db_base != NULL)
596 iounmap(adapter->ahw.db_base);
597 if (adapter->ahw.pci_base0 != NULL)
598 iounmap(adapter->ahw.pci_base0);
599 if (adapter->ahw.pci_base1 != NULL)
600 iounmap(adapter->ahw.pci_base1);
601 if (adapter->ahw.pci_base2 != NULL)
602 iounmap(adapter->ahw.pci_base2);
603}
604
605static int
606netxen_setup_pci_map(struct netxen_adapter *adapter)
607{
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800608 void __iomem *db_ptr = NULL;
609
Dhananjay Phadke71fb62f2009-10-13 00:26:04 -0700610 resource_size_t mem_base, db_base;
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000611 unsigned long mem_len, db_len = 0;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800612
613 struct pci_dev *pdev = adapter->pdev;
614 int pci_func = adapter->ahw.pci_func;
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000615 struct netxen_hardware_context *ahw = &adapter->ahw;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800616
617 int err = 0;
618
619 /*
620 * Set the CRB window to invalid. If any register in window 0 is
621 * accessed it should set the window to 0 and then reset it to 1.
622 */
Dhananjay Phadke907fa122009-10-13 05:31:43 +0000623 adapter->ahw.crb_win = -1;
Dhananjay Phadke47abe352009-10-13 05:31:42 +0000624 adapter->ahw.ocm_win = -1;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800625
626 /* remap phys address */
627 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
628 mem_len = pci_resource_len(pdev, 0);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800629
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800630 /* 128 Meg of memory */
631 if (mem_len == NETXEN_PCI_128MB_SIZE) {
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000632
633 ahw->pci_base0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
634 ahw->pci_base1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800635 SECOND_PAGE_GROUP_SIZE);
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000636 ahw->pci_base2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800637 THIRD_PAGE_GROUP_SIZE);
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000638 if (ahw->pci_base0 == NULL || ahw->pci_base1 == NULL ||
639 ahw->pci_base2 == NULL) {
640 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
641 err = -EIO;
642 goto err_out;
643 }
644
645 ahw->pci_len0 = FIRST_PAGE_GROUP_SIZE;
646
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800647 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000648
649 ahw->pci_base1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
650 ahw->pci_base2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800651 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000652 if (ahw->pci_base1 == NULL || ahw->pci_base2 == NULL) {
653 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
654 err = -EIO;
655 goto err_out;
656 }
657
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800658 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800659
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000660 ahw->pci_base0 = pci_ioremap_bar(pdev, 0);
661 if (ahw->pci_base0 == NULL) {
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800662 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
663 return -EIO;
664 }
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000665 ahw->pci_len0 = mem_len;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800666 } else {
667 return -EIO;
668 }
669
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000670 netxen_setup_hwops(adapter);
671
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800672 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
673
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +0000674 if (NX_IS_REVISION_P3P(adapter->ahw.revision_id)) {
675 adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter,
676 NETXEN_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(pci_func)));
677
678 } else if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadke47abe352009-10-13 05:31:42 +0000679 adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter,
680 NETXEN_PCIX_PS_REG(PCIE_MN_WINDOW_REG(pci_func)));
681 }
682
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800683 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
684 goto skip_doorbell;
685
686 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
687 db_len = pci_resource_len(pdev, 4);
688
689 if (db_len == 0) {
690 printk(KERN_ERR "%s: doorbell is disabled\n",
691 netxen_nic_driver_name);
692 err = -EIO;
693 goto err_out;
694 }
695
696 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
697 if (!db_ptr) {
698 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
699 netxen_nic_driver_name);
700 err = -EIO;
701 goto err_out;
702 }
703
704skip_doorbell:
705 adapter->ahw.db_base = db_ptr;
706 adapter->ahw.db_len = db_len;
707 return 0;
708
709err_out:
710 netxen_cleanup_pci_map(adapter);
711 return err;
712}
713
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000714static void
715netxen_check_options(struct netxen_adapter *adapter)
716{
717 u32 fw_major, fw_minor, fw_build;
718 char brd_name[NETXEN_MAX_SHORT_NAME];
719 char serial_num[32];
720 int i, offset, val;
721 int *ptr32;
722 struct pci_dev *pdev = adapter->pdev;
723
724 adapter->driver_mismatch = 0;
725
726 ptr32 = (int *)&serial_num;
727 offset = NX_FW_SERIAL_NUM_OFFSET;
728 for (i = 0; i < 8; i++) {
729 if (netxen_rom_fast_read(adapter, offset, &val) == -1) {
730 dev_err(&pdev->dev, "error reading board info\n");
731 adapter->driver_mismatch = 1;
732 return;
733 }
734 ptr32[i] = cpu_to_le32(val);
735 offset += sizeof(u32);
736 }
737
738 fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
739 fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
740 fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
741
742 adapter->fw_version = NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build);
743
744 if (adapter->portnum == 0) {
745 get_brd_name_by_type(adapter->ahw.board_type, brd_name);
746
Dhananjay Phadkec25c0b92009-10-28 04:11:04 -0700747 pr_info("%s: %s Board S/N %s Chip rev 0x%x\n",
748 module_name(THIS_MODULE),
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000749 brd_name, serial_num, adapter->ahw.revision_id);
750 }
751
752 if (adapter->fw_version < NETXEN_VERSION_CODE(3, 4, 216)) {
753 adapter->driver_mismatch = 1;
754 dev_warn(&pdev->dev, "firmware version %d.%d.%d unsupported\n",
755 fw_major, fw_minor, fw_build);
756 return;
757 }
758
759 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
760 i = NXRD32(adapter, NETXEN_SRE_MISC);
761 adapter->ahw.cut_through = (i & 0x8000) ? 1 : 0;
762 }
763
764 dev_info(&pdev->dev, "firmware v%d.%d.%d [%s]\n",
765 fw_major, fw_minor, fw_build,
766 adapter->ahw.cut_through ? "cut-through" : "legacy");
767
768 if (adapter->fw_version >= NETXEN_VERSION_CODE(4, 0, 222))
769 adapter->capabilities = NXRD32(adapter, CRB_FW_CAPABILITIES_1);
770
771 adapter->flags &= ~NETXEN_NIC_LRO_ENABLED;
772
773 if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
774 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
775 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
776 } else if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
777 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
778 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
779 }
780
781 adapter->msix_supported = 0;
782 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
783 adapter->msix_supported = !!use_msi_x;
784 adapter->rss_supported = !!use_msi_x;
Amit Kumar Salecha083ba272010-03-29 02:43:45 +0000785 } else {
786 u32 flashed_ver = 0;
787 netxen_rom_fast_read(adapter,
788 NX_FW_VERSION_OFFSET, (int *)&flashed_ver);
789 flashed_ver = NETXEN_DECODE_VERSION(flashed_ver);
790
791 if (flashed_ver >= NETXEN_VERSION_CODE(3, 4, 336)) {
792 switch (adapter->ahw.board_type) {
793 case NETXEN_BRDTYPE_P2_SB31_10G:
794 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
795 adapter->msix_supported = !!use_msi_x;
796 adapter->rss_supported = !!use_msi_x;
797 break;
798 default:
799 break;
800 }
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000801 }
802 }
803
804 adapter->num_txd = MAX_CMD_DESCRIPTORS;
805
806 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
807 adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS;
808 adapter->max_rds_rings = 3;
809 } else {
810 adapter->num_lro_rxd = 0;
811 adapter->max_rds_rings = 2;
812 }
813}
814
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800815static int
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000816netxen_start_firmware(struct netxen_adapter *adapter)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800817{
818 int val, err, first_boot;
819 struct pci_dev *pdev = adapter->pdev;
820
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000821 /* required for NX2031 dummy dma */
822 err = nx_set_dma_mask(adapter);
823 if (err)
824 return err;
825
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000826 if (!netxen_can_start_firmware(adapter))
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000827 goto wait_init;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000828
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000829 first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800830
831 err = netxen_check_hw_init(adapter, first_boot);
832 if (err) {
833 dev_err(&pdev->dev, "error in init HW init sequence\n");
834 return err;
835 }
836
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000837 netxen_request_firmware(adapter);
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000838
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000839 err = netxen_need_fw_reset(adapter);
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000840 if (err < 0)
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000841 goto err_out;
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000842 if (err == 0)
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +0000843 goto wait_init;
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000844
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800845 if (first_boot != 0x55555555) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000846 NXWR32(adapter, CRB_CMDPEG_STATE, 0);
Amit Kumar Salecha0be367b2009-10-16 15:50:08 +0000847 netxen_pinit_from_rom(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800848 msleep(1);
849 }
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000850
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000851 NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000852 NXWR32(adapter, NETXEN_PEG_HALT_STATUS1, 0);
853 NXWR32(adapter, NETXEN_PEG_HALT_STATUS2, 0);
854
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000855 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
856 netxen_set_port_mode(adapter);
857
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000858 err = netxen_load_firmware(adapter);
859 if (err)
860 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800861
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000862 netxen_release_firmware(adapter);
863
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800864 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
865
866 /* Initialize multicast addr pool owners */
867 val = 0x7654;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000868 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800869 val |= 0x0f000000;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000870 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800871
872 }
873
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000874 err = netxen_init_dummy_dma(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800875 if (err)
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000876 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800877
878 /*
879 * Tell the hardware our version number.
880 */
881 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
882 | ((_NETXEN_NIC_LINUX_MINOR << 8))
883 | (_NETXEN_NIC_LINUX_SUBVERSION);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000884 NXWR32(adapter, CRB_DRIVER_VERSION, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800885
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000886wait_init:
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800887 /* Handshake with the card before we register the devices. */
888 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
889 if (err) {
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000890 netxen_free_dummy_dma(adapter);
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000891 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800892 }
893
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +0000894 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_READY);
895
Dhananjay Phadke68b3cae2009-07-26 20:07:36 +0000896 nx_update_dma_mask(adapter);
897
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000898 netxen_check_options(adapter);
Dhananjay Phadke68b3cae2009-07-26 20:07:36 +0000899
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +0000900 adapter->need_fw_reset = 0;
901
Dhananjay Phadkeec5c50c2009-09-11 11:28:13 +0000902 /* fall through and release firmware */
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000903
904err_out:
905 netxen_release_firmware(adapter);
906 return err;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800907}
908
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000909static int
910netxen_nic_request_irq(struct netxen_adapter *adapter)
911{
912 irq_handler_t handler;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000913 struct nx_host_sds_ring *sds_ring;
914 int err, ring;
915
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000916 unsigned long flags = IRQF_SAMPLE_RANDOM;
917 struct net_device *netdev = adapter->netdev;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000918 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000919
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000920 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
921 handler = netxen_msix_intr;
922 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
923 handler = netxen_msi_intr;
924 else {
925 flags |= IRQF_SHARED;
926 handler = netxen_intr;
927 }
928 adapter->irq = netdev->irq;
929
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000930 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
931 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000932 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000933 err = request_irq(sds_ring->irq, handler,
934 flags, sds_ring->name, sds_ring);
935 if (err)
936 return err;
937 }
938
939 return 0;
940}
941
942static void
943netxen_nic_free_irq(struct netxen_adapter *adapter)
944{
945 int ring;
946 struct nx_host_sds_ring *sds_ring;
947
948 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
949
950 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
951 sds_ring = &recv_ctx->sds_rings[ring];
952 free_irq(sds_ring->irq, sds_ring);
953 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000954}
955
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000956static void
957netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter)
958{
959 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
960 adapter->coal.normal.data.rx_time_us =
961 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
962 adapter->coal.normal.data.rx_packets =
963 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
964 adapter->coal.normal.data.tx_time_us =
965 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US;
966 adapter->coal.normal.data.tx_packets =
967 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS;
968}
969
Amit Kumar Salecha6f771412009-12-05 12:23:54 +0000970/* with rtnl_lock */
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000971static int
Amit Kumar Salecha6f771412009-12-05 12:23:54 +0000972__netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000973{
974 int err;
975
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000976 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
977 return -EIO;
978
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000979 err = adapter->init_port(adapter, adapter->physical_port);
980 if (err) {
981 printk(KERN_ERR "%s: Failed to initialize port %d\n",
982 netxen_nic_driver_name, adapter->portnum);
983 return err;
984 }
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000985 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
Narender Kumar5d09e532009-11-20 22:08:57 +0000986 adapter->macaddr_set(adapter, adapter->mac_addr);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000987
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000988 adapter->set_multi(netdev);
989 adapter->set_mtu(adapter, netdev->mtu);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000990
991 adapter->ahw.linkup = 0;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000992
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000993 if (adapter->max_sds_rings > 1)
994 netxen_config_rss(adapter, 1);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000995
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000996 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
997 netxen_config_intr_coalesce(adapter);
998
Narender Kumar1bb482f2009-08-23 08:35:09 +0000999 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
1000 netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED);
1001
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001002 netxen_napi_enable(adapter);
1003
Dhananjay Phadke5103c9f2009-04-28 15:29:09 +00001004 if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001005 netxen_linkevent_request(adapter, 1);
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +00001006 else
1007 netxen_nic_set_link_parameters(adapter);
1008
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001009 set_bit(__NX_DEV_UP, &adapter->state);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001010 return 0;
1011}
1012
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001013/* Usage: During resume and firmware recovery module.*/
1014
1015static inline int
1016netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
1017{
1018 int err = 0;
1019
1020 rtnl_lock();
1021 if (netif_running(netdev))
1022 err = __netxen_nic_up(adapter, netdev);
1023 rtnl_unlock();
1024
1025 return err;
1026}
1027
1028/* with rtnl_lock */
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001029static void
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001030__netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001031{
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +00001032 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1033 return;
1034
Amit Kumar Salechaf2251f62009-12-05 12:23:55 +00001035 if (!test_and_clear_bit(__NX_DEV_UP, &adapter->state))
1036 return;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001037
Amit Kumar Salechaf2251f62009-12-05 12:23:55 +00001038 smp_mb();
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001039 spin_lock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001040 netif_carrier_off(netdev);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001041 netif_tx_disable(netdev);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001042
1043 if (adapter->stop_port)
1044 adapter->stop_port(adapter);
1045
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +00001046 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1047 netxen_p3_free_mac_list(adapter);
1048
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001049 adapter->set_promisc(adapter, NETXEN_NIU_NON_PROMISC_MODE);
1050
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +00001051 netxen_napi_disable(adapter);
1052
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001053 netxen_release_tx_buffers(adapter);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001054 spin_unlock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001055}
1056
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001057/* Usage: During suspend and firmware recovery module */
1058
1059static inline void
1060netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
1061{
1062 rtnl_lock();
1063 if (netif_running(netdev))
1064 __netxen_nic_down(adapter, netdev);
1065 rtnl_unlock();
1066
1067}
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001068
1069static int
1070netxen_nic_attach(struct netxen_adapter *adapter)
1071{
1072 struct net_device *netdev = adapter->netdev;
1073 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +00001074 int err, ring;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001075 struct nx_host_rds_ring *rds_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001076 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001077
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001078 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
1079 return 0;
1080
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001081 err = netxen_init_firmware(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +00001082 if (err)
1083 return err;
1084
1085 err = netxen_napi_add(adapter, netdev);
1086 if (err)
1087 return err;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001088
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001089 err = netxen_alloc_sw_resources(adapter);
1090 if (err) {
1091 printk(KERN_ERR "%s: Error in setting sw resources\n",
1092 netdev->name);
1093 return err;
1094 }
1095
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001096 err = netxen_alloc_hw_resources(adapter);
1097 if (err) {
1098 printk(KERN_ERR "%s: Error in setting hw resources\n",
1099 netdev->name);
1100 goto err_out_free_sw;
1101 }
1102
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001103 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001104 tx_ring = adapter->tx_ring;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001105 tx_ring->crb_cmd_producer = netxen_get_ioaddr(adapter,
1106 crb_cmd_producer[adapter->portnum]);
1107 tx_ring->crb_cmd_consumer = netxen_get_ioaddr(adapter,
1108 crb_cmd_consumer[adapter->portnum]);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001109
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001110 tx_ring->producer = 0;
1111 tx_ring->sw_consumer = 0;
1112
1113 netxen_nic_update_cmd_producer(adapter, tx_ring);
1114 netxen_nic_update_cmd_consumer(adapter, tx_ring);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001115 }
1116
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001117 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1118 rds_ring = &adapter->recv_ctx.rds_rings[ring];
1119 netxen_post_rx_buffers(adapter, ring, rds_ring);
1120 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001121
1122 err = netxen_nic_request_irq(adapter);
1123 if (err) {
1124 dev_err(&pdev->dev, "%s: failed to setup interrupt\n",
1125 netdev->name);
1126 goto err_out_free_rxbuf;
1127 }
1128
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +00001129 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1130 netxen_nic_init_coalesce_defaults(adapter);
1131
Narender Kumarfa3ce352009-08-24 19:23:28 +00001132 netxen_create_sysfs_entries(adapter);
1133
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001134 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1135 return 0;
1136
1137err_out_free_rxbuf:
1138 netxen_release_rx_buffers(adapter);
1139 netxen_free_hw_resources(adapter);
1140err_out_free_sw:
1141 netxen_free_sw_resources(adapter);
1142 return err;
1143}
1144
1145static void
1146netxen_nic_detach(struct netxen_adapter *adapter)
1147{
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001148 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1149 return;
1150
Narender Kumarfa3ce352009-08-24 19:23:28 +00001151 netxen_remove_sysfs_entries(adapter);
1152
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001153 netxen_free_hw_resources(adapter);
Dhananjay Phadkecf981ff2009-07-17 15:27:06 +00001154 netxen_release_rx_buffers(adapter);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +00001155 netxen_nic_free_irq(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +00001156 netxen_napi_del(adapter);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001157 netxen_free_sw_resources(adapter);
1158
1159 adapter->is_up = 0;
1160}
1161
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001162int
1163netxen_nic_reset_context(struct netxen_adapter *adapter)
1164{
1165 int err = 0;
1166 struct net_device *netdev = adapter->netdev;
1167
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001168 if (test_and_set_bit(__NX_RESETTING, &adapter->state))
1169 return -EBUSY;
1170
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001171 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
1172
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001173 netif_device_detach(netdev);
1174
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001175 if (netif_running(netdev))
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001176 __netxen_nic_down(adapter, netdev);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001177
1178 netxen_nic_detach(adapter);
1179
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001180 if (netif_running(netdev)) {
1181 err = netxen_nic_attach(adapter);
1182 if (!err)
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001183 err = __netxen_nic_up(adapter, netdev);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001184
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001185 if (err)
1186 goto done;
1187 }
1188
1189 netif_device_attach(netdev);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001190 }
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001191
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001192done:
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001193 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001194 return err;
1195}
1196
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001197static int
1198netxen_setup_netdev(struct netxen_adapter *adapter,
1199 struct net_device *netdev)
1200{
1201 int err = 0;
1202 struct pci_dev *pdev = adapter->pdev;
1203
1204 adapter->rx_csum = 1;
1205 adapter->mc_enabled = 0;
1206 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1207 adapter->max_mc_count = 38;
1208 else
1209 adapter->max_mc_count = 16;
1210
1211 netdev->netdev_ops = &netxen_netdev_ops;
1212 netdev->watchdog_timeo = 2*HZ;
1213
1214 netxen_nic_change_mtu(netdev, netdev->mtu);
1215
1216 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
1217
1218 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1219 netdev->features |= (NETIF_F_GRO);
1220 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1221
1222 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1223 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1224 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1225 }
1226
1227 if (adapter->pci_using_dac) {
1228 netdev->features |= NETIF_F_HIGHDMA;
1229 netdev->vlan_features |= NETIF_F_HIGHDMA;
1230 }
1231
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001232 if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX)
1233 netdev->features |= (NETIF_F_HW_VLAN_TX);
1234
Narender Kumar1bb482f2009-08-23 08:35:09 +00001235 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
1236 netdev->features |= NETIF_F_LRO;
1237
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001238 netdev->irq = adapter->msix_entries[0].vector;
1239
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001240 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001241
1242 if (netxen_read_mac_addr(adapter))
1243 dev_warn(&pdev->dev, "failed to read mac addr\n");
1244
1245 netif_carrier_off(netdev);
1246 netif_stop_queue(netdev);
1247
1248 err = register_netdev(netdev);
1249 if (err) {
1250 dev_err(&pdev->dev, "failed to register net device\n");
1251 return err;
1252 }
1253
1254 return 0;
1255}
1256
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001257static int __devinit
1258netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1259{
1260 struct net_device *netdev = NULL;
1261 struct netxen_adapter *adapter = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001262 int i = 0, err;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001263 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001264 uint8_t revision_id;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001265
Eric W. Biederman688328c2010-03-17 22:24:39 +00001266 if (pdev->revision >= NX_P3_A0 && pdev->revision <= NX_P3_B1) {
1267 pr_warning("%s: chip revisions between 0x%x-0x%x "
Dhananjay Phadke11d89d62008-08-08 00:08:45 -07001268 "will not be enabled.\n",
Dhananjay Phadkec25c0b92009-10-28 04:11:04 -07001269 module_name(THIS_MODULE), NX_P3_A0, NX_P3_B1);
Dhananjay Phadke11d89d62008-08-08 00:08:45 -07001270 return -ENODEV;
1271 }
1272
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001273 if ((err = pci_enable_device(pdev)))
1274 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001275
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001276 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1277 err = -ENODEV;
1278 goto err_out_disable_pdev;
1279 }
1280
1281 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
1282 goto err_out_disable_pdev;
1283
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00001284 if (NX_IS_REVISION_P3(pdev->revision))
1285 pci_enable_pcie_error_reporting(pdev);
1286
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001287 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001288
1289 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
1290 if(!netdev) {
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001291 dev_err(&pdev->dev, "failed to allocate net_device\n");
1292 err = -ENOMEM;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001293 goto err_out_free_res;
1294 }
1295
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001296 SET_NETDEV_DEV(netdev, &pdev->dev);
1297
Wang Chen4cf16532008-11-12 23:38:14 -08001298 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001299 adapter->netdev = netdev;
1300 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001301 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001302
1303 revision_id = pdev->revision;
1304 adapter->ahw.revision_id = revision_id;
1305
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001306 rwlock_init(&adapter->ahw.crb_lock);
1307 spin_lock_init(&adapter->ahw.mem_lock);
1308
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001309 spin_lock_init(&adapter->tx_clean_lock);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +00001310 INIT_LIST_HEAD(&adapter->mac_list);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001311
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001312 err = netxen_setup_pci_map(adapter);
1313 if (err)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001314 goto err_out_free_netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001315
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +05301316 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001317 adapter->portnum = pci_func_id;
1318
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001319 err = netxen_nic_get_board_info(adapter);
1320 if (err) {
1321 dev_err(&pdev->dev, "Error getting board config info.\n");
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001322 goto err_out_iounmap;
1323 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001324
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001325 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001326 switch (adapter->ahw.board_type) {
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001327 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1328 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1329 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001330 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001331 break;
1332 default:
1333 break;
1334 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001335
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001336 err = netxen_start_firmware(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001337 if (err)
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00001338 goto err_out_decr_ref;
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001339
Dhananjay Phadke29566402008-07-21 19:44:04 -07001340 /*
1341 * See if the firmware gave us a virtual-physical port mapping.
1342 */
1343 adapter->physical_port = adapter->portnum;
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001344 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001345 i = NXRD32(adapter, CRB_V2P(adapter->portnum));
Dhananjay Phadke044fad02009-02-24 03:42:59 -08001346 if (i != 0x55555555)
1347 adapter->physical_port = i;
1348 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001349
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001350 netxen_nic_clear_stats(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001351
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001352 netxen_setup_intr(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001353
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001354 err = netxen_setup_netdev(adapter, netdev);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001355 if (err)
Dhananjay Phadke29566402008-07-21 19:44:04 -07001356 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001357
1358 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001359
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001360 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
1361
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001362 switch (adapter->ahw.port_type) {
Dhananjay Phadke29566402008-07-21 19:44:04 -07001363 case NETXEN_NIC_GBE:
1364 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1365 adapter->netdev->name);
1366 break;
1367 case NETXEN_NIC_XGBE:
1368 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1369 adapter->netdev->name);
1370 break;
1371 }
1372
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00001373 netxen_create_diag_entries(adapter);
1374
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001375 return 0;
1376
Dhananjay Phadke29566402008-07-21 19:44:04 -07001377err_out_disable_msi:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001378 netxen_teardown_intr(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001379
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001380 netxen_free_dummy_dma(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001381
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00001382err_out_decr_ref:
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001383 nx_decr_dev_ref_cnt(adapter);
1384
Dhananjay Phadke29566402008-07-21 19:44:04 -07001385err_out_iounmap:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001386 netxen_cleanup_pci_map(adapter);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001387
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001388err_out_free_netdev:
1389 free_netdev(netdev);
1390
1391err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001392 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001393
1394err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001395 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001396 pci_disable_device(pdev);
1397 return err;
1398}
1399
1400static void __devexit netxen_nic_remove(struct pci_dev *pdev)
1401{
1402 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001403 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001404
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001405 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001406 if (adapter == NULL)
1407 return;
1408
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001409 netdev = adapter->netdev;
1410
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001411 netxen_cancel_fw_work(adapter);
1412
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301413 unregister_netdev(netdev);
1414
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001415 cancel_work_sync(&adapter->tx_timeout_task);
1416
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001417 netxen_nic_detach(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001418
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001419 nx_decr_dev_ref_cnt(adapter);
1420
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001421 if (adapter->portnum == 0)
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001422 netxen_free_dummy_dma(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301423
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001424 clear_bit(__NX_RESETTING, &adapter->state);
1425
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001426 netxen_teardown_intr(adapter);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301427
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00001428 netxen_remove_diag_entries(adapter);
1429
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001430 netxen_cleanup_pci_map(adapter);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001431
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001432 netxen_release_firmware(adapter);
1433
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00001434 if (NX_IS_REVISION_P3(pdev->revision))
1435 pci_disable_pcie_error_reporting(pdev);
1436
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001437 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301438 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001439 pci_set_drvdata(pdev, NULL);
1440
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001441 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001442}
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00001443
1444static void netxen_nic_detach_func(struct netxen_adapter *adapter)
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001445{
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001446 struct net_device *netdev = adapter->netdev;
1447
1448 netif_device_detach(netdev);
1449
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001450 netxen_cancel_fw_work(adapter);
1451
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001452 if (netif_running(netdev))
1453 netxen_nic_down(adapter, netdev);
1454
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001455 cancel_work_sync(&adapter->tx_timeout_task);
1456
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001457 netxen_nic_detach(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001458
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001459 if (adapter->portnum == 0)
1460 netxen_free_dummy_dma(adapter);
1461
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001462 nx_decr_dev_ref_cnt(adapter);
1463
1464 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001465}
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001466
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00001467static int netxen_nic_attach_func(struct pci_dev *pdev)
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001468{
1469 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1470 struct net_device *netdev = adapter->netdev;
1471 int err;
1472
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001473 err = pci_enable_device(pdev);
1474 if (err)
1475 return err;
1476
Amit Kumar Salechabc86fcb2009-12-08 20:40:54 +00001477 pci_set_power_state(pdev, PCI_D0);
1478 pci_set_master(pdev);
1479 pci_restore_state(pdev);
1480
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001481 adapter->ahw.crb_win = -1;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001482 adapter->ahw.ocm_win = -1;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001483
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001484 err = netxen_start_firmware(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001485 if (err) {
1486 dev_err(&pdev->dev, "failed to start firmware\n");
1487 return err;
1488 }
1489
1490 if (netif_running(netdev)) {
1491 err = netxen_nic_attach(adapter);
1492 if (err)
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001493 goto err_out;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001494
1495 err = netxen_nic_up(adapter, netdev);
1496 if (err)
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001497 goto err_out_detach;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001498
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00001499 netxen_config_indev_addr(netdev, NETDEV_UP);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001500 }
1501
Amit Kumar Salechabc86fcb2009-12-08 20:40:54 +00001502 netif_device_attach(netdev);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001503 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
Dhananjay Phadke07653aa2009-09-20 19:20:39 +00001504 return 0;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001505
1506err_out_detach:
1507 netxen_nic_detach(adapter);
1508err_out:
1509 nx_decr_dev_ref_cnt(adapter);
1510 return err;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001511}
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00001512
1513static pci_ers_result_t netxen_io_error_detected(struct pci_dev *pdev,
1514 pci_channel_state_t state)
1515{
1516 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1517
1518 if (state == pci_channel_io_perm_failure)
1519 return PCI_ERS_RESULT_DISCONNECT;
1520
1521 if (nx_dev_request_aer(adapter))
1522 return PCI_ERS_RESULT_RECOVERED;
1523
1524 netxen_nic_detach_func(adapter);
1525
1526 pci_disable_device(pdev);
1527
1528 return PCI_ERS_RESULT_NEED_RESET;
1529}
1530
1531static pci_ers_result_t netxen_io_slot_reset(struct pci_dev *pdev)
1532{
1533 int err = 0;
1534
1535 err = netxen_nic_attach_func(pdev);
1536
1537 return err ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED;
1538}
1539
1540static void netxen_io_resume(struct pci_dev *pdev)
1541{
1542 pci_cleanup_aer_uncorrect_error_status(pdev);
1543}
1544
1545static void netxen_nic_shutdown(struct pci_dev *pdev)
1546{
1547 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1548
1549 netxen_nic_detach_func(adapter);
1550
1551 if (pci_save_state(pdev))
1552 return;
1553
1554 if (netxen_nic_wol_supported(adapter)) {
1555 pci_enable_wake(pdev, PCI_D3cold, 1);
1556 pci_enable_wake(pdev, PCI_D3hot, 1);
1557 }
1558
1559 pci_disable_device(pdev);
1560}
1561
1562#ifdef CONFIG_PM
1563static int
1564netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
1565{
1566 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1567 int retval;
1568
1569 netxen_nic_detach_func(adapter);
1570
1571 retval = pci_save_state(pdev);
1572 if (retval)
1573 return retval;
1574
1575 if (netxen_nic_wol_supported(adapter)) {
1576 pci_enable_wake(pdev, PCI_D3cold, 1);
1577 pci_enable_wake(pdev, PCI_D3hot, 1);
1578 }
1579
1580 pci_disable_device(pdev);
1581 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1582
1583 return 0;
1584}
1585
1586static int
1587netxen_nic_resume(struct pci_dev *pdev)
1588{
1589 return netxen_nic_attach_func(pdev);
1590}
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00001591#endif
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001592
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001593static int netxen_nic_open(struct net_device *netdev)
1594{
Wang Chen4cf16532008-11-12 23:38:14 -08001595 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001596 int err = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001597
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001598 if (adapter->driver_mismatch)
1599 return -EIO;
1600
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001601 err = netxen_nic_attach(adapter);
1602 if (err)
1603 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001604
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001605 err = __netxen_nic_up(adapter, netdev);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001606 if (err)
1607 goto err_out;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001608
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001609 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001610
1611 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001612
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001613err_out:
1614 netxen_nic_detach(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001615 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001616}
1617
1618/*
1619 * netxen_nic_close - Disables a network interface entry point
1620 */
1621static int netxen_nic_close(struct net_device *netdev)
1622{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001623 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001624
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001625 __netxen_nic_down(adapter, netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001626 return 0;
1627}
1628
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001629static void
1630netxen_tso_check(struct net_device *netdev,
1631 struct nx_host_tx_ring *tx_ring,
1632 struct cmd_desc_type0 *first_desc,
1633 struct sk_buff *skb)
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001634{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001635 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001636 __be16 protocol = skb->protocol;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001637 u16 flags = 0, vid = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001638 u32 producer;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001639 int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001640 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001641 struct vlan_ethhdr *vh;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001642
Harvey Harrison09640e62009-02-01 00:45:17 -08001643 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001644
1645 vh = (struct vlan_ethhdr *)skb->data;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001646 protocol = vh->h_vlan_encapsulated_proto;
1647 flags = FLAGS_VLAN_TAGGED;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001648
1649 } else if (vlan_tx_tag_present(skb)) {
1650
1651 flags = FLAGS_VLAN_OOB;
1652 vid = vlan_tx_tag_get(skb);
1653 netxen_set_tx_vlan_tci(first_desc, vid);
1654 vlan_oob = 1;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001655 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001656
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001657 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1658 skb_shinfo(skb)->gso_size > 0) {
1659
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001660 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1661
1662 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1663 first_desc->total_hdr_length = hdr_len;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001664 if (vlan_oob) {
1665 first_desc->total_hdr_length += VLAN_HLEN;
1666 first_desc->tcp_hdr_offset = VLAN_HLEN;
1667 first_desc->ip_hdr_offset = VLAN_HLEN;
1668 /* Only in case of TSO on vlan device */
1669 flags |= FLAGS_VLAN_TAGGED;
1670 }
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001671
Harvey Harrison09640e62009-02-01 00:45:17 -08001672 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001673 TX_TCP_LSO6 : TX_TCP_LSO;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001674 tso = 1;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001675
1676 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001677 u8 l4proto;
1678
Harvey Harrison09640e62009-02-01 00:45:17 -08001679 if (protocol == cpu_to_be16(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001680 l4proto = ip_hdr(skb)->protocol;
1681
1682 if (l4proto == IPPROTO_TCP)
1683 opcode = TX_TCP_PKT;
1684 else if(l4proto == IPPROTO_UDP)
1685 opcode = TX_UDP_PKT;
Harvey Harrison09640e62009-02-01 00:45:17 -08001686 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001687 l4proto = ipv6_hdr(skb)->nexthdr;
1688
1689 if (l4proto == IPPROTO_TCP)
1690 opcode = TX_TCPV6_PKT;
1691 else if(l4proto == IPPROTO_UDP)
1692 opcode = TX_UDPV6_PKT;
1693 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001694 }
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001695
1696 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
1697 first_desc->ip_hdr_offset += skb_network_offset(skb);
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001698 netxen_set_tx_flags_opcode(first_desc, flags, opcode);
1699
1700 if (!tso)
1701 return;
1702
1703 /* For LSO, we need to copy the MAC/IP/TCP headers into
1704 * the descriptor ring
1705 */
1706 producer = tx_ring->producer;
1707 copied = 0;
1708 offset = 2;
1709
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001710 if (vlan_oob) {
1711 /* Create a TSO vlan header template for firmware */
1712
1713 hwdesc = &tx_ring->desc_head[producer];
1714 tx_ring->cmd_buf_arr[producer].skb = NULL;
1715
1716 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1717 hdr_len + VLAN_HLEN);
1718
1719 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2);
1720 skb_copy_from_linear_data(skb, vh, 12);
1721 vh->h_vlan_proto = htons(ETH_P_8021Q);
1722 vh->h_vlan_TCI = htons(vid);
1723 skb_copy_from_linear_data_offset(skb, 12,
1724 (char *)vh + 16, copy_len - 16);
1725
Dhananjay Phadke545eb372009-08-05 07:34:07 +00001726 copied = copy_len - VLAN_HLEN;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001727 offset = 0;
1728
1729 producer = get_next_index(producer, tx_ring->num_desc);
1730 }
1731
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001732 while (copied < hdr_len) {
1733
1734 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1735 (hdr_len - copied));
1736
1737 hwdesc = &tx_ring->desc_head[producer];
1738 tx_ring->cmd_buf_arr[producer].skb = NULL;
1739
1740 skb_copy_from_linear_data_offset(skb, copied,
1741 (char *)hwdesc + offset, copy_len);
1742
1743 copied += copy_len;
1744 offset = 0;
1745
1746 producer = get_next_index(producer, tx_ring->num_desc);
1747 }
1748
1749 tx_ring->producer = producer;
1750 barrier();
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001751}
1752
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001753static int
1754netxen_map_tx_skb(struct pci_dev *pdev,
1755 struct sk_buff *skb, struct netxen_cmd_buffer *pbuf)
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001756{
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001757 struct netxen_skb_frag *nf;
1758 struct skb_frag_struct *frag;
1759 int i, nr_frags;
1760 dma_addr_t map;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001761
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001762 nr_frags = skb_shinfo(skb)->nr_frags;
1763 nf = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001764
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001765 map = pci_map_single(pdev, skb->data,
1766 skb_headlen(skb), PCI_DMA_TODEVICE);
1767 if (pci_dma_mapping_error(pdev, map))
1768 goto out_err;
1769
1770 nf->dma = map;
1771 nf->length = skb_headlen(skb);
1772
1773 for (i = 0; i < nr_frags; i++) {
1774 frag = &skb_shinfo(skb)->frags[i];
1775 nf = &pbuf->frag_array[i+1];
1776
1777 map = pci_map_page(pdev, frag->page, frag->page_offset,
1778 frag->size, PCI_DMA_TODEVICE);
1779 if (pci_dma_mapping_error(pdev, map))
1780 goto unwind;
1781
1782 nf->dma = map;
1783 nf->length = frag->size;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001784 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001785
1786 return 0;
1787
1788unwind:
Dhananjay Phadkecf503e82009-09-03 13:10:55 +00001789 while (--i >= 0) {
1790 nf = &pbuf->frag_array[i+1];
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001791 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
1792 }
1793
1794 nf = &pbuf->frag_array[0];
1795 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
1796
1797out_err:
1798 return -ENOMEM;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001799}
1800
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001801static inline void
1802netxen_clear_cmddesc(u64 *desc)
1803{
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001804 desc[0] = 0ULL;
1805 desc[2] = 0ULL;
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001806}
1807
Stephen Hemminger613573252009-08-31 19:50:58 +00001808static netdev_tx_t
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001809netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001810{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001811 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001812 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001813 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001814 struct netxen_skb_frag *buffrag;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001815 struct cmd_desc_type0 *hwdesc, *first_desc;
1816 struct pci_dev *pdev;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001817 int i, k;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001818
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001819 u32 producer;
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001820 int frag_count, no_of_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001821 u32 num_txd = tx_ring->num_desc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001822
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001823 frag_count = skb_shinfo(skb)->nr_frags + 1;
1824
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001825 /* 4 fragments per cmd des */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001826 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001827
Roel Kluinfa9859e2009-10-06 19:34:39 +00001828 if (unlikely(no_of_desc + 2 > netxen_tx_avail(tx_ring))) {
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001829 netif_stop_queue(netdev);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001830 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001831 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001832
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001833 producer = tx_ring->producer;
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001834 pbuf = &tx_ring->cmd_buf_arr[producer];
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001835
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001836 pdev = adapter->pdev;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001837
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001838 if (netxen_map_tx_skb(pdev, skb, pbuf))
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001839 goto drop_packet;
1840
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001841 pbuf->skb = skb;
1842 pbuf->frag_count = frag_count;
1843
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001844 first_desc = hwdesc = &tx_ring->desc_head[producer];
1845 netxen_clear_cmddesc((u64 *)hwdesc);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001846
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001847 netxen_set_tx_frags_len(first_desc, frag_count, skb->len);
1848 netxen_set_tx_port(first_desc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001849
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001850 for (i = 0; i < frag_count; i++) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001851
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001852 k = i % 4;
1853
1854 if ((k == 0) && (i > 0)) {
1855 /* move to next desc.*/
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001856 producer = get_next_index(producer, num_txd);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001857 hwdesc = &tx_ring->desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001858 netxen_clear_cmddesc((u64 *)hwdesc);
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001859 tx_ring->cmd_buf_arr[producer].skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001860 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001861
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001862 buffrag = &pbuf->frag_array[i];
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001863
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001864 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001865 switch (k) {
1866 case 0:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001867 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001868 break;
1869 case 1:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001870 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001871 break;
1872 case 2:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001873 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001874 break;
1875 case 3:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001876 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001877 break;
1878 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001879 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001880
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001881 tx_ring->producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001882
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001883 netxen_tso_check(netdev, tx_ring, first_desc, skb);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001884
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001885 netxen_nic_update_cmd_producer(adapter, tx_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001886
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001887 adapter->stats.txbytes += skb->len;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001888 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001889
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001890 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001891
1892drop_packet:
1893 adapter->stats.txdropped++;
1894 dev_kfree_skb_any(skb);
1895 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001896}
1897
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001898static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1899{
1900 struct net_device *netdev = adapter->netdev;
1901 uint32_t temp, temp_state, temp_val;
1902 int rv = 0;
1903
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001904 temp = NXRD32(adapter, CRB_TEMP_STATE);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001905
1906 temp_state = nx_get_temp_state(temp);
1907 temp_val = nx_get_temp_val(temp);
1908
1909 if (temp_state == NX_TEMP_PANIC) {
1910 printk(KERN_ALERT
1911 "%s: Device temperature %d degrees C exceeds"
1912 " maximum allowed. Hardware has been shut down.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001913 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001914 rv = 1;
1915 } else if (temp_state == NX_TEMP_WARN) {
1916 if (adapter->temp == NX_TEMP_NORMAL) {
1917 printk(KERN_ALERT
1918 "%s: Device temperature %d degrees C "
1919 "exceeds operating range."
1920 " Immediate action needed.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001921 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001922 }
1923 } else {
1924 if (adapter->temp == NX_TEMP_WARN) {
1925 printk(KERN_INFO
1926 "%s: Device temperature is now %d degrees C"
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001927 " in normal range.\n", netdev->name,
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001928 temp_val);
1929 }
1930 }
1931 adapter->temp = temp_state;
1932 return rv;
1933}
1934
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001935void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup)
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001936{
1937 struct net_device *netdev = adapter->netdev;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001938
1939 if (adapter->ahw.linkup && !linkup) {
1940 printk(KERN_INFO "%s: %s NIC Link is down\n",
1941 netxen_nic_driver_name, netdev->name);
1942 adapter->ahw.linkup = 0;
1943 if (netif_running(netdev)) {
1944 netif_carrier_off(netdev);
1945 netif_stop_queue(netdev);
1946 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001947 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001948 } else if (!adapter->ahw.linkup && linkup) {
1949 printk(KERN_INFO "%s: %s NIC Link is up\n",
1950 netxen_nic_driver_name, netdev->name);
1951 adapter->ahw.linkup = 1;
1952 if (netif_running(netdev)) {
1953 netif_carrier_on(netdev);
1954 netif_wake_queue(netdev);
1955 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001956 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001957 }
1958}
1959
1960static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1961{
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001962 u32 val, port, linkup;
1963
1964 port = adapter->physical_port;
1965
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001966 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001967 val = NXRD32(adapter, CRB_XG_STATE_P3);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001968 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1969 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001970 } else {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001971 val = NXRD32(adapter, CRB_XG_STATE);
Sucheta Chakrabortya4b751d2010-01-02 03:25:19 +00001972 val = (val >> port*8) & 0xff;
1973 linkup = (val == XG_LINK_UP);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001974 }
1975
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001976 netxen_advert_link_change(adapter, linkup);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001977}
1978
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001979static void netxen_tx_timeout(struct net_device *netdev)
1980{
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001981 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001982
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001983 if (test_bit(__NX_RESETTING, &adapter->state))
1984 return;
1985
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001986 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001987 schedule_work(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001988}
1989
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001990static void netxen_tx_timeout_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001991{
Jeff Garzik47906542007-11-23 21:23:36 -05001992 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001993 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001994
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001995 if (!netif_running(adapter->netdev))
1996 return;
1997
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001998 if (test_and_set_bit(__NX_RESETTING, &adapter->state))
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001999 return;
2000
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002001 if (++adapter->tx_timeo_cnt >= NX_MAX_TX_TIMEOUTS)
2002 goto request_reset;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07002003
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002004 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
2005 /* try to scrub interrupt */
2006 netxen_napi_disable(adapter);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07002007
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002008 adapter->netdev->trans_start = jiffies;
2009
2010 netxen_napi_enable(adapter);
2011
2012 netif_wake_queue(adapter->netdev);
2013
Dhananjay Phadkea598ae12009-09-20 19:20:38 +00002014 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha41f3e0b2010-02-02 04:16:20 +00002015 return;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002016 } else {
Dhananjay Phadkea598ae12009-09-20 19:20:38 +00002017 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002018 if (!netxen_nic_reset_context(adapter)) {
2019 adapter->netdev->trans_start = jiffies;
Dhananjay Phadkea598ae12009-09-20 19:20:38 +00002020 return;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002021 }
2022
2023 /* context reset failed, fall through for fw reset */
2024 }
2025
2026request_reset:
2027 adapter->need_fw_reset = 1;
Amit Kumar Salechaff8a3062009-10-21 19:39:02 +00002028 clear_bit(__NX_RESETTING, &adapter->state);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002029}
2030
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002031struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
2032{
2033 struct netxen_adapter *adapter = netdev_priv(netdev);
Ajit Khaparde5a4d6312009-10-07 02:45:34 +00002034 struct net_device_stats *stats = &netdev->stats;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002035
2036 memset(stats, 0, sizeof(*stats));
2037
Narender Kumar1bb482f2009-08-23 08:35:09 +00002038 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00002039 stats->tx_packets = adapter->stats.xmitfinished;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002040 stats->rx_bytes = adapter->stats.rxbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002041 stats->tx_bytes = adapter->stats.txbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002042 stats->rx_dropped = adapter->stats.rxdropped;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002043 stats->tx_dropped = adapter->stats.txdropped;
2044
2045 return stats;
2046}
2047
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07002048static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002049{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002050 struct nx_host_sds_ring *sds_ring = data;
2051 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002052 u32 status = 0;
2053
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002054 status = readl(adapter->isr_int_vec);
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002055
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002056 if (!(status & adapter->int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002057 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05302058
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002059 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002060 /* check interrupt state machine, to be sure */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002061 status = readl(adapter->crb_int_state_reg);
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002062 if (!ISR_LEGACY_INT_TRIGGERED(status))
2063 return IRQ_NONE;
2064
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002065 } else {
2066 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002067
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002068 our_int = readl(adapter->crb_int_state_reg);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002069
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002070 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002071 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002072 return IRQ_NONE;
2073
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002074 /* claim interrupt */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002075 writel((our_int & 0xffffffff), adapter->crb_int_state_reg);
2076
2077 /* clear interrupt */
2078 netxen_nic_disable_int(sds_ring);
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05302079 }
2080
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002081 writel(0xffffffff, adapter->tgt_status_reg);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002082 /* read twice to ensure write is flushed */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002083 readl(adapter->isr_int_vec);
2084 readl(adapter->isr_int_vec);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002085
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002086 napi_schedule(&sds_ring->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002087
2088 return IRQ_HANDLED;
2089}
2090
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07002091static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002092{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002093 struct nx_host_sds_ring *sds_ring = data;
2094 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002095
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002096 /* clear interrupt */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002097 writel(0xffffffff, adapter->tgt_status_reg);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002098
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002099 napi_schedule(&sds_ring->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002100 return IRQ_HANDLED;
2101}
2102
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08002103static irqreturn_t netxen_msix_intr(int irq, void *data)
2104{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002105 struct nx_host_sds_ring *sds_ring = data;
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08002106
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002107 napi_schedule(&sds_ring->napi);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08002108 return IRQ_HANDLED;
2109}
2110
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002111static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002112{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002113 struct nx_host_sds_ring *sds_ring =
2114 container_of(napi, struct nx_host_sds_ring, napi);
2115
2116 struct netxen_adapter *adapter = sds_ring->adapter;
2117
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002118 int tx_complete;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002119 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002120
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002121 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002122
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002123 work_done = netxen_process_rcv_ring(sds_ring, budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002124
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002125 if ((work_done < budget) && tx_complete) {
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002126 napi_complete(&sds_ring->napi);
Amit Kumar Salechaf2251f62009-12-05 12:23:55 +00002127 if (test_bit(__NX_DEV_UP, &adapter->state))
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00002128 netxen_nic_enable_int(sds_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002129 }
2130
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002131 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002132}
2133
2134#ifdef CONFIG_NET_POLL_CONTROLLER
2135static void netxen_nic_poll_controller(struct net_device *netdev)
2136{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002137 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002138 disable_irq(adapter->irq);
Jeff Garzik1494a812006-11-07 05:12:16 -05002139 netxen_intr(adapter->irq, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002140 enable_irq(adapter->irq);
2141}
2142#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002143
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002144static int
2145nx_incr_dev_ref_cnt(struct netxen_adapter *adapter)
2146{
2147 int count;
2148 if (netxen_api_lock(adapter))
2149 return -EIO;
2150
2151 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2152
2153 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2154
2155 netxen_api_unlock(adapter);
2156 return count;
2157}
2158
2159static int
2160nx_decr_dev_ref_cnt(struct netxen_adapter *adapter)
2161{
2162 int count;
2163 if (netxen_api_lock(adapter))
2164 return -EIO;
2165
2166 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2167 WARN_ON(count == 0);
2168
2169 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, --count);
2170
2171 if (count == 0)
2172 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_COLD);
2173
2174 netxen_api_unlock(adapter);
2175 return count;
2176}
2177
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002178static int
2179nx_dev_request_aer(struct netxen_adapter *adapter)
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002180{
2181 u32 state;
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002182 int ret = -EINVAL;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002183
2184 if (netxen_api_lock(adapter))
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002185 return ret;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002186
2187 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2188
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002189 if (state == NX_DEV_NEED_AER)
2190 ret = 0;
2191 else if (state == NX_DEV_READY) {
2192 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_AER);
2193 ret = 0;
2194 }
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002195
2196 netxen_api_unlock(adapter);
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002197 return ret;
2198}
2199
2200static int
2201nx_dev_request_reset(struct netxen_adapter *adapter)
2202{
2203 u32 state;
2204 int ret = -EINVAL;
2205
2206 if (netxen_api_lock(adapter))
2207 return ret;
2208
2209 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2210
2211 if (state == NX_DEV_NEED_RESET)
2212 ret = 0;
2213 else if (state != NX_DEV_INITALIZING && state != NX_DEV_NEED_AER) {
2214 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_RESET);
2215 ret = 0;
2216 }
2217
2218 netxen_api_unlock(adapter);
2219
2220 return ret;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002221}
2222
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002223static int
2224netxen_can_start_firmware(struct netxen_adapter *adapter)
2225{
2226 int count;
2227 int can_start = 0;
2228
2229 if (netxen_api_lock(adapter))
2230 return 0;
2231
2232 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2233
2234 if ((count < 0) || (count >= NX_MAX_PCI_FUNC))
2235 count = 0;
2236
2237 if (count == 0) {
2238 can_start = 1;
2239 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_INITALIZING);
2240 }
2241
2242 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2243
2244 netxen_api_unlock(adapter);
2245
2246 return can_start;
2247}
2248
2249static void
2250netxen_schedule_work(struct netxen_adapter *adapter,
2251 work_func_t func, int delay)
2252{
2253 INIT_DELAYED_WORK(&adapter->fw_work, func);
2254 schedule_delayed_work(&adapter->fw_work, delay);
2255}
2256
2257static void
2258netxen_cancel_fw_work(struct netxen_adapter *adapter)
2259{
2260 while (test_and_set_bit(__NX_RESETTING, &adapter->state))
2261 msleep(10);
2262
2263 cancel_delayed_work_sync(&adapter->fw_work);
2264}
2265
2266static void
2267netxen_attach_work(struct work_struct *work)
2268{
2269 struct netxen_adapter *adapter = container_of(work,
2270 struct netxen_adapter, fw_work.work);
2271 struct net_device *netdev = adapter->netdev;
2272 int err = 0;
2273
2274 if (netif_running(netdev)) {
2275 err = netxen_nic_attach(adapter);
2276 if (err)
2277 goto done;
2278
2279 err = netxen_nic_up(adapter, netdev);
2280 if (err) {
2281 netxen_nic_detach(adapter);
2282 goto done;
2283 }
2284
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002285 netxen_config_indev_addr(netdev, NETDEV_UP);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002286 }
2287
2288 netif_device_attach(netdev);
2289
2290done:
2291 adapter->fw_fail_cnt = 0;
2292 clear_bit(__NX_RESETTING, &adapter->state);
2293 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
2294}
2295
2296static void
2297netxen_fwinit_work(struct work_struct *work)
2298{
2299 struct netxen_adapter *adapter = container_of(work,
2300 struct netxen_adapter, fw_work.work);
2301 int dev_state;
2302
2303 dev_state = NXRD32(adapter, NX_CRB_DEV_STATE);
2304
2305 switch (dev_state) {
2306 case NX_DEV_COLD:
2307 case NX_DEV_READY:
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002308 if (!netxen_start_firmware(adapter)) {
2309 netxen_schedule_work(adapter, netxen_attach_work, 0);
2310 return;
2311 }
2312 break;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002313
Amit Kumar Salecha6b50ea12010-03-29 02:43:42 +00002314 case NX_DEV_NEED_RESET:
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002315 case NX_DEV_INITALIZING:
2316 if (++adapter->fw_wait_cnt < FW_POLL_THRESH) {
2317 netxen_schedule_work(adapter,
2318 netxen_fwinit_work, 2 * FW_POLL_DELAY);
2319 return;
2320 }
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002321
2322 case NX_DEV_FAILED:
2323 default:
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00002324 nx_incr_dev_ref_cnt(adapter);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002325 break;
2326 }
2327
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002328 clear_bit(__NX_RESETTING, &adapter->state);
2329}
2330
2331static void
2332netxen_detach_work(struct work_struct *work)
2333{
2334 struct netxen_adapter *adapter = container_of(work,
2335 struct netxen_adapter, fw_work.work);
2336 struct net_device *netdev = adapter->netdev;
2337 int ref_cnt, delay;
2338 u32 status;
2339
2340 netif_device_detach(netdev);
2341
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00002342 netxen_nic_down(adapter, netdev);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002343
Amit Kumar Salechae15eec22010-02-02 04:16:21 +00002344 rtnl_lock();
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002345 netxen_nic_detach(adapter);
Amit Kumar Salechae15eec22010-02-02 04:16:21 +00002346 rtnl_unlock();
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002347
2348 status = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1);
2349
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002350 if (status & NX_RCODE_FATAL_ERROR)
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00002351 goto err_ret;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002352
2353 if (adapter->temp == NX_TEMP_PANIC)
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00002354 goto err_ret;
2355
2356 ref_cnt = nx_decr_dev_ref_cnt(adapter);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002357
Amit Kumar Salecha6b50ea12010-03-29 02:43:42 +00002358 if (ref_cnt == -EIO)
2359 goto err_ret;
2360
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002361 delay = (ref_cnt == 0) ? 0 : (2 * FW_POLL_DELAY);
2362
2363 adapter->fw_wait_cnt = 0;
2364 netxen_schedule_work(adapter, netxen_fwinit_work, delay);
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00002365
2366 return;
2367
2368err_ret:
2369 clear_bit(__NX_RESETTING, &adapter->state);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002370}
2371
2372static int
2373netxen_check_health(struct netxen_adapter *adapter)
2374{
2375 u32 state, heartbit;
2376 struct net_device *netdev = adapter->netdev;
2377
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002378 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2379 if (state == NX_DEV_NEED_AER)
2380 return 0;
2381
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002382 if (netxen_nic_check_temp(adapter))
2383 goto detach;
2384
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002385 if (adapter->need_fw_reset) {
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002386 if (nx_dev_request_reset(adapter))
2387 return 0;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002388 goto detach;
2389 }
2390
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002391 /* NX_DEV_NEED_RESET, this state can be marked in two cases
2392 * 1. Tx timeout 2. Fw hang
2393 * Send request to destroy context in case of tx timeout only
2394 * and doesn't required in case of Fw hang
2395 */
Amit Kumar Salecha6a808c62009-12-08 20:40:55 +00002396 if (state == NX_DEV_NEED_RESET) {
2397 adapter->need_fw_reset = 1;
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002398 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2399 goto detach;
Amit Kumar Salecha6a808c62009-12-08 20:40:55 +00002400 }
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002401
2402 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2403 return 0;
2404
2405 heartbit = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER);
2406 if (heartbit != adapter->heartbit) {
2407 adapter->heartbit = heartbit;
2408 adapter->fw_fail_cnt = 0;
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002409 if (adapter->need_fw_reset)
2410 goto detach;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002411 return 0;
2412 }
2413
2414 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2415 return 0;
2416
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002417 if (nx_dev_request_reset(adapter))
2418 return 0;
2419
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002420 clear_bit(__NX_FW_ATTACHED, &adapter->state);
2421
2422 dev_info(&netdev->dev, "firmware hang detected\n");
2423
2424detach:
Narender Kumarcaa2dd52009-10-16 15:50:11 +00002425 if ((auto_fw_reset == AUTO_FW_RESET_ENABLED) &&
2426 !test_and_set_bit(__NX_RESETTING, &adapter->state))
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002427 netxen_schedule_work(adapter, netxen_detach_work, 0);
2428 return 1;
2429}
2430
2431static void
2432netxen_fw_poll_work(struct work_struct *work)
2433{
2434 struct netxen_adapter *adapter = container_of(work,
2435 struct netxen_adapter, fw_work.work);
2436
2437 if (test_bit(__NX_RESETTING, &adapter->state))
2438 goto reschedule;
2439
2440 if (test_bit(__NX_DEV_UP, &adapter->state)) {
2441 if (!adapter->has_link_events) {
2442
2443 netxen_nic_handle_phy_intr(adapter);
2444
2445 if (adapter->link_changed)
2446 netxen_nic_set_link_parameters(adapter);
2447 }
2448 }
2449
2450 if (netxen_check_health(adapter))
2451 return;
2452
2453reschedule:
2454 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
2455}
2456
Narender Kumarfa3ce352009-08-24 19:23:28 +00002457static ssize_t
2458netxen_store_bridged_mode(struct device *dev,
2459 struct device_attribute *attr, const char *buf, size_t len)
2460{
2461 struct net_device *net = to_net_dev(dev);
2462 struct netxen_adapter *adapter = netdev_priv(net);
2463 unsigned long new;
2464 int ret = -EINVAL;
2465
2466 if (!(adapter->capabilities & NX_FW_CAPABILITY_BDG))
2467 goto err_out;
2468
2469 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2470 goto err_out;
2471
2472 if (strict_strtoul(buf, 2, &new))
2473 goto err_out;
2474
2475 if (!netxen_config_bridged_mode(adapter, !!new))
2476 ret = len;
2477
2478err_out:
2479 return ret;
2480}
2481
2482static ssize_t
2483netxen_show_bridged_mode(struct device *dev,
2484 struct device_attribute *attr, char *buf)
2485{
2486 struct net_device *net = to_net_dev(dev);
2487 struct netxen_adapter *adapter;
2488 int bridged_mode = 0;
2489
2490 adapter = netdev_priv(net);
2491
2492 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2493 bridged_mode = !!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED);
2494
2495 return sprintf(buf, "%d\n", bridged_mode);
2496}
2497
2498static struct device_attribute dev_attr_bridged_mode = {
2499 .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
2500 .show = netxen_show_bridged_mode,
2501 .store = netxen_store_bridged_mode,
2502};
2503
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002504static ssize_t
2505netxen_store_diag_mode(struct device *dev,
2506 struct device_attribute *attr, const char *buf, size_t len)
2507{
2508 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2509 unsigned long new;
2510
2511 if (strict_strtoul(buf, 2, &new))
2512 return -EINVAL;
2513
2514 if (!!new != !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2515 adapter->flags ^= NETXEN_NIC_DIAG_ENABLED;
2516
2517 return len;
2518}
2519
2520static ssize_t
2521netxen_show_diag_mode(struct device *dev,
2522 struct device_attribute *attr, char *buf)
2523{
2524 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2525
2526 return sprintf(buf, "%d\n",
2527 !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED));
2528}
2529
2530static struct device_attribute dev_attr_diag_mode = {
2531 .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)},
2532 .show = netxen_show_diag_mode,
2533 .store = netxen_store_diag_mode,
2534};
2535
2536static int
2537netxen_sysfs_validate_crb(struct netxen_adapter *adapter,
2538 loff_t offset, size_t size)
2539{
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002540 size_t crb_size = 4;
2541
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002542 if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2543 return -EIO;
2544
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002545 if (offset < NETXEN_PCI_CRBSPACE) {
2546 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2547 return -EINVAL;
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002548
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002549 if (ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM,
2550 NETXEN_PCI_CAMQM_2M_END))
2551 crb_size = 8;
2552 else
2553 return -EINVAL;
2554 }
2555
2556 if ((size != crb_size) || (offset & (crb_size-1)))
2557 return -EINVAL;
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002558
2559 return 0;
2560}
2561
2562static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002563netxen_sysfs_read_crb(struct file *filp, struct kobject *kobj,
2564 struct bin_attribute *attr,
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002565 char *buf, loff_t offset, size_t size)
2566{
2567 struct device *dev = container_of(kobj, struct device, kobj);
2568 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2569 u32 data;
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002570 u64 qmdata;
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002571 int ret;
2572
2573 ret = netxen_sysfs_validate_crb(adapter, offset, size);
2574 if (ret != 0)
2575 return ret;
2576
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002577 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) &&
2578 ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM,
2579 NETXEN_PCI_CAMQM_2M_END)) {
2580 netxen_pci_camqm_read_2M(adapter, offset, &qmdata);
2581 memcpy(buf, &qmdata, size);
2582 } else {
2583 data = NXRD32(adapter, offset);
2584 memcpy(buf, &data, size);
2585 }
2586
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002587 return size;
2588}
2589
2590static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002591netxen_sysfs_write_crb(struct file *filp, struct kobject *kobj,
2592 struct bin_attribute *attr,
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002593 char *buf, loff_t offset, size_t size)
2594{
2595 struct device *dev = container_of(kobj, struct device, kobj);
2596 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2597 u32 data;
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002598 u64 qmdata;
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002599 int ret;
2600
2601 ret = netxen_sysfs_validate_crb(adapter, offset, size);
2602 if (ret != 0)
2603 return ret;
2604
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002605 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) &&
2606 ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM,
2607 NETXEN_PCI_CAMQM_2M_END)) {
2608 memcpy(&qmdata, buf, size);
2609 netxen_pci_camqm_write_2M(adapter, offset, qmdata);
2610 } else {
2611 memcpy(&data, buf, size);
2612 NXWR32(adapter, offset, data);
2613 }
2614
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002615 return size;
2616}
2617
2618static int
2619netxen_sysfs_validate_mem(struct netxen_adapter *adapter,
2620 loff_t offset, size_t size)
2621{
2622 if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2623 return -EIO;
2624
2625 if ((size != 8) || (offset & 0x7))
2626 return -EIO;
2627
2628 return 0;
2629}
2630
2631static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002632netxen_sysfs_read_mem(struct file *filp, struct kobject *kobj,
2633 struct bin_attribute *attr,
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002634 char *buf, loff_t offset, size_t size)
2635{
2636 struct device *dev = container_of(kobj, struct device, kobj);
2637 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2638 u64 data;
2639 int ret;
2640
2641 ret = netxen_sysfs_validate_mem(adapter, offset, size);
2642 if (ret != 0)
2643 return ret;
2644
2645 if (adapter->pci_mem_read(adapter, offset, &data))
2646 return -EIO;
2647
2648 memcpy(buf, &data, size);
2649
2650 return size;
2651}
2652
Chris Wright2c3c8be2010-05-12 18:28:57 -07002653static ssize_t netxen_sysfs_write_mem(struct file *filp, struct kobject *kobj,
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002654 struct bin_attribute *attr, char *buf,
2655 loff_t offset, size_t size)
2656{
2657 struct device *dev = container_of(kobj, struct device, kobj);
2658 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2659 u64 data;
2660 int ret;
2661
2662 ret = netxen_sysfs_validate_mem(adapter, offset, size);
2663 if (ret != 0)
2664 return ret;
2665
2666 memcpy(&data, buf, size);
2667
2668 if (adapter->pci_mem_write(adapter, offset, data))
2669 return -EIO;
2670
2671 return size;
2672}
2673
2674
2675static struct bin_attribute bin_attr_crb = {
2676 .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)},
2677 .size = 0,
2678 .read = netxen_sysfs_read_crb,
2679 .write = netxen_sysfs_write_crb,
2680};
2681
2682static struct bin_attribute bin_attr_mem = {
2683 .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)},
2684 .size = 0,
2685 .read = netxen_sysfs_read_mem,
2686 .write = netxen_sysfs_write_mem,
2687};
2688
Narender Kumarcaa2dd52009-10-16 15:50:11 +00002689
Narender Kumarfa3ce352009-08-24 19:23:28 +00002690static void
2691netxen_create_sysfs_entries(struct netxen_adapter *adapter)
2692{
2693 struct net_device *netdev = adapter->netdev;
2694 struct device *dev = &netdev->dev;
2695
2696 if (adapter->capabilities & NX_FW_CAPABILITY_BDG) {
2697 /* bridged_mode control */
2698 if (device_create_file(dev, &dev_attr_bridged_mode)) {
2699 dev_warn(&netdev->dev,
2700 "failed to create bridged_mode sysfs entry\n");
2701 }
2702 }
2703}
2704
2705static void
2706netxen_remove_sysfs_entries(struct netxen_adapter *adapter)
2707{
2708 struct net_device *netdev = adapter->netdev;
2709 struct device *dev = &netdev->dev;
2710
2711 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2712 device_remove_file(dev, &dev_attr_bridged_mode);
2713}
2714
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002715static void
2716netxen_create_diag_entries(struct netxen_adapter *adapter)
2717{
2718 struct pci_dev *pdev = adapter->pdev;
2719 struct device *dev;
2720
2721 dev = &pdev->dev;
2722 if (device_create_file(dev, &dev_attr_diag_mode))
2723 dev_info(dev, "failed to create diag_mode sysfs entry\n");
2724 if (device_create_bin_file(dev, &bin_attr_crb))
2725 dev_info(dev, "failed to create crb sysfs entry\n");
2726 if (device_create_bin_file(dev, &bin_attr_mem))
2727 dev_info(dev, "failed to create mem sysfs entry\n");
2728}
2729
2730
2731static void
2732netxen_remove_diag_entries(struct netxen_adapter *adapter)
2733{
2734 struct pci_dev *pdev = adapter->pdev;
2735 struct device *dev = &pdev->dev;
2736
2737 device_remove_file(dev, &dev_attr_diag_mode);
2738 device_remove_bin_file(dev, &bin_attr_crb);
2739 device_remove_bin_file(dev, &bin_attr_mem);
2740}
2741
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002742#ifdef CONFIG_INET
2743
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002744#define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2745
2746static int
2747netxen_destip_supported(struct netxen_adapter *adapter)
2748{
2749 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2750 return 0;
2751
2752 if (adapter->ahw.cut_through)
2753 return 0;
2754
2755 return 1;
2756}
2757
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002758static void
2759netxen_config_indev_addr(struct net_device *dev, unsigned long event)
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002760{
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002761 struct in_device *indev;
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002762 struct netxen_adapter *adapter = netdev_priv(dev);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002763
Amit Kumar Salecha3db76752009-09-09 18:12:37 -07002764 if (!netxen_destip_supported(adapter))
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002765 return;
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002766
2767 indev = in_dev_get(dev);
2768 if (!indev)
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002769 return;
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002770
2771 for_ifa(indev) {
2772 switch (event) {
2773 case NETDEV_UP:
2774 netxen_config_ipaddr(adapter,
2775 ifa->ifa_address, NX_IP_UP);
2776 break;
2777 case NETDEV_DOWN:
2778 netxen_config_ipaddr(adapter,
2779 ifa->ifa_address, NX_IP_DOWN);
2780 break;
2781 default:
2782 break;
2783 }
2784 } endfor_ifa(indev);
2785
2786 in_dev_put(indev);
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002787}
2788
2789static int netxen_netdev_event(struct notifier_block *this,
2790 unsigned long event, void *ptr)
2791{
2792 struct netxen_adapter *adapter;
2793 struct net_device *dev = (struct net_device *)ptr;
2794
2795recheck:
2796 if (dev == NULL)
2797 goto done;
2798
2799 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2800 dev = vlan_dev_real_dev(dev);
2801 goto recheck;
2802 }
2803
2804 if (!is_netxen_netdev(dev))
2805 goto done;
2806
2807 adapter = netdev_priv(dev);
2808
2809 if (!adapter)
2810 goto done;
2811
2812 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2813 goto done;
2814
2815 netxen_config_indev_addr(dev, event);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002816done:
2817 return NOTIFY_DONE;
2818}
2819
2820static int
2821netxen_inetaddr_event(struct notifier_block *this,
2822 unsigned long event, void *ptr)
2823{
2824 struct netxen_adapter *adapter;
2825 struct net_device *dev;
2826
2827 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
2828
2829 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
2830
2831recheck:
2832 if (dev == NULL || !netif_running(dev))
2833 goto done;
2834
2835 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2836 dev = vlan_dev_real_dev(dev);
2837 goto recheck;
2838 }
2839
2840 if (!is_netxen_netdev(dev))
2841 goto done;
2842
2843 adapter = netdev_priv(dev);
2844
2845 if (!adapter || !netxen_destip_supported(adapter))
2846 goto done;
2847
2848 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2849 goto done;
2850
2851 switch (event) {
2852 case NETDEV_UP:
2853 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP);
2854 break;
2855 case NETDEV_DOWN:
2856 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN);
2857 break;
2858 default:
2859 break;
2860 }
2861
2862done:
2863 return NOTIFY_DONE;
2864}
2865
2866static struct notifier_block netxen_netdev_cb = {
2867 .notifier_call = netxen_netdev_event,
2868};
2869
2870static struct notifier_block netxen_inetaddr_cb = {
2871 .notifier_call = netxen_inetaddr_event,
2872};
Randy Dunlap9feae562009-09-11 12:41:04 +00002873#else
2874static void
2875netxen_config_indev_addr(struct net_device *dev, unsigned long event)
2876{ }
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002877#endif
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002878
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002879static struct pci_error_handlers netxen_err_handler = {
2880 .error_detected = netxen_io_error_detected,
2881 .slot_reset = netxen_io_slot_reset,
2882 .resume = netxen_io_resume,
2883};
2884
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002885static struct pci_driver netxen_driver = {
2886 .name = netxen_nic_driver_name,
2887 .id_table = netxen_pci_tbl,
2888 .probe = netxen_nic_probe,
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002889 .remove = __devexit_p(netxen_nic_remove),
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002890#ifdef CONFIG_PM
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002891 .suspend = netxen_nic_suspend,
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00002892 .resume = netxen_nic_resume,
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002893#endif
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002894 .shutdown = netxen_nic_shutdown,
2895 .err_handler = &netxen_err_handler
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002896};
2897
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002898static int __init netxen_init_module(void)
2899{
Dhananjay Phadkeff4fbd42009-03-13 14:52:06 +00002900 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
2901
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002902#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002903 register_netdevice_notifier(&netxen_netdev_cb);
2904 register_inetaddr_notifier(&netxen_inetaddr_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002905#endif
Amit S. Kale184231b2007-01-22 06:52:53 -08002906 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002907}
2908
2909module_init(netxen_init_module);
2910
2911static void __exit netxen_exit_module(void)
2912{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002913 pci_unregister_driver(&netxen_driver);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002914
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002915#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002916 unregister_inetaddr_notifier(&netxen_inetaddr_cb);
2917 unregister_netdevice_notifier(&netxen_netdev_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002918#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002919}
2920
2921module_exit(netxen_exit_module);