Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5450224pxv; Wed, 28 Jul 2021 11:01:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0UwXLXO+12FWkrtLsahQ8UIGGaTOwXfmuKrgauImqGelvXSCu9n/jlPWK+fdpFPZZylen X-Received: by 2002:aa7:d543:: with SMTP id u3mr1258003edr.37.1627495271978; Wed, 28 Jul 2021 11:01:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627495271; cv=none; d=google.com; s=arc-20160816; b=u2zsnhDNe/dOjy30pRQbbIJD/fSzRLfn48iT0gnm6M3IP0Vy5ZWhui332tf3wwMc5U 0YUZPlehL2nwDLzFsNvbI7LAZiscJCxHLoK4asDjUyAXcIpsKsX9IJiShEdnL6wuX3+p axdUB9wpJNTvcTSamKRxKQDYrpk4GrCNvb8zoGjYkxLzE3w4/sD/W0r4JO8irdDHSMwa BbpU+CbgWGP/ahvlUj4ymHb9FaE/Zn9WCEtt68RQp5dYsGNRtzv50HhKcLmr6LGsfbWi iSEwAXxZX/+0tYmL9MJMAW3ki3dqot3t+fDPe/KH+VMY81GG4usBInEnV8Sj8n8tp6Ad L9UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=+Wj6KVlyJC/h/2/YVFr/gtLEYi4PLJs5U0droaFnLNA=; b=GniPZlj1jdDTXthONM7atZ55OL1Aq+n5ReDSyCC8MyR1NkaH66s6j8Pt+sMJ0K9Ou5 yatAsOGm2iWjeFHoRUTx9IjvyYuBCfHLfqIxCQDKQhuwjWzf5XLBVjtQxt3jkie/5lQh igTE+8B0m1fBngs7sLOJTgAQ81SMPvCJESC0XsVS+zBODdq8BHZN7BpA45p3qAHuHmFO pG6m2SM68JIMj9hiCiuCTcpKgRwEHqzCsc9Jnz//5aGNlMmnVRUK/7gXFlF+xm0g/fEX 2ZS4s643g6NWpyKSmaXe2yMUqwDlVvzFOAbr3nH/gBEm5/agWSwLhUrX+v70LInSp4Dd SCzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="F/q9vUaV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x8si404794eju.237.2021.07.28.11.00.48; Wed, 28 Jul 2021 11:01:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="F/q9vUaV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230315AbhG1R7Q (ORCPT + 99 others); Wed, 28 Jul 2021 13:59:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:41094 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbhG1R7P (ORCPT ); Wed, 28 Jul 2021 13:59:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D22B560E09; Wed, 28 Jul 2021 17:59:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627495153; bh=KmSuc9Pd93lOTIGMQxTWSAYFqcwC3Y4fLLqNgjxx34g=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=F/q9vUaVHZThHQrQL+D8P6qefjBuVmrFR2sHv2QsbkeubJWgta10TAjdUKbnoBCKA GH0XrsJ7eSAfgchWQXudLYNHROjBLP2wh5VyKY7HfOT03xYYRwikI14M/KKadNmtDM 1TAOzoXxYIQpFSujyrdR4EC+jpZFOUEEzNzwum0/hNKQZR1hLaJ6tAefyqTuYzvhhl MLmg0WiRzwOtWFciEJ9uSdeyNbwaR/INIs/jAapoDEWb1f4TMMFhXczBrGr6VP2Uh+ eP+YnvTUE3Jg7dDWq6MSlA3VF71McuWo2cWkua5Gac98vH0e50TPI6MbmsGmkfl17E SVZqJwSYj/n7g== Date: Wed, 28 Jul 2021 12:59:11 -0500 From: Bjorn Helgaas To: Amey Narkhede Cc: alex.williamson@redhat.com, Raphael Norwitz , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kw@linux.com, Shanker Donthineni , Sinan Kaya , Len Brown , "Rafael J. Wysocki" Subject: Re: [PATCH v10 2/8] PCI: Add new array for keeping track of ordering of reset methods Message-ID: <20210728175911.GA835695@bjorn-Precision-5520> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210728174519.has5xvy6rksbukup@archlinux> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 28, 2021 at 11:15:19PM +0530, Amey Narkhede wrote: > On 21/07/27 05:59PM, Bjorn Helgaas wrote: > > On Fri, Jul 09, 2021 at 06:08:07PM +0530, Amey Narkhede wrote: > > > Introduce a new array reset_methods in struct pci_dev to keep track of > > > reset mechanisms supported by the device and their ordering. > > > > > > Also refactor probing and reset functions to take advantage of calling > > > convention of reset functions. > > > > > > Co-developed-by: Alex Williamson > > > Signed-off-by: Alex Williamson > > > Signed-off-by: Amey Narkhede > > > --- > > > drivers/pci/pci.c | 92 ++++++++++++++++++++++++++------------------- > > > drivers/pci/pci.h | 9 ++++- > > > drivers/pci/probe.c | 5 +-- > > > include/linux/pci.h | 7 ++++ > > > 4 files changed, 70 insertions(+), 43 deletions(-) > > > > > > [...] > > > + BUILD_BUG_ON(ARRAY_SIZE(pci_reset_fn_methods) != PCI_NUM_RESET_METHODS); > > > > > > might_sleep(); > > > > > > - rc = pci_dev_specific_reset(dev, 1); > > > - if (rc != -ENOTTY) > > > - return rc; > > > - rc = pcie_reset_flr(dev, 1); > > > - if (rc != -ENOTTY) > > > - return rc; > > > - rc = pci_af_flr(dev, 1); > > > - if (rc != -ENOTTY) > > > - return rc; > > > - rc = pci_pm_reset(dev, 1); > > > - if (rc != -ENOTTY) > > > - return rc; > > > + for (i = 1; i < PCI_NUM_RESET_METHODS; i++) { > > > + rc = pci_reset_fn_methods[i].reset_fn(dev, 1); > > > + if (!rc) > > > + reset_methods[n++] = i; > > > > Why do we need this local reset_methods[] array? Can we just fill > > in dev->reset_methods[] directly and skip the memcpy() below? > > > This is for avoiding caching of previously supported reset methods. > Is it okay if I use memset(dev->reset_methods, 0, > sizeof(dev->reset_methods)) instead to clear the values in > dev->reset_methods? I don't think there's ever a case where you look at a dev->reset_methods[] element past a zero value, so we shouldn't care about any previously-supported methods left in the array. If we *do* look at something past a zero value, why do we do that? It sounds like it would be a bug. > > > + else if (rc != -ENOTTY) > > > + break; > > > + } > > > > > > - return pci_reset_bus_function(dev, 1); > > > + memcpy(dev->reset_methods, reset_methods, sizeof(reset_methods)); > > > } > > > > > > /** > [...]