blob: d17210bf451a3aecb0e8b68afafe73da7713fd98 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07002/*
Yogesh Gaur1a0c4ae2018-05-09 10:52:17 +05303 * Copyright 2013-2016 Freescale Semiconductor, Inc.
Ioana Ciorneibc262da2023-05-31 19:04:35 +03004 * Copyright 2017, 2023 NXP
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07005 */
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 Ciorneibc262da2023-05-31 19:04:35 +030011/**
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 */
28int dpio_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpio_id,
29 u16 *token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070030{
Ioana Ciorneibc262da2023-05-31 19:04:35 +030031 struct dpio_cmd_open *cmd_params;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070032 struct mc_command cmd = { 0 };
33 int err;
34
35 /* prepare command */
36 cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053037 cmd_flags,
38 0);
Ioana Ciorneibc262da2023-05-31 19:04:35 +030039 cmd_params = (struct dpio_cmd_open *)cmd.params;
40 cmd_params->dpio_id = cpu_to_le32(dpio_id);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070041
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 Ciorneibc262da2023-05-31 19:04:35 +030048 *token = mc_cmd_hdr_read_token(&cmd);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070049
50 return 0;
51}
52
Ioana Ciorneibc262da2023-05-31 19:04:35 +030053/**
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 */
61int dpio_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070062{
63 struct mc_command cmd = { 0 };
64
65 /* prepare command */
66 cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053067 cmd_flags,
68 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070069
70 /* send command to mc*/
71 return mc_send_command(mc_io, &cmd);
72}
73
Ioana Ciorneibc262da2023-05-31 19:04:35 +030074/**
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 */
96int dpio_create(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags,
97 const struct dpio_cfg *cfg, u32 *obj_id)
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053098{
Ioana Ciorneibc262da2023-05-31 19:04:35 +030099 struct dpio_cmd_create *cmd_params;
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530100 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 Gaur318c32f2017-11-15 11:59:31 +0530106 dprc_token);
Ioana Ciorneibc262da2023-05-31 19:04:35 +0300107 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 Kushwahacf0c8cf2015-11-04 12:25:53 +0530112
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 Ciorneibc262da2023-05-31 19:04:35 +0300119 *obj_id = mc_cmd_read_object_id(&cmd);
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530120
121 return 0;
122}
123
Ioana Ciorneibc262da2023-05-31 19:04:35 +0300124/**
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 */
139int dpio_destroy(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags,
140 u32 object_id)
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530141{
Ioana Ciorneibc262da2023-05-31 19:04:35 +0300142 struct dpio_cmd_destroy *cmd_params;
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530143 struct mc_command cmd = { 0 };
144
145 /* prepare command */
146 cmd.header = mc_encode_cmd_header(DPIO_CMDID_DESTROY,
Ioana Ciorneibc262da2023-05-31 19:04:35 +0300147 cmd_flags,
148 dprc_token);
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530149
150 /* set object id to destroy */
Ioana Ciorneibc262da2023-05-31 19:04:35 +0300151 cmd_params = (struct dpio_cmd_destroy *)cmd.params;
152 cmd_params->dpio_id = cpu_to_le32(object_id);
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530153
154 /* send command to mc*/
155 return mc_send_command(mc_io, &cmd);
156}
157
Ioana Ciorneibc262da2023-05-31 19:04:35 +0300158/**
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 */
166int dpio_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700167{
168 struct mc_command cmd = { 0 };
169
170 /* prepare command */
171 cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530172 cmd_flags,
173 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700174
175 /* send command to mc*/
176 return mc_send_command(mc_io, &cmd);
177}
178
Ioana Ciorneibc262da2023-05-31 19:04:35 +0300179/**
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 */
187int dpio_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700188{
189 struct mc_command cmd = { 0 };
190
191 /* prepare command */
192 cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530193 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700194 token);
195
196 /* send command to mc*/
197 return mc_send_command(mc_io, &cmd);
198}
199
Ioana Ciorneibc262da2023-05-31 19:04:35 +0300200/**
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 */
209int dpio_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700210 struct dpio_attr *attr)
211{
Ioana Ciorneibc262da2023-05-31 19:04:35 +0300212 struct dpio_rsp_get_attr *rsp_params;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700213 struct mc_command cmd = { 0 };
214 int err;
215
216 /* prepare command */
217 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530218 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700219 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 Ciorneibc262da2023-05-31 19:04:35 +0300227 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 Kushwahacfd9fbf2015-03-19 09:20:45 -0700236
237 return 0;
238}
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530239
Ioana Ciorneibc262da2023-05-31 19:04:35 +0300240/**
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 */
249int dpio_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
250 u16 *major_ver, u16 *minor_ver)
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530251{
252 struct mc_command cmd = { 0 };
253 int err;
254
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530255 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION,
Ioana Ciorneibc262da2023-05-31 19:04:35 +0300256 cmd_flags,
257 0);
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530258
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530259 err = mc_send_command(mc_io, &cmd);
260 if (err)
261 return err;
262
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530263 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
264
265 return 0;
266}