Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
0002 /* Copyright 2013-2016 Freescale Semiconductor Inc.
0003  * Copyright 2019 NXP
0004  */
0005 #include <linux/fsl/mc.h>
0006 #include "dpmac.h"
0007 #include "dpmac-cmd.h"
0008 
0009 /**
0010  * dpmac_open() - Open a control session for the specified object.
0011  * @mc_io:  Pointer to MC portal's I/O object
0012  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0013  * @dpmac_id:   DPMAC unique ID
0014  * @token:  Returned token; use in subsequent API calls
0015  *
0016  * This function can be used to open a control session for an
0017  * already created object; an object may have been declared in
0018  * the DPL or by calling the dpmac_create function.
0019  * This function returns a unique authentication token,
0020  * associated with the specific object ID and the specific MC
0021  * portal; this token must be used in all subsequent commands for
0022  * this specific object
0023  *
0024  * Return:  '0' on Success; Error code otherwise.
0025  */
0026 int dpmac_open(struct fsl_mc_io *mc_io,
0027            u32 cmd_flags,
0028            int dpmac_id,
0029            u16 *token)
0030 {
0031     struct dpmac_cmd_open *cmd_params;
0032     struct fsl_mc_command cmd = { 0 };
0033     int err;
0034 
0035     /* prepare command */
0036     cmd.header = mc_encode_cmd_header(DPMAC_CMDID_OPEN,
0037                       cmd_flags,
0038                       0);
0039     cmd_params = (struct dpmac_cmd_open *)cmd.params;
0040     cmd_params->dpmac_id = cpu_to_le32(dpmac_id);
0041 
0042     /* send command to mc*/
0043     err = mc_send_command(mc_io, &cmd);
0044     if (err)
0045         return err;
0046 
0047     /* retrieve response parameters */
0048     *token = mc_cmd_hdr_read_token(&cmd);
0049 
0050     return err;
0051 }
0052 
0053 /**
0054  * dpmac_close() - Close the control session of the object
0055  * @mc_io:  Pointer to MC portal's I/O object
0056  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0057  * @token:  Token of DPMAC object
0058  *
0059  * After this function is called, no further operations are
0060  * allowed on the object without opening a new control session.
0061  *
0062  * Return:  '0' on Success; Error code otherwise.
0063  */
0064 int dpmac_close(struct fsl_mc_io *mc_io,
0065         u32 cmd_flags,
0066         u16 token)
0067 {
0068     struct fsl_mc_command cmd = { 0 };
0069 
0070     /* prepare command */
0071     cmd.header = mc_encode_cmd_header(DPMAC_CMDID_CLOSE, cmd_flags,
0072                       token);
0073 
0074     /* send command to mc*/
0075     return mc_send_command(mc_io, &cmd);
0076 }
0077 
0078 /**
0079  * dpmac_get_attributes - Retrieve DPMAC attributes.
0080  *
0081  * @mc_io:  Pointer to MC portal's I/O object
0082  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0083  * @token:  Token of DPMAC object
0084  * @attr:   Returned object's attributes
0085  *
0086  * Return:  '0' on Success; Error code otherwise.
0087  */
0088 int dpmac_get_attributes(struct fsl_mc_io *mc_io,
0089              u32 cmd_flags,
0090              u16 token,
0091              struct dpmac_attr *attr)
0092 {
0093     struct dpmac_rsp_get_attributes *rsp_params;
0094     struct fsl_mc_command cmd = { 0 };
0095     int err;
0096 
0097     /* prepare command */
0098     cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_ATTR,
0099                       cmd_flags,
0100                       token);
0101 
0102     /* send command to mc*/
0103     err = mc_send_command(mc_io, &cmd);
0104     if (err)
0105         return err;
0106 
0107     /* retrieve response parameters */
0108     rsp_params = (struct dpmac_rsp_get_attributes *)cmd.params;
0109     attr->eth_if = rsp_params->eth_if;
0110     attr->link_type = rsp_params->link_type;
0111     attr->id = le16_to_cpu(rsp_params->id);
0112     attr->max_rate = le32_to_cpu(rsp_params->max_rate);
0113 
0114     return 0;
0115 }
0116 
0117 /**
0118  * dpmac_set_link_state() - Set the Ethernet link status
0119  * @mc_io:      Pointer to opaque I/O object
0120  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0121  * @token:      Token of DPMAC object
0122  * @link_state: Link state configuration
0123  *
0124  * Return:      '0' on Success; Error code otherwise.
0125  */
0126 int dpmac_set_link_state(struct fsl_mc_io *mc_io,
0127              u32 cmd_flags,
0128              u16 token,
0129              struct dpmac_link_state *link_state)
0130 {
0131     struct dpmac_cmd_set_link_state *cmd_params;
0132     struct fsl_mc_command cmd = { 0 };
0133 
0134     /* prepare command */
0135     cmd.header = mc_encode_cmd_header(DPMAC_CMDID_SET_LINK_STATE,
0136                       cmd_flags,
0137                       token);
0138     cmd_params = (struct dpmac_cmd_set_link_state *)cmd.params;
0139     cmd_params->options = cpu_to_le64(link_state->options);
0140     cmd_params->rate = cpu_to_le32(link_state->rate);
0141     dpmac_set_field(cmd_params->state, STATE, link_state->up);
0142     dpmac_set_field(cmd_params->state, STATE_VALID,
0143             link_state->state_valid);
0144     cmd_params->supported = cpu_to_le64(link_state->supported);
0145     cmd_params->advertising = cpu_to_le64(link_state->advertising);
0146 
0147     /* send command to mc*/
0148     return mc_send_command(mc_io, &cmd);
0149 }
0150 
0151 /**
0152  * dpmac_get_counter() - Read a specific DPMAC counter
0153  * @mc_io:  Pointer to opaque I/O object
0154  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0155  * @token:  Token of DPMAC object
0156  * @id:     The requested counter ID
0157  * @value:  Returned counter value
0158  *
0159  * Return:  The requested counter; '0' otherwise.
0160  */
0161 int dpmac_get_counter(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0162               enum dpmac_counter_id id, u64 *value)
0163 {
0164     struct dpmac_cmd_get_counter *dpmac_cmd;
0165     struct dpmac_rsp_get_counter *dpmac_rsp;
0166     struct fsl_mc_command cmd = { 0 };
0167     int err = 0;
0168 
0169     cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_COUNTER,
0170                       cmd_flags,
0171                       token);
0172     dpmac_cmd = (struct dpmac_cmd_get_counter *)cmd.params;
0173     dpmac_cmd->id = id;
0174 
0175     err = mc_send_command(mc_io, &cmd);
0176     if (err)
0177         return err;
0178 
0179     dpmac_rsp = (struct dpmac_rsp_get_counter *)cmd.params;
0180     *value = le64_to_cpu(dpmac_rsp->counter);
0181 
0182     return 0;
0183 }
0184 
0185 /**
0186  * dpmac_get_api_version() - Get Data Path MAC version
0187  * @mc_io:  Pointer to MC portal's I/O object
0188  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0189  * @major_ver:  Major version of data path mac API
0190  * @minor_ver:  Minor version of data path mac API
0191  *
0192  * Return:  '0' on Success; Error code otherwise.
0193  */
0194 int dpmac_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
0195               u16 *major_ver, u16 *minor_ver)
0196 {
0197     struct dpmac_rsp_get_api_version *rsp_params;
0198     struct fsl_mc_command cmd = { 0 };
0199     int err;
0200 
0201     cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_API_VERSION,
0202                       cmd_flags,
0203                       0);
0204 
0205     err = mc_send_command(mc_io, &cmd);
0206     if (err)
0207         return err;
0208 
0209     rsp_params = (struct dpmac_rsp_get_api_version *)cmd.params;
0210     *major_ver = le16_to_cpu(rsp_params->major);
0211     *minor_ver = le16_to_cpu(rsp_params->minor);
0212 
0213     return 0;
0214 }
0215 
0216 /**
0217  * dpmac_set_protocol() - Reconfigure the DPMAC protocol
0218  * @mc_io:      Pointer to opaque I/O object
0219  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0220  * @token:      Token of DPMAC object
0221  * @protocol:   New protocol for the DPMAC to be reconfigured in.
0222  *
0223  * Return:      '0' on Success; Error code otherwise.
0224  */
0225 int dpmac_set_protocol(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0226                enum dpmac_eth_if protocol)
0227 {
0228     struct dpmac_cmd_set_protocol *cmd_params;
0229     struct fsl_mc_command cmd = { 0 };
0230 
0231     cmd.header = mc_encode_cmd_header(DPMAC_CMDID_SET_PROTOCOL,
0232                       cmd_flags, token);
0233     cmd_params = (struct dpmac_cmd_set_protocol *)cmd.params;
0234     cmd_params->eth_if = protocol;
0235 
0236     return mc_send_command(mc_io, &cmd);
0237 }