From patchwork Mon Feb 10 04:04:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yijing Wang X-Patchwork-Id: 3615211 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B51E49F2F6 for ; Mon, 10 Feb 2014 04:06:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E2F2D2016C for ; Mon, 10 Feb 2014 04:06:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1AB1220160 for ; Mon, 10 Feb 2014 04:06:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752484AbaBJEFu (ORCPT ); Sun, 9 Feb 2014 23:05:50 -0500 Received: from szxga01-in.huawei.com ([119.145.14.64]:8553 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752270AbaBJEFI (ORCPT ); Sun, 9 Feb 2014 23:05:08 -0500 Received: from 172.24.2.119 (EHLO szxeml211-edg.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BRD14644; Mon, 10 Feb 2014 12:05:06 +0800 (CST) Received: from SZXEML462-HUB.china.huawei.com (10.82.67.205) by szxeml211-edg.china.huawei.com (172.24.2.182) with Microsoft SMTP Server (TLS) id 14.3.158.1; Mon, 10 Feb 2014 12:05:06 +0800 Received: from localhost (10.177.27.212) by szxeml462-hub.china.huawei.com (10.82.67.205) with Microsoft SMTP Server id 14.3.158.1; Mon, 10 Feb 2014 12:04:53 +0800 From: Yijing Wang To: Bjorn Helgaas CC: , , Yijing Wang , Hanjun Guo , Paul Bolle , "Rafael J. Wysocki" , Oliver Neukum , Gu Zheng Subject: [PATCH part1 v5 4/7] PCI: Introduce pci_serial_number_changed() Date: Mon, 10 Feb 2014 12:04:08 +0800 Message-ID: <1392005051-54508-5-git-send-email-wangyijing@huawei.com> X-Mailer: git-send-email 1.7.11.msysgit.1 In-Reply-To: <1392005051-54508-1-git-send-email-wangyijing@huawei.com> References: <1392005051-54508-1-git-send-email-wangyijing@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.27.212] X-CFilter-Loop: Reflected 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.5 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 Sometimes OS do not know the physical device swap, for instance, some device hotplug during system suspend. Interrupt can not deliver to OS in some platform. So we can use pci serial number capability to detect this issue if device supports serial number. Signed-off-by: Yijing Wang Cc: Paul Bolle Cc: "Rafael J. Wysocki" Cc: Oliver Neukum Cc: Gu Zheng Cc: linux-pci@vger.kernel.org --- drivers/pci/pci.c | 28 ++++++++++++++++++++++++++++ include/linux/pci.h | 2 ++ 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index af06064..8f31ab3 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2198,6 +2198,34 @@ void pci_dsn_init(struct pci_dev *dev) } /** + * pci_serial_number_changed - check the device SN is changed + * @pdev: the PCI device + * + * check the device serial number is changed. + * if device does not support device serial number, + * return false. + */ +bool pci_serial_number_changed(struct pci_dev *pdev) +{ + u64 old, new; + old = pdev->sn; + + if (!pci_is_pcie(pdev)) + return false; + + new = pci_device_serial_number(pdev->bus, + pdev->devfn); + + if (old != new) { + pr_info("%s: Device Serial Number Changed!\n", + pci_name(pdev)); + return true; + } else + return false; +} +EXPORT_SYMBOL(pci_serial_number_changed); + +/** * pci_configure_ari - enable or disable ARI forwarding * @dev: the PCI device * diff --git a/include/linux/pci.h b/include/linux/pci.h index 3631859..d60c0b6 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1025,6 +1025,8 @@ void pci_unlock_rescan_remove(void); ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf); ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void *buf); +bool pci_serial_number_changed(struct pci_dev *pdev); + /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */ resource_size_t pcibios_retrieve_fw_addr(struct pci_dev *dev, int idx); void pci_bus_assign_resources(const struct pci_bus *bus);