Skip to content

Commit 3cf01ec

Browse files
committed
drivers: ethernet: Add platform driver for MMIO mapping reuse
The Ethernet device model consists of multiple subsystem components, such as MDIO, PHY, MAC and PTP_CLOCK. These components are are mapped into a single PCIe BAR location with same base address. This platform driver retrieves the MMIO mapping details and provides a framework to share them with all the child subsystem components. This approach ensures efficient re-use of MMIO mappings across related devices. Example device tree structure for first ethernet instance: parent0: parent0 { compatible = "intel,eth-plat"; vendor-id = <0x8086>; device-id = <0xXXXX>; igc0: igc0 { compatible = "intel,igc-mac"; interrupt-parent = <&intc>; /* * MAC specific properties. */ status = "okay"; }; mdio0: mdio0 { compatible = "intel,igc-mdio"; #address-cells = <1>; #size-cells = <0>; ethphy0: igc-phy@0 { compatible = "intel,igc-phy"; /* * PHY specific properties. */ reg = <0x0>; }; }; }; This framework is modular and re-usable for other PCIe based Ethernet devices. It can also be extended to support additional platform specific information shared across child nodes. Signed-off-by: Vijayakannan Ayyathurai <vijayakannan.ayyathurai@intel.com>
1 parent 03c5f5f commit 3cf01ec

File tree

7 files changed

+132
-0
lines changed

7 files changed

+132
-0
lines changed

drivers/ethernet/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ add_subdirectory(phy)
7474
add_subdirectory(eth_nxp_enet_qos)
7575
add_subdirectory(nxp_imx_netc)
7676
add_subdirectory(dwc_xgmac)
77+
add_subdirectory(intel)

drivers/ethernet/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ source "drivers/ethernet/phy/Kconfig"
8686

8787
source "drivers/ethernet/nxp_imx_netc/Kconfig"
8888
source "drivers/ethernet/Kconfig.renesas_ra"
89+
source "drivers/ethernet/intel/Kconfig"
8990

9091
endif # "Ethernet Drivers"
9192

drivers/ethernet/intel/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (c) 2025 Intel Corporation.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
zephyr_library_sources_ifdef(CONFIG_ETH_INTEL_PLAT eth_intel_plat.c)

drivers/ethernet/intel/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2025 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config ETH_INTEL_PLAT
5+
bool "Intel Ethernet parent Platform device driver"
6+
depends on DT_HAS_INTEL_ETH_PLAT_ENABLED
7+
help
8+
Enable Platform driver to retrieve the MMIO mapping details and
9+
share them with all the child devices such as MDIO, PHY, MAC
10+
and PTP_CLOCK.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2025 Intel Corporation.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/device.h>
8+
#include <zephyr/kernel.h>
9+
#include <zephyr/drivers/pcie/pcie.h>
10+
#include <zephyr/drivers/ethernet/eth_intel_plat.h>
11+
12+
#include <zephyr/logging/log.h>
13+
LOG_MODULE_REGISTER(intel_eth_plat, CONFIG_ETHERNET_LOG_LEVEL);
14+
15+
#define DT_DRV_COMPAT intel_eth_plat
16+
17+
struct intel_eth_plat_cfg {
18+
struct pcie_dev *pcie;
19+
};
20+
21+
struct intel_eth_plat_data {
22+
DEVICE_MMIO_RAM;
23+
};
24+
25+
uint32_t eth_intel_get_pcie_bdf(const struct device *dev)
26+
{
27+
const struct intel_eth_plat_cfg *cfg = dev->config;
28+
29+
return cfg->pcie->bdf;
30+
}
31+
32+
uint32_t eth_intel_get_pcie_id(const struct device *dev)
33+
{
34+
const struct intel_eth_plat_cfg *cfg = dev->config;
35+
36+
return cfg->pcie->id;
37+
}
38+
39+
static int intel_eth_plat_init(const struct device *dev)
40+
{
41+
const struct intel_eth_plat_cfg *cfg = dev->config;
42+
struct pcie_bar mbar;
43+
44+
if (cfg->pcie->bdf == PCIE_BDF_NONE ||
45+
!pcie_probe_mbar(cfg->pcie->bdf, 0, &mbar)) {
46+
LOG_ERR("Cannot get mbar");
47+
return -ENOENT;
48+
}
49+
50+
pcie_set_cmd(cfg->pcie->bdf,
51+
PCIE_CONF_CMDSTAT_MEM | PCIE_CONF_CMDSTAT_MASTER, true);
52+
53+
device_map(DEVICE_MMIO_RAM_PTR(dev),
54+
mbar.phys_addr, mbar.size, K_MEM_CACHE_NONE);
55+
56+
return 0;
57+
}
58+
59+
#define INTEL_ETH_PLAT_CONFIG(n) \
60+
static const struct intel_eth_plat_cfg plat_cfg_##n = { \
61+
DEVICE_PCIE_INST_INIT(n, pcie), \
62+
};
63+
64+
#define INTEL_ETH_PLAT_INIT(n) \
65+
DEVICE_PCIE_INST_DECLARE(n); \
66+
INTEL_ETH_PLAT_CONFIG(n); \
67+
static struct intel_eth_plat_data plat_data_##n; \
68+
\
69+
DEVICE_DT_INST_DEFINE(n, intel_eth_plat_init, NULL, \
70+
&plat_data_##n, &plat_cfg_##n, POST_KERNEL, \
71+
CONFIG_PCIE_INIT_PRIORITY, NULL);
72+
73+
DT_INST_FOREACH_STATUS_OKAY(INTEL_ETH_PLAT_INIT)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2025 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Intel Ethernet parent platform device.
5+
6+
compatible: "intel,eth-plat"
7+
8+
include: [base.yaml, ethernet-controller.yaml, pcie-device.yaml]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Ethernet Platform Utilities for Intel Devices
3+
*
4+
* This module provides utility functions to interact with the PCIe features
5+
* of Intel Ethernet devices, facilitating the retrieval of device-specific
6+
* PCIe configuration details such as BDF (Bus/Device/Function) and device ID.
7+
*
8+
* Copyright (c) 2025 Intel Corporation.
9+
*
10+
* SPDX-License-Identifier: Apache-2.0
11+
*/
12+
13+
#ifndef ZEPHYR_INCLUDE_DRIVERS_ETH_INTEL_PLAT_H__
14+
#define ZEPHYR_INCLUDE_DRIVERS_ETH_INTEL_PLAT_H__
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif
19+
20+
/**
21+
* @brief Retrieve the PCIe Bus/Device/Function of the device.
22+
*
23+
* @param dev Pointer to the device structure.
24+
* @return PCIe BDF address as a uint32_t.
25+
*/
26+
extern uint32_t eth_intel_get_pcie_bdf(const struct device *dev);
27+
28+
/**
29+
* @brief Retrieve the PCIe ID of the device.
30+
*
31+
* @param dev Pointer to the device structure.
32+
* @return PCIe ID as a uint32_t.
33+
*/
34+
extern uint32_t eth_intel_get_pcie_id(const struct device *dev);
35+
#endif /* ZEPHYR_INCLUDE_DRIVERS_ETH_INTEL_PLAT_H__ */

0 commit comments

Comments
 (0)