Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (c) 2022-2023 Google LLC
3 : : * Copyright (c) 2022-2023 Intel Corporation
4 : : */
5 : :
6 : : #include <rte_net.h>
7 : :
8 : : #include "gve_ethdev.h"
9 : : #include "base/gve_adminq.h"
10 : : #include "rte_malloc.h"
11 : :
12 : : static inline void
13 : : gve_free_compl_tags_init(struct gve_tx_queue *txq)
14 : : {
15 : 0 : uint16_t sw_mask = txq->sw_size - 1;
16 : : int i;
17 : :
18 [ # # ]: 0 : for (i = 0; i < sw_mask; i++)
19 : 0 : txq->pkt_ring_dqo[i].next_avail_pkt = (i + 1) & sw_mask;
20 : :
21 : 0 : txq->pkt_ring_dqo[sw_mask].next_avail_pkt = -1;
22 : 0 : txq->free_compl_tags_head = 0;
23 : 0 : txq->num_free_compl_tags = txq->sw_size;
24 : : }
25 : :
26 : : /* Removes first item from the buffer free list, and return its array index. */
27 : : static inline bool
28 : 0 : gve_free_compl_tags_pop(struct gve_tx_queue *txq, uint16_t *compl_tag)
29 : : {
30 : 0 : int16_t head = txq->free_compl_tags_head;
31 [ # # ]: 0 : if (likely(head != -1)) {
32 : 0 : struct gve_tx_pkt *head_pkt = &txq->pkt_ring_dqo[head];
33 : :
34 : 0 : txq->free_compl_tags_head = head_pkt->next_avail_pkt;
35 : 0 : txq->num_free_compl_tags--;
36 : 0 : *compl_tag = head;
37 : 0 : return true;
38 : : }
39 : :
40 : 0 : PMD_DRV_DP_LOG(ERR, "Completion tags list is empty!");
41 : 0 : return false;
42 : : }
43 : :
44 : : /* Adds gve_tx_pkt in pkt_ring to free list. Assumes that
45 : : * buf_id < txq->sw_size.
46 : : */
47 : : static inline void
48 : : gve_free_compl_tags_push(struct gve_tx_queue *txq, uint16_t compl_tag)
49 : : {
50 : 0 : txq->pkt_ring_dqo[compl_tag].next_avail_pkt = txq->free_compl_tags_head;
51 : 0 : txq->free_compl_tags_head = compl_tag;
52 : 0 : txq->num_free_compl_tags++;
53 : 0 : }
54 : :
55 : : static inline void
56 : 0 : gve_tx_clean_dqo(struct gve_tx_queue *txq)
57 : : {
58 : : struct gve_tx_compl_desc *compl_ring;
59 : : struct gve_tx_compl_desc *compl_desc;
60 : : struct gve_tx_pkt *pkt;
61 : : uint16_t new_tx_head;
62 : : uint16_t compl_tag;
63 : : uint16_t next;
64 : :
65 : 0 : next = txq->complq_tail;
66 : 0 : compl_ring = txq->compl_ring;
67 : 0 : compl_desc = &compl_ring[next];
68 : :
69 [ # # ]: 0 : if (compl_desc->generation != txq->cur_gen_bit)
70 : : return;
71 : :
72 : 0 : rte_io_rmb();
73 : :
74 [ # # # # ]: 0 : switch (compl_desc->type) {
75 : 0 : case GVE_COMPL_TYPE_DQO_DESC:
76 : 0 : new_tx_head = rte_le_to_cpu_16(compl_desc->tx_head);
77 : 0 : txq->nb_free +=
78 : 0 : (new_tx_head - txq->last_desc_cleaned)
79 : 0 : & (txq->nb_tx_desc - 1);
80 : 0 : txq->last_desc_cleaned = new_tx_head;
81 : 0 : break;
82 : 0 : case GVE_COMPL_TYPE_DQO_REINJECTION:
83 : : PMD_DRV_DP_LOG(DEBUG, "GVE_COMPL_TYPE_DQO_REINJECTION !!!");
84 : : /* FALLTHROUGH */
85 : : case GVE_COMPL_TYPE_DQO_PKT:
86 : : /* The first segment has buf_id == completion_tag. */
87 : 0 : compl_tag = rte_le_to_cpu_16(compl_desc->completion_tag);
88 [ # # ]: 0 : if (unlikely(compl_tag >= txq->sw_size)) {
89 : 0 : PMD_DRV_DP_LOG(ERR, "Invalid completion tag %d",
90 : : compl_tag);
91 : 0 : break;
92 : : }
93 : :
94 : : /* Free packet.*/
95 : 0 : pkt = &txq->pkt_ring_dqo[compl_tag];
96 [ # # ]: 0 : if (unlikely(!pkt->mbuf)) {
97 : 0 : PMD_DRV_DP_LOG(ERR, "No outstanding packet for completion tag %d",
98 : : compl_tag);
99 : 0 : break;
100 : : }
101 : 0 : rte_pktmbuf_free(pkt->mbuf);
102 : 0 : pkt->mbuf = NULL;
103 : : gve_free_compl_tags_push(txq, compl_tag);
104 : : break;
105 : 0 : case GVE_COMPL_TYPE_DQO_MISS:
106 : 0 : rte_delay_us_sleep(1);
107 : : PMD_DRV_DP_LOG(DEBUG, "GVE_COMPL_TYPE_DQO_MISS ignored !!!");
108 : 0 : break;
109 : 0 : default:
110 : 0 : PMD_DRV_DP_LOG(ERR, "unknown completion type %u", compl_desc->type);
111 : 0 : break;
112 : : }
113 : :
114 : 0 : next++;
115 [ # # ]: 0 : if (next == txq->nb_complq_desc) {
116 : : next = 0;
117 : 0 : txq->cur_gen_bit ^= 1;
118 : : }
119 : 0 : txq->complq_tail = next;
120 : : }
121 : :
122 : : static inline void
123 : : gve_tx_clean_descs_dqo(struct gve_tx_queue *txq, uint16_t nb_descs) {
124 [ # # # # ]: 0 : while (nb_descs--)
125 : 0 : gve_tx_clean_dqo(txq);
126 : : }
127 : :
128 : : /* Validate packet lengths against the device limits. */
129 : : static inline bool
130 : 0 : gve_tx_validate_pkt_limits(const struct rte_mbuf *tx_pkt, bool is_tso)
131 : : {
132 : : uint32_t headlen;
133 : :
134 [ # # ]: 0 : if (!is_tso)
135 : 0 : return tx_pkt->pkt_len >= GVE_TX_MIN_PKT_SIZE_DQO &&
136 : : tx_pkt->pkt_len <= GVE_TX_MAX_PKT_SIZE_DQO;
137 : :
138 : : /* Headers must be present, fit the context descriptor, and be
139 : : * contained in the first segment; the payload must not be empty.
140 : : */
141 : 0 : headlen = tx_pkt->l2_len + tx_pkt->l3_len + tx_pkt->l4_len;
142 [ # # # # ]: 0 : if (tx_pkt->l4_len == 0 || headlen < GVE_TX_MIN_TSO_HDR_LEN_DQO ||
143 [ # # ]: 0 : headlen > GVE_TX_MAX_HDR_SIZE_DQO || tx_pkt->data_len < headlen ||
144 [ # # ]: 0 : tx_pkt->pkt_len <= headlen)
145 : : return false;
146 : :
147 : 0 : return tx_pkt->pkt_len - headlen <= GVE_TX_MAX_TSO_LEN_DQO &&
148 [ # # # # : 0 : tx_pkt->tso_segsz >= GVE_TX_MIN_TSO_MSS_DQO &&
# # ]
149 : : tx_pkt->tso_segsz <= GVE_TX_MAX_PKT_SIZE_DQO;
150 : : }
151 : :
152 : : /* Max descriptors a single packet may use. A larger packet can never pass
153 : : * gve_can_tx(): one slot is always reserved, the cacheline overlap margin
154 : : * must stay free, and up to GVE_TX_MIN_RE_INTERVAL - 1 descriptors posted
155 : : * after the last report_event are not reclaimed until more are posted.
156 : : */
157 : : static inline int
158 : : gve_tx_max_pkt_descs(const struct gve_tx_queue *txq)
159 : : {
160 : 0 : return (int)txq->nb_tx_desc - 1 - GVE_TX_MIN_DESC_PREVENT_CACHE_OVERLAP -
161 : : (GVE_TX_MIN_RE_INTERVAL - 1);
162 : : }
163 : :
164 : : /* GVE expects at most 10 data descriptors per mtu-sized segment. Beyond this,
165 : : * the hardware will assume the driver is malicious and stop transmitting
166 : : * packets altogether. Validate that a packet can be sent to avoid sending
167 : : * posting descriptors for an invalid packet.
168 : : */
169 : : static inline bool
170 : 0 : gve_tx_validate_descs(const struct gve_tx_queue *txq, struct rte_mbuf *tx_pkt,
171 : : uint16_t nb_descs, bool is_tso)
172 : : {
173 [ # # ]: 0 : if (nb_descs > gve_tx_max_pkt_descs(txq))
174 : : return false;
175 : :
176 [ # # ]: 0 : if (!is_tso)
177 : 0 : return nb_descs <= GVE_TX_MAX_DATA_DESCS;
178 : :
179 : 0 : int tso_segsz = tx_pkt->tso_segsz;
180 : : int num_descs, seg_offset, mbuf_len;
181 : 0 : int headlen = tx_pkt->l2_len + tx_pkt->l3_len + tx_pkt->l4_len;
182 : :
183 : : /* Headers will be split into their own buffer. */
184 : : num_descs = 1;
185 : : seg_offset = 0;
186 : 0 : mbuf_len = tx_pkt->data_len - headlen;
187 : :
188 [ # # ]: 0 : while (tx_pkt) {
189 [ # # ]: 0 : if (!mbuf_len)
190 : 0 : goto next_mbuf;
191 : :
192 : 0 : int seg_remain = tso_segsz - seg_offset;
193 [ # # ]: 0 : if (num_descs == GVE_TX_MAX_DATA_DESCS && seg_remain)
194 : : return false;
195 : :
196 [ # # ]: 0 : if (seg_remain < mbuf_len) {
197 : 0 : seg_offset = (mbuf_len - seg_remain) % tso_segsz;
198 : : /* The MSS is bound from above by 9728B, so a
199 : : * single TSO segment in the middle of an mbuf
200 : : * will be part of at most two descriptors, and
201 : : * is not at risk of defying this limitation.
202 : : * Thus, such segments are ignored.
203 : : */
204 : 0 : int mbuf_remain = tx_pkt->data_len % GVE_TX_MAX_BUF_SIZE_DQO;
205 : :
206 : : /* For each TSO segment, HW will prepend
207 : : * headers. The remaining bytes of this mbuf
208 : : * will be the start of the payload of the next
209 : : * TSO segment. In addition, if the final
210 : : * segment in this mbuf is divided between two
211 : : * descriptors, both must be counted.
212 : : */
213 [ # # ]: 0 : num_descs = 1 + !!(seg_offset) +
214 : 0 : (mbuf_remain < seg_offset && mbuf_remain);
215 : : } else {
216 : 0 : seg_offset += mbuf_len;
217 : 0 : num_descs++;
218 : : }
219 : :
220 : 0 : next_mbuf:
221 : 0 : tx_pkt = tx_pkt->next;
222 [ # # ]: 0 : if (tx_pkt)
223 : 0 : mbuf_len = tx_pkt->data_len;
224 : : }
225 : :
226 : :
227 : : return true;
228 : : }
229 : :
230 : : static uint16_t
231 : : gve_tx_pkt_nb_data_descs(struct rte_mbuf *tx_pkt)
232 : : {
233 : : int nb_descs = 0;
234 : :
235 [ # # # # : 0 : while (tx_pkt) {
# # ]
236 : 0 : nb_descs += (GVE_TX_MAX_BUF_SIZE_DQO - 1 + tx_pkt->data_len) /
237 : : GVE_TX_MAX_BUF_SIZE_DQO;
238 : 0 : tx_pkt = tx_pkt->next;
239 : : }
240 : 0 : return nb_descs;
241 : : }
242 : :
243 : : static inline bool
244 : : gve_can_tx(struct gve_tx_queue *txq, uint16_t nb_desc, uint16_t nb_pkts)
245 : : {
246 [ # # # # : 0 : return txq->nb_free >= nb_desc && txq->num_free_compl_tags >= nb_pkts;
# # # # ]
247 : : }
248 : :
249 : : static inline void
250 : : gve_tx_fill_seg_desc_dqo(volatile union gve_tx_desc_dqo *desc, struct rte_mbuf *tx_pkt)
251 : : {
252 : 0 : uint32_t hlen = tx_pkt->l2_len + tx_pkt->l3_len + tx_pkt->l4_len;
253 : :
254 : 0 : desc->tso_ctx = (struct gve_tx_tso_context_desc_dqo) {};
255 : 0 : desc->tso_ctx.cmd_dtype.dtype = GVE_TX_TSO_CTX_DESC_DTYPE_DQO;
256 : 0 : desc->tso_ctx.cmd_dtype.tso = 1;
257 : 0 : desc->tso_ctx.mss = (uint16_t)tx_pkt->tso_segsz;
258 : 0 : desc->tso_ctx.tso_total_len = tx_pkt->pkt_len - hlen;
259 : 0 : desc->tso_ctx.header_len = (uint8_t)hlen;
260 : : }
261 : :
262 : : static void
263 : 0 : gve_fill_tx_pkt_desc(struct gve_tx_queue *txq, uint16_t *tx_id,
264 : : struct rte_mbuf *tx_pkt, uint16_t compl_tag,
265 : : bool checksum_offload_enable)
266 : : {
267 : : volatile union gve_tx_desc_dqo *desc;
268 : 0 : uint16_t mask = txq->nb_tx_desc - 1;
269 : : int mbuf_offset = 0;
270 : :
271 [ # # ]: 0 : while (mbuf_offset < tx_pkt->data_len) {
272 : 0 : uint64_t buf_addr = rte_mbuf_data_iova(tx_pkt) + mbuf_offset;
273 : :
274 : 0 : desc = &txq->tx_ring[*tx_id];
275 : 0 : desc->pkt = (struct gve_tx_pkt_desc_dqo) {};
276 : 0 : desc->pkt.buf_addr = rte_cpu_to_le_64(buf_addr);
277 : 0 : desc->pkt.compl_tag = rte_cpu_to_le_16(compl_tag);
278 : 0 : desc->pkt.dtype = GVE_TX_PKT_DESC_DTYPE_DQO;
279 : 0 : desc->pkt.buf_size = RTE_MIN(tx_pkt->data_len - mbuf_offset,
280 : : GVE_TX_MAX_BUF_SIZE_DQO);
281 : 0 : desc->pkt.end_of_packet = 0;
282 : 0 : desc->pkt.checksum_offload_enable = checksum_offload_enable;
283 : :
284 : 0 : mbuf_offset += desc->pkt.buf_size;
285 : 0 : *tx_id = (*tx_id + 1) & mask;
286 : : }
287 : 0 : }
288 : :
289 : : uint16_t
290 : 0 : gve_tx_pkt_prepare_dqo(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
291 : : {
292 : : struct gve_tx_queue *txq = tx_queue;
293 : : uint16_t i;
294 : :
295 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
296 : : struct rte_mbuf *tx_pkt;
297 : : uint16_t nb_descs;
298 : : bool tso;
299 : : int err;
300 : :
301 : 0 : tx_pkt = tx_pkts[i];
302 : :
303 : : #ifdef RTE_ETHDEV_DEBUG_TX
304 : : const char *reason;
305 : :
306 : : if (rte_mbuf_check(tx_pkt, true, &reason)) {
307 : : rte_errno = EINVAL;
308 : : return i;
309 : : }
310 : :
311 : : err = rte_validate_tx_offload(tx_pkt);
312 : : if (err != 0) {
313 : : rte_errno = -err;
314 : : return i;
315 : : }
316 : : #endif
317 : :
318 : 0 : tso = !!(tx_pkt->ol_flags & RTE_MBUF_F_TX_TCP_SEG);
319 [ # # ]: 0 : if (!gve_tx_validate_pkt_limits(tx_pkt, tso)) {
320 : 0 : rte_errno = EINVAL;
321 : 0 : return i;
322 : : }
323 : :
324 [ # # ]: 0 : if (tso) {
325 : 0 : nb_descs = gve_tx_pkt_nb_data_descs(tx_pkt) + 1;
326 : : } else {
327 : : /* Handle non-TSO packets by directly checking nb_segs.
328 : : * The packet has already been validated to be no larger
329 : : * than 9728B, so every descriptor is guaranteed to only
330 : : * require a single descriptor.
331 : : * If the packet does not meet the hardware descriptor
332 : : * limits, fall back to the mbuf walk in case the
333 : : * mbuf has empty segments.
334 : : */
335 [ # # ]: 0 : if (tx_pkt->nb_segs <= GVE_TX_MAX_DATA_DESCS)
336 : 0 : continue;
337 : : nb_descs = gve_tx_pkt_nb_data_descs(tx_pkt);
338 : : }
339 [ # # ]: 0 : if (!gve_tx_validate_descs(txq, tx_pkt, nb_descs, tso)) {
340 : 0 : rte_errno = ENOTSUP;
341 : 0 : return i;
342 : : }
343 : :
344 : : /* If TSO is enabled, the L4 pseudo header checksum must be
345 : : * seeded. In this case, headers must all be in the same buffer.
346 : : */
347 [ # # ]: 0 : if (tso) {
348 : : err = rte_net_intel_cksum_prepare(tx_pkt);
349 [ # # ]: 0 : if (err != 0) {
350 : 0 : rte_errno = -err;
351 : 0 : return i;
352 : : }
353 : : }
354 : : }
355 : :
356 : : return nb_pkts;
357 : : }
358 : :
359 : : uint16_t
360 : 0 : gve_tx_burst_dqo(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
361 : : {
362 : : struct gve_tx_queue *txq = tx_queue;
363 : : volatile union gve_tx_desc_dqo *txr;
364 : : volatile union gve_tx_desc_dqo *txd;
365 : 0 : uint16_t mask = txq->nb_tx_desc - 1;
366 : : uint16_t last_re_interval;
367 : : uint16_t last_desc_idx;
368 : : struct gve_tx_pkt *pkts;
369 : : struct rte_mbuf *tx_pkt;
370 : : uint16_t compl_tag;
371 : : uint16_t req_descs;
372 : : const char *reason;
373 : : uint16_t nb_sent = 0;
374 : : uint16_t nb_tx = 0;
375 : : uint64_t bytes = 0;
376 : : uint64_t ol_flags;
377 : : uint16_t nb_descs;
378 : : bool csum, tso;
379 : : uint16_t tx_id;
380 : :
381 : 0 : pkts = txq->pkt_ring_dqo;
382 : 0 : txr = txq->tx_ring;
383 : :
384 : 0 : tx_id = txq->tx_tail;
385 : :
386 [ # # ]: 0 : for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
387 : 0 : tx_pkt = tx_pkts[nb_tx];
388 : :
389 [ # # # # ]: 0 : if (!gve_can_tx(txq, txq->free_thresh, nb_pkts - nb_tx))
390 : 0 : gve_tx_clean_descs_dqo(txq, DQO_TX_MULTIPLIER *
391 : 0 : txq->rs_thresh);
392 : :
393 : :
394 [ # # ]: 0 : if (rte_mbuf_check(tx_pkt, true, &reason)) {
395 : : PMD_DRV_DP_LOG(DEBUG, "Invalid mbuf: %s", reason);
396 : 0 : txq->stats.invalid_mbufs++;
397 : 0 : rte_pktmbuf_free(tx_pkt);
398 : 0 : continue;
399 : : }
400 : :
401 : 0 : ol_flags = tx_pkt->ol_flags;
402 : 0 : tso = !!(ol_flags & RTE_MBUF_F_TX_TCP_SEG);
403 : 0 : csum = !!(ol_flags & GVE_TX_CKSUM_OFFLOAD_MASK_DQO);
404 : :
405 [ # # ]: 0 : if (!gve_tx_validate_pkt_limits(tx_pkt, tso)) {
406 : 0 : txq->stats.invalid_pkts++;
407 : 0 : rte_pktmbuf_free(tx_pkt);
408 : 0 : continue;
409 : : }
410 : :
411 : : nb_descs = gve_tx_pkt_nb_data_descs(tx_pkt);
412 : 0 : nb_descs += tso;
413 : :
414 : : /* Drop packet if it doesn't adhere to hardware limits. */
415 [ # # ]: 0 : if (!gve_tx_validate_descs(txq, tx_pkt, nb_descs, tso)) {
416 : 0 : txq->stats.too_many_descs++;
417 : 0 : rte_pktmbuf_free(tx_pkt);
418 : 0 : continue;
419 : : }
420 : :
421 : 0 : req_descs = nb_descs + GVE_TX_MIN_DESC_PREVENT_CACHE_OVERLAP;
422 : :
423 : : /* Clean if there aren't enough descriptors to send the packet
424 : : * while maintaining the cacheline overlap margin.
425 : : */
426 [ # # # # ]: 0 : if (unlikely(!gve_can_tx(txq, req_descs, 1))) {
427 : 0 : int nb_to_clean = RTE_MAX(DQO_TX_MULTIPLIER * txq->rs_thresh,
428 : : (int)req_descs);
429 : :
430 : 0 : gve_tx_clean_descs_dqo(txq, nb_to_clean);
431 [ # # ]: 0 : if (!gve_can_tx(txq, req_descs, 1))
432 : : break;
433 : : }
434 : :
435 [ # # ]: 0 : if (!gve_free_compl_tags_pop(txq, &compl_tag))
436 : : break;
437 : :
438 [ # # ]: 0 : if (tso) {
439 : 0 : txd = &txr[tx_id];
440 : : gve_tx_fill_seg_desc_dqo(txd, tx_pkt);
441 : 0 : tx_id = (tx_id + 1) & mask;
442 : : }
443 : :
444 : 0 : pkts[compl_tag].mbuf = tx_pkt;
445 [ # # ]: 0 : while (tx_pkt) {
446 : : /* Skip writing descriptors if mbuf has no data. */
447 [ # # ]: 0 : if (!tx_pkt->data_len) {
448 : 0 : tx_pkt = tx_pkt->next;
449 : 0 : continue;
450 : : }
451 : 0 : gve_fill_tx_pkt_desc(txq, &tx_id, tx_pkt, compl_tag,
452 : : csum);
453 : 0 : bytes += tx_pkt->data_len;
454 : 0 : tx_pkt = tx_pkt->next;
455 : : }
456 : : /* fill the last written descriptor with End of Packet (EOP) bit */
457 : 0 : txd = &txr[(tx_id - 1) & mask];
458 : 0 : txd->pkt.end_of_packet = 1;
459 : :
460 : : /* Request a descriptor completion once at least
461 : : * GVE_TX_MIN_RE_INTERVAL descriptors have been posted
462 : : * since the last request.
463 : : */
464 : 0 : last_desc_idx = (tx_id - 1) & mask;
465 : 0 : last_re_interval = (last_desc_idx - txq->last_re_idx) & mask;
466 [ # # ]: 0 : if (unlikely(last_re_interval >= GVE_TX_MIN_RE_INTERVAL)) {
467 : 0 : txd->pkt.report_event = true;
468 : 0 : txq->last_re_idx = last_desc_idx;
469 : : }
470 : :
471 : 0 : txq->nb_free -= nb_descs;
472 : 0 : txq->nb_used += nb_descs;
473 : 0 : nb_sent++;
474 : : }
475 : :
476 : : /* update the tail pointer if any packets were processed */
477 [ # # ]: 0 : if (nb_tx > 0) {
478 : 0 : rte_write32(tx_id, txq->qtx_tail);
479 : 0 : txq->tx_tail = tx_id;
480 : :
481 : 0 : txq->stats.packets += nb_sent;
482 : 0 : txq->stats.bytes += bytes;
483 : 0 : txq->stats.errors += nb_pkts - nb_sent;
484 : : }
485 : :
486 : 0 : return nb_tx;
487 : : }
488 : :
489 : : static inline void
490 : : gve_release_txq_mbufs_dqo(struct gve_tx_queue *txq)
491 : : {
492 : : uint16_t i;
493 : :
494 [ # # # # ]: 0 : for (i = 0; i < txq->sw_size; i++)
495 : 0 : rte_pktmbuf_free(txq->pkt_ring_dqo[i].mbuf);
496 : : }
497 : :
498 : : void
499 : 0 : gve_tx_queue_release_dqo(struct rte_eth_dev *dev, uint16_t qid)
500 : : {
501 : 0 : struct gve_tx_queue *q = dev->data->tx_queues[qid];
502 : :
503 [ # # ]: 0 : if (q == NULL)
504 : : return;
505 : :
506 : : gve_release_txq_mbufs_dqo(q);
507 : 0 : rte_free(q->pkt_ring_dqo);
508 : 0 : rte_memzone_free(q->mz);
509 : 0 : rte_memzone_free(q->compl_ring_mz);
510 : 0 : rte_memzone_free(q->qres_mz);
511 : 0 : q->qres = NULL;
512 : 0 : rte_free(q);
513 : :
514 : 0 : dev->data->tx_queues[qid] = NULL;
515 : : }
516 : :
517 : : static int
518 : 0 : check_tx_thresh_dqo(uint16_t nb_desc, uint16_t tx_rs_thresh,
519 : : uint16_t tx_free_thresh)
520 : : {
521 [ # # ]: 0 : if (tx_rs_thresh >= (nb_desc - 2)) {
522 : 0 : PMD_DRV_LOG(ERR, "tx_rs_thresh (%u) must be less than the "
523 : : "number of TX descriptors (%u) minus 2",
524 : : tx_rs_thresh, nb_desc);
525 : 0 : return -EINVAL;
526 : : }
527 [ # # ]: 0 : if (tx_free_thresh >= (nb_desc - 3)) {
528 : 0 : PMD_DRV_LOG(ERR, "tx_free_thresh (%u) must be less than the "
529 : : "number of TX descriptors (%u) minus 3.",
530 : : tx_free_thresh, nb_desc);
531 : 0 : return -EINVAL;
532 : : }
533 [ # # ]: 0 : if (tx_rs_thresh > tx_free_thresh) {
534 : 0 : PMD_DRV_LOG(ERR, "tx_rs_thresh (%u) must be less than or "
535 : : "equal to tx_free_thresh (%u).",
536 : : tx_rs_thresh, tx_free_thresh);
537 : 0 : return -EINVAL;
538 : : }
539 [ # # ]: 0 : if ((nb_desc % tx_rs_thresh) != 0) {
540 : 0 : PMD_DRV_LOG(ERR, "tx_rs_thresh (%u) must be a divisor of the "
541 : : "number of TX descriptors (%u).",
542 : : tx_rs_thresh, nb_desc);
543 : 0 : return -EINVAL;
544 : : }
545 : :
546 : : return 0;
547 : : }
548 : :
549 : : static void
550 : 0 : gve_reset_tx_ring_state_dqo(struct gve_tx_queue *txq)
551 : : {
552 : : struct gve_tx_pkt *pkt_ring_dqo;
553 : : uint32_t size, i;
554 : :
555 [ # # ]: 0 : if (txq == NULL) {
556 : 0 : PMD_DRV_LOG(ERR, "Pointer to txq is NULL");
557 : 0 : return;
558 : : }
559 : :
560 : 0 : size = txq->nb_tx_desc * sizeof(union gve_tx_desc_dqo);
561 [ # # ]: 0 : for (i = 0; i < size; i++)
562 : 0 : ((volatile char *)txq->tx_ring)[i] = 0;
563 : :
564 : 0 : size = txq->nb_complq_desc * sizeof(struct gve_tx_compl_desc);
565 [ # # ]: 0 : for (i = 0; i < size; i++)
566 : 0 : ((volatile char *)txq->compl_ring)[i] = 0;
567 : :
568 : 0 : pkt_ring_dqo = txq->pkt_ring_dqo;
569 [ # # ]: 0 : for (i = 0; i < txq->sw_size; i++)
570 : 0 : pkt_ring_dqo[i].mbuf = NULL;
571 : :
572 : : gve_free_compl_tags_init(txq);
573 : :
574 : 0 : txq->tx_tail = 0;
575 : 0 : txq->nb_used = 0;
576 : :
577 : 0 : txq->last_desc_cleaned = 0;
578 : 0 : txq->last_re_idx = 0;
579 : 0 : txq->nb_free = txq->nb_tx_desc - 1;
580 : :
581 : 0 : txq->complq_tail = 0;
582 : 0 : txq->cur_gen_bit = 1;
583 : : }
584 : :
585 : : int
586 : 0 : gve_tx_queue_setup_dqo(struct rte_eth_dev *dev, uint16_t queue_id,
587 : : uint16_t nb_desc, unsigned int socket_id,
588 : : const struct rte_eth_txconf *conf)
589 : : {
590 : 0 : struct gve_priv *hw = dev->data->dev_private;
591 : : const struct rte_memzone *mz;
592 : : struct gve_tx_queue *txq;
593 : : uint16_t free_thresh;
594 : : uint16_t rs_thresh;
595 : : uint16_t sw_size;
596 : : int err = 0;
597 : :
598 : : /* Free memory if needed. */
599 [ # # ]: 0 : if (dev->data->tx_queues[queue_id]) {
600 : 0 : gve_tx_queue_release_dqo(dev, queue_id);
601 : 0 : dev->data->tx_queues[queue_id] = NULL;
602 : : }
603 : :
604 : : /* Allocate the TX queue data structure. */
605 : 0 : txq = rte_zmalloc_socket("gve txq",
606 : : sizeof(struct gve_tx_queue),
607 : : RTE_CACHE_LINE_SIZE, socket_id);
608 [ # # ]: 0 : if (txq == NULL) {
609 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for tx queue structure");
610 : 0 : return -ENOMEM;
611 : : }
612 : :
613 : : /* need to check free_thresh here */
614 [ # # ]: 0 : free_thresh = conf->tx_free_thresh ?
615 : : conf->tx_free_thresh : GVE_DEFAULT_TX_FREE_THRESH;
616 [ # # ]: 0 : rs_thresh = conf->tx_rs_thresh ?
617 : : conf->tx_rs_thresh : GVE_DEFAULT_TX_RS_THRESH;
618 [ # # ]: 0 : if (check_tx_thresh_dqo(nb_desc, rs_thresh, free_thresh))
619 : : return -EINVAL;
620 : :
621 : 0 : txq->nb_tx_desc = nb_desc;
622 : 0 : txq->nb_complq_desc = nb_desc * DQO_TX_MULTIPLIER;
623 : 0 : txq->free_thresh = free_thresh;
624 : 0 : txq->rs_thresh = rs_thresh;
625 : 0 : txq->queue_id = queue_id;
626 : 0 : txq->port_id = dev->data->port_id;
627 : 0 : txq->ntfy_id = queue_id;
628 : 0 : txq->hw = hw;
629 [ # # ]: 0 : txq->ntfy_addr = &hw->db_bar[rte_be_to_cpu_32(hw->irq_dbs[txq->ntfy_id].id)];
630 : :
631 : : /* Allocate software ring */
632 : : sw_size = nb_desc;
633 : 0 : txq->pkt_ring_dqo = rte_zmalloc_socket("gve tx sw ring",
634 : : sw_size * sizeof(struct gve_tx_pkt),
635 : : RTE_CACHE_LINE_SIZE, socket_id);
636 [ # # ]: 0 : if (txq->pkt_ring_dqo == NULL) {
637 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for SW TX ring");
638 : : err = -ENOMEM;
639 : 0 : goto free_txq;
640 : : }
641 : 0 : txq->sw_size = sw_size;
642 : :
643 : : /* Allocate TX hardware ring descriptors. */
644 : 0 : mz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_id,
645 : : nb_desc * sizeof(union gve_tx_desc_dqo),
646 : : PAGE_SIZE, socket_id);
647 [ # # ]: 0 : if (mz == NULL) {
648 : 0 : PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX");
649 : : err = -ENOMEM;
650 : 0 : goto free_txq_pkt_ring;
651 : : }
652 : 0 : txq->tx_ring = (union gve_tx_desc_dqo *)mz->addr;
653 : 0 : txq->tx_ring_phys_addr = mz->iova;
654 : 0 : txq->mz = mz;
655 : :
656 : : /* Allocate TX completion ring descriptors. */
657 : 0 : mz = rte_eth_dma_zone_reserve(dev, "tx_compl_ring", queue_id,
658 : 0 : txq->nb_complq_desc * sizeof(struct gve_tx_compl_desc),
659 : : PAGE_SIZE, socket_id);
660 [ # # ]: 0 : if (mz == NULL) {
661 : 0 : PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX completion queue");
662 : : err = -ENOMEM;
663 : 0 : goto free_txq_mz;
664 : : }
665 : 0 : txq->compl_ring = (struct gve_tx_compl_desc *)mz->addr;
666 : 0 : txq->compl_ring_phys_addr = mz->iova;
667 : 0 : txq->compl_ring_mz = mz;
668 : :
669 : 0 : mz = rte_eth_dma_zone_reserve(dev, "txq_res", queue_id,
670 : : sizeof(struct gve_queue_resources),
671 : : PAGE_SIZE, socket_id);
672 [ # # ]: 0 : if (mz == NULL) {
673 : 0 : PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX resource");
674 : : err = -ENOMEM;
675 : 0 : goto free_txq_cq_mz;
676 : : }
677 : 0 : txq->qres = (struct gve_queue_resources *)mz->addr;
678 : 0 : txq->qres_mz = mz;
679 : :
680 : 0 : gve_reset_tx_ring_state_dqo(txq);
681 : :
682 : 0 : dev->data->tx_queues[queue_id] = txq;
683 : :
684 : 0 : return 0;
685 : :
686 : : free_txq_cq_mz:
687 : 0 : rte_memzone_free(txq->compl_ring_mz);
688 : 0 : free_txq_mz:
689 : 0 : rte_memzone_free(txq->mz);
690 : 0 : free_txq_pkt_ring:
691 : 0 : rte_free(txq->pkt_ring_dqo);
692 : 0 : free_txq:
693 : 0 : rte_free(txq);
694 : 0 : return err;
695 : : }
696 : :
697 : : int
698 : 0 : gve_tx_queue_start_dqo(struct rte_eth_dev *dev, uint16_t tx_queue_id)
699 : : {
700 : 0 : struct gve_priv *hw = dev->data->dev_private;
701 : : struct gve_tx_queue *txq;
702 : :
703 [ # # ]: 0 : if (tx_queue_id >= dev->data->nb_tx_queues)
704 : : return -EINVAL;
705 : :
706 : 0 : txq = dev->data->tx_queues[tx_queue_id];
707 : :
708 [ # # ]: 0 : txq->qtx_tail = &hw->db_bar[rte_be_to_cpu_32(txq->qres->db_index)];
709 : 0 : txq->qtx_head =
710 [ # # ]: 0 : &hw->cnt_array[rte_be_to_cpu_32(txq->qres->counter_index)];
711 : :
712 : : rte_write32(rte_cpu_to_le_32(GVE_NO_INT_MODE_DQO |
713 : : GVE_ITR_NO_UPDATE_DQO),
714 : 0 : txq->ntfy_addr);
715 : :
716 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
717 : :
718 : 0 : return 0;
719 : : }
720 : :
721 : : int
722 : 0 : gve_tx_queue_stop_dqo(struct rte_eth_dev *dev, uint16_t tx_queue_id)
723 : : {
724 : : struct gve_tx_queue *txq;
725 : :
726 [ # # ]: 0 : if (tx_queue_id >= dev->data->nb_tx_queues)
727 : : return -EINVAL;
728 : :
729 : 0 : txq = dev->data->tx_queues[tx_queue_id];
730 : : gve_release_txq_mbufs_dqo(txq);
731 : 0 : gve_reset_tx_ring_state_dqo(txq);
732 : :
733 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
734 : :
735 : 0 : return 0;
736 : : }
737 : :
738 : : void
739 : 0 : gve_stop_tx_queues_dqo(struct rte_eth_dev *dev)
740 : : {
741 : 0 : struct gve_process_private *process_priv = dev->process_private;
742 : 0 : struct gve_priv *hw = dev->data->dev_private;
743 : : uint16_t i;
744 : : int err;
745 : :
746 : 0 : err = process_priv->ctrl_ops->destroy_tx_queues(hw, dev->data->nb_tx_queues);
747 [ # # ]: 0 : if (err != 0)
748 : 0 : PMD_DRV_LOG(WARNING, "failed to destroy txqs");
749 : :
750 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
751 [ # # ]: 0 : if (gve_tx_queue_stop_dqo(dev, i) != 0)
752 : 0 : PMD_DRV_LOG(WARNING, "Fail to stop Tx queue %d", i);
753 : 0 : }
754 : :
755 : : void
756 : 0 : gve_set_tx_function_dqo(struct rte_eth_dev *dev)
757 : : {
758 : 0 : dev->tx_pkt_burst = gve_tx_burst_dqo;
759 : 0 : dev->tx_pkt_prepare = gve_tx_pkt_prepare_dqo;
760 : 0 : }
|