From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 87B0DA0471 for ; Tue, 16 Jul 2019 14:33:44 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 61BEF2C18; Tue, 16 Jul 2019 14:33:44 +0200 (CEST) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by dpdk.org (Postfix) with ESMTP id D33FD2C18 for ; Tue, 16 Jul 2019 14:33:42 +0200 (CEST) Received: by mail-pg1-f195.google.com with SMTP id f20so148462pgj.0 for ; Tue, 16 Jul 2019 05:33:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=UqSjYonMIH+b8QmJldv7MxyoMAGR7Nm1FXoR8h5cbkg=; b=Cy6AEyP2Eo2h8V85UyYLto1vliurBghK+9yRyaFncCHTPFMsUEq9PAskSpr9HC8pKE kxELDdkdnbgA+9FyvoqmGmNg8DOcNKBq1tV18zGdGu//QK840PUyrckzsq4sUhvd8gKy cJv+hzzD1G/2ahTPTda2oFokSHPV9fg6MDhJcTYyA5cPCNkz9P82SiMIQP6ukumG+RW3 2EPHtdoT4++ZWO40eJGt2FnNtBVe1P4rJUwRRYdcYqpyjqgrohBXAdE06H1Viv1mYn2m NAWB9W+wIGtBD1taKAwOquSn4RqoCx/5V955SJ5VM7vNrknP0aOJXtnqxBg3WP0NHctJ mCQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=UqSjYonMIH+b8QmJldv7MxyoMAGR7Nm1FXoR8h5cbkg=; b=B8M3dlg6uH70xglPPz0Lkpf0x2X5BM9Vgdc/wVt4mRRezqb7+UqFriwfx2sWz6Wfmk CAzimqdQYDW2xkg8jWrAXHzpGR5ND5Fcjt2MwHZCLJCvtEOgoP0+rgz2RsS+TK3zgMmo UeVnIyha4Ld6W3d94VaNMO4fPDbHRLFMC97YbZe0IJUjuG3tDQvhf0rGD8FP+fMbpYUC uVD0yg5AJaOWZMzIFrc2gWqm/dVQB9mrX/7jy068OBLF8yODgp03L1BbSyOXZR5ezgXG JNFUbURYPC2cdn8LFLKg9YPllVczku1xcvziEewYYj9kfUQA2BDJjj/OPMj6dJM/AOOx yARQ== X-Gm-Message-State: APjAAAWgdonB9QvXw+11MrrBG6gLAYcz41MIfj2TeDEkRLHXngwcoaRL 5ABexQJB8fVT9l+RvlUYhyCrlhlD X-Google-Smtp-Source: APXvYqz1zh/Wt4E0mp1UcI24G37W3+ZRcok9bKXJgQf9kVoR8Xc6KlMXYeDOTlhxsoa+/4nduTP/og== X-Received: by 2002:a63:6f8f:: with SMTP id k137mr33274455pgc.90.1563280421853; Tue, 16 Jul 2019 05:33:41 -0700 (PDT) Received: from localhost.localdomain ([192.47.164.146]) by smtp.gmail.com with ESMTPSA id y22sm25342688pfo.39.2019.07.16.05.33.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jul 2019 05:33:41 -0700 (PDT) From: yasufum.o@gmail.com To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com Date: Tue, 16 Jul 2019 21:33:35 +0900 Message-Id: <20190716123335.40985-1-yasufum.o@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [spp] [PATCH] shared: add parsing ethdev name X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: spp-bounces@dpdk.org Sender: "spp" From: Yasufumi Ogawa This update is to add parser parse_dev_name() for the name of ethdev, such as `eth_vhost1` or `net_ring1`. By using this function, port type `VHOST` and ID `1` can be extracted from `eth_vhost1`. This parser is intended to be used in initialization of ports in secondary process in which all shared ports managed by spp_primary are initialized as PHY incorrectly even if it is not PHY type. It is because secondary expects the type of ports in spp_primary is always PHY. However, port type might be other than PHY if spp_primary is launched with `--vdev` option. By using this parser, port type and ID can be inspected in secondary. Signed-off-by: Yasufumi Ogawa --- src/shared/common.c | 66 +++++++++++++++++++++++++++++++++++++++++++++ src/shared/common.h | 17 ++++++++++++ 2 files changed, 83 insertions(+) diff --git a/src/shared/common.c b/src/shared/common.c index 55c53c0..6655f17 100644 --- a/src/shared/common.c +++ b/src/shared/common.c @@ -163,3 +163,69 @@ int set_spp_ctl_port(int s_port) spp_ctl_port = s_port; return 0; } + +/** + * Get port type and port ID from ethdev name, such as `eth_vhost1` which + * can be retrieved with rte_eth_dev_get_name_by_port(). + * In this case of `eth_vhost1`, port type is `VHOST` and port ID is `1`. + */ +int parse_dev_name(char *dev_name, int *port_type, int *port_id) +{ + char pid_str[12] = { 0 }; + int pid_len; + int dev_name_len = strlen(dev_name); + int dev_str_len; + + if (strncmp(dev_name, VDEV_PREFIX_RING, + strlen(VDEV_PREFIX_RING)) == 0) { + dev_str_len = strlen(VDEV_PREFIX_RING); + pid_len = dev_name_len - dev_str_len; + strncpy(pid_str, dev_name + strlen(VDEV_PREFIX_RING), + pid_len); + *port_id = (int)strtol(pid_str, NULL, 10); + *port_type = RING; + + } else if (strncmp(dev_name, VDEV_PREFIX_VHOST, + strlen(VDEV_PREFIX_VHOST)) == 0) { + dev_str_len = strlen(VDEV_PREFIX_VHOST); + pid_len = dev_name_len - dev_str_len; + strncpy(pid_str, dev_name + strlen(VDEV_PREFIX_VHOST), + pid_len); + *port_id = (int)strtol(pid_str, NULL, 10); + *port_type = VHOST; + + } else if (strncmp(dev_name, VDEV_PREFIX_PCAP, + strlen(VDEV_PREFIX_PCAP)) == 0) { + dev_str_len = strlen(VDEV_PREFIX_PCAP); + pid_len = dev_name_len - dev_str_len; + strncpy(pid_str, dev_name + strlen(VDEV_PREFIX_PCAP), + pid_len); + *port_id = (int)strtol(pid_str, NULL, 10); + *port_type = PCAP; + + } else if (strncmp(dev_name, VDEV_PREFIX_TAP, + strlen(VDEV_PREFIX_TAP)) == 0) { + dev_str_len = strlen(VDEV_PREFIX_TAP); + pid_len = dev_name_len - dev_str_len; + strncpy(pid_str, dev_name + strlen(VDEV_PREFIX_TAP), + pid_len); + *port_id = (int)strtol(pid_str, NULL, 10); + *port_type = TAP; + + } else if (strncmp(dev_name, VDEV_PREFIX_NULL, + strlen(VDEV_PREFIX_NULL)) == 0) { + dev_str_len = strlen(VDEV_PREFIX_NULL); + pid_len = dev_name_len - dev_str_len; + strncpy(pid_str, dev_name + strlen(VDEV_PREFIX_NULL), + pid_len); + *port_id = (int)strtol(pid_str, NULL, 10); + *port_type = PCAP; + + /* TODO(yasufum) add checking invalid port type and return -1 */ + } else { + *port_id = 0; + *port_type = PHY; + } + + return 0; +} diff --git a/src/shared/common.h b/src/shared/common.h index 78d2520..d51d6df 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -43,6 +43,13 @@ #define RTE_MP_RX_DESC_DEFAULT 512 #define RTE_MP_TX_DESC_DEFAULT 512 +#define VDEV_PREFIX_RING "net_ring" +#define VDEV_PREFIX_VHOST "eth_vhost" +#define VDEV_PREFIX_PCAP "net_pcap" +#define VDEV_PREFIX_TAP "net_tap" +#define VDEV_PREFIX_NULL "eth_null" + + /* Command. */ enum cmd_type { STOP, @@ -82,6 +89,7 @@ enum port_type { VHOST, PCAP, NULLPMD, + TAP, UNDEF, }; @@ -172,4 +180,13 @@ int get_spp_ctl_port(void); */ int set_spp_ctl_port(int s_port); +/** + * Get port type and port ID from ethdev name, such as `eth_vhost1` which + * can be retrieved with rte_eth_dev_get_name_by_port(). + * In this case of `eth_vhost1`, port type is `VHOST` and port ID is `1`. + * + * @return 0 if succeeded, or -1 if failed. + */ +int parse_dev_name(char *dev_name, int *port_type, int *port_id); + #endif -- 2.17.1