From patchwork Tue Mar 26 14:12:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13604275 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 CD83A12BF02; Tue, 26 Mar 2024 14:13:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711462384; cv=none; b=F7vjHb9cqR6MWYHEH4uTWbnGICNtXDFI6eW3NcPN1JEfV6adWV/YpU7TAOlxQlV6H1E71GDPPNi21CCmOZ28/cPkfZikhiwtp5AxQdNRG9zqGtTIAq0l57QQkwzsXzw68jyOZvwLy8LEXTwb7iqgIC7TQkJ+29G7GzhQURG1nEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711462384; c=relaxed/simple; bh=FhtNZLQWuyLFu7dDdT12isku2y5LiTvNqB0gI4titEg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=u+ujBrZfXeBgMmNxD0mxp2SDGw/69OYpKvUz3bzKvlTfiGuLZrN3BbZysVsPMfNIz7L5seYIpNngGwUW9l6nM3adTE5HVYVChjP58KcRjst7529Fyy8+rlye3Kqe5Sktojv3L4BkL7FUZ2hRzpjq+B1BA4/YnaA4x3wJcXX2o/w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IdbRuFIM; arc=none smtp.client-ip=209.85.218.53 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="IdbRuFIM" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a45f257b81fso648644966b.0; Tue, 26 Mar 2024 07:13:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711462380; x=1712067180; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qLHRRxSI4Hl56G/+UarRDoZK1Wj/9ZIxTRiWiXAgPnQ=; b=IdbRuFIMs/SGOMn8ny5swhNJSlNNOM7bfKJRbY2tHZSOsjf7Dhc6Su17D+i8nfs5Gl Ji0ATmQM1n3c48/gCeempYK6psQ1k4PI3Oo0LIlPGpXlrkNyoguXC8JVV1AarixvhHWT MoJ9LpxGapL7moKZOEbo2yF38dpXgwlzbSi+xpEek1kLKZ+7U/0VObrcT8Q+9A+cRmki G15QXlT+uZF6/yOQbGfsq6Vz9n2ShedcA8J6FDa5OKpBN8FAj8/IBnhd/lKYUE7F9uQP iwcJecQKzvSY/DD2B54QswSZGzmjFw6+UJ7hEhBsR1Z/qH4nJ11X9iqMG9KUxFt1MCzb zVyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711462380; x=1712067180; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qLHRRxSI4Hl56G/+UarRDoZK1Wj/9ZIxTRiWiXAgPnQ=; b=ttp/ySxlYu6iO0Kpve7uYKjHLqHlKgdO3jKBbGuvGYLhwpYiVe7Oo0P7G1EZIo+W75 Z/oUo6FX14YSbOe0FDhqVzoGcrkMUaRzKjrf5YZIo8XDTU5sv/kRMZySsBXpivaTlvUz JaBM+xGgnzv7YakmW9j7ro5Yf72HLJCH2H+mjxksoff6JF9M2br1hL4LPzwtZt8NuVf9 U2HPS3dTnqGTLU/8HED85QK/jioL2titcXG6YVvw/mhzL7oKtVnNyBWirPAVaC1h7EL3 Eknjx+qscAH/I0vhityQhIrmqyhyMGnQsz/j6eQL108Nl9CQwDJW0jhd6aunBFGlTxWk 9xMw== X-Forwarded-Encrypted: i=1; AJvYcCXxrRzQO5ZISxiotkgxxxy3sbeNZe3tRyC5yKtlNeV8+cNpPhhBz2x6KVxUHBvedcJcDv/LVh7NPwAb9gi21ueCT/Jh1cAia1QmalZC X-Gm-Message-State: AOJu0YxWYr1rRcCt0yMUynhcWEUqiuTxyEQ6rcxbgcv/Qp3VKfryeuLn 27TRCr8AWAxA/oDymryDCFXk3uNEOLZ0FA2mwGdseVY/Gu3LQHAr93e+j6f65rI= X-Google-Smtp-Source: AGHT+IGsVcoN+1x6FIYzS/p2U4qw+4XpV/UTj6G66QyIUFm13sLxUw+Smj8kV0oO3H0gHD5xJtVXBg== X-Received: by 2002:a17:906:33d2:b0:a47:31aa:142d with SMTP id w18-20020a17090633d200b00a4731aa142dmr7382520eja.70.1711462380393; Tue, 26 Mar 2024 07:13:00 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id t21-20020a170906179500b00a468bf8586bsm4324094eje.174.2024.03.26.07.12.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 07:12:59 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Pawel Dembicki , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Stefan Eichenberger , Dimitri Fedrau , linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/2] net: phy: marvell: add basic support of 88E308X/88E609X family Date: Tue, 26 Mar 2024 15:12:35 +0100 Message-Id: <20240326141238.2315974-1-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 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 This patch implements only basic support. It covers PHY used in multiple IC: PHY: 88E3082, 88E3083 Switch: 88E6096, 88E6097 Signed-off-by: Pawel Dembicki --- drivers/net/phy/marvell.c | 13 +++++++++++++ include/linux/marvell_phy.h | 1 + 2 files changed, 14 insertions(+) diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index 42ed013385bf..fae7eb57ee2c 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -3289,6 +3289,18 @@ static struct phy_driver marvell_drivers[] = { .get_strings = marvell_get_strings, .get_stats = marvell_get_stats, }, + { + .phy_id = MARVELL_PHY_ID_88E3082, + .phy_id_mask = MARVELL_PHY_ID_MASK, + .name = "Marvell 88E308X/88E609X Family", + /* PHY_BASIC_FEATURES */ + .probe = marvell_probe, + .config_init = marvell_config_init, + .aneg_done = marvell_aneg_done, + .read_status = marvell_read_status, + .resume = genphy_resume, + .suspend = genphy_suspend, + }, { .phy_id = MARVELL_PHY_ID_88E1112, .phy_id_mask = MARVELL_PHY_ID_MASK, @@ -3742,6 +3754,7 @@ module_phy_driver(marvell_drivers); static struct mdio_device_id __maybe_unused marvell_tbl[] = { { MARVELL_PHY_ID_88E1101, MARVELL_PHY_ID_MASK }, + { MARVELL_PHY_ID_88E3082, MARVELL_PHY_ID_MASK }, { MARVELL_PHY_ID_88E1112, MARVELL_PHY_ID_MASK }, { MARVELL_PHY_ID_88E1111, MARVELL_PHY_ID_MASK }, { MARVELL_PHY_ID_88E1111_FINISAR, MARVELL_PHY_ID_MASK }, diff --git a/include/linux/marvell_phy.h b/include/linux/marvell_phy.h index 693eba9869e4..88254f9aec2b 100644 --- a/include/linux/marvell_phy.h +++ b/include/linux/marvell_phy.h @@ -7,6 +7,7 @@ /* Known PHY IDs */ #define MARVELL_PHY_ID_88E1101 0x01410c60 +#define MARVELL_PHY_ID_88E3082 0x01410c80 #define MARVELL_PHY_ID_88E1112 0x01410c90 #define MARVELL_PHY_ID_88E1111 0x01410cc0 #define MARVELL_PHY_ID_88E1118 0x01410e10 From patchwork Tue Mar 26 14:12:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13604276 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.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 EACB712DDA0; Tue, 26 Mar 2024 14:13:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711462395; cv=none; b=urlkuIUIuN82JYqR6GH59DEz7G2bHP/Yc3hy0ITNEtFAMezgI6PvdqCZLF5OFH3rF0GfYc/6rYj5g6pIG64VSiARMvZucEivHqKO5FNPRnFAxrJLSWH7gx7PNf0OkuTm2SRTpG1r7lrBdWBPLDyWjSsCeVBY4qU/Nkj/PL7+sY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711462395; c=relaxed/simple; bh=rd+GujPVaOvUJwVylR9IElXqqM9cFOri2AQWjsbGONw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SUmTrZd57THE0gMWt8+4kXAa8DO0hAlduiVG5aNO0GPJAErGdNgxUUrpYi/h6tcBETmC3mIauDlKIZm7T+p//lhm3AzU6L/Ze1mt0IdFrChLAS+ur4ZEZNK452Akasl0j2ODIK59hY8MUmAdwVjLyUqLjhh1sOkGWKzo2kMtCCU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AaUcad1r; arc=none smtp.client-ip=209.85.218.43 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="AaUcad1r" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a46ea03c2a5so963740166b.1; Tue, 26 Mar 2024 07:13:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711462392; x=1712067192; 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=KFsmieGNc1bxhgiMa27ija0tbeAhS5xqyMs1Xxv+l1U=; b=AaUcad1rYQMBc9IvxTfJqUIoIx4B6an9eRIxAxlYuCuNgjdRYu879YUJCoO88yRSP8 /7p01pxsALuRpTgqMEr38VsrcHnx1I6ioipeTp0gbCov+58uxiXJl+pYm7cnaNOJyh6c xF6eFXgEMynXYEtcszpTAGIfrN5DmVrRLDBJxJC1phgoT/Yje/zAQqnezSCHfAifH5JW FZkZ6Z0Iswee03co/PDP9YkG0KChp95E+d7LCZBTnH/qTVhmhcFIE6hFPfTjtvwMdd9A 63RqeG1ILA9JqVVCw4Z91RsGOfHvaO/TgVb+uw/BkHHP0Uksj+ymqngqEDE8W5eiReAY wQUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711462392; x=1712067192; 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=KFsmieGNc1bxhgiMa27ija0tbeAhS5xqyMs1Xxv+l1U=; b=oQ/2emhnwaZMiSF2FkJ/i8ZcdugiV/llY2Ks+SKLIy4MdhRPsd5BnjUwk8aML/PD+P tCBoFhx9NuVH6NvnmX3PiFZQyFUYos8bkpFyG2jhXmY43/8ce97eF0OxKByueLXk8A0A +vzSNJkVj2QO5XmbE46TWEGN76EGU/KvBmWefY+K9px4OfajQBssI6oqTHJNaKi2+vNY nnnqG7QriMi2raCScshwYDtggx7nGOKc8j34stp8U9OT0u3AtB+NhO5oj32oPtrVaaiY Gldwd8xkLkP8t6lCIY2NHGdFXKF25NugSlQw5DdWHN2DKQsMJVeRXhv3SBzJazIZduvx 0N3Q== X-Forwarded-Encrypted: i=1; AJvYcCUmNA7ceNL06EtqHR5Ad5fV67vB4kUaRLl4ZuRwQIM0jPs0Nb4tqDnss/5ND9OJPWHKquIocZ7THSlKbiwC2UHWx73YvdJq19sMUnjI X-Gm-Message-State: AOJu0YwRHgixYsVBoSWgz0FvTmTi9HIHj2GzIBubqlOlxLeOtCra7n8F 8NQe8E1WM3Cf93DbqFIOqOpJICMyvpGOxpqmfQvkXWVGFkml7blpgmCNXL7r9q4= X-Google-Smtp-Source: AGHT+IHfrfujSOFtGoOI11tvJv/NxuhsnlchHAmi90dsftBI3Cy4Qw+45xXPIwfUh7W0aLbMrHs+Bw== X-Received: by 2002:a17:906:5ad7:b0:a46:ab93:9848 with SMTP id x23-20020a1709065ad700b00a46ab939848mr1452245ejs.26.1711462391616; Tue, 26 Mar 2024 07:13:11 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id t21-20020a170906179500b00a468bf8586bsm4324094eje.174.2024.03.26.07.13.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 07:13:11 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Pawel Dembicki , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Stefan Eichenberger , Dimitri Fedrau , linux-kernel@vger.kernel.org Subject: [PATCH net-next 2/2] net: phy: marvell: implement cable-test for 88E308X/88E609X family Date: Tue, 26 Mar 2024 15:12:36 +0100 Message-Id: <20240326141238.2315974-2-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240326141238.2315974-1-paweldembicki@gmail.com> References: <20240326141238.2315974-1-paweldembicki@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 This commit implements VCT in 88E308X/88E609X Family. It require two workarounds with some magic configuration. Regular use require only one register configuration. But Open Circuit require second workaround. It cause implementation two phases for fault length measuring. Fast Ethernet PHY have implemented very simple version of VCT. It's complitley different than vct5 or vct7. Signed-off-by: Pawel Dembicki --- drivers/net/phy/marvell.c | 252 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index fae7eb57ee2c..38316d641d31 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -279,6 +279,23 @@ #define MII_VCT7_CTRL_METERS BIT(10) #define MII_VCT7_CTRL_CENTIMETERS 0 +#define MII_VCT_TXPINS 0x1A +#define MII_VCT_RXPINS 0x1B +#define MII_VCT_TXPINS_ENVCT BIT(15) +#define MII_VCT_TXRXPINS_VCTTST GENMASK(14, 13) +#define MII_VCT_TXRXPINS_VCTTST_SHIFT 13 +#define MII_VCT_TXRXPINS_VCTTST_OK 0 +#define MII_VCT_TXRXPINS_VCTTST_SHORT 1 +#define MII_VCT_TXRXPINS_VCTTST_OPEN 2 +#define MII_VCT_TXRXPINS_VCTTST_FAIL 3 +#define MII_VCT_TXRXPINS_AMPRFLN GENMASK(12, 8) +#define MII_VCT_TXRXPINS_AMPRFLN_SHIFT 8 +#define MII_VCT_TXRXPINS_DISTRFLN GENMASK(7, 0) +#define MII_VCT_TXRXPINS_DISTRFLN_MAX 0xff + +#define M88E3082_PAIR_A BIT(0) +#define M88E3082_PAIR_B BIT(1) + #define LPA_PAUSE_FIBER 0x180 #define LPA_PAUSE_ASYM_FIBER 0x100 @@ -301,6 +318,12 @@ static struct marvell_hw_stat marvell_hw_stats[] = { { "phy_receive_errors_fiber", 1, 21, 16}, }; +enum { + M88E3082_VCT_OFF, + M88E3082_VCT_PHASE1, + M88E3082_VCT_PHASE2, +}; + struct marvell_priv { u64 stats[ARRAY_SIZE(marvell_hw_stats)]; char *hwmon_name; @@ -310,6 +333,8 @@ struct marvell_priv { u32 last; u32 step; s8 pair; + u8 vct_phase; + u16 m88e3082_vct_reg_backup; }; static int marvell_read_page(struct phy_device *phydev) @@ -2417,6 +2442,231 @@ static int marvell_vct7_cable_test_get_status(struct phy_device *phydev, return 0; } +static int m88e3082_vct_cable_test_start(struct phy_device *phydev) +{ + struct marvell_priv *priv = phydev->priv; + int ret; + + /* It needs some magic workaround described in VCT manual for this PHY. + */ + + switch (priv->vct_phase) { + case M88E3082_VCT_OFF: + ret = phy_write(phydev, 29, 0x0003); + if (ret < 0) + return ret; + + ret = phy_write(phydev, 30, 0x6440); + if (ret < 0) + return ret; + + ret = phy_read(phydev, MII_BMCR); + if (ret < 0) + return ret; + priv->m88e3082_vct_reg_backup = ret; + + ret = phy_write(phydev, MII_BMCR, 0xa100); + if (ret < 0) + return ret; + + ret = phy_write(phydev, MII_VCT_TXPINS, MII_VCT_TXPINS_ENVCT); + if (ret < 0) + return ret; + + ret = phy_write(phydev, 29, 0x0003); + if (ret < 0) + return ret; + + ret = phy_write(phydev, 30, 0x0); + if (ret < 0) + return ret; + + priv->vct_phase = M88E3082_VCT_PHASE1; + priv->pair = 0; + + break; + + case M88E3082_VCT_PHASE1: + ret = phy_write(phydev, 29, 0x0003); + if (ret < 0) + return ret; + + ret = phy_write(phydev, 30, 0x6440); + if (ret < 0) + return ret; + + ret = phy_write(phydev, 29, 0x000a); + if (ret < 0) + return ret; + + ret = phy_write(phydev, 30, 0x0002); + if (ret < 0) + return ret; + + ret = phy_read(phydev, MII_BMCR); + if (ret < 0) + return ret; + priv->m88e3082_vct_reg_backup = ret; + + ret = phy_write(phydev, MII_BMCR, 0xa100); + if (ret < 0) + return ret; + + ret = phy_write(phydev, MII_VCT_TXPINS, MII_VCT_TXPINS_ENVCT); + if (ret < 0) + return ret; + + ret = phy_write(phydev, 29, 0x0003); + if (ret < 0) + return ret; + + ret = phy_write(phydev, 30, 0x0); + if (ret < 0) + return ret; + + ret = phy_write(phydev, 29, 0x000a); + if (ret < 0) + return ret; + + ret = phy_write(phydev, 30, 0x0); + if (ret < 0) + return ret; + + priv->vct_phase = M88E3082_VCT_PHASE2; + break; + + default: + break; + } + + return 0; +} + +static int m88e3082_vct_cable_test_report_trans(int result, u8 distance) +{ + switch (result) { + case MII_VCT_TXRXPINS_VCTTST_OK: + if (distance == MII_VCT_TXRXPINS_DISTRFLN_MAX) + return ETHTOOL_A_CABLE_RESULT_CODE_OK; + /* Impedance mismatch */ + return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; + case MII_VCT_TXRXPINS_VCTTST_SHORT: + return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; + case MII_VCT_TXRXPINS_VCTTST_OPEN: + return ETHTOOL_A_CABLE_RESULT_CODE_OPEN; + default: + return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; + } +} + +u32 m88e3082_vct_distrfln_2_cm(u8 distrfln) +{ + if (distrfln < 24) + return 0; + + /* Original function for meters: y = 0.7861x - 18.862 */ + return (7861 * distrfln - 188620) / 100; +} + +static int m88e3082_vct_cable_test_get_status(struct phy_device *phydev, + bool *finished) +{ + u8 tx_vcttst_res, rx_vcttst_res, tx_distrfln, rx_distrfln; + struct marvell_priv *priv = phydev->priv; + int ret, tx_result, rx_result; + bool done_phase = true; + + *finished = false; + + ret = phy_read(phydev, MII_VCT_TXPINS); + if (ret < 0) + return ret; + else if (ret & MII_VCT_TXPINS_ENVCT) + return 0; + + tx_distrfln = ret & MII_VCT_TXRXPINS_DISTRFLN; + tx_vcttst_res = (ret & MII_VCT_TXRXPINS_VCTTST) >> + MII_VCT_TXRXPINS_VCTTST_SHIFT; + + ret = phy_read(phydev, MII_VCT_RXPINS); + if (ret < 0) + return ret; + + rx_distrfln = ret & MII_VCT_TXRXPINS_DISTRFLN; + rx_vcttst_res = (ret & MII_VCT_TXRXPINS_VCTTST) >> + MII_VCT_TXRXPINS_VCTTST_SHIFT; + + *finished = true; + + switch (priv->vct_phase) { + case M88E3082_VCT_PHASE1: + tx_result = m88e3082_vct_cable_test_report_trans(tx_vcttst_res, + tx_distrfln); + rx_result = m88e3082_vct_cable_test_report_trans(rx_vcttst_res, + rx_distrfln); + + ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A, + tx_result); + ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B, + rx_result); + + if (tx_vcttst_res == MII_VCT_TXRXPINS_VCTTST_OPEN) { + done_phase = false; + priv->pair |= M88E3082_PAIR_A; + } else if (tx_distrfln < MII_VCT_TXRXPINS_DISTRFLN_MAX) { + u8 pair = ETHTOOL_A_CABLE_PAIR_A; + u32 cm = m88e3082_vct_distrfln_2_cm(tx_distrfln); + + ethnl_cable_test_fault_length(phydev, pair, cm); + } + + if (rx_vcttst_res == MII_VCT_TXRXPINS_VCTTST_OPEN) { + done_phase = false; + priv->pair |= M88E3082_PAIR_B; + } else if (rx_distrfln < MII_VCT_TXRXPINS_DISTRFLN_MAX) { + u8 pair = ETHTOOL_A_CABLE_PAIR_B; + u32 cm = m88e3082_vct_distrfln_2_cm(rx_distrfln); + + ethnl_cable_test_fault_length(phydev, pair, cm); + } + + break; + case M88E3082_VCT_PHASE2: + if (priv->pair & M88E3082_PAIR_A && + tx_vcttst_res == MII_VCT_TXRXPINS_VCTTST_OPEN && + tx_distrfln < MII_VCT_TXRXPINS_DISTRFLN_MAX) { + u8 pair = ETHTOOL_A_CABLE_PAIR_A; + u32 cm = m88e3082_vct_distrfln_2_cm(tx_distrfln); + + ethnl_cable_test_fault_length(phydev, pair, cm); + } + if (priv->pair & M88E3082_PAIR_B && + rx_vcttst_res == MII_VCT_TXRXPINS_VCTTST_OPEN && + rx_distrfln < MII_VCT_TXRXPINS_DISTRFLN_MAX) { + u8 pair = ETHTOOL_A_CABLE_PAIR_B; + u32 cm = m88e3082_vct_distrfln_2_cm(rx_distrfln); + + ethnl_cable_test_fault_length(phydev, pair, cm); + } + + break; + default: + return -EINVAL; + } + + ret = phy_write(phydev, MII_BMCR, priv->m88e3082_vct_reg_backup); + if (ret < 0) + return ret; + + if (!done_phase) { + *finished = false; + return m88e3082_vct_cable_test_start(phydev); + } + if (*finished) + priv->vct_phase = M88E3082_VCT_OFF; + return 0; +} + #ifdef CONFIG_HWMON struct marvell_hwmon_ops { int (*config)(struct phy_device *phydev); @@ -3300,6 +3550,8 @@ static struct phy_driver marvell_drivers[] = { .read_status = marvell_read_status, .resume = genphy_resume, .suspend = genphy_suspend, + .cable_test_start = m88e3082_vct_cable_test_start, + .cable_test_get_status = m88e3082_vct_cable_test_get_status, }, { .phy_id = MARVELL_PHY_ID_88E1112,