LCOV - code coverage report
Current view: top level - drivers/net/octeontx/base - octeontx_bgx.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 185 0.0 %
Date: 2025-03-01 20:23:48 Functions: 0 21 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 42 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2017 Cavium, Inc
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <errno.h>
       6                 :            : #include <string.h>
       7                 :            : 
       8                 :            : #include "octeontx_bgx.h"
       9                 :            : 
      10                 :            : int
      11                 :          0 : octeontx_bgx_port_open(int port, octeontx_mbox_bgx_port_conf_t *conf)
      12                 :            : {
      13                 :            :         struct octeontx_mbox_hdr hdr;
      14                 :            :         octeontx_mbox_bgx_port_conf_t bgx_conf;
      15                 :            :         int len = sizeof(octeontx_mbox_bgx_port_conf_t);
      16                 :            :         int res;
      17                 :            : 
      18                 :            :         memset(&bgx_conf, 0, sizeof(octeontx_mbox_bgx_port_conf_t));
      19                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
      20                 :          0 :         hdr.msg = MBOX_BGX_PORT_OPEN;
      21                 :          0 :         hdr.vfid = port;
      22                 :            : 
      23                 :          0 :         res = octeontx_mbox_send(&hdr, NULL, 0, &bgx_conf, len);
      24         [ #  # ]:          0 :         if (res < 0)
      25                 :            :                 return -EACCES;
      26                 :            : 
      27                 :          0 :         conf->enable = bgx_conf.enable;
      28                 :          0 :         conf->promisc = bgx_conf.promisc;
      29                 :          0 :         conf->bpen = bgx_conf.bpen;
      30                 :          0 :         conf->node = bgx_conf.node;
      31                 :          0 :         conf->base_chan = bgx_conf.base_chan;
      32                 :          0 :         conf->num_chans = bgx_conf.num_chans;
      33                 :          0 :         conf->mtu = bgx_conf.mtu;
      34                 :          0 :         conf->bgx = bgx_conf.bgx;
      35                 :          0 :         conf->lmac = bgx_conf.lmac;
      36                 :          0 :         conf->mode = bgx_conf.mode;
      37                 :          0 :         conf->pkind = bgx_conf.pkind;
      38                 :          0 :         memcpy(conf->macaddr, bgx_conf.macaddr, 6);
      39                 :            : 
      40                 :          0 :         return res;
      41                 :            : }
      42                 :            : 
      43                 :            : int
      44                 :          0 : octeontx_bgx_port_close(int port)
      45                 :            : {
      46                 :            :         struct octeontx_mbox_hdr hdr;
      47                 :            :         int res;
      48                 :            : 
      49                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
      50                 :          0 :         hdr.msg = MBOX_BGX_PORT_CLOSE;
      51                 :          0 :         hdr.vfid = port;
      52                 :            : 
      53                 :          0 :         res = octeontx_mbox_send(&hdr, NULL, 0, NULL, 0);
      54         [ #  # ]:          0 :         if (res < 0)
      55                 :          0 :                 return -EACCES;
      56                 :            : 
      57                 :            :         return res;
      58                 :            : }
      59                 :            : 
      60                 :            : int
      61                 :          0 : octeontx_bgx_port_start(int port)
      62                 :            : {
      63                 :            :         struct octeontx_mbox_hdr hdr;
      64                 :            :         int res;
      65                 :            : 
      66                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
      67                 :          0 :         hdr.msg = MBOX_BGX_PORT_START;
      68                 :          0 :         hdr.vfid = port;
      69                 :            : 
      70                 :          0 :         res = octeontx_mbox_send(&hdr, NULL, 0, NULL, 0);
      71         [ #  # ]:          0 :         if (res < 0)
      72                 :          0 :                 return -EACCES;
      73                 :            : 
      74                 :            :         return res;
      75                 :            : }
      76                 :            : 
      77                 :            : int
      78                 :          0 : octeontx_bgx_port_stop(int port)
      79                 :            : {
      80                 :            :         struct octeontx_mbox_hdr hdr;
      81                 :            :         int res;
      82                 :            : 
      83                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
      84                 :          0 :         hdr.msg = MBOX_BGX_PORT_STOP;
      85                 :          0 :         hdr.vfid = port;
      86                 :            : 
      87                 :          0 :         res = octeontx_mbox_send(&hdr, NULL, 0, NULL, 0);
      88         [ #  # ]:          0 :         if (res < 0)
      89                 :          0 :                 return -EACCES;
      90                 :            : 
      91                 :            :         return res;
      92                 :            : }
      93                 :            : 
      94                 :            : int
      95                 :          0 : octeontx_bgx_port_get_config(int port, octeontx_mbox_bgx_port_conf_t *conf)
      96                 :            : {
      97                 :            :         struct octeontx_mbox_hdr hdr;
      98                 :            :         octeontx_mbox_bgx_port_conf_t bgx_conf;
      99                 :            :         int len = sizeof(octeontx_mbox_bgx_port_conf_t);
     100                 :            :         int res;
     101                 :            : 
     102                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     103                 :          0 :         hdr.msg = MBOX_BGX_PORT_GET_CONFIG;
     104                 :          0 :         hdr.vfid = port;
     105                 :            : 
     106                 :            :         memset(&bgx_conf, 0, sizeof(octeontx_mbox_bgx_port_conf_t));
     107                 :          0 :         res = octeontx_mbox_send(&hdr, NULL, 0, &bgx_conf, len);
     108         [ #  # ]:          0 :         if (res < 0)
     109                 :            :                 return -EACCES;
     110                 :            : 
     111                 :          0 :         conf->enable = bgx_conf.enable;
     112                 :          0 :         conf->promisc = bgx_conf.promisc;
     113                 :          0 :         conf->bpen = bgx_conf.bpen;
     114                 :          0 :         conf->node = bgx_conf.node;
     115                 :          0 :         conf->base_chan = bgx_conf.base_chan;
     116                 :          0 :         conf->num_chans = bgx_conf.num_chans;
     117                 :          0 :         conf->mtu = bgx_conf.mtu;
     118                 :          0 :         conf->bgx = bgx_conf.bgx;
     119                 :          0 :         conf->lmac = bgx_conf.lmac;
     120                 :          0 :         conf->mode = bgx_conf.mode;
     121                 :          0 :         conf->pkind = bgx_conf.pkind;
     122                 :          0 :         memcpy(conf->macaddr, bgx_conf.macaddr, 6);
     123                 :            : 
     124                 :          0 :         return res;
     125                 :            : }
     126                 :            : 
     127                 :            : int
     128                 :          0 : octeontx_bgx_port_status(int port, octeontx_mbox_bgx_port_status_t *stat)
     129                 :            : {
     130                 :            :         struct octeontx_mbox_hdr hdr;
     131                 :            :         octeontx_mbox_bgx_port_status_t bgx_stat;
     132                 :            :         int len = sizeof(octeontx_mbox_bgx_port_status_t);
     133                 :            :         int res;
     134                 :            : 
     135                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     136                 :          0 :         hdr.msg = MBOX_BGX_PORT_GET_STATUS;
     137                 :          0 :         hdr.vfid = port;
     138                 :            : 
     139                 :          0 :         res = octeontx_mbox_send(&hdr, NULL, 0, &bgx_stat, len);
     140         [ #  # ]:          0 :         if (res < 0)
     141                 :            :                 return -EACCES;
     142                 :            : 
     143                 :          0 :         stat->link_up = bgx_stat.link_up;
     144                 :            : 
     145                 :          0 :         return res;
     146                 :            : }
     147                 :            : 
     148                 :            : int
     149                 :          0 : octeontx_bgx_port_multicast_set(int port, int en)
     150                 :            : {
     151                 :            :         struct octeontx_mbox_hdr hdr;
     152                 :            :         uint8_t prom;
     153                 :            :         int res;
     154                 :            : 
     155                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     156                 :          0 :         hdr.msg = MBOX_BGX_PORT_SET_MCAST;
     157                 :          0 :         hdr.vfid = port;
     158                 :          0 :         prom = en ? 1 : 0;
     159                 :            : 
     160                 :          0 :         res = octeontx_mbox_send(&hdr, &prom, sizeof(prom), NULL, 0);
     161         [ #  # ]:          0 :         if (res < 0)
     162                 :          0 :                 return -EACCES;
     163                 :            : 
     164                 :            :         return res;
     165                 :            : }
     166                 :            : 
     167                 :            : int
     168                 :          0 : octeontx_bgx_port_xstats(int port, octeontx_mbox_bgx_port_stats_t *stats)
     169                 :            : {
     170                 :            :         struct octeontx_mbox_hdr hdr;
     171                 :            :         int len = sizeof(octeontx_mbox_bgx_port_stats_t);
     172                 :            :         int res;
     173                 :            : 
     174                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     175                 :          0 :         hdr.msg = MBOX_BGX_PORT_GET_STATS;
     176                 :          0 :         hdr.vfid = port;
     177                 :            : 
     178                 :          0 :         res = octeontx_mbox_send(&hdr, NULL, 0, stats, len);
     179         [ #  # ]:          0 :         if (res < 0)
     180                 :          0 :                 return -EACCES;
     181                 :            :         return res;
     182                 :            : }
     183                 :            : 
     184                 :            : int
     185                 :          0 : octeontx_bgx_port_stats(int port, octeontx_mbox_bgx_port_stats_t *stats)
     186                 :            : {
     187                 :            :         struct octeontx_mbox_hdr hdr;
     188                 :            :         octeontx_mbox_bgx_port_stats_t bgx_stats;
     189                 :            :         int len = sizeof(octeontx_mbox_bgx_port_stats_t);
     190                 :            :         int res;
     191                 :            : 
     192                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     193                 :          0 :         hdr.msg = MBOX_BGX_PORT_GET_STATS;
     194                 :          0 :         hdr.vfid = port;
     195                 :            : 
     196                 :          0 :         res = octeontx_mbox_send(&hdr, NULL, 0, &bgx_stats, len);
     197         [ #  # ]:          0 :         if (res < 0)
     198                 :            :                 return -EACCES;
     199                 :            : 
     200                 :          0 :         stats->rx_packets = bgx_stats.rx_packets;
     201                 :          0 :         stats->rx_bytes = bgx_stats.rx_bytes;
     202                 :          0 :         stats->rx_dropped = bgx_stats.rx_dropped;
     203                 :          0 :         stats->rx_errors = bgx_stats.rx_errors;
     204                 :          0 :         stats->tx_packets = bgx_stats.tx_packets;
     205                 :          0 :         stats->tx_bytes = bgx_stats.tx_bytes;
     206                 :          0 :         stats->tx_dropped = bgx_stats.tx_dropped;
     207                 :          0 :         stats->tx_errors = bgx_stats.tx_errors;
     208                 :          0 :         return res;
     209                 :            : }
     210                 :            : 
     211                 :            : int
     212                 :          0 : octeontx_bgx_port_stats_clr(int port)
     213                 :            : {
     214                 :            :         struct octeontx_mbox_hdr hdr;
     215                 :            :         int res;
     216                 :            : 
     217                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     218                 :          0 :         hdr.msg = MBOX_BGX_PORT_CLR_STATS;
     219                 :          0 :         hdr.vfid = port;
     220                 :            : 
     221                 :          0 :         res = octeontx_mbox_send(&hdr, NULL, 0, NULL, 0);
     222         [ #  # ]:          0 :         if (res < 0)
     223                 :          0 :                 return -EACCES;
     224                 :            : 
     225                 :            :         return res;
     226                 :            : }
     227                 :            : 
     228                 :            : int
     229                 :          0 : octeontx_bgx_port_link_status(int port)
     230                 :            : {
     231                 :            :         struct octeontx_mbox_hdr hdr;
     232                 :            :         uint8_t link;
     233                 :            :         int len = sizeof(uint8_t);
     234                 :            :         int res;
     235                 :            : 
     236                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     237                 :          0 :         hdr.msg = MBOX_BGX_PORT_GET_LINK_STATUS;
     238                 :          0 :         hdr.vfid = port;
     239                 :            : 
     240                 :          0 :         res = octeontx_mbox_send(&hdr, NULL, 0, &link, len);
     241         [ #  # ]:          0 :         if (res < 0)
     242                 :            :                 return -EACCES;
     243                 :            : 
     244                 :          0 :         return link;
     245                 :            : }
     246                 :            : 
     247                 :            : int
     248                 :          0 : octeontx_bgx_port_set_link_state(int port, bool enable)
     249                 :            : {
     250                 :            :         struct octeontx_mbox_hdr hdr;
     251                 :            : 
     252                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     253                 :          0 :         hdr.msg = MBOX_BGX_PORT_SET_LINK_STATE;
     254                 :          0 :         hdr.vfid = port;
     255                 :            : 
     256                 :          0 :         return octeontx_mbox_send(&hdr, &enable, sizeof(bool), NULL, 0);
     257                 :            : }
     258                 :            : 
     259                 :            : int
     260                 :          0 : octeontx_bgx_port_promisc_set(int port, int en)
     261                 :            : {
     262                 :            :         struct octeontx_mbox_hdr hdr;
     263                 :            :         uint8_t prom;
     264                 :            :         int res;
     265                 :            : 
     266                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     267                 :          0 :         hdr.msg = MBOX_BGX_PORT_SET_PROMISC;
     268                 :          0 :         hdr.vfid = port;
     269                 :          0 :         prom = en ? 1 : 0;
     270                 :            : 
     271                 :          0 :         res = octeontx_mbox_send(&hdr, &prom, sizeof(prom), NULL, 0);
     272         [ #  # ]:          0 :         if (res < 0)
     273                 :          0 :                 return -EACCES;
     274                 :            : 
     275                 :            :         return res;
     276                 :            : }
     277                 :            : 
     278                 :            : int
     279                 :          0 : octeontx_bgx_port_mtu_set(int port, int mtu)
     280                 :            : {
     281                 :            :         struct octeontx_mbox_hdr hdr;
     282                 :            :         int res;
     283                 :            : 
     284                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     285                 :          0 :         hdr.msg = MBOX_BGX_PORT_SET_MTU;
     286                 :          0 :         hdr.vfid = port;
     287                 :            : 
     288                 :          0 :         res = octeontx_mbox_send(&hdr, &mtu, sizeof(mtu), NULL, 0);
     289         [ #  # ]:          0 :         if (res < 0)
     290                 :          0 :                 return -EACCES;
     291                 :            : 
     292                 :            :         return res;
     293                 :            : }
     294                 :            : 
     295                 :            : int
     296                 :          0 : octeontx_bgx_port_mac_set(int port, uint8_t *mac_addr)
     297                 :            : {
     298                 :            :         struct octeontx_mbox_hdr hdr;
     299                 :            :         int len = 6;
     300                 :            :         int res = 0;
     301                 :            : 
     302                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     303                 :          0 :         hdr.msg = MBOX_BGX_PORT_SET_MACADDR;
     304                 :          0 :         hdr.vfid = port;
     305                 :            : 
     306                 :          0 :         res = octeontx_mbox_send(&hdr, mac_addr, len, NULL, 0);
     307         [ #  # ]:          0 :         if (res < 0)
     308                 :          0 :                 return -EACCES;
     309                 :            : 
     310                 :            :         return res;
     311                 :            : }
     312                 :            : 
     313                 :            : int
     314                 :          0 : octeontx_bgx_port_mac_add(int port, uint8_t *mac_addr, int index)
     315                 :            : {
     316                 :            :         struct octeontx_mbox_bgx_port_mac_filter filter;
     317                 :            :         struct octeontx_mbox_hdr hdr;
     318                 :            :         int len = 6;
     319                 :            : 
     320                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     321                 :          0 :         hdr.msg = MBOX_BGX_PORT_ADD_MACADDR;
     322                 :          0 :         hdr.vfid = port;
     323                 :            : 
     324                 :            :         memcpy(filter.mac_addr, mac_addr, len);
     325                 :          0 :         filter.index = index;
     326                 :            :         len = sizeof(struct octeontx_mbox_bgx_port_mac_filter);
     327                 :            : 
     328                 :          0 :         return octeontx_mbox_send(&hdr, &filter, len, NULL, 0);
     329                 :            : }
     330                 :            : 
     331                 :            : int
     332                 :          0 : octeontx_bgx_port_mac_del(int port, uint32_t index)
     333                 :            : {
     334                 :            :         struct octeontx_mbox_hdr hdr;
     335                 :            :         int len = sizeof(uint32_t);
     336                 :            :         int res = 0;
     337                 :            : 
     338                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     339                 :          0 :         hdr.msg = MBOX_BGX_PORT_DEL_MACADDR;
     340                 :          0 :         hdr.vfid = port;
     341                 :            : 
     342                 :          0 :         res = octeontx_mbox_send(&hdr, &index, len, NULL, 0);
     343         [ #  # ]:          0 :         if (res < 0)
     344                 :          0 :                 return -EACCES;
     345                 :            : 
     346                 :            :         return res;
     347                 :            : }
     348                 :            : 
     349                 :            : int
     350                 :          0 : octeontx_bgx_port_mac_entries_get(int port)
     351                 :            : {
     352                 :            :         struct octeontx_mbox_hdr hdr;
     353                 :          0 :         int resp = 6;
     354                 :            :         int res = 0;
     355                 :            : 
     356                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     357                 :          0 :         hdr.msg = MBOX_BGX_PORT_GET_MACADDR_ENTRIES;
     358                 :          0 :         hdr.vfid = port;
     359                 :            : 
     360                 :          0 :         res = octeontx_mbox_send(&hdr, NULL, 0, &resp, sizeof(int));
     361         [ #  # ]:          0 :         if (res < 0)
     362                 :            :                 return -EACCES;
     363                 :            : 
     364                 :          0 :         return resp;
     365                 :            : }
     366                 :            : 
     367                 :          0 : int octeontx_bgx_port_get_fifo_cfg(int port,
     368                 :            :                                    octeontx_mbox_bgx_port_fifo_cfg_t *cfg)
     369                 :            : {
     370                 :            :         int len = sizeof(octeontx_mbox_bgx_port_fifo_cfg_t);
     371                 :            :         octeontx_mbox_bgx_port_fifo_cfg_t conf;
     372                 :            :         struct octeontx_mbox_hdr hdr;
     373                 :            : 
     374                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     375                 :          0 :         hdr.msg = MBOX_BGX_PORT_GET_FIFO_CFG;
     376                 :          0 :         hdr.vfid = port;
     377                 :            : 
     378         [ #  # ]:          0 :         if (octeontx_mbox_send(&hdr, NULL, 0, &conf, len) < 0)
     379                 :            :                 return -EACCES;
     380                 :            : 
     381                 :          0 :         cfg->rx_fifosz = conf.rx_fifosz;
     382                 :            : 
     383                 :          0 :         return 0;
     384                 :            : }
     385                 :            : 
     386                 :          0 : int octeontx_bgx_port_flow_ctrl_cfg(int port,
     387                 :            :                                     octeontx_mbox_bgx_port_fc_cfg_t *cfg)
     388                 :            : {
     389                 :            :         int len = sizeof(octeontx_mbox_bgx_port_fc_cfg_t);
     390                 :            :         octeontx_mbox_bgx_port_fc_cfg_t conf;
     391                 :            :         struct octeontx_mbox_hdr hdr;
     392                 :            : 
     393                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     394                 :          0 :         hdr.msg = MBOX_BGX_PORT_FLOW_CTRL_CFG;
     395                 :          0 :         hdr.vfid = port;
     396                 :            : 
     397         [ #  # ]:          0 :         if (cfg->fc_cfg == BGX_PORT_FC_CFG_SET)
     398                 :            :                 memcpy(&conf, cfg, len);
     399                 :            :         else
     400                 :            :                 memset(&conf, 0, len);
     401                 :            : 
     402         [ #  # ]:          0 :         if (octeontx_mbox_send(&hdr, &conf, len, &conf, len) < 0)
     403                 :            :                 return -EACCES;
     404                 :            : 
     405         [ #  # ]:          0 :         if (cfg->fc_cfg == BGX_PORT_FC_CFG_SET)
     406                 :          0 :                 goto done;
     407                 :            : 
     408                 :          0 :         cfg->rx_pause = conf.rx_pause;
     409                 :          0 :         cfg->tx_pause = conf.tx_pause;
     410                 :          0 :         cfg->low_water = conf.low_water;
     411                 :          0 :         cfg->high_water = conf.high_water;
     412                 :            : 
     413                 :            : done:
     414                 :            :         return 0;
     415                 :            : }
     416                 :            : 
     417                 :          0 : int octeontx_bgx_port_change_mode(int port,
     418                 :            :                                   octeontx_mbox_bgx_port_change_mode_t *cfg)
     419                 :            : {
     420                 :            :         int len = sizeof(octeontx_mbox_bgx_port_change_mode_t), res;
     421                 :            :         octeontx_mbox_bgx_port_change_mode_t conf;
     422                 :            :         struct octeontx_mbox_hdr hdr;
     423                 :            : 
     424                 :          0 :         hdr.coproc = OCTEONTX_BGX_COPROC;
     425                 :          0 :         hdr.msg = MBOX_BGX_PORT_CHANGE_MODE;
     426                 :          0 :         hdr.vfid = port;
     427                 :            : 
     428                 :            :         memcpy(&conf, cfg, len);
     429                 :          0 :         res = octeontx_mbox_send(&hdr, &conf, len, NULL, 0);
     430         [ #  # ]:          0 :         if (res < 0)
     431                 :          0 :                 return -EACCES;
     432                 :            : 
     433                 :            :         return res;
     434                 :            : }

Generated by: LCOV version 1.14