From patchwork Tue Jan 30 23:13:22 2024 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: 194377 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1554105dyb; Tue, 30 Jan 2024 15:15:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IHYKz6c0CN59+tnL7ETzbZt9Hp+Ewk3tbD9dmKHJufT9gTcNrv3BEbg/t0f8Z5Oj5nxU3LT X-Received: by 2002:a17:90a:9a7:b0:295:bbfb:bf67 with SMTP id 36-20020a17090a09a700b00295bbfbbf67mr98519pjo.19.1706656540119; Tue, 30 Jan 2024 15:15:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706656540; cv=pass; d=google.com; s=arc-20160816; b=bPZXKS72c9OICaFj0l/8WbbePk0JIYxiUlsRwIwzvs2/rZIxsFRSNBbHbILM2qrbbd D6MK6wPweEb92IIDstLOTDXdkCXxwLP/HUMfxHCP/FoKlLsd38Wee8+SNNF3eVJMpJ0e OVgwa9uYJjQenx5i7wh/Y4poC2emEiDwol+ZXi2g0pyJ4++pg1TXR/zvmrmL5x8irtrJ TQenN483Q8nsWbJ2A+U3+QLZ2zHVCHbCIpLipx6ASFuXs3mwbMmYMbMQFIFaK4V5BQ2P PaUndOtj4QITse9sk/jCgw8EhzQRk+qzivKMD6G2jkyDCblCrafsUZ0ZCkHaLI5AeuLt 8zhg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=0+y1sA3tC6540mMSZV86cZx/IVw+CrYw9uo7PgguBzI=; fh=BU4RSkB+Q4EYbEXM8vpZ5rnbcSjfYSNW9lfntnZ9xiw=; b=enPDnZKW9nHBnc9hfLVcwnM+hyzKph4WSri8z8iHMgvA/0jRyZVEeTtnModZg0K0F/ WOj1kBuLve+/2zSbjtMKiiydgOtJrjFxLlZW+5UdLROO7CLQHx9X+x+AciiefOrPxmS+ AQGHccxApA2/i8fyyxAt3sS7dfg/ilwF8ohh4QyYJusCnCmtGG/AlUOqoftsy2RzoyDh hZRdcg027VA/Lbmr2jV1YZDmy2L5jpdJD7dPC3gztAYcBP84m0w5W/hkuvcqxRNR0u0q qK3EkTHdHY6eHGPqF3LToM7P28EiZWMYRQAG38jzXuJARqD2ZOJ4grE8TswGPC+sn4qV KAzQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DipxvnIa; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45453-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45453-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x4-20020a17090a9dc400b00290443272e3si10232844pjv.105.2024.01.30.15.15.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:15:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45453-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DipxvnIa; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45453-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45453-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D9DA2285EE1 for ; Tue, 30 Jan 2024 23:15:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9219E80BF1; Tue, 30 Jan 2024 23:14:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DipxvnIa" Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 798B97F472; Tue, 30 Jan 2024 23:14:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656453; cv=none; b=bluy8XctmInU7z0u9+v9mtG5Dk3c7vn5e+3Jjv+HHQ64FQoIJoqvnF3Is2NU1zP4/cIwcYASSDNpnaR9bn1oev4YJDTOHaaM05IhvfUyarnD0ne4DfXQoUP/r3P7qPA2QAylRFnFImHEwkA4PiDM2n1SJzYFggxoYxSN6zNJeR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656453; c=relaxed/simple; bh=UFN9BYB7BILVgTZyi8yjg3FFvbLkWlA36Mb1eKYgCPs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bXEyszhIzNU4yxCN701gKUPMCo/X4LmJFy7ILejd1P5YXOtcSOGogO9UYzJ8hbV7kzKa8NC6Szy+Nx+WDSFLESIdOkVX4T0riBvCmqwmxS/XGEjksiW7B4IVw98tH0KsUP5rgwPAynAHGNYzqQSvKkYWymFx3PUd55ihoIFxT9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DipxvnIa; arc=none smtp.client-ip=209.85.215.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-5c229dabbb6so2530763a12.0; Tue, 30 Jan 2024 15:14:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706656451; x=1707261251; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=0+y1sA3tC6540mMSZV86cZx/IVw+CrYw9uo7PgguBzI=; b=DipxvnIac34Uas3IDzOl6w8e9zwsmuILEWgQlbBORwbtwVTWtpXmwRvmgbo1K8Wzw6 wefT/0inLZyCLj3RpCc09yHufmdwh8jL27jtZpayrO1URZYrQCJrhF8GqH7HaB4ZFkuc ecTPY/A6WK17OX6xxrxBE49CLiGDdKElbeNCG4VHmMFxQV0Qbee81RSenwMNFvEvKIU0 pwgA5B43Kxy0iEGz1Gnl5ETh1S6Z1AJHtYPYM8lLpHbMdVrusBvKMEUkv6P78G8STxXD a176HaKTmUZnIl6F/FDeAgefhVM5GyDaaumZo8DYnHbc/kr5BNdQgl6DI8QOoX7PJcQw OdUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706656451; x=1707261251; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0+y1sA3tC6540mMSZV86cZx/IVw+CrYw9uo7PgguBzI=; b=erd0ULKKuGeR0JgX/1uaxq8IEmm0NTYPbhhTYl9jpGTZMBn5LWb4BfjjSOQE//vUEL JL2xfBnhsI/OTI18G2p5VSG4WhIlDvZuRGjZj4WcbNVme70A1B53k0bgQK9uC9VRTXgv 7G1hqTQ4i5z8Bz7umQzg/KdIZujshoq3/H3i6c2febf5ckuxSCguBSd1rBOBnoo13EA2 ga7Q5pfEIwFZVzFpbIZ5fHjjlmntE1UUSPXuwu1wHehDbr2V3YzDJ+RlRXFFrzP0yMAY NaCehbvBibDt6WNZUyRJy3rO/0gvm7k3bSvZ68cKXRs19QtObX9MZ6ed8Jq2ATEw0Tk4 d9sQ== X-Gm-Message-State: AOJu0YxNAu/uGuBu9kJOmn1u4GhOw5KgRPtB/II42nENSc9H80RpHTeQ qJC3mw0dpNtGwG1fbMBYm6yNa2zhPYnxWbTHZ5Mjwhy2LH+9R60E X-Received: by 2002:a17:903:94f:b0:1d8:a530:b885 with SMTP id ma15-20020a170903094f00b001d8a530b885mr44735plb.67.1706656450567; Tue, 30 Jan 2024 15:14:10 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:c:204:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id jx2-20020a170903138200b001d8f251c8b2sm3473203plb.221.2024.01.30.15.14.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:14:09 -0800 (PST) From: Luiz Angelo Daros de Luca Date: Tue, 30 Jan 2024 20:13:22 -0300 Subject: [PATCH net-next v5 03/11] net: dsa: realtek: convert variants into real drivers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240130-realtek_reverse-v5-3-ecafd9283a07@gmail.com> References: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> In-Reply-To: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> To: Linus Walleij , =?utf-8?q?Alvin_=C5=A0ipraga?= , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luiz Angelo Daros de Luca X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=17741; i=luizluca@gmail.com; h=from:subject:message-id; bh=UFN9BYB7BILVgTZyi8yjg3FFvbLkWlA36Mb1eKYgCPs=; b=owEBbQGS/pANAwAIAbsR27rRBztWAcsmYgBluYKwVCqzAI1Txsx40qwe61/rwY65wzFq2BrXP 2Kgn1TRvwSJATMEAAEIAB0WIQQRByhHhc1bOhL6L/i7Edu60Qc7VgUCZbmCsAAKCRC7Edu60Qc7 VgfeB/45cSRw7yjoxpI7rJMVnW/zn3lOInpfnHCySn1khthVxDpSr7M9opMFbalYPDwkM+9tn8H pZiRMb6vzqfchUM+8kvkBqMdTHTqHoFkaFKCaZwpiLywrbqZ7IK3ek7rWCZK2PQ514J2/cTCKpf 8fjshrw1Jl3C5w0unAojOY8R2pX5SDB906In6QYlI/CVdfx9LVwhttp9ItQwBHwroi7LESC70+P NTwWTcsREpDYfMWm83u5w4OZ8Gab2F74Da847uxoMK6c+IYWh1ZYhLibNJYmbxv8upLp3FOIubj BwmBGhVYCTNT1Kxw/YncZxJxOFjwHIeA1bWKEkyYHdGOkzCj X-Developer-Key: i=luizluca@gmail.com; a=openpgp; fpr=1107284785CD5B3A12FA2FF8BB11DBBAD1073B56 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789559087916278680 X-GMAIL-MSGID: 1789559087916278680 Previously, the interface modules realtek-smi and realtek-mdio served as a platform and an MDIO driver, respectively. Each interface module redundantly specified the same compatible strings for both variants and referenced symbols from the variants. Now, each variant module has been transformed into a unified driver serving both as a platform and an MDIO driver. This modification reverses the relationship between the interface and variant modules, with the variant module now utilizing symbols from the interface modules. Signed-off-by: Luiz Angelo Daros de Luca Reviewed-by: Vladimir Oltean --- drivers/net/dsa/realtek/Kconfig | 20 +++------- drivers/net/dsa/realtek/realtek-mdio.c | 68 +++++++++++++++++++------------ drivers/net/dsa/realtek/realtek-mdio.h | 48 ++++++++++++++++++++++ drivers/net/dsa/realtek/realtek-smi.c | 73 +++++++++++++++++++--------------- drivers/net/dsa/realtek/realtek-smi.h | 48 ++++++++++++++++++++++ drivers/net/dsa/realtek/rtl8365mb.c | 54 ++++++++++++++++++++++++- drivers/net/dsa/realtek/rtl8366rb.c | 54 ++++++++++++++++++++++++- 7 files changed, 292 insertions(+), 73 deletions(-) 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 c2572463679f..3433f64fb0d7 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,19 @@ static const struct regmap_config realtek_mdio_nolock_regmap_config = { .disable_locking = true, }; -static int realtek_mdio_probe(struct mdio_device *mdiodev) +/** + * realtek_mdio_probe() - Probe a platform device for an MDIO-connected switch + * @mdiodev: mdio_device to probe on. + * + * This function should be used as the .probe in an mdio_driver. It + * initializes realtek_priv and read data from the device-tree node. The switch + * is hard resetted if a method is provided. It checks the switch chip ID and, + * finally, a DSA switch is registered. + * + * Context: Can sleep. Takes and releases priv->map_lock. + * Return: Returns 0 on success, a negative error on failure. + */ +int realtek_mdio_probe(struct mdio_device *mdiodev) { struct realtek_priv *priv; struct device *dev = &mdiodev->dev; @@ -235,8 +248,20 @@ static int realtek_mdio_probe(struct mdio_device *mdiodev) return 0; } +EXPORT_SYMBOL_NS_GPL(realtek_mdio_probe, REALTEK_DSA); -static void realtek_mdio_remove(struct mdio_device *mdiodev) +/** + * realtek_mdio_remove() - Remove the driver of an MDIO-connected switch + * @mdiodev: mdio_device to be removed. + * + * This function should be used as the .remove_new in an mdio_driver. First + * it unregisters the DSA switch and cleans internal data. If a method is + * provided, the hard reset is asserted to avoid traffic leakage. + * + * Context: Can sleep. + * Return: Nothing. + */ +void realtek_mdio_remove(struct mdio_device *mdiodev) { struct realtek_priv *priv = dev_get_drvdata(&mdiodev->dev); @@ -249,8 +274,21 @@ static void realtek_mdio_remove(struct mdio_device *mdiodev) if (priv->reset) gpiod_set_value(priv->reset, 1); } +EXPORT_SYMBOL_NS_GPL(realtek_mdio_remove, REALTEK_DSA); -static void realtek_mdio_shutdown(struct mdio_device *mdiodev) +/** + * realtek_mdio_shutdown() - Shutdown the driver of a MDIO-connected switch + * @mdiodev: mdio_device shutting down. + * + * This function should be used as the .shutdown in an mdio_driver. It shuts + * down the DSA switch and cleans the platform driver data, to prevent + * realtek_mdio_remove() from running afterwards, which is possible if the + * parent bus implements its own .shutdown() as .remove(). + * + * Context: Can sleep. + * Return: Nothing. + */ +void realtek_mdio_shutdown(struct mdio_device *mdiodev) { struct realtek_priv *priv = dev_get_drvdata(&mdiodev->dev); @@ -261,29 +299,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_NS_GPL(realtek_mdio_shutdown, REALTEK_DSA); 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..ee70f6a5b8ff --- /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 /* IS_ENABLED(CONFIG_NET_DSA_REALTEK_MDIO) */ + +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 /* IS_ENABLED(CONFIG_NET_DSA_REALTEK_MDIO) */ + +#endif /* _REALTEK_MDIO_H */ diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index 668336515119..d8a9a6a6b5bc 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,19 @@ static int realtek_smi_setup_mdio(struct dsa_switch *ds) return ret; } -static int realtek_smi_probe(struct platform_device *pdev) +/** + * realtek_smi_probe() - Probe a platform device for an SMI-connected switch + * @pdev: platform_device to probe on. + * + * This function should be used as the .probe in a platform_driver. It + * initializes realtek_priv and read data from the device-tree node. The switch + * is hard resetted if a method is provided. It checks the switch chip ID and, + * finally, a DSA switch is registered. + * + * Context: Can sleep. Takes and releases priv->map_lock. + * Return: Returns 0 on success, a negative error on failure. + */ +int realtek_smi_probe(struct platform_device *pdev) { const struct realtek_variant *var; struct device *dev = &pdev->dev; @@ -505,8 +518,20 @@ static int realtek_smi_probe(struct platform_device *pdev) } return 0; } +EXPORT_SYMBOL_NS_GPL(realtek_smi_probe, REALTEK_DSA); -static void realtek_smi_remove(struct platform_device *pdev) +/** + * realtek_smi_remove() - Remove the driver of a SMI-connected switch + * @pdev: platform_device to be removed. + * + * This function should be used as the .remove_new in a platform_driver. First + * it unregisters the DSA switch and cleans internal data. If a method is + * provided, the hard reset is asserted to avoid traffic leakage. + * + * Context: Can sleep. + * Return: Nothing. + */ +void realtek_smi_remove(struct platform_device *pdev) { struct realtek_priv *priv = platform_get_drvdata(pdev); @@ -521,8 +546,21 @@ static void realtek_smi_remove(struct platform_device *pdev) if (priv->reset) gpiod_set_value(priv->reset, 1); } +EXPORT_SYMBOL_NS_GPL(realtek_smi_remove, REALTEK_DSA); -static void realtek_smi_shutdown(struct platform_device *pdev) +/** + * realtek_smi_shutdown() - Shutdown the driver of a SMI-connected switch + * @pdev: platform_device shutting down. + * + * This function should be used as the .shutdown in a platform_driver. It shuts + * down the DSA switch and cleans the platform driver data, to prevent + * realtek_smi_remove() from running afterwards, which is possible if the + * parent bus implements its own .shutdown() as .remove(). + * + * Context: Can sleep. + * Return: Nothing. + */ +void realtek_smi_shutdown(struct platform_device *pdev) { struct realtek_priv *priv = platform_get_drvdata(pdev); @@ -533,34 +571,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_NS_GPL(realtek_smi_shutdown, REALTEK_DSA); 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..ea49a2edd3c8 --- /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 /* IS_ENABLED(CONFIG_NET_DSA_REALTEK_SMI) */ + +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 /* IS_ENABLED(CONFIG_NET_DSA_REALTEK_SMI) */ + +#endif /* _REALTEK_SMI_H */ diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/rtl8365mb.c index c42ee8241ca2..e67c4562f5db 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,57 @@ 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; + + ret = realtek_smi_driver_register(&rtl8365mb_smi_driver); + if (ret) { + realtek_mdio_driver_unregister(&rtl8365mb_mdio_driver); + return ret; + } + + return 0; +} +module_init(rtl8365mb_init); + +static void __exit rtl8365mb_exit(void) +{ + realtek_smi_driver_unregister(&rtl8365mb_smi_driver); + realtek_mdio_driver_unregister(&rtl8365mb_mdio_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 6661d4ba6882..747407ae8225 100644 --- a/drivers/net/dsa/realtek/rtl8366rb.c +++ b/drivers/net/dsa/realtek/rtl8366rb.c @@ -23,6 +23,8 @@ #include #include "realtek.h" +#include "realtek-smi.h" +#include "realtek-mdio.h" #define RTL8366RB_PORT_NUM_CPU 5 #define RTL8366RB_NUM_PORTS 6 @@ -1933,7 +1935,57 @@ 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; + + ret = realtek_smi_driver_register(&rtl8366rb_smi_driver); + if (ret) { + realtek_mdio_driver_unregister(&rtl8366rb_mdio_driver); + return ret; + } + + return 0; +} +module_init(rtl8366rb_init); + +static void __exit rtl8366rb_exit(void) +{ + realtek_smi_driver_unregister(&rtl8366rb_smi_driver); + realtek_mdio_driver_unregister(&rtl8366rb_mdio_driver); +} +module_exit(rtl8366rb_exit); MODULE_AUTHOR("Linus Walleij "); MODULE_DESCRIPTION("Driver for RTL8366RB ethernet switch"); From patchwork Tue Jan 30 23:13:23 2024 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: 194378 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1554191dyb; Tue, 30 Jan 2024 15:15:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkQ/mVWnnsumY5URfZZ88pLfhzQMUQjWrOWJJmysKowt8tKb0ASTmCyAYfaAtCFoQKdzOd X-Received: by 2002:a05:6402:c94:b0:55f:797:8602 with SMTP id cm20-20020a0564020c9400b0055f07978602mr3649162edb.18.1706656546746; Tue, 30 Jan 2024 15:15:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706656546; cv=pass; d=google.com; s=arc-20160816; b=cGRfM1UORz+dtXzSz03aNcIbyODIBNmUw6BpIE4Q6AWLo4wMkREhY771c6wBk1HrS7 2OarweKcgdOReK8tFEDOK7QHVVftszgv9y51fCwpS0WKdnaLmJywrlCJ4ozQ+ll35YIq XMdGAnwBzTK5TTOihFlpRTtBc3RC3KvvsJtL6+LPYUfvw7fK95bnwdey9wgniE5IA15w 0th6MZ6WUZ77f6o2fXVJplpF8BPFaR+j+w1kvFgafFiAB8oP81ba3Upl8dfaHNEn5rsa E7yA81SXaE4QF3LYZ59+z8d9GzFY3Rg3xFac/gNjmNCE7AhcO2C6LNUD4nInRiic3UQ8 B+6w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=5qeFL4aGiz4VFRECgb8oorsdrovpNi4/WsaBAAfE8/g=; fh=mTvjTqym02yeN0tlAPLrMKgv4tfcsXLZmOUHn1dWpO8=; b=rPU4Ud+Mf+nPPbGnr4G1ZKVPhkI99KiTe1rXjGCZS87jG94jn1Pyr/5TwzZUdz+QS0 e71LA+gj2G4h7mJrt66PwoCCYgDrEEIE/eqeH2CUzUfzG8ElchzjtGA8b1MwlpPr4rgI 9POQmptyImkSNBjeYCDGhkb3XvyUroK4MaKBInmpsxO6O7AXcLzzv8W5za6oljJBEX8Z MELRtYNT43BEtH8R5vOlfwlD5LL4A33qC0i75BU+xXZq8UJnsFbfvcnnKSBd0CLekZ18 3FRtm9WoA7BTmqnplWtl4F+wxNExkJ5/ihX1mp4pCAU/JEQDlC24TxzfKW4hhoJ/jepw yGGQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fgRVLta2; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45454-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45454-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cs12-20020a0564020c4c00b0055a4e60f287si5238705edb.495.2024.01.30.15.15.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:15:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45454-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fgRVLta2; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45454-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45454-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5DAE21F24FEB for ; Tue, 30 Jan 2024 23:15:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94ABA80BFA; Tue, 30 Jan 2024 23:14:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fgRVLta2" Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A3F779959; Tue, 30 Jan 2024 23:14:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656457; cv=none; b=Oa7bvYB5rr7/Let7jRndPqyQ3hjBLygY6fCX+JJXGPQu/6jOeVjRxm14imqOsLrm0MGjfa5a71gbTeLLAZ89z3f+4ZrO7JPT2kwwSbAyieqI0iWuR5+AN7djI59DB5PUKqHcuxDz2ka7KqioQzi6Iti2arO9rcK+ZaP1ry6qnuI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656457; c=relaxed/simple; bh=S5obDCnGvS5TS91erx2GSsdEW9PcBn5bVY35DeZVlyI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=n6TlSuExfaBWWm6iIYKRd2xxwmU/xmIuo7RJSn8RP11WDQnIRjAIAlMadvmeJLF10PGXqwyJj2Fvo6A3wckS1TBFUr2lBbfaHOSCv74qcxZ9K5e90pOTUI/kGKfrYRyoZcZrM/Db3kRoYI2zIlxkloHO/wXMC4RopwQC9COPZRg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fgRVLta2; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1d911c9240dso8324015ad.2; Tue, 30 Jan 2024 15:14:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706656455; x=1707261255; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=5qeFL4aGiz4VFRECgb8oorsdrovpNi4/WsaBAAfE8/g=; b=fgRVLta2OfchmJGyRtjI/yFeHo8As+khBv3UPWxPHlDnu8eDUO8vWEgXwGQ+vpPW8z d0BOx7/QSq5JZiLt+hxal383QsHDPUNe+o3WNzd/HqS9pP4LzY/EtX3qDSh0qpq5Lf5M +UswaEqyldr3wszZbpC/LpFSeFPniIaTP5rK31CVc6Fn4WV+6pwNgJHrD8gsiPaXC4ha EO3Zyla/UWF2EWKqZwmePfUGRYhihm5JSJ5RdegEexfHtmxaz0rNyzahf31cNiGUeJJ/ GT+eOTNf7IJWHeD05qp7WQvrAUdg0zM3jMW7mYsAVVQkYvm4Zz3S8IhNheIES5IoKRQw trhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706656455; x=1707261255; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5qeFL4aGiz4VFRECgb8oorsdrovpNi4/WsaBAAfE8/g=; b=erHXknx0Y8mnGCuqsyNz/hXefp0n07wvr/I8S7ep9XBsbmC0eLwp2Awma+TSactV2S NfOQnYH/GqWNpSKgEkhkRMxgXB0CU3LDPE+ygyG3D6z6+r++PoIVv85VqmHXLXnppqDM w+aoWLwhqsBYLapVJ4uk0G20KDeLWXQVDDUwTte9gTjaXMJxEze/7zmlniVWuW26S9ib 6V0FQlYROy/l5RY+KOOYeAyhoagiDWSLMiT//BCZ8ZrzD47VnifOh7aENIOlUu37iArX aY7TS8jVhJ6IIyB/vqTBDLrbVTQ6ud8flsJ9XXnw8tE+h1s8rmjPTGvk+YdP68ha86FG Keow== X-Gm-Message-State: AOJu0YzrP+Xyz+uhEOfvopZ3JU8OK1aqGOiaSx9YtWyCmxdwhTzejJUX jXVfIefu0ajXcf2I8kudoASZWHCWHqBuP0JV4SbncEZ9HNOEngOf X-Received: by 2002:a17:902:6bcc:b0:1d9:21bc:c616 with SMTP id m12-20020a1709026bcc00b001d921bcc616mr50766plt.15.1706656454861; Tue, 30 Jan 2024 15:14:14 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:c:204:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id jx2-20020a170903138200b001d8f251c8b2sm3473203plb.221.2024.01.30.15.14.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:14:14 -0800 (PST) From: Luiz Angelo Daros de Luca Date: Tue, 30 Jan 2024 20:13:23 -0300 Subject: [PATCH net-next v5 04/11] net: dsa: realtek: keep variant reference in realtek_priv Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240130-realtek_reverse-v5-4-ecafd9283a07@gmail.com> References: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> In-Reply-To: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> To: Linus Walleij , =?utf-8?q?Alvin_=C5=A0ipraga?= , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luiz Angelo Daros de Luca , Florian Fainelli X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=3206; i=luizluca@gmail.com; h=from:subject:message-id; bh=S5obDCnGvS5TS91erx2GSsdEW9PcBn5bVY35DeZVlyI=; b=owEBbQGS/pANAwAIAbsR27rRBztWAcsmYgBluYKwQqpcjOshsLZV0YcKCTVx++oFT8946t5bv 8KcGNfrCQKJATMEAAEIAB0WIQQRByhHhc1bOhL6L/i7Edu60Qc7VgUCZbmCsAAKCRC7Edu60Qc7 VkIsCACdZ8sDZ+u0PxugFUdeC3M9qpdtZbAYrYtx9/jsTxOe0Ou0xsjPl37XC8wPLBeqkdZf9b1 sE1HNf6WTyyCIQmU7tYG+hhf0ChU9ZxW/EWHol3Udr0WF60sLwItujnVkydZVDjcrBa6Mkqp1f7 tJhh3EkFHwuGlb0cfOCrdHEUbdm2/NTAGkatR8mcoBXA+G239Nw4lT0eQnMsnZMSHmgN7K7acRi QcuU5HHEY8xdYW6IqH0XD/J/R7ZPqu4BugzWkfabZ2X34HQcLbXJjZ4YhbmTlGiggd1iqhfyOow LwS6tyHHoccbY0efOrpYBNROMb4VeCiLz+kkSCdCHO6lvY/0 X-Developer-Key: i=luizluca@gmail.com; a=openpgp; fpr=1107284785CD5B3A12FA2FF8BB11DBBAD1073B56 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789559094999229936 X-GMAIL-MSGID: 1789559094999229936 Instead of copying values from the variant, we can keep a reference in realtek_priv. This is a preliminary change for sharing code betwen interfaces. It will allow to move most of the probe into a common module while still allow code specific to each interface to read variant fields. Signed-off-by: Luiz Angelo Daros de Luca Reviewed-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- drivers/net/dsa/realtek/realtek-mdio.c | 4 +--- drivers/net/dsa/realtek/realtek-smi.c | 10 ++++------ drivers/net/dsa/realtek/realtek.h | 5 ++--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/net/dsa/realtek/realtek-mdio.c b/drivers/net/dsa/realtek/realtek-mdio.c index 3433f64fb0d7..5b78402b1683 100644 --- a/drivers/net/dsa/realtek/realtek-mdio.c +++ b/drivers/net/dsa/realtek/realtek-mdio.c @@ -196,9 +196,7 @@ int realtek_mdio_probe(struct mdio_device *mdiodev) 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->variant = var; priv->ops = var->ops; priv->write_reg_noack = realtek_mdio_write; diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index d8a9a6a6b5bc..147260f77d2f 100644 --- a/drivers/net/dsa/realtek/realtek-smi.c +++ b/drivers/net/dsa/realtek/realtek-smi.c @@ -46,7 +46,7 @@ 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 +209,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 +250,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; @@ -459,9 +459,7 @@ int realtek_smi_probe(struct platform_device *pdev) /* 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->variant = var; priv->ops = var->ops; priv->setup_interface = realtek_smi_setup_mdio; diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h index e9ee778665b2..c7d5ef99e9db 100644 --- a/drivers/net/dsa/realtek/realtek.h +++ b/drivers/net/dsa/realtek/realtek.h @@ -58,9 +58,8 @@ struct realtek_priv { struct mii_bus *bus; int mdio_addr; - unsigned int clk_delay; - u8 cmd_read; - u8 cmd_write; + const struct realtek_variant *variant; + spinlock_t lock; /* Locks around command writes */ struct dsa_switch *ds; struct irq_domain *irqdomain; From patchwork Tue Jan 30 23:13:24 2024 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: 194381 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1555197dyb; Tue, 30 Jan 2024 15:17:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVjhbjTfAviwIyEIRb8tonlwT7c2zQ8ConhrTVcrW+mI/OM8re/noHpFGJREpEWAjragFu X-Received: by 2002:a05:6a00:23d4:b0:6d9:b0cb:8cde with SMTP id g20-20020a056a0023d400b006d9b0cb8cdemr3045121pfc.18.1706656669905; Tue, 30 Jan 2024 15:17:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706656669; cv=pass; d=google.com; s=arc-20160816; b=IZWpdVdFFoB4VaeWuj0h2y0anwM6HTZsBCab/dytrqi+nHn7j8qvsO88xVJM8H0KFX sA/+k9LqhEusP7xnQKiD2HMQoBxf00u7UnNVCkK1FkG9L4MdNy7WTP+EZOfJZkBMyHvx Zo6/5xq7zFYXrZmLc4h2MYmXJ94hoIVSDyckp7VbL39qIEJ04Ddzqb+j49Hq8EhXwEjt Jz11Zf/PbQ9YxlLbOvntxqIHRrl2BYZg4FRS5FQIAHY6tLxqenqWqBnMYB/yHP+uP2S9 4XhllM6z6MDdOeOe4eeoOhrYpkjwcG5WQg8s0r8n/hjdGYPX/V3ZorYMTzhHByrvDlNB IWhg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=ikY+pjJX33DUmHYtNV5sfQVpXB3UCzlH5AZYzfIc5Jc=; fh=BU4RSkB+Q4EYbEXM8vpZ5rnbcSjfYSNW9lfntnZ9xiw=; b=rrn0CO4QAggNoElcJ9vIQ2lEXoEEKJStW5BfjuP5PhpgtubKn3F3DI0C+KO9cyY9xc riXgPYLHpEAA5fS55ajts/oEp1BjyNOiGZXRpsYxY8cNNGTivU/8sZuHCz4uHx5kFhc3 xiAkov8Q664ajmB7dp1x6KFYJlaDKr4xamRHQrKInoybasevaReeqCD9FpvPQkd8L+cE xghpJRVqQyFMe8J0FvT9RpuHQMejarl8rNqm/Qj6YMA4f7b5szoX8aEalXZ8mTtrAMre xhnvoatQs511FK/jbudlee7UDqFKYUoK+aAFvUaAwTR2bBDmgKCE/j0eGu50SoukSAcg WwPw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=c9GgPyVy; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45455-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45455-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q19-20020a62ae13000000b006d9a6d5737dsi8232959pff.91.2024.01.30.15.17.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:17:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45455-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=c9GgPyVy; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45455-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45455-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 999ABB24C69 for ; Tue, 30 Jan 2024 23:16:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B1DD97AE58; Tue, 30 Jan 2024 23:14:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c9GgPyVy" Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 940D180BF2; Tue, 30 Jan 2024 23:14:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656462; cv=none; b=FAosK6K3RSi1vQMLXzz5jgudQ+3up6uViq+7rmYBFbNx7O0N6ZptjN3SMPDeNzW0zWjF/cvDXxA4N7w5rS3vtwB2i/lV5ETe6S9Qr6yHxnjArpFBIzV5Ao+/TYP1ch4zDh80TgJJlPPUgIIXKZpmJlOGC54uKssRCVyWJHR8TGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656462; c=relaxed/simple; bh=T9f8fNfHr8hRR+OUVVZ5NRn5CpIYhFPJ14DBghd07tQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hQa/xnfC7BO93LO31ce3yrv7ivYZepnjGgf7jQ8aCltRcYSoh7abThtNfIVp91nVj4OJYF1WegXHiEh6p1NyFZ7e6EirVrmGKMgP3V6RlS7S/M4m0YAPmc+DGq3xRsa5DW4lVp2dpVlyK/bZS1hwoEjoo0cId3o2BhUOY1SEwIw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c9GgPyVy; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1d911dac3dcso2409055ad.0; Tue, 30 Jan 2024 15:14:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706656460; x=1707261260; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ikY+pjJX33DUmHYtNV5sfQVpXB3UCzlH5AZYzfIc5Jc=; b=c9GgPyVyn59sWOr9w1QGg6Xsq2S5gMxwc8IAQ33bvh7+iaTIEruCS39Wf+eppt6GW3 H+feyVVbwsHIwZvWtZxknaAA9zbLGJyNyQS5WFN0a9/G9+Adqg0XhyiGNKTs5LpPtrnx YVFsVVaF8prgbCFKfAsg/hMBthFAZz2wXvttYdlhV5rJbXXoxJ6rRT8V/Y93V7N6B/mq 05haT7/Q5t58xPF4x8FPb18uSpGXBug2RjdnKFI+pwx8xg7iqkQxy4uu4zdl2BTZKL+5 MBSnASe9aHDVKGDES/413gy7T1Sye8VcFRxuDDsiETPL144aXmW2hdFaze1LMpLyHS7Y Ifwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706656460; x=1707261260; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ikY+pjJX33DUmHYtNV5sfQVpXB3UCzlH5AZYzfIc5Jc=; b=lHF87O65VNGHk5Gt9T3oFPbhg0w7pebLQ3KZ/qlWslNb2pBHL8OxOt56/d1AfhyCSQ zOhSvDTOgE8pKq1OoYHyPQQiEG0G5jILPhLq3m6aNfBLCa/dXnX0Xz1Y+wjywyRfK9Zn LJF382ZvjSpjBTvEKIfLGdHnVJWpgM615hOT6GrE95YPKFitgA7RsjHUonRByMKOwhjz Fe0PXiH+fuU3LnXEWB+ge1Pr44sqhpgXy2+3uHm8xDkDGjzca0SNdQY2LYqAxL4HPqPQ EywnWuHgGUnflymGO/4792K6xWPqEEmwwb9USXDLpCJ+zNoRFbl+rwhbxSr3pOP0vh00 BG2A== X-Gm-Message-State: AOJu0Yyitnl22xm1X1hDMi0B+vbfeJS1ofsR6marZx536PqZCnwnQ9RN 4DnYPisCavjB5yvHA5Sk3biO9NpQeCChIcyDULspGlHNwR+XClycOEBJe7NCMWI= X-Received: by 2002:a17:902:6b89:b0:1d8:f977:4159 with SMTP id p9-20020a1709026b8900b001d8f9774159mr2515110plk.4.1706656459648; Tue, 30 Jan 2024 15:14:19 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:c:204:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id jx2-20020a170903138200b001d8f251c8b2sm3473203plb.221.2024.01.30.15.14.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:14:18 -0800 (PST) From: Luiz Angelo Daros de Luca Date: Tue, 30 Jan 2024 20:13:24 -0300 Subject: [PATCH net-next v5 05/11] net: dsa: realtek: common rtl83xx module Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240130-realtek_reverse-v5-5-ecafd9283a07@gmail.com> References: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> In-Reply-To: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> To: Linus Walleij , =?utf-8?q?Alvin_=C5=A0ipraga?= , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luiz Angelo Daros de Luca X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=26907; i=luizluca@gmail.com; h=from:subject:message-id; bh=T9f8fNfHr8hRR+OUVVZ5NRn5CpIYhFPJ14DBghd07tQ=; b=owEBbQGS/pANAwAIAbsR27rRBztWAcsmYgBluYKwSKVZEvE4HbUlR3J/oynnjL7Zyfk6wOB7a p6o8xEYmTCJATMEAAEIAB0WIQQRByhHhc1bOhL6L/i7Edu60Qc7VgUCZbmCsAAKCRC7Edu60Qc7 VmWwB/90sbe9tiynx9M8jrf5XKsJLLzpIIT++i8lR0MaxlSFLlQxJTpgZGtnOKgT2at8YvRjqU9 LfRMO+wYBOUmI3ucjBB5oTXwF6r0AvqY0IGpM12Kgln8xpS0dl9SdRIbxB/uCwZjbnOMCG3JA/m dcERJboorDHJkqsIFvniJUkCLTasUK+PywE5lDgfWgJ295PhdPXMF6Y8CNuRnNp+99SDs0NPdbS jv/ekTK+aE41Eq3SM0EaCLAFjsYAMmaYHh5PxtlEW4bH6RBv+I5+suZ+LScj9qQ1q97wP0UnwQS Gbig+qB1Gm2uhCaIJsJ/vAvf4j/G/VZ9/dLQVrnZpVgp6lzO X-Developer-Key: i=luizluca@gmail.com; a=openpgp; fpr=1107284785CD5B3A12FA2FF8BB11DBBAD1073B56 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789559224583729880 X-GMAIL-MSGID: 1789559224583729880 Some code can be shared between both interface modules (MDIO and SMI) and among variants. These interface functions migrated to a common module: - rtl83xx_lock - rtl83xx_unlock - rtl83xx_probe - rtl83xx_register_switch - rtl83xx_unregister_switch - rtl83xx_shutdown - rtl83xx_remove The reset during probe was moved to the end of the common probe. This way, we avoid a reset if anything else fails. Signed-off-by: Luiz Angelo Daros de Luca --- drivers/net/dsa/realtek/Makefile | 2 + drivers/net/dsa/realtek/realtek-mdio.c | 154 +++------------------- drivers/net/dsa/realtek/realtek-smi.c | 160 ++++------------------ drivers/net/dsa/realtek/realtek.h | 1 + drivers/net/dsa/realtek/rtl8365mb.c | 9 +- drivers/net/dsa/realtek/rtl8366rb.c | 9 +- drivers/net/dsa/realtek/rtl83xx.c | 233 +++++++++++++++++++++++++++++++++ drivers/net/dsa/realtek/rtl83xx.h | 21 +++ 8 files changed, 314 insertions(+), 275 deletions(-) diff --git a/drivers/net/dsa/realtek/Makefile b/drivers/net/dsa/realtek/Makefile index 0aab57252a7c..67b5ee1c43a9 100644 --- a/drivers/net/dsa/realtek/Makefile +++ b/drivers/net/dsa/realtek/Makefile @@ -1,4 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_NET_DSA_REALTEK) += realtek-dsa.o +realtek-dsa-objs := rtl83xx.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-mdio.c b/drivers/net/dsa/realtek/realtek-mdio.c index 5b78402b1683..7cbce3e893e1 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 "rtl83xx.h" /* Read/write via mdiobus */ #define REALTEK_MDIO_CTRL0_REG 31 @@ -100,149 +101,41 @@ 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, - .reg_stride = 1, - /* PHY regs are at 0x8000 */ - .max_register = 0xffff, - .reg_format_endian = REGMAP_ENDIAN_BIG, - .reg_read = realtek_mdio_read, - .reg_write = realtek_mdio_write, - .cache_type = REGCACHE_NONE, - .lock = realtek_mdio_lock, - .unlock = realtek_mdio_unlock, -}; - -static const struct regmap_config realtek_mdio_nolock_regmap_config = { - .reg_bits = 10, /* A4..A0 R4..R0 */ - .val_bits = 16, - .reg_stride = 1, - /* PHY regs are at 0x8000 */ - .max_register = 0xffff, - .reg_format_endian = REGMAP_ENDIAN_BIG, +static const struct realtek_interface_info realtek_mdio_info = { .reg_read = realtek_mdio_read, .reg_write = realtek_mdio_write, - .cache_type = REGCACHE_NONE, - .disable_locking = true, }; /** * realtek_mdio_probe() - Probe a platform device for an MDIO-connected switch * @mdiodev: mdio_device to probe on. * - * This function should be used as the .probe in an mdio_driver. It - * initializes realtek_priv and read data from the device-tree node. The switch - * is hard resetted if a method is provided. It checks the switch chip ID and, - * finally, a DSA switch is registered. + * This function should be used as the .probe in an mdio_driver. After + * calling the common probe function for both interfaces, it initializes the + * values specific for MDIO-connected devices. Finally, it calls a common + * function to register the DSA switch. * * Context: Can sleep. Takes and releases priv->map_lock. * Return: Returns 0 on success, a negative error on failure. */ 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; + struct realtek_priv *priv; 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; - } - - 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 = rtl83xx_probe(dev, &realtek_mdio_info); + 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->variant = var; - 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); + ret = rtl83xx_register_switch(priv); + if (ret) return ret; - } return 0; } @@ -253,8 +146,7 @@ EXPORT_SYMBOL_NS_GPL(realtek_mdio_probe, REALTEK_DSA); * @mdiodev: mdio_device to be removed. * * This function should be used as the .remove_new in an mdio_driver. First - * it unregisters the DSA switch and cleans internal data. If a method is - * provided, the hard reset is asserted to avoid traffic leakage. + * it unregisters the DSA switch and then it calls the common remove function. * * Context: Can sleep. * Return: Nothing. @@ -266,11 +158,9 @@ void realtek_mdio_remove(struct mdio_device *mdiodev) if (!priv) return; - dsa_unregister_switch(priv->ds); + rtl83xx_unregister_switch(priv); - /* leave the device reset asserted */ - if (priv->reset) - gpiod_set_value(priv->reset, 1); + rtl83xx_remove(priv); } EXPORT_SYMBOL_NS_GPL(realtek_mdio_remove, REALTEK_DSA); @@ -278,10 +168,8 @@ EXPORT_SYMBOL_NS_GPL(realtek_mdio_remove, REALTEK_DSA); * realtek_mdio_shutdown() - Shutdown the driver of a MDIO-connected switch * @mdiodev: mdio_device shutting down. * - * This function should be used as the .shutdown in an mdio_driver. It shuts - * down the DSA switch and cleans the platform driver data, to prevent - * realtek_mdio_remove() from running afterwards, which is possible if the - * parent bus implements its own .shutdown() as .remove(). + * This function should be used as the .shutdown in a platform_driver. It calls + * the common shutdown function. * * Context: Can sleep. * Return: Nothing. @@ -293,9 +181,7 @@ void realtek_mdio_shutdown(struct mdio_device *mdiodev) if (!priv) return; - dsa_switch_shutdown(priv->ds); - - dev_set_drvdata(&mdiodev->dev, NULL); + rtl83xx_shutdown(priv); } EXPORT_SYMBOL_NS_GPL(realtek_mdio_shutdown, REALTEK_DSA); diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index 147260f77d2f..ffa68272d0d4 100644 --- a/drivers/net/dsa/realtek/realtek-smi.c +++ b/drivers/net/dsa/realtek/realtek-smi.c @@ -41,6 +41,7 @@ #include "realtek.h" #include "realtek-smi.h" +#include "rtl83xx.h" #define REALTEK_SMI_ACK_RETRY_COUNT 5 @@ -311,47 +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, - .reg_stride = 1, - /* PHY regs are at 0x8000 */ - .max_register = 0xffff, - .reg_format_endian = REGMAP_ENDIAN_BIG, - .reg_read = realtek_smi_read, - .reg_write = realtek_smi_write, - .cache_type = REGCACHE_NONE, - .lock = realtek_smi_lock, - .unlock = realtek_smi_unlock, -}; - -static const struct regmap_config realtek_smi_nolock_regmap_config = { - .reg_bits = 10, /* A4..A0 R4..R0 */ - .val_bits = 16, - .reg_stride = 1, - /* PHY regs are at 0x8000 */ - .max_register = 0xffff, - .reg_format_endian = REGMAP_ENDIAN_BIG, - .reg_read = realtek_smi_read, - .reg_write = realtek_smi_write, - .cache_type = REGCACHE_NONE, - .disable_locking = true, -}; - static int realtek_smi_mdio_read(struct mii_bus *bus, int addr, int regnum) { struct realtek_priv *priv = bus->priv; @@ -409,111 +369,50 @@ static int realtek_smi_setup_mdio(struct dsa_switch *ds) return ret; } +static const struct realtek_interface_info realtek_smi_info = { + .reg_read = realtek_smi_read, + .reg_write = realtek_smi_write, +}; + /** * realtek_smi_probe() - Probe a platform device for an SMI-connected switch * @pdev: platform_device to probe on. * - * This function should be used as the .probe in a platform_driver. It - * initializes realtek_priv and read data from the device-tree node. The switch - * is hard resetted if a method is provided. It checks the switch chip ID and, - * finally, a DSA switch is registered. + * This function should be used as the .probe in a platform_driver. After + * calling the common probe function for both interfaces, it initializes the + * values specific for SMI-connected devices. Finally, it calls a common + * function to register the DSA switch. * * Context: Can sleep. Takes and releases priv->map_lock. * Return: Returns 0 on success, a negative error on failure. */ 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->variant = var; - 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 = rtl83xx_probe(dev, &realtek_smi_info); + 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"); + priv->write_reg_noack = realtek_smi_write_reg_noack; + priv->setup_interface = realtek_smi_setup_mdio; + priv->ds_ops = priv->variant->ds_ops_smi; - ret = priv->ops->detect(priv); - if (ret) { - dev_err(dev, "unable to detect switch\n"); + ret = rtl83xx_register_switch(priv); + if (ret) 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_smi; - ret = dsa_register_switch(priv->ds); - if (ret) { - dev_err_probe(dev, ret, "unable to register switch\n"); - return ret; - } return 0; } EXPORT_SYMBOL_NS_GPL(realtek_smi_probe, REALTEK_DSA); @@ -523,8 +422,8 @@ EXPORT_SYMBOL_NS_GPL(realtek_smi_probe, REALTEK_DSA); * @pdev: platform_device to be removed. * * This function should be used as the .remove_new in a platform_driver. First - * it unregisters the DSA switch and cleans internal data. If a method is - * provided, the hard reset is asserted to avoid traffic leakage. + * it unregisters the DSA switch and cleans internal data. Finally, it calls + * the common remove function. * * Context: Can sleep. * Return: Nothing. @@ -536,13 +435,12 @@ void realtek_smi_remove(struct platform_device *pdev) if (!priv) return; - dsa_unregister_switch(priv->ds); + rtl83xx_unregister_switch(priv); + if (priv->user_mii_bus) of_node_put(priv->user_mii_bus->dev.of_node); - /* leave the device reset asserted */ - if (priv->reset) - gpiod_set_value(priv->reset, 1); + rtl83xx_remove(priv); } EXPORT_SYMBOL_NS_GPL(realtek_smi_remove, REALTEK_DSA); @@ -550,10 +448,8 @@ EXPORT_SYMBOL_NS_GPL(realtek_smi_remove, REALTEK_DSA); * realtek_smi_shutdown() - Shutdown the driver of a SMI-connected switch * @pdev: platform_device shutting down. * - * This function should be used as the .shutdown in a platform_driver. It shuts - * down the DSA switch and cleans the platform driver data, to prevent - * realtek_smi_remove() from running afterwards, which is possible if the - * parent bus implements its own .shutdown() as .remove(). + * This function should be used as the .shutdown in a platform_driver. It calls + * the common shutdown function. * * Context: Can sleep. * Return: Nothing. @@ -565,9 +461,7 @@ void realtek_smi_shutdown(struct platform_device *pdev) if (!priv) return; - dsa_switch_shutdown(priv->ds); - - platform_set_drvdata(pdev, NULL); + rtl83xx_shutdown(priv); } EXPORT_SYMBOL_NS_GPL(realtek_smi_shutdown, REALTEK_DSA); diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h index c7d5ef99e9db..e9e28b189509 100644 --- a/drivers/net/dsa/realtek/realtek.h +++ b/drivers/net/dsa/realtek/realtek.h @@ -62,6 +62,7 @@ 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; diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/rtl8365mb.c index e67c4562f5db..60f826a5a00a 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 "rtl83xx.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); + rtl83xx_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); + rtl83xx_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); + rtl83xx_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); + rtl83xx_unlock(priv); return 0; } diff --git a/drivers/net/dsa/realtek/rtl8366rb.c b/drivers/net/dsa/realtek/rtl8366rb.c index 747407ae8225..a0c365325b4a 100644 --- a/drivers/net/dsa/realtek/rtl8366rb.c +++ b/drivers/net/dsa/realtek/rtl8366rb.c @@ -25,6 +25,7 @@ #include "realtek.h" #include "realtek-smi.h" #include "realtek-mdio.h" +#include "rtl83xx.h" #define RTL8366RB_PORT_NUM_CPU 5 #define RTL8366RB_NUM_PORTS 6 @@ -1720,7 +1721,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); + rtl83xx_lock(priv); ret = regmap_write(priv->map_nolock, RTL8366RB_PHY_ACCESS_CTRL_REG, RTL8366RB_PHY_CTRL_READ); @@ -1748,7 +1749,7 @@ static int rtl8366rb_phy_read(struct realtek_priv *priv, int phy, int regnum) phy, regnum, reg, val); out: - mutex_unlock(&priv->map_lock); + rtl83xx_unlock(priv); return ret; } @@ -1762,7 +1763,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); + rtl83xx_lock(priv); ret = regmap_write(priv->map_nolock, RTL8366RB_PHY_ACCESS_CTRL_REG, RTL8366RB_PHY_CTRL_WRITE); @@ -1779,7 +1780,7 @@ static int rtl8366rb_phy_write(struct realtek_priv *priv, int phy, int regnum, goto out; out: - mutex_unlock(&priv->map_lock); + rtl83xx_unlock(priv); return ret; } diff --git a/drivers/net/dsa/realtek/rtl83xx.c b/drivers/net/dsa/realtek/rtl83xx.c new file mode 100644 index 000000000000..702ee0d40b0b --- /dev/null +++ b/drivers/net/dsa/realtek/rtl83xx.c @@ -0,0 +1,233 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include + +#include "realtek.h" +#include "rtl83xx.h" + +/** + * rtl83xx_lock() - Locks the mutex used by regmaps + * @ctx: realtek_priv pointer + * + * This function is passed to regmap to be used as the lock function. + * It is also used externally to block regmap before executing multiple + * operations that must happen in sequence (which will use + * realtek_priv.map_nolock instead). + * + * Context: Can sleep. Holds priv->map_lock lock. + * Return: nothing + */ +void rtl83xx_lock(void *ctx) +{ + struct realtek_priv *priv = ctx; + + mutex_lock(&priv->map_lock); +} +EXPORT_SYMBOL_NS_GPL(rtl83xx_lock, REALTEK_DSA); + +/** + * rtl83xx_unlock() - Unlocks the mutex used by regmaps + * @ctx: realtek_priv pointer + * + * This function unlocks the lock acquired by rtl83xx_lock. + * + * Context: Releases priv->map_lock lock. + * Return: nothing + */ +void rtl83xx_unlock(void *ctx) +{ + struct realtek_priv *priv = ctx; + + mutex_unlock(&priv->map_lock); +} +EXPORT_SYMBOL_NS_GPL(rtl83xx_unlock, REALTEK_DSA); + +/** + * rtl83xx_probe() - probe a Realtek switch + * @dev: the device being probed + * @interface_info: specific management interface info. + * + * This function initializes realtek_priv and reads data from the device tree + * node. The switch is hard resetted if a method is provided. + * + * Context: Can sleep. + * Return: Pointer to the realtek_priv or ERR_PTR() in case of failure. + * + * The realtek_priv pointer does not need to be freed as it is controlled by + * devres. + */ +struct realtek_priv * +rtl83xx_probe(struct device *dev, + const struct realtek_interface_info *interface_info) +{ + const struct realtek_variant *var; + struct realtek_priv *priv; + struct regmap_config rc = { + .reg_bits = 10, /* A4..A0 R4..R0 */ + .val_bits = 16, + .reg_stride = 1, + .max_register = 0xffff, + .reg_format_endian = REGMAP_ENDIAN_BIG, + .reg_read = interface_info->reg_read, + .reg_write = interface_info->reg_write, + .cache_type = REGCACHE_NONE, + .lock = rtl83xx_lock, + .unlock = rtl83xx_unlock, + }; + 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); + } + + rc.disable_locking = true; + 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 ERR_PTR(ret); + } + + /* Link forward and backward */ + priv->dev = dev; + priv->variant = var; + priv->ops = var->ops; + priv->chip_data = (void *)priv + sizeof(*priv); + + spin_lock_init(&priv->lock); + + priv->leds_disabled = of_property_read_bool(dev->of_node, + "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); + } + + dev_set_drvdata(dev, priv); + + 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_NS_GPL(rtl83xx_probe, REALTEK_DSA); + +/** + * rtl83xx_register_switch() - detects and register a switch + * @priv: realtek_priv pointer + * + * This function first checks the switch chip ID and register a DSA + * switch. + * + * Context: Can sleep. Takes and releases priv->map_lock. + * Return: 0 on success, negative value for failure. + */ +int rtl83xx_register_switch(struct realtek_priv *priv) +{ + int ret; + + ret = priv->ops->detect(priv); + if (ret) { + dev_err_probe(priv->dev, ret, "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_NS_GPL(rtl83xx_register_switch, REALTEK_DSA); + +/** + * rtl83xx_unregister_switch() - unregister a switch + * @priv: realtek_priv pointer + * + * This function unregister a DSA switch. + * + * Context: Can sleep. + * Return: Nothing. + */ +void rtl83xx_unregister_switch(struct realtek_priv *priv) +{ + dsa_unregister_switch(priv->ds); +} +EXPORT_SYMBOL_NS_GPL(rtl83xx_unregister_switch, REALTEK_DSA); + +/** + * rtl83xx_shutdown() - shutdown a switch + * @priv: realtek_priv pointer + * + * This function shuts down the DSA switch and cleans the platform driver data, + * to prevent realtek_{smi,mdio}_remove() from running afterwards, which is + * possible if the parent bus implements its own .shutdown() as .remove(). + * + * Context: Can sleep. + * Return: Nothing. + */ +void rtl83xx_shutdown(struct realtek_priv *priv) +{ + dsa_switch_shutdown(priv->ds); + + dev_set_drvdata(priv->dev, NULL); +} +EXPORT_SYMBOL_NS_GPL(rtl83xx_shutdown, REALTEK_DSA); + +/** + * rtl83xx_remove() - Cleanup a realtek switch driver + * @priv: realtek_priv pointer + * + * If a method is provided, this function asserts the hard reset of the switch + * in order to avoid leaking traffic when the driver is gone. + * + * Context: Might sleep if priv->gdev->chip->can_sleep. + * Return: nothing + */ +void rtl83xx_remove(struct realtek_priv *priv) +{ + /* leave the device reset asserted */ + if (priv->reset) + gpiod_set_value(priv->reset, 1); +} +EXPORT_SYMBOL_NS_GPL(rtl83xx_remove, REALTEK_DSA); + +MODULE_AUTHOR("Luiz Angelo Daros de Luca "); +MODULE_DESCRIPTION("Realtek DSA switches common module"); +MODULE_LICENSE("GPL"); diff --git a/drivers/net/dsa/realtek/rtl83xx.h b/drivers/net/dsa/realtek/rtl83xx.h new file mode 100644 index 000000000000..a8eed92bce1a --- /dev/null +++ b/drivers/net/dsa/realtek/rtl83xx.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef _RTL83XX_H +#define _RTL83XX_H + +struct realtek_interface_info { + int (*reg_read)(void *ctx, u32 reg, u32 *val); + int (*reg_write)(void *ctx, u32 reg, u32 val); +}; + +void rtl83xx_lock(void *ctx); +void rtl83xx_unlock(void *ctx); +struct realtek_priv * +rtl83xx_probe(struct device *dev, + const struct realtek_interface_info *interface_info); +int rtl83xx_register_switch(struct realtek_priv *priv); +void rtl83xx_unregister_switch(struct realtek_priv *priv); +void rtl83xx_shutdown(struct realtek_priv *priv); +void rtl83xx_remove(struct realtek_priv *priv); + +#endif /* _RTL83XX_H */ From patchwork Tue Jan 30 23:13:25 2024 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: 194379 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1554491dyb; Tue, 30 Jan 2024 15:16:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPFOfNr7KNN3PQF3hHiX96WXhmzEzb61Y4mqIVKCG1OBKhmsVSVJWVSYE5wZwx3edragcz X-Received: by 2002:a05:6214:c6e:b0:68c:46c0:b8f5 with SMTP id t14-20020a0562140c6e00b0068c46c0b8f5mr7294277qvj.64.1706656580615; Tue, 30 Jan 2024 15:16:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706656580; cv=pass; d=google.com; s=arc-20160816; b=HfN2ucSjOMuGNG39Nl/3YWc8D3+WlNNyMKxk7A5OpfEpJ9ITEmTxBJA1HELVEuchAG ZXuXRh6rPOsicRouJBgMOfn/eH2bq6eauixyerjK7cakbQ7AUHaSQlR6KB3VY7wMW6XR EzhYbRTPUOC6TJQO4E2WUNaVs10ETW/DL9v+hPYqF6oICa8gGJQ3142Jl3CVoN/PrCPg 0QoWPPslMjXDTu6Y8WrQrI7fyahuLq0sOd3rlF6wgTPNdVEWUd5K2TZhWH90qq6UBRsJ 0SHjAS7pb52WTc8AZzZueNhUegA+xTpLvcCTayLCIZ8v7B4SOAF5biBF+YIrg2AO4Cwi Jpzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=RFmiP8u0XylO+2YgibNLkampEImJxL5ecq2MK58dcw0=; fh=TCcLf7EavSIkIIsiG21rrKuZThVnfTIr5SNowV4EQGY=; b=vSeKhBwNW9u/6InBN+2MEWitIKUQsVB2sF7OE3gi2MZaHrmMW/1rOwkGZX1liZSpDt pfpkoNUFZNYNqZ++y+HhHprUnl+x2OCUmCJY0bfiieI/d10ys0+IakH28Rf/ajOl7isT JIu8IKtsGrpPifXBMXv25p3GZdiKJGcDb0BfCuhz0LLiCvZXG8wfyZ79BzUXck331TEs T07H4gXKCvFf61aXsN93mow7zZqouy4WHtj3W2Tz9avAxjrIfNY0Q/2BrxewYUq/znhk cGI6DO9wQrXx0wTgnZolFxlv3ACVgnNXqaF1cTWGu9wkGaTRE1AyEALFKPW87xb0ze0X yT8Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bQe58B2g; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45456-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45456-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCVMuM9v4vdpprycuE7H0bncSFnsZaFiZRNcDuDt9Si3eiA+ATP6A/CIFI9nXoi+9op/2rlK3EuMMueCVn1YIeS/VlaJRQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e9-20020a0562141d0900b0068c6b1ffc9bsi342684qvd.254.2024.01.30.15.16.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:16:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45456-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bQe58B2g; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45456-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45456-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5B5FC1C214D1 for ; Tue, 30 Jan 2024 23:16:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E7718286F; Tue, 30 Jan 2024 23:14:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bQe58B2g" Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8577D80C05; Tue, 30 Jan 2024 23:14:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656466; cv=none; b=kM7Asg8vw+uzLWQ2krMxmasKTylpq4yBpFOFsowuNLCkKLDpAN0/TqZlBa9L5eMg0CYhcfuBefxnzJFXHR/rwnSNeTTZHfPkxrbvtbjX32+eJD7/Py2XAP09mgPLi0hwjTDTm1JrttVdrzQIqSsVA+ZpqYX0dkiMec0CFwZPxlM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656466; c=relaxed/simple; bh=O9Z0K/in+V/0Sg8kYoxYiAta8TGB/5GvVdjlD41NHi4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZAjIuc3m0V4J4ScEJTnhOoPJ7p4BFyhKj/+BTWvUkVXQOII7IAiwTJGvT1pvah6Cq0H4XiTEK6a2OUQVdntYiljr/ef2KWfa0gp0V5fpvCd7pghDZ463yXPv+SNv4Vf3Hrdy07S+oqvp4zGiqzvt3U3OWOkSE3U2bnBXfzuLcYw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bQe58B2g; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1d751bc0c15so38780395ad.2; Tue, 30 Jan 2024 15:14:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706656464; x=1707261264; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=RFmiP8u0XylO+2YgibNLkampEImJxL5ecq2MK58dcw0=; b=bQe58B2gRzgtrK/IoIl7R44LIVaXm6rA2fjGIryAOa2JDkYkaYRiz9RJ4RJj2ymNUq irOHKNCi2FEuIbT89fmDrYVHzgp1ltuQ+0qcY/SFaLPlF3GNmbUN8ghRzOGwzL1yQElT Ldfdo5wwiUASerA3Nn9IWEzCSVOeMJJoXCWt6G71Wap5xM87gMzsYsan70xXnRldSj00 Iea1SBi64U/qbrJVFFyozxav2FnAApzVXVN1VxzAHZz3dMiN7dXGpPq3eLZcBBcVv17w AY3xdbaMLtzr+DZLk96WbBewTuu3pR8juFhWOqVkLUqVVZ93pI6EB/ZQPUD60MwJN0hj QWMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706656464; x=1707261264; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RFmiP8u0XylO+2YgibNLkampEImJxL5ecq2MK58dcw0=; b=pOiP0kuCNUQCJEDwfPBR5eilwzmU8V8L9qlLhHL1VeE55ZIe+kBmHrS28V06rZ7rOV 9JOceXGKqrNui8TFXGjVeRQNjZukwbU5QQzCY+89qlw3MkpjTqk7j5lVohxHLOSWGYIB QRCWs7V6wyCcKCkA1YyijCNYJdVwnHh/S9cJfImTM5Ui2wlYJoqvlprmSK2S74of40y/ LNJKk7o9w/CAC/jUR8o8Y0IyIVfkOIJIzjCunD0UaslLzLqXm68nVyWllx+G4lZnQPS9 Te1jguqLZ4jY9S2aJU/7SH+yrigt6vVq/92v9N9yCvkOdzd9+zO+Ic9stLh1O2ajROnO AaSA== X-Gm-Message-State: AOJu0YyWF4UC4W4gDv/qK9q9gbBI4nD/jL0dRFHfpnZKEng1QCF34kMu 4gjizG2MpbHQ/dP1nth4RC5A/BTnFayw5Ph64QkRZETTSFUNzfSs X-Received: by 2002:a17:903:11cc:b0:1d8:ebdf:183a with SMTP id q12-20020a17090311cc00b001d8ebdf183amr80430plh.6.1706656463871; Tue, 30 Jan 2024 15:14:23 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:c:204:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id jx2-20020a170903138200b001d8f251c8b2sm3473203plb.221.2024.01.30.15.14.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:14:23 -0800 (PST) From: Luiz Angelo Daros de Luca Date: Tue, 30 Jan 2024 20:13:25 -0300 Subject: [PATCH net-next v5 06/11] net: dsa: realtek: merge rtl83xx and interface modules into realtek-dsa Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240130-realtek_reverse-v5-6-ecafd9283a07@gmail.com> References: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> In-Reply-To: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> To: Linus Walleij , =?utf-8?q?Alvin_=C5=A0ipraga?= , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luiz Angelo Daros de Luca , Florian Fainelli X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=3898; i=luizluca@gmail.com; h=from:subject:message-id; bh=O9Z0K/in+V/0Sg8kYoxYiAta8TGB/5GvVdjlD41NHi4=; b=owEBbQGS/pANAwAIAbsR27rRBztWAcsmYgBluYKxF8R4opkUW6HN6uV0Nens8pcKQvtDrelMM MAsQSccR9CJATMEAAEIAB0WIQQRByhHhc1bOhL6L/i7Edu60Qc7VgUCZbmCsQAKCRC7Edu60Qc7 VpjIB/9s7c9o2n3On29AW5hEBVabaguN1eI0gdan+JynoEAYTLsjy1jX8dLLQUzii91j6xBuQH4 Nbs7e35EA+BXFrOx/80R2frlIX4ADz6kzy8D9oK8TUCClDHpDliTy7q9X6KBBFBX3aYZGCDycwy 1bzYU6h8l236jjens+/qhye7A9kkNRkEc2r6UZbED9MkFpag5LFpaovzogoPe/EvTdHJr7z1eHP Utzwm8BGokEGezUMUBht+uwDuv0agxKV46zhrom9gLgMZnnN7YDlQ4QrXPDapN57b9RQpjsqYmS PEUAv6B0nyitR6hr/Gz+qlSS4rFuarn6126UyPNqwqHRlx1l X-Developer-Key: i=luizluca@gmail.com; a=openpgp; fpr=1107284785CD5B3A12FA2FF8BB11DBBAD1073B56 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789559130513039735 X-GMAIL-MSGID: 1789559130513039735 Since rtl83xx and realtek-{smi,mdio} are always loaded together, we can optimize resource usage by consolidating them into a single module. Signed-off-by: Luiz Angelo Daros de Luca Reviewed-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- drivers/net/dsa/realtek/Kconfig | 4 ++-- drivers/net/dsa/realtek/Makefile | 11 +++++++++-- drivers/net/dsa/realtek/realtek-mdio.c | 5 ----- drivers/net/dsa/realtek/realtek-smi.c | 5 ----- drivers/net/dsa/realtek/rtl83xx.c | 1 + 5 files changed, 12 insertions(+), 14 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 67b5ee1c43a9..6ed6b4598d2e 100644 --- a/drivers/net/dsa/realtek/Makefile +++ b/drivers/net/dsa/realtek/Makefile @@ -1,8 +1,15 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_NET_DSA_REALTEK) += realtek-dsa.o realtek-dsa-objs := rtl83xx.o -obj-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o -obj-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o + +ifdef CONFIG_NET_DSA_REALTEK_MDIO +realtek-dsa-objs += realtek-mdio.o +endif + +ifdef CONFIG_NET_DSA_REALTEK_SMI +realtek-dsa-objs += realtek-smi.o +endif + 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-mdio.c b/drivers/net/dsa/realtek/realtek-mdio.c index 7cbce3e893e1..45d9ef43fe3d 100644 --- a/drivers/net/dsa/realtek/realtek-mdio.c +++ b/drivers/net/dsa/realtek/realtek-mdio.c @@ -184,8 +184,3 @@ void realtek_mdio_shutdown(struct mdio_device *mdiodev) rtl83xx_shutdown(priv); } EXPORT_SYMBOL_NS_GPL(realtek_mdio_shutdown, REALTEK_DSA); - -MODULE_AUTHOR("Luiz Angelo Daros de Luca "); -MODULE_DESCRIPTION("Driver for Realtek ethernet switch connected via MDIO interface"); -MODULE_LICENSE("GPL"); -MODULE_IMPORT_NS(REALTEK_DSA); diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index ffa68272d0d4..67bdad7ac910 100644 --- a/drivers/net/dsa/realtek/realtek-smi.c +++ b/drivers/net/dsa/realtek/realtek-smi.c @@ -464,8 +464,3 @@ void realtek_smi_shutdown(struct platform_device *pdev) rtl83xx_shutdown(priv); } EXPORT_SYMBOL_NS_GPL(realtek_smi_shutdown, REALTEK_DSA); - -MODULE_AUTHOR("Linus Walleij "); -MODULE_DESCRIPTION("Driver for Realtek ethernet switch connected via SMI interface"); -MODULE_LICENSE("GPL"); -MODULE_IMPORT_NS(REALTEK_DSA); diff --git a/drivers/net/dsa/realtek/rtl83xx.c b/drivers/net/dsa/realtek/rtl83xx.c index 702ee0d40b0b..fb3b3b2305d1 100644 --- a/drivers/net/dsa/realtek/rtl83xx.c +++ b/drivers/net/dsa/realtek/rtl83xx.c @@ -229,5 +229,6 @@ void rtl83xx_remove(struct realtek_priv *priv) EXPORT_SYMBOL_NS_GPL(rtl83xx_remove, REALTEK_DSA); MODULE_AUTHOR("Luiz Angelo Daros de Luca "); +MODULE_AUTHOR("Linus Walleij "); MODULE_DESCRIPTION("Realtek DSA switches common module"); MODULE_LICENSE("GPL"); From patchwork Tue Jan 30 23:13:27 2024 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: 194380 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1554889dyb; Tue, 30 Jan 2024 15:17:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqqvZLzw/Rx2VInHHtQclA7IR7ohE6oowCDapG4yhqxIO9t8es8/sObFjoSIMfurHWIvje X-Received: by 2002:ad4:5ba5:0:b0:68c:4f64:a122 with SMTP id 5-20020ad45ba5000000b0068c4f64a122mr52740qvq.6.1706656626642; Tue, 30 Jan 2024 15:17:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706656626; cv=pass; d=google.com; s=arc-20160816; b=astMO0zAIidKY/Q2IjIs1gx0aHnc5xHy1KirEnKzZ4Ca60Za+HHuBOAwytyf/d+fWq d/QF/XO/GO4Rv645HKn4Xxd0/mQCxX0STv9qkRnwanVkq/+JvknJsK0pCq1cstdgp354 9CFi6Q8dAnx+9am0npbnEujhRiQUo7dBjw9vxl4l3hQrZ0irKy5RL1PouLAw8mZH0Rya Dh9fC9oqQkasONRtjywURLdWyx4p7K7dFMFE+kky1dM2dzh/EDm22Sg26nPqrXTN5W0Y h1oUVxMK5EDJMJ+YXYgFROzL31CnIwjw+2mtvstfN10Lz4xX+wjwFEFj6+cImKg6WoJ0 Piww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=JzlkUZ88PnE68OAhgmXxQkn/nQs2BjH2k5xb3I1hQhI=; fh=BU4RSkB+Q4EYbEXM8vpZ5rnbcSjfYSNW9lfntnZ9xiw=; b=VR+AR6TmR0jhpop09t4GmvDXAW2yekMW9FCZCSesjFx3TXaemwjNQVC5F25HrA4bJm qasD1/cG4kAEOjJkeO0qhyUJG8Z93OUZPx7RQChc+a4M/gCTA9XKphQeVe3rNM3eIjJi oV+HPQKLPWqwHo2w0VmhlMjfWxxYF6qj5U2pE8Wtij7A6xV7Rv5Xid/jbJfQXNh7fFA9 scMIlQmjxGFnGGNLQRIVnUKp5gapxDFP5sNy1tPK20GDQ6e4fnZcvjxia/OJJEvMK1k1 0ZJNTgLrhJ3YGI/UggmWA587yl6v+2aoyaG1UpLSUe+2DrQnFbXI+6aRIOS8kvrnVSg9 4qcA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FtjDk2IZ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45458-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45458-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 4-20020a05621420c400b0068c46b80c08si7206496qve.141.2024.01.30.15.17.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:17:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45458-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FtjDk2IZ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45458-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45458-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5D5BD1C21407 for ; Tue, 30 Jan 2024 23:17:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9EA883CAF; Tue, 30 Jan 2024 23:14:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FtjDk2IZ" Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4624382894; Tue, 30 Jan 2024 23:14:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656474; cv=none; b=hnv0owVbxcrw0XvYe+XVKCNB7vWE3iBdgSlWdkHOirBH17HYSJVhrqCHXo6tCn4D5ufTodSTe/eBxhmHtZG4PH+w85JZFioJ8/w2plqlJmj6z5YhNbQhLO4J4hewz0QL+3L3y4VvigArv5kTpzB5h+GOFl1PoIDOZc90KaNYAK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656474; c=relaxed/simple; bh=4IV+dPdI08zimBNVCA9zvFgCo39imZ7Pxgsk7JpWdaY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=W/e2IuNPdHJSIWkksWT9Mli8mAMZ/0h4OHBgkPI4HQ28FbPYjgsheB0S82gPPWbHOTLOwd1bW6t5dzUF439yJMo6jz8Jnpj7UnmSJSrOP2cP+dr38LFW5Hzn2Ofr3S6OttqOmqNPTUTjWkc/hcUFv0euau6f+PEVa+aNT25C1ok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FtjDk2IZ; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1d7232dcb3eso23771775ad.2; Tue, 30 Jan 2024 15:14:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706656472; x=1707261272; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=JzlkUZ88PnE68OAhgmXxQkn/nQs2BjH2k5xb3I1hQhI=; b=FtjDk2IZZjZN4bwzBNx+DWF8eu5VxfkHW1E1ntsjcznbwhcp6TtKAzGXQxSldTMENy h9i0HMYKMnk/EV2xnT0lKPlY40JE22ozfiRNcikr8A5NAyMUe02tf896971K7UicM2WU qccbVNJTrmWSn7IzMWlQYneKhWD7+qhjyzdPuztuvZ4vVD8vz0JNObVRxxorOzb9M2Ea ST/MwhHvrx+M6hbg095EJnv2HudTr4CgarPjgBx0M5OBCh7/P9ZcEIHK0p9iceNHxV75 0LRK9kQMptReZewROX96fNqIehejNGDhVJi+vncAbJ71c7DKyNP79caGDQxAdew+kCxR uqvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706656472; x=1707261272; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JzlkUZ88PnE68OAhgmXxQkn/nQs2BjH2k5xb3I1hQhI=; b=jg0iZGgIHEF2Qwz9cpD2vfdWxMUiVgVJqGPoVFEmLfXZQS3lufX8OexLebLI0PBdrd JPX+LnuV8NUjkaJuyys26kAjs3RqCbo3vHIVhdzirZucoKPWEIlA3mako92RcTFRY4UJ ye32OBElKB22ejsA06SKgSepm6x+x42CKfQ8vgA9mUMZe2GIbkIcWFlwKM10FITI/Yop 55+kZd1v9saWW7R5DKmDgoYXkBrngguXvn1acFS3W6LzrNoG+Yvd3BiAQSVk8kHCcvY8 olbwUXb5iofh8FB6Hw8lbd99HAZDN+T1PA5bLqY61xGnZr0V3twtWpDavDXtQrN1Brd5 mIEQ== X-Gm-Message-State: AOJu0YwLIGI+3i8q35sehq0rmcAvmPiEnJouaWDNayXF7+gFHJca5MOt Av2m/I1LDQL4XuI7DGBqOSw/+FpCVBiC8uWfOSvXotyGuFuARJ3f X-Received: by 2002:a17:902:6507:b0:1d8:a75c:2dd6 with SMTP id b7-20020a170902650700b001d8a75c2dd6mr63483plk.15.1706656472615; Tue, 30 Jan 2024 15:14:32 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:c:204:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id jx2-20020a170903138200b001d8f251c8b2sm3473203plb.221.2024.01.30.15.14.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:14:31 -0800 (PST) From: Luiz Angelo Daros de Luca Date: Tue, 30 Jan 2024 20:13:27 -0300 Subject: [PATCH net-next v5 08/11] net: dsa: realtek: clean user_mii_bus setup Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240130-realtek_reverse-v5-8-ecafd9283a07@gmail.com> References: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> In-Reply-To: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> To: Linus Walleij , =?utf-8?q?Alvin_=C5=A0ipraga?= , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luiz Angelo Daros de Luca X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=2718; i=luizluca@gmail.com; h=from:subject:message-id; bh=4IV+dPdI08zimBNVCA9zvFgCo39imZ7Pxgsk7JpWdaY=; b=owEBbQGS/pANAwAIAbsR27rRBztWAcsmYgBluYKxsocLt6Ost9igjJjs9XSOU6LhVTUi1iHyj 5sR8nP2n5eJATMEAAEIAB0WIQQRByhHhc1bOhL6L/i7Edu60Qc7VgUCZbmCsQAKCRC7Edu60Qc7 Vj9nB/9USXIGEXOjj0uJiEgniJ5zjV7cxQBufC7TqiqSvCUfivQgxLJZJCzn/emzAbwCCQ6ndg2 +Nbj0JkR3T1HV+wFPc5J8gMU6PngbSUbWPQXF2F3DH7Sjg9MuUnvKqShI4sFSLbr6qvNjLRTlLU V9KnuHEFjUc0odKkXFCiIVesgyVNrGLGUedKS+drLMUZNFk9B0duU8Bnz6jo7FD/eu5n52z9S7i o1G/kQTNfzaWuG6b/iyyod3pZJTBhKwUrvE6l2BSInd9x/qyKNNDW+SNxi2b/CqyI7uU2J5Jl+O vUFPFo3xsipO0555+Vv2XFtH0NzftvAN3XCxfZ1JqHvP6Vrj X-Developer-Key: i=luizluca@gmail.com; a=openpgp; fpr=1107284785CD5B3A12FA2FF8BB11DBBAD1073B56 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789559178731001155 X-GMAIL-MSGID: 1789559178731001155 Remove the line assigning dev.of_node in mdio_bus as subsequent of_mdiobus_register will always overwrite it. As discussed in [1], allow the DSA core to be simplified, by not assigning ds->user_mii_bus when the MDIO bus is described in OF, as it is unnecessary. Since commit 3b73a7b8ec38 ("net: mdio_bus: add refcounting for fwnodes to mdiobus"), we can put the "mdio" node just after the MDIO bus registration. [1] https://lkml.kernel.org/netdev/20231213120656.x46fyad6ls7sqyzv@skbuf/T/#u Signed-off-by: Luiz Angelo Daros de Luca Reviewed-by: Vladimir Oltean --- drivers/net/dsa/realtek/realtek-smi.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index ad47dcbbd2b2..b84df4564c15 100644 --- a/drivers/net/dsa/realtek/realtek-smi.c +++ b/drivers/net/dsa/realtek/realtek-smi.c @@ -331,7 +331,7 @@ static int realtek_smi_setup_mdio(struct dsa_switch *ds) { struct realtek_priv *priv = ds->priv; struct device_node *mdio_np; - int ret; + int ret = 0; mdio_np = of_get_child_by_name(priv->dev->of_node, "mdio"); if (!mdio_np) { @@ -344,15 +344,14 @@ static int realtek_smi_setup_mdio(struct dsa_switch *ds) 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->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); if (ret) { @@ -361,8 +360,6 @@ static int realtek_smi_setup_mdio(struct dsa_switch *ds) goto err_put_node; } - return 0; - err_put_node: of_node_put(mdio_np); @@ -422,8 +419,7 @@ EXPORT_SYMBOL_NS_GPL(realtek_smi_probe, REALTEK_DSA); * @pdev: platform_device to be removed. * * This function should be used as the .remove_new in a platform_driver. First - * it unregisters the DSA switch and cleans internal data. Finally, it calls - * the common remove function. + * it unregisters the DSA switch and then it calls the common remove function. * * Context: Can sleep. * Return: Nothing. @@ -437,9 +433,6 @@ void realtek_smi_remove(struct platform_device *pdev) rtl83xx_unregister_switch(priv); - if (priv->user_mii_bus) - of_node_put(priv->user_mii_bus->dev.of_node); - rtl83xx_remove(priv); } EXPORT_SYMBOL_NS_GPL(realtek_smi_remove, REALTEK_DSA); From patchwork Tue Jan 30 23:13:28 2024 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: 194384 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1555764dyb; Tue, 30 Jan 2024 15:19:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmmjOd5HTQuXA1a7J2x9CM9gRxKFKWv/BWALL6DBmpJzwQnRr+Np+My1E9Gb6feFActTVP X-Received: by 2002:a05:6a20:e103:b0:19a:28c3:ee0d with SMTP id kr3-20020a056a20e10300b0019a28c3ee0dmr7233308pzb.15.1706656747244; Tue, 30 Jan 2024 15:19:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706656747; cv=pass; d=google.com; s=arc-20160816; b=wzCC9Qa0y3vpKIC7K3dQcJynNvE2cnWPFfHdAVPs7mVGelcbgpxsrvcCSNXx84Kc12 1V6CjoRjcpg6WzX72FL5wVvSry8iOXr6UTpeJ1WAkDWjUjgp/RwGbz9dtKkVJRD4EArS irsPA4WUmIFvlfr+8c4XHguzM9MXfOoAQKbFrbRm7INPrvqSx6PhBHi8H3hH7m9BaNYt eLB7qnSSb0Zlc4Eyw3538IIqQWX9YDC4OJB/IvP/p0c36qhOVQxwLjhRFTXzaqQpHW7d ceZGhKgfqAjuo/EAyZtNEBCYUk44VhAafI+QV0gApjmPAQz6YsBFbezUHZD5k7evTnlE iXbg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=dH08kQGG8/TB47QvoaZ0YHpG8Sx3RZOkHm5Pla/90B8=; fh=BU4RSkB+Q4EYbEXM8vpZ5rnbcSjfYSNW9lfntnZ9xiw=; b=UtY3GB810WBATYvPV3ld+nx1lvpB1Z8V1auW95FJbAT1PbZepAaoksYq/023iIBtND eUYgkTh1MKdzgI1Hd7SVJL3jlhEw5cFnY/Z8u+6XV1h6j8jeNGl44wKcxW37o1x9mq5J +f/hko+d2Ing2tvUmo2cJEVYLsCG73Is8bRM3gTUwyVctaG8CBWne0hCZuE5TbGFran9 SeHbLcX3tuec/w2uk3vNneRbh933ImwFzohA9431McGaKYdqhMZRmWCwuvvHkMAGihVS NmjKht/B9usD4tPYn/17vLm6cwGGyAgRCT7tRYaJ2/MDrExAWvvnVic9OURDSX51LU6L IyYQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gkxel4D9; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45459-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45459-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e4-20020a170902b78400b001d8ef863df3si3460026pls.151.2024.01.30.15.19.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:19:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45459-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gkxel4D9; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45459-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45459-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 1FF4AB251B6 for ; Tue, 30 Jan 2024 23:17:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E43783CD2; Tue, 30 Jan 2024 23:14:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gkxel4D9" Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61E1583CA0; Tue, 30 Jan 2024 23:14:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656478; cv=none; b=rolcQKM8ZYjtXBGThVibFhiavji0/ui4QOjLKt/RSzkMa36xM/3vJTtrJT3iiYmydvuR+OWok26RvaB6MO0OX95uooO1CSND7AwqXOiTJicSHPGBpgmsmyTZWH0L4gFEOT0zWe4AwjMbPIARDjv6GQN01rFeHJTzruhrX9zAGdU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656478; c=relaxed/simple; bh=Z+KSWzoyD03FxX1yk8zLCaZt3EiLsZ0lz5o1EfgHvEY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KmnaWHwWVTGpljiUXpMViD37AQrYScmzqQgTKFqSAImR1hP6TXzpxnEbZw88n/rzLqzbfSQgtIyMXVuY7Q5CmzXRsN/Y2VK8eYKxWnnQrZEcDL345FTf83cYjFcWCTiCwddB+BD2Tn6QEZuCSTiuFNNXXrnV7w4VNg71Y9JGKNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gkxel4D9; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1d8e7df6abcso17074785ad.1; Tue, 30 Jan 2024 15:14:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706656477; x=1707261277; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=dH08kQGG8/TB47QvoaZ0YHpG8Sx3RZOkHm5Pla/90B8=; b=gkxel4D9EofINjAH9M9rgxwhg0UYYW+BCx8Qhi+MlK0ghwpLCxM9LCgOwGImjHHy5V qbQaXSehudZ7VPWG2SlNGLYRfYNVFihhaV4Rj/4ne8YEc/wlMRAjRppfipaC+7/h9jau z6zMK4c6q30LN1Ie6ZKlAWb4KQvAetm4gdhInSRxoMPFsdJjkwdKKFDB8DCvm+qwZvD6 G5ZhzoVhJlD3dzRiqvxvuP3gm+N/Yh4Gr909mZVZiaGptBYcT2JK/qsSyZYT6BzJlnUN ASq7ywv1lPuvUcns0b4F/9dhcabITkotPYzbDjsfmqTrMrnaoRiNEdlFR7QyPzvJq2t1 zkew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706656477; x=1707261277; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dH08kQGG8/TB47QvoaZ0YHpG8Sx3RZOkHm5Pla/90B8=; b=euNCNB0Wfkl6ldDLfuQYYfUi5q/ZhYsHRAeXxJCKmGuErHoraRXgZc0BUHy92hN01O JV0Wryhnd0NJZH7gJ1wxPXME5nsbzlFVLf87ZLAzZgDognqf8kz4xwekjA8X3jRFLBpJ gYgIRccP6Bc+ok/pCpy+gRwjkBa0u+GqsV9wgOz8JZFZkRLkJM/11C47RnG2DhVLdIlS +oV5zNy0MQ9sPbnYTf5cysiUKZRb/+7qQg16fz2/3QiiRHD1e3OroXk6NDc3uRD8CXs+ FHdM+5iF9yqu3Ov93PC4pZSY7wGEEsh495yF/Al9ASFi8POxnrLAGwP3DOl4LCxK9H8V wggQ== X-Gm-Message-State: AOJu0Yw6DNc3i6c8f6MwYjCLuBz/2N5zHR4cuV4BoW18O7Etf1O4vU36 BYzW5Cecwlq+J/G3TkvypyXWROP7U3aFLDB5UnVt5XyjF3TNbd4r X-Received: by 2002:a17:902:f551:b0:1d8:f21b:809c with SMTP id h17-20020a170902f55100b001d8f21b809cmr45494plf.60.1706656476680; Tue, 30 Jan 2024 15:14:36 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:c:204:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id jx2-20020a170903138200b001d8f251c8b2sm3473203plb.221.2024.01.30.15.14.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:14:36 -0800 (PST) From: Luiz Angelo Daros de Luca Date: Tue, 30 Jan 2024 20:13:28 -0300 Subject: [PATCH net-next v5 09/11] net: dsa: realtek: migrate user_mii_bus setup to realtek-dsa Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240130-realtek_reverse-v5-9-ecafd9283a07@gmail.com> References: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> In-Reply-To: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> To: Linus Walleij , =?utf-8?q?Alvin_=C5=A0ipraga?= , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luiz Angelo Daros de Luca X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=6171; i=luizluca@gmail.com; h=from:subject:message-id; bh=Z+KSWzoyD03FxX1yk8zLCaZt3EiLsZ0lz5o1EfgHvEY=; b=owGbwMvMwMG4W/D2rovs1mGMp9WSGFJ3Nm3kyJ0Y2pn7VZBXmu+K9BkL/XczDwQxFfsIbjj0/ +/fiZKXOhmNWRgYORhkxRRZBNk13FvPRlsJ/dL/ATOIlQlkCgMXpwBMpKSG/X9KpXb9t+OyOedK 0nkN/57ZyLNnKs+S7ZxdIqrqHg2L7e5+Vgw/Nf979YlFfsujy9WP+PJGsxi0zA4607XZIsxDpbx veveOr03P2J/Mzpi8wvLZRQ029f2xEWfmSXgcv3Ey97dboefKitWB7/7ueREi+ZPFae8q9ld1Jc ady0Wtje/qZAX9TV/3aeH2UJ4CPdcHidwH93BmCvXmxy3ZE9ZnEfIsfPO97tMP/CwZp79TLLARr 3CeyfQtT9GN70aI4eKl05cUMzyrC/40Y87iJM+DLxm0GySFXSz3tyT0TN/Pn2j5V4rjh4R4HFvb Kr111RElsjMrxbK13/Ye2pPAqp1uwCfpYH79b6N5/48uAA== X-Developer-Key: i=luizluca@gmail.com; a=openpgp; fpr=1107284785CD5B3A12FA2FF8BB11DBBAD1073B56 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789559305634511349 X-GMAIL-MSGID: 1789559305634511349 In the user MDIO driver, despite numerous references to SMI, including its compatible string, there's nothing inherently specific about the SMI interface in the user MDIO bus. Consequently, the code has been migrated to the rtl83xx module. All references to SMI have been eliminated. The MDIO bus id was changed from Realtek- to the switch devname suffixed with :user_mii, giving more information about the bus it is referencing. Signed-off-by: Luiz Angelo Daros de Luca --- drivers/net/dsa/realtek/realtek-smi.c | 57 +---------------------------- drivers/net/dsa/realtek/rtl83xx.c | 69 +++++++++++++++++++++++++++++++++++ drivers/net/dsa/realtek/rtl83xx.h | 1 + 3 files changed, 71 insertions(+), 56 deletions(-) diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index b84df4564c15..4d35621b5583 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 @@ -312,60 +311,6 @@ static int realtek_smi_read(void *ctx, u32 reg, u32 *val) return realtek_smi_read_reg(priv, reg, val); } -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 = 0; - - mdio_np = of_get_child_by_name(priv->dev->of_node, "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; - - ret = devm_of_mdiobus_register(priv->dev, priv->user_mii_bus, mdio_np); - if (ret) { - dev_err(priv->dev, "unable to register MDIO bus %s\n", - priv->user_mii_bus->id); - goto err_put_node; - } - -err_put_node: - of_node_put(mdio_np); - - return ret; -} - static const struct realtek_interface_info realtek_smi_info = { .reg_read = realtek_smi_read, .reg_write = realtek_smi_write, @@ -403,7 +348,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->setup_interface = rtl83xx_setup_user_mdio; priv->ds_ops = priv->variant->ds_ops_smi; ret = rtl83xx_register_switch(priv); diff --git a/drivers/net/dsa/realtek/rtl83xx.c b/drivers/net/dsa/realtek/rtl83xx.c index fb3b3b2305d1..f05fe6efe5a4 100644 --- a/drivers/net/dsa/realtek/rtl83xx.c +++ b/drivers/net/dsa/realtek/rtl83xx.c @@ -2,6 +2,7 @@ #include #include +#include #include "realtek.h" #include "rtl83xx.h" @@ -43,6 +44,74 @@ void rtl83xx_unlock(void *ctx) } EXPORT_SYMBOL_NS_GPL(rtl83xx_unlock, REALTEK_DSA); +static int rtl83xx_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 rtl83xx_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); +} + +/** + * rtl83xx_setup_user_mdio() - register the user mii bus driver + * @ds: DSA switch associated with this user_mii_bus + * + * This function first gets and mdio node under the dev OF node, aborting + * if missing. That mdio node describing an mdio bus is used to register a + * new mdio bus. + * + * Context: Can sleep. + * Return: 0 on success, negative value for failure. + */ +int rtl83xx_setup_user_mdio(struct dsa_switch *ds) +{ + struct realtek_priv *priv = ds->priv; + struct device_node *mdio_np; + struct mii_bus *bus; + int ret = 0; + + mdio_np = of_get_child_by_name(priv->dev->of_node, "mdio"); + if (!mdio_np) { + dev_err(priv->dev, "no MDIO bus node\n"); + return -ENODEV; + } + + bus = devm_mdiobus_alloc(priv->dev); + if (!bus) { + ret = -ENOMEM; + goto err_put_node; + } + + bus->priv = priv; + bus->name = "Realtek user MII"; + bus->read = rtl83xx_user_mdio_read; + bus->write = rtl83xx_user_mdio_write; + snprintf(bus->id, MII_BUS_ID_SIZE, "%s:user_mii", dev_name(priv->dev)); + bus->parent = priv->dev; + + ret = devm_of_mdiobus_register(priv->dev, bus, mdio_np); + if (ret) { + dev_err(priv->dev, "unable to register MDIO bus %s\n", + bus->id); + goto err_put_node; + } + + priv->user_mii_bus = bus; + +err_put_node: + of_node_put(mdio_np); + + return ret; +} +EXPORT_SYMBOL_NS_GPL(rtl83xx_setup_user_mdio, REALTEK_DSA); + /** * rtl83xx_probe() - probe a Realtek switch * @dev: the device being probed diff --git a/drivers/net/dsa/realtek/rtl83xx.h b/drivers/net/dsa/realtek/rtl83xx.h index a8eed92bce1a..0ddff33df6b0 100644 --- a/drivers/net/dsa/realtek/rtl83xx.h +++ b/drivers/net/dsa/realtek/rtl83xx.h @@ -10,6 +10,7 @@ struct realtek_interface_info { void rtl83xx_lock(void *ctx); void rtl83xx_unlock(void *ctx); +int rtl83xx_setup_user_mdio(struct dsa_switch *ds); struct realtek_priv * rtl83xx_probe(struct device *dev, const struct realtek_interface_info *interface_info); From patchwork Tue Jan 30 23:13:29 2024 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: 194382 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1555227dyb; Tue, 30 Jan 2024 15:17:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9bXYrfW+clab2eUoKpzNnf7I/EUSt3Umm2o7zwXrXn1N821gJhgAznvxFfQ06gSXCcD8T X-Received: by 2002:a0c:ab5c:0:b0:68c:4f04:a72c with SMTP id i28-20020a0cab5c000000b0068c4f04a72cmr2794071qvb.19.1706656673927; Tue, 30 Jan 2024 15:17:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706656673; cv=pass; d=google.com; s=arc-20160816; b=xsPb3NQVQ+dqCg1ejGvXNjQ88jAHxmlsZVBRPIrrXIZoYduiM75ub0pXKZ5ehXQLHl xnLNIXRy4tuX6pKPlGYStwNOUV8+j+evRBDzvIyRdXqffoHtwTF6dnsSPyrlVIFVD8Az 0r2o11ed0SmNf01uFQobGh6jG9mkTN0IvDpIu0zO8QH1GrZSLpDT/dnShVKSxDhTMzFk 5JSmX1fa7iwsigWQaoP/rJiNfGpOE1hgHUn9bjw4DoIvtEW5m8m4V4yef+A6IBlS8vxg qR7Cm7KqbpbPzbwCNvg34BsdwD53rzqHe8fQQL2+kLxX9hrpYCCGjEyWVkBTAKJfQfyZ /G1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=SAPqHzvNNOM7nTx+K7TaD2P+YhLDDwChHGAOyG76qvs=; fh=TWq1qMEcOFEK/aa5mszcF6yChS1jUoxllpXweoFr/HM=; b=UOilSOofzbLBAf8bB31jFtSj6kMXuALl80lGBK2FVP0iqPTSCFZ+T22BX+UCDUSFZG IWBZRBzcFGu6Ia8ldKKnTpHQKp64hxOYE2JLRJdeazLv62oJm0nIJWdfT9iQYdtiwlRv M+rjufGBeTfNfn40Cth+x40Q15hpWudtXu23PAQWP7H8ijGZ1mi5TFo022K4YHyKT25S YNiYW8Hpcn+jZj6MNV4QPDNRgqGw4K6xWYAz0SwXo1JAPITQbaLCHOzT1uj4+8TqJd4a GXiUuAbCFQ6LMZN3ONzx4Eb8kb1LFWxWpxp8ob4U0cnGfcXKXnHxrzDTS1pQuX+TF6AM aVLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mwD682Hj; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45460-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45460-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCVvocm1rs+IN+9Adxepe6LRUnpVEFLAZEV0Mi3d21f2TkIFHW1xPYJFZ1ThimBHoebV6EcZeKFYBEg1Pr1dVZnvBdEC1g== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y11-20020a0cec0b000000b0068063f0d760si8632352qvo.404.2024.01.30.15.17.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:17:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45460-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mwD682Hj; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45460-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45460-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8DA441C21C74 for ; Tue, 30 Jan 2024 23:17:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC36684A3C; Tue, 30 Jan 2024 23:14:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mwD682Hj" Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9417F83CCE; Tue, 30 Jan 2024 23:14:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656483; cv=none; b=WmkShpTcfftnQXYeZt4ZPF4oGCx/kHjH73mA3BqSqWJmY4iHd5eFeAfO8fq0kFglsKkzhoK+dbDknQfsdj9V34DajRkQOKwES/g592U9yiSBzQJlOzlfcRSaa5Ix3sbQPkweOwPaCAGRYbwpE0yjiJgJgFeda89ISRRy847heeM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656483; c=relaxed/simple; bh=biU4n9JkMdJOmAVA0wTiIfvmyySAO8kYaLwtX8a899w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eGsDlSTtWiIo5Q18E0ffbUGkcE6f3o1pv/sU+0rt4SIatXwpLEvw9aJynWDRGnLmkO7BTxkVE93pdeljse2LsydIWDWca8qb3VyHfHR2EgZ5arzX8wZrjicgpNUajyqE8Oz4QrU7q0g5wUn4NvHsEXCYvIEzvWhZhUg+jr7kCgs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mwD682Hj; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1d8f3acc758so2301355ad.1; Tue, 30 Jan 2024 15:14:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706656481; x=1707261281; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=SAPqHzvNNOM7nTx+K7TaD2P+YhLDDwChHGAOyG76qvs=; b=mwD682Hjx0vluwysxYgXVmDwuxQoJUuNjV4ZOLP9HDCRNGriNJ4yF7gRKAUvdyElC+ 8xvovMsC45CFQmcvtIIfopSX8LGPdnysZ3JWCWfJVbnVC3RXmjflK1iBydzqh6lu4Rvq DLnM5q8MGVHNrAdEjkTz80Mziv601x4uiuH1x7mwtrFqrQzhA1mOVFtoPuuYydn19eEA dN25Gj2VF2CbkqCN+Tig8SqtI7gM4g4sw1WRkkRtdYLFvD3H3jwzU8BswkXWa/FByjpo m+VpNJADPHhpLCCN5Xwg9R3+v0C2UtpaSsMLfIZSzkndDeaU+sAQSO8OMeLa+HVrvDcZ qnKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706656481; x=1707261281; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SAPqHzvNNOM7nTx+K7TaD2P+YhLDDwChHGAOyG76qvs=; b=hSX4kvhQjmlnUjYZymC6exJFrhPw1MDcnbY9RMUnbE4JasXuzUlCEWpULXjAUZrY1h SaLC3DQIY5XYGylIS+A+D5AZ0Y3z8mfQzXH+qwv3XmQUQ8qhbv3+aAqve9hpfVu6gThz PntXEQ6IfYVYojUgOKRmw50qqYHJ9Br77xgCDmJXIAH7zQ6wBbi8Qdjn1t8VNTIxodjc LlA/7/qe3Jnyj6lHeaoozMnL+wrFrICOJisN3tqkIWyo32X10EZ2BX+6iI+JZGjg4XSH bxdUo5DglYzFminbymPAmMymK8pb6bmbA84de38BRfoako65kiIMhABTM7qJKsJYfKmP z19g== X-Gm-Message-State: AOJu0YxM9+lluim9El293M87DELeY2s6/YK5/5ezyUp8IhFF+0Yd+WXH E0vtvZXfifvPHDUpV+1cFQuGMc7HmnY2NqNpzmNHa2CeBbqmQtJJ X-Received: by 2002:a17:902:d50e:b0:1d7:836d:7b3f with SMTP id b14-20020a170902d50e00b001d7836d7b3fmr3220325plg.9.1706656480889; Tue, 30 Jan 2024 15:14:40 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:c:204:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id jx2-20020a170903138200b001d8f251c8b2sm3473203plb.221.2024.01.30.15.14.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:14:40 -0800 (PST) From: Luiz Angelo Daros de Luca Date: Tue, 30 Jan 2024 20:13:29 -0300 Subject: [PATCH net-next v5 10/11] net: dsa: realtek: use the same mii bus driver for both interfaces Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240130-realtek_reverse-v5-10-ecafd9283a07@gmail.com> References: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> In-Reply-To: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> To: Linus Walleij , =?utf-8?q?Alvin_=C5=A0ipraga?= , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luiz Angelo Daros de Luca X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=9984; i=luizluca@gmail.com; h=from:subject:message-id; bh=biU4n9JkMdJOmAVA0wTiIfvmyySAO8kYaLwtX8a899w=; b=owEBbQGS/pANAwAIAbsR27rRBztWAcsmYgBluYKxjbzK02XBcQpG9ZkOqE5h3DZFU4R6hfZum XPH5FNdJwOJATMEAAEIAB0WIQQRByhHhc1bOhL6L/i7Edu60Qc7VgUCZbmCsQAKCRC7Edu60Qc7 VuDqCACs/xP1vRR5xd2BrmSNhv/s271S4XA7P5YQ5/MJIIN2iEwZA1A4G0xtH8wtcr+NRx6JLGo sAuYT62NMnp2V+h2OuZlTLiJzGzguQAZd3cO1RpEl5NcrDtCqPxIR9cqIDB+GO3pL5Le7QXnyHQ KUWXE7xrklWzJkPaHsNcA5YHcw/5s4l0y3tKrIP19e/WxJbb2BCADmlF9HBlZzt1W5v5bpGW9nk l6aXyC86wC449+LcfBlGDGDopIonyd5p6DMe7irgLAsv46U72Sk/ETdMOL8Mpro5Jgv7GETFGtk JoBmdjXlF3Ug7GQ10sBxd6Uzno1N+C9SL8D58tS8DqXkWCcj X-Developer-Key: i=luizluca@gmail.com; a=openpgp; fpr=1107284785CD5B3A12FA2FF8BB11DBBAD1073B56 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789559228718511075 X-GMAIL-MSGID: 1789559228718511075 The realtek-mdio will now use this driver instead of the generic DSA driver ("dsa user smi"), which should not be used with OF[1]. With a single ds_ops for both interfaces, the ds_ops in realtek_priv is no longer necessary. Now, the realtek_variant.ds_ops can be used directly. The realtek_priv.setup_interface() has been removed as we can directly call the new common function. [1] https://lkml.kernel.org/netdev/20220630200423.tieprdu5fpabflj7@bang-olufsen.dk/T/ Signed-off-by: Luiz Angelo Daros de Luca Reviewed-by: Vladimir Oltean --- drivers/net/dsa/realtek/realtek-mdio.c | 1 - drivers/net/dsa/realtek/realtek-smi.c | 2 -- drivers/net/dsa/realtek/realtek.h | 5 +--- drivers/net/dsa/realtek/rtl8365mb.c | 49 ++++---------------------------- drivers/net/dsa/realtek/rtl8366rb.c | 52 ++++------------------------------ drivers/net/dsa/realtek/rtl83xx.c | 2 +- 6 files changed, 14 insertions(+), 97 deletions(-) diff --git a/drivers/net/dsa/realtek/realtek-mdio.c b/drivers/net/dsa/realtek/realtek-mdio.c index 45d9ef43fe3d..1ae31575d096 100644 --- a/drivers/net/dsa/realtek/realtek-mdio.c +++ b/drivers/net/dsa/realtek/realtek-mdio.c @@ -131,7 +131,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_mdio; ret = rtl83xx_register_switch(priv); if (ret) diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index 4d35621b5583..c075770c6986 100644 --- a/drivers/net/dsa/realtek/realtek-smi.c +++ b/drivers/net/dsa/realtek/realtek-smi.c @@ -348,8 +348,6 @@ 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 = rtl83xx_setup_user_mdio; - priv->ds_ops = priv->variant->ds_ops_smi; ret = rtl83xx_register_switch(priv); if (ret) diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h index e9e28b189509..864bb9a88f14 100644 --- a/drivers/net/dsa/realtek/realtek.h +++ b/drivers/net/dsa/realtek/realtek.h @@ -62,7 +62,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; @@ -73,7 +72,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 +113,7 @@ 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; 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 60f826a5a00a..778a962727ab 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->setup_interface) { - ret = priv->setup_interface(ds); - if (ret) { - dev_err(priv->dev, "could not set up MDIO bus\n"); - goto out_teardown_irq; - } + ret = rtl83xx_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_smi = { - .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_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_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_smi = &rtl8365mb_switch_ops_smi, - .ds_ops_mdio = &rtl8365mb_switch_ops_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 a0c365325b4a..54eff9cd0c03 100644 --- a/drivers/net/dsa/realtek/rtl8366rb.c +++ b/drivers/net/dsa/realtek/rtl8366rb.c @@ -1033,12 +1033,10 @@ 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 (ret) { - dev_err(priv->dev, "could not set up MDIO bus\n"); - return -ENODEV; - } + ret = rtl83xx_setup_user_mdio(ds); + if (ret) { + dev_err(priv->dev, "could not set up MDIO bus\n"); + return -ENODEV; } return 0; @@ -1785,17 +1783,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; @@ -1861,35 +1848,9 @@ static int rtl8366rb_detect(struct realtek_priv *priv) return 0; } -static const struct dsa_switch_ops rtl8366rb_switch_ops_smi = { - .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_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, @@ -1928,8 +1889,7 @@ 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 = &rtl8366rb_switch_ops, .ops = &rtl8366rb_ops, .clk_delay = 10, .cmd_read = 0xa9, diff --git a/drivers/net/dsa/realtek/rtl83xx.c b/drivers/net/dsa/realtek/rtl83xx.c index f05fe6efe5a4..aa998e15c42b 100644 --- a/drivers/net/dsa/realtek/rtl83xx.c +++ b/drivers/net/dsa/realtek/rtl83xx.c @@ -232,7 +232,7 @@ int rtl83xx_register_switch(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); From patchwork Tue Jan 30 23:13:30 2024 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: 194383 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1555341dyb; Tue, 30 Jan 2024 15:18:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IEF1iQ1ohnY2fgUJ9t6SvQ0X+UJsclm508NFgtv/asusZ5E7wKBOavAsjdYg4VePqLupvTJ X-Received: by 2002:aa7:c61a:0:b0:55e:b155:260b with SMTP id h26-20020aa7c61a000000b0055eb155260bmr5886922edq.33.1706656690674; Tue, 30 Jan 2024 15:18:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706656690; cv=pass; d=google.com; s=arc-20160816; b=T0nO+m/8fciovZXlyrEK7+4EoZ/qbGpCoyKePJL9WQyF7pzjLa6G9ObIbXdTsfZLqX 3/9WaMBzOxDpCJXZ4sg1WejykZkcjc74dcUg/J+YsRjPyrEYHzdPwxvetaQQgJf0aWNz LUEE8W6hq/XT3CaSbt1hjZMa4jNyvg2Vn7mY6Jqbvw53nBQkyuiDZoMkm8GKjtBsxYdP SKT43ajEwfzy+adl2uVVryD49p9OTnUuJK1n3gsFY/EdT8w26gtkMkMzYd48rQPInEel I3X1KxhYhIhLW6980ONaRnHUa4lyf+begQ8O1qx67W9BBlOmw3RKA5KyTCsuKcUCCcfA 1ukw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=Cmf6IXAOX4sOtXhjJ9bPGawS7c4pqgm3fjtDF1AA0Pw=; fh=BU4RSkB+Q4EYbEXM8vpZ5rnbcSjfYSNW9lfntnZ9xiw=; b=oJNnd84nonFaqsnkf2QEZaLvyVNB/+CN9BR90YuqJdNoOLOXnrrTurt/OhQWg/1cZq /JcH/rahWX2T23L6G35vhj1ID3G6QbQ4zXQWXQHAzk75kN8ZnAr2sBVLiuvt+Yos8Urx r74H6wncojQGXIIzaL2C60qq7tAOIsMAcq80RTwPZ7FqKwFs6fwBk++9+Blz2hBgR1g6 uG9Hw/IDPKCuOHQ1aM5XR4lSWJiGsLDXSPOizH0FLmacIgQmc39QmCCqsvm7cMQs9JDC ZJLbaWalsE7vuFprr+haolcMg2irVJWewOkjX2MG5815eDfuxUlDMl/TRNRkd1a3vAu8 oZoQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hTq83wgH; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45461-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45461-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w21-20020aa7dcd5000000b0055f5c0d3f29si508951edu.598.2024.01.30.15.18.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:18:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45461-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hTq83wgH; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-45461-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45461-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1E9D01F2205C for ; Tue, 30 Jan 2024 23:18:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D28B584A50; Tue, 30 Jan 2024 23:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hTq83wgH" Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AA9384A29; Tue, 30 Jan 2024 23:14:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656487; cv=none; b=qEU9fhPcL40J82aX2eUxT+vh+11irFf7Kvv5TePbQlHBelvVUauB3JumLqQyh64fgVDqAg7oe+C9NW05wwEnsgUTfsX+R+oEyPrDxEp/N2OVeNLO6m/VmID4gToV9Mv/LlJg2H8ZpoPvsyi96vt4Amko8fVd+I4Opt+d+42BKFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706656487; c=relaxed/simple; bh=BG5ESZ6S3xcp89l1N+mS5Clo2oqsEkk72iSZeToz9kM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Sewm4FsRPmP7i2mxhCNjt85stdigPecgKrFgSkRPrX51wipW1eRMuocflhtQViZdkvXVROVB76SaSdW6TXPXtf1es61pz5lhNhJ9Y3/tl17ekVulKodyP/4a3e6B3Sdd7FV6ptaNm5Nd5p3PVh1f7CqfDnO71FmKpKrq1gFiCKI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hTq83wgH; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1d731314e67so21933725ad.1; Tue, 30 Jan 2024 15:14:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706656485; x=1707261285; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Cmf6IXAOX4sOtXhjJ9bPGawS7c4pqgm3fjtDF1AA0Pw=; b=hTq83wgHCQC4CmXVm9hxyZNKqilf49H52VEHD7dQOT5QqZ7oA/mWv2VpUQLZWcS/SM 86/2HZbEfwoZUCYCbsBh6+KqWu0w0w9U7wGOmZ8jJVUURRD3P9ZGo2WWY7dV9YUUDcFY k/F1ye6oZ//fB2ux9NhLhH3n095g+u5Q2HgxjRnDKI1WWU1yTQHGbax/susytkxAXgwl S1QO1O/BvDbiTXrl7Xcx5qk/80Wk4ssacUs+EkC5mYpZEkjSNh2UNSUZU+0qeU5LBB12 wM0bfdDrMQ8+UC1DNC+XToiPK+54wwDb6bsEq/bB/T/vd18f2dX+lYVtQMSxQHLEBPGy GfHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706656485; x=1707261285; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cmf6IXAOX4sOtXhjJ9bPGawS7c4pqgm3fjtDF1AA0Pw=; b=U9Xkswov4NC18cgH718huhNHJ6FBPKS4rvK7sLCX6s+ne5J2izlfTTcHL6h6mLrKOm uV42fqt5504v8NuzWuFyoMFNdhFHRierAs2x5pTtpqb5OMCilruK1VWPkcH5hW5rWjfM wdaPObDTaC6yysR2cM27sbT1rHBuTkCx8kOOvMnQlGFiZ932HZFnKpUNvWZQeZIePGzm A0vgpBk+P3v6lzL7374A9HjTkmyQzoOHwad5bjcsdrVEyBiCgfFaQFPK/SOrkybx0SwL Ns5D+fnjYswTClJu9gpyb80aiGLZgueKC3ypFLZFW70uQCRtU93V3x5WRzVigS9/Ir6F rzFw== X-Gm-Message-State: AOJu0YzF02ZU3jDnZIZxZLVlqp+i4eJwo4KD+1XwgoNUpnSCuXSwjLxD 9CgkuCVv/Qe/LcXCFWvglOhnBFh/MC9mUvD+91VwuQ17YuZ2xXvo X-Received: by 2002:a17:903:11cf:b0:1d8:ac08:3cb7 with SMTP id q15-20020a17090311cf00b001d8ac083cb7mr52810plh.33.1706656484948; Tue, 30 Jan 2024 15:14: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 jx2-20020a170903138200b001d8f251c8b2sm3473203plb.221.2024.01.30.15.14.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:14:44 -0800 (PST) From: Luiz Angelo Daros de Luca Date: Tue, 30 Jan 2024 20:13:30 -0300 Subject: [PATCH net-next v5 11/11] net: dsa: realtek: embed dsa_switch into realtek_priv Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240130-realtek_reverse-v5-11-ecafd9283a07@gmail.com> References: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> In-Reply-To: <20240130-realtek_reverse-v5-0-ecafd9283a07@gmail.com> To: Linus Walleij , =?utf-8?q?Alvin_=C5=A0ipraga?= , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luiz Angelo Daros de Luca X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=5204; i=luizluca@gmail.com; h=from:subject:message-id; bh=BG5ESZ6S3xcp89l1N+mS5Clo2oqsEkk72iSZeToz9kM=; b=owEBbQGS/pANAwAIAbsR27rRBztWAcsmYgBluYKxnBF4fse//mhC/q5GitrBp5Vnid95kwo0N dDwY2RkwciJATMEAAEIAB0WIQQRByhHhc1bOhL6L/i7Edu60Qc7VgUCZbmCsQAKCRC7Edu60Qc7 Vi+nB/4zPlKfX2EjMeiuYd9mmY1iicYxLG5bzkJLKDPKw9NyqSnlouwY2KGAUk24+jWjtnT2mvf /gO+5+bk0kfBuifuYDXgULj0YiBRp2xAohla4ccECAxrdGrR0qKd/cPyLZtFeY9ULcxcbI6SnTd CcavS3u2F3ypfcDzAd27DQqxKtPyPlKVVgeqL7KUGjaZPPsnmeqwGjNVyDv8se5IHKoS8m/IGii +KvV8+ld1JAvgApXrlL9G8UU9ohuShnOd7nzDMb2KjCMjYAWKKEZPAlf3bz5bFJcQc7K1UVxH86 ogcqtJ9MHcOcq6UemIUaCu9JMPUyZi6P1ipJAI759lXe6K3b X-Developer-Key: i=luizluca@gmail.com; a=openpgp; fpr=1107284785CD5B3A12FA2FF8BB11DBBAD1073B56 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789559245650937664 X-GMAIL-MSGID: 1789559245650937664 To eliminate the need for a second memory allocation for dsa_switch, it has been embedded within realtek_priv. Suggested-by: Alvin Šipraga Signed-off-by: Luiz Angelo Daros de Luca Reviewed-by: Vladimir Oltean --- drivers/net/dsa/realtek/realtek.h | 2 +- drivers/net/dsa/realtek/rtl8365mb.c | 12 ++++++------ drivers/net/dsa/realtek/rtl8366rb.c | 2 +- drivers/net/dsa/realtek/rtl83xx.c | 18 +++++++----------- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h index 864bb9a88f14..b80bfde1ad04 100644 --- a/drivers/net/dsa/realtek/realtek.h +++ b/drivers/net/dsa/realtek/realtek.h @@ -61,7 +61,7 @@ struct realtek_priv { const struct realtek_variant *variant; spinlock_t lock; /* Locks around command writes */ - struct dsa_switch *ds; + struct dsa_switch ds; struct irq_domain *irqdomain; bool leds_disabled; diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/rtl8365mb.c index 778a962727ab..9066e34e9ace 100644 --- a/drivers/net/dsa/realtek/rtl8365mb.c +++ b/drivers/net/dsa/realtek/rtl8365mb.c @@ -880,7 +880,7 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port, if (!extint) return -ENODEV; - dp = dsa_to_port(priv->ds, port); + dp = dsa_to_port(&priv->ds, port); dn = dp->dn; /* Set the RGMII TX/RX delay @@ -1543,7 +1543,7 @@ static void rtl8365mb_stats_setup(struct realtek_priv *priv) for (i = 0; i < priv->num_ports; i++) { struct rtl8365mb_port *p = &mb->ports[i]; - if (dsa_is_unused_port(priv->ds, i)) + if (dsa_is_unused_port(&priv->ds, i)) continue; /* Per-port spinlock to protect the stats64 data */ @@ -1564,7 +1564,7 @@ static void rtl8365mb_stats_teardown(struct realtek_priv *priv) for (i = 0; i < priv->num_ports; i++) { struct rtl8365mb_port *p = &mb->ports[i]; - if (dsa_is_unused_port(priv->ds, i)) + if (dsa_is_unused_port(&priv->ds, i)) continue; cancel_delayed_work_sync(&p->mib_work); @@ -1963,7 +1963,7 @@ static int rtl8365mb_setup(struct dsa_switch *ds) dev_info(priv->dev, "no interrupt support\n"); /* Configure CPU tagging */ - dsa_switch_for_each_cpu_port(cpu_dp, priv->ds) { + dsa_switch_for_each_cpu_port(cpu_dp, &priv->ds) { cpu->mask |= BIT(cpu_dp->index); if (cpu->trap_port == RTL8365MB_MAX_NUM_PORTS) @@ -1978,7 +1978,7 @@ static int rtl8365mb_setup(struct dsa_switch *ds) for (i = 0; i < priv->num_ports; i++) { struct rtl8365mb_port *p = &mb->ports[i]; - if (dsa_is_unused_port(priv->ds, i)) + if (dsa_is_unused_port(&priv->ds, i)) continue; /* Forward only to the CPU */ @@ -1995,7 +1995,7 @@ static int rtl8365mb_setup(struct dsa_switch *ds) * ports will still forward frames to the CPU despite being * administratively down by default. */ - rtl8365mb_port_stp_state_set(priv->ds, i, BR_STATE_DISABLED); + rtl8365mb_port_stp_state_set(&priv->ds, i, BR_STATE_DISABLED); /* Set up per-port private data */ p->priv = priv; diff --git a/drivers/net/dsa/realtek/rtl8366rb.c b/drivers/net/dsa/realtek/rtl8366rb.c index 54eff9cd0c03..cdc37be1ed2c 100644 --- a/drivers/net/dsa/realtek/rtl8366rb.c +++ b/drivers/net/dsa/realtek/rtl8366rb.c @@ -1675,7 +1675,7 @@ static int rtl8366rb_set_mc_index(struct realtek_priv *priv, int port, int index * not drop any untagged or C-tagged frames. Make sure to update the * filtering setting. */ - if (dsa_port_is_vlan_filtering(dsa_to_port(priv->ds, port))) + if (dsa_port_is_vlan_filtering(dsa_to_port(&priv->ds, port))) ret = rtl8366rb_drop_untagged(priv, port, !pvid_enabled); return ret; diff --git a/drivers/net/dsa/realtek/rtl83xx.c b/drivers/net/dsa/realtek/rtl83xx.c index aa998e15c42b..f65e47339d5b 100644 --- a/drivers/net/dsa/realtek/rtl83xx.c +++ b/drivers/net/dsa/realtek/rtl83xx.c @@ -226,16 +226,12 @@ int rtl83xx_register_switch(struct realtek_priv *priv) 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->variant->ds_ops; + priv->ds.num_ports = priv->num_ports; - priv->ds->priv = priv; - priv->ds->dev = priv->dev; - priv->ds->ops = priv->variant->ds_ops; - priv->ds->num_ports = priv->num_ports; - - ret = dsa_register_switch(priv->ds); + ret = dsa_register_switch(&priv->ds); if (ret) { dev_err_probe(priv->dev, ret, "unable to register switch\n"); return ret; @@ -256,7 +252,7 @@ EXPORT_SYMBOL_NS_GPL(rtl83xx_register_switch, REALTEK_DSA); */ void rtl83xx_unregister_switch(struct realtek_priv *priv) { - dsa_unregister_switch(priv->ds); + dsa_unregister_switch(&priv->ds); } EXPORT_SYMBOL_NS_GPL(rtl83xx_unregister_switch, REALTEK_DSA); @@ -273,7 +269,7 @@ EXPORT_SYMBOL_NS_GPL(rtl83xx_unregister_switch, REALTEK_DSA); */ void rtl83xx_shutdown(struct realtek_priv *priv) { - dsa_switch_shutdown(priv->ds); + dsa_switch_shutdown(&priv->ds); dev_set_drvdata(priv->dev, NULL); }