LCOV - code coverage report
Current view: top level - drivers/bus/fslmc/qbman - qbman_debug.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 238 0.0 %
Date: 2026-10-01 18:19:24 Functions: 0 74 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 54 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright (C) 2015 Freescale Semiconductor, Inc.
       3                 :            :  * Copyright 2018-2020,2022 NXP
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "compat.h"
       7                 :            : #include <fsl_qbman_debug.h>
       8                 :            : #include "qbman_portal.h"
       9                 :            : 
      10                 :            : #include <eal_export.h>
      11                 :            : 
      12                 :            : /* Mask used to extract the response verb from a management command result */
      13                 :            : #define QBMAN_RESPONSE_VERB_MASK  0x7f
      14                 :            : 
      15                 :            : /* QBMan portal management command code */
      16                 :            : #define QBMAN_BP_QUERY            0x32
      17                 :            : #define QBMAN_FQ_QUERY            0x44
      18                 :            : #define QBMAN_FQ_QUERY_NP         0x45
      19                 :            : #define QBMAN_WQ_QUERY            0x47
      20                 :            : #define QBMAN_CGR_QUERY           0x51
      21                 :            : #define QBMAN_WRED_QUERY          0x54
      22                 :            : #define QBMAN_CGR_STAT_QUERY      0x55
      23                 :            : #define QBMAN_CGR_STAT_QUERY_CLR  0x56
      24                 :            : 
      25                 :            : struct qbman_bp_query_desc {
      26                 :            :         uint8_t verb;
      27                 :            :         uint8_t reserved;
      28                 :            :         uint16_t bpid;
      29                 :            :         uint8_t reserved2[60];
      30                 :            : };
      31                 :            : 
      32                 :            : #define QB_BP_STATE_SHIFT  24
      33                 :            : #define QB_BP_VA_SHIFT     1
      34                 :            : #define QB_BP_VA_MASK      0x2
      35                 :            : #define QB_BP_WAE_SHIFT    2
      36                 :            : #define QB_BP_WAE_MASK     0x4
      37                 :            : #define QB_BP_PL_SHIFT     15
      38                 :            : #define QB_BP_PL_MASK      0x8000
      39                 :            : #define QB_BP_ICID_MASK    0x7FFF
      40                 :            : 
      41                 :          0 : int qbman_bp_query(struct qbman_swp *s, uint32_t bpid,
      42                 :            :                    struct qbman_bp_query_rslt *r)
      43                 :            : {
      44                 :            :         struct qbman_bp_query_desc *p;
      45                 :            :         struct qbman_bp_query_rslt *bp_query_rslt;
      46                 :            : 
      47                 :            :         /* Start the management command */
      48                 :          0 :         p = (struct qbman_bp_query_desc *)qbman_swp_mc_start(s);
      49         [ #  # ]:          0 :         if (!p)
      50                 :            :                 return -EBUSY;
      51                 :            : 
      52                 :            :         /* Encode the caller-provided attributes */
      53                 :          0 :         p->bpid = bpid;
      54                 :            : 
      55                 :            :         /* Complete the management command */
      56                 :          0 :         bp_query_rslt = (struct qbman_bp_query_rslt *)qbman_swp_mc_complete(s,
      57                 :            :                                                 p, QBMAN_BP_QUERY);
      58         [ #  # ]:          0 :         if (!bp_query_rslt) {
      59                 :          0 :                 pr_err("qbman: Query BPID %d failed, no response\n",
      60                 :            :                         bpid);
      61                 :          0 :                 return -EIO;
      62                 :            :         }
      63                 :            : 
      64                 :          0 :         *r = *bp_query_rslt;
      65                 :            : 
      66                 :            :         /* Decode the outcome */
      67                 :            :         QBMAN_BUG_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_BP_QUERY);
      68                 :            : 
      69                 :            :         /* Determine success or failure */
      70         [ #  # ]:          0 :         if (r->rslt != QBMAN_MC_RSLT_OK) {
      71                 :          0 :                 pr_err("Query of BPID 0x%x failed, code=0x%02x\n", bpid,
      72                 :            :                                                                 r->rslt);
      73                 :          0 :                 return -EIO;
      74                 :            :         }
      75                 :            : 
      76                 :            :         return 0;
      77                 :            : }
      78                 :            : 
      79                 :          0 : int qbman_bp_get_bdi(struct qbman_bp_query_rslt *r)
      80                 :            : {
      81                 :          0 :         return r->bdi & 1;
      82                 :            : }
      83                 :            : 
      84                 :          0 : int qbman_bp_get_va(struct qbman_bp_query_rslt *r)
      85                 :            : {
      86                 :          0 :         return (r->bdi & QB_BP_VA_MASK) >> QB_BP_VA_MASK;
      87                 :            : }
      88                 :            : 
      89                 :          0 : int qbman_bp_get_wae(struct qbman_bp_query_rslt *r)
      90                 :            : {
      91                 :          0 :         return (r->bdi & QB_BP_WAE_MASK) >> QB_BP_WAE_SHIFT;
      92                 :            : }
      93                 :            : 
      94                 :            : static uint16_t qbman_bp_thresh_to_value(uint16_t val)
      95                 :            : {
      96                 :          0 :         return (val & 0xff) << ((val & 0xf00) >> 8);
      97                 :            : }
      98                 :            : 
      99                 :          0 : uint16_t qbman_bp_get_swdet(struct qbman_bp_query_rslt  *r)
     100                 :            : {
     101                 :            : 
     102                 :          0 :         return qbman_bp_thresh_to_value(r->swdet);
     103                 :            : }
     104                 :            : 
     105                 :          0 : uint16_t qbman_bp_get_swdxt(struct qbman_bp_query_rslt  *r)
     106                 :            : {
     107                 :          0 :         return qbman_bp_thresh_to_value(r->swdxt);
     108                 :            : }
     109                 :            : 
     110                 :          0 : uint16_t qbman_bp_get_hwdet(struct qbman_bp_query_rslt  *r)
     111                 :            : {
     112                 :          0 :         return qbman_bp_thresh_to_value(r->hwdet);
     113                 :            : }
     114                 :            : 
     115                 :          0 : uint16_t qbman_bp_get_hwdxt(struct qbman_bp_query_rslt  *r)
     116                 :            : {
     117                 :          0 :         return qbman_bp_thresh_to_value(r->hwdxt);
     118                 :            : }
     119                 :            : 
     120                 :          0 : uint16_t qbman_bp_get_swset(struct qbman_bp_query_rslt  *r)
     121                 :            : {
     122                 :          0 :         return qbman_bp_thresh_to_value(r->swset);
     123                 :            : }
     124                 :            : 
     125                 :          0 : uint16_t qbman_bp_get_swsxt(struct qbman_bp_query_rslt  *r)
     126                 :            : {
     127                 :            : 
     128                 :          0 :         return qbman_bp_thresh_to_value(r->swsxt);
     129                 :            : }
     130                 :            : 
     131                 :          0 : uint16_t qbman_bp_get_vbpid(struct qbman_bp_query_rslt  *r)
     132                 :            : {
     133                 :          0 :         return r->vbpid;
     134                 :            : }
     135                 :            : 
     136                 :          0 : uint16_t qbman_bp_get_icid(struct qbman_bp_query_rslt  *r)
     137                 :            : {
     138                 :          0 :         return r->icid & QB_BP_ICID_MASK;
     139                 :            : }
     140                 :            : 
     141                 :          0 : int qbman_bp_get_pl(struct qbman_bp_query_rslt  *r)
     142                 :            : {
     143                 :          0 :         return (r->icid & QB_BP_PL_MASK) >> QB_BP_PL_SHIFT;
     144                 :            : }
     145                 :            : 
     146                 :          0 : uint64_t qbman_bp_get_bpscn_addr(struct qbman_bp_query_rslt  *r)
     147                 :            : {
     148                 :          0 :         return r->bpscn_addr;
     149                 :            : }
     150                 :            : 
     151                 :          0 : uint64_t qbman_bp_get_bpscn_ctx(struct qbman_bp_query_rslt  *r)
     152                 :            : {
     153                 :          0 :         return r->bpscn_ctx;
     154                 :            : }
     155                 :            : 
     156                 :          0 : uint16_t qbman_bp_get_hw_targ(struct qbman_bp_query_rslt  *r)
     157                 :            : {
     158                 :          0 :         return r->hw_targ;
     159                 :            : }
     160                 :            : 
     161                 :          0 : int qbman_bp_has_free_bufs(struct qbman_bp_query_rslt  *r)
     162                 :            : {
     163                 :          0 :         return !(int)(r->state & 0x1);
     164                 :            : }
     165                 :            : 
     166                 :          0 : int qbman_bp_is_depleted(struct qbman_bp_query_rslt  *r)
     167                 :            : {
     168                 :          0 :         return (int)((r->state & 0x2) >> 1);
     169                 :            : }
     170                 :            : 
     171                 :          0 : int qbman_bp_is_surplus(struct qbman_bp_query_rslt  *r)
     172                 :            : {
     173                 :          0 :         return (int)((r->state & 0x4) >> 2);
     174                 :            : }
     175                 :            : 
     176                 :          0 : uint32_t qbman_bp_num_free_bufs(struct qbman_bp_query_rslt  *r)
     177                 :            : {
     178                 :          0 :         return r->fill;
     179                 :            : }
     180                 :            : 
     181                 :          0 : uint32_t qbman_bp_get_hdptr(struct qbman_bp_query_rslt  *r)
     182                 :            : {
     183                 :          0 :         return r->hdptr;
     184                 :            : }
     185                 :            : 
     186                 :          0 : uint32_t qbman_bp_get_sdcnt(struct qbman_bp_query_rslt  *r)
     187                 :            : {
     188                 :          0 :         return r->sdcnt;
     189                 :            : }
     190                 :            : 
     191                 :          0 : uint32_t qbman_bp_get_hdcnt(struct qbman_bp_query_rslt  *r)
     192                 :            : {
     193                 :          0 :         return r->hdcnt;
     194                 :            : }
     195                 :            : 
     196                 :          0 : uint32_t qbman_bp_get_sscnt(struct qbman_bp_query_rslt  *r)
     197                 :            : {
     198                 :          0 :         return r->sscnt;
     199                 :            : }
     200                 :            : 
     201                 :            : struct qbman_fq_query_desc {
     202                 :            :         uint8_t verb;
     203                 :            :         uint8_t reserved[3];
     204                 :            :         uint32_t fqid;
     205                 :            :         uint8_t reserved2[56];
     206                 :            : };
     207                 :            : 
     208                 :            : /* FQ query function for programmable fields */
     209                 :          0 : int qbman_fq_query(struct qbman_swp *s, uint32_t fqid,
     210                 :            :                    struct qbman_fq_query_rslt *r)
     211                 :            : {
     212                 :            :         struct qbman_fq_query_desc *p;
     213                 :            :         struct qbman_fq_query_rslt *fq_query_rslt;
     214                 :            : 
     215                 :          0 :         p = (struct qbman_fq_query_desc *)qbman_swp_mc_start(s);
     216         [ #  # ]:          0 :         if (!p)
     217                 :            :                 return -EBUSY;
     218                 :            : 
     219                 :          0 :         p->fqid = fqid;
     220                 :          0 :         fq_query_rslt = (struct qbman_fq_query_rslt *)qbman_swp_mc_complete(s,
     221                 :            :                                         p, QBMAN_FQ_QUERY);
     222         [ #  # ]:          0 :         if (!fq_query_rslt) {
     223                 :          0 :                 pr_err("qbman: Query FQID %d failed, no response\n",
     224                 :            :                         fqid);
     225                 :          0 :                 return -EIO;
     226                 :            :         }
     227                 :            : 
     228                 :          0 :         *r = *fq_query_rslt;
     229                 :            : 
     230                 :            :         /* Decode the outcome */
     231                 :            :         QBMAN_BUG_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_FQ_QUERY);
     232                 :            : 
     233                 :            :         /* Determine success or failure */
     234         [ #  # ]:          0 :         if (r->rslt != QBMAN_MC_RSLT_OK) {
     235                 :          0 :                 pr_err("Query of FQID 0x%x failed, code=0x%02x\n",
     236                 :            :                        fqid, r->rslt);
     237                 :          0 :                 return -EIO;
     238                 :            :         }
     239                 :            : 
     240                 :            :         return 0;
     241                 :            : }
     242                 :            : 
     243                 :          0 : uint8_t qbman_fq_attr_get_fqctrl(struct qbman_fq_query_rslt *r)
     244                 :            : {
     245                 :          0 :         return r->fq_ctrl;
     246                 :            : }
     247                 :            : 
     248                 :          0 : uint16_t qbman_fq_attr_get_cgrid(struct qbman_fq_query_rslt *r)
     249                 :            : {
     250                 :          0 :         return r->cgid;
     251                 :            : }
     252                 :            : 
     253                 :          0 : uint16_t qbman_fq_attr_get_destwq(struct qbman_fq_query_rslt *r)
     254                 :            : {
     255                 :          0 :         return r->dest_wq;
     256                 :            : }
     257                 :            : 
     258                 :            : static uint16_t qbman_thresh_to_value(uint16_t val)
     259                 :            : {
     260                 :          0 :         return ((val & 0x1FE0) >> 5) << (val & 0x1F);
     261                 :            : }
     262                 :            : 
     263                 :          0 : uint16_t qbman_fq_attr_get_tdthresh(struct qbman_fq_query_rslt *r)
     264                 :            : {
     265                 :          0 :         return qbman_thresh_to_value(r->td_thresh);
     266                 :            : }
     267                 :            : 
     268                 :          0 : int qbman_fq_attr_get_oa_ics(struct qbman_fq_query_rslt *r)
     269                 :            : {
     270                 :          0 :         return (int)(r->oal_oac >> 14) & 0x1;
     271                 :            : }
     272                 :            : 
     273                 :          0 : int qbman_fq_attr_get_oa_cgr(struct qbman_fq_query_rslt *r)
     274                 :            : {
     275                 :          0 :         return (int)(r->oal_oac >> 15);
     276                 :            : }
     277                 :            : 
     278                 :          0 : uint16_t qbman_fq_attr_get_oal(struct qbman_fq_query_rslt *r)
     279                 :            : {
     280                 :          0 :         return (r->oal_oac & 0x0FFF);
     281                 :            : }
     282                 :            : 
     283                 :          0 : int qbman_fq_attr_get_bdi(struct qbman_fq_query_rslt *r)
     284                 :            : {
     285                 :          0 :         return (r->mctl & 0x1);
     286                 :            : }
     287                 :            : 
     288                 :          0 : int qbman_fq_attr_get_ff(struct qbman_fq_query_rslt *r)
     289                 :            : {
     290                 :          0 :         return (r->mctl & 0x2) >> 1;
     291                 :            : }
     292                 :            : 
     293                 :          0 : int qbman_fq_attr_get_va(struct qbman_fq_query_rslt *r)
     294                 :            : {
     295                 :          0 :         return (r->mctl & 0x4) >> 2;
     296                 :            : }
     297                 :            : 
     298                 :          0 : int qbman_fq_attr_get_ps(struct qbman_fq_query_rslt *r)
     299                 :            : {
     300                 :          0 :         return (r->mctl & 0x8) >> 3;
     301                 :            : }
     302                 :            : 
     303                 :          0 : int qbman_fq_attr_get_pps(struct qbman_fq_query_rslt *r)
     304                 :            : {
     305                 :          0 :         return (r->mctl & 0x30) >> 4;
     306                 :            : }
     307                 :            : 
     308                 :          0 : uint16_t qbman_fq_attr_get_icid(struct qbman_fq_query_rslt *r)
     309                 :            : {
     310                 :          0 :         return r->icid & 0x7FFF;
     311                 :            : }
     312                 :            : 
     313                 :          0 : int qbman_fq_attr_get_pl(struct qbman_fq_query_rslt *r)
     314                 :            : {
     315                 :          0 :         return (int)((r->icid & 0x8000) >> 15);
     316                 :            : }
     317                 :            : 
     318                 :          0 : uint32_t qbman_fq_attr_get_vfqid(struct qbman_fq_query_rslt *r)
     319                 :            : {
     320                 :          0 :         return r->vfqid & 0x00FFFFFF;
     321                 :            : }
     322                 :            : 
     323                 :          0 : uint32_t qbman_fq_attr_get_erfqid(struct qbman_fq_query_rslt *r)
     324                 :            : {
     325                 :          0 :         return r->fqid_er & 0x00FFFFFF;
     326                 :            : }
     327                 :            : 
     328                 :          0 : uint16_t qbman_fq_attr_get_opridsz(struct qbman_fq_query_rslt *r)
     329                 :            : {
     330                 :          0 :         return r->opridsz;
     331                 :            : }
     332                 :            : 
     333                 :            : RTE_EXPORT_INTERNAL_SYMBOL(qbman_fq_query_state)
     334                 :          0 : int qbman_fq_query_state(struct qbman_swp *s, uint32_t fqid,
     335                 :            :                          struct qbman_fq_query_np_rslt *r)
     336                 :            : {
     337                 :            :         struct qbman_fq_query_desc *p;
     338                 :            :         struct qbman_fq_query_np_rslt *var;
     339                 :            : 
     340                 :          0 :         p = (struct qbman_fq_query_desc *)qbman_swp_mc_start(s);
     341         [ #  # ]:          0 :         if (!p)
     342                 :            :                 return -EBUSY;
     343                 :            : 
     344                 :          0 :         p->fqid = fqid;
     345                 :          0 :         var = qbman_swp_mc_complete(s, p, QBMAN_FQ_QUERY_NP);
     346         [ #  # ]:          0 :         if (!var) {
     347                 :          0 :                 pr_err("qbman: Query FQID %d NP fields failed, no response\n",
     348                 :            :                        fqid);
     349                 :          0 :                 return -EIO;
     350                 :            :         }
     351                 :          0 :         *r = *var;
     352                 :            : 
     353                 :            :         /* Decode the outcome */
     354                 :            :         QBMAN_BUG_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_FQ_QUERY_NP);
     355                 :            : 
     356                 :            :         /* Determine success or failure */
     357         [ #  # ]:          0 :         if (r->rslt != QBMAN_MC_RSLT_OK) {
     358                 :          0 :                 pr_err("Query NP fields of FQID 0x%x failed, code=0x%02x\n",
     359                 :            :                        fqid, r->rslt);
     360                 :          0 :                 return -EIO;
     361                 :            :         }
     362                 :            : 
     363                 :            :         return 0;
     364                 :            : }
     365                 :            : 
     366                 :          0 : uint8_t qbman_fq_state_schedstate(const struct qbman_fq_query_np_rslt *r)
     367                 :            : {
     368                 :          0 :         return r->st1 & 0x7;
     369                 :            : }
     370                 :            : 
     371                 :          0 : int qbman_fq_state_force_eligible(const struct qbman_fq_query_np_rslt *r)
     372                 :            : {
     373                 :          0 :         return (int)((r->st1 & 0x8) >> 3);
     374                 :            : }
     375                 :            : 
     376                 :          0 : int qbman_fq_state_xoff(const struct qbman_fq_query_np_rslt *r)
     377                 :            : {
     378                 :          0 :         return (int)((r->st1 & 0x10) >> 4);
     379                 :            : }
     380                 :            : 
     381                 :          0 : int qbman_fq_state_retirement_pending(const struct qbman_fq_query_np_rslt *r)
     382                 :            : {
     383                 :          0 :         return (int)((r->st1 & 0x20) >> 5);
     384                 :            : }
     385                 :            : 
     386                 :          0 : int qbman_fq_state_overflow_error(const struct qbman_fq_query_np_rslt *r)
     387                 :            : {
     388                 :          0 :         return (int)((r->st1 & 0x40) >> 6);
     389                 :            : }
     390                 :            : 
     391                 :            : RTE_EXPORT_INTERNAL_SYMBOL(qbman_fq_state_frame_count)
     392                 :          0 : uint32_t qbman_fq_state_frame_count(const struct qbman_fq_query_np_rslt *r)
     393                 :            : {
     394                 :          0 :         return (r->frm_cnt & 0x00FFFFFF);
     395                 :            : }
     396                 :            : 
     397                 :          0 : uint32_t qbman_fq_state_byte_count(const struct qbman_fq_query_np_rslt *r)
     398                 :            : {
     399                 :          0 :         return r->byte_cnt;
     400                 :            : }
     401                 :            : 
     402                 :            : /* Query CGR */
     403                 :            : struct qbman_cgr_query_desc {
     404                 :            :         uint8_t verb;
     405                 :            :         uint8_t reserved;
     406                 :            :         uint16_t cgid;
     407                 :            :         uint8_t reserved2[60];
     408                 :            : };
     409                 :            : 
     410                 :          0 : int qbman_cgr_query(struct qbman_swp *s, uint32_t cgid,
     411                 :            :                     struct qbman_cgr_query_rslt *r)
     412                 :            : {
     413                 :            :         struct qbman_cgr_query_desc *p;
     414                 :            :         struct qbman_cgr_query_rslt *cgr_query_rslt;
     415                 :            : 
     416                 :          0 :         p = (struct qbman_cgr_query_desc *)qbman_swp_mc_start(s);
     417         [ #  # ]:          0 :         if (!p)
     418                 :            :                 return -EBUSY;
     419                 :            : 
     420                 :          0 :         p->cgid = cgid;
     421                 :          0 :         cgr_query_rslt = (struct qbman_cgr_query_rslt *)qbman_swp_mc_complete(s,
     422                 :            :                                         p, QBMAN_CGR_QUERY);
     423         [ #  # ]:          0 :         if (!cgr_query_rslt) {
     424                 :          0 :                 pr_err("qbman: Query CGID %d failed, no response\n",
     425                 :            :                         cgid);
     426                 :          0 :                 return -EIO;
     427                 :            :         }
     428                 :            : 
     429                 :          0 :         *r = *cgr_query_rslt;
     430                 :            : 
     431                 :            :         /* Decode the outcome */
     432                 :            :         QBMAN_BUG_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_CGR_QUERY);
     433                 :            : 
     434                 :            :         /* Determine success or failure */
     435         [ #  # ]:          0 :         if (r->rslt != QBMAN_MC_RSLT_OK) {
     436                 :          0 :                 pr_err("Query CGID 0x%x failed,code=0x%02x\n", cgid, r->rslt);
     437                 :          0 :                 return -EIO;
     438                 :            :         }
     439                 :            : 
     440                 :            :         return 0;
     441                 :            : }
     442                 :            : 
     443                 :          0 : int qbman_cgr_get_cscn_wq_en_enter(struct qbman_cgr_query_rslt *r)
     444                 :            : {
     445                 :          0 :         return (int)(r->ctl1 & 0x1);
     446                 :            : }
     447                 :            : 
     448                 :          0 : int qbman_cgr_get_cscn_wq_en_exit(struct qbman_cgr_query_rslt *r)
     449                 :            : {
     450                 :          0 :         return (int)((r->ctl1 & 0x2) >> 1);
     451                 :            : }
     452                 :            : 
     453                 :          0 : int qbman_cgr_get_cscn_wq_icd(struct qbman_cgr_query_rslt *r)
     454                 :            : {
     455                 :          0 :         return (int)((r->ctl1 & 0x4) >> 2);
     456                 :            : }
     457                 :            : 
     458                 :          0 : uint8_t qbman_cgr_get_mode(struct qbman_cgr_query_rslt *r)
     459                 :            : {
     460                 :          0 :         return r->mode & 0x3;
     461                 :            : }
     462                 :            : 
     463                 :          0 : int qbman_cgr_get_rej_cnt_mode(struct qbman_cgr_query_rslt *r)
     464                 :            : {
     465                 :          0 :         return (int)((r->mode & 0x4) >> 2);
     466                 :            : }
     467                 :            : 
     468                 :          0 : int qbman_cgr_get_cscn_bdi(struct qbman_cgr_query_rslt *r)
     469                 :            : {
     470                 :          0 :         return (int)((r->mode & 0x8) >> 3);
     471                 :            : }
     472                 :            : 
     473                 :          0 : uint16_t qbman_cgr_attr_get_cs_thres(struct qbman_cgr_query_rslt *r)
     474                 :            : {
     475                 :          0 :         return qbman_thresh_to_value(r->cs_thres);
     476                 :            : }
     477                 :            : 
     478                 :          0 : uint16_t qbman_cgr_attr_get_cs_thres_x(struct qbman_cgr_query_rslt *r)
     479                 :            : {
     480                 :          0 :         return qbman_thresh_to_value(r->cs_thres_x);
     481                 :            : }
     482                 :            : 
     483                 :          0 : uint16_t qbman_cgr_attr_get_td_thres(struct qbman_cgr_query_rslt *r)
     484                 :            : {
     485                 :          0 :         return qbman_thresh_to_value(r->td_thres);
     486                 :            : }
     487                 :            : 
     488                 :          0 : int qbman_cgr_wred_query(struct qbman_swp *s, uint32_t cgid,
     489                 :            :                         struct qbman_wred_query_rslt *r)
     490                 :            : {
     491                 :            :         struct qbman_cgr_query_desc *p;
     492                 :            :         struct qbman_wred_query_rslt *wred_query_rslt;
     493                 :            : 
     494                 :          0 :         p = (struct qbman_cgr_query_desc *)qbman_swp_mc_start(s);
     495         [ #  # ]:          0 :         if (!p)
     496                 :            :                 return -EBUSY;
     497                 :            : 
     498                 :          0 :         p->cgid = cgid;
     499                 :          0 :         wred_query_rslt = (struct qbman_wred_query_rslt *)qbman_swp_mc_complete(
     500                 :            :                                         s, p, QBMAN_WRED_QUERY);
     501         [ #  # ]:          0 :         if (!wred_query_rslt) {
     502                 :          0 :                 pr_err("qbman: Query CGID WRED %d failed, no response\n",
     503                 :            :                         cgid);
     504                 :          0 :                 return -EIO;
     505                 :            :         }
     506                 :            : 
     507                 :          0 :         *r = *wred_query_rslt;
     508                 :            : 
     509                 :            :         /* Decode the outcome */
     510                 :            :         QBMAN_BUG_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_WRED_QUERY);
     511                 :            : 
     512                 :            :         /* Determine success or failure */
     513         [ #  # ]:          0 :         if (r->rslt != QBMAN_MC_RSLT_OK) {
     514                 :          0 :                 pr_err("Query CGID WRED 0x%x failed,code=0x%02x\n",
     515                 :            :                                                          cgid, r->rslt);
     516                 :          0 :                 return -EIO;
     517                 :            :         }
     518                 :            : 
     519                 :            :         return 0;
     520                 :            : }
     521                 :            : 
     522                 :          0 : int qbman_cgr_attr_wred_get_edp(struct qbman_wred_query_rslt *r, uint32_t idx)
     523                 :            : {
     524                 :          0 :         return (int)(r->edp[idx] & 1);
     525                 :            : }
     526                 :            : 
     527                 :          0 : uint32_t qbman_cgr_attr_wred_get_parm_dp(struct qbman_wred_query_rslt *r,
     528                 :            :                                          uint32_t idx)
     529                 :            : {
     530                 :          0 :         return r->wred_parm_dp[idx];
     531                 :            : }
     532                 :            : 
     533                 :          0 : void qbman_cgr_attr_wred_dp_decompose(uint32_t dp, uint64_t *minth,
     534                 :            :                                       uint64_t *maxth, uint8_t *maxp)
     535                 :            : {
     536                 :            :         uint8_t ma, mn, step_i, step_s, pn;
     537                 :            : 
     538                 :          0 :         ma = (uint8_t)(dp >> 24);
     539                 :          0 :         mn = (uint8_t)(dp >> 19) & 0x1f;
     540                 :          0 :         step_i = (uint8_t)(dp >> 11);
     541                 :          0 :         step_s = (uint8_t)(dp >> 6) & 0x1f;
     542                 :          0 :         pn = (uint8_t)dp & 0x3f;
     543                 :            : 
     544                 :          0 :         *maxp = (uint8_t)(((pn<<2) * 100)/256);
     545                 :            : 
     546         [ #  # ]:          0 :         if (mn == 0)
     547                 :          0 :                 *maxth = ma;
     548                 :            :         else
     549                 :          0 :                 *maxth = ((uint64_t)(ma+256) * (1<<(mn-1)));
     550                 :            : 
     551         [ #  # ]:          0 :         if (step_s == 0)
     552                 :          0 :                 *minth = *maxth - step_i;
     553                 :            :         else
     554                 :          0 :                 *minth = *maxth - (256 + step_i) * (1<<(step_s - 1));
     555                 :          0 : }
     556                 :            : 
     557                 :            : /* Query CGR/CCGR/CQ statistics */
     558                 :            : struct qbman_cgr_statistics_query_desc {
     559                 :            :         uint8_t verb;
     560                 :            :         uint8_t reserved;
     561                 :            :         uint16_t cgid;
     562                 :            :         uint8_t reserved1;
     563                 :            :         uint8_t ct;
     564                 :            :         uint8_t reserved2[58];
     565                 :            : };
     566                 :            : 
     567                 :            : struct qbman_cgr_statistics_query_rslt {
     568                 :            :         uint8_t verb;
     569                 :            :         uint8_t rslt;
     570                 :            :         uint8_t reserved[14];
     571                 :            :         uint64_t frm_cnt;
     572                 :            :         uint64_t byte_cnt;
     573                 :            :         uint32_t reserved2[8];
     574                 :            : };
     575                 :            : 
     576                 :          0 : static int qbman_cgr_statistics_query(struct qbman_swp *s, uint32_t cgid,
     577                 :            :                                       int clear, uint32_t command_type,
     578                 :            :                                       uint64_t *frame_cnt, uint64_t *byte_cnt)
     579                 :            : {
     580                 :            :         struct qbman_cgr_statistics_query_desc *p;
     581                 :            :         struct qbman_cgr_statistics_query_rslt *r;
     582                 :            :         uint32_t query_verb;
     583                 :            : 
     584                 :          0 :         p = (struct qbman_cgr_statistics_query_desc *)qbman_swp_mc_start(s);
     585         [ #  # ]:          0 :         if (!p)
     586                 :            :                 return -EBUSY;
     587                 :            : 
     588                 :          0 :         p->cgid = cgid;
     589         [ #  # ]:          0 :         if (command_type < 2)
     590                 :          0 :                 p->ct = command_type;
     591                 :            :         query_verb = clear ?
     592         [ #  # ]:          0 :                         QBMAN_CGR_STAT_QUERY_CLR : QBMAN_CGR_STAT_QUERY;
     593                 :          0 :         r = (struct qbman_cgr_statistics_query_rslt *)qbman_swp_mc_complete(s,
     594                 :            :                                                         p, query_verb);
     595         [ #  # ]:          0 :         if (!r) {
     596                 :          0 :                 pr_err("qbman: Query CGID %d statistics failed, no response\n",
     597                 :            :                         cgid);
     598                 :          0 :                 return -EIO;
     599                 :            :         }
     600                 :            : 
     601                 :            :         /* Decode the outcome */
     602                 :            :         QBMAN_BUG_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != query_verb);
     603                 :            : 
     604                 :            :         /* Determine success or failure */
     605         [ #  # ]:          0 :         if (r->rslt != QBMAN_MC_RSLT_OK) {
     606                 :          0 :                 pr_err("Query statistics of CGID 0x%x failed, code=0x%02x\n",
     607                 :            :                                                 cgid, r->rslt);
     608                 :          0 :                 return -EIO;
     609                 :            :         }
     610                 :            : 
     611         [ #  # ]:          0 :         if (*frame_cnt)
     612                 :          0 :                 *frame_cnt = r->frm_cnt & 0xFFFFFFFFFFllu;
     613         [ #  # ]:          0 :         if (*byte_cnt)
     614                 :          0 :                 *byte_cnt = r->byte_cnt & 0xFFFFFFFFFFllu;
     615                 :            : 
     616                 :            :         return 0;
     617                 :            : }
     618                 :            : 
     619                 :          0 : int qbman_cgr_reject_statistics(struct qbman_swp *s, uint32_t cgid, int clear,
     620                 :            :                                 uint64_t *frame_cnt, uint64_t *byte_cnt)
     621                 :            : {
     622                 :          0 :         return qbman_cgr_statistics_query(s, cgid, clear, 0xff,
     623                 :            :                                           frame_cnt, byte_cnt);
     624                 :            : }
     625                 :            : 
     626                 :          0 : int qbman_ccgr_reject_statistics(struct qbman_swp *s, uint32_t cgid, int clear,
     627                 :            :                                  uint64_t *frame_cnt, uint64_t *byte_cnt)
     628                 :            : {
     629                 :          0 :         return qbman_cgr_statistics_query(s, cgid, clear, 1,
     630                 :            :                                           frame_cnt, byte_cnt);
     631                 :            : }
     632                 :            : 
     633                 :          0 : int qbman_cq_dequeue_statistics(struct qbman_swp *s, uint32_t cgid, int clear,
     634                 :            :                                 uint64_t *frame_cnt, uint64_t *byte_cnt)
     635                 :            : {
     636                 :          0 :         return qbman_cgr_statistics_query(s, cgid, clear, 0,
     637                 :            :                                           frame_cnt, byte_cnt);
     638                 :            : }
     639                 :            : 
     640                 :            : /* WQ Chan Query */
     641                 :            : struct qbman_wqchan_query_desc {
     642                 :            :         uint8_t verb;
     643                 :            :         uint8_t reserved;
     644                 :            :         uint16_t chid;
     645                 :            :         uint8_t reserved2[60];
     646                 :            : };
     647                 :            : 
     648                 :          0 : int qbman_wqchan_query(struct qbman_swp *s, uint16_t chanid,
     649                 :            :                        struct qbman_wqchan_query_rslt *r)
     650                 :            : {
     651                 :            :         struct qbman_wqchan_query_desc *p;
     652                 :            :         struct qbman_wqchan_query_rslt *wqchan_query_rslt;
     653                 :            : 
     654                 :            :         /* Start the management command */
     655                 :          0 :         p = (struct qbman_wqchan_query_desc *)qbman_swp_mc_start(s);
     656         [ #  # ]:          0 :         if (!p)
     657                 :            :                 return -EBUSY;
     658                 :            : 
     659                 :            :         /* Encode the caller-provided attributes */
     660                 :          0 :         p->chid = chanid;
     661                 :            : 
     662                 :            :         /* Complete the management command */
     663                 :          0 :         wqchan_query_rslt = (struct qbman_wqchan_query_rslt *)qbman_swp_mc_complete(
     664                 :            :                                                 s, p, QBMAN_WQ_QUERY);
     665         [ #  # ]:          0 :         if (!wqchan_query_rslt) {
     666                 :          0 :                 pr_err("qbman: Query WQ Channel %d failed, no response\n",
     667                 :            :                         chanid);
     668                 :          0 :                 return -EIO;
     669                 :            :         }
     670                 :            : 
     671                 :          0 :         *r = *wqchan_query_rslt;
     672                 :            : 
     673                 :            :         /* Decode the outcome */
     674                 :            :         QBMAN_BUG_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_WQ_QUERY);
     675                 :            : 
     676                 :            :         /* Determine success or failure */
     677         [ #  # ]:          0 :         if (r->rslt != QBMAN_MC_RSLT_OK) {
     678                 :          0 :                 pr_err("Query of WQCHAN 0x%x failed, code=0x%02x\n",
     679                 :            :                        chanid, r->rslt);
     680                 :          0 :                 return -EIO;
     681                 :            :         }
     682                 :            : 
     683                 :            :         return 0;
     684                 :            : }
     685                 :            : 
     686                 :          0 : uint32_t qbman_wqchan_attr_get_wqlen(struct qbman_wqchan_query_rslt *r, int wq)
     687                 :            : {
     688                 :          0 :         return r->wq_len[wq] & 0x00FFFFFF;
     689                 :            : }
     690                 :            : 
     691                 :          0 : uint64_t qbman_wqchan_attr_get_cdan_ctx(struct qbman_wqchan_query_rslt *r)
     692                 :            : {
     693                 :          0 :         return r->cdan_ctx;
     694                 :            : }
     695                 :            : 
     696                 :          0 : uint16_t qbman_wqchan_attr_get_cdan_wqid(struct qbman_wqchan_query_rslt *r)
     697                 :            : {
     698                 :          0 :         return r->cdan_wqid;
     699                 :            : }
     700                 :            : 
     701                 :          0 : uint8_t qbman_wqchan_attr_get_ctrl(struct qbman_wqchan_query_rslt *r)
     702                 :            : {
     703                 :          0 :         return r->ctrl;
     704                 :            : }
     705                 :            : 
     706                 :          0 : uint16_t qbman_wqchan_attr_get_chanid(struct qbman_wqchan_query_rslt *r)
     707                 :            : {
     708                 :          0 :         return r->chid;
     709                 :            : }

Generated by: LCOV version 1.14