From patchwork Tue Jun 12 16:40:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 10460631 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8D36C601A0 for ; Tue, 12 Jun 2018 16:40:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7403628A5C for ; Tue, 12 Jun 2018 16:40:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 678C628A60; Tue, 12 Jun 2018 16:40:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C105628A5C for ; Tue, 12 Jun 2018 16:40:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933429AbeFLQkr (ORCPT ); Tue, 12 Jun 2018 12:40:47 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34645 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933082AbeFLQkq (ORCPT ); Tue, 12 Jun 2018 12:40:46 -0400 Received: by mail-pf0-f195.google.com with SMTP id a63-v6so12399434pfl.1 for ; Tue, 12 Jun 2018 09:40:46 -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=Dp7yYJmpZrkwt1W1QPpzPlPOTceWVoHXq9ZV9IY3trQ=; b=RuoD+Sdovt4htBXVKx4P0EVF8PGqNNmojf5nZHga9jT6lJn4QFsruxi2Iraujp+TFB ufGzcwzJY8kvzSXaVJEkaJGGjjuLg8oWlvllkX3q+haKYBBL4xsJuz6uDXsdNE5yCwAm kHvRI/hRlFF+hXGanIbRcELgDC/oLGopjIoaFS3KCJTKAQcFYfCxsGOWYtgRFJR0qDRy XKI+T3M94cNy/OonVGfmXtwrTTYgQMmblR4KLFh9u5RmazovpqX8JzDLNH/i2/K8CMEp dohh4qk94u+CVJb1/x/NfntqxwwnPnBqf+8XIkJOZM+TQ8MMl9QgBQCRCea+/irnPbpX LBhQ== 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=Dp7yYJmpZrkwt1W1QPpzPlPOTceWVoHXq9ZV9IY3trQ=; b=ObvaYtlgDOcQa/TnuQ3wX57dqDHRnaBcu1ig9PDbFpE9+F5yjwCD7BOEHPvwbv5xC7 tkBuR5AW/abhhJmh+/ezzirSuC1LcqYi8yUwlaZ7YOesPFl3ZlMfT2zHPrVXQI8WS9jk zrnHRF/xXB0GTJarPv4LJICmpqsDW2DiA3VRv3CYmT9H69lKXYyQDoiDIkBRyYUnDTV0 aAh8eIpcitAJ41spS34hx2vykP+2CsvqL7Hem2tvUPu3S585zrLZz6fW6OeQSOMpGE77 gLhrNtgLGfiCjhgslD0DjeFpwSLh11eZdZxs6fzrBUZ5PUt4SoexdIjm+JNOa1Nc5De1 YWiA== X-Gm-Message-State: APt69E2lqv0SSzeHzjagCzsN1TbkdhyZQD3T0VaaimGu/ouaHIH0alDr MiNf8J+KaA8Xo5MZ9jnXW8PjuA== X-Google-Smtp-Source: ADUXVKLmD9kIwjJIzEb4GkHN+fiInWlQCzvwAHHLnA2BSb0X8K886m9sCe9mKTmvk1lXmYxa8nGEuA== X-Received: by 2002:a63:ab45:: with SMTP id k5-v6mr962630pgp.23.1528821645580; Tue, 12 Jun 2018 09:40:45 -0700 (PDT) Received: from xeon-e3.lan (204-195-35-107.wavecable.com. [204.195.35.107]) by smtp.gmail.com with ESMTPSA id l8-v6sm1041973pfb.102.2018.06.12.09.40.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jun 2018 09:40:44 -0700 (PDT) From: Stephen Hemminger X-Google-Original-From: Stephen Hemminger To: bhelgaas@google.com, kys@microsoft.com Cc: linux-pci@vger.kernel.org, Stephen Hemminger Subject: [PATCH] PCI: hv: support reporting serial number as slot information Date: Tue, 12 Jun 2018 09:40:37 -0700 Message-Id: <20180612164037.10672-1-sthemmin@microsoft.com> X-Mailer: git-send-email 2.17.1 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The Hyper-V host API for PCI provides a unique "serial number" which can be used as the 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 a 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 may be some cases where the serial number is not unique such as when using GPU's. But the PCI slot infrastructure will handle that. This also shortens the network device names generated by systemd/udev. The new names use slot (ens2) rather than PCI address (enP2p0s2). Signed-off-by: Stephen Hemminger --- v2 - retarget for current filenames in PCI next - remove debug log message drivers/pci/controller/pci-hyperv.c | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 6cc5036ac83c..4e3575716ced 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/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 21 + /* * Message Types */ @@ -493,6 +495,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; @@ -1454,6 +1457,28 @@ 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); + hpdev->pci_slot = pci_create_slot(hbus->pci_bus, slot_nr, + name, NULL); + if (!hpdev->pci_slot) + pr_warn("pci_create slot %s failed\n", name); + } + 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 @@ -1477,6 +1502,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; @@ -1739,6 +1765,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; @@ -1855,6 +1882,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;