From patchwork Mon Apr 1 13:35:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13612774 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9D413FB31 for ; Mon, 1 Apr 2024 13:36:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711978573; cv=none; b=sidcAAp+fxIje4apUW/ugIFOP0/Fnlr2N+Irk4CtP/IQstAz0/opmHCo2QpNMKtv/eg+JjGaU60EiBtxCjtfHvZ6WmAuzGQMFiOMY+aK+VODTJgPUSbiK3KtfA2vyDMPzREojGmqC1o8rPubO/Ldga2yy9avrjnp39xlphH2X+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711978573; c=relaxed/simple; bh=Wv5Au3GN6EVOwYEscSwkEYCzUl3gsdXhrVkJvQGNGts=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WkHrv9Asn8Kz5EIM1TMcInv+Tqd3BM2SNZo8dIyx2yFS/HpbU30qSQIjFf0NYjG/rseSKN77gwOouz0BXnV27WXVHngkJteJM9T8s4YbMfT8VLEk/ksYcBTz7sdQEXgrpHhgRZi2C+n3EaiMKa0yyE2LkMBpNUnC0K+ILc2K6n8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=Nb8UZxak; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="Nb8UZxak" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=jG9hkeqPqADNNiDfJeyzLij7rhDH+uXL633QTYLkMWQ=; b=Nb 8UZxake59ybMAmUtWy4QEAnhza3CHerw2mzU6nFLocI6fBErwpZfMUuQh5HCRet8nQRxGalmSBEwm cc5Fk/E7i+LgDZVqQCncpkT/O4U87H9sy6nrm7AIpufKi0AWNV5Egwi+y/HLqfDhxyBgKWVWRJTdN mmifsEloYZoHYgE=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rrHpY-00BrFx-1n; Mon, 01 Apr 2024 15:36:08 +0200 From: Andrew Lunn Date: Mon, 01 Apr 2024 08:35:46 -0500 Subject: [PATCH net-next v3 1/7] dsa: move call to driver port_setup after creation of netdev. Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-1-221b3fa55f78@lunn.ch> References: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-0-221b3fa55f78@lunn.ch> In-Reply-To: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-0-221b3fa55f78@lunn.ch> To: Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Gregory Clement Cc: netdev@vger.kernel.org, Andrew Lunn X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2108; i=andrew@lunn.ch; h=from:subject:message-id; bh=Wv5Au3GN6EVOwYEscSwkEYCzUl3gsdXhrVkJvQGNGts=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmCrhAO8i3xFEIWgBnzXqyFDje+fuI+n+uAFmvn UgI9nFM2NqJAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZgq4QAAKCRDmvw3LpmlM hJteD/94lFZ0ixLpZwz1i6STzRcjw/UQuGiDTf95TGgWryHtDKjBy3qbrjcYG/HDWYLPwBpiwzv tm9Ec20ujY2iTu707avm6YLE+wbJbERIRZ3xF9CPy3Jbjh5uVSSL6OPTUP/lWOmQ41COTnfJtRI hy1lzo+5zl/gJxL2x+tqDwRiI4duUBsza442W5Wcq5SiIk+sSXJU+nZjTO8yqJPU6Q27Be+XlXR l/MpZtHjNV8fsjhJpzB1l0DlQVxqdkDUk+jWjXUbUWwvTvFvj7LtmPDBI92O6EmaRV8tngz557g WjFbdMGPYvCrRTtrzpVeIR63l1Iskk1KkP/HWNJi8fwNyyXKBaGvaTy7WHWK/wNjmPFlsjOJRUH ue4FFpZB7p4aMOChszWdNa84B+Vnfy6Ef+AMjBRx/q6mCE8uR0DUa1+lV2AvEMoMevmPau2qWg0 NWcskDLnQ5y4xpz6LsNFikTwLUr3eiRocqz/uUI0lSk/PB5ggpz6rHW2TM/BmsD7KUcjH8b5t6b OKTwvSwQpgEEF713ClLzHKOz375Nnda6fPR9ByZr1PHH77Kk+51VnWhPdU2yR++CB6wXfFobxks j9a/tFATxhXAgUWA66hDFCjzupXRDVXUHGQAb3RHzins4UB4UDUk11OWZq24FxEY+p1K4HswfCI 6TMEnU6tFHlhL8w== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org The drivers call port_setup() is a good place to add the LEDs of a port to the netdev representing the port. However, when port_setup() is called in dsa_port_devlink_setup() the netdev does not exist yet. That only happens in dsa_user_create() which is latter in dsa_port_setup(). Move the call to port_setup() out of dsa_port_devlink_setup() and to the end of dsa_port_setup() where the netdev will exist. Signed-off-by: Andrew Lunn --- net/dsa/devlink.c | 17 +---------------- net/dsa/dsa.c | 3 +++ 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/net/dsa/devlink.c b/net/dsa/devlink.c index 431bf52290a1..9c3dc6319269 100644 --- a/net/dsa/devlink.c +++ b/net/dsa/devlink.c @@ -294,20 +294,12 @@ int dsa_port_devlink_setup(struct dsa_port *dp) struct dsa_switch_tree *dst = dp->ds->dst; struct devlink_port_attrs attrs = {}; struct devlink *dl = dp->ds->devlink; - struct dsa_switch *ds = dp->ds; const unsigned char *id; unsigned char len; - int err; memset(dlp, 0, sizeof(*dlp)); devlink_port_init(dl, dlp); - if (ds->ops->port_setup) { - err = ds->ops->port_setup(ds, dp->index); - if (err) - return err; - } - id = (const unsigned char *)&dst->index; len = sizeof(dst->index); @@ -331,14 +323,7 @@ int dsa_port_devlink_setup(struct dsa_port *dp) } devlink_port_attrs_set(dlp, &attrs); - err = devlink_port_register(dl, dlp, dp->index); - if (err) { - if (ds->ops->port_teardown) - ds->ops->port_teardown(ds, dp->index); - return err; - } - - return 0; + return devlink_port_register(dl, dlp, dp->index); } void dsa_port_devlink_teardown(struct dsa_port *dp) diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 09d2f5d4b3dd..6ffee2a7de94 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -520,6 +520,9 @@ static int dsa_port_setup(struct dsa_port *dp) break; } + if (ds->ops->port_setup) + err = ds->ops->port_setup(ds, dp->index); + if (err && dsa_port_enabled) dsa_port_disable(dp); if (err && dsa_port_link_registered) From patchwork Mon Apr 1 13:35:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13612775 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8315C3FB29 for ; Mon, 1 Apr 2024 13:36:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711978576; cv=none; b=E6uPb/XwPEKLki+IlqW2ja96BijgfBil7Vm0r6gswItmSoahS0KylXlRjiGalJpfGjONP4w9z6brqj9VQ52i3T3ZpsrEXt4Oj4ndypHHzwn+EKpj4Sxj6CD80vJPbNioIveoaK0F3rAfp2wvS56kHmpuRpxs5SGMbZ+1yTsE8fg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711978576; c=relaxed/simple; bh=kQjFgWgNTPOE+tvEYg/fcwHA2KwB8/r4hq+NnvwjDnk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XphiLl31Ub/Sk+mGUGSDGbV6DrmnpZh02G/3bP5iklSNzoFYUTc1yKC0Sop+hD9++1qodIFXV53AV4UM0nfxZ7PpafwLPxdopSsVYB9Lql0XAVEDkJq81pFuV2A1ncdF3zlDw0tZ5UxH2QBKv1tYCDmb0dqBLvHhcDsUoBubi1g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=k5ypIJpu; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="k5ypIJpu" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=MQkbzDCMjvD/j514nS3sL7oKG5IQsBk7PsTbAZ2Chlo=; b=k5 ypIJpuhWbfWT5MVS2QWryL7uAlPkgH34HgHRgjl71DDWck2I9e6deep54ydspW+KsdHAO+XB+IB60 0L/Bt8UQnx1g2fs25jtkHpKO+SQ+c1UKF8vaSEJ7sE2Z3WPjiNIZP4X4XDdwFVGvtuH0Vcg1Y2nHX o4GnrjVgQiSNfVk=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rrHpa-00BrFx-NC; Mon, 01 Apr 2024 15:36:10 +0200 From: Andrew Lunn Date: Mon, 01 Apr 2024 08:35:47 -0500 Subject: [PATCH net-next v3 2/7] net: Add helpers for netdev LEDs Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-2-221b3fa55f78@lunn.ch> References: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-0-221b3fa55f78@lunn.ch> In-Reply-To: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-0-221b3fa55f78@lunn.ch> To: Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Gregory Clement Cc: netdev@vger.kernel.org, Andrew Lunn X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=9076; i=andrew@lunn.ch; h=from:subject:message-id; bh=kQjFgWgNTPOE+tvEYg/fcwHA2KwB8/r4hq+NnvwjDnk=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmCrhAvE5/Olez4mgWxddYAvyKwNzTBJvWt7Nl1 8TjjqtVZg+JAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZgq4QAAKCRDmvw3LpmlM hHcfEACPWqUD+Nj429XibLd0mrWOrpgKJkfll538T6wra2gWqh9iNaRQ2JErVlz9jY3odrS8HcE yqts9WO535TnlsR/A8y/wXMpSSWRbHwAH/nFY7W9Qz49OZ6i8KhxpT/7gEO3/gVa37np3bwja49 oxlJ82wvLtQQY+WzKmOmUESRJQwUoGIxo1S2rgx1EBeKUD5vfSuKrU1oIXBmaWyT/m+VK/i+9mB zjo93sY5gAms4yHaHDG0VdAw6rmYIhqVuJUUcjz5m+GHDkg2et8fDnUs70UBlugNworlyxAsSNn SGdqCOP5NBdROGkx2n0KlqlzWgKogk0LINQVWhozXLWbggbOKXkzmQLWG8DLHG2Z1KrhQZ/DmUO 1k7bJaG1EMccMs8xRf2bpvIeFA5Ir4vfIi/oJ3BEUyR/UtRo6N3hNN+JBiJhWE5W5dTXeJq7IeF m8STwearXKYvjK20JPaoG88Mr7PgXRnsn8Tq17xZae/OBNepQwqxu3tKAf3REoBBLhWpf77iFm6 eiJxNmbfMoj+fA+Re25R3TEsHD0fps33RqTwy2mzxoQIFrdPWjJFmtPst1OwZkFcoSai1XTNf+b 7w9hL+5iGHJKvk2SkmJtqGaBkLEAI9Zc4fTm3RO4N6REQE5ba25W/Bk4hM2tLh3ZTXXFluLDTV9 wgJSV4QnnMXoG2Q== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org Add a set of helpers for parsing the standard device tree properties for LEDs as part of an ethernet device, and registering them with the LED subsystem. This code can be used by any sort of netdev driver, including plain MAC, DSA switches or pure switchdev switch driver. Signed-off-by: Andrew Lunn --- include/net/netdev_leds.h | 45 +++++++++++ net/Kconfig | 11 +++ net/core/Makefile | 1 + net/core/netdev-leds.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 258 insertions(+) diff --git a/include/net/netdev_leds.h b/include/net/netdev_leds.h new file mode 100644 index 000000000000..239f492f29f5 --- /dev/null +++ b/include/net/netdev_leds.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Helpers used for creating and managing LEDs on a netdev MAC + * driver. + */ + +#ifndef _NET_NETDEV_LEDS_H +#define _NET_NETDEV_LEDS_H + +struct netdev_leds_ops { + int (*brightness_set)(struct net_device *ndev, u8 led, + enum led_brightness brightness); + int (*blink_set)(struct net_device *ndev, u8 led, + unsigned long *delay_on, unsigned long *delay_off); + int (*hw_control_is_supported)(struct net_device *ndev, u8 led, + unsigned long flags); + int (*hw_control_set)(struct net_device *ndev, u8 led, + unsigned long flags); + int (*hw_control_get)(struct net_device *ndev, u8 led, + unsigned long *flags); +}; + +#ifdef CONFIG_NETDEV_LEDS +int netdev_leds_setup(struct net_device *ndev, struct device_node *np, + struct list_head *list, struct netdev_leds_ops *ops, + int max_leds); + +void netdev_leds_teardown(struct list_head *list, struct net_device *ndev); + +#else +static inline int netdev_leds_setup(struct net_device *ndev, + struct device_node *np, + struct list_head *list, + struct netdev_leds_ops *ops) +{ + return 0; +} + +static inline void netdev_leds_teardown(struct list_head *list, + struct net_device *ndev) +{ +} +#endif /* CONFIG_NETDEV_LEDS */ + +#endif /* _NET_PORT_LEDS_H */ diff --git a/net/Kconfig b/net/Kconfig index 3e57ccf0da27..753dfd11f014 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -516,4 +516,15 @@ config NET_TEST If unsure, say N. +config NETDEV_LEDS + bool "NETDEV helper code for MAC LEDs" + select LEDS_CLASS + select LEDS_TRIGGERS + select LEDS_TRIGGER_NETDEV + help + NICs and Switches often contain LED controllers. When the LEDs + are part of the MAC, the MAC driver, aka netdev driver, should + make the LEDs available. NETDEV_LEDS offers a small library + of code to help MAC drivers do this. + endif # if NET diff --git a/net/core/Makefile b/net/core/Makefile index 21d6fbc7e884..d04ce07541b5 100644 --- a/net/core/Makefile +++ b/net/core/Makefile @@ -42,3 +42,4 @@ obj-$(CONFIG_BPF_SYSCALL) += sock_map.o obj-$(CONFIG_BPF_SYSCALL) += bpf_sk_storage.o obj-$(CONFIG_OF) += of_net.o obj-$(CONFIG_NET_TEST) += net_test.o +obj-$(CONFIG_NETDEV_LEDS) += netdev-leds.o diff --git a/net/core/netdev-leds.c b/net/core/netdev-leds.c new file mode 100644 index 000000000000..802dd819a991 --- /dev/null +++ b/net/core/netdev-leds.c @@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include +#include +#include +#include +#include + +struct netdev_led { + struct list_head led_list; + struct led_classdev led_cdev; + struct netdev_leds_ops *ops; + struct net_device *ndev; + u8 index; +}; + +#define to_netdev_led(d) container_of(d, struct netdev_led, led_cdev) + +static int netdev_brightness_set(struct led_classdev *led_cdev, + enum led_brightness value) +{ + struct netdev_led *netdev_led = to_netdev_led(led_cdev); + + return netdev_led->ops->brightness_set(netdev_led->ndev, + netdev_led->index, + value); +} + +static int netdev_blink_set(struct led_classdev *led_cdev, + unsigned long *delay_on, unsigned long *delay_off) +{ + struct netdev_led *netdev_led = to_netdev_led(led_cdev); + + return netdev_led->ops->blink_set(netdev_led->ndev, + netdev_led->index, + delay_on, delay_off); +} + +static __maybe_unused int +netdev_hw_control_is_supported(struct led_classdev *led_cdev, + unsigned long flags) +{ + struct netdev_led *netdev_led = to_netdev_led(led_cdev); + + return netdev_led->ops->hw_control_is_supported(netdev_led->ndev, + netdev_led->index, + flags); +} + +static __maybe_unused int netdev_hw_control_set(struct led_classdev *led_cdev, + unsigned long flags) +{ + struct netdev_led *netdev_led = to_netdev_led(led_cdev); + + return netdev_led->ops->hw_control_set(netdev_led->ndev, + netdev_led->index, + flags); +} + +static __maybe_unused int netdev_hw_control_get(struct led_classdev *led_cdev, + unsigned long *flags) +{ + struct netdev_led *netdev_led = to_netdev_led(led_cdev); + + return netdev_led->ops->hw_control_get(netdev_led->ndev, + netdev_led->index, + flags); +} + +static struct device * +netdev_hw_control_get_device(struct led_classdev *led_cdev) +{ + struct netdev_led *netdev_led = to_netdev_led(led_cdev); + + return &netdev_led->ndev->dev; +} + +static int netdev_led_setup(struct net_device *ndev, struct device_node *led, + struct list_head *list, struct netdev_leds_ops *ops, + int max_leds) +{ + struct led_init_data init_data = {}; + struct device *dev = &ndev->dev; + struct netdev_led *netdev_led; + struct led_classdev *cdev; + u32 index; + int err; + + netdev_led = devm_kzalloc(dev, sizeof(*netdev_led), GFP_KERNEL); + if (!netdev_led) + return -ENOMEM; + + netdev_led->ndev = ndev; + netdev_led->ops = ops; + cdev = &netdev_led->led_cdev; + + err = of_property_read_u32(led, "reg", &index); + if (err) + return err; + + if (index >= max_leds) + return -EINVAL; + + netdev_led->index = index; + + if (ops->brightness_set) + cdev->brightness_set_blocking = netdev_brightness_set; + if (ops->blink_set) + cdev->blink_set = netdev_blink_set; +#ifdef CONFIG_LEDS_TRIGGERS + if (ops->hw_control_is_supported) + cdev->hw_control_is_supported = netdev_hw_control_is_supported; + if (ops->hw_control_set) + cdev->hw_control_set = netdev_hw_control_set; + if (ops->hw_control_get) + cdev->hw_control_get = netdev_hw_control_get; + cdev->hw_control_trigger = "netdev"; +#endif + cdev->hw_control_get_device = netdev_hw_control_get_device; + cdev->max_brightness = 1; + init_data.fwnode = of_fwnode_handle(led); + init_data.devname_mandatory = true; + + init_data.devicename = dev_name(dev); + err = devm_led_classdev_register_ext(dev, cdev, &init_data); + if (err) + return err; + + INIT_LIST_HEAD(&netdev_led->led_list); + list_add(&netdev_led->led_list, list); + + return 0; +} + +/** + * netdev_leds_setup - Parse DT node and create LEDs for netdev + * + * @ndev: struct netdev for the MAC + * @np: ethernet-node in device tree + * @list: list to add LEDs to + * @ops: structure of ops to manipulate the LED. + * @max_leds: maximum number of LEDs support by netdev. + * + * Parse the device tree node, as described in + * ethernet-controller.yaml, and find any LEDs. For each LED found, + * ensure the reg value is less than max_leds, create an LED and + * register it with the LED subsystem. The LED will be added to the + * list, which can be shared by all netdevs of the device. The ops + * structure contains the callbacks needed to control the LEDs. + * + * Return 0 in success, otherwise an negative error code. + */ +int netdev_leds_setup(struct net_device *ndev, struct device_node *np, + struct list_head *list, struct netdev_leds_ops *ops, + int max_leds) +{ + struct device_node *leds, *led; + int err; + + leds = of_get_child_by_name(np, "leds"); + if (!leds) + return 0; + + for_each_available_child_of_node(leds, led) { + err = netdev_led_setup(ndev, led, list, ops, max_leds); + if (err) { + of_node_put(led); + return err; + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(netdev_leds_setup); + +/** + * netdev_leds_teardown - Remove LEDs for a netdev + * + * @list: list to add LEDs to teardown + * @ndev: The netdev for which LEDs should be removed + * + * Unregister all LEDs for a given netdev, freeing up any allocated + * memory. + */ +void netdev_leds_teardown(struct list_head *list, struct net_device *ndev) +{ + struct netdev_led *netdev_led; + struct led_classdev *cdev; + struct device *dev; + + list_for_each_entry(netdev_led, list, led_list) { + if (netdev_led->ndev != ndev) + continue; + dev = &netdev_led->ndev->dev; + cdev = &netdev_led->led_cdev; + devm_led_classdev_unregister(dev, cdev); + } +} +EXPORT_SYMBOL_GPL(netdev_leds_teardown); From patchwork Mon Apr 1 13:35:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13612776 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AECD53FB07 for ; Mon, 1 Apr 2024 13:36:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711978578; cv=none; b=S9elZAYmF3i6pNXokQ6MHLeCzF3cDXMmAPUf2ocfIPfThcqtY2cWyUuFDrxszIpgIeFfcxSopCPnns0dpdEaTZigQM8hSrfWipAR6dKemrrvscFGGIevvw8JtYei7B3efSIAgQYO1UyMmZn+X9eyjUW2AqQgBq79xYiZh9oIpPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711978578; c=relaxed/simple; bh=Ba8ZRPcHIpN0lalX1MJan4IYyVadQnFD5BsiVvTcBu0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Hatuy41z38D/O/gO7pFSUz0yjfa7OYewWLQzlXKRtOrsWWGUJiOTBj8H92pYeRLyiKkP9wIC5g+J2dlRX7Eugn5gxKCy3BWGd/EyqnJUQZuD9ibRW6Z+z0ScoDGHbUHd5o81KwlV3DUENwunG4ZGjbotKtGxwCqJwMo7HBgbvps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=NpYGXAXQ; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="NpYGXAXQ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=horO3WQSlmE1YpmKxwySgRee+ScV5A7WgNw1ql2FvsM=; b=Np YGXAXQ3P9Piy5h+8ojpDaHbb5lgg45zrNZvJTSG2+eivvZgnJbuNb9YQp42Ej1ld7OIWu85HtZj8I bDGa23ddibORIIDrL/qzbtOaieKeedueU/DUADJizJ1ITzMBRAOppwUnGQ6q8kpVsOiFpYz9MddOP MVZ74Dwr54HnmDk=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rrHpd-00BrFx-CJ; Mon, 01 Apr 2024 15:36:13 +0200 From: Andrew Lunn Date: Mon, 01 Apr 2024 08:35:48 -0500 Subject: [PATCH net-next v3 3/7] net: dsa: mv88e6xxx: Add helpers for 6352 LED blink and brightness Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-3-221b3fa55f78@lunn.ch> References: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-0-221b3fa55f78@lunn.ch> In-Reply-To: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-0-221b3fa55f78@lunn.ch> To: Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Gregory Clement Cc: netdev@vger.kernel.org, Andrew Lunn X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=8530; i=andrew@lunn.ch; h=from:subject:message-id; bh=Ba8ZRPcHIpN0lalX1MJan4IYyVadQnFD5BsiVvTcBu0=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmCrhB/85He6vDXpBQGnKw40yi8zeNVOYzwlenQ HiFcEYb4DyJAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZgq4QQAKCRDmvw3LpmlM hLtwD/4sNDBVK/lmDrW2kUkLuXkenbWzTYeof7duj51W47y5mXNb+YgPsW75gNkgdPpNkSuDI4f mcqSMtlObCKxqwOFCYVr+teq34sQw2zaErlW8Ypozo9DxRhpN09BI+XEp1fKDZxjJawnv5FQXYw +9zmuEZRQsAVTRC3S/SRF1cVxf0MEon/jaJ5R638F0qQKpacfMJ9wRkGEiRZkxWrvpISfkMOEGC x/hMI0lBgADOpv2mo0Ri46nfV8B+k9jU1zskPrUEhqT8eqK23GRY0NoIrw4//bGzfPi4j1AvSB5 Bqi1EyjHH+BBWN86ORjZQxE/Zqf0Xr+XfimCCyic0v3JPZ5rKb4joRUOnK3UWlzZq1zIN06ocBl NUix+MbwQUOBn6/4IZdBQztuNWmJ2IzfckYZJXEta99yqrpnmnw2mvJ1h/f0tmZJBuu+FrBsr12 usu5btLwZLqt/NUJVaAqqGacuD5nGMmENwanv2DtbO9ySTS3ZWr2EdtA0SXWeMxLcTv7kRvHtgF nSGyeatjqrxw+ZVHlJIXp2YCJKoargHYgy2zVd9H+PB5sB2bk2e/cdUtFgYiJaRE2zC9reGITRl 9ii/COMH2mC2ERp0FUkkXlhTQZvfGIcsSc+IsDFnRPtciNqZNd3LMMShuOV9dypYduB4kV5XrzT c9cdAZEZylBTtEA== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org The 6352 family has two LEDs per port for ports 0-4. Ports 5 and 6 share a couple of LEDs. Add support functions to set the brightness, i.e. on or off, and to make the LEDs blink at a fixed rate. Signed-off-by: Andrew Lunn --- drivers/net/dsa/mv88e6xxx/port.c | 93 ++++++++++++++++++++++++++++++++++++++++ drivers/net/dsa/mv88e6xxx/port.h | 76 +++++++++++++++++++++++++++++++- 2 files changed, 168 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/mv88e6xxx/port.c b/drivers/net/dsa/mv88e6xxx/port.c index 5394a8cf7bf1..37315a4aa9cf 100644 --- a/drivers/net/dsa/mv88e6xxx/port.c +++ b/drivers/net/dsa/mv88e6xxx/port.c @@ -1723,3 +1723,96 @@ int mv88e6393x_port_set_policy(struct mv88e6xxx_chip *chip, int port, return mv88e6393x_port_policy_write(chip, port, ptr, reg); } + +/* Offset 0x16: LED Control Register */ + +static int mv88e6352_port_led_write(struct mv88e6xxx_chip *chip, int port, + u16 pointer, u16 data) +{ + u16 reg = MV88E6352_PORT_LED_CTL_UPDATE | pointer | data; + + return mv88e6xxx_port_write(chip, port, MV88E6352_PORT_LED_CTL, reg); +} + +static int mv88e6352_port_led_read(struct mv88e6xxx_chip *chip, int port, + u16 pointer, u16 *data) +{ + int err; + u16 val; + + err = mv88e6xxx_port_write(chip, port, MV88E6352_PORT_LED_CTL, pointer); + if (err) + return err; + + err = mv88e6xxx_port_read(chip, port, MV88E6352_PORT_LED_CTL, &val); + if (err) + return err; + + *data = val & MV88E6352_PORT_LED_CTL_DATA_MASK; + + return 0; +} + +int mv88e6352_port_led_brightness_set(struct mv88e6xxx_chip *chip, int port, + u8 led, enum led_brightness value) +{ + int err; + u16 val; + + if (port > 5) + return -EOPNOTSUPP; + + err = mv88e6352_port_led_read(chip, port, + MV88E6352_PORT_LED_CTL_PTR_LED01, + &val); + if (err) + return err; + + if (led == 0) { + val &= ~MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_MASK; + if (value) + val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_ON; + else + val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_OFF; + } else { + val &= ~MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_MASK; + if (value) + val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_ON; + else + val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_OFF; + } + return mv88e6352_port_led_write(chip, port, + MV88E6352_PORT_LED_CTL_PTR_LED01, + val); +} + +int mv88e6352_port_led_blink_set(struct mv88e6xxx_chip *chip, int port, u8 led, + unsigned long *delay_on, + unsigned long *delay_off) +{ + int err; + u16 val; + + if (port > 5) + return -EOPNOTSUPP; + + /* Reset default is 84ms */ + *delay_on = 84 / 2; + *delay_off = 84 / 2; + err = mv88e6352_port_led_read(chip, port, + MV88E6352_PORT_LED_CTL_PTR_LED01, + &val); + if (err) + return err; + + if (led == 0) { + val &= ~MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_MASK; + val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_BLINK; + } else { + val &= ~MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_MASK; + val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_BLINK; + } + return mv88e6352_port_led_write(chip, port, + MV88E6352_PORT_LED_CTL_PTR_LED01, + val); +} diff --git a/drivers/net/dsa/mv88e6xxx/port.h b/drivers/net/dsa/mv88e6xxx/port.h index 86deeb347cbc..72556e4d154c 100644 --- a/drivers/net/dsa/mv88e6xxx/port.h +++ b/drivers/net/dsa/mv88e6xxx/port.h @@ -294,6 +294,76 @@ /* Offset 0x13: OutFiltered Counter */ #define MV88E6XXX_PORT_OUT_FILTERED 0x13 +/* Offset 0x16: LED Control */ +#define MV88E6352_PORT_LED_CTL 0x16 +#define MV88E6352_PORT_LED_CTL_UPDATE 0x8000 +#define MV88E6352_PORT_LED_CTL_PTR_LED01 0x0000 +#define MV88E6352_PORT_LED_CTL_PTR_STRETCH_BLINK 0x6000 +#define MV88E6352_PORT_LED_CTL_PTR_SPECIAL 0x7000 +#define MV88E6352_PORT_LED_CTL_DATA_MASK 0x03ff +/* Ports 0-4 */ +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_P2_SPECIAL 0x0000 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_10_100_ACT 0x0010 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_1000 0x0030 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_P1_SPECIAL 0x0040 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_10_1000_ACT 0x0060 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_10_1000 0x0070 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_ACT 0x0080 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_100 0x0090 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_100_ACT 0x00A0 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_10_100 0x00B0 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_PTP_ACT 0x00C0 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_BLINK 0x00D0 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_OFF 0x00E0 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_ON 0x00F0 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_MASK 0x00F0 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_LINK_ACT 0x0000 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_100_1000_ACT 0x0001 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_1000_ACT 0x0002 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_LINK_ACT 0x0003 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_P0_SPECIAL 0x0004 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_DUPLEX_COL 0x0006 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_10_1000_ACT 0x0007 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_LINK 0x0008 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_10 0x0009 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_10_ACT 0x000A +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_100_1000 0x000B +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_PTP_ACT 0x000C +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_BLINK 0x000D +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_OFF 0x000E +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_ON 0x000F +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_MASK 0x000F + +/* Port 5 */ +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P6_ACT 0x0000 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_FIBER_1000_ACT 0x0010 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_FIBER_100_ACT 0x0020 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_FIBER 0x0030 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P5_ACT 0x0040 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P6_LINK 0x0050 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P6_DUPLEX_COL 0x0060 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P6_LINK_ACT 0x0070 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P0_SPECIAL 0x0080 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P1_SPECIAL 0x0090 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P2_SPECIAL 0x00A0 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P6_PTP_ACT 0x00C0 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_BLINK 0x00D0 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_OFF 0x00E0 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_ON 0x00F0 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P5_LINK_ACT 0x0000 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_FIBER_100_ACT 0x0001 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_FIBER_1000_ACT 0x0002 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P0_SPECIAL 0x0003 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P1_SPECIAL 0x0004 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P2_SPECIAL 0x0005 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P5_DUPLEX_COL 0x0006 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P5_LINK_ACT 0x0007 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P6_LINK_ACT 0x0008 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_BLINK 0x000D +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_OFF 0x000E +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_ON 0x000F +/* Port 6 does not have any LEDs */ + /* Offset 0x18: IEEE Priority Mapping Table */ #define MV88E6390_PORT_IEEE_PRIO_MAP_TABLE 0x18 #define MV88E6390_PORT_IEEE_PRIO_MAP_TABLE_UPDATE 0x8000 @@ -459,5 +529,9 @@ int mv88e6xxx_port_hidden_write(struct mv88e6xxx_chip *chip, int block, int mv88e6xxx_port_hidden_wait(struct mv88e6xxx_chip *chip); int mv88e6xxx_port_hidden_read(struct mv88e6xxx_chip *chip, int block, int port, int reg, u16 *val); - +int mv88e6352_port_led_brightness_set(struct mv88e6xxx_chip *chip, int port, + u8 led, enum led_brightness value); +int mv88e6352_port_led_blink_set(struct mv88e6xxx_chip *chip, int port, u8 led, + unsigned long *delay_on, + unsigned long *delay_off); #endif /* _MV88E6XXX_PORT_H */ From patchwork Mon Apr 1 13:35:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13612777 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6778B3FE4E for ; Mon, 1 Apr 2024 13:36:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711978580; cv=none; b=eEo1j1Lo8YUVy8i/dJnj8iP4kBOhjW9mxos9cqBZwjlCdew5VGqjgb3XxhSEnLOp0IhelcblN371olkjiBvyVekyphu4ik04aqICkTA9Fy23qgZOLWedsxWhU7vHul4JFhMiSMflBktt/IY0G3bm8FxRSn5kOr6pJpuELdcgLn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711978580; c=relaxed/simple; bh=7REgVx3Hk+G70l5YOIE6zqEavzl38e/93gZxmXsSzgA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Xv9XDdTMEFw38jR5RMS9Dz/ksaXTdB0+Lf/vtdcpFO+dAy1QW7Up8p5tIOqxFNqphPm2e1HNAwuBr252xd4wL0w1vcmCPQpYBnQt3YA1rn2Vz2nhDDsz+ew1bUEr1h4EAFy9MD++68cu9WCrygrWUxVME7G/Yj+J7cZ2aEvhS1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=Poocr3tk; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="Poocr3tk" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=iHiJcTca4uqI5eVNh//6Wjc2B/iJjDsQUALvb+o+t0E=; b=Po ocr3tkyLPkg3N+hoDGTRSrZ6PNvTNNkVdkntXzDzepGW3b/a/lKItLCgM5krZvNPgXawiZ/lF6u47 wavDlJ/n/iLAJmBUaIzNcRFLJWIUSNKB5KFZsFyE6z2Ij3UtebNkNJE80xBT6heXyby/MVMwGG79f QtHbNTnmPWoEYnk=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rrHpg-00BrFx-1P; Mon, 01 Apr 2024 15:36:16 +0200 From: Andrew Lunn Date: Mon, 01 Apr 2024 08:35:49 -0500 Subject: [PATCH net-next v3 4/7] net: dsa: mv88e6xxx: Tie the low level LED functions to device ops Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-4-221b3fa55f78@lunn.ch> References: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-0-221b3fa55f78@lunn.ch> In-Reply-To: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-0-221b3fa55f78@lunn.ch> To: Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Gregory Clement Cc: netdev@vger.kernel.org, Andrew Lunn X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2653; i=andrew@lunn.ch; h=from:subject:message-id; bh=7REgVx3Hk+G70l5YOIE6zqEavzl38e/93gZxmXsSzgA=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmCrhB9wF3ybn7TCaOpEb7fjn1iMtO7rJEbtu76 JQuF3uIKK2JAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZgq4QQAKCRDmvw3LpmlM hEiLEADLqQiIKohfK7o2nAsg4K1R2RrqA29D5aBEGqHOBnZjBFKxwzSbMKC7e2+I8RvaOIGGfL1 HtU2Z12CVUOhZYUBsJkM6Rj9geMWhXLOoL9qmAZpdbm30MgezxWpZvIpAFKRDhfizQVh5FlNvfP d1qefbEp3HH0F1KF1OPDpl7cy9aVj8ny+TJysILy2VWIxQCTQNGzGGPofTz9ZV2rG03lsgqPK/r MKvMCgKc49q07VcC63kGZ2hgo3yjlHcGM8VpUujG80TuB8I6XyWFCDudZFmc6/smHkSTmkD/6E9 51QIdVMz78kL1iqT8xX4yPjKbjTSoOMRoZOWQF1LujMA6NII4vPkKKDL5nv8PHYQV1s+vAltWlW QDo6VKPLmf3d/2ouz1hbDgSbrU1Jsmvob7isIHhMXLa4MSdfBWblYEqL1o9XxvsBsEiImwQeN9c SL/JhR572A9MMg4Owpn6WAbU/MrsKy9bOJplMfnlA6LVFJBjtXGia5vQT5zBuwMojSk/zA2vdZJ Cni+5tkw86BJ/oDAxpp1p6bpp+tiTrnmLRks0uZMiH9T/N/Eesak41hMFcFYrHagCIAWncfY7SL 8uwZTLZYYUXaISna3SO/rpkLFo2J5JmLeN/QdQO87Z8Wxf0jSRtNeZ+UFkPBzZhJagvdNOUsbbF XDsHS0BVznEBWPA== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org Make the LED brightness and blink helpers available for the 6352 family via their ops structure. Signed-off-by: Andrew Lunn --- drivers/net/dsa/mv88e6xxx/chip.c | 8 ++++++++ drivers/net/dsa/mv88e6xxx/chip.h | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 9ed1821184ec..3d7e4aa9293a 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -4526,6 +4526,8 @@ static const struct mv88e6xxx_ops mv88e6172_ops = { .gpio_ops = &mv88e6352_gpio_ops, .phylink_get_caps = mv88e6352_phylink_get_caps, .pcs_ops = &mv88e6352_pcs_ops, + .led_brightness_set = mv88e6352_port_led_brightness_set, + .led_blink_set = mv88e6352_port_led_blink_set, }; static const struct mv88e6xxx_ops mv88e6175_ops = { @@ -4628,6 +4630,8 @@ static const struct mv88e6xxx_ops mv88e6176_ops = { .gpio_ops = &mv88e6352_gpio_ops, .phylink_get_caps = mv88e6352_phylink_get_caps, .pcs_ops = &mv88e6352_pcs_ops, + .led_brightness_set = mv88e6352_port_led_brightness_set, + .led_blink_set = mv88e6352_port_led_blink_set, }; static const struct mv88e6xxx_ops mv88e6185_ops = { @@ -4897,6 +4901,8 @@ static const struct mv88e6xxx_ops mv88e6240_ops = { .ptp_ops = &mv88e6352_ptp_ops, .phylink_get_caps = mv88e6352_phylink_get_caps, .pcs_ops = &mv88e6352_pcs_ops, + .led_brightness_set = mv88e6352_port_led_brightness_set, + .led_blink_set = mv88e6352_port_led_blink_set, }; static const struct mv88e6xxx_ops mv88e6250_ops = { @@ -5310,6 +5316,8 @@ static const struct mv88e6xxx_ops mv88e6352_ops = { .serdes_set_tx_amplitude = mv88e6352_serdes_set_tx_amplitude, .phylink_get_caps = mv88e6352_phylink_get_caps, .pcs_ops = &mv88e6352_pcs_ops, + .led_brightness_set = mv88e6352_port_led_brightness_set, + .led_blink_set = mv88e6352_port_led_blink_set, }; static const struct mv88e6xxx_ops mv88e6390_ops = { diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h index 85eb293381a7..64f8bde68ccf 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.h +++ b/drivers/net/dsa/mv88e6xxx/chip.h @@ -661,6 +661,13 @@ struct mv88e6xxx_ops { /* Max Frame Size */ int (*set_max_frame_size)(struct mv88e6xxx_chip *chip, int mtu); + + /* LEDs */ + int (*led_brightness_set)(struct mv88e6xxx_chip *chip, int port, + u8 led, enum led_brightness value); + int (*led_blink_set)(struct mv88e6xxx_chip *chip, int port, u8 led, + unsigned long *delay_on, + unsigned long *delay_off); }; struct mv88e6xxx_irq_ops { From patchwork Mon Apr 1 13:35:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13612778 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13FB8405E5 for ; Mon, 1 Apr 2024 13:36:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711978583; cv=none; b=RXyPhlvfo7+rSiI0As9LyThihfqTBOoSQSXp/yrUz2l0fCmFaKaSZeuhH4FJ9oFFHxWfKMe9tifbXw6CRPF/32w2ksAFgnK66ei04nf5p/HE9XMLOdaYuJt8FoFwB3lVJz4ITdhG2KVKhehEN5dgppYN30g3Do3bGphpqTUT8fk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711978583; c=relaxed/simple; bh=jN06A6RN74/A9JG07iAr7h9U1L7CPt7cjU7nOZyzbGA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gkKSFjt/2zjPRyP4fwteHgoueS2OVU1lDZhF84PGt246GNv9HdY78v9q1tuynFU0+RV/aiJxukjkdeCACJqk7UIgVzmd/5LjrkX4UAlyU05Cw6zPyjr8Hc2zIOTsHNQhxm+cCR6oXuYZs9Lo6gX8YWJSUbUOiOAGi2JBwJWE8YM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=3hp1xPFa; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="3hp1xPFa" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=jQR7P1Q5Se8GixNYzr/FafPy3P2nvqlYT8DftTiAOhc=; b=3h p1xPFaU1c4TOza0+KDUC8watsZuPK7hM0fC32OJoOd2RSDfv+ZeTs/yBQdcoLgZBa5jeKP6PtC87X LPc9k+s+0b7gPgtWQj7HC9tngLcZCdUgI0YSbny55I+6AhHZV/Rc9QgOUckN5QuEsXhLXF7p8phkp b0gRkv7PX+cQhq4=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rrHpi-00BrFx-Ml; Mon, 01 Apr 2024 15:36:18 +0200 From: Andrew Lunn Date: Mon, 01 Apr 2024 08:35:50 -0500 Subject: [PATCH net-next v3 5/7] net: dsa: Add helpers to convert netdev to ds or port index Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-5-221b3fa55f78@lunn.ch> References: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-0-221b3fa55f78@lunn.ch> In-Reply-To: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-0-221b3fa55f78@lunn.ch> To: Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Gregory Clement Cc: netdev@vger.kernel.org, Andrew Lunn X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2468; i=andrew@lunn.ch; h=from:subject:message-id; bh=jN06A6RN74/A9JG07iAr7h9U1L7CPt7cjU7nOZyzbGA=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmCrhBnnKaJbOApBkClkmls/TXY7PaiauY4t9Fe 0TM8gsvRq2JAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZgq4QQAKCRDmvw3LpmlM hMmED/4+YWkQ02dThPIkLxgXMULXMwkFnQUD7EsGnDGcffufN7MvmiAw9lD88YyvWu5XHNkpUhA 3J7tnGfUd8N9l2slKiUQZKhjHjXfoIduFs08yYSgPLnA/BV57U7RS7leK/N8EdvIUS+y4HyDc9T IRY0DKuBr3Adh6TlS8jjZ3Jnznd+s2VYX4N5YqREwrYV9TJsl4oIk/TSdVMZhrKjIvJVExZqy2F u1TUntNktdQWqgrJtvTxxhmCkLO26mIcne+C0Ut2s/0ucU2yget51WIMMX4csj7Xp/D8JMd9itG gwqsF58R0q9lT1yaQkkIfamnlvusGZmDXSc69IwzEb+sJjXuefJUCfMk1/3WO7/W+FTFzMMdDi5 QJAu190/BB0XDrOhoYWeq9nX20Di2XnAd1AXbmjVdRofaTDYQmrTizhIg3xAQXiSBMD3M+8Qw/R UDuscG2V4XuOb5Ke76F4LNT4lZ6Q9B9vH1q2J0FMwshWCtQeAR4y0/sxbnDuU+jtToVq2w6m7w5 ukSgYdSRaE4rwk5VcFFY7INmHOI4dLNMuCmDs3G0q2iAAXXHnVy8q5YEXo6Nh3tB0EjUPdmluTU C+YAPRiULEbcG5HTR0HrwCqx7Vm+F0lBHau6ZSzZHU4ZX+9UwvI6W+NsgX/FSYLry9WLmF22+z0 MLWJTBDc/YeAvDw== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org The LED helpers make use of a struct netdev. Add helpers a DSA driver can use to convert a netdev to a struct dsa_switch and the port index. To do this, dsa_user_to_port() has to be made available out side of net/dev, to convert the inline function in net/dsa/user.h into a normal function, and export it. Signed-off-by: Andrew Lunn --- include/net/dsa.h | 17 +++++++++++++++++ net/dsa/user.c | 8 ++++++++ net/dsa/user.h | 7 ------- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index 7c0da9effe4e..1fbfada6678d 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -1359,6 +1359,23 @@ int dsa_register_switch(struct dsa_switch *ds); void dsa_switch_shutdown(struct dsa_switch *ds); struct dsa_switch *dsa_switch_find(int tree_index, int sw_index); void dsa_flush_workqueue(void); + +struct dsa_port *dsa_user_to_port(const struct net_device *dev); + +static inline struct dsa_switch *dsa_user_to_ds(const struct net_device *ndev) +{ + struct dsa_port *dp = dsa_user_to_port(ndev); + + return dp->ds; +} + +static inline unsigned int dsa_user_to_index(const struct net_device *ndev) +{ + struct dsa_port *dp = dsa_user_to_port(ndev); + + return dp->index; +} + #ifdef CONFIG_PM_SLEEP int dsa_switch_suspend(struct dsa_switch *ds); int dsa_switch_resume(struct dsa_switch *ds); diff --git a/net/dsa/user.c b/net/dsa/user.c index 16d395bb1a1f..bbee3f63e2c7 100644 --- a/net/dsa/user.c +++ b/net/dsa/user.c @@ -3699,3 +3699,11 @@ void dsa_user_unregister_notifier(void) if (err) pr_err("DSA: failed to unregister user notifier (%d)\n", err); } + +struct dsa_port *dsa_user_to_port(const struct net_device *dev) +{ + struct dsa_user_priv *p = netdev_priv(dev); + + return p->dp; +} +EXPORT_SYMBOL_GPL(dsa_user_to_port); diff --git a/net/dsa/user.h b/net/dsa/user.h index 996069130bea..b6bcf027643e 100644 --- a/net/dsa/user.h +++ b/net/dsa/user.h @@ -51,13 +51,6 @@ int dsa_user_change_conduit(struct net_device *dev, struct net_device *conduit, int dsa_user_manage_vlan_filtering(struct net_device *dev, bool vlan_filtering); -static inline struct dsa_port *dsa_user_to_port(const struct net_device *dev) -{ - struct dsa_user_priv *p = netdev_priv(dev); - - return p->dp; -} - static inline struct net_device * dsa_user_to_conduit(const struct net_device *dev) { From patchwork Mon Apr 1 13:35:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13612779 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CB233F9C8 for ; Mon, 1 Apr 2024 13:36:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711978586; cv=none; b=qhqsYlKye7sOrR1T99fkgsKqZjV4PEy7bo9DnlbPqiuHGOBQR5HckByMooFthaoAKw7etT57fv/bvKvl1q9ODYHO0nPgodK6eWBjLaBwMZ6Wl+GwI6Pk61bIwZW6XbD1matRNdAUtgJQ2YZUb0KIOZLy4KHfWiAUKoSYGFynegQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711978586; c=relaxed/simple; bh=eyWWTxPoudNlAZdERrOv9Bwe45r32AgBYq27NFhVTt4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aM4ftW7SkWOWFtzb/jTjhrCOwPqeJA9TW7uEp/5Lq8nLaifOO9qGtYjwL5loSumDs8m9lTAAo+ZjVW37B3KBjzKZkHeN5j//+uE6iXSAnyjAsd6X7Tf9vQYu6DFz2ZqiF0JGRXvnw7AhPmI0OZ/harVAPDKKS5krpNjTx/lCcuw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=lbLQng5Q; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="lbLQng5Q" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=88VDQyfelWFzdQfAlUflPNZGjeED3LV01VuBtwMW+6Y=; b=lb LQng5QwlyWowf/DMjWM2MQAIAIgYY9WfTvMejDDdnlg9uaTJv5fdyAASGs32Wepxdxq08k5QgdnJo Q3hxS9rTH9luDkdaMz4rRXgTjcGF+7FXKFp63fz1UmDZpM0J+25FgVFAHHyRG9JJwUC0XbbdtPyR1 P+F8KihBwTPl+e8=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rrHpl-00BrFx-CB; Mon, 01 Apr 2024 15:36:21 +0200 From: Andrew Lunn Date: Mon, 01 Apr 2024 08:35:51 -0500 Subject: [PATCH net-next v3 6/7] dsa: mv88e6xxx: Create port/netdev LEDs Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-6-221b3fa55f78@lunn.ch> References: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-0-221b3fa55f78@lunn.ch> In-Reply-To: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-0-221b3fa55f78@lunn.ch> To: Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Gregory Clement Cc: netdev@vger.kernel.org, Andrew Lunn X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6701; i=andrew@lunn.ch; h=from:subject:message-id; bh=eyWWTxPoudNlAZdERrOv9Bwe45r32AgBYq27NFhVTt4=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmCrhCzFukQX+FFU3w4DTGz1lP4VItn8JWPGO4V EJDb2zRammJAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZgq4QgAKCRDmvw3LpmlM hLYkEACMd5aJmwkRTVBaPkh2MqInna8l2zlG0NJjlWh5mOKg4YkHWiXphM1g+i9HrDk1L31+Zmt mX04vm6C9HjFauTTiLY8naOIJkKXlhPhx6hGSdbAeb5+bouZiVHZLhTEc6nIC+6+8tJTUFx1+qD 0Kv/18Fi9mbrIH54WBGsRRLbvrUBYd1C4bTLaDdXCtNdNfVrKmmzuoaZaSk3jwCdRpztHVLANsH /5nUAQZnozNJwrIOhRf32+cezeP7uV/aj3ig4gffeDqQuhfM/cR3wSaUODWLLwwL4hHPu3vX2vT CtDeoONCmfhR8Ylq7fr/J0X0ZXYdauFReH1RWgOYmmujGaLEcBXGA2vLVny23aDuqIA0EEemlVE QIqrW0xzln083v0aqsCv04Uh+8crhFNl0NE/UZI8G9zSJ/l8bHRuA4wwGPqV2taHmPOHyl1big2 GNoGxylLd1cmLuXAWh3qqu8BJbjzdTwwugfQsVDRjSLZIpRxwc4gQNeYCP3IM5aIbq7ZK9JxCKy OWAhBP1+R5EL1MtzQWvABvezlONB8vkY20JEX2WbsQT/Uwybdmy8WxyMDNrrjxwGm8lzH9p0EKT bczCHEvCV0nfvHWoNo+dk1w+yOoRZREPwoGJB+KIOxeQdtjWika9h7qLiGFkCg5IMMc004rcoQ5 wnHt1w7E5N7i6LQ== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org Make use of the helpers to add LEDs to the user ports when the port is setup. Signed-off-by: Andrew Lunn --- drivers/net/dsa/mv88e6xxx/Kconfig | 1 + drivers/net/dsa/mv88e6xxx/chip.c | 117 +++++++++++++++++++++++++++++++++++++- drivers/net/dsa/mv88e6xxx/chip.h | 12 ++++ 3 files changed, 129 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/mv88e6xxx/Kconfig b/drivers/net/dsa/mv88e6xxx/Kconfig index e3181d5471df..ded5c6b9132b 100644 --- a/drivers/net/dsa/mv88e6xxx/Kconfig +++ b/drivers/net/dsa/mv88e6xxx/Kconfig @@ -5,6 +5,7 @@ config NET_DSA_MV88E6XXX select IRQ_DOMAIN select NET_DSA_TAG_EDSA select NET_DSA_TAG_DSA + select NETDEV_LEDS help This driver adds support for most of the Marvell 88E6xxx models of Ethernet switch chips, except 88E6060. diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 3d7e4aa9293a..b8e39dcad2da 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "chip.h" #include "devlink.h" @@ -3129,6 +3130,105 @@ static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip) return mv88e6xxx_software_reset(chip); } +static int mv88e6xxx_led_brightness_set(struct net_device *ndev, + u8 led, enum led_brightness value) +{ + struct dsa_switch *ds = dsa_user_to_ds(ndev); + struct mv88e6xxx_chip *chip = ds->priv; + int port = dsa_user_to_index(ndev); + int err; + + if (chip->info->ops->led_brightness_set) { + mv88e6xxx_reg_lock(chip); + err = chip->info->ops->led_brightness_set(chip, port, led, + value); + mv88e6xxx_reg_unlock(chip); + return err; + } + return -EOPNOTSUPP; +} + +static int mv88e6xxx_led_blink_set(struct net_device *ndev, u8 led, + unsigned long *delay_on, + unsigned long *delay_off) +{ + struct dsa_switch *ds = dsa_user_to_ds(ndev); + struct mv88e6xxx_chip *chip = ds->priv; + int port = dsa_user_to_index(ndev); + int err; + + if (chip->info->ops->led_blink_set) { + mv88e6xxx_reg_lock(chip); + err = chip->info->ops->led_blink_set(chip, port, led, + delay_on, delay_off); + mv88e6xxx_reg_unlock(chip); + return err; + } + return -EOPNOTSUPP; +} + +static int mv88e6xxx_led_hw_control_is_supported(struct net_device *ndev, + u8 led, unsigned long flags) +{ + struct dsa_switch *ds = dsa_user_to_ds(ndev); + struct mv88e6xxx_chip *chip = ds->priv; + int port = dsa_user_to_index(ndev); + int err; + + if (chip->info->ops->led_hw_control_is_supported) { + mv88e6xxx_reg_lock(chip); + err = chip->info->ops->led_hw_control_is_supported(chip, port, + led, flags); + mv88e6xxx_reg_unlock(chip); + return err; + } + return -EOPNOTSUPP; +} + +static int mv88e6xxx_led_hw_control_set(struct net_device *ndev, u8 led, + unsigned long flags) +{ + struct dsa_switch *ds = dsa_user_to_ds(ndev); + struct mv88e6xxx_chip *chip = ds->priv; + int port = dsa_user_to_index(ndev); + int err; + + if (chip->info->ops->led_hw_control_set) { + mv88e6xxx_reg_lock(chip); + err = chip->info->ops->led_hw_control_set(chip, port, + led, flags); + mv88e6xxx_reg_unlock(chip); + return err; + } + return -EOPNOTSUPP; +} + +static int mv88e6xxx_led_hw_control_get(struct net_device *ndev, + u8 led, unsigned long *flags) +{ + struct dsa_switch *ds = dsa_user_to_ds(ndev); + struct mv88e6xxx_chip *chip = ds->priv; + int port = dsa_user_to_index(ndev); + int err; + + if (chip->info->ops->led_hw_control_get) { + mv88e6xxx_reg_lock(chip); + err = chip->info->ops->led_hw_control_get(chip, port, + led, flags); + mv88e6xxx_reg_unlock(chip); + return err; + } + return -EOPNOTSUPP; +} + +static struct netdev_leds_ops mv88e6xxx_netdev_leds_ops = { + .brightness_set = mv88e6xxx_led_brightness_set, + .blink_set = mv88e6xxx_led_blink_set, + .hw_control_is_supported = mv88e6xxx_led_hw_control_is_supported, + .hw_control_set = mv88e6xxx_led_hw_control_set, + .hw_control_get = mv88e6xxx_led_hw_control_get, +}; + static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port, enum mv88e6xxx_frame_mode frame, enum mv88e6xxx_egress_mode egress, u16 etype) @@ -4006,6 +4106,7 @@ static int mv88e6xxx_setup(struct dsa_switch *ds) static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port) { + struct dsa_port *dp = dsa_to_port(ds, port); struct mv88e6xxx_chip *chip = ds->priv; int err; @@ -4016,13 +4117,26 @@ static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port) return err; } - return mv88e6xxx_setup_devlink_regions_port(ds, port); + err = mv88e6xxx_setup_devlink_regions_port(ds, port); + if (err) + return err; + + if (dp->dn) { + err = netdev_leds_setup(dp->user, dp->dn, &chip->leds, + &mv88e6xxx_netdev_leds_ops, 2); + if (err) + mv88e6xxx_teardown_devlink_regions_port(ds, port); + } + return err; } static void mv88e6xxx_port_teardown(struct dsa_switch *ds, int port) { + struct dsa_port *dp = dsa_to_port(ds, port); struct mv88e6xxx_chip *chip = ds->priv; + netdev_leds_teardown(&chip->leds, dp->user); + mv88e6xxx_teardown_devlink_regions_port(ds, port); if (chip->info->ops->pcs_ops && @@ -6397,6 +6511,7 @@ static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev) INIT_LIST_HEAD(&chip->mdios); idr_init(&chip->policies); INIT_LIST_HEAD(&chip->msts); + INIT_LIST_HEAD(&chip->leds); return chip; } diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h index 64f8bde68ccf..b70e74203b31 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.h +++ b/drivers/net/dsa/mv88e6xxx/chip.h @@ -432,6 +432,9 @@ struct mv88e6xxx_chip { /* Bridge MST to SID mappings */ struct list_head msts; + + /* LEDs associated to the ports */ + struct list_head leds; }; struct mv88e6xxx_bus_ops { @@ -668,6 +671,15 @@ struct mv88e6xxx_ops { int (*led_blink_set)(struct mv88e6xxx_chip *chip, int port, u8 led, unsigned long *delay_on, unsigned long *delay_off); + int (*led_hw_control_is_supported)(struct mv88e6xxx_chip *chip, + int port, u8 led, + unsigned long flags); + int (*led_hw_control_set)(struct mv88e6xxx_chip *chip, + int port, u8 led, + unsigned long flags); + int (*led_hw_control_get)(struct mv88e6xxx_chip *chip, + int port, u8 led, + unsigned long *flags); }; struct mv88e6xxx_irq_ops { From patchwork Mon Apr 1 13:35:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13612780 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5456A4085E for ; Mon, 1 Apr 2024 13:36:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711978588; cv=none; b=EUA2UfOYErzAnK33z12tponyVPS4rdDUC3zoOb/fpcw59s2vofXaKfDVMLUF5f5rEdJarbANA/Y/WpqW3qHLKRDnbZuG1z7++gbVoRCGUQwqr+EnoYEduH7vPyGkrsP9Et8DZS6FznkEwj4OUBHogNoq1InxDarXA9S932XauoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711978588; c=relaxed/simple; bh=T4hHSCqSyUP8uN3eUppXBTMJHEC7jNr+/N/npfR2Ba4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OwzvSnyaH51ekAkgVnuCwVTtenA95ful2ieal+wQJ94zr79/Hqv/FL4fKRj7/ftyBffYnEwD1SR0Cz5uP/KjW5adyUWEBo2sZlPW8Q8w99VEJb40h77QHPqqmyeGlZditaymbY77yD/qmMSm7FX1aI/s9nFMQHUAoJaMKv8Dpfc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=K9szebRD; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="K9szebRD" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=3YRt0gr+yx7yiv5+KJ+D1BgjqflOQhh375/OUfItcZA=; b=K9 szebRDVPARXusir2d9lpp/4EmgcYJ0NwjiNcM7XCd3RyJ+duqhtCdYtAN38/Hjvdvlb6371QeXK8j LPBs8cJf0SjH7DGH3idBt26Rf3Ye1QHhEHyN5nCQCkYCktTEmvdi1eH3KXWdpHXxMyZL6DfbJ57k8 28mPwHPtJ13MSFE=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rrHpo-00BrFx-0z; Mon, 01 Apr 2024 15:36:24 +0200 From: Andrew Lunn Date: Mon, 01 Apr 2024 08:35:52 -0500 Subject: [PATCH net-next v3 7/7] arm: boot: dts: mvebu: linksys-mamba: Add Ethernet LEDs Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-7-221b3fa55f78@lunn.ch> References: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-0-221b3fa55f78@lunn.ch> In-Reply-To: <20240401-v6-8-0-net-next-mv88e6xxx-leds-v4-v3-0-221b3fa55f78@lunn.ch> To: Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Gregory Clement Cc: netdev@vger.kernel.org, Andrew Lunn X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2890; i=andrew@lunn.ch; h=from:subject:message-id; bh=T4hHSCqSyUP8uN3eUppXBTMJHEC7jNr+/N/npfR2Ba4=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmCrhCFqWZwVStP3xVRQLj3X3L+3pptgOf2vBmw cuWB49G5myJAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZgq4QgAKCRDmvw3LpmlM hMeyD/0VlIf2O/pDJsF+4o5KWIZkKhsQCVlvyv2IyvdWB/EjupeMTSYYYEVz2O8b5anZ+qlK4mC M6OSksVG8NmHQHODa/E5tUyfkVlbASqMsw2CkBkRze/Jrs6m/ob2doF45DukQVDIehlX47dUcIU Y0Rp4bzEggHAvNcvuCLiXyDYMpjABzpzHOt5TaiyXcL2g+OX9BMG2BZeeZOr6InOkd9t+uz+cpC H6Gnn3S98o2ZGjY4lJkFHuu2P7wwoNHINAZkSlK6KPSoaI2xrAM31osF0NnMbMRBfWgvxR8rcwB 7p1Btcy8qaHg3iNemae+z81dcseUgCkS/jldZy4gd0X6Q4SlDOT8ux2TQFCmvbwmTOC+3WOQTzK 4jAaZF09l89MKzKH4EEyC59Ln/JlVT307xFW77KBnbJMclzG00Br4zACVHHc3WPpDL3aiMWx+9k RvsgYdO0CXNFsh6u9lRdh0IOK9y5/NRA/gJmHdpNBdTcSu+G+0EmX/+UJcshtjTR7Lig4YLw529 MHKHLoxA4LqrZpt2j3BpyTDd9MFCgMIV3Qo4awB0f2b6yPIUJU3yr/bP1GAR0/rChIH4yy8yz/f 18W8gN9RE1TStJMkswPfUVh4QGp/63H+ulwUNleIhiFRzjLWJ8OR2e5UeLIEhZiIc2IU7o9gq99 pUtHEr/Mri7RtGw== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org List the front panel Ethernet LEDs in the switch section of the device tree. They can then be controlled via /sys/class/led/ The node contains a label property to influence the name of the LED. Without it, all the LEDs get the name lan:white, which classes, and so some get a number appended. lan:white_1, lan:white_2, etc. Using the label the LEDs are named lan1:front, lan2:front, lan3:front, where lanX indicates the interface name, and front indicates they are on the front of the box. Signed-off-by: Andrew Lunn --- .../boot/dts/marvell/armada-xp-linksys-mamba.dts | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/arch/arm/boot/dts/marvell/armada-xp-linksys-mamba.dts b/arch/arm/boot/dts/marvell/armada-xp-linksys-mamba.dts index ea859f7ea042..0784fd0355b2 100644 --- a/arch/arm/boot/dts/marvell/armada-xp-linksys-mamba.dts +++ b/arch/arm/boot/dts/marvell/armada-xp-linksys-mamba.dts @@ -19,6 +19,7 @@ /dts-v1/; #include #include +#include #include "armada-xp-mv78230.dtsi" / { @@ -276,26 +277,91 @@ ethernet-ports { ethernet-port@0 { reg = <0>; label = "lan4"; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = ; + function = LED_FUNCTION_LAN; + label = "front"; + default-state = "keep"; + }; + }; }; ethernet-port@1 { reg = <1>; label = "lan3"; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = ; + function = LED_FUNCTION_LAN; + label = "front"; + default-state = "keep"; + }; + }; }; ethernet-port@2 { reg = <2>; label = "lan2"; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = ; + function = LED_FUNCTION_LAN; + label = "front"; + default-state = "keep"; + }; + }; }; ethernet-port@3 { reg = <3>; label = "lan1"; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = ; + function = LED_FUNCTION_LAN; + label = "front"; + default-state = "keep"; + }; + }; }; ethernet-port@4 { reg = <4>; label = "internet"; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = ; + function = LED_FUNCTION_WAN; + label = "front"; + default-state = "keep"; + }; + }; }; ethernet-port@5 {