Imported Upstream version 16.07-rc2
[deb_dpdk.git] / drivers / net / ena / base / ena_eth_com.c
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright (c) 2015-2016 Amazon.com, Inc. or its affiliates.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include "ena_eth_com.h"
35
36 static inline struct ena_eth_io_rx_cdesc_base *ena_com_get_next_rx_cdesc(
37         struct ena_com_io_cq *io_cq)
38 {
39         struct ena_eth_io_rx_cdesc_base *cdesc;
40         u16 expected_phase, head_masked;
41         u16 desc_phase;
42
43         head_masked = io_cq->head & (io_cq->q_depth - 1);
44         expected_phase = io_cq->phase;
45
46         cdesc = (struct ena_eth_io_rx_cdesc_base *)
47                 ((unsigned char *)io_cq->cdesc_addr.virt_addr
48                         + (head_masked * io_cq->cdesc_entry_size_in_bytes));
49
50         desc_phase = (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_PHASE_MASK) >>
51                         ENA_ETH_IO_RX_CDESC_BASE_PHASE_SHIFT;
52
53         if (desc_phase != expected_phase)
54                 return NULL;
55
56         return cdesc;
57 }
58
59 static inline void ena_com_cq_inc_head(struct ena_com_io_cq *io_cq)
60 {
61         io_cq->head++;
62
63         /* Switch phase bit in case of wrap around */
64         if (unlikely((io_cq->head & (io_cq->q_depth - 1)) == 0))
65                 io_cq->phase ^= 1;
66 }
67
68 static inline void *get_sq_desc(struct ena_com_io_sq *io_sq)
69 {
70         u16 tail_masked;
71         u32 offset;
72
73         tail_masked = io_sq->tail & (io_sq->q_depth - 1);
74
75         offset = tail_masked * io_sq->desc_entry_size;
76
77         return (unsigned char *)io_sq->desc_addr.virt_addr + offset;
78 }
79
80 static inline void ena_com_copy_curr_sq_desc_to_dev(struct ena_com_io_sq *io_sq)
81 {
82         u16 tail_masked = io_sq->tail & (io_sq->q_depth - 1);
83         u32 offset = tail_masked * io_sq->desc_entry_size;
84
85         /* In case this queue isn't a LLQ */
86         if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_HOST)
87                 return;
88
89         memcpy_toio((unsigned char *)io_sq->desc_addr.pbuf_dev_addr + offset,
90                     (unsigned char *)io_sq->desc_addr.virt_addr + offset,
91                     io_sq->desc_entry_size);
92 }
93
94 static inline void ena_com_sq_update_tail(struct ena_com_io_sq *io_sq)
95 {
96         io_sq->tail++;
97
98         /* Switch phase bit in case of wrap around */
99         if (unlikely((io_sq->tail & (io_sq->q_depth - 1)) == 0))
100                 io_sq->phase ^= 1;
101 }
102
103 static inline int ena_com_write_header(struct ena_com_io_sq *io_sq,
104                                        u8 *head_src, u16 header_len)
105 {
106         u16 tail_masked = io_sq->tail & (io_sq->q_depth - 1);
107         u8 __iomem *dev_head_addr =
108                 io_sq->header_addr + (tail_masked * io_sq->tx_max_header_size);
109
110         if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_HOST)
111                 return 0;
112
113         if (unlikely(!io_sq->header_addr)) {
114                 ena_trc_err("Push buffer header ptr is NULL\n");
115                 return ENA_COM_INVAL;
116         }
117
118         memcpy_toio(dev_head_addr, head_src, header_len);
119
120         return 0;
121 }
122
123 static inline struct ena_eth_io_rx_cdesc_base *
124         ena_com_rx_cdesc_idx_to_ptr(struct ena_com_io_cq *io_cq, u16 idx)
125 {
126         idx &= (io_cq->q_depth - 1);
127         return (struct ena_eth_io_rx_cdesc_base *)
128                 ((unsigned char *)io_cq->cdesc_addr.virt_addr +
129                         idx * io_cq->cdesc_entry_size_in_bytes);
130 }
131
132 static inline int ena_com_cdesc_rx_pkt_get(struct ena_com_io_cq *io_cq,
133                                            u16 *first_cdesc_idx)
134 {
135         struct ena_eth_io_rx_cdesc_base *cdesc;
136         u16 count = 0, head_masked;
137         u32 last = 0;
138
139         do {
140                 cdesc = ena_com_get_next_rx_cdesc(io_cq);
141                 if (!cdesc)
142                         break;
143
144                 ena_com_cq_inc_head(io_cq);
145                 count++;
146                 last = (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_LAST_MASK) >>
147                         ENA_ETH_IO_RX_CDESC_BASE_LAST_SHIFT;
148         } while (!last);
149
150         if (last) {
151                 *first_cdesc_idx = io_cq->cur_rx_pkt_cdesc_start_idx;
152                 count += io_cq->cur_rx_pkt_cdesc_count;
153
154                 head_masked = io_cq->head & (io_cq->q_depth - 1);
155
156                 io_cq->cur_rx_pkt_cdesc_count = 0;
157                 io_cq->cur_rx_pkt_cdesc_start_idx = head_masked;
158
159                 ena_trc_dbg("ena q_id: %d packets were completed. first desc idx %u descs# %d\n",
160                             io_cq->qid, *first_cdesc_idx, count);
161         } else {
162                 io_cq->cur_rx_pkt_cdesc_count += count;
163                 count = 0;
164         }
165
166         return count;
167 }
168
169 static inline bool ena_com_meta_desc_changed(struct ena_com_io_sq *io_sq,
170                                              struct ena_com_tx_ctx *ena_tx_ctx)
171 {
172         int rc;
173
174         if (ena_tx_ctx->meta_valid) {
175                 rc = memcmp(&io_sq->cached_tx_meta,
176                             &ena_tx_ctx->ena_meta,
177                             sizeof(struct ena_com_tx_meta));
178
179                 if (unlikely(rc != 0))
180                         return true;
181         }
182
183         return false;
184 }
185
186 static inline void ena_com_create_and_store_tx_meta_desc(
187         struct ena_com_io_sq *io_sq,
188         struct ena_com_tx_ctx *ena_tx_ctx)
189 {
190         struct ena_eth_io_tx_meta_desc *meta_desc = NULL;
191         struct ena_com_tx_meta *ena_meta = &ena_tx_ctx->ena_meta;
192
193         meta_desc = get_sq_desc(io_sq);
194         memset(meta_desc, 0x0, sizeof(struct ena_eth_io_tx_meta_desc));
195
196         meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_META_DESC_MASK;
197
198         meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_EXT_VALID_MASK;
199
200         /* bits 0-9 of the mss */
201         meta_desc->word2 |= (ena_meta->mss <<
202                 ENA_ETH_IO_TX_META_DESC_MSS_LO_SHIFT) &
203                 ENA_ETH_IO_TX_META_DESC_MSS_LO_MASK;
204         /* bits 10-13 of the mss */
205         meta_desc->len_ctrl |= ((ena_meta->mss >> 10) <<
206                 ENA_ETH_IO_TX_META_DESC_MSS_HI_PTP_SHIFT) &
207                 ENA_ETH_IO_TX_META_DESC_MSS_HI_PTP_MASK;
208
209         /* Extended meta desc */
210         meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_ETH_META_TYPE_MASK;
211         meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_META_STORE_MASK;
212         meta_desc->len_ctrl |= (io_sq->phase <<
213                 ENA_ETH_IO_TX_META_DESC_PHASE_SHIFT) &
214                 ENA_ETH_IO_TX_META_DESC_PHASE_MASK;
215
216         meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_FIRST_MASK;
217         meta_desc->word2 |= ena_meta->l3_hdr_len &
218                 ENA_ETH_IO_TX_META_DESC_L3_HDR_LEN_MASK;
219         meta_desc->word2 |= (ena_meta->l3_hdr_offset <<
220                 ENA_ETH_IO_TX_META_DESC_L3_HDR_OFF_SHIFT) &
221                 ENA_ETH_IO_TX_META_DESC_L3_HDR_OFF_MASK;
222
223         meta_desc->word2 |= (ena_meta->l4_hdr_len <<
224                 ENA_ETH_IO_TX_META_DESC_L4_HDR_LEN_IN_WORDS_SHIFT) &
225                 ENA_ETH_IO_TX_META_DESC_L4_HDR_LEN_IN_WORDS_MASK;
226
227         meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_META_STORE_MASK;
228
229         /* Cached the meta desc */
230         memcpy(&io_sq->cached_tx_meta, ena_meta,
231                sizeof(struct ena_com_tx_meta));
232
233         ena_com_copy_curr_sq_desc_to_dev(io_sq);
234         ena_com_sq_update_tail(io_sq);
235 }
236
237 static inline void ena_com_rx_set_flags(struct ena_com_rx_ctx *ena_rx_ctx,
238                                         struct ena_eth_io_rx_cdesc_base *cdesc)
239 {
240         ena_rx_ctx->l3_proto = (enum ena_eth_io_l3_proto_index)(cdesc->status &
241                 ENA_ETH_IO_RX_CDESC_BASE_L3_PROTO_IDX_MASK);
242         ena_rx_ctx->l4_proto = (enum ena_eth_io_l4_proto_index)
243                 ((cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_L4_PROTO_IDX_MASK) >>
244                 ENA_ETH_IO_RX_CDESC_BASE_L4_PROTO_IDX_SHIFT);
245         ena_rx_ctx->l3_csum_err =
246                 (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_L3_CSUM_ERR_MASK) >>
247                 ENA_ETH_IO_RX_CDESC_BASE_L3_CSUM_ERR_SHIFT;
248         ena_rx_ctx->l4_csum_err =
249                 (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_L4_CSUM_ERR_MASK) >>
250                 ENA_ETH_IO_RX_CDESC_BASE_L4_CSUM_ERR_SHIFT;
251         ena_rx_ctx->hash = cdesc->hash;
252         ena_rx_ctx->frag =
253                 (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_IPV4_FRAG_MASK) >>
254                 ENA_ETH_IO_RX_CDESC_BASE_IPV4_FRAG_SHIFT;
255
256         ena_trc_dbg("ena_rx_ctx->l3_proto %d ena_rx_ctx->l4_proto %d\nena_rx_ctx->l3_csum_err %d ena_rx_ctx->l4_csum_err %d\nhash frag %d frag: %d cdesc_status: %x\n",
257                     ena_rx_ctx->l3_proto,
258                     ena_rx_ctx->l4_proto,
259                     ena_rx_ctx->l3_csum_err,
260                     ena_rx_ctx->l4_csum_err,
261                     ena_rx_ctx->hash,
262                     ena_rx_ctx->frag,
263                     cdesc->status);
264 }
265
266 /*****************************************************************************/
267 /*****************************     API      **********************************/
268 /*****************************************************************************/
269
270 int ena_com_prepare_tx(struct ena_com_io_sq *io_sq,
271                        struct ena_com_tx_ctx *ena_tx_ctx,
272                        int *nb_hw_desc)
273 {
274         struct ena_eth_io_tx_desc *desc = NULL;
275         struct ena_com_buf *ena_bufs = ena_tx_ctx->ena_bufs;
276         void *push_header = ena_tx_ctx->push_header;
277         u16 header_len = ena_tx_ctx->header_len;
278         u16 num_bufs = ena_tx_ctx->num_bufs;
279         int total_desc, i, rc;
280         bool have_meta;
281         u64 addr_hi;
282
283         ENA_ASSERT(io_sq->direction == ENA_COM_IO_QUEUE_DIRECTION_TX,
284                    "wrong Q type");
285
286         /* num_bufs +1 for potential meta desc */
287         if (ena_com_sq_empty_space(io_sq) < (num_bufs + 1)) {
288                 ena_trc_err("Not enough space in the tx queue\n");
289                 return ENA_COM_NO_MEM;
290         }
291
292         if (unlikely(header_len > io_sq->tx_max_header_size)) {
293                 ena_trc_err("header size is too large %d max header: %d\n",
294                             header_len, io_sq->tx_max_header_size);
295                 return ENA_COM_INVAL;
296         }
297
298         /* start with pushing the header (if needed) */
299         rc = ena_com_write_header(io_sq, push_header, header_len);
300         if (unlikely(rc))
301                 return rc;
302
303         have_meta = ena_tx_ctx->meta_valid && ena_com_meta_desc_changed(io_sq,
304                         ena_tx_ctx);
305         if (have_meta)
306                 ena_com_create_and_store_tx_meta_desc(io_sq, ena_tx_ctx);
307
308         /* If the caller doesn't want send packets */
309         if (unlikely(!num_bufs && !header_len)) {
310                 *nb_hw_desc = have_meta ? 0 : 1;
311                 return 0;
312         }
313
314         desc = get_sq_desc(io_sq);
315         memset(desc, 0x0, sizeof(struct ena_eth_io_tx_desc));
316
317         /* Set first desc when we don't have meta descriptor */
318         if (!have_meta)
319                 desc->len_ctrl |= ENA_ETH_IO_TX_DESC_FIRST_MASK;
320
321         desc->buff_addr_hi_hdr_sz |= (header_len <<
322                 ENA_ETH_IO_TX_DESC_HEADER_LENGTH_SHIFT) &
323                 ENA_ETH_IO_TX_DESC_HEADER_LENGTH_MASK;
324         desc->len_ctrl |= (io_sq->phase << ENA_ETH_IO_TX_DESC_PHASE_SHIFT) &
325                 ENA_ETH_IO_TX_DESC_PHASE_MASK;
326
327         desc->len_ctrl |= ENA_ETH_IO_TX_DESC_COMP_REQ_MASK;
328
329         /* Bits 0-9 */
330         desc->meta_ctrl |= (ena_tx_ctx->req_id <<
331                 ENA_ETH_IO_TX_DESC_REQ_ID_LO_SHIFT) &
332                 ENA_ETH_IO_TX_DESC_REQ_ID_LO_MASK;
333
334         desc->meta_ctrl |= (ena_tx_ctx->df <<
335                 ENA_ETH_IO_TX_DESC_DF_SHIFT) &
336                 ENA_ETH_IO_TX_DESC_DF_MASK;
337
338         /* Bits 10-15 */
339         desc->len_ctrl |= ((ena_tx_ctx->req_id >> 10) <<
340                 ENA_ETH_IO_TX_DESC_REQ_ID_HI_SHIFT) &
341                 ENA_ETH_IO_TX_DESC_REQ_ID_HI_MASK;
342
343         if (ena_tx_ctx->meta_valid) {
344                 desc->meta_ctrl |= (ena_tx_ctx->tso_enable <<
345                         ENA_ETH_IO_TX_DESC_TSO_EN_SHIFT) &
346                         ENA_ETH_IO_TX_DESC_TSO_EN_MASK;
347                 desc->meta_ctrl |= ena_tx_ctx->l3_proto &
348                         ENA_ETH_IO_TX_DESC_L3_PROTO_IDX_MASK;
349                 desc->meta_ctrl |= (ena_tx_ctx->l4_proto <<
350                         ENA_ETH_IO_TX_DESC_L4_PROTO_IDX_SHIFT) &
351                         ENA_ETH_IO_TX_DESC_L4_PROTO_IDX_MASK;
352                 desc->meta_ctrl |= (ena_tx_ctx->l3_csum_enable <<
353                         ENA_ETH_IO_TX_DESC_L3_CSUM_EN_SHIFT) &
354                         ENA_ETH_IO_TX_DESC_L3_CSUM_EN_MASK;
355                 desc->meta_ctrl |= (ena_tx_ctx->l4_csum_enable <<
356                         ENA_ETH_IO_TX_DESC_L4_CSUM_EN_SHIFT) &
357                         ENA_ETH_IO_TX_DESC_L4_CSUM_EN_MASK;
358                 desc->meta_ctrl |= (ena_tx_ctx->l4_csum_partial <<
359                         ENA_ETH_IO_TX_DESC_L4_CSUM_PARTIAL_SHIFT) &
360                         ENA_ETH_IO_TX_DESC_L4_CSUM_PARTIAL_MASK;
361         }
362
363         for (i = 0; i < num_bufs; i++) {
364                 /* The first desc share the same desc as the header */
365                 if (likely(i != 0)) {
366                         ena_com_copy_curr_sq_desc_to_dev(io_sq);
367                         ena_com_sq_update_tail(io_sq);
368
369                         desc = get_sq_desc(io_sq);
370                         memset(desc, 0x0, sizeof(struct ena_eth_io_tx_desc));
371
372                         desc->len_ctrl |= (io_sq->phase <<
373                                 ENA_ETH_IO_TX_DESC_PHASE_SHIFT) &
374                                 ENA_ETH_IO_TX_DESC_PHASE_MASK;
375                 }
376
377                 desc->len_ctrl |= ena_bufs->len &
378                         ENA_ETH_IO_TX_DESC_LENGTH_MASK;
379
380                 addr_hi = ((ena_bufs->paddr &
381                         GENMASK_ULL(io_sq->dma_addr_bits - 1, 32)) >> 32);
382
383                 desc->buff_addr_lo = (u32)ena_bufs->paddr;
384                 desc->buff_addr_hi_hdr_sz |= addr_hi &
385                         ENA_ETH_IO_TX_DESC_ADDR_HI_MASK;
386                 ena_bufs++;
387         }
388
389         /* set the last desc indicator */
390         desc->len_ctrl |= ENA_ETH_IO_TX_DESC_LAST_MASK;
391
392         ena_com_copy_curr_sq_desc_to_dev(io_sq);
393
394         ena_com_sq_update_tail(io_sq);
395
396         total_desc = ENA_MAX16(num_bufs, 1);
397         total_desc += have_meta ? 1 : 0;
398
399         *nb_hw_desc = total_desc;
400         return 0;
401 }
402
403 int ena_com_rx_pkt(struct ena_com_io_cq *io_cq,
404                    struct ena_com_io_sq *io_sq,
405                    struct ena_com_rx_ctx *ena_rx_ctx)
406 {
407         struct ena_com_rx_buf_info *ena_buf = &ena_rx_ctx->ena_bufs[0];
408         struct ena_eth_io_rx_cdesc_base *cdesc = NULL;
409         u16 cdesc_idx = 0;
410         u16 nb_hw_desc;
411         u16 i;
412
413         ENA_ASSERT(io_cq->direction == ENA_COM_IO_QUEUE_DIRECTION_RX,
414                    "wrong Q type");
415
416         nb_hw_desc = ena_com_cdesc_rx_pkt_get(io_cq, &cdesc_idx);
417         if (nb_hw_desc == 0) {
418                 ena_rx_ctx->descs = nb_hw_desc;
419                 return 0;
420         }
421
422         ena_trc_dbg("fetch rx packet: queue %d completed desc: %d\n",
423                     io_cq->qid, nb_hw_desc);
424
425         if (unlikely(nb_hw_desc > ena_rx_ctx->max_bufs)) {
426                 ena_trc_err("Too many RX cdescs (%d) > MAX(%d)\n",
427                             nb_hw_desc, ena_rx_ctx->max_bufs);
428                 return ENA_COM_NO_SPACE;
429         }
430
431         for (i = 0; i < nb_hw_desc; i++) {
432                 cdesc = ena_com_rx_cdesc_idx_to_ptr(io_cq, cdesc_idx + i);
433
434                 ena_buf->len = cdesc->length;
435                 ena_buf->req_id = cdesc->req_id;
436                 ena_buf++;
437         }
438
439         /* Update SQ head ptr */
440         io_sq->next_to_comp += nb_hw_desc;
441
442         ena_trc_dbg("[%s][QID#%d] Updating SQ head to: %d\n", __func__,
443                     io_sq->qid, io_sq->next_to_comp);
444
445         /* Get rx flags from the last pkt */
446         ena_com_rx_set_flags(ena_rx_ctx, cdesc);
447
448         ena_rx_ctx->descs = nb_hw_desc;
449         return 0;
450 }
451
452 int ena_com_add_single_rx_desc(struct ena_com_io_sq *io_sq,
453                                struct ena_com_buf *ena_buf,
454                                u16 req_id)
455 {
456         struct ena_eth_io_rx_desc *desc;
457
458         ENA_ASSERT(io_sq->direction == ENA_COM_IO_QUEUE_DIRECTION_RX,
459                    "wrong Q type");
460
461         if (unlikely(ena_com_sq_empty_space(io_sq) == 0))
462                 return ENA_COM_NO_SPACE;
463
464         desc = get_sq_desc(io_sq);
465         memset(desc, 0x0, sizeof(struct ena_eth_io_rx_desc));
466
467         desc->length = ena_buf->len;
468
469         desc->ctrl |= ENA_ETH_IO_RX_DESC_FIRST_MASK;
470         desc->ctrl |= ENA_ETH_IO_RX_DESC_LAST_MASK;
471         desc->ctrl |= io_sq->phase & ENA_ETH_IO_RX_DESC_PHASE_MASK;
472         desc->ctrl |= ENA_ETH_IO_RX_DESC_COMP_REQ_MASK;
473
474         desc->req_id = req_id;
475
476         desc->buff_addr_lo = (u32)ena_buf->paddr;
477         desc->buff_addr_hi =
478                 ((ena_buf->paddr &
479                   GENMASK_ULL(io_sq->dma_addr_bits - 1, 32)) >> 32);
480
481         ena_com_sq_update_tail(io_sq);
482
483         return 0;
484 }
485
486 int ena_com_tx_comp_req_id_get(struct ena_com_io_cq *io_cq, u16 *req_id)
487 {
488         u8 expected_phase, cdesc_phase;
489         struct ena_eth_io_tx_cdesc *cdesc;
490         u16 masked_head;
491
492         masked_head = io_cq->head & (io_cq->q_depth - 1);
493         expected_phase = io_cq->phase;
494
495         cdesc = (struct ena_eth_io_tx_cdesc *)
496                 ((unsigned char *)io_cq->cdesc_addr.virt_addr
497                 + (masked_head * io_cq->cdesc_entry_size_in_bytes));
498
499         /* When the current completion descriptor phase isn't the same as the
500          * expected, it mean that the device still didn't update
501          * this completion.
502          */
503         cdesc_phase = cdesc->flags & ENA_ETH_IO_TX_CDESC_PHASE_MASK;
504         if (cdesc_phase != expected_phase)
505                 return ENA_COM_TRY_AGAIN;
506
507         ena_com_cq_inc_head(io_cq);
508
509         *req_id = cdesc->req_id;
510
511         return 0;
512 }