00813284ee5aa738d965f4e2f546e689ac43971c
[dpdk.git] / drivers / net / enetc / base / enetc_hw.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018-2020 NXP
3  */
4
5 #ifndef _ENETC_HW_H_
6 #define _ENETC_HW_H_
7 #include <rte_io.h>
8
9 #define BIT(x)          ((uint64_t)1 << ((x)))
10
11 /* ENETC device IDs */
12 #define ENETC_DEV_ID_VF         0xef00
13 #define ENETC_DEV_ID            0xe100
14
15 /* BD RING ALIGNMENT */
16 #define ENETC_BD_RING_ALIGN     128
17
18 /* ENETC register block BAR */
19 #define ENETC_BAR_REGS                  0x0
20
21 /* SI regs, offset: 0h */
22 #define ENETC_SIMR                      0x0
23 #define ENETC_SIMR_EN                   BIT(31)
24
25 #define ENETC_SIPMAR0                   0x80
26 #define ENETC_SIPMAR1                   0x84
27
28 #define ENETC_SICAPR0                   0x900
29 #define ENETC_SICAPR1                   0x904
30
31 #define ENETC_SIMSITRV(n)               (0xB00 + (n) * 0x4)
32 #define ENETC_SIMSIRRV(n)               (0xB80 + (n) * 0x4)
33
34 #define ENETC_SICCAPR                   0x1200
35
36 /* enum for BD type */
37 enum enetc_bdr_type {TX, RX};
38
39 #define ENETC_BDR(type, n, off)         (0x8000 + (type) * 0x100 + (n) * 0x200 \
40                                                         + (off))
41 /* RX BDR reg offsets */
42 #define ENETC_RBMR              0x0 /* RX BDR mode register*/
43 #define ENETC_RBMR_EN           BIT(31)
44
45 #define ENETC_RBSR              0x4  /* Rx BDR status register*/
46 #define ENETC_RBBSR             0x8  /* Rx BDR buffer size register*/
47 #define ENETC_RBCIR             0xc  /* Rx BDR consumer index register*/
48 #define ENETC_RBBAR0            0x10 /* Rx BDR base address register 0 */
49 #define ENETC_RBBAR1            0x14 /* Rx BDR base address register 1*/
50 #define ENETC_RBPIR             0x18 /* Rx BDR producer index register*/
51 #define ENETC_RBLENR            0x20 /* Rx BDR length register*/
52 #define ENETC_RBIER             0xa0 /* Rx BDR interrupt enable register*/
53 #define ENETC_RBIER_RXTIE       BIT(0)
54 #define ENETC_RBIDR             0xa4 /* Rx BDR interrupt detect register*/
55 #define ENETC_RBICIR0           0xa8 /* Rx BDR inetrrupt coalescing register 0*/
56 #define ENETC_RBICIR0_ICEN      BIT(31)
57
58
59 #define ENETC_TBMR      0x0  /* Tx BDR mode register (TBMR) 32 RW */
60 #define ENETC_TBSR      0x4  /* x BDR status register (TBSR) 32 RO */
61 #define ENETC_TBBAR0    0x10 /* Tx BDR base address register 0 (TBBAR0) 32 RW */
62 #define ENETC_TBBAR1    0x14 /* Tx BDR base address register 1 (TBBAR1) 32 RW */
63 #define ENETC_TBCIR     0x18 /* Tx BDR consumer index register (TBCIR) 32 RW */
64 #define ENETC_TBCISR    0x1C /* Tx BDR consumer index shadow register 32 RW */
65 #define ENETC_TBIER     0xA0 /* Tx BDR interrupt enable register 32 RW */
66 #define ENETC_TBIDR     0xA4 /* Tx BDR interrupt detect register 32 RO */
67 #define ENETC_TBICR0    0xA8 /* Tx BDR interrupt coalescing register 0 32 RW */
68 #define ENETC_TBICR1    0xAC /* Tx BDR interrupt coalescing register 1 32 RW */
69 #define ENETC_TBLENR    0x20
70
71 #define ENETC_TBCISR_IDX_MASK           0xffff
72 #define ENETC_TBIER_TXFIE               BIT(1)
73
74 #define ENETC_RTBLENR_LEN(n)            ((n) & ~0x7)
75 #define ENETC_TBMR_EN                   BIT(31)
76
77 /* Port regs, offset: 1_0000h */
78 #define ENETC_PORT_BASE                 0x10000
79 #define ENETC_PMR                       0x00000
80 #define ENETC_PMR_EN                    (BIT(16) | BIT(17) | BIT(18))
81 #define ENETC_PSR                       0x00004 /* RO */
82 #define ENETC_PSIPMR                    0x00018
83 #define ENETC_PSIPMR_SET_UP(n)          (0x1 << (n)) /* n = SI index */
84 #define ENETC_PSIPMR_SET_MP(n)          (0x1 << ((n) + 16))
85 #define ENETC_PSIPMAR0(n)               (0x00100 + (n) * 0x20)
86 #define ENETC_PSIPMAR1(n)               (0x00104 + (n) * 0x20)
87 #define ENETC_PCAPR0                    0x00900
88 #define ENETC_PCAPR1                    0x00904
89 #define ENETC_PM0_RX_FIFO               0x801C
90 #define ENETC_PM0_IF_MODE               0x8300
91 #define ENETC_PM1_IF_MODE               0x9300
92 #define ENETC_PMO_IFM_RG                BIT(2)
93 #define ENETC_PM0_IFM_RLP               (BIT(5) | BIT(11))
94 #define ENETC_PM0_IFM_RGAUTO            (BIT(15) | ENETC_PMO_IFM_RG | BIT(1))
95 #define ENETC_PM0_IFM_XGMII             BIT(12)
96
97 #define ENETC_PV0CFGR(n)                (0x00920 + (n) * 0x10)
98 #define ENETC_PVCFGR_SET_TXBDR(val)     ((val) & 0xff)
99 #define ENETC_PVCFGR_SET_RXBDR(val)     (((val) & 0xff) << 16)
100
101 #define ENETC_PM0_CMD_CFG               0x08008
102 #define ENETC_PM0_TX_EN                 BIT(0)
103 #define ENETC_PM0_RX_EN                 BIT(1)
104 #define ENETC_PM0_CRC                   BIT(6)
105
106 #define ENETC_PAR_PORT_CFG              0x03050
107 #define L3_CKSUM                        BIT(0)
108 #define L4_CKSUM                        BIT(1)
109
110 #define ENETC_PM0_MAXFRM                0x08014
111 #define ENETC_SET_TX_MTU(val)           ((val) << 16)
112 #define ENETC_SET_MAXFRM(val)           ((val) & 0xffff)
113 #define ENETC_PTXMBAR                   0x0608
114 /* n = TC index [0..7] */
115 #define ENETC_PTCMSDUR(n)               (0x2020 + (n) * 4)
116
117 #define ENETC_PM0_STATUS                0x08304
118 #define ENETC_LINK_MODE                 0x0000000000080000ULL
119 #define ENETC_LINK_STATUS               0x0000000000010000ULL
120 #define ENETC_LINK_SPEED_MASK           0x0000000000060000ULL
121 #define ENETC_LINK_SPEED_10M            0x0ULL
122 #define ENETC_LINK_SPEED_100M           0x0000000000020000ULL
123 #define ENETC_LINK_SPEED_1G             0x0000000000040000ULL
124
125 /* Global regs, offset: 2_0000h */
126 #define ENETC_GLOBAL_BASE               0x20000
127 #define ENETC_G_EIPBRR0                 0x00bf8
128 #define ENETC_G_EIPBRR1                 0x00bfc
129
130 /* MAC Counters */
131 /* Config register to reset counters*/
132 #define ENETC_PM0_STAT_CONFIG           0x080E0
133 /* Receive frames counter without error */
134 #define ENETC_PM0_RFRM                  0x08120
135 /* Receive packets counter, good + bad */
136 #define ENETC_PM0_RPKT                  0x08160
137 /* Received octets, good + bad */
138 #define ENETC_PM0_REOCT                 0x08120
139 /* Transmit octets, good + bad */
140 #define ENETC_PM0_TEOCT                 0x08200
141 /* Transmit frames counter without error */
142 #define ENETC_PM0_TFRM                  0x08220
143 /* Transmit packets counter, good + bad */
144 #define ENETC_PM0_TPKT                  0x08260
145 /* Dropped not Truncated packets counter */
146 #define ENETC_PM0_RDRNTP                0x081C8
147 /* Dropped + trucated packets counter */
148 #define ENETC_PM0_RDRP                  0x08158
149 /* Receive packets error counter */
150 #define ENETC_PM0_RERR                  0x08138
151 /* Transmit packets error counter */
152 #define ENETC_PM0_TERR                  0x08238
153
154 /* Stats Reset Bit*/
155 #define ENETC_CLEAR_STATS               BIT(2)
156
157 #define ENETC_G_EPFBLPR(n)              (0xd00 + 4 * (n))
158 #define ENETC_G_EPFBLPR1_XGMII          0x80000000
159
160 /* general register accessors */
161 #define enetc_rd_reg(reg)       rte_read32((void *)(reg))
162 #define enetc_wr_reg(reg, val)  rte_write32((val), (void *)(reg))
163 #define enetc_rd(hw, off)       enetc_rd_reg((size_t)(hw)->reg + (off))
164 #define enetc_wr(hw, off, val)  enetc_wr_reg((size_t)(hw)->reg + (off), val)
165 /* port register accessors - PF only */
166 #define enetc_port_rd(hw, off)  enetc_rd_reg((size_t)(hw)->port + (off))
167 #define enetc_port_wr(hw, off, val) \
168                                 enetc_wr_reg((size_t)(hw)->port + (off), val)
169 /* global register accessors - PF only */
170 #define enetc_global_rd(hw, off) \
171                                 enetc_rd_reg((size_t)(hw)->global + (off))
172 #define enetc_global_wr(hw, off, val) \
173                                 enetc_wr_reg((size_t)(hw)->global + (off), val)
174 /* BDR register accessors, see ENETC_BDR() */
175 #define enetc_bdr_rd(hw, t, n, off) \
176                                 enetc_rd(hw, ENETC_BDR(t, n, off))
177 #define enetc_bdr_wr(hw, t, n, off, val) \
178                                 enetc_wr(hw, ENETC_BDR(t, n, off), val)
179
180 #define enetc_txbdr_rd(hw, n, off) enetc_bdr_rd(hw, TX, n, off)
181 #define enetc_rxbdr_rd(hw, n, off) enetc_bdr_rd(hw, RX, n, off)
182 #define enetc_txbdr_wr(hw, n, off, val) \
183                                 enetc_bdr_wr(hw, TX, n, off, val)
184 #define enetc_rxbdr_wr(hw, n, off, val) \
185                                 enetc_bdr_wr(hw, RX, n, off, val)
186
187 #define ENETC_TX_ADDR(txq, addr) ((void *)((txq)->enetc_txbdr + (addr)))
188
189 #define ENETC_TXBD_FLAGS_IE             BIT(13)
190 #define ENETC_TXBD_FLAGS_F              BIT(15)
191
192 /* ENETC Parsed values (Little Endian) */
193 #define ENETC_PARSE_ERROR               0x8000
194 #define ENETC_PKT_TYPE_ETHER            0x0060
195 #define ENETC_PKT_TYPE_IPV4             0x0000
196 #define ENETC_PKT_TYPE_IPV6             0x0020
197 #define ENETC_PKT_TYPE_IPV4_TCP \
198                         (0x0010 | ENETC_PKT_TYPE_IPV4)
199 #define ENETC_PKT_TYPE_IPV6_TCP \
200                         (0x0010 | ENETC_PKT_TYPE_IPV6)
201 #define ENETC_PKT_TYPE_IPV4_UDP \
202                         (0x0011 | ENETC_PKT_TYPE_IPV4)
203 #define ENETC_PKT_TYPE_IPV6_UDP \
204                         (0x0011 | ENETC_PKT_TYPE_IPV6)
205 #define ENETC_PKT_TYPE_IPV4_SCTP \
206                         (0x0013 | ENETC_PKT_TYPE_IPV4)
207 #define ENETC_PKT_TYPE_IPV6_SCTP \
208                         (0x0013 | ENETC_PKT_TYPE_IPV6)
209 #define ENETC_PKT_TYPE_IPV4_ICMP \
210                         (0x0003 | ENETC_PKT_TYPE_IPV4)
211 #define ENETC_PKT_TYPE_IPV6_ICMP \
212                         (0x0003 | ENETC_PKT_TYPE_IPV6)
213
214 /* PCI device info */
215 struct enetc_hw {
216         void *reg;      /* SI registers, used by all PCI functions */
217         void *port;     /* Port registers, PF only */
218         void *global;   /* IP global registers, PF only */
219 };
220
221 struct enetc_eth_mac_info {
222         uint8_t addr[RTE_ETHER_ADDR_LEN];
223         uint8_t perm_addr[RTE_ETHER_ADDR_LEN];
224         uint8_t get_link_status;
225 };
226
227 struct enetc_eth_hw {
228         struct rte_eth_dev *ndev;
229         struct enetc_hw hw;
230         uint16_t device_id;
231         uint16_t vendor_id;
232         uint8_t revision_id;
233         struct enetc_eth_mac_info mac;
234 };
235
236 /* Transmit Descriptor */
237 struct enetc_tx_desc {
238         uint64_t addr;
239         uint16_t frm_len;
240         uint16_t buf_len;
241         uint32_t flags_errors;
242 };
243
244 /* TX Buffer Descriptors (BD) */
245 struct enetc_tx_bd {
246         uint64_t addr;
247         uint16_t buf_len;
248         uint16_t frm_len;
249         uint16_t err_csum;
250         uint16_t flags;
251 };
252
253 /* RX buffer descriptor */
254 union enetc_rx_bd {
255         struct {
256                 uint64_t addr;
257                 uint8_t reserved[8];
258         } w;
259         struct {
260                 uint16_t inet_csum;
261                 uint16_t parse_summary;
262                 uint32_t rss_hash;
263                 uint16_t buf_len;
264                 uint16_t vlan_opt;
265                 union {
266                         struct {
267                                 uint16_t flags;
268                                 uint16_t error;
269                         };
270                         uint32_t lstatus;
271                 };
272         } r;
273 };
274
275 #endif