global: Move remaining CONFIG_SYS_* to CFG_SYS_*
[platform/kernel/u-boot.git] / drivers / net / cortina_ni.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2
3 /*
4  * Copyright (C) 2020 Cortina Access Inc.
5  * Author: Aaron Tseng <aaron.tseng@cortina-access.com>
6  *
7  * Ethernet MAC Driver for all supported CAxxxx SoCs
8  */
9
10 #ifndef __CORTINA_NI_H
11 #define __CORTINA_NI_H
12
13 #include <asm/types.h>
14 #include <asm/io.h>
15 #include <config.h>
16
17 #define GE_MAC_INTF_GMII                0x0
18 #define GE_MAC_INTF_MII                 0x1
19 #define GE_MAC_INTF_RGMII_1000          0x2
20 #define GE_MAC_INTF_RGMII_100           0x3
21
22 /* Defines the base and top address in CPU XRA
23  * for packets to cpu instance 0
24  * 0x300 * 8-byte = 6K-byte
25  */
26 #define RX_TOP_ADDR                     0x02FF
27 #define RX_BASE_ADDR                    0x0000
28
29 /* Defines the base and top address in CPU XRAM
30  * for packets from cpu instance 0.
31  * 0x100 * 8-byte = 2K-byte
32  */
33 #define TX_TOP_ADDR                     0x03FF
34 #define TX_BASE_ADDR                    0x0300
35
36 struct port_map_s {
37         u32 phy_addr;
38         u32 port;
39 };
40
41 struct gphy_cal_s {
42         u32 reg_off;
43         u32 value;
44 };
45
46 #if !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
47 struct cortina_ni_priv {
48         u32 ni_xram_base;
49         u32 rx_xram_base_adr;
50         u32 rx_xram_end_adr;
51         u16 rx_xram_start;
52         u16 rx_xram_end;
53         u32 tx_xram_base_adr;
54         u32 tx_xram_end_adr;
55         u16 tx_xram_start;
56         u16 tx_xram_end;
57         u32 valid_port_map;
58         u32 valid_port_num;
59         u32 init_rgmii;
60         u32 gphy_num;
61         struct port_map_s port_map[5];
62         struct gphy_cal_s gphy_values[10];
63         void __iomem *glb_base_addr;
64         void __iomem *per_mdio_base_addr;
65         void __iomem *ni_hv_base_addr;
66
67         struct mii_dev *mdio_bus;
68         struct phy_device *phydev;
69         int phy_interface;
70         int active_port;
71 };
72
73 struct NI_HEADER_X_T {
74         u32 next_link           : 10; /* bits  9: 0 */
75         u32 bytes_valid         :  4; /* bits 13:10 */
76         u32 reserved            : 16; /* bits 29:14 */
77         u32 hdr_a               :  1; /* bits 30:30 */
78         u32 ownership           :  1; /* bits 31:31 */
79 };
80
81 struct NI_PACKET_STATUS {
82         u32 packet_size       : 14; /* bits 13:0 */
83         u32 byte_valid        :  4; /* bits 17:14 */
84         u32 pfc               :  1; /* bits 18:18 */
85         u32 valid             :  1; /* bits 19:19 */
86         u32 drop              :  1; /* bits 20:20 */
87         u32 runt              :  1; /* bits 21:21 */
88         u32 oversize          :  1; /* bits 22:22 */
89         u32 jumbo             :  1; /* bits 23:23 */
90         u32 link_status       :  1; /* bits 24:24 */
91         u32 jabber            :  1; /* bits 25:25 */
92         u32 crc_error         :  1; /* bits 26:26 */
93         u32 pause             :  1; /* bits 27:27 */
94         u32 oam               :  1; /* bits 28:28 */
95         u32 unknown_opcode    :  1; /* bits 29:29 */
96         u32 multicast         :  1; /* bits 30:30 */
97         u32 broadcast         :  1; /* bits 31:31 */
98 };
99
100 struct NI_MDIO_OPER_T {
101         u32 reserved       : 2; /* bits  1:0 */
102         u32 reg_off        : 5; /* bits  6:2 */
103         u32 phy_addr       : 5; /* bits 11:7 */
104         u32 reg_base       : 20; /* bits 31:12 */
105 };
106
107 #define __MDIO_WR_FLAG                          (0)
108 #define __MDIO_RD_FLAG                          (1)
109 #define __MDIO_ACCESS_TIMEOUT                   (1000000)
110 #define CA_MDIO_ADDR_MIN                        (1)
111 #define CA_MDIO_ADDR_MAX                        (31)
112
113 #endif /* !__ASSEMBLER__ */
114
115 /* HW REG */
116 struct NI_HV_GLB_MAC_ADDR_CFG0_t {
117         u32 mac_addr0            : 32; /* bits 31:0 */
118 };
119
120 struct NI_HV_GLB_MAC_ADDR_CFG1_t {
121         u32 mac_addr1            :  8; /* bits 7:0 */
122         u32 rsrvd1               : 24;
123 };
124
125 struct NI_HV_PT_PORT_STATIC_CFG_t {
126         u32 int_cfg              :  4; /* bits 3:0 */
127         u32 phy_mode             :  1; /* bits 4:4 */
128         u32 rmii_clksrc          :  1; /* bits 5:5 */
129         u32 inv_clk_in           :  1; /* bits 6:6 */
130         u32 inv_clk_out          :  1; /* bits 7:7 */
131         u32 inv_rxclk_out        :  1; /* bits 8:8 */
132         u32 tx_use_gefifo        :  1; /* bits 9:9 */
133         u32 smii_tx_stat         :  1; /* bits 10:10 */
134         u32 crs_polarity         :  1; /* bits 11:11 */
135         u32 lpbk_mode            :  2; /* bits 13:12 */
136         u32 gmii_like_half_duplex_en :  1; /* bits 14:14 */
137         u32 sup_tx_to_rx_lpbk_data :  1; /* bits 15:15 */
138         u32 rsrvd1               :  8;
139         u32 mac_addr6            :  8; /* bits 31:24 */
140 };
141
142 struct NI_HV_XRAM_CPUXRAM_CFG_t {
143         u32 rx_0_cpu_pkt_dis     :  1; /* bits 0:0 */
144         u32 rsrvd1               :  8;
145         u32 tx_0_cpu_pkt_dis     :  1; /* bits 9:9 */
146         u32 rsrvd2               :  1;
147         u32 rx_x_drop_err_pkt    :  1; /* bits 11:11 */
148         u32 xram_mgmt_dis_drop_ovsz_pkt :  1; /* bits 12:12 */
149         u32 xram_mgmt_term_large_pkt :  1; /* bits 13:13 */
150         u32 xram_mgmt_promisc_mode :  2; /* bits 15:14 */
151         u32 xram_cntr_debug_mode :  1; /* bits 16:16 */
152         u32 xram_cntr_op_code    :  2; /* bits 18:17 */
153         u32 rsrvd3               :  2;
154         u32 xram_rx_mgmtfifo_srst :  1; /* bits 21:21 */
155         u32 xram_dma_fifo_srst   :  1; /* bits 22:22 */
156         u32 rsrvd4               :  9;
157 };
158
159 struct NI_HV_PT_RXMAC_CFG_t {
160         u32 rx_en                :  1; /* bits 0:0 */
161         u32 rsrvd1               :  7;
162         u32 rx_flow_disable      :  1; /* bits 8:8 */
163         u32 rsrvd2               :  3;
164         u32 rx_flow_to_tx_en     :  1; /* bits 12:12 */
165         u32 rx_pfc_disable       :  1; /* bits 13:13 */
166         u32 rsrvd3               : 15;
167         u32 send_pg_data         :  1; /* bits 29:29 */
168         u32 rsrvd4               :  2;
169 };
170
171 struct NI_HV_PT_TXMAC_CFG_t {
172         u32 tx_en                :  1; /* bits 0:0 */
173         u32 rsrvd1               :  7;
174         u32 mac_crc_calc_en      :  1; /* bits 8:8 */
175         u32 tx_ipg_sel           :  3; /* bits 11:9 */
176         u32 tx_flow_disable      :  1; /* bits 12:12 */
177         u32 tx_drain             :  1; /* bits 13:13 */
178         u32 tx_pfc_disable       :  1; /* bits 14:14 */
179         u32 tx_pau_sel           :  2; /* bits 16:15 */
180         u32 rsrvd2               :  9;
181         u32 tx_auto_xon          :  1; /* bits 26:26 */
182         u32 rsrvd3               :  1;
183         u32 pass_thru_hdr        :  1; /* bits 28:28 */
184         u32 rsrvd4               :  3;
185 };
186
187 struct NI_HV_GLB_INTF_RST_CONFIG_t {
188         u32 intf_rst_p0          :  1; /* bits 0:0 */
189         u32 intf_rst_p1          :  1; /* bits 1:1 */
190         u32 intf_rst_p2          :  1; /* bits 2:2 */
191         u32 intf_rst_p3          :  1; /* bits 3:3 */
192         u32 intf_rst_p4          :  1; /* bits 4:4 */
193         u32 mac_rx_rst_p0        :  1; /* bits 5:5 */
194         u32 mac_rx_rst_p1        :  1; /* bits 6:6 */
195         u32 mac_rx_rst_p2        :  1; /* bits 7:7 */
196         u32 mac_rx_rst_p3        :  1; /* bits 8:8 */
197         u32 mac_rx_rst_p4        :  1; /* bits 9:9 */
198         u32 mac_tx_rst_p0        :  1; /* bits 10:10 */
199         u32 mac_tx_rst_p1        :  1; /* bits 11:11 */
200         u32 mac_tx_rst_p2        :  1; /* bits 12:12 */
201         u32 mac_tx_rst_p3        :  1; /* bits 13:13 */
202         u32 mac_tx_rst_p4        :  1; /* bits 14:14 */
203         u32 port_rst_p5          :  1; /* bits 15:15 */
204         u32 pcs_rst_p6           :  1; /* bits 16:16 */
205         u32 pcs_rst_p7           :  1; /* bits 17:17 */
206         u32 mac_rst_p6           :  1; /* bits 18:18 */
207         u32 mac_rst_p7           :  1; /* bits 19:19 */
208         u32 rsrvd1               : 12;
209 };
210
211 struct NI_HV_GLB_STATIC_CFG_t {
212         u32 port_to_cpu          :  4; /* bits 3:0 */
213         u32 mgmt_pt_to_fe_also   :  1; /* bits 4:4 */
214         u32 txcrc_chk_en         :  1; /* bits 5:5 */
215         u32 p4_rgmii_tx_clk_phase :  2; /* bits 7:6 */
216         u32 p4_rgmii_tx_data_order :  1; /* bits 8:8 */
217         u32 rsrvd1               :  7;
218         u32 rxmib_mode           :  1; /* bits 16:16 */
219         u32 txmib_mode           :  1; /* bits 17:17 */
220         u32 eth_sch_rdy_pkt      :  1; /* bits 18:18 */
221         u32 rsrvd2               :  1;
222         u32 rxaui_mode           :  2; /* bits 21:20 */
223         u32 rxaui_sigdet         :  2; /* bits 23:22 */
224         u32 cnt_op_mode          :  3; /* bits 26:24 */
225         u32 rsrvd3               :  5;
226 };
227
228 struct GLOBAL_BLOCK_RESET_t {
229         u32 reset_ni             :  1; /* bits 0:0 */
230         u32 reset_l2fe           :  1; /* bits 1:1 */
231         u32 reset_l2tm           :  1; /* bits 2:2 */
232         u32 reset_l3fe           :  1; /* bits 3:3 */
233         u32 reset_sdram          :  1; /* bits 4:4 */
234         u32 reset_tqm            :  1; /* bits 5:5 */
235         u32 reset_pcie0          :  1; /* bits 6:6 */
236         u32 reset_pcie1          :  1; /* bits 7:7 */
237         u32 reset_pcie2          :  1; /* bits 8:8 */
238         u32 reset_sata           :  1; /* bits 9:9 */
239         u32 reset_gic400         :  1; /* bits 10:10 */
240         u32 rsrvd1               :  2;
241         u32 reset_usb            :  1; /* bits 13:13 */
242         u32 reset_flash          :  1; /* bits 14:14 */
243         u32 reset_per            :  1; /* bits 15:15 */
244         u32 reset_dma            :  1; /* bits 16:16 */
245         u32 reset_rtc            :  1; /* bits 17:17 */
246         u32 reset_pe0            :  1; /* bits 18:18 */
247         u32 reset_pe1            :  1; /* bits 19:19 */
248         u32 reset_rcpu0          :  1; /* bits 20:20 */
249         u32 reset_rcpu1          :  1; /* bits 21:21 */
250         u32 reset_sadb           :  1; /* bits 22:22 */
251         u32 rsrvd2               :  1;
252         u32 reset_rcrypto        :  1; /* bits 24:24 */
253         u32 reset_ldma           :  1; /* bits 25:25 */
254         u32 reset_fbm            :  1; /* bits 26:26 */
255         u32 reset_eaxi           :  1; /* bits 27:27 */
256         u32 reset_sd             :  1; /* bits 28:28 */
257         u32 reset_otprom         :  1; /* bits 29:29 */
258         u32 rsrvd3               :  2;
259 };
260
261 struct PER_MDIO_ADDR_t {
262         u32 mdio_addr            :  5; /* bits 4:0 */
263         u32 rsrvd1               :  3;
264         u32 mdio_offset          :  5; /* bits 12:8 */
265         u32 rsrvd2               :  2;
266         u32 mdio_rd_wr           :  1; /* bits 15:15 */
267         u32 mdio_st              :  1; /* bits 16:16 */
268         u32 rsrvd3               :  1;
269         u32 mdio_op              :  2; /* bits 19:18 */
270         u32 rsrvd4               : 12;
271 };
272
273 struct PER_MDIO_CTRL_t {
274         u32 mdiodone             :  1; /* bits 0:0 */
275         u32 rsrvd1               :  6;
276         u32 mdiostart            :  1; /* bits 7:7 */
277         u32 rsrvd2               : 24;
278 };
279
280 struct PER_MDIO_RDDATA_t {
281         u32 mdio_rddata          : 16; /* bits 15:0 */
282         u32 rsrvd1               : 16;
283 };
284
285 /* XRAM */
286
287 struct NI_HV_XRAM_CPUXRAM_ADRCFG_RX_t {
288         u32 rx_base_addr         : 10; /* bits 9:0 */
289         u32 rsrvd1               :  6;
290         u32 rx_top_addr          : 10; /* bits 25:16 */
291         u32 rsrvd2               :  6;
292 };
293
294 struct NI_HV_XRAM_CPUXRAM_ADRCFG_TX_0_t {
295         u32 tx_base_addr         : 10; /* bits 9:0 */
296         u32 rsrvd1               :  6;
297         u32 tx_top_addr          : 10; /* bits 25:16 */
298         u32 rsrvd2               :  6;
299 };
300
301 struct NI_HV_XRAM_CPUXRAM_CPU_STA_RX_0_t {
302         u32 pkt_wr_ptr           : 10; /* bits 9:0 */
303         u32 rsrvd1               :  5;
304         u32 int_colsc_thresh_reached :  1; /* bits 15:15 */
305         u32 rsrvd2               : 16;
306 };
307
308 struct NI_HV_XRAM_CPUXRAM_CPU_CFG_RX_0_t {
309         u32 pkt_rd_ptr           : 10; /* bits 9:0 */
310         u32 rsrvd1               : 22;
311 };
312
313 struct NI_HV_XRAM_CPUXRAM_CPU_CFG_TX_0_t {
314         u32 pkt_wr_ptr           : 10; /* bits 9:0 */
315         u32 rsrvd1               : 22;
316 };
317
318 struct GLOBAL_GLOBAL_CONFIG_t {
319         u32 rsrvd1               :  4;
320         u32 wd_reset_subsys_enable :  1; /* bits 4:4 */
321         u32 rsrvd2               :  1;
322         u32 wd_reset_all_blocks  :  1; /* bits 6:6 */
323         u32 wd_reset_remap       :  1; /* bits 7:7 */
324         u32 wd_reset_ext_reset   :  1; /* bits 8:8 */
325         u32 ext_reset            :  1; /* bits 9:9 */
326         u32 cfg_pcie_0_clken     :  1; /* bits 10:10 */
327         u32 cfg_sata_clken       :  1; /* bits 11:11 */
328         u32 cfg_pcie_1_clken     :  1; /* bits 12:12 */
329         u32 rsrvd3               :  1;
330         u32 cfg_pcie_2_clken     :  1; /* bits 14:14 */
331         u32 rsrvd4               :  2;
332         u32 ext_eth_refclk       :  1; /* bits 17:17 */
333         u32 refclk_sel           :  2; /* bits 19:18 */
334         u32 rsrvd5               :  7;
335         u32 l3fe_pd              :  1; /* bits 27:27 */
336         u32 offload0_pd          :  1; /* bits 28:28 */
337         u32 offload1_pd          :  1; /* bits 29:29 */
338         u32 crypto_pd            :  1; /* bits 30:30 */
339         u32 core_pd              :  1; /* bits 31:31 */
340 };
341
342 struct GLOBAL_IO_DRIVE_CONTROL_t {
343         u32 gmac_dp              :  3; /* bits 2:0 */
344         u32 gmac_dn              :  3; /* bits 5:3 */
345         u32 gmac_mode            :  2; /* bits 7:6 */
346         u32 gmac_ds              :  1; /* bits 8:8 */
347         u32 flash_ds             :  1; /* bits 9:9 */
348         u32 nu_ds                :  1; /* bits 10:10 */
349         u32 ssp_ds               :  1; /* bits 11:11 */
350         u32 spi_ds               :  1; /* bits 12:12 */
351         u32 gpio_ds              :  1; /* bits 13:13 */
352         u32 misc_ds              :  1; /* bits 14:14 */
353         u32 eaxi_ds              :  1; /* bits 15:15 */
354         u32 sd_ds                :  8; /* bits 23:16 */
355         u32 rsrvd1               :  8;
356 };
357
358 struct NI_HV_GLB_INIT_DONE_t {
359         u32 rsrvd1               :  1;
360         u32 ni_init_done         :  1; /* bits 1:1 */
361         u32 rsrvd2               : 30;
362 };
363
364 struct NI_HV_PT_PORT_GLB_CFG_t {
365         u32 speed                :  1; /* bits 0:0 */
366         u32 duplex               :  1; /* bits 1:1 */
367         u32 link_status          :  1; /* bits 2:2 */
368         u32 link_stat_mask       :  1; /* bits 3:3 */
369         u32 rsrvd1               :  7;
370         u32 power_dwn_rx         :  1; /* bits 11:11 */
371         u32 power_dwn_tx         :  1; /* bits 12:12 */
372         u32 tx_intf_lp_time      :  1; /* bits 13:13 */
373         u32 rsrvd2               : 18;
374 };
375
376 #define NI_HV_GLB_INIT_DONE_OFFSET                      0x004
377 #define NI_HV_GLB_INTF_RST_CONFIG_OFFSET                0x008
378 #define NI_HV_GLB_STATIC_CFG_OFFSET                     0x00c
379
380 #define NI_HV_PT_PORT_STATIC_CFG_OFFSET                 NI_HV_PT_BASE
381 #define NI_HV_PT_PORT_GLB_CFG_OFFSET                    (0x4 + NI_HV_PT_BASE)
382 #define NI_HV_PT_RXMAC_CFG_OFFSET                       (0x8 + NI_HV_PT_BASE)
383 #define NI_HV_PT_TXMAC_CFG_OFFSET                       (0x14 + NI_HV_PT_BASE)
384
385 #define NI_HV_XRAM_CPUXRAM_ADRCFG_RX_OFFSET             NI_HV_XRAM_BASE
386 #define NI_HV_XRAM_CPUXRAM_ADRCFG_TX_0_OFFSET           (0x4 + NI_HV_XRAM_BASE)
387 #define NI_HV_XRAM_CPUXRAM_CFG_OFFSET                   (0x8 + NI_HV_XRAM_BASE)
388 #define NI_HV_XRAM_CPUXRAM_CPU_CFG_RX_0_OFFSET          (0xc + NI_HV_XRAM_BASE)
389 #define NI_HV_XRAM_CPUXRAM_CPU_STA_RX_0_OFFSET          (0x10 + NI_HV_XRAM_BASE)
390 #define NI_HV_XRAM_CPUXRAM_CPU_CFG_TX_0_OFFSET          (0x24 + NI_HV_XRAM_BASE)
391 #define NI_HV_XRAM_CPUXRAM_CPU_STAT_TX_0_OFFSET         (0x28 + NI_HV_XRAM_BASE)
392
393 #define PER_MDIO_CFG_OFFSET                             0x00
394 #define PER_MDIO_ADDR_OFFSET                            0x04
395 #define PER_MDIO_WRDATA_OFFSET                          0x08
396 #define PER_MDIO_RDDATA_OFFSET                          0x0C
397 #define PER_MDIO_CTRL_OFFSET                            0x10
398
399 #define APB0_NI_HV_PT_STRIDE                            160
400
401 #endif /* __CORTINA_NI_H */