// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)1/*2* Copyright 2013-2016 Freescale Semiconductor Inc.3*4*/5#include <linux/kernel.h>6#include <linux/fsl/mc.h>78#include "fsl-mc-private.h"910/**11* dpbp_open() - Open a control session for the specified object.12* @mc_io: Pointer to MC portal's I/O object13* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'14* @dpbp_id: DPBP unique ID15* @token: Returned token; use in subsequent API calls16*17* This function can be used to open a control session for an18* already created object; an object may have been declared in19* the DPL or by calling the dpbp_create function.20* This function returns a unique authentication token,21* associated with the specific object ID and the specific MC22* portal; this token must be used in all subsequent commands for23* this specific object24*25* Return: '0' on Success; Error code otherwise.26*/27int dpbp_open(struct fsl_mc_io *mc_io,28u32 cmd_flags,29int dpbp_id,30u16 *token)31{32struct fsl_mc_command cmd = { 0 };33struct dpbp_cmd_open *cmd_params;34int err;3536/* prepare command */37cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,38cmd_flags, 0);39cmd_params = (struct dpbp_cmd_open *)cmd.params;40cmd_params->dpbp_id = cpu_to_le32(dpbp_id);4142/* send command to mc*/43err = mc_send_command(mc_io, &cmd);44if (err)45return err;4647/* retrieve response parameters */48*token = mc_cmd_hdr_read_token(&cmd);4950return err;51}52EXPORT_SYMBOL_GPL(dpbp_open);5354/**55* dpbp_close() - Close the control session of the object56* @mc_io: Pointer to MC portal's I/O object57* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'58* @token: Token of DPBP object59*60* After this function is called, no further operations are61* allowed on the object without opening a new control session.62*63* Return: '0' on Success; Error code otherwise.64*/65int dpbp_close(struct fsl_mc_io *mc_io,66u32 cmd_flags,67u16 token)68{69struct fsl_mc_command cmd = { 0 };7071/* prepare command */72cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,73token);7475/* send command to mc*/76return mc_send_command(mc_io, &cmd);77}78EXPORT_SYMBOL_GPL(dpbp_close);7980/**81* dpbp_enable() - Enable the DPBP.82* @mc_io: Pointer to MC portal's I/O object83* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'84* @token: Token of DPBP object85*86* Return: '0' on Success; Error code otherwise.87*/88int dpbp_enable(struct fsl_mc_io *mc_io,89u32 cmd_flags,90u16 token)91{92struct fsl_mc_command cmd = { 0 };9394/* prepare command */95cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,96token);9798/* send command to mc*/99return mc_send_command(mc_io, &cmd);100}101EXPORT_SYMBOL_GPL(dpbp_enable);102103/**104* dpbp_disable() - Disable the DPBP.105* @mc_io: Pointer to MC portal's I/O object106* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'107* @token: Token of DPBP object108*109* Return: '0' on Success; Error code otherwise.110*/111int dpbp_disable(struct fsl_mc_io *mc_io,112u32 cmd_flags,113u16 token)114{115struct fsl_mc_command cmd = { 0 };116117/* prepare command */118cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,119cmd_flags, token);120121/* send command to mc*/122return mc_send_command(mc_io, &cmd);123}124EXPORT_SYMBOL_GPL(dpbp_disable);125126/**127* dpbp_reset() - Reset the DPBP, returns the object to initial state.128* @mc_io: Pointer to MC portal's I/O object129* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'130* @token: Token of DPBP object131*132* Return: '0' on Success; Error code otherwise.133*/134int dpbp_reset(struct fsl_mc_io *mc_io,135u32 cmd_flags,136u16 token)137{138struct fsl_mc_command cmd = { 0 };139140/* prepare command */141cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,142cmd_flags, token);143144/* send command to mc*/145return mc_send_command(mc_io, &cmd);146}147EXPORT_SYMBOL_GPL(dpbp_reset);148149/**150* dpbp_get_attributes - Retrieve DPBP attributes.151*152* @mc_io: Pointer to MC portal's I/O object153* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'154* @token: Token of DPBP object155* @attr: Returned object's attributes156*157* Return: '0' on Success; Error code otherwise.158*/159int dpbp_get_attributes(struct fsl_mc_io *mc_io,160u32 cmd_flags,161u16 token,162struct dpbp_attr *attr)163{164struct fsl_mc_command cmd = { 0 };165struct dpbp_rsp_get_attributes *rsp_params;166int err;167168/* prepare command */169cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,170cmd_flags, token);171172/* send command to mc*/173err = mc_send_command(mc_io, &cmd);174if (err)175return err;176177/* retrieve response parameters */178rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;179attr->bpid = le16_to_cpu(rsp_params->bpid);180attr->id = le32_to_cpu(rsp_params->id);181182return 0;183}184EXPORT_SYMBOL_GPL(dpbp_get_attributes);185186187