From patchwork Tue Jan 2 14:03:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 184361 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4463067dyb; Tue, 2 Jan 2024 06:05:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IEoZCVnDghKz1egjEz4woA3ODjyI1ptJrj93ul/fTPfmK8+aNMdcS73z6YBP5dwlCRUzXc2 X-Received: by 2002:a17:903:44b:b0:1d3:838f:156 with SMTP id iw11-20020a170903044b00b001d3838f0156mr6635248plb.121.1704204358067; Tue, 02 Jan 2024 06:05:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704204358; cv=none; d=google.com; s=arc-20160816; b=Hq7MOyz5vKFA9HBYgmLM9Qu49jx/Rr5maKneY7NkJqDle3yuz2VfnGkhakm8sW5iCv EYy9g8kQkaNd4uQxDT5LmiVU5qx43Q65x/LAxwIYVQaag8i9qtsve6EbSPYeT6fV8RPc ROcxK9xsI9wrYEV5aHdc5nTO5fCJW5FZYUQuWC7uScO66Y5GPFe1knWZsSaswt48t9mH Con7cwNkDEp7iaIrV+xu+rumI/Cm1om1hYOKiJxxZuS97+t1Z5ooYD56doXbwHaLhHTV faBJ0cKLZdnZPAHIHlwa+AesL4dB461gSwhbD8/VUwQhHSSsnMqfAJzoZl8eKIIbCtf8 IETw== 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=lsA0JDN11Q2nz8SUx5kA6LiRo/4zS6VELKeRkM4TXVA=; fh=utmrxdkgikAlLxVfQI1kldUG+rNjhrLN+3fAlOYj01s=; b=gzlkGY1MFFb+Z7DZCT1HY37HBzbJeaYVaCe70osuPevIo67rtwXRYz5j1QCnaCswUy VNKs0uztcvyLdWP2YiEQVPYnPfBuyZQT6aUHH82URSQwweXjr4Zgz7Vfizq2qWrLrYIR lIMpPd7nfXf4nYwQ1OLbr0BCX6pc6Qs7HqeizXzJCUUT3Gx1NUarJE1rR+wWIcMPISlQ KtOIGshAF4YZ2G/0bZdyDi2ZnfzNUfF0dQXU4ovlmR6s7v9w1bg7cSTXrIPbHAetV1Cp K9Pg02F5YQNKTYMWbdi2GAdkS9TX27hAHMdELIptP+vL7ne7PtptAIG8fXjZTsVRCMnS tQoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OZM2Fg+s; spf=pass (google.com: domain of linux-kernel+bounces-14457-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14457-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id l17-20020a170902f69100b001d3e44faf1bsi20360691plg.242.2024.01.02.06.05.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 06:05:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14457-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OZM2Fg+s; spf=pass (google.com: domain of linux-kernel+bounces-14457-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14457-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 545F4B222DD for ; Tue, 2 Jan 2024 14:05:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C16E14F75; Tue, 2 Jan 2024 14:03:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OZM2Fg+s" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 0C1A911704; Tue, 2 Jan 2024 14:03:39 +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-wm1-f47.google.com with SMTP id 5b1f17b1804b1-40d8e7a50c1so1611995e9.2; Tue, 02 Jan 2024 06:03:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704204218; x=1704809018; 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=lsA0JDN11Q2nz8SUx5kA6LiRo/4zS6VELKeRkM4TXVA=; b=OZM2Fg+skPXGCyBQJKo57m5mD6aNcZCZsqlMcRxX2ZotQXN4yI7Y8y5B1OESfyDdT5 +ZJAFRSnqM/kLDIYj5kJ8TBj4+A/lXMEJB7GeWQ222HXprEQWZ2wTLV5Ee2TaGGWeOq1 PR7qdkEuuTSSKtW81woIcOSDyS3b66EuZ7FttPdRqX0hKuAnsLdvDrpM/NbmxwYA+Dni rcSjy91n+cCWh8Ryoe0KpHqWXjsupA7KLVDdHK76VBIhOkCFdO+gPrVPm57zxbDQeDD9 uyMUf3QHOT2iRiYxdgGbUXhj/1faJsVIgTHZ+WXSZmsUF/UmFFA4nzfXri/XrA4r3Jg6 oZeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704204218; x=1704809018; 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=lsA0JDN11Q2nz8SUx5kA6LiRo/4zS6VELKeRkM4TXVA=; b=OmJnbu8cMmocmHp1gR/RnOK0gEDHNC6/F39XXo156Z2NWpTO22VyNNdYtB1VxOLZXO 0/hrMl2doLYFN7xLEq6ZJytX/feqiKeWfcjX6pN61syH5mRIKa/BbBJZAR/T6Ddj1P/P aTzKQ+LUaclloFUBH6BPu88ZsjQHByMQDlX7bth33BO9rgKQjXZiNIh0LM9eQdHLB8bx dWK3GGRHTFBo9oZlgFjG4YNu8hpd2vi7/ikQHXV2qiuj+wgAOdk+//TR70KPv4jCQeAu 7twxijmpBBbVR2WlhFR1nbtnXNThy8anWwtcCNKZ5rIXi6sNZCf2mqtc14bHw7KtwowB tqrg== X-Gm-Message-State: AOJu0Yyw+cxiFOAmryyga/v5bq5Plnvr3Sd6/+D8p4HkYVatAPZv1n6b hXwHele6RSZ9fsaqsOMWxsM= X-Received: by 2002:a7b:c4cc:0:b0:40d:88c4:a59e with SMTP id g12-20020a7bc4cc000000b0040d88c4a59emr1239494wmk.164.1704204218226; Tue, 02 Jan 2024 06:03:38 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 06:03:37 -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 2/4] net: phy: at803x: refactor qca808x cable test get status function Date: Tue, 2 Jan 2024 15:03:26 +0100 Message-ID: <20240102140330.7371-3-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: 1786987788536674980 X-GMAIL-MSGID: 1786987788536674980 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 072bcd670ef0..9610b51a5928 100644 --- a/drivers/net/phy/at803x.c +++ b/drivers/net/phy/at803x.c @@ -2102,10 +2102,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; @@ -2124,36 +2153,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;