Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6718852ybc; Thu, 28 Nov 2019 04:20:27 -0800 (PST) X-Google-Smtp-Source: APXvYqz73YHefYwZ4Sks/If6jeVyFSmH6P35Dcjq7DsMDX0JiKNxSLnn6vT15foE/Mhic5hinkaI X-Received: by 2002:a17:906:4e99:: with SMTP id v25mr55490452eju.106.1574943626961; Thu, 28 Nov 2019 04:20:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574943626; cv=none; d=google.com; s=arc-20160816; b=uvTqMJoI8FVMOs/+kd6VyyShpnfRa7jVn7UDb/Z3kK7U3YaPAJBgChjVq4uWhTgGS5 FgeYdwOPbrkGsMkgMP82V+yPSrUNoGDI6LE9dPBcEDDGVh95FH9DcA2zXzrQM1P3yuMX eSE70fNv446E6T7PIGoNz3PaydK163W/U7f7jzlcGU3iC7xqH8NkKo+PKY7fzvt8QUoP TASj6C38OP/i2gt9sesfeL7koivA34KohZh5HNVHjHmVg7H8x0SLRRMFS5ZN/zXGFmA1 63QL9sabi88Fpf2K9Qj6DCCR3vZeUaF/gdfRQnIgD06zn4dG9TIilrSjC8nyTRbJUjMi TATQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:authenticated-by; bh=zm8R5Ym6irw9iy0ktda29TF5Fp0IASSo6jjGZ/Uc6Ck=; b=rCO87S3NJv+8LVpjVeCM+XWDRlUc0sXLuA9u4lb6EUArv4Uvu0Vm4MmJt2kHcK1QRj V816h74CqavMXbO3psMuPxNuMpxKtP43s4i+v0vEsLYwO7GRLgWMAPo8v7HdXVMPVyWf OuRXXaLQg5+ySxMY6Ddy/LiMlIvJLExiSRPGefqbh/HKHV9nFMT0BcsgwGMF6ZbpwEH5 ppnvv576EA4FeIJ/8MTwERLEgaO6GuCSGfBYbxuIHmPCsRMB9YgBdsmm5DbjtXjZw+Vg 2M5eWrWKB2A4rvK77arAcU1SLo2g41hrt6zHoNFQQqVTRZE0NRJ1KkRT5FHlWEpxb5aR vq3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-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 c15si11792605ejd.74.2019.11.28.04.20.01; Thu, 28 Nov 2019 04:20:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-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-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726856AbfK1MTV (ORCPT + 99 others); Thu, 28 Nov 2019 07:19:21 -0500 Received: from rtits2.realtek.com ([211.75.126.72]:59535 "EHLO rtits2.realtek.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726296AbfK1MTV (ORCPT ); Thu, 28 Nov 2019 07:19:21 -0500 Authenticated-By: X-SpamFilter-By: BOX Solutions SpamTrap 5.62 with qID xASCJD8S004452, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (RTITCASV01.realtek.com.tw[172.21.6.18]) by rtits2.realtek.com.tw (8.15.2/2.57/5.78) with ESMTPS id xASCJD8S004452 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 28 Nov 2019 20:19:14 +0800 Received: from localhost.localdomain (172.21.68.126) by RTITCASV01.realtek.com.tw (172.21.6.18) with Microsoft SMTP Server id 14.3.468.0; Thu, 28 Nov 2019 20:19:13 +0800 From: To: CC: , Subject: [PATCH 3/6] rtw88: load wowlan firmware if wowlan is supported Date: Thu, 28 Nov 2019 20:19:04 +0800 Message-ID: <20191128121907.6178-4-yhchuang@realtek.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191128121907.6178-1-yhchuang@realtek.com> References: <20191128121907.6178-1-yhchuang@realtek.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.21.68.126] Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Chin-Yen Lee Driver used to download normal firmware only, but some devices support wowlan and require to download wowlan firmware when system suspends. So modify rtw_load_firmware() and its callback to allow driver to download both normal and wowlan firmware. Signed-off-by: Chin-Yen Lee Signed-off-by: Yan-Hsuan Chuang --- drivers/net/wireless/realtek/rtw88/main.c | 72 +++++++++++++++++++---- drivers/net/wireless/realtek/rtw88/main.h | 10 ++++ 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/main.c b/drivers/net/wireless/realtek/rtw88/main.c index ae61415e1665..54e8a0cef14b 100644 --- a/drivers/net/wireless/realtek/rtw88/main.c +++ b/drivers/net/wireless/realtek/rtw88/main.c @@ -793,6 +793,26 @@ void rtw_update_sta_info(struct rtw_dev *rtwdev, struct rtw_sta_info *si) rtw_fw_send_ra_info(rtwdev, si); } +static int rtw_wait_firmware_completion(struct rtw_dev *rtwdev) +{ + struct rtw_chip_info *chip = rtwdev->chip; + struct rtw_fw_state *fw; + + fw = &rtwdev->fw; + wait_for_completion(&fw->completion); + if (!fw->firmware) + return -EINVAL; + + if (chip->wow_fw_name) { + fw = &rtwdev->wow_fw; + wait_for_completion(&fw->completion); + if (!fw->firmware) + return -EINVAL; + } + + return 0; +} + static int rtw_power_on(struct rtw_dev *rtwdev) { struct rtw_chip_info *chip = rtwdev->chip; @@ -813,11 +833,10 @@ static int rtw_power_on(struct rtw_dev *rtwdev) goto err; } - wait_for_completion(&fw->completion); - if (!fw->firmware) { - ret = -EINVAL; - rtw_err(rtwdev, "failed to load firmware\n"); - goto err; + ret = rtw_wait_firmware_completion(rtwdev); + if (ret) { + rtw_err(rtwdev, "failed to wait firmware completion\n"); + goto err_off; } ret = rtw_download_firmware(rtwdev, fw); @@ -1020,8 +1039,8 @@ static void rtw_unset_supported_band(struct ieee80211_hw *hw, static void rtw_load_firmware_cb(const struct firmware *firmware, void *context) { - struct rtw_dev *rtwdev = context; - struct rtw_fw_state *fw = &rtwdev->fw; + struct rtw_fw_state *fw = context; + struct rtw_dev *rtwdev = fw->rtwdev; const struct rtw_fw_hdr *fw_hdr; if (!firmware || !firmware->data) { @@ -1043,17 +1062,35 @@ static void rtw_load_firmware_cb(const struct firmware *firmware, void *context) fw->version, fw->sub_version, fw->sub_index, fw->h2c_version); } -static int rtw_load_firmware(struct rtw_dev *rtwdev, const char *fw_name) +static int rtw_load_firmware(struct rtw_dev *rtwdev, enum rtw_fw_type type) { - struct rtw_fw_state *fw = &rtwdev->fw; + const char *fw_name; + struct rtw_fw_state *fw; int ret; + switch (type) { + case RTW_WOWLAN_FW: + fw = &rtwdev->wow_fw; + fw_name = rtwdev->chip->wow_fw_name; + break; + + case RTW_NORMAL_FW: + fw = &rtwdev->fw; + fw_name = rtwdev->chip->fw_name; + break; + + default: + rtw_warn(rtwdev, "unsupported firmware type\n"); + return -ENOENT; + } + + fw->rtwdev = rtwdev; init_completion(&fw->completion); ret = request_firmware_nowait(THIS_MODULE, true, fw_name, rtwdev->dev, - GFP_KERNEL, rtwdev, rtw_load_firmware_cb); + GFP_KERNEL, fw, rtw_load_firmware_cb); if (ret) { - rtw_err(rtwdev, "async firmware request failed\n"); + rtw_err(rtwdev, "failed to async firmware request\n"); return ret; } @@ -1372,12 +1409,19 @@ int rtw_core_init(struct rtw_dev *rtwdev) BIT_HTC_LOC_CTRL | BIT_APP_PHYSTS | BIT_AB | BIT_AM | BIT_APM; - ret = rtw_load_firmware(rtwdev, rtwdev->chip->fw_name); + ret = rtw_load_firmware(rtwdev, RTW_NORMAL_FW); if (ret) { rtw_warn(rtwdev, "no firmware loaded\n"); return ret; } + if (chip->wow_fw_name) { + ret = rtw_load_firmware(rtwdev, RTW_WOWLAN_FW); + if (ret) { + rtw_warn(rtwdev, "no wow firmware loaded\n"); + return ret; + } + } return 0; } EXPORT_SYMBOL(rtw_core_init); @@ -1385,12 +1429,16 @@ EXPORT_SYMBOL(rtw_core_init); void rtw_core_deinit(struct rtw_dev *rtwdev) { struct rtw_fw_state *fw = &rtwdev->fw; + struct rtw_fw_state *wow_fw = &rtwdev->wow_fw; struct rtw_rsvd_page *rsvd_pkt, *tmp; unsigned long flags; if (fw->firmware) release_firmware(fw->firmware); + if (wow_fw->firmware) + release_firmware(wow_fw->firmware); + tasklet_kill(&rtwdev->tx_tasklet); spin_lock_irqsave(&rtwdev->tx_report.q_lock, flags); skb_queue_purge(&rtwdev->tx_report.queue); diff --git a/drivers/net/wireless/realtek/rtw88/main.h b/drivers/net/wireless/realtek/rtw88/main.h index d012eefcd0da..b7690666fd57 100644 --- a/drivers/net/wireless/realtek/rtw88/main.h +++ b/drivers/net/wireless/realtek/rtw88/main.h @@ -193,6 +193,11 @@ enum rtw_rx_queue_type { RTK_MAX_RX_QUEUE_NUM }; +enum rtw_fw_type { + RTW_NORMAL_FW = 0x0, + RTW_WOWLAN_FW = 0x1, +}; + enum rtw_rate_index { RTW_RATEID_BGN_40M_2SS = 0, RTW_RATEID_BGN_40M_1SS = 1, @@ -1030,6 +1035,8 @@ struct rtw_chip_info { u8 bfer_su_max_num; u8 bfer_mu_max_num; + const char *wow_fw_name; + /* coex paras */ u32 coex_para_ver; u8 bt_desired_ver; @@ -1456,6 +1463,7 @@ struct rtw_fifo_conf { struct rtw_fw_state { const struct firmware *firmware; + struct rtw_dev *rtwdev; struct completion completion; u16 version; u8 sub_version; @@ -1580,6 +1588,8 @@ struct rtw_dev { u8 mp_mode; + struct rtw_fw_state wow_fw; + /* hci related data, must be last */ u8 priv[0] __aligned(sizeof(void *)); }; -- 2.17.1