From: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: bhelgaas@google.com, kys@microsoft.com,
linux-pci@vger.kernel.org,
Stephen Hemminger <sthemmin@microsoft.com>
Subject: Re: [PATCH] PCI: hv: support reporting serial number as slot information
Date: Wed, 4 Jul 2018 17:08:34 +0100 [thread overview]
Message-ID: <20180704160834.GB12996@red-moon> (raw)
In-Reply-To: <20180612164037.10672-1-sthemmin@microsoft.com>
On Tue, Jun 12, 2018 at 09:40:37AM -0700, Stephen Hemminger wrote:
> 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).
Hi Stephen,
I wanted to apply this patch but wanted to make sure all HV
maintainers are in agreement first since this looks like
a significant user-space ABI change.
I would also ask Bjorn's opinion on this since he has more
insights into the slot interface history.
Thanks,
Lorenzo
> Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
> ---
> 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;
> --
> 2.17.1
>
next prev parent reply other threads:[~2018-07-04 16:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-12 16:40 [PATCH] PCI: hv: support reporting serial number as slot information Stephen Hemminger
2018-07-04 16:08 ` Lorenzo Pieralisi [this message]
2018-07-10 23:11 ` Stephen Hemminger
2018-07-11 13:49 ` Bjorn Helgaas
2018-07-13 21:38 ` Stephen Hemminger
2018-07-19 16:58 ` Lorenzo Pieralisi
2018-07-19 17:36 ` Stephen Hemminger
2018-07-30 19:22 ` Stephen Hemminger
2018-07-19 17:28 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180704160834.GB12996@red-moon \
--to=lorenzo.pieralisi@arm.com \
--cc=bhelgaas@google.com \
--cc=kys@microsoft.com \
--cc=linux-pci@vger.kernel.org \
--cc=stephen@networkplumber.org \
--cc=sthemmin@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox