blob: 5b815a45a99de47a224b57795e05e98f2beb3597 [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 Ciorneibe117372023-05-31 19:04:33 +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_dpni.h>
10
Ioana Ciorneibe117372023-05-31 19:04:33 +030011/**
12 * dpni_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 * @dpni_id: DPNI 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 dpni_create() function.
21 * This function returns a unique authentication token,
22 * associated with the specific object ID and the specific MC
23 * portal; this token must be used in all subsequent commands for
24 * this specific object.
25 *
26 * Return: '0' on Success; Error code otherwise.
27 */
28int dpni_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpni_id, u16 *token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070029{
Ioana Ciorneibe117372023-05-31 19:04:33 +030030 struct dpni_cmd_open *cmd_params;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070031 struct mc_command cmd = { 0 };
Ioana Ciorneibe117372023-05-31 19:04:33 +030032
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070033 int err;
34
35 /* prepare command */
36 cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053037 cmd_flags,
38 0);
Ioana Ciorneibe117372023-05-31 19:04:33 +030039 cmd_params = (struct dpni_cmd_open *)cmd.params;
40 cmd_params->dpni_id = cpu_to_le32(dpni_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 Ciorneibe117372023-05-31 19:04:33 +030048 *token = mc_cmd_hdr_read_token(&cmd);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070049
50 return 0;
51}
52
Ioana Ciorneibe117372023-05-31 19:04:33 +030053/**
54 * dpni_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 DPNI object
58 *
59 * After this function is called, no further operations are
60 * allowed on the object without opening a new control session.
61 *
62 * Return: '0' on Success; Error code otherwise.
63 */
64int dpni_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070065{
66 struct mc_command cmd = { 0 };
67
68 /* prepare command */
69 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053070 cmd_flags,
71 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070072
73 /* send command to mc*/
74 return mc_send_command(mc_io, &cmd);
75}
76
Ioana Ciorneibe117372023-05-31 19:04:33 +030077/**
78 * dpni_create() - Create the DPNI object
79 * @mc_io: Pointer to MC portal's I/O object
80 * @dprc_token: Parent container token; '0' for default container
81 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
82 * @cfg: Configuration structure
83 * @obj_id: Returned object id
84 *
85 * Create the DPNI object, allocate required resources and
86 * perform required initialization.
87 *
88 * The object can be created either by declaring it in the
89 * DPL file, or by calling this function.
90 *
91 * The function accepts an authentication token of a parent
92 * container that this object should be assigned to. The token
93 * can be '0' so the object will be assigned to the default container.
94 * The newly created object can be opened with the returned
95 * object id and using the container's associated tokens and MC portals.
96 *
97 * Return: '0' on Success; Error code otherwise.
98 */
99int dpni_create(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags,
100 const struct dpni_cfg *cfg, u32 *obj_id)
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530101{
Ioana Ciorneibe117372023-05-31 19:04:33 +0300102 struct dpni_cmd_create *cmd_params;
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530103 struct mc_command cmd = { 0 };
104 int err;
105
106 /* prepare command */
107 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CREATE,
108 cmd_flags,
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530109 dprc_token);
Ioana Ciorneibe117372023-05-31 19:04:33 +0300110 cmd_params = (struct dpni_cmd_create *)cmd.params;
111 cmd_params->options = cpu_to_le32(cfg->options);
112 cmd_params->num_queues = cfg->num_queues;
113 cmd_params->num_tcs = cfg->num_tcs;
114 cmd_params->mac_filter_entries = cfg->mac_filter_entries;
115 cmd_params->num_rx_tcs = cfg->num_rx_tcs;
116 cmd_params->vlan_filter_entries = cfg->vlan_filter_entries;
117 cmd_params->qos_entries = cfg->qos_entries;
118 cmd_params->fs_entries = cpu_to_le16(cfg->fs_entries);
119 cmd_params->num_cgs = cfg->num_cgs;
120 cmd_params->num_opr = cfg->num_opr;
121 cmd_params->dist_key_size = cfg->dist_key_size;
122 cmd_params->num_channels = cfg->num_channels;
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530123
124 /* send command to mc*/
125 err = mc_send_command(mc_io, &cmd);
126 if (err)
127 return err;
128
129 /* retrieve response parameters */
Ioana Ciorneibe117372023-05-31 19:04:33 +0300130 *obj_id = mc_cmd_read_object_id(&cmd);
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530131
132 return 0;
133}
134
Ioana Ciorneibe117372023-05-31 19:04:33 +0300135/**
136 * dpni_destroy() - Destroy the DPNI object and release all its resources.
137 * @mc_io: Pointer to MC portal's I/O object
138 * @dprc_token: Parent container token; '0' for default container
139 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
140 * @object_id: The object id; it must be a valid id within the container that
141 * created this object;
142 *
143 * The function accepts the authentication token of the parent container that
144 * created the object (not the one that currently owns the object). The object
145 * is searched within parent using the provided 'object_id'.
146 * All tokens to the object must be closed before calling destroy.
147 *
148 * Return: '0' on Success; error code otherwise.
149 */
150int dpni_destroy(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags,
151 u32 object_id)
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530152{
Ioana Ciorneibe117372023-05-31 19:04:33 +0300153 struct dpni_cmd_destroy *cmd_params;
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530154 struct mc_command cmd = { 0 };
155
156 /* prepare command */
157 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DESTROY,
158 cmd_flags,
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530159 dprc_token);
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530160 /* set object id to destroy */
Ioana Ciorneibe117372023-05-31 19:04:33 +0300161 cmd_params = (struct dpni_cmd_destroy *)cmd.params;
162 cmd_params->dpni_id = cpu_to_le32(object_id);
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530163
164 /* send command to mc*/
165 return mc_send_command(mc_io, &cmd);
166}
167
Ioana Ciorneibe117372023-05-31 19:04:33 +0300168/**
169 * dpni_set_pools() - Set buffer pools configuration
170 * @mc_io: Pointer to MC portal's I/O object
171 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
172 * @token: Token of DPNI object
173 * @cfg: Buffer pools configuration
174 *
175 * mandatory for DPNI operation
176 * warning:Allowed only when DPNI is disabled
177 *
178 * Return: '0' on Success; Error code otherwise.
179 */
180int dpni_set_pools(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700181 const struct dpni_pools_cfg *cfg)
182{
183 struct mc_command cmd = { 0 };
Ioana Ciorneibe117372023-05-31 19:04:33 +0300184 struct dpni_cmd_set_pools *cmd_params;
185 int i;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700186
187 /* prepare command */
188 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530189 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700190 token);
Ioana Ciorneibe117372023-05-31 19:04:33 +0300191 cmd_params = (struct dpni_cmd_set_pools *)cmd.params;
192 cmd_params->num_dpbp = cfg->num_dpbp;
193 cmd_params->pool_options = cfg->pool_options;
194 for (i = 0; i < DPNI_MAX_DPBP; i++) {
195 cmd_params->pool[i].dpbp_id =
196 cpu_to_le16(cfg->pools[i].dpbp_id);
197 cmd_params->pool[i].priority_mask =
198 cfg->pools[i].priority_mask;
199 cmd_params->buffer_size[i] =
200 cpu_to_le16(cfg->pools[i].buffer_size);
201 cmd_params->backup_pool_mask |=
202 DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i);
203 }
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700204
205 /* send command to mc*/
206 return mc_send_command(mc_io, &cmd);
207}
208
Ioana Ciorneibe117372023-05-31 19:04:33 +0300209/**
210 * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
211 * @mc_io: Pointer to MC portal's I/O object
212 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
213 * @token: Token of DPNI object
214 *
215 * Return: '0' on Success; Error code otherwise.
216 */
217int dpni_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700218{
219 struct mc_command cmd = { 0 };
220
221 /* prepare command */
222 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530223 cmd_flags,
224 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700225
226 /* send command to mc*/
227 return mc_send_command(mc_io, &cmd);
228}
229
Ioana Ciorneibe117372023-05-31 19:04:33 +0300230/**
231 * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
232 * @mc_io: Pointer to MC portal's I/O object
233 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
234 * @token: Token of DPNI object
235 *
236 * Return: '0' on Success; Error code otherwise.
237 */
238int dpni_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700239{
240 struct mc_command cmd = { 0 };
241
242 /* prepare command */
243 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530244 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700245 token);
246
247 /* send command to mc*/
248 return mc_send_command(mc_io, &cmd);
249}
250
Ioana Ciorneibe117372023-05-31 19:04:33 +0300251/**
252 * dpni_reset() - Reset the DPNI, returns the object to initial state.
253 * @mc_io: Pointer to MC portal's I/O object
254 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
255 * @token: Token of DPNI object
256 *
257 * Return: '0' on Success; Error code otherwise.
258 */
259int dpni_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700260{
261 struct mc_command cmd = { 0 };
262
263 /* prepare command */
264 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530265 cmd_flags,
266 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700267
268 /* send command to mc*/
269 return mc_send_command(mc_io, &cmd);
270}
271
Ioana Ciorneibe117372023-05-31 19:04:33 +0300272/**
273 * dpni_get_attributes() - Retrieve DPNI attributes.
274 * @mc_io: Pointer to MC portal's I/O object
275 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
276 * @token: Token of DPNI object
277 * @attr: Object's attributes
278 *
279 * Return: '0' on Success; Error code otherwise.
280 */
281int dpni_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700282 struct dpni_attr *attr)
283{
284 struct mc_command cmd = { 0 };
Ioana Ciorneibe117372023-05-31 19:04:33 +0300285 struct dpni_rsp_get_attr *rsp_params;
286
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700287 int err;
288
289 /* prepare command */
290 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530291 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700292 token);
Ioana Ciorneibe117372023-05-31 19:04:33 +0300293
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700294 /* send command to mc*/
295 err = mc_send_command(mc_io, &cmd);
296 if (err)
297 return err;
298
299 /* retrieve response parameters */
Ioana Ciorneibe117372023-05-31 19:04:33 +0300300 rsp_params = (struct dpni_rsp_get_attr *)cmd.params;
301 attr->options = le32_to_cpu(rsp_params->options);
302 attr->num_queues = rsp_params->num_queues;
303 attr->num_rx_tcs = rsp_params->num_rx_tcs;
304 attr->num_tx_tcs = rsp_params->num_tx_tcs;
305 attr->mac_filter_entries = rsp_params->mac_filter_entries;
306 attr->vlan_filter_entries = rsp_params->vlan_filter_entries;
307 attr->num_channels = rsp_params->num_channels;
308 attr->qos_entries = rsp_params->qos_entries;
309 attr->fs_entries = le16_to_cpu(rsp_params->fs_entries);
310 attr->num_opr = le16_to_cpu(rsp_params->num_opr);
311 attr->qos_key_size = rsp_params->qos_key_size;
312 attr->fs_key_size = rsp_params->fs_key_size;
313 attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
314 attr->num_cgs = rsp_params->num_cgs;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700315
316 return 0;
317}
318
Ioana Ciorneibe117372023-05-31 19:04:33 +0300319/**
320 * dpni_set_buffer_layout() - Set buffer layout configuration.
321 * @mc_io: Pointer to MC portal's I/O object
322 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
323 * @token: Token of DPNI object
324 * @qtype: Type of queue this configuration applies to
325 * @layout: Buffer layout configuration
326 *
327 * Return: '0' on Success; Error code otherwise.
328 *
329 * @warning Allowed only when DPNI is disabled
330 */
331int dpni_set_buffer_layout(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
332 enum dpni_queue_type qtype,
333 const struct dpni_buffer_layout *layout)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700334{
Ioana Ciorneibe117372023-05-31 19:04:33 +0300335 struct dpni_cmd_set_buffer_layout *cmd_params;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700336 struct mc_command cmd = { 0 };
337
338 /* prepare command */
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530339 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530340 cmd_flags,
341 token);
Ioana Ciorneibe117372023-05-31 19:04:33 +0300342 cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
343 cmd_params->qtype = qtype;
344 cmd_params->options = cpu_to_le16((u16)layout->options);
345 dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
346 dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
347 dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
348 dpni_set_field(cmd_params->flags, PASS_SWO, layout->pass_sw_opaque);
349 cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
350 cmd_params->data_align = cpu_to_le16(layout->data_align);
351 cmd_params->head_room = cpu_to_le16(layout->data_head_room);
352 cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700353
354 /* send command to mc*/
355 return mc_send_command(mc_io, &cmd);
356}
357
Ioana Ciorneibe117372023-05-31 19:04:33 +0300358/**
359 * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
360 * for enqueue operations
361 * @mc_io: Pointer to MC portal's I/O object
362 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
363 * @token: Token of DPNI object
364 * @qtype: Type of queue to receive QDID for
365 * @qdid: Returned virtual QDID value that should be used as an argument
366 * in all enqueue operations
367 *
368 * Return: '0' on Success; Error code otherwise.
369 *
370 * If dpni object is created using multiple Tc channels this function will return
371 * qdid value for the first channel
372 */
373int dpni_get_qdid(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
374 enum dpni_queue_type qtype, u16 *qdid)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700375{
376 struct mc_command cmd = { 0 };
Ioana Ciorneibe117372023-05-31 19:04:33 +0300377 struct dpni_cmd_get_qdid *cmd_params;
378 struct dpni_rsp_get_qdid *rsp_params;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700379 int err;
380
381 /* prepare command */
382 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530383 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700384 token);
Ioana Ciorneibe117372023-05-31 19:04:33 +0300385 cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
386 cmd_params->qtype = qtype;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700387
388 /* send command to mc*/
389 err = mc_send_command(mc_io, &cmd);
390 if (err)
391 return err;
392
393 /* retrieve response parameters */
Ioana Ciorneibe117372023-05-31 19:04:33 +0300394 rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
395 *qdid = le16_to_cpu(rsp_params->qdid);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700396
397 return 0;
398}
399
Ioana Ciorneibe117372023-05-31 19:04:33 +0300400/**
401 * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
402 * @mc_io: Pointer to MC portal's I/O object
403 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
404 * @token: Token of DPNI object
405 * @data_offset: Tx data offset (from start of buffer)
406 *
407 * Return: '0' on Success; Error code otherwise.
408 */
409int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
410 u16 *data_offset)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700411{
412 struct mc_command cmd = { 0 };
Ioana Ciorneibe117372023-05-31 19:04:33 +0300413 struct dpni_rsp_get_tx_data_offset *rsp_params;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700414 int err;
415
416 /* prepare command */
417 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530418 cmd_flags,
419 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700420
421 /* send command to mc*/
422 err = mc_send_command(mc_io, &cmd);
423 if (err)
424 return err;
425
426 /* retrieve response parameters */
Ioana Ciorneibe117372023-05-31 19:04:33 +0300427 rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
428 *data_offset = le16_to_cpu(rsp_params->data_offset);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700429
430 return 0;
431}
432
Ioana Ciorneibe117372023-05-31 19:04:33 +0300433/**
434 * dpni_set_link_cfg() - set the link configuration.
435 * @mc_io: Pointer to MC portal's I/O object
436 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
437 * @token: Token of DPNI object
438 * @cfg: Link configuration
439 *
440 * Return: '0' on Success; Error code otherwise.
441 */
442int dpni_set_link_cfg(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530443 const struct dpni_link_cfg *cfg)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700444{
445 struct mc_command cmd = { 0 };
Ioana Ciorneibe117372023-05-31 19:04:33 +0300446 struct dpni_cmd_set_link_cfg *cmd_params;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700447
448 /* prepare command */
449 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530450 cmd_flags,
451 token);
Ioana Ciorneibe117372023-05-31 19:04:33 +0300452 cmd_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
453 cmd_params->rate = cpu_to_le32(cfg->rate);
454 cmd_params->options = cpu_to_le64(cfg->options);
455 cmd_params->advertising = cpu_to_le64(cfg->advertising);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700456
457 /* send command to mc*/
458 return mc_send_command(mc_io, &cmd);
459}
460
Ioana Ciorneibe117372023-05-31 19:04:33 +0300461/**
462 * dpni_get_link_state() - Return the link state (either up or down)
463 * @mc_io: Pointer to MC portal's I/O object
464 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
465 * @token: Token of DPNI object
466 * @state: Returned link state;
467 *
468 * Return: '0' on Success; Error code otherwise.
469 */
470int dpni_get_link_state(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700471 struct dpni_link_state *state)
472{
473 struct mc_command cmd = { 0 };
Ioana Ciorneibe117372023-05-31 19:04:33 +0300474 struct dpni_rsp_get_link_state *rsp_params;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700475 int err;
476
477 /* prepare command */
478 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530479 cmd_flags,
480 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700481
482 /* send command to mc*/
483 err = mc_send_command(mc_io, &cmd);
484 if (err)
485 return err;
486
487 /* retrieve response parameters */
Ioana Ciorneibe117372023-05-31 19:04:33 +0300488 rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
489 state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
490 state->state_valid = dpni_get_field(rsp_params->flags, STATE_VALID);
491 state->rate = le32_to_cpu(rsp_params->rate);
492 state->options = le64_to_cpu(rsp_params->options);
493 state->supported = le64_to_cpu(rsp_params->supported);
494 state->advertising = le64_to_cpu(rsp_params->advertising);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700495
496 return 0;
497}
498
Ioana Ciorneibe117372023-05-31 19:04:33 +0300499/**
500 * dpni_add_mac_addr() - Add MAC address filter
501 * @mc_io: Pointer to MC portal's I/O object
502 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
503 * @token: Token of DPNI object
504 * @mac_addr: MAC address to add
505 * @flags :0 - tc_id and flow_id will be ignored.
506 * Pkt with this mac_id will be passed to the next
507 * classification stages
508 * DPNI_MAC_SET_QUEUE_ACTION
509 * Pkt with this mac will be forward directly to
510 * queue defined by the tc_id and flow_id
511 * @tc_id : Traffic class selection (0-7)
512 * @flow_id : Selects the specific queue out of the set allocated for the
513 * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
514 * Return: '0' on Success; Error code otherwise.
515 */
516int dpni_add_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
517 const u8 mac_addr[6], u8 flags,
518 u8 tc_id, u8 flow_id)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700519{
Ioana Ciorneibe117372023-05-31 19:04:33 +0300520 struct dpni_cmd_add_mac_addr *cmd_params;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700521 struct mc_command cmd = { 0 };
Ioana Ciorneibe117372023-05-31 19:04:33 +0300522 int i;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700523
524 /* prepare command */
525 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530526 cmd_flags,
527 token);
Ioana Ciorneibe117372023-05-31 19:04:33 +0300528 cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
529 cmd_params->flags = flags;
530 cmd_params->tc_id = tc_id;
531 cmd_params->fq_id = flow_id;
532
533 for (i = 0; i < 6; i++)
534 cmd_params->mac_addr[i] = mac_addr[5 - i];
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700535
536 /* send command to mc*/
537 return mc_send_command(mc_io, &cmd);
538}
539
Ioana Ciorneibe117372023-05-31 19:04:33 +0300540/**
541 * dpni_get_api_version() - Get Data Path Network Interface API version
542 * @mc_io: Pointer to MC portal's I/O object
543 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
544 * @major_ver: Major version of data path network interface API
545 * @minor_ver: Minor version of data path network interface API
546 *
547 * Return: '0' on Success; Error code otherwise.
548 */
549int dpni_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
550 u16 *major_ver, u16 *minor_ver)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700551{
552 struct mc_command cmd = { 0 };
553 int err;
554
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530555 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
Ioana Ciorneibe117372023-05-31 19:04:33 +0300556 cmd_flags,
557 0);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700558
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700559 err = mc_send_command(mc_io, &cmd);
560 if (err)
561 return err;
562
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530563 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700564
565 return 0;
566}
567
Ioana Ciorneibe117372023-05-31 19:04:33 +0300568/**
569 * dpni_set_queue() - Set queue parameters
570 * @mc_io: Pointer to MC portal's I/O object
571 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
572 * @token: Token of DPNI object
573 * @qtype: Type of queue - all queue types are supported, although
574 * the command is ignored for Tx
575 * @tc: Traffic class, in range 0 to NUM_TCS - 1
576 * @index: Selects the specific queue out of the set allocated for the
577 * same TC. Value must be in range 0 to NUM_QUEUES - 1
578 * @options: A combination of DPNI_QUEUE_OPT_ values that control what
579 * configuration options are set on the queue
580 * @queue: Queue structure
581 *
582 * Return: '0' on Success; Error code otherwise.
583 */
584int dpni_set_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
585 enum dpni_queue_type qtype, u16 param, u8 index,
586 u8 options, const struct dpni_queue *queue)
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530587{
588 struct mc_command cmd = { 0 };
Ioana Ciorneibe117372023-05-31 19:04:33 +0300589 struct dpni_cmd_set_queue *cmd_params;
590
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530591 /* prepare command */
592 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
593 cmd_flags,
594 token);
Ioana Ciorneibe117372023-05-31 19:04:33 +0300595 cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
596 cmd_params->qtype = qtype;
597 cmd_params->tc = (u8)(param & 0xff);
598 cmd_params->channel_id = (u8)((param >> 8) & 0xff);
599 cmd_params->index = index;
600 cmd_params->options = options;
601 cmd_params->dest_id = cpu_to_le32(queue->destination.id);
602 cmd_params->dest_prio = queue->destination.priority;
603 dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
604 dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
605 dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
606 queue->destination.hold_active);
607 cmd_params->flc = cpu_to_le64(queue->flc.value);
608 cmd_params->user_context = cpu_to_le64(queue->user_context);
609 cmd_params->cgid = queue->cgid;
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530610
Ioana Ciorneibe117372023-05-31 19:04:33 +0300611 /* send command to mc */
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530612 return mc_send_command(mc_io, &cmd);
613}
614
Ioana Ciorneibe117372023-05-31 19:04:33 +0300615/**
616 * dpni_get_queue() - Get queue parameters
617 * @mc_io: Pointer to MC portal's I/O object
618 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
619 * @token: Token of DPNI object
620 * @qtype: Type of queue - all queue types are supported
621 * @param: Traffic class and channel ID.
622 * MSB - channel id; used only for DPNI_QUEUE_TX and
623 * DPNI_QUEUE_TX_CONFIRM, ignored for the rest
624 * LSB - traffic class
625 * Use macro DPNI_BUILD_PARAM() to build correct value.
626 * If dpni uses a single channel (uses only channel zero)
627 * the parameter can receive traffic class directly.
628 * @index: Selects the specific queue out of the set allocated for the
629 * same TC. Value must be in range 0 to NUM_QUEUES - 1
630 * @queue: Queue configuration structure
631 * @qid: Queue identification
632 *
633 * Return: '0' on Success; Error code otherwise.
634 */
635int dpni_get_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
636 enum dpni_queue_type qtype, u16 param, u8 index,
637 struct dpni_queue *queue, struct dpni_queue_id *qid)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700638{
639 struct mc_command cmd = { 0 };
Ioana Ciorneibe117372023-05-31 19:04:33 +0300640 struct dpni_cmd_get_queue *cmd_params;
641 struct dpni_rsp_get_queue *rsp_params;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700642 int err;
643
644 /* prepare command */
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530645 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530646 cmd_flags,
647 token);
Ioana Ciorneibe117372023-05-31 19:04:33 +0300648 cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
649 cmd_params->qtype = qtype;
650 cmd_params->tc = (u8)(param & 0xff);
651 cmd_params->index = index;
652 cmd_params->channel_id = (u8)((param >> 8) & 0xff);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700653
Ioana Ciorneibe117372023-05-31 19:04:33 +0300654 /* send command to mc */
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700655 err = mc_send_command(mc_io, &cmd);
656 if (err)
657 return err;
658
659 /* retrieve response parameters */
Ioana Ciorneibe117372023-05-31 19:04:33 +0300660 rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
661 queue->destination.id = le32_to_cpu(rsp_params->dest_id);
662 queue->destination.priority = rsp_params->dest_prio;
663 queue->destination.type = dpni_get_field(rsp_params->flags, DEST_TYPE);
664 queue->flc.stash_control = dpni_get_field(rsp_params->flags, STASH_CTRL);
665 queue->destination.hold_active = dpni_get_field(rsp_params->flags, HOLD_ACTIVE);
666 queue->flc.value = le64_to_cpu(rsp_params->flc);
667 queue->user_context = le64_to_cpu(rsp_params->user_context);
668 qid->fqid = le32_to_cpu(rsp_params->fqid);
669 qid->qdbin = le16_to_cpu(rsp_params->qdbin);
670 if (dpni_get_field(rsp_params->flags, CGID_VALID))
671 queue->cgid = rsp_params->cgid;
672 else
673 queue->cgid = -1;
674
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700675 return 0;
676}
677
Ioana Ciorneibe117372023-05-31 19:04:33 +0300678/**
679 * dpni_set_tx_confirmation_mode() - Tx confirmation mode
680 * @mc_io: Pointer to MC portal's I/O object
681 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
682 * @token: Token of DPNI object
683 * @ceetm_ch_idx: ceetm channel index
684 * @mode: Tx confirmation mode
685 *
686 * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not
687 * selected at DPNI creation.
688 * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all
689 * transmit confirmation (including the private confirmation queues), regardless
690 * of previous settings; Note that in this case, Tx error frames are still
691 * enqueued to the general transmit errors queue.
692 * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all
693 * Tx confirmations to a shared Tx conf queue. 'index' field in dpni_get_queue
694 * command will be ignored.
695 *
696 * Return: '0' on Success; Error code otherwise.
697 */
698int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
699 u8 ceetm_ch_idx, enum dpni_confirmation_mode mode)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700700{
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530701 struct dpni_tx_confirmation_mode *cmd_params;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700702 struct mc_command cmd = { 0 };
703
704 /* prepare command */
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530705 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
Ioana Ciorneibe117372023-05-31 19:04:33 +0300706 cmd_flags, token);
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530707 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params;
Ioana Ciorneibe117372023-05-31 19:04:33 +0300708 cmd_params->ceetm_ch_idx = ceetm_ch_idx;
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530709 cmd_params->confirmation_mode = mode;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700710
711 /* send command to mc*/
712 return mc_send_command(mc_io, &cmd);
713}
714
Ioana Ciorneibe117372023-05-31 19:04:33 +0300715/**
716 * dpni_get_statistics() - Get DPNI statistics
717 * @mc_io: Pointer to MC portal's I/O object
718 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
719 * @token: Token of DPNI object
720 * @page: Selects the statistics page to retrieve, see
721 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 6.
722 * @param: Custom parameter for some pages used to select
723 * a certain statistic source, for example the TC.
724 * - page_0: not used
725 * - page_1: not used
726 * - page_2: not used
727 * - page_3: high_byte - channel_id, low_byte - traffic class
728 * - page_4: high_byte - queue_index have meaning only if dpni is
729 * created using option DPNI_OPT_CUSTOM_CG, low_byte - traffic class
730 * - page_5: not used
731 * - page_6: not used
732 * @stat: Structure containing the statistics
733 *
734 * Return: '0' on Success; Error code otherwise.
735 */
736int dpni_get_statistics(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
737 u8 page, u16 param, union dpni_statistics *stat)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700738{
Ioana Ciorneibe117372023-05-31 19:04:33 +0300739 struct dpni_cmd_get_statistics *cmd_params;
740 struct dpni_rsp_get_statistics *rsp_params;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700741 struct mc_command cmd = { 0 };
Ioana Ciorneibe117372023-05-31 19:04:33 +0300742 int i, err;
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530743
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700744 /* prepare command */
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530745 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
Ioana Ciorneibe117372023-05-31 19:04:33 +0300746 cmd_flags,
747 token);
748 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
749 cmd_params->page_number = page;
750 cmd_params->param = param;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700751
Ioana Ciorneibe117372023-05-31 19:04:33 +0300752 /* send command to mc */
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700753 err = mc_send_command(mc_io, &cmd);
754 if (err)
755 return err;
756
757 /* retrieve response parameters */
Ioana Ciorneibe117372023-05-31 19:04:33 +0300758 rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
759 for (i = 0; i < DPNI_STATISTICS_CNT; i++)
760 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700761
762 return 0;
763}