LCOV - code coverage report
Current view: top level - drivers/net/enic/base - vnic_wq.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 79 0.0 %
Date: 2024-02-14 00:53:57 Functions: 0 10 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 16 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2008-2017 Cisco Systems, Inc.  All rights reserved.
       3                 :            :  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "vnic_dev.h"
       7                 :            : #include "vnic_wq.h"
       8                 :            : 
       9                 :            : static inline
      10                 :            : int vnic_wq_get_ctrl(struct vnic_dev *vdev, struct vnic_wq *wq,
      11                 :            :                                 unsigned int index, enum vnic_res_type res_type)
      12                 :            : {
      13                 :          0 :         wq->ctrl = vnic_dev_get_res(vdev, res_type, index);
      14         [ #  # ]:          0 :         if (!wq->ctrl)
      15                 :            :                 return -EINVAL;
      16                 :            :         return 0;
      17                 :            : }
      18                 :            : 
      19                 :            : static inline
      20                 :          0 : int vnic_wq_alloc_ring(struct vnic_dev *vdev, struct vnic_wq *wq,
      21                 :            :                                 unsigned int desc_count, unsigned int desc_size)
      22                 :            : {
      23                 :            :         char res_name[RTE_MEMZONE_NAMESIZE];
      24                 :            :         static int instance;
      25                 :            : 
      26                 :          0 :         snprintf(res_name, sizeof(res_name), "%d-wq-%u", instance++, wq->index);
      27                 :          0 :         return vnic_dev_alloc_desc_ring(vdev, &wq->ring, desc_count, desc_size,
      28                 :            :                 wq->socket_id, res_name);
      29                 :            : }
      30                 :            : 
      31                 :          0 : static int vnic_wq_alloc_bufs(struct vnic_wq *wq)
      32                 :            : {
      33                 :          0 :         unsigned int count = wq->ring.desc_count;
      34                 :            :        /* Allocate the mbuf ring */
      35                 :          0 :         wq->bufs = (struct rte_mbuf **)rte_zmalloc_socket("wq->bufs",
      36                 :            :                     sizeof(struct rte_mbuf *) * count,
      37                 :          0 :                     RTE_CACHE_LINE_SIZE, wq->socket_id);
      38                 :          0 :         wq->head_idx = 0;
      39                 :          0 :         wq->tail_idx = 0;
      40         [ #  # ]:          0 :         if (wq->bufs == NULL)
      41                 :          0 :                 return -ENOMEM;
      42                 :            :         return 0;
      43                 :            : }
      44                 :            : 
      45                 :          0 : void vnic_wq_free(struct vnic_wq *wq)
      46                 :            : {
      47                 :            :         struct vnic_dev *vdev;
      48                 :            : 
      49                 :          0 :         vdev = wq->vdev;
      50                 :            : 
      51                 :          0 :         vnic_dev_free_desc_ring(vdev, &wq->ring);
      52                 :            : 
      53                 :          0 :         rte_free(wq->bufs);
      54                 :          0 :         wq->ctrl = NULL;
      55                 :          0 : }
      56                 :            : 
      57                 :            : 
      58                 :          0 : int vnic_wq_alloc(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int index,
      59                 :            :         unsigned int desc_count, unsigned int desc_size)
      60                 :            : {
      61                 :            :         int err;
      62                 :            : 
      63                 :          0 :         wq->index = index;
      64                 :          0 :         wq->vdev = vdev;
      65                 :            : 
      66                 :            :         err = vnic_wq_get_ctrl(vdev, wq, index, RES_TYPE_WQ);
      67                 :            :         if (err) {
      68                 :          0 :                 pr_err("Failed to hook WQ[%d] resource, err %d\n", index, err);
      69                 :          0 :                 return err;
      70                 :            :         }
      71                 :            : 
      72                 :          0 :         vnic_wq_disable(wq);
      73                 :            : 
      74                 :          0 :         err = vnic_wq_alloc_ring(vdev, wq, desc_count, desc_size);
      75         [ #  # ]:          0 :         if (err)
      76                 :            :                 return err;
      77                 :            : 
      78                 :          0 :         err = vnic_wq_alloc_bufs(wq);
      79         [ #  # ]:          0 :         if (err) {
      80                 :          0 :                 vnic_wq_free(wq);
      81                 :          0 :                 return err;
      82                 :            :         }
      83                 :            : 
      84                 :            :         return 0;
      85                 :            : }
      86                 :            : 
      87                 :          0 : void vnic_wq_init_start(struct vnic_wq *wq, unsigned int cq_index,
      88                 :            :         unsigned int fetch_index, unsigned int posted_index,
      89                 :            :         unsigned int error_interrupt_enable,
      90                 :            :         unsigned int error_interrupt_offset)
      91                 :            : {
      92                 :            :         uint64_t paddr;
      93                 :          0 :         unsigned int count = wq->ring.desc_count;
      94                 :            : 
      95                 :          0 :         paddr = (uint64_t)wq->ring.base_addr | VNIC_PADDR_TARGET;
      96                 :          0 :         writeq(paddr, &wq->ctrl->ring_base);
      97                 :          0 :         iowrite32(count, &wq->ctrl->ring_size);
      98                 :          0 :         iowrite32(fetch_index, &wq->ctrl->fetch_index);
      99                 :          0 :         iowrite32(posted_index, &wq->ctrl->posted_index);
     100                 :          0 :         iowrite32(cq_index, &wq->ctrl->cq_index);
     101                 :          0 :         iowrite32(error_interrupt_enable, &wq->ctrl->error_interrupt_enable);
     102                 :          0 :         iowrite32(error_interrupt_offset, &wq->ctrl->error_interrupt_offset);
     103                 :          0 :         iowrite32(0, &wq->ctrl->error_status);
     104                 :            : 
     105                 :          0 :         wq->head_idx = fetch_index;
     106                 :          0 :         wq->tail_idx = wq->head_idx;
     107                 :          0 : }
     108                 :            : 
     109                 :          0 : void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index,
     110                 :            :         unsigned int error_interrupt_enable,
     111                 :            :         unsigned int error_interrupt_offset)
     112                 :            : {
     113                 :          0 :         vnic_wq_init_start(wq, cq_index, 0, 0,
     114                 :            :                 error_interrupt_enable,
     115                 :            :                 error_interrupt_offset);
     116                 :          0 :         wq->cq_pend = 0;
     117                 :          0 :         wq->last_completed_index = 0;
     118                 :          0 : }
     119                 :            : 
     120                 :          0 : unsigned int vnic_wq_error_status(struct vnic_wq *wq)
     121                 :            : {
     122                 :          0 :         return ioread32(&wq->ctrl->error_status);
     123                 :            : }
     124                 :            : 
     125                 :          0 : void vnic_wq_enable(struct vnic_wq *wq)
     126                 :            : {
     127                 :          0 :         iowrite32(1, &wq->ctrl->enable);
     128                 :          0 : }
     129                 :            : 
     130                 :          0 : int vnic_wq_disable(struct vnic_wq *wq)
     131                 :            : {
     132                 :            :         unsigned int wait;
     133                 :            : 
     134                 :          0 :         iowrite32(0, &wq->ctrl->enable);
     135                 :            : 
     136                 :            :         /* Wait for HW to ACK disable request */
     137         [ #  # ]:          0 :         for (wait = 0; wait < 1000; wait++) {
     138         [ #  # ]:          0 :                 if (!(ioread32(&wq->ctrl->running)))
     139                 :            :                         return 0;
     140                 :          0 :                 usleep(10);
     141                 :            :         }
     142                 :            : 
     143                 :          0 :         pr_err("Failed to disable WQ[%d]\n", wq->index);
     144                 :            : 
     145                 :          0 :         return -ETIMEDOUT;
     146                 :            : }
     147                 :            : 
     148                 :          0 : void vnic_wq_clean(struct vnic_wq *wq,
     149                 :            :                    void (*buf_clean)(struct rte_mbuf **buf))
     150                 :            : {
     151                 :            :         struct rte_mbuf **buf;
     152                 :          0 :         unsigned int  to_clean = wq->tail_idx;
     153                 :            : 
     154                 :          0 :         buf = &wq->bufs[to_clean];
     155                 :            : 
     156         [ #  # ]:          0 :         while (vnic_wq_desc_used(wq) > 0) {
     157                 :            : 
     158                 :          0 :                 (*buf_clean)(buf);
     159         [ #  # ]:          0 :                 to_clean = buf_idx_incr(wq->ring.desc_count, to_clean);
     160                 :            : 
     161                 :          0 :                 buf = &wq->bufs[to_clean];
     162                 :          0 :                 wq->ring.desc_avail++;
     163                 :            :         }
     164                 :            : 
     165                 :          0 :         wq->head_idx = 0;
     166                 :          0 :         wq->tail_idx = 0;
     167                 :          0 :         wq->last_completed_index = 0;
     168                 :          0 :         *((uint32_t *)wq->cqmsg_rz->addr) = 0;
     169                 :            : 
     170                 :          0 :         iowrite32(0, &wq->ctrl->fetch_index);
     171                 :          0 :         iowrite32(0, &wq->ctrl->posted_index);
     172                 :          0 :         iowrite32(0, &wq->ctrl->error_status);
     173                 :            : 
     174                 :          0 :         vnic_dev_clear_desc_ring(&wq->ring);
     175                 :          0 : }

Generated by: LCOV version 1.14