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