Skip to contentSkip to conversation

PCI: endpoint: pci-epf-test: Allow overriding default BAR sizes

PATCH Superseded Niklas Cassel 2 participants 3 messages Jan 29 – Jan 30

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 PCI: endpoint: pci-epf-test: Allow overriding default BAR sizes

Add bar{0,1,2,3,4,5}_size attributes in configfs, so that the user is not restricted to run pci-epf-test with the hardcoded BAR size values defined in pci-epf-test.c.

This code is shamelessly more or less copy pasted from pci-epf-vntb.c

---
Changes since V3:
-Use sysfs_emit() (Damien)
-Reduce indendation level of macros by one tab (Damien)

 Documentation/PCI/endpoint/pci-test-howto.rst |  19 ++++
 drivers/pci/endpoint/functions/pci-epf-test.c | 100 +++++++++++++++++-
 2 files changed, 117 insertions(+), 2 deletions(-)
Documentation/PCI/endpoint/pci-test-howto.rst +19 -0
index dd66858cde46..cf38daa512ea 100644
@@ -84,6 +84,25 @@ device, the following commands can be used::
 	# echo 32 > functions/pci_epf_test/func1/msi_interrupts
 	# echo 2048 > functions/pci_epf_test/func1/msix_interrupts
 
+By default, pci-epf-test uses the following BAR sizes::
+
+	# grep . functions/pci_epf_test/func1/pci_epf_test.0/bar?_size
+	  functions/pci_epf_test/func1/pci_epf_test.0/bar0_size:131072
+	  functions/pci_epf_test/func1/pci_epf_test.0/bar1_size:131072
+	  functions/pci_epf_test/func1/pci_epf_test.0/bar2_size:131072
+	  functions/pci_epf_test/func1/pci_epf_test.0/bar3_size:131072
+	  functions/pci_epf_test/func1/pci_epf_test.0/bar4_size:131072
+	  functions/pci_epf_test/func1/pci_epf_test.0/bar5_size:1048576
+
+The user can override a default value using e.g.::
+	# echo 1048576 > functions/pci_epf_test/func1/pci_epf_test.0/bar1_size
+
+Overriding the default BAR sizes can only be done before binding the
+pci-epf-test device to a PCI endpoint controller driver.
+
+Note: Some endpoint controllers might have fixed size BARs, or reserved BARs,
+for such controllers, the corresponding BAR size in configfs will be ignored.
+
 
 Binding pci-epf-test Device to EP Controller
 --------------------------------------------
drivers/pci/endpoint/functions/pci-epf-test.c +98 -2

148 lines not on this page · raw message

base-commit: 0ebf8e7943e01b2c38c199228f51adbb89c02425

Signature · 1 line
2.52.0
#1 lore raw
Quoted 4 lines · Niklas Cassel
drivers/pci/endpoint/functions/pci-epf-test.c +4 -0
+#define PCI_EPF_TEST_BAR_SIZE_W(_name, _id)				\
+static ssize_t pci_epf_test_##_name##_store(struct config_item *item,	\
+					    const char *page,		\
+					    size_t len)			\

drivers/pci/endpoint/functions/pci-epf-test.c static void pci_epf_test_unbind(struct pci_epf *epf) · line 1342

Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-test.c +10 -0
+{									\
+	struct config_group *group = to_config_group(item);		\
+	struct pci_epf_test *epf_test =					\
+		container_of(group, struct pci_epf_test, group);	\
+	int val;							\
+	int ret;							\
+									\
+	/*								\
+	 * BAR sizes can only be modified before binding to an EPC,	\
+	 * pci_epf_test_alloc_space() is called in .bind().		\

Argh...

This comment was supposed to be:
... EPC,
as pci_epf_test_alloc_space() is called in .bind().

(I forgot to readd the word "as" when rewrapping the comment...)

Mani, if no other comments, perhaps you could fixup while applying?

(Sorry for the trouble...)

Kind regards,
Niklas

Quoted 15 lines
drivers/pci/endpoint/functions/pci-epf-test.c +15 -0
+	 */								\
+	if (epf_test->epf->epc)						\
+		return -EINVAL;						\
+									\
+	ret = kstrtouint(page, 0, &val);				\
+	if (ret)							\
+		return ret;						\
+									\
+	if (!is_power_of_2(val))					\
+		return -EINVAL;						\
+									\
+	epf_test->bar_size[_id] = val;					\
+									\
+	return len;							\
+}
Reviewed-by on v4 1/1
#2 lore raw
In reply to Niklas Cassel
Quoted 9 lines · Niklas Cassel

Add bar{0,1,2,3,4,5}_size attributes in configfs, so that the user is not restricted to run pci-epf-test with the hardcoded BAR size values defined in pci-epf-test.c.

This code is shamelessly more or less copy pasted from pci-epf-vntb.c

Looks OK to me.

One nit below.

drivers/pci/endpoint/functions/pci-epf-test.c static void pci_epf_test_unbind(struct pci_epf *epf) · line 1338

Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-test.c +10 -0
+#define PCI_EPF_TEST_BAR_SIZE_W(_name, _id)				\
+static ssize_t pci_epf_test_##_name##_store(struct config_item *item,	\
+					    const char *page,		\
+					    size_t len)			\
+{									\
+	struct config_group *group = to_config_group(item);		\
+	struct pci_epf_test *epf_test =					\
+		container_of(group, struct pci_epf_test, group);	\
+	int val;							\
+	int ret;							\

You can use one line to declare both variables.

Quoted 19 lines
drivers/pci/endpoint/functions/pci-epf-test.c +19 -0
+									\
+	/*								\
+	 * BAR sizes can only be modified before binding to an EPC,	\
+	 * pci_epf_test_alloc_space() is called in .bind().		\
+	 */								\
+	if (epf_test->epf->epc)						\
+		return -EINVAL;						\
+									\
+	ret = kstrtouint(page, 0, &val);				\
+	if (ret)							\
+		return ret;						\
+									\
+	if (!is_power_of_2(val))					\
+		return -EINVAL;						\
+									\
+	epf_test->bar_size[_id] = val;					\
+									\
+	return len;							\
+}
Signature · 2 lines
Damien Le Moal
Western Digital Research