Commit | Line | Data |
---|---|---|
8e730c15 BH |
1 | /**************************************************************************** |
2 | * Driver for Solarflare Solarstorm network controllers and boards | |
3 | * Copyright 2005-2006 Fen Systems Ltd. | |
906bb26c | 4 | * Copyright 2006-2009 Solarflare Communications Inc. |
8e730c15 BH |
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> | |
16 | #include "net_driver.h" | |
17 | #include "bitfield.h" | |
18 | #include "efx.h" | |
19 | #include "nic.h" | |
20 | #include "regs.h" | |
21 | #include "io.h" | |
22 | #include "workarounds.h" | |
23 | ||
24 | /************************************************************************** | |
25 | * | |
26 | * Configurable values | |
27 | * | |
28 | ************************************************************************** | |
29 | */ | |
30 | ||
31 | /* This is set to 16 for a good reason. In summary, if larger than | |
32 | * 16, the descriptor cache holds more than a default socket | |
33 | * buffer's worth of packets (for UDP we can only have at most one | |
34 | * socket buffer's worth outstanding). This combined with the fact | |
35 | * that we only get 1 TX event per descriptor cache means the NIC | |
36 | * goes idle. | |
37 | */ | |
38 | #define TX_DC_ENTRIES 16 | |
39 | #define TX_DC_ENTRIES_ORDER 1 | |
40 | ||
41 | #define RX_DC_ENTRIES 64 | |
42 | #define RX_DC_ENTRIES_ORDER 3 | |
43 | ||
44 | /* RX FIFO XOFF watermark | |
45 | * | |
46 | * When the amount of the RX FIFO increases used increases past this | |
47 | * watermark send XOFF. Only used if RX flow control is enabled (ethtool -A) | |
48 | * This also has an effect on RX/TX arbitration | |
49 | */ | |
50 | int efx_nic_rx_xoff_thresh = -1; | |
51 | module_param_named(rx_xoff_thresh_bytes, efx_nic_rx_xoff_thresh, int, 0644); | |
52 | MODULE_PARM_DESC(rx_xoff_thresh_bytes, "RX fifo XOFF threshold"); | |
53 | ||
54 | /* RX FIFO XON watermark | |
55 | * | |
56 | * When the amount of the RX FIFO used decreases below this | |
57 | * watermark send XON. Only used if TX flow control is enabled (ethtool -A) | |
58 | * This also has an effect on RX/TX arbitration | |
59 | */ | |
60 | int efx_nic_rx_xon_thresh = -1; | |
61 | module_param_named(rx_xon_thresh_bytes, efx_nic_rx_xon_thresh, int, 0644); | |
62 | MODULE_PARM_DESC(rx_xon_thresh_bytes, "RX fifo XON threshold"); | |
63 | ||
64 | /* If EFX_MAX_INT_ERRORS internal errors occur within | |
65 | * EFX_INT_ERROR_EXPIRE seconds, we consider the NIC broken and | |
66 | * disable it. | |
67 | */ | |
68 | #define EFX_INT_ERROR_EXPIRE 3600 | |
69 | #define EFX_MAX_INT_ERRORS 5 | |
70 | ||
71 | /* We poll for events every FLUSH_INTERVAL ms, and check FLUSH_POLL_COUNT times | |
72 | */ | |
73 | #define EFX_FLUSH_INTERVAL 10 | |
74 | #define EFX_FLUSH_POLL_COUNT 100 | |
75 | ||
76 | /* Size and alignment of special buffers (4KB) */ | |
77 | #define EFX_BUF_SIZE 4096 | |
78 | ||
79 | /* Depth of RX flush request fifo */ | |
80 | #define EFX_RX_FLUSH_COUNT 4 | |
81 | ||
90d683af SH |
82 | /* Generated event code for efx_generate_test_event() */ |
83 | #define EFX_CHANNEL_MAGIC_TEST(_channel) \ | |
d730dc52 SH |
84 | (0x00010100 + (_channel)->channel) |
85 | ||
90d683af SH |
86 | /* Generated event code for efx_generate_fill_event() */ |
87 | #define EFX_CHANNEL_MAGIC_FILL(_channel) \ | |
88 | (0x00010200 + (_channel)->channel) | |
89 | ||
8e730c15 BH |
90 | /************************************************************************** |
91 | * | |
92 | * Solarstorm hardware access | |
93 | * | |
94 | **************************************************************************/ | |
95 | ||
96 | static inline void efx_write_buf_tbl(struct efx_nic *efx, efx_qword_t *value, | |
97 | unsigned int index) | |
98 | { | |
99 | efx_sram_writeq(efx, efx->membase + efx->type->buf_tbl_base, | |
100 | value, index); | |
101 | } | |
102 | ||
103 | /* Read the current event from the event queue */ | |
104 | static inline efx_qword_t *efx_event(struct efx_channel *channel, | |
105 | unsigned int index) | |
106 | { | |
807540ba | 107 | return ((efx_qword_t *) (channel->eventq.addr)) + index; |
8e730c15 BH |
108 | } |
109 | ||
110 | /* See if an event is present | |
111 | * | |
112 | * We check both the high and low dword of the event for all ones. We | |
113 | * wrote all ones when we cleared the event, and no valid event can | |
114 | * have all ones in either its high or low dwords. This approach is | |
115 | * robust against reordering. | |
116 | * | |
117 | * Note that using a single 64-bit comparison is incorrect; even | |
118 | * though the CPU read will be atomic, the DMA write may not be. | |
119 | */ | |
120 | static inline int efx_event_present(efx_qword_t *event) | |
121 | { | |
807540ba ED |
122 | return !(EFX_DWORD_IS_ALL_ONES(event->dword[0]) | |
123 | EFX_DWORD_IS_ALL_ONES(event->dword[1])); | |
8e730c15 BH |
124 | } |
125 | ||
126 | static bool efx_masked_compare_oword(const efx_oword_t *a, const efx_oword_t *b, | |
127 | const efx_oword_t *mask) | |
128 | { | |
129 | return ((a->u64[0] ^ b->u64[0]) & mask->u64[0]) || | |
130 | ((a->u64[1] ^ b->u64[1]) & mask->u64[1]); | |
131 | } | |
132 | ||
133 | int efx_nic_test_registers(struct efx_nic *efx, | |
134 | const struct efx_nic_register_test *regs, | |
135 | size_t n_regs) | |
136 | { | |
137 | unsigned address = 0, i, j; | |
138 | efx_oword_t mask, imask, original, reg, buf; | |
139 | ||
140 | /* Falcon should be in loopback to isolate the XMAC from the PHY */ | |
141 | WARN_ON(!LOOPBACK_INTERNAL(efx)); | |
142 | ||
143 | for (i = 0; i < n_regs; ++i) { | |
144 | address = regs[i].address; | |
145 | mask = imask = regs[i].mask; | |
146 | EFX_INVERT_OWORD(imask); | |
147 | ||
148 | efx_reado(efx, &original, address); | |
149 | ||
150 | /* bit sweep on and off */ | |
151 | for (j = 0; j < 128; j++) { | |
152 | if (!EFX_EXTRACT_OWORD32(mask, j, j)) | |
153 | continue; | |
154 | ||
155 | /* Test this testable bit can be set in isolation */ | |
156 | EFX_AND_OWORD(reg, original, mask); | |
157 | EFX_SET_OWORD32(reg, j, j, 1); | |
158 | ||
159 | efx_writeo(efx, ®, address); | |
160 | efx_reado(efx, &buf, address); | |
161 | ||
162 | if (efx_masked_compare_oword(®, &buf, &mask)) | |
163 | goto fail; | |
164 | ||
165 | /* Test this testable bit can be cleared in isolation */ | |
166 | EFX_OR_OWORD(reg, original, mask); | |
167 | EFX_SET_OWORD32(reg, j, j, 0); | |
168 | ||
169 | efx_writeo(efx, ®, address); | |
170 | efx_reado(efx, &buf, address); | |
171 | ||
172 | if (efx_masked_compare_oword(®, &buf, &mask)) | |
173 | goto fail; | |
174 | } | |
175 | ||
176 | efx_writeo(efx, &original, address); | |
177 | } | |
178 | ||
179 | return 0; | |
180 | ||
181 | fail: | |
62776d03 BH |
182 | netif_err(efx, hw, efx->net_dev, |
183 | "wrote "EFX_OWORD_FMT" read "EFX_OWORD_FMT | |
184 | " at address 0x%x mask "EFX_OWORD_FMT"\n", EFX_OWORD_VAL(reg), | |
185 | EFX_OWORD_VAL(buf), address, EFX_OWORD_VAL(mask)); | |
8e730c15 BH |
186 | return -EIO; |
187 | } | |
188 | ||
189 | /************************************************************************** | |
190 | * | |
191 | * Special buffer handling | |
192 | * Special buffers are used for event queues and the TX and RX | |
193 | * descriptor rings. | |
194 | * | |
195 | *************************************************************************/ | |
196 | ||
197 | /* | |
198 | * Initialise a special buffer | |
199 | * | |
200 | * This will define a buffer (previously allocated via | |
201 | * efx_alloc_special_buffer()) in the buffer table, allowing | |
202 | * it to be used for event queues, descriptor rings etc. | |
203 | */ | |
204 | static void | |
205 | efx_init_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer) | |
206 | { | |
207 | efx_qword_t buf_desc; | |
208 | int index; | |
209 | dma_addr_t dma_addr; | |
210 | int i; | |
211 | ||
212 | EFX_BUG_ON_PARANOID(!buffer->addr); | |
213 | ||
214 | /* Write buffer descriptors to NIC */ | |
215 | for (i = 0; i < buffer->entries; i++) { | |
216 | index = buffer->index + i; | |
217 | dma_addr = buffer->dma_addr + (i * 4096); | |
62776d03 BH |
218 | netif_dbg(efx, probe, efx->net_dev, |
219 | "mapping special buffer %d at %llx\n", | |
220 | index, (unsigned long long)dma_addr); | |
8e730c15 BH |
221 | EFX_POPULATE_QWORD_3(buf_desc, |
222 | FRF_AZ_BUF_ADR_REGION, 0, | |
223 | FRF_AZ_BUF_ADR_FBUF, dma_addr >> 12, | |
224 | FRF_AZ_BUF_OWNER_ID_FBUF, 0); | |
225 | efx_write_buf_tbl(efx, &buf_desc, index); | |
226 | } | |
227 | } | |
228 | ||
229 | /* Unmaps a buffer and clears the buffer table entries */ | |
230 | static void | |
231 | efx_fini_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer) | |
232 | { | |
233 | efx_oword_t buf_tbl_upd; | |
234 | unsigned int start = buffer->index; | |
235 | unsigned int end = (buffer->index + buffer->entries - 1); | |
236 | ||
237 | if (!buffer->entries) | |
238 | return; | |
239 | ||
62776d03 BH |
240 | netif_dbg(efx, hw, efx->net_dev, "unmapping special buffers %d-%d\n", |
241 | buffer->index, buffer->index + buffer->entries - 1); | |
8e730c15 BH |
242 | |
243 | EFX_POPULATE_OWORD_4(buf_tbl_upd, | |
244 | FRF_AZ_BUF_UPD_CMD, 0, | |
245 | FRF_AZ_BUF_CLR_CMD, 1, | |
246 | FRF_AZ_BUF_CLR_END_ID, end, | |
247 | FRF_AZ_BUF_CLR_START_ID, start); | |
248 | efx_writeo(efx, &buf_tbl_upd, FR_AZ_BUF_TBL_UPD); | |
249 | } | |
250 | ||
251 | /* | |
252 | * Allocate a new special buffer | |
253 | * | |
254 | * This allocates memory for a new buffer, clears it and allocates a | |
255 | * new buffer ID range. It does not write into the buffer table. | |
256 | * | |
257 | * This call will allocate 4KB buffers, since 8KB buffers can't be | |
258 | * used for event queues and descriptor rings. | |
259 | */ | |
260 | static int efx_alloc_special_buffer(struct efx_nic *efx, | |
261 | struct efx_special_buffer *buffer, | |
262 | unsigned int len) | |
263 | { | |
264 | len = ALIGN(len, EFX_BUF_SIZE); | |
265 | ||
58758aa5 BH |
266 | buffer->addr = dma_alloc_coherent(&efx->pci_dev->dev, len, |
267 | &buffer->dma_addr, GFP_KERNEL); | |
8e730c15 BH |
268 | if (!buffer->addr) |
269 | return -ENOMEM; | |
270 | buffer->len = len; | |
271 | buffer->entries = len / EFX_BUF_SIZE; | |
272 | BUG_ON(buffer->dma_addr & (EFX_BUF_SIZE - 1)); | |
273 | ||
274 | /* All zeros is a potentially valid event so memset to 0xff */ | |
275 | memset(buffer->addr, 0xff, len); | |
276 | ||
277 | /* Select new buffer ID */ | |
278 | buffer->index = efx->next_buffer_table; | |
279 | efx->next_buffer_table += buffer->entries; | |
280 | ||
62776d03 BH |
281 | netif_dbg(efx, probe, efx->net_dev, |
282 | "allocating special buffers %d-%d at %llx+%x " | |
283 | "(virt %p phys %llx)\n", buffer->index, | |
284 | buffer->index + buffer->entries - 1, | |
285 | (u64)buffer->dma_addr, len, | |
286 | buffer->addr, (u64)virt_to_phys(buffer->addr)); | |
8e730c15 BH |
287 | |
288 | return 0; | |
289 | } | |
290 | ||
291 | static void | |
292 | efx_free_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer) | |
293 | { | |
294 | if (!buffer->addr) | |
295 | return; | |
296 | ||
62776d03 BH |
297 | netif_dbg(efx, hw, efx->net_dev, |
298 | "deallocating special buffers %d-%d at %llx+%x " | |
299 | "(virt %p phys %llx)\n", buffer->index, | |
300 | buffer->index + buffer->entries - 1, | |
301 | (u64)buffer->dma_addr, buffer->len, | |
302 | buffer->addr, (u64)virt_to_phys(buffer->addr)); | |
8e730c15 | 303 | |
58758aa5 BH |
304 | dma_free_coherent(&efx->pci_dev->dev, buffer->len, buffer->addr, |
305 | buffer->dma_addr); | |
8e730c15 BH |
306 | buffer->addr = NULL; |
307 | buffer->entries = 0; | |
308 | } | |
309 | ||
310 | /************************************************************************** | |
311 | * | |
312 | * Generic buffer handling | |
313 | * These buffers are used for interrupt status and MAC stats | |
314 | * | |
315 | **************************************************************************/ | |
316 | ||
317 | int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer, | |
318 | unsigned int len) | |
319 | { | |
320 | buffer->addr = pci_alloc_consistent(efx->pci_dev, len, | |
321 | &buffer->dma_addr); | |
322 | if (!buffer->addr) | |
323 | return -ENOMEM; | |
324 | buffer->len = len; | |
325 | memset(buffer->addr, 0, len); | |
326 | return 0; | |
327 | } | |
328 | ||
329 | void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer) | |
330 | { | |
331 | if (buffer->addr) { | |
332 | pci_free_consistent(efx->pci_dev, buffer->len, | |
333 | buffer->addr, buffer->dma_addr); | |
334 | buffer->addr = NULL; | |
335 | } | |
336 | } | |
337 | ||
338 | /************************************************************************** | |
339 | * | |
340 | * TX path | |
341 | * | |
342 | **************************************************************************/ | |
343 | ||
344 | /* Returns a pointer to the specified transmit descriptor in the TX | |
345 | * descriptor queue belonging to the specified channel. | |
346 | */ | |
347 | static inline efx_qword_t * | |
348 | efx_tx_desc(struct efx_tx_queue *tx_queue, unsigned int index) | |
349 | { | |
807540ba | 350 | return ((efx_qword_t *) (tx_queue->txd.addr)) + index; |
8e730c15 BH |
351 | } |
352 | ||
353 | /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */ | |
354 | static inline void efx_notify_tx_desc(struct efx_tx_queue *tx_queue) | |
355 | { | |
356 | unsigned write_ptr; | |
357 | efx_dword_t reg; | |
358 | ||
ecc910f5 | 359 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; |
8e730c15 BH |
360 | EFX_POPULATE_DWORD_1(reg, FRF_AZ_TX_DESC_WPTR_DWORD, write_ptr); |
361 | efx_writed_page(tx_queue->efx, ®, | |
362 | FR_AZ_TX_DESC_UPD_DWORD_P0, tx_queue->queue); | |
363 | } | |
364 | ||
365 | ||
366 | /* For each entry inserted into the software descriptor ring, create a | |
367 | * descriptor in the hardware TX descriptor ring (in host memory), and | |
368 | * write a doorbell. | |
369 | */ | |
370 | void efx_nic_push_buffers(struct efx_tx_queue *tx_queue) | |
371 | { | |
372 | ||
373 | struct efx_tx_buffer *buffer; | |
374 | efx_qword_t *txd; | |
375 | unsigned write_ptr; | |
376 | ||
377 | BUG_ON(tx_queue->write_count == tx_queue->insert_count); | |
378 | ||
379 | do { | |
ecc910f5 | 380 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; |
8e730c15 BH |
381 | buffer = &tx_queue->buffer[write_ptr]; |
382 | txd = efx_tx_desc(tx_queue, write_ptr); | |
383 | ++tx_queue->write_count; | |
384 | ||
385 | /* Create TX descriptor ring entry */ | |
386 | EFX_POPULATE_QWORD_4(*txd, | |
387 | FSF_AZ_TX_KER_CONT, buffer->continuation, | |
388 | FSF_AZ_TX_KER_BYTE_COUNT, buffer->len, | |
389 | FSF_AZ_TX_KER_BUF_REGION, 0, | |
390 | FSF_AZ_TX_KER_BUF_ADDR, buffer->dma_addr); | |
391 | } while (tx_queue->write_count != tx_queue->insert_count); | |
392 | ||
393 | wmb(); /* Ensure descriptors are written before they are fetched */ | |
394 | efx_notify_tx_desc(tx_queue); | |
395 | } | |
396 | ||
397 | /* Allocate hardware resources for a TX queue */ | |
398 | int efx_nic_probe_tx(struct efx_tx_queue *tx_queue) | |
399 | { | |
400 | struct efx_nic *efx = tx_queue->efx; | |
ecc910f5 SH |
401 | unsigned entries; |
402 | ||
403 | entries = tx_queue->ptr_mask + 1; | |
8e730c15 | 404 | return efx_alloc_special_buffer(efx, &tx_queue->txd, |
ecc910f5 | 405 | entries * sizeof(efx_qword_t)); |
8e730c15 BH |
406 | } |
407 | ||
408 | void efx_nic_init_tx(struct efx_tx_queue *tx_queue) | |
409 | { | |
410 | efx_oword_t tx_desc_ptr; | |
411 | struct efx_nic *efx = tx_queue->efx; | |
412 | ||
413 | tx_queue->flushed = FLUSH_NONE; | |
414 | ||
415 | /* Pin TX descriptor ring */ | |
416 | efx_init_special_buffer(efx, &tx_queue->txd); | |
417 | ||
418 | /* Push TX descriptor ring to card */ | |
419 | EFX_POPULATE_OWORD_10(tx_desc_ptr, | |
420 | FRF_AZ_TX_DESCQ_EN, 1, | |
421 | FRF_AZ_TX_ISCSI_DDIG_EN, 0, | |
422 | FRF_AZ_TX_ISCSI_HDIG_EN, 0, | |
423 | FRF_AZ_TX_DESCQ_BUF_BASE_ID, tx_queue->txd.index, | |
424 | FRF_AZ_TX_DESCQ_EVQ_ID, | |
425 | tx_queue->channel->channel, | |
426 | FRF_AZ_TX_DESCQ_OWNER_ID, 0, | |
427 | FRF_AZ_TX_DESCQ_LABEL, tx_queue->queue, | |
428 | FRF_AZ_TX_DESCQ_SIZE, | |
429 | __ffs(tx_queue->txd.entries), | |
430 | FRF_AZ_TX_DESCQ_TYPE, 0, | |
431 | FRF_BZ_TX_NON_IP_DROP_DIS, 1); | |
432 | ||
433 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) { | |
a4900ac9 | 434 | int csum = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD; |
8e730c15 BH |
435 | EFX_SET_OWORD_FIELD(tx_desc_ptr, FRF_BZ_TX_IP_CHKSM_DIS, !csum); |
436 | EFX_SET_OWORD_FIELD(tx_desc_ptr, FRF_BZ_TX_TCP_CHKSM_DIS, | |
437 | !csum); | |
438 | } | |
439 | ||
440 | efx_writeo_table(efx, &tx_desc_ptr, efx->type->txd_ptr_tbl_base, | |
441 | tx_queue->queue); | |
442 | ||
443 | if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) { | |
444 | efx_oword_t reg; | |
445 | ||
446 | /* Only 128 bits in this register */ | |
a4900ac9 | 447 | BUILD_BUG_ON(EFX_MAX_TX_QUEUES > 128); |
8e730c15 BH |
448 | |
449 | efx_reado(efx, ®, FR_AA_TX_CHKSM_CFG); | |
a4900ac9 | 450 | if (tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD) |
8e730c15 BH |
451 | clear_bit_le(tx_queue->queue, (void *)®); |
452 | else | |
453 | set_bit_le(tx_queue->queue, (void *)®); | |
454 | efx_writeo(efx, ®, FR_AA_TX_CHKSM_CFG); | |
455 | } | |
456 | } | |
457 | ||
458 | static void efx_flush_tx_queue(struct efx_tx_queue *tx_queue) | |
459 | { | |
460 | struct efx_nic *efx = tx_queue->efx; | |
461 | efx_oword_t tx_flush_descq; | |
462 | ||
463 | tx_queue->flushed = FLUSH_PENDING; | |
464 | ||
465 | /* Post a flush command */ | |
466 | EFX_POPULATE_OWORD_2(tx_flush_descq, | |
467 | FRF_AZ_TX_FLUSH_DESCQ_CMD, 1, | |
468 | FRF_AZ_TX_FLUSH_DESCQ, tx_queue->queue); | |
469 | efx_writeo(efx, &tx_flush_descq, FR_AZ_TX_FLUSH_DESCQ); | |
470 | } | |
471 | ||
472 | void efx_nic_fini_tx(struct efx_tx_queue *tx_queue) | |
473 | { | |
474 | struct efx_nic *efx = tx_queue->efx; | |
475 | efx_oword_t tx_desc_ptr; | |
476 | ||
477 | /* The queue should have been flushed */ | |
478 | WARN_ON(tx_queue->flushed != FLUSH_DONE); | |
479 | ||
480 | /* Remove TX descriptor ring from card */ | |
481 | EFX_ZERO_OWORD(tx_desc_ptr); | |
482 | efx_writeo_table(efx, &tx_desc_ptr, efx->type->txd_ptr_tbl_base, | |
483 | tx_queue->queue); | |
484 | ||
485 | /* Unpin TX descriptor ring */ | |
486 | efx_fini_special_buffer(efx, &tx_queue->txd); | |
487 | } | |
488 | ||
489 | /* Free buffers backing TX queue */ | |
490 | void efx_nic_remove_tx(struct efx_tx_queue *tx_queue) | |
491 | { | |
492 | efx_free_special_buffer(tx_queue->efx, &tx_queue->txd); | |
493 | } | |
494 | ||
495 | /************************************************************************** | |
496 | * | |
497 | * RX path | |
498 | * | |
499 | **************************************************************************/ | |
500 | ||
501 | /* Returns a pointer to the specified descriptor in the RX descriptor queue */ | |
502 | static inline efx_qword_t * | |
503 | efx_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index) | |
504 | { | |
807540ba | 505 | return ((efx_qword_t *) (rx_queue->rxd.addr)) + index; |
8e730c15 BH |
506 | } |
507 | ||
508 | /* This creates an entry in the RX descriptor queue */ | |
509 | static inline void | |
510 | efx_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned index) | |
511 | { | |
512 | struct efx_rx_buffer *rx_buf; | |
513 | efx_qword_t *rxd; | |
514 | ||
515 | rxd = efx_rx_desc(rx_queue, index); | |
516 | rx_buf = efx_rx_buffer(rx_queue, index); | |
517 | EFX_POPULATE_QWORD_3(*rxd, | |
518 | FSF_AZ_RX_KER_BUF_SIZE, | |
519 | rx_buf->len - | |
520 | rx_queue->efx->type->rx_buffer_padding, | |
521 | FSF_AZ_RX_KER_BUF_REGION, 0, | |
522 | FSF_AZ_RX_KER_BUF_ADDR, rx_buf->dma_addr); | |
523 | } | |
524 | ||
525 | /* This writes to the RX_DESC_WPTR register for the specified receive | |
526 | * descriptor ring. | |
527 | */ | |
528 | void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue) | |
529 | { | |
ecc910f5 | 530 | struct efx_nic *efx = rx_queue->efx; |
8e730c15 BH |
531 | efx_dword_t reg; |
532 | unsigned write_ptr; | |
533 | ||
534 | while (rx_queue->notified_count != rx_queue->added_count) { | |
ecc910f5 SH |
535 | efx_build_rx_desc( |
536 | rx_queue, | |
537 | rx_queue->notified_count & rx_queue->ptr_mask); | |
8e730c15 BH |
538 | ++rx_queue->notified_count; |
539 | } | |
540 | ||
541 | wmb(); | |
ecc910f5 | 542 | write_ptr = rx_queue->added_count & rx_queue->ptr_mask; |
8e730c15 | 543 | EFX_POPULATE_DWORD_1(reg, FRF_AZ_RX_DESC_WPTR_DWORD, write_ptr); |
ecc910f5 | 544 | efx_writed_page(efx, ®, FR_AZ_RX_DESC_UPD_DWORD_P0, |
ba1e8a35 | 545 | efx_rx_queue_index(rx_queue)); |
8e730c15 BH |
546 | } |
547 | ||
548 | int efx_nic_probe_rx(struct efx_rx_queue *rx_queue) | |
549 | { | |
550 | struct efx_nic *efx = rx_queue->efx; | |
ecc910f5 SH |
551 | unsigned entries; |
552 | ||
553 | entries = rx_queue->ptr_mask + 1; | |
8e730c15 | 554 | return efx_alloc_special_buffer(efx, &rx_queue->rxd, |
ecc910f5 | 555 | entries * sizeof(efx_qword_t)); |
8e730c15 BH |
556 | } |
557 | ||
558 | void efx_nic_init_rx(struct efx_rx_queue *rx_queue) | |
559 | { | |
560 | efx_oword_t rx_desc_ptr; | |
561 | struct efx_nic *efx = rx_queue->efx; | |
562 | bool is_b0 = efx_nic_rev(efx) >= EFX_REV_FALCON_B0; | |
563 | bool iscsi_digest_en = is_b0; | |
564 | ||
62776d03 BH |
565 | netif_dbg(efx, hw, efx->net_dev, |
566 | "RX queue %d ring in special buffers %d-%d\n", | |
ba1e8a35 | 567 | efx_rx_queue_index(rx_queue), rx_queue->rxd.index, |
62776d03 | 568 | rx_queue->rxd.index + rx_queue->rxd.entries - 1); |
8e730c15 BH |
569 | |
570 | rx_queue->flushed = FLUSH_NONE; | |
571 | ||
572 | /* Pin RX descriptor ring */ | |
573 | efx_init_special_buffer(efx, &rx_queue->rxd); | |
574 | ||
575 | /* Push RX descriptor ring to card */ | |
576 | EFX_POPULATE_OWORD_10(rx_desc_ptr, | |
577 | FRF_AZ_RX_ISCSI_DDIG_EN, iscsi_digest_en, | |
578 | FRF_AZ_RX_ISCSI_HDIG_EN, iscsi_digest_en, | |
579 | FRF_AZ_RX_DESCQ_BUF_BASE_ID, rx_queue->rxd.index, | |
580 | FRF_AZ_RX_DESCQ_EVQ_ID, | |
ba1e8a35 | 581 | efx_rx_queue_channel(rx_queue)->channel, |
8e730c15 | 582 | FRF_AZ_RX_DESCQ_OWNER_ID, 0, |
ba1e8a35 BH |
583 | FRF_AZ_RX_DESCQ_LABEL, |
584 | efx_rx_queue_index(rx_queue), | |
8e730c15 BH |
585 | FRF_AZ_RX_DESCQ_SIZE, |
586 | __ffs(rx_queue->rxd.entries), | |
587 | FRF_AZ_RX_DESCQ_TYPE, 0 /* kernel queue */ , | |
588 | /* For >=B0 this is scatter so disable */ | |
589 | FRF_AZ_RX_DESCQ_JUMBO, !is_b0, | |
590 | FRF_AZ_RX_DESCQ_EN, 1); | |
591 | efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base, | |
ba1e8a35 | 592 | efx_rx_queue_index(rx_queue)); |
8e730c15 BH |
593 | } |
594 | ||
595 | static void efx_flush_rx_queue(struct efx_rx_queue *rx_queue) | |
596 | { | |
597 | struct efx_nic *efx = rx_queue->efx; | |
598 | efx_oword_t rx_flush_descq; | |
599 | ||
600 | rx_queue->flushed = FLUSH_PENDING; | |
601 | ||
602 | /* Post a flush command */ | |
603 | EFX_POPULATE_OWORD_2(rx_flush_descq, | |
604 | FRF_AZ_RX_FLUSH_DESCQ_CMD, 1, | |
ba1e8a35 BH |
605 | FRF_AZ_RX_FLUSH_DESCQ, |
606 | efx_rx_queue_index(rx_queue)); | |
8e730c15 BH |
607 | efx_writeo(efx, &rx_flush_descq, FR_AZ_RX_FLUSH_DESCQ); |
608 | } | |
609 | ||
610 | void efx_nic_fini_rx(struct efx_rx_queue *rx_queue) | |
611 | { | |
612 | efx_oword_t rx_desc_ptr; | |
613 | struct efx_nic *efx = rx_queue->efx; | |
614 | ||
615 | /* The queue should already have been flushed */ | |
616 | WARN_ON(rx_queue->flushed != FLUSH_DONE); | |
617 | ||
618 | /* Remove RX descriptor ring from card */ | |
619 | EFX_ZERO_OWORD(rx_desc_ptr); | |
620 | efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base, | |
ba1e8a35 | 621 | efx_rx_queue_index(rx_queue)); |
8e730c15 BH |
622 | |
623 | /* Unpin RX descriptor ring */ | |
624 | efx_fini_special_buffer(efx, &rx_queue->rxd); | |
625 | } | |
626 | ||
627 | /* Free buffers backing RX queue */ | |
628 | void efx_nic_remove_rx(struct efx_rx_queue *rx_queue) | |
629 | { | |
630 | efx_free_special_buffer(rx_queue->efx, &rx_queue->rxd); | |
631 | } | |
632 | ||
633 | /************************************************************************** | |
634 | * | |
635 | * Event queue processing | |
636 | * Event queues are processed by per-channel tasklets. | |
637 | * | |
638 | **************************************************************************/ | |
639 | ||
640 | /* Update a channel's event queue's read pointer (RPTR) register | |
641 | * | |
642 | * This writes the EVQ_RPTR_REG register for the specified channel's | |
643 | * event queue. | |
8e730c15 BH |
644 | */ |
645 | void efx_nic_eventq_read_ack(struct efx_channel *channel) | |
646 | { | |
647 | efx_dword_t reg; | |
648 | struct efx_nic *efx = channel->efx; | |
649 | ||
650 | EFX_POPULATE_DWORD_1(reg, FRF_AZ_EVQ_RPTR, channel->eventq_read_ptr); | |
651 | efx_writed_table(efx, ®, efx->type->evq_rptr_tbl_base, | |
652 | channel->channel); | |
653 | } | |
654 | ||
655 | /* Use HW to insert a SW defined event */ | |
d215697f | 656 | static void efx_generate_event(struct efx_channel *channel, efx_qword_t *event) |
8e730c15 BH |
657 | { |
658 | efx_oword_t drv_ev_reg; | |
659 | ||
660 | BUILD_BUG_ON(FRF_AZ_DRV_EV_DATA_LBN != 0 || | |
661 | FRF_AZ_DRV_EV_DATA_WIDTH != 64); | |
662 | drv_ev_reg.u32[0] = event->u32[0]; | |
663 | drv_ev_reg.u32[1] = event->u32[1]; | |
664 | drv_ev_reg.u32[2] = 0; | |
665 | drv_ev_reg.u32[3] = 0; | |
666 | EFX_SET_OWORD_FIELD(drv_ev_reg, FRF_AZ_DRV_EV_QID, channel->channel); | |
667 | efx_writeo(channel->efx, &drv_ev_reg, FR_AZ_DRV_EV); | |
668 | } | |
669 | ||
670 | /* Handle a transmit completion event | |
671 | * | |
672 | * The NIC batches TX completion events; the message we receive is of | |
673 | * the form "complete all TX events up to this index". | |
674 | */ | |
fa236e18 | 675 | static int |
8e730c15 BH |
676 | efx_handle_tx_event(struct efx_channel *channel, efx_qword_t *event) |
677 | { | |
678 | unsigned int tx_ev_desc_ptr; | |
679 | unsigned int tx_ev_q_label; | |
680 | struct efx_tx_queue *tx_queue; | |
681 | struct efx_nic *efx = channel->efx; | |
fa236e18 | 682 | int tx_packets = 0; |
8e730c15 BH |
683 | |
684 | if (likely(EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_COMP))) { | |
685 | /* Transmit completion */ | |
686 | tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_DESC_PTR); | |
687 | tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL); | |
f7d12cdc BH |
688 | tx_queue = efx_channel_get_tx_queue( |
689 | channel, tx_ev_q_label % EFX_TXQ_TYPES); | |
fa236e18 | 690 | tx_packets = ((tx_ev_desc_ptr - tx_queue->read_count) & |
ecc910f5 | 691 | tx_queue->ptr_mask); |
fa236e18 | 692 | channel->irq_mod_score += tx_packets; |
8e730c15 BH |
693 | efx_xmit_done(tx_queue, tx_ev_desc_ptr); |
694 | } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_WQ_FF_FULL)) { | |
695 | /* Rewrite the FIFO write pointer */ | |
696 | tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL); | |
f7d12cdc BH |
697 | tx_queue = efx_channel_get_tx_queue( |
698 | channel, tx_ev_q_label % EFX_TXQ_TYPES); | |
8e730c15 BH |
699 | |
700 | if (efx_dev_registered(efx)) | |
701 | netif_tx_lock(efx->net_dev); | |
702 | efx_notify_tx_desc(tx_queue); | |
703 | if (efx_dev_registered(efx)) | |
704 | netif_tx_unlock(efx->net_dev); | |
705 | } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_PKT_ERR) && | |
706 | EFX_WORKAROUND_10727(efx)) { | |
707 | efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH); | |
708 | } else { | |
62776d03 BH |
709 | netif_err(efx, tx_err, efx->net_dev, |
710 | "channel %d unexpected TX event " | |
711 | EFX_QWORD_FMT"\n", channel->channel, | |
712 | EFX_QWORD_VAL(*event)); | |
8e730c15 | 713 | } |
fa236e18 BH |
714 | |
715 | return tx_packets; | |
8e730c15 BH |
716 | } |
717 | ||
718 | /* Detect errors included in the rx_evt_pkt_ok bit. */ | |
719 | static void efx_handle_rx_not_ok(struct efx_rx_queue *rx_queue, | |
720 | const efx_qword_t *event, | |
721 | bool *rx_ev_pkt_ok, | |
722 | bool *discard) | |
723 | { | |
ba1e8a35 | 724 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); |
8e730c15 BH |
725 | struct efx_nic *efx = rx_queue->efx; |
726 | bool rx_ev_buf_owner_id_err, rx_ev_ip_hdr_chksum_err; | |
727 | bool rx_ev_tcp_udp_chksum_err, rx_ev_eth_crc_err; | |
728 | bool rx_ev_frm_trunc, rx_ev_drib_nib, rx_ev_tobe_disc; | |
729 | bool rx_ev_other_err, rx_ev_pause_frm; | |
730 | bool rx_ev_hdr_type, rx_ev_mcast_pkt; | |
731 | unsigned rx_ev_pkt_type; | |
732 | ||
733 | rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE); | |
734 | rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT); | |
735 | rx_ev_tobe_disc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_TOBE_DISC); | |
736 | rx_ev_pkt_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_TYPE); | |
737 | rx_ev_buf_owner_id_err = EFX_QWORD_FIELD(*event, | |
738 | FSF_AZ_RX_EV_BUF_OWNER_ID_ERR); | |
739 | rx_ev_ip_hdr_chksum_err = EFX_QWORD_FIELD(*event, | |
740 | FSF_AZ_RX_EV_IP_HDR_CHKSUM_ERR); | |
741 | rx_ev_tcp_udp_chksum_err = EFX_QWORD_FIELD(*event, | |
742 | FSF_AZ_RX_EV_TCP_UDP_CHKSUM_ERR); | |
743 | rx_ev_eth_crc_err = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_ETH_CRC_ERR); | |
744 | rx_ev_frm_trunc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_FRM_TRUNC); | |
745 | rx_ev_drib_nib = ((efx_nic_rev(efx) >= EFX_REV_FALCON_B0) ? | |
746 | 0 : EFX_QWORD_FIELD(*event, FSF_AA_RX_EV_DRIB_NIB)); | |
747 | rx_ev_pause_frm = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PAUSE_FRM_ERR); | |
748 | ||
749 | /* Every error apart from tobe_disc and pause_frm */ | |
750 | rx_ev_other_err = (rx_ev_drib_nib | rx_ev_tcp_udp_chksum_err | | |
751 | rx_ev_buf_owner_id_err | rx_ev_eth_crc_err | | |
752 | rx_ev_frm_trunc | rx_ev_ip_hdr_chksum_err); | |
753 | ||
754 | /* Count errors that are not in MAC stats. Ignore expected | |
755 | * checksum errors during self-test. */ | |
756 | if (rx_ev_frm_trunc) | |
ba1e8a35 | 757 | ++channel->n_rx_frm_trunc; |
8e730c15 | 758 | else if (rx_ev_tobe_disc) |
ba1e8a35 | 759 | ++channel->n_rx_tobe_disc; |
8e730c15 BH |
760 | else if (!efx->loopback_selftest) { |
761 | if (rx_ev_ip_hdr_chksum_err) | |
ba1e8a35 | 762 | ++channel->n_rx_ip_hdr_chksum_err; |
8e730c15 | 763 | else if (rx_ev_tcp_udp_chksum_err) |
ba1e8a35 | 764 | ++channel->n_rx_tcp_udp_chksum_err; |
8e730c15 BH |
765 | } |
766 | ||
767 | /* The frame must be discarded if any of these are true. */ | |
768 | *discard = (rx_ev_eth_crc_err | rx_ev_frm_trunc | rx_ev_drib_nib | | |
769 | rx_ev_tobe_disc | rx_ev_pause_frm); | |
770 | ||
771 | /* TOBE_DISC is expected on unicast mismatches; don't print out an | |
772 | * error message. FRM_TRUNC indicates RXDP dropped the packet due | |
773 | * to a FIFO overflow. | |
774 | */ | |
775 | #ifdef EFX_ENABLE_DEBUG | |
62776d03 BH |
776 | if (rx_ev_other_err && net_ratelimit()) { |
777 | netif_dbg(efx, rx_err, efx->net_dev, | |
778 | " RX queue %d unexpected RX event " | |
779 | EFX_QWORD_FMT "%s%s%s%s%s%s%s%s\n", | |
ba1e8a35 | 780 | efx_rx_queue_index(rx_queue), EFX_QWORD_VAL(*event), |
62776d03 BH |
781 | rx_ev_buf_owner_id_err ? " [OWNER_ID_ERR]" : "", |
782 | rx_ev_ip_hdr_chksum_err ? | |
783 | " [IP_HDR_CHKSUM_ERR]" : "", | |
784 | rx_ev_tcp_udp_chksum_err ? | |
785 | " [TCP_UDP_CHKSUM_ERR]" : "", | |
786 | rx_ev_eth_crc_err ? " [ETH_CRC_ERR]" : "", | |
787 | rx_ev_frm_trunc ? " [FRM_TRUNC]" : "", | |
788 | rx_ev_drib_nib ? " [DRIB_NIB]" : "", | |
789 | rx_ev_tobe_disc ? " [TOBE_DISC]" : "", | |
790 | rx_ev_pause_frm ? " [PAUSE]" : ""); | |
8e730c15 BH |
791 | } |
792 | #endif | |
793 | } | |
794 | ||
795 | /* Handle receive events that are not in-order. */ | |
796 | static void | |
797 | efx_handle_rx_bad_index(struct efx_rx_queue *rx_queue, unsigned index) | |
798 | { | |
799 | struct efx_nic *efx = rx_queue->efx; | |
800 | unsigned expected, dropped; | |
801 | ||
ecc910f5 SH |
802 | expected = rx_queue->removed_count & rx_queue->ptr_mask; |
803 | dropped = (index - expected) & rx_queue->ptr_mask; | |
62776d03 BH |
804 | netif_info(efx, rx_err, efx->net_dev, |
805 | "dropped %d events (index=%d expected=%d)\n", | |
806 | dropped, index, expected); | |
8e730c15 BH |
807 | |
808 | efx_schedule_reset(efx, EFX_WORKAROUND_5676(efx) ? | |
809 | RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE); | |
810 | } | |
811 | ||
812 | /* Handle a packet received event | |
813 | * | |
814 | * The NIC gives a "discard" flag if it's a unicast packet with the | |
815 | * wrong destination address | |
816 | * Also "is multicast" and "matches multicast filter" flags can be used to | |
817 | * discard non-matching multicast packets. | |
818 | */ | |
819 | static void | |
820 | efx_handle_rx_event(struct efx_channel *channel, const efx_qword_t *event) | |
821 | { | |
822 | unsigned int rx_ev_desc_ptr, rx_ev_byte_cnt; | |
823 | unsigned int rx_ev_hdr_type, rx_ev_mcast_pkt; | |
824 | unsigned expected_ptr; | |
825 | bool rx_ev_pkt_ok, discard = false, checksummed; | |
826 | struct efx_rx_queue *rx_queue; | |
827 | struct efx_nic *efx = channel->efx; | |
828 | ||
829 | /* Basic packet information */ | |
830 | rx_ev_byte_cnt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_BYTE_CNT); | |
831 | rx_ev_pkt_ok = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_OK); | |
832 | rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE); | |
833 | WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_JUMBO_CONT)); | |
834 | WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_SOP) != 1); | |
835 | WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_Q_LABEL) != | |
836 | channel->channel); | |
837 | ||
f7d12cdc | 838 | rx_queue = efx_channel_get_rx_queue(channel); |
8e730c15 BH |
839 | |
840 | rx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_DESC_PTR); | |
ecc910f5 | 841 | expected_ptr = rx_queue->removed_count & rx_queue->ptr_mask; |
8e730c15 BH |
842 | if (unlikely(rx_ev_desc_ptr != expected_ptr)) |
843 | efx_handle_rx_bad_index(rx_queue, rx_ev_desc_ptr); | |
844 | ||
845 | if (likely(rx_ev_pkt_ok)) { | |
846 | /* If packet is marked as OK and packet type is TCP/IP or | |
847 | * UDP/IP, then we can rely on the hardware checksum. | |
848 | */ | |
849 | checksummed = | |
850 | likely(efx->rx_checksum_enabled) && | |
851 | (rx_ev_hdr_type == FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_TCP || | |
852 | rx_ev_hdr_type == FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_UDP); | |
853 | } else { | |
854 | efx_handle_rx_not_ok(rx_queue, event, &rx_ev_pkt_ok, &discard); | |
855 | checksummed = false; | |
856 | } | |
857 | ||
858 | /* Detect multicast packets that didn't match the filter */ | |
859 | rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT); | |
860 | if (rx_ev_mcast_pkt) { | |
861 | unsigned int rx_ev_mcast_hash_match = | |
862 | EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_HASH_MATCH); | |
863 | ||
864 | if (unlikely(!rx_ev_mcast_hash_match)) { | |
865 | ++channel->n_rx_mcast_mismatch; | |
866 | discard = true; | |
867 | } | |
868 | } | |
869 | ||
870 | channel->irq_mod_score += 2; | |
871 | ||
872 | /* Handle received packet */ | |
873 | efx_rx_packet(rx_queue, rx_ev_desc_ptr, rx_ev_byte_cnt, | |
874 | checksummed, discard); | |
875 | } | |
876 | ||
90d683af SH |
877 | static void |
878 | efx_handle_generated_event(struct efx_channel *channel, efx_qword_t *event) | |
879 | { | |
880 | struct efx_nic *efx = channel->efx; | |
881 | unsigned code; | |
882 | ||
883 | code = EFX_QWORD_FIELD(*event, FSF_AZ_DRV_GEN_EV_MAGIC); | |
884 | if (code == EFX_CHANNEL_MAGIC_TEST(channel)) | |
885 | ++channel->magic_count; | |
886 | else if (code == EFX_CHANNEL_MAGIC_FILL(channel)) | |
887 | /* The queue must be empty, so we won't receive any rx | |
888 | * events, so efx_process_channel() won't refill the | |
889 | * queue. Refill it here */ | |
f7d12cdc | 890 | efx_fast_push_rx_descriptors(efx_channel_get_rx_queue(channel)); |
90d683af | 891 | else |
62776d03 BH |
892 | netif_dbg(efx, hw, efx->net_dev, "channel %d received " |
893 | "generated event "EFX_QWORD_FMT"\n", | |
894 | channel->channel, EFX_QWORD_VAL(*event)); | |
90d683af SH |
895 | } |
896 | ||
8e730c15 BH |
897 | static void |
898 | efx_handle_driver_event(struct efx_channel *channel, efx_qword_t *event) | |
899 | { | |
900 | struct efx_nic *efx = channel->efx; | |
901 | unsigned int ev_sub_code; | |
902 | unsigned int ev_sub_data; | |
903 | ||
904 | ev_sub_code = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBCODE); | |
905 | ev_sub_data = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA); | |
906 | ||
907 | switch (ev_sub_code) { | |
908 | case FSE_AZ_TX_DESCQ_FLS_DONE_EV: | |
62776d03 BH |
909 | netif_vdbg(efx, hw, efx->net_dev, "channel %d TXQ %d flushed\n", |
910 | channel->channel, ev_sub_data); | |
8e730c15 BH |
911 | break; |
912 | case FSE_AZ_RX_DESCQ_FLS_DONE_EV: | |
62776d03 BH |
913 | netif_vdbg(efx, hw, efx->net_dev, "channel %d RXQ %d flushed\n", |
914 | channel->channel, ev_sub_data); | |
8e730c15 BH |
915 | break; |
916 | case FSE_AZ_EVQ_INIT_DONE_EV: | |
62776d03 BH |
917 | netif_dbg(efx, hw, efx->net_dev, |
918 | "channel %d EVQ %d initialised\n", | |
919 | channel->channel, ev_sub_data); | |
8e730c15 BH |
920 | break; |
921 | case FSE_AZ_SRM_UPD_DONE_EV: | |
62776d03 BH |
922 | netif_vdbg(efx, hw, efx->net_dev, |
923 | "channel %d SRAM update done\n", channel->channel); | |
8e730c15 BH |
924 | break; |
925 | case FSE_AZ_WAKE_UP_EV: | |
62776d03 BH |
926 | netif_vdbg(efx, hw, efx->net_dev, |
927 | "channel %d RXQ %d wakeup event\n", | |
928 | channel->channel, ev_sub_data); | |
8e730c15 BH |
929 | break; |
930 | case FSE_AZ_TIMER_EV: | |
62776d03 BH |
931 | netif_vdbg(efx, hw, efx->net_dev, |
932 | "channel %d RX queue %d timer expired\n", | |
933 | channel->channel, ev_sub_data); | |
8e730c15 BH |
934 | break; |
935 | case FSE_AA_RX_RECOVER_EV: | |
62776d03 BH |
936 | netif_err(efx, rx_err, efx->net_dev, |
937 | "channel %d seen DRIVER RX_RESET event. " | |
8e730c15 BH |
938 | "Resetting.\n", channel->channel); |
939 | atomic_inc(&efx->rx_reset); | |
940 | efx_schedule_reset(efx, | |
941 | EFX_WORKAROUND_6555(efx) ? | |
942 | RESET_TYPE_RX_RECOVERY : | |
943 | RESET_TYPE_DISABLE); | |
944 | break; | |
945 | case FSE_BZ_RX_DSC_ERROR_EV: | |
62776d03 BH |
946 | netif_err(efx, rx_err, efx->net_dev, |
947 | "RX DMA Q %d reports descriptor fetch error." | |
948 | " RX Q %d is disabled.\n", ev_sub_data, ev_sub_data); | |
8e730c15 BH |
949 | efx_schedule_reset(efx, RESET_TYPE_RX_DESC_FETCH); |
950 | break; | |
951 | case FSE_BZ_TX_DSC_ERROR_EV: | |
62776d03 BH |
952 | netif_err(efx, tx_err, efx->net_dev, |
953 | "TX DMA Q %d reports descriptor fetch error." | |
954 | " TX Q %d is disabled.\n", ev_sub_data, ev_sub_data); | |
8e730c15 BH |
955 | efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH); |
956 | break; | |
957 | default: | |
62776d03 BH |
958 | netif_vdbg(efx, hw, efx->net_dev, |
959 | "channel %d unknown driver event code %d " | |
960 | "data %04x\n", channel->channel, ev_sub_code, | |
961 | ev_sub_data); | |
8e730c15 BH |
962 | break; |
963 | } | |
964 | } | |
965 | ||
fa236e18 | 966 | int efx_nic_process_eventq(struct efx_channel *channel, int budget) |
8e730c15 | 967 | { |
ecc910f5 | 968 | struct efx_nic *efx = channel->efx; |
8e730c15 BH |
969 | unsigned int read_ptr; |
970 | efx_qword_t event, *p_event; | |
971 | int ev_code; | |
fa236e18 BH |
972 | int tx_packets = 0; |
973 | int spent = 0; | |
8e730c15 BH |
974 | |
975 | read_ptr = channel->eventq_read_ptr; | |
976 | ||
fa236e18 | 977 | for (;;) { |
8e730c15 BH |
978 | p_event = efx_event(channel, read_ptr); |
979 | event = *p_event; | |
980 | ||
981 | if (!efx_event_present(&event)) | |
982 | /* End of events */ | |
983 | break; | |
984 | ||
62776d03 BH |
985 | netif_vdbg(channel->efx, intr, channel->efx->net_dev, |
986 | "channel %d event is "EFX_QWORD_FMT"\n", | |
987 | channel->channel, EFX_QWORD_VAL(event)); | |
8e730c15 BH |
988 | |
989 | /* Clear this event by marking it all ones */ | |
990 | EFX_SET_QWORD(*p_event); | |
991 | ||
fa236e18 | 992 | /* Increment read pointer */ |
ecc910f5 | 993 | read_ptr = (read_ptr + 1) & channel->eventq_mask; |
fa236e18 | 994 | |
8e730c15 BH |
995 | ev_code = EFX_QWORD_FIELD(event, FSF_AZ_EV_CODE); |
996 | ||
997 | switch (ev_code) { | |
998 | case FSE_AZ_EV_CODE_RX_EV: | |
999 | efx_handle_rx_event(channel, &event); | |
fa236e18 BH |
1000 | if (++spent == budget) |
1001 | goto out; | |
8e730c15 BH |
1002 | break; |
1003 | case FSE_AZ_EV_CODE_TX_EV: | |
fa236e18 | 1004 | tx_packets += efx_handle_tx_event(channel, &event); |
ecc910f5 | 1005 | if (tx_packets > efx->txq_entries) { |
fa236e18 BH |
1006 | spent = budget; |
1007 | goto out; | |
1008 | } | |
8e730c15 BH |
1009 | break; |
1010 | case FSE_AZ_EV_CODE_DRV_GEN_EV: | |
90d683af | 1011 | efx_handle_generated_event(channel, &event); |
8e730c15 | 1012 | break; |
8e730c15 BH |
1013 | case FSE_AZ_EV_CODE_DRIVER_EV: |
1014 | efx_handle_driver_event(channel, &event); | |
1015 | break; | |
8880f4ec BH |
1016 | case FSE_CZ_EV_CODE_MCDI_EV: |
1017 | efx_mcdi_process_event(channel, &event); | |
1018 | break; | |
40641ed9 BH |
1019 | case FSE_AZ_EV_CODE_GLOBAL_EV: |
1020 | if (efx->type->handle_global_event && | |
1021 | efx->type->handle_global_event(channel, &event)) | |
1022 | break; | |
1023 | /* else fall through */ | |
8e730c15 | 1024 | default: |
62776d03 BH |
1025 | netif_err(channel->efx, hw, channel->efx->net_dev, |
1026 | "channel %d unknown event type %d (data " | |
1027 | EFX_QWORD_FMT ")\n", channel->channel, | |
1028 | ev_code, EFX_QWORD_VAL(event)); | |
8e730c15 | 1029 | } |
fa236e18 | 1030 | } |
8e730c15 | 1031 | |
fa236e18 | 1032 | out: |
8e730c15 | 1033 | channel->eventq_read_ptr = read_ptr; |
fa236e18 | 1034 | return spent; |
8e730c15 BH |
1035 | } |
1036 | ||
1037 | ||
1038 | /* Allocate buffer table entries for event queue */ | |
1039 | int efx_nic_probe_eventq(struct efx_channel *channel) | |
1040 | { | |
1041 | struct efx_nic *efx = channel->efx; | |
ecc910f5 SH |
1042 | unsigned entries; |
1043 | ||
1044 | entries = channel->eventq_mask + 1; | |
8e730c15 | 1045 | return efx_alloc_special_buffer(efx, &channel->eventq, |
ecc910f5 | 1046 | entries * sizeof(efx_qword_t)); |
8e730c15 BH |
1047 | } |
1048 | ||
1049 | void efx_nic_init_eventq(struct efx_channel *channel) | |
1050 | { | |
8880f4ec | 1051 | efx_oword_t reg; |
8e730c15 BH |
1052 | struct efx_nic *efx = channel->efx; |
1053 | ||
62776d03 BH |
1054 | netif_dbg(efx, hw, efx->net_dev, |
1055 | "channel %d event queue in special buffers %d-%d\n", | |
1056 | channel->channel, channel->eventq.index, | |
1057 | channel->eventq.index + channel->eventq.entries - 1); | |
8e730c15 | 1058 | |
8880f4ec BH |
1059 | if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) { |
1060 | EFX_POPULATE_OWORD_3(reg, | |
1061 | FRF_CZ_TIMER_Q_EN, 1, | |
1062 | FRF_CZ_HOST_NOTIFY_MODE, 0, | |
1063 | FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS); | |
1064 | efx_writeo_table(efx, ®, FR_BZ_TIMER_TBL, channel->channel); | |
1065 | } | |
1066 | ||
8e730c15 BH |
1067 | /* Pin event queue buffer */ |
1068 | efx_init_special_buffer(efx, &channel->eventq); | |
1069 | ||
1070 | /* Fill event queue with all ones (i.e. empty events) */ | |
1071 | memset(channel->eventq.addr, 0xff, channel->eventq.len); | |
1072 | ||
1073 | /* Push event queue to card */ | |
8880f4ec | 1074 | EFX_POPULATE_OWORD_3(reg, |
8e730c15 BH |
1075 | FRF_AZ_EVQ_EN, 1, |
1076 | FRF_AZ_EVQ_SIZE, __ffs(channel->eventq.entries), | |
1077 | FRF_AZ_EVQ_BUF_BASE_ID, channel->eventq.index); | |
8880f4ec | 1078 | efx_writeo_table(efx, ®, efx->type->evq_ptr_tbl_base, |
8e730c15 BH |
1079 | channel->channel); |
1080 | ||
1081 | efx->type->push_irq_moderation(channel); | |
1082 | } | |
1083 | ||
1084 | void efx_nic_fini_eventq(struct efx_channel *channel) | |
1085 | { | |
8880f4ec | 1086 | efx_oword_t reg; |
8e730c15 BH |
1087 | struct efx_nic *efx = channel->efx; |
1088 | ||
1089 | /* Remove event queue from card */ | |
8880f4ec BH |
1090 | EFX_ZERO_OWORD(reg); |
1091 | efx_writeo_table(efx, ®, efx->type->evq_ptr_tbl_base, | |
8e730c15 | 1092 | channel->channel); |
8880f4ec BH |
1093 | if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) |
1094 | efx_writeo_table(efx, ®, FR_BZ_TIMER_TBL, channel->channel); | |
8e730c15 BH |
1095 | |
1096 | /* Unpin event queue */ | |
1097 | efx_fini_special_buffer(efx, &channel->eventq); | |
1098 | } | |
1099 | ||
1100 | /* Free buffers backing event queue */ | |
1101 | void efx_nic_remove_eventq(struct efx_channel *channel) | |
1102 | { | |
1103 | efx_free_special_buffer(channel->efx, &channel->eventq); | |
1104 | } | |
1105 | ||
1106 | ||
d730dc52 | 1107 | void efx_nic_generate_test_event(struct efx_channel *channel) |
8e730c15 | 1108 | { |
90d683af SH |
1109 | unsigned int magic = EFX_CHANNEL_MAGIC_TEST(channel); |
1110 | efx_qword_t test_event; | |
1111 | ||
1112 | EFX_POPULATE_QWORD_2(test_event, FSF_AZ_EV_CODE, | |
1113 | FSE_AZ_EV_CODE_DRV_GEN_EV, | |
1114 | FSF_AZ_DRV_GEN_EV_MAGIC, magic); | |
1115 | efx_generate_event(channel, &test_event); | |
1116 | } | |
1117 | ||
1118 | void efx_nic_generate_fill_event(struct efx_channel *channel) | |
1119 | { | |
1120 | unsigned int magic = EFX_CHANNEL_MAGIC_FILL(channel); | |
8e730c15 BH |
1121 | efx_qword_t test_event; |
1122 | ||
1123 | EFX_POPULATE_QWORD_2(test_event, FSF_AZ_EV_CODE, | |
1124 | FSE_AZ_EV_CODE_DRV_GEN_EV, | |
1125 | FSF_AZ_DRV_GEN_EV_MAGIC, magic); | |
1126 | efx_generate_event(channel, &test_event); | |
1127 | } | |
1128 | ||
1129 | /************************************************************************** | |
1130 | * | |
1131 | * Flush handling | |
1132 | * | |
1133 | **************************************************************************/ | |
1134 | ||
1135 | ||
1136 | static void efx_poll_flush_events(struct efx_nic *efx) | |
1137 | { | |
f7d12cdc | 1138 | struct efx_channel *channel = efx_get_channel(efx, 0); |
8e730c15 BH |
1139 | struct efx_tx_queue *tx_queue; |
1140 | struct efx_rx_queue *rx_queue; | |
1141 | unsigned int read_ptr = channel->eventq_read_ptr; | |
ecc910f5 | 1142 | unsigned int end_ptr = (read_ptr - 1) & channel->eventq_mask; |
8e730c15 BH |
1143 | |
1144 | do { | |
1145 | efx_qword_t *event = efx_event(channel, read_ptr); | |
1146 | int ev_code, ev_sub_code, ev_queue; | |
1147 | bool ev_failed; | |
1148 | ||
1149 | if (!efx_event_present(event)) | |
1150 | break; | |
1151 | ||
1152 | ev_code = EFX_QWORD_FIELD(*event, FSF_AZ_EV_CODE); | |
1153 | ev_sub_code = EFX_QWORD_FIELD(*event, | |
1154 | FSF_AZ_DRIVER_EV_SUBCODE); | |
1155 | if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV && | |
1156 | ev_sub_code == FSE_AZ_TX_DESCQ_FLS_DONE_EV) { | |
1157 | ev_queue = EFX_QWORD_FIELD(*event, | |
1158 | FSF_AZ_DRIVER_EV_SUBDATA); | |
a4900ac9 | 1159 | if (ev_queue < EFX_TXQ_TYPES * efx->n_tx_channels) { |
f7d12cdc BH |
1160 | tx_queue = efx_get_tx_queue( |
1161 | efx, ev_queue / EFX_TXQ_TYPES, | |
1162 | ev_queue % EFX_TXQ_TYPES); | |
8e730c15 BH |
1163 | tx_queue->flushed = FLUSH_DONE; |
1164 | } | |
1165 | } else if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV && | |
1166 | ev_sub_code == FSE_AZ_RX_DESCQ_FLS_DONE_EV) { | |
1167 | ev_queue = EFX_QWORD_FIELD( | |
1168 | *event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID); | |
1169 | ev_failed = EFX_QWORD_FIELD( | |
1170 | *event, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL); | |
a4900ac9 | 1171 | if (ev_queue < efx->n_rx_channels) { |
f7d12cdc | 1172 | rx_queue = efx_get_rx_queue(efx, ev_queue); |
8e730c15 BH |
1173 | rx_queue->flushed = |
1174 | ev_failed ? FLUSH_FAILED : FLUSH_DONE; | |
1175 | } | |
1176 | } | |
1177 | ||
1178 | /* We're about to destroy the queue anyway, so | |
1179 | * it's ok to throw away every non-flush event */ | |
1180 | EFX_SET_QWORD(*event); | |
1181 | ||
ecc910f5 | 1182 | read_ptr = (read_ptr + 1) & channel->eventq_mask; |
8e730c15 BH |
1183 | } while (read_ptr != end_ptr); |
1184 | ||
1185 | channel->eventq_read_ptr = read_ptr; | |
1186 | } | |
1187 | ||
1188 | /* Handle tx and rx flushes at the same time, since they run in | |
1189 | * parallel in the hardware and there's no reason for us to | |
1190 | * serialise them */ | |
1191 | int efx_nic_flush_queues(struct efx_nic *efx) | |
1192 | { | |
f7d12cdc | 1193 | struct efx_channel *channel; |
8e730c15 BH |
1194 | struct efx_rx_queue *rx_queue; |
1195 | struct efx_tx_queue *tx_queue; | |
1196 | int i, tx_pending, rx_pending; | |
1197 | ||
1198 | /* If necessary prepare the hardware for flushing */ | |
1199 | efx->type->prepare_flush(efx); | |
1200 | ||
1201 | /* Flush all tx queues in parallel */ | |
f7d12cdc BH |
1202 | efx_for_each_channel(channel, efx) { |
1203 | efx_for_each_channel_tx_queue(tx_queue, channel) | |
1204 | efx_flush_tx_queue(tx_queue); | |
1205 | } | |
8e730c15 BH |
1206 | |
1207 | /* The hardware supports four concurrent rx flushes, each of which may | |
1208 | * need to be retried if there is an outstanding descriptor fetch */ | |
1209 | for (i = 0; i < EFX_FLUSH_POLL_COUNT; ++i) { | |
1210 | rx_pending = tx_pending = 0; | |
f7d12cdc BH |
1211 | efx_for_each_channel(channel, efx) { |
1212 | efx_for_each_channel_rx_queue(rx_queue, channel) { | |
1213 | if (rx_queue->flushed == FLUSH_PENDING) | |
1214 | ++rx_pending; | |
8e730c15 BH |
1215 | } |
1216 | } | |
f7d12cdc BH |
1217 | efx_for_each_channel(channel, efx) { |
1218 | efx_for_each_channel_rx_queue(rx_queue, channel) { | |
1219 | if (rx_pending == EFX_RX_FLUSH_COUNT) | |
1220 | break; | |
1221 | if (rx_queue->flushed == FLUSH_FAILED || | |
1222 | rx_queue->flushed == FLUSH_NONE) { | |
1223 | efx_flush_rx_queue(rx_queue); | |
1224 | ++rx_pending; | |
1225 | } | |
1226 | } | |
1227 | efx_for_each_channel_tx_queue(tx_queue, channel) { | |
1228 | if (tx_queue->flushed != FLUSH_DONE) | |
1229 | ++tx_pending; | |
1230 | } | |
8e730c15 BH |
1231 | } |
1232 | ||
1233 | if (rx_pending == 0 && tx_pending == 0) | |
1234 | return 0; | |
1235 | ||
1236 | msleep(EFX_FLUSH_INTERVAL); | |
1237 | efx_poll_flush_events(efx); | |
1238 | } | |
1239 | ||
1240 | /* Mark the queues as all flushed. We're going to return failure | |
1241 | * leading to a reset, or fake up success anyway */ | |
f7d12cdc BH |
1242 | efx_for_each_channel(channel, efx) { |
1243 | efx_for_each_channel_tx_queue(tx_queue, channel) { | |
1244 | if (tx_queue->flushed != FLUSH_DONE) | |
1245 | netif_err(efx, hw, efx->net_dev, | |
1246 | "tx queue %d flush command timed out\n", | |
1247 | tx_queue->queue); | |
1248 | tx_queue->flushed = FLUSH_DONE; | |
1249 | } | |
1250 | efx_for_each_channel_rx_queue(rx_queue, channel) { | |
1251 | if (rx_queue->flushed != FLUSH_DONE) | |
1252 | netif_err(efx, hw, efx->net_dev, | |
1253 | "rx queue %d flush command timed out\n", | |
1254 | efx_rx_queue_index(rx_queue)); | |
1255 | rx_queue->flushed = FLUSH_DONE; | |
1256 | } | |
8e730c15 BH |
1257 | } |
1258 | ||
8e730c15 BH |
1259 | return -ETIMEDOUT; |
1260 | } | |
1261 | ||
1262 | /************************************************************************** | |
1263 | * | |
1264 | * Hardware interrupts | |
1265 | * The hardware interrupt handler does very little work; all the event | |
1266 | * queue processing is carried out by per-channel tasklets. | |
1267 | * | |
1268 | **************************************************************************/ | |
1269 | ||
1270 | /* Enable/disable/generate interrupts */ | |
1271 | static inline void efx_nic_interrupts(struct efx_nic *efx, | |
1272 | bool enabled, bool force) | |
1273 | { | |
1274 | efx_oword_t int_en_reg_ker; | |
8880f4ec BH |
1275 | |
1276 | EFX_POPULATE_OWORD_3(int_en_reg_ker, | |
63695459 | 1277 | FRF_AZ_KER_INT_LEVE_SEL, efx->fatal_irq_level, |
8e730c15 BH |
1278 | FRF_AZ_KER_INT_KER, force, |
1279 | FRF_AZ_DRV_INT_EN_KER, enabled); | |
1280 | efx_writeo(efx, &int_en_reg_ker, FR_AZ_INT_EN_KER); | |
1281 | } | |
1282 | ||
1283 | void efx_nic_enable_interrupts(struct efx_nic *efx) | |
1284 | { | |
1285 | struct efx_channel *channel; | |
1286 | ||
1287 | EFX_ZERO_OWORD(*((efx_oword_t *) efx->irq_status.addr)); | |
1288 | wmb(); /* Ensure interrupt vector is clear before interrupts enabled */ | |
1289 | ||
1290 | /* Enable interrupts */ | |
1291 | efx_nic_interrupts(efx, true, false); | |
1292 | ||
1293 | /* Force processing of all the channels to get the EVQ RPTRs up to | |
1294 | date */ | |
1295 | efx_for_each_channel(channel, efx) | |
1296 | efx_schedule_channel(channel); | |
1297 | } | |
1298 | ||
1299 | void efx_nic_disable_interrupts(struct efx_nic *efx) | |
1300 | { | |
1301 | /* Disable interrupts */ | |
1302 | efx_nic_interrupts(efx, false, false); | |
1303 | } | |
1304 | ||
1305 | /* Generate a test interrupt | |
1306 | * Interrupt must already have been enabled, otherwise nasty things | |
1307 | * may happen. | |
1308 | */ | |
1309 | void efx_nic_generate_interrupt(struct efx_nic *efx) | |
1310 | { | |
1311 | efx_nic_interrupts(efx, true, true); | |
1312 | } | |
1313 | ||
1314 | /* Process a fatal interrupt | |
1315 | * Disable bus mastering ASAP and schedule a reset | |
1316 | */ | |
1317 | irqreturn_t efx_nic_fatal_interrupt(struct efx_nic *efx) | |
1318 | { | |
1319 | struct falcon_nic_data *nic_data = efx->nic_data; | |
1320 | efx_oword_t *int_ker = efx->irq_status.addr; | |
1321 | efx_oword_t fatal_intr; | |
1322 | int error, mem_perr; | |
1323 | ||
1324 | efx_reado(efx, &fatal_intr, FR_AZ_FATAL_INTR_KER); | |
1325 | error = EFX_OWORD_FIELD(fatal_intr, FRF_AZ_FATAL_INTR); | |
1326 | ||
62776d03 BH |
1327 | netif_err(efx, hw, efx->net_dev, "SYSTEM ERROR "EFX_OWORD_FMT" status " |
1328 | EFX_OWORD_FMT ": %s\n", EFX_OWORD_VAL(*int_ker), | |
1329 | EFX_OWORD_VAL(fatal_intr), | |
1330 | error ? "disabling bus mastering" : "no recognised error"); | |
8e730c15 BH |
1331 | |
1332 | /* If this is a memory parity error dump which blocks are offending */ | |
97e1eaa0 SH |
1333 | mem_perr = (EFX_OWORD_FIELD(fatal_intr, FRF_AZ_MEM_PERR_INT_KER) || |
1334 | EFX_OWORD_FIELD(fatal_intr, FRF_AZ_SRM_PERR_INT_KER)); | |
8e730c15 BH |
1335 | if (mem_perr) { |
1336 | efx_oword_t reg; | |
1337 | efx_reado(efx, ®, FR_AZ_MEM_STAT); | |
62776d03 BH |
1338 | netif_err(efx, hw, efx->net_dev, |
1339 | "SYSTEM ERROR: memory parity error "EFX_OWORD_FMT"\n", | |
1340 | EFX_OWORD_VAL(reg)); | |
8e730c15 BH |
1341 | } |
1342 | ||
1343 | /* Disable both devices */ | |
1344 | pci_clear_master(efx->pci_dev); | |
1345 | if (efx_nic_is_dual_func(efx)) | |
1346 | pci_clear_master(nic_data->pci_dev2); | |
1347 | efx_nic_disable_interrupts(efx); | |
1348 | ||
1349 | /* Count errors and reset or disable the NIC accordingly */ | |
1350 | if (efx->int_error_count == 0 || | |
1351 | time_after(jiffies, efx->int_error_expire)) { | |
1352 | efx->int_error_count = 0; | |
1353 | efx->int_error_expire = | |
1354 | jiffies + EFX_INT_ERROR_EXPIRE * HZ; | |
1355 | } | |
1356 | if (++efx->int_error_count < EFX_MAX_INT_ERRORS) { | |
62776d03 BH |
1357 | netif_err(efx, hw, efx->net_dev, |
1358 | "SYSTEM ERROR - reset scheduled\n"); | |
8e730c15 BH |
1359 | efx_schedule_reset(efx, RESET_TYPE_INT_ERROR); |
1360 | } else { | |
62776d03 BH |
1361 | netif_err(efx, hw, efx->net_dev, |
1362 | "SYSTEM ERROR - max number of errors seen." | |
1363 | "NIC will be disabled\n"); | |
8e730c15 BH |
1364 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); |
1365 | } | |
63695459 | 1366 | |
8e730c15 BH |
1367 | return IRQ_HANDLED; |
1368 | } | |
1369 | ||
1370 | /* Handle a legacy interrupt | |
1371 | * Acknowledges the interrupt and schedule event queue processing. | |
1372 | */ | |
1373 | static irqreturn_t efx_legacy_interrupt(int irq, void *dev_id) | |
1374 | { | |
1375 | struct efx_nic *efx = dev_id; | |
1376 | efx_oword_t *int_ker = efx->irq_status.addr; | |
1377 | irqreturn_t result = IRQ_NONE; | |
1378 | struct efx_channel *channel; | |
1379 | efx_dword_t reg; | |
1380 | u32 queues; | |
1381 | int syserr; | |
1382 | ||
1383 | /* Read the ISR which also ACKs the interrupts */ | |
1384 | efx_readd(efx, ®, FR_BZ_INT_ISR0); | |
1385 | queues = EFX_EXTRACT_DWORD(reg, 0, 31); | |
1386 | ||
1387 | /* Check to see if we have a serious error condition */ | |
63695459 SH |
1388 | if (queues & (1U << efx->fatal_irq_level)) { |
1389 | syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT); | |
1390 | if (unlikely(syserr)) | |
1391 | return efx_nic_fatal_interrupt(efx); | |
1392 | } | |
8e730c15 | 1393 | |
8880f4ec BH |
1394 | if (queues != 0) { |
1395 | if (EFX_WORKAROUND_15783(efx)) | |
1396 | efx->irq_zero_count = 0; | |
1397 | ||
1398 | /* Schedule processing of any interrupting queues */ | |
1399 | efx_for_each_channel(channel, efx) { | |
1400 | if (queues & 1) | |
8e730c15 | 1401 | efx_schedule_channel(channel); |
8880f4ec | 1402 | queues >>= 1; |
8e730c15 | 1403 | } |
8880f4ec BH |
1404 | result = IRQ_HANDLED; |
1405 | ||
41b7e4c3 | 1406 | } else if (EFX_WORKAROUND_15783(efx)) { |
8880f4ec BH |
1407 | efx_qword_t *event; |
1408 | ||
41b7e4c3 SH |
1409 | /* We can't return IRQ_HANDLED more than once on seeing ISR=0 |
1410 | * because this might be a shared interrupt. */ | |
1411 | if (efx->irq_zero_count++ == 0) | |
1412 | result = IRQ_HANDLED; | |
1413 | ||
1414 | /* Ensure we schedule or rearm all event queues */ | |
8880f4ec BH |
1415 | efx_for_each_channel(channel, efx) { |
1416 | event = efx_event(channel, channel->eventq_read_ptr); | |
1417 | if (efx_event_present(event)) | |
1418 | efx_schedule_channel(channel); | |
41b7e4c3 SH |
1419 | else |
1420 | efx_nic_eventq_read_ack(channel); | |
8880f4ec | 1421 | } |
8e730c15 BH |
1422 | } |
1423 | ||
1424 | if (result == IRQ_HANDLED) { | |
1425 | efx->last_irq_cpu = raw_smp_processor_id(); | |
62776d03 BH |
1426 | netif_vdbg(efx, intr, efx->net_dev, |
1427 | "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n", | |
1428 | irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg)); | |
8e730c15 BH |
1429 | } |
1430 | ||
1431 | return result; | |
1432 | } | |
1433 | ||
1434 | /* Handle an MSI interrupt | |
1435 | * | |
1436 | * Handle an MSI hardware interrupt. This routine schedules event | |
1437 | * queue processing. No interrupt acknowledgement cycle is necessary. | |
1438 | * Also, we never need to check that the interrupt is for us, since | |
1439 | * MSI interrupts cannot be shared. | |
1440 | */ | |
1441 | static irqreturn_t efx_msi_interrupt(int irq, void *dev_id) | |
1442 | { | |
4642610c | 1443 | struct efx_channel *channel = *(struct efx_channel **)dev_id; |
8e730c15 BH |
1444 | struct efx_nic *efx = channel->efx; |
1445 | efx_oword_t *int_ker = efx->irq_status.addr; | |
1446 | int syserr; | |
1447 | ||
1448 | efx->last_irq_cpu = raw_smp_processor_id(); | |
62776d03 BH |
1449 | netif_vdbg(efx, intr, efx->net_dev, |
1450 | "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n", | |
1451 | irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker)); | |
8e730c15 BH |
1452 | |
1453 | /* Check to see if we have a serious error condition */ | |
63695459 SH |
1454 | if (channel->channel == efx->fatal_irq_level) { |
1455 | syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT); | |
1456 | if (unlikely(syserr)) | |
1457 | return efx_nic_fatal_interrupt(efx); | |
1458 | } | |
8e730c15 BH |
1459 | |
1460 | /* Schedule processing of the channel */ | |
1461 | efx_schedule_channel(channel); | |
1462 | ||
1463 | return IRQ_HANDLED; | |
1464 | } | |
1465 | ||
1466 | ||
1467 | /* Setup RSS indirection table. | |
1468 | * This maps from the hash value of the packet to RXQ | |
1469 | */ | |
765c9f46 | 1470 | void efx_nic_push_rx_indir_table(struct efx_nic *efx) |
8e730c15 | 1471 | { |
765c9f46 | 1472 | size_t i = 0; |
8e730c15 BH |
1473 | efx_dword_t dword; |
1474 | ||
1475 | if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) | |
1476 | return; | |
1477 | ||
765c9f46 BH |
1478 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) != |
1479 | FR_BZ_RX_INDIRECTION_TBL_ROWS); | |
1480 | ||
1481 | for (i = 0; i < FR_BZ_RX_INDIRECTION_TBL_ROWS; i++) { | |
8e730c15 | 1482 | EFX_POPULATE_DWORD_1(dword, FRF_BZ_IT_QUEUE, |
765c9f46 BH |
1483 | efx->rx_indir_table[i]); |
1484 | efx_writed_table(efx, &dword, FR_BZ_RX_INDIRECTION_TBL, i); | |
8e730c15 BH |
1485 | } |
1486 | } | |
1487 | ||
1488 | /* Hook interrupt handler(s) | |
1489 | * Try MSI and then legacy interrupts. | |
1490 | */ | |
1491 | int efx_nic_init_interrupt(struct efx_nic *efx) | |
1492 | { | |
1493 | struct efx_channel *channel; | |
1494 | int rc; | |
1495 | ||
1496 | if (!EFX_INT_MODE_USE_MSI(efx)) { | |
1497 | irq_handler_t handler; | |
1498 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) | |
1499 | handler = efx_legacy_interrupt; | |
1500 | else | |
1501 | handler = falcon_legacy_interrupt_a1; | |
1502 | ||
1503 | rc = request_irq(efx->legacy_irq, handler, IRQF_SHARED, | |
1504 | efx->name, efx); | |
1505 | if (rc) { | |
62776d03 BH |
1506 | netif_err(efx, drv, efx->net_dev, |
1507 | "failed to hook legacy IRQ %d\n", | |
1508 | efx->pci_dev->irq); | |
8e730c15 BH |
1509 | goto fail1; |
1510 | } | |
1511 | return 0; | |
1512 | } | |
1513 | ||
1514 | /* Hook MSI or MSI-X interrupt */ | |
1515 | efx_for_each_channel(channel, efx) { | |
1516 | rc = request_irq(channel->irq, efx_msi_interrupt, | |
1517 | IRQF_PROBE_SHARED, /* Not shared */ | |
4642610c BH |
1518 | efx->channel_name[channel->channel], |
1519 | &efx->channel[channel->channel]); | |
8e730c15 | 1520 | if (rc) { |
62776d03 BH |
1521 | netif_err(efx, drv, efx->net_dev, |
1522 | "failed to hook IRQ %d\n", channel->irq); | |
8e730c15 BH |
1523 | goto fail2; |
1524 | } | |
1525 | } | |
1526 | ||
1527 | return 0; | |
1528 | ||
1529 | fail2: | |
1530 | efx_for_each_channel(channel, efx) | |
4642610c | 1531 | free_irq(channel->irq, &efx->channel[channel->channel]); |
8e730c15 BH |
1532 | fail1: |
1533 | return rc; | |
1534 | } | |
1535 | ||
1536 | void efx_nic_fini_interrupt(struct efx_nic *efx) | |
1537 | { | |
1538 | struct efx_channel *channel; | |
1539 | efx_oword_t reg; | |
1540 | ||
1541 | /* Disable MSI/MSI-X interrupts */ | |
1542 | efx_for_each_channel(channel, efx) { | |
1543 | if (channel->irq) | |
4642610c | 1544 | free_irq(channel->irq, &efx->channel[channel->channel]); |
8e730c15 BH |
1545 | } |
1546 | ||
1547 | /* ACK legacy interrupt */ | |
1548 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) | |
1549 | efx_reado(efx, ®, FR_BZ_INT_ISR0); | |
1550 | else | |
1551 | falcon_irq_ack_a1(efx); | |
1552 | ||
1553 | /* Disable legacy interrupt */ | |
1554 | if (efx->legacy_irq) | |
1555 | free_irq(efx->legacy_irq, efx); | |
1556 | } | |
1557 | ||
1558 | u32 efx_nic_fpga_ver(struct efx_nic *efx) | |
1559 | { | |
1560 | efx_oword_t altera_build; | |
1561 | efx_reado(efx, &altera_build, FR_AZ_ALTERA_BUILD); | |
1562 | return EFX_OWORD_FIELD(altera_build, FRF_AZ_ALTERA_BUILD_VER); | |
1563 | } | |
1564 | ||
1565 | void efx_nic_init_common(struct efx_nic *efx) | |
1566 | { | |
1567 | efx_oword_t temp; | |
1568 | ||
1569 | /* Set positions of descriptor caches in SRAM. */ | |
1570 | EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_TX_DC_BASE_ADR, | |
1571 | efx->type->tx_dc_base / 8); | |
1572 | efx_writeo(efx, &temp, FR_AZ_SRM_TX_DC_CFG); | |
1573 | EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_RX_DC_BASE_ADR, | |
1574 | efx->type->rx_dc_base / 8); | |
1575 | efx_writeo(efx, &temp, FR_AZ_SRM_RX_DC_CFG); | |
1576 | ||
1577 | /* Set TX descriptor cache size. */ | |
1578 | BUILD_BUG_ON(TX_DC_ENTRIES != (8 << TX_DC_ENTRIES_ORDER)); | |
1579 | EFX_POPULATE_OWORD_1(temp, FRF_AZ_TX_DC_SIZE, TX_DC_ENTRIES_ORDER); | |
1580 | efx_writeo(efx, &temp, FR_AZ_TX_DC_CFG); | |
1581 | ||
1582 | /* Set RX descriptor cache size. Set low watermark to size-8, as | |
1583 | * this allows most efficient prefetching. | |
1584 | */ | |
1585 | BUILD_BUG_ON(RX_DC_ENTRIES != (8 << RX_DC_ENTRIES_ORDER)); | |
1586 | EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_SIZE, RX_DC_ENTRIES_ORDER); | |
1587 | efx_writeo(efx, &temp, FR_AZ_RX_DC_CFG); | |
1588 | EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_PF_LWM, RX_DC_ENTRIES - 8); | |
1589 | efx_writeo(efx, &temp, FR_AZ_RX_DC_PF_WM); | |
1590 | ||
1591 | /* Program INT_KER address */ | |
1592 | EFX_POPULATE_OWORD_2(temp, | |
1593 | FRF_AZ_NORM_INT_VEC_DIS_KER, | |
1594 | EFX_INT_MODE_USE_MSI(efx), | |
1595 | FRF_AZ_INT_ADR_KER, efx->irq_status.dma_addr); | |
1596 | efx_writeo(efx, &temp, FR_AZ_INT_ADR_KER); | |
1597 | ||
63695459 SH |
1598 | if (EFX_WORKAROUND_17213(efx) && !EFX_INT_MODE_USE_MSI(efx)) |
1599 | /* Use an interrupt level unused by event queues */ | |
1600 | efx->fatal_irq_level = 0x1f; | |
1601 | else | |
1602 | /* Use a valid MSI-X vector */ | |
1603 | efx->fatal_irq_level = 0; | |
1604 | ||
8e730c15 BH |
1605 | /* Enable all the genuinely fatal interrupts. (They are still |
1606 | * masked by the overall interrupt mask, controlled by | |
1607 | * falcon_interrupts()). | |
1608 | * | |
1609 | * Note: All other fatal interrupts are enabled | |
1610 | */ | |
1611 | EFX_POPULATE_OWORD_3(temp, | |
1612 | FRF_AZ_ILL_ADR_INT_KER_EN, 1, | |
1613 | FRF_AZ_RBUF_OWN_INT_KER_EN, 1, | |
1614 | FRF_AZ_TBUF_OWN_INT_KER_EN, 1); | |
b17424b0 SH |
1615 | if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) |
1616 | EFX_SET_OWORD_FIELD(temp, FRF_CZ_SRAM_PERR_INT_P_KER_EN, 1); | |
8e730c15 BH |
1617 | EFX_INVERT_OWORD(temp); |
1618 | efx_writeo(efx, &temp, FR_AZ_FATAL_INTR_KER); | |
1619 | ||
765c9f46 | 1620 | efx_nic_push_rx_indir_table(efx); |
8e730c15 BH |
1621 | |
1622 | /* Disable the ugly timer-based TX DMA backoff and allow TX DMA to be | |
1623 | * controlled by the RX FIFO fill level. Set arbitration to one pkt/Q. | |
1624 | */ | |
1625 | efx_reado(efx, &temp, FR_AZ_TX_RESERVED); | |
1626 | EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER, 0xfe); | |
1627 | EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER_EN, 1); | |
1628 | EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_ONE_PKT_PER_Q, 1); | |
1629 | EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PUSH_EN, 0); | |
1630 | EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_DIS_NON_IP_EV, 1); | |
1631 | /* Enable SW_EV to inherit in char driver - assume harmless here */ | |
1632 | EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_SOFT_EVT_EN, 1); | |
1633 | /* Prefetch threshold 2 => fetch when descriptor cache half empty */ | |
1634 | EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_THRESHOLD, 2); | |
286d47ba BH |
1635 | /* Disable hardware watchdog which can misfire */ |
1636 | EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_WD_TMR, 0x3fffff); | |
8e730c15 BH |
1637 | /* Squash TX of packets of 16 bytes or less */ |
1638 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) | |
1639 | EFX_SET_OWORD_FIELD(temp, FRF_BZ_TX_FLUSH_MIN_LEN_EN, 1); | |
1640 | efx_writeo(efx, &temp, FR_AZ_TX_RESERVED); | |
1641 | } | |
5b98c1bf BH |
1642 | |
1643 | /* Register dump */ | |
1644 | ||
1645 | #define REGISTER_REVISION_A 1 | |
1646 | #define REGISTER_REVISION_B 2 | |
1647 | #define REGISTER_REVISION_C 3 | |
1648 | #define REGISTER_REVISION_Z 3 /* latest revision */ | |
1649 | ||
1650 | struct efx_nic_reg { | |
1651 | u32 offset:24; | |
1652 | u32 min_revision:2, max_revision:2; | |
1653 | }; | |
1654 | ||
1655 | #define REGISTER(name, min_rev, max_rev) { \ | |
1656 | FR_ ## min_rev ## max_rev ## _ ## name, \ | |
1657 | REGISTER_REVISION_ ## min_rev, REGISTER_REVISION_ ## max_rev \ | |
1658 | } | |
1659 | #define REGISTER_AA(name) REGISTER(name, A, A) | |
1660 | #define REGISTER_AB(name) REGISTER(name, A, B) | |
1661 | #define REGISTER_AZ(name) REGISTER(name, A, Z) | |
1662 | #define REGISTER_BB(name) REGISTER(name, B, B) | |
1663 | #define REGISTER_BZ(name) REGISTER(name, B, Z) | |
1664 | #define REGISTER_CZ(name) REGISTER(name, C, Z) | |
1665 | ||
1666 | static const struct efx_nic_reg efx_nic_regs[] = { | |
1667 | REGISTER_AZ(ADR_REGION), | |
1668 | REGISTER_AZ(INT_EN_KER), | |
1669 | REGISTER_BZ(INT_EN_CHAR), | |
1670 | REGISTER_AZ(INT_ADR_KER), | |
1671 | REGISTER_BZ(INT_ADR_CHAR), | |
1672 | /* INT_ACK_KER is WO */ | |
1673 | /* INT_ISR0 is RC */ | |
1674 | REGISTER_AZ(HW_INIT), | |
1675 | REGISTER_CZ(USR_EV_CFG), | |
1676 | REGISTER_AB(EE_SPI_HCMD), | |
1677 | REGISTER_AB(EE_SPI_HADR), | |
1678 | REGISTER_AB(EE_SPI_HDATA), | |
1679 | REGISTER_AB(EE_BASE_PAGE), | |
1680 | REGISTER_AB(EE_VPD_CFG0), | |
1681 | /* EE_VPD_SW_CNTL and EE_VPD_SW_DATA are not used */ | |
1682 | /* PMBX_DBG_IADDR and PBMX_DBG_IDATA are indirect */ | |
1683 | /* PCIE_CORE_INDIRECT is indirect */ | |
1684 | REGISTER_AB(NIC_STAT), | |
1685 | REGISTER_AB(GPIO_CTL), | |
1686 | REGISTER_AB(GLB_CTL), | |
1687 | /* FATAL_INTR_KER and FATAL_INTR_CHAR are partly RC */ | |
1688 | REGISTER_BZ(DP_CTRL), | |
1689 | REGISTER_AZ(MEM_STAT), | |
1690 | REGISTER_AZ(CS_DEBUG), | |
1691 | REGISTER_AZ(ALTERA_BUILD), | |
1692 | REGISTER_AZ(CSR_SPARE), | |
1693 | REGISTER_AB(PCIE_SD_CTL0123), | |
1694 | REGISTER_AB(PCIE_SD_CTL45), | |
1695 | REGISTER_AB(PCIE_PCS_CTL_STAT), | |
1696 | /* DEBUG_DATA_OUT is not used */ | |
1697 | /* DRV_EV is WO */ | |
1698 | REGISTER_AZ(EVQ_CTL), | |
1699 | REGISTER_AZ(EVQ_CNT1), | |
1700 | REGISTER_AZ(EVQ_CNT2), | |
1701 | REGISTER_AZ(BUF_TBL_CFG), | |
1702 | REGISTER_AZ(SRM_RX_DC_CFG), | |
1703 | REGISTER_AZ(SRM_TX_DC_CFG), | |
1704 | REGISTER_AZ(SRM_CFG), | |
1705 | /* BUF_TBL_UPD is WO */ | |
1706 | REGISTER_AZ(SRM_UPD_EVQ), | |
1707 | REGISTER_AZ(SRAM_PARITY), | |
1708 | REGISTER_AZ(RX_CFG), | |
1709 | REGISTER_BZ(RX_FILTER_CTL), | |
1710 | /* RX_FLUSH_DESCQ is WO */ | |
1711 | REGISTER_AZ(RX_DC_CFG), | |
1712 | REGISTER_AZ(RX_DC_PF_WM), | |
1713 | REGISTER_BZ(RX_RSS_TKEY), | |
1714 | /* RX_NODESC_DROP is RC */ | |
1715 | REGISTER_AA(RX_SELF_RST), | |
1716 | /* RX_DEBUG, RX_PUSH_DROP are not used */ | |
1717 | REGISTER_CZ(RX_RSS_IPV6_REG1), | |
1718 | REGISTER_CZ(RX_RSS_IPV6_REG2), | |
1719 | REGISTER_CZ(RX_RSS_IPV6_REG3), | |
1720 | /* TX_FLUSH_DESCQ is WO */ | |
1721 | REGISTER_AZ(TX_DC_CFG), | |
1722 | REGISTER_AA(TX_CHKSM_CFG), | |
1723 | REGISTER_AZ(TX_CFG), | |
1724 | /* TX_PUSH_DROP is not used */ | |
1725 | REGISTER_AZ(TX_RESERVED), | |
1726 | REGISTER_BZ(TX_PACE), | |
1727 | /* TX_PACE_DROP_QID is RC */ | |
1728 | REGISTER_BB(TX_VLAN), | |
1729 | REGISTER_BZ(TX_IPFIL_PORTEN), | |
1730 | REGISTER_AB(MD_TXD), | |
1731 | REGISTER_AB(MD_RXD), | |
1732 | REGISTER_AB(MD_CS), | |
1733 | REGISTER_AB(MD_PHY_ADR), | |
1734 | REGISTER_AB(MD_ID), | |
1735 | /* MD_STAT is RC */ | |
1736 | REGISTER_AB(MAC_STAT_DMA), | |
1737 | REGISTER_AB(MAC_CTRL), | |
1738 | REGISTER_BB(GEN_MODE), | |
1739 | REGISTER_AB(MAC_MC_HASH_REG0), | |
1740 | REGISTER_AB(MAC_MC_HASH_REG1), | |
1741 | REGISTER_AB(GM_CFG1), | |
1742 | REGISTER_AB(GM_CFG2), | |
1743 | /* GM_IPG and GM_HD are not used */ | |
1744 | REGISTER_AB(GM_MAX_FLEN), | |
1745 | /* GM_TEST is not used */ | |
1746 | REGISTER_AB(GM_ADR1), | |
1747 | REGISTER_AB(GM_ADR2), | |
1748 | REGISTER_AB(GMF_CFG0), | |
1749 | REGISTER_AB(GMF_CFG1), | |
1750 | REGISTER_AB(GMF_CFG2), | |
1751 | REGISTER_AB(GMF_CFG3), | |
1752 | REGISTER_AB(GMF_CFG4), | |
1753 | REGISTER_AB(GMF_CFG5), | |
1754 | REGISTER_BB(TX_SRC_MAC_CTL), | |
1755 | REGISTER_AB(XM_ADR_LO), | |
1756 | REGISTER_AB(XM_ADR_HI), | |
1757 | REGISTER_AB(XM_GLB_CFG), | |
1758 | REGISTER_AB(XM_TX_CFG), | |
1759 | REGISTER_AB(XM_RX_CFG), | |
1760 | REGISTER_AB(XM_MGT_INT_MASK), | |
1761 | REGISTER_AB(XM_FC), | |
1762 | REGISTER_AB(XM_PAUSE_TIME), | |
1763 | REGISTER_AB(XM_TX_PARAM), | |
1764 | REGISTER_AB(XM_RX_PARAM), | |
1765 | /* XM_MGT_INT_MSK (note no 'A') is RC */ | |
1766 | REGISTER_AB(XX_PWR_RST), | |
1767 | REGISTER_AB(XX_SD_CTL), | |
1768 | REGISTER_AB(XX_TXDRV_CTL), | |
1769 | /* XX_PRBS_CTL, XX_PRBS_CHK and XX_PRBS_ERR are not used */ | |
1770 | /* XX_CORE_STAT is partly RC */ | |
1771 | }; | |
1772 | ||
1773 | struct efx_nic_reg_table { | |
1774 | u32 offset:24; | |
1775 | u32 min_revision:2, max_revision:2; | |
1776 | u32 step:6, rows:21; | |
1777 | }; | |
1778 | ||
1779 | #define REGISTER_TABLE_DIMENSIONS(_, offset, min_rev, max_rev, step, rows) { \ | |
1780 | offset, \ | |
1781 | REGISTER_REVISION_ ## min_rev, REGISTER_REVISION_ ## max_rev, \ | |
1782 | step, rows \ | |
1783 | } | |
1784 | #define REGISTER_TABLE(name, min_rev, max_rev) \ | |
1785 | REGISTER_TABLE_DIMENSIONS( \ | |
1786 | name, FR_ ## min_rev ## max_rev ## _ ## name, \ | |
1787 | min_rev, max_rev, \ | |
1788 | FR_ ## min_rev ## max_rev ## _ ## name ## _STEP, \ | |
1789 | FR_ ## min_rev ## max_rev ## _ ## name ## _ROWS) | |
1790 | #define REGISTER_TABLE_AA(name) REGISTER_TABLE(name, A, A) | |
1791 | #define REGISTER_TABLE_AZ(name) REGISTER_TABLE(name, A, Z) | |
1792 | #define REGISTER_TABLE_BB(name) REGISTER_TABLE(name, B, B) | |
1793 | #define REGISTER_TABLE_BZ(name) REGISTER_TABLE(name, B, Z) | |
1794 | #define REGISTER_TABLE_BB_CZ(name) \ | |
1795 | REGISTER_TABLE_DIMENSIONS(name, FR_BZ_ ## name, B, B, \ | |
1796 | FR_BZ_ ## name ## _STEP, \ | |
1797 | FR_BB_ ## name ## _ROWS), \ | |
1798 | REGISTER_TABLE_DIMENSIONS(name, FR_BZ_ ## name, C, Z, \ | |
1799 | FR_BZ_ ## name ## _STEP, \ | |
1800 | FR_CZ_ ## name ## _ROWS) | |
1801 | #define REGISTER_TABLE_CZ(name) REGISTER_TABLE(name, C, Z) | |
1802 | ||
1803 | static const struct efx_nic_reg_table efx_nic_reg_tables[] = { | |
1804 | /* DRIVER is not used */ | |
1805 | /* EVQ_RPTR, TIMER_COMMAND, USR_EV and {RX,TX}_DESC_UPD are WO */ | |
1806 | REGISTER_TABLE_BB(TX_IPFIL_TBL), | |
1807 | REGISTER_TABLE_BB(TX_SRC_MAC_TBL), | |
1808 | REGISTER_TABLE_AA(RX_DESC_PTR_TBL_KER), | |
1809 | REGISTER_TABLE_BB_CZ(RX_DESC_PTR_TBL), | |
1810 | REGISTER_TABLE_AA(TX_DESC_PTR_TBL_KER), | |
1811 | REGISTER_TABLE_BB_CZ(TX_DESC_PTR_TBL), | |
1812 | REGISTER_TABLE_AA(EVQ_PTR_TBL_KER), | |
1813 | REGISTER_TABLE_BB_CZ(EVQ_PTR_TBL), | |
75abc51c | 1814 | /* We can't reasonably read all of the buffer table (up to 8MB!). |
5b98c1bf BH |
1815 | * However this driver will only use a few entries. Reading |
1816 | * 1K entries allows for some expansion of queue count and | |
1817 | * size before we need to change the version. */ | |
1818 | REGISTER_TABLE_DIMENSIONS(BUF_FULL_TBL_KER, FR_AA_BUF_FULL_TBL_KER, | |
1819 | A, A, 8, 1024), | |
1820 | REGISTER_TABLE_DIMENSIONS(BUF_FULL_TBL, FR_BZ_BUF_FULL_TBL, | |
1821 | B, Z, 8, 1024), | |
5b98c1bf BH |
1822 | REGISTER_TABLE_CZ(RX_MAC_FILTER_TBL0), |
1823 | REGISTER_TABLE_BB_CZ(TIMER_TBL), | |
1824 | REGISTER_TABLE_BB_CZ(TX_PACE_TBL), | |
1825 | REGISTER_TABLE_BZ(RX_INDIRECTION_TBL), | |
1826 | /* TX_FILTER_TBL0 is huge and not used by this driver */ | |
1827 | REGISTER_TABLE_CZ(TX_MAC_FILTER_TBL0), | |
1828 | REGISTER_TABLE_CZ(MC_TREG_SMEM), | |
1829 | /* MSIX_PBA_TABLE is not mapped */ | |
1830 | /* SRM_DBG is not mapped (and is redundant with BUF_FLL_TBL) */ | |
75abc51c | 1831 | REGISTER_TABLE_BZ(RX_FILTER_TBL0), |
5b98c1bf BH |
1832 | }; |
1833 | ||
1834 | size_t efx_nic_get_regs_len(struct efx_nic *efx) | |
1835 | { | |
1836 | const struct efx_nic_reg *reg; | |
1837 | const struct efx_nic_reg_table *table; | |
1838 | size_t len = 0; | |
1839 | ||
1840 | for (reg = efx_nic_regs; | |
1841 | reg < efx_nic_regs + ARRAY_SIZE(efx_nic_regs); | |
1842 | reg++) | |
1843 | if (efx->type->revision >= reg->min_revision && | |
1844 | efx->type->revision <= reg->max_revision) | |
1845 | len += sizeof(efx_oword_t); | |
1846 | ||
1847 | for (table = efx_nic_reg_tables; | |
1848 | table < efx_nic_reg_tables + ARRAY_SIZE(efx_nic_reg_tables); | |
1849 | table++) | |
1850 | if (efx->type->revision >= table->min_revision && | |
1851 | efx->type->revision <= table->max_revision) | |
1852 | len += table->rows * min_t(size_t, table->step, 16); | |
1853 | ||
1854 | return len; | |
1855 | } | |
1856 | ||
1857 | void efx_nic_get_regs(struct efx_nic *efx, void *buf) | |
1858 | { | |
1859 | const struct efx_nic_reg *reg; | |
1860 | const struct efx_nic_reg_table *table; | |
1861 | ||
1862 | for (reg = efx_nic_regs; | |
1863 | reg < efx_nic_regs + ARRAY_SIZE(efx_nic_regs); | |
1864 | reg++) { | |
1865 | if (efx->type->revision >= reg->min_revision && | |
1866 | efx->type->revision <= reg->max_revision) { | |
1867 | efx_reado(efx, (efx_oword_t *)buf, reg->offset); | |
1868 | buf += sizeof(efx_oword_t); | |
1869 | } | |
1870 | } | |
1871 | ||
1872 | for (table = efx_nic_reg_tables; | |
1873 | table < efx_nic_reg_tables + ARRAY_SIZE(efx_nic_reg_tables); | |
1874 | table++) { | |
1875 | size_t size, i; | |
1876 | ||
1877 | if (!(efx->type->revision >= table->min_revision && | |
1878 | efx->type->revision <= table->max_revision)) | |
1879 | continue; | |
1880 | ||
1881 | size = min_t(size_t, table->step, 16); | |
1882 | ||
1883 | for (i = 0; i < table->rows; i++) { | |
1884 | switch (table->step) { | |
1885 | case 4: /* 32-bit register or SRAM */ | |
1886 | efx_readd_table(efx, buf, table->offset, i); | |
1887 | break; | |
1888 | case 8: /* 64-bit SRAM */ | |
1889 | efx_sram_readq(efx, | |
1890 | efx->membase + table->offset, | |
1891 | buf, i); | |
1892 | break; | |
1893 | case 16: /* 128-bit register */ | |
1894 | efx_reado_table(efx, buf, table->offset, i); | |
1895 | break; | |
1896 | case 32: /* 128-bit register, interleaved */ | |
1897 | efx_reado_table(efx, buf, table->offset, 2 * i); | |
1898 | break; | |
1899 | default: | |
1900 | WARN_ON(1); | |
1901 | return; | |
1902 | } | |
1903 | buf += size; | |
1904 | } | |
1905 | } | |
1906 | } |