blob: 80a66746051485016180ccfcd49a56002297f8cd [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
26#include <linux/netdevice.h>
27#include <linux/delay.h>
28#include "netxen_nic.h"
29#include "netxen_nic_hw.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040030
31struct crb_addr_pair {
Linsys Contractor Mithlesh Thukrale0e20a12007-02-28 05:16:40 -080032 u32 addr;
33 u32 data;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040034};
35
36#define NETXEN_MAX_CRB_XFORM 60
37static unsigned int crb_addr_xform[NETXEN_MAX_CRB_XFORM];
Linsys Contractor Mithlesh Thukrale0e20a12007-02-28 05:16:40 -080038#define NETXEN_ADDR_ERROR (0xffffffff)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040039
40#define crb_addr_transform(name) \
41 crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \
42 NETXEN_HW_CRB_HUB_AGT_ADR_##name << 20
43
Amit S. Kalecb8011a2006-11-29 09:00:10 -080044#define NETXEN_NIC_XDMA_RESET 0x8000ff
45
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +000046static void
Dhananjay Phadked8b100c2009-03-13 14:52:05 +000047netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter,
48 struct nx_host_rds_ring *rds_ring);
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +000049static int netxen_p3_has_mn(struct netxen_adapter *adapter);
Adrian Bunk993fb902007-11-05 18:07:31 +010050
Amit S. Kale3d396eb2006-10-21 15:33:03 -040051static void crb_addr_transform_setup(void)
52{
53 crb_addr_transform(XDMA);
54 crb_addr_transform(TIMR);
55 crb_addr_transform(SRE);
56 crb_addr_transform(SQN3);
57 crb_addr_transform(SQN2);
58 crb_addr_transform(SQN1);
59 crb_addr_transform(SQN0);
60 crb_addr_transform(SQS3);
61 crb_addr_transform(SQS2);
62 crb_addr_transform(SQS1);
63 crb_addr_transform(SQS0);
64 crb_addr_transform(RPMX7);
65 crb_addr_transform(RPMX6);
66 crb_addr_transform(RPMX5);
67 crb_addr_transform(RPMX4);
68 crb_addr_transform(RPMX3);
69 crb_addr_transform(RPMX2);
70 crb_addr_transform(RPMX1);
71 crb_addr_transform(RPMX0);
72 crb_addr_transform(ROMUSB);
73 crb_addr_transform(SN);
74 crb_addr_transform(QMN);
75 crb_addr_transform(QMS);
76 crb_addr_transform(PGNI);
77 crb_addr_transform(PGND);
78 crb_addr_transform(PGN3);
79 crb_addr_transform(PGN2);
80 crb_addr_transform(PGN1);
81 crb_addr_transform(PGN0);
82 crb_addr_transform(PGSI);
83 crb_addr_transform(PGSD);
84 crb_addr_transform(PGS3);
85 crb_addr_transform(PGS2);
86 crb_addr_transform(PGS1);
87 crb_addr_transform(PGS0);
88 crb_addr_transform(PS);
89 crb_addr_transform(PH);
90 crb_addr_transform(NIU);
91 crb_addr_transform(I2Q);
92 crb_addr_transform(EG);
93 crb_addr_transform(MN);
94 crb_addr_transform(MS);
95 crb_addr_transform(CAS2);
96 crb_addr_transform(CAS1);
97 crb_addr_transform(CAS0);
98 crb_addr_transform(CAM);
99 crb_addr_transform(C2C1);
100 crb_addr_transform(C2C0);
Amit S. Kale1fcca1a2007-02-05 07:35:26 -0800101 crb_addr_transform(SMB);
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700102 crb_addr_transform(OCM0);
103 crb_addr_transform(I2C0);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400104}
105
Dhananjay Phadke29566402008-07-21 19:44:04 -0700106void netxen_release_rx_buffers(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400107{
Dhananjay Phadke29566402008-07-21 19:44:04 -0700108 struct netxen_recv_context *recv_ctx;
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700109 struct nx_host_rds_ring *rds_ring;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700110 struct netxen_rx_buffer *rx_buf;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000111 int i, ring;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400112
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000113 recv_ctx = &adapter->recv_ctx;
114 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
115 rds_ring = &recv_ctx->rds_rings[ring];
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000116 for (i = 0; i < rds_ring->num_desc; ++i) {
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000117 rx_buf = &(rds_ring->rx_buf_arr[i]);
118 if (rx_buf->state == NETXEN_BUFFER_FREE)
119 continue;
120 pci_unmap_single(adapter->pdev,
121 rx_buf->dma,
122 rds_ring->dma_size,
123 PCI_DMA_FROMDEVICE);
124 if (rx_buf->skb != NULL)
125 dev_kfree_skb_any(rx_buf->skb);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700126 }
127 }
128}
129
130void netxen_release_tx_buffers(struct netxen_adapter *adapter)
131{
132 struct netxen_cmd_buffer *cmd_buf;
133 struct netxen_skb_frag *buffrag;
134 int i, j;
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000135 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700136
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000137 cmd_buf = tx_ring->cmd_buf_arr;
138 for (i = 0; i < tx_ring->num_desc; i++) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700139 buffrag = cmd_buf->frag_array;
140 if (buffrag->dma) {
141 pci_unmap_single(adapter->pdev, buffrag->dma,
142 buffrag->length, PCI_DMA_TODEVICE);
143 buffrag->dma = 0ULL;
144 }
145 for (j = 0; j < cmd_buf->frag_count; j++) {
146 buffrag++;
147 if (buffrag->dma) {
148 pci_unmap_page(adapter->pdev, buffrag->dma,
149 buffrag->length,
150 PCI_DMA_TODEVICE);
151 buffrag->dma = 0ULL;
152 }
153 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700154 if (cmd_buf->skb) {
155 dev_kfree_skb_any(cmd_buf->skb);
156 cmd_buf->skb = NULL;
157 }
158 cmd_buf++;
159 }
160}
161
162void netxen_free_sw_resources(struct netxen_adapter *adapter)
163{
164 struct netxen_recv_context *recv_ctx;
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700165 struct nx_host_rds_ring *rds_ring;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000166 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000167 int ring;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700168
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000169 recv_ctx = &adapter->recv_ctx;
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000170
171 if (recv_ctx->rds_rings == NULL)
172 goto skip_rds;
173
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000174 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
175 rds_ring = &recv_ctx->rds_rings[ring];
Figo.zhangf2333a02009-06-11 02:49:10 -0700176 vfree(rds_ring->rx_buf_arr);
177 rds_ring->rx_buf_arr = NULL;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700178 }
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000179 kfree(recv_ctx->rds_rings);
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000180
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000181skip_rds:
182 if (adapter->tx_ring == NULL)
183 return;
184
185 tx_ring = adapter->tx_ring;
Figo.zhangf2333a02009-06-11 02:49:10 -0700186 vfree(tx_ring->cmd_buf_arr);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700187}
188
189int netxen_alloc_sw_resources(struct netxen_adapter *adapter)
190{
191 struct netxen_recv_context *recv_ctx;
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700192 struct nx_host_rds_ring *rds_ring;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000193 struct nx_host_sds_ring *sds_ring;
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000194 struct nx_host_tx_ring *tx_ring;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700195 struct netxen_rx_buffer *rx_buf;
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000196 int ring, i, size;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700197
198 struct netxen_cmd_buffer *cmd_buf_arr;
199 struct net_device *netdev = adapter->netdev;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000200 struct pci_dev *pdev = adapter->pdev;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700201
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000202 size = sizeof(struct nx_host_tx_ring);
203 tx_ring = kzalloc(size, GFP_KERNEL);
204 if (tx_ring == NULL) {
205 dev_err(&pdev->dev, "%s: failed to allocate tx ring struct\n",
206 netdev->name);
207 return -ENOMEM;
208 }
209 adapter->tx_ring = tx_ring;
210
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000211 tx_ring->num_desc = adapter->num_txd;
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +0000212 tx_ring->txq = netdev_get_tx_queue(netdev, 0);
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000213
214 cmd_buf_arr = vmalloc(TX_BUFF_RINGSIZE(tx_ring));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700215 if (cmd_buf_arr == NULL) {
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000216 dev_err(&pdev->dev, "%s: failed to allocate cmd buffer ring\n",
Dhananjay Phadke29566402008-07-21 19:44:04 -0700217 netdev->name);
218 return -ENOMEM;
219 }
Dhananjay Phadked877f1e2009-04-07 22:50:40 +0000220 memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring));
221 tx_ring->cmd_buf_arr = cmd_buf_arr;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700222
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000223 recv_ctx = &adapter->recv_ctx;
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000224
225 size = adapter->max_rds_rings * sizeof (struct nx_host_rds_ring);
226 rds_ring = kzalloc(size, GFP_KERNEL);
227 if (rds_ring == NULL) {
228 dev_err(&pdev->dev, "%s: failed to allocate rds ring struct\n",
229 netdev->name);
230 return -ENOMEM;
231 }
232 recv_ctx->rds_rings = rds_ring;
233
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000234 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
235 rds_ring = &recv_ctx->rds_rings[ring];
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000236 switch (ring) {
237 case RCV_RING_NORMAL:
238 rds_ring->num_desc = adapter->num_rxd;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000239 if (adapter->ahw.cut_through) {
240 rds_ring->dma_size =
241 NX_CT_DEFAULT_RX_BUF_LEN;
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700242 rds_ring->skb_size =
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000243 NX_CT_DEFAULT_RX_BUF_LEN;
244 } else {
Dhananjay Phadke9b08beb2009-07-26 20:07:44 +0000245 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
246 rds_ring->dma_size =
247 NX_P3_RX_BUF_MAX_LEN;
248 else
249 rds_ring->dma_size =
250 NX_P2_RX_BUF_MAX_LEN;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000251 rds_ring->skb_size =
Dhananjay Phadke9b08beb2009-07-26 20:07:44 +0000252 rds_ring->dma_size + NET_IP_ALIGN;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000253 }
254 break;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700255
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000256 case RCV_RING_JUMBO:
257 rds_ring->num_desc = adapter->num_jumbo_rxd;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000258 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
259 rds_ring->dma_size =
260 NX_P3_RX_JUMBO_BUF_MAX_LEN;
261 else
262 rds_ring->dma_size =
263 NX_P2_RX_JUMBO_BUF_MAX_LEN;
Dhananjay Phadkebc75e5b2009-09-03 13:10:53 +0000264
265 if (adapter->capabilities & NX_CAP0_HW_LRO)
266 rds_ring->dma_size += NX_LRO_BUFFER_EXTRA;
267
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000268 rds_ring->skb_size =
269 rds_ring->dma_size + NET_IP_ALIGN;
270 break;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700271
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000272 case RCV_RING_LRO:
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000273 rds_ring->num_desc = adapter->num_lro_rxd;
Dhananjay Phadke9b08beb2009-07-26 20:07:44 +0000274 rds_ring->dma_size = NX_RX_LRO_BUFFER_LENGTH;
275 rds_ring->skb_size = rds_ring->dma_size + NET_IP_ALIGN;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000276 break;
277
278 }
279 rds_ring->rx_buf_arr = (struct netxen_rx_buffer *)
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000280 vmalloc(RCV_BUFF_RINGSIZE(rds_ring));
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000281 if (rds_ring->rx_buf_arr == NULL) {
282 printk(KERN_ERR "%s: Failed to allocate "
283 "rx buffer ring %d\n",
284 netdev->name, ring);
285 /* free whatever was already allocated */
286 goto err_out;
287 }
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000288 memset(rds_ring->rx_buf_arr, 0, RCV_BUFF_RINGSIZE(rds_ring));
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000289 INIT_LIST_HEAD(&rds_ring->free_list);
290 /*
291 * Now go through all of them, set reference handles
292 * and put them in the queues.
293 */
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000294 rx_buf = rds_ring->rx_buf_arr;
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +0000295 for (i = 0; i < rds_ring->num_desc; i++) {
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000296 list_add_tail(&rx_buf->list,
297 &rds_ring->free_list);
298 rx_buf->ref_handle = i;
299 rx_buf->state = NETXEN_BUFFER_FREE;
300 rx_buf++;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400301 }
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000302 spin_lock_init(&rds_ring->lock);
303 }
304
305 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
306 sds_ring = &recv_ctx->sds_rings[ring];
307 sds_ring->irq = adapter->msix_entries[ring].vector;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +0000308 sds_ring->adapter = adapter;
309 sds_ring->num_desc = adapter->num_rxd;
310
311 for (i = 0; i < NUM_RCV_DESC_RINGS; i++)
312 INIT_LIST_HEAD(&sds_ring->free_list[i]);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400313 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700314
315 return 0;
316
317err_out:
318 netxen_free_sw_resources(adapter);
319 return -ENOMEM;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400320}
321
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400322/*
323 * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB
324 * address to external PCI CRB address.
325 */
Adrian Bunk993fb902007-11-05 18:07:31 +0100326static u32 netxen_decode_crb_addr(u32 addr)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400327{
328 int i;
Linsys Contractor Mithlesh Thukrale0e20a12007-02-28 05:16:40 -0800329 u32 base_addr, offset, pci_base;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400330
331 crb_addr_transform_setup();
332
333 pci_base = NETXEN_ADDR_ERROR;
334 base_addr = addr & 0xfff00000;
335 offset = addr & 0x000fffff;
336
337 for (i = 0; i < NETXEN_MAX_CRB_XFORM; i++) {
338 if (crb_addr_xform[i] == base_addr) {
339 pci_base = i << 20;
340 break;
341 }
342 }
343 if (pci_base == NETXEN_ADDR_ERROR)
344 return pci_base;
345 else
346 return (pci_base + offset);
347}
348
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000349#define NETXEN_MAX_ROM_WAIT_USEC 100
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400350
Adrian Bunk993fb902007-11-05 18:07:31 +0100351static int netxen_wait_rom_done(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400352{
353 long timeout = 0;
354 long done = 0;
355
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800356 cond_resched();
357
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400358 while (done == 0) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000359 done = NXRD32(adapter, NETXEN_ROMUSB_GLB_STATUS);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400360 done &= 2;
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000361 if (++timeout >= NETXEN_MAX_ROM_WAIT_USEC) {
362 dev_err(&adapter->pdev->dev,
363 "Timeout reached waiting for rom done");
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400364 return -EIO;
365 }
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000366 udelay(1);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400367 }
368 return 0;
369}
370
Adrian Bunk993fb902007-11-05 18:07:31 +0100371static int do_rom_fast_read(struct netxen_adapter *adapter,
372 int addr, int *valp)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400373{
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000374 NXWR32(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr);
375 NXWR32(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0);
376 NXWR32(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3);
377 NXWR32(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, 0xb);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400378 if (netxen_wait_rom_done(adapter)) {
379 printk("Error waiting for rom done\n");
380 return -EIO;
381 }
382 /* reset abyte_cnt and dummy_byte_cnt */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000383 NXWR32(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800384 udelay(10);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000385 NXWR32(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400386
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000387 *valp = NXRD32(adapter, NETXEN_ROMUSB_ROM_RDATA);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400388 return 0;
389}
390
Adrian Bunk993fb902007-11-05 18:07:31 +0100391static int do_rom_fast_read_words(struct netxen_adapter *adapter, int addr,
392 u8 *bytes, size_t size)
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800393{
394 int addridx;
395 int ret = 0;
396
397 for (addridx = addr; addridx < (addr + size); addridx += 4) {
Al Virof305f782007-12-22 19:44:00 +0000398 int v;
399 ret = do_rom_fast_read(adapter, addridx, &v);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800400 if (ret != 0)
401 break;
Al Virof305f782007-12-22 19:44:00 +0000402 *(__le32 *)bytes = cpu_to_le32(v);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800403 bytes += 4;
404 }
405
406 return ret;
407}
408
409int
Jeff Garzik47906542007-11-23 21:23:36 -0500410netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr,
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800411 u8 *bytes, size_t size)
412{
413 int ret;
414
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000415 ret = netxen_rom_lock(adapter);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800416 if (ret < 0)
417 return ret;
418
419 ret = do_rom_fast_read_words(adapter, addr, bytes, size);
420
421 netxen_rom_unlock(adapter);
422 return ret;
423}
424
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400425int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp)
426{
427 int ret;
428
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000429 if (netxen_rom_lock(adapter) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400430 return -EIO;
431
432 ret = do_rom_fast_read(adapter, addr, valp);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800433 netxen_rom_unlock(adapter);
434 return ret;
435}
436
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400437#define NETXEN_BOARDTYPE 0x4008
438#define NETXEN_BOARDNUM 0x400c
439#define NETXEN_CHIPNUM 0x4010
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400440
Amit Kumar Salecha0be367b2009-10-16 15:50:08 +0000441int netxen_pinit_from_rom(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400442{
Dhananjay Phadkedcd56fd2008-06-15 22:59:45 -0700443 int addr, val;
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800444 int i, n, init_delay = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400445 struct crb_addr_pair *buf;
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800446 unsigned offset;
Linsys Contractor Mithlesh Thukrale0e20a12007-02-28 05:16:40 -0800447 u32 off;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400448
449 /* resetall */
Dhananjay Phadkec9517e52009-08-24 19:23:26 +0000450 netxen_rom_lock(adapter);
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000451 NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0xffffffff);
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800452 netxen_rom_unlock(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400453
Dhananjay Phadke29566402008-07-21 19:44:04 -0700454 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
455 if (netxen_rom_fast_read(adapter, 0, &n) != 0 ||
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800456 (n != 0xcafecafe) ||
Dhananjay Phadke29566402008-07-21 19:44:04 -0700457 netxen_rom_fast_read(adapter, 4, &n) != 0) {
458 printk(KERN_ERR "%s: ERROR Reading crb_init area: "
459 "n: %08x\n", netxen_nic_driver_name, n);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400460 return -EIO;
461 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700462 offset = n & 0xffffU;
463 n = (n >> 16) & 0xffffU;
464 } else {
465 if (netxen_rom_fast_read(adapter, 0, &n) != 0 ||
466 !(n & 0x80000000)) {
467 printk(KERN_ERR "%s: ERROR Reading crb_init area: "
468 "n: %08x\n", netxen_nic_driver_name, n);
469 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400470 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700471 offset = 1;
472 n &= ~0x80000000;
473 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400474
Amit Kumar Salecha0be367b2009-10-16 15:50:08 +0000475 if (n >= 1024) {
Dhananjay Phadke29566402008-07-21 19:44:04 -0700476 printk(KERN_ERR "%s:n=0x%x Error! NetXen card flash not"
477 " initialized.\n", __func__, n);
478 return -EIO;
479 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400480
Dhananjay Phadke29566402008-07-21 19:44:04 -0700481 buf = kcalloc(n, sizeof(struct crb_addr_pair), GFP_KERNEL);
482 if (buf == NULL) {
483 printk("%s: netxen_pinit_from_rom: Unable to calloc memory.\n",
484 netxen_nic_driver_name);
485 return -ENOMEM;
486 }
Amit Kumar Salecha0be367b2009-10-16 15:50:08 +0000487
Dhananjay Phadke29566402008-07-21 19:44:04 -0700488 for (i = 0; i < n; i++) {
489 if (netxen_rom_fast_read(adapter, 8*i + 4*offset, &val) != 0 ||
Daniel Marjamäki584dbe92009-01-29 08:55:56 +0000490 netxen_rom_fast_read(adapter, 8*i + 4*offset + 4, &addr) != 0) {
491 kfree(buf);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700492 return -EIO;
Daniel Marjamäki584dbe92009-01-29 08:55:56 +0000493 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400494
Dhananjay Phadke29566402008-07-21 19:44:04 -0700495 buf[i].addr = addr;
496 buf[i].data = val;
497
Dhananjay Phadke29566402008-07-21 19:44:04 -0700498 }
Amit Kumar Salecha0be367b2009-10-16 15:50:08 +0000499
Dhananjay Phadke29566402008-07-21 19:44:04 -0700500 for (i = 0; i < n; i++) {
501
502 off = netxen_decode_crb_addr(buf[i].addr);
503 if (off == NETXEN_ADDR_ERROR) {
504 printk(KERN_ERR"CRB init value out of range %x\n",
Amit S. Kale1fcca1a2007-02-05 07:35:26 -0800505 buf[i].addr);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700506 continue;
507 }
508 off += NETXEN_PCI_CRBSPACE;
Amit Kumar Salecha0be367b2009-10-16 15:50:08 +0000509
510 if (off & 1)
511 continue;
512
Dhananjay Phadke29566402008-07-21 19:44:04 -0700513 /* skipping cold reboot MAGIC */
514 if (off == NETXEN_CAM_RAM(0x1fc))
515 continue;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400516
Dhananjay Phadke29566402008-07-21 19:44:04 -0700517 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
Dhananjay Phadke8bee0a92009-10-21 19:39:01 +0000518 if (off == (NETXEN_CRB_I2C0 + 0x1c))
519 continue;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700520 /* do not reset PCI */
521 if (off == (ROMUSB_GLB + 0xbc))
522 continue;
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800523 if (off == (ROMUSB_GLB + 0xa8))
524 continue;
525 if (off == (ROMUSB_GLB + 0xc8)) /* core clock */
526 continue;
527 if (off == (ROMUSB_GLB + 0x24)) /* MN clock */
528 continue;
529 if (off == (ROMUSB_GLB + 0x1c)) /* MS clock */
530 continue;
Amit Kumar Salechae7473f12009-11-29 21:54:55 -0800531 if ((off & 0x0ff00000) == NETXEN_CRB_DDR_NET)
532 continue;
Amit Kumar Salecha0be367b2009-10-16 15:50:08 +0000533 if (off == (NETXEN_CRB_PEG_NET_1 + 0x18) &&
534 !NX_IS_REVISION_P3P(adapter->ahw.revision_id))
Dhananjay Phadke29566402008-07-21 19:44:04 -0700535 buf[i].data = 0x1020;
536 /* skip the function enable register */
537 if (off == NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION))
538 continue;
539 if (off == NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION2))
540 continue;
541 if ((off & 0x0ff00000) == NETXEN_CRB_SMB)
542 continue;
543 }
544
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800545 init_delay = 1;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700546 /* After writing this register, HW needs time for CRB */
547 /* to quiet down (else crb_window returns 0xffffffff) */
548 if (off == NETXEN_ROMUSB_GLB_SW_RESET) {
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800549 init_delay = 1000;
Dhananjay Phadke29566402008-07-21 19:44:04 -0700550 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400551 /* hold xdma in reset also */
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800552 buf[i].data = NETXEN_NIC_XDMA_RESET;
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800553 buf[i].data = 0x8000ff;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400554 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400555 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400556
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000557 NXWR32(adapter, off, buf[i].data);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400558
Dhananjay Phadke27c915a2009-01-14 20:49:00 -0800559 msleep(init_delay);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400560 }
Dhananjay Phadke29566402008-07-21 19:44:04 -0700561 kfree(buf);
562
563 /* disable_peg_cache_all */
564
565 /* unreset_net_cache */
566 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000567 val = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET);
568 NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, (val & 0xffffff0f));
Dhananjay Phadke29566402008-07-21 19:44:04 -0700569 }
570
571 /* p2dn replyCount */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000572 NXWR32(adapter, NETXEN_CRB_PEG_NET_D + 0xec, 0x1e);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700573 /* disable_peg_cache 0 */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000574 NXWR32(adapter, NETXEN_CRB_PEG_NET_D + 0x4c, 8);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700575 /* disable_peg_cache 1 */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000576 NXWR32(adapter, NETXEN_CRB_PEG_NET_I + 0x4c, 8);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700577
578 /* peg_clr_all */
579
580 /* peg_clr 0 */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000581 NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0x8, 0);
582 NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0xc, 0);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700583 /* peg_clr 1 */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000584 NXWR32(adapter, NETXEN_CRB_PEG_NET_1 + 0x8, 0);
585 NXWR32(adapter, NETXEN_CRB_PEG_NET_1 + 0xc, 0);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700586 /* peg_clr 2 */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000587 NXWR32(adapter, NETXEN_CRB_PEG_NET_2 + 0x8, 0);
588 NXWR32(adapter, NETXEN_CRB_PEG_NET_2 + 0xc, 0);
Dhananjay Phadke29566402008-07-21 19:44:04 -0700589 /* peg_clr 3 */
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +0000590 NXWR32(adapter, NETXEN_CRB_PEG_NET_3 + 0x8, 0);
591 NXWR32(adapter, NETXEN_CRB_PEG_NET_3 + 0xc, 0);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400592 return 0;
593}
594
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000595static struct uni_table_desc *nx_get_table_desc(const u8 *unirom, int section)
596{
597 uint32_t i;
598 struct uni_table_desc *directory = (struct uni_table_desc *) &unirom[0];
599 __le32 entries = cpu_to_le32(directory->num_entries);
600
601 for (i = 0; i < entries; i++) {
602
603 __le32 offs = cpu_to_le32(directory->findex) +
604 (i * cpu_to_le32(directory->entry_size));
605 __le32 tab_type = cpu_to_le32(*((u32 *)&unirom[offs] + 8));
606
607 if (tab_type == section)
608 return (struct uni_table_desc *) &unirom[offs];
609 }
610
611 return NULL;
612}
613
614static int
615nx_set_product_offs(struct netxen_adapter *adapter)
616{
617 struct uni_table_desc *ptab_descr;
618 const u8 *unirom = adapter->fw->data;
619 uint32_t i;
620 __le32 entries;
621
622 ptab_descr = nx_get_table_desc(unirom, NX_UNI_DIR_SECT_PRODUCT_TBL);
623 if (ptab_descr == NULL)
624 return -1;
625
626 entries = cpu_to_le32(ptab_descr->num_entries);
627
628 for (i = 0; i < entries; i++) {
629
630 __le32 flags, file_chiprev, offs;
631 u8 chiprev = adapter->ahw.revision_id;
632 int mn_present = netxen_p3_has_mn(adapter);
633 uint32_t flagbit;
634
635 offs = cpu_to_le32(ptab_descr->findex) +
636 (i * cpu_to_le32(ptab_descr->entry_size));
637 flags = cpu_to_le32(*((int *)&unirom[offs] + NX_UNI_FLAGS_OFF));
638 file_chiprev = cpu_to_le32(*((int *)&unirom[offs] +
639 NX_UNI_CHIP_REV_OFF));
640
641 flagbit = mn_present ? 1 : 2;
642
643 if ((chiprev == file_chiprev) &&
644 ((1ULL << flagbit) & flags)) {
645 adapter->file_prd_off = offs;
646 return 0;
647 }
648 }
649
650 return -1;
651}
652
653
654static struct uni_data_desc *nx_get_data_desc(struct netxen_adapter *adapter,
655 u32 section, u32 idx_offset)
656{
657 const u8 *unirom = adapter->fw->data;
658 int idx = cpu_to_le32(*((int *)&unirom[adapter->file_prd_off] +
659 idx_offset));
660 struct uni_table_desc *tab_desc;
661 __le32 offs;
662
663 tab_desc = nx_get_table_desc(unirom, section);
664
665 if (tab_desc == NULL)
666 return NULL;
667
668 offs = cpu_to_le32(tab_desc->findex) +
669 (cpu_to_le32(tab_desc->entry_size) * idx);
670
671 return (struct uni_data_desc *)&unirom[offs];
672}
673
674static u8 *
675nx_get_bootld_offs(struct netxen_adapter *adapter)
676{
677 u32 offs = NETXEN_BOOTLD_START;
678
679 if (adapter->fw_type == NX_UNIFIED_ROMIMAGE)
680 offs = cpu_to_le32((nx_get_data_desc(adapter,
681 NX_UNI_DIR_SECT_BOOTLD,
682 NX_UNI_BOOTLD_IDX_OFF))->findex);
683
684 return (u8 *)&adapter->fw->data[offs];
685}
686
687static u8 *
688nx_get_fw_offs(struct netxen_adapter *adapter)
689{
690 u32 offs = NETXEN_IMAGE_START;
691
692 if (adapter->fw_type == NX_UNIFIED_ROMIMAGE)
693 offs = cpu_to_le32((nx_get_data_desc(adapter,
694 NX_UNI_DIR_SECT_FW,
695 NX_UNI_FIRMWARE_IDX_OFF))->findex);
696
697 return (u8 *)&adapter->fw->data[offs];
698}
699
700static __le32
701nx_get_fw_size(struct netxen_adapter *adapter)
702{
703 if (adapter->fw_type == NX_UNIFIED_ROMIMAGE)
704 return cpu_to_le32((nx_get_data_desc(adapter,
705 NX_UNI_DIR_SECT_FW,
706 NX_UNI_FIRMWARE_IDX_OFF))->size);
707 else
708 return cpu_to_le32(
709 *(u32 *)&adapter->fw->data[NX_FW_SIZE_OFFSET]);
710}
711
712static __le32
713nx_get_fw_version(struct netxen_adapter *adapter)
714{
715 struct uni_data_desc *fw_data_desc;
716 const struct firmware *fw = adapter->fw;
717 __le32 major, minor, sub;
718 const u8 *ver_str;
719 int i, ret = 0;
720
721 if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) {
722
723 fw_data_desc = nx_get_data_desc(adapter,
724 NX_UNI_DIR_SECT_FW, NX_UNI_FIRMWARE_IDX_OFF);
725 ver_str = fw->data + cpu_to_le32(fw_data_desc->findex) +
726 cpu_to_le32(fw_data_desc->size) - 17;
727
728 for (i = 0; i < 12; i++) {
729 if (!strncmp(&ver_str[i], "REV=", 4)) {
730 ret = sscanf(&ver_str[i+4], "%u.%u.%u ",
731 &major, &minor, &sub);
732 break;
733 }
734 }
735
736 if (ret != 3)
737 return 0;
738
739 return major + (minor << 8) + (sub << 16);
740
741 } else
742 return cpu_to_le32(*(u32 *)&fw->data[NX_FW_VERSION_OFFSET]);
743}
744
745static __le32
746nx_get_bios_version(struct netxen_adapter *adapter)
747{
748 const struct firmware *fw = adapter->fw;
749 __le32 bios_ver, prd_off = adapter->file_prd_off;
750
751 if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) {
752 bios_ver = cpu_to_le32(*((u32 *) (&fw->data[prd_off])
753 + NX_UNI_BIOS_VERSION_OFF));
754 return (bios_ver << 24) + ((bios_ver >> 8) & 0xff00) +
755 (bios_ver >> 24);
756 } else
757 return cpu_to_le32(*(u32 *)&fw->data[NX_BIOS_VERSION_OFFSET]);
758
759}
760
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000761int
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000762netxen_need_fw_reset(struct netxen_adapter *adapter)
763{
764 u32 count, old_count;
765 u32 val, version, major, minor, build;
766 int i, timeout;
767 u8 fw_type;
768
769 /* NX2031 firmware doesn't support heartbit */
770 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
771 return 1;
772
773 /* last attempt had failed */
774 if (NXRD32(adapter, CRB_CMDPEG_STATE) == PHAN_INITIALIZE_FAILED)
775 return 1;
776
777 old_count = count = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER);
778
779 for (i = 0; i < 10; i++) {
780
781 timeout = msleep_interruptible(200);
782 if (timeout) {
783 NXWR32(adapter, CRB_CMDPEG_STATE,
784 PHAN_INITIALIZE_FAILED);
785 return -EINTR;
786 }
787
788 count = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER);
789 if (count != old_count)
790 break;
791 }
792
793 /* firmware is dead */
794 if (count == old_count)
795 return 1;
796
797 /* check if we have got newer or different file firmware */
798 if (adapter->fw) {
799
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000800 val = nx_get_fw_version(adapter);
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000801
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000802 version = NETXEN_DECODE_VERSION(val);
803
804 major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
805 minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
806 build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
807
808 if (version > NETXEN_VERSION_CODE(major, minor, build))
809 return 1;
810
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000811 if (version == NETXEN_VERSION_CODE(major, minor, build) &&
812 adapter->fw_type != NX_UNIFIED_ROMIMAGE) {
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000813
814 val = NXRD32(adapter, NETXEN_MIU_MN_CONTROL);
815 fw_type = (val & 0x4) ?
816 NX_P3_CT_ROMIMAGE : NX_P3_MN_ROMIMAGE;
817
818 if (adapter->fw_type != fw_type)
819 return 1;
820 }
821 }
822
823 return 0;
824}
825
826static char *fw_name[] = {
Dhananjay Phadke7e8e5d92009-10-24 16:04:02 +0000827 NX_P2_MN_ROMIMAGE_NAME,
828 NX_P3_CT_ROMIMAGE_NAME,
829 NX_P3_MN_ROMIMAGE_NAME,
830 NX_UNIFIED_ROMIMAGE_NAME,
831 NX_FLASH_ROMIMAGE_NAME,
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000832};
833
834int
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000835netxen_load_firmware(struct netxen_adapter *adapter)
836{
837 u64 *ptr64;
838 u32 i, flashaddr, size;
839 const struct firmware *fw = adapter->fw;
Dhananjay Phadke67c38fc2009-07-01 11:41:43 +0000840 struct pci_dev *pdev = adapter->pdev;
841
842 dev_info(&pdev->dev, "loading firmware from %s\n",
843 fw_name[adapter->fw_type]);
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000844
845 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
846 NXWR32(adapter, NETXEN_ROMUSB_GLB_CAS_RST, 1);
847
848 if (fw) {
849 __le64 data;
850
851 size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 8;
852
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000853 ptr64 = (u64 *)nx_get_bootld_offs(adapter);
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000854 flashaddr = NETXEN_BOOTLD_START;
855
856 for (i = 0; i < size; i++) {
857 data = cpu_to_le64(ptr64[i]);
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000858
859 if (adapter->pci_mem_write(adapter, flashaddr, data))
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +0000860 return -EIO;
861
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000862 flashaddr += 8;
863 }
864
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000865 size = (__force u32)nx_get_fw_size(adapter) / 8;
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000866
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000867 ptr64 = (u64 *)nx_get_fw_offs(adapter);
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000868 flashaddr = NETXEN_IMAGE_START;
869
870 for (i = 0; i < size; i++) {
871 data = cpu_to_le64(ptr64[i]);
872
873 if (adapter->pci_mem_write(adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +0000874 flashaddr, data))
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000875 return -EIO;
876
877 flashaddr += 8;
878 }
879 } else {
Amit Kumar Salechaf78c0852009-09-11 11:28:11 +0000880 u64 data;
881 u32 hi, lo;
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000882
Amit Kumar Salechaf78c0852009-09-11 11:28:11 +0000883 size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 8;
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000884 flashaddr = NETXEN_BOOTLD_START;
885
886 for (i = 0; i < size; i++) {
887 if (netxen_rom_fast_read(adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +0000888 flashaddr, (int *)&lo) != 0)
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000889 return -EIO;
Amit Kumar Salechaf78c0852009-09-11 11:28:11 +0000890 if (netxen_rom_fast_read(adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +0000891 flashaddr + 4, (int *)&hi) != 0)
Amit Kumar Salechaf78c0852009-09-11 11:28:11 +0000892 return -EIO;
893
894 /* hi, lo are already in host endian byteorder */
895 data = (((u64)hi << 32) | lo);
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000896
897 if (adapter->pci_mem_write(adapter,
Amit Kumar Salecha1f5e0552009-10-13 05:31:41 +0000898 flashaddr, data))
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000899 return -EIO;
900
Amit Kumar Salechaf78c0852009-09-11 11:28:11 +0000901 flashaddr += 8;
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000902 }
903 }
904 msleep(1);
905
Amit Kumar Salecha0be367b2009-10-16 15:50:08 +0000906 if (NX_IS_REVISION_P3P(adapter->ahw.revision_id)) {
907 NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0x18, 0x1020);
908 NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0x80001e);
909 } else if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000910 NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0x80001d);
911 else {
912 NXWR32(adapter, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL, 0x3fff);
913 NXWR32(adapter, NETXEN_ROMUSB_GLB_CAS_RST, 0);
914 }
915
916 return 0;
917}
918
919static int
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000920netxen_validate_firmware(struct netxen_adapter *adapter)
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000921{
922 __le32 val;
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000923 u32 ver, min_ver, bios, min_size;
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000924 struct pci_dev *pdev = adapter->pdev;
925 const struct firmware *fw = adapter->fw;
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000926 u8 fw_type = adapter->fw_type;
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000927
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000928 if (fw_type == NX_UNIFIED_ROMIMAGE) {
929 if (nx_set_product_offs(adapter))
930 return -EINVAL;
931
932 min_size = NX_UNI_FW_MIN_SIZE;
933 } else {
934 val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_MAGIC_OFFSET]);
935 if ((__force u32)val != NETXEN_BDINFO_MAGIC)
936 return -EINVAL;
937
938 min_size = NX_FW_MIN_SIZE;
939 }
940
941 if (fw->size < min_size)
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000942 return -EINVAL;
943
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000944 val = nx_get_fw_version(adapter);
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000945
946 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
947 min_ver = NETXEN_VERSION_CODE(4, 0, 216);
948 else
949 min_ver = NETXEN_VERSION_CODE(3, 4, 216);
950
Dhananjay Phadke98e31bb2009-07-01 11:41:42 +0000951 ver = NETXEN_DECODE_VERSION(val);
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000952
Dhananjay Phadke98e31bb2009-07-01 11:41:42 +0000953 if ((_major(ver) > _NETXEN_NIC_LINUX_MAJOR) || (ver < min_ver)) {
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000954 dev_err(&pdev->dev,
955 "%s: firmware version %d.%d.%d unsupported\n",
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000956 fw_name[fw_type], _major(ver), _minor(ver), _build(ver));
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000957 return -EINVAL;
958 }
959
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000960 val = nx_get_bios_version(adapter);
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000961 netxen_rom_fast_read(adapter, NX_BIOS_VERSION_OFFSET, (int *)&bios);
962 if ((__force u32)val != bios) {
963 dev_err(&pdev->dev, "%s: firmware bios is incompatible\n",
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000964 fw_name[fw_type]);
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000965 return -EINVAL;
966 }
967
968 /* check if flashed firmware is newer */
969 if (netxen_rom_fast_read(adapter,
970 NX_FW_VERSION_OFFSET, (int *)&val))
971 return -EIO;
Dhananjay Phadke98e31bb2009-07-01 11:41:42 +0000972 val = NETXEN_DECODE_VERSION(val);
973 if (val > ver) {
974 dev_info(&pdev->dev, "%s: firmware is older than flash\n",
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000975 fw_name[fw_type]);
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000976 return -EINVAL;
Dhananjay Phadke98e31bb2009-07-01 11:41:42 +0000977 }
Dhananjay Phadkef7185c72009-04-28 15:29:11 +0000978
979 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
980 return 0;
981}
982
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +0000983static void
984nx_get_next_fwtype(struct netxen_adapter *adapter)
985{
986 u8 fw_type;
987
988 switch (adapter->fw_type) {
989 case NX_UNKNOWN_ROMIMAGE:
990 fw_type = NX_UNIFIED_ROMIMAGE;
991 break;
992
993 case NX_UNIFIED_ROMIMAGE:
994 if (NX_IS_REVISION_P3P(adapter->ahw.revision_id))
995 fw_type = NX_FLASH_ROMIMAGE;
996 else if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
997 fw_type = NX_P2_MN_ROMIMAGE;
998 else if (netxen_p3_has_mn(adapter))
999 fw_type = NX_P3_MN_ROMIMAGE;
1000 else
1001 fw_type = NX_P3_CT_ROMIMAGE;
1002 break;
1003
1004 case NX_P3_MN_ROMIMAGE:
1005 fw_type = NX_P3_CT_ROMIMAGE;
1006 break;
1007
1008 case NX_P2_MN_ROMIMAGE:
1009 case NX_P3_CT_ROMIMAGE:
1010 default:
1011 fw_type = NX_FLASH_ROMIMAGE;
1012 break;
1013 }
1014
1015 adapter->fw_type = fw_type;
1016}
1017
Dhananjay Phadke6598b162009-07-26 20:07:37 +00001018static int
1019netxen_p3_has_mn(struct netxen_adapter *adapter)
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001020{
1021 u32 capability, flashed_ver;
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001022 capability = 0;
1023
1024 netxen_rom_fast_read(adapter,
1025 NX_FW_VERSION_OFFSET, (int *)&flashed_ver);
Dhananjay Phadke98e31bb2009-07-01 11:41:42 +00001026 flashed_ver = NETXEN_DECODE_VERSION(flashed_ver);
1027
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001028 if (flashed_ver >= NETXEN_VERSION_CODE(4, 0, 220)) {
Dhananjay Phadke6598b162009-07-26 20:07:37 +00001029
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001030 capability = NXRD32(adapter, NX_PEG_TUNE_CAPABILITY);
Dhananjay Phadke6598b162009-07-26 20:07:37 +00001031 if (capability & NX_PEG_TUNE_MN_PRESENT)
1032 return 1;
1033 }
1034 return 0;
1035}
1036
1037void netxen_request_firmware(struct netxen_adapter *adapter)
1038{
Dhananjay Phadke6598b162009-07-26 20:07:37 +00001039 struct pci_dev *pdev = adapter->pdev;
1040 int rc = 0;
1041
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +00001042 adapter->fw_type = NX_UNKNOWN_ROMIMAGE;
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001043
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +00001044next:
1045 nx_get_next_fwtype(adapter);
Dhananjay Phadke7cecdca12009-10-16 15:50:10 +00001046
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +00001047 if (adapter->fw_type == NX_FLASH_ROMIMAGE) {
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001048 adapter->fw = NULL;
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +00001049 } else {
1050 rc = request_firmware(&adapter->fw,
1051 fw_name[adapter->fw_type], &pdev->dev);
1052 if (rc != 0)
1053 goto next;
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001054
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +00001055 rc = netxen_validate_firmware(adapter);
1056 if (rc != 0) {
1057 release_firmware(adapter->fw);
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001058 msleep(1);
Amit Kumar Salechaf50330f2009-10-24 16:03:58 +00001059 goto next;
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001060 }
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001061 }
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001062}
1063
1064
1065void
1066netxen_release_firmware(struct netxen_adapter *adapter)
1067{
1068 if (adapter->fw)
1069 release_firmware(adapter->fw);
Dhananjay Phadkedb4cfd82009-09-05 17:43:07 +00001070 adapter->fw = NULL;
Dhananjay Phadkef7185c72009-04-28 15:29:11 +00001071}
1072
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001073int netxen_init_dummy_dma(struct netxen_adapter *adapter)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001074{
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001075 u64 addr;
1076 u32 hi, lo;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001077
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001078 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
1079 return 0;
1080
1081 adapter->dummy_dma.addr = pci_alloc_consistent(adapter->pdev,
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001082 NETXEN_HOST_DUMMY_DMA_SIZE,
1083 &adapter->dummy_dma.phys_addr);
1084 if (adapter->dummy_dma.addr == NULL) {
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001085 dev_err(&adapter->pdev->dev,
1086 "ERROR: Could not allocate dummy DMA memory\n");
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001087 return -ENOMEM;
1088 }
1089
1090 addr = (uint64_t) adapter->dummy_dma.phys_addr;
1091 hi = (addr >> 32) & 0xffffffff;
1092 lo = addr & 0xffffffff;
1093
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001094 NXWR32(adapter, CRB_HOST_DUMMY_BUF_ADDR_HI, hi);
1095 NXWR32(adapter, CRB_HOST_DUMMY_BUF_ADDR_LO, lo);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001096
1097 return 0;
1098}
1099
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001100/*
1101 * NetXen DMA watchdog control:
1102 *
1103 * Bit 0 : enabled => R/O: 1 watchdog active, 0 inactive
1104 * Bit 1 : disable_request => 1 req disable dma watchdog
1105 * Bit 2 : enable_request => 1 req enable dma watchdog
1106 * Bit 3-31 : unused
1107 */
1108void netxen_free_dummy_dma(struct netxen_adapter *adapter)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001109{
Dhananjay Phadke15eef1e2008-08-08 00:08:42 -07001110 int i = 100;
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001111 u32 ctrl;
1112
1113 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
1114 return;
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001115
Dhananjay Phadke15eef1e2008-08-08 00:08:42 -07001116 if (!adapter->dummy_dma.addr)
1117 return;
1118
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001119 ctrl = NXRD32(adapter, NETXEN_DMA_WATCHDOG_CTRL);
1120 if ((ctrl & 0x1) != 0) {
1121 NXWR32(adapter, NETXEN_DMA_WATCHDOG_CTRL, (ctrl | 0x2));
1122
1123 while ((ctrl & 0x1) != 0) {
1124
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001125 msleep(50);
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001126
1127 ctrl = NXRD32(adapter, NETXEN_DMA_WATCHDOG_CTRL);
1128
1129 if (--i == 0)
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001130 break;
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001131 };
Dhananjay Phadke15eef1e2008-08-08 00:08:42 -07001132 }
Dhananjay Phadke439b4542008-06-15 22:59:46 -07001133
Dhananjay Phadke15eef1e2008-08-08 00:08:42 -07001134 if (i) {
1135 pci_free_consistent(adapter->pdev,
1136 NETXEN_HOST_DUMMY_DMA_SIZE,
1137 adapter->dummy_dma.addr,
1138 adapter->dummy_dma.phys_addr);
1139 adapter->dummy_dma.addr = NULL;
Dhananjay Phadke83ac51f2009-07-26 20:07:39 +00001140 } else
1141 dev_err(&adapter->pdev->dev, "dma_watchdog_shutdown failed\n");
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001142}
1143
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301144int netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001145{
1146 u32 val = 0;
Dhananjay Phadke29566402008-07-21 19:44:04 -07001147 int retries = 60;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001148
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +00001149 if (pegtune_val)
1150 return 0;
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301151
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +00001152 do {
1153 val = NXRD32(adapter, CRB_CMDPEG_STATE);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301154
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +00001155 switch (val) {
1156 case PHAN_INITIALIZE_COMPLETE:
1157 case PHAN_INITIALIZE_ACK:
1158 return 0;
1159 case PHAN_INITIALIZE_FAILED:
1160 goto out_err;
1161 default:
1162 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001163 }
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301164
Dhananjay Phadke96f2ebd2009-06-22 20:26:21 +00001165 msleep(500);
1166
1167 } while (--retries);
1168
1169 NXWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_FAILED);
1170
1171out_err:
1172 dev_warn(&adapter->pdev->dev, "firmware init failed\n");
1173 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001174}
1175
Dhananjay Phadke56a00782009-04-07 22:50:41 +00001176static int
1177netxen_receive_peg_ready(struct netxen_adapter *adapter)
Dhananjay Phadke29566402008-07-21 19:44:04 -07001178{
1179 u32 val = 0;
1180 int retries = 2000;
1181
1182 do {
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001183 val = NXRD32(adapter, CRB_RCVPEG_STATE);
Dhananjay Phadke29566402008-07-21 19:44:04 -07001184
1185 if (val == PHAN_PEG_RCV_INITIALIZED)
1186 return 0;
1187
1188 msleep(10);
1189
1190 } while (--retries);
1191
1192 if (!retries) {
1193 printk(KERN_ERR "Receive Peg initialization not "
1194 "complete, state: 0x%x.\n", val);
1195 return -EIO;
1196 }
1197
1198 return 0;
1199}
1200
Dhananjay Phadke56a00782009-04-07 22:50:41 +00001201int netxen_init_firmware(struct netxen_adapter *adapter)
1202{
1203 int err;
1204
1205 err = netxen_receive_peg_ready(adapter);
1206 if (err)
1207 return err;
1208
Dhananjay Phadkef98a9f62009-04-07 22:50:45 +00001209 NXWR32(adapter, CRB_NIC_CAPABILITIES_HOST, INTR_SCHEME_PERPORT);
1210 NXWR32(adapter, CRB_NIC_MSI_MODE_HOST, MSI_MODE_MULTIFUNC);
1211 NXWR32(adapter, CRB_MPORT_MODE, MPORT_MULTI_FUNCTION_MODE);
1212 NXWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_ACK);
Dhananjay Phadke56a00782009-04-07 22:50:41 +00001213
1214 return err;
1215}
1216
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001217static void
1218netxen_handle_linkevent(struct netxen_adapter *adapter, nx_fw_msg_t *msg)
1219{
1220 u32 cable_OUI;
1221 u16 cable_len;
1222 u16 link_speed;
1223 u8 link_status, module, duplex, autoneg;
1224 struct net_device *netdev = adapter->netdev;
1225
1226 adapter->has_link_events = 1;
1227
1228 cable_OUI = msg->body[1] & 0xffffffff;
1229 cable_len = (msg->body[1] >> 32) & 0xffff;
1230 link_speed = (msg->body[1] >> 48) & 0xffff;
1231
1232 link_status = msg->body[2] & 0xff;
1233 duplex = (msg->body[2] >> 16) & 0xff;
1234 autoneg = (msg->body[2] >> 24) & 0xff;
1235
1236 module = (msg->body[2] >> 8) & 0xff;
1237 if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE) {
1238 printk(KERN_INFO "%s: unsupported cable: OUI 0x%x, length %d\n",
1239 netdev->name, cable_OUI, cable_len);
1240 } else if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN) {
1241 printk(KERN_INFO "%s: unsupported cable length %d\n",
1242 netdev->name, cable_len);
1243 }
1244
1245 netxen_advert_link_change(adapter, link_status);
1246
1247 /* update link parameters */
1248 if (duplex == LINKEVENT_FULL_DUPLEX)
1249 adapter->link_duplex = DUPLEX_FULL;
1250 else
1251 adapter->link_duplex = DUPLEX_HALF;
1252 adapter->module_type = module;
1253 adapter->link_autoneg = autoneg;
1254 adapter->link_speed = link_speed;
1255}
1256
1257static void
1258netxen_handle_fw_message(int desc_cnt, int index,
1259 struct nx_host_sds_ring *sds_ring)
1260{
1261 nx_fw_msg_t msg;
1262 struct status_desc *desc;
1263 int i = 0, opcode;
1264
1265 while (desc_cnt > 0 && i < 8) {
1266 desc = &sds_ring->desc_head[index];
1267 msg.words[i++] = le64_to_cpu(desc->status_desc_data[0]);
1268 msg.words[i++] = le64_to_cpu(desc->status_desc_data[1]);
1269
1270 index = get_next_index(index, sds_ring->num_desc);
1271 desc_cnt--;
1272 }
1273
1274 opcode = netxen_get_nic_msg_opcode(msg.body[0]);
1275 switch (opcode) {
1276 case NX_NIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE:
1277 netxen_handle_linkevent(sds_ring->adapter, &msg);
1278 break;
1279 default:
1280 break;
1281 }
1282}
1283
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001284static int
1285netxen_alloc_rx_skb(struct netxen_adapter *adapter,
1286 struct nx_host_rds_ring *rds_ring,
1287 struct netxen_rx_buffer *buffer)
1288{
1289 struct sk_buff *skb;
1290 dma_addr_t dma;
1291 struct pci_dev *pdev = adapter->pdev;
1292
1293 buffer->skb = dev_alloc_skb(rds_ring->skb_size);
1294 if (!buffer->skb)
1295 return 1;
1296
1297 skb = buffer->skb;
1298
1299 if (!adapter->ahw.cut_through)
1300 skb_reserve(skb, 2);
1301
1302 dma = pci_map_single(pdev, skb->data,
1303 rds_ring->dma_size, PCI_DMA_FROMDEVICE);
1304
1305 if (pci_dma_mapping_error(pdev, dma)) {
1306 dev_kfree_skb_any(skb);
1307 buffer->skb = NULL;
1308 return 1;
1309 }
1310
1311 buffer->skb = skb;
1312 buffer->dma = dma;
1313 buffer->state = NETXEN_BUFFER_BUSY;
1314
1315 return 0;
1316}
1317
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001318static struct sk_buff *netxen_process_rxbuf(struct netxen_adapter *adapter,
1319 struct nx_host_rds_ring *rds_ring, u16 index, u16 cksum)
1320{
1321 struct netxen_rx_buffer *buffer;
1322 struct sk_buff *skb;
1323
1324 buffer = &rds_ring->rx_buf_arr[index];
1325
1326 pci_unmap_single(adapter->pdev, buffer->dma, rds_ring->dma_size,
1327 PCI_DMA_FROMDEVICE);
1328
1329 skb = buffer->skb;
1330 if (!skb)
1331 goto no_skb;
1332
1333 if (likely(adapter->rx_csum && cksum == STATUS_CKSUM_OK)) {
1334 adapter->stats.csummed++;
1335 skb->ip_summed = CHECKSUM_UNNECESSARY;
1336 } else
1337 skb->ip_summed = CHECKSUM_NONE;
1338
1339 skb->dev = adapter->netdev;
1340
1341 buffer->skb = NULL;
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001342no_skb:
1343 buffer->state = NETXEN_BUFFER_FREE;
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001344 return skb;
1345}
1346
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001347static struct netxen_rx_buffer *
Dhananjay Phadke9b3ef552009-03-13 14:52:04 +00001348netxen_process_rcv(struct netxen_adapter *adapter,
Dhananjay Phadkec1c00ab2009-08-05 07:34:09 +00001349 struct nx_host_sds_ring *sds_ring,
1350 int ring, u64 sts_data0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001351{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001352 struct net_device *netdev = adapter->netdev;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +00001353 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001354 struct netxen_rx_buffer *buffer;
1355 struct sk_buff *skb;
Dhananjay Phadkec1c00ab2009-08-05 07:34:09 +00001356 struct nx_host_rds_ring *rds_ring;
1357 int index, length, cksum, pkt_offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001358
Dhananjay Phadkec1c00ab2009-08-05 07:34:09 +00001359 if (unlikely(ring >= adapter->max_rds_rings))
1360 return NULL;
1361
1362 rds_ring = &recv_ctx->rds_rings[ring];
1363
1364 index = netxen_get_sts_refhandle(sts_data0);
1365 if (unlikely(index >= rds_ring->num_desc))
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001366 return NULL;
Dhananjay Phadke438627c2009-03-13 14:52:03 +00001367
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001368 buffer = &rds_ring->rx_buf_arr[index];
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001369
Dhananjay Phadkec1c00ab2009-08-05 07:34:09 +00001370 length = netxen_get_sts_totallength(sts_data0);
1371 cksum = netxen_get_sts_status(sts_data0);
1372 pkt_offset = netxen_get_sts_pkt_offset(sts_data0);
1373
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001374 skb = netxen_process_rxbuf(adapter, rds_ring, index, cksum);
1375 if (!skb)
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001376 return buffer;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001377
Dhananjay Phadke9b3ef552009-03-13 14:52:04 +00001378 if (length > rds_ring->skb_size)
1379 skb_put(skb, rds_ring->skb_size);
1380 else
1381 skb_put(skb, length);
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001382
Dhananjay Phadke9b3ef552009-03-13 14:52:04 +00001383
1384 if (pkt_offset)
1385 skb_pull(skb, pkt_offset);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001386
Dhananjay Phadkebc75e5b2009-09-03 13:10:53 +00001387 skb->truesize = skb->len + sizeof(struct sk_buff);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001388 skb->protocol = eth_type_trans(skb, netdev);
1389
Amit Kumar Salechaa92e9e62009-04-07 22:50:47 +00001390 napi_gro_receive(&sds_ring->napi, skb);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001391
Narender Kumar1bb482f2009-08-23 08:35:09 +00001392 adapter->stats.rx_pkts++;
Dhananjay Phadke0ddc1102009-03-09 08:50:52 +00001393 adapter->stats.rxbytes += length;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001394
1395 return buffer;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001396}
1397
Dhananjay Phadkec1c00ab2009-08-05 07:34:09 +00001398#define TCP_HDR_SIZE 20
1399#define TCP_TS_OPTION_SIZE 12
1400#define TCP_TS_HDR_SIZE (TCP_HDR_SIZE + TCP_TS_OPTION_SIZE)
1401
1402static struct netxen_rx_buffer *
1403netxen_process_lro(struct netxen_adapter *adapter,
1404 struct nx_host_sds_ring *sds_ring,
1405 int ring, u64 sts_data0, u64 sts_data1)
1406{
1407 struct net_device *netdev = adapter->netdev;
1408 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
1409 struct netxen_rx_buffer *buffer;
1410 struct sk_buff *skb;
1411 struct nx_host_rds_ring *rds_ring;
1412 struct iphdr *iph;
1413 struct tcphdr *th;
1414 bool push, timestamp;
1415 int l2_hdr_offset, l4_hdr_offset;
1416 int index;
1417 u16 lro_length, length, data_offset;
1418 u32 seq_number;
1419
1420 if (unlikely(ring > adapter->max_rds_rings))
1421 return NULL;
1422
1423 rds_ring = &recv_ctx->rds_rings[ring];
1424
1425 index = netxen_get_lro_sts_refhandle(sts_data0);
1426 if (unlikely(index > rds_ring->num_desc))
1427 return NULL;
1428
1429 buffer = &rds_ring->rx_buf_arr[index];
1430
1431 timestamp = netxen_get_lro_sts_timestamp(sts_data0);
1432 lro_length = netxen_get_lro_sts_length(sts_data0);
1433 l2_hdr_offset = netxen_get_lro_sts_l2_hdr_offset(sts_data0);
1434 l4_hdr_offset = netxen_get_lro_sts_l4_hdr_offset(sts_data0);
1435 push = netxen_get_lro_sts_push_flag(sts_data0);
1436 seq_number = netxen_get_lro_sts_seq_number(sts_data1);
1437
1438 skb = netxen_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
1439 if (!skb)
1440 return buffer;
1441
1442 if (timestamp)
1443 data_offset = l4_hdr_offset + TCP_TS_HDR_SIZE;
1444 else
1445 data_offset = l4_hdr_offset + TCP_HDR_SIZE;
1446
1447 skb_put(skb, lro_length + data_offset);
1448
Dhananjay Phadkebc75e5b2009-09-03 13:10:53 +00001449 skb->truesize = skb->len + sizeof(struct sk_buff) + skb_headroom(skb);
Dhananjay Phadkec1c00ab2009-08-05 07:34:09 +00001450
1451 skb_pull(skb, l2_hdr_offset);
1452 skb->protocol = eth_type_trans(skb, netdev);
1453
1454 iph = (struct iphdr *)skb->data;
1455 th = (struct tcphdr *)(skb->data + (iph->ihl << 2));
1456
1457 length = (iph->ihl << 2) + (th->doff << 2) + lro_length;
1458 iph->tot_len = htons(length);
1459 iph->check = 0;
1460 iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
1461 th->psh = push;
1462 th->seq = htonl(seq_number);
1463
Narender Kumar1bb482f2009-08-23 08:35:09 +00001464 length = skb->len;
1465
Dhananjay Phadkec1c00ab2009-08-05 07:34:09 +00001466 netif_receive_skb(skb);
1467
Narender Kumar1bb482f2009-08-23 08:35:09 +00001468 adapter->stats.lro_pkts++;
1469 adapter->stats.rxbytes += length;
1470
Dhananjay Phadkec1c00ab2009-08-05 07:34:09 +00001471 return buffer;
1472}
1473
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001474#define netxen_merge_rx_buffers(list, head) \
1475 do { list_splice_tail_init(list, head); } while (0);
1476
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +00001477int
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001478netxen_process_rcv_ring(struct nx_host_sds_ring *sds_ring, int max)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001479{
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001480 struct netxen_adapter *adapter = sds_ring->adapter;
1481
1482 struct list_head *cur;
1483
Dhananjay Phadke0ddc1102009-03-09 08:50:52 +00001484 struct status_desc *desc;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001485 struct netxen_rx_buffer *rxbuf;
1486
1487 u32 consumer = sds_ring->consumer;
1488
Dhananjay Phadke9b3ef552009-03-13 14:52:04 +00001489 int count = 0;
Dhananjay Phadkec1c00ab2009-08-05 07:34:09 +00001490 u64 sts_data0, sts_data1;
1491 int opcode, ring = 0, desc_cnt;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001492
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001493 while (count < max) {
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001494 desc = &sds_ring->desc_head[consumer];
Dhananjay Phadkec1c00ab2009-08-05 07:34:09 +00001495 sts_data0 = le64_to_cpu(desc->status_desc_data[0]);
Dhananjay Phadke0ddc1102009-03-09 08:50:52 +00001496
Dhananjay Phadkec1c00ab2009-08-05 07:34:09 +00001497 if (!(sts_data0 & STATUS_OWNER_HOST))
Dhananjay Phadke0ddc1102009-03-09 08:50:52 +00001498 break;
1499
Dhananjay Phadkec1c00ab2009-08-05 07:34:09 +00001500 desc_cnt = netxen_get_sts_desc_cnt(sts_data0);
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001501
Dhananjay Phadkec1c00ab2009-08-05 07:34:09 +00001502 opcode = netxen_get_sts_opcode(sts_data0);
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001503
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001504 switch (opcode) {
1505 case NETXEN_NIC_RXPKT_DESC:
1506 case NETXEN_OLD_RXPKT_DESC:
Dhananjay Phadke6598b162009-07-26 20:07:37 +00001507 case NETXEN_NIC_SYN_OFFLOAD:
Dhananjay Phadkec1c00ab2009-08-05 07:34:09 +00001508 ring = netxen_get_sts_type(sts_data0);
1509 rxbuf = netxen_process_rcv(adapter, sds_ring,
1510 ring, sts_data0);
1511 break;
1512 case NETXEN_NIC_LRO_DESC:
1513 ring = netxen_get_lro_sts_type(sts_data0);
1514 sts_data1 = le64_to_cpu(desc->status_desc_data[1]);
1515 rxbuf = netxen_process_lro(adapter, sds_ring,
1516 ring, sts_data0, sts_data1);
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001517 break;
1518 case NETXEN_NIC_RESPONSE_DESC:
1519 netxen_handle_fw_message(desc_cnt, consumer, sds_ring);
1520 default:
1521 goto skip;
1522 }
1523
1524 WARN_ON(desc_cnt > 1);
1525
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001526 if (rxbuf)
1527 list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]);
1528
Dhananjay Phadke3bf26ce2009-04-07 22:50:42 +00001529skip:
1530 for (; desc_cnt > 0; desc_cnt--) {
1531 desc = &sds_ring->desc_head[consumer];
1532 desc->status_desc_data[0] =
1533 cpu_to_le64(STATUS_OWNER_PHANTOM);
1534 consumer = get_next_index(consumer, sds_ring->num_desc);
1535 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001536 count++;
1537 }
Dhananjay Phadke0ddc1102009-03-09 08:50:52 +00001538
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001539 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1540 struct nx_host_rds_ring *rds_ring =
1541 &adapter->recv_ctx.rds_rings[ring];
1542
1543 if (!list_empty(&sds_ring->free_list[ring])) {
1544 list_for_each(cur, &sds_ring->free_list[ring]) {
1545 rxbuf = list_entry(cur,
1546 struct netxen_rx_buffer, list);
1547 netxen_alloc_rx_skb(adapter, rds_ring, rxbuf);
1548 }
1549 spin_lock(&rds_ring->lock);
1550 netxen_merge_rx_buffers(&sds_ring->free_list[ring],
1551 &rds_ring->free_list);
1552 spin_unlock(&rds_ring->lock);
1553 }
1554
1555 netxen_post_rx_buffers_nodb(adapter, rds_ring);
1556 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001557
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001558 if (count) {
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001559 sds_ring->consumer = consumer;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001560 NXWRIO(adapter, sds_ring->crb_sts_consumer, consumer);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001561 }
1562
1563 return count;
1564}
1565
1566/* Process Command status ring */
Dhananjay Phadke05aaa022008-03-17 19:59:49 -07001567int netxen_process_cmd_ring(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001568{
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001569 u32 sw_consumer, hw_consumer;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001570 int count = 0, i;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001571 struct netxen_cmd_buffer *buffer;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001572 struct pci_dev *pdev = adapter->pdev;
1573 struct net_device *netdev = adapter->netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001574 struct netxen_skb_frag *frag;
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001575 int done = 0;
Dhananjay Phadke4ea528a2009-04-28 15:29:10 +00001576 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001577
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001578 if (!spin_trylock(&adapter->tx_clean_lock))
1579 return 1;
1580
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001581 sw_consumer = tx_ring->sw_consumer;
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001582 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001583
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001584 while (sw_consumer != hw_consumer) {
1585 buffer = &tx_ring->cmd_buf_arr[sw_consumer];
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001586 if (buffer->skb) {
1587 frag = &buffer->frag_array[0];
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001588 pci_unmap_single(pdev, frag->dma, frag->length,
1589 PCI_DMA_TODEVICE);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301590 frag->dma = 0ULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001591 for (i = 1; i < buffer->frag_count; i++) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001592 frag++; /* Get the next frag */
1593 pci_unmap_page(pdev, frag->dma, frag->length,
1594 PCI_DMA_TODEVICE);
Dhananjay Phadke96acb6e2007-07-02 09:37:57 +05301595 frag->dma = 0ULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001596 }
1597
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001598 adapter->stats.xmitfinished++;
dhananjay@netxen.com53a01e02007-12-26 10:23:58 -08001599 dev_kfree_skb_any(buffer->skb);
1600 buffer->skb = NULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001601 }
1602
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001603 sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc);
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001604 if (++count >= MAX_STATUS_HANDLE)
1605 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001606 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001607
Dhananjay Phadke22527862009-05-05 19:05:06 +00001608 if (count && netif_running(netdev)) {
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001609 tx_ring->sw_consumer = sw_consumer;
1610
Dhananjay Phadkeba53e6b2008-03-17 19:59:50 -07001611 smp_mb();
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001612
Dhananjay Phadke22527862009-05-05 19:05:06 +00001613 if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) {
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001614 __netif_tx_lock(tx_ring->txq, smp_processor_id());
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001615 if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH) {
Dhananjay Phadkecb2107b2009-06-17 17:27:25 +00001616 netif_wake_queue(netdev);
Amit Kumar Salecha74c520d2009-09-11 11:28:14 +00001617 adapter->tx_timeo_cnt = 0;
1618 }
Dhananjay Phadkeb2af9cb2009-07-17 15:27:07 +00001619 __netif_tx_unlock(tx_ring->txq);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001620 }
1621 }
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001622 /*
1623 * If everything is freed up to consumer then check if the ring is full
1624 * If the ring is full then check if more needs to be freed and
1625 * schedule the call back again.
1626 *
1627 * This happens when there are 2 CPUs. One could be freeing and the
1628 * other filling it. If the ring is full when we get out of here and
1629 * the card has already interrupted the host then the host can miss the
1630 * interrupt.
1631 *
1632 * There is still a possible race condition and the host could miss an
1633 * interrupt. The card has to take care of this.
1634 */
Dhananjay Phadked877f1e2009-04-07 22:50:40 +00001635 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
1636 done = (sw_consumer == hw_consumer);
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001637 spin_unlock(&adapter->tx_clean_lock);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001638
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001639 return (done);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001640}
1641
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +00001642void
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001643netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ringid,
1644 struct nx_host_rds_ring *rds_ring)
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001645{
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001646 struct rcv_desc *pdesc;
1647 struct netxen_rx_buffer *buffer;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001648 int producer, count = 0;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001649 netxen_ctx_msg msg = 0;
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001650 struct list_head *head;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001651
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001652 producer = rds_ring->producer;
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001653
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001654 spin_lock(&rds_ring->lock);
1655 head = &rds_ring->free_list;
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001656 while (!list_empty(head)) {
1657
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001658 buffer = list_entry(head->next, struct netxen_rx_buffer, list);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001659
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001660 if (!buffer->skb) {
1661 if (netxen_alloc_rx_skb(adapter, rds_ring, buffer))
1662 break;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001663 }
1664
1665 count++;
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001666 list_del(&buffer->list);
1667
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001668 /* make a rcv descriptor */
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001669 pdesc = &rds_ring->desc_head[producer];
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001670 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
Amit S. Kaleed33ebe2006-12-18 05:53:59 -08001671 pdesc->reference_handle = cpu_to_le16(buffer->ref_handle);
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001672 pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001673
Dhananjay Phadke438627c2009-03-13 14:52:03 +00001674 producer = get_next_index(producer, rds_ring->num_desc);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001675 }
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001676 spin_unlock(&rds_ring->lock);
Dhananjay Phadke9b3ef552009-03-13 14:52:04 +00001677
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001678 if (count) {
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001679 rds_ring->producer = producer;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001680 NXWRIO(adapter, rds_ring->crb_rcv_producer,
Dhananjay Phadke438627c2009-03-13 14:52:03 +00001681 (producer-1) & (rds_ring->num_desc-1));
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001682
Dhananjay Phadke4f96b982009-07-26 20:07:42 +00001683 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001684 /*
1685 * Write a doorbell msg to tell phanmon of change in
1686 * receive ring producer
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001687 * Only for firmware version < 4.0.0
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001688 */
1689 netxen_set_msg_peg_id(msg, NETXEN_RCV_PEG_DB_ID);
1690 netxen_set_msg_privid(msg);
1691 netxen_set_msg_count(msg,
Dhananjay Phadke438627c2009-03-13 14:52:03 +00001692 ((producer - 1) &
1693 (rds_ring->num_desc - 1)));
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001694 netxen_set_msg_ctxid(msg, adapter->portnum);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001695 netxen_set_msg_opcode(msg, NETXEN_RCV_PRODUCER(ringid));
Dhananjay Phadkef03b0eb2009-10-13 05:31:44 +00001696 NXWRIO(adapter, DB_NORMALIZE(adapter,
1697 NETXEN_RCV_PRODUCER_OFFSET), msg);
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001698 }
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001699 }
1700}
1701
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +00001702static void
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001703netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter,
1704 struct nx_host_rds_ring *rds_ring)
Amit S. Kaleed25ffa2006-12-04 09:23:25 -08001705{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001706 struct rcv_desc *pdesc;
1707 struct netxen_rx_buffer *buffer;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001708 int producer, count = 0;
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001709 struct list_head *head;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001710
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001711 producer = rds_ring->producer;
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001712 if (!spin_trylock(&rds_ring->lock))
1713 return;
1714
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001715 head = &rds_ring->free_list;
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001716 while (!list_empty(head)) {
1717
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001718 buffer = list_entry(head->next, struct netxen_rx_buffer, list);
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001719
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001720 if (!buffer->skb) {
1721 if (netxen_alloc_rx_skb(adapter, rds_ring, buffer))
1722 break;
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001723 }
1724
1725 count++;
Dhananjay Phadked9e651b2008-07-21 19:44:08 -07001726 list_del(&buffer->list);
1727
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001728 /* make a rcv descriptor */
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001729 pdesc = &rds_ring->desc_head[producer];
Amit S. Kaleed33ebe2006-12-18 05:53:59 -08001730 pdesc->reference_handle = cpu_to_le16(buffer->ref_handle);
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001731 pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001732 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
Dhananjay Phadke6f703402009-01-14 20:50:00 -08001733
Dhananjay Phadke438627c2009-03-13 14:52:03 +00001734 producer = get_next_index(producer, rds_ring->num_desc);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001735 }
1736
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001737 if (count) {
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -07001738 rds_ring->producer = producer;
Amit Kumar Salecha195c5f92009-09-05 17:43:10 +00001739 NXWRIO(adapter, rds_ring->crb_rcv_producer,
Dhananjay Phadke438627c2009-03-13 14:52:03 +00001740 (producer - 1) & (rds_ring->num_desc - 1));
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001741 }
Dhananjay Phadked8b100c2009-03-13 14:52:05 +00001742 spin_unlock(&rds_ring->lock);
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001743}
1744
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001745void netxen_nic_clear_stats(struct netxen_adapter *adapter)
1746{
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001747 memset(&adapter->stats, 0, sizeof(adapter->stats));
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07001748 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001749}
1750