* [PATCH 1/2] net/nfp: support getting pause frame switch mode
2023-11-02 6:16 [PATCH 0/2] add support of RX/TX pause frame switch Chaoyong He
@ 2023-11-02 6:16 ` Chaoyong He
2023-11-02 6:16 ` [PATCH 2/2] net/nfp: support setting " Chaoyong He
2023-11-02 20:39 ` [PATCH 0/2] add support of RX/TX pause frame switch Ferruh Yigit
2 siblings, 0 replies; 4+ messages in thread
From: Chaoyong He @ 2023-11-02 6:16 UTC (permalink / raw)
To: dev; +Cc: oss-drivers, Zerun Fu, Long Wu, Peng Zhang, Chaoyong He
From: Zerun Fu <zerun.fu@corigine.com>
Add support for querying current RX/TX pause frame
switch mode from the device.
Signed-off-by: Zerun Fu <zerun.fu@corigine.com>
Reviewed-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/nfp_ethdev.c | 1 +
drivers/net/nfp/nfp_net_common.c | 41 +++++++++++++++++++++++++++
drivers/net/nfp/nfp_net_common.h | 2 ++
drivers/net/nfp/nfpcore/nfp_nsp.h | 2 ++
drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 11 +++++++
5 files changed, 57 insertions(+)
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 4fae2e5540..452e16e126 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -428,6 +428,7 @@ static const struct eth_dev_ops nfp_net_eth_dev_ops = {
.udp_tunnel_port_add = nfp_udp_tunnel_port_add,
.udp_tunnel_port_del = nfp_udp_tunnel_port_del,
.fw_version_get = nfp_net_firmware_version_get,
+ .flow_ctrl_get = nfp_net_flow_ctrl_get,
};
static inline void
diff --git a/drivers/net/nfp/nfp_net_common.c b/drivers/net/nfp/nfp_net_common.c
index 4efcdff76f..44b2d6dd4f 100644
--- a/drivers/net/nfp/nfp_net_common.c
+++ b/drivers/net/nfp/nfp_net_common.c
@@ -2073,3 +2073,44 @@ nfp_net_stop(struct rte_eth_dev *dev)
return 0;
}
+
+static enum rte_eth_fc_mode
+nfp_net_get_pause_mode(struct nfp_eth_table_port *eth_port)
+{
+ enum rte_eth_fc_mode mode;
+
+ if (eth_port->rx_pause_enabled) {
+ if (eth_port->tx_pause_enabled)
+ mode = RTE_ETH_FC_FULL;
+ else
+ mode = RTE_ETH_FC_RX_PAUSE;
+ } else {
+ if (eth_port->tx_pause_enabled)
+ mode = RTE_ETH_FC_TX_PAUSE;
+ else
+ mode = RTE_ETH_FC_NONE;
+ }
+
+ return mode;
+}
+
+int
+nfp_net_flow_ctrl_get(struct rte_eth_dev *dev,
+ struct rte_eth_fc_conf *fc_conf)
+{
+ struct nfp_net_hw *net_hw;
+ struct nfp_eth_table *nfp_eth_table;
+ struct nfp_eth_table_port *eth_port;
+
+ net_hw = nfp_net_get_hw(dev);
+ if (net_hw->pf_dev == NULL)
+ return -EINVAL;
+
+ nfp_eth_table = net_hw->pf_dev->nfp_eth_table;
+ eth_port = &nfp_eth_table->ports[dev->data->port_id];
+
+ /* Currently only RX/TX switch are supported */
+ fc_conf->mode = nfp_net_get_pause_mode(eth_port);
+
+ return 0;
+}
diff --git a/drivers/net/nfp/nfp_net_common.h b/drivers/net/nfp/nfp_net_common.h
index 1f9001c81d..5a65d166e0 100644
--- a/drivers/net/nfp/nfp_net_common.h
+++ b/drivers/net/nfp/nfp_net_common.h
@@ -238,6 +238,8 @@ int nfp_net_firmware_version_get(struct rte_eth_dev *dev, char *fw_version, size
bool nfp_net_is_valid_nfd_version(struct nfp_net_fw_ver version);
struct nfp_net_hw *nfp_net_get_hw(const struct rte_eth_dev *dev);
int nfp_net_stop(struct rte_eth_dev *dev);
+int nfp_net_flow_ctrl_get(struct rte_eth_dev *dev,
+ struct rte_eth_fc_conf *fc_conf);
#define NFP_PRIV_TO_APP_FW_NIC(app_fw_priv)\
((struct nfp_app_fw_nic *)app_fw_priv)
diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h
index fe52dffeb7..dc1eb55a1f 100644
--- a/drivers/net/nfp/nfpcore/nfp_nsp.h
+++ b/drivers/net/nfp/nfpcore/nfp_nsp.h
@@ -139,6 +139,8 @@ struct nfp_eth_table {
bool supp_aneg; /**< Support auto negotiation */
bool override_changed; /**< Media reconfig pending */
+ bool rx_pause_enabled; /**< Switch of RX pause frame */
+ bool tx_pause_enabled; /**< Switch of TX pause frame */
uint8_t port_type; /**< One of %PORT_* */
/** Sum of lanes of all subports of this port */
diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c
index 75f6d40fea..ca8bc8f550 100644
--- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c
+++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c
@@ -33,6 +33,8 @@
#define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23)
#define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26)
#define NSP_ETH_STATE_ACT_FEC GENMASK_ULL(29, 28)
+#define NSP_ETH_STATE_TX_PAUSE RTE_BIT64(31)
+#define NSP_ETH_STATE_RX_PAUSE RTE_BIT64(32)
#define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0)
#define NSP_ETH_CTRL_ENABLED RTE_BIT64(1)
@@ -186,6 +188,15 @@ nfp_eth_port_translate(struct nfp_nsp *nsp,
dst->act_fec = FIELD_GET(NSP_ETH_STATE_ACT_FEC, state);
dst->supp_aneg = FIELD_GET(NSP_ETH_PORT_SUPP_ANEG, port);
+
+ if (nfp_nsp_get_abi_ver_minor(nsp) < 37) {
+ dst->tx_pause_enabled = true;
+ dst->rx_pause_enabled = true;
+ return;
+ }
+
+ dst->tx_pause_enabled = FIELD_GET(NSP_ETH_STATE_TX_PAUSE, state);
+ dst->rx_pause_enabled = FIELD_GET(NSP_ETH_STATE_RX_PAUSE, state);
}
static void
--
2.39.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] net/nfp: support setting pause frame switch mode
2023-11-02 6:16 [PATCH 0/2] add support of RX/TX pause frame switch Chaoyong He
2023-11-02 6:16 ` [PATCH 1/2] net/nfp: support getting pause frame switch mode Chaoyong He
@ 2023-11-02 6:16 ` Chaoyong He
2023-11-02 20:39 ` [PATCH 0/2] add support of RX/TX pause frame switch Ferruh Yigit
2 siblings, 0 replies; 4+ messages in thread
From: Chaoyong He @ 2023-11-02 6:16 UTC (permalink / raw)
To: dev; +Cc: oss-drivers, Zerun Fu, Long Wu, Peng Zhang, Chaoyong He
From: Zerun Fu <zerun.fu@corigine.com>
Add support for configuring RX/TX pause frame switch mode.
Signed-off-by: Zerun Fu <zerun.fu@corigine.com>
Reviewed-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/nfp_ethdev.c | 1 +
drivers/net/nfp/nfp_net_common.c | 75 +++++++++++++++++++++++++++
drivers/net/nfp/nfp_net_common.h | 2 +
drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +
drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 52 ++++++++++++++++++-
5 files changed, 131 insertions(+), 1 deletion(-)
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 452e16e126..fd54d58cb5 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -429,6 +429,7 @@ static const struct eth_dev_ops nfp_net_eth_dev_ops = {
.udp_tunnel_port_del = nfp_udp_tunnel_port_del,
.fw_version_get = nfp_net_firmware_version_get,
.flow_ctrl_get = nfp_net_flow_ctrl_get,
+ .flow_ctrl_set = nfp_net_flow_ctrl_set,
};
static inline void
diff --git a/drivers/net/nfp/nfp_net_common.c b/drivers/net/nfp/nfp_net_common.c
index 44b2d6dd4f..8dd014c575 100644
--- a/drivers/net/nfp/nfp_net_common.c
+++ b/drivers/net/nfp/nfp_net_common.c
@@ -2114,3 +2114,78 @@ nfp_net_flow_ctrl_get(struct rte_eth_dev *dev,
return 0;
}
+
+static int
+nfp_net_pause_frame_set(struct nfp_net_hw *net_hw,
+ struct nfp_eth_table_port *eth_port,
+ enum rte_eth_fc_mode mode)
+{
+ int err;
+ bool flag;
+ struct nfp_nsp *nsp;
+
+ nsp = nfp_eth_config_start(net_hw->cpp, eth_port->index);
+ if (nsp == NULL) {
+ PMD_DRV_LOG(ERR, "NFP error when obtaining NSP handle.");
+ return -EIO;
+ }
+
+ flag = (mode & RTE_ETH_FC_TX_PAUSE) == 0 ? false : true;
+ err = nfp_eth_set_tx_pause(nsp, flag);
+ if (err != 0) {
+ PMD_DRV_LOG(ERR, "Failed to configure TX pause frame.");
+ nfp_eth_config_cleanup_end(nsp);
+ return err;
+ }
+
+ flag = (mode & RTE_ETH_FC_RX_PAUSE) == 0 ? false : true;
+ err = nfp_eth_set_rx_pause(nsp, flag);
+ if (err != 0) {
+ PMD_DRV_LOG(ERR, "Failed to configure RX pause frame.");
+ nfp_eth_config_cleanup_end(nsp);
+ return err;
+ }
+
+ err = nfp_eth_config_commit_end(nsp);
+ if (err != 0) {
+ PMD_DRV_LOG(ERR, "Failed to configure pause frame.");
+ return err;
+ }
+
+ return 0;
+}
+
+int
+nfp_net_flow_ctrl_set(struct rte_eth_dev *dev,
+ struct rte_eth_fc_conf *fc_conf)
+{
+ int ret;
+ struct nfp_net_hw *net_hw;
+ enum rte_eth_fc_mode set_mode;
+ enum rte_eth_fc_mode original_mode;
+ struct nfp_eth_table *nfp_eth_table;
+ struct nfp_eth_table_port *eth_port;
+
+ net_hw = nfp_net_get_hw(dev);
+ if (net_hw->pf_dev == NULL)
+ return -EINVAL;
+
+ nfp_eth_table = net_hw->pf_dev->nfp_eth_table;
+ eth_port = &nfp_eth_table->ports[net_hw->idx];
+
+ original_mode = nfp_net_get_pause_mode(eth_port);
+ set_mode = fc_conf->mode;
+
+ if (set_mode == original_mode)
+ return 0;
+
+ ret = nfp_net_pause_frame_set(net_hw, eth_port, set_mode);
+ if (ret != 0)
+ return ret;
+
+ /* Update eth_table after modifying RX/TX pause frame mode. */
+ eth_port->tx_pause_enabled = (set_mode & RTE_ETH_FC_TX_PAUSE) == 0 ? false : true;
+ eth_port->rx_pause_enabled = (set_mode & RTE_ETH_FC_RX_PAUSE) == 0 ? false : true;
+
+ return 0;
+}
diff --git a/drivers/net/nfp/nfp_net_common.h b/drivers/net/nfp/nfp_net_common.h
index 5a65d166e0..68a84dea06 100644
--- a/drivers/net/nfp/nfp_net_common.h
+++ b/drivers/net/nfp/nfp_net_common.h
@@ -240,6 +240,8 @@ struct nfp_net_hw *nfp_net_get_hw(const struct rte_eth_dev *dev);
int nfp_net_stop(struct rte_eth_dev *dev);
int nfp_net_flow_ctrl_get(struct rte_eth_dev *dev,
struct rte_eth_fc_conf *fc_conf);
+int nfp_net_flow_ctrl_set(struct rte_eth_dev *dev,
+ struct rte_eth_fc_conf *fc_conf);
#define NFP_PRIV_TO_APP_FW_NIC(app_fw_priv)\
((struct nfp_app_fw_nic *)app_fw_priv)
diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h
index dc1eb55a1f..4888501e46 100644
--- a/drivers/net/nfp/nfpcore/nfp_nsp.h
+++ b/drivers/net/nfp/nfpcore/nfp_nsp.h
@@ -189,6 +189,8 @@ void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp);
int nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode);
int nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed);
int nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes);
+int nfp_eth_set_tx_pause(struct nfp_nsp *nsp, bool tx_pause);
+int nfp_eth_set_rx_pause(struct nfp_nsp *nsp, bool rx_pause);
/* NSP static information */
struct nfp_nsp_identify {
diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c
index ca8bc8f550..87db928c08 100644
--- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c
+++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c
@@ -44,6 +44,8 @@
#define NSP_ETH_CTRL_SET_LANES RTE_BIT64(5)
#define NSP_ETH_CTRL_SET_ANEG RTE_BIT64(6)
#define NSP_ETH_CTRL_SET_FEC RTE_BIT64(7)
+#define NSP_ETH_CTRL_SET_TX_PAUSE RTE_BIT64(10)
+#define NSP_ETH_CTRL_SET_RX_PAUSE RTE_BIT64(11)
/* Which connector port. */
#define PORT_TP 0x00
@@ -519,7 +521,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp,
uint32_t raw_idx,
const uint64_t mask,
const uint32_t shift,
- uint32_t val,
+ uint64_t val,
const uint64_t ctrl_bit)
{
uint64_t reg;
@@ -683,3 +685,51 @@ nfp_eth_set_split(struct nfp_nsp *nsp,
return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT,
NSP_ETH_PORT_LANES, lanes, NSP_ETH_CTRL_SET_LANES);
}
+
+/**
+ * Set TX pause switch.
+ *
+ * @param nsp
+ * NFP NSP handle returned from nfp_eth_config_start()
+ * @param tx_pause
+ * TX pause switch
+ *
+ * @return
+ * 0 or -ERRNO
+ */
+int
+nfp_eth_set_tx_pause(struct nfp_nsp *nsp,
+ bool tx_pause)
+{
+ if (nfp_nsp_get_abi_ver_minor(nsp) < 37) {
+ PMD_DRV_LOG(ERR, "Set frame pause operation not supported, please update flash.");
+ return -EOPNOTSUPP;
+ }
+
+ return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE,
+ NSP_ETH_STATE_TX_PAUSE, tx_pause, NSP_ETH_CTRL_SET_TX_PAUSE);
+}
+
+/**
+ * Set RX pause switch.
+ *
+ * @param nsp
+ * NFP NSP handle returned from nfp_eth_config_start()
+ * @param rx_pause
+ * RX pause switch
+ *
+ * @return
+ * 0 or -ERRNO
+ */
+int
+nfp_eth_set_rx_pause(struct nfp_nsp *nsp,
+ bool rx_pause)
+{
+ if (nfp_nsp_get_abi_ver_minor(nsp) < 37) {
+ PMD_DRV_LOG(ERR, "Set frame pause operation not supported, please update flash.");
+ return -EOPNOTSUPP;
+ }
+
+ return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE,
+ NSP_ETH_STATE_RX_PAUSE, rx_pause, NSP_ETH_CTRL_SET_RX_PAUSE);
+}
--
2.39.1
^ permalink raw reply [flat|nested] 4+ messages in thread