Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
0002 /*
0003  * Copyright 2013-2016 Freescale Semiconductor Inc.
0004  *
0005  */
0006 #include <linux/kernel.h>
0007 #include <linux/fsl/mc.h>
0008 
0009 #include "fsl-mc-private.h"
0010 
0011 /**
0012  * dpbp_open() - Open a control session for the specified object.
0013  * @mc_io:  Pointer to MC portal's I/O object
0014  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0015  * @dpbp_id:    DPBP unique ID
0016  * @token:  Returned token; use in subsequent API calls
0017  *
0018  * This function can be used to open a control session for an
0019  * already created object; an object may have been declared in
0020  * the DPL or by calling the dpbp_create function.
0021  * This function returns a unique authentication token,
0022  * associated with the specific object ID and the specific MC
0023  * portal; this token must be used in all subsequent commands for
0024  * this specific object
0025  *
0026  * Return:  '0' on Success; Error code otherwise.
0027  */
0028 int dpbp_open(struct fsl_mc_io *mc_io,
0029           u32 cmd_flags,
0030           int dpbp_id,
0031           u16 *token)
0032 {
0033     struct fsl_mc_command cmd = { 0 };
0034     struct dpbp_cmd_open *cmd_params;
0035     int err;
0036 
0037     /* prepare command */
0038     cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
0039                       cmd_flags, 0);
0040     cmd_params = (struct dpbp_cmd_open *)cmd.params;
0041     cmd_params->dpbp_id = cpu_to_le32(dpbp_id);
0042 
0043     /* send command to mc*/
0044     err = mc_send_command(mc_io, &cmd);
0045     if (err)
0046         return err;
0047 
0048     /* retrieve response parameters */
0049     *token = mc_cmd_hdr_read_token(&cmd);
0050 
0051     return err;
0052 }
0053 EXPORT_SYMBOL_GPL(dpbp_open);
0054 
0055 /**
0056  * dpbp_close() - Close the control session of the object
0057  * @mc_io:  Pointer to MC portal's I/O object
0058  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0059  * @token:  Token of DPBP object
0060  *
0061  * After this function is called, no further operations are
0062  * allowed on the object without opening a new control session.
0063  *
0064  * Return:  '0' on Success; Error code otherwise.
0065  */
0066 int dpbp_close(struct fsl_mc_io *mc_io,
0067            u32 cmd_flags,
0068            u16 token)
0069 {
0070     struct fsl_mc_command cmd = { 0 };
0071 
0072     /* prepare command */
0073     cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
0074                       token);
0075 
0076     /* send command to mc*/
0077     return mc_send_command(mc_io, &cmd);
0078 }
0079 EXPORT_SYMBOL_GPL(dpbp_close);
0080 
0081 /**
0082  * dpbp_enable() - Enable the DPBP.
0083  * @mc_io:  Pointer to MC portal's I/O object
0084  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0085  * @token:  Token of DPBP object
0086  *
0087  * Return:  '0' on Success; Error code otherwise.
0088  */
0089 int dpbp_enable(struct fsl_mc_io *mc_io,
0090         u32 cmd_flags,
0091         u16 token)
0092 {
0093     struct fsl_mc_command cmd = { 0 };
0094 
0095     /* prepare command */
0096     cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
0097                       token);
0098 
0099     /* send command to mc*/
0100     return mc_send_command(mc_io, &cmd);
0101 }
0102 EXPORT_SYMBOL_GPL(dpbp_enable);
0103 
0104 /**
0105  * dpbp_disable() - Disable the DPBP.
0106  * @mc_io:  Pointer to MC portal's I/O object
0107  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0108  * @token:  Token of DPBP object
0109  *
0110  * Return:  '0' on Success; Error code otherwise.
0111  */
0112 int dpbp_disable(struct fsl_mc_io *mc_io,
0113          u32 cmd_flags,
0114          u16 token)
0115 {
0116     struct fsl_mc_command cmd = { 0 };
0117 
0118     /* prepare command */
0119     cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
0120                       cmd_flags, token);
0121 
0122     /* send command to mc*/
0123     return mc_send_command(mc_io, &cmd);
0124 }
0125 EXPORT_SYMBOL_GPL(dpbp_disable);
0126 
0127 /**
0128  * dpbp_reset() - Reset the DPBP, returns the object to initial state.
0129  * @mc_io:  Pointer to MC portal's I/O object
0130  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0131  * @token:  Token of DPBP object
0132  *
0133  * Return:  '0' on Success; Error code otherwise.
0134  */
0135 int dpbp_reset(struct fsl_mc_io *mc_io,
0136            u32 cmd_flags,
0137            u16 token)
0138 {
0139     struct fsl_mc_command cmd = { 0 };
0140 
0141     /* prepare command */
0142     cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
0143                       cmd_flags, token);
0144 
0145     /* send command to mc*/
0146     return mc_send_command(mc_io, &cmd);
0147 }
0148 EXPORT_SYMBOL_GPL(dpbp_reset);
0149 
0150 /**
0151  * dpbp_get_attributes - Retrieve DPBP attributes.
0152  *
0153  * @mc_io:  Pointer to MC portal's I/O object
0154  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0155  * @token:  Token of DPBP object
0156  * @attr:   Returned object's attributes
0157  *
0158  * Return:  '0' on Success; Error code otherwise.
0159  */
0160 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
0161             u32 cmd_flags,
0162             u16 token,
0163             struct dpbp_attr *attr)
0164 {
0165     struct fsl_mc_command cmd = { 0 };
0166     struct dpbp_rsp_get_attributes *rsp_params;
0167     int err;
0168 
0169     /* prepare command */
0170     cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
0171                       cmd_flags, token);
0172 
0173     /* send command to mc*/
0174     err = mc_send_command(mc_io, &cmd);
0175     if (err)
0176         return err;
0177 
0178     /* retrieve response parameters */
0179     rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
0180     attr->bpid = le16_to_cpu(rsp_params->bpid);
0181     attr->id = le32_to_cpu(rsp_params->id);
0182 
0183     return 0;
0184 }
0185 EXPORT_SYMBOL_GPL(dpbp_get_attributes);