LCOV - code coverage report
Current view: top level - drivers/net/octeon_ep - cnxk_ep_tx.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 93 0.0 %
Date: 2024-04-01 19:00:53 Functions: 0 5 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 22 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2023 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "cnxk_ep_vf.h"
       6                 :            : #include "otx_ep_rxtx.h"
       7                 :            : 
       8                 :            : static inline uint32_t
       9                 :          0 : cnxk_ep_check_tx_ism_mem(void *tx_queue)
      10                 :            : {
      11                 :            :         struct otx_ep_instr_queue *iq = (struct otx_ep_instr_queue *)tx_queue;
      12                 :            :         uint32_t val;
      13                 :            : 
      14                 :            :         /* Batch subtractions from the HW counter to reduce PCIe traffic
      15                 :            :          * This adds an extra local variable, but almost halves the
      16                 :            :          * number of PCIe writes.
      17                 :            :          */
      18                 :          0 :         val = __atomic_load_n(iq->inst_cnt_ism, __ATOMIC_RELAXED);
      19                 :          0 :         iq->inst_cnt += val - iq->inst_cnt_prev;
      20                 :          0 :         iq->inst_cnt_prev = val;
      21                 :            : 
      22         [ #  # ]:          0 :         if (val > (uint32_t)(1 << 31)) {
      23                 :            :                 /* Only subtract the packet count in the HW counter
      24                 :            :                  * when count above halfway to saturation.
      25                 :            :                  */
      26                 :          0 :                 rte_write64((uint64_t)val, iq->inst_cnt_reg);
      27                 :            :                 rte_mb();
      28                 :            : 
      29                 :          0 :                 rte_write64(OTX2_SDP_REQUEST_ISM, iq->inst_cnt_reg);
      30         [ #  # ]:          0 :                 while (__atomic_load_n(iq->inst_cnt_ism, __ATOMIC_RELAXED) >= val) {
      31                 :          0 :                         rte_write64(OTX2_SDP_REQUEST_ISM, iq->inst_cnt_reg);
      32                 :            :                         rte_mb();
      33                 :            :                 }
      34                 :            : 
      35                 :          0 :                 iq->inst_cnt_prev = 0;
      36                 :            :         }
      37                 :          0 :         rte_write64(OTX2_SDP_REQUEST_ISM, iq->inst_cnt_reg);
      38                 :            : 
      39                 :            :         /* Modulo of the new index with the IQ size will give us
      40                 :            :          * the new index.
      41                 :            :          */
      42                 :          0 :         return iq->inst_cnt & (iq->nb_desc - 1);
      43                 :            : }
      44                 :            : 
      45                 :            : static inline uint32_t
      46                 :          0 : cnxk_ep_check_tx_pkt_reg(void *tx_queue)
      47                 :            : {
      48                 :            :         struct otx_ep_instr_queue *iq = (struct otx_ep_instr_queue *)tx_queue;
      49                 :            :         uint32_t val;
      50                 :            : 
      51                 :          0 :         val = rte_read32(iq->inst_cnt_reg);
      52                 :          0 :         iq->inst_cnt += val - iq->inst_cnt_prev;
      53                 :          0 :         iq->inst_cnt_prev = val;
      54                 :            : 
      55         [ #  # ]:          0 :         if (val > (uint32_t)(1 << 31)) {
      56                 :            :                 /* Only subtract the packet count in the HW counter
      57                 :            :                  * when count above halfway to saturation.
      58                 :            :                  */
      59                 :          0 :                 rte_write64((uint64_t)val, iq->inst_cnt_reg);
      60                 :            :                 rte_mb();
      61                 :            : 
      62                 :          0 :                 iq->inst_cnt_prev = 0;
      63                 :            :         }
      64                 :            : 
      65                 :            :         /* Modulo of the new index with the IQ size will give us
      66                 :            :          * the new index.
      67                 :            :          */
      68                 :          0 :         return iq->inst_cnt & (iq->nb_desc - 1);
      69                 :            : }
      70                 :            : 
      71                 :            : static inline void
      72                 :          0 : cnxk_ep_flush_iq(struct otx_ep_instr_queue *iq)
      73                 :            : {
      74                 :          0 :         const otx_ep_check_pkt_count_t cnxk_tx_pkt_count[2] = { cnxk_ep_check_tx_pkt_reg,
      75                 :            :                                                                 cnxk_ep_check_tx_ism_mem };
      76                 :            : 
      77                 :            :         uint32_t instr_processed = 0;
      78                 :            :         uint32_t cnt = 0;
      79                 :            : 
      80                 :          0 :         iq->otx_read_index = cnxk_tx_pkt_count[iq->ism_ena](iq);
      81                 :            : 
      82         [ #  # ]:          0 :         if (unlikely(iq->flush_index == iq->otx_read_index))
      83                 :          0 :                 return;
      84                 :            : 
      85         [ #  # ]:          0 :         if (iq->flush_index < iq->otx_read_index) {
      86                 :          0 :                 instr_processed = iq->otx_read_index - iq->flush_index;
      87                 :          0 :                 rte_pktmbuf_free_bulk(&iq->mbuf_list[iq->flush_index], instr_processed);
      88                 :          0 :                 iq->flush_index = otx_ep_incr_index(iq->flush_index, instr_processed, iq->nb_desc);
      89                 :            :         } else {
      90                 :          0 :                 cnt = iq->nb_desc - iq->flush_index;
      91                 :          0 :                 rte_pktmbuf_free_bulk(&iq->mbuf_list[iq->flush_index], cnt);
      92                 :          0 :                 iq->flush_index = otx_ep_incr_index(iq->flush_index, cnt, iq->nb_desc);
      93                 :            : 
      94                 :          0 :                 instr_processed = iq->otx_read_index;
      95                 :          0 :                 rte_pktmbuf_free_bulk(&iq->mbuf_list[iq->flush_index], instr_processed);
      96                 :          0 :                 iq->flush_index = otx_ep_incr_index(iq->flush_index, instr_processed, iq->nb_desc);
      97                 :            : 
      98                 :          0 :                 instr_processed += cnt;
      99                 :            :         }
     100                 :            : 
     101                 :          0 :         iq->stats.instr_processed = instr_processed;
     102                 :          0 :         iq->instr_pending -= instr_processed;
     103                 :            : }
     104                 :            : 
     105                 :            : static inline void
     106                 :            : set_sg_size(struct otx_ep_sg_entry *sg_entry, uint16_t size, uint32_t pos)
     107                 :            : {
     108                 :            : #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
     109                 :            :         sg_entry->u.size[pos] = size;
     110                 :            : #elif RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
     111                 :          0 :         sg_entry->u.size[(OTX_EP_NUM_SG_PTRS - 1) - pos] = size;
     112                 :            : #endif
     113                 :            : }
     114                 :            : 
     115                 :            : static __rte_always_inline void
     116                 :            : cnxk_ep_xmit_pkts_scalar(struct rte_mbuf **tx_pkts, struct otx_ep_instr_queue *iq, uint16_t nb_pkts)
     117                 :            : {
     118                 :            :         struct cnxk_ep_instr_32B *iqcmd;
     119                 :            :         struct rte_mbuf *m;
     120                 :            :         uint32_t pkt_len;
     121                 :            :         uint32_t tx_bytes = 0;
     122                 :          0 :         uint32_t write_idx = iq->host_write_index;
     123                 :            :         uint16_t pkts, nb_desc = iq->nb_desc;
     124                 :          0 :         uint8_t desc_size = iq->desc_size;
     125                 :            : 
     126         [ #  # ]:          0 :         for (pkts = 0; pkts < nb_pkts; pkts++) {
     127                 :          0 :                 m = tx_pkts[pkts];
     128                 :          0 :                 iq->mbuf_list[write_idx] = m;
     129                 :          0 :                 pkt_len = rte_pktmbuf_data_len(m);
     130                 :            : 
     131                 :          0 :                 iqcmd = (struct cnxk_ep_instr_32B *)(iq->base_addr + (write_idx * desc_size));
     132                 :          0 :                 iqcmd->ih.u64 = iq->partial_ih | pkt_len;
     133                 :          0 :                 iqcmd->dptr = rte_mbuf_data_iova(m); /*dptr*/
     134                 :          0 :                 tx_bytes += pkt_len;
     135                 :            : 
     136                 :            :                 /* Increment the host write index */
     137                 :            :                 write_idx = otx_ep_incr_index(write_idx, 1, nb_desc);
     138                 :            :         }
     139                 :          0 :         iq->host_write_index = write_idx;
     140                 :            : 
     141                 :            :         /* ring dbell */
     142                 :          0 :         rte_io_wmb();
     143                 :          0 :         rte_write64(pkts, iq->doorbell_reg);
     144                 :          0 :         iq->instr_pending += pkts;
     145                 :          0 :         iq->stats.tx_pkts += pkts;
     146                 :          0 :         iq->stats.tx_bytes += tx_bytes;
     147                 :            : }
     148                 :            : 
     149                 :            : static __rte_always_inline uint16_t
     150                 :            : cnxk_ep_xmit_pkts_scalar_mseg(struct rte_mbuf **tx_pkts, struct otx_ep_instr_queue *iq,
     151                 :            :                               uint16_t nb_pkts)
     152                 :            : {
     153                 :            :         uint16_t frags, num_sg, mask = OTX_EP_NUM_SG_PTRS - 1;
     154                 :            :         struct otx_ep_buf_free_info *finfo;
     155                 :            :         struct cnxk_ep_instr_32B *iqcmd;
     156                 :            :         struct rte_mbuf *m;
     157                 :            :         uint32_t pkt_len, tx_bytes = 0;
     158                 :          0 :         uint32_t write_idx = iq->host_write_index;
     159                 :            :         uint16_t pkts, nb_desc = iq->nb_desc;
     160                 :          0 :         uint8_t desc_size = iq->desc_size;
     161                 :            : 
     162         [ #  # ]:          0 :         for (pkts = 0; pkts < nb_pkts; pkts++) {
     163                 :            :                 uint16_t j = 0;
     164                 :            : 
     165                 :          0 :                 m = tx_pkts[pkts];
     166                 :          0 :                 frags = m->nb_segs;
     167                 :            : 
     168                 :          0 :                 pkt_len = rte_pktmbuf_pkt_len(m);
     169                 :          0 :                 num_sg = (frags + mask) / OTX_EP_NUM_SG_PTRS;
     170                 :            : 
     171         [ #  # ]:          0 :                 if (unlikely(pkt_len > OTX_EP_MAX_PKT_SZ && num_sg > OTX_EP_MAX_SG_LISTS)) {
     172                 :          0 :                         otx_ep_err("Failed to xmit the pkt, pkt_len is higher or pkt has more segments\n");
     173                 :          0 :                         goto exit;
     174                 :            :                 }
     175                 :            : 
     176                 :          0 :                 finfo = &iq->req_list[write_idx].finfo;
     177                 :            : 
     178                 :          0 :                 iq->mbuf_list[write_idx] = m;
     179                 :          0 :                 iqcmd = (struct cnxk_ep_instr_32B *)(iq->base_addr + (write_idx * desc_size));
     180                 :          0 :                 iqcmd->dptr = rte_mem_virt2iova(finfo->g.sg);
     181                 :          0 :                 iqcmd->ih.u64 = iq->partial_ih | (1ULL << 62) | ((uint64_t)frags << 48) | pkt_len;
     182                 :            : 
     183         [ #  # ]:          0 :                 while (frags--) {
     184                 :          0 :                         finfo->g.sg[(j >> 2)].ptr[(j & mask)] = rte_mbuf_data_iova(m);
     185                 :          0 :                         set_sg_size(&finfo->g.sg[(j >> 2)], m->data_len, (j & mask));
     186                 :          0 :                         j++;
     187                 :          0 :                         m = m->next;
     188                 :            :                 }
     189                 :            : 
     190                 :            :                 /* Increment the host write index */
     191                 :            :                 write_idx = otx_ep_incr_index(write_idx, 1, nb_desc);
     192                 :          0 :                 tx_bytes += pkt_len;
     193                 :            :         }
     194                 :          0 : exit:
     195                 :          0 :         iq->host_write_index = write_idx;
     196                 :            : 
     197                 :            :         /* ring dbell */
     198                 :          0 :         rte_io_wmb();
     199                 :          0 :         rte_write64(pkts, iq->doorbell_reg);
     200                 :          0 :         iq->instr_pending += pkts;
     201                 :          0 :         iq->stats.tx_pkts += pkts;
     202                 :          0 :         iq->stats.tx_bytes += tx_bytes;
     203                 :            : 
     204                 :            :         return pkts;
     205                 :            : }
     206                 :            : 
     207                 :            : uint16_t __rte_noinline __rte_hot
     208                 :          0 : cnxk_ep_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
     209                 :            : {
     210                 :            :         struct otx_ep_instr_queue *iq = (struct otx_ep_instr_queue *)tx_queue;
     211                 :            :         uint16_t pkts;
     212                 :            : 
     213                 :          0 :         pkts = RTE_MIN(nb_pkts, iq->nb_desc - iq->instr_pending);
     214                 :            : 
     215                 :            :         cnxk_ep_xmit_pkts_scalar(tx_pkts, iq, pkts);
     216                 :            : 
     217         [ #  # ]:          0 :         if (iq->instr_pending >= OTX_EP_MAX_INSTR)
     218                 :          0 :                 cnxk_ep_flush_iq(iq);
     219                 :            : 
     220                 :            :         /* Return no# of instructions posted successfully. */
     221                 :          0 :         return pkts;
     222                 :            : }
     223                 :            : 
     224                 :            : uint16_t __rte_noinline __rte_hot
     225                 :          0 : cnxk_ep_xmit_pkts_mseg(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
     226                 :            : {
     227                 :            :         struct otx_ep_instr_queue *iq = (struct otx_ep_instr_queue *)tx_queue;
     228                 :            :         uint16_t pkts;
     229                 :            : 
     230                 :          0 :         pkts = RTE_MIN(nb_pkts, iq->nb_desc - iq->instr_pending);
     231                 :            : 
     232                 :            :         pkts = cnxk_ep_xmit_pkts_scalar_mseg(tx_pkts, iq, pkts);
     233                 :            : 
     234         [ #  # ]:          0 :         if (iq->instr_pending >= OTX_EP_MAX_INSTR)
     235                 :          0 :                 cnxk_ep_flush_iq(iq);
     236                 :            : 
     237                 :            :         /* Return no# of instructions posted successfully. */
     238                 :          0 :         return pkts;
     239                 :            : }

Generated by: LCOV version 1.14