blob: 539d0223b4347fcddea834543e7a0238f9a38d39 [file] [log] [blame]
Ben Hutchings8ceee662008-04-27 12:55:59 +01001/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2008 Solarflare Communications Inc.
5 *
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>
Ben Hutchings37b5a602008-05-30 22:27:04 +010016#include <linux/i2c.h>
Ben Hutchingsf31a45d2008-12-12 21:43:33 -080017#include <linux/mii.h>
Ben Hutchings8ceee662008-04-27 12:55:59 +010018#include "net_driver.h"
19#include "bitfield.h"
20#include "efx.h"
21#include "mac.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010022#include "spi.h"
23#include "falcon.h"
Ben Hutchings3e6c4532009-10-23 08:30:36 +000024#include "regs.h"
Ben Hutchings12d00ca2009-10-23 08:30:46 +000025#include "io.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010026#include "mdio_10g.h"
27#include "phy.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010028#include "workarounds.h"
29
Ben Hutchings89863522009-11-25 16:09:04 +000030/* Hardware control for SFC4000 (aka Falcon). */
Ben Hutchings8ceee662008-04-27 12:55:59 +010031
Ben Hutchings8ceee662008-04-27 12:55:59 +010032/**************************************************************************
33 *
34 * Configurable values
35 *
36 **************************************************************************
37 */
38
Ben Hutchings8ceee662008-04-27 12:55:59 +010039/* This is set to 16 for a good reason. In summary, if larger than
40 * 16, the descriptor cache holds more than a default socket
41 * buffer's worth of packets (for UDP we can only have at most one
42 * socket buffer's worth outstanding). This combined with the fact
43 * that we only get 1 TX event per descriptor cache means the NIC
44 * goes idle.
45 */
46#define TX_DC_ENTRIES 16
Ben Hutchings46e1ac02009-11-25 16:08:30 +000047#define TX_DC_ENTRIES_ORDER 1
Ben Hutchings8ceee662008-04-27 12:55:59 +010048
49#define RX_DC_ENTRIES 64
Ben Hutchings46e1ac02009-11-25 16:08:30 +000050#define RX_DC_ENTRIES_ORDER 3
Ben Hutchings8ceee662008-04-27 12:55:59 +010051
Ben Hutchings2f7f5732008-12-12 21:34:25 -080052static const unsigned int
53/* "Large" EEPROM device: Atmel AT25640 or similar
54 * 8 KB, 16-bit address, 32 B write block */
55large_eeprom_type = ((13 << SPI_DEV_TYPE_SIZE_LBN)
56 | (2 << SPI_DEV_TYPE_ADDR_LEN_LBN)
57 | (5 << SPI_DEV_TYPE_BLOCK_SIZE_LBN)),
58/* Default flash device: Atmel AT25F1024
59 * 128 KB, 24-bit address, 32 KB erase block, 256 B write block */
60default_flash_type = ((17 << SPI_DEV_TYPE_SIZE_LBN)
61 | (3 << SPI_DEV_TYPE_ADDR_LEN_LBN)
62 | (0x52 << SPI_DEV_TYPE_ERASE_CMD_LBN)
63 | (15 << SPI_DEV_TYPE_ERASE_SIZE_LBN)
64 | (8 << SPI_DEV_TYPE_BLOCK_SIZE_LBN));
65
Ben Hutchings8ceee662008-04-27 12:55:59 +010066/* RX FIFO XOFF watermark
67 *
68 * When the amount of the RX FIFO increases used increases past this
69 * watermark send XOFF. Only used if RX flow control is enabled (ethtool -A)
70 * This also has an effect on RX/TX arbitration
71 */
72static int rx_xoff_thresh_bytes = -1;
73module_param(rx_xoff_thresh_bytes, int, 0644);
74MODULE_PARM_DESC(rx_xoff_thresh_bytes, "RX fifo XOFF threshold");
75
76/* RX FIFO XON watermark
77 *
78 * When the amount of the RX FIFO used decreases below this
79 * watermark send XON. Only used if TX flow control is enabled (ethtool -A)
80 * This also has an effect on RX/TX arbitration
81 */
82static int rx_xon_thresh_bytes = -1;
83module_param(rx_xon_thresh_bytes, int, 0644);
84MODULE_PARM_DESC(rx_xon_thresh_bytes, "RX fifo XON threshold");
85
Ben Hutchings2c3c3d02009-03-04 10:01:57 +000086/* If FALCON_MAX_INT_ERRORS internal errors occur within
87 * FALCON_INT_ERROR_EXPIRE seconds, we consider the NIC broken and
88 * disable it.
89 */
90#define FALCON_INT_ERROR_EXPIRE 3600
91#define FALCON_MAX_INT_ERRORS 5
Ben Hutchings8ceee662008-04-27 12:55:59 +010092
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +010093/* We poll for events every FLUSH_INTERVAL ms, and check FLUSH_POLL_COUNT times
94 */
95#define FALCON_FLUSH_INTERVAL 10
96#define FALCON_FLUSH_POLL_COUNT 100
Ben Hutchings8ceee662008-04-27 12:55:59 +010097
98/**************************************************************************
99 *
100 * Falcon constants
101 *
102 **************************************************************************
103 */
104
Ben Hutchings8ceee662008-04-27 12:55:59 +0100105/* Size and alignment of special buffers (4KB) */
106#define FALCON_BUF_SIZE 4096
107
Ben Hutchings127e6e12009-11-25 16:09:55 +0000108/* Depth of RX flush request fifo */
109#define FALCON_RX_FLUSH_COUNT 4
110
Ben Hutchings8ceee662008-04-27 12:55:59 +0100111#define FALCON_IS_DUAL_FUNC(efx) \
Ben Hutchingsdaeda632009-11-28 05:36:04 +0000112 (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100113
114/**************************************************************************
115 *
116 * Falcon hardware access
117 *
118 **************************************************************************/
119
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000120static inline void falcon_write_buf_tbl(struct efx_nic *efx, efx_qword_t *value,
121 unsigned int index)
122{
123 efx_sram_writeq(efx, efx->membase + efx->type->buf_tbl_base,
124 value, index);
125}
126
Ben Hutchings8ceee662008-04-27 12:55:59 +0100127/* Read the current event from the event queue */
128static inline efx_qword_t *falcon_event(struct efx_channel *channel,
129 unsigned int index)
130{
131 return (((efx_qword_t *) (channel->eventq.addr)) + index);
132}
133
134/* See if an event is present
135 *
136 * We check both the high and low dword of the event for all ones. We
137 * wrote all ones when we cleared the event, and no valid event can
138 * have all ones in either its high or low dwords. This approach is
139 * robust against reordering.
140 *
141 * Note that using a single 64-bit comparison is incorrect; even
142 * though the CPU read will be atomic, the DMA write may not be.
143 */
144static inline int falcon_event_present(efx_qword_t *event)
145{
146 return (!(EFX_DWORD_IS_ALL_ONES(event->dword[0]) |
147 EFX_DWORD_IS_ALL_ONES(event->dword[1])));
148}
149
150/**************************************************************************
151 *
152 * I2C bus - this is a bit-bashing interface using GPIO pins
153 * Note that it uses the output enables to tristate the outputs
154 * SDA is the data pin and SCL is the clock
155 *
156 **************************************************************************
157 */
Ben Hutchings37b5a602008-05-30 22:27:04 +0100158static void falcon_setsda(void *data, int state)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100159{
Ben Hutchings37b5a602008-05-30 22:27:04 +0100160 struct efx_nic *efx = (struct efx_nic *)data;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100161 efx_oword_t reg;
162
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000163 efx_reado(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000164 EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO3_OEN, !state);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000165 efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100166}
167
Ben Hutchings37b5a602008-05-30 22:27:04 +0100168static void falcon_setscl(void *data, int state)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100169{
Ben Hutchings37b5a602008-05-30 22:27:04 +0100170 struct efx_nic *efx = (struct efx_nic *)data;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100171 efx_oword_t reg;
172
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000173 efx_reado(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000174 EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO0_OEN, !state);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000175 efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchings37b5a602008-05-30 22:27:04 +0100176}
177
178static int falcon_getsda(void *data)
179{
180 struct efx_nic *efx = (struct efx_nic *)data;
181 efx_oword_t reg;
182
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000183 efx_reado(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000184 return EFX_OWORD_FIELD(reg, FRF_AB_GPIO3_IN);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100185}
186
Ben Hutchings37b5a602008-05-30 22:27:04 +0100187static int falcon_getscl(void *data)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100188{
Ben Hutchings37b5a602008-05-30 22:27:04 +0100189 struct efx_nic *efx = (struct efx_nic *)data;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100190 efx_oword_t reg;
191
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000192 efx_reado(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000193 return EFX_OWORD_FIELD(reg, FRF_AB_GPIO0_IN);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100194}
195
Ben Hutchings37b5a602008-05-30 22:27:04 +0100196static struct i2c_algo_bit_data falcon_i2c_bit_operations = {
197 .setsda = falcon_setsda,
198 .setscl = falcon_setscl,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100199 .getsda = falcon_getsda,
200 .getscl = falcon_getscl,
Ben Hutchings62c78322008-05-30 22:27:46 +0100201 .udelay = 5,
Ben Hutchings9dadae62008-07-18 18:59:12 +0100202 /* Wait up to 50 ms for slave to let us pull SCL high */
203 .timeout = DIV_ROUND_UP(HZ, 20),
Ben Hutchings8ceee662008-04-27 12:55:59 +0100204};
205
206/**************************************************************************
207 *
208 * Falcon special buffer handling
209 * Special buffers are used for event queues and the TX and RX
210 * descriptor rings.
211 *
212 *************************************************************************/
213
214/*
215 * Initialise a Falcon special buffer
216 *
217 * This will define a buffer (previously allocated via
218 * falcon_alloc_special_buffer()) in Falcon's buffer table, allowing
219 * it to be used for event queues, descriptor rings etc.
220 */
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100221static void
Ben Hutchings8ceee662008-04-27 12:55:59 +0100222falcon_init_special_buffer(struct efx_nic *efx,
223 struct efx_special_buffer *buffer)
224{
225 efx_qword_t buf_desc;
226 int index;
227 dma_addr_t dma_addr;
228 int i;
229
230 EFX_BUG_ON_PARANOID(!buffer->addr);
231
232 /* Write buffer descriptors to NIC */
233 for (i = 0; i < buffer->entries; i++) {
234 index = buffer->index + i;
235 dma_addr = buffer->dma_addr + (i * 4096);
236 EFX_LOG(efx, "mapping special buffer %d at %llx\n",
237 index, (unsigned long long)dma_addr);
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000238 EFX_POPULATE_QWORD_3(buf_desc,
239 FRF_AZ_BUF_ADR_REGION, 0,
240 FRF_AZ_BUF_ADR_FBUF, dma_addr >> 12,
241 FRF_AZ_BUF_OWNER_ID_FBUF, 0);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000242 falcon_write_buf_tbl(efx, &buf_desc, index);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100243 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100244}
245
246/* Unmaps a buffer from Falcon and clears the buffer table entries */
247static void
248falcon_fini_special_buffer(struct efx_nic *efx,
249 struct efx_special_buffer *buffer)
250{
251 efx_oword_t buf_tbl_upd;
252 unsigned int start = buffer->index;
253 unsigned int end = (buffer->index + buffer->entries - 1);
254
255 if (!buffer->entries)
256 return;
257
258 EFX_LOG(efx, "unmapping special buffers %d-%d\n",
259 buffer->index, buffer->index + buffer->entries - 1);
260
261 EFX_POPULATE_OWORD_4(buf_tbl_upd,
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000262 FRF_AZ_BUF_UPD_CMD, 0,
263 FRF_AZ_BUF_CLR_CMD, 1,
264 FRF_AZ_BUF_CLR_END_ID, end,
265 FRF_AZ_BUF_CLR_START_ID, start);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000266 efx_writeo(efx, &buf_tbl_upd, FR_AZ_BUF_TBL_UPD);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100267}
268
269/*
270 * Allocate a new Falcon special buffer
271 *
272 * This allocates memory for a new buffer, clears it and allocates a
273 * new buffer ID range. It does not write into Falcon's buffer table.
274 *
275 * This call will allocate 4KB buffers, since Falcon can't use 8KB
276 * buffers for event queues and descriptor rings.
277 */
278static int falcon_alloc_special_buffer(struct efx_nic *efx,
279 struct efx_special_buffer *buffer,
280 unsigned int len)
281{
Ben Hutchings8ceee662008-04-27 12:55:59 +0100282 len = ALIGN(len, FALCON_BUF_SIZE);
283
284 buffer->addr = pci_alloc_consistent(efx->pci_dev, len,
285 &buffer->dma_addr);
286 if (!buffer->addr)
287 return -ENOMEM;
288 buffer->len = len;
289 buffer->entries = len / FALCON_BUF_SIZE;
290 BUG_ON(buffer->dma_addr & (FALCON_BUF_SIZE - 1));
291
292 /* All zeros is a potentially valid event so memset to 0xff */
293 memset(buffer->addr, 0xff, len);
294
295 /* Select new buffer ID */
Ben Hutchings0484e0d2009-10-23 08:32:04 +0000296 buffer->index = efx->next_buffer_table;
297 efx->next_buffer_table += buffer->entries;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100298
299 EFX_LOG(efx, "allocating special buffers %d-%d at %llx+%x "
Jaswinder Singh Rajput9c8976a2009-02-11 23:49:52 +0530300 "(virt %p phys %llx)\n", buffer->index,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100301 buffer->index + buffer->entries - 1,
Jaswinder Singh Rajput9c8976a2009-02-11 23:49:52 +0530302 (u64)buffer->dma_addr, len,
303 buffer->addr, (u64)virt_to_phys(buffer->addr));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100304
305 return 0;
306}
307
308static void falcon_free_special_buffer(struct efx_nic *efx,
309 struct efx_special_buffer *buffer)
310{
311 if (!buffer->addr)
312 return;
313
314 EFX_LOG(efx, "deallocating special buffers %d-%d at %llx+%x "
Jaswinder Singh Rajput9c8976a2009-02-11 23:49:52 +0530315 "(virt %p phys %llx)\n", buffer->index,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100316 buffer->index + buffer->entries - 1,
Jaswinder Singh Rajput9c8976a2009-02-11 23:49:52 +0530317 (u64)buffer->dma_addr, buffer->len,
318 buffer->addr, (u64)virt_to_phys(buffer->addr));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100319
320 pci_free_consistent(efx->pci_dev, buffer->len, buffer->addr,
321 buffer->dma_addr);
322 buffer->addr = NULL;
323 buffer->entries = 0;
324}
325
326/**************************************************************************
327 *
328 * Falcon generic buffer handling
329 * These buffers are used for interrupt status and MAC stats
330 *
331 **************************************************************************/
332
333static int falcon_alloc_buffer(struct efx_nic *efx,
334 struct efx_buffer *buffer, unsigned int len)
335{
336 buffer->addr = pci_alloc_consistent(efx->pci_dev, len,
337 &buffer->dma_addr);
338 if (!buffer->addr)
339 return -ENOMEM;
340 buffer->len = len;
341 memset(buffer->addr, 0, len);
342 return 0;
343}
344
345static void falcon_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer)
346{
347 if (buffer->addr) {
348 pci_free_consistent(efx->pci_dev, buffer->len,
349 buffer->addr, buffer->dma_addr);
350 buffer->addr = NULL;
351 }
352}
353
354/**************************************************************************
355 *
356 * Falcon TX path
357 *
358 **************************************************************************/
359
360/* Returns a pointer to the specified transmit descriptor in the TX
361 * descriptor queue belonging to the specified channel.
362 */
363static inline efx_qword_t *falcon_tx_desc(struct efx_tx_queue *tx_queue,
364 unsigned int index)
365{
366 return (((efx_qword_t *) (tx_queue->txd.addr)) + index);
367}
368
369/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
370static inline void falcon_notify_tx_desc(struct efx_tx_queue *tx_queue)
371{
372 unsigned write_ptr;
373 efx_dword_t reg;
374
Ben Hutchings3ffeabd2009-10-23 08:30:58 +0000375 write_ptr = tx_queue->write_count & EFX_TXQ_MASK;
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000376 EFX_POPULATE_DWORD_1(reg, FRF_AZ_TX_DESC_WPTR_DWORD, write_ptr);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000377 efx_writed_page(tx_queue->efx, &reg,
378 FR_AZ_TX_DESC_UPD_DWORD_P0, tx_queue->queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100379}
380
381
382/* For each entry inserted into the software descriptor ring, create a
383 * descriptor in the hardware TX descriptor ring (in host memory), and
384 * write a doorbell.
385 */
386void falcon_push_buffers(struct efx_tx_queue *tx_queue)
387{
388
389 struct efx_tx_buffer *buffer;
390 efx_qword_t *txd;
391 unsigned write_ptr;
392
393 BUG_ON(tx_queue->write_count == tx_queue->insert_count);
394
395 do {
Ben Hutchings3ffeabd2009-10-23 08:30:58 +0000396 write_ptr = tx_queue->write_count & EFX_TXQ_MASK;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100397 buffer = &tx_queue->buffer[write_ptr];
398 txd = falcon_tx_desc(tx_queue, write_ptr);
399 ++tx_queue->write_count;
400
401 /* Create TX descriptor ring entry */
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000402 EFX_POPULATE_QWORD_4(*txd,
403 FSF_AZ_TX_KER_CONT, buffer->continuation,
404 FSF_AZ_TX_KER_BYTE_COUNT, buffer->len,
405 FSF_AZ_TX_KER_BUF_REGION, 0,
406 FSF_AZ_TX_KER_BUF_ADDR, buffer->dma_addr);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100407 } while (tx_queue->write_count != tx_queue->insert_count);
408
409 wmb(); /* Ensure descriptors are written before they are fetched */
410 falcon_notify_tx_desc(tx_queue);
411}
412
413/* Allocate hardware resources for a TX queue */
414int falcon_probe_tx(struct efx_tx_queue *tx_queue)
415{
416 struct efx_nic *efx = tx_queue->efx;
Ben Hutchings3ffeabd2009-10-23 08:30:58 +0000417 BUILD_BUG_ON(EFX_TXQ_SIZE < 512 || EFX_TXQ_SIZE > 4096 ||
418 EFX_TXQ_SIZE & EFX_TXQ_MASK);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100419 return falcon_alloc_special_buffer(efx, &tx_queue->txd,
Ben Hutchings3ffeabd2009-10-23 08:30:58 +0000420 EFX_TXQ_SIZE * sizeof(efx_qword_t));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100421}
422
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100423void falcon_init_tx(struct efx_tx_queue *tx_queue)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100424{
425 efx_oword_t tx_desc_ptr;
426 struct efx_nic *efx = tx_queue->efx;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100427
Ben Hutchings127e6e12009-11-25 16:09:55 +0000428 tx_queue->flushed = FLUSH_NONE;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100429
Ben Hutchings8ceee662008-04-27 12:55:59 +0100430 /* Pin TX descriptor ring */
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100431 falcon_init_special_buffer(efx, &tx_queue->txd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100432
433 /* Push TX descriptor ring to card */
434 EFX_POPULATE_OWORD_10(tx_desc_ptr,
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000435 FRF_AZ_TX_DESCQ_EN, 1,
436 FRF_AZ_TX_ISCSI_DDIG_EN, 0,
437 FRF_AZ_TX_ISCSI_HDIG_EN, 0,
438 FRF_AZ_TX_DESCQ_BUF_BASE_ID, tx_queue->txd.index,
439 FRF_AZ_TX_DESCQ_EVQ_ID,
440 tx_queue->channel->channel,
441 FRF_AZ_TX_DESCQ_OWNER_ID, 0,
442 FRF_AZ_TX_DESCQ_LABEL, tx_queue->queue,
Ben Hutchings3ffeabd2009-10-23 08:30:58 +0000443 FRF_AZ_TX_DESCQ_SIZE,
444 __ffs(tx_queue->txd.entries),
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000445 FRF_AZ_TX_DESCQ_TYPE, 0,
446 FRF_BZ_TX_NON_IP_DROP_DIS, 1);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100447
Ben Hutchingsdaeda632009-11-28 05:36:04 +0000448 if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
Ben Hutchings60ac1062008-09-01 12:44:59 +0100449 int csum = tx_queue->queue == EFX_TX_QUEUE_OFFLOAD_CSUM;
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000450 EFX_SET_OWORD_FIELD(tx_desc_ptr, FRF_BZ_TX_IP_CHKSM_DIS, !csum);
451 EFX_SET_OWORD_FIELD(tx_desc_ptr, FRF_BZ_TX_TCP_CHKSM_DIS,
452 !csum);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100453 }
454
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000455 efx_writeo_table(efx, &tx_desc_ptr, efx->type->txd_ptr_tbl_base,
456 tx_queue->queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100457
Ben Hutchingsdaeda632009-11-28 05:36:04 +0000458 if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100459 efx_oword_t reg;
460
Ben Hutchings60ac1062008-09-01 12:44:59 +0100461 /* Only 128 bits in this register */
462 BUILD_BUG_ON(EFX_TX_QUEUE_COUNT >= 128);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100463
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000464 efx_reado(efx, &reg, FR_AA_TX_CHKSM_CFG);
Ben Hutchings60ac1062008-09-01 12:44:59 +0100465 if (tx_queue->queue == EFX_TX_QUEUE_OFFLOAD_CSUM)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100466 clear_bit_le(tx_queue->queue, (void *)&reg);
467 else
468 set_bit_le(tx_queue->queue, (void *)&reg);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000469 efx_writeo(efx, &reg, FR_AA_TX_CHKSM_CFG);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100470 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100471}
472
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100473static void falcon_flush_tx_queue(struct efx_tx_queue *tx_queue)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100474{
475 struct efx_nic *efx = tx_queue->efx;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100476 efx_oword_t tx_flush_descq;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100477
Ben Hutchings127e6e12009-11-25 16:09:55 +0000478 tx_queue->flushed = FLUSH_PENDING;
479
Ben Hutchings8ceee662008-04-27 12:55:59 +0100480 /* Post a flush command */
481 EFX_POPULATE_OWORD_2(tx_flush_descq,
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000482 FRF_AZ_TX_FLUSH_DESCQ_CMD, 1,
483 FRF_AZ_TX_FLUSH_DESCQ, tx_queue->queue);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000484 efx_writeo(efx, &tx_flush_descq, FR_AZ_TX_FLUSH_DESCQ);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100485}
486
487void falcon_fini_tx(struct efx_tx_queue *tx_queue)
488{
489 struct efx_nic *efx = tx_queue->efx;
490 efx_oword_t tx_desc_ptr;
491
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100492 /* The queue should have been flushed */
Ben Hutchings127e6e12009-11-25 16:09:55 +0000493 WARN_ON(tx_queue->flushed != FLUSH_DONE);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100494
495 /* Remove TX descriptor ring from card */
496 EFX_ZERO_OWORD(tx_desc_ptr);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000497 efx_writeo_table(efx, &tx_desc_ptr, efx->type->txd_ptr_tbl_base,
498 tx_queue->queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100499
500 /* Unpin TX descriptor ring */
501 falcon_fini_special_buffer(efx, &tx_queue->txd);
502}
503
504/* Free buffers backing TX queue */
505void falcon_remove_tx(struct efx_tx_queue *tx_queue)
506{
507 falcon_free_special_buffer(tx_queue->efx, &tx_queue->txd);
508}
509
510/**************************************************************************
511 *
512 * Falcon RX path
513 *
514 **************************************************************************/
515
516/* Returns a pointer to the specified descriptor in the RX descriptor queue */
517static inline efx_qword_t *falcon_rx_desc(struct efx_rx_queue *rx_queue,
518 unsigned int index)
519{
520 return (((efx_qword_t *) (rx_queue->rxd.addr)) + index);
521}
522
523/* This creates an entry in the RX descriptor queue */
524static inline void falcon_build_rx_desc(struct efx_rx_queue *rx_queue,
525 unsigned index)
526{
527 struct efx_rx_buffer *rx_buf;
528 efx_qword_t *rxd;
529
530 rxd = falcon_rx_desc(rx_queue, index);
531 rx_buf = efx_rx_buffer(rx_queue, index);
532 EFX_POPULATE_QWORD_3(*rxd,
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000533 FSF_AZ_RX_KER_BUF_SIZE,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100534 rx_buf->len -
535 rx_queue->efx->type->rx_buffer_padding,
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000536 FSF_AZ_RX_KER_BUF_REGION, 0,
537 FSF_AZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100538}
539
540/* This writes to the RX_DESC_WPTR register for the specified receive
541 * descriptor ring.
542 */
543void falcon_notify_rx_desc(struct efx_rx_queue *rx_queue)
544{
545 efx_dword_t reg;
546 unsigned write_ptr;
547
548 while (rx_queue->notified_count != rx_queue->added_count) {
549 falcon_build_rx_desc(rx_queue,
550 rx_queue->notified_count &
Ben Hutchings3ffeabd2009-10-23 08:30:58 +0000551 EFX_RXQ_MASK);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100552 ++rx_queue->notified_count;
553 }
554
555 wmb();
Ben Hutchings3ffeabd2009-10-23 08:30:58 +0000556 write_ptr = rx_queue->added_count & EFX_RXQ_MASK;
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000557 EFX_POPULATE_DWORD_1(reg, FRF_AZ_RX_DESC_WPTR_DWORD, write_ptr);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000558 efx_writed_page(rx_queue->efx, &reg,
559 FR_AZ_RX_DESC_UPD_DWORD_P0, rx_queue->queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100560}
561
562int falcon_probe_rx(struct efx_rx_queue *rx_queue)
563{
564 struct efx_nic *efx = rx_queue->efx;
Ben Hutchings3ffeabd2009-10-23 08:30:58 +0000565 BUILD_BUG_ON(EFX_RXQ_SIZE < 512 || EFX_RXQ_SIZE > 4096 ||
566 EFX_RXQ_SIZE & EFX_RXQ_MASK);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100567 return falcon_alloc_special_buffer(efx, &rx_queue->rxd,
Ben Hutchings3ffeabd2009-10-23 08:30:58 +0000568 EFX_RXQ_SIZE * sizeof(efx_qword_t));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100569}
570
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100571void falcon_init_rx(struct efx_rx_queue *rx_queue)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100572{
573 efx_oword_t rx_desc_ptr;
574 struct efx_nic *efx = rx_queue->efx;
Ben Hutchingsdaeda632009-11-28 05:36:04 +0000575 bool is_b0 = efx_nic_rev(efx) >= EFX_REV_FALCON_B0;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100576 bool iscsi_digest_en = is_b0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100577
578 EFX_LOG(efx, "RX queue %d ring in special buffers %d-%d\n",
579 rx_queue->queue, rx_queue->rxd.index,
580 rx_queue->rxd.index + rx_queue->rxd.entries - 1);
581
Ben Hutchings127e6e12009-11-25 16:09:55 +0000582 rx_queue->flushed = FLUSH_NONE;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100583
Ben Hutchings8ceee662008-04-27 12:55:59 +0100584 /* Pin RX descriptor ring */
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100585 falcon_init_special_buffer(efx, &rx_queue->rxd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100586
587 /* Push RX descriptor ring to card */
588 EFX_POPULATE_OWORD_10(rx_desc_ptr,
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000589 FRF_AZ_RX_ISCSI_DDIG_EN, iscsi_digest_en,
590 FRF_AZ_RX_ISCSI_HDIG_EN, iscsi_digest_en,
591 FRF_AZ_RX_DESCQ_BUF_BASE_ID, rx_queue->rxd.index,
592 FRF_AZ_RX_DESCQ_EVQ_ID,
593 rx_queue->channel->channel,
594 FRF_AZ_RX_DESCQ_OWNER_ID, 0,
595 FRF_AZ_RX_DESCQ_LABEL, rx_queue->queue,
Ben Hutchings3ffeabd2009-10-23 08:30:58 +0000596 FRF_AZ_RX_DESCQ_SIZE,
597 __ffs(rx_queue->rxd.entries),
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000598 FRF_AZ_RX_DESCQ_TYPE, 0 /* kernel queue */ ,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100599 /* For >=B0 this is scatter so disable */
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000600 FRF_AZ_RX_DESCQ_JUMBO, !is_b0,
601 FRF_AZ_RX_DESCQ_EN, 1);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000602 efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base,
603 rx_queue->queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100604}
605
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100606static void falcon_flush_rx_queue(struct efx_rx_queue *rx_queue)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100607{
608 struct efx_nic *efx = rx_queue->efx;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100609 efx_oword_t rx_flush_descq;
610
Ben Hutchings127e6e12009-11-25 16:09:55 +0000611 rx_queue->flushed = FLUSH_PENDING;
612
Ben Hutchings8ceee662008-04-27 12:55:59 +0100613 /* Post a flush command */
614 EFX_POPULATE_OWORD_2(rx_flush_descq,
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000615 FRF_AZ_RX_FLUSH_DESCQ_CMD, 1,
616 FRF_AZ_RX_FLUSH_DESCQ, rx_queue->queue);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000617 efx_writeo(efx, &rx_flush_descq, FR_AZ_RX_FLUSH_DESCQ);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100618}
619
620void falcon_fini_rx(struct efx_rx_queue *rx_queue)
621{
622 efx_oword_t rx_desc_ptr;
623 struct efx_nic *efx = rx_queue->efx;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100624
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100625 /* The queue should already have been flushed */
Ben Hutchings127e6e12009-11-25 16:09:55 +0000626 WARN_ON(rx_queue->flushed != FLUSH_DONE);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100627
628 /* Remove RX descriptor ring from card */
629 EFX_ZERO_OWORD(rx_desc_ptr);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000630 efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base,
631 rx_queue->queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100632
633 /* Unpin RX descriptor ring */
634 falcon_fini_special_buffer(efx, &rx_queue->rxd);
635}
636
637/* Free buffers backing RX queue */
638void falcon_remove_rx(struct efx_rx_queue *rx_queue)
639{
640 falcon_free_special_buffer(rx_queue->efx, &rx_queue->rxd);
641}
642
643/**************************************************************************
644 *
645 * Falcon event queue processing
646 * Event queues are processed by per-channel tasklets.
647 *
648 **************************************************************************/
649
650/* Update a channel's event queue's read pointer (RPTR) register
651 *
652 * This writes the EVQ_RPTR_REG register for the specified channel's
653 * event queue.
654 *
655 * Note that EVQ_RPTR_REG contains the index of the "last read" event,
656 * whereas channel->eventq_read_ptr contains the index of the "next to
657 * read" event.
658 */
659void falcon_eventq_read_ack(struct efx_channel *channel)
660{
661 efx_dword_t reg;
662 struct efx_nic *efx = channel->efx;
663
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000664 EFX_POPULATE_DWORD_1(reg, FRF_AZ_EVQ_RPTR, channel->eventq_read_ptr);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000665 efx_writed_table(efx, &reg, efx->type->evq_rptr_tbl_base,
Ben Hutchingsd3074022008-09-01 12:48:03 +0100666 channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100667}
668
669/* Use HW to insert a SW defined event */
670void falcon_generate_event(struct efx_channel *channel, efx_qword_t *event)
671{
672 efx_oword_t drv_ev_reg;
673
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000674 BUILD_BUG_ON(FRF_AZ_DRV_EV_DATA_LBN != 0 ||
675 FRF_AZ_DRV_EV_DATA_WIDTH != 64);
676 drv_ev_reg.u32[0] = event->u32[0];
677 drv_ev_reg.u32[1] = event->u32[1];
678 drv_ev_reg.u32[2] = 0;
679 drv_ev_reg.u32[3] = 0;
680 EFX_SET_OWORD_FIELD(drv_ev_reg, FRF_AZ_DRV_EV_QID, channel->channel);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000681 efx_writeo(channel->efx, &drv_ev_reg, FR_AZ_DRV_EV);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100682}
683
684/* Handle a transmit completion event
685 *
686 * Falcon batches TX completion events; the message we receive is of
687 * the form "complete all TX events up to this index".
688 */
Ben Hutchings4d566062008-09-01 12:47:12 +0100689static void falcon_handle_tx_event(struct efx_channel *channel,
690 efx_qword_t *event)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100691{
692 unsigned int tx_ev_desc_ptr;
693 unsigned int tx_ev_q_label;
694 struct efx_tx_queue *tx_queue;
695 struct efx_nic *efx = channel->efx;
696
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000697 if (likely(EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_COMP))) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100698 /* Transmit completion */
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000699 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_DESC_PTR);
700 tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100701 tx_queue = &efx->tx_queue[tx_ev_q_label];
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000702 channel->irq_mod_score +=
703 (tx_ev_desc_ptr - tx_queue->read_count) &
Ben Hutchings3ffeabd2009-10-23 08:30:58 +0000704 EFX_TXQ_MASK;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100705 efx_xmit_done(tx_queue, tx_ev_desc_ptr);
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000706 } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_WQ_FF_FULL)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100707 /* Rewrite the FIFO write pointer */
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000708 tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100709 tx_queue = &efx->tx_queue[tx_ev_q_label];
710
Ben Hutchings55668612008-05-16 21:16:10 +0100711 if (efx_dev_registered(efx))
Ben Hutchings8ceee662008-04-27 12:55:59 +0100712 netif_tx_lock(efx->net_dev);
713 falcon_notify_tx_desc(tx_queue);
Ben Hutchings55668612008-05-16 21:16:10 +0100714 if (efx_dev_registered(efx))
Ben Hutchings8ceee662008-04-27 12:55:59 +0100715 netif_tx_unlock(efx->net_dev);
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000716 } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_PKT_ERR) &&
Ben Hutchings8ceee662008-04-27 12:55:59 +0100717 EFX_WORKAROUND_10727(efx)) {
718 efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
719 } else {
720 EFX_ERR(efx, "channel %d unexpected TX event "
721 EFX_QWORD_FMT"\n", channel->channel,
722 EFX_QWORD_VAL(*event));
723 }
724}
725
Ben Hutchings8ceee662008-04-27 12:55:59 +0100726/* Detect errors included in the rx_evt_pkt_ok bit. */
727static void falcon_handle_rx_not_ok(struct efx_rx_queue *rx_queue,
728 const efx_qword_t *event,
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100729 bool *rx_ev_pkt_ok,
730 bool *discard)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100731{
732 struct efx_nic *efx = rx_queue->efx;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100733 bool rx_ev_buf_owner_id_err, rx_ev_ip_hdr_chksum_err;
734 bool rx_ev_tcp_udp_chksum_err, rx_ev_eth_crc_err;
735 bool rx_ev_frm_trunc, rx_ev_drib_nib, rx_ev_tobe_disc;
736 bool rx_ev_other_err, rx_ev_pause_frm;
737 bool rx_ev_ip_frag_err, rx_ev_hdr_type, rx_ev_mcast_pkt;
738 unsigned rx_ev_pkt_type;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100739
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000740 rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE);
741 rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT);
742 rx_ev_tobe_disc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_TOBE_DISC);
743 rx_ev_pkt_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_TYPE);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100744 rx_ev_buf_owner_id_err = EFX_QWORD_FIELD(*event,
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000745 FSF_AZ_RX_EV_BUF_OWNER_ID_ERR);
746 rx_ev_ip_frag_err = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_IP_FRAG_ERR);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100747 rx_ev_ip_hdr_chksum_err = EFX_QWORD_FIELD(*event,
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000748 FSF_AZ_RX_EV_IP_HDR_CHKSUM_ERR);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100749 rx_ev_tcp_udp_chksum_err = EFX_QWORD_FIELD(*event,
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000750 FSF_AZ_RX_EV_TCP_UDP_CHKSUM_ERR);
751 rx_ev_eth_crc_err = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_ETH_CRC_ERR);
752 rx_ev_frm_trunc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_FRM_TRUNC);
Ben Hutchingsdaeda632009-11-28 05:36:04 +0000753 rx_ev_drib_nib = ((efx_nic_rev(efx) >= EFX_REV_FALCON_B0) ?
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000754 0 : EFX_QWORD_FIELD(*event, FSF_AA_RX_EV_DRIB_NIB));
755 rx_ev_pause_frm = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PAUSE_FRM_ERR);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100756
757 /* Every error apart from tobe_disc and pause_frm */
758 rx_ev_other_err = (rx_ev_drib_nib | rx_ev_tcp_udp_chksum_err |
759 rx_ev_buf_owner_id_err | rx_ev_eth_crc_err |
760 rx_ev_frm_trunc | rx_ev_ip_hdr_chksum_err);
761
Ben Hutchings50050872008-12-12 21:42:42 -0800762 /* Count errors that are not in MAC stats. Ignore expected
763 * checksum errors during self-test. */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100764 if (rx_ev_frm_trunc)
765 ++rx_queue->channel->n_rx_frm_trunc;
766 else if (rx_ev_tobe_disc)
767 ++rx_queue->channel->n_rx_tobe_disc;
Ben Hutchings50050872008-12-12 21:42:42 -0800768 else if (!efx->loopback_selftest) {
769 if (rx_ev_ip_hdr_chksum_err)
770 ++rx_queue->channel->n_rx_ip_hdr_chksum_err;
771 else if (rx_ev_tcp_udp_chksum_err)
772 ++rx_queue->channel->n_rx_tcp_udp_chksum_err;
773 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100774 if (rx_ev_ip_frag_err)
775 ++rx_queue->channel->n_rx_ip_frag_err;
776
777 /* The frame must be discarded if any of these are true. */
778 *discard = (rx_ev_eth_crc_err | rx_ev_frm_trunc | rx_ev_drib_nib |
779 rx_ev_tobe_disc | rx_ev_pause_frm);
780
781 /* TOBE_DISC is expected on unicast mismatches; don't print out an
782 * error message. FRM_TRUNC indicates RXDP dropped the packet due
783 * to a FIFO overflow.
784 */
785#ifdef EFX_ENABLE_DEBUG
786 if (rx_ev_other_err) {
787 EFX_INFO_RL(efx, " RX queue %d unexpected RX event "
Ben Hutchings5b39fe32008-09-01 12:46:03 +0100788 EFX_QWORD_FMT "%s%s%s%s%s%s%s%s\n",
Ben Hutchings8ceee662008-04-27 12:55:59 +0100789 rx_queue->queue, EFX_QWORD_VAL(*event),
790 rx_ev_buf_owner_id_err ? " [OWNER_ID_ERR]" : "",
791 rx_ev_ip_hdr_chksum_err ?
792 " [IP_HDR_CHKSUM_ERR]" : "",
793 rx_ev_tcp_udp_chksum_err ?
794 " [TCP_UDP_CHKSUM_ERR]" : "",
795 rx_ev_eth_crc_err ? " [ETH_CRC_ERR]" : "",
796 rx_ev_frm_trunc ? " [FRM_TRUNC]" : "",
797 rx_ev_drib_nib ? " [DRIB_NIB]" : "",
798 rx_ev_tobe_disc ? " [TOBE_DISC]" : "",
Ben Hutchings5b39fe32008-09-01 12:46:03 +0100799 rx_ev_pause_frm ? " [PAUSE]" : "");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100800 }
801#endif
Ben Hutchings8ceee662008-04-27 12:55:59 +0100802}
803
804/* Handle receive events that are not in-order. */
805static void falcon_handle_rx_bad_index(struct efx_rx_queue *rx_queue,
806 unsigned index)
807{
808 struct efx_nic *efx = rx_queue->efx;
809 unsigned expected, dropped;
810
Ben Hutchings3ffeabd2009-10-23 08:30:58 +0000811 expected = rx_queue->removed_count & EFX_RXQ_MASK;
812 dropped = (index - expected) & EFX_RXQ_MASK;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100813 EFX_INFO(efx, "dropped %d events (index=%d expected=%d)\n",
814 dropped, index, expected);
815
816 efx_schedule_reset(efx, EFX_WORKAROUND_5676(efx) ?
817 RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
818}
819
820/* Handle a packet received event
821 *
822 * Falcon silicon gives a "discard" flag if it's a unicast packet with the
823 * wrong destination address
824 * Also "is multicast" and "matches multicast filter" flags can be used to
825 * discard non-matching multicast packets.
826 */
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100827static void falcon_handle_rx_event(struct efx_channel *channel,
828 const efx_qword_t *event)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100829{
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100830 unsigned int rx_ev_desc_ptr, rx_ev_byte_cnt;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100831 unsigned int rx_ev_hdr_type, rx_ev_mcast_pkt;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100832 unsigned expected_ptr;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100833 bool rx_ev_pkt_ok, discard = false, checksummed;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100834 struct efx_rx_queue *rx_queue;
835 struct efx_nic *efx = channel->efx;
836
837 /* Basic packet information */
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000838 rx_ev_byte_cnt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_BYTE_CNT);
839 rx_ev_pkt_ok = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_OK);
840 rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE);
841 WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_JUMBO_CONT));
842 WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_SOP) != 1);
843 WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_Q_LABEL) !=
844 channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100845
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100846 rx_queue = &efx->rx_queue[channel->channel];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100847
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000848 rx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_DESC_PTR);
Ben Hutchings3ffeabd2009-10-23 08:30:58 +0000849 expected_ptr = rx_queue->removed_count & EFX_RXQ_MASK;
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100850 if (unlikely(rx_ev_desc_ptr != expected_ptr))
Ben Hutchings8ceee662008-04-27 12:55:59 +0100851 falcon_handle_rx_bad_index(rx_queue, rx_ev_desc_ptr);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100852
853 if (likely(rx_ev_pkt_ok)) {
854 /* If packet is marked as OK and packet type is TCP/IPv4 or
855 * UDP/IPv4, then we can rely on the hardware checksum.
856 */
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000857 checksummed =
Ben Hutchings9c1bbba2009-10-28 02:50:44 -0700858 efx->rx_checksum_enabled &&
859 (rx_ev_hdr_type == FSE_AB_RX_EV_HDR_TYPE_IPV4_TCP ||
860 rx_ev_hdr_type == FSE_AB_RX_EV_HDR_TYPE_IPV4_UDP);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100861 } else {
862 falcon_handle_rx_not_ok(rx_queue, event, &rx_ev_pkt_ok,
Ben Hutchings5b39fe32008-09-01 12:46:03 +0100863 &discard);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100864 checksummed = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100865 }
866
867 /* Detect multicast packets that didn't match the filter */
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000868 rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100869 if (rx_ev_mcast_pkt) {
870 unsigned int rx_ev_mcast_hash_match =
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000871 EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_HASH_MATCH);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100872
873 if (unlikely(!rx_ev_mcast_hash_match))
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100874 discard = true;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100875 }
876
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000877 channel->irq_mod_score += 2;
878
Ben Hutchings8ceee662008-04-27 12:55:59 +0100879 /* Handle received packet */
880 efx_rx_packet(rx_queue, rx_ev_desc_ptr, rx_ev_byte_cnt,
881 checksummed, discard);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100882}
883
884/* Global events are basically PHY events */
885static void falcon_handle_global_event(struct efx_channel *channel,
886 efx_qword_t *event)
887{
888 struct efx_nic *efx = channel->efx;
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800889 bool handled = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100890
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000891 if (EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_G_PHY0_INTR) ||
892 EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XG_PHY0_INTR) ||
893 EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XFP_PHY0_INTR)) {
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000894 /* Ignored */
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800895 handled = true;
896 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100897
Ben Hutchingsdaeda632009-11-28 05:36:04 +0000898 if ((efx_nic_rev(efx) >= EFX_REV_FALCON_B0) &&
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000899 EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_XG_MGT_INTR)) {
Ben Hutchings9007b9f2009-11-25 16:12:01 +0000900 efx->xmac_poll_required = true;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100901 handled = true;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100902 }
903
Ben Hutchingsdaeda632009-11-28 05:36:04 +0000904 if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ?
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000905 EFX_QWORD_FIELD(*event, FSF_AA_GLB_EV_RX_RECOVERY) :
906 EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_RX_RECOVERY)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100907 EFX_ERR(efx, "channel %d seen global RX_RESET "
908 "event. Resetting.\n", channel->channel);
909
910 atomic_inc(&efx->rx_reset);
911 efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ?
912 RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100913 handled = true;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100914 }
915
916 if (!handled)
917 EFX_ERR(efx, "channel %d unknown global event "
918 EFX_QWORD_FMT "\n", channel->channel,
919 EFX_QWORD_VAL(*event));
920}
921
922static void falcon_handle_driver_event(struct efx_channel *channel,
923 efx_qword_t *event)
924{
925 struct efx_nic *efx = channel->efx;
926 unsigned int ev_sub_code;
927 unsigned int ev_sub_data;
928
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000929 ev_sub_code = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBCODE);
930 ev_sub_data = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100931
932 switch (ev_sub_code) {
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000933 case FSE_AZ_TX_DESCQ_FLS_DONE_EV:
Ben Hutchings8ceee662008-04-27 12:55:59 +0100934 EFX_TRACE(efx, "channel %d TXQ %d flushed\n",
935 channel->channel, ev_sub_data);
936 break;
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000937 case FSE_AZ_RX_DESCQ_FLS_DONE_EV:
Ben Hutchings8ceee662008-04-27 12:55:59 +0100938 EFX_TRACE(efx, "channel %d RXQ %d flushed\n",
939 channel->channel, ev_sub_data);
940 break;
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000941 case FSE_AZ_EVQ_INIT_DONE_EV:
Ben Hutchings8ceee662008-04-27 12:55:59 +0100942 EFX_LOG(efx, "channel %d EVQ %d initialised\n",
943 channel->channel, ev_sub_data);
944 break;
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000945 case FSE_AZ_SRM_UPD_DONE_EV:
Ben Hutchings8ceee662008-04-27 12:55:59 +0100946 EFX_TRACE(efx, "channel %d SRAM update done\n",
947 channel->channel);
948 break;
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000949 case FSE_AZ_WAKE_UP_EV:
Ben Hutchings8ceee662008-04-27 12:55:59 +0100950 EFX_TRACE(efx, "channel %d RXQ %d wakeup event\n",
951 channel->channel, ev_sub_data);
952 break;
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000953 case FSE_AZ_TIMER_EV:
Ben Hutchings8ceee662008-04-27 12:55:59 +0100954 EFX_TRACE(efx, "channel %d RX queue %d timer expired\n",
955 channel->channel, ev_sub_data);
956 break;
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000957 case FSE_AA_RX_RECOVER_EV:
Ben Hutchings8ceee662008-04-27 12:55:59 +0100958 EFX_ERR(efx, "channel %d seen DRIVER RX_RESET event. "
959 "Resetting.\n", channel->channel);
Ben Hutchings05e3ec02008-05-07 13:00:39 +0100960 atomic_inc(&efx->rx_reset);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100961 efx_schedule_reset(efx,
962 EFX_WORKAROUND_6555(efx) ?
963 RESET_TYPE_RX_RECOVERY :
964 RESET_TYPE_DISABLE);
965 break;
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000966 case FSE_BZ_RX_DSC_ERROR_EV:
Ben Hutchings8ceee662008-04-27 12:55:59 +0100967 EFX_ERR(efx, "RX DMA Q %d reports descriptor fetch error."
968 " RX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
969 efx_schedule_reset(efx, RESET_TYPE_RX_DESC_FETCH);
970 break;
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000971 case FSE_BZ_TX_DSC_ERROR_EV:
Ben Hutchings8ceee662008-04-27 12:55:59 +0100972 EFX_ERR(efx, "TX DMA Q %d reports descriptor fetch error."
973 " TX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
974 efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
975 break;
976 default:
977 EFX_TRACE(efx, "channel %d unknown driver event code %d "
978 "data %04x\n", channel->channel, ev_sub_code,
979 ev_sub_data);
980 break;
981 }
982}
983
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100984int falcon_process_eventq(struct efx_channel *channel, int rx_quota)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100985{
986 unsigned int read_ptr;
987 efx_qword_t event, *p_event;
988 int ev_code;
Ben Hutchings42cbe2d2008-09-01 12:48:08 +0100989 int rx_packets = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100990
991 read_ptr = channel->eventq_read_ptr;
992
993 do {
994 p_event = falcon_event(channel, read_ptr);
995 event = *p_event;
996
997 if (!falcon_event_present(&event))
998 /* End of events */
999 break;
1000
1001 EFX_TRACE(channel->efx, "channel %d event is "EFX_QWORD_FMT"\n",
1002 channel->channel, EFX_QWORD_VAL(event));
1003
1004 /* Clear this event by marking it all ones */
1005 EFX_SET_QWORD(*p_event);
1006
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001007 ev_code = EFX_QWORD_FIELD(event, FSF_AZ_EV_CODE);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001008
1009 switch (ev_code) {
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001010 case FSE_AZ_EV_CODE_RX_EV:
Ben Hutchings42cbe2d2008-09-01 12:48:08 +01001011 falcon_handle_rx_event(channel, &event);
1012 ++rx_packets;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001013 break;
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001014 case FSE_AZ_EV_CODE_TX_EV:
Ben Hutchings8ceee662008-04-27 12:55:59 +01001015 falcon_handle_tx_event(channel, &event);
1016 break;
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001017 case FSE_AZ_EV_CODE_DRV_GEN_EV:
1018 channel->eventq_magic = EFX_QWORD_FIELD(
1019 event, FSF_AZ_DRV_GEN_EV_MAGIC);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001020 EFX_LOG(channel->efx, "channel %d received generated "
1021 "event "EFX_QWORD_FMT"\n", channel->channel,
1022 EFX_QWORD_VAL(event));
1023 break;
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001024 case FSE_AZ_EV_CODE_GLOBAL_EV:
Ben Hutchings8ceee662008-04-27 12:55:59 +01001025 falcon_handle_global_event(channel, &event);
1026 break;
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001027 case FSE_AZ_EV_CODE_DRIVER_EV:
Ben Hutchings8ceee662008-04-27 12:55:59 +01001028 falcon_handle_driver_event(channel, &event);
1029 break;
1030 default:
1031 EFX_ERR(channel->efx, "channel %d unknown event type %d"
1032 " (data " EFX_QWORD_FMT ")\n", channel->channel,
1033 ev_code, EFX_QWORD_VAL(event));
1034 }
1035
1036 /* Increment read pointer */
Ben Hutchings3ffeabd2009-10-23 08:30:58 +00001037 read_ptr = (read_ptr + 1) & EFX_EVQ_MASK;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001038
Ben Hutchings42cbe2d2008-09-01 12:48:08 +01001039 } while (rx_packets < rx_quota);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001040
1041 channel->eventq_read_ptr = read_ptr;
Ben Hutchings42cbe2d2008-09-01 12:48:08 +01001042 return rx_packets;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001043}
1044
1045void falcon_set_int_moderation(struct efx_channel *channel)
1046{
1047 efx_dword_t timer_cmd;
1048 struct efx_nic *efx = channel->efx;
1049
1050 /* Set timer register */
1051 if (channel->irq_moderation) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001052 EFX_POPULATE_DWORD_2(timer_cmd,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001053 FRF_AB_TC_TIMER_MODE,
1054 FFE_BB_TIMER_MODE_INT_HLDOFF,
1055 FRF_AB_TC_TIMER_VAL,
Ben Hutchings0d86ebd2009-10-23 08:32:13 +00001056 channel->irq_moderation - 1);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001057 } else {
1058 EFX_POPULATE_DWORD_2(timer_cmd,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001059 FRF_AB_TC_TIMER_MODE,
1060 FFE_BB_TIMER_MODE_DIS,
1061 FRF_AB_TC_TIMER_VAL, 0);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001062 }
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001063 BUILD_BUG_ON(FR_AA_TIMER_COMMAND_KER != FR_BZ_TIMER_COMMAND_P0);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001064 efx_writed_page_locked(efx, &timer_cmd, FR_BZ_TIMER_COMMAND_P0,
1065 channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001066
1067}
1068
1069/* Allocate buffer table entries for event queue */
1070int falcon_probe_eventq(struct efx_channel *channel)
1071{
1072 struct efx_nic *efx = channel->efx;
Ben Hutchings3ffeabd2009-10-23 08:30:58 +00001073 BUILD_BUG_ON(EFX_EVQ_SIZE < 512 || EFX_EVQ_SIZE > 32768 ||
1074 EFX_EVQ_SIZE & EFX_EVQ_MASK);
1075 return falcon_alloc_special_buffer(efx, &channel->eventq,
1076 EFX_EVQ_SIZE * sizeof(efx_qword_t));
Ben Hutchings8ceee662008-04-27 12:55:59 +01001077}
1078
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +01001079void falcon_init_eventq(struct efx_channel *channel)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001080{
1081 efx_oword_t evq_ptr;
1082 struct efx_nic *efx = channel->efx;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001083
1084 EFX_LOG(efx, "channel %d event queue in special buffers %d-%d\n",
1085 channel->channel, channel->eventq.index,
1086 channel->eventq.index + channel->eventq.entries - 1);
1087
1088 /* Pin event queue buffer */
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +01001089 falcon_init_special_buffer(efx, &channel->eventq);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001090
1091 /* Fill event queue with all ones (i.e. empty events) */
1092 memset(channel->eventq.addr, 0xff, channel->eventq.len);
1093
1094 /* Push event queue to card */
1095 EFX_POPULATE_OWORD_3(evq_ptr,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001096 FRF_AZ_EVQ_EN, 1,
Ben Hutchings3ffeabd2009-10-23 08:30:58 +00001097 FRF_AZ_EVQ_SIZE, __ffs(channel->eventq.entries),
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001098 FRF_AZ_EVQ_BUF_BASE_ID, channel->eventq.index);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001099 efx_writeo_table(efx, &evq_ptr, efx->type->evq_ptr_tbl_base,
1100 channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001101
1102 falcon_set_int_moderation(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001103}
1104
1105void falcon_fini_eventq(struct efx_channel *channel)
1106{
1107 efx_oword_t eventq_ptr;
1108 struct efx_nic *efx = channel->efx;
1109
1110 /* Remove event queue from card */
1111 EFX_ZERO_OWORD(eventq_ptr);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001112 efx_writeo_table(efx, &eventq_ptr, efx->type->evq_ptr_tbl_base,
1113 channel->channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001114
1115 /* Unpin event queue */
1116 falcon_fini_special_buffer(efx, &channel->eventq);
1117}
1118
1119/* Free buffers backing event queue */
1120void falcon_remove_eventq(struct efx_channel *channel)
1121{
1122 falcon_free_special_buffer(channel->efx, &channel->eventq);
1123}
1124
1125
1126/* Generates a test event on the event queue. A subsequent call to
1127 * process_eventq() should pick up the event and place the value of
1128 * "magic" into channel->eventq_magic;
1129 */
1130void falcon_generate_test_event(struct efx_channel *channel, unsigned int magic)
1131{
1132 efx_qword_t test_event;
1133
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001134 EFX_POPULATE_QWORD_2(test_event, FSF_AZ_EV_CODE,
1135 FSE_AZ_EV_CODE_DRV_GEN_EV,
1136 FSF_AZ_DRV_GEN_EV_MAGIC, magic);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001137 falcon_generate_event(channel, &test_event);
1138}
1139
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001140/**************************************************************************
1141 *
1142 * Flush handling
1143 *
1144 **************************************************************************/
1145
1146
1147static void falcon_poll_flush_events(struct efx_nic *efx)
1148{
1149 struct efx_channel *channel = &efx->channel[0];
1150 struct efx_tx_queue *tx_queue;
1151 struct efx_rx_queue *rx_queue;
Ben Hutchings4720bc62009-03-04 10:01:15 +00001152 unsigned int read_ptr = channel->eventq_read_ptr;
Ben Hutchings3ffeabd2009-10-23 08:30:58 +00001153 unsigned int end_ptr = (read_ptr - 1) & EFX_EVQ_MASK;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001154
Ben Hutchings4720bc62009-03-04 10:01:15 +00001155 do {
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001156 efx_qword_t *event = falcon_event(channel, read_ptr);
1157 int ev_code, ev_sub_code, ev_queue;
1158 bool ev_failed;
Ben Hutchings4720bc62009-03-04 10:01:15 +00001159
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001160 if (!falcon_event_present(event))
1161 break;
1162
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001163 ev_code = EFX_QWORD_FIELD(*event, FSF_AZ_EV_CODE);
1164 ev_sub_code = EFX_QWORD_FIELD(*event,
1165 FSF_AZ_DRIVER_EV_SUBCODE);
1166 if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
1167 ev_sub_code == FSE_AZ_TX_DESCQ_FLS_DONE_EV) {
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001168 ev_queue = EFX_QWORD_FIELD(*event,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001169 FSF_AZ_DRIVER_EV_SUBDATA);
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001170 if (ev_queue < EFX_TX_QUEUE_COUNT) {
1171 tx_queue = efx->tx_queue + ev_queue;
Ben Hutchings127e6e12009-11-25 16:09:55 +00001172 tx_queue->flushed = FLUSH_DONE;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001173 }
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001174 } else if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
1175 ev_sub_code == FSE_AZ_RX_DESCQ_FLS_DONE_EV) {
1176 ev_queue = EFX_QWORD_FIELD(
1177 *event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);
1178 ev_failed = EFX_QWORD_FIELD(
1179 *event, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001180 if (ev_queue < efx->n_rx_queues) {
1181 rx_queue = efx->rx_queue + ev_queue;
Ben Hutchings127e6e12009-11-25 16:09:55 +00001182 rx_queue->flushed =
1183 ev_failed ? FLUSH_FAILED : FLUSH_DONE;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001184 }
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001185 }
1186
Ben Hutchings127e6e12009-11-25 16:09:55 +00001187 /* We're about to destroy the queue anyway, so
1188 * it's ok to throw away every non-flush event */
1189 EFX_SET_QWORD(*event);
1190
Ben Hutchings3ffeabd2009-10-23 08:30:58 +00001191 read_ptr = (read_ptr + 1) & EFX_EVQ_MASK;
Ben Hutchings4720bc62009-03-04 10:01:15 +00001192 } while (read_ptr != end_ptr);
Ben Hutchings127e6e12009-11-25 16:09:55 +00001193
1194 channel->eventq_read_ptr = read_ptr;
1195}
1196
1197static void falcon_prepare_flush(struct efx_nic *efx)
1198{
1199 falcon_deconfigure_mac_wrapper(efx);
1200
1201 /* Wait for the tx and rx fifo's to get to the next packet boundary
1202 * (~1ms without back-pressure), then to drain the remainder of the
1203 * fifo's at data path speeds (negligible), with a healthy margin. */
1204 msleep(10);
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001205}
1206
1207/* Handle tx and rx flushes at the same time, since they run in
1208 * parallel in the hardware and there's no reason for us to
1209 * serialise them */
1210int falcon_flush_queues(struct efx_nic *efx)
1211{
1212 struct efx_rx_queue *rx_queue;
1213 struct efx_tx_queue *tx_queue;
Ben Hutchings127e6e12009-11-25 16:09:55 +00001214 int i, tx_pending, rx_pending;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001215
Ben Hutchings127e6e12009-11-25 16:09:55 +00001216 falcon_prepare_flush(efx);
1217
1218 /* Flush all tx queues in parallel */
1219 efx_for_each_tx_queue(tx_queue, efx)
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001220 falcon_flush_tx_queue(tx_queue);
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001221
Ben Hutchings127e6e12009-11-25 16:09:55 +00001222 /* The hardware supports four concurrent rx flushes, each of which may
1223 * need to be retried if there is an outstanding descriptor fetch */
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001224 for (i = 0; i < FALCON_FLUSH_POLL_COUNT; ++i) {
Ben Hutchings127e6e12009-11-25 16:09:55 +00001225 rx_pending = tx_pending = 0;
1226 efx_for_each_rx_queue(rx_queue, efx) {
1227 if (rx_queue->flushed == FLUSH_PENDING)
1228 ++rx_pending;
1229 }
1230 efx_for_each_rx_queue(rx_queue, efx) {
1231 if (rx_pending == FALCON_RX_FLUSH_COUNT)
1232 break;
1233 if (rx_queue->flushed == FLUSH_FAILED ||
1234 rx_queue->flushed == FLUSH_NONE) {
1235 falcon_flush_rx_queue(rx_queue);
1236 ++rx_pending;
1237 }
1238 }
1239 efx_for_each_tx_queue(tx_queue, efx) {
1240 if (tx_queue->flushed != FLUSH_DONE)
1241 ++tx_pending;
1242 }
1243
1244 if (rx_pending == 0 && tx_pending == 0)
1245 return 0;
1246
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001247 msleep(FALCON_FLUSH_INTERVAL);
1248 falcon_poll_flush_events(efx);
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001249 }
1250
1251 /* Mark the queues as all flushed. We're going to return failure
Ben Hutchings127e6e12009-11-25 16:09:55 +00001252 * leading to a reset, or fake up success anyway */
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001253 efx_for_each_tx_queue(tx_queue, efx) {
Ben Hutchings127e6e12009-11-25 16:09:55 +00001254 if (tx_queue->flushed != FLUSH_DONE)
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001255 EFX_ERR(efx, "tx queue %d flush command timed out\n",
1256 tx_queue->queue);
Ben Hutchings127e6e12009-11-25 16:09:55 +00001257 tx_queue->flushed = FLUSH_DONE;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001258 }
1259 efx_for_each_rx_queue(rx_queue, efx) {
Ben Hutchings127e6e12009-11-25 16:09:55 +00001260 if (rx_queue->flushed != FLUSH_DONE)
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001261 EFX_ERR(efx, "rx queue %d flush command timed out\n",
1262 rx_queue->queue);
Ben Hutchings127e6e12009-11-25 16:09:55 +00001263 rx_queue->flushed = FLUSH_DONE;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +01001264 }
1265
1266 if (EFX_WORKAROUND_7803(efx))
1267 return 0;
1268
1269 return -ETIMEDOUT;
1270}
Ben Hutchings8ceee662008-04-27 12:55:59 +01001271
1272/**************************************************************************
1273 *
1274 * Falcon hardware interrupts
1275 * The hardware interrupt handler does very little work; all the event
1276 * queue processing is carried out by per-channel tasklets.
1277 *
1278 **************************************************************************/
1279
1280/* Enable/disable/generate Falcon interrupts */
1281static inline void falcon_interrupts(struct efx_nic *efx, int enabled,
1282 int force)
1283{
1284 efx_oword_t int_en_reg_ker;
1285
1286 EFX_POPULATE_OWORD_2(int_en_reg_ker,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001287 FRF_AZ_KER_INT_KER, force,
1288 FRF_AZ_DRV_INT_EN_KER, enabled);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001289 efx_writeo(efx, &int_en_reg_ker, FR_AZ_INT_EN_KER);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001290}
1291
1292void falcon_enable_interrupts(struct efx_nic *efx)
1293{
1294 efx_oword_t int_adr_reg_ker;
1295 struct efx_channel *channel;
1296
1297 EFX_ZERO_OWORD(*((efx_oword_t *) efx->irq_status.addr));
1298 wmb(); /* Ensure interrupt vector is clear before interrupts enabled */
1299
1300 /* Program address */
1301 EFX_POPULATE_OWORD_2(int_adr_reg_ker,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001302 FRF_AZ_NORM_INT_VEC_DIS_KER,
1303 EFX_INT_MODE_USE_MSI(efx),
1304 FRF_AZ_INT_ADR_KER, efx->irq_status.dma_addr);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001305 efx_writeo(efx, &int_adr_reg_ker, FR_AZ_INT_ADR_KER);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001306
1307 /* Enable interrupts */
1308 falcon_interrupts(efx, 1, 0);
1309
1310 /* Force processing of all the channels to get the EVQ RPTRs up to
1311 date */
Ben Hutchings64ee3122008-09-01 12:47:38 +01001312 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001313 efx_schedule_channel(channel);
1314}
1315
1316void falcon_disable_interrupts(struct efx_nic *efx)
1317{
1318 /* Disable interrupts */
1319 falcon_interrupts(efx, 0, 0);
1320}
1321
1322/* Generate a Falcon test interrupt
1323 * Interrupt must already have been enabled, otherwise nasty things
1324 * may happen.
1325 */
1326void falcon_generate_interrupt(struct efx_nic *efx)
1327{
1328 falcon_interrupts(efx, 1, 1);
1329}
1330
1331/* Acknowledge a legacy interrupt from Falcon
1332 *
1333 * This acknowledges a legacy (not MSI) interrupt via INT_ACK_KER_REG.
1334 *
1335 * Due to SFC bug 3706 (silicon revision <=A1) reads can be duplicated in the
1336 * BIU. Interrupt acknowledge is read sensitive so must write instead
1337 * (then read to ensure the BIU collector is flushed)
1338 *
1339 * NB most hardware supports MSI interrupts
1340 */
1341static inline void falcon_irq_ack_a1(struct efx_nic *efx)
1342{
1343 efx_dword_t reg;
1344
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001345 EFX_POPULATE_DWORD_1(reg, FRF_AA_INT_ACK_KER_FIELD, 0xb7eb7e);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001346 efx_writed(efx, &reg, FR_AA_INT_ACK_KER);
1347 efx_readd(efx, &reg, FR_AA_WORK_AROUND_BROKEN_PCI_READS);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001348}
1349
1350/* Process a fatal interrupt
1351 * Disable bus mastering ASAP and schedule a reset
1352 */
1353static irqreturn_t falcon_fatal_interrupt(struct efx_nic *efx)
1354{
1355 struct falcon_nic_data *nic_data = efx->nic_data;
Ben Hutchingsd3208b52008-05-16 21:20:00 +01001356 efx_oword_t *int_ker = efx->irq_status.addr;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001357 efx_oword_t fatal_intr;
1358 int error, mem_perr;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001359
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001360 efx_reado(efx, &fatal_intr, FR_AZ_FATAL_INTR_KER);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001361 error = EFX_OWORD_FIELD(fatal_intr, FRF_AZ_FATAL_INTR);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001362
1363 EFX_ERR(efx, "SYSTEM ERROR " EFX_OWORD_FMT " status "
1364 EFX_OWORD_FMT ": %s\n", EFX_OWORD_VAL(*int_ker),
1365 EFX_OWORD_VAL(fatal_intr),
1366 error ? "disabling bus mastering" : "no recognised error");
1367 if (error == 0)
1368 goto out;
1369
1370 /* If this is a memory parity error dump which blocks are offending */
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001371 mem_perr = EFX_OWORD_FIELD(fatal_intr, FRF_AZ_MEM_PERR_INT_KER);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001372 if (mem_perr) {
1373 efx_oword_t reg;
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001374 efx_reado(efx, &reg, FR_AZ_MEM_STAT);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001375 EFX_ERR(efx, "SYSTEM ERROR: memory parity error "
1376 EFX_OWORD_FMT "\n", EFX_OWORD_VAL(reg));
1377 }
1378
Ben Hutchings0a62f1a2008-09-01 12:50:14 +01001379 /* Disable both devices */
Ben Hutchingsef1bba22008-12-23 03:09:53 +00001380 pci_clear_master(efx->pci_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001381 if (FALCON_IS_DUAL_FUNC(efx))
Ben Hutchingsef1bba22008-12-23 03:09:53 +00001382 pci_clear_master(nic_data->pci_dev2);
Ben Hutchings0a62f1a2008-09-01 12:50:14 +01001383 falcon_disable_interrupts(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001384
Ben Hutchings2c3c3d02009-03-04 10:01:57 +00001385 /* Count errors and reset or disable the NIC accordingly */
Ben Hutchings0484e0d2009-10-23 08:32:04 +00001386 if (efx->int_error_count == 0 ||
1387 time_after(jiffies, efx->int_error_expire)) {
1388 efx->int_error_count = 0;
1389 efx->int_error_expire =
Ben Hutchings2c3c3d02009-03-04 10:01:57 +00001390 jiffies + FALCON_INT_ERROR_EXPIRE * HZ;
1391 }
Ben Hutchings0484e0d2009-10-23 08:32:04 +00001392 if (++efx->int_error_count < FALCON_MAX_INT_ERRORS) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001393 EFX_ERR(efx, "SYSTEM ERROR - reset scheduled\n");
1394 efx_schedule_reset(efx, RESET_TYPE_INT_ERROR);
1395 } else {
1396 EFX_ERR(efx, "SYSTEM ERROR - max number of errors seen."
1397 "NIC will be disabled\n");
1398 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
1399 }
1400out:
1401 return IRQ_HANDLED;
1402}
1403
1404/* Handle a legacy interrupt from Falcon
1405 * Acknowledges the interrupt and schedule event queue processing.
1406 */
1407static irqreturn_t falcon_legacy_interrupt_b0(int irq, void *dev_id)
1408{
Ben Hutchingsd3208b52008-05-16 21:20:00 +01001409 struct efx_nic *efx = dev_id;
1410 efx_oword_t *int_ker = efx->irq_status.addr;
Ben Hutchingsa9de9a72009-03-20 13:26:41 +00001411 irqreturn_t result = IRQ_NONE;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001412 struct efx_channel *channel;
1413 efx_dword_t reg;
1414 u32 queues;
1415 int syserr;
1416
1417 /* Read the ISR which also ACKs the interrupts */
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001418 efx_readd(efx, &reg, FR_BZ_INT_ISR0);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001419 queues = EFX_EXTRACT_DWORD(reg, 0, 31);
1420
1421 /* Check to see if we have a serious error condition */
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001422 syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001423 if (unlikely(syserr))
1424 return falcon_fatal_interrupt(efx);
1425
Ben Hutchings8ceee662008-04-27 12:55:59 +01001426 /* Schedule processing of any interrupting queues */
Ben Hutchingsa9de9a72009-03-20 13:26:41 +00001427 efx_for_each_channel(channel, efx) {
1428 if ((queues & 1) ||
1429 falcon_event_present(
1430 falcon_event(channel, channel->eventq_read_ptr))) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001431 efx_schedule_channel(channel);
Ben Hutchingsa9de9a72009-03-20 13:26:41 +00001432 result = IRQ_HANDLED;
1433 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001434 queues >>= 1;
1435 }
1436
Ben Hutchingsa9de9a72009-03-20 13:26:41 +00001437 if (result == IRQ_HANDLED) {
1438 efx->last_irq_cpu = raw_smp_processor_id();
1439 EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
1440 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
1441 }
1442
1443 return result;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001444}
1445
1446
1447static irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id)
1448{
Ben Hutchingsd3208b52008-05-16 21:20:00 +01001449 struct efx_nic *efx = dev_id;
1450 efx_oword_t *int_ker = efx->irq_status.addr;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001451 struct efx_channel *channel;
1452 int syserr;
1453 int queues;
1454
1455 /* Check to see if this is our interrupt. If it isn't, we
1456 * exit without having touched the hardware.
1457 */
1458 if (unlikely(EFX_OWORD_IS_ZERO(*int_ker))) {
1459 EFX_TRACE(efx, "IRQ %d on CPU %d not for me\n", irq,
1460 raw_smp_processor_id());
1461 return IRQ_NONE;
1462 }
1463 efx->last_irq_cpu = raw_smp_processor_id();
1464 EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
1465 irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
1466
1467 /* Check to see if we have a serious error condition */
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001468 syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001469 if (unlikely(syserr))
1470 return falcon_fatal_interrupt(efx);
1471
1472 /* Determine interrupting queues, clear interrupt status
1473 * register and acknowledge the device interrupt.
1474 */
1475 BUILD_BUG_ON(INT_EVQS_WIDTH > EFX_MAX_CHANNELS);
1476 queues = EFX_OWORD_FIELD(*int_ker, INT_EVQS);
1477 EFX_ZERO_OWORD(*int_ker);
1478 wmb(); /* Ensure the vector is cleared before interrupt ack */
1479 falcon_irq_ack_a1(efx);
1480
1481 /* Schedule processing of any interrupting queues */
1482 channel = &efx->channel[0];
1483 while (queues) {
1484 if (queues & 0x01)
1485 efx_schedule_channel(channel);
1486 channel++;
1487 queues >>= 1;
1488 }
1489
1490 return IRQ_HANDLED;
1491}
1492
1493/* Handle an MSI interrupt from Falcon
1494 *
1495 * Handle an MSI hardware interrupt. This routine schedules event
1496 * queue processing. No interrupt acknowledgement cycle is necessary.
1497 * Also, we never need to check that the interrupt is for us, since
1498 * MSI interrupts cannot be shared.
1499 */
1500static irqreturn_t falcon_msi_interrupt(int irq, void *dev_id)
1501{
Ben Hutchingsd3208b52008-05-16 21:20:00 +01001502 struct efx_channel *channel = dev_id;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001503 struct efx_nic *efx = channel->efx;
Ben Hutchingsd3208b52008-05-16 21:20:00 +01001504 efx_oword_t *int_ker = efx->irq_status.addr;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001505 int syserr;
1506
1507 efx->last_irq_cpu = raw_smp_processor_id();
1508 EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
1509 irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
1510
1511 /* Check to see if we have a serious error condition */
1512 syserr = EFX_OWORD_FIELD(*int_ker, FATAL_INT);
1513 if (unlikely(syserr))
1514 return falcon_fatal_interrupt(efx);
1515
1516 /* Schedule processing of the channel */
1517 efx_schedule_channel(channel);
1518
1519 return IRQ_HANDLED;
1520}
1521
1522
1523/* Setup RSS indirection table.
1524 * This maps from the hash value of the packet to RXQ
1525 */
1526static void falcon_setup_rss_indir_table(struct efx_nic *efx)
1527{
1528 int i = 0;
1529 unsigned long offset;
1530 efx_dword_t dword;
1531
Ben Hutchingsdaeda632009-11-28 05:36:04 +00001532 if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001533 return;
1534
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001535 for (offset = FR_BZ_RX_INDIRECTION_TBL;
1536 offset < FR_BZ_RX_INDIRECTION_TBL + 0x800;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001537 offset += 0x10) {
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001538 EFX_POPULATE_DWORD_1(dword, FRF_BZ_IT_QUEUE,
Ben Hutchings8831da72008-09-01 12:47:48 +01001539 i % efx->n_rx_queues);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001540 efx_writed(efx, &dword, offset);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001541 i++;
1542 }
1543}
1544
1545/* Hook interrupt handler(s)
1546 * Try MSI and then legacy interrupts.
1547 */
1548int falcon_init_interrupt(struct efx_nic *efx)
1549{
1550 struct efx_channel *channel;
1551 int rc;
1552
1553 if (!EFX_INT_MODE_USE_MSI(efx)) {
1554 irq_handler_t handler;
Ben Hutchingsdaeda632009-11-28 05:36:04 +00001555 if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001556 handler = falcon_legacy_interrupt_b0;
1557 else
1558 handler = falcon_legacy_interrupt_a1;
1559
1560 rc = request_irq(efx->legacy_irq, handler, IRQF_SHARED,
1561 efx->name, efx);
1562 if (rc) {
1563 EFX_ERR(efx, "failed to hook legacy IRQ %d\n",
1564 efx->pci_dev->irq);
1565 goto fail1;
1566 }
1567 return 0;
1568 }
1569
1570 /* Hook MSI or MSI-X interrupt */
Ben Hutchings64ee3122008-09-01 12:47:38 +01001571 efx_for_each_channel(channel, efx) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001572 rc = request_irq(channel->irq, falcon_msi_interrupt,
1573 IRQF_PROBE_SHARED, /* Not shared */
Ben Hutchings56536e92008-12-12 21:37:02 -08001574 channel->name, channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001575 if (rc) {
1576 EFX_ERR(efx, "failed to hook IRQ %d\n", channel->irq);
1577 goto fail2;
1578 }
1579 }
1580
1581 return 0;
1582
1583 fail2:
Ben Hutchings64ee3122008-09-01 12:47:38 +01001584 efx_for_each_channel(channel, efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001585 free_irq(channel->irq, channel);
1586 fail1:
1587 return rc;
1588}
1589
1590void falcon_fini_interrupt(struct efx_nic *efx)
1591{
1592 struct efx_channel *channel;
1593 efx_oword_t reg;
1594
1595 /* Disable MSI/MSI-X interrupts */
Ben Hutchings64ee3122008-09-01 12:47:38 +01001596 efx_for_each_channel(channel, efx) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001597 if (channel->irq)
1598 free_irq(channel->irq, channel);
Ben Hutchingsb3475642008-05-16 21:15:49 +01001599 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001600
1601 /* ACK legacy interrupt */
Ben Hutchingsdaeda632009-11-28 05:36:04 +00001602 if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001603 efx_reado(efx, &reg, FR_BZ_INT_ISR0);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001604 else
1605 falcon_irq_ack_a1(efx);
1606
1607 /* Disable legacy interrupt */
1608 if (efx->legacy_irq)
1609 free_irq(efx->legacy_irq, efx);
1610}
1611
1612/**************************************************************************
1613 *
1614 * EEPROM/flash
1615 *
1616 **************************************************************************
1617 */
1618
Ben Hutchings23d30f02008-12-12 21:56:11 -08001619#define FALCON_SPI_MAX_LEN sizeof(efx_oword_t)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001620
Ben Hutchingsbe4ea892008-12-12 21:33:50 -08001621static int falcon_spi_poll(struct efx_nic *efx)
1622{
1623 efx_oword_t reg;
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001624 efx_reado(efx, &reg, FR_AB_EE_SPI_HCMD);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001625 return EFX_OWORD_FIELD(reg, FRF_AB_EE_SPI_HCMD_CMD_EN) ? -EBUSY : 0;
Ben Hutchingsbe4ea892008-12-12 21:33:50 -08001626}
1627
Ben Hutchings8ceee662008-04-27 12:55:59 +01001628/* Wait for SPI command completion */
1629static int falcon_spi_wait(struct efx_nic *efx)
1630{
Ben Hutchingsbe4ea892008-12-12 21:33:50 -08001631 /* Most commands will finish quickly, so we start polling at
1632 * very short intervals. Sometimes the command may have to
1633 * wait for VPD or expansion ROM access outside of our
1634 * control, so we allow up to 100 ms. */
1635 unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 10);
1636 int i;
1637
1638 for (i = 0; i < 10; i++) {
1639 if (!falcon_spi_poll(efx))
1640 return 0;
1641 udelay(10);
1642 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001643
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001644 for (;;) {
Ben Hutchingsbe4ea892008-12-12 21:33:50 -08001645 if (!falcon_spi_poll(efx))
Ben Hutchings8ceee662008-04-27 12:55:59 +01001646 return 0;
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001647 if (time_after_eq(jiffies, timeout)) {
1648 EFX_ERR(efx, "timed out waiting for SPI\n");
1649 return -ETIMEDOUT;
1650 }
Ben Hutchingsbe4ea892008-12-12 21:33:50 -08001651 schedule_timeout_uninterruptible(1);
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001652 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001653}
1654
Ben Hutchingsf4150722008-11-04 20:34:28 +00001655int falcon_spi_cmd(const struct efx_spi_device *spi,
1656 unsigned int command, int address,
Ben Hutchings23d30f02008-12-12 21:56:11 -08001657 const void *in, void *out, size_t len)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001658{
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001659 struct efx_nic *efx = spi->efx;
1660 bool addressed = (address >= 0);
1661 bool reading = (out != NULL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001662 efx_oword_t reg;
1663 int rc;
1664
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001665 /* Input validation */
1666 if (len > FALCON_SPI_MAX_LEN)
1667 return -EINVAL;
Ben Hutchingsf4150722008-11-04 20:34:28 +00001668 BUG_ON(!mutex_is_locked(&efx->spi_lock));
Ben Hutchings8ceee662008-04-27 12:55:59 +01001669
Ben Hutchingsbe4ea892008-12-12 21:33:50 -08001670 /* Check that previous command is not still running */
1671 rc = falcon_spi_poll(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001672 if (rc)
1673 return rc;
1674
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001675 /* Program address register, if we have an address */
1676 if (addressed) {
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001677 EFX_POPULATE_OWORD_1(reg, FRF_AB_EE_SPI_HADR_ADR, address);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001678 efx_writeo(efx, &reg, FR_AB_EE_SPI_HADR);
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001679 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001680
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001681 /* Program data register, if we have data */
1682 if (in != NULL) {
1683 memcpy(&reg, in, len);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001684 efx_writeo(efx, &reg, FR_AB_EE_SPI_HDATA);
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001685 }
1686
1687 /* Issue read/write command */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001688 EFX_POPULATE_OWORD_7(reg,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001689 FRF_AB_EE_SPI_HCMD_CMD_EN, 1,
1690 FRF_AB_EE_SPI_HCMD_SF_SEL, spi->device_id,
1691 FRF_AB_EE_SPI_HCMD_DABCNT, len,
1692 FRF_AB_EE_SPI_HCMD_READ, reading,
1693 FRF_AB_EE_SPI_HCMD_DUBCNT, 0,
1694 FRF_AB_EE_SPI_HCMD_ADBCNT,
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001695 (addressed ? spi->addr_len : 0),
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001696 FRF_AB_EE_SPI_HCMD_ENC, command);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001697 efx_writeo(efx, &reg, FR_AB_EE_SPI_HCMD);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001698
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001699 /* Wait for read/write to complete */
Ben Hutchings8ceee662008-04-27 12:55:59 +01001700 rc = falcon_spi_wait(efx);
1701 if (rc)
1702 return rc;
1703
1704 /* Read data */
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001705 if (out != NULL) {
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001706 efx_reado(efx, &reg, FR_AB_EE_SPI_HDATA);
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001707 memcpy(out, &reg, len);
1708 }
1709
Ben Hutchings8ceee662008-04-27 12:55:59 +01001710 return 0;
1711}
1712
Ben Hutchings23d30f02008-12-12 21:56:11 -08001713static size_t
1714falcon_spi_write_limit(const struct efx_spi_device *spi, size_t start)
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001715{
1716 return min(FALCON_SPI_MAX_LEN,
1717 (spi->block_size - (start & (spi->block_size - 1))));
1718}
1719
1720static inline u8
1721efx_spi_munge_command(const struct efx_spi_device *spi,
1722 const u8 command, const unsigned int address)
1723{
1724 return command | (((address >> 8) & spi->munge_address) << 3);
1725}
1726
Ben Hutchingsbe4ea892008-12-12 21:33:50 -08001727/* Wait up to 10 ms for buffered write completion */
1728int falcon_spi_wait_write(const struct efx_spi_device *spi)
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001729{
Ben Hutchingsbe4ea892008-12-12 21:33:50 -08001730 struct efx_nic *efx = spi->efx;
1731 unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 100);
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001732 u8 status;
Ben Hutchingsbe4ea892008-12-12 21:33:50 -08001733 int rc;
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001734
Ben Hutchingsbe4ea892008-12-12 21:33:50 -08001735 for (;;) {
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001736 rc = falcon_spi_cmd(spi, SPI_RDSR, -1, NULL,
1737 &status, sizeof(status));
1738 if (rc)
1739 return rc;
1740 if (!(status & SPI_STATUS_NRDY))
1741 return 0;
Ben Hutchingsbe4ea892008-12-12 21:33:50 -08001742 if (time_after_eq(jiffies, timeout)) {
1743 EFX_ERR(efx, "SPI write timeout on device %d"
1744 " last status=0x%02x\n",
1745 spi->device_id, status);
1746 return -ETIMEDOUT;
1747 }
1748 schedule_timeout_uninterruptible(1);
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001749 }
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001750}
1751
1752int falcon_spi_read(const struct efx_spi_device *spi, loff_t start,
1753 size_t len, size_t *retlen, u8 *buffer)
1754{
Ben Hutchings23d30f02008-12-12 21:56:11 -08001755 size_t block_len, pos = 0;
1756 unsigned int command;
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001757 int rc = 0;
1758
1759 while (pos < len) {
Ben Hutchings23d30f02008-12-12 21:56:11 -08001760 block_len = min(len - pos, FALCON_SPI_MAX_LEN);
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001761
1762 command = efx_spi_munge_command(spi, SPI_READ, start + pos);
1763 rc = falcon_spi_cmd(spi, command, start + pos, NULL,
1764 buffer + pos, block_len);
1765 if (rc)
1766 break;
1767 pos += block_len;
1768
1769 /* Avoid locking up the system */
1770 cond_resched();
1771 if (signal_pending(current)) {
1772 rc = -EINTR;
1773 break;
1774 }
1775 }
1776
1777 if (retlen)
1778 *retlen = pos;
1779 return rc;
1780}
1781
1782int falcon_spi_write(const struct efx_spi_device *spi, loff_t start,
1783 size_t len, size_t *retlen, const u8 *buffer)
1784{
1785 u8 verify_buffer[FALCON_SPI_MAX_LEN];
Ben Hutchings23d30f02008-12-12 21:56:11 -08001786 size_t block_len, pos = 0;
1787 unsigned int command;
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001788 int rc = 0;
1789
1790 while (pos < len) {
1791 rc = falcon_spi_cmd(spi, SPI_WREN, -1, NULL, NULL, 0);
1792 if (rc)
1793 break;
1794
Ben Hutchings23d30f02008-12-12 21:56:11 -08001795 block_len = min(len - pos,
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001796 falcon_spi_write_limit(spi, start + pos));
1797 command = efx_spi_munge_command(spi, SPI_WRITE, start + pos);
1798 rc = falcon_spi_cmd(spi, command, start + pos,
1799 buffer + pos, NULL, block_len);
1800 if (rc)
1801 break;
1802
Ben Hutchingsbe4ea892008-12-12 21:33:50 -08001803 rc = falcon_spi_wait_write(spi);
Ben Hutchings4a5b5042008-09-01 12:47:16 +01001804 if (rc)
1805 break;
1806
1807 command = efx_spi_munge_command(spi, SPI_READ, start + pos);
1808 rc = falcon_spi_cmd(spi, command, start + pos,
1809 NULL, verify_buffer, block_len);
1810 if (memcmp(verify_buffer, buffer + pos, block_len)) {
1811 rc = -EIO;
1812 break;
1813 }
1814
1815 pos += block_len;
1816
1817 /* Avoid locking up the system */
1818 cond_resched();
1819 if (signal_pending(current)) {
1820 rc = -EINTR;
1821 break;
1822 }
1823 }
1824
1825 if (retlen)
1826 *retlen = pos;
1827 return rc;
1828}
1829
Ben Hutchings8ceee662008-04-27 12:55:59 +01001830/**************************************************************************
1831 *
1832 * MAC wrapper
1833 *
1834 **************************************************************************
1835 */
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001836
1837static int falcon_reset_macs(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001838{
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001839 efx_oword_t reg;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001840 int count;
1841
Ben Hutchingsdaeda632009-11-28 05:36:04 +00001842 if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) {
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001843 /* It's not safe to use GLB_CTL_REG to reset the
1844 * macs, so instead use the internal MAC resets
1845 */
1846 if (!EFX_IS10G(efx)) {
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001847 EFX_POPULATE_OWORD_1(reg, FRF_AB_GM_SW_RST, 1);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001848 efx_writeo(efx, &reg, FR_AB_GM_CFG1);
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001849 udelay(1000);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001850
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001851 EFX_POPULATE_OWORD_1(reg, FRF_AB_GM_SW_RST, 0);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001852 efx_writeo(efx, &reg, FR_AB_GM_CFG1);
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001853 udelay(1000);
1854 return 0;
1855 } else {
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001856 EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_CORE_RST, 1);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001857 efx_writeo(efx, &reg, FR_AB_XM_GLB_CFG);
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001858
1859 for (count = 0; count < 10000; count++) {
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001860 efx_reado(efx, &reg, FR_AB_XM_GLB_CFG);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001861 if (EFX_OWORD_FIELD(reg, FRF_AB_XM_CORE_RST) ==
1862 0)
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001863 return 0;
1864 udelay(10);
1865 }
1866
1867 EFX_ERR(efx, "timed out waiting for XMAC core reset\n");
1868 return -ETIMEDOUT;
1869 }
1870 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001871
1872 /* MAC stats will fail whilst the TX fifo is draining. Serialise
1873 * the drain sequence with the statistics fetch */
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001874 falcon_stop_nic_stats(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001875
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001876 efx_reado(efx, &reg, FR_AB_MAC_CTRL);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001877 EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN, 1);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001878 efx_writeo(efx, &reg, FR_AB_MAC_CTRL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001879
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001880 efx_reado(efx, &reg, FR_AB_GLB_CTL);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001881 EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGTX, 1);
1882 EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGRX, 1);
1883 EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_EM, 1);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001884 efx_writeo(efx, &reg, FR_AB_GLB_CTL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001885
1886 count = 0;
1887 while (1) {
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001888 efx_reado(efx, &reg, FR_AB_GLB_CTL);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001889 if (!EFX_OWORD_FIELD(reg, FRF_AB_RST_XGTX) &&
1890 !EFX_OWORD_FIELD(reg, FRF_AB_RST_XGRX) &&
1891 !EFX_OWORD_FIELD(reg, FRF_AB_RST_EM)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001892 EFX_LOG(efx, "Completed MAC reset after %d loops\n",
1893 count);
1894 break;
1895 }
1896 if (count > 20) {
1897 EFX_ERR(efx, "MAC reset failed\n");
1898 break;
1899 }
1900 count++;
1901 udelay(10);
1902 }
1903
Ben Hutchings8ceee662008-04-27 12:55:59 +01001904 /* If we've reset the EM block and the link is up, then
1905 * we'll have to kick the XAUI link so the PHY can recover */
Ben Hutchingseb50c0d2009-11-23 16:06:30 +00001906 if (efx->link_state.up && EFX_IS10G(efx) && EFX_WORKAROUND_5147(efx))
Ben Hutchings8ceee662008-04-27 12:55:59 +01001907 falcon_reset_xaui(efx);
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001908
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001909 falcon_start_nic_stats(efx);
1910
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001911 return 0;
1912}
1913
1914void falcon_drain_tx_fifo(struct efx_nic *efx)
1915{
1916 efx_oword_t reg;
1917
Ben Hutchingsdaeda632009-11-28 05:36:04 +00001918 if ((efx_nic_rev(efx) < EFX_REV_FALCON_B0) ||
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001919 (efx->loopback_mode != LOOPBACK_NONE))
1920 return;
1921
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001922 efx_reado(efx, &reg, FR_AB_MAC_CTRL);
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001923 /* There is no point in draining more than once */
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001924 if (EFX_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN))
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001925 return;
1926
1927 falcon_reset_macs(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001928}
1929
1930void falcon_deconfigure_mac_wrapper(struct efx_nic *efx)
1931{
Ben Hutchings177dfcd2008-12-12 21:50:08 -08001932 efx_oword_t reg;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001933
Ben Hutchingsdaeda632009-11-28 05:36:04 +00001934 if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001935 return;
1936
1937 /* Isolate the MAC -> RX */
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001938 efx_reado(efx, &reg, FR_AZ_RX_CFG);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001939 EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 0);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001940 efx_writeo(efx, &reg, FR_AZ_RX_CFG);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001941
Ben Hutchingseb50c0d2009-11-23 16:06:30 +00001942 if (!efx->link_state.up)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001943 falcon_drain_tx_fifo(efx);
1944}
1945
1946void falcon_reconfigure_mac_wrapper(struct efx_nic *efx)
1947{
Ben Hutchingseb50c0d2009-11-23 16:06:30 +00001948 struct efx_link_state *link_state = &efx->link_state;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001949 efx_oword_t reg;
1950 int link_speed;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +01001951 bool tx_fc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001952
Ben Hutchingseb50c0d2009-11-23 16:06:30 +00001953 switch (link_state->speed) {
Ben Hutchingsf31a45d2008-12-12 21:43:33 -08001954 case 10000: link_speed = 3; break;
1955 case 1000: link_speed = 2; break;
1956 case 100: link_speed = 1; break;
1957 default: link_speed = 0; break;
1958 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01001959 /* MAC_LINK_STATUS controls MAC backpressure but doesn't work
1960 * as advertised. Disable to ensure packets are not
1961 * indefinitely held and TX queue can be flushed at any point
1962 * while the link is down. */
1963 EFX_POPULATE_OWORD_5(reg,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001964 FRF_AB_MAC_XOFF_VAL, 0xffff /* max pause time */,
1965 FRF_AB_MAC_BCAD_ACPT, 1,
1966 FRF_AB_MAC_UC_PROM, efx->promiscuous,
1967 FRF_AB_MAC_LINK_STATUS, 1, /* always set */
1968 FRF_AB_MAC_SPEED, link_speed);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001969 /* On B0, MAC backpressure can be disabled and packets get
1970 * discarded. */
Ben Hutchingsdaeda632009-11-28 05:36:04 +00001971 if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001972 EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN,
Ben Hutchingseb50c0d2009-11-23 16:06:30 +00001973 !link_state->up);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001974 }
1975
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001976 efx_writeo(efx, &reg, FR_AB_MAC_CTRL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001977
1978 /* Restore the multicast hash registers. */
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00001979 falcon_push_multicast_hash(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001980
1981 /* Transmission of pause frames when RX crosses the threshold is
1982 * covered by RX_XOFF_MAC_EN and XM_TX_CFG_REG:XM_FCNTL.
1983 * Action on receipt of pause frames is controller by XM_DIS_FCNTL */
Ben Hutchingseb50c0d2009-11-23 16:06:30 +00001984 tx_fc = !!(efx->link_state.fc & EFX_FC_TX);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001985 efx_reado(efx, &reg, FR_AZ_RX_CFG);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001986 EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, tx_fc);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001987
1988 /* Unisolate the MAC -> RX */
Ben Hutchingsdaeda632009-11-28 05:36:04 +00001989 if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
Ben Hutchings3e6c4532009-10-23 08:30:36 +00001990 EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00001991 efx_writeo(efx, &reg, FR_AZ_RX_CFG);
Ben Hutchings8ceee662008-04-27 12:55:59 +01001992}
1993
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001994static void falcon_stats_request(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01001995{
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001996 struct falcon_nic_data *nic_data = efx->nic_data;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001997 efx_oword_t reg;
Ben Hutchings8ceee662008-04-27 12:55:59 +01001998
Ben Hutchings55edc6e2009-11-25 16:11:35 +00001999 WARN_ON(nic_data->stats_pending);
2000 WARN_ON(nic_data->stats_disable_count);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002001
Ben Hutchings55edc6e2009-11-25 16:11:35 +00002002 if (nic_data->stats_dma_done == NULL)
2003 return; /* no mac selected */
Ben Hutchings8ceee662008-04-27 12:55:59 +01002004
Ben Hutchings55edc6e2009-11-25 16:11:35 +00002005 *nic_data->stats_dma_done = FALCON_STATS_NOT_DONE;
2006 nic_data->stats_pending = true;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002007 wmb(); /* ensure done flag is clear */
2008
2009 /* Initiate DMA transfer of stats */
2010 EFX_POPULATE_OWORD_2(reg,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002011 FRF_AB_MAC_STAT_DMA_CMD, 1,
2012 FRF_AB_MAC_STAT_DMA_ADR,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002013 efx->stats_buffer.dma_addr);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002014 efx_writeo(efx, &reg, FR_AB_MAC_STAT_DMA);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002015
Ben Hutchings55edc6e2009-11-25 16:11:35 +00002016 mod_timer(&nic_data->stats_timer, round_jiffies_up(jiffies + HZ / 2));
2017}
Ben Hutchings8ceee662008-04-27 12:55:59 +01002018
Ben Hutchings55edc6e2009-11-25 16:11:35 +00002019static void falcon_stats_complete(struct efx_nic *efx)
2020{
2021 struct falcon_nic_data *nic_data = efx->nic_data;
2022
2023 if (!nic_data->stats_pending)
2024 return;
2025
2026 nic_data->stats_pending = 0;
2027 if (*nic_data->stats_dma_done == FALCON_STATS_DONE) {
2028 rmb(); /* read the done flag before the stats */
2029 efx->mac_op->update_stats(efx);
2030 } else {
2031 EFX_ERR(efx, "timed out waiting for statistics\n");
2032 }
2033}
2034
2035static void falcon_stats_timer_func(unsigned long context)
2036{
2037 struct efx_nic *efx = (struct efx_nic *)context;
2038 struct falcon_nic_data *nic_data = efx->nic_data;
2039
2040 spin_lock(&efx->stats_lock);
2041
2042 falcon_stats_complete(efx);
2043 if (nic_data->stats_disable_count == 0)
2044 falcon_stats_request(efx);
2045
2046 spin_unlock(&efx->stats_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002047}
2048
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002049static bool falcon_loopback_link_poll(struct efx_nic *efx)
2050{
2051 struct efx_link_state old_state = efx->link_state;
2052
2053 WARN_ON(!mutex_is_locked(&efx->mac_lock));
2054 WARN_ON(!LOOPBACK_INTERNAL(efx));
2055
2056 efx->link_state.fd = true;
2057 efx->link_state.fc = efx->wanted_fc;
2058 efx->link_state.up = true;
2059
2060 if (efx->loopback_mode == LOOPBACK_GMAC)
2061 efx->link_state.speed = 1000;
2062 else
2063 efx->link_state.speed = 10000;
2064
2065 return !efx_link_state_equal(&efx->link_state, &old_state);
2066}
2067
Ben Hutchings8ceee662008-04-27 12:55:59 +01002068/**************************************************************************
2069 *
2070 * PHY access via GMII
2071 *
2072 **************************************************************************
2073 */
2074
Ben Hutchings8ceee662008-04-27 12:55:59 +01002075/* Wait for GMII access to complete */
2076static int falcon_gmii_wait(struct efx_nic *efx)
2077{
Ben Hutchings80cb9a02009-11-25 16:08:41 +00002078 efx_oword_t md_stat;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002079 int count;
2080
Ben Hutchings177dfcd2008-12-12 21:50:08 -08002081 /* wait upto 50ms - taken max from datasheet */
2082 for (count = 0; count < 5000; count++) {
Ben Hutchings80cb9a02009-11-25 16:08:41 +00002083 efx_reado(efx, &md_stat, FR_AB_MD_STAT);
2084 if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSY) == 0) {
2085 if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_LNFL) != 0 ||
2086 EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSERR) != 0) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01002087 EFX_ERR(efx, "error from GMII access "
Ben Hutchings80cb9a02009-11-25 16:08:41 +00002088 EFX_OWORD_FMT"\n",
2089 EFX_OWORD_VAL(md_stat));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002090 return -EIO;
2091 }
2092 return 0;
2093 }
2094 udelay(10);
2095 }
2096 EFX_ERR(efx, "timed out waiting for GMII\n");
2097 return -ETIMEDOUT;
2098}
2099
Ben Hutchings68e7f452009-04-29 08:05:08 +00002100/* Write an MDIO register of a PHY connected to Falcon. */
2101static int falcon_mdio_write(struct net_device *net_dev,
2102 int prtad, int devad, u16 addr, u16 value)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002103{
Ben Hutchings767e4682008-09-01 12:43:14 +01002104 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002105 efx_oword_t reg;
Ben Hutchings68e7f452009-04-29 08:05:08 +00002106 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002107
Ben Hutchings68e7f452009-04-29 08:05:08 +00002108 EFX_REGDUMP(efx, "writing MDIO %d register %d.%d with 0x%04x\n",
2109 prtad, devad, addr, value);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002110
Steve Hodgsonab867462009-11-28 05:34:44 +00002111 mutex_lock(&efx->mdio_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002112
Ben Hutchings68e7f452009-04-29 08:05:08 +00002113 /* Check MDIO not currently being accessed */
2114 rc = falcon_gmii_wait(efx);
2115 if (rc)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002116 goto out;
2117
2118 /* Write the address/ID register */
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002119 EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002120 efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002121
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002122 EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
2123 FRF_AB_MD_DEV_ADR, devad);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002124 efx_writeo(efx, &reg, FR_AB_MD_ID);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002125
2126 /* Write data */
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002127 EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_TXD, value);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002128 efx_writeo(efx, &reg, FR_AB_MD_TXD);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002129
2130 EFX_POPULATE_OWORD_2(reg,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002131 FRF_AB_MD_WRC, 1,
2132 FRF_AB_MD_GC, 0);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002133 efx_writeo(efx, &reg, FR_AB_MD_CS);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002134
2135 /* Wait for data to be written */
Ben Hutchings68e7f452009-04-29 08:05:08 +00002136 rc = falcon_gmii_wait(efx);
2137 if (rc) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01002138 /* Abort the write operation */
2139 EFX_POPULATE_OWORD_2(reg,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002140 FRF_AB_MD_WRC, 0,
2141 FRF_AB_MD_GC, 1);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002142 efx_writeo(efx, &reg, FR_AB_MD_CS);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002143 udelay(10);
2144 }
2145
Steve Hodgsonab867462009-11-28 05:34:44 +00002146out:
2147 mutex_unlock(&efx->mdio_lock);
Ben Hutchings68e7f452009-04-29 08:05:08 +00002148 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002149}
2150
Ben Hutchings68e7f452009-04-29 08:05:08 +00002151/* Read an MDIO register of a PHY connected to Falcon. */
2152static int falcon_mdio_read(struct net_device *net_dev,
2153 int prtad, int devad, u16 addr)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002154{
Ben Hutchings767e4682008-09-01 12:43:14 +01002155 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002156 efx_oword_t reg;
Ben Hutchings68e7f452009-04-29 08:05:08 +00002157 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002158
Steve Hodgsonab867462009-11-28 05:34:44 +00002159 mutex_lock(&efx->mdio_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002160
Ben Hutchings68e7f452009-04-29 08:05:08 +00002161 /* Check MDIO not currently being accessed */
2162 rc = falcon_gmii_wait(efx);
2163 if (rc)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002164 goto out;
2165
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002166 EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002167 efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002168
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002169 EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
2170 FRF_AB_MD_DEV_ADR, devad);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002171 efx_writeo(efx, &reg, FR_AB_MD_ID);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002172
2173 /* Request data to be read */
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002174 EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_RDC, 1, FRF_AB_MD_GC, 0);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002175 efx_writeo(efx, &reg, FR_AB_MD_CS);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002176
2177 /* Wait for data to become available */
Ben Hutchings68e7f452009-04-29 08:05:08 +00002178 rc = falcon_gmii_wait(efx);
2179 if (rc == 0) {
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002180 efx_reado(efx, &reg, FR_AB_MD_RXD);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002181 rc = EFX_OWORD_FIELD(reg, FRF_AB_MD_RXD);
Ben Hutchings68e7f452009-04-29 08:05:08 +00002182 EFX_REGDUMP(efx, "read from MDIO %d register %d.%d, got %04x\n",
2183 prtad, devad, addr, rc);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002184 } else {
2185 /* Abort the read operation */
2186 EFX_POPULATE_OWORD_2(reg,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002187 FRF_AB_MD_RIC, 0,
2188 FRF_AB_MD_GC, 1);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002189 efx_writeo(efx, &reg, FR_AB_MD_CS);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002190
Ben Hutchings68e7f452009-04-29 08:05:08 +00002191 EFX_LOG(efx, "read from MDIO %d register %d.%d, got error %d\n",
2192 prtad, devad, addr, rc);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002193 }
2194
Steve Hodgsonab867462009-11-28 05:34:44 +00002195out:
2196 mutex_unlock(&efx->mdio_lock);
Ben Hutchings68e7f452009-04-29 08:05:08 +00002197 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002198}
2199
Steve Hodgson26deba52009-11-25 16:11:03 +00002200static void falcon_clock_mac(struct efx_nic *efx)
2201{
2202 unsigned strap_val;
2203 efx_oword_t nic_stat;
2204
2205 /* Configure the NIC generated MAC clock correctly */
2206 efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
2207 strap_val = EFX_IS10G(efx) ? 5 : 3;
Ben Hutchingsdaeda632009-11-28 05:36:04 +00002208 if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
Steve Hodgson26deba52009-11-25 16:11:03 +00002209 EFX_SET_OWORD_FIELD(nic_stat, FRF_BB_EE_STRAP_EN, 1);
2210 EFX_SET_OWORD_FIELD(nic_stat, FRF_BB_EE_STRAP, strap_val);
2211 efx_writeo(efx, &nic_stat, FR_AB_NIC_STAT);
2212 } else {
2213 /* Falcon A1 does not support 1G/10G speed switching
2214 * and must not be used with a PHY that does. */
2215 BUG_ON(EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_PINS) !=
2216 strap_val);
2217 }
2218}
2219
Ben Hutchings177dfcd2008-12-12 21:50:08 -08002220int falcon_switch_mac(struct efx_nic *efx)
2221{
2222 struct efx_mac_operations *old_mac_op = efx->mac_op;
Ben Hutchings55edc6e2009-11-25 16:11:35 +00002223 struct falcon_nic_data *nic_data = efx->nic_data;
2224 unsigned int stats_done_offset;
Ben Hutchings1974cc22009-01-29 18:00:07 +00002225 int rc = 0;
2226
2227 /* Don't try to fetch MAC stats while we're switching MACs */
Ben Hutchings55edc6e2009-11-25 16:11:35 +00002228 falcon_stop_nic_stats(efx);
Ben Hutchings177dfcd2008-12-12 21:50:08 -08002229
Steve Hodgson0cc1283872009-01-29 17:49:59 +00002230 WARN_ON(!mutex_is_locked(&efx->mac_lock));
Ben Hutchings177dfcd2008-12-12 21:50:08 -08002231 efx->mac_op = (EFX_IS10G(efx) ?
2232 &falcon_xmac_operations : &falcon_gmac_operations);
Ben Hutchings177dfcd2008-12-12 21:50:08 -08002233
Ben Hutchings55edc6e2009-11-25 16:11:35 +00002234 if (EFX_IS10G(efx))
2235 stats_done_offset = XgDmaDone_offset;
2236 else
2237 stats_done_offset = GDmaDone_offset;
2238 nic_data->stats_dma_done = efx->stats_buffer.addr + stats_done_offset;
2239
Steve Hodgson0cc1283872009-01-29 17:49:59 +00002240 if (old_mac_op == efx->mac_op)
Ben Hutchings1974cc22009-01-29 18:00:07 +00002241 goto out;
Ben Hutchings177dfcd2008-12-12 21:50:08 -08002242
Steve Hodgson26deba52009-11-25 16:11:03 +00002243 falcon_clock_mac(efx);
2244
Ben Hutchings177dfcd2008-12-12 21:50:08 -08002245 EFX_LOG(efx, "selected %cMAC\n", EFX_IS10G(efx) ? 'X' : 'G');
Steve Hodgson0cc1283872009-01-29 17:49:59 +00002246 /* Not all macs support a mac-level link state */
Ben Hutchings9007b9f2009-11-25 16:12:01 +00002247 efx->xmac_poll_required = false;
Steve Hodgson0cc1283872009-01-29 17:49:59 +00002248
Ben Hutchings1974cc22009-01-29 18:00:07 +00002249 rc = falcon_reset_macs(efx);
2250out:
Ben Hutchings55edc6e2009-11-25 16:11:35 +00002251 falcon_start_nic_stats(efx);
Ben Hutchings1974cc22009-01-29 18:00:07 +00002252 return rc;
Ben Hutchings177dfcd2008-12-12 21:50:08 -08002253}
2254
Ben Hutchings8ceee662008-04-27 12:55:59 +01002255/* This call is responsible for hooking in the MAC and PHY operations */
2256int falcon_probe_port(struct efx_nic *efx)
2257{
2258 int rc;
2259
Ben Hutchings96c457262009-10-23 08:32:42 +00002260 switch (efx->phy_type) {
2261 case PHY_TYPE_SFX7101:
2262 efx->phy_op = &falcon_sfx7101_phy_ops;
2263 break;
2264 case PHY_TYPE_SFT9001A:
2265 case PHY_TYPE_SFT9001B:
2266 efx->phy_op = &falcon_sft9001_phy_ops;
2267 break;
2268 case PHY_TYPE_QT2022C2:
2269 case PHY_TYPE_QT2025C:
Ben Hutchingsb37b62f2009-10-23 08:33:42 +00002270 efx->phy_op = &falcon_qt202x_phy_ops;
Ben Hutchings96c457262009-10-23 08:32:42 +00002271 break;
2272 default:
2273 EFX_ERR(efx, "Unknown PHY type %d\n",
2274 efx->phy_type);
2275 return -ENODEV;
2276 }
2277
2278 if (efx->phy_op->macs & EFX_XMAC)
2279 efx->loopback_modes |= ((1 << LOOPBACK_XGMII) |
2280 (1 << LOOPBACK_XGXS) |
2281 (1 << LOOPBACK_XAUI));
2282 if (efx->phy_op->macs & EFX_GMAC)
2283 efx->loopback_modes |= (1 << LOOPBACK_GMAC);
2284 efx->loopback_modes |= efx->phy_op->loopbacks;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002285
Ben Hutchings68e7f452009-04-29 08:05:08 +00002286 /* Set up MDIO structure for PHY */
2287 efx->mdio.mmds = efx->phy_op->mmds;
2288 efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
2289 efx->mdio.mdio_read = falcon_mdio_read;
2290 efx->mdio.mdio_write = falcon_mdio_write;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002291
Steve Hodgsonb895d732009-11-28 05:35:00 +00002292 /* Initial assumption */
2293 efx->link_state.speed = 10000;
2294 efx->link_state.fd = true;
2295
Ben Hutchings8ceee662008-04-27 12:55:59 +01002296 /* Hardware flow ctrl. FalconA RX FIFO too small for pause generation */
Ben Hutchingsdaeda632009-11-28 05:36:04 +00002297 if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -08002298 efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002299 else
Ben Hutchings04cc8ca2008-12-12 21:50:46 -08002300 efx->wanted_fc = EFX_FC_RX;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002301
2302 /* Allocate buffer for stats */
2303 rc = falcon_alloc_buffer(efx, &efx->stats_buffer,
2304 FALCON_MAC_STATS_SIZE);
2305 if (rc)
2306 return rc;
Jaswinder Singh Rajput9c8976a2009-02-11 23:49:52 +05302307 EFX_LOG(efx, "stats buffer at %llx (virt %p phys %llx)\n",
2308 (u64)efx->stats_buffer.dma_addr,
Ben Hutchings8ceee662008-04-27 12:55:59 +01002309 efx->stats_buffer.addr,
Jaswinder Singh Rajput9c8976a2009-02-11 23:49:52 +05302310 (u64)virt_to_phys(efx->stats_buffer.addr));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002311
2312 return 0;
2313}
2314
2315void falcon_remove_port(struct efx_nic *efx)
2316{
2317 falcon_free_buffer(efx, &efx->stats_buffer);
2318}
2319
2320/**************************************************************************
2321 *
2322 * Multicast filtering
2323 *
2324 **************************************************************************
2325 */
2326
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00002327void falcon_push_multicast_hash(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +01002328{
2329 union efx_multicast_hash *mc_hash = &efx->multicast_hash;
2330
Ben Hutchings8be4f3e2009-11-25 16:12:16 +00002331 WARN_ON(!mutex_is_locked(&efx->mac_lock));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002332
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002333 efx_writeo(efx, &mc_hash->oword[0], FR_AB_MAC_MC_HASH_REG0);
2334 efx_writeo(efx, &mc_hash->oword[1], FR_AB_MAC_MC_HASH_REG1);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002335}
2336
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002337
2338/**************************************************************************
2339 *
2340 * Falcon test code
2341 *
2342 **************************************************************************/
2343
2344int falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
2345{
2346 struct falcon_nvconfig *nvconfig;
2347 struct efx_spi_device *spi;
2348 void *region;
2349 int rc, magic_num, struct_ver;
2350 __le16 *word, *limit;
2351 u32 csum;
2352
Ben Hutchings2f7f5732008-12-12 21:34:25 -08002353 spi = efx->spi_flash ? efx->spi_flash : efx->spi_eeprom;
2354 if (!spi)
2355 return -EINVAL;
2356
Ben Hutchings0a95f562008-11-04 20:33:11 +00002357 region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL);
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002358 if (!region)
2359 return -ENOMEM;
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002360 nvconfig = region + FALCON_NVCONFIG_OFFSET;
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002361
Ben Hutchingsf4150722008-11-04 20:34:28 +00002362 mutex_lock(&efx->spi_lock);
Ben Hutchings0a95f562008-11-04 20:33:11 +00002363 rc = falcon_spi_read(spi, 0, FALCON_NVCONFIG_END, NULL, region);
Ben Hutchingsf4150722008-11-04 20:34:28 +00002364 mutex_unlock(&efx->spi_lock);
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002365 if (rc) {
2366 EFX_ERR(efx, "Failed to read %s\n",
2367 efx->spi_flash ? "flash" : "EEPROM");
2368 rc = -EIO;
2369 goto out;
2370 }
2371
2372 magic_num = le16_to_cpu(nvconfig->board_magic_num);
2373 struct_ver = le16_to_cpu(nvconfig->board_struct_ver);
2374
2375 rc = -EINVAL;
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002376 if (magic_num != FALCON_NVCONFIG_BOARD_MAGIC_NUM) {
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002377 EFX_ERR(efx, "NVRAM bad magic 0x%x\n", magic_num);
2378 goto out;
2379 }
2380 if (struct_ver < 2) {
2381 EFX_ERR(efx, "NVRAM has ancient version 0x%x\n", struct_ver);
2382 goto out;
2383 } else if (struct_ver < 4) {
2384 word = &nvconfig->board_magic_num;
2385 limit = (__le16 *) (nvconfig + 1);
2386 } else {
2387 word = region;
Ben Hutchings0a95f562008-11-04 20:33:11 +00002388 limit = region + FALCON_NVCONFIG_END;
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002389 }
2390 for (csum = 0; word < limit; ++word)
2391 csum += le16_to_cpu(*word);
2392
2393 if (~csum & 0xffff) {
2394 EFX_ERR(efx, "NVRAM has incorrect checksum\n");
2395 goto out;
2396 }
2397
2398 rc = 0;
2399 if (nvconfig_out)
2400 memcpy(nvconfig_out, nvconfig, sizeof(*nvconfig));
2401
2402 out:
2403 kfree(region);
2404 return rc;
2405}
2406
2407/* Registers tested in the falcon register test */
2408static struct {
2409 unsigned address;
2410 efx_oword_t mask;
2411} efx_test_registers[] = {
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002412 { FR_AZ_ADR_REGION,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002413 EFX_OWORD32(0x0001FFFF, 0x0001FFFF, 0x0001FFFF, 0x0001FFFF) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002414 { FR_AZ_RX_CFG,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002415 EFX_OWORD32(0xFFFFFFFE, 0x00017FFF, 0x00000000, 0x00000000) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002416 { FR_AZ_TX_CFG,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002417 EFX_OWORD32(0x7FFF0037, 0x00000000, 0x00000000, 0x00000000) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002418 { FR_AZ_TX_RESERVED,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002419 EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002420 { FR_AB_MAC_CTRL,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002421 EFX_OWORD32(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002422 { FR_AZ_SRM_TX_DC_CFG,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002423 EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002424 { FR_AZ_RX_DC_CFG,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002425 EFX_OWORD32(0x0000000F, 0x00000000, 0x00000000, 0x00000000) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002426 { FR_AZ_RX_DC_PF_WM,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002427 EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002428 { FR_BZ_DP_CTRL,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002429 EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002430 { FR_AB_GM_CFG2,
Ben Hutchings177dfcd2008-12-12 21:50:08 -08002431 EFX_OWORD32(0x00007337, 0x00000000, 0x00000000, 0x00000000) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002432 { FR_AB_GMF_CFG0,
Ben Hutchings177dfcd2008-12-12 21:50:08 -08002433 EFX_OWORD32(0x00001F1F, 0x00000000, 0x00000000, 0x00000000) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002434 { FR_AB_XM_GLB_CFG,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002435 EFX_OWORD32(0x00000C68, 0x00000000, 0x00000000, 0x00000000) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002436 { FR_AB_XM_TX_CFG,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002437 EFX_OWORD32(0x00080164, 0x00000000, 0x00000000, 0x00000000) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002438 { FR_AB_XM_RX_CFG,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002439 EFX_OWORD32(0x07100A0C, 0x00000000, 0x00000000, 0x00000000) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002440 { FR_AB_XM_RX_PARAM,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002441 EFX_OWORD32(0x00001FF8, 0x00000000, 0x00000000, 0x00000000) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002442 { FR_AB_XM_FC,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002443 EFX_OWORD32(0xFFFF0001, 0x00000000, 0x00000000, 0x00000000) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002444 { FR_AB_XM_ADR_LO,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002445 EFX_OWORD32(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000) },
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002446 { FR_AB_XX_SD_CTL,
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002447 EFX_OWORD32(0x0003FF0F, 0x00000000, 0x00000000, 0x00000000) },
2448};
2449
2450static bool efx_masked_compare_oword(const efx_oword_t *a, const efx_oword_t *b,
2451 const efx_oword_t *mask)
2452{
2453 return ((a->u64[0] ^ b->u64[0]) & mask->u64[0]) ||
2454 ((a->u64[1] ^ b->u64[1]) & mask->u64[1]);
2455}
2456
2457int falcon_test_registers(struct efx_nic *efx)
2458{
2459 unsigned address = 0, i, j;
2460 efx_oword_t mask, imask, original, reg, buf;
2461
2462 /* Falcon should be in loopback to isolate the XMAC from the PHY */
2463 WARN_ON(!LOOPBACK_INTERNAL(efx));
2464
2465 for (i = 0; i < ARRAY_SIZE(efx_test_registers); ++i) {
2466 address = efx_test_registers[i].address;
2467 mask = imask = efx_test_registers[i].mask;
2468 EFX_INVERT_OWORD(imask);
2469
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002470 efx_reado(efx, &original, address);
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002471
2472 /* bit sweep on and off */
2473 for (j = 0; j < 128; j++) {
2474 if (!EFX_EXTRACT_OWORD32(mask, j, j))
2475 continue;
2476
2477 /* Test this testable bit can be set in isolation */
2478 EFX_AND_OWORD(reg, original, mask);
2479 EFX_SET_OWORD32(reg, j, j, 1);
2480
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002481 efx_writeo(efx, &reg, address);
2482 efx_reado(efx, &buf, address);
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002483
2484 if (efx_masked_compare_oword(&reg, &buf, &mask))
2485 goto fail;
2486
2487 /* Test this testable bit can be cleared in isolation */
2488 EFX_OR_OWORD(reg, original, mask);
2489 EFX_SET_OWORD32(reg, j, j, 0);
2490
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002491 efx_writeo(efx, &reg, address);
2492 efx_reado(efx, &buf, address);
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002493
2494 if (efx_masked_compare_oword(&reg, &buf, &mask))
2495 goto fail;
2496 }
2497
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002498 efx_writeo(efx, &original, address);
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002499 }
2500
2501 return 0;
2502
2503fail:
2504 EFX_ERR(efx, "wrote "EFX_OWORD_FMT" read "EFX_OWORD_FMT
2505 " at address 0x%x mask "EFX_OWORD_FMT"\n", EFX_OWORD_VAL(reg),
2506 EFX_OWORD_VAL(buf), address, EFX_OWORD_VAL(mask));
2507 return -EIO;
2508}
2509
Ben Hutchings8ceee662008-04-27 12:55:59 +01002510/**************************************************************************
2511 *
2512 * Device reset
2513 *
2514 **************************************************************************
2515 */
2516
2517/* Resets NIC to known state. This routine must be called in process
2518 * context and is allowed to sleep. */
2519int falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
2520{
2521 struct falcon_nic_data *nic_data = efx->nic_data;
2522 efx_oword_t glb_ctl_reg_ker;
2523 int rc;
2524
Ben Hutchingsc4593022009-11-23 16:08:17 +00002525 EFX_LOG(efx, "performing %s hardware reset\n", RESET_TYPE(method));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002526
2527 /* Initiate device reset */
2528 if (method == RESET_TYPE_WORLD) {
2529 rc = pci_save_state(efx->pci_dev);
2530 if (rc) {
2531 EFX_ERR(efx, "failed to backup PCI state of primary "
2532 "function prior to hardware reset\n");
2533 goto fail1;
2534 }
2535 if (FALCON_IS_DUAL_FUNC(efx)) {
2536 rc = pci_save_state(nic_data->pci_dev2);
2537 if (rc) {
2538 EFX_ERR(efx, "failed to backup PCI state of "
2539 "secondary function prior to "
2540 "hardware reset\n");
2541 goto fail2;
2542 }
2543 }
2544
2545 EFX_POPULATE_OWORD_2(glb_ctl_reg_ker,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002546 FRF_AB_EXT_PHY_RST_DUR,
2547 FFE_AB_EXT_PHY_RST_DUR_10240US,
2548 FRF_AB_SWRST, 1);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002549 } else {
Ben Hutchings8ceee662008-04-27 12:55:59 +01002550 EFX_POPULATE_OWORD_7(glb_ctl_reg_ker,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002551 /* exclude PHY from "invisible" reset */
2552 FRF_AB_EXT_PHY_RST_CTL,
2553 method == RESET_TYPE_INVISIBLE,
2554 /* exclude EEPROM/flash and PCIe */
2555 FRF_AB_PCIE_CORE_RST_CTL, 1,
2556 FRF_AB_PCIE_NSTKY_RST_CTL, 1,
2557 FRF_AB_PCIE_SD_RST_CTL, 1,
2558 FRF_AB_EE_RST_CTL, 1,
2559 FRF_AB_EXT_PHY_RST_DUR,
2560 FFE_AB_EXT_PHY_RST_DUR_10240US,
2561 FRF_AB_SWRST, 1);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002562 }
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002563 efx_writeo(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002564
2565 EFX_LOG(efx, "waiting for hardware reset\n");
2566 schedule_timeout_uninterruptible(HZ / 20);
2567
2568 /* Restore PCI configuration if needed */
2569 if (method == RESET_TYPE_WORLD) {
2570 if (FALCON_IS_DUAL_FUNC(efx)) {
2571 rc = pci_restore_state(nic_data->pci_dev2);
2572 if (rc) {
2573 EFX_ERR(efx, "failed to restore PCI config for "
2574 "the secondary function\n");
2575 goto fail3;
2576 }
2577 }
2578 rc = pci_restore_state(efx->pci_dev);
2579 if (rc) {
2580 EFX_ERR(efx, "failed to restore PCI config for the "
2581 "primary function\n");
2582 goto fail4;
2583 }
2584 EFX_LOG(efx, "successfully restored PCI config\n");
2585 }
2586
2587 /* Assert that reset complete */
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002588 efx_reado(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002589 if (EFX_OWORD_FIELD(glb_ctl_reg_ker, FRF_AB_SWRST) != 0) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01002590 rc = -ETIMEDOUT;
2591 EFX_ERR(efx, "timed out waiting for hardware reset\n");
2592 goto fail5;
2593 }
2594 EFX_LOG(efx, "hardware reset complete\n");
2595
2596 return 0;
2597
2598 /* pci_save_state() and pci_restore_state() MUST be called in pairs */
2599fail2:
2600fail3:
2601 pci_restore_state(efx->pci_dev);
2602fail1:
2603fail4:
2604fail5:
2605 return rc;
2606}
2607
Ben Hutchingsfe758202009-11-25 16:11:45 +00002608void falcon_monitor(struct efx_nic *efx)
2609{
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002610 bool link_changed;
Ben Hutchingsfe758202009-11-25 16:11:45 +00002611 int rc;
2612
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002613 BUG_ON(!mutex_is_locked(&efx->mac_lock));
2614
Ben Hutchingsfe758202009-11-25 16:11:45 +00002615 rc = falcon_board(efx)->type->monitor(efx);
2616 if (rc) {
2617 EFX_ERR(efx, "Board sensor %s; shutting down PHY\n",
2618 (rc == -ERANGE) ? "reported fault" : "failed");
2619 efx->phy_mode |= PHY_MODE_LOW_POWER;
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002620 __efx_reconfigure_port(efx);
Ben Hutchingsfe758202009-11-25 16:11:45 +00002621 }
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +00002622
2623 if (LOOPBACK_INTERNAL(efx))
2624 link_changed = falcon_loopback_link_poll(efx);
2625 else
2626 link_changed = efx->phy_op->poll(efx);
2627
2628 if (link_changed) {
2629 falcon_stop_nic_stats(efx);
2630 falcon_deconfigure_mac_wrapper(efx);
2631
2632 falcon_switch_mac(efx);
2633 efx->mac_op->reconfigure(efx);
2634
2635 falcon_start_nic_stats(efx);
2636
2637 efx_link_status_changed(efx);
2638 }
2639
Ben Hutchings9007b9f2009-11-25 16:12:01 +00002640 if (EFX_IS10G(efx))
2641 falcon_poll_xmac(efx);
Ben Hutchingsfe758202009-11-25 16:11:45 +00002642}
2643
Ben Hutchings8ceee662008-04-27 12:55:59 +01002644/* Zeroes out the SRAM contents. This routine must be called in
2645 * process context and is allowed to sleep.
2646 */
2647static int falcon_reset_sram(struct efx_nic *efx)
2648{
2649 efx_oword_t srm_cfg_reg_ker, gpio_cfg_reg_ker;
2650 int count;
2651
2652 /* Set the SRAM wake/sleep GPIO appropriately. */
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002653 efx_reado(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002654 EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OEN, 1);
2655 EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OUT, 1);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002656 efx_writeo(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002657
2658 /* Initiate SRAM reset */
2659 EFX_POPULATE_OWORD_2(srm_cfg_reg_ker,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002660 FRF_AZ_SRM_INIT_EN, 1,
2661 FRF_AZ_SRM_NB_SZ, 0);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002662 efx_writeo(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002663
2664 /* Wait for SRAM reset to complete */
2665 count = 0;
2666 do {
2667 EFX_LOG(efx, "waiting for SRAM reset (attempt %d)...\n", count);
2668
2669 /* SRAM reset is slow; expect around 16ms */
2670 schedule_timeout_uninterruptible(HZ / 50);
2671
2672 /* Check for reset complete */
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002673 efx_reado(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002674 if (!EFX_OWORD_FIELD(srm_cfg_reg_ker, FRF_AZ_SRM_INIT_EN)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01002675 EFX_LOG(efx, "SRAM reset complete\n");
2676
2677 return 0;
2678 }
2679 } while (++count < 20); /* wait upto 0.4 sec */
2680
2681 EFX_ERR(efx, "timed out waiting for SRAM reset\n");
2682 return -ETIMEDOUT;
2683}
2684
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002685static int falcon_spi_device_init(struct efx_nic *efx,
2686 struct efx_spi_device **spi_device_ret,
2687 unsigned int device_id, u32 device_type)
2688{
2689 struct efx_spi_device *spi_device;
2690
2691 if (device_type != 0) {
Ben Hutchings0c53d8c2008-12-12 22:08:50 -08002692 spi_device = kzalloc(sizeof(*spi_device), GFP_KERNEL);
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002693 if (!spi_device)
2694 return -ENOMEM;
2695 spi_device->device_id = device_id;
2696 spi_device->size =
2697 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE);
2698 spi_device->addr_len =
2699 SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN);
2700 spi_device->munge_address = (spi_device->size == 1 << 9 &&
2701 spi_device->addr_len == 1);
Ben Hutchingsf4150722008-11-04 20:34:28 +00002702 spi_device->erase_command =
2703 SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ERASE_CMD);
2704 spi_device->erase_size =
2705 1 << SPI_DEV_TYPE_FIELD(device_type,
2706 SPI_DEV_TYPE_ERASE_SIZE);
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002707 spi_device->block_size =
2708 1 << SPI_DEV_TYPE_FIELD(device_type,
2709 SPI_DEV_TYPE_BLOCK_SIZE);
2710
2711 spi_device->efx = efx;
2712 } else {
2713 spi_device = NULL;
2714 }
2715
2716 kfree(*spi_device_ret);
2717 *spi_device_ret = spi_device;
2718 return 0;
2719}
2720
2721
2722static void falcon_remove_spi_devices(struct efx_nic *efx)
2723{
2724 kfree(efx->spi_eeprom);
2725 efx->spi_eeprom = NULL;
2726 kfree(efx->spi_flash);
2727 efx->spi_flash = NULL;
2728}
2729
Ben Hutchings8ceee662008-04-27 12:55:59 +01002730/* Extract non-volatile configuration */
2731static int falcon_probe_nvconfig(struct efx_nic *efx)
2732{
2733 struct falcon_nvconfig *nvconfig;
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002734 int board_rev;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002735 int rc;
2736
Ben Hutchings8ceee662008-04-27 12:55:59 +01002737 nvconfig = kmalloc(sizeof(*nvconfig), GFP_KERNEL);
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002738 if (!nvconfig)
2739 return -ENOMEM;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002740
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002741 rc = falcon_read_nvram(efx, nvconfig);
2742 if (rc == -EINVAL) {
2743 EFX_ERR(efx, "NVRAM is invalid therefore using defaults\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +01002744 efx->phy_type = PHY_TYPE_NONE;
Ben Hutchings68e7f452009-04-29 08:05:08 +00002745 efx->mdio.prtad = MDIO_PRTAD_NONE;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002746 board_rev = 0;
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002747 rc = 0;
2748 } else if (rc) {
2749 goto fail1;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002750 } else {
2751 struct falcon_nvconfig_board_v2 *v2 = &nvconfig->board_v2;
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002752 struct falcon_nvconfig_board_v3 *v3 = &nvconfig->board_v3;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002753
2754 efx->phy_type = v2->port0_phy_type;
Ben Hutchings68e7f452009-04-29 08:05:08 +00002755 efx->mdio.prtad = v2->port0_phy_addr;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002756 board_rev = le16_to_cpu(v2->board_revision);
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002757
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002758 if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) {
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002759 rc = falcon_spi_device_init(
2760 efx, &efx->spi_flash, FFE_AB_SPI_DEVICE_FLASH,
2761 le32_to_cpu(v3->spi_device_type
2762 [FFE_AB_SPI_DEVICE_FLASH]));
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002763 if (rc)
2764 goto fail2;
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002765 rc = falcon_spi_device_init(
2766 efx, &efx->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM,
2767 le32_to_cpu(v3->spi_device_type
2768 [FFE_AB_SPI_DEVICE_EEPROM]));
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002769 if (rc)
2770 goto fail2;
2771 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002772 }
2773
Ben Hutchings8c8661e2008-09-01 12:49:02 +01002774 /* Read the MAC addresses */
2775 memcpy(efx->mac_address, nvconfig->mac_address[0], ETH_ALEN);
2776
Ben Hutchings68e7f452009-04-29 08:05:08 +00002777 EFX_LOG(efx, "PHY is %d phy_id %d\n", efx->phy_type, efx->mdio.prtad);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002778
Ben Hutchings3473a5b2009-10-23 08:29:16 +00002779 falcon_probe_board(efx, board_rev);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002780
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002781 kfree(nvconfig);
2782 return 0;
2783
2784 fail2:
2785 falcon_remove_spi_devices(efx);
2786 fail1:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002787 kfree(nvconfig);
2788 return rc;
2789}
2790
2791/* Probe the NIC variant (revision, ASIC vs FPGA, function count, port
2792 * count, port speed). Set workaround and feature flags accordingly.
2793 */
2794static int falcon_probe_nic_variant(struct efx_nic *efx)
2795{
2796 efx_oword_t altera_build;
Ben Hutchings177dfcd2008-12-12 21:50:08 -08002797 efx_oword_t nic_stat;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002798
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002799 efx_reado(efx, &altera_build, FR_AZ_ALTERA_BUILD);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002800 if (EFX_OWORD_FIELD(altera_build, FRF_AZ_ALTERA_BUILD_VER)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01002801 EFX_ERR(efx, "Falcon FPGA not supported\n");
2802 return -ENODEV;
2803 }
2804
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002805 efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
Ben Hutchings177dfcd2008-12-12 21:50:08 -08002806
Ben Hutchingsdaeda632009-11-28 05:36:04 +00002807 if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
2808 u8 pci_rev = efx->pci_dev->revision;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002809
Ben Hutchingsdaeda632009-11-28 05:36:04 +00002810 if ((pci_rev == 0xff) || (pci_rev == 0)) {
2811 EFX_ERR(efx, "Falcon rev A0 not supported\n");
2812 return -ENODEV;
2813 }
Steve Hodgsonb895d732009-11-28 05:35:00 +00002814 if (EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_10G) == 0) {
2815 EFX_ERR(efx, "Falcon rev A1 1G not supported\n");
2816 return -ENODEV;
2817 }
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002818 if (EFX_OWORD_FIELD(nic_stat, FRF_AA_STRAP_PCIE) == 0) {
Ben Hutchings8ceee662008-04-27 12:55:59 +01002819 EFX_ERR(efx, "Falcon rev A1 PCI-X not supported\n");
2820 return -ENODEV;
2821 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01002822 }
2823
2824 return 0;
2825}
2826
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002827/* Probe all SPI devices on the NIC */
2828static void falcon_probe_spi_devices(struct efx_nic *efx)
2829{
2830 efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
Ben Hutchings2f7f5732008-12-12 21:34:25 -08002831 int boot_dev;
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002832
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002833 efx_reado(efx, &gpio_ctl, FR_AB_GPIO_CTL);
2834 efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
2835 efx_reado(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002836
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002837 if (EFX_OWORD_FIELD(gpio_ctl, FRF_AB_GPIO3_PWRUP_VALUE)) {
2838 boot_dev = (EFX_OWORD_FIELD(nic_stat, FRF_AB_SF_PRST) ?
2839 FFE_AB_SPI_DEVICE_FLASH : FFE_AB_SPI_DEVICE_EEPROM);
Ben Hutchings2f7f5732008-12-12 21:34:25 -08002840 EFX_LOG(efx, "Booted from %s\n",
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002841 boot_dev == FFE_AB_SPI_DEVICE_FLASH ? "flash" : "EEPROM");
Ben Hutchings2f7f5732008-12-12 21:34:25 -08002842 } else {
2843 /* Disable VPD and set clock dividers to safe
2844 * values for initial programming. */
2845 boot_dev = -1;
2846 EFX_LOG(efx, "Booted from internal ASIC settings;"
2847 " setting SPI config\n");
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002848 EFX_POPULATE_OWORD_3(ee_vpd_cfg, FRF_AB_EE_VPD_EN, 0,
Ben Hutchings2f7f5732008-12-12 21:34:25 -08002849 /* 125 MHz / 7 ~= 20 MHz */
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002850 FRF_AB_EE_SF_CLOCK_DIV, 7,
Ben Hutchings2f7f5732008-12-12 21:34:25 -08002851 /* 125 MHz / 63 ~= 2 MHz */
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002852 FRF_AB_EE_EE_CLOCK_DIV, 63);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002853 efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002854 }
2855
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002856 if (boot_dev == FFE_AB_SPI_DEVICE_FLASH)
2857 falcon_spi_device_init(efx, &efx->spi_flash,
2858 FFE_AB_SPI_DEVICE_FLASH,
Ben Hutchings2f7f5732008-12-12 21:34:25 -08002859 default_flash_type);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002860 if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM)
2861 falcon_spi_device_init(efx, &efx->spi_eeprom,
2862 FFE_AB_SPI_DEVICE_EEPROM,
Ben Hutchings2f7f5732008-12-12 21:34:25 -08002863 large_eeprom_type);
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002864}
2865
Ben Hutchings8ceee662008-04-27 12:55:59 +01002866int falcon_probe_nic(struct efx_nic *efx)
2867{
2868 struct falcon_nic_data *nic_data;
Ben Hutchingse775fb92009-11-23 16:06:02 +00002869 struct falcon_board *board;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002870 int rc;
2871
Ben Hutchings8ceee662008-04-27 12:55:59 +01002872 /* Allocate storage for hardware specific data */
2873 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
Ben Hutchings88c59422008-09-03 15:07:50 +01002874 if (!nic_data)
2875 return -ENOMEM;
Ben Hutchings5daab962008-05-16 21:19:43 +01002876 efx->nic_data = nic_data;
Ben Hutchings8ceee662008-04-27 12:55:59 +01002877
2878 /* Determine number of ports etc. */
2879 rc = falcon_probe_nic_variant(efx);
2880 if (rc)
2881 goto fail1;
2882
2883 /* Probe secondary function if expected */
2884 if (FALCON_IS_DUAL_FUNC(efx)) {
2885 struct pci_dev *dev = pci_dev_get(efx->pci_dev);
2886
2887 while ((dev = pci_get_device(EFX_VENDID_SFC, FALCON_A_S_DEVID,
2888 dev))) {
2889 if (dev->bus == efx->pci_dev->bus &&
2890 dev->devfn == efx->pci_dev->devfn + 1) {
2891 nic_data->pci_dev2 = dev;
2892 break;
2893 }
2894 }
2895 if (!nic_data->pci_dev2) {
2896 EFX_ERR(efx, "failed to find secondary function\n");
2897 rc = -ENODEV;
2898 goto fail2;
2899 }
2900 }
2901
2902 /* Now we can reset the NIC */
2903 rc = falcon_reset_hw(efx, RESET_TYPE_ALL);
2904 if (rc) {
2905 EFX_ERR(efx, "failed to reset NIC\n");
2906 goto fail3;
2907 }
2908
2909 /* Allocate memory for INT_KER */
2910 rc = falcon_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t));
2911 if (rc)
2912 goto fail4;
2913 BUG_ON(efx->irq_status.dma_addr & 0x0f);
2914
Jaswinder Singh Rajput9c8976a2009-02-11 23:49:52 +05302915 EFX_LOG(efx, "INT_KER at %llx (virt %p phys %llx)\n",
2916 (u64)efx->irq_status.dma_addr,
2917 efx->irq_status.addr, (u64)virt_to_phys(efx->irq_status.addr));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002918
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002919 falcon_probe_spi_devices(efx);
2920
Ben Hutchings8ceee662008-04-27 12:55:59 +01002921 /* Read in the non-volatile configuration */
2922 rc = falcon_probe_nvconfig(efx);
2923 if (rc)
2924 goto fail5;
2925
Ben Hutchings37b5a602008-05-30 22:27:04 +01002926 /* Initialise I2C adapter */
Ben Hutchingse775fb92009-11-23 16:06:02 +00002927 board = falcon_board(efx);
2928 board->i2c_adap.owner = THIS_MODULE;
2929 board->i2c_data = falcon_i2c_bit_operations;
2930 board->i2c_data.data = efx;
2931 board->i2c_adap.algo_data = &board->i2c_data;
2932 board->i2c_adap.dev.parent = &efx->pci_dev->dev;
2933 strlcpy(board->i2c_adap.name, "SFC4000 GPIO",
2934 sizeof(board->i2c_adap.name));
2935 rc = i2c_bit_add_bus(&board->i2c_adap);
Ben Hutchings37b5a602008-05-30 22:27:04 +01002936 if (rc)
2937 goto fail5;
2938
Ben Hutchings44838a42009-11-25 16:09:41 +00002939 rc = falcon_board(efx)->type->init(efx);
Ben Hutchings278c0622009-11-23 16:05:12 +00002940 if (rc) {
2941 EFX_ERR(efx, "failed to initialise board\n");
2942 goto fail6;
2943 }
2944
Ben Hutchings55edc6e2009-11-25 16:11:35 +00002945 nic_data->stats_disable_count = 1;
2946 setup_timer(&nic_data->stats_timer, &falcon_stats_timer_func,
2947 (unsigned long)efx);
2948
Ben Hutchings8ceee662008-04-27 12:55:59 +01002949 return 0;
2950
Ben Hutchings278c0622009-11-23 16:05:12 +00002951 fail6:
Ben Hutchingse775fb92009-11-23 16:06:02 +00002952 BUG_ON(i2c_del_adapter(&board->i2c_adap));
2953 memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
Ben Hutchings8ceee662008-04-27 12:55:59 +01002954 fail5:
Ben Hutchings4a5b5042008-09-01 12:47:16 +01002955 falcon_remove_spi_devices(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01002956 falcon_free_buffer(efx, &efx->irq_status);
2957 fail4:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002958 fail3:
2959 if (nic_data->pci_dev2) {
2960 pci_dev_put(nic_data->pci_dev2);
2961 nic_data->pci_dev2 = NULL;
2962 }
2963 fail2:
Ben Hutchings8ceee662008-04-27 12:55:59 +01002964 fail1:
2965 kfree(efx->nic_data);
2966 return rc;
2967}
2968
Ben Hutchings56241ce2009-10-23 08:30:06 +00002969static void falcon_init_rx_cfg(struct efx_nic *efx)
2970{
2971 /* Prior to Siena the RX DMA engine will split each frame at
2972 * intervals of RX_USR_BUF_SIZE (32-byte units). We set it to
2973 * be so large that that never happens. */
2974 const unsigned huge_buf_size = (3 * 4096) >> 5;
2975 /* RX control FIFO thresholds (32 entries) */
2976 const unsigned ctrl_xon_thr = 20;
2977 const unsigned ctrl_xoff_thr = 25;
2978 /* RX data FIFO thresholds (256-byte units; size varies) */
Ben Hutchings625b4512009-10-23 08:30:17 +00002979 int data_xon_thr = rx_xon_thresh_bytes >> 8;
2980 int data_xoff_thr = rx_xoff_thresh_bytes >> 8;
Ben Hutchings56241ce2009-10-23 08:30:06 +00002981 efx_oword_t reg;
2982
Ben Hutchings12d00ca2009-10-23 08:30:46 +00002983 efx_reado(efx, &reg, FR_AZ_RX_CFG);
Ben Hutchingsdaeda632009-11-28 05:36:04 +00002984 if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
Ben Hutchings625b4512009-10-23 08:30:17 +00002985 /* Data FIFO size is 5.5K */
2986 if (data_xon_thr < 0)
2987 data_xon_thr = 512 >> 8;
2988 if (data_xoff_thr < 0)
2989 data_xoff_thr = 2048 >> 8;
Ben Hutchings3e6c4532009-10-23 08:30:36 +00002990 EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_DESC_PUSH_EN, 0);
2991 EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_USR_BUF_SIZE,
2992 huge_buf_size);
2993 EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_MAC_TH, data_xon_thr);
2994 EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_MAC_TH, data_xoff_thr);
2995 EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_TX_TH, ctrl_xon_thr);
2996 EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_TX_TH, ctrl_xoff_thr);
Ben Hutchings56241ce2009-10-23 08:30:06 +00002997 } else {
Ben Hutchings625b4512009-10-23 08:30:17 +00002998 /* Data FIFO size is 80K; register fields moved */
2999 if (data_xon_thr < 0)
3000 data_xon_thr = 27648 >> 8; /* ~3*max MTU */
3001 if (data_xoff_thr < 0)
3002 data_xoff_thr = 54272 >> 8; /* ~80Kb - 3*max MTU */
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003003 EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_DESC_PUSH_EN, 0);
3004 EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_USR_BUF_SIZE,
3005 huge_buf_size);
3006 EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_MAC_TH, data_xon_thr);
3007 EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_MAC_TH, data_xoff_thr);
3008 EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_TX_TH, ctrl_xon_thr);
3009 EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_TX_TH, ctrl_xoff_thr);
3010 EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
Ben Hutchings56241ce2009-10-23 08:30:06 +00003011 }
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003012 efx_writeo(efx, &reg, FR_AZ_RX_CFG);
Ben Hutchings56241ce2009-10-23 08:30:06 +00003013}
3014
Ben Hutchings8ceee662008-04-27 12:55:59 +01003015/* This call performs hardware-specific global initialisation, such as
3016 * defining the descriptor cache sizes and number of RSS channels.
3017 * It does not set up any buffers, descriptor rings or event queues.
3018 */
3019int falcon_init_nic(struct efx_nic *efx)
3020{
Ben Hutchings8ceee662008-04-27 12:55:59 +01003021 efx_oword_t temp;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003022 int rc;
3023
Ben Hutchings8ceee662008-04-27 12:55:59 +01003024 /* Use on-chip SRAM */
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003025 efx_reado(efx, &temp, FR_AB_NIC_STAT);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003026 EFX_SET_OWORD_FIELD(temp, FRF_AB_ONCHIP_SRAM, 1);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003027 efx_writeo(efx, &temp, FR_AB_NIC_STAT);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003028
Ben Hutchings6f158d52008-12-12 22:00:49 -08003029 /* Set the source of the GMAC clock */
Ben Hutchingsdaeda632009-11-28 05:36:04 +00003030 if (efx_nic_rev(efx) == EFX_REV_FALCON_B0) {
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003031 efx_reado(efx, &temp, FR_AB_GPIO_CTL);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003032 EFX_SET_OWORD_FIELD(temp, FRF_AB_USE_NIC_CLK, true);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003033 efx_writeo(efx, &temp, FR_AB_GPIO_CTL);
Ben Hutchings6f158d52008-12-12 22:00:49 -08003034 }
3035
Steve Hodgson26deba52009-11-25 16:11:03 +00003036 /* Select the correct MAC */
3037 falcon_clock_mac(efx);
3038
Ben Hutchings8ceee662008-04-27 12:55:59 +01003039 rc = falcon_reset_sram(efx);
3040 if (rc)
3041 return rc;
3042
3043 /* Set positions of descriptor caches in SRAM. */
Ben Hutchings0228f5cdb02009-11-28 05:36:12 +00003044 EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_TX_DC_BASE_ADR,
3045 efx->type->tx_dc_base / 8);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003046 efx_writeo(efx, &temp, FR_AZ_SRM_TX_DC_CFG);
Ben Hutchings0228f5cdb02009-11-28 05:36:12 +00003047 EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_RX_DC_BASE_ADR,
3048 efx->type->rx_dc_base / 8);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003049 efx_writeo(efx, &temp, FR_AZ_SRM_RX_DC_CFG);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003050
3051 /* Set TX descriptor cache size. */
Ben Hutchings46e1ac02009-11-25 16:08:30 +00003052 BUILD_BUG_ON(TX_DC_ENTRIES != (8 << TX_DC_ENTRIES_ORDER));
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003053 EFX_POPULATE_OWORD_1(temp, FRF_AZ_TX_DC_SIZE, TX_DC_ENTRIES_ORDER);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003054 efx_writeo(efx, &temp, FR_AZ_TX_DC_CFG);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003055
3056 /* Set RX descriptor cache size. Set low watermark to size-8, as
3057 * this allows most efficient prefetching.
3058 */
Ben Hutchings46e1ac02009-11-25 16:08:30 +00003059 BUILD_BUG_ON(RX_DC_ENTRIES != (8 << RX_DC_ENTRIES_ORDER));
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003060 EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_SIZE, RX_DC_ENTRIES_ORDER);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003061 efx_writeo(efx, &temp, FR_AZ_RX_DC_CFG);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003062 EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_PF_LWM, RX_DC_ENTRIES - 8);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003063 efx_writeo(efx, &temp, FR_AZ_RX_DC_PF_WM);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003064
3065 /* Clear the parity enables on the TX data fifos as
3066 * they produce false parity errors because of timing issues
3067 */
3068 if (EFX_WORKAROUND_5129(efx)) {
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003069 efx_reado(efx, &temp, FR_AZ_CSR_SPARE);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003070 EFX_SET_OWORD_FIELD(temp, FRF_AB_MEM_PERR_EN_TX_DATA, 0);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003071 efx_writeo(efx, &temp, FR_AZ_CSR_SPARE);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003072 }
3073
3074 /* Enable all the genuinely fatal interrupts. (They are still
3075 * masked by the overall interrupt mask, controlled by
3076 * falcon_interrupts()).
3077 *
3078 * Note: All other fatal interrupts are enabled
3079 */
3080 EFX_POPULATE_OWORD_3(temp,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003081 FRF_AZ_ILL_ADR_INT_KER_EN, 1,
3082 FRF_AZ_RBUF_OWN_INT_KER_EN, 1,
3083 FRF_AZ_TBUF_OWN_INT_KER_EN, 1);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003084 EFX_INVERT_OWORD(temp);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003085 efx_writeo(efx, &temp, FR_AZ_FATAL_INTR_KER);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003086
Ben Hutchings8ceee662008-04-27 12:55:59 +01003087 if (EFX_WORKAROUND_7244(efx)) {
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003088 efx_reado(efx, &temp, FR_BZ_RX_FILTER_CTL);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003089 EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_FULL_SRCH_LIMIT, 8);
3090 EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_WILD_SRCH_LIMIT, 8);
3091 EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_FULL_SRCH_LIMIT, 8);
3092 EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_WILD_SRCH_LIMIT, 8);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003093 efx_writeo(efx, &temp, FR_BZ_RX_FILTER_CTL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003094 }
Ben Hutchings8ceee662008-04-27 12:55:59 +01003095
3096 falcon_setup_rss_indir_table(efx);
3097
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003098 /* XXX This is documented only for Falcon A0/A1 */
Ben Hutchings8ceee662008-04-27 12:55:59 +01003099 /* Setup RX. Wait for descriptor is broken and must
3100 * be disabled. RXDP recovery shouldn't be needed, but is.
3101 */
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003102 efx_reado(efx, &temp, FR_AA_RX_SELF_RST);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003103 EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_NODESC_WAIT_DIS, 1);
3104 EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_SELF_RST_EN, 1);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003105 if (EFX_WORKAROUND_5583(efx))
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003106 EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_ISCSI_DIS, 1);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003107 efx_writeo(efx, &temp, FR_AA_RX_SELF_RST);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003108
3109 /* Disable the ugly timer-based TX DMA backoff and allow TX DMA to be
3110 * controlled by the RX FIFO fill level. Set arbitration to one pkt/Q.
3111 */
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003112 efx_reado(efx, &temp, FR_AZ_TX_RESERVED);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003113 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER, 0xfe);
3114 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER_EN, 1);
3115 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_ONE_PKT_PER_Q, 1);
3116 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PUSH_EN, 0);
3117 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_DIS_NON_IP_EV, 1);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003118 /* Enable SW_EV to inherit in char driver - assume harmless here */
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003119 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_SOFT_EVT_EN, 1);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003120 /* Prefetch threshold 2 => fetch when descriptor cache half empty */
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003121 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_THRESHOLD, 2);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003122 /* Squash TX of packets of 16 bytes or less */
Ben Hutchingsdaeda632009-11-28 05:36:04 +00003123 if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003124 EFX_SET_OWORD_FIELD(temp, FRF_BZ_TX_FLUSH_MIN_LEN_EN, 1);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003125 efx_writeo(efx, &temp, FR_AZ_TX_RESERVED);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003126
3127 /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
3128 * descriptors (which is bad).
3129 */
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003130 efx_reado(efx, &temp, FR_AZ_TX_CFG);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003131 EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003132 efx_writeo(efx, &temp, FR_AZ_TX_CFG);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003133
Ben Hutchings56241ce2009-10-23 08:30:06 +00003134 falcon_init_rx_cfg(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003135
3136 /* Set destination of both TX and RX Flush events */
Ben Hutchingsdaeda632009-11-28 05:36:04 +00003137 if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003138 EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0);
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003139 efx_writeo(efx, &temp, FR_BZ_DP_CTRL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003140 }
3141
3142 return 0;
3143}
3144
3145void falcon_remove_nic(struct efx_nic *efx)
3146{
3147 struct falcon_nic_data *nic_data = efx->nic_data;
Ben Hutchingse775fb92009-11-23 16:06:02 +00003148 struct falcon_board *board = falcon_board(efx);
Ben Hutchings37b5a602008-05-30 22:27:04 +01003149 int rc;
3150
Ben Hutchings44838a42009-11-25 16:09:41 +00003151 board->type->fini(efx);
Ben Hutchings278c0622009-11-23 16:05:12 +00003152
Ben Hutchings8c870372009-03-04 09:53:02 +00003153 /* Remove I2C adapter and clear it in preparation for a retry */
Ben Hutchingse775fb92009-11-23 16:06:02 +00003154 rc = i2c_del_adapter(&board->i2c_adap);
Ben Hutchings37b5a602008-05-30 22:27:04 +01003155 BUG_ON(rc);
Ben Hutchingse775fb92009-11-23 16:06:02 +00003156 memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
Ben Hutchings8ceee662008-04-27 12:55:59 +01003157
Ben Hutchings4a5b5042008-09-01 12:47:16 +01003158 falcon_remove_spi_devices(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003159 falcon_free_buffer(efx, &efx->irq_status);
3160
Ben Hutchings91ad7572008-05-16 21:14:27 +01003161 falcon_reset_hw(efx, RESET_TYPE_ALL);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003162
3163 /* Release the second function after the reset */
3164 if (nic_data->pci_dev2) {
3165 pci_dev_put(nic_data->pci_dev2);
3166 nic_data->pci_dev2 = NULL;
3167 }
3168
3169 /* Tear down the private nic state */
3170 kfree(efx->nic_data);
3171 efx->nic_data = NULL;
3172}
3173
3174void falcon_update_nic_stats(struct efx_nic *efx)
3175{
Ben Hutchings55edc6e2009-11-25 16:11:35 +00003176 struct falcon_nic_data *nic_data = efx->nic_data;
Ben Hutchings8ceee662008-04-27 12:55:59 +01003177 efx_oword_t cnt;
3178
Ben Hutchings55edc6e2009-11-25 16:11:35 +00003179 if (nic_data->stats_disable_count)
3180 return;
3181
Ben Hutchings12d00ca2009-10-23 08:30:46 +00003182 efx_reado(efx, &cnt, FR_AZ_RX_NODESC_DROP);
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003183 efx->n_rx_nodesc_drop_cnt +=
3184 EFX_OWORD_FIELD(cnt, FRF_AB_RX_NODESC_DROP_CNT);
Ben Hutchings55edc6e2009-11-25 16:11:35 +00003185
3186 if (nic_data->stats_pending &&
3187 *nic_data->stats_dma_done == FALCON_STATS_DONE) {
3188 nic_data->stats_pending = false;
3189 rmb(); /* read the done flag before the stats */
3190 efx->mac_op->update_stats(efx);
3191 }
3192}
3193
3194void falcon_start_nic_stats(struct efx_nic *efx)
3195{
3196 struct falcon_nic_data *nic_data = efx->nic_data;
3197
3198 spin_lock_bh(&efx->stats_lock);
3199 if (--nic_data->stats_disable_count == 0)
3200 falcon_stats_request(efx);
3201 spin_unlock_bh(&efx->stats_lock);
3202}
3203
3204void falcon_stop_nic_stats(struct efx_nic *efx)
3205{
3206 struct falcon_nic_data *nic_data = efx->nic_data;
3207 int i;
3208
3209 might_sleep();
3210
3211 spin_lock_bh(&efx->stats_lock);
3212 ++nic_data->stats_disable_count;
3213 spin_unlock_bh(&efx->stats_lock);
3214
3215 del_timer_sync(&nic_data->stats_timer);
3216
3217 /* Wait enough time for the most recent transfer to
3218 * complete. */
3219 for (i = 0; i < 4 && nic_data->stats_pending; i++) {
3220 if (*nic_data->stats_dma_done == FALCON_STATS_DONE)
3221 break;
3222 msleep(1);
3223 }
3224
3225 spin_lock_bh(&efx->stats_lock);
3226 falcon_stats_complete(efx);
3227 spin_unlock_bh(&efx->stats_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +01003228}
3229
3230/**************************************************************************
3231 *
3232 * Revision-dependent attributes used by efx.c
3233 *
3234 **************************************************************************
3235 */
3236
Ben Hutchingsdaeda632009-11-28 05:36:04 +00003237struct efx_nic_type falcon_a1_nic_type = {
Steve Hodgsonb895d732009-11-28 05:35:00 +00003238 .default_mac_ops = &falcon_xmac_operations,
3239
Ben Hutchingsdaeda632009-11-28 05:36:04 +00003240 .revision = EFX_REV_FALCON_A1,
Ben Hutchings8ceee662008-04-27 12:55:59 +01003241 .mem_map_size = 0x20000,
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003242 .txd_ptr_tbl_base = FR_AA_TX_DESC_PTR_TBL_KER,
3243 .rxd_ptr_tbl_base = FR_AA_RX_DESC_PTR_TBL_KER,
3244 .buf_tbl_base = FR_AA_BUF_FULL_TBL_KER,
3245 .evq_ptr_tbl_base = FR_AA_EVQ_PTR_TBL_KER,
3246 .evq_rptr_tbl_base = FR_AA_EVQ_RPTR_KER,
Ben Hutchings6d51d302009-10-23 08:31:07 +00003247 .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
Ben Hutchings8ceee662008-04-27 12:55:59 +01003248 .rx_buffer_padding = 0x24,
3249 .max_interrupt_mode = EFX_INT_MODE_MSI,
3250 .phys_addr_channels = 4,
Ben Hutchings0228f5cdb02009-11-28 05:36:12 +00003251 .tx_dc_base = 0x130000,
3252 .rx_dc_base = 0x100000,
Ben Hutchings8ceee662008-04-27 12:55:59 +01003253};
3254
Ben Hutchingsdaeda632009-11-28 05:36:04 +00003255struct efx_nic_type falcon_b0_nic_type = {
Steve Hodgsonb895d732009-11-28 05:35:00 +00003256 .default_mac_ops = &falcon_xmac_operations,
3257
Ben Hutchingsdaeda632009-11-28 05:36:04 +00003258 .revision = EFX_REV_FALCON_B0,
Ben Hutchings8ceee662008-04-27 12:55:59 +01003259 /* Map everything up to and including the RSS indirection
3260 * table. Don't map MSI-X table, MSI-X PBA since Linux
3261 * requires that they not be mapped. */
Ben Hutchings3e6c4532009-10-23 08:30:36 +00003262 .mem_map_size = (FR_BZ_RX_INDIRECTION_TBL +
3263 FR_BZ_RX_INDIRECTION_TBL_STEP *
3264 FR_BZ_RX_INDIRECTION_TBL_ROWS),
3265 .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL,
3266 .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL,
3267 .buf_tbl_base = FR_BZ_BUF_FULL_TBL,
3268 .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL,
3269 .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR,
Ben Hutchings6d51d302009-10-23 08:31:07 +00003270 .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
Ben Hutchings8ceee662008-04-27 12:55:59 +01003271 .rx_buffer_padding = 0,
3272 .max_interrupt_mode = EFX_INT_MODE_MSIX,
3273 .phys_addr_channels = 32, /* Hardware limit is 64, but the legacy
3274 * interrupt handler only supports 32
3275 * channels */
Ben Hutchings0228f5cdb02009-11-28 05:36:12 +00003276 .tx_dc_base = 0x130000,
3277 .rx_dc_base = 0x100000,
Ben Hutchings8ceee662008-04-27 12:55:59 +01003278};
3279