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