Centos-kernel-stream-9/drivers/base/firmware_loader/sysfs.c

415 lines
9.7 KiB
C
Raw Normal View History

firmware_loader: Split sysfs support from fallback Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 Conflicts: drivers/base/firmware_loader/fallback.c - context differences when deleting old code drivers/base/firmware_loader/sysfs.c - the new code had to be modified to match the code moved from fallback.c Notably, CONFIG_FW_LOADER_USER_HELPER references were removed and (un)register_sysfs_loader was simplified and the references to firmware_config_sysctl() were removed. commit e0c11a8b985137aebf4bcd07cd957b80ac23924d Author: Russ Weight <russell.h.weight@intel.com> Date: Thu, 21 Apr 2022 14:21:59 -0700 In preparation for sharing the "loading" and "data" sysfs nodes with the new firmware upload support, split out sysfs functionality from fallback.c and fallback.h into sysfs.c and sysfs.h. This includes the firmware class driver code that is associated with the sysfs files and the fw_fallback_config support for the timeout sysfs node. CONFIG_FW_LOADER_SYSFS is created and is selected by CONFIG_FW_LOADER_USER_HELPER in order to include sysfs.o in firmware_class-objs. This is mostly just a code reorganization. There are a few symbols that change in scope, and these can be identified by looking at the header file changes. A few white-space warnings from checkpatch are also addressed in this patch. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com> Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Signed-off-by: Russ Weight <russell.h.weight@intel.com> Link: https://lore.kernel.org/r/20220421212204.36052-4-russell.h.weight@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 20:47:41 +00:00
// SPDX-License-Identifier: GPL-2.0
#include <linux/highmem.h>
#include <linux/module.h>
#include <linux/security.h>
#include <linux/slab.h>
#include <linux/types.h>
#include "sysfs.h"
/*
* sysfs support for firmware loader
*/
void __fw_load_abort(struct fw_priv *fw_priv)
{
/*
* There is a small window in which user can write to 'loading'
* between loading done/aborted and disappearance of 'loading'
*/
if (fw_state_is_aborted(fw_priv) || fw_state_is_done(fw_priv))
return;
fw_state_aborted(fw_priv);
}
#ifdef CONFIG_FW_LOADER_USER_HELPER
driver core: class: mark the struct class for sysfs callbacks as constant JIRA: https://issues.redhat.com/browse/RHEL-1023 Conflicts: fs/ksmbd/server.c - not present in centos-9, so this part of the commit was ignored commit 75a2d4226b53710380d1017b3f4c88f937ddba78 Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Date: Wed, 29 Mar 2023 07:54:58 +0000 struct class should never be modified in a sysfs callback as there is nothing in the structure to modify, and frankly, the structure is almost never used in a sysfs callback, so mark it as constant to allow struct class to be moved to read-only memory. While we are touching all class sysfs callbacks also mark the attribute as constant as it can not be modified. The bonding code still uses this structure so it can not be removed from the function callbacks. Cc: "David S. Miller" <davem@davemloft.net> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Bartosz Golaszewski <brgl@bgdev.pl> Cc: Eric Dumazet <edumazet@google.com> Cc: Jakub Kicinski <kuba@kernel.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: Minchan Kim <minchan@kernel.org> Cc: Miquel Raynal <miquel.raynal@bootlin.com> Cc: Namjae Jeon <linkinjeon@kernel.org> Cc: Paolo Abeni <pabeni@redhat.com> Cc: Russ Weight <russell.h.weight@intel.com> Cc: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Steve French <sfrench@samba.org> Cc: Vignesh Raghavendra <vigneshr@ti.com> Cc: linux-cifs@vger.kernel.org Cc: linux-gpio@vger.kernel.org Cc: linux-mtd@lists.infradead.org Cc: linux-rdma@vger.kernel.org Cc: linux-s390@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Cc: netdev@vger.kernel.org Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Link: https://lore.kernel.org/r/20230325084537.3622280-1-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2023-08-07 15:01:41 +00:00
static ssize_t timeout_show(const struct class *class, const struct class_attribute *attr,
firmware_loader: Split sysfs support from fallback Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 Conflicts: drivers/base/firmware_loader/fallback.c - context differences when deleting old code drivers/base/firmware_loader/sysfs.c - the new code had to be modified to match the code moved from fallback.c Notably, CONFIG_FW_LOADER_USER_HELPER references were removed and (un)register_sysfs_loader was simplified and the references to firmware_config_sysctl() were removed. commit e0c11a8b985137aebf4bcd07cd957b80ac23924d Author: Russ Weight <russell.h.weight@intel.com> Date: Thu, 21 Apr 2022 14:21:59 -0700 In preparation for sharing the "loading" and "data" sysfs nodes with the new firmware upload support, split out sysfs functionality from fallback.c and fallback.h into sysfs.c and sysfs.h. This includes the firmware class driver code that is associated with the sysfs files and the fw_fallback_config support for the timeout sysfs node. CONFIG_FW_LOADER_SYSFS is created and is selected by CONFIG_FW_LOADER_USER_HELPER in order to include sysfs.o in firmware_class-objs. This is mostly just a code reorganization. There are a few symbols that change in scope, and these can be identified by looking at the header file changes. A few white-space warnings from checkpatch are also addressed in this patch. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com> Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Signed-off-by: Russ Weight <russell.h.weight@intel.com> Link: https://lore.kernel.org/r/20220421212204.36052-4-russell.h.weight@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 20:47:41 +00:00
char *buf)
{
return sysfs_emit(buf, "%d\n", __firmware_loading_timeout());
}
/**
* timeout_store() - set number of seconds to wait for firmware
* @class: device class pointer
* @attr: device attribute pointer
* @buf: buffer to scan for timeout value
* @count: number of bytes in @buf
*
* Sets the number of seconds to wait for the firmware. Once
* this expires an error will be returned to the driver and no
* firmware will be provided.
*
* Note: zero means 'wait forever'.
**/
driver core: class: mark the struct class for sysfs callbacks as constant JIRA: https://issues.redhat.com/browse/RHEL-1023 Conflicts: fs/ksmbd/server.c - not present in centos-9, so this part of the commit was ignored commit 75a2d4226b53710380d1017b3f4c88f937ddba78 Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Date: Wed, 29 Mar 2023 07:54:58 +0000 struct class should never be modified in a sysfs callback as there is nothing in the structure to modify, and frankly, the structure is almost never used in a sysfs callback, so mark it as constant to allow struct class to be moved to read-only memory. While we are touching all class sysfs callbacks also mark the attribute as constant as it can not be modified. The bonding code still uses this structure so it can not be removed from the function callbacks. Cc: "David S. Miller" <davem@davemloft.net> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Bartosz Golaszewski <brgl@bgdev.pl> Cc: Eric Dumazet <edumazet@google.com> Cc: Jakub Kicinski <kuba@kernel.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: Minchan Kim <minchan@kernel.org> Cc: Miquel Raynal <miquel.raynal@bootlin.com> Cc: Namjae Jeon <linkinjeon@kernel.org> Cc: Paolo Abeni <pabeni@redhat.com> Cc: Russ Weight <russell.h.weight@intel.com> Cc: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Steve French <sfrench@samba.org> Cc: Vignesh Raghavendra <vigneshr@ti.com> Cc: linux-cifs@vger.kernel.org Cc: linux-gpio@vger.kernel.org Cc: linux-mtd@lists.infradead.org Cc: linux-rdma@vger.kernel.org Cc: linux-s390@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Cc: netdev@vger.kernel.org Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Link: https://lore.kernel.org/r/20230325084537.3622280-1-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2023-08-07 15:01:41 +00:00
static ssize_t timeout_store(const struct class *class, const struct class_attribute *attr,
firmware_loader: Split sysfs support from fallback Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 Conflicts: drivers/base/firmware_loader/fallback.c - context differences when deleting old code drivers/base/firmware_loader/sysfs.c - the new code had to be modified to match the code moved from fallback.c Notably, CONFIG_FW_LOADER_USER_HELPER references were removed and (un)register_sysfs_loader was simplified and the references to firmware_config_sysctl() were removed. commit e0c11a8b985137aebf4bcd07cd957b80ac23924d Author: Russ Weight <russell.h.weight@intel.com> Date: Thu, 21 Apr 2022 14:21:59 -0700 In preparation for sharing the "loading" and "data" sysfs nodes with the new firmware upload support, split out sysfs functionality from fallback.c and fallback.h into sysfs.c and sysfs.h. This includes the firmware class driver code that is associated with the sysfs files and the fw_fallback_config support for the timeout sysfs node. CONFIG_FW_LOADER_SYSFS is created and is selected by CONFIG_FW_LOADER_USER_HELPER in order to include sysfs.o in firmware_class-objs. This is mostly just a code reorganization. There are a few symbols that change in scope, and these can be identified by looking at the header file changes. A few white-space warnings from checkpatch are also addressed in this patch. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com> Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Signed-off-by: Russ Weight <russell.h.weight@intel.com> Link: https://lore.kernel.org/r/20220421212204.36052-4-russell.h.weight@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 20:47:41 +00:00
const char *buf, size_t count)
{
int tmp_loading_timeout = simple_strtol(buf, NULL, 10);
if (tmp_loading_timeout < 0)
tmp_loading_timeout = 0;
__fw_fallback_set_timeout(tmp_loading_timeout);
return count;
}
static CLASS_ATTR_RW(timeout);
static struct attribute *firmware_class_attrs[] = {
&class_attr_timeout.attr,
NULL,
};
ATTRIBUTE_GROUPS(firmware_class);
driver core: make struct class.dev_uevent() take a const * Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2178302 Conflicts: drivers/base/firmware_loader/sysfs.h - replace the single line version of to_fw_sysfs with the longer inline version commit 23680f0b7d7f67a935adb38058110d2d81bbe6ea Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Date: Wed, 23 Nov 2022 13:25:19 +0100 The dev_uevent() in struct class should not be modifying the device that is passed into it, so mark it as a const * and propagate the function signature changes out into all relevant subsystems that use this callback. Cc: Jens Axboe <axboe@kernel.dk> Cc: Luis Chamberlain <mcgrof@kernel.org> Cc: Russ Weight <russell.h.weight@intel.com> Cc: Jean Delvare <jdelvare@suse.com> Cc: Johan Hovold <johan@kernel.org> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Leon Romanovsky <leon@kernel.org> Cc: Karsten Keil <isdn@linux-pingi.de> Cc: Mauro Carvalho Chehab <mchehab@kernel.org> Cc: Keith Busch <kbusch@kernel.org> Cc: Christoph Hellwig <hch@lst.de> Cc: Sagi Grimberg <sagi@grimberg.me> Cc: Dominik Brodowski <linux@dominikbrodowski.net> Cc: "David S. Miller" <davem@davemloft.net> Cc: Eric Dumazet <edumazet@google.com> Cc: Jakub Kicinski <kuba@kernel.org> Cc: Paolo Abeni <pabeni@redhat.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: Wolfram Sang <wsa+renesas@sang-engineering.com> Cc: Raed Salem <raeds@nvidia.com> Cc: Chen Zhongjin <chenzhongjin@huawei.com> Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Cc: Avihai Horon <avihaih@nvidia.com> Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: Colin Ian King <colin.i.king@gmail.com> Cc: Geert Uytterhoeven <geert+renesas@glider.be> Cc: Jakob Koschel <jakobkoschel@gmail.com> Cc: Antoine Tenart <atenart@kernel.org> Cc: Frederic Weisbecker <frederic@kernel.org> Cc: Wang Yufen <wangyufen@huawei.com> Cc: linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-media@vger.kernel.org Cc: linux-nvme@lists.infradead.org Cc: linux-pm@vger.kernel.org Cc: linux-rdma@vger.kernel.org Cc: linux-usb@vger.kernel.org Cc: linux-wireless@vger.kernel.org Cc: netdev@vger.kernel.org Acked-by: Sebastian Reichel <sre@kernel.org> Acked-by: Rafael J. Wysocki <rafael@kernel.org> Link: https://lore.kernel.org/r/20221123122523.1332370-1-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2023-03-14 20:22:16 +00:00
static int do_firmware_uevent(const struct fw_sysfs *fw_sysfs, struct kobj_uevent_env *env)
firmware_loader: Split sysfs support from fallback Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 Conflicts: drivers/base/firmware_loader/fallback.c - context differences when deleting old code drivers/base/firmware_loader/sysfs.c - the new code had to be modified to match the code moved from fallback.c Notably, CONFIG_FW_LOADER_USER_HELPER references were removed and (un)register_sysfs_loader was simplified and the references to firmware_config_sysctl() were removed. commit e0c11a8b985137aebf4bcd07cd957b80ac23924d Author: Russ Weight <russell.h.weight@intel.com> Date: Thu, 21 Apr 2022 14:21:59 -0700 In preparation for sharing the "loading" and "data" sysfs nodes with the new firmware upload support, split out sysfs functionality from fallback.c and fallback.h into sysfs.c and sysfs.h. This includes the firmware class driver code that is associated with the sysfs files and the fw_fallback_config support for the timeout sysfs node. CONFIG_FW_LOADER_SYSFS is created and is selected by CONFIG_FW_LOADER_USER_HELPER in order to include sysfs.o in firmware_class-objs. This is mostly just a code reorganization. There are a few symbols that change in scope, and these can be identified by looking at the header file changes. A few white-space warnings from checkpatch are also addressed in this patch. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com> Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Signed-off-by: Russ Weight <russell.h.weight@intel.com> Link: https://lore.kernel.org/r/20220421212204.36052-4-russell.h.weight@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 20:47:41 +00:00
{
if (add_uevent_var(env, "FIRMWARE=%s", fw_sysfs->fw_priv->fw_name))
return -ENOMEM;
if (add_uevent_var(env, "TIMEOUT=%i", __firmware_loading_timeout()))
return -ENOMEM;
if (add_uevent_var(env, "ASYNC=%d", fw_sysfs->nowait))
return -ENOMEM;
return 0;
}
driver core: make struct class.dev_uevent() take a const * Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2178302 Conflicts: drivers/base/firmware_loader/sysfs.h - replace the single line version of to_fw_sysfs with the longer inline version commit 23680f0b7d7f67a935adb38058110d2d81bbe6ea Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Date: Wed, 23 Nov 2022 13:25:19 +0100 The dev_uevent() in struct class should not be modifying the device that is passed into it, so mark it as a const * and propagate the function signature changes out into all relevant subsystems that use this callback. Cc: Jens Axboe <axboe@kernel.dk> Cc: Luis Chamberlain <mcgrof@kernel.org> Cc: Russ Weight <russell.h.weight@intel.com> Cc: Jean Delvare <jdelvare@suse.com> Cc: Johan Hovold <johan@kernel.org> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Leon Romanovsky <leon@kernel.org> Cc: Karsten Keil <isdn@linux-pingi.de> Cc: Mauro Carvalho Chehab <mchehab@kernel.org> Cc: Keith Busch <kbusch@kernel.org> Cc: Christoph Hellwig <hch@lst.de> Cc: Sagi Grimberg <sagi@grimberg.me> Cc: Dominik Brodowski <linux@dominikbrodowski.net> Cc: "David S. Miller" <davem@davemloft.net> Cc: Eric Dumazet <edumazet@google.com> Cc: Jakub Kicinski <kuba@kernel.org> Cc: Paolo Abeni <pabeni@redhat.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: Wolfram Sang <wsa+renesas@sang-engineering.com> Cc: Raed Salem <raeds@nvidia.com> Cc: Chen Zhongjin <chenzhongjin@huawei.com> Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Cc: Avihai Horon <avihaih@nvidia.com> Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: Colin Ian King <colin.i.king@gmail.com> Cc: Geert Uytterhoeven <geert+renesas@glider.be> Cc: Jakob Koschel <jakobkoschel@gmail.com> Cc: Antoine Tenart <atenart@kernel.org> Cc: Frederic Weisbecker <frederic@kernel.org> Cc: Wang Yufen <wangyufen@huawei.com> Cc: linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-media@vger.kernel.org Cc: linux-nvme@lists.infradead.org Cc: linux-pm@vger.kernel.org Cc: linux-rdma@vger.kernel.org Cc: linux-usb@vger.kernel.org Cc: linux-wireless@vger.kernel.org Cc: netdev@vger.kernel.org Acked-by: Sebastian Reichel <sre@kernel.org> Acked-by: Rafael J. Wysocki <rafael@kernel.org> Link: https://lore.kernel.org/r/20221123122523.1332370-1-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2023-03-14 20:22:16 +00:00
static int firmware_uevent(const struct device *dev, struct kobj_uevent_env *env)
firmware_loader: Split sysfs support from fallback Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 Conflicts: drivers/base/firmware_loader/fallback.c - context differences when deleting old code drivers/base/firmware_loader/sysfs.c - the new code had to be modified to match the code moved from fallback.c Notably, CONFIG_FW_LOADER_USER_HELPER references were removed and (un)register_sysfs_loader was simplified and the references to firmware_config_sysctl() were removed. commit e0c11a8b985137aebf4bcd07cd957b80ac23924d Author: Russ Weight <russell.h.weight@intel.com> Date: Thu, 21 Apr 2022 14:21:59 -0700 In preparation for sharing the "loading" and "data" sysfs nodes with the new firmware upload support, split out sysfs functionality from fallback.c and fallback.h into sysfs.c and sysfs.h. This includes the firmware class driver code that is associated with the sysfs files and the fw_fallback_config support for the timeout sysfs node. CONFIG_FW_LOADER_SYSFS is created and is selected by CONFIG_FW_LOADER_USER_HELPER in order to include sysfs.o in firmware_class-objs. This is mostly just a code reorganization. There are a few symbols that change in scope, and these can be identified by looking at the header file changes. A few white-space warnings from checkpatch are also addressed in this patch. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com> Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Signed-off-by: Russ Weight <russell.h.weight@intel.com> Link: https://lore.kernel.org/r/20220421212204.36052-4-russell.h.weight@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 20:47:41 +00:00
{
driver core: make struct class.dev_uevent() take a const * Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2178302 Conflicts: drivers/base/firmware_loader/sysfs.h - replace the single line version of to_fw_sysfs with the longer inline version commit 23680f0b7d7f67a935adb38058110d2d81bbe6ea Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Date: Wed, 23 Nov 2022 13:25:19 +0100 The dev_uevent() in struct class should not be modifying the device that is passed into it, so mark it as a const * and propagate the function signature changes out into all relevant subsystems that use this callback. Cc: Jens Axboe <axboe@kernel.dk> Cc: Luis Chamberlain <mcgrof@kernel.org> Cc: Russ Weight <russell.h.weight@intel.com> Cc: Jean Delvare <jdelvare@suse.com> Cc: Johan Hovold <johan@kernel.org> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Leon Romanovsky <leon@kernel.org> Cc: Karsten Keil <isdn@linux-pingi.de> Cc: Mauro Carvalho Chehab <mchehab@kernel.org> Cc: Keith Busch <kbusch@kernel.org> Cc: Christoph Hellwig <hch@lst.de> Cc: Sagi Grimberg <sagi@grimberg.me> Cc: Dominik Brodowski <linux@dominikbrodowski.net> Cc: "David S. Miller" <davem@davemloft.net> Cc: Eric Dumazet <edumazet@google.com> Cc: Jakub Kicinski <kuba@kernel.org> Cc: Paolo Abeni <pabeni@redhat.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: Wolfram Sang <wsa+renesas@sang-engineering.com> Cc: Raed Salem <raeds@nvidia.com> Cc: Chen Zhongjin <chenzhongjin@huawei.com> Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Cc: Avihai Horon <avihaih@nvidia.com> Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: Colin Ian King <colin.i.king@gmail.com> Cc: Geert Uytterhoeven <geert+renesas@glider.be> Cc: Jakob Koschel <jakobkoschel@gmail.com> Cc: Antoine Tenart <atenart@kernel.org> Cc: Frederic Weisbecker <frederic@kernel.org> Cc: Wang Yufen <wangyufen@huawei.com> Cc: linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-media@vger.kernel.org Cc: linux-nvme@lists.infradead.org Cc: linux-pm@vger.kernel.org Cc: linux-rdma@vger.kernel.org Cc: linux-usb@vger.kernel.org Cc: linux-wireless@vger.kernel.org Cc: netdev@vger.kernel.org Acked-by: Sebastian Reichel <sre@kernel.org> Acked-by: Rafael J. Wysocki <rafael@kernel.org> Link: https://lore.kernel.org/r/20221123122523.1332370-1-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2023-03-14 20:22:16 +00:00
const struct fw_sysfs *fw_sysfs = to_fw_sysfs(dev);
firmware_loader: Split sysfs support from fallback Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 Conflicts: drivers/base/firmware_loader/fallback.c - context differences when deleting old code drivers/base/firmware_loader/sysfs.c - the new code had to be modified to match the code moved from fallback.c Notably, CONFIG_FW_LOADER_USER_HELPER references were removed and (un)register_sysfs_loader was simplified and the references to firmware_config_sysctl() were removed. commit e0c11a8b985137aebf4bcd07cd957b80ac23924d Author: Russ Weight <russell.h.weight@intel.com> Date: Thu, 21 Apr 2022 14:21:59 -0700 In preparation for sharing the "loading" and "data" sysfs nodes with the new firmware upload support, split out sysfs functionality from fallback.c and fallback.h into sysfs.c and sysfs.h. This includes the firmware class driver code that is associated with the sysfs files and the fw_fallback_config support for the timeout sysfs node. CONFIG_FW_LOADER_SYSFS is created and is selected by CONFIG_FW_LOADER_USER_HELPER in order to include sysfs.o in firmware_class-objs. This is mostly just a code reorganization. There are a few symbols that change in scope, and these can be identified by looking at the header file changes. A few white-space warnings from checkpatch are also addressed in this patch. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com> Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Signed-off-by: Russ Weight <russell.h.weight@intel.com> Link: https://lore.kernel.org/r/20220421212204.36052-4-russell.h.weight@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 20:47:41 +00:00
int err = 0;
mutex_lock(&fw_lock);
if (fw_sysfs->fw_priv)
err = do_firmware_uevent(fw_sysfs, env);
mutex_unlock(&fw_lock);
return err;
}
#endif /* CONFIG_FW_LOADER_USER_HELPER */
static void fw_dev_release(struct device *dev)
{
struct fw_sysfs *fw_sysfs = to_fw_sysfs(dev);
if (fw_sysfs->fw_upload_priv)
fw_upload_free(fw_sysfs);
firmware_loader: Split sysfs support from fallback Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 Conflicts: drivers/base/firmware_loader/fallback.c - context differences when deleting old code drivers/base/firmware_loader/sysfs.c - the new code had to be modified to match the code moved from fallback.c Notably, CONFIG_FW_LOADER_USER_HELPER references were removed and (un)register_sysfs_loader was simplified and the references to firmware_config_sysctl() were removed. commit e0c11a8b985137aebf4bcd07cd957b80ac23924d Author: Russ Weight <russell.h.weight@intel.com> Date: Thu, 21 Apr 2022 14:21:59 -0700 In preparation for sharing the "loading" and "data" sysfs nodes with the new firmware upload support, split out sysfs functionality from fallback.c and fallback.h into sysfs.c and sysfs.h. This includes the firmware class driver code that is associated with the sysfs files and the fw_fallback_config support for the timeout sysfs node. CONFIG_FW_LOADER_SYSFS is created and is selected by CONFIG_FW_LOADER_USER_HELPER in order to include sysfs.o in firmware_class-objs. This is mostly just a code reorganization. There are a few symbols that change in scope, and these can be identified by looking at the header file changes. A few white-space warnings from checkpatch are also addressed in this patch. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com> Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Signed-off-by: Russ Weight <russell.h.weight@intel.com> Link: https://lore.kernel.org/r/20220421212204.36052-4-russell.h.weight@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 20:47:41 +00:00
kfree(fw_sysfs);
}
static struct class firmware_class = {
.name = "firmware",
#ifdef CONFIG_FW_LOADER_USER_HELPER
.class_groups = firmware_class_groups,
.dev_uevent = firmware_uevent,
#endif
.dev_release = fw_dev_release,
};
int register_sysfs_loader(void)
{
return class_register(&firmware_class);
}
void unregister_sysfs_loader(void)
{
class_unregister(&firmware_class);
}
static ssize_t firmware_loading_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct fw_sysfs *fw_sysfs = to_fw_sysfs(dev);
int loading = 0;
mutex_lock(&fw_lock);
if (fw_sysfs->fw_priv)
loading = fw_state_is_loading(fw_sysfs->fw_priv);
mutex_unlock(&fw_lock);
return sysfs_emit(buf, "%d\n", loading);
}
/**
* firmware_loading_store() - set value in the 'loading' control file
* @dev: device pointer
* @attr: device attribute pointer
* @buf: buffer to scan for loading control value
* @count: number of bytes in @buf
*
* The relevant values are:
*
* 1: Start a load, discarding any previous partial load.
* 0: Conclude the load and hand the data to the driver code.
* -1: Conclude the load with an error and discard any written data.
**/
static ssize_t firmware_loading_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct fw_sysfs *fw_sysfs = to_fw_sysfs(dev);
struct fw_priv *fw_priv;
ssize_t written = count;
int loading = simple_strtol(buf, NULL, 10);
mutex_lock(&fw_lock);
fw_priv = fw_sysfs->fw_priv;
if (fw_state_is_aborted(fw_priv) || fw_state_is_done(fw_priv))
goto out;
switch (loading) {
case 1:
/* discarding any previous partial load */
fw_free_paged_buf(fw_priv);
fw_state_start(fw_priv);
break;
case 0:
if (fw_state_is_loading(fw_priv)) {
int rc;
/*
* Several loading requests may be pending on
* one same firmware buf, so let all requests
* see the mapped 'buf->data' once the loading
* is completed.
*/
rc = fw_map_paged_buf(fw_priv);
if (rc)
dev_err(dev, "%s: map pages failed\n",
__func__);
else
rc = security_kernel_post_load_data(fw_priv->data,
fw_priv->size,
LOADING_FIRMWARE,
"blob");
/*
* Same logic as fw_load_abort, only the DONE bit
* is ignored and we set ABORT only on failure.
*/
if (rc) {
fw_state_aborted(fw_priv);
written = rc;
} else {
fw_state_done(fw_priv);
/*
* If this is a user-initiated firmware upload
* then start the upload in a worker thread now.
*/
rc = fw_upload_start(fw_sysfs);
if (rc)
written = rc;
firmware_loader: Split sysfs support from fallback Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 Conflicts: drivers/base/firmware_loader/fallback.c - context differences when deleting old code drivers/base/firmware_loader/sysfs.c - the new code had to be modified to match the code moved from fallback.c Notably, CONFIG_FW_LOADER_USER_HELPER references were removed and (un)register_sysfs_loader was simplified and the references to firmware_config_sysctl() were removed. commit e0c11a8b985137aebf4bcd07cd957b80ac23924d Author: Russ Weight <russell.h.weight@intel.com> Date: Thu, 21 Apr 2022 14:21:59 -0700 In preparation for sharing the "loading" and "data" sysfs nodes with the new firmware upload support, split out sysfs functionality from fallback.c and fallback.h into sysfs.c and sysfs.h. This includes the firmware class driver code that is associated with the sysfs files and the fw_fallback_config support for the timeout sysfs node. CONFIG_FW_LOADER_SYSFS is created and is selected by CONFIG_FW_LOADER_USER_HELPER in order to include sysfs.o in firmware_class-objs. This is mostly just a code reorganization. There are a few symbols that change in scope, and these can be identified by looking at the header file changes. A few white-space warnings from checkpatch are also addressed in this patch. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com> Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Signed-off-by: Russ Weight <russell.h.weight@intel.com> Link: https://lore.kernel.org/r/20220421212204.36052-4-russell.h.weight@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 20:47:41 +00:00
}
break;
}
fallthrough;
default:
dev_err(dev, "%s: unexpected value (%d)\n", __func__, loading);
fallthrough;
case -1:
fw_load_abort(fw_sysfs);
if (fw_sysfs->fw_upload_priv)
fw_state_init(fw_sysfs->fw_priv);
firmware_loader: Split sysfs support from fallback Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 Conflicts: drivers/base/firmware_loader/fallback.c - context differences when deleting old code drivers/base/firmware_loader/sysfs.c - the new code had to be modified to match the code moved from fallback.c Notably, CONFIG_FW_LOADER_USER_HELPER references were removed and (un)register_sysfs_loader was simplified and the references to firmware_config_sysctl() were removed. commit e0c11a8b985137aebf4bcd07cd957b80ac23924d Author: Russ Weight <russell.h.weight@intel.com> Date: Thu, 21 Apr 2022 14:21:59 -0700 In preparation for sharing the "loading" and "data" sysfs nodes with the new firmware upload support, split out sysfs functionality from fallback.c and fallback.h into sysfs.c and sysfs.h. This includes the firmware class driver code that is associated with the sysfs files and the fw_fallback_config support for the timeout sysfs node. CONFIG_FW_LOADER_SYSFS is created and is selected by CONFIG_FW_LOADER_USER_HELPER in order to include sysfs.o in firmware_class-objs. This is mostly just a code reorganization. There are a few symbols that change in scope, and these can be identified by looking at the header file changes. A few white-space warnings from checkpatch are also addressed in this patch. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com> Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Signed-off-by: Russ Weight <russell.h.weight@intel.com> Link: https://lore.kernel.org/r/20220421212204.36052-4-russell.h.weight@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 20:47:41 +00:00
break;
}
out:
mutex_unlock(&fw_lock);
return written;
}
DEVICE_ATTR(loading, 0644, firmware_loading_show, firmware_loading_store);
firmware_loader: Split sysfs support from fallback Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 Conflicts: drivers/base/firmware_loader/fallback.c - context differences when deleting old code drivers/base/firmware_loader/sysfs.c - the new code had to be modified to match the code moved from fallback.c Notably, CONFIG_FW_LOADER_USER_HELPER references were removed and (un)register_sysfs_loader was simplified and the references to firmware_config_sysctl() were removed. commit e0c11a8b985137aebf4bcd07cd957b80ac23924d Author: Russ Weight <russell.h.weight@intel.com> Date: Thu, 21 Apr 2022 14:21:59 -0700 In preparation for sharing the "loading" and "data" sysfs nodes with the new firmware upload support, split out sysfs functionality from fallback.c and fallback.h into sysfs.c and sysfs.h. This includes the firmware class driver code that is associated with the sysfs files and the fw_fallback_config support for the timeout sysfs node. CONFIG_FW_LOADER_SYSFS is created and is selected by CONFIG_FW_LOADER_USER_HELPER in order to include sysfs.o in firmware_class-objs. This is mostly just a code reorganization. There are a few symbols that change in scope, and these can be identified by looking at the header file changes. A few white-space warnings from checkpatch are also addressed in this patch. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com> Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Signed-off-by: Russ Weight <russell.h.weight@intel.com> Link: https://lore.kernel.org/r/20220421212204.36052-4-russell.h.weight@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 20:47:41 +00:00
static void firmware_rw_data(struct fw_priv *fw_priv, char *buffer,
loff_t offset, size_t count, bool read)
{
if (read)
memcpy(buffer, fw_priv->data + offset, count);
else
memcpy(fw_priv->data + offset, buffer, count);
}
static void firmware_rw(struct fw_priv *fw_priv, char *buffer,
loff_t offset, size_t count, bool read)
{
while (count) {
int page_nr = offset >> PAGE_SHIFT;
int page_ofs = offset & (PAGE_SIZE - 1);
int page_cnt = min_t(size_t, PAGE_SIZE - page_ofs, count);
if (read)
firmware_loader: Replace kmap() with kmap_local_page() Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 commit f2d57765b79857264fb0ddc52679d661b60ecc21 Author: "Fabio M. De Francesco" <fmdefrancesco@gmail.com> Date: Fri, 15 Jul 2022 01:50:30 +0200 The use of kmap() is being deprecated in favor of kmap_local_page(). Two main problems with kmap(): (1) It comes with an overhead as mapping space is restricted and protected by a global lock for synchronization and (2) kmap() also requires global TLB invalidation when the kmap’s pool wraps and it might block when the mapping space is fully utilized until a slot becomes available. kmap_local_page() is preferred over kmap() and kmap_atomic(). Where it cannot mechanically replace the latters, code refactor should be considered (special care must be taken if kernel virtual addresses are aliases in different contexts). With kmap_local_page() the mappings are per thread, CPU local, can take page faults, and can be called from any context (including interrupts). Call kmap_local_page() in firmware_loader wherever kmap() is currently used. In firmware_rw() use the helpers copy_{from,to}_page() instead of open coding the local mappings + memcpy(). Successfully tested with "firmware" selftests on a QEMU/KVM 32-bits VM with 4GB RAM, booting a kernel with HIGHMEM64GB enabled. Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Luis Chamberlain <mcgrof@kernel.org> Suggested-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com> Link: https://lore.kernel.org/r/20220714235030.12732-1-fmdefrancesco@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 21:07:53 +00:00
memcpy_from_page(buffer, fw_priv->pages[page_nr],
page_ofs, page_cnt);
firmware_loader: Split sysfs support from fallback Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 Conflicts: drivers/base/firmware_loader/fallback.c - context differences when deleting old code drivers/base/firmware_loader/sysfs.c - the new code had to be modified to match the code moved from fallback.c Notably, CONFIG_FW_LOADER_USER_HELPER references were removed and (un)register_sysfs_loader was simplified and the references to firmware_config_sysctl() were removed. commit e0c11a8b985137aebf4bcd07cd957b80ac23924d Author: Russ Weight <russell.h.weight@intel.com> Date: Thu, 21 Apr 2022 14:21:59 -0700 In preparation for sharing the "loading" and "data" sysfs nodes with the new firmware upload support, split out sysfs functionality from fallback.c and fallback.h into sysfs.c and sysfs.h. This includes the firmware class driver code that is associated with the sysfs files and the fw_fallback_config support for the timeout sysfs node. CONFIG_FW_LOADER_SYSFS is created and is selected by CONFIG_FW_LOADER_USER_HELPER in order to include sysfs.o in firmware_class-objs. This is mostly just a code reorganization. There are a few symbols that change in scope, and these can be identified by looking at the header file changes. A few white-space warnings from checkpatch are also addressed in this patch. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com> Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Signed-off-by: Russ Weight <russell.h.weight@intel.com> Link: https://lore.kernel.org/r/20220421212204.36052-4-russell.h.weight@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 20:47:41 +00:00
else
firmware_loader: Replace kmap() with kmap_local_page() Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 commit f2d57765b79857264fb0ddc52679d661b60ecc21 Author: "Fabio M. De Francesco" <fmdefrancesco@gmail.com> Date: Fri, 15 Jul 2022 01:50:30 +0200 The use of kmap() is being deprecated in favor of kmap_local_page(). Two main problems with kmap(): (1) It comes with an overhead as mapping space is restricted and protected by a global lock for synchronization and (2) kmap() also requires global TLB invalidation when the kmap’s pool wraps and it might block when the mapping space is fully utilized until a slot becomes available. kmap_local_page() is preferred over kmap() and kmap_atomic(). Where it cannot mechanically replace the latters, code refactor should be considered (special care must be taken if kernel virtual addresses are aliases in different contexts). With kmap_local_page() the mappings are per thread, CPU local, can take page faults, and can be called from any context (including interrupts). Call kmap_local_page() in firmware_loader wherever kmap() is currently used. In firmware_rw() use the helpers copy_{from,to}_page() instead of open coding the local mappings + memcpy(). Successfully tested with "firmware" selftests on a QEMU/KVM 32-bits VM with 4GB RAM, booting a kernel with HIGHMEM64GB enabled. Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Luis Chamberlain <mcgrof@kernel.org> Suggested-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com> Link: https://lore.kernel.org/r/20220714235030.12732-1-fmdefrancesco@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 21:07:53 +00:00
memcpy_to_page(fw_priv->pages[page_nr], page_ofs,
buffer, page_cnt);
firmware_loader: Split sysfs support from fallback Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 Conflicts: drivers/base/firmware_loader/fallback.c - context differences when deleting old code drivers/base/firmware_loader/sysfs.c - the new code had to be modified to match the code moved from fallback.c Notably, CONFIG_FW_LOADER_USER_HELPER references were removed and (un)register_sysfs_loader was simplified and the references to firmware_config_sysctl() were removed. commit e0c11a8b985137aebf4bcd07cd957b80ac23924d Author: Russ Weight <russell.h.weight@intel.com> Date: Thu, 21 Apr 2022 14:21:59 -0700 In preparation for sharing the "loading" and "data" sysfs nodes with the new firmware upload support, split out sysfs functionality from fallback.c and fallback.h into sysfs.c and sysfs.h. This includes the firmware class driver code that is associated with the sysfs files and the fw_fallback_config support for the timeout sysfs node. CONFIG_FW_LOADER_SYSFS is created and is selected by CONFIG_FW_LOADER_USER_HELPER in order to include sysfs.o in firmware_class-objs. This is mostly just a code reorganization. There are a few symbols that change in scope, and these can be identified by looking at the header file changes. A few white-space warnings from checkpatch are also addressed in this patch. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com> Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Signed-off-by: Russ Weight <russell.h.weight@intel.com> Link: https://lore.kernel.org/r/20220421212204.36052-4-russell.h.weight@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 20:47:41 +00:00
buffer += page_cnt;
offset += page_cnt;
count -= page_cnt;
}
}
static ssize_t firmware_data_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buffer, loff_t offset, size_t count)
{
struct device *dev = kobj_to_dev(kobj);
struct fw_sysfs *fw_sysfs = to_fw_sysfs(dev);
struct fw_priv *fw_priv;
ssize_t ret_count;
mutex_lock(&fw_lock);
fw_priv = fw_sysfs->fw_priv;
if (!fw_priv || fw_state_is_done(fw_priv)) {
ret_count = -ENODEV;
goto out;
}
if (offset > fw_priv->size) {
ret_count = 0;
goto out;
}
if (count > fw_priv->size - offset)
count = fw_priv->size - offset;
ret_count = count;
if (fw_priv->data)
firmware_rw_data(fw_priv, buffer, offset, count, true);
else
firmware_rw(fw_priv, buffer, offset, count, true);
out:
mutex_unlock(&fw_lock);
return ret_count;
}
static int fw_realloc_pages(struct fw_sysfs *fw_sysfs, int min_size)
{
int err;
err = fw_grow_paged_buf(fw_sysfs->fw_priv,
PAGE_ALIGN(min_size) >> PAGE_SHIFT);
if (err)
fw_load_abort(fw_sysfs);
return err;
}
/**
* firmware_data_write() - write method for firmware
* @filp: open sysfs file
* @kobj: kobject for the device
* @bin_attr: bin_attr structure
* @buffer: buffer being written
* @offset: buffer offset for write in total data store area
* @count: buffer size
*
* Data written to the 'data' attribute will be later handed to
* the driver as a firmware image.
**/
static ssize_t firmware_data_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buffer, loff_t offset, size_t count)
{
struct device *dev = kobj_to_dev(kobj);
struct fw_sysfs *fw_sysfs = to_fw_sysfs(dev);
struct fw_priv *fw_priv;
ssize_t retval;
if (!capable(CAP_SYS_RAWIO))
return -EPERM;
mutex_lock(&fw_lock);
fw_priv = fw_sysfs->fw_priv;
if (!fw_priv || fw_state_is_done(fw_priv)) {
retval = -ENODEV;
goto out;
}
if (fw_priv->data) {
if (offset + count > fw_priv->allocated_size) {
retval = -ENOMEM;
goto out;
}
firmware_rw_data(fw_priv, buffer, offset, count, false);
retval = count;
} else {
retval = fw_realloc_pages(fw_sysfs, offset + count);
if (retval)
goto out;
retval = count;
firmware_rw(fw_priv, buffer, offset, count, false);
}
fw_priv->size = max_t(size_t, offset + count, fw_priv->size);
out:
mutex_unlock(&fw_lock);
return retval;
}
static struct bin_attribute firmware_attr_data = {
.attr = { .name = "data", .mode = 0644 },
.size = 0,
.read = firmware_data_read,
.write = firmware_data_write,
};
static struct attribute *fw_dev_attrs[] = {
&dev_attr_loading.attr,
#ifdef CONFIG_FW_UPLOAD
&dev_attr_cancel.attr,
&dev_attr_status.attr,
&dev_attr_error.attr,
&dev_attr_remaining_size.attr,
#endif
firmware_loader: Split sysfs support from fallback Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 Conflicts: drivers/base/firmware_loader/fallback.c - context differences when deleting old code drivers/base/firmware_loader/sysfs.c - the new code had to be modified to match the code moved from fallback.c Notably, CONFIG_FW_LOADER_USER_HELPER references were removed and (un)register_sysfs_loader was simplified and the references to firmware_config_sysctl() were removed. commit e0c11a8b985137aebf4bcd07cd957b80ac23924d Author: Russ Weight <russell.h.weight@intel.com> Date: Thu, 21 Apr 2022 14:21:59 -0700 In preparation for sharing the "loading" and "data" sysfs nodes with the new firmware upload support, split out sysfs functionality from fallback.c and fallback.h into sysfs.c and sysfs.h. This includes the firmware class driver code that is associated with the sysfs files and the fw_fallback_config support for the timeout sysfs node. CONFIG_FW_LOADER_SYSFS is created and is selected by CONFIG_FW_LOADER_USER_HELPER in order to include sysfs.o in firmware_class-objs. This is mostly just a code reorganization. There are a few symbols that change in scope, and these can be identified by looking at the header file changes. A few white-space warnings from checkpatch are also addressed in this patch. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com> Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Signed-off-by: Russ Weight <russell.h.weight@intel.com> Link: https://lore.kernel.org/r/20220421212204.36052-4-russell.h.weight@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 20:47:41 +00:00
NULL
};
static struct bin_attribute *fw_dev_bin_attrs[] = {
&firmware_attr_data,
NULL
};
static const struct attribute_group fw_dev_attr_group = {
.attrs = fw_dev_attrs,
.bin_attrs = fw_dev_bin_attrs,
#ifdef CONFIG_FW_UPLOAD
.is_visible = fw_upload_is_visible,
#endif
firmware_loader: Split sysfs support from fallback Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122318 Conflicts: drivers/base/firmware_loader/fallback.c - context differences when deleting old code drivers/base/firmware_loader/sysfs.c - the new code had to be modified to match the code moved from fallback.c Notably, CONFIG_FW_LOADER_USER_HELPER references were removed and (un)register_sysfs_loader was simplified and the references to firmware_config_sysctl() were removed. commit e0c11a8b985137aebf4bcd07cd957b80ac23924d Author: Russ Weight <russell.h.weight@intel.com> Date: Thu, 21 Apr 2022 14:21:59 -0700 In preparation for sharing the "loading" and "data" sysfs nodes with the new firmware upload support, split out sysfs functionality from fallback.c and fallback.h into sysfs.c and sysfs.h. This includes the firmware class driver code that is associated with the sysfs files and the fw_fallback_config support for the timeout sysfs node. CONFIG_FW_LOADER_SYSFS is created and is selected by CONFIG_FW_LOADER_USER_HELPER in order to include sysfs.o in firmware_class-objs. This is mostly just a code reorganization. There are a few symbols that change in scope, and these can be identified by looking at the header file changes. A few white-space warnings from checkpatch are also addressed in this patch. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Tianfei zhang <tianfei.zhang@intel.com> Tested-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Signed-off-by: Russ Weight <russell.h.weight@intel.com> Link: https://lore.kernel.org/r/20220421212204.36052-4-russell.h.weight@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-10-04 20:47:41 +00:00
};
static const struct attribute_group *fw_dev_attr_groups[] = {
&fw_dev_attr_group,
NULL
};
struct fw_sysfs *
fw_create_instance(struct firmware *firmware, const char *fw_name,
struct device *device, u32 opt_flags)
{
struct fw_sysfs *fw_sysfs;
struct device *f_dev;
fw_sysfs = kzalloc(sizeof(*fw_sysfs), GFP_KERNEL);
if (!fw_sysfs) {
fw_sysfs = ERR_PTR(-ENOMEM);
goto exit;
}
fw_sysfs->nowait = !!(opt_flags & FW_OPT_NOWAIT);
fw_sysfs->fw = firmware;
f_dev = &fw_sysfs->dev;
device_initialize(f_dev);
dev_set_name(f_dev, "%s", fw_name);
f_dev->parent = device;
f_dev->class = &firmware_class;
f_dev->groups = fw_dev_attr_groups;
exit:
return fw_sysfs;
}