^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) * dpbp_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) * @dpbp_id: DPBP 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 dpbp_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 dpbp_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 dpbp_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 dpbp_cmd_open *cmd_params;
^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(DPBP_CMDID_OPEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) cmd_flags, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) cmd_params = (struct dpbp_cmd_open *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) cmd_params->dpbp_id = cpu_to_le32(dpbp_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) err = mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* retrieve response parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *token = mc_cmd_hdr_read_token(&cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) EXPORT_SYMBOL_GPL(dpbp_open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * dpbp_close() - Close the control session of the object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * @mc_io: Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * @token: Token of DPBP object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * After this function is called, no further operations are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * allowed on the object without opening a new control session.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * Return: '0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int dpbp_close(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) u16 token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) EXPORT_SYMBOL_GPL(dpbp_close);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * dpbp_enable() - Enable the DPBP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * @mc_io: Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * @token: Token of DPBP object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * Return: '0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) int dpbp_enable(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) u16 token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) EXPORT_SYMBOL_GPL(dpbp_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * dpbp_disable() - Disable the DPBP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * @mc_io: Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * @token: Token of DPBP object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * Return: '0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int dpbp_disable(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) u16 token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) cmd_flags, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) EXPORT_SYMBOL_GPL(dpbp_disable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * dpbp_reset() - Reset the DPBP, returns the object to initial state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * @mc_io: Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * @token: Token of DPBP object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * Return: '0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int dpbp_reset(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) u16 token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) cmd_flags, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) EXPORT_SYMBOL_GPL(dpbp_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * dpbp_get_attributes - Retrieve DPBP attributes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * @mc_io: Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * @token: Token of DPBP object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * @attr: Returned object's attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * Return: '0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int dpbp_get_attributes(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) u16 token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct dpbp_attr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct dpbp_rsp_get_attributes *rsp_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) cmd_flags, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) err = mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /* retrieve response parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) attr->bpid = le16_to_cpu(rsp_params->bpid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) attr->id = le32_to_cpu(rsp_params->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) EXPORT_SYMBOL_GPL(dpbp_get_attributes);