From: Chaoyong He <chaoyong.he@corigine.com>
To: dev@dpdk.org
Cc: oss-drivers@corigine.com, Long Wu <long.wu@corigine.com>,
Peng Zhang <peng.zhang@corigine.com>,
Chaoyong He <chaoyong.he@corigine.com>
Subject: [PATCH v5 11/14] net/nfp: support bond member notification
Date: Tue, 26 Dec 2023 10:37:42 +0800 [thread overview]
Message-ID: <20231226023745.3144143-12-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20231226023745.3144143-1-chaoyong.he@corigine.com>
From: Long Wu <long.wu@corigine.com>
A NFP representor port can receive a bond notification. Then driver
will parse this notification into one of these two events:
1. Bonding port configuration may have changed.
This includes creation of a bonding port, removal/addition of
a member port, changing the bond mode, etc.
2. Bonding port is deleted.
Signed-off-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
---
drivers/net/nfp/flower/nfp_flower_bond.c | 183 +++++++++++++++++-
drivers/net/nfp/flower/nfp_flower_bond.h | 2 +
.../net/nfp/flower/nfp_flower_representor.c | 21 ++
3 files changed, 205 insertions(+), 1 deletion(-)
diff --git a/drivers/net/nfp/flower/nfp_flower_bond.c b/drivers/net/nfp/flower/nfp_flower_bond.c
index c814c0d4ea..523e0025ad 100644
--- a/drivers/net/nfp/flower/nfp_flower_bond.c
+++ b/drivers/net/nfp/flower/nfp_flower_bond.c
@@ -46,6 +46,39 @@ nfp_flower_bond_increment_version(struct nfp_flower_bond *nfp_bond)
nfp_bond->batch_ver += 2;
}
+static void
+nfp_flower_bond_group_id_clear(struct nfp_flower_bond *nfp_bond,
+ uint32_t id_clear)
+{
+ bool *group_id_map = nfp_bond->group_id_map;
+
+ if (id_clear >= NFP_FL_BOND_GROUP_MAX || id_clear < NFP_FL_BOND_GROUP_MIN) {
+ PMD_DRV_LOG(ERR, "Try to clear invalid group id %u.", id_clear);
+ return;
+ }
+
+ if (group_id_map[id_clear])
+ group_id_map[id_clear] = false;
+}
+
+static int
+nfp_flower_bond_group_id_get(struct nfp_flower_bond *nfp_bond,
+ uint32_t *id_ret)
+{
+ uint32_t id;
+ bool *group_id_map = nfp_bond->group_id_map;
+
+ for (id = NFP_FL_BOND_GROUP_MIN; id < NFP_FL_BOND_GROUP_MAX; id++) {
+ if (!group_id_map[id]) {
+ group_id_map[id] = true;
+ *id_ret = id;
+ return 0;
+ }
+ }
+
+ return -ENOSPC;
+}
+
static enum nfp_flower_bond_batch
nfp_flower_bond_remove_node(struct nfp_flower_bond *nfp_bond,
struct nfp_bond_group *entry,
@@ -65,6 +98,7 @@ nfp_flower_bond_remove_node(struct nfp_flower_bond *nfp_bond,
entry->offloaded = false;
if (entry->to_destroy) {
+ nfp_flower_bond_group_id_clear(nfp_bond, entry->group_id);
LIST_REMOVE(entry, next);
rte_free(entry);
}
@@ -139,6 +173,7 @@ nfp_flower_bond_cleanup(struct nfp_app_fw_flower *app_fw_flower)
pthread_mutex_lock(&nfp_bond->mutex);
LIST_FOREACH(entry, &nfp_bond->group_list, next) {
+ nfp_flower_bond_group_id_clear(nfp_bond, entry->group_id);
LIST_REMOVE(entry, next);
rte_free(entry);
}
@@ -271,16 +306,162 @@ nfp_flower_bond_change_linkstatus_event(struct nfp_flower_bond *nfp_bond,
*bond_port_flags |= NFP_FL_BOND_PORT_CHANGED;
}
+static struct nfp_bond_group *
+nfp_flower_bond_group_create(struct nfp_flower_bond *nfp_bond,
+ struct rte_eth_dev *bond_dev)
+{
+ uint32_t id;
+ unsigned int numa_node;
+ struct nfp_bond_group *group = NULL;
+
+ if (nfp_flower_bond_group_id_get(nfp_bond, &id) < 0)
+ return NULL;
+
+ numa_node = rte_socket_id();
+
+ group = rte_zmalloc_socket(NULL, sizeof(struct nfp_bond_group),
+ RTE_CACHE_LINE_SIZE, numa_node);
+ if (group == NULL) {
+ PMD_DRV_LOG(ERR, "Unable malloc memory for nfp bond group");
+ nfp_flower_bond_group_id_clear(nfp_bond, id);
+ return NULL;
+ }
+
+ group->group_id = id;
+ group->main_dev = bond_dev;
+ group->dirty = true;
+ group->offloaded = false;
+ group->to_remove = false;
+ group->to_destroy = false;
+ group->member_cnt = 0;
+ group->group_inst = ++nfp_bond->global_inst;
+ LIST_INSERT_HEAD(&nfp_bond->group_list, group, next);
+
+ return group;
+}
+
+static int
+nfp_flower_bond_changeupper_event(struct nfp_flower_bond *nfp_bond,
+ struct rte_eth_dev *bond_dev)
+{
+ uint32_t i;
+ uint16_t port_id;
+ bool can_offload = true;
+ uint16_t nfp_member_count;
+ struct rte_eth_dev *eth_dev;
+ struct nfp_bond_group *group;
+ struct bond_dev_private *internals;
+ struct nfp_flower_representor *repr;
+ struct nfp_app_fw_flower *app_flower;
+
+ internals = bond_dev->data->dev_private;
+ app_flower = nfp_bond->app_fw_flower;
+ nfp_member_count = 0;
+
+ for (i = 0; i < internals->member_count; i++) {
+ port_id = internals->members[i].port_id;
+ eth_dev = &rte_eth_devices[port_id];
+ if (!nfp_flower_is_phy_repr(eth_dev)) {
+ can_offload = false;
+ break;
+ }
+
+ repr = eth_dev->data->dev_private;
+
+ if (repr->app_fw_flower != app_flower) {
+ can_offload = false;
+ break;
+ }
+
+ if (internals->current_primary_port == port_id ||
+ internals->mode != BONDING_MODE_ACTIVE_BACKUP)
+ nfp_member_count++;
+ }
+
+ if (internals != NULL &&
+ internals->mode != BONDING_MODE_ACTIVE_BACKUP &&
+ ((internals->mode != BONDING_MODE_BALANCE &&
+ internals->mode != BONDING_MODE_8023AD) ||
+ internals->balance_xmit_policy != BALANCE_XMIT_POLICY_LAYER34)) {
+ can_offload = false;
+ PMD_DRV_LOG(WARNING, "Unable to offload mode %u hash %u.",
+ internals->mode,
+ internals->balance_xmit_policy);
+ }
+
+ pthread_mutex_lock(&nfp_bond->mutex);
+
+ group = nfp_flower_bond_find_group(nfp_bond, bond_dev);
+ if (nfp_member_count == 0 || !can_offload) {
+ if (group != NULL && group->offloaded)
+ /* Set remove flag */
+ group->to_remove = true;
+
+ pthread_mutex_unlock(&nfp_bond->mutex);
+ return 0;
+ }
+
+ if (group == NULL) {
+ group = nfp_flower_bond_group_create(nfp_bond, bond_dev);
+ if (group == NULL) {
+ pthread_mutex_unlock(&nfp_bond->mutex);
+ return -1;
+ }
+ }
+
+ group->dirty = true;
+ group->member_cnt = nfp_member_count;
+ group->to_remove = false;
+
+ pthread_mutex_unlock(&nfp_bond->mutex);
+
+ return 0;
+}
+
+static void
+nfp_flower_bond_group_delete(struct nfp_flower_bond *nfp_bond,
+ struct rte_eth_dev *bond_dev)
+{
+ struct nfp_bond_group *group;
+
+ pthread_mutex_lock(&nfp_bond->mutex);
+
+ group = nfp_flower_bond_find_group(nfp_bond, bond_dev);
+ if (group == NULL) {
+ pthread_mutex_unlock(&nfp_bond->mutex);
+ PMD_DRV_LOG(WARNING, "Untracked bond got unregistered %s",
+ bond_dev->device->name);
+ return;
+ }
+
+ group->to_remove = true;
+ group->to_destroy = true;
+
+ pthread_mutex_unlock(&nfp_bond->mutex);
+}
+
int
nfp_flower_bond_event_handle(struct nfp_flower_bond *nfp_bond,
struct rte_eth_dev *bond_dev,
struct rte_eth_dev *nfp_dev,
enum nfp_flower_bond_event event)
{
+ int ret = 0;
+
switch (event) {
+ case NFP_FLOWER_CHANGEUPPER:
+ ret = nfp_flower_bond_changeupper_event(nfp_bond, bond_dev);
+ if (ret != 0) {
+ PMD_DRV_LOG(ERR, "Change upper event can not work.");
+ return ret;
+ }
+ break;
case NFP_FLOWER_CHANGELINKSTATUS:
nfp_flower_bond_change_linkstatus_event(nfp_bond, bond_dev, nfp_dev);
break;
+ case NFP_FLOWER_UNREGISTER:
+ nfp_flower_bond_group_delete(nfp_bond, bond_dev);
+ break;
default:
PMD_DRV_LOG(ERR, "Invalid bond offload event.");
return -1;
@@ -288,7 +469,7 @@ nfp_flower_bond_event_handle(struct nfp_flower_bond *nfp_bond,
nfp_flower_bond_do_work(nfp_bond);
- return 0;
+ return ret;
}
enum nfp_flower_bond_batch
diff --git a/drivers/net/nfp/flower/nfp_flower_bond.h b/drivers/net/nfp/flower/nfp_flower_bond.h
index 80f56a6780..f73589265f 100644
--- a/drivers/net/nfp/flower/nfp_flower_bond.h
+++ b/drivers/net/nfp/flower/nfp_flower_bond.h
@@ -109,6 +109,8 @@ struct nfp_flower_bond {
uint32_t global_inst;
/** Incremented for each config packet sent */
uint32_t pkt_num;
+ /** ID of bond group in driver, true is used */
+ bool group_id_map[NFP_FL_BOND_GROUP_MAX];
/** Pointer to the flower app */
struct nfp_app_fw_flower *app_fw_flower;
};
diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c
index 2810a7a271..43106da90e 100644
--- a/drivers/net/nfp/flower/nfp_flower_representor.c
+++ b/drivers/net/nfp/flower/nfp_flower_representor.c
@@ -390,6 +390,25 @@ nfp_flower_repr_dev_close(struct rte_eth_dev *dev)
return 0;
}
+static int
+nfp_flower_repr_bond_notify_member(struct rte_eth_dev *dev,
+ struct rte_eth_dev *bond_dev)
+{
+ struct nfp_flower_representor *repr;
+ enum nfp_flower_bond_event event = NFP_FLOWER_CHANGEUPPER;
+
+ if (!nfp_flower_bond_all_member_are_phyrepr(bond_dev))
+ event = NFP_FLOWER_UNREGISTER;
+
+ repr = dev->data->dev_private;
+
+ if (nfp_flower_support_bond_offload(repr->app_fw_flower))
+ return nfp_flower_bond_event_handle(repr->app_fw_flower->nfp_bond,
+ bond_dev, dev, event);
+
+ return 0;
+}
+
static const struct eth_dev_ops nfp_flower_pf_repr_dev_ops = {
.dev_infos_get = nfp_flower_repr_dev_infos_get,
@@ -437,6 +456,8 @@ static const struct eth_dev_ops nfp_flower_repr_dev_ops = {
.flow_ops_get = nfp_flow_ops_get,
.mtr_ops_get = nfp_net_mtr_ops_get,
+
+ .bond_notify_member = nfp_flower_repr_bond_notify_member,
};
static uint32_t
--
2.39.1
next prev parent reply other threads:[~2023-12-26 2:39 UTC|newest]
Thread overview: 79+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-05 2:40 [PATCH 0/8] Enhance the bond framework to support offload Chaoyong He
2023-10-05 2:40 ` [PATCH 1/8] ethdev: add member notification for bonding port Chaoyong He
2023-10-05 2:40 ` [PATCH 2/8] ethdev: add API to get hardware creation of " Chaoyong He
2023-10-05 2:40 ` [PATCH 3/8] net/bonding: modify interface comment format Chaoyong He
2023-10-05 2:40 ` [PATCH 4/8] net/bonding: add bonding port arguments Chaoyong He
2023-10-05 2:40 ` [PATCH 5/8] net/bonding: support add port by data name Chaoyong He
2023-10-05 2:40 ` [PATCH 6/8] net/bonding: create new rte flow header file Chaoyong He
2023-10-05 2:40 ` [PATCH 7/8] net/bonding: support checking valid bonding port ID Chaoyong He
2023-10-05 2:40 ` [PATCH 8/8] net/bonding: add commands for bonding port notification Chaoyong He
2023-10-07 1:34 ` [PATCH v2 0/8] Enhance the bond framework to support offload Chaoyong He
2023-10-07 1:34 ` [PATCH v2 1/8] ethdev: add member notification for bonding port Chaoyong He
2023-10-07 15:49 ` Stephen Hemminger
2023-10-08 1:37 ` Chaoyong He
2023-10-07 1:34 ` [PATCH v2 2/8] ethdev: add API to get hardware creation of " Chaoyong He
2023-10-07 1:34 ` [PATCH v2 3/8] net/bonding: modify interface comment format Chaoyong He
2023-10-07 1:34 ` [PATCH v2 4/8] net/bonding: add bonding port arguments Chaoyong He
2023-10-07 1:34 ` [PATCH v2 5/8] net/bonding: support add port by data name Chaoyong He
2023-10-07 1:34 ` [PATCH v2 6/8] net/bonding: create new rte flow header file Chaoyong He
2023-10-07 1:34 ` [PATCH v2 7/8] net/bonding: support checking valid bonding port ID Chaoyong He
2023-10-07 1:34 ` [PATCH v2 8/8] net/bonding: add commands for bonding port notification Chaoyong He
2023-10-08 1:50 ` [PATCH v3 0/8] Enhance the bond framework to support offload Chaoyong He
2023-10-08 1:50 ` [PATCH v3 1/8] ethdev: add member notification for bonding port Chaoyong He
2023-10-08 2:49 ` lihuisong (C)
2023-10-09 3:11 ` 回复: " Long Wu
2023-10-17 8:27 ` lihuisong (C)
2023-10-18 2:16 ` Chaoyong He
2023-10-08 1:50 ` [PATCH v3 2/8] ethdev: add API to get hardware creation of " Chaoyong He
2023-10-08 1:50 ` [PATCH v3 3/8] net/bonding: modify interface comment format Chaoyong He
2023-10-08 1:50 ` [PATCH v3 4/8] net/bonding: add bonding port arguments Chaoyong He
2023-10-08 1:50 ` [PATCH v3 5/8] net/bonding: support add port by data name Chaoyong He
2023-10-08 1:50 ` [PATCH v3 6/8] net/bonding: create new rte flow header file Chaoyong He
2023-10-08 1:50 ` [PATCH v3 7/8] net/bonding: support checking valid bonding port ID Chaoyong He
2023-10-17 8:33 ` lihuisong (C)
2023-10-17 9:25 ` Chaoyong He
2023-10-17 11:34 ` lihuisong (C)
2023-10-18 1:53 ` Chaoyong He
2023-10-17 15:56 ` Stephen Hemminger
2023-10-08 1:50 ` [PATCH v3 8/8] net/bonding: add commands for bonding port notification Chaoyong He
2023-10-13 2:22 ` [PATCH v3 0/8] Enhance the bond framework to support offload Chaoyong He
2023-10-13 12:53 ` Ferruh Yigit
2023-10-18 7:48 ` [PATCH v4 0/6] " Chaoyong He
2023-10-18 7:48 ` [PATCH v4 1/6] ethdev: add member notification for bonding port Chaoyong He
2023-10-18 7:48 ` [PATCH v4 2/6] ethdev: add API to get hardware creation of " Chaoyong He
2023-10-18 7:48 ` [PATCH v4 3/6] net/bonding: add bonding port arguments Chaoyong He
2023-10-18 7:48 ` [PATCH v4 4/6] net/bonding: support add port by data name Chaoyong He
2023-10-18 7:48 ` [PATCH v4 5/6] net/bonding: support checking valid bonding port ID Chaoyong He
2023-10-18 7:48 ` [PATCH v4 6/6] net/bonding: add commands for bonding port notification Chaoyong He
2023-11-15 16:01 ` [PATCH v4 0/6] Enhance the bond framework to support offload Ferruh Yigit
2023-11-16 1:45 ` Chaoyong He
2023-12-26 2:37 ` [PATCH v5 00/14] " Chaoyong He
2023-12-26 2:37 ` [PATCH v5 01/14] ethdev: add member notification for bonding port Chaoyong He
2023-12-26 2:37 ` [PATCH v5 02/14] ethdev: add API to get firmware creation of " Chaoyong He
2023-12-26 2:37 ` [PATCH v5 03/14] net/bonding: add bonding port arguments Chaoyong He
2023-12-26 2:37 ` [PATCH v5 04/14] net/bonding: support add port by data name Chaoyong He
2023-12-26 2:37 ` [PATCH v5 05/14] net/bonding: support checking valid bonding port ID Chaoyong He
2023-12-26 2:37 ` [PATCH v5 06/14] net/bonding: add commands for bonding port notification Chaoyong He
2023-12-26 2:37 ` [PATCH v5 07/14] net/bonding: create new rte flow header file Chaoyong He
2023-12-26 2:37 ` [PATCH v5 08/14] net/nfp: add bond firmware creation initialization Chaoyong He
2023-12-26 2:37 ` [PATCH v5 09/14] net/nfp: reset bond configuration of firmware Chaoyong He
2023-12-26 2:37 ` [PATCH v5 10/14] net/nfp: handle link event of bond firmware creation Chaoyong He
2023-12-26 2:37 ` Chaoyong He [this message]
2023-12-26 2:37 ` [PATCH v5 12/14] net/nfp: handle bond packets from firmware Chaoyong He
2023-12-26 2:37 ` [PATCH v5 13/14] net/nfp: support getting bond firmware creation Chaoyong He
2023-12-26 2:37 ` [PATCH v5 14/14] net/nfp: support offloading bond-flow Chaoyong He
2023-12-26 7:28 ` [PATCH v6 00/14] Enhance the bond framework to support offload Chaoyong He
2023-12-26 7:28 ` [PATCH v6 01/14] ethdev: add member notification for bonding port Chaoyong He
2023-12-26 7:28 ` [PATCH v6 02/14] ethdev: add API to get firmware creation of " Chaoyong He
2023-12-26 7:28 ` [PATCH v6 03/14] net/bonding: add bonding port arguments Chaoyong He
2023-12-26 7:28 ` [PATCH v6 04/14] net/bonding: support add port by data name Chaoyong He
2023-12-26 7:28 ` [PATCH v6 05/14] net/bonding: support checking valid bonding port ID Chaoyong He
2023-12-26 7:28 ` [PATCH v6 06/14] net/bonding: add commands for bonding port notification Chaoyong He
2023-12-26 7:28 ` [PATCH v6 07/14] net/bonding: create new rte flow header file Chaoyong He
2023-12-26 7:28 ` [PATCH v6 08/14] net/nfp: add bond firmware creation initialization Chaoyong He
2023-12-26 7:28 ` [PATCH v6 09/14] net/nfp: reset bond configuration of firmware Chaoyong He
2023-12-26 7:28 ` [PATCH v6 10/14] net/nfp: handle link event of bond firmware creation Chaoyong He
2023-12-26 7:28 ` [PATCH v6 11/14] net/nfp: support bond member notification Chaoyong He
2023-12-26 7:28 ` [PATCH v6 12/14] net/nfp: handle bond packets from firmware Chaoyong He
2023-12-26 7:28 ` [PATCH v6 13/14] net/nfp: support getting bond firmware creation Chaoyong He
2023-12-26 7:28 ` [PATCH v6 14/14] net/nfp: support offloading bond-flow Chaoyong He
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=20231226023745.3144143-12-chaoyong.he@corigine.com \
--to=chaoyong.he@corigine.com \
--cc=dev@dpdk.org \
--cc=long.wu@corigine.com \
--cc=oss-drivers@corigine.com \
--cc=peng.zhang@corigine.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).