blob: 0b4a56a8c8d5fc2d9d9d1f8619e88e2031577a55 [file] [log] [blame]
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001/*
Dhananjay Phadke5d242f12009-02-25 15:57:56 +00002 * Copyright (C) 2003 - 2009 NetXen, Inc.
Dhananjay Phadke13af7a62009-09-11 11:28:15 +00003 * Copyright (C) 2009 - QLogic Corporation.
Amit S. Kale3d396eb2006-10-21 15:33:03 -04004 * All rights reserved.
Amit S. Kale80922fb2006-12-04 09:18:00 -08005 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -04006 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
Amit S. Kale80922fb2006-12-04 09:18:00 -080010 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040011 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Amit S. Kale80922fb2006-12-04 09:18:00 -080015 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040016 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
Amit S. Kale80922fb2006-12-04 09:18:00 -080020 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040021 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.
Amit S. Kale80922fb2006-12-04 09:18:00 -080023 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040024 */
25
Amit S. Kalecb8011a2006-11-29 09:00:10 -080026#include <linux/vmalloc.h>
Dhananjay Phadkee98e3352009-04-07 22:50:38 +000027#include <linux/interrupt.h>
Amit S. Kale3d396eb2006-10-21 15:33:03 -040028#include "netxen_nic_hw.h"
29
30#include "netxen_nic.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040031
Jeff Garzik1494a812006-11-07 05:12:16 -050032#include <linux/dma-mapping.h>
Dhananjay Phadke391587c2009-01-14 20:48:11 -080033#include <linux/if_vlan.h>
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030034#include <net/ip.h>
Dhananjay Phadke00977782009-01-16 11:03:25 -080035#include <linux/ipv6.h>
Dhananjay Phadke6598b162009-07-26 20:07:37 +000036#include <linux/inetdevice.h>
Jeff Garzik1494a812006-11-07 05:12:16 -050037
Amit S. Kale3d396eb2006-10-21 15:33:03 -040038MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
39MODULE_LICENSE("GPL");
40MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
41
dhananjay@netxen.comceded322007-07-19 14:41:09 +053042char netxen_nic_driver_name[] = "netxen_nic";
Amit S. Kale3d396eb2006-10-21 15:33:03 -040043static char netxen_nic_driver_string[] = "NetXen Network Driver version "
Amit S. Kalecb8011a2006-11-29 09:00:10 -080044 NETXEN_NIC_LINUX_VERSIONID;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040045
Dhananjay Phadke29566402008-07-21 19:44:04 -070046static int port_mode = NETXEN_PORT_MODE_AUTO_NEG;
47
48/* Default to restricted 1G auto-neg mode */
49static int wol_port_mode = 5;
50
51static int use_msi = 1;
52
53static int use_msi_x = 1;
54
Amit S. Kale3d396eb2006-10-21 15:33:03 -040055/* Local functions to NetXen NIC driver */
56static int __devinit netxen_nic_probe(struct pci_dev *pdev,
Dhananjay Phadke29566402008-07-21 19:44:04 -070057 const struct pci_device_id *ent);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040058static void __devexit netxen_nic_remove(struct pci_dev *pdev);
59static int netxen_nic_open(struct net_device *netdev);
60static int netxen_nic_close(struct net_device *netdev);
Stephen Hemminger613573252009-08-31 19:50:58 +000061static netdev_tx_t netxen_nic_xmit_frame(struct sk_buff *,
62 struct net_device *);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040063static void netxen_tx_timeout(struct net_device *netdev);
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +000064static void netxen_tx_timeout_task(struct work_struct *work);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +000065static void netxen_fw_poll_work(struct work_struct *work);
66static void netxen_schedule_work(struct netxen_adapter *adapter,
67 work_func_t func, int delay);
68static void netxen_cancel_fw_work(struct netxen_adapter *adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -070069static int netxen_nic_poll(struct napi_struct *napi, int budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040070#ifdef CONFIG_NET_POLL_CONTROLLER
71static void netxen_nic_poll_controller(struct net_device *netdev);
72#endif
Narender Kumarfa3ce352009-08-24 19:23:28 +000073
74static void netxen_create_sysfs_entries(struct netxen_adapter *adapter);
75static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter);
76
Dhananjay Phadke6a581e92009-09-05 17:43:08 +000077static int nx_decr_dev_ref_cnt(struct netxen_adapter *adapter);
78static int netxen_can_start_firmware(struct netxen_adapter *adapter);
79
Jeff Garzik1494a812006-11-07 05:12:16 -050080static irqreturn_t netxen_intr(int irq, void *data);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -070081static irqreturn_t netxen_msi_intr(int irq, void *data);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -080082static irqreturn_t netxen_msix_intr(int irq, void *data);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040083
Amit Kumar Salechad0725e42009-09-05 17:43:09 +000084static void netxen_config_indev_addr(struct net_device *dev, unsigned long);
85
Amit S. Kale3d396eb2006-10-21 15:33:03 -040086/* PCI Device ID Table */
Al Viro70081ac2008-06-23 02:04:50 +010087#define ENTRY(device) \
Dhananjay Phadke040dec32008-09-12 06:55:14 -070088 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
Al Viro70081ac2008-06-23 02:04:50 +010089 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
90
Amit S. Kale3d396eb2006-10-21 15:33:03 -040091static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
Dhananjay Phadke040dec32008-09-12 06:55:14 -070092 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR),
93 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4),
94 ENTRY(PCI_DEVICE_ID_NX2031_4GCU),
95 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ),
96 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ),
97 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT),
98 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2),
99 ENTRY(PCI_DEVICE_ID_NX3031),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400100 {0,}
101};
102
103MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
104
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700105static uint32_t crb_cmd_producer[4] = {
106 CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1,
107 CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3
108};
109
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700110void
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700111netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000112 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700113{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000114 NXWRIO(adapter, tx_ring->crb_cmd_producer, tx_ring->producer);
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000115
116 if (netxen_tx_avail(tx_ring) <= TX_STOP_THRESH) {
117 netif_stop_queue(adapter->netdev);
118 smp_mb();
119 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700120}
121
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700122static uint32_t crb_cmd_consumer[4] = {
123 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
124 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
125};
126
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700127static inline void
128netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +0000129 struct nx_host_tx_ring *tx_ring)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700130{
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000131 NXWRIO(adapter, tx_ring->crb_cmd_consumer, tx_ring->sw_consumer);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700132}
133
Dhananjay Phadke29566402008-07-21 19:44:04 -0700134static uint32_t msi_tgt_status[8] = {
Dhananjay Phadke443be792008-03-17 19:59:48 -0700135 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
Dhananjay Phadke29566402008-07-21 19:44:04 -0700136 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
137 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
138 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
Dhananjay Phadke443be792008-03-17 19:59:48 -0700139};
140
Dhananjay Phadke29566402008-07-21 19:44:04 -0700141static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
142
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000143static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700144{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000145 struct netxen_adapter *adapter = sds_ring->adapter;
146
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000147 NXWRIO(adapter, sds_ring->crb_intr_mask, 0);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700148}
149
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000150static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring)
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700151{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000152 struct netxen_adapter *adapter = sds_ring->adapter;
153
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000154 NXWRIO(adapter, sds_ring->crb_intr_mask, 0x1);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700155
Dhananjay Phadke092bc572008-08-08 00:08:43 -0700156 if (!NETXEN_IS_MSI_FAMILY(adapter))
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000157 NXWRIO(adapter, adapter->tgt_mask_reg, 0xfbff);
Stephen Hemminger4638aef12007-07-05 16:13:55 -0700158}
159
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000160static int
161netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count)
162{
163 int size = sizeof(struct nx_host_sds_ring) * count;
164
165 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
166
167 return (recv_ctx->sds_rings == NULL);
168}
169
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000170static void
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000171netxen_free_sds_rings(struct netxen_recv_context *recv_ctx)
172{
173 if (recv_ctx->sds_rings != NULL)
174 kfree(recv_ctx->sds_rings);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000175
176 recv_ctx->sds_rings = NULL;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000177}
178
179static int
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000180netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
181{
182 int ring;
183 struct nx_host_sds_ring *sds_ring;
184 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
185
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000186 if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
Dhananjay Phadkef17443f2009-07-26 20:07:43 +0000187 return -ENOMEM;
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000188
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000189 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
190 sds_ring = &recv_ctx->sds_rings[ring];
191 netif_napi_add(netdev, &sds_ring->napi,
192 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
193 }
Dhananjay Phadke71dcddb2009-04-07 22:50:43 +0000194
195 return 0;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000196}
197
198static void
Dhananjay Phadke232e7d62009-08-13 07:03:01 +0000199netxen_napi_del(struct netxen_adapter *adapter)
200{
201 int ring;
202 struct nx_host_sds_ring *sds_ring;
203 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
204
205 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
206 sds_ring = &recv_ctx->sds_rings[ring];
207 netif_napi_del(&sds_ring->napi);
208 }
209
210 netxen_free_sds_rings(&adapter->recv_ctx);
211}
212
213static void
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000214netxen_napi_enable(struct netxen_adapter *adapter)
215{
216 int ring;
217 struct nx_host_sds_ring *sds_ring;
218 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
219
220 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
221 sds_ring = &recv_ctx->sds_rings[ring];
222 napi_enable(&sds_ring->napi);
223 netxen_nic_enable_int(sds_ring);
224 }
225}
226
227static void
228netxen_napi_disable(struct netxen_adapter *adapter)
229{
230 int ring;
231 struct nx_host_sds_ring *sds_ring;
232 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
233
234 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
235 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000236 netxen_nic_disable_int(sds_ring);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000237 napi_synchronize(&sds_ring->napi);
238 napi_disable(&sds_ring->napi);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000239 }
240}
241
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000242static int nx_set_dma_mask(struct netxen_adapter *adapter)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700243{
244 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000245 uint64_t mask, cmask;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700246
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000247 adapter->pci_using_dac = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700248
Yang Hongyang6afd1422009-04-06 19:01:15 -0700249 mask = DMA_BIT_MASK(32);
Yang Hongyang6afd1422009-04-06 19:01:15 -0700250 cmask = DMA_BIT_MASK(32);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000251
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000252 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000253#ifndef CONFIG_IA64
Yang Hongyang6afd1422009-04-06 19:01:15 -0700254 mask = DMA_BIT_MASK(35);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000255#endif
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000256 } else {
257 mask = DMA_BIT_MASK(39);
258 cmask = mask;
259 }
260
Dhananjay Phadke29566402008-07-21 19:44:04 -0700261 if (pci_set_dma_mask(pdev, mask) == 0 &&
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000262 pci_set_consistent_dma_mask(pdev, cmask) == 0) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700263 adapter->pci_using_dac = 1;
264 return 0;
265 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700266
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000267 return -EIO;
268}
269
270/* Update addressable range if firmware supports it */
271static int
272nx_update_dma_mask(struct netxen_adapter *adapter)
273{
274 int change, shift, err;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000275 uint64_t mask, old_mask, old_cmask;
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000276 struct pci_dev *pdev = adapter->pdev;
277
278 change = 0;
279
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000280 shift = NXRD32(adapter, CRB_DMA_SHIFT);
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000281 if (shift > 32)
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000282 return 0;
283
284 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9))
285 change = 1;
286 else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4))
287 change = 1;
288
289 if (change) {
290 old_mask = pdev->dma_mask;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000291 old_cmask = pdev->dev.coherent_dma_mask;
292
Dhananjay Phadkef60f7852009-08-04 10:39:03 +0000293 mask = DMA_BIT_MASK(32+shift);
Dhananjay Phadke1f434f62009-03-02 16:02:16 +0000294
295 err = pci_set_dma_mask(pdev, mask);
296 if (err)
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000297 goto err_out;
298
299 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
300
301 err = pci_set_consistent_dma_mask(pdev, mask);
302 if (err)
303 goto err_out;
304 }
305 dev_info(&pdev->dev, "using %d-bit dma mask\n", 32+shift);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700306 }
307
Dhananjay Phadke29566402008-07-21 19:44:04 -0700308 return 0;
Dhananjay Phadke50c643e2009-08-01 21:36:16 +0000309
310err_out:
311 pci_set_dma_mask(pdev, old_mask);
312 pci_set_consistent_dma_mask(pdev, old_cmask);
313 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700314}
315
Dhananjay Phadke29566402008-07-21 19:44:04 -0700316static int
317netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
318{
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800319 u32 val, timeout;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700320
321 if (first_boot == 0x55555555) {
322 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000323 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800324
325 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
326 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700327
328 /* PCI bus master workaround */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000329 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700330 if (!(first_boot & 0x4)) {
331 first_boot |= 0x4;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000332 NXWR32(adapter, NETXEN_PCIE_REG(0x4), first_boot);
333 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700334 }
335
336 /* This is the first boot after power up */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000337 first_boot = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700338 if (first_boot != 0x80000f) {
339 /* clear the register for future unloads/loads */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000340 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), 0);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800341 return -EIO;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700342 }
343
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800344 /* Start P2 boot loader */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000345 val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
346 NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800347 timeout = 0;
348 do {
349 msleep(1);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000350 val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800351
352 if (++timeout > 5000)
353 return -EIO;
354
355 } while (val == NETXEN_BDINFO_MAGIC);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700356 }
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800357 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700358}
359
360static void netxen_set_port_mode(struct netxen_adapter *adapter)
361{
362 u32 val, data;
363
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000364 val = adapter->ahw.board_type;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700365 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
366 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
367 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
368 data = NETXEN_PORT_MODE_802_3_AP;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000369 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700370 } else if (port_mode == NETXEN_PORT_MODE_XG) {
371 data = NETXEN_PORT_MODE_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000372 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700373 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
374 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000375 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700376 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
377 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000378 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700379 } else {
380 data = NETXEN_PORT_MODE_AUTO_NEG;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000381 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700382 }
383
384 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
385 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
386 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
387 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
388 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
389 }
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000390 NXWR32(adapter, NETXEN_WOL_PORT_MODE, wol_port_mode);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700391 }
392}
393
Dhananjay Phadke29566402008-07-21 19:44:04 -0700394static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
395{
396 u32 control;
397 int pos;
398
399 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
400 if (pos) {
401 pci_read_config_dword(pdev, pos, &control);
402 if (enable)
403 control |= PCI_MSIX_FLAGS_ENABLE;
404 else
405 control = 0;
406 pci_write_config_dword(pdev, pos, control);
407 }
408}
409
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000410static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700411{
412 int i;
413
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000414 for (i = 0; i < count; i++)
Dhananjay Phadke29566402008-07-21 19:44:04 -0700415 adapter->msix_entries[i].entry = i;
416}
417
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700418static int
419netxen_read_mac_addr(struct netxen_adapter *adapter)
420{
421 int i;
422 unsigned char *p;
423 __le64 mac_addr;
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700424 struct net_device *netdev = adapter->netdev;
425 struct pci_dev *pdev = adapter->pdev;
426
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700427 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
428 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
429 return -EIO;
430 } else {
431 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
432 return -EIO;
433 }
434
435 p = (unsigned char *)&mac_addr;
436 for (i = 0; i < 6; i++)
437 netdev->dev_addr[i] = *(p + 5 - i);
438
439 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
440
441 /* set station address */
442
Johannes Berge1749612008-10-27 15:59:26 -0700443 if (!is_valid_ether_addr(netdev->perm_addr))
444 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -0700445
446 return 0;
447}
448
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000449int netxen_nic_set_mac(struct net_device *netdev, void *p)
450{
451 struct netxen_adapter *adapter = netdev_priv(netdev);
452 struct sockaddr *addr = p;
453
454 if (!is_valid_ether_addr(addr->sa_data))
455 return -EINVAL;
456
457 if (netif_running(netdev)) {
458 netif_device_detach(netdev);
459 netxen_napi_disable(adapter);
460 }
461
462 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
463 adapter->macaddr_set(adapter, addr->sa_data);
464
465 if (netif_running(netdev)) {
466 netif_device_attach(netdev);
467 netxen_napi_enable(adapter);
468 }
469 return 0;
470}
471
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800472static void netxen_set_multicast_list(struct net_device *dev)
473{
474 struct netxen_adapter *adapter = netdev_priv(dev);
475
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000476 adapter->set_multi(dev);
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800477}
478
479static const struct net_device_ops netxen_netdev_ops = {
480 .ndo_open = netxen_nic_open,
481 .ndo_stop = netxen_nic_close,
482 .ndo_start_xmit = netxen_nic_xmit_frame,
483 .ndo_get_stats = netxen_nic_get_stats,
484 .ndo_validate_addr = eth_validate_addr,
485 .ndo_set_multicast_list = netxen_set_multicast_list,
486 .ndo_set_mac_address = netxen_nic_set_mac,
487 .ndo_change_mtu = netxen_nic_change_mtu,
488 .ndo_tx_timeout = netxen_tx_timeout,
489#ifdef CONFIG_NET_POLL_CONTROLLER
490 .ndo_poll_controller = netxen_nic_poll_controller,
491#endif
492};
493
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800494static void
495netxen_setup_intr(struct netxen_adapter *adapter)
496{
497 struct netxen_legacy_intr_set *legacy_intrp;
498 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000499 int err, num_msix;
500
501 if (adapter->rss_supported) {
502 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
503 MSIX_ENTRIES_PER_ADAPTER : 2;
504 } else
505 num_msix = 1;
506
507 adapter->max_sds_rings = 1;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800508
509 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800510
511 if (adapter->ahw.revision_id >= NX_P3_B0)
512 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
513 else
514 legacy_intrp = &legacy_intr[0];
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000515
516 adapter->int_vec_bit = legacy_intrp->int_vec_bit;
517 adapter->tgt_status_reg = netxen_get_ioaddr(adapter,
518 legacy_intrp->tgt_status_reg);
519 adapter->tgt_mask_reg = netxen_get_ioaddr(adapter,
520 legacy_intrp->tgt_mask_reg);
521 adapter->pci_int_reg = netxen_get_ioaddr(adapter,
522 legacy_intrp->pci_int_reg);
523 adapter->isr_int_vec = netxen_get_ioaddr(adapter, ISR_INT_VECTOR);
524
525 if (adapter->ahw.revision_id >= NX_P3_B1)
526 adapter->crb_int_state_reg = netxen_get_ioaddr(adapter,
527 ISR_INT_STATE_REG);
528 else
529 adapter->crb_int_state_reg = netxen_get_ioaddr(adapter,
530 CRB_INT_VECTOR);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800531
532 netxen_set_msix_bit(pdev, 0);
533
534 if (adapter->msix_supported) {
535
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000536 netxen_init_msix_entries(adapter, num_msix);
537 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
538 if (err == 0) {
539 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
540 netxen_set_msix_bit(pdev, 1);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800541
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000542 if (adapter->rss_supported)
543 adapter->max_sds_rings = num_msix;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800544
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000545 dev_info(&pdev->dev, "using msi-x interrupts\n");
546 return;
547 }
548
549 if (err > 0)
550 pci_disable_msix(pdev);
551
552 /* fall through for msi */
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800553 }
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000554
555 if (use_msi && !pci_enable_msi(pdev)) {
556 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000557 adapter->tgt_status_reg = netxen_get_ioaddr(adapter,
558 msi_tgt_status[adapter->ahw.pci_func]);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000559 dev_info(&pdev->dev, "using msi interrupts\n");
Dhananjay Phadkef67f3402009-05-18 21:46:40 -0700560 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000561 return;
562 }
563
564 dev_info(&pdev->dev, "using legacy interrupts\n");
565 adapter->msix_entries[0].vector = pdev->irq;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800566}
567
568static void
569netxen_teardown_intr(struct netxen_adapter *adapter)
570{
571 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
572 pci_disable_msix(adapter->pdev);
573 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
574 pci_disable_msi(adapter->pdev);
575}
576
577static void
578netxen_cleanup_pci_map(struct netxen_adapter *adapter)
579{
580 if (adapter->ahw.db_base != NULL)
581 iounmap(adapter->ahw.db_base);
582 if (adapter->ahw.pci_base0 != NULL)
583 iounmap(adapter->ahw.pci_base0);
584 if (adapter->ahw.pci_base1 != NULL)
585 iounmap(adapter->ahw.pci_base1);
586 if (adapter->ahw.pci_base2 != NULL)
587 iounmap(adapter->ahw.pci_base2);
588}
589
590static int
591netxen_setup_pci_map(struct netxen_adapter *adapter)
592{
593 void __iomem *mem_ptr0 = NULL;
594 void __iomem *mem_ptr1 = NULL;
595 void __iomem *mem_ptr2 = NULL;
596 void __iomem *db_ptr = NULL;
597
Dhananjay Phadke71fb62f2009-10-13 00:26:04 -0700598 resource_size_t mem_base, db_base;
599 unsigned long mem_len, db_len = 0, pci_len0 = 0;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800600
601 struct pci_dev *pdev = adapter->pdev;
602 int pci_func = adapter->ahw.pci_func;
603
604 int err = 0;
605
606 /*
607 * Set the CRB window to invalid. If any register in window 0 is
608 * accessed it should set the window to 0 and then reset it to 1.
609 */
610 adapter->curr_window = 255;
611 adapter->ahw.qdr_sn_window = -1;
612 adapter->ahw.ddr_mn_window = -1;
613
614 /* remap phys address */
615 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
616 mem_len = pci_resource_len(pdev, 0);
617 pci_len0 = 0;
618
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800619 /* 128 Meg of memory */
620 if (mem_len == NETXEN_PCI_128MB_SIZE) {
621 mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
622 mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
623 SECOND_PAGE_GROUP_SIZE);
624 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
625 THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800626 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
627 mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
628 mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
629 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800630 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800631
632 mem_ptr0 = pci_ioremap_bar(pdev, 0);
633 if (mem_ptr0 == NULL) {
634 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
635 return -EIO;
636 }
637 pci_len0 = mem_len;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800638
639 adapter->ahw.ddr_mn_window = 0;
640 adapter->ahw.qdr_sn_window = 0;
641
Dhananjay Phadkeea6828b2009-09-11 11:28:12 +0000642 adapter->ahw.mn_win_crb = NETXEN_PCI_CRBSPACE +
643 0x100000 + PCIX_MN_WINDOW + (pci_func * 0x20);
644 adapter->ahw.ms_win_crb = NETXEN_PCI_CRBSPACE +
645 0x100000 + PCIX_SN_WINDOW;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800646 if (pci_func < 4)
647 adapter->ahw.ms_win_crb += (pci_func * 0x20);
648 else
649 adapter->ahw.ms_win_crb +=
650 0xA0 + ((pci_func - 4) * 0x10);
651 } else {
652 return -EIO;
653 }
654
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +0000655 netxen_setup_hwops(adapter);
656
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800657 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
658
659 adapter->ahw.pci_base0 = mem_ptr0;
660 adapter->ahw.pci_len0 = pci_len0;
Dhananjay Phadke97daee82009-02-24 16:39:21 -0800661 adapter->ahw.pci_base1 = mem_ptr1;
662 adapter->ahw.pci_base2 = mem_ptr2;
663
664 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
665 goto skip_doorbell;
666
667 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
668 db_len = pci_resource_len(pdev, 4);
669
670 if (db_len == 0) {
671 printk(KERN_ERR "%s: doorbell is disabled\n",
672 netxen_nic_driver_name);
673 err = -EIO;
674 goto err_out;
675 }
676
677 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
678 if (!db_ptr) {
679 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
680 netxen_nic_driver_name);
681 err = -EIO;
682 goto err_out;
683 }
684
685skip_doorbell:
686 adapter->ahw.db_base = db_ptr;
687 adapter->ahw.db_len = db_len;
688 return 0;
689
690err_out:
691 netxen_cleanup_pci_map(adapter);
692 return err;
693}
694
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000695static void
696netxen_check_options(struct netxen_adapter *adapter)
697{
698 u32 fw_major, fw_minor, fw_build;
699 char brd_name[NETXEN_MAX_SHORT_NAME];
700 char serial_num[32];
701 int i, offset, val;
702 int *ptr32;
703 struct pci_dev *pdev = adapter->pdev;
704
705 adapter->driver_mismatch = 0;
706
707 ptr32 = (int *)&serial_num;
708 offset = NX_FW_SERIAL_NUM_OFFSET;
709 for (i = 0; i < 8; i++) {
710 if (netxen_rom_fast_read(adapter, offset, &val) == -1) {
711 dev_err(&pdev->dev, "error reading board info\n");
712 adapter->driver_mismatch = 1;
713 return;
714 }
715 ptr32[i] = cpu_to_le32(val);
716 offset += sizeof(u32);
717 }
718
719 fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
720 fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
721 fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
722
723 adapter->fw_version = NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build);
724
725 if (adapter->portnum == 0) {
726 get_brd_name_by_type(adapter->ahw.board_type, brd_name);
727
728 printk(KERN_INFO "NetXen %s Board S/N %s Chip rev 0x%x\n",
729 brd_name, serial_num, adapter->ahw.revision_id);
730 }
731
732 if (adapter->fw_version < NETXEN_VERSION_CODE(3, 4, 216)) {
733 adapter->driver_mismatch = 1;
734 dev_warn(&pdev->dev, "firmware version %d.%d.%d unsupported\n",
735 fw_major, fw_minor, fw_build);
736 return;
737 }
738
739 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
740 i = NXRD32(adapter, NETXEN_SRE_MISC);
741 adapter->ahw.cut_through = (i & 0x8000) ? 1 : 0;
742 }
743
744 dev_info(&pdev->dev, "firmware v%d.%d.%d [%s]\n",
745 fw_major, fw_minor, fw_build,
746 adapter->ahw.cut_through ? "cut-through" : "legacy");
747
748 if (adapter->fw_version >= NETXEN_VERSION_CODE(4, 0, 222))
749 adapter->capabilities = NXRD32(adapter, CRB_FW_CAPABILITIES_1);
750
751 adapter->flags &= ~NETXEN_NIC_LRO_ENABLED;
752
753 if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
754 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
755 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
756 } else if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
757 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
758 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
759 }
760
761 adapter->msix_supported = 0;
762 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
763 adapter->msix_supported = !!use_msi_x;
764 adapter->rss_supported = !!use_msi_x;
765 } else if (adapter->fw_version >= NETXEN_VERSION_CODE(3, 4, 336)) {
766 switch (adapter->ahw.board_type) {
767 case NETXEN_BRDTYPE_P2_SB31_10G:
768 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
769 adapter->msix_supported = !!use_msi_x;
770 adapter->rss_supported = !!use_msi_x;
771 break;
772 default:
773 break;
774 }
775 }
776
777 adapter->num_txd = MAX_CMD_DESCRIPTORS;
778
779 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
780 adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS;
781 adapter->max_rds_rings = 3;
782 } else {
783 adapter->num_lro_rxd = 0;
784 adapter->max_rds_rings = 2;
785 }
786}
787
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800788static int
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000789netxen_start_firmware(struct netxen_adapter *adapter)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800790{
791 int val, err, first_boot;
792 struct pci_dev *pdev = adapter->pdev;
793
Dhananjay Phadke2b9e62e2009-09-05 17:43:11 +0000794 /* required for NX2031 dummy dma */
795 err = nx_set_dma_mask(adapter);
796 if (err)
797 return err;
798
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000799 if (!netxen_can_start_firmware(adapter))
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000800 goto wait_init;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +0000801
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000802 first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800803
804 err = netxen_check_hw_init(adapter, first_boot);
805 if (err) {
806 dev_err(&pdev->dev, "error in init HW init sequence\n");
807 return err;
808 }
809
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000810 netxen_request_firmware(adapter);
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000811
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000812 err = netxen_need_fw_reset(adapter);
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000813 if (err < 0)
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000814 goto err_out;
Dhananjay Phadke1dbc84a2009-08-23 08:35:10 +0000815 if (err == 0)
Dhananjay Phadkeec5c50c2009-09-11 11:28:13 +0000816 goto ready;
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000817
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800818 if (first_boot != 0x55555555) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000819 NXWR32(adapter, CRB_CMDPEG_STATE, 0);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800820 netxen_pinit_from_rom(adapter, 0);
821 msleep(1);
822 }
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000823
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000824 NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000825 NXWR32(adapter, NETXEN_PEG_HALT_STATUS1, 0);
826 NXWR32(adapter, NETXEN_PEG_HALT_STATUS2, 0);
827
Dhananjay Phadke567c6c42009-03-02 16:02:17 +0000828 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
829 netxen_set_port_mode(adapter);
830
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000831 err = netxen_load_firmware(adapter);
832 if (err)
833 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800834
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000835 netxen_release_firmware(adapter);
836
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800837 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
838
839 /* Initialize multicast addr pool owners */
840 val = 0x7654;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000841 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800842 val |= 0x0f000000;
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000843 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800844
845 }
846
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000847 err = netxen_init_dummy_dma(adapter);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800848 if (err)
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000849 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800850
851 /*
852 * Tell the hardware our version number.
853 */
854 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
855 | ((_NETXEN_NIC_LINUX_MINOR << 8))
856 | (_NETXEN_NIC_LINUX_SUBVERSION);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000857 NXWR32(adapter, CRB_DRIVER_VERSION, val);
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800858
Dhananjay Phadkeec5c50c2009-09-11 11:28:13 +0000859ready:
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000860 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_READY);
861
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +0000862wait_init:
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800863 /* Handshake with the card before we register the devices. */
864 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
865 if (err) {
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +0000866 netxen_free_dummy_dma(adapter);
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000867 goto err_out;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800868 }
869
Dhananjay Phadke68b3cae2009-07-26 20:07:36 +0000870 nx_update_dma_mask(adapter);
871
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000872 netxen_check_options(adapter);
Dhananjay Phadke68b3cae2009-07-26 20:07:36 +0000873
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +0000874 adapter->need_fw_reset = 0;
875
Dhananjay Phadkeec5c50c2009-09-11 11:28:13 +0000876 /* fall through and release firmware */
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000877
878err_out:
879 netxen_release_firmware(adapter);
880 return err;
Dhananjay Phadkeba599d42009-02-24 16:38:22 -0800881}
882
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000883static int
884netxen_nic_request_irq(struct netxen_adapter *adapter)
885{
886 irq_handler_t handler;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000887 struct nx_host_sds_ring *sds_ring;
888 int err, ring;
889
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000890 unsigned long flags = IRQF_SAMPLE_RANDOM;
891 struct net_device *netdev = adapter->netdev;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000892 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000893
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000894 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
895 handler = netxen_msix_intr;
896 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
897 handler = netxen_msi_intr;
898 else {
899 flags |= IRQF_SHARED;
900 handler = netxen_intr;
901 }
902 adapter->irq = netdev->irq;
903
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000904 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
905 sds_ring = &recv_ctx->sds_rings[ring];
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +0000906 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000907 err = request_irq(sds_ring->irq, handler,
908 flags, sds_ring->name, sds_ring);
909 if (err)
910 return err;
911 }
912
913 return 0;
914}
915
916static void
917netxen_nic_free_irq(struct netxen_adapter *adapter)
918{
919 int ring;
920 struct nx_host_sds_ring *sds_ring;
921
922 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
923
924 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
925 sds_ring = &recv_ctx->sds_rings[ring];
926 free_irq(sds_ring->irq, sds_ring);
927 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000928}
929
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000930static void
931netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter)
932{
933 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
934 adapter->coal.normal.data.rx_time_us =
935 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
936 adapter->coal.normal.data.rx_packets =
937 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
938 adapter->coal.normal.data.tx_time_us =
939 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US;
940 adapter->coal.normal.data.tx_packets =
941 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS;
942}
943
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000944static int
945netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
946{
947 int err;
948
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000949 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
950 return -EIO;
951
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000952 err = adapter->init_port(adapter, adapter->physical_port);
953 if (err) {
954 printk(KERN_ERR "%s: Failed to initialize port %d\n",
955 netxen_nic_driver_name, adapter->portnum);
956 return err;
957 }
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000958 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
959 adapter->macaddr_set(adapter, netdev->dev_addr);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000960
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000961 adapter->set_multi(netdev);
962 adapter->set_mtu(adapter, netdev->mtu);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000963
964 adapter->ahw.linkup = 0;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000965
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000966 if (adapter->max_sds_rings > 1)
967 netxen_config_rss(adapter, 1);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000968
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +0000969 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
970 netxen_config_intr_coalesce(adapter);
971
Narender Kumar1bb482f2009-08-23 08:35:09 +0000972 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
973 netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED);
974
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000975 netxen_napi_enable(adapter);
976
Dhananjay Phadke5103c9f2009-04-28 15:29:09 +0000977 if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +0000978 netxen_linkevent_request(adapter, 1);
Dhananjay Phadke3d0a3cc2009-05-05 19:05:08 +0000979 else
980 netxen_nic_set_link_parameters(adapter);
981
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000982 set_bit(__NX_DEV_UP, &adapter->state);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000983 return 0;
984}
985
986static void
987netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
988{
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +0000989 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
990 return;
991
Dhananjay Phadke6a581e92009-09-05 17:43:08 +0000992 clear_bit(__NX_DEV_UP, &adapter->state);
993
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000994 spin_lock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000995 netif_carrier_off(netdev);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000996 netif_tx_disable(netdev);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +0000997
998 if (adapter->stop_port)
999 adapter->stop_port(adapter);
1000
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +00001001 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1002 netxen_p3_free_mac_list(adapter);
1003
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001004 adapter->set_promisc(adapter, NETXEN_NIU_NON_PROMISC_MODE);
1005
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +00001006 netxen_napi_disable(adapter);
1007
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001008 netxen_release_tx_buffers(adapter);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001009 spin_unlock(&adapter->tx_clean_lock);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001010}
1011
1012
1013static int
1014netxen_nic_attach(struct netxen_adapter *adapter)
1015{
1016 struct net_device *netdev = adapter->netdev;
1017 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +00001018 int err, ring;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001019 struct nx_host_rds_ring *rds_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001020 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001021
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001022 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
1023 return 0;
1024
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001025 err = netxen_init_firmware(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +00001026 if (err)
1027 return err;
1028
1029 err = netxen_napi_add(adapter, netdev);
1030 if (err)
1031 return err;
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001032
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001033 err = netxen_alloc_sw_resources(adapter);
1034 if (err) {
1035 printk(KERN_ERR "%s: Error in setting sw resources\n",
1036 netdev->name);
1037 return err;
1038 }
1039
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001040 err = netxen_alloc_hw_resources(adapter);
1041 if (err) {
1042 printk(KERN_ERR "%s: Error in setting hw resources\n",
1043 netdev->name);
1044 goto err_out_free_sw;
1045 }
1046
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001047 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001048 tx_ring = adapter->tx_ring;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001049 tx_ring->crb_cmd_producer = netxen_get_ioaddr(adapter,
1050 crb_cmd_producer[adapter->portnum]);
1051 tx_ring->crb_cmd_consumer = netxen_get_ioaddr(adapter,
1052 crb_cmd_consumer[adapter->portnum]);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001053
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001054 tx_ring->producer = 0;
1055 tx_ring->sw_consumer = 0;
1056
1057 netxen_nic_update_cmd_producer(adapter, tx_ring);
1058 netxen_nic_update_cmd_consumer(adapter, tx_ring);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001059 }
1060
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001061 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1062 rds_ring = &adapter->recv_ctx.rds_rings[ring];
1063 netxen_post_rx_buffers(adapter, ring, rds_ring);
1064 }
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001065
1066 err = netxen_nic_request_irq(adapter);
1067 if (err) {
1068 dev_err(&pdev->dev, "%s: failed to setup interrupt\n",
1069 netdev->name);
1070 goto err_out_free_rxbuf;
1071 }
1072
Dhananjay Phadkeca2ef332009-07-26 20:07:38 +00001073 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1074 netxen_nic_init_coalesce_defaults(adapter);
1075
Narender Kumarfa3ce352009-08-24 19:23:28 +00001076 netxen_create_sysfs_entries(adapter);
1077
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001078 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1079 return 0;
1080
1081err_out_free_rxbuf:
1082 netxen_release_rx_buffers(adapter);
1083 netxen_free_hw_resources(adapter);
1084err_out_free_sw:
1085 netxen_free_sw_resources(adapter);
1086 return err;
1087}
1088
1089static void
1090netxen_nic_detach(struct netxen_adapter *adapter)
1091{
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001092 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1093 return;
1094
Narender Kumarfa3ce352009-08-24 19:23:28 +00001095 netxen_remove_sysfs_entries(adapter);
1096
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001097 netxen_free_hw_resources(adapter);
Dhananjay Phadkecf981ff2009-07-17 15:27:06 +00001098 netxen_release_rx_buffers(adapter);
Dhananjay Phadkebe339ae2009-05-08 22:02:28 +00001099 netxen_nic_free_irq(adapter);
Dhananjay Phadke232e7d62009-08-13 07:03:01 +00001100 netxen_napi_del(adapter);
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001101 netxen_free_sw_resources(adapter);
1102
1103 adapter->is_up = 0;
1104}
1105
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001106int
1107netxen_nic_reset_context(struct netxen_adapter *adapter)
1108{
1109 int err = 0;
1110 struct net_device *netdev = adapter->netdev;
1111
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001112 if (test_and_set_bit(__NX_RESETTING, &adapter->state))
1113 return -EBUSY;
1114
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001115 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
1116
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001117 netif_device_detach(netdev);
1118
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001119 if (netif_running(netdev))
1120 netxen_nic_down(adapter, netdev);
1121
1122 netxen_nic_detach(adapter);
1123
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001124 if (netif_running(netdev)) {
1125 err = netxen_nic_attach(adapter);
1126 if (!err)
1127 err = netxen_nic_up(adapter, netdev);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001128
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001129 if (err)
1130 goto done;
1131 }
1132
1133 netif_device_attach(netdev);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001134 }
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001135
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001136done:
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001137 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001138 return err;
1139}
1140
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001141static int
1142netxen_setup_netdev(struct netxen_adapter *adapter,
1143 struct net_device *netdev)
1144{
1145 int err = 0;
1146 struct pci_dev *pdev = adapter->pdev;
1147
1148 adapter->rx_csum = 1;
1149 adapter->mc_enabled = 0;
1150 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1151 adapter->max_mc_count = 38;
1152 else
1153 adapter->max_mc_count = 16;
1154
1155 netdev->netdev_ops = &netxen_netdev_ops;
1156 netdev->watchdog_timeo = 2*HZ;
1157
1158 netxen_nic_change_mtu(netdev, netdev->mtu);
1159
1160 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
1161
1162 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1163 netdev->features |= (NETIF_F_GRO);
1164 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1165
1166 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1167 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1168 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1169 }
1170
1171 if (adapter->pci_using_dac) {
1172 netdev->features |= NETIF_F_HIGHDMA;
1173 netdev->vlan_features |= NETIF_F_HIGHDMA;
1174 }
1175
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001176 if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX)
1177 netdev->features |= (NETIF_F_HW_VLAN_TX);
1178
Narender Kumar1bb482f2009-08-23 08:35:09 +00001179 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
1180 netdev->features |= NETIF_F_LRO;
1181
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001182 netdev->irq = adapter->msix_entries[0].vector;
1183
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001184 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001185
1186 if (netxen_read_mac_addr(adapter))
1187 dev_warn(&pdev->dev, "failed to read mac addr\n");
1188
1189 netif_carrier_off(netdev);
1190 netif_stop_queue(netdev);
1191
1192 err = register_netdev(netdev);
1193 if (err) {
1194 dev_err(&pdev->dev, "failed to register net device\n");
1195 return err;
1196 }
1197
1198 return 0;
1199}
1200
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001201static int __devinit
1202netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1203{
1204 struct net_device *netdev = NULL;
1205 struct netxen_adapter *adapter = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001206 int i = 0, err;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001207 int pci_func_id = PCI_FUNC(pdev->devfn);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001208 uint8_t revision_id;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001209
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001210 if (pdev->class != 0x020000) {
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001211 printk(KERN_DEBUG "NetXen function %d, class %x will not "
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001212 "be enabled.\n",pci_func_id, pdev->class);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001213 return -ENODEV;
1214 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001215
Dhananjay Phadke11d89d62008-08-08 00:08:45 -07001216 if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) {
1217 printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x"
1218 "will not be enabled.\n",
1219 NX_P3_A0, NX_P3_B1);
1220 return -ENODEV;
1221 }
1222
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001223 if ((err = pci_enable_device(pdev)))
1224 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001225
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001226 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1227 err = -ENODEV;
1228 goto err_out_disable_pdev;
1229 }
1230
1231 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
1232 goto err_out_disable_pdev;
1233
1234 pci_set_master(pdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001235
1236 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
1237 if(!netdev) {
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001238 dev_err(&pdev->dev, "failed to allocate net_device\n");
1239 err = -ENOMEM;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001240 goto err_out_free_res;
1241 }
1242
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001243 SET_NETDEV_DEV(netdev, &pdev->dev);
1244
Wang Chen4cf16532008-11-12 23:38:14 -08001245 adapter = netdev_priv(netdev);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001246 adapter->netdev = netdev;
1247 adapter->pdev = pdev;
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001248 adapter->ahw.pci_func = pci_func_id;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001249
1250 revision_id = pdev->revision;
1251 adapter->ahw.revision_id = revision_id;
1252
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -07001253 rwlock_init(&adapter->adapter_lock);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001254 spin_lock_init(&adapter->tx_clean_lock);
Dhananjay Phadke5cf4d322009-05-05 19:05:07 +00001255 INIT_LIST_HEAD(&adapter->mac_list);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001256
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001257 err = netxen_setup_pci_map(adapter);
1258 if (err)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001259 goto err_out_free_netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001260
dhananjay.phadke@gmail.com2d1a3bb2007-07-02 00:26:00 +05301261 /* This will be reset for mezz cards */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001262 adapter->portnum = pci_func_id;
1263
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001264 err = netxen_nic_get_board_info(adapter);
1265 if (err) {
1266 dev_err(&pdev->dev, "Error getting board config info.\n");
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001267 goto err_out_iounmap;
1268 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001269
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001270 /* Mezz cards have PCI function 0,2,3 enabled */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001271 switch (adapter->ahw.board_type) {
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001272 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1273 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1274 if (pci_func_id >= 2)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001275 adapter->portnum = pci_func_id - 2;
Dhananjay Phadkedc515f22008-06-15 22:59:43 -07001276 break;
1277 default:
1278 break;
1279 }
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -07001280
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001281 err = netxen_start_firmware(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001282 if (err)
1283 goto err_out_iounmap;
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001284
Dhananjay Phadke29566402008-07-21 19:44:04 -07001285 /*
1286 * See if the firmware gave us a virtual-physical port mapping.
1287 */
1288 adapter->physical_port = adapter->portnum;
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001289 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001290 i = NXRD32(adapter, CRB_V2P(adapter->portnum));
Dhananjay Phadke044fad02009-02-24 03:42:59 -08001291 if (i != 0x55555555)
1292 adapter->physical_port = i;
1293 }
Dhananjay Phadke29566402008-07-21 19:44:04 -07001294
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001295 netxen_nic_clear_stats(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001296
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001297 netxen_setup_intr(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001298
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001299 err = netxen_setup_netdev(adapter, netdev);
Dhananjay Phadke9dc28ef2008-08-08 00:08:39 -07001300 if (err)
Dhananjay Phadke29566402008-07-21 19:44:04 -07001301 goto err_out_disable_msi;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001302
1303 pci_set_drvdata(pdev, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001304
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001305 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
1306
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001307 switch (adapter->ahw.port_type) {
Dhananjay Phadke29566402008-07-21 19:44:04 -07001308 case NETXEN_NIC_GBE:
1309 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1310 adapter->netdev->name);
1311 break;
1312 case NETXEN_NIC_XGBE:
1313 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1314 adapter->netdev->name);
1315 break;
1316 }
1317
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001318 return 0;
1319
Dhananjay Phadke29566402008-07-21 19:44:04 -07001320err_out_disable_msi:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001321 netxen_teardown_intr(adapter);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001322
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001323 netxen_free_dummy_dma(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001324
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001325 nx_decr_dev_ref_cnt(adapter);
1326
Dhananjay Phadke29566402008-07-21 19:44:04 -07001327err_out_iounmap:
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001328 netxen_cleanup_pci_map(adapter);
Amit S. Kalecb8011a2006-11-29 09:00:10 -08001329
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001330err_out_free_netdev:
1331 free_netdev(netdev);
1332
1333err_out_free_res:
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001334 pci_release_regions(pdev);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001335
1336err_out_disable_pdev:
Dhananjay Phadke29566402008-07-21 19:44:04 -07001337 pci_set_drvdata(pdev, NULL);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001338 pci_disable_device(pdev);
1339 return err;
1340}
1341
1342static void __devexit netxen_nic_remove(struct pci_dev *pdev)
1343{
1344 struct netxen_adapter *adapter;
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001345 struct net_device *netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001346
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001347 adapter = pci_get_drvdata(pdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001348 if (adapter == NULL)
1349 return;
1350
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001351 netdev = adapter->netdev;
1352
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001353 netxen_cancel_fw_work(adapter);
1354
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301355 unregister_netdev(netdev);
1356
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001357 cancel_work_sync(&adapter->tx_timeout_task);
1358
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001359 netxen_nic_detach(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001360
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001361 nx_decr_dev_ref_cnt(adapter);
1362
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001363 if (adapter->portnum == 0)
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001364 netxen_free_dummy_dma(adapter);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301365
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001366 clear_bit(__NX_RESETTING, &adapter->state);
1367
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001368 netxen_teardown_intr(adapter);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301369
Dhananjay Phadke97daee82009-02-24 16:39:21 -08001370 netxen_cleanup_pci_map(adapter);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001371
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001372 netxen_release_firmware(adapter);
1373
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001374 pci_release_regions(pdev);
dhananjay@netxen.com30522462007-08-28 17:23:26 +05301375 pci_disable_device(pdev);
Mithlesh Thukral595e3fb2007-04-20 07:53:52 -07001376 pci_set_drvdata(pdev, NULL);
1377
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001378 free_netdev(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001379}
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001380static int __netxen_nic_shutdown(struct pci_dev *pdev)
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001381{
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001382 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1383 struct net_device *netdev = adapter->netdev;
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001384 int retval;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001385
1386 netif_device_detach(netdev);
1387
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001388 netxen_cancel_fw_work(adapter);
1389
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001390 if (netif_running(netdev))
1391 netxen_nic_down(adapter, netdev);
1392
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001393 cancel_work_sync(&adapter->tx_timeout_task);
1394
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001395 netxen_nic_detach(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001396
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001397 if (adapter->portnum == 0)
1398 netxen_free_dummy_dma(adapter);
1399
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001400 nx_decr_dev_ref_cnt(adapter);
1401
1402 clear_bit(__NX_RESETTING, &adapter->state);
1403
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001404 retval = pci_save_state(pdev);
1405 if (retval)
1406 return retval;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001407
1408 if (netxen_nic_wol_supported(adapter)) {
1409 pci_enable_wake(pdev, PCI_D3cold, 1);
1410 pci_enable_wake(pdev, PCI_D3hot, 1);
1411 }
1412
1413 pci_disable_device(pdev);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001414
1415 return 0;
1416}
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00001417static void netxen_nic_shutdown(struct pci_dev *pdev)
1418{
1419 if (__netxen_nic_shutdown(pdev))
1420 return;
1421}
1422#ifdef CONFIG_PM
1423static int
1424netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
1425{
1426 int retval;
1427
1428 retval = __netxen_nic_shutdown(pdev);
1429 if (retval)
1430 return retval;
1431
1432 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1433 return 0;
1434}
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001435
1436static int
1437netxen_nic_resume(struct pci_dev *pdev)
1438{
1439 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1440 struct net_device *netdev = adapter->netdev;
1441 int err;
1442
1443 pci_set_power_state(pdev, PCI_D0);
1444 pci_restore_state(pdev);
1445
1446 err = pci_enable_device(pdev);
1447 if (err)
1448 return err;
1449
1450 adapter->curr_window = 255;
1451
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001452 err = netxen_start_firmware(adapter);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001453 if (err) {
1454 dev_err(&pdev->dev, "failed to start firmware\n");
1455 return err;
1456 }
1457
1458 if (netif_running(netdev)) {
1459 err = netxen_nic_attach(adapter);
1460 if (err)
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001461 goto err_out;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001462
1463 err = netxen_nic_up(adapter, netdev);
1464 if (err)
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001465 goto err_out_detach;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001466
1467 netif_device_attach(netdev);
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00001468
1469 netxen_config_indev_addr(netdev, NETDEV_UP);
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001470 }
1471
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001472 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
Dhananjay Phadke07653aa2009-09-20 19:20:39 +00001473 return 0;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001474
1475err_out_detach:
1476 netxen_nic_detach(adapter);
1477err_out:
1478 nx_decr_dev_ref_cnt(adapter);
1479 return err;
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001480}
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00001481#endif
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00001482
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001483static int netxen_nic_open(struct net_device *netdev)
1484{
Wang Chen4cf16532008-11-12 23:38:14 -08001485 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001486 int err = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001487
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001488 if (adapter->driver_mismatch)
1489 return -EIO;
1490
Amit Kumar Salecha7042cd82009-07-27 11:15:54 -07001491 err = netxen_nic_attach(adapter);
1492 if (err)
1493 return err;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001494
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001495 err = netxen_nic_up(adapter, netdev);
1496 if (err)
1497 goto err_out;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001498
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -07001499 netif_start_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001500
1501 return 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001502
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001503err_out:
1504 netxen_nic_detach(adapter);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001505 return err;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001506}
1507
1508/*
1509 * netxen_nic_close - Disables a network interface entry point
1510 */
1511static int netxen_nic_close(struct net_device *netdev)
1512{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001513 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001514
Dhananjay Phadke9f5bc7f2009-03-09 08:50:54 +00001515 netxen_nic_down(adapter, netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001516 return 0;
1517}
1518
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001519static void
1520netxen_tso_check(struct net_device *netdev,
1521 struct nx_host_tx_ring *tx_ring,
1522 struct cmd_desc_type0 *first_desc,
1523 struct sk_buff *skb)
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001524{
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001525 u8 opcode = TX_ETHER_PKT;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001526 __be16 protocol = skb->protocol;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001527 u16 flags = 0, vid = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001528 u32 producer;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001529 int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001530 struct cmd_desc_type0 *hwdesc;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001531 struct vlan_ethhdr *vh;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001532
Harvey Harrison09640e62009-02-01 00:45:17 -08001533 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001534
1535 vh = (struct vlan_ethhdr *)skb->data;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001536 protocol = vh->h_vlan_encapsulated_proto;
1537 flags = FLAGS_VLAN_TAGGED;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001538
1539 } else if (vlan_tx_tag_present(skb)) {
1540
1541 flags = FLAGS_VLAN_OOB;
1542 vid = vlan_tx_tag_get(skb);
1543 netxen_set_tx_vlan_tci(first_desc, vid);
1544 vlan_oob = 1;
Dhananjay Phadkecdff1032009-01-26 12:34:57 -08001545 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001546
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001547 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1548 skb_shinfo(skb)->gso_size > 0) {
1549
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001550 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1551
1552 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1553 first_desc->total_hdr_length = hdr_len;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001554 if (vlan_oob) {
1555 first_desc->total_hdr_length += VLAN_HLEN;
1556 first_desc->tcp_hdr_offset = VLAN_HLEN;
1557 first_desc->ip_hdr_offset = VLAN_HLEN;
1558 /* Only in case of TSO on vlan device */
1559 flags |= FLAGS_VLAN_TAGGED;
1560 }
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001561
Harvey Harrison09640e62009-02-01 00:45:17 -08001562 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001563 TX_TCP_LSO6 : TX_TCP_LSO;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001564 tso = 1;
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001565
1566 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001567 u8 l4proto;
1568
Harvey Harrison09640e62009-02-01 00:45:17 -08001569 if (protocol == cpu_to_be16(ETH_P_IP)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001570 l4proto = ip_hdr(skb)->protocol;
1571
1572 if (l4proto == IPPROTO_TCP)
1573 opcode = TX_TCP_PKT;
1574 else if(l4proto == IPPROTO_UDP)
1575 opcode = TX_UDP_PKT;
Harvey Harrison09640e62009-02-01 00:45:17 -08001576 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001577 l4proto = ipv6_hdr(skb)->nexthdr;
1578
1579 if (l4proto == IPPROTO_TCP)
1580 opcode = TX_TCPV6_PKT;
1581 else if(l4proto == IPPROTO_UDP)
1582 opcode = TX_UDPV6_PKT;
1583 }
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001584 }
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001585
1586 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
1587 first_desc->ip_hdr_offset += skb_network_offset(skb);
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001588 netxen_set_tx_flags_opcode(first_desc, flags, opcode);
1589
1590 if (!tso)
1591 return;
1592
1593 /* For LSO, we need to copy the MAC/IP/TCP headers into
1594 * the descriptor ring
1595 */
1596 producer = tx_ring->producer;
1597 copied = 0;
1598 offset = 2;
1599
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001600 if (vlan_oob) {
1601 /* Create a TSO vlan header template for firmware */
1602
1603 hwdesc = &tx_ring->desc_head[producer];
1604 tx_ring->cmd_buf_arr[producer].skb = NULL;
1605
1606 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1607 hdr_len + VLAN_HLEN);
1608
1609 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2);
1610 skb_copy_from_linear_data(skb, vh, 12);
1611 vh->h_vlan_proto = htons(ETH_P_8021Q);
1612 vh->h_vlan_TCI = htons(vid);
1613 skb_copy_from_linear_data_offset(skb, 12,
1614 (char *)vh + 16, copy_len - 16);
1615
Dhananjay Phadke545eb372009-08-05 07:34:07 +00001616 copied = copy_len - VLAN_HLEN;
Dhananjay Phadke028afe72009-07-26 20:07:45 +00001617 offset = 0;
1618
1619 producer = get_next_index(producer, tx_ring->num_desc);
1620 }
1621
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001622 while (copied < hdr_len) {
1623
1624 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1625 (hdr_len - copied));
1626
1627 hwdesc = &tx_ring->desc_head[producer];
1628 tx_ring->cmd_buf_arr[producer].skb = NULL;
1629
1630 skb_copy_from_linear_data_offset(skb, copied,
1631 (char *)hwdesc + offset, copy_len);
1632
1633 copied += copy_len;
1634 offset = 0;
1635
1636 producer = get_next_index(producer, tx_ring->num_desc);
1637 }
1638
1639 tx_ring->producer = producer;
1640 barrier();
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -07001641}
1642
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001643static int
1644netxen_map_tx_skb(struct pci_dev *pdev,
1645 struct sk_buff *skb, struct netxen_cmd_buffer *pbuf)
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001646{
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001647 struct netxen_skb_frag *nf;
1648 struct skb_frag_struct *frag;
1649 int i, nr_frags;
1650 dma_addr_t map;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001651
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001652 nr_frags = skb_shinfo(skb)->nr_frags;
1653 nf = &pbuf->frag_array[0];
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001654
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001655 map = pci_map_single(pdev, skb->data,
1656 skb_headlen(skb), PCI_DMA_TODEVICE);
1657 if (pci_dma_mapping_error(pdev, map))
1658 goto out_err;
1659
1660 nf->dma = map;
1661 nf->length = skb_headlen(skb);
1662
1663 for (i = 0; i < nr_frags; i++) {
1664 frag = &skb_shinfo(skb)->frags[i];
1665 nf = &pbuf->frag_array[i+1];
1666
1667 map = pci_map_page(pdev, frag->page, frag->page_offset,
1668 frag->size, PCI_DMA_TODEVICE);
1669 if (pci_dma_mapping_error(pdev, map))
1670 goto unwind;
1671
1672 nf->dma = map;
1673 nf->length = frag->size;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001674 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001675
1676 return 0;
1677
1678unwind:
Dhananjay Phadkecf503e82009-09-03 13:10:55 +00001679 while (--i >= 0) {
1680 nf = &pbuf->frag_array[i+1];
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001681 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
1682 }
1683
1684 nf = &pbuf->frag_array[0];
1685 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
1686
1687out_err:
1688 return -ENOMEM;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001689}
1690
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001691static inline void
1692netxen_clear_cmddesc(u64 *desc)
1693{
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001694 desc[0] = 0ULL;
1695 desc[2] = 0ULL;
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001696}
1697
Stephen Hemminger613573252009-08-31 19:50:58 +00001698static netdev_tx_t
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001699netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001700{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001701 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001702 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001703 struct netxen_cmd_buffer *pbuf;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001704 struct netxen_skb_frag *buffrag;
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001705 struct cmd_desc_type0 *hwdesc, *first_desc;
1706 struct pci_dev *pdev;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001707 int i, k;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001708
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001709 u32 producer;
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001710 int frag_count, no_of_desc;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001711 u32 num_txd = tx_ring->num_desc;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001712
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001713 frag_count = skb_shinfo(skb)->nr_frags + 1;
1714
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001715 /* 4 fragments per cmd des */
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001716 no_of_desc = (frag_count + 3) >> 2;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001717
Roel Kluinfa9859e2009-10-06 19:34:39 +00001718 if (unlikely(no_of_desc + 2 > netxen_tx_avail(tx_ring))) {
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001719 netif_stop_queue(netdev);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001720 return NETDEV_TX_BUSY;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001721 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001722
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001723 producer = tx_ring->producer;
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001724 pbuf = &tx_ring->cmd_buf_arr[producer];
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001725
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001726 pdev = adapter->pdev;
Dhananjay Phadke391587c2009-01-14 20:48:11 -08001727
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001728 if (netxen_map_tx_skb(pdev, skb, pbuf))
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001729 goto drop_packet;
1730
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001731 pbuf->skb = skb;
1732 pbuf->frag_count = frag_count;
1733
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001734 first_desc = hwdesc = &tx_ring->desc_head[producer];
1735 netxen_clear_cmddesc((u64 *)hwdesc);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001736
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001737 netxen_set_tx_frags_len(first_desc, frag_count, skb->len);
1738 netxen_set_tx_port(first_desc, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001739
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001740 for (i = 0; i < frag_count; i++) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001741
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001742 k = i % 4;
1743
1744 if ((k == 0) && (i > 0)) {
1745 /* move to next desc.*/
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001746 producer = get_next_index(producer, num_txd);
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001747 hwdesc = &tx_ring->desc_head[producer];
Dhananjay Phadked32cc3d2009-03-09 08:50:53 +00001748 netxen_clear_cmddesc((u64 *)hwdesc);
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001749 tx_ring->cmd_buf_arr[producer].skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001750 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001751
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001752 buffrag = &pbuf->frag_array[i];
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001753
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001754 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001755 switch (k) {
1756 case 0:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001757 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001758 break;
1759 case 1:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001760 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001761 break;
1762 case 2:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001763 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001764 break;
1765 case 3:
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001766 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001767 break;
1768 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001769 }
Dhananjay Phadkece644ed2009-08-23 08:35:11 +00001770
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001771 tx_ring->producer = get_next_index(producer, num_txd);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001772
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001773 netxen_tso_check(netdev, tx_ring, first_desc, skb);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -07001774
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001775 netxen_nic_update_cmd_producer(adapter, tx_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001776
Dhananjay Phadke1bcfd792009-07-26 20:07:40 +00001777 adapter->stats.txbytes += skb->len;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001778 adapter->stats.xmitcalled++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001779
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001780 return NETDEV_TX_OK;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001781
1782drop_packet:
1783 adapter->stats.txdropped++;
1784 dev_kfree_skb_any(skb);
1785 return NETDEV_TX_OK;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001786}
1787
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001788static int netxen_nic_check_temp(struct netxen_adapter *adapter)
1789{
1790 struct net_device *netdev = adapter->netdev;
1791 uint32_t temp, temp_state, temp_val;
1792 int rv = 0;
1793
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001794 temp = NXRD32(adapter, CRB_TEMP_STATE);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001795
1796 temp_state = nx_get_temp_state(temp);
1797 temp_val = nx_get_temp_val(temp);
1798
1799 if (temp_state == NX_TEMP_PANIC) {
1800 printk(KERN_ALERT
1801 "%s: Device temperature %d degrees C exceeds"
1802 " maximum allowed. Hardware has been shut down.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001803 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001804 rv = 1;
1805 } else if (temp_state == NX_TEMP_WARN) {
1806 if (adapter->temp == NX_TEMP_NORMAL) {
1807 printk(KERN_ALERT
1808 "%s: Device temperature %d degrees C "
1809 "exceeds operating range."
1810 " Immediate action needed.\n",
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001811 netdev->name, temp_val);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001812 }
1813 } else {
1814 if (adapter->temp == NX_TEMP_WARN) {
1815 printk(KERN_INFO
1816 "%s: Device temperature is now %d degrees C"
Dhananjay Phadkee4135c22009-07-17 15:27:08 +00001817 " in normal range.\n", netdev->name,
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001818 temp_val);
1819 }
1820 }
1821 adapter->temp = temp_state;
1822 return rv;
1823}
1824
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001825void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup)
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001826{
1827 struct net_device *netdev = adapter->netdev;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001828
1829 if (adapter->ahw.linkup && !linkup) {
1830 printk(KERN_INFO "%s: %s NIC Link is down\n",
1831 netxen_nic_driver_name, netdev->name);
1832 adapter->ahw.linkup = 0;
1833 if (netif_running(netdev)) {
1834 netif_carrier_off(netdev);
1835 netif_stop_queue(netdev);
1836 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001837 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001838 } else if (!adapter->ahw.linkup && linkup) {
1839 printk(KERN_INFO "%s: %s NIC Link is up\n",
1840 netxen_nic_driver_name, netdev->name);
1841 adapter->ahw.linkup = 1;
1842 if (netif_running(netdev)) {
1843 netif_carrier_on(netdev);
1844 netif_wake_queue(netdev);
1845 }
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001846 adapter->link_changed = !adapter->has_link_events;
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001847 }
1848}
1849
1850static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
1851{
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001852 u32 val, port, linkup;
1853
1854 port = adapter->physical_port;
1855
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001856 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001857 val = NXRD32(adapter, CRB_XG_STATE_P3);
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001858 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
1859 linkup = (val == XG_LINK_UP_P3);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001860 } else {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001861 val = NXRD32(adapter, CRB_XG_STATE);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +00001862 if (adapter->ahw.port_type == NETXEN_NIC_GBE)
Dhananjay Phadke24a7a452008-08-01 03:14:55 -07001863 linkup = (val >> port) & 1;
1864 else {
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001865 val = (val >> port*8) & 0xff;
1866 linkup = (val == XG_LINK_UP);
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -07001867 }
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001868 }
1869
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001870 netxen_advert_link_change(adapter, linkup);
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001871}
1872
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001873static void netxen_tx_timeout(struct net_device *netdev)
1874{
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001875 struct netxen_adapter *adapter = netdev_priv(netdev);
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001876
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001877 if (test_bit(__NX_RESETTING, &adapter->state))
1878 return;
1879
Dhananjay Phadkef17443f2009-07-26 20:07:43 +00001880 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechae424fa92009-08-13 07:03:00 +00001881 schedule_work(&adapter->tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001882}
1883
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001884static void netxen_tx_timeout_task(struct work_struct *work)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001885{
Jeff Garzik47906542007-11-23 21:23:36 -05001886 struct netxen_adapter *adapter =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001887 container_of(work, struct netxen_adapter, tx_timeout_task);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001888
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001889 if (!netif_running(adapter->netdev))
1890 return;
1891
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001892 if (test_and_set_bit(__NX_RESETTING, &adapter->state))
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00001893 return;
1894
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001895 if (++adapter->tx_timeo_cnt >= NX_MAX_TX_TIMEOUTS)
1896 goto request_reset;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001897
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001898 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1899 /* try to scrub interrupt */
1900 netxen_napi_disable(adapter);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001901
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001902 adapter->netdev->trans_start = jiffies;
1903
1904 netxen_napi_enable(adapter);
1905
1906 netif_wake_queue(adapter->netdev);
1907
Dhananjay Phadkea598ae12009-09-20 19:20:38 +00001908 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001909
1910 } else {
Dhananjay Phadkea598ae12009-09-20 19:20:38 +00001911 clear_bit(__NX_RESETTING, &adapter->state);
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001912 if (!netxen_nic_reset_context(adapter)) {
1913 adapter->netdev->trans_start = jiffies;
Dhananjay Phadkea598ae12009-09-20 19:20:38 +00001914 return;
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001915 }
1916
1917 /* context reset failed, fall through for fw reset */
1918 }
1919
1920request_reset:
1921 adapter->need_fw_reset = 1;
Amit Kumar Salechaff8a3062009-10-21 19:39:02 +00001922 clear_bit(__NX_RESETTING, &adapter->state);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001923}
1924
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001925struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
1926{
1927 struct netxen_adapter *adapter = netdev_priv(netdev);
1928 struct net_device_stats *stats = &adapter->net_stats;
1929
1930 memset(stats, 0, sizeof(*stats));
1931
Narender Kumar1bb482f2009-08-23 08:35:09 +00001932 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
Dhananjay Phadkee98e3352009-04-07 22:50:38 +00001933 stats->tx_packets = adapter->stats.xmitfinished;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001934 stats->rx_bytes = adapter->stats.rxbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001935 stats->tx_bytes = adapter->stats.txbytes;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001936 stats->rx_dropped = adapter->stats.rxdropped;
Dhananjay Phadkea97342f2008-07-21 19:44:05 -07001937 stats->tx_dropped = adapter->stats.txdropped;
1938
1939 return stats;
1940}
1941
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001942static irqreturn_t netxen_intr(int irq, void *data)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001943{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001944 struct nx_host_sds_ring *sds_ring = data;
1945 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001946 u32 status = 0;
1947
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001948 status = readl(adapter->isr_int_vec);
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001949
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001950 if (!(status & adapter->int_vec_bit))
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001951 return IRQ_NONE;
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301952
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001953 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001954 /* check interrupt state machine, to be sure */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001955 status = readl(adapter->crb_int_state_reg);
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001956 if (!ISR_LEGACY_INT_TRIGGERED(status))
1957 return IRQ_NONE;
1958
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001959 } else {
1960 unsigned long our_int = 0;
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001961
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001962 our_int = readl(adapter->crb_int_state_reg);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001963
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001964 /* not our interrupt */
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001965 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
Dhananjay Phadked71e1be2008-08-01 03:14:57 -07001966 return IRQ_NONE;
1967
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001968 /* claim interrupt */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001969 writel((our_int & 0xffffffff), adapter->crb_int_state_reg);
1970
1971 /* clear interrupt */
1972 netxen_nic_disable_int(sds_ring);
dhananjay@netxen.come01872af2007-07-25 20:13:12 +05301973 }
1974
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001975 writel(0xffffffff, adapter->tgt_status_reg);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001976 /* read twice to ensure write is flushed */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001977 readl(adapter->isr_int_vec);
1978 readl(adapter->isr_int_vec);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001979
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001980 napi_schedule(&sds_ring->napi);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001981
1982 return IRQ_HANDLED;
1983}
1984
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -07001985static irqreturn_t netxen_msi_intr(int irq, void *data)
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001986{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001987 struct nx_host_sds_ring *sds_ring = data;
1988 struct netxen_adapter *adapter = sds_ring->adapter;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001989
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001990 /* clear interrupt */
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001991 writel(0xffffffff, adapter->tgt_status_reg);
Dhananjay Phadke092bc572008-08-08 00:08:43 -07001992
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001993 napi_schedule(&sds_ring->napi);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001994 return IRQ_HANDLED;
1995}
1996
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08001997static irqreturn_t netxen_msix_intr(int irq, void *data)
1998{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001999 struct nx_host_sds_ring *sds_ring = data;
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08002000
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002001 napi_schedule(&sds_ring->napi);
Dhananjay Phadkeb3df68f2009-02-08 19:20:19 -08002002 return IRQ_HANDLED;
2003}
2004
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002005static int netxen_nic_poll(struct napi_struct *napi, int budget)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002006{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002007 struct nx_host_sds_ring *sds_ring =
2008 container_of(napi, struct nx_host_sds_ring, napi);
2009
2010 struct netxen_adapter *adapter = sds_ring->adapter;
2011
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002012 int tx_complete;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002013 int work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002014
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002015 tx_complete = netxen_process_cmd_ring(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002016
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002017 work_done = netxen_process_rcv_ring(sds_ring, budget);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002018
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07002019 if ((work_done < budget) && tx_complete) {
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00002020 napi_complete(&sds_ring->napi);
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00002021 if (netif_running(adapter->netdev))
2022 netxen_nic_enable_int(sds_ring);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002023 }
2024
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002025 return work_done;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002026}
2027
2028#ifdef CONFIG_NET_POLL_CONTROLLER
2029static void netxen_nic_poll_controller(struct net_device *netdev)
2030{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07002031 struct netxen_adapter *adapter = netdev_priv(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002032 disable_irq(adapter->irq);
Jeff Garzik1494a812006-11-07 05:12:16 -05002033 netxen_intr(adapter->irq, adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002034 enable_irq(adapter->irq);
2035}
2036#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002037
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002038static int
2039nx_incr_dev_ref_cnt(struct netxen_adapter *adapter)
2040{
2041 int count;
2042 if (netxen_api_lock(adapter))
2043 return -EIO;
2044
2045 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2046
2047 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2048
2049 netxen_api_unlock(adapter);
2050 return count;
2051}
2052
2053static int
2054nx_decr_dev_ref_cnt(struct netxen_adapter *adapter)
2055{
2056 int count;
2057 if (netxen_api_lock(adapter))
2058 return -EIO;
2059
2060 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2061 WARN_ON(count == 0);
2062
2063 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, --count);
2064
2065 if (count == 0)
2066 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_COLD);
2067
2068 netxen_api_unlock(adapter);
2069 return count;
2070}
2071
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002072static void
2073nx_dev_request_reset(struct netxen_adapter *adapter)
2074{
2075 u32 state;
2076
2077 if (netxen_api_lock(adapter))
2078 return;
2079
2080 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2081
2082 if (state != NX_DEV_INITALIZING)
2083 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_RESET);
2084
2085 netxen_api_unlock(adapter);
2086}
2087
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002088static int
2089netxen_can_start_firmware(struct netxen_adapter *adapter)
2090{
2091 int count;
2092 int can_start = 0;
2093
2094 if (netxen_api_lock(adapter))
2095 return 0;
2096
2097 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2098
2099 if ((count < 0) || (count >= NX_MAX_PCI_FUNC))
2100 count = 0;
2101
2102 if (count == 0) {
2103 can_start = 1;
2104 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_INITALIZING);
2105 }
2106
2107 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2108
2109 netxen_api_unlock(adapter);
2110
2111 return can_start;
2112}
2113
2114static void
2115netxen_schedule_work(struct netxen_adapter *adapter,
2116 work_func_t func, int delay)
2117{
2118 INIT_DELAYED_WORK(&adapter->fw_work, func);
2119 schedule_delayed_work(&adapter->fw_work, delay);
2120}
2121
2122static void
2123netxen_cancel_fw_work(struct netxen_adapter *adapter)
2124{
2125 while (test_and_set_bit(__NX_RESETTING, &adapter->state))
2126 msleep(10);
2127
2128 cancel_delayed_work_sync(&adapter->fw_work);
2129}
2130
2131static void
2132netxen_attach_work(struct work_struct *work)
2133{
2134 struct netxen_adapter *adapter = container_of(work,
2135 struct netxen_adapter, fw_work.work);
2136 struct net_device *netdev = adapter->netdev;
2137 int err = 0;
2138
2139 if (netif_running(netdev)) {
2140 err = netxen_nic_attach(adapter);
2141 if (err)
2142 goto done;
2143
2144 err = netxen_nic_up(adapter, netdev);
2145 if (err) {
2146 netxen_nic_detach(adapter);
2147 goto done;
2148 }
2149
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002150 netxen_config_indev_addr(netdev, NETDEV_UP);
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002151 }
2152
2153 netif_device_attach(netdev);
2154
2155done:
2156 adapter->fw_fail_cnt = 0;
2157 clear_bit(__NX_RESETTING, &adapter->state);
2158 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
2159}
2160
2161static void
2162netxen_fwinit_work(struct work_struct *work)
2163{
2164 struct netxen_adapter *adapter = container_of(work,
2165 struct netxen_adapter, fw_work.work);
2166 int dev_state;
2167
2168 dev_state = NXRD32(adapter, NX_CRB_DEV_STATE);
2169
2170 switch (dev_state) {
2171 case NX_DEV_COLD:
2172 case NX_DEV_READY:
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002173 if (!netxen_start_firmware(adapter)) {
2174 netxen_schedule_work(adapter, netxen_attach_work, 0);
2175 return;
2176 }
2177 break;
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002178
2179 case NX_DEV_INITALIZING:
2180 if (++adapter->fw_wait_cnt < FW_POLL_THRESH) {
2181 netxen_schedule_work(adapter,
2182 netxen_fwinit_work, 2 * FW_POLL_DELAY);
2183 return;
2184 }
2185 break;
2186
2187 case NX_DEV_FAILED:
2188 default:
2189 break;
2190 }
2191
2192 nx_incr_dev_ref_cnt(adapter);
2193 clear_bit(__NX_RESETTING, &adapter->state);
2194}
2195
2196static void
2197netxen_detach_work(struct work_struct *work)
2198{
2199 struct netxen_adapter *adapter = container_of(work,
2200 struct netxen_adapter, fw_work.work);
2201 struct net_device *netdev = adapter->netdev;
2202 int ref_cnt, delay;
2203 u32 status;
2204
2205 netif_device_detach(netdev);
2206
2207 if (netif_running(netdev))
2208 netxen_nic_down(adapter, netdev);
2209
2210 netxen_nic_detach(adapter);
2211
2212 status = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1);
2213
2214 ref_cnt = nx_decr_dev_ref_cnt(adapter);
2215
2216 if (status & NX_RCODE_FATAL_ERROR)
2217 return;
2218
2219 if (adapter->temp == NX_TEMP_PANIC)
2220 return;
2221
2222 delay = (ref_cnt == 0) ? 0 : (2 * FW_POLL_DELAY);
2223
2224 adapter->fw_wait_cnt = 0;
2225 netxen_schedule_work(adapter, netxen_fwinit_work, delay);
2226}
2227
2228static int
2229netxen_check_health(struct netxen_adapter *adapter)
2230{
2231 u32 state, heartbit;
2232 struct net_device *netdev = adapter->netdev;
2233
2234 if (netxen_nic_check_temp(adapter))
2235 goto detach;
2236
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00002237 if (adapter->need_fw_reset) {
2238 nx_dev_request_reset(adapter);
2239 goto detach;
2240 }
2241
Dhananjay Phadke6a581e92009-09-05 17:43:08 +00002242 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2243 if (state == NX_DEV_NEED_RESET)
2244 goto detach;
2245
2246 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2247 return 0;
2248
2249 heartbit = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER);
2250 if (heartbit != adapter->heartbit) {
2251 adapter->heartbit = heartbit;
2252 adapter->fw_fail_cnt = 0;
2253 return 0;
2254 }
2255
2256 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2257 return 0;
2258
2259 clear_bit(__NX_FW_ATTACHED, &adapter->state);
2260
2261 dev_info(&netdev->dev, "firmware hang detected\n");
2262
2263detach:
2264 if (!test_and_set_bit(__NX_RESETTING, &adapter->state))
2265 netxen_schedule_work(adapter, netxen_detach_work, 0);
2266 return 1;
2267}
2268
2269static void
2270netxen_fw_poll_work(struct work_struct *work)
2271{
2272 struct netxen_adapter *adapter = container_of(work,
2273 struct netxen_adapter, fw_work.work);
2274
2275 if (test_bit(__NX_RESETTING, &adapter->state))
2276 goto reschedule;
2277
2278 if (test_bit(__NX_DEV_UP, &adapter->state)) {
2279 if (!adapter->has_link_events) {
2280
2281 netxen_nic_handle_phy_intr(adapter);
2282
2283 if (adapter->link_changed)
2284 netxen_nic_set_link_parameters(adapter);
2285 }
2286 }
2287
2288 if (netxen_check_health(adapter))
2289 return;
2290
2291reschedule:
2292 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
2293}
2294
Narender Kumarfa3ce352009-08-24 19:23:28 +00002295static ssize_t
2296netxen_store_bridged_mode(struct device *dev,
2297 struct device_attribute *attr, const char *buf, size_t len)
2298{
2299 struct net_device *net = to_net_dev(dev);
2300 struct netxen_adapter *adapter = netdev_priv(net);
2301 unsigned long new;
2302 int ret = -EINVAL;
2303
2304 if (!(adapter->capabilities & NX_FW_CAPABILITY_BDG))
2305 goto err_out;
2306
2307 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2308 goto err_out;
2309
2310 if (strict_strtoul(buf, 2, &new))
2311 goto err_out;
2312
2313 if (!netxen_config_bridged_mode(adapter, !!new))
2314 ret = len;
2315
2316err_out:
2317 return ret;
2318}
2319
2320static ssize_t
2321netxen_show_bridged_mode(struct device *dev,
2322 struct device_attribute *attr, char *buf)
2323{
2324 struct net_device *net = to_net_dev(dev);
2325 struct netxen_adapter *adapter;
2326 int bridged_mode = 0;
2327
2328 adapter = netdev_priv(net);
2329
2330 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2331 bridged_mode = !!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED);
2332
2333 return sprintf(buf, "%d\n", bridged_mode);
2334}
2335
2336static struct device_attribute dev_attr_bridged_mode = {
2337 .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
2338 .show = netxen_show_bridged_mode,
2339 .store = netxen_store_bridged_mode,
2340};
2341
2342static void
2343netxen_create_sysfs_entries(struct netxen_adapter *adapter)
2344{
2345 struct net_device *netdev = adapter->netdev;
2346 struct device *dev = &netdev->dev;
2347
2348 if (adapter->capabilities & NX_FW_CAPABILITY_BDG) {
2349 /* bridged_mode control */
2350 if (device_create_file(dev, &dev_attr_bridged_mode)) {
2351 dev_warn(&netdev->dev,
2352 "failed to create bridged_mode sysfs entry\n");
2353 }
2354 }
2355}
2356
2357static void
2358netxen_remove_sysfs_entries(struct netxen_adapter *adapter)
2359{
2360 struct net_device *netdev = adapter->netdev;
2361 struct device *dev = &netdev->dev;
2362
2363 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2364 device_remove_file(dev, &dev_attr_bridged_mode);
2365}
2366
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002367#ifdef CONFIG_INET
2368
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002369#define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2370
2371static int
2372netxen_destip_supported(struct netxen_adapter *adapter)
2373{
2374 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2375 return 0;
2376
2377 if (adapter->ahw.cut_through)
2378 return 0;
2379
2380 return 1;
2381}
2382
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002383static void
2384netxen_config_indev_addr(struct net_device *dev, unsigned long event)
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002385{
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002386 struct in_device *indev;
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002387 struct netxen_adapter *adapter = netdev_priv(dev);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002388
Amit Kumar Salecha3db76752009-09-09 18:12:37 -07002389 if (!netxen_destip_supported(adapter))
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002390 return;
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002391
2392 indev = in_dev_get(dev);
2393 if (!indev)
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002394 return;
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002395
2396 for_ifa(indev) {
2397 switch (event) {
2398 case NETDEV_UP:
2399 netxen_config_ipaddr(adapter,
2400 ifa->ifa_address, NX_IP_UP);
2401 break;
2402 case NETDEV_DOWN:
2403 netxen_config_ipaddr(adapter,
2404 ifa->ifa_address, NX_IP_DOWN);
2405 break;
2406 default:
2407 break;
2408 }
2409 } endfor_ifa(indev);
2410
2411 in_dev_put(indev);
Amit Kumar Salechad0725e42009-09-05 17:43:09 +00002412 return;
2413}
2414
2415static int netxen_netdev_event(struct notifier_block *this,
2416 unsigned long event, void *ptr)
2417{
2418 struct netxen_adapter *adapter;
2419 struct net_device *dev = (struct net_device *)ptr;
2420
2421recheck:
2422 if (dev == NULL)
2423 goto done;
2424
2425 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2426 dev = vlan_dev_real_dev(dev);
2427 goto recheck;
2428 }
2429
2430 if (!is_netxen_netdev(dev))
2431 goto done;
2432
2433 adapter = netdev_priv(dev);
2434
2435 if (!adapter)
2436 goto done;
2437
2438 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2439 goto done;
2440
2441 netxen_config_indev_addr(dev, event);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002442done:
2443 return NOTIFY_DONE;
2444}
2445
2446static int
2447netxen_inetaddr_event(struct notifier_block *this,
2448 unsigned long event, void *ptr)
2449{
2450 struct netxen_adapter *adapter;
2451 struct net_device *dev;
2452
2453 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
2454
2455 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
2456
2457recheck:
2458 if (dev == NULL || !netif_running(dev))
2459 goto done;
2460
2461 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2462 dev = vlan_dev_real_dev(dev);
2463 goto recheck;
2464 }
2465
2466 if (!is_netxen_netdev(dev))
2467 goto done;
2468
2469 adapter = netdev_priv(dev);
2470
2471 if (!adapter || !netxen_destip_supported(adapter))
2472 goto done;
2473
2474 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2475 goto done;
2476
2477 switch (event) {
2478 case NETDEV_UP:
2479 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP);
2480 break;
2481 case NETDEV_DOWN:
2482 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN);
2483 break;
2484 default:
2485 break;
2486 }
2487
2488done:
2489 return NOTIFY_DONE;
2490}
2491
2492static struct notifier_block netxen_netdev_cb = {
2493 .notifier_call = netxen_netdev_event,
2494};
2495
2496static struct notifier_block netxen_inetaddr_cb = {
2497 .notifier_call = netxen_inetaddr_event,
2498};
Randy Dunlap9feae562009-09-11 12:41:04 +00002499#else
2500static void
2501netxen_config_indev_addr(struct net_device *dev, unsigned long event)
2502{ }
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002503#endif
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002504
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002505static struct pci_driver netxen_driver = {
2506 .name = netxen_nic_driver_name,
2507 .id_table = netxen_pci_tbl,
2508 .probe = netxen_nic_probe,
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002509 .remove = __devexit_p(netxen_nic_remove),
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002510#ifdef CONFIG_PM
Dhananjay Phadke0b72e652009-03-13 14:52:02 +00002511 .suspend = netxen_nic_suspend,
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00002512 .resume = netxen_nic_resume,
Dhananjay Phadke01542cd2009-06-22 20:26:20 +00002513#endif
Amit Kumar Salecha22b57942009-08-23 08:35:12 +00002514 .shutdown = netxen_nic_shutdown
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002515};
2516
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002517static int __init netxen_init_module(void)
2518{
Dhananjay Phadkeff4fbd42009-03-13 14:52:06 +00002519 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
2520
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002521#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002522 register_netdevice_notifier(&netxen_netdev_cb);
2523 register_inetaddr_notifier(&netxen_inetaddr_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002524#endif
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002525
Amit S. Kale184231b2007-01-22 06:52:53 -08002526 return pci_register_driver(&netxen_driver);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002527}
2528
2529module_init(netxen_init_module);
2530
2531static void __exit netxen_exit_module(void)
2532{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002533 pci_unregister_driver(&netxen_driver);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002534
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002535#ifdef CONFIG_INET
Dhananjay Phadke6598b162009-07-26 20:07:37 +00002536 unregister_inetaddr_notifier(&netxen_inetaddr_cb);
2537 unregister_netdevice_notifier(&netxen_netdev_cb);
Dhananjay Phadke044824d2009-07-28 09:10:03 +00002538#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -04002539}
2540
2541module_exit(netxen_exit_module);