Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4212441pxb; Mon, 4 Oct 2021 20:42:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEj8YGtACmsSvYkAkzh1sCPm5lpnnpLCjzEruFS1becofxAHrTWLaGrZyqgfSSlZitT/3J X-Received: by 2002:a17:906:b098:: with SMTP id x24mr22128802ejy.88.1633405376511; Mon, 04 Oct 2021 20:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633405376; cv=none; d=google.com; s=arc-20160816; b=bxfuGAuRcUSLj7aKzG5kxqZE1dLTh4y+2+PB/gNHQLgRp8sX6CawS2FcAqAnT8Rbbx JsLiejsLoS2L4L/rWbAyu5kk5mVZi+7HIJRLZfL7jS7FzpflAKJIb2KmUO73CDXPT9/z 1DAFOYw7YMB5GM+efqCzCjweXXpPl/RXQ8aJDp4K/IHQra1dUebCMkX2wfPOVaIWFsGT Ru/kG6s+kJHx2qR+pMa0xLosHfKd49swvfcUUPQP4T0Zl8DEeBpX2dH0sKA+97CFFs0Q nj3nCnsbGsxYDFWpsiEbw2IN3vZhDzGXWC/EkImpgVSJqPcPEf3OHAWWRbdCdh9pINo2 LwNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Y+mXSU8CxzekQZf+U9bBAAM7xfTkIFcq99Zzyh1Kkfo=; b=BboR1AKAGBfabXWKBLRGmxX/uS5mtYC5wz/BJQv9Y34CJhpQUpPkT862DD/wik3oJG 4dGy0HHOmN0A3bbAWek6fc1tD6Ysvu8QWqp2LidqQmjldTCR0UVYfoMFmpJQFv2YmdUv 6QZrQ71+cgQLJaD6imUuT0vVVgRPcWZT6fu47cLeQJs8GbAOGLJA4d0afbpSJqWvOSLU 7duQT4e1r+cG1FM5liA8vA8H2vyU9V2AXyHs8vJCzTjWI++LDzSK5p4z2UkGOlt+dqrB /Ibz/9F5ZsjATM9Udf5Hgggc9/KKtZ4KBBUgDo5R70mhQ3/jGBm5oIJI/jVHVemngJRO YLHQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s11si23301613edh.403.2021.10.04.20.42.32; Mon, 04 Oct 2021 20:42:56 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231363AbhJEDlD (ORCPT + 99 others); Mon, 4 Oct 2021 23:41:03 -0400 Received: from mga14.intel.com ([192.55.52.115]:55059 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229659AbhJEDlC (ORCPT ); Mon, 4 Oct 2021 23:41:02 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10127"; a="225957957" X-IronPort-AV: E=Sophos;i="5.85,347,1624345200"; d="scan'208";a="225957957" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2021 20:39:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,347,1624345200"; d="scan'208";a="544610054" Received: from linux.intel.com ([10.54.29.200]) by fmsmga004.fm.intel.com with ESMTP; 04 Oct 2021 20:39:12 -0700 Received: from glass.png.intel.com (glass.png.intel.com [10.158.65.69]) by linux.intel.com (Postfix) with ESMTP id ABF72580A6C; Mon, 4 Oct 2021 20:39:09 -0700 (PDT) From: Wong Vee Khee To: "David S . Miller" , Jose Abreu , Andrew Lunn , Heiner Kallweit , Russell King , Jakub Kicinski Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Vladimir Oltean , Wong Vee Khee Subject: [PATCH net v4 1/1] net: pcs: xpcs: fix incorrect CL37 AN sequence Date: Tue, 5 Oct 2021 11:45:21 +0800 Message-Id: <20211005034521.534125-1-vee.khee.wong@linux.intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org According to Synopsys DesignWare Cores Ethernet PCS databook, it is required to disable Clause 37 auto-negotiation by programming bit-12 (AN_ENABLE) to 0 if it is already enabled, before programming various fields of VR_MII_AN_CTRL registers. After all these programming are done, it is then required to enable Clause 37 auto-negotiation by programming bit-12 (AN_ENABLE) to 1. Fixes: b97b5331b8ab ("net: pcs: add C37 SGMII AN support for intel mGbE controller") Cc: Vladimir Oltean Signed-off-by: Wong Vee Khee --- v3 -> v4: - Removed redunctant 'changed' variable. v2 -> v3: - Added error handling after xpcs_write(). - Added 'changed' flag. - Added fixes tag. v1 -> v2: - Removed use of xpcs_modify() helper function. - Add conditional check on inband auto-negotiation. --- drivers/net/pcs/pcs-xpcs.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index fb0a83dc09ac..a3e806cfa684 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -697,14 +697,17 @@ EXPORT_SYMBOL_GPL(xpcs_config_eee); static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, unsigned int mode) { - int ret; + int ret, mdio_ctrl; /* For AN for C37 SGMII mode, the settings are :- - * 1) VR_MII_AN_CTRL Bit(2:1)[PCS_MODE] = 10b (SGMII AN) - * 2) VR_MII_AN_CTRL Bit(3) [TX_CONFIG] = 0b (MAC side SGMII) + * 1) VR_MII_MMD_CTRL Bit(12) [AN_ENABLE] = 0b (Disable SGMII AN in case + it is already enabled) + * 2) VR_MII_AN_CTRL Bit(2:1)[PCS_MODE] = 10b (SGMII AN) + * 3) VR_MII_AN_CTRL Bit(3) [TX_CONFIG] = 0b (MAC side SGMII) * DW xPCS used with DW EQoS MAC is always MAC side SGMII. - * 3) VR_MII_DIG_CTRL1 Bit(9) [MAC_AUTO_SW] = 1b (Automatic + * 4) VR_MII_DIG_CTRL1 Bit(9) [MAC_AUTO_SW] = 1b (Automatic * speed/duplex mode change by HW after SGMII AN complete) + * 5) VR_MII_MMD_CTRL Bit(12) [AN_ENABLE] = 1b (Enable SGMII AN) * * Note: Since it is MAC side SGMII, there is no need to set * SR_MII_AN_ADV. MAC side SGMII receives AN Tx Config from @@ -712,6 +715,17 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, unsigned int mode) * between PHY and Link Partner. There is also no need to * trigger AN restart for MAC-side SGMII. */ + mdio_ctrl = xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_CTRL); + if (mdio_ctrl < 0) + return mdio_ctrl; + + if (mdio_ctrl & AN_CL37_EN) { + ret = xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_CTRL, + mdio_ctrl & ~AN_CL37_EN); + if (ret < 0) + return ret; + } + ret = xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_CTRL); if (ret < 0) return ret; @@ -736,7 +750,15 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, unsigned int mode) else ret &= ~DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW; - return xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL1, ret); + ret = xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL1, ret); + if (ret < 0) + return ret; + + if (phylink_autoneg_inband(mode)) + ret = xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_CTRL, + mdio_ctrl | AN_CL37_EN); + + return ret; } static int xpcs_config_2500basex(struct dw_xpcs *xpcs) -- 2.25.1