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  * dpcon_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  * @dpcon_id:   DPCON 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 dpcon_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 dpcon_open(struct fsl_mc_io *mc_io,
0029            u32 cmd_flags,
0030            int dpcon_id,
0031            u16 *token)
0032 {
0033     struct fsl_mc_command cmd = { 0 };
0034     struct dpcon_cmd_open *dpcon_cmd;
0035     int err;
0036 
0037     /* prepare command */
0038     cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
0039                       cmd_flags,
0040                       0);
0041     dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
0042     dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
0043 
0044     /* send command to mc*/
0045     err = mc_send_command(mc_io, &cmd);
0046     if (err)
0047         return err;
0048 
0049     /* retrieve response parameters */
0050     *token = mc_cmd_hdr_read_token(&cmd);
0051 
0052     return 0;
0053 }
0054 EXPORT_SYMBOL_GPL(dpcon_open);
0055 
0056 /**
0057  * dpcon_close() - Close the control session of the object
0058  * @mc_io:  Pointer to MC portal's I/O object
0059  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0060  * @token:  Token of DPCON object
0061  *
0062  * After this function is called, no further operations are
0063  * allowed on the object without opening a new control session.
0064  *
0065  * Return:  '0' on Success; Error code otherwise.
0066  */
0067 int dpcon_close(struct fsl_mc_io *mc_io,
0068         u32 cmd_flags,
0069         u16 token)
0070 {
0071     struct fsl_mc_command cmd = { 0 };
0072 
0073     /* prepare command */
0074     cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
0075                       cmd_flags,
0076                       token);
0077 
0078     /* send command to mc*/
0079     return mc_send_command(mc_io, &cmd);
0080 }
0081 EXPORT_SYMBOL_GPL(dpcon_close);
0082 
0083 /**
0084  * dpcon_enable() - Enable the DPCON
0085  * @mc_io:  Pointer to MC portal's I/O object
0086  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0087  * @token:  Token of DPCON object
0088  *
0089  * Return:  '0' on Success; Error code otherwise
0090  */
0091 int dpcon_enable(struct fsl_mc_io *mc_io,
0092          u32 cmd_flags,
0093          u16 token)
0094 {
0095     struct fsl_mc_command cmd = { 0 };
0096 
0097     /* prepare command */
0098     cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
0099                       cmd_flags,
0100                       token);
0101 
0102     /* send command to mc*/
0103     return mc_send_command(mc_io, &cmd);
0104 }
0105 EXPORT_SYMBOL_GPL(dpcon_enable);
0106 
0107 /**
0108  * dpcon_disable() - Disable the DPCON
0109  * @mc_io:  Pointer to MC portal's I/O object
0110  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0111  * @token:  Token of DPCON object
0112  *
0113  * Return:  '0' on Success; Error code otherwise
0114  */
0115 int dpcon_disable(struct fsl_mc_io *mc_io,
0116           u32 cmd_flags,
0117           u16 token)
0118 {
0119     struct fsl_mc_command cmd = { 0 };
0120 
0121     /* prepare command */
0122     cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
0123                       cmd_flags,
0124                       token);
0125 
0126     /* send command to mc*/
0127     return mc_send_command(mc_io, &cmd);
0128 }
0129 EXPORT_SYMBOL_GPL(dpcon_disable);
0130 
0131 /**
0132  * dpcon_reset() - Reset the DPCON, returns the object to initial state.
0133  * @mc_io:  Pointer to MC portal's I/O object
0134  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0135  * @token:  Token of DPCON object
0136  *
0137  * Return:  '0' on Success; Error code otherwise.
0138  */
0139 int dpcon_reset(struct fsl_mc_io *mc_io,
0140         u32 cmd_flags,
0141         u16 token)
0142 {
0143     struct fsl_mc_command cmd = { 0 };
0144 
0145     /* prepare command */
0146     cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
0147                       cmd_flags, token);
0148 
0149     /* send command to mc*/
0150     return mc_send_command(mc_io, &cmd);
0151 }
0152 EXPORT_SYMBOL_GPL(dpcon_reset);
0153 
0154 /**
0155  * dpcon_get_attributes() - Retrieve DPCON attributes.
0156  * @mc_io:  Pointer to MC portal's I/O object
0157  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0158  * @token:  Token of DPCON object
0159  * @attr:   Object's attributes
0160  *
0161  * Return:  '0' on Success; Error code otherwise.
0162  */
0163 int dpcon_get_attributes(struct fsl_mc_io *mc_io,
0164              u32 cmd_flags,
0165              u16 token,
0166              struct dpcon_attr *attr)
0167 {
0168     struct fsl_mc_command cmd = { 0 };
0169     struct dpcon_rsp_get_attr *dpcon_rsp;
0170     int err;
0171 
0172     /* prepare command */
0173     cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
0174                       cmd_flags,
0175                       token);
0176 
0177     /* send command to mc*/
0178     err = mc_send_command(mc_io, &cmd);
0179     if (err)
0180         return err;
0181 
0182     /* retrieve response parameters */
0183     dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;
0184     attr->id = le32_to_cpu(dpcon_rsp->id);
0185     attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);
0186     attr->num_priorities = dpcon_rsp->num_priorities;
0187 
0188     return 0;
0189 }
0190 EXPORT_SYMBOL_GPL(dpcon_get_attributes);
0191 
0192 /**
0193  * dpcon_set_notification() - Set DPCON notification destination
0194  * @mc_io:  Pointer to MC portal's I/O object
0195  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0196  * @token:  Token of DPCON object
0197  * @cfg:    Notification parameters
0198  *
0199  * Return:  '0' on Success; Error code otherwise
0200  */
0201 int dpcon_set_notification(struct fsl_mc_io *mc_io,
0202                u32 cmd_flags,
0203                u16 token,
0204                struct dpcon_notification_cfg *cfg)
0205 {
0206     struct fsl_mc_command cmd = { 0 };
0207     struct dpcon_cmd_set_notification *dpcon_cmd;
0208 
0209     /* prepare command */
0210     cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION,
0211                       cmd_flags,
0212                       token);
0213     dpcon_cmd = (struct dpcon_cmd_set_notification *)cmd.params;
0214     dpcon_cmd->dpio_id = cpu_to_le32(cfg->dpio_id);
0215     dpcon_cmd->priority = cfg->priority;
0216     dpcon_cmd->user_ctx = cpu_to_le64(cfg->user_ctx);
0217 
0218     /* send command to mc*/
0219     return mc_send_command(mc_io, &cmd);
0220 }
0221 EXPORT_SYMBOL_GPL(dpcon_set_notification);