+ adapter->max_tx_sgl_size);
+
+ return 0;
+}
+
+static inline void ena_init_rx_mbuf(struct rte_mbuf *mbuf, uint16_t len)
+{
+ mbuf->data_len = len;
+ mbuf->data_off = RTE_PKTMBUF_HEADROOM;
+ mbuf->refcnt = 1;
+ mbuf->next = NULL;
+}
+
+static struct rte_mbuf *ena_rx_mbuf(struct ena_ring *rx_ring,
+ struct ena_com_rx_buf_info *ena_bufs,
+ uint32_t descs,
+ uint16_t *next_to_clean,
+ uint8_t offset)
+{
+ struct rte_mbuf *mbuf;
+ struct rte_mbuf *mbuf_head;
+ struct ena_rx_buffer *rx_info;
+ int rc;
+ uint16_t ntc, len, req_id, buf = 0;
+
+ if (unlikely(descs == 0))
+ return NULL;
+
+ ntc = *next_to_clean;
+
+ len = ena_bufs[buf].len;
+ req_id = ena_bufs[buf].req_id;
+
+ rx_info = &rx_ring->rx_buffer_info[req_id];
+
+ mbuf = rx_info->mbuf;
+ RTE_ASSERT(mbuf != NULL);
+
+ ena_init_rx_mbuf(mbuf, len);
+
+ /* Fill the mbuf head with the data specific for 1st segment. */
+ mbuf_head = mbuf;
+ mbuf_head->nb_segs = descs;
+ mbuf_head->port = rx_ring->port_id;
+ mbuf_head->pkt_len = len;
+ mbuf_head->data_off += offset;
+
+ rx_info->mbuf = NULL;
+ rx_ring->empty_rx_reqs[ntc] = req_id;
+ ntc = ENA_IDX_NEXT_MASKED(ntc, rx_ring->size_mask);
+
+ while (--descs) {
+ ++buf;
+ len = ena_bufs[buf].len;
+ req_id = ena_bufs[buf].req_id;
+
+ rx_info = &rx_ring->rx_buffer_info[req_id];
+ RTE_ASSERT(rx_info->mbuf != NULL);
+
+ if (unlikely(len == 0)) {
+ /*
+ * Some devices can pass descriptor with the length 0.
+ * To avoid confusion, the PMD is simply putting the
+ * descriptor back, as it was never used. We'll avoid
+ * mbuf allocation that way.
+ */
+ rc = ena_add_single_rx_desc(rx_ring->ena_com_io_sq,
+ rx_info->mbuf, req_id);
+ if (unlikely(rc != 0)) {
+ /* Free the mbuf in case of an error. */
+ rte_mbuf_raw_free(rx_info->mbuf);
+ } else {
+ /*
+ * If there was no error, just exit the loop as
+ * 0 length descriptor is always the last one.
+ */
+ break;
+ }
+ } else {
+ /* Create an mbuf chain. */
+ mbuf->next = rx_info->mbuf;
+ mbuf = mbuf->next;
+
+ ena_init_rx_mbuf(mbuf, len);
+ mbuf_head->pkt_len += len;
+ }
+
+ /*
+ * Mark the descriptor as depleted and perform necessary
+ * cleanup.
+ * This code will execute in two cases:
+ * 1. Descriptor len was greater than 0 - normal situation.
+ * 2. Descriptor len was 0 and we failed to add the descriptor
+ * to the device. In that situation, we should try to add
+ * the mbuf again in the populate routine and mark the
+ * descriptor as used up by the device.
+ */
+ rx_info->mbuf = NULL;
+ rx_ring->empty_rx_reqs[ntc] = req_id;
+ ntc = ENA_IDX_NEXT_MASKED(ntc, rx_ring->size_mask);
+ }
+
+ *next_to_clean = ntc;
+
+ return mbuf_head;