LCOV - code coverage report
Current view: top level - drivers/crypto/octeontx - otx_cryptodev_mbox.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 79 0.0 %
Date: 2025-01-02 22:41:34 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 38 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2018 Cavium, Inc
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <unistd.h>
       6                 :            : 
       7                 :            : #include "otx_cryptodev_hw_access.h"
       8                 :            : #include "otx_cryptodev_mbox.h"
       9                 :            : 
      10                 :            : void
      11                 :          0 : otx_cpt_handle_mbox_intr(struct cpt_vf *cptvf)
      12                 :            : {
      13                 :            :         struct cpt_mbox mbx = {0, 0};
      14                 :            : 
      15                 :            :         /*
      16                 :            :          * MBOX[0] contains msg
      17                 :            :          * MBOX[1] contains data
      18                 :            :          */
      19   [ #  #  #  #  :          0 :         mbx.msg  = CPT_READ_CSR(CPT_CSR_REG_BASE(cptvf),
                #  #  # ]
      20                 :            :                                 CPTX_VFX_PF_MBOXX(0, 0, 0));
      21                 :            :         mbx.data = CPT_READ_CSR(CPT_CSR_REG_BASE(cptvf),
      22                 :            :                                 CPTX_VFX_PF_MBOXX(0, 0, 1));
      23                 :            : 
      24                 :            :         CPT_LOG_DP_DEBUG("%s: Mailbox msg 0x%lx from PF",
      25                 :            :                     cptvf->dev_name, (unsigned int long)mbx.msg);
      26   [ #  #  #  #  :          0 :         switch (mbx.msg) {
                #  #  # ]
      27                 :          0 :         case OTX_CPT_MSG_VF_UP:
      28                 :          0 :                 cptvf->pf_acked = true;
      29                 :          0 :                 break;
      30                 :          0 :         case OTX_CPT_MSG_READY:
      31                 :            :                 {
      32                 :            :                         otx_cpt_chipid_vfid_t cid;
      33                 :            : 
      34                 :            :                         cid.u64 = mbx.data;
      35                 :          0 :                         cptvf->pf_acked = true;
      36                 :          0 :                         cptvf->vfid = cid.s.vfid;
      37                 :            :                         CPT_LOG_DP_DEBUG("%s: Received VFID %d chip_id %d",
      38                 :            :                                          cptvf->dev_name,
      39                 :            :                                          cptvf->vfid, cid.s.chip_id);
      40                 :            :                 }
      41                 :          0 :                 break;
      42                 :          0 :         case OTX_CPT_MSG_QBIND_GRP:
      43                 :          0 :                 cptvf->pf_acked = true;
      44                 :          0 :                 cptvf->vftype = mbx.data;
      45                 :            :                 CPT_LOG_DP_DEBUG("%s: VF %d group %d",
      46                 :            :                                  cptvf->dev_name, cptvf->vfid,
      47                 :            :                                  cptvf->vfgrp);
      48                 :          0 :                 break;
      49                 :          0 :         case OTX_CPT_MSG_PF_TYPE:
      50                 :          0 :                 cptvf->pf_acked = true;
      51         [ #  # ]:          0 :                 if (mbx.data == OTX_CPT_PF_TYPE_AE)
      52                 :          0 :                         cptvf->vftype = OTX_CPT_VF_TYPE_AE;
      53         [ #  # ]:          0 :                 else if (mbx.data == OTX_CPT_PF_TYPE_SE)
      54                 :          0 :                         cptvf->vftype = OTX_CPT_VF_TYPE_SE;
      55                 :            :                 else
      56                 :          0 :                         cptvf->vftype = OTX_CPT_VF_TYPE_INVALID;
      57                 :            :                 break;
      58                 :          0 :         case OTX_CPT_MBOX_MSG_TYPE_ACK:
      59                 :          0 :                 cptvf->pf_acked = true;
      60                 :          0 :                 break;
      61                 :          0 :         case OTX_CPT_MBOX_MSG_TYPE_NACK:
      62                 :          0 :                 cptvf->pf_nacked = true;
      63                 :          0 :                 break;
      64                 :            :         default:
      65                 :            :                 CPT_LOG_DP_DEBUG("%s: Invalid msg from PF, msg 0x%lx",
      66                 :            :                                  cptvf->dev_name, (unsigned int long)mbx.msg);
      67                 :            :                 break;
      68                 :            :         }
      69                 :          0 : }
      70                 :            : 
      71                 :            : /* Send a mailbox message to PF
      72                 :            :  * @vf: vf from which this message to be sent
      73                 :            :  * @mbx: Message to be sent
      74                 :            :  */
      75                 :            : static void
      76                 :            : otx_cpt_send_msg_to_pf(struct cpt_vf *cptvf, struct cpt_mbox *mbx)
      77                 :            : {
      78                 :            :         /* Writing mbox(1) causes interrupt */
      79                 :          0 :         CPT_WRITE_CSR(CPT_CSR_REG_BASE(cptvf),
      80                 :            :                       CPTX_VFX_PF_MBOXX(0, 0, 0), mbx->msg);
      81                 :          0 :         CPT_WRITE_CSR(CPT_CSR_REG_BASE(cptvf),
      82                 :            :                       CPTX_VFX_PF_MBOXX(0, 0, 1), mbx->data);
      83                 :          0 : }
      84                 :            : 
      85                 :            : static int32_t
      86                 :          0 : otx_cpt_send_msg_to_pf_timeout(struct cpt_vf *cptvf, struct cpt_mbox *mbx)
      87                 :            : {
      88                 :            :         int timeout = OTX_CPT_MBOX_MSG_TIMEOUT;
      89                 :            :         int sleep_ms = 10;
      90                 :            : 
      91                 :          0 :         cptvf->pf_acked = false;
      92                 :          0 :         cptvf->pf_nacked = false;
      93                 :            : 
      94                 :            :         otx_cpt_send_msg_to_pf(cptvf, mbx);
      95                 :            : 
      96                 :            :         /* Wait for previous message to be acked, timeout 2sec */
      97         [ #  # ]:          0 :         while (!cptvf->pf_acked) {
      98         [ #  # ]:          0 :                 if (cptvf->pf_nacked)
      99                 :            :                         return -EINVAL;
     100                 :          0 :                 usleep(sleep_ms * 1000);
     101                 :          0 :                 otx_cpt_poll_misc(cptvf);
     102         [ #  # ]:          0 :                 if (cptvf->pf_acked)
     103                 :            :                         break;
     104                 :          0 :                 timeout -= sleep_ms;
     105         [ #  # ]:          0 :                 if (!timeout) {
     106                 :          0 :                         CPT_LOG_ERR("%s: PF didn't ack mbox msg %lx(vfid %u)",
     107                 :            :                                     cptvf->dev_name,
     108                 :            :                                     (unsigned int long)(mbx->msg & 0xFF),
     109                 :            :                                     cptvf->vfid);
     110                 :          0 :                         return -EBUSY;
     111                 :            :                 }
     112                 :            :         }
     113                 :            :         return 0;
     114                 :            : }
     115                 :            : 
     116                 :            : int
     117                 :          0 : otx_cpt_check_pf_ready(struct cpt_vf *cptvf)
     118                 :            : {
     119                 :          0 :         struct cpt_mbox mbx = {0, 0};
     120                 :            : 
     121                 :          0 :         mbx.msg = OTX_CPT_MSG_READY;
     122         [ #  # ]:          0 :         if (otx_cpt_send_msg_to_pf_timeout(cptvf, &mbx)) {
     123                 :          0 :                 CPT_LOG_ERR("%s: PF didn't respond to READY msg",
     124                 :            :                             cptvf->dev_name);
     125                 :          0 :                 return 1;
     126                 :            :         }
     127                 :            :         return 0;
     128                 :            : }
     129                 :            : 
     130                 :            : int
     131                 :          0 : otx_cpt_get_dev_type(struct cpt_vf *cptvf)
     132                 :            : {
     133                 :          0 :         struct cpt_mbox mbx = {0, 0};
     134                 :            : 
     135                 :          0 :         mbx.msg = OTX_CPT_MSG_PF_TYPE;
     136         [ #  # ]:          0 :         if (otx_cpt_send_msg_to_pf_timeout(cptvf, &mbx)) {
     137                 :          0 :                 CPT_LOG_ERR("%s: PF didn't respond to query msg",
     138                 :            :                             cptvf->dev_name);
     139                 :          0 :                 return 1;
     140                 :            :         }
     141                 :            :         return 0;
     142                 :            : }
     143                 :            : 
     144                 :            : int
     145                 :          0 : otx_cpt_send_vq_size_msg(struct cpt_vf *cptvf)
     146                 :            : {
     147                 :            :         struct cpt_mbox mbx = {0, 0};
     148                 :            : 
     149                 :          0 :         mbx.msg = OTX_CPT_MSG_QLEN;
     150                 :            : 
     151                 :          0 :         mbx.data = cptvf->qsize;
     152         [ #  # ]:          0 :         if (otx_cpt_send_msg_to_pf_timeout(cptvf, &mbx)) {
     153                 :          0 :                 CPT_LOG_ERR("%s: PF didn't respond to vq_size msg",
     154                 :            :                             cptvf->dev_name);
     155                 :          0 :                 return 1;
     156                 :            :         }
     157                 :            :         return 0;
     158                 :            : }
     159                 :            : 
     160                 :            : int
     161                 :          0 : otx_cpt_send_vf_grp_msg(struct cpt_vf *cptvf, uint32_t group)
     162                 :            : {
     163                 :            :         struct cpt_mbox mbx = {0, 0};
     164                 :            : 
     165                 :          0 :         mbx.msg = OTX_CPT_MSG_QBIND_GRP;
     166                 :            : 
     167                 :            :         /* Convey group of the VF */
     168                 :          0 :         mbx.data = group;
     169         [ #  # ]:          0 :         if (otx_cpt_send_msg_to_pf_timeout(cptvf, &mbx)) {
     170                 :          0 :                 CPT_LOG_ERR("%s: PF didn't respond to vf_type msg",
     171                 :            :                             cptvf->dev_name);
     172                 :          0 :                 return 1;
     173                 :            :         }
     174                 :            :         return 0;
     175                 :            : }
     176                 :            : 
     177                 :            : int
     178                 :          0 : otx_cpt_send_vf_up(struct cpt_vf *cptvf)
     179                 :            : {
     180                 :          0 :         struct cpt_mbox mbx = {0, 0};
     181                 :            : 
     182                 :          0 :         mbx.msg = OTX_CPT_MSG_VF_UP;
     183         [ #  # ]:          0 :         if (otx_cpt_send_msg_to_pf_timeout(cptvf, &mbx)) {
     184                 :          0 :                 CPT_LOG_ERR("%s: PF didn't respond to UP msg",
     185                 :            :                             cptvf->dev_name);
     186                 :          0 :                 return 1;
     187                 :            :         }
     188                 :            :         return 0;
     189                 :            : }
     190                 :            : 
     191                 :            : int
     192                 :          0 : otx_cpt_send_vf_down(struct cpt_vf *cptvf)
     193                 :            : {
     194                 :          0 :         struct cpt_mbox mbx = {0, 0};
     195                 :            : 
     196                 :          0 :         mbx.msg = OTX_CPT_MSG_VF_DOWN;
     197         [ #  # ]:          0 :         if (otx_cpt_send_msg_to_pf_timeout(cptvf, &mbx)) {
     198                 :          0 :                 CPT_LOG_ERR("%s: PF didn't respond to DOWN msg",
     199                 :            :                             cptvf->dev_name);
     200                 :          0 :                 return 1;
     201                 :            :         }
     202                 :            :         return 0;
     203                 :            : }

Generated by: LCOV version 1.14