blob: 1071f090a124be2705e835a61cd13527811aa6b5 [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
22 * in the file called LICENSE.
Amit S. Kale80922fb2006-12-04 09:18:00 -080023 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040024 */
25
Amit S. Kalecb8011a2006-11-29 09:00:10 -080026#include <linux/vmalloc.h>
Dhananjay Phadkee98e3352009-04-07 22:50:38 +000027#include <linux/interrupt.h>
Amit S. Kale3d396eb2006-10-21 15:33:03 -040028#include "netxen_nic_hw.h"
29
30#include "netxen_nic.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040031
Jeff Garzik1494a812006-11-07 05:12:16 -050032#include <linux/dma-mapping.h>
Dhananjay Phadke391587c2009-01-14 20:48:11 -080033#include <linux/if_vlan.h>
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030034#include <net/ip.h>
Dhananjay Phadke00977782009-01-16 11:03:25 -080035#include <linux/ipv6.h>
Dhananjay Phadke6598b162009-07-26 20:07:37 +000036#include <linux/inetdevice.h>
Jeff Garzik1494a812006-11-07 05:12:16 -050037
Amit S. Kale3d396eb2006-10-21 15:33:03 -040038MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
39MODULE_LICENSE("GPL");
40MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
41
dhananjay@netxen.comceded322007-07-19 14:41:09 +053042char netxen_nic_driver_name[] = "netxen_nic";
Amit S. Kale3d396eb2006-10-21 15:33:03 -040043static char netxen_nic_driver_string[] = "NetXen Network Driver version "
Amit S. Kalecb8011a2006-11-29 09:00:10 -080044 NETXEN_NIC_LINUX_VERSIONID;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040045
Dhananjay Phadke29566402008-07-21 19:44:04 -070046static int port_mode = NETXEN_PORT_MODE_AUTO_NEG;
47
48/* Default to restricted 1G auto-neg mode */
49static int wol_port_mode = 5;
50
51static int use_msi = 1;
52
53static int use_msi_x = 1;
54
Narender Kumarcaa2dd52009-10-16 15:50:11 +000055static unsigned long auto_fw_reset = AUTO_FW_RESET_ENABLED;
56
Amit S. Kale3d396eb2006-10-21 15:33:03 -040057/* Local functions to NetXen NIC driver */
58static int __devinit netxen_nic_probe(struct pci_dev *pdev,
Dhananjay Phadke29566402008-07-21 19:44:04 -070059 const struct pci_device_id *ent);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040060static void __devexit netxen_nic_remove(struct pci_dev *pdev);
61static int netxen_nic_open(struct net_device *netdev);
62static int netxen_nic_close(struct net_device *netdev);
Stephen Hemminger613573252009-08-31 19:50:58 +000063static netdev_tx_t netxen_nic_xmit_frame(struct sk_buff *,
64 struct net_device *);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040065static void netxen_tx_timeout(struct net_device *netdev);
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +000066static void netxen_tx_timeout_task(struct work_struct *work);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +000067static void netxen_fw_poll_work(struct work_struct *work);
68static void netxen_schedule_work(struct netxen_adapter *adapter,
69 work_func_t func, int delay);
70static void netxen_cancel_fw_work(struct netxen_adapter *adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -070071static int netxen_nic_poll(struct napi_struct *napi, int budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040072#ifdef CONFIG_NET_POLL_CONTROLLER
73static void netxen_nic_poll_controller(struct net_device *netdev);
74#endif
Narender Kumarfa3ce352009-08-24 19:23:28 +000075
76static void netxen_create_sysfs_entries(struct netxen_adapter *adapter);
77static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter);
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +000078static void netxen_create_diag_entries(struct netxen_adapter *adapter);
79static void netxen_remove_diag_entries(struct netxen_adapter *adapter);
Narender Kumarfa3ce352009-08-24 19:23:28 +000080
Dhananjay Phadke6a581e92009-09-05 17:43:08 +000081static int nx_decr_dev_ref_cnt(struct netxen_adapter *adapter);
82static int netxen_can_start_firmware(struct netxen_adapter *adapter);
83
Jeff Garzik1494a812006-11-07 05:12:16 -050084static irqreturn_t netxen_intr(int irq, void *data);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -070085static irqreturn_t netxen_msi_intr(int irq, void *data);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -080086static irqreturn_t netxen_msix_intr(int irq, void *data);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040087
Amit Kumar Salechad0725e42009-09-05 17:43:09 +000088static void netxen_config_indev_addr(struct net_device *dev, unsigned long);
89
Amit S. Kale3d396eb2006-10-21 15:33:03 -040090/* PCI Device ID Table */
Al Viro70081ac2008-06-23 02:04:50 +010091#define ENTRY(device) \
Dhananjay Phadke040dec32008-09-12 06:55:14 -070092 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
Al Viro70081ac2008-06-23 02:04:50 +010093 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
94
Amit S. Kale3d396eb2006-10-21 15:33:03 -040095static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
Dhananjay Phadke040dec32008-09-12 06:55:14 -070096 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR),
97 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4),
98 ENTRY(PCI_DEVICE_ID_NX2031_4GCU),
99 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ),
100 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ),
101 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT),
102 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2),
103 ENTRY(PCI_DEVICE_ID_NX3031),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400104 {0,}
105};
106
107MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
108
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700109static uint32_t crb_cmd_producer[4] = {
110 CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1,
111 CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3
112};
113
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700114void
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700115netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000116 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700117{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000118 NXWRIO(adapter, tx_ring->crb_cmd_producer, tx_ring->producer);
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000119
120 if (netxen_tx_avail(tx_ring) <= TX_STOP_THRESH) {
121 netif_stop_queue(adapter->netdev);
122 smp_mb();
123 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700124}
125
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700126static uint32_t crb_cmd_consumer[4] = {
127 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
128 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
129};
130
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700131static inline void
132netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000133 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700134{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000135 NXWRIO(adapter, tx_ring->crb_cmd_consumer, tx_ring->sw_consumer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700136}
137
Dhananjay Phadke29566402008-07-21 19:44:04 -0700138static uint32_t msi_tgt_status[8] = {
Dhananjay Phadke443be792008-03-17 19:59:48 -0700139 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700140 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
141 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
142 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
Dhananjay Phadke443be792008-03-17 19:59:48 -0700143};
144
Dhananjay Phadke29566402008-07-21 19:44:04 -0700145static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
146
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000147static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700148{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000149 struct netxen_adapter *adapter = sds_ring->adapter;
150
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000151 NXWRIO(adapter, sds_ring->crb_intr_mask, 0);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700152}
153
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000154static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700155{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000156 struct netxen_adapter *adapter = sds_ring->adapter;
157
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000158 NXWRIO(adapter, sds_ring->crb_intr_mask, 0x1);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700159
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700160 if (!NETXEN_IS_MSI_FAMILY(adapter))
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000161 NXWRIO(adapter, adapter->tgt_mask_reg, 0xfbff);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700162}
163
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000164static int
165netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count)
166{
167 int size = sizeof(struct nx_host_sds_ring) * count;
168
169 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
170
171 return (recv_ctx->sds_rings == NULL);
172}
173
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000174static void
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000175netxen_free_sds_rings(struct netxen_recv_context *recv_ctx)
176{
177 if (recv_ctx->sds_rings != NULL)
178 kfree(recv_ctx->sds_rings);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000179
180 recv_ctx->sds_rings = NULL;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000181}
182
183static int
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000184netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
185{
186 int ring;
187 struct nx_host_sds_ring *sds_ring;
188 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
189
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000190 if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
Dhananjay Phadkef17443f2009-07-26 20:07:43 +0000191 return -ENOMEM;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000192
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000193 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
194 sds_ring = &recv_ctx->sds_rings[ring];
195 netif_napi_add(netdev, &sds_ring->napi,
196 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
197 }
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000198
199 return 0;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000200}
201
202static void
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000203netxen_napi_del(struct netxen_adapter *adapter)
204{
205 int ring;
206 struct nx_host_sds_ring *sds_ring;
207 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
208
209 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
210 sds_ring = &recv_ctx->sds_rings[ring];
211 netif_napi_del(&sds_ring->napi);
212 }
213
214 netxen_free_sds_rings(&adapter->recv_ctx);
215}
216
217static void
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000218netxen_napi_enable(struct netxen_adapter *adapter)
219{
220 int ring;
221 struct nx_host_sds_ring *sds_ring;
222 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
223
224 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
225 sds_ring = &recv_ctx->sds_rings[ring];
226 napi_enable(&sds_ring->napi);
227 netxen_nic_enable_int(sds_ring);
228 }
229}
230
231static void
232netxen_napi_disable(struct netxen_adapter *adapter)
233{
234 int ring;
235 struct nx_host_sds_ring *sds_ring;
236 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
237
238 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
239 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000240 netxen_nic_disable_int(sds_ring);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000241 napi_synchronize(&sds_ring->napi);
242 napi_disable(&sds_ring->napi);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000243 }
244}
245
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000246static int nx_set_dma_mask(struct netxen_adapter *adapter)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700247{
248 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000249 uint64_t mask, cmask;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700250
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000251 adapter->pci_using_dac = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700252
Yang Hongyang6afd1422009-04-06 19:01:15 -0700253 mask = DMA_BIT_MASK(32);
Yang Hongyang6afd1422009-04-06 19:01:15 -0700254 cmask = DMA_BIT_MASK(32);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000255
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000256 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000257#ifndef CONFIG_IA64
Yang Hongyang6afd1422009-04-06 19:01:15 -0700258 mask = DMA_BIT_MASK(35);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000259#endif
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000260 } else {
261 mask = DMA_BIT_MASK(39);
262 cmask = mask;
263 }
264
Dhananjay Phadke29566402008-07-21 19:44:04 -0700265 if (pci_set_dma_mask(pdev, mask) == 0 &&
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000266 pci_set_consistent_dma_mask(pdev, cmask) == 0) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700267 adapter->pci_using_dac = 1;
268 return 0;
269 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700270
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000271 return -EIO;
272}
273
274/* Update addressable range if firmware supports it */
275static int
276nx_update_dma_mask(struct netxen_adapter *adapter)
277{
278 int change, shift, err;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000279 uint64_t mask, old_mask, old_cmask;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000280 struct pci_dev *pdev = adapter->pdev;
281
282 change = 0;
283
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000284 shift = NXRD32(adapter, CRB_DMA_SHIFT);
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000285 if (shift > 32)
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000286 return 0;
287
288 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9))
289 change = 1;
290 else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4))
291 change = 1;
292
293 if (change) {
294 old_mask = pdev->dma_mask;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000295 old_cmask = pdev->dev.coherent_dma_mask;
296
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000297 mask = DMA_BIT_MASK(32+shift);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000298
299 err = pci_set_dma_mask(pdev, mask);
300 if (err)
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000301 goto err_out;
302
303 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
304
305 err = pci_set_consistent_dma_mask(pdev, mask);
306 if (err)
307 goto err_out;
308 }
309 dev_info(&pdev->dev, "using %d-bit dma mask\n", 32+shift);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700310 }
311
Dhananjay Phadke29566402008-07-21 19:44:04 -0700312 return 0;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000313
314err_out:
315 pci_set_dma_mask(pdev, old_mask);
316 pci_set_consistent_dma_mask(pdev, old_cmask);
317 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700318}
319
Dhananjay Phadke29566402008-07-21 19:44:04 -0700320static int
321netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
322{
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800323 u32 val, timeout;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700324
325 if (first_boot == 0x55555555) {
326 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000327 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800328
329 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
330 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700331
332 /* PCI bus master workaround */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000333 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700334 if (!(first_boot & 0x4)) {
335 first_boot |= 0x4;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000336 NXWR32(adapter, NETXEN_PCIE_REG(0x4), first_boot);
337 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700338 }
339
340 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000341 first_boot = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700342 if (first_boot != 0x80000f) {
343 /* clear the register for future unloads/loads */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000344 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), 0);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800345 return -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700346 }
347
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800348 /* Start P2 boot loader */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000349 val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
350 NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800351 timeout = 0;
352 do {
353 msleep(1);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000354 val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800355
356 if (++timeout > 5000)
357 return -EIO;
358
359 } while (val == NETXEN_BDINFO_MAGIC);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700360 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800361 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700362}
363
364static void netxen_set_port_mode(struct netxen_adapter *adapter)
365{
366 u32 val, data;
367
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000368 val = adapter->ahw.board_type;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700369 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
370 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
371 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
372 data = NETXEN_PORT_MODE_802_3_AP;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000373 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700374 } else if (port_mode == NETXEN_PORT_MODE_XG) {
375 data = NETXEN_PORT_MODE_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000376 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700377 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
378 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000379 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700380 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
381 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000382 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700383 } else {
384 data = NETXEN_PORT_MODE_AUTO_NEG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000385 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700386 }
387
388 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
389 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
390 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
391 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
392 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
393 }
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000394 NXWR32(adapter, NETXEN_WOL_PORT_MODE, wol_port_mode);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700395 }
396}
397
Dhananjay Phadke29566402008-07-21 19:44:04 -0700398static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
399{
400 u32 control;
401 int pos;
402
403 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
404 if (pos) {
405 pci_read_config_dword(pdev, pos, &control);
406 if (enable)
407 control |= PCI_MSIX_FLAGS_ENABLE;
408 else
409 control = 0;
410 pci_write_config_dword(pdev, pos, control);
411 }
412}
413
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000414static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700415{
416 int i;
417
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000418 for (i = 0; i < count; i++)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700419 adapter->msix_entries[i].entry = i;
420}
421
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700422static int
423netxen_read_mac_addr(struct netxen_adapter *adapter)
424{
425 int i;
426 unsigned char *p;
427 __le64 mac_addr;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700428 struct net_device *netdev = adapter->netdev;
429 struct pci_dev *pdev = adapter->pdev;
430
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700431 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
432 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
433 return -EIO;
434 } else {
435 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
436 return -EIO;
437 }
438
439 p = (unsigned char *)&mac_addr;
440 for (i = 0; i < 6; i++)
441 netdev->dev_addr[i] = *(p + 5 - i);
442
443 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
444
445 /* set station address */
446
Johannes Berge1749612008-10-27 15:59:26 -0700447 if (!is_valid_ether_addr(netdev->perm_addr))
448 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700449
450 return 0;
451}
452
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000453int netxen_nic_set_mac(struct net_device *netdev, void *p)
454{
455 struct netxen_adapter *adapter = netdev_priv(netdev);
456 struct sockaddr *addr = p;
457
458 if (!is_valid_ether_addr(addr->sa_data))
459 return -EINVAL;
460
461 if (netif_running(netdev)) {
462 netif_device_detach(netdev);
463 netxen_napi_disable(adapter);
464 }
465
466 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
467 adapter->macaddr_set(adapter, addr->sa_data);
468
469 if (netif_running(netdev)) {
470 netif_device_attach(netdev);
471 netxen_napi_enable(adapter);
472 }
473 return 0;
474}
475
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800476static void netxen_set_multicast_list(struct net_device *dev)
477{
478 struct netxen_adapter *adapter = netdev_priv(dev);
479
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000480 adapter->set_multi(dev);
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800481}
482
483static const struct net_device_ops netxen_netdev_ops = {
484 .ndo_open = netxen_nic_open,
485 .ndo_stop = netxen_nic_close,
486 .ndo_start_xmit = netxen_nic_xmit_frame,
487 .ndo_get_stats = netxen_nic_get_stats,
488 .ndo_validate_addr = eth_validate_addr,
489 .ndo_set_multicast_list = netxen_set_multicast_list,
490 .ndo_set_mac_address = netxen_nic_set_mac,
491 .ndo_change_mtu = netxen_nic_change_mtu,
492 .ndo_tx_timeout = netxen_tx_timeout,
493#ifdef CONFIG_NET_POLL_CONTROLLER
494 .ndo_poll_controller = netxen_nic_poll_controller,
495#endif
496};
497
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800498static void
499netxen_setup_intr(struct netxen_adapter *adapter)
500{
501 struct netxen_legacy_intr_set *legacy_intrp;
502 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000503 int err, num_msix;
504
505 if (adapter->rss_supported) {
506 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
507 MSIX_ENTRIES_PER_ADAPTER : 2;
508 } else
509 num_msix = 1;
510
511 adapter->max_sds_rings = 1;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800512
513 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800514
515 if (adapter->ahw.revision_id >= NX_P3_B0)
516 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
517 else
518 legacy_intrp = &legacy_intr[0];
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000519
520 adapter->int_vec_bit = legacy_intrp->int_vec_bit;
521 adapter->tgt_status_reg = netxen_get_ioaddr(adapter,
522 legacy_intrp->tgt_status_reg);
523 adapter->tgt_mask_reg = netxen_get_ioaddr(adapter,
524 legacy_intrp->tgt_mask_reg);
525 adapter->pci_int_reg = netxen_get_ioaddr(adapter,
526 legacy_intrp->pci_int_reg);
527 adapter->isr_int_vec = netxen_get_ioaddr(adapter, ISR_INT_VECTOR);
528
529 if (adapter->ahw.revision_id >= NX_P3_B1)
530 adapter->crb_int_state_reg = netxen_get_ioaddr(adapter,
531 ISR_INT_STATE_REG);
532 else
533 adapter->crb_int_state_reg = netxen_get_ioaddr(adapter,
534 CRB_INT_VECTOR);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800535
536 netxen_set_msix_bit(pdev, 0);
537
538 if (adapter->msix_supported) {
539
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000540 netxen_init_msix_entries(adapter, num_msix);
541 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
542 if (err == 0) {
543 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
544 netxen_set_msix_bit(pdev, 1);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800545
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000546 if (adapter->rss_supported)
547 adapter->max_sds_rings = num_msix;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800548
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000549 dev_info(&pdev->dev, "using msi-x interrupts\n");
550 return;
551 }
552
553 if (err > 0)
554 pci_disable_msix(pdev);
555
556 /* fall through for msi */
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800557 }
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000558
559 if (use_msi && !pci_enable_msi(pdev)) {
560 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000561 adapter->tgt_status_reg = netxen_get_ioaddr(adapter,
562 msi_tgt_status[adapter->ahw.pci_func]);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000563 dev_info(&pdev->dev, "using msi interrupts\n");
Dhananjay Phadkef67f3402009-05-18 21:46:40 -0700564 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000565 return;
566 }
567
568 dev_info(&pdev->dev, "using legacy interrupts\n");
569 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800570}
571
572static void
573netxen_teardown_intr(struct netxen_adapter *adapter)
574{
575 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
576 pci_disable_msix(adapter->pdev);
577 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
578 pci_disable_msi(adapter->pdev);
579}
580
581static void
582netxen_cleanup_pci_map(struct netxen_adapter *adapter)
583{
584 if (adapter->ahw.db_base != NULL)
585 iounmap(adapter->ahw.db_base);
586 if (adapter->ahw.pci_base0 != NULL)
587 iounmap(adapter->ahw.pci_base0);
588 if (adapter->ahw.pci_base1 != NULL)
589 iounmap(adapter->ahw.pci_base1);
590 if (adapter->ahw.pci_base2 != NULL)
591 iounmap(adapter->ahw.pci_base2);
592}
593
594static int
595netxen_setup_pci_map(struct netxen_adapter *adapter)
596{
597 void __iomem *mem_ptr0 = NULL;
598 void __iomem *mem_ptr1 = NULL;
599 void __iomem *mem_ptr2 = NULL;
600 void __iomem *db_ptr = NULL;
601
Dhananjay Phadke71fb62f2009-10-13 00:26:04 -0700602 resource_size_t mem_base, db_base;
603 unsigned long mem_len, db_len = 0, pci_len0 = 0;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800604
605 struct pci_dev *pdev = adapter->pdev;
606 int pci_func = adapter->ahw.pci_func;
607
608 int err = 0;
609
610 /*
611 * Set the CRB window to invalid. If any register in window 0 is
612 * accessed it should set the window to 0 and then reset it to 1.
613 */
Dhananjay Phadke907fa122009-10-13 05:31:43 +0000614 adapter->ahw.crb_win = -1;
Dhananjay Phadke47abe352009-10-13 05:31:42 +0000615 adapter->ahw.ocm_win = -1;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800616
617 /* remap phys address */
618 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
619 mem_len = pci_resource_len(pdev, 0);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800620
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800621 /* 128 Meg of memory */
622 if (mem_len == NETXEN_PCI_128MB_SIZE) {
623 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
624 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
625 SECOND_PAGE_GROUP_SIZE);
626 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
627 THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke47abe352009-10-13 05:31:42 +0000628 pci_len0 = FIRST_PAGE_GROUP_SIZE;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800629 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
630 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
631 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
632 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800633 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800634
635 mem_ptr0 = pci_ioremap_bar(pdev, 0);
636 if (mem_ptr0 == NULL) {
637 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
638 return -EIO;
639 }
640 pci_len0 = mem_len;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800641 } else {
642 return -EIO;
643 }
644
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000645 netxen_setup_hwops(adapter);
646
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800647 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
648
649 adapter->ahw.pci_base0 = mem_ptr0;
650 adapter->ahw.pci_len0 = pci_len0;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800651 adapter->ahw.pci_base1 = mem_ptr1;
652 adapter->ahw.pci_base2 = mem_ptr2;
653
Amit Kumar Salecha6abb4b82009-10-16 15:50:09 +0000654 if (NX_IS_REVISION_P3P(adapter->ahw.revision_id)) {
655 adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter,
656 NETXEN_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(pci_func)));
657
658 } else if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadke47abe352009-10-13 05:31:42 +0000659 adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter,
660 NETXEN_PCIX_PS_REG(PCIE_MN_WINDOW_REG(pci_func)));
661 }
662
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800663 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
664 goto skip_doorbell;
665
666 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
667 db_len = pci_resource_len(pdev, 4);
668
669 if (db_len == 0) {
670 printk(KERN_ERR "%s: doorbell is disabled\n",
671 netxen_nic_driver_name);
672 err = -EIO;
673 goto err_out;
674 }
675
676 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
677 if (!db_ptr) {
678 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
679 netxen_nic_driver_name);
680 err = -EIO;
681 goto err_out;
682 }
683
684skip_doorbell:
685 adapter->ahw.db_base = db_ptr;
686 adapter->ahw.db_len = db_len;
687 return 0;
688
689err_out:
690 netxen_cleanup_pci_map(adapter);
691 return err;
692}
693
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000694static void
695netxen_check_options(struct netxen_adapter *adapter)
696{
697 u32 fw_major, fw_minor, fw_build;
698 char brd_name[NETXEN_MAX_SHORT_NAME];
699 char serial_num[32];
700 int i, offset, val;
701 int *ptr32;
702 struct pci_dev *pdev = adapter->pdev;
703
704 adapter->driver_mismatch = 0;
705
706 ptr32 = (int *)&serial_num;
707 offset = NX_FW_SERIAL_NUM_OFFSET;
708 for (i = 0; i < 8; i++) {
709 if (netxen_rom_fast_read(adapter, offset, &val) == -1) {
710 dev_err(&pdev->dev, "error reading board info\n");
711 adapter->driver_mismatch = 1;
712 return;
713 }
714 ptr32[i] = cpu_to_le32(val);
715 offset += sizeof(u32);
716 }
717
718 fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
719 fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
720 fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
721
722 adapter->fw_version = NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build);
723
724 if (adapter->portnum == 0) {
725 get_brd_name_by_type(adapter->ahw.board_type, brd_name);
726
727 printk(KERN_INFO "NetXen %s Board S/N %s Chip rev 0x%x\n",
728 brd_name, serial_num, adapter->ahw.revision_id);
729 }
730
731 if (adapter->fw_version < NETXEN_VERSION_CODE(3, 4, 216)) {
732 adapter->driver_mismatch = 1;
733 dev_warn(&pdev->dev, "firmware version %d.%d.%d unsupported\n",
734 fw_major, fw_minor, fw_build);
735 return;
736 }
737
738 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
739 i = NXRD32(adapter, NETXEN_SRE_MISC);
740 adapter->ahw.cut_through = (i & 0x8000) ? 1 : 0;
741 }
742
743 dev_info(&pdev->dev, "firmware v%d.%d.%d [%s]\n",
744 fw_major, fw_minor, fw_build,
745 adapter->ahw.cut_through ? "cut-through" : "legacy");
746
747 if (adapter->fw_version >= NETXEN_VERSION_CODE(4, 0, 222))
748 adapter->capabilities = NXRD32(adapter, CRB_FW_CAPABILITIES_1);
749
750 adapter->flags &= ~NETXEN_NIC_LRO_ENABLED;
751
752 if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
753 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
754 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
755 } else if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
756 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
757 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
758 }
759
760 adapter->msix_supported = 0;
761 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
762 adapter->msix_supported = !!use_msi_x;
763 adapter->rss_supported = !!use_msi_x;
764 } else if (adapter->fw_version >= NETXEN_VERSION_CODE(3, 4, 336)) {
765 switch (adapter->ahw.board_type) {
766 case NETXEN_BRDTYPE_P2_SB31_10G:
767 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
768 adapter->msix_supported = !!use_msi_x;
769 adapter->rss_supported = !!use_msi_x;
770 break;
771 default:
772 break;
773 }
774 }
775
776 adapter->num_txd = MAX_CMD_DESCRIPTORS;
777
778 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
779 adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS;
780 adapter->max_rds_rings = 3;
781 } else {
782 adapter->num_lro_rxd = 0;
783 adapter->max_rds_rings = 2;
784 }
785}
786
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800787static int
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000788netxen_start_firmware(struct netxen_adapter *adapter)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800789{
790 int val, err, first_boot;
791 struct pci_dev *pdev = adapter->pdev;
792
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000793 /* required for NX2031 dummy dma */
794 err = nx_set_dma_mask(adapter);
795 if (err)
796 return err;
797
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000798 if (!netxen_can_start_firmware(adapter))
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000799 goto wait_init;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000800
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000801 first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800802
803 err = netxen_check_hw_init(adapter, first_boot);
804 if (err) {
805 dev_err(&pdev->dev, "error in init HW init sequence\n");
806 return err;
807 }
808
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000809 netxen_request_firmware(adapter);
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000810
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000811 err = netxen_need_fw_reset(adapter);
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000812 if (err < 0)
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000813 goto err_out;
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000814 if (err == 0)
Dhananjay Phadkeec5c50c2009-09-11 11:28:13 +0000815 goto ready;
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000816
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800817 if (first_boot != 0x55555555) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000818 NXWR32(adapter, CRB_CMDPEG_STATE, 0);
Amit Kumar Salecha0be367b2009-10-16 15:50:08 +0000819 netxen_pinit_from_rom(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800820 msleep(1);
821 }
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000822
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000823 NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000824 NXWR32(adapter, NETXEN_PEG_HALT_STATUS1, 0);
825 NXWR32(adapter, NETXEN_PEG_HALT_STATUS2, 0);
826
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000827 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
828 netxen_set_port_mode(adapter);
829
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000830 err = netxen_load_firmware(adapter);
831 if (err)
832 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800833
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000834 netxen_release_firmware(adapter);
835
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800836 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
837
838 /* Initialize multicast addr pool owners */
839 val = 0x7654;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000840 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800841 val |= 0x0f000000;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000842 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800843
844 }
845
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000846 err = netxen_init_dummy_dma(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800847 if (err)
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000848 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800849
850 /*
851 * Tell the hardware our version number.
852 */
853 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
854 | ((_NETXEN_NIC_LINUX_MINOR << 8))
855 | (_NETXEN_NIC_LINUX_SUBVERSION);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000856 NXWR32(adapter, CRB_DRIVER_VERSION, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800857
Dhananjay Phadkeec5c50c2009-09-11 11:28:13 +0000858ready:
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000859 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_READY);
860
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000861wait_init:
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800862 /* Handshake with the card before we register the devices. */
863 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
864 if (err) {
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000865 netxen_free_dummy_dma(adapter);
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000866 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800867 }
868
Dhananjay Phadke68b3cae2009-07-26 20:07:36 +0000869 nx_update_dma_mask(adapter);
870
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000871 netxen_check_options(adapter);
Dhananjay Phadke68b3cae2009-07-26 20:07:36 +0000872
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +0000873 adapter->need_fw_reset = 0;
874
Dhananjay Phadkeec5c50c2009-09-11 11:28:13 +0000875 /* fall through and release firmware */
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000876
877err_out:
878 netxen_release_firmware(adapter);
879 return err;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800880}
881
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000882static int
883netxen_nic_request_irq(struct netxen_adapter *adapter)
884{
885 irq_handler_t handler;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000886 struct nx_host_sds_ring *sds_ring;
887 int err, ring;
888
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000889 unsigned long flags = IRQF_SAMPLE_RANDOM;
890 struct net_device *netdev = adapter->netdev;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000891 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000892
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000893 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
894 handler = netxen_msix_intr;
895 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
896 handler = netxen_msi_intr;
897 else {
898 flags |= IRQF_SHARED;
899 handler = netxen_intr;
900 }
901 adapter->irq = netdev->irq;
902
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000903 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
904 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000905 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000906 err = request_irq(sds_ring->irq, handler,
907 flags, sds_ring->name, sds_ring);
908 if (err)
909 return err;
910 }
911
912 return 0;
913}
914
915static void
916netxen_nic_free_irq(struct netxen_adapter *adapter)
917{
918 int ring;
919 struct nx_host_sds_ring *sds_ring;
920
921 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
922
923 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
924 sds_ring = &recv_ctx->sds_rings[ring];
925 free_irq(sds_ring->irq, sds_ring);
926 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000927}
928
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000929static void
930netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter)
931{
932 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
933 adapter->coal.normal.data.rx_time_us =
934 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
935 adapter->coal.normal.data.rx_packets =
936 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
937 adapter->coal.normal.data.tx_time_us =
938 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US;
939 adapter->coal.normal.data.tx_packets =
940 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS;
941}
942
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000943static int
944netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
945{
946 int err;
947
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000948 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
949 return -EIO;
950
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000951 err = adapter->init_port(adapter, adapter->physical_port);
952 if (err) {
953 printk(KERN_ERR "%s: Failed to initialize port %d\n",
954 netxen_nic_driver_name, adapter->portnum);
955 return err;
956 }
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000957 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
958 adapter->macaddr_set(adapter, netdev->dev_addr);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000959
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000960 adapter->set_multi(netdev);
961 adapter->set_mtu(adapter, netdev->mtu);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000962
963 adapter->ahw.linkup = 0;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000964
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000965 if (adapter->max_sds_rings > 1)
966 netxen_config_rss(adapter, 1);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000967
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000968 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
969 netxen_config_intr_coalesce(adapter);
970
Narender Kumar1bb482f2009-08-23 08:35:09 +0000971 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
972 netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED);
973
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000974 netxen_napi_enable(adapter);
975
Dhananjay Phadke5103c9f2009-04-28 15:29:09 +0000976 if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000977 netxen_linkevent_request(adapter, 1);
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000978 else
979 netxen_nic_set_link_parameters(adapter);
980
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000981 set_bit(__NX_DEV_UP, &adapter->state);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000982 return 0;
983}
984
985static void
986netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
987{
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000988 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
989 return;
990
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000991 clear_bit(__NX_DEV_UP, &adapter->state);
992
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000993 spin_lock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000994 netif_carrier_off(netdev);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000995 netif_tx_disable(netdev);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000996
997 if (adapter->stop_port)
998 adapter->stop_port(adapter);
999
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +00001000 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1001 netxen_p3_free_mac_list(adapter);
1002
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001003 adapter->set_promisc(adapter, NETXEN_NIU_NON_PROMISC_MODE);
1004
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +00001005 netxen_napi_disable(adapter);
1006
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001007 netxen_release_tx_buffers(adapter);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001008 spin_unlock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001009}
1010
1011
1012static int
1013netxen_nic_attach(struct netxen_adapter *adapter)
1014{
1015 struct net_device *netdev = adapter->netdev;
1016 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +00001017 int err, ring;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001018 struct nx_host_rds_ring *rds_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001019 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001020
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001021 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
1022 return 0;
1023
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001024 err = netxen_init_firmware(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +00001025 if (err)
1026 return err;
1027
1028 err = netxen_napi_add(adapter, netdev);
1029 if (err)
1030 return err;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001031
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001032 err = netxen_alloc_sw_resources(adapter);
1033 if (err) {
1034 printk(KERN_ERR "%s: Error in setting sw resources\n",
1035 netdev->name);
1036 return err;
1037 }
1038
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001039 err = netxen_alloc_hw_resources(adapter);
1040 if (err) {
1041 printk(KERN_ERR "%s: Error in setting hw resources\n",
1042 netdev->name);
1043 goto err_out_free_sw;
1044 }
1045
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001046 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001047 tx_ring = adapter->tx_ring;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001048 tx_ring->crb_cmd_producer = netxen_get_ioaddr(adapter,
1049 crb_cmd_producer[adapter->portnum]);
1050 tx_ring->crb_cmd_consumer = netxen_get_ioaddr(adapter,
1051 crb_cmd_consumer[adapter->portnum]);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001052
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001053 tx_ring->producer = 0;
1054 tx_ring->sw_consumer = 0;
1055
1056 netxen_nic_update_cmd_producer(adapter, tx_ring);
1057 netxen_nic_update_cmd_consumer(adapter, tx_ring);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001058 }
1059
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001060 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1061 rds_ring = &adapter->recv_ctx.rds_rings[ring];
1062 netxen_post_rx_buffers(adapter, ring, rds_ring);
1063 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001064
1065 err = netxen_nic_request_irq(adapter);
1066 if (err) {
1067 dev_err(&pdev->dev, "%s: failed to setup interrupt\n",
1068 netdev->name);
1069 goto err_out_free_rxbuf;
1070 }
1071
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +00001072 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1073 netxen_nic_init_coalesce_defaults(adapter);
1074
Narender Kumarfa3ce352009-08-24 19:23:28 +00001075 netxen_create_sysfs_entries(adapter);
1076
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001077 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1078 return 0;
1079
1080err_out_free_rxbuf:
1081 netxen_release_rx_buffers(adapter);
1082 netxen_free_hw_resources(adapter);
1083err_out_free_sw:
1084 netxen_free_sw_resources(adapter);
1085 return err;
1086}
1087
1088static void
1089netxen_nic_detach(struct netxen_adapter *adapter)
1090{
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001091 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1092 return;
1093
Narender Kumarfa3ce352009-08-24 19:23:28 +00001094 netxen_remove_sysfs_entries(adapter);
1095
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001096 netxen_free_hw_resources(adapter);
Dhananjay Phadkecf981ff2009-07-17 15:27:06 +00001097 netxen_release_rx_buffers(adapter);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +00001098 netxen_nic_free_irq(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +00001099 netxen_napi_del(adapter);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001100 netxen_free_sw_resources(adapter);
1101
1102 adapter->is_up = 0;
1103}
1104
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001105int
1106netxen_nic_reset_context(struct netxen_adapter *adapter)
1107{
1108 int err = 0;
1109 struct net_device *netdev = adapter->netdev;
1110
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001111 if (test_and_set_bit(__NX_RESETTING, &adapter->state))
1112 return -EBUSY;
1113
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001114 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
1115
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001116 netif_device_detach(netdev);
1117
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001118 if (netif_running(netdev))
1119 netxen_nic_down(adapter, netdev);
1120
1121 netxen_nic_detach(adapter);
1122
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001123 if (netif_running(netdev)) {
1124 err = netxen_nic_attach(adapter);
1125 if (!err)
1126 err = netxen_nic_up(adapter, netdev);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001127
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001128 if (err)
1129 goto done;
1130 }
1131
1132 netif_device_attach(netdev);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001133 }
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001134
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001135done:
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001136 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001137 return err;
1138}
1139
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001140static int
1141netxen_setup_netdev(struct netxen_adapter *adapter,
1142 struct net_device *netdev)
1143{
1144 int err = 0;
1145 struct pci_dev *pdev = adapter->pdev;
1146
1147 adapter->rx_csum = 1;
1148 adapter->mc_enabled = 0;
1149 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1150 adapter->max_mc_count = 38;
1151 else
1152 adapter->max_mc_count = 16;
1153
1154 netdev->netdev_ops = &netxen_netdev_ops;
1155 netdev->watchdog_timeo = 2*HZ;
1156
1157 netxen_nic_change_mtu(netdev, netdev->mtu);
1158
1159 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
1160
1161 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1162 netdev->features |= (NETIF_F_GRO);
1163 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1164
1165 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1166 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1167 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1168 }
1169
1170 if (adapter->pci_using_dac) {
1171 netdev->features |= NETIF_F_HIGHDMA;
1172 netdev->vlan_features |= NETIF_F_HIGHDMA;
1173 }
1174
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001175 if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX)
1176 netdev->features |= (NETIF_F_HW_VLAN_TX);
1177
Narender Kumar1bb482f2009-08-23 08:35:09 +00001178 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
1179 netdev->features |= NETIF_F_LRO;
1180
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001181 netdev->irq = adapter->msix_entries[0].vector;
1182
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001183 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001184
1185 if (netxen_read_mac_addr(adapter))
1186 dev_warn(&pdev->dev, "failed to read mac addr\n");
1187
1188 netif_carrier_off(netdev);
1189 netif_stop_queue(netdev);
1190
1191 err = register_netdev(netdev);
1192 if (err) {
1193 dev_err(&pdev->dev, "failed to register net device\n");
1194 return err;
1195 }
1196
1197 return 0;
1198}
1199
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001200static int __devinit
1201netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1202{
1203 struct net_device *netdev = NULL;
1204 struct netxen_adapter *adapter = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001205 int i = 0, err;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001206 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001207 uint8_t revision_id;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001208
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001209 if (pdev->class != 0x020000) {
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001210 printk(KERN_DEBUG "NetXen function %d, class %x will not "
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001211 "be enabled.\n",pci_func_id, pdev->class);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001212 return -ENODEV;
1213 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001214
Dhananjay Phadke11d89d62008-08-08 00:08:45 -07001215 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
1216 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
1217 "will not be enabled.\n",
1218 NX_P3_A0, NX_P3_B1);
1219 return -ENODEV;
1220 }
1221
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001222 if ((err = pci_enable_device(pdev)))
1223 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001224
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001225 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1226 err = -ENODEV;
1227 goto err_out_disable_pdev;
1228 }
1229
1230 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
1231 goto err_out_disable_pdev;
1232
1233 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001234
1235 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
1236 if(!netdev) {
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001237 dev_err(&pdev->dev, "failed to allocate net_device\n");
1238 err = -ENOMEM;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001239 goto err_out_free_res;
1240 }
1241
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001242 SET_NETDEV_DEV(netdev, &pdev->dev);
1243
Wang Chen4cf16532008-11-12 23:38:14 -08001244 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001245 adapter->netdev = netdev;
1246 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001247 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001248
1249 revision_id = pdev->revision;
1250 adapter->ahw.revision_id = revision_id;
1251
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001252 rwlock_init(&adapter->ahw.crb_lock);
1253 spin_lock_init(&adapter->ahw.mem_lock);
1254
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001255 spin_lock_init(&adapter->tx_clean_lock);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +00001256 INIT_LIST_HEAD(&adapter->mac_list);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001257
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001258 err = netxen_setup_pci_map(adapter);
1259 if (err)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001260 goto err_out_free_netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001261
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +05301262 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001263 adapter->portnum = pci_func_id;
1264
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001265 err = netxen_nic_get_board_info(adapter);
1266 if (err) {
1267 dev_err(&pdev->dev, "Error getting board config info.\n");
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001268 goto err_out_iounmap;
1269 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001270
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001271 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001272 switch (adapter->ahw.board_type) {
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001273 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1274 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1275 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001276 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001277 break;
1278 default:
1279 break;
1280 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001281
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001282 err = netxen_start_firmware(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001283 if (err)
1284 goto err_out_iounmap;
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001285
Dhananjay Phadke29566402008-07-21 19:44:04 -07001286 /*
1287 * See if the firmware gave us a virtual-physical port mapping.
1288 */
1289 adapter->physical_port = adapter->portnum;
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001290 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001291 i = NXRD32(adapter, CRB_V2P(adapter->portnum));
Dhananjay Phadke044fad02009-02-24 03:42:59 -08001292 if (i != 0x55555555)
1293 adapter->physical_port = i;
1294 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001295
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001296 netxen_nic_clear_stats(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001297
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001298 netxen_setup_intr(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001299
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001300 err = netxen_setup_netdev(adapter, netdev);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001301 if (err)
Dhananjay Phadke29566402008-07-21 19:44:04 -07001302 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001303
1304 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001305
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001306 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
1307
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001308 switch (adapter->ahw.port_type) {
Dhananjay Phadke29566402008-07-21 19:44:04 -07001309 case NETXEN_NIC_GBE:
1310 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1311 adapter->netdev->name);
1312 break;
1313 case NETXEN_NIC_XGBE:
1314 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1315 adapter->netdev->name);
1316 break;
1317 }
1318
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00001319 netxen_create_diag_entries(adapter);
1320
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001321 return 0;
1322
Dhananjay Phadke29566402008-07-21 19:44:04 -07001323err_out_disable_msi:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001324 netxen_teardown_intr(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001325
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001326 netxen_free_dummy_dma(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001327
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001328 nx_decr_dev_ref_cnt(adapter);
1329
Dhananjay Phadke29566402008-07-21 19:44:04 -07001330err_out_iounmap:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001331 netxen_cleanup_pci_map(adapter);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001332
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001333err_out_free_netdev:
1334 free_netdev(netdev);
1335
1336err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001337 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001338
1339err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001340 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001341 pci_disable_device(pdev);
1342 return err;
1343}
1344
1345static void __devexit netxen_nic_remove(struct pci_dev *pdev)
1346{
1347 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001348 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001349
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001350 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001351 if (adapter == NULL)
1352 return;
1353
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001354 netdev = adapter->netdev;
1355
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001356 netxen_cancel_fw_work(adapter);
1357
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301358 unregister_netdev(netdev);
1359
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001360 cancel_work_sync(&adapter->tx_timeout_task);
1361
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001362 netxen_nic_detach(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001363
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001364 nx_decr_dev_ref_cnt(adapter);
1365
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001366 if (adapter->portnum == 0)
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001367 netxen_free_dummy_dma(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301368
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001369 clear_bit(__NX_RESETTING, &adapter->state);
1370
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001371 netxen_teardown_intr(adapter);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301372
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00001373 netxen_remove_diag_entries(adapter);
1374
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001375 netxen_cleanup_pci_map(adapter);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001376
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001377 netxen_release_firmware(adapter);
1378
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001379 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301380 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001381 pci_set_drvdata(pdev, NULL);
1382
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001383 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001384}
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001385static int __netxen_nic_shutdown(struct pci_dev *pdev)
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001386{
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001387 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1388 struct net_device *netdev = adapter->netdev;
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001389 int retval;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001390
1391 netif_device_detach(netdev);
1392
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001393 netxen_cancel_fw_work(adapter);
1394
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001395 if (netif_running(netdev))
1396 netxen_nic_down(adapter, netdev);
1397
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001398 cancel_work_sync(&adapter->tx_timeout_task);
1399
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001400 netxen_nic_detach(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001401
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001402 if (adapter->portnum == 0)
1403 netxen_free_dummy_dma(adapter);
1404
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001405 nx_decr_dev_ref_cnt(adapter);
1406
1407 clear_bit(__NX_RESETTING, &adapter->state);
1408
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001409 retval = pci_save_state(pdev);
1410 if (retval)
1411 return retval;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001412
1413 if (netxen_nic_wol_supported(adapter)) {
1414 pci_enable_wake(pdev, PCI_D3cold, 1);
1415 pci_enable_wake(pdev, PCI_D3hot, 1);
1416 }
1417
1418 pci_disable_device(pdev);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001419
1420 return 0;
1421}
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001422static void netxen_nic_shutdown(struct pci_dev *pdev)
1423{
1424 if (__netxen_nic_shutdown(pdev))
1425 return;
1426}
1427#ifdef CONFIG_PM
1428static int
1429netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
1430{
1431 int retval;
1432
1433 retval = __netxen_nic_shutdown(pdev);
1434 if (retval)
1435 return retval;
1436
1437 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1438 return 0;
1439}
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001440
1441static int
1442netxen_nic_resume(struct pci_dev *pdev)
1443{
1444 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1445 struct net_device *netdev = adapter->netdev;
1446 int err;
1447
1448 pci_set_power_state(pdev, PCI_D0);
1449 pci_restore_state(pdev);
1450
1451 err = pci_enable_device(pdev);
1452 if (err)
1453 return err;
1454
Dhananjay Phadke907fa122009-10-13 05:31:43 +00001455 adapter->ahw.crb_win = -1;
Dhananjay Phadke47abe352009-10-13 05:31:42 +00001456 adapter->ahw.ocm_win = -1;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001457
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001458 err = netxen_start_firmware(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001459 if (err) {
1460 dev_err(&pdev->dev, "failed to start firmware\n");
1461 return err;
1462 }
1463
1464 if (netif_running(netdev)) {
1465 err = netxen_nic_attach(adapter);
1466 if (err)
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001467 goto err_out;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001468
1469 err = netxen_nic_up(adapter, netdev);
1470 if (err)
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001471 goto err_out_detach;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001472
1473 netif_device_attach(netdev);
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00001474
1475 netxen_config_indev_addr(netdev, NETDEV_UP);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001476 }
1477
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001478 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
Dhananjay Phadke07653aa2009-09-20 19:20:39 +00001479 return 0;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001480
1481err_out_detach:
1482 netxen_nic_detach(adapter);
1483err_out:
1484 nx_decr_dev_ref_cnt(adapter);
1485 return err;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001486}
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00001487#endif
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001488
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001489static int netxen_nic_open(struct net_device *netdev)
1490{
Wang Chen4cf16532008-11-12 23:38:14 -08001491 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001492 int err = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001493
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001494 if (adapter->driver_mismatch)
1495 return -EIO;
1496
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001497 err = netxen_nic_attach(adapter);
1498 if (err)
1499 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001500
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001501 err = netxen_nic_up(adapter, netdev);
1502 if (err)
1503 goto err_out;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001504
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001505 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001506
1507 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001508
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001509err_out:
1510 netxen_nic_detach(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001511 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001512}
1513
1514/*
1515 * netxen_nic_close - Disables a network interface entry point
1516 */
1517static int netxen_nic_close(struct net_device *netdev)
1518{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001519 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001520
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001521 netxen_nic_down(adapter, netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001522 return 0;
1523}
1524
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001525static void
1526netxen_tso_check(struct net_device *netdev,
1527 struct nx_host_tx_ring *tx_ring,
1528 struct cmd_desc_type0 *first_desc,
1529 struct sk_buff *skb)
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001530{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001531 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001532 __be16 protocol = skb->protocol;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001533 u16 flags = 0, vid = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001534 u32 producer;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001535 int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001536 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001537 struct vlan_ethhdr *vh;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001538
Harvey Harrison09640e62009-02-01 00:45:17 -08001539 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001540
1541 vh = (struct vlan_ethhdr *)skb->data;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001542 protocol = vh->h_vlan_encapsulated_proto;
1543 flags = FLAGS_VLAN_TAGGED;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001544
1545 } else if (vlan_tx_tag_present(skb)) {
1546
1547 flags = FLAGS_VLAN_OOB;
1548 vid = vlan_tx_tag_get(skb);
1549 netxen_set_tx_vlan_tci(first_desc, vid);
1550 vlan_oob = 1;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001551 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001552
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001553 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1554 skb_shinfo(skb)->gso_size > 0) {
1555
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001556 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1557
1558 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1559 first_desc->total_hdr_length = hdr_len;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001560 if (vlan_oob) {
1561 first_desc->total_hdr_length += VLAN_HLEN;
1562 first_desc->tcp_hdr_offset = VLAN_HLEN;
1563 first_desc->ip_hdr_offset = VLAN_HLEN;
1564 /* Only in case of TSO on vlan device */
1565 flags |= FLAGS_VLAN_TAGGED;
1566 }
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001567
Harvey Harrison09640e62009-02-01 00:45:17 -08001568 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001569 TX_TCP_LSO6 : TX_TCP_LSO;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001570 tso = 1;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001571
1572 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001573 u8 l4proto;
1574
Harvey Harrison09640e62009-02-01 00:45:17 -08001575 if (protocol == cpu_to_be16(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001576 l4proto = ip_hdr(skb)->protocol;
1577
1578 if (l4proto == IPPROTO_TCP)
1579 opcode = TX_TCP_PKT;
1580 else if(l4proto == IPPROTO_UDP)
1581 opcode = TX_UDP_PKT;
Harvey Harrison09640e62009-02-01 00:45:17 -08001582 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001583 l4proto = ipv6_hdr(skb)->nexthdr;
1584
1585 if (l4proto == IPPROTO_TCP)
1586 opcode = TX_TCPV6_PKT;
1587 else if(l4proto == IPPROTO_UDP)
1588 opcode = TX_UDPV6_PKT;
1589 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001590 }
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001591
1592 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
1593 first_desc->ip_hdr_offset += skb_network_offset(skb);
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001594 netxen_set_tx_flags_opcode(first_desc, flags, opcode);
1595
1596 if (!tso)
1597 return;
1598
1599 /* For LSO, we need to copy the MAC/IP/TCP headers into
1600 * the descriptor ring
1601 */
1602 producer = tx_ring->producer;
1603 copied = 0;
1604 offset = 2;
1605
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001606 if (vlan_oob) {
1607 /* Create a TSO vlan header template for firmware */
1608
1609 hwdesc = &tx_ring->desc_head[producer];
1610 tx_ring->cmd_buf_arr[producer].skb = NULL;
1611
1612 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1613 hdr_len + VLAN_HLEN);
1614
1615 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2);
1616 skb_copy_from_linear_data(skb, vh, 12);
1617 vh->h_vlan_proto = htons(ETH_P_8021Q);
1618 vh->h_vlan_TCI = htons(vid);
1619 skb_copy_from_linear_data_offset(skb, 12,
1620 (char *)vh + 16, copy_len - 16);
1621
Dhananjay Phadke545eb372009-08-05 07:34:07 +00001622 copied = copy_len - VLAN_HLEN;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001623 offset = 0;
1624
1625 producer = get_next_index(producer, tx_ring->num_desc);
1626 }
1627
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001628 while (copied < hdr_len) {
1629
1630 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1631 (hdr_len - copied));
1632
1633 hwdesc = &tx_ring->desc_head[producer];
1634 tx_ring->cmd_buf_arr[producer].skb = NULL;
1635
1636 skb_copy_from_linear_data_offset(skb, copied,
1637 (char *)hwdesc + offset, copy_len);
1638
1639 copied += copy_len;
1640 offset = 0;
1641
1642 producer = get_next_index(producer, tx_ring->num_desc);
1643 }
1644
1645 tx_ring->producer = producer;
1646 barrier();
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001647}
1648
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001649static int
1650netxen_map_tx_skb(struct pci_dev *pdev,
1651 struct sk_buff *skb, struct netxen_cmd_buffer *pbuf)
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001652{
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001653 struct netxen_skb_frag *nf;
1654 struct skb_frag_struct *frag;
1655 int i, nr_frags;
1656 dma_addr_t map;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001657
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001658 nr_frags = skb_shinfo(skb)->nr_frags;
1659 nf = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001660
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001661 map = pci_map_single(pdev, skb->data,
1662 skb_headlen(skb), PCI_DMA_TODEVICE);
1663 if (pci_dma_mapping_error(pdev, map))
1664 goto out_err;
1665
1666 nf->dma = map;
1667 nf->length = skb_headlen(skb);
1668
1669 for (i = 0; i < nr_frags; i++) {
1670 frag = &skb_shinfo(skb)->frags[i];
1671 nf = &pbuf->frag_array[i+1];
1672
1673 map = pci_map_page(pdev, frag->page, frag->page_offset,
1674 frag->size, PCI_DMA_TODEVICE);
1675 if (pci_dma_mapping_error(pdev, map))
1676 goto unwind;
1677
1678 nf->dma = map;
1679 nf->length = frag->size;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001680 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001681
1682 return 0;
1683
1684unwind:
Dhananjay Phadkecf503e82009-09-03 13:10:55 +00001685 while (--i >= 0) {
1686 nf = &pbuf->frag_array[i+1];
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001687 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
1688 }
1689
1690 nf = &pbuf->frag_array[0];
1691 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
1692
1693out_err:
1694 return -ENOMEM;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001695}
1696
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001697static inline void
1698netxen_clear_cmddesc(u64 *desc)
1699{
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001700 desc[0] = 0ULL;
1701 desc[2] = 0ULL;
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001702}
1703
Stephen Hemminger613573252009-08-31 19:50:58 +00001704static netdev_tx_t
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001705netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001706{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001707 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001708 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001709 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001710 struct netxen_skb_frag *buffrag;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001711 struct cmd_desc_type0 *hwdesc, *first_desc;
1712 struct pci_dev *pdev;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001713 int i, k;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001714
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001715 u32 producer;
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001716 int frag_count, no_of_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001717 u32 num_txd = tx_ring->num_desc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001718
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001719 frag_count = skb_shinfo(skb)->nr_frags + 1;
1720
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001721 /* 4 fragments per cmd des */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001722 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001723
Roel Kluinfa9859e2009-10-06 19:34:39 +00001724 if (unlikely(no_of_desc + 2 > netxen_tx_avail(tx_ring))) {
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001725 netif_stop_queue(netdev);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001726 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001727 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001728
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001729 producer = tx_ring->producer;
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001730 pbuf = &tx_ring->cmd_buf_arr[producer];
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001731
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001732 pdev = adapter->pdev;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001733
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001734 if (netxen_map_tx_skb(pdev, skb, pbuf))
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001735 goto drop_packet;
1736
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001737 pbuf->skb = skb;
1738 pbuf->frag_count = frag_count;
1739
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001740 first_desc = hwdesc = &tx_ring->desc_head[producer];
1741 netxen_clear_cmddesc((u64 *)hwdesc);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001742
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001743 netxen_set_tx_frags_len(first_desc, frag_count, skb->len);
1744 netxen_set_tx_port(first_desc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001745
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001746 for (i = 0; i < frag_count; i++) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001747
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001748 k = i % 4;
1749
1750 if ((k == 0) && (i > 0)) {
1751 /* move to next desc.*/
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001752 producer = get_next_index(producer, num_txd);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001753 hwdesc = &tx_ring->desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001754 netxen_clear_cmddesc((u64 *)hwdesc);
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001755 tx_ring->cmd_buf_arr[producer].skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001756 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001757
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001758 buffrag = &pbuf->frag_array[i];
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001759
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001760 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001761 switch (k) {
1762 case 0:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001763 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001764 break;
1765 case 1:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001766 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001767 break;
1768 case 2:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001769 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001770 break;
1771 case 3:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001772 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001773 break;
1774 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001775 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001776
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001777 tx_ring->producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001778
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001779 netxen_tso_check(netdev, tx_ring, first_desc, skb);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001780
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001781 netxen_nic_update_cmd_producer(adapter, tx_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001782
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001783 adapter->stats.txbytes += skb->len;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001784 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001785
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001786 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001787
1788drop_packet:
1789 adapter->stats.txdropped++;
1790 dev_kfree_skb_any(skb);
1791 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001792}
1793
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001794static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1795{
1796 struct net_device *netdev = adapter->netdev;
1797 uint32_t temp, temp_state, temp_val;
1798 int rv = 0;
1799
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001800 temp = NXRD32(adapter, CRB_TEMP_STATE);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001801
1802 temp_state = nx_get_temp_state(temp);
1803 temp_val = nx_get_temp_val(temp);
1804
1805 if (temp_state == NX_TEMP_PANIC) {
1806 printk(KERN_ALERT
1807 "%s: Device temperature %d degrees C exceeds"
1808 " maximum allowed. Hardware has been shut down.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001809 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001810 rv = 1;
1811 } else if (temp_state == NX_TEMP_WARN) {
1812 if (adapter->temp == NX_TEMP_NORMAL) {
1813 printk(KERN_ALERT
1814 "%s: Device temperature %d degrees C "
1815 "exceeds operating range."
1816 " Immediate action needed.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001817 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001818 }
1819 } else {
1820 if (adapter->temp == NX_TEMP_WARN) {
1821 printk(KERN_INFO
1822 "%s: Device temperature is now %d degrees C"
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001823 " in normal range.\n", netdev->name,
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001824 temp_val);
1825 }
1826 }
1827 adapter->temp = temp_state;
1828 return rv;
1829}
1830
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001831void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup)
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001832{
1833 struct net_device *netdev = adapter->netdev;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001834
1835 if (adapter->ahw.linkup && !linkup) {
1836 printk(KERN_INFO "%s: %s NIC Link is down\n",
1837 netxen_nic_driver_name, netdev->name);
1838 adapter->ahw.linkup = 0;
1839 if (netif_running(netdev)) {
1840 netif_carrier_off(netdev);
1841 netif_stop_queue(netdev);
1842 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001843 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001844 } else if (!adapter->ahw.linkup && linkup) {
1845 printk(KERN_INFO "%s: %s NIC Link is up\n",
1846 netxen_nic_driver_name, netdev->name);
1847 adapter->ahw.linkup = 1;
1848 if (netif_running(netdev)) {
1849 netif_carrier_on(netdev);
1850 netif_wake_queue(netdev);
1851 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001852 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001853 }
1854}
1855
1856static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1857{
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001858 u32 val, port, linkup;
1859
1860 port = adapter->physical_port;
1861
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001862 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001863 val = NXRD32(adapter, CRB_XG_STATE_P3);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001864 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1865 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001866 } else {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001867 val = NXRD32(adapter, CRB_XG_STATE);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001868 if (adapter->ahw.port_type == NETXEN_NIC_GBE)
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001869 linkup = (val >> port) & 1;
1870 else {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001871 val = (val >> port*8) & 0xff;
1872 linkup = (val == XG_LINK_UP);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001873 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001874 }
1875
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001876 netxen_advert_link_change(adapter, linkup);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001877}
1878
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001879static void netxen_tx_timeout(struct net_device *netdev)
1880{
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001881 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001882
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001883 if (test_bit(__NX_RESETTING, &adapter->state))
1884 return;
1885
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001886 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001887 schedule_work(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001888}
1889
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001890static void netxen_tx_timeout_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001891{
Jeff Garzik47906542007-11-23 21:23:36 -05001892 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001893 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001894
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001895 if (!netif_running(adapter->netdev))
1896 return;
1897
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001898 if (test_and_set_bit(__NX_RESETTING, &adapter->state))
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001899 return;
1900
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001901 if (++adapter->tx_timeo_cnt >= NX_MAX_TX_TIMEOUTS)
1902 goto request_reset;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001903
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001904 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1905 /* try to scrub interrupt */
1906 netxen_napi_disable(adapter);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001907
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001908 adapter->netdev->trans_start = jiffies;
1909
1910 netxen_napi_enable(adapter);
1911
1912 netif_wake_queue(adapter->netdev);
1913
Dhananjay Phadkea598ae12009-09-20 19:20:38 +00001914 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001915
1916 } else {
Dhananjay Phadkea598ae12009-09-20 19:20:38 +00001917 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001918 if (!netxen_nic_reset_context(adapter)) {
1919 adapter->netdev->trans_start = jiffies;
Dhananjay Phadkea598ae12009-09-20 19:20:38 +00001920 return;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001921 }
1922
1923 /* context reset failed, fall through for fw reset */
1924 }
1925
1926request_reset:
1927 adapter->need_fw_reset = 1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001928}
1929
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001930struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1931{
1932 struct netxen_adapter *adapter = netdev_priv(netdev);
Ajit Khaparde5a4d6312009-10-07 02:45:34 +00001933 struct net_device_stats *stats = &netdev->stats;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001934
1935 memset(stats, 0, sizeof(*stats));
1936
Narender Kumar1bb482f2009-08-23 08:35:09 +00001937 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00001938 stats->tx_packets = adapter->stats.xmitfinished;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001939 stats->rx_bytes = adapter->stats.rxbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001940 stats->tx_bytes = adapter->stats.txbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001941 stats->rx_dropped = adapter->stats.rxdropped;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001942 stats->tx_dropped = adapter->stats.txdropped;
1943
1944 return stats;
1945}
1946
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001947static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001948{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001949 struct nx_host_sds_ring *sds_ring = data;
1950 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001951 u32 status = 0;
1952
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001953 status = readl(adapter->isr_int_vec);
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001954
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001955 if (!(status & adapter->int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001956 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301957
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001958 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001959 /* check interrupt state machine, to be sure */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001960 status = readl(adapter->crb_int_state_reg);
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001961 if (!ISR_LEGACY_INT_TRIGGERED(status))
1962 return IRQ_NONE;
1963
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001964 } else {
1965 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001966
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001967 our_int = readl(adapter->crb_int_state_reg);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001968
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001969 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001970 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001971 return IRQ_NONE;
1972
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001973 /* claim interrupt */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001974 writel((our_int & 0xffffffff), adapter->crb_int_state_reg);
1975
1976 /* clear interrupt */
1977 netxen_nic_disable_int(sds_ring);
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301978 }
1979
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001980 writel(0xffffffff, adapter->tgt_status_reg);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001981 /* read twice to ensure write is flushed */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001982 readl(adapter->isr_int_vec);
1983 readl(adapter->isr_int_vec);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001984
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001985 napi_schedule(&sds_ring->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001986
1987 return IRQ_HANDLED;
1988}
1989
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001990static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001991{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001992 struct nx_host_sds_ring *sds_ring = data;
1993 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001994
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001995 /* clear interrupt */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001996 writel(0xffffffff, adapter->tgt_status_reg);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001997
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001998 napi_schedule(&sds_ring->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001999 return IRQ_HANDLED;
2000}
2001
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08002002static irqreturn_t netxen_msix_intr(int irq, void *data)
2003{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002004 struct nx_host_sds_ring *sds_ring = data;
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08002005
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002006 napi_schedule(&sds_ring->napi);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08002007 return IRQ_HANDLED;
2008}
2009
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002010static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002011{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002012 struct nx_host_sds_ring *sds_ring =
2013 container_of(napi, struct nx_host_sds_ring, napi);
2014
2015 struct netxen_adapter *adapter = sds_ring->adapter;
2016
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002017 int tx_complete;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002018 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002019
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002020 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002021
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002022 work_done = netxen_process_rcv_ring(sds_ring, budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002023
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002024 if ((work_done < budget) && tx_complete) {
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002025 napi_complete(&sds_ring->napi);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00002026 if (netif_running(adapter->netdev))
2027 netxen_nic_enable_int(sds_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002028 }
2029
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002030 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002031}
2032
2033#ifdef CONFIG_NET_POLL_CONTROLLER
2034static void netxen_nic_poll_controller(struct net_device *netdev)
2035{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002036 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002037 disable_irq(adapter->irq);
Jeff Garzik1494a812006-11-07 05:12:16 -05002038 netxen_intr(adapter->irq, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002039 enable_irq(adapter->irq);
2040}
2041#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002042
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002043static int
2044nx_incr_dev_ref_cnt(struct netxen_adapter *adapter)
2045{
2046 int count;
2047 if (netxen_api_lock(adapter))
2048 return -EIO;
2049
2050 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2051
2052 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2053
2054 netxen_api_unlock(adapter);
2055 return count;
2056}
2057
2058static int
2059nx_decr_dev_ref_cnt(struct netxen_adapter *adapter)
2060{
2061 int count;
2062 if (netxen_api_lock(adapter))
2063 return -EIO;
2064
2065 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2066 WARN_ON(count == 0);
2067
2068 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, --count);
2069
2070 if (count == 0)
2071 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_COLD);
2072
2073 netxen_api_unlock(adapter);
2074 return count;
2075}
2076
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002077static void
2078nx_dev_request_reset(struct netxen_adapter *adapter)
2079{
2080 u32 state;
2081
2082 if (netxen_api_lock(adapter))
2083 return;
2084
2085 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2086
2087 if (state != NX_DEV_INITALIZING)
2088 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_RESET);
2089
2090 netxen_api_unlock(adapter);
2091}
2092
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002093static int
2094netxen_can_start_firmware(struct netxen_adapter *adapter)
2095{
2096 int count;
2097 int can_start = 0;
2098
2099 if (netxen_api_lock(adapter))
2100 return 0;
2101
2102 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2103
2104 if ((count < 0) || (count >= NX_MAX_PCI_FUNC))
2105 count = 0;
2106
2107 if (count == 0) {
2108 can_start = 1;
2109 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_INITALIZING);
2110 }
2111
2112 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2113
2114 netxen_api_unlock(adapter);
2115
2116 return can_start;
2117}
2118
2119static void
2120netxen_schedule_work(struct netxen_adapter *adapter,
2121 work_func_t func, int delay)
2122{
2123 INIT_DELAYED_WORK(&adapter->fw_work, func);
2124 schedule_delayed_work(&adapter->fw_work, delay);
2125}
2126
2127static void
2128netxen_cancel_fw_work(struct netxen_adapter *adapter)
2129{
2130 while (test_and_set_bit(__NX_RESETTING, &adapter->state))
2131 msleep(10);
2132
2133 cancel_delayed_work_sync(&adapter->fw_work);
2134}
2135
2136static void
2137netxen_attach_work(struct work_struct *work)
2138{
2139 struct netxen_adapter *adapter = container_of(work,
2140 struct netxen_adapter, fw_work.work);
2141 struct net_device *netdev = adapter->netdev;
2142 int err = 0;
2143
2144 if (netif_running(netdev)) {
2145 err = netxen_nic_attach(adapter);
2146 if (err)
2147 goto done;
2148
2149 err = netxen_nic_up(adapter, netdev);
2150 if (err) {
2151 netxen_nic_detach(adapter);
2152 goto done;
2153 }
2154
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002155 netxen_config_indev_addr(netdev, NETDEV_UP);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002156 }
2157
2158 netif_device_attach(netdev);
2159
2160done:
2161 adapter->fw_fail_cnt = 0;
2162 clear_bit(__NX_RESETTING, &adapter->state);
2163 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
2164}
2165
2166static void
2167netxen_fwinit_work(struct work_struct *work)
2168{
2169 struct netxen_adapter *adapter = container_of(work,
2170 struct netxen_adapter, fw_work.work);
2171 int dev_state;
2172
2173 dev_state = NXRD32(adapter, NX_CRB_DEV_STATE);
2174
2175 switch (dev_state) {
2176 case NX_DEV_COLD:
2177 case NX_DEV_READY:
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002178 if (!netxen_start_firmware(adapter)) {
2179 netxen_schedule_work(adapter, netxen_attach_work, 0);
2180 return;
2181 }
2182 break;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002183
2184 case NX_DEV_INITALIZING:
2185 if (++adapter->fw_wait_cnt < FW_POLL_THRESH) {
2186 netxen_schedule_work(adapter,
2187 netxen_fwinit_work, 2 * FW_POLL_DELAY);
2188 return;
2189 }
2190 break;
2191
2192 case NX_DEV_FAILED:
2193 default:
2194 break;
2195 }
2196
2197 nx_incr_dev_ref_cnt(adapter);
2198 clear_bit(__NX_RESETTING, &adapter->state);
2199}
2200
2201static void
2202netxen_detach_work(struct work_struct *work)
2203{
2204 struct netxen_adapter *adapter = container_of(work,
2205 struct netxen_adapter, fw_work.work);
2206 struct net_device *netdev = adapter->netdev;
2207 int ref_cnt, delay;
2208 u32 status;
2209
2210 netif_device_detach(netdev);
2211
2212 if (netif_running(netdev))
2213 netxen_nic_down(adapter, netdev);
2214
2215 netxen_nic_detach(adapter);
2216
2217 status = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1);
2218
2219 ref_cnt = nx_decr_dev_ref_cnt(adapter);
2220
2221 if (status & NX_RCODE_FATAL_ERROR)
2222 return;
2223
2224 if (adapter->temp == NX_TEMP_PANIC)
2225 return;
2226
2227 delay = (ref_cnt == 0) ? 0 : (2 * FW_POLL_DELAY);
2228
2229 adapter->fw_wait_cnt = 0;
2230 netxen_schedule_work(adapter, netxen_fwinit_work, delay);
2231}
2232
2233static int
2234netxen_check_health(struct netxen_adapter *adapter)
2235{
2236 u32 state, heartbit;
2237 struct net_device *netdev = adapter->netdev;
2238
2239 if (netxen_nic_check_temp(adapter))
2240 goto detach;
2241
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002242 if (adapter->need_fw_reset) {
2243 nx_dev_request_reset(adapter);
2244 goto detach;
2245 }
2246
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002247 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2248 if (state == NX_DEV_NEED_RESET)
2249 goto detach;
2250
2251 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2252 return 0;
2253
2254 heartbit = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER);
2255 if (heartbit != adapter->heartbit) {
2256 adapter->heartbit = heartbit;
2257 adapter->fw_fail_cnt = 0;
2258 return 0;
2259 }
2260
2261 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2262 return 0;
2263
2264 clear_bit(__NX_FW_ATTACHED, &adapter->state);
2265
2266 dev_info(&netdev->dev, "firmware hang detected\n");
2267
2268detach:
Narender Kumarcaa2dd52009-10-16 15:50:11 +00002269 if ((auto_fw_reset == AUTO_FW_RESET_ENABLED) &&
2270 !test_and_set_bit(__NX_RESETTING, &adapter->state))
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002271 netxen_schedule_work(adapter, netxen_detach_work, 0);
2272 return 1;
2273}
2274
2275static void
2276netxen_fw_poll_work(struct work_struct *work)
2277{
2278 struct netxen_adapter *adapter = container_of(work,
2279 struct netxen_adapter, fw_work.work);
2280
2281 if (test_bit(__NX_RESETTING, &adapter->state))
2282 goto reschedule;
2283
2284 if (test_bit(__NX_DEV_UP, &adapter->state)) {
2285 if (!adapter->has_link_events) {
2286
2287 netxen_nic_handle_phy_intr(adapter);
2288
2289 if (adapter->link_changed)
2290 netxen_nic_set_link_parameters(adapter);
2291 }
2292 }
2293
2294 if (netxen_check_health(adapter))
2295 return;
2296
2297reschedule:
2298 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
2299}
2300
Narender Kumarfa3ce352009-08-24 19:23:28 +00002301static ssize_t
2302netxen_store_bridged_mode(struct device *dev,
2303 struct device_attribute *attr, const char *buf, size_t len)
2304{
2305 struct net_device *net = to_net_dev(dev);
2306 struct netxen_adapter *adapter = netdev_priv(net);
2307 unsigned long new;
2308 int ret = -EINVAL;
2309
2310 if (!(adapter->capabilities & NX_FW_CAPABILITY_BDG))
2311 goto err_out;
2312
2313 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2314 goto err_out;
2315
2316 if (strict_strtoul(buf, 2, &new))
2317 goto err_out;
2318
2319 if (!netxen_config_bridged_mode(adapter, !!new))
2320 ret = len;
2321
2322err_out:
2323 return ret;
2324}
2325
2326static ssize_t
2327netxen_show_bridged_mode(struct device *dev,
2328 struct device_attribute *attr, char *buf)
2329{
2330 struct net_device *net = to_net_dev(dev);
2331 struct netxen_adapter *adapter;
2332 int bridged_mode = 0;
2333
2334 adapter = netdev_priv(net);
2335
2336 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2337 bridged_mode = !!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED);
2338
2339 return sprintf(buf, "%d\n", bridged_mode);
2340}
2341
2342static struct device_attribute dev_attr_bridged_mode = {
2343 .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
2344 .show = netxen_show_bridged_mode,
2345 .store = netxen_store_bridged_mode,
2346};
2347
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002348static ssize_t
2349netxen_store_diag_mode(struct device *dev,
2350 struct device_attribute *attr, const char *buf, size_t len)
2351{
2352 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2353 unsigned long new;
2354
2355 if (strict_strtoul(buf, 2, &new))
2356 return -EINVAL;
2357
2358 if (!!new != !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2359 adapter->flags ^= NETXEN_NIC_DIAG_ENABLED;
2360
2361 return len;
2362}
2363
2364static ssize_t
2365netxen_show_diag_mode(struct device *dev,
2366 struct device_attribute *attr, char *buf)
2367{
2368 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2369
2370 return sprintf(buf, "%d\n",
2371 !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED));
2372}
2373
2374static struct device_attribute dev_attr_diag_mode = {
2375 .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)},
2376 .show = netxen_show_diag_mode,
2377 .store = netxen_store_diag_mode,
2378};
2379
2380static int
2381netxen_sysfs_validate_crb(struct netxen_adapter *adapter,
2382 loff_t offset, size_t size)
2383{
2384 if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2385 return -EIO;
2386
2387 if ((size != 4) || (offset & 0x3))
2388 return -EINVAL;
2389
2390 if (offset < NETXEN_PCI_CRBSPACE)
2391 return -EINVAL;
2392
2393 return 0;
2394}
2395
2396static ssize_t
2397netxen_sysfs_read_crb(struct kobject *kobj, struct bin_attribute *attr,
2398 char *buf, loff_t offset, size_t size)
2399{
2400 struct device *dev = container_of(kobj, struct device, kobj);
2401 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2402 u32 data;
2403 int ret;
2404
2405 ret = netxen_sysfs_validate_crb(adapter, offset, size);
2406 if (ret != 0)
2407 return ret;
2408
2409 data = NXRD32(adapter, offset);
2410 memcpy(buf, &data, size);
2411 return size;
2412}
2413
2414static ssize_t
2415netxen_sysfs_write_crb(struct kobject *kobj, struct bin_attribute *attr,
2416 char *buf, loff_t offset, size_t size)
2417{
2418 struct device *dev = container_of(kobj, struct device, kobj);
2419 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2420 u32 data;
2421 int ret;
2422
2423 ret = netxen_sysfs_validate_crb(adapter, offset, size);
2424 if (ret != 0)
2425 return ret;
2426
2427 memcpy(&data, buf, size);
2428 NXWR32(adapter, offset, data);
2429 return size;
2430}
2431
2432static int
2433netxen_sysfs_validate_mem(struct netxen_adapter *adapter,
2434 loff_t offset, size_t size)
2435{
2436 if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2437 return -EIO;
2438
2439 if ((size != 8) || (offset & 0x7))
2440 return -EIO;
2441
2442 return 0;
2443}
2444
2445static ssize_t
2446netxen_sysfs_read_mem(struct kobject *kobj, struct bin_attribute *attr,
2447 char *buf, loff_t offset, size_t size)
2448{
2449 struct device *dev = container_of(kobj, struct device, kobj);
2450 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2451 u64 data;
2452 int ret;
2453
2454 ret = netxen_sysfs_validate_mem(adapter, offset, size);
2455 if (ret != 0)
2456 return ret;
2457
2458 if (adapter->pci_mem_read(adapter, offset, &data))
2459 return -EIO;
2460
2461 memcpy(buf, &data, size);
2462
2463 return size;
2464}
2465
2466ssize_t netxen_sysfs_write_mem(struct kobject *kobj,
2467 struct bin_attribute *attr, char *buf,
2468 loff_t offset, size_t size)
2469{
2470 struct device *dev = container_of(kobj, struct device, kobj);
2471 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2472 u64 data;
2473 int ret;
2474
2475 ret = netxen_sysfs_validate_mem(adapter, offset, size);
2476 if (ret != 0)
2477 return ret;
2478
2479 memcpy(&data, buf, size);
2480
2481 if (adapter->pci_mem_write(adapter, offset, data))
2482 return -EIO;
2483
2484 return size;
2485}
2486
2487
2488static struct bin_attribute bin_attr_crb = {
2489 .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)},
2490 .size = 0,
2491 .read = netxen_sysfs_read_crb,
2492 .write = netxen_sysfs_write_crb,
2493};
2494
2495static struct bin_attribute bin_attr_mem = {
2496 .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)},
2497 .size = 0,
2498 .read = netxen_sysfs_read_mem,
2499 .write = netxen_sysfs_write_mem,
2500};
2501
Narender Kumarcaa2dd52009-10-16 15:50:11 +00002502static ssize_t
2503netxen_store_auto_fw_reset(struct module_attribute *mattr,
2504 struct module *mod, const char *buf, size_t count)
2505
2506{
2507 unsigned long new;
2508
2509 if (strict_strtoul(buf, 16, &new))
2510 return -EINVAL;
2511
2512 if ((new == AUTO_FW_RESET_ENABLED) || (new == AUTO_FW_RESET_DISABLED)) {
2513 auto_fw_reset = new;
2514 return count;
2515 }
2516
2517 return -EINVAL;
2518}
2519
2520static ssize_t
2521netxen_show_auto_fw_reset(struct module_attribute *mattr,
2522 struct module *mod, char *buf)
2523
2524{
2525 if (auto_fw_reset == AUTO_FW_RESET_ENABLED)
2526 return sprintf(buf, "enabled\n");
2527 else
2528 return sprintf(buf, "disabled\n");
2529}
2530
2531static struct module_attribute mod_attr_fw_reset = {
2532 .attr = {.name = "auto_fw_reset", .mode = (S_IRUGO | S_IWUSR)},
2533 .show = netxen_show_auto_fw_reset,
2534 .store = netxen_store_auto_fw_reset,
2535};
2536
Narender Kumarfa3ce352009-08-24 19:23:28 +00002537static void
2538netxen_create_sysfs_entries(struct netxen_adapter *adapter)
2539{
2540 struct net_device *netdev = adapter->netdev;
2541 struct device *dev = &netdev->dev;
2542
2543 if (adapter->capabilities & NX_FW_CAPABILITY_BDG) {
2544 /* bridged_mode control */
2545 if (device_create_file(dev, &dev_attr_bridged_mode)) {
2546 dev_warn(&netdev->dev,
2547 "failed to create bridged_mode sysfs entry\n");
2548 }
2549 }
2550}
2551
2552static void
2553netxen_remove_sysfs_entries(struct netxen_adapter *adapter)
2554{
2555 struct net_device *netdev = adapter->netdev;
2556 struct device *dev = &netdev->dev;
2557
2558 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2559 device_remove_file(dev, &dev_attr_bridged_mode);
2560}
2561
Dhananjay Phadke70f9cf82009-10-13 05:31:45 +00002562static void
2563netxen_create_diag_entries(struct netxen_adapter *adapter)
2564{
2565 struct pci_dev *pdev = adapter->pdev;
2566 struct device *dev;
2567
2568 dev = &pdev->dev;
2569 if (device_create_file(dev, &dev_attr_diag_mode))
2570 dev_info(dev, "failed to create diag_mode sysfs entry\n");
2571 if (device_create_bin_file(dev, &bin_attr_crb))
2572 dev_info(dev, "failed to create crb sysfs entry\n");
2573 if (device_create_bin_file(dev, &bin_attr_mem))
2574 dev_info(dev, "failed to create mem sysfs entry\n");
2575}
2576
2577
2578static void
2579netxen_remove_diag_entries(struct netxen_adapter *adapter)
2580{
2581 struct pci_dev *pdev = adapter->pdev;
2582 struct device *dev = &pdev->dev;
2583
2584 device_remove_file(dev, &dev_attr_diag_mode);
2585 device_remove_bin_file(dev, &bin_attr_crb);
2586 device_remove_bin_file(dev, &bin_attr_mem);
2587}
2588
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002589#ifdef CONFIG_INET
2590
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002591#define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2592
2593static int
2594netxen_destip_supported(struct netxen_adapter *adapter)
2595{
2596 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2597 return 0;
2598
2599 if (adapter->ahw.cut_through)
2600 return 0;
2601
2602 return 1;
2603}
2604
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002605static void
2606netxen_config_indev_addr(struct net_device *dev, unsigned long event)
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002607{
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002608 struct in_device *indev;
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002609 struct netxen_adapter *adapter = netdev_priv(dev);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002610
Amit Kumar Salecha3db76752009-09-09 18:12:37 -07002611 if (!netxen_destip_supported(adapter))
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002612 return;
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002613
2614 indev = in_dev_get(dev);
2615 if (!indev)
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002616 return;
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002617
2618 for_ifa(indev) {
2619 switch (event) {
2620 case NETDEV_UP:
2621 netxen_config_ipaddr(adapter,
2622 ifa->ifa_address, NX_IP_UP);
2623 break;
2624 case NETDEV_DOWN:
2625 netxen_config_ipaddr(adapter,
2626 ifa->ifa_address, NX_IP_DOWN);
2627 break;
2628 default:
2629 break;
2630 }
2631 } endfor_ifa(indev);
2632
2633 in_dev_put(indev);
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002634 return;
2635}
2636
2637static int netxen_netdev_event(struct notifier_block *this,
2638 unsigned long event, void *ptr)
2639{
2640 struct netxen_adapter *adapter;
2641 struct net_device *dev = (struct net_device *)ptr;
2642
2643recheck:
2644 if (dev == NULL)
2645 goto done;
2646
2647 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2648 dev = vlan_dev_real_dev(dev);
2649 goto recheck;
2650 }
2651
2652 if (!is_netxen_netdev(dev))
2653 goto done;
2654
2655 adapter = netdev_priv(dev);
2656
2657 if (!adapter)
2658 goto done;
2659
2660 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2661 goto done;
2662
2663 netxen_config_indev_addr(dev, event);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002664done:
2665 return NOTIFY_DONE;
2666}
2667
2668static int
2669netxen_inetaddr_event(struct notifier_block *this,
2670 unsigned long event, void *ptr)
2671{
2672 struct netxen_adapter *adapter;
2673 struct net_device *dev;
2674
2675 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
2676
2677 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
2678
2679recheck:
2680 if (dev == NULL || !netif_running(dev))
2681 goto done;
2682
2683 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2684 dev = vlan_dev_real_dev(dev);
2685 goto recheck;
2686 }
2687
2688 if (!is_netxen_netdev(dev))
2689 goto done;
2690
2691 adapter = netdev_priv(dev);
2692
2693 if (!adapter || !netxen_destip_supported(adapter))
2694 goto done;
2695
2696 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2697 goto done;
2698
2699 switch (event) {
2700 case NETDEV_UP:
2701 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP);
2702 break;
2703 case NETDEV_DOWN:
2704 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN);
2705 break;
2706 default:
2707 break;
2708 }
2709
2710done:
2711 return NOTIFY_DONE;
2712}
2713
2714static struct notifier_block netxen_netdev_cb = {
2715 .notifier_call = netxen_netdev_event,
2716};
2717
2718static struct notifier_block netxen_inetaddr_cb = {
2719 .notifier_call = netxen_inetaddr_event,
2720};
Randy Dunlap9feae562009-09-11 12:41:04 +00002721#else
2722static void
2723netxen_config_indev_addr(struct net_device *dev, unsigned long event)
2724{ }
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002725#endif
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002726
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002727static struct pci_driver netxen_driver = {
2728 .name = netxen_nic_driver_name,
2729 .id_table = netxen_pci_tbl,
2730 .probe = netxen_nic_probe,
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002731 .remove = __devexit_p(netxen_nic_remove),
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002732#ifdef CONFIG_PM
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002733 .suspend = netxen_nic_suspend,
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00002734 .resume = netxen_nic_resume,
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002735#endif
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00002736 .shutdown = netxen_nic_shutdown
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002737};
2738
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002739static int __init netxen_init_module(void)
2740{
Narender Kumarcaa2dd52009-10-16 15:50:11 +00002741 struct module *mod = THIS_MODULE;
2742
Dhananjay Phadkeff4fbd42009-03-13 14:52:06 +00002743 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
2744
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002745#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002746 register_netdevice_notifier(&netxen_netdev_cb);
2747 register_inetaddr_notifier(&netxen_inetaddr_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002748#endif
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002749
Narender Kumarcaa2dd52009-10-16 15:50:11 +00002750 if (sysfs_create_file(&mod->mkobj.kobj, &mod_attr_fw_reset.attr))
2751 printk(KERN_ERR "%s: Failed to create auto_fw_reset "
2752 "sysfs entry.", netxen_nic_driver_name);
2753
Amit S. Kale184231b2007-01-22 06:52:53 -08002754 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002755}
2756
2757module_init(netxen_init_module);
2758
2759static void __exit netxen_exit_module(void)
2760{
Narender Kumarcaa2dd52009-10-16 15:50:11 +00002761 struct module *mod = THIS_MODULE;
2762
2763 sysfs_remove_file(&mod->mkobj.kobj, &mod_attr_fw_reset.attr);
2764
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002765 pci_unregister_driver(&netxen_driver);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002766
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002767#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002768 unregister_inetaddr_notifier(&netxen_inetaddr_cb);
2769 unregister_netdevice_notifier(&netxen_netdev_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002770#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002771}
2772
2773module_exit(netxen_exit_module);