Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3575594pxb; Sun, 31 Jan 2021 21:43:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJzCT3bl9LbJFbuaAiUbv8AIc3A4bTdTvXBRsbyo7qn9GwZPsHX3Etgv1dPQW10MMUZnescS X-Received: by 2002:a17:906:414e:: with SMTP id l14mr16500596ejk.476.1612158183506; Sun, 31 Jan 2021 21:43:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612158183; cv=none; d=google.com; s=arc-20160816; b=pwUY1aAmzXXkGXTaoFBz2iy5B8BcLPVRAWq8AdnLhYMYU6Qnbxjztc4NfzKNzdzTtb +gpygEfu8/BHUivRnLHheOzJR7hpUERgvoNBWHnjiGq9zb3d3L14uA6zsxHvJtE6bAGC ZJf3/a3+tUJIIzbRnmqzjDtmRri6bQ1/3AiHc43camXbrHxU/0R2xbfVvewua/zCUlqq q1ghUKoAskcgLA3951hvNdk/vWiAoHBNgupvodECINkMFD1cg2bfYvBwhDq+ktncOlwF a6sMwZuRyhx2fj/BlttclTPxVlSlwjXn+e222Awa3Eomr83yv1UFU8ld34m+YrH6tKFO Fv8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=k2W0HGdS52YxBqxCw5+glP2NLyQW59WceMVWV8sZtaE=; b=csHtEd41gPvyPVRhych3+tCVeVv0UuxlJnTsNEgIF7Z0IScOdTqKk5mROXzWCzz2LC QIDMLnib4EPAfjuI5xI0RuFIYLRzjW07Xrhmy9blyS0K3uw4dA30xYBkybCziPa1yXMP Z7pqXkRJQ2C6JjDiONVls6D9192yjaUSkcKch9yCBNpWMRUea9Fqhz2Sent2O1JReUAZ 8rXxF+mbFJ8vQFAW0NmlBm9df+DKFf8fNPFLrd1MeXWNoxSA4btvIqrcg5BKdYektnef Vg2B2jp873jGupq8Mzs/wun0rsD0+pVzGRNzP4M5twLS7WJz9LszV2i2pEbpmAmOXY3q 1zZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marvell.com header.s=pfpt0220 header.b=k3CWw1bq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=marvell.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e17si9635867ejr.533.2021.01.31.21.42.39; Sun, 31 Jan 2021 21:43:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@marvell.com header.s=pfpt0220 header.b=k3CWw1bq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=marvell.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231569AbhBAFkh (ORCPT + 99 others); Mon, 1 Feb 2021 00:40:37 -0500 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:33452 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231484AbhBAF0G (ORCPT ); Mon, 1 Feb 2021 00:26:06 -0500 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 1115L9p0004725; Sun, 31 Jan 2021 21:25:19 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0220; bh=k2W0HGdS52YxBqxCw5+glP2NLyQW59WceMVWV8sZtaE=; b=k3CWw1bq/lgCXL/XGznwDsLc68bSCyXX51ikyOxLU+gShYaqHBovtmRkdtR8e6mPVx9t 3O5GedaOh2RCysVB0OPqVe5LR+0+ZfNe1+NHBT2uhSCpBI9NOs/MUiYTOD2RefeUwyWN 9FsfCAma5OanXpBuDZ57+/gO++Tt8Vjab55dKo8jP5qUb2d1WALS5yCf1k0DXerGM3xL 1jXi7PWVN25+yseoBWcSPTi94VxaeAKMRUqx19hkI5xbIzVWesbPP7yZCSUuGvhqypLD GQJL4GbsDbTN1iJO+FOSYz5gckP0tMDHAwEw/+rzTb/p29QKQjUXmnZDa4n0/SgBZxFO Eg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com with ESMTP id 36d7uq2s4x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 31 Jan 2021 21:25:19 -0800 Received: from SC-EXCH04.marvell.com (10.93.176.84) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 31 Jan 2021 21:25:17 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 31 Jan 2021 21:25:17 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sun, 31 Jan 2021 21:25:16 -0800 Received: from hyd1soter2.marvell.com (unknown [10.29.37.45]) by maili.marvell.com (Postfix) with ESMTP id 8EDE13F7040; Sun, 31 Jan 2021 21:25:13 -0800 (PST) From: Hariprasad Kelam To: , CC: , , , , , , , , , Subject: [Patch v3 net-next 7/7] octeontx2-pf: ethtool physical link configuration Date: Mon, 1 Feb 2021 10:54:44 +0530 Message-ID: <1612157084-101715-8-git-send-email-hkelam@marvell.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1612157084-101715-1-git-send-email-hkelam@marvell.com> References: <1612157084-101715-1-git-send-email-hkelam@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.737 definitions=2021-02-01_02:2021-01-29,2021-02-01 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christina Jacob 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 Signed-off-by: Sunil Goutham Signed-off-by: Hariprasad Kelam --- .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c index d637815..74a62de 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c @@ -1170,6 +1170,72 @@ static int otx2_get_link_ksettings(struct net_device *netdev, return 0; } +static void otx2_get_advertised_mode(const struct ethtool_link_ksettings *cmd, + u64 *mode) +{ + u32 bit_pos; + + /* Firmware does not support requesting multiple advertised modes + * return first set bit + */ + bit_pos = find_first_bit(cmd->link_modes.advertising, + __ETHTOOL_LINK_MODE_MASK_NBITS); + if (bit_pos != __ETHTOOL_LINK_MODE_MASK_NBITS) + *mode = bit_pos; +} + +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 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) { + err = -ENOMEM; + goto end; + } + + 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; + otx2_get_advertised_mode(&req_ks, &req->args.mode); + + err = otx2_sync_mbox_msg(&pf->mbox); +end: + mutex_unlock(&mbox->lock); + return err; +} + static const struct ethtool_ops otx2_ethtool_ops = { .supported_coalesce_params = ETHTOOL_COALESCE_USECS | ETHTOOL_COALESCE_MAX_FRAMES, @@ -1200,6 +1266,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