1 1.1 jmcneill /*- 2 1.1 jmcneill * Copyright (c) 2016 Jared McNeill <jmcneill (at) invisible.ca> 3 1.1 jmcneill * All rights reserved. 4 1.1 jmcneill * 5 1.1 jmcneill * Redistribution and use in source and binary forms, with or without 6 1.1 jmcneill * modification, are permitted provided that the following conditions 7 1.1 jmcneill * are met: 8 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright 9 1.1 jmcneill * notice, this list of conditions and the following disclaimer. 10 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright 11 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the 12 1.1 jmcneill * documentation and/or other materials provided with the distribution. 13 1.1 jmcneill * 14 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 1.1 jmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 1.1 jmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 1.1 jmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 1.1 jmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 19 1.1 jmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 1.1 jmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 21 1.1 jmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 1.1 jmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 1.1 jmcneill * SUCH DAMAGE. 25 1.1 jmcneill * 26 1.1 jmcneill * $FreeBSD$ 27 1.1 jmcneill */ 28 1.1 jmcneill 29 1.1 jmcneill /* 30 1.1 jmcneill * Allwinner Gigabit Ethernet 31 1.1 jmcneill */ 32 1.1 jmcneill 33 1.1 jmcneill #ifndef __SUNXI_EMAC_H__ 34 1.1 jmcneill #define __SUNXI_EMAC_H__ 35 1.1 jmcneill 36 1.1 jmcneill #define EMAC_BASIC_CTL_0 0x00 37 1.1 jmcneill #define BASIC_CTL_SPEED (0x3 << 2) 38 1.1 jmcneill #define BASIC_CTL_SPEED_SHIFT 2 39 1.1 jmcneill #define BASIC_CTL_SPEED_1000 0 40 1.1 jmcneill #define BASIC_CTL_SPEED_10 2 41 1.1 jmcneill #define BASIC_CTL_SPEED_100 3 42 1.1 jmcneill #define BASIC_CTL_LOOPBACK (1 << 1) 43 1.1 jmcneill #define BASIC_CTL_DUPLEX (1 << 0) 44 1.1 jmcneill #define EMAC_BASIC_CTL_1 0x04 45 1.1 jmcneill #define BASIC_CTL_BURST_LEN (0x3f << 24) 46 1.1 jmcneill #define BASIC_CTL_BURST_LEN_SHIFT 24 47 1.1 jmcneill #define BASIC_CTL_RX_TX_PRI (1 << 1) 48 1.1 jmcneill #define BASIC_CTL_SOFT_RST (1 << 0) 49 1.1 jmcneill #define EMAC_INT_STA 0x08 50 1.4 jmcneill #define RGMII_LINK_STA_INT (1 << 16) 51 1.4 jmcneill #define RX_EARLY_INT (1 << 13) 52 1.4 jmcneill #define RX_OVERFLOW_INT (1 << 12) 53 1.4 jmcneill #define RX_TIMEOUT_INT (1 << 11) 54 1.4 jmcneill #define RX_DMA_STOPPED_INT (1 << 10) 55 1.4 jmcneill #define RX_BUF_UA_INT (1 << 9) 56 1.1 jmcneill #define RX_INT (1 << 8) 57 1.4 jmcneill #define TX_EARLY_INT (1 << 5) 58 1.1 jmcneill #define TX_UNDERFLOW_INT (1 << 4) 59 1.4 jmcneill #define TX_TIMEOUT_INT (1 << 3) 60 1.1 jmcneill #define TX_BUF_UA_INT (1 << 2) 61 1.1 jmcneill #define TX_DMA_STOPPED_INT (1 << 1) 62 1.1 jmcneill #define TX_INT (1 << 0) 63 1.1 jmcneill #define EMAC_INT_EN 0x0c 64 1.4 jmcneill #define RX_EARLY_INT_EN (1 << 13) 65 1.4 jmcneill #define RX_OVERFLOW_INT_EN (1 << 12) 66 1.4 jmcneill #define RX_TIMEOUT_INT_EN (1 << 11) 67 1.4 jmcneill #define RX_DMA_STOPPED_INT_EN (1 << 10) 68 1.4 jmcneill #define RX_BUF_UA_INT_EN (1 << 9) 69 1.1 jmcneill #define RX_INT_EN (1 << 8) 70 1.4 jmcneill #define TX_EARLY_INT_EN (1 << 5) 71 1.1 jmcneill #define TX_UNDERFLOW_INT_EN (1 << 4) 72 1.4 jmcneill #define TX_TIMEOUT_INT_EN (1 << 3) 73 1.1 jmcneill #define TX_BUF_UA_INT_EN (1 << 2) 74 1.1 jmcneill #define TX_DMA_STOPPED_INT_EN (1 << 1) 75 1.1 jmcneill #define TX_INT_EN (1 << 0) 76 1.1 jmcneill #define EMAC_TX_CTL_0 0x10 77 1.1 jmcneill #define TX_EN (1 << 31) 78 1.4 jmcneill #define TX_FRM_LEN_CTL (1 << 30) 79 1.1 jmcneill #define EMAC_TX_CTL_1 0x14 80 1.1 jmcneill #define TX_DMA_START (1 << 31) 81 1.1 jmcneill #define TX_DMA_EN (1 << 30) 82 1.4 jmcneill #define TX_TH (0x7 << 8) 83 1.1 jmcneill #define TX_NEXT_FRAME (1 << 2) 84 1.1 jmcneill #define TX_MD (1 << 1) 85 1.1 jmcneill #define FLUSH_TX_FIFO (1 << 0) 86 1.1 jmcneill #define EMAC_TX_FLOW_CTL 0x1c 87 1.1 jmcneill #define PAUSE_TIME (0xffff << 4) 88 1.1 jmcneill #define PAUSE_TIME_SHIFT 4 89 1.1 jmcneill #define TX_FLOW_CTL_EN (1 << 0) 90 1.1 jmcneill #define EMAC_TX_DMA_LIST 0x20 91 1.1 jmcneill #define EMAC_RX_CTL_0 0x24 92 1.1 jmcneill #define RX_EN (1 << 31) 93 1.4 jmcneill #define RX_FRM_LEN_CTL (1 << 30) 94 1.1 jmcneill #define JUMBO_FRM_EN (1 << 29) 95 1.1 jmcneill #define STRIP_FCS (1 << 28) 96 1.1 jmcneill #define CHECK_CRC (1 << 27) 97 1.4 jmcneill #define RX_PAUSE_FRM_MD (1 << 17) 98 1.1 jmcneill #define RX_FLOW_CTL_EN (1 << 16) 99 1.1 jmcneill #define EMAC_RX_CTL_1 0x28 100 1.1 jmcneill #define RX_DMA_START (1 << 31) 101 1.1 jmcneill #define RX_DMA_EN (1 << 30) 102 1.4 jmcneill #define RX_FIFO_FLOW_CTL (1 << 24) 103 1.4 jmcneill #define RX_FLOW_CTL_TH_DEACT (0x3 << 22) 104 1.4 jmcneill #define RX_FLOW_CTL_TH_ACT (0x3 << 20) 105 1.4 jmcneill #define RX_TH (0x3 << 4) 106 1.4 jmcneill #define RX_ERR_FRM (1 << 3) 107 1.4 jmcneill #define RX_RUNT_FRM (1 << 2) 108 1.1 jmcneill #define RX_MD (1 << 1) 109 1.4 jmcneill #define FLUSH_RX_FRM (1 << 0) 110 1.1 jmcneill #define EMAC_RX_DMA_LIST 0x34 111 1.1 jmcneill #define EMAC_RX_FRM_FLT 0x38 112 1.1 jmcneill #define DIS_ADDR_FILTER (1 << 31) 113 1.1 jmcneill #define DIS_BROADCAST (1 << 17) 114 1.1 jmcneill #define RX_ALL_MULTICAST (1 << 16) 115 1.1 jmcneill #define CTL_FRM_FILTER (0x3 << 12) 116 1.1 jmcneill #define CTL_FRM_FILTER_SHIFT 12 117 1.1 jmcneill #define HASH_MULTICAST (1 << 9) 118 1.1 jmcneill #define HASH_UNICAST (1 << 8) 119 1.1 jmcneill #define SA_FILTER_EN (1 << 6) 120 1.1 jmcneill #define SA_INV_FILTER (1 << 5) 121 1.1 jmcneill #define DA_INV_FILTER (1 << 4) 122 1.1 jmcneill #define FLT_MD (1 << 1) 123 1.1 jmcneill #define RX_ALL (1 << 0) 124 1.1 jmcneill #define EMAC_RX_HASH_0 0x40 125 1.1 jmcneill #define EMAC_RX_HASH_1 0x44 126 1.1 jmcneill #define EMAC_MII_CMD 0x48 127 1.1 jmcneill #define MDC_DIV_RATIO_M (0x7 << 20) 128 1.1 jmcneill #define MDC_DIV_RATIO_M_16 0 129 1.1 jmcneill #define MDC_DIV_RATIO_M_32 1 130 1.1 jmcneill #define MDC_DIV_RATIO_M_64 2 131 1.1 jmcneill #define MDC_DIV_RATIO_M_128 3 132 1.1 jmcneill #define MDC_DIV_RATIO_M_SHIFT 20 133 1.1 jmcneill #define PHY_ADDR (0x1f << 12) 134 1.1 jmcneill #define PHY_ADDR_SHIFT 12 135 1.1 jmcneill #define PHY_REG_ADDR (0x1f << 4) 136 1.1 jmcneill #define PHY_REG_ADDR_SHIFT 4 137 1.1 jmcneill #define MII_WR (1 << 1) 138 1.1 jmcneill #define MII_BUSY (1 << 0) 139 1.1 jmcneill #define EMAC_MII_DATA 0x4c 140 1.1 jmcneill #define EMAC_ADDR_HIGH(n) (0x50 + (n) * 8) 141 1.1 jmcneill #define EMAC_ADDR_LOW(n) (0x54 + (n) * 8) 142 1.3 jmcneill #define EMAC_TX_DMA_STA 0xb0 143 1.3 jmcneill #define EMAC_TX_DMA_CUR_DESC 0xb4 144 1.3 jmcneill #define EMAC_TX_DMA_CUR_BUF 0xb8 145 1.1 jmcneill #define EMAC_RX_DMA_STA 0xc0 146 1.1 jmcneill #define EMAC_RX_DMA_CUR_DESC 0xc4 147 1.1 jmcneill #define EMAC_RX_DMA_CUR_BUF 0xc8 148 1.1 jmcneill #define EMAC_RGMII_STA 0xd0 149 1.1 jmcneill 150 1.1 jmcneill struct sunxi_emac_desc { 151 1.1 jmcneill uint32_t status; 152 1.1 jmcneill /* Transmit */ 153 1.1 jmcneill #define TX_DESC_CTL (1 << 31) 154 1.1 jmcneill #define TX_HEADER_ERR (1 << 16) 155 1.1 jmcneill #define TX_LENGTH_ERR (1 << 14) 156 1.1 jmcneill #define TX_PAYLOAD_ERR (1 << 12) 157 1.1 jmcneill #define TX_CRS_ERR (1 << 10) 158 1.1 jmcneill #define TX_COL_ERR_0 (1 << 9) 159 1.1 jmcneill #define TX_COL_ERR_1 (1 << 8) 160 1.1 jmcneill #define TX_COL_CNT (0xf << 3) 161 1.1 jmcneill #define TX_COL_CNT_SHIFT 3 162 1.1 jmcneill #define TX_DEFER_ERR (1 << 2) 163 1.1 jmcneill #define TX_UNDERFLOW_ERR (1 << 1) 164 1.1 jmcneill #define TX_DEFER (1 << 0) 165 1.1 jmcneill /* Receive */ 166 1.1 jmcneill #define RX_DESC_CTL (1 << 31) 167 1.1 jmcneill #define RX_DAF_FAIL (1 << 30) 168 1.1 jmcneill #define RX_FRM_LEN (0x3fff << 16) 169 1.1 jmcneill #define RX_FRM_LEN_SHIFT 16 170 1.1 jmcneill #define RX_NO_ENOUGH_BUF_ERR (1 << 14) 171 1.1 jmcneill #define RX_SAF_FAIL (1 << 13) 172 1.1 jmcneill #define RX_OVERFLOW_ERR (1 << 11) 173 1.1 jmcneill #define RX_FIR_DESC (1 << 9) 174 1.1 jmcneill #define RX_LAST_DESC (1 << 8) 175 1.1 jmcneill #define RX_HEADER_ERR (1 << 7) 176 1.1 jmcneill #define RX_COL_ERR (1 << 6) 177 1.1 jmcneill #define RX_FRM_TYPE (1 << 5) 178 1.1 jmcneill #define RX_LENGTH_ERR (1 << 4) 179 1.1 jmcneill #define RX_PHY_ERR (1 << 3) 180 1.1 jmcneill #define RX_CRC_ERR (1 << 1) 181 1.1 jmcneill #define RX_PAYLOAD_ERR (1 << 0) 182 1.1 jmcneill 183 1.1 jmcneill uint32_t size; 184 1.1 jmcneill /* Transmit */ 185 1.1 jmcneill #define TX_INT_CTL (1 << 31) 186 1.1 jmcneill #define TX_LAST_DESC (1 << 30) 187 1.1 jmcneill #define TX_FIR_DESC (1 << 29) 188 1.1 jmcneill #define TX_CHECKSUM_CTL (0x3 << 27) 189 1.1 jmcneill #define TX_CHECKSUM_CTL_IP 1 190 1.1 jmcneill #define TX_CHECKSUM_CTL_NO_PSE 2 191 1.1 jmcneill #define TX_CHECKSUM_CTL_FULL 3 192 1.1 jmcneill #define TX_CHECKSUM_CTL_SHIFT 27 193 1.1 jmcneill #define TX_CRC_CTL (1 << 26) 194 1.4 jmcneill #define TX_CHAIN_DESC (1 << 24) 195 1.4 jmcneill #define TX_BUF_SIZE (0x7ff << 0) 196 1.1 jmcneill #define TX_BUF_SIZE_SHIFT 0 197 1.1 jmcneill /* Receive */ 198 1.1 jmcneill #define RX_INT_CTL (1 << 31) 199 1.4 jmcneill #define RX_CHAIN_DESC (1 << 24) 200 1.4 jmcneill #define RX_BUF_SIZE (0x7ff << 0) 201 1.1 jmcneill #define RX_BUF_SIZE_SHIFT 0 202 1.1 jmcneill 203 1.1 jmcneill uint32_t addr; 204 1.1 jmcneill 205 1.1 jmcneill uint32_t next; 206 1.5 jmcneill } __packed __aligned(64); 207 1.1 jmcneill 208 1.5 jmcneill __CTASSERT(sizeof(struct sunxi_emac_desc) == 64); 209 1.1 jmcneill 210 1.1 jmcneill #endif /* !__SUNXI_EMAC_H__ */ 211