162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* Copyright (C) 2021 Gerhard Engleder <gerhard@engleder-embedded.com> */ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci/* Hardware definition of TSNEP and EtherCAT MAC device */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef _TSNEP_HW_H 762306a36Sopenharmony_ci#define _TSNEP_HW_H 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include <linux/types.h> 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci/* type */ 1262306a36Sopenharmony_ci#define ECM_TYPE 0x0000 1362306a36Sopenharmony_ci#define ECM_REVISION_MASK 0x000000FF 1462306a36Sopenharmony_ci#define ECM_REVISION_SHIFT 0 1562306a36Sopenharmony_ci#define ECM_VERSION_MASK 0x0000FF00 1662306a36Sopenharmony_ci#define ECM_VERSION_SHIFT 8 1762306a36Sopenharmony_ci#define ECM_QUEUE_COUNT_MASK 0x00070000 1862306a36Sopenharmony_ci#define ECM_QUEUE_COUNT_SHIFT 16 1962306a36Sopenharmony_ci#define ECM_GATE_CONTROL 0x02000000 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci/* system time */ 2262306a36Sopenharmony_ci#define ECM_SYSTEM_TIME_LOW 0x0008 2362306a36Sopenharmony_ci#define ECM_SYSTEM_TIME_HIGH 0x000C 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci/* clock */ 2662306a36Sopenharmony_ci#define ECM_CLOCK_RATE 0x0010 2762306a36Sopenharmony_ci#define ECM_CLOCK_RATE_OFFSET_MASK 0x7FFFFFFF 2862306a36Sopenharmony_ci#define ECM_CLOCK_RATE_OFFSET_SIGN 0x80000000 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci/* interrupt */ 3162306a36Sopenharmony_ci#define ECM_INT_ENABLE 0x0018 3262306a36Sopenharmony_ci#define ECM_INT_ACTIVE 0x001C 3362306a36Sopenharmony_ci#define ECM_INT_ACKNOWLEDGE 0x001C 3462306a36Sopenharmony_ci#define ECM_INT_LINK 0x00000020 3562306a36Sopenharmony_ci#define ECM_INT_TX_0 0x00000100 3662306a36Sopenharmony_ci#define ECM_INT_RX_0 0x00000200 3762306a36Sopenharmony_ci#define ECM_INT_TXRX_SHIFT 2 3862306a36Sopenharmony_ci#define ECM_INT_ALL 0x7FFFFFFF 3962306a36Sopenharmony_ci#define ECM_INT_DISABLE 0x80000000 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci/* reset */ 4262306a36Sopenharmony_ci#define ECM_RESET 0x0020 4362306a36Sopenharmony_ci#define ECM_RESET_COMMON 0x00000001 4462306a36Sopenharmony_ci#define ECM_RESET_CHANNEL 0x00000100 4562306a36Sopenharmony_ci#define ECM_RESET_TXRX 0x00010000 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci/* counter */ 4862306a36Sopenharmony_ci#define ECM_COUNTER_LOW 0x0028 4962306a36Sopenharmony_ci#define ECM_COUNTER_HIGH 0x002C 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci/* interrupt delay */ 5262306a36Sopenharmony_ci#define ECM_INT_DELAY 0x0030 5362306a36Sopenharmony_ci#define ECM_INT_DELAY_MASK 0xF0 5462306a36Sopenharmony_ci#define ECM_INT_DELAY_SHIFT 4 5562306a36Sopenharmony_ci#define ECM_INT_DELAY_BASE_US 16 5662306a36Sopenharmony_ci#define ECM_INT_DELAY_OFFSET 1 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci/* control and status */ 5962306a36Sopenharmony_ci#define ECM_STATUS 0x0080 6062306a36Sopenharmony_ci#define ECM_LINK_MODE_OFF 0x01000000 6162306a36Sopenharmony_ci#define ECM_LINK_MODE_100 0x02000000 6262306a36Sopenharmony_ci#define ECM_LINK_MODE_1000 0x04000000 6362306a36Sopenharmony_ci#define ECM_NO_LINK 0x01000000 6462306a36Sopenharmony_ci#define ECM_LINK_MODE_MASK 0x06000000 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci/* management data */ 6762306a36Sopenharmony_ci#define ECM_MD_CONTROL 0x0084 6862306a36Sopenharmony_ci#define ECM_MD_STATUS 0x0084 6962306a36Sopenharmony_ci#define ECM_MD_PREAMBLE 0x00000001 7062306a36Sopenharmony_ci#define ECM_MD_READ 0x00000004 7162306a36Sopenharmony_ci#define ECM_MD_WRITE 0x00000002 7262306a36Sopenharmony_ci#define ECM_MD_ADDR_MASK 0x000000F8 7362306a36Sopenharmony_ci#define ECM_MD_ADDR_SHIFT 3 7462306a36Sopenharmony_ci#define ECM_MD_PHY_ADDR_MASK 0x00001F00 7562306a36Sopenharmony_ci#define ECM_MD_PHY_ADDR_SHIFT 8 7662306a36Sopenharmony_ci#define ECM_MD_BUSY 0x00000001 7762306a36Sopenharmony_ci#define ECM_MD_DATA_MASK 0xFFFF0000 7862306a36Sopenharmony_ci#define ECM_MD_DATA_SHIFT 16 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci/* statistic */ 8162306a36Sopenharmony_ci#define ECM_STAT 0x00B0 8262306a36Sopenharmony_ci#define ECM_STAT_RX_ERR_MASK 0x000000FF 8362306a36Sopenharmony_ci#define ECM_STAT_RX_ERR_SHIFT 0 8462306a36Sopenharmony_ci#define ECM_STAT_INV_FRM_MASK 0x0000FF00 8562306a36Sopenharmony_ci#define ECM_STAT_INV_FRM_SHIFT 8 8662306a36Sopenharmony_ci#define ECM_STAT_FWD_RX_ERR_MASK 0x00FF0000 8762306a36Sopenharmony_ci#define ECM_STAT_FWD_RX_ERR_SHIFT 16 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci/* tsnep */ 9062306a36Sopenharmony_ci#define TSNEP_MAC_SIZE 0x4000 9162306a36Sopenharmony_ci#define TSNEP_QUEUE_SIZE 0x1000 9262306a36Sopenharmony_ci#define TSNEP_QUEUE(n) ({ typeof(n) __n = (n); \ 9362306a36Sopenharmony_ci (__n) == 0 ? \ 9462306a36Sopenharmony_ci 0 : \ 9562306a36Sopenharmony_ci TSNEP_MAC_SIZE + TSNEP_QUEUE_SIZE * ((__n) - 1); }) 9662306a36Sopenharmony_ci#define TSNEP_MAX_QUEUES 8 9762306a36Sopenharmony_ci#define TSNEP_MAX_FRAME_SIZE (2 * 1024) /* hardware supports actually 16k */ 9862306a36Sopenharmony_ci#define TSNEP_DESC_SIZE 256 9962306a36Sopenharmony_ci#define TSNEP_DESC_OFFSET 128 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci/* tsnep register */ 10262306a36Sopenharmony_ci#define TSNEP_INFO 0x0100 10362306a36Sopenharmony_ci#define TSNEP_INFO_TX_TIME 0x00010000 10462306a36Sopenharmony_ci#define TSNEP_CONTROL 0x0108 10562306a36Sopenharmony_ci#define TSNEP_CONTROL_TX_RESET 0x00000001 10662306a36Sopenharmony_ci#define TSNEP_CONTROL_TX_ENABLE 0x00000002 10762306a36Sopenharmony_ci#define TSNEP_CONTROL_TX_DMA_ERROR 0x00000010 10862306a36Sopenharmony_ci#define TSNEP_CONTROL_TX_DESC_ERROR 0x00000020 10962306a36Sopenharmony_ci#define TSNEP_CONTROL_RX_RESET 0x00000100 11062306a36Sopenharmony_ci#define TSNEP_CONTROL_RX_ENABLE 0x00000200 11162306a36Sopenharmony_ci#define TSNEP_CONTROL_RX_DISABLE 0x00000400 11262306a36Sopenharmony_ci#define TSNEP_CONTROL_RX_DMA_ERROR 0x00001000 11362306a36Sopenharmony_ci#define TSNEP_CONTROL_RX_DESC_ERROR 0x00002000 11462306a36Sopenharmony_ci#define TSNEP_TX_DESC_ADDR_LOW 0x0140 11562306a36Sopenharmony_ci#define TSNEP_TX_DESC_ADDR_HIGH 0x0144 11662306a36Sopenharmony_ci#define TSNEP_RX_DESC_ADDR_LOW 0x0180 11762306a36Sopenharmony_ci#define TSNEP_RX_DESC_ADDR_HIGH 0x0184 11862306a36Sopenharmony_ci#define TSNEP_RESET_OWNER_COUNTER 0x01 11962306a36Sopenharmony_ci#define TSNEP_RX_STATISTIC 0x0190 12062306a36Sopenharmony_ci#define TSNEP_RX_STATISTIC_NO_DESC_MASK 0x000000FF 12162306a36Sopenharmony_ci#define TSNEP_RX_STATISTIC_NO_DESC_SHIFT 0 12262306a36Sopenharmony_ci#define TSNEP_RX_STATISTIC_BUFFER_TOO_SMALL_MASK 0x0000FF00 12362306a36Sopenharmony_ci#define TSNEP_RX_STATISTIC_BUFFER_TOO_SMALL_SHIFT 8 12462306a36Sopenharmony_ci#define TSNEP_RX_STATISTIC_FIFO_OVERFLOW_MASK 0x00FF0000 12562306a36Sopenharmony_ci#define TSNEP_RX_STATISTIC_FIFO_OVERFLOW_SHIFT 16 12662306a36Sopenharmony_ci#define TSNEP_RX_STATISTIC_INVALID_FRAME_MASK 0xFF000000 12762306a36Sopenharmony_ci#define TSNEP_RX_STATISTIC_INVALID_FRAME_SHIFT 24 12862306a36Sopenharmony_ci#define TSNEP_RX_STATISTIC_NO_DESC 0x0190 12962306a36Sopenharmony_ci#define TSNEP_RX_STATISTIC_BUFFER_TOO_SMALL 0x0191 13062306a36Sopenharmony_ci#define TSNEP_RX_STATISTIC_FIFO_OVERFLOW 0x0192 13162306a36Sopenharmony_ci#define TSNEP_RX_STATISTIC_INVALID_FRAME 0x0193 13262306a36Sopenharmony_ci#define TSNEP_MAC_ADDRESS_LOW 0x0800 13362306a36Sopenharmony_ci#define TSNEP_MAC_ADDRESS_HIGH 0x0804 13462306a36Sopenharmony_ci#define TSNEP_RX_FILTER 0x0806 13562306a36Sopenharmony_ci#define TSNEP_RX_FILTER_ACCEPT_ALL_MULTICASTS 0x0001 13662306a36Sopenharmony_ci#define TSNEP_RX_FILTER_ACCEPT_ALL_UNICASTS 0x0002 13762306a36Sopenharmony_ci#define TSNEP_GC 0x0808 13862306a36Sopenharmony_ci#define TSNEP_GC_ENABLE_A 0x00000002 13962306a36Sopenharmony_ci#define TSNEP_GC_ENABLE_B 0x00000004 14062306a36Sopenharmony_ci#define TSNEP_GC_DISABLE 0x00000008 14162306a36Sopenharmony_ci#define TSNEP_GC_ENABLE_TIMEOUT 0x00000010 14262306a36Sopenharmony_ci#define TSNEP_GC_ACTIVE_A 0x00000002 14362306a36Sopenharmony_ci#define TSNEP_GC_ACTIVE_B 0x00000004 14462306a36Sopenharmony_ci#define TSNEP_GC_CHANGE_AB 0x00000008 14562306a36Sopenharmony_ci#define TSNEP_GC_TIMEOUT_ACTIVE 0x00000010 14662306a36Sopenharmony_ci#define TSNEP_GC_TIMEOUT_SIGNAL 0x00000020 14762306a36Sopenharmony_ci#define TSNEP_GC_LIST_ERROR 0x00000080 14862306a36Sopenharmony_ci#define TSNEP_GC_OPEN 0x00FF0000 14962306a36Sopenharmony_ci#define TSNEP_GC_OPEN_SHIFT 16 15062306a36Sopenharmony_ci#define TSNEP_GC_NEXT_OPEN 0xFF000000 15162306a36Sopenharmony_ci#define TSNEP_GC_NEXT_OPEN_SHIFT 24 15262306a36Sopenharmony_ci#define TSNEP_GC_TIMEOUT 131072 15362306a36Sopenharmony_ci#define TSNEP_GC_TIME 0x080C 15462306a36Sopenharmony_ci#define TSNEP_GC_CHANGE 0x0810 15562306a36Sopenharmony_ci#define TSNEP_GCL_A 0x2000 15662306a36Sopenharmony_ci#define TSNEP_GCL_B 0x2800 15762306a36Sopenharmony_ci#define TSNEP_GCL_SIZE SZ_2K 15862306a36Sopenharmony_ci#define TSNEP_RX_ASSIGN 0x0840 15962306a36Sopenharmony_ci#define TSNEP_RX_ASSIGN_ACTIVE 0x00000001 16062306a36Sopenharmony_ci#define TSNEP_RX_ASSIGN_QUEUE_MASK 0x00000006 16162306a36Sopenharmony_ci#define TSNEP_RX_ASSIGN_QUEUE_SHIFT 1 16262306a36Sopenharmony_ci#define TSNEP_RX_ASSIGN_OFFSET 1 16362306a36Sopenharmony_ci#define TSNEP_RX_ASSIGN_ETHER_TYPE 0x0880 16462306a36Sopenharmony_ci#define TSNEP_RX_ASSIGN_ETHER_TYPE_OFFSET 2 16562306a36Sopenharmony_ci#define TSNEP_RX_ASSIGN_ETHER_TYPE_COUNT 2 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ci/* tsnep gate control list operation */ 16862306a36Sopenharmony_cistruct tsnep_gcl_operation { 16962306a36Sopenharmony_ci u32 properties; 17062306a36Sopenharmony_ci u32 interval; 17162306a36Sopenharmony_ci}; 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci#define TSNEP_GCL_COUNT (TSNEP_GCL_SIZE / sizeof(struct tsnep_gcl_operation)) 17462306a36Sopenharmony_ci#define TSNEP_GCL_MASK 0x000000FF 17562306a36Sopenharmony_ci#define TSNEP_GCL_INSERT 0x20000000 17662306a36Sopenharmony_ci#define TSNEP_GCL_CHANGE 0x40000000 17762306a36Sopenharmony_ci#define TSNEP_GCL_LAST 0x80000000 17862306a36Sopenharmony_ci#define TSNEP_GCL_MIN_INTERVAL 32 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci/* tsnep TX/RX descriptor */ 18162306a36Sopenharmony_ci#define TSNEP_DESC_SIZE 256 18262306a36Sopenharmony_ci#define TSNEP_DESC_SIZE_DATA_AFTER 2048 18362306a36Sopenharmony_ci#define TSNEP_DESC_OFFSET 128 18462306a36Sopenharmony_ci#define TSNEP_DESC_OWNER_COUNTER_MASK 0xC0000000 18562306a36Sopenharmony_ci#define TSNEP_DESC_OWNER_COUNTER_SHIFT 30 18662306a36Sopenharmony_ci#define TSNEP_DESC_LENGTH_MASK 0x00003FFF 18762306a36Sopenharmony_ci#define TSNEP_DESC_INTERRUPT_FLAG 0x00040000 18862306a36Sopenharmony_ci#define TSNEP_DESC_EXTENDED_WRITEBACK_FLAG 0x00080000 18962306a36Sopenharmony_ci#define TSNEP_DESC_NO_LINK_FLAG 0x01000000 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci/* tsnep TX descriptor */ 19262306a36Sopenharmony_cistruct tsnep_tx_desc { 19362306a36Sopenharmony_ci __le32 properties; 19462306a36Sopenharmony_ci __le32 more_properties; 19562306a36Sopenharmony_ci __le32 reserved[2]; 19662306a36Sopenharmony_ci __le64 next; 19762306a36Sopenharmony_ci __le64 tx; 19862306a36Sopenharmony_ci}; 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci#define TSNEP_TX_DESC_OWNER_MASK 0xE0000000 20162306a36Sopenharmony_ci#define TSNEP_TX_DESC_OWNER_USER_FLAG 0x20000000 20262306a36Sopenharmony_ci#define TSNEP_TX_DESC_LAST_FRAGMENT_FLAG 0x00010000 20362306a36Sopenharmony_ci#define TSNEP_TX_DESC_DATA_AFTER_DESC_FLAG 0x00020000 20462306a36Sopenharmony_ci 20562306a36Sopenharmony_ci/* tsnep TX descriptor writeback */ 20662306a36Sopenharmony_cistruct tsnep_tx_desc_wb { 20762306a36Sopenharmony_ci __le32 properties; 20862306a36Sopenharmony_ci __le32 reserved1; 20962306a36Sopenharmony_ci __le64 counter; 21062306a36Sopenharmony_ci __le64 timestamp; 21162306a36Sopenharmony_ci __le32 dma_delay; 21262306a36Sopenharmony_ci __le32 reserved2; 21362306a36Sopenharmony_ci}; 21462306a36Sopenharmony_ci 21562306a36Sopenharmony_ci#define TSNEP_TX_DESC_UNDERRUN_ERROR_FLAG 0x00010000 21662306a36Sopenharmony_ci#define TSNEP_TX_DESC_DMA_DELAY_FIRST_DATA_MASK 0x0000FFFC 21762306a36Sopenharmony_ci#define TSNEP_TX_DESC_DMA_DELAY_FIRST_DATA_SHIFT 2 21862306a36Sopenharmony_ci#define TSNEP_TX_DESC_DMA_DELAY_LAST_DATA_MASK 0xFFFC0000 21962306a36Sopenharmony_ci#define TSNEP_TX_DESC_DMA_DELAY_LAST_DATA_SHIFT 18 22062306a36Sopenharmony_ci#define TSNEP_TX_DESC_DMA_DELAY_NS 64 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_ci/* tsnep RX descriptor */ 22362306a36Sopenharmony_cistruct tsnep_rx_desc { 22462306a36Sopenharmony_ci __le32 properties; 22562306a36Sopenharmony_ci __le32 reserved[3]; 22662306a36Sopenharmony_ci __le64 next; 22762306a36Sopenharmony_ci __le64 rx; 22862306a36Sopenharmony_ci}; 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_ci#define TSNEP_RX_DESC_BUFFER_SIZE_MASK 0x00003FFC 23162306a36Sopenharmony_ci 23262306a36Sopenharmony_ci/* tsnep RX descriptor writeback */ 23362306a36Sopenharmony_cistruct tsnep_rx_desc_wb { 23462306a36Sopenharmony_ci __le32 properties; 23562306a36Sopenharmony_ci __le32 reserved[7]; 23662306a36Sopenharmony_ci}; 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ci/* tsnep RX inline meta */ 23962306a36Sopenharmony_cistruct tsnep_rx_inline { 24062306a36Sopenharmony_ci __le64 counter; 24162306a36Sopenharmony_ci __le64 timestamp; 24262306a36Sopenharmony_ci}; 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ci#define TSNEP_RX_INLINE_METADATA_SIZE (sizeof(struct tsnep_rx_inline)) 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_ci#endif /* _TSNEP_HW_H */ 247