@@ -26,3 +26,14 @@ Description:
streams can be returned to the available secure streams pool by
invoking the tsm/disconnect flow. The link points to the
endpoint PCI device at domain:DDDDD bus:BB device:DD function:F.
+
+What: pciDDDDD:BB/available_secure_streams
+Date: December, 2024
+Contact: linux-pci@vger.kernel.org
+Description:
+ (RO) When a host-bridge has root ports that support PCIe IDE
+ (link encryption and integrity protection) there may be a
+ limited number of streams that can be used for establishing new
+ secure links. This attribute decrements upon secure link setup,
+ and increments upon secure link teardown. The in-use stream
+ count is determined by counting stream symlinks.
@@ -75,8 +75,54 @@ void pci_ide_init(struct pci_dev *pdev)
pdev->nr_ide_mem = nr_ide_mem;
}
+static ssize_t available_secure_streams_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct pci_host_bridge *hb = to_pci_host_bridge(dev);
+ int avail;
+
+ if (hb->nr_ide_streams < 0)
+ return -ENXIO;
+
+ avail = hb->nr_ide_streams -
+ bitmap_weight(hb->ide_stream_ids, PCI_IDE_SEL_CTL_ID_MAX + 1);
+ return sysfs_emit(buf, "%d\n", avail);
+}
+static DEVICE_ATTR_RO(available_secure_streams);
+
+static struct attribute *pci_ide_attrs[] = {
+ &dev_attr_available_secure_streams.attr,
+ NULL,
+};
+
+static umode_t pci_ide_attr_visible(struct kobject *kobj, struct attribute *a, int n)
+{
+ struct device *dev = kobj_to_dev(kobj);
+ struct pci_host_bridge *hb = to_pci_host_bridge(dev);
+
+ if (a == &dev_attr_available_secure_streams.attr)
+ if (hb->nr_ide_streams < 0)
+ return 0;
+
+ return a->mode;
+}
+
+struct attribute_group pci_ide_attr_group = {
+ .attrs = pci_ide_attrs,
+ .is_visible = pci_ide_attr_visible,
+};
+
+void pci_set_nr_ide_streams(struct pci_host_bridge *hb, int nr)
+{
+ hb->nr_ide_streams = nr;
+ sysfs_update_group(&hb->dev.kobj, &pci_ide_attr_group);
+}
+EXPORT_SYMBOL_NS_GPL(pci_set_nr_ide_streams, PCI_IDE);
+
void pci_init_host_bridge_ide(struct pci_host_bridge *hb)
{
+ hb->nr_ide_streams = -1;
hb->ide_stream_res =
DEFINE_RES_MEM_NAMED(0, 0, "IDE Address Association");
}
@@ -466,11 +466,14 @@ static inline void pci_npem_remove(struct pci_dev *dev) { }
#ifdef CONFIG_PCI_IDE
void pci_ide_init(struct pci_dev *dev);
void pci_init_host_bridge_ide(struct pci_host_bridge *bridge);
+extern struct attribute_group pci_ide_attr_group;
+#define PCI_IDE_ATTR_GROUP (&pci_ide_attr_group)
#else
static inline void pci_ide_init(struct pci_dev *dev) { }
static inline void pci_init_host_bridge_ide(struct pci_host_bridge *bridge)
{
}
+#define PCI_IDE_ATTR_GROUP NULL
#endif
#ifdef CONFIG_PCI_TSM
@@ -589,6 +589,16 @@ static void pci_release_host_bridge_dev(struct device *dev)
kfree(bridge);
}
+static const struct attribute_group *pci_host_bridge_groups[] = {
+ PCI_IDE_ATTR_GROUP,
+ NULL,
+};
+
+static const struct device_type pci_host_bridge_type = {
+ .groups = pci_host_bridge_groups,
+ .release = pci_release_host_bridge_dev,
+};
+
static void pci_init_host_bridge(struct pci_host_bridge *bridge)
{
INIT_LIST_HEAD(&bridge->windows);
@@ -622,7 +632,6 @@ struct pci_host_bridge *pci_alloc_host_bridge(size_t priv)
return NULL;
pci_init_host_bridge(bridge);
- bridge->dev.release = pci_release_host_bridge_dev;
return bridge;
}
@@ -604,6 +604,7 @@ struct pci_host_bridge {
#ifdef CONFIG_PCI_IDE /* track IDE stream id allocation */
DECLARE_BITMAP(ide_stream_ids, PCI_IDE_SEL_CTL_ID_MAX + 1);
struct resource ide_stream_res; /* track ide stream address association */
+ int nr_ide_streams;
#endif
u8 (*swizzle_irq)(struct pci_dev *, u8 *); /* Platform IRQ swizzler */
int (*map_irq)(const struct pci_dev *, u8, u8);
@@ -654,6 +655,14 @@ void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
void (*release_fn)(struct pci_host_bridge *),
void *release_data);
+#ifdef CONFIG_PCI_IDE
+void pci_set_nr_ide_streams(struct pci_host_bridge *hb, int nr);
+#else
+static inline void pci_set_nr_ide_streams(struct pci_host_bridge *hb, int nr)
+{
+}
+#endif
+
int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge);
#define PCI_REGION_FLAG_MASK 0x0fU /* These bits of resource flags tell us the PCI region flags */
The limited number of link-encryption (IDE) streams that a given set of host-bridges supports is a platform specific detail. Provide pci_set_nr_ide_streams() as a generic facility for either platform TSM drivers, or in the future PCI core native IDE, to report the number available streams. After invoking pci_set_nr_ide_streams() an "available_secure_streams" attribute appears in PCI Host Bridge sysfs to convey how many streams are available for IDE establishment. Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Samuel Ortiz <sameo@rivosinc.com> Cc: Alexey Kardashevskiy <aik@amd.com> Cc: Xu Yilun <yilun.xu@linux.intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- .../ABI/testing/sysfs-devices-pci-host-bridge | 11 +++++ drivers/pci/ide.c | 46 ++++++++++++++++++++ drivers/pci/pci.h | 3 + drivers/pci/probe.c | 11 ++++- include/linux/pci.h | 9 ++++ 5 files changed, 79 insertions(+), 1 deletion(-)