LCOV - code coverage report
Current view: top level - drivers/common/cnxk - roc_nix_vlan.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 113 0.0 %
Date: 2024-12-01 18:57:19 Functions: 0 9 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 46 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2021 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "roc_api.h"
       6                 :            : #include "roc_priv.h"
       7                 :            : 
       8                 :            : int
       9                 :          0 : roc_nix_vlan_mcam_entry_read(struct roc_nix *roc_nix, uint32_t index,
      10                 :            :                              struct npc_mcam_read_entry_rsp **rsp)
      11                 :            : {
      12                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      13                 :            :         struct dev *dev = &nix->dev;
      14                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
      15                 :            :         struct npc_mcam_read_entry_req *req;
      16                 :            :         int rc = -ENOSPC;
      17                 :            : 
      18                 :          0 :         req = mbox_alloc_msg_npc_mcam_read_entry(mbox);
      19         [ #  # ]:          0 :         if (req == NULL)
      20                 :          0 :                 goto exit;
      21                 :          0 :         req->entry = index;
      22                 :            : 
      23                 :            :         rc = mbox_process_msg(mbox, (void **)rsp);
      24                 :          0 : exit:
      25                 :            :         mbox_put(mbox);
      26                 :          0 :         return rc;
      27                 :            : }
      28                 :            : 
      29                 :            : int
      30                 :          0 : roc_nix_vlan_mcam_entry_write(struct roc_nix *roc_nix, uint32_t index,
      31                 :            :                               struct mcam_entry *entry, uint8_t intf,
      32                 :            :                               uint8_t enable)
      33                 :            : {
      34                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      35                 :            :         struct dev *dev = &nix->dev;
      36                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
      37                 :            :         struct npc_mcam_write_entry_req *req;
      38                 :            :         struct msghdr *rsp;
      39                 :            :         int rc = -ENOSPC;
      40                 :            : 
      41                 :          0 :         req = mbox_alloc_msg_npc_mcam_write_entry(mbox);
      42         [ #  # ]:          0 :         if (req == NULL)
      43                 :          0 :                 goto exit;
      44                 :          0 :         req->entry = index;
      45                 :          0 :         req->intf = intf;
      46                 :          0 :         req->enable_entry = enable;
      47         [ #  # ]:          0 :         mbox_memcpy(&req->entry_data, entry, sizeof(struct mcam_entry));
      48                 :            : 
      49                 :            :         rc = mbox_process_msg(mbox, (void *)&rsp);
      50                 :          0 : exit:
      51                 :            :         mbox_put(mbox);
      52                 :          0 :         return rc;
      53                 :            : }
      54                 :            : 
      55                 :            : int
      56                 :          0 : roc_nix_vlan_mcam_entry_alloc_and_write(struct roc_nix *roc_nix,
      57                 :            :                                         struct mcam_entry *entry, uint8_t intf,
      58                 :            :                                         uint8_t priority, uint8_t ref_entry)
      59                 :            : {
      60                 :            :         struct npc_mcam_alloc_and_write_entry_req *req;
      61                 :            :         struct npc_mcam_alloc_and_write_entry_rsp *rsp;
      62                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      63                 :            :         struct dev *dev = &nix->dev;
      64                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
      65                 :            :         int rc = -ENOSPC;
      66                 :            : 
      67                 :          0 :         req = mbox_alloc_msg_npc_mcam_alloc_and_write_entry(mbox);
      68         [ #  # ]:          0 :         if (req == NULL)
      69                 :          0 :                 goto exit;
      70                 :          0 :         req->priority = priority;
      71                 :          0 :         req->ref_entry = ref_entry;
      72                 :          0 :         req->intf = intf;
      73                 :          0 :         req->enable_entry = true;
      74         [ #  # ]:          0 :         mbox_memcpy(&req->entry_data, entry, sizeof(struct mcam_entry));
      75                 :            : 
      76                 :            :         rc = mbox_process_msg(mbox, (void *)&rsp);
      77         [ #  # ]:          0 :         if (rc)
      78                 :          0 :                 goto exit;
      79                 :            : 
      80                 :          0 :         rc = rsp->entry;
      81                 :          0 : exit:
      82                 :            :         mbox_put(mbox);
      83                 :          0 :         return rc;
      84                 :            : }
      85                 :            : 
      86                 :            : int
      87                 :          0 : roc_nix_vlan_mcam_entry_free(struct roc_nix *roc_nix, uint32_t index)
      88                 :            : {
      89                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      90                 :            :         struct dev *dev = &nix->dev;
      91                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
      92                 :            :         struct npc_mcam_free_entry_req *req;
      93                 :            :         int rc = -ENOSPC;
      94                 :            : 
      95                 :          0 :         req = mbox_alloc_msg_npc_mcam_free_entry(mbox);
      96         [ #  # ]:          0 :         if (req == NULL)
      97                 :          0 :                 goto exit;
      98                 :          0 :         req->entry = index;
      99                 :            : 
     100                 :            :         rc = mbox_process_msg(mbox, NULL);
     101                 :          0 : exit:
     102                 :            :         mbox_put(mbox);
     103                 :          0 :         return rc;
     104                 :            : }
     105                 :            : 
     106                 :            : int
     107                 :          0 : roc_nix_vlan_mcam_entry_ena_dis(struct roc_nix *roc_nix, uint32_t index,
     108                 :            :                                 const int enable)
     109                 :            : {
     110                 :            :         struct npc_mcam_ena_dis_entry_req *req;
     111                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     112                 :            :         struct dev *dev = &nix->dev;
     113                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     114                 :            :         int rc = -ENOSPC;
     115                 :            : 
     116         [ #  # ]:          0 :         if (enable) {
     117                 :          0 :                 req = mbox_alloc_msg_npc_mcam_ena_entry(mbox);
     118         [ #  # ]:          0 :                 if (req == NULL)
     119                 :          0 :                         goto exit;
     120                 :            :         } else {
     121                 :          0 :                 req = mbox_alloc_msg_npc_mcam_dis_entry(mbox);
     122         [ #  # ]:          0 :                 if (req == NULL)
     123                 :          0 :                         goto exit;
     124                 :            :         }
     125                 :            : 
     126                 :          0 :         req->entry = index;
     127                 :            :         rc =  mbox_process_msg(mbox, NULL);
     128                 :          0 : exit:
     129                 :            :         mbox_put(mbox);
     130                 :          0 :         return rc;
     131                 :            : }
     132                 :            : 
     133                 :            : int
     134                 :          0 : roc_nix_vlan_strip_vtag_ena_dis(struct roc_nix *roc_nix, bool enable)
     135                 :            : {
     136                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     137                 :            :         struct dev *dev = &nix->dev;
     138                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     139                 :            :         struct nix_vtag_config *vtag_cfg;
     140                 :            :         int rc = -ENOSPC;
     141                 :            : 
     142                 :          0 :         vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
     143         [ #  # ]:          0 :         if (vtag_cfg == NULL)
     144                 :          0 :                 goto exit;
     145                 :          0 :         vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
     146                 :          0 :         vtag_cfg->cfg_type = 1;             /* Rx VLAN configuration */
     147                 :          0 :         vtag_cfg->rx.capture_vtag = 1; /* Always capture */
     148                 :          0 :         vtag_cfg->rx.vtag_type = 0;    /* Use index 0 */
     149                 :            : 
     150         [ #  # ]:          0 :         if (enable)
     151                 :          0 :                 vtag_cfg->rx.strip_vtag = 1;
     152                 :            :         else
     153                 :          0 :                 vtag_cfg->rx.strip_vtag = 0;
     154                 :            : 
     155                 :          0 :         rc = mbox_process(mbox);
     156                 :          0 : exit:
     157                 :            :         mbox_put(mbox);
     158                 :          0 :         return rc;
     159                 :            : }
     160                 :            : 
     161                 :            : int
     162                 :          0 : roc_nix_vlan_insert_ena_dis(struct roc_nix *roc_nix,
     163                 :            :                             struct roc_nix_vlan_config *vlan_cfg,
     164                 :            :                             uint64_t *mcam_index, bool enable)
     165                 :            : {
     166                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     167                 :            :         struct dev *dev = &nix->dev;
     168                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     169                 :            :         struct nix_vtag_config *vtag_cfg;
     170                 :            :         struct nix_vtag_config_rsp *rsp;
     171                 :            :         int rc = -ENOSPC;
     172                 :            : 
     173                 :          0 :         vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
     174         [ #  # ]:          0 :         if (vtag_cfg == NULL)
     175                 :          0 :                 goto exit;
     176                 :          0 :         vtag_cfg->cfg_type = 0; /* Tx VLAN configuration */
     177                 :          0 :         vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
     178                 :            : 
     179         [ #  # ]:          0 :         if (enable) {
     180         [ #  # ]:          0 :                 if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_INNER) {
     181                 :          0 :                         vtag_cfg->tx.vtag0 = vlan_cfg->vlan.vtag_inner;
     182                 :          0 :                         vtag_cfg->tx.cfg_vtag0 = true;
     183                 :            :                 }
     184         [ #  # ]:          0 :                 if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_OUTER) {
     185                 :          0 :                         vtag_cfg->tx.vtag1 = vlan_cfg->vlan.vtag_outer;
     186                 :          0 :                         vtag_cfg->tx.cfg_vtag1 = true;
     187                 :            :                 }
     188                 :            :         } else {
     189         [ #  # ]:          0 :                 if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_INNER) {
     190                 :          0 :                         vtag_cfg->tx.vtag0_idx = vlan_cfg->mcam.idx_inner;
     191                 :          0 :                         vtag_cfg->tx.free_vtag0 = true;
     192                 :            :                 }
     193         [ #  # ]:          0 :                 if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_OUTER) {
     194                 :          0 :                         vtag_cfg->tx.vtag1_idx = vlan_cfg->mcam.idx_outer;
     195                 :          0 :                         vtag_cfg->tx.free_vtag1 = true;
     196                 :            :                 }
     197                 :            :         }
     198                 :            : 
     199                 :            :         rc = mbox_process_msg(mbox, (void *)&rsp);
     200         [ #  # ]:          0 :         if (rc)
     201                 :          0 :                 goto exit;
     202                 :            : 
     203         [ #  # ]:          0 :         if (enable)
     204                 :          0 :                 *mcam_index =
     205                 :          0 :                         (((uint64_t)rsp->vtag1_idx << 32) | rsp->vtag0_idx);
     206                 :            : 
     207                 :            :         rc = 0;
     208                 :          0 : exit:
     209                 :            :         mbox_put(mbox);
     210                 :          0 :         return rc;
     211                 :            : }
     212                 :            : 
     213                 :            : int
     214                 :          0 : nix_vlan_tpid_set(struct mbox *mbox, uint16_t pcifunc, uint32_t type, uint16_t tpid)
     215                 :            : {
     216                 :            :         struct nix_set_vlan_tpid *tpid_cfg;
     217                 :            :         int rc = -ENOSPC;
     218                 :            : 
     219                 :            :         /* Configuring for PF */
     220                 :          0 :         tpid_cfg = mbox_alloc_msg_nix_set_vlan_tpid(mbox_get(mbox));
     221         [ #  # ]:          0 :         if (tpid_cfg == NULL)
     222                 :          0 :                 goto exit;
     223                 :          0 :         tpid_cfg->tpid = tpid;
     224                 :          0 :         tpid_cfg->hdr.pcifunc = pcifunc;
     225                 :            : 
     226         [ #  # ]:          0 :         if (type & ROC_NIX_VLAN_TYPE_OUTER)
     227                 :          0 :                 tpid_cfg->vlan_type = NIX_VLAN_TYPE_OUTER;
     228                 :            :         else
     229                 :          0 :                 tpid_cfg->vlan_type = NIX_VLAN_TYPE_INNER;
     230                 :            : 
     231                 :          0 :         rc = mbox_process(mbox);
     232                 :          0 : exit:
     233                 :            :         mbox_put(mbox);
     234                 :          0 :         return rc;
     235                 :            : }
     236                 :            : 
     237                 :            : int
     238                 :          0 : roc_nix_vlan_tpid_set(struct roc_nix *roc_nix, uint32_t type, uint16_t tpid)
     239                 :            : {
     240                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     241                 :            :         struct dev *dev = &nix->dev;
     242                 :            :         int rc;
     243                 :            : 
     244                 :          0 :         rc = nix_vlan_tpid_set(dev->mbox, dev->pf_func, type, tpid);
     245         [ #  # ]:          0 :         if (rc)
     246                 :          0 :                 plt_err("Failed to set tpid for PF, rc %d", rc);
     247                 :            : 
     248                 :          0 :         return rc;
     249                 :            : }

Generated by: LCOV version 1.14