From: Jiawen Wu <jiawenwu@trustnetic.com>
To: dev@dpdk.org
Cc: Jiawen Wu <jiawenwu@trustnetic.com>, stable@dpdk.org
Subject: [PATCH 03/11] net/ngbe: fix to set flow control
Date: Thu, 28 Sep 2023 17:47:50 +0800 [thread overview]
Message-ID: <20230928094758.1076236-4-jiawenwu@trustnetic.com> (raw)
In-Reply-To: <20230928094758.1076236-1-jiawenwu@trustnetic.com>
Fix flow control high/low water limit.
Fixes: f40e9f0e2278 ("net/ngbe: support flow control")
Cc: stable@dpdk.org
Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
drivers/net/ngbe/base/ngbe_type.h | 40 ++++++++++++++
drivers/net/ngbe/ngbe_ethdev.c | 89 +++++++++++++++++++++++++++++++
2 files changed, 129 insertions(+)
diff --git a/drivers/net/ngbe/base/ngbe_type.h b/drivers/net/ngbe/base/ngbe_type.h
index 37be288a74..8a7d2cd331 100644
--- a/drivers/net/ngbe/base/ngbe_type.h
+++ b/drivers/net/ngbe/base/ngbe_type.h
@@ -116,6 +116,46 @@ struct ngbe_fc_info {
enum ngbe_fc_mode requested_mode; /* FC mode requested by caller */
};
+/* Flow Control Data Sheet defined values
+ * Calculation and defines taken from 802.1bb Annex O
+ */
+/* BitTimes (BT) conversion */
+#define NGBE_BT2KB(BT) (((BT) + (8 * 1024 - 1)) / (8 * 1024))
+#define NGBE_B2BT(BT) ((BT) * 8)
+
+/* Calculate Delay to respond to PFC */
+#define NGBE_PFC_D 672
+
+/* Calculate Cable Delay */
+#define NGBE_CABLE_DC 5556 /* Delay Copper */
+
+/* Calculate Interface Delay */
+#define NGBE_PHY_D 12800
+#define NGBE_MAC_D 4096
+#define NGBE_XAUI_D (2 * 1024)
+
+#define NGBE_ID (NGBE_MAC_D + NGBE_XAUI_D + NGBE_PHY_D)
+
+/* Calculate Delay incurred from higher layer */
+#define NGBE_HD 6144
+
+/* Calculate PCI Bus delay for low thresholds */
+#define NGBE_PCI_DELAY 10000
+
+/* Calculate delay value in bit times */
+#define NGBE_DV(_max_frame_link, _max_frame_tc) \
+ ((36 * \
+ (NGBE_B2BT(_max_frame_link) + \
+ NGBE_PFC_D + \
+ (2 * NGBE_CABLE_DC) + \
+ (2 * NGBE_ID) + \
+ NGBE_HD) / 25 + 1) + \
+ 2 * NGBE_B2BT(_max_frame_tc))
+
+#define NGBE_LOW_DV(_max_frame_tc) \
+ (2 * ((2 * NGBE_B2BT(_max_frame_tc) + \
+ (36 * NGBE_PCI_DELAY / 25) + 1)))
+
/* Statistics counters collected by the MAC */
/* PB[] RxTx */
struct ngbe_pb_stats {
diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c
index af77081d9a..039c3c35a8 100644
--- a/drivers/net/ngbe/ngbe_ethdev.c
+++ b/drivers/net/ngbe/ngbe_ethdev.c
@@ -90,6 +90,7 @@ static int ngbe_dev_misc_interrupt_setup(struct rte_eth_dev *dev);
static int ngbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev);
static void ngbe_dev_interrupt_handler(void *param);
static void ngbe_configure_msix(struct rte_eth_dev *dev);
+static void ngbe_pbthresh_set(struct rte_eth_dev *dev);
#define NGBE_SET_HWSTRIP(h, q) do {\
uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
@@ -1037,6 +1038,7 @@ ngbe_dev_start(struct rte_eth_dev *dev)
}
hw->mac.setup_pba(hw);
+ ngbe_pbthresh_set(dev);
ngbe_configure_port(dev);
err = ngbe_dev_rxtx_start(dev);
@@ -2386,6 +2388,93 @@ ngbe_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
return -EIO;
}
+/* Additional bittime to account for NGBE framing */
+#define NGBE_ETH_FRAMING 20
+
+/*
+ * ngbe_fc_hpbthresh_set - calculate high water mark for flow control
+ *
+ * @dv_id: device interface delay
+ * @pb: packet buffer to calculate
+ */
+static s32
+ngbe_fc_hpbthresh_set(struct rte_eth_dev *dev)
+{
+ struct ngbe_hw *hw = ngbe_dev_hw(dev);
+ struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+ u32 max_frame_size, tc, dv_id, rx_pb;
+ s32 kb, marker;
+
+ /* Calculate max LAN frame size */
+ max_frame_size = rd32m(hw, NGBE_FRMSZ, NGBE_FRMSZ_MAX_MASK);
+ tc = max_frame_size + NGBE_ETH_FRAMING;
+
+ /* Calculate delay value for device */
+ dv_id = NGBE_DV(tc, tc);
+
+ /* Loopback switch introduces additional latency */
+ if (pci_dev->max_vfs)
+ dv_id += NGBE_B2BT(tc);
+
+ /* Delay value is calculated in bit times convert to KB */
+ kb = NGBE_BT2KB(dv_id);
+ rx_pb = rd32(hw, NGBE_PBRXSIZE) >> 10;
+
+ marker = rx_pb - kb;
+
+ /* It is possible that the packet buffer is not large enough
+ * to provide required headroom. In this case throw an error
+ * to user and do the best we can.
+ */
+ if (marker < 0) {
+ PMD_DRV_LOG(WARNING, "Packet Buffer can not provide enough headroom to support flow control.");
+ marker = tc + 1;
+ }
+
+ return marker;
+}
+
+/*
+ * ngbe_fc_lpbthresh_set - calculate low water mark for for flow control
+ *
+ * @dv_id: device interface delay
+ */
+static s32
+ngbe_fc_lpbthresh_set(struct rte_eth_dev *dev)
+{
+ struct ngbe_hw *hw = ngbe_dev_hw(dev);
+ u32 max_frame_size, tc, dv_id;
+ s32 kb;
+
+ /* Calculate max LAN frame size */
+ max_frame_size = rd32m(hw, NGBE_FRMSZ, NGBE_FRMSZ_MAX_MASK);
+ tc = max_frame_size + NGBE_ETH_FRAMING;
+
+ /* Calculate delay value for device */
+ dv_id = NGBE_LOW_DV(tc);
+
+ /* Delay value is calculated in bit times convert to KB */
+ kb = NGBE_BT2KB(dv_id);
+
+ return kb;
+}
+
+/*
+ * ngbe_pbthresh_setup - calculate and setup high low water marks
+ */
+static void
+ngbe_pbthresh_set(struct rte_eth_dev *dev)
+{
+ struct ngbe_hw *hw = ngbe_dev_hw(dev);
+
+ hw->fc.high_water = ngbe_fc_hpbthresh_set(dev);
+ hw->fc.low_water = ngbe_fc_lpbthresh_set(dev);
+
+ /* Low water marks must not be larger than high water marks */
+ if (hw->fc.low_water > hw->fc.high_water)
+ hw->fc.low_water = 0;
+}
+
int
ngbe_dev_rss_reta_update(struct rte_eth_dev *dev,
struct rte_eth_rss_reta_entry64 *reta_conf,
--
2.27.0
next prev parent reply other threads:[~2023-09-28 9:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230928094758.1076236-1-jiawenwu@trustnetic.com>
2023-09-28 9:47 ` [PATCH 01/11] net/txgbe: add Tx queue maximum limit Jiawen Wu
2023-09-28 9:47 ` [PATCH 02/11] net/txgbe: fix GRE tunnel packet checksum Jiawen Wu
2023-09-28 9:47 ` Jiawen Wu [this message]
2023-09-28 9:47 ` [PATCH 04/11] net/ngbe: prevent the NIC from slowing down link speed Jiawen Wu
2023-09-28 9:47 ` [PATCH 05/11] net/txgbe: reconfigure MAC Rx when link update Jiawen Wu
2023-09-28 9:47 ` [PATCH 06/11] net/ngbe: " Jiawen Wu
2023-09-28 9:47 ` [PATCH 07/11] net/txgbe: fix to keep link down after device close Jiawen Wu
2023-09-28 9:47 ` [PATCH 08/11] net/ngbe: " Jiawen Wu
2023-09-28 9:47 ` [PATCH 09/11] net/txgbe: check process type in close operation Jiawen Wu
2023-09-28 9:47 ` [PATCH 10/11] net/ngbe: " Jiawen Wu
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=20230928094758.1076236-4-jiawenwu@trustnetic.com \
--to=jiawenwu@trustnetic.com \
--cc=dev@dpdk.org \
--cc=stable@dpdk.org \
/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).