From patchwork Mon Jun 24 13:26:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13709518 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 055BCC3064D for ; Mon, 24 Jun 2024 13:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=L+/PkaXmRsVYIqKGZx4UeA9J6j62ytdn83yxhqwCP6o=; b=XAFlDA+rJ7+viI+mCH5t05Mqf5 6NGaj3X0hDlAJ8pWPKcV1He9gUhqlkS8wMWHdfrYa5yfttD0/iMrJ/LQZojG0ACm1+AF6M+61+F8l 0aS8Bp/XDN92cljT4e9UZhrFp0yDyKJP8YE6SQYCkk0FqzzspUVn+DzW+6JjaEVYSlrCtVlIHnhhz KFRhpn6jj1KYhfdqNQBkcDqxHHUf/30oPlWznMi0r+sqns3626vxnLFflNUGgz/g7hFL12b5WDf2U BqQLmFI8A+9VP8bcw06m4JeL409ZQyFlmDpe7pY425KfNCuKZziaN47C4MGbGSTEWKY0HJ+VVK5dH SNKVmUVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLjkk-0000000GvC4-0JY9; Mon, 24 Jun 2024 13:29:02 +0000 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLjkO-0000000GuzS-1DTv for linux-arm-kernel@lists.infradead.org; Mon, 24 Jun 2024 13:28:42 +0000 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-52cd87277d8so2670026e87.2 for ; Mon, 24 Jun 2024 06:28:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719235716; x=1719840516; darn=lists.infradead.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=L+/PkaXmRsVYIqKGZx4UeA9J6j62ytdn83yxhqwCP6o=; b=ZhOrEeSpeBnRcSSMHGFoPZiot8+FRl3xcAskX4Pkb67SvaGzvG23FNwB2kkOipkXF1 nKGSwu2rLTCz+zH6AUxwLKKP+GVMLFkRww3PCXosKOCDMOKHIWXM7e3Jed1wO/ZgOru1 ktwG9gC2Z3S13t71hmYgpzlvcpNBUu4CwEFtDa9VOXKdsHSMgggHxtrFvYO9hm3MYnFX KeDrqNLtAFMVbSLGlKCf6Iq8TE+fAfikE0PErCmKrDtVBbsahBiapC3PQOc/mcJW7B7y HAdXZkXpGl2j5BAcLib42cZS25kBtFGyO9n67OAat8YcJhiiEXr2bE59tSnwDRuO+AxP VZnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719235716; x=1719840516; 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=L+/PkaXmRsVYIqKGZx4UeA9J6j62ytdn83yxhqwCP6o=; b=RaKQRaO1oUblb8DnK7MiScoymTpfbfEu5aZ9SvPLI4QT1nVPl5Pi1RChuTtj+XRmP0 8yBItQGOJJyUZUJw+X1NUaDHrSPUNrc0wgU/veaag7ejoDC54k2vSJIr1eaNtAkALthj Dbzf0kQ/iS8hbfzcLt0HjI8UEjIxv279SGSPoQk2456xnvPDrX6DSbmyrGfQvCaqNf1f eJrPiT8BfXQQyuyhB+MOK/3bKrAFSAfovKK/2Zx1d9+vEa41SpJEmjU01NMscKuZsmtH Iqa9Mav71w9+a0Kai7AsAdPMDaCKMlVvTgaxCwJ6bcs8CHSwwv4ZGnvPG4lO77BOFvZd 3fHA== X-Forwarded-Encrypted: i=1; AJvYcCVvOU9TDWHFgZjYZWdRQEGvlp1We33uNieHsWKB/A8pYo0NYhvG/oEVzyMQHSVYMicvXoKSJHiK7LURk3PQT0FqRg6jUksG/ew5a2Q9KyhmdObWNoY= X-Gm-Message-State: AOJu0YxXdSzJg8JSHnBm6HHs7mtY+N9uKdHrHqrug7K3JpT2/9B7NiPN HA4r9TDaZiY7TbkDIQ74zsvY0n1kj9QSSuT4bfk9M/L+AwGmIhfP X-Google-Smtp-Source: AGHT+IH809R8vF6zTQILCWIugVLXjGsYzjDJo9A/xeg6IqGYA6QXLn9MgMKJTyre4EaY/xpUaBI5NA== X-Received: by 2002:a05:6512:1154:b0:52c:9d38:9df1 with SMTP id 2adb3069b0e04-52ce183263dmr3351699e87.10.1719235715596; Mon, 24 Jun 2024 06:28:35 -0700 (PDT) Received: from localhost ([213.79.110.82]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cd63b4bc2sm982966e87.27.2024.06.24.06.28.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 06:28:35 -0700 (PDT) From: Serge Semin To: Russell King , Andrew Halaney , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin Cc: Alexei Starovoitov , Jesper Dangaard Brouer , John Fastabend , Daniel Borkmann , linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC net-next v2 11/17] net: stmmac: Introduce internal PCS config register getter Date: Mon, 24 Jun 2024 16:26:28 +0300 Message-ID: <20240624132802.14238-3-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240624_062840_623049_EF03F48B X-CRM114-Status: GOOD ( 16.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The optional PCS module CSRs are mainly represented in the framework of the address spaces [0x00c0:0x00db] on DW GMAC and [0x00e0:0x00f7] on DW QoS Eth. The spaces mapping is identical in both IP-cores. But the link state retrieved from the PHY or from another MAC (in MAC2MAC setup) is mapped over the SGMII/RGMII/SMII Control and Status register in a non-compatible way. In particular the DW GMAC register have the link state mapped at the [15:0] field, and the DW QoS Eth register have it mapped at the [31:16] field. Other than that the fields semantics is identical - it's the TX_CONFIG_REG[15:0] register (see SGMII specification for details) with a bit re-ordered fields and extended with some SMII-specific flags: tx_config_reg[0]: LNKMOD tx_config_reg[1:2]: LNKSPEED tx_config_reg[3]: LNKSTS tx_config_reg[4]: JABTO (Jabber Timeout, SMII-specific) tx_config_reg[5]: FALSCARDET (False Carrier Detected, SMII-specific) In order to provide a fully generic internal STMMAC PCS module, let's introduce the MAC-specific callback returning the link state detected by the internal PCS. Note the callback name has been chosen to be referring to the TX_CONFIG_REG data described in the IP-core databooks and in the SGMII specification. Signed-off-by: Serge Semin --- drivers/net/ethernet/stmicro/stmmac/dwmac1000.h | 1 + .../net/ethernet/stmicro/stmmac/dwmac1000_core.c | 11 +++++++++++ drivers/net/ethernet/stmicro/stmmac/dwmac4.h | 1 + drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 13 +++++++++++++ drivers/net/ethernet/stmicro/stmmac/hwif.h | 3 +++ 5 files changed, 29 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h index 4296ddda8aaa..f3a95d27298c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h @@ -86,6 +86,7 @@ enum power_event { #define GMAC_RGSMIIIS 0x000000d8 /* RGMII/SMII status */ /* SGMII/RGMII status register */ +#define GMAC_RGSMIIIS_CONFIG_REG GENMASK(15, 0) #define GMAC_RGSMIIIS_LNKMODE BIT(0) #define GMAC_RGSMIIIS_SPEED GENMASK(2, 1) #define GMAC_RGSMIIIS_SPEED_SHIFT 1 diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c index e525b92955b4..1e50cc573407 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c @@ -365,6 +365,16 @@ static void dwmac1000_set_eee_timer(struct mac_device_info *hw, int ls, int tw) writel(value, ioaddr + LPI_TIMER_CTRL); } +static u16 dwmac1000_pcs_get_config_reg(struct mac_device_info *hw) +{ + void __iomem *ioaddr = hw->pcsr; + u32 val; + + val = readl(ioaddr + GMAC_RGSMIIIS); + + return FIELD_GET(GMAC_RGSMIIIS_CONFIG_REG, val); +} + static void dwmac1000_ctrl_ane(void __iomem *pcsaddr, bool ane, bool srgmi_ral, bool loopback) { @@ -568,6 +578,7 @@ const struct stmmac_ops dwmac1000_ops = { .set_eee_timer = dwmac1000_set_eee_timer, .set_eee_pls = dwmac1000_set_eee_pls, .debug = dwmac1000_debug, + .pcs_get_config_reg = dwmac1000_pcs_get_config_reg, .pcs_ctrl_ane = dwmac1000_ctrl_ane, .set_mac_loopback = dwmac1000_set_mac_loopback, }; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h index d3c5306f1c41..bb2997191f08 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h @@ -567,6 +567,7 @@ static inline u32 mtl_low_credx_base_addr(const struct dwmac4_addrs *addrs, #define GMAC_PHYIF_CTRLSTATUS_TC BIT(0) #define GMAC_PHYIF_CTRLSTATUS_LUD BIT(1) #define GMAC_PHYIF_CTRLSTATUS_SMIDRXS BIT(4) +#define GMAC_PHYIF_CTRLSTATUS_CONFIG_REG GENMASK(31, 16) #define GMAC_PHYIF_CTRLSTATUS_LNKMOD BIT(16) #define GMAC_PHYIF_CTRLSTATUS_SPEED GENMASK(18, 17) #define GMAC_PHYIF_CTRLSTATUS_SPEED_SHIFT 17 diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c index e51c95732bad..b7db076b4214 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c @@ -456,6 +456,16 @@ static void dwmac4_set_eee_timer(struct mac_device_info *hw, int ls, int tw) writel(value, ioaddr + GMAC4_LPI_TIMER_CTRL); } +static u16 dwmac4_pcs_get_config_reg(struct mac_device_info *hw) +{ + void __iomem *ioaddr = hw->pcsr; + u32 val; + + val = readl(ioaddr + GMAC_PHYIF_CONTROL_STATUS); + + return FIELD_GET(GMAC_PHYIF_CTRLSTATUS_CONFIG_REG, val); +} + static void dwmac4_write_single_vlan(struct net_device *dev, u16 vid) { void __iomem *ioaddr = (void __iomem *)dev->base_addr; @@ -1274,6 +1284,7 @@ const struct stmmac_ops dwmac4_ops = { .set_eee_pls = dwmac4_set_eee_pls, .pcs_ctrl_ane = dwmac4_ctrl_ane, .debug = dwmac4_debug, + .pcs_get_config_reg = dwmac4_pcs_get_config_reg, .set_filter = dwmac4_set_filter, .set_mac_loopback = dwmac4_set_mac_loopback, .update_vlan_hash = dwmac4_update_vlan_hash, @@ -1318,6 +1329,7 @@ const struct stmmac_ops dwmac410_ops = { .set_eee_pls = dwmac4_set_eee_pls, .pcs_ctrl_ane = dwmac4_ctrl_ane, .debug = dwmac4_debug, + .pcs_get_config_reg = dwmac4_pcs_get_config_reg, .set_filter = dwmac4_set_filter, .flex_pps_config = dwmac5_flex_pps_config, .set_mac_loopback = dwmac4_set_mac_loopback, @@ -1366,6 +1378,7 @@ const struct stmmac_ops dwmac510_ops = { .set_eee_pls = dwmac4_set_eee_pls, .pcs_ctrl_ane = dwmac4_ctrl_ane, .debug = dwmac4_debug, + .pcs_get_config_reg = dwmac4_pcs_get_config_reg, .set_filter = dwmac4_set_filter, .safety_feat_config = dwmac5_safety_feat_config, .safety_feat_irq_status = dwmac5_safety_feat_irq_status, diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h index ba930a87b71a..00995a0c9813 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -376,6 +376,7 @@ struct stmmac_ops { struct stmmac_extra_stats *x, u32 rx_queues, u32 tx_queues); /* PCS calls */ + u16 (*pcs_get_config_reg)(struct mac_device_info *hw); void (*pcs_ctrl_ane)(void __iomem *pcsaddr, bool ane, bool srgmi_ral, bool loopback); /* Safety Features */ @@ -492,6 +493,8 @@ struct stmmac_ops { stmmac_do_void_callback(__priv, mac, set_eee_pls, __args) #define stmmac_mac_debug(__priv, __args...) \ stmmac_do_void_callback(__priv, mac, debug, __priv, __args) +#define stmmac_pcs_get_config_reg(__priv, __args...) \ + stmmac_do_callback(__priv, mac, pcs_get_config_reg, __args) #define stmmac_pcs_ctrl_ane(__priv, __args...) \ stmmac_do_void_callback(__priv, mac, pcs_ctrl_ane, __args) #define stmmac_safety_feat_config(__priv, __args...) \