blob: de67e42a29712aae4eb4ce9ec132afe21325600e [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);
757 if (err <= 0)
758 return err;
759
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800760 if (first_boot != 0x55555555) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000761 NXWR32(adapter, CRB_CMDPEG_STATE, 0);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800762 netxen_pinit_from_rom(adapter, 0);
763 msleep(1);
764 }
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000765
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000766 NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555);
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000767 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
768 netxen_set_port_mode(adapter);
769
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800770 netxen_load_firmware(adapter);
771
772 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
773
774 /* Initialize multicast addr pool owners */
775 val = 0x7654;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000776 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800777 val |= 0x0f000000;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000778 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800779
780 }
781
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000782 err = netxen_init_dummy_dma(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800783 if (err)
784 return err;
785
786 /*
787 * Tell the hardware our version number.
788 */
789 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
790 | ((_NETXEN_NIC_LINUX_MINOR << 8))
791 | (_NETXEN_NIC_LINUX_SUBVERSION);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000792 NXWR32(adapter, CRB_DRIVER_VERSION, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800793
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000794wait_init:
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800795 /* Handshake with the card before we register the devices. */
796 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
797 if (err) {
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000798 netxen_free_dummy_dma(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800799 return err;
800 }
801
Dhananjay Phadke68b3cae2009-07-26 20:07:36 +0000802 nx_update_dma_mask(adapter);
803
804 netxen_nic_get_firmware_info(adapter);
805
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800806 return 0;
807}
808
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000809static int
810netxen_nic_request_irq(struct netxen_adapter *adapter)
811{
812 irq_handler_t handler;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000813 struct nx_host_sds_ring *sds_ring;
814 int err, ring;
815
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000816 unsigned long flags = IRQF_SAMPLE_RANDOM;
817 struct net_device *netdev = adapter->netdev;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000818 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000819
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000820 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
821 handler = netxen_msix_intr;
822 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
823 handler = netxen_msi_intr;
824 else {
825 flags |= IRQF_SHARED;
826 handler = netxen_intr;
827 }
828 adapter->irq = netdev->irq;
829
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000830 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
831 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000832 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000833 err = request_irq(sds_ring->irq, handler,
834 flags, sds_ring->name, sds_ring);
835 if (err)
836 return err;
837 }
838
839 return 0;
840}
841
842static void
843netxen_nic_free_irq(struct netxen_adapter *adapter)
844{
845 int ring;
846 struct nx_host_sds_ring *sds_ring;
847
848 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
849
850 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
851 sds_ring = &recv_ctx->sds_rings[ring];
852 free_irq(sds_ring->irq, sds_ring);
853 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000854}
855
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000856static void
857netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter)
858{
859 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
860 adapter->coal.normal.data.rx_time_us =
861 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
862 adapter->coal.normal.data.rx_packets =
863 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
864 adapter->coal.normal.data.tx_time_us =
865 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US;
866 adapter->coal.normal.data.tx_packets =
867 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS;
868}
869
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000870static int
871netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
872{
873 int err;
874
875 err = adapter->init_port(adapter, adapter->physical_port);
876 if (err) {
877 printk(KERN_ERR "%s: Failed to initialize port %d\n",
878 netxen_nic_driver_name, adapter->portnum);
879 return err;
880 }
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000881 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
882 adapter->macaddr_set(adapter, netdev->dev_addr);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000883
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000884 adapter->set_multi(netdev);
885 adapter->set_mtu(adapter, netdev->mtu);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000886
887 adapter->ahw.linkup = 0;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000888
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000889 if (adapter->max_sds_rings > 1)
890 netxen_config_rss(adapter, 1);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000891
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000892 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
893 netxen_config_intr_coalesce(adapter);
894
Narender Kumar1bb482f2009-08-23 08:35:09 +0000895 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
896 netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED);
897
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000898 netxen_napi_enable(adapter);
899
Dhananjay Phadke5103c9f2009-04-28 15:29:09 +0000900 if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000901 netxen_linkevent_request(adapter, 1);
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000902 else
903 netxen_nic_set_link_parameters(adapter);
904
905 mod_timer(&adapter->watchdog_timer, jiffies);
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000906
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000907 return 0;
908}
909
910static void
911netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
912{
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000913 spin_lock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000914 netif_carrier_off(netdev);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000915 netif_tx_disable(netdev);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000916
917 if (adapter->stop_port)
918 adapter->stop_port(adapter);
919
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +0000920 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
921 netxen_p3_free_mac_list(adapter);
922
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000923 netxen_napi_disable(adapter);
924
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000925 netxen_release_tx_buffers(adapter);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000926 spin_unlock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000927
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000928 del_timer_sync(&adapter->watchdog_timer);
929}
930
931
932static int
933netxen_nic_attach(struct netxen_adapter *adapter)
934{
935 struct net_device *netdev = adapter->netdev;
936 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000937 int err, ring;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000938 struct nx_host_rds_ring *rds_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000939 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000940
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -0700941 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
942 return 0;
943
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000944 err = netxen_init_firmware(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000945 if (err)
946 return err;
947
948 err = netxen_napi_add(adapter, netdev);
949 if (err)
950 return err;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000951
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000952 err = netxen_alloc_sw_resources(adapter);
953 if (err) {
954 printk(KERN_ERR "%s: Error in setting sw resources\n",
955 netdev->name);
956 return err;
957 }
958
959 netxen_nic_clear_stats(adapter);
960
961 err = netxen_alloc_hw_resources(adapter);
962 if (err) {
963 printk(KERN_ERR "%s: Error in setting hw resources\n",
964 netdev->name);
965 goto err_out_free_sw;
966 }
967
Dhananjay Phadke4f96b982009-07-26 20:07:42 +0000968 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000969 tx_ring = adapter->tx_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000970 tx_ring->crb_cmd_producer = crb_cmd_producer[adapter->portnum];
971 tx_ring->crb_cmd_consumer = crb_cmd_consumer[adapter->portnum];
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000972
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000973 tx_ring->producer = 0;
974 tx_ring->sw_consumer = 0;
975
976 netxen_nic_update_cmd_producer(adapter, tx_ring);
977 netxen_nic_update_cmd_consumer(adapter, tx_ring);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000978 }
979
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000980 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
981 rds_ring = &adapter->recv_ctx.rds_rings[ring];
982 netxen_post_rx_buffers(adapter, ring, rds_ring);
983 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000984
985 err = netxen_nic_request_irq(adapter);
986 if (err) {
987 dev_err(&pdev->dev, "%s: failed to setup interrupt\n",
988 netdev->name);
989 goto err_out_free_rxbuf;
990 }
991
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000992 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
993 netxen_nic_init_coalesce_defaults(adapter);
994
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000995 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
996 return 0;
997
998err_out_free_rxbuf:
999 netxen_release_rx_buffers(adapter);
1000 netxen_free_hw_resources(adapter);
1001err_out_free_sw:
1002 netxen_free_sw_resources(adapter);
1003 return err;
1004}
1005
1006static void
1007netxen_nic_detach(struct netxen_adapter *adapter)
1008{
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001009 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1010 return;
1011
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001012 netxen_free_hw_resources(adapter);
Dhananjay Phadkecf981ff2009-07-17 15:27:06 +00001013 netxen_release_rx_buffers(adapter);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +00001014 netxen_nic_free_irq(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +00001015 netxen_napi_del(adapter);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001016 netxen_free_sw_resources(adapter);
1017
1018 adapter->is_up = 0;
1019}
1020
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001021int
1022netxen_nic_reset_context(struct netxen_adapter *adapter)
1023{
1024 int err = 0;
1025 struct net_device *netdev = adapter->netdev;
1026
1027 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
1028
1029 if (netif_running(netdev))
1030 netxen_nic_down(adapter, netdev);
1031
1032 netxen_nic_detach(adapter);
1033
1034 err = netxen_nic_attach(adapter);
1035 if (err)
1036 goto done;
1037
1038 if (netif_running(netdev))
1039 err = netxen_nic_up(adapter, netdev);
1040 }
1041done:
1042 return err;
1043}
1044
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001045static int
1046netxen_setup_netdev(struct netxen_adapter *adapter,
1047 struct net_device *netdev)
1048{
1049 int err = 0;
1050 struct pci_dev *pdev = adapter->pdev;
1051
1052 adapter->rx_csum = 1;
1053 adapter->mc_enabled = 0;
1054 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1055 adapter->max_mc_count = 38;
1056 else
1057 adapter->max_mc_count = 16;
1058
1059 netdev->netdev_ops = &netxen_netdev_ops;
1060 netdev->watchdog_timeo = 2*HZ;
1061
1062 netxen_nic_change_mtu(netdev, netdev->mtu);
1063
1064 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
1065
1066 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1067 netdev->features |= (NETIF_F_GRO);
1068 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1069
1070 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1071 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1072 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1073 }
1074
1075 if (adapter->pci_using_dac) {
1076 netdev->features |= NETIF_F_HIGHDMA;
1077 netdev->vlan_features |= NETIF_F_HIGHDMA;
1078 }
1079
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001080 if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX)
1081 netdev->features |= (NETIF_F_HW_VLAN_TX);
1082
Narender Kumar1bb482f2009-08-23 08:35:09 +00001083 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
1084 netdev->features |= NETIF_F_LRO;
1085
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001086 netdev->irq = adapter->msix_entries[0].vector;
1087
1088 err = netxen_napi_add(adapter, netdev);
1089 if (err)
1090 return err;
1091
1092 init_timer(&adapter->watchdog_timer);
1093 adapter->watchdog_timer.function = &netxen_watchdog;
1094 adapter->watchdog_timer.data = (unsigned long)adapter;
1095 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
1096 INIT_WORK(&adapter->tx_timeout_task, netxen_reset_task);
1097
1098 if (netxen_read_mac_addr(adapter))
1099 dev_warn(&pdev->dev, "failed to read mac addr\n");
1100
1101 netif_carrier_off(netdev);
1102 netif_stop_queue(netdev);
1103
1104 err = register_netdev(netdev);
1105 if (err) {
1106 dev_err(&pdev->dev, "failed to register net device\n");
1107 return err;
1108 }
1109
1110 return 0;
1111}
1112
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001113static int __devinit
1114netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1115{
1116 struct net_device *netdev = NULL;
1117 struct netxen_adapter *adapter = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001118 int i = 0, err;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001119 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001120 uint8_t revision_id;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001121
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001122 if (pdev->class != 0x020000) {
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001123 printk(KERN_DEBUG "NetXen function %d, class %x will not "
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001124 "be enabled.\n",pci_func_id, pdev->class);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001125 return -ENODEV;
1126 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001127
Dhananjay Phadke11d89d62008-08-08 00:08:45 -07001128 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
1129 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
1130 "will not be enabled.\n",
1131 NX_P3_A0, NX_P3_B1);
1132 return -ENODEV;
1133 }
1134
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001135 if ((err = pci_enable_device(pdev)))
1136 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001137
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001138 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1139 err = -ENODEV;
1140 goto err_out_disable_pdev;
1141 }
1142
1143 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
1144 goto err_out_disable_pdev;
1145
1146 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001147
1148 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
1149 if(!netdev) {
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001150 dev_err(&pdev->dev, "failed to allocate net_device\n");
1151 err = -ENOMEM;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001152 goto err_out_free_res;
1153 }
1154
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001155 SET_NETDEV_DEV(netdev, &pdev->dev);
1156
Wang Chen4cf16532008-11-12 23:38:14 -08001157 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001158 adapter->netdev = netdev;
1159 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001160 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001161
1162 revision_id = pdev->revision;
1163 adapter->ahw.revision_id = revision_id;
1164
Dhananjay Phadke50c643e2009-08-01 21:36:16 +00001165 err = nx_set_dma_mask(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001166 if (err)
1167 goto err_out_free_netdev;
1168
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001169 rwlock_init(&adapter->adapter_lock);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001170 spin_lock_init(&adapter->tx_clean_lock);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +00001171 INIT_LIST_HEAD(&adapter->mac_list);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001172
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001173 err = netxen_setup_pci_map(adapter);
1174 if (err)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001175 goto err_out_free_netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001176
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +05301177 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001178 adapter->portnum = pci_func_id;
1179
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001180 err = netxen_nic_get_board_info(adapter);
1181 if (err) {
1182 dev_err(&pdev->dev, "Error getting board config info.\n");
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001183 goto err_out_iounmap;
1184 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001185
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001186 netxen_initialize_adapter_ops(adapter);
1187
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001188 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001189 switch (adapter->ahw.board_type) {
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001190 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1191 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1192 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001193 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001194 break;
1195 default:
1196 break;
1197 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001198
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001199 err = netxen_start_firmware(adapter, 1);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001200 if (err)
1201 goto err_out_iounmap;
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001202
Dhananjay Phadke29566402008-07-21 19:44:04 -07001203 /*
1204 * See if the firmware gave us a virtual-physical port mapping.
1205 */
1206 adapter->physical_port = adapter->portnum;
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001207 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001208 i = NXRD32(adapter, CRB_V2P(adapter->portnum));
Dhananjay Phadke044fad02009-02-24 03:42:59 -08001209 if (i != 0x55555555)
1210 adapter->physical_port = i;
1211 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001212
Dhananjay Phadke438627c2009-03-13 14:52:03 +00001213 netxen_check_options(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001214
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001215 netxen_setup_intr(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001216
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001217 err = netxen_setup_netdev(adapter, netdev);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001218 if (err)
Dhananjay Phadke29566402008-07-21 19:44:04 -07001219 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001220
1221 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001222
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001223 switch (adapter->ahw.port_type) {
Dhananjay Phadke29566402008-07-21 19:44:04 -07001224 case NETXEN_NIC_GBE:
1225 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1226 adapter->netdev->name);
1227 break;
1228 case NETXEN_NIC_XGBE:
1229 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1230 adapter->netdev->name);
1231 break;
1232 }
1233
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001234 return 0;
1235
Dhananjay Phadke29566402008-07-21 19:44:04 -07001236err_out_disable_msi:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001237 netxen_teardown_intr(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001238
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001239 netxen_free_dummy_dma(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001240
Dhananjay Phadke29566402008-07-21 19:44:04 -07001241err_out_iounmap:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001242 netxen_cleanup_pci_map(adapter);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001243
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001244err_out_free_netdev:
1245 free_netdev(netdev);
1246
1247err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001248 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001249
1250err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001251 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001252 pci_disable_device(pdev);
1253 return err;
1254}
1255
1256static void __devexit netxen_nic_remove(struct pci_dev *pdev)
1257{
1258 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001259 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001260
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001261 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001262 if (adapter == NULL)
1263 return;
1264
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001265 netdev = adapter->netdev;
1266
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301267 unregister_netdev(netdev);
1268
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001269 cancel_work_sync(&adapter->watchdog_task);
1270 cancel_work_sync(&adapter->tx_timeout_task);
1271
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001272 netxen_nic_detach(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001273
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001274 if (adapter->portnum == 0)
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001275 netxen_free_dummy_dma(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301276
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001277 netxen_teardown_intr(adapter);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301278
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001279 netxen_cleanup_pci_map(adapter);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001280
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001281 netxen_release_firmware(adapter);
1282
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001283 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301284 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001285 pci_set_drvdata(pdev, NULL);
1286
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001287 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001288}
1289
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00001290#ifdef CONFIG_PM
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001291static int
1292netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
1293{
1294
1295 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1296 struct net_device *netdev = adapter->netdev;
1297
1298 netif_device_detach(netdev);
1299
1300 if (netif_running(netdev))
1301 netxen_nic_down(adapter, netdev);
1302
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001303 cancel_work_sync(&adapter->watchdog_task);
1304 cancel_work_sync(&adapter->tx_timeout_task);
1305
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001306 netxen_nic_detach(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001307
1308 pci_save_state(pdev);
1309
1310 if (netxen_nic_wol_supported(adapter)) {
1311 pci_enable_wake(pdev, PCI_D3cold, 1);
1312 pci_enable_wake(pdev, PCI_D3hot, 1);
1313 }
1314
1315 pci_disable_device(pdev);
1316 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1317
1318 return 0;
1319}
1320
1321static int
1322netxen_nic_resume(struct pci_dev *pdev)
1323{
1324 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1325 struct net_device *netdev = adapter->netdev;
1326 int err;
1327
1328 pci_set_power_state(pdev, PCI_D0);
1329 pci_restore_state(pdev);
1330
1331 err = pci_enable_device(pdev);
1332 if (err)
1333 return err;
1334
1335 adapter->curr_window = 255;
1336
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001337 err = netxen_start_firmware(adapter, 0);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001338 if (err) {
1339 dev_err(&pdev->dev, "failed to start firmware\n");
1340 return err;
1341 }
1342
1343 if (netif_running(netdev)) {
1344 err = netxen_nic_attach(adapter);
1345 if (err)
1346 return err;
1347
1348 err = netxen_nic_up(adapter, netdev);
1349 if (err)
1350 return err;
1351
1352 netif_device_attach(netdev);
1353 }
1354
1355 return 0;
1356}
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00001357#endif
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001358
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001359static int netxen_nic_open(struct net_device *netdev)
1360{
Wang Chen4cf16532008-11-12 23:38:14 -08001361 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001362 int err = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001363
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001364 if (adapter->driver_mismatch)
1365 return -EIO;
1366
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001367 err = netxen_nic_attach(adapter);
1368 if (err)
1369 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001370
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001371 err = netxen_nic_up(adapter, netdev);
1372 if (err)
1373 goto err_out;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001374
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001375 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001376
1377 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001378
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001379err_out:
1380 netxen_nic_detach(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001381 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001382}
1383
1384/*
1385 * netxen_nic_close - Disables a network interface entry point
1386 */
1387static int netxen_nic_close(struct net_device *netdev)
1388{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001389 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001390
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001391 netxen_nic_down(adapter, netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001392 return 0;
1393}
1394
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001395static void
1396netxen_tso_check(struct net_device *netdev,
1397 struct nx_host_tx_ring *tx_ring,
1398 struct cmd_desc_type0 *first_desc,
1399 struct sk_buff *skb)
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001400{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001401 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001402 __be16 protocol = skb->protocol;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001403 u16 flags = 0, vid = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001404 u32 producer;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001405 int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001406 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001407 struct vlan_ethhdr *vh;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001408
Harvey Harrison09640e62009-02-01 00:45:17 -08001409 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001410
1411 vh = (struct vlan_ethhdr *)skb->data;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001412 protocol = vh->h_vlan_encapsulated_proto;
1413 flags = FLAGS_VLAN_TAGGED;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001414
1415 } else if (vlan_tx_tag_present(skb)) {
1416
1417 flags = FLAGS_VLAN_OOB;
1418 vid = vlan_tx_tag_get(skb);
1419 netxen_set_tx_vlan_tci(first_desc, vid);
1420 vlan_oob = 1;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001421 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001422
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001423 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1424 skb_shinfo(skb)->gso_size > 0) {
1425
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001426 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1427
1428 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1429 first_desc->total_hdr_length = hdr_len;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001430 if (vlan_oob) {
1431 first_desc->total_hdr_length += VLAN_HLEN;
1432 first_desc->tcp_hdr_offset = VLAN_HLEN;
1433 first_desc->ip_hdr_offset = VLAN_HLEN;
1434 /* Only in case of TSO on vlan device */
1435 flags |= FLAGS_VLAN_TAGGED;
1436 }
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001437
Harvey Harrison09640e62009-02-01 00:45:17 -08001438 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001439 TX_TCP_LSO6 : TX_TCP_LSO;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001440 tso = 1;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001441
1442 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001443 u8 l4proto;
1444
Harvey Harrison09640e62009-02-01 00:45:17 -08001445 if (protocol == cpu_to_be16(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001446 l4proto = ip_hdr(skb)->protocol;
1447
1448 if (l4proto == IPPROTO_TCP)
1449 opcode = TX_TCP_PKT;
1450 else if(l4proto == IPPROTO_UDP)
1451 opcode = TX_UDP_PKT;
Harvey Harrison09640e62009-02-01 00:45:17 -08001452 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001453 l4proto = ipv6_hdr(skb)->nexthdr;
1454
1455 if (l4proto == IPPROTO_TCP)
1456 opcode = TX_TCPV6_PKT;
1457 else if(l4proto == IPPROTO_UDP)
1458 opcode = TX_UDPV6_PKT;
1459 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001460 }
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001461
1462 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
1463 first_desc->ip_hdr_offset += skb_network_offset(skb);
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001464 netxen_set_tx_flags_opcode(first_desc, flags, opcode);
1465
1466 if (!tso)
1467 return;
1468
1469 /* For LSO, we need to copy the MAC/IP/TCP headers into
1470 * the descriptor ring
1471 */
1472 producer = tx_ring->producer;
1473 copied = 0;
1474 offset = 2;
1475
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001476 if (vlan_oob) {
1477 /* Create a TSO vlan header template for firmware */
1478
1479 hwdesc = &tx_ring->desc_head[producer];
1480 tx_ring->cmd_buf_arr[producer].skb = NULL;
1481
1482 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1483 hdr_len + VLAN_HLEN);
1484
1485 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2);
1486 skb_copy_from_linear_data(skb, vh, 12);
1487 vh->h_vlan_proto = htons(ETH_P_8021Q);
1488 vh->h_vlan_TCI = htons(vid);
1489 skb_copy_from_linear_data_offset(skb, 12,
1490 (char *)vh + 16, copy_len - 16);
1491
Dhananjay Phadke545eb372009-08-05 07:34:07 +00001492 copied = copy_len - VLAN_HLEN;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001493 offset = 0;
1494
1495 producer = get_next_index(producer, tx_ring->num_desc);
1496 }
1497
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001498 while (copied < hdr_len) {
1499
1500 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1501 (hdr_len - copied));
1502
1503 hwdesc = &tx_ring->desc_head[producer];
1504 tx_ring->cmd_buf_arr[producer].skb = NULL;
1505
1506 skb_copy_from_linear_data_offset(skb, copied,
1507 (char *)hwdesc + offset, copy_len);
1508
1509 copied += copy_len;
1510 offset = 0;
1511
1512 producer = get_next_index(producer, tx_ring->num_desc);
1513 }
1514
1515 tx_ring->producer = producer;
1516 barrier();
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001517}
1518
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001519static void
1520netxen_clean_tx_dma_mapping(struct pci_dev *pdev,
1521 struct netxen_cmd_buffer *pbuf, int last)
1522{
1523 int k;
1524 struct netxen_skb_frag *buffrag;
1525
1526 buffrag = &pbuf->frag_array[0];
1527 pci_unmap_single(pdev, buffrag->dma,
1528 buffrag->length, PCI_DMA_TODEVICE);
1529
1530 for (k = 1; k < last; k++) {
1531 buffrag = &pbuf->frag_array[k];
1532 pci_unmap_page(pdev, buffrag->dma,
1533 buffrag->length, PCI_DMA_TODEVICE);
1534 }
1535}
1536
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001537static inline void
1538netxen_clear_cmddesc(u64 *desc)
1539{
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001540 desc[0] = 0ULL;
1541 desc[2] = 0ULL;
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001542}
1543
1544static int
1545netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001546{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001547 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001548 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001549 struct skb_frag_struct *frag;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001550 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001551 struct netxen_skb_frag *buffrag;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001552 struct cmd_desc_type0 *hwdesc, *first_desc;
1553 struct pci_dev *pdev;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001554 dma_addr_t temp_dma;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001555 int i, k;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001556 unsigned long offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001557
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001558 u32 producer;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001559 int len, frag_count, no_of_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001560 u32 num_txd = tx_ring->num_desc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001561
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001562 frag_count = skb_shinfo(skb)->nr_frags + 1;
1563
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001564 /* 4 fragments per cmd des */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001565 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001566
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001567 if (unlikely(no_of_desc + 2) > netxen_tx_avail(tx_ring)) {
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001568 netif_stop_queue(netdev);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001569 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001570 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001571
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001572 producer = tx_ring->producer;
1573
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001574 pdev = adapter->pdev;
1575 len = skb->len - skb->data_len;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001576
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001577 temp_dma = pci_map_single(pdev, skb->data, len, PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001578 if (pci_dma_mapping_error(pdev, temp_dma))
1579 goto drop_packet;
1580
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001581 pbuf = &tx_ring->cmd_buf_arr[producer];
1582 pbuf->skb = skb;
1583 pbuf->frag_count = frag_count;
1584
1585 buffrag = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001586 buffrag->dma = temp_dma;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001587 buffrag->length = len;
1588
1589 first_desc = hwdesc = &tx_ring->desc_head[producer];
1590 netxen_clear_cmddesc((u64 *)hwdesc);
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001591 netxen_set_tx_frags_len(hwdesc, frag_count, skb->len);
1592 netxen_set_tx_port(hwdesc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001593
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001594 hwdesc->buffer_length[0] = cpu_to_le16(len);
1595 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001596
1597 for (i = 1, k = 1; i < frag_count; i++, k++) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001598
1599 /* move to next desc. if there is a need */
1600 if ((i & 0x3) == 0) {
1601 k = 0;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001602 producer = get_next_index(producer, num_txd);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001603 hwdesc = &tx_ring->desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001604 netxen_clear_cmddesc((u64 *)hwdesc);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001605 pbuf = &tx_ring->cmd_buf_arr[producer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001606 pbuf->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001607 }
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001608 buffrag = &pbuf->frag_array[i];
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001609 frag = &skb_shinfo(skb)->frags[i - 1];
1610 len = frag->size;
1611 offset = frag->page_offset;
1612
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001613 temp_dma = pci_map_page(pdev, frag->page, offset,
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001614 len, PCI_DMA_TODEVICE);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001615 if (pci_dma_mapping_error(pdev, temp_dma)) {
1616 netxen_clean_tx_dma_mapping(pdev, pbuf, i);
1617 goto drop_packet;
1618 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001619
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001620 buffrag->dma = temp_dma;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001621 buffrag->length = len;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001622
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001623 hwdesc->buffer_length[k] = cpu_to_le16(len);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001624 switch (k) {
1625 case 0:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001626 hwdesc->addr_buffer1 = cpu_to_le64(temp_dma);
1627 break;
1628 case 1:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001629 hwdesc->addr_buffer2 = cpu_to_le64(temp_dma);
1630 break;
1631 case 2:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001632 hwdesc->addr_buffer3 = cpu_to_le64(temp_dma);
1633 break;
1634 case 3:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001635 hwdesc->addr_buffer4 = cpu_to_le64(temp_dma);
1636 break;
1637 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001638 }
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001639 tx_ring->producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001640
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001641 netxen_tso_check(netdev, tx_ring, first_desc, skb);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001642
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001643 netxen_nic_update_cmd_producer(adapter, tx_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001644
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001645 adapter->stats.txbytes += skb->len;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001646 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001647
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001648 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001649
1650drop_packet:
1651 adapter->stats.txdropped++;
1652 dev_kfree_skb_any(skb);
1653 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001654}
1655
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001656static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1657{
1658 struct net_device *netdev = adapter->netdev;
1659 uint32_t temp, temp_state, temp_val;
1660 int rv = 0;
1661
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001662 temp = NXRD32(adapter, CRB_TEMP_STATE);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001663
1664 temp_state = nx_get_temp_state(temp);
1665 temp_val = nx_get_temp_val(temp);
1666
1667 if (temp_state == NX_TEMP_PANIC) {
1668 printk(KERN_ALERT
1669 "%s: Device temperature %d degrees C exceeds"
1670 " maximum allowed. Hardware has been shut down.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001671 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001672 rv = 1;
1673 } else if (temp_state == NX_TEMP_WARN) {
1674 if (adapter->temp == NX_TEMP_NORMAL) {
1675 printk(KERN_ALERT
1676 "%s: Device temperature %d degrees C "
1677 "exceeds operating range."
1678 " Immediate action needed.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001679 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001680 }
1681 } else {
1682 if (adapter->temp == NX_TEMP_WARN) {
1683 printk(KERN_INFO
1684 "%s: Device temperature is now %d degrees C"
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001685 " in normal range.\n", netdev->name,
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001686 temp_val);
1687 }
1688 }
1689 adapter->temp = temp_state;
1690 return rv;
1691}
1692
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001693void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup)
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001694{
1695 struct net_device *netdev = adapter->netdev;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001696
1697 if (adapter->ahw.linkup && !linkup) {
1698 printk(KERN_INFO "%s: %s NIC Link is down\n",
1699 netxen_nic_driver_name, netdev->name);
1700 adapter->ahw.linkup = 0;
1701 if (netif_running(netdev)) {
1702 netif_carrier_off(netdev);
1703 netif_stop_queue(netdev);
1704 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001705 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001706 } else if (!adapter->ahw.linkup && linkup) {
1707 printk(KERN_INFO "%s: %s NIC Link is up\n",
1708 netxen_nic_driver_name, netdev->name);
1709 adapter->ahw.linkup = 1;
1710 if (netif_running(netdev)) {
1711 netif_carrier_on(netdev);
1712 netif_wake_queue(netdev);
1713 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001714 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001715 }
1716}
1717
1718static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1719{
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001720 u32 val, port, linkup;
1721
1722 port = adapter->physical_port;
1723
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001724 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001725 val = NXRD32(adapter, CRB_XG_STATE_P3);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001726 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1727 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001728 } else {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001729 val = NXRD32(adapter, CRB_XG_STATE);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001730 if (adapter->ahw.port_type == NETXEN_NIC_GBE)
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001731 linkup = (val >> port) & 1;
1732 else {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001733 val = (val >> port*8) & 0xff;
1734 linkup = (val == XG_LINK_UP);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001735 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001736 }
1737
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001738 netxen_advert_link_change(adapter, linkup);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001739}
1740
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001741static void netxen_nic_thermal_shutdown(struct netxen_adapter *adapter)
1742{
1743 struct net_device *netdev = adapter->netdev;
1744
1745 netif_device_detach(netdev);
1746 netxen_nic_down(adapter, netdev);
1747 netxen_nic_detach(adapter);
1748}
1749
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001750static void netxen_watchdog(unsigned long v)
1751{
1752 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001753
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001754 if (netxen_nic_check_temp(adapter))
1755 goto do_sched;
1756
1757 if (!adapter->has_link_events) {
1758 netxen_nic_handle_phy_intr(adapter);
1759
1760 if (adapter->link_changed)
1761 goto do_sched;
1762 }
1763
1764 if (netif_running(adapter->netdev))
1765 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1766
1767 return;
1768
1769do_sched:
1770 schedule_work(&adapter->watchdog_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001771}
1772
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001773void netxen_watchdog_task(struct work_struct *work)
1774{
1775 struct netxen_adapter *adapter =
1776 container_of(work, struct netxen_adapter, watchdog_task);
1777
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001778 if (adapter->temp == NX_TEMP_PANIC) {
1779 netxen_nic_thermal_shutdown(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001780 return;
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001781 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001782
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001783 if (adapter->link_changed)
1784 netxen_nic_set_link_parameters(adapter);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001785
Dhananjay Phadke922c4f22008-08-08 00:08:41 -07001786 if (netif_running(adapter->netdev))
1787 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001788}
1789
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001790static void netxen_tx_timeout(struct net_device *netdev)
1791{
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001792 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001793
1794 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001795 schedule_work(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001796}
1797
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001798static void netxen_reset_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001799{
Jeff Garzik47906542007-11-23 21:23:36 -05001800 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001801 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001802
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001803 if (!netif_running(adapter->netdev))
1804 return;
1805
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001806 netxen_napi_disable(adapter);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001807
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001808 adapter->netdev->trans_start = jiffies;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001809
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001810 netxen_napi_enable(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001811 netif_wake_queue(adapter->netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001812}
1813
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001814struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1815{
1816 struct netxen_adapter *adapter = netdev_priv(netdev);
1817 struct net_device_stats *stats = &adapter->net_stats;
1818
1819 memset(stats, 0, sizeof(*stats));
1820
Narender Kumar1bb482f2009-08-23 08:35:09 +00001821 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00001822 stats->tx_packets = adapter->stats.xmitfinished;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001823 stats->rx_bytes = adapter->stats.rxbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001824 stats->tx_bytes = adapter->stats.txbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001825 stats->rx_dropped = adapter->stats.rxdropped;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001826 stats->tx_dropped = adapter->stats.txdropped;
1827
1828 return stats;
1829}
1830
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001831static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001832{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001833 struct nx_host_sds_ring *sds_ring = data;
1834 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001835 u32 status = 0;
1836
1837 status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1838
1839 if (!(status & adapter->legacy_intr.int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001840 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301841
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001842 if (adapter->ahw.revision_id >= NX_P3_B1) {
1843 /* check interrupt state machine, to be sure */
1844 status = adapter->pci_read_immediate(adapter,
1845 ISR_INT_STATE_REG);
1846 if (!ISR_LEGACY_INT_TRIGGERED(status))
1847 return IRQ_NONE;
1848
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001849 } else {
1850 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001851
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001852 our_int = NXRD32(adapter, CRB_INT_VECTOR);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001853
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001854 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001855 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001856 return IRQ_NONE;
1857
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001858 /* claim interrupt */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001859 NXWR32(adapter, CRB_INT_VECTOR, (our_int & 0xffffffff));
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301860 }
1861
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001862 /* clear interrupt */
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001863 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001864 netxen_nic_disable_int(sds_ring);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001865
1866 adapter->pci_write_immediate(adapter,
1867 adapter->legacy_intr.tgt_status_reg,
1868 0xffffffff);
1869 /* read twice to ensure write is flushed */
1870 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1871 adapter->pci_read_immediate(adapter, ISR_INT_VECTOR);
1872
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001873 napi_schedule(&sds_ring->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001874
1875 return IRQ_HANDLED;
1876}
1877
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001878static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001879{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001880 struct nx_host_sds_ring *sds_ring = data;
1881 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001882
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001883 /* clear interrupt */
1884 adapter->pci_write_immediate(adapter,
Dhananjay Phadke7a2469c2009-05-08 22:02:27 +00001885 adapter->msi_tgt_status, 0xffffffff);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001886
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001887 napi_schedule(&sds_ring->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001888 return IRQ_HANDLED;
1889}
1890
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001891static irqreturn_t netxen_msix_intr(int irq, void *data)
1892{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001893 struct nx_host_sds_ring *sds_ring = data;
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001894
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001895 napi_schedule(&sds_ring->napi);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001896 return IRQ_HANDLED;
1897}
1898
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001899static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001900{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001901 struct nx_host_sds_ring *sds_ring =
1902 container_of(napi, struct nx_host_sds_ring, napi);
1903
1904 struct netxen_adapter *adapter = sds_ring->adapter;
1905
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001906 int tx_complete;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001907 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001908
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001909 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001910
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001911 work_done = netxen_process_rcv_ring(sds_ring, budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001912
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001913 if ((work_done < budget) && tx_complete) {
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001914 napi_complete(&sds_ring->napi);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001915 if (netif_running(adapter->netdev))
1916 netxen_nic_enable_int(sds_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001917 }
1918
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001919 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001920}
1921
1922#ifdef CONFIG_NET_POLL_CONTROLLER
1923static void netxen_nic_poll_controller(struct net_device *netdev)
1924{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001925 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001926 disable_irq(adapter->irq);
Jeff Garzik1494a812006-11-07 05:12:16 -05001927 netxen_intr(adapter->irq, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001928 enable_irq(adapter->irq);
1929}
1930#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001931
Dhananjay Phadke044824d2009-07-28 09:10:03 +00001932#ifdef CONFIG_INET
1933
Dhananjay Phadke6598b162009-07-26 20:07:37 +00001934#define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
1935
1936static int
1937netxen_destip_supported(struct netxen_adapter *adapter)
1938{
1939 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
1940 return 0;
1941
1942 if (adapter->ahw.cut_through)
1943 return 0;
1944
1945 return 1;
1946}
1947
1948static int netxen_netdev_event(struct notifier_block *this,
1949 unsigned long event, void *ptr)
1950{
1951 struct netxen_adapter *adapter;
1952 struct net_device *dev = (struct net_device *)ptr;
1953 struct in_device *indev;
1954
1955recheck:
1956 if (dev == NULL)
1957 goto done;
1958
1959 if (dev->priv_flags & IFF_802_1Q_VLAN) {
1960 dev = vlan_dev_real_dev(dev);
1961 goto recheck;
1962 }
1963
1964 if (!is_netxen_netdev(dev))
1965 goto done;
1966
1967 adapter = netdev_priv(dev);
1968
1969 if (!adapter || !netxen_destip_supported(adapter))
1970 goto done;
1971
1972 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1973 goto done;
1974
1975 indev = in_dev_get(dev);
1976 if (!indev)
1977 goto done;
1978
1979 for_ifa(indev) {
1980 switch (event) {
1981 case NETDEV_UP:
1982 netxen_config_ipaddr(adapter,
1983 ifa->ifa_address, NX_IP_UP);
1984 break;
1985 case NETDEV_DOWN:
1986 netxen_config_ipaddr(adapter,
1987 ifa->ifa_address, NX_IP_DOWN);
1988 break;
1989 default:
1990 break;
1991 }
1992 } endfor_ifa(indev);
1993
1994 in_dev_put(indev);
1995done:
1996 return NOTIFY_DONE;
1997}
1998
1999static int
2000netxen_inetaddr_event(struct notifier_block *this,
2001 unsigned long event, void *ptr)
2002{
2003 struct netxen_adapter *adapter;
2004 struct net_device *dev;
2005
2006 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
2007
2008 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
2009
2010recheck:
2011 if (dev == NULL || !netif_running(dev))
2012 goto done;
2013
2014 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2015 dev = vlan_dev_real_dev(dev);
2016 goto recheck;
2017 }
2018
2019 if (!is_netxen_netdev(dev))
2020 goto done;
2021
2022 adapter = netdev_priv(dev);
2023
2024 if (!adapter || !netxen_destip_supported(adapter))
2025 goto done;
2026
2027 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2028 goto done;
2029
2030 switch (event) {
2031 case NETDEV_UP:
2032 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP);
2033 break;
2034 case NETDEV_DOWN:
2035 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN);
2036 break;
2037 default:
2038 break;
2039 }
2040
2041done:
2042 return NOTIFY_DONE;
2043}
2044
2045static struct notifier_block netxen_netdev_cb = {
2046 .notifier_call = netxen_netdev_event,
2047};
2048
2049static struct notifier_block netxen_inetaddr_cb = {
2050 .notifier_call = netxen_inetaddr_event,
2051};
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002052#endif
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002053
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002054static struct pci_driver netxen_driver = {
2055 .name = netxen_nic_driver_name,
2056 .id_table = netxen_pci_tbl,
2057 .probe = netxen_nic_probe,
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002058 .remove = __devexit_p(netxen_nic_remove),
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002059#ifdef CONFIG_PM
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002060 .suspend = netxen_nic_suspend,
2061 .resume = netxen_nic_resume
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002062#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002063};
2064
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002065static int __init netxen_init_module(void)
2066{
Dhananjay Phadkeff4fbd42009-03-13 14:52:06 +00002067 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
2068
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002069#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002070 register_netdevice_notifier(&netxen_netdev_cb);
2071 register_inetaddr_notifier(&netxen_inetaddr_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002072#endif
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002073
Amit S. Kale184231b2007-01-22 06:52:53 -08002074 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002075}
2076
2077module_init(netxen_init_module);
2078
2079static void __exit netxen_exit_module(void)
2080{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002081 pci_unregister_driver(&netxen_driver);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002082
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002083#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002084 unregister_inetaddr_notifier(&netxen_inetaddr_cb);
2085 unregister_netdevice_notifier(&netxen_netdev_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002086#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002087}
2088
2089module_exit(netxen_exit_module);