blob: ca9cf1a338035a1865d24892b29a5cd4a3836c3a [file] [log] [blame]
Ben Hutchings8e730c12009-11-29 15:14:45 +00001/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
Ben Hutchings906bb262009-11-29 15:16:19 +00004 * Copyright 2006-2009 Solarflare Communications Inc.
Ben Hutchings8e730c12009-11-29 15:14:45 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#include <linux/bitops.h>
12#include <linux/delay.h>
13#include <linux/pci.h>
14#include <linux/module.h>
15#include <linux/seq_file.h>
16#include "net_driver.h"
17#include "bitfield.h"
18#include "efx.h"
19#include "nic.h"
20#include "regs.h"
21#include "io.h"
22#include "workarounds.h"
23
24/**************************************************************************
25 *
26 * Configurable values
27 *
28 **************************************************************************
29 */
30
31/* This is set to 16 for a good reason. In summary, if larger than
32 * 16, the descriptor cache holds more than a default socket
33 * buffer's worth of packets (for UDP we can only have at most one
34 * socket buffer's worth outstanding). This combined with the fact
35 * that we only get 1 TX event per descriptor cache means the NIC
36 * goes idle.
37 */
38#define TX_DC_ENTRIES 16
39#define TX_DC_ENTRIES_ORDER 1
40
41#define RX_DC_ENTRIES 64
42#define RX_DC_ENTRIES_ORDER 3
43
44/* RX FIFO XOFF watermark
45 *
46 * When the amount of the RX FIFO increases used increases past this
47 * watermark send XOFF. Only used if RX flow control is enabled (ethtool -A)
48 * This also has an effect on RX/TX arbitration
49 */
50int efx_nic_rx_xoff_thresh = -1;
51module_param_named(rx_xoff_thresh_bytes, efx_nic_rx_xoff_thresh, int, 0644);
52MODULE_PARM_DESC(rx_xoff_thresh_bytes, "RX fifo XOFF threshold");
53
54/* RX FIFO XON watermark
55 *
56 * When the amount of the RX FIFO used decreases below this
57 * watermark send XON. Only used if TX flow control is enabled (ethtool -A)
58 * This also has an effect on RX/TX arbitration
59 */
60int efx_nic_rx_xon_thresh = -1;
61module_param_named(rx_xon_thresh_bytes, efx_nic_rx_xon_thresh, int, 0644);
62MODULE_PARM_DESC(rx_xon_thresh_bytes, "RX fifo XON threshold");
63
64/* If EFX_MAX_INT_ERRORS internal errors occur within
65 * EFX_INT_ERROR_EXPIRE seconds, we consider the NIC broken and
66 * disable it.
67 */
68#define EFX_INT_ERROR_EXPIRE 3600
69#define EFX_MAX_INT_ERRORS 5
70
71/* We poll for events every FLUSH_INTERVAL ms, and check FLUSH_POLL_COUNT times
72 */
73#define EFX_FLUSH_INTERVAL 10
74#define EFX_FLUSH_POLL_COUNT 100
75
76/* Size and alignment of special buffers (4KB) */
77#define EFX_BUF_SIZE 4096
78
79/* Depth of RX flush request fifo */
80#define EFX_RX_FLUSH_COUNT 4
81
Steve Hodgsond730dc52010-06-01 11:19:09 +000082/* Magic value for efx_generate_test_event() */
83#define EFX_CHANNEL_MAGIC(_channel) \
84 (0x00010100 + (_channel)->channel)
85
Ben Hutchings8e730c12009-11-29 15:14:45 +000086/**************************************************************************
87 *
88 * Solarstorm hardware access
89 *
90 **************************************************************************/
91
92static inline void efx_write_buf_tbl(struct efx_nic *efx, efx_qword_t *value,
93 unsigned int index)
94{
95 efx_sram_writeq(efx, efx->membase + efx->type->buf_tbl_base,
96 value, index);
97}
98
99/* Read the current event from the event queue */
100static inline efx_qword_t *efx_event(struct efx_channel *channel,
101 unsigned int index)
102{
103 return (((efx_qword_t *) (channel->eventq.addr)) + index);
104}
105
106/* See if an event is present
107 *
108 * We check both the high and low dword of the event for all ones. We
109 * wrote all ones when we cleared the event, and no valid event can
110 * have all ones in either its high or low dwords. This approach is
111 * robust against reordering.
112 *
113 * Note that using a single 64-bit comparison is incorrect; even
114 * though the CPU read will be atomic, the DMA write may not be.
115 */
116static inline int efx_event_present(efx_qword_t *event)
117{
118 return (!(EFX_DWORD_IS_ALL_ONES(event->dword[0]) |
119 EFX_DWORD_IS_ALL_ONES(event->dword[1])));
120}
121
122static bool efx_masked_compare_oword(const efx_oword_t *a, const efx_oword_t *b,
123 const efx_oword_t *mask)
124{
125 return ((a->u64[0] ^ b->u64[0]) & mask->u64[0]) ||
126 ((a->u64[1] ^ b->u64[1]) & mask->u64[1]);
127}
128
129int efx_nic_test_registers(struct efx_nic *efx,
130 const struct efx_nic_register_test *regs,
131 size_t n_regs)
132{
133 unsigned address = 0, i, j;
134 efx_oword_t mask, imask, original, reg, buf;
135
136 /* Falcon should be in loopback to isolate the XMAC from the PHY */
137 WARN_ON(!LOOPBACK_INTERNAL(efx));
138
139 for (i = 0; i < n_regs; ++i) {
140 address = regs[i].address;
141 mask = imask = regs[i].mask;
142 EFX_INVERT_OWORD(imask);
143
144 efx_reado(efx, &original, address);
145
146 /* bit sweep on and off */
147 for (j = 0; j < 128; j++) {
148 if (!EFX_EXTRACT_OWORD32(mask, j, j))
149 continue;
150
151 /* Test this testable bit can be set in isolation */
152 EFX_AND_OWORD(reg, original, mask);
153 EFX_SET_OWORD32(reg, j, j, 1);
154
155 efx_writeo(efx, &reg, address);
156 efx_reado(efx, &buf, address);
157
158 if (efx_masked_compare_oword(&reg, &buf, &mask))
159 goto fail;
160
161 /* Test this testable bit can be cleared in isolation */
162 EFX_OR_OWORD(reg, original, mask);
163 EFX_SET_OWORD32(reg, j, j, 0);
164
165 efx_writeo(efx, &reg, address);
166 efx_reado(efx, &buf, address);
167
168 if (efx_masked_compare_oword(&reg, &buf, &mask))
169 goto fail;
170 }
171
172 efx_writeo(efx, &original, address);
173 }
174
175 return 0;
176
177fail:
178 EFX_ERR(efx, "wrote "EFX_OWORD_FMT" read "EFX_OWORD_FMT
179 " at address 0x%x mask "EFX_OWORD_FMT"\n", EFX_OWORD_VAL(reg),
180 EFX_OWORD_VAL(buf), address, EFX_OWORD_VAL(mask));
181 return -EIO;
182}
183
184/**************************************************************************
185 *
186 * Special buffer handling
187 * Special buffers are used for event queues and the TX and RX
188 * descriptor rings.
189 *
190 *************************************************************************/
191
192/*
193 * Initialise a special buffer
194 *
195 * This will define a buffer (previously allocated via
196 * efx_alloc_special_buffer()) in the buffer table, allowing
197 * it to be used for event queues, descriptor rings etc.
198 */
199static void
200efx_init_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer)
201{
202 efx_qword_t buf_desc;
203 int index;
204 dma_addr_t dma_addr;
205 int i;
206
207 EFX_BUG_ON_PARANOID(!buffer->addr);
208
209 /* Write buffer descriptors to NIC */
210 for (i = 0; i < buffer->entries; i++) {
211 index = buffer->index + i;
212 dma_addr = buffer->dma_addr + (i * 4096);
213 EFX_LOG(efx, "mapping special buffer %d at %llx\n",
214 index, (unsigned long long)dma_addr);
215 EFX_POPULATE_QWORD_3(buf_desc,
216 FRF_AZ_BUF_ADR_REGION, 0,
217 FRF_AZ_BUF_ADR_FBUF, dma_addr >> 12,
218 FRF_AZ_BUF_OWNER_ID_FBUF, 0);
219 efx_write_buf_tbl(efx, &buf_desc, index);
220 }
221}
222
223/* Unmaps a buffer and clears the buffer table entries */
224static void
225efx_fini_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer)
226{
227 efx_oword_t buf_tbl_upd;
228 unsigned int start = buffer->index;
229 unsigned int end = (buffer->index + buffer->entries - 1);
230
231 if (!buffer->entries)
232 return;
233
234 EFX_LOG(efx, "unmapping special buffers %d-%d\n",
235 buffer->index, buffer->index + buffer->entries - 1);
236
237 EFX_POPULATE_OWORD_4(buf_tbl_upd,
238 FRF_AZ_BUF_UPD_CMD, 0,
239 FRF_AZ_BUF_CLR_CMD, 1,
240 FRF_AZ_BUF_CLR_END_ID, end,
241 FRF_AZ_BUF_CLR_START_ID, start);
242 efx_writeo(efx, &buf_tbl_upd, FR_AZ_BUF_TBL_UPD);
243}
244
245/*
246 * Allocate a new special buffer
247 *
248 * This allocates memory for a new buffer, clears it and allocates a
249 * new buffer ID range. It does not write into the buffer table.
250 *
251 * This call will allocate 4KB buffers, since 8KB buffers can't be
252 * used for event queues and descriptor rings.
253 */
254static int efx_alloc_special_buffer(struct efx_nic *efx,
255 struct efx_special_buffer *buffer,
256 unsigned int len)
257{
258 len = ALIGN(len, EFX_BUF_SIZE);
259
260 buffer->addr = pci_alloc_consistent(efx->pci_dev, len,
261 &buffer->dma_addr);
262 if (!buffer->addr)
263 return -ENOMEM;
264 buffer->len = len;
265 buffer->entries = len / EFX_BUF_SIZE;
266 BUG_ON(buffer->dma_addr & (EFX_BUF_SIZE - 1));
267
268 /* All zeros is a potentially valid event so memset to 0xff */
269 memset(buffer->addr, 0xff, len);
270
271 /* Select new buffer ID */
272 buffer->index = efx->next_buffer_table;
273 efx->next_buffer_table += buffer->entries;
274
275 EFX_LOG(efx, "allocating special buffers %d-%d at %llx+%x "
276 "(virt %p phys %llx)\n", buffer->index,
277 buffer->index + buffer->entries - 1,
278 (u64)buffer->dma_addr, len,
279 buffer->addr, (u64)virt_to_phys(buffer->addr));
280
281 return 0;
282}
283
284static void
285efx_free_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer)
286{
287 if (!buffer->addr)
288 return;
289
290 EFX_LOG(efx, "deallocating special buffers %d-%d at %llx+%x "
291 "(virt %p phys %llx)\n", buffer->index,
292 buffer->index + buffer->entries - 1,
293 (u64)buffer->dma_addr, buffer->len,
294 buffer->addr, (u64)virt_to_phys(buffer->addr));
295
296 pci_free_consistent(efx->pci_dev, buffer->len, buffer->addr,
297 buffer->dma_addr);
298 buffer->addr = NULL;
299 buffer->entries = 0;
300}
301
302/**************************************************************************
303 *
304 * Generic buffer handling
305 * These buffers are used for interrupt status and MAC stats
306 *
307 **************************************************************************/
308
309int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
310 unsigned int len)
311{
312 buffer->addr = pci_alloc_consistent(efx->pci_dev, len,
313 &buffer->dma_addr);
314 if (!buffer->addr)
315 return -ENOMEM;
316 buffer->len = len;
317 memset(buffer->addr, 0, len);
318 return 0;
319}
320
321void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer)
322{
323 if (buffer->addr) {
324 pci_free_consistent(efx->pci_dev, buffer->len,
325 buffer->addr, buffer->dma_addr);
326 buffer->addr = NULL;
327 }
328}
329
330/**************************************************************************
331 *
332 * TX path
333 *
334 **************************************************************************/
335
336/* Returns a pointer to the specified transmit descriptor in the TX
337 * descriptor queue belonging to the specified channel.
338 */
339static inline efx_qword_t *
340efx_tx_desc(struct efx_tx_queue *tx_queue, unsigned int index)
341{
342 return (((efx_qword_t *) (tx_queue->txd.addr)) + index);
343}
344
345/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
346static inline void efx_notify_tx_desc(struct efx_tx_queue *tx_queue)
347{
348 unsigned write_ptr;
349 efx_dword_t reg;
350
351 write_ptr = tx_queue->write_count & EFX_TXQ_MASK;
352 EFX_POPULATE_DWORD_1(reg, FRF_AZ_TX_DESC_WPTR_DWORD, write_ptr);
353 efx_writed_page(tx_queue->efx, &reg,
354 FR_AZ_TX_DESC_UPD_DWORD_P0, tx_queue->queue);
355}
356
357
358/* For each entry inserted into the software descriptor ring, create a
359 * descriptor in the hardware TX descriptor ring (in host memory), and
360 * write a doorbell.
361 */
362void efx_nic_push_buffers(struct efx_tx_queue *tx_queue)
363{
364
365 struct efx_tx_buffer *buffer;
366 efx_qword_t *txd;
367 unsigned write_ptr;
368
369 BUG_ON(tx_queue->write_count == tx_queue->insert_count);
370
371 do {
372 write_ptr = tx_queue->write_count & EFX_TXQ_MASK;
373 buffer = &tx_queue->buffer[write_ptr];
374 txd = efx_tx_desc(tx_queue, write_ptr);
375 ++tx_queue->write_count;
376
377 /* Create TX descriptor ring entry */
378 EFX_POPULATE_QWORD_4(*txd,
379 FSF_AZ_TX_KER_CONT, buffer->continuation,
380 FSF_AZ_TX_KER_BYTE_COUNT, buffer->len,
381 FSF_AZ_TX_KER_BUF_REGION, 0,
382 FSF_AZ_TX_KER_BUF_ADDR, buffer->dma_addr);
383 } while (tx_queue->write_count != tx_queue->insert_count);
384
385 wmb(); /* Ensure descriptors are written before they are fetched */
386 efx_notify_tx_desc(tx_queue);
387}
388
389/* Allocate hardware resources for a TX queue */
390int efx_nic_probe_tx(struct efx_tx_queue *tx_queue)
391{
392 struct efx_nic *efx = tx_queue->efx;
393 BUILD_BUG_ON(EFX_TXQ_SIZE < 512 || EFX_TXQ_SIZE > 4096 ||
394 EFX_TXQ_SIZE & EFX_TXQ_MASK);
395 return efx_alloc_special_buffer(efx, &tx_queue->txd,
396 EFX_TXQ_SIZE * sizeof(efx_qword_t));
397}
398
399void efx_nic_init_tx(struct efx_tx_queue *tx_queue)
400{
401 efx_oword_t tx_desc_ptr;
402 struct efx_nic *efx = tx_queue->efx;
403
404 tx_queue->flushed = FLUSH_NONE;
405
406 /* Pin TX descriptor ring */
407 efx_init_special_buffer(efx, &tx_queue->txd);
408
409 /* Push TX descriptor ring to card */
410 EFX_POPULATE_OWORD_10(tx_desc_ptr,
411 FRF_AZ_TX_DESCQ_EN, 1,
412 FRF_AZ_TX_ISCSI_DDIG_EN, 0,
413 FRF_AZ_TX_ISCSI_HDIG_EN, 0,
414 FRF_AZ_TX_DESCQ_BUF_BASE_ID, tx_queue->txd.index,
415 FRF_AZ_TX_DESCQ_EVQ_ID,
416 tx_queue->channel->channel,
417 FRF_AZ_TX_DESCQ_OWNER_ID, 0,
418 FRF_AZ_TX_DESCQ_LABEL, tx_queue->queue,
419 FRF_AZ_TX_DESCQ_SIZE,
420 __ffs(tx_queue->txd.entries),
421 FRF_AZ_TX_DESCQ_TYPE, 0,
422 FRF_BZ_TX_NON_IP_DROP_DIS, 1);
423
424 if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
Ben Hutchingsa4900ac2010-04-28 09:30:43 +0000425 int csum = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
Ben Hutchings8e730c12009-11-29 15:14:45 +0000426 EFX_SET_OWORD_FIELD(tx_desc_ptr, FRF_BZ_TX_IP_CHKSM_DIS, !csum);
427 EFX_SET_OWORD_FIELD(tx_desc_ptr, FRF_BZ_TX_TCP_CHKSM_DIS,
428 !csum);
429 }
430
431 efx_writeo_table(efx, &tx_desc_ptr, efx->type->txd_ptr_tbl_base,
432 tx_queue->queue);
433
434 if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) {
435 efx_oword_t reg;
436
437 /* Only 128 bits in this register */
Ben Hutchingsa4900ac2010-04-28 09:30:43 +0000438 BUILD_BUG_ON(EFX_MAX_TX_QUEUES > 128);
Ben Hutchings8e730c12009-11-29 15:14:45 +0000439
440 efx_reado(efx, &reg, FR_AA_TX_CHKSM_CFG);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +0000441 if (tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD)
Ben Hutchings8e730c12009-11-29 15:14:45 +0000442 clear_bit_le(tx_queue->queue, (void *)&reg);
443 else
444 set_bit_le(tx_queue->queue, (void *)&reg);
445 efx_writeo(efx, &reg, FR_AA_TX_CHKSM_CFG);
446 }
447}
448
449static void efx_flush_tx_queue(struct efx_tx_queue *tx_queue)
450{
451 struct efx_nic *efx = tx_queue->efx;
452 efx_oword_t tx_flush_descq;
453
454 tx_queue->flushed = FLUSH_PENDING;
455
456 /* Post a flush command */
457 EFX_POPULATE_OWORD_2(tx_flush_descq,
458 FRF_AZ_TX_FLUSH_DESCQ_CMD, 1,
459 FRF_AZ_TX_FLUSH_DESCQ, tx_queue->queue);
460 efx_writeo(efx, &tx_flush_descq, FR_AZ_TX_FLUSH_DESCQ);
461}
462
463void efx_nic_fini_tx(struct efx_tx_queue *tx_queue)
464{
465 struct efx_nic *efx = tx_queue->efx;
466 efx_oword_t tx_desc_ptr;
467
468 /* The queue should have been flushed */
469 WARN_ON(tx_queue->flushed != FLUSH_DONE);
470
471 /* Remove TX descriptor ring from card */
472 EFX_ZERO_OWORD(tx_desc_ptr);
473 efx_writeo_table(efx, &tx_desc_ptr, efx->type->txd_ptr_tbl_base,
474 tx_queue->queue);
475
476 /* Unpin TX descriptor ring */
477 efx_fini_special_buffer(efx, &tx_queue->txd);
478}
479
480/* Free buffers backing TX queue */
481void efx_nic_remove_tx(struct efx_tx_queue *tx_queue)
482{
483 efx_free_special_buffer(tx_queue->efx, &tx_queue->txd);
484}
485
486/**************************************************************************
487 *
488 * RX path
489 *
490 **************************************************************************/
491
492/* Returns a pointer to the specified descriptor in the RX descriptor queue */
493static inline efx_qword_t *
494efx_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
495{
496 return (((efx_qword_t *) (rx_queue->rxd.addr)) + index);
497}
498
499/* This creates an entry in the RX descriptor queue */
500static inline void
501efx_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned index)
502{
503 struct efx_rx_buffer *rx_buf;
504 efx_qword_t *rxd;
505
506 rxd = efx_rx_desc(rx_queue, index);
507 rx_buf = efx_rx_buffer(rx_queue, index);
508 EFX_POPULATE_QWORD_3(*rxd,
509 FSF_AZ_RX_KER_BUF_SIZE,
510 rx_buf->len -
511 rx_queue->efx->type->rx_buffer_padding,
512 FSF_AZ_RX_KER_BUF_REGION, 0,
513 FSF_AZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
514}
515
516/* This writes to the RX_DESC_WPTR register for the specified receive
517 * descriptor ring.
518 */
519void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue)
520{
521 efx_dword_t reg;
522 unsigned write_ptr;
523
524 while (rx_queue->notified_count != rx_queue->added_count) {
525 efx_build_rx_desc(rx_queue,
526 rx_queue->notified_count &
527 EFX_RXQ_MASK);
528 ++rx_queue->notified_count;
529 }
530
531 wmb();
532 write_ptr = rx_queue->added_count & EFX_RXQ_MASK;
533 EFX_POPULATE_DWORD_1(reg, FRF_AZ_RX_DESC_WPTR_DWORD, write_ptr);
534 efx_writed_page(rx_queue->efx, &reg,
535 FR_AZ_RX_DESC_UPD_DWORD_P0, rx_queue->queue);
536}
537
538int efx_nic_probe_rx(struct efx_rx_queue *rx_queue)
539{
540 struct efx_nic *efx = rx_queue->efx;
541 BUILD_BUG_ON(EFX_RXQ_SIZE < 512 || EFX_RXQ_SIZE > 4096 ||
542 EFX_RXQ_SIZE & EFX_RXQ_MASK);
543 return efx_alloc_special_buffer(efx, &rx_queue->rxd,
544 EFX_RXQ_SIZE * sizeof(efx_qword_t));
545}
546
547void efx_nic_init_rx(struct efx_rx_queue *rx_queue)
548{
549 efx_oword_t rx_desc_ptr;
550 struct efx_nic *efx = rx_queue->efx;
551 bool is_b0 = efx_nic_rev(efx) >= EFX_REV_FALCON_B0;
552 bool iscsi_digest_en = is_b0;
553
554 EFX_LOG(efx, "RX queue %d ring in special buffers %d-%d\n",
555 rx_queue->queue, rx_queue->rxd.index,
556 rx_queue->rxd.index + rx_queue->rxd.entries - 1);
557
558 rx_queue->flushed = FLUSH_NONE;
559
560 /* Pin RX descriptor ring */
561 efx_init_special_buffer(efx, &rx_queue->rxd);
562
563 /* Push RX descriptor ring to card */
564 EFX_POPULATE_OWORD_10(rx_desc_ptr,
565 FRF_AZ_RX_ISCSI_DDIG_EN, iscsi_digest_en,
566 FRF_AZ_RX_ISCSI_HDIG_EN, iscsi_digest_en,
567 FRF_AZ_RX_DESCQ_BUF_BASE_ID, rx_queue->rxd.index,
568 FRF_AZ_RX_DESCQ_EVQ_ID,
569 rx_queue->channel->channel,
570 FRF_AZ_RX_DESCQ_OWNER_ID, 0,
571 FRF_AZ_RX_DESCQ_LABEL, rx_queue->queue,
572 FRF_AZ_RX_DESCQ_SIZE,
573 __ffs(rx_queue->rxd.entries),
574 FRF_AZ_RX_DESCQ_TYPE, 0 /* kernel queue */ ,
575 /* For >=B0 this is scatter so disable */
576 FRF_AZ_RX_DESCQ_JUMBO, !is_b0,
577 FRF_AZ_RX_DESCQ_EN, 1);
578 efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base,
579 rx_queue->queue);
580}
581
582static void efx_flush_rx_queue(struct efx_rx_queue *rx_queue)
583{
584 struct efx_nic *efx = rx_queue->efx;
585 efx_oword_t rx_flush_descq;
586
587 rx_queue->flushed = FLUSH_PENDING;
588
589 /* Post a flush command */
590 EFX_POPULATE_OWORD_2(rx_flush_descq,
591 FRF_AZ_RX_FLUSH_DESCQ_CMD, 1,
592 FRF_AZ_RX_FLUSH_DESCQ, rx_queue->queue);
593 efx_writeo(efx, &rx_flush_descq, FR_AZ_RX_FLUSH_DESCQ);
594}
595
596void efx_nic_fini_rx(struct efx_rx_queue *rx_queue)
597{
598 efx_oword_t rx_desc_ptr;
599 struct efx_nic *efx = rx_queue->efx;
600
601 /* The queue should already have been flushed */
602 WARN_ON(rx_queue->flushed != FLUSH_DONE);
603
604 /* Remove RX descriptor ring from card */
605 EFX_ZERO_OWORD(rx_desc_ptr);
606 efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base,
607 rx_queue->queue);
608
609 /* Unpin RX descriptor ring */
610 efx_fini_special_buffer(efx, &rx_queue->rxd);
611}
612
613/* Free buffers backing RX queue */
614void efx_nic_remove_rx(struct efx_rx_queue *rx_queue)
615{
616 efx_free_special_buffer(rx_queue->efx, &rx_queue->rxd);
617}
618
619/**************************************************************************
620 *
621 * Event queue processing
622 * Event queues are processed by per-channel tasklets.
623 *
624 **************************************************************************/
625
626/* Update a channel's event queue's read pointer (RPTR) register
627 *
628 * This writes the EVQ_RPTR_REG register for the specified channel's
629 * event queue.
Ben Hutchings8e730c12009-11-29 15:14:45 +0000630 */
631void efx_nic_eventq_read_ack(struct efx_channel *channel)
632{
633 efx_dword_t reg;
634 struct efx_nic *efx = channel->efx;
635
636 EFX_POPULATE_DWORD_1(reg, FRF_AZ_EVQ_RPTR, channel->eventq_read_ptr);
637 efx_writed_table(efx, &reg, efx->type->evq_rptr_tbl_base,
638 channel->channel);
639}
640
641/* Use HW to insert a SW defined event */
642void efx_generate_event(struct efx_channel *channel, efx_qword_t *event)
643{
644 efx_oword_t drv_ev_reg;
645
646 BUILD_BUG_ON(FRF_AZ_DRV_EV_DATA_LBN != 0 ||
647 FRF_AZ_DRV_EV_DATA_WIDTH != 64);
648 drv_ev_reg.u32[0] = event->u32[0];
649 drv_ev_reg.u32[1] = event->u32[1];
650 drv_ev_reg.u32[2] = 0;
651 drv_ev_reg.u32[3] = 0;
652 EFX_SET_OWORD_FIELD(drv_ev_reg, FRF_AZ_DRV_EV_QID, channel->channel);
653 efx_writeo(channel->efx, &drv_ev_reg, FR_AZ_DRV_EV);
654}
655
656/* Handle a transmit completion event
657 *
658 * The NIC batches TX completion events; the message we receive is of
659 * the form "complete all TX events up to this index".
660 */
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000661static int
Ben Hutchings8e730c12009-11-29 15:14:45 +0000662efx_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
663{
664 unsigned int tx_ev_desc_ptr;
665 unsigned int tx_ev_q_label;
666 struct efx_tx_queue *tx_queue;
667 struct efx_nic *efx = channel->efx;
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000668 int tx_packets = 0;
Ben Hutchings8e730c12009-11-29 15:14:45 +0000669
670 if (likely(EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_COMP))) {
671 /* Transmit completion */
672 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_DESC_PTR);
673 tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
674 tx_queue = &efx->tx_queue[tx_ev_q_label];
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000675 tx_packets = ((tx_ev_desc_ptr - tx_queue->read_count) &
676 EFX_TXQ_MASK);
677 channel->irq_mod_score += tx_packets;
Ben Hutchings8e730c12009-11-29 15:14:45 +0000678 efx_xmit_done(tx_queue, tx_ev_desc_ptr);
679 } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_WQ_FF_FULL)) {
680 /* Rewrite the FIFO write pointer */
681 tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
682 tx_queue = &efx->tx_queue[tx_ev_q_label];
683
684 if (efx_dev_registered(efx))
685 netif_tx_lock(efx->net_dev);
686 efx_notify_tx_desc(tx_queue);
687 if (efx_dev_registered(efx))
688 netif_tx_unlock(efx->net_dev);
689 } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_PKT_ERR) &&
690 EFX_WORKAROUND_10727(efx)) {
691 efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
692 } else {
693 EFX_ERR(efx, "channel %d unexpected TX event "
694 EFX_QWORD_FMT"\n", channel->channel,
695 EFX_QWORD_VAL(*event));
696 }
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000697
698 return tx_packets;
Ben Hutchings8e730c12009-11-29 15:14:45 +0000699}
700
701/* Detect errors included in the rx_evt_pkt_ok bit. */
702static void efx_handle_rx_not_ok(struct efx_rx_queue *rx_queue,
703 const efx_qword_t *event,
704 bool *rx_ev_pkt_ok,
705 bool *discard)
706{
707 struct efx_nic *efx = rx_queue->efx;
708 bool rx_ev_buf_owner_id_err, rx_ev_ip_hdr_chksum_err;
709 bool rx_ev_tcp_udp_chksum_err, rx_ev_eth_crc_err;
710 bool rx_ev_frm_trunc, rx_ev_drib_nib, rx_ev_tobe_disc;
711 bool rx_ev_other_err, rx_ev_pause_frm;
712 bool rx_ev_hdr_type, rx_ev_mcast_pkt;
713 unsigned rx_ev_pkt_type;
714
715 rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE);
716 rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT);
717 rx_ev_tobe_disc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_TOBE_DISC);
718 rx_ev_pkt_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_TYPE);
719 rx_ev_buf_owner_id_err = EFX_QWORD_FIELD(*event,
720 FSF_AZ_RX_EV_BUF_OWNER_ID_ERR);
721 rx_ev_ip_hdr_chksum_err = EFX_QWORD_FIELD(*event,
722 FSF_AZ_RX_EV_IP_HDR_CHKSUM_ERR);
723 rx_ev_tcp_udp_chksum_err = EFX_QWORD_FIELD(*event,
724 FSF_AZ_RX_EV_TCP_UDP_CHKSUM_ERR);
725 rx_ev_eth_crc_err = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_ETH_CRC_ERR);
726 rx_ev_frm_trunc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_FRM_TRUNC);
727 rx_ev_drib_nib = ((efx_nic_rev(efx) >= EFX_REV_FALCON_B0) ?
728 0 : EFX_QWORD_FIELD(*event, FSF_AA_RX_EV_DRIB_NIB));
729 rx_ev_pause_frm = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PAUSE_FRM_ERR);
730
731 /* Every error apart from tobe_disc and pause_frm */
732 rx_ev_other_err = (rx_ev_drib_nib | rx_ev_tcp_udp_chksum_err |
733 rx_ev_buf_owner_id_err | rx_ev_eth_crc_err |
734 rx_ev_frm_trunc | rx_ev_ip_hdr_chksum_err);
735
736 /* Count errors that are not in MAC stats. Ignore expected
737 * checksum errors during self-test. */
738 if (rx_ev_frm_trunc)
739 ++rx_queue->channel->n_rx_frm_trunc;
740 else if (rx_ev_tobe_disc)
741 ++rx_queue->channel->n_rx_tobe_disc;
742 else if (!efx->loopback_selftest) {
743 if (rx_ev_ip_hdr_chksum_err)
744 ++rx_queue->channel->n_rx_ip_hdr_chksum_err;
745 else if (rx_ev_tcp_udp_chksum_err)
746 ++rx_queue->channel->n_rx_tcp_udp_chksum_err;
747 }
748
749 /* The frame must be discarded if any of these are true. */
750 *discard = (rx_ev_eth_crc_err | rx_ev_frm_trunc | rx_ev_drib_nib |
751 rx_ev_tobe_disc | rx_ev_pause_frm);
752
753 /* TOBE_DISC is expected on unicast mismatches; don't print out an
754 * error message. FRM_TRUNC indicates RXDP dropped the packet due
755 * to a FIFO overflow.
756 */
757#ifdef EFX_ENABLE_DEBUG
758 if (rx_ev_other_err) {
759 EFX_INFO_RL(efx, " RX queue %d unexpected RX event "
760 EFX_QWORD_FMT "%s%s%s%s%s%s%s%s\n",
761 rx_queue->queue, EFX_QWORD_VAL(*event),
762 rx_ev_buf_owner_id_err ? " [OWNER_ID_ERR]" : "",
763 rx_ev_ip_hdr_chksum_err ?
764 " [IP_HDR_CHKSUM_ERR]" : "",
765 rx_ev_tcp_udp_chksum_err ?
766 " [TCP_UDP_CHKSUM_ERR]" : "",
767 rx_ev_eth_crc_err ? " [ETH_CRC_ERR]" : "",
768 rx_ev_frm_trunc ? " [FRM_TRUNC]" : "",
769 rx_ev_drib_nib ? " [DRIB_NIB]" : "",
770 rx_ev_tobe_disc ? " [TOBE_DISC]" : "",
771 rx_ev_pause_frm ? " [PAUSE]" : "");
772 }
773#endif
774}
775
776/* Handle receive events that are not in-order. */
777static void
778efx_handle_rx_bad_index(struct efx_rx_queue *rx_queue, unsigned index)
779{
780 struct efx_nic *efx = rx_queue->efx;
781 unsigned expected, dropped;
782
783 expected = rx_queue->removed_count & EFX_RXQ_MASK;
784 dropped = (index - expected) & EFX_RXQ_MASK;
785 EFX_INFO(efx, "dropped %d events (index=%d expected=%d)\n",
786 dropped, index, expected);
787
788 efx_schedule_reset(efx, EFX_WORKAROUND_5676(efx) ?
789 RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
790}
791
792/* Handle a packet received event
793 *
794 * The NIC gives a "discard" flag if it's a unicast packet with the
795 * wrong destination address
796 * Also "is multicast" and "matches multicast filter" flags can be used to
797 * discard non-matching multicast packets.
798 */
799static void
800efx_handle_rx_event(struct efx_channel *channel, const efx_qword_t *event)
801{
802 unsigned int rx_ev_desc_ptr, rx_ev_byte_cnt;
803 unsigned int rx_ev_hdr_type, rx_ev_mcast_pkt;
804 unsigned expected_ptr;
805 bool rx_ev_pkt_ok, discard = false, checksummed;
806 struct efx_rx_queue *rx_queue;
807 struct efx_nic *efx = channel->efx;
808
809 /* Basic packet information */
810 rx_ev_byte_cnt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_BYTE_CNT);
811 rx_ev_pkt_ok = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_OK);
812 rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE);
813 WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_JUMBO_CONT));
814 WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_SOP) != 1);
815 WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_Q_LABEL) !=
816 channel->channel);
817
818 rx_queue = &efx->rx_queue[channel->channel];
819
820 rx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_DESC_PTR);
821 expected_ptr = rx_queue->removed_count & EFX_RXQ_MASK;
822 if (unlikely(rx_ev_desc_ptr != expected_ptr))
823 efx_handle_rx_bad_index(rx_queue, rx_ev_desc_ptr);
824
825 if (likely(rx_ev_pkt_ok)) {
826 /* If packet is marked as OK and packet type is TCP/IP or
827 * UDP/IP, then we can rely on the hardware checksum.
828 */
829 checksummed =
830 likely(efx->rx_checksum_enabled) &&
831 (rx_ev_hdr_type == FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_TCP ||
832 rx_ev_hdr_type == FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_UDP);
833 } else {
834 efx_handle_rx_not_ok(rx_queue, event, &rx_ev_pkt_ok, &discard);
835 checksummed = false;
836 }
837
838 /* Detect multicast packets that didn't match the filter */
839 rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT);
840 if (rx_ev_mcast_pkt) {
841 unsigned int rx_ev_mcast_hash_match =
842 EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_HASH_MATCH);
843
844 if (unlikely(!rx_ev_mcast_hash_match)) {
845 ++channel->n_rx_mcast_mismatch;
846 discard = true;
847 }
848 }
849
850 channel->irq_mod_score += 2;
851
852 /* Handle received packet */
853 efx_rx_packet(rx_queue, rx_ev_desc_ptr, rx_ev_byte_cnt,
854 checksummed, discard);
855}
856
857/* Global events are basically PHY events */
858static void
859efx_handle_global_event(struct efx_channel *channel, efx_qword_t *event)
860{
861 struct efx_nic *efx = channel->efx;
862 bool handled = false;
863
864 if (EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_G_PHY0_INTR) ||
865 EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XG_PHY0_INTR) ||
866 EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XFP_PHY0_INTR)) {
867 /* Ignored */
868 handled = true;
869 }
870
871 if ((efx_nic_rev(efx) >= EFX_REV_FALCON_B0) &&
872 EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_XG_MGT_INTR)) {
873 efx->xmac_poll_required = true;
874 handled = true;
875 }
876
877 if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ?
878 EFX_QWORD_FIELD(*event, FSF_AA_GLB_EV_RX_RECOVERY) :
879 EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_RX_RECOVERY)) {
880 EFX_ERR(efx, "channel %d seen global RX_RESET "
881 "event. Resetting.\n", channel->channel);
882
883 atomic_inc(&efx->rx_reset);
884 efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ?
885 RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
886 handled = true;
887 }
888
889 if (!handled)
890 EFX_ERR(efx, "channel %d unknown global event "
891 EFX_QWORD_FMT "\n", channel->channel,
892 EFX_QWORD_VAL(*event));
893}
894
895static void
896efx_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
897{
898 struct efx_nic *efx = channel->efx;
899 unsigned int ev_sub_code;
900 unsigned int ev_sub_data;
901
902 ev_sub_code = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBCODE);
903 ev_sub_data = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA);
904
905 switch (ev_sub_code) {
906 case FSE_AZ_TX_DESCQ_FLS_DONE_EV:
907 EFX_TRACE(efx, "channel %d TXQ %d flushed\n",
908 channel->channel, ev_sub_data);
909 break;
910 case FSE_AZ_RX_DESCQ_FLS_DONE_EV:
911 EFX_TRACE(efx, "channel %d RXQ %d flushed\n",
912 channel->channel, ev_sub_data);
913 break;
914 case FSE_AZ_EVQ_INIT_DONE_EV:
915 EFX_LOG(efx, "channel %d EVQ %d initialised\n",
916 channel->channel, ev_sub_data);
917 break;
918 case FSE_AZ_SRM_UPD_DONE_EV:
919 EFX_TRACE(efx, "channel %d SRAM update done\n",
920 channel->channel);
921 break;
922 case FSE_AZ_WAKE_UP_EV:
923 EFX_TRACE(efx, "channel %d RXQ %d wakeup event\n",
924 channel->channel, ev_sub_data);
925 break;
926 case FSE_AZ_TIMER_EV:
927 EFX_TRACE(efx, "channel %d RX queue %d timer expired\n",
928 channel->channel, ev_sub_data);
929 break;
930 case FSE_AA_RX_RECOVER_EV:
931 EFX_ERR(efx, "channel %d seen DRIVER RX_RESET event. "
932 "Resetting.\n", channel->channel);
933 atomic_inc(&efx->rx_reset);
934 efx_schedule_reset(efx,
935 EFX_WORKAROUND_6555(efx) ?
936 RESET_TYPE_RX_RECOVERY :
937 RESET_TYPE_DISABLE);
938 break;
939 case FSE_BZ_RX_DSC_ERROR_EV:
940 EFX_ERR(efx, "RX DMA Q %d reports descriptor fetch error."
941 " RX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
942 efx_schedule_reset(efx, RESET_TYPE_RX_DESC_FETCH);
943 break;
944 case FSE_BZ_TX_DSC_ERROR_EV:
945 EFX_ERR(efx, "TX DMA Q %d reports descriptor fetch error."
946 " TX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
947 efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
948 break;
949 default:
950 EFX_TRACE(efx, "channel %d unknown driver event code %d "
951 "data %04x\n", channel->channel, ev_sub_code,
952 ev_sub_data);
953 break;
954 }
955}
956
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000957int efx_nic_process_eventq(struct efx_channel *channel, int budget)
Ben Hutchings8e730c12009-11-29 15:14:45 +0000958{
959 unsigned int read_ptr;
960 efx_qword_t event, *p_event;
961 int ev_code;
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000962 int tx_packets = 0;
963 int spent = 0;
Ben Hutchings8e730c12009-11-29 15:14:45 +0000964
965 read_ptr = channel->eventq_read_ptr;
966
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000967 for (;;) {
Ben Hutchings8e730c12009-11-29 15:14:45 +0000968 p_event = efx_event(channel, read_ptr);
969 event = *p_event;
970
971 if (!efx_event_present(&event))
972 /* End of events */
973 break;
974
975 EFX_TRACE(channel->efx, "channel %d event is "EFX_QWORD_FMT"\n",
976 channel->channel, EFX_QWORD_VAL(event));
977
978 /* Clear this event by marking it all ones */
979 EFX_SET_QWORD(*p_event);
980
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000981 /* Increment read pointer */
982 read_ptr = (read_ptr + 1) & EFX_EVQ_MASK;
983
Ben Hutchings8e730c12009-11-29 15:14:45 +0000984 ev_code = EFX_QWORD_FIELD(event, FSF_AZ_EV_CODE);
985
986 switch (ev_code) {
987 case FSE_AZ_EV_CODE_RX_EV:
988 efx_handle_rx_event(channel, &event);
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000989 if (++spent == budget)
990 goto out;
Ben Hutchings8e730c12009-11-29 15:14:45 +0000991 break;
992 case FSE_AZ_EV_CODE_TX_EV:
Ben Hutchingsfa236e12010-04-28 09:29:42 +0000993 tx_packets += efx_handle_tx_event(channel, &event);
994 if (tx_packets >= EFX_TXQ_SIZE) {
995 spent = budget;
996 goto out;
997 }
Ben Hutchings8e730c12009-11-29 15:14:45 +0000998 break;
999 case FSE_AZ_EV_CODE_DRV_GEN_EV:
Steve Hodgsond730dc52010-06-01 11:19:09 +00001000 if (EFX_QWORD_FIELD(event, FSF_AZ_DRV_GEN_EV_MAGIC)
1001 == EFX_CHANNEL_MAGIC(channel))
1002 ++channel->magic_count;
1003
Ben Hutchings8e730c12009-11-29 15:14:45 +00001004 EFX_LOG(channel->efx, "channel %d received generated "
1005 "event "EFX_QWORD_FMT"\n", channel->channel,
1006 EFX_QWORD_VAL(event));
1007 break;
1008 case FSE_AZ_EV_CODE_GLOBAL_EV:
1009 efx_handle_global_event(channel, &event);
1010 break;
1011 case FSE_AZ_EV_CODE_DRIVER_EV:
1012 efx_handle_driver_event(channel, &event);
1013 break;
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001014 case FSE_CZ_EV_CODE_MCDI_EV:
1015 efx_mcdi_process_event(channel, &event);
1016 break;
Ben Hutchings8e730c12009-11-29 15:14:45 +00001017 default:
1018 EFX_ERR(channel->efx, "channel %d unknown event type %d"
1019 " (data " EFX_QWORD_FMT ")\n", channel->channel,
1020 ev_code, EFX_QWORD_VAL(event));
1021 }
Ben Hutchingsfa236e12010-04-28 09:29:42 +00001022 }
Ben Hutchings8e730c12009-11-29 15:14:45 +00001023
Ben Hutchingsfa236e12010-04-28 09:29:42 +00001024out:
Ben Hutchings8e730c12009-11-29 15:14:45 +00001025 channel->eventq_read_ptr = read_ptr;
Ben Hutchingsfa236e12010-04-28 09:29:42 +00001026 return spent;
Ben Hutchings8e730c12009-11-29 15:14:45 +00001027}
1028
1029
1030/* Allocate buffer table entries for event queue */
1031int efx_nic_probe_eventq(struct efx_channel *channel)
1032{
1033 struct efx_nic *efx = channel->efx;
1034 BUILD_BUG_ON(EFX_EVQ_SIZE < 512 || EFX_EVQ_SIZE > 32768 ||
1035 EFX_EVQ_SIZE & EFX_EVQ_MASK);
1036 return efx_alloc_special_buffer(efx, &channel->eventq,
1037 EFX_EVQ_SIZE * sizeof(efx_qword_t));
1038}
1039
1040void efx_nic_init_eventq(struct efx_channel *channel)
1041{
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001042 efx_oword_t reg;
Ben Hutchings8e730c12009-11-29 15:14:45 +00001043 struct efx_nic *efx = channel->efx;
1044
1045 EFX_LOG(efx, "channel %d event queue in special buffers %d-%d\n",
1046 channel->channel, channel->eventq.index,
1047 channel->eventq.index + channel->eventq.entries - 1);
1048
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001049 if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) {
1050 EFX_POPULATE_OWORD_3(reg,
1051 FRF_CZ_TIMER_Q_EN, 1,
1052 FRF_CZ_HOST_NOTIFY_MODE, 0,
1053 FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS);
1054 efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL, channel->channel);
1055 }
1056
Ben Hutchings8e730c12009-11-29 15:14:45 +00001057 /* Pin event queue buffer */
1058 efx_init_special_buffer(efx, &channel->eventq);
1059
1060 /* Fill event queue with all ones (i.e. empty events) */
1061 memset(channel->eventq.addr, 0xff, channel->eventq.len);
1062
1063 /* Push event queue to card */
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001064 EFX_POPULATE_OWORD_3(reg,
Ben Hutchings8e730c12009-11-29 15:14:45 +00001065 FRF_AZ_EVQ_EN, 1,
1066 FRF_AZ_EVQ_SIZE, __ffs(channel->eventq.entries),
1067 FRF_AZ_EVQ_BUF_BASE_ID, channel->eventq.index);
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001068 efx_writeo_table(efx, &reg, efx->type->evq_ptr_tbl_base,
Ben Hutchings8e730c12009-11-29 15:14:45 +00001069 channel->channel);
1070
1071 efx->type->push_irq_moderation(channel);
1072}
1073
1074void efx_nic_fini_eventq(struct efx_channel *channel)
1075{
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001076 efx_oword_t reg;
Ben Hutchings8e730c12009-11-29 15:14:45 +00001077 struct efx_nic *efx = channel->efx;
1078
1079 /* Remove event queue from card */
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001080 EFX_ZERO_OWORD(reg);
1081 efx_writeo_table(efx, &reg, efx->type->evq_ptr_tbl_base,
Ben Hutchings8e730c12009-11-29 15:14:45 +00001082 channel->channel);
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001083 if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
1084 efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL, channel->channel);
Ben Hutchings8e730c12009-11-29 15:14:45 +00001085
1086 /* Unpin event queue */
1087 efx_fini_special_buffer(efx, &channel->eventq);
1088}
1089
1090/* Free buffers backing event queue */
1091void efx_nic_remove_eventq(struct efx_channel *channel)
1092{
1093 efx_free_special_buffer(channel->efx, &channel->eventq);
1094}
1095
1096
Steve Hodgsond730dc52010-06-01 11:19:09 +00001097void efx_nic_generate_test_event(struct efx_channel *channel)
Ben Hutchings8e730c12009-11-29 15:14:45 +00001098{
Steve Hodgsond730dc52010-06-01 11:19:09 +00001099 unsigned int magic = EFX_CHANNEL_MAGIC(channel);
Ben Hutchings8e730c12009-11-29 15:14:45 +00001100 efx_qword_t test_event;
1101
1102 EFX_POPULATE_QWORD_2(test_event, FSF_AZ_EV_CODE,
1103 FSE_AZ_EV_CODE_DRV_GEN_EV,
1104 FSF_AZ_DRV_GEN_EV_MAGIC, magic);
1105 efx_generate_event(channel, &test_event);
1106}
1107
1108/**************************************************************************
1109 *
1110 * Flush handling
1111 *
1112 **************************************************************************/
1113
1114
1115static void efx_poll_flush_events(struct efx_nic *efx)
1116{
1117 struct efx_channel *channel = &efx->channel[0];
1118 struct efx_tx_queue *tx_queue;
1119 struct efx_rx_queue *rx_queue;
1120 unsigned int read_ptr = channel->eventq_read_ptr;
1121 unsigned int end_ptr = (read_ptr - 1) & EFX_EVQ_MASK;
1122
1123 do {
1124 efx_qword_t *event = efx_event(channel, read_ptr);
1125 int ev_code, ev_sub_code, ev_queue;
1126 bool ev_failed;
1127
1128 if (!efx_event_present(event))
1129 break;
1130
1131 ev_code = EFX_QWORD_FIELD(*event, FSF_AZ_EV_CODE);
1132 ev_sub_code = EFX_QWORD_FIELD(*event,
1133 FSF_AZ_DRIVER_EV_SUBCODE);
1134 if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
1135 ev_sub_code == FSE_AZ_TX_DESCQ_FLS_DONE_EV) {
1136 ev_queue = EFX_QWORD_FIELD(*event,
1137 FSF_AZ_DRIVER_EV_SUBDATA);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001138 if (ev_queue < EFX_TXQ_TYPES * efx->n_tx_channels) {
Ben Hutchings8e730c12009-11-29 15:14:45 +00001139 tx_queue = efx->tx_queue + ev_queue;
1140 tx_queue->flushed = FLUSH_DONE;
1141 }
1142 } else if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
1143 ev_sub_code == FSE_AZ_RX_DESCQ_FLS_DONE_EV) {
1144 ev_queue = EFX_QWORD_FIELD(
1145 *event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);
1146 ev_failed = EFX_QWORD_FIELD(
1147 *event, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001148 if (ev_queue < efx->n_rx_channels) {
Ben Hutchings8e730c12009-11-29 15:14:45 +00001149 rx_queue = efx->rx_queue + ev_queue;
1150 rx_queue->flushed =
1151 ev_failed ? FLUSH_FAILED : FLUSH_DONE;
1152 }
1153 }
1154
1155 /* We're about to destroy the queue anyway, so
1156 * it's ok to throw away every non-flush event */
1157 EFX_SET_QWORD(*event);
1158
1159 read_ptr = (read_ptr + 1) & EFX_EVQ_MASK;
1160 } while (read_ptr != end_ptr);
1161
1162 channel->eventq_read_ptr = read_ptr;
1163}
1164
1165/* Handle tx and rx flushes at the same time, since they run in
1166 * parallel in the hardware and there's no reason for us to
1167 * serialise them */
1168int efx_nic_flush_queues(struct efx_nic *efx)
1169{
1170 struct efx_rx_queue *rx_queue;
1171 struct efx_tx_queue *tx_queue;
1172 int i, tx_pending, rx_pending;
1173
1174 /* If necessary prepare the hardware for flushing */
1175 efx->type->prepare_flush(efx);
1176
1177 /* Flush all tx queues in parallel */
1178 efx_for_each_tx_queue(tx_queue, efx)
1179 efx_flush_tx_queue(tx_queue);
1180
1181 /* The hardware supports four concurrent rx flushes, each of which may
1182 * need to be retried if there is an outstanding descriptor fetch */
1183 for (i = 0; i < EFX_FLUSH_POLL_COUNT; ++i) {
1184 rx_pending = tx_pending = 0;
1185 efx_for_each_rx_queue(rx_queue, efx) {
1186 if (rx_queue->flushed == FLUSH_PENDING)
1187 ++rx_pending;
1188 }
1189 efx_for_each_rx_queue(rx_queue, efx) {
1190 if (rx_pending == EFX_RX_FLUSH_COUNT)
1191 break;
1192 if (rx_queue->flushed == FLUSH_FAILED ||
1193 rx_queue->flushed == FLUSH_NONE) {
1194 efx_flush_rx_queue(rx_queue);
1195 ++rx_pending;
1196 }
1197 }
1198 efx_for_each_tx_queue(tx_queue, efx) {
1199 if (tx_queue->flushed != FLUSH_DONE)
1200 ++tx_pending;
1201 }
1202
1203 if (rx_pending == 0 && tx_pending == 0)
1204 return 0;
1205
1206 msleep(EFX_FLUSH_INTERVAL);
1207 efx_poll_flush_events(efx);
1208 }
1209
1210 /* Mark the queues as all flushed. We're going to return failure
1211 * leading to a reset, or fake up success anyway */
1212 efx_for_each_tx_queue(tx_queue, efx) {
1213 if (tx_queue->flushed != FLUSH_DONE)
1214 EFX_ERR(efx, "tx queue %d flush command timed out\n",
1215 tx_queue->queue);
1216 tx_queue->flushed = FLUSH_DONE;
1217 }
1218 efx_for_each_rx_queue(rx_queue, efx) {
1219 if (rx_queue->flushed != FLUSH_DONE)
1220 EFX_ERR(efx, "rx queue %d flush command timed out\n",
1221 rx_queue->queue);
1222 rx_queue->flushed = FLUSH_DONE;
1223 }
1224
Ben Hutchings8e730c12009-11-29 15:14:45 +00001225 return -ETIMEDOUT;
1226}
1227
1228/**************************************************************************
1229 *
1230 * Hardware interrupts
1231 * The hardware interrupt handler does very little work; all the event
1232 * queue processing is carried out by per-channel tasklets.
1233 *
1234 **************************************************************************/
1235
1236/* Enable/disable/generate interrupts */
1237static inline void efx_nic_interrupts(struct efx_nic *efx,
1238 bool enabled, bool force)
1239{
1240 efx_oword_t int_en_reg_ker;
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001241
1242 EFX_POPULATE_OWORD_3(int_en_reg_ker,
Steve Hodgson63695452010-04-28 09:27:36 +00001243 FRF_AZ_KER_INT_LEVE_SEL, efx->fatal_irq_level,
Ben Hutchings8e730c12009-11-29 15:14:45 +00001244 FRF_AZ_KER_INT_KER, force,
1245 FRF_AZ_DRV_INT_EN_KER, enabled);
1246 efx_writeo(efx, &int_en_reg_ker, FR_AZ_INT_EN_KER);
1247}
1248
1249void efx_nic_enable_interrupts(struct efx_nic *efx)
1250{
1251 struct efx_channel *channel;
1252
1253 EFX_ZERO_OWORD(*((efx_oword_t *) efx->irq_status.addr));
1254 wmb(); /* Ensure interrupt vector is clear before interrupts enabled */
1255
1256 /* Enable interrupts */
1257 efx_nic_interrupts(efx, true, false);
1258
1259 /* Force processing of all the channels to get the EVQ RPTRs up to
1260 date */
1261 efx_for_each_channel(channel, efx)
1262 efx_schedule_channel(channel);
1263}
1264
1265void efx_nic_disable_interrupts(struct efx_nic *efx)
1266{
1267 /* Disable interrupts */
1268 efx_nic_interrupts(efx, false, false);
1269}
1270
1271/* Generate a test interrupt
1272 * Interrupt must already have been enabled, otherwise nasty things
1273 * may happen.
1274 */
1275void efx_nic_generate_interrupt(struct efx_nic *efx)
1276{
1277 efx_nic_interrupts(efx, true, true);
1278}
1279
1280/* Process a fatal interrupt
1281 * Disable bus mastering ASAP and schedule a reset
1282 */
1283irqreturn_t efx_nic_fatal_interrupt(struct efx_nic *efx)
1284{
1285 struct falcon_nic_data *nic_data = efx->nic_data;
1286 efx_oword_t *int_ker = efx->irq_status.addr;
1287 efx_oword_t fatal_intr;
1288 int error, mem_perr;
1289
1290 efx_reado(efx, &fatal_intr, FR_AZ_FATAL_INTR_KER);
1291 error = EFX_OWORD_FIELD(fatal_intr, FRF_AZ_FATAL_INTR);
1292
1293 EFX_ERR(efx, "SYSTEM ERROR " EFX_OWORD_FMT " status "
1294 EFX_OWORD_FMT ": %s\n", EFX_OWORD_VAL(*int_ker),
1295 EFX_OWORD_VAL(fatal_intr),
1296 error ? "disabling bus mastering" : "no recognised error");
Ben Hutchings8e730c12009-11-29 15:14:45 +00001297
1298 /* If this is a memory parity error dump which blocks are offending */
Steve Hodgson97e1eaa2010-04-28 09:28:52 +00001299 mem_perr = (EFX_OWORD_FIELD(fatal_intr, FRF_AZ_MEM_PERR_INT_KER) ||
1300 EFX_OWORD_FIELD(fatal_intr, FRF_AZ_SRM_PERR_INT_KER));
Ben Hutchings8e730c12009-11-29 15:14:45 +00001301 if (mem_perr) {
1302 efx_oword_t reg;
1303 efx_reado(efx, &reg, FR_AZ_MEM_STAT);
1304 EFX_ERR(efx, "SYSTEM ERROR: memory parity error "
1305 EFX_OWORD_FMT "\n", EFX_OWORD_VAL(reg));
1306 }
1307
1308 /* Disable both devices */
1309 pci_clear_master(efx->pci_dev);
1310 if (efx_nic_is_dual_func(efx))
1311 pci_clear_master(nic_data->pci_dev2);
1312 efx_nic_disable_interrupts(efx);
1313
1314 /* Count errors and reset or disable the NIC accordingly */
1315 if (efx->int_error_count == 0 ||
1316 time_after(jiffies, efx->int_error_expire)) {
1317 efx->int_error_count = 0;
1318 efx->int_error_expire =
1319 jiffies + EFX_INT_ERROR_EXPIRE * HZ;
1320 }
1321 if (++efx->int_error_count < EFX_MAX_INT_ERRORS) {
1322 EFX_ERR(efx, "SYSTEM ERROR - reset scheduled\n");
1323 efx_schedule_reset(efx, RESET_TYPE_INT_ERROR);
1324 } else {
1325 EFX_ERR(efx, "SYSTEM ERROR - max number of errors seen."
1326 "NIC will be disabled\n");
1327 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
1328 }
Steve Hodgson63695452010-04-28 09:27:36 +00001329
Ben Hutchings8e730c12009-11-29 15:14:45 +00001330 return IRQ_HANDLED;
1331}
1332
1333/* Handle a legacy interrupt
1334 * Acknowledges the interrupt and schedule event queue processing.
1335 */
1336static irqreturn_t efx_legacy_interrupt(int irq, void *dev_id)
1337{
1338 struct efx_nic *efx = dev_id;
1339 efx_oword_t *int_ker = efx->irq_status.addr;
1340 irqreturn_t result = IRQ_NONE;
1341 struct efx_channel *channel;
1342 efx_dword_t reg;
1343 u32 queues;
1344 int syserr;
1345
1346 /* Read the ISR which also ACKs the interrupts */
1347 efx_readd(efx, &reg, FR_BZ_INT_ISR0);
1348 queues = EFX_EXTRACT_DWORD(reg, 0, 31);
1349
1350 /* Check to see if we have a serious error condition */
Steve Hodgson63695452010-04-28 09:27:36 +00001351 if (queues & (1U << efx->fatal_irq_level)) {
1352 syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
1353 if (unlikely(syserr))
1354 return efx_nic_fatal_interrupt(efx);
1355 }
Ben Hutchings8e730c12009-11-29 15:14:45 +00001356
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001357 if (queues != 0) {
1358 if (EFX_WORKAROUND_15783(efx))
1359 efx->irq_zero_count = 0;
1360
1361 /* Schedule processing of any interrupting queues */
1362 efx_for_each_channel(channel, efx) {
1363 if (queues & 1)
Ben Hutchings8e730c12009-11-29 15:14:45 +00001364 efx_schedule_channel(channel);
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001365 queues >>= 1;
Ben Hutchings8e730c12009-11-29 15:14:45 +00001366 }
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001367 result = IRQ_HANDLED;
1368
Steve Hodgson41b7e4c2010-04-28 09:28:27 +00001369 } else if (EFX_WORKAROUND_15783(efx)) {
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001370 efx_qword_t *event;
1371
Steve Hodgson41b7e4c2010-04-28 09:28:27 +00001372 /* We can't return IRQ_HANDLED more than once on seeing ISR=0
1373 * because this might be a shared interrupt. */
1374 if (efx->irq_zero_count++ == 0)
1375 result = IRQ_HANDLED;
1376
1377 /* Ensure we schedule or rearm all event queues */
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001378 efx_for_each_channel(channel, efx) {
1379 event = efx_event(channel, channel->eventq_read_ptr);
1380 if (efx_event_present(event))
1381 efx_schedule_channel(channel);
Steve Hodgson41b7e4c2010-04-28 09:28:27 +00001382 else
1383 efx_nic_eventq_read_ack(channel);
Ben Hutchings8880f4e2009-11-29 15:15:41 +00001384 }
Ben Hutchings8e730c12009-11-29 15:14:45 +00001385 }
1386
1387 if (result == IRQ_HANDLED) {
1388 efx->last_irq_cpu = raw_smp_processor_id();
1389 EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
1390 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
1391 }
1392
1393 return result;
1394}
1395
1396/* Handle an MSI interrupt
1397 *
1398 * Handle an MSI hardware interrupt. This routine schedules event
1399 * queue processing. No interrupt acknowledgement cycle is necessary.
1400 * Also, we never need to check that the interrupt is for us, since
1401 * MSI interrupts cannot be shared.
1402 */
1403static irqreturn_t efx_msi_interrupt(int irq, void *dev_id)
1404{
1405 struct efx_channel *channel = dev_id;
1406 struct efx_nic *efx = channel->efx;
1407 efx_oword_t *int_ker = efx->irq_status.addr;
1408 int syserr;
1409
1410 efx->last_irq_cpu = raw_smp_processor_id();
1411 EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
1412 irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
1413
1414 /* Check to see if we have a serious error condition */
Steve Hodgson63695452010-04-28 09:27:36 +00001415 if (channel->channel == efx->fatal_irq_level) {
1416 syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
1417 if (unlikely(syserr))
1418 return efx_nic_fatal_interrupt(efx);
1419 }
Ben Hutchings8e730c12009-11-29 15:14:45 +00001420
1421 /* Schedule processing of the channel */
1422 efx_schedule_channel(channel);
1423
1424 return IRQ_HANDLED;
1425}
1426
1427
1428/* Setup RSS indirection table.
1429 * This maps from the hash value of the packet to RXQ
1430 */
1431static void efx_setup_rss_indir_table(struct efx_nic *efx)
1432{
1433 int i = 0;
1434 unsigned long offset;
1435 efx_dword_t dword;
1436
1437 if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
1438 return;
1439
1440 for (offset = FR_BZ_RX_INDIRECTION_TBL;
1441 offset < FR_BZ_RX_INDIRECTION_TBL + 0x800;
1442 offset += 0x10) {
1443 EFX_POPULATE_DWORD_1(dword, FRF_BZ_IT_QUEUE,
Ben Hutchingsa4900ac2010-04-28 09:30:43 +00001444 i % efx->n_rx_channels);
Ben Hutchings8e730c12009-11-29 15:14:45 +00001445 efx_writed(efx, &dword, offset);
1446 i++;
1447 }
1448}
1449
1450/* Hook interrupt handler(s)
1451 * Try MSI and then legacy interrupts.
1452 */
1453int efx_nic_init_interrupt(struct efx_nic *efx)
1454{
1455 struct efx_channel *channel;
1456 int rc;
1457
1458 if (!EFX_INT_MODE_USE_MSI(efx)) {
1459 irq_handler_t handler;
1460 if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
1461 handler = efx_legacy_interrupt;
1462 else
1463 handler = falcon_legacy_interrupt_a1;
1464
1465 rc = request_irq(efx->legacy_irq, handler, IRQF_SHARED,
1466 efx->name, efx);
1467 if (rc) {
1468 EFX_ERR(efx, "failed to hook legacy IRQ %d\n",
1469 efx->pci_dev->irq);
1470 goto fail1;
1471 }
1472 return 0;
1473 }
1474
1475 /* Hook MSI or MSI-X interrupt */
1476 efx_for_each_channel(channel, efx) {
1477 rc = request_irq(channel->irq, efx_msi_interrupt,
1478 IRQF_PROBE_SHARED, /* Not shared */
1479 channel->name, channel);
1480 if (rc) {
1481 EFX_ERR(efx, "failed to hook IRQ %d\n", channel->irq);
1482 goto fail2;
1483 }
1484 }
1485
1486 return 0;
1487
1488 fail2:
1489 efx_for_each_channel(channel, efx)
1490 free_irq(channel->irq, channel);
1491 fail1:
1492 return rc;
1493}
1494
1495void efx_nic_fini_interrupt(struct efx_nic *efx)
1496{
1497 struct efx_channel *channel;
1498 efx_oword_t reg;
1499
1500 /* Disable MSI/MSI-X interrupts */
1501 efx_for_each_channel(channel, efx) {
1502 if (channel->irq)
1503 free_irq(channel->irq, channel);
1504 }
1505
1506 /* ACK legacy interrupt */
1507 if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
1508 efx_reado(efx, &reg, FR_BZ_INT_ISR0);
1509 else
1510 falcon_irq_ack_a1(efx);
1511
1512 /* Disable legacy interrupt */
1513 if (efx->legacy_irq)
1514 free_irq(efx->legacy_irq, efx);
1515}
1516
1517u32 efx_nic_fpga_ver(struct efx_nic *efx)
1518{
1519 efx_oword_t altera_build;
1520 efx_reado(efx, &altera_build, FR_AZ_ALTERA_BUILD);
1521 return EFX_OWORD_FIELD(altera_build, FRF_AZ_ALTERA_BUILD_VER);
1522}
1523
1524void efx_nic_init_common(struct efx_nic *efx)
1525{
1526 efx_oword_t temp;
1527
1528 /* Set positions of descriptor caches in SRAM. */
1529 EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_TX_DC_BASE_ADR,
1530 efx->type->tx_dc_base / 8);
1531 efx_writeo(efx, &temp, FR_AZ_SRM_TX_DC_CFG);
1532 EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_RX_DC_BASE_ADR,
1533 efx->type->rx_dc_base / 8);
1534 efx_writeo(efx, &temp, FR_AZ_SRM_RX_DC_CFG);
1535
1536 /* Set TX descriptor cache size. */
1537 BUILD_BUG_ON(TX_DC_ENTRIES != (8 << TX_DC_ENTRIES_ORDER));
1538 EFX_POPULATE_OWORD_1(temp, FRF_AZ_TX_DC_SIZE, TX_DC_ENTRIES_ORDER);
1539 efx_writeo(efx, &temp, FR_AZ_TX_DC_CFG);
1540
1541 /* Set RX descriptor cache size. Set low watermark to size-8, as
1542 * this allows most efficient prefetching.
1543 */
1544 BUILD_BUG_ON(RX_DC_ENTRIES != (8 << RX_DC_ENTRIES_ORDER));
1545 EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_SIZE, RX_DC_ENTRIES_ORDER);
1546 efx_writeo(efx, &temp, FR_AZ_RX_DC_CFG);
1547 EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_PF_LWM, RX_DC_ENTRIES - 8);
1548 efx_writeo(efx, &temp, FR_AZ_RX_DC_PF_WM);
1549
1550 /* Program INT_KER address */
1551 EFX_POPULATE_OWORD_2(temp,
1552 FRF_AZ_NORM_INT_VEC_DIS_KER,
1553 EFX_INT_MODE_USE_MSI(efx),
1554 FRF_AZ_INT_ADR_KER, efx->irq_status.dma_addr);
1555 efx_writeo(efx, &temp, FR_AZ_INT_ADR_KER);
1556
Steve Hodgson63695452010-04-28 09:27:36 +00001557 if (EFX_WORKAROUND_17213(efx) && !EFX_INT_MODE_USE_MSI(efx))
1558 /* Use an interrupt level unused by event queues */
1559 efx->fatal_irq_level = 0x1f;
1560 else
1561 /* Use a valid MSI-X vector */
1562 efx->fatal_irq_level = 0;
1563
Ben Hutchings8e730c12009-11-29 15:14:45 +00001564 /* Enable all the genuinely fatal interrupts. (They are still
1565 * masked by the overall interrupt mask, controlled by
1566 * falcon_interrupts()).
1567 *
1568 * Note: All other fatal interrupts are enabled
1569 */
1570 EFX_POPULATE_OWORD_3(temp,
1571 FRF_AZ_ILL_ADR_INT_KER_EN, 1,
1572 FRF_AZ_RBUF_OWN_INT_KER_EN, 1,
1573 FRF_AZ_TBUF_OWN_INT_KER_EN, 1);
Steve Hodgsonb17424b2010-04-28 09:25:22 +00001574 if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
1575 EFX_SET_OWORD_FIELD(temp, FRF_CZ_SRAM_PERR_INT_P_KER_EN, 1);
Ben Hutchings8e730c12009-11-29 15:14:45 +00001576 EFX_INVERT_OWORD(temp);
1577 efx_writeo(efx, &temp, FR_AZ_FATAL_INTR_KER);
1578
1579 efx_setup_rss_indir_table(efx);
1580
1581 /* Disable the ugly timer-based TX DMA backoff and allow TX DMA to be
1582 * controlled by the RX FIFO fill level. Set arbitration to one pkt/Q.
1583 */
1584 efx_reado(efx, &temp, FR_AZ_TX_RESERVED);
1585 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER, 0xfe);
1586 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER_EN, 1);
1587 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_ONE_PKT_PER_Q, 1);
1588 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PUSH_EN, 0);
1589 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_DIS_NON_IP_EV, 1);
1590 /* Enable SW_EV to inherit in char driver - assume harmless here */
1591 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_SOFT_EVT_EN, 1);
1592 /* Prefetch threshold 2 => fetch when descriptor cache half empty */
1593 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_THRESHOLD, 2);
Ben Hutchings286d47b2009-12-23 13:49:13 +00001594 /* Disable hardware watchdog which can misfire */
1595 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_WD_TMR, 0x3fffff);
Ben Hutchings8e730c12009-11-29 15:14:45 +00001596 /* Squash TX of packets of 16 bytes or less */
1597 if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
1598 EFX_SET_OWORD_FIELD(temp, FRF_BZ_TX_FLUSH_MIN_LEN_EN, 1);
1599 efx_writeo(efx, &temp, FR_AZ_TX_RESERVED);
1600}