DPDK patches and discussions
 help / color / mirror / Atom feed
From: <ssebasti@amd.com>
To: <dev@dpdk.org>
Subject: [PATCH v1 3/6] net/axgbe: simplify mailbox interface rate change code
Date: Mon, 10 Jan 2022 17:05:06 +0530	[thread overview]
Message-ID: <20220110113509.553184-4-ssebasti@amd.com> (raw)
In-Reply-To: <20220110113509.553184-1-ssebasti@amd.com>

From: Selwin Sebastian <selwin.sebastian@amd.com>

Simplify and centralize the mailbox command rate change interface by
having a single function perform the writes to the mailbox registers
to issue the request.

Signed-off-by: Selwin Sebastian <selwin.sebastian@amd.com>
---
 drivers/net/axgbe/axgbe_phy_impl.c | 95 ++++++++----------------------
 1 file changed, 23 insertions(+), 72 deletions(-)

diff --git a/drivers/net/axgbe/axgbe_phy_impl.c b/drivers/net/axgbe/axgbe_phy_impl.c
index dc9489f0aa..0894dbf74b 100644
--- a/drivers/net/axgbe/axgbe_phy_impl.c
+++ b/drivers/net/axgbe/axgbe_phy_impl.c
@@ -1207,21 +1207,26 @@ static void axgbe_phy_pll_ctrl(struct axgbe_port *pdata, bool enable)
 	rte_delay_us(150);
 }
 
-static void axgbe_phy_start_ratechange(struct axgbe_port *pdata)
+static void axgbe_phy_perform_ratechange(struct axgbe_port *pdata,
+					unsigned int cmd, unsigned int sub_cmd)
 {
+	unsigned int s0 = 0;
+	unsigned int wait;
 	/* Clear the PLL so that it helps in power down sequence */
 	axgbe_phy_pll_ctrl(pdata, false);
 
 	/* Log if a previous command did not complete */
 	if (XP_IOREAD_BITS(pdata, XP_DRIVER_INT_RO, STATUS))
 		PMD_DRV_LOG(NOTICE, "firmware mailbox not ready for command\n");
-	else
-		return;
-}
 
-static void axgbe_phy_complete_ratechange(struct axgbe_port *pdata)
-{
-	unsigned int wait;
+	/* Construct the command */
+	XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, COMMAND, cmd);
+	XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, sub_cmd);
+
+	/* Issue the command */
+	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_0, s0);
+	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_1, 0);
+	XP_IOWRITE_BITS(pdata, XP_DRIVER_INT_REQ, REQUEST, 1);
 
 	/* Wait for command to complete */
 	wait = AXGBE_RATECHANGE_COUNT;
@@ -1240,21 +1245,10 @@ static void axgbe_phy_complete_ratechange(struct axgbe_port *pdata)
 
 static void axgbe_phy_rrc(struct axgbe_port *pdata)
 {
-	unsigned int s0;
 
-	axgbe_phy_start_ratechange(pdata);
 
 	/* Receiver Reset Cycle */
-	s0 = 0;
-	XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, COMMAND, 5);
-	XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, 0);
-
-	/* Call FW to make the change */
-	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_0, s0);
-	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_1, 0);
-	XP_IOWRITE_BITS(pdata, XP_DRIVER_INT_REQ, REQUEST, 1);
-
-	axgbe_phy_complete_ratechange(pdata);
+	axgbe_phy_perform_ratechange(pdata, 5, 0);
 
 	PMD_DRV_LOG(DEBUG, "receiver reset complete\n");
 }
@@ -1263,13 +1257,9 @@ static void axgbe_phy_power_off(struct axgbe_port *pdata)
 {
 	struct axgbe_phy_data *phy_data = pdata->phy_data;
 
-	axgbe_phy_start_ratechange(pdata);
+	/* Power off */
+	axgbe_phy_perform_ratechange(pdata, 0, 0);
 
-	/* Call FW to make the change */
-	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_0, 0);
-	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_1, 0);
-	XP_IOWRITE_BITS(pdata, XP_DRIVER_INT_REQ, REQUEST, 1);
-	axgbe_phy_complete_ratechange(pdata);
 	phy_data->cur_mode = AXGBE_MODE_UNKNOWN;
 
 	PMD_DRV_LOG(DEBUG, "phy powered off\n");
@@ -1278,31 +1268,21 @@ static void axgbe_phy_power_off(struct axgbe_port *pdata)
 static void axgbe_phy_sfi_mode(struct axgbe_port *pdata)
 {
 	struct axgbe_phy_data *phy_data = pdata->phy_data;
-	unsigned int s0;
 
 	axgbe_phy_set_redrv_mode(pdata);
 
-	axgbe_phy_start_ratechange(pdata);
-
 	/* 10G/SFI */
-	s0 = 0;
-	XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, COMMAND, 3);
 	if (phy_data->sfp_cable != AXGBE_SFP_CABLE_PASSIVE) {
-		XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, 0);
+		axgbe_phy_perform_ratechange(pdata, 3, 0);
 	} else {
 		if (phy_data->sfp_cable_len <= 1)
-			XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, 1);
+			axgbe_phy_perform_ratechange(pdata, 3, 1);
 		else if (phy_data->sfp_cable_len <= 3)
-			XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, 2);
+			axgbe_phy_perform_ratechange(pdata, 3, 2);
 		else
-			XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, 3);
+			axgbe_phy_perform_ratechange(pdata, 3, 3);
 	}
 
-	/* Call FW to make the change */
-	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_0, s0);
-	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_1, 0);
-	XP_IOWRITE_BITS(pdata, XP_DRIVER_INT_REQ, REQUEST, 1);
-	axgbe_phy_complete_ratechange(pdata);
 	phy_data->cur_mode = AXGBE_MODE_SFI;
 
 	PMD_DRV_LOG(DEBUG, "10GbE SFI mode set\n");
@@ -1311,22 +1291,11 @@ static void axgbe_phy_sfi_mode(struct axgbe_port *pdata)
 static void axgbe_phy_kr_mode(struct axgbe_port *pdata)
 {
 	struct axgbe_phy_data *phy_data = pdata->phy_data;
-	unsigned int s0;
 
 	axgbe_phy_set_redrv_mode(pdata);
 
-	axgbe_phy_start_ratechange(pdata);
-
 	/* 10G/KR */
-	s0 = 0;
-	XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, COMMAND, 4);
-	XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, 0);
-
-	/* Call FW to make the change */
-	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_0, s0);
-	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_1, 0);
-	XP_IOWRITE_BITS(pdata, XP_DRIVER_INT_REQ, REQUEST, 1);
-	axgbe_phy_complete_ratechange(pdata);
+	axgbe_phy_perform_ratechange(pdata, 4, 0);
 	phy_data->cur_mode = AXGBE_MODE_KR;
 
 	PMD_DRV_LOG(DEBUG, "10GbE KR mode set\n");
@@ -1335,40 +1304,22 @@ static void axgbe_phy_kr_mode(struct axgbe_port *pdata)
 static void axgbe_phy_kx_2500_mode(struct axgbe_port *pdata)
 {
 	struct axgbe_phy_data *phy_data = pdata->phy_data;
-	unsigned int s0;
 
 	axgbe_phy_set_redrv_mode(pdata);
-	/* 2.5G/KX */
-	axgbe_phy_start_ratechange(pdata);
-	s0 = 0;
-	XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, COMMAND, 2);
-	XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, 0);
-
-	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_0, s0);
-	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_1, 0);
-
-	XP_IOWRITE_BITS(pdata, XP_DRIVER_INT_REQ, REQUEST, 1);
 
+	/* 2.5G/KX */
+	axgbe_phy_perform_ratechange(pdata, 2, 0);
 	phy_data->cur_mode = AXGBE_MODE_KX_2500;
 }
 
 static void axgbe_phy_sgmii_1000_mode(struct axgbe_port *pdata)
 {
 	struct axgbe_phy_data *phy_data = pdata->phy_data;
-	unsigned int s0;
 
 	axgbe_phy_set_redrv_mode(pdata);
 
 	/* 1G/SGMII */
-	axgbe_phy_start_ratechange(pdata);
-	s0 = 0;
-	XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, COMMAND, 1);
-	XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, 2);
-
-	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_0, s0);
-	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_1, 0);
-
-	XP_IOWRITE_BITS(pdata, XP_DRIVER_INT_REQ, REQUEST, 1);
+	axgbe_phy_perform_ratechange(pdata, 1, 2);
 
 	phy_data->cur_mode = AXGBE_MODE_SGMII_1000;
 }
-- 
2.25.1


  parent reply	other threads:[~2022-01-10 11:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-10 11:35 axgbe PMD fixes and updates ssebasti
2022-01-10 11:35 ` [PATCH v1 1/6] net/axgbe: always attempt link training in KR mode ssebasti
2022-01-10 11:35 ` [PATCH v1 2/6] net/axgbe: toggle PLL settings during rate change ssebasti
2022-01-19  9:26   ` Namburu, Chandu-babu
2022-01-10 11:35 ` ssebasti [this message]
2022-01-24 16:39   ` [PATCH v1 3/6] net/axgbe: simplify mailbox interface rate change code Namburu, Chandu-babu
2022-01-10 11:35 ` [PATCH v1 4/6] net/axgbe: reset PHY Rx when mailbox command timeout ssebasti
2022-01-24 16:40   ` Namburu, Chandu-babu
2022-01-10 11:35 ` [PATCH v1 5/6] net/axgbe: add support for new port mode ssebasti
2022-01-24 16:40   ` Namburu, Chandu-babu
2022-01-10 11:35 ` [PATCH v1 6/6] net/axgbe: alter the port speed bit range ssebasti
2022-01-24 16:40   ` Namburu, Chandu-babu
2022-01-25 10:23 ` axgbe PMD fixes and updates Ferruh Yigit

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=20220110113509.553184-4-ssebasti@amd.com \
    --to=ssebasti@amd.com \
    --cc=dev@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).