222 lines · c
1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)2/*3 * Copyright 2013-2016 Freescale Semiconductor Inc.4 *5 */6#include <linux/kernel.h>7#include <linux/fsl/mc.h>8 9#include "fsl-mc-private.h"10 11/**12 * dpcon_open() - Open a control session for the specified object13 * @mc_io: Pointer to MC portal's I/O object14 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'15 * @dpcon_id: DPCON unique ID16 * @token: Returned token; use in subsequent API calls17 *18 * This function can be used to open a control session for an19 * already created object; an object may have been declared in20 * the DPL or by calling the dpcon_create() function.21 * This function returns a unique authentication token,22 * associated with the specific object ID and the specific MC23 * portal; this token must be used in all subsequent commands for24 * this specific object.25 *26 * Return: '0' on Success; Error code otherwise.27 */28int dpcon_open(struct fsl_mc_io *mc_io,29 u32 cmd_flags,30 int dpcon_id,31 u16 *token)32{33 struct fsl_mc_command cmd = { 0 };34 struct dpcon_cmd_open *dpcon_cmd;35 int err;36 37 /* prepare command */38 cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,39 cmd_flags,40 0);41 dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;42 dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);43 44 /* send command to mc*/45 err = mc_send_command(mc_io, &cmd);46 if (err)47 return err;48 49 /* retrieve response parameters */50 *token = mc_cmd_hdr_read_token(&cmd);51 52 return 0;53}54EXPORT_SYMBOL_GPL(dpcon_open);55 56/**57 * dpcon_close() - Close the control session of the object58 * @mc_io: Pointer to MC portal's I/O object59 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'60 * @token: Token of DPCON object61 *62 * After this function is called, no further operations are63 * allowed on the object without opening a new control session.64 *65 * Return: '0' on Success; Error code otherwise.66 */67int dpcon_close(struct fsl_mc_io *mc_io,68 u32 cmd_flags,69 u16 token)70{71 struct fsl_mc_command cmd = { 0 };72 73 /* prepare command */74 cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,75 cmd_flags,76 token);77 78 /* send command to mc*/79 return mc_send_command(mc_io, &cmd);80}81EXPORT_SYMBOL_GPL(dpcon_close);82 83/**84 * dpcon_enable() - Enable the DPCON85 * @mc_io: Pointer to MC portal's I/O object86 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'87 * @token: Token of DPCON object88 *89 * Return: '0' on Success; Error code otherwise90 */91int dpcon_enable(struct fsl_mc_io *mc_io,92 u32 cmd_flags,93 u16 token)94{95 struct fsl_mc_command cmd = { 0 };96 97 /* prepare command */98 cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,99 cmd_flags,100 token);101 102 /* send command to mc*/103 return mc_send_command(mc_io, &cmd);104}105EXPORT_SYMBOL_GPL(dpcon_enable);106 107/**108 * dpcon_disable() - Disable the DPCON109 * @mc_io: Pointer to MC portal's I/O object110 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'111 * @token: Token of DPCON object112 *113 * Return: '0' on Success; Error code otherwise114 */115int dpcon_disable(struct fsl_mc_io *mc_io,116 u32 cmd_flags,117 u16 token)118{119 struct fsl_mc_command cmd = { 0 };120 121 /* prepare command */122 cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,123 cmd_flags,124 token);125 126 /* send command to mc*/127 return mc_send_command(mc_io, &cmd);128}129EXPORT_SYMBOL_GPL(dpcon_disable);130 131/**132 * dpcon_reset() - Reset the DPCON, returns the object to initial state.133 * @mc_io: Pointer to MC portal's I/O object134 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'135 * @token: Token of DPCON object136 *137 * Return: '0' on Success; Error code otherwise.138 */139int dpcon_reset(struct fsl_mc_io *mc_io,140 u32 cmd_flags,141 u16 token)142{143 struct fsl_mc_command cmd = { 0 };144 145 /* prepare command */146 cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,147 cmd_flags, token);148 149 /* send command to mc*/150 return mc_send_command(mc_io, &cmd);151}152EXPORT_SYMBOL_GPL(dpcon_reset);153 154/**155 * dpcon_get_attributes() - Retrieve DPCON attributes.156 * @mc_io: Pointer to MC portal's I/O object157 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'158 * @token: Token of DPCON object159 * @attr: Object's attributes160 *161 * Return: '0' on Success; Error code otherwise.162 */163int dpcon_get_attributes(struct fsl_mc_io *mc_io,164 u32 cmd_flags,165 u16 token,166 struct dpcon_attr *attr)167{168 struct fsl_mc_command cmd = { 0 };169 struct dpcon_rsp_get_attr *dpcon_rsp;170 int err;171 172 /* prepare command */173 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,174 cmd_flags,175 token);176 177 /* send command to mc*/178 err = mc_send_command(mc_io, &cmd);179 if (err)180 return err;181 182 /* retrieve response parameters */183 dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;184 attr->id = le32_to_cpu(dpcon_rsp->id);185 attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);186 attr->num_priorities = dpcon_rsp->num_priorities;187 188 return 0;189}190EXPORT_SYMBOL_GPL(dpcon_get_attributes);191 192/**193 * dpcon_set_notification() - Set DPCON notification destination194 * @mc_io: Pointer to MC portal's I/O object195 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'196 * @token: Token of DPCON object197 * @cfg: Notification parameters198 *199 * Return: '0' on Success; Error code otherwise200 */201int dpcon_set_notification(struct fsl_mc_io *mc_io,202 u32 cmd_flags,203 u16 token,204 struct dpcon_notification_cfg *cfg)205{206 struct fsl_mc_command cmd = { 0 };207 struct dpcon_cmd_set_notification *dpcon_cmd;208 209 /* prepare command */210 cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION,211 cmd_flags,212 token);213 dpcon_cmd = (struct dpcon_cmd_set_notification *)cmd.params;214 dpcon_cmd->dpio_id = cpu_to_le32(cfg->dpio_id);215 dpcon_cmd->priority = cfg->priority;216 dpcon_cmd->user_ctx = cpu_to_le64(cfg->user_ctx);217 218 /* send command to mc*/219 return mc_send_command(mc_io, &cmd);220}221EXPORT_SYMBOL_GPL(dpcon_set_notification);222