Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3118525rdb; Thu, 16 Nov 2023 00:03:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjJg1PwafLBNq6rrSRS4oASyAL1MEj4odjiqPizFh0K54vczUt9Pyb5q4/gAug5WRmkK9r X-Received: by 2002:a17:902:9894:b0:1cc:e66:3732 with SMTP id s20-20020a170902989400b001cc0e663732mr8115812plp.19.1700121797115; Thu, 16 Nov 2023 00:03:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700121797; cv=none; d=google.com; s=arc-20160816; b=po8/A15k9dY1zcdN/YszWVg4b6Ih0p3eVzdk8GcGmKQnfcDyw7L0Oh562smsPiY946 b0A2zDTw+gLouhi0MpetibMmOsZ2YvoJkjdww0hjqGd4ZM6QsZ5+3GrgqvzYrqJgX+Uh dxuZ2mFS8rZ5AzgjmptB/RcPz6cez7d2GmoqlaKZgZruXP5RkvP4T3eRCz4NOl6nkEgi sX+W2ud3C1zfHfZCyl9VGqZm/vHBWwTYoLnxYnqe9DRYrfMmoF2dDRXzqCptcs3VKpjk /4Bxuwn25qWsMEgOR+yFTrMWRluoEnxeslFk7VWmMj0QrKFI6VY9EGvWnPXMwpjWmArW Vj3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=JSG7fZSabUg2aqNRyBqAYavoHqVU7o0YazDPmD97T1M=; fh=t2qGvYY2T8sI25xghw/yY2Ok4bjLdUJ/BVTDV1w148w=; b=xpxH5+yVXFyuKKK1NeCzPbBW6oOmuwxya5eJC8AhlXlaTBK0UG+m0JyJq4xVHq6Q8Y 6RqjmMPw99w6v9Y6sHUcyI8qTCqbRktdZfVtn8mHMdpZ1eq/puULIQ1gyH8PsLSd8B5Z QcRuelplTqwY8vEtWvbn/tFiUBhlCVKNP3PUNKgosNZO9EWB2aqVMFX7lFQ3+wuE0GVr 5fTXk/qkFVaLtOlRr9aRc2guvdu9zgqDpMIIGmmzUTwSZFK5ICStxMMVfPMQaGBFExVS nBJhGhKmQOzjyliNfqFFSWyyGGfe3/x5EWWF2YQu1W/CXyXk0A8Cf4J2ZEJsfVWq3ZvZ W/Vg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id bg12-20020a1709028e8c00b001cc2989d3e0si11463634plb.562.2023.11.16.00.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 00:03:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C002B815D7DB; Thu, 16 Nov 2023 00:03:00 -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 S234762AbjKPICx (ORCPT + 99 others); Thu, 16 Nov 2023 03:02:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229997AbjKPICw (ORCPT ); Thu, 16 Nov 2023 03:02:52 -0500 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09BF2E1; Thu, 16 Nov 2023 00:02:47 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R731e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=xueshuai@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0VwVk1Zu_1700121763; Received: from 30.240.112.215(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0VwVk1Zu_1700121763) by smtp.aliyun-inc.com; Thu, 16 Nov 2023 16:02:45 +0800 Message-ID: <7e383d7f-8df5-4d49-a45e-3dbe23b2c925@linux.alibaba.com> Date: Thu, 16 Nov 2023 16:02:38 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v10 4/5] drivers/perf: add DesignWare PCIe PMU driver Content-Language: en-US To: Ilkka Koskinen Cc: kaishen@linux.alibaba.com, helgaas@kernel.org, yangyicong@huawei.com, will@kernel.org, Jonathan.Cameron@huawei.com, baolin.wang@linux.alibaba.com, robin.murphy@arm.com, chengyou@linux.alibaba.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, rdunlap@infradead.org, mark.rutland@arm.com, zhuo.song@linux.alibaba.com, renyu.zj@linux.alibaba.com References: <20231104133216.42056-1-xueshuai@linux.alibaba.com> <20231104133216.42056-5-xueshuai@linux.alibaba.com> <32626689-c8b1-9bd-b00-5285c633bfbc@os.amperecomputing.com> From: Shuai Xue In-Reply-To: <32626689-c8b1-9bd-b00-5285c633bfbc@os.amperecomputing.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 16 Nov 2023 00:03:00 -0800 (PST) On 2023/11/16 11:50, Ilkka Koskinen wrote: > > Hi Shuai, > > I have a few comments below > > ... > >> +static void dwc_pcie_pmu_time_based_event_enable(struct dwc_pcie_pmu *pcie_pmu, >> +                      bool enable) >> +{ >> +    struct pci_dev *pdev = pcie_pmu->pdev; >> +    u16 ras_des_offset = pcie_pmu->ras_des_offset; >> + >> +    if (enable) >> +        pci_clear_and_set_dword(pdev, >> +            ras_des_offset + DWC_PCIE_TIME_BASED_ANAL_CTL, >> +            DWC_PCIE_TIME_BASED_TIMER_START, 0x1); >> +    else >> +        pci_clear_and_set_dword(pdev, >> +            ras_des_offset + DWC_PCIE_TIME_BASED_ANAL_CTL, >> +            DWC_PCIE_TIME_BASED_TIMER_START, 0x0); > > It's a matter of taste, but you could simply do: > >     pci_clear_and_set_dword(pdev, >                  ras_des_offset + DWC_PCIE_TIME_BASED_ANAL_CTL, >                  DWC_PCIE_TIME_BASED_TIMER_START, enable); > > > However, I'm fine with either way. Good suggestion, will fix it. > >> +static u64 dwc_pcie_pmu_read_lane_event_counter(struct perf_event *event) >> +{ >> +    struct dwc_pcie_pmu *pcie_pmu = to_dwc_pcie_pmu(event->pmu); >> +    struct pci_dev *pdev = pcie_pmu->pdev; >> +    u16 ras_des_offset = pcie_pmu->ras_des_offset; >> +    u32 val; >> + >> +    pci_read_config_dword(pdev, ras_des_offset + DWC_PCIE_EVENT_CNT_DATA, &val); >> + >> +    return val; >> +} > > ... > >> +static int dwc_pcie_register_dev(struct pci_dev *pdev) >> +{ >> +    struct platform_device *plat_dev; >> +    struct dwc_pcie_dev_info *dev_info; >> +    int ret; >> +    u32 bdf; >> + >> +    bdf = PCI_DEVID(pdev->bus->number, pdev->devfn); >> +    plat_dev = platform_device_register_data(NULL, "dwc_pcie_pmu", bdf, >> +                         pdev, sizeof(*pdev)); >> +    ret = PTR_ERR_OR_ZERO(plat_dev); >> +    if (ret) >> +             return ret; > > platform_device_register_data() doesn't return a null pointer and you don't really need 'ret'. You could do something like instead: > >    if (IS_ERR(plat_dev)) >           return PTR_ERR(plat_dev); > >> +    dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL); >> +    if (!dev_info) >> +        return -ENOMEM; >> + >> +    /* Cache platform device to handle pci device hotplug */ >> +    dev_info->plat_dev = plat_dev; >> +    dev_info->pdev = pdev; >> +    list_add(&dev_info->dev_node, &dwc_pcie_dev_info_head); >> + >> +    return 0; >> +} >> + >> +static int dwc_pcie_pmu_notifier(struct notifier_block *nb, >> +                     unsigned long action, void *data) >> +{ >> +    struct device *dev = data; >> +    struct pci_dev *pdev = to_pci_dev(dev); >> +    struct dwc_pcie_dev_info *dev_info; >> + >> +    switch (action) { >> +    case BUS_NOTIFY_ADD_DEVICE: >> +        if (!dwc_pcie_match_des_cap(pdev)) >> +            return NOTIFY_DONE; >> +        if (dwc_pcie_register_dev(pdev)) >> +            return NOTIFY_BAD; >> +        break; >> +    case BUS_NOTIFY_DEL_DEVICE: >> +        dev_info = dwc_pcie_find_dev_info(pdev); >> +        if (!dev_info) >> +            return NOTIFY_DONE; >> +        dwc_pcie_unregister_dev(dev_info); >> +        break; >> +    } >> + >> +    return NOTIFY_OK; >> +} >> + >> +static struct notifier_block dwc_pcie_pmu_nb = { >> +    .notifier_call = dwc_pcie_pmu_notifier, >> +}; >> + >> +static int dwc_pcie_pmu_probe(struct platform_device *plat_dev) >> +{ >> +    struct pci_dev *pdev = plat_dev->dev.platform_data; >> +    struct dwc_pcie_pmu *pcie_pmu; >> +    char *name; >> +    u32 bdf, val; >> +    u16 vsec; >> +    int ret; >> + >> +    vsec = pci_find_vsec_capability(pdev, PCI_VENDOR_ID_ALIBABA, >> +                    DWC_PCIE_VSEC_RAS_DES_ID); > > You nicely changed to use vendor list in this version but here the driver still tries to find Alibaba specific capability. Sorry, I missed here. > I guess, you could search again using the vendor list. The other option would be to make dwc_pcie_match_des_cap() to return the vendor id, pass it to dwc_pcie_register_dev(), which would add it to device's platform data with > the pointer to the pci device. The dwc_pcie_pmu_probe() is called by device which has DWC_PCIE_VSEC_RAS_DES_ID cap. So I guess I can use pdev->vendor directly here, e.g? pci_find_vsec_capability(pdev, pdev->vendor, DWC_PCIE_VSEC_RAS_DES_ID); Best Regards, Shuai