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

Generated by: LCOV version 1.14