Skip to content

Commit b48e787

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 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 it with all the child subsystem components. This approach avoid the duplicate remapping, ensures efficient re-use of MMIO mappings across related devices. Example device tree structure for first ethernet instance: parent0: parent0 { compatible = "intel,eth-plat"; interrupt-parent = <&intc>; vendor-id = <0x8086>; device-id = <0xXXXX>; igc0: igc0 { compatible = "intel,igc-mac"; /* * MAC specific properties. */ status = "okay"; }; mdio0: mdio0 { compatible = "intel,igc-mdio"; #address-cells = <1>; #size-cells = <0>; ethphy0: ethernet-phy@0 { compatible = "ethernet-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 e22ca6b commit b48e787

File tree

7 files changed

+147
-0
lines changed

7 files changed

+147
-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: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
/* Device id supported in igc */
18+
enum i226_sku {
19+
INTEL_IGC_I226_LMVP = 0x5503,
20+
INTEL_IGC_I226_LM = 0x125B,
21+
INTEL_IGC_I226_V = 0x125C,
22+
INTEL_IGC_I226_IT = 0x125D,
23+
INTEL_IGC_I226_BLANK_NVM = 0x125F,
24+
};
25+
26+
struct intel_eth_plat_cfg {
27+
struct pcie_dev *pcie;
28+
};
29+
30+
struct intel_eth_plat_data {
31+
DEVICE_MMIO_RAM;
32+
mm_reg_t base;
33+
};
34+
35+
uint32_t eth_intel_get_pcie_bdf(const struct device *dev)
36+
{
37+
const struct intel_eth_plat_cfg *cfg = dev->config;
38+
39+
return cfg->pcie->bdf;
40+
}
41+
42+
static int eth_intel_validate_sku(const struct device *dev)
43+
{
44+
const struct intel_eth_plat_cfg *cfg = dev->config;
45+
pcie_id_t pcie_id = cfg->pcie->id;
46+
47+
switch (PCIE_ID_TO_DEV(pcie_id)) {
48+
case INTEL_IGC_I226_LMVP:
49+
case INTEL_IGC_I226_LM:
50+
case INTEL_IGC_I226_V:
51+
case INTEL_IGC_I226_IT:
52+
return 0;
53+
case INTEL_IGC_I226_BLANK_NVM:
54+
default:
55+
break;
56+
}
57+
58+
LOG_ERR("SKU validation failed & pcie_id is %x", pcie_id);
59+
60+
return -EIO;
61+
}
62+
63+
static int intel_eth_plat_init(const struct device *dev)
64+
{
65+
const struct intel_eth_plat_cfg *cfg = dev->config;
66+
struct pcie_bar mbar;
67+
int ret;
68+
69+
ret = eth_intel_validate_sku(dev);
70+
if (ret < 0) {
71+
return ret;
72+
}
73+
74+
if (cfg->pcie->bdf == PCIE_BDF_NONE || !pcie_probe_mbar(cfg->pcie->bdf, 0, &mbar)) {
75+
LOG_ERR("Cannot get mbar");
76+
return -ENOENT;
77+
}
78+
79+
pcie_set_cmd(cfg->pcie->bdf, PCIE_CONF_CMDSTAT_MEM | PCIE_CONF_CMDSTAT_MASTER, true);
80+
81+
device_map(DEVICE_MMIO_RAM_PTR(dev), mbar.phys_addr, mbar.size, K_MEM_CACHE_NONE);
82+
83+
return 0;
84+
}
85+
86+
#define INTEL_ETH_PLAT_INIT(n) \
87+
DEVICE_PCIE_INST_DECLARE(n); \
88+
static struct intel_eth_plat_data plat_data_##n; \
89+
static const struct intel_eth_plat_cfg plat_cfg_##n = { \
90+
DEVICE_PCIE_INST_INIT(n, pcie), \
91+
}; \
92+
DEVICE_DT_INST_DEFINE(n, intel_eth_plat_init, NULL, &plat_data_##n, &plat_cfg_##n, \
93+
POST_KERNEL, CONFIG_PCIE_INIT_PRIORITY, NULL);
94+
95+
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, pcie-device.yaml]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
#endif /* ZEPHYR_INCLUDE_DRIVERS_ETH_INTEL_PLAT_H__ */

0 commit comments

Comments
 (0)