From patchwork Wed Jan 3 12:46:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13509983 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 399A619442; Wed, 3 Jan 2024 12:46:52 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QekCfjTI" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-40d894764e7so22499105e9.1; Wed, 03 Jan 2024 04:46:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704286010; x=1704890810; 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=mndGvtpI2oeo6GQDcXQC8VQnYdadwT7o6axDFA5/9kY=; b=QekCfjTIL8QQj5Qe+8uR6eAWOlRqBAcLned5f27TgXvSPU32Qo6lLGnCtOUK94vYJH d6ZlCDduT6KD+TxB6ZQNQSLxDxHy3vCYKvGdtwF6T6hY5l8qfO56QBluN6VHDhktGt6b /E0aEGL9lq0RvyJPZr6N2N1wX4x2Y8GYU99Ls/Bn+qNTCpj0SYS3BoUbSPEtJGMukjMV j97s83+cSQALXLTEi/bfvf0Fl+NAfGqYvm/Jk6F6AeKcY8QoT26lWQLF8DSVZXzOURsu wE28t5Q4amt8Uj2m6icv05dYBC7jX6mhDwp/jC3ydF1YPf9IM59mVtHMhR+0dUh/22mK oZOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704286010; x=1704890810; 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=mndGvtpI2oeo6GQDcXQC8VQnYdadwT7o6axDFA5/9kY=; b=dAO+moEnP2fHxB0OJLWnGKqwJ2wJaQkuMJmUfxMp1IigxAUnc01wGDlOs9RWNhW4GX 5z726PqhtBIOyC0TP7cy7aQovD55RupynsnlCVBh5nlntEg+TnDAWqwxo/svRK0bLU2R sDYy0Hzb7SUUkcVYJRVcMihllht0qB0PZTccNPLUMFqqCWHLZm9ieLHjf5Y1e4t2QsZI UYueXs96o3AlzzRfKZ6OBeDbdE/MODQnSikgaflxpBBxQUlIN1NaE2/j4TiGb9f7YfTU KyKlxWgtv2ZrK2NtU8bsCkqLgkP6pil1+JEjVNpM/dVWn8FO1+Jce92JGkAJ1K0huLR8 v7qg== X-Gm-Message-State: AOJu0YzYsHHg6HU/wS2Q0rIxlTvT1fIqploikDZoCQEPidZDYC/Lw+Hu P5x6mouY33taXQn0hPZxX0g= X-Google-Smtp-Source: AGHT+IGp2MrNzRY01sihvbJWIm3HjemQ8W8vu82Brf0FhPLaENaKlgHggNj427GoV3Ybg3qDuDgqzQ== X-Received: by 2002:a05:600c:1c11:b0:40d:88fd:e1 with SMTP id j17-20020a05600c1c1100b0040d88fd00e1mr1453451wms.24.1704286010370; Wed, 03 Jan 2024 04:46:50 -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 fc16-20020a05600c525000b0040d5c58c41dsm2219676wmb.24.2024.01.03.04.46.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 04:46:49 -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 v3 1/4] net: phy: at803x: generalize cdt fault length function Date: Wed, 3 Jan 2024 13:46:32 +0100 Message-ID: <20240103124637.3078-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240103124637.3078-1-ansuelsmth@gmail.com> References: <20240103124637.3078-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Generalize cable test fault length function since they all base on the same magic values (already reverse engineered to understand the meaning of it) to have consistenct values on every PHY. Signed-off-by: Christian Marangi Reviewed-by: Simon Horman --- drivers/net/phy/at803x.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c index aaf6c654aaed..acf483fa0887 100644 --- a/drivers/net/phy/at803x.c +++ b/drivers/net/phy/at803x.c @@ -1192,10 +1192,8 @@ static bool at803x_cdt_fault_length_valid(u16 status) return false; } -static int at803x_cdt_fault_length(u16 status) +static int at803x_cdt_fault_length(int dt) { - int dt; - /* According to the datasheet the distance to the fault is * DELTA_TIME * 0.824 meters. * @@ -1211,8 +1209,6 @@ static int at803x_cdt_fault_length(u16 status) * With a VF of 0.69 we get the factor 0.824 mentioned in the * datasheet. */ - dt = FIELD_GET(AT803X_CDT_STATUS_DELTA_TIME_MASK, status); - return (dt * 824) / 10; } @@ -1265,9 +1261,11 @@ static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair) ethnl_cable_test_result(phydev, ethtool_pair[pair], at803x_cable_test_result_trans(val)); - if (at803x_cdt_fault_length_valid(val)) + if (at803x_cdt_fault_length_valid(val)) { + val = FIELD_GET(AT803X_CDT_STATUS_DELTA_TIME_MASK, val); ethnl_cable_test_fault_length(phydev, ethtool_pair[pair], at803x_cdt_fault_length(val)); + } return 1; } @@ -1994,7 +1992,8 @@ static int qca808x_cdt_fault_length(struct phy_device *phydev, int pair) if (val < 0) return val; - return (FIELD_GET(QCA808X_CDT_DIAG_LENGTH, val) * 824) / 10; + val = FIELD_GET(QCA808X_CDT_DIAG_LENGTH, val); + return at803x_cdt_fault_length(val); } static int qca808x_cable_test_start(struct phy_device *phydev) From patchwork Wed Jan 3 12:46:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13509984 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 A8C461946B; Wed, 3 Jan 2024 12:46:53 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AfUaXq8i" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3366e78d872so10037963f8f.3; Wed, 03 Jan 2024 04:46:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704286012; x=1704890812; 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=XCJqZdq/iqlteXCIkR1kOvJH/pGADA5Hu358ETfwzNc=; b=AfUaXq8i4gzX5Cr8POjULLsWuAI9CKSmUcLkoZ5qAtyot0H2gULh2UXLs1cMiiRFdl rBkpadouheHNioCl4MAs2wexM8UHTD2tvkI8jUV144WrjsQnmF1XmQ01zZ/uPefLK/oh +TdJw1sQx14b2vu6zMnyCO3zTnBAyjsG7Ya3m+W4IYMRvJxKvdNV/jG5TD5AJsdWPl8q I8QoK43xQk4jXHre4iRKjQLK5GEq8UeFvQF1VDOQTZru1uKvxpTBlF7GViGls3ElBDFi dT0J2Qxq4+KNwbC2BCZOqO3wBu8zkDq7NQ+1L4INVe7uDN/jfzzbmwxFPs9jOvDrSK3O UMYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704286012; x=1704890812; 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=XCJqZdq/iqlteXCIkR1kOvJH/pGADA5Hu358ETfwzNc=; b=gzKH6mpKaKFEJRdgTbpF5TGomyqYuR6DD2vKWTxeYbux0vyNE7oQUYxefuGThd4x1u X5Uo3mMvRE7JvXEh5az3xT3d6UVQuLaUYNGH0lMv6GD+YuHiE66tY1phHKJ9dpuW2CYo wo8fS+l/RXeTXHt7WJEIYCFIHzDUi5/BxLOgsDp4z+YMsJ/e5bgFvZWxIrr/RV+wq7y2 TVO5mI57kMaNAp+SfNX/TdxtSHOgBHfHcl7SXg5413jWjazsRxokCJOYCPc+yIvgqEo7 cbdFvGcmqA2OO4R2HljlxOArVfMHB3xcj9qQzSiDM3TP81E1XMhvKDarnPkFkqQyPZl+ X5pA== X-Gm-Message-State: AOJu0YwvKXzv1D53F/65NTsNqpwX+Uj1vh2BZnSszBVmBcsMN1bKZSTb W9cKeiNysRT52mrntBk1CvE= X-Google-Smtp-Source: AGHT+IFsHG+aL1d2o3l8gkE3tvPrX7dtHc1YZa0s7VMNnweJcK9cu64DMQ1jLm7U9VpDEoSWAG5Qlw== X-Received: by 2002:a05:600c:3c94:b0:40d:62f9:8e5f with SMTP id bg20-20020a05600c3c9400b0040d62f98e5fmr2631717wmb.214.1704286011846; Wed, 03 Jan 2024 04:46:51 -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 fc16-20020a05600c525000b0040d5c58c41dsm2219676wmb.24.2024.01.03.04.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 04:46:51 -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 v3 2/4] net: phy: at803x: refactor qca808x cable test get status function Date: Wed, 3 Jan 2024 13:46:33 +0100 Message-ID: <20240103124637.3078-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240103124637.3078-1-ansuelsmth@gmail.com> References: <20240103124637.3078-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Refactor qca808x cable test get status function to remove code duplication and clean things up. The same logic is applied to each pair hence it can be generalized and moved to a common function. Signed-off-by: Christian Marangi --- drivers/net/phy/at803x.c | 65 +++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c index acf483fa0887..b87293ee736c 100644 --- a/drivers/net/phy/at803x.c +++ b/drivers/net/phy/at803x.c @@ -2037,10 +2037,39 @@ static int qca808x_cable_test_start(struct phy_device *phydev) return 0; } +static void qca808x_cable_test_get_pair_status(struct phy_device *phydev, u8 pair, + u16 status) +{ + u16 pair_code; + int length; + + switch (pair) { + case ETHTOOL_A_CABLE_PAIR_A: + pair_code = FIELD_GET(QCA808X_CDT_CODE_PAIR_A, status); + break; + case ETHTOOL_A_CABLE_PAIR_B: + pair_code = FIELD_GET(QCA808X_CDT_CODE_PAIR_B, status); + break; + case ETHTOOL_A_CABLE_PAIR_C: + pair_code = FIELD_GET(QCA808X_CDT_CODE_PAIR_C, status); + break; + case ETHTOOL_A_CABLE_PAIR_D: + pair_code = FIELD_GET(QCA808X_CDT_CODE_PAIR_D, status); + break; + } + + ethnl_cable_test_result(phydev, pair, + qca808x_cable_test_result_trans(pair_code)); + + if (qca808x_cdt_fault_length_valid(pair_code)) { + length = qca808x_cdt_fault_length(phydev, pair); + ethnl_cable_test_fault_length(phydev, pair, length); + } +} + static int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finished) { int ret, val; - int pair_a, pair_b, pair_c, pair_d; *finished = false; @@ -2059,36 +2088,10 @@ static int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finish if (val < 0) return val; - pair_a = FIELD_GET(QCA808X_CDT_CODE_PAIR_A, val); - pair_b = FIELD_GET(QCA808X_CDT_CODE_PAIR_B, val); - pair_c = FIELD_GET(QCA808X_CDT_CODE_PAIR_C, val); - pair_d = FIELD_GET(QCA808X_CDT_CODE_PAIR_D, val); - - ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A, - qca808x_cable_test_result_trans(pair_a)); - ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B, - qca808x_cable_test_result_trans(pair_b)); - ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_C, - qca808x_cable_test_result_trans(pair_c)); - ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_D, - qca808x_cable_test_result_trans(pair_d)); - - if (qca808x_cdt_fault_length_valid(pair_a)) { - val = qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A); - ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A, val); - } - if (qca808x_cdt_fault_length_valid(pair_b)) { - val = qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B); - ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B, val); - } - if (qca808x_cdt_fault_length_valid(pair_c)) { - val = qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C); - ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C, val); - } - if (qca808x_cdt_fault_length_valid(pair_d)) { - val = qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D); - ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D, val); - } + qca808x_cable_test_get_pair_status(phydev, ETHTOOL_A_CABLE_PAIR_A, val); + qca808x_cable_test_get_pair_status(phydev, ETHTOOL_A_CABLE_PAIR_B, val); + qca808x_cable_test_get_pair_status(phydev, ETHTOOL_A_CABLE_PAIR_C, val); + qca808x_cable_test_get_pair_status(phydev, ETHTOOL_A_CABLE_PAIR_D, val); *finished = true; From patchwork Wed Jan 3 12:46:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13509985 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.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 56497199C9; Wed, 3 Jan 2024 12:46:55 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="awWjsNRz" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-40d5336986cso102026845e9.1; Wed, 03 Jan 2024 04:46:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704286013; x=1704890813; 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=sLK5iCROUw8443l+GbLHNZT9zorVpYX24QDPt5c4KHg=; b=awWjsNRzxWzjNKbRpyb9EfVhZK4mOld2FfmKStzXa0GPLKb3ebDsARcXQE4YafpV9x CkHHg8k89tAHbVWVIXPAPu8hsFBr5Ou1tA2gvKPIcur+NyDrB84KXqnYoIOvnb2alkVK buWgznT2QcxQAcD6lw7SDWC9Dgy2xcBlH6+kSrDT/HmpC1MJnJ8nhssP7FQ0o9zWBvjH 7OkJ0LPqGcxpGGUxg1d+S6mSi7F2zwpUf8XF6ODV4r3NuggzZKDh5dU3AMgp3cCMK3qC Az7b1t3pKEuJYtk8pCWTHrFeanXClcf3SZLqqxPYU4dKmPhFh8ZHgqWimgbKMEhBJerm rf9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704286013; x=1704890813; 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=sLK5iCROUw8443l+GbLHNZT9zorVpYX24QDPt5c4KHg=; b=ppHcK/E+H3zVxYn5nChhTVgCPh4RApjt00JMCfFjS7Pb90F6+kScq1KAb51WWquvCj iBCRiryQEuxAaZ1Yesw2DAxwUKg8P2QNIlp0UhHUZfW3Lxi5eIEAT1Kq8fmLRG1XrPHk LDZtwlMogfGb8m8vhd0Af+glxzRKBT+FtzIm736wMFCSEgnH/Q1WmeNqcyxGRyNoerSL ABDahY9UwuuuldSRKYgRk02YXX6mVDad7z3CEariv66PuVtyv8rsBhnBuJT/NaTqogar K5T5UMaDmXdlXNzuXcP+2nmHtbWOBrPVjnAKBqblVsihsAvOlAcObOIHaliHy0MXFAfZ 5Kdg== X-Gm-Message-State: AOJu0Yw0ZGu7F0/p8rGjYUnnzVvtv7cY2xmqCAttjH3/0g+7SSnEDWVF JkKsxXLCkTKtDTVrm6D9fy0= X-Google-Smtp-Source: AGHT+IG32cRCa7TOIH2XjBjJ/8f2Vh/2f7l+rYA17uznCoenFXLhnD0FSqhL+U5UzMSSB0knY2kKuA== X-Received: by 2002:a05:600c:3652:b0:40d:5c54:9bb5 with SMTP id y18-20020a05600c365200b0040d5c549bb5mr6167204wmq.170.1704286013288; Wed, 03 Jan 2024 04:46:53 -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 fc16-20020a05600c525000b0040d5c58c41dsm2219676wmb.24.2024.01.03.04.46.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 04:46:52 -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 v3 3/4] net: phy: at803x: add support for cdt cross short test for qca808x Date: Wed, 3 Jan 2024 13:46:34 +0100 Message-ID: <20240103124637.3078-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240103124637.3078-1-ansuelsmth@gmail.com> References: <20240103124637.3078-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 b87293ee736c..d6dfe906cb62 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)) /* QCA808X 1G chip type */ #define QCA808X_PHY_MMD7_CHIP_TYPE 0x901d @@ -1943,8 +1972,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; @@ -1956,17 +1994,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; @@ -1992,7 +2041,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); } @@ -2040,8 +2093,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: @@ -2058,11 +2111,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); } } @@ -2074,8 +2127,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; From patchwork Wed Jan 3 12:46:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13509986 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 9CFF119BCD; Wed, 3 Jan 2024 12:46:56 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eaZjJE3F" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-40d5d898162so49165475e9.3; Wed, 03 Jan 2024 04:46:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704286015; x=1704890815; 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=pNLTRaIyuxFbq61p3RNSu84SuTxURa8ax70mY+8XCbA=; b=eaZjJE3FrALOPof5TAkwL+cqUXuQQn25OvqNuMRR8GYomJE7V+3MC5Vxe6cNPke/48 GIjB9ylhT2YXqBWqj1u93QDrf1HFUV04WqG36jZAxB/VwylqUfN3q7BucysNaivWTb5C vfaPywM/MRS+lNyrO2CSChSLU5TAIy6Bj2IJhtOFUON3MdC8PJTadS+yy136x4ZtToFt yVXOubwJfR3kz7Ffv05Un2KAL3aTYTBtpgapXk6KGhAR1Tng9G0WwGxeye2u8VZ+corU sGJn3PuCpgGg7g231+0+BlBEdrtBYS59eJuq49jEUqdCCgIijWuWfjUe4TT+gfrCpEsi HygA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704286015; x=1704890815; 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=pNLTRaIyuxFbq61p3RNSu84SuTxURa8ax70mY+8XCbA=; b=lV1m05mLjh1iVcLXhOhCNTCwjDHXwSueqlACrTTwgoslNXiPRvu0ELdriyR7PhAq0g mwkXfrKAyBwVz6H+QPsFFsRsa5ea2duXeC432T9OTu90gf5omesTLTT7dr1pTvRLagTN NZCK9CvgSNzkMl4sR4T9IcA/WR5YSq4zJ9vapiOI7V2xmr8UPeFOS+gT1xxaStDkJEDj FC0u9x+dwUtzE9LlL0nU3Hvd8UlKKBvSRSbOaOXV6rYaidIhzYw5Mkgrjhy8DitV8BwI 9AmFA+VkXzuYXBzmxA2BrWh+DKDdUZPpPPxjG6aEbLkrdgJdWA/IJXVGNuPrRyYKvh9E f6iA== X-Gm-Message-State: AOJu0Yw8V32+zycZ6pEM3VaWmQGxfUlqMcuKlQEjbmEKt5SJ7KkkCJer 811UsOR9cD6x6o3HVcbBzls= X-Google-Smtp-Source: AGHT+IGh1e7o8Es+BEwB6mEpjbTB9s70LeHZYOx0AqeMMz94p/WWtsf/PtngFsIodfZoSirJa7y8IQ== X-Received: by 2002:a05:600c:5409:b0:40c:2b29:1bbe with SMTP id he9-20020a05600c540900b0040c2b291bbemr10967229wmb.54.1704286014598; Wed, 03 Jan 2024 04:46:54 -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 fc16-20020a05600c525000b0040d5c58c41dsm2219676wmb.24.2024.01.03.04.46.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 04:46:54 -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 v3 4/4] net: phy: at803x: make read_status more generic Date: Wed, 3 Jan 2024 13:46:35 +0100 Message-ID: <20240103124637.3078-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240103124637.3078-1-ansuelsmth@gmail.com> References: <20240103124637.3078-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Make read_status more generic in preparation on moving it to shared library as other PHY Family Driver will have the exact same implementation. The only specific part was a check for AR8031/33 if 1000basex was used. The check is moved to a dedicated function specific for those PHYs. Signed-off-by: Christian Marangi --- drivers/net/phy/at803x.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c index d6dfe906cb62..6f64a809e413 100644 --- a/drivers/net/phy/at803x.c +++ b/drivers/net/phy/at803x.c @@ -1020,13 +1020,9 @@ static int at803x_read_specific_status(struct phy_device *phydev, static int at803x_read_status(struct phy_device *phydev) { - struct at803x_priv *priv = phydev->priv; struct at803x_ss_mask ss_mask = { 0 }; int err, old_link = phydev->link; - if (priv->is_1000basex) - return genphy_c37_read_status(phydev); - /* Update the link, but return if there was an error */ err = genphy_update_link(phydev); if (err) @@ -1620,6 +1616,17 @@ static int at8031_config_intr(struct phy_device *phydev) return at803x_config_intr(phydev); } +/* AR8031 and AR8033 share the same read status logic */ +static int at8031_read_status(struct phy_device *phydev) +{ + struct at803x_priv *priv = phydev->priv; + + if (priv->is_1000basex) + return genphy_c37_read_status(phydev); + + return at803x_read_status(phydev); +} + /* AR8031 and AR8035 share the same cable test get status reg */ static int at8031_cable_test_get_status(struct phy_device *phydev, bool *finished) @@ -2268,7 +2275,7 @@ static struct phy_driver at803x_driver[] = { .read_page = at803x_read_page, .write_page = at803x_write_page, .get_features = at803x_get_features, - .read_status = at803x_read_status, + .read_status = at8031_read_status, .config_intr = at8031_config_intr, .handle_interrupt = at803x_handle_interrupt, .get_tunable = at803x_get_tunable,