From patchwork Tue Apr 8 23:42:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 3951711 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9302BBFF02 for ; Tue, 8 Apr 2014 23:42:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B9060204D3 for ; Tue, 8 Apr 2014 23:42:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3C396204AF for ; Tue, 8 Apr 2014 23:42:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756799AbaDHXm0 (ORCPT ); Tue, 8 Apr 2014 19:42:26 -0400 Received: from mga02.intel.com ([134.134.136.20]:55443 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756235AbaDHXmZ (ORCPT ); Tue, 8 Apr 2014 19:42:25 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 08 Apr 2014 16:42:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,821,1389772800"; d="scan'208";a="517193005" Received: from dcgshare.lm.intel.com ([10.232.118.254]) by orsmga002.jf.intel.com with ESMTP; 08 Apr 2014 16:42:22 -0700 Received: by dcgshare.lm.intel.com (Postfix, from userid 1017) id 359A8E00F2; Tue, 8 Apr 2014 17:42:22 -0600 (MDT) From: Keith Busch To: linux-pci@vger.kernel.org, linux-nvme@lists.infradead.org, bhelgaas@google.com Cc: Keith Busch Subject: [PATCH 1/2] PCI: Device driver function reset notification Date: Tue, 8 Apr 2014 17:42:20 -0600 Message-Id: <1397000541-1085-1-git-send-email-keith.busch@intel.com> X-Mailer: git-send-email 1.7.1 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A user can issue a pci function level reset to a device using sysfs entry /sys/bus/pci/devices/.../reset. A kernel driver handling the pci device might like to know this reset is about to occur and when the reset attempt completes. This is so the driver has a chance to take appropriate device specific actions; for example, it may need to quiesce before the reset, and reinitialize the device after. Signed-off-by: Keith Busch --- drivers/pci/pci.c | 13 +++++++++++++ include/linux/pci.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index fdbc294..cb24bbe 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3320,6 +3320,15 @@ static int pci_dev_reset(struct pci_dev *dev, int probe) return rc; } + +static void pci_reset_notify(struct pci_dev *dev, bool prepare) +{ + const struct pci_error_handlers *err_handler = + dev->driver ? dev->driver->err_handler : NULL; + if (err_handler && err_handler->reset_notify) + err_handler->reset_notify(dev, prepare); +} + /** * __pci_reset_function - reset a PCI device function * @dev: PCI device to reset @@ -3408,11 +3417,13 @@ int pci_reset_function(struct pci_dev *dev) if (rc) return rc; + pci_reset_notify(dev, true); pci_dev_save_and_disable(dev); rc = pci_dev_reset(dev, 0); pci_dev_restore(dev); + pci_reset_notify(dev, false); return rc; } @@ -3432,6 +3443,7 @@ int pci_try_reset_function(struct pci_dev *dev) if (rc) return rc; + pci_reset_notify(dev, true); pci_dev_save_and_disable(dev); if (pci_dev_trylock(dev)) { @@ -3441,6 +3453,7 @@ int pci_try_reset_function(struct pci_dev *dev) rc = -EAGAIN; pci_dev_restore(dev); + pci_reset_notify(dev, false); return rc; } diff --git a/include/linux/pci.h b/include/linux/pci.h index 33aa2ca..d82dd3f 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -603,6 +603,9 @@ struct pci_error_handlers { /* PCI slot has been reset */ pci_ers_result_t (*slot_reset)(struct pci_dev *dev); + /* PCI function reset prepare or completed */ + void (*reset_notify)(struct pci_dev *dev, bool prepare); + /* Device driver may resume normal operations */ void (*resume)(struct pci_dev *dev); };