LCOV - code coverage report
Current view: top level - drivers/bus/fslmc/mc - dpcon.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 61 0.0 %
Date: 2025-03-01 20:23:48 Functions: 0 10 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 10 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 2017-2019 NXP
       5                 :            :  *
       6                 :            :  */
       7                 :            : #include <fsl_mc_sys.h>
       8                 :            : #include <fsl_mc_cmd.h>
       9                 :            : #include <fsl_dpcon.h>
      10                 :            : #include <fsl_dpcon_cmd.h>
      11                 :            : 
      12                 :            : /**
      13                 :            :  * dpcon_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                 :            :  * @dpcon_id:   DPCON 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 dpcon_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 dpcon_open(struct fsl_mc_io *mc_io,
      30                 :            :                uint32_t cmd_flags,
      31                 :            :                int dpcon_id,
      32                 :            :                uint16_t *token)
      33                 :            : {
      34                 :          0 :         struct mc_command cmd = { 0 };
      35                 :            :         struct dpcon_cmd_open *dpcon_cmd;
      36                 :            :         int err;
      37                 :            : 
      38                 :            :         /* prepare command */
      39                 :          0 :         cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
      40                 :            :                                           cmd_flags,
      41                 :            :                                           0);
      42                 :            :         dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
      43                 :          0 :         dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
      44                 :            : 
      45                 :            :         /* send command to mc*/
      46                 :          0 :         err = mc_send_command(mc_io, &cmd);
      47         [ #  # ]:          0 :         if (err)
      48                 :            :                 return err;
      49                 :            : 
      50                 :            :         /* retrieve response parameters */
      51                 :          0 :         *token = mc_cmd_hdr_read_token(&cmd);
      52                 :            : 
      53                 :          0 :         return 0;
      54                 :            : }
      55                 :            : 
      56                 :            : /**
      57                 :            :  * dpcon_close() - Close the control session of the object
      58                 :            :  * @mc_io:      Pointer to MC portal's I/O object
      59                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
      60                 :            :  * @token:      Token of DPCON object
      61                 :            :  *
      62                 :            :  * After this function is called, no further operations are
      63                 :            :  * allowed on the object without opening a new control session.
      64                 :            :  *
      65                 :            :  * Return:      '0' on Success; Error code otherwise.
      66                 :            :  */
      67                 :          0 : int dpcon_close(struct fsl_mc_io *mc_io,
      68                 :            :                 uint32_t cmd_flags,
      69                 :            :                 uint16_t token)
      70                 :            : {
      71                 :          0 :         struct mc_command cmd = { 0 };
      72                 :            : 
      73                 :            :         /* prepare command */
      74                 :          0 :         cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
      75                 :            :                                           cmd_flags,
      76                 :            :                                           token);
      77                 :            : 
      78                 :            :         /* send command to mc*/
      79                 :          0 :         return mc_send_command(mc_io, &cmd);
      80                 :            : }
      81                 :            : 
      82                 :            : /**
      83                 :            :  * dpcon_create() - Create the DPCON object.
      84                 :            :  * @mc_io:      Pointer to MC portal's I/O object
      85                 :            :  * @dprc_token: Parent container token; '0' for default container
      86                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
      87                 :            :  * @cfg:        Configuration structure
      88                 :            :  * @obj_id:     Returned object id; use in subsequent API calls
      89                 :            :  *
      90                 :            :  * Create the DPCON object, allocate required resources and
      91                 :            :  * perform required initialization.
      92                 :            :  *
      93                 :            :  * The object can be created either by declaring it in the
      94                 :            :  * DPL file, or by calling this function.
      95                 :            :  *
      96                 :            :  * This function accepts an authentication token of a parent
      97                 :            :  * container that this object should be assigned to and returns
      98                 :            :  * an object id. This object_id will be used in all subsequent calls to
      99                 :            :  * this specific object.
     100                 :            :  *
     101                 :            :  * Return:      '0' on Success; Error code otherwise.
     102                 :            :  */
     103                 :          0 : int dpcon_create(struct fsl_mc_io *mc_io,
     104                 :            :                  uint16_t dprc_token,
     105                 :            :                  uint32_t cmd_flags,
     106                 :            :                  const struct dpcon_cfg *cfg,
     107                 :            :                  uint32_t *obj_id)
     108                 :            : {
     109                 :            :         struct dpcon_cmd_create *dpcon_cmd;
     110                 :          0 :         struct mc_command cmd = { 0 };
     111                 :            :         int err;
     112                 :            : 
     113                 :            :         /* prepare command */
     114                 :          0 :         cmd.header = mc_encode_cmd_header(DPCON_CMDID_CREATE,
     115                 :            :                                           cmd_flags,
     116                 :            :                                           dprc_token);
     117                 :            :         dpcon_cmd = (struct dpcon_cmd_create *)cmd.params;
     118                 :          0 :         dpcon_cmd->num_priorities = cfg->num_priorities;
     119                 :            : 
     120                 :            :         /* send command to mc*/
     121                 :          0 :         err = mc_send_command(mc_io, &cmd);
     122         [ #  # ]:          0 :         if (err)
     123                 :            :                 return err;
     124                 :            : 
     125                 :            :         /* retrieve response parameters */
     126                 :          0 :         *obj_id = mc_cmd_read_object_id(&cmd);
     127                 :            : 
     128                 :          0 :         return 0;
     129                 :            : }
     130                 :            : 
     131                 :            : /**
     132                 :            :  * dpcon_destroy() - Destroy the DPCON object and release all its resources.
     133                 :            :  * @mc_io:      Pointer to MC portal's I/O object
     134                 :            :  * @dprc_token: Parent container token; '0' for default container
     135                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
     136                 :            :  * @obj_id:     ID of DPCON object
     137                 :            :  *
     138                 :            :  * Return:      '0' on Success; error code otherwise.
     139                 :            :  */
     140                 :          0 : int dpcon_destroy(struct fsl_mc_io *mc_io,
     141                 :            :                   uint16_t dprc_token,
     142                 :            :                   uint32_t cmd_flags,
     143                 :            :                   uint32_t obj_id)
     144                 :            : {
     145                 :            :         struct dpcon_cmd_destroy *cmd_params;
     146                 :          0 :         struct mc_command cmd = { 0 };
     147                 :            : 
     148                 :            :         /* prepare command */
     149                 :          0 :         cmd.header = mc_encode_cmd_header(DPCON_CMDID_DESTROY,
     150                 :            :                                           cmd_flags,
     151                 :            :                                           dprc_token);
     152                 :            :         cmd_params = (struct dpcon_cmd_destroy *)cmd.params;
     153                 :          0 :         cmd_params->object_id = cpu_to_le32(obj_id);
     154                 :            : 
     155                 :            :         /* send command to mc*/
     156                 :          0 :         return mc_send_command(mc_io, &cmd);
     157                 :            : }
     158                 :            : 
     159                 :            : /**
     160                 :            :  * dpcon_enable() - Enable the DPCON
     161                 :            :  * @mc_io:      Pointer to MC portal's I/O object
     162                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
     163                 :            :  * @token:      Token of DPCON object
     164                 :            :  *
     165                 :            :  * Return:      '0' on Success; Error code otherwise
     166                 :            :  */
     167                 :          0 : int dpcon_enable(struct fsl_mc_io *mc_io,
     168                 :            :                  uint32_t cmd_flags,
     169                 :            :                  uint16_t token)
     170                 :            : {
     171                 :          0 :         struct mc_command cmd = { 0 };
     172                 :            : 
     173                 :            :         /* prepare command */
     174                 :          0 :         cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
     175                 :            :                                           cmd_flags,
     176                 :            :                                           token);
     177                 :            : 
     178                 :            :         /* send command to mc*/
     179                 :          0 :         return mc_send_command(mc_io, &cmd);
     180                 :            : }
     181                 :            : 
     182                 :            : /**
     183                 :            :  * dpcon_disable() - Disable the DPCON
     184                 :            :  * @mc_io:      Pointer to MC portal's I/O object
     185                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
     186                 :            :  * @token:      Token of DPCON object
     187                 :            :  *
     188                 :            :  * Return:      '0' on Success; Error code otherwise
     189                 :            :  */
     190                 :          0 : int dpcon_disable(struct fsl_mc_io *mc_io,
     191                 :            :                   uint32_t cmd_flags,
     192                 :            :                   uint16_t token)
     193                 :            : {
     194                 :          0 :         struct mc_command cmd = { 0 };
     195                 :            : 
     196                 :            :         /* prepare command */
     197                 :          0 :         cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
     198                 :            :                                           cmd_flags,
     199                 :            :                                           token);
     200                 :            : 
     201                 :            :         /* send command to mc*/
     202                 :          0 :         return mc_send_command(mc_io, &cmd);
     203                 :            : }
     204                 :            : 
     205                 :            : /**
     206                 :            :  * dpcon_is_enabled() - Check if the DPCON is enabled.
     207                 :            :  * @mc_io:      Pointer to MC portal's I/O object
     208                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
     209                 :            :  * @token:      Token of DPCON object
     210                 :            :  * @en:         Returns '1' if object is enabled; '0' otherwise
     211                 :            :  *
     212                 :            :  * Return:      '0' on Success; Error code otherwise.
     213                 :            :  */
     214                 :          0 : int dpcon_is_enabled(struct fsl_mc_io *mc_io,
     215                 :            :                      uint32_t cmd_flags,
     216                 :            :                      uint16_t token,
     217                 :            :                      int *en)
     218                 :            : {
     219                 :            :         struct dpcon_rsp_is_enabled *dpcon_rsp;
     220                 :          0 :         struct mc_command cmd = { 0 };
     221                 :            :         int err;
     222                 :            : 
     223                 :            :         /* prepare command */
     224                 :          0 :         cmd.header = mc_encode_cmd_header(DPCON_CMDID_IS_ENABLED,
     225                 :            :                                           cmd_flags,
     226                 :            :                                           token);
     227                 :            : 
     228                 :            :         /* send command to mc*/
     229                 :          0 :         err = mc_send_command(mc_io, &cmd);
     230         [ #  # ]:          0 :         if (err)
     231                 :            :                 return err;
     232                 :            : 
     233                 :            :         /* retrieve response parameters */
     234                 :            :         dpcon_rsp = (struct dpcon_rsp_is_enabled *)cmd.params;
     235                 :          0 :         *en = dpcon_rsp->enabled & DPCON_ENABLE;
     236                 :            : 
     237                 :          0 :         return 0;
     238                 :            : }
     239                 :            : 
     240                 :            : /**
     241                 :            :  * dpcon_reset() - Reset the DPCON, returns the object to initial state.
     242                 :            :  * @mc_io:      Pointer to MC portal's I/O object
     243                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
     244                 :            :  * @token:      Token of DPCON object
     245                 :            :  *
     246                 :            :  * Return:      '0' on Success; Error code otherwise.
     247                 :            :  */
     248                 :          0 : int dpcon_reset(struct fsl_mc_io *mc_io,
     249                 :            :                 uint32_t cmd_flags,
     250                 :            :                 uint16_t token)
     251                 :            : {
     252                 :          0 :         struct mc_command cmd = { 0 };
     253                 :            : 
     254                 :            :         /* prepare command */
     255                 :          0 :         cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
     256                 :            :                                           cmd_flags, token);
     257                 :            : 
     258                 :            :         /* send command to mc*/
     259                 :          0 :         return mc_send_command(mc_io, &cmd);
     260                 :            : }
     261                 :            : 
     262                 :            : /**
     263                 :            :  * dpcon_get_attributes() - Retrieve DPCON attributes.
     264                 :            :  * @mc_io:      Pointer to MC portal's I/O object
     265                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
     266                 :            :  * @token:      Token of DPCON object
     267                 :            :  * @attr:       Object's attributes
     268                 :            :  *
     269                 :            :  * Return:      '0' on Success; Error code otherwise.
     270                 :            :  */
     271                 :          0 : int dpcon_get_attributes(struct fsl_mc_io *mc_io,
     272                 :            :                          uint32_t cmd_flags,
     273                 :            :                          uint16_t token,
     274                 :            :                          struct dpcon_attr *attr)
     275                 :            : {
     276                 :            :         struct dpcon_rsp_get_attr *dpcon_rsp;
     277                 :          0 :         struct mc_command cmd = { 0 };
     278                 :            :         int err;
     279                 :            : 
     280                 :            :         /* prepare command */
     281                 :          0 :         cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
     282                 :            :                                           cmd_flags,
     283                 :            :                                           token);
     284                 :            : 
     285                 :            :         /* send command to mc*/
     286                 :          0 :         err = mc_send_command(mc_io, &cmd);
     287         [ #  # ]:          0 :         if (err)
     288                 :            :                 return err;
     289                 :            : 
     290                 :            :         /* retrieve response parameters */
     291                 :            :         dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;
     292                 :          0 :         attr->id = le32_to_cpu(dpcon_rsp->id);
     293                 :          0 :         attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);
     294                 :          0 :         attr->num_priorities = dpcon_rsp->num_priorities;
     295                 :            : 
     296                 :          0 :         return 0;
     297                 :            : }
     298                 :            : 
     299                 :            : /**
     300                 :            :  * dpcon_get_api_version - Get Data Path Concentrator API version
     301                 :            :  * @mc_io:      Pointer to MC portal's DPCON object
     302                 :            :  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
     303                 :            :  * @major_ver:  Major version of DPCON API
     304                 :            :  * @minor_ver:  Minor version of DPCON API
     305                 :            :  *
     306                 :            :  * Return:      '0' on Success; Error code otherwise
     307                 :            :  */
     308                 :          0 : int dpcon_get_api_version(struct fsl_mc_io *mc_io,
     309                 :            :                           uint32_t cmd_flags,
     310                 :            :                           uint16_t *major_ver,
     311                 :            :                           uint16_t *minor_ver)
     312                 :            : {
     313                 :            :         struct dpcon_rsp_get_api_version *rsp_params;
     314                 :          0 :         struct mc_command cmd = { 0 };
     315                 :            :         int err;
     316                 :            : 
     317                 :            :         /* prepare command */
     318                 :          0 :         cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_API_VERSION,
     319                 :            :                                           cmd_flags, 0);
     320                 :            : 
     321                 :            :         /* send command to mc */
     322                 :          0 :         err = mc_send_command(mc_io, &cmd);
     323         [ #  # ]:          0 :         if (err)
     324                 :            :                 return err;
     325                 :            : 
     326                 :            :         /* retrieve response parameters */
     327                 :            :         rsp_params = (struct dpcon_rsp_get_api_version *)cmd.params;
     328                 :          0 :         *major_ver = le16_to_cpu(rsp_params->major);
     329                 :          0 :         *minor_ver = le16_to_cpu(rsp_params->minor);
     330                 :            : 
     331                 :          0 :         return 0;
     332                 :            : }

Generated by: LCOV version 1.14