menu "Ethernet"

    # Invisible item that is enabled if any Ethernet selection is made
    config ETH_ENABLED
        bool

    menuconfig ETH_USE_ESP32_EMAC
        depends on SOC_EMAC_SUPPORTED
        bool "Support ESP32 internal EMAC controller"
        default y
        select ETH_ENABLED
        help
            ESP32 integrates a 10/100M Ethernet MAC controller.

    if ETH_USE_ESP32_EMAC
        config ETH_DMA_BUFFER_SIZE
            int "Ethernet DMA buffer size (Byte)"
            range 256 1600
            default 512
            help
                Set the size of each buffer used by Ethernet MAC DMA.
                !! Important !! Make sure it is 64B aligned for ESP32P4!

        config ETH_DMA_RX_BUFFER_NUM
            int "Amount of Ethernet DMA Rx buffers"
            range 3 30
            default 10 if IDF_TARGET_ESP32
            default 20 if IDF_TARGET_ESP32P4 #ESP32P4 has smaller internal Rx FIFO
            help
                Number of DMA receive buffers. Each buffer's size is ETH_DMA_BUFFER_SIZE.
                Larger number of buffers could increase throughput somehow.

        config ETH_DMA_TX_BUFFER_NUM
            int "Amount of Ethernet DMA Tx buffers"
            range 3 30
            default 10
            help
                Number of DMA transmit buffers. Each buffer's size is ETH_DMA_BUFFER_SIZE.
                Larger number of buffers could increase throughput somehow.

        if ETH_DMA_RX_BUFFER_NUM > 15
            config ETH_SOFT_FLOW_CONTROL
                bool "Enable software flow control"
                default n
                help
                    Ethernet MAC engine on ESP32 doesn't feature a flow control logic.
                    The MAC driver can perform a software flow control if you enable this option.
                    Note that, if the RX buffer number is small, enabling software flow control will
                    cause obvious performance loss.
        endif

        config ETH_IRAM_OPTIMIZATION
            bool "Enable IRAM optimization"
            default n
            help
                If enabled, functions related to RX/TX are placed into IRAM. It can improve Ethernet throughput.
                If disabled, all functions are placed into FLASH.

    endif # ETH_USE_ESP32_EMAC
    menuconfig ETH_USE_SPI_ETHERNET
        bool "Support SPI to Ethernet Module"
        default y
        select ETH_ENABLED
        help
            ESP-IDF can also support SPI-Ethernet. Actual chip drivers are available as components in
            Component Registry.

    menuconfig ETH_USE_OPENETH
        bool "Support OpenCores Ethernet MAC (for use with QEMU)"
        default n
        select ETH_ENABLED
        help
            OpenCores Ethernet MAC driver can be used when an ESP-IDF application
            is executed in QEMU. This driver is not supported when running on a
            real chip.

    if ETH_USE_OPENETH
        config ETH_OPENETH_DMA_RX_BUFFER_NUM
            int "Number of Ethernet DMA Rx buffers"
            range 1 64
            default 4
            help
                Number of DMA receive buffers, each buffer is 1600 bytes.

        config ETH_OPENETH_DMA_TX_BUFFER_NUM
            int "Number of Ethernet DMA Tx buffers"
            range 1 64
            default 1
            help
                Number of DMA transmit buffers, each buffer is 1600 bytes.
    endif # ETH_USE_OPENETH

    config ETH_TRANSMIT_MUTEX
        depends on ETH_ENABLED
        bool "Enable Transmit Mutex"
        default n
        help
            Prevents multiple accesses when Ethernet interface is used as shared resource and multiple
            functionalities might try to access it at a time.
endmenu
