Skip to content

Commit 63c5215

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 63c5215

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

include/zephyr/net/ethernet.h

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

0 commit comments

Comments
 (0)