blob: f574edff7fcb8ed9790a5281d1cff27b1b76d2d4 [file] [log] [blame]
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001/*
Dhananjay Phadke5d242f12009-02-25 15:57:56 +00002 * Copyright (C) 2003 - 2009 NetXen, Inc.
Dhananjay Phadke13af7a62009-09-11 11:28:15 +00003 * Copyright (C) 2009 - QLogic Corporation.
Amit S. Kale3d396eb2006-10-21 15:33:03 -04004 * All rights reserved.
Amit S. Kale80922fb2006-12-04 09:18:00 -08005 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -04006 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
Amit S. Kale80922fb2006-12-04 09:18:00 -080010 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040011 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Amit S. Kale80922fb2006-12-04 09:18:00 -080015 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040016 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
Amit S. Kale80922fb2006-12-04 09:18:00 -080020 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040021 * The full GNU General Public License is included in this distribution
Amit Kumar Salecha4d21fef2010-01-14 01:53:23 +000022 * in the file called "COPYING".
Amit S. Kale80922fb2006-12-04 09:18:00 -080023 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040024 */
25
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Amit S. Kalecb8011a2006-11-29 09:00:10 -080027#include <linux/vmalloc.h>
Dhananjay Phadkee98e3352009-04-07 22:50:38 +000028#include <linux/interrupt.h>
Amit S. Kale3d396eb2006-10-21 15:33:03 -040029#include "netxen_nic_hw.h"
30
31#include "netxen_nic.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040032
Jeff Garzik1494a812006-11-07 05:12:16 -050033#include <linux/dma-mapping.h>
Dhananjay Phadke391587c2009-01-14 20:48:11 -080034#include <linux/if_vlan.h>
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030035#include <net/ip.h>
Dhananjay Phadke00977782009-01-16 11:03:25 -080036#include <linux/ipv6.h>
Dhananjay Phadke6598b162009-07-26 20:07:37 +000037#include <linux/inetdevice.h>
Randy Dunlap0531d7b82009-10-26 12:09:45 +000038#include <linux/sysfs.h>
Amit Kumar Salechae87ad552009-12-08 20:40:56 +000039#include <linux/aer.h>
Jeff Garzik1494a812006-11-07 05:12:16 -050040
Amit Kumar Salecha0438a1b2010-12-31 10:55:38 -080041MODULE_DESCRIPTION("QLogic/NetXen (1/10) GbE Intelligent Ethernet Driver");
Amit S. Kale3d396eb2006-10-21 15:33:03 -040042MODULE_LICENSE("GPL");
43MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
Dhananjay Phadke7e8e5d92009-10-24 16:04:02 +000044MODULE_FIRMWARE(NX_UNIFIED_ROMIMAGE_NAME);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040045
dhananjay@netxen.comceded322007-07-19 14:41:09 +053046char netxen_nic_driver_name[] = "netxen_nic";
Dhananjay Phadkec25c0b92009-10-28 04:11:04 -070047static char netxen_nic_driver_string[] = "QLogic/NetXen Network Driver v"
Amit S. Kalecb8011a2006-11-29 09:00:10 -080048 NETXEN_NIC_LINUX_VERSIONID;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040049
Dhananjay Phadke29566402008-07-21 19:44:04 -070050static int port_mode = NETXEN_PORT_MODE_AUTO_NEG;
51
52/* Default to restricted 1G auto-neg mode */
53static int wol_port_mode = 5;
54
55static int use_msi = 1;
56
57static int use_msi_x = 1;
58
Stephen Hemmingerafdafff2009-12-18 20:13:35 -080059static int auto_fw_reset = AUTO_FW_RESET_ENABLED;
60module_param(auto_fw_reset, int, 0644);
61MODULE_PARM_DESC(auto_fw_reset,"Auto firmware reset (0=disabled, 1=enabled");
Narender Kumarcaa2dd52009-10-16 15:50:11 +000062
Amit S. Kale3d396eb2006-10-21 15:33:03 -040063static int __devinit netxen_nic_probe(struct pci_dev *pdev,
Dhananjay Phadke29566402008-07-21 19:44:04 -070064 const struct pci_device_id *ent);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040065static void __devexit netxen_nic_remove(struct pci_dev *pdev);
66static int netxen_nic_open(struct net_device *netdev);
67static int netxen_nic_close(struct net_device *netdev);
Stephen Hemminger613573252009-08-31 19:50:58 +000068static netdev_tx_t netxen_nic_xmit_frame(struct sk_buff *,
69 struct net_device *);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040070static void netxen_tx_timeout(struct net_device *netdev);
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +000071static void netxen_tx_timeout_task(struct work_struct *work);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +000072static void netxen_fw_poll_work(struct work_struct *work);
73static void netxen_schedule_work(struct netxen_adapter *adapter,
74 work_func_t func, int delay);
75static void netxen_cancel_fw_work(struct netxen_adapter *adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -070076static int netxen_nic_poll(struct napi_struct *napi, int budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040077#ifdef CONFIG_NET_POLL_CONTROLLER
78static void netxen_nic_poll_controller(struct net_device *netdev);
79#endif
Narender Kumarfa3ce352009-08-24 19:23:28 +000080
81static void netxen_create_sysfs_entries(struct netxen_adapter *adapter);
82static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter);
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +000083static void netxen_create_diag_entries(struct netxen_adapter *adapter);
84static void netxen_remove_diag_entries(struct netxen_adapter *adapter);
Narender Kumarfa3ce352009-08-24 19:23:28 +000085
Amit Kumar Salechae87ad552009-12-08 20:40:56 +000086static int nx_dev_request_aer(struct netxen_adapter *adapter);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +000087static int nx_decr_dev_ref_cnt(struct netxen_adapter *adapter);
88static int netxen_can_start_firmware(struct netxen_adapter *adapter);
89
Jeff Garzik1494a812006-11-07 05:12:16 -050090static irqreturn_t netxen_intr(int irq, void *data);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -070091static irqreturn_t netxen_msi_intr(int irq, void *data);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -080092static irqreturn_t netxen_msix_intr(int irq, void *data);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040093
Amit Kumar Salechad0725e42009-09-05 17:43:09 +000094static void netxen_config_indev_addr(struct net_device *dev, unsigned long);
stephen hemminger47fd4282011-06-08 14:54:01 +000095static struct rtnl_link_stats64 *netxen_nic_get_stats(struct net_device *dev,
96 struct rtnl_link_stats64 *stats);
stephen hemminger7e12bb02010-10-18 17:40:10 +000097static int netxen_nic_set_mac(struct net_device *netdev, void *p);
Amit Kumar Salechad0725e42009-09-05 17:43:09 +000098
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);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700128}
129
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700130static uint32_t crb_cmd_consumer[4] = {
131 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
132 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
133};
134
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700135static inline void
136netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000137 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700138{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000139 NXWRIO(adapter, tx_ring->crb_cmd_consumer, tx_ring->sw_consumer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700140}
141
Dhananjay Phadke29566402008-07-21 19:44:04 -0700142static uint32_t msi_tgt_status[8] = {
Dhananjay Phadke443be792008-03-17 19:59:48 -0700143 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700144 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
145 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
146 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
Dhananjay Phadke443be792008-03-17 19:59:48 -0700147};
148
Dhananjay Phadke29566402008-07-21 19:44:04 -0700149static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
150
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000151static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700152{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000153 struct netxen_adapter *adapter = sds_ring->adapter;
154
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000155 NXWRIO(adapter, sds_ring->crb_intr_mask, 0);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700156}
157
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000158static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700159{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000160 struct netxen_adapter *adapter = sds_ring->adapter;
161
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000162 NXWRIO(adapter, sds_ring->crb_intr_mask, 0x1);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700163
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700164 if (!NETXEN_IS_MSI_FAMILY(adapter))
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000165 NXWRIO(adapter, adapter->tgt_mask_reg, 0xfbff);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700166}
167
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000168static int
169netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count)
170{
171 int size = sizeof(struct nx_host_sds_ring) * count;
172
173 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
174
Eric Dumazet807540b2010-09-23 05:40:09 +0000175 return recv_ctx->sds_rings == NULL;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000176}
177
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000178static void
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000179netxen_free_sds_rings(struct netxen_recv_context *recv_ctx)
180{
181 if (recv_ctx->sds_rings != NULL)
182 kfree(recv_ctx->sds_rings);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000183
184 recv_ctx->sds_rings = NULL;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000185}
186
187static int
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000188netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
189{
190 int ring;
191 struct nx_host_sds_ring *sds_ring;
192 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
193
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000194 if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
Dhananjay Phadkef17443f2009-07-26 20:07:43 +0000195 return -ENOMEM;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000196
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000197 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
198 sds_ring = &recv_ctx->sds_rings[ring];
199 netif_napi_add(netdev, &sds_ring->napi,
200 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
201 }
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000202
203 return 0;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000204}
205
206static void
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000207netxen_napi_del(struct netxen_adapter *adapter)
208{
209 int ring;
210 struct nx_host_sds_ring *sds_ring;
211 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
212
213 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
214 sds_ring = &recv_ctx->sds_rings[ring];
215 netif_napi_del(&sds_ring->napi);
216 }
217
218 netxen_free_sds_rings(&adapter->recv_ctx);
219}
220
221static void
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000222netxen_napi_enable(struct netxen_adapter *adapter)
223{
224 int ring;
225 struct nx_host_sds_ring *sds_ring;
226 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
227
228 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
229 sds_ring = &recv_ctx->sds_rings[ring];
230 napi_enable(&sds_ring->napi);
231 netxen_nic_enable_int(sds_ring);
232 }
233}
234
235static void
236netxen_napi_disable(struct netxen_adapter *adapter)
237{
238 int ring;
239 struct nx_host_sds_ring *sds_ring;
240 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
241
242 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
243 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000244 netxen_nic_disable_int(sds_ring);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000245 napi_synchronize(&sds_ring->napi);
246 napi_disable(&sds_ring->napi);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000247 }
248}
249
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000250static int nx_set_dma_mask(struct netxen_adapter *adapter)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700251{
252 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000253 uint64_t mask, cmask;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700254
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000255 adapter->pci_using_dac = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700256
Yang Hongyang6afd1422009-04-06 19:01:15 -0700257 mask = DMA_BIT_MASK(32);
Yang Hongyang6afd1422009-04-06 19:01:15 -0700258 cmask = DMA_BIT_MASK(32);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000259
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000260 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000261#ifndef CONFIG_IA64
Yang Hongyang6afd1422009-04-06 19:01:15 -0700262 mask = DMA_BIT_MASK(35);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000263#endif
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000264 } else {
265 mask = DMA_BIT_MASK(39);
266 cmask = mask;
267 }
268
Dhananjay Phadke29566402008-07-21 19:44:04 -0700269 if (pci_set_dma_mask(pdev, mask) == 0 &&
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000270 pci_set_consistent_dma_mask(pdev, cmask) == 0) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700271 adapter->pci_using_dac = 1;
272 return 0;
273 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700274
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000275 return -EIO;
276}
277
278/* Update addressable range if firmware supports it */
279static int
280nx_update_dma_mask(struct netxen_adapter *adapter)
281{
282 int change, shift, err;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000283 uint64_t mask, old_mask, old_cmask;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000284 struct pci_dev *pdev = adapter->pdev;
285
286 change = 0;
287
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000288 shift = NXRD32(adapter, CRB_DMA_SHIFT);
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000289 if (shift > 32)
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000290 return 0;
291
292 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9))
293 change = 1;
294 else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4))
295 change = 1;
296
297 if (change) {
298 old_mask = pdev->dma_mask;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000299 old_cmask = pdev->dev.coherent_dma_mask;
300
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000301 mask = DMA_BIT_MASK(32+shift);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000302
303 err = pci_set_dma_mask(pdev, mask);
304 if (err)
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000305 goto err_out;
306
307 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
308
309 err = pci_set_consistent_dma_mask(pdev, mask);
310 if (err)
311 goto err_out;
312 }
313 dev_info(&pdev->dev, "using %d-bit dma mask\n", 32+shift);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700314 }
315
Dhananjay Phadke29566402008-07-21 19:44:04 -0700316 return 0;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000317
318err_out:
319 pci_set_dma_mask(pdev, old_mask);
320 pci_set_consistent_dma_mask(pdev, old_cmask);
321 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700322}
323
Dhananjay Phadke29566402008-07-21 19:44:04 -0700324static int
325netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
326{
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800327 u32 val, timeout;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700328
329 if (first_boot == 0x55555555) {
330 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000331 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800332
333 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
334 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700335
336 /* PCI bus master workaround */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000337 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700338 if (!(first_boot & 0x4)) {
339 first_boot |= 0x4;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000340 NXWR32(adapter, NETXEN_PCIE_REG(0x4), first_boot);
Amit Kumar Salecha581e8ae2010-01-07 22:10:15 +0000341 NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700342 }
343
344 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000345 first_boot = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700346 if (first_boot != 0x80000f) {
347 /* clear the register for future unloads/loads */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000348 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), 0);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800349 return -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700350 }
351
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800352 /* Start P2 boot loader */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000353 val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
354 NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800355 timeout = 0;
356 do {
357 msleep(1);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000358 val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800359
360 if (++timeout > 5000)
361 return -EIO;
362
363 } while (val == NETXEN_BDINFO_MAGIC);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700364 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800365 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700366}
367
368static void netxen_set_port_mode(struct netxen_adapter *adapter)
369{
370 u32 val, data;
371
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000372 val = adapter->ahw.board_type;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700373 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
374 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
375 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
376 data = NETXEN_PORT_MODE_802_3_AP;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000377 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700378 } else if (port_mode == NETXEN_PORT_MODE_XG) {
379 data = NETXEN_PORT_MODE_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000380 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700381 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
382 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000383 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700384 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
385 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000386 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700387 } else {
388 data = NETXEN_PORT_MODE_AUTO_NEG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000389 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700390 }
391
392 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
393 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
394 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
395 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
396 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
397 }
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000398 NXWR32(adapter, NETXEN_WOL_PORT_MODE, wol_port_mode);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700399 }
400}
401
Dhananjay Phadke29566402008-07-21 19:44:04 -0700402static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
403{
404 u32 control;
405 int pos;
406
407 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
408 if (pos) {
409 pci_read_config_dword(pdev, pos, &control);
410 if (enable)
411 control |= PCI_MSIX_FLAGS_ENABLE;
412 else
413 control = 0;
414 pci_write_config_dword(pdev, pos, control);
415 }
416}
417
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000418static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700419{
420 int i;
421
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000422 for (i = 0; i < count; i++)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700423 adapter->msix_entries[i].entry = i;
424}
425
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700426static int
427netxen_read_mac_addr(struct netxen_adapter *adapter)
428{
429 int i;
430 unsigned char *p;
Amit Kumar Salechaa03d2452010-01-14 01:53:21 +0000431 u64 mac_addr;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700432 struct net_device *netdev = adapter->netdev;
433 struct pci_dev *pdev = adapter->pdev;
434
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700435 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
436 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
437 return -EIO;
438 } else {
439 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
440 return -EIO;
441 }
442
443 p = (unsigned char *)&mac_addr;
444 for (i = 0; i < 6; i++)
445 netdev->dev_addr[i] = *(p + 5 - i);
446
447 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
Narender Kumar5d09e532009-11-20 22:08:57 +0000448 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700449
450 /* set station address */
451
Johannes Berge1749612008-10-27 15:59:26 -0700452 if (!is_valid_ether_addr(netdev->perm_addr))
453 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700454
455 return 0;
456}
457
stephen hemminger7e12bb02010-10-18 17:40:10 +0000458static int netxen_nic_set_mac(struct net_device *netdev, void *p)
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000459{
460 struct netxen_adapter *adapter = netdev_priv(netdev);
461 struct sockaddr *addr = p;
462
463 if (!is_valid_ether_addr(addr->sa_data))
464 return -EINVAL;
465
466 if (netif_running(netdev)) {
467 netif_device_detach(netdev);
468 netxen_napi_disable(adapter);
469 }
470
Narender Kumar5d09e532009-11-20 22:08:57 +0000471 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000472 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
473 adapter->macaddr_set(adapter, addr->sa_data);
474
475 if (netif_running(netdev)) {
476 netif_device_attach(netdev);
477 netxen_napi_enable(adapter);
478 }
479 return 0;
480}
481
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800482static void netxen_set_multicast_list(struct net_device *dev)
483{
484 struct netxen_adapter *adapter = netdev_priv(dev);
485
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000486 adapter->set_multi(dev);
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800487}
488
Michał Mirosław066413d2011-04-05 01:36:58 +0000489static u32 netxen_fix_features(struct net_device *dev, u32 features)
490{
491 if (!(features & NETIF_F_RXCSUM)) {
492 netdev_info(dev, "disabling LRO as RXCSUM is off\n");
493
494 features &= ~NETIF_F_LRO;
495 }
496
497 return features;
498}
499
500static int netxen_set_features(struct net_device *dev, u32 features)
501{
502 struct netxen_adapter *adapter = netdev_priv(dev);
503 int hw_lro;
504
505 if (!((dev->features ^ features) & NETIF_F_LRO))
506 return 0;
507
508 hw_lro = (features & NETIF_F_LRO) ? NETXEN_NIC_LRO_ENABLED
509 : NETXEN_NIC_LRO_DISABLED;
510
511 if (netxen_config_hw_lro(adapter, hw_lro))
512 return -EIO;
513
514 if (!(features & NETIF_F_LRO) && netxen_send_lro_cleanup(adapter))
515 return -EIO;
516
517 return 0;
518}
519
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800520static const struct net_device_ops netxen_netdev_ops = {
521 .ndo_open = netxen_nic_open,
522 .ndo_stop = netxen_nic_close,
523 .ndo_start_xmit = netxen_nic_xmit_frame,
stephen hemminger47fd4282011-06-08 14:54:01 +0000524 .ndo_get_stats64 = netxen_nic_get_stats,
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800525 .ndo_validate_addr = eth_validate_addr,
526 .ndo_set_multicast_list = netxen_set_multicast_list,
527 .ndo_set_mac_address = netxen_nic_set_mac,
528 .ndo_change_mtu = netxen_nic_change_mtu,
529 .ndo_tx_timeout = netxen_tx_timeout,
Michał Mirosław066413d2011-04-05 01:36:58 +0000530 .ndo_fix_features = netxen_fix_features,
531 .ndo_set_features = netxen_set_features,
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800532#ifdef CONFIG_NET_POLL_CONTROLLER
533 .ndo_poll_controller = netxen_nic_poll_controller,
534#endif
535};
536
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800537static void
538netxen_setup_intr(struct netxen_adapter *adapter)
539{
540 struct netxen_legacy_intr_set *legacy_intrp;
541 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000542 int err, num_msix;
543
544 if (adapter->rss_supported) {
545 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
546 MSIX_ENTRIES_PER_ADAPTER : 2;
547 } else
548 num_msix = 1;
549
550 adapter->max_sds_rings = 1;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800551
552 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800553
554 if (adapter->ahw.revision_id >= NX_P3_B0)
555 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
556 else
557 legacy_intrp = &legacy_intr[0];
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000558
559 adapter->int_vec_bit = legacy_intrp->int_vec_bit;
560 adapter->tgt_status_reg = netxen_get_ioaddr(adapter,
561 legacy_intrp->tgt_status_reg);
562 adapter->tgt_mask_reg = netxen_get_ioaddr(adapter,
563 legacy_intrp->tgt_mask_reg);
564 adapter->pci_int_reg = netxen_get_ioaddr(adapter,
565 legacy_intrp->pci_int_reg);
566 adapter->isr_int_vec = netxen_get_ioaddr(adapter, ISR_INT_VECTOR);
567
568 if (adapter->ahw.revision_id >= NX_P3_B1)
569 adapter->crb_int_state_reg = netxen_get_ioaddr(adapter,
570 ISR_INT_STATE_REG);
571 else
572 adapter->crb_int_state_reg = netxen_get_ioaddr(adapter,
573 CRB_INT_VECTOR);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800574
575 netxen_set_msix_bit(pdev, 0);
576
577 if (adapter->msix_supported) {
578
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000579 netxen_init_msix_entries(adapter, num_msix);
580 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
581 if (err == 0) {
582 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
583 netxen_set_msix_bit(pdev, 1);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800584
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000585 if (adapter->rss_supported)
586 adapter->max_sds_rings = num_msix;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800587
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000588 dev_info(&pdev->dev, "using msi-x interrupts\n");
589 return;
590 }
591
592 if (err > 0)
593 pci_disable_msix(pdev);
594
595 /* fall through for msi */
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800596 }
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000597
598 if (use_msi && !pci_enable_msi(pdev)) {
599 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000600 adapter->tgt_status_reg = netxen_get_ioaddr(adapter,
601 msi_tgt_status[adapter->ahw.pci_func]);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000602 dev_info(&pdev->dev, "using msi interrupts\n");
Dhananjay Phadkef67f3402009-05-18 21:46:40 -0700603 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000604 return;
605 }
606
607 dev_info(&pdev->dev, "using legacy interrupts\n");
608 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800609}
610
611static void
612netxen_teardown_intr(struct netxen_adapter *adapter)
613{
614 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
615 pci_disable_msix(adapter->pdev);
616 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
617 pci_disable_msi(adapter->pdev);
618}
619
620static void
621netxen_cleanup_pci_map(struct netxen_adapter *adapter)
622{
623 if (adapter->ahw.db_base != NULL)
624 iounmap(adapter->ahw.db_base);
625 if (adapter->ahw.pci_base0 != NULL)
626 iounmap(adapter->ahw.pci_base0);
627 if (adapter->ahw.pci_base1 != NULL)
628 iounmap(adapter->ahw.pci_base1);
629 if (adapter->ahw.pci_base2 != NULL)
630 iounmap(adapter->ahw.pci_base2);
631}
632
633static int
634netxen_setup_pci_map(struct netxen_adapter *adapter)
635{
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800636 void __iomem *db_ptr = NULL;
637
Dhananjay Phadke71fb62f2009-10-13 00:26:04 -0700638 resource_size_t mem_base, db_base;
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000639 unsigned long mem_len, db_len = 0;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800640
641 struct pci_dev *pdev = adapter->pdev;
642 int pci_func = adapter->ahw.pci_func;
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000643 struct netxen_hardware_context *ahw = &adapter->ahw;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800644
645 int err = 0;
646
647 /*
648 * Set the CRB window to invalid. If any register in window 0 is
649 * accessed it should set the window to 0 and then reset it to 1.
650 */
Dhananjay Phadke907fa122009-10-13 05:31:43 +0000651 adapter->ahw.crb_win = -1;
Dhananjay Phadke47abe352009-10-13 05:31:42 +0000652 adapter->ahw.ocm_win = -1;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800653
654 /* remap phys address */
655 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
656 mem_len = pci_resource_len(pdev, 0);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800657
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800658 /* 128 Meg of memory */
659 if (mem_len == NETXEN_PCI_128MB_SIZE) {
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000660
661 ahw->pci_base0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
662 ahw->pci_base1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800663 SECOND_PAGE_GROUP_SIZE);
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000664 ahw->pci_base2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800665 THIRD_PAGE_GROUP_SIZE);
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000666 if (ahw->pci_base0 == NULL || ahw->pci_base1 == NULL ||
667 ahw->pci_base2 == NULL) {
668 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
669 err = -EIO;
670 goto err_out;
671 }
672
673 ahw->pci_len0 = FIRST_PAGE_GROUP_SIZE;
674
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800675 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000676
677 ahw->pci_base1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
678 ahw->pci_base2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800679 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000680 if (ahw->pci_base1 == NULL || ahw->pci_base2 == NULL) {
681 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
682 err = -EIO;
683 goto err_out;
684 }
685
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800686 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800687
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000688 ahw->pci_base0 = pci_ioremap_bar(pdev, 0);
689 if (ahw->pci_base0 == NULL) {
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800690 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
691 return -EIO;
692 }
Amit Kumar Salechaafbe5cd2010-03-26 00:30:09 +0000693 ahw->pci_len0 = mem_len;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800694 } else {
695 return -EIO;
696 }
697
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000698 netxen_setup_hwops(adapter);
699
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800700 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
701
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +0000702 if (NX_IS_REVISION_P3P(adapter->ahw.revision_id)) {
703 adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter,
704 NETXEN_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(pci_func)));
705
706 } else if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadke47abe352009-10-13 05:31:42 +0000707 adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter,
708 NETXEN_PCIX_PS_REG(PCIE_MN_WINDOW_REG(pci_func)));
709 }
710
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800711 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
712 goto skip_doorbell;
713
714 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
715 db_len = pci_resource_len(pdev, 4);
716
717 if (db_len == 0) {
718 printk(KERN_ERR "%s: doorbell is disabled\n",
719 netxen_nic_driver_name);
720 err = -EIO;
721 goto err_out;
722 }
723
724 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
725 if (!db_ptr) {
726 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
727 netxen_nic_driver_name);
728 err = -EIO;
729 goto err_out;
730 }
731
732skip_doorbell:
733 adapter->ahw.db_base = db_ptr;
734 adapter->ahw.db_len = db_len;
735 return 0;
736
737err_out:
738 netxen_cleanup_pci_map(adapter);
739 return err;
740}
741
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000742static void
743netxen_check_options(struct netxen_adapter *adapter)
744{
745 u32 fw_major, fw_minor, fw_build;
746 char brd_name[NETXEN_MAX_SHORT_NAME];
747 char serial_num[32];
748 int i, offset, val;
749 int *ptr32;
750 struct pci_dev *pdev = adapter->pdev;
751
752 adapter->driver_mismatch = 0;
753
754 ptr32 = (int *)&serial_num;
755 offset = NX_FW_SERIAL_NUM_OFFSET;
756 for (i = 0; i < 8; i++) {
757 if (netxen_rom_fast_read(adapter, offset, &val) == -1) {
758 dev_err(&pdev->dev, "error reading board info\n");
759 adapter->driver_mismatch = 1;
760 return;
761 }
762 ptr32[i] = cpu_to_le32(val);
763 offset += sizeof(u32);
764 }
765
766 fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
767 fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
768 fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
769
770 adapter->fw_version = NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build);
771
772 if (adapter->portnum == 0) {
773 get_brd_name_by_type(adapter->ahw.board_type, brd_name);
774
Dhananjay Phadkec25c0b92009-10-28 04:11:04 -0700775 pr_info("%s: %s Board S/N %s Chip rev 0x%x\n",
776 module_name(THIS_MODULE),
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000777 brd_name, serial_num, adapter->ahw.revision_id);
778 }
779
780 if (adapter->fw_version < NETXEN_VERSION_CODE(3, 4, 216)) {
781 adapter->driver_mismatch = 1;
782 dev_warn(&pdev->dev, "firmware version %d.%d.%d unsupported\n",
783 fw_major, fw_minor, fw_build);
784 return;
785 }
786
787 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
788 i = NXRD32(adapter, NETXEN_SRE_MISC);
789 adapter->ahw.cut_through = (i & 0x8000) ? 1 : 0;
790 }
791
792 dev_info(&pdev->dev, "firmware v%d.%d.%d [%s]\n",
793 fw_major, fw_minor, fw_build,
794 adapter->ahw.cut_through ? "cut-through" : "legacy");
795
796 if (adapter->fw_version >= NETXEN_VERSION_CODE(4, 0, 222))
797 adapter->capabilities = NXRD32(adapter, CRB_FW_CAPABILITIES_1);
798
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000799 if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
800 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
801 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
802 } else if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
803 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
804 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
805 }
806
807 adapter->msix_supported = 0;
808 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
809 adapter->msix_supported = !!use_msi_x;
810 adapter->rss_supported = !!use_msi_x;
Amit Kumar Salecha083ba272010-03-29 02:43:45 +0000811 } else {
812 u32 flashed_ver = 0;
813 netxen_rom_fast_read(adapter,
814 NX_FW_VERSION_OFFSET, (int *)&flashed_ver);
815 flashed_ver = NETXEN_DECODE_VERSION(flashed_ver);
816
817 if (flashed_ver >= NETXEN_VERSION_CODE(3, 4, 336)) {
818 switch (adapter->ahw.board_type) {
819 case NETXEN_BRDTYPE_P2_SB31_10G:
820 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
821 adapter->msix_supported = !!use_msi_x;
822 adapter->rss_supported = !!use_msi_x;
823 break;
824 default:
825 break;
826 }
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000827 }
828 }
829
830 adapter->num_txd = MAX_CMD_DESCRIPTORS;
831
832 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
833 adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS;
834 adapter->max_rds_rings = 3;
835 } else {
836 adapter->num_lro_rxd = 0;
837 adapter->max_rds_rings = 2;
838 }
839}
840
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800841static int
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000842netxen_start_firmware(struct netxen_adapter *adapter)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800843{
844 int val, err, first_boot;
845 struct pci_dev *pdev = adapter->pdev;
846
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000847 /* required for NX2031 dummy dma */
848 err = nx_set_dma_mask(adapter);
849 if (err)
850 return err;
851
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000852 if (!netxen_can_start_firmware(adapter))
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000853 goto wait_init;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000854
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000855 first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800856
857 err = netxen_check_hw_init(adapter, first_boot);
858 if (err) {
859 dev_err(&pdev->dev, "error in init HW init sequence\n");
860 return err;
861 }
862
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000863 netxen_request_firmware(adapter);
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000864
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000865 err = netxen_need_fw_reset(adapter);
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000866 if (err < 0)
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000867 goto err_out;
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000868 if (err == 0)
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +0000869 goto wait_init;
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000870
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800871 if (first_boot != 0x55555555) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000872 NXWR32(adapter, CRB_CMDPEG_STATE, 0);
Amit Kumar Salecha0be367b2009-10-16 15:50:08 +0000873 netxen_pinit_from_rom(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800874 msleep(1);
875 }
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000876
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000877 NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000878 NXWR32(adapter, NETXEN_PEG_HALT_STATUS1, 0);
879 NXWR32(adapter, NETXEN_PEG_HALT_STATUS2, 0);
880
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000881 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
882 netxen_set_port_mode(adapter);
883
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000884 err = netxen_load_firmware(adapter);
885 if (err)
886 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800887
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000888 netxen_release_firmware(adapter);
889
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800890 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
891
892 /* Initialize multicast addr pool owners */
893 val = 0x7654;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000894 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800895 val |= 0x0f000000;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000896 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800897
898 }
899
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000900 err = netxen_init_dummy_dma(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800901 if (err)
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000902 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800903
904 /*
905 * Tell the hardware our version number.
906 */
907 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
908 | ((_NETXEN_NIC_LINUX_MINOR << 8))
909 | (_NETXEN_NIC_LINUX_SUBVERSION);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000910 NXWR32(adapter, CRB_DRIVER_VERSION, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800911
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000912wait_init:
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800913 /* Handshake with the card before we register the devices. */
914 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
915 if (err) {
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000916 netxen_free_dummy_dma(adapter);
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000917 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800918 }
919
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +0000920 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_READY);
921
Dhananjay Phadke68b3cae2009-07-26 20:07:36 +0000922 nx_update_dma_mask(adapter);
923
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000924 netxen_check_options(adapter);
Dhananjay Phadke68b3cae2009-07-26 20:07:36 +0000925
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +0000926 adapter->need_fw_reset = 0;
927
Dhananjay Phadkeec5c50c2009-09-11 11:28:13 +0000928 /* fall through and release firmware */
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000929
930err_out:
931 netxen_release_firmware(adapter);
932 return err;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800933}
934
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000935static int
936netxen_nic_request_irq(struct netxen_adapter *adapter)
937{
938 irq_handler_t handler;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000939 struct nx_host_sds_ring *sds_ring;
940 int err, ring;
941
Javier Martinez Canillasab392d22011-03-28 16:27:31 +0000942 unsigned long flags = 0;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000943 struct net_device *netdev = adapter->netdev;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000944 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000945
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000946 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
947 handler = netxen_msix_intr;
948 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
949 handler = netxen_msi_intr;
950 else {
951 flags |= IRQF_SHARED;
952 handler = netxen_intr;
953 }
954 adapter->irq = netdev->irq;
955
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000956 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
957 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000958 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000959 err = request_irq(sds_ring->irq, handler,
960 flags, sds_ring->name, sds_ring);
961 if (err)
962 return err;
963 }
964
965 return 0;
966}
967
968static void
969netxen_nic_free_irq(struct netxen_adapter *adapter)
970{
971 int ring;
972 struct nx_host_sds_ring *sds_ring;
973
974 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
975
976 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
977 sds_ring = &recv_ctx->sds_rings[ring];
978 free_irq(sds_ring->irq, sds_ring);
979 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000980}
981
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000982static void
983netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter)
984{
985 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
986 adapter->coal.normal.data.rx_time_us =
987 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
988 adapter->coal.normal.data.rx_packets =
989 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
990 adapter->coal.normal.data.tx_time_us =
991 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US;
992 adapter->coal.normal.data.tx_packets =
993 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS;
994}
995
Amit Kumar Salecha6f771412009-12-05 12:23:54 +0000996/* with rtnl_lock */
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000997static int
Amit Kumar Salecha6f771412009-12-05 12:23:54 +0000998__netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000999{
1000 int err;
1001
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +00001002 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1003 return -EIO;
1004
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001005 err = adapter->init_port(adapter, adapter->physical_port);
1006 if (err) {
1007 printk(KERN_ERR "%s: Failed to initialize port %d\n",
1008 netxen_nic_driver_name, adapter->portnum);
1009 return err;
1010 }
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +00001011 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
Narender Kumar5d09e532009-11-20 22:08:57 +00001012 adapter->macaddr_set(adapter, adapter->mac_addr);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001013
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +00001014 adapter->set_multi(netdev);
1015 adapter->set_mtu(adapter, netdev->mtu);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001016
1017 adapter->ahw.linkup = 0;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001018
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001019 if (adapter->max_sds_rings > 1)
1020 netxen_config_rss(adapter, 1);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001021
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +00001022 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1023 netxen_config_intr_coalesce(adapter);
1024
Sucheta Chakrabortye4baaf72011-01-02 21:58:44 +00001025 if (netdev->features & NETIF_F_LRO)
Narender Kumar1bb482f2009-08-23 08:35:09 +00001026 netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED);
1027
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001028 netxen_napi_enable(adapter);
1029
Dhananjay Phadke5103c9f2009-04-28 15:29:09 +00001030 if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001031 netxen_linkevent_request(adapter, 1);
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +00001032 else
1033 netxen_nic_set_link_parameters(adapter);
1034
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001035 set_bit(__NX_DEV_UP, &adapter->state);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001036 return 0;
1037}
1038
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001039/* Usage: During resume and firmware recovery module.*/
1040
1041static inline int
1042netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
1043{
1044 int err = 0;
1045
1046 rtnl_lock();
1047 if (netif_running(netdev))
1048 err = __netxen_nic_up(adapter, netdev);
1049 rtnl_unlock();
1050
1051 return err;
1052}
1053
1054/* with rtnl_lock */
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001055static void
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001056__netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001057{
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +00001058 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1059 return;
1060
Amit Kumar Salechaf2251f62009-12-05 12:23:55 +00001061 if (!test_and_clear_bit(__NX_DEV_UP, &adapter->state))
1062 return;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001063
Amit Kumar Salechaf2251f62009-12-05 12:23:55 +00001064 smp_mb();
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001065 spin_lock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001066 netif_carrier_off(netdev);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001067 netif_tx_disable(netdev);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001068
Sony Chackod478af02011-03-10 23:50:02 +00001069 if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)
1070 netxen_linkevent_request(adapter, 0);
1071
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001072 if (adapter->stop_port)
1073 adapter->stop_port(adapter);
1074
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +00001075 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1076 netxen_p3_free_mac_list(adapter);
1077
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001078 adapter->set_promisc(adapter, NETXEN_NIU_NON_PROMISC_MODE);
1079
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +00001080 netxen_napi_disable(adapter);
1081
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001082 netxen_release_tx_buffers(adapter);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001083 spin_unlock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001084}
1085
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001086/* Usage: During suspend and firmware recovery module */
1087
1088static inline void
1089netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
1090{
1091 rtnl_lock();
1092 if (netif_running(netdev))
1093 __netxen_nic_down(adapter, netdev);
1094 rtnl_unlock();
1095
1096}
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001097
1098static int
1099netxen_nic_attach(struct netxen_adapter *adapter)
1100{
1101 struct net_device *netdev = adapter->netdev;
1102 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +00001103 int err, ring;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001104 struct nx_host_rds_ring *rds_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001105 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001106
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001107 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
1108 return 0;
1109
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001110 err = netxen_init_firmware(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +00001111 if (err)
1112 return err;
1113
1114 err = netxen_napi_add(adapter, netdev);
1115 if (err)
1116 return err;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001117
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001118 err = netxen_alloc_sw_resources(adapter);
1119 if (err) {
1120 printk(KERN_ERR "%s: Error in setting sw resources\n",
1121 netdev->name);
1122 return err;
1123 }
1124
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001125 err = netxen_alloc_hw_resources(adapter);
1126 if (err) {
1127 printk(KERN_ERR "%s: Error in setting hw resources\n",
1128 netdev->name);
1129 goto err_out_free_sw;
1130 }
1131
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001132 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001133 tx_ring = adapter->tx_ring;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001134 tx_ring->crb_cmd_producer = netxen_get_ioaddr(adapter,
1135 crb_cmd_producer[adapter->portnum]);
1136 tx_ring->crb_cmd_consumer = netxen_get_ioaddr(adapter,
1137 crb_cmd_consumer[adapter->portnum]);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001138
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001139 tx_ring->producer = 0;
1140 tx_ring->sw_consumer = 0;
1141
1142 netxen_nic_update_cmd_producer(adapter, tx_ring);
1143 netxen_nic_update_cmd_consumer(adapter, tx_ring);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001144 }
1145
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001146 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1147 rds_ring = &adapter->recv_ctx.rds_rings[ring];
1148 netxen_post_rx_buffers(adapter, ring, rds_ring);
1149 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001150
1151 err = netxen_nic_request_irq(adapter);
1152 if (err) {
1153 dev_err(&pdev->dev, "%s: failed to setup interrupt\n",
1154 netdev->name);
1155 goto err_out_free_rxbuf;
1156 }
1157
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +00001158 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1159 netxen_nic_init_coalesce_defaults(adapter);
1160
Narender Kumarfa3ce352009-08-24 19:23:28 +00001161 netxen_create_sysfs_entries(adapter);
1162
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001163 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1164 return 0;
1165
1166err_out_free_rxbuf:
1167 netxen_release_rx_buffers(adapter);
1168 netxen_free_hw_resources(adapter);
1169err_out_free_sw:
1170 netxen_free_sw_resources(adapter);
1171 return err;
1172}
1173
1174static void
1175netxen_nic_detach(struct netxen_adapter *adapter)
1176{
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001177 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1178 return;
1179
Narender Kumarfa3ce352009-08-24 19:23:28 +00001180 netxen_remove_sysfs_entries(adapter);
1181
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001182 netxen_free_hw_resources(adapter);
Dhananjay Phadkecf981ff2009-07-17 15:27:06 +00001183 netxen_release_rx_buffers(adapter);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +00001184 netxen_nic_free_irq(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +00001185 netxen_napi_del(adapter);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001186 netxen_free_sw_resources(adapter);
1187
1188 adapter->is_up = 0;
1189}
1190
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001191int
1192netxen_nic_reset_context(struct netxen_adapter *adapter)
1193{
1194 int err = 0;
1195 struct net_device *netdev = adapter->netdev;
1196
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001197 if (test_and_set_bit(__NX_RESETTING, &adapter->state))
1198 return -EBUSY;
1199
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001200 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
1201
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001202 netif_device_detach(netdev);
1203
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001204 if (netif_running(netdev))
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001205 __netxen_nic_down(adapter, netdev);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001206
1207 netxen_nic_detach(adapter);
1208
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001209 if (netif_running(netdev)) {
1210 err = netxen_nic_attach(adapter);
1211 if (!err)
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001212 err = __netxen_nic_up(adapter, netdev);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001213
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001214 if (err)
1215 goto done;
1216 }
1217
1218 netif_device_attach(netdev);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001219 }
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001220
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001221done:
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001222 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001223 return err;
1224}
1225
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001226static int
1227netxen_setup_netdev(struct netxen_adapter *adapter,
1228 struct net_device *netdev)
1229{
1230 int err = 0;
1231 struct pci_dev *pdev = adapter->pdev;
1232
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001233 adapter->mc_enabled = 0;
1234 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1235 adapter->max_mc_count = 38;
1236 else
1237 adapter->max_mc_count = 16;
1238
1239 netdev->netdev_ops = &netxen_netdev_ops;
Rajesh Borundia7a9905e2010-10-18 02:03:41 +00001240 netdev->watchdog_timeo = 5*HZ;
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001241
1242 netxen_nic_change_mtu(netdev, netdev->mtu);
1243
1244 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
1245
Michał Mirosław066413d2011-04-05 01:36:58 +00001246 netdev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO |
1247 NETIF_F_RXCSUM;
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001248
Michał Mirosław066413d2011-04-05 01:36:58 +00001249 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1250 netdev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6;
1251
1252 netdev->vlan_features |= netdev->hw_features;
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001253
1254 if (adapter->pci_using_dac) {
1255 netdev->features |= NETIF_F_HIGHDMA;
1256 netdev->vlan_features |= NETIF_F_HIGHDMA;
1257 }
1258
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001259 if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX)
Michał Mirosław066413d2011-04-05 01:36:58 +00001260 netdev->hw_features |= NETIF_F_HW_VLAN_TX;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001261
Narender Kumar1bb482f2009-08-23 08:35:09 +00001262 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
Michał Mirosław066413d2011-04-05 01:36:58 +00001263 netdev->hw_features |= NETIF_F_LRO;
1264
1265 netdev->features |= netdev->hw_features;
Narender Kumar1bb482f2009-08-23 08:35:09 +00001266
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001267 netdev->irq = adapter->msix_entries[0].vector;
1268
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001269 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001270
1271 if (netxen_read_mac_addr(adapter))
1272 dev_warn(&pdev->dev, "failed to read mac addr\n");
1273
1274 netif_carrier_off(netdev);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001275
1276 err = register_netdev(netdev);
1277 if (err) {
1278 dev_err(&pdev->dev, "failed to register net device\n");
1279 return err;
1280 }
1281
1282 return 0;
1283}
1284
amit salechadce87b92010-10-18 02:03:42 +00001285#ifdef CONFIG_PCIEAER
1286static void netxen_mask_aer_correctable(struct netxen_adapter *adapter)
1287{
1288 struct pci_dev *pdev = adapter->pdev;
1289 struct pci_dev *root = pdev->bus->self;
1290 u32 aer_pos;
1291
1292 if (adapter->ahw.board_type != NETXEN_BRDTYPE_P3_4_GB_MM &&
1293 adapter->ahw.board_type != NETXEN_BRDTYPE_P3_10G_TP)
1294 return;
1295
1296 if (root->pcie_type != PCI_EXP_TYPE_ROOT_PORT)
1297 return;
1298
1299 aer_pos = pci_find_ext_capability(root, PCI_EXT_CAP_ID_ERR);
1300 if (!aer_pos)
1301 return;
1302
1303 pci_write_config_dword(root, aer_pos + PCI_ERR_COR_MASK, 0xffff);
1304}
1305#endif
1306
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001307static int __devinit
1308netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1309{
1310 struct net_device *netdev = NULL;
1311 struct netxen_adapter *adapter = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001312 int i = 0, err;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001313 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001314 uint8_t revision_id;
Rajesh Borundia5a6f95e2010-11-23 03:08:27 +00001315 u32 val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001316
Eric W. Biederman688328c2010-03-17 22:24:39 +00001317 if (pdev->revision >= NX_P3_A0 && pdev->revision <= NX_P3_B1) {
1318 pr_warning("%s: chip revisions between 0x%x-0x%x "
Dhananjay Phadke11d89d62008-08-08 00:08:45 -07001319 "will not be enabled.\n",
Dhananjay Phadkec25c0b92009-10-28 04:11:04 -07001320 module_name(THIS_MODULE), NX_P3_A0, NX_P3_B1);
Dhananjay Phadke11d89d62008-08-08 00:08:45 -07001321 return -ENODEV;
1322 }
1323
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001324 if ((err = pci_enable_device(pdev)))
1325 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001326
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001327 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1328 err = -ENODEV;
1329 goto err_out_disable_pdev;
1330 }
1331
1332 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
1333 goto err_out_disable_pdev;
1334
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00001335 if (NX_IS_REVISION_P3(pdev->revision))
1336 pci_enable_pcie_error_reporting(pdev);
1337
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001338 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001339
1340 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
1341 if(!netdev) {
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001342 dev_err(&pdev->dev, "failed to allocate net_device\n");
1343 err = -ENOMEM;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001344 goto err_out_free_res;
1345 }
1346
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001347 SET_NETDEV_DEV(netdev, &pdev->dev);
1348
Wang Chen4cf16532008-11-12 23:38:14 -08001349 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001350 adapter->netdev = netdev;
1351 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001352 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001353
1354 revision_id = pdev->revision;
1355 adapter->ahw.revision_id = revision_id;
1356
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001357 rwlock_init(&adapter->ahw.crb_lock);
1358 spin_lock_init(&adapter->ahw.mem_lock);
1359
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001360 spin_lock_init(&adapter->tx_clean_lock);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +00001361 INIT_LIST_HEAD(&adapter->mac_list);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001362
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001363 err = netxen_setup_pci_map(adapter);
1364 if (err)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001365 goto err_out_free_netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001366
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +05301367 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001368 adapter->portnum = pci_func_id;
1369
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001370 err = netxen_nic_get_board_info(adapter);
1371 if (err) {
1372 dev_err(&pdev->dev, "Error getting board config info.\n");
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001373 goto err_out_iounmap;
1374 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001375
amit salechadce87b92010-10-18 02:03:42 +00001376#ifdef CONFIG_PCIEAER
1377 netxen_mask_aer_correctable(adapter);
1378#endif
1379
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001380 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001381 switch (adapter->ahw.board_type) {
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001382 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1383 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1384 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001385 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001386 break;
1387 default:
1388 break;
1389 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001390
Amit Kumar Salechae933d012011-07-20 00:08:53 +00001391 err = netxen_check_flash_fw_compatibility(adapter);
1392 if (err)
1393 goto err_out_iounmap;
1394
Rajesh Borundia5a6f95e2010-11-23 03:08:27 +00001395 if (adapter->portnum == 0) {
1396 val = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
1397 if (val != 0xffffffff && val != 0) {
Rajesh Borundia683b65f2010-10-26 22:51:50 +00001398 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, 0);
1399 adapter->need_fw_reset = 1;
1400 }
1401 }
1402
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001403 err = netxen_start_firmware(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001404 if (err)
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00001405 goto err_out_decr_ref;
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001406
Dhananjay Phadke29566402008-07-21 19:44:04 -07001407 /*
1408 * See if the firmware gave us a virtual-physical port mapping.
1409 */
1410 adapter->physical_port = adapter->portnum;
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001411 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001412 i = NXRD32(adapter, CRB_V2P(adapter->portnum));
Dhananjay Phadke044fad02009-02-24 03:42:59 -08001413 if (i != 0x55555555)
1414 adapter->physical_port = i;
1415 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001416
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001417 netxen_nic_clear_stats(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001418
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001419 netxen_setup_intr(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001420
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001421 err = netxen_setup_netdev(adapter, netdev);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001422 if (err)
Dhananjay Phadke29566402008-07-21 19:44:04 -07001423 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001424
1425 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001426
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001427 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
1428
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001429 switch (adapter->ahw.port_type) {
Dhananjay Phadke29566402008-07-21 19:44:04 -07001430 case NETXEN_NIC_GBE:
1431 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1432 adapter->netdev->name);
1433 break;
1434 case NETXEN_NIC_XGBE:
1435 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1436 adapter->netdev->name);
1437 break;
1438 }
1439
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00001440 netxen_create_diag_entries(adapter);
1441
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001442 return 0;
1443
Dhananjay Phadke29566402008-07-21 19:44:04 -07001444err_out_disable_msi:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001445 netxen_teardown_intr(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001446
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001447 netxen_free_dummy_dma(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001448
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00001449err_out_decr_ref:
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001450 nx_decr_dev_ref_cnt(adapter);
1451
Dhananjay Phadke29566402008-07-21 19:44:04 -07001452err_out_iounmap:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001453 netxen_cleanup_pci_map(adapter);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001454
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001455err_out_free_netdev:
1456 free_netdev(netdev);
1457
1458err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001459 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001460
1461err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001462 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001463 pci_disable_device(pdev);
1464 return err;
1465}
1466
1467static void __devexit netxen_nic_remove(struct pci_dev *pdev)
1468{
1469 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001470 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001471
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001472 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001473 if (adapter == NULL)
1474 return;
1475
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001476 netdev = adapter->netdev;
1477
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001478 netxen_cancel_fw_work(adapter);
1479
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301480 unregister_netdev(netdev);
1481
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001482 cancel_work_sync(&adapter->tx_timeout_task);
1483
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001484 netxen_nic_detach(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001485
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001486 nx_decr_dev_ref_cnt(adapter);
1487
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001488 if (adapter->portnum == 0)
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001489 netxen_free_dummy_dma(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301490
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001491 clear_bit(__NX_RESETTING, &adapter->state);
1492
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001493 netxen_teardown_intr(adapter);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301494
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00001495 netxen_remove_diag_entries(adapter);
1496
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001497 netxen_cleanup_pci_map(adapter);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001498
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001499 netxen_release_firmware(adapter);
1500
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00001501 if (NX_IS_REVISION_P3(pdev->revision))
1502 pci_disable_pcie_error_reporting(pdev);
1503
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001504 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301505 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001506 pci_set_drvdata(pdev, NULL);
1507
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001508 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001509}
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00001510
1511static void netxen_nic_detach_func(struct netxen_adapter *adapter)
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001512{
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001513 struct net_device *netdev = adapter->netdev;
1514
1515 netif_device_detach(netdev);
1516
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001517 netxen_cancel_fw_work(adapter);
1518
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001519 if (netif_running(netdev))
1520 netxen_nic_down(adapter, netdev);
1521
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001522 cancel_work_sync(&adapter->tx_timeout_task);
1523
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001524 netxen_nic_detach(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001525
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001526 if (adapter->portnum == 0)
1527 netxen_free_dummy_dma(adapter);
1528
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001529 nx_decr_dev_ref_cnt(adapter);
1530
1531 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001532}
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001533
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00001534static int netxen_nic_attach_func(struct pci_dev *pdev)
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001535{
1536 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1537 struct net_device *netdev = adapter->netdev;
1538 int err;
1539
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001540 err = pci_enable_device(pdev);
1541 if (err)
1542 return err;
1543
Amit Kumar Salechabc86fcb2009-12-08 20:40:54 +00001544 pci_set_power_state(pdev, PCI_D0);
1545 pci_set_master(pdev);
1546 pci_restore_state(pdev);
1547
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001548 adapter->ahw.crb_win = -1;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001549 adapter->ahw.ocm_win = -1;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001550
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001551 err = netxen_start_firmware(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001552 if (err) {
1553 dev_err(&pdev->dev, "failed to start firmware\n");
1554 return err;
1555 }
1556
1557 if (netif_running(netdev)) {
1558 err = netxen_nic_attach(adapter);
1559 if (err)
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001560 goto err_out;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001561
1562 err = netxen_nic_up(adapter, netdev);
1563 if (err)
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001564 goto err_out_detach;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001565
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00001566 netxen_config_indev_addr(netdev, NETDEV_UP);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001567 }
1568
Amit Kumar Salechabc86fcb2009-12-08 20:40:54 +00001569 netif_device_attach(netdev);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001570 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
Dhananjay Phadke07653aa2009-09-20 19:20:39 +00001571 return 0;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001572
1573err_out_detach:
1574 netxen_nic_detach(adapter);
1575err_out:
1576 nx_decr_dev_ref_cnt(adapter);
1577 return err;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001578}
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00001579
1580static pci_ers_result_t netxen_io_error_detected(struct pci_dev *pdev,
1581 pci_channel_state_t state)
1582{
1583 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1584
1585 if (state == pci_channel_io_perm_failure)
1586 return PCI_ERS_RESULT_DISCONNECT;
1587
1588 if (nx_dev_request_aer(adapter))
1589 return PCI_ERS_RESULT_RECOVERED;
1590
1591 netxen_nic_detach_func(adapter);
1592
1593 pci_disable_device(pdev);
1594
1595 return PCI_ERS_RESULT_NEED_RESET;
1596}
1597
1598static pci_ers_result_t netxen_io_slot_reset(struct pci_dev *pdev)
1599{
1600 int err = 0;
1601
1602 err = netxen_nic_attach_func(pdev);
1603
1604 return err ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED;
1605}
1606
1607static void netxen_io_resume(struct pci_dev *pdev)
1608{
1609 pci_cleanup_aer_uncorrect_error_status(pdev);
1610}
1611
1612static void netxen_nic_shutdown(struct pci_dev *pdev)
1613{
1614 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1615
1616 netxen_nic_detach_func(adapter);
1617
1618 if (pci_save_state(pdev))
1619 return;
1620
1621 if (netxen_nic_wol_supported(adapter)) {
1622 pci_enable_wake(pdev, PCI_D3cold, 1);
1623 pci_enable_wake(pdev, PCI_D3hot, 1);
1624 }
1625
1626 pci_disable_device(pdev);
1627}
1628
1629#ifdef CONFIG_PM
1630static int
1631netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
1632{
1633 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1634 int retval;
1635
1636 netxen_nic_detach_func(adapter);
1637
1638 retval = pci_save_state(pdev);
1639 if (retval)
1640 return retval;
1641
1642 if (netxen_nic_wol_supported(adapter)) {
1643 pci_enable_wake(pdev, PCI_D3cold, 1);
1644 pci_enable_wake(pdev, PCI_D3hot, 1);
1645 }
1646
1647 pci_disable_device(pdev);
1648 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1649
1650 return 0;
1651}
1652
1653static int
1654netxen_nic_resume(struct pci_dev *pdev)
1655{
1656 return netxen_nic_attach_func(pdev);
1657}
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00001658#endif
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001659
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001660static int netxen_nic_open(struct net_device *netdev)
1661{
Wang Chen4cf16532008-11-12 23:38:14 -08001662 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001663 int err = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001664
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001665 if (adapter->driver_mismatch)
1666 return -EIO;
1667
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001668 err = netxen_nic_attach(adapter);
1669 if (err)
1670 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001671
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001672 err = __netxen_nic_up(adapter, netdev);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001673 if (err)
1674 goto err_out;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001675
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001676 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001677
1678 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001679
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001680err_out:
1681 netxen_nic_detach(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001682 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001683}
1684
1685/*
1686 * netxen_nic_close - Disables a network interface entry point
1687 */
1688static int netxen_nic_close(struct net_device *netdev)
1689{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001690 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001691
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00001692 __netxen_nic_down(adapter, netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001693 return 0;
1694}
1695
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001696static void
1697netxen_tso_check(struct net_device *netdev,
1698 struct nx_host_tx_ring *tx_ring,
1699 struct cmd_desc_type0 *first_desc,
1700 struct sk_buff *skb)
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001701{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001702 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001703 __be16 protocol = skb->protocol;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001704 u16 flags = 0, vid = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001705 u32 producer;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001706 int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001707 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001708 struct vlan_ethhdr *vh;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001709
Harvey Harrison09640e62009-02-01 00:45:17 -08001710 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001711
1712 vh = (struct vlan_ethhdr *)skb->data;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001713 protocol = vh->h_vlan_encapsulated_proto;
1714 flags = FLAGS_VLAN_TAGGED;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001715
1716 } else if (vlan_tx_tag_present(skb)) {
1717
1718 flags = FLAGS_VLAN_OOB;
1719 vid = vlan_tx_tag_get(skb);
1720 netxen_set_tx_vlan_tci(first_desc, vid);
1721 vlan_oob = 1;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001722 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001723
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001724 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1725 skb_shinfo(skb)->gso_size > 0) {
1726
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001727 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1728
1729 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1730 first_desc->total_hdr_length = hdr_len;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001731 if (vlan_oob) {
1732 first_desc->total_hdr_length += VLAN_HLEN;
1733 first_desc->tcp_hdr_offset = VLAN_HLEN;
1734 first_desc->ip_hdr_offset = VLAN_HLEN;
1735 /* Only in case of TSO on vlan device */
1736 flags |= FLAGS_VLAN_TAGGED;
1737 }
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001738
Harvey Harrison09640e62009-02-01 00:45:17 -08001739 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001740 TX_TCP_LSO6 : TX_TCP_LSO;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001741 tso = 1;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001742
1743 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001744 u8 l4proto;
1745
Harvey Harrison09640e62009-02-01 00:45:17 -08001746 if (protocol == cpu_to_be16(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001747 l4proto = ip_hdr(skb)->protocol;
1748
1749 if (l4proto == IPPROTO_TCP)
1750 opcode = TX_TCP_PKT;
1751 else if(l4proto == IPPROTO_UDP)
1752 opcode = TX_UDP_PKT;
Harvey Harrison09640e62009-02-01 00:45:17 -08001753 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001754 l4proto = ipv6_hdr(skb)->nexthdr;
1755
1756 if (l4proto == IPPROTO_TCP)
1757 opcode = TX_TCPV6_PKT;
1758 else if(l4proto == IPPROTO_UDP)
1759 opcode = TX_UDPV6_PKT;
1760 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001761 }
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001762
1763 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
1764 first_desc->ip_hdr_offset += skb_network_offset(skb);
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001765 netxen_set_tx_flags_opcode(first_desc, flags, opcode);
1766
1767 if (!tso)
1768 return;
1769
1770 /* For LSO, we need to copy the MAC/IP/TCP headers into
1771 * the descriptor ring
1772 */
1773 producer = tx_ring->producer;
1774 copied = 0;
1775 offset = 2;
1776
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001777 if (vlan_oob) {
1778 /* Create a TSO vlan header template for firmware */
1779
1780 hwdesc = &tx_ring->desc_head[producer];
1781 tx_ring->cmd_buf_arr[producer].skb = NULL;
1782
1783 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1784 hdr_len + VLAN_HLEN);
1785
1786 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2);
1787 skb_copy_from_linear_data(skb, vh, 12);
1788 vh->h_vlan_proto = htons(ETH_P_8021Q);
1789 vh->h_vlan_TCI = htons(vid);
1790 skb_copy_from_linear_data_offset(skb, 12,
1791 (char *)vh + 16, copy_len - 16);
1792
Dhananjay Phadke545eb372009-08-05 07:34:07 +00001793 copied = copy_len - VLAN_HLEN;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001794 offset = 0;
1795
1796 producer = get_next_index(producer, tx_ring->num_desc);
1797 }
1798
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001799 while (copied < hdr_len) {
1800
1801 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1802 (hdr_len - copied));
1803
1804 hwdesc = &tx_ring->desc_head[producer];
1805 tx_ring->cmd_buf_arr[producer].skb = NULL;
1806
1807 skb_copy_from_linear_data_offset(skb, copied,
1808 (char *)hwdesc + offset, copy_len);
1809
1810 copied += copy_len;
1811 offset = 0;
1812
1813 producer = get_next_index(producer, tx_ring->num_desc);
1814 }
1815
1816 tx_ring->producer = producer;
1817 barrier();
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001818}
1819
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001820static int
1821netxen_map_tx_skb(struct pci_dev *pdev,
1822 struct sk_buff *skb, struct netxen_cmd_buffer *pbuf)
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001823{
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001824 struct netxen_skb_frag *nf;
1825 struct skb_frag_struct *frag;
1826 int i, nr_frags;
1827 dma_addr_t map;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001828
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001829 nr_frags = skb_shinfo(skb)->nr_frags;
1830 nf = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001831
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001832 map = pci_map_single(pdev, skb->data,
1833 skb_headlen(skb), PCI_DMA_TODEVICE);
1834 if (pci_dma_mapping_error(pdev, map))
1835 goto out_err;
1836
1837 nf->dma = map;
1838 nf->length = skb_headlen(skb);
1839
1840 for (i = 0; i < nr_frags; i++) {
1841 frag = &skb_shinfo(skb)->frags[i];
1842 nf = &pbuf->frag_array[i+1];
1843
1844 map = pci_map_page(pdev, frag->page, frag->page_offset,
1845 frag->size, PCI_DMA_TODEVICE);
1846 if (pci_dma_mapping_error(pdev, map))
1847 goto unwind;
1848
1849 nf->dma = map;
1850 nf->length = frag->size;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001851 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001852
1853 return 0;
1854
1855unwind:
Dhananjay Phadkecf503e82009-09-03 13:10:55 +00001856 while (--i >= 0) {
1857 nf = &pbuf->frag_array[i+1];
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001858 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
1859 }
1860
1861 nf = &pbuf->frag_array[0];
1862 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
1863
1864out_err:
1865 return -ENOMEM;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001866}
1867
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001868static inline void
1869netxen_clear_cmddesc(u64 *desc)
1870{
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001871 desc[0] = 0ULL;
1872 desc[2] = 0ULL;
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001873}
1874
Stephen Hemminger613573252009-08-31 19:50:58 +00001875static netdev_tx_t
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001876netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001877{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001878 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001879 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001880 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001881 struct netxen_skb_frag *buffrag;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001882 struct cmd_desc_type0 *hwdesc, *first_desc;
1883 struct pci_dev *pdev;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001884 int i, k;
amit salechac968bdf2011-04-11 02:10:22 +00001885 int delta = 0;
1886 struct skb_frag_struct *frag;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001887
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001888 u32 producer;
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001889 int frag_count, no_of_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001890 u32 num_txd = tx_ring->num_desc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001891
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001892 frag_count = skb_shinfo(skb)->nr_frags + 1;
1893
amit salechac968bdf2011-04-11 02:10:22 +00001894 /* 14 frags supported for normal packet and
1895 * 32 frags supported for TSO packet
1896 */
1897 if (!skb_is_gso(skb) && frag_count > NETXEN_MAX_FRAGS_PER_TX) {
1898
1899 for (i = 0; i < (frag_count - NETXEN_MAX_FRAGS_PER_TX); i++) {
1900 frag = &skb_shinfo(skb)->frags[i];
1901 delta += frag->size;
1902 }
1903
1904 if (!__pskb_pull_tail(skb, delta))
1905 goto drop_packet;
1906
1907 frag_count = 1 + skb_shinfo(skb)->nr_frags;
1908 }
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001909 /* 4 fragments per cmd des */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001910 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001911
Rajesh Borundia7a9905e2010-10-18 02:03:41 +00001912 if (unlikely(netxen_tx_avail(tx_ring) <= TX_STOP_THRESH)) {
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001913 netif_stop_queue(netdev);
Rajesh Borundia7a9905e2010-10-18 02:03:41 +00001914 smp_mb();
1915 if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH)
1916 netif_start_queue(netdev);
1917 else
1918 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001919 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001920
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001921 producer = tx_ring->producer;
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001922 pbuf = &tx_ring->cmd_buf_arr[producer];
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001923
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001924 pdev = adapter->pdev;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001925
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001926 if (netxen_map_tx_skb(pdev, skb, pbuf))
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001927 goto drop_packet;
1928
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001929 pbuf->skb = skb;
1930 pbuf->frag_count = frag_count;
1931
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001932 first_desc = hwdesc = &tx_ring->desc_head[producer];
1933 netxen_clear_cmddesc((u64 *)hwdesc);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001934
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001935 netxen_set_tx_frags_len(first_desc, frag_count, skb->len);
1936 netxen_set_tx_port(first_desc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001937
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001938 for (i = 0; i < frag_count; i++) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001939
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001940 k = i % 4;
1941
1942 if ((k == 0) && (i > 0)) {
1943 /* move to next desc.*/
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001944 producer = get_next_index(producer, num_txd);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001945 hwdesc = &tx_ring->desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001946 netxen_clear_cmddesc((u64 *)hwdesc);
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001947 tx_ring->cmd_buf_arr[producer].skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001948 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001949
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001950 buffrag = &pbuf->frag_array[i];
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001951
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001952 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001953 switch (k) {
1954 case 0:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001955 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001956 break;
1957 case 1:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001958 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001959 break;
1960 case 2:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001961 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001962 break;
1963 case 3:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001964 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001965 break;
1966 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001967 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001968
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001969 tx_ring->producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001970
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001971 netxen_tso_check(netdev, tx_ring, first_desc, skb);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001972
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001973 adapter->stats.txbytes += skb->len;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001974 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001975
Eric Dumazetc82b9d72011-06-19 20:26:15 +00001976 netxen_nic_update_cmd_producer(adapter, tx_ring);
1977
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001978 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001979
1980drop_packet:
1981 adapter->stats.txdropped++;
1982 dev_kfree_skb_any(skb);
1983 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001984}
1985
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001986static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1987{
1988 struct net_device *netdev = adapter->netdev;
1989 uint32_t temp, temp_state, temp_val;
1990 int rv = 0;
1991
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001992 temp = NXRD32(adapter, CRB_TEMP_STATE);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001993
1994 temp_state = nx_get_temp_state(temp);
1995 temp_val = nx_get_temp_val(temp);
1996
1997 if (temp_state == NX_TEMP_PANIC) {
1998 printk(KERN_ALERT
1999 "%s: Device temperature %d degrees C exceeds"
2000 " maximum allowed. Hardware has been shut down.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00002001 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002002 rv = 1;
2003 } else if (temp_state == NX_TEMP_WARN) {
2004 if (adapter->temp == NX_TEMP_NORMAL) {
2005 printk(KERN_ALERT
2006 "%s: Device temperature %d degrees C "
2007 "exceeds operating range."
2008 " Immediate action needed.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00002009 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002010 }
2011 } else {
2012 if (adapter->temp == NX_TEMP_WARN) {
2013 printk(KERN_INFO
2014 "%s: Device temperature is now %d degrees C"
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00002015 " in normal range.\n", netdev->name,
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002016 temp_val);
2017 }
2018 }
2019 adapter->temp = temp_state;
2020 return rv;
2021}
2022
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00002023void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup)
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002024{
2025 struct net_device *netdev = adapter->netdev;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00002026
2027 if (adapter->ahw.linkup && !linkup) {
2028 printk(KERN_INFO "%s: %s NIC Link is down\n",
2029 netxen_nic_driver_name, netdev->name);
2030 adapter->ahw.linkup = 0;
2031 if (netif_running(netdev)) {
2032 netif_carrier_off(netdev);
2033 netif_stop_queue(netdev);
2034 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00002035 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00002036 } else if (!adapter->ahw.linkup && linkup) {
2037 printk(KERN_INFO "%s: %s NIC Link is up\n",
2038 netxen_nic_driver_name, netdev->name);
2039 adapter->ahw.linkup = 1;
2040 if (netif_running(netdev)) {
2041 netif_carrier_on(netdev);
2042 netif_wake_queue(netdev);
2043 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00002044 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00002045 }
2046}
2047
2048static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
2049{
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002050 u32 val, port, linkup;
2051
2052 port = adapter->physical_port;
2053
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002054 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002055 val = NXRD32(adapter, CRB_XG_STATE_P3);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07002056 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
2057 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07002058 } else {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00002059 val = NXRD32(adapter, CRB_XG_STATE);
Sucheta Chakrabortya4b751d2010-01-02 03:25:19 +00002060 val = (val >> port*8) & 0xff;
2061 linkup = (val == XG_LINK_UP);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002062 }
2063
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00002064 netxen_advert_link_change(adapter, linkup);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002065}
2066
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002067static void netxen_tx_timeout(struct net_device *netdev)
2068{
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00002069 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00002070
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002071 if (test_bit(__NX_RESETTING, &adapter->state))
2072 return;
2073
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00002074 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00002075 schedule_work(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002076}
2077
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002078static void netxen_tx_timeout_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002079{
Jeff Garzik47906542007-11-23 21:23:36 -05002080 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002081 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002082
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00002083 if (!netif_running(adapter->netdev))
2084 return;
2085
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002086 if (test_and_set_bit(__NX_RESETTING, &adapter->state))
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002087 return;
2088
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002089 if (++adapter->tx_timeo_cnt >= NX_MAX_TX_TIMEOUTS)
2090 goto request_reset;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07002091
Amit Kumar Salecha16d884b2010-08-07 23:05:23 -07002092 rtnl_lock();
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002093 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
2094 /* try to scrub interrupt */
2095 netxen_napi_disable(adapter);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07002096
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002097 netxen_napi_enable(adapter);
2098
2099 netif_wake_queue(adapter->netdev);
2100
Dhananjay Phadkea598ae12009-09-20 19:20:38 +00002101 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002102 } else {
Dhananjay Phadkea598ae12009-09-20 19:20:38 +00002103 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha16d884b2010-08-07 23:05:23 -07002104 if (netxen_nic_reset_context(adapter)) {
2105 rtnl_unlock();
2106 goto request_reset;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002107 }
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002108 }
Amit Kumar Salecha16d884b2010-08-07 23:05:23 -07002109 adapter->netdev->trans_start = jiffies;
2110 rtnl_unlock();
2111 return;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002112
2113request_reset:
2114 adapter->need_fw_reset = 1;
Amit Kumar Salechaff8a3062009-10-21 19:39:02 +00002115 clear_bit(__NX_RESETTING, &adapter->state);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002116}
2117
stephen hemminger47fd4282011-06-08 14:54:01 +00002118static struct rtnl_link_stats64 *netxen_nic_get_stats(struct net_device *netdev,
2119 struct rtnl_link_stats64 *stats)
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002120{
2121 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002122
Narender Kumar1bb482f2009-08-23 08:35:09 +00002123 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00002124 stats->tx_packets = adapter->stats.xmitfinished;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002125 stats->rx_bytes = adapter->stats.rxbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002126 stats->tx_bytes = adapter->stats.txbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002127 stats->rx_dropped = adapter->stats.rxdropped;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07002128 stats->tx_dropped = adapter->stats.txdropped;
2129
2130 return stats;
2131}
2132
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07002133static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002134{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002135 struct nx_host_sds_ring *sds_ring = data;
2136 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002137 u32 status = 0;
2138
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002139 status = readl(adapter->isr_int_vec);
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002140
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002141 if (!(status & adapter->int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002142 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05302143
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002144 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002145 /* check interrupt state machine, to be sure */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002146 status = readl(adapter->crb_int_state_reg);
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002147 if (!ISR_LEGACY_INT_TRIGGERED(status))
2148 return IRQ_NONE;
2149
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002150 } else {
2151 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002152
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002153 our_int = readl(adapter->crb_int_state_reg);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002154
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002155 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002156 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07002157 return IRQ_NONE;
2158
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002159 /* claim interrupt */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002160 writel((our_int & 0xffffffff), adapter->crb_int_state_reg);
2161
2162 /* clear interrupt */
2163 netxen_nic_disable_int(sds_ring);
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05302164 }
2165
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002166 writel(0xffffffff, adapter->tgt_status_reg);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002167 /* read twice to ensure write is flushed */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002168 readl(adapter->isr_int_vec);
2169 readl(adapter->isr_int_vec);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002170
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002171 napi_schedule(&sds_ring->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002172
2173 return IRQ_HANDLED;
2174}
2175
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07002176static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002177{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002178 struct nx_host_sds_ring *sds_ring = data;
2179 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002180
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002181 /* clear interrupt */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00002182 writel(0xffffffff, adapter->tgt_status_reg);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07002183
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002184 napi_schedule(&sds_ring->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002185 return IRQ_HANDLED;
2186}
2187
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08002188static irqreturn_t netxen_msix_intr(int irq, void *data)
2189{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002190 struct nx_host_sds_ring *sds_ring = data;
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08002191
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002192 napi_schedule(&sds_ring->napi);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08002193 return IRQ_HANDLED;
2194}
2195
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002196static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002197{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002198 struct nx_host_sds_ring *sds_ring =
2199 container_of(napi, struct nx_host_sds_ring, napi);
2200
2201 struct netxen_adapter *adapter = sds_ring->adapter;
2202
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002203 int tx_complete;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002204 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002205
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002206 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002207
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002208 work_done = netxen_process_rcv_ring(sds_ring, budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002209
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002210 if ((work_done < budget) && tx_complete) {
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002211 napi_complete(&sds_ring->napi);
Amit Kumar Salechaf2251f62009-12-05 12:23:55 +00002212 if (test_bit(__NX_DEV_UP, &adapter->state))
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00002213 netxen_nic_enable_int(sds_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002214 }
2215
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002216 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002217}
2218
2219#ifdef CONFIG_NET_POLL_CONTROLLER
2220static void netxen_nic_poll_controller(struct net_device *netdev)
2221{
Yinglin Luan7b589a32010-08-22 21:56:19 +00002222 int ring;
2223 struct nx_host_sds_ring *sds_ring;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002224 struct netxen_adapter *adapter = netdev_priv(netdev);
Yinglin Luan7b589a32010-08-22 21:56:19 +00002225 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
2226
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002227 disable_irq(adapter->irq);
Yinglin Luan7b589a32010-08-22 21:56:19 +00002228 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
2229 sds_ring = &recv_ctx->sds_rings[ring];
2230 netxen_intr(adapter->irq, sds_ring);
2231 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002232 enable_irq(adapter->irq);
2233}
2234#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002235
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002236static int
2237nx_incr_dev_ref_cnt(struct netxen_adapter *adapter)
2238{
2239 int count;
2240 if (netxen_api_lock(adapter))
2241 return -EIO;
2242
2243 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2244
2245 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2246
2247 netxen_api_unlock(adapter);
2248 return count;
2249}
2250
2251static int
2252nx_decr_dev_ref_cnt(struct netxen_adapter *adapter)
2253{
2254 int count;
2255 if (netxen_api_lock(adapter))
2256 return -EIO;
2257
2258 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2259 WARN_ON(count == 0);
2260
2261 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, --count);
2262
2263 if (count == 0)
2264 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_COLD);
2265
2266 netxen_api_unlock(adapter);
2267 return count;
2268}
2269
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002270static int
2271nx_dev_request_aer(struct netxen_adapter *adapter)
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002272{
2273 u32 state;
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002274 int ret = -EINVAL;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002275
2276 if (netxen_api_lock(adapter))
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002277 return ret;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002278
2279 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2280
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002281 if (state == NX_DEV_NEED_AER)
2282 ret = 0;
2283 else if (state == NX_DEV_READY) {
2284 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_AER);
2285 ret = 0;
2286 }
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002287
2288 netxen_api_unlock(adapter);
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002289 return ret;
2290}
2291
2292static int
2293nx_dev_request_reset(struct netxen_adapter *adapter)
2294{
2295 u32 state;
2296 int ret = -EINVAL;
2297
2298 if (netxen_api_lock(adapter))
2299 return ret;
2300
2301 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2302
2303 if (state == NX_DEV_NEED_RESET)
2304 ret = 0;
2305 else if (state != NX_DEV_INITALIZING && state != NX_DEV_NEED_AER) {
2306 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_RESET);
2307 ret = 0;
2308 }
2309
2310 netxen_api_unlock(adapter);
2311
2312 return ret;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002313}
2314
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002315static int
2316netxen_can_start_firmware(struct netxen_adapter *adapter)
2317{
2318 int count;
2319 int can_start = 0;
2320
2321 if (netxen_api_lock(adapter))
2322 return 0;
2323
2324 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2325
2326 if ((count < 0) || (count >= NX_MAX_PCI_FUNC))
2327 count = 0;
2328
2329 if (count == 0) {
2330 can_start = 1;
2331 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_INITALIZING);
2332 }
2333
2334 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2335
2336 netxen_api_unlock(adapter);
2337
2338 return can_start;
2339}
2340
2341static void
2342netxen_schedule_work(struct netxen_adapter *adapter,
2343 work_func_t func, int delay)
2344{
2345 INIT_DELAYED_WORK(&adapter->fw_work, func);
2346 schedule_delayed_work(&adapter->fw_work, delay);
2347}
2348
2349static void
2350netxen_cancel_fw_work(struct netxen_adapter *adapter)
2351{
2352 while (test_and_set_bit(__NX_RESETTING, &adapter->state))
2353 msleep(10);
2354
2355 cancel_delayed_work_sync(&adapter->fw_work);
2356}
2357
2358static void
2359netxen_attach_work(struct work_struct *work)
2360{
2361 struct netxen_adapter *adapter = container_of(work,
2362 struct netxen_adapter, fw_work.work);
2363 struct net_device *netdev = adapter->netdev;
2364 int err = 0;
2365
2366 if (netif_running(netdev)) {
2367 err = netxen_nic_attach(adapter);
2368 if (err)
2369 goto done;
2370
2371 err = netxen_nic_up(adapter, netdev);
2372 if (err) {
2373 netxen_nic_detach(adapter);
2374 goto done;
2375 }
2376
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002377 netxen_config_indev_addr(netdev, NETDEV_UP);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002378 }
2379
2380 netif_device_attach(netdev);
2381
2382done:
2383 adapter->fw_fail_cnt = 0;
2384 clear_bit(__NX_RESETTING, &adapter->state);
2385 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
2386}
2387
2388static void
2389netxen_fwinit_work(struct work_struct *work)
2390{
2391 struct netxen_adapter *adapter = container_of(work,
2392 struct netxen_adapter, fw_work.work);
2393 int dev_state;
2394
2395 dev_state = NXRD32(adapter, NX_CRB_DEV_STATE);
2396
2397 switch (dev_state) {
2398 case NX_DEV_COLD:
2399 case NX_DEV_READY:
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002400 if (!netxen_start_firmware(adapter)) {
2401 netxen_schedule_work(adapter, netxen_attach_work, 0);
2402 return;
2403 }
2404 break;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002405
Amit Kumar Salecha6b50ea12010-03-29 02:43:42 +00002406 case NX_DEV_NEED_RESET:
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002407 case NX_DEV_INITALIZING:
2408 if (++adapter->fw_wait_cnt < FW_POLL_THRESH) {
2409 netxen_schedule_work(adapter,
2410 netxen_fwinit_work, 2 * FW_POLL_DELAY);
2411 return;
2412 }
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002413
2414 case NX_DEV_FAILED:
2415 default:
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00002416 nx_incr_dev_ref_cnt(adapter);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002417 break;
2418 }
2419
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002420 clear_bit(__NX_RESETTING, &adapter->state);
2421}
2422
2423static void
2424netxen_detach_work(struct work_struct *work)
2425{
2426 struct netxen_adapter *adapter = container_of(work,
2427 struct netxen_adapter, fw_work.work);
2428 struct net_device *netdev = adapter->netdev;
2429 int ref_cnt, delay;
2430 u32 status;
2431
2432 netif_device_detach(netdev);
2433
Amit Kumar Salecha6f771412009-12-05 12:23:54 +00002434 netxen_nic_down(adapter, netdev);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002435
Amit Kumar Salechae15eec22010-02-02 04:16:21 +00002436 rtnl_lock();
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002437 netxen_nic_detach(adapter);
Amit Kumar Salechae15eec22010-02-02 04:16:21 +00002438 rtnl_unlock();
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002439
2440 status = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1);
2441
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002442 if (status & NX_RCODE_FATAL_ERROR)
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00002443 goto err_ret;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002444
2445 if (adapter->temp == NX_TEMP_PANIC)
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00002446 goto err_ret;
2447
2448 ref_cnt = nx_decr_dev_ref_cnt(adapter);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002449
Amit Kumar Salecha6b50ea12010-03-29 02:43:42 +00002450 if (ref_cnt == -EIO)
2451 goto err_ret;
2452
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002453 delay = (ref_cnt == 0) ? 0 : (2 * FW_POLL_DELAY);
2454
2455 adapter->fw_wait_cnt = 0;
2456 netxen_schedule_work(adapter, netxen_fwinit_work, delay);
Amit Kumar Salecha8f9b3f62009-12-02 15:46:19 +00002457
2458 return;
2459
2460err_ret:
2461 clear_bit(__NX_RESETTING, &adapter->state);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002462}
2463
2464static int
2465netxen_check_health(struct netxen_adapter *adapter)
2466{
2467 u32 state, heartbit;
2468 struct net_device *netdev = adapter->netdev;
2469
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002470 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2471 if (state == NX_DEV_NEED_AER)
2472 return 0;
2473
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002474 if (netxen_nic_check_temp(adapter))
2475 goto detach;
2476
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002477 if (adapter->need_fw_reset) {
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002478 if (nx_dev_request_reset(adapter))
2479 return 0;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002480 goto detach;
2481 }
2482
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002483 /* NX_DEV_NEED_RESET, this state can be marked in two cases
2484 * 1. Tx timeout 2. Fw hang
2485 * Send request to destroy context in case of tx timeout only
2486 * and doesn't required in case of Fw hang
2487 */
Amit Kumar Salecha6a808c62009-12-08 20:40:55 +00002488 if (state == NX_DEV_NEED_RESET) {
2489 adapter->need_fw_reset = 1;
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002490 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2491 goto detach;
Amit Kumar Salecha6a808c62009-12-08 20:40:55 +00002492 }
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002493
2494 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2495 return 0;
2496
2497 heartbit = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER);
2498 if (heartbit != adapter->heartbit) {
2499 adapter->heartbit = heartbit;
2500 adapter->fw_fail_cnt = 0;
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002501 if (adapter->need_fw_reset)
2502 goto detach;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002503 return 0;
2504 }
2505
2506 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2507 return 0;
2508
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002509 if (nx_dev_request_reset(adapter))
2510 return 0;
2511
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002512 clear_bit(__NX_FW_ATTACHED, &adapter->state);
2513
2514 dev_info(&netdev->dev, "firmware hang detected\n");
2515
2516detach:
Narender Kumarcaa2dd52009-10-16 15:50:11 +00002517 if ((auto_fw_reset == AUTO_FW_RESET_ENABLED) &&
2518 !test_and_set_bit(__NX_RESETTING, &adapter->state))
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002519 netxen_schedule_work(adapter, netxen_detach_work, 0);
2520 return 1;
2521}
2522
2523static void
2524netxen_fw_poll_work(struct work_struct *work)
2525{
2526 struct netxen_adapter *adapter = container_of(work,
2527 struct netxen_adapter, fw_work.work);
2528
2529 if (test_bit(__NX_RESETTING, &adapter->state))
2530 goto reschedule;
2531
2532 if (test_bit(__NX_DEV_UP, &adapter->state)) {
2533 if (!adapter->has_link_events) {
2534
2535 netxen_nic_handle_phy_intr(adapter);
2536
2537 if (adapter->link_changed)
2538 netxen_nic_set_link_parameters(adapter);
2539 }
2540 }
2541
2542 if (netxen_check_health(adapter))
2543 return;
2544
2545reschedule:
2546 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
2547}
2548
Narender Kumarfa3ce352009-08-24 19:23:28 +00002549static ssize_t
2550netxen_store_bridged_mode(struct device *dev,
2551 struct device_attribute *attr, const char *buf, size_t len)
2552{
2553 struct net_device *net = to_net_dev(dev);
2554 struct netxen_adapter *adapter = netdev_priv(net);
2555 unsigned long new;
2556 int ret = -EINVAL;
2557
2558 if (!(adapter->capabilities & NX_FW_CAPABILITY_BDG))
2559 goto err_out;
2560
2561 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2562 goto err_out;
2563
2564 if (strict_strtoul(buf, 2, &new))
2565 goto err_out;
2566
2567 if (!netxen_config_bridged_mode(adapter, !!new))
2568 ret = len;
2569
2570err_out:
2571 return ret;
2572}
2573
2574static ssize_t
2575netxen_show_bridged_mode(struct device *dev,
2576 struct device_attribute *attr, char *buf)
2577{
2578 struct net_device *net = to_net_dev(dev);
2579 struct netxen_adapter *adapter;
2580 int bridged_mode = 0;
2581
2582 adapter = netdev_priv(net);
2583
2584 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2585 bridged_mode = !!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED);
2586
2587 return sprintf(buf, "%d\n", bridged_mode);
2588}
2589
2590static struct device_attribute dev_attr_bridged_mode = {
2591 .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
2592 .show = netxen_show_bridged_mode,
2593 .store = netxen_store_bridged_mode,
2594};
2595
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002596static ssize_t
2597netxen_store_diag_mode(struct device *dev,
2598 struct device_attribute *attr, const char *buf, size_t len)
2599{
2600 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2601 unsigned long new;
2602
2603 if (strict_strtoul(buf, 2, &new))
2604 return -EINVAL;
2605
2606 if (!!new != !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2607 adapter->flags ^= NETXEN_NIC_DIAG_ENABLED;
2608
2609 return len;
2610}
2611
2612static ssize_t
2613netxen_show_diag_mode(struct device *dev,
2614 struct device_attribute *attr, char *buf)
2615{
2616 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2617
2618 return sprintf(buf, "%d\n",
2619 !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED));
2620}
2621
2622static struct device_attribute dev_attr_diag_mode = {
2623 .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)},
2624 .show = netxen_show_diag_mode,
2625 .store = netxen_store_diag_mode,
2626};
2627
2628static int
2629netxen_sysfs_validate_crb(struct netxen_adapter *adapter,
2630 loff_t offset, size_t size)
2631{
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002632 size_t crb_size = 4;
2633
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002634 if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2635 return -EIO;
2636
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002637 if (offset < NETXEN_PCI_CRBSPACE) {
2638 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2639 return -EINVAL;
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002640
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002641 if (ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM,
2642 NETXEN_PCI_CAMQM_2M_END))
2643 crb_size = 8;
2644 else
2645 return -EINVAL;
2646 }
2647
2648 if ((size != crb_size) || (offset & (crb_size-1)))
2649 return -EINVAL;
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002650
2651 return 0;
2652}
2653
2654static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002655netxen_sysfs_read_crb(struct file *filp, struct kobject *kobj,
2656 struct bin_attribute *attr,
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002657 char *buf, loff_t offset, size_t size)
2658{
2659 struct device *dev = container_of(kobj, struct device, kobj);
2660 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2661 u32 data;
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002662 u64 qmdata;
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002663 int ret;
2664
2665 ret = netxen_sysfs_validate_crb(adapter, offset, size);
2666 if (ret != 0)
2667 return ret;
2668
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002669 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) &&
2670 ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM,
2671 NETXEN_PCI_CAMQM_2M_END)) {
2672 netxen_pci_camqm_read_2M(adapter, offset, &qmdata);
2673 memcpy(buf, &qmdata, size);
2674 } else {
2675 data = NXRD32(adapter, offset);
2676 memcpy(buf, &data, size);
2677 }
2678
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002679 return size;
2680}
2681
2682static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002683netxen_sysfs_write_crb(struct file *filp, struct kobject *kobj,
2684 struct bin_attribute *attr,
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002685 char *buf, loff_t offset, size_t size)
2686{
2687 struct device *dev = container_of(kobj, struct device, kobj);
2688 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2689 u32 data;
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002690 u64 qmdata;
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002691 int ret;
2692
2693 ret = netxen_sysfs_validate_crb(adapter, offset, size);
2694 if (ret != 0)
2695 return ret;
2696
Amit Kumar Salecha0b9715e2010-05-11 23:53:05 +00002697 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) &&
2698 ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM,
2699 NETXEN_PCI_CAMQM_2M_END)) {
2700 memcpy(&qmdata, buf, size);
2701 netxen_pci_camqm_write_2M(adapter, offset, qmdata);
2702 } else {
2703 memcpy(&data, buf, size);
2704 NXWR32(adapter, offset, data);
2705 }
2706
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002707 return size;
2708}
2709
2710static int
2711netxen_sysfs_validate_mem(struct netxen_adapter *adapter,
2712 loff_t offset, size_t size)
2713{
2714 if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2715 return -EIO;
2716
2717 if ((size != 8) || (offset & 0x7))
2718 return -EIO;
2719
2720 return 0;
2721}
2722
2723static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002724netxen_sysfs_read_mem(struct file *filp, struct kobject *kobj,
2725 struct bin_attribute *attr,
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002726 char *buf, loff_t offset, size_t size)
2727{
2728 struct device *dev = container_of(kobj, struct device, kobj);
2729 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2730 u64 data;
2731 int ret;
2732
2733 ret = netxen_sysfs_validate_mem(adapter, offset, size);
2734 if (ret != 0)
2735 return ret;
2736
2737 if (adapter->pci_mem_read(adapter, offset, &data))
2738 return -EIO;
2739
2740 memcpy(buf, &data, size);
2741
2742 return size;
2743}
2744
Chris Wright2c3c8be2010-05-12 18:28:57 -07002745static ssize_t netxen_sysfs_write_mem(struct file *filp, struct kobject *kobj,
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002746 struct bin_attribute *attr, char *buf,
2747 loff_t offset, size_t size)
2748{
2749 struct device *dev = container_of(kobj, struct device, kobj);
2750 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2751 u64 data;
2752 int ret;
2753
2754 ret = netxen_sysfs_validate_mem(adapter, offset, size);
2755 if (ret != 0)
2756 return ret;
2757
2758 memcpy(&data, buf, size);
2759
2760 if (adapter->pci_mem_write(adapter, offset, data))
2761 return -EIO;
2762
2763 return size;
2764}
2765
2766
2767static struct bin_attribute bin_attr_crb = {
2768 .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)},
2769 .size = 0,
2770 .read = netxen_sysfs_read_crb,
2771 .write = netxen_sysfs_write_crb,
2772};
2773
2774static struct bin_attribute bin_attr_mem = {
2775 .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)},
2776 .size = 0,
2777 .read = netxen_sysfs_read_mem,
2778 .write = netxen_sysfs_write_mem,
2779};
2780
Narender Kumarcaa2dd52009-10-16 15:50:11 +00002781
Narender Kumarfa3ce352009-08-24 19:23:28 +00002782static void
2783netxen_create_sysfs_entries(struct netxen_adapter *adapter)
2784{
2785 struct net_device *netdev = adapter->netdev;
2786 struct device *dev = &netdev->dev;
2787
2788 if (adapter->capabilities & NX_FW_CAPABILITY_BDG) {
2789 /* bridged_mode control */
2790 if (device_create_file(dev, &dev_attr_bridged_mode)) {
2791 dev_warn(&netdev->dev,
2792 "failed to create bridged_mode sysfs entry\n");
2793 }
2794 }
2795}
2796
2797static void
2798netxen_remove_sysfs_entries(struct netxen_adapter *adapter)
2799{
2800 struct net_device *netdev = adapter->netdev;
2801 struct device *dev = &netdev->dev;
2802
2803 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2804 device_remove_file(dev, &dev_attr_bridged_mode);
2805}
2806
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002807static void
2808netxen_create_diag_entries(struct netxen_adapter *adapter)
2809{
2810 struct pci_dev *pdev = adapter->pdev;
2811 struct device *dev;
2812
2813 dev = &pdev->dev;
2814 if (device_create_file(dev, &dev_attr_diag_mode))
2815 dev_info(dev, "failed to create diag_mode sysfs entry\n");
2816 if (device_create_bin_file(dev, &bin_attr_crb))
2817 dev_info(dev, "failed to create crb sysfs entry\n");
2818 if (device_create_bin_file(dev, &bin_attr_mem))
2819 dev_info(dev, "failed to create mem sysfs entry\n");
2820}
2821
2822
2823static void
2824netxen_remove_diag_entries(struct netxen_adapter *adapter)
2825{
2826 struct pci_dev *pdev = adapter->pdev;
2827 struct device *dev = &pdev->dev;
2828
2829 device_remove_file(dev, &dev_attr_diag_mode);
2830 device_remove_bin_file(dev, &bin_attr_crb);
2831 device_remove_bin_file(dev, &bin_attr_mem);
2832}
2833
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002834#ifdef CONFIG_INET
2835
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002836#define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2837
2838static int
2839netxen_destip_supported(struct netxen_adapter *adapter)
2840{
2841 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2842 return 0;
2843
2844 if (adapter->ahw.cut_through)
2845 return 0;
2846
2847 return 1;
2848}
2849
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002850static void
2851netxen_config_indev_addr(struct net_device *dev, unsigned long event)
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002852{
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002853 struct in_device *indev;
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002854 struct netxen_adapter *adapter = netdev_priv(dev);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002855
Amit Kumar Salecha3db76752009-09-09 18:12:37 -07002856 if (!netxen_destip_supported(adapter))
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002857 return;
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002858
2859 indev = in_dev_get(dev);
2860 if (!indev)
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002861 return;
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002862
2863 for_ifa(indev) {
2864 switch (event) {
2865 case NETDEV_UP:
2866 netxen_config_ipaddr(adapter,
2867 ifa->ifa_address, NX_IP_UP);
2868 break;
2869 case NETDEV_DOWN:
2870 netxen_config_ipaddr(adapter,
2871 ifa->ifa_address, NX_IP_DOWN);
2872 break;
2873 default:
2874 break;
2875 }
2876 } endfor_ifa(indev);
2877
2878 in_dev_put(indev);
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002879}
2880
2881static int netxen_netdev_event(struct notifier_block *this,
2882 unsigned long event, void *ptr)
2883{
2884 struct netxen_adapter *adapter;
2885 struct net_device *dev = (struct net_device *)ptr;
2886
2887recheck:
2888 if (dev == NULL)
2889 goto done;
2890
2891 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2892 dev = vlan_dev_real_dev(dev);
2893 goto recheck;
2894 }
2895
2896 if (!is_netxen_netdev(dev))
2897 goto done;
2898
2899 adapter = netdev_priv(dev);
2900
2901 if (!adapter)
2902 goto done;
2903
2904 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2905 goto done;
2906
2907 netxen_config_indev_addr(dev, event);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002908done:
2909 return NOTIFY_DONE;
2910}
2911
2912static int
2913netxen_inetaddr_event(struct notifier_block *this,
2914 unsigned long event, void *ptr)
2915{
2916 struct netxen_adapter *adapter;
2917 struct net_device *dev;
2918
2919 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
2920
2921 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
2922
2923recheck:
2924 if (dev == NULL || !netif_running(dev))
2925 goto done;
2926
2927 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2928 dev = vlan_dev_real_dev(dev);
2929 goto recheck;
2930 }
2931
2932 if (!is_netxen_netdev(dev))
2933 goto done;
2934
2935 adapter = netdev_priv(dev);
2936
2937 if (!adapter || !netxen_destip_supported(adapter))
2938 goto done;
2939
2940 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2941 goto done;
2942
2943 switch (event) {
2944 case NETDEV_UP:
2945 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP);
2946 break;
2947 case NETDEV_DOWN:
2948 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN);
2949 break;
2950 default:
2951 break;
2952 }
2953
2954done:
2955 return NOTIFY_DONE;
2956}
2957
2958static struct notifier_block netxen_netdev_cb = {
2959 .notifier_call = netxen_netdev_event,
2960};
2961
2962static struct notifier_block netxen_inetaddr_cb = {
2963 .notifier_call = netxen_inetaddr_event,
2964};
Randy Dunlap9feae562009-09-11 12:41:04 +00002965#else
2966static void
2967netxen_config_indev_addr(struct net_device *dev, unsigned long event)
2968{ }
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002969#endif
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002970
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002971static struct pci_error_handlers netxen_err_handler = {
2972 .error_detected = netxen_io_error_detected,
2973 .slot_reset = netxen_io_slot_reset,
2974 .resume = netxen_io_resume,
2975};
2976
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002977static struct pci_driver netxen_driver = {
2978 .name = netxen_nic_driver_name,
2979 .id_table = netxen_pci_tbl,
2980 .probe = netxen_nic_probe,
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002981 .remove = __devexit_p(netxen_nic_remove),
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002982#ifdef CONFIG_PM
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002983 .suspend = netxen_nic_suspend,
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00002984 .resume = netxen_nic_resume,
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002985#endif
Amit Kumar Salechae87ad552009-12-08 20:40:56 +00002986 .shutdown = netxen_nic_shutdown,
2987 .err_handler = &netxen_err_handler
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002988};
2989
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002990static int __init netxen_init_module(void)
2991{
Dhananjay Phadkeff4fbd42009-03-13 14:52:06 +00002992 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
2993
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002994#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002995 register_netdevice_notifier(&netxen_netdev_cb);
2996 register_inetaddr_notifier(&netxen_inetaddr_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002997#endif
Amit S. Kale184231b2007-01-22 06:52:53 -08002998 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002999}
3000
3001module_init(netxen_init_module);
3002
3003static void __exit netxen_exit_module(void)
3004{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04003005 pci_unregister_driver(&netxen_driver);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00003006
Dhananjay Phadke044824d2009-07-28 09:10:03 +00003007#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00003008 unregister_inetaddr_notifier(&netxen_inetaddr_cb);
3009 unregister_netdevice_notifier(&netxen_netdev_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00003010#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04003011}
3012
3013module_exit(netxen_exit_module);