10
10
#include <zephyr/sys/util.h>
11
11
#include <zephyr/sys/__assert.h>
12
12
#include <ethernet/eth_stats.h>
13
+ #include <zephyr/linker/devicetree_regions.h>
13
14
14
15
#include <errno.h>
15
16
#include <stdbool.h>
@@ -41,7 +42,11 @@ static struct eth_stm32_tx_context dma_tx_context[ETH_TX_DESC_CNT];
41
42
/* Pointer to an array of ETH_STM32_RX_BUF_SIZE uint8_t's */
42
43
typedef uint8_t (* RxBufferPtr )[ETH_STM32_RX_BUF_SIZE ];
43
44
45
+ #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32mp13_ethernet )
46
+ void HAL_ETH_RxAllocateCallback (ETH_HandleTypeDef * heth , uint8_t * * buf )
47
+ #else
44
48
void HAL_ETH_RxAllocateCallback (uint8_t * * buf )
49
+ #endif
45
50
{
46
51
for (size_t i = 0 ; i < ETH_RXBUFNB ; ++ i ) {
47
52
if (!dma_rx_buffer_header [i ].used ) {
@@ -56,7 +61,12 @@ void HAL_ETH_RxAllocateCallback(uint8_t **buf)
56
61
}
57
62
58
63
/* called by HAL_ETH_ReadData() */
64
+ #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32mp13_ethernet )
65
+ void HAL_ETH_RxLinkCallback (ETH_HandleTypeDef * heth , void * * pStart , void * * pEnd ,
66
+ uint8_t * buff , uint16_t Length )
67
+ #else
59
68
void HAL_ETH_RxLinkCallback (void * * pStart , void * * pEnd , uint8_t * buff , uint16_t Length )
69
+ #endif
60
70
{
61
71
/* buff points to the begin on one of the rx buffers,
62
72
* so we can compute the index of the given buffer
@@ -81,7 +91,11 @@ void HAL_ETH_RxLinkCallback(void **pStart, void **pEnd, uint8_t *buff, uint16_t
81
91
}
82
92
83
93
/* Called by HAL_ETH_ReleaseTxPacket */
94
+ #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32mp13_ethernet )
95
+ void HAL_ETH_TxFreeCallback (ETH_HandleTypeDef * heth , uint32_t * buff )
96
+ #else
84
97
void HAL_ETH_TxFreeCallback (uint32_t * buff )
98
+ #endif
85
99
{
86
100
__ASSERT_NO_MSG (buff != NULL );
87
101
@@ -279,7 +293,11 @@ int eth_stm32_tx(const struct device *dev, struct net_pkt *pkt)
279
293
HAL_ETH_ReleaseTxPacket (heth );
280
294
} else {
281
295
/* We need to release the tx context and its buffers */
296
+ #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32mp13_ethernet )
297
+ HAL_ETH_TxFreeCallback (heth , (uint32_t * )ctx );
298
+ #else
282
299
HAL_ETH_TxFreeCallback ((uint32_t * )ctx );
300
+ #endif
283
301
}
284
302
285
303
k_mutex_unlock (& dev_data -> tx_mutex );
@@ -454,6 +472,9 @@ void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *heth)
454
472
#if DT_HAS_COMPAT_STATUS_OKAY (st_stm32h7_ethernet )
455
473
dev_data -> stats .error_details .rx_crc_errors = heth -> Instance -> MMCRCRCEPR ;
456
474
dev_data -> stats .error_details .rx_align_errors = heth -> Instance -> MMCRAEPR ;
475
+ #elif DT_HAS_COMPAT_STATUS_OKAY (st_stm32mp13_ethernet )
476
+ dev_data -> stats .error_details .rx_crc_errors = heth -> Instance -> MMCRXCRCEPR ;
477
+ dev_data -> stats .error_details .rx_align_errors = heth -> Instance -> MMCRXAEPR ;
457
478
#else
458
479
dev_data -> stats .error_details .rx_crc_errors = heth -> Instance -> MMCRFCECR ;
459
480
dev_data -> stats .error_details .rx_align_errors = heth -> Instance -> MMCRFAECR ;
@@ -467,6 +488,9 @@ int eth_stm32_hal_init(const struct device *dev)
467
488
struct eth_stm32_hal_dev_data * dev_data = dev -> data ;
468
489
ETH_HandleTypeDef * heth = & dev_data -> heth ;
469
490
HAL_StatusTypeDef hal_ret = HAL_OK ;
491
+ __maybe_unused const struct eth_stm32_hal_dev_cfg * cfg = dev -> config ;
492
+ __maybe_unused uint8_t * desc_uncached_addr ;
493
+ __maybe_unused int ret ;
470
494
471
495
#if DT_HAS_COMPAT_STATUS_OKAY (st_stm32n6_ethernet )
472
496
for (int ch = 0 ; ch < ETH_DMA_CH_CNT ; ch ++ ) {
@@ -479,6 +503,37 @@ int eth_stm32_hal_init(const struct device *dev)
479
503
#endif
480
504
heth -> Init .RxBuffLen = ETH_STM32_RX_BUF_SIZE ;
481
505
506
+ #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32mp13_ethernet )
507
+ /* Map memory region for DMA descriptor and buffer as non cacheable */
508
+ k_mem_map_phys_bare (& desc_uncached_addr ,
509
+ DT_REG_ADDR (ETH_DMA_REGION ),
510
+ DT_REG_SIZE (ETH_DMA_REGION ),
511
+ K_MEM_PERM_RW | K_MEM_DIRECT_MAP | K_MEM_CACHE_NONE |
512
+ K_MEM_ARM_NORMAL_NC );
513
+
514
+ heth -> Init .ClockSelection = cfg -> clockselection ;
515
+ #endif
516
+
517
+ #if DT_INST_CLOCKS_HAS_NAME (0 , eth_ker )
518
+ /* Turn on DCMIPP peripheral clock */
519
+ ret = clock_control_configure (DEVICE_DT_GET (STM32_CLOCK_CONTROL_NODE ),
520
+ (clock_control_subsys_t )& cfg -> pclken_ker ,
521
+ NULL );
522
+ if (ret < 0 ) {
523
+ LOG_ERR ("Failed to configure ETH kernel clock. Error %d" , ret );
524
+ return ret ;
525
+ }
526
+ #endif
527
+
528
+ #if DT_INST_CLOCKS_HAS_NAME (0 , mac_clk )
529
+ ret = clock_control_on (DEVICE_DT_GET (STM32_CLOCK_CONTROL_NODE ),
530
+ (clock_control_subsys_t )& cfg -> pclken_mac );
531
+ if (ret < 0 ) {
532
+ LOG_ERR ("Failed to configure mac clock. Error %d" , ret );
533
+ return ret ;
534
+ }
535
+ #endif
536
+
482
537
hal_ret = HAL_ETH_Init (heth );
483
538
if (hal_ret == HAL_TIMEOUT ) {
484
539
/* HAL Init time out. This could be linked to */
0 commit comments