4 * Copyright (c) 2015-2016 Amazon.com, Inc. or its affiliates.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
34 #include <rte_ether.h>
35 #include <rte_ethdev.h>
37 #include <rte_atomic.h>
39 #include <rte_errno.h>
41 #include "ena_ethdev.h"
43 #include "ena_platform.h"
45 #include "ena_eth_com.h"
47 #include <ena_common_defs.h>
48 #include <ena_regs_defs.h>
49 #include <ena_admin_defs.h>
50 #include <ena_eth_io_defs.h>
52 #define ENA_IO_TXQ_IDX(q) (2 * (q))
53 #define ENA_IO_RXQ_IDX(q) (2 * (q) + 1)
54 /*reverse version of ENA_IO_RXQ_IDX*/
55 #define ENA_IO_RXQ_IDX_REV(q) ((q - 1) / 2)
57 /* While processing submitted and completed descriptors (rx and tx path
58 * respectively) in a loop it is desired to:
59 * - perform batch submissions while populating sumbissmion queue
60 * - avoid blocking transmission of other packets during cleanup phase
61 * Hence the utilization ratio of 1/8 of a queue size.
63 #define ENA_RING_DESCS_RATIO(ring_size) (ring_size / 8)
65 #define __MERGE_64B_H_L(h, l) (((uint64_t)h << 32) | l)
66 #define TEST_BIT(val, bit_shift) (val & (1UL << bit_shift))
68 #define GET_L4_HDR_LEN(mbuf) \
69 ((rte_pktmbuf_mtod_offset(mbuf, struct tcp_hdr *, \
70 mbuf->l3_len + mbuf->l2_len)->data_off) >> 4)
72 #define ENA_RX_RSS_TABLE_LOG_SIZE 7
73 #define ENA_RX_RSS_TABLE_SIZE (1 << ENA_RX_RSS_TABLE_LOG_SIZE)
74 #define ENA_HASH_KEY_SIZE 40
76 /** Vendor ID used by Amazon devices */
77 #define PCI_VENDOR_ID_AMAZON 0x1D0F
79 #define PCI_DEVICE_ID_ENA_VF 0xEC20
80 #define PCI_DEVICE_ID_ENA_LLQ_VF 0xEC21
82 static struct rte_pci_id pci_id_ena_map[] = {
83 #define RTE_PCI_DEV_ID_DECL_ENA(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
85 RTE_PCI_DEV_ID_DECL_ENA(PCI_VENDOR_ID_AMAZON, PCI_DEVICE_ID_ENA_VF)
86 RTE_PCI_DEV_ID_DECL_ENA(PCI_VENDOR_ID_AMAZON, PCI_DEVICE_ID_ENA_LLQ_VF)
90 static int ena_device_init(struct ena_com_dev *ena_dev,
91 struct ena_com_dev_get_features_ctx *get_feat_ctx);
92 static int ena_dev_configure(struct rte_eth_dev *dev);
93 static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
95 static int ena_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
96 uint16_t nb_desc, unsigned int socket_id,
97 const struct rte_eth_txconf *tx_conf);
98 static int ena_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
99 uint16_t nb_desc, unsigned int socket_id,
100 const struct rte_eth_rxconf *rx_conf,
101 struct rte_mempool *mp);
102 static uint16_t eth_ena_recv_pkts(void *rx_queue,
103 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
104 static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count);
105 static void ena_init_rings(struct ena_adapter *adapter);
106 static int ena_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
107 static int ena_start(struct rte_eth_dev *dev);
108 static void ena_close(struct rte_eth_dev *dev);
109 static void ena_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
110 static void ena_rx_queue_release_all(struct rte_eth_dev *dev);
111 static void ena_tx_queue_release_all(struct rte_eth_dev *dev);
112 static void ena_rx_queue_release(void *queue);
113 static void ena_tx_queue_release(void *queue);
114 static void ena_rx_queue_release_bufs(struct ena_ring *ring);
115 static void ena_tx_queue_release_bufs(struct ena_ring *ring);
116 static int ena_link_update(struct rte_eth_dev *dev,
117 __rte_unused int wait_to_complete);
118 static int ena_queue_restart(struct ena_ring *ring);
119 static int ena_queue_restart_all(struct rte_eth_dev *dev,
120 enum ena_ring_type ring_type);
121 static void ena_stats_restart(struct rte_eth_dev *dev);
122 static void ena_infos_get(__rte_unused struct rte_eth_dev *dev,
123 struct rte_eth_dev_info *dev_info);
124 static int ena_rss_reta_update(struct rte_eth_dev *dev,
125 struct rte_eth_rss_reta_entry64 *reta_conf,
127 static int ena_rss_reta_query(struct rte_eth_dev *dev,
128 struct rte_eth_rss_reta_entry64 *reta_conf,
131 static struct eth_dev_ops ena_dev_ops = {
132 .dev_configure = ena_dev_configure,
133 .dev_infos_get = ena_infos_get,
134 .rx_queue_setup = ena_rx_queue_setup,
135 .tx_queue_setup = ena_tx_queue_setup,
136 .dev_start = ena_start,
137 .link_update = ena_link_update,
138 .stats_get = ena_stats_get,
139 .mtu_set = ena_mtu_set,
140 .rx_queue_release = ena_rx_queue_release,
141 .tx_queue_release = ena_tx_queue_release,
142 .dev_close = ena_close,
143 .reta_update = ena_rss_reta_update,
144 .reta_query = ena_rss_reta_query,
147 static inline void ena_rx_mbuf_prepare(struct rte_mbuf *mbuf,
148 struct ena_com_rx_ctx *ena_rx_ctx)
150 uint64_t ol_flags = 0;
152 if (ena_rx_ctx->l4_proto == ENA_ETH_IO_L4_PROTO_TCP)
153 ol_flags |= PKT_TX_TCP_CKSUM;
154 else if (ena_rx_ctx->l4_proto == ENA_ETH_IO_L4_PROTO_UDP)
155 ol_flags |= PKT_TX_UDP_CKSUM;
157 if (ena_rx_ctx->l3_proto == ENA_ETH_IO_L3_PROTO_IPV4)
158 ol_flags |= PKT_TX_IPV4;
159 else if (ena_rx_ctx->l3_proto == ENA_ETH_IO_L3_PROTO_IPV6)
160 ol_flags |= PKT_TX_IPV6;
162 if (unlikely(ena_rx_ctx->l4_csum_err))
163 ol_flags |= PKT_RX_L4_CKSUM_BAD;
164 if (unlikely(ena_rx_ctx->l3_csum_err))
165 ol_flags |= PKT_RX_IP_CKSUM_BAD;
167 mbuf->ol_flags = ol_flags;
170 static inline void ena_tx_mbuf_prepare(struct rte_mbuf *mbuf,
171 struct ena_com_tx_ctx *ena_tx_ctx)
173 struct ena_com_tx_meta *ena_meta = &ena_tx_ctx->ena_meta;
176 (PKT_TX_L4_MASK | PKT_TX_IP_CKSUM | PKT_TX_TCP_SEG)) {
177 /* check if TSO is required */
178 if (mbuf->ol_flags & PKT_TX_TCP_SEG) {
179 ena_tx_ctx->tso_enable = true;
181 ena_meta->l4_hdr_len = GET_L4_HDR_LEN(mbuf);
184 /* check if L3 checksum is needed */
185 if (mbuf->ol_flags & PKT_TX_IP_CKSUM)
186 ena_tx_ctx->l3_csum_enable = true;
188 if (mbuf->ol_flags & PKT_TX_IPV6) {
189 ena_tx_ctx->l3_proto = ENA_ETH_IO_L3_PROTO_IPV6;
191 ena_tx_ctx->l3_proto = ENA_ETH_IO_L3_PROTO_IPV4;
193 /* set don't fragment (DF) flag */
194 if (mbuf->packet_type &
195 (RTE_PTYPE_L4_NONFRAG
196 | RTE_PTYPE_INNER_L4_NONFRAG))
197 ena_tx_ctx->df = true;
200 /* check if L4 checksum is needed */
201 switch (mbuf->ol_flags & PKT_TX_L4_MASK) {
202 case PKT_TX_TCP_CKSUM:
203 ena_tx_ctx->l4_proto = ENA_ETH_IO_L4_PROTO_TCP;
204 ena_tx_ctx->l4_csum_enable = true;
206 case PKT_TX_UDP_CKSUM:
207 ena_tx_ctx->l4_proto = ENA_ETH_IO_L4_PROTO_UDP;
208 ena_tx_ctx->l4_csum_enable = true;
211 ena_tx_ctx->l4_proto = ENA_ETH_IO_L4_PROTO_UNKNOWN;
212 ena_tx_ctx->l4_csum_enable = false;
216 ena_meta->mss = mbuf->tso_segsz;
217 ena_meta->l3_hdr_len = mbuf->l3_len;
218 ena_meta->l3_hdr_offset = mbuf->l2_len;
219 /* this param needed only for TSO */
220 ena_meta->l3_outer_hdr_len = 0;
221 ena_meta->l3_outer_hdr_offset = 0;
223 ena_tx_ctx->meta_valid = true;
225 ena_tx_ctx->meta_valid = false;
229 static void ena_close(struct rte_eth_dev *dev)
231 struct ena_adapter *adapter =
232 (struct ena_adapter *)(dev->data->dev_private);
234 adapter->state = ENA_ADAPTER_STATE_STOPPED;
236 ena_rx_queue_release_all(dev);
237 ena_tx_queue_release_all(dev);
240 static int ena_rss_reta_update(struct rte_eth_dev *dev,
241 struct rte_eth_rss_reta_entry64 *reta_conf,
244 struct ena_adapter *adapter =
245 (struct ena_adapter *)(dev->data->dev_private);
246 struct ena_com_dev *ena_dev = &adapter->ena_dev;
252 if ((reta_size == 0) || (reta_conf == NULL))
255 if (reta_size > ENA_RX_RSS_TABLE_SIZE) {
256 RTE_LOG(WARNING, PMD,
257 "indirection table %d is bigger than supported (%d)\n",
258 reta_size, ENA_RX_RSS_TABLE_SIZE);
263 for (i = 0 ; i < reta_size ; i++) {
264 /* each reta_conf is for 64 entries.
265 * to support 128 we use 2 conf of 64
267 conf_idx = i / RTE_RETA_GROUP_SIZE;
268 idx = i % RTE_RETA_GROUP_SIZE;
269 if (TEST_BIT(reta_conf[conf_idx].mask, idx)) {
271 ENA_IO_RXQ_IDX(reta_conf[conf_idx].reta[idx]);
272 ret = ena_com_indirect_table_fill_entry(ena_dev,
275 if (unlikely(ret && (ret != ENA_COM_PERMISSION))) {
277 "Cannot fill indirect table\n");
284 ret = ena_com_indirect_table_set(ena_dev);
285 if (unlikely(ret && (ret != ENA_COM_PERMISSION))) {
286 RTE_LOG(ERR, PMD, "Cannot flush the indirect table\n");
291 RTE_LOG(DEBUG, PMD, "%s(): RSS configured %d entries for port %d\n",
292 __func__, reta_size, adapter->rte_dev->data->port_id);
297 /* Query redirection table. */
298 static int ena_rss_reta_query(struct rte_eth_dev *dev,
299 struct rte_eth_rss_reta_entry64 *reta_conf,
302 struct ena_adapter *adapter =
303 (struct ena_adapter *)(dev->data->dev_private);
304 struct ena_com_dev *ena_dev = &adapter->ena_dev;
307 u32 indirect_table[ENA_RX_RSS_TABLE_SIZE] = {0};
311 if (reta_size == 0 || reta_conf == NULL ||
312 (reta_size > RTE_RETA_GROUP_SIZE && ((reta_conf + 1) == NULL)))
315 ret = ena_com_indirect_table_get(ena_dev, indirect_table);
316 if (unlikely(ret && (ret != ENA_COM_PERMISSION))) {
317 RTE_LOG(ERR, PMD, "cannot get indirect table\n");
322 for (i = 0 ; i < reta_size ; i++) {
323 reta_conf_idx = i / RTE_RETA_GROUP_SIZE;
324 reta_idx = i % RTE_RETA_GROUP_SIZE;
325 if (TEST_BIT(reta_conf[reta_conf_idx].mask, reta_idx))
326 reta_conf[reta_conf_idx].reta[reta_idx] =
327 ENA_IO_RXQ_IDX_REV(indirect_table[i]);
333 static int ena_rss_init_default(struct ena_adapter *adapter)
335 struct ena_com_dev *ena_dev = &adapter->ena_dev;
336 uint16_t nb_rx_queues = adapter->rte_dev->data->nb_rx_queues;
340 rc = ena_com_rss_init(ena_dev, ENA_RX_RSS_TABLE_LOG_SIZE);
342 RTE_LOG(ERR, PMD, "Cannot init indirect table\n");
346 for (i = 0; i < ENA_RX_RSS_TABLE_SIZE; i++) {
347 val = i % nb_rx_queues;
348 rc = ena_com_indirect_table_fill_entry(ena_dev, i,
349 ENA_IO_RXQ_IDX(val));
350 if (unlikely(rc && (rc != ENA_COM_PERMISSION))) {
351 RTE_LOG(ERR, PMD, "Cannot fill indirect table\n");
356 rc = ena_com_fill_hash_function(ena_dev, ENA_ADMIN_CRC32, NULL,
357 ENA_HASH_KEY_SIZE, 0xFFFFFFFF);
358 if (unlikely(rc && (rc != ENA_COM_PERMISSION))) {
359 RTE_LOG(INFO, PMD, "Cannot fill hash function\n");
363 rc = ena_com_set_default_hash_ctrl(ena_dev);
364 if (unlikely(rc && (rc != ENA_COM_PERMISSION))) {
365 RTE_LOG(INFO, PMD, "Cannot fill hash control\n");
369 rc = ena_com_indirect_table_set(ena_dev);
370 if (unlikely(rc && (rc != ENA_COM_PERMISSION))) {
371 RTE_LOG(ERR, PMD, "Cannot flush the indirect table\n");
374 RTE_LOG(DEBUG, PMD, "RSS configured for port %d\n",
375 adapter->rte_dev->data->port_id);
380 ena_com_rss_destroy(ena_dev);
386 static void ena_rx_queue_release_all(struct rte_eth_dev *dev)
388 struct ena_ring **queues = (struct ena_ring **)dev->data->rx_queues;
389 int nb_queues = dev->data->nb_rx_queues;
392 for (i = 0; i < nb_queues; i++)
393 ena_rx_queue_release(queues[i]);
396 static void ena_tx_queue_release_all(struct rte_eth_dev *dev)
398 struct ena_ring **queues = (struct ena_ring **)dev->data->tx_queues;
399 int nb_queues = dev->data->nb_tx_queues;
402 for (i = 0; i < nb_queues; i++)
403 ena_tx_queue_release(queues[i]);
406 static void ena_rx_queue_release(void *queue)
408 struct ena_ring *ring = (struct ena_ring *)queue;
409 struct ena_adapter *adapter = ring->adapter;
412 ena_assert_msg(ring->configured,
413 "API violation - releasing not configured queue");
414 ena_assert_msg(ring->adapter->state != ENA_ADAPTER_STATE_RUNNING,
417 /* Destroy HW queue */
418 ena_qid = ENA_IO_RXQ_IDX(ring->id);
419 ena_com_destroy_io_queue(&adapter->ena_dev, ena_qid);
422 ena_rx_queue_release_bufs(ring);
424 /* Free ring resources */
425 if (ring->rx_buffer_info)
426 rte_free(ring->rx_buffer_info);
427 ring->rx_buffer_info = NULL;
429 ring->configured = 0;
431 RTE_LOG(NOTICE, PMD, "RX Queue %d:%d released\n",
432 ring->port_id, ring->id);
435 static void ena_tx_queue_release(void *queue)
437 struct ena_ring *ring = (struct ena_ring *)queue;
438 struct ena_adapter *adapter = ring->adapter;
441 ena_assert_msg(ring->configured,
442 "API violation. Releasing not configured queue");
443 ena_assert_msg(ring->adapter->state != ENA_ADAPTER_STATE_RUNNING,
446 /* Destroy HW queue */
447 ena_qid = ENA_IO_TXQ_IDX(ring->id);
448 ena_com_destroy_io_queue(&adapter->ena_dev, ena_qid);
451 ena_tx_queue_release_bufs(ring);
453 /* Free ring resources */
454 if (ring->tx_buffer_info)
455 rte_free(ring->tx_buffer_info);
457 if (ring->empty_tx_reqs)
458 rte_free(ring->empty_tx_reqs);
460 ring->empty_tx_reqs = NULL;
461 ring->tx_buffer_info = NULL;
463 ring->configured = 0;
465 RTE_LOG(NOTICE, PMD, "TX Queue %d:%d released\n",
466 ring->port_id, ring->id);
469 static void ena_rx_queue_release_bufs(struct ena_ring *ring)
471 unsigned int ring_mask = ring->ring_size - 1;
473 while (ring->next_to_clean != ring->next_to_use) {
475 ring->rx_buffer_info[ring->next_to_clean & ring_mask];
478 __rte_mbuf_raw_free(m);
480 ring->next_to_clean =
481 ENA_CIRC_INC(ring->next_to_clean, 1, ring->ring_size);
485 static void ena_tx_queue_release_bufs(struct ena_ring *ring)
487 unsigned int ring_mask = ring->ring_size - 1;
489 while (ring->next_to_clean != ring->next_to_use) {
490 struct ena_tx_buffer *tx_buf =
491 &ring->tx_buffer_info[ring->next_to_clean & ring_mask];
494 rte_pktmbuf_free(tx_buf->mbuf);
496 ring->next_to_clean =
497 ENA_CIRC_INC(ring->next_to_clean, 1, ring->ring_size);
501 static int ena_link_update(struct rte_eth_dev *dev,
502 __rte_unused int wait_to_complete)
504 struct rte_eth_link *link = &dev->data->dev_link;
506 link->link_status = 1;
507 link->link_speed = ETH_SPEED_NUM_10G;
508 link->link_duplex = ETH_LINK_FULL_DUPLEX;
513 static int ena_queue_restart_all(struct rte_eth_dev *dev,
514 enum ena_ring_type ring_type)
516 struct ena_adapter *adapter =
517 (struct ena_adapter *)(dev->data->dev_private);
518 struct ena_ring *queues = NULL;
522 queues = (ring_type == ENA_RING_TYPE_RX) ?
523 adapter->rx_ring : adapter->tx_ring;
525 for (i = 0; i < adapter->num_queues; i++) {
526 if (queues[i].configured) {
527 if (ring_type == ENA_RING_TYPE_RX) {
529 dev->data->rx_queues[i] == &queues[i],
530 "Inconsistent state of rx queues\n");
533 dev->data->tx_queues[i] == &queues[i],
534 "Inconsistent state of tx queues\n");
537 rc = ena_queue_restart(&queues[i]);
541 "failed to restart queue %d type(%d)\n",
551 static uint32_t ena_get_mtu_conf(struct ena_adapter *adapter)
553 uint32_t max_frame_len = adapter->max_mtu;
555 if (adapter->rte_eth_dev_data->dev_conf.rxmode.jumbo_frame == 1)
557 adapter->rte_eth_dev_data->dev_conf.rxmode.max_rx_pkt_len;
559 return max_frame_len;
562 static int ena_check_valid_conf(struct ena_adapter *adapter)
564 uint32_t max_frame_len = ena_get_mtu_conf(adapter);
566 if (max_frame_len > adapter->max_mtu) {
567 PMD_INIT_LOG(ERR, "Unsupported MTU of %d\n", max_frame_len);
575 ena_calc_queue_size(struct ena_com_dev *ena_dev,
576 struct ena_com_dev_get_features_ctx *get_feat_ctx)
578 uint32_t queue_size = ENA_DEFAULT_RING_SIZE;
580 queue_size = RTE_MIN(queue_size,
581 get_feat_ctx->max_queues.max_cq_depth);
582 queue_size = RTE_MIN(queue_size,
583 get_feat_ctx->max_queues.max_sq_depth);
585 if (ena_dev->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV)
586 queue_size = RTE_MIN(queue_size,
587 get_feat_ctx->max_queues.max_llq_depth);
589 /* Round down to power of 2 */
590 if (!rte_is_power_of_2(queue_size))
591 queue_size = rte_align32pow2(queue_size >> 1);
593 if (queue_size == 0) {
594 PMD_INIT_LOG(ERR, "Invalid queue size\n");
601 static void ena_stats_restart(struct rte_eth_dev *dev)
603 struct ena_adapter *adapter =
604 (struct ena_adapter *)(dev->data->dev_private);
606 rte_atomic64_init(&adapter->drv_stats->ierrors);
607 rte_atomic64_init(&adapter->drv_stats->oerrors);
608 rte_atomic64_init(&adapter->drv_stats->imcasts);
609 rte_atomic64_init(&adapter->drv_stats->rx_nombuf);
612 static void ena_stats_get(struct rte_eth_dev *dev,
613 struct rte_eth_stats *stats)
615 struct ena_admin_basic_stats ena_stats;
616 struct ena_adapter *adapter =
617 (struct ena_adapter *)(dev->data->dev_private);
618 struct ena_com_dev *ena_dev = &adapter->ena_dev;
621 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
624 memset(&ena_stats, 0, sizeof(ena_stats));
625 rc = ena_com_get_dev_basic_stats(ena_dev, &ena_stats);
627 RTE_LOG(ERR, PMD, "Could not retrieve statistics from ENA");
631 /* Set of basic statistics from ENA */
632 stats->ipackets = __MERGE_64B_H_L(ena_stats.rx_pkts_high,
633 ena_stats.rx_pkts_low);
634 stats->opackets = __MERGE_64B_H_L(ena_stats.tx_pkts_high,
635 ena_stats.tx_pkts_low);
636 stats->ibytes = __MERGE_64B_H_L(ena_stats.rx_bytes_high,
637 ena_stats.rx_bytes_low);
638 stats->obytes = __MERGE_64B_H_L(ena_stats.tx_bytes_high,
639 ena_stats.tx_bytes_low);
640 stats->imissed = __MERGE_64B_H_L(ena_stats.rx_drops_high,
641 ena_stats.rx_drops_low);
643 /* Driver related stats */
644 stats->ierrors = rte_atomic64_read(&adapter->drv_stats->ierrors);
645 stats->oerrors = rte_atomic64_read(&adapter->drv_stats->oerrors);
646 stats->imcasts = rte_atomic64_read(&adapter->drv_stats->imcasts);
647 stats->rx_nombuf = rte_atomic64_read(&adapter->drv_stats->rx_nombuf);
650 static int ena_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
652 struct ena_adapter *adapter;
653 struct ena_com_dev *ena_dev;
656 ena_assert_msg(dev->data != NULL, "Uninitialized device");
657 ena_assert_msg(dev->data->dev_private != NULL, "Uninitialized device");
658 adapter = (struct ena_adapter *)(dev->data->dev_private);
660 ena_dev = &adapter->ena_dev;
661 ena_assert_msg(ena_dev != NULL, "Uninitialized device");
663 if (mtu > ena_get_mtu_conf(adapter)) {
665 "Given MTU (%d) exceeds maximum MTU supported (%d)\n",
666 mtu, ena_get_mtu_conf(adapter));
671 rc = ena_com_set_dev_mtu(ena_dev, mtu);
673 RTE_LOG(ERR, PMD, "Could not set MTU: %d\n", mtu);
675 RTE_LOG(NOTICE, PMD, "Set MTU: %d\n", mtu);
681 static int ena_start(struct rte_eth_dev *dev)
683 struct ena_adapter *adapter =
684 (struct ena_adapter *)(dev->data->dev_private);
687 if (!(adapter->state == ENA_ADAPTER_STATE_CONFIG ||
688 adapter->state == ENA_ADAPTER_STATE_STOPPED)) {
689 PMD_INIT_LOG(ERR, "API violation");
693 rc = ena_check_valid_conf(adapter);
697 rc = ena_queue_restart_all(dev, ENA_RING_TYPE_RX);
701 rc = ena_queue_restart_all(dev, ENA_RING_TYPE_TX);
705 if (adapter->rte_dev->data->dev_conf.rxmode.mq_mode &
706 ETH_MQ_RX_RSS_FLAG) {
707 rc = ena_rss_init_default(adapter);
712 ena_stats_restart(dev);
714 adapter->state = ENA_ADAPTER_STATE_RUNNING;
719 static int ena_queue_restart(struct ena_ring *ring)
723 ena_assert_msg(ring->configured == 1,
724 "Trying to restart unconfigured queue\n");
726 ring->next_to_clean = 0;
727 ring->next_to_use = 0;
729 if (ring->type == ENA_RING_TYPE_TX)
732 rc = ena_populate_rx_queue(ring, ring->ring_size - 1);
733 if ((unsigned int)rc != ring->ring_size - 1) {
734 PMD_INIT_LOG(ERR, "Failed to populate rx ring !\n");
741 static int ena_tx_queue_setup(struct rte_eth_dev *dev,
744 __rte_unused unsigned int socket_id,
745 __rte_unused const struct rte_eth_txconf *tx_conf)
747 struct ena_ring *txq = NULL;
748 struct ena_adapter *adapter =
749 (struct ena_adapter *)(dev->data->dev_private);
753 struct ena_com_dev *ena_dev = &adapter->ena_dev;
755 txq = &adapter->tx_ring[queue_idx];
757 if (txq->configured) {
759 "API violation. Queue %d is already configured\n",
764 if (nb_desc > adapter->tx_ring_size) {
766 "Unsupported size of TX queue (max size: %d)\n",
767 adapter->tx_ring_size);
771 ena_qid = ENA_IO_TXQ_IDX(queue_idx);
772 rc = ena_com_create_io_queue(ena_dev, ena_qid,
773 ENA_COM_IO_QUEUE_DIRECTION_TX,
774 ena_dev->tx_mem_queue_type,
775 -1 /* admin interrupts is not used */,
779 "failed to create io TX queue #%d (qid:%d) rc: %d\n",
780 queue_idx, ena_qid, rc);
782 txq->ena_com_io_cq = &ena_dev->io_cq_queues[ena_qid];
783 txq->ena_com_io_sq = &ena_dev->io_sq_queues[ena_qid];
785 txq->port_id = dev->data->port_id;
786 txq->next_to_clean = 0;
787 txq->next_to_use = 0;
788 txq->ring_size = nb_desc;
790 txq->tx_buffer_info = rte_zmalloc("txq->tx_buffer_info",
791 sizeof(struct ena_tx_buffer) *
793 RTE_CACHE_LINE_SIZE);
794 if (!txq->tx_buffer_info) {
795 RTE_LOG(ERR, PMD, "failed to alloc mem for tx buffer info\n");
799 txq->empty_tx_reqs = rte_zmalloc("txq->empty_tx_reqs",
800 sizeof(u16) * txq->ring_size,
801 RTE_CACHE_LINE_SIZE);
802 if (!txq->empty_tx_reqs) {
803 RTE_LOG(ERR, PMD, "failed to alloc mem for tx reqs\n");
804 rte_free(txq->tx_buffer_info);
807 for (i = 0; i < txq->ring_size; i++)
808 txq->empty_tx_reqs[i] = i;
810 /* Store pointer to this queue in upper layer */
812 dev->data->tx_queues[queue_idx] = txq;
817 static int ena_rx_queue_setup(struct rte_eth_dev *dev,
820 __rte_unused unsigned int socket_id,
821 __rte_unused const struct rte_eth_rxconf *rx_conf,
822 struct rte_mempool *mp)
824 struct ena_adapter *adapter =
825 (struct ena_adapter *)(dev->data->dev_private);
826 struct ena_ring *rxq = NULL;
827 uint16_t ena_qid = 0;
829 struct ena_com_dev *ena_dev = &adapter->ena_dev;
831 rxq = &adapter->rx_ring[queue_idx];
832 if (rxq->configured) {
834 "API violation. Queue %d is already configured\n",
839 if (nb_desc > adapter->rx_ring_size) {
841 "Unsupported size of RX queue (max size: %d)\n",
842 adapter->rx_ring_size);
846 ena_qid = ENA_IO_RXQ_IDX(queue_idx);
847 rc = ena_com_create_io_queue(ena_dev, ena_qid,
848 ENA_COM_IO_QUEUE_DIRECTION_RX,
849 ENA_ADMIN_PLACEMENT_POLICY_HOST,
850 -1 /* admin interrupts not used */,
853 RTE_LOG(ERR, PMD, "failed to create io RX queue #%d rc: %d\n",
856 rxq->ena_com_io_cq = &ena_dev->io_cq_queues[ena_qid];
857 rxq->ena_com_io_sq = &ena_dev->io_sq_queues[ena_qid];
859 rxq->port_id = dev->data->port_id;
860 rxq->next_to_clean = 0;
861 rxq->next_to_use = 0;
862 rxq->ring_size = nb_desc;
865 rxq->rx_buffer_info = rte_zmalloc("rxq->buffer_info",
866 sizeof(struct rte_mbuf *) * nb_desc,
867 RTE_CACHE_LINE_SIZE);
868 if (!rxq->rx_buffer_info) {
869 RTE_LOG(ERR, PMD, "failed to alloc mem for rx buffer info\n");
873 /* Store pointer to this queue in upper layer */
875 dev->data->rx_queues[queue_idx] = rxq;
880 static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count)
884 unsigned int ring_size = rxq->ring_size;
885 unsigned int ring_mask = ring_size - 1;
886 int next_to_use = rxq->next_to_use & ring_mask;
887 struct rte_mbuf **mbufs = &rxq->rx_buffer_info[0];
889 if (unlikely(!count))
892 ena_assert_msg((((ENA_CIRC_COUNT(rxq->next_to_use, rxq->next_to_clean,
894 count) < rxq->ring_size), "bad ring state");
896 count = RTE_MIN(count, ring_size - next_to_use);
898 /* get resources for incoming packets */
899 rc = rte_mempool_get_bulk(rxq->mb_pool,
900 (void **)(&mbufs[next_to_use]), count);
901 if (unlikely(rc < 0)) {
902 rte_atomic64_inc(&rxq->adapter->drv_stats->rx_nombuf);
903 PMD_RX_LOG(DEBUG, "there are no enough free buffers");
907 for (i = 0; i < count; i++) {
908 struct rte_mbuf *mbuf = mbufs[next_to_use];
909 struct ena_com_buf ebuf;
911 rte_prefetch0(mbufs[((next_to_use + 4) & ring_mask)]);
912 /* prepare physical address for DMA transaction */
913 ebuf.paddr = mbuf->buf_physaddr + RTE_PKTMBUF_HEADROOM;
914 ebuf.len = mbuf->buf_len - RTE_PKTMBUF_HEADROOM;
915 /* pass resource to device */
916 rc = ena_com_add_single_rx_desc(rxq->ena_com_io_sq,
919 RTE_LOG(WARNING, PMD, "failed adding rx desc\n");
922 next_to_use = ENA_RX_RING_IDX_NEXT(next_to_use, ring_size);
926 rxq->next_to_use = next_to_use;
927 /* let HW know that it can fill buffers with data */
928 ena_com_write_sq_doorbell(rxq->ena_com_io_sq);
933 static int ena_device_init(struct ena_com_dev *ena_dev,
934 struct ena_com_dev_get_features_ctx *get_feat_ctx)
938 /* Initialize mmio registers */
939 rc = ena_com_mmio_reg_read_request_init(ena_dev);
941 RTE_LOG(ERR, PMD, "failed to init mmio read less\n");
946 rc = ena_com_dev_reset(ena_dev);
948 RTE_LOG(ERR, PMD, "cannot reset device\n");
949 goto err_mmio_read_less;
952 /* check FW version */
953 rc = ena_com_validate_version(ena_dev);
955 RTE_LOG(ERR, PMD, "device version is too low\n");
956 goto err_mmio_read_less;
959 ena_dev->dma_addr_bits = ena_com_get_dma_width(ena_dev);
961 /* ENA device administration layer init */
962 rc = ena_com_admin_init(ena_dev, NULL, true);
965 "cannot initialize ena admin queue with device\n");
966 goto err_mmio_read_less;
969 /* To enable the msix interrupts the driver needs to know the number
970 * of queues. So the driver uses polling mode to retrieve this
973 ena_com_set_admin_polling_mode(ena_dev, true);
975 /* Get Device Attributes and features */
976 rc = ena_com_get_dev_attr_feat(ena_dev, get_feat_ctx);
979 "cannot get attribute for ena device rc= %d\n", rc);
986 ena_com_admin_destroy(ena_dev);
989 ena_com_mmio_reg_read_request_destroy(ena_dev);
994 static int eth_ena_dev_init(struct rte_eth_dev *eth_dev)
996 struct rte_pci_device *pci_dev;
997 struct ena_adapter *adapter =
998 (struct ena_adapter *)(eth_dev->data->dev_private);
999 struct ena_com_dev *ena_dev = &adapter->ena_dev;
1000 struct ena_com_dev_get_features_ctx get_feat_ctx;
1003 static int adapters_found;
1005 memset(adapter, 0, sizeof(struct ena_adapter));
1006 ena_dev = &adapter->ena_dev;
1008 eth_dev->dev_ops = &ena_dev_ops;
1009 eth_dev->rx_pkt_burst = ð_ena_recv_pkts;
1010 eth_dev->tx_pkt_burst = ð_ena_xmit_pkts;
1011 adapter->rte_eth_dev_data = eth_dev->data;
1012 adapter->rte_dev = eth_dev;
1014 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1017 pci_dev = eth_dev->pci_dev;
1018 adapter->pdev = pci_dev;
1020 PMD_INIT_LOG(INFO, "Initializing %x:%x:%x.%d\n",
1021 pci_dev->addr.domain,
1023 pci_dev->addr.devid,
1024 pci_dev->addr.function);
1026 adapter->regs = pci_dev->mem_resource[ENA_REGS_BAR].addr;
1027 adapter->dev_mem_base = pci_dev->mem_resource[ENA_MEM_BAR].addr;
1029 /* Present ENA_MEM_BAR indicates available LLQ mode.
1030 * Use corresponding policy
1032 if (adapter->dev_mem_base)
1033 ena_dev->tx_mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_DEV;
1034 else if (adapter->regs)
1035 ena_dev->tx_mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST;
1037 PMD_INIT_LOG(CRIT, "Failed to access registers BAR(%d)\n",
1040 ena_dev->reg_bar = adapter->regs;
1041 ena_dev->dmadev = adapter->pdev;
1043 adapter->id_number = adapters_found;
1045 snprintf(adapter->name, ENA_NAME_MAX_LEN, "ena_%d",
1046 adapter->id_number);
1048 /* device specific initialization routine */
1049 rc = ena_device_init(ena_dev, &get_feat_ctx);
1051 PMD_INIT_LOG(CRIT, "Failed to init ENA device\n");
1055 if (ena_dev->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV) {
1056 if (get_feat_ctx.max_queues.max_llq_num == 0) {
1058 "Trying to use LLQ but llq_num is 0.\n"
1059 "Fall back into regular queues.\n");
1060 ena_dev->tx_mem_queue_type =
1061 ENA_ADMIN_PLACEMENT_POLICY_HOST;
1062 adapter->num_queues =
1063 get_feat_ctx.max_queues.max_sq_num;
1065 adapter->num_queues =
1066 get_feat_ctx.max_queues.max_llq_num;
1069 adapter->num_queues = get_feat_ctx.max_queues.max_sq_num;
1072 queue_size = ena_calc_queue_size(ena_dev, &get_feat_ctx);
1073 if ((queue_size <= 0) || (adapter->num_queues <= 0))
1076 adapter->tx_ring_size = queue_size;
1077 adapter->rx_ring_size = queue_size;
1079 /* prepare ring structures */
1080 ena_init_rings(adapter);
1082 /* Set max MTU for this device */
1083 adapter->max_mtu = get_feat_ctx.dev_attr.max_mtu;
1085 /* Copy MAC address and point DPDK to it */
1086 eth_dev->data->mac_addrs = (struct ether_addr *)adapter->mac_addr;
1087 ether_addr_copy((struct ether_addr *)get_feat_ctx.dev_attr.mac_addr,
1088 (struct ether_addr *)adapter->mac_addr);
1090 adapter->drv_stats = rte_zmalloc("adapter stats",
1091 sizeof(*adapter->drv_stats),
1092 RTE_CACHE_LINE_SIZE);
1093 if (!adapter->drv_stats) {
1094 RTE_LOG(ERR, PMD, "failed to alloc mem for adapter stats\n");
1099 adapter->state = ENA_ADAPTER_STATE_INIT;
1104 static int ena_dev_configure(struct rte_eth_dev *dev)
1106 struct ena_adapter *adapter =
1107 (struct ena_adapter *)(dev->data->dev_private);
1109 if (!(adapter->state == ENA_ADAPTER_STATE_INIT ||
1110 adapter->state == ENA_ADAPTER_STATE_STOPPED)) {
1111 PMD_INIT_LOG(ERR, "Illegal adapter state: %d\n",
1116 switch (adapter->state) {
1117 case ENA_ADAPTER_STATE_INIT:
1118 case ENA_ADAPTER_STATE_STOPPED:
1119 adapter->state = ENA_ADAPTER_STATE_CONFIG;
1121 case ENA_ADAPTER_STATE_CONFIG:
1122 RTE_LOG(WARNING, PMD,
1123 "Ivalid driver state while trying to configure device\n");
1132 static void ena_init_rings(struct ena_adapter *adapter)
1136 for (i = 0; i < adapter->num_queues; i++) {
1137 struct ena_ring *ring = &adapter->tx_ring[i];
1139 ring->configured = 0;
1140 ring->type = ENA_RING_TYPE_TX;
1141 ring->adapter = adapter;
1143 ring->tx_mem_queue_type = adapter->ena_dev.tx_mem_queue_type;
1144 ring->tx_max_header_size = adapter->ena_dev.tx_max_header_size;
1147 for (i = 0; i < adapter->num_queues; i++) {
1148 struct ena_ring *ring = &adapter->rx_ring[i];
1150 ring->configured = 0;
1151 ring->type = ENA_RING_TYPE_RX;
1152 ring->adapter = adapter;
1157 static void ena_infos_get(struct rte_eth_dev *dev,
1158 struct rte_eth_dev_info *dev_info)
1160 struct ena_adapter *adapter;
1161 struct ena_com_dev *ena_dev;
1162 struct ena_com_dev_get_features_ctx feat;
1163 uint32_t rx_feat = 0, tx_feat = 0;
1166 ena_assert_msg(dev->data != NULL, "Uninitialized device");
1167 ena_assert_msg(dev->data->dev_private != NULL, "Uninitialized device");
1168 adapter = (struct ena_adapter *)(dev->data->dev_private);
1170 ena_dev = &adapter->ena_dev;
1171 ena_assert_msg(ena_dev != NULL, "Uninitialized device");
1173 /* Get supported features from HW */
1174 rc = ena_com_get_dev_attr_feat(ena_dev, &feat);
1177 "Cannot get attribute for ena device rc= %d\n", rc);
1181 /* Set Tx & Rx features available for device */
1182 if (feat.offload.tx & ENA_ADMIN_FEATURE_OFFLOAD_DESC_TSO_IPV4_MASK)
1183 tx_feat |= DEV_TX_OFFLOAD_TCP_TSO;
1185 if (feat.offload.tx &
1186 ENA_ADMIN_FEATURE_OFFLOAD_DESC_TX_L4_IPV4_CSUM_PART_MASK)
1187 tx_feat |= DEV_TX_OFFLOAD_IPV4_CKSUM |
1188 DEV_TX_OFFLOAD_UDP_CKSUM |
1189 DEV_TX_OFFLOAD_TCP_CKSUM;
1191 if (feat.offload.tx &
1192 ENA_ADMIN_FEATURE_OFFLOAD_DESC_RX_L4_IPV4_CSUM_MASK)
1193 rx_feat |= DEV_RX_OFFLOAD_IPV4_CKSUM |
1194 DEV_RX_OFFLOAD_UDP_CKSUM |
1195 DEV_RX_OFFLOAD_TCP_CKSUM;
1197 /* Inform framework about available features */
1198 dev_info->rx_offload_capa = rx_feat;
1199 dev_info->tx_offload_capa = tx_feat;
1201 dev_info->min_rx_bufsize = ENA_MIN_FRAME_LEN;
1202 dev_info->max_rx_pktlen = adapter->max_mtu;
1203 dev_info->max_mac_addrs = 1;
1205 dev_info->max_rx_queues = adapter->num_queues;
1206 dev_info->max_tx_queues = adapter->num_queues;
1207 dev_info->reta_size = ENA_RX_RSS_TABLE_SIZE;
1210 static uint16_t eth_ena_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1213 struct ena_ring *rx_ring = (struct ena_ring *)(rx_queue);
1214 unsigned int ring_size = rx_ring->ring_size;
1215 unsigned int ring_mask = ring_size - 1;
1216 uint16_t next_to_clean = rx_ring->next_to_clean;
1217 int desc_in_use = 0;
1218 unsigned int recv_idx = 0;
1219 struct rte_mbuf *mbuf = NULL;
1220 struct rte_mbuf *mbuf_head = NULL;
1221 struct rte_mbuf *mbuf_prev = NULL;
1222 struct rte_mbuf **rx_buff_info = rx_ring->rx_buffer_info;
1223 unsigned int completed;
1225 struct ena_com_rx_ctx ena_rx_ctx;
1228 /* Check adapter state */
1229 if (unlikely(rx_ring->adapter->state != ENA_ADAPTER_STATE_RUNNING)) {
1231 "Trying to receive pkts while device is NOT running\n");
1235 desc_in_use = ENA_CIRC_COUNT(rx_ring->next_to_use,
1236 next_to_clean, ring_size);
1237 if (unlikely(nb_pkts > desc_in_use))
1238 nb_pkts = desc_in_use;
1240 for (completed = 0; completed < nb_pkts; completed++) {
1243 ena_rx_ctx.max_bufs = rx_ring->ring_size;
1244 ena_rx_ctx.ena_bufs = rx_ring->ena_bufs;
1245 ena_rx_ctx.descs = 0;
1246 /* receive packet context */
1247 rc = ena_com_rx_pkt(rx_ring->ena_com_io_cq,
1248 rx_ring->ena_com_io_sq,
1251 RTE_LOG(ERR, PMD, "ena_com_rx_pkt error %d\n", rc);
1255 if (unlikely(ena_rx_ctx.descs == 0))
1258 while (segments < ena_rx_ctx.descs) {
1259 mbuf = rx_buff_info[next_to_clean & ring_mask];
1260 mbuf->data_len = ena_rx_ctx.ena_bufs[segments].len;
1261 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
1264 if (segments == 0) {
1265 mbuf->nb_segs = ena_rx_ctx.descs;
1266 mbuf->port = rx_ring->port_id;
1270 /* for multi-segment pkts create mbuf chain */
1271 mbuf_prev->next = mbuf;
1273 mbuf_head->pkt_len += mbuf->data_len;
1278 ENA_RX_RING_IDX_NEXT(next_to_clean, ring_size);
1281 /* fill mbuf attributes if any */
1282 ena_rx_mbuf_prepare(mbuf_head, &ena_rx_ctx);
1283 mbuf_head->hash.rss = (uint32_t)rx_ring->id;
1285 /* pass to DPDK application head mbuf */
1286 rx_pkts[recv_idx] = mbuf_head;
1290 /* Burst refill to save doorbells, memory barriers, const interval */
1291 if (ring_size - desc_in_use - 1 > ENA_RING_DESCS_RATIO(ring_size))
1292 ena_populate_rx_queue(rx_ring, ring_size - desc_in_use - 1);
1294 rx_ring->next_to_clean = next_to_clean & ring_mask;
1299 static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
1302 struct ena_ring *tx_ring = (struct ena_ring *)(tx_queue);
1303 unsigned int next_to_use = tx_ring->next_to_use;
1304 struct rte_mbuf *mbuf;
1305 unsigned int ring_size = tx_ring->ring_size;
1306 unsigned int ring_mask = ring_size - 1;
1307 struct ena_com_tx_ctx ena_tx_ctx;
1308 struct ena_tx_buffer *tx_info;
1309 struct ena_com_buf *ebuf;
1310 uint16_t rc, req_id, total_tx_descs = 0;
1314 /* Check adapter state */
1315 if (unlikely(tx_ring->adapter->state != ENA_ADAPTER_STATE_RUNNING)) {
1317 "Trying to xmit pkts while device is NOT running\n");
1321 for (sent_idx = 0; sent_idx < nb_pkts; sent_idx++) {
1322 mbuf = tx_pkts[sent_idx];
1324 req_id = tx_ring->empty_tx_reqs[next_to_use];
1325 tx_info = &tx_ring->tx_buffer_info[req_id];
1326 tx_info->mbuf = mbuf;
1327 tx_info->num_of_bufs = 0;
1328 ebuf = tx_info->bufs;
1330 /* Prepare TX context */
1331 memset(&ena_tx_ctx, 0x0, sizeof(struct ena_com_tx_ctx));
1332 memset(&ena_tx_ctx.ena_meta, 0x0,
1333 sizeof(struct ena_com_tx_meta));
1334 ena_tx_ctx.ena_bufs = ebuf;
1335 ena_tx_ctx.req_id = req_id;
1336 if (tx_ring->tx_mem_queue_type ==
1337 ENA_ADMIN_PLACEMENT_POLICY_DEV) {
1338 /* prepare the push buffer with
1339 * virtual address of the data
1341 ena_tx_ctx.header_len =
1342 RTE_MIN(mbuf->data_len,
1343 tx_ring->tx_max_header_size);
1344 ena_tx_ctx.push_header =
1345 (void *)((char *)mbuf->buf_addr +
1347 } /* there's no else as we take advantage of memset zeroing */
1349 /* Set TX offloads flags, if applicable */
1350 ena_tx_mbuf_prepare(mbuf, &ena_tx_ctx);
1352 if (unlikely(mbuf->ol_flags &
1353 (PKT_RX_L4_CKSUM_BAD | PKT_RX_IP_CKSUM_BAD)))
1354 rte_atomic64_inc(&tx_ring->adapter->drv_stats->ierrors);
1356 rte_prefetch0(tx_pkts[(sent_idx + 4) & ring_mask]);
1358 /* Process first segment taking into
1359 * consideration pushed header
1361 if (mbuf->data_len > ena_tx_ctx.header_len) {
1362 ebuf->paddr = mbuf->buf_physaddr +
1364 ena_tx_ctx.header_len;
1365 ebuf->len = mbuf->data_len - ena_tx_ctx.header_len;
1367 tx_info->num_of_bufs++;
1370 while ((mbuf = mbuf->next) != NULL) {
1371 ebuf->paddr = mbuf->buf_physaddr + mbuf->data_off;
1372 ebuf->len = mbuf->data_len;
1374 tx_info->num_of_bufs++;
1377 ena_tx_ctx.num_bufs = tx_info->num_of_bufs;
1379 /* Write data to device */
1380 rc = ena_com_prepare_tx(tx_ring->ena_com_io_sq,
1381 &ena_tx_ctx, &nb_hw_desc);
1385 tx_info->tx_descs = nb_hw_desc;
1387 next_to_use = ENA_TX_RING_IDX_NEXT(next_to_use, ring_size);
1390 /* Let HW do it's best :-) */
1392 ena_com_write_sq_doorbell(tx_ring->ena_com_io_sq);
1394 /* Clear complete packets */
1395 while (ena_com_tx_comp_req_id_get(tx_ring->ena_com_io_cq, &req_id) >= 0) {
1396 /* Get Tx info & store how many descs were processed */
1397 tx_info = &tx_ring->tx_buffer_info[req_id];
1398 total_tx_descs += tx_info->tx_descs;
1400 /* Free whole mbuf chain */
1401 mbuf = tx_info->mbuf;
1402 rte_pktmbuf_free(mbuf);
1404 /* Put back descriptor to the ring for reuse */
1405 tx_ring->empty_tx_reqs[tx_ring->next_to_clean] = req_id;
1406 tx_ring->next_to_clean =
1407 ENA_TX_RING_IDX_NEXT(tx_ring->next_to_clean,
1408 tx_ring->ring_size);
1410 /* If too many descs to clean, leave it for another run */
1411 if (unlikely(total_tx_descs > ENA_RING_DESCS_RATIO(ring_size)))
1415 /* acknowledge completion of sent packets */
1416 ena_com_comp_ack(tx_ring->ena_com_io_sq, total_tx_descs);
1417 tx_ring->next_to_use = next_to_use;
1421 static struct eth_driver rte_ena_pmd = {
1423 .name = "rte_ena_pmd",
1424 .id_table = pci_id_ena_map,
1425 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1427 .eth_dev_init = eth_ena_dev_init,
1428 .dev_private_size = sizeof(struct ena_adapter),
1432 rte_ena_pmd_init(const char *name __rte_unused,
1433 const char *params __rte_unused)
1435 rte_eth_driver_register(&rte_ena_pmd);
1439 struct rte_driver ena_pmd_drv = {
1440 .name = "ena_driver",
1442 .init = rte_ena_pmd_init,
1445 PMD_REGISTER_DRIVER(ena_pmd_drv);