From patchwork Thu May 24 21:30:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 920107 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=networkplumber.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=networkplumber-org.20150623.gappssmtp.com header.i=@networkplumber-org.20150623.gappssmtp.com header.b="rlqAG8vZ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40sMxd71Mkz9ry1 for ; Fri, 25 May 2018 07:30:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966531AbeEXVao (ORCPT ); Thu, 24 May 2018 17:30:44 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:35180 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966424AbeEXVan (ORCPT ); Thu, 24 May 2018 17:30:43 -0400 Received: by mail-pl0-f66.google.com with SMTP id i5-v6so1822951plt.2 for ; Thu, 24 May 2018 14:30:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=probGWJv6t4Jxq0PUj92RrXkOerIsVu0+F13qF+Ix84=; b=rlqAG8vZDVnGrCy4SPfKGv1v37/tuc3dC5CRVKu3p4jBeh872yoo14FWu6qPU1BYxp roFzEn75gfa6yoT4gqQcPPSy9mxpDXChS5mcRtxuy0yfOEFpFGIMACHHK93cmbvd1oMk uX2kp18kSmn0X/yWWJ2YekojRr6HnJz2LnvHe7Fs2eogoORUign7yN94qr0NRCYog3tq B9yeEMkLW6LxjsuFKGP8V80SGoXuaUPc2hRTQUP68RGaigCoiRg4Hi0x0h7Z7fB50QMa dlrzo94U3ZlzNTGtMzXu3DMcoPeUYc6FbIf+1iOdRhpQMrOdoHKNebT8ALNCri5aIy3m aeOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=probGWJv6t4Jxq0PUj92RrXkOerIsVu0+F13qF+Ix84=; b=J7Z/LxlabRVzuLN+Yu2qtn6JMIbLzu9yznNbZD0AHs1Rdkw+VFDXa965IGX6OGO3at J0L88oDaJXAwNqCCVS2jsXb7Tl418ulBQG6CkRK6RHqJfWOu1o3KhEax47zcnWIU3mnP LobORNqSmY8Czw4C0k59ssT1Hm4ZLIl+uSOuIRKiSaju0YWYTmDPplUsNJy0dTf559Lo GzDBasxrUYCsDv2yb39vGJ8mbzMKBorrmo+Dx5kBUOHJYjEYhZkulgyDNYUBzsx49t6j MlL0AtbwqNVdlvNqndsotmoRmK7c42Qn8zezHTir2jKoIqYNCbCK7vwlt6ptTugTAvg0 WZog== X-Gm-Message-State: ALKqPwcqJQj5uKGXX26wo85DBPtFdzaIBZ9O1vDaEyq8tQHOu3hkBfsp QRH5WyZ+MgAH19h60vWsETxbREUl0sw= X-Google-Smtp-Source: AB8JxZp5c8eoZH4XFSVOjfTH9DO9Y0N0ax2XIJ6km4U3QuwGauTZLVnzjzr+En7dysNIHdUz6P2KAg== X-Received: by 2002:a17:902:d68b:: with SMTP id v11-v6mr4595138ply.16.1527197442896; Thu, 24 May 2018 14:30:42 -0700 (PDT) Received: from xeon-e3.lan (204-195-35-107.wavecable.com. [204.195.35.107]) by smtp.gmail.com with ESMTPSA id h75-v6sm43933304pfh.148.2018.05.24.14.30.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 May 2018 14:30:42 -0700 (PDT) From: Stephen Hemminger X-Google-Original-From: Stephen Hemminger To: lorenzo.pieralisi@arm.com, bhelgaas@google.com Cc: linux-pci@vger.kernel.org, Stephen Hemminger Subject: [RFC] PCI: hv: support reporting serial number as slot information Date: Thu, 24 May 2018 14:30:39 -0700 Message-Id: <20180524213039.27841-1-sthemmin@microsoft.com> X-Mailer: git-send-email 2.17.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The Hyper-V host API for PCI provides a unique "serial number" which can be used as basis for sysfs PCI slot table. This can be useful for cases where userspace wants to find the PCI device based on serial number. When an SR-IOV NIC is added, the host sends an attach message with serial number. The kernel doesn't use the serial number, but it is useful when doing the same thing in a userspace driver such as the DPDK. By having /sys/bus/pci/slots/N it provides a direct way to find the matching PCI device. There maybe some cases where serial number is not unique such as when using GPU's. But the PCI slot infrastructure will handle that. This has a side effect which may also be useful. The common udev network device naming policy uses the slot information (rather than PCI address). Signed-off-by: Stephen Hemminger --- drivers/pci/host/pci-hyperv.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index 50cdefe3f6d3..42656ebadd5b 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -88,6 +88,8 @@ static enum pci_protocol_version_t pci_protocol_version; #define STATUS_REVISION_MISMATCH 0xC0000059 +#define SLOT_NAME_SIZE 16 + /* * Message Types */ @@ -504,6 +506,7 @@ struct hv_pci_dev { struct list_head list_entry; refcount_t refs; enum hv_pcichild_state state; + struct pci_slot *pci_slot; struct pci_function_description desc; bool reported_missing; struct hv_pcibus_device *hbus; @@ -1443,6 +1446,29 @@ static void prepopulate_bars(struct hv_pcibus_device *hbus) spin_unlock_irqrestore(&hbus->device_list_lock, flags); } +static void hv_pci_assign_slots(struct hv_pcibus_device *hbus) +{ + struct hv_pci_dev *hpdev; + char name[SLOT_NAME_SIZE]; + unsigned long flags; + int slot_nr; + + spin_lock_irqsave(&hbus->device_list_lock, flags); + list_for_each_entry(hpdev, &hbus->children, list_entry) { + if (hpdev->pci_slot) + continue; + + slot_nr = PCI_SLOT(wslot_to_devfn(hpdev->desc.win_slot.slot)); + snprintf(name, SLOT_NAME_SIZE, "%u", hpdev->desc.ser); + pr_info("%s slot %u name '%s'\n", __func__, slot_nr, name); + hpdev->pci_slot = pci_create_slot(hbus->pci_bus, slot_nr, + name, NULL); + if (!hpdev->pci_slot) + pr_warn("pci_create slot failed\n"); + } + spin_unlock_irqrestore(&hbus->device_list_lock, flags); +} + /** * create_root_hv_pci_bus() - Expose a new root PCI bus * @hbus: Root PCI bus, as understood by this driver @@ -1466,6 +1492,7 @@ static int create_root_hv_pci_bus(struct hv_pcibus_device *hbus) pci_lock_rescan_remove(); pci_scan_child_bus(hbus->pci_bus); pci_bus_assign_resources(hbus->pci_bus); + hv_pci_assign_slots(hbus); pci_bus_add_devices(hbus->pci_bus); pci_unlock_rescan_remove(); hbus->state = hv_pcibus_installed; @@ -1759,6 +1786,7 @@ static void pci_devices_present_work(struct work_struct *work) */ pci_lock_rescan_remove(); pci_scan_child_bus(hbus->pci_bus); + hv_pci_assign_slots(hbus); pci_unlock_rescan_remove(); break; @@ -1875,6 +1903,9 @@ static void hv_eject_device_work(struct work_struct *work) list_del(&hpdev->list_entry); spin_unlock_irqrestore(&hpdev->hbus->device_list_lock, flags); + if (hpdev->pci_slot) + pci_destroy_slot(hpdev->pci_slot); + memset(&ctxt, 0, sizeof(ctxt)); ejct_pkt = (struct pci_eject_response *)&ctxt.pkt.message; ejct_pkt->message_type.type = PCI_EJECTION_COMPLETE;