1c33d45afSEd Czeck /*- 2c33d45afSEd Czeck * BSD LICENSE 3c33d45afSEd Czeck * 4c33d45afSEd Czeck * Copyright (c) 2015-2017 Atomic Rules LLC 5c33d45afSEd Czeck * All rights reserved. 6c33d45afSEd Czeck * 7c33d45afSEd Czeck * Redistribution and use in source and binary forms, with or without 8c33d45afSEd Czeck * modification, are permitted provided that the following conditions 9c33d45afSEd Czeck * are met: 10c33d45afSEd Czeck * 11c33d45afSEd Czeck * * Redistributions of source code must retain the above copyright 12c33d45afSEd Czeck * notice, this list of conditions and the following disclaimer. 13c33d45afSEd Czeck * * Redistributions in binary form must reproduce the above copyright 14c33d45afSEd Czeck * notice, this list of conditions and the following disclaimer in 15c33d45afSEd Czeck * the documentation and/or other materials provided with the 16c33d45afSEd Czeck * distribution. 17c33d45afSEd Czeck * * Neither the name of copyright holder nor the names of its 18c33d45afSEd Czeck * contributors may be used to endorse or promote products derived 19c33d45afSEd Czeck * from this software without specific prior written permission. 20c33d45afSEd Czeck * 21c33d45afSEd Czeck * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22c33d45afSEd Czeck * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23c33d45afSEd Czeck * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24c33d45afSEd Czeck * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25c33d45afSEd Czeck * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26c33d45afSEd Czeck * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27c33d45afSEd Czeck * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28c33d45afSEd Czeck * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29c33d45afSEd Czeck * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30c33d45afSEd Czeck * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31c33d45afSEd Czeck * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32c33d45afSEd Czeck */ 33c33d45afSEd Czeck 34c33d45afSEd Czeck #include <unistd.h> 35c33d45afSEd Czeck 36c33d45afSEd Czeck #include "ark_ethdev_tx.h" 37c33d45afSEd Czeck #include "ark_global.h" 38c33d45afSEd Czeck #include "ark_mpu.h" 39c33d45afSEd Czeck #include "ark_ddm.h" 40c33d45afSEd Czeck #include "ark_logs.h" 41c33d45afSEd Czeck 42c33d45afSEd Czeck #define ARK_TX_META_SIZE 32 43c33d45afSEd Czeck #define ARK_TX_META_OFFSET (RTE_PKTMBUF_HEADROOM - ARK_TX_META_SIZE) 44c33d45afSEd Czeck #define ARK_TX_MAX_NOCHAIN (RTE_MBUF_DEFAULT_DATAROOM) 45c33d45afSEd Czeck 46c33d45afSEd Czeck 47c33d45afSEd Czeck /* ************************************************************************* */ 48c33d45afSEd Czeck struct ark_tx_queue { 49c33d45afSEd Czeck struct ark_tx_meta *meta_q; 50c33d45afSEd Czeck struct rte_mbuf **bufs; 51c33d45afSEd Czeck 52c33d45afSEd Czeck /* handles for hw objects */ 53c33d45afSEd Czeck struct ark_mpu_t *mpu; 54c33d45afSEd Czeck struct ark_ddm_t *ddm; 55c33d45afSEd Czeck 56c33d45afSEd Czeck /* Stats HW tracks bytes and packets, need to count send errors */ 57c33d45afSEd Czeck uint64_t tx_errors; 58c33d45afSEd Czeck 59c33d45afSEd Czeck uint32_t queue_size; 60c33d45afSEd Czeck uint32_t queue_mask; 61c33d45afSEd Czeck 62c33d45afSEd Czeck /* 3 indexes to the paired data rings. */ 63c33d45afSEd Czeck uint32_t prod_index; /* where to put the next one */ 64c33d45afSEd Czeck uint32_t free_index; /* mbuf has been freed */ 65c33d45afSEd Czeck 66c33d45afSEd Czeck /* The queue Id is used to identify the HW Q */ 67c33d45afSEd Czeck uint16_t phys_qid; 68c33d45afSEd Czeck /* The queue Index within the dpdk device structures */ 69c33d45afSEd Czeck uint16_t queue_index; 70c33d45afSEd Czeck 71c33d45afSEd Czeck uint32_t pad[1]; 72c33d45afSEd Czeck 73c33d45afSEd Czeck /* second cache line - fields only used in slow path */ 74c33d45afSEd Czeck MARKER cacheline1 __rte_cache_min_aligned; 75c33d45afSEd Czeck uint32_t cons_index; /* hw is done, can be freed */ 76c33d45afSEd Czeck } __rte_cache_aligned; 77c33d45afSEd Czeck 78c33d45afSEd Czeck /* Forward declarations */ 79c33d45afSEd Czeck static uint32_t eth_ark_tx_jumbo(struct ark_tx_queue *queue, 80c33d45afSEd Czeck struct rte_mbuf *mbuf); 81c33d45afSEd Czeck static int eth_ark_tx_hw_queue_config(struct ark_tx_queue *queue); 82c33d45afSEd Czeck static void free_completed_tx(struct ark_tx_queue *queue); 83c33d45afSEd Czeck 84c33d45afSEd Czeck static inline void 85c33d45afSEd Czeck ark_tx_hw_queue_stop(struct ark_tx_queue *queue) 86c33d45afSEd Czeck { 87c33d45afSEd Czeck ark_mpu_stop(queue->mpu); 88c33d45afSEd Czeck } 89c33d45afSEd Czeck 90c33d45afSEd Czeck /* ************************************************************************* */ 91c33d45afSEd Czeck static inline void 92c33d45afSEd Czeck eth_ark_tx_meta_from_mbuf(struct ark_tx_meta *meta, 93c33d45afSEd Czeck const struct rte_mbuf *mbuf, 94c33d45afSEd Czeck uint8_t flags) 95c33d45afSEd Czeck { 96*bfa9a8a4SThomas Monjalon meta->physaddr = rte_mbuf_data_iova(mbuf); 97c33d45afSEd Czeck meta->delta_ns = 0; 98c33d45afSEd Czeck meta->data_len = rte_pktmbuf_data_len(mbuf); 99c33d45afSEd Czeck meta->flags = flags; 100c33d45afSEd Czeck } 101c33d45afSEd Czeck 102c33d45afSEd Czeck /* ************************************************************************* */ 103c33d45afSEd Czeck uint16_t 104c33d45afSEd Czeck eth_ark_xmit_pkts_noop(void *vtxq __rte_unused, 105c33d45afSEd Czeck struct rte_mbuf **tx_pkts __rte_unused, 106c33d45afSEd Czeck uint16_t nb_pkts __rte_unused) 107c33d45afSEd Czeck { 108c33d45afSEd Czeck return 0; 109c33d45afSEd Czeck } 110c33d45afSEd Czeck 111c33d45afSEd Czeck /* ************************************************************************* */ 112c33d45afSEd Czeck uint16_t 113c33d45afSEd Czeck eth_ark_xmit_pkts(void *vtxq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) 114c33d45afSEd Czeck { 115c33d45afSEd Czeck struct ark_tx_queue *queue; 116c33d45afSEd Czeck struct rte_mbuf *mbuf; 117c33d45afSEd Czeck struct ark_tx_meta *meta; 118c33d45afSEd Czeck 119c33d45afSEd Czeck uint32_t idx; 120c33d45afSEd Czeck uint32_t prod_index_limit; 121c33d45afSEd Czeck int stat; 122c33d45afSEd Czeck uint16_t nb; 123c33d45afSEd Czeck 124c33d45afSEd Czeck queue = (struct ark_tx_queue *)vtxq; 125c33d45afSEd Czeck 126c33d45afSEd Czeck /* free any packets after the HW is done with them */ 127c33d45afSEd Czeck free_completed_tx(queue); 128c33d45afSEd Czeck 129c33d45afSEd Czeck prod_index_limit = queue->queue_size + queue->free_index; 130c33d45afSEd Czeck 131c33d45afSEd Czeck for (nb = 0; 132c33d45afSEd Czeck (nb < nb_pkts) && (queue->prod_index != prod_index_limit); 133c33d45afSEd Czeck ++nb) { 134c33d45afSEd Czeck mbuf = tx_pkts[nb]; 135c33d45afSEd Czeck 136c33d45afSEd Czeck if (ARK_TX_PAD_TO_60) { 137c33d45afSEd Czeck if (unlikely(rte_pktmbuf_pkt_len(mbuf) < 60)) { 138c33d45afSEd Czeck /* this packet even if it is small can be split, 139c33d45afSEd Czeck * be sure to add to the end mbuf 140c33d45afSEd Czeck */ 141c33d45afSEd Czeck uint16_t to_add = 142c33d45afSEd Czeck 60 - rte_pktmbuf_pkt_len(mbuf); 143c33d45afSEd Czeck char *appended = 144c33d45afSEd Czeck rte_pktmbuf_append(mbuf, to_add); 145c33d45afSEd Czeck 146c33d45afSEd Czeck if (appended == 0) { 147c33d45afSEd Czeck /* This packet is in error, 148c33d45afSEd Czeck * we cannot send it so just 149c33d45afSEd Czeck * count it and delete it. 150c33d45afSEd Czeck */ 151c33d45afSEd Czeck queue->tx_errors += 1; 152c33d45afSEd Czeck rte_pktmbuf_free(mbuf); 153c33d45afSEd Czeck continue; 154c33d45afSEd Czeck } 155c33d45afSEd Czeck memset(appended, 0, to_add); 156c33d45afSEd Czeck } 157c33d45afSEd Czeck } 158c33d45afSEd Czeck 159c33d45afSEd Czeck if (unlikely(mbuf->nb_segs != 1)) { 160c33d45afSEd Czeck stat = eth_ark_tx_jumbo(queue, mbuf); 161c33d45afSEd Czeck if (unlikely(stat != 0)) 162c33d45afSEd Czeck break; /* Queue is full */ 163c33d45afSEd Czeck } else { 164c33d45afSEd Czeck idx = queue->prod_index & queue->queue_mask; 165c33d45afSEd Czeck queue->bufs[idx] = mbuf; 166c33d45afSEd Czeck meta = &queue->meta_q[idx]; 167c33d45afSEd Czeck eth_ark_tx_meta_from_mbuf(meta, 168c33d45afSEd Czeck mbuf, 169c33d45afSEd Czeck ARK_DDM_SOP | 170c33d45afSEd Czeck ARK_DDM_EOP); 171c33d45afSEd Czeck queue->prod_index++; 172c33d45afSEd Czeck } 173c33d45afSEd Czeck } 174c33d45afSEd Czeck 175c33d45afSEd Czeck if (ARK_TX_DEBUG && (nb != nb_pkts)) { 176c33d45afSEd Czeck PMD_TX_LOG(DEBUG, "TX: Failure to send:" 177c33d45afSEd Czeck " req: %" PRIU32 178c33d45afSEd Czeck " sent: %" PRIU32 179c33d45afSEd Czeck " prod: %" PRIU32 180c33d45afSEd Czeck " cons: %" PRIU32 181c33d45afSEd Czeck " free: %" PRIU32 "\n", 182c33d45afSEd Czeck nb_pkts, nb, 183c33d45afSEd Czeck queue->prod_index, 184c33d45afSEd Czeck queue->cons_index, 185c33d45afSEd Czeck queue->free_index); 186c33d45afSEd Czeck ark_mpu_dump(queue->mpu, 187c33d45afSEd Czeck "TX Failure MPU: ", 188c33d45afSEd Czeck queue->phys_qid); 189c33d45afSEd Czeck } 190c33d45afSEd Czeck 191c33d45afSEd Czeck /* let FPGA know producer index. */ 192c33d45afSEd Czeck if (likely(nb != 0)) 193c33d45afSEd Czeck ark_mpu_set_producer(queue->mpu, queue->prod_index); 194c33d45afSEd Czeck 195c33d45afSEd Czeck return nb; 196c33d45afSEd Czeck } 197c33d45afSEd Czeck 198c33d45afSEd Czeck /* ************************************************************************* */ 199c33d45afSEd Czeck static uint32_t 200c33d45afSEd Czeck eth_ark_tx_jumbo(struct ark_tx_queue *queue, struct rte_mbuf *mbuf) 201c33d45afSEd Czeck { 202c33d45afSEd Czeck struct rte_mbuf *next; 203c33d45afSEd Czeck struct ark_tx_meta *meta; 204c33d45afSEd Czeck uint32_t free_queue_space; 205c33d45afSEd Czeck uint32_t idx; 206c33d45afSEd Czeck uint8_t flags = ARK_DDM_SOP; 207c33d45afSEd Czeck 208c33d45afSEd Czeck free_queue_space = queue->queue_mask - 209c33d45afSEd Czeck (queue->prod_index - queue->free_index); 210c33d45afSEd Czeck if (unlikely(free_queue_space < mbuf->nb_segs)) 211c33d45afSEd Czeck return -1; 212c33d45afSEd Czeck 213c33d45afSEd Czeck while (mbuf != NULL) { 214c33d45afSEd Czeck next = mbuf->next; 215c33d45afSEd Czeck 216c33d45afSEd Czeck idx = queue->prod_index & queue->queue_mask; 217c33d45afSEd Czeck queue->bufs[idx] = mbuf; 218c33d45afSEd Czeck meta = &queue->meta_q[idx]; 219c33d45afSEd Czeck 220c33d45afSEd Czeck flags |= (next == NULL) ? ARK_DDM_EOP : 0; 221c33d45afSEd Czeck eth_ark_tx_meta_from_mbuf(meta, mbuf, flags); 222c33d45afSEd Czeck queue->prod_index++; 223c33d45afSEd Czeck 224c33d45afSEd Czeck flags &= ~ARK_DDM_SOP; /* drop SOP flags */ 225c33d45afSEd Czeck mbuf = next; 226c33d45afSEd Czeck } 227c33d45afSEd Czeck 228c33d45afSEd Czeck return 0; 229c33d45afSEd Czeck } 230c33d45afSEd Czeck 231c33d45afSEd Czeck /* ************************************************************************* */ 232c33d45afSEd Czeck int 233c33d45afSEd Czeck eth_ark_tx_queue_setup(struct rte_eth_dev *dev, 234c33d45afSEd Czeck uint16_t queue_idx, 235c33d45afSEd Czeck uint16_t nb_desc, 236c33d45afSEd Czeck unsigned int socket_id, 237c33d45afSEd Czeck const struct rte_eth_txconf *tx_conf __rte_unused) 238c33d45afSEd Czeck { 239c33d45afSEd Czeck struct ark_adapter *ark = (struct ark_adapter *)dev->data->dev_private; 240c33d45afSEd Czeck struct ark_tx_queue *queue; 241c33d45afSEd Czeck int status; 242c33d45afSEd Czeck 243c33d45afSEd Czeck /* Future: divide the Q's evenly with multi-ports */ 244c33d45afSEd Czeck int port = dev->data->port_id; 245c33d45afSEd Czeck int qidx = port + queue_idx; 246c33d45afSEd Czeck 247c33d45afSEd Czeck if (!rte_is_power_of_2(nb_desc)) { 248c33d45afSEd Czeck PMD_DRV_LOG(ERR, 249c33d45afSEd Czeck "DPDK Arkville configuration queue size" 250c33d45afSEd Czeck " must be power of two %u (%s)\n", 251c33d45afSEd Czeck nb_desc, __func__); 252c33d45afSEd Czeck return -1; 253c33d45afSEd Czeck } 254c33d45afSEd Czeck 255c33d45afSEd Czeck /* Allocate queue struct */ 256c33d45afSEd Czeck queue = rte_zmalloc_socket("Ark_txqueue", 257c33d45afSEd Czeck sizeof(struct ark_tx_queue), 258c33d45afSEd Czeck 64, 259c33d45afSEd Czeck socket_id); 260c33d45afSEd Czeck if (queue == 0) { 261c33d45afSEd Czeck PMD_DRV_LOG(ERR, "Failed to allocate tx " 262c33d45afSEd Czeck "queue memory in %s\n", 263c33d45afSEd Czeck __func__); 264c33d45afSEd Czeck return -ENOMEM; 265c33d45afSEd Czeck } 266c33d45afSEd Czeck 267c33d45afSEd Czeck /* we use zmalloc no need to initialize fields */ 268c33d45afSEd Czeck queue->queue_size = nb_desc; 269c33d45afSEd Czeck queue->queue_mask = nb_desc - 1; 270c33d45afSEd Czeck queue->phys_qid = qidx; 271c33d45afSEd Czeck queue->queue_index = queue_idx; 272c33d45afSEd Czeck dev->data->tx_queues[queue_idx] = queue; 273c33d45afSEd Czeck 274c33d45afSEd Czeck queue->meta_q = 275c33d45afSEd Czeck rte_zmalloc_socket("Ark_txqueue meta", 276c33d45afSEd Czeck nb_desc * sizeof(struct ark_tx_meta), 277c33d45afSEd Czeck 64, 278c33d45afSEd Czeck socket_id); 279c33d45afSEd Czeck queue->bufs = 280c33d45afSEd Czeck rte_zmalloc_socket("Ark_txqueue bufs", 281c33d45afSEd Czeck nb_desc * sizeof(struct rte_mbuf *), 282c33d45afSEd Czeck 64, 283c33d45afSEd Czeck socket_id); 284c33d45afSEd Czeck 285c33d45afSEd Czeck if (queue->meta_q == 0 || queue->bufs == 0) { 286c33d45afSEd Czeck PMD_DRV_LOG(ERR, "Failed to allocate " 287c33d45afSEd Czeck "queue memory in %s\n", __func__); 288c33d45afSEd Czeck rte_free(queue->meta_q); 289c33d45afSEd Czeck rte_free(queue->bufs); 290c33d45afSEd Czeck rte_free(queue); 291c33d45afSEd Czeck return -ENOMEM; 292c33d45afSEd Czeck } 293c33d45afSEd Czeck 294c33d45afSEd Czeck queue->ddm = RTE_PTR_ADD(ark->ddm.v, qidx * ARK_DDM_QOFFSET); 295c33d45afSEd Czeck queue->mpu = RTE_PTR_ADD(ark->mputx.v, qidx * ARK_MPU_QOFFSET); 296c33d45afSEd Czeck 297c33d45afSEd Czeck status = eth_ark_tx_hw_queue_config(queue); 298c33d45afSEd Czeck 299c33d45afSEd Czeck if (unlikely(status != 0)) { 300c33d45afSEd Czeck rte_free(queue->meta_q); 301c33d45afSEd Czeck rte_free(queue->bufs); 302c33d45afSEd Czeck rte_free(queue); 303c33d45afSEd Czeck return -1; /* ERROR CODE */ 304c33d45afSEd Czeck } 305c33d45afSEd Czeck 306c33d45afSEd Czeck return 0; 307c33d45afSEd Czeck } 308c33d45afSEd Czeck 309c33d45afSEd Czeck /* ************************************************************************* */ 310c33d45afSEd Czeck static int 311c33d45afSEd Czeck eth_ark_tx_hw_queue_config(struct ark_tx_queue *queue) 312c33d45afSEd Czeck { 313c33d45afSEd Czeck phys_addr_t queue_base, ring_base, cons_index_addr; 314c33d45afSEd Czeck uint32_t write_interval_ns; 315c33d45afSEd Czeck 316c33d45afSEd Czeck /* Verify HW -- MPU */ 317c33d45afSEd Czeck if (ark_mpu_verify(queue->mpu, sizeof(struct ark_tx_meta))) 318c33d45afSEd Czeck return -1; 319c33d45afSEd Czeck 32087cf4c6cSThomas Monjalon queue_base = rte_malloc_virt2iova(queue); 32187cf4c6cSThomas Monjalon ring_base = rte_malloc_virt2iova(queue->meta_q); 322c33d45afSEd Czeck cons_index_addr = 323c33d45afSEd Czeck queue_base + offsetof(struct ark_tx_queue, cons_index); 324c33d45afSEd Czeck 325c33d45afSEd Czeck ark_mpu_stop(queue->mpu); 326c33d45afSEd Czeck ark_mpu_reset(queue->mpu); 327c33d45afSEd Czeck 328c33d45afSEd Czeck /* Stop and Reset and configure MPU */ 329c33d45afSEd Czeck ark_mpu_configure(queue->mpu, ring_base, queue->queue_size, 1); 330c33d45afSEd Czeck 331c33d45afSEd Czeck /* 332c33d45afSEd Czeck * Adjust the write interval based on queue size -- 333c33d45afSEd Czeck * increase pcie traffic when low mbuf count 334c33d45afSEd Czeck * Queue sizes less than 128 are not allowed 335c33d45afSEd Czeck */ 336c33d45afSEd Czeck switch (queue->queue_size) { 337c33d45afSEd Czeck case 128: 338c33d45afSEd Czeck write_interval_ns = 500; 339c33d45afSEd Czeck break; 340c33d45afSEd Czeck case 256: 341c33d45afSEd Czeck write_interval_ns = 500; 342c33d45afSEd Czeck break; 343c33d45afSEd Czeck case 512: 344c33d45afSEd Czeck write_interval_ns = 1000; 345c33d45afSEd Czeck break; 346c33d45afSEd Czeck default: 347c33d45afSEd Czeck write_interval_ns = 2000; 348c33d45afSEd Czeck break; 349c33d45afSEd Czeck } 350c33d45afSEd Czeck 351c33d45afSEd Czeck /* Completion address in UDM */ 352c33d45afSEd Czeck ark_ddm_setup(queue->ddm, cons_index_addr, write_interval_ns); 353c33d45afSEd Czeck 354c33d45afSEd Czeck return 0; 355c33d45afSEd Czeck } 356c33d45afSEd Czeck 357c33d45afSEd Czeck /* ************************************************************************* */ 358c33d45afSEd Czeck void 359c33d45afSEd Czeck eth_ark_tx_queue_release(void *vtx_queue) 360c33d45afSEd Czeck { 361c33d45afSEd Czeck struct ark_tx_queue *queue; 362c33d45afSEd Czeck 363c33d45afSEd Czeck queue = (struct ark_tx_queue *)vtx_queue; 364c33d45afSEd Czeck 365c33d45afSEd Czeck ark_tx_hw_queue_stop(queue); 366c33d45afSEd Czeck 367c33d45afSEd Czeck queue->cons_index = queue->prod_index; 368c33d45afSEd Czeck free_completed_tx(queue); 369c33d45afSEd Czeck 370c33d45afSEd Czeck rte_free(queue->meta_q); 371c33d45afSEd Czeck rte_free(queue->bufs); 372c33d45afSEd Czeck rte_free(queue); 373c33d45afSEd Czeck } 374c33d45afSEd Czeck 375c33d45afSEd Czeck /* ************************************************************************* */ 376c33d45afSEd Czeck int 377c33d45afSEd Czeck eth_ark_tx_queue_stop(struct rte_eth_dev *dev, uint16_t queue_id) 378c33d45afSEd Czeck { 379c33d45afSEd Czeck struct ark_tx_queue *queue; 380c33d45afSEd Czeck int cnt = 0; 381c33d45afSEd Czeck 382c33d45afSEd Czeck queue = dev->data->tx_queues[queue_id]; 383c33d45afSEd Czeck 384c33d45afSEd Czeck /* Wait for DDM to send out all packets. */ 385c33d45afSEd Czeck while (queue->cons_index != queue->prod_index) { 386c33d45afSEd Czeck usleep(100); 387c33d45afSEd Czeck if (cnt++ > 10000) 388c33d45afSEd Czeck return -1; 389c33d45afSEd Czeck } 390c33d45afSEd Czeck 391c33d45afSEd Czeck ark_mpu_stop(queue->mpu); 392c33d45afSEd Czeck free_completed_tx(queue); 393c33d45afSEd Czeck 394c33d45afSEd Czeck dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STOPPED; 395c33d45afSEd Czeck 396c33d45afSEd Czeck return 0; 397c33d45afSEd Czeck } 398c33d45afSEd Czeck 399c33d45afSEd Czeck int 400c33d45afSEd Czeck eth_ark_tx_queue_start(struct rte_eth_dev *dev, uint16_t queue_id) 401c33d45afSEd Czeck { 402c33d45afSEd Czeck struct ark_tx_queue *queue; 403c33d45afSEd Czeck 404c33d45afSEd Czeck queue = dev->data->tx_queues[queue_id]; 405c33d45afSEd Czeck if (dev->data->tx_queue_state[queue_id] == RTE_ETH_QUEUE_STATE_STARTED) 406c33d45afSEd Czeck return 0; 407c33d45afSEd Czeck 408c33d45afSEd Czeck ark_mpu_start(queue->mpu); 409c33d45afSEd Czeck dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STARTED; 410c33d45afSEd Czeck 411c33d45afSEd Czeck return 0; 412c33d45afSEd Czeck } 413c33d45afSEd Czeck 414c33d45afSEd Czeck /* ************************************************************************* */ 415c33d45afSEd Czeck static void 416c33d45afSEd Czeck free_completed_tx(struct ark_tx_queue *queue) 417c33d45afSEd Czeck { 418c33d45afSEd Czeck struct rte_mbuf *mbuf; 419c33d45afSEd Czeck struct ark_tx_meta *meta; 420c33d45afSEd Czeck uint32_t top_index; 421c33d45afSEd Czeck 422c33d45afSEd Czeck top_index = queue->cons_index; /* read once */ 423c33d45afSEd Czeck while (queue->free_index != top_index) { 424c33d45afSEd Czeck meta = &queue->meta_q[queue->free_index & queue->queue_mask]; 425c33d45afSEd Czeck mbuf = queue->bufs[queue->free_index & queue->queue_mask]; 426c33d45afSEd Czeck 427c33d45afSEd Czeck if (likely((meta->flags & ARK_DDM_SOP) != 0)) { 428c33d45afSEd Czeck /* ref count of the mbuf is checked in this call. */ 429c33d45afSEd Czeck rte_pktmbuf_free(mbuf); 430c33d45afSEd Czeck } 431c33d45afSEd Czeck queue->free_index++; 432c33d45afSEd Czeck } 433c33d45afSEd Czeck } 434c33d45afSEd Czeck 435c33d45afSEd Czeck /* ************************************************************************* */ 436c33d45afSEd Czeck void 437c33d45afSEd Czeck eth_tx_queue_stats_get(void *vqueue, struct rte_eth_stats *stats) 438c33d45afSEd Czeck { 439c33d45afSEd Czeck struct ark_tx_queue *queue; 440c33d45afSEd Czeck struct ark_ddm_t *ddm; 441c33d45afSEd Czeck uint64_t bytes, pkts; 442c33d45afSEd Czeck 443c33d45afSEd Czeck queue = vqueue; 444c33d45afSEd Czeck ddm = queue->ddm; 445c33d45afSEd Czeck 446c33d45afSEd Czeck bytes = ark_ddm_queue_byte_count(ddm); 447c33d45afSEd Czeck pkts = ark_ddm_queue_pkt_count(ddm); 448c33d45afSEd Czeck 449c33d45afSEd Czeck stats->q_opackets[queue->queue_index] = pkts; 450c33d45afSEd Czeck stats->q_obytes[queue->queue_index] = bytes; 451c33d45afSEd Czeck stats->opackets += pkts; 452c33d45afSEd Czeck stats->obytes += bytes; 453c33d45afSEd Czeck stats->oerrors += queue->tx_errors; 454c33d45afSEd Czeck } 455c33d45afSEd Czeck 456c33d45afSEd Czeck void 457c33d45afSEd Czeck eth_tx_queue_stats_reset(void *vqueue) 458c33d45afSEd Czeck { 459c33d45afSEd Czeck struct ark_tx_queue *queue; 460c33d45afSEd Czeck struct ark_ddm_t *ddm; 461c33d45afSEd Czeck 462c33d45afSEd Czeck queue = vqueue; 463c33d45afSEd Czeck ddm = queue->ddm; 464c33d45afSEd Czeck 465c33d45afSEd Czeck ark_ddm_queue_reset_stats(ddm); 466c33d45afSEd Czeck queue->tx_errors = 0; 467c33d45afSEd Czeck } 468