Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3573754pxv; Mon, 12 Jul 2021 21:51:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxc3MzSp3BdRVGnBOQLEBQvHaUY1Jkw2uxuDfKRihjZbT9ieHggYUTdY23Lm2/ejS4RyMLH X-Received: by 2002:a92:360e:: with SMTP id d14mr1623054ila.106.1626151861652; Mon, 12 Jul 2021 21:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626151861; cv=none; d=google.com; s=arc-20160816; b=a8uASiBuFcVKR9DN4axKtRssij2w7fvw5L6t/wjnwXhBjEuetymsmJtGCo90toX1rY K3CRnTpVxR4iEbxGNBFxWcCAiBpro+EgBBpAeku6OA7AMhYMsd7PhYsjB1qKSa9Mxadj aWmPkKtagyxB9jYaI4+3oaYRPP5RPr2TiZCloBCQr5qRim4lTcF2TlF+13fSgpdMVw1X f+hxcNAdRqh1Btrd34YP9ZKp2+68X3BkSQlKJsIqJCWEyHVbpwv4XeyVPkSp/BTuji47 n/ALrf2AbsXi5P3ZTJkNFaAc06gVu/sgtdXDsbxmF8bMw7dBPFyrpEAg4j+53uR0xdL/ x7Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=x5g5j/7sahfM4LxRJ52c5PwziyS1UadMI3k391zw6KU=; b=CersJZIXhTfDPtTJRat8p54jMpDPBfxfMhq+CsrzAs81Zogysgr51jaLb0eOMYLlBi 5oclyMOMB0efromeNMaNMEW9hMZCRguOnN1BGQ9JRHQ0PERpFuRx2/XoPsgqARQEoEb6 981nqyRd/tnT43b8WaHsjpedRyR7p3dDrdReld4lQDcQjTcQugx1dTSdiW3VafWMva+c Dl50qCnIeq5ef68vdDUA7F4Qu4ZxL0cvq30JlNBIJ1Ly9pjJntn2OUofldkexZK/fl5s rAddnXRcwAihqwdZDJdwBaxZNn+ThOQYW9703ql2udyiR/WJBz4JwsFntTb6N/EuquEl e1Qg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p14si23017027ils.62.2021.07.12.21.50.45; Mon, 12 Jul 2021 21:51:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230074AbhGMExV (ORCPT + 99 others); Tue, 13 Jul 2021 00:53:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbhGMExV (ORCPT ); Tue, 13 Jul 2021 00:53:21 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3314C0613DD for ; Mon, 12 Jul 2021 21:50:31 -0700 (PDT) Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3ANE-00041L-9K; Tue, 13 Jul 2021 06:50:24 +0200 Received: from ore by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1m3ANC-0000Cr-4Q; Tue, 13 Jul 2021 06:50:22 +0200 Date: Tue, 13 Jul 2021 06:50:22 +0200 From: Oleksij Rempel To: Brian Norris Cc: Pkshih , "kvalo@codeaurora.org" , "linux-wireless@vger.kernel.org" Subject: Re: [PATCH 04/24] rtw89: add debug files Message-ID: <20210713045022.bki4tlcxnm3pwqdv@pengutronix.de> References: <20210618064625.14131-1-pkshih@realtek.com> <20210618064625.14131-5-pkshih@realtek.com> <20210702072308.GA4184@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 05:46:38 up 222 days, 17:53, 36 users, load average: 0.05, 0.06, 0.03 User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-wireless@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Mon, Jul 12, 2021 at 06:57:37PM -0700, Brian Norris wrote: > On Mon, Jul 5, 2021 at 1:59 AM Pkshih wrote: > > > -----Original Message----- > > > From: Oleksij Rempel [mailto:o.rempel@pengutronix.de] > > > > Based on this and other part of this driver I would recommend to use > > > regmap. It will provide to additional interface for the register > > > access. And typically for the network devices we have an ethtool > > > interface for that. > > > > > > > Could I know the 'regmap' you mentioned? > > include/linux/regmap.h > drivers/base/regmap/ > > It's a driver framework and API for abstracting register accesses, > whether they are accessed directly via MMIO, or behind some kind of > indirect bus (I2C, SPI, etc.). It also happens to have its own debugfs > operators for doing various kinds of register get/set/dump. So if you > can successfully teach your driver to use it, then you don't need to > implement your own debugfs files for it. > > I've only ever used regmap with Device Tree systems (which can more > easily specify syscon nodes, etc. -- see > Documentation/devicetree/bindings/regmap/regmap.txt). I'm totally > unfamiliar how to use this with ACPI (which I'm sure you want to > support). I'm sure it's possible somehow. > > FWIW, search engines turn up a few basic articles about it, if you > find its documentation or code examples too sparse: > https://www.collabora.com/news-and-blog/blog/2020/05/27/using-regmaps-to-make-linux-drivers-more-generic/ There are not ACPI specific register accesses in this driver. It is using simple readl/writel for the PCI accesses. This driver would need to use devm_regmap_init() and register own regmap_bus. I motivate to use it not only to cover debugfs use case: 1. Current driver implements only PCI access, but potentially wont to support SDIO and USB buses: drivers/net/wireless/realtek/rtw89/core.h enum rtw89_hci_type { RTW89_HCI_TYPE_PCIE, RTW89_HCI_TYPE_USB, RTW89_HCI_TYPE_SDIO, }; SDIO and USB buses may return error on any access. So, driver should test if return value is error on every access. regmap read/write functions separate error value from actual register read value and motivate to handle errors in the driver. Suddenly not every mainline driver is doing it. 2. Current driver implements patter based error detection for the PCI bus: static u32 rtw89_pci_ops_read32_cmac(struct rtw89_dev *rtwdev, u32 addr) { struct rtw89_pci *rtwpci = (struct rtw89_pci *)rtwdev->priv; u32 val = readl(rtwpci->mmap + addr); int count; for (count = 0; ; count++) { if (val != RTW89_R32_DEAD) return val; if (count >= MAC_REG_POOL_COUNT) { rtw89_warn(rtwdev, "addr %#x = %#x\n", addr, val); return RTW89_R32_DEAD; } rtw89_pci_ops_write32(rtwdev, R_AX_CK_EN, B_AX_CMAC_ALLCKEN); val = readl(rtwpci->mmap + addr); } return val; } and handle this patter only in one place: .... int rtw89_mac_check_mac_en(struct rtw89_dev *rtwdev, u8 mac_idx, enum rtw89_mac_hwmod_sel sel) { .... r_val = rtw89_read32(rtwdev, R_AX_SYS_ISO_CTRL_EXTEND); .... if (r_val == RTW89_R32_EA || r_val == RTW89_R32_DEAD || (val & r_val) != val) return -EFAULT; return 0; } potentially this should be done on every read attempt for the PCI, and on every read/write for SDIO and USB buses. 3. This driver has traces of watchdog support on the firmware side, so potentially, firmware can return error on any access if it was reset by the watchdog. 4. regmap provide a way to define support register ranges and will warn if calculated register offset goes outside of this range. 5. regamp is endianness aware and will help to make this driver work properly on big-endian systems. Regards, Oleksij -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |