From patchwork Tue Apr 2 05:58:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Woudstra X-Patchwork-Id: 13613381 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 73B8118050 for ; Tue, 2 Apr 2024 05:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712037541; cv=none; b=VVZxwfrripa2KP4t6w0iViq9KIoh+gjh3bhxFln0k1PIKVhnEXXAvVeoUGjj2UwBFeq/KNRTyBr3Tcy48pfiPzed+0cyXOhXaCFrMnsuKUo0oTl+sT69bFjLz7vlp5YlyqhNGjKDr/Ba3vfevRzbrGbDWmvmkVujWnMuFzsHp+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712037541; c=relaxed/simple; bh=Ampd6HQHcXxr9ZEFyFME+2325RtBlr/wpqtz3fXPUDo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MEiaf3ncCaEjX8b9RVTBfg9z8aDefsfYWBigSPrzxxyiaBsrPL8rTsQkXktNuIYGDKIhzBDnVwSc1V7CTU3WPVRT7jFNEkiEBuOnUw174K65/AcQ3ASneiGtHHQ24Q2Hfk6rryndF96HbAm0f6aEqhBSf48r20zKwRo/xmk03nE= 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=Pbo1Z0ds; arc=none smtp.client-ip=209.85.208.51 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="Pbo1Z0ds" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-56d5d4d2e2bso2613928a12.3 for ; Mon, 01 Apr 2024 22:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712037538; x=1712642338; 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=L9V31exu69XJdwQKx28bPGGlT6S7Qasz8QRl4Vw0vQQ=; b=Pbo1Z0dsWsWNwGIGnJbqhrXpbYy0ZNDQOxk17CMe+rMmhq2GW8XiPuQMqj5smzedxT EzcUhfjRaSGpVi0uuVXczsuFc+8gcQ6IWv+zqV24PFBBcUL6gwAK6tEmikrGBPybixsZ TH6w+Xa+VtY4/jQhbWmKhXXT07+D/4oOyv7H/fuG2yDqrl3c1DlZpPDw4w7rlVIfbjgJ Mm9mOiOmMMllQi0NJRhHUVEtEIXiTB5Qb8TnlrMI9IYE8Ww09y/5EPygLH0Myy/OTl4o KnRKPjPIcpvfAFlcwaTbh4YB+mXKOBGv+dLN6I0GEEKKBJjpOrAOEOuxiRbV/bUFE+SF RGDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712037538; x=1712642338; 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=L9V31exu69XJdwQKx28bPGGlT6S7Qasz8QRl4Vw0vQQ=; b=BO5+gT6SPOITNK0GkTXhmYY0k7bPH1GV4r1tDfT4XFHNLqflTaRTocpoiVc6nf6JJY jx6iFc2V+o/5vZqs7s4wJFkwXFt7gxVNnrMsKK2z+GUDNYMA4suTmphmn7FJFVkwDTWN X/HWG8gYEpXL4OZmQHYCeNBt5DSGhabYLIwS58OKBYyZBZQDEpIplDG709wMGCIa7qfx DEwXXFeNlg/3S83wxxOCJU0aX307rdgiRy4PPyrDRFildqmLcvm3+xnUcFhCYXjSWbbK y/eUbPWDifj26cAaFawPP+IK+dcwVgbtlotmdyL7UeN3aHvAUv+PsszoeCDFZhS9qCWG ZdMA== X-Gm-Message-State: AOJu0Yz6c/qyxMmZVZ1B91iHRve7vE501F6peqEzN2diFoMwzl6qLPC3 lbzHRYYxgog9lVwzgAFkTAAbBS7mHTa/OuN0hZBTt1bHVeIB8FHK X-Google-Smtp-Source: AGHT+IGSJbMuI3uG5O0FyVMCDQaucJ3ZC0NDFnhrGUr4E9b1b1qTCQ3NYPhdUW9019kX8ws9bTZJ3g== X-Received: by 2002:a17:907:11cd:b0:a4e:2d1e:6914 with SMTP id va13-20020a17090711cd00b00a4e2d1e6914mr6946123ejb.11.1712037537512; Mon, 01 Apr 2024 22:58:57 -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 cd1-20020a170906b34100b00a4a396ba54asm6136636ejb.93.2024.04.01.22.58.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 22:58:57 -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 Subject: [PATCH v3 net-next 1/6] net: phy: realtek: configure SerDes mode for rtl822xb PHYs Date: Tue, 2 Apr 2024 07:58:43 +0200 Message-ID: <20240402055848.177580-2-ericwouds@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240402055848.177580-1-ericwouds@gmail.com> References: <20240402055848.177580-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) --- 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 2 05:58:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Woudstra X-Patchwork-Id: 13613382 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 64F4E182BD for ; Tue, 2 Apr 2024 05:59:00 +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=1712037542; cv=none; b=E1yRCx5UzJaqVVpMk1KwLyruObW7ei1hNyDt6OxRUXuJkvWLofpACdu9t0IstL5dVU+Z6ABgTX4tG1UIHYzY1kzuWr4zfoZFFld6vf2lHVcOHEFhx/c6u+V939qHZ1X9QhyQr6aerxihWxIctEWsChS+DJBdWlEmV7vR23jqtfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712037542; c=relaxed/simple; bh=bakkUEd+sfh8hCc1uTZ1eQ7Ul4771yVG6DUhGDryZOU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fM4m90W7oCRGNs5Nkl3/xITowvaeBI00Iv6D49TdIQ0khQogpU/Z2K/puvX0ic5Pp6KrKtJFgLtW8xF6PcyapDW7ZcXZSqjRy20QCmC5jIn1Bl2OMmLTv4S4dK1tyG8SzFrF1zaAInj8XLUh6i1S4iAuR61KOY6KFTXLNMOU0x4= 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=lrqM2aBs; 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="lrqM2aBs" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a4e83bf72f5so55354566b.2 for ; Mon, 01 Apr 2024 22:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712037539; x=1712642339; 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=EL1uEd3eRQvQawYg+l+RPdo3Mmhw2fuADfl058DWnRw=; b=lrqM2aBsu1wi3aW1Bd0zKXubTOk/UF4UQcSujT7kNV9gbfJuAIHkrIaXzNY7c+lzYF GSpIC5GG3xUXg6eLJtXfaaOz2Ho10lgNO32eGLbY4kQiNYmecPxsIav1hvnyrYXIxaln qvVR8nbyNsyvopxsoLitRuGwxo8B/CPDylQ2yBM5ai/JEXMtIyYd3qKVCULD90l0nezw /H8e1rpeWCfX7Lo5JXWCgLoyk2TKKr9cm1pIioix7Ic8LLklpjM90IYcngRKRqODREVd 4COJB8pqtmGT8FRDqKD3EwRRWun7t+qSzARthqEAkuDYOjspvcgzJhMfqv/ONy848LLj KhjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712037539; x=1712642339; 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=EL1uEd3eRQvQawYg+l+RPdo3Mmhw2fuADfl058DWnRw=; b=pbdxi6HYn1XRseIzTTIcCjf7IOZh2+orMJI7X58EIGXljHi7nl/Rul3ekFOABuPdsO 1hkLXKfzyQL0n540YR/UW1VKH2FyFDJoykx62CUlIoXlqEGafZ2QZiA4OwzKjgGIOLul GBNmNjpICD0ODAx2dPImS/4KbWU389CkSlhTyUZNAzaa4ZKV8ymvup7W7v+HuXXKyMcv 0MILtlqFlzVCwmvoSwlN3QfGGEdDvPKqjwGp4UN8mjKqr8q5XPb/5+U6FD4YRUhUtXgn rggdyMVEdSrfF6GCPrnCYwpSVt8e0c6SMjFHpcctPZgsUV1J1WT+k5H4dfToIKSygx9P 35Eg== X-Gm-Message-State: AOJu0YxaD7SleYrDrrKawHdB/82AIKK39v0f/D9n9YpMsSQefOV247tX OZyBOLDmSqtElUJ5LtdTaSILgj41Ou1uQe8wyG2SgBVvhUpCxZ95 X-Google-Smtp-Source: AGHT+IHcnXgHCh/88IMrBDCpojdyLEiP7DVutJ0YLcIPEebpyK5hquhk4qeYckOgI6Cp0ZjEX5eRiw== X-Received: by 2002:a17:906:eb59:b0:a47:4fe1:cf99 with SMTP id mc25-20020a170906eb5900b00a474fe1cf99mr7489484ejb.21.1712037538566; Mon, 01 Apr 2024 22:58:58 -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 cd1-20020a170906b34100b00a4a396ba54asm6136636ejb.93.2024.04.01.22.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 22:58:58 -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 v3 net-next 2/6] net: phy: realtek: add get_rate_matching() for rtl822xb PHYs Date: Tue, 2 Apr 2024 07:58:44 +0200 Message-ID: <20240402055848.177580-3-ericwouds@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240402055848.177580-1-ericwouds@gmail.com> References: <20240402055848.177580-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 Reviewed-by: Russell King (Oracle) --- drivers/net/phy/realtek.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index 70cd1834a832..ca1d61fa44f5 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -726,6 +726,28 @@ 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; + + switch (val & RTL822X_VND1_SERDES_OPTION_MODE_MASK) { + case RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX: + return RATE_MATCH_PAUSE; + /* case RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX_SGMII: */ + default: + return RATE_MATCH_NONE; + } +} + static int rtl822x_get_features(struct phy_device *phydev) { int val; @@ -1091,6 +1113,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 +1137,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 +1149,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 +1161,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 2 05:58:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Woudstra X-Patchwork-Id: 13613383 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (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 1778B1862E for ; Tue, 2 Apr 2024 05:59:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712037542; cv=none; b=NFQ3f6DXjH8FAZe/TCPIQvcr7BkKxBJBmmFBrDnAXqP8wbRDz1gI5P1xHizGatw68Y1Vyzk2tSc5pgtknj8AAiyuMGqvPn3w6xGAjUrCp+yO5DiK/1Ogd5ibK6aNVVUukRq2cgvBjVW3uRxd7RPlx7hB0kcnsMcmYXCSnOAEW6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712037542; c=relaxed/simple; bh=A3MVv24g4QV8LN5gJsYKjdeaaxkNitOaJ8A8zhZZS8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qsH///FnJ7V3avi8cTPn6m8nKQyieEApUc9sS5yR11I0N4UjB5RsRO8EftvRUr2d2bPDPb1J+ZTs9F2ULktCr8bzxRo5jgHazKXZvIaCB8vWBeIs+2RQv6e/dYtYQSM0aathcq/vkzXFVKZWahZjPXZ6AloXOWlTWQMv7dua5EM= 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=NNwsP06w; arc=none smtp.client-ip=209.85.218.44 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="NNwsP06w" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a4e62f3e63dso210041466b.0 for ; Mon, 01 Apr 2024 22:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712037539; x=1712642339; 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=hRkNpAKRKsU36uMj/FI8dPhQFnxtSs2t1Hcr7YYNwBk=; b=NNwsP06wedvvqGoCd9/gj/z7WFa3AN9CX3AjNXqOx7ir5qcDOciJNb3Oqg+J279QZV kWVq5PnkCsKMHk85HgPcZQbnNMetl7rXR3nQYXPjEiWW3YAiuUAa3vq9WEi6XGHVeVl1 1Zy+rt3l8ZKYPwSIZi1mgNjv0VJLIqFLWj1mXDkLBRJM+t2x440GExQMLzkd7qI/xDVM 9V3u8Skwt1CZcTxyAns5mMulgNex4MNy8U3j4sn6u3/bcH7iJMoOU09Wrk1fAvv+7/cG 7dXClkwgEKNJZlozmaWMnmJyAeMwYjEzVPUCAx3vijdHMT7tSMdrHHRdhpYzCHV5C/0D QtoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712037539; x=1712642339; 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=hRkNpAKRKsU36uMj/FI8dPhQFnxtSs2t1Hcr7YYNwBk=; b=P+KysBReeo7uBtfS6Dm0rGowhNu4m6EKi1dGHt+ZW8jt57fRVbhF7UMNfy0vKbr+OF RZGm4wqU/nudiqBtgwSELbvxiz5ExGGQXIS0wfp8c2/bm6mSTz0UM73Ym+7QAojd0j0w bFQ9hFcFdHR7ge+y/ug+0ResQLxc0LXkdfYb0Bs1i7qdtxV5Y3qgo2fJNzUw7rddRCVU bDh5wqjmamxzp8r/DakrRLIdQijrD1K2OcVbi56EusjSLPj/GXv5JyStAfqpQXWtRNvO K8GtuKaTuB9ytvXj1brfK46buDUnHzlSIKqJgeBfVhaTgJKNFFpaPUIktSQvilc7cq9/ OceQ== X-Gm-Message-State: AOJu0YxtcYo8nd+Ta+Z+phKxAsrEtvTzMCf+0FfstWts8CSGvSZR8xYK H64ABZD2j6AOKobHn1g9nwp2LlRKUceItb8rJ7X7buvONynJObCM X-Google-Smtp-Source: AGHT+IFyGjBlnGuP8Md3eiF4ioBdvDiCnO/LkPva0dEC2gLEEqGHYkEEVrL7bfkFH1OOIaqHF5X0vg== X-Received: by 2002:a17:906:30c4:b0:a4e:fe3:ceff with SMTP id b4-20020a17090630c400b00a4e0fe3ceffmr5394802ejb.57.1712037539398; Mon, 01 Apr 2024 22:58:59 -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 cd1-20020a170906b34100b00a4a396ba54asm6136636ejb.93.2024.04.01.22.58.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 22:58:59 -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 v3 net-next 3/6] net: phy: realtek: Add driver instances for rtl8221b via Clause 45 Date: Tue, 2 Apr 2024 07:58:45 +0200 Message-ID: <20240402055848.177580-4-ericwouds@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240402055848.177580-1-ericwouds@gmail.com> References: <20240402055848.177580-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 ca1d61fa44f5..2215a31d5aab 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"); @@ -840,6 +850,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; @@ -863,6 +934,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); @@ -873,6 +973,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; @@ -1144,8 +1253,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, @@ -1156,8 +1265,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, @@ -1167,6 +1285,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 2 05:58:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Woudstra X-Patchwork-Id: 13613384 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 427EB19477 for ; Tue, 2 Apr 2024 05:59:02 +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=1712037543; cv=none; b=glhBRYtdgif+cVACGSAfEsOtjZKnqt8kWdSptameCOOkxdVV6uAIOO+iDvPMEvn8Chmako9uk3yhz2oE5ZYABTujcyGrR9BJdfbcYxlvYNTxJrdhc6BMxAOm1OW/DFNjVgE3wlWWCbmdj0WTgygv8mYNR5+u6XGa/mtupIAS/1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712037543; c=relaxed/simple; bh=qI4EkGt1lRVXThePQvIizEVoKNfdwX3+gMHUx9GulF4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BcJA3FY593KHLYeapA8qrIicp7mf/cKOmIJAq3+kz0f/UWolicrIGmJbMegxNhxLBTNPrODe3RmW8ILtpo2uYaQ7xZqbtzNHrRo/ZziiPuF90S3ovKIWfz70ty9rhBhpzJCctZtalgVVcilRh9s3eAaFyQVTl2BWv78E8U/aFvI= 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=GyutLmJz; 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="GyutLmJz" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5688eaf1165so6505089a12.1 for ; Mon, 01 Apr 2024 22:59:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712037540; x=1712642340; 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=U/ybX8G8LSGKMTLWp+71FV+9Atmqurbwgxi8KnNdjoQ=; b=GyutLmJz2/OZrCKdFE3Z7ljlejoAIH0mWDluCuMmf76WnDpddoWA5splwo76ms9W0j q8U/NsYNNKCofhUM3RLuHvomyIA8IoabLV3zNRGV6BqGzStb4tdUu9o5rkV29Augp50P UaxYz9v7GiJ+e3O89igw+gB/sIJY4w6KIAHW+tRRPsdvHwMYb5w2rtArkzQRYSHBxNK+ ozg6B7bYBXAr2b7aB3u9Y/gpnbAbMTkG5KooUxzcC/1Gyw9SjQKnZSNUNGrvvDyuX/s3 71WtIQOZytyY7zJQ6ZjY3REkOhsIghXn/gpoqp4hUEGaF234kqiSVoG+I+Jp/R4DkUhf IfUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712037540; x=1712642340; 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=U/ybX8G8LSGKMTLWp+71FV+9Atmqurbwgxi8KnNdjoQ=; b=TUGHdZjYoEnGE7zr+lDSe93ExnRWwVxckk06wk4770q1JYCgzwwl3hP2d1tEQDB7SZ mMtquFcnyy2KoBkS8zymS3imguJ6UUsYsvq+Lwo4Y+0qpFkyOaqjdHzadHlSpBMiI9PC npItO+IyAXb/Bpq5Sdk6Hwq5MYqiNGLWeAanWQQRpxp3EutztgItTr3omQeX9s89K0Aw MF7XCbIFwE4dZIIEmjDGkBx1wJsEqmvMRuh9zHge1gFkWDqObW3ITy0081QZV7jy0vpt I3OGgnDoIdZB1a18baO7q80HN6R5J3gMxJ5KAGOLeccWRQg8+T6Wgfok8VqLU8m5H9Fl DNAw== X-Gm-Message-State: AOJu0YzcoW1ELj136/YEtY8ZMYjBey06f6RgWPw3uxxI5eztJZ0Ydy7I IbZ0zQ974l6NDU52Vjg+pOlAmHAcPy+vZDqscObrt3BVVKLTJIl3 X-Google-Smtp-Source: AGHT+IF8DzA+EderdBEm8/ZbyTZ5BDpjyIQxX6iby7dBG0Z5sFRY6GnOGqiLMrlp+sUCLgKnVyATpw== X-Received: by 2002:a17:907:77cb:b0:a46:8c9f:f783 with SMTP id kz11-20020a17090777cb00b00a468c9ff783mr8062157ejc.67.1712037540619; Mon, 01 Apr 2024 22:59:00 -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 cd1-20020a170906b34100b00a4a396ba54asm6136636ejb.93.2024.04.01.22.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 22:59:00 -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 v3 net-next 4/6] net: phy: realtek: Change rtlgen_get_speed() to rtlgen_decode_speed() Date: Tue, 2 Apr 2024 07:58:46 +0200 Message-ID: <20240402055848.177580-5-ericwouds@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240402055848.177580-1-ericwouds@gmail.com> References: <20240402055848.177580-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 2215a31d5aab..af5e77fd6576 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) @@ -818,8 +818,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); @@ -830,11 +828,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) @@ -895,6 +889,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 2 05:58:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Woudstra X-Patchwork-Id: 13613385 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 0E9781C287 for ; Tue, 2 Apr 2024 05:59:02 +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=1712037544; cv=none; b=FpYS4MaZXy1gb4vvNILrusfwllAjcXzIfcZpycIXxi+bxlW2byNPkdfwmRTAXCXqTJW2J77Eg6dw4orR5C36+MO4u7ovzpjumvlKYUoRh/mofiwgyTxGKGkLqcbVIUfWsTY5q2KyXKS2pyzzWPj3IFbG7V79Nzem/z1MC3JLy3g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712037544; c=relaxed/simple; bh=w8fn6+LGaLVqhS8crIsqZ0BUgFZZpm5jp8uYVJr9sWo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m79RJ8yXekZDPR23Z2S76v+4m2qTGi1IDSxODeBAvtR0xkCzJZIXHYGkMeyF5yDAyIvQwxz/n6joM+rYq3TTuGcIVLei+XiK/AJJ9/gWSUZ6fvW7T8Ng9PiFVHLaBBurCqoaWU5aBStZKn/kKi1jIPL+Qo0/l1YpGqGxKp5CPSU= 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=jm0ImZcg; 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="jm0ImZcg" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a472f8c6a55so592082666b.0 for ; Mon, 01 Apr 2024 22:59:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712037541; x=1712642341; 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=EWFVQ4guP4fCF27EbKTTsXrsTp0zlLou+J3gTsJX728=; b=jm0ImZcgh8zus9ld/S7zQWcK7dlor1LaHkjflZy6UJPKiUk8NyS4WjtXyDdDWTKQJR WhcJtg/NBT3iI3UibjyeHd5mRnp0vilJNOgMAixSnVnlo8c0i567JIJzcs2wmR/IjJ8N VCEkNVKBr6VZtpFypV9HgXyv2Xhl0b381Fl3taB5SXPm5kPOLgZcXHJ5ALRcMUdLS9h4 w51a/76/JW71k4f3uyBr3BoYY/s9ldUr9JRF8QDkOev6UqSxBnD6Z3aoXonWPCKWkfWa uCC5V66BuKl7OWgJa6jIwEfMGFtzpOs1x4nfxTzNbaOE4i06hmUyyO8dcSeBIDDfggZd nBXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712037541; x=1712642341; 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=EWFVQ4guP4fCF27EbKTTsXrsTp0zlLou+J3gTsJX728=; b=oih3pTE8jz6oYg62EXJseaF1yMmsx7j6oGfN2RW/TTUKA/KrtKefq1to21YqjPW7Ws 2MeGO2eLoy7fKbP8wQx4Roiqyx4QeUTmVtFLmOm+NydLHyvLaZPvKrdyYMvQkoAb+2Ce aMtlX/hplY6nfW1sldOssvwDAgPTUI2ftBbqPM6M0cZqJotZitd22WnvscgfMKTEcK2/ 3EzsC+TLq3Mo53QmF+VFSofJlHPYCbjIs+mBNliRxewx/29WdJbeVZta2eEKgBlgSvaP mYH0GC4BQrub/Y6Hr6NTZO/0KnMQz9GfK11Bf0ML+p2LTqWZJztct8fq/rQRQTv6m6mU ffLg== X-Gm-Message-State: AOJu0YzHAVrPVb7lBvnxlj4yLXBNEXs/Gkxh8T3lUggN+O6K3GpAmw2o c4VU6MI325sL6Cd9McBUprnJQlaqjTixnfs2UYAq68iECabR68vZ X-Google-Smtp-Source: AGHT+IHyOmxdylBaAdGtX/ALZTJpDWBg6b5kPKmI9BNtudTkN/YuGQq1gam6eJPJ65nGBFzhgC+wjQ== X-Received: by 2002:a17:906:c958:b0:a48:45e7:5d46 with SMTP id fw24-20020a170906c95800b00a4845e75d46mr6876565ejb.22.1712037541454; Mon, 01 Apr 2024 22:59:01 -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 cd1-20020a170906b34100b00a4a396ba54asm6136636ejb.93.2024.04.01.22.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 22:59:01 -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 v3 net-next 5/6] net: phy: realtek: add rtl822x_c45_get_features() to set supported ports Date: Tue, 2 Apr 2024 07:58:47 +0200 Message-ID: <20240402055848.177580-6-ericwouds@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240402055848.177580-1-ericwouds@gmail.com> References: <20240402055848.177580-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 and ETHTOOL_LINK_MODE_MII_BIT in phydev->supported. Signed-off-by: Eric Woudstra --- drivers/net/phy/realtek.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index af5e77fd6576..b483aa3800e2 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -844,6 +844,16 @@ 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); + linkmode_set_bit(ETHTOOL_LINK_MODE_MII_BIT, + phydev->supported); + + return genphy_c45_pma_read_abilities(phydev); +} + static int rtl822x_c45_config_aneg(struct phy_device *phydev) { bool changed = false; @@ -1273,6 +1283,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, @@ -1294,6 +1305,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 2 05:58:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Woudstra X-Patchwork-Id: 13613386 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (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 5F3481862E for ; Tue, 2 Apr 2024 05:59:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712037545; cv=none; b=L5ozDepgH5LwOoq2S+wH+bs6aTUs2Czovu2EkkfQGZjU+ijgUdm+ErA6QvtFsIkMN1maXFCfYlm6Zsm6YM4gd7XKhtadOU1DONclpolbdX6sZ9UUMvkemM9paL1/XnZnXz0E7wlbCXhyyw6xe100YOOrU3iRpw0cxU/0O84NmQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712037545; c=relaxed/simple; bh=wvKMTNgAe1hezUcUgYIskyDhvLfQTRzL4d6cbfc9M/c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YzLKJmJ1ZoOBiEmR1jqARD6ARZX1IWOJbwNX0jqGjTUnWZDtfCWWSKv3SreYM4F72L2uyMTA7lXZTayShdw4sulI50d2CxBwhgD8b7SQK9rLCqL6JVLOjxWr+yVtVMPtGt+XcQiF4AovuaSh3y+5E3QlcVnBgE8Sze6wUeG9PtU= 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=mXVKzOG8; arc=none smtp.client-ip=209.85.208.170 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="mXVKzOG8" Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2d485886545so78372941fa.2 for ; Mon, 01 Apr 2024 22:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712037542; x=1712642342; 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=fScNHd38fKXVunjONxLTs2Bfy7uVYSFHE6CXgTpd1f0=; b=mXVKzOG8C/5n6ihTez5khMLYq28Rp6n4BPJxkLTFa86ZMLXQan6ST7HOFkjavu7qHi jCR4hAbqI/qCB7fBGL12PQozcwGZT+CJUL5AI+gwe61reqHjF+7HTvyKIZW51UR2pss4 Yze+TKaYMCY3Xu/iRtNorB91RhKVLQZuKHUTNfSe1/DwaBTmxeSIAvDPOFG2jSU+9STI W8OEC9fAN5UNPzdTI30cKcSTvlXno6W41d3C0Bb5yfgjBFR3v+4UsebAnSZFPz3u5qSv ePQEdF88+4cWz5xCo8Jab2rH2h3lNTl1roVtyRZHw54yLPm716fa/cRK19Ye+/TGnLxC D/dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712037542; x=1712642342; 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=fScNHd38fKXVunjONxLTs2Bfy7uVYSFHE6CXgTpd1f0=; b=FpCyHkpyjzDYLcJNeLFzM+bDJotd7yb7TXA3UFXKm2FLTsWHwt5iK5OOdE3eiKBn2q /shBPKD2kGeJUrKR3tIKNphwgXWH5gDspSJFZeNEy5/y4CEw4uXhbHpTGYWwZKf3PEu/ 0342B59CAkSYvRE/Y1sDVFiKfxQeNHXzGXh2Knky6+FuMH8autAsNTzSUOK/uLOSnCkY m5TTts4lOpRy4v61DP0HlmyzQKOjuAHaXjZ3j44GdXuA6cWshBxAKpd9ZAHuBgY/SwFQ acTz6YzuCmNGEzoIw4qwGVHuOS6eKDb2iKJCNo5DK/XqzGa9aCp854d+G2MNxBcUoIaj 6OLQ== X-Gm-Message-State: AOJu0Yx/7wguNea01yzoUGAn2zdYa7d7Oh9FvAOa+6wFEZCyYsT0QvM+ 9hOBwJ0zC9aW98Ke0WcdrSr32XgeXZ7MzfkwCx2eum5qyuQhTVQ5 X-Google-Smtp-Source: AGHT+IHQq01t+zLvi4gg/ASiwTxLItUQ0scBfNMl90zXnqrMIzSsGRvxMThIGdcwSbPtpWgKrDvmzA== X-Received: by 2002:a2e:740d:0:b0:2d6:cd05:1899 with SMTP id p13-20020a2e740d000000b002d6cd051899mr456510ljc.17.1712037542419; Mon, 01 Apr 2024 22:59:02 -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 cd1-20020a170906b34100b00a4a396ba54asm6136636ejb.93.2024.04.01.22.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 22:59:01 -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 v3 net-next 6/6] net: sfp: add quirk for another multigig RollBall transceiver Date: Tue, 2 Apr 2024 07:58:48 +0200 Message-ID: <20240402055848.177580-7-ericwouds@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240402055848.177580-1-ericwouds@gmail.com> References: <20240402055848.177580-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), };