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 | /* |
Yogesh Gaur | 1a0c4ae | 2018-05-09 10:52:17 +0530 | [diff] [blame] | 3 | * Copyright 2013-2016 Freescale Semiconductor, Inc. |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 4 | * Copyright 2017, 2023 NXP |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <fsl-mc/fsl_mc_sys.h> |
| 8 | #include <fsl-mc/fsl_mc_cmd.h> |
| 9 | #include <fsl-mc/fsl_dpio.h> |
| 10 | |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 11 | /** |
| 12 | * dpio_open() - Open a control session for the specified object |
| 13 | * @mc_io: Pointer to MC portal's I/O object |
| 14 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 15 | * @dpio_id: DPIO unique ID |
| 16 | * @token: Returned token; use in subsequent API calls |
| 17 | * |
| 18 | * This function can be used to open a control session for an |
| 19 | * already created object; an object may have been declared in |
| 20 | * the DPL or by calling the dpio_create() function. |
| 21 | * This function returns a unique authentication token, |
| 22 | * associated with the specific object ID and any MC portals |
| 23 | * assigned to the parent container; this token must be used in |
| 24 | * all subsequent commands for this specific object. |
| 25 | * |
| 26 | * Return: '0' on Success; Error code otherwise. |
| 27 | */ |
| 28 | int dpio_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpio_id, |
| 29 | u16 *token) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 30 | { |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 31 | struct dpio_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(DPIO_CMDID_OPEN, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 37 | cmd_flags, |
| 38 | 0); |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 39 | cmd_params = (struct dpio_cmd_open *)cmd.params; |
| 40 | cmd_params->dpio_id = cpu_to_le32(dpio_id); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 41 | |
| 42 | /* send command to mc*/ |
| 43 | err = mc_send_command(mc_io, &cmd); |
| 44 | if (err) |
| 45 | return err; |
| 46 | |
| 47 | /* retrieve response parameters */ |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 48 | *token = mc_cmd_hdr_read_token(&cmd); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 53 | /** |
| 54 | * dpio_close() - Close the control session of the object |
| 55 | * @mc_io: Pointer to MC portal's I/O object |
| 56 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 57 | * @token: Token of DPIO object |
| 58 | * |
| 59 | * Return: '0' on Success; Error code otherwise. |
| 60 | */ |
| 61 | int dpio_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 62 | { |
| 63 | struct mc_command cmd = { 0 }; |
| 64 | |
| 65 | /* prepare command */ |
| 66 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 67 | cmd_flags, |
| 68 | token); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 69 | |
| 70 | /* send command to mc*/ |
| 71 | return mc_send_command(mc_io, &cmd); |
| 72 | } |
| 73 | |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 74 | /** |
| 75 | * dpio_create() - Create the DPIO object. |
| 76 | * @mc_io: Pointer to MC portal's I/O object |
| 77 | * @dprc_token: Parent container token; '0' for default container |
| 78 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 79 | * @cfg: Configuration structure |
| 80 | * @obj_id: Returned object id |
| 81 | * |
| 82 | * Create the DPIO object, allocate required resources and |
| 83 | * perform required initialization. |
| 84 | * |
| 85 | * The object can be created either by declaring it in the |
| 86 | * DPL file, or by calling this function. |
| 87 | * |
| 88 | * The function accepts an authentication token of a parent |
| 89 | * container that this object should be assigned to. The token |
| 90 | * can be '0' so the object will be assigned to the default container. |
| 91 | * The newly created object can be opened with the returned |
| 92 | * object id and using the container's associated tokens and MC portals. |
| 93 | * |
| 94 | * Return: '0' on Success; Error code otherwise. |
| 95 | */ |
| 96 | int dpio_create(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags, |
| 97 | const struct dpio_cfg *cfg, u32 *obj_id) |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 98 | { |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 99 | struct dpio_cmd_create *cmd_params; |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 100 | struct mc_command cmd = { 0 }; |
| 101 | int err; |
| 102 | |
| 103 | /* prepare command */ |
| 104 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_CREATE, |
| 105 | cmd_flags, |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 106 | dprc_token); |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 107 | cmd_params = (struct dpio_cmd_create *)cmd.params; |
| 108 | cmd_params->num_priorities = cfg->num_priorities; |
| 109 | dpio_set_field(cmd_params->channel_mode, |
| 110 | CHANNEL_MODE, |
| 111 | cfg->channel_mode); |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 112 | |
| 113 | /* send command to mc*/ |
| 114 | err = mc_send_command(mc_io, &cmd); |
| 115 | if (err) |
| 116 | return err; |
| 117 | |
| 118 | /* retrieve response parameters */ |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 119 | *obj_id = mc_cmd_read_object_id(&cmd); |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 124 | /** |
| 125 | * dpio_destroy() - Destroy the DPIO object and release all its resources. |
| 126 | * @mc_io: Pointer to MC portal's I/O object |
| 127 | * @dprc_token: Parent container token; '0' for default container |
| 128 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 129 | * @object_id: The object id; it must be a valid id within the container that |
| 130 | * created this object; |
| 131 | * |
| 132 | * The function accepts the authentication token of the parent container that |
| 133 | * created the object (not the one that currently owns the object). The object |
| 134 | * is searched within parent using the provided 'object_id'. |
| 135 | * All tokens to the object must be closed before calling destroy. |
| 136 | * |
| 137 | * Return: '0' on Success; Error code otherwise |
| 138 | */ |
| 139 | int dpio_destroy(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags, |
| 140 | u32 object_id) |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 141 | { |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 142 | struct dpio_cmd_destroy *cmd_params; |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 143 | struct mc_command cmd = { 0 }; |
| 144 | |
| 145 | /* prepare command */ |
| 146 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_DESTROY, |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 147 | cmd_flags, |
| 148 | dprc_token); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 149 | |
| 150 | /* set object id to destroy */ |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 151 | cmd_params = (struct dpio_cmd_destroy *)cmd.params; |
| 152 | cmd_params->dpio_id = cpu_to_le32(object_id); |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 153 | |
| 154 | /* send command to mc*/ |
| 155 | return mc_send_command(mc_io, &cmd); |
| 156 | } |
| 157 | |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 158 | /** |
| 159 | * dpio_enable() - Enable the DPIO, allow I/O portal operations. |
| 160 | * @mc_io: Pointer to MC portal's I/O object |
| 161 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 162 | * @token: Token of DPIO object |
| 163 | * |
| 164 | * Return: '0' on Success; Error code otherwise |
| 165 | */ |
| 166 | int dpio_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 167 | { |
| 168 | struct mc_command cmd = { 0 }; |
| 169 | |
| 170 | /* prepare command */ |
| 171 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 172 | cmd_flags, |
| 173 | token); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 174 | |
| 175 | /* send command to mc*/ |
| 176 | return mc_send_command(mc_io, &cmd); |
| 177 | } |
| 178 | |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 179 | /** |
| 180 | * dpio_disable() - Disable the DPIO, stop any I/O portal operation. |
| 181 | * @mc_io: Pointer to MC portal's I/O object |
| 182 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 183 | * @token: Token of DPIO object |
| 184 | * |
| 185 | * Return: '0' on Success; Error code otherwise |
| 186 | */ |
| 187 | int dpio_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 188 | { |
| 189 | struct mc_command cmd = { 0 }; |
| 190 | |
| 191 | /* prepare command */ |
| 192 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 193 | cmd_flags, |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 194 | token); |
| 195 | |
| 196 | /* send command to mc*/ |
| 197 | return mc_send_command(mc_io, &cmd); |
| 198 | } |
| 199 | |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 200 | /** |
| 201 | * dpio_get_attributes() - Retrieve DPIO attributes |
| 202 | * @mc_io: Pointer to MC portal's I/O object |
| 203 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 204 | * @token: Token of DPIO object |
| 205 | * @attr: Returned object's attributes |
| 206 | * |
| 207 | * Return: '0' on Success; Error code otherwise |
| 208 | */ |
| 209 | int dpio_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] | 210 | struct dpio_attr *attr) |
| 211 | { |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 212 | struct dpio_rsp_get_attr *rsp_params; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 213 | struct mc_command cmd = { 0 }; |
| 214 | int err; |
| 215 | |
| 216 | /* prepare command */ |
| 217 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 218 | cmd_flags, |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 219 | token); |
| 220 | |
| 221 | /* send command to mc*/ |
| 222 | err = mc_send_command(mc_io, &cmd); |
| 223 | if (err) |
| 224 | return err; |
| 225 | |
| 226 | /* retrieve response parameters */ |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 227 | rsp_params = (struct dpio_rsp_get_attr *)cmd.params; |
| 228 | attr->id = le32_to_cpu(rsp_params->id); |
| 229 | attr->qbman_portal_id = le16_to_cpu(rsp_params->qbman_portal_id); |
| 230 | attr->num_priorities = rsp_params->num_priorities; |
| 231 | attr->qbman_portal_ce_offset = le64_to_cpu(rsp_params->qbman_portal_ce_offset); |
| 232 | attr->qbman_portal_ci_offset = le64_to_cpu(rsp_params->qbman_portal_ci_offset); |
| 233 | attr->qbman_version = le32_to_cpu(rsp_params->qbman_version); |
| 234 | attr->clk = le32_to_cpu(rsp_params->clk); |
| 235 | attr->channel_mode = dpio_get_field(rsp_params->channel_mode, ATTR_CHANNEL_MODE); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 236 | |
| 237 | return 0; |
| 238 | } |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 239 | |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 240 | /** |
| 241 | * dpio_get_api_version() - Get Data Path I/O API version |
| 242 | * @mc_io: Pointer to MC portal's I/O object |
| 243 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 244 | * @major_ver: Major version of data path i/o API |
| 245 | * @minor_ver: Minor version of data path i/o API |
| 246 | * |
| 247 | * Return: '0' on Success; Error code otherwise. |
| 248 | */ |
| 249 | int dpio_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags, |
| 250 | u16 *major_ver, u16 *minor_ver) |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 251 | { |
| 252 | struct mc_command cmd = { 0 }; |
| 253 | int err; |
| 254 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 255 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION, |
Ioana Ciornei | bc262da | 2023-05-31 19:04:35 +0300 | [diff] [blame] | 256 | cmd_flags, |
| 257 | 0); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 258 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 259 | err = mc_send_command(mc_io, &cmd); |
| 260 | if (err) |
| 261 | return err; |
| 262 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 263 | mc_cmd_read_api_version(&cmd, major_ver, minor_ver); |
| 264 | |
| 265 | return 0; |
| 266 | } |