Skip to content

Commit 4a779a1

Browse files
committed
include: zephyr: net: ethernet.h: Add MAC address configuration
WIP Signed-off-by: Pieter De Gendt <[email protected]>
1 parent fe37610 commit 4a779a1

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

include/zephyr/net/ethernet.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define ZEPHYR_INCLUDE_NET_ETHERNET_H_
1515

1616
#include <zephyr/kernel.h>
17+
#include <zephyr/nvmem.h>
1718
#include <zephyr/types.h>
1819
#include <stdbool.h>
1920
#include <zephyr/sys/atomic.h>
@@ -1287,6 +1288,72 @@ static inline bool net_eth_is_vlan_interface(struct net_if *iface)
12871288
#define ETH_NET_L3_REGISTER(name, ptype, handler) \
12881289
NET_L3_REGISTER(&NET_L2_GET_NAME(ETHERNET), name, ptype, handler)
12891290

1291+
enum net_eth_mac_type {
1292+
NET_ETH_MAC_STATIC,
1293+
NET_ETH_MAC_RANDOM,
1294+
NET_ETH_MAC_NVMEM,
1295+
};
1296+
1297+
struct net_eth_mac_config {
1298+
enum net_eth_mac_type type;
1299+
uint8_t addr[NET_ETH_ADDR_LEN];
1300+
uint8_t addr_len;
1301+
struct nvmem_cell cell;
1302+
};
1303+
1304+
/** @cond INTERNAL_HIDDEN */
1305+
1306+
/**
1307+
* @brief Obtain the variable name storing ethernet MAC config for the
1308+
* given DT node identifier.
1309+
*
1310+
* @param node_id Node identifier.
1311+
*/
1312+
#define Z_NET_ETH_MAC_DEV_CONFIG_NAME(node_id) \
1313+
_CONCAT(__net_eth_mac_dev_config, DEVICE_DT_NAME_GET(node_id))
1314+
1315+
#define Z_NET_ETH_MAC_DEV_CONFIG_TYPE(node_id) \
1316+
COND_CODE_1(DT_PROP(node_id, zephyr_random_mac_address), \
1317+
(NET_ETH_MAC_RANDOM), \
1318+
(COND_CODE_1(DT_NVMEM_CELLS_HAS_NAME(node_id, mac_address), \
1319+
(NET_ETH_MAC_NVMEM), \
1320+
(NET_ETH_MAC_STATIC))))
1321+
1322+
#define Z_NET_ETH_MAC_DEV_CONFIG_INIT(node_id) \
1323+
{ \
1324+
.type = Z_NET_ETH_MAC_DEV_CONFIG_TYPE(node_id), \
1325+
.addr = DT_PROP_OR(node_id, local_mac_address, {0}), \
1326+
.addr_len = DT_PROP_LEN_OR(node_id, local_mac_address, 0), \
1327+
.cell = NVMEM_CELL_GET_BY_NAME_OR(node_id, mac_address, {0}), \
1328+
}
1329+
1330+
/** @endcond */
1331+
1332+
#define NET_ETH_MAC_DT_DEFINE(node_id) \
1333+
static const struct net_eth_mac_config Z_NET_ETH_MAC_DEV_CONFIG_NAME(node_id) = \
1334+
Z_NET_ETH_MAC_DEV_CONFIG_INIT(node_id)
1335+
1336+
#define NET_ETH_MAC_DT_INST_DEFINE(inst) NET_ETH_MAC_DT_DEFINE(DT_DRV_INST(inst))
1337+
1338+
/**
1339+
* @brief Obtain a reference to the ethernet MAC configuration given a node
1340+
* identifier.
1341+
*
1342+
* @param node_id Node identifier.
1343+
*/
1344+
#define NET_ETH_MAC_DT_DEV_CONFIG_GET(node_id) &Z_NET_ETH_MAC_DEV_CONFIG_NAME(node_id)
1345+
1346+
/**
1347+
* @brief Obtain a reference to the ethernet MAC configuration given current
1348+
* compatible instance number.
1349+
*
1350+
* @param inst Instance number.
1351+
*
1352+
* @see #NET_ETH_MAC_DT_DEV_CONFIG_GET
1353+
*/
1354+
#define NET_ETH_MAC_DT_INST_DEV_CONFIG_GET(inst) \
1355+
NET_ETH_MAC_DT_DEV_CONFIG_GET(DT_DRV_INST(inst))
1356+
12901357
/**
12911358
* @brief Inform ethernet L2 driver that ethernet carrier is detected.
12921359
* This happens when cable is connected.

0 commit comments

Comments
 (0)