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  * Copyright 2016 NXP
0005  *
0006  */
0007 #include <linux/kernel.h>
0008 #include <linux/fsl/mc.h>
0009 
0010 #include "dpio.h"
0011 #include "dpio-cmd.h"
0012 
0013 /*
0014  * Data Path I/O Portal API
0015  * Contains initialization APIs and runtime control APIs for DPIO
0016  */
0017 
0018 /**
0019  * dpio_open() - Open a control session for the specified object
0020  * @mc_io:  Pointer to MC portal's I/O object
0021  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0022  * @dpio_id:    DPIO unique ID
0023  * @token:  Returned token; use in subsequent API calls
0024  *
0025  * This function can be used to open a control session for an
0026  * already created object; an object may have been declared in
0027  * the DPL or by calling the dpio_create() function.
0028  * This function returns a unique authentication token,
0029  * associated with the specific object ID and the specific MC
0030  * portal; this token must be used in all subsequent commands for
0031  * this specific object.
0032  *
0033  * Return:  '0' on Success; Error code otherwise.
0034  */
0035 int dpio_open(struct fsl_mc_io *mc_io,
0036           u32 cmd_flags,
0037           int dpio_id,
0038           u16 *token)
0039 {
0040     struct fsl_mc_command cmd = { 0 };
0041     struct dpio_cmd_open *dpio_cmd;
0042     int err;
0043 
0044     /* prepare command */
0045     cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN,
0046                       cmd_flags,
0047                       0);
0048     dpio_cmd = (struct dpio_cmd_open *)cmd.params;
0049     dpio_cmd->dpio_id = cpu_to_le32(dpio_id);
0050 
0051     err = mc_send_command(mc_io, &cmd);
0052     if (err)
0053         return err;
0054 
0055     /* retrieve response parameters */
0056     *token = mc_cmd_hdr_read_token(&cmd);
0057 
0058     return 0;
0059 }
0060 
0061 /**
0062  * dpio_close() - Close the control session of the object
0063  * @mc_io:  Pointer to MC portal's I/O object
0064  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0065  * @token:  Token of DPIO object
0066  *
0067  * Return:  '0' on Success; Error code otherwise.
0068  */
0069 int dpio_close(struct fsl_mc_io *mc_io,
0070            u32 cmd_flags,
0071            u16 token)
0072 {
0073     struct fsl_mc_command cmd = { 0 };
0074 
0075     /* prepare command */
0076     cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE,
0077                       cmd_flags,
0078                       token);
0079 
0080     return mc_send_command(mc_io, &cmd);
0081 }
0082 
0083 /**
0084  * dpio_enable() - Enable the DPIO, allow I/O portal operations.
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 DPIO object
0088  *
0089  * Return:  '0' on Success; Error code otherwise
0090  */
0091 int dpio_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(DPIO_CMDID_ENABLE,
0099                       cmd_flags,
0100                       token);
0101 
0102     return mc_send_command(mc_io, &cmd);
0103 }
0104 
0105 /**
0106  * dpio_disable() - Disable the DPIO, stop any I/O portal operation.
0107  * @mc_io:  Pointer to MC portal's I/O object
0108  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0109  * @token:  Token of DPIO object
0110  *
0111  * Return:  '0' on Success; Error code otherwise
0112  */
0113 int dpio_disable(struct fsl_mc_io *mc_io,
0114          u32 cmd_flags,
0115          u16 token)
0116 {
0117     struct fsl_mc_command cmd = { 0 };
0118 
0119     /* prepare command */
0120     cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
0121                       cmd_flags,
0122                       token);
0123 
0124     return mc_send_command(mc_io, &cmd);
0125 }
0126 
0127 /**
0128  * dpio_get_attributes() - Retrieve DPIO attributes
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 DPIO object
0132  * @attr:   Returned object's attributes
0133  *
0134  * Return:  '0' on Success; Error code otherwise
0135  */
0136 int dpio_get_attributes(struct fsl_mc_io *mc_io,
0137             u32 cmd_flags,
0138             u16 token,
0139             struct dpio_attr *attr)
0140 {
0141     struct fsl_mc_command cmd = { 0 };
0142     struct dpio_rsp_get_attr *dpio_rsp;
0143     int err;
0144 
0145     /* prepare command */
0146     cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
0147                       cmd_flags,
0148                       token);
0149 
0150     err = mc_send_command(mc_io, &cmd);
0151     if (err)
0152         return err;
0153 
0154     /* retrieve response parameters */
0155     dpio_rsp = (struct dpio_rsp_get_attr *)cmd.params;
0156     attr->id = le32_to_cpu(dpio_rsp->id);
0157     attr->qbman_portal_id = le16_to_cpu(dpio_rsp->qbman_portal_id);
0158     attr->num_priorities = dpio_rsp->num_priorities;
0159     attr->channel_mode = dpio_rsp->channel_mode & DPIO_CHANNEL_MODE_MASK;
0160     attr->qbman_portal_ce_offset =
0161         le64_to_cpu(dpio_rsp->qbman_portal_ce_addr);
0162     attr->qbman_portal_ci_offset =
0163         le64_to_cpu(dpio_rsp->qbman_portal_ci_addr);
0164     attr->qbman_version = le32_to_cpu(dpio_rsp->qbman_version);
0165     attr->clk = le32_to_cpu(dpio_rsp->clk);
0166 
0167     return 0;
0168 }
0169 
0170 int dpio_set_stashing_destination(struct fsl_mc_io *mc_io,
0171                   u32 cmd_flags,
0172                   u16 token,
0173                   u8 sdest)
0174 {
0175     struct fsl_mc_command cmd = { 0 };
0176     struct dpio_stashing_dest *dpio_cmd;
0177 
0178     cmd.header = mc_encode_cmd_header(DPIO_CMDID_SET_STASHING_DEST,
0179                       cmd_flags, token);
0180     dpio_cmd = (struct dpio_stashing_dest *)cmd.params;
0181     dpio_cmd->sdest = sdest;
0182 
0183     return mc_send_command(mc_io, &cmd);
0184 }
0185 
0186 /**
0187  * dpio_get_api_version - Get Data Path I/O API version
0188  * @mc_io:  Pointer to MC portal's DPIO object
0189  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0190  * @major_ver:  Major version of DPIO API
0191  * @minor_ver:  Minor version of DPIO API
0192  *
0193  * Return:  '0' on Success; Error code otherwise
0194  */
0195 int dpio_get_api_version(struct fsl_mc_io *mc_io,
0196              u32 cmd_flags,
0197              u16 *major_ver,
0198              u16 *minor_ver)
0199 {
0200     struct fsl_mc_command cmd = { 0 };
0201     int err;
0202 
0203     /* prepare command */
0204     cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION,
0205                       cmd_flags, 0);
0206 
0207     err = mc_send_command(mc_io, &cmd);
0208     if (err)
0209         return err;
0210 
0211     /* retrieve response parameters */
0212     mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
0213 
0214     return 0;
0215 }
0216 
0217 /**
0218  * dpio_reset() - Reset the DPIO, returns the object to initial state.
0219  * @mc_io:  Pointer to MC portal's I/O object
0220  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0221  * @token:  Token of DPIO object
0222  *
0223  * Return:  '0' on Success; Error code otherwise.
0224  */
0225 int dpio_reset(struct fsl_mc_io *mc_io,
0226            u32 cmd_flags,
0227            u16 token)
0228 {
0229     struct fsl_mc_command cmd = { 0 };
0230 
0231     /* prepare command */
0232     cmd.header = mc_encode_cmd_header(DPIO_CMDID_RESET,
0233                       cmd_flags,
0234                       token);
0235 
0236     /* send command to mc*/
0237     return mc_send_command(mc_io, &cmd);
0238 }