18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/**************************************************************************** 38c2ecf20Sopenharmony_ci * Driver for Solarflare network controllers and boards 48c2ecf20Sopenharmony_ci * Copyright 2005-2006 Fen Systems Ltd. 58c2ecf20Sopenharmony_ci * Copyright 2006-2013 Solarflare Communications Inc. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/bitops.h> 98c2ecf20Sopenharmony_ci#include <linux/delay.h> 108c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 118c2ecf20Sopenharmony_ci#include <linux/pci.h> 128c2ecf20Sopenharmony_ci#include <linux/module.h> 138c2ecf20Sopenharmony_ci#include <linux/seq_file.h> 148c2ecf20Sopenharmony_ci#include <linux/crc32.h> 158c2ecf20Sopenharmony_ci#include "net_driver.h" 168c2ecf20Sopenharmony_ci#include "bitfield.h" 178c2ecf20Sopenharmony_ci#include "efx.h" 188c2ecf20Sopenharmony_ci#include "rx_common.h" 198c2ecf20Sopenharmony_ci#include "nic.h" 208c2ecf20Sopenharmony_ci#include "farch_regs.h" 218c2ecf20Sopenharmony_ci#include "sriov.h" 228c2ecf20Sopenharmony_ci#include "siena_sriov.h" 238c2ecf20Sopenharmony_ci#include "io.h" 248c2ecf20Sopenharmony_ci#include "workarounds.h" 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci/* Falcon-architecture (SFC9000-family) support */ 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/************************************************************************** 298c2ecf20Sopenharmony_ci * 308c2ecf20Sopenharmony_ci * Configurable values 318c2ecf20Sopenharmony_ci * 328c2ecf20Sopenharmony_ci ************************************************************************** 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* This is set to 16 for a good reason. In summary, if larger than 368c2ecf20Sopenharmony_ci * 16, the descriptor cache holds more than a default socket 378c2ecf20Sopenharmony_ci * buffer's worth of packets (for UDP we can only have at most one 388c2ecf20Sopenharmony_ci * socket buffer's worth outstanding). This combined with the fact 398c2ecf20Sopenharmony_ci * that we only get 1 TX event per descriptor cache means the NIC 408c2ecf20Sopenharmony_ci * goes idle. 418c2ecf20Sopenharmony_ci */ 428c2ecf20Sopenharmony_ci#define TX_DC_ENTRIES 16 438c2ecf20Sopenharmony_ci#define TX_DC_ENTRIES_ORDER 1 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define RX_DC_ENTRIES 64 468c2ecf20Sopenharmony_ci#define RX_DC_ENTRIES_ORDER 3 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* If EFX_MAX_INT_ERRORS internal errors occur within 498c2ecf20Sopenharmony_ci * EFX_INT_ERROR_EXPIRE seconds, we consider the NIC broken and 508c2ecf20Sopenharmony_ci * disable it. 518c2ecf20Sopenharmony_ci */ 528c2ecf20Sopenharmony_ci#define EFX_INT_ERROR_EXPIRE 3600 538c2ecf20Sopenharmony_ci#define EFX_MAX_INT_ERRORS 5 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci/* Depth of RX flush request fifo */ 568c2ecf20Sopenharmony_ci#define EFX_RX_FLUSH_COUNT 4 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* Driver generated events */ 598c2ecf20Sopenharmony_ci#define _EFX_CHANNEL_MAGIC_TEST 0x000101 608c2ecf20Sopenharmony_ci#define _EFX_CHANNEL_MAGIC_FILL 0x000102 618c2ecf20Sopenharmony_ci#define _EFX_CHANNEL_MAGIC_RX_DRAIN 0x000103 628c2ecf20Sopenharmony_ci#define _EFX_CHANNEL_MAGIC_TX_DRAIN 0x000104 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci#define _EFX_CHANNEL_MAGIC(_code, _data) ((_code) << 8 | (_data)) 658c2ecf20Sopenharmony_ci#define _EFX_CHANNEL_MAGIC_CODE(_magic) ((_magic) >> 8) 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#define EFX_CHANNEL_MAGIC_TEST(_channel) \ 688c2ecf20Sopenharmony_ci _EFX_CHANNEL_MAGIC(_EFX_CHANNEL_MAGIC_TEST, (_channel)->channel) 698c2ecf20Sopenharmony_ci#define EFX_CHANNEL_MAGIC_FILL(_rx_queue) \ 708c2ecf20Sopenharmony_ci _EFX_CHANNEL_MAGIC(_EFX_CHANNEL_MAGIC_FILL, \ 718c2ecf20Sopenharmony_ci efx_rx_queue_index(_rx_queue)) 728c2ecf20Sopenharmony_ci#define EFX_CHANNEL_MAGIC_RX_DRAIN(_rx_queue) \ 738c2ecf20Sopenharmony_ci _EFX_CHANNEL_MAGIC(_EFX_CHANNEL_MAGIC_RX_DRAIN, \ 748c2ecf20Sopenharmony_ci efx_rx_queue_index(_rx_queue)) 758c2ecf20Sopenharmony_ci#define EFX_CHANNEL_MAGIC_TX_DRAIN(_tx_queue) \ 768c2ecf20Sopenharmony_ci _EFX_CHANNEL_MAGIC(_EFX_CHANNEL_MAGIC_TX_DRAIN, \ 778c2ecf20Sopenharmony_ci (_tx_queue)->queue) 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_cistatic void efx_farch_magic_event(struct efx_channel *channel, u32 magic); 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci/************************************************************************** 828c2ecf20Sopenharmony_ci * 838c2ecf20Sopenharmony_ci * Hardware access 848c2ecf20Sopenharmony_ci * 858c2ecf20Sopenharmony_ci **************************************************************************/ 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_cistatic inline void efx_write_buf_tbl(struct efx_nic *efx, efx_qword_t *value, 888c2ecf20Sopenharmony_ci unsigned int index) 898c2ecf20Sopenharmony_ci{ 908c2ecf20Sopenharmony_ci efx_sram_writeq(efx, efx->membase + efx->type->buf_tbl_base, 918c2ecf20Sopenharmony_ci value, index); 928c2ecf20Sopenharmony_ci} 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_cistatic bool efx_masked_compare_oword(const efx_oword_t *a, const efx_oword_t *b, 958c2ecf20Sopenharmony_ci const efx_oword_t *mask) 968c2ecf20Sopenharmony_ci{ 978c2ecf20Sopenharmony_ci return ((a->u64[0] ^ b->u64[0]) & mask->u64[0]) || 988c2ecf20Sopenharmony_ci ((a->u64[1] ^ b->u64[1]) & mask->u64[1]); 998c2ecf20Sopenharmony_ci} 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ciint efx_farch_test_registers(struct efx_nic *efx, 1028c2ecf20Sopenharmony_ci const struct efx_farch_register_test *regs, 1038c2ecf20Sopenharmony_ci size_t n_regs) 1048c2ecf20Sopenharmony_ci{ 1058c2ecf20Sopenharmony_ci unsigned address = 0; 1068c2ecf20Sopenharmony_ci int i, j; 1078c2ecf20Sopenharmony_ci efx_oword_t mask, imask, original, reg, buf; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci for (i = 0; i < n_regs; ++i) { 1108c2ecf20Sopenharmony_ci address = regs[i].address; 1118c2ecf20Sopenharmony_ci mask = imask = regs[i].mask; 1128c2ecf20Sopenharmony_ci EFX_INVERT_OWORD(imask); 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci efx_reado(efx, &original, address); 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci /* bit sweep on and off */ 1178c2ecf20Sopenharmony_ci for (j = 0; j < 128; j++) { 1188c2ecf20Sopenharmony_ci if (!EFX_EXTRACT_OWORD32(mask, j, j)) 1198c2ecf20Sopenharmony_ci continue; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci /* Test this testable bit can be set in isolation */ 1228c2ecf20Sopenharmony_ci EFX_AND_OWORD(reg, original, mask); 1238c2ecf20Sopenharmony_ci EFX_SET_OWORD32(reg, j, j, 1); 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci efx_writeo(efx, ®, address); 1268c2ecf20Sopenharmony_ci efx_reado(efx, &buf, address); 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci if (efx_masked_compare_oword(®, &buf, &mask)) 1298c2ecf20Sopenharmony_ci goto fail; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci /* Test this testable bit can be cleared in isolation */ 1328c2ecf20Sopenharmony_ci EFX_OR_OWORD(reg, original, mask); 1338c2ecf20Sopenharmony_ci EFX_SET_OWORD32(reg, j, j, 0); 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci efx_writeo(efx, ®, address); 1368c2ecf20Sopenharmony_ci efx_reado(efx, &buf, address); 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci if (efx_masked_compare_oword(®, &buf, &mask)) 1398c2ecf20Sopenharmony_ci goto fail; 1408c2ecf20Sopenharmony_ci } 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci efx_writeo(efx, &original, address); 1438c2ecf20Sopenharmony_ci } 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci return 0; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_cifail: 1488c2ecf20Sopenharmony_ci netif_err(efx, hw, efx->net_dev, 1498c2ecf20Sopenharmony_ci "wrote "EFX_OWORD_FMT" read "EFX_OWORD_FMT 1508c2ecf20Sopenharmony_ci " at address 0x%x mask "EFX_OWORD_FMT"\n", EFX_OWORD_VAL(reg), 1518c2ecf20Sopenharmony_ci EFX_OWORD_VAL(buf), address, EFX_OWORD_VAL(mask)); 1528c2ecf20Sopenharmony_ci return -EIO; 1538c2ecf20Sopenharmony_ci} 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci/************************************************************************** 1568c2ecf20Sopenharmony_ci * 1578c2ecf20Sopenharmony_ci * Special buffer handling 1588c2ecf20Sopenharmony_ci * Special buffers are used for event queues and the TX and RX 1598c2ecf20Sopenharmony_ci * descriptor rings. 1608c2ecf20Sopenharmony_ci * 1618c2ecf20Sopenharmony_ci *************************************************************************/ 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci/* 1648c2ecf20Sopenharmony_ci * Initialise a special buffer 1658c2ecf20Sopenharmony_ci * 1668c2ecf20Sopenharmony_ci * This will define a buffer (previously allocated via 1678c2ecf20Sopenharmony_ci * efx_alloc_special_buffer()) in the buffer table, allowing 1688c2ecf20Sopenharmony_ci * it to be used for event queues, descriptor rings etc. 1698c2ecf20Sopenharmony_ci */ 1708c2ecf20Sopenharmony_cistatic void 1718c2ecf20Sopenharmony_ciefx_init_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer) 1728c2ecf20Sopenharmony_ci{ 1738c2ecf20Sopenharmony_ci efx_qword_t buf_desc; 1748c2ecf20Sopenharmony_ci unsigned int index; 1758c2ecf20Sopenharmony_ci dma_addr_t dma_addr; 1768c2ecf20Sopenharmony_ci int i; 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci EFX_WARN_ON_PARANOID(!buffer->buf.addr); 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci /* Write buffer descriptors to NIC */ 1818c2ecf20Sopenharmony_ci for (i = 0; i < buffer->entries; i++) { 1828c2ecf20Sopenharmony_ci index = buffer->index + i; 1838c2ecf20Sopenharmony_ci dma_addr = buffer->buf.dma_addr + (i * EFX_BUF_SIZE); 1848c2ecf20Sopenharmony_ci netif_dbg(efx, probe, efx->net_dev, 1858c2ecf20Sopenharmony_ci "mapping special buffer %d at %llx\n", 1868c2ecf20Sopenharmony_ci index, (unsigned long long)dma_addr); 1878c2ecf20Sopenharmony_ci EFX_POPULATE_QWORD_3(buf_desc, 1888c2ecf20Sopenharmony_ci FRF_AZ_BUF_ADR_REGION, 0, 1898c2ecf20Sopenharmony_ci FRF_AZ_BUF_ADR_FBUF, dma_addr >> 12, 1908c2ecf20Sopenharmony_ci FRF_AZ_BUF_OWNER_ID_FBUF, 0); 1918c2ecf20Sopenharmony_ci efx_write_buf_tbl(efx, &buf_desc, index); 1928c2ecf20Sopenharmony_ci } 1938c2ecf20Sopenharmony_ci} 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci/* Unmaps a buffer and clears the buffer table entries */ 1968c2ecf20Sopenharmony_cistatic void 1978c2ecf20Sopenharmony_ciefx_fini_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer) 1988c2ecf20Sopenharmony_ci{ 1998c2ecf20Sopenharmony_ci efx_oword_t buf_tbl_upd; 2008c2ecf20Sopenharmony_ci unsigned int start = buffer->index; 2018c2ecf20Sopenharmony_ci unsigned int end = (buffer->index + buffer->entries - 1); 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci if (!buffer->entries) 2048c2ecf20Sopenharmony_ci return; 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci netif_dbg(efx, hw, efx->net_dev, "unmapping special buffers %d-%d\n", 2078c2ecf20Sopenharmony_ci buffer->index, buffer->index + buffer->entries - 1); 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_4(buf_tbl_upd, 2108c2ecf20Sopenharmony_ci FRF_AZ_BUF_UPD_CMD, 0, 2118c2ecf20Sopenharmony_ci FRF_AZ_BUF_CLR_CMD, 1, 2128c2ecf20Sopenharmony_ci FRF_AZ_BUF_CLR_END_ID, end, 2138c2ecf20Sopenharmony_ci FRF_AZ_BUF_CLR_START_ID, start); 2148c2ecf20Sopenharmony_ci efx_writeo(efx, &buf_tbl_upd, FR_AZ_BUF_TBL_UPD); 2158c2ecf20Sopenharmony_ci} 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci/* 2188c2ecf20Sopenharmony_ci * Allocate a new special buffer 2198c2ecf20Sopenharmony_ci * 2208c2ecf20Sopenharmony_ci * This allocates memory for a new buffer, clears it and allocates a 2218c2ecf20Sopenharmony_ci * new buffer ID range. It does not write into the buffer table. 2228c2ecf20Sopenharmony_ci * 2238c2ecf20Sopenharmony_ci * This call will allocate 4KB buffers, since 8KB buffers can't be 2248c2ecf20Sopenharmony_ci * used for event queues and descriptor rings. 2258c2ecf20Sopenharmony_ci */ 2268c2ecf20Sopenharmony_cistatic int efx_alloc_special_buffer(struct efx_nic *efx, 2278c2ecf20Sopenharmony_ci struct efx_special_buffer *buffer, 2288c2ecf20Sopenharmony_ci unsigned int len) 2298c2ecf20Sopenharmony_ci{ 2308c2ecf20Sopenharmony_ci#ifdef CONFIG_SFC_SRIOV 2318c2ecf20Sopenharmony_ci struct siena_nic_data *nic_data = efx->nic_data; 2328c2ecf20Sopenharmony_ci#endif 2338c2ecf20Sopenharmony_ci len = ALIGN(len, EFX_BUF_SIZE); 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci if (efx_nic_alloc_buffer(efx, &buffer->buf, len, GFP_KERNEL)) 2368c2ecf20Sopenharmony_ci return -ENOMEM; 2378c2ecf20Sopenharmony_ci buffer->entries = len / EFX_BUF_SIZE; 2388c2ecf20Sopenharmony_ci BUG_ON(buffer->buf.dma_addr & (EFX_BUF_SIZE - 1)); 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci /* Select new buffer ID */ 2418c2ecf20Sopenharmony_ci buffer->index = efx->next_buffer_table; 2428c2ecf20Sopenharmony_ci efx->next_buffer_table += buffer->entries; 2438c2ecf20Sopenharmony_ci#ifdef CONFIG_SFC_SRIOV 2448c2ecf20Sopenharmony_ci BUG_ON(efx_siena_sriov_enabled(efx) && 2458c2ecf20Sopenharmony_ci nic_data->vf_buftbl_base < efx->next_buffer_table); 2468c2ecf20Sopenharmony_ci#endif 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci netif_dbg(efx, probe, efx->net_dev, 2498c2ecf20Sopenharmony_ci "allocating special buffers %d-%d at %llx+%x " 2508c2ecf20Sopenharmony_ci "(virt %p phys %llx)\n", buffer->index, 2518c2ecf20Sopenharmony_ci buffer->index + buffer->entries - 1, 2528c2ecf20Sopenharmony_ci (u64)buffer->buf.dma_addr, len, 2538c2ecf20Sopenharmony_ci buffer->buf.addr, (u64)virt_to_phys(buffer->buf.addr)); 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci return 0; 2568c2ecf20Sopenharmony_ci} 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_cistatic void 2598c2ecf20Sopenharmony_ciefx_free_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer) 2608c2ecf20Sopenharmony_ci{ 2618c2ecf20Sopenharmony_ci if (!buffer->buf.addr) 2628c2ecf20Sopenharmony_ci return; 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci netif_dbg(efx, hw, efx->net_dev, 2658c2ecf20Sopenharmony_ci "deallocating special buffers %d-%d at %llx+%x " 2668c2ecf20Sopenharmony_ci "(virt %p phys %llx)\n", buffer->index, 2678c2ecf20Sopenharmony_ci buffer->index + buffer->entries - 1, 2688c2ecf20Sopenharmony_ci (u64)buffer->buf.dma_addr, buffer->buf.len, 2698c2ecf20Sopenharmony_ci buffer->buf.addr, (u64)virt_to_phys(buffer->buf.addr)); 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci efx_nic_free_buffer(efx, &buffer->buf); 2728c2ecf20Sopenharmony_ci buffer->entries = 0; 2738c2ecf20Sopenharmony_ci} 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci/************************************************************************** 2768c2ecf20Sopenharmony_ci * 2778c2ecf20Sopenharmony_ci * TX path 2788c2ecf20Sopenharmony_ci * 2798c2ecf20Sopenharmony_ci **************************************************************************/ 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */ 2828c2ecf20Sopenharmony_cistatic inline void efx_farch_notify_tx_desc(struct efx_tx_queue *tx_queue) 2838c2ecf20Sopenharmony_ci{ 2848c2ecf20Sopenharmony_ci unsigned write_ptr; 2858c2ecf20Sopenharmony_ci efx_dword_t reg; 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci write_ptr = tx_queue->write_count & tx_queue->ptr_mask; 2888c2ecf20Sopenharmony_ci EFX_POPULATE_DWORD_1(reg, FRF_AZ_TX_DESC_WPTR_DWORD, write_ptr); 2898c2ecf20Sopenharmony_ci efx_writed_page(tx_queue->efx, ®, 2908c2ecf20Sopenharmony_ci FR_AZ_TX_DESC_UPD_DWORD_P0, tx_queue->queue); 2918c2ecf20Sopenharmony_ci} 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci/* Write pointer and first descriptor for TX descriptor ring */ 2948c2ecf20Sopenharmony_cistatic inline void efx_farch_push_tx_desc(struct efx_tx_queue *tx_queue, 2958c2ecf20Sopenharmony_ci const efx_qword_t *txd) 2968c2ecf20Sopenharmony_ci{ 2978c2ecf20Sopenharmony_ci unsigned write_ptr; 2988c2ecf20Sopenharmony_ci efx_oword_t reg; 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci BUILD_BUG_ON(FRF_AZ_TX_DESC_LBN != 0); 3018c2ecf20Sopenharmony_ci BUILD_BUG_ON(FR_AA_TX_DESC_UPD_KER != FR_BZ_TX_DESC_UPD_P0); 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci write_ptr = tx_queue->write_count & tx_queue->ptr_mask; 3048c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_2(reg, FRF_AZ_TX_DESC_PUSH_CMD, true, 3058c2ecf20Sopenharmony_ci FRF_AZ_TX_DESC_WPTR, write_ptr); 3068c2ecf20Sopenharmony_ci reg.qword[0] = *txd; 3078c2ecf20Sopenharmony_ci efx_writeo_page(tx_queue->efx, ®, 3088c2ecf20Sopenharmony_ci FR_BZ_TX_DESC_UPD_P0, tx_queue->queue); 3098c2ecf20Sopenharmony_ci} 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci/* For each entry inserted into the software descriptor ring, create a 3138c2ecf20Sopenharmony_ci * descriptor in the hardware TX descriptor ring (in host memory), and 3148c2ecf20Sopenharmony_ci * write a doorbell. 3158c2ecf20Sopenharmony_ci */ 3168c2ecf20Sopenharmony_civoid efx_farch_tx_write(struct efx_tx_queue *tx_queue) 3178c2ecf20Sopenharmony_ci{ 3188c2ecf20Sopenharmony_ci struct efx_tx_buffer *buffer; 3198c2ecf20Sopenharmony_ci efx_qword_t *txd; 3208c2ecf20Sopenharmony_ci unsigned write_ptr; 3218c2ecf20Sopenharmony_ci unsigned old_write_count = tx_queue->write_count; 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci tx_queue->xmit_pending = false; 3248c2ecf20Sopenharmony_ci if (unlikely(tx_queue->write_count == tx_queue->insert_count)) 3258c2ecf20Sopenharmony_ci return; 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci do { 3288c2ecf20Sopenharmony_ci write_ptr = tx_queue->write_count & tx_queue->ptr_mask; 3298c2ecf20Sopenharmony_ci buffer = &tx_queue->buffer[write_ptr]; 3308c2ecf20Sopenharmony_ci txd = efx_tx_desc(tx_queue, write_ptr); 3318c2ecf20Sopenharmony_ci ++tx_queue->write_count; 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci EFX_WARN_ON_ONCE_PARANOID(buffer->flags & EFX_TX_BUF_OPTION); 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci /* Create TX descriptor ring entry */ 3368c2ecf20Sopenharmony_ci BUILD_BUG_ON(EFX_TX_BUF_CONT != 1); 3378c2ecf20Sopenharmony_ci EFX_POPULATE_QWORD_4(*txd, 3388c2ecf20Sopenharmony_ci FSF_AZ_TX_KER_CONT, 3398c2ecf20Sopenharmony_ci buffer->flags & EFX_TX_BUF_CONT, 3408c2ecf20Sopenharmony_ci FSF_AZ_TX_KER_BYTE_COUNT, buffer->len, 3418c2ecf20Sopenharmony_ci FSF_AZ_TX_KER_BUF_REGION, 0, 3428c2ecf20Sopenharmony_ci FSF_AZ_TX_KER_BUF_ADDR, buffer->dma_addr); 3438c2ecf20Sopenharmony_ci } while (tx_queue->write_count != tx_queue->insert_count); 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci wmb(); /* Ensure descriptors are written before they are fetched */ 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) { 3488c2ecf20Sopenharmony_ci txd = efx_tx_desc(tx_queue, 3498c2ecf20Sopenharmony_ci old_write_count & tx_queue->ptr_mask); 3508c2ecf20Sopenharmony_ci efx_farch_push_tx_desc(tx_queue, txd); 3518c2ecf20Sopenharmony_ci ++tx_queue->pushes; 3528c2ecf20Sopenharmony_ci } else { 3538c2ecf20Sopenharmony_ci efx_farch_notify_tx_desc(tx_queue); 3548c2ecf20Sopenharmony_ci } 3558c2ecf20Sopenharmony_ci} 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ciunsigned int efx_farch_tx_limit_len(struct efx_tx_queue *tx_queue, 3588c2ecf20Sopenharmony_ci dma_addr_t dma_addr, unsigned int len) 3598c2ecf20Sopenharmony_ci{ 3608c2ecf20Sopenharmony_ci /* Don't cross 4K boundaries with descriptors. */ 3618c2ecf20Sopenharmony_ci unsigned int limit = (~dma_addr & (EFX_PAGE_SIZE - 1)) + 1; 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci len = min(limit, len); 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci return len; 3668c2ecf20Sopenharmony_ci} 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci/* Allocate hardware resources for a TX queue */ 3708c2ecf20Sopenharmony_ciint efx_farch_tx_probe(struct efx_tx_queue *tx_queue) 3718c2ecf20Sopenharmony_ci{ 3728c2ecf20Sopenharmony_ci struct efx_nic *efx = tx_queue->efx; 3738c2ecf20Sopenharmony_ci unsigned entries; 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci tx_queue->type = ((tx_queue->label & 1) ? EFX_TXQ_TYPE_OUTER_CSUM : 0) | 3768c2ecf20Sopenharmony_ci ((tx_queue->label & 2) ? EFX_TXQ_TYPE_HIGHPRI : 0); 3778c2ecf20Sopenharmony_ci entries = tx_queue->ptr_mask + 1; 3788c2ecf20Sopenharmony_ci return efx_alloc_special_buffer(efx, &tx_queue->txd, 3798c2ecf20Sopenharmony_ci entries * sizeof(efx_qword_t)); 3808c2ecf20Sopenharmony_ci} 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_civoid efx_farch_tx_init(struct efx_tx_queue *tx_queue) 3838c2ecf20Sopenharmony_ci{ 3848c2ecf20Sopenharmony_ci int csum = tx_queue->type & EFX_TXQ_TYPE_OUTER_CSUM; 3858c2ecf20Sopenharmony_ci struct efx_nic *efx = tx_queue->efx; 3868c2ecf20Sopenharmony_ci efx_oword_t reg; 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci /* Pin TX descriptor ring */ 3898c2ecf20Sopenharmony_ci efx_init_special_buffer(efx, &tx_queue->txd); 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci /* Push TX descriptor ring to card */ 3928c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_10(reg, 3938c2ecf20Sopenharmony_ci FRF_AZ_TX_DESCQ_EN, 1, 3948c2ecf20Sopenharmony_ci FRF_AZ_TX_ISCSI_DDIG_EN, 0, 3958c2ecf20Sopenharmony_ci FRF_AZ_TX_ISCSI_HDIG_EN, 0, 3968c2ecf20Sopenharmony_ci FRF_AZ_TX_DESCQ_BUF_BASE_ID, tx_queue->txd.index, 3978c2ecf20Sopenharmony_ci FRF_AZ_TX_DESCQ_EVQ_ID, 3988c2ecf20Sopenharmony_ci tx_queue->channel->channel, 3998c2ecf20Sopenharmony_ci FRF_AZ_TX_DESCQ_OWNER_ID, 0, 4008c2ecf20Sopenharmony_ci FRF_AZ_TX_DESCQ_LABEL, tx_queue->label, 4018c2ecf20Sopenharmony_ci FRF_AZ_TX_DESCQ_SIZE, 4028c2ecf20Sopenharmony_ci __ffs(tx_queue->txd.entries), 4038c2ecf20Sopenharmony_ci FRF_AZ_TX_DESCQ_TYPE, 0, 4048c2ecf20Sopenharmony_ci FRF_BZ_TX_NON_IP_DROP_DIS, 1); 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(reg, FRF_BZ_TX_IP_CHKSM_DIS, !csum); 4078c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(reg, FRF_BZ_TX_TCP_CHKSM_DIS, !csum); 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci efx_writeo_table(efx, ®, efx->type->txd_ptr_tbl_base, 4108c2ecf20Sopenharmony_ci tx_queue->queue); 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_1(reg, 4138c2ecf20Sopenharmony_ci FRF_BZ_TX_PACE, 4148c2ecf20Sopenharmony_ci (tx_queue->type & EFX_TXQ_TYPE_HIGHPRI) ? 4158c2ecf20Sopenharmony_ci FFE_BZ_TX_PACE_OFF : 4168c2ecf20Sopenharmony_ci FFE_BZ_TX_PACE_RESERVED); 4178c2ecf20Sopenharmony_ci efx_writeo_table(efx, ®, FR_BZ_TX_PACE_TBL, tx_queue->queue); 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci tx_queue->tso_version = 1; 4208c2ecf20Sopenharmony_ci} 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_cistatic void efx_farch_flush_tx_queue(struct efx_tx_queue *tx_queue) 4238c2ecf20Sopenharmony_ci{ 4248c2ecf20Sopenharmony_ci struct efx_nic *efx = tx_queue->efx; 4258c2ecf20Sopenharmony_ci efx_oword_t tx_flush_descq; 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci WARN_ON(atomic_read(&tx_queue->flush_outstanding)); 4288c2ecf20Sopenharmony_ci atomic_set(&tx_queue->flush_outstanding, 1); 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_2(tx_flush_descq, 4318c2ecf20Sopenharmony_ci FRF_AZ_TX_FLUSH_DESCQ_CMD, 1, 4328c2ecf20Sopenharmony_ci FRF_AZ_TX_FLUSH_DESCQ, tx_queue->queue); 4338c2ecf20Sopenharmony_ci efx_writeo(efx, &tx_flush_descq, FR_AZ_TX_FLUSH_DESCQ); 4348c2ecf20Sopenharmony_ci} 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_civoid efx_farch_tx_fini(struct efx_tx_queue *tx_queue) 4378c2ecf20Sopenharmony_ci{ 4388c2ecf20Sopenharmony_ci struct efx_nic *efx = tx_queue->efx; 4398c2ecf20Sopenharmony_ci efx_oword_t tx_desc_ptr; 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci /* Remove TX descriptor ring from card */ 4428c2ecf20Sopenharmony_ci EFX_ZERO_OWORD(tx_desc_ptr); 4438c2ecf20Sopenharmony_ci efx_writeo_table(efx, &tx_desc_ptr, efx->type->txd_ptr_tbl_base, 4448c2ecf20Sopenharmony_ci tx_queue->queue); 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci /* Unpin TX descriptor ring */ 4478c2ecf20Sopenharmony_ci efx_fini_special_buffer(efx, &tx_queue->txd); 4488c2ecf20Sopenharmony_ci} 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci/* Free buffers backing TX queue */ 4518c2ecf20Sopenharmony_civoid efx_farch_tx_remove(struct efx_tx_queue *tx_queue) 4528c2ecf20Sopenharmony_ci{ 4538c2ecf20Sopenharmony_ci efx_free_special_buffer(tx_queue->efx, &tx_queue->txd); 4548c2ecf20Sopenharmony_ci} 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci/************************************************************************** 4578c2ecf20Sopenharmony_ci * 4588c2ecf20Sopenharmony_ci * RX path 4598c2ecf20Sopenharmony_ci * 4608c2ecf20Sopenharmony_ci **************************************************************************/ 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci/* This creates an entry in the RX descriptor queue */ 4638c2ecf20Sopenharmony_cistatic inline void 4648c2ecf20Sopenharmony_ciefx_farch_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned index) 4658c2ecf20Sopenharmony_ci{ 4668c2ecf20Sopenharmony_ci struct efx_rx_buffer *rx_buf; 4678c2ecf20Sopenharmony_ci efx_qword_t *rxd; 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ci rxd = efx_rx_desc(rx_queue, index); 4708c2ecf20Sopenharmony_ci rx_buf = efx_rx_buffer(rx_queue, index); 4718c2ecf20Sopenharmony_ci EFX_POPULATE_QWORD_3(*rxd, 4728c2ecf20Sopenharmony_ci FSF_AZ_RX_KER_BUF_SIZE, 4738c2ecf20Sopenharmony_ci rx_buf->len - 4748c2ecf20Sopenharmony_ci rx_queue->efx->type->rx_buffer_padding, 4758c2ecf20Sopenharmony_ci FSF_AZ_RX_KER_BUF_REGION, 0, 4768c2ecf20Sopenharmony_ci FSF_AZ_RX_KER_BUF_ADDR, rx_buf->dma_addr); 4778c2ecf20Sopenharmony_ci} 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci/* This writes to the RX_DESC_WPTR register for the specified receive 4808c2ecf20Sopenharmony_ci * descriptor ring. 4818c2ecf20Sopenharmony_ci */ 4828c2ecf20Sopenharmony_civoid efx_farch_rx_write(struct efx_rx_queue *rx_queue) 4838c2ecf20Sopenharmony_ci{ 4848c2ecf20Sopenharmony_ci struct efx_nic *efx = rx_queue->efx; 4858c2ecf20Sopenharmony_ci efx_dword_t reg; 4868c2ecf20Sopenharmony_ci unsigned write_ptr; 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci while (rx_queue->notified_count != rx_queue->added_count) { 4898c2ecf20Sopenharmony_ci efx_farch_build_rx_desc( 4908c2ecf20Sopenharmony_ci rx_queue, 4918c2ecf20Sopenharmony_ci rx_queue->notified_count & rx_queue->ptr_mask); 4928c2ecf20Sopenharmony_ci ++rx_queue->notified_count; 4938c2ecf20Sopenharmony_ci } 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci wmb(); 4968c2ecf20Sopenharmony_ci write_ptr = rx_queue->added_count & rx_queue->ptr_mask; 4978c2ecf20Sopenharmony_ci EFX_POPULATE_DWORD_1(reg, FRF_AZ_RX_DESC_WPTR_DWORD, write_ptr); 4988c2ecf20Sopenharmony_ci efx_writed_page(efx, ®, FR_AZ_RX_DESC_UPD_DWORD_P0, 4998c2ecf20Sopenharmony_ci efx_rx_queue_index(rx_queue)); 5008c2ecf20Sopenharmony_ci} 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ciint efx_farch_rx_probe(struct efx_rx_queue *rx_queue) 5038c2ecf20Sopenharmony_ci{ 5048c2ecf20Sopenharmony_ci struct efx_nic *efx = rx_queue->efx; 5058c2ecf20Sopenharmony_ci unsigned entries; 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci entries = rx_queue->ptr_mask + 1; 5088c2ecf20Sopenharmony_ci return efx_alloc_special_buffer(efx, &rx_queue->rxd, 5098c2ecf20Sopenharmony_ci entries * sizeof(efx_qword_t)); 5108c2ecf20Sopenharmony_ci} 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_civoid efx_farch_rx_init(struct efx_rx_queue *rx_queue) 5138c2ecf20Sopenharmony_ci{ 5148c2ecf20Sopenharmony_ci efx_oword_t rx_desc_ptr; 5158c2ecf20Sopenharmony_ci struct efx_nic *efx = rx_queue->efx; 5168c2ecf20Sopenharmony_ci bool jumbo_en; 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci /* For kernel-mode queues in Siena, the JUMBO flag enables scatter. */ 5198c2ecf20Sopenharmony_ci jumbo_en = efx->rx_scatter; 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci netif_dbg(efx, hw, efx->net_dev, 5228c2ecf20Sopenharmony_ci "RX queue %d ring in special buffers %d-%d\n", 5238c2ecf20Sopenharmony_ci efx_rx_queue_index(rx_queue), rx_queue->rxd.index, 5248c2ecf20Sopenharmony_ci rx_queue->rxd.index + rx_queue->rxd.entries - 1); 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci rx_queue->scatter_n = 0; 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ci /* Pin RX descriptor ring */ 5298c2ecf20Sopenharmony_ci efx_init_special_buffer(efx, &rx_queue->rxd); 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci /* Push RX descriptor ring to card */ 5328c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_10(rx_desc_ptr, 5338c2ecf20Sopenharmony_ci FRF_AZ_RX_ISCSI_DDIG_EN, true, 5348c2ecf20Sopenharmony_ci FRF_AZ_RX_ISCSI_HDIG_EN, true, 5358c2ecf20Sopenharmony_ci FRF_AZ_RX_DESCQ_BUF_BASE_ID, rx_queue->rxd.index, 5368c2ecf20Sopenharmony_ci FRF_AZ_RX_DESCQ_EVQ_ID, 5378c2ecf20Sopenharmony_ci efx_rx_queue_channel(rx_queue)->channel, 5388c2ecf20Sopenharmony_ci FRF_AZ_RX_DESCQ_OWNER_ID, 0, 5398c2ecf20Sopenharmony_ci FRF_AZ_RX_DESCQ_LABEL, 5408c2ecf20Sopenharmony_ci efx_rx_queue_index(rx_queue), 5418c2ecf20Sopenharmony_ci FRF_AZ_RX_DESCQ_SIZE, 5428c2ecf20Sopenharmony_ci __ffs(rx_queue->rxd.entries), 5438c2ecf20Sopenharmony_ci FRF_AZ_RX_DESCQ_TYPE, 0 /* kernel queue */ , 5448c2ecf20Sopenharmony_ci FRF_AZ_RX_DESCQ_JUMBO, jumbo_en, 5458c2ecf20Sopenharmony_ci FRF_AZ_RX_DESCQ_EN, 1); 5468c2ecf20Sopenharmony_ci efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base, 5478c2ecf20Sopenharmony_ci efx_rx_queue_index(rx_queue)); 5488c2ecf20Sopenharmony_ci} 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_cistatic void efx_farch_flush_rx_queue(struct efx_rx_queue *rx_queue) 5518c2ecf20Sopenharmony_ci{ 5528c2ecf20Sopenharmony_ci struct efx_nic *efx = rx_queue->efx; 5538c2ecf20Sopenharmony_ci efx_oword_t rx_flush_descq; 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_2(rx_flush_descq, 5568c2ecf20Sopenharmony_ci FRF_AZ_RX_FLUSH_DESCQ_CMD, 1, 5578c2ecf20Sopenharmony_ci FRF_AZ_RX_FLUSH_DESCQ, 5588c2ecf20Sopenharmony_ci efx_rx_queue_index(rx_queue)); 5598c2ecf20Sopenharmony_ci efx_writeo(efx, &rx_flush_descq, FR_AZ_RX_FLUSH_DESCQ); 5608c2ecf20Sopenharmony_ci} 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_civoid efx_farch_rx_fini(struct efx_rx_queue *rx_queue) 5638c2ecf20Sopenharmony_ci{ 5648c2ecf20Sopenharmony_ci efx_oword_t rx_desc_ptr; 5658c2ecf20Sopenharmony_ci struct efx_nic *efx = rx_queue->efx; 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci /* Remove RX descriptor ring from card */ 5688c2ecf20Sopenharmony_ci EFX_ZERO_OWORD(rx_desc_ptr); 5698c2ecf20Sopenharmony_ci efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base, 5708c2ecf20Sopenharmony_ci efx_rx_queue_index(rx_queue)); 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci /* Unpin RX descriptor ring */ 5738c2ecf20Sopenharmony_ci efx_fini_special_buffer(efx, &rx_queue->rxd); 5748c2ecf20Sopenharmony_ci} 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_ci/* Free buffers backing RX queue */ 5778c2ecf20Sopenharmony_civoid efx_farch_rx_remove(struct efx_rx_queue *rx_queue) 5788c2ecf20Sopenharmony_ci{ 5798c2ecf20Sopenharmony_ci efx_free_special_buffer(rx_queue->efx, &rx_queue->rxd); 5808c2ecf20Sopenharmony_ci} 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci/************************************************************************** 5838c2ecf20Sopenharmony_ci * 5848c2ecf20Sopenharmony_ci * Flush handling 5858c2ecf20Sopenharmony_ci * 5868c2ecf20Sopenharmony_ci **************************************************************************/ 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci/* efx_farch_flush_queues() must be woken up when all flushes are completed, 5898c2ecf20Sopenharmony_ci * or more RX flushes can be kicked off. 5908c2ecf20Sopenharmony_ci */ 5918c2ecf20Sopenharmony_cistatic bool efx_farch_flush_wake(struct efx_nic *efx) 5928c2ecf20Sopenharmony_ci{ 5938c2ecf20Sopenharmony_ci /* Ensure that all updates are visible to efx_farch_flush_queues() */ 5948c2ecf20Sopenharmony_ci smp_mb(); 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci return (atomic_read(&efx->active_queues) == 0 || 5978c2ecf20Sopenharmony_ci (atomic_read(&efx->rxq_flush_outstanding) < EFX_RX_FLUSH_COUNT 5988c2ecf20Sopenharmony_ci && atomic_read(&efx->rxq_flush_pending) > 0)); 5998c2ecf20Sopenharmony_ci} 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_cistatic bool efx_check_tx_flush_complete(struct efx_nic *efx) 6028c2ecf20Sopenharmony_ci{ 6038c2ecf20Sopenharmony_ci bool i = true; 6048c2ecf20Sopenharmony_ci efx_oword_t txd_ptr_tbl; 6058c2ecf20Sopenharmony_ci struct efx_channel *channel; 6068c2ecf20Sopenharmony_ci struct efx_tx_queue *tx_queue; 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci efx_for_each_channel(channel, efx) { 6098c2ecf20Sopenharmony_ci efx_for_each_channel_tx_queue(tx_queue, channel) { 6108c2ecf20Sopenharmony_ci efx_reado_table(efx, &txd_ptr_tbl, 6118c2ecf20Sopenharmony_ci FR_BZ_TX_DESC_PTR_TBL, tx_queue->queue); 6128c2ecf20Sopenharmony_ci if (EFX_OWORD_FIELD(txd_ptr_tbl, 6138c2ecf20Sopenharmony_ci FRF_AZ_TX_DESCQ_FLUSH) || 6148c2ecf20Sopenharmony_ci EFX_OWORD_FIELD(txd_ptr_tbl, 6158c2ecf20Sopenharmony_ci FRF_AZ_TX_DESCQ_EN)) { 6168c2ecf20Sopenharmony_ci netif_dbg(efx, hw, efx->net_dev, 6178c2ecf20Sopenharmony_ci "flush did not complete on TXQ %d\n", 6188c2ecf20Sopenharmony_ci tx_queue->queue); 6198c2ecf20Sopenharmony_ci i = false; 6208c2ecf20Sopenharmony_ci } else if (atomic_cmpxchg(&tx_queue->flush_outstanding, 6218c2ecf20Sopenharmony_ci 1, 0)) { 6228c2ecf20Sopenharmony_ci /* The flush is complete, but we didn't 6238c2ecf20Sopenharmony_ci * receive a flush completion event 6248c2ecf20Sopenharmony_ci */ 6258c2ecf20Sopenharmony_ci netif_dbg(efx, hw, efx->net_dev, 6268c2ecf20Sopenharmony_ci "flush complete on TXQ %d, so drain " 6278c2ecf20Sopenharmony_ci "the queue\n", tx_queue->queue); 6288c2ecf20Sopenharmony_ci /* Don't need to increment active_queues as it 6298c2ecf20Sopenharmony_ci * has already been incremented for the queues 6308c2ecf20Sopenharmony_ci * which did not drain 6318c2ecf20Sopenharmony_ci */ 6328c2ecf20Sopenharmony_ci efx_farch_magic_event(channel, 6338c2ecf20Sopenharmony_ci EFX_CHANNEL_MAGIC_TX_DRAIN( 6348c2ecf20Sopenharmony_ci tx_queue)); 6358c2ecf20Sopenharmony_ci } 6368c2ecf20Sopenharmony_ci } 6378c2ecf20Sopenharmony_ci } 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ci return i; 6408c2ecf20Sopenharmony_ci} 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_ci/* Flush all the transmit queues, and continue flushing receive queues until 6438c2ecf20Sopenharmony_ci * they're all flushed. Wait for the DRAIN events to be received so that there 6448c2ecf20Sopenharmony_ci * are no more RX and TX events left on any channel. */ 6458c2ecf20Sopenharmony_cistatic int efx_farch_do_flush(struct efx_nic *efx) 6468c2ecf20Sopenharmony_ci{ 6478c2ecf20Sopenharmony_ci unsigned timeout = msecs_to_jiffies(5000); /* 5s for all flushes and drains */ 6488c2ecf20Sopenharmony_ci struct efx_channel *channel; 6498c2ecf20Sopenharmony_ci struct efx_rx_queue *rx_queue; 6508c2ecf20Sopenharmony_ci struct efx_tx_queue *tx_queue; 6518c2ecf20Sopenharmony_ci int rc = 0; 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci efx_for_each_channel(channel, efx) { 6548c2ecf20Sopenharmony_ci efx_for_each_channel_tx_queue(tx_queue, channel) { 6558c2ecf20Sopenharmony_ci efx_farch_flush_tx_queue(tx_queue); 6568c2ecf20Sopenharmony_ci } 6578c2ecf20Sopenharmony_ci efx_for_each_channel_rx_queue(rx_queue, channel) { 6588c2ecf20Sopenharmony_ci rx_queue->flush_pending = true; 6598c2ecf20Sopenharmony_ci atomic_inc(&efx->rxq_flush_pending); 6608c2ecf20Sopenharmony_ci } 6618c2ecf20Sopenharmony_ci } 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci while (timeout && atomic_read(&efx->active_queues) > 0) { 6648c2ecf20Sopenharmony_ci /* If SRIOV is enabled, then offload receive queue flushing to 6658c2ecf20Sopenharmony_ci * the firmware (though we will still have to poll for 6668c2ecf20Sopenharmony_ci * completion). If that fails, fall back to the old scheme. 6678c2ecf20Sopenharmony_ci */ 6688c2ecf20Sopenharmony_ci if (efx_siena_sriov_enabled(efx)) { 6698c2ecf20Sopenharmony_ci rc = efx_mcdi_flush_rxqs(efx); 6708c2ecf20Sopenharmony_ci if (!rc) 6718c2ecf20Sopenharmony_ci goto wait; 6728c2ecf20Sopenharmony_ci } 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_ci /* The hardware supports four concurrent rx flushes, each of 6758c2ecf20Sopenharmony_ci * which may need to be retried if there is an outstanding 6768c2ecf20Sopenharmony_ci * descriptor fetch 6778c2ecf20Sopenharmony_ci */ 6788c2ecf20Sopenharmony_ci efx_for_each_channel(channel, efx) { 6798c2ecf20Sopenharmony_ci efx_for_each_channel_rx_queue(rx_queue, channel) { 6808c2ecf20Sopenharmony_ci if (atomic_read(&efx->rxq_flush_outstanding) >= 6818c2ecf20Sopenharmony_ci EFX_RX_FLUSH_COUNT) 6828c2ecf20Sopenharmony_ci break; 6838c2ecf20Sopenharmony_ci 6848c2ecf20Sopenharmony_ci if (rx_queue->flush_pending) { 6858c2ecf20Sopenharmony_ci rx_queue->flush_pending = false; 6868c2ecf20Sopenharmony_ci atomic_dec(&efx->rxq_flush_pending); 6878c2ecf20Sopenharmony_ci atomic_inc(&efx->rxq_flush_outstanding); 6888c2ecf20Sopenharmony_ci efx_farch_flush_rx_queue(rx_queue); 6898c2ecf20Sopenharmony_ci } 6908c2ecf20Sopenharmony_ci } 6918c2ecf20Sopenharmony_ci } 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ci wait: 6948c2ecf20Sopenharmony_ci timeout = wait_event_timeout(efx->flush_wq, 6958c2ecf20Sopenharmony_ci efx_farch_flush_wake(efx), 6968c2ecf20Sopenharmony_ci timeout); 6978c2ecf20Sopenharmony_ci } 6988c2ecf20Sopenharmony_ci 6998c2ecf20Sopenharmony_ci if (atomic_read(&efx->active_queues) && 7008c2ecf20Sopenharmony_ci !efx_check_tx_flush_complete(efx)) { 7018c2ecf20Sopenharmony_ci netif_err(efx, hw, efx->net_dev, "failed to flush %d queues " 7028c2ecf20Sopenharmony_ci "(rx %d+%d)\n", atomic_read(&efx->active_queues), 7038c2ecf20Sopenharmony_ci atomic_read(&efx->rxq_flush_outstanding), 7048c2ecf20Sopenharmony_ci atomic_read(&efx->rxq_flush_pending)); 7058c2ecf20Sopenharmony_ci rc = -ETIMEDOUT; 7068c2ecf20Sopenharmony_ci 7078c2ecf20Sopenharmony_ci atomic_set(&efx->active_queues, 0); 7088c2ecf20Sopenharmony_ci atomic_set(&efx->rxq_flush_pending, 0); 7098c2ecf20Sopenharmony_ci atomic_set(&efx->rxq_flush_outstanding, 0); 7108c2ecf20Sopenharmony_ci } 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_ci return rc; 7138c2ecf20Sopenharmony_ci} 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_ciint efx_farch_fini_dmaq(struct efx_nic *efx) 7168c2ecf20Sopenharmony_ci{ 7178c2ecf20Sopenharmony_ci struct efx_channel *channel; 7188c2ecf20Sopenharmony_ci struct efx_tx_queue *tx_queue; 7198c2ecf20Sopenharmony_ci struct efx_rx_queue *rx_queue; 7208c2ecf20Sopenharmony_ci int rc = 0; 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_ci /* Do not attempt to write to the NIC during EEH recovery */ 7238c2ecf20Sopenharmony_ci if (efx->state != STATE_RECOVERY) { 7248c2ecf20Sopenharmony_ci /* Only perform flush if DMA is enabled */ 7258c2ecf20Sopenharmony_ci if (efx->pci_dev->is_busmaster) { 7268c2ecf20Sopenharmony_ci efx->type->prepare_flush(efx); 7278c2ecf20Sopenharmony_ci rc = efx_farch_do_flush(efx); 7288c2ecf20Sopenharmony_ci efx->type->finish_flush(efx); 7298c2ecf20Sopenharmony_ci } 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_ci efx_for_each_channel(channel, efx) { 7328c2ecf20Sopenharmony_ci efx_for_each_channel_rx_queue(rx_queue, channel) 7338c2ecf20Sopenharmony_ci efx_farch_rx_fini(rx_queue); 7348c2ecf20Sopenharmony_ci efx_for_each_channel_tx_queue(tx_queue, channel) 7358c2ecf20Sopenharmony_ci efx_farch_tx_fini(tx_queue); 7368c2ecf20Sopenharmony_ci } 7378c2ecf20Sopenharmony_ci } 7388c2ecf20Sopenharmony_ci 7398c2ecf20Sopenharmony_ci return rc; 7408c2ecf20Sopenharmony_ci} 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_ci/* Reset queue and flush accounting after FLR 7438c2ecf20Sopenharmony_ci * 7448c2ecf20Sopenharmony_ci * One possible cause of FLR recovery is that DMA may be failing (eg. if bus 7458c2ecf20Sopenharmony_ci * mastering was disabled), in which case we don't receive (RXQ) flush 7468c2ecf20Sopenharmony_ci * completion events. This means that efx->rxq_flush_outstanding remained at 4 7478c2ecf20Sopenharmony_ci * after the FLR; also, efx->active_queues was non-zero (as no flush completion 7488c2ecf20Sopenharmony_ci * events were received, and we didn't go through efx_check_tx_flush_complete()) 7498c2ecf20Sopenharmony_ci * If we don't fix this up, on the next call to efx_realloc_channels() we won't 7508c2ecf20Sopenharmony_ci * flush any RX queues because efx->rxq_flush_outstanding is at the limit of 4 7518c2ecf20Sopenharmony_ci * for batched flush requests; and the efx->active_queues gets messed up because 7528c2ecf20Sopenharmony_ci * we keep incrementing for the newly initialised queues, but it never went to 7538c2ecf20Sopenharmony_ci * zero previously. Then we get a timeout every time we try to restart the 7548c2ecf20Sopenharmony_ci * queues, as it doesn't go back to zero when we should be flushing the queues. 7558c2ecf20Sopenharmony_ci */ 7568c2ecf20Sopenharmony_civoid efx_farch_finish_flr(struct efx_nic *efx) 7578c2ecf20Sopenharmony_ci{ 7588c2ecf20Sopenharmony_ci atomic_set(&efx->rxq_flush_pending, 0); 7598c2ecf20Sopenharmony_ci atomic_set(&efx->rxq_flush_outstanding, 0); 7608c2ecf20Sopenharmony_ci atomic_set(&efx->active_queues, 0); 7618c2ecf20Sopenharmony_ci} 7628c2ecf20Sopenharmony_ci 7638c2ecf20Sopenharmony_ci 7648c2ecf20Sopenharmony_ci/************************************************************************** 7658c2ecf20Sopenharmony_ci * 7668c2ecf20Sopenharmony_ci * Event queue processing 7678c2ecf20Sopenharmony_ci * Event queues are processed by per-channel tasklets. 7688c2ecf20Sopenharmony_ci * 7698c2ecf20Sopenharmony_ci **************************************************************************/ 7708c2ecf20Sopenharmony_ci 7718c2ecf20Sopenharmony_ci/* Update a channel's event queue's read pointer (RPTR) register 7728c2ecf20Sopenharmony_ci * 7738c2ecf20Sopenharmony_ci * This writes the EVQ_RPTR_REG register for the specified channel's 7748c2ecf20Sopenharmony_ci * event queue. 7758c2ecf20Sopenharmony_ci */ 7768c2ecf20Sopenharmony_civoid efx_farch_ev_read_ack(struct efx_channel *channel) 7778c2ecf20Sopenharmony_ci{ 7788c2ecf20Sopenharmony_ci efx_dword_t reg; 7798c2ecf20Sopenharmony_ci struct efx_nic *efx = channel->efx; 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_ci EFX_POPULATE_DWORD_1(reg, FRF_AZ_EVQ_RPTR, 7828c2ecf20Sopenharmony_ci channel->eventq_read_ptr & channel->eventq_mask); 7838c2ecf20Sopenharmony_ci 7848c2ecf20Sopenharmony_ci /* For Falcon A1, EVQ_RPTR_KER is documented as having a step size 7858c2ecf20Sopenharmony_ci * of 4 bytes, but it is really 16 bytes just like later revisions. 7868c2ecf20Sopenharmony_ci */ 7878c2ecf20Sopenharmony_ci efx_writed(efx, ®, 7888c2ecf20Sopenharmony_ci efx->type->evq_rptr_tbl_base + 7898c2ecf20Sopenharmony_ci FR_BZ_EVQ_RPTR_STEP * channel->channel); 7908c2ecf20Sopenharmony_ci} 7918c2ecf20Sopenharmony_ci 7928c2ecf20Sopenharmony_ci/* Use HW to insert a SW defined event */ 7938c2ecf20Sopenharmony_civoid efx_farch_generate_event(struct efx_nic *efx, unsigned int evq, 7948c2ecf20Sopenharmony_ci efx_qword_t *event) 7958c2ecf20Sopenharmony_ci{ 7968c2ecf20Sopenharmony_ci efx_oword_t drv_ev_reg; 7978c2ecf20Sopenharmony_ci 7988c2ecf20Sopenharmony_ci BUILD_BUG_ON(FRF_AZ_DRV_EV_DATA_LBN != 0 || 7998c2ecf20Sopenharmony_ci FRF_AZ_DRV_EV_DATA_WIDTH != 64); 8008c2ecf20Sopenharmony_ci drv_ev_reg.u32[0] = event->u32[0]; 8018c2ecf20Sopenharmony_ci drv_ev_reg.u32[1] = event->u32[1]; 8028c2ecf20Sopenharmony_ci drv_ev_reg.u32[2] = 0; 8038c2ecf20Sopenharmony_ci drv_ev_reg.u32[3] = 0; 8048c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(drv_ev_reg, FRF_AZ_DRV_EV_QID, evq); 8058c2ecf20Sopenharmony_ci efx_writeo(efx, &drv_ev_reg, FR_AZ_DRV_EV); 8068c2ecf20Sopenharmony_ci} 8078c2ecf20Sopenharmony_ci 8088c2ecf20Sopenharmony_cistatic void efx_farch_magic_event(struct efx_channel *channel, u32 magic) 8098c2ecf20Sopenharmony_ci{ 8108c2ecf20Sopenharmony_ci efx_qword_t event; 8118c2ecf20Sopenharmony_ci 8128c2ecf20Sopenharmony_ci EFX_POPULATE_QWORD_2(event, FSF_AZ_EV_CODE, 8138c2ecf20Sopenharmony_ci FSE_AZ_EV_CODE_DRV_GEN_EV, 8148c2ecf20Sopenharmony_ci FSF_AZ_DRV_GEN_EV_MAGIC, magic); 8158c2ecf20Sopenharmony_ci efx_farch_generate_event(channel->efx, channel->channel, &event); 8168c2ecf20Sopenharmony_ci} 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_ci/* Handle a transmit completion event 8198c2ecf20Sopenharmony_ci * 8208c2ecf20Sopenharmony_ci * The NIC batches TX completion events; the message we receive is of 8218c2ecf20Sopenharmony_ci * the form "complete all TX events up to this index". 8228c2ecf20Sopenharmony_ci */ 8238c2ecf20Sopenharmony_cistatic void 8248c2ecf20Sopenharmony_ciefx_farch_handle_tx_event(struct efx_channel *channel, efx_qword_t *event) 8258c2ecf20Sopenharmony_ci{ 8268c2ecf20Sopenharmony_ci unsigned int tx_ev_desc_ptr; 8278c2ecf20Sopenharmony_ci unsigned int tx_ev_q_label; 8288c2ecf20Sopenharmony_ci struct efx_tx_queue *tx_queue; 8298c2ecf20Sopenharmony_ci struct efx_nic *efx = channel->efx; 8308c2ecf20Sopenharmony_ci 8318c2ecf20Sopenharmony_ci if (unlikely(READ_ONCE(efx->reset_pending))) 8328c2ecf20Sopenharmony_ci return; 8338c2ecf20Sopenharmony_ci 8348c2ecf20Sopenharmony_ci if (likely(EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_COMP))) { 8358c2ecf20Sopenharmony_ci /* Transmit completion */ 8368c2ecf20Sopenharmony_ci tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_DESC_PTR); 8378c2ecf20Sopenharmony_ci tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL); 8388c2ecf20Sopenharmony_ci tx_queue = channel->tx_queue + 8398c2ecf20Sopenharmony_ci (tx_ev_q_label % EFX_MAX_TXQ_PER_CHANNEL); 8408c2ecf20Sopenharmony_ci efx_xmit_done(tx_queue, tx_ev_desc_ptr); 8418c2ecf20Sopenharmony_ci } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_WQ_FF_FULL)) { 8428c2ecf20Sopenharmony_ci /* Rewrite the FIFO write pointer */ 8438c2ecf20Sopenharmony_ci tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL); 8448c2ecf20Sopenharmony_ci tx_queue = channel->tx_queue + 8458c2ecf20Sopenharmony_ci (tx_ev_q_label % EFX_MAX_TXQ_PER_CHANNEL); 8468c2ecf20Sopenharmony_ci 8478c2ecf20Sopenharmony_ci netif_tx_lock(efx->net_dev); 8488c2ecf20Sopenharmony_ci efx_farch_notify_tx_desc(tx_queue); 8498c2ecf20Sopenharmony_ci netif_tx_unlock(efx->net_dev); 8508c2ecf20Sopenharmony_ci } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_PKT_ERR)) { 8518c2ecf20Sopenharmony_ci efx_schedule_reset(efx, RESET_TYPE_DMA_ERROR); 8528c2ecf20Sopenharmony_ci } else { 8538c2ecf20Sopenharmony_ci netif_err(efx, tx_err, efx->net_dev, 8548c2ecf20Sopenharmony_ci "channel %d unexpected TX event " 8558c2ecf20Sopenharmony_ci EFX_QWORD_FMT"\n", channel->channel, 8568c2ecf20Sopenharmony_ci EFX_QWORD_VAL(*event)); 8578c2ecf20Sopenharmony_ci } 8588c2ecf20Sopenharmony_ci} 8598c2ecf20Sopenharmony_ci 8608c2ecf20Sopenharmony_ci/* Detect errors included in the rx_evt_pkt_ok bit. */ 8618c2ecf20Sopenharmony_cistatic u16 efx_farch_handle_rx_not_ok(struct efx_rx_queue *rx_queue, 8628c2ecf20Sopenharmony_ci const efx_qword_t *event) 8638c2ecf20Sopenharmony_ci{ 8648c2ecf20Sopenharmony_ci struct efx_channel *channel = efx_rx_queue_channel(rx_queue); 8658c2ecf20Sopenharmony_ci struct efx_nic *efx = rx_queue->efx; 8668c2ecf20Sopenharmony_ci bool rx_ev_buf_owner_id_err, rx_ev_ip_hdr_chksum_err; 8678c2ecf20Sopenharmony_ci bool rx_ev_tcp_udp_chksum_err, rx_ev_eth_crc_err; 8688c2ecf20Sopenharmony_ci bool rx_ev_frm_trunc, rx_ev_tobe_disc; 8698c2ecf20Sopenharmony_ci bool rx_ev_other_err, rx_ev_pause_frm; 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_ci rx_ev_tobe_disc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_TOBE_DISC); 8728c2ecf20Sopenharmony_ci rx_ev_buf_owner_id_err = EFX_QWORD_FIELD(*event, 8738c2ecf20Sopenharmony_ci FSF_AZ_RX_EV_BUF_OWNER_ID_ERR); 8748c2ecf20Sopenharmony_ci rx_ev_ip_hdr_chksum_err = EFX_QWORD_FIELD(*event, 8758c2ecf20Sopenharmony_ci FSF_AZ_RX_EV_IP_HDR_CHKSUM_ERR); 8768c2ecf20Sopenharmony_ci rx_ev_tcp_udp_chksum_err = EFX_QWORD_FIELD(*event, 8778c2ecf20Sopenharmony_ci FSF_AZ_RX_EV_TCP_UDP_CHKSUM_ERR); 8788c2ecf20Sopenharmony_ci rx_ev_eth_crc_err = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_ETH_CRC_ERR); 8798c2ecf20Sopenharmony_ci rx_ev_frm_trunc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_FRM_TRUNC); 8808c2ecf20Sopenharmony_ci rx_ev_pause_frm = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PAUSE_FRM_ERR); 8818c2ecf20Sopenharmony_ci 8828c2ecf20Sopenharmony_ci /* Every error apart from tobe_disc and pause_frm */ 8838c2ecf20Sopenharmony_ci rx_ev_other_err = (rx_ev_tcp_udp_chksum_err | 8848c2ecf20Sopenharmony_ci rx_ev_buf_owner_id_err | rx_ev_eth_crc_err | 8858c2ecf20Sopenharmony_ci rx_ev_frm_trunc | rx_ev_ip_hdr_chksum_err); 8868c2ecf20Sopenharmony_ci 8878c2ecf20Sopenharmony_ci /* Count errors that are not in MAC stats. Ignore expected 8888c2ecf20Sopenharmony_ci * checksum errors during self-test. */ 8898c2ecf20Sopenharmony_ci if (rx_ev_frm_trunc) 8908c2ecf20Sopenharmony_ci ++channel->n_rx_frm_trunc; 8918c2ecf20Sopenharmony_ci else if (rx_ev_tobe_disc) 8928c2ecf20Sopenharmony_ci ++channel->n_rx_tobe_disc; 8938c2ecf20Sopenharmony_ci else if (!efx->loopback_selftest) { 8948c2ecf20Sopenharmony_ci if (rx_ev_ip_hdr_chksum_err) 8958c2ecf20Sopenharmony_ci ++channel->n_rx_ip_hdr_chksum_err; 8968c2ecf20Sopenharmony_ci else if (rx_ev_tcp_udp_chksum_err) 8978c2ecf20Sopenharmony_ci ++channel->n_rx_tcp_udp_chksum_err; 8988c2ecf20Sopenharmony_ci } 8998c2ecf20Sopenharmony_ci 9008c2ecf20Sopenharmony_ci /* TOBE_DISC is expected on unicast mismatches; don't print out an 9018c2ecf20Sopenharmony_ci * error message. FRM_TRUNC indicates RXDP dropped the packet due 9028c2ecf20Sopenharmony_ci * to a FIFO overflow. 9038c2ecf20Sopenharmony_ci */ 9048c2ecf20Sopenharmony_ci#ifdef DEBUG 9058c2ecf20Sopenharmony_ci if (rx_ev_other_err && net_ratelimit()) { 9068c2ecf20Sopenharmony_ci netif_dbg(efx, rx_err, efx->net_dev, 9078c2ecf20Sopenharmony_ci " RX queue %d unexpected RX event " 9088c2ecf20Sopenharmony_ci EFX_QWORD_FMT "%s%s%s%s%s%s%s\n", 9098c2ecf20Sopenharmony_ci efx_rx_queue_index(rx_queue), EFX_QWORD_VAL(*event), 9108c2ecf20Sopenharmony_ci rx_ev_buf_owner_id_err ? " [OWNER_ID_ERR]" : "", 9118c2ecf20Sopenharmony_ci rx_ev_ip_hdr_chksum_err ? 9128c2ecf20Sopenharmony_ci " [IP_HDR_CHKSUM_ERR]" : "", 9138c2ecf20Sopenharmony_ci rx_ev_tcp_udp_chksum_err ? 9148c2ecf20Sopenharmony_ci " [TCP_UDP_CHKSUM_ERR]" : "", 9158c2ecf20Sopenharmony_ci rx_ev_eth_crc_err ? " [ETH_CRC_ERR]" : "", 9168c2ecf20Sopenharmony_ci rx_ev_frm_trunc ? " [FRM_TRUNC]" : "", 9178c2ecf20Sopenharmony_ci rx_ev_tobe_disc ? " [TOBE_DISC]" : "", 9188c2ecf20Sopenharmony_ci rx_ev_pause_frm ? " [PAUSE]" : ""); 9198c2ecf20Sopenharmony_ci } 9208c2ecf20Sopenharmony_ci#else 9218c2ecf20Sopenharmony_ci (void) rx_ev_other_err; 9228c2ecf20Sopenharmony_ci#endif 9238c2ecf20Sopenharmony_ci 9248c2ecf20Sopenharmony_ci if (efx->net_dev->features & NETIF_F_RXALL) 9258c2ecf20Sopenharmony_ci /* don't discard frame for CRC error */ 9268c2ecf20Sopenharmony_ci rx_ev_eth_crc_err = false; 9278c2ecf20Sopenharmony_ci 9288c2ecf20Sopenharmony_ci /* The frame must be discarded if any of these are true. */ 9298c2ecf20Sopenharmony_ci return (rx_ev_eth_crc_err | rx_ev_frm_trunc | 9308c2ecf20Sopenharmony_ci rx_ev_tobe_disc | rx_ev_pause_frm) ? 9318c2ecf20Sopenharmony_ci EFX_RX_PKT_DISCARD : 0; 9328c2ecf20Sopenharmony_ci} 9338c2ecf20Sopenharmony_ci 9348c2ecf20Sopenharmony_ci/* Handle receive events that are not in-order. Return true if this 9358c2ecf20Sopenharmony_ci * can be handled as a partial packet discard, false if it's more 9368c2ecf20Sopenharmony_ci * serious. 9378c2ecf20Sopenharmony_ci */ 9388c2ecf20Sopenharmony_cistatic bool 9398c2ecf20Sopenharmony_ciefx_farch_handle_rx_bad_index(struct efx_rx_queue *rx_queue, unsigned index) 9408c2ecf20Sopenharmony_ci{ 9418c2ecf20Sopenharmony_ci struct efx_channel *channel = efx_rx_queue_channel(rx_queue); 9428c2ecf20Sopenharmony_ci struct efx_nic *efx = rx_queue->efx; 9438c2ecf20Sopenharmony_ci unsigned expected, dropped; 9448c2ecf20Sopenharmony_ci 9458c2ecf20Sopenharmony_ci if (rx_queue->scatter_n && 9468c2ecf20Sopenharmony_ci index == ((rx_queue->removed_count + rx_queue->scatter_n - 1) & 9478c2ecf20Sopenharmony_ci rx_queue->ptr_mask)) { 9488c2ecf20Sopenharmony_ci ++channel->n_rx_nodesc_trunc; 9498c2ecf20Sopenharmony_ci return true; 9508c2ecf20Sopenharmony_ci } 9518c2ecf20Sopenharmony_ci 9528c2ecf20Sopenharmony_ci expected = rx_queue->removed_count & rx_queue->ptr_mask; 9538c2ecf20Sopenharmony_ci dropped = (index - expected) & rx_queue->ptr_mask; 9548c2ecf20Sopenharmony_ci netif_info(efx, rx_err, efx->net_dev, 9558c2ecf20Sopenharmony_ci "dropped %d events (index=%d expected=%d)\n", 9568c2ecf20Sopenharmony_ci dropped, index, expected); 9578c2ecf20Sopenharmony_ci 9588c2ecf20Sopenharmony_ci efx_schedule_reset(efx, RESET_TYPE_DISABLE); 9598c2ecf20Sopenharmony_ci return false; 9608c2ecf20Sopenharmony_ci} 9618c2ecf20Sopenharmony_ci 9628c2ecf20Sopenharmony_ci/* Handle a packet received event 9638c2ecf20Sopenharmony_ci * 9648c2ecf20Sopenharmony_ci * The NIC gives a "discard" flag if it's a unicast packet with the 9658c2ecf20Sopenharmony_ci * wrong destination address 9668c2ecf20Sopenharmony_ci * Also "is multicast" and "matches multicast filter" flags can be used to 9678c2ecf20Sopenharmony_ci * discard non-matching multicast packets. 9688c2ecf20Sopenharmony_ci */ 9698c2ecf20Sopenharmony_cistatic void 9708c2ecf20Sopenharmony_ciefx_farch_handle_rx_event(struct efx_channel *channel, const efx_qword_t *event) 9718c2ecf20Sopenharmony_ci{ 9728c2ecf20Sopenharmony_ci unsigned int rx_ev_desc_ptr, rx_ev_byte_cnt; 9738c2ecf20Sopenharmony_ci unsigned int rx_ev_hdr_type, rx_ev_mcast_pkt; 9748c2ecf20Sopenharmony_ci unsigned expected_ptr; 9758c2ecf20Sopenharmony_ci bool rx_ev_pkt_ok, rx_ev_sop, rx_ev_cont; 9768c2ecf20Sopenharmony_ci u16 flags; 9778c2ecf20Sopenharmony_ci struct efx_rx_queue *rx_queue; 9788c2ecf20Sopenharmony_ci struct efx_nic *efx = channel->efx; 9798c2ecf20Sopenharmony_ci 9808c2ecf20Sopenharmony_ci if (unlikely(READ_ONCE(efx->reset_pending))) 9818c2ecf20Sopenharmony_ci return; 9828c2ecf20Sopenharmony_ci 9838c2ecf20Sopenharmony_ci rx_ev_cont = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_JUMBO_CONT); 9848c2ecf20Sopenharmony_ci rx_ev_sop = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_SOP); 9858c2ecf20Sopenharmony_ci WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_Q_LABEL) != 9868c2ecf20Sopenharmony_ci channel->channel); 9878c2ecf20Sopenharmony_ci 9888c2ecf20Sopenharmony_ci rx_queue = efx_channel_get_rx_queue(channel); 9898c2ecf20Sopenharmony_ci 9908c2ecf20Sopenharmony_ci rx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_DESC_PTR); 9918c2ecf20Sopenharmony_ci expected_ptr = ((rx_queue->removed_count + rx_queue->scatter_n) & 9928c2ecf20Sopenharmony_ci rx_queue->ptr_mask); 9938c2ecf20Sopenharmony_ci 9948c2ecf20Sopenharmony_ci /* Check for partial drops and other errors */ 9958c2ecf20Sopenharmony_ci if (unlikely(rx_ev_desc_ptr != expected_ptr) || 9968c2ecf20Sopenharmony_ci unlikely(rx_ev_sop != (rx_queue->scatter_n == 0))) { 9978c2ecf20Sopenharmony_ci if (rx_ev_desc_ptr != expected_ptr && 9988c2ecf20Sopenharmony_ci !efx_farch_handle_rx_bad_index(rx_queue, rx_ev_desc_ptr)) 9998c2ecf20Sopenharmony_ci return; 10008c2ecf20Sopenharmony_ci 10018c2ecf20Sopenharmony_ci /* Discard all pending fragments */ 10028c2ecf20Sopenharmony_ci if (rx_queue->scatter_n) { 10038c2ecf20Sopenharmony_ci efx_rx_packet( 10048c2ecf20Sopenharmony_ci rx_queue, 10058c2ecf20Sopenharmony_ci rx_queue->removed_count & rx_queue->ptr_mask, 10068c2ecf20Sopenharmony_ci rx_queue->scatter_n, 0, EFX_RX_PKT_DISCARD); 10078c2ecf20Sopenharmony_ci rx_queue->removed_count += rx_queue->scatter_n; 10088c2ecf20Sopenharmony_ci rx_queue->scatter_n = 0; 10098c2ecf20Sopenharmony_ci } 10108c2ecf20Sopenharmony_ci 10118c2ecf20Sopenharmony_ci /* Return if there is no new fragment */ 10128c2ecf20Sopenharmony_ci if (rx_ev_desc_ptr != expected_ptr) 10138c2ecf20Sopenharmony_ci return; 10148c2ecf20Sopenharmony_ci 10158c2ecf20Sopenharmony_ci /* Discard new fragment if not SOP */ 10168c2ecf20Sopenharmony_ci if (!rx_ev_sop) { 10178c2ecf20Sopenharmony_ci efx_rx_packet( 10188c2ecf20Sopenharmony_ci rx_queue, 10198c2ecf20Sopenharmony_ci rx_queue->removed_count & rx_queue->ptr_mask, 10208c2ecf20Sopenharmony_ci 1, 0, EFX_RX_PKT_DISCARD); 10218c2ecf20Sopenharmony_ci ++rx_queue->removed_count; 10228c2ecf20Sopenharmony_ci return; 10238c2ecf20Sopenharmony_ci } 10248c2ecf20Sopenharmony_ci } 10258c2ecf20Sopenharmony_ci 10268c2ecf20Sopenharmony_ci ++rx_queue->scatter_n; 10278c2ecf20Sopenharmony_ci if (rx_ev_cont) 10288c2ecf20Sopenharmony_ci return; 10298c2ecf20Sopenharmony_ci 10308c2ecf20Sopenharmony_ci rx_ev_byte_cnt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_BYTE_CNT); 10318c2ecf20Sopenharmony_ci rx_ev_pkt_ok = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_OK); 10328c2ecf20Sopenharmony_ci rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE); 10338c2ecf20Sopenharmony_ci 10348c2ecf20Sopenharmony_ci if (likely(rx_ev_pkt_ok)) { 10358c2ecf20Sopenharmony_ci /* If packet is marked as OK then we can rely on the 10368c2ecf20Sopenharmony_ci * hardware checksum and classification. 10378c2ecf20Sopenharmony_ci */ 10388c2ecf20Sopenharmony_ci flags = 0; 10398c2ecf20Sopenharmony_ci switch (rx_ev_hdr_type) { 10408c2ecf20Sopenharmony_ci case FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_TCP: 10418c2ecf20Sopenharmony_ci flags |= EFX_RX_PKT_TCP; 10428c2ecf20Sopenharmony_ci fallthrough; 10438c2ecf20Sopenharmony_ci case FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_UDP: 10448c2ecf20Sopenharmony_ci flags |= EFX_RX_PKT_CSUMMED; 10458c2ecf20Sopenharmony_ci fallthrough; 10468c2ecf20Sopenharmony_ci case FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_OTHER: 10478c2ecf20Sopenharmony_ci case FSE_AZ_RX_EV_HDR_TYPE_OTHER: 10488c2ecf20Sopenharmony_ci break; 10498c2ecf20Sopenharmony_ci } 10508c2ecf20Sopenharmony_ci } else { 10518c2ecf20Sopenharmony_ci flags = efx_farch_handle_rx_not_ok(rx_queue, event); 10528c2ecf20Sopenharmony_ci } 10538c2ecf20Sopenharmony_ci 10548c2ecf20Sopenharmony_ci /* Detect multicast packets that didn't match the filter */ 10558c2ecf20Sopenharmony_ci rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT); 10568c2ecf20Sopenharmony_ci if (rx_ev_mcast_pkt) { 10578c2ecf20Sopenharmony_ci unsigned int rx_ev_mcast_hash_match = 10588c2ecf20Sopenharmony_ci EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_HASH_MATCH); 10598c2ecf20Sopenharmony_ci 10608c2ecf20Sopenharmony_ci if (unlikely(!rx_ev_mcast_hash_match)) { 10618c2ecf20Sopenharmony_ci ++channel->n_rx_mcast_mismatch; 10628c2ecf20Sopenharmony_ci flags |= EFX_RX_PKT_DISCARD; 10638c2ecf20Sopenharmony_ci } 10648c2ecf20Sopenharmony_ci } 10658c2ecf20Sopenharmony_ci 10668c2ecf20Sopenharmony_ci channel->irq_mod_score += 2; 10678c2ecf20Sopenharmony_ci 10688c2ecf20Sopenharmony_ci /* Handle received packet */ 10698c2ecf20Sopenharmony_ci efx_rx_packet(rx_queue, 10708c2ecf20Sopenharmony_ci rx_queue->removed_count & rx_queue->ptr_mask, 10718c2ecf20Sopenharmony_ci rx_queue->scatter_n, rx_ev_byte_cnt, flags); 10728c2ecf20Sopenharmony_ci rx_queue->removed_count += rx_queue->scatter_n; 10738c2ecf20Sopenharmony_ci rx_queue->scatter_n = 0; 10748c2ecf20Sopenharmony_ci} 10758c2ecf20Sopenharmony_ci 10768c2ecf20Sopenharmony_ci/* If this flush done event corresponds to a &struct efx_tx_queue, then 10778c2ecf20Sopenharmony_ci * send an %EFX_CHANNEL_MAGIC_TX_DRAIN event to drain the event queue 10788c2ecf20Sopenharmony_ci * of all transmit completions. 10798c2ecf20Sopenharmony_ci */ 10808c2ecf20Sopenharmony_cistatic void 10818c2ecf20Sopenharmony_ciefx_farch_handle_tx_flush_done(struct efx_nic *efx, efx_qword_t *event) 10828c2ecf20Sopenharmony_ci{ 10838c2ecf20Sopenharmony_ci struct efx_tx_queue *tx_queue; 10848c2ecf20Sopenharmony_ci struct efx_channel *channel; 10858c2ecf20Sopenharmony_ci int qid; 10868c2ecf20Sopenharmony_ci 10878c2ecf20Sopenharmony_ci qid = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA); 10888c2ecf20Sopenharmony_ci if (qid < EFX_MAX_TXQ_PER_CHANNEL * (efx->n_tx_channels + efx->n_extra_tx_channels)) { 10898c2ecf20Sopenharmony_ci channel = efx_get_tx_channel(efx, qid / EFX_MAX_TXQ_PER_CHANNEL); 10908c2ecf20Sopenharmony_ci tx_queue = channel->tx_queue + (qid % EFX_MAX_TXQ_PER_CHANNEL); 10918c2ecf20Sopenharmony_ci if (atomic_cmpxchg(&tx_queue->flush_outstanding, 1, 0)) 10928c2ecf20Sopenharmony_ci efx_farch_magic_event(tx_queue->channel, 10938c2ecf20Sopenharmony_ci EFX_CHANNEL_MAGIC_TX_DRAIN(tx_queue)); 10948c2ecf20Sopenharmony_ci } 10958c2ecf20Sopenharmony_ci} 10968c2ecf20Sopenharmony_ci 10978c2ecf20Sopenharmony_ci/* If this flush done event corresponds to a &struct efx_rx_queue: If the flush 10988c2ecf20Sopenharmony_ci * was successful then send an %EFX_CHANNEL_MAGIC_RX_DRAIN, otherwise add 10998c2ecf20Sopenharmony_ci * the RX queue back to the mask of RX queues in need of flushing. 11008c2ecf20Sopenharmony_ci */ 11018c2ecf20Sopenharmony_cistatic void 11028c2ecf20Sopenharmony_ciefx_farch_handle_rx_flush_done(struct efx_nic *efx, efx_qword_t *event) 11038c2ecf20Sopenharmony_ci{ 11048c2ecf20Sopenharmony_ci struct efx_channel *channel; 11058c2ecf20Sopenharmony_ci struct efx_rx_queue *rx_queue; 11068c2ecf20Sopenharmony_ci int qid; 11078c2ecf20Sopenharmony_ci bool failed; 11088c2ecf20Sopenharmony_ci 11098c2ecf20Sopenharmony_ci qid = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID); 11108c2ecf20Sopenharmony_ci failed = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL); 11118c2ecf20Sopenharmony_ci if (qid >= efx->n_channels) 11128c2ecf20Sopenharmony_ci return; 11138c2ecf20Sopenharmony_ci channel = efx_get_channel(efx, qid); 11148c2ecf20Sopenharmony_ci if (!efx_channel_has_rx_queue(channel)) 11158c2ecf20Sopenharmony_ci return; 11168c2ecf20Sopenharmony_ci rx_queue = efx_channel_get_rx_queue(channel); 11178c2ecf20Sopenharmony_ci 11188c2ecf20Sopenharmony_ci if (failed) { 11198c2ecf20Sopenharmony_ci netif_info(efx, hw, efx->net_dev, 11208c2ecf20Sopenharmony_ci "RXQ %d flush retry\n", qid); 11218c2ecf20Sopenharmony_ci rx_queue->flush_pending = true; 11228c2ecf20Sopenharmony_ci atomic_inc(&efx->rxq_flush_pending); 11238c2ecf20Sopenharmony_ci } else { 11248c2ecf20Sopenharmony_ci efx_farch_magic_event(efx_rx_queue_channel(rx_queue), 11258c2ecf20Sopenharmony_ci EFX_CHANNEL_MAGIC_RX_DRAIN(rx_queue)); 11268c2ecf20Sopenharmony_ci } 11278c2ecf20Sopenharmony_ci atomic_dec(&efx->rxq_flush_outstanding); 11288c2ecf20Sopenharmony_ci if (efx_farch_flush_wake(efx)) 11298c2ecf20Sopenharmony_ci wake_up(&efx->flush_wq); 11308c2ecf20Sopenharmony_ci} 11318c2ecf20Sopenharmony_ci 11328c2ecf20Sopenharmony_cistatic void 11338c2ecf20Sopenharmony_ciefx_farch_handle_drain_event(struct efx_channel *channel) 11348c2ecf20Sopenharmony_ci{ 11358c2ecf20Sopenharmony_ci struct efx_nic *efx = channel->efx; 11368c2ecf20Sopenharmony_ci 11378c2ecf20Sopenharmony_ci WARN_ON(atomic_read(&efx->active_queues) == 0); 11388c2ecf20Sopenharmony_ci atomic_dec(&efx->active_queues); 11398c2ecf20Sopenharmony_ci if (efx_farch_flush_wake(efx)) 11408c2ecf20Sopenharmony_ci wake_up(&efx->flush_wq); 11418c2ecf20Sopenharmony_ci} 11428c2ecf20Sopenharmony_ci 11438c2ecf20Sopenharmony_cistatic void efx_farch_handle_generated_event(struct efx_channel *channel, 11448c2ecf20Sopenharmony_ci efx_qword_t *event) 11458c2ecf20Sopenharmony_ci{ 11468c2ecf20Sopenharmony_ci struct efx_nic *efx = channel->efx; 11478c2ecf20Sopenharmony_ci struct efx_rx_queue *rx_queue = 11488c2ecf20Sopenharmony_ci efx_channel_has_rx_queue(channel) ? 11498c2ecf20Sopenharmony_ci efx_channel_get_rx_queue(channel) : NULL; 11508c2ecf20Sopenharmony_ci unsigned magic, code; 11518c2ecf20Sopenharmony_ci 11528c2ecf20Sopenharmony_ci magic = EFX_QWORD_FIELD(*event, FSF_AZ_DRV_GEN_EV_MAGIC); 11538c2ecf20Sopenharmony_ci code = _EFX_CHANNEL_MAGIC_CODE(magic); 11548c2ecf20Sopenharmony_ci 11558c2ecf20Sopenharmony_ci if (magic == EFX_CHANNEL_MAGIC_TEST(channel)) { 11568c2ecf20Sopenharmony_ci channel->event_test_cpu = raw_smp_processor_id(); 11578c2ecf20Sopenharmony_ci } else if (rx_queue && magic == EFX_CHANNEL_MAGIC_FILL(rx_queue)) { 11588c2ecf20Sopenharmony_ci /* The queue must be empty, so we won't receive any rx 11598c2ecf20Sopenharmony_ci * events, so efx_process_channel() won't refill the 11608c2ecf20Sopenharmony_ci * queue. Refill it here */ 11618c2ecf20Sopenharmony_ci efx_fast_push_rx_descriptors(rx_queue, true); 11628c2ecf20Sopenharmony_ci } else if (rx_queue && magic == EFX_CHANNEL_MAGIC_RX_DRAIN(rx_queue)) { 11638c2ecf20Sopenharmony_ci efx_farch_handle_drain_event(channel); 11648c2ecf20Sopenharmony_ci } else if (code == _EFX_CHANNEL_MAGIC_TX_DRAIN) { 11658c2ecf20Sopenharmony_ci efx_farch_handle_drain_event(channel); 11668c2ecf20Sopenharmony_ci } else { 11678c2ecf20Sopenharmony_ci netif_dbg(efx, hw, efx->net_dev, "channel %d received " 11688c2ecf20Sopenharmony_ci "generated event "EFX_QWORD_FMT"\n", 11698c2ecf20Sopenharmony_ci channel->channel, EFX_QWORD_VAL(*event)); 11708c2ecf20Sopenharmony_ci } 11718c2ecf20Sopenharmony_ci} 11728c2ecf20Sopenharmony_ci 11738c2ecf20Sopenharmony_cistatic void 11748c2ecf20Sopenharmony_ciefx_farch_handle_driver_event(struct efx_channel *channel, efx_qword_t *event) 11758c2ecf20Sopenharmony_ci{ 11768c2ecf20Sopenharmony_ci struct efx_nic *efx = channel->efx; 11778c2ecf20Sopenharmony_ci unsigned int ev_sub_code; 11788c2ecf20Sopenharmony_ci unsigned int ev_sub_data; 11798c2ecf20Sopenharmony_ci 11808c2ecf20Sopenharmony_ci ev_sub_code = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBCODE); 11818c2ecf20Sopenharmony_ci ev_sub_data = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA); 11828c2ecf20Sopenharmony_ci 11838c2ecf20Sopenharmony_ci switch (ev_sub_code) { 11848c2ecf20Sopenharmony_ci case FSE_AZ_TX_DESCQ_FLS_DONE_EV: 11858c2ecf20Sopenharmony_ci netif_vdbg(efx, hw, efx->net_dev, "channel %d TXQ %d flushed\n", 11868c2ecf20Sopenharmony_ci channel->channel, ev_sub_data); 11878c2ecf20Sopenharmony_ci efx_farch_handle_tx_flush_done(efx, event); 11888c2ecf20Sopenharmony_ci#ifdef CONFIG_SFC_SRIOV 11898c2ecf20Sopenharmony_ci efx_siena_sriov_tx_flush_done(efx, event); 11908c2ecf20Sopenharmony_ci#endif 11918c2ecf20Sopenharmony_ci break; 11928c2ecf20Sopenharmony_ci case FSE_AZ_RX_DESCQ_FLS_DONE_EV: 11938c2ecf20Sopenharmony_ci netif_vdbg(efx, hw, efx->net_dev, "channel %d RXQ %d flushed\n", 11948c2ecf20Sopenharmony_ci channel->channel, ev_sub_data); 11958c2ecf20Sopenharmony_ci efx_farch_handle_rx_flush_done(efx, event); 11968c2ecf20Sopenharmony_ci#ifdef CONFIG_SFC_SRIOV 11978c2ecf20Sopenharmony_ci efx_siena_sriov_rx_flush_done(efx, event); 11988c2ecf20Sopenharmony_ci#endif 11998c2ecf20Sopenharmony_ci break; 12008c2ecf20Sopenharmony_ci case FSE_AZ_EVQ_INIT_DONE_EV: 12018c2ecf20Sopenharmony_ci netif_dbg(efx, hw, efx->net_dev, 12028c2ecf20Sopenharmony_ci "channel %d EVQ %d initialised\n", 12038c2ecf20Sopenharmony_ci channel->channel, ev_sub_data); 12048c2ecf20Sopenharmony_ci break; 12058c2ecf20Sopenharmony_ci case FSE_AZ_SRM_UPD_DONE_EV: 12068c2ecf20Sopenharmony_ci netif_vdbg(efx, hw, efx->net_dev, 12078c2ecf20Sopenharmony_ci "channel %d SRAM update done\n", channel->channel); 12088c2ecf20Sopenharmony_ci break; 12098c2ecf20Sopenharmony_ci case FSE_AZ_WAKE_UP_EV: 12108c2ecf20Sopenharmony_ci netif_vdbg(efx, hw, efx->net_dev, 12118c2ecf20Sopenharmony_ci "channel %d RXQ %d wakeup event\n", 12128c2ecf20Sopenharmony_ci channel->channel, ev_sub_data); 12138c2ecf20Sopenharmony_ci break; 12148c2ecf20Sopenharmony_ci case FSE_AZ_TIMER_EV: 12158c2ecf20Sopenharmony_ci netif_vdbg(efx, hw, efx->net_dev, 12168c2ecf20Sopenharmony_ci "channel %d RX queue %d timer expired\n", 12178c2ecf20Sopenharmony_ci channel->channel, ev_sub_data); 12188c2ecf20Sopenharmony_ci break; 12198c2ecf20Sopenharmony_ci case FSE_AA_RX_RECOVER_EV: 12208c2ecf20Sopenharmony_ci netif_err(efx, rx_err, efx->net_dev, 12218c2ecf20Sopenharmony_ci "channel %d seen DRIVER RX_RESET event. " 12228c2ecf20Sopenharmony_ci "Resetting.\n", channel->channel); 12238c2ecf20Sopenharmony_ci atomic_inc(&efx->rx_reset); 12248c2ecf20Sopenharmony_ci efx_schedule_reset(efx, RESET_TYPE_DISABLE); 12258c2ecf20Sopenharmony_ci break; 12268c2ecf20Sopenharmony_ci case FSE_BZ_RX_DSC_ERROR_EV: 12278c2ecf20Sopenharmony_ci if (ev_sub_data < EFX_VI_BASE) { 12288c2ecf20Sopenharmony_ci netif_err(efx, rx_err, efx->net_dev, 12298c2ecf20Sopenharmony_ci "RX DMA Q %d reports descriptor fetch error." 12308c2ecf20Sopenharmony_ci " RX Q %d is disabled.\n", ev_sub_data, 12318c2ecf20Sopenharmony_ci ev_sub_data); 12328c2ecf20Sopenharmony_ci efx_schedule_reset(efx, RESET_TYPE_DMA_ERROR); 12338c2ecf20Sopenharmony_ci } 12348c2ecf20Sopenharmony_ci#ifdef CONFIG_SFC_SRIOV 12358c2ecf20Sopenharmony_ci else 12368c2ecf20Sopenharmony_ci efx_siena_sriov_desc_fetch_err(efx, ev_sub_data); 12378c2ecf20Sopenharmony_ci#endif 12388c2ecf20Sopenharmony_ci break; 12398c2ecf20Sopenharmony_ci case FSE_BZ_TX_DSC_ERROR_EV: 12408c2ecf20Sopenharmony_ci if (ev_sub_data < EFX_VI_BASE) { 12418c2ecf20Sopenharmony_ci netif_err(efx, tx_err, efx->net_dev, 12428c2ecf20Sopenharmony_ci "TX DMA Q %d reports descriptor fetch error." 12438c2ecf20Sopenharmony_ci " TX Q %d is disabled.\n", ev_sub_data, 12448c2ecf20Sopenharmony_ci ev_sub_data); 12458c2ecf20Sopenharmony_ci efx_schedule_reset(efx, RESET_TYPE_DMA_ERROR); 12468c2ecf20Sopenharmony_ci } 12478c2ecf20Sopenharmony_ci#ifdef CONFIG_SFC_SRIOV 12488c2ecf20Sopenharmony_ci else 12498c2ecf20Sopenharmony_ci efx_siena_sriov_desc_fetch_err(efx, ev_sub_data); 12508c2ecf20Sopenharmony_ci#endif 12518c2ecf20Sopenharmony_ci break; 12528c2ecf20Sopenharmony_ci default: 12538c2ecf20Sopenharmony_ci netif_vdbg(efx, hw, efx->net_dev, 12548c2ecf20Sopenharmony_ci "channel %d unknown driver event code %d " 12558c2ecf20Sopenharmony_ci "data %04x\n", channel->channel, ev_sub_code, 12568c2ecf20Sopenharmony_ci ev_sub_data); 12578c2ecf20Sopenharmony_ci break; 12588c2ecf20Sopenharmony_ci } 12598c2ecf20Sopenharmony_ci} 12608c2ecf20Sopenharmony_ci 12618c2ecf20Sopenharmony_ciint efx_farch_ev_process(struct efx_channel *channel, int budget) 12628c2ecf20Sopenharmony_ci{ 12638c2ecf20Sopenharmony_ci struct efx_nic *efx = channel->efx; 12648c2ecf20Sopenharmony_ci unsigned int read_ptr; 12658c2ecf20Sopenharmony_ci efx_qword_t event, *p_event; 12668c2ecf20Sopenharmony_ci int ev_code; 12678c2ecf20Sopenharmony_ci int spent = 0; 12688c2ecf20Sopenharmony_ci 12698c2ecf20Sopenharmony_ci if (budget <= 0) 12708c2ecf20Sopenharmony_ci return spent; 12718c2ecf20Sopenharmony_ci 12728c2ecf20Sopenharmony_ci read_ptr = channel->eventq_read_ptr; 12738c2ecf20Sopenharmony_ci 12748c2ecf20Sopenharmony_ci for (;;) { 12758c2ecf20Sopenharmony_ci p_event = efx_event(channel, read_ptr); 12768c2ecf20Sopenharmony_ci event = *p_event; 12778c2ecf20Sopenharmony_ci 12788c2ecf20Sopenharmony_ci if (!efx_event_present(&event)) 12798c2ecf20Sopenharmony_ci /* End of events */ 12808c2ecf20Sopenharmony_ci break; 12818c2ecf20Sopenharmony_ci 12828c2ecf20Sopenharmony_ci netif_vdbg(channel->efx, intr, channel->efx->net_dev, 12838c2ecf20Sopenharmony_ci "channel %d event is "EFX_QWORD_FMT"\n", 12848c2ecf20Sopenharmony_ci channel->channel, EFX_QWORD_VAL(event)); 12858c2ecf20Sopenharmony_ci 12868c2ecf20Sopenharmony_ci /* Clear this event by marking it all ones */ 12878c2ecf20Sopenharmony_ci EFX_SET_QWORD(*p_event); 12888c2ecf20Sopenharmony_ci 12898c2ecf20Sopenharmony_ci ++read_ptr; 12908c2ecf20Sopenharmony_ci 12918c2ecf20Sopenharmony_ci ev_code = EFX_QWORD_FIELD(event, FSF_AZ_EV_CODE); 12928c2ecf20Sopenharmony_ci 12938c2ecf20Sopenharmony_ci switch (ev_code) { 12948c2ecf20Sopenharmony_ci case FSE_AZ_EV_CODE_RX_EV: 12958c2ecf20Sopenharmony_ci efx_farch_handle_rx_event(channel, &event); 12968c2ecf20Sopenharmony_ci if (++spent == budget) 12978c2ecf20Sopenharmony_ci goto out; 12988c2ecf20Sopenharmony_ci break; 12998c2ecf20Sopenharmony_ci case FSE_AZ_EV_CODE_TX_EV: 13008c2ecf20Sopenharmony_ci efx_farch_handle_tx_event(channel, &event); 13018c2ecf20Sopenharmony_ci break; 13028c2ecf20Sopenharmony_ci case FSE_AZ_EV_CODE_DRV_GEN_EV: 13038c2ecf20Sopenharmony_ci efx_farch_handle_generated_event(channel, &event); 13048c2ecf20Sopenharmony_ci break; 13058c2ecf20Sopenharmony_ci case FSE_AZ_EV_CODE_DRIVER_EV: 13068c2ecf20Sopenharmony_ci efx_farch_handle_driver_event(channel, &event); 13078c2ecf20Sopenharmony_ci break; 13088c2ecf20Sopenharmony_ci#ifdef CONFIG_SFC_SRIOV 13098c2ecf20Sopenharmony_ci case FSE_CZ_EV_CODE_USER_EV: 13108c2ecf20Sopenharmony_ci efx_siena_sriov_event(channel, &event); 13118c2ecf20Sopenharmony_ci break; 13128c2ecf20Sopenharmony_ci#endif 13138c2ecf20Sopenharmony_ci case FSE_CZ_EV_CODE_MCDI_EV: 13148c2ecf20Sopenharmony_ci efx_mcdi_process_event(channel, &event); 13158c2ecf20Sopenharmony_ci break; 13168c2ecf20Sopenharmony_ci case FSE_AZ_EV_CODE_GLOBAL_EV: 13178c2ecf20Sopenharmony_ci if (efx->type->handle_global_event && 13188c2ecf20Sopenharmony_ci efx->type->handle_global_event(channel, &event)) 13198c2ecf20Sopenharmony_ci break; 13208c2ecf20Sopenharmony_ci fallthrough; 13218c2ecf20Sopenharmony_ci default: 13228c2ecf20Sopenharmony_ci netif_err(channel->efx, hw, channel->efx->net_dev, 13238c2ecf20Sopenharmony_ci "channel %d unknown event type %d (data " 13248c2ecf20Sopenharmony_ci EFX_QWORD_FMT ")\n", channel->channel, 13258c2ecf20Sopenharmony_ci ev_code, EFX_QWORD_VAL(event)); 13268c2ecf20Sopenharmony_ci } 13278c2ecf20Sopenharmony_ci } 13288c2ecf20Sopenharmony_ci 13298c2ecf20Sopenharmony_ciout: 13308c2ecf20Sopenharmony_ci channel->eventq_read_ptr = read_ptr; 13318c2ecf20Sopenharmony_ci return spent; 13328c2ecf20Sopenharmony_ci} 13338c2ecf20Sopenharmony_ci 13348c2ecf20Sopenharmony_ci/* Allocate buffer table entries for event queue */ 13358c2ecf20Sopenharmony_ciint efx_farch_ev_probe(struct efx_channel *channel) 13368c2ecf20Sopenharmony_ci{ 13378c2ecf20Sopenharmony_ci struct efx_nic *efx = channel->efx; 13388c2ecf20Sopenharmony_ci unsigned entries; 13398c2ecf20Sopenharmony_ci 13408c2ecf20Sopenharmony_ci entries = channel->eventq_mask + 1; 13418c2ecf20Sopenharmony_ci return efx_alloc_special_buffer(efx, &channel->eventq, 13428c2ecf20Sopenharmony_ci entries * sizeof(efx_qword_t)); 13438c2ecf20Sopenharmony_ci} 13448c2ecf20Sopenharmony_ci 13458c2ecf20Sopenharmony_ciint efx_farch_ev_init(struct efx_channel *channel) 13468c2ecf20Sopenharmony_ci{ 13478c2ecf20Sopenharmony_ci efx_oword_t reg; 13488c2ecf20Sopenharmony_ci struct efx_nic *efx = channel->efx; 13498c2ecf20Sopenharmony_ci 13508c2ecf20Sopenharmony_ci netif_dbg(efx, hw, efx->net_dev, 13518c2ecf20Sopenharmony_ci "channel %d event queue in special buffers %d-%d\n", 13528c2ecf20Sopenharmony_ci channel->channel, channel->eventq.index, 13538c2ecf20Sopenharmony_ci channel->eventq.index + channel->eventq.entries - 1); 13548c2ecf20Sopenharmony_ci 13558c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_3(reg, 13568c2ecf20Sopenharmony_ci FRF_CZ_TIMER_Q_EN, 1, 13578c2ecf20Sopenharmony_ci FRF_CZ_HOST_NOTIFY_MODE, 0, 13588c2ecf20Sopenharmony_ci FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS); 13598c2ecf20Sopenharmony_ci efx_writeo_table(efx, ®, FR_BZ_TIMER_TBL, channel->channel); 13608c2ecf20Sopenharmony_ci 13618c2ecf20Sopenharmony_ci /* Pin event queue buffer */ 13628c2ecf20Sopenharmony_ci efx_init_special_buffer(efx, &channel->eventq); 13638c2ecf20Sopenharmony_ci 13648c2ecf20Sopenharmony_ci /* Fill event queue with all ones (i.e. empty events) */ 13658c2ecf20Sopenharmony_ci memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len); 13668c2ecf20Sopenharmony_ci 13678c2ecf20Sopenharmony_ci /* Push event queue to card */ 13688c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_3(reg, 13698c2ecf20Sopenharmony_ci FRF_AZ_EVQ_EN, 1, 13708c2ecf20Sopenharmony_ci FRF_AZ_EVQ_SIZE, __ffs(channel->eventq.entries), 13718c2ecf20Sopenharmony_ci FRF_AZ_EVQ_BUF_BASE_ID, channel->eventq.index); 13728c2ecf20Sopenharmony_ci efx_writeo_table(efx, ®, efx->type->evq_ptr_tbl_base, 13738c2ecf20Sopenharmony_ci channel->channel); 13748c2ecf20Sopenharmony_ci 13758c2ecf20Sopenharmony_ci return 0; 13768c2ecf20Sopenharmony_ci} 13778c2ecf20Sopenharmony_ci 13788c2ecf20Sopenharmony_civoid efx_farch_ev_fini(struct efx_channel *channel) 13798c2ecf20Sopenharmony_ci{ 13808c2ecf20Sopenharmony_ci efx_oword_t reg; 13818c2ecf20Sopenharmony_ci struct efx_nic *efx = channel->efx; 13828c2ecf20Sopenharmony_ci 13838c2ecf20Sopenharmony_ci /* Remove event queue from card */ 13848c2ecf20Sopenharmony_ci EFX_ZERO_OWORD(reg); 13858c2ecf20Sopenharmony_ci efx_writeo_table(efx, ®, efx->type->evq_ptr_tbl_base, 13868c2ecf20Sopenharmony_ci channel->channel); 13878c2ecf20Sopenharmony_ci efx_writeo_table(efx, ®, FR_BZ_TIMER_TBL, channel->channel); 13888c2ecf20Sopenharmony_ci 13898c2ecf20Sopenharmony_ci /* Unpin event queue */ 13908c2ecf20Sopenharmony_ci efx_fini_special_buffer(efx, &channel->eventq); 13918c2ecf20Sopenharmony_ci} 13928c2ecf20Sopenharmony_ci 13938c2ecf20Sopenharmony_ci/* Free buffers backing event queue */ 13948c2ecf20Sopenharmony_civoid efx_farch_ev_remove(struct efx_channel *channel) 13958c2ecf20Sopenharmony_ci{ 13968c2ecf20Sopenharmony_ci efx_free_special_buffer(channel->efx, &channel->eventq); 13978c2ecf20Sopenharmony_ci} 13988c2ecf20Sopenharmony_ci 13998c2ecf20Sopenharmony_ci 14008c2ecf20Sopenharmony_civoid efx_farch_ev_test_generate(struct efx_channel *channel) 14018c2ecf20Sopenharmony_ci{ 14028c2ecf20Sopenharmony_ci efx_farch_magic_event(channel, EFX_CHANNEL_MAGIC_TEST(channel)); 14038c2ecf20Sopenharmony_ci} 14048c2ecf20Sopenharmony_ci 14058c2ecf20Sopenharmony_civoid efx_farch_rx_defer_refill(struct efx_rx_queue *rx_queue) 14068c2ecf20Sopenharmony_ci{ 14078c2ecf20Sopenharmony_ci efx_farch_magic_event(efx_rx_queue_channel(rx_queue), 14088c2ecf20Sopenharmony_ci EFX_CHANNEL_MAGIC_FILL(rx_queue)); 14098c2ecf20Sopenharmony_ci} 14108c2ecf20Sopenharmony_ci 14118c2ecf20Sopenharmony_ci/************************************************************************** 14128c2ecf20Sopenharmony_ci * 14138c2ecf20Sopenharmony_ci * Hardware interrupts 14148c2ecf20Sopenharmony_ci * The hardware interrupt handler does very little work; all the event 14158c2ecf20Sopenharmony_ci * queue processing is carried out by per-channel tasklets. 14168c2ecf20Sopenharmony_ci * 14178c2ecf20Sopenharmony_ci **************************************************************************/ 14188c2ecf20Sopenharmony_ci 14198c2ecf20Sopenharmony_ci/* Enable/disable/generate interrupts */ 14208c2ecf20Sopenharmony_cistatic inline void efx_farch_interrupts(struct efx_nic *efx, 14218c2ecf20Sopenharmony_ci bool enabled, bool force) 14228c2ecf20Sopenharmony_ci{ 14238c2ecf20Sopenharmony_ci efx_oword_t int_en_reg_ker; 14248c2ecf20Sopenharmony_ci 14258c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_3(int_en_reg_ker, 14268c2ecf20Sopenharmony_ci FRF_AZ_KER_INT_LEVE_SEL, efx->irq_level, 14278c2ecf20Sopenharmony_ci FRF_AZ_KER_INT_KER, force, 14288c2ecf20Sopenharmony_ci FRF_AZ_DRV_INT_EN_KER, enabled); 14298c2ecf20Sopenharmony_ci efx_writeo(efx, &int_en_reg_ker, FR_AZ_INT_EN_KER); 14308c2ecf20Sopenharmony_ci} 14318c2ecf20Sopenharmony_ci 14328c2ecf20Sopenharmony_civoid efx_farch_irq_enable_master(struct efx_nic *efx) 14338c2ecf20Sopenharmony_ci{ 14348c2ecf20Sopenharmony_ci EFX_ZERO_OWORD(*((efx_oword_t *) efx->irq_status.addr)); 14358c2ecf20Sopenharmony_ci wmb(); /* Ensure interrupt vector is clear before interrupts enabled */ 14368c2ecf20Sopenharmony_ci 14378c2ecf20Sopenharmony_ci efx_farch_interrupts(efx, true, false); 14388c2ecf20Sopenharmony_ci} 14398c2ecf20Sopenharmony_ci 14408c2ecf20Sopenharmony_civoid efx_farch_irq_disable_master(struct efx_nic *efx) 14418c2ecf20Sopenharmony_ci{ 14428c2ecf20Sopenharmony_ci /* Disable interrupts */ 14438c2ecf20Sopenharmony_ci efx_farch_interrupts(efx, false, false); 14448c2ecf20Sopenharmony_ci} 14458c2ecf20Sopenharmony_ci 14468c2ecf20Sopenharmony_ci/* Generate a test interrupt 14478c2ecf20Sopenharmony_ci * Interrupt must already have been enabled, otherwise nasty things 14488c2ecf20Sopenharmony_ci * may happen. 14498c2ecf20Sopenharmony_ci */ 14508c2ecf20Sopenharmony_ciint efx_farch_irq_test_generate(struct efx_nic *efx) 14518c2ecf20Sopenharmony_ci{ 14528c2ecf20Sopenharmony_ci efx_farch_interrupts(efx, true, true); 14538c2ecf20Sopenharmony_ci return 0; 14548c2ecf20Sopenharmony_ci} 14558c2ecf20Sopenharmony_ci 14568c2ecf20Sopenharmony_ci/* Process a fatal interrupt 14578c2ecf20Sopenharmony_ci * Disable bus mastering ASAP and schedule a reset 14588c2ecf20Sopenharmony_ci */ 14598c2ecf20Sopenharmony_ciirqreturn_t efx_farch_fatal_interrupt(struct efx_nic *efx) 14608c2ecf20Sopenharmony_ci{ 14618c2ecf20Sopenharmony_ci efx_oword_t *int_ker = efx->irq_status.addr; 14628c2ecf20Sopenharmony_ci efx_oword_t fatal_intr; 14638c2ecf20Sopenharmony_ci int error, mem_perr; 14648c2ecf20Sopenharmony_ci 14658c2ecf20Sopenharmony_ci efx_reado(efx, &fatal_intr, FR_AZ_FATAL_INTR_KER); 14668c2ecf20Sopenharmony_ci error = EFX_OWORD_FIELD(fatal_intr, FRF_AZ_FATAL_INTR); 14678c2ecf20Sopenharmony_ci 14688c2ecf20Sopenharmony_ci netif_err(efx, hw, efx->net_dev, "SYSTEM ERROR "EFX_OWORD_FMT" status " 14698c2ecf20Sopenharmony_ci EFX_OWORD_FMT ": %s\n", EFX_OWORD_VAL(*int_ker), 14708c2ecf20Sopenharmony_ci EFX_OWORD_VAL(fatal_intr), 14718c2ecf20Sopenharmony_ci error ? "disabling bus mastering" : "no recognised error"); 14728c2ecf20Sopenharmony_ci 14738c2ecf20Sopenharmony_ci /* If this is a memory parity error dump which blocks are offending */ 14748c2ecf20Sopenharmony_ci mem_perr = (EFX_OWORD_FIELD(fatal_intr, FRF_AZ_MEM_PERR_INT_KER) || 14758c2ecf20Sopenharmony_ci EFX_OWORD_FIELD(fatal_intr, FRF_AZ_SRM_PERR_INT_KER)); 14768c2ecf20Sopenharmony_ci if (mem_perr) { 14778c2ecf20Sopenharmony_ci efx_oword_t reg; 14788c2ecf20Sopenharmony_ci efx_reado(efx, ®, FR_AZ_MEM_STAT); 14798c2ecf20Sopenharmony_ci netif_err(efx, hw, efx->net_dev, 14808c2ecf20Sopenharmony_ci "SYSTEM ERROR: memory parity error "EFX_OWORD_FMT"\n", 14818c2ecf20Sopenharmony_ci EFX_OWORD_VAL(reg)); 14828c2ecf20Sopenharmony_ci } 14838c2ecf20Sopenharmony_ci 14848c2ecf20Sopenharmony_ci /* Disable both devices */ 14858c2ecf20Sopenharmony_ci pci_clear_master(efx->pci_dev); 14868c2ecf20Sopenharmony_ci efx_farch_irq_disable_master(efx); 14878c2ecf20Sopenharmony_ci 14888c2ecf20Sopenharmony_ci /* Count errors and reset or disable the NIC accordingly */ 14898c2ecf20Sopenharmony_ci if (efx->int_error_count == 0 || 14908c2ecf20Sopenharmony_ci time_after(jiffies, efx->int_error_expire)) { 14918c2ecf20Sopenharmony_ci efx->int_error_count = 0; 14928c2ecf20Sopenharmony_ci efx->int_error_expire = 14938c2ecf20Sopenharmony_ci jiffies + EFX_INT_ERROR_EXPIRE * HZ; 14948c2ecf20Sopenharmony_ci } 14958c2ecf20Sopenharmony_ci if (++efx->int_error_count < EFX_MAX_INT_ERRORS) { 14968c2ecf20Sopenharmony_ci netif_err(efx, hw, efx->net_dev, 14978c2ecf20Sopenharmony_ci "SYSTEM ERROR - reset scheduled\n"); 14988c2ecf20Sopenharmony_ci efx_schedule_reset(efx, RESET_TYPE_INT_ERROR); 14998c2ecf20Sopenharmony_ci } else { 15008c2ecf20Sopenharmony_ci netif_err(efx, hw, efx->net_dev, 15018c2ecf20Sopenharmony_ci "SYSTEM ERROR - max number of errors seen." 15028c2ecf20Sopenharmony_ci "NIC will be disabled\n"); 15038c2ecf20Sopenharmony_ci efx_schedule_reset(efx, RESET_TYPE_DISABLE); 15048c2ecf20Sopenharmony_ci } 15058c2ecf20Sopenharmony_ci 15068c2ecf20Sopenharmony_ci return IRQ_HANDLED; 15078c2ecf20Sopenharmony_ci} 15088c2ecf20Sopenharmony_ci 15098c2ecf20Sopenharmony_ci/* Handle a legacy interrupt 15108c2ecf20Sopenharmony_ci * Acknowledges the interrupt and schedule event queue processing. 15118c2ecf20Sopenharmony_ci */ 15128c2ecf20Sopenharmony_ciirqreturn_t efx_farch_legacy_interrupt(int irq, void *dev_id) 15138c2ecf20Sopenharmony_ci{ 15148c2ecf20Sopenharmony_ci struct efx_nic *efx = dev_id; 15158c2ecf20Sopenharmony_ci bool soft_enabled = READ_ONCE(efx->irq_soft_enabled); 15168c2ecf20Sopenharmony_ci efx_oword_t *int_ker = efx->irq_status.addr; 15178c2ecf20Sopenharmony_ci irqreturn_t result = IRQ_NONE; 15188c2ecf20Sopenharmony_ci struct efx_channel *channel; 15198c2ecf20Sopenharmony_ci efx_dword_t reg; 15208c2ecf20Sopenharmony_ci u32 queues; 15218c2ecf20Sopenharmony_ci int syserr; 15228c2ecf20Sopenharmony_ci 15238c2ecf20Sopenharmony_ci /* Read the ISR which also ACKs the interrupts */ 15248c2ecf20Sopenharmony_ci efx_readd(efx, ®, FR_BZ_INT_ISR0); 15258c2ecf20Sopenharmony_ci queues = EFX_EXTRACT_DWORD(reg, 0, 31); 15268c2ecf20Sopenharmony_ci 15278c2ecf20Sopenharmony_ci /* Legacy interrupts are disabled too late by the EEH kernel 15288c2ecf20Sopenharmony_ci * code. Disable them earlier. 15298c2ecf20Sopenharmony_ci * If an EEH error occurred, the read will have returned all ones. 15308c2ecf20Sopenharmony_ci */ 15318c2ecf20Sopenharmony_ci if (EFX_DWORD_IS_ALL_ONES(reg) && efx_try_recovery(efx) && 15328c2ecf20Sopenharmony_ci !efx->eeh_disabled_legacy_irq) { 15338c2ecf20Sopenharmony_ci disable_irq_nosync(efx->legacy_irq); 15348c2ecf20Sopenharmony_ci efx->eeh_disabled_legacy_irq = true; 15358c2ecf20Sopenharmony_ci } 15368c2ecf20Sopenharmony_ci 15378c2ecf20Sopenharmony_ci /* Handle non-event-queue sources */ 15388c2ecf20Sopenharmony_ci if (queues & (1U << efx->irq_level) && soft_enabled) { 15398c2ecf20Sopenharmony_ci syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT); 15408c2ecf20Sopenharmony_ci if (unlikely(syserr)) 15418c2ecf20Sopenharmony_ci return efx_farch_fatal_interrupt(efx); 15428c2ecf20Sopenharmony_ci efx->last_irq_cpu = raw_smp_processor_id(); 15438c2ecf20Sopenharmony_ci } 15448c2ecf20Sopenharmony_ci 15458c2ecf20Sopenharmony_ci if (queues != 0) { 15468c2ecf20Sopenharmony_ci efx->irq_zero_count = 0; 15478c2ecf20Sopenharmony_ci 15488c2ecf20Sopenharmony_ci /* Schedule processing of any interrupting queues */ 15498c2ecf20Sopenharmony_ci if (likely(soft_enabled)) { 15508c2ecf20Sopenharmony_ci efx_for_each_channel(channel, efx) { 15518c2ecf20Sopenharmony_ci if (queues & 1) 15528c2ecf20Sopenharmony_ci efx_schedule_channel_irq(channel); 15538c2ecf20Sopenharmony_ci queues >>= 1; 15548c2ecf20Sopenharmony_ci } 15558c2ecf20Sopenharmony_ci } 15568c2ecf20Sopenharmony_ci result = IRQ_HANDLED; 15578c2ecf20Sopenharmony_ci 15588c2ecf20Sopenharmony_ci } else { 15598c2ecf20Sopenharmony_ci efx_qword_t *event; 15608c2ecf20Sopenharmony_ci 15618c2ecf20Sopenharmony_ci /* Legacy ISR read can return zero once (SF bug 15783) */ 15628c2ecf20Sopenharmony_ci 15638c2ecf20Sopenharmony_ci /* We can't return IRQ_HANDLED more than once on seeing ISR=0 15648c2ecf20Sopenharmony_ci * because this might be a shared interrupt. */ 15658c2ecf20Sopenharmony_ci if (efx->irq_zero_count++ == 0) 15668c2ecf20Sopenharmony_ci result = IRQ_HANDLED; 15678c2ecf20Sopenharmony_ci 15688c2ecf20Sopenharmony_ci /* Ensure we schedule or rearm all event queues */ 15698c2ecf20Sopenharmony_ci if (likely(soft_enabled)) { 15708c2ecf20Sopenharmony_ci efx_for_each_channel(channel, efx) { 15718c2ecf20Sopenharmony_ci event = efx_event(channel, 15728c2ecf20Sopenharmony_ci channel->eventq_read_ptr); 15738c2ecf20Sopenharmony_ci if (efx_event_present(event)) 15748c2ecf20Sopenharmony_ci efx_schedule_channel_irq(channel); 15758c2ecf20Sopenharmony_ci else 15768c2ecf20Sopenharmony_ci efx_farch_ev_read_ack(channel); 15778c2ecf20Sopenharmony_ci } 15788c2ecf20Sopenharmony_ci } 15798c2ecf20Sopenharmony_ci } 15808c2ecf20Sopenharmony_ci 15818c2ecf20Sopenharmony_ci if (result == IRQ_HANDLED) 15828c2ecf20Sopenharmony_ci netif_vdbg(efx, intr, efx->net_dev, 15838c2ecf20Sopenharmony_ci "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n", 15848c2ecf20Sopenharmony_ci irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg)); 15858c2ecf20Sopenharmony_ci 15868c2ecf20Sopenharmony_ci return result; 15878c2ecf20Sopenharmony_ci} 15888c2ecf20Sopenharmony_ci 15898c2ecf20Sopenharmony_ci/* Handle an MSI interrupt 15908c2ecf20Sopenharmony_ci * 15918c2ecf20Sopenharmony_ci * Handle an MSI hardware interrupt. This routine schedules event 15928c2ecf20Sopenharmony_ci * queue processing. No interrupt acknowledgement cycle is necessary. 15938c2ecf20Sopenharmony_ci * Also, we never need to check that the interrupt is for us, since 15948c2ecf20Sopenharmony_ci * MSI interrupts cannot be shared. 15958c2ecf20Sopenharmony_ci */ 15968c2ecf20Sopenharmony_ciirqreturn_t efx_farch_msi_interrupt(int irq, void *dev_id) 15978c2ecf20Sopenharmony_ci{ 15988c2ecf20Sopenharmony_ci struct efx_msi_context *context = dev_id; 15998c2ecf20Sopenharmony_ci struct efx_nic *efx = context->efx; 16008c2ecf20Sopenharmony_ci efx_oword_t *int_ker = efx->irq_status.addr; 16018c2ecf20Sopenharmony_ci int syserr; 16028c2ecf20Sopenharmony_ci 16038c2ecf20Sopenharmony_ci netif_vdbg(efx, intr, efx->net_dev, 16048c2ecf20Sopenharmony_ci "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n", 16058c2ecf20Sopenharmony_ci irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker)); 16068c2ecf20Sopenharmony_ci 16078c2ecf20Sopenharmony_ci if (!likely(READ_ONCE(efx->irq_soft_enabled))) 16088c2ecf20Sopenharmony_ci return IRQ_HANDLED; 16098c2ecf20Sopenharmony_ci 16108c2ecf20Sopenharmony_ci /* Handle non-event-queue sources */ 16118c2ecf20Sopenharmony_ci if (context->index == efx->irq_level) { 16128c2ecf20Sopenharmony_ci syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT); 16138c2ecf20Sopenharmony_ci if (unlikely(syserr)) 16148c2ecf20Sopenharmony_ci return efx_farch_fatal_interrupt(efx); 16158c2ecf20Sopenharmony_ci efx->last_irq_cpu = raw_smp_processor_id(); 16168c2ecf20Sopenharmony_ci } 16178c2ecf20Sopenharmony_ci 16188c2ecf20Sopenharmony_ci /* Schedule processing of the channel */ 16198c2ecf20Sopenharmony_ci efx_schedule_channel_irq(efx->channel[context->index]); 16208c2ecf20Sopenharmony_ci 16218c2ecf20Sopenharmony_ci return IRQ_HANDLED; 16228c2ecf20Sopenharmony_ci} 16238c2ecf20Sopenharmony_ci 16248c2ecf20Sopenharmony_ci/* Setup RSS indirection table. 16258c2ecf20Sopenharmony_ci * This maps from the hash value of the packet to RXQ 16268c2ecf20Sopenharmony_ci */ 16278c2ecf20Sopenharmony_civoid efx_farch_rx_push_indir_table(struct efx_nic *efx) 16288c2ecf20Sopenharmony_ci{ 16298c2ecf20Sopenharmony_ci size_t i = 0; 16308c2ecf20Sopenharmony_ci efx_dword_t dword; 16318c2ecf20Sopenharmony_ci 16328c2ecf20Sopenharmony_ci BUILD_BUG_ON(ARRAY_SIZE(efx->rss_context.rx_indir_table) != 16338c2ecf20Sopenharmony_ci FR_BZ_RX_INDIRECTION_TBL_ROWS); 16348c2ecf20Sopenharmony_ci 16358c2ecf20Sopenharmony_ci for (i = 0; i < FR_BZ_RX_INDIRECTION_TBL_ROWS; i++) { 16368c2ecf20Sopenharmony_ci EFX_POPULATE_DWORD_1(dword, FRF_BZ_IT_QUEUE, 16378c2ecf20Sopenharmony_ci efx->rss_context.rx_indir_table[i]); 16388c2ecf20Sopenharmony_ci efx_writed(efx, &dword, 16398c2ecf20Sopenharmony_ci FR_BZ_RX_INDIRECTION_TBL + 16408c2ecf20Sopenharmony_ci FR_BZ_RX_INDIRECTION_TBL_STEP * i); 16418c2ecf20Sopenharmony_ci } 16428c2ecf20Sopenharmony_ci} 16438c2ecf20Sopenharmony_ci 16448c2ecf20Sopenharmony_civoid efx_farch_rx_pull_indir_table(struct efx_nic *efx) 16458c2ecf20Sopenharmony_ci{ 16468c2ecf20Sopenharmony_ci size_t i = 0; 16478c2ecf20Sopenharmony_ci efx_dword_t dword; 16488c2ecf20Sopenharmony_ci 16498c2ecf20Sopenharmony_ci BUILD_BUG_ON(ARRAY_SIZE(efx->rss_context.rx_indir_table) != 16508c2ecf20Sopenharmony_ci FR_BZ_RX_INDIRECTION_TBL_ROWS); 16518c2ecf20Sopenharmony_ci 16528c2ecf20Sopenharmony_ci for (i = 0; i < FR_BZ_RX_INDIRECTION_TBL_ROWS; i++) { 16538c2ecf20Sopenharmony_ci efx_readd(efx, &dword, 16548c2ecf20Sopenharmony_ci FR_BZ_RX_INDIRECTION_TBL + 16558c2ecf20Sopenharmony_ci FR_BZ_RX_INDIRECTION_TBL_STEP * i); 16568c2ecf20Sopenharmony_ci efx->rss_context.rx_indir_table[i] = EFX_DWORD_FIELD(dword, FRF_BZ_IT_QUEUE); 16578c2ecf20Sopenharmony_ci } 16588c2ecf20Sopenharmony_ci} 16598c2ecf20Sopenharmony_ci 16608c2ecf20Sopenharmony_ci/* Looks at available SRAM resources and works out how many queues we 16618c2ecf20Sopenharmony_ci * can support, and where things like descriptor caches should live. 16628c2ecf20Sopenharmony_ci * 16638c2ecf20Sopenharmony_ci * SRAM is split up as follows: 16648c2ecf20Sopenharmony_ci * 0 buftbl entries for channels 16658c2ecf20Sopenharmony_ci * efx->vf_buftbl_base buftbl entries for SR-IOV 16668c2ecf20Sopenharmony_ci * efx->rx_dc_base RX descriptor caches 16678c2ecf20Sopenharmony_ci * efx->tx_dc_base TX descriptor caches 16688c2ecf20Sopenharmony_ci */ 16698c2ecf20Sopenharmony_civoid efx_farch_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw) 16708c2ecf20Sopenharmony_ci{ 16718c2ecf20Sopenharmony_ci unsigned vi_count, buftbl_min, total_tx_channels; 16728c2ecf20Sopenharmony_ci 16738c2ecf20Sopenharmony_ci#ifdef CONFIG_SFC_SRIOV 16748c2ecf20Sopenharmony_ci struct siena_nic_data *nic_data = efx->nic_data; 16758c2ecf20Sopenharmony_ci#endif 16768c2ecf20Sopenharmony_ci 16778c2ecf20Sopenharmony_ci total_tx_channels = efx->n_tx_channels + efx->n_extra_tx_channels; 16788c2ecf20Sopenharmony_ci /* Account for the buffer table entries backing the datapath channels 16798c2ecf20Sopenharmony_ci * and the descriptor caches for those channels. 16808c2ecf20Sopenharmony_ci */ 16818c2ecf20Sopenharmony_ci buftbl_min = ((efx->n_rx_channels * EFX_MAX_DMAQ_SIZE + 16828c2ecf20Sopenharmony_ci total_tx_channels * EFX_MAX_TXQ_PER_CHANNEL * EFX_MAX_DMAQ_SIZE + 16838c2ecf20Sopenharmony_ci efx->n_channels * EFX_MAX_EVQ_SIZE) 16848c2ecf20Sopenharmony_ci * sizeof(efx_qword_t) / EFX_BUF_SIZE); 16858c2ecf20Sopenharmony_ci vi_count = max(efx->n_channels, total_tx_channels * EFX_MAX_TXQ_PER_CHANNEL); 16868c2ecf20Sopenharmony_ci 16878c2ecf20Sopenharmony_ci#ifdef CONFIG_SFC_SRIOV 16888c2ecf20Sopenharmony_ci if (efx->type->sriov_wanted) { 16898c2ecf20Sopenharmony_ci if (efx->type->sriov_wanted(efx)) { 16908c2ecf20Sopenharmony_ci unsigned vi_dc_entries, buftbl_free; 16918c2ecf20Sopenharmony_ci unsigned entries_per_vf, vf_limit; 16928c2ecf20Sopenharmony_ci 16938c2ecf20Sopenharmony_ci nic_data->vf_buftbl_base = buftbl_min; 16948c2ecf20Sopenharmony_ci 16958c2ecf20Sopenharmony_ci vi_dc_entries = RX_DC_ENTRIES + TX_DC_ENTRIES; 16968c2ecf20Sopenharmony_ci vi_count = max(vi_count, EFX_VI_BASE); 16978c2ecf20Sopenharmony_ci buftbl_free = (sram_lim_qw - buftbl_min - 16988c2ecf20Sopenharmony_ci vi_count * vi_dc_entries); 16998c2ecf20Sopenharmony_ci 17008c2ecf20Sopenharmony_ci entries_per_vf = ((vi_dc_entries + 17018c2ecf20Sopenharmony_ci EFX_VF_BUFTBL_PER_VI) * 17028c2ecf20Sopenharmony_ci efx_vf_size(efx)); 17038c2ecf20Sopenharmony_ci vf_limit = min(buftbl_free / entries_per_vf, 17048c2ecf20Sopenharmony_ci (1024U - EFX_VI_BASE) >> efx->vi_scale); 17058c2ecf20Sopenharmony_ci 17068c2ecf20Sopenharmony_ci if (efx->vf_count > vf_limit) { 17078c2ecf20Sopenharmony_ci netif_err(efx, probe, efx->net_dev, 17088c2ecf20Sopenharmony_ci "Reducing VF count from from %d to %d\n", 17098c2ecf20Sopenharmony_ci efx->vf_count, vf_limit); 17108c2ecf20Sopenharmony_ci efx->vf_count = vf_limit; 17118c2ecf20Sopenharmony_ci } 17128c2ecf20Sopenharmony_ci vi_count += efx->vf_count * efx_vf_size(efx); 17138c2ecf20Sopenharmony_ci } 17148c2ecf20Sopenharmony_ci } 17158c2ecf20Sopenharmony_ci#endif 17168c2ecf20Sopenharmony_ci 17178c2ecf20Sopenharmony_ci efx->tx_dc_base = sram_lim_qw - vi_count * TX_DC_ENTRIES; 17188c2ecf20Sopenharmony_ci efx->rx_dc_base = efx->tx_dc_base - vi_count * RX_DC_ENTRIES; 17198c2ecf20Sopenharmony_ci} 17208c2ecf20Sopenharmony_ci 17218c2ecf20Sopenharmony_ciu32 efx_farch_fpga_ver(struct efx_nic *efx) 17228c2ecf20Sopenharmony_ci{ 17238c2ecf20Sopenharmony_ci efx_oword_t altera_build; 17248c2ecf20Sopenharmony_ci efx_reado(efx, &altera_build, FR_AZ_ALTERA_BUILD); 17258c2ecf20Sopenharmony_ci return EFX_OWORD_FIELD(altera_build, FRF_AZ_ALTERA_BUILD_VER); 17268c2ecf20Sopenharmony_ci} 17278c2ecf20Sopenharmony_ci 17288c2ecf20Sopenharmony_civoid efx_farch_init_common(struct efx_nic *efx) 17298c2ecf20Sopenharmony_ci{ 17308c2ecf20Sopenharmony_ci efx_oword_t temp; 17318c2ecf20Sopenharmony_ci 17328c2ecf20Sopenharmony_ci /* Set positions of descriptor caches in SRAM. */ 17338c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_TX_DC_BASE_ADR, efx->tx_dc_base); 17348c2ecf20Sopenharmony_ci efx_writeo(efx, &temp, FR_AZ_SRM_TX_DC_CFG); 17358c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_RX_DC_BASE_ADR, efx->rx_dc_base); 17368c2ecf20Sopenharmony_ci efx_writeo(efx, &temp, FR_AZ_SRM_RX_DC_CFG); 17378c2ecf20Sopenharmony_ci 17388c2ecf20Sopenharmony_ci /* Set TX descriptor cache size. */ 17398c2ecf20Sopenharmony_ci BUILD_BUG_ON(TX_DC_ENTRIES != (8 << TX_DC_ENTRIES_ORDER)); 17408c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_1(temp, FRF_AZ_TX_DC_SIZE, TX_DC_ENTRIES_ORDER); 17418c2ecf20Sopenharmony_ci efx_writeo(efx, &temp, FR_AZ_TX_DC_CFG); 17428c2ecf20Sopenharmony_ci 17438c2ecf20Sopenharmony_ci /* Set RX descriptor cache size. Set low watermark to size-8, as 17448c2ecf20Sopenharmony_ci * this allows most efficient prefetching. 17458c2ecf20Sopenharmony_ci */ 17468c2ecf20Sopenharmony_ci BUILD_BUG_ON(RX_DC_ENTRIES != (8 << RX_DC_ENTRIES_ORDER)); 17478c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_SIZE, RX_DC_ENTRIES_ORDER); 17488c2ecf20Sopenharmony_ci efx_writeo(efx, &temp, FR_AZ_RX_DC_CFG); 17498c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_PF_LWM, RX_DC_ENTRIES - 8); 17508c2ecf20Sopenharmony_ci efx_writeo(efx, &temp, FR_AZ_RX_DC_PF_WM); 17518c2ecf20Sopenharmony_ci 17528c2ecf20Sopenharmony_ci /* Program INT_KER address */ 17538c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_2(temp, 17548c2ecf20Sopenharmony_ci FRF_AZ_NORM_INT_VEC_DIS_KER, 17558c2ecf20Sopenharmony_ci EFX_INT_MODE_USE_MSI(efx), 17568c2ecf20Sopenharmony_ci FRF_AZ_INT_ADR_KER, efx->irq_status.dma_addr); 17578c2ecf20Sopenharmony_ci efx_writeo(efx, &temp, FR_AZ_INT_ADR_KER); 17588c2ecf20Sopenharmony_ci 17598c2ecf20Sopenharmony_ci if (EFX_WORKAROUND_17213(efx) && !EFX_INT_MODE_USE_MSI(efx)) 17608c2ecf20Sopenharmony_ci /* Use an interrupt level unused by event queues */ 17618c2ecf20Sopenharmony_ci efx->irq_level = 0x1f; 17628c2ecf20Sopenharmony_ci else 17638c2ecf20Sopenharmony_ci /* Use a valid MSI-X vector */ 17648c2ecf20Sopenharmony_ci efx->irq_level = 0; 17658c2ecf20Sopenharmony_ci 17668c2ecf20Sopenharmony_ci /* Enable all the genuinely fatal interrupts. (They are still 17678c2ecf20Sopenharmony_ci * masked by the overall interrupt mask, controlled by 17688c2ecf20Sopenharmony_ci * falcon_interrupts()). 17698c2ecf20Sopenharmony_ci * 17708c2ecf20Sopenharmony_ci * Note: All other fatal interrupts are enabled 17718c2ecf20Sopenharmony_ci */ 17728c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_3(temp, 17738c2ecf20Sopenharmony_ci FRF_AZ_ILL_ADR_INT_KER_EN, 1, 17748c2ecf20Sopenharmony_ci FRF_AZ_RBUF_OWN_INT_KER_EN, 1, 17758c2ecf20Sopenharmony_ci FRF_AZ_TBUF_OWN_INT_KER_EN, 1); 17768c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(temp, FRF_CZ_SRAM_PERR_INT_P_KER_EN, 1); 17778c2ecf20Sopenharmony_ci EFX_INVERT_OWORD(temp); 17788c2ecf20Sopenharmony_ci efx_writeo(efx, &temp, FR_AZ_FATAL_INTR_KER); 17798c2ecf20Sopenharmony_ci 17808c2ecf20Sopenharmony_ci /* Disable the ugly timer-based TX DMA backoff and allow TX DMA to be 17818c2ecf20Sopenharmony_ci * controlled by the RX FIFO fill level. Set arbitration to one pkt/Q. 17828c2ecf20Sopenharmony_ci */ 17838c2ecf20Sopenharmony_ci efx_reado(efx, &temp, FR_AZ_TX_RESERVED); 17848c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER, 0xfe); 17858c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER_EN, 1); 17868c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_ONE_PKT_PER_Q, 1); 17878c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PUSH_EN, 1); 17888c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_DIS_NON_IP_EV, 1); 17898c2ecf20Sopenharmony_ci /* Enable SW_EV to inherit in char driver - assume harmless here */ 17908c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_SOFT_EVT_EN, 1); 17918c2ecf20Sopenharmony_ci /* Prefetch threshold 2 => fetch when descriptor cache half empty */ 17928c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_THRESHOLD, 2); 17938c2ecf20Sopenharmony_ci /* Disable hardware watchdog which can misfire */ 17948c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_WD_TMR, 0x3fffff); 17958c2ecf20Sopenharmony_ci /* Squash TX of packets of 16 bytes or less */ 17968c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(temp, FRF_BZ_TX_FLUSH_MIN_LEN_EN, 1); 17978c2ecf20Sopenharmony_ci efx_writeo(efx, &temp, FR_AZ_TX_RESERVED); 17988c2ecf20Sopenharmony_ci 17998c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_4(temp, 18008c2ecf20Sopenharmony_ci /* Default values */ 18018c2ecf20Sopenharmony_ci FRF_BZ_TX_PACE_SB_NOT_AF, 0x15, 18028c2ecf20Sopenharmony_ci FRF_BZ_TX_PACE_SB_AF, 0xb, 18038c2ecf20Sopenharmony_ci FRF_BZ_TX_PACE_FB_BASE, 0, 18048c2ecf20Sopenharmony_ci /* Allow large pace values in the fast bin. */ 18058c2ecf20Sopenharmony_ci FRF_BZ_TX_PACE_BIN_TH, 18068c2ecf20Sopenharmony_ci FFE_BZ_TX_PACE_RESERVED); 18078c2ecf20Sopenharmony_ci efx_writeo(efx, &temp, FR_BZ_TX_PACE); 18088c2ecf20Sopenharmony_ci} 18098c2ecf20Sopenharmony_ci 18108c2ecf20Sopenharmony_ci/************************************************************************** 18118c2ecf20Sopenharmony_ci * 18128c2ecf20Sopenharmony_ci * Filter tables 18138c2ecf20Sopenharmony_ci * 18148c2ecf20Sopenharmony_ci ************************************************************************** 18158c2ecf20Sopenharmony_ci */ 18168c2ecf20Sopenharmony_ci 18178c2ecf20Sopenharmony_ci/* "Fudge factors" - difference between programmed value and actual depth. 18188c2ecf20Sopenharmony_ci * Due to pipelined implementation we need to program H/W with a value that 18198c2ecf20Sopenharmony_ci * is larger than the hop limit we want. 18208c2ecf20Sopenharmony_ci */ 18218c2ecf20Sopenharmony_ci#define EFX_FARCH_FILTER_CTL_SRCH_FUDGE_WILD 3 18228c2ecf20Sopenharmony_ci#define EFX_FARCH_FILTER_CTL_SRCH_FUDGE_FULL 1 18238c2ecf20Sopenharmony_ci 18248c2ecf20Sopenharmony_ci/* Hard maximum search limit. Hardware will time-out beyond 200-something. 18258c2ecf20Sopenharmony_ci * We also need to avoid infinite loops in efx_farch_filter_search() when the 18268c2ecf20Sopenharmony_ci * table is full. 18278c2ecf20Sopenharmony_ci */ 18288c2ecf20Sopenharmony_ci#define EFX_FARCH_FILTER_CTL_SRCH_MAX 200 18298c2ecf20Sopenharmony_ci 18308c2ecf20Sopenharmony_ci/* Don't try very hard to find space for performance hints, as this is 18318c2ecf20Sopenharmony_ci * counter-productive. */ 18328c2ecf20Sopenharmony_ci#define EFX_FARCH_FILTER_CTL_SRCH_HINT_MAX 5 18338c2ecf20Sopenharmony_ci 18348c2ecf20Sopenharmony_cienum efx_farch_filter_type { 18358c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TCP_FULL = 0, 18368c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TCP_WILD, 18378c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_UDP_FULL, 18388c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_UDP_WILD, 18398c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_MAC_FULL = 4, 18408c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_MAC_WILD, 18418c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_UC_DEF = 8, 18428c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_MC_DEF, 18438c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TYPE_COUNT, /* number of specific types */ 18448c2ecf20Sopenharmony_ci}; 18458c2ecf20Sopenharmony_ci 18468c2ecf20Sopenharmony_cienum efx_farch_filter_table_id { 18478c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TABLE_RX_IP = 0, 18488c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TABLE_RX_MAC, 18498c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TABLE_RX_DEF, 18508c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TABLE_TX_MAC, 18518c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TABLE_COUNT, 18528c2ecf20Sopenharmony_ci}; 18538c2ecf20Sopenharmony_ci 18548c2ecf20Sopenharmony_cienum efx_farch_filter_index { 18558c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_INDEX_UC_DEF, 18568c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_INDEX_MC_DEF, 18578c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_SIZE_RX_DEF, 18588c2ecf20Sopenharmony_ci}; 18598c2ecf20Sopenharmony_ci 18608c2ecf20Sopenharmony_cistruct efx_farch_filter_spec { 18618c2ecf20Sopenharmony_ci u8 type:4; 18628c2ecf20Sopenharmony_ci u8 priority:4; 18638c2ecf20Sopenharmony_ci u8 flags; 18648c2ecf20Sopenharmony_ci u16 dmaq_id; 18658c2ecf20Sopenharmony_ci u32 data[3]; 18668c2ecf20Sopenharmony_ci}; 18678c2ecf20Sopenharmony_ci 18688c2ecf20Sopenharmony_cistruct efx_farch_filter_table { 18698c2ecf20Sopenharmony_ci enum efx_farch_filter_table_id id; 18708c2ecf20Sopenharmony_ci u32 offset; /* address of table relative to BAR */ 18718c2ecf20Sopenharmony_ci unsigned size; /* number of entries */ 18728c2ecf20Sopenharmony_ci unsigned step; /* step between entries */ 18738c2ecf20Sopenharmony_ci unsigned used; /* number currently used */ 18748c2ecf20Sopenharmony_ci unsigned long *used_bitmap; 18758c2ecf20Sopenharmony_ci struct efx_farch_filter_spec *spec; 18768c2ecf20Sopenharmony_ci unsigned search_limit[EFX_FARCH_FILTER_TYPE_COUNT]; 18778c2ecf20Sopenharmony_ci}; 18788c2ecf20Sopenharmony_ci 18798c2ecf20Sopenharmony_cistruct efx_farch_filter_state { 18808c2ecf20Sopenharmony_ci struct rw_semaphore lock; /* Protects table contents */ 18818c2ecf20Sopenharmony_ci struct efx_farch_filter_table table[EFX_FARCH_FILTER_TABLE_COUNT]; 18828c2ecf20Sopenharmony_ci}; 18838c2ecf20Sopenharmony_ci 18848c2ecf20Sopenharmony_cistatic void 18858c2ecf20Sopenharmony_ciefx_farch_filter_table_clear_entry(struct efx_nic *efx, 18868c2ecf20Sopenharmony_ci struct efx_farch_filter_table *table, 18878c2ecf20Sopenharmony_ci unsigned int filter_idx); 18888c2ecf20Sopenharmony_ci 18898c2ecf20Sopenharmony_ci/* The filter hash function is LFSR polynomial x^16 + x^3 + 1 of a 32-bit 18908c2ecf20Sopenharmony_ci * key derived from the n-tuple. The initial LFSR state is 0xffff. */ 18918c2ecf20Sopenharmony_cistatic u16 efx_farch_filter_hash(u32 key) 18928c2ecf20Sopenharmony_ci{ 18938c2ecf20Sopenharmony_ci u16 tmp; 18948c2ecf20Sopenharmony_ci 18958c2ecf20Sopenharmony_ci /* First 16 rounds */ 18968c2ecf20Sopenharmony_ci tmp = 0x1fff ^ key >> 16; 18978c2ecf20Sopenharmony_ci tmp = tmp ^ tmp >> 3 ^ tmp >> 6; 18988c2ecf20Sopenharmony_ci tmp = tmp ^ tmp >> 9; 18998c2ecf20Sopenharmony_ci /* Last 16 rounds */ 19008c2ecf20Sopenharmony_ci tmp = tmp ^ tmp << 13 ^ key; 19018c2ecf20Sopenharmony_ci tmp = tmp ^ tmp >> 3 ^ tmp >> 6; 19028c2ecf20Sopenharmony_ci return tmp ^ tmp >> 9; 19038c2ecf20Sopenharmony_ci} 19048c2ecf20Sopenharmony_ci 19058c2ecf20Sopenharmony_ci/* To allow for hash collisions, filter search continues at these 19068c2ecf20Sopenharmony_ci * increments from the first possible entry selected by the hash. */ 19078c2ecf20Sopenharmony_cistatic u16 efx_farch_filter_increment(u32 key) 19088c2ecf20Sopenharmony_ci{ 19098c2ecf20Sopenharmony_ci return key * 2 - 1; 19108c2ecf20Sopenharmony_ci} 19118c2ecf20Sopenharmony_ci 19128c2ecf20Sopenharmony_cistatic enum efx_farch_filter_table_id 19138c2ecf20Sopenharmony_ciefx_farch_filter_spec_table_id(const struct efx_farch_filter_spec *spec) 19148c2ecf20Sopenharmony_ci{ 19158c2ecf20Sopenharmony_ci BUILD_BUG_ON(EFX_FARCH_FILTER_TABLE_RX_IP != 19168c2ecf20Sopenharmony_ci (EFX_FARCH_FILTER_TCP_FULL >> 2)); 19178c2ecf20Sopenharmony_ci BUILD_BUG_ON(EFX_FARCH_FILTER_TABLE_RX_IP != 19188c2ecf20Sopenharmony_ci (EFX_FARCH_FILTER_TCP_WILD >> 2)); 19198c2ecf20Sopenharmony_ci BUILD_BUG_ON(EFX_FARCH_FILTER_TABLE_RX_IP != 19208c2ecf20Sopenharmony_ci (EFX_FARCH_FILTER_UDP_FULL >> 2)); 19218c2ecf20Sopenharmony_ci BUILD_BUG_ON(EFX_FARCH_FILTER_TABLE_RX_IP != 19228c2ecf20Sopenharmony_ci (EFX_FARCH_FILTER_UDP_WILD >> 2)); 19238c2ecf20Sopenharmony_ci BUILD_BUG_ON(EFX_FARCH_FILTER_TABLE_RX_MAC != 19248c2ecf20Sopenharmony_ci (EFX_FARCH_FILTER_MAC_FULL >> 2)); 19258c2ecf20Sopenharmony_ci BUILD_BUG_ON(EFX_FARCH_FILTER_TABLE_RX_MAC != 19268c2ecf20Sopenharmony_ci (EFX_FARCH_FILTER_MAC_WILD >> 2)); 19278c2ecf20Sopenharmony_ci BUILD_BUG_ON(EFX_FARCH_FILTER_TABLE_TX_MAC != 19288c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TABLE_RX_MAC + 2); 19298c2ecf20Sopenharmony_ci return (spec->type >> 2) + ((spec->flags & EFX_FILTER_FLAG_TX) ? 2 : 0); 19308c2ecf20Sopenharmony_ci} 19318c2ecf20Sopenharmony_ci 19328c2ecf20Sopenharmony_cistatic void efx_farch_filter_push_rx_config(struct efx_nic *efx) 19338c2ecf20Sopenharmony_ci{ 19348c2ecf20Sopenharmony_ci struct efx_farch_filter_state *state = efx->filter_state; 19358c2ecf20Sopenharmony_ci struct efx_farch_filter_table *table; 19368c2ecf20Sopenharmony_ci efx_oword_t filter_ctl; 19378c2ecf20Sopenharmony_ci 19388c2ecf20Sopenharmony_ci efx_reado(efx, &filter_ctl, FR_BZ_RX_FILTER_CTL); 19398c2ecf20Sopenharmony_ci 19408c2ecf20Sopenharmony_ci table = &state->table[EFX_FARCH_FILTER_TABLE_RX_IP]; 19418c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(filter_ctl, FRF_BZ_TCP_FULL_SRCH_LIMIT, 19428c2ecf20Sopenharmony_ci table->search_limit[EFX_FARCH_FILTER_TCP_FULL] + 19438c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_CTL_SRCH_FUDGE_FULL); 19448c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(filter_ctl, FRF_BZ_TCP_WILD_SRCH_LIMIT, 19458c2ecf20Sopenharmony_ci table->search_limit[EFX_FARCH_FILTER_TCP_WILD] + 19468c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_CTL_SRCH_FUDGE_WILD); 19478c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(filter_ctl, FRF_BZ_UDP_FULL_SRCH_LIMIT, 19488c2ecf20Sopenharmony_ci table->search_limit[EFX_FARCH_FILTER_UDP_FULL] + 19498c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_CTL_SRCH_FUDGE_FULL); 19508c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD(filter_ctl, FRF_BZ_UDP_WILD_SRCH_LIMIT, 19518c2ecf20Sopenharmony_ci table->search_limit[EFX_FARCH_FILTER_UDP_WILD] + 19528c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_CTL_SRCH_FUDGE_WILD); 19538c2ecf20Sopenharmony_ci 19548c2ecf20Sopenharmony_ci table = &state->table[EFX_FARCH_FILTER_TABLE_RX_MAC]; 19558c2ecf20Sopenharmony_ci if (table->size) { 19568c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD( 19578c2ecf20Sopenharmony_ci filter_ctl, FRF_CZ_ETHERNET_FULL_SEARCH_LIMIT, 19588c2ecf20Sopenharmony_ci table->search_limit[EFX_FARCH_FILTER_MAC_FULL] + 19598c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_CTL_SRCH_FUDGE_FULL); 19608c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD( 19618c2ecf20Sopenharmony_ci filter_ctl, FRF_CZ_ETHERNET_WILDCARD_SEARCH_LIMIT, 19628c2ecf20Sopenharmony_ci table->search_limit[EFX_FARCH_FILTER_MAC_WILD] + 19638c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_CTL_SRCH_FUDGE_WILD); 19648c2ecf20Sopenharmony_ci } 19658c2ecf20Sopenharmony_ci 19668c2ecf20Sopenharmony_ci table = &state->table[EFX_FARCH_FILTER_TABLE_RX_DEF]; 19678c2ecf20Sopenharmony_ci if (table->size) { 19688c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD( 19698c2ecf20Sopenharmony_ci filter_ctl, FRF_CZ_UNICAST_NOMATCH_Q_ID, 19708c2ecf20Sopenharmony_ci table->spec[EFX_FARCH_FILTER_INDEX_UC_DEF].dmaq_id); 19718c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD( 19728c2ecf20Sopenharmony_ci filter_ctl, FRF_CZ_UNICAST_NOMATCH_RSS_ENABLED, 19738c2ecf20Sopenharmony_ci !!(table->spec[EFX_FARCH_FILTER_INDEX_UC_DEF].flags & 19748c2ecf20Sopenharmony_ci EFX_FILTER_FLAG_RX_RSS)); 19758c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD( 19768c2ecf20Sopenharmony_ci filter_ctl, FRF_CZ_MULTICAST_NOMATCH_Q_ID, 19778c2ecf20Sopenharmony_ci table->spec[EFX_FARCH_FILTER_INDEX_MC_DEF].dmaq_id); 19788c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD( 19798c2ecf20Sopenharmony_ci filter_ctl, FRF_CZ_MULTICAST_NOMATCH_RSS_ENABLED, 19808c2ecf20Sopenharmony_ci !!(table->spec[EFX_FARCH_FILTER_INDEX_MC_DEF].flags & 19818c2ecf20Sopenharmony_ci EFX_FILTER_FLAG_RX_RSS)); 19828c2ecf20Sopenharmony_ci 19838c2ecf20Sopenharmony_ci /* There is a single bit to enable RX scatter for all 19848c2ecf20Sopenharmony_ci * unmatched packets. Only set it if scatter is 19858c2ecf20Sopenharmony_ci * enabled in both filter specs. 19868c2ecf20Sopenharmony_ci */ 19878c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD( 19888c2ecf20Sopenharmony_ci filter_ctl, FRF_BZ_SCATTER_ENBL_NO_MATCH_Q, 19898c2ecf20Sopenharmony_ci !!(table->spec[EFX_FARCH_FILTER_INDEX_UC_DEF].flags & 19908c2ecf20Sopenharmony_ci table->spec[EFX_FARCH_FILTER_INDEX_MC_DEF].flags & 19918c2ecf20Sopenharmony_ci EFX_FILTER_FLAG_RX_SCATTER)); 19928c2ecf20Sopenharmony_ci } else { 19938c2ecf20Sopenharmony_ci /* We don't expose 'default' filters because unmatched 19948c2ecf20Sopenharmony_ci * packets always go to the queue number found in the 19958c2ecf20Sopenharmony_ci * RSS table. But we still need to set the RX scatter 19968c2ecf20Sopenharmony_ci * bit here. 19978c2ecf20Sopenharmony_ci */ 19988c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD( 19998c2ecf20Sopenharmony_ci filter_ctl, FRF_BZ_SCATTER_ENBL_NO_MATCH_Q, 20008c2ecf20Sopenharmony_ci efx->rx_scatter); 20018c2ecf20Sopenharmony_ci } 20028c2ecf20Sopenharmony_ci 20038c2ecf20Sopenharmony_ci efx_writeo(efx, &filter_ctl, FR_BZ_RX_FILTER_CTL); 20048c2ecf20Sopenharmony_ci} 20058c2ecf20Sopenharmony_ci 20068c2ecf20Sopenharmony_cistatic void efx_farch_filter_push_tx_limits(struct efx_nic *efx) 20078c2ecf20Sopenharmony_ci{ 20088c2ecf20Sopenharmony_ci struct efx_farch_filter_state *state = efx->filter_state; 20098c2ecf20Sopenharmony_ci struct efx_farch_filter_table *table; 20108c2ecf20Sopenharmony_ci efx_oword_t tx_cfg; 20118c2ecf20Sopenharmony_ci 20128c2ecf20Sopenharmony_ci efx_reado(efx, &tx_cfg, FR_AZ_TX_CFG); 20138c2ecf20Sopenharmony_ci 20148c2ecf20Sopenharmony_ci table = &state->table[EFX_FARCH_FILTER_TABLE_TX_MAC]; 20158c2ecf20Sopenharmony_ci if (table->size) { 20168c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD( 20178c2ecf20Sopenharmony_ci tx_cfg, FRF_CZ_TX_ETH_FILTER_FULL_SEARCH_RANGE, 20188c2ecf20Sopenharmony_ci table->search_limit[EFX_FARCH_FILTER_MAC_FULL] + 20198c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_CTL_SRCH_FUDGE_FULL); 20208c2ecf20Sopenharmony_ci EFX_SET_OWORD_FIELD( 20218c2ecf20Sopenharmony_ci tx_cfg, FRF_CZ_TX_ETH_FILTER_WILD_SEARCH_RANGE, 20228c2ecf20Sopenharmony_ci table->search_limit[EFX_FARCH_FILTER_MAC_WILD] + 20238c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_CTL_SRCH_FUDGE_WILD); 20248c2ecf20Sopenharmony_ci } 20258c2ecf20Sopenharmony_ci 20268c2ecf20Sopenharmony_ci efx_writeo(efx, &tx_cfg, FR_AZ_TX_CFG); 20278c2ecf20Sopenharmony_ci} 20288c2ecf20Sopenharmony_ci 20298c2ecf20Sopenharmony_cistatic int 20308c2ecf20Sopenharmony_ciefx_farch_filter_from_gen_spec(struct efx_farch_filter_spec *spec, 20318c2ecf20Sopenharmony_ci const struct efx_filter_spec *gen_spec) 20328c2ecf20Sopenharmony_ci{ 20338c2ecf20Sopenharmony_ci bool is_full = false; 20348c2ecf20Sopenharmony_ci 20358c2ecf20Sopenharmony_ci if ((gen_spec->flags & EFX_FILTER_FLAG_RX_RSS) && gen_spec->rss_context) 20368c2ecf20Sopenharmony_ci return -EINVAL; 20378c2ecf20Sopenharmony_ci 20388c2ecf20Sopenharmony_ci spec->priority = gen_spec->priority; 20398c2ecf20Sopenharmony_ci spec->flags = gen_spec->flags; 20408c2ecf20Sopenharmony_ci spec->dmaq_id = gen_spec->dmaq_id; 20418c2ecf20Sopenharmony_ci 20428c2ecf20Sopenharmony_ci switch (gen_spec->match_flags) { 20438c2ecf20Sopenharmony_ci case (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_IP_PROTO | 20448c2ecf20Sopenharmony_ci EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_LOC_PORT | 20458c2ecf20Sopenharmony_ci EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_REM_PORT): 20468c2ecf20Sopenharmony_ci is_full = true; 20478c2ecf20Sopenharmony_ci fallthrough; 20488c2ecf20Sopenharmony_ci case (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_IP_PROTO | 20498c2ecf20Sopenharmony_ci EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_LOC_PORT): { 20508c2ecf20Sopenharmony_ci __be32 rhost, host1, host2; 20518c2ecf20Sopenharmony_ci __be16 rport, port1, port2; 20528c2ecf20Sopenharmony_ci 20538c2ecf20Sopenharmony_ci EFX_WARN_ON_PARANOID(!(gen_spec->flags & EFX_FILTER_FLAG_RX)); 20548c2ecf20Sopenharmony_ci 20558c2ecf20Sopenharmony_ci if (gen_spec->ether_type != htons(ETH_P_IP)) 20568c2ecf20Sopenharmony_ci return -EPROTONOSUPPORT; 20578c2ecf20Sopenharmony_ci if (gen_spec->loc_port == 0 || 20588c2ecf20Sopenharmony_ci (is_full && gen_spec->rem_port == 0)) 20598c2ecf20Sopenharmony_ci return -EADDRNOTAVAIL; 20608c2ecf20Sopenharmony_ci switch (gen_spec->ip_proto) { 20618c2ecf20Sopenharmony_ci case IPPROTO_TCP: 20628c2ecf20Sopenharmony_ci spec->type = (is_full ? EFX_FARCH_FILTER_TCP_FULL : 20638c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TCP_WILD); 20648c2ecf20Sopenharmony_ci break; 20658c2ecf20Sopenharmony_ci case IPPROTO_UDP: 20668c2ecf20Sopenharmony_ci spec->type = (is_full ? EFX_FARCH_FILTER_UDP_FULL : 20678c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_UDP_WILD); 20688c2ecf20Sopenharmony_ci break; 20698c2ecf20Sopenharmony_ci default: 20708c2ecf20Sopenharmony_ci return -EPROTONOSUPPORT; 20718c2ecf20Sopenharmony_ci } 20728c2ecf20Sopenharmony_ci 20738c2ecf20Sopenharmony_ci /* Filter is constructed in terms of source and destination, 20748c2ecf20Sopenharmony_ci * with the odd wrinkle that the ports are swapped in a UDP 20758c2ecf20Sopenharmony_ci * wildcard filter. We need to convert from local and remote 20768c2ecf20Sopenharmony_ci * (= zero for wildcard) addresses. 20778c2ecf20Sopenharmony_ci */ 20788c2ecf20Sopenharmony_ci rhost = is_full ? gen_spec->rem_host[0] : 0; 20798c2ecf20Sopenharmony_ci rport = is_full ? gen_spec->rem_port : 0; 20808c2ecf20Sopenharmony_ci host1 = rhost; 20818c2ecf20Sopenharmony_ci host2 = gen_spec->loc_host[0]; 20828c2ecf20Sopenharmony_ci if (!is_full && gen_spec->ip_proto == IPPROTO_UDP) { 20838c2ecf20Sopenharmony_ci port1 = gen_spec->loc_port; 20848c2ecf20Sopenharmony_ci port2 = rport; 20858c2ecf20Sopenharmony_ci } else { 20868c2ecf20Sopenharmony_ci port1 = rport; 20878c2ecf20Sopenharmony_ci port2 = gen_spec->loc_port; 20888c2ecf20Sopenharmony_ci } 20898c2ecf20Sopenharmony_ci spec->data[0] = ntohl(host1) << 16 | ntohs(port1); 20908c2ecf20Sopenharmony_ci spec->data[1] = ntohs(port2) << 16 | ntohl(host1) >> 16; 20918c2ecf20Sopenharmony_ci spec->data[2] = ntohl(host2); 20928c2ecf20Sopenharmony_ci 20938c2ecf20Sopenharmony_ci break; 20948c2ecf20Sopenharmony_ci } 20958c2ecf20Sopenharmony_ci 20968c2ecf20Sopenharmony_ci case EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_OUTER_VID: 20978c2ecf20Sopenharmony_ci is_full = true; 20988c2ecf20Sopenharmony_ci fallthrough; 20998c2ecf20Sopenharmony_ci case EFX_FILTER_MATCH_LOC_MAC: 21008c2ecf20Sopenharmony_ci spec->type = (is_full ? EFX_FARCH_FILTER_MAC_FULL : 21018c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_MAC_WILD); 21028c2ecf20Sopenharmony_ci spec->data[0] = is_full ? ntohs(gen_spec->outer_vid) : 0; 21038c2ecf20Sopenharmony_ci spec->data[1] = (gen_spec->loc_mac[2] << 24 | 21048c2ecf20Sopenharmony_ci gen_spec->loc_mac[3] << 16 | 21058c2ecf20Sopenharmony_ci gen_spec->loc_mac[4] << 8 | 21068c2ecf20Sopenharmony_ci gen_spec->loc_mac[5]); 21078c2ecf20Sopenharmony_ci spec->data[2] = (gen_spec->loc_mac[0] << 8 | 21088c2ecf20Sopenharmony_ci gen_spec->loc_mac[1]); 21098c2ecf20Sopenharmony_ci break; 21108c2ecf20Sopenharmony_ci 21118c2ecf20Sopenharmony_ci case EFX_FILTER_MATCH_LOC_MAC_IG: 21128c2ecf20Sopenharmony_ci spec->type = (is_multicast_ether_addr(gen_spec->loc_mac) ? 21138c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_MC_DEF : 21148c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_UC_DEF); 21158c2ecf20Sopenharmony_ci memset(spec->data, 0, sizeof(spec->data)); /* ensure equality */ 21168c2ecf20Sopenharmony_ci break; 21178c2ecf20Sopenharmony_ci 21188c2ecf20Sopenharmony_ci default: 21198c2ecf20Sopenharmony_ci return -EPROTONOSUPPORT; 21208c2ecf20Sopenharmony_ci } 21218c2ecf20Sopenharmony_ci 21228c2ecf20Sopenharmony_ci return 0; 21238c2ecf20Sopenharmony_ci} 21248c2ecf20Sopenharmony_ci 21258c2ecf20Sopenharmony_cistatic void 21268c2ecf20Sopenharmony_ciefx_farch_filter_to_gen_spec(struct efx_filter_spec *gen_spec, 21278c2ecf20Sopenharmony_ci const struct efx_farch_filter_spec *spec) 21288c2ecf20Sopenharmony_ci{ 21298c2ecf20Sopenharmony_ci bool is_full = false; 21308c2ecf20Sopenharmony_ci 21318c2ecf20Sopenharmony_ci /* *gen_spec should be completely initialised, to be consistent 21328c2ecf20Sopenharmony_ci * with efx_filter_init_{rx,tx}() and in case we want to copy 21338c2ecf20Sopenharmony_ci * it back to userland. 21348c2ecf20Sopenharmony_ci */ 21358c2ecf20Sopenharmony_ci memset(gen_spec, 0, sizeof(*gen_spec)); 21368c2ecf20Sopenharmony_ci 21378c2ecf20Sopenharmony_ci gen_spec->priority = spec->priority; 21388c2ecf20Sopenharmony_ci gen_spec->flags = spec->flags; 21398c2ecf20Sopenharmony_ci gen_spec->dmaq_id = spec->dmaq_id; 21408c2ecf20Sopenharmony_ci 21418c2ecf20Sopenharmony_ci switch (spec->type) { 21428c2ecf20Sopenharmony_ci case EFX_FARCH_FILTER_TCP_FULL: 21438c2ecf20Sopenharmony_ci case EFX_FARCH_FILTER_UDP_FULL: 21448c2ecf20Sopenharmony_ci is_full = true; 21458c2ecf20Sopenharmony_ci fallthrough; 21468c2ecf20Sopenharmony_ci case EFX_FARCH_FILTER_TCP_WILD: 21478c2ecf20Sopenharmony_ci case EFX_FARCH_FILTER_UDP_WILD: { 21488c2ecf20Sopenharmony_ci __be32 host1, host2; 21498c2ecf20Sopenharmony_ci __be16 port1, port2; 21508c2ecf20Sopenharmony_ci 21518c2ecf20Sopenharmony_ci gen_spec->match_flags = 21528c2ecf20Sopenharmony_ci EFX_FILTER_MATCH_ETHER_TYPE | 21538c2ecf20Sopenharmony_ci EFX_FILTER_MATCH_IP_PROTO | 21548c2ecf20Sopenharmony_ci EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_LOC_PORT; 21558c2ecf20Sopenharmony_ci if (is_full) 21568c2ecf20Sopenharmony_ci gen_spec->match_flags |= (EFX_FILTER_MATCH_REM_HOST | 21578c2ecf20Sopenharmony_ci EFX_FILTER_MATCH_REM_PORT); 21588c2ecf20Sopenharmony_ci gen_spec->ether_type = htons(ETH_P_IP); 21598c2ecf20Sopenharmony_ci gen_spec->ip_proto = 21608c2ecf20Sopenharmony_ci (spec->type == EFX_FARCH_FILTER_TCP_FULL || 21618c2ecf20Sopenharmony_ci spec->type == EFX_FARCH_FILTER_TCP_WILD) ? 21628c2ecf20Sopenharmony_ci IPPROTO_TCP : IPPROTO_UDP; 21638c2ecf20Sopenharmony_ci 21648c2ecf20Sopenharmony_ci host1 = htonl(spec->data[0] >> 16 | spec->data[1] << 16); 21658c2ecf20Sopenharmony_ci port1 = htons(spec->data[0]); 21668c2ecf20Sopenharmony_ci host2 = htonl(spec->data[2]); 21678c2ecf20Sopenharmony_ci port2 = htons(spec->data[1] >> 16); 21688c2ecf20Sopenharmony_ci if (spec->flags & EFX_FILTER_FLAG_TX) { 21698c2ecf20Sopenharmony_ci gen_spec->loc_host[0] = host1; 21708c2ecf20Sopenharmony_ci gen_spec->rem_host[0] = host2; 21718c2ecf20Sopenharmony_ci } else { 21728c2ecf20Sopenharmony_ci gen_spec->loc_host[0] = host2; 21738c2ecf20Sopenharmony_ci gen_spec->rem_host[0] = host1; 21748c2ecf20Sopenharmony_ci } 21758c2ecf20Sopenharmony_ci if (!!(gen_spec->flags & EFX_FILTER_FLAG_TX) ^ 21768c2ecf20Sopenharmony_ci (!is_full && gen_spec->ip_proto == IPPROTO_UDP)) { 21778c2ecf20Sopenharmony_ci gen_spec->loc_port = port1; 21788c2ecf20Sopenharmony_ci gen_spec->rem_port = port2; 21798c2ecf20Sopenharmony_ci } else { 21808c2ecf20Sopenharmony_ci gen_spec->loc_port = port2; 21818c2ecf20Sopenharmony_ci gen_spec->rem_port = port1; 21828c2ecf20Sopenharmony_ci } 21838c2ecf20Sopenharmony_ci 21848c2ecf20Sopenharmony_ci break; 21858c2ecf20Sopenharmony_ci } 21868c2ecf20Sopenharmony_ci 21878c2ecf20Sopenharmony_ci case EFX_FARCH_FILTER_MAC_FULL: 21888c2ecf20Sopenharmony_ci is_full = true; 21898c2ecf20Sopenharmony_ci fallthrough; 21908c2ecf20Sopenharmony_ci case EFX_FARCH_FILTER_MAC_WILD: 21918c2ecf20Sopenharmony_ci gen_spec->match_flags = EFX_FILTER_MATCH_LOC_MAC; 21928c2ecf20Sopenharmony_ci if (is_full) 21938c2ecf20Sopenharmony_ci gen_spec->match_flags |= EFX_FILTER_MATCH_OUTER_VID; 21948c2ecf20Sopenharmony_ci gen_spec->loc_mac[0] = spec->data[2] >> 8; 21958c2ecf20Sopenharmony_ci gen_spec->loc_mac[1] = spec->data[2]; 21968c2ecf20Sopenharmony_ci gen_spec->loc_mac[2] = spec->data[1] >> 24; 21978c2ecf20Sopenharmony_ci gen_spec->loc_mac[3] = spec->data[1] >> 16; 21988c2ecf20Sopenharmony_ci gen_spec->loc_mac[4] = spec->data[1] >> 8; 21998c2ecf20Sopenharmony_ci gen_spec->loc_mac[5] = spec->data[1]; 22008c2ecf20Sopenharmony_ci gen_spec->outer_vid = htons(spec->data[0]); 22018c2ecf20Sopenharmony_ci break; 22028c2ecf20Sopenharmony_ci 22038c2ecf20Sopenharmony_ci case EFX_FARCH_FILTER_UC_DEF: 22048c2ecf20Sopenharmony_ci case EFX_FARCH_FILTER_MC_DEF: 22058c2ecf20Sopenharmony_ci gen_spec->match_flags = EFX_FILTER_MATCH_LOC_MAC_IG; 22068c2ecf20Sopenharmony_ci gen_spec->loc_mac[0] = spec->type == EFX_FARCH_FILTER_MC_DEF; 22078c2ecf20Sopenharmony_ci break; 22088c2ecf20Sopenharmony_ci 22098c2ecf20Sopenharmony_ci default: 22108c2ecf20Sopenharmony_ci WARN_ON(1); 22118c2ecf20Sopenharmony_ci break; 22128c2ecf20Sopenharmony_ci } 22138c2ecf20Sopenharmony_ci} 22148c2ecf20Sopenharmony_ci 22158c2ecf20Sopenharmony_cistatic void 22168c2ecf20Sopenharmony_ciefx_farch_filter_init_rx_auto(struct efx_nic *efx, 22178c2ecf20Sopenharmony_ci struct efx_farch_filter_spec *spec) 22188c2ecf20Sopenharmony_ci{ 22198c2ecf20Sopenharmony_ci /* If there's only one channel then disable RSS for non VF 22208c2ecf20Sopenharmony_ci * traffic, thereby allowing VFs to use RSS when the PF can't. 22218c2ecf20Sopenharmony_ci */ 22228c2ecf20Sopenharmony_ci spec->priority = EFX_FILTER_PRI_AUTO; 22238c2ecf20Sopenharmony_ci spec->flags = (EFX_FILTER_FLAG_RX | 22248c2ecf20Sopenharmony_ci (efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0) | 22258c2ecf20Sopenharmony_ci (efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0)); 22268c2ecf20Sopenharmony_ci spec->dmaq_id = 0; 22278c2ecf20Sopenharmony_ci} 22288c2ecf20Sopenharmony_ci 22298c2ecf20Sopenharmony_ci/* Build a filter entry and return its n-tuple key. */ 22308c2ecf20Sopenharmony_cistatic u32 efx_farch_filter_build(efx_oword_t *filter, 22318c2ecf20Sopenharmony_ci struct efx_farch_filter_spec *spec) 22328c2ecf20Sopenharmony_ci{ 22338c2ecf20Sopenharmony_ci u32 data3; 22348c2ecf20Sopenharmony_ci 22358c2ecf20Sopenharmony_ci switch (efx_farch_filter_spec_table_id(spec)) { 22368c2ecf20Sopenharmony_ci case EFX_FARCH_FILTER_TABLE_RX_IP: { 22378c2ecf20Sopenharmony_ci bool is_udp = (spec->type == EFX_FARCH_FILTER_UDP_FULL || 22388c2ecf20Sopenharmony_ci spec->type == EFX_FARCH_FILTER_UDP_WILD); 22398c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_7( 22408c2ecf20Sopenharmony_ci *filter, 22418c2ecf20Sopenharmony_ci FRF_BZ_RSS_EN, 22428c2ecf20Sopenharmony_ci !!(spec->flags & EFX_FILTER_FLAG_RX_RSS), 22438c2ecf20Sopenharmony_ci FRF_BZ_SCATTER_EN, 22448c2ecf20Sopenharmony_ci !!(spec->flags & EFX_FILTER_FLAG_RX_SCATTER), 22458c2ecf20Sopenharmony_ci FRF_BZ_TCP_UDP, is_udp, 22468c2ecf20Sopenharmony_ci FRF_BZ_RXQ_ID, spec->dmaq_id, 22478c2ecf20Sopenharmony_ci EFX_DWORD_2, spec->data[2], 22488c2ecf20Sopenharmony_ci EFX_DWORD_1, spec->data[1], 22498c2ecf20Sopenharmony_ci EFX_DWORD_0, spec->data[0]); 22508c2ecf20Sopenharmony_ci data3 = is_udp; 22518c2ecf20Sopenharmony_ci break; 22528c2ecf20Sopenharmony_ci } 22538c2ecf20Sopenharmony_ci 22548c2ecf20Sopenharmony_ci case EFX_FARCH_FILTER_TABLE_RX_MAC: { 22558c2ecf20Sopenharmony_ci bool is_wild = spec->type == EFX_FARCH_FILTER_MAC_WILD; 22568c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_7( 22578c2ecf20Sopenharmony_ci *filter, 22588c2ecf20Sopenharmony_ci FRF_CZ_RMFT_RSS_EN, 22598c2ecf20Sopenharmony_ci !!(spec->flags & EFX_FILTER_FLAG_RX_RSS), 22608c2ecf20Sopenharmony_ci FRF_CZ_RMFT_SCATTER_EN, 22618c2ecf20Sopenharmony_ci !!(spec->flags & EFX_FILTER_FLAG_RX_SCATTER), 22628c2ecf20Sopenharmony_ci FRF_CZ_RMFT_RXQ_ID, spec->dmaq_id, 22638c2ecf20Sopenharmony_ci FRF_CZ_RMFT_WILDCARD_MATCH, is_wild, 22648c2ecf20Sopenharmony_ci FRF_CZ_RMFT_DEST_MAC_HI, spec->data[2], 22658c2ecf20Sopenharmony_ci FRF_CZ_RMFT_DEST_MAC_LO, spec->data[1], 22668c2ecf20Sopenharmony_ci FRF_CZ_RMFT_VLAN_ID, spec->data[0]); 22678c2ecf20Sopenharmony_ci data3 = is_wild; 22688c2ecf20Sopenharmony_ci break; 22698c2ecf20Sopenharmony_ci } 22708c2ecf20Sopenharmony_ci 22718c2ecf20Sopenharmony_ci case EFX_FARCH_FILTER_TABLE_TX_MAC: { 22728c2ecf20Sopenharmony_ci bool is_wild = spec->type == EFX_FARCH_FILTER_MAC_WILD; 22738c2ecf20Sopenharmony_ci EFX_POPULATE_OWORD_5(*filter, 22748c2ecf20Sopenharmony_ci FRF_CZ_TMFT_TXQ_ID, spec->dmaq_id, 22758c2ecf20Sopenharmony_ci FRF_CZ_TMFT_WILDCARD_MATCH, is_wild, 22768c2ecf20Sopenharmony_ci FRF_CZ_TMFT_SRC_MAC_HI, spec->data[2], 22778c2ecf20Sopenharmony_ci FRF_CZ_TMFT_SRC_MAC_LO, spec->data[1], 22788c2ecf20Sopenharmony_ci FRF_CZ_TMFT_VLAN_ID, spec->data[0]); 22798c2ecf20Sopenharmony_ci data3 = is_wild | spec->dmaq_id << 1; 22808c2ecf20Sopenharmony_ci break; 22818c2ecf20Sopenharmony_ci } 22828c2ecf20Sopenharmony_ci 22838c2ecf20Sopenharmony_ci default: 22848c2ecf20Sopenharmony_ci BUG(); 22858c2ecf20Sopenharmony_ci } 22868c2ecf20Sopenharmony_ci 22878c2ecf20Sopenharmony_ci return spec->data[0] ^ spec->data[1] ^ spec->data[2] ^ data3; 22888c2ecf20Sopenharmony_ci} 22898c2ecf20Sopenharmony_ci 22908c2ecf20Sopenharmony_cistatic bool efx_farch_filter_equal(const struct efx_farch_filter_spec *left, 22918c2ecf20Sopenharmony_ci const struct efx_farch_filter_spec *right) 22928c2ecf20Sopenharmony_ci{ 22938c2ecf20Sopenharmony_ci if (left->type != right->type || 22948c2ecf20Sopenharmony_ci memcmp(left->data, right->data, sizeof(left->data))) 22958c2ecf20Sopenharmony_ci return false; 22968c2ecf20Sopenharmony_ci 22978c2ecf20Sopenharmony_ci if (left->flags & EFX_FILTER_FLAG_TX && 22988c2ecf20Sopenharmony_ci left->dmaq_id != right->dmaq_id) 22998c2ecf20Sopenharmony_ci return false; 23008c2ecf20Sopenharmony_ci 23018c2ecf20Sopenharmony_ci return true; 23028c2ecf20Sopenharmony_ci} 23038c2ecf20Sopenharmony_ci 23048c2ecf20Sopenharmony_ci/* 23058c2ecf20Sopenharmony_ci * Construct/deconstruct external filter IDs. At least the RX filter 23068c2ecf20Sopenharmony_ci * IDs must be ordered by matching priority, for RX NFC semantics. 23078c2ecf20Sopenharmony_ci * 23088c2ecf20Sopenharmony_ci * Deconstruction needs to be robust against invalid IDs so that 23098c2ecf20Sopenharmony_ci * efx_filter_remove_id_safe() and efx_filter_get_filter_safe() can 23108c2ecf20Sopenharmony_ci * accept user-provided IDs. 23118c2ecf20Sopenharmony_ci */ 23128c2ecf20Sopenharmony_ci 23138c2ecf20Sopenharmony_ci#define EFX_FARCH_FILTER_MATCH_PRI_COUNT 5 23148c2ecf20Sopenharmony_ci 23158c2ecf20Sopenharmony_cistatic const u8 efx_farch_filter_type_match_pri[EFX_FARCH_FILTER_TYPE_COUNT] = { 23168c2ecf20Sopenharmony_ci [EFX_FARCH_FILTER_TCP_FULL] = 0, 23178c2ecf20Sopenharmony_ci [EFX_FARCH_FILTER_UDP_FULL] = 0, 23188c2ecf20Sopenharmony_ci [EFX_FARCH_FILTER_TCP_WILD] = 1, 23198c2ecf20Sopenharmony_ci [EFX_FARCH_FILTER_UDP_WILD] = 1, 23208c2ecf20Sopenharmony_ci [EFX_FARCH_FILTER_MAC_FULL] = 2, 23218c2ecf20Sopenharmony_ci [EFX_FARCH_FILTER_MAC_WILD] = 3, 23228c2ecf20Sopenharmony_ci [EFX_FARCH_FILTER_UC_DEF] = 4, 23238c2ecf20Sopenharmony_ci [EFX_FARCH_FILTER_MC_DEF] = 4, 23248c2ecf20Sopenharmony_ci}; 23258c2ecf20Sopenharmony_ci 23268c2ecf20Sopenharmony_cistatic const enum efx_farch_filter_table_id efx_farch_filter_range_table[] = { 23278c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TABLE_RX_IP, /* RX match pri 0 */ 23288c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TABLE_RX_IP, 23298c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TABLE_RX_MAC, 23308c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TABLE_RX_MAC, 23318c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TABLE_RX_DEF, /* RX match pri 4 */ 23328c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TABLE_TX_MAC, /* TX match pri 0 */ 23338c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_TABLE_TX_MAC, /* TX match pri 1 */ 23348c2ecf20Sopenharmony_ci}; 23358c2ecf20Sopenharmony_ci 23368c2ecf20Sopenharmony_ci#define EFX_FARCH_FILTER_INDEX_WIDTH 13 23378c2ecf20Sopenharmony_ci#define EFX_FARCH_FILTER_INDEX_MASK ((1 << EFX_FARCH_FILTER_INDEX_WIDTH) - 1) 23388c2ecf20Sopenharmony_ci 23398c2ecf20Sopenharmony_cistatic inline u32 23408c2ecf20Sopenharmony_ciefx_farch_filter_make_id(const struct efx_farch_filter_spec *spec, 23418c2ecf20Sopenharmony_ci unsigned int index) 23428c2ecf20Sopenharmony_ci{ 23438c2ecf20Sopenharmony_ci unsigned int range; 23448c2ecf20Sopenharmony_ci 23458c2ecf20Sopenharmony_ci range = efx_farch_filter_type_match_pri[spec->type]; 23468c2ecf20Sopenharmony_ci if (!(spec->flags & EFX_FILTER_FLAG_RX)) 23478c2ecf20Sopenharmony_ci range += EFX_FARCH_FILTER_MATCH_PRI_COUNT; 23488c2ecf20Sopenharmony_ci 23498c2ecf20Sopenharmony_ci return range << EFX_FARCH_FILTER_INDEX_WIDTH | index; 23508c2ecf20Sopenharmony_ci} 23518c2ecf20Sopenharmony_ci 23528c2ecf20Sopenharmony_cistatic inline enum efx_farch_filter_table_id 23538c2ecf20Sopenharmony_ciefx_farch_filter_id_table_id(u32 id) 23548c2ecf20Sopenharmony_ci{ 23558c2ecf20Sopenharmony_ci unsigned int range = id >> EFX_FARCH_FILTER_INDEX_WIDTH; 23568c2ecf20Sopenharmony_ci 23578c2ecf20Sopenharmony_ci if (range < ARRAY_SIZE(efx_farch_filter_range_table)) 23588c2ecf20Sopenharmony_ci return efx_farch_filter_range_table[range]; 23598c2ecf20Sopenharmony_ci else 23608c2ecf20Sopenharmony_ci return EFX_FARCH_FILTER_TABLE_COUNT; /* invalid */ 23618c2ecf20Sopenharmony_ci} 23628c2ecf20Sopenharmony_ci 23638c2ecf20Sopenharmony_cistatic inline unsigned int efx_farch_filter_id_index(u32 id) 23648c2ecf20Sopenharmony_ci{ 23658c2ecf20Sopenharmony_ci return id & EFX_FARCH_FILTER_INDEX_MASK; 23668c2ecf20Sopenharmony_ci} 23678c2ecf20Sopenharmony_ci 23688c2ecf20Sopenharmony_ciu32 efx_farch_filter_get_rx_id_limit(struct efx_nic *efx) 23698c2ecf20Sopenharmony_ci{ 23708c2ecf20Sopenharmony_ci struct efx_farch_filter_state *state = efx->filter_state; 23718c2ecf20Sopenharmony_ci unsigned int range = EFX_FARCH_FILTER_MATCH_PRI_COUNT - 1; 23728c2ecf20Sopenharmony_ci enum efx_farch_filter_table_id table_id; 23738c2ecf20Sopenharmony_ci 23748c2ecf20Sopenharmony_ci do { 23758c2ecf20Sopenharmony_ci table_id = efx_farch_filter_range_table[range]; 23768c2ecf20Sopenharmony_ci if (state->table[table_id].size != 0) 23778c2ecf20Sopenharmony_ci return range << EFX_FARCH_FILTER_INDEX_WIDTH | 23788c2ecf20Sopenharmony_ci state->table[table_id].size; 23798c2ecf20Sopenharmony_ci } while (range--); 23808c2ecf20Sopenharmony_ci 23818c2ecf20Sopenharmony_ci return 0; 23828c2ecf20Sopenharmony_ci} 23838c2ecf20Sopenharmony_ci 23848c2ecf20Sopenharmony_cis32 efx_farch_filter_insert(struct efx_nic *efx, 23858c2ecf20Sopenharmony_ci struct efx_filter_spec *gen_spec, 23868c2ecf20Sopenharmony_ci bool replace_equal) 23878c2ecf20Sopenharmony_ci{ 23888c2ecf20Sopenharmony_ci struct efx_farch_filter_state *state = efx->filter_state; 23898c2ecf20Sopenharmony_ci struct efx_farch_filter_table *table; 23908c2ecf20Sopenharmony_ci struct efx_farch_filter_spec spec; 23918c2ecf20Sopenharmony_ci efx_oword_t filter; 23928c2ecf20Sopenharmony_ci int rep_index, ins_index; 23938c2ecf20Sopenharmony_ci unsigned int depth = 0; 23948c2ecf20Sopenharmony_ci int rc; 23958c2ecf20Sopenharmony_ci 23968c2ecf20Sopenharmony_ci rc = efx_farch_filter_from_gen_spec(&spec, gen_spec); 23978c2ecf20Sopenharmony_ci if (rc) 23988c2ecf20Sopenharmony_ci return rc; 23998c2ecf20Sopenharmony_ci 24008c2ecf20Sopenharmony_ci down_write(&state->lock); 24018c2ecf20Sopenharmony_ci 24028c2ecf20Sopenharmony_ci table = &state->table[efx_farch_filter_spec_table_id(&spec)]; 24038c2ecf20Sopenharmony_ci if (table->size == 0) { 24048c2ecf20Sopenharmony_ci rc = -EINVAL; 24058c2ecf20Sopenharmony_ci goto out_unlock; 24068c2ecf20Sopenharmony_ci } 24078c2ecf20Sopenharmony_ci 24088c2ecf20Sopenharmony_ci netif_vdbg(efx, hw, efx->net_dev, 24098c2ecf20Sopenharmony_ci "%s: type %d search_limit=%d", __func__, spec.type, 24108c2ecf20Sopenharmony_ci table->search_limit[spec.type]); 24118c2ecf20Sopenharmony_ci 24128c2ecf20Sopenharmony_ci if (table->id == EFX_FARCH_FILTER_TABLE_RX_DEF) { 24138c2ecf20Sopenharmony_ci /* One filter spec per type */ 24148c2ecf20Sopenharmony_ci BUILD_BUG_ON(EFX_FARCH_FILTER_INDEX_UC_DEF != 0); 24158c2ecf20Sopenharmony_ci BUILD_BUG_ON(EFX_FARCH_FILTER_INDEX_MC_DEF != 24168c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_MC_DEF - EFX_FARCH_FILTER_UC_DEF); 24178c2ecf20Sopenharmony_ci rep_index = spec.type - EFX_FARCH_FILTER_UC_DEF; 24188c2ecf20Sopenharmony_ci ins_index = rep_index; 24198c2ecf20Sopenharmony_ci } else { 24208c2ecf20Sopenharmony_ci /* Search concurrently for 24218c2ecf20Sopenharmony_ci * (1) a filter to be replaced (rep_index): any filter 24228c2ecf20Sopenharmony_ci * with the same match values, up to the current 24238c2ecf20Sopenharmony_ci * search depth for this type, and 24248c2ecf20Sopenharmony_ci * (2) the insertion point (ins_index): (1) or any 24258c2ecf20Sopenharmony_ci * free slot before it or up to the maximum search 24268c2ecf20Sopenharmony_ci * depth for this priority 24278c2ecf20Sopenharmony_ci * We fail if we cannot find (2). 24288c2ecf20Sopenharmony_ci * 24298c2ecf20Sopenharmony_ci * We can stop once either 24308c2ecf20Sopenharmony_ci * (a) we find (1), in which case we have definitely 24318c2ecf20Sopenharmony_ci * found (2) as well; or 24328c2ecf20Sopenharmony_ci * (b) we have searched exhaustively for (1), and have 24338c2ecf20Sopenharmony_ci * either found (2) or searched exhaustively for it 24348c2ecf20Sopenharmony_ci */ 24358c2ecf20Sopenharmony_ci u32 key = efx_farch_filter_build(&filter, &spec); 24368c2ecf20Sopenharmony_ci unsigned int hash = efx_farch_filter_hash(key); 24378c2ecf20Sopenharmony_ci unsigned int incr = efx_farch_filter_increment(key); 24388c2ecf20Sopenharmony_ci unsigned int max_rep_depth = table->search_limit[spec.type]; 24398c2ecf20Sopenharmony_ci unsigned int max_ins_depth = 24408c2ecf20Sopenharmony_ci spec.priority <= EFX_FILTER_PRI_HINT ? 24418c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_CTL_SRCH_HINT_MAX : 24428c2ecf20Sopenharmony_ci EFX_FARCH_FILTER_CTL_SRCH_MAX; 24438c2ecf20Sopenharmony_ci unsigned int i = hash & (table->size - 1); 24448c2ecf20Sopenharmony_ci 24458c2ecf20Sopenharmony_ci ins_index = -1; 24468c2ecf20Sopenharmony_ci depth = 1; 24478c2ecf20Sopenharmony_ci 24488c2ecf20Sopenharmony_ci for (;;) { 24498c2ecf20Sopenharmony_ci if (!test_bit(i, table->used_bitmap)) { 24508c2ecf20Sopenharmony_ci if (ins_index < 0) 24518c2ecf20Sopenharmony_ci ins_index = i; 24528c2ecf20Sopenharmony_ci } else if (efx_farch_filter_equal(&spec, 24538c2ecf20Sopenharmony_ci &table->spec[i])) { 24548c2ecf20Sopenharmony_ci /* Case (a) */ 24558c2ecf20Sopenharmony_ci if (ins_index < 0) 24568c2ecf20Sopenharmony_ci ins_index = i; 24578c2ecf20Sopenharmony_ci rep_index = i; 24588c2ecf20Sopenharmony_ci break; 24598c2ecf20Sopenharmony_ci } 24608c2ecf20Sopenharmony_ci 24618c2ecf20Sopenharmony_ci if (depth >= max_rep_depth && 24628c2ecf20Sopenharmony_ci (ins_index >= 0 || depth >= max_ins_depth)) { 24638c2ecf20Sopenharmony_ci /* Case (b) */ 24648c2ecf20Sopenharmony_ci if (ins_index < 0) { 24658c2ecf20Sopenharmony_ci rc = -EBUSY; 24668c2ecf20Sopenharmony_ci goto out_unlock; 24678c2ecf20Sopenharmony_ci } 24688c2ecf20Sopenharmony_ci rep_index = -1; 24698c2ecf20Sopenharmony_ci break; 24708c2ecf20Sopenharmony_ci } 24718c2ecf20Sopenharmony_ci 24728c2ecf20Sopenharmony_ci i = (i + incr) & (table->size - 1); 24738c2ecf20Sopenharmony_ci ++depth; 24748c2ecf20Sopenharmony_ci } 24758c2ecf20Sopenharmony_ci } 24768c2ecf20Sopenharmony_ci 24778c2ecf20Sopenharmony_ci /* If we found a filter to be replaced, check whether we 24788c2ecf20Sopenharmony_ci * should do so 24798c2ecf20Sopenharmony_ci */ 24808c2ecf20Sopenharmony_ci if (rep_index >= 0) { 24818c2ecf20Sopenharmony_ci struct efx_farch_filter_spec *saved_spec = 24828c2ecf20Sopenharmony_ci &table->spec[rep_index]; 24838c2ecf20Sopenharmony_ci 24848c2ecf20Sopenharmony_ci if (spec.priority == saved_spec->priority && !replace_equal) { 24858c2ecf20Sopenharmony_ci rc = -EEXIST; 24868c2ecf20Sopenharmony_ci goto out_unlock; 24878c2ecf20Sopenharmony_ci } 24888c2ecf20Sopenharmony_ci if (spec.priority < saved_spec->priority) { 24898c2ecf20Sopenharmony_ci rc = -EPERM; 24908c2ecf20Sopenharmony_ci goto out_unlock; 24918c2ecf20Sopenharmony_ci } 24928c2ecf20Sopenharmony_ci if (saved_spec->priority == EFX_FILTER_PRI_AUTO || 24938c2ecf20Sopenharmony_ci saved_spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) 24948c2ecf20Sopenharmony_ci spec.flags |= EFX_FILTER_FLAG_RX_OVER_AUTO; 24958c2ecf20Sopenharmony_ci } 24968c2ecf20Sopenharmony_ci 24978c2ecf20Sopenharmony_ci /* Insert the filter */ 24988c2ecf20Sopenharmony_ci if (ins_index != rep_index) { 24998c2ecf20Sopenharmony_ci __set_bit(ins_index, table->used_bitmap); 25008c2ecf20Sopenharmony_ci ++table->used; 25018c2ecf20Sopenharmony_ci } 25028c2ecf20Sopenharmony_ci table->spec[ins_index] = spec; 25038c2ecf20Sopenharmony_ci 25048c2ecf20Sopenharmony_ci if (table->id == EFX_FARCH_FILTER_TABLE_RX_DEF) { 25058c2ecf20Sopenharmony_ci efx_farch_filter_push_rx_config(efx); 25068c2ecf20Sopenharmony_ci } else { 25078c2ecf20Sopenharmony_ci if (table->search_limit[spec.type] < depth) { 25088c2ecf20Sopenharmony_ci table->search_limit[spec.type] = depth; 25098c2ecf20Sopenharmony_ci if (spec.flags & EFX_FILTER_FLAG_TX) 25108c2ecf20Sopenharmony_ci efx_farch_filter_push_tx_limits(efx); 25118c2ecf20Sopenharmony_ci else 25128c2ecf20Sopenharmony_ci efx_farch_filter_push_rx_config(efx); 25138c2ecf20Sopenharmony_ci } 25148c2ecf20Sopenharmony_ci 25158c2ecf20Sopenharmony_ci efx_writeo(efx, &filter, 25168c2ecf20Sopenharmony_ci table->offset + table->step * ins_index); 25178c2ecf20Sopenharmony_ci 25188c2ecf20Sopenharmony_ci /* If we were able to replace a filter by inserting 25198c2ecf20Sopenharmony_ci * at a lower depth, clear the replaced filter 25208c2ecf20Sopenharmony_ci */ 25218c2ecf20Sopenharmony_ci if (ins_index != rep_index && rep_index >= 0) 25228c2ecf20Sopenharmony_ci efx_farch_filter_table_clear_entry(efx, table, 25238c2ecf20Sopenharmony_ci rep_index); 25248c2ecf20Sopenharmony_ci } 25258c2ecf20Sopenharmony_ci 25268c2ecf20Sopenharmony_ci netif_vdbg(efx, hw, efx->net_dev, 25278c2ecf20Sopenharmony_ci "%s: filter type %d index %d rxq %u set", 25288c2ecf20Sopenharmony_ci __func__, spec.type, ins_index, spec.dmaq_id); 25298c2ecf20Sopenharmony_ci rc = efx_farch_filter_make_id(&spec, ins_index); 25308c2ecf20Sopenharmony_ci 25318c2ecf20Sopenharmony_ciout_unlock: 25328c2ecf20Sopenharmony_ci up_write(&state->lock); 25338c2ecf20Sopenharmony_ci return rc; 25348c2ecf20Sopenharmony_ci} 25358c2ecf20Sopenharmony_ci 25368c2ecf20Sopenharmony_cistatic void 25378c2ecf20Sopenharmony_ciefx_farch_filter_table_clear_entry(struct efx_nic *efx, 25388c2ecf20Sopenharmony_ci struct efx_farch_filter_table *table, 25398c2ecf20Sopenharmony_ci unsigned int filter_idx) 25408c2ecf20Sopenharmony_ci{ 25418c2ecf20Sopenharmony_ci static efx_oword_t filter; 25428c2ecf20Sopenharmony_ci 25438c2ecf20Sopenharmony_ci EFX_WARN_ON_PARANOID(!test_bit(filter_idx, table->used_bitmap)); 25448c2ecf20Sopenharmony_ci BUG_ON(table->offset == 0); /* can't clear MAC default filters */ 25458c2ecf20Sopenharmony_ci 25468c2ecf20Sopenharmony_ci __clear_bit(filter_idx, table->used_bitmap); 25478c2ecf20Sopenharmony_ci --table->used; 25488c2ecf20Sopenharmony_ci memset(&table->spec[filter_idx], 0, sizeof(table->spec[0])); 25498c2ecf20Sopenharmony_ci 25508c2ecf20Sopenharmony_ci efx_writeo(efx, &filter, table->offset + table->step * filter_idx); 25518c2ecf20Sopenharmony_ci 25528c2ecf20Sopenharmony_ci /* If this filter required a greater search depth than 25538c2ecf20Sopenharmony_ci * any other, the search limit for its type can now be 25548c2ecf20Sopenharmony_ci * decreased. However, it is hard to determine that 25558c2ecf20Sopenharmony_ci * unless the table has become completely empty - in 25568c2ecf20Sopenharmony_ci * which case, all its search limits can be set to 0. 25578c2ecf20Sopenharmony_ci */ 25588c2ecf20Sopenharmony_ci if (unlikely(table->used == 0)) { 25598c2ecf20Sopenharmony_ci memset(table->search_limit, 0, sizeof(table->search_limit)); 25608c2ecf20Sopenharmony_ci if (table->id == EFX_FARCH_FILTER_TABLE_TX_MAC) 25618c2ecf20Sopenharmony_ci efx_farch_filter_push_tx_limits(efx); 25628c2ecf20Sopenharmony_ci else 25638c2ecf20Sopenharmony_ci efx_farch_filter_push_rx_config(efx); 25648c2ecf20Sopenharmony_ci } 25658c2ecf20Sopenharmony_ci} 25668c2ecf20Sopenharmony_ci 25678c2ecf20Sopenharmony_cistatic int efx_farch_filter_remove(struct efx_nic *efx, 25688c2ecf20Sopenharmony_ci struct efx_farch_filter_table *table, 25698c2ecf20Sopenharmony_ci unsigned int filter_idx, 25708c2ecf20Sopenharmony_ci enum efx_filter_priority priority) 25718c2ecf20Sopenharmony_ci{ 25728c2ecf20Sopenharmony_ci struct efx_farch_filter_spec *spec = &table->spec[filter_idx]; 25738c2ecf20Sopenharmony_ci 25748c2ecf20Sopenharmony_ci if (!test_bit(filter_idx, table->used_bitmap) || 25758c2ecf20Sopenharmony_ci spec->priority != priority) 25768c2ecf20Sopenharmony_ci return -ENOENT; 25778c2ecf20Sopenharmony_ci 25788c2ecf20Sopenharmony_ci if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) { 25798c2ecf20Sopenharmony_ci efx_farch_filter_init_rx_auto(efx, spec); 25808c2ecf20Sopenharmony_ci efx_farch_filter_push_rx_config(efx); 25818c2ecf20Sopenharmony_ci } else { 25828c2ecf20Sopenharmony_ci efx_farch_filter_table_clear_entry(efx, table, filter_idx); 25838c2ecf20Sopenharmony_ci } 25848c2ecf20Sopenharmony_ci 25858c2ecf20Sopenharmony_ci return 0; 25868c2ecf20Sopenharmony_ci} 25878c2ecf20Sopenharmony_ci 25888c2ecf20Sopenharmony_ciint efx_farch_filter_remove_safe(struct efx_nic *efx, 25898c2ecf20Sopenharmony_ci enum efx_filter_priority priority, 25908c2ecf20Sopenharmony_ci u32 filter_id) 25918c2ecf20Sopenharmony_ci{ 25928c2ecf20Sopenharmony_ci struct efx_farch_filter_state *state = efx->filter_state; 25938c2ecf20Sopenharmony_ci enum efx_farch_filter_table_id table_id; 25948c2ecf20Sopenharmony_ci struct efx_farch_filter_table *table; 25958c2ecf20Sopenharmony_ci unsigned int filter_idx; 25968c2ecf20Sopenharmony_ci int rc; 25978c2ecf20Sopenharmony_ci 25988c2ecf20Sopenharmony_ci table_id = efx_farch_filter_id_table_id(filter_id); 25998c2ecf20Sopenharmony_ci if ((unsigned int)table_id >= EFX_FARCH_FILTER_TABLE_COUNT) 26008c2ecf20Sopenharmony_ci return -ENOENT; 26018c2ecf20Sopenharmony_ci table = &state->table[table_id]; 26028c2ecf20Sopenharmony_ci 26038c2ecf20Sopenharmony_ci filter_idx = efx_farch_filter_id_index(filter_id); 26048c2ecf20Sopenharmony_ci if (filter_idx >= table->size) 26058c2ecf20Sopenharmony_ci return -ENOENT; 26068c2ecf20Sopenharmony_ci down_write(&state->lock); 26078c2ecf20Sopenharmony_ci 26088c2ecf20Sopenharmony_ci rc = efx_farch_filter_remove(efx, table, filter_idx, priority); 26098c2ecf20Sopenharmony_ci up_write(&state->lock); 26108c2ecf20Sopenharmony_ci 26118c2ecf20Sopenharmony_ci return rc; 26128c2ecf20Sopenharmony_ci} 26138c2ecf20Sopenharmony_ci 26148c2ecf20Sopenharmony_ciint efx_farch_filter_get_safe(struct efx_nic *efx, 26158c2ecf20Sopenharmony_ci enum efx_filter_priority priority, 26168c2ecf20Sopenharmony_ci u32 filter_id, struct efx_filter_spec *spec_buf) 26178c2ecf20Sopenharmony_ci{ 26188c2ecf20Sopenharmony_ci struct efx_farch_filter_state *state = efx->filter_state; 26198c2ecf20Sopenharmony_ci enum efx_farch_filter_table_id table_id; 26208c2ecf20Sopenharmony_ci struct efx_farch_filter_table *table; 26218c2ecf20Sopenharmony_ci struct efx_farch_filter_spec *spec; 26228c2ecf20Sopenharmony_ci unsigned int filter_idx; 26238c2ecf20Sopenharmony_ci int rc = -ENOENT; 26248c2ecf20Sopenharmony_ci 26258c2ecf20Sopenharmony_ci down_read(&state->lock); 26268c2ecf20Sopenharmony_ci 26278c2ecf20Sopenharmony_ci table_id = efx_farch_filter_id_table_id(filter_id); 26288c2ecf20Sopenharmony_ci if ((unsigned int)table_id >= EFX_FARCH_FILTER_TABLE_COUNT) 26298c2ecf20Sopenharmony_ci goto out_unlock; 26308c2ecf20Sopenharmony_ci table = &state->table[table_id]; 26318c2ecf20Sopenharmony_ci 26328c2ecf20Sopenharmony_ci filter_idx = efx_farch_filter_id_index(filter_id); 26338c2ecf20Sopenharmony_ci if (filter_idx >= table->size) 26348c2ecf20Sopenharmony_ci goto out_unlock; 26358c2ecf20Sopenharmony_ci spec = &table->spec[filter_idx]; 26368c2ecf20Sopenharmony_ci 26378c2ecf20Sopenharmony_ci if (test_bit(filter_idx, table->used_bitmap) && 26388c2ecf20Sopenharmony_ci spec->priority == priority) { 26398c2ecf20Sopenharmony_ci efx_farch_filter_to_gen_spec(spec_buf, spec); 26408c2ecf20Sopenharmony_ci rc = 0; 26418c2ecf20Sopenharmony_ci } 26428c2ecf20Sopenharmony_ci 26438c2ecf20Sopenharmony_ciout_unlock: 26448c2ecf20Sopenharmony_ci up_read(&state->lock); 26458c2ecf20Sopenharmony_ci return rc; 26468c2ecf20Sopenharmony_ci} 26478c2ecf20Sopenharmony_ci 26488c2ecf20Sopenharmony_cistatic void 26498c2ecf20Sopenharmony_ciefx_farch_filter_table_clear(struct efx_nic *efx, 26508c2ecf20Sopenharmony_ci enum efx_farch_filter_table_id table_id, 26518c2ecf20Sopenharmony_ci enum efx_filter_priority priority) 26528c2ecf20Sopenharmony_ci{ 26538c2ecf20Sopenharmony_ci struct efx_farch_filter_state *state = efx->filter_state; 26548c2ecf20Sopenharmony_ci struct efx_farch_filter_table *table = &state->table[table_id]; 26558c2ecf20Sopenharmony_ci unsigned int filter_idx; 26568c2ecf20Sopenharmony_ci 26578c2ecf20Sopenharmony_ci down_write(&state->lock); 26588c2ecf20Sopenharmony_ci for (filter_idx = 0; filter_idx < table->size; ++filter_idx) { 26598c2ecf20Sopenharmony_ci if (table->spec[filter_idx].priority != EFX_FILTER_PRI_AUTO) 26608c2ecf20Sopenharmony_ci efx_farch_filter_remove(efx, table, 26618c2ecf20Sopenharmony_ci filter_idx, priority); 26628c2ecf20Sopenharmony_ci } 26638c2ecf20Sopenharmony_ci up_write(&state->lock); 26648c2ecf20Sopenharmony_ci} 26658c2ecf20Sopenharmony_ci 26668c2ecf20Sopenharmony_ciint efx_farch_filter_clear_rx(struct efx_nic *efx, 26678c2ecf20Sopenharmony_ci enum efx_filter_priority priority) 26688c2ecf20Sopenharmony_ci{ 26698c2ecf20Sopenharmony_ci efx_farch_filter_table_clear(efx, EFX_FARCH_FILTER_TABLE_RX_IP, 26708c2ecf20Sopenharmony_ci priority); 26718c2ecf20Sopenharmony_ci efx_farch_filter_table_clear(efx, EFX_FARCH_FILTER_TABLE_RX_MAC, 26728c2ecf20Sopenharmony_ci priority); 26738c2ecf20Sopenharmony_ci efx_farch_filter_table_clear(efx, EFX_FARCH_FILTER_TABLE_RX_DEF, 26748c2ecf20Sopenharmony_ci priority); 26758c2ecf20Sopenharmony_ci return 0; 26768c2ecf20Sopenharmony_ci} 26778c2ecf20Sopenharmony_ci 26788c2ecf20Sopenharmony_ciu32 efx_farch_filter_count_rx_used(struct efx_nic *efx, 26798c2ecf20Sopenharmony_ci enum efx_filter_priority priority) 26808c2ecf20Sopenharmony_ci{ 26818c2ecf20Sopenharmony_ci struct efx_farch_filter_state *state = efx->filter_state; 26828c2ecf20Sopenharmony_ci enum efx_farch_filter_table_id table_id; 26838c2ecf20Sopenharmony_ci struct efx_farch_filter_table *table; 26848c2ecf20Sopenharmony_ci unsigned int filter_idx; 26858c2ecf20Sopenharmony_ci u32 count = 0; 26868c2ecf20Sopenharmony_ci 26878c2ecf20Sopenharmony_ci down_read(&state->lock); 26888c2ecf20Sopenharmony_ci 26898c2ecf20Sopenharmony_ci for (table_id = EFX_FARCH_FILTER_TABLE_RX_IP; 26908c2ecf20Sopenharmony_ci table_id <= EFX_FARCH_FILTER_TABLE_RX_DEF; 26918c2ecf20Sopenharmony_ci table_id++) { 26928c2ecf20Sopenharmony_ci table = &state->table[table_id]; 26938c2ecf20Sopenharmony_ci for (filter_idx = 0; filter_idx < table->size; filter_idx++) { 26948c2ecf20Sopenharmony_ci if (test_bit(filter_idx, table->used_bitmap) && 26958c2ecf20Sopenharmony_ci table->spec[filter_idx].priority == priority) 26968c2ecf20Sopenharmony_ci ++count; 26978c2ecf20Sopenharmony_ci } 26988c2ecf20Sopenharmony_ci } 26998c2ecf20Sopenharmony_ci 27008c2ecf20Sopenharmony_ci up_read(&state->lock); 27018c2ecf20Sopenharmony_ci 27028c2ecf20Sopenharmony_ci return count; 27038c2ecf20Sopenharmony_ci} 27048c2ecf20Sopenharmony_ci 27058c2ecf20Sopenharmony_cis32 efx_farch_filter_get_rx_ids(struct efx_nic *efx, 27068c2ecf20Sopenharmony_ci enum efx_filter_priority priority, 27078c2ecf20Sopenharmony_ci u32 *buf, u32 size) 27088c2ecf20Sopenharmony_ci{ 27098c2ecf20Sopenharmony_ci struct efx_farch_filter_state *state = efx->filter_state; 27108c2ecf20Sopenharmony_ci enum efx_farch_filter_table_id table_id; 27118c2ecf20Sopenharmony_ci struct efx_farch_filter_table *table; 27128c2ecf20Sopenharmony_ci unsigned int filter_idx; 27138c2ecf20Sopenharmony_ci s32 count = 0; 27148c2ecf20Sopenharmony_ci 27158c2ecf20Sopenharmony_ci down_read(&state->lock); 27168c2ecf20Sopenharmony_ci 27178c2ecf20Sopenharmony_ci for (table_id = EFX_FARCH_FILTER_TABLE_RX_IP; 27188c2ecf20Sopenharmony_ci table_id <= EFX_FARCH_FILTER_TABLE_RX_DEF; 27198c2ecf20Sopenharmony_ci table_id++) { 27208c2ecf20Sopenharmony_ci table = &state->table[table_id]; 27218c2ecf20Sopenharmony_ci for (filter_idx = 0; filter_idx < table->size; filter_idx++) { 27228c2ecf20Sopenharmony_ci if (test_bit(filter_idx, table->used_bitmap) && 27238c2ecf20Sopenharmony_ci table->spec[filter_idx].priority == priority) { 27248c2ecf20Sopenharmony_ci if (count == size) { 27258c2ecf20Sopenharmony_ci count = -EMSGSIZE; 27268c2ecf20Sopenharmony_ci goto out; 27278c2ecf20Sopenharmony_ci } 27288c2ecf20Sopenharmony_ci buf[count++] = efx_farch_filter_make_id( 27298c2ecf20Sopenharmony_ci &table->spec[filter_idx], filter_idx); 27308c2ecf20Sopenharmony_ci } 27318c2ecf20Sopenharmony_ci } 27328c2ecf20Sopenharmony_ci } 27338c2ecf20Sopenharmony_ciout: 27348c2ecf20Sopenharmony_ci up_read(&state->lock); 27358c2ecf20Sopenharmony_ci 27368c2ecf20Sopenharmony_ci return count; 27378c2ecf20Sopenharmony_ci} 27388c2ecf20Sopenharmony_ci 27398c2ecf20Sopenharmony_ci/* Restore filter stater after reset */ 27408c2ecf20Sopenharmony_civoid efx_farch_filter_table_restore(struct efx_nic *efx) 27418c2ecf20Sopenharmony_ci{ 27428c2ecf20Sopenharmony_ci struct efx_farch_filter_state *state = efx->filter_state; 27438c2ecf20Sopenharmony_ci enum efx_farch_filter_table_id table_id; 27448c2ecf20Sopenharmony_ci struct efx_farch_filter_table *table; 27458c2ecf20Sopenharmony_ci efx_oword_t filter; 27468c2ecf20Sopenharmony_ci unsigned int filter_idx; 27478c2ecf20Sopenharmony_ci 27488c2ecf20Sopenharmony_ci down_write(&state->lock); 27498c2ecf20Sopenharmony_ci 27508c2ecf20Sopenharmony_ci for (table_id = 0; table_id < EFX_FARCH_FILTER_TABLE_COUNT; table_id++) { 27518c2ecf20Sopenharmony_ci table = &state->table[table_id]; 27528c2ecf20Sopenharmony_ci 27538c2ecf20Sopenharmony_ci /* Check whether this is a regular register table */ 27548c2ecf20Sopenharmony_ci if (table->step == 0) 27558c2ecf20Sopenharmony_ci continue; 27568c2ecf20Sopenharmony_ci 27578c2ecf20Sopenharmony_ci for (filter_idx = 0; filter_idx < table->size; filter_idx++) { 27588c2ecf20Sopenharmony_ci if (!test_bit(filter_idx, table->used_bitmap)) 27598c2ecf20Sopenharmony_ci continue; 27608c2ecf20Sopenharmony_ci efx_farch_filter_build(&filter, &table->spec[filter_idx]); 27618c2ecf20Sopenharmony_ci efx_writeo(efx, &filter, 27628c2ecf20Sopenharmony_ci table->offset + table->step * filter_idx); 27638c2ecf20Sopenharmony_ci } 27648c2ecf20Sopenharmony_ci } 27658c2ecf20Sopenharmony_ci 27668c2ecf20Sopenharmony_ci efx_farch_filter_push_rx_config(efx); 27678c2ecf20Sopenharmony_ci efx_farch_filter_push_tx_limits(efx); 27688c2ecf20Sopenharmony_ci 27698c2ecf20Sopenharmony_ci up_write(&state->lock); 27708c2ecf20Sopenharmony_ci} 27718c2ecf20Sopenharmony_ci 27728c2ecf20Sopenharmony_civoid efx_farch_filter_table_remove(struct efx_nic *efx) 27738c2ecf20Sopenharmony_ci{ 27748c2ecf20Sopenharmony_ci struct efx_farch_filter_state *state = efx->filter_state; 27758c2ecf20Sopenharmony_ci enum efx_farch_filter_table_id table_id; 27768c2ecf20Sopenharmony_ci 27778c2ecf20Sopenharmony_ci for (table_id = 0; table_id < EFX_FARCH_FILTER_TABLE_COUNT; table_id++) { 27788c2ecf20Sopenharmony_ci kfree(state->table[table_id].used_bitmap); 27798c2ecf20Sopenharmony_ci vfree(state->table[table_id].spec); 27808c2ecf20Sopenharmony_ci } 27818c2ecf20Sopenharmony_ci kfree(state); 27828c2ecf20Sopenharmony_ci} 27838c2ecf20Sopenharmony_ci 27848c2ecf20Sopenharmony_ciint efx_farch_filter_table_probe(struct efx_nic *efx) 27858c2ecf20Sopenharmony_ci{ 27868c2ecf20Sopenharmony_ci struct efx_farch_filter_state *state; 27878c2ecf20Sopenharmony_ci struct efx_farch_filter_table *table; 27888c2ecf20Sopenharmony_ci unsigned table_id; 27898c2ecf20Sopenharmony_ci 27908c2ecf20Sopenharmony_ci state = kzalloc(sizeof(struct efx_farch_filter_state), GFP_KERNEL); 27918c2ecf20Sopenharmony_ci if (!state) 27928c2ecf20Sopenharmony_ci return -ENOMEM; 27938c2ecf20Sopenharmony_ci efx->filter_state = state; 27948c2ecf20Sopenharmony_ci init_rwsem(&state->lock); 27958c2ecf20Sopenharmony_ci 27968c2ecf20Sopenharmony_ci table = &state->table[EFX_FARCH_FILTER_TABLE_RX_IP]; 27978c2ecf20Sopenharmony_ci table->id = EFX_FARCH_FILTER_TABLE_RX_IP; 27988c2ecf20Sopenharmony_ci table->offset = FR_BZ_RX_FILTER_TBL0; 27998c2ecf20Sopenharmony_ci table->size = FR_BZ_RX_FILTER_TBL0_ROWS; 28008c2ecf20Sopenharmony_ci table->step = FR_BZ_RX_FILTER_TBL0_STEP; 28018c2ecf20Sopenharmony_ci 28028c2ecf20Sopenharmony_ci table = &state->table[EFX_FARCH_FILTER_TABLE_RX_MAC]; 28038c2ecf20Sopenharmony_ci table->id = EFX_FARCH_FILTER_TABLE_RX_MAC; 28048c2ecf20Sopenharmony_ci table->offset = FR_CZ_RX_MAC_FILTER_TBL0; 28058c2ecf20Sopenharmony_ci table->size = FR_CZ_RX_MAC_FILTER_TBL0_ROWS; 28068c2ecf20Sopenharmony_ci table->step = FR_CZ_RX_MAC_FILTER_TBL0_STEP; 28078c2ecf20Sopenharmony_ci 28088c2ecf20Sopenharmony_ci table = &state->table[EFX_FARCH_FILTER_TABLE_RX_DEF]; 28098c2ecf20Sopenharmony_ci table->id = EFX_FARCH_FILTER_TABLE_RX_DEF; 28108c2ecf20Sopenharmony_ci table->size = EFX_FARCH_FILTER_SIZE_RX_DEF; 28118c2ecf20Sopenharmony_ci 28128c2ecf20Sopenharmony_ci table = &state->table[EFX_FARCH_FILTER_TABLE_TX_MAC]; 28138c2ecf20Sopenharmony_ci table->id = EFX_FARCH_FILTER_TABLE_TX_MAC; 28148c2ecf20Sopenharmony_ci table->offset = FR_CZ_TX_MAC_FILTER_TBL0; 28158c2ecf20Sopenharmony_ci table->size = FR_CZ_TX_MAC_FILTER_TBL0_ROWS; 28168c2ecf20Sopenharmony_ci table->step = FR_CZ_TX_MAC_FILTER_TBL0_STEP; 28178c2ecf20Sopenharmony_ci 28188c2ecf20Sopenharmony_ci for (table_id = 0; table_id < EFX_FARCH_FILTER_TABLE_COUNT; table_id++) { 28198c2ecf20Sopenharmony_ci table = &state->table[table_id]; 28208c2ecf20Sopenharmony_ci if (table->size == 0) 28218c2ecf20Sopenharmony_ci continue; 28228c2ecf20Sopenharmony_ci table->used_bitmap = kcalloc(BITS_TO_LONGS(table->size), 28238c2ecf20Sopenharmony_ci sizeof(unsigned long), 28248c2ecf20Sopenharmony_ci GFP_KERNEL); 28258c2ecf20Sopenharmony_ci if (!table->used_bitmap) 28268c2ecf20Sopenharmony_ci goto fail; 28278c2ecf20Sopenharmony_ci table->spec = vzalloc(array_size(sizeof(*table->spec), 28288c2ecf20Sopenharmony_ci table->size)); 28298c2ecf20Sopenharmony_ci if (!table->spec) 28308c2ecf20Sopenharmony_ci goto fail; 28318c2ecf20Sopenharmony_ci } 28328c2ecf20Sopenharmony_ci 28338c2ecf20Sopenharmony_ci table = &state->table[EFX_FARCH_FILTER_TABLE_RX_DEF]; 28348c2ecf20Sopenharmony_ci if (table->size) { 28358c2ecf20Sopenharmony_ci /* RX default filters must always exist */ 28368c2ecf20Sopenharmony_ci struct efx_farch_filter_spec *spec; 28378c2ecf20Sopenharmony_ci unsigned i; 28388c2ecf20Sopenharmony_ci 28398c2ecf20Sopenharmony_ci for (i = 0; i < EFX_FARCH_FILTER_SIZE_RX_DEF; i++) { 28408c2ecf20Sopenharmony_ci spec = &table->spec[i]; 28418c2ecf20Sopenharmony_ci spec->type = EFX_FARCH_FILTER_UC_DEF + i; 28428c2ecf20Sopenharmony_ci efx_farch_filter_init_rx_auto(efx, spec); 28438c2ecf20Sopenharmony_ci __set_bit(i, table->used_bitmap); 28448c2ecf20Sopenharmony_ci } 28458c2ecf20Sopenharmony_ci } 28468c2ecf20Sopenharmony_ci 28478c2ecf20Sopenharmony_ci efx_farch_filter_push_rx_config(efx); 28488c2ecf20Sopenharmony_ci 28498c2ecf20Sopenharmony_ci return 0; 28508c2ecf20Sopenharmony_ci 28518c2ecf20Sopenharmony_cifail: 28528c2ecf20Sopenharmony_ci efx_farch_filter_table_remove(efx); 28538c2ecf20Sopenharmony_ci return -ENOMEM; 28548c2ecf20Sopenharmony_ci} 28558c2ecf20Sopenharmony_ci 28568c2ecf20Sopenharmony_ci/* Update scatter enable flags for filters pointing to our own RX queues */ 28578c2ecf20Sopenharmony_civoid efx_farch_filter_update_rx_scatter(struct efx_nic *efx) 28588c2ecf20Sopenharmony_ci{ 28598c2ecf20Sopenharmony_ci struct efx_farch_filter_state *state = efx->filter_state; 28608c2ecf20Sopenharmony_ci enum efx_farch_filter_table_id table_id; 28618c2ecf20Sopenharmony_ci struct efx_farch_filter_table *table; 28628c2ecf20Sopenharmony_ci efx_oword_t filter; 28638c2ecf20Sopenharmony_ci unsigned int filter_idx; 28648c2ecf20Sopenharmony_ci 28658c2ecf20Sopenharmony_ci down_write(&state->lock); 28668c2ecf20Sopenharmony_ci 28678c2ecf20Sopenharmony_ci for (table_id = EFX_FARCH_FILTER_TABLE_RX_IP; 28688c2ecf20Sopenharmony_ci table_id <= EFX_FARCH_FILTER_TABLE_RX_DEF; 28698c2ecf20Sopenharmony_ci table_id++) { 28708c2ecf20Sopenharmony_ci table = &state->table[table_id]; 28718c2ecf20Sopenharmony_ci 28728c2ecf20Sopenharmony_ci for (filter_idx = 0; filter_idx < table->size; filter_idx++) { 28738c2ecf20Sopenharmony_ci if (!test_bit(filter_idx, table->used_bitmap) || 28748c2ecf20Sopenharmony_ci table->spec[filter_idx].dmaq_id >= 28758c2ecf20Sopenharmony_ci efx->n_rx_channels) 28768c2ecf20Sopenharmony_ci continue; 28778c2ecf20Sopenharmony_ci 28788c2ecf20Sopenharmony_ci if (efx->rx_scatter) 28798c2ecf20Sopenharmony_ci table->spec[filter_idx].flags |= 28808c2ecf20Sopenharmony_ci EFX_FILTER_FLAG_RX_SCATTER; 28818c2ecf20Sopenharmony_ci else 28828c2ecf20Sopenharmony_ci table->spec[filter_idx].flags &= 28838c2ecf20Sopenharmony_ci ~EFX_FILTER_FLAG_RX_SCATTER; 28848c2ecf20Sopenharmony_ci 28858c2ecf20Sopenharmony_ci if (table_id == EFX_FARCH_FILTER_TABLE_RX_DEF) 28868c2ecf20Sopenharmony_ci /* Pushed by efx_farch_filter_push_rx_config() */ 28878c2ecf20Sopenharmony_ci continue; 28888c2ecf20Sopenharmony_ci 28898c2ecf20Sopenharmony_ci efx_farch_filter_build(&filter, &table->spec[filter_idx]); 28908c2ecf20Sopenharmony_ci efx_writeo(efx, &filter, 28918c2ecf20Sopenharmony_ci table->offset + table->step * filter_idx); 28928c2ecf20Sopenharmony_ci } 28938c2ecf20Sopenharmony_ci } 28948c2ecf20Sopenharmony_ci 28958c2ecf20Sopenharmony_ci efx_farch_filter_push_rx_config(efx); 28968c2ecf20Sopenharmony_ci 28978c2ecf20Sopenharmony_ci up_write(&state->lock); 28988c2ecf20Sopenharmony_ci} 28998c2ecf20Sopenharmony_ci 29008c2ecf20Sopenharmony_ci#ifdef CONFIG_RFS_ACCEL 29018c2ecf20Sopenharmony_ci 29028c2ecf20Sopenharmony_cibool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id, 29038c2ecf20Sopenharmony_ci unsigned int index) 29048c2ecf20Sopenharmony_ci{ 29058c2ecf20Sopenharmony_ci struct efx_farch_filter_state *state = efx->filter_state; 29068c2ecf20Sopenharmony_ci struct efx_farch_filter_table *table; 29078c2ecf20Sopenharmony_ci bool ret = false, force = false; 29088c2ecf20Sopenharmony_ci u16 arfs_id; 29098c2ecf20Sopenharmony_ci 29108c2ecf20Sopenharmony_ci down_write(&state->lock); 29118c2ecf20Sopenharmony_ci spin_lock_bh(&efx->rps_hash_lock); 29128c2ecf20Sopenharmony_ci table = &state->table[EFX_FARCH_FILTER_TABLE_RX_IP]; 29138c2ecf20Sopenharmony_ci if (test_bit(index, table->used_bitmap) && 29148c2ecf20Sopenharmony_ci table->spec[index].priority == EFX_FILTER_PRI_HINT) { 29158c2ecf20Sopenharmony_ci struct efx_arfs_rule *rule = NULL; 29168c2ecf20Sopenharmony_ci struct efx_filter_spec spec; 29178c2ecf20Sopenharmony_ci 29188c2ecf20Sopenharmony_ci efx_farch_filter_to_gen_spec(&spec, &table->spec[index]); 29198c2ecf20Sopenharmony_ci if (!efx->rps_hash_table) { 29208c2ecf20Sopenharmony_ci /* In the absence of the table, we always returned 0 to 29218c2ecf20Sopenharmony_ci * ARFS, so use the same to query it. 29228c2ecf20Sopenharmony_ci */ 29238c2ecf20Sopenharmony_ci arfs_id = 0; 29248c2ecf20Sopenharmony_ci } else { 29258c2ecf20Sopenharmony_ci rule = efx_rps_hash_find(efx, &spec); 29268c2ecf20Sopenharmony_ci if (!rule) { 29278c2ecf20Sopenharmony_ci /* ARFS table doesn't know of this filter, remove it */ 29288c2ecf20Sopenharmony_ci force = true; 29298c2ecf20Sopenharmony_ci } else { 29308c2ecf20Sopenharmony_ci arfs_id = rule->arfs_id; 29318c2ecf20Sopenharmony_ci if (!efx_rps_check_rule(rule, index, &force)) 29328c2ecf20Sopenharmony_ci goto out_unlock; 29338c2ecf20Sopenharmony_ci } 29348c2ecf20Sopenharmony_ci } 29358c2ecf20Sopenharmony_ci if (force || rps_may_expire_flow(efx->net_dev, spec.dmaq_id, 29368c2ecf20Sopenharmony_ci flow_id, arfs_id)) { 29378c2ecf20Sopenharmony_ci if (rule) 29388c2ecf20Sopenharmony_ci rule->filter_id = EFX_ARFS_FILTER_ID_REMOVING; 29398c2ecf20Sopenharmony_ci efx_rps_hash_del(efx, &spec); 29408c2ecf20Sopenharmony_ci efx_farch_filter_table_clear_entry(efx, table, index); 29418c2ecf20Sopenharmony_ci ret = true; 29428c2ecf20Sopenharmony_ci } 29438c2ecf20Sopenharmony_ci } 29448c2ecf20Sopenharmony_ciout_unlock: 29458c2ecf20Sopenharmony_ci spin_unlock_bh(&efx->rps_hash_lock); 29468c2ecf20Sopenharmony_ci up_write(&state->lock); 29478c2ecf20Sopenharmony_ci return ret; 29488c2ecf20Sopenharmony_ci} 29498c2ecf20Sopenharmony_ci 29508c2ecf20Sopenharmony_ci#endif /* CONFIG_RFS_ACCEL */ 29518c2ecf20Sopenharmony_ci 29528c2ecf20Sopenharmony_civoid efx_farch_filter_sync_rx_mode(struct efx_nic *efx) 29538c2ecf20Sopenharmony_ci{ 29548c2ecf20Sopenharmony_ci struct net_device *net_dev = efx->net_dev; 29558c2ecf20Sopenharmony_ci struct netdev_hw_addr *ha; 29568c2ecf20Sopenharmony_ci union efx_multicast_hash *mc_hash = &efx->multicast_hash; 29578c2ecf20Sopenharmony_ci u32 crc; 29588c2ecf20Sopenharmony_ci int bit; 29598c2ecf20Sopenharmony_ci 29608c2ecf20Sopenharmony_ci if (!efx_dev_registered(efx)) 29618c2ecf20Sopenharmony_ci return; 29628c2ecf20Sopenharmony_ci 29638c2ecf20Sopenharmony_ci netif_addr_lock_bh(net_dev); 29648c2ecf20Sopenharmony_ci 29658c2ecf20Sopenharmony_ci efx->unicast_filter = !(net_dev->flags & IFF_PROMISC); 29668c2ecf20Sopenharmony_ci 29678c2ecf20Sopenharmony_ci /* Build multicast hash table */ 29688c2ecf20Sopenharmony_ci if (net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) { 29698c2ecf20Sopenharmony_ci memset(mc_hash, 0xff, sizeof(*mc_hash)); 29708c2ecf20Sopenharmony_ci } else { 29718c2ecf20Sopenharmony_ci memset(mc_hash, 0x00, sizeof(*mc_hash)); 29728c2ecf20Sopenharmony_ci netdev_for_each_mc_addr(ha, net_dev) { 29738c2ecf20Sopenharmony_ci crc = ether_crc_le(ETH_ALEN, ha->addr); 29748c2ecf20Sopenharmony_ci bit = crc & (EFX_MCAST_HASH_ENTRIES - 1); 29758c2ecf20Sopenharmony_ci __set_bit_le(bit, mc_hash); 29768c2ecf20Sopenharmony_ci } 29778c2ecf20Sopenharmony_ci 29788c2ecf20Sopenharmony_ci /* Broadcast packets go through the multicast hash filter. 29798c2ecf20Sopenharmony_ci * ether_crc_le() of the broadcast address is 0xbe2612ff 29808c2ecf20Sopenharmony_ci * so we always add bit 0xff to the mask. 29818c2ecf20Sopenharmony_ci */ 29828c2ecf20Sopenharmony_ci __set_bit_le(0xff, mc_hash); 29838c2ecf20Sopenharmony_ci } 29848c2ecf20Sopenharmony_ci 29858c2ecf20Sopenharmony_ci netif_addr_unlock_bh(net_dev); 29868c2ecf20Sopenharmony_ci} 2987