From patchwork Wed May 26 18:00:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12282495 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F89DC47088 for ; Wed, 26 May 2021 18:01:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D1CC613DC for ; Wed, 26 May 2021 18:01:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235337AbhEZSDI (ORCPT ); Wed, 26 May 2021 14:03:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:58504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234792AbhEZSDF (ORCPT ); Wed, 26 May 2021 14:03:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 95545613DC; Wed, 26 May 2021 18:01:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622052093; bh=FvskSE+fiFOQO8upGh0hC4EfFft4hH1AbDZuqNNLT6I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BX5lqq03/LuGedtbncYguYb4pdwrd2KwsA7mh8dJZ8yzkSGuzALlpebvHj9agcHLx NToEKPx2PicX/5utl9QekpgjHsEKubLhemoQX4aCGh/56YX7BSBpbP5ufPmycWr6Wl tLhinSCLAqpGz5Nma8lSvksHObSIuuUVDCgEZeewvTsl8H1cD9n870Xcrwk86QbuVr moGurAjBjVkLZSEhBj2z0a260afZYfz+1jtcH8zV7djPJGSsMw3UvwiHMwZKVLgwaz cPXmbTKLbI4Iwt9WICuuUFcbO7f7PBdlb8KnExlUOjhJkJfvJkFqZvUyLnSIa9o8U1 4kO3YnaWCKdVw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: linux-leds@vger.kernel.org Cc: netdev@vger.kernel.org, Pavel Machek , Dan Murphy , Russell King , Andrew Lunn , Matthias Schiffer , Jacek Anaszewski , Mauro Carvalho Chehab , =?utf-8?q?Marek_Beh?= =?utf-8?q?=C3=BAn?= Subject: [PATCH leds v1 1/5] leds: trigger: netdev: don't explicitly zero kzalloced data Date: Wed, 26 May 2021 20:00:16 +0200 Message-Id: <20210526180020.13557-2-kabel@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210526180020.13557-1-kabel@kernel.org> References: <20210526180020.13557-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The trigger_data struct is allocated with kzalloc, so we do not need to explicitly set members to zero. Signed-off-by: Marek Behún Acked-by: Pavel Machek Reviewed-by: Andrew Lunn --- drivers/leds/trigger/ledtrig-netdev.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index d5e774d83021..4f6b73e3b491 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -406,12 +406,8 @@ static int netdev_trig_activate(struct led_classdev *led_cdev) INIT_DELAYED_WORK(&trigger_data->work, netdev_trig_work); trigger_data->led_cdev = led_cdev; - trigger_data->net_dev = NULL; - trigger_data->device_name[0] = 0; - trigger_data->mode = 0; atomic_set(&trigger_data->interval, msecs_to_jiffies(50)); - trigger_data->last_activity = 0; led_set_trigger_data(led_cdev, trigger_data); From patchwork Wed May 26 18:00:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12282497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73197C47088 for ; Wed, 26 May 2021 18:01:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5295A613D7 for ; Wed, 26 May 2021 18:01:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235378AbhEZSDJ (ORCPT ); Wed, 26 May 2021 14:03:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:58572 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235272AbhEZSDH (ORCPT ); Wed, 26 May 2021 14:03:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B2BDF613C5; Wed, 26 May 2021 18:01:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622052095; bh=kbEZ5zXz08FpxCDhu351Q/y9lUjc6eLNagWCRQaDCQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T1m0ocqJn9/NPEs2ro1sRlRGNm3vMB0srBkKLuvHVhTGcWEHJpoVnAIqyHbXNr5tg qO6aFJdgTtF5QkLzJj0QaWdeImFSK2w1iPfh1N3T3BbhxpcRTF1VpXHrCaq9UJZ4Vn y3ec+WVqVlRSEUK0d5Epti2lz+xit70829gJ70ixb+57uSXnOWA3Q3G7+T2X7jQLNU VQgPwkbZcGdJo5XVilTKwegkk7Nw85NJJmyBTsYa3dcBdsAc49/ip6kgJluzvbhKaa 11gp+2B3ikSK5orvr5sZRC3PLbcjIz3uozSICCa04SWrQ7Rb06dBsSiOmP9TE+GgFd LdOaUN+VSiUBw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: linux-leds@vger.kernel.org Cc: netdev@vger.kernel.org, Pavel Machek , Dan Murphy , Russell King , Andrew Lunn , Matthias Schiffer , Jacek Anaszewski , Mauro Carvalho Chehab , =?utf-8?q?Marek_Beh?= =?utf-8?q?=C3=BAn?= Subject: [PATCH leds v1 2/5] leds: trigger: add API for HW offloading of triggers Date: Wed, 26 May 2021 20:00:17 +0200 Message-Id: <20210526180020.13557-3-kabel@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210526180020.13557-1-kabel@kernel.org> References: <20210526180020.13557-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add method trigger_offload() and member variable `offloaded` to struct led_classdev. Add helper functions led_trigger_offload() and led_trigger_offload_stop(). The trigger_offload() method, when implemented by the LED driver, should be called (via led_trigger_offload() function) from trigger code wanting to be offloaded at the moment when configuration of the trigger changes. If the trigger is successfully offloaded, this method returns 0 and the trigger does not have to blink the LED in software. If the trigger with given configuration cannot be offloaded, the method should return -EOPNOTSUPP, in which case the trigger must blink the LED in SW. The second argument to trigger_offload() being false means that the offloading is being disabled. In this case the function must return 0, errors are not permitted. Signed-off-by: Marek Behún --- Documentation/leds/leds-class.rst | 22 ++++++++++++++++++++++ drivers/leds/led-triggers.c | 1 + include/linux/leds.h | 29 +++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/Documentation/leds/leds-class.rst b/Documentation/leds/leds-class.rst index cd155ead8703..ebda64768e9d 100644 --- a/Documentation/leds/leds-class.rst +++ b/Documentation/leds/leds-class.rst @@ -169,6 +169,28 @@ Setting the brightness to zero with brightness_set() callback function should completely turn off the LED and cancel the previously programmed hardware blinking function, if any. +Hardware offloading of LED triggers +=================================== + +Some LEDs can offload SW triggers to hardware (for example a LED connected to +an ethernet PHY or an ethernet switch can be configured to blink on activity on +the network, which in software is done by the netdev trigger). + +To do such offloading, both the trigger code and LED driver must support this. +The LED must implement the trigger_offload() method and the trigger code must +try to call this method (via led_trigger_offload() function) when configuration +of the trigger (trigger_data) changes. + +The implementation of the trigger_offload() method by the LED driver must return +0 if the offload is successful and -EOPNOTSUPP if the requested trigger +configuration is not supported and the trigger should be executed in software. +If trigger_offload() returns negative value, the trigger will be done in +software, so any active offloading must also be disabled. + +If the second argument (enable) to the trigger_offload() method is false, any +active HW offloading must be deactivated. In this case errors are not permitted +in the trigger_offload() method. + Known Issues ============ diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index 4e7b78a84149..372980791b87 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -177,6 +177,7 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig) flags); cancel_work_sync(&led_cdev->set_brightness_work); led_stop_software_blink(led_cdev); + led_trigger_offload_stop(led_cdev); if (led_cdev->trigger->deactivate) led_cdev->trigger->deactivate(led_cdev); device_remove_groups(led_cdev->dev, led_cdev->trigger->groups); diff --git a/include/linux/leds.h b/include/linux/leds.h index 329fd914cf24..b331e7bceac3 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -148,6 +148,11 @@ struct led_classdev { /* LEDs that have private triggers have this set */ struct led_hw_trigger_type *trigger_type; + + /* some LEDs may be able to offload some SW triggers to HW */ + int (*trigger_offload)(struct led_classdev *led_cdev, + bool enable); + bool offloaded; #endif #ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED @@ -403,6 +408,30 @@ static inline void *led_get_trigger_data(struct led_classdev *led_cdev) return led_cdev->trigger_data; } +static inline int led_trigger_offload(struct led_classdev *led_cdev) +{ + int ret; + + if (!led_cdev->trigger_offload) + return -EOPNOTSUPP; + + ret = led_cdev->trigger_offload(led_cdev, true); + led_cdev->offloaded = !ret; + + return ret; +} + +static inline void led_trigger_offload_stop(struct led_classdev *led_cdev) +{ + if (!led_cdev->trigger_offload) + return; + + if (led_cdev->offloaded) { + led_cdev->trigger_offload(led_cdev, false); + led_cdev->offloaded = false; + } +} + /** * led_trigger_rename_static - rename a trigger * @name: the new trigger name From patchwork Wed May 26 18:00:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12282499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52911C4708A for ; Wed, 26 May 2021 18:01:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 396A4613E5 for ; Wed, 26 May 2021 18:01:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235411AbhEZSDM (ORCPT ); Wed, 26 May 2021 14:03:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:58644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235345AbhEZSDJ (ORCPT ); Wed, 26 May 2021 14:03:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CE942613EC; Wed, 26 May 2021 18:01:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622052097; bh=IcrTTUXB12OA3E1dGQSEXA9SbqeA5iFFzo+wGhFn9vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K2d7b3+N5s5HYdJEYBIPG9iIlP55DbTBwnpMV7H3284VjK+H5ycDu9EN+TTcLeb6q c7+1WleIstR4iAOEKxBlmFDtOkLX5BTAxKXiPSxW9/SgWzoH04mZ2WxwGfXQVlPLC4 YDWjmBq8Z5txmLcGIjXKnO/8frXo6CxmNlqu6ciod/Hk86UOD5kQcMCxtZBxx5sj01 RreWpon6GunxigHX5HuamwWdSxL+ssWOmkxmzO6b74NkytHGml+9hcCPET+7j/Z7gW yh1RprXzajTcfjp+zduQEpYpFYVABiEG3hAvGwoitpdKN8nwSCiK1NilXKzQlOHpfy C0DOaQumkXCnQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: linux-leds@vger.kernel.org Cc: netdev@vger.kernel.org, Pavel Machek , Dan Murphy , Russell King , Andrew Lunn , Matthias Schiffer , Jacek Anaszewski , Mauro Carvalho Chehab , =?utf-8?q?Marek_Beh?= =?utf-8?q?=C3=BAn?= Subject: [PATCH leds v1 3/5] leds: trigger: netdev: move trigger data structure to global include dir Date: Wed, 26 May 2021 20:00:18 +0200 Message-Id: <20210526180020.13557-4-kabel@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210526180020.13557-1-kabel@kernel.org> References: <20210526180020.13557-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In preparation for HW offloading of netdev trigger, move struct led_trigger_data into global include directory, into file linux/ledtrig.h, so that drivers wanting to offload the trigger can see the requested settings. Signed-off-by: Marek Behún --- drivers/leds/trigger/ledtrig-netdev.c | 23 +--------------- include/linux/ledtrig.h | 38 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 include/linux/ledtrig.h diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 4f6b73e3b491..a611ad755036 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -10,17 +10,16 @@ // Copyright 2005-2006 Openedhand Ltd. // Author: Richard Purdie -#include #include #include #include #include #include #include +#include #include #include #include -#include #include #include "../leds.h" @@ -36,26 +35,6 @@ * */ -struct led_netdev_data { - spinlock_t lock; - - struct delayed_work work; - struct notifier_block notifier; - - struct led_classdev *led_cdev; - struct net_device *net_dev; - - char device_name[IFNAMSIZ]; - atomic_t interval; - unsigned int last_activity; - - unsigned long mode; -#define NETDEV_LED_LINK 0 -#define NETDEV_LED_TX 1 -#define NETDEV_LED_RX 2 -#define NETDEV_LED_MODE_LINKUP 3 -}; - enum netdev_led_attr { NETDEV_ATTR_LINK, NETDEV_ATTR_TX, diff --git a/include/linux/ledtrig.h b/include/linux/ledtrig.h new file mode 100644 index 000000000000..1cb7f03e6c16 --- /dev/null +++ b/include/linux/ledtrig.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * LED trigger shared structures + */ + +#ifndef __LINUX_LEDTRIG_H__ +#define __LINUX_LEDTRIG_H__ + +#include +#include +#include +#include + +#if IS_ENABLED(CONFIG_LEDS_TRIGGER_NETDEV) + +struct led_netdev_data { + spinlock_t lock; + + struct delayed_work work; + struct notifier_block notifier; + + struct led_classdev *led_cdev; + struct net_device *net_dev; + + char device_name[IFNAMSIZ]; + atomic_t interval; + unsigned int last_activity; + + unsigned long mode; +#define NETDEV_LED_LINK 0 +#define NETDEV_LED_TX 1 +#define NETDEV_LED_RX 2 +#define NETDEV_LED_MODE_LINKUP 3 +}; + +#endif /* IS_ENABLED(CONFIG_LEDS_TRIGGER_NETDEV) */ + +#endif /* __LINUX_LEDTRIG_H__ */ From patchwork Wed May 26 18:00:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12282501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3096C47082 for ; Wed, 26 May 2021 18:01:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B6EE611C2 for ; Wed, 26 May 2021 18:01:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234793AbhEZSDQ (ORCPT ); Wed, 26 May 2021 14:03:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:58686 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235390AbhEZSDL (ORCPT ); Wed, 26 May 2021 14:03:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EBBFB613D2; Wed, 26 May 2021 18:01:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622052099; bh=qCF24aDvqymIhf4BNzt4adPmMhhIa5R/Qjb11z5q3DA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ENMDuCQAvIahtB5REBoPeNOjooyuE39J+GsdnuWQWLwktILf2ZgTE/UYDOIQt6uTL AD3p5eaxL3WMY+NBzS6Ke+CgIxXdAU27R2+QDmGYgOMXgUdVnhTFKUUQvvqVfQHNII BkGKgkbHPIuEgohyphmB5hT8kCn5apagWYOUIUWvTCFOyUtQLzX9aKx05rIWxbYo/j Y68Wx1dCguuEb0Zn3toZZkjKDQIOAk2nSnSrdAt1ZA4hWuiYfV1Uv+N8iaF7o62l2G HCzVPDJhBJB/NIDXu3Dl1ln8xmT5pCzb5LM938htFSAvq9ZPLDR0eKZPhZ4k+GXIrZ cEyNmL8laZcZA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: linux-leds@vger.kernel.org Cc: netdev@vger.kernel.org, Pavel Machek , Dan Murphy , Russell King , Andrew Lunn , Matthias Schiffer , Jacek Anaszewski , Mauro Carvalho Chehab , =?utf-8?q?Marek_Beh?= =?utf-8?q?=C3=BAn?= Subject: [PATCH leds v1 4/5] leds: trigger: netdev: support HW offloading Date: Wed, 26 May 2021 20:00:19 +0200 Message-Id: <20210526180020.13557-5-kabel@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210526180020.13557-1-kabel@kernel.org> References: <20210526180020.13557-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add support for HW offloading of the netdev trigger. We need to export the netdev_led_trigger variable so that drivers may check whether the LED is set to this trigger. Signed-off-by: Marek Behún --- drivers/leds/trigger/ledtrig-netdev.c | 6 +++++- include/linux/ledtrig.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index a611ad755036..b6d51b24c213 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -52,6 +52,9 @@ static void set_baseline_state(struct led_netdev_data *trigger_data) if (!led_cdev->blink_brightness) led_cdev->blink_brightness = led_cdev->max_brightness; + if (!led_trigger_offload(led_cdev)) + return; + if (!test_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode)) led_set_brightness(led_cdev, LED_OFF); else { @@ -411,12 +414,13 @@ static void netdev_trig_deactivate(struct led_classdev *led_cdev) kfree(trigger_data); } -static struct led_trigger netdev_led_trigger = { +struct led_trigger netdev_led_trigger = { .name = "netdev", .activate = netdev_trig_activate, .deactivate = netdev_trig_deactivate, .groups = netdev_trig_groups, }; +EXPORT_SYMBOL_GPL(netdev_led_trigger); static int __init netdev_trig_init(void) { diff --git a/include/linux/ledtrig.h b/include/linux/ledtrig.h index 1cb7f03e6c16..a6a813bb154a 100644 --- a/include/linux/ledtrig.h +++ b/include/linux/ledtrig.h @@ -33,6 +33,8 @@ struct led_netdev_data { #define NETDEV_LED_MODE_LINKUP 3 }; +extern struct led_trigger netdev_led_trigger; + #endif /* IS_ENABLED(CONFIG_LEDS_TRIGGER_NETDEV) */ #endif /* __LINUX_LEDTRIG_H__ */ From patchwork Wed May 26 18:00:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12282503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF2B3C47089 for ; Wed, 26 May 2021 18:01:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A45186113D for ; Wed, 26 May 2021 18:01:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235272AbhEZSDR (ORCPT ); Wed, 26 May 2021 14:03:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:58710 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235414AbhEZSDN (ORCPT ); Wed, 26 May 2021 14:03:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 14805613C5; Wed, 26 May 2021 18:01:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622052101; bh=YYukrN0gtN9kwTFXmThy4546a/7oLlBsJI81+BNz9/8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a//HXFXo35dDN1h8bbn/ar2X9NNjvm/24NE5UPYchG0HWzw9+YWZj6SaV4uaZ4Jon NCQzTDNprsUKr2zzxylukjk7WCGJyVL2VxU7AG2u2G0UV9apaQPU/xz8kmCicLTlYk UW2GvcQQU46HEYhu7k1scQTuz2fJFgD53w4jgDMcC8PjshqXEbunwsUcsx3q8aOp4o ltfYEDoFrp+hUER9eHiqEThvx+Q/p2YyLndbd0qrc+n1iToMI82AEZiCTtDt5tE3w5 byRVih5+yR+jhbFkaVv3/QurVkGZlUe1KXn2/1IoYiEqlj97myVVh+Pog54aH4Rm21 uH6ujIU9ry19g== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: linux-leds@vger.kernel.org Cc: netdev@vger.kernel.org, Pavel Machek , Dan Murphy , Russell King , Andrew Lunn , Matthias Schiffer , Jacek Anaszewski , Mauro Carvalho Chehab , =?utf-8?q?Marek_Beh?= =?utf-8?q?=C3=BAn?= Subject: [PATCH leds v1 5/5] leds: trigger: netdev: change spinlock to mutex Date: Wed, 26 May 2021 20:00:20 +0200 Message-Id: <20210526180020.13557-6-kabel@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210526180020.13557-1-kabel@kernel.org> References: <20210526180020.13557-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Using spinlocks requires that the trigger_offload() method cannot sleep. This can be problematic for some hardware, since access to registers may sleep. We can change the spinlock to mutex because, according to Jacek: register_netdevice_notifier() registers raw notifier chain, whose callbacks are not called from atomic context and there are no restrictions on callbacks. See include/linux/notifier.h. Signed-off-by: Marek Behún --- drivers/leds/trigger/ledtrig-netdev.c | 14 +++++++------- include/linux/ledtrig.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index b6d51b24c213..7073cc6b8ca2 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -79,9 +79,9 @@ static ssize_t device_name_show(struct device *dev, struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); ssize_t len; - spin_lock_bh(&trigger_data->lock); + mutex_lock(&trigger_data->lock); len = sprintf(buf, "%s\n", trigger_data->device_name); - spin_unlock_bh(&trigger_data->lock); + mutex_unlock(&trigger_data->lock); return len; } @@ -97,7 +97,7 @@ static ssize_t device_name_store(struct device *dev, cancel_delayed_work_sync(&trigger_data->work); - spin_lock_bh(&trigger_data->lock); + mutex_lock(&trigger_data->lock); if (trigger_data->net_dev) { dev_put(trigger_data->net_dev); @@ -121,7 +121,7 @@ static ssize_t device_name_store(struct device *dev, trigger_data->last_activity = 0; set_baseline_state(trigger_data); - spin_unlock_bh(&trigger_data->lock); + mutex_unlock(&trigger_data->lock); return size; } @@ -295,7 +295,7 @@ static int netdev_trig_notify(struct notifier_block *nb, cancel_delayed_work_sync(&trigger_data->work); - spin_lock_bh(&trigger_data->lock); + mutex_lock(&trigger_data->lock); clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); switch (evt) { @@ -319,7 +319,7 @@ static int netdev_trig_notify(struct notifier_block *nb, set_baseline_state(trigger_data); - spin_unlock_bh(&trigger_data->lock); + mutex_unlock(&trigger_data->lock); return NOTIFY_DONE; } @@ -380,7 +380,7 @@ static int netdev_trig_activate(struct led_classdev *led_cdev) if (!trigger_data) return -ENOMEM; - spin_lock_init(&trigger_data->lock); + mutex_init(&trigger_data->lock); trigger_data->notifier.notifier_call = netdev_trig_notify; trigger_data->notifier.priority = 10; diff --git a/include/linux/ledtrig.h b/include/linux/ledtrig.h index a6a813bb154a..bd8cdcfaf232 100644 --- a/include/linux/ledtrig.h +++ b/include/linux/ledtrig.h @@ -8,13 +8,13 @@ #include #include +#include #include -#include #if IS_ENABLED(CONFIG_LEDS_TRIGGER_NETDEV) struct led_netdev_data { - spinlock_t lock; + struct mutex lock; struct delayed_work work; struct notifier_block notifier;