blob: 41b29671fc9a196437292b55007fcdf439868c01 [file] [log] [blame]
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001/*
Dhananjay Phadke5d242f12009-02-25 15:57:56 +00002 * Copyright (C) 2003 - 2009 NetXen, Inc.
Amit S. Kale3d396eb2006-10-21 15:33:03 -04003 * All rights reserved.
Amit S. Kale80922fb2006-12-04 09:18:00 -08004 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -04005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
Amit S. Kale80922fb2006-12-04 09:18:00 -08009 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040010 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Amit S. Kale80922fb2006-12-04 09:18:00 -080014 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040015 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 * MA 02111-1307, USA.
Amit S. Kale80922fb2006-12-04 09:18:00 -080019 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040020 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
Amit S. Kale80922fb2006-12-04 09:18:00 -080022 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040023 * Contact Information:
24 * info@netxen.com
Dhananjay Phadke5d242f12009-02-25 15:57:56 +000025 * NetXen Inc,
26 * 18922 Forge Drive
27 * Cupertino, CA 95014-0701
Amit S. Kale3d396eb2006-10-21 15:33:03 -040028 *
29 */
30
Amit S. Kalecb8011a2006-11-29 09:00:10 -080031#include <linux/vmalloc.h>
Dhananjay Phadkee98e3352009-04-07 22:50:38 +000032#include <linux/interrupt.h>
Amit S. Kale3d396eb2006-10-21 15:33:03 -040033#include "netxen_nic_hw.h"
34
35#include "netxen_nic.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040036
Jeff Garzik1494a812006-11-07 05:12:16 -050037#include <linux/dma-mapping.h>
Dhananjay Phadke391587c2009-01-14 20:48:11 -080038#include <linux/if_vlan.h>
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030039#include <net/ip.h>
Dhananjay Phadke00977782009-01-16 11:03:25 -080040#include <linux/ipv6.h>
Dhananjay Phadke6598b162009-07-26 20:07:37 +000041#include <linux/inetdevice.h>
Jeff Garzik1494a812006-11-07 05:12:16 -050042
Amit S. Kale3d396eb2006-10-21 15:33:03 -040043MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
44MODULE_LICENSE("GPL");
45MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
46
dhananjay@netxen.comceded322007-07-19 14:41:09 +053047char netxen_nic_driver_name[] = "netxen_nic";
Amit S. Kale3d396eb2006-10-21 15:33:03 -040048static char netxen_nic_driver_string[] = "NetXen Network Driver version "
Amit S. Kalecb8011a2006-11-29 09:00:10 -080049 NETXEN_NIC_LINUX_VERSIONID;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040050
Dhananjay Phadke29566402008-07-21 19:44:04 -070051static int port_mode = NETXEN_PORT_MODE_AUTO_NEG;
52
53/* Default to restricted 1G auto-neg mode */
54static int wol_port_mode = 5;
55
56static int use_msi = 1;
57
58static int use_msi_x = 1;
59
Amit S. Kale3d396eb2006-10-21 15:33:03 -040060/* Local functions to NetXen NIC driver */
61static int __devinit netxen_nic_probe(struct pci_dev *pdev,
Dhananjay Phadke29566402008-07-21 19:44:04 -070062 const struct pci_device_id *ent);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040063static void __devexit netxen_nic_remove(struct pci_dev *pdev);
64static int netxen_nic_open(struct net_device *netdev);
65static int netxen_nic_close(struct net_device *netdev);
Stephen Hemminger613573252009-08-31 19:50:58 +000066static netdev_tx_t netxen_nic_xmit_frame(struct sk_buff *,
67 struct net_device *);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040068static void netxen_tx_timeout(struct net_device *netdev);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +000069static void netxen_reset_task(struct work_struct *work);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040070static void netxen_watchdog(unsigned long);
Stephen Hemmingerbea33482007-10-03 16:41:36 -070071static int netxen_nic_poll(struct napi_struct *napi, int budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040072#ifdef CONFIG_NET_POLL_CONTROLLER
73static void netxen_nic_poll_controller(struct net_device *netdev);
74#endif
Narender Kumarfa3ce352009-08-24 19:23:28 +000075
76static void netxen_create_sysfs_entries(struct netxen_adapter *adapter);
77static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter);
78
Jeff Garzik1494a812006-11-07 05:12:16 -050079static irqreturn_t netxen_intr(int irq, void *data);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -070080static irqreturn_t netxen_msi_intr(int irq, void *data);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -080081static irqreturn_t netxen_msix_intr(int irq, void *data);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040082
83/* PCI Device ID Table */
Al Viro70081ac2008-06-23 02:04:50 +010084#define ENTRY(device) \
Dhananjay Phadke040dec32008-09-12 06:55:14 -070085 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
Al Viro70081ac2008-06-23 02:04:50 +010086 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
87
Amit S. Kale3d396eb2006-10-21 15:33:03 -040088static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
Dhananjay Phadke040dec32008-09-12 06:55:14 -070089 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR),
90 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4),
91 ENTRY(PCI_DEVICE_ID_NX2031_4GCU),
92 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ),
93 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ),
94 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT),
95 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2),
96 ENTRY(PCI_DEVICE_ID_NX3031),
Amit S. Kale3d396eb2006-10-21 15:33:03 -040097 {0,}
98};
99
100MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
101
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700102static uint32_t crb_cmd_producer[4] = {
103 CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1,
104 CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3
105};
106
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700107void
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700108netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000109 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700110{
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000111 NXWR32(adapter, tx_ring->crb_cmd_producer, tx_ring->producer);
112
113 if (netxen_tx_avail(tx_ring) <= TX_STOP_THRESH) {
114 netif_stop_queue(adapter->netdev);
115 smp_mb();
116 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700117}
118
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700119static uint32_t crb_cmd_consumer[4] = {
120 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
121 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
122};
123
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700124static inline void
125netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000126 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700127{
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000128 NXWR32(adapter, tx_ring->crb_cmd_consumer, tx_ring->sw_consumer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700129}
130
Dhananjay Phadke29566402008-07-21 19:44:04 -0700131static uint32_t msi_tgt_status[8] = {
Dhananjay Phadke443be792008-03-17 19:59:48 -0700132 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700133 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
134 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
135 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
Dhananjay Phadke443be792008-03-17 19:59:48 -0700136};
137
Dhananjay Phadke29566402008-07-21 19:44:04 -0700138static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
139
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000140static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700141{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000142 struct netxen_adapter *adapter = sds_ring->adapter;
143
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000144 NXWR32(adapter, sds_ring->crb_intr_mask, 0);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700145}
146
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000147static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700148{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000149 struct netxen_adapter *adapter = sds_ring->adapter;
150
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000151 NXWR32(adapter, sds_ring->crb_intr_mask, 0x1);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700152
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700153 if (!NETXEN_IS_MSI_FAMILY(adapter))
154 adapter->pci_write_immediate(adapter,
155 adapter->legacy_intr.tgt_mask_reg, 0xfbff);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700156}
157
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000158static int
159netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count)
160{
161 int size = sizeof(struct nx_host_sds_ring) * count;
162
163 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
164
165 return (recv_ctx->sds_rings == NULL);
166}
167
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000168static void
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000169netxen_free_sds_rings(struct netxen_recv_context *recv_ctx)
170{
171 if (recv_ctx->sds_rings != NULL)
172 kfree(recv_ctx->sds_rings);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000173
174 recv_ctx->sds_rings = NULL;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000175}
176
177static int
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000178netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
179{
180 int ring;
181 struct nx_host_sds_ring *sds_ring;
182 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
183
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000184 if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
Dhananjay Phadkef17443f2009-07-26 20:07:43 +0000185 return -ENOMEM;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000186
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000187 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
188 sds_ring = &recv_ctx->sds_rings[ring];
189 netif_napi_add(netdev, &sds_ring->napi,
190 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
191 }
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000192
193 return 0;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000194}
195
196static void
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000197netxen_napi_del(struct netxen_adapter *adapter)
198{
199 int ring;
200 struct nx_host_sds_ring *sds_ring;
201 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
202
203 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
204 sds_ring = &recv_ctx->sds_rings[ring];
205 netif_napi_del(&sds_ring->napi);
206 }
207
208 netxen_free_sds_rings(&adapter->recv_ctx);
209}
210
211static void
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000212netxen_napi_enable(struct netxen_adapter *adapter)
213{
214 int ring;
215 struct nx_host_sds_ring *sds_ring;
216 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
217
218 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
219 sds_ring = &recv_ctx->sds_rings[ring];
220 napi_enable(&sds_ring->napi);
221 netxen_nic_enable_int(sds_ring);
222 }
223}
224
225static void
226netxen_napi_disable(struct netxen_adapter *adapter)
227{
228 int ring;
229 struct nx_host_sds_ring *sds_ring;
230 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
231
232 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
233 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000234 netxen_nic_disable_int(sds_ring);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000235 napi_synchronize(&sds_ring->napi);
236 napi_disable(&sds_ring->napi);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000237 }
238}
239
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000240static int nx_set_dma_mask(struct netxen_adapter *adapter)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700241{
242 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000243 uint64_t mask, cmask;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700244
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000245 adapter->pci_using_dac = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700246
Yang Hongyang6afd1422009-04-06 19:01:15 -0700247 mask = DMA_BIT_MASK(32);
Yang Hongyang6afd1422009-04-06 19:01:15 -0700248 cmask = DMA_BIT_MASK(32);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000249
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000250 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000251#ifndef CONFIG_IA64
Yang Hongyang6afd1422009-04-06 19:01:15 -0700252 mask = DMA_BIT_MASK(35);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000253#endif
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000254 } else {
255 mask = DMA_BIT_MASK(39);
256 cmask = mask;
257 }
258
Dhananjay Phadke29566402008-07-21 19:44:04 -0700259 if (pci_set_dma_mask(pdev, mask) == 0 &&
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000260 pci_set_consistent_dma_mask(pdev, cmask) == 0) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700261 adapter->pci_using_dac = 1;
262 return 0;
263 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700264
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000265 return -EIO;
266}
267
268/* Update addressable range if firmware supports it */
269static int
270nx_update_dma_mask(struct netxen_adapter *adapter)
271{
272 int change, shift, err;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000273 uint64_t mask, old_mask, old_cmask;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000274 struct pci_dev *pdev = adapter->pdev;
275
276 change = 0;
277
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000278 shift = NXRD32(adapter, CRB_DMA_SHIFT);
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000279 if (shift > 32)
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000280 return 0;
281
282 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9))
283 change = 1;
284 else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4))
285 change = 1;
286
287 if (change) {
288 old_mask = pdev->dma_mask;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000289 old_cmask = pdev->dev.coherent_dma_mask;
290
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000291 mask = DMA_BIT_MASK(32+shift);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000292
293 err = pci_set_dma_mask(pdev, mask);
294 if (err)
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000295 goto err_out;
296
297 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
298
299 err = pci_set_consistent_dma_mask(pdev, mask);
300 if (err)
301 goto err_out;
302 }
303 dev_info(&pdev->dev, "using %d-bit dma mask\n", 32+shift);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700304 }
305
Dhananjay Phadke29566402008-07-21 19:44:04 -0700306 return 0;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000307
308err_out:
309 pci_set_dma_mask(pdev, old_mask);
310 pci_set_consistent_dma_mask(pdev, old_cmask);
311 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700312}
313
Dhananjay Phadke24767ab2009-07-27 11:08:00 -0700314static void
315netxen_check_options(struct netxen_adapter *adapter)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700316{
Dhananjay Phadke24767ab2009-07-27 11:08:00 -0700317 if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
318 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
319 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
320 } else if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
321 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
322 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
323 }
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000324
Dhananjay Phadkef6d21f42009-04-07 22:50:46 +0000325 adapter->msix_supported = 0;
326 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700327 adapter->msix_supported = !!use_msi_x;
Dhananjay Phadkef6d21f42009-04-07 22:50:46 +0000328 adapter->rss_supported = !!use_msi_x;
329 } else if (adapter->fw_version >= NETXEN_VERSION_CODE(3, 4, 336)) {
330 switch (adapter->ahw.board_type) {
331 case NETXEN_BRDTYPE_P2_SB31_10G:
332 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkef6d21f42009-04-07 22:50:46 +0000333 adapter->msix_supported = !!use_msi_x;
334 adapter->rss_supported = !!use_msi_x;
335 break;
336 default:
337 break;
338 }
339 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700340
Dhananjay Phadke24767ab2009-07-27 11:08:00 -0700341 adapter->num_txd = MAX_CMD_DESCRIPTORS;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700342
Dhananjay Phadke24767ab2009-07-27 11:08:00 -0700343 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
344 adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS;
345 adapter->max_rds_rings = 3;
346 } else {
347 adapter->num_lro_rxd = 0;
348 adapter->max_rds_rings = 2;
349 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700350}
351
352static int
353netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
354{
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800355 u32 val, timeout;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700356
357 if (first_boot == 0x55555555) {
358 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000359 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800360
361 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
362 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700363
364 /* PCI bus master workaround */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000365 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700366 if (!(first_boot & 0x4)) {
367 first_boot |= 0x4;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000368 NXWR32(adapter, NETXEN_PCIE_REG(0x4), first_boot);
369 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700370 }
371
372 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000373 first_boot = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700374 if (first_boot != 0x80000f) {
375 /* clear the register for future unloads/loads */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000376 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), 0);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800377 return -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700378 }
379
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800380 /* Start P2 boot loader */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000381 val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
382 NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800383 timeout = 0;
384 do {
385 msleep(1);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000386 val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800387
388 if (++timeout > 5000)
389 return -EIO;
390
391 } while (val == NETXEN_BDINFO_MAGIC);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700392 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800393 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700394}
395
396static void netxen_set_port_mode(struct netxen_adapter *adapter)
397{
398 u32 val, data;
399
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000400 val = adapter->ahw.board_type;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700401 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
402 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
403 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
404 data = NETXEN_PORT_MODE_802_3_AP;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000405 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700406 } else if (port_mode == NETXEN_PORT_MODE_XG) {
407 data = NETXEN_PORT_MODE_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000408 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700409 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
410 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000411 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700412 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
413 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000414 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700415 } else {
416 data = NETXEN_PORT_MODE_AUTO_NEG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000417 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700418 }
419
420 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
421 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
422 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
423 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
424 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
425 }
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000426 NXWR32(adapter, NETXEN_WOL_PORT_MODE, wol_port_mode);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700427 }
428}
429
Dhananjay Phadke29566402008-07-21 19:44:04 -0700430static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
431{
432 u32 control;
433 int pos;
434
435 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
436 if (pos) {
437 pci_read_config_dword(pdev, pos, &control);
438 if (enable)
439 control |= PCI_MSIX_FLAGS_ENABLE;
440 else
441 control = 0;
442 pci_write_config_dword(pdev, pos, control);
443 }
444}
445
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000446static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700447{
448 int i;
449
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000450 for (i = 0; i < count; i++)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700451 adapter->msix_entries[i].entry = i;
452}
453
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700454static int
455netxen_read_mac_addr(struct netxen_adapter *adapter)
456{
457 int i;
458 unsigned char *p;
459 __le64 mac_addr;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700460 struct net_device *netdev = adapter->netdev;
461 struct pci_dev *pdev = adapter->pdev;
462
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700463 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
464 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
465 return -EIO;
466 } else {
467 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
468 return -EIO;
469 }
470
471 p = (unsigned char *)&mac_addr;
472 for (i = 0; i < 6; i++)
473 netdev->dev_addr[i] = *(p + 5 - i);
474
475 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
476
477 /* set station address */
478
Johannes Berge1749612008-10-27 15:59:26 -0700479 if (!is_valid_ether_addr(netdev->perm_addr))
480 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700481
482 return 0;
483}
484
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000485int netxen_nic_set_mac(struct net_device *netdev, void *p)
486{
487 struct netxen_adapter *adapter = netdev_priv(netdev);
488 struct sockaddr *addr = p;
489
490 if (!is_valid_ether_addr(addr->sa_data))
491 return -EINVAL;
492
493 if (netif_running(netdev)) {
494 netif_device_detach(netdev);
495 netxen_napi_disable(adapter);
496 }
497
498 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
499 adapter->macaddr_set(adapter, addr->sa_data);
500
501 if (netif_running(netdev)) {
502 netif_device_attach(netdev);
503 netxen_napi_enable(adapter);
504 }
505 return 0;
506}
507
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800508static void netxen_set_multicast_list(struct net_device *dev)
509{
510 struct netxen_adapter *adapter = netdev_priv(dev);
511
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000512 adapter->set_multi(dev);
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800513}
514
515static const struct net_device_ops netxen_netdev_ops = {
516 .ndo_open = netxen_nic_open,
517 .ndo_stop = netxen_nic_close,
518 .ndo_start_xmit = netxen_nic_xmit_frame,
519 .ndo_get_stats = netxen_nic_get_stats,
520 .ndo_validate_addr = eth_validate_addr,
521 .ndo_set_multicast_list = netxen_set_multicast_list,
522 .ndo_set_mac_address = netxen_nic_set_mac,
523 .ndo_change_mtu = netxen_nic_change_mtu,
524 .ndo_tx_timeout = netxen_tx_timeout,
525#ifdef CONFIG_NET_POLL_CONTROLLER
526 .ndo_poll_controller = netxen_nic_poll_controller,
527#endif
528};
529
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800530static void
531netxen_setup_intr(struct netxen_adapter *adapter)
532{
533 struct netxen_legacy_intr_set *legacy_intrp;
534 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000535 int err, num_msix;
536
537 if (adapter->rss_supported) {
538 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
539 MSIX_ENTRIES_PER_ADAPTER : 2;
540 } else
541 num_msix = 1;
542
543 adapter->max_sds_rings = 1;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800544
545 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800546
547 if (adapter->ahw.revision_id >= NX_P3_B0)
548 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
549 else
550 legacy_intrp = &legacy_intr[0];
551 adapter->legacy_intr.int_vec_bit = legacy_intrp->int_vec_bit;
552 adapter->legacy_intr.tgt_status_reg = legacy_intrp->tgt_status_reg;
553 adapter->legacy_intr.tgt_mask_reg = legacy_intrp->tgt_mask_reg;
554 adapter->legacy_intr.pci_int_reg = legacy_intrp->pci_int_reg;
555
556 netxen_set_msix_bit(pdev, 0);
557
558 if (adapter->msix_supported) {
559
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000560 netxen_init_msix_entries(adapter, num_msix);
561 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
562 if (err == 0) {
563 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
564 netxen_set_msix_bit(pdev, 1);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800565
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000566 if (adapter->rss_supported)
567 adapter->max_sds_rings = num_msix;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800568
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000569 dev_info(&pdev->dev, "using msi-x interrupts\n");
570 return;
571 }
572
573 if (err > 0)
574 pci_disable_msix(pdev);
575
576 /* fall through for msi */
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800577 }
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000578
579 if (use_msi && !pci_enable_msi(pdev)) {
580 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
581 adapter->msi_tgt_status =
582 msi_tgt_status[adapter->ahw.pci_func];
583 dev_info(&pdev->dev, "using msi interrupts\n");
Dhananjay Phadkef67f3402009-05-18 21:46:40 -0700584 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000585 return;
586 }
587
588 dev_info(&pdev->dev, "using legacy interrupts\n");
589 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800590}
591
592static void
593netxen_teardown_intr(struct netxen_adapter *adapter)
594{
595 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
596 pci_disable_msix(adapter->pdev);
597 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
598 pci_disable_msi(adapter->pdev);
599}
600
601static void
602netxen_cleanup_pci_map(struct netxen_adapter *adapter)
603{
604 if (adapter->ahw.db_base != NULL)
605 iounmap(adapter->ahw.db_base);
606 if (adapter->ahw.pci_base0 != NULL)
607 iounmap(adapter->ahw.pci_base0);
608 if (adapter->ahw.pci_base1 != NULL)
609 iounmap(adapter->ahw.pci_base1);
610 if (adapter->ahw.pci_base2 != NULL)
611 iounmap(adapter->ahw.pci_base2);
612}
613
614static int
615netxen_setup_pci_map(struct netxen_adapter *adapter)
616{
617 void __iomem *mem_ptr0 = NULL;
618 void __iomem *mem_ptr1 = NULL;
619 void __iomem *mem_ptr2 = NULL;
620 void __iomem *db_ptr = NULL;
621
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800622 unsigned long mem_base, mem_len, db_base, db_len = 0, pci_len0 = 0;
623
624 struct pci_dev *pdev = adapter->pdev;
625 int pci_func = adapter->ahw.pci_func;
626
627 int err = 0;
628
629 /*
630 * Set the CRB window to invalid. If any register in window 0 is
631 * accessed it should set the window to 0 and then reset it to 1.
632 */
633 adapter->curr_window = 255;
634 adapter->ahw.qdr_sn_window = -1;
635 adapter->ahw.ddr_mn_window = -1;
636
637 /* remap phys address */
638 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
639 mem_len = pci_resource_len(pdev, 0);
640 pci_len0 = 0;
641
642 adapter->hw_write_wx = netxen_nic_hw_write_wx_128M;
643 adapter->hw_read_wx = netxen_nic_hw_read_wx_128M;
644 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_128M;
645 adapter->pci_write_immediate = netxen_nic_pci_write_immediate_128M;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800646 adapter->pci_set_window = netxen_nic_pci_set_window_128M;
647 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M;
648 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M;
649
650 /* 128 Meg of memory */
651 if (mem_len == NETXEN_PCI_128MB_SIZE) {
652 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
653 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
654 SECOND_PAGE_GROUP_SIZE);
655 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
656 THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800657 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
658 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
659 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
660 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800661 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
662 adapter->hw_write_wx = netxen_nic_hw_write_wx_2M;
663 adapter->hw_read_wx = netxen_nic_hw_read_wx_2M;
664 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_2M;
665 adapter->pci_write_immediate =
666 netxen_nic_pci_write_immediate_2M;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800667 adapter->pci_set_window = netxen_nic_pci_set_window_2M;
668 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M;
669 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M;
670
671 mem_ptr0 = pci_ioremap_bar(pdev, 0);
672 if (mem_ptr0 == NULL) {
673 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
674 return -EIO;
675 }
676 pci_len0 = mem_len;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800677
678 adapter->ahw.ddr_mn_window = 0;
679 adapter->ahw.qdr_sn_window = 0;
680
681 adapter->ahw.mn_win_crb = 0x100000 + PCIX_MN_WINDOW +
682 (pci_func * 0x20);
683 adapter->ahw.ms_win_crb = 0x100000 + PCIX_SN_WINDOW;
684 if (pci_func < 4)
685 adapter->ahw.ms_win_crb += (pci_func * 0x20);
686 else
687 adapter->ahw.ms_win_crb +=
688 0xA0 + ((pci_func - 4) * 0x10);
689 } else {
690 return -EIO;
691 }
692
693 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
694
695 adapter->ahw.pci_base0 = mem_ptr0;
696 adapter->ahw.pci_len0 = pci_len0;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800697 adapter->ahw.pci_base1 = mem_ptr1;
698 adapter->ahw.pci_base2 = mem_ptr2;
699
700 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
701 goto skip_doorbell;
702
703 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
704 db_len = pci_resource_len(pdev, 4);
705
706 if (db_len == 0) {
707 printk(KERN_ERR "%s: doorbell is disabled\n",
708 netxen_nic_driver_name);
709 err = -EIO;
710 goto err_out;
711 }
712
713 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
714 if (!db_ptr) {
715 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
716 netxen_nic_driver_name);
717 err = -EIO;
718 goto err_out;
719 }
720
721skip_doorbell:
722 adapter->ahw.db_base = db_ptr;
723 adapter->ahw.db_len = db_len;
724 return 0;
725
726err_out:
727 netxen_cleanup_pci_map(adapter);
728 return err;
729}
730
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800731static int
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000732netxen_start_firmware(struct netxen_adapter *adapter, int request_fw)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800733{
734 int val, err, first_boot;
735 struct pci_dev *pdev = adapter->pdev;
736
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000737 int first_driver = 0;
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000738
739 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
740 first_driver = (adapter->portnum == 0);
741 else
742 first_driver = (adapter->ahw.pci_func == 0);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000743
744 if (!first_driver)
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000745 goto wait_init;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000746
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000747 first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800748
749 err = netxen_check_hw_init(adapter, first_boot);
750 if (err) {
751 dev_err(&pdev->dev, "error in init HW init sequence\n");
752 return err;
753 }
754
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000755 if (request_fw)
756 netxen_request_firmware(adapter);
757
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000758 err = netxen_need_fw_reset(adapter);
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000759 if (err < 0)
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000760 return err;
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000761 if (err == 0)
762 goto wait_init;
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000763
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800764 if (first_boot != 0x55555555) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000765 NXWR32(adapter, CRB_CMDPEG_STATE, 0);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800766 netxen_pinit_from_rom(adapter, 0);
767 msleep(1);
768 }
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000769
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000770 NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555);
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000771 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
772 netxen_set_port_mode(adapter);
773
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800774 netxen_load_firmware(adapter);
775
776 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
777
778 /* Initialize multicast addr pool owners */
779 val = 0x7654;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000780 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800781 val |= 0x0f000000;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000782 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800783
784 }
785
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000786 err = netxen_init_dummy_dma(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800787 if (err)
788 return err;
789
790 /*
791 * Tell the hardware our version number.
792 */
793 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
794 | ((_NETXEN_NIC_LINUX_MINOR << 8))
795 | (_NETXEN_NIC_LINUX_SUBVERSION);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000796 NXWR32(adapter, CRB_DRIVER_VERSION, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800797
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000798wait_init:
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800799 /* Handshake with the card before we register the devices. */
800 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
801 if (err) {
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000802 netxen_free_dummy_dma(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800803 return err;
804 }
805
Dhananjay Phadke68b3cae2009-07-26 20:07:36 +0000806 nx_update_dma_mask(adapter);
807
808 netxen_nic_get_firmware_info(adapter);
809
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800810 return 0;
811}
812
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000813static int
814netxen_nic_request_irq(struct netxen_adapter *adapter)
815{
816 irq_handler_t handler;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000817 struct nx_host_sds_ring *sds_ring;
818 int err, ring;
819
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000820 unsigned long flags = IRQF_SAMPLE_RANDOM;
821 struct net_device *netdev = adapter->netdev;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000822 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000823
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000824 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
825 handler = netxen_msix_intr;
826 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
827 handler = netxen_msi_intr;
828 else {
829 flags |= IRQF_SHARED;
830 handler = netxen_intr;
831 }
832 adapter->irq = netdev->irq;
833
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000834 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
835 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000836 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000837 err = request_irq(sds_ring->irq, handler,
838 flags, sds_ring->name, sds_ring);
839 if (err)
840 return err;
841 }
842
843 return 0;
844}
845
846static void
847netxen_nic_free_irq(struct netxen_adapter *adapter)
848{
849 int ring;
850 struct nx_host_sds_ring *sds_ring;
851
852 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
853
854 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
855 sds_ring = &recv_ctx->sds_rings[ring];
856 free_irq(sds_ring->irq, sds_ring);
857 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000858}
859
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000860static void
861netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter)
862{
863 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
864 adapter->coal.normal.data.rx_time_us =
865 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
866 adapter->coal.normal.data.rx_packets =
867 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
868 adapter->coal.normal.data.tx_time_us =
869 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US;
870 adapter->coal.normal.data.tx_packets =
871 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS;
872}
873
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000874static int
875netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
876{
877 int err;
878
879 err = adapter->init_port(adapter, adapter->physical_port);
880 if (err) {
881 printk(KERN_ERR "%s: Failed to initialize port %d\n",
882 netxen_nic_driver_name, adapter->portnum);
883 return err;
884 }
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000885 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
886 adapter->macaddr_set(adapter, netdev->dev_addr);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000887
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000888 adapter->set_multi(netdev);
889 adapter->set_mtu(adapter, netdev->mtu);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000890
891 adapter->ahw.linkup = 0;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000892
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000893 if (adapter->max_sds_rings > 1)
894 netxen_config_rss(adapter, 1);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000895
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000896 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
897 netxen_config_intr_coalesce(adapter);
898
Narender Kumar1bb482f2009-08-23 08:35:09 +0000899 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
900 netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED);
901
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000902 netxen_napi_enable(adapter);
903
Dhananjay Phadke5103c9f2009-04-28 15:29:09 +0000904 if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000905 netxen_linkevent_request(adapter, 1);
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000906 else
907 netxen_nic_set_link_parameters(adapter);
908
909 mod_timer(&adapter->watchdog_timer, jiffies);
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000910
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000911 return 0;
912}
913
914static void
915netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
916{
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000917 spin_lock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000918 netif_carrier_off(netdev);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000919 netif_tx_disable(netdev);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000920
921 if (adapter->stop_port)
922 adapter->stop_port(adapter);
923
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000924 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
925 netxen_p3_free_mac_list(adapter);
926
Amit Kumar Salecha22b57942009-08-23 08:35:12 +0000927 adapter->set_promisc(adapter, NETXEN_NIU_NON_PROMISC_MODE);
928
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000929 netxen_napi_disable(adapter);
930
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000931 netxen_release_tx_buffers(adapter);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000932 spin_unlock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000933
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000934 del_timer_sync(&adapter->watchdog_timer);
935}
936
937
938static int
939netxen_nic_attach(struct netxen_adapter *adapter)
940{
941 struct net_device *netdev = adapter->netdev;
942 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000943 int err, ring;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000944 struct nx_host_rds_ring *rds_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000945 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000946
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -0700947 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
948 return 0;
949
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000950 err = netxen_init_firmware(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000951 if (err)
952 return err;
953
954 err = netxen_napi_add(adapter, netdev);
955 if (err)
956 return err;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000957
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000958 err = netxen_alloc_sw_resources(adapter);
959 if (err) {
960 printk(KERN_ERR "%s: Error in setting sw resources\n",
961 netdev->name);
962 return err;
963 }
964
965 netxen_nic_clear_stats(adapter);
966
967 err = netxen_alloc_hw_resources(adapter);
968 if (err) {
969 printk(KERN_ERR "%s: Error in setting hw resources\n",
970 netdev->name);
971 goto err_out_free_sw;
972 }
973
Dhananjay Phadke4f96b982009-07-26 20:07:42 +0000974 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000975 tx_ring = adapter->tx_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000976 tx_ring->crb_cmd_producer = crb_cmd_producer[adapter->portnum];
977 tx_ring->crb_cmd_consumer = crb_cmd_consumer[adapter->portnum];
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000978
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000979 tx_ring->producer = 0;
980 tx_ring->sw_consumer = 0;
981
982 netxen_nic_update_cmd_producer(adapter, tx_ring);
983 netxen_nic_update_cmd_consumer(adapter, tx_ring);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000984 }
985
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000986 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
987 rds_ring = &adapter->recv_ctx.rds_rings[ring];
988 netxen_post_rx_buffers(adapter, ring, rds_ring);
989 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000990
991 err = netxen_nic_request_irq(adapter);
992 if (err) {
993 dev_err(&pdev->dev, "%s: failed to setup interrupt\n",
994 netdev->name);
995 goto err_out_free_rxbuf;
996 }
997
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000998 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
999 netxen_nic_init_coalesce_defaults(adapter);
1000
Narender Kumarfa3ce352009-08-24 19:23:28 +00001001 netxen_create_sysfs_entries(adapter);
1002
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001003 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1004 return 0;
1005
1006err_out_free_rxbuf:
1007 netxen_release_rx_buffers(adapter);
1008 netxen_free_hw_resources(adapter);
1009err_out_free_sw:
1010 netxen_free_sw_resources(adapter);
1011 return err;
1012}
1013
1014static void
1015netxen_nic_detach(struct netxen_adapter *adapter)
1016{
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001017 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1018 return;
1019
Narender Kumarfa3ce352009-08-24 19:23:28 +00001020 netxen_remove_sysfs_entries(adapter);
1021
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001022 netxen_free_hw_resources(adapter);
Dhananjay Phadkecf981ff2009-07-17 15:27:06 +00001023 netxen_release_rx_buffers(adapter);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +00001024 netxen_nic_free_irq(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +00001025 netxen_napi_del(adapter);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001026 netxen_free_sw_resources(adapter);
1027
1028 adapter->is_up = 0;
1029}
1030
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001031int
1032netxen_nic_reset_context(struct netxen_adapter *adapter)
1033{
1034 int err = 0;
1035 struct net_device *netdev = adapter->netdev;
1036
1037 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
1038
1039 if (netif_running(netdev))
1040 netxen_nic_down(adapter, netdev);
1041
1042 netxen_nic_detach(adapter);
1043
1044 err = netxen_nic_attach(adapter);
1045 if (err)
1046 goto done;
1047
1048 if (netif_running(netdev))
1049 err = netxen_nic_up(adapter, netdev);
1050 }
1051done:
1052 return err;
1053}
1054
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001055static int
1056netxen_setup_netdev(struct netxen_adapter *adapter,
1057 struct net_device *netdev)
1058{
1059 int err = 0;
1060 struct pci_dev *pdev = adapter->pdev;
1061
1062 adapter->rx_csum = 1;
1063 adapter->mc_enabled = 0;
1064 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1065 adapter->max_mc_count = 38;
1066 else
1067 adapter->max_mc_count = 16;
1068
1069 netdev->netdev_ops = &netxen_netdev_ops;
1070 netdev->watchdog_timeo = 2*HZ;
1071
1072 netxen_nic_change_mtu(netdev, netdev->mtu);
1073
1074 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
1075
1076 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1077 netdev->features |= (NETIF_F_GRO);
1078 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1079
1080 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1081 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1082 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1083 }
1084
1085 if (adapter->pci_using_dac) {
1086 netdev->features |= NETIF_F_HIGHDMA;
1087 netdev->vlan_features |= NETIF_F_HIGHDMA;
1088 }
1089
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001090 if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX)
1091 netdev->features |= (NETIF_F_HW_VLAN_TX);
1092
Narender Kumar1bb482f2009-08-23 08:35:09 +00001093 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
1094 netdev->features |= NETIF_F_LRO;
1095
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001096 netdev->irq = adapter->msix_entries[0].vector;
1097
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001098 init_timer(&adapter->watchdog_timer);
1099 adapter->watchdog_timer.function = &netxen_watchdog;
1100 adapter->watchdog_timer.data = (unsigned long)adapter;
1101 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
1102 INIT_WORK(&adapter->tx_timeout_task, netxen_reset_task);
1103
1104 if (netxen_read_mac_addr(adapter))
1105 dev_warn(&pdev->dev, "failed to read mac addr\n");
1106
1107 netif_carrier_off(netdev);
1108 netif_stop_queue(netdev);
1109
1110 err = register_netdev(netdev);
1111 if (err) {
1112 dev_err(&pdev->dev, "failed to register net device\n");
1113 return err;
1114 }
1115
1116 return 0;
1117}
1118
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001119static int __devinit
1120netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1121{
1122 struct net_device *netdev = NULL;
1123 struct netxen_adapter *adapter = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001124 int i = 0, err;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001125 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001126 uint8_t revision_id;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001127
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001128 if (pdev->class != 0x020000) {
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001129 printk(KERN_DEBUG "NetXen function %d, class %x will not "
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001130 "be enabled.\n",pci_func_id, pdev->class);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001131 return -ENODEV;
1132 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001133
Dhananjay Phadke11d89d62008-08-08 00:08:45 -07001134 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
1135 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
1136 "will not be enabled.\n",
1137 NX_P3_A0, NX_P3_B1);
1138 return -ENODEV;
1139 }
1140
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001141 if ((err = pci_enable_device(pdev)))
1142 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001143
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001144 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1145 err = -ENODEV;
1146 goto err_out_disable_pdev;
1147 }
1148
1149 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
1150 goto err_out_disable_pdev;
1151
1152 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001153
1154 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
1155 if(!netdev) {
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001156 dev_err(&pdev->dev, "failed to allocate net_device\n");
1157 err = -ENOMEM;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001158 goto err_out_free_res;
1159 }
1160
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001161 SET_NETDEV_DEV(netdev, &pdev->dev);
1162
Wang Chen4cf16532008-11-12 23:38:14 -08001163 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001164 adapter->netdev = netdev;
1165 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001166 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001167
1168 revision_id = pdev->revision;
1169 adapter->ahw.revision_id = revision_id;
1170
Dhananjay Phadke50c643e2009-08-01 21:36:16 +00001171 err = nx_set_dma_mask(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001172 if (err)
1173 goto err_out_free_netdev;
1174
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001175 rwlock_init(&adapter->adapter_lock);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001176 spin_lock_init(&adapter->tx_clean_lock);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +00001177 INIT_LIST_HEAD(&adapter->mac_list);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001178
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001179 err = netxen_setup_pci_map(adapter);
1180 if (err)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001181 goto err_out_free_netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001182
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +05301183 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001184 adapter->portnum = pci_func_id;
1185
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001186 err = netxen_nic_get_board_info(adapter);
1187 if (err) {
1188 dev_err(&pdev->dev, "Error getting board config info.\n");
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001189 goto err_out_iounmap;
1190 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001191
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001192 netxen_initialize_adapter_ops(adapter);
1193
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001194 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001195 switch (adapter->ahw.board_type) {
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001196 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1197 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1198 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001199 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001200 break;
1201 default:
1202 break;
1203 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001204
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001205 err = netxen_start_firmware(adapter, 1);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001206 if (err)
1207 goto err_out_iounmap;
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001208
Dhananjay Phadke29566402008-07-21 19:44:04 -07001209 /*
1210 * See if the firmware gave us a virtual-physical port mapping.
1211 */
1212 adapter->physical_port = adapter->portnum;
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001213 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001214 i = NXRD32(adapter, CRB_V2P(adapter->portnum));
Dhananjay Phadke044fad02009-02-24 03:42:59 -08001215 if (i != 0x55555555)
1216 adapter->physical_port = i;
1217 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001218
Dhananjay Phadke438627c2009-03-13 14:52:03 +00001219 netxen_check_options(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001220
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001221 netxen_setup_intr(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001222
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001223 err = netxen_setup_netdev(adapter, netdev);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001224 if (err)
Dhananjay Phadke29566402008-07-21 19:44:04 -07001225 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001226
1227 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001228
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001229 switch (adapter->ahw.port_type) {
Dhananjay Phadke29566402008-07-21 19:44:04 -07001230 case NETXEN_NIC_GBE:
1231 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1232 adapter->netdev->name);
1233 break;
1234 case NETXEN_NIC_XGBE:
1235 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1236 adapter->netdev->name);
1237 break;
1238 }
1239
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001240 return 0;
1241
Dhananjay Phadke29566402008-07-21 19:44:04 -07001242err_out_disable_msi:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001243 netxen_teardown_intr(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001244
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001245 netxen_free_dummy_dma(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001246
Dhananjay Phadke29566402008-07-21 19:44:04 -07001247err_out_iounmap:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001248 netxen_cleanup_pci_map(adapter);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001249
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001250err_out_free_netdev:
1251 free_netdev(netdev);
1252
1253err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001254 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001255
1256err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001257 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001258 pci_disable_device(pdev);
1259 return err;
1260}
1261
1262static void __devexit netxen_nic_remove(struct pci_dev *pdev)
1263{
1264 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001265 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001266
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001267 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001268 if (adapter == NULL)
1269 return;
1270
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001271 netdev = adapter->netdev;
1272
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301273 unregister_netdev(netdev);
1274
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001275 cancel_work_sync(&adapter->watchdog_task);
1276 cancel_work_sync(&adapter->tx_timeout_task);
1277
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001278 netxen_nic_detach(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001279
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001280 if (adapter->portnum == 0)
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001281 netxen_free_dummy_dma(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301282
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001283 netxen_teardown_intr(adapter);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301284
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001285 netxen_cleanup_pci_map(adapter);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001286
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001287 netxen_release_firmware(adapter);
1288
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001289 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301290 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001291 pci_set_drvdata(pdev, NULL);
1292
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001293 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001294}
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001295static int __netxen_nic_shutdown(struct pci_dev *pdev)
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001296{
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001297 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1298 struct net_device *netdev = adapter->netdev;
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001299 int retval;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001300
1301 netif_device_detach(netdev);
1302
1303 if (netif_running(netdev))
1304 netxen_nic_down(adapter, netdev);
1305
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001306 cancel_work_sync(&adapter->watchdog_task);
1307 cancel_work_sync(&adapter->tx_timeout_task);
1308
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001309 netxen_nic_detach(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001310
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001311 if (adapter->portnum == 0)
1312 netxen_free_dummy_dma(adapter);
1313
1314 retval = pci_save_state(pdev);
1315 if (retval)
1316 return retval;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001317
1318 if (netxen_nic_wol_supported(adapter)) {
1319 pci_enable_wake(pdev, PCI_D3cold, 1);
1320 pci_enable_wake(pdev, PCI_D3hot, 1);
1321 }
1322
1323 pci_disable_device(pdev);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001324
1325 return 0;
1326}
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001327static void netxen_nic_shutdown(struct pci_dev *pdev)
1328{
1329 if (__netxen_nic_shutdown(pdev))
1330 return;
1331}
1332#ifdef CONFIG_PM
1333static int
1334netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
1335{
1336 int retval;
1337
1338 retval = __netxen_nic_shutdown(pdev);
1339 if (retval)
1340 return retval;
1341
1342 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1343 return 0;
1344}
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001345
1346static int
1347netxen_nic_resume(struct pci_dev *pdev)
1348{
1349 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1350 struct net_device *netdev = adapter->netdev;
1351 int err;
1352
1353 pci_set_power_state(pdev, PCI_D0);
1354 pci_restore_state(pdev);
1355
1356 err = pci_enable_device(pdev);
1357 if (err)
1358 return err;
1359
1360 adapter->curr_window = 255;
1361
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001362 err = netxen_start_firmware(adapter, 0);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001363 if (err) {
1364 dev_err(&pdev->dev, "failed to start firmware\n");
1365 return err;
1366 }
1367
1368 if (netif_running(netdev)) {
1369 err = netxen_nic_attach(adapter);
1370 if (err)
1371 return err;
1372
1373 err = netxen_nic_up(adapter, netdev);
1374 if (err)
1375 return err;
1376
1377 netif_device_attach(netdev);
1378 }
1379
1380 return 0;
1381}
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00001382#endif
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001383
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001384static int netxen_nic_open(struct net_device *netdev)
1385{
Wang Chen4cf16532008-11-12 23:38:14 -08001386 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001387 int err = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001388
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001389 if (adapter->driver_mismatch)
1390 return -EIO;
1391
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001392 err = netxen_nic_attach(adapter);
1393 if (err)
1394 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001395
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001396 err = netxen_nic_up(adapter, netdev);
1397 if (err)
1398 goto err_out;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001399
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001400 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001401
1402 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001403
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001404err_out:
1405 netxen_nic_detach(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001406 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001407}
1408
1409/*
1410 * netxen_nic_close - Disables a network interface entry point
1411 */
1412static int netxen_nic_close(struct net_device *netdev)
1413{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001414 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001415
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001416 netxen_nic_down(adapter, netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001417 return 0;
1418}
1419
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001420static void
1421netxen_tso_check(struct net_device *netdev,
1422 struct nx_host_tx_ring *tx_ring,
1423 struct cmd_desc_type0 *first_desc,
1424 struct sk_buff *skb)
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001425{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001426 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001427 __be16 protocol = skb->protocol;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001428 u16 flags = 0, vid = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001429 u32 producer;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001430 int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001431 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001432 struct vlan_ethhdr *vh;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001433
Harvey Harrison09640e62009-02-01 00:45:17 -08001434 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001435
1436 vh = (struct vlan_ethhdr *)skb->data;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001437 protocol = vh->h_vlan_encapsulated_proto;
1438 flags = FLAGS_VLAN_TAGGED;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001439
1440 } else if (vlan_tx_tag_present(skb)) {
1441
1442 flags = FLAGS_VLAN_OOB;
1443 vid = vlan_tx_tag_get(skb);
1444 netxen_set_tx_vlan_tci(first_desc, vid);
1445 vlan_oob = 1;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001446 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001447
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001448 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1449 skb_shinfo(skb)->gso_size > 0) {
1450
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001451 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1452
1453 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1454 first_desc->total_hdr_length = hdr_len;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001455 if (vlan_oob) {
1456 first_desc->total_hdr_length += VLAN_HLEN;
1457 first_desc->tcp_hdr_offset = VLAN_HLEN;
1458 first_desc->ip_hdr_offset = VLAN_HLEN;
1459 /* Only in case of TSO on vlan device */
1460 flags |= FLAGS_VLAN_TAGGED;
1461 }
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001462
Harvey Harrison09640e62009-02-01 00:45:17 -08001463 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001464 TX_TCP_LSO6 : TX_TCP_LSO;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001465 tso = 1;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001466
1467 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001468 u8 l4proto;
1469
Harvey Harrison09640e62009-02-01 00:45:17 -08001470 if (protocol == cpu_to_be16(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001471 l4proto = ip_hdr(skb)->protocol;
1472
1473 if (l4proto == IPPROTO_TCP)
1474 opcode = TX_TCP_PKT;
1475 else if(l4proto == IPPROTO_UDP)
1476 opcode = TX_UDP_PKT;
Harvey Harrison09640e62009-02-01 00:45:17 -08001477 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001478 l4proto = ipv6_hdr(skb)->nexthdr;
1479
1480 if (l4proto == IPPROTO_TCP)
1481 opcode = TX_TCPV6_PKT;
1482 else if(l4proto == IPPROTO_UDP)
1483 opcode = TX_UDPV6_PKT;
1484 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001485 }
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001486
1487 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
1488 first_desc->ip_hdr_offset += skb_network_offset(skb);
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001489 netxen_set_tx_flags_opcode(first_desc, flags, opcode);
1490
1491 if (!tso)
1492 return;
1493
1494 /* For LSO, we need to copy the MAC/IP/TCP headers into
1495 * the descriptor ring
1496 */
1497 producer = tx_ring->producer;
1498 copied = 0;
1499 offset = 2;
1500
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001501 if (vlan_oob) {
1502 /* Create a TSO vlan header template for firmware */
1503
1504 hwdesc = &tx_ring->desc_head[producer];
1505 tx_ring->cmd_buf_arr[producer].skb = NULL;
1506
1507 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1508 hdr_len + VLAN_HLEN);
1509
1510 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2);
1511 skb_copy_from_linear_data(skb, vh, 12);
1512 vh->h_vlan_proto = htons(ETH_P_8021Q);
1513 vh->h_vlan_TCI = htons(vid);
1514 skb_copy_from_linear_data_offset(skb, 12,
1515 (char *)vh + 16, copy_len - 16);
1516
Dhananjay Phadke545eb372009-08-05 07:34:07 +00001517 copied = copy_len - VLAN_HLEN;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001518 offset = 0;
1519
1520 producer = get_next_index(producer, tx_ring->num_desc);
1521 }
1522
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001523 while (copied < hdr_len) {
1524
1525 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1526 (hdr_len - copied));
1527
1528 hwdesc = &tx_ring->desc_head[producer];
1529 tx_ring->cmd_buf_arr[producer].skb = NULL;
1530
1531 skb_copy_from_linear_data_offset(skb, copied,
1532 (char *)hwdesc + offset, copy_len);
1533
1534 copied += copy_len;
1535 offset = 0;
1536
1537 producer = get_next_index(producer, tx_ring->num_desc);
1538 }
1539
1540 tx_ring->producer = producer;
1541 barrier();
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001542}
1543
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001544static int
1545netxen_map_tx_skb(struct pci_dev *pdev,
1546 struct sk_buff *skb, struct netxen_cmd_buffer *pbuf)
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001547{
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001548 struct netxen_skb_frag *nf;
1549 struct skb_frag_struct *frag;
1550 int i, nr_frags;
1551 dma_addr_t map;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001552
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001553 nr_frags = skb_shinfo(skb)->nr_frags;
1554 nf = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001555
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001556 map = pci_map_single(pdev, skb->data,
1557 skb_headlen(skb), PCI_DMA_TODEVICE);
1558 if (pci_dma_mapping_error(pdev, map))
1559 goto out_err;
1560
1561 nf->dma = map;
1562 nf->length = skb_headlen(skb);
1563
1564 for (i = 0; i < nr_frags; i++) {
1565 frag = &skb_shinfo(skb)->frags[i];
1566 nf = &pbuf->frag_array[i+1];
1567
1568 map = pci_map_page(pdev, frag->page, frag->page_offset,
1569 frag->size, PCI_DMA_TODEVICE);
1570 if (pci_dma_mapping_error(pdev, map))
1571 goto unwind;
1572
1573 nf->dma = map;
1574 nf->length = frag->size;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001575 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001576
1577 return 0;
1578
1579unwind:
Dhananjay Phadkecf503e82009-09-03 13:10:55 +00001580 while (--i >= 0) {
1581 nf = &pbuf->frag_array[i+1];
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001582 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
1583 }
1584
1585 nf = &pbuf->frag_array[0];
1586 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
1587
1588out_err:
1589 return -ENOMEM;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001590}
1591
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001592static inline void
1593netxen_clear_cmddesc(u64 *desc)
1594{
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001595 desc[0] = 0ULL;
1596 desc[2] = 0ULL;
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001597}
1598
Stephen Hemminger613573252009-08-31 19:50:58 +00001599static netdev_tx_t
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001600netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001601{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001602 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001603 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001604 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001605 struct netxen_skb_frag *buffrag;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001606 struct cmd_desc_type0 *hwdesc, *first_desc;
1607 struct pci_dev *pdev;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001608 int i, k;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001609
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001610 u32 producer;
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001611 int frag_count, no_of_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001612 u32 num_txd = tx_ring->num_desc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001613
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001614 frag_count = skb_shinfo(skb)->nr_frags + 1;
1615
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001616 /* 4 fragments per cmd des */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001617 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001618
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001619 if (unlikely(no_of_desc + 2) > netxen_tx_avail(tx_ring)) {
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001620 netif_stop_queue(netdev);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001621 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001622 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001623
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001624 producer = tx_ring->producer;
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001625 pbuf = &tx_ring->cmd_buf_arr[producer];
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001626
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001627 pdev = adapter->pdev;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001628
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001629 if (netxen_map_tx_skb(pdev, skb, pbuf))
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001630 goto drop_packet;
1631
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001632 pbuf->skb = skb;
1633 pbuf->frag_count = frag_count;
1634
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001635 first_desc = hwdesc = &tx_ring->desc_head[producer];
1636 netxen_clear_cmddesc((u64 *)hwdesc);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001637
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001638 netxen_set_tx_frags_len(first_desc, frag_count, skb->len);
1639 netxen_set_tx_port(first_desc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001640
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001641 for (i = 0; i < frag_count; i++) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001642
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001643 k = i % 4;
1644
1645 if ((k == 0) && (i > 0)) {
1646 /* move to next desc.*/
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001647 producer = get_next_index(producer, num_txd);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001648 hwdesc = &tx_ring->desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001649 netxen_clear_cmddesc((u64 *)hwdesc);
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001650 tx_ring->cmd_buf_arr[producer].skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001651 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001652
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001653 buffrag = &pbuf->frag_array[i];
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001654
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001655 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001656 switch (k) {
1657 case 0:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001658 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001659 break;
1660 case 1:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001661 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001662 break;
1663 case 2:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001664 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001665 break;
1666 case 3:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001667 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001668 break;
1669 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001670 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001671
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001672 tx_ring->producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001673
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001674 netxen_tso_check(netdev, tx_ring, first_desc, skb);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001675
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001676 netxen_nic_update_cmd_producer(adapter, tx_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001677
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001678 adapter->stats.txbytes += skb->len;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001679 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001680
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001681 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001682
1683drop_packet:
1684 adapter->stats.txdropped++;
1685 dev_kfree_skb_any(skb);
1686 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001687}
1688
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001689static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1690{
1691 struct net_device *netdev = adapter->netdev;
1692 uint32_t temp, temp_state, temp_val;
1693 int rv = 0;
1694
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001695 temp = NXRD32(adapter, CRB_TEMP_STATE);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001696
1697 temp_state = nx_get_temp_state(temp);
1698 temp_val = nx_get_temp_val(temp);
1699
1700 if (temp_state == NX_TEMP_PANIC) {
1701 printk(KERN_ALERT
1702 "%s: Device temperature %d degrees C exceeds"
1703 " maximum allowed. Hardware has been shut down.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001704 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001705 rv = 1;
1706 } else if (temp_state == NX_TEMP_WARN) {
1707 if (adapter->temp == NX_TEMP_NORMAL) {
1708 printk(KERN_ALERT
1709 "%s: Device temperature %d degrees C "
1710 "exceeds operating range."
1711 " Immediate action needed.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001712 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001713 }
1714 } else {
1715 if (adapter->temp == NX_TEMP_WARN) {
1716 printk(KERN_INFO
1717 "%s: Device temperature is now %d degrees C"
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001718 " in normal range.\n", netdev->name,
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001719 temp_val);
1720 }
1721 }
1722 adapter->temp = temp_state;
1723 return rv;
1724}
1725
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001726void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup)
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001727{
1728 struct net_device *netdev = adapter->netdev;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001729
1730 if (adapter->ahw.linkup && !linkup) {
1731 printk(KERN_INFO "%s: %s NIC Link is down\n",
1732 netxen_nic_driver_name, netdev->name);
1733 adapter->ahw.linkup = 0;
1734 if (netif_running(netdev)) {
1735 netif_carrier_off(netdev);
1736 netif_stop_queue(netdev);
1737 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001738 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001739 } else if (!adapter->ahw.linkup && linkup) {
1740 printk(KERN_INFO "%s: %s NIC Link is up\n",
1741 netxen_nic_driver_name, netdev->name);
1742 adapter->ahw.linkup = 1;
1743 if (netif_running(netdev)) {
1744 netif_carrier_on(netdev);
1745 netif_wake_queue(netdev);
1746 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001747 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001748 }
1749}
1750
1751static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1752{
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001753 u32 val, port, linkup;
1754
1755 port = adapter->physical_port;
1756
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001757 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001758 val = NXRD32(adapter, CRB_XG_STATE_P3);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001759 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1760 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001761 } else {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001762 val = NXRD32(adapter, CRB_XG_STATE);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001763 if (adapter->ahw.port_type == NETXEN_NIC_GBE)
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001764 linkup = (val >> port) & 1;
1765 else {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001766 val = (val >> port*8) & 0xff;
1767 linkup = (val == XG_LINK_UP);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001768 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001769 }
1770
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001771 netxen_advert_link_change(adapter, linkup);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001772}
1773
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001774static void netxen_nic_thermal_shutdown(struct netxen_adapter *adapter)
1775{
1776 struct net_device *netdev = adapter->netdev;
1777
1778 netif_device_detach(netdev);
1779 netxen_nic_down(adapter, netdev);
1780 netxen_nic_detach(adapter);
1781}
1782
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001783static void netxen_watchdog(unsigned long v)
1784{
1785 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001786
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001787 if (netxen_nic_check_temp(adapter))
1788 goto do_sched;
1789
1790 if (!adapter->has_link_events) {
1791 netxen_nic_handle_phy_intr(adapter);
1792
1793 if (adapter->link_changed)
1794 goto do_sched;
1795 }
1796
1797 if (netif_running(adapter->netdev))
1798 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1799
1800 return;
1801
1802do_sched:
1803 schedule_work(&adapter->watchdog_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001804}
1805
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001806void netxen_watchdog_task(struct work_struct *work)
1807{
1808 struct netxen_adapter *adapter =
1809 container_of(work, struct netxen_adapter, watchdog_task);
1810
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001811 if (adapter->temp == NX_TEMP_PANIC) {
1812 netxen_nic_thermal_shutdown(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001813 return;
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001814 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001815
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001816 if (adapter->link_changed)
1817 netxen_nic_set_link_parameters(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001818
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001819 if (netif_running(adapter->netdev))
1820 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001821}
1822
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001823static void netxen_tx_timeout(struct net_device *netdev)
1824{
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001825 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001826
1827 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001828 schedule_work(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001829}
1830
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001831static void netxen_reset_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001832{
Jeff Garzik47906542007-11-23 21:23:36 -05001833 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001834 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001835
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001836 if (!netif_running(adapter->netdev))
1837 return;
1838
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001839 netxen_napi_disable(adapter);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001840
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001841 adapter->netdev->trans_start = jiffies;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001842
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001843 netxen_napi_enable(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001844 netif_wake_queue(adapter->netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001845}
1846
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001847struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1848{
1849 struct netxen_adapter *adapter = netdev_priv(netdev);
1850 struct net_device_stats *stats = &adapter->net_stats;
1851
1852 memset(stats, 0, sizeof(*stats));
1853
Narender Kumar1bb482f2009-08-23 08:35:09 +00001854 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00001855 stats->tx_packets = adapter->stats.xmitfinished;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001856 stats->rx_bytes = adapter->stats.rxbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001857 stats->tx_bytes = adapter->stats.txbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001858 stats->rx_dropped = adapter->stats.rxdropped;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001859 stats->tx_dropped = adapter->stats.txdropped;
1860
1861 return stats;
1862}
1863
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001864static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001865{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001866 struct nx_host_sds_ring *sds_ring = data;
1867 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001868 u32 status = 0;
1869
1870 status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1871
1872 if (!(status & adapter->legacy_intr.int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001873 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301874
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001875 if (adapter->ahw.revision_id >= NX_P3_B1) {
1876 /* check interrupt state machine, to be sure */
1877 status = adapter->pci_read_immediate(adapter,
1878 ISR_INT_STATE_REG);
1879 if (!ISR_LEGACY_INT_TRIGGERED(status))
1880 return IRQ_NONE;
1881
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001882 } else {
1883 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001884
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001885 our_int = NXRD32(adapter, CRB_INT_VECTOR);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001886
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001887 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001888 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001889 return IRQ_NONE;
1890
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001891 /* claim interrupt */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001892 NXWR32(adapter, CRB_INT_VECTOR, (our_int & 0xffffffff));
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301893 }
1894
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001895 /* clear interrupt */
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001896 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001897 netxen_nic_disable_int(sds_ring);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001898
1899 adapter->pci_write_immediate(adapter,
1900 adapter->legacy_intr.tgt_status_reg,
1901 0xffffffff);
1902 /* read twice to ensure write is flushed */
1903 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1904 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1905
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001906 napi_schedule(&sds_ring->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001907
1908 return IRQ_HANDLED;
1909}
1910
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001911static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001912{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001913 struct nx_host_sds_ring *sds_ring = data;
1914 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001915
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001916 /* clear interrupt */
1917 adapter->pci_write_immediate(adapter,
Dhananjay Phadke7a2469c2009-05-08 22:02:27 +00001918 adapter->msi_tgt_status, 0xffffffff);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001919
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001920 napi_schedule(&sds_ring->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001921 return IRQ_HANDLED;
1922}
1923
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001924static irqreturn_t netxen_msix_intr(int irq, void *data)
1925{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001926 struct nx_host_sds_ring *sds_ring = data;
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001927
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001928 napi_schedule(&sds_ring->napi);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001929 return IRQ_HANDLED;
1930}
1931
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001932static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001933{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001934 struct nx_host_sds_ring *sds_ring =
1935 container_of(napi, struct nx_host_sds_ring, napi);
1936
1937 struct netxen_adapter *adapter = sds_ring->adapter;
1938
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001939 int tx_complete;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001940 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001941
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001942 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001943
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001944 work_done = netxen_process_rcv_ring(sds_ring, budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001945
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001946 if ((work_done < budget) && tx_complete) {
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001947 napi_complete(&sds_ring->napi);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001948 if (netif_running(adapter->netdev))
1949 netxen_nic_enable_int(sds_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001950 }
1951
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001952 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001953}
1954
1955#ifdef CONFIG_NET_POLL_CONTROLLER
1956static void netxen_nic_poll_controller(struct net_device *netdev)
1957{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001958 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001959 disable_irq(adapter->irq);
Jeff Garzik1494a812006-11-07 05:12:16 -05001960 netxen_intr(adapter->irq, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001961 enable_irq(adapter->irq);
1962}
1963#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001964
Narender Kumarfa3ce352009-08-24 19:23:28 +00001965static ssize_t
1966netxen_store_bridged_mode(struct device *dev,
1967 struct device_attribute *attr, const char *buf, size_t len)
1968{
1969 struct net_device *net = to_net_dev(dev);
1970 struct netxen_adapter *adapter = netdev_priv(net);
1971 unsigned long new;
1972 int ret = -EINVAL;
1973
1974 if (!(adapter->capabilities & NX_FW_CAPABILITY_BDG))
1975 goto err_out;
1976
1977 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1978 goto err_out;
1979
1980 if (strict_strtoul(buf, 2, &new))
1981 goto err_out;
1982
1983 if (!netxen_config_bridged_mode(adapter, !!new))
1984 ret = len;
1985
1986err_out:
1987 return ret;
1988}
1989
1990static ssize_t
1991netxen_show_bridged_mode(struct device *dev,
1992 struct device_attribute *attr, char *buf)
1993{
1994 struct net_device *net = to_net_dev(dev);
1995 struct netxen_adapter *adapter;
1996 int bridged_mode = 0;
1997
1998 adapter = netdev_priv(net);
1999
2000 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2001 bridged_mode = !!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED);
2002
2003 return sprintf(buf, "%d\n", bridged_mode);
2004}
2005
2006static struct device_attribute dev_attr_bridged_mode = {
2007 .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
2008 .show = netxen_show_bridged_mode,
2009 .store = netxen_store_bridged_mode,
2010};
2011
2012static void
2013netxen_create_sysfs_entries(struct netxen_adapter *adapter)
2014{
2015 struct net_device *netdev = adapter->netdev;
2016 struct device *dev = &netdev->dev;
2017
2018 if (adapter->capabilities & NX_FW_CAPABILITY_BDG) {
2019 /* bridged_mode control */
2020 if (device_create_file(dev, &dev_attr_bridged_mode)) {
2021 dev_warn(&netdev->dev,
2022 "failed to create bridged_mode sysfs entry\n");
2023 }
2024 }
2025}
2026
2027static void
2028netxen_remove_sysfs_entries(struct netxen_adapter *adapter)
2029{
2030 struct net_device *netdev = adapter->netdev;
2031 struct device *dev = &netdev->dev;
2032
2033 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2034 device_remove_file(dev, &dev_attr_bridged_mode);
2035}
2036
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002037#ifdef CONFIG_INET
2038
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002039#define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2040
2041static int
2042netxen_destip_supported(struct netxen_adapter *adapter)
2043{
2044 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2045 return 0;
2046
2047 if (adapter->ahw.cut_through)
2048 return 0;
2049
2050 return 1;
2051}
2052
2053static int netxen_netdev_event(struct notifier_block *this,
2054 unsigned long event, void *ptr)
2055{
2056 struct netxen_adapter *adapter;
2057 struct net_device *dev = (struct net_device *)ptr;
2058 struct in_device *indev;
2059
2060recheck:
2061 if (dev == NULL)
2062 goto done;
2063
2064 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2065 dev = vlan_dev_real_dev(dev);
2066 goto recheck;
2067 }
2068
2069 if (!is_netxen_netdev(dev))
2070 goto done;
2071
2072 adapter = netdev_priv(dev);
2073
2074 if (!adapter || !netxen_destip_supported(adapter))
2075 goto done;
2076
2077 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2078 goto done;
2079
2080 indev = in_dev_get(dev);
2081 if (!indev)
2082 goto done;
2083
2084 for_ifa(indev) {
2085 switch (event) {
2086 case NETDEV_UP:
2087 netxen_config_ipaddr(adapter,
2088 ifa->ifa_address, NX_IP_UP);
2089 break;
2090 case NETDEV_DOWN:
2091 netxen_config_ipaddr(adapter,
2092 ifa->ifa_address, NX_IP_DOWN);
2093 break;
2094 default:
2095 break;
2096 }
2097 } endfor_ifa(indev);
2098
2099 in_dev_put(indev);
2100done:
2101 return NOTIFY_DONE;
2102}
2103
2104static int
2105netxen_inetaddr_event(struct notifier_block *this,
2106 unsigned long event, void *ptr)
2107{
2108 struct netxen_adapter *adapter;
2109 struct net_device *dev;
2110
2111 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
2112
2113 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
2114
2115recheck:
2116 if (dev == NULL || !netif_running(dev))
2117 goto done;
2118
2119 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2120 dev = vlan_dev_real_dev(dev);
2121 goto recheck;
2122 }
2123
2124 if (!is_netxen_netdev(dev))
2125 goto done;
2126
2127 adapter = netdev_priv(dev);
2128
2129 if (!adapter || !netxen_destip_supported(adapter))
2130 goto done;
2131
2132 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2133 goto done;
2134
2135 switch (event) {
2136 case NETDEV_UP:
2137 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP);
2138 break;
2139 case NETDEV_DOWN:
2140 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN);
2141 break;
2142 default:
2143 break;
2144 }
2145
2146done:
2147 return NOTIFY_DONE;
2148}
2149
2150static struct notifier_block netxen_netdev_cb = {
2151 .notifier_call = netxen_netdev_event,
2152};
2153
2154static struct notifier_block netxen_inetaddr_cb = {
2155 .notifier_call = netxen_inetaddr_event,
2156};
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002157#endif
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002158
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002159static struct pci_driver netxen_driver = {
2160 .name = netxen_nic_driver_name,
2161 .id_table = netxen_pci_tbl,
2162 .probe = netxen_nic_probe,
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002163 .remove = __devexit_p(netxen_nic_remove),
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002164#ifdef CONFIG_PM
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002165 .suspend = netxen_nic_suspend,
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00002166 .resume = netxen_nic_resume,
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002167#endif
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00002168 .shutdown = netxen_nic_shutdown
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002169};
2170
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002171static int __init netxen_init_module(void)
2172{
Dhananjay Phadkeff4fbd42009-03-13 14:52:06 +00002173 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
2174
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002175#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002176 register_netdevice_notifier(&netxen_netdev_cb);
2177 register_inetaddr_notifier(&netxen_inetaddr_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002178#endif
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002179
Amit S. Kale184231b2007-01-22 06:52:53 -08002180 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002181}
2182
2183module_init(netxen_init_module);
2184
2185static void __exit netxen_exit_module(void)
2186{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002187 pci_unregister_driver(&netxen_driver);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002188
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002189#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002190 unregister_inetaddr_notifier(&netxen_inetaddr_cb);
2191 unregister_netdevice_notifier(&netxen_netdev_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002192#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002193}
2194
2195module_exit(netxen_exit_module);