LCOV - code coverage report
Current view: top level - drivers/bus/fslmc/mc - dpbp.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 66 0.0 %
Date: 2025-05-01 17:49:45 Functions: 0 11 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 12 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
       2                 :            :  *
       3                 :            :  * Copyright 2013-2016 Freescale Semiconductor Inc.
       4                 :            :  * Copyright 2016-2017 NXP
       5                 :            :  *
       6                 :            :  */
       7                 :            : #include <fsl_mc_sys.h>
       8                 :            : #include <fsl_mc_cmd.h>
       9                 :            : #include <fsl_dpbp.h>
      10                 :            : #include <fsl_dpbp_cmd.h>
      11                 :            : 
      12                 :            : #include <eal_export.h>
      13                 :            : 
      14                 :            : /**
      15                 :            :  * dpbp_open() - Open a control session for the specified object.
      16                 :            :  * @mc_io:      Pointer to MC portal's I/O object
      17                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
      18                 :            :  * @dpbp_id:    DPBP unique ID
      19                 :            :  * @token:      Returned token; use in subsequent API calls
      20                 :            :  *
      21                 :            :  * This function can be used to open a control session for an
      22                 :            :  * already created object; an object may have been declared in
      23                 :            :  * the DPL or by calling the dpbp_create function.
      24                 :            :  * This function returns a unique authentication token,
      25                 :            :  * associated with the specific object ID and the specific MC
      26                 :            :  * portal; this token must be used in all subsequent commands for
      27                 :            :  * this specific object
      28                 :            :  *
      29                 :            :  * Return:      '0' on Success; Error code otherwise.
      30                 :            :  */
      31                 :            : RTE_EXPORT_INTERNAL_SYMBOL(dpbp_open)
      32                 :          0 : int dpbp_open(struct fsl_mc_io *mc_io,
      33                 :            :               uint32_t cmd_flags,
      34                 :            :               int dpbp_id,
      35                 :            :               uint16_t *token)
      36                 :            : {
      37                 :            :         struct dpbp_cmd_open *cmd_params;
      38                 :          0 :         struct mc_command cmd = { 0 };
      39                 :            :         int err;
      40                 :            : 
      41                 :            :         /* prepare command */
      42                 :          0 :         cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
      43                 :            :                                           cmd_flags, 0);
      44                 :            :         cmd_params = (struct dpbp_cmd_open *)cmd.params;
      45                 :          0 :         cmd_params->dpbp_id = cpu_to_le32(dpbp_id);
      46                 :            : 
      47                 :            :         /* send command to mc*/
      48                 :          0 :         err = mc_send_command(mc_io, &cmd);
      49         [ #  # ]:          0 :         if (err)
      50                 :            :                 return err;
      51                 :            : 
      52                 :            :         /* retrieve response parameters */
      53                 :          0 :         *token = mc_cmd_hdr_read_token(&cmd);
      54                 :            : 
      55                 :          0 :         return err;
      56                 :            : }
      57                 :            : 
      58                 :            : /**
      59                 :            :  * dpbp_close() - Close the control session of the object
      60                 :            :  * @mc_io:      Pointer to MC portal's I/O object
      61                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
      62                 :            :  * @token:      Token of DPBP object
      63                 :            :  *
      64                 :            :  * After this function is called, no further operations are
      65                 :            :  * allowed on the object without opening a new control session.
      66                 :            :  *
      67                 :            :  * Return:      '0' on Success; Error code otherwise.
      68                 :            :  */
      69                 :          0 : int dpbp_close(struct fsl_mc_io *mc_io,
      70                 :            :                uint32_t cmd_flags,
      71                 :            :                uint16_t token)
      72                 :            : {
      73                 :          0 :         struct mc_command cmd = { 0 };
      74                 :            : 
      75                 :            :         /* prepare command */
      76                 :          0 :         cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
      77                 :            :                                           token);
      78                 :            : 
      79                 :            :         /* send command to mc*/
      80                 :          0 :         return mc_send_command(mc_io, &cmd);
      81                 :            : }
      82                 :            : 
      83                 :            : /**
      84                 :            :  * dpbp_create() - Create the DPBP object.
      85                 :            :  * @mc_io:      Pointer to MC portal's I/O object
      86                 :            :  * @dprc_token: Parent container token; '0' for default container
      87                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
      88                 :            :  * @cfg:        Configuration structure
      89                 :            :  * @obj_id:     Returned object id; use in subsequent API calls
      90                 :            :  *
      91                 :            :  * Create the DPBP object, allocate required resources and
      92                 :            :  * perform required initialization.
      93                 :            :  *
      94                 :            :  * This function accepts an authentication token of a parent
      95                 :            :  * container that this object should be assigned to and returns
      96                 :            :  * an object id. This object_id will be used in all subsequent calls to
      97                 :            :  * this specific object.
      98                 :            :  *
      99                 :            :  * Return:      '0' on Success; Error code otherwise.
     100                 :            :  */
     101                 :          0 : int dpbp_create(struct fsl_mc_io *mc_io,
     102                 :            :                 uint16_t dprc_token,
     103                 :            :                 uint32_t cmd_flags,
     104                 :            :                 const struct dpbp_cfg *cfg,
     105                 :            :                 uint32_t *obj_id)
     106                 :            : {
     107                 :          0 :         struct mc_command cmd = { 0 };
     108                 :            :         int err;
     109                 :            : 
     110                 :            :         (void)(cfg); /* unused */
     111                 :            : 
     112                 :            :         /* prepare command */
     113                 :          0 :         cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
     114                 :            :                                           cmd_flags, dprc_token);
     115                 :            : 
     116                 :            :         /* send command to mc*/
     117                 :          0 :         err = mc_send_command(mc_io, &cmd);
     118         [ #  # ]:          0 :         if (err)
     119                 :            :                 return err;
     120                 :            : 
     121                 :            :         /* retrieve response parameters */
     122                 :          0 :         *obj_id = mc_cmd_read_object_id(&cmd);
     123                 :            : 
     124                 :          0 :         return 0;
     125                 :            : }
     126                 :            : 
     127                 :            : /**
     128                 :            :  * dpbp_destroy() - Destroy the DPBP object and release all its resources.
     129                 :            :  * @mc_io:      Pointer to MC portal's I/O object
     130                 :            :  * @dprc_token: Parent container token; '0' for default container
     131                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
     132                 :            :  * @obj_id:     ID of DPBP object
     133                 :            :  *
     134                 :            :  * Return:      '0' on Success; error code otherwise.
     135                 :            :  */
     136                 :          0 : int dpbp_destroy(struct fsl_mc_io *mc_io,
     137                 :            :                  uint16_t dprc_token,
     138                 :            :                  uint32_t cmd_flags,
     139                 :            :                  uint32_t obj_id)
     140                 :            : {
     141                 :            :         struct dpbp_cmd_destroy *cmd_params;
     142                 :          0 :         struct mc_command cmd = { 0 };
     143                 :            : 
     144                 :            :         /* prepare command */
     145                 :          0 :         cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
     146                 :            :                                           cmd_flags, dprc_token);
     147                 :            : 
     148                 :            :         cmd_params = (struct dpbp_cmd_destroy *)cmd.params;
     149                 :          0 :         cmd_params->object_id = cpu_to_le32(obj_id);
     150                 :            : 
     151                 :            :         /* send command to mc*/
     152                 :          0 :         return mc_send_command(mc_io, &cmd);
     153                 :            : }
     154                 :            : 
     155                 :            : /**
     156                 :            :  * dpbp_enable() - Enable the DPBP.
     157                 :            :  * @mc_io:      Pointer to MC portal's I/O object
     158                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
     159                 :            :  * @token:      Token of DPBP object
     160                 :            :  *
     161                 :            :  * Return:      '0' on Success; Error code otherwise.
     162                 :            :  */
     163                 :            : RTE_EXPORT_INTERNAL_SYMBOL(dpbp_enable)
     164                 :          0 : int dpbp_enable(struct fsl_mc_io *mc_io,
     165                 :            :                 uint32_t cmd_flags,
     166                 :            :                 uint16_t token)
     167                 :            : {
     168                 :          0 :         struct mc_command cmd = { 0 };
     169                 :            : 
     170                 :            :         /* prepare command */
     171                 :          0 :         cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
     172                 :            :                                           token);
     173                 :            : 
     174                 :            :         /* send command to mc*/
     175                 :          0 :         return mc_send_command(mc_io, &cmd);
     176                 :            : }
     177                 :            : 
     178                 :            : /**
     179                 :            :  * dpbp_disable() - Disable the DPBP.
     180                 :            :  * @mc_io:      Pointer to MC portal's I/O object
     181                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
     182                 :            :  * @token:      Token of DPBP object
     183                 :            :  *
     184                 :            :  * Return:      '0' on Success; Error code otherwise.
     185                 :            :  */
     186                 :            : RTE_EXPORT_INTERNAL_SYMBOL(dpbp_disable)
     187                 :          0 : int dpbp_disable(struct fsl_mc_io *mc_io,
     188                 :            :                  uint32_t cmd_flags,
     189                 :            :                  uint16_t token)
     190                 :            : {
     191                 :          0 :         struct mc_command cmd = { 0 };
     192                 :            : 
     193                 :            :         /* prepare command */
     194                 :          0 :         cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
     195                 :            :                                           cmd_flags, token);
     196                 :            : 
     197                 :            :         /* send command to mc*/
     198                 :          0 :         return mc_send_command(mc_io, &cmd);
     199                 :            : }
     200                 :            : 
     201                 :            : /**
     202                 :            :  * dpbp_is_enabled() - Check if the DPBP is enabled.
     203                 :            :  * @mc_io:      Pointer to MC portal's I/O object
     204                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
     205                 :            :  * @token:      Token of DPBP object
     206                 :            :  * @en:         Returns '1' if object is enabled; '0' otherwise
     207                 :            :  *
     208                 :            :  * Return:      '0' on Success; Error code otherwise.
     209                 :            :  */
     210                 :          0 : int dpbp_is_enabled(struct fsl_mc_io *mc_io,
     211                 :            :                     uint32_t cmd_flags,
     212                 :            :                     uint16_t token,
     213                 :            :                     int *en)
     214                 :            : {
     215                 :            :         struct dpbp_rsp_is_enabled *rsp_params;
     216                 :          0 :         struct mc_command cmd = { 0 };
     217                 :            :         int err;
     218                 :            : 
     219                 :            :         /* prepare command */
     220                 :          0 :         cmd.header = mc_encode_cmd_header(DPBP_CMDID_IS_ENABLED, cmd_flags,
     221                 :            :                                           token);
     222                 :            : 
     223                 :            :         /* send command to mc*/
     224                 :          0 :         err = mc_send_command(mc_io, &cmd);
     225         [ #  # ]:          0 :         if (err)
     226                 :            :                 return err;
     227                 :            : 
     228                 :            :         /* retrieve response parameters */
     229                 :            :         rsp_params = (struct dpbp_rsp_is_enabled *)cmd.params;
     230                 :          0 :         *en = rsp_params->enabled & DPBP_ENABLE;
     231                 :            : 
     232                 :          0 :         return 0;
     233                 :            : }
     234                 :            : 
     235                 :            : /**
     236                 :            :  * dpbp_reset() - Reset the DPBP, returns the object to initial state.
     237                 :            :  * @mc_io:      Pointer to MC portal's I/O object
     238                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
     239                 :            :  * @token:      Token of DPBP object
     240                 :            :  *
     241                 :            :  * Return:      '0' on Success; Error code otherwise.
     242                 :            :  */
     243                 :            : RTE_EXPORT_INTERNAL_SYMBOL(dpbp_reset)
     244                 :          0 : int dpbp_reset(struct fsl_mc_io *mc_io,
     245                 :            :                uint32_t cmd_flags,
     246                 :            :                uint16_t token)
     247                 :            : {
     248                 :          0 :         struct mc_command cmd = { 0 };
     249                 :            : 
     250                 :            :         /* prepare command */
     251                 :          0 :         cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
     252                 :            :                                           cmd_flags, token);
     253                 :            : 
     254                 :            :         /* send command to mc*/
     255                 :          0 :         return mc_send_command(mc_io, &cmd);
     256                 :            : }
     257                 :            : /**
     258                 :            :  * dpbp_get_attributes - Retrieve DPBP attributes.
     259                 :            :  *
     260                 :            :  * @mc_io:      Pointer to MC portal's I/O object
     261                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
     262                 :            :  * @token:      Token of DPBP object
     263                 :            :  * @attr:       Returned object's attributes
     264                 :            :  *
     265                 :            :  * Return:      '0' on Success; Error code otherwise.
     266                 :            :  */
     267                 :            : RTE_EXPORT_INTERNAL_SYMBOL(dpbp_get_attributes)
     268                 :          0 : int dpbp_get_attributes(struct fsl_mc_io *mc_io,
     269                 :            :                         uint32_t cmd_flags,
     270                 :            :                         uint16_t token,
     271                 :            :                         struct dpbp_attr *attr)
     272                 :            : {
     273                 :            :         struct dpbp_rsp_get_attributes *rsp_params;
     274                 :          0 :         struct mc_command cmd = { 0 };
     275                 :            :         int err;
     276                 :            : 
     277                 :            :         /* prepare command */
     278                 :          0 :         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
     279                 :            :                                           cmd_flags, token);
     280                 :            : 
     281                 :            :         /* send command to mc*/
     282                 :          0 :         err = mc_send_command(mc_io, &cmd);
     283         [ #  # ]:          0 :         if (err)
     284                 :            :                 return err;
     285                 :            : 
     286                 :            :         /* retrieve response parameters */
     287                 :            :         rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
     288                 :          0 :         attr->bpid = le16_to_cpu(rsp_params->bpid);
     289                 :          0 :         attr->id = le32_to_cpu(rsp_params->id);
     290                 :            : 
     291                 :          0 :         return 0;
     292                 :            : }
     293                 :            : 
     294                 :            : /**
     295                 :            :  * dpbp_get_api_version - Get Data Path Buffer Pool API version
     296                 :            :  * @mc_io:      Pointer to Mc portal's I/O object
     297                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
     298                 :            :  * @major_ver:  Major version of Buffer Pool API
     299                 :            :  * @minor_ver:  Minor version of Buffer Pool API
     300                 :            :  *
     301                 :            :  * Return:      '0' on Success; Error code otherwise.
     302                 :            :  */
     303                 :          0 : int dpbp_get_api_version(struct fsl_mc_io *mc_io,
     304                 :            :                          uint32_t cmd_flags,
     305                 :            :                          uint16_t *major_ver,
     306                 :            :                          uint16_t *minor_ver)
     307                 :            : {
     308                 :            :         struct dpbp_rsp_get_api_version *rsp_params;
     309                 :          0 :         struct mc_command cmd = { 0 };
     310                 :            :         int err;
     311                 :            : 
     312                 :            :         /* prepare command */
     313                 :          0 :         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_API_VERSION,
     314                 :            :                                           cmd_flags, 0);
     315                 :            : 
     316                 :            :         /* send command to mc */
     317                 :          0 :         err = mc_send_command(mc_io, &cmd);
     318         [ #  # ]:          0 :         if (err)
     319                 :            :                 return err;
     320                 :            : 
     321                 :            :         /* retrieve response parameters */
     322                 :            :         rsp_params = (struct dpbp_rsp_get_api_version *)cmd.params;
     323                 :          0 :         *major_ver = le16_to_cpu(rsp_params->major);
     324                 :          0 :         *minor_ver = le16_to_cpu(rsp_params->minor);
     325                 :            : 
     326                 :          0 :         return 0;
     327                 :            : }
     328                 :            : 
     329                 :            : /**
     330                 :            :  * dpbp_get_num_free_bufs() - Get number of free buffers in the buffer pool
     331                 :            :  * @mc_io:  Pointer to MC portal's I/O object
     332                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
     333                 :            :  * @token:      Token of DPBP object
     334                 :            :  * @num_free_bufs:      Number of free buffers
     335                 :            :  *
     336                 :            :  * Return:  '0' on Success; Error code otherwise.
     337                 :            :  */
     338                 :            : 
     339                 :            : RTE_EXPORT_INTERNAL_SYMBOL(dpbp_get_num_free_bufs)
     340                 :          0 : int dpbp_get_num_free_bufs(struct fsl_mc_io *mc_io,
     341                 :            :                            uint32_t cmd_flags,
     342                 :            :                            uint16_t token,
     343                 :            :                            uint32_t *num_free_bufs)
     344                 :            : {
     345                 :            :         struct dpbp_rsp_get_num_free_bufs *rsp_params;
     346                 :          0 :         struct mc_command cmd = { 0 };
     347                 :            :         int err;
     348                 :            : 
     349                 :            :         /* prepare command */
     350                 :          0 :         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_FREE_BUFFERS_NUM,
     351                 :            :                                           cmd_flags,
     352                 :            :                                           token);
     353                 :            : 
     354                 :            :         /* send command to mc*/
     355                 :          0 :         err = mc_send_command(mc_io, &cmd);
     356         [ #  # ]:          0 :         if (err)
     357                 :            :                 return err;
     358                 :            : 
     359                 :            :         /* retrieve response parameters */
     360                 :            :         rsp_params = (struct dpbp_rsp_get_num_free_bufs *)cmd.params;
     361                 :          0 :         *num_free_bufs =  le32_to_cpu(rsp_params->num_free_bufs);
     362                 :            : 
     363                 :          0 :         return 0;
     364                 :            : }

Generated by: LCOV version 1.14