Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp437634ybn; Wed, 2 Oct 2019 00:08:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqz25o8eN9WBsa/S12gd5Ob0TDSAm6A1phQmpUnxRMkL38rCvFIF/lOKwXsrkevXk1p9FPiy X-Received: by 2002:a05:6402:2cb:: with SMTP id b11mr2181153edx.285.1570000100779; Wed, 02 Oct 2019 00:08:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570000100; cv=none; d=google.com; s=arc-20160816; b=L39eSdK4puQcBGrwbTwebDNpS85P06Q6zZiLjHFFpva9o22clMEaY7CIuMvCPZsrFO MU1Bu0nNQ5kWJfzNS2bNk1x0rclw7NBgCH6xcpkaiKnWHetZD+HYgACORo/AKZ4Q1uws +Zf4tOSoat/PZb3lJiB7TYV21qw7wGYiHJwL+DQnj5MiGRwXlOgB6fu4HTSkOA0iXEgB SiTezmpjvQcd7RCQD5+4FIIn9I5dK5sNAkOY2RCc8gGeU9oaP3oTsYg59WkKsmgzHCEK j8Sx7bNthah/FiHhNrb07pMRgrqozmn0RKbpl7AJ9ZPxtYzEO71dn0ONToh7xnI5Eua1 FzjA== 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=BsSaId9Ik2L1ZFwFpXJNBYV1MUieyR2fVo2tlxJjXsw=; b=WQ8HCH4tS1RICmKZNZbescV+bxE37PHI7f7H83AwwCquVUvcr0jBeDBHevEsjnAeEk KZ9QXr6J6rh5H8471aP6eX9NaD+699iLHT/5AmCdmXCskWTytIdBfXcFZ89SOjOUC+Ij TBKhW8yLeL2sLL3w9UPr8mUs/LlssOVssqLodGEkBgs2VvwhfwDkkOudlSHnl9cLC3mK xXQnp27qkxiW5Rs7enDdWc2XXFIVImblyX3/FeWUFnWonn13PyJEiAQbPy99wS/7EkUC Z3kQ13T/ibqiQLLJo7c78KB5X4Qj0d2CTQjA4qrsU1WVYoZ5KxqtbRPvJT9q0J7jQxhU tiGg== 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 h50si10628476ede.423.2019.10.02.00.07.55; Wed, 02 Oct 2019 00:08:20 -0700 (PDT) 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 S1726840AbfJBGfm (ORCPT + 99 others); Wed, 2 Oct 2019 02:35:42 -0400 Received: from rtits2.realtek.com ([211.75.126.72]:57690 "EHLO rtits2.realtek.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726202AbfJBGfl (ORCPT ); Wed, 2 Oct 2019 02:35:41 -0400 Authenticated-By: X-SpamFilter-By: BOX Solutions SpamTrap 5.62 with qID x926ZYeV013042, 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 x926ZYeV013042 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 2 Oct 2019 14:35:35 +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; Wed, 2 Oct 2019 14:35:34 +0800 From: To: CC: , Subject: [PATCH 01/14] rtw88: check firmware leave lps successfully Date: Wed, 2 Oct 2019 14:35:18 +0800 Message-ID: <20191002063531.18135-2-yhchuang@realtek.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191002063531.18135-1-yhchuang@realtek.com> References: <20191002063531.18135-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 needs to wait for firmware to restore hardware setting to active mode after leaving lps. After getting H2C from driver for leaving lps, firmware will issue null packet without PS bit to inform AP driver is active, and then restore REG_TCR Register if AP has receiced null packet. But the transmission of null packet may cost much more time in noisy environment. If driver does not wait for firmware, null packet with PS bit could be sent due to incorrect REG_TCR setting. And AP will be confused. In our test, 100ms is enough for firmware to send null packet to AP. If REG_TCR Register is still wrong after 100ms, we will modify it directly, force the PS bit to be cleared Signed-off-by: Chin-Yen Lee Signed-off-by: Yan-Hsuan Chuang --- drivers/net/wireless/realtek/rtw88/ps.c | 29 ++++++++++++++++++++++++ drivers/net/wireless/realtek/rtw88/ps.h | 2 ++ drivers/net/wireless/realtek/rtw88/reg.h | 1 + 3 files changed, 32 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw88/ps.c b/drivers/net/wireless/realtek/rtw88/ps.c index 83db6cf6a219..bf149956b04e 100644 --- a/drivers/net/wireless/realtek/rtw88/ps.c +++ b/drivers/net/wireless/realtek/rtw88/ps.c @@ -9,6 +9,7 @@ #include "mac.h" #include "coex.h" #include "debug.h" +#include "reg.h" static int rtw_ips_pwr_up(struct rtw_dev *rtwdev) { @@ -118,6 +119,32 @@ static void __rtw_leave_lps_deep(struct rtw_dev *rtwdev) rtw_hci_deep_ps(rtwdev, false); } +static void rtw_fw_leave_lps_state_check(struct rtw_dev *rtwdev) +{ + int i; + + /* Driver needs to wait for firmware to leave LPS state + * successfully. Firmware will send null packet to inform AP, + * and see if AP sends an ACK back, then firmware will restore + * the REG_TCR register. + * + * If driver does not wait for firmware, null packet with + * PS bit could be sent due to incorrect REG_TCR setting. + * + * In our test, 100ms should be enough for firmware to finish + * the flow. If REG_TCR Register is still incorrect after 100ms, + * just modify it directly, and throw a warn message. + */ + for (i = 0 ; i < LEAVE_LPS_TRY_CNT; i++) { + if (rtw_read32_mask(rtwdev, REG_TCR, BIT_PWRMGT_HWDATA_EN) == 0) + return; + msleep(20); + } + + rtw_write32_mask(rtwdev, REG_TCR, BIT_PWRMGT_HWDATA_EN, 0); + rtw_warn(rtwdev, "firmware failed to restore hardware setting\n"); +} + static void rtw_leave_lps_core(struct rtw_dev *rtwdev) { struct rtw_lps_conf *conf = &rtwdev->lps_conf; @@ -128,6 +155,8 @@ static void rtw_leave_lps_core(struct rtw_dev *rtwdev) conf->smart_ps = 0; rtw_fw_set_pwr_mode(rtwdev); + rtw_fw_leave_lps_state_check(rtwdev); + clear_bit(RTW_FLAG_LEISURE_PS, rtwdev->flags); rtw_coex_lps_notify(rtwdev, COEX_LPS_DISABLE); diff --git a/drivers/net/wireless/realtek/rtw88/ps.h b/drivers/net/wireless/realtek/rtw88/ps.h index 18f687cfe211..25925eedbad4 100644 --- a/drivers/net/wireless/realtek/rtw88/ps.h +++ b/drivers/net/wireless/realtek/rtw88/ps.h @@ -11,6 +11,8 @@ #define POWER_MODE_PG BIT(4) #define POWER_MODE_LCLK BIT(0) +#define LEAVE_LPS_TRY_CNT 5 + int rtw_enter_ips(struct rtw_dev *rtwdev); int rtw_leave_ips(struct rtw_dev *rtwdev); diff --git a/drivers/net/wireless/realtek/rtw88/reg.h b/drivers/net/wireless/realtek/rtw88/reg.h index fe793e270d22..60014077de77 100644 --- a/drivers/net/wireless/realtek/rtw88/reg.h +++ b/drivers/net/wireless/realtek/rtw88/reg.h @@ -271,6 +271,7 @@ #define BIT_TSFT_SEL_TIMER0 (BIT(4) | BIT(5) | BIT(6)) #define REG_TCR 0x0604 +#define BIT_PWRMGT_HWDATA_EN BIT(7) #define REG_RCR 0x0608 #define BIT_APP_FCS BIT(31) #define BIT_APP_MIC BIT(30) -- 2.17.1