Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Freescale Layerscape MC I/O wrapper |
| 4 | * |
Yogesh Gaur | 1a0c4ae | 2018-05-09 10:52:17 +0530 | [diff] [blame] | 5 | * Copyright 2013-2016 Freescale Semiconductor, Inc. |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 6 | * Copyright 2017-2023 NXP |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 7 | */ |
| 8 | #include <fsl-mc/fsl_mc_sys.h> |
| 9 | #include <fsl-mc/fsl_mc_cmd.h> |
| 10 | #include <fsl-mc/fsl_dpbp.h> |
| 11 | |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 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, u32 cmd_flags, int dpbp_id, u16 *token) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 30 | { |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 31 | struct dpbp_cmd_open *cmd_params; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 32 | struct mc_command cmd = { 0 }; |
| 33 | int err; |
| 34 | |
| 35 | /* prepare command */ |
| 36 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN, |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 37 | cmd_flags, 0); |
| 38 | cmd_params = (struct dpbp_cmd_open *)cmd.params; |
| 39 | cmd_params->dpbp_id = cpu_to_le32(dpbp_id); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 40 | |
| 41 | /* send command to mc*/ |
| 42 | err = mc_send_command(mc_io, &cmd); |
| 43 | if (err) |
| 44 | return err; |
| 45 | |
| 46 | /* retrieve response parameters */ |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 47 | *token = mc_cmd_hdr_read_token(&cmd); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 48 | |
| 49 | return err; |
| 50 | } |
| 51 | |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 52 | /** |
| 53 | * dpbp_close() - Close the control session of the object |
| 54 | * @mc_io: Pointer to MC portal's I/O object |
| 55 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 56 | * @token: Token of DPBP object |
| 57 | * |
| 58 | * After this function is called, no further operations are |
| 59 | * allowed on the object without opening a new control session. |
| 60 | * |
| 61 | * Return: '0' on Success; Error code otherwise. |
| 62 | */ |
| 63 | int dpbp_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 64 | { |
| 65 | struct mc_command cmd = { 0 }; |
| 66 | |
| 67 | /* prepare command */ |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 68 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags, |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 69 | token); |
| 70 | |
| 71 | /* send command to mc*/ |
| 72 | return mc_send_command(mc_io, &cmd); |
| 73 | } |
| 74 | |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 75 | /** |
| 76 | * dpbp_create() - Create the DPBP object. |
| 77 | * @mc_io: Pointer to MC portal's I/O object |
| 78 | * @dprc_token: Parent container token; '0' for default container |
| 79 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 80 | * @cfg: Configuration structure |
| 81 | * @obj_id: Returned object id; use in subsequent API calls |
| 82 | * |
| 83 | * Create the DPBP object, allocate required resources and |
| 84 | * perform required initialization. |
| 85 | * |
| 86 | * This function accepts an authentication token of a parent |
| 87 | * container that this object should be assigned to and returns |
| 88 | * an object id. This object_id will be used in all subsequent calls to |
| 89 | * this specific object. |
| 90 | * |
| 91 | * Return: '0' on Success; Error code otherwise. |
| 92 | */ |
| 93 | int dpbp_create(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags, |
| 94 | const struct dpbp_cfg *cfg, u32 *obj_id) |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 95 | { |
| 96 | struct mc_command cmd = { 0 }; |
| 97 | int err; |
| 98 | |
| 99 | (void)(cfg); /* unused */ |
| 100 | |
| 101 | /* prepare command */ |
| 102 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE, |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 103 | cmd_flags, dprc_token); |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 104 | |
| 105 | /* send command to mc*/ |
| 106 | err = mc_send_command(mc_io, &cmd); |
| 107 | if (err) |
| 108 | return err; |
| 109 | |
| 110 | /* retrieve response parameters */ |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 111 | *obj_id = mc_cmd_read_object_id(&cmd); |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 116 | /** |
| 117 | * dpbp_destroy() - Destroy the DPBP object and release all its resources. |
| 118 | * @mc_io: Pointer to MC portal's I/O object |
| 119 | * @dprc_token: Parent container token; '0' for default container |
| 120 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 121 | * @obj_id: ID of DPBP object |
| 122 | * |
| 123 | * Return: '0' on Success; error code otherwise. |
| 124 | */ |
| 125 | int dpbp_destroy(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags, |
| 126 | u32 obj_id) |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 127 | { |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 128 | struct dpbp_cmd_destroy *cmd_params; |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 129 | struct mc_command cmd = { 0 }; |
| 130 | |
| 131 | /* prepare command */ |
| 132 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY, |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 133 | cmd_flags, dprc_token); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 134 | |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 135 | cmd_params = (struct dpbp_cmd_destroy *)cmd.params; |
| 136 | cmd_params->object_id = cpu_to_le32(obj_id); |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 137 | |
| 138 | /* send command to mc*/ |
| 139 | return mc_send_command(mc_io, &cmd); |
| 140 | } |
| 141 | |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 142 | /** |
| 143 | * dpbp_enable() - Enable the DPBP. |
| 144 | * @mc_io: Pointer to MC portal's I/O object |
| 145 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 146 | * @token: Token of DPBP object |
| 147 | * |
| 148 | * Return: '0' on Success; Error code otherwise. |
| 149 | */ |
| 150 | int dpbp_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 151 | { |
| 152 | struct mc_command cmd = { 0 }; |
| 153 | |
| 154 | /* prepare command */ |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 155 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags, |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 156 | token); |
| 157 | |
| 158 | /* send command to mc*/ |
| 159 | return mc_send_command(mc_io, &cmd); |
| 160 | } |
| 161 | |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 162 | /** |
| 163 | * dpbp_disable() - Disable the DPBP. |
| 164 | * @mc_io: Pointer to MC portal's I/O object |
| 165 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 166 | * @token: Token of DPBP object |
| 167 | * |
| 168 | * Return: '0' on Success; Error code otherwise. |
| 169 | */ |
| 170 | int dpbp_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 171 | { |
| 172 | struct mc_command cmd = { 0 }; |
| 173 | |
| 174 | /* prepare command */ |
| 175 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE, |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 176 | cmd_flags, token); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 177 | |
| 178 | /* send command to mc*/ |
| 179 | return mc_send_command(mc_io, &cmd); |
| 180 | } |
| 181 | |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 182 | /** |
| 183 | * dpbp_reset() - Reset the DPBP, returns the object to initial state. |
| 184 | * @mc_io: Pointer to MC portal's I/O object |
| 185 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 186 | * @token: Token of DPBP object |
| 187 | * |
| 188 | * Return: '0' on Success; Error code otherwise. |
| 189 | */ |
| 190 | int dpbp_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 191 | { |
| 192 | struct mc_command cmd = { 0 }; |
| 193 | |
| 194 | /* prepare command */ |
| 195 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET, |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 196 | cmd_flags, token); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 197 | |
| 198 | /* send command to mc*/ |
| 199 | return mc_send_command(mc_io, &cmd); |
| 200 | } |
| 201 | |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 202 | /** |
| 203 | * dpbp_get_attributes - Retrieve DPBP attributes. |
| 204 | * |
| 205 | * @mc_io: Pointer to MC portal's I/O object |
| 206 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 207 | * @token: Token of DPBP object |
| 208 | * @attr: Returned object's attributes |
| 209 | * |
| 210 | * Return: '0' on Success; Error code otherwise. |
| 211 | */ |
| 212 | int dpbp_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 213 | struct dpbp_attr *attr) |
| 214 | { |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 215 | struct dpbp_rsp_get_attributes *rsp_params; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 216 | struct mc_command cmd = { 0 }; |
| 217 | int err; |
| 218 | |
| 219 | /* prepare command */ |
| 220 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR, |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 221 | cmd_flags, token); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 222 | |
| 223 | /* send command to mc*/ |
| 224 | err = mc_send_command(mc_io, &cmd); |
| 225 | if (err) |
| 226 | return err; |
| 227 | |
| 228 | /* retrieve response parameters */ |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 229 | rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params; |
| 230 | attr->bpid = le16_to_cpu(rsp_params->bpid); |
| 231 | attr->id = le32_to_cpu(rsp_params->id); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 232 | |
| 233 | return 0; |
| 234 | } |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 235 | |
Ioana Ciornei | 2f232fa | 2023-05-31 19:04:30 +0300 | [diff] [blame] | 236 | /** |
| 237 | * dpbp_get_api_version - Get Data Path Buffer Pool API version |
| 238 | * @mc_io: Pointer to Mc portal's I/O object |
| 239 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 240 | * @major_ver: Major version of Buffer Pool API |
| 241 | * @minor_ver: Minor version of Buffer Pool API |
| 242 | * |
| 243 | * Return: '0' on Success; Error code otherwise. |
| 244 | */ |
| 245 | int dpbp_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags, |
| 246 | u16 *major_ver, u16 *minor_ver) |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 247 | { |
| 248 | struct mc_command cmd = { 0 }; |
| 249 | int err; |
| 250 | |
| 251 | /* prepare command */ |
| 252 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_API_VERSION, |
| 253 | cmd_flags, 0); |
| 254 | |
| 255 | /* send command to mc */ |
| 256 | err = mc_send_command(mc_io, &cmd); |
| 257 | if (err) |
| 258 | return err; |
| 259 | |
| 260 | /* retrieve response parameters */ |
| 261 | mc_cmd_read_api_version(&cmd, major_ver, minor_ver); |
| 262 | |
| 263 | return 0; |
| 264 | } |