Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2093420rdb; Mon, 20 Nov 2023 01:28:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IHSzLrAyiuHS6YWfenZNm92PGrbHUXc3mHAkBG/+8e+WJbbJ9nWLXUv5TatzJ1zfdPExDaP X-Received: by 2002:a05:6870:788c:b0:1f5:b5ca:435e with SMTP id hc12-20020a056870788c00b001f5b5ca435emr7878314oab.52.1700472500393; Mon, 20 Nov 2023 01:28:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700472500; cv=none; d=google.com; s=arc-20160816; b=YPDo3SNNKm/W6qfbS0QDOFhAKYQqxqMlK/WNVMqUGS/xnxhsu4+7cuZcX0CwBY09HV NQRHjYtVG1czhY8BcMdSrhR61LuKXut8ivOxvgPs6SCHfJI7hp24IiRsW74BZbyp/mhP AgdihgGnEWG+Z82SzYbYy/1SYivlQwsnpqt47FvhR97Vofl5I76NIjIICD20U6V6ULVm K0eNGkwUryqqaerxiNJKppXiszAdqCNR4DEvmDHHOm8prasOdid8Jl+cfKqM/R84omcl sssTAhCX0SX9PlSQaYenbSDGzvr50BvdMFJjuUsFyWQrozW+qD0zmZCNj4rAfKIeQJLb u0KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-id:mime-version:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=MLVUktbkKPfXcsNUMvVPcmjhIDhI+S2HocBHskRvXBA=; fh=jYya/AvJOh/sQSCpCwl3UAupIwf/01QJ44wmo4o8hfM=; b=nO3FCko0Qa+5qN+0HRwCdJ4tl+P68IGNLJvxB8fQ92WXIZJiZeg0xxbUta9+Qk1YVn 08UoVJiOiEH4/UXsDqlFCaqoTPqXU+Qr1iGWuZYscVXn0hOOBcdYoMXlLfaLzSJtA3XM pnesjRFi2w1iZ2M2pvqoMxMhLJKK8eKObVO1iNI08VmKTcLwkMwAQ7ECDJRl5jZ6EfAB lb1lb9TMpTBWZB3KcyD7779x9eOMgOYB4oyepLpekEDXv+GV1f8yeCcBs6l/rILGY+9v 7aAM09rqNjeITl73/K8K/fGngR3U4rUEgvZqMlaifJgaBCmXaydRU0D7Y9EjC6ytcrXp U/Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="RoO18/ZU"; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id bo7-20020a056a02038700b005b9b45ba3c1si8571627pgb.563.2023.11.20.01.28.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 01:28:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="RoO18/ZU"; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4CD02806CC30; Mon, 20 Nov 2023 01:25:17 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232571AbjKTJZN (ORCPT + 54 others); Mon, 20 Nov 2023 04:25:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231997AbjKTJZM (ORCPT ); Mon, 20 Nov 2023 04:25:12 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5F4DCD; Mon, 20 Nov 2023 01:25:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700472308; x=1732008308; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version:content-id; bh=BVUYYQ1JYAQmJwUnfzncwjq61tORuEuESunZjowyk9o=; b=RoO18/ZUgKH+IGafBqYuRiwNfDVEkPmNmRc0YsFPvqJ6ALrkh2I5Fpbk U5/Krds5dG7rsKf+vImHCYkUWVgf2YfSOpgNXqfmlFb5woNZM45fgzbHo lw5FjVIfVQs2+geGQMsfVliUtNhsvlECTydNvTPSFd2infdrl0/fl38uB XOsuajJQy10sBu8T5QVq1nVyFNOckUzrjvnFyTHi3yZeBo8pWQC+PmjXJ QWP1iCkr6x3u5bc1VV8kPsd8CNq7I2HuXT4LfaFweWwgOfHcZps+FpiYS w4Bzfg2dwGd1XPtB9VB/zeTZoe1pysD5Q3Y/Y9DZh3G/m/otpwzmSkRhJ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="4765284" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="4765284" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 01:25:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="795418486" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="795418486" Received: from akeren-mobl.ger.corp.intel.com ([10.252.40.26]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 01:25:05 -0800 Date: Mon, 20 Nov 2023 11:25:03 +0200 (EET) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: Bjorn Helgaas cc: "John W. Linville" , Kalle Valo , Larry Finger , linux-wireless@vger.kernel.org, Ping-Ke Shih , Bjorn Helgaas , LKML Subject: Re: [PATCH 1/7] wifi: rtlwifi: Convert LNKCTL change to PCIe cap RMW accessors In-Reply-To: <20231117222416.GA94936@bhelgaas> Message-ID: References: <20231117222416.GA94936@bhelgaas> MIME-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="8323329-1911404933-1700466388=:2032" Content-ID: <118f9d3-aec8-f64a-2857-2dfad61f381c@linux.intel.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 01:25:17 -0800 (PST) This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-1911404933-1700466388=:2032 Content-Type: text/plain; CHARSET=ISO-8859-15 Content-Transfer-Encoding: 8BIT Content-ID: <79bf996f-ae7-d121-1633-98d3cdbca3de@linux.intel.com> On Fri, 17 Nov 2023, Bjorn Helgaas wrote: > On Fri, Nov 17, 2023 at 11:44:19AM +0200, Ilpo J?rvinen wrote: > > The rtlwifi driver comes with custom code to write into PCIe Link > > Control register. RMW access for the Link Control register requires > > locking that is already provided by the standard PCIe capability > > accessors. > > > > Convert the custom RMW code writing into LNKCTL register to standard > > RMW capability accessors. The accesses are changed to cover the full > > LNKCTL register instead of touching just a single byte of the register. > > > > After custom LNKCTL access code is removed, .num4bytes in the struct > > mp_adapter is no longer needed. > > Looks like some nice fixes here. I confess they're not all obvious to > me. It took a while to figure out what it is doing, yes... and while figuring it out, I found more and more to cleanup... And seems you also found some more... ;-) lol. When going all the way with cleanups, I tend run this kind of things that are not all that obvious but those are usually the most valuable cleanups (and normally cannot be automated either so we'll have a lot less people looking at them). > > @@ -164,21 +164,27 @@ static bool _rtl_pci_platform_switch_device_pci_aspm( > > struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); > > struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); > > > > + value &= PCI_EXP_LNKCTL_ASPMC; > > + > > if (rtlhal->hw_type != HARDWARE_TYPE_RTL8192SE) > > value |= 0x40; > > I guess this 0x40 is PCI_EXP_LNKCTL_CCC? Good point, I forgot to change that in 2/7 and it belongs logically into this patch anyway so I'll add it to this patch. > > - pci_write_config_byte(rtlpci->pdev, 0x80, value); > > + pcie_capability_clear_and_set_word(rtlpci->pdev, PCI_EXP_LNKCTL, > > PCI_EXP_LNKCTL is 0x10, so I guess we know somehow that the PCIe > Capability is at 0x70? It's what I inferred based on the offsets of LNKCTL & DEVCTL2. And if that assumption does not hold with all these devices, the writes would just wreck some random havoc. :-/ > > + PCI_EXP_LNKCTL_ASPMC | value, > > + value); > > > > return false; > > } > > > > /*When we set 0x01 to enable clk request. Set 0x0 to disable clk req.*/ > > -static void _rtl_pci_switch_clk_req(struct ieee80211_hw *hw, u8 value) > > +static void _rtl_pci_switch_clk_req(struct ieee80211_hw *hw, u16 value) > > { > > struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); > > struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); > > > > - pci_write_config_byte(rtlpci->pdev, 0x81, value); > > + pcie_capability_clear_and_set_word(rtlpci->pdev, PCI_EXP_LNKCTL, > > + PCI_EXP_LNKCTL_CLKREQ_EN, > > Depends on the fact that the caller only passes 0 or 1. Ugly, but > looks true, and I see you clean this up a little more later. I like > how you made it explicit in _rtl_pci_platform_switch_device_pci_aspm() > above by masking the value to set. I thought of adding the masking here too but since it wasn't strictly necessary, I didn't. But I can add that now and I'll also update the comment to match the code :-). These code fragments hopefully die anyway once I get the ASPM from drivers to core series done. > > @@ -268,13 +267,14 @@ static void rtl_pci_enable_aspm(struct ieee80211_hw *hw) > > if (pcibridge_vendor == PCI_BRIDGE_VENDOR_INTEL) > > u_pcibridge_aspmsetting &= ~BIT(0); > > > > - pci_write_config_byte(rtlpci->pdev, (num4bytes << 2), > > - u_pcibridge_aspmsetting); > > + pcie_capability_clear_and_set_word(rtlpci->pdev, PCI_EXP_LNKCTL, > > + PCI_EXP_LNKCTL_ASPMC, > > + u_pcibridge_aspmsetting & > > + PCI_EXP_LNKCTL_ASPMC); > > > > rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, > > - "PlatformEnableASPM(): Write reg[%x] = %x\n", > > - (pcipriv->ndis_adapter.pcibridge_pciehdr_offset + 0x10), > > - u_pcibridge_aspmsetting); > > + "PlatformEnableASPM(): Write ASPM = %x\n", > > + u_pcibridge_aspmsetting & PCI_EXP_LNKCTL_ASPMC); > > > > udelay(50); > > @@ -2030,8 +2031,6 @@ static bool _rtl_pci_find_adapter(struct pci_dev *pdev, > > PCI_FUNC(bridge_pdev->devfn); > > pcipriv->ndis_adapter.pcibridge_pciehdr_offset = > > pci_pcie_cap(bridge_pdev); > > - pcipriv->ndis_adapter.num4bytes = > > - (pcipriv->ndis_adapter.pcibridge_pciehdr_offset + 0x10) / 4; > > I don't understand what's going on here. Are we caching the PCIe > Capability offset of the *upstream bridge* here? And then computing > the dword offset of the *bridge's* LNKCTL? And then writing a byte to > the rtlwifi device (not the bridge) at the dword offset << 2, i.e., the > byte offset? I must be out to lunch, because how could that ever > work? > > If we were using the bridge capability location to write to the > rtlwifi device, that would clearly be a bug fix that would merit its > own patch. Oh no, I entirely missed it because of those nice comments which tell it's trying to update bridge's ASPM so I didn't pay attention to which device it passes for real... Now I'm left to wonder what would be the best course of action here... Since it has never really written to bridge's ASPM at all, perhaps that's not needed and those writes could just be dropped rather than point them to the correct device. > Maybe this num4bytes thing could be its own patch, too. Seems so > cumbersome that it makes me wonder if the device has issues with > larger accesses. I thought of that but since it was just 2 extra context blocks which are clearly disjoint from the rest, I didn't separate the removal of the member variable to its own patch. -- i. --8323329-1911404933-1700466388=:2032--