LCOV - code coverage report
Current view: top level - drivers/net/cnxk - cnxk_eswitch_rxtx.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 36 0.0 %
Date: 2024-04-01 19:00:53 Functions: 0 3 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) 2024 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <cnxk_eswitch.h>
       6                 :            : 
       7                 :            : static __rte_always_inline struct rte_mbuf *
       8                 :            : eswitch_nix_get_mbuf_from_cqe(void *cq, const uint64_t data_off)
       9                 :            : {
      10                 :            :         rte_iova_t buff;
      11                 :            : 
      12                 :            :         /* Skip CQE, NIX_RX_PARSE_S and SG HDR(9 DWORDs) and peek buff addr */
      13                 :            :         buff = *((rte_iova_t *)((uint64_t *)cq + 9));
      14                 :            :         return (struct rte_mbuf *)(buff - data_off);
      15                 :            : }
      16                 :            : 
      17                 :            : static inline uint64_t
      18                 :            : eswitch_nix_rx_nb_pkts(struct roc_nix_cq *cq, const uint64_t wdata, const uint32_t qmask)
      19                 :            : {
      20                 :            :         uint64_t reg, head, tail;
      21                 :            :         uint32_t available;
      22                 :            : 
      23                 :            :         /* Update the available count if cached value is not enough */
      24                 :            : 
      25                 :            :         /* Use LDADDA version to avoid reorder */
      26                 :            :         reg = roc_atomic64_add_sync(wdata, cq->status);
      27                 :            :         /* CQ_OP_STATUS operation error */
      28                 :            :         if (reg & BIT_ULL(NIX_CQ_OP_STAT_OP_ERR) || reg & BIT_ULL(NIX_CQ_OP_STAT_CQ_ERR))
      29                 :            :                 return 0;
      30                 :            : 
      31                 :            :         tail = reg & 0xFFFFF;
      32                 :            :         head = (reg >> 20) & 0xFFFFF;
      33                 :            :         if (tail < head)
      34                 :            :                 available = tail - head + qmask + 1;
      35                 :            :         else
      36                 :            :                 available = tail - head;
      37                 :            : 
      38                 :            :         return available;
      39                 :            : }
      40                 :            : 
      41                 :            : static inline void
      42                 :          0 : nix_cn9k_xmit_one(uint64_t *cmd, void *lmt_addr, const plt_iova_t io_addr)
      43                 :            : {
      44                 :            :         uint64_t lmt_status;
      45                 :            : 
      46                 :            :         do {
      47                 :            :                 roc_lmt_mov(lmt_addr, cmd, 0);
      48                 :            :                 lmt_status = roc_lmt_submit_ldeor(io_addr);
      49                 :            :         } while (lmt_status == 0);
      50                 :            : }
      51                 :            : 
      52                 :            : uint16_t
      53                 :          0 : cnxk_eswitch_dev_tx_burst(struct cnxk_eswitch_dev *eswitch_dev, uint16_t qid,
      54                 :            :                           struct rte_mbuf **pkts, uint16_t nb_xmit, const uint16_t flags)
      55                 :            : {
      56                 :          0 :         struct roc_nix_sq *sq = &eswitch_dev->txq[qid].sqs;
      57                 :            :         struct roc_nix_rq *rq = &eswitch_dev->rxq[qid].rqs;
      58                 :            :         uint64_t aura_handle, cmd[6], data = 0;
      59                 :            :         uint16_t lmt_id, pkt = 0, nb_tx = 0;
      60                 :            :         struct nix_send_ext_s *send_hdr_ext;
      61                 :            :         struct nix_send_hdr_s *send_hdr;
      62                 :            :         uint16_t vlan_tci = qid;
      63                 :            :         union nix_send_sg_s *sg;
      64                 :            :         uintptr_t lmt_base, pa;
      65                 :            :         int64_t fc_pkts, dw_m1;
      66                 :            :         rte_iova_t io_addr;
      67                 :            : 
      68         [ #  # ]:          0 :         if (unlikely(eswitch_dev->txq[qid].state != CNXK_ESWITCH_QUEUE_STATE_STARTED))
      69                 :            :                 return 0;
      70                 :            : 
      71                 :          0 :         lmt_base = sq->roc_nix->lmt_base;
      72                 :            :         io_addr = sq->io_addr;
      73                 :            :         aura_handle = rq->aura_handle;
      74                 :            :         /* Get LMT base address and LMT ID as per thread ID */
      75                 :          0 :         lmt_id = roc_plt_control_lmt_id_get();
      76         [ #  # ]:          0 :         lmt_base += ((uint64_t)lmt_id << ROC_LMT_LINE_SIZE_LOG2);
      77                 :            :         /* Double word minus 1: LMTST size-1 in units of 128 bits */
      78                 :            :         /* 2(HDR) + 2(EXT_HDR) + 1(SG) + 1(IOVA) = 6/2 - 1 = 2 */
      79         [ #  # ]:          0 :         dw_m1 = cn10k_nix_tx_ext_subs(flags) + 1;
      80                 :            : 
      81                 :            :         memset(cmd, 0, sizeof(cmd));
      82                 :            :         send_hdr = (struct nix_send_hdr_s *)&cmd[0];
      83                 :          0 :         send_hdr->w0.sizem1 = dw_m1;
      84                 :          0 :         send_hdr->w0.sq = sq->qid;
      85                 :            : 
      86         [ #  # ]:          0 :         if (dw_m1 >= 2) {
      87                 :            :                 send_hdr_ext = (struct nix_send_ext_s *)&cmd[2];
      88                 :          0 :                 send_hdr_ext->w0.subdc = NIX_SUBDC_EXT;
      89         [ #  # ]:          0 :                 if (flags & NIX_TX_OFFLOAD_VLAN_QINQ_F) {
      90                 :          0 :                         send_hdr_ext->w1.vlan0_ins_ena = true;
      91                 :            :                         /* 2B before end of l2 header */
      92                 :          0 :                         send_hdr_ext->w1.vlan0_ins_ptr = 12;
      93                 :            :                         send_hdr_ext->w1.vlan0_ins_tci = 0;
      94                 :            :                 }
      95                 :            :                 sg = (union nix_send_sg_s *)&cmd[4];
      96                 :            :         } else {
      97                 :            :                 sg = (union nix_send_sg_s *)&cmd[2];
      98                 :            :         }
      99                 :            : 
     100                 :          0 :         sg->subdc = NIX_SUBDC_SG;
     101                 :          0 :         sg->segs = 1;
     102                 :          0 :         sg->ld_type = NIX_SENDLDTYPE_LDD;
     103                 :            : 
     104                 :            :         /* Tx */
     105                 :          0 :         fc_pkts = ((int64_t)sq->nb_sqb_bufs_adj - *((uint64_t *)sq->fc)) << sq->sqes_per_sqb_log2;
     106                 :            : 
     107         [ #  # ]:          0 :         if (fc_pkts < 0)
     108                 :            :                 nb_tx = 0;
     109                 :            :         else
     110                 :          0 :                 nb_tx = PLT_MIN(nb_xmit, (uint64_t)fc_pkts);
     111                 :            : 
     112         [ #  # ]:          0 :         for (pkt = 0; pkt < nb_tx; pkt++) {
     113                 :          0 :                 send_hdr->w0.total = pkts[pkt]->pkt_len;
     114         [ #  # ]:          0 :                 if (pkts[pkt]->pool) {
     115                 :          0 :                         aura_handle = pkts[pkt]->pool->pool_id;
     116                 :          0 :                         send_hdr->w0.aura = roc_npa_aura_handle_to_aura(aura_handle);
     117                 :            :                 } else {
     118                 :          0 :                         send_hdr->w0.df = 1;
     119                 :            :                 }
     120   [ #  #  #  # ]:          0 :                 if (dw_m1 >= 2 && flags & NIX_TX_OFFLOAD_VLAN_QINQ_F)
     121                 :          0 :                         send_hdr_ext->w1.vlan0_ins_tci = vlan_tci;
     122                 :          0 :                 sg->seg1_size = pkts[pkt]->pkt_len;
     123                 :          0 :                 *(plt_iova_t *)(sg + 1) = rte_mbuf_data_iova(pkts[pkt]);
     124                 :            : 
     125                 :          0 :                 plt_esw_dbg("Transmitting pkt %d (%p) vlan tci %x on sq %d esw qid %d", pkt,
     126                 :            :                             pkts[pkt], vlan_tci, sq->qid, qid);
     127         [ #  # ]:          0 :                 if (roc_model_is_cn9k()) {
     128                 :          0 :                         nix_cn9k_xmit_one(cmd, sq->lmt_addr, sq->io_addr);
     129                 :            :                 } else {
     130                 :            :                         cn10k_nix_xmit_mv_lmt_base(lmt_base, cmd, flags);
     131                 :            :                         /* PA<6:4> = LMTST size-1 in units of 128 bits. Size of the first LMTST in
     132                 :            :                          * burst.
     133                 :            :                          */
     134                 :            :                         pa = io_addr | (dw_m1 << 4);
     135                 :            :                         data &= ~0x7ULL;
     136                 :            :                         /*<15:12> = CNTM1: Count minus one of LMTSTs in the burst */
     137                 :            :                         data = (0ULL << 12);
     138                 :            :                         /* *<10:0> = LMT_ID: Identifies which LMT line is used for the first LMTST
     139                 :            :                          */
     140                 :            :                         data |= (uint64_t)lmt_id;
     141                 :            : 
     142                 :            :                         /* STEOR0 */
     143                 :            :                         roc_lmt_submit_steorl(data, pa);
     144                 :          0 :                         rte_io_wmb();
     145                 :            :                 }
     146                 :            :         }
     147                 :            : 
     148                 :            :         return nb_tx;
     149                 :            : }
     150                 :            : 
     151                 :            : uint16_t
     152                 :          0 : cnxk_eswitch_dev_rx_burst(struct cnxk_eswitch_dev *eswitch_dev, uint16_t qid,
     153                 :            :                           struct rte_mbuf **pkts, uint16_t nb_pkts)
     154                 :            : {
     155                 :            :         struct roc_nix_rq *rq = &eswitch_dev->rxq[qid].rqs;
     156                 :            :         struct roc_nix_cq *cq = &eswitch_dev->cxq[qid].cqs;
     157                 :            :         const union nix_rx_parse_u *rx;
     158                 :            :         struct nix_cqe_hdr_s *cqe;
     159                 :            :         uint64_t pkt = 0, nb_rx;
     160                 :            :         struct rte_mbuf *mbuf;
     161                 :            :         uint64_t wdata;
     162                 :            :         uint32_t qmask;
     163                 :            :         uintptr_t desc;
     164                 :            :         uint32_t head;
     165                 :            : 
     166                 :            :         if (unlikely(eswitch_dev->rxq[qid].state != CNXK_ESWITCH_QUEUE_STATE_STARTED))
     167                 :            :                 return 0;
     168                 :            : 
     169                 :            :         wdata = cq->wdata;
     170                 :            :         qmask = cq->qmask;
     171                 :            :         desc = (uintptr_t)cq->desc_base;
     172                 :            :         nb_rx = eswitch_nix_rx_nb_pkts(cq, wdata, qmask);
     173                 :            :         nb_rx = RTE_MIN(nb_rx, nb_pkts);
     174                 :            :         head = cq->head;
     175                 :            : 
     176                 :            :         /* Nothing to receive */
     177                 :            :         if (!nb_rx)
     178                 :            :                 return 0;
     179                 :            : 
     180                 :            :         /* Rx */
     181                 :            :         for (pkt = 0; pkt < nb_rx; pkt++) {
     182                 :            :                 /* Prefetch N desc ahead */
     183                 :            :                 rte_prefetch_non_temporal((void *)(desc + (CQE_SZ((head + 2) & qmask))));
     184                 :            :                 cqe = (struct nix_cqe_hdr_s *)(desc + CQE_SZ(head));
     185                 :            :                 rx = (const union nix_rx_parse_u *)((const uint64_t *)cqe + 1);
     186                 :            : 
     187                 :            :                 /* Skip QE, NIX_RX_PARSE_S and SG HDR(9 DWORDs) and peek buff addr */
     188                 :            :                 mbuf = eswitch_nix_get_mbuf_from_cqe(cqe, rq->first_skip);
     189                 :            :                 mbuf->pkt_len = rx->pkt_lenm1 + 1;
     190                 :            :                 mbuf->data_len = rx->pkt_lenm1 + 1;
     191                 :            :                 mbuf->data_off = 128;
     192                 :            :                 /* Rx parse to capture vlan info */
     193                 :            :                 if (rx->vtag0_valid)
     194                 :            :                         mbuf->vlan_tci = rx->vtag0_tci;
     195                 :            :                 /* Populate RSS hash */
     196                 :            :                 mbuf->hash.rss = cqe->tag;
     197                 :            :                 mbuf->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
     198                 :            :                 pkts[pkt] = mbuf;
     199                 :            :                 roc_prefetch_store_keep(mbuf);
     200                 :            :                 plt_esw_dbg("Packet %d rec on queue %d esw qid %d hash %x mbuf %p vlan tci %d",
     201                 :            :                             (uint32_t)pkt, rq->qid, qid, mbuf->hash.rss, mbuf, mbuf->vlan_tci);
     202                 :            :                 head++;
     203                 :            :                 head &= qmask;
     204                 :            :         }
     205                 :            : 
     206                 :            :         /* Free all the CQs that we've processed */
     207                 :            :         rte_write64_relaxed((wdata | nb_rx), (void *)cq->door);
     208                 :            :         cq->head = head;
     209                 :            : 
     210                 :            :         return nb_rx;
     211                 :            : }

Generated by: LCOV version 1.14