1390f9b8dSAndrew Rybchenko /* SPDX-License-Identifier: BSD-3-Clause
2390f9b8dSAndrew Rybchenko *
398d26ef7SAndrew Rybchenko * Copyright(c) 2019-2021 Xilinx, Inc.
4a0147be5SAndrew Rybchenko * Copyright(c) 2017-2019 Solarflare Communications Inc.
5390f9b8dSAndrew Rybchenko *
6390f9b8dSAndrew Rybchenko * This software was jointly developed between OKTET Labs (under contract
7390f9b8dSAndrew Rybchenko * for Solarflare) and Solarflare Communications, Inc.
8390f9b8dSAndrew Rybchenko */
9390f9b8dSAndrew Rybchenko
10390f9b8dSAndrew Rybchenko /* EF10 equal stride packed stream receive native datapath implementation */
11390f9b8dSAndrew Rybchenko
12390f9b8dSAndrew Rybchenko #include <stdbool.h>
13390f9b8dSAndrew Rybchenko
14390f9b8dSAndrew Rybchenko #include <rte_byteorder.h>
15390f9b8dSAndrew Rybchenko #include <rte_mbuf.h>
16390f9b8dSAndrew Rybchenko #include <rte_io.h>
17390f9b8dSAndrew Rybchenko
18390f9b8dSAndrew Rybchenko #include "efx_types.h"
19390f9b8dSAndrew Rybchenko #include "efx_regs_ef10.h"
20c6845644SAndrew Rybchenko #include "efx.h"
21390f9b8dSAndrew Rybchenko
221b0236e2SAndrew Rybchenko #include "sfc_debug.h"
23390f9b8dSAndrew Rybchenko #include "sfc_tweak.h"
24390f9b8dSAndrew Rybchenko #include "sfc_dp_rx.h"
25390f9b8dSAndrew Rybchenko #include "sfc_kvargs.h"
26390f9b8dSAndrew Rybchenko #include "sfc_ef10.h"
27390f9b8dSAndrew Rybchenko
28390f9b8dSAndrew Rybchenko /* Tunnels are not supported */
29390f9b8dSAndrew Rybchenko #define SFC_EF10_RX_EV_ENCAP_SUPPORT 0
30390f9b8dSAndrew Rybchenko #include "sfc_ef10_rx_ev.h"
31390f9b8dSAndrew Rybchenko
32390f9b8dSAndrew Rybchenko #define sfc_ef10_essb_rx_err(dpq, ...) \
33390f9b8dSAndrew Rybchenko SFC_DP_LOG(SFC_KVARG_DATAPATH_EF10_ESSB, ERR, dpq, __VA_ARGS__)
34390f9b8dSAndrew Rybchenko
35390f9b8dSAndrew Rybchenko #define sfc_ef10_essb_rx_info(dpq, ...) \
36390f9b8dSAndrew Rybchenko SFC_DP_LOG(SFC_KVARG_DATAPATH_EF10_ESSB, INFO, dpq, __VA_ARGS__)
37390f9b8dSAndrew Rybchenko
38390f9b8dSAndrew Rybchenko /*
39390f9b8dSAndrew Rybchenko * Fake length for RXQ descriptors in equal stride super-buffer mode
40390f9b8dSAndrew Rybchenko * to make hardware happy.
41390f9b8dSAndrew Rybchenko */
42390f9b8dSAndrew Rybchenko #define SFC_EF10_ESSB_RX_FAKE_BUF_SIZE 32
43390f9b8dSAndrew Rybchenko
44390f9b8dSAndrew Rybchenko /**
45e9ff01b3SAndrew Rybchenko * Minimum number of Rx buffers the datapath allows to use.
46e9ff01b3SAndrew Rybchenko *
47e9ff01b3SAndrew Rybchenko * Each HW Rx descriptor has many Rx buffers. The number of buffers
48e9ff01b3SAndrew Rybchenko * in one HW Rx descriptor is equal to size of contiguous block
49e9ff01b3SAndrew Rybchenko * provided by Rx buffers memory pool. The contiguous block size
5019653eedSThomas Monjalon * depends on RTE_DRIVER_MEMPOOL_BUCKET_SIZE_KB and rte_mbuf
51e9ff01b3SAndrew Rybchenko * data size specified on the memory pool creation. Typical rte_mbuf
52e9ff01b3SAndrew Rybchenko * data size is about 2k which makes a bit less than 32 buffers in
53e9ff01b3SAndrew Rybchenko * contiguous block with default bucket size equal to 64k.
54e9ff01b3SAndrew Rybchenko * Since HW Rx descriptors are pushed by 8 (see SFC_EF10_RX_WPTR_ALIGN),
55e9ff01b3SAndrew Rybchenko * it makes about 256 as required minimum. Double it in advertised
56e9ff01b3SAndrew Rybchenko * minimum to allow for at least 2 refill blocks.
57e9ff01b3SAndrew Rybchenko */
58e9ff01b3SAndrew Rybchenko #define SFC_EF10_ESSB_RX_DESCS_MIN 512
59e9ff01b3SAndrew Rybchenko
60e9ff01b3SAndrew Rybchenko /**
61e9ff01b3SAndrew Rybchenko * Number of Rx buffers should be aligned to.
62e9ff01b3SAndrew Rybchenko *
63e9ff01b3SAndrew Rybchenko * There are no extra requirements on alignment since actual number of
64e9ff01b3SAndrew Rybchenko * pushed Rx buffers will be multiple by contiguous block size which
65e9ff01b3SAndrew Rybchenko * is unknown beforehand.
66e9ff01b3SAndrew Rybchenko */
67e9ff01b3SAndrew Rybchenko #define SFC_EF10_ESSB_RX_DESCS_ALIGN 1
68e9ff01b3SAndrew Rybchenko
69e9ff01b3SAndrew Rybchenko /**
70390f9b8dSAndrew Rybchenko * Maximum number of descriptors/buffers in the Rx ring.
71390f9b8dSAndrew Rybchenko * It should guarantee that corresponding event queue never overfill.
72390f9b8dSAndrew Rybchenko */
73390f9b8dSAndrew Rybchenko #define SFC_EF10_ESSB_RXQ_LIMIT(_nevs) \
74390f9b8dSAndrew Rybchenko ((_nevs) - 1 /* head must not step on tail */ - \
75390f9b8dSAndrew Rybchenko (SFC_EF10_EV_PER_CACHE_LINE - 1) /* max unused EvQ entries */ - \
76390f9b8dSAndrew Rybchenko 1 /* Rx error */ - 1 /* flush */)
77390f9b8dSAndrew Rybchenko
78390f9b8dSAndrew Rybchenko struct sfc_ef10_essb_rx_sw_desc {
79390f9b8dSAndrew Rybchenko struct rte_mbuf *first_mbuf;
80390f9b8dSAndrew Rybchenko };
81390f9b8dSAndrew Rybchenko
82390f9b8dSAndrew Rybchenko struct sfc_ef10_essb_rxq {
83390f9b8dSAndrew Rybchenko /* Used on data path */
84390f9b8dSAndrew Rybchenko unsigned int flags;
85390f9b8dSAndrew Rybchenko #define SFC_EF10_ESSB_RXQ_STARTED 0x1
86390f9b8dSAndrew Rybchenko #define SFC_EF10_ESSB_RXQ_NOT_RUNNING 0x2
87390f9b8dSAndrew Rybchenko #define SFC_EF10_ESSB_RXQ_EXCEPTION 0x4
88390f9b8dSAndrew Rybchenko unsigned int rxq_ptr_mask;
89390f9b8dSAndrew Rybchenko unsigned int block_size;
90390f9b8dSAndrew Rybchenko unsigned int buf_stride;
91390f9b8dSAndrew Rybchenko unsigned int bufs_ptr;
92390f9b8dSAndrew Rybchenko unsigned int completed;
93390f9b8dSAndrew Rybchenko unsigned int pending_id;
94390f9b8dSAndrew Rybchenko unsigned int bufs_pending;
95390f9b8dSAndrew Rybchenko unsigned int left_in_completed;
96390f9b8dSAndrew Rybchenko unsigned int left_in_pending;
97390f9b8dSAndrew Rybchenko unsigned int evq_read_ptr;
98390f9b8dSAndrew Rybchenko unsigned int evq_ptr_mask;
99390f9b8dSAndrew Rybchenko efx_qword_t *evq_hw_ring;
100390f9b8dSAndrew Rybchenko struct sfc_ef10_essb_rx_sw_desc *sw_ring;
101390f9b8dSAndrew Rybchenko uint16_t port_id;
102390f9b8dSAndrew Rybchenko
103390f9b8dSAndrew Rybchenko /* Used on refill */
104390f9b8dSAndrew Rybchenko unsigned int added;
105390f9b8dSAndrew Rybchenko unsigned int max_fill_level;
106390f9b8dSAndrew Rybchenko unsigned int refill_threshold;
107390f9b8dSAndrew Rybchenko struct rte_mempool *refill_mb_pool;
108390f9b8dSAndrew Rybchenko efx_qword_t *rxq_hw_ring;
109390f9b8dSAndrew Rybchenko volatile void *doorbell;
110390f9b8dSAndrew Rybchenko
111390f9b8dSAndrew Rybchenko /* Datapath receive queue anchor */
112390f9b8dSAndrew Rybchenko struct sfc_dp_rxq dp;
113390f9b8dSAndrew Rybchenko };
114390f9b8dSAndrew Rybchenko
115390f9b8dSAndrew Rybchenko static inline struct sfc_ef10_essb_rxq *
sfc_ef10_essb_rxq_by_dp_rxq(struct sfc_dp_rxq * dp_rxq)116390f9b8dSAndrew Rybchenko sfc_ef10_essb_rxq_by_dp_rxq(struct sfc_dp_rxq *dp_rxq)
117390f9b8dSAndrew Rybchenko {
118390f9b8dSAndrew Rybchenko return container_of(dp_rxq, struct sfc_ef10_essb_rxq, dp);
119390f9b8dSAndrew Rybchenko }
120390f9b8dSAndrew Rybchenko
121390f9b8dSAndrew Rybchenko static struct rte_mbuf *
sfc_ef10_essb_next_mbuf(const struct sfc_ef10_essb_rxq * rxq,struct rte_mbuf * mbuf)122390f9b8dSAndrew Rybchenko sfc_ef10_essb_next_mbuf(const struct sfc_ef10_essb_rxq *rxq,
123390f9b8dSAndrew Rybchenko struct rte_mbuf *mbuf)
124390f9b8dSAndrew Rybchenko {
125f3a5fa85SAndrew Rybchenko struct rte_mbuf *m;
126f3a5fa85SAndrew Rybchenko
127f3a5fa85SAndrew Rybchenko m = (struct rte_mbuf *)((uintptr_t)mbuf + rxq->buf_stride);
1283a35c1c0SMorten Brørup __rte_mbuf_raw_sanity_check(m);
129f3a5fa85SAndrew Rybchenko return m;
130390f9b8dSAndrew Rybchenko }
131390f9b8dSAndrew Rybchenko
132390f9b8dSAndrew Rybchenko static struct rte_mbuf *
sfc_ef10_essb_mbuf_by_index(const struct sfc_ef10_essb_rxq * rxq,struct rte_mbuf * mbuf,unsigned int idx)133390f9b8dSAndrew Rybchenko sfc_ef10_essb_mbuf_by_index(const struct sfc_ef10_essb_rxq *rxq,
134390f9b8dSAndrew Rybchenko struct rte_mbuf *mbuf, unsigned int idx)
135390f9b8dSAndrew Rybchenko {
136f3a5fa85SAndrew Rybchenko struct rte_mbuf *m;
137f3a5fa85SAndrew Rybchenko
138f3a5fa85SAndrew Rybchenko m = (struct rte_mbuf *)((uintptr_t)mbuf + idx * rxq->buf_stride);
1393a35c1c0SMorten Brørup __rte_mbuf_raw_sanity_check(m);
140f3a5fa85SAndrew Rybchenko return m;
141390f9b8dSAndrew Rybchenko }
142390f9b8dSAndrew Rybchenko
143390f9b8dSAndrew Rybchenko static struct rte_mbuf *
sfc_ef10_essb_maybe_next_completed(struct sfc_ef10_essb_rxq * rxq)144390f9b8dSAndrew Rybchenko sfc_ef10_essb_maybe_next_completed(struct sfc_ef10_essb_rxq *rxq)
145390f9b8dSAndrew Rybchenko {
146390f9b8dSAndrew Rybchenko const struct sfc_ef10_essb_rx_sw_desc *rxd;
147390f9b8dSAndrew Rybchenko
148390f9b8dSAndrew Rybchenko if (rxq->left_in_completed != 0) {
149390f9b8dSAndrew Rybchenko rxd = &rxq->sw_ring[rxq->completed & rxq->rxq_ptr_mask];
150390f9b8dSAndrew Rybchenko return sfc_ef10_essb_mbuf_by_index(rxq, rxd->first_mbuf,
151390f9b8dSAndrew Rybchenko rxq->block_size - rxq->left_in_completed);
152390f9b8dSAndrew Rybchenko } else {
153390f9b8dSAndrew Rybchenko rxq->completed++;
154390f9b8dSAndrew Rybchenko rxd = &rxq->sw_ring[rxq->completed & rxq->rxq_ptr_mask];
155390f9b8dSAndrew Rybchenko rxq->left_in_completed = rxq->block_size;
156390f9b8dSAndrew Rybchenko return rxd->first_mbuf;
157390f9b8dSAndrew Rybchenko }
158390f9b8dSAndrew Rybchenko }
159390f9b8dSAndrew Rybchenko
160390f9b8dSAndrew Rybchenko static void
sfc_ef10_essb_rx_qrefill(struct sfc_ef10_essb_rxq * rxq)161390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_qrefill(struct sfc_ef10_essb_rxq *rxq)
162390f9b8dSAndrew Rybchenko {
163390f9b8dSAndrew Rybchenko const unsigned int rxq_ptr_mask = rxq->rxq_ptr_mask;
164390f9b8dSAndrew Rybchenko unsigned int free_space;
165390f9b8dSAndrew Rybchenko unsigned int bulks;
166390f9b8dSAndrew Rybchenko void *mbuf_blocks[SFC_EF10_RX_WPTR_ALIGN];
167390f9b8dSAndrew Rybchenko unsigned int added = rxq->added;
168390f9b8dSAndrew Rybchenko
169390f9b8dSAndrew Rybchenko free_space = rxq->max_fill_level - (added - rxq->completed);
170390f9b8dSAndrew Rybchenko
171390f9b8dSAndrew Rybchenko if (free_space < rxq->refill_threshold)
172390f9b8dSAndrew Rybchenko return;
173390f9b8dSAndrew Rybchenko
174390f9b8dSAndrew Rybchenko bulks = free_space / RTE_DIM(mbuf_blocks);
175390f9b8dSAndrew Rybchenko /* refill_threshold guarantees that bulks is positive */
176390f9b8dSAndrew Rybchenko SFC_ASSERT(bulks > 0);
177390f9b8dSAndrew Rybchenko
178390f9b8dSAndrew Rybchenko do {
179390f9b8dSAndrew Rybchenko unsigned int id;
180390f9b8dSAndrew Rybchenko unsigned int i;
181390f9b8dSAndrew Rybchenko
182390f9b8dSAndrew Rybchenko if (unlikely(rte_mempool_get_contig_blocks(rxq->refill_mb_pool,
183390f9b8dSAndrew Rybchenko mbuf_blocks, RTE_DIM(mbuf_blocks)) < 0)) {
184390f9b8dSAndrew Rybchenko struct rte_eth_dev_data *dev_data =
185390f9b8dSAndrew Rybchenko rte_eth_devices[rxq->port_id].data;
186390f9b8dSAndrew Rybchenko
187390f9b8dSAndrew Rybchenko /*
188390f9b8dSAndrew Rybchenko * It is hardly a safe way to increment counter
189390f9b8dSAndrew Rybchenko * from different contexts, but all PMDs do it.
190390f9b8dSAndrew Rybchenko */
191390f9b8dSAndrew Rybchenko dev_data->rx_mbuf_alloc_failed += RTE_DIM(mbuf_blocks);
192390f9b8dSAndrew Rybchenko /* Return if we have posted nothing yet */
193390f9b8dSAndrew Rybchenko if (added == rxq->added)
194390f9b8dSAndrew Rybchenko return;
195390f9b8dSAndrew Rybchenko /* Push posted */
196390f9b8dSAndrew Rybchenko break;
197390f9b8dSAndrew Rybchenko }
198390f9b8dSAndrew Rybchenko
199390f9b8dSAndrew Rybchenko for (i = 0, id = added & rxq_ptr_mask;
200390f9b8dSAndrew Rybchenko i < RTE_DIM(mbuf_blocks);
201390f9b8dSAndrew Rybchenko ++i, ++id) {
202390f9b8dSAndrew Rybchenko struct rte_mbuf *m = mbuf_blocks[i];
203390f9b8dSAndrew Rybchenko struct sfc_ef10_essb_rx_sw_desc *rxd;
204390f9b8dSAndrew Rybchenko
205390f9b8dSAndrew Rybchenko SFC_ASSERT((id & ~rxq_ptr_mask) == 0);
206390f9b8dSAndrew Rybchenko rxd = &rxq->sw_ring[id];
207390f9b8dSAndrew Rybchenko rxd->first_mbuf = m;
208390f9b8dSAndrew Rybchenko
209390f9b8dSAndrew Rybchenko /* RX_KER_BYTE_CNT is ignored by firmware */
210390f9b8dSAndrew Rybchenko EFX_POPULATE_QWORD_2(rxq->rxq_hw_ring[id],
211390f9b8dSAndrew Rybchenko ESF_DZ_RX_KER_BYTE_CNT,
212390f9b8dSAndrew Rybchenko SFC_EF10_ESSB_RX_FAKE_BUF_SIZE,
213390f9b8dSAndrew Rybchenko ESF_DZ_RX_KER_BUF_ADDR,
214390f9b8dSAndrew Rybchenko rte_mbuf_data_iova_default(m));
215390f9b8dSAndrew Rybchenko }
216390f9b8dSAndrew Rybchenko
217390f9b8dSAndrew Rybchenko added += RTE_DIM(mbuf_blocks);
218390f9b8dSAndrew Rybchenko
219390f9b8dSAndrew Rybchenko } while (--bulks > 0);
220390f9b8dSAndrew Rybchenko
221390f9b8dSAndrew Rybchenko SFC_ASSERT(rxq->added != added);
222390f9b8dSAndrew Rybchenko rxq->added = added;
223fdd7719eSIvan Ilchenko sfc_ef10_rx_qpush(rxq->doorbell, added, rxq_ptr_mask,
22450448dd3SAndrew Rybchenko &rxq->dp.dpq.dbells);
225390f9b8dSAndrew Rybchenko }
226390f9b8dSAndrew Rybchenko
227390f9b8dSAndrew Rybchenko static bool
sfc_ef10_essb_rx_event_get(struct sfc_ef10_essb_rxq * rxq,efx_qword_t * rx_ev)228390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_event_get(struct sfc_ef10_essb_rxq *rxq, efx_qword_t *rx_ev)
229390f9b8dSAndrew Rybchenko {
230390f9b8dSAndrew Rybchenko *rx_ev = rxq->evq_hw_ring[rxq->evq_read_ptr & rxq->evq_ptr_mask];
231390f9b8dSAndrew Rybchenko
232390f9b8dSAndrew Rybchenko if (!sfc_ef10_ev_present(*rx_ev))
233390f9b8dSAndrew Rybchenko return false;
234390f9b8dSAndrew Rybchenko
235390f9b8dSAndrew Rybchenko if (unlikely(EFX_QWORD_FIELD(*rx_ev, FSF_AZ_EV_CODE) !=
236390f9b8dSAndrew Rybchenko FSE_AZ_EV_CODE_RX_EV)) {
237390f9b8dSAndrew Rybchenko /*
238390f9b8dSAndrew Rybchenko * Do not move read_ptr to keep the event for exception
239390f9b8dSAndrew Rybchenko * handling
240390f9b8dSAndrew Rybchenko */
241390f9b8dSAndrew Rybchenko rxq->flags |= SFC_EF10_ESSB_RXQ_EXCEPTION;
242390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_err(&rxq->dp.dpq,
243390f9b8dSAndrew Rybchenko "RxQ exception at EvQ read ptr %#x",
244390f9b8dSAndrew Rybchenko rxq->evq_read_ptr);
245390f9b8dSAndrew Rybchenko return false;
246390f9b8dSAndrew Rybchenko }
247390f9b8dSAndrew Rybchenko
248390f9b8dSAndrew Rybchenko rxq->evq_read_ptr++;
249390f9b8dSAndrew Rybchenko return true;
250390f9b8dSAndrew Rybchenko }
251390f9b8dSAndrew Rybchenko
252390f9b8dSAndrew Rybchenko static void
sfc_ef10_essb_rx_process_ev(struct sfc_ef10_essb_rxq * rxq,efx_qword_t rx_ev)253390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_process_ev(struct sfc_ef10_essb_rxq *rxq, efx_qword_t rx_ev)
254390f9b8dSAndrew Rybchenko {
255390f9b8dSAndrew Rybchenko unsigned int ready;
256390f9b8dSAndrew Rybchenko
257390f9b8dSAndrew Rybchenko ready = (EFX_QWORD_FIELD(rx_ev, ESF_DZ_RX_DSC_PTR_LBITS) -
258390f9b8dSAndrew Rybchenko rxq->bufs_ptr) &
259390f9b8dSAndrew Rybchenko EFX_MASK32(ESF_DZ_RX_DSC_PTR_LBITS);
260390f9b8dSAndrew Rybchenko
261390f9b8dSAndrew Rybchenko rxq->bufs_ptr += ready;
262390f9b8dSAndrew Rybchenko rxq->bufs_pending += ready;
263390f9b8dSAndrew Rybchenko
264390f9b8dSAndrew Rybchenko SFC_ASSERT(ready > 0);
265390f9b8dSAndrew Rybchenko do {
266390f9b8dSAndrew Rybchenko const struct sfc_ef10_essb_rx_sw_desc *rxd;
267390f9b8dSAndrew Rybchenko struct rte_mbuf *m;
268390f9b8dSAndrew Rybchenko unsigned int todo_bufs;
269390f9b8dSAndrew Rybchenko struct rte_mbuf *m0;
270390f9b8dSAndrew Rybchenko
271390f9b8dSAndrew Rybchenko rxd = &rxq->sw_ring[rxq->pending_id];
272390f9b8dSAndrew Rybchenko m = sfc_ef10_essb_mbuf_by_index(rxq, rxd->first_mbuf,
273390f9b8dSAndrew Rybchenko rxq->block_size - rxq->left_in_pending);
274390f9b8dSAndrew Rybchenko
275390f9b8dSAndrew Rybchenko if (ready < rxq->left_in_pending) {
276390f9b8dSAndrew Rybchenko todo_bufs = ready;
277390f9b8dSAndrew Rybchenko ready = 0;
278390f9b8dSAndrew Rybchenko rxq->left_in_pending -= todo_bufs;
279390f9b8dSAndrew Rybchenko } else {
280390f9b8dSAndrew Rybchenko todo_bufs = rxq->left_in_pending;
281390f9b8dSAndrew Rybchenko ready -= todo_bufs;
282390f9b8dSAndrew Rybchenko rxq->left_in_pending = rxq->block_size;
283390f9b8dSAndrew Rybchenko if (rxq->pending_id != rxq->rxq_ptr_mask)
284390f9b8dSAndrew Rybchenko rxq->pending_id++;
285390f9b8dSAndrew Rybchenko else
286390f9b8dSAndrew Rybchenko rxq->pending_id = 0;
287390f9b8dSAndrew Rybchenko }
288390f9b8dSAndrew Rybchenko
289390f9b8dSAndrew Rybchenko SFC_ASSERT(todo_bufs > 0);
290390f9b8dSAndrew Rybchenko --todo_bufs;
291390f9b8dSAndrew Rybchenko
292390f9b8dSAndrew Rybchenko sfc_ef10_rx_ev_to_offloads(rx_ev, m, ~0ull);
293390f9b8dSAndrew Rybchenko
294390f9b8dSAndrew Rybchenko /* Prefetch pseudo-header */
295390f9b8dSAndrew Rybchenko rte_prefetch0((uint8_t *)m->buf_addr + RTE_PKTMBUF_HEADROOM);
296390f9b8dSAndrew Rybchenko
297390f9b8dSAndrew Rybchenko m0 = m;
298390f9b8dSAndrew Rybchenko while (todo_bufs-- > 0) {
299390f9b8dSAndrew Rybchenko m = sfc_ef10_essb_next_mbuf(rxq, m);
300390f9b8dSAndrew Rybchenko m->ol_flags = m0->ol_flags;
301390f9b8dSAndrew Rybchenko m->packet_type = m0->packet_type;
302390f9b8dSAndrew Rybchenko /* Prefetch pseudo-header */
303390f9b8dSAndrew Rybchenko rte_prefetch0((uint8_t *)m->buf_addr +
304390f9b8dSAndrew Rybchenko RTE_PKTMBUF_HEADROOM);
305390f9b8dSAndrew Rybchenko }
306390f9b8dSAndrew Rybchenko } while (ready > 0);
307390f9b8dSAndrew Rybchenko }
308390f9b8dSAndrew Rybchenko
309c6845644SAndrew Rybchenko /*
310c6845644SAndrew Rybchenko * Below function relies on the following length and layout of the
311c6845644SAndrew Rybchenko * Rx prefix.
312c6845644SAndrew Rybchenko */
313c6845644SAndrew Rybchenko static const efx_rx_prefix_layout_t sfc_ef10_essb_rx_prefix_layout = {
314c6845644SAndrew Rybchenko .erpl_length = ES_EZ_ESSB_RX_PREFIX_LEN,
315c6845644SAndrew Rybchenko .erpl_fields = {
316c6845644SAndrew Rybchenko #define SFC_EF10_ESSB_RX_PREFIX_FIELD(_efx, _ef10) \
317c6845644SAndrew Rybchenko EFX_RX_PREFIX_FIELD(_efx, ES_EZ_ESSB_RX_PREFIX_ ## _ef10, B_FALSE)
318c6845644SAndrew Rybchenko
319c6845644SAndrew Rybchenko SFC_EF10_ESSB_RX_PREFIX_FIELD(LENGTH, DATA_LEN),
320c6845644SAndrew Rybchenko SFC_EF10_ESSB_RX_PREFIX_FIELD(USER_MARK, MARK),
321c6845644SAndrew Rybchenko SFC_EF10_ESSB_RX_PREFIX_FIELD(RSS_HASH_VALID, HASH_VALID),
322c6845644SAndrew Rybchenko SFC_EF10_ESSB_RX_PREFIX_FIELD(USER_MARK_VALID, MARK_VALID),
323c6845644SAndrew Rybchenko SFC_EF10_ESSB_RX_PREFIX_FIELD(USER_FLAG, MATCH_FLAG),
324c6845644SAndrew Rybchenko SFC_EF10_ESSB_RX_PREFIX_FIELD(RSS_HASH, HASH),
325c6845644SAndrew Rybchenko
326c6845644SAndrew Rybchenko #undef SFC_EF10_ESSB_RX_PREFIX_FIELD
327c6845644SAndrew Rybchenko }
328c6845644SAndrew Rybchenko };
329c6845644SAndrew Rybchenko
330390f9b8dSAndrew Rybchenko static unsigned int
sfc_ef10_essb_rx_get_pending(struct sfc_ef10_essb_rxq * rxq,struct rte_mbuf ** rx_pkts,uint16_t nb_pkts)331390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_get_pending(struct sfc_ef10_essb_rxq *rxq,
332390f9b8dSAndrew Rybchenko struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
333390f9b8dSAndrew Rybchenko {
334390f9b8dSAndrew Rybchenko unsigned int n_rx_pkts = 0;
335390f9b8dSAndrew Rybchenko unsigned int todo_bufs;
336390f9b8dSAndrew Rybchenko struct rte_mbuf *m;
337390f9b8dSAndrew Rybchenko
338390f9b8dSAndrew Rybchenko while ((todo_bufs = RTE_MIN(nb_pkts - n_rx_pkts,
339390f9b8dSAndrew Rybchenko rxq->bufs_pending)) > 0) {
340390f9b8dSAndrew Rybchenko m = sfc_ef10_essb_maybe_next_completed(rxq);
341390f9b8dSAndrew Rybchenko
342390f9b8dSAndrew Rybchenko todo_bufs = RTE_MIN(todo_bufs, rxq->left_in_completed);
343390f9b8dSAndrew Rybchenko
344390f9b8dSAndrew Rybchenko rxq->bufs_pending -= todo_bufs;
345390f9b8dSAndrew Rybchenko rxq->left_in_completed -= todo_bufs;
346390f9b8dSAndrew Rybchenko
347390f9b8dSAndrew Rybchenko SFC_ASSERT(todo_bufs > 0);
348390f9b8dSAndrew Rybchenko todo_bufs--;
349390f9b8dSAndrew Rybchenko
350390f9b8dSAndrew Rybchenko do {
351390f9b8dSAndrew Rybchenko const efx_qword_t *qwordp;
352390f9b8dSAndrew Rybchenko uint16_t pkt_len;
353390f9b8dSAndrew Rybchenko
354aeeb5571SAndrew Rybchenko /* Buffers to be discarded have 0 in packet type */
355aeeb5571SAndrew Rybchenko if (unlikely(m->packet_type == 0)) {
35666e10b8dSAndrew Rybchenko rte_mbuf_raw_free(m);
357aeeb5571SAndrew Rybchenko goto next_buf;
358aeeb5571SAndrew Rybchenko }
359aeeb5571SAndrew Rybchenko
360390f9b8dSAndrew Rybchenko rx_pkts[n_rx_pkts++] = m;
361390f9b8dSAndrew Rybchenko
362390f9b8dSAndrew Rybchenko /* Parse pseudo-header */
363390f9b8dSAndrew Rybchenko qwordp = (const efx_qword_t *)
364390f9b8dSAndrew Rybchenko ((uint8_t *)m->buf_addr + RTE_PKTMBUF_HEADROOM);
365390f9b8dSAndrew Rybchenko pkt_len =
366390f9b8dSAndrew Rybchenko EFX_QWORD_FIELD(*qwordp,
367390f9b8dSAndrew Rybchenko ES_EZ_ESSB_RX_PREFIX_DATA_LEN);
368390f9b8dSAndrew Rybchenko
369390f9b8dSAndrew Rybchenko m->data_off = RTE_PKTMBUF_HEADROOM +
370390f9b8dSAndrew Rybchenko ES_EZ_ESSB_RX_PREFIX_LEN;
371390f9b8dSAndrew Rybchenko m->port = rxq->port_id;
372390f9b8dSAndrew Rybchenko
373390f9b8dSAndrew Rybchenko rte_pktmbuf_pkt_len(m) = pkt_len;
374390f9b8dSAndrew Rybchenko rte_pktmbuf_data_len(m) = pkt_len;
375390f9b8dSAndrew Rybchenko
376390f9b8dSAndrew Rybchenko m->ol_flags |=
377daa02b5cSOlivier Matz (RTE_MBUF_F_RX_RSS_HASH *
378390f9b8dSAndrew Rybchenko !!EFX_TEST_QWORD_BIT(*qwordp,
37926c4f608SAndrew Rybchenko ES_EZ_ESSB_RX_PREFIX_HASH_VALID_LBN)) |
380daa02b5cSOlivier Matz (RTE_MBUF_F_RX_FDIR_ID *
38126c4f608SAndrew Rybchenko !!EFX_TEST_QWORD_BIT(*qwordp,
38226c4f608SAndrew Rybchenko ES_EZ_ESSB_RX_PREFIX_MARK_VALID_LBN)) |
383daa02b5cSOlivier Matz (RTE_MBUF_F_RX_FDIR *
38426c4f608SAndrew Rybchenko !!EFX_TEST_QWORD_BIT(*qwordp,
38526c4f608SAndrew Rybchenko ES_EZ_ESSB_RX_PREFIX_MATCH_FLAG_LBN));
386390f9b8dSAndrew Rybchenko
387390f9b8dSAndrew Rybchenko /* EFX_QWORD_FIELD converts little-endian to CPU */
388390f9b8dSAndrew Rybchenko m->hash.rss =
389390f9b8dSAndrew Rybchenko EFX_QWORD_FIELD(*qwordp,
390390f9b8dSAndrew Rybchenko ES_EZ_ESSB_RX_PREFIX_HASH);
39126c4f608SAndrew Rybchenko m->hash.fdir.hi =
39226c4f608SAndrew Rybchenko EFX_QWORD_FIELD(*qwordp,
39326c4f608SAndrew Rybchenko ES_EZ_ESSB_RX_PREFIX_MARK);
394390f9b8dSAndrew Rybchenko
395aeeb5571SAndrew Rybchenko next_buf:
396390f9b8dSAndrew Rybchenko m = sfc_ef10_essb_next_mbuf(rxq, m);
397390f9b8dSAndrew Rybchenko } while (todo_bufs-- > 0);
398390f9b8dSAndrew Rybchenko }
399390f9b8dSAndrew Rybchenko
400390f9b8dSAndrew Rybchenko return n_rx_pkts;
401390f9b8dSAndrew Rybchenko }
402390f9b8dSAndrew Rybchenko
403390f9b8dSAndrew Rybchenko
404390f9b8dSAndrew Rybchenko static uint16_t
sfc_ef10_essb_recv_pkts(void * rx_queue,struct rte_mbuf ** rx_pkts,uint16_t nb_pkts)405390f9b8dSAndrew Rybchenko sfc_ef10_essb_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
406390f9b8dSAndrew Rybchenko uint16_t nb_pkts)
407390f9b8dSAndrew Rybchenko {
408390f9b8dSAndrew Rybchenko struct sfc_ef10_essb_rxq *rxq = sfc_ef10_essb_rxq_by_dp_rxq(rx_queue);
409390f9b8dSAndrew Rybchenko const unsigned int evq_old_read_ptr = rxq->evq_read_ptr;
410390f9b8dSAndrew Rybchenko uint16_t n_rx_pkts;
411390f9b8dSAndrew Rybchenko efx_qword_t rx_ev;
412390f9b8dSAndrew Rybchenko
413390f9b8dSAndrew Rybchenko if (unlikely(rxq->flags & (SFC_EF10_ESSB_RXQ_NOT_RUNNING |
414390f9b8dSAndrew Rybchenko SFC_EF10_ESSB_RXQ_EXCEPTION)))
415390f9b8dSAndrew Rybchenko return 0;
416390f9b8dSAndrew Rybchenko
417390f9b8dSAndrew Rybchenko n_rx_pkts = sfc_ef10_essb_rx_get_pending(rxq, rx_pkts, nb_pkts);
418390f9b8dSAndrew Rybchenko
419390f9b8dSAndrew Rybchenko while (n_rx_pkts != nb_pkts &&
420390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_event_get(rxq, &rx_ev)) {
421390f9b8dSAndrew Rybchenko /*
422390f9b8dSAndrew Rybchenko * DROP_EVENT is an internal to the NIC, software should
423390f9b8dSAndrew Rybchenko * never see it and, therefore, may ignore it.
424390f9b8dSAndrew Rybchenko */
425390f9b8dSAndrew Rybchenko
426390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_process_ev(rxq, rx_ev);
427390f9b8dSAndrew Rybchenko n_rx_pkts += sfc_ef10_essb_rx_get_pending(rxq,
428390f9b8dSAndrew Rybchenko rx_pkts + n_rx_pkts,
429390f9b8dSAndrew Rybchenko nb_pkts - n_rx_pkts);
430390f9b8dSAndrew Rybchenko }
431390f9b8dSAndrew Rybchenko
432390f9b8dSAndrew Rybchenko sfc_ef10_ev_qclear(rxq->evq_hw_ring, rxq->evq_ptr_mask,
433390f9b8dSAndrew Rybchenko evq_old_read_ptr, rxq->evq_read_ptr);
434390f9b8dSAndrew Rybchenko
435390f9b8dSAndrew Rybchenko /* It is not a problem if we refill in the case of exception */
436390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_qrefill(rxq);
437390f9b8dSAndrew Rybchenko
438390f9b8dSAndrew Rybchenko return n_rx_pkts;
439390f9b8dSAndrew Rybchenko }
440390f9b8dSAndrew Rybchenko
441390f9b8dSAndrew Rybchenko static sfc_dp_rx_qdesc_npending_t sfc_ef10_essb_rx_qdesc_npending;
442390f9b8dSAndrew Rybchenko static unsigned int
sfc_ef10_essb_rx_qdesc_npending(struct sfc_dp_rxq * dp_rxq)4436e98e4d2SAndrew Rybchenko sfc_ef10_essb_rx_qdesc_npending(struct sfc_dp_rxq *dp_rxq)
444390f9b8dSAndrew Rybchenko {
4456e98e4d2SAndrew Rybchenko struct sfc_ef10_essb_rxq *rxq = sfc_ef10_essb_rxq_by_dp_rxq(dp_rxq);
4466e98e4d2SAndrew Rybchenko const unsigned int evq_old_read_ptr = rxq->evq_read_ptr;
4476e98e4d2SAndrew Rybchenko efx_qword_t rx_ev;
4486e98e4d2SAndrew Rybchenko
4496e98e4d2SAndrew Rybchenko if (unlikely(rxq->flags & (SFC_EF10_ESSB_RXQ_NOT_RUNNING |
4506e98e4d2SAndrew Rybchenko SFC_EF10_ESSB_RXQ_EXCEPTION)))
4516e98e4d2SAndrew Rybchenko return rxq->bufs_pending;
4526e98e4d2SAndrew Rybchenko
4536e98e4d2SAndrew Rybchenko while (sfc_ef10_essb_rx_event_get(rxq, &rx_ev)) {
454390f9b8dSAndrew Rybchenko /*
4556e98e4d2SAndrew Rybchenko * DROP_EVENT is an internal to the NIC, software should
4566e98e4d2SAndrew Rybchenko * never see it and, therefore, may ignore it.
457390f9b8dSAndrew Rybchenko */
4586e98e4d2SAndrew Rybchenko sfc_ef10_essb_rx_process_ev(rxq, rx_ev);
4596e98e4d2SAndrew Rybchenko }
4606e98e4d2SAndrew Rybchenko
4616e98e4d2SAndrew Rybchenko sfc_ef10_ev_qclear(rxq->evq_hw_ring, rxq->evq_ptr_mask,
4626e98e4d2SAndrew Rybchenko evq_old_read_ptr, rxq->evq_read_ptr);
4636e98e4d2SAndrew Rybchenko
4646e98e4d2SAndrew Rybchenko return rxq->bufs_pending;
465390f9b8dSAndrew Rybchenko }
466390f9b8dSAndrew Rybchenko
467a654e29bSAndrew Rybchenko static sfc_dp_rx_qdesc_status_t sfc_ef10_essb_rx_qdesc_status;
468a654e29bSAndrew Rybchenko static int
sfc_ef10_essb_rx_qdesc_status(struct sfc_dp_rxq * dp_rxq,uint16_t offset)469886beef8SAndrew Rybchenko sfc_ef10_essb_rx_qdesc_status(struct sfc_dp_rxq *dp_rxq, uint16_t offset)
470a654e29bSAndrew Rybchenko {
471886beef8SAndrew Rybchenko struct sfc_ef10_essb_rxq *rxq = sfc_ef10_essb_rxq_by_dp_rxq(dp_rxq);
472886beef8SAndrew Rybchenko unsigned int pending = sfc_ef10_essb_rx_qdesc_npending(dp_rxq);
473886beef8SAndrew Rybchenko
474886beef8SAndrew Rybchenko if (offset < pending)
475886beef8SAndrew Rybchenko return RTE_ETH_RX_DESC_DONE;
476886beef8SAndrew Rybchenko
477886beef8SAndrew Rybchenko if (offset < (rxq->added - rxq->completed) * rxq->block_size +
478886beef8SAndrew Rybchenko rxq->left_in_completed - rxq->block_size)
479886beef8SAndrew Rybchenko return RTE_ETH_RX_DESC_AVAIL;
480886beef8SAndrew Rybchenko
481886beef8SAndrew Rybchenko return RTE_ETH_RX_DESC_UNAVAIL;
482a654e29bSAndrew Rybchenko }
483a654e29bSAndrew Rybchenko
484390f9b8dSAndrew Rybchenko static sfc_dp_rx_get_dev_info_t sfc_ef10_essb_rx_get_dev_info;
485390f9b8dSAndrew Rybchenko static void
sfc_ef10_essb_rx_get_dev_info(struct rte_eth_dev_info * dev_info)486390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_get_dev_info(struct rte_eth_dev_info *dev_info)
487390f9b8dSAndrew Rybchenko {
488390f9b8dSAndrew Rybchenko /*
489390f9b8dSAndrew Rybchenko * Number of descriptors just defines maximum number of pushed
490390f9b8dSAndrew Rybchenko * descriptors (fill level).
491390f9b8dSAndrew Rybchenko */
492e9ff01b3SAndrew Rybchenko dev_info->rx_desc_lim.nb_min = SFC_EF10_ESSB_RX_DESCS_MIN;
493e9ff01b3SAndrew Rybchenko dev_info->rx_desc_lim.nb_align = SFC_EF10_ESSB_RX_DESCS_ALIGN;
494390f9b8dSAndrew Rybchenko }
495390f9b8dSAndrew Rybchenko
4962a97a82bSAndrew Rybchenko static sfc_dp_rx_pool_ops_supported_t sfc_ef10_essb_rx_pool_ops_supported;
4972a97a82bSAndrew Rybchenko static int
sfc_ef10_essb_rx_pool_ops_supported(const char * pool)4982a97a82bSAndrew Rybchenko sfc_ef10_essb_rx_pool_ops_supported(const char *pool)
4992a97a82bSAndrew Rybchenko {
5002a97a82bSAndrew Rybchenko SFC_ASSERT(pool != NULL);
5012a97a82bSAndrew Rybchenko
5022a97a82bSAndrew Rybchenko if (strcmp(pool, "bucket") == 0)
5032a97a82bSAndrew Rybchenko return 0;
5042a97a82bSAndrew Rybchenko
5052a97a82bSAndrew Rybchenko return -ENOTSUP;
5062a97a82bSAndrew Rybchenko }
5072a97a82bSAndrew Rybchenko
508390f9b8dSAndrew Rybchenko static sfc_dp_rx_qsize_up_rings_t sfc_ef10_essb_rx_qsize_up_rings;
509390f9b8dSAndrew Rybchenko static int
sfc_ef10_essb_rx_qsize_up_rings(uint16_t nb_rx_desc,struct sfc_dp_rx_hw_limits * limits,struct rte_mempool * mb_pool,unsigned int * rxq_entries,unsigned int * evq_entries,unsigned int * rxq_max_fill_level)510390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_qsize_up_rings(uint16_t nb_rx_desc,
511048a0d1aSIgor Romanov struct sfc_dp_rx_hw_limits *limits,
512390f9b8dSAndrew Rybchenko struct rte_mempool *mb_pool,
513390f9b8dSAndrew Rybchenko unsigned int *rxq_entries,
514390f9b8dSAndrew Rybchenko unsigned int *evq_entries,
515390f9b8dSAndrew Rybchenko unsigned int *rxq_max_fill_level)
516390f9b8dSAndrew Rybchenko {
517390f9b8dSAndrew Rybchenko int rc;
518390f9b8dSAndrew Rybchenko struct rte_mempool_info mp_info;
519390f9b8dSAndrew Rybchenko unsigned int nb_hw_rx_desc;
520390f9b8dSAndrew Rybchenko unsigned int max_events;
521390f9b8dSAndrew Rybchenko
522390f9b8dSAndrew Rybchenko rc = rte_mempool_ops_get_info(mb_pool, &mp_info);
523390f9b8dSAndrew Rybchenko if (rc != 0)
524390f9b8dSAndrew Rybchenko return -rc;
525390f9b8dSAndrew Rybchenko if (mp_info.contig_block_size == 0)
526390f9b8dSAndrew Rybchenko return EINVAL;
527390f9b8dSAndrew Rybchenko
528390f9b8dSAndrew Rybchenko /*
529390f9b8dSAndrew Rybchenko * Calculate required number of hardware Rx descriptors each
530390f9b8dSAndrew Rybchenko * carrying contig block size Rx buffers.
531390f9b8dSAndrew Rybchenko * It cannot be less than Rx write pointer alignment plus 1
532390f9b8dSAndrew Rybchenko * in order to avoid cases when the ring is guaranteed to be
533390f9b8dSAndrew Rybchenko * empty.
534390f9b8dSAndrew Rybchenko */
535390f9b8dSAndrew Rybchenko nb_hw_rx_desc = RTE_MAX(SFC_DIV_ROUND_UP(nb_rx_desc,
536390f9b8dSAndrew Rybchenko mp_info.contig_block_size),
537390f9b8dSAndrew Rybchenko SFC_EF10_RX_WPTR_ALIGN + 1);
538048a0d1aSIgor Romanov if (nb_hw_rx_desc <= limits->rxq_min_entries) {
539048a0d1aSIgor Romanov *rxq_entries = limits->rxq_min_entries;
540390f9b8dSAndrew Rybchenko } else {
541390f9b8dSAndrew Rybchenko *rxq_entries = rte_align32pow2(nb_hw_rx_desc);
542048a0d1aSIgor Romanov if (*rxq_entries > limits->rxq_max_entries)
543390f9b8dSAndrew Rybchenko return EINVAL;
544390f9b8dSAndrew Rybchenko }
545390f9b8dSAndrew Rybchenko
546390f9b8dSAndrew Rybchenko max_events = RTE_ALIGN_FLOOR(nb_hw_rx_desc, SFC_EF10_RX_WPTR_ALIGN) *
547390f9b8dSAndrew Rybchenko mp_info.contig_block_size +
548390f9b8dSAndrew Rybchenko (SFC_EF10_EV_PER_CACHE_LINE - 1) /* max unused EvQ entries */ +
549390f9b8dSAndrew Rybchenko 1 /* Rx error */ + 1 /* flush */ + 1 /* head-tail space */;
550390f9b8dSAndrew Rybchenko
551390f9b8dSAndrew Rybchenko *evq_entries = rte_align32pow2(max_events);
552d5371f3dSIgor Romanov *evq_entries = RTE_MAX(*evq_entries, limits->evq_min_entries);
553d5371f3dSIgor Romanov *evq_entries = RTE_MIN(*evq_entries, limits->evq_max_entries);
554390f9b8dSAndrew Rybchenko
555390f9b8dSAndrew Rybchenko /*
556390f9b8dSAndrew Rybchenko * May be even maximum event queue size is insufficient to handle
557390f9b8dSAndrew Rybchenko * so many Rx descriptors. If so, we should limit Rx queue fill level.
558390f9b8dSAndrew Rybchenko */
559390f9b8dSAndrew Rybchenko *rxq_max_fill_level = RTE_MIN(nb_rx_desc,
560390f9b8dSAndrew Rybchenko SFC_EF10_ESSB_RXQ_LIMIT(*evq_entries));
561390f9b8dSAndrew Rybchenko return 0;
562390f9b8dSAndrew Rybchenko }
563390f9b8dSAndrew Rybchenko
564390f9b8dSAndrew Rybchenko static sfc_dp_rx_qcreate_t sfc_ef10_essb_rx_qcreate;
565390f9b8dSAndrew Rybchenko static int
sfc_ef10_essb_rx_qcreate(uint16_t port_id,uint16_t queue_id,const struct rte_pci_addr * pci_addr,int socket_id,const struct sfc_dp_rx_qcreate_info * info,struct sfc_dp_rxq ** dp_rxqp)566390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_qcreate(uint16_t port_id, uint16_t queue_id,
567390f9b8dSAndrew Rybchenko const struct rte_pci_addr *pci_addr, int socket_id,
568390f9b8dSAndrew Rybchenko const struct sfc_dp_rx_qcreate_info *info,
569390f9b8dSAndrew Rybchenko struct sfc_dp_rxq **dp_rxqp)
570390f9b8dSAndrew Rybchenko {
571390f9b8dSAndrew Rybchenko struct rte_mempool * const mp = info->refill_mb_pool;
572390f9b8dSAndrew Rybchenko struct rte_mempool_info mp_info;
573390f9b8dSAndrew Rybchenko struct sfc_ef10_essb_rxq *rxq;
574390f9b8dSAndrew Rybchenko int rc;
575390f9b8dSAndrew Rybchenko
5763037e6cfSViacheslav Galaktionov rc = ENOTSUP;
5773037e6cfSViacheslav Galaktionov if (info->nic_dma_info->nb_regions > 0)
5783037e6cfSViacheslav Galaktionov goto fail_nic_dma;
5793037e6cfSViacheslav Galaktionov
580390f9b8dSAndrew Rybchenko rc = rte_mempool_ops_get_info(mp, &mp_info);
581390f9b8dSAndrew Rybchenko if (rc != 0) {
582390f9b8dSAndrew Rybchenko /* Positive errno is used in the driver */
583390f9b8dSAndrew Rybchenko rc = -rc;
584390f9b8dSAndrew Rybchenko goto fail_get_contig_block_size;
585390f9b8dSAndrew Rybchenko }
586390f9b8dSAndrew Rybchenko
587390f9b8dSAndrew Rybchenko /* Check if the mempool provides block dequeue */
588390f9b8dSAndrew Rybchenko rc = EINVAL;
589390f9b8dSAndrew Rybchenko if (mp_info.contig_block_size == 0)
590390f9b8dSAndrew Rybchenko goto fail_no_block_dequeue;
591390f9b8dSAndrew Rybchenko
592390f9b8dSAndrew Rybchenko rc = ENOMEM;
593390f9b8dSAndrew Rybchenko rxq = rte_zmalloc_socket("sfc-ef10-rxq", sizeof(*rxq),
594390f9b8dSAndrew Rybchenko RTE_CACHE_LINE_SIZE, socket_id);
595390f9b8dSAndrew Rybchenko if (rxq == NULL)
596390f9b8dSAndrew Rybchenko goto fail_rxq_alloc;
597390f9b8dSAndrew Rybchenko
598390f9b8dSAndrew Rybchenko sfc_dp_queue_init(&rxq->dp.dpq, port_id, queue_id, pci_addr);
599390f9b8dSAndrew Rybchenko
600390f9b8dSAndrew Rybchenko rc = ENOMEM;
601390f9b8dSAndrew Rybchenko rxq->sw_ring = rte_calloc_socket("sfc-ef10-rxq-sw_ring",
602390f9b8dSAndrew Rybchenko info->rxq_entries,
603390f9b8dSAndrew Rybchenko sizeof(*rxq->sw_ring),
604390f9b8dSAndrew Rybchenko RTE_CACHE_LINE_SIZE, socket_id);
605390f9b8dSAndrew Rybchenko if (rxq->sw_ring == NULL)
606390f9b8dSAndrew Rybchenko goto fail_desc_alloc;
607390f9b8dSAndrew Rybchenko
608390f9b8dSAndrew Rybchenko rxq->block_size = mp_info.contig_block_size;
609390f9b8dSAndrew Rybchenko rxq->buf_stride = mp->header_size + mp->elt_size + mp->trailer_size;
610390f9b8dSAndrew Rybchenko rxq->rxq_ptr_mask = info->rxq_entries - 1;
611390f9b8dSAndrew Rybchenko rxq->evq_ptr_mask = info->evq_entries - 1;
612390f9b8dSAndrew Rybchenko rxq->evq_hw_ring = info->evq_hw_ring;
613390f9b8dSAndrew Rybchenko rxq->port_id = port_id;
614390f9b8dSAndrew Rybchenko
615390f9b8dSAndrew Rybchenko rxq->max_fill_level = info->max_fill_level / mp_info.contig_block_size;
616390f9b8dSAndrew Rybchenko rxq->refill_threshold =
617390f9b8dSAndrew Rybchenko RTE_MAX(info->refill_threshold / mp_info.contig_block_size,
618390f9b8dSAndrew Rybchenko SFC_EF10_RX_WPTR_ALIGN);
619390f9b8dSAndrew Rybchenko rxq->refill_mb_pool = mp;
620390f9b8dSAndrew Rybchenko rxq->rxq_hw_ring = info->rxq_hw_ring;
621390f9b8dSAndrew Rybchenko
622390f9b8dSAndrew Rybchenko rxq->doorbell = (volatile uint8_t *)info->mem_bar +
623390f9b8dSAndrew Rybchenko ER_DZ_RX_DESC_UPD_REG_OFST +
624390f9b8dSAndrew Rybchenko (info->hw_index << info->vi_window_shift);
625390f9b8dSAndrew Rybchenko
626e7fbf6f5SAndrew Rybchenko sfc_ef10_essb_rx_info(&rxq->dp.dpq, "RxQ doorbell is %p",
627e7fbf6f5SAndrew Rybchenko rxq->doorbell);
628390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_info(&rxq->dp.dpq,
629390f9b8dSAndrew Rybchenko "block size is %u, buf stride is %u",
630390f9b8dSAndrew Rybchenko rxq->block_size, rxq->buf_stride);
631390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_info(&rxq->dp.dpq,
632390f9b8dSAndrew Rybchenko "max fill level is %u descs (%u bufs), "
633*7be78d02SJosh Soref "refill threshold %u descs (%u bufs)",
634390f9b8dSAndrew Rybchenko rxq->max_fill_level,
635390f9b8dSAndrew Rybchenko rxq->max_fill_level * rxq->block_size,
636390f9b8dSAndrew Rybchenko rxq->refill_threshold,
637390f9b8dSAndrew Rybchenko rxq->refill_threshold * rxq->block_size);
638390f9b8dSAndrew Rybchenko
639390f9b8dSAndrew Rybchenko *dp_rxqp = &rxq->dp;
640390f9b8dSAndrew Rybchenko return 0;
641390f9b8dSAndrew Rybchenko
642390f9b8dSAndrew Rybchenko fail_desc_alloc:
643390f9b8dSAndrew Rybchenko rte_free(rxq);
644390f9b8dSAndrew Rybchenko
645390f9b8dSAndrew Rybchenko fail_rxq_alloc:
646390f9b8dSAndrew Rybchenko fail_no_block_dequeue:
647390f9b8dSAndrew Rybchenko fail_get_contig_block_size:
6483037e6cfSViacheslav Galaktionov fail_nic_dma:
649390f9b8dSAndrew Rybchenko return rc;
650390f9b8dSAndrew Rybchenko }
651390f9b8dSAndrew Rybchenko
652390f9b8dSAndrew Rybchenko static sfc_dp_rx_qdestroy_t sfc_ef10_essb_rx_qdestroy;
653390f9b8dSAndrew Rybchenko static void
sfc_ef10_essb_rx_qdestroy(struct sfc_dp_rxq * dp_rxq)654390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_qdestroy(struct sfc_dp_rxq *dp_rxq)
655390f9b8dSAndrew Rybchenko {
656390f9b8dSAndrew Rybchenko struct sfc_ef10_essb_rxq *rxq = sfc_ef10_essb_rxq_by_dp_rxq(dp_rxq);
657390f9b8dSAndrew Rybchenko
658390f9b8dSAndrew Rybchenko rte_free(rxq->sw_ring);
659390f9b8dSAndrew Rybchenko rte_free(rxq);
660390f9b8dSAndrew Rybchenko }
661390f9b8dSAndrew Rybchenko
662390f9b8dSAndrew Rybchenko static sfc_dp_rx_qstart_t sfc_ef10_essb_rx_qstart;
663390f9b8dSAndrew Rybchenko static int
sfc_ef10_essb_rx_qstart(struct sfc_dp_rxq * dp_rxq,unsigned int evq_read_ptr,const efx_rx_prefix_layout_t * pinfo)664c6845644SAndrew Rybchenko sfc_ef10_essb_rx_qstart(struct sfc_dp_rxq *dp_rxq, unsigned int evq_read_ptr,
665c6845644SAndrew Rybchenko const efx_rx_prefix_layout_t *pinfo)
666390f9b8dSAndrew Rybchenko {
667390f9b8dSAndrew Rybchenko struct sfc_ef10_essb_rxq *rxq = sfc_ef10_essb_rxq_by_dp_rxq(dp_rxq);
668390f9b8dSAndrew Rybchenko
669c6845644SAndrew Rybchenko if (pinfo->erpl_length != sfc_ef10_essb_rx_prefix_layout.erpl_length)
670c6845644SAndrew Rybchenko return ENOTSUP;
671c6845644SAndrew Rybchenko
672c6845644SAndrew Rybchenko if (efx_rx_prefix_layout_check(pinfo,
673c6845644SAndrew Rybchenko &sfc_ef10_essb_rx_prefix_layout) != 0)
674c6845644SAndrew Rybchenko return ENOTSUP;
675c6845644SAndrew Rybchenko
676390f9b8dSAndrew Rybchenko rxq->evq_read_ptr = evq_read_ptr;
677390f9b8dSAndrew Rybchenko
678390f9b8dSAndrew Rybchenko /* Initialize before refill */
679390f9b8dSAndrew Rybchenko rxq->completed = rxq->pending_id = rxq->added = 0;
680390f9b8dSAndrew Rybchenko rxq->left_in_completed = rxq->left_in_pending = rxq->block_size;
681390f9b8dSAndrew Rybchenko rxq->bufs_ptr = UINT_MAX;
682390f9b8dSAndrew Rybchenko rxq->bufs_pending = 0;
683390f9b8dSAndrew Rybchenko
684390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_qrefill(rxq);
685390f9b8dSAndrew Rybchenko
686390f9b8dSAndrew Rybchenko rxq->flags |= SFC_EF10_ESSB_RXQ_STARTED;
687390f9b8dSAndrew Rybchenko rxq->flags &=
688390f9b8dSAndrew Rybchenko ~(SFC_EF10_ESSB_RXQ_NOT_RUNNING | SFC_EF10_ESSB_RXQ_EXCEPTION);
689390f9b8dSAndrew Rybchenko
690390f9b8dSAndrew Rybchenko return 0;
691390f9b8dSAndrew Rybchenko }
692390f9b8dSAndrew Rybchenko
693390f9b8dSAndrew Rybchenko static sfc_dp_rx_qstop_t sfc_ef10_essb_rx_qstop;
694390f9b8dSAndrew Rybchenko static void
sfc_ef10_essb_rx_qstop(struct sfc_dp_rxq * dp_rxq,unsigned int * evq_read_ptr)695390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_qstop(struct sfc_dp_rxq *dp_rxq, unsigned int *evq_read_ptr)
696390f9b8dSAndrew Rybchenko {
697390f9b8dSAndrew Rybchenko struct sfc_ef10_essb_rxq *rxq = sfc_ef10_essb_rxq_by_dp_rxq(dp_rxq);
698390f9b8dSAndrew Rybchenko
699390f9b8dSAndrew Rybchenko rxq->flags |= SFC_EF10_ESSB_RXQ_NOT_RUNNING;
700390f9b8dSAndrew Rybchenko
701390f9b8dSAndrew Rybchenko *evq_read_ptr = rxq->evq_read_ptr;
702390f9b8dSAndrew Rybchenko }
703390f9b8dSAndrew Rybchenko
704390f9b8dSAndrew Rybchenko static sfc_dp_rx_qrx_ev_t sfc_ef10_essb_rx_qrx_ev;
705390f9b8dSAndrew Rybchenko static bool
sfc_ef10_essb_rx_qrx_ev(struct sfc_dp_rxq * dp_rxq,__rte_unused unsigned int id)706390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_qrx_ev(struct sfc_dp_rxq *dp_rxq, __rte_unused unsigned int id)
707390f9b8dSAndrew Rybchenko {
708390f9b8dSAndrew Rybchenko __rte_unused struct sfc_ef10_essb_rxq *rxq;
709390f9b8dSAndrew Rybchenko
710390f9b8dSAndrew Rybchenko rxq = sfc_ef10_essb_rxq_by_dp_rxq(dp_rxq);
711390f9b8dSAndrew Rybchenko SFC_ASSERT(rxq->flags & SFC_EF10_ESSB_RXQ_NOT_RUNNING);
712390f9b8dSAndrew Rybchenko
713390f9b8dSAndrew Rybchenko /*
714390f9b8dSAndrew Rybchenko * It is safe to ignore Rx event since we free all mbufs on
715390f9b8dSAndrew Rybchenko * queue purge anyway.
716390f9b8dSAndrew Rybchenko */
717390f9b8dSAndrew Rybchenko
718390f9b8dSAndrew Rybchenko return false;
719390f9b8dSAndrew Rybchenko }
720390f9b8dSAndrew Rybchenko
721390f9b8dSAndrew Rybchenko static sfc_dp_rx_qpurge_t sfc_ef10_essb_rx_qpurge;
722390f9b8dSAndrew Rybchenko static void
sfc_ef10_essb_rx_qpurge(struct sfc_dp_rxq * dp_rxq)723390f9b8dSAndrew Rybchenko sfc_ef10_essb_rx_qpurge(struct sfc_dp_rxq *dp_rxq)
724390f9b8dSAndrew Rybchenko {
725390f9b8dSAndrew Rybchenko struct sfc_ef10_essb_rxq *rxq = sfc_ef10_essb_rxq_by_dp_rxq(dp_rxq);
72620680daeSAndrew Rybchenko unsigned int i;
727390f9b8dSAndrew Rybchenko const struct sfc_ef10_essb_rx_sw_desc *rxd;
728390f9b8dSAndrew Rybchenko struct rte_mbuf *m;
729390f9b8dSAndrew Rybchenko
730390f9b8dSAndrew Rybchenko for (i = rxq->completed; i != rxq->added; ++i) {
731390f9b8dSAndrew Rybchenko rxd = &rxq->sw_ring[i & rxq->rxq_ptr_mask];
73220680daeSAndrew Rybchenko m = sfc_ef10_essb_mbuf_by_index(rxq, rxd->first_mbuf,
73320680daeSAndrew Rybchenko rxq->block_size - rxq->left_in_completed);
73420680daeSAndrew Rybchenko while (rxq->left_in_completed > 0) {
73566e10b8dSAndrew Rybchenko rte_mbuf_raw_free(m);
736390f9b8dSAndrew Rybchenko m = sfc_ef10_essb_next_mbuf(rxq, m);
73720680daeSAndrew Rybchenko rxq->left_in_completed--;
738390f9b8dSAndrew Rybchenko }
73920680daeSAndrew Rybchenko rxq->left_in_completed = rxq->block_size;
740390f9b8dSAndrew Rybchenko }
741390f9b8dSAndrew Rybchenko
742390f9b8dSAndrew Rybchenko rxq->flags &= ~SFC_EF10_ESSB_RXQ_STARTED;
743390f9b8dSAndrew Rybchenko }
744390f9b8dSAndrew Rybchenko
745390f9b8dSAndrew Rybchenko struct sfc_dp_rx sfc_ef10_essb_rx = {
746390f9b8dSAndrew Rybchenko .dp = {
747390f9b8dSAndrew Rybchenko .name = SFC_KVARG_DATAPATH_EF10_ESSB,
748390f9b8dSAndrew Rybchenko .type = SFC_DP_RX,
749390f9b8dSAndrew Rybchenko .hw_fw_caps = SFC_DP_HW_FW_CAP_EF10 |
750390f9b8dSAndrew Rybchenko SFC_DP_HW_FW_CAP_RX_ES_SUPER_BUFFER,
751390f9b8dSAndrew Rybchenko },
75226c4f608SAndrew Rybchenko .features = SFC_DP_RX_FEAT_FLOW_FLAG |
753f08d113dSAndrew Rybchenko SFC_DP_RX_FEAT_FLOW_MARK,
754295968d1SFerruh Yigit .dev_offload_capa = RTE_ETH_RX_OFFLOAD_CHECKSUM |
755295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_RSS_HASH,
756f08d113dSAndrew Rybchenko .queue_offload_capa = 0,
757390f9b8dSAndrew Rybchenko .get_dev_info = sfc_ef10_essb_rx_get_dev_info,
7582a97a82bSAndrew Rybchenko .pool_ops_supported = sfc_ef10_essb_rx_pool_ops_supported,
759390f9b8dSAndrew Rybchenko .qsize_up_rings = sfc_ef10_essb_rx_qsize_up_rings,
760390f9b8dSAndrew Rybchenko .qcreate = sfc_ef10_essb_rx_qcreate,
761390f9b8dSAndrew Rybchenko .qdestroy = sfc_ef10_essb_rx_qdestroy,
762390f9b8dSAndrew Rybchenko .qstart = sfc_ef10_essb_rx_qstart,
763390f9b8dSAndrew Rybchenko .qstop = sfc_ef10_essb_rx_qstop,
764390f9b8dSAndrew Rybchenko .qrx_ev = sfc_ef10_essb_rx_qrx_ev,
765390f9b8dSAndrew Rybchenko .qpurge = sfc_ef10_essb_rx_qpurge,
766390f9b8dSAndrew Rybchenko .supported_ptypes_get = sfc_ef10_supported_ptypes_get,
767390f9b8dSAndrew Rybchenko .qdesc_npending = sfc_ef10_essb_rx_qdesc_npending,
768a654e29bSAndrew Rybchenko .qdesc_status = sfc_ef10_essb_rx_qdesc_status,
769390f9b8dSAndrew Rybchenko .pkt_burst = sfc_ef10_essb_recv_pkts,
770390f9b8dSAndrew Rybchenko };
771