From patchwork Tue Jan 2 14:03:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 184360 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4463004dyb; Tue, 2 Jan 2024 06:05:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgw0F53xQXNWrXPruOm67wUclUZJTUKW3fU7g7DiNKo2lBsXsy9eQ94YvWpCkW0B/eBlwq X-Received: by 2002:a05:6602:2108:b0:7b7:f972:c016 with SMTP id x8-20020a056602210800b007b7f972c016mr17706926iox.43.1704204353668; Tue, 02 Jan 2024 06:05:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704204353; cv=none; d=google.com; s=arc-20160816; b=ZbV40q1GWhZTSdOihfQ+goVgTE3g2ENNIC5eQ3XmCpAstI8Ii1hKnqwRGGXQFRV/uE K4GLPKWJpTJgBcZj/9DxcScEwNSJBG5b3U65x5adMua28jxdZTxVLIj49cPI5J77LNkc BWOKz7e4dVqb/x/P7m35mAb81Zg9GKLNkDQl1XT68Drw6OPirg4infwZOP+bxBPXWpXk xMcb4wh5s7FTc1x/Pdih17X7fnK4bxGu0rgglSH/K1jA3FhbsHW0lMdhQr1gX6zVjOGh PX5XGkDHxFu8G2myMG6Y+mvfKcYitErSIWjg/Xd45WzWLDrQW0+Cq2ErpCd+i9kTWS9u JJUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=MCe7bi22I9OO+O1jPW0w/LAeUi3E0GH8xhFVY0QzJoM=; fh=utmrxdkgikAlLxVfQI1kldUG+rNjhrLN+3fAlOYj01s=; b=rerFSKpQTo7cNZvF0aI6N6gqb66yZk36bWwIkT7jTGw/RrTZvUOqeYxfnE/uY4cv2c oct8ftsd83DhE206ZLW6dWNEbGObEbqeN5AOaAFTb/kHdS+3/zE2N84gB4bCa+nHMDdk 6yPZuHr/Nb61GWTXLeS3Lrz2s0CVaorK3VeEKMPKlWgsertfTLwA865SKE6JHnp6jilS zZVjNZwic5nt5HplGULCa6gZ/9r8lvC/y0TzaFOXjM87GdYbmMxfsWDM6QxRjvrcvYTF Pq99o6vtk1xdC6YvxgjUP2dYQnBkOHe20YpPGrafz8d8JqJUSn0HwnFMHOxa2qk+3sSS QIZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fLCHUUNk; spf=pass (google.com: domain of linux-kernel+bounces-14458-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14458-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g3-20020a636b03000000b005c6bc10835fsi19915274pgc.84.2024.01.02.06.05.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 06:05:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14458-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fLCHUUNk; spf=pass (google.com: domain of linux-kernel+bounces-14458-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14458-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 27D0E28393A for ; Tue, 2 Jan 2024 14:05:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 266F8154AB; Tue, 2 Jan 2024 14:03:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fLCHUUNk" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C622313ADA; Tue, 2 Jan 2024 14:03:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-33686649b72so9638710f8f.3; Tue, 02 Jan 2024 06:03:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704204220; x=1704809020; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MCe7bi22I9OO+O1jPW0w/LAeUi3E0GH8xhFVY0QzJoM=; b=fLCHUUNkmQDujZtVtblj+Zr0aey0ivB+dSQQvLzAvQkeYcoh7jIfzQFsrhbNHvaOLW +hLEaWuVc20PMzK0/QD1FYd6C3LckqLTUnVWcz3vuaNVFTNTFkLLH0M/DDmhtoJe4mTx yFfJkQdd00nLB3WeTP2yWJkEQR6ywUUf0TpUu3zNagBzuQSMuBjJrgoC/pA+YytA4Que ET4hKkbo6ptiHq75QswTfqUlz6fIpsCe7W0x44dzHgm56RYBUTCiemYNu1rzMXcF4gT3 dKULmC/wgr4CkTwjNUXNX7ArQa8rBqgjvfF2drd+ZOmIgBxCFhVfniu5KHLw7S0xlhQU AwRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704204220; x=1704809020; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MCe7bi22I9OO+O1jPW0w/LAeUi3E0GH8xhFVY0QzJoM=; b=Ox85IbzxNNvr0Rw/YPdMMlZmGBlqJc7J5Rnyyz55fo2MQ/Y/b++j98Ledkxcdwbmxu VFmILtbz4QehaNRHPpSP/2K4w5HvQrjNs7qrZvTrjV/Oj+1tpBWXF1CMfiD42M/Mo57B 2ILv70QKmAfyPM3M6G5iYlUQsaPbmjMGYC7jK01/Fmuo0iFohUFQCU9RPPT0oTMwV2Nh v5lGhxXQGHtoF1hjb5PQS08rDyHjGz3WAmOrXTkcJGAZdCY6q44ioIHYhh8RZLqZSkTg X/ykjw41SXNrLx5ysp1fODHRnYm8tHVVbHq/+v5aV69ish3yQkuIWZBtOBsrQYp0Xcvh G1XA== X-Gm-Message-State: AOJu0YxgZ3XUIypEC02qXirSIFUxKuQ9iLKtXSb48weYZ5kioXnwsaQ7 k4tDBSHeWUFZIW5BVybfLgs= X-Received: by 2002:adf:fa84:0:b0:336:b937:3d0e with SMTP id h4-20020adffa84000000b00336b9373d0emr9009616wrr.14.1704204219894; Tue, 02 Jan 2024 06:03:39 -0800 (PST) Received: from localhost.localdomain (host-87-10-250-100.retail.telecomitalia.it. [87.10.250.100]) by smtp.googlemail.com with ESMTPSA id e17-20020a5d5311000000b0033672cfca96sm28427527wrv.89.2024.01.02.06.03.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 06:03:39 -0800 (PST) From: Christian Marangi To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [net-next PATCH v2 3/4] net: phy: at803x: add support for cdt cross short test for qca808x Date: Tue, 2 Jan 2024 15:03:27 +0100 Message-ID: <20240102140330.7371-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240102140330.7371-1-ansuelsmth@gmail.com> References: <20240102140330.7371-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786987784233202845 X-GMAIL-MSGID: 1786987784233202845 QCA808x PHY Family supports Cable Diagnostic Test also for Cross Pair Short. Add all the define to make enable and support these additional tests. Cross Short test was previously disabled by default, this is now changed and enabled by default. In this mode, the mask changed a bit and length is shifted based on the fault condition. Signed-off-by: Christian Marangi --- drivers/net/phy/at803x.c | 86 ++++++++++++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 17 deletions(-) diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c index 9610b51a5928..3d3d34ef594c 100644 --- a/drivers/net/phy/at803x.c +++ b/drivers/net/phy/at803x.c @@ -254,6 +254,7 @@ #define QCA808X_CDT_ENABLE_TEST BIT(15) #define QCA808X_CDT_INTER_CHECK_DIS BIT(13) +#define QCA808X_CDT_STATUS BIT(11) #define QCA808X_CDT_LENGTH_UNIT BIT(10) #define QCA808X_MMD3_CDT_STATUS 0x8064 @@ -261,16 +262,44 @@ #define QCA808X_MMD3_CDT_DIAG_PAIR_B 0x8066 #define QCA808X_MMD3_CDT_DIAG_PAIR_C 0x8067 #define QCA808X_MMD3_CDT_DIAG_PAIR_D 0x8068 -#define QCA808X_CDT_DIAG_LENGTH GENMASK(7, 0) +#define QCA808X_CDT_DIAG_LENGTH_SAME_SHORT GENMASK(15, 8) +#define QCA808X_CDT_DIAG_LENGTH_CROSS_SHORT GENMASK(7, 0) #define QCA808X_CDT_CODE_PAIR_A GENMASK(15, 12) #define QCA808X_CDT_CODE_PAIR_B GENMASK(11, 8) #define QCA808X_CDT_CODE_PAIR_C GENMASK(7, 4) #define QCA808X_CDT_CODE_PAIR_D GENMASK(3, 0) -#define QCA808X_CDT_STATUS_STAT_FAIL 0 -#define QCA808X_CDT_STATUS_STAT_NORMAL 1 -#define QCA808X_CDT_STATUS_STAT_OPEN 2 -#define QCA808X_CDT_STATUS_STAT_SHORT 3 + +#define QCA808X_CDT_STATUS_STAT_TYPE GENMASK(1, 0) +#define QCA808X_CDT_STATUS_STAT_FAIL FIELD_PREP_CONST(QCA808X_CDT_STATUS_STAT_TYPE, 0) +#define QCA808X_CDT_STATUS_STAT_NORMAL FIELD_PREP_CONST(QCA808X_CDT_STATUS_STAT_TYPE, 1) +#define QCA808X_CDT_STATUS_STAT_SAME_OPEN FIELD_PREP_CONST(QCA808X_CDT_STATUS_STAT_TYPE, 2) +#define QCA808X_CDT_STATUS_STAT_SAME_SHORT FIELD_PREP_CONST(QCA808X_CDT_STATUS_STAT_TYPE, 3) + +#define QCA808X_CDT_STATUS_STAT_MDI GENMASK(3, 2) +#define QCA808X_CDT_STATUS_STAT_MDI1 FIELD_PREP_CONST(QCA808X_CDT_STATUS_STAT_MDI, 1) +#define QCA808X_CDT_STATUS_STAT_MDI2 FIELD_PREP_CONST(QCA808X_CDT_STATUS_STAT_MDI, 2) +#define QCA808X_CDT_STATUS_STAT_MDI3 FIELD_PREP_CONST(QCA808X_CDT_STATUS_STAT_MDI, 3) + +/* NORMAL are MDI with type set to 0 */ +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_NORMAL QCA808X_CDT_STATUS_STAT_MDI1 +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_OPEN (QCA808X_CDT_STATUS_STAT_SAME_OPEN |\ + QCA808X_CDT_STATUS_STAT_MDI1) +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_SHORT (QCA808X_CDT_STATUS_STAT_SAME_SHORT |\ + QCA808X_CDT_STATUS_STAT_MDI1) +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_NORMAL QCA808X_CDT_STATUS_STAT_MDI2 +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_OPEN (QCA808X_CDT_STATUS_STAT_SAME_OPEN |\ + QCA808X_CDT_STATUS_STAT_MDI2) +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_SHORT (QCA808X_CDT_STATUS_STAT_SAME_SHORT |\ + QCA808X_CDT_STATUS_STAT_MDI2) +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_NORMAL QCA808X_CDT_STATUS_STAT_MDI3 +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_OPEN (QCA808X_CDT_STATUS_STAT_SAME_OPEN |\ + QCA808X_CDT_STATUS_STAT_MDI3) +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_SHORT (QCA808X_CDT_STATUS_STAT_SAME_SHORT |\ + QCA808X_CDT_STATUS_STAT_MDI3) + +/* Added for reference of existence but should be handled by wait_for_completion already */ +#define QCA808X_CDT_STATUS_STAT_BUSY (BIT(1) | BIT(3)) #define QCA808X_MMD7_LED2_CTRL 0x8074 #define QCA808X_MMD7_LED2_FORCE_CTRL 0x8075 @@ -2008,8 +2037,17 @@ static int qca808x_soft_reset(struct phy_device *phydev) static bool qca808x_cdt_fault_length_valid(int cdt_code) { switch (cdt_code) { - case QCA808X_CDT_STATUS_STAT_SHORT: - case QCA808X_CDT_STATUS_STAT_OPEN: + case QCA808X_CDT_STATUS_STAT_SAME_SHORT: + case QCA808X_CDT_STATUS_STAT_SAME_OPEN: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_NORMAL: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_OPEN: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_SHORT: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_NORMAL: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_OPEN: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_SHORT: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_NORMAL: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_OPEN: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_SHORT: return true; default: return false; @@ -2021,17 +2059,28 @@ static int qca808x_cable_test_result_trans(int cdt_code) switch (cdt_code) { case QCA808X_CDT_STATUS_STAT_NORMAL: return ETHTOOL_A_CABLE_RESULT_CODE_OK; - case QCA808X_CDT_STATUS_STAT_SHORT: + case QCA808X_CDT_STATUS_STAT_SAME_SHORT: return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; - case QCA808X_CDT_STATUS_STAT_OPEN: + case QCA808X_CDT_STATUS_STAT_SAME_OPEN: return ETHTOOL_A_CABLE_RESULT_CODE_OPEN; + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_NORMAL: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_OPEN: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_SHORT: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_NORMAL: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_OPEN: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_SHORT: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_NORMAL: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_OPEN: + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_SHORT: + return ETHTOOL_A_CABLE_RESULT_CODE_CROSS_SHORT; case QCA808X_CDT_STATUS_STAT_FAIL: default: return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; } } -static int qca808x_cdt_fault_length(struct phy_device *phydev, int pair) +static int qca808x_cdt_fault_length(struct phy_device *phydev, int pair, + int result) { int val; u32 cdt_length_reg = 0; @@ -2057,7 +2106,11 @@ static int qca808x_cdt_fault_length(struct phy_device *phydev, int pair) if (val < 0) return val; - val = FIELD_GET(QCA808X_CDT_DIAG_LENGTH, val); + if (result == ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT) + val = FIELD_GET(QCA808X_CDT_DIAG_LENGTH_SAME_SHORT, val); + else + val = FIELD_GET(QCA808X_CDT_DIAG_LENGTH_CROSS_SHORT, val); + return at803x_cdt_fault_length(val); } @@ -2105,8 +2158,8 @@ static int qca808x_cable_test_start(struct phy_device *phydev) static void qca808x_cable_test_get_pair_status(struct phy_device *phydev, u8 pair, u16 status) { + int length, result; u16 pair_code; - int length; switch (pair) { case ETHTOOL_A_CABLE_PAIR_A: @@ -2123,11 +2176,11 @@ static void qca808x_cable_test_get_pair_status(struct phy_device *phydev, u8 pai break; } - ethnl_cable_test_result(phydev, pair, - qca808x_cable_test_result_trans(pair_code)); + result = qca808x_cable_test_result_trans(pair_code); + ethnl_cable_test_result(phydev, pair, result); if (qca808x_cdt_fault_length_valid(pair_code)) { - length = qca808x_cdt_fault_length(phydev, pair); + length = qca808x_cdt_fault_length(phydev, pair, result); ethnl_cable_test_fault_length(phydev, pair, length); } } @@ -2139,8 +2192,7 @@ static int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finish *finished = false; val = QCA808X_CDT_ENABLE_TEST | - QCA808X_CDT_LENGTH_UNIT | - QCA808X_CDT_INTER_CHECK_DIS; + QCA808X_CDT_LENGTH_UNIT; ret = at803x_cdt_start(phydev, val); if (ret) return ret;