Skip to contentSkip to conversation

Support Linux format PCI addresses on BSD

PATCH Superseded Bruce Richardson 1 participant 8 messages Nov 4 – Nov 10 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover Support Linux format PCI addresses on BSD

DPDK EAL parameters for specifying PCI devices use the linux format, even when on FreeBSD, and Linux format is the standard throughout our docs, so make some updates to allow BSD tools to also support that format for consistency.

Specifically:
* Have the PCI address output from dpdk-devbind script use Linux format on both Linux and BSD
* Allow the FreeBSD kernel module, nic_uio, accept parameters in either BSD or Linux format.

After these changes, the Linux format ([DDDD:]BB:DD.F, all hex), can be used across the board in BSD, while still allowing BSD format ([pciD]:B:D:F, all decimal), for compatibility as before.

Bruce Richardson (3):
usertools/dpdk-devbind: align BSD output format with Linux kernel/nic_uio: support Linux format PCI addresses app/test: add unit tests for nic_uio BDF parsing fns

 app/test/meson.build                  |   1 +
 app/test/test_kmod_pci_bdf.c          | 142 ++++++++++++++++++++++++++
 doc/guides/freebsd_gsg/build_dpdk.rst |   8 ++
 doc/guides/tools/devbind.rst          |   4 +
 kernel/freebsd/nic_uio/meson.build    |   2 +-
 kernel/freebsd/nic_uio/nic_uio.c      |  93 +++++++----------
 kernel/freebsd/nic_uio/pci_bdf.h      | 129 +++++++++++++++++++++++
 usertools/dpdk-devbind.py             |   5 +-
 8 files changed, 323 insertions(+), 61 deletions(-)
 create mode 100644 app/test/test_kmod_pci_bdf.c
 create mode 100644 kernel/freebsd/nic_uio/pci_bdf.h

--
2.55.0

#1 lore raw

PATCH 1/3 usertools/dpdk-devbind: align BSD output format with Linux

Change the PCI address output format used by dpdk-devbind.py to match that used on linux, where we have the bus values in hex rather than in decimal, "pci0" is replaced with "0000", and the final separator is a "." rather than a ":". As well as having consistent output across platforms, this also aligns the output format with the BDF format accepted by EAL -a/-b flags.

---
 doc/guides/tools/devbind.rst | 4 ++++
 usertools/dpdk-devbind.py    | 5 +++--
 2 files changed, 7 insertions(+), 2 deletions(-)
doc/guides/tools/devbind.rst +4 -0
index 90b289de1e..f36e8c4de7 100644
@@ -8,6 +8,10 @@ The ``dpdk-devbind`` tool is a Data Plane Development Kit (DPDK) utility
 that helps binding and unbinding devices from specific drivers.
 As well as checking their status in that regard.
 
+PCI addresses use the hexadecimal ``dddd:bb:dd.f`` format on both Linux and FreeBSD.
+For example, FreeBSD's ``pci0:152:0:1`` is displayed as ``0000:98:00.1``,
+and this address can be used directly in EAL device arguments.
+
 
 Running the Application
 -----------------------
usertools/dpdk-devbind.py +3 -2
index 00d7188618..c62b3ad6d8 100755
@@ -286,8 +286,9 @@ def init_devices_cache_bsd():
             # Parse slot/address from first part
             name_addr, fields = line.split(maxsplit=1)
             devname, addr = name_addr.split('@')
-            # Remove trailing colon from address
-            addr = addr.rstrip(':')
+            # Convert the decimal pciconf address to hexadecimal DPDK format.
+            domain, bus, slot, function = map(int, addr[3:].rstrip(':').split(':'))
+            addr = f"{domain:04x}:{bus:02x}:{slot:02x}.{function:x}"
 
             current_dev = {}
             current_dev["Slot"] = addr
Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/3 kernel/nic_uio: support Linux format PCI addresses

In reply to Bruce Richardson

For consistency with linux and with DPDK EAL -a/-b parameters which take PCI devices in Linux BDF format, allow nic_uio to also accept the device specifiers in that format. In the process, also support taking the domain specifier for both linux-format and bsd-format cases.

---
 doc/guides/freebsd_gsg/build_dpdk.rst |   8 ++
 kernel/freebsd/nic_uio/nic_uio.c      | 185 ++++++++++++++++++--------
 2 files changed, 141 insertions(+), 52 deletions(-)
doc/guides/freebsd_gsg/build_dpdk.rst +8 -0
index 9dafa64e84..20d4a63246 100644
@@ -228,12 +228,20 @@ kernel environment variable prior to loading ``nic_uio``, as follows::
 
 Where a comma separated list of selectors is set, the list must not contain any
 whitespace.
+Selectors can use colon-separated decimal FreeBSD addresses (``b:d:f`` or ``pciD:b:d:f``)
+or fixed-width hexadecimal Linux/DPDK addresses with final "." separator (``bb:dd.f`` or ``dddd:bb:dd.f``).
+An omitted domain is zero.
+Invalid selectors cause module loading to fail before any devices are detached.
 
 For example to re-bind ``ix2@pci0:2:0:0`` and ``ix3@pci0:2:0:1`` to the ``nic_uio`` module
 upon loading, use the following command::
 
     kenv hw.nic_uio.bdfs="2:0:0,2:0:1"
 
+The equivalent DPDK addresses can also be used::
+
+    kenv hw.nic_uio.bdfs="02:00.0,02:00.1"
+
 The variable can also be specified during boot by placing the following into
 ``/boot/loader.conf``, before the previously-described ``nic_uio_load`` line - as
 shown:
kernel/freebsd/nic_uio/nic_uio.c +133 -52

246 lines not on this page · raw message

Signature · 1 line
2.55.0
#3 lore raw

PATCH 3/3 app/test: add unit tests for nic_uio BDF parsing fns

In reply to Bruce Richardson

Move the BDF parsing functions from nic_uio into a separate header which allows us to unit test them as independent functions, verifying that both BSD and Linux format PCI addresses are supported.

---
 app/test/meson.build               |   1 +
 app/test/test_kmod_pci_bdf.c       | 142 +++++++++++++++++++++++++++++
 kernel/freebsd/nic_uio/meson.build |   2 +-
 kernel/freebsd/nic_uio/nic_uio.c   | 112 +----------------------
 kernel/freebsd/nic_uio/pci_bdf.h   | 129 ++++++++++++++++++++++++++
 5 files changed, 277 insertions(+), 109 deletions(-)
 create mode 100644 app/test/test_kmod_pci_bdf.c
 create mode 100644 kernel/freebsd/nic_uio/pci_bdf.h
app/test/meson.build +1 -0
index 51abeeb732..a5d4716650 100644
@@ -104,6 +104,7 @@ source_file_deps = {
     'test_ipsec.c': ['bus_vdev', 'net', 'cryptodev', 'ipsec', 'security'],
     'test_ipsec_perf.c': ['net', 'ipsec'],
     'test_ipsec_sad.c': ['ipsec'],
+    'test_kmod_pci_bdf.c': [],
     'test_kvargs.c': ['kvargs'],
     'test_latencystats.c': ['ethdev', 'latencystats', 'metrics'] + sample_packet_forward_deps,
     'test_lcore_var.c': [],
app/test/test_kmod_pci_bdf.c new file +142 -0

142 lines not on this page · raw message

kernel/freebsd/nic_uio/meson.build +1 -1
index 4bdaf96944..f10a8a7913 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
-sources = files('nic_uio.c')
+sources = files('nic_uio.c', 'pci_bdf.h')
kernel/freebsd/nic_uio/nic_uio.c +4 -108

142 lines not on this page · raw message

kernel/freebsd/nic_uio/pci_bdf.h new file +129 -0

129 lines not on this page · raw message

Signature · 1 line
2.55.0
#4 lore raw

v2 cover Support Linux format PCI addresses on BSD

In reply to Bruce Richardson

DPDK EAL parameters for specifying PCI devices use the linux format, even when on FreeBSD, and Linux format is the standard throughout our docs, so make some updates to allow BSD tools to also support that format for consistency.

Specifically:
* Have the PCI address output from dpdk-devbind script use Linux format on both Linux and BSD
* Allow the FreeBSD kernel module, nic_uio, accept parameters in either BSD or Linux format.

After these changes, the Linux format ([DDDD:]BB:DD.F, all hex), can be used across the board in BSD, while still allowing BSD format ([pciD]:B:D:F, all decimal), for compatibility as before.

V2:
* Reworked following AI review of V1.
- cleaned up patch 2 with typecasts to calls to isxdigit() etc.
- kept compatible handling of invalid BDFs by skipping them
- supported trailing commas on BDFs

Bruce Richardson (3):
usertools/dpdk-devbind: align BSD output format with Linux kernel/nic_uio: support Linux format PCI addresses app/test: add unit tests for nic_uio BDF parsing fns

 app/test/meson.build                  |   1 +
 app/test/test_kmod_pci_bdf.c          | 187 ++++++++++++++++++++++++++
 doc/guides/freebsd_gsg/build_dpdk.rst |   9 ++
 doc/guides/tools/devbind.rst          |   4 +
 kernel/freebsd/nic_uio/meson.build    |   2 +-
 kernel/freebsd/nic_uio/nic_uio.c      |  85 +++++-------
 kernel/freebsd/nic_uio/pci_bdf.h      | 157 +++++++++++++++++++++
 usertools/dpdk-devbind.py             |   5 +-
 8 files changed, 397 insertions(+), 53 deletions(-)
 create mode 100644 app/test/test_kmod_pci_bdf.c
 create mode 100644 kernel/freebsd/nic_uio/pci_bdf.h

--
2.55.0

#5 lore raw

PATCH v2 1/3 usertools/dpdk-devbind: align BSD output format with Linux

Change the PCI address output format used by dpdk-devbind.py to match that used on linux, where we have the bus values in hex rather than in decimal, "pci0" is replaced with "0000", and the final separator is a "." rather than a ":". As well as having consistent output across platforms, this also aligns the output format with the BDF format accepted by EAL -a/-b flags.

---
 doc/guides/tools/devbind.rst | 4 ++++
 usertools/dpdk-devbind.py    | 5 +++--
 2 files changed, 7 insertions(+), 2 deletions(-)
doc/guides/tools/devbind.rst +4 -0
index 90b289de1e..f36e8c4de7 100644
@@ -8,6 +8,10 @@ The ``dpdk-devbind`` tool is a Data Plane Development Kit (DPDK) utility
 that helps binding and unbinding devices from specific drivers.
 As well as checking their status in that regard.
 
+PCI addresses use the hexadecimal ``dddd:bb:dd.f`` format on both Linux and FreeBSD.
+For example, FreeBSD's ``pci0:152:0:1`` is displayed as ``0000:98:00.1``,
+and this address can be used directly in EAL device arguments.
+
 
 Running the Application
 -----------------------
usertools/dpdk-devbind.py +3 -2
index e70bdc23b4..1625fae9e9 100755
@@ -287,8 +287,9 @@ def init_devices_cache_bsd():
             # Parse slot/address from first part
             name_addr, fields = line.split(maxsplit=1)
             devname, addr = name_addr.split('@')
-            # Remove trailing colon from address
-            addr = addr.rstrip(':')
+            # Convert the decimal pciconf address to hexadecimal DPDK format.
+            domain, bus, slot, function = map(int, addr[3:].rstrip(':').split(':'))
+            addr = f"{domain:04x}:{bus:02x}:{slot:02x}.{function:x}"
 
             current_dev = {}
             current_dev["Slot"] = addr
Signature · 1 line
2.55.0
#6 lore raw

PATCH v2 2/3 kernel/nic_uio: support Linux format PCI addresses

In reply to Bruce Richardson

For consistency with linux and with DPDK EAL -a/-b parameters which take PCI devices in Linux BDF format, allow nic_uio to also accept the device specifiers in that format. In the process, also support taking the domain specifier for both linux-format and bsd-format cases.

---
 doc/guides/freebsd_gsg/build_dpdk.rst |   9 ++
 kernel/freebsd/nic_uio/nic_uio.c      | 175 +++++++++++++++++++-------
 2 files changed, 138 insertions(+), 46 deletions(-)
doc/guides/freebsd_gsg/build_dpdk.rst +9 -0
index 9dafa64e84..9a918202f0 100644
@@ -228,12 +228,21 @@ kernel environment variable prior to loading ``nic_uio``, as follows::
 
 Where a comma separated list of selectors is set, the list must not contain any
 whitespace.
+Selectors can use colon-separated decimal FreeBSD addresses (``b:d:f`` or ``pciD:b:d:f``)
+or fixed-width hexadecimal Linux/DPDK addresses with final "." separator (``bb:dd.f`` or ``dddd:bb:dd.f``).
+An omitted domain is zero.
+Invalid selectors are reported and ignored; valid selectors in the same list are still applied.
+Trailing commas are ignored.
 
 For example to re-bind ``ix2@pci0:2:0:0`` and ``ix3@pci0:2:0:1`` to the ``nic_uio`` module
 upon loading, use the following command::
 
     kenv hw.nic_uio.bdfs="2:0:0,2:0:1"
 
+The equivalent DPDK addresses can also be used::
+
+    kenv hw.nic_uio.bdfs="02:00.0,02:00.1"
+
 The variable can also be specified during boot by placing the following into
 ``/boot/loader.conf``, before the previously-described ``nic_uio_load`` line - as
 shown:
kernel/freebsd/nic_uio/nic_uio.c +129 -46

225 lines not on this page · raw message

Signature · 1 line
2.55.0
#7 lore raw

PATCH v2 3/3 app/test: add unit tests for nic_uio BDF parsing fns

In reply to Bruce Richardson

Move the BDF parsing functions from nic_uio into a separate header which allows us to unit test them as independent functions, verifying that both BSD and Linux format PCI addresses are supported.

---
 app/test/meson.build               |   1 +
 app/test/test_kmod_pci_bdf.c       | 187 +++++++++++++++++++++++++++++
 kernel/freebsd/nic_uio/meson.build |   2 +-
 kernel/freebsd/nic_uio/nic_uio.c   | 122 ++-----------------
 kernel/freebsd/nic_uio/pci_bdf.h   | 157 ++++++++++++++++++++++++
 5 files changed, 358 insertions(+), 111 deletions(-)
 create mode 100644 app/test/test_kmod_pci_bdf.c
 create mode 100644 kernel/freebsd/nic_uio/pci_bdf.h
app/test/meson.build +1 -0
index 2f1cd817cd..96ff4292a5 100644
@@ -110,6 +110,7 @@ source_file_deps = {
     'test_ipsec.c': ['bus_vdev', 'net', 'cryptodev', 'ipsec', 'security'],
     'test_ipsec_perf.c': ['net', 'ipsec'],
     'test_ipsec_sad.c': ['ipsec'],
+    'test_kmod_pci_bdf.c': [],
     'test_kvargs.c': ['kvargs'],
     'test_latencystats.c': ['ethdev', 'latencystats', 'metrics'] + sample_packet_forward_deps,
     'test_lcore_var.c': [],
app/test/test_kmod_pci_bdf.c new file +187 -0

187 lines not on this page · raw message

kernel/freebsd/nic_uio/meson.build +1 -1
index 4bdaf96944..f10a8a7913 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
-sources = files('nic_uio.c')
+sources = files('nic_uio.c', 'pci_bdf.h')
kernel/freebsd/nic_uio/nic_uio.c +12 -110

163 lines not on this page · raw message

kernel/freebsd/nic_uio/pci_bdf.h new file +157 -0

157 lines not on this page · raw message

Signature · 1 line
2.55.0