LCOV - code coverage report
Current view: top level - drivers/common/cnxk - roc_nix_mac.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 185 0.0 %
Date: 2025-12-01 19:08:10 Functions: 0 19 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 70 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_mac_rxtx_start_stop(struct roc_nix *roc_nix, bool start)
      10                 :            : {
      11                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      12                 :            :         struct dev *dev = &nix->dev;
      13                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
      14                 :            :         int rc;
      15                 :            : 
      16         [ #  # ]:          0 :         if (roc_nix_is_vf_or_sdp(roc_nix)) {
      17                 :            :                 rc = NIX_ERR_OP_NOTSUP;
      18                 :          0 :                 goto exit;
      19                 :            :         }
      20                 :            : 
      21         [ #  # ]:          0 :         if (start)
      22                 :          0 :                 mbox_alloc_msg_cgx_start_rxtx(mbox);
      23                 :            :         else
      24                 :          0 :                 mbox_alloc_msg_cgx_stop_rxtx(mbox);
      25                 :            : 
      26                 :          0 :         rc = mbox_process(mbox);
      27                 :          0 : exit:
      28                 :            :         mbox_put(mbox);
      29                 :          0 :         return rc;
      30                 :            : }
      31                 :            : 
      32                 :            : int
      33                 :          0 : roc_nix_mac_link_event_start_stop(struct roc_nix *roc_nix, bool start)
      34                 :            : {
      35                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      36                 :            :         struct dev *dev = &nix->dev;
      37                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
      38                 :            :         int rc;
      39                 :            : 
      40         [ #  # ]:          0 :         if (roc_nix_is_vf_or_sdp(roc_nix)) {
      41                 :            :                 rc = NIX_ERR_OP_NOTSUP;
      42                 :          0 :                 goto exit;
      43                 :            :         }
      44                 :            : 
      45         [ #  # ]:          0 :         if (start)
      46                 :          0 :                 mbox_alloc_msg_cgx_start_linkevents(mbox);
      47                 :            :         else
      48                 :          0 :                 mbox_alloc_msg_cgx_stop_linkevents(mbox);
      49                 :            : 
      50                 :          0 :         rc = mbox_process(mbox);
      51                 :          0 : exit:
      52                 :            :         mbox_put(mbox);
      53                 :          0 :         return rc;
      54                 :            : }
      55                 :            : 
      56                 :            : int
      57                 :          0 : roc_nix_mac_loopback_enable(struct roc_nix *roc_nix, bool enable)
      58                 :            : {
      59                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      60                 :            :         struct dev *dev = &nix->dev;
      61                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
      62                 :            :         int rc;
      63                 :            : 
      64   [ #  #  #  # ]:          0 :         if (enable && roc_nix_is_vf_or_sdp(roc_nix)) {
      65                 :            :                 rc = NIX_ERR_OP_NOTSUP;
      66                 :          0 :                 goto exit;
      67                 :            :         }
      68                 :            : 
      69         [ #  # ]:          0 :         if (enable)
      70                 :          0 :                 mbox_alloc_msg_cgx_intlbk_enable(mbox);
      71                 :            :         else
      72                 :          0 :                 mbox_alloc_msg_cgx_intlbk_disable(mbox);
      73                 :            : 
      74                 :          0 :         rc = mbox_process(mbox);
      75                 :          0 : exit:
      76                 :            :         mbox_put(mbox);
      77                 :          0 :         return rc;
      78                 :            : }
      79                 :            : 
      80                 :            : int
      81                 :          0 : roc_nix_mac_addr_set(struct roc_nix *roc_nix, const uint8_t addr[])
      82                 :            : {
      83                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      84                 :            :         struct cgx_mac_addr_set_or_get *req, *rsp;
      85                 :            :         struct dev *dev = &nix->dev;
      86                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
      87                 :            :         int rc = -ENOSPC;
      88                 :            : 
      89         [ #  # ]:          0 :         if (roc_nix_is_vf_or_sdp(roc_nix)) {
      90                 :            :                 rc = NIX_ERR_OP_NOTSUP;
      91                 :          0 :                 goto exit;
      92                 :            :         }
      93                 :            : 
      94                 :          0 :         req = mbox_alloc_msg_cgx_mac_addr_set(mbox);
      95         [ #  # ]:          0 :         if (req == NULL)
      96                 :          0 :                 goto exit;
      97                 :            : 
      98                 :          0 :         req->index = nix->dmac_flt_idx;
      99         [ #  # ]:          0 :         mbox_memcpy(req->mac_addr, addr, PLT_ETHER_ADDR_LEN);
     100                 :            : 
     101                 :            :         rc = mbox_process_msg(mbox, (void *)&rsp);
     102         [ #  # ]:          0 :         if (rc)
     103                 :          0 :                 goto exit;
     104                 :          0 :         nix->dmac_flt_idx = rsp->index;
     105                 :          0 : exit:
     106                 :            :         mbox_put(mbox);
     107                 :          0 :         return rc;
     108                 :            : }
     109                 :            : 
     110                 :            : int
     111                 :          0 : roc_nix_mac_max_entries_get(struct roc_nix *roc_nix)
     112                 :            : {
     113                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     114                 :            :         struct cgx_max_dmac_entries_get_rsp *rsp;
     115                 :            :         struct dev *dev = &nix->dev;
     116                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     117                 :            :         int rc;
     118                 :            : 
     119         [ #  # ]:          0 :         if (roc_nix_is_vf_or_sdp(roc_nix)) {
     120                 :            :                 rc = NIX_ERR_OP_NOTSUP;
     121                 :          0 :                 goto exit;
     122                 :            :         }
     123                 :            : 
     124                 :          0 :         mbox_alloc_msg_cgx_mac_max_entries_get(mbox);
     125                 :            :         rc = mbox_process_msg(mbox, (void *)&rsp);
     126         [ #  # ]:          0 :         if (rc)
     127                 :          0 :                 goto exit;
     128                 :            : 
     129         [ #  # ]:          0 :         rc = rsp->max_dmac_filters ? rsp->max_dmac_filters : 1;
     130                 :          0 : exit:
     131                 :            :         mbox_put(mbox);
     132                 :          0 :         return rc;
     133                 :            : }
     134                 :            : 
     135                 :            : int
     136                 :          0 : roc_nix_mac_addr_add(struct roc_nix *roc_nix, uint8_t addr[])
     137                 :            : {
     138                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     139                 :            :         struct cgx_mac_addr_add_req *req;
     140                 :            :         struct cgx_mac_addr_add_rsp *rsp;
     141                 :            :         struct dev *dev = &nix->dev;
     142                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     143                 :            :         int rc;
     144                 :            : 
     145         [ #  # ]:          0 :         if (roc_nix_is_vf_or_sdp(roc_nix)) {
     146                 :            :                 rc = NIX_ERR_OP_NOTSUP;
     147                 :          0 :                 goto exit;
     148                 :            :         }
     149                 :            : 
     150                 :          0 :         req = mbox_alloc_msg_cgx_mac_addr_add(mbox);
     151         [ #  # ]:          0 :         mbox_memcpy(req->mac_addr, addr, PLT_ETHER_ADDR_LEN);
     152                 :            : 
     153                 :            :         rc = mbox_process_msg(mbox, (void *)&rsp);
     154         [ #  # ]:          0 :         if (rc < 0)
     155                 :          0 :                 goto exit;
     156                 :            : 
     157                 :          0 :         rc = rsp->index;
     158                 :          0 : exit:
     159                 :            :         mbox_put(mbox);
     160                 :          0 :         return rc;
     161                 :            : }
     162                 :            : 
     163                 :            : int
     164                 :          0 : roc_nix_mac_addr_del(struct roc_nix *roc_nix, uint32_t index)
     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 cgx_mac_addr_del_req *req;
     170                 :            :         int rc = -ENOSPC;
     171                 :            : 
     172         [ #  # ]:          0 :         if (roc_nix_is_vf_or_sdp(roc_nix)) {
     173                 :            :                 rc = NIX_ERR_OP_NOTSUP;
     174                 :          0 :                 goto exit;
     175                 :            :         }
     176                 :            : 
     177                 :          0 :         req = mbox_alloc_msg_cgx_mac_addr_del(mbox);
     178         [ #  # ]:          0 :         if (req == NULL)
     179                 :          0 :                 goto exit;
     180                 :          0 :         req->index = index;
     181                 :            : 
     182                 :          0 :         rc = mbox_process(mbox);
     183                 :          0 : exit:
     184                 :            :         mbox_put(mbox);
     185                 :          0 :         return rc;
     186                 :            : }
     187                 :            : 
     188                 :            : int
     189                 :          0 : roc_nix_mac_promisc_mode_enable(struct roc_nix *roc_nix, int enable)
     190                 :            : {
     191                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     192                 :            :         struct dev *dev = &nix->dev;
     193                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     194                 :            :         int rc;
     195                 :            : 
     196         [ #  # ]:          0 :         if (roc_nix_is_vf_or_sdp(roc_nix)) {
     197                 :            :                 rc = NIX_ERR_OP_NOTSUP;
     198                 :          0 :                 goto exit;
     199                 :            :         }
     200                 :            : 
     201         [ #  # ]:          0 :         if (enable)
     202                 :          0 :                 mbox_alloc_msg_cgx_promisc_enable(mbox);
     203                 :            :         else
     204                 :          0 :                 mbox_alloc_msg_cgx_promisc_disable(mbox);
     205                 :            : 
     206                 :          0 :         rc = mbox_process(mbox);
     207                 :          0 : exit:
     208                 :            :         mbox_put(mbox);
     209                 :          0 :         return rc;
     210                 :            : }
     211                 :            : 
     212                 :            : int
     213                 :          0 : roc_nix_mac_link_info_get(struct roc_nix *roc_nix,
     214                 :            :                           struct roc_nix_link_info *link_info)
     215                 :            : {
     216                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     217                 :            :         struct dev *dev = &nix->dev;
     218                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     219                 :            :         struct cgx_link_info_msg *rsp;
     220                 :            :         int rc;
     221                 :            : 
     222                 :          0 :         mbox_alloc_msg_cgx_get_linkinfo(mbox);
     223                 :            :         rc = mbox_process_msg(mbox, (void *)&rsp);
     224         [ #  # ]:          0 :         if (rc)
     225                 :          0 :                 goto exit;
     226                 :            : 
     227                 :          0 :         link_info->status = rsp->link_info.link_up;
     228                 :          0 :         link_info->full_duplex = rsp->link_info.full_duplex;
     229                 :          0 :         link_info->lmac_type_id = rsp->link_info.lmac_type_id;
     230                 :          0 :         link_info->speed = rsp->link_info.speed;
     231                 :          0 :         link_info->autoneg = rsp->link_info.an;
     232                 :          0 :         link_info->fec = rsp->link_info.fec;
     233                 :          0 :         link_info->port = rsp->link_info.port;
     234                 :            : 
     235                 :            :         rc = 0;
     236                 :          0 : exit:
     237                 :            :         mbox_put(mbox);
     238                 :          0 :         return rc;
     239                 :            : }
     240                 :            : 
     241                 :            : int
     242                 :          0 : roc_nix_mac_link_state_set(struct roc_nix *roc_nix, uint8_t up)
     243                 :            : {
     244                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     245                 :            :         struct dev *dev = &nix->dev;
     246                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     247                 :            :         struct cgx_set_link_state_msg *req;
     248                 :            :         int rc = -ENOSPC;
     249                 :            : 
     250                 :          0 :         req = mbox_alloc_msg_cgx_set_link_state(mbox);
     251         [ #  # ]:          0 :         if (req == NULL)
     252                 :          0 :                 goto exit;
     253                 :          0 :         req->enable = up;
     254                 :          0 :         rc = mbox_process(mbox);
     255                 :          0 : exit:
     256                 :            :         mbox_put(mbox);
     257                 :          0 :         return rc;
     258                 :            : }
     259                 :            : 
     260                 :            : int
     261                 :          0 : roc_nix_mac_link_info_set(struct roc_nix *roc_nix,
     262                 :            :                           struct roc_nix_link_info *link_info)
     263                 :            : {
     264                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     265                 :            :         struct dev *dev = &nix->dev;
     266                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     267                 :            :         struct cgx_set_link_mode_req *req;
     268                 :            :         int rc;
     269                 :            : 
     270                 :          0 :         req = mbox_alloc_msg_cgx_set_link_mode(mbox);
     271         [ #  # ]:          0 :         if (req == NULL) {
     272                 :            :                 rc =  -ENOSPC;
     273                 :          0 :                 goto exit;
     274                 :            :         }
     275                 :            : 
     276                 :          0 :         req->args.advertising = link_info->advertising;
     277                 :          0 :         req->args.speed = link_info->speed;
     278                 :          0 :         req->args.duplex = link_info->full_duplex;
     279                 :          0 :         req->args.an = link_info->autoneg;
     280                 :            : 
     281                 :            :         /* Link mode changes takes more time. */
     282                 :          0 :         rc = mbox_process_tmo(mbox, mbox->rsp_tmo * 4);
     283                 :          0 : exit:
     284                 :            :         mbox_put(mbox);
     285                 :          0 :         return rc;
     286                 :            : 
     287                 :            : }
     288                 :            : 
     289                 :            : int
     290                 :          0 : roc_nix_mac_mtu_set(struct roc_nix *roc_nix, uint16_t mtu)
     291                 :            : {
     292                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     293                 :            :         struct dev *dev = &nix->dev;
     294                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     295                 :            :         struct nix_frs_cfg *req;
     296                 :            :         bool sdp_link = false;
     297                 :            :         int rc = -ENOSPC;
     298                 :            : 
     299         [ #  # ]:          0 :         if (roc_nix_is_sdp(roc_nix))
     300                 :            :                 sdp_link = true;
     301                 :            : 
     302                 :          0 :         req = mbox_alloc_msg_nix_set_hw_frs(mbox);
     303         [ #  # ]:          0 :         if (req == NULL)
     304                 :          0 :                 goto exit;
     305                 :          0 :         req->maxlen = mtu;
     306                 :          0 :         req->update_smq = true;
     307                 :          0 :         req->sdp_link = sdp_link;
     308                 :            : 
     309                 :          0 :         rc = mbox_process(mbox);
     310         [ #  # ]:          0 :         if (rc)
     311                 :          0 :                 goto exit;
     312                 :            : 
     313                 :            :         /* Save MTU for later use */
     314                 :          0 :         nix->mtu = mtu;
     315                 :            :         rc = 0;
     316                 :          0 : exit:
     317                 :            :         mbox_put(mbox);
     318                 :          0 :         return rc;
     319                 :            : }
     320                 :            : 
     321                 :            : int
     322                 :          0 : roc_nix_mac_max_rx_len_set(struct roc_nix *roc_nix, uint16_t maxlen)
     323                 :            : {
     324                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     325                 :            :         struct dev *dev = &nix->dev;
     326                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     327                 :            :         struct nix_frs_cfg *req;
     328                 :            :         bool sdp_link = false;
     329                 :            :         int rc = -ENOSPC;
     330                 :            : 
     331         [ #  # ]:          0 :         if (roc_nix_is_sdp(roc_nix))
     332                 :            :                 sdp_link = true;
     333                 :            : 
     334                 :          0 :         req = mbox_alloc_msg_nix_set_hw_frs(mbox);
     335         [ #  # ]:          0 :         if (req == NULL)
     336                 :          0 :                 goto exit;
     337                 :          0 :         req->sdp_link = sdp_link;
     338                 :          0 :         req->maxlen = maxlen;
     339                 :            : 
     340                 :          0 :         rc = mbox_process(mbox);
     341                 :          0 : exit:
     342                 :            :         mbox_put(mbox);
     343                 :          0 :         return rc;
     344                 :            : }
     345                 :            : 
     346                 :            : int
     347                 :          0 : roc_nix_mac_stats_reset(struct roc_nix *roc_nix)
     348                 :            : {
     349                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     350                 :            :         struct dev *dev = &nix->dev;
     351                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     352                 :            :         struct msg_req *req;
     353                 :            :         int rc = -ENOSPC;
     354                 :            : 
     355         [ #  # ]:          0 :         if (roc_nix_is_vf_or_sdp(roc_nix)) {
     356                 :            :                 rc = 0;
     357                 :          0 :                 goto exit;
     358                 :            :         }
     359                 :            : 
     360                 :          0 :         req = mbox_alloc_msg_cgx_stats_rst(mbox);
     361         [ #  # ]:          0 :         if (req == NULL)
     362                 :          0 :                 goto exit;
     363                 :            : 
     364                 :          0 :         rc = mbox_process(mbox);
     365                 :          0 : exit:
     366                 :            :         mbox_put(mbox);
     367                 :          0 :         return rc;
     368                 :            : }
     369                 :            : 
     370                 :            : int
     371                 :          0 : roc_nix_mac_link_cb_register(struct roc_nix *roc_nix, link_status_t link_update)
     372                 :            : {
     373                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     374                 :            :         struct dev *dev = &nix->dev;
     375                 :            : 
     376         [ #  # ]:          0 :         if (link_update == NULL)
     377                 :            :                 return NIX_ERR_PARAM;
     378                 :            : 
     379                 :          0 :         dev->ops->link_status_update = (link_info_t)link_update;
     380                 :          0 :         return 0;
     381                 :            : }
     382                 :            : 
     383                 :            : void
     384                 :          0 : roc_nix_mac_link_cb_unregister(struct roc_nix *roc_nix)
     385                 :            : {
     386                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     387                 :            :         struct dev *dev = &nix->dev;
     388                 :            : 
     389                 :          0 :         dev->ops->link_status_update = NULL;
     390                 :          0 : }
     391                 :            : 
     392                 :            : int
     393                 :          0 : roc_nix_mac_link_info_get_cb_register(struct roc_nix *roc_nix,
     394                 :            :                                       link_info_get_t link_info_get)
     395                 :            : {
     396                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     397                 :            :         struct dev *dev = &nix->dev;
     398                 :            : 
     399         [ #  # ]:          0 :         if (link_info_get == NULL)
     400                 :            :                 return NIX_ERR_PARAM;
     401                 :            : 
     402                 :          0 :         dev->ops->link_status_get = (link_info_t)link_info_get;
     403                 :          0 :         return 0;
     404                 :            : }
     405                 :            : 
     406                 :            : void
     407                 :          0 : roc_nix_mac_link_info_get_cb_unregister(struct roc_nix *roc_nix)
     408                 :            : {
     409                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     410                 :            :         struct dev *dev = &nix->dev;
     411                 :            : 
     412                 :          0 :         dev->ops->link_status_get = NULL;
     413                 :          0 : }
     414                 :            : 
     415                 :            : int
     416                 :          0 : roc_nix_mac_fwdata_get(struct roc_nix *roc_nix, struct roc_nix_mac_fwdata *data)
     417                 :            : {
     418                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     419                 :            :         struct cgx_fw_data *fw_data;
     420                 :            :         struct dev *dev = &nix->dev;
     421                 :            :         struct mbox *mbox;
     422                 :            :         int rc;
     423                 :            : 
     424         [ #  # ]:          0 :         if (roc_nix_is_sdp(roc_nix))
     425                 :            :                 return 0;
     426                 :            : 
     427                 :          0 :         mbox = mbox_get(dev->mbox);
     428                 :            : 
     429                 :          0 :         mbox_alloc_msg_cgx_get_aux_link_info(mbox);
     430                 :            :         rc = mbox_process_msg(mbox, (void *)&fw_data);
     431         [ #  # ]:          0 :         if (rc)
     432                 :          0 :                 goto exit;
     433                 :            : 
     434                 :          0 :         nix->supported_link_modes = fw_data->fwdata.supported_link_modes;
     435                 :          0 :         nix->advertised_link_modes = fw_data->fwdata.advertised_link_modes;
     436                 :          0 :         data->supported_link_modes = nix->supported_link_modes;
     437                 :          0 :         data->advertised_link_modes = nix->advertised_link_modes;
     438                 :          0 :         data->supported_an = fw_data->fwdata.supported_an;
     439                 :          0 :         data->port_type = fw_data->fwdata.port;
     440                 :          0 : exit:
     441                 :            :         mbox_put(mbox);
     442                 :          0 :         return rc;
     443                 :            : }

Generated by: LCOV version 1.14