From patchwork Fri Dec 8 04:41:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 13484763 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IQH+reP4" Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A16D212E for ; Thu, 7 Dec 2023 20:51:45 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6ceb2501f1bso1154224b3a.0 for ; Thu, 07 Dec 2023 20:51:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702011104; x=1702615904; 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=sj+NGTLcVIm2x2Sna2sYJVoQeNn+dqA0+AshLQHmF+o=; b=IQH+reP4eDVUkB6BHPFkAV2l8z79FcUSwc3CD4gTsLV9FmRggyXR5Rox+R1lgLqn/C 0OZqCF9ROwym56ICRSGvbJw4dppqeL2jd9PZBqGxjw+0J+MI5+uzJUH0wDw/NdZxa0Pa 7oHA3ayVPfmQaC5zDIulQ7iAkPeRqyp4eEabkLMHyRcDz3Cnrr+5rM3qdHQFiaDeUOi9 tr53rrsQEzrYNx6CyYbThfZ1fpHKTZfP4eTD6THL/zplswm1MJ8OfWubwBosZPR8YWQj PNh7AbjGTG76p3Hm74+ioOE6Ly1owlNI9xLxDJRFLJKVTZj/Huri3SrHlngx7aPwoNK9 bCgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702011104; x=1702615904; 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=sj+NGTLcVIm2x2Sna2sYJVoQeNn+dqA0+AshLQHmF+o=; b=YCQedBQkJSYoVSwz0VLivEFqcSSe5yWDRBLDJNWtvH0lhvkKVB+MNcjXR8V2DTwPdR 8vJP9jwXpuJTWAETsF0GifMukd4IPmGNEBQ0qV7ey+a2UU/pKPBABwlvSVysUyhhjg4P Bx4ls8Uzt5mmdBlwRYQnBNUl7sVVQRp2QxfXBBdl2S1t8oPCWdA2Qdxq7R9glMKWHb4Y 91ImJlKoxQZ8Vmep5PQJXrtZnWTlrAWrHxfbDzSZWN9gpQtXxM8t45OnBEWIwm3dLimk mf5N7Kb9j8Mk16/XOfTLJWelw2E92/0aGILdKMA7BicDne2TaTXhmN0h96eZXUTI2PsL NXdg== X-Gm-Message-State: AOJu0Yzdt63dvNjtehocNc4hv8IgdbeFEbDf5hyYF4g2k+dX43+U8zo3 IDePu/ICmuFUj4y6QrQWBiwp6P61FT6jhBM4 X-Google-Smtp-Source: AGHT+IEA6Wcfhjn+312rzY5UMo1zhqifO11C3yBoAmFuBYkH8Z+lVVpGDfmiZ8j7i0NQujB2Yl5Myw== X-Received: by 2002:a05:6a00:1249:b0:6ce:3aca:c5f1 with SMTP id u9-20020a056a00124900b006ce3acac5f1mr4372705pfi.50.1702011104549; Thu, 07 Dec 2023 20:51:44 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:c:204:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id f18-20020a056a00229200b006cbae51f335sm657865pfe.144.2023.12.07.20.51.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 20:51:43 -0800 (PST) From: Luiz Angelo Daros de Luca To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, alsi@bang-olufsen.dk, andrew@lunn.ch, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, arinc.unal@arinc9.com, Luiz Angelo Daros de Luca Subject: [PATCH net-next 1/7] net: dsa: realtek: drop cleanup from realtek_priv Date: Fri, 8 Dec 2023 01:41:37 -0300 Message-ID: <20231208045054.27966-2-luizluca@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208045054.27966-1-luizluca@gmail.com> References: <20231208045054.27966-1-luizluca@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 It was never used and never referenced. Signed-off-by: Luiz Angelo Daros de Luca Reviewed-by: Alvin Šipraga --- drivers/net/dsa/realtek/realtek.h | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h index 790488e9c667..e9ee778665b2 100644 --- a/drivers/net/dsa/realtek/realtek.h +++ b/drivers/net/dsa/realtek/realtek.h @@ -91,7 +91,6 @@ struct realtek_ops { int (*detect)(struct realtek_priv *priv); int (*reset_chip)(struct realtek_priv *priv); int (*setup)(struct realtek_priv *priv); - void (*cleanup)(struct realtek_priv *priv); int (*get_mib_counter)(struct realtek_priv *priv, int port, struct rtl8366_mib_counter *mib, From patchwork Fri Dec 8 04:41:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 13484764 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LZJI/Jh/" Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE60912E for ; Thu, 7 Dec 2023 20:51:49 -0800 (PST) Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-5c690c3d113so1407936a12.1 for ; Thu, 07 Dec 2023 20:51:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702011108; x=1702615908; 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=W0eOfB0tKM0JaOpVnqpzW1lSQC85X8TE4EuRnyccUbg=; b=LZJI/Jh/ySCGsBQclOZjvR4oPpfay/4pqN6zXh3xh+FzdiZUO2m7Ao2Iaq5QNQ66l6 Ie+ehE+1HHuJag7gGCsACwBVz1Iv6OiFllS08QombKYk/Qw2wRGMWdOTwkDLjrHL9bbw fYUWA9mEY126E3X9sxKBDlYpAgQy0CAnnv17/27TEFqANTtMn6Nq5kcpzNEvRC1rE/0R 0AtB74qKNHtIJ0WQoIrSzX/WyRE4tTDbjrSOmEIg1AiBlPXIgYTLYyu4AZlPCH6fQmtb +5Rb2Mm2VJ37NhlGs6DpTDxY3fuL3L9OBpm1nokYlWiTV1oynx9XHy+yvZyYkACyCcbB etCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702011108; x=1702615908; 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=W0eOfB0tKM0JaOpVnqpzW1lSQC85X8TE4EuRnyccUbg=; b=GyxM/0SWVPTyyVh0SPdYHBZY72AUNtFc+kMJjsTAfssSVLqj25nkxMUSlfNw8o7Fnv /AI3k9fL6gXahI5SDCVkVC4Jihp81JZDhOUahlnIzvoN5bL/jSneEiIc8BDSY2Cko3TA GomNtZrMEIqLEFtnwLV4ttMO8wC1QYZIT5qKVzyzHsnGH6ze7JE7Cwlq1i1y7W3Frvqj u87UhBhoI8SY/Ep6Y/fT4mNnEbvpOiSihtBJHwm6SZWmV/um24XI9aCuZhYhtnoXZ//f R3MNKMzfHeqFmCpvxHPOWzRo/9XZFHx+PuCw1IKaZuBUc6lUrd7BFZg9LoUVZgElQHzY MfIA== X-Gm-Message-State: AOJu0Yw3dYHNp65oIHWjAElBSrDBynPsmvM+frBiQGCui/eQ9zadGb6g cTsVueDe9NXTiVQUM5DgFhc90B4f/sCezG3x X-Google-Smtp-Source: AGHT+IEZ8ac1QH/jpF4haqvMomFDcSo8iZPE3X2QwxWDjVsQC2AOB6NJwOMPGEargmYoR2ii4k+MSA== X-Received: by 2002:a05:6a20:840e:b0:189:bde9:9cb0 with SMTP id c14-20020a056a20840e00b00189bde99cb0mr4966326pzd.27.1702011108287; Thu, 07 Dec 2023 20:51:48 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:c:204:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id f18-20020a056a00229200b006cbae51f335sm657865pfe.144.2023.12.07.20.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 20:51:47 -0800 (PST) From: Luiz Angelo Daros de Luca To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, alsi@bang-olufsen.dk, andrew@lunn.ch, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, arinc.unal@arinc9.com, Luiz Angelo Daros de Luca Subject: [PATCH net-next 2/7] net: dsa: realtek: put of node after MDIO registration Date: Fri, 8 Dec 2023 01:41:38 -0300 Message-ID: <20231208045054.27966-3-luizluca@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208045054.27966-1-luizluca@gmail.com> References: <20231208045054.27966-1-luizluca@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 If we don't keep a reference to the OF node, we can put it right after we use it during MDIO registration. Signed-off-by: Luiz Angelo Daros de Luca Signed-off-by: Luiz Angelo Daros de Luca --- drivers/net/dsa/realtek/realtek-smi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index 755546ed8db6..ddcae546afbc 100644 --- a/drivers/net/dsa/realtek/realtek-smi.c +++ b/drivers/net/dsa/realtek/realtek-smi.c @@ -389,15 +389,15 @@ static int realtek_smi_setup_mdio(struct dsa_switch *ds) priv->user_mii_bus->write = realtek_smi_mdio_write; snprintf(priv->user_mii_bus->id, MII_BUS_ID_SIZE, "SMI-%d", ds->index); - priv->user_mii_bus->dev.of_node = mdio_np; priv->user_mii_bus->parent = priv->dev; ds->user_mii_bus = priv->user_mii_bus; ret = devm_of_mdiobus_register(priv->dev, priv->user_mii_bus, mdio_np); + of_node_put(mdio_np); if (ret) { dev_err(priv->dev, "unable to register MDIO bus %s\n", priv->user_mii_bus->id); - goto err_put_node; + return ret; } return 0; @@ -514,8 +514,6 @@ static void realtek_smi_remove(struct platform_device *pdev) return; dsa_unregister_switch(priv->ds); - if (priv->user_mii_bus) - of_node_put(priv->user_mii_bus->dev.of_node); /* leave the device reset asserted */ if (priv->reset) From patchwork Fri Dec 8 04:41:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 13484765 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ycxn9UoA" Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E747171C for ; Thu, 7 Dec 2023 20:51:53 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6ceba6c4b8dso959035b3a.1 for ; Thu, 07 Dec 2023 20:51:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702011112; x=1702615912; 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=6gIl4moLWQ6MsdJ7wu8JP4u/C4R3/43I+7+xjaDQBeU=; b=Ycxn9UoAHWhjkINaHMn/X2Sykz6vmypGOvqKFdG7q7BUUiopJtVWa3jDwu8SFn9qcX D6ALz40BNHSzVkPZLupWkzT67vW+oRy/0dS/Qt2kZWeRZP9QeJI1t4a8ivllsdphg7hs BTBS6egJN4GKv9pvqhhh+X8FwoQdIEa6DogcDk30mepAknCN6oXGPZtmnke2024X3a/9 1ZE7L3/rmnavmHhwmrQLQLPeiEXGw++1Dy8cKbxxotiGdUPftduaB8sYc2hhj6r37ipU BUpOBgcoBZZhOiIIovvvOny71GeSqBVdF1Kh5jeJt9TTNhNp38v3Hi64xyj3GiyNpGbj bMqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702011112; x=1702615912; 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=6gIl4moLWQ6MsdJ7wu8JP4u/C4R3/43I+7+xjaDQBeU=; b=hXbtOxO88K7HXJJX8ZQ+1Jaj/vxo7rFuptV8rK7HnUYZT4qKkJmUQ8yAh0qK4eOZzL m7Sg3l3fhzRYNgh5NEJl89O6x2rIjLfNH/jdKxKbDTasoxq7k57Me/OiqIMAiS+iGpYK mwaItR7qo+Cai7qzKNH790RshJcCKvK4eAQ6MqSYRSjHxOF/CTi7/vZ2xdtCnFw1KU6z B/vfeM5/R62xnUfVNZVmnjwUcr6TiiKnjGeXYvrJ+nrGHKdVruNPtEoIDE9hABkNGbze 6UpToS+p/j7ukqibqBlYvN+t06zXEGH+JQ4cOO1/qkLQdYaDo7bMaCcEkRqCtaglos7i IkCA== X-Gm-Message-State: AOJu0YxN0peHhENHYADJBGwYJ+PxSjSalAvdA5Gv8G7fp+zxyHmNesS/ DH3SKM0t+gG73OO5l4DNbCavzykLYe2RLa3P X-Google-Smtp-Source: AGHT+IGHl1m7sr/rgzXchheNnbuAyezf7GaLK6OxYd/dCY+Z2HWBjzkDEqjSWOKfkOEKaXmcGDQwHw== X-Received: by 2002:a05:6a00:f8d:b0:6ce:6f21:566c with SMTP id ct13-20020a056a000f8d00b006ce6f21566cmr5090913pfb.7.1702011112036; Thu, 07 Dec 2023 20:51:52 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:c:204:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id f18-20020a056a00229200b006cbae51f335sm657865pfe.144.2023.12.07.20.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 20:51:51 -0800 (PST) From: Luiz Angelo Daros de Luca To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, alsi@bang-olufsen.dk, andrew@lunn.ch, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, arinc.unal@arinc9.com, Luiz Angelo Daros de Luca Subject: [PATCH net-next 3/7] net: dsa: realtek: convert variants into a real driver Date: Fri, 8 Dec 2023 01:41:39 -0300 Message-ID: <20231208045054.27966-4-luizluca@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208045054.27966-1-luizluca@gmail.com> References: <20231208045054.27966-1-luizluca@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 Previously, the interface modules realtek-smi and realtek-mdio were, respectively, a platform and an MDIO driver. Each interface module repeated the same compatible strings for both variants and they referenced symbols from variants. Now each variant module was converted into both a platform and an MDIO driver. It reverses the relationship between interface and variant module, with the variant now using symbols from interface modules. Signed-off-by: Luiz Angelo Daros de Luca --- drivers/net/dsa/realtek/Kconfig | 20 ++++------- drivers/net/dsa/realtek/realtek-mdio.c | 33 ++++-------------- drivers/net/dsa/realtek/realtek-mdio.h | 48 ++++++++++++++++++++++++++ drivers/net/dsa/realtek/realtek-smi.c | 38 ++++---------------- drivers/net/dsa/realtek/realtek-smi.h | 48 ++++++++++++++++++++++++++ drivers/net/dsa/realtek/rtl8365mb.c | 48 +++++++++++++++++++++++++- drivers/net/dsa/realtek/rtl8366rb.c | 48 +++++++++++++++++++++++++- 7 files changed, 210 insertions(+), 73 deletions(-) create mode 100644 drivers/net/dsa/realtek/realtek-mdio.h create mode 100644 drivers/net/dsa/realtek/realtek-smi.h diff --git a/drivers/net/dsa/realtek/Kconfig b/drivers/net/dsa/realtek/Kconfig index 060165a85fb7..9d182fde11b4 100644 --- a/drivers/net/dsa/realtek/Kconfig +++ b/drivers/net/dsa/realtek/Kconfig @@ -16,37 +16,29 @@ menuconfig NET_DSA_REALTEK if NET_DSA_REALTEK config NET_DSA_REALTEK_MDIO - tristate "Realtek MDIO interface driver" + tristate "Realtek MDIO interface support" depends on OF - depends on NET_DSA_REALTEK_RTL8365MB || NET_DSA_REALTEK_RTL8366RB - depends on NET_DSA_REALTEK_RTL8365MB || !NET_DSA_REALTEK_RTL8365MB - depends on NET_DSA_REALTEK_RTL8366RB || !NET_DSA_REALTEK_RTL8366RB help Select to enable support for registering switches configured through MDIO. config NET_DSA_REALTEK_SMI - tristate "Realtek SMI interface driver" + tristate "Realtek SMI interface support" depends on OF - depends on NET_DSA_REALTEK_RTL8365MB || NET_DSA_REALTEK_RTL8366RB - depends on NET_DSA_REALTEK_RTL8365MB || !NET_DSA_REALTEK_RTL8365MB - depends on NET_DSA_REALTEK_RTL8366RB || !NET_DSA_REALTEK_RTL8366RB help Select to enable support for registering switches connected through SMI. config NET_DSA_REALTEK_RTL8365MB - tristate "Realtek RTL8365MB switch subdriver" - imply NET_DSA_REALTEK_SMI - imply NET_DSA_REALTEK_MDIO + tristate "Realtek RTL8365MB switch driver" + depends on NET_DSA_REALTEK_SMI || NET_DSA_REALTEK_MDIO select NET_DSA_TAG_RTL8_4 help Select to enable support for Realtek RTL8365MB-VC and RTL8367S. config NET_DSA_REALTEK_RTL8366RB - tristate "Realtek RTL8366RB switch subdriver" - imply NET_DSA_REALTEK_SMI - imply NET_DSA_REALTEK_MDIO + tristate "Realtek RTL8366RB switch driver" + depends on NET_DSA_REALTEK_SMI || NET_DSA_REALTEK_MDIO select NET_DSA_TAG_RTL4_A help Select to enable support for Realtek RTL8366RB. diff --git a/drivers/net/dsa/realtek/realtek-mdio.c b/drivers/net/dsa/realtek/realtek-mdio.c index 292e6d087e8b..58966d0625c8 100644 --- a/drivers/net/dsa/realtek/realtek-mdio.c +++ b/drivers/net/dsa/realtek/realtek-mdio.c @@ -25,6 +25,7 @@ #include #include "realtek.h" +#include "realtek-mdio.h" /* Read/write via mdiobus */ #define REALTEK_MDIO_CTRL0_REG 31 @@ -140,7 +141,7 @@ static const struct regmap_config realtek_mdio_nolock_regmap_config = { .disable_locking = true, }; -static int realtek_mdio_probe(struct mdio_device *mdiodev) +int realtek_mdio_probe(struct mdio_device *mdiodev) { struct realtek_priv *priv; struct device *dev = &mdiodev->dev; @@ -235,8 +236,9 @@ static int realtek_mdio_probe(struct mdio_device *mdiodev) return 0; } +EXPORT_SYMBOL_GPL(realtek_mdio_probe); -static void realtek_mdio_remove(struct mdio_device *mdiodev) +void realtek_mdio_remove(struct mdio_device *mdiodev) { struct realtek_priv *priv = dev_get_drvdata(&mdiodev->dev); @@ -249,8 +251,9 @@ static void realtek_mdio_remove(struct mdio_device *mdiodev) if (priv->reset) gpiod_set_value(priv->reset, 1); } +EXPORT_SYMBOL_GPL(realtek_mdio_remove); -static void realtek_mdio_shutdown(struct mdio_device *mdiodev) +void realtek_mdio_shutdown(struct mdio_device *mdiodev) { struct realtek_priv *priv = dev_get_drvdata(&mdiodev->dev); @@ -261,29 +264,7 @@ static void realtek_mdio_shutdown(struct mdio_device *mdiodev) dev_set_drvdata(&mdiodev->dev, NULL); } - -static const struct of_device_id realtek_mdio_of_match[] = { -#if IS_ENABLED(CONFIG_NET_DSA_REALTEK_RTL8366RB) - { .compatible = "realtek,rtl8366rb", .data = &rtl8366rb_variant, }, -#endif -#if IS_ENABLED(CONFIG_NET_DSA_REALTEK_RTL8365MB) - { .compatible = "realtek,rtl8365mb", .data = &rtl8365mb_variant, }, -#endif - { /* sentinel */ }, -}; -MODULE_DEVICE_TABLE(of, realtek_mdio_of_match); - -static struct mdio_driver realtek_mdio_driver = { - .mdiodrv.driver = { - .name = "realtek-mdio", - .of_match_table = realtek_mdio_of_match, - }, - .probe = realtek_mdio_probe, - .remove = realtek_mdio_remove, - .shutdown = realtek_mdio_shutdown, -}; - -mdio_module_driver(realtek_mdio_driver); +EXPORT_SYMBOL_GPL(realtek_mdio_shutdown); MODULE_AUTHOR("Luiz Angelo Daros de Luca "); MODULE_DESCRIPTION("Driver for Realtek ethernet switch connected via MDIO interface"); diff --git a/drivers/net/dsa/realtek/realtek-mdio.h b/drivers/net/dsa/realtek/realtek-mdio.h new file mode 100644 index 000000000000..b938a55249c9 --- /dev/null +++ b/drivers/net/dsa/realtek/realtek-mdio.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef _REALTEK_MDIO_H +#define _REALTEK_MDIO_H + +#if IS_ENABLED(CONFIG_NET_DSA_REALTEK_MDIO) + +static inline int realtek_mdio_driver_register(struct mdio_driver *drv) +{ + return mdio_driver_register(drv); +} + +static inline void realtek_mdio_driver_unregister(struct mdio_driver *drv) +{ + mdio_driver_unregister(drv); +} + +int realtek_mdio_probe(struct mdio_device *mdiodev); +void realtek_mdio_remove(struct mdio_device *mdiodev); +void realtek_mdio_shutdown(struct mdio_device *mdiodev); + +#else + +static inline int realtek_mdio_driver_register(struct mdio_driver *drv) +{ + return 0; +} + +static inline void realtek_mdio_driver_unregister(struct mdio_driver *drv) +{ +} + +static inline int realtek_mdio_probe(struct mdio_device *mdiodev) +{ + return -ENOENT; +} + +static inline void realtek_mdio_remove(struct mdio_device *mdiodev) +{ +} + +static inline void realtek_mdio_shutdown(struct mdio_device *mdiodev) +{ +} + +#endif + +#endif diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index ddcae546afbc..55586d158c0e 100644 --- a/drivers/net/dsa/realtek/realtek-smi.c +++ b/drivers/net/dsa/realtek/realtek-smi.c @@ -40,6 +40,7 @@ #include #include "realtek.h" +#include "realtek-smi.h" #define REALTEK_SMI_ACK_RETRY_COUNT 5 @@ -408,7 +409,7 @@ static int realtek_smi_setup_mdio(struct dsa_switch *ds) return ret; } -static int realtek_smi_probe(struct platform_device *pdev) +int realtek_smi_probe(struct platform_device *pdev) { const struct realtek_variant *var; struct device *dev = &pdev->dev; @@ -505,8 +506,9 @@ static int realtek_smi_probe(struct platform_device *pdev) } return 0; } +EXPORT_SYMBOL_GPL(realtek_smi_probe); -static void realtek_smi_remove(struct platform_device *pdev) +void realtek_smi_remove(struct platform_device *pdev) { struct realtek_priv *priv = platform_get_drvdata(pdev); @@ -519,8 +521,9 @@ static void realtek_smi_remove(struct platform_device *pdev) if (priv->reset) gpiod_set_value(priv->reset, 1); } +EXPORT_SYMBOL_GPL(realtek_smi_remove); -static void realtek_smi_shutdown(struct platform_device *pdev) +void realtek_smi_shutdown(struct platform_device *pdev) { struct realtek_priv *priv = platform_get_drvdata(pdev); @@ -531,34 +534,7 @@ static void realtek_smi_shutdown(struct platform_device *pdev) platform_set_drvdata(pdev, NULL); } - -static const struct of_device_id realtek_smi_of_match[] = { -#if IS_ENABLED(CONFIG_NET_DSA_REALTEK_RTL8366RB) - { - .compatible = "realtek,rtl8366rb", - .data = &rtl8366rb_variant, - }, -#endif -#if IS_ENABLED(CONFIG_NET_DSA_REALTEK_RTL8365MB) - { - .compatible = "realtek,rtl8365mb", - .data = &rtl8365mb_variant, - }, -#endif - { /* sentinel */ }, -}; -MODULE_DEVICE_TABLE(of, realtek_smi_of_match); - -static struct platform_driver realtek_smi_driver = { - .driver = { - .name = "realtek-smi", - .of_match_table = realtek_smi_of_match, - }, - .probe = realtek_smi_probe, - .remove_new = realtek_smi_remove, - .shutdown = realtek_smi_shutdown, -}; -module_platform_driver(realtek_smi_driver); +EXPORT_SYMBOL_GPL(realtek_smi_shutdown); MODULE_AUTHOR("Linus Walleij "); MODULE_DESCRIPTION("Driver for Realtek ethernet switch connected via SMI interface"); diff --git a/drivers/net/dsa/realtek/realtek-smi.h b/drivers/net/dsa/realtek/realtek-smi.h new file mode 100644 index 000000000000..76fb58df728b --- /dev/null +++ b/drivers/net/dsa/realtek/realtek-smi.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef _REALTEK_SMI_H +#define _REALTEK_SMI_H + +#if IS_ENABLED(CONFIG_NET_DSA_REALTEK_SMI) + +static inline int realtek_smi_driver_register(struct platform_driver *drv) +{ + return platform_driver_register(drv); +} + +static inline void realtek_smi_driver_unregister(struct platform_driver *drv) +{ + platform_driver_unregister(drv); +} + +int realtek_smi_probe(struct platform_device *pdev); +void realtek_smi_remove(struct platform_device *pdev); +void realtek_smi_shutdown(struct platform_device *pdev); + +#else + +static inline int realtek_smi_driver_register(struct platform_driver *drv) +{ + return 0; +} + +static inline void realtek_smi_driver_unregister(struct platform_driver *drv) +{ +} + +static inline int realtek_smi_probe(struct platform_device *pdev) +{ + return -ENOENT; +} + +static inline void realtek_smi_remove(struct platform_device *pdev) +{ +} + +static inline void realtek_smi_shutdown(struct platform_device *pdev) +{ +} + +#endif + +#endif diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/rtl8365mb.c index 0875e4fc9f57..526bf98cef1d 100644 --- a/drivers/net/dsa/realtek/rtl8365mb.c +++ b/drivers/net/dsa/realtek/rtl8365mb.c @@ -101,6 +101,8 @@ #include #include "realtek.h" +#include "realtek-smi.h" +#include "realtek-mdio.h" /* Family-specific data and limits */ #define RTL8365MB_PHYADDRMAX 7 @@ -2172,7 +2174,51 @@ const struct realtek_variant rtl8365mb_variant = { .cmd_write = 0xb8, .chip_data_sz = sizeof(struct rtl8365mb), }; -EXPORT_SYMBOL_GPL(rtl8365mb_variant); + +static const struct of_device_id rtl8365mb_of_match[] = { + { .compatible = "realtek,rtl8365mb", .data = &rtl8365mb_variant, }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, rtl8365mb_of_match); + +static struct platform_driver rtl8365mb_smi_driver = { + .driver = { + .name = "rtl8365mb-smi", + .of_match_table = rtl8365mb_of_match, + }, + .probe = realtek_smi_probe, + .remove_new = realtek_smi_remove, + .shutdown = realtek_smi_shutdown, +}; + +static struct mdio_driver rtl8365mb_mdio_driver = { + .mdiodrv.driver = { + .name = "rtl8365mb-mdio", + .of_match_table = rtl8365mb_of_match, + }, + .probe = realtek_mdio_probe, + .remove = realtek_mdio_remove, + .shutdown = realtek_mdio_shutdown, +}; + +static int rtl8365mb_init(void) +{ + int ret; + + ret = realtek_mdio_driver_register(&rtl8365mb_mdio_driver); + if (ret) + return ret; + + return platform_driver_register(&rtl8365mb_smi_driver); +} +module_init(rtl8365mb_init); + +static void __exit rtl8365mb_exit(void) +{ + realtek_mdio_driver_unregister(&rtl8365mb_mdio_driver); + platform_driver_unregister(&rtl8365mb_smi_driver); +} +module_exit(rtl8365mb_exit); MODULE_AUTHOR("Alvin Šipraga "); MODULE_DESCRIPTION("Driver for RTL8365MB-VC ethernet switch"); diff --git a/drivers/net/dsa/realtek/rtl8366rb.c b/drivers/net/dsa/realtek/rtl8366rb.c index b39b719a5b8f..09c17de19457 100644 --- a/drivers/net/dsa/realtek/rtl8366rb.c +++ b/drivers/net/dsa/realtek/rtl8366rb.c @@ -22,6 +22,8 @@ #include #include "realtek.h" +#include "realtek-smi.h" +#include "realtek-mdio.h" #define RTL8366RB_PORT_NUM_CPU 5 #define RTL8366RB_NUM_PORTS 6 @@ -1920,7 +1922,51 @@ const struct realtek_variant rtl8366rb_variant = { .cmd_write = 0xa8, .chip_data_sz = sizeof(struct rtl8366rb), }; -EXPORT_SYMBOL_GPL(rtl8366rb_variant); + +static const struct of_device_id rtl8366rb_of_match[] = { + { .compatible = "realtek,rtl8366rb", .data = &rtl8366rb_variant, }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, rtl8366rb_of_match); + +static struct platform_driver rtl8366rb_smi_driver = { + .driver = { + .name = "rtl8366rb-smi", + .of_match_table = rtl8366rb_of_match, + }, + .probe = realtek_smi_probe, + .remove_new = realtek_smi_remove, + .shutdown = realtek_smi_shutdown, +}; + +static struct mdio_driver rtl8366rb_mdio_driver = { + .mdiodrv.driver = { + .name = "rtl8366rb-mdio", + .of_match_table = rtl8366rb_of_match, + }, + .probe = realtek_mdio_probe, + .remove = realtek_mdio_remove, + .shutdown = realtek_mdio_shutdown, +}; + +static int rtl8366rb_init(void) +{ + int ret; + + ret = realtek_mdio_driver_register(&rtl8366rb_mdio_driver); + if (ret) + return ret; + + return realtek_smi_driver_register(&rtl8366rb_smi_driver); +} +module_init(rtl8366rb_init); + +static void __exit rtl8366rb_exit(void) +{ + realtek_mdio_driver_unregister(&rtl8366rb_mdio_driver); + realtek_smi_driver_unregister(&rtl8366rb_smi_driver); +} +module_exit(rtl8366rb_exit); MODULE_AUTHOR("Linus Walleij "); MODULE_DESCRIPTION("Driver for RTL8366RB ethernet switch"); From patchwork Fri Dec 8 04:41:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 13484766 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Yl2fNUv5" Received: from mail-oo1-xc2f.google.com (mail-oo1-xc2f.google.com [IPv6:2607:f8b0:4864:20::c2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03F87171C for ; Thu, 7 Dec 2023 20:51:57 -0800 (PST) Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-58d3c5126e9so844366eaf.1 for ; Thu, 07 Dec 2023 20:51:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702011116; x=1702615916; 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=IU2glogs/8fAJjcqO9GZdZpMnZL7AlhURC5uUcxZqUA=; b=Yl2fNUv5T/1Bh6tobMVwbfNMJ+1lKGKnDJm8hzai3hWAotx1Lh+sTZpzQgIyAcnm/s UhYoL1jEu1DJCvVteg9dI67DgXgYoJtiXgxQkFI9V4tg87vQlyYJCTOU+xdGl5A/fLyV VGVorx9tfS9kbuUKB1ccMjV8YC9ZfrmT3xZDS125Ypuj2/UA5xCR6BGdZRPg1xNb8r3r trGL1Zdjmb/6o/HVtLbQz9kg5ZcS+0UiQLL+b2pVdQAaZ9Fqc+xkou1THZpeY7iY4c4E yMutDbgeMZ3ok6dT1FwQHlNeKkHE3ya5B6xCHTzNVqXzqQlMChKoqn4pkOz9egXD3cxn x9xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702011116; x=1702615916; 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=IU2glogs/8fAJjcqO9GZdZpMnZL7AlhURC5uUcxZqUA=; b=JmsBSvkJARntXgpgQxAWxjzBRUpnN59rXklUlrpB18fvoXaZotRy7zqaTz/PCPfbzC UtZgpFb2Br5PyH8PxDT/0rQ9dIPEplhRQYx9UXAEQytFuifnLVdDUYdgSB4G3DlHP1d7 xFGdg+MLZ25SpiGG6C8LPbOQ7EDXrFU/MJYkjXKkLtJ6zFG6+XrMK3b/EJl2Pj42yYLO CZSCwDYK4hcHYXULLs9ITjJEeSflx4nuRIvAn9rWcZ4JcEyON6y6q2dQCPCA92loU8l6 ffZ/tvP+wcLMZ7LfdXHzfZb6jEOGCcx+ZIkiN1mUD3x7kRpbmT8+5tjKcarhb4TMYcrC +Jmw== X-Gm-Message-State: AOJu0YwBjGkyMlCQoU8N90cmI8DvbFKec9kO14/05agVpjLaWheMjL2R BBks9A2vnIjDgrTgV97id3ncKCOPutBO/NkG X-Google-Smtp-Source: AGHT+IEJIWTrBaGLfCUSt9obv19c6zf3OxGbvEWk69er2yzteAUqPK/+a8ZsikvUktc5yt1VCI//5Q== X-Received: by 2002:a05:6358:720a:b0:16e:5939:be with SMTP id h10-20020a056358720a00b0016e593900bemr4827336rwa.26.1702011115849; Thu, 07 Dec 2023 20:51:55 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:c:204:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id f18-20020a056a00229200b006cbae51f335sm657865pfe.144.2023.12.07.20.51.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 20:51:55 -0800 (PST) From: Luiz Angelo Daros de Luca To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, alsi@bang-olufsen.dk, andrew@lunn.ch, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, arinc.unal@arinc9.com, Luiz Angelo Daros de Luca Subject: [PATCH net-next 4/7] net: dsa: realtek: create realtek-common Date: Fri, 8 Dec 2023 01:41:40 -0300 Message-ID: <20231208045054.27966-5-luizluca@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208045054.27966-1-luizluca@gmail.com> References: <20231208045054.27966-1-luizluca@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 Some code can be shared between both interface modules (MDIO and SMI) and among variants. Currently, these interface functions are shared: - realtek_common_lock - realtek_common_unlock - realtek_common_probe - realtek_common_remove The reset during probe was moved to the last moment before a variant detects the switch. This way, we avoid a reset if anything else fails. Signed-off-by: Luiz Angelo Daros de Luca Reviewed-by: Linus Walleij --- drivers/net/dsa/realtek/Makefile | 1 + drivers/net/dsa/realtek/realtek-common.c | 136 +++++++++++++++++++++++ drivers/net/dsa/realtek/realtek-common.h | 16 +++ drivers/net/dsa/realtek/realtek-mdio.c | 121 ++------------------ drivers/net/dsa/realtek/realtek-smi.c | 124 +++------------------ drivers/net/dsa/realtek/realtek.h | 6 +- drivers/net/dsa/realtek/rtl8365mb.c | 9 +- drivers/net/dsa/realtek/rtl8366rb.c | 9 +- 8 files changed, 194 insertions(+), 228 deletions(-) create mode 100644 drivers/net/dsa/realtek/realtek-common.c create mode 100644 drivers/net/dsa/realtek/realtek-common.h diff --git a/drivers/net/dsa/realtek/Makefile b/drivers/net/dsa/realtek/Makefile index 0aab57252a7c..5e0c1ef200a3 100644 --- a/drivers/net/dsa/realtek/Makefile +++ b/drivers/net/dsa/realtek/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_NET_DSA_REALTEK) += realtek-common.o obj-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o obj-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o obj-$(CONFIG_NET_DSA_REALTEK_RTL8366RB) += rtl8366.o diff --git a/drivers/net/dsa/realtek/realtek-common.c b/drivers/net/dsa/realtek/realtek-common.c new file mode 100644 index 000000000000..75b6aa071990 --- /dev/null +++ b/drivers/net/dsa/realtek/realtek-common.c @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include + +#include "realtek.h" +#include "realtek-common.h" + +void realtek_common_lock(void *ctx) +{ + struct realtek_priv *priv = ctx; + + mutex_lock(&priv->map_lock); +} +EXPORT_SYMBOL_GPL(realtek_common_lock); + +void realtek_common_unlock(void *ctx) +{ + struct realtek_priv *priv = ctx; + + mutex_unlock(&priv->map_lock); +} +EXPORT_SYMBOL_GPL(realtek_common_unlock); + +struct realtek_priv * +realtek_common_probe_pre(struct device *dev, struct regmap_config rc, + struct regmap_config rc_nolock) +{ + const struct realtek_variant *var; + struct realtek_priv *priv; + struct device_node *np; + int ret; + + var = of_device_get_match_data(dev); + if (!var) + return ERR_PTR(-EINVAL); + + priv = devm_kzalloc(dev, size_add(sizeof(*priv), var->chip_data_sz), + GFP_KERNEL); + if (!priv) + return ERR_PTR(-ENOMEM); + + mutex_init(&priv->map_lock); + + rc.lock_arg = priv; + priv->map = devm_regmap_init(dev, NULL, priv, &rc); + if (IS_ERR(priv->map)) { + ret = PTR_ERR(priv->map); + dev_err(dev, "regmap init failed: %d\n", ret); + return ERR_PTR(ret); + } + + priv->map_nolock = devm_regmap_init(dev, NULL, priv, &rc_nolock); + if (IS_ERR(priv->map_nolock)) { + ret = PTR_ERR(priv->map_nolock); + dev_err(dev, "regmap init failed: %d\n", ret); + return ERR_PTR(ret); + } + + /* Link forward and backward */ + priv->dev = dev; + priv->variant = var; + priv->ops = var->ops; + priv->chip_data = (void *)priv + sizeof(*priv); + + dev_set_drvdata(dev, priv); + spin_lock_init(&priv->lock); + + np = dev->of_node; + + priv->leds_disabled = of_property_read_bool(np, "realtek,disable-leds"); + + /* TODO: if power is software controlled, set up any regulators here */ + + priv->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); + if (IS_ERR(priv->reset)) { + dev_err(dev, "failed to get RESET GPIO\n"); + return ERR_CAST(priv->reset); + } + if (priv->reset) { + gpiod_set_value(priv->reset, 1); + dev_dbg(dev, "asserted RESET\n"); + msleep(REALTEK_HW_STOP_DELAY); + gpiod_set_value(priv->reset, 0); + msleep(REALTEK_HW_START_DELAY); + dev_dbg(dev, "deasserted RESET\n"); + } + + return priv; +} +EXPORT_SYMBOL(realtek_common_probe_pre); + +int realtek_common_probe_post(struct realtek_priv *priv) +{ + int ret; + + ret = priv->ops->detect(priv); + if (ret) { + dev_err(priv->dev, "unable to detect switch\n"); + return ret; + } + + priv->ds = devm_kzalloc(priv->dev, sizeof(*priv->ds), GFP_KERNEL); + if (!priv->ds) + return -ENOMEM; + + priv->ds->priv = priv; + priv->ds->dev = priv->dev; + priv->ds->ops = priv->ds_ops; + priv->ds->num_ports = priv->num_ports; + + ret = dsa_register_switch(priv->ds); + if (ret) { + dev_err_probe(priv->dev, ret, "unable to register switch\n"); + return ret; + } + + return 0; +} +EXPORT_SYMBOL(realtek_common_probe_post); + +void realtek_common_remove(struct realtek_priv *priv) +{ + if (!priv) + return; + + dsa_unregister_switch(priv->ds); + + /* leave the device reset asserted */ + if (priv->reset) + gpiod_set_value(priv->reset, 1); +} +EXPORT_SYMBOL(realtek_common_remove); + +MODULE_AUTHOR("Luiz Angelo Daros de Luca "); +MODULE_DESCRIPTION("Realtek DSA switches common module"); +MODULE_LICENSE("GPL"); diff --git a/drivers/net/dsa/realtek/realtek-common.h b/drivers/net/dsa/realtek/realtek-common.h new file mode 100644 index 000000000000..405bd0d85d2b --- /dev/null +++ b/drivers/net/dsa/realtek/realtek-common.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef _REALTEK_INTERFACE_H +#define _REALTEK_INTERFACE_H + +#include + +void realtek_common_lock(void *ctx); +void realtek_common_unlock(void *ctx); +struct realtek_priv * +realtek_common_probe_pre(struct device *dev, struct regmap_config rc, + struct regmap_config rc_nolock); +int realtek_common_probe_post(struct realtek_priv *priv); +void realtek_common_remove(struct realtek_priv *priv); + +#endif diff --git a/drivers/net/dsa/realtek/realtek-mdio.c b/drivers/net/dsa/realtek/realtek-mdio.c index 58966d0625c8..4c9a744b72f8 100644 --- a/drivers/net/dsa/realtek/realtek-mdio.c +++ b/drivers/net/dsa/realtek/realtek-mdio.c @@ -26,6 +26,7 @@ #include "realtek.h" #include "realtek-mdio.h" +#include "realtek-common.h" /* Read/write via mdiobus */ #define REALTEK_MDIO_CTRL0_REG 31 @@ -100,20 +101,6 @@ static int realtek_mdio_read(void *ctx, u32 reg, u32 *val) return ret; } -static void realtek_mdio_lock(void *ctx) -{ - struct realtek_priv *priv = ctx; - - mutex_lock(&priv->map_lock); -} - -static void realtek_mdio_unlock(void *ctx) -{ - struct realtek_priv *priv = ctx; - - mutex_unlock(&priv->map_lock); -} - static const struct regmap_config realtek_mdio_regmap_config = { .reg_bits = 10, /* A4..A0 R4..R0 */ .val_bits = 16, @@ -124,8 +111,8 @@ static const struct regmap_config realtek_mdio_regmap_config = { .reg_read = realtek_mdio_read, .reg_write = realtek_mdio_write, .cache_type = REGCACHE_NONE, - .lock = realtek_mdio_lock, - .unlock = realtek_mdio_unlock, + .lock = realtek_common_lock, + .unlock = realtek_common_unlock, }; static const struct regmap_config realtek_mdio_nolock_regmap_config = { @@ -143,98 +130,21 @@ static const struct regmap_config realtek_mdio_nolock_regmap_config = { int realtek_mdio_probe(struct mdio_device *mdiodev) { - struct realtek_priv *priv; struct device *dev = &mdiodev->dev; - const struct realtek_variant *var; - struct regmap_config rc; - struct device_node *np; - int ret; - - var = of_device_get_match_data(dev); - if (!var) - return -EINVAL; - - priv = devm_kzalloc(&mdiodev->dev, - size_add(sizeof(*priv), var->chip_data_sz), - GFP_KERNEL); - if (!priv) - return -ENOMEM; - - mutex_init(&priv->map_lock); - - rc = realtek_mdio_regmap_config; - rc.lock_arg = priv; - priv->map = devm_regmap_init(dev, NULL, priv, &rc); - if (IS_ERR(priv->map)) { - ret = PTR_ERR(priv->map); - dev_err(dev, "regmap init failed: %d\n", ret); - return ret; - } + struct realtek_priv *priv; - rc = realtek_mdio_nolock_regmap_config; - priv->map_nolock = devm_regmap_init(dev, NULL, priv, &rc); - if (IS_ERR(priv->map_nolock)) { - ret = PTR_ERR(priv->map_nolock); - dev_err(dev, "regmap init failed: %d\n", ret); - return ret; - } + priv = realtek_common_probe_pre(dev, realtek_mdio_regmap_config, + realtek_mdio_nolock_regmap_config); + if (IS_ERR(priv)) + return PTR_ERR(priv); - priv->mdio_addr = mdiodev->addr; priv->bus = mdiodev->bus; - priv->dev = &mdiodev->dev; - priv->chip_data = (void *)priv + sizeof(*priv); - - priv->clk_delay = var->clk_delay; - priv->cmd_read = var->cmd_read; - priv->cmd_write = var->cmd_write; - priv->ops = var->ops; - + priv->mdio_addr = mdiodev->addr; priv->write_reg_noack = realtek_mdio_write; + priv->ds_ops = priv->variant->ds_ops_mdio; - np = dev->of_node; - - dev_set_drvdata(dev, priv); - - /* TODO: if power is software controlled, set up any regulators here */ - priv->leds_disabled = of_property_read_bool(np, "realtek,disable-leds"); - - priv->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); - if (IS_ERR(priv->reset)) { - dev_err(dev, "failed to get RESET GPIO\n"); - return PTR_ERR(priv->reset); - } - - if (priv->reset) { - gpiod_set_value(priv->reset, 1); - dev_dbg(dev, "asserted RESET\n"); - msleep(REALTEK_HW_STOP_DELAY); - gpiod_set_value(priv->reset, 0); - msleep(REALTEK_HW_START_DELAY); - dev_dbg(dev, "deasserted RESET\n"); - } - - ret = priv->ops->detect(priv); - if (ret) { - dev_err(dev, "unable to detect switch\n"); - return ret; - } - - priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL); - if (!priv->ds) - return -ENOMEM; - - priv->ds->dev = dev; - priv->ds->num_ports = priv->num_ports; - priv->ds->priv = priv; - priv->ds->ops = var->ds_ops_mdio; - - ret = dsa_register_switch(priv->ds); - if (ret) { - dev_err(priv->dev, "unable to register switch ret = %d\n", ret); - return ret; - } + return realtek_common_probe_post(priv); - return 0; } EXPORT_SYMBOL_GPL(realtek_mdio_probe); @@ -242,14 +152,7 @@ void realtek_mdio_remove(struct mdio_device *mdiodev) { struct realtek_priv *priv = dev_get_drvdata(&mdiodev->dev); - if (!priv) - return; - - dsa_unregister_switch(priv->ds); - - /* leave the device reset asserted */ - if (priv->reset) - gpiod_set_value(priv->reset, 1); + realtek_common_remove(priv); } EXPORT_SYMBOL_GPL(realtek_mdio_remove); diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index 55586d158c0e..246024eec3bd 100644 --- a/drivers/net/dsa/realtek/realtek-smi.c +++ b/drivers/net/dsa/realtek/realtek-smi.c @@ -41,12 +41,13 @@ #include "realtek.h" #include "realtek-smi.h" +#include "realtek-common.h" #define REALTEK_SMI_ACK_RETRY_COUNT 5 static inline void realtek_smi_clk_delay(struct realtek_priv *priv) { - ndelay(priv->clk_delay); + ndelay(priv->variant->clk_delay); } static void realtek_smi_start(struct realtek_priv *priv) @@ -209,7 +210,7 @@ static int realtek_smi_read_reg(struct realtek_priv *priv, u32 addr, u32 *data) realtek_smi_start(priv); /* Send READ command */ - ret = realtek_smi_write_byte(priv, priv->cmd_read); + ret = realtek_smi_write_byte(priv, priv->variant->cmd_read); if (ret) goto out; @@ -250,7 +251,7 @@ static int realtek_smi_write_reg(struct realtek_priv *priv, realtek_smi_start(priv); /* Send WRITE command */ - ret = realtek_smi_write_byte(priv, priv->cmd_write); + ret = realtek_smi_write_byte(priv, priv->variant->cmd_write); if (ret) goto out; @@ -311,20 +312,6 @@ static int realtek_smi_read(void *ctx, u32 reg, u32 *val) return realtek_smi_read_reg(priv, reg, val); } -static void realtek_smi_lock(void *ctx) -{ - struct realtek_priv *priv = ctx; - - mutex_lock(&priv->map_lock); -} - -static void realtek_smi_unlock(void *ctx) -{ - struct realtek_priv *priv = ctx; - - mutex_unlock(&priv->map_lock); -} - static const struct regmap_config realtek_smi_regmap_config = { .reg_bits = 10, /* A4..A0 R4..R0 */ .val_bits = 16, @@ -335,8 +322,8 @@ static const struct regmap_config realtek_smi_regmap_config = { .reg_read = realtek_smi_read, .reg_write = realtek_smi_write, .cache_type = REGCACHE_NONE, - .lock = realtek_smi_lock, - .unlock = realtek_smi_unlock, + .lock = realtek_common_lock, + .unlock = realtek_common_unlock, }; static const struct regmap_config realtek_smi_nolock_regmap_config = { @@ -411,100 +398,28 @@ static int realtek_smi_setup_mdio(struct dsa_switch *ds) int realtek_smi_probe(struct platform_device *pdev) { - const struct realtek_variant *var; struct device *dev = &pdev->dev; struct realtek_priv *priv; - struct regmap_config rc; - struct device_node *np; - int ret; - - var = of_device_get_match_data(dev); - np = dev->of_node; - - priv = devm_kzalloc(dev, sizeof(*priv) + var->chip_data_sz, GFP_KERNEL); - if (!priv) - return -ENOMEM; - priv->chip_data = (void *)priv + sizeof(*priv); - - mutex_init(&priv->map_lock); - - rc = realtek_smi_regmap_config; - rc.lock_arg = priv; - priv->map = devm_regmap_init(dev, NULL, priv, &rc); - if (IS_ERR(priv->map)) { - ret = PTR_ERR(priv->map); - dev_err(dev, "regmap init failed: %d\n", ret); - return ret; - } - - rc = realtek_smi_nolock_regmap_config; - priv->map_nolock = devm_regmap_init(dev, NULL, priv, &rc); - if (IS_ERR(priv->map_nolock)) { - ret = PTR_ERR(priv->map_nolock); - dev_err(dev, "regmap init failed: %d\n", ret); - return ret; - } - - /* Link forward and backward */ - priv->dev = dev; - priv->clk_delay = var->clk_delay; - priv->cmd_read = var->cmd_read; - priv->cmd_write = var->cmd_write; - priv->ops = var->ops; - - priv->setup_interface = realtek_smi_setup_mdio; - priv->write_reg_noack = realtek_smi_write_reg_noack; - - dev_set_drvdata(dev, priv); - spin_lock_init(&priv->lock); - /* TODO: if power is software controlled, set up any regulators here */ - - priv->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); - if (IS_ERR(priv->reset)) { - dev_err(dev, "failed to get RESET GPIO\n"); - return PTR_ERR(priv->reset); - } - if (priv->reset) { - gpiod_set_value(priv->reset, 1); - dev_dbg(dev, "asserted RESET\n"); - msleep(REALTEK_HW_STOP_DELAY); - gpiod_set_value(priv->reset, 0); - msleep(REALTEK_HW_START_DELAY); - dev_dbg(dev, "deasserted RESET\n"); - } + priv = realtek_common_probe_pre(dev, realtek_smi_regmap_config, + realtek_smi_nolock_regmap_config); + if (IS_ERR(priv)) + return PTR_ERR(priv); /* Fetch MDIO pins */ priv->mdc = devm_gpiod_get_optional(dev, "mdc", GPIOD_OUT_LOW); if (IS_ERR(priv->mdc)) return PTR_ERR(priv->mdc); + priv->mdio = devm_gpiod_get_optional(dev, "mdio", GPIOD_OUT_LOW); if (IS_ERR(priv->mdio)) return PTR_ERR(priv->mdio); - priv->leds_disabled = of_property_read_bool(np, "realtek,disable-leds"); - - ret = priv->ops->detect(priv); - if (ret) { - dev_err(dev, "unable to detect switch\n"); - return ret; - } - - priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL); - if (!priv->ds) - return -ENOMEM; - - priv->ds->dev = dev; - priv->ds->num_ports = priv->num_ports; - priv->ds->priv = priv; + priv->write_reg_noack = realtek_smi_write_reg_noack; + priv->setup_interface = realtek_smi_setup_mdio; + priv->ds_ops = priv->variant->ds_ops_smi; - priv->ds->ops = var->ds_ops_smi; - ret = dsa_register_switch(priv->ds); - if (ret) { - dev_err_probe(dev, ret, "unable to register switch\n"); - return ret; - } - return 0; + return realtek_common_probe_post(priv); } EXPORT_SYMBOL_GPL(realtek_smi_probe); @@ -512,14 +427,7 @@ void realtek_smi_remove(struct platform_device *pdev) { struct realtek_priv *priv = platform_get_drvdata(pdev); - if (!priv) - return; - - dsa_unregister_switch(priv->ds); - - /* leave the device reset asserted */ - if (priv->reset) - gpiod_set_value(priv->reset, 1); + realtek_common_remove(priv); } EXPORT_SYMBOL_GPL(realtek_smi_remove); diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h index e9ee778665b2..fbd0616c1df3 100644 --- a/drivers/net/dsa/realtek/realtek.h +++ b/drivers/net/dsa/realtek/realtek.h @@ -58,11 +58,9 @@ struct realtek_priv { struct mii_bus *bus; int mdio_addr; - unsigned int clk_delay; - u8 cmd_read; - u8 cmd_write; spinlock_t lock; /* Locks around command writes */ struct dsa_switch *ds; + const struct dsa_switch_ops *ds_ops; struct irq_domain *irqdomain; bool leds_disabled; @@ -79,6 +77,8 @@ struct realtek_priv { int vlan_enabled; int vlan4k_enabled; + const struct realtek_variant *variant; + char buf[4096]; void *chip_data; /* Per-chip extra variant data */ }; diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/rtl8365mb.c index 526bf98cef1d..ac848b965f84 100644 --- a/drivers/net/dsa/realtek/rtl8365mb.c +++ b/drivers/net/dsa/realtek/rtl8365mb.c @@ -103,6 +103,7 @@ #include "realtek.h" #include "realtek-smi.h" #include "realtek-mdio.h" +#include "realtek-common.h" /* Family-specific data and limits */ #define RTL8365MB_PHYADDRMAX 7 @@ -691,7 +692,7 @@ static int rtl8365mb_phy_ocp_read(struct realtek_priv *priv, int phy, u32 val; int ret; - mutex_lock(&priv->map_lock); + realtek_common_lock(priv); ret = rtl8365mb_phy_poll_busy(priv); if (ret) @@ -724,7 +725,7 @@ static int rtl8365mb_phy_ocp_read(struct realtek_priv *priv, int phy, *data = val & 0xFFFF; out: - mutex_unlock(&priv->map_lock); + realtek_common_unlock(priv); return ret; } @@ -735,7 +736,7 @@ static int rtl8365mb_phy_ocp_write(struct realtek_priv *priv, int phy, u32 val; int ret; - mutex_lock(&priv->map_lock); + realtek_common_lock(priv); ret = rtl8365mb_phy_poll_busy(priv); if (ret) @@ -766,7 +767,7 @@ static int rtl8365mb_phy_ocp_write(struct realtek_priv *priv, int phy, goto out; out: - mutex_unlock(&priv->map_lock); + realtek_common_unlock(priv); return 0; } diff --git a/drivers/net/dsa/realtek/rtl8366rb.c b/drivers/net/dsa/realtek/rtl8366rb.c index 09c17de19457..1cc4de3cf54f 100644 --- a/drivers/net/dsa/realtek/rtl8366rb.c +++ b/drivers/net/dsa/realtek/rtl8366rb.c @@ -24,6 +24,7 @@ #include "realtek.h" #include "realtek-smi.h" #include "realtek-mdio.h" +#include "realtek-common.h" #define RTL8366RB_PORT_NUM_CPU 5 #define RTL8366RB_NUM_PORTS 6 @@ -1707,7 +1708,7 @@ static int rtl8366rb_phy_read(struct realtek_priv *priv, int phy, int regnum) if (phy > RTL8366RB_PHY_NO_MAX) return -EINVAL; - mutex_lock(&priv->map_lock); + realtek_common_lock(priv); ret = regmap_write(priv->map_nolock, RTL8366RB_PHY_ACCESS_CTRL_REG, RTL8366RB_PHY_CTRL_READ); @@ -1735,7 +1736,7 @@ static int rtl8366rb_phy_read(struct realtek_priv *priv, int phy, int regnum) phy, regnum, reg, val); out: - mutex_unlock(&priv->map_lock); + realtek_common_unlock(priv); return ret; } @@ -1749,7 +1750,7 @@ static int rtl8366rb_phy_write(struct realtek_priv *priv, int phy, int regnum, if (phy > RTL8366RB_PHY_NO_MAX) return -EINVAL; - mutex_lock(&priv->map_lock); + realtek_common_lock(priv); ret = regmap_write(priv->map_nolock, RTL8366RB_PHY_ACCESS_CTRL_REG, RTL8366RB_PHY_CTRL_WRITE); @@ -1766,7 +1767,7 @@ static int rtl8366rb_phy_write(struct realtek_priv *priv, int phy, int regnum, goto out; out: - mutex_unlock(&priv->map_lock); + realtek_common_unlock(priv); return ret; } From patchwork Fri Dec 8 04:41:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 13484767 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NVRINDQ9" Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1946F1720 for ; Thu, 7 Dec 2023 20:52:01 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6ceb93fb381so942089b3a.0 for ; Thu, 07 Dec 2023 20:52:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702011119; x=1702615919; 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=kpH6jZQ9zwuKUS/xyDafAoPM/JI3TSc6VKYkKHHLkJc=; b=NVRINDQ99SbELl2yxIUHUrIY/EphkpLID8EVVN1Y4qw+A1QD6Bzsp7cKFmgyYffgI5 0+fJDhVvlunElwKNtB493PCpnR2jofcgmhwuBvNppsBh3ioSR2KhGR08+E2pPyDt431+ ZGdbrGkhCPBuyrN3c3pKgSlEWrctK2fNHp2rJfRuT9DOjoX9/qUJt+yh+Ft9+2KbbHlF 70rDwL6jeNBoyhf5pJW7eApiBce1KrEk4+gKvMrUtiAPY61H2NLn3KbZq0DhDp97uS3S P5csgjZeLfEewhSODmDQOKRMRfvRW6WbP3FJFeIJ5WURhQ3EIMPrwdC1qtt15jSJ5PRT WGpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702011119; x=1702615919; 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=kpH6jZQ9zwuKUS/xyDafAoPM/JI3TSc6VKYkKHHLkJc=; b=WekmV+AmYa5tMbAAXM5h3Py7rP+0QH7MjmO+DO0gs10s7Qyuj2LfXj91H8mB/IHlPK LpaeWHAVFofPWID3VuwNPbg4ABqOLpVII8AehUEkxMlzf1ci+K9VRlwgYmKoj9fh0MEK nrZH9ROPnTQcxEcQrm6pP75p0PVdNBK0gtiQkwMNysVU3kri83IhAtzXhjwiJP73i5cJ dXYOLwk75oxhPGqEarQo6wSaF2BrE6x0JoIiDvJYQAfKkjmt6jyuJRw+waEuj8FgDuOr sTltGCucS1CEOKjvAGDtpoV5vYHIQGfOLU1Qk3xC8bS+selG9JoL74x6zkqLPGvusGhn Esrg== X-Gm-Message-State: AOJu0YwvVtmBnZnF0uaom8pHLTccOUFOriLF5Qr0U8EAe0331fuwLGAW yRlTvIOlEebcC+BkgAxDgsud6tBWUyE+vOMS X-Google-Smtp-Source: AGHT+IEgA7gOazd6nwVESsBj+HX5jRK1MDRamGL65Eqm+w5rlMthhXQYsw6skLnUnpViYZNgIs2sjw== X-Received: by 2002:a05:6a21:a5a2:b0:18b:826d:1e89 with SMTP id gd34-20020a056a21a5a200b0018b826d1e89mr444470pzc.12.1702011119655; Thu, 07 Dec 2023 20:51:59 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:c:204:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id f18-20020a056a00229200b006cbae51f335sm657865pfe.144.2023.12.07.20.51.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 20:51:59 -0800 (PST) From: Luiz Angelo Daros de Luca To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, alsi@bang-olufsen.dk, andrew@lunn.ch, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, arinc.unal@arinc9.com, Luiz Angelo Daros de Luca Subject: [PATCH net-next 5/7] net: dsa: realtek: merge interface modules into common Date: Fri, 8 Dec 2023 01:41:41 -0300 Message-ID: <20231208045054.27966-6-luizluca@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208045054.27966-1-luizluca@gmail.com> References: <20231208045054.27966-1-luizluca@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 As both realtek-common and realtek-{smi,mdio} must always be loaded together, we can save some resources merging them into a single module. Signed-off-by: Luiz Angelo Daros de Luca --- drivers/net/dsa/realtek/Kconfig | 4 ++-- drivers/net/dsa/realtek/Makefile | 8 +++++--- drivers/net/dsa/realtek/realtek-common.c | 1 + drivers/net/dsa/realtek/realtek-mdio.c | 4 ---- drivers/net/dsa/realtek/realtek-smi.c | 4 ---- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/net/dsa/realtek/Kconfig b/drivers/net/dsa/realtek/Kconfig index 9d182fde11b4..6989972eebc3 100644 --- a/drivers/net/dsa/realtek/Kconfig +++ b/drivers/net/dsa/realtek/Kconfig @@ -16,14 +16,14 @@ menuconfig NET_DSA_REALTEK if NET_DSA_REALTEK config NET_DSA_REALTEK_MDIO - tristate "Realtek MDIO interface support" + bool "Realtek MDIO interface support" depends on OF help Select to enable support for registering switches configured through MDIO. config NET_DSA_REALTEK_SMI - tristate "Realtek SMI interface support" + bool "Realtek SMI interface support" depends on OF help Select to enable support for registering switches connected diff --git a/drivers/net/dsa/realtek/Makefile b/drivers/net/dsa/realtek/Makefile index 5e0c1ef200a3..88f6652f9850 100644 --- a/drivers/net/dsa/realtek/Makefile +++ b/drivers/net/dsa/realtek/Makefile @@ -1,7 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_NET_DSA_REALTEK) += realtek-common.o -obj-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o -obj-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o +obj-$(CONFIG_NET_DSA_REALTEK) += realtek_common.o +realtek_common-objs-y := realtek-common.o +realtek_common-objs-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o +realtek_common-objs-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o +realtek_common-objs := $(realtek_common-objs-y) obj-$(CONFIG_NET_DSA_REALTEK_RTL8366RB) += rtl8366.o rtl8366-objs := rtl8366-core.o rtl8366rb.o obj-$(CONFIG_NET_DSA_REALTEK_RTL8365MB) += rtl8365mb.o diff --git a/drivers/net/dsa/realtek/realtek-common.c b/drivers/net/dsa/realtek/realtek-common.c index 75b6aa071990..73c25d114dd3 100644 --- a/drivers/net/dsa/realtek/realtek-common.c +++ b/drivers/net/dsa/realtek/realtek-common.c @@ -132,5 +132,6 @@ void realtek_common_remove(struct realtek_priv *priv) EXPORT_SYMBOL(realtek_common_remove); MODULE_AUTHOR("Luiz Angelo Daros de Luca "); +MODULE_AUTHOR("Linus Walleij "); MODULE_DESCRIPTION("Realtek DSA switches common module"); MODULE_LICENSE("GPL"); diff --git a/drivers/net/dsa/realtek/realtek-mdio.c b/drivers/net/dsa/realtek/realtek-mdio.c index 4c9a744b72f8..bb5bff719ae9 100644 --- a/drivers/net/dsa/realtek/realtek-mdio.c +++ b/drivers/net/dsa/realtek/realtek-mdio.c @@ -168,7 +168,3 @@ void realtek_mdio_shutdown(struct mdio_device *mdiodev) dev_set_drvdata(&mdiodev->dev, NULL); } EXPORT_SYMBOL_GPL(realtek_mdio_shutdown); - -MODULE_AUTHOR("Luiz Angelo Daros de Luca "); -MODULE_DESCRIPTION("Driver for Realtek ethernet switch connected via MDIO interface"); -MODULE_LICENSE("GPL"); diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index 246024eec3bd..1ca2aa784d24 100644 --- a/drivers/net/dsa/realtek/realtek-smi.c +++ b/drivers/net/dsa/realtek/realtek-smi.c @@ -443,7 +443,3 @@ void realtek_smi_shutdown(struct platform_device *pdev) platform_set_drvdata(pdev, NULL); } EXPORT_SYMBOL_GPL(realtek_smi_shutdown); - -MODULE_AUTHOR("Linus Walleij "); -MODULE_DESCRIPTION("Driver for Realtek ethernet switch connected via SMI interface"); -MODULE_LICENSE("GPL"); From patchwork Fri Dec 8 04:41:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 13484768 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GliKuIyG" Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F04C210DF for ; Thu, 7 Dec 2023 20:52:04 -0800 (PST) Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3b9e6262fccso505562b6e.3 for ; Thu, 07 Dec 2023 20:52:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702011124; x=1702615924; 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=gaLuLAvvhJHcsb9yo6DwDQL3NLBHLYnwTPlqBlfiIYo=; b=GliKuIyGMkRCMtlAkNn2wTdWMvFuyKTT5oULKdKZi8YgCrf3zAmD/sNSu/Cnq4JAba eHOpUJbBKtF1ngvxwBEC1IWj4smCXjR0IDv48nuM7deL+4rE3xg8E7ISqjn8RLQwGM+i jOLB8e6CdNUnelj9qW1XKBD/DQM8DL7Zj1uFbCrWAyAekBNzbf5fdBt24K+ZAZYhkIN+ MAz1l0JZwK5vfRX9d0d0jH1+MlHiF5QdRvMTkHrQZYvwhuHxG5vOJhBGxe0cesitInp5 wXyOhykuRw3rMEzUb54XzWGmQzxFdmcTnV7irnvpB0J+qARFv9lUlIb3xETVR8pg7tuB RYvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702011124; x=1702615924; 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=gaLuLAvvhJHcsb9yo6DwDQL3NLBHLYnwTPlqBlfiIYo=; b=ezHBuU06s4nrTled4O/rule4dA+7JtiLnIiMcTe11ezmedZXa0nHKUpG5AIkyd+if7 0tPdrbIRs9kO73AysA3L2msytDGGTlzr8MiHRTvv4sHrYrqsFOJJ8MpHTHxAxXA9UOlN OKQS9LIjsjsbNfbsonZuqNYuguyV70LodE/0I5tJu0sRy4AHlS8kXGUuhpX6kpSf6MKZ njA6TmvGFOIRRKCfmLW2iRPHfw7j8lFhNp8K2qVdLvjHwqICAYwlQ3azLjDnna/euZm+ 7NhQdqpyleMtAf1i2MWZ+3baiO84uAy/G5J6djd6X2WQfQ3DDfj1giDlAi4Ijbw/T0Hz O86A== X-Gm-Message-State: AOJu0Yz4xC5Nx7ZN3RyRS8lqpjCB7IRrajoYVtXdQLoA7o+d57efUwbF gyEtNBb58LJE9eiSjdHcWUg0oxtEijQdQdwJ X-Google-Smtp-Source: AGHT+IGizaBXvO2zagkwxnbAeIA91QDveLCjsbxmmJ1ylOjk8qizP/0fLB96qvQC2Km9rw5QIDXTVg== X-Received: by 2002:a54:4483:0:b0:3b9:dd4d:721b with SMTP id v3-20020a544483000000b003b9dd4d721bmr2132687oiv.65.1702011123733; Thu, 07 Dec 2023 20:52:03 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:c:204:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id f18-20020a056a00229200b006cbae51f335sm657865pfe.144.2023.12.07.20.51.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 20:52:03 -0800 (PST) From: Luiz Angelo Daros de Luca To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, alsi@bang-olufsen.dk, andrew@lunn.ch, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, arinc.unal@arinc9.com, Luiz Angelo Daros de Luca Subject: [PATCH net-next 6/7] net: dsa: realtek: migrate user_mii setup to common Date: Fri, 8 Dec 2023 01:41:42 -0300 Message-ID: <20231208045054.27966-7-luizluca@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208045054.27966-1-luizluca@gmail.com> References: <20231208045054.27966-1-luizluca@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 Although there are many mentions to SMI in in the user mdio driver, including its compatible string, there is nothing special about the SMI interface in the user mdio bus. That way, the code was migrated to the common module. All references to SMI were removed, except for the compatible string that will still work but warn about using the mdio node name instead. The variant ds_ops_{smi,mdio} fields were rename to, respectively, ds_ops_custom_user_mdio and ds_ops_default_user_mdio. The priv->setup_interface() is also gone. If the ds_ops defines phy_read/write, it means DSA will handle the user_mii_bus. We don't need to check in another place. Also, with the function that would define setup_interface() in common, we can call it directly. Signed-off-by: Luiz Angelo Daros de Luca --- drivers/net/dsa/realtek/realtek-common.c | 67 ++++++++++++++++++++++++ drivers/net/dsa/realtek/realtek-common.h | 1 + drivers/net/dsa/realtek/realtek-mdio.c | 2 +- drivers/net/dsa/realtek/realtek-smi.c | 61 +-------------------- drivers/net/dsa/realtek/realtek.h | 5 +- drivers/net/dsa/realtek/rtl8365mb.c | 12 ++--- drivers/net/dsa/realtek/rtl8366rb.c | 12 ++--- 7 files changed, 84 insertions(+), 76 deletions(-) diff --git a/drivers/net/dsa/realtek/realtek-common.c b/drivers/net/dsa/realtek/realtek-common.c index 73c25d114dd3..64a55cb1ea05 100644 --- a/drivers/net/dsa/realtek/realtek-common.c +++ b/drivers/net/dsa/realtek/realtek-common.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ #include +#include #include "realtek.h" #include "realtek-common.h" @@ -21,6 +22,72 @@ void realtek_common_unlock(void *ctx) } EXPORT_SYMBOL_GPL(realtek_common_unlock); +static int realtek_common_user_mdio_read(struct mii_bus *bus, int addr, + int regnum) +{ + struct realtek_priv *priv = bus->priv; + + return priv->ops->phy_read(priv, addr, regnum); +} + +static int realtek_common_user_mdio_write(struct mii_bus *bus, int addr, + int regnum, u16 val) +{ + struct realtek_priv *priv = bus->priv; + + return priv->ops->phy_write(priv, addr, regnum, val); +} + +int realtek_common_setup_user_mdio(struct dsa_switch *ds) +{ + struct realtek_priv *priv = ds->priv; + struct device_node *mdio_np; + const char compatible = "realtek,smi-mdio"; + int ret; + + mdio_np = of_get_child_by_name(priv->dev->of_node, "mdio"); + if (!mdio_np) { + mdio_np = of_get_compatible_child(priv->dev->of_node, compatible); + if (!mdio_np) { + dev_err(priv->dev, "no MDIO bus node\n"); + return -ENODEV; + } + dev_warn(priv->dev, + "Rename node '%s' to 'mdio' and remove compatible '%s'", + mdio_np->name, compatible); + } + + priv->user_mii_bus = devm_mdiobus_alloc(priv->dev); + if (!priv->user_mii_bus) { + ret = -ENOMEM; + goto err_put_node; + } + priv->user_mii_bus->priv = priv; + priv->user_mii_bus->name = "Realtek user MII"; + priv->user_mii_bus->read = realtek_common_user_mdio_read; + priv->user_mii_bus->write = realtek_common_user_mdio_write; + snprintf(priv->user_mii_bus->id, MII_BUS_ID_SIZE, "Realtek-%d", + ds->index); + priv->user_mii_bus->parent = priv->dev; + ds->user_mii_bus = priv->user_mii_bus; + + ret = devm_of_mdiobus_register(priv->dev, priv->user_mii_bus, mdio_np); + of_node_put(mdio_np); + if (ret) { + dev_err(priv->dev, "unable to register MDIO bus %s\n", + priv->user_mii_bus->id); + return ret; + } + + return 0; + +err_put_node: + of_node_put(mdio_np); + + return ret; +} +EXPORT_SYMBOL_GPL(realtek_common_setup_user_mdio); + struct realtek_priv * realtek_common_probe_pre(struct device *dev, struct regmap_config rc, struct regmap_config rc_nolock) diff --git a/drivers/net/dsa/realtek/realtek-common.h b/drivers/net/dsa/realtek/realtek-common.h index 405bd0d85d2b..4f8c66167b15 100644 --- a/drivers/net/dsa/realtek/realtek-common.h +++ b/drivers/net/dsa/realtek/realtek-common.h @@ -7,6 +7,7 @@ void realtek_common_lock(void *ctx); void realtek_common_unlock(void *ctx); +int realtek_common_setup_user_mdio(struct dsa_switch *ds); struct realtek_priv * realtek_common_probe_pre(struct device *dev, struct regmap_config rc, struct regmap_config rc_nolock); diff --git a/drivers/net/dsa/realtek/realtek-mdio.c b/drivers/net/dsa/realtek/realtek-mdio.c index bb5bff719ae9..37a41bab20b4 100644 --- a/drivers/net/dsa/realtek/realtek-mdio.c +++ b/drivers/net/dsa/realtek/realtek-mdio.c @@ -141,7 +141,7 @@ int realtek_mdio_probe(struct mdio_device *mdiodev) priv->bus = mdiodev->bus; priv->mdio_addr = mdiodev->addr; priv->write_reg_noack = realtek_mdio_write; - priv->ds_ops = priv->variant->ds_ops_mdio; + priv->ds_ops = priv->variant->ds_ops_default_user_mdio; return realtek_common_probe_post(priv); diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index 1ca2aa784d24..84dde2123b09 100644 --- a/drivers/net/dsa/realtek/realtek-smi.c +++ b/drivers/net/dsa/realtek/realtek-smi.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -339,63 +338,6 @@ static const struct regmap_config realtek_smi_nolock_regmap_config = { .disable_locking = true, }; -static int realtek_smi_mdio_read(struct mii_bus *bus, int addr, int regnum) -{ - struct realtek_priv *priv = bus->priv; - - return priv->ops->phy_read(priv, addr, regnum); -} - -static int realtek_smi_mdio_write(struct mii_bus *bus, int addr, int regnum, - u16 val) -{ - struct realtek_priv *priv = bus->priv; - - return priv->ops->phy_write(priv, addr, regnum, val); -} - -static int realtek_smi_setup_mdio(struct dsa_switch *ds) -{ - struct realtek_priv *priv = ds->priv; - struct device_node *mdio_np; - int ret; - - mdio_np = of_get_compatible_child(priv->dev->of_node, "realtek,smi-mdio"); - if (!mdio_np) { - dev_err(priv->dev, "no MDIO bus node\n"); - return -ENODEV; - } - - priv->user_mii_bus = devm_mdiobus_alloc(priv->dev); - if (!priv->user_mii_bus) { - ret = -ENOMEM; - goto err_put_node; - } - priv->user_mii_bus->priv = priv; - priv->user_mii_bus->name = "SMI user MII"; - priv->user_mii_bus->read = realtek_smi_mdio_read; - priv->user_mii_bus->write = realtek_smi_mdio_write; - snprintf(priv->user_mii_bus->id, MII_BUS_ID_SIZE, "SMI-%d", - ds->index); - priv->user_mii_bus->parent = priv->dev; - ds->user_mii_bus = priv->user_mii_bus; - - ret = devm_of_mdiobus_register(priv->dev, priv->user_mii_bus, mdio_np); - of_node_put(mdio_np); - if (ret) { - dev_err(priv->dev, "unable to register MDIO bus %s\n", - priv->user_mii_bus->id); - return ret; - } - - return 0; - -err_put_node: - of_node_put(mdio_np); - - return ret; -} - int realtek_smi_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -416,8 +358,7 @@ int realtek_smi_probe(struct platform_device *pdev) return PTR_ERR(priv->mdio); priv->write_reg_noack = realtek_smi_write_reg_noack; - priv->setup_interface = realtek_smi_setup_mdio; - priv->ds_ops = priv->variant->ds_ops_smi; + priv->ds_ops = priv->variant->ds_ops_custom_user_mdio; return realtek_common_probe_post(priv); } diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h index fbd0616c1df3..3fa8479c396f 100644 --- a/drivers/net/dsa/realtek/realtek.h +++ b/drivers/net/dsa/realtek/realtek.h @@ -71,7 +71,6 @@ struct realtek_priv { struct rtl8366_mib_counter *mib_counters; const struct realtek_ops *ops; - int (*setup_interface)(struct dsa_switch *ds); int (*write_reg_noack)(void *ctx, u32 addr, u32 data); int vlan_enabled; @@ -115,8 +114,8 @@ struct realtek_ops { }; struct realtek_variant { - const struct dsa_switch_ops *ds_ops_smi; - const struct dsa_switch_ops *ds_ops_mdio; + const struct dsa_switch_ops *ds_ops_default_user_mdio; + const struct dsa_switch_ops *ds_ops_custom_user_mdio; const struct realtek_ops *ops; unsigned int clk_delay; u8 cmd_read; diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/rtl8365mb.c index ac848b965f84..a52fb07504b5 100644 --- a/drivers/net/dsa/realtek/rtl8365mb.c +++ b/drivers/net/dsa/realtek/rtl8365mb.c @@ -2017,8 +2017,8 @@ static int rtl8365mb_setup(struct dsa_switch *ds) if (ret) goto out_teardown_irq; - if (priv->setup_interface) { - ret = priv->setup_interface(ds); + if (!priv->ds_ops->phy_read) { + ret = realtek_common_setup_user_mdio(ds); if (ret) { dev_err(priv->dev, "could not set up MDIO bus\n"); goto out_teardown_irq; @@ -2116,7 +2116,7 @@ static int rtl8365mb_detect(struct realtek_priv *priv) return 0; } -static const struct dsa_switch_ops rtl8365mb_switch_ops_smi = { +static const struct dsa_switch_ops rtl8365mb_switch_ops_custom_user_mdio = { .get_tag_protocol = rtl8365mb_get_tag_protocol, .change_tag_protocol = rtl8365mb_change_tag_protocol, .setup = rtl8365mb_setup, @@ -2137,7 +2137,7 @@ static const struct dsa_switch_ops rtl8365mb_switch_ops_smi = { .port_max_mtu = rtl8365mb_port_max_mtu, }; -static const struct dsa_switch_ops rtl8365mb_switch_ops_mdio = { +static const struct dsa_switch_ops rtl8365mb_switch_ops_default_user_mdio = { .get_tag_protocol = rtl8365mb_get_tag_protocol, .change_tag_protocol = rtl8365mb_change_tag_protocol, .setup = rtl8365mb_setup, @@ -2167,8 +2167,8 @@ static const struct realtek_ops rtl8365mb_ops = { }; const struct realtek_variant rtl8365mb_variant = { - .ds_ops_smi = &rtl8365mb_switch_ops_smi, - .ds_ops_mdio = &rtl8365mb_switch_ops_mdio, + .ds_ops_default_user_mdio = &rtl8365mb_switch_ops_default_user_mdio, + .ds_ops_custom_user_mdio = &rtl8365mb_switch_ops_custom_user_mdio, .ops = &rtl8365mb_ops, .clk_delay = 10, .cmd_read = 0xb9, diff --git a/drivers/net/dsa/realtek/rtl8366rb.c b/drivers/net/dsa/realtek/rtl8366rb.c index 1cc4de3cf54f..9b6997574d2c 100644 --- a/drivers/net/dsa/realtek/rtl8366rb.c +++ b/drivers/net/dsa/realtek/rtl8366rb.c @@ -1027,8 +1027,8 @@ static int rtl8366rb_setup(struct dsa_switch *ds) if (ret) dev_info(priv->dev, "no interrupt support\n"); - if (priv->setup_interface) { - ret = priv->setup_interface(ds); + if (!priv->ds_ops->phy_read) { + ret = realtek_common_setup_user_mdio(ds); if (ret) { dev_err(priv->dev, "could not set up MDIO bus\n"); return -ENODEV; @@ -1848,7 +1848,7 @@ static int rtl8366rb_detect(struct realtek_priv *priv) return 0; } -static const struct dsa_switch_ops rtl8366rb_switch_ops_smi = { +static const struct dsa_switch_ops rtl8366rb_switch_ops_custom_user_mdio = { .get_tag_protocol = rtl8366_get_tag_protocol, .setup = rtl8366rb_setup, .phylink_get_caps = rtl8366rb_phylink_get_caps, @@ -1872,7 +1872,7 @@ static const struct dsa_switch_ops rtl8366rb_switch_ops_smi = { .port_max_mtu = rtl8366rb_max_mtu, }; -static const struct dsa_switch_ops rtl8366rb_switch_ops_mdio = { +static const struct dsa_switch_ops rtl8366rb_switch_ops_default_user_mdio = { .get_tag_protocol = rtl8366_get_tag_protocol, .setup = rtl8366rb_setup, .phy_read = rtl8366rb_dsa_phy_read, @@ -1915,8 +1915,8 @@ static const struct realtek_ops rtl8366rb_ops = { }; const struct realtek_variant rtl8366rb_variant = { - .ds_ops_smi = &rtl8366rb_switch_ops_smi, - .ds_ops_mdio = &rtl8366rb_switch_ops_mdio, + .ds_ops_default_user_mdio = &rtl8366rb_switch_ops_default_user_mdio, + .ds_ops_custom_user_mdio = &rtl8366rb_switch_ops_custom_user_mdio, .ops = &rtl8366rb_ops, .clk_delay = 10, .cmd_read = 0xa9, From patchwork Fri Dec 8 04:41:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 13484769 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GaQDLiEb" Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E5A510DF for ; Thu, 7 Dec 2023 20:52:09 -0800 (PST) Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-6d99c3a3a32so1107030a34.3 for ; Thu, 07 Dec 2023 20:52:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702011127; x=1702615927; 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=99mdIioUbBhs4PEyXUHYzmP64HTbTsdx/htPvpodEMg=; b=GaQDLiEbvVt6uLR0A6rZ600+IE0toqYVNHWTii/dM37HBatqS5l7aZvtnWixa7wp9+ PVD4yDkBwgcEctjkD3XjMvabUGVf4dX5a7fBAd40SJrV+Css8MBCQSy6YjaUpavq58gT nkNDRG6OYLACoNUF80SISNIiMhXTVVP+oXmjmJuL/HuA3j7ISsoTWY1Ws5V2hwSVs+ud c7blw5kV9kZVhuXrMAKa1WpAEOistVmvh6ZKUA5NDlVTqEezRFD0QbXRGuCriQvdqiSn 5kF3vayZK8vt8wYBTzCTDSiK/jmRh+d3mQOUFkTLATxqgEoG4VB69L1GHau6za1zob2T pTqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702011127; x=1702615927; 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=99mdIioUbBhs4PEyXUHYzmP64HTbTsdx/htPvpodEMg=; b=RDrO7lCEpJSExaVAdx/jy8YW2BGaFeNZUw2y/9FzV0KJy+vpMqcm444fS9+P5BPWLA XxUvqQoXhqKhq92GKAP/6SboWV+JECAXIS44NizlQENmN2UivpOYiMRtLJw12ynT0JKc HNRaM6UfPwRyP7zWUY73smzBL460D0ZG4ulyaewmju7eje9RKNWhOdM7btiOQwEb4FMJ 5ehYN8uUewv4K+C/EuUnoX0O5EOoDqnL2NPE5l78Q2tVsgsXY3lE5Qn/PGFMJhwYbTrP R4rzUPp3+n/n3igGj61A2D4ZMBe3ThKNtJ+jH+IHmcjjqa5hxC777Ma6PaOXJQZZuSHe BcNg== X-Gm-Message-State: AOJu0YxAh1NmyrtkZTF9F4ZnSM/GkYXjKi+/h5yHxJRsxQU0tlY5rQUu HLTDTkCMvQ+j2Ac8S+c0V4AwextEdEx7EhqP X-Google-Smtp-Source: AGHT+IHkFVm/5Z3/79R/tjWqTFcOX9DrNGTpF/Gj6tS3AcA4HqjbF5jG+MlMbHGQMsQdiGqQt2d1Xw== X-Received: by 2002:a9d:6d98:0:b0:6d9:d1f4:361b with SMTP id x24-20020a9d6d98000000b006d9d1f4361bmr2843083otp.59.1702011127518; Thu, 07 Dec 2023 20:52:07 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:c:204:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id f18-20020a056a00229200b006cbae51f335sm657865pfe.144.2023.12.07.20.52.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 20:52:06 -0800 (PST) From: Luiz Angelo Daros de Luca To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, alsi@bang-olufsen.dk, andrew@lunn.ch, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, arinc.unal@arinc9.com, Luiz Angelo Daros de Luca Subject: [PATCH net-next 7/7] net: dsa: realtek: always use the realtek user mdio driver Date: Fri, 8 Dec 2023 01:41:43 -0300 Message-ID: <20231208045054.27966-8-luizluca@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208045054.27966-1-luizluca@gmail.com> References: <20231208045054.27966-1-luizluca@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 Although the DSA switch will register a generic mdio driver when ds_ops.phy_{read,write} exists ("dsa user smi"), it was pointed out that it was not a core feature to depend on [1]. That way, the realtek user mdio driver will be used by both interfaces. [1] https://lkml.kernel.org/netdev/20220630200423.tieprdu5fpabflj7@bang-olufsen.dk/T/ The ds_ops field in realtek_priv was also dropped as now we can directly reference the variant->ds_ops. Signed-off-by: Luiz Angelo Daros de Luca --- drivers/net/dsa/realtek/realtek-common.c | 4 +- drivers/net/dsa/realtek/realtek-mdio.c | 1 - drivers/net/dsa/realtek/realtek-smi.c | 1 - drivers/net/dsa/realtek/realtek.h | 4 +- drivers/net/dsa/realtek/rtl8365mb.c | 49 +++------------------- drivers/net/dsa/realtek/rtl8366rb.c | 52 +++--------------------- 6 files changed, 15 insertions(+), 96 deletions(-) diff --git a/drivers/net/dsa/realtek/realtek-common.c b/drivers/net/dsa/realtek/realtek-common.c index 64a55cb1ea05..058c16cea6c3 100644 --- a/drivers/net/dsa/realtek/realtek-common.c +++ b/drivers/net/dsa/realtek/realtek-common.c @@ -42,7 +42,7 @@ int realtek_common_setup_user_mdio(struct dsa_switch *ds) { struct realtek_priv *priv = ds->priv; struct device_node *mdio_np; - const char compatible = "realtek,smi-mdio"; + const char *compatible = "realtek,smi-mdio"; int ret; mdio_np = of_get_child_by_name(priv->dev->of_node, "mdio"); @@ -172,7 +172,7 @@ int realtek_common_probe_post(struct realtek_priv *priv) priv->ds->priv = priv; priv->ds->dev = priv->dev; - priv->ds->ops = priv->ds_ops; + priv->ds->ops = priv->variant->ds_ops; priv->ds->num_ports = priv->num_ports; ret = dsa_register_switch(priv->ds); diff --git a/drivers/net/dsa/realtek/realtek-mdio.c b/drivers/net/dsa/realtek/realtek-mdio.c index 37a41bab20b4..bfa2bda35232 100644 --- a/drivers/net/dsa/realtek/realtek-mdio.c +++ b/drivers/net/dsa/realtek/realtek-mdio.c @@ -141,7 +141,6 @@ int realtek_mdio_probe(struct mdio_device *mdiodev) priv->bus = mdiodev->bus; priv->mdio_addr = mdiodev->addr; priv->write_reg_noack = realtek_mdio_write; - priv->ds_ops = priv->variant->ds_ops_default_user_mdio; return realtek_common_probe_post(priv); diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index 84dde2123b09..9a62c9993d7c 100644 --- a/drivers/net/dsa/realtek/realtek-smi.c +++ b/drivers/net/dsa/realtek/realtek-smi.c @@ -358,7 +358,6 @@ int realtek_smi_probe(struct platform_device *pdev) return PTR_ERR(priv->mdio); priv->write_reg_noack = realtek_smi_write_reg_noack; - priv->ds_ops = priv->variant->ds_ops_custom_user_mdio; return realtek_common_probe_post(priv); } diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h index 3fa8479c396f..7af6dcc1bb24 100644 --- a/drivers/net/dsa/realtek/realtek.h +++ b/drivers/net/dsa/realtek/realtek.h @@ -60,7 +60,6 @@ struct realtek_priv { spinlock_t lock; /* Locks around command writes */ struct dsa_switch *ds; - const struct dsa_switch_ops *ds_ops; struct irq_domain *irqdomain; bool leds_disabled; @@ -114,8 +113,7 @@ struct realtek_ops { }; struct realtek_variant { - const struct dsa_switch_ops *ds_ops_default_user_mdio; - const struct dsa_switch_ops *ds_ops_custom_user_mdio; + const struct dsa_switch_ops *ds_ops; const struct realtek_ops *ops; unsigned int clk_delay; u8 cmd_read; diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/rtl8365mb.c index a52fb07504b5..eb20ade9e025 100644 --- a/drivers/net/dsa/realtek/rtl8365mb.c +++ b/drivers/net/dsa/realtek/rtl8365mb.c @@ -828,17 +828,6 @@ static int rtl8365mb_phy_write(struct realtek_priv *priv, int phy, int regnum, return 0; } -static int rtl8365mb_dsa_phy_read(struct dsa_switch *ds, int phy, int regnum) -{ - return rtl8365mb_phy_read(ds->priv, phy, regnum); -} - -static int rtl8365mb_dsa_phy_write(struct dsa_switch *ds, int phy, int regnum, - u16 val) -{ - return rtl8365mb_phy_write(ds->priv, phy, regnum, val); -} - static const struct rtl8365mb_extint * rtl8365mb_get_port_extint(struct realtek_priv *priv, int port) { @@ -2017,12 +2006,10 @@ static int rtl8365mb_setup(struct dsa_switch *ds) if (ret) goto out_teardown_irq; - if (!priv->ds_ops->phy_read) { - ret = realtek_common_setup_user_mdio(ds); - if (ret) { - dev_err(priv->dev, "could not set up MDIO bus\n"); - goto out_teardown_irq; - } + ret = realtek_common_setup_user_mdio(ds); + if (ret) { + dev_err(priv->dev, "could not set up MDIO bus\n"); + goto out_teardown_irq; } /* Start statistics counter polling */ @@ -2116,28 +2103,7 @@ static int rtl8365mb_detect(struct realtek_priv *priv) return 0; } -static const struct dsa_switch_ops rtl8365mb_switch_ops_custom_user_mdio = { - .get_tag_protocol = rtl8365mb_get_tag_protocol, - .change_tag_protocol = rtl8365mb_change_tag_protocol, - .setup = rtl8365mb_setup, - .teardown = rtl8365mb_teardown, - .phylink_get_caps = rtl8365mb_phylink_get_caps, - .phylink_mac_config = rtl8365mb_phylink_mac_config, - .phylink_mac_link_down = rtl8365mb_phylink_mac_link_down, - .phylink_mac_link_up = rtl8365mb_phylink_mac_link_up, - .port_stp_state_set = rtl8365mb_port_stp_state_set, - .get_strings = rtl8365mb_get_strings, - .get_ethtool_stats = rtl8365mb_get_ethtool_stats, - .get_sset_count = rtl8365mb_get_sset_count, - .get_eth_phy_stats = rtl8365mb_get_phy_stats, - .get_eth_mac_stats = rtl8365mb_get_mac_stats, - .get_eth_ctrl_stats = rtl8365mb_get_ctrl_stats, - .get_stats64 = rtl8365mb_get_stats64, - .port_change_mtu = rtl8365mb_port_change_mtu, - .port_max_mtu = rtl8365mb_port_max_mtu, -}; - -static const struct dsa_switch_ops rtl8365mb_switch_ops_default_user_mdio = { +static const struct dsa_switch_ops rtl8365mb_switch_ops = { .get_tag_protocol = rtl8365mb_get_tag_protocol, .change_tag_protocol = rtl8365mb_change_tag_protocol, .setup = rtl8365mb_setup, @@ -2146,8 +2112,6 @@ static const struct dsa_switch_ops rtl8365mb_switch_ops_default_user_mdio = { .phylink_mac_config = rtl8365mb_phylink_mac_config, .phylink_mac_link_down = rtl8365mb_phylink_mac_link_down, .phylink_mac_link_up = rtl8365mb_phylink_mac_link_up, - .phy_read = rtl8365mb_dsa_phy_read, - .phy_write = rtl8365mb_dsa_phy_write, .port_stp_state_set = rtl8365mb_port_stp_state_set, .get_strings = rtl8365mb_get_strings, .get_ethtool_stats = rtl8365mb_get_ethtool_stats, @@ -2167,8 +2131,7 @@ static const struct realtek_ops rtl8365mb_ops = { }; const struct realtek_variant rtl8365mb_variant = { - .ds_ops_default_user_mdio = &rtl8365mb_switch_ops_default_user_mdio, - .ds_ops_custom_user_mdio = &rtl8365mb_switch_ops_custom_user_mdio, + .ds_ops = &rtl8365mb_switch_ops, .ops = &rtl8365mb_ops, .clk_delay = 10, .cmd_read = 0xb9, diff --git a/drivers/net/dsa/realtek/rtl8366rb.c b/drivers/net/dsa/realtek/rtl8366rb.c index 9b6997574d2c..a6caa3cb4e30 100644 --- a/drivers/net/dsa/realtek/rtl8366rb.c +++ b/drivers/net/dsa/realtek/rtl8366rb.c @@ -1027,12 +1027,10 @@ static int rtl8366rb_setup(struct dsa_switch *ds) if (ret) dev_info(priv->dev, "no interrupt support\n"); - if (!priv->ds_ops->phy_read) { - ret = realtek_common_setup_user_mdio(ds); - if (ret) { - dev_err(priv->dev, "could not set up MDIO bus\n"); - return -ENODEV; - } + ret = realtek_common_setup_user_mdio(ds); + if (ret) { + dev_err(priv->dev, "could not set up MDIO bus\n"); + return -ENODEV; } return 0; @@ -1772,17 +1770,6 @@ static int rtl8366rb_phy_write(struct realtek_priv *priv, int phy, int regnum, return ret; } -static int rtl8366rb_dsa_phy_read(struct dsa_switch *ds, int phy, int regnum) -{ - return rtl8366rb_phy_read(ds->priv, phy, regnum); -} - -static int rtl8366rb_dsa_phy_write(struct dsa_switch *ds, int phy, int regnum, - u16 val) -{ - return rtl8366rb_phy_write(ds->priv, phy, regnum, val); -} - static int rtl8366rb_reset_chip(struct realtek_priv *priv) { int timeout = 10; @@ -1848,35 +1835,9 @@ static int rtl8366rb_detect(struct realtek_priv *priv) return 0; } -static const struct dsa_switch_ops rtl8366rb_switch_ops_custom_user_mdio = { - .get_tag_protocol = rtl8366_get_tag_protocol, - .setup = rtl8366rb_setup, - .phylink_get_caps = rtl8366rb_phylink_get_caps, - .phylink_mac_link_up = rtl8366rb_mac_link_up, - .phylink_mac_link_down = rtl8366rb_mac_link_down, - .get_strings = rtl8366_get_strings, - .get_ethtool_stats = rtl8366_get_ethtool_stats, - .get_sset_count = rtl8366_get_sset_count, - .port_bridge_join = rtl8366rb_port_bridge_join, - .port_bridge_leave = rtl8366rb_port_bridge_leave, - .port_vlan_filtering = rtl8366rb_vlan_filtering, - .port_vlan_add = rtl8366_vlan_add, - .port_vlan_del = rtl8366_vlan_del, - .port_enable = rtl8366rb_port_enable, - .port_disable = rtl8366rb_port_disable, - .port_pre_bridge_flags = rtl8366rb_port_pre_bridge_flags, - .port_bridge_flags = rtl8366rb_port_bridge_flags, - .port_stp_state_set = rtl8366rb_port_stp_state_set, - .port_fast_age = rtl8366rb_port_fast_age, - .port_change_mtu = rtl8366rb_change_mtu, - .port_max_mtu = rtl8366rb_max_mtu, -}; - -static const struct dsa_switch_ops rtl8366rb_switch_ops_default_user_mdio = { +static const struct dsa_switch_ops rtl8366rb_switch_ops = { .get_tag_protocol = rtl8366_get_tag_protocol, .setup = rtl8366rb_setup, - .phy_read = rtl8366rb_dsa_phy_read, - .phy_write = rtl8366rb_dsa_phy_write, .phylink_get_caps = rtl8366rb_phylink_get_caps, .phylink_mac_link_up = rtl8366rb_mac_link_up, .phylink_mac_link_down = rtl8366rb_mac_link_down, @@ -1915,8 +1876,7 @@ static const struct realtek_ops rtl8366rb_ops = { }; const struct realtek_variant rtl8366rb_variant = { - .ds_ops_default_user_mdio = &rtl8366rb_switch_ops_default_user_mdio, - .ds_ops_custom_user_mdio = &rtl8366rb_switch_ops_custom_user_mdio, + .ds_ops = &rtl8366rb_switch_ops, .ops = &rtl8366rb_ops, .clk_delay = 10, .cmd_read = 0xa9,