netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hariprasad Kelam <hkelam@marvell.com>
To: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <davem@davemloft.net>, <kuba@kernel.org>, <sgoutham@marvell.com>,
	<lcherian@marvell.com>, <gakula@marvell.com>,
	<jerinj@marvell.com>, <sbhatta@marvell.com>,
	Christina Jacob <cjacob@marvell.com>,
	Hariprasad Kelam <hkelam@marvell.com>
Subject: [net-next PATCH 7/7] octeontx2-pf: ethtool physical link configuration
Date: Thu, 21 Jan 2021 13:23:29 +0530	[thread overview]
Message-ID: <1611215609-92301-8-git-send-email-hkelam@marvell.com> (raw)
In-Reply-To: <1611215609-92301-1-git-send-email-hkelam@marvell.com>

From: Christina Jacob <cjacob@marvell.com>

Register set_link_ksetting callback with driver such that
link configurations parameters like advertised mode,speed, duplex
and autoneg can be configured.

below command
ethtool -s eth0 advertise 0x1 speed 10 duplex full autoneg on

Signed-off-by: Christina Jacob <cjacob@marvell.com>
Signed-off-by: Sunil Goutham <sgoutham@marvell.com>
Signed-off-by: Hariprasad Kelam <hkelam@marvell.com>
---
 .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c  | 59 ++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c
index ef79ecf..b928745 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c
@@ -1134,6 +1134,64 @@ static int otx2_get_link_ksettings(struct net_device *netdev,
 	return 0;
 }
 
+static int otx2_set_link_ksettings(struct net_device *netdev,
+				   const struct ethtool_link_ksettings *cmd)
+{
+	struct otx2_nic *pf = netdev_priv(netdev);
+	struct ethtool_link_ksettings req_ks;
+	struct ethtool_link_ksettings cur_ks;
+	struct cgx_set_link_mode_req *req;
+	struct cgx_set_link_mode_rsp *rsp;
+	struct mbox *mbox = &pf->mbox;
+	int err = 0;
+
+	/* save requested link settings */
+	memcpy(&req_ks, cmd, sizeof(struct ethtool_link_ksettings));
+
+	memset(&cur_ks, 0, sizeof(struct ethtool_link_ksettings));
+
+	if (!ethtool_validate_speed(cmd->base.speed) ||
+	    !ethtool_validate_duplex(cmd->base.duplex))
+		return -EINVAL;
+
+	if (cmd->base.autoneg != AUTONEG_ENABLE &&
+	    cmd->base.autoneg != AUTONEG_DISABLE)
+		return -EINVAL;
+
+	otx2_get_link_ksettings(netdev, &cur_ks);
+
+	/* Check requested modes against supported modes by hardware */
+	if (!bitmap_subset(req_ks.link_modes.advertising,
+			   cur_ks.link_modes.supported,
+			   __ETHTOOL_LINK_MODE_MASK_NBITS))
+		return -EINVAL;
+
+	mutex_lock(&mbox->lock);
+	req = otx2_mbox_alloc_msg_cgx_set_link_mode(&pf->mbox);
+	if (!req) {
+		mutex_unlock(&mbox->lock);
+		return -EAGAIN;
+	}
+
+	req->args.speed = req_ks.base.speed;
+	/* firmware expects 1 for half duplex and 0 for full duplex
+	 * hence inverting
+	 */
+	req->args.duplex = req_ks.base.duplex ^ 0x1;
+	req->args.an =  req_ks.base.autoneg;
+	req->args.mode   = *req_ks.link_modes.advertising;
+
+	err =  otx2_sync_mbox_msg(&pf->mbox);
+	if (!err) {
+		rsp = (struct cgx_set_link_mode_rsp *)
+			otx2_mbox_get_rsp(&pf->mbox.mbox, 0, &req->hdr);
+		if (rsp->status)
+			err =  rsp->status;
+	}
+	mutex_unlock(&mbox->lock);
+	return err;
+}
+
 static const struct ethtool_ops otx2_ethtool_ops = {
 	.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
 				     ETHTOOL_COALESCE_MAX_FRAMES,
@@ -1164,6 +1222,7 @@ static const struct ethtool_ops otx2_ethtool_ops = {
 	.get_fecparam		= otx2_get_fecparam,
 	.set_fecparam		= otx2_set_fecparam,
 	.get_link_ksettings     = otx2_get_link_ksettings,
+	.set_link_ksettings     = otx2_set_link_ksettings,
 };
 
 void otx2_set_ethtool_ops(struct net_device *netdev)
-- 
2.7.4


      parent reply	other threads:[~2021-01-21  7:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21  7:53 [net-next PATCH 0/7] ethtool support for fec and link configuration Hariprasad Kelam
2021-01-21  7:53 ` [net-next PATCH 1/7] octeontx2-af: forward error correction configuration Hariprasad Kelam
2021-01-21  7:53 ` [net-next PATCH 2/7] octeontx2-af: Add new CGX_CMD to get PHY FEC statistics Hariprasad Kelam
2021-01-21  7:53 ` [net-next PATCH 3/7] octeontx2-pf: ethtool fec mode support Hariprasad Kelam
2021-01-23  4:29   ` Jakub Kicinski
2021-01-24 17:16     ` [EXT] " Hariprasad Kelam
2021-01-21  7:53 ` [net-next PATCH 4/7] octeontx2-af: Physical link configuration support Hariprasad Kelam
2021-01-21  7:53 ` [net-next PATCH 5/7] octeontx2-af: advertised link modes support on cgx Hariprasad Kelam
2021-01-21  7:53 ` [net-next PATCH 6/7] octeontx2-pf: ethtool physical link status Hariprasad Kelam
2021-01-21  7:53 ` Hariprasad Kelam [this message]

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=1611215609-92301-8-git-send-email-hkelam@marvell.com \
    --to=hkelam@marvell.com \
    --cc=cjacob@marvell.com \
    --cc=davem@davemloft.net \
    --cc=gakula@marvell.com \
    --cc=jerinj@marvell.com \
    --cc=kuba@kernel.org \
    --cc=lcherian@marvell.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sbhatta@marvell.com \
    --cc=sgoutham@marvell.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).