// 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* dpcon_open() - Open a control session for the specified object12* @mc_io: Pointer to MC portal's I/O object13* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'14* @dpcon_id: DPCON 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 dpcon_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 object.24*25* Return: '0' on Success; Error code otherwise.26*/27int dpcon_open(struct fsl_mc_io *mc_io,28u32 cmd_flags,29int dpcon_id,30u16 *token)31{32struct fsl_mc_command cmd = { 0 };33struct dpcon_cmd_open *dpcon_cmd;34int err;3536/* prepare command */37cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,38cmd_flags,390);40dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;41dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);4243/* send command to mc*/44err = mc_send_command(mc_io, &cmd);45if (err)46return err;4748/* retrieve response parameters */49*token = mc_cmd_hdr_read_token(&cmd);5051return 0;52}53EXPORT_SYMBOL_GPL(dpcon_open);5455/**56* dpcon_close() - Close the control session of the object57* @mc_io: Pointer to MC portal's I/O object58* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'59* @token: Token of DPCON object60*61* After this function is called, no further operations are62* allowed on the object without opening a new control session.63*64* Return: '0' on Success; Error code otherwise.65*/66int dpcon_close(struct fsl_mc_io *mc_io,67u32 cmd_flags,68u16 token)69{70struct fsl_mc_command cmd = { 0 };7172/* prepare command */73cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,74cmd_flags,75token);7677/* send command to mc*/78return mc_send_command(mc_io, &cmd);79}80EXPORT_SYMBOL_GPL(dpcon_close);8182/**83* dpcon_enable() - Enable the DPCON84* @mc_io: Pointer to MC portal's I/O object85* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'86* @token: Token of DPCON object87*88* Return: '0' on Success; Error code otherwise89*/90int dpcon_enable(struct fsl_mc_io *mc_io,91u32 cmd_flags,92u16 token)93{94struct fsl_mc_command cmd = { 0 };9596/* prepare command */97cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,98cmd_flags,99token);100101/* send command to mc*/102return mc_send_command(mc_io, &cmd);103}104EXPORT_SYMBOL_GPL(dpcon_enable);105106/**107* dpcon_disable() - Disable the DPCON108* @mc_io: Pointer to MC portal's I/O object109* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'110* @token: Token of DPCON object111*112* Return: '0' on Success; Error code otherwise113*/114int dpcon_disable(struct fsl_mc_io *mc_io,115u32 cmd_flags,116u16 token)117{118struct fsl_mc_command cmd = { 0 };119120/* prepare command */121cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,122cmd_flags,123token);124125/* send command to mc*/126return mc_send_command(mc_io, &cmd);127}128EXPORT_SYMBOL_GPL(dpcon_disable);129130/**131* dpcon_reset() - Reset the DPCON, returns the object to initial state.132* @mc_io: Pointer to MC portal's I/O object133* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'134* @token: Token of DPCON object135*136* Return: '0' on Success; Error code otherwise.137*/138int dpcon_reset(struct fsl_mc_io *mc_io,139u32 cmd_flags,140u16 token)141{142struct fsl_mc_command cmd = { 0 };143144/* prepare command */145cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,146cmd_flags, token);147148/* send command to mc*/149return mc_send_command(mc_io, &cmd);150}151EXPORT_SYMBOL_GPL(dpcon_reset);152153/**154* dpcon_get_attributes() - Retrieve DPCON attributes.155* @mc_io: Pointer to MC portal's I/O object156* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'157* @token: Token of DPCON object158* @attr: Object's attributes159*160* Return: '0' on Success; Error code otherwise.161*/162int dpcon_get_attributes(struct fsl_mc_io *mc_io,163u32 cmd_flags,164u16 token,165struct dpcon_attr *attr)166{167struct fsl_mc_command cmd = { 0 };168struct dpcon_rsp_get_attr *dpcon_rsp;169int err;170171/* prepare command */172cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,173cmd_flags,174token);175176/* send command to mc*/177err = mc_send_command(mc_io, &cmd);178if (err)179return err;180181/* retrieve response parameters */182dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;183attr->id = le32_to_cpu(dpcon_rsp->id);184attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);185attr->num_priorities = dpcon_rsp->num_priorities;186187return 0;188}189EXPORT_SYMBOL_GPL(dpcon_get_attributes);190191/**192* dpcon_set_notification() - Set DPCON notification destination193* @mc_io: Pointer to MC portal's I/O object194* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'195* @token: Token of DPCON object196* @cfg: Notification parameters197*198* Return: '0' on Success; Error code otherwise199*/200int dpcon_set_notification(struct fsl_mc_io *mc_io,201u32 cmd_flags,202u16 token,203struct dpcon_notification_cfg *cfg)204{205struct fsl_mc_command cmd = { 0 };206struct dpcon_cmd_set_notification *dpcon_cmd;207208/* prepare command */209cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION,210cmd_flags,211token);212dpcon_cmd = (struct dpcon_cmd_set_notification *)cmd.params;213dpcon_cmd->dpio_id = cpu_to_le32(cfg->dpio_id);214dpcon_cmd->priority = cfg->priority;215dpcon_cmd->user_ctx = cpu_to_le64(cfg->user_ctx);216217/* send command to mc*/218return mc_send_command(mc_io, &cmd);219}220EXPORT_SYMBOL_GPL(dpcon_set_notification);221222223