]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/drivers/net/dpaa2/mc/dpdmux.c
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / dpdk / drivers / net / dpaa2 / mc / dpdmux.c
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2 *
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2018-2019 NXP
5 *
6 */
7 #include <fsl_mc_sys.h>
8 #include <fsl_mc_cmd.h>
9 #include <fsl_dpdmux.h>
10 #include <fsl_dpdmux_cmd.h>
11
12 /** @addtogroup dpdmux
13 * @{
14 */
15
16 /**
17 * dpdmux_open() - Open a control session for the specified object
18 * @mc_io: Pointer to MC portal's I/O object
19 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
20 * @dpdmux_id: DPDMUX unique ID
21 * @token: Returned token; use in subsequent API calls
22 *
23 * This function can be used to open a control session for an
24 * already created object; an object may have been declared in
25 * the DPL or by calling the dpdmux_create() function.
26 * This function returns a unique authentication token,
27 * associated with the specific object ID and the specific MC
28 * portal; this token must be used in all subsequent commands for
29 * this specific object.
30 *
31 * Return: '0' on Success; Error code otherwise.
32 */
33 int dpdmux_open(struct fsl_mc_io *mc_io,
34 uint32_t cmd_flags,
35 int dpdmux_id,
36 uint16_t *token)
37 {
38 struct mc_command cmd = { 0 };
39 struct dpdmux_cmd_open *cmd_params;
40 int err;
41
42 /* prepare command */
43 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_OPEN,
44 cmd_flags,
45 0);
46 cmd_params = (struct dpdmux_cmd_open *)cmd.params;
47 cmd_params->dpdmux_id = cpu_to_le32(dpdmux_id);
48
49 /* send command to mc*/
50 err = mc_send_command(mc_io, &cmd);
51 if (err)
52 return err;
53
54 /* retrieve response parameters */
55 *token = mc_cmd_hdr_read_token(&cmd);
56
57 return 0;
58 }
59
60 /**
61 * dpdmux_close() - Close the control session of the object
62 * @mc_io: Pointer to MC portal's I/O object
63 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
64 * @token: Token of DPDMUX object
65 *
66 * After this function is called, no further operations are
67 * allowed on the object without opening a new control session.
68 *
69 * Return: '0' on Success; Error code otherwise.
70 */
71 int dpdmux_close(struct fsl_mc_io *mc_io,
72 uint32_t cmd_flags,
73 uint16_t token)
74 {
75 struct mc_command cmd = { 0 };
76
77 /* prepare command */
78 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_CLOSE,
79 cmd_flags,
80 token);
81
82 /* send command to mc*/
83 return mc_send_command(mc_io, &cmd);
84 }
85
86 /**
87 * dpdmux_create() - Create the DPDMUX object
88 * @mc_io: Pointer to MC portal's I/O object
89 * @dprc_token: Parent container token; '0' for default container
90 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
91 * @cfg: Configuration structure
92 * @obj_id: returned object id
93 *
94 * Create the DPDMUX object, allocate required resources and
95 * perform required initialization.
96 *
97 * The object can be created either by declaring it in the
98 * DPL file, or by calling this function.
99 *
100 * The function accepts an authentication token of a parent
101 * container that this object should be assigned to. The token
102 * can be '0' so the object will be assigned to the default container.
103 * The newly created object can be opened with the returned
104 * object id and using the container's associated tokens and MC portals.
105 *
106 * Return: '0' on Success; Error code otherwise.
107 */
108 int dpdmux_create(struct fsl_mc_io *mc_io,
109 uint16_t dprc_token,
110 uint32_t cmd_flags,
111 const struct dpdmux_cfg *cfg,
112 uint32_t *obj_id)
113 {
114 struct mc_command cmd = { 0 };
115 struct dpdmux_cmd_create *cmd_params;
116 int err;
117
118 /* prepare command */
119 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_CREATE,
120 cmd_flags,
121 dprc_token);
122 cmd_params = (struct dpdmux_cmd_create *)cmd.params;
123 cmd_params->method = cfg->method;
124 cmd_params->manip = cfg->manip;
125 cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
126 cmd_params->adv_max_dmat_entries =
127 cpu_to_le16(cfg->adv.max_dmat_entries);
128 cmd_params->adv_max_mc_groups = cpu_to_le16(cfg->adv.max_mc_groups);
129 cmd_params->adv_max_vlan_ids = cpu_to_le16(cfg->adv.max_vlan_ids);
130 cmd_params->options = cpu_to_le64(cfg->adv.options);
131
132 /* send command to mc*/
133 err = mc_send_command(mc_io, &cmd);
134 if (err)
135 return err;
136
137 /* retrieve response parameters */
138 *obj_id = mc_cmd_read_object_id(&cmd);
139
140 return 0;
141 }
142
143 /**
144 * dpdmux_destroy() - Destroy the DPDMUX object and release all its resources.
145 * @mc_io: Pointer to MC portal's I/O object
146 * @dprc_token: Parent container token; '0' for default container
147 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
148 * @object_id: The object id; it must be a valid id within the container that
149 * created this object;
150 *
151 * The function accepts the authentication token of the parent container that
152 * created the object (not the one that currently owns the object). The object
153 * is searched within parent using the provided 'object_id'.
154 * All tokens to the object must be closed before calling destroy.
155 *
156 * Return: '0' on Success; error code otherwise.
157 */
158 int dpdmux_destroy(struct fsl_mc_io *mc_io,
159 uint16_t dprc_token,
160 uint32_t cmd_flags,
161 uint32_t object_id)
162 {
163 struct mc_command cmd = { 0 };
164 struct dpdmux_cmd_destroy *cmd_params;
165
166 /* prepare command */
167 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_DESTROY,
168 cmd_flags,
169 dprc_token);
170 cmd_params = (struct dpdmux_cmd_destroy *)cmd.params;
171 cmd_params->dpdmux_id = cpu_to_le32(object_id);
172
173 /* send command to mc*/
174 return mc_send_command(mc_io, &cmd);
175 }
176
177 /**
178 * dpdmux_enable() - Enable DPDMUX functionality
179 * @mc_io: Pointer to MC portal's I/O object
180 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
181 * @token: Token of DPDMUX object
182 *
183 * Return: '0' on Success; Error code otherwise.
184 */
185 int dpdmux_enable(struct fsl_mc_io *mc_io,
186 uint32_t cmd_flags,
187 uint16_t token)
188 {
189 struct mc_command cmd = { 0 };
190
191 /* prepare command */
192 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_ENABLE,
193 cmd_flags,
194 token);
195
196 /* send command to mc*/
197 return mc_send_command(mc_io, &cmd);
198 }
199
200 /**
201 * dpdmux_disable() - Disable DPDMUX functionality
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 DPDMUX object
205 *
206 * Return: '0' on Success; Error code otherwise.
207 */
208 int dpdmux_disable(struct fsl_mc_io *mc_io,
209 uint32_t cmd_flags,
210 uint16_t token)
211 {
212 struct mc_command cmd = { 0 };
213
214 /* prepare command */
215 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_DISABLE,
216 cmd_flags,
217 token);
218
219 /* send command to mc*/
220 return mc_send_command(mc_io, &cmd);
221 }
222
223 /**
224 * dpdmux_is_enabled() - Check if the DPDMUX is enabled.
225 * @mc_io: Pointer to MC portal's I/O object
226 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
227 * @token: Token of DPDMUX object
228 * @en: Returns '1' if object is enabled; '0' otherwise
229 *
230 * Return: '0' on Success; Error code otherwise.
231 */
232 int dpdmux_is_enabled(struct fsl_mc_io *mc_io,
233 uint32_t cmd_flags,
234 uint16_t token,
235 int *en)
236 {
237 struct mc_command cmd = { 0 };
238 struct dpdmux_rsp_is_enabled *rsp_params;
239 int err;
240
241 /* prepare command */
242 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IS_ENABLED,
243 cmd_flags,
244 token);
245
246 /* send command to mc*/
247 err = mc_send_command(mc_io, &cmd);
248 if (err)
249 return err;
250
251 /* retrieve response parameters */
252 rsp_params = (struct dpdmux_rsp_is_enabled *)cmd.params;
253 *en = dpdmux_get_field(rsp_params->en, ENABLE);
254
255 return 0;
256 }
257
258 /**
259 * dpdmux_reset() - Reset the DPDMUX, returns the object to initial state.
260 * @mc_io: Pointer to MC portal's I/O object
261 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
262 * @token: Token of DPDMUX object
263 *
264 * Return: '0' on Success; Error code otherwise.
265 */
266 int dpdmux_reset(struct fsl_mc_io *mc_io,
267 uint32_t cmd_flags,
268 uint16_t token)
269 {
270 struct mc_command cmd = { 0 };
271
272 /* prepare command */
273 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_RESET,
274 cmd_flags,
275 token);
276
277 /* send command to mc*/
278 return mc_send_command(mc_io, &cmd);
279 }
280
281 /**
282 * dpdmux_get_attributes() - Retrieve DPDMUX attributes
283 * @mc_io: Pointer to MC portal's I/O object
284 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
285 * @token: Token of DPDMUX object
286 * @attr: Returned object's attributes
287 *
288 * Return: '0' on Success; Error code otherwise.
289 */
290 int dpdmux_get_attributes(struct fsl_mc_io *mc_io,
291 uint32_t cmd_flags,
292 uint16_t token,
293 struct dpdmux_attr *attr)
294 {
295 struct mc_command cmd = { 0 };
296 struct dpdmux_rsp_get_attr *rsp_params;
297 int err;
298
299 /* prepare command */
300 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_ATTR,
301 cmd_flags,
302 token);
303
304 /* send command to mc*/
305 err = mc_send_command(mc_io, &cmd);
306 if (err)
307 return err;
308
309 /* retrieve response parameters */
310 rsp_params = (struct dpdmux_rsp_get_attr *)cmd.params;
311 attr->id = le32_to_cpu(rsp_params->id);
312 attr->options = le64_to_cpu(rsp_params->options);
313 attr->method = rsp_params->method;
314 attr->manip = rsp_params->manip;
315 attr->num_ifs = le16_to_cpu(rsp_params->num_ifs);
316 attr->mem_size = le16_to_cpu(rsp_params->mem_size);
317
318 return 0;
319 }
320
321 /**
322 * dpdmux_if_enable() - Enable Interface
323 * @mc_io: Pointer to MC portal's I/O object
324 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
325 * @token: Token of DPDMUX object
326 * @if_id: Interface Identifier
327 *
328 * Return: Completion status. '0' on Success; Error code otherwise.
329 */
330 int dpdmux_if_enable(struct fsl_mc_io *mc_io,
331 uint32_t cmd_flags,
332 uint16_t token,
333 uint16_t if_id)
334 {
335 struct dpdmux_cmd_if *cmd_params;
336 struct mc_command cmd = { 0 };
337
338 /* prepare command */
339 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_ENABLE,
340 cmd_flags,
341 token);
342 cmd_params = (struct dpdmux_cmd_if *)cmd.params;
343 cmd_params->if_id = cpu_to_le16(if_id);
344
345 /* send command to mc*/
346 return mc_send_command(mc_io, &cmd);
347 }
348
349 /**
350 * dpdmux_if_disable() - Disable Interface
351 * @mc_io: Pointer to MC portal's I/O object
352 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
353 * @token: Token of DPDMUX object
354 * @if_id: Interface Identifier
355 *
356 * Return: Completion status. '0' on Success; Error code otherwise.
357 */
358 int dpdmux_if_disable(struct fsl_mc_io *mc_io,
359 uint32_t cmd_flags,
360 uint16_t token,
361 uint16_t if_id)
362 {
363 struct dpdmux_cmd_if *cmd_params;
364 struct mc_command cmd = { 0 };
365
366 /* prepare command */
367 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_DISABLE,
368 cmd_flags,
369 token);
370 cmd_params = (struct dpdmux_cmd_if *)cmd.params;
371 cmd_params->if_id = cpu_to_le16(if_id);
372
373 /* send command to mc*/
374 return mc_send_command(mc_io, &cmd);
375 }
376
377 /**
378 * dpdmux_set_max_frame_length() - Set the maximum frame length in DPDMUX
379 * @mc_io: Pointer to MC portal's I/O object
380 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
381 * @token: Token of DPDMUX object
382 * @max_frame_length: The required maximum frame length
383 *
384 * Update the maximum frame length on all DMUX interfaces.
385 * In case of VEPA, the maximum frame length on all dmux interfaces
386 * will be updated with the minimum value of the mfls of the connected
387 * dpnis and the actual value of dmux mfl.
388 *
389 * Return: '0' on Success; Error code otherwise.
390 */
391 int dpdmux_set_max_frame_length(struct fsl_mc_io *mc_io,
392 uint32_t cmd_flags,
393 uint16_t token,
394 uint16_t max_frame_length)
395 {
396 struct mc_command cmd = { 0 };
397 struct dpdmux_cmd_set_max_frame_length *cmd_params;
398
399 /* prepare command */
400 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_MAX_FRAME_LENGTH,
401 cmd_flags,
402 token);
403 cmd_params = (struct dpdmux_cmd_set_max_frame_length *)cmd.params;
404 cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
405
406 /* send command to mc*/
407 return mc_send_command(mc_io, &cmd);
408 }
409
410 /**
411 * dpdmux_ul_reset_counters() - Function resets the uplink counter
412 * @mc_io: Pointer to MC portal's I/O object
413 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
414 * @token: Token of DPDMUX object
415 *
416 * Return: '0' on Success; Error code otherwise.
417 */
418 int dpdmux_ul_reset_counters(struct fsl_mc_io *mc_io,
419 uint32_t cmd_flags,
420 uint16_t token)
421 {
422 struct mc_command cmd = { 0 };
423
424 /* prepare command */
425 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_UL_RESET_COUNTERS,
426 cmd_flags,
427 token);
428
429 /* send command to mc*/
430 return mc_send_command(mc_io, &cmd);
431 }
432
433 /**
434 * dpdmux_if_set_accepted_frames() - Set the accepted frame types
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 DPDMUX object
438 * @if_id: Interface ID (0 for uplink, or 1-num_ifs);
439 * @cfg: Frame types configuration
440 *
441 * if 'DPDMUX_ADMIT_ONLY_VLAN_TAGGED' is set - untagged frames or
442 * priority-tagged frames are discarded.
443 * if 'DPDMUX_ADMIT_ONLY_UNTAGGED' is set - untagged frames or
444 * priority-tagged frames are accepted.
445 * if 'DPDMUX_ADMIT_ALL' is set (default mode) - all VLAN tagged,
446 * untagged and priority-tagged frame are accepted;
447 *
448 * Return: '0' on Success; Error code otherwise.
449 */
450 int dpdmux_if_set_accepted_frames(struct fsl_mc_io *mc_io,
451 uint32_t cmd_flags,
452 uint16_t token,
453 uint16_t if_id,
454 const struct dpdmux_accepted_frames *cfg)
455 {
456 struct mc_command cmd = { 0 };
457 struct dpdmux_cmd_if_set_accepted_frames *cmd_params;
458
459 /* prepare command */
460 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_ACCEPTED_FRAMES,
461 cmd_flags,
462 token);
463 cmd_params = (struct dpdmux_cmd_if_set_accepted_frames *)cmd.params;
464 cmd_params->if_id = cpu_to_le16(if_id);
465 dpdmux_set_field(cmd_params->frames_options,
466 ACCEPTED_FRAMES_TYPE,
467 cfg->type);
468 dpdmux_set_field(cmd_params->frames_options,
469 UNACCEPTED_FRAMES_ACTION,
470 cfg->unaccept_act);
471
472 /* send command to mc*/
473 return mc_send_command(mc_io, &cmd);
474 }
475
476 /**
477 * dpdmux_if_get_attributes() - Obtain DPDMUX interface attributes
478 * @mc_io: Pointer to MC portal's I/O object
479 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
480 * @token: Token of DPDMUX object
481 * @if_id: Interface ID (0 for uplink, or 1-num_ifs);
482 * @attr: Interface attributes
483 *
484 * Return: '0' on Success; Error code otherwise.
485 */
486 int dpdmux_if_get_attributes(struct fsl_mc_io *mc_io,
487 uint32_t cmd_flags,
488 uint16_t token,
489 uint16_t if_id,
490 struct dpdmux_if_attr *attr)
491 {
492 struct mc_command cmd = { 0 };
493 struct dpdmux_cmd_if *cmd_params;
494 struct dpdmux_rsp_if_get_attr *rsp_params;
495 int err;
496
497 /* prepare command */
498 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_ATTR,
499 cmd_flags,
500 token);
501 cmd_params = (struct dpdmux_cmd_if *)cmd.params;
502 cmd_params->if_id = cpu_to_le16(if_id);
503
504 /* send command to mc*/
505 err = mc_send_command(mc_io, &cmd);
506 if (err)
507 return err;
508
509 /* retrieve response parameters */
510 rsp_params = (struct dpdmux_rsp_if_get_attr *)cmd.params;
511 attr->rate = le32_to_cpu(rsp_params->rate);
512 attr->enabled = dpdmux_get_field(rsp_params->enabled, ENABLE);
513 attr->is_default = dpdmux_get_field(rsp_params->enabled, IS_DEFAULT);
514 attr->accept_frame_type = dpdmux_get_field(
515 rsp_params->accepted_frames_type,
516 ACCEPTED_FRAMES_TYPE);
517
518 return 0;
519 }
520
521 /**
522 * dpdmux_if_remove_l2_rule() - Remove L2 rule from DPDMUX table
523 * @mc_io: Pointer to MC portal's I/O object
524 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
525 * @token: Token of DPDMUX object
526 * @if_id: Destination interface ID
527 * @rule: L2 rule
528 *
529 * Function removes a L2 rule from DPDMUX table
530 * or adds an interface to an existing multicast address
531 *
532 * Return: '0' on Success; Error code otherwise.
533 */
534 int dpdmux_if_remove_l2_rule(struct fsl_mc_io *mc_io,
535 uint32_t cmd_flags,
536 uint16_t token,
537 uint16_t if_id,
538 const struct dpdmux_l2_rule *rule)
539 {
540 struct mc_command cmd = { 0 };
541 struct dpdmux_cmd_if_l2_rule *cmd_params;
542
543 /* prepare command */
544 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_REMOVE_L2_RULE,
545 cmd_flags,
546 token);
547 cmd_params = (struct dpdmux_cmd_if_l2_rule *)cmd.params;
548 cmd_params->if_id = cpu_to_le16(if_id);
549 cmd_params->vlan_id = cpu_to_le16(rule->vlan_id);
550 cmd_params->mac_addr5 = rule->mac_addr[5];
551 cmd_params->mac_addr4 = rule->mac_addr[4];
552 cmd_params->mac_addr3 = rule->mac_addr[3];
553 cmd_params->mac_addr2 = rule->mac_addr[2];
554 cmd_params->mac_addr1 = rule->mac_addr[1];
555 cmd_params->mac_addr0 = rule->mac_addr[0];
556
557 /* send command to mc*/
558 return mc_send_command(mc_io, &cmd);
559 }
560
561 /**
562 * dpdmux_if_add_l2_rule() - Add L2 rule into DPDMUX table
563 * @mc_io: Pointer to MC portal's I/O object
564 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
565 * @token: Token of DPDMUX object
566 * @if_id: Destination interface ID
567 * @rule: L2 rule
568 *
569 * Function adds a L2 rule into DPDMUX table
570 * or adds an interface to an existing multicast address
571 *
572 * Return: '0' on Success; Error code otherwise.
573 */
574 int dpdmux_if_add_l2_rule(struct fsl_mc_io *mc_io,
575 uint32_t cmd_flags,
576 uint16_t token,
577 uint16_t if_id,
578 const struct dpdmux_l2_rule *rule)
579 {
580 struct mc_command cmd = { 0 };
581 struct dpdmux_cmd_if_l2_rule *cmd_params;
582
583 /* prepare command */
584 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_ADD_L2_RULE,
585 cmd_flags,
586 token);
587 cmd_params = (struct dpdmux_cmd_if_l2_rule *)cmd.params;
588 cmd_params->if_id = cpu_to_le16(if_id);
589 cmd_params->vlan_id = cpu_to_le16(rule->vlan_id);
590 cmd_params->mac_addr5 = rule->mac_addr[5];
591 cmd_params->mac_addr4 = rule->mac_addr[4];
592 cmd_params->mac_addr3 = rule->mac_addr[3];
593 cmd_params->mac_addr2 = rule->mac_addr[2];
594 cmd_params->mac_addr1 = rule->mac_addr[1];
595 cmd_params->mac_addr0 = rule->mac_addr[0];
596
597 /* send command to mc*/
598 return mc_send_command(mc_io, &cmd);
599 }
600
601 /**
602 * dpdmux_if_get_counter() - Functions obtains specific counter of an interface
603 * @mc_io: Pointer to MC portal's I/O object
604 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
605 * @token: Token of DPDMUX object
606 * @if_id: Interface Id
607 * @counter_type: counter type
608 * @counter: Returned specific counter information
609 *
610 * Return: '0' on Success; Error code otherwise.
611 */
612 int dpdmux_if_get_counter(struct fsl_mc_io *mc_io,
613 uint32_t cmd_flags,
614 uint16_t token,
615 uint16_t if_id,
616 enum dpdmux_counter_type counter_type,
617 uint64_t *counter)
618 {
619 struct mc_command cmd = { 0 };
620 struct dpdmux_cmd_if_get_counter *cmd_params;
621 struct dpdmux_rsp_if_get_counter *rsp_params;
622 int err;
623
624 /* prepare command */
625 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_COUNTER,
626 cmd_flags,
627 token);
628 cmd_params = (struct dpdmux_cmd_if_get_counter *)cmd.params;
629 cmd_params->if_id = cpu_to_le16(if_id);
630 cmd_params->counter_type = counter_type;
631
632 /* send command to mc*/
633 err = mc_send_command(mc_io, &cmd);
634 if (err)
635 return err;
636
637 /* retrieve response parameters */
638 rsp_params = (struct dpdmux_rsp_if_get_counter *)cmd.params;
639 *counter = le64_to_cpu(rsp_params->counter);
640
641 return 0;
642 }
643
644 /**
645 * dpdmux_if_set_link_cfg() - set the link configuration.
646 * @mc_io: Pointer to MC portal's I/O object
647 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
648 * @token: Token of DPSW object
649 * @if_id: interface id
650 * @cfg: Link configuration
651 *
652 * Return: '0' on Success; Error code otherwise.
653 */
654 int dpdmux_if_set_link_cfg(struct fsl_mc_io *mc_io,
655 uint32_t cmd_flags,
656 uint16_t token,
657 uint16_t if_id,
658 struct dpdmux_link_cfg *cfg)
659 {
660 struct mc_command cmd = { 0 };
661 struct dpdmux_cmd_if_set_link_cfg *cmd_params;
662
663 /* prepare command */
664 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_LINK_CFG,
665 cmd_flags,
666 token);
667 cmd_params = (struct dpdmux_cmd_if_set_link_cfg *)cmd.params;
668 cmd_params->if_id = cpu_to_le16(if_id);
669 cmd_params->rate = cpu_to_le32(cfg->rate);
670 cmd_params->options = cpu_to_le64(cfg->options);
671 cmd_params->advertising = cpu_to_le64(cfg->advertising);
672
673 /* send command to mc*/
674 return mc_send_command(mc_io, &cmd);
675 }
676
677 /**
678 * dpdmux_if_get_link_state - Return the link state
679 * @mc_io: Pointer to MC portal's I/O object
680 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
681 * @token: Token of DPSW object
682 * @if_id: interface id
683 * @state: link state
684 *
685 * @returns '0' on Success; Error code otherwise.
686 */
687 int dpdmux_if_get_link_state(struct fsl_mc_io *mc_io,
688 uint32_t cmd_flags,
689 uint16_t token,
690 uint16_t if_id,
691 struct dpdmux_link_state *state)
692 {
693 struct mc_command cmd = { 0 };
694 struct dpdmux_cmd_if_get_link_state *cmd_params;
695 struct dpdmux_rsp_if_get_link_state *rsp_params;
696 int err;
697
698 /* prepare command */
699 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_LINK_STATE,
700 cmd_flags,
701 token);
702 cmd_params = (struct dpdmux_cmd_if_get_link_state *)cmd.params;
703 cmd_params->if_id = cpu_to_le16(if_id);
704
705 /* send command to mc*/
706 err = mc_send_command(mc_io, &cmd);
707 if (err)
708 return err;
709
710 /* retrieve response parameters */
711 rsp_params = (struct dpdmux_rsp_if_get_link_state *)cmd.params;
712 state->rate = le32_to_cpu(rsp_params->rate);
713 state->options = le64_to_cpu(rsp_params->options);
714 state->up = dpdmux_get_field(rsp_params->up, UP);
715 state->state_valid = dpdmux_get_field(rsp_params->up, STATE_VALID);
716 state->supported = le64_to_cpu(rsp_params->supported);
717 state->advertising = le64_to_cpu(rsp_params->advertising);
718
719 return 0;
720 }
721
722 /**
723 * dpdmux_if_set_default - Set default interface
724 * @mc_io: Pointer to MC portal's I/O object
725 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
726 * @token: Token of DPSW object
727 * @if_id: interface id
728 *
729 * @returns '0' on Success; Error code otherwise.
730 */
731 int dpdmux_if_set_default(struct fsl_mc_io *mc_io,
732 uint32_t cmd_flags,
733 uint16_t token,
734 uint16_t if_id)
735 {
736 struct dpdmux_cmd_if *cmd_params;
737 struct mc_command cmd = { 0 };
738
739 /* prepare command */
740 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_DEFAULT,
741 cmd_flags,
742 token);
743 cmd_params = (struct dpdmux_cmd_if *)cmd.params;
744 cmd_params->if_id = cpu_to_le16(if_id);
745
746 /* send command to mc*/
747 return mc_send_command(mc_io, &cmd);
748 }
749
750 /**
751 * dpdmux_if_get_default - Get default interface
752 * @mc_io: Pointer to MC portal's I/O object
753 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
754 * @token: Token of DPSW object
755 * @if_id: interface id
756 *
757 * @returns '0' on Success; Error code otherwise.
758 */
759 int dpdmux_if_get_default(struct fsl_mc_io *mc_io,
760 uint32_t cmd_flags,
761 uint16_t token,
762 uint16_t *if_id)
763 {
764 struct dpdmux_cmd_if *rsp_params;
765 struct mc_command cmd = { 0 };
766 int err;
767
768 /* prepare command */
769 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_DEFAULT,
770 cmd_flags,
771 token);
772
773 /* send command to mc*/
774 err = mc_send_command(mc_io, &cmd);
775 if (err)
776 return err;
777
778 /* retrieve response parameters */
779 rsp_params = (struct dpdmux_cmd_if *)cmd.params;
780 *if_id = le16_to_cpu(rsp_params->if_id);
781
782 return 0;
783 }
784
785 /**
786 * dpdmux_set_custom_key - Set a custom classification key.
787 *
788 * This API is only available for DPDMUX instance created with
789 * DPDMUX_METHOD_CUSTOM. This API must be called before populating the
790 * classification table using dpdmux_add_custom_cls_entry.
791 *
792 * Calls to dpdmux_set_custom_key remove all existing classification entries
793 * that may have been added previously using dpdmux_add_custom_cls_entry.
794 *
795 * @mc_io: Pointer to MC portal's I/O object
796 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
797 * @token: Token of DPSW object
798 * @if_id: Interface id
799 * @key_cfg_iova: DMA address of a configuration structure set up using
800 * dpkg_prepare_key_cfg. Maximum key size is 24 bytes
801 *
802 * @returns '0' on Success; Error code otherwise.
803 */
804 int dpdmux_set_custom_key(struct fsl_mc_io *mc_io,
805 uint32_t cmd_flags,
806 uint16_t token,
807 uint64_t key_cfg_iova)
808 {
809 struct dpdmux_set_custom_key *cmd_params;
810 struct mc_command cmd = { 0 };
811
812 /* prepare command */
813 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_CUSTOM_KEY,
814 cmd_flags,
815 token);
816 cmd_params = (struct dpdmux_set_custom_key *)cmd.params;
817 cmd_params->key_cfg_iova = cpu_to_le64(key_cfg_iova);
818
819 /* send command to mc*/
820 return mc_send_command(mc_io, &cmd);
821 }
822
823 /**
824 * dpdmux_add_custom_cls_entry - Adds a custom classification entry.
825 *
826 * This API is only available for DPDMUX instances created with
827 * DPDMUX_METHOD_CUSTOM. Before calling this function a classification key
828 * composition rule must be set up using dpdmux_set_custom_key.
829 *
830 * @mc_io: Pointer to MC portal's I/O object
831 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
832 * @token: Token of DPSW object
833 * @rule: Classification rule to insert. Rules cannot be duplicated, if a
834 * matching rule already exists, the action will be replaced.
835 * @action: Action to perform for matching traffic.
836 *
837 * @returns '0' on Success; Error code otherwise.
838 */
839 int dpdmux_add_custom_cls_entry(struct fsl_mc_io *mc_io,
840 uint32_t cmd_flags,
841 uint16_t token,
842 struct dpdmux_rule_cfg *rule,
843 struct dpdmux_cls_action *action)
844 {
845 struct dpdmux_cmd_add_custom_cls_entry *cmd_params;
846 struct mc_command cmd = { 0 };
847
848 /* prepare command */
849 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_ADD_CUSTOM_CLS_ENTRY,
850 cmd_flags,
851 token);
852
853 cmd_params = (struct dpdmux_cmd_add_custom_cls_entry *)cmd.params;
854 cmd_params->key_size = rule->key_size;
855 cmd_params->dest_if = cpu_to_le16(action->dest_if);
856 cmd_params->key_iova = cpu_to_le64(rule->key_iova);
857 cmd_params->mask_iova = cpu_to_le64(rule->mask_iova);
858
859 /* send command to mc*/
860 return mc_send_command(mc_io, &cmd);
861 }
862
863 /**
864 * dpdmux_remove_custom_cls_entry - Removes a custom classification entry.
865 *
866 * This API is only available for DPDMUX instances created with
867 * DPDMUX_METHOD_CUSTOM. The API can be used to remove classification
868 * entries previously inserted using dpdmux_add_custom_cls_entry.
869 *
870 * @mc_io: Pointer to MC portal's I/O object
871 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
872 * @token: Token of DPSW object
873 * @rule: Classification rule to remove
874 *
875 * @returns '0' on Success; Error code otherwise.
876 */
877 int dpdmux_remove_custom_cls_entry(struct fsl_mc_io *mc_io,
878 uint32_t cmd_flags,
879 uint16_t token,
880 struct dpdmux_rule_cfg *rule)
881 {
882 struct dpdmux_cmd_remove_custom_cls_entry *cmd_params;
883 struct mc_command cmd = { 0 };
884
885 /* prepare command */
886 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_REMOVE_CUSTOM_CLS_ENTRY,
887 cmd_flags,
888 token);
889 cmd_params = (struct dpdmux_cmd_remove_custom_cls_entry *)cmd.params;
890 cmd_params->key_size = rule->key_size;
891 cmd_params->key_iova = cpu_to_le64(rule->key_iova);
892 cmd_params->mask_iova = cpu_to_le64(rule->mask_iova);
893
894 /* send command to mc*/
895 return mc_send_command(mc_io, &cmd);
896 }
897
898 /**
899 * dpdmux_get_api_version() - Get Data Path Demux API version
900 * @mc_io: Pointer to MC portal's I/O object
901 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
902 * @major_ver: Major version of data path demux API
903 * @minor_ver: Minor version of data path demux API
904 *
905 * Return: '0' on Success; Error code otherwise.
906 */
907 int dpdmux_get_api_version(struct fsl_mc_io *mc_io,
908 uint32_t cmd_flags,
909 uint16_t *major_ver,
910 uint16_t *minor_ver)
911 {
912 struct mc_command cmd = { 0 };
913 struct dpdmux_rsp_get_api_version *rsp_params;
914 int err;
915
916 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_API_VERSION,
917 cmd_flags,
918 0);
919
920 err = mc_send_command(mc_io, &cmd);
921 if (err)
922 return err;
923
924 rsp_params = (struct dpdmux_rsp_get_api_version *)cmd.params;
925 *major_ver = le16_to_cpu(rsp_params->major);
926 *minor_ver = le16_to_cpu(rsp_params->minor);
927
928 return 0;
929 }