Skip to content

Commit

Permalink
firmware: add firmware_request_cache() to help with cache on reboot
Browse files Browse the repository at this point in the history
Some devices have an optimization in place to enable the firmware to
be retaineed during a system reboot, so after reboot the device can skip
requesting and loading the firmware. This can save up to 1s in load
time. The mt7601u 802.11 device happens to be such a device.

When these devices retain the firmware on a reboot and then suspend
they can miss looking for the firmware on resume. To help with this we
need a way to cache the firmware when such an optimization has taken
place.

Signed-off-by: Luis R. Rodriguez <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
mcgrof authored and gregkh committed Mar 22, 2018
1 parent c6263a4 commit 5d42c96
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Documentation/driver-api/firmware/request_firmware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ request_firmware_nowait
.. kernel-doc:: drivers/base/firmware_class.c
:functions: request_firmware_nowait

Special optimizations on reboot
===============================

Some devices have an optimization in place to enable the firmware to be
retained during system reboot. When such optimizations are used the driver
author must ensure the firmware is still available on resume from suspend,
this can be done with firmware_request_cache() insted of requesting for the
firmare to be loaded.

firmware_request_cache()
-----------------------
.. kernel-doc:: drivers/base/firmware_class.c
:functions: firmware_request_cache

request firmware API expected driver use
========================================

Expand Down
24 changes: 24 additions & 0 deletions drivers/base/firmware_loader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,30 @@ int request_firmware_direct(const struct firmware **firmware_p,
}
EXPORT_SYMBOL_GPL(request_firmware_direct);

/**
* firmware_request_cache: - cache firmware for suspend so resume can use it
* @name: name of firmware file
* @device: device for which firmware should be cached for
*
* There are some devices with an optimization that enables the device to not
* require loading firmware on system reboot. This optimization may still
* require the firmware present on resume from suspend. This routine can be
* used to ensure the firmware is present on resume from suspend in these
* situations. This helper is not compatible with drivers which use
* request_firmware_into_buf() or request_firmware_nowait() with no uevent set.
**/
int firmware_request_cache(struct device *device, const char *name)
{
int ret;

mutex_lock(&fw_lock);
ret = fw_add_devm_name(device, name);
mutex_unlock(&fw_lock);

return ret;
}
EXPORT_SYMBOL_GPL(firmware_request_cache);

/**
* request_firmware_into_buf - load firmware into a previously allocated buffer
* @firmware_p: pointer to firmware image
Expand Down
3 changes: 3 additions & 0 deletions include/linux/firmware.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ static inline int request_firmware_into_buf(const struct firmware **firmware_p,
}

#endif

int firmware_request_cache(struct device *device, const char *name);

#endif

0 comments on commit 5d42c96

Please sign in to comment.