File: feature.c

package info (click to toggle)
dpdk 25.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 127,892 kB
  • sloc: ansic: 2,358,479; python: 16,426; sh: 4,474; makefile: 1,713; awk: 70
file content (141 lines) | stat: -rw-r--r-- 3,749 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(C) 2025 Marvell International Ltd.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <cmdline_parse.h>
#include <cmdline_parse_num.h>
#include <cmdline_parse_string.h>
#include <cmdline_socket.h>
#include <rte_ethdev.h>

#include "module_api.h"

static const char
cmd_feature_arcs_help[] = "feature arcs    # Display all feature arcs";

static const char
cmd_feature_show_help[] = "feature <arc_name> show   # Display features within an arc";

static const char
cmd_feature_enable_help[] = "feature enable <arc name> <feature name> <port-id>";

static const char
cmd_feature_disable_help[] = "feature disable <arc name> <feature name> <port-id>";

static void
feature_show(const char *arc_name)
{
	rte_graph_feature_arc_t _arc;
	uint32_t length, count, i;

	length = strlen(conn->msg_out);
	conn->msg_out += length;

	if (rte_graph_feature_arc_lookup_by_name(arc_name, &_arc) < 0)
		return;

	count = rte_graph_feature_arc_num_features(_arc);

	if (count) {
		snprintf(conn->msg_out, conn->msg_out_len_max, "\n%s%s%s\n",
			 "----------------------------- feature arc: ",
			 rte_graph_feature_arc_get(_arc)->feature_arc_name,
			 " -----------------------------");
		for (i = 0; i < count; i++)
			snprintf(conn->msg_out + strlen(conn->msg_out),
				 conn->msg_out_len_max, "%s\n",
				 rte_graph_feature_arc_feature_to_name(_arc, i));
	}
	length = strlen(conn->msg_out);
	conn->msg_out_len_max -= length;
}

static void
feature_arcs_show(void)
{
	uint32_t length, count, i;
	char **names;

	length = strlen(conn->msg_out);
	conn->msg_out += length;

	count = rte_graph_feature_arc_names_get(NULL);

	if (count) {
		names = malloc(count);
		if (!names) {
			snprintf(conn->msg_out, conn->msg_out_len_max, "Failed to allocate memory\n");
			return;
		}
		count = rte_graph_feature_arc_names_get(names);
		snprintf(conn->msg_out, conn->msg_out_len_max, "\n%s\n",
			 "----------------------------- feature arcs -----------------------------");
		for (i = 0; i < count; i++)
			feature_show(names[i]);
		free(names);
	}
	length = strlen(conn->msg_out);
	conn->msg_out_len_max -= length;
}

void
cmd_feature_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
		   __rte_unused void *data)
{
	struct cmd_feature_result *res = parsed_result;

	feature_show(res->name);
}


void
cmd_feature_arcs_parsed(__rte_unused void *parsed_result, __rte_unused struct cmdline *cl,
			__rte_unused void *data)
{
		feature_arcs_show();
}

void
cmd_feature_enable_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
			  __rte_unused void *data)
{
	struct cmd_feature_enable_result *res = parsed_result;
	rte_graph_feature_arc_t arc;

	if (!rte_graph_feature_arc_lookup_by_name(res->arc_name, &arc))
		rte_graph_feature_enable(arc, res->interface, res->feature_name,
					 res->interface, NULL);
}

void
cmd_feature_disable_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
			   __rte_unused void *data)
{
	struct cmd_feature_disable_result *res = parsed_result;
	rte_graph_feature_arc_t arc;

	if (!rte_graph_feature_arc_lookup_by_name(res->arc_name, &arc))
		rte_graph_feature_disable(arc, res->interface, res->feature_name, NULL);

}

void
cmd_help_feature_parsed(__rte_unused void *parsed_result, __rte_unused struct cmdline *cl,
			__rte_unused void *data)
{
	size_t len;

	len = strlen(conn->msg_out);
	conn->msg_out += len;
	snprintf(conn->msg_out, conn->msg_out_len_max, "\n%s\n%s\n%s\n%s\n%s\n",
		 "----------------------------- feature command help -----------------------------",
		 cmd_feature_arcs_help, cmd_feature_show_help, cmd_feature_enable_help,
		 cmd_feature_disable_help);

	len = strlen(conn->msg_out);
	conn->msg_out_len_max -= len;
}