Robert Marko | ea1b88b | 2024-06-03 14:06:15 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (c) 2020 Sartura Ltd. |
| 4 | * |
| 5 | * Author: Robert Marko <robert.marko@sartura.hr> |
| 6 | * |
| 7 | * Copyright (c) 2021 Toco Technologies FZE <contact@toco.ae> |
| 8 | * Copyright (c) 2021 Gabor Juhos <j4g8y7@gmail.com> |
| 9 | * |
| 10 | * Qualcomm ESS EDMA ethernet driver |
| 11 | */ |
| 12 | |
| 13 | #ifndef _ESSEDMA_ETH_H |
| 14 | #define _ESSEDMA_ETH_H |
| 15 | |
| 16 | #define ESS_PORTS_NUM 6 |
| 17 | |
| 18 | #define ESS_RGMII_CTRL 0x4 |
| 19 | |
| 20 | #define ESS_GLOBAL_FW_CTRL1 0x624 |
| 21 | |
| 22 | #define ESS_PORT0_STATUS 0x7c |
| 23 | #define ESS_PORT_SPEED_MASK GENMASK(1, 0) |
| 24 | #define ESS_PORT_SPEED_1000 3 |
| 25 | #define ESS_PORT_SPEED_100 2 |
| 26 | #define ESS_PORT_SPEED_10 1 |
| 27 | #define ESS_PORT_TXMAC_EN BIT(2) |
| 28 | #define ESS_PORT_RXMAC_EN BIT(3) |
| 29 | #define ESS_PORT_TX_FLOW_EN BIT(4) |
| 30 | #define ESS_PORT_RX_FLOW_EN BIT(5) |
| 31 | #define ESS_PORT_DUPLEX_MODE BIT(6) |
| 32 | |
| 33 | #define ESS_PORT_LOOKUP_CTRL(_p) (0x660 + (_p) * 12) |
| 34 | #define ESS_PORT_LOOP_BACK_EN BIT(21) |
| 35 | #define ESS_PORT_VID_MEM_MASK GENMASK(6, 0) |
| 36 | |
| 37 | #define ESS_PORT_HOL_CTRL0(_p) (0x970 + (_p) * 8) |
| 38 | #define EG_PORT_QUEUE_NUM_MASK GENMASK(29, 24) |
| 39 | |
| 40 | /* Ports 0 and 5 have queues 0-5 |
| 41 | * Ports 1 to 4 have queues 0-3 |
| 42 | */ |
| 43 | #define EG_PRI5_QUEUE_NUM_MASK GENMASK(23, 20) |
| 44 | #define EG_PRI4_QUEUE_NUM_MASK GENMASK(19, 16) |
| 45 | #define EG_PRI3_QUEUE_NUM_MASK GENMASK(15, 12) |
| 46 | #define EG_PRI2_QUEUE_NUM_MASK GENMASK(11, 8) |
| 47 | #define EG_PRI1_QUEUE_NUM_MASK GENMASK(7, 4) |
| 48 | #define EG_PRI0_QUEUE_NUM_MASK GENMASK(3, 0) |
| 49 | |
| 50 | #define ESS_PORT_HOL_CTRL1(_p) (0x974 + (_p) * 8) |
| 51 | #define ESS_ING_BUF_NUM_0_MASK GENMASK(3, 0) |
| 52 | |
| 53 | /* QCA807x PHY registers */ |
| 54 | #define QCA807X_CHIP_CONFIGURATION 0x1f |
| 55 | #define QCA807X_MEDIA_PAGE_SELECT BIT(15) |
| 56 | |
| 57 | #define QCA807X_POWER_DOWN BIT(11) |
| 58 | |
| 59 | #define QCA807X_FUNCTION_CONTROL 0x10 |
| 60 | #define QCA807X_MDI_CROSSOVER_MODE_MASK GENMASK(6, 5) |
| 61 | #define QCA807X_MDI_CROSSOVER_MODE_MANUAL_MDI 0 |
| 62 | #define QCA807X_POLARITY_REVERSAL BIT(1) |
| 63 | |
| 64 | #define QCA807X_PHY_SPECIFIC 0x11 |
| 65 | #define QCA807X_PHY_SPECIFIC_LINK BIT(10) |
| 66 | |
| 67 | #define QCA807X_MMD7_CRC_PACKET_COUNTER 0x8029 |
| 68 | #define QCA807X_MMD7_PACKET_COUNTER_SELFCLR BIT(1) |
| 69 | #define QCA807X_MMD7_CRC_PACKET_COUNTER_EN BIT(0) |
| 70 | #define QCA807X_MMD7_VALID_EGRESS_COUNTER_2 0x802e |
| 71 | |
| 72 | /* PSGMII specific registers */ |
| 73 | #define PSGMIIPHY_VCO_CALIBRATION_CTRL_REGISTER_1 0x9c |
| 74 | #define PSGMIIPHY_VCO_VAL 0x4ada |
| 75 | #define PSGMIIPHY_VCO_RST_VAL 0xada |
| 76 | #define PSGMIIPHY_VCO_CALIBRATION_CTRL_REGISTER_2 0xa0 |
| 77 | |
| 78 | #define PSGMIIPHY_PLL_VCO_RELATED_CTRL 0x78c |
| 79 | #define PSGMIIPHY_PLL_VCO_VAL 0x2803 |
| 80 | |
| 81 | #define RGMII_TCSR_ESS_CFG 0x01953000 |
| 82 | |
| 83 | /* EDMA registers */ |
| 84 | #define IPQ40XX_EDMA_TX_RING_SIZE 8 |
| 85 | #define IPQ40XX_EDMA_RSS_TYPE_NONE 0x1 |
| 86 | |
| 87 | #define EDMA_RSS_TYPE 0 |
| 88 | #define EDMA_TPD_EOP_SHIFT 31 |
| 89 | |
| 90 | /* tpd word 3 bit 18-28 */ |
| 91 | #define EDMA_TPD_PORT_BITMAP_SHIFT 18 |
| 92 | |
| 93 | /* Enable Tx for all ports */ |
| 94 | #define EDMA_PORT_ENABLE_ALL 0x3E |
| 95 | |
| 96 | /* Edma receive consumer index */ |
| 97 | /* x = queue id */ |
| 98 | #define EDMA_REG_RX_SW_CONS_IDX_Q(x) (0x220 + ((x) << 2)) |
| 99 | /* Edma transmit consumer index */ |
| 100 | #define EDMA_REG_TX_SW_CONS_IDX_Q(x) (0x240 + ((x) << 2)) |
| 101 | /* TPD Index Register */ |
| 102 | #define EDMA_REG_TPD_IDX_Q(x) (0x460 + ((x) << 2)) |
| 103 | /* Tx Descriptor Control Register */ |
| 104 | #define EDMA_REG_TPD_RING_SIZE 0x41C |
| 105 | #define EDMA_TPD_RING_SIZE_MASK 0xFFFF |
| 106 | |
| 107 | /* Transmit descriptor base address */ |
| 108 | /* x = queue id */ |
| 109 | #define EDMA_REG_TPD_BASE_ADDR_Q(x) (0x420 + ((x) << 2)) |
| 110 | #define EDMA_TPD_PROD_IDX_MASK GENMASK(15, 0) |
| 111 | #define EDMA_TPD_CONS_IDX_MASK GENMASK(31, 16) |
| 112 | |
| 113 | #define EDMA_REG_TX_SRAM_PART 0x400 |
| 114 | #define EDMA_LOAD_PTR_SHIFT 16 |
| 115 | |
| 116 | /* TXQ Control Register */ |
| 117 | #define EDMA_REG_TXQ_CTRL 0x404 |
| 118 | #define EDMA_TXQ_CTRL_TXQ_EN 0x20 |
| 119 | #define EDMA_TXQ_CTRL_TPD_BURST_EN 0x100 |
| 120 | #define EDMA_TXQ_NUM_TPD_BURST_SHIFT 0 |
| 121 | #define EDMA_TXQ_TXF_BURST_NUM_SHIFT 16 |
| 122 | #define EDMA_TXF_BURST 0x100 |
| 123 | #define EDMA_TPD_BURST 5 |
| 124 | |
| 125 | #define EDMA_REG_TXF_WATER_MARK 0x408 |
| 126 | |
| 127 | /* RSS Indirection Register */ |
| 128 | /* x = No. of indirection table */ |
| 129 | #define EDMA_REG_RSS_IDT(x) (0x840 + ((x) << 2)) |
| 130 | #define EDMA_NUM_IDT 16 |
| 131 | #define EDMA_RSS_IDT_VALUE 0x64206420 |
| 132 | |
| 133 | /* RSS Hash Function Type Register */ |
| 134 | #define EDMA_REG_RSS_TYPE 0x894 |
| 135 | |
| 136 | /* x = queue id */ |
| 137 | #define EDMA_REG_RFD_BASE_ADDR_Q(x) (0x950 + ((x) << 2)) |
| 138 | /* RFD Index Register */ |
| 139 | #define EDMA_RFD_BURST 8 |
| 140 | #define EDMA_RFD_THR 16 |
| 141 | #define EDMA_RFD_LTHR 0 |
| 142 | #define EDMA_REG_RFD_IDX_Q(x) (0x9B0 + ((x) << 2)) |
| 143 | |
| 144 | #define EDMA_RFD_CONS_IDX_MASK GENMASK(27, 16) |
| 145 | |
| 146 | /* Rx Descriptor Control Register */ |
| 147 | #define EDMA_REG_RX_DESC0 0xA10 |
| 148 | #define EDMA_RFD_RING_SIZE_MASK 0xFFF |
| 149 | #define EDMA_RX_BUF_SIZE_MASK 0xFFFF |
| 150 | #define EDMA_RFD_RING_SIZE_SHIFT 0 |
| 151 | #define EDMA_RX_BUF_SIZE_SHIFT 16 |
| 152 | |
| 153 | #define EDMA_REG_RX_DESC1 0xA14 |
| 154 | #define EDMA_RXQ_RFD_BURST_NUM_SHIFT 0 |
| 155 | #define EDMA_RXQ_RFD_PF_THRESH_SHIFT 8 |
| 156 | #define EDMA_RXQ_RFD_LOW_THRESH_SHIFT 16 |
| 157 | |
| 158 | /* RXQ Control Register */ |
| 159 | #define EDMA_REG_RXQ_CTRL 0xA18 |
| 160 | #define EDMA_FIFO_THRESH_128_BYTE 0x0 |
| 161 | #define EDMA_RXQ_CTRL_RMV_VLAN 0x00000002 |
| 162 | #define EDMA_RXQ_CTRL_EN 0x0000FF00 |
| 163 | |
| 164 | /* MAC Control Register */ |
| 165 | #define REG_MAC_CTRL0 0xC20 |
| 166 | #define REG_MAC_CTRL1 0xC24 |
| 167 | |
| 168 | /* Transmit Packet Descriptor */ |
| 169 | struct edma_tpd { |
| 170 | u16 len; /* full packet including CRC */ |
| 171 | u16 svlan_tag; /* vlan tag */ |
| 172 | u32 word1; /* byte 4-7 */ |
| 173 | u32 addr; /* address of buffer */ |
| 174 | u32 word3; /* byte 12 */ |
| 175 | }; |
| 176 | |
| 177 | /* Receive Return Descriptor */ |
| 178 | struct edma_rrd { |
| 179 | u16 rrd0; |
| 180 | u16 rrd1; |
| 181 | u16 rrd2; |
| 182 | u16 rrd3; |
| 183 | u16 rrd4; |
| 184 | u16 rrd5; |
| 185 | u16 rrd6; |
| 186 | u16 rrd7; |
| 187 | } __packed; |
| 188 | |
| 189 | #define EDMA_RRD_SIZE sizeof(struct edma_rrd) |
| 190 | |
| 191 | #define EDMA_RRD7_DESC_VALID BIT(15) |
| 192 | |
| 193 | /* Receive Free Descriptor */ |
| 194 | struct edma_rfd { |
Tom Rini | 5690c25 | 2024-07-25 18:04:16 -0600 | [diff] [blame] | 195 | u32 buffer_addr; /* buffer address */ |
Robert Marko | ea1b88b | 2024-06-03 14:06:15 +0200 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | #endif /* _ESSEDMA_ETH_H */ |