From patchwork Tue Apr 9 07:30:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Woudstra X-Patchwork-Id: 13621898 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.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 A42DA7BB11 for ; Tue, 9 Apr 2024 07:30:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712647828; cv=none; b=cVNYw8Faz6b3Y9vQJhmW4/6tGz2+W7uYk9BeS81tz2TFLvxPaYgHmd9ZUYEMwGnTVpFI5F/gQPyGZvzWOnDbfrQCDmd40oUSuxYBkHhmkThwApLhyUrWYkFPjsm/LeigQHbP3EIa5SE7N9ZIR3XzoWgcWyzscUz3jbGMJmdwt0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712647828; c=relaxed/simple; bh=GFdJqQERxwf3ogjuKeJLFkZNfHbqAIUgRXfSk1CJh9E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r0cFB4aqpAR5mkrdDVaUGKSIHKxalN+L7E3EinhWK7y+2uYD4b4IbOe+y3P+YT/e7XMMJIGCgRVqIEAr75mqSB2Hpi5+LGNKdIQkRnqvcUjiO2iCzo6lBx3CwN7DiaLKbecT8nR+tQ4cIRuFjWZOcGYGs1Tsp09bf3tzpZrXruI= 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=k9i5dCdR; arc=none smtp.client-ip=209.85.167.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="k9i5dCdR" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-51381021af1so8491972e87.0 for ; Tue, 09 Apr 2024 00:30:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712647825; x=1713252625; 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=PUGNrGMMaWToBXy+N/O6G9Hn7sqcj1wDeJzInv5qykk=; b=k9i5dCdRaCay/FnO8y5AGoTVJULFrA8W6Yedy/tUez+LSrTkv7MTpm2/DS1ShKFl6p waI4W5Z/pjhYyPq6oBlePeJBWxoMVJs9uOcEtB18Gt7MfYoP7t8XHR/LUbnfMiPD1Txz iagCKFzURSV3kI9XIZruKhsrUejR/2H1ES08v1epy0zzS1BQTedYZcE5wtPyQ1lyUk32 hHamR+3SvAiA/etbhZyvtH9xRmw5YEW1gA1JvgwcDJRTX18P4ZWuqeH5kUKFqWNi26Bn JhOT1N4eUDLfAc518034Q6l7Yr+6T5JVW+geCMvxDcyor3uozqecbQ4v9ugC2mSb2Y9G +w0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712647825; x=1713252625; 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=PUGNrGMMaWToBXy+N/O6G9Hn7sqcj1wDeJzInv5qykk=; b=CMZd3Pis0J5zyELLaIK/bCmrPtDFKTYl4SXtyXPVN4jzMpirbOE1jnE5G3j8P2z8/I GkkWbLocq8mGMcOLFFnw/zqkmzjfiYqABGk+O2c6GDyo0uXgErpFMMiFoOUMiqcibFlv m6sxx+5S7Ud9wgPKEIf/KC4Z65Ipx3vreHBqXGAKGknnJhdS+wcUw6iOsNCwGqC7UoE2 Q4rRQJQqLJpeGv5g3t/9j2x/QjNkEFdmIsSsAo06bRMy9t1vAhk0qnOhV1TsywQL6918 3sZBEj4KcdZhwv4PB7iWtUqPagU4YzXIBdvvw3VANgt87OQfrTA7j9QppBdGFLzaKp2B r29A== X-Gm-Message-State: AOJu0YwpZFeUusV4z/QoEdPqGlk0YoCtXMImMzmxh7Us2qUg7B8JHlWy lnk5o2QE7Tz48RuxEw82w6Ey4MLRAzdINEVaswHtexbsIfuZ6ONf X-Google-Smtp-Source: AGHT+IEuFOR3lpSZczmbCpVbqVWTovkrx9ORnETTuGdyywgNKCju0Qzj+90IAONQ8DI+gseBvrYVog== X-Received: by 2002:ac2:5636:0:b0:516:be9d:11ac with SMTP id b22-20020ac25636000000b00516be9d11acmr9873656lff.13.1712647824439; Tue, 09 Apr 2024 00:30:24 -0700 (PDT) Received: from corebook.localdomain (2001-1c00-020d-1300-1b1c-4449-176a-89ea.cable.dynamic.v6.ziggo.nl. [2001:1c00:20d:1300:1b1c:4449:176a:89ea]) by smtp.gmail.com with ESMTPSA id j25-20020a1709066dd900b00a473362062fsm5315694ejt.220.2024.04.09.00.30.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 00:30:24 -0700 (PDT) From: Eric Woudstra To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?utf-8?q?Marek_Beh=C3=BAn?= , "Frank Wunderlich" , Daniel Golle Cc: netdev@vger.kernel.org, Alexander Couzens , Eric Woudstra , Russell King Subject: [PATCH v4 net-next 1/6] net: phy: realtek: configure SerDes mode for rtl822xb PHYs Date: Tue, 9 Apr 2024 09:30:11 +0200 Message-ID: <20240409073016.367771-2-ericwouds@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240409073016.367771-1-ericwouds@gmail.com> References: <20240409073016.367771-1-ericwouds@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 From: Alexander Couzens The rtl8221b and rtl8226b series support switching SerDes mode between 2500base-x and sgmii based on the negotiated copper speed. Configure this switching mode according to SerDes modes supported by host. There is an additional datasheet for RTL8226B/RTL8221B called "SERDES MODE SETTING FLOW APPLICATION NOTE" where a sequence is described to setup interface and rate adapter mode. However, there is no documentation about the meaning of registers and bits, it's literally just magic numbers and pseudo-code. Signed-off-by: Alexander Couzens [ refactored, dropped HiSGMII mode and changed commit message ] Signed-off-by: Marek Behún [ changed rtl822x_update_interface() to use vendor register ] [ always fill in possible interfaces ] [ only apply to rtl8221b and rtl8226b phy's ] [ set phydev->rate_matching in .config_init() ] Signed-off-by: Eric Woudstra Reviewed-by: Russell King (Oracle) Reviewed-by: should come before them, without any blank lines. As the --- drivers/net/phy/realtek.c | 114 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 4 deletions(-) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index 1fa70427b2a2..70cd1834a832 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -54,6 +54,16 @@ RTL8201F_ISR_LINK) #define RTL8201F_IER 0x13 +#define RTL822X_VND1_SERDES_OPTION 0x697a +#define RTL822X_VND1_SERDES_OPTION_MODE_MASK GENMASK(5, 0) +#define RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX_SGMII 0 +#define RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX 2 + +#define RTL822X_VND1_SERDES_CTRL3 0x7580 +#define RTL822X_VND1_SERDES_CTRL3_MODE_MASK GENMASK(5, 0) +#define RTL822X_VND1_SERDES_CTRL3_MODE_SGMII 0x02 +#define RTL822X_VND1_SERDES_CTRL3_MODE_2500BASEX 0x16 + #define RTL8366RB_POWER_SAVE 0x15 #define RTL8366RB_POWER_SAVE_ON BIT(12) @@ -659,6 +669,63 @@ static int rtl822x_write_mmd(struct phy_device *phydev, int devnum, u16 regnum, return ret; } +static int rtl822xb_config_init(struct phy_device *phydev) +{ + bool has_2500, has_sgmii; + u16 mode; + int ret; + + has_2500 = test_bit(PHY_INTERFACE_MODE_2500BASEX, + phydev->host_interfaces) || + phydev->interface == PHY_INTERFACE_MODE_2500BASEX; + + has_sgmii = test_bit(PHY_INTERFACE_MODE_SGMII, + phydev->host_interfaces) || + phydev->interface == PHY_INTERFACE_MODE_SGMII; + + /* fill in possible interfaces */ + __assign_bit(PHY_INTERFACE_MODE_2500BASEX, phydev->possible_interfaces, + has_2500); + __assign_bit(PHY_INTERFACE_MODE_SGMII, phydev->possible_interfaces, + has_sgmii); + + if (!has_2500 && !has_sgmii) + return 0; + + /* determine SerDes option mode */ + if (has_2500 && !has_sgmii) { + mode = RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX; + phydev->rate_matching = RATE_MATCH_PAUSE; + } else { + mode = RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX_SGMII; + phydev->rate_matching = RATE_MATCH_NONE; + } + + /* the following sequence with magic numbers sets up the SerDes + * option mode + */ + ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x75f3, 0); + if (ret < 0) + return ret; + + ret = phy_modify_mmd_changed(phydev, MDIO_MMD_VEND1, + RTL822X_VND1_SERDES_OPTION, + RTL822X_VND1_SERDES_OPTION_MODE_MASK, + mode); + if (ret < 0) + return ret; + + ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x6a04, 0x0503); + if (ret < 0) + return ret; + + ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x6f10, 0xd455); + if (ret < 0) + return ret; + + return phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x6f11, 0x8020); +} + static int rtl822x_get_features(struct phy_device *phydev) { int val; @@ -695,6 +762,28 @@ static int rtl822x_config_aneg(struct phy_device *phydev) return __genphy_config_aneg(phydev, ret); } +static void rtl822xb_update_interface(struct phy_device *phydev) +{ + int val; + + if (!phydev->link) + return; + + /* Change interface according to serdes mode */ + val = phy_read_mmd(phydev, MDIO_MMD_VEND1, RTL822X_VND1_SERDES_CTRL3); + if (val < 0) + return; + + switch (val & RTL822X_VND1_SERDES_CTRL3_MODE_MASK) { + case RTL822X_VND1_SERDES_CTRL3_MODE_2500BASEX: + phydev->interface = PHY_INTERFACE_MODE_2500BASEX; + break; + case RTL822X_VND1_SERDES_CTRL3_MODE_SGMII: + phydev->interface = PHY_INTERFACE_MODE_SGMII; + break; + } +} + static int rtl822x_read_status(struct phy_device *phydev) { int ret; @@ -716,6 +805,19 @@ static int rtl822x_read_status(struct phy_device *phydev) return rtlgen_get_speed(phydev); } +static int rtl822xb_read_status(struct phy_device *phydev) +{ + int ret; + + ret = rtl822x_read_status(phydev); + if (ret < 0) + return ret; + + rtl822xb_update_interface(phydev); + + return 0; +} + static bool rtlgen_supports_2_5gbps(struct phy_device *phydev) { int val; @@ -988,7 +1090,8 @@ static struct phy_driver realtek_drvs[] = { .name = "RTL8226B_RTL8221B 2.5Gbps PHY", .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, - .read_status = rtl822x_read_status, + .config_init = rtl822xb_config_init, + .read_status = rtl822xb_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, .read_page = rtl821x_read_page, @@ -1010,7 +1113,8 @@ static struct phy_driver realtek_drvs[] = { .name = "RTL8226B-CG_RTL8221B-CG 2.5Gbps PHY", .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, - .read_status = rtl822x_read_status, + .config_init = rtl822xb_config_init, + .read_status = rtl822xb_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, .read_page = rtl821x_read_page, @@ -1020,7 +1124,8 @@ static struct phy_driver realtek_drvs[] = { .name = "RTL8221B-VB-CG 2.5Gbps PHY", .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, - .read_status = rtl822x_read_status, + .config_init = rtl822xb_config_init, + .read_status = rtl822xb_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, .read_page = rtl821x_read_page, @@ -1030,7 +1135,8 @@ static struct phy_driver realtek_drvs[] = { .name = "RTL8221B-VM-CG 2.5Gbps PHY", .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, - .read_status = rtl822x_read_status, + .config_init = rtl822xb_config_init, + .read_status = rtl822xb_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, .read_page = rtl821x_read_page, From patchwork Tue Apr 9 07:30:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Woudstra X-Patchwork-Id: 13621899 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 58A6E7C6E9 for ; Tue, 9 Apr 2024 07:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712647829; cv=none; b=cdosrffLffSBVYtrvWHLa3iVJefRRHVQOk76cAZAaxEM/OAYSW8ZxgmdaTijMjS7fl5k0jkUnEy+ilMis1+RQqKKgwvT9DfzmEhQ1nSj2SaLqXNF0TJJFfg6qghCehTvmwy8xvBvPupq38qerkOsx8FMNNuI7aT0BxFV9YNKUTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712647829; c=relaxed/simple; bh=vtB6yGJgo+xJBjwo2aPEj6An2i/IcemQoK6ItWCNfAQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KNYcgtJRXQ9zIOnCK4qNUiasdBoteG8yoQJuC6K7wEQydJf4hh8FD++50qvl1XpY1VRZzKRX3iBJ7g2SdOvkPf5IETuHuS5e6bUaKPEqTlcsThn7QSohhslFEhYbxgYkYCmsml1f7wZNVs11dNItBSs4D6cAsR3MIpaeLMqwIDg= 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=UruCRz/L; arc=none smtp.client-ip=209.85.208.50 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="UruCRz/L" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-56e136cbcecso7240557a12.3 for ; Tue, 09 Apr 2024 00:30:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712647825; x=1713252625; 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=IOUmkKoltFZufK17eGVufFHxAOB0ZBowfgVM7R4VLZw=; b=UruCRz/LU9DH/gGnn9O699FQS97HlN86QDFAjAcAvvp7OcS49qvC7JtiV2YFiRCN4H DXS6Et3d+CV4yh2BvLG5PgyNNS/dFYWJpqVDa5o89Gg71QfOgO9u2WdDW3k7J1aNarM3 aOktiieFXqb+duM94O40jrrR0Tp9t+QlDT63fjmur0C5LZHb6QbTuOm68kvb/hAduj2a M1u+oQSyAjpFDBuwzqBPjt40Mu0Q0qeB6MdP1XNWYbdP3vpr5n6CV1N54NKgPYobL2E6 UDgPcxm6OIfcF7/rgiDVxbuJfM6pGwy65VAToQap7iQZO8JBPg8qk6IeoI9AviAVh57w 6Y3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712647825; x=1713252625; 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=IOUmkKoltFZufK17eGVufFHxAOB0ZBowfgVM7R4VLZw=; b=GSly67Gg/X/0RgSs1azzxJiO48bhYrvU4VdsmoUlwWMV5Lqv2WeCuDBTJIHFqaJmPK HvdaCdJ599xiDtRwXSRQy3Fiz8z7LNQRgG6vzaZgnnbB5x/haXvOaDNqbP0XMg5MDgM5 zeHtihlAkLFBsZaSIhAYcPHBSUfWWBxioKG/+Y1mG2ZqK3aBkGuX6tsUwWt8d6IGbwQE TNr/Z3V2tfA5Ppt9FLq/jnfnul5cCH3B3MPnQ8cAcLA3oxvJ5PTVtojE7EnzA38SwkPO K9kaJtnQ5vuNISfpsrybAXVZtu4///rrH8pVIQoqoLGC6n0yI6oVSPUPXOEwctpXM50m GGEQ== X-Gm-Message-State: AOJu0YxZC7XB9m5M3iK4DDMXXuPTftQniP7KF721CV9bjfgTLq+HcLvR ORDhpYQcP1RF7kQ5lShreikHjsYmJry09wR2bV6oMc7VxBiD8JIy X-Google-Smtp-Source: AGHT+IHNw+jgejSPzRZP3uqZRAbj02QJWTtMdh75921+/0Y8l6zSrXqQWFaTP1jG6EbsdaRwjhC9Sw== X-Received: by 2002:a17:907:6d06:b0:a50:7cdd:348f with SMTP id sa6-20020a1709076d0600b00a507cdd348fmr10651826ejc.46.1712647825365; Tue, 09 Apr 2024 00:30:25 -0700 (PDT) Received: from corebook.localdomain (2001-1c00-020d-1300-1b1c-4449-176a-89ea.cable.dynamic.v6.ziggo.nl. [2001:1c00:20d:1300:1b1c:4449:176a:89ea]) by smtp.gmail.com with ESMTPSA id j25-20020a1709066dd900b00a473362062fsm5315694ejt.220.2024.04.09.00.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 00:30:24 -0700 (PDT) From: Eric Woudstra To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?utf-8?q?Marek_Beh=C3=BAn?= , "Frank Wunderlich" , Daniel Golle Cc: netdev@vger.kernel.org, Eric Woudstra Subject: [PATCH v4 net-next 2/6] net: phy: realtek: add get_rate_matching() for rtl822xb PHYs Date: Tue, 9 Apr 2024 09:30:12 +0200 Message-ID: <20240409073016.367771-3-ericwouds@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240409073016.367771-1-ericwouds@gmail.com> References: <20240409073016.367771-1-ericwouds@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 Uses vendor register to determine if SerDes is setup in rate-matching mode. Rate-matching only supported when SerDes is set to 2500base-x. Signed-off-by: Eric Woudstra --- drivers/net/phy/realtek.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index 70cd1834a832..08d338271bd0 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -726,6 +726,27 @@ static int rtl822xb_config_init(struct phy_device *phydev) return phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x6f11, 0x8020); } +static int rtl822xb_get_rate_matching(struct phy_device *phydev, + phy_interface_t iface) +{ + int val; + + /* Only rate matching at 2500base-x */ + if (iface != PHY_INTERFACE_MODE_2500BASEX) + return RATE_MATCH_NONE; + + val = phy_read_mmd(phydev, MDIO_MMD_VEND1, RTL822X_VND1_SERDES_OPTION); + if (val < 0) + return val; + + if ((val & RTL822X_VND1_SERDES_OPTION_MODE_MASK) == + RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX) + return RATE_MATCH_PAUSE; + + /* RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX_SGMII */ + return RATE_MATCH_NONE; +} + static int rtl822x_get_features(struct phy_device *phydev) { int val; @@ -1091,6 +1112,7 @@ static struct phy_driver realtek_drvs[] = { .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, .config_init = rtl822xb_config_init, + .get_rate_matching = rtl822xb_get_rate_matching, .read_status = rtl822xb_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, @@ -1114,6 +1136,7 @@ static struct phy_driver realtek_drvs[] = { .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, .config_init = rtl822xb_config_init, + .get_rate_matching = rtl822xb_get_rate_matching, .read_status = rtl822xb_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, @@ -1125,6 +1148,7 @@ static struct phy_driver realtek_drvs[] = { .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, .config_init = rtl822xb_config_init, + .get_rate_matching = rtl822xb_get_rate_matching, .read_status = rtl822xb_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, @@ -1136,6 +1160,7 @@ static struct phy_driver realtek_drvs[] = { .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, .config_init = rtl822xb_config_init, + .get_rate_matching = rtl822xb_get_rate_matching, .read_status = rtl822xb_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, From patchwork Tue Apr 9 07:30:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Woudstra X-Patchwork-Id: 13621900 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 419E37D096 for ; Tue, 9 Apr 2024 07:30:28 +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=1712647830; cv=none; b=dlDhBOM3THV+tYXXoOagMl6ARqWEY1/v++I3vqqJnBgqH5Z3smyaHPjH8E2+GsVsdQk8R3bUdCPHHWVpHYuhGttAIdyeWqaOtvKWf/a1CWGIMrh8aulzLrdLw6k8yNJfRXE7xh0vBVQqIDnGZWgIBlqNRLMdXuaGQ5Nkg/40/RE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712647830; c=relaxed/simple; bh=q2Cs0YfNPRBwgUjeXgYZPRIY4hFMTnOMGrXWS87chwQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BAvnj/B8O2IwUb//5uihb9HeNZIHK+hRwY3lsTkhk78EL4It2roaNAKJuLTYMF9l5GZoVvrg+pwlxn+KpW62HsZOvWy33LKIw9czmCPedewb7JCz66mEcL51KIF2Yu3MEUreWeu0/QnEhqToe2k4Xbg817LAk8CqdZhD2ELJTw4= 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=Qbb7z23t; 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="Qbb7z23t" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a51fc011e8fso26118366b.0 for ; Tue, 09 Apr 2024 00:30:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712647826; x=1713252626; 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=LKp9iyhdpbkHShnqT1Bpb+638mmslPyOXZxA0lb4kzI=; b=Qbb7z23tpFrfuUTHaiGKIqCSLKt5TTYKMZPpT0DLHlXNiXu/k/3/PVUScB/Ls3n3ny kSXYoQ6Ao2yIJkRp3mLpNNtb9HVlNumWmucdVa2Ft7TT0Kjc+qz7p4Z0OomnO5nmSDwe N2i5uqYIra2NVCrbGV8ebw5BQj98g+xjXTerdsNOX9BiYRtpCe6F/Il9Rw4hR1cGUJfS 9ZDh4cW7ZJ2t11OKOKzZaGyNtXmJ+KtdvLb5KzDdT/+EQE9aY/zUMEnmStqjMjOIWK85 8j/BtJOfExnZJarYV0wYfwp3j8NYpVeJKYsVUGdLuETb9Cd7xvH3NIH7Iq+Yee8k4loB dchA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712647826; x=1713252626; 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=LKp9iyhdpbkHShnqT1Bpb+638mmslPyOXZxA0lb4kzI=; b=gvadxQ2TLo5oM5K6+DPTf4ryKre4HHUbIDZ6VWSmSt/70vfksS32F5jmP9qr32EhOA 6wzOhyoMhr8WDwGoEZnqaxIcMSyZBJAiArCKvtS9/Wkpc+2DY8HNAekA8ZtaeSspWb68 RxxrYA7+N/RaaGGsoMItb6J4dHFQgwifxr1D6xuuNHn4CkXZUBJO6rvWOvuuKBvysLy9 U6/EoP80FNLB53394/aHCXWcAL1r3L68fNKmnAM8GgN7I15YYN1qCaEhWJR4gSXV6oo4 hfWxmGoepXVHobbAOb9Z26SC5UHVFcujcEIlwTa2Y4QZjD1C7EU10Yktaz2q+bdT+TWj 3B1A== X-Gm-Message-State: AOJu0Ywe6XyiJAVocCR7YbT2Hu+3b5mRUyGj48cKZxlyKT9VInPvZvvo hrNSCqOUDtH1qwZLahtPLHwqvJQkg1pjyQD4MuE7v8Q9WYbQTgTw X-Google-Smtp-Source: AGHT+IHX6pw57OxB55P+xu1QmbI3txukm6hitwT8eEukEF0fQjDiDfT3e7XO/ajKyxW2Td1HzDoacQ== X-Received: by 2002:a17:907:2d09:b0:a51:d463:32c0 with SMTP id gs9-20020a1709072d0900b00a51d46332c0mr4934529ejc.57.1712647826515; Tue, 09 Apr 2024 00:30:26 -0700 (PDT) Received: from corebook.localdomain (2001-1c00-020d-1300-1b1c-4449-176a-89ea.cable.dynamic.v6.ziggo.nl. [2001:1c00:20d:1300:1b1c:4449:176a:89ea]) by smtp.gmail.com with ESMTPSA id j25-20020a1709066dd900b00a473362062fsm5315694ejt.220.2024.04.09.00.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 00:30:25 -0700 (PDT) From: Eric Woudstra To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?utf-8?q?Marek_Beh=C3=BAn?= , "Frank Wunderlich" , Daniel Golle Cc: netdev@vger.kernel.org, Eric Woudstra , Russell King Subject: [PATCH v4 net-next 3/6] net: phy: realtek: Add driver instances for rtl8221b via Clause 45 Date: Tue, 9 Apr 2024 09:30:13 +0200 Message-ID: <20240409073016.367771-4-ericwouds@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240409073016.367771-1-ericwouds@gmail.com> References: <20240409073016.367771-1-ericwouds@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 From: Marek Behún Collected from several commits in [PATCH net-next] "Realtek RTL822x PHY rework to c45 and SerDes interface switching" The instances are used by Clause 45 only accessible PHY's on several sfp modules, which are using RollBall protocol. Signed-off-by: Marek Behún [ Added matching functions to differentiate C45 instances ] Signed-off-by: Eric Woudstra Reviewed-by: Russell King (Oracle) --- drivers/net/phy/realtek.c | 135 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 131 insertions(+), 4 deletions(-) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index 08d338271bd0..f4a6f073a1f7 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -64,6 +64,13 @@ #define RTL822X_VND1_SERDES_CTRL3_MODE_SGMII 0x02 #define RTL822X_VND1_SERDES_CTRL3_MODE_2500BASEX 0x16 +/* RTL822X_VND2_XXXXX registers are only accessible when phydev->is_c45 + * is set, they cannot be accessed by C45-over-C22. + */ +#define RTL822X_VND2_GBCR 0xa412 + +#define RTL822X_VND2_GANLPAR 0xa414 + #define RTL8366RB_POWER_SAVE 0x15 #define RTL8366RB_POWER_SAVE_ON BIT(12) @@ -74,6 +81,9 @@ #define RTL_GENERIC_PHYID 0x001cc800 #define RTL_8211FVD_PHYID 0x001cc878 +#define RTL_8221B_VB_CG 0x001cc849 +#define RTL_8221B_VN_CG 0x001cc84a +#define RTL_8251B 0x001cc862 MODULE_DESCRIPTION("Realtek PHY driver"); MODULE_AUTHOR("Johnson Leung"); @@ -839,6 +849,67 @@ static int rtl822xb_read_status(struct phy_device *phydev) return 0; } +static int rtl822x_c45_config_aneg(struct phy_device *phydev) +{ + bool changed = false; + int ret, val; + + if (phydev->autoneg == AUTONEG_DISABLE) + return genphy_c45_pma_setup_forced(phydev); + + ret = genphy_c45_an_config_aneg(phydev); + if (ret < 0) + return ret; + if (ret > 0) + changed = true; + + val = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising); + + /* Vendor register as C45 has no standardized support for 1000BaseT */ + ret = phy_modify_mmd_changed(phydev, MDIO_MMD_VEND2, RTL822X_VND2_GBCR, + ADVERTISE_1000FULL, val); + if (ret < 0) + return ret; + if (ret > 0) + changed = true; + + return genphy_c45_check_and_restart_aneg(phydev, changed); +} + +static int rtl822x_c45_read_status(struct phy_device *phydev) +{ + int ret, val; + + ret = genphy_c45_read_status(phydev); + if (ret < 0) + return ret; + + /* Vendor register as C45 has no standardized support for 1000BaseT */ + if (phydev->autoneg == AUTONEG_ENABLE) { + val = phy_read_mmd(phydev, MDIO_MMD_VEND2, + RTL822X_VND2_GANLPAR); + if (val < 0) + return val; + + mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, val); + } + + return 0; +} + +static int rtl822xb_c45_read_status(struct phy_device *phydev) +{ + int ret; + + ret = rtl822x_c45_read_status(phydev); + if (ret < 0) + return ret; + + rtl822xb_update_interface(phydev); + + return 0; +} + static bool rtlgen_supports_2_5gbps(struct phy_device *phydev) { int val; @@ -862,6 +933,35 @@ static int rtl8226_match_phy_device(struct phy_device *phydev) rtlgen_supports_2_5gbps(phydev); } +static int rtlgen_is_c45_match(struct phy_device *phydev, unsigned int id, + bool is_c45) +{ + if (phydev->is_c45) + return is_c45 && (id == phydev->c45_ids.device_ids[1]); + else + return !is_c45 && (id == phydev->phy_id); +} + +static int rtl8221b_vb_cg_c22_match_phy_device(struct phy_device *phydev) +{ + return rtlgen_is_c45_match(phydev, RTL_8221B_VB_CG, false); +} + +static int rtl8221b_vb_cg_c45_match_phy_device(struct phy_device *phydev) +{ + return rtlgen_is_c45_match(phydev, RTL_8221B_VB_CG, true); +} + +static int rtl8221b_vn_cg_c22_match_phy_device(struct phy_device *phydev) +{ + return rtlgen_is_c45_match(phydev, RTL_8221B_VN_CG, false); +} + +static int rtl8221b_vn_cg_c45_match_phy_device(struct phy_device *phydev) +{ + return rtlgen_is_c45_match(phydev, RTL_8221B_VN_CG, true); +} + static int rtlgen_resume(struct phy_device *phydev) { int ret = genphy_resume(phydev); @@ -872,6 +972,15 @@ static int rtlgen_resume(struct phy_device *phydev) return ret; } +static int rtlgen_c45_resume(struct phy_device *phydev) +{ + int ret = genphy_c45_pma_resume(phydev); + + msleep(20); + + return ret; +} + static int rtl9000a_config_init(struct phy_device *phydev) { phydev->autoneg = AUTONEG_DISABLE; @@ -1143,8 +1252,8 @@ static struct phy_driver realtek_drvs[] = { .read_page = rtl821x_read_page, .write_page = rtl821x_write_page, }, { - PHY_ID_MATCH_EXACT(0x001cc849), - .name = "RTL8221B-VB-CG 2.5Gbps PHY", + .match_phy_device = rtl8221b_vb_cg_c22_match_phy_device, + .name = "RTL8221B-VB-CG 2.5Gbps PHY (C22)", .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, .config_init = rtl822xb_config_init, @@ -1155,8 +1264,17 @@ static struct phy_driver realtek_drvs[] = { .read_page = rtl821x_read_page, .write_page = rtl821x_write_page, }, { - PHY_ID_MATCH_EXACT(0x001cc84a), - .name = "RTL8221B-VM-CG 2.5Gbps PHY", + .match_phy_device = rtl8221b_vb_cg_c45_match_phy_device, + .name = "RTL8221B-VB-CG 2.5Gbps PHY (C45)", + .config_init = rtl822xb_config_init, + .get_rate_matching = rtl822xb_get_rate_matching, + .config_aneg = rtl822x_c45_config_aneg, + .read_status = rtl822xb_c45_read_status, + .suspend = genphy_c45_pma_suspend, + .resume = rtlgen_c45_resume, + }, { + .match_phy_device = rtl8221b_vn_cg_c22_match_phy_device, + .name = "RTL8221B-VM-CG 2.5Gbps PHY (C22)", .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, .config_init = rtl822xb_config_init, @@ -1166,6 +1284,15 @@ static struct phy_driver realtek_drvs[] = { .resume = rtlgen_resume, .read_page = rtl821x_read_page, .write_page = rtl821x_write_page, + }, { + .match_phy_device = rtl8221b_vn_cg_c45_match_phy_device, + .name = "RTL8221B-VN-CG 2.5Gbps PHY (C45)", + .config_init = rtl822xb_config_init, + .get_rate_matching = rtl822xb_get_rate_matching, + .config_aneg = rtl822x_c45_config_aneg, + .read_status = rtl822xb_c45_read_status, + .suspend = genphy_c45_pma_suspend, + .resume = rtlgen_c45_resume, }, { PHY_ID_MATCH_EXACT(0x001cc862), .name = "RTL8251B 5Gbps PHY", From patchwork Tue Apr 9 07:30:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Woudstra X-Patchwork-Id: 13621901 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.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 4A48A7D3EC for ; Tue, 9 Apr 2024 07:30:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712647831; cv=none; b=tbsiwrbCBtfkxDVzhBe3z8NeNcvzg4ahsPJdwHRATJal4ZFQ4JZ0i6XJjHRb3Pry1ltHGhR+Ore+0Vh6oRqEVkXG3nLncqgPk+7DQJPJw76wq5aEYdjjby2JTsYsVobA3OJ/mvPoU9ss8jqh1YJYdwdwm4wahNNDwSGeXvd0vwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712647831; c=relaxed/simple; bh=OtGHJbGUgHc9dZuM2JQHrf1CGB+d6FDODUqjTGCDDk0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QK84AInYA3vyPCLfNFf2le4wGpvrejEWQzYHbwj+pDJKQ7K6lB3SThDbop1V3B826WHs7Ekc0RAHmTc/ShvKOcgSmSBZy2jeUm1s+YrW/SvSLFYJykiOQOwjZV5SVgAO8zutMaZOzouy27NY85rVqidnudSw6Ez76VfTZLDTIzk= 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=hoEtnWlh; arc=none smtp.client-ip=209.85.208.47 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="hoEtnWlh" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-56bdf81706aso6959311a12.2 for ; Tue, 09 Apr 2024 00:30:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712647827; x=1713252627; 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=5ArUcu/OIuu70X1GylkMgA2lcpO4SjCntOxNcsByY5E=; b=hoEtnWlhfeD8/2mYjWKqqfYxX0V3oS3BDTmegZRLlF1/0SU2U9Ohj/+I6S1wm1LZPP R1r5TF7YTvH4bKu/O38IF83p3F5tCPEXuo1VSogAD0MUIEqtZcqZIB0ztJl311G40ljq ejFoqrsfWMl6Rts+W24UiHB7utXpXBsGXtygi4RbdME4YiuXN74Ubvl5iNXIJfApydRb wfBYh7ApaIo0KsmqLe3zbNia7cPBZSUDitF/vT+UJvXW/dzby0wF3nBs+S+q3sRa7zQ6 HxskFj1lE1aXP1ZwcrhZ28xssawirkvt7SIx+ozUzHr4ygENXS8s2NNEkOIoRMeCok9I tamg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712647827; x=1713252627; 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=5ArUcu/OIuu70X1GylkMgA2lcpO4SjCntOxNcsByY5E=; b=lii+RL2H7V9/e3c93LYPPOJrZhLKQGrLhURpb4Z3cH1RI7KSBz3gN4BKll6P8rvvv+ DZCX++875wAyl8v76vSey2XvHQ95YCPWQXuRwvK1bTyVO7f2N4q6W1Idz1H3qszR6GL2 ImCFBqR4w6GVjmyuX9FFabfnuC7kPudLYN+ouqNzYW9FF2XN5Ph9YkDa81hFxrTI5H48 ck1GUUhfADSpq3vN7ocyoVWEUnyaDd28X943eKxnfRXQIybkB/wAtgU5cqZvpQPbJRB2 MravSjYWWmdA5ujK3CRfN0JfGCzKTjMEZQMJOnd6k2tYLgZdME0y9BQJfava7dQByLXM K4jQ== X-Gm-Message-State: AOJu0YzU/cgH/Q64RCTVyypxhTwL5tHymkNVD+9lah+s5d2yeWgCbeMd qOLUkznEVVhxmcp+ZjXwTrMGpjxousrYlvA+u3z2znRH52/rtniS X-Google-Smtp-Source: AGHT+IHwabGo99NumrWX4B7jidWK1Z8oLngpHs15OB5YK85qoU/reUXwrBMyXs9/XXrWAPJLrZuZlw== X-Received: by 2002:a17:906:d8f:b0:a51:89f1:2841 with SMTP id m15-20020a1709060d8f00b00a5189f12841mr6183997eji.50.1712647827447; Tue, 09 Apr 2024 00:30:27 -0700 (PDT) Received: from corebook.localdomain (2001-1c00-020d-1300-1b1c-4449-176a-89ea.cable.dynamic.v6.ziggo.nl. [2001:1c00:20d:1300:1b1c:4449:176a:89ea]) by smtp.gmail.com with ESMTPSA id j25-20020a1709066dd900b00a473362062fsm5315694ejt.220.2024.04.09.00.30.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 00:30:27 -0700 (PDT) From: Eric Woudstra To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?utf-8?q?Marek_Beh=C3=BAn?= , "Frank Wunderlich" , Daniel Golle Cc: netdev@vger.kernel.org, Eric Woudstra , Russell King Subject: [PATCH v4 net-next 4/6] net: phy: realtek: Change rtlgen_get_speed() to rtlgen_decode_speed() Date: Tue, 9 Apr 2024 09:30:14 +0200 Message-ID: <20240409073016.367771-5-ericwouds@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240409073016.367771-1-ericwouds@gmail.com> References: <20240409073016.367771-1-ericwouds@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 The value of the register to determine the speed, is retrieved differently when using Clause 45 only. To use the rtlgen_get_speed() function in this case, pass the value of the register as argument to rtlgen_get_speed(). The function would then always return 0, so change it to void. A better name for this function now is rtlgen_decode_speed(). Replace a call to genphy_read_status() followed by rtlgen_get_speed() with a call to rtlgen_read_status() in rtl822x_read_status(). Add reading speed to rtl822x_c45_read_status(). Signed-off-by: Eric Woudstra Reviewed-by: Russell King (Oracle) --- drivers/net/phy/realtek.c | 46 +++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index f4a6f073a1f7..901c6f7b04c2 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -71,6 +71,8 @@ #define RTL822X_VND2_GANLPAR 0xa414 +#define RTL822X_VND2_PHYSR 0xa434 + #define RTL8366RB_POWER_SAVE 0x15 #define RTL8366RB_POWER_SAVE_ON BIT(12) @@ -551,17 +553,8 @@ static int rtl8366rb_config_init(struct phy_device *phydev) } /* get actual speed to cover the downshift case */ -static int rtlgen_get_speed(struct phy_device *phydev) +static void rtlgen_decode_speed(struct phy_device *phydev, int val) { - int val; - - if (!phydev->link) - return 0; - - val = phy_read_paged(phydev, 0xa43, 0x12); - if (val < 0) - return val; - switch (val & RTLGEN_SPEED_MASK) { case 0x0000: phydev->speed = SPEED_10; @@ -584,19 +577,26 @@ static int rtlgen_get_speed(struct phy_device *phydev) default: break; } - - return 0; } static int rtlgen_read_status(struct phy_device *phydev) { - int ret; + int ret, val; ret = genphy_read_status(phydev); if (ret < 0) return ret; - return rtlgen_get_speed(phydev); + if (!phydev->link) + return 0; + + val = phy_read_paged(phydev, 0xa43, 0x12); + if (val < 0) + return val; + + rtlgen_decode_speed(phydev, val); + + return 0; } static int rtlgen_read_mmd(struct phy_device *phydev, int devnum, u16 regnum) @@ -817,8 +817,6 @@ static void rtl822xb_update_interface(struct phy_device *phydev) static int rtl822x_read_status(struct phy_device *phydev) { - int ret; - if (phydev->autoneg == AUTONEG_ENABLE) { int lpadv = phy_read_paged(phydev, 0xa5d, 0x13); @@ -829,11 +827,7 @@ static int rtl822x_read_status(struct phy_device *phydev) lpadv); } - ret = genphy_read_status(phydev); - if (ret < 0) - return ret; - - return rtlgen_get_speed(phydev); + return rtlgen_read_status(phydev); } static int rtl822xb_read_status(struct phy_device *phydev) @@ -894,6 +888,16 @@ static int rtl822x_c45_read_status(struct phy_device *phydev) mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, val); } + if (!phydev->link) + return 0; + + /* Read actual speed from vendor register. */ + val = phy_read_mmd(phydev, MDIO_MMD_VEND2, RTL822X_VND2_PHYSR); + if (val < 0) + return val; + + rtlgen_decode_speed(phydev, val); + return 0; } From patchwork Tue Apr 9 07:30:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Woudstra X-Patchwork-Id: 13621902 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 8BCEB7E0E9 for ; Tue, 9 Apr 2024 07:30:30 +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=1712647832; cv=none; b=f1fdCtSqNp/t0VpA65uH0kwX4O8020CIIT+jjQQGf7zPe9mf/+/7ICUxO6pY4NdxWjP5UNiCGsHQUHtO9LHzMu7a9BtiBK+3VFKHGSs30Q6LN+xSUo/k1SEAdMVu1/91zPhTAbrlYWnYebGI6vg0Dbhcam2fF04Y65TmgGOdkec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712647832; c=relaxed/simple; bh=GngB600xY5hfqgfmZBmIjGlASFh2xiuAmDjoCxb9TB4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Iz7oe5jn+dFmwMv16wQNxrT3fBA8MW3BXIOibbIwgORF48XtkrjT4YmBHP7D7Kg5/sYDtCuAdppeZ3LrK8OR898MQ9cPM2ffb36a+YtKfHWxB/moCQ90wGuB1K+/Eueq5xCrO2Cb3tIVoZgCsfqtmE2HFKQ0zdbXf/m99SWG+jM= 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=eNWvqDEE; 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="eNWvqDEE" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a51969e780eso638050866b.3 for ; Tue, 09 Apr 2024 00:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712647829; x=1713252629; 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=uQx9pZpqUKcaSj5KJw0x3/f5LiaORM0IdemqNK5rHwU=; b=eNWvqDEEBuP8qxSZymXyMTrgjSvVp3kH/e57gezSF9oPKvoY6MD9sVkAaN5479TvFw wvAaCahJ0q4WRVhymnP7EMkkK9i2TgfLP/2kXT3tVV2WUmqQYFkccv53GXRNYvr1x7db K0qm69zhz/Lh5IkbnAHmjzwgjI+m7qdww9idz93JCJpyqxTuL+Jw+zmqHaPSXbgaPwD0 oDSELZEyKCnazXEINuimIsJ7df21WRBpuuGC4W+cGahJjD/eTmhAKwCKTutI/3rc52DB ZngGY80iwZpkp06Rwfw+ag+c3DgDblarZy9FVtpBtOmFoO8YsxQNqsKYh7thh8lLNhaY vy0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712647829; x=1713252629; 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=uQx9pZpqUKcaSj5KJw0x3/f5LiaORM0IdemqNK5rHwU=; b=adOB9cUMUKyrFGOH0nHVqUtIqQNCbvTKBeE73u8SeHBG9AY3iXNVzWiF/QwRfE3duO BlN9MeZGTCO9F44hcgMoBAzmnPjs2QpTScmRrIcfXy7XERu93zf4v2ZOJ7L3IdfqjqLm 1s1xgHTcOmzai2eCvQ9yQ9IcWcZyueFEtheq5pxyeNjdUz1MPi0h/r0OIGcLIP0CyPJi wXDqpXjA3LMN6EhlsHchTbEQwIRmsw0JA16OuSlJ9wROCpTXyydM09DMCeGWO6TdC6Xg R1KtElPj2hP6xF5xXqUEld+lfpums3h7p+rVBAt5MwWJVoVwLy3kjNntcOQO9bmUqeqv Cyow== X-Gm-Message-State: AOJu0YwWS0vfa3xRmlTQGnomz02BuMluJAAtrxIQ6KCFhpG5LGQh2TqB tPjRSm4BjuLQTkelbJjlTd945WEQda1CwjJ2QjUhmI/5x3GI2D5I X-Google-Smtp-Source: AGHT+IHgLM4cWNg+ObY3d/CCSOHeInIJcaDzr/1exsaJQZ6Y6C6WQNAEzBAzWrofBzF1KsKHrgk+pw== X-Received: by 2002:a17:906:36da:b0:a51:f463:cfa6 with SMTP id b26-20020a17090636da00b00a51f463cfa6mr792335ejc.29.1712647828654; Tue, 09 Apr 2024 00:30:28 -0700 (PDT) Received: from corebook.localdomain (2001-1c00-020d-1300-1b1c-4449-176a-89ea.cable.dynamic.v6.ziggo.nl. [2001:1c00:20d:1300:1b1c:4449:176a:89ea]) by smtp.gmail.com with ESMTPSA id j25-20020a1709066dd900b00a473362062fsm5315694ejt.220.2024.04.09.00.30.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 00:30:28 -0700 (PDT) From: Eric Woudstra To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?utf-8?q?Marek_Beh=C3=BAn?= , "Frank Wunderlich" , Daniel Golle Cc: netdev@vger.kernel.org, Eric Woudstra Subject: [PATCH v4 net-next 5/6] net: phy: realtek: add rtl822x_c45_get_features() to set supported port Date: Tue, 9 Apr 2024 09:30:15 +0200 Message-ID: <20240409073016.367771-6-ericwouds@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240409073016.367771-1-ericwouds@gmail.com> References: <20240409073016.367771-1-ericwouds@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 Sets ETHTOOL_LINK_MODE_TP_BIT in phydev->supported. Signed-off-by: Eric Woudstra Reviewed-by: Andrew Lunn --- drivers/net/phy/realtek.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index 901c6f7b04c2..7ab41f95dae5 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -843,6 +843,14 @@ static int rtl822xb_read_status(struct phy_device *phydev) return 0; } +static int rtl822x_c45_get_features(struct phy_device *phydev) +{ + linkmode_set_bit(ETHTOOL_LINK_MODE_TP_BIT, + phydev->supported); + + return genphy_c45_pma_read_abilities(phydev); +} + static int rtl822x_c45_config_aneg(struct phy_device *phydev) { bool changed = false; @@ -1272,6 +1280,7 @@ static struct phy_driver realtek_drvs[] = { .name = "RTL8221B-VB-CG 2.5Gbps PHY (C45)", .config_init = rtl822xb_config_init, .get_rate_matching = rtl822xb_get_rate_matching, + .get_features = rtl822x_c45_get_features, .config_aneg = rtl822x_c45_config_aneg, .read_status = rtl822xb_c45_read_status, .suspend = genphy_c45_pma_suspend, @@ -1293,6 +1302,7 @@ static struct phy_driver realtek_drvs[] = { .name = "RTL8221B-VN-CG 2.5Gbps PHY (C45)", .config_init = rtl822xb_config_init, .get_rate_matching = rtl822xb_get_rate_matching, + .get_features = rtl822x_c45_get_features, .config_aneg = rtl822x_c45_config_aneg, .read_status = rtl822xb_c45_read_status, .suspend = genphy_c45_pma_suspend, From patchwork Tue Apr 9 07:30:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Woudstra X-Patchwork-Id: 13621903 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.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 57A397E116 for ; Tue, 9 Apr 2024 07:30:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712647834; cv=none; b=A429GYNvUmB8gsrgL8lIEwWBLWx4onphNavGKJhrt8S9bivGqTyYb5XluFs32Iub8Iw9gDjQz6dhgid073pxXAVBOXjrraHoqGTDsmHrU6P/q0xnj+gW+/9/R5D+xFKIJ8gsF2DjfDrk81yINmnYGwunElz6guUIGPlINYDg9tg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712647834; c=relaxed/simple; bh=gIz7MdS/+GZwGdahnbu/fUAyMyBCexr2zybpIeHADT8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=p0PWu/dNobXoXgazodQKi0Mdfjr9+qRUdFaEgiz+WQrvZuYASIq/3+nS11JTwGT/Dlg5wEjMKPLBarjGen0gm4/XE7rv0UDmkhhj4Xf8OpBzKJpzy50vJYK4oHwHhFW6GPUkB/djc7lLnwowwqThVxcypAgcVTNJ4eB92cPLK/A= 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=Cn8ZLU9v; arc=none smtp.client-ip=209.85.218.41 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="Cn8ZLU9v" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a51abd0d7c2so514740866b.2 for ; Tue, 09 Apr 2024 00:30:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712647829; x=1713252629; 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=YDkw88b3lYtuDM0Po1l0W+9RfoTKioIBFPIWL2ETjQQ=; b=Cn8ZLU9vTohx1aDiofsJY7ebXX62QtHYyavEQiAHhYjL4Wk18nhXjuKU/Vb8BMhLbg bixcpiGH+PT3+ls8jlUAzwmbV/WTN33du8Ef8iQabu98KPHu7hMxurBcekuCXY8vmr15 96e0CeIz2H469vlB/A4ts01QY4zjH5m9SpnSXmF/BMlkF+R6vRUHci9bU2fL7lR+cnd3 jKrc4Y39S5dvAVG8JUhC0nN9I2eU2EfNMk+2PEH+ByIjby5o9TpUhFCgIf1wvNYJjvXI RhHoBXUGHl91xXaY5QvT5XTCcCd0Ried9jqQcNBmjos98+sh6flV4KhBd0rKmt8ClGgw yEuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712647829; x=1713252629; 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=YDkw88b3lYtuDM0Po1l0W+9RfoTKioIBFPIWL2ETjQQ=; b=byWVRjMQCHUH6P2tXyoWulr4uI/HPMrrhSV96OPD0TM7Vj6XErdXFCS4qLrTCypKSk VyyXiYsi95wQ3XaoeUgmaxBqZoeA1fg5bI3xVE7tZ6A91z03P6E/VtItTyTmBXeSFuwV 0W7IVkSs3Gn6BSf2dvL3IJQuulmXZ4v0wNyMDZU58ARRcMTVToxtr2SXfWCbQzj7stjo +sTdG1/Y80hW2cjmYh6uNqkA6ZuGp/s+6QJ9+0Jge2lJ//dZvcfqUfYFzj4YKO+cWZXh Y8zBo9wUTk0JsUdT4jf34mfVRIkW6gz5Bp7Kia1iMOGl6DAy3FWKz1Ao7EsEZus0hUOw w4Gw== X-Gm-Message-State: AOJu0Yy03tXakWFse5H+N2RFSTYGF7SsNSzw6E07O2/ZWO24PuNWI2IE BUOAj3Qt1S3A1B0po4T16PP//fFEYFqO859sAYfSr5PT2FjAyIvaBtlJaVVo5gU= X-Google-Smtp-Source: AGHT+IEJj4qTvawNrr/1mvzrgObjIkXXMzC0xE2m4ZuH1Iu2C5jjXms5vA5AA5SI2Jq722sfHhf7Fg== X-Received: by 2002:a17:906:2e88:b0:a51:e5b1:6d4a with SMTP id o8-20020a1709062e8800b00a51e5b16d4amr1229036eji.64.1712647829602; Tue, 09 Apr 2024 00:30:29 -0700 (PDT) Received: from corebook.localdomain (2001-1c00-020d-1300-1b1c-4449-176a-89ea.cable.dynamic.v6.ziggo.nl. [2001:1c00:20d:1300:1b1c:4449:176a:89ea]) by smtp.gmail.com with ESMTPSA id j25-20020a1709066dd900b00a473362062fsm5315694ejt.220.2024.04.09.00.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 00:30:29 -0700 (PDT) From: Eric Woudstra To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?utf-8?q?Marek_Beh=C3=BAn?= , "Frank Wunderlich" , Daniel Golle Cc: netdev@vger.kernel.org, Eric Woudstra , Russell King Subject: [PATCH v4 net-next 6/6] net: sfp: add quirk for another multigig RollBall transceiver Date: Tue, 9 Apr 2024 09:30:16 +0200 Message-ID: <20240409073016.367771-7-ericwouds@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240409073016.367771-1-ericwouds@gmail.com> References: <20240409073016.367771-1-ericwouds@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 From: Marek Behún Add quirk for another RollBall copper transceiver: Turris RTSFP-2.5G, containing 2.5g capable RTL8221B PHY. Signed-off-by: Marek Behún Signed-off-by: Eric Woudstra Reviewed-by: Russell King (Oracle) --- drivers/net/phy/sfp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index f75c9eb3958e..6e7639fc64dd 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -506,6 +506,7 @@ static const struct sfp_quirk sfp_quirks[] = { SFP_QUIRK_M("OEM", "SFP-2.5G-T", sfp_quirk_oem_2_5g), SFP_QUIRK_F("OEM", "RTSFP-10", sfp_fixup_rollball_cc), SFP_QUIRK_F("OEM", "RTSFP-10G", sfp_fixup_rollball_cc), + SFP_QUIRK_F("Turris", "RTSFP-2.5G", sfp_fixup_rollball), SFP_QUIRK_F("Turris", "RTSFP-10", sfp_fixup_rollball), SFP_QUIRK_F("Turris", "RTSFP-10G", sfp_fixup_rollball), };