| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame^] | 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 | #include <linux/fsl/mc.h> |
| 9 | |
| 10 | #include "fsl-mc-private.h" |
| 11 | |
| 12 | /** |
| 13 | * dpbp_open() - Open a control session for the specified object. |
| 14 | * @mc_io: Pointer to MC portal's I/O object |
| 15 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 16 | * @dpbp_id: DPBP unique ID |
| 17 | * @token: Returned token; use in subsequent API calls |
| 18 | * |
| 19 | * This function can be used to open a control session for an |
| 20 | * already created object; an object may have been declared in |
| 21 | * the DPL or by calling the dpbp_create function. |
| 22 | * This function returns a unique authentication token, |
| 23 | * associated with the specific object ID and the specific MC |
| 24 | * portal; this token must be used in all subsequent commands for |
| 25 | * this specific object |
| 26 | * |
| 27 | * Return: '0' on Success; Error code otherwise. |
| 28 | */ |
| 29 | int dpbp_open(struct fsl_mc_io *mc_io, |
| 30 | u32 cmd_flags, |
| 31 | int dpbp_id, |
| 32 | u16 *token) |
| 33 | { |
| 34 | struct fsl_mc_command cmd = { 0 }; |
| 35 | struct dpbp_cmd_open *cmd_params; |
| 36 | int err; |
| 37 | |
| 38 | /* prepare command */ |
| 39 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN, |
| 40 | cmd_flags, 0); |
| 41 | cmd_params = (struct dpbp_cmd_open *)cmd.params; |
| 42 | cmd_params->dpbp_id = cpu_to_le32(dpbp_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 err; |
| 53 | } |
| 54 | EXPORT_SYMBOL_GPL(dpbp_open); |
| 55 | |
| 56 | /** |
| 57 | * dpbp_close() - Close the control session of the object |
| 58 | * @mc_io: Pointer to MC portal's I/O object |
| 59 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 60 | * @token: Token of DPBP object |
| 61 | * |
| 62 | * After this function is called, no further operations are |
| 63 | * allowed on the object without opening a new control session. |
| 64 | * |
| 65 | * Return: '0' on Success; Error code otherwise. |
| 66 | */ |
| 67 | int dpbp_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(DPBP_CMDID_CLOSE, cmd_flags, |
| 75 | token); |
| 76 | |
| 77 | /* send command to mc*/ |
| 78 | return mc_send_command(mc_io, &cmd); |
| 79 | } |
| 80 | EXPORT_SYMBOL_GPL(dpbp_close); |
| 81 | |
| 82 | /** |
| 83 | * dpbp_enable() - Enable the DPBP. |
| 84 | * @mc_io: Pointer to MC portal's I/O object |
| 85 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 86 | * @token: Token of DPBP object |
| 87 | * |
| 88 | * Return: '0' on Success; Error code otherwise. |
| 89 | */ |
| 90 | int dpbp_enable(struct fsl_mc_io *mc_io, |
| 91 | u32 cmd_flags, |
| 92 | u16 token) |
| 93 | { |
| 94 | struct fsl_mc_command cmd = { 0 }; |
| 95 | |
| 96 | /* prepare command */ |
| 97 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags, |
| 98 | token); |
| 99 | |
| 100 | /* send command to mc*/ |
| 101 | return mc_send_command(mc_io, &cmd); |
| 102 | } |
| 103 | EXPORT_SYMBOL_GPL(dpbp_enable); |
| 104 | |
| 105 | /** |
| 106 | * dpbp_disable() - Disable the DPBP. |
| 107 | * @mc_io: Pointer to MC portal's I/O object |
| 108 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 109 | * @token: Token of DPBP object |
| 110 | * |
| 111 | * Return: '0' on Success; Error code otherwise. |
| 112 | */ |
| 113 | int dpbp_disable(struct fsl_mc_io *mc_io, |
| 114 | u32 cmd_flags, |
| 115 | u16 token) |
| 116 | { |
| 117 | struct fsl_mc_command cmd = { 0 }; |
| 118 | |
| 119 | /* prepare command */ |
| 120 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE, |
| 121 | cmd_flags, token); |
| 122 | |
| 123 | /* send command to mc*/ |
| 124 | return mc_send_command(mc_io, &cmd); |
| 125 | } |
| 126 | EXPORT_SYMBOL_GPL(dpbp_disable); |
| 127 | |
| 128 | /** |
| 129 | * dpbp_reset() - Reset the DPBP, returns the object to initial state. |
| 130 | * @mc_io: Pointer to MC portal's I/O object |
| 131 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 132 | * @token: Token of DPBP object |
| 133 | * |
| 134 | * Return: '0' on Success; Error code otherwise. |
| 135 | */ |
| 136 | int dpbp_reset(struct fsl_mc_io *mc_io, |
| 137 | u32 cmd_flags, |
| 138 | u16 token) |
| 139 | { |
| 140 | struct fsl_mc_command cmd = { 0 }; |
| 141 | |
| 142 | /* prepare command */ |
| 143 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET, |
| 144 | cmd_flags, token); |
| 145 | |
| 146 | /* send command to mc*/ |
| 147 | return mc_send_command(mc_io, &cmd); |
| 148 | } |
| 149 | EXPORT_SYMBOL_GPL(dpbp_reset); |
| 150 | |
| 151 | /** |
| 152 | * dpbp_get_attributes - Retrieve DPBP attributes. |
| 153 | * |
| 154 | * @mc_io: Pointer to MC portal's I/O object |
| 155 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 156 | * @token: Token of DPBP object |
| 157 | * @attr: Returned object's attributes |
| 158 | * |
| 159 | * Return: '0' on Success; Error code otherwise. |
| 160 | */ |
| 161 | int dpbp_get_attributes(struct fsl_mc_io *mc_io, |
| 162 | u32 cmd_flags, |
| 163 | u16 token, |
| 164 | struct dpbp_attr *attr) |
| 165 | { |
| 166 | struct fsl_mc_command cmd = { 0 }; |
| 167 | struct dpbp_rsp_get_attributes *rsp_params; |
| 168 | int err; |
| 169 | |
| 170 | /* prepare command */ |
| 171 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR, |
| 172 | cmd_flags, token); |
| 173 | |
| 174 | /* send command to mc*/ |
| 175 | err = mc_send_command(mc_io, &cmd); |
| 176 | if (err) |
| 177 | return err; |
| 178 | |
| 179 | /* retrieve response parameters */ |
| 180 | rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params; |
| 181 | attr->bpid = le16_to_cpu(rsp_params->bpid); |
| 182 | attr->id = le32_to_cpu(rsp_params->id); |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | EXPORT_SYMBOL_GPL(dpbp_get_attributes); |