Expose __rte_experimental helpers to read and write 64-bit registers in the optional PIO BAR mapped for an MCDMA port. Applications use these to reach user logic behind the PCIe function.
Co-developed-by: Cheryl Bansal <[email protected]> Signed-off-by: Cheryl Bansal <[email protected]> Signed-off-by: Subhransu S. Prusty <[email protected]> --- doc/guides/nics/mcdma.rst | 13 +++ drivers/net/altera/mcdma/meson.build | 3 + drivers/net/altera/mcdma/rte_pmd_mcdma.c | 106 +++++++++++++++++++++++ drivers/net/altera/mcdma/rte_pmd_mcdma.h | 61 +++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 drivers/net/altera/mcdma/rte_pmd_mcdma.c create mode 100644 drivers/net/altera/mcdma/rte_pmd_mcdma.h diff --git a/doc/guides/nics/mcdma.rst b/doc/guides/nics/mcdma.rst index e31fac2efe71..3bbd345d575c 100644 --- a/doc/guides/nics/mcdma.rst +++ b/doc/guides/nics/mcdma.rst @@ -104,6 +104,19 @@ The following standard ethdev features are not implemented: Traffic acceptance and any Ethernet semantics beyond descriptor DMA are defined by the FPGA application connected to the MCDMA IP. +Experimental driver API +----------------------- + +The header ``rte_pmd_mcdma.h`` provides experimental helpers to access + the PIO BAR: + +rte_pmd_mcdma_pio_read64() / rte_pmd_mcdma_pio_write64() + Read or write 64-bit registers in the mapped PIO BAR. ``pio_read64`` returns + 0 on success and stores the value via an output pointer so a valid register + read of zero is not confused with an error. + +These symbols are experimental and may change without notice. + Building and testing -------------------- diff --git a/drivers/net/altera/mcdma/meson.build b/drivers/net/altera/mcdma/meson.build index 65f442310f07..df1bbc495c73 100644 --- a/drivers/net/altera/mcdma/meson.build +++ b/drivers/net/altera/mcdma/meson.build @@ -10,4 +10,7 @@ sources += files( 'mcdma_eth.c', 'mcdma_eth_ops.c', 'mcdma_eth_rxtx.c', + 'rte_pmd_mcdma.c', ) + +headers = files('rte_pmd_mcdma.h') diff --git a/drivers/net/altera/mcdma/rte_pmd_mcdma.c b/drivers/net/altera/mcdma/rte_pmd_mcdma.c new file mode 100644 index 000000000000..49d7d97b90bc --- /dev/null +++ b/drivers/net/altera/mcdma/rte_pmd_mcdma.c @@ -0,0 +1,106 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2020-2026 Altera Corporation + */ + +#include <errno.h> +#include <stdio.h> +#include <string.h> + +#include <eal_export.h> +#include <ethdev_driver.h> +#include <rte_compat.h> + +#include "mcdma_eth.h" +#include "rte_pmd_mcdma.h" + +#define MCDMA_PMD_NAME "net_mcdma" + +static int +mcdma_pmd_port_get(uint16_t port_id, struct rte_eth_dev **eth_dev) +{ + struct rte_eth_dev *dev; + + if (eth_dev == NULL) + return -EINVAL; + + if (!rte_eth_dev_is_valid_port(port_id)) + return -EINVAL; + + dev = &rte_eth_devices[port_id]; + if (dev->state != RTE_ETH_DEV_ATTACHED) + return -ENODEV; + + if (dev->device == NULL || dev->device->driver == NULL || + strcmp(dev->device->driver->name, MCDMA_PMD_NAME) != 0) + return -ENODEV; + + *eth_dev = dev; + return 0; +} + +static int +mcdma_pio_offset_check(const struct mcdma_pci_device *priv, uint64_t offset) +{ + if (priv->pio == NULL || priv->pio_bar_len == 0) + return -ENODEV; + + if ((offset & (sizeof(uint64_t) - 1)) != 0) + return -EINVAL; + + if (priv->pio_bar_len < sizeof(uint64_t) || + offset > priv->pio_bar_len - sizeof(uint64_t)) + return -EINVAL; + + return 0; +} + +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mcdma_pio_read64, 26.11) +int +rte_pmd_mcdma_pio_read64(uint16_t port_id, uint64_t offset, uint64_t *val) +{ + struct rte_eth_dev *dev; + struct mcdma_pci_device *priv; + int ret; + + if (val == NULL) + return -EINVAL; + + ret = mcdma_pmd_port_get(port_id, &dev); + if (ret != 0) + return ret; + + priv = dev->data->dev_private; + if (priv == NULL) + return -EINVAL; + + ret = mcdma_pio_offset_check(priv, offset); + if (ret != 0) + return ret; + + *val = mcdma_pio_reg_read64(priv->pio, offset); + return 0; +} + +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mcdma_pio_write64, 26.11) +int +rte_pmd_mcdma_pio_write64(uint16_t port_id, uint64_t offset, uint64_t val) +{ + struct rte_eth_dev *dev; + struct mcdma_pci_device *priv; + int ret; + + ret = mcdma_pmd_port_get(port_id, &dev); + if (ret != 0) + return ret; + + priv = dev->data->dev_private; + if (priv == NULL) + return -EINVAL; + + ret = mcdma_pio_offset_check(priv, offset); + if (ret != 0) + return ret; + + mcdma_pio_reg_write64(priv->pio, offset, val); + return 0; +} diff --git a/drivers/net/altera/mcdma/rte_pmd_mcdma.h b/drivers/net/altera/mcdma/rte_pmd_mcdma.h new file mode 100644 index 000000000000..d76babbdf7e0 --- /dev/null +++ b/drivers/net/altera/mcdma/rte_pmd_mcdma.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2020-2026 Altera Corporation + */ + +#ifndef RTE_PMD_MCDMA_H +#define RTE_PMD_MCDMA_H + +/** + * @file rte_pmd_mcdma.h + * + * Altera MCDMA PMD specific functions. + */ + +#include <stdint.h> +#include <stdio.h> + +#include <rte_compat.h> + +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Read a 64-bit value from the mapped PIO BAR at @p offset. + * + * @param port_id + * Port identifier. + * @param offset + * Byte offset from the PIO BAR base (must be 8-byte aligned and fit a + * 64-bit access within the mapped PIO BAR). + * @param val + * On success, the 64-bit register value is stored here. Untouched on failure. + * + * @return + * 0 on success, negative errno on failure (-EINVAL, -ENODEV). + */ +__rte_experimental +int +rte_pmd_mcdma_pio_read64(uint16_t port_id, uint64_t offset, uint64_t *val); + +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Write a 64-bit value to the mapped PIO BAR at @p offset. + * + * @param port_id + * Port identifier. + * @param offset + * Byte offset from the PIO BAR base (must be 8-byte aligned and fit a + * 64-bit access within the mapped PIO BAR). + * @param val + * Value to write. + * + * @return + * 0 on success, negative errno on failure (-EINVAL, -ENODEV). + */ +__rte_experimental +int +rte_pmd_mcdma_pio_write64(uint16_t port_id, uint64_t offset, uint64_t val); + +#endif /* RTE_PMD_MCDMA_H */ -- 2.34.1

