ena_eth_com.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. /*
  2. * Copyright 2015 Amazon.com, Inc. or its affiliates.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include "ena_eth_com.h"
  33. static inline struct ena_eth_io_rx_cdesc_base *ena_com_get_next_rx_cdesc(
  34. struct ena_com_io_cq *io_cq)
  35. {
  36. struct ena_eth_io_rx_cdesc_base *cdesc;
  37. u16 expected_phase, head_masked;
  38. u16 desc_phase;
  39. head_masked = io_cq->head & (io_cq->q_depth - 1);
  40. expected_phase = io_cq->phase;
  41. cdesc = (struct ena_eth_io_rx_cdesc_base *)(io_cq->cdesc_addr.virt_addr
  42. + (head_masked * io_cq->cdesc_entry_size_in_bytes));
  43. desc_phase = (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_PHASE_MASK) >>
  44. ENA_ETH_IO_RX_CDESC_BASE_PHASE_SHIFT;
  45. if (desc_phase != expected_phase)
  46. return NULL;
  47. return cdesc;
  48. }
  49. static inline void ena_com_cq_inc_head(struct ena_com_io_cq *io_cq)
  50. {
  51. io_cq->head++;
  52. /* Switch phase bit in case of wrap around */
  53. if (unlikely((io_cq->head & (io_cq->q_depth - 1)) == 0))
  54. io_cq->phase ^= 1;
  55. }
  56. static inline void *get_sq_desc(struct ena_com_io_sq *io_sq)
  57. {
  58. u16 tail_masked;
  59. u32 offset;
  60. tail_masked = io_sq->tail & (io_sq->q_depth - 1);
  61. offset = tail_masked * io_sq->desc_entry_size;
  62. return (void *)((uintptr_t)io_sq->desc_addr.virt_addr + offset);
  63. }
  64. static inline void ena_com_copy_curr_sq_desc_to_dev(struct ena_com_io_sq *io_sq)
  65. {
  66. u16 tail_masked = io_sq->tail & (io_sq->q_depth - 1);
  67. u32 offset = tail_masked * io_sq->desc_entry_size;
  68. /* In case this queue isn't a LLQ */
  69. if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_HOST)
  70. return;
  71. memcpy_toio(io_sq->desc_addr.pbuf_dev_addr + offset,
  72. io_sq->desc_addr.virt_addr + offset,
  73. io_sq->desc_entry_size);
  74. }
  75. static inline void ena_com_sq_update_tail(struct ena_com_io_sq *io_sq)
  76. {
  77. io_sq->tail++;
  78. /* Switch phase bit in case of wrap around */
  79. if (unlikely((io_sq->tail & (io_sq->q_depth - 1)) == 0))
  80. io_sq->phase ^= 1;
  81. }
  82. static inline int ena_com_write_header(struct ena_com_io_sq *io_sq,
  83. u8 *head_src, u16 header_len)
  84. {
  85. u16 tail_masked = io_sq->tail & (io_sq->q_depth - 1);
  86. u8 __iomem *dev_head_addr =
  87. io_sq->header_addr + (tail_masked * io_sq->tx_max_header_size);
  88. if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_HOST)
  89. return 0;
  90. if (unlikely(!io_sq->header_addr)) {
  91. pr_err("Push buffer header ptr is NULL\n");
  92. return -EINVAL;
  93. }
  94. memcpy_toio(dev_head_addr, head_src, header_len);
  95. return 0;
  96. }
  97. static inline struct ena_eth_io_rx_cdesc_base *
  98. ena_com_rx_cdesc_idx_to_ptr(struct ena_com_io_cq *io_cq, u16 idx)
  99. {
  100. idx &= (io_cq->q_depth - 1);
  101. return (struct ena_eth_io_rx_cdesc_base *)
  102. ((uintptr_t)io_cq->cdesc_addr.virt_addr +
  103. idx * io_cq->cdesc_entry_size_in_bytes);
  104. }
  105. static inline u16 ena_com_cdesc_rx_pkt_get(struct ena_com_io_cq *io_cq,
  106. u16 *first_cdesc_idx)
  107. {
  108. struct ena_eth_io_rx_cdesc_base *cdesc;
  109. u16 count = 0, head_masked;
  110. u32 last = 0;
  111. do {
  112. cdesc = ena_com_get_next_rx_cdesc(io_cq);
  113. if (!cdesc)
  114. break;
  115. ena_com_cq_inc_head(io_cq);
  116. count++;
  117. last = (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_LAST_MASK) >>
  118. ENA_ETH_IO_RX_CDESC_BASE_LAST_SHIFT;
  119. } while (!last);
  120. if (last) {
  121. *first_cdesc_idx = io_cq->cur_rx_pkt_cdesc_start_idx;
  122. count += io_cq->cur_rx_pkt_cdesc_count;
  123. head_masked = io_cq->head & (io_cq->q_depth - 1);
  124. io_cq->cur_rx_pkt_cdesc_count = 0;
  125. io_cq->cur_rx_pkt_cdesc_start_idx = head_masked;
  126. pr_debug("ena q_id: %d packets were completed. first desc idx %u descs# %d\n",
  127. io_cq->qid, *first_cdesc_idx, count);
  128. } else {
  129. io_cq->cur_rx_pkt_cdesc_count += count;
  130. count = 0;
  131. }
  132. return count;
  133. }
  134. static inline bool ena_com_meta_desc_changed(struct ena_com_io_sq *io_sq,
  135. struct ena_com_tx_ctx *ena_tx_ctx)
  136. {
  137. int rc;
  138. if (ena_tx_ctx->meta_valid) {
  139. rc = memcmp(&io_sq->cached_tx_meta,
  140. &ena_tx_ctx->ena_meta,
  141. sizeof(struct ena_com_tx_meta));
  142. if (unlikely(rc != 0))
  143. return true;
  144. }
  145. return false;
  146. }
  147. static inline void ena_com_create_and_store_tx_meta_desc(struct ena_com_io_sq *io_sq,
  148. struct ena_com_tx_ctx *ena_tx_ctx)
  149. {
  150. struct ena_eth_io_tx_meta_desc *meta_desc = NULL;
  151. struct ena_com_tx_meta *ena_meta = &ena_tx_ctx->ena_meta;
  152. meta_desc = get_sq_desc(io_sq);
  153. memset(meta_desc, 0x0, sizeof(struct ena_eth_io_tx_meta_desc));
  154. meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_META_DESC_MASK;
  155. meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_EXT_VALID_MASK;
  156. /* bits 0-9 of the mss */
  157. meta_desc->word2 |= (ena_meta->mss <<
  158. ENA_ETH_IO_TX_META_DESC_MSS_LO_SHIFT) &
  159. ENA_ETH_IO_TX_META_DESC_MSS_LO_MASK;
  160. /* bits 10-13 of the mss */
  161. meta_desc->len_ctrl |= ((ena_meta->mss >> 10) <<
  162. ENA_ETH_IO_TX_META_DESC_MSS_HI_SHIFT) &
  163. ENA_ETH_IO_TX_META_DESC_MSS_HI_MASK;
  164. /* Extended meta desc */
  165. meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_ETH_META_TYPE_MASK;
  166. meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_META_STORE_MASK;
  167. meta_desc->len_ctrl |= (io_sq->phase <<
  168. ENA_ETH_IO_TX_META_DESC_PHASE_SHIFT) &
  169. ENA_ETH_IO_TX_META_DESC_PHASE_MASK;
  170. meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_FIRST_MASK;
  171. meta_desc->word2 |= ena_meta->l3_hdr_len &
  172. ENA_ETH_IO_TX_META_DESC_L3_HDR_LEN_MASK;
  173. meta_desc->word2 |= (ena_meta->l3_hdr_offset <<
  174. ENA_ETH_IO_TX_META_DESC_L3_HDR_OFF_SHIFT) &
  175. ENA_ETH_IO_TX_META_DESC_L3_HDR_OFF_MASK;
  176. meta_desc->word2 |= (ena_meta->l4_hdr_len <<
  177. ENA_ETH_IO_TX_META_DESC_L4_HDR_LEN_IN_WORDS_SHIFT) &
  178. ENA_ETH_IO_TX_META_DESC_L4_HDR_LEN_IN_WORDS_MASK;
  179. meta_desc->len_ctrl |= ENA_ETH_IO_TX_META_DESC_META_STORE_MASK;
  180. /* Cached the meta desc */
  181. memcpy(&io_sq->cached_tx_meta, ena_meta,
  182. sizeof(struct ena_com_tx_meta));
  183. ena_com_copy_curr_sq_desc_to_dev(io_sq);
  184. ena_com_sq_update_tail(io_sq);
  185. }
  186. static inline void ena_com_rx_set_flags(struct ena_com_rx_ctx *ena_rx_ctx,
  187. struct ena_eth_io_rx_cdesc_base *cdesc)
  188. {
  189. ena_rx_ctx->l3_proto = cdesc->status &
  190. ENA_ETH_IO_RX_CDESC_BASE_L3_PROTO_IDX_MASK;
  191. ena_rx_ctx->l4_proto =
  192. (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_L4_PROTO_IDX_MASK) >>
  193. ENA_ETH_IO_RX_CDESC_BASE_L4_PROTO_IDX_SHIFT;
  194. ena_rx_ctx->l3_csum_err =
  195. (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_L3_CSUM_ERR_MASK) >>
  196. ENA_ETH_IO_RX_CDESC_BASE_L3_CSUM_ERR_SHIFT;
  197. ena_rx_ctx->l4_csum_err =
  198. (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_L4_CSUM_ERR_MASK) >>
  199. ENA_ETH_IO_RX_CDESC_BASE_L4_CSUM_ERR_SHIFT;
  200. ena_rx_ctx->hash = cdesc->hash;
  201. ena_rx_ctx->frag =
  202. (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_IPV4_FRAG_MASK) >>
  203. ENA_ETH_IO_RX_CDESC_BASE_IPV4_FRAG_SHIFT;
  204. pr_debug("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",
  205. ena_rx_ctx->l3_proto, ena_rx_ctx->l4_proto,
  206. ena_rx_ctx->l3_csum_err, ena_rx_ctx->l4_csum_err,
  207. ena_rx_ctx->hash, ena_rx_ctx->frag, cdesc->status);
  208. }
  209. /*****************************************************************************/
  210. /***************************** API **********************************/
  211. /*****************************************************************************/
  212. int ena_com_prepare_tx(struct ena_com_io_sq *io_sq,
  213. struct ena_com_tx_ctx *ena_tx_ctx,
  214. int *nb_hw_desc)
  215. {
  216. struct ena_eth_io_tx_desc *desc = NULL;
  217. struct ena_com_buf *ena_bufs = ena_tx_ctx->ena_bufs;
  218. void *push_header = ena_tx_ctx->push_header;
  219. u16 header_len = ena_tx_ctx->header_len;
  220. u16 num_bufs = ena_tx_ctx->num_bufs;
  221. int total_desc, i, rc;
  222. bool have_meta;
  223. u64 addr_hi;
  224. WARN(io_sq->direction != ENA_COM_IO_QUEUE_DIRECTION_TX, "wrong Q type");
  225. /* num_bufs +1 for potential meta desc */
  226. if (ena_com_sq_empty_space(io_sq) < (num_bufs + 1)) {
  227. pr_err("Not enough space in the tx queue\n");
  228. return -ENOMEM;
  229. }
  230. if (unlikely(header_len > io_sq->tx_max_header_size)) {
  231. pr_err("header size is too large %d max header: %d\n",
  232. header_len, io_sq->tx_max_header_size);
  233. return -EINVAL;
  234. }
  235. /* start with pushing the header (if needed) */
  236. rc = ena_com_write_header(io_sq, push_header, header_len);
  237. if (unlikely(rc))
  238. return rc;
  239. have_meta = ena_tx_ctx->meta_valid && ena_com_meta_desc_changed(io_sq,
  240. ena_tx_ctx);
  241. if (have_meta)
  242. ena_com_create_and_store_tx_meta_desc(io_sq, ena_tx_ctx);
  243. /* If the caller doesn't want send packets */
  244. if (unlikely(!num_bufs && !header_len)) {
  245. *nb_hw_desc = have_meta ? 0 : 1;
  246. return 0;
  247. }
  248. desc = get_sq_desc(io_sq);
  249. memset(desc, 0x0, sizeof(struct ena_eth_io_tx_desc));
  250. /* Set first desc when we don't have meta descriptor */
  251. if (!have_meta)
  252. desc->len_ctrl |= ENA_ETH_IO_TX_DESC_FIRST_MASK;
  253. desc->buff_addr_hi_hdr_sz |= (header_len <<
  254. ENA_ETH_IO_TX_DESC_HEADER_LENGTH_SHIFT) &
  255. ENA_ETH_IO_TX_DESC_HEADER_LENGTH_MASK;
  256. desc->len_ctrl |= (io_sq->phase << ENA_ETH_IO_TX_DESC_PHASE_SHIFT) &
  257. ENA_ETH_IO_TX_DESC_PHASE_MASK;
  258. desc->len_ctrl |= ENA_ETH_IO_TX_DESC_COMP_REQ_MASK;
  259. /* Bits 0-9 */
  260. desc->meta_ctrl |= (ena_tx_ctx->req_id <<
  261. ENA_ETH_IO_TX_DESC_REQ_ID_LO_SHIFT) &
  262. ENA_ETH_IO_TX_DESC_REQ_ID_LO_MASK;
  263. desc->meta_ctrl |= (ena_tx_ctx->df <<
  264. ENA_ETH_IO_TX_DESC_DF_SHIFT) &
  265. ENA_ETH_IO_TX_DESC_DF_MASK;
  266. /* Bits 10-15 */
  267. desc->len_ctrl |= ((ena_tx_ctx->req_id >> 10) <<
  268. ENA_ETH_IO_TX_DESC_REQ_ID_HI_SHIFT) &
  269. ENA_ETH_IO_TX_DESC_REQ_ID_HI_MASK;
  270. if (ena_tx_ctx->meta_valid) {
  271. desc->meta_ctrl |= (ena_tx_ctx->tso_enable <<
  272. ENA_ETH_IO_TX_DESC_TSO_EN_SHIFT) &
  273. ENA_ETH_IO_TX_DESC_TSO_EN_MASK;
  274. desc->meta_ctrl |= ena_tx_ctx->l3_proto &
  275. ENA_ETH_IO_TX_DESC_L3_PROTO_IDX_MASK;
  276. desc->meta_ctrl |= (ena_tx_ctx->l4_proto <<
  277. ENA_ETH_IO_TX_DESC_L4_PROTO_IDX_SHIFT) &
  278. ENA_ETH_IO_TX_DESC_L4_PROTO_IDX_MASK;
  279. desc->meta_ctrl |= (ena_tx_ctx->l3_csum_enable <<
  280. ENA_ETH_IO_TX_DESC_L3_CSUM_EN_SHIFT) &
  281. ENA_ETH_IO_TX_DESC_L3_CSUM_EN_MASK;
  282. desc->meta_ctrl |= (ena_tx_ctx->l4_csum_enable <<
  283. ENA_ETH_IO_TX_DESC_L4_CSUM_EN_SHIFT) &
  284. ENA_ETH_IO_TX_DESC_L4_CSUM_EN_MASK;
  285. desc->meta_ctrl |= (ena_tx_ctx->l4_csum_partial <<
  286. ENA_ETH_IO_TX_DESC_L4_CSUM_PARTIAL_SHIFT) &
  287. ENA_ETH_IO_TX_DESC_L4_CSUM_PARTIAL_MASK;
  288. }
  289. for (i = 0; i < num_bufs; i++) {
  290. /* The first desc share the same desc as the header */
  291. if (likely(i != 0)) {
  292. ena_com_copy_curr_sq_desc_to_dev(io_sq);
  293. ena_com_sq_update_tail(io_sq);
  294. desc = get_sq_desc(io_sq);
  295. memset(desc, 0x0, sizeof(struct ena_eth_io_tx_desc));
  296. desc->len_ctrl |= (io_sq->phase <<
  297. ENA_ETH_IO_TX_DESC_PHASE_SHIFT) &
  298. ENA_ETH_IO_TX_DESC_PHASE_MASK;
  299. }
  300. desc->len_ctrl |= ena_bufs->len &
  301. ENA_ETH_IO_TX_DESC_LENGTH_MASK;
  302. addr_hi = ((ena_bufs->paddr &
  303. GENMASK_ULL(io_sq->dma_addr_bits - 1, 32)) >> 32);
  304. desc->buff_addr_lo = (u32)ena_bufs->paddr;
  305. desc->buff_addr_hi_hdr_sz |= addr_hi &
  306. ENA_ETH_IO_TX_DESC_ADDR_HI_MASK;
  307. ena_bufs++;
  308. }
  309. /* set the last desc indicator */
  310. desc->len_ctrl |= ENA_ETH_IO_TX_DESC_LAST_MASK;
  311. ena_com_copy_curr_sq_desc_to_dev(io_sq);
  312. ena_com_sq_update_tail(io_sq);
  313. total_desc = max_t(u16, num_bufs, 1);
  314. total_desc += have_meta ? 1 : 0;
  315. *nb_hw_desc = total_desc;
  316. return 0;
  317. }
  318. int ena_com_rx_pkt(struct ena_com_io_cq *io_cq,
  319. struct ena_com_io_sq *io_sq,
  320. struct ena_com_rx_ctx *ena_rx_ctx)
  321. {
  322. struct ena_com_rx_buf_info *ena_buf = &ena_rx_ctx->ena_bufs[0];
  323. struct ena_eth_io_rx_cdesc_base *cdesc = NULL;
  324. u16 cdesc_idx = 0;
  325. u16 nb_hw_desc;
  326. u16 i;
  327. WARN(io_cq->direction != ENA_COM_IO_QUEUE_DIRECTION_RX, "wrong Q type");
  328. nb_hw_desc = ena_com_cdesc_rx_pkt_get(io_cq, &cdesc_idx);
  329. if (nb_hw_desc == 0) {
  330. ena_rx_ctx->descs = nb_hw_desc;
  331. return 0;
  332. }
  333. pr_debug("fetch rx packet: queue %d completed desc: %d\n", io_cq->qid,
  334. nb_hw_desc);
  335. if (unlikely(nb_hw_desc > ena_rx_ctx->max_bufs)) {
  336. pr_err("Too many RX cdescs (%d) > MAX(%d)\n", nb_hw_desc,
  337. ena_rx_ctx->max_bufs);
  338. return -ENOSPC;
  339. }
  340. for (i = 0; i < nb_hw_desc; i++) {
  341. cdesc = ena_com_rx_cdesc_idx_to_ptr(io_cq, cdesc_idx + i);
  342. ena_buf->len = cdesc->length;
  343. ena_buf->req_id = cdesc->req_id;
  344. ena_buf++;
  345. }
  346. /* Update SQ head ptr */
  347. io_sq->next_to_comp += nb_hw_desc;
  348. pr_debug("[%s][QID#%d] Updating SQ head to: %d\n", __func__, io_sq->qid,
  349. io_sq->next_to_comp);
  350. /* Get rx flags from the last pkt */
  351. ena_com_rx_set_flags(ena_rx_ctx, cdesc);
  352. ena_rx_ctx->descs = nb_hw_desc;
  353. return 0;
  354. }
  355. int ena_com_add_single_rx_desc(struct ena_com_io_sq *io_sq,
  356. struct ena_com_buf *ena_buf,
  357. u16 req_id)
  358. {
  359. struct ena_eth_io_rx_desc *desc;
  360. WARN(io_sq->direction != ENA_COM_IO_QUEUE_DIRECTION_RX, "wrong Q type");
  361. if (unlikely(ena_com_sq_empty_space(io_sq) == 0))
  362. return -ENOSPC;
  363. desc = get_sq_desc(io_sq);
  364. memset(desc, 0x0, sizeof(struct ena_eth_io_rx_desc));
  365. desc->length = ena_buf->len;
  366. desc->ctrl |= ENA_ETH_IO_RX_DESC_FIRST_MASK;
  367. desc->ctrl |= ENA_ETH_IO_RX_DESC_LAST_MASK;
  368. desc->ctrl |= io_sq->phase & ENA_ETH_IO_RX_DESC_PHASE_MASK;
  369. desc->ctrl |= ENA_ETH_IO_RX_DESC_COMP_REQ_MASK;
  370. desc->req_id = req_id;
  371. desc->buff_addr_lo = (u32)ena_buf->paddr;
  372. desc->buff_addr_hi =
  373. ((ena_buf->paddr & GENMASK_ULL(io_sq->dma_addr_bits - 1, 32)) >> 32);
  374. ena_com_sq_update_tail(io_sq);
  375. return 0;
  376. }
  377. int ena_com_tx_comp_req_id_get(struct ena_com_io_cq *io_cq, u16 *req_id)
  378. {
  379. u8 expected_phase, cdesc_phase;
  380. struct ena_eth_io_tx_cdesc *cdesc;
  381. u16 masked_head;
  382. masked_head = io_cq->head & (io_cq->q_depth - 1);
  383. expected_phase = io_cq->phase;
  384. cdesc = (struct ena_eth_io_tx_cdesc *)
  385. ((uintptr_t)io_cq->cdesc_addr.virt_addr +
  386. (masked_head * io_cq->cdesc_entry_size_in_bytes));
  387. /* When the current completion descriptor phase isn't the same as the
  388. * expected, it mean that the device still didn't update
  389. * this completion.
  390. */
  391. cdesc_phase = cdesc->flags & ENA_ETH_IO_TX_CDESC_PHASE_MASK;
  392. if (cdesc_phase != expected_phase)
  393. return -EAGAIN;
  394. ena_com_cq_inc_head(io_cq);
  395. *req_id = cdesc->req_id;
  396. return 0;
  397. }