LCOV - code coverage report
Current view: top level - drivers/common/zsda - zsda_qp_common.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 101 0.0 %
Date: 2025-03-01 20:23:48 Functions: 0 5 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 62 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2024 ZTE Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "zsda_qp_common.h"
       6                 :            : 
       7                 :            : void
       8                 :          0 : zsda_stats_get(void **queue_pairs, const uint32_t nb_queue_pairs,
       9                 :            :               struct zsda_qp_stat *stats)
      10                 :            : {
      11                 :            :         enum zsda_service_type type;
      12                 :            :         uint32_t i;
      13                 :            :         struct zsda_qp *qp;
      14                 :            : 
      15         [ #  # ]:          0 :         if ((stats == NULL) || (queue_pairs == NULL)) {
      16                 :          0 :                 ZSDA_LOG(ERR, "Failed! stats or queue_pairs is NULL");
      17                 :          0 :                 return;
      18                 :            :         }
      19                 :            : 
      20         [ #  # ]:          0 :         for (i = 0; i < nb_queue_pairs; i++) {
      21                 :          0 :                 qp = queue_pairs[i];
      22                 :            : 
      23         [ #  # ]:          0 :                 if (qp == NULL) {
      24                 :          0 :                         ZSDA_LOG(ERR, "Failed! queue_pairs[i] is NULL");
      25                 :          0 :                         break;
      26                 :            :                 }
      27                 :            : 
      28         [ #  # ]:          0 :                 for (type = 0; type < ZSDA_SERVICE_INVALID; type++) {
      29         [ #  # ]:          0 :                         if (qp->srv[type].used) {
      30                 :          0 :                                 stats->enqueued_count +=
      31                 :          0 :                                         qp->srv[type].stats.enqueued_count;
      32                 :          0 :                                 stats->dequeued_count +=
      33                 :          0 :                                         qp->srv[type].stats.dequeued_count;
      34                 :          0 :                                 stats->enqueue_err_count +=
      35                 :          0 :                                         qp->srv[type].stats.enqueue_err_count;
      36                 :          0 :                                 stats->dequeue_err_count +=
      37                 :          0 :                                         qp->srv[type].stats.dequeue_err_count;
      38                 :            :                         }
      39                 :            :                 }
      40                 :            :         }
      41                 :            : }
      42                 :            : 
      43                 :            : void
      44                 :          0 : zsda_stats_reset(void **queue_pairs, const uint32_t nb_queue_pairs)
      45                 :            : {
      46                 :            :         enum zsda_service_type type;
      47                 :            :         uint32_t i;
      48                 :            :         struct zsda_qp *qp;
      49                 :            : 
      50         [ #  # ]:          0 :         if (queue_pairs == NULL) {
      51                 :          0 :                 ZSDA_LOG(ERR, "Failed! queue_pairs is NULL");
      52                 :          0 :                 return;
      53                 :            :         }
      54                 :            : 
      55         [ #  # ]:          0 :         for (i = 0; i < nb_queue_pairs; i++) {
      56                 :          0 :                 qp = queue_pairs[i];
      57                 :            : 
      58         [ #  # ]:          0 :                 if (qp == NULL) {
      59                 :          0 :                         ZSDA_LOG(ERR, "Failed! queue_pairs[i] is NULL");
      60                 :          0 :                         break;
      61                 :            :                 }
      62         [ #  # ]:          0 :                 for (type = 0; type < ZSDA_MAX_SERVICES; type++) {
      63         [ #  # ]:          0 :                         if (qp->srv[type].used)
      64                 :          0 :                                 memset(&(qp->srv[type].stats), 0,
      65                 :            :                                        sizeof(struct zsda_qp_stat));
      66                 :            :                 }
      67                 :            :         }
      68                 :            : }
      69                 :            : 
      70                 :            : void
      71                 :          0 : zsda_queue_delete(const struct zsda_queue *queue)
      72                 :            : {
      73                 :            :         const struct rte_memzone *mz;
      74                 :            : 
      75         [ #  # ]:          0 :         if (queue == NULL) {
      76                 :          0 :                 ZSDA_LOG(DEBUG, "Invalid queue");
      77                 :          0 :                 return;
      78                 :            :         }
      79                 :            : 
      80                 :          0 :         mz = rte_memzone_lookup(queue->memz_name);
      81         [ #  # ]:          0 :         if (mz != NULL) {
      82                 :          0 :                 memset(queue->base_addr, 0x0,
      83                 :          0 :                        (uint16_t)(queue->queue_size * queue->msg_size));
      84                 :          0 :                 rte_memzone_free(mz);
      85                 :            :         } else
      86                 :          0 :                 ZSDA_LOG(DEBUG, "queue %s doesn't exist", queue->memz_name);
      87                 :            : }
      88                 :            : 
      89                 :            : int
      90                 :          0 : zsda_queue_pair_release(struct zsda_qp **qp_addr)
      91                 :            : {
      92                 :          0 :         struct zsda_qp *qp = *qp_addr;
      93                 :            :         uint32_t i;
      94                 :            :         enum zsda_service_type type;
      95                 :            : 
      96         [ #  # ]:          0 :         if (qp == NULL) {
      97                 :          0 :                 ZSDA_LOG(DEBUG, "qp already freed");
      98                 :          0 :                 return 0;
      99                 :            :         }
     100                 :            : 
     101         [ #  # ]:          0 :         for (type = 0; type < ZSDA_SERVICE_INVALID; type++) {
     102         [ #  # ]:          0 :                 if (!qp->srv[type].used)
     103                 :          0 :                         continue;
     104                 :            : 
     105                 :          0 :                 zsda_queue_delete(&(qp->srv[type].tx_q));
     106                 :          0 :                 zsda_queue_delete(&(qp->srv[type].rx_q));
     107                 :          0 :                 qp->srv[type].used = false;
     108         [ #  # ]:          0 :                 for (i = 0; i < qp->srv[type].nb_descriptors; i++)
     109                 :          0 :                         rte_mempool_put(qp->srv[type].op_cookie_pool,
     110         [ #  # ]:          0 :                                         qp->srv[type].op_cookies[i]);
     111                 :            : 
     112                 :          0 :                 rte_mempool_free(qp->srv[type].op_cookie_pool);
     113                 :          0 :                 rte_free(qp->srv[type].op_cookies);
     114                 :            :         }
     115                 :            : 
     116                 :          0 :         rte_free(qp);
     117                 :          0 :         *qp_addr = NULL;
     118                 :            : 
     119                 :          0 :         return ZSDA_SUCCESS;
     120                 :            : }
     121                 :            : 
     122                 :            : int
     123                 :          0 : zsda_sgl_fill(const struct rte_mbuf *buf, uint32_t offset, struct zsda_sgl *sgl,
     124                 :            :               const phys_addr_t sgl_phy_addr, uint32_t remain_len,
     125                 :            :               struct comp_head_info *comp_head_info)
     126                 :            : {
     127                 :            :         uint32_t nr;
     128                 :            :         uint16_t put_in_len;
     129                 :            :         bool head_set = false;
     130                 :            : 
     131         [ #  # ]:          0 :         for (nr = 0; (buf && (nr < (ZSDA_SGL_MAX_NUMBER - 1)));) {
     132         [ #  # ]:          0 :                 if (offset >= rte_pktmbuf_data_len(buf)) {
     133                 :          0 :                         offset -= rte_pktmbuf_data_len(buf);
     134                 :          0 :                         buf = buf->next;
     135                 :          0 :                         continue;
     136                 :            :                 }
     137         [ #  # ]:          0 :                 memset(&(sgl->buffers[nr]), 0, sizeof(struct zsda_buf));
     138   [ #  #  #  # ]:          0 :                 if ((nr > 0) && (((nr + 1) % ZSDA_SGL_FRAGMENT_SIZE) == 0) &&
     139         [ #  # ]:          0 :                     (buf->next != NULL)) {
     140                 :          0 :                         sgl->buffers[nr].len = SGL_TYPE_PHYS_ADDR;
     141                 :          0 :                         sgl->buffers[nr].addr =
     142                 :          0 :                                 sgl_phy_addr +
     143                 :          0 :                                 ((nr + 1) * sizeof(struct zsda_buf));
     144                 :          0 :                         sgl->buffers[nr].type = SGL_TYPE_NEXT_LIST;
     145                 :            :                         ++nr;
     146                 :          0 :                         continue;
     147                 :            :                 }
     148         [ #  # ]:          0 :                 if (comp_head_info && !head_set) {
     149                 :          0 :                         sgl->buffers[nr].len = comp_head_info->head_len;
     150                 :          0 :                         sgl->buffers[nr].addr = comp_head_info->head_phys_addr;
     151                 :          0 :                         sgl->buffers[nr].type = SGL_TYPE_PHYS_ADDR;
     152                 :          0 :                         ++nr;
     153                 :            :                         head_set = true;
     154                 :          0 :                         remain_len -= comp_head_info->head_len;
     155                 :          0 :                         continue;
     156                 :            :                 } else {
     157                 :          0 :                         put_in_len = rte_pktmbuf_data_len(buf) - (offset & 0xffff);
     158         [ #  # ]:          0 :                         if (remain_len <= put_in_len)
     159                 :          0 :                                 put_in_len = remain_len;
     160                 :          0 :                         remain_len -= put_in_len;
     161                 :            : 
     162         [ #  # ]:          0 :                         sgl->buffers[nr].len = put_in_len;
     163                 :          0 :                         sgl->buffers[nr].addr = rte_pktmbuf_iova_offset(buf, offset);
     164                 :          0 :                         sgl->buffers[nr].type = SGL_TYPE_PHYS_ADDR;
     165                 :            :                 }
     166                 :            :                 offset = 0;
     167                 :          0 :                 ++nr;
     168                 :          0 :                 buf = buf->next;
     169                 :            : 
     170         [ #  # ]:          0 :                 if (remain_len == 0)
     171                 :            :                         break;
     172                 :            :         }
     173                 :            : 
     174         [ #  # ]:          0 :         if (nr == 0) {
     175                 :          0 :                 ZSDA_LOG(ERR, "In fill_sgl, nr == 0");
     176                 :          0 :                 return ZSDA_FAILED;
     177                 :            :         }
     178                 :            : 
     179                 :          0 :         sgl->buffers[nr - 1].type = SGL_TYPE_LAST_PHYS_ADDR;
     180                 :            : 
     181         [ #  # ]:          0 :         if (buf) {
     182         [ #  # ]:          0 :                 if (unlikely(buf->next)) {
     183         [ #  # ]:          0 :                         if (nr == (ZSDA_SGL_MAX_NUMBER - 1)) {
     184                 :          0 :                                 ZSDA_LOG(ERR, "ERR! segs size (%u)",
     185                 :            :                                          (ZSDA_SGL_MAX_NUMBER));
     186                 :          0 :                                 return -EINVAL;
     187                 :            :                         }
     188                 :            :                 }
     189                 :            :         }
     190                 :            : 
     191                 :            :         return ZSDA_SUCCESS;
     192                 :            : }

Generated by: LCOV version 1.14