Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp827225ybx; Thu, 7 Nov 2019 03:18:18 -0800 (PST) X-Google-Smtp-Source: APXvYqxR4flwZGXn5fyEdkT3HPZXBkBYhoYfmToz64qvdUlEFVcAr1SJwVh4qlFyLCLqPwKl+uwu X-Received: by 2002:aa7:dd9a:: with SMTP id g26mr2890772edv.85.1573125497895; Thu, 07 Nov 2019 03:18:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573125497; cv=none; d=google.com; s=arc-20160816; b=zpSGq0fLeyLmWW0Zg2dnU3iiy2cAdhf610UkRZEjSZfZqm9u5qW4xdNGHFUkyzlC3P 9Vi4caoF0aQ2Etz6br2uzAGCQQNa1yyaLKd4hhsuliv2XvktLZh3frowgMenYe9sOwlT ZzMZ447u/VmDBSJ/DLedlel1BvA6zW5wswhyA6fFldzbI1L80roFp3Xdt5ZchUy40saV kyK/jp3zP1K4y1VgzEv/DwcBTU3rT2b2tFP6tvyUOgGjw2LiVLcIZwoF1FUbOPNWgWhw unwXFB8vLHpRQo+c5gPvFeleqI2PgmIjnGvAVzh6zJ5VwA4LSRS0C/1WtiVL5/1rthWa 1XSA== 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=ovlEzO5O8IK51vEbThwZwe7mb0rSy7jGt3EYe/af0+4=; b=UVGa5/bofN6ZhFUOYMmlD68H71y9UAATvVunHPh5tbFiNLo8ZJE0wh/2RtVDkAPtWr pq057+s2zso8xThSaFfOGXSGPcZlFvRhtUomxRKs1vHPM9K6xr2lg7NAu54ifKJoXk88 d3mOUZAnv9n8QXy0EYmkNyVUu8X5UpizC/u7ZvRg4l5lU9SqMi0s2rlmQz+M+SkUpPno ZHZrWUxj5BgsozFQ6ecleovoTfeHg77cE9AiDQOXdrKzUlR6ussIHfi/Ap9AxBZ8NA4R /EM1rrp5/0/JIgb3YphQoKyeZdbGB9A0evS/MGwIl8oL3gClVxNhkDbfxaSzxitsV8Te s8kg== 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 p3si1184926edj.395.2019.11.07.03.17.42; Thu, 07 Nov 2019 03:18:17 -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 S2388427AbfKGLQO (ORCPT + 99 others); Thu, 7 Nov 2019 06:16:14 -0500 Received: from rtits2.realtek.com ([211.75.126.72]:43301 "EHLO rtits2.realtek.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727528AbfKGLQO (ORCPT ); Thu, 7 Nov 2019 06:16:14 -0500 Authenticated-By: X-SpamFilter-By: BOX Solutions SpamTrap 5.62 with qID xA7BG8nU012869, 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 xA7BG8nU012869 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 7 Nov 2019 19:16:08 +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, 7 Nov 2019 19:16:08 +0800 From: To: CC: , Subject: [PATCH 2/4] rtw88: pci: use for loop instead of while loop for DBI/MDIO Date: Thu, 7 Nov 2019 19:16:01 +0800 Message-ID: <20191107111603.12317-3-yhchuang@realtek.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191107111603.12317-1-yhchuang@realtek.com> References: <20191107111603.12317-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: Yan-Hsuan Chuang Use a for loop to polling DBI/MDIO read/write flags to avoid infinite loop happens Signed-off-by: Yan-Hsuan Chuang --- drivers/net/wireless/realtek/rtw88/pci.c | 26 +++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/pci.c b/drivers/net/wireless/realtek/rtw88/pci.c index b158ef8ded17..6d1aa6f41e84 100644 --- a/drivers/net/wireless/realtek/rtw88/pci.c +++ b/drivers/net/wireless/realtek/rtw88/pci.c @@ -1062,7 +1062,7 @@ static void rtw_dbi_write8(struct rtw_dev *rtwdev, u16 addr, u8 data) u16 write_addr; u16 remainder = addr & ~(BITS_DBI_WREN | BITS_DBI_ADDR_MASK); u8 flag; - u8 cnt = RTW_PCI_WR_RETRY_CNT; + u8 cnt; write_addr = addr & BITS_DBI_ADDR_MASK; write_addr |= u16_encode_bits(BIT(remainder), BITS_DBI_WREN); @@ -1070,21 +1070,22 @@ static void rtw_dbi_write8(struct rtw_dev *rtwdev, u16 addr, u8 data) rtw_write16(rtwdev, REG_DBI_FLAG_V1, write_addr); rtw_write8(rtwdev, REG_DBI_FLAG_V1 + 2, BIT_DBI_WFLAG >> 16); - flag = rtw_read8(rtwdev, REG_DBI_FLAG_V1 + 2); - while (flag && (cnt != 0)) { - udelay(10); + for (cnt = 0; cnt < RTW_PCI_WR_RETRY_CNT; cnt++) { flag = rtw_read8(rtwdev, REG_DBI_FLAG_V1 + 2); - cnt--; + if (flag == 0) + return; + + udelay(10); } - WARN(flag, "DBI write fail\n"); + WARN(flag, "failed to write to DBI register, addr=0x%04x\n", addr); } static void rtw_mdio_write(struct rtw_dev *rtwdev, u8 addr, u16 data, bool g1) { u8 page; u8 wflag; - u8 cnt = RTW_PCI_WR_RETRY_CNT; + u8 cnt; rtw_write16(rtwdev, REG_MDIO_V1, data); @@ -1094,15 +1095,16 @@ static void rtw_mdio_write(struct rtw_dev *rtwdev, u8 addr, u16 data, bool g1) rtw_write8(rtwdev, REG_PCIE_MIX_CFG + 3, page); rtw_write32_mask(rtwdev, REG_PCIE_MIX_CFG, BIT_MDIO_WFLAG_V1, 1); - wflag = rtw_read32_mask(rtwdev, REG_PCIE_MIX_CFG, BIT_MDIO_WFLAG_V1); - while (wflag && (cnt != 0)) { - udelay(10); + for (cnt = 0; cnt < RTW_PCI_WR_RETRY_CNT; cnt++) { wflag = rtw_read32_mask(rtwdev, REG_PCIE_MIX_CFG, BIT_MDIO_WFLAG_V1); - cnt--; + if (wflag == 0) + return; + + udelay(10); } - WARN(wflag, "MDIO write fail\n"); + WARN(wflag, "failed to write to MDIO register, addr=0x%02x\n", addr); } static void rtw_pci_phy_cfg(struct rtw_dev *rtwdev) -- 2.17.1