5
5
* SPDX-License-Identifier: Apache-2.0
6
6
*/
7
7
8
+ #define DT_DRV_COMPAT xlnx_axi_ethernet_1_00_a
9
+
8
10
#include <zephyr/logging/log.h>
9
11
LOG_MODULE_REGISTER (eth_xilinx_axienet , CONFIG_ETHERNET_LOG_LEVEL );
10
12
@@ -16,6 +18,7 @@ LOG_MODULE_REGISTER(eth_xilinx_axienet, CONFIG_ETHERNET_LOG_LEVEL);
16
18
#include <zephyr/net/phy.h>
17
19
#include <zephyr/irq.h>
18
20
#include <zephyr/sys/barrier.h>
21
+ #include "eth.h"
19
22
20
23
#include "../dma/dma_xilinx_axi_dma.h"
21
24
@@ -48,6 +51,11 @@ LOG_MODULE_REGISTER(eth_xilinx_axienet, CONFIG_ETHERNET_LOG_LEVEL);
48
51
#define XILINX_AXIENET_UNICAST_ADDRESS_WORD_0_OFFSET 0x00000700
49
52
#define XILINX_AXIENET_UNICAST_ADDRESS_WORD_1_OFFSET 0x00000704
50
53
54
+ /* Xilinx OUI (Organizationally Unique Identifier) for MAC */
55
+ #define XILINX_OUI_BYTE_0 0x00
56
+ #define XILINX_OUI_BYTE_1 0x0A
57
+ #define XILINX_OUI_BYTE_2 0x35
58
+
51
59
#if (CONFIG_DCACHE_LINE_SIZE > 0 )
52
60
/* cache-line aligned to allow selective cache-line invalidation on the buffer */
53
61
#define XILINX_AXIENET_ETH_ALIGN CONFIG_DCACHE_LINE_SIZE
@@ -498,6 +506,27 @@ static int xilinx_axienet_send(const struct device *dev, struct net_pkt *pkt)
498
506
return setup_dma_tx_transfer (dev , config , data , pkt_len );
499
507
}
500
508
509
+ static void xilinx_axienet_generate_mac_address (uint8_t * mac_addr )
510
+ {
511
+ #if DT_INST_PROP (0 , zephyr_random_mac_address )
512
+ /* Generate random MAC address using Xilinx OUI as vendor prefix */
513
+ gen_random_mac (mac_addr , XILINX_OUI_BYTE_0 , XILINX_OUI_BYTE_1 , XILINX_OUI_BYTE_2 );
514
+ #elif DT_INST_NODE_HAS_PROP (0 , local_mac_address )
515
+ /* Use provided MAC address from device tree */
516
+ uint8_t dt_mac [] = DT_INST_PROP (0 , local_mac_address );
517
+
518
+ memcpy (mac_addr , dt_mac , NET_ETH_ADDR_LEN );
519
+ #else
520
+ /* Default fallback - use Xilinx OUI with all zeros for device-specific part */
521
+ mac_addr [0 ] = XILINX_OUI_BYTE_0 ;
522
+ mac_addr [1 ] = XILINX_OUI_BYTE_1 ;
523
+ mac_addr [2 ] = XILINX_OUI_BYTE_2 ;
524
+ mac_addr [3 ] = 0x00 ;
525
+ mac_addr [4 ] = 0x00 ;
526
+ mac_addr [5 ] = 0x00 ;
527
+ #endif
528
+ }
529
+
501
530
static int xilinx_axienet_probe (const struct device * dev )
502
531
{
503
532
const struct xilinx_axienet_config * config = dev -> config ;
@@ -540,6 +569,9 @@ static int xilinx_axienet_probe(const struct device *dev)
540
569
LOG_INF ("TX Checksum offloading %s" ,
541
570
config -> have_tx_csum_offload ? "requested" : "disabled" );
542
571
572
+ /* Generate MAC address at runtime */
573
+ xilinx_axienet_generate_mac_address (data -> mac_addr );
574
+
543
575
xilinx_axienet_set_mac_address (config , data );
544
576
545
577
for (int i = 0 ; i < CONFIG_ETH_XILINX_AXIENET_BUFFER_NUM_RX - 1 ; i ++ ) {
@@ -586,7 +618,6 @@ static const struct ethernet_api xilinx_axienet_api = {
586
618
} \
587
619
\
588
620
static struct xilinx_axienet_data data_##inst = { \
589
- .mac_addr = DT_INST_PROP_OR(inst, local_mac_address, {0}), \
590
621
.dma_is_configured_rx = false, \
591
622
.dma_is_configured_tx = false}; \
592
623
static const struct xilinx_axienet_config config_##inst = { \
@@ -603,5 +634,4 @@ static const struct ethernet_api xilinx_axienet_api = {
603
634
&config_##inst, CONFIG_ETH_INIT_PRIORITY, \
604
635
&xilinx_axienet_api, NET_ETH_MTU);
605
636
606
- #define DT_DRV_COMPAT xlnx_axi_ethernet_1_00_a
607
637
DT_INST_FOREACH_STATUS_OKAY (XILINX_AXIENET_INIT );
0 commit comments