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

Generated by: LCOV version 1.14