Received: by 10.223.185.111 with SMTP id b44csp1452222wrg; Sat, 10 Mar 2018 06:17:28 -0800 (PST) X-Google-Smtp-Source: AG47ELur4qkExzpk9Rz1nD3uJPjKkHJ4CdI5PMN/trB4gesQFfMRhfpYynvELUzw14fehmCvEkl5 X-Received: by 10.98.231.26 with SMTP id s26mr2125773pfh.210.1520691448573; Sat, 10 Mar 2018 06:17:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520691448; cv=none; d=google.com; s=arc-20160816; b=gQ67zz5WUrr1sP20Yz5ObbiQbXMFi14B3zuoMHpfw/FI9mL0a2cyx7qZIyaRBgGvIO QM9IauDO0db66LalM9UhYWWGWofFfNRGjZ//LDbTWRGX44b9EDQ3P0aK0Lch8PWiv9h2 oMUVIneIjHU8a5SpvWXM3GBFhxDJLG/uA0NnQI3qtF5wCGDd14YwHnAUxwG/CRyGsKPh gLmUZyaDnYw5eTdfDJ7H+TIaQM6e8vRSHtTR/1Uqv2xiIyLrPpFTyyuXPxC/qLkxJ0LT kqso7GJoxCdT2btNYslwlexUH7VmQKYhYzKoAxaOS8f62VQ5W47sTnJqYEmEPuVjCov6 8chA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:arc-authentication-results; bh=xWZq61tGkwxl7GT0aBWYE6fOeXBFZCpKKFxkSinR6lM=; b=FUwYIbn8qgm8HgVWUA9zGmsqEHZ1ZfcxdouB1Jg/WiTgomSK4QAi7lK2A4PJzDLC4A w1hkHtWMXSESzNZ2GF4QZrXpjJszrsWYjAN9yyVDb9CcDlNZg6mUw+abRZnjCcwIuM47 AWa2SY5QpwRZk5TvebE9gIow5lRoIlVIqutuTfFBvXD0/E76/NqvB70TqZMhFjMurIio lNlyXIqVw3IkJcEpVnLudMLu62zBA1JjY0PWRSZ8aCSxBk/+e42g/tYXmde95PUxZDdv jt8q2L321/uPfvmCaB6zaHPJng6pO3mLO2S9+24Fo3fHrxAc7wTADDGhLKgD5tvkC3ml xe6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4-v6si2840365plp.672.2018.03.10.06.17.14; Sat, 10 Mar 2018 06:17:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932964AbeCJOQA (ORCPT + 99 others); Sat, 10 Mar 2018 09:16:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:50982 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933207AbeCJOPg (ORCPT ); Sat, 10 Mar 2018 09:15:36 -0500 Received: from garbanzo.do-not-panic.com (c-73-15-241-2.hsd1.ca.comcast.net [73.15.241.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 33777217D5; Sat, 10 Mar 2018 14:15:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 33777217D5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=mcgrof@kernel.org From: "Luis R. Rodriguez" To: gregkh@linuxfoundation.org Cc: akpm@linux-foundation.org, cantabile.desu@gmail.com, kubakici@wp.pl, linux-wireless@vger.kernel.org, keescook@chromium.org, shuah@kernel.org, mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com, dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de, arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com, markivx@codeaurora.org, broonie@kernel.org, dmitry.torokhov@gmail.com, dwmw2@infradead.org, torvalds@linux-foundation.org, Abhay_Salunke@dell.com, bjorn.andersson@linaro.org, jewalt@lgsinnovations.com, oneukum@suse.com, ast@fb.com, andresx7@gmail.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Luis R. Rodriguez" Subject: [PATCH v3 19/20] firmware: add request_firmware_cache() to help with cache on reboot Date: Sat, 10 Mar 2018 06:15:00 -0800 Message-Id: <20180310141501.2214-20-mcgrof@kernel.org> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20180310141501.2214-1-mcgrof@kernel.org> References: <20180310141501.2214-1-mcgrof@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- .../driver-api/firmware/request_firmware.rst | 14 +++++++++++++ drivers/base/firmware_loader/main.c | 24 ++++++++++++++++++++++ include/linux/firmware.h | 3 +++ 3 files changed, 41 insertions(+) diff --git a/Documentation/driver-api/firmware/request_firmware.rst b/Documentation/driver-api/firmware/request_firmware.rst index cc0aea880824..b554f4338859 100644 --- a/Documentation/driver-api/firmware/request_firmware.rst +++ b/Documentation/driver-api/firmware/request_firmware.rst @@ -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 request_firmware_cache() insted of requesting for the +firmare to be loaded. + +request_firmware_cache() +----------------------- +.. kernel-doc:: drivers/base/firmware_class.c + :functions: request_firmware_load + request firmware API expected driver use ======================================== diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c index 2913bb0e5e7b..04bf853f60e9 100644 --- a/drivers/base/firmware_loader/main.c +++ b/drivers/base/firmware_loader/main.c @@ -656,6 +656,30 @@ int request_firmware_direct(const struct firmware **firmware_p, } EXPORT_SYMBOL_GPL(request_firmware_direct); +/** + * request_firmware_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 request_firmware_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(request_firmware_cache); + /** * request_firmware_into_buf - load firmware into a previously allocated buffer * @firmware_p: pointer to firmware image diff --git a/include/linux/firmware.h b/include/linux/firmware.h index d4508080348d..166867910ebc 100644 --- a/include/linux/firmware.h +++ b/include/linux/firmware.h @@ -85,4 +85,7 @@ static inline int request_firmware_into_buf(const struct firmware **firmware_p, } #endif + +int request_firmware_cache(struct device *device, const char *name); + #endif -- 2.16.2