From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5F6E7A0555; Fri, 26 Aug 2022 13:22:03 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ED2FC4282F; Fri, 26 Aug 2022 13:21:38 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 4B0E4427E9 for ; Fri, 26 Aug 2022 13:21:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661512894; x=1693048894; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=sx/iaGyaadlMWvywXnlJlbEUv5hTvQSceNb+Jn4oEVo=; b=KfUw22yWZ/K96MxO056wn6VRIcoZuSzEe7YpftS7zqh04MN1xS+wQFLy yUCkJZZAPzDIgl+v391qqImyNEyLbgfGK/a1BNh+vZ0O9FtYwOFvuKbm9 mNG2y9lx5je6eHF98ccWk51QNOOR9m78OVeXfMvDipxRpLNIsLlh66Wt8 gHmcuNbkTYahSXJCqJhlk7baFzKNwvZMbtJWa00V1f6pFXtYzN6Kfjh7Z R4Rz9zxZA94ao8lD80g74Z/QubBdlAveiq34m5sezqOiAwNSOqZNorslM +mSAHez4uIY2XJ+iCsR7rqd0JAkGJ/Eoal5z2kZf9Z/FuwLdgJJh9oqie g==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="295264084" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="295264084" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 04:21:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="678834812" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by fmsmga004.fm.intel.com with ESMTP; 26 Aug 2022 04:21:33 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V2 6/7] examples/pipeline: add CLI commands for direct registers Date: Fri, 26 Aug 2022 11:21:26 +0000 Message-Id: <20220826112127.1580044-7-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826112127.1580044-1-cristian.dumitrescu@intel.com> References: <20220826103605.1579589-1-cristian.dumitrescu@intel.com> <20220826112127.1580044-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add the CLI command support for reading/writing direct registers. Signed-off-by: Cristian Dumitrescu --- examples/pipeline/cli.c | 228 +++++++++++++++++++++++++++++++++------- 1 file changed, 192 insertions(+), 36 deletions(-) diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c index 2e69698031..115147adfc 100644 --- a/examples/pipeline/cli.c +++ b/examples/pipeline/cli.c @@ -142,6 +142,54 @@ is_comment(char *in) return 0; } +static void +table_entry_free(struct rte_swx_table_entry *entry) +{ + if (!entry) + return; + + free(entry->key); + free(entry->key_mask); + free(entry->action_data); + free(entry); +} + +static struct rte_swx_table_entry * +parse_table_entry(struct rte_swx_ctl_pipeline *p, + char *table_name, + char **tokens, + uint32_t n_tokens) +{ + struct rte_swx_table_entry *entry; + char *line; + uint32_t i; + + /* Buffer allocation. */ + line = malloc(MAX_LINE_SIZE); + if (!line) + return NULL; + + /* Copy tokens to buffer. Since the tokens were initially part of a buffer of size + * MAX_LINE_LENGTH, it is guaranteed that putting back some of them into a buffer of the + * same size separated by a single space will not result in buffer overrun. + */ + line[0] = 0; + for (i = 0; i < n_tokens; i++) { + if (i) + strcat(line, " "); + + strcat(line, tokens[i]); + } + + /* Read the table entry from the input buffer. */ + entry = rte_swx_ctl_pipeline_table_entry_read(p, table_name, line, NULL); + + /* Buffer free. */ + free(line); + + return entry; +} + static const char cmd_mempool_help[] = "mempool \n" " buffer \n" @@ -732,18 +780,6 @@ cmd_pipeline_build(char **tokens, fclose(iospec_file); } -static void -table_entry_free(struct rte_swx_table_entry *entry) -{ - if (!entry) - return; - - free(entry->key); - free(entry->key_mask); - free(entry->action_data); - free(entry); -} - static int pipeline_table_entries_add(struct rte_swx_ctl_pipeline *p, const char *table_name, @@ -1710,7 +1746,9 @@ cmd_pipeline_abort(char **tokens, } static const char cmd_pipeline_regrd_help[] = -"pipeline regrd \n"; +"pipeline regrd \n" + "index \n" + " | table match ...\n"; static void cmd_pipeline_regrd(char **tokens, @@ -1720,18 +1758,20 @@ cmd_pipeline_regrd(char **tokens, void *obj __rte_unused) { struct rte_swx_pipeline *p; - const char *name; + struct rte_swx_ctl_pipeline *ctl; + const char *pipeline_name, *name; uint64_t value; - uint32_t idx; int status; - if (n_tokens != 5) { + if (n_tokens < 5) { snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); return; } - p = rte_swx_pipeline_find(tokens[1]); - if (!p) { + pipeline_name = tokens[1]; + p = rte_swx_pipeline_find(pipeline_name); + ctl = rte_swx_ctl_pipeline_find(pipeline_name); + if (!p || !ctl) { snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); return; } @@ -1743,22 +1783,77 @@ cmd_pipeline_regrd(char **tokens, name = tokens[3]; - if (parser_read_uint32(&idx, tokens[4])) { - snprintf(out, out_size, MSG_ARG_INVALID, "index"); + /* index. */ + if (!strcmp(tokens[4], "index")) { + uint32_t idx; + + if (n_tokens != 6) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + if (parser_read_uint32(&idx, tokens[5])) { + snprintf(out, out_size, MSG_ARG_INVALID, "index"); + return; + } + + status = rte_swx_ctl_pipeline_regarray_read(p, name, idx, &value); + if (status) { + snprintf(out, out_size, "Command failed.\n"); + return; + } + + snprintf(out, out_size, "0x%" PRIx64 "\n", value); return; } - status = rte_swx_ctl_pipeline_regarray_read(p, name, idx, &value); - if (status) { - snprintf(out, out_size, "Command failed.\n"); + /* table. */ + if (!strcmp(tokens[4], "table")) { + struct rte_swx_table_entry *entry; + char *table_name; + + if (n_tokens < 8) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + table_name = tokens[5]; + + if (strcmp(tokens[6], "match")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match"); + return; + } + + entry = parse_table_entry(ctl, table_name, &tokens[6], n_tokens - 6); + if (!entry) { + snprintf(out, out_size, "Invalid match tokens.\n"); + return; + } + + status = rte_swx_ctl_pipeline_regarray_read_with_key(p, + name, + table_name, + entry->key, + &value); + table_entry_free(entry); + if (status) { + snprintf(out, out_size, "Command failed.\n"); + return; + } + + snprintf(out, out_size, "0x%" PRIx64 "\n", value); return; } - snprintf(out, out_size, "0x%" PRIx64 "\n", value); + /* anything else. */ + snprintf(out, out_size, "Invalid token %s\n.", tokens[4]); + return; } static const char cmd_pipeline_regwr_help[] = -"pipeline regwr \n"; +"pipeline regwr value \n" + "index \n" + " | table match ...\n"; static void cmd_pipeline_regwr(char **tokens, @@ -1768,18 +1863,20 @@ cmd_pipeline_regwr(char **tokens, void *obj __rte_unused) { struct rte_swx_pipeline *p; - const char *name; - uint64_t value; - uint32_t idx; + struct rte_swx_ctl_pipeline *ctl; + const char *pipeline_name, *name; + uint64_t value = 0; int status; - if (n_tokens != 6) { + if (n_tokens < 7) { snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); return; } - p = rte_swx_pipeline_find(tokens[1]); - if (!p) { + pipeline_name = tokens[1]; + p = rte_swx_pipeline_find(pipeline_name); + ctl = rte_swx_ctl_pipeline_find(pipeline_name); + if (!p || !ctl) { snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); return; } @@ -1791,8 +1888,8 @@ cmd_pipeline_regwr(char **tokens, name = tokens[3]; - if (parser_read_uint32(&idx, tokens[4])) { - snprintf(out, out_size, MSG_ARG_INVALID, "index"); + if (strcmp(tokens[4], "value")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "value"); return; } @@ -1801,11 +1898,70 @@ cmd_pipeline_regwr(char **tokens, return; } - status = rte_swx_ctl_pipeline_regarray_write(p, name, idx, value); - if (status) { - snprintf(out, out_size, "Command failed.\n"); + /* index. */ + if (!strcmp(tokens[6], "index")) { + uint32_t idx; + + if (n_tokens != 8) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + if (parser_read_uint32(&idx, tokens[7])) { + snprintf(out, out_size, MSG_ARG_INVALID, "index"); + return; + } + + status = rte_swx_ctl_pipeline_regarray_write(p, name, idx, value); + if (status) { + snprintf(out, out_size, "Command failed.\n"); + return; + } + + snprintf(out, out_size, "0x%" PRIx64 "\n", value); return; } + + /* table. */ + if (!strcmp(tokens[6], "table")) { + struct rte_swx_table_entry *entry; + char *table_name; + + if (n_tokens < 10) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + table_name = tokens[7]; + + if (strcmp(tokens[8], "match")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match"); + return; + } + + entry = parse_table_entry(ctl, table_name, &tokens[8], n_tokens - 8); + if (!entry) { + snprintf(out, out_size, "Invalid match tokens.\n"); + return; + } + + status = rte_swx_ctl_pipeline_regarray_write_with_key(p, + name, + table_name, + entry->key, + value); + table_entry_free(entry); + if (status) { + snprintf(out, out_size, "Command failed.\n"); + return; + } + + return; + } + + /* anything else. */ + snprintf(out, out_size, "Invalid token %s\n.", tokens[6]); + return; } static const char cmd_pipeline_meter_profile_add_help[] = -- 2.34.1