blob: 008657423f8e009b99db08b9d26fa4e7c5b7b661 [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#include "netxen_nic_phan_reg.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040037
Jeff Garzik1494a812006-11-07 05:12:16 -050038#include <linux/dma-mapping.h>
Dhananjay Phadke391587c2009-01-14 20:48:11 -080039#include <linux/if_vlan.h>
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030040#include <net/ip.h>
Dhananjay Phadke00977782009-01-16 11:03:25 -080041#include <linux/ipv6.h>
Dhananjay Phadke6598b162009-07-26 20:07:37 +000042#include <linux/inetdevice.h>
Jeff Garzik1494a812006-11-07 05:12:16 -050043
Amit S. Kale3d396eb2006-10-21 15:33:03 -040044MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
45MODULE_LICENSE("GPL");
46MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
47
dhananjay@netxen.comceded322007-07-19 14:41:09 +053048char netxen_nic_driver_name[] = "netxen_nic";
Amit S. Kale3d396eb2006-10-21 15:33:03 -040049static char netxen_nic_driver_string[] = "NetXen Network Driver version "
Amit S. Kalecb8011a2006-11-29 09:00:10 -080050 NETXEN_NIC_LINUX_VERSIONID;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040051
Dhananjay Phadke29566402008-07-21 19:44:04 -070052static int port_mode = NETXEN_PORT_MODE_AUTO_NEG;
53
54/* Default to restricted 1G auto-neg mode */
55static int wol_port_mode = 5;
56
57static int use_msi = 1;
58
59static int use_msi_x = 1;
60
Amit S. Kale3d396eb2006-10-21 15:33:03 -040061/* Local functions to NetXen NIC driver */
62static int __devinit netxen_nic_probe(struct pci_dev *pdev,
Dhananjay Phadke29566402008-07-21 19:44:04 -070063 const struct pci_device_id *ent);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040064static void __devexit netxen_nic_remove(struct pci_dev *pdev);
65static int netxen_nic_open(struct net_device *netdev);
66static int netxen_nic_close(struct net_device *netdev);
67static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *);
68static 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
Jeff Garzik1494a812006-11-07 05:12:16 -050075static irqreturn_t netxen_intr(int irq, void *data);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -070076static irqreturn_t netxen_msi_intr(int irq, void *data);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -080077static irqreturn_t netxen_msix_intr(int irq, void *data);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040078
79/* PCI Device ID Table */
Al Viro70081ac2008-06-23 02:04:50 +010080#define ENTRY(device) \
Dhananjay Phadke040dec32008-09-12 06:55:14 -070081 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
Al Viro70081ac2008-06-23 02:04:50 +010082 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
83
Amit S. Kale3d396eb2006-10-21 15:33:03 -040084static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
Dhananjay Phadke040dec32008-09-12 06:55:14 -070085 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR),
86 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4),
87 ENTRY(PCI_DEVICE_ID_NX2031_4GCU),
88 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ),
89 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ),
90 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT),
91 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2),
92 ENTRY(PCI_DEVICE_ID_NX3031),
Amit S. Kale3d396eb2006-10-21 15:33:03 -040093 {0,}
94};
95
96MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
97
Amit S. Kaleed25ffa2006-12-04 09:23:25 -080098static void netxen_watchdog(unsigned long);
99
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700100static uint32_t crb_cmd_producer[4] = {
101 CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1,
102 CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3
103};
104
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700105void
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700106netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000107 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700108{
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000109 NXWR32(adapter, tx_ring->crb_cmd_producer, tx_ring->producer);
110
111 if (netxen_tx_avail(tx_ring) <= TX_STOP_THRESH) {
112 netif_stop_queue(adapter->netdev);
113 smp_mb();
114 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700115}
116
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700117static uint32_t crb_cmd_consumer[4] = {
118 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
119 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
120};
121
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700122static inline void
123netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000124 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700125{
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000126 NXWR32(adapter, tx_ring->crb_cmd_consumer, tx_ring->sw_consumer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700127}
128
Dhananjay Phadke29566402008-07-21 19:44:04 -0700129static uint32_t msi_tgt_status[8] = {
Dhananjay Phadke443be792008-03-17 19:59:48 -0700130 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700131 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
132 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
133 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
Dhananjay Phadke443be792008-03-17 19:59:48 -0700134};
135
Dhananjay Phadke29566402008-07-21 19:44:04 -0700136static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
137
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000138static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700139{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000140 struct netxen_adapter *adapter = sds_ring->adapter;
141
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000142 NXWR32(adapter, sds_ring->crb_intr_mask, 0);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700143}
144
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000145static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700146{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000147 struct netxen_adapter *adapter = sds_ring->adapter;
148
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000149 NXWR32(adapter, sds_ring->crb_intr_mask, 0x1);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700150
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700151 if (!NETXEN_IS_MSI_FAMILY(adapter))
152 adapter->pci_write_immediate(adapter,
153 adapter->legacy_intr.tgt_mask_reg, 0xfbff);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700154}
155
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000156static int
157netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count)
158{
159 int size = sizeof(struct nx_host_sds_ring) * count;
160
161 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
162
163 return (recv_ctx->sds_rings == NULL);
164}
165
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000166static void
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000167netxen_free_sds_rings(struct netxen_recv_context *recv_ctx)
168{
169 if (recv_ctx->sds_rings != NULL)
170 kfree(recv_ctx->sds_rings);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000171
172 recv_ctx->sds_rings = NULL;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000173}
174
175static int
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000176netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
177{
178 int ring;
179 struct nx_host_sds_ring *sds_ring;
180 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
181
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000182 if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
Dhananjay Phadkef17443f2009-07-26 20:07:43 +0000183 return -ENOMEM;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000184
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000185 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
186 sds_ring = &recv_ctx->sds_rings[ring];
187 netif_napi_add(netdev, &sds_ring->napi,
188 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
189 }
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000190
191 return 0;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000192}
193
194static void
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000195netxen_napi_del(struct netxen_adapter *adapter)
196{
197 int ring;
198 struct nx_host_sds_ring *sds_ring;
199 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
200
201 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
202 sds_ring = &recv_ctx->sds_rings[ring];
203 netif_napi_del(&sds_ring->napi);
204 }
205
206 netxen_free_sds_rings(&adapter->recv_ctx);
207}
208
209static void
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000210netxen_napi_enable(struct netxen_adapter *adapter)
211{
212 int ring;
213 struct nx_host_sds_ring *sds_ring;
214 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
215
216 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
217 sds_ring = &recv_ctx->sds_rings[ring];
218 napi_enable(&sds_ring->napi);
219 netxen_nic_enable_int(sds_ring);
220 }
221}
222
223static void
224netxen_napi_disable(struct netxen_adapter *adapter)
225{
226 int ring;
227 struct nx_host_sds_ring *sds_ring;
228 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
229
230 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
231 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000232 netxen_nic_disable_int(sds_ring);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000233 napi_synchronize(&sds_ring->napi);
234 napi_disable(&sds_ring->napi);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000235 }
236}
237
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000238static int nx_set_dma_mask(struct netxen_adapter *adapter)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700239{
240 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000241 uint64_t mask, cmask;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700242
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000243 adapter->pci_using_dac = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700244
Yang Hongyang6afd1422009-04-06 19:01:15 -0700245 mask = DMA_BIT_MASK(32);
Yang Hongyang6afd1422009-04-06 19:01:15 -0700246 cmask = DMA_BIT_MASK(32);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000247
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000248 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000249#ifndef CONFIG_IA64
Yang Hongyang6afd1422009-04-06 19:01:15 -0700250 mask = DMA_BIT_MASK(35);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000251#endif
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000252 } else {
253 mask = DMA_BIT_MASK(39);
254 cmask = mask;
255 }
256
Dhananjay Phadke29566402008-07-21 19:44:04 -0700257 if (pci_set_dma_mask(pdev, mask) == 0 &&
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000258 pci_set_consistent_dma_mask(pdev, cmask) == 0) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700259 adapter->pci_using_dac = 1;
260 return 0;
261 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700262
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000263 return -EIO;
264}
265
266/* Update addressable range if firmware supports it */
267static int
268nx_update_dma_mask(struct netxen_adapter *adapter)
269{
270 int change, shift, err;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000271 uint64_t mask, old_mask, old_cmask;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000272 struct pci_dev *pdev = adapter->pdev;
273
274 change = 0;
275
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000276 shift = NXRD32(adapter, CRB_DMA_SHIFT);
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000277 if (shift > 32)
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000278 return 0;
279
280 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9))
281 change = 1;
282 else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4))
283 change = 1;
284
285 if (change) {
286 old_mask = pdev->dma_mask;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000287 old_cmask = pdev->dev.coherent_dma_mask;
288
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000289 mask = DMA_BIT_MASK(32+shift);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000290
291 err = pci_set_dma_mask(pdev, mask);
292 if (err)
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000293 goto err_out;
294
295 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
296
297 err = pci_set_consistent_dma_mask(pdev, mask);
298 if (err)
299 goto err_out;
300 }
301 dev_info(&pdev->dev, "using %d-bit dma mask\n", 32+shift);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700302 }
303
Dhananjay Phadke29566402008-07-21 19:44:04 -0700304 return 0;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000305
306err_out:
307 pci_set_dma_mask(pdev, old_mask);
308 pci_set_consistent_dma_mask(pdev, old_cmask);
309 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700310}
311
Dhananjay Phadke24767ab2009-07-27 11:08:00 -0700312static void
313netxen_check_options(struct netxen_adapter *adapter)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700314{
Dhananjay Phadke24767ab2009-07-27 11:08:00 -0700315 if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
316 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
317 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
318 } else if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
319 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
320 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
321 }
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000322
Dhananjay Phadkef6d21f42009-04-07 22:50:46 +0000323 adapter->msix_supported = 0;
324 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700325 adapter->msix_supported = !!use_msi_x;
Dhananjay Phadkef6d21f42009-04-07 22:50:46 +0000326 adapter->rss_supported = !!use_msi_x;
327 } else if (adapter->fw_version >= NETXEN_VERSION_CODE(3, 4, 336)) {
328 switch (adapter->ahw.board_type) {
329 case NETXEN_BRDTYPE_P2_SB31_10G:
330 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkef6d21f42009-04-07 22:50:46 +0000331 adapter->msix_supported = !!use_msi_x;
332 adapter->rss_supported = !!use_msi_x;
333 break;
334 default:
335 break;
336 }
337 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700338
Dhananjay Phadke24767ab2009-07-27 11:08:00 -0700339 adapter->num_txd = MAX_CMD_DESCRIPTORS;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700340
Dhananjay Phadke24767ab2009-07-27 11:08:00 -0700341 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
342 adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS;
343 adapter->max_rds_rings = 3;
344 } else {
345 adapter->num_lro_rxd = 0;
346 adapter->max_rds_rings = 2;
347 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700348}
349
350static int
351netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
352{
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800353 u32 val, timeout;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700354
355 if (first_boot == 0x55555555) {
356 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000357 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800358
359 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
360 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700361
362 /* PCI bus master workaround */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000363 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700364 if (!(first_boot & 0x4)) {
365 first_boot |= 0x4;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000366 NXWR32(adapter, NETXEN_PCIE_REG(0x4), first_boot);
367 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700368 }
369
370 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000371 first_boot = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700372 if (first_boot != 0x80000f) {
373 /* clear the register for future unloads/loads */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000374 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), 0);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800375 return -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700376 }
377
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800378 /* Start P2 boot loader */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000379 val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
380 NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800381 timeout = 0;
382 do {
383 msleep(1);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000384 val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800385
386 if (++timeout > 5000)
387 return -EIO;
388
389 } while (val == NETXEN_BDINFO_MAGIC);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700390 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800391 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700392}
393
394static void netxen_set_port_mode(struct netxen_adapter *adapter)
395{
396 u32 val, data;
397
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000398 val = adapter->ahw.board_type;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700399 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
400 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
401 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
402 data = NETXEN_PORT_MODE_802_3_AP;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000403 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700404 } else if (port_mode == NETXEN_PORT_MODE_XG) {
405 data = NETXEN_PORT_MODE_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000406 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700407 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
408 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000409 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700410 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
411 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000412 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700413 } else {
414 data = NETXEN_PORT_MODE_AUTO_NEG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000415 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700416 }
417
418 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
419 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
420 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
421 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
422 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
423 }
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000424 NXWR32(adapter, NETXEN_WOL_PORT_MODE, wol_port_mode);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700425 }
426}
427
Dhananjay Phadke29566402008-07-21 19:44:04 -0700428static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
429{
430 u32 control;
431 int pos;
432
433 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
434 if (pos) {
435 pci_read_config_dword(pdev, pos, &control);
436 if (enable)
437 control |= PCI_MSIX_FLAGS_ENABLE;
438 else
439 control = 0;
440 pci_write_config_dword(pdev, pos, control);
441 }
442}
443
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000444static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700445{
446 int i;
447
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000448 for (i = 0; i < count; i++)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700449 adapter->msix_entries[i].entry = i;
450}
451
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700452static int
453netxen_read_mac_addr(struct netxen_adapter *adapter)
454{
455 int i;
456 unsigned char *p;
457 __le64 mac_addr;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700458 struct net_device *netdev = adapter->netdev;
459 struct pci_dev *pdev = adapter->pdev;
460
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700461 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
462 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
463 return -EIO;
464 } else {
465 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
466 return -EIO;
467 }
468
469 p = (unsigned char *)&mac_addr;
470 for (i = 0; i < 6; i++)
471 netdev->dev_addr[i] = *(p + 5 - i);
472
473 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
474
475 /* set station address */
476
Johannes Berge1749612008-10-27 15:59:26 -0700477 if (!is_valid_ether_addr(netdev->perm_addr))
478 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700479
480 return 0;
481}
482
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000483int netxen_nic_set_mac(struct net_device *netdev, void *p)
484{
485 struct netxen_adapter *adapter = netdev_priv(netdev);
486 struct sockaddr *addr = p;
487
488 if (!is_valid_ether_addr(addr->sa_data))
489 return -EINVAL;
490
491 if (netif_running(netdev)) {
492 netif_device_detach(netdev);
493 netxen_napi_disable(adapter);
494 }
495
496 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
497 adapter->macaddr_set(adapter, addr->sa_data);
498
499 if (netif_running(netdev)) {
500 netif_device_attach(netdev);
501 netxen_napi_enable(adapter);
502 }
503 return 0;
504}
505
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800506static void netxen_set_multicast_list(struct net_device *dev)
507{
508 struct netxen_adapter *adapter = netdev_priv(dev);
509
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000510 adapter->set_multi(dev);
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800511}
512
513static const struct net_device_ops netxen_netdev_ops = {
514 .ndo_open = netxen_nic_open,
515 .ndo_stop = netxen_nic_close,
516 .ndo_start_xmit = netxen_nic_xmit_frame,
517 .ndo_get_stats = netxen_nic_get_stats,
518 .ndo_validate_addr = eth_validate_addr,
519 .ndo_set_multicast_list = netxen_set_multicast_list,
520 .ndo_set_mac_address = netxen_nic_set_mac,
521 .ndo_change_mtu = netxen_nic_change_mtu,
522 .ndo_tx_timeout = netxen_tx_timeout,
523#ifdef CONFIG_NET_POLL_CONTROLLER
524 .ndo_poll_controller = netxen_nic_poll_controller,
525#endif
526};
527
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800528static void
529netxen_setup_intr(struct netxen_adapter *adapter)
530{
531 struct netxen_legacy_intr_set *legacy_intrp;
532 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000533 int err, num_msix;
534
535 if (adapter->rss_supported) {
536 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
537 MSIX_ENTRIES_PER_ADAPTER : 2;
538 } else
539 num_msix = 1;
540
541 adapter->max_sds_rings = 1;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800542
543 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800544
545 if (adapter->ahw.revision_id >= NX_P3_B0)
546 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
547 else
548 legacy_intrp = &legacy_intr[0];
549 adapter->legacy_intr.int_vec_bit = legacy_intrp->int_vec_bit;
550 adapter->legacy_intr.tgt_status_reg = legacy_intrp->tgt_status_reg;
551 adapter->legacy_intr.tgt_mask_reg = legacy_intrp->tgt_mask_reg;
552 adapter->legacy_intr.pci_int_reg = legacy_intrp->pci_int_reg;
553
554 netxen_set_msix_bit(pdev, 0);
555
556 if (adapter->msix_supported) {
557
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000558 netxen_init_msix_entries(adapter, num_msix);
559 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
560 if (err == 0) {
561 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
562 netxen_set_msix_bit(pdev, 1);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800563
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000564 if (adapter->rss_supported)
565 adapter->max_sds_rings = num_msix;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800566
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000567 dev_info(&pdev->dev, "using msi-x interrupts\n");
568 return;
569 }
570
571 if (err > 0)
572 pci_disable_msix(pdev);
573
574 /* fall through for msi */
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800575 }
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000576
577 if (use_msi && !pci_enable_msi(pdev)) {
578 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
579 adapter->msi_tgt_status =
580 msi_tgt_status[adapter->ahw.pci_func];
581 dev_info(&pdev->dev, "using msi interrupts\n");
Dhananjay Phadkef67f3402009-05-18 21:46:40 -0700582 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000583 return;
584 }
585
586 dev_info(&pdev->dev, "using legacy interrupts\n");
587 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800588}
589
590static void
591netxen_teardown_intr(struct netxen_adapter *adapter)
592{
593 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
594 pci_disable_msix(adapter->pdev);
595 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
596 pci_disable_msi(adapter->pdev);
597}
598
599static void
600netxen_cleanup_pci_map(struct netxen_adapter *adapter)
601{
602 if (adapter->ahw.db_base != NULL)
603 iounmap(adapter->ahw.db_base);
604 if (adapter->ahw.pci_base0 != NULL)
605 iounmap(adapter->ahw.pci_base0);
606 if (adapter->ahw.pci_base1 != NULL)
607 iounmap(adapter->ahw.pci_base1);
608 if (adapter->ahw.pci_base2 != NULL)
609 iounmap(adapter->ahw.pci_base2);
610}
611
612static int
613netxen_setup_pci_map(struct netxen_adapter *adapter)
614{
615 void __iomem *mem_ptr0 = NULL;
616 void __iomem *mem_ptr1 = NULL;
617 void __iomem *mem_ptr2 = NULL;
618 void __iomem *db_ptr = NULL;
619
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800620 unsigned long mem_base, mem_len, db_base, db_len = 0, pci_len0 = 0;
621
622 struct pci_dev *pdev = adapter->pdev;
623 int pci_func = adapter->ahw.pci_func;
624
625 int err = 0;
626
627 /*
628 * Set the CRB window to invalid. If any register in window 0 is
629 * accessed it should set the window to 0 and then reset it to 1.
630 */
631 adapter->curr_window = 255;
632 adapter->ahw.qdr_sn_window = -1;
633 adapter->ahw.ddr_mn_window = -1;
634
635 /* remap phys address */
636 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
637 mem_len = pci_resource_len(pdev, 0);
638 pci_len0 = 0;
639
640 adapter->hw_write_wx = netxen_nic_hw_write_wx_128M;
641 adapter->hw_read_wx = netxen_nic_hw_read_wx_128M;
642 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_128M;
643 adapter->pci_write_immediate = netxen_nic_pci_write_immediate_128M;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800644 adapter->pci_set_window = netxen_nic_pci_set_window_128M;
645 adapter->pci_mem_read = netxen_nic_pci_mem_read_128M;
646 adapter->pci_mem_write = netxen_nic_pci_mem_write_128M;
647
648 /* 128 Meg of memory */
649 if (mem_len == NETXEN_PCI_128MB_SIZE) {
650 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
651 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
652 SECOND_PAGE_GROUP_SIZE);
653 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
654 THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800655 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
656 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
657 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
658 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800659 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
660 adapter->hw_write_wx = netxen_nic_hw_write_wx_2M;
661 adapter->hw_read_wx = netxen_nic_hw_read_wx_2M;
662 adapter->pci_read_immediate = netxen_nic_pci_read_immediate_2M;
663 adapter->pci_write_immediate =
664 netxen_nic_pci_write_immediate_2M;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800665 adapter->pci_set_window = netxen_nic_pci_set_window_2M;
666 adapter->pci_mem_read = netxen_nic_pci_mem_read_2M;
667 adapter->pci_mem_write = netxen_nic_pci_mem_write_2M;
668
669 mem_ptr0 = pci_ioremap_bar(pdev, 0);
670 if (mem_ptr0 == NULL) {
671 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
672 return -EIO;
673 }
674 pci_len0 = mem_len;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800675
676 adapter->ahw.ddr_mn_window = 0;
677 adapter->ahw.qdr_sn_window = 0;
678
679 adapter->ahw.mn_win_crb = 0x100000 + PCIX_MN_WINDOW +
680 (pci_func * 0x20);
681 adapter->ahw.ms_win_crb = 0x100000 + PCIX_SN_WINDOW;
682 if (pci_func < 4)
683 adapter->ahw.ms_win_crb += (pci_func * 0x20);
684 else
685 adapter->ahw.ms_win_crb +=
686 0xA0 + ((pci_func - 4) * 0x10);
687 } else {
688 return -EIO;
689 }
690
691 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
692
693 adapter->ahw.pci_base0 = mem_ptr0;
694 adapter->ahw.pci_len0 = pci_len0;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800695 adapter->ahw.pci_base1 = mem_ptr1;
696 adapter->ahw.pci_base2 = mem_ptr2;
697
698 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
699 goto skip_doorbell;
700
701 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
702 db_len = pci_resource_len(pdev, 4);
703
704 if (db_len == 0) {
705 printk(KERN_ERR "%s: doorbell is disabled\n",
706 netxen_nic_driver_name);
707 err = -EIO;
708 goto err_out;
709 }
710
711 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
712 if (!db_ptr) {
713 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
714 netxen_nic_driver_name);
715 err = -EIO;
716 goto err_out;
717 }
718
719skip_doorbell:
720 adapter->ahw.db_base = db_ptr;
721 adapter->ahw.db_len = db_len;
722 return 0;
723
724err_out:
725 netxen_cleanup_pci_map(adapter);
726 return err;
727}
728
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800729static int
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000730netxen_start_firmware(struct netxen_adapter *adapter, int request_fw)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800731{
732 int val, err, first_boot;
733 struct pci_dev *pdev = adapter->pdev;
734
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000735 int first_driver = 0;
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000736
737 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
738 first_driver = (adapter->portnum == 0);
739 else
740 first_driver = (adapter->ahw.pci_func == 0);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000741
742 if (!first_driver)
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000743 goto wait_init;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000744
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000745 first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800746
747 err = netxen_check_hw_init(adapter, first_boot);
748 if (err) {
749 dev_err(&pdev->dev, "error in init HW init sequence\n");
750 return err;
751 }
752
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000753 if (request_fw)
754 netxen_request_firmware(adapter);
755
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000756 err = netxen_need_fw_reset(adapter);
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000757 if (err < 0)
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000758 return err;
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000759 if (err == 0)
760 goto wait_init;
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000761
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800762 if (first_boot != 0x55555555) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000763 NXWR32(adapter, CRB_CMDPEG_STATE, 0);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800764 netxen_pinit_from_rom(adapter, 0);
765 msleep(1);
766 }
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000767
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000768 NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555);
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000769 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
770 netxen_set_port_mode(adapter);
771
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800772 netxen_load_firmware(adapter);
773
774 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
775
776 /* Initialize multicast addr pool owners */
777 val = 0x7654;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000778 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800779 val |= 0x0f000000;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000780 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800781
782 }
783
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000784 err = netxen_init_dummy_dma(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800785 if (err)
786 return err;
787
788 /*
789 * Tell the hardware our version number.
790 */
791 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
792 | ((_NETXEN_NIC_LINUX_MINOR << 8))
793 | (_NETXEN_NIC_LINUX_SUBVERSION);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000794 NXWR32(adapter, CRB_DRIVER_VERSION, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800795
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000796wait_init:
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800797 /* Handshake with the card before we register the devices. */
798 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
799 if (err) {
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000800 netxen_free_dummy_dma(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800801 return err;
802 }
803
Dhananjay Phadke68b3cae2009-07-26 20:07:36 +0000804 nx_update_dma_mask(adapter);
805
806 netxen_nic_get_firmware_info(adapter);
807
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800808 return 0;
809}
810
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000811static int
812netxen_nic_request_irq(struct netxen_adapter *adapter)
813{
814 irq_handler_t handler;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000815 struct nx_host_sds_ring *sds_ring;
816 int err, ring;
817
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000818 unsigned long flags = IRQF_SAMPLE_RANDOM;
819 struct net_device *netdev = adapter->netdev;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000820 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000821
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000822 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
823 handler = netxen_msix_intr;
824 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
825 handler = netxen_msi_intr;
826 else {
827 flags |= IRQF_SHARED;
828 handler = netxen_intr;
829 }
830 adapter->irq = netdev->irq;
831
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000832 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
833 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000834 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000835 err = request_irq(sds_ring->irq, handler,
836 flags, sds_ring->name, sds_ring);
837 if (err)
838 return err;
839 }
840
841 return 0;
842}
843
844static void
845netxen_nic_free_irq(struct netxen_adapter *adapter)
846{
847 int ring;
848 struct nx_host_sds_ring *sds_ring;
849
850 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
851
852 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
853 sds_ring = &recv_ctx->sds_rings[ring];
854 free_irq(sds_ring->irq, sds_ring);
855 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000856}
857
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000858static void
859netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter)
860{
861 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
862 adapter->coal.normal.data.rx_time_us =
863 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
864 adapter->coal.normal.data.rx_packets =
865 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
866 adapter->coal.normal.data.tx_time_us =
867 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US;
868 adapter->coal.normal.data.tx_packets =
869 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS;
870}
871
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000872static int
873netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
874{
875 int err;
876
877 err = adapter->init_port(adapter, adapter->physical_port);
878 if (err) {
879 printk(KERN_ERR "%s: Failed to initialize port %d\n",
880 netxen_nic_driver_name, adapter->portnum);
881 return err;
882 }
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000883 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
884 adapter->macaddr_set(adapter, netdev->dev_addr);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000885
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000886 adapter->set_multi(netdev);
887 adapter->set_mtu(adapter, netdev->mtu);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000888
889 adapter->ahw.linkup = 0;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000890
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000891 if (adapter->max_sds_rings > 1)
892 netxen_config_rss(adapter, 1);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000893
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000894 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
895 netxen_config_intr_coalesce(adapter);
896
Narender Kumar1bb482f2009-08-23 08:35:09 +0000897 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
898 netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED);
899
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000900 netxen_napi_enable(adapter);
901
Dhananjay Phadke5103c9f2009-04-28 15:29:09 +0000902 if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000903 netxen_linkevent_request(adapter, 1);
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000904 else
905 netxen_nic_set_link_parameters(adapter);
906
907 mod_timer(&adapter->watchdog_timer, jiffies);
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000908
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000909 return 0;
910}
911
912static void
913netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
914{
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000915 spin_lock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000916 netif_carrier_off(netdev);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000917 netif_tx_disable(netdev);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000918
919 if (adapter->stop_port)
920 adapter->stop_port(adapter);
921
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000922 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
923 netxen_p3_free_mac_list(adapter);
924
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000925 netxen_napi_disable(adapter);
926
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000927 netxen_release_tx_buffers(adapter);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000928 spin_unlock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000929
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000930 del_timer_sync(&adapter->watchdog_timer);
931}
932
933
934static int
935netxen_nic_attach(struct netxen_adapter *adapter)
936{
937 struct net_device *netdev = adapter->netdev;
938 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000939 int err, ring;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000940 struct nx_host_rds_ring *rds_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000941 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000942
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -0700943 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
944 return 0;
945
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000946 err = netxen_init_firmware(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000947 if (err)
948 return err;
949
950 err = netxen_napi_add(adapter, netdev);
951 if (err)
952 return err;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000953
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000954 err = netxen_alloc_sw_resources(adapter);
955 if (err) {
956 printk(KERN_ERR "%s: Error in setting sw resources\n",
957 netdev->name);
958 return err;
959 }
960
961 netxen_nic_clear_stats(adapter);
962
963 err = netxen_alloc_hw_resources(adapter);
964 if (err) {
965 printk(KERN_ERR "%s: Error in setting hw resources\n",
966 netdev->name);
967 goto err_out_free_sw;
968 }
969
Dhananjay Phadke4f96b982009-07-26 20:07:42 +0000970 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000971 tx_ring = adapter->tx_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000972 tx_ring->crb_cmd_producer = crb_cmd_producer[adapter->portnum];
973 tx_ring->crb_cmd_consumer = crb_cmd_consumer[adapter->portnum];
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000974
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000975 tx_ring->producer = 0;
976 tx_ring->sw_consumer = 0;
977
978 netxen_nic_update_cmd_producer(adapter, tx_ring);
979 netxen_nic_update_cmd_consumer(adapter, tx_ring);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000980 }
981
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000982 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
983 rds_ring = &adapter->recv_ctx.rds_rings[ring];
984 netxen_post_rx_buffers(adapter, ring, rds_ring);
985 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000986
987 err = netxen_nic_request_irq(adapter);
988 if (err) {
989 dev_err(&pdev->dev, "%s: failed to setup interrupt\n",
990 netdev->name);
991 goto err_out_free_rxbuf;
992 }
993
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000994 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
995 netxen_nic_init_coalesce_defaults(adapter);
996
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000997 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
998 return 0;
999
1000err_out_free_rxbuf:
1001 netxen_release_rx_buffers(adapter);
1002 netxen_free_hw_resources(adapter);
1003err_out_free_sw:
1004 netxen_free_sw_resources(adapter);
1005 return err;
1006}
1007
1008static void
1009netxen_nic_detach(struct netxen_adapter *adapter)
1010{
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001011 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1012 return;
1013
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001014 netxen_free_hw_resources(adapter);
Dhananjay Phadkecf981ff2009-07-17 15:27:06 +00001015 netxen_release_rx_buffers(adapter);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +00001016 netxen_nic_free_irq(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +00001017 netxen_napi_del(adapter);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001018 netxen_free_sw_resources(adapter);
1019
1020 adapter->is_up = 0;
1021}
1022
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001023int
1024netxen_nic_reset_context(struct netxen_adapter *adapter)
1025{
1026 int err = 0;
1027 struct net_device *netdev = adapter->netdev;
1028
1029 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
1030
1031 if (netif_running(netdev))
1032 netxen_nic_down(adapter, netdev);
1033
1034 netxen_nic_detach(adapter);
1035
1036 err = netxen_nic_attach(adapter);
1037 if (err)
1038 goto done;
1039
1040 if (netif_running(netdev))
1041 err = netxen_nic_up(adapter, netdev);
1042 }
1043done:
1044 return err;
1045}
1046
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001047static int
1048netxen_setup_netdev(struct netxen_adapter *adapter,
1049 struct net_device *netdev)
1050{
1051 int err = 0;
1052 struct pci_dev *pdev = adapter->pdev;
1053
1054 adapter->rx_csum = 1;
1055 adapter->mc_enabled = 0;
1056 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1057 adapter->max_mc_count = 38;
1058 else
1059 adapter->max_mc_count = 16;
1060
1061 netdev->netdev_ops = &netxen_netdev_ops;
1062 netdev->watchdog_timeo = 2*HZ;
1063
1064 netxen_nic_change_mtu(netdev, netdev->mtu);
1065
1066 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
1067
1068 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1069 netdev->features |= (NETIF_F_GRO);
1070 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1071
1072 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1073 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1074 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1075 }
1076
1077 if (adapter->pci_using_dac) {
1078 netdev->features |= NETIF_F_HIGHDMA;
1079 netdev->vlan_features |= NETIF_F_HIGHDMA;
1080 }
1081
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001082 if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX)
1083 netdev->features |= (NETIF_F_HW_VLAN_TX);
1084
Narender Kumar1bb482f2009-08-23 08:35:09 +00001085 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
1086 netdev->features |= NETIF_F_LRO;
1087
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001088 netdev->irq = adapter->msix_entries[0].vector;
1089
1090 err = netxen_napi_add(adapter, netdev);
1091 if (err)
1092 return err;
1093
1094 init_timer(&adapter->watchdog_timer);
1095 adapter->watchdog_timer.function = &netxen_watchdog;
1096 adapter->watchdog_timer.data = (unsigned long)adapter;
1097 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
1098 INIT_WORK(&adapter->tx_timeout_task, netxen_reset_task);
1099
1100 if (netxen_read_mac_addr(adapter))
1101 dev_warn(&pdev->dev, "failed to read mac addr\n");
1102
1103 netif_carrier_off(netdev);
1104 netif_stop_queue(netdev);
1105
1106 err = register_netdev(netdev);
1107 if (err) {
1108 dev_err(&pdev->dev, "failed to register net device\n");
1109 return err;
1110 }
1111
1112 return 0;
1113}
1114
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001115static int __devinit
1116netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1117{
1118 struct net_device *netdev = NULL;
1119 struct netxen_adapter *adapter = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001120 int i = 0, err;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001121 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001122 uint8_t revision_id;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001123
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001124 if (pdev->class != 0x020000) {
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001125 printk(KERN_DEBUG "NetXen function %d, class %x will not "
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001126 "be enabled.\n",pci_func_id, pdev->class);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001127 return -ENODEV;
1128 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001129
Dhananjay Phadke11d89d62008-08-08 00:08:45 -07001130 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
1131 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
1132 "will not be enabled.\n",
1133 NX_P3_A0, NX_P3_B1);
1134 return -ENODEV;
1135 }
1136
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001137 if ((err = pci_enable_device(pdev)))
1138 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001139
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001140 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1141 err = -ENODEV;
1142 goto err_out_disable_pdev;
1143 }
1144
1145 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
1146 goto err_out_disable_pdev;
1147
1148 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001149
1150 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
1151 if(!netdev) {
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001152 dev_err(&pdev->dev, "failed to allocate net_device\n");
1153 err = -ENOMEM;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001154 goto err_out_free_res;
1155 }
1156
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001157 SET_NETDEV_DEV(netdev, &pdev->dev);
1158
Wang Chen4cf16532008-11-12 23:38:14 -08001159 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001160 adapter->netdev = netdev;
1161 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001162 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001163
1164 revision_id = pdev->revision;
1165 adapter->ahw.revision_id = revision_id;
1166
Dhananjay Phadke50c643e2009-08-01 21:36:16 +00001167 err = nx_set_dma_mask(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001168 if (err)
1169 goto err_out_free_netdev;
1170
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001171 rwlock_init(&adapter->adapter_lock);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001172 spin_lock_init(&adapter->tx_clean_lock);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +00001173 INIT_LIST_HEAD(&adapter->mac_list);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001174
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001175 err = netxen_setup_pci_map(adapter);
1176 if (err)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001177 goto err_out_free_netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001178
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +05301179 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001180 adapter->portnum = pci_func_id;
1181
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001182 err = netxen_nic_get_board_info(adapter);
1183 if (err) {
1184 dev_err(&pdev->dev, "Error getting board config info.\n");
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001185 goto err_out_iounmap;
1186 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001187
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001188 netxen_initialize_adapter_ops(adapter);
1189
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001190 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001191 switch (adapter->ahw.board_type) {
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001192 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1193 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1194 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001195 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001196 break;
1197 default:
1198 break;
1199 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001200
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001201 err = netxen_start_firmware(adapter, 1);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001202 if (err)
1203 goto err_out_iounmap;
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001204
Dhananjay Phadke29566402008-07-21 19:44:04 -07001205 /*
1206 * See if the firmware gave us a virtual-physical port mapping.
1207 */
1208 adapter->physical_port = adapter->portnum;
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001209 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001210 i = NXRD32(adapter, CRB_V2P(adapter->portnum));
Dhananjay Phadke044fad02009-02-24 03:42:59 -08001211 if (i != 0x55555555)
1212 adapter->physical_port = i;
1213 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001214
Dhananjay Phadke438627c2009-03-13 14:52:03 +00001215 netxen_check_options(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001216
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001217 netxen_setup_intr(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001218
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001219 err = netxen_setup_netdev(adapter, netdev);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001220 if (err)
Dhananjay Phadke29566402008-07-21 19:44:04 -07001221 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001222
1223 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001224
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001225 switch (adapter->ahw.port_type) {
Dhananjay Phadke29566402008-07-21 19:44:04 -07001226 case NETXEN_NIC_GBE:
1227 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1228 adapter->netdev->name);
1229 break;
1230 case NETXEN_NIC_XGBE:
1231 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1232 adapter->netdev->name);
1233 break;
1234 }
1235
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001236 return 0;
1237
Dhananjay Phadke29566402008-07-21 19:44:04 -07001238err_out_disable_msi:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001239 netxen_teardown_intr(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001240
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001241 netxen_free_dummy_dma(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001242
Dhananjay Phadke29566402008-07-21 19:44:04 -07001243err_out_iounmap:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001244 netxen_cleanup_pci_map(adapter);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001245
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001246err_out_free_netdev:
1247 free_netdev(netdev);
1248
1249err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001250 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001251
1252err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001253 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001254 pci_disable_device(pdev);
1255 return err;
1256}
1257
1258static void __devexit netxen_nic_remove(struct pci_dev *pdev)
1259{
1260 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001261 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001262
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001263 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001264 if (adapter == NULL)
1265 return;
1266
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001267 netdev = adapter->netdev;
1268
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301269 unregister_netdev(netdev);
1270
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001271 cancel_work_sync(&adapter->watchdog_task);
1272 cancel_work_sync(&adapter->tx_timeout_task);
1273
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001274 netxen_nic_detach(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001275
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001276 if (adapter->portnum == 0)
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001277 netxen_free_dummy_dma(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301278
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001279 netxen_teardown_intr(adapter);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301280
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001281 netxen_cleanup_pci_map(adapter);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001282
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001283 netxen_release_firmware(adapter);
1284
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001285 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301286 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001287 pci_set_drvdata(pdev, NULL);
1288
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001289 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001290}
1291
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00001292#ifdef CONFIG_PM
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001293static int
1294netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
1295{
1296
1297 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1298 struct net_device *netdev = adapter->netdev;
1299
1300 netif_device_detach(netdev);
1301
1302 if (netif_running(netdev))
1303 netxen_nic_down(adapter, netdev);
1304
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001305 cancel_work_sync(&adapter->watchdog_task);
1306 cancel_work_sync(&adapter->tx_timeout_task);
1307
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001308 netxen_nic_detach(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001309
1310 pci_save_state(pdev);
1311
1312 if (netxen_nic_wol_supported(adapter)) {
1313 pci_enable_wake(pdev, PCI_D3cold, 1);
1314 pci_enable_wake(pdev, PCI_D3hot, 1);
1315 }
1316
1317 pci_disable_device(pdev);
1318 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1319
1320 return 0;
1321}
1322
1323static int
1324netxen_nic_resume(struct pci_dev *pdev)
1325{
1326 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1327 struct net_device *netdev = adapter->netdev;
1328 int err;
1329
1330 pci_set_power_state(pdev, PCI_D0);
1331 pci_restore_state(pdev);
1332
1333 err = pci_enable_device(pdev);
1334 if (err)
1335 return err;
1336
1337 adapter->curr_window = 255;
1338
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001339 err = netxen_start_firmware(adapter, 0);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001340 if (err) {
1341 dev_err(&pdev->dev, "failed to start firmware\n");
1342 return err;
1343 }
1344
1345 if (netif_running(netdev)) {
1346 err = netxen_nic_attach(adapter);
1347 if (err)
1348 return err;
1349
1350 err = netxen_nic_up(adapter, netdev);
1351 if (err)
1352 return err;
1353
1354 netif_device_attach(netdev);
1355 }
1356
1357 return 0;
1358}
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00001359#endif
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001360
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001361static int netxen_nic_open(struct net_device *netdev)
1362{
Wang Chen4cf16532008-11-12 23:38:14 -08001363 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001364 int err = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001365
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001366 if (adapter->driver_mismatch)
1367 return -EIO;
1368
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001369 err = netxen_nic_attach(adapter);
1370 if (err)
1371 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001372
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001373 err = netxen_nic_up(adapter, netdev);
1374 if (err)
1375 goto err_out;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001376
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001377 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001378
1379 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001380
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001381err_out:
1382 netxen_nic_detach(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001383 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001384}
1385
1386/*
1387 * netxen_nic_close - Disables a network interface entry point
1388 */
1389static int netxen_nic_close(struct net_device *netdev)
1390{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001391 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001392
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001393 netxen_nic_down(adapter, netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001394 return 0;
1395}
1396
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001397static void
1398netxen_tso_check(struct net_device *netdev,
1399 struct nx_host_tx_ring *tx_ring,
1400 struct cmd_desc_type0 *first_desc,
1401 struct sk_buff *skb)
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001402{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001403 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001404 __be16 protocol = skb->protocol;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001405 u16 flags = 0, vid = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001406 u32 producer;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001407 int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001408 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001409 struct vlan_ethhdr *vh;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001410
Harvey Harrison09640e62009-02-01 00:45:17 -08001411 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001412
1413 vh = (struct vlan_ethhdr *)skb->data;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001414 protocol = vh->h_vlan_encapsulated_proto;
1415 flags = FLAGS_VLAN_TAGGED;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001416
1417 } else if (vlan_tx_tag_present(skb)) {
1418
1419 flags = FLAGS_VLAN_OOB;
1420 vid = vlan_tx_tag_get(skb);
1421 netxen_set_tx_vlan_tci(first_desc, vid);
1422 vlan_oob = 1;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001423 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001424
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001425 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1426 skb_shinfo(skb)->gso_size > 0) {
1427
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001428 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1429
1430 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1431 first_desc->total_hdr_length = hdr_len;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001432 if (vlan_oob) {
1433 first_desc->total_hdr_length += VLAN_HLEN;
1434 first_desc->tcp_hdr_offset = VLAN_HLEN;
1435 first_desc->ip_hdr_offset = VLAN_HLEN;
1436 /* Only in case of TSO on vlan device */
1437 flags |= FLAGS_VLAN_TAGGED;
1438 }
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001439
Harvey Harrison09640e62009-02-01 00:45:17 -08001440 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001441 TX_TCP_LSO6 : TX_TCP_LSO;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001442 tso = 1;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001443
1444 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001445 u8 l4proto;
1446
Harvey Harrison09640e62009-02-01 00:45:17 -08001447 if (protocol == cpu_to_be16(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001448 l4proto = ip_hdr(skb)->protocol;
1449
1450 if (l4proto == IPPROTO_TCP)
1451 opcode = TX_TCP_PKT;
1452 else if(l4proto == IPPROTO_UDP)
1453 opcode = TX_UDP_PKT;
Harvey Harrison09640e62009-02-01 00:45:17 -08001454 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001455 l4proto = ipv6_hdr(skb)->nexthdr;
1456
1457 if (l4proto == IPPROTO_TCP)
1458 opcode = TX_TCPV6_PKT;
1459 else if(l4proto == IPPROTO_UDP)
1460 opcode = TX_UDPV6_PKT;
1461 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001462 }
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001463
1464 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
1465 first_desc->ip_hdr_offset += skb_network_offset(skb);
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001466 netxen_set_tx_flags_opcode(first_desc, flags, opcode);
1467
1468 if (!tso)
1469 return;
1470
1471 /* For LSO, we need to copy the MAC/IP/TCP headers into
1472 * the descriptor ring
1473 */
1474 producer = tx_ring->producer;
1475 copied = 0;
1476 offset = 2;
1477
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001478 if (vlan_oob) {
1479 /* Create a TSO vlan header template for firmware */
1480
1481 hwdesc = &tx_ring->desc_head[producer];
1482 tx_ring->cmd_buf_arr[producer].skb = NULL;
1483
1484 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1485 hdr_len + VLAN_HLEN);
1486
1487 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2);
1488 skb_copy_from_linear_data(skb, vh, 12);
1489 vh->h_vlan_proto = htons(ETH_P_8021Q);
1490 vh->h_vlan_TCI = htons(vid);
1491 skb_copy_from_linear_data_offset(skb, 12,
1492 (char *)vh + 16, copy_len - 16);
1493
Dhananjay Phadke545eb372009-08-05 07:34:07 +00001494 copied = copy_len - VLAN_HLEN;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001495 offset = 0;
1496
1497 producer = get_next_index(producer, tx_ring->num_desc);
1498 }
1499
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001500 while (copied < hdr_len) {
1501
1502 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1503 (hdr_len - copied));
1504
1505 hwdesc = &tx_ring->desc_head[producer];
1506 tx_ring->cmd_buf_arr[producer].skb = NULL;
1507
1508 skb_copy_from_linear_data_offset(skb, copied,
1509 (char *)hwdesc + offset, copy_len);
1510
1511 copied += copy_len;
1512 offset = 0;
1513
1514 producer = get_next_index(producer, tx_ring->num_desc);
1515 }
1516
1517 tx_ring->producer = producer;
1518 barrier();
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001519}
1520
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001521static void
1522netxen_clean_tx_dma_mapping(struct pci_dev *pdev,
1523 struct netxen_cmd_buffer *pbuf, int last)
1524{
1525 int k;
1526 struct netxen_skb_frag *buffrag;
1527
1528 buffrag = &pbuf->frag_array[0];
1529 pci_unmap_single(pdev, buffrag->dma,
1530 buffrag->length, PCI_DMA_TODEVICE);
1531
1532 for (k = 1; k < last; k++) {
1533 buffrag = &pbuf->frag_array[k];
1534 pci_unmap_page(pdev, buffrag->dma,
1535 buffrag->length, PCI_DMA_TODEVICE);
1536 }
1537}
1538
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001539static inline void
1540netxen_clear_cmddesc(u64 *desc)
1541{
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001542 desc[0] = 0ULL;
1543 desc[2] = 0ULL;
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001544}
1545
1546static int
1547netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001548{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001549 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001550 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001551 struct skb_frag_struct *frag;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001552 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001553 struct netxen_skb_frag *buffrag;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001554 struct cmd_desc_type0 *hwdesc, *first_desc;
1555 struct pci_dev *pdev;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001556 dma_addr_t temp_dma;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001557 int i, k;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001558 unsigned long offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001559
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001560 u32 producer;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001561 int len, frag_count, no_of_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001562 u32 num_txd = tx_ring->num_desc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001563
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001564 frag_count = skb_shinfo(skb)->nr_frags + 1;
1565
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001566 /* 4 fragments per cmd des */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001567 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001568
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001569 if (unlikely(no_of_desc + 2) > netxen_tx_avail(tx_ring)) {
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001570 netif_stop_queue(netdev);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001571 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001572 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001573
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001574 producer = tx_ring->producer;
1575
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001576 pdev = adapter->pdev;
1577 len = skb->len - skb->data_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001578
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001579 temp_dma = pci_map_single(pdev, skb->data, len, PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001580 if (pci_dma_mapping_error(pdev, temp_dma))
1581 goto drop_packet;
1582
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001583 pbuf = &tx_ring->cmd_buf_arr[producer];
1584 pbuf->skb = skb;
1585 pbuf->frag_count = frag_count;
1586
1587 buffrag = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001588 buffrag->dma = temp_dma;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001589 buffrag->length = len;
1590
1591 first_desc = hwdesc = &tx_ring->desc_head[producer];
1592 netxen_clear_cmddesc((u64 *)hwdesc);
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001593 netxen_set_tx_frags_len(hwdesc, frag_count, skb->len);
1594 netxen_set_tx_port(hwdesc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001595
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001596 hwdesc->buffer_length[0] = cpu_to_le16(len);
1597 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001598
1599 for (i = 1, k = 1; i < frag_count; i++, k++) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001600
1601 /* move to next desc. if there is a need */
1602 if ((i & 0x3) == 0) {
1603 k = 0;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001604 producer = get_next_index(producer, num_txd);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001605 hwdesc = &tx_ring->desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001606 netxen_clear_cmddesc((u64 *)hwdesc);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001607 pbuf = &tx_ring->cmd_buf_arr[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001608 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001609 }
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001610 buffrag = &pbuf->frag_array[i];
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001611 frag = &skb_shinfo(skb)->frags[i - 1];
1612 len = frag->size;
1613 offset = frag->page_offset;
1614
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001615 temp_dma = pci_map_page(pdev, frag->page, offset,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001616 len, PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001617 if (pci_dma_mapping_error(pdev, temp_dma)) {
1618 netxen_clean_tx_dma_mapping(pdev, pbuf, i);
1619 goto drop_packet;
1620 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001621
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001622 buffrag->dma = temp_dma;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001623 buffrag->length = len;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001624
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001625 hwdesc->buffer_length[k] = cpu_to_le16(len);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001626 switch (k) {
1627 case 0:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001628 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
1629 break;
1630 case 1:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001631 hwdesc->addr_buffer2 = cpu_to_le64(temp_dma);
1632 break;
1633 case 2:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001634 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
1635 break;
1636 case 3:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001637 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
1638 break;
1639 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001640 }
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001641 tx_ring->producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001642
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001643 netxen_tso_check(netdev, tx_ring, first_desc, skb);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001644
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001645 netxen_nic_update_cmd_producer(adapter, tx_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001646
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001647 adapter->stats.txbytes += skb->len;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001648 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001649
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001650 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001651
1652drop_packet:
1653 adapter->stats.txdropped++;
1654 dev_kfree_skb_any(skb);
1655 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001656}
1657
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001658static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1659{
1660 struct net_device *netdev = adapter->netdev;
1661 uint32_t temp, temp_state, temp_val;
1662 int rv = 0;
1663
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001664 temp = NXRD32(adapter, CRB_TEMP_STATE);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001665
1666 temp_state = nx_get_temp_state(temp);
1667 temp_val = nx_get_temp_val(temp);
1668
1669 if (temp_state == NX_TEMP_PANIC) {
1670 printk(KERN_ALERT
1671 "%s: Device temperature %d degrees C exceeds"
1672 " maximum allowed. Hardware has been shut down.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001673 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001674 rv = 1;
1675 } else if (temp_state == NX_TEMP_WARN) {
1676 if (adapter->temp == NX_TEMP_NORMAL) {
1677 printk(KERN_ALERT
1678 "%s: Device temperature %d degrees C "
1679 "exceeds operating range."
1680 " Immediate action needed.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001681 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001682 }
1683 } else {
1684 if (adapter->temp == NX_TEMP_WARN) {
1685 printk(KERN_INFO
1686 "%s: Device temperature is now %d degrees C"
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001687 " in normal range.\n", netdev->name,
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001688 temp_val);
1689 }
1690 }
1691 adapter->temp = temp_state;
1692 return rv;
1693}
1694
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001695void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup)
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001696{
1697 struct net_device *netdev = adapter->netdev;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001698
1699 if (adapter->ahw.linkup && !linkup) {
1700 printk(KERN_INFO "%s: %s NIC Link is down\n",
1701 netxen_nic_driver_name, netdev->name);
1702 adapter->ahw.linkup = 0;
1703 if (netif_running(netdev)) {
1704 netif_carrier_off(netdev);
1705 netif_stop_queue(netdev);
1706 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001707 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001708 } else if (!adapter->ahw.linkup && linkup) {
1709 printk(KERN_INFO "%s: %s NIC Link is up\n",
1710 netxen_nic_driver_name, netdev->name);
1711 adapter->ahw.linkup = 1;
1712 if (netif_running(netdev)) {
1713 netif_carrier_on(netdev);
1714 netif_wake_queue(netdev);
1715 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001716 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001717 }
1718}
1719
1720static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1721{
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001722 u32 val, port, linkup;
1723
1724 port = adapter->physical_port;
1725
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001726 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001727 val = NXRD32(adapter, CRB_XG_STATE_P3);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001728 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1729 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001730 } else {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001731 val = NXRD32(adapter, CRB_XG_STATE);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001732 if (adapter->ahw.port_type == NETXEN_NIC_GBE)
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001733 linkup = (val >> port) & 1;
1734 else {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001735 val = (val >> port*8) & 0xff;
1736 linkup = (val == XG_LINK_UP);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001737 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001738 }
1739
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001740 netxen_advert_link_change(adapter, linkup);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001741}
1742
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001743static void netxen_nic_thermal_shutdown(struct netxen_adapter *adapter)
1744{
1745 struct net_device *netdev = adapter->netdev;
1746
1747 netif_device_detach(netdev);
1748 netxen_nic_down(adapter, netdev);
1749 netxen_nic_detach(adapter);
1750}
1751
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001752static void netxen_watchdog(unsigned long v)
1753{
1754 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001755
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001756 if (netxen_nic_check_temp(adapter))
1757 goto do_sched;
1758
1759 if (!adapter->has_link_events) {
1760 netxen_nic_handle_phy_intr(adapter);
1761
1762 if (adapter->link_changed)
1763 goto do_sched;
1764 }
1765
1766 if (netif_running(adapter->netdev))
1767 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1768
1769 return;
1770
1771do_sched:
1772 schedule_work(&adapter->watchdog_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001773}
1774
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001775void netxen_watchdog_task(struct work_struct *work)
1776{
1777 struct netxen_adapter *adapter =
1778 container_of(work, struct netxen_adapter, watchdog_task);
1779
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001780 if (adapter->temp == NX_TEMP_PANIC) {
1781 netxen_nic_thermal_shutdown(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001782 return;
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001783 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001784
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001785 if (adapter->link_changed)
1786 netxen_nic_set_link_parameters(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001787
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001788 if (netif_running(adapter->netdev))
1789 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001790}
1791
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001792static void netxen_tx_timeout(struct net_device *netdev)
1793{
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001794 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001795
1796 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001797 schedule_work(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001798}
1799
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001800static void netxen_reset_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001801{
Jeff Garzik47906542007-11-23 21:23:36 -05001802 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001803 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001804
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001805 if (!netif_running(adapter->netdev))
1806 return;
1807
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001808 netxen_napi_disable(adapter);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001809
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001810 adapter->netdev->trans_start = jiffies;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001811
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001812 netxen_napi_enable(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001813 netif_wake_queue(adapter->netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001814}
1815
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001816struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1817{
1818 struct netxen_adapter *adapter = netdev_priv(netdev);
1819 struct net_device_stats *stats = &adapter->net_stats;
1820
1821 memset(stats, 0, sizeof(*stats));
1822
Narender Kumar1bb482f2009-08-23 08:35:09 +00001823 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00001824 stats->tx_packets = adapter->stats.xmitfinished;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001825 stats->rx_bytes = adapter->stats.rxbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001826 stats->tx_bytes = adapter->stats.txbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001827 stats->rx_dropped = adapter->stats.rxdropped;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001828 stats->tx_dropped = adapter->stats.txdropped;
1829
1830 return stats;
1831}
1832
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001833static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001834{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001835 struct nx_host_sds_ring *sds_ring = data;
1836 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001837 u32 status = 0;
1838
1839 status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1840
1841 if (!(status & adapter->legacy_intr.int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001842 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301843
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001844 if (adapter->ahw.revision_id >= NX_P3_B1) {
1845 /* check interrupt state machine, to be sure */
1846 status = adapter->pci_read_immediate(adapter,
1847 ISR_INT_STATE_REG);
1848 if (!ISR_LEGACY_INT_TRIGGERED(status))
1849 return IRQ_NONE;
1850
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001851 } else {
1852 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001853
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001854 our_int = NXRD32(adapter, CRB_INT_VECTOR);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001855
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001856 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001857 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001858 return IRQ_NONE;
1859
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001860 /* claim interrupt */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001861 NXWR32(adapter, CRB_INT_VECTOR, (our_int & 0xffffffff));
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301862 }
1863
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001864 /* clear interrupt */
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001865 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001866 netxen_nic_disable_int(sds_ring);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001867
1868 adapter->pci_write_immediate(adapter,
1869 adapter->legacy_intr.tgt_status_reg,
1870 0xffffffff);
1871 /* read twice to ensure write is flushed */
1872 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1873 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1874
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001875 napi_schedule(&sds_ring->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001876
1877 return IRQ_HANDLED;
1878}
1879
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001880static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001881{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001882 struct nx_host_sds_ring *sds_ring = data;
1883 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001884
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001885 /* clear interrupt */
1886 adapter->pci_write_immediate(adapter,
Dhananjay Phadke7a2469c2009-05-08 22:02:27 +00001887 adapter->msi_tgt_status, 0xffffffff);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001888
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001889 napi_schedule(&sds_ring->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001890 return IRQ_HANDLED;
1891}
1892
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001893static irqreturn_t netxen_msix_intr(int irq, void *data)
1894{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001895 struct nx_host_sds_ring *sds_ring = data;
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001896
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001897 napi_schedule(&sds_ring->napi);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001898 return IRQ_HANDLED;
1899}
1900
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001901static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001902{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001903 struct nx_host_sds_ring *sds_ring =
1904 container_of(napi, struct nx_host_sds_ring, napi);
1905
1906 struct netxen_adapter *adapter = sds_ring->adapter;
1907
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001908 int tx_complete;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001909 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001910
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001911 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001912
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001913 work_done = netxen_process_rcv_ring(sds_ring, budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001914
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001915 if ((work_done < budget) && tx_complete) {
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001916 napi_complete(&sds_ring->napi);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001917 if (netif_running(adapter->netdev))
1918 netxen_nic_enable_int(sds_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001919 }
1920
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001921 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001922}
1923
1924#ifdef CONFIG_NET_POLL_CONTROLLER
1925static void netxen_nic_poll_controller(struct net_device *netdev)
1926{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001927 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001928 disable_irq(adapter->irq);
Jeff Garzik1494a812006-11-07 05:12:16 -05001929 netxen_intr(adapter->irq, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001930 enable_irq(adapter->irq);
1931}
1932#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001933
Dhananjay Phadke044824d2009-07-28 09:10:03 +00001934#ifdef CONFIG_INET
1935
Dhananjay Phadke6598b162009-07-26 20:07:37 +00001936#define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
1937
1938static int
1939netxen_destip_supported(struct netxen_adapter *adapter)
1940{
1941 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
1942 return 0;
1943
1944 if (adapter->ahw.cut_through)
1945 return 0;
1946
1947 return 1;
1948}
1949
1950static int netxen_netdev_event(struct notifier_block *this,
1951 unsigned long event, void *ptr)
1952{
1953 struct netxen_adapter *adapter;
1954 struct net_device *dev = (struct net_device *)ptr;
1955 struct in_device *indev;
1956
1957recheck:
1958 if (dev == NULL)
1959 goto done;
1960
1961 if (dev->priv_flags & IFF_802_1Q_VLAN) {
1962 dev = vlan_dev_real_dev(dev);
1963 goto recheck;
1964 }
1965
1966 if (!is_netxen_netdev(dev))
1967 goto done;
1968
1969 adapter = netdev_priv(dev);
1970
1971 if (!adapter || !netxen_destip_supported(adapter))
1972 goto done;
1973
1974 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1975 goto done;
1976
1977 indev = in_dev_get(dev);
1978 if (!indev)
1979 goto done;
1980
1981 for_ifa(indev) {
1982 switch (event) {
1983 case NETDEV_UP:
1984 netxen_config_ipaddr(adapter,
1985 ifa->ifa_address, NX_IP_UP);
1986 break;
1987 case NETDEV_DOWN:
1988 netxen_config_ipaddr(adapter,
1989 ifa->ifa_address, NX_IP_DOWN);
1990 break;
1991 default:
1992 break;
1993 }
1994 } endfor_ifa(indev);
1995
1996 in_dev_put(indev);
1997done:
1998 return NOTIFY_DONE;
1999}
2000
2001static int
2002netxen_inetaddr_event(struct notifier_block *this,
2003 unsigned long event, void *ptr)
2004{
2005 struct netxen_adapter *adapter;
2006 struct net_device *dev;
2007
2008 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
2009
2010 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
2011
2012recheck:
2013 if (dev == NULL || !netif_running(dev))
2014 goto done;
2015
2016 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2017 dev = vlan_dev_real_dev(dev);
2018 goto recheck;
2019 }
2020
2021 if (!is_netxen_netdev(dev))
2022 goto done;
2023
2024 adapter = netdev_priv(dev);
2025
2026 if (!adapter || !netxen_destip_supported(adapter))
2027 goto done;
2028
2029 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2030 goto done;
2031
2032 switch (event) {
2033 case NETDEV_UP:
2034 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP);
2035 break;
2036 case NETDEV_DOWN:
2037 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN);
2038 break;
2039 default:
2040 break;
2041 }
2042
2043done:
2044 return NOTIFY_DONE;
2045}
2046
2047static struct notifier_block netxen_netdev_cb = {
2048 .notifier_call = netxen_netdev_event,
2049};
2050
2051static struct notifier_block netxen_inetaddr_cb = {
2052 .notifier_call = netxen_inetaddr_event,
2053};
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002054#endif
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002055
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002056static struct pci_driver netxen_driver = {
2057 .name = netxen_nic_driver_name,
2058 .id_table = netxen_pci_tbl,
2059 .probe = netxen_nic_probe,
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002060 .remove = __devexit_p(netxen_nic_remove),
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002061#ifdef CONFIG_PM
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002062 .suspend = netxen_nic_suspend,
2063 .resume = netxen_nic_resume
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002064#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002065};
2066
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002067static int __init netxen_init_module(void)
2068{
Dhananjay Phadkeff4fbd42009-03-13 14:52:06 +00002069 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
2070
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002071#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002072 register_netdevice_notifier(&netxen_netdev_cb);
2073 register_inetaddr_notifier(&netxen_inetaddr_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002074#endif
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002075
Amit S. Kale184231b2007-01-22 06:52:53 -08002076 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002077}
2078
2079module_init(netxen_init_module);
2080
2081static void __exit netxen_exit_module(void)
2082{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002083 pci_unregister_driver(&netxen_driver);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002084
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002085#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002086 unregister_inetaddr_notifier(&netxen_inetaddr_cb);
2087 unregister_netdevice_notifier(&netxen_netdev_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002088#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002089}
2090
2091module_exit(netxen_exit_module);