# STM32 HAL Ethernet driver configuration options

# Copyright (c) 2017 Erwin Rol <erwin@erwinrol.com>
# Copyright (c) 2020 Alexander Kozhinov <ak.alexander.kozhinov@gmail.com>
# SPDX-License-Identifier: Apache-2.0

menuconfig ETH_STM32_HAL
	bool "STM32 HAL Ethernet driver"
	default y
	depends on DT_HAS_ST_STM32_ETHERNET_ENABLED
	select USE_STM32_HAL_ETH
	select USE_STM32_HAL_RIF if SOC_SERIES_STM32N6X
	select NOCACHE_MEMORY if (SOC_SERIES_STM32H7X && CPU_CORTEX_M7) || SOC_SERIES_STM32N6X
	select HWINFO
	select ETH_DSA_SUPPORT_DEPRECATED
	select PINCTRL
	select MDIO if DT_HAS_ST_STM32_MDIO_ENABLED
	imply CRC
	help
	  Enable STM32 HAL based Ethernet driver. It is available for
	  all Ethernet enabled variants of the F2, F4, F7 and H7 series.

if ETH_STM32_HAL

choice ETH_STM32_HAL_API_VERSION
	prompt "STM32Cube HAL Ethernet version"

config ETH_STM32_HAL_API_V2
	bool "Use official STM32Cube HAL driver"
	depends on SOC_SERIES_STM32H7X || SOC_SERIES_STM32H5X || SOC_SERIES_STM32F4X || SOC_SERIES_STM32F7X || SOC_SERIES_STM32N6X
	select USE_STM32_HAL_ETH_EX if SOC_SERIES_STM32N6X
	help
	  Use the official STM32Cube HAL driver instead of the legacy one.

config ETH_STM32_HAL_API_V1
	bool "Use legacy STM32Cube HAL driver"
	depends on SOC_SERIES_STM32F1X || SOC_SERIES_STM32F2X
	help
	  Driver version based on legacy HAL version as the current official API version.
	  Available only for STM32F1 and STM32F2 SoC series.

endchoice

config ETH_STM32_HAL_RX_THREAD_STACK_SIZE
	int "RX thread stack size"
	default 1500
	help
	  RX thread stack size

config ETH_STM32_HAL_RX_THREAD_PREEMPTIVE
	bool "STM32 Ethernet RX Thread pre-emptive [EXPERIMENTAL]"
	default y if NET_TC_THREAD_PREEMPTIVE
	depends on PREEMPT_ENABLED
	select EXPERIMENTAL
	help
	  With pre-emptive threads, the thread can be pre-empted.

config ETH_STM32_HAL_RX_THREAD_PRIO
	int "STM32 Ethernet RX Thread Priority"
	default 2
	help
	  This option allows to configure the priority of the RX thread that
	  handles incoming Ethernet packets.
	  Switching between preemptive and cooperative scheduling can be done by
	  NET_TC_THREAD_PREEMPTIVE.
	  Preemptive scheduling can lead to more responsive handling of network traffic,
	  especially under high load.

config ETH_STM32_HAL_USE_DTCM_FOR_DMA_BUFFER
	bool "Use DTCM for DMA buffers"
	default y
	depends on SOC_SERIES_STM32F7X
	help
	  When this option is activated, the buffers for DMA transfer are
	  moved from SRAM to the DTCM (Data Tightly Coupled Memory).

config ETH_STM32_HW_CHECKSUM
	bool "Use TX and RX hardware checksum"
	depends on !SOC_SERIES_STM32H5X
	help
	  Enable receive and transmit checksum offload to enhance throughput
	  performances.
	  See reference manual for more information on this feature.

menuconfig PTP_CLOCK_STM32_HAL
	bool "STM32 HAL PTP clock driver support"
	default y
	depends on PTP_CLOCK || NET_L2_PTP
	depends on ETH_STM32_HAL_API_V2
	depends on SOC_SERIES_STM32F7X || SOC_SERIES_STM32H7X || SOC_SERIES_STM32H5X
	help
	  Enable STM32 PTP clock support.

if PTP_CLOCK_STM32_HAL

config ETH_STM32_HAL_PTP_CLOCK_SRC_HZ
	int "Frequency of the clock source for the PTP timer"
	default 50000000
	help
	  Set the frequency in Hz sourced to the PTP timer.
	  If the value is set properly, the timer will be accurate.

config ETH_STM32_HAL_PTP_CLOCK_ADJ_MIN_PCT
	int "Lower bound of clock frequency adjustment (in percent)"
	default 90
	help
	  Specifies lower bound of PTP clock rate adjustment.

config ETH_STM32_HAL_PTP_CLOCK_ADJ_MAX_PCT
	int "Upper bound of clock frequency adjustment (in percent)"
	default 110
	help
	  Specifies upper bound of PTP clock rate adjustment.

config ETH_STM32_HAL_PTP_CLOCK_INIT_PRIO
	int
	default 85
	help
	  STM32 PTP Clock initialization priority level. There is
	  a dependency from the network stack that this device
	  initializes before network stack (NET_INIT_PRIO).

endif # PTP_CLOCK_STM32_HAL

config ETH_STM32_MULTICAST_FILTER
	bool "Multicast hash filter support"
	help
	  Enable support for multicast hash filtering in the MAC.
	  Once enabled the ethernet MAC performs imperfect filtering
	  based on a computed hash of the destination MAC address of
	  the multicast address. Only multicast with the computed
	  hash set in the multicast table will be received and all
	  other multicast is dropped by the MAC. If disabled then all
	  multicast is received by the MAC.

endif # ETH_STM32_HAL
