From: beilei.xing@intel.com
To: jingjing.wu@intel.com, qi.z.zhang@intel.com
Cc: dev@dpdk.org, Beilei Xing <beilei.xing@intel.com>
Subject: [PATCH 2/3] net/idpf: remove req vports from adapter
Date: Thu, 8 Dec 2022 07:27:24 +0000 [thread overview]
Message-ID: <20221208072725.32434-3-beilei.xing@intel.com> (raw)
In-Reply-To: <20221208072725.32434-1-beilei.xing@intel.com>
From: Jingjing Wu <jingjing.wu@intel.com>
This patch refines idpf_adapter structure by removing req_vports.
Signed-off-by: Jingjing Wu <jingjing.wu@intel.com>
Signed-off-by: Beilei Xing <beilei.xing@intel.com>
---
drivers/net/idpf/idpf_ethdev.c | 79 ++++++++++++++++++----------------
drivers/net/idpf/idpf_ethdev.h | 9 +++-
2 files changed, 49 insertions(+), 39 deletions(-)
diff --git a/drivers/net/idpf/idpf_ethdev.c b/drivers/net/idpf/idpf_ethdev.c
index d8b7b069cf..f7b3f8f515 100644
--- a/drivers/net/idpf/idpf_ethdev.c
+++ b/drivers/net/idpf/idpf_ethdev.c
@@ -619,29 +619,30 @@ idpf_dev_close(struct rte_eth_dev *dev)
}
static int
-insert_value(struct idpf_adapter *adapter, uint16_t id)
+insert_value(struct idpf_devargs *devargs, uint16_t id)
{
uint16_t i;
- for (i = 0; i < adapter->req_vport_nb; i++) {
- if (adapter->req_vports[i] == id)
+ /* ignore duplicate */
+ for (i = 0; i < devargs->req_vport_nb; i++) {
+ if (devargs->req_vports[i] == id)
return 0;
}
- if (adapter->req_vport_nb >= RTE_DIM(adapter->req_vports)) {
+ if (devargs->req_vport_nb >= RTE_DIM(devargs->req_vports)) {
PMD_INIT_LOG(ERR, "Total vport number can't be > %d",
IDPF_MAX_VPORT_NUM);
return -EINVAL;
}
- adapter->req_vports[adapter->req_vport_nb] = id;
- adapter->req_vport_nb++;
+ devargs->req_vports[devargs->req_vport_nb] = id;
+ devargs->req_vport_nb++;
return 0;
}
static const char *
-parse_range(const char *value, struct idpf_adapter *adapter)
+parse_range(const char *value, struct idpf_devargs *devargs)
{
uint16_t lo, hi, i;
int n = 0;
@@ -652,13 +653,13 @@ parse_range(const char *value, struct idpf_adapter *adapter)
if (result == 1) {
if (lo >= IDPF_MAX_VPORT_NUM)
return NULL;
- if (insert_value(adapter, lo) != 0)
+ if (insert_value(devargs, lo) != 0)
return NULL;
} else if (result == 2) {
if (lo > hi || hi >= IDPF_MAX_VPORT_NUM)
return NULL;
for (i = lo; i <= hi; i++) {
- if (insert_value(adapter, i) != 0)
+ if (insert_value(devargs, i) != 0)
return NULL;
}
} else {
@@ -671,17 +672,16 @@ parse_range(const char *value, struct idpf_adapter *adapter)
static int
parse_vport(const char *key, const char *value, void *args)
{
- struct idpf_adapter *adapter = args;
+ struct idpf_devargs *devargs = args;
const char *pos = value;
- int i;
- adapter->req_vport_nb = 0;
+ devargs->req_vport_nb = 0;
if (*pos == '[')
pos++;
while (1) {
- pos = parse_range(pos, adapter);
+ pos = parse_range(pos, devargs);
if (pos == NULL) {
PMD_INIT_LOG(ERR, "invalid value:\"%s\" for key:\"%s\", ",
value, key);
@@ -698,21 +698,6 @@ parse_vport(const char *key, const char *value, void *args)
return -EINVAL;
}
- if (adapter->cur_vport_nb + adapter->req_vport_nb >
- IDPF_MAX_VPORT_NUM) {
- PMD_INIT_LOG(ERR, "Total vport number can't be > %d",
- IDPF_MAX_VPORT_NUM);
- return -EINVAL;
- }
-
- for (i = 0; i < adapter->req_vport_nb; i++) {
- if (adapter->cur_vports & RTE_BIT32(adapter->req_vports[i])) {
- PMD_INIT_LOG(ERR, "Vport %d has been created",
- adapter->req_vports[i]);
- return -EINVAL;
- }
- }
-
return 0;
}
@@ -738,13 +723,14 @@ parse_bool(const char *key, const char *value, void *args)
}
static int
-idpf_parse_devargs(struct rte_pci_device *pci_dev, struct idpf_adapter *adapter)
+idpf_parse_devargs(struct rte_pci_device *pci_dev, struct idpf_adapter *adapter,
+ struct idpf_devargs *idpf_args)
{
struct rte_devargs *devargs = pci_dev->device.devargs;
struct rte_kvargs *kvlist;
- int ret;
+ int i, ret;
- adapter->req_vport_nb = 0;
+ idpf_args->req_vport_nb = 0;
if (devargs == NULL)
return 0;
@@ -755,8 +741,26 @@ idpf_parse_devargs(struct rte_pci_device *pci_dev, struct idpf_adapter *adapter)
return -EINVAL;
}
+ /* check parsed devargs */
+ if (adapter->cur_vport_nb + idpf_args->req_vport_nb >
+ IDPF_MAX_VPORT_NUM) {
+ PMD_INIT_LOG(ERR, "Total vport number can't be > %d",
+ IDPF_MAX_VPORT_NUM);
+ ret = -EINVAL;
+ goto bail;
+ }
+
+ for (i = 0; i < idpf_args->req_vport_nb; i++) {
+ if (adapter->cur_vports & RTE_BIT32(idpf_args->req_vports[i])) {
+ PMD_INIT_LOG(ERR, "Vport %d has been created",
+ idpf_args->req_vports[i]);
+ ret = -EINVAL;
+ goto bail;
+ }
+ }
+
ret = rte_kvargs_process(kvlist, IDPF_VPORT, &parse_vport,
- adapter);
+ idpf_args);
if (ret != 0)
goto bail;
@@ -1123,6 +1127,7 @@ idpf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
{
struct idpf_vport_param vport_param;
struct idpf_adapter *adapter;
+ struct idpf_devargs devargs;
char name[RTE_ETH_NAME_MAX_LEN];
int i, retval;
bool first_probe = false;
@@ -1154,13 +1159,13 @@ idpf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
rte_spinlock_unlock(&idpf_adapter_lock);
}
- retval = idpf_parse_devargs(pci_dev, adapter);
+ retval = idpf_parse_devargs(pci_dev, adapter, &devargs);
if (retval != 0) {
PMD_INIT_LOG(ERR, "Failed to parse private devargs");
goto err;
}
- if (adapter->req_vport_nb == 0) {
+ if (devargs.req_vport_nb == 0) {
/* If no vport devarg, create vport 0 by default. */
vport_param.adapter = adapter;
vport_param.devarg_id = 0;
@@ -1178,9 +1183,9 @@ idpf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
if (retval != 0)
PMD_DRV_LOG(ERR, "Failed to create default vport 0");
} else {
- for (i = 0; i < adapter->req_vport_nb; i++) {
+ for (i = 0; i < devargs.req_vport_nb; i++) {
vport_param.adapter = adapter;
- vport_param.devarg_id = adapter->req_vports[i];
+ vport_param.devarg_id = devargs.req_vports[i];
vport_param.idx = idpf_vport_idx_alloc(adapter);
if (vport_param.idx == IDPF_INVALID_VPORT_IDX) {
PMD_INIT_LOG(ERR, "No space for vport %u", vport_param.devarg_id);
@@ -1188,7 +1193,7 @@ idpf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
}
snprintf(name, sizeof(name), "idpf_%s_vport_%d",
pci_dev->device.name,
- adapter->req_vports[i]);
+ devargs.req_vports[i]);
retval = rte_eth_dev_create(&pci_dev->device, name,
sizeof(struct idpf_vport),
NULL, NULL, idpf_dev_vport_init,
diff --git a/drivers/net/idpf/idpf_ethdev.h b/drivers/net/idpf/idpf_ethdev.h
index c236cc8f16..bf37d5184c 100644
--- a/drivers/net/idpf/idpf_ethdev.h
+++ b/drivers/net/idpf/idpf_ethdev.h
@@ -137,6 +137,12 @@ struct idpf_vport {
bool stopped;
};
+/* Struct used when parse driver specific devargs */
+struct idpf_devargs {
+ uint16_t req_vports[IDPF_MAX_VPORT_NUM];
+ uint16_t req_vport_nb;
+};
+
struct idpf_adapter {
TAILQ_ENTRY(idpf_adapter) next;
struct idpf_hw hw;
@@ -154,8 +160,7 @@ struct idpf_adapter {
struct idpf_vport **vports;
uint16_t max_vport_nb;
- uint16_t req_vports[IDPF_MAX_VPORT_NUM];
- uint16_t req_vport_nb;
+
uint16_t cur_vports; /* bit mask of created vport */
uint16_t cur_vport_nb;
--
2.26.2
next prev parent reply other threads:[~2022-12-08 7:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-08 7:27 [PATCH 0/3] net/idpf: code refine beilei.xing
2022-12-08 7:27 ` [PATCH 1/3] net/idpf: remove vport req and recv info from adapter beilei.xing
2022-12-08 7:27 ` beilei.xing [this message]
2022-12-08 7:27 ` [PATCH 3/3] net/idpf: fix splitq xmit free beilei.xing
2023-01-06 9:04 ` [PATCH v2 0/5] net/idpf: code refine beilei.xing
2023-01-06 9:04 ` [PATCH v2 1/5] net/idpf: remove vport req and recv info from adapter beilei.xing
2023-01-06 9:04 ` [PATCH v2 2/5] net/idpf: remove req vports " beilei.xing
2023-01-06 9:04 ` [PATCH v2 3/5] net/idpf: fix splitq xmit free beilei.xing
2023-01-06 9:05 ` [PATCH v2 4/5] net/idpf: fix driver init symbols beilei.xing
2023-01-06 9:05 ` [PATCH v2 5/5] net/idpf: refine MTU setting beilei.xing
2023-01-16 7:59 ` [PATCH v2 0/5] net/idpf: code refine Zhang, Qi Z
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221208072725.32434-3-beilei.xing@intel.com \
--to=beilei.xing@intel.com \
--cc=dev@dpdk.org \
--cc=jingjing.wu@intel.com \
--cc=qi.z.zhang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).