blob: 6220284798b10e7db57742707392406fc7cd3c2d [file] [log] [blame]
Antoine Tenartf1e37e32018-07-14 13:29:24 +02001/* SPDX-License-Identifier: GPL-2.0 */
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +02002/*
3 * Definitions for Marvell PPv2 network controller for Armada 375 SoC.
4 *
5 * Copyright (C) 2014 Marvell
6 *
7 * Marcin Wojtas <mw@semihalf.com>
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +02008 */
9#ifndef _MVPP2_H_
10#define _MVPP2_H_
11
Antoine Tenartb32b0882018-07-09 17:00:43 +020012#include <linux/interrupt.h>
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +020013#include <linux/kernel.h>
14#include <linux/netdevice.h>
15#include <linux/phy.h>
16#include <linux/phylink.h>
17
18/* Fifo Registers */
19#define MVPP2_RX_DATA_FIFO_SIZE_REG(port) (0x00 + 4 * (port))
20#define MVPP2_RX_ATTR_FIFO_SIZE_REG(port) (0x20 + 4 * (port))
21#define MVPP2_RX_MIN_PKT_SIZE_REG 0x60
22#define MVPP2_RX_FIFO_INIT_REG 0x64
23#define MVPP22_TX_FIFO_THRESH_REG(port) (0x8840 + 4 * (port))
24#define MVPP22_TX_FIFO_SIZE_REG(port) (0x8860 + 4 * (port))
25
26/* RX DMA Top Registers */
27#define MVPP2_RX_CTRL_REG(port) (0x140 + 4 * (port))
28#define MVPP2_RX_LOW_LATENCY_PKT_SIZE(s) (((s) & 0xfff) << 16)
29#define MVPP2_RX_USE_PSEUDO_FOR_CSUM_MASK BIT(31)
30#define MVPP2_POOL_BUF_SIZE_REG(pool) (0x180 + 4 * (pool))
31#define MVPP2_POOL_BUF_SIZE_OFFSET 5
32#define MVPP2_RXQ_CONFIG_REG(rxq) (0x800 + 4 * (rxq))
33#define MVPP2_SNOOP_PKT_SIZE_MASK 0x1ff
34#define MVPP2_SNOOP_BUF_HDR_MASK BIT(9)
35#define MVPP2_RXQ_POOL_SHORT_OFFS 20
36#define MVPP21_RXQ_POOL_SHORT_MASK 0x700000
37#define MVPP22_RXQ_POOL_SHORT_MASK 0xf00000
38#define MVPP2_RXQ_POOL_LONG_OFFS 24
39#define MVPP21_RXQ_POOL_LONG_MASK 0x7000000
40#define MVPP22_RXQ_POOL_LONG_MASK 0xf000000
41#define MVPP2_RXQ_PACKET_OFFSET_OFFS 28
42#define MVPP2_RXQ_PACKET_OFFSET_MASK 0x70000000
43#define MVPP2_RXQ_DISABLE_MASK BIT(31)
44
45/* Top Registers */
46#define MVPP2_MH_REG(port) (0x5040 + 4 * (port))
47#define MVPP2_DSA_EXTENDED BIT(5)
48
49/* Parser Registers */
50#define MVPP2_PRS_INIT_LOOKUP_REG 0x1000
51#define MVPP2_PRS_PORT_LU_MAX 0xf
52#define MVPP2_PRS_PORT_LU_MASK(port) (0xff << ((port) * 4))
53#define MVPP2_PRS_PORT_LU_VAL(port, val) ((val) << ((port) * 4))
54#define MVPP2_PRS_INIT_OFFS_REG(port) (0x1004 + ((port) & 4))
55#define MVPP2_PRS_INIT_OFF_MASK(port) (0x3f << (((port) % 4) * 8))
56#define MVPP2_PRS_INIT_OFF_VAL(port, val) ((val) << (((port) % 4) * 8))
57#define MVPP2_PRS_MAX_LOOP_REG(port) (0x100c + ((port) & 4))
58#define MVPP2_PRS_MAX_LOOP_MASK(port) (0xff << (((port) % 4) * 8))
59#define MVPP2_PRS_MAX_LOOP_VAL(port, val) ((val) << (((port) % 4) * 8))
60#define MVPP2_PRS_TCAM_IDX_REG 0x1100
61#define MVPP2_PRS_TCAM_DATA_REG(idx) (0x1104 + (idx) * 4)
62#define MVPP2_PRS_TCAM_INV_MASK BIT(31)
63#define MVPP2_PRS_SRAM_IDX_REG 0x1200
64#define MVPP2_PRS_SRAM_DATA_REG(idx) (0x1204 + (idx) * 4)
65#define MVPP2_PRS_TCAM_CTRL_REG 0x1230
66#define MVPP2_PRS_TCAM_EN_MASK BIT(0)
Maxime Chevallier12033412018-07-14 13:29:26 +020067#define MVPP2_PRS_TCAM_HIT_IDX_REG 0x1240
68#define MVPP2_PRS_TCAM_HIT_CNT_REG 0x1244
69#define MVPP2_PRS_TCAM_HIT_CNT_MASK GENMASK(15, 0)
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +020070
71/* RSS Registers */
72#define MVPP22_RSS_INDEX 0x1500
73#define MVPP22_RSS_INDEX_TABLE_ENTRY(idx) (idx)
74#define MVPP22_RSS_INDEX_TABLE(idx) ((idx) << 8)
75#define MVPP22_RSS_INDEX_QUEUE(idx) ((idx) << 16)
Maxime Chevallier4b86097b2018-07-12 13:54:18 +020076#define MVPP22_RXQ2RSS_TABLE 0x1504
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +020077#define MVPP22_RSS_TABLE_POINTER(p) (p)
Maxime Chevallier4b86097b2018-07-12 13:54:18 +020078#define MVPP22_RSS_TABLE_ENTRY 0x1508
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +020079#define MVPP22_RSS_WIDTH 0x150c
80
81/* Classifier Registers */
82#define MVPP2_CLS_MODE_REG 0x1800
83#define MVPP2_CLS_MODE_ACTIVE_MASK BIT(0)
84#define MVPP2_CLS_PORT_WAY_REG 0x1810
85#define MVPP2_CLS_PORT_WAY_MASK(port) (1 << (port))
86#define MVPP2_CLS_LKP_INDEX_REG 0x1814
87#define MVPP2_CLS_LKP_INDEX_WAY_OFFS 6
88#define MVPP2_CLS_LKP_TBL_REG 0x1818
89#define MVPP2_CLS_LKP_TBL_RXQ_MASK 0xff
Maxime Chevallierb1a962c2018-07-12 13:54:24 +020090#define MVPP2_CLS_LKP_FLOW_PTR(flow) ((flow) << 16)
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +020091#define MVPP2_CLS_LKP_TBL_LOOKUP_EN_MASK BIT(25)
92#define MVPP2_CLS_FLOW_INDEX_REG 0x1820
93#define MVPP2_CLS_FLOW_TBL0_REG 0x1824
Maxime Chevallierb1a962c2018-07-12 13:54:24 +020094#define MVPP2_CLS_FLOW_TBL0_LAST BIT(0)
95#define MVPP2_CLS_FLOW_TBL0_ENG_MASK 0x7
96#define MVPP2_CLS_FLOW_TBL0_OFFS 1
97#define MVPP2_CLS_FLOW_TBL0_ENG(x) ((x) << 1)
98#define MVPP2_CLS_FLOW_TBL0_PORT_ID_MASK 0xff
99#define MVPP2_CLS_FLOW_TBL0_PORT_ID(port) ((port) << 4)
100#define MVPP2_CLS_FLOW_TBL0_PORT_ID_SEL BIT(23)
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200101#define MVPP2_CLS_FLOW_TBL1_REG 0x1828
Maxime Chevallierb1a962c2018-07-12 13:54:24 +0200102#define MVPP2_CLS_FLOW_TBL1_N_FIELDS_MASK 0x7
103#define MVPP2_CLS_FLOW_TBL1_N_FIELDS(x) (x)
Maxime Chevallier32f1a672019-03-27 09:44:08 +0100104#define MVPP2_CLS_FLOW_TBL1_LU_TYPE(lu) (((lu) & 0x3f) << 3)
Maxime Chevallierb1a962c2018-07-12 13:54:24 +0200105#define MVPP2_CLS_FLOW_TBL1_PRIO_MASK 0x3f
106#define MVPP2_CLS_FLOW_TBL1_PRIO(x) ((x) << 9)
107#define MVPP2_CLS_FLOW_TBL1_SEQ_MASK 0x7
108#define MVPP2_CLS_FLOW_TBL1_SEQ(x) ((x) << 15)
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200109#define MVPP2_CLS_FLOW_TBL2_REG 0x182c
Maxime Chevallierb1a962c2018-07-12 13:54:24 +0200110#define MVPP2_CLS_FLOW_TBL2_FLD_MASK 0x3f
111#define MVPP2_CLS_FLOW_TBL2_FLD_OFFS(n) ((n) * 6)
112#define MVPP2_CLS_FLOW_TBL2_FLD(n, x) ((x) << ((n) * 6))
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200113#define MVPP2_CLS_OVERSIZE_RXQ_LOW_REG(port) (0x1980 + ((port) * 4))
114#define MVPP2_CLS_OVERSIZE_RXQ_LOW_BITS 3
115#define MVPP2_CLS_OVERSIZE_RXQ_LOW_MASK 0x7
116#define MVPP2_CLS_SWFWD_P2HQ_REG(port) (0x19b0 + ((port) * 4))
117#define MVPP2_CLS_SWFWD_PCTRL_REG 0x19d0
118#define MVPP2_CLS_SWFWD_PCTRL_MASK(port) (1 << (port))
119
Maxime Chevallierb1a962c2018-07-12 13:54:24 +0200120/* Classifier C2 engine Registers */
121#define MVPP22_CLS_C2_TCAM_IDX 0x1b00
122#define MVPP22_CLS_C2_TCAM_DATA0 0x1b10
123#define MVPP22_CLS_C2_TCAM_DATA1 0x1b14
124#define MVPP22_CLS_C2_TCAM_DATA2 0x1b18
125#define MVPP22_CLS_C2_TCAM_DATA3 0x1b1c
126#define MVPP22_CLS_C2_TCAM_DATA4 0x1b20
Maxime Chevallier32f1a672019-03-27 09:44:08 +0100127#define MVPP22_CLS_C2_LU_TYPE(lu) ((lu) & 0x3f)
Maxime Chevallierb1a962c2018-07-12 13:54:24 +0200128#define MVPP22_CLS_C2_PORT_ID(port) ((port) << 8)
Maxime Chevallierf9d30d52018-07-14 13:29:28 +0200129#define MVPP22_CLS_C2_HIT_CTR 0x1b50
Maxime Chevallierb1a962c2018-07-12 13:54:24 +0200130#define MVPP22_CLS_C2_ACT 0x1b60
131#define MVPP22_CLS_C2_ACT_RSS_EN(act) (((act) & 0x3) << 19)
132#define MVPP22_CLS_C2_ACT_FWD(act) (((act) & 0x7) << 13)
133#define MVPP22_CLS_C2_ACT_QHIGH(act) (((act) & 0x3) << 11)
134#define MVPP22_CLS_C2_ACT_QLOW(act) (((act) & 0x3) << 9)
135#define MVPP22_CLS_C2_ATTR0 0x1b64
136#define MVPP22_CLS_C2_ATTR0_QHIGH(qh) (((qh) & 0x1f) << 24)
137#define MVPP22_CLS_C2_ATTR0_QHIGH_MASK 0x1f
Maxime Chevallierdba1d912018-07-14 13:29:27 +0200138#define MVPP22_CLS_C2_ATTR0_QHIGH_OFFS 24
Maxime Chevallierb1a962c2018-07-12 13:54:24 +0200139#define MVPP22_CLS_C2_ATTR0_QLOW(ql) (((ql) & 0x7) << 21)
140#define MVPP22_CLS_C2_ATTR0_QLOW_MASK 0x7
Maxime Chevallierdba1d912018-07-14 13:29:27 +0200141#define MVPP22_CLS_C2_ATTR0_QLOW_OFFS 21
Maxime Chevallierb1a962c2018-07-12 13:54:24 +0200142#define MVPP22_CLS_C2_ATTR1 0x1b68
143#define MVPP22_CLS_C2_ATTR2 0x1b6c
144#define MVPP22_CLS_C2_ATTR2_RSS_EN BIT(30)
145#define MVPP22_CLS_C2_ATTR3 0x1b70
146
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200147/* Descriptor Manager Top Registers */
148#define MVPP2_RXQ_NUM_REG 0x2040
149#define MVPP2_RXQ_DESC_ADDR_REG 0x2044
150#define MVPP22_DESC_ADDR_OFFS 8
151#define MVPP2_RXQ_DESC_SIZE_REG 0x2048
152#define MVPP2_RXQ_DESC_SIZE_MASK 0x3ff0
153#define MVPP2_RXQ_STATUS_UPDATE_REG(rxq) (0x3000 + 4 * (rxq))
154#define MVPP2_RXQ_NUM_PROCESSED_OFFSET 0
155#define MVPP2_RXQ_NUM_NEW_OFFSET 16
156#define MVPP2_RXQ_STATUS_REG(rxq) (0x3400 + 4 * (rxq))
157#define MVPP2_RXQ_OCCUPIED_MASK 0x3fff
158#define MVPP2_RXQ_NON_OCCUPIED_OFFSET 16
159#define MVPP2_RXQ_NON_OCCUPIED_MASK 0x3fff0000
160#define MVPP2_RXQ_THRESH_REG 0x204c
161#define MVPP2_OCCUPIED_THRESH_OFFSET 0
162#define MVPP2_OCCUPIED_THRESH_MASK 0x3fff
163#define MVPP2_RXQ_INDEX_REG 0x2050
164#define MVPP2_TXQ_NUM_REG 0x2080
165#define MVPP2_TXQ_DESC_ADDR_REG 0x2084
166#define MVPP2_TXQ_DESC_SIZE_REG 0x2088
167#define MVPP2_TXQ_DESC_SIZE_MASK 0x3ff0
168#define MVPP2_TXQ_THRESH_REG 0x2094
169#define MVPP2_TXQ_THRESH_OFFSET 16
170#define MVPP2_TXQ_THRESH_MASK 0x3fff
171#define MVPP2_AGGR_TXQ_UPDATE_REG 0x2090
172#define MVPP2_TXQ_INDEX_REG 0x2098
173#define MVPP2_TXQ_PREF_BUF_REG 0x209c
174#define MVPP2_PREF_BUF_PTR(desc) ((desc) & 0xfff)
175#define MVPP2_PREF_BUF_SIZE_4 (BIT(12) | BIT(13))
176#define MVPP2_PREF_BUF_SIZE_16 (BIT(12) | BIT(14))
177#define MVPP2_PREF_BUF_THRESH(val) ((val) << 17)
178#define MVPP2_TXQ_DRAIN_EN_MASK BIT(31)
179#define MVPP2_TXQ_PENDING_REG 0x20a0
180#define MVPP2_TXQ_PENDING_MASK 0x3fff
181#define MVPP2_TXQ_INT_STATUS_REG 0x20a4
182#define MVPP2_TXQ_SENT_REG(txq) (0x3c00 + 4 * (txq))
183#define MVPP2_TRANSMITTED_COUNT_OFFSET 16
184#define MVPP2_TRANSMITTED_COUNT_MASK 0x3fff0000
185#define MVPP2_TXQ_RSVD_REQ_REG 0x20b0
186#define MVPP2_TXQ_RSVD_REQ_Q_OFFSET 16
187#define MVPP2_TXQ_RSVD_RSLT_REG 0x20b4
188#define MVPP2_TXQ_RSVD_RSLT_MASK 0x3fff
189#define MVPP2_TXQ_RSVD_CLR_REG 0x20b8
190#define MVPP2_TXQ_RSVD_CLR_OFFSET 16
191#define MVPP2_AGGR_TXQ_DESC_ADDR_REG(cpu) (0x2100 + 4 * (cpu))
192#define MVPP22_AGGR_TXQ_DESC_ADDR_OFFS 8
193#define MVPP2_AGGR_TXQ_DESC_SIZE_REG(cpu) (0x2140 + 4 * (cpu))
194#define MVPP2_AGGR_TXQ_DESC_SIZE_MASK 0x3ff0
195#define MVPP2_AGGR_TXQ_STATUS_REG(cpu) (0x2180 + 4 * (cpu))
196#define MVPP2_AGGR_TXQ_PENDING_MASK 0x3fff
197#define MVPP2_AGGR_TXQ_INDEX_REG(cpu) (0x21c0 + 4 * (cpu))
198
199/* MBUS bridge registers */
200#define MVPP2_WIN_BASE(w) (0x4000 + ((w) << 2))
201#define MVPP2_WIN_SIZE(w) (0x4020 + ((w) << 2))
202#define MVPP2_WIN_REMAP(w) (0x4040 + ((w) << 2))
203#define MVPP2_BASE_ADDR_ENABLE 0x4060
204
205/* AXI Bridge Registers */
206#define MVPP22_AXI_BM_WR_ATTR_REG 0x4100
207#define MVPP22_AXI_BM_RD_ATTR_REG 0x4104
208#define MVPP22_AXI_AGGRQ_DESCR_RD_ATTR_REG 0x4110
209#define MVPP22_AXI_TXQ_DESCR_WR_ATTR_REG 0x4114
210#define MVPP22_AXI_TXQ_DESCR_RD_ATTR_REG 0x4118
211#define MVPP22_AXI_RXQ_DESCR_WR_ATTR_REG 0x411c
212#define MVPP22_AXI_RX_DATA_WR_ATTR_REG 0x4120
213#define MVPP22_AXI_TX_DATA_RD_ATTR_REG 0x4130
214#define MVPP22_AXI_RD_NORMAL_CODE_REG 0x4150
215#define MVPP22_AXI_RD_SNOOP_CODE_REG 0x4154
216#define MVPP22_AXI_WR_NORMAL_CODE_REG 0x4160
217#define MVPP22_AXI_WR_SNOOP_CODE_REG 0x4164
218
219/* Values for AXI Bridge registers */
220#define MVPP22_AXI_ATTR_CACHE_OFFS 0
221#define MVPP22_AXI_ATTR_DOMAIN_OFFS 12
222
223#define MVPP22_AXI_CODE_CACHE_OFFS 0
224#define MVPP22_AXI_CODE_DOMAIN_OFFS 4
225
226#define MVPP22_AXI_CODE_CACHE_NON_CACHE 0x3
227#define MVPP22_AXI_CODE_CACHE_WR_CACHE 0x7
228#define MVPP22_AXI_CODE_CACHE_RD_CACHE 0xb
229
230#define MVPP22_AXI_CODE_DOMAIN_OUTER_DOM 2
231#define MVPP22_AXI_CODE_DOMAIN_SYSTEM 3
232
233/* Interrupt Cause and Mask registers */
234#define MVPP2_ISR_TX_THRESHOLD_REG(port) (0x5140 + 4 * (port))
235#define MVPP2_MAX_ISR_TX_THRESHOLD 0xfffff0
236
237#define MVPP2_ISR_RX_THRESHOLD_REG(rxq) (0x5200 + 4 * (rxq))
238#define MVPP2_MAX_ISR_RX_THRESHOLD 0xfffff0
239#define MVPP21_ISR_RXQ_GROUP_REG(port) (0x5400 + 4 * (port))
240
241#define MVPP22_ISR_RXQ_GROUP_INDEX_REG 0x5400
242#define MVPP22_ISR_RXQ_GROUP_INDEX_SUBGROUP_MASK 0xf
243#define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_MASK 0x380
244#define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_OFFSET 7
245
246#define MVPP22_ISR_RXQ_GROUP_INDEX_SUBGROUP_MASK 0xf
247#define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_MASK 0x380
248
249#define MVPP22_ISR_RXQ_SUB_GROUP_CONFIG_REG 0x5404
250#define MVPP22_ISR_RXQ_SUB_GROUP_STARTQ_MASK 0x1f
251#define MVPP22_ISR_RXQ_SUB_GROUP_SIZE_MASK 0xf00
252#define MVPP22_ISR_RXQ_SUB_GROUP_SIZE_OFFSET 8
253
254#define MVPP2_ISR_ENABLE_REG(port) (0x5420 + 4 * (port))
255#define MVPP2_ISR_ENABLE_INTERRUPT(mask) ((mask) & 0xffff)
256#define MVPP2_ISR_DISABLE_INTERRUPT(mask) (((mask) << 16) & 0xffff0000)
257#define MVPP2_ISR_RX_TX_CAUSE_REG(port) (0x5480 + 4 * (port))
Antoine Tenart70afb582018-09-19 11:27:04 +0200258#define MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK(version) \
259 ((version) == MVPP21 ? 0xffff : 0xff)
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200260#define MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK 0xff0000
261#define MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_OFFSET 16
262#define MVPP2_CAUSE_RX_FIFO_OVERRUN_MASK BIT(24)
263#define MVPP2_CAUSE_FCS_ERR_MASK BIT(25)
264#define MVPP2_CAUSE_TX_FIFO_UNDERRUN_MASK BIT(26)
265#define MVPP2_CAUSE_TX_EXCEPTION_SUM_MASK BIT(29)
266#define MVPP2_CAUSE_RX_EXCEPTION_SUM_MASK BIT(30)
267#define MVPP2_CAUSE_MISC_SUM_MASK BIT(31)
268#define MVPP2_ISR_RX_TX_MASK_REG(port) (0x54a0 + 4 * (port))
269#define MVPP2_ISR_PON_RX_TX_MASK_REG 0x54bc
270#define MVPP2_PON_CAUSE_RXQ_OCCUP_DESC_ALL_MASK 0xffff
271#define MVPP2_PON_CAUSE_TXP_OCCUP_DESC_ALL_MASK 0x3fc00000
272#define MVPP2_PON_CAUSE_MISC_SUM_MASK BIT(31)
273#define MVPP2_ISR_MISC_CAUSE_REG 0x55b0
274
275/* Buffer Manager registers */
276#define MVPP2_BM_POOL_BASE_REG(pool) (0x6000 + ((pool) * 4))
277#define MVPP2_BM_POOL_BASE_ADDR_MASK 0xfffff80
278#define MVPP2_BM_POOL_SIZE_REG(pool) (0x6040 + ((pool) * 4))
279#define MVPP2_BM_POOL_SIZE_MASK 0xfff0
280#define MVPP2_BM_POOL_READ_PTR_REG(pool) (0x6080 + ((pool) * 4))
281#define MVPP2_BM_POOL_GET_READ_PTR_MASK 0xfff0
282#define MVPP2_BM_POOL_PTRS_NUM_REG(pool) (0x60c0 + ((pool) * 4))
283#define MVPP2_BM_POOL_PTRS_NUM_MASK 0xfff0
284#define MVPP2_BM_BPPI_READ_PTR_REG(pool) (0x6100 + ((pool) * 4))
285#define MVPP2_BM_BPPI_PTRS_NUM_REG(pool) (0x6140 + ((pool) * 4))
286#define MVPP2_BM_BPPI_PTR_NUM_MASK 0x7ff
287#define MVPP22_BM_POOL_PTRS_NUM_MASK 0xfff8
288#define MVPP2_BM_BPPI_PREFETCH_FULL_MASK BIT(16)
289#define MVPP2_BM_POOL_CTRL_REG(pool) (0x6200 + ((pool) * 4))
290#define MVPP2_BM_START_MASK BIT(0)
291#define MVPP2_BM_STOP_MASK BIT(1)
292#define MVPP2_BM_STATE_MASK BIT(4)
293#define MVPP2_BM_LOW_THRESH_OFFS 8
294#define MVPP2_BM_LOW_THRESH_MASK 0x7f00
295#define MVPP2_BM_LOW_THRESH_VALUE(val) ((val) << \
296 MVPP2_BM_LOW_THRESH_OFFS)
297#define MVPP2_BM_HIGH_THRESH_OFFS 16
298#define MVPP2_BM_HIGH_THRESH_MASK 0x7f0000
299#define MVPP2_BM_HIGH_THRESH_VALUE(val) ((val) << \
300 MVPP2_BM_HIGH_THRESH_OFFS)
301#define MVPP2_BM_INTR_CAUSE_REG(pool) (0x6240 + ((pool) * 4))
302#define MVPP2_BM_RELEASED_DELAY_MASK BIT(0)
303#define MVPP2_BM_ALLOC_FAILED_MASK BIT(1)
304#define MVPP2_BM_BPPE_EMPTY_MASK BIT(2)
305#define MVPP2_BM_BPPE_FULL_MASK BIT(3)
306#define MVPP2_BM_AVAILABLE_BP_LOW_MASK BIT(4)
307#define MVPP2_BM_INTR_MASK_REG(pool) (0x6280 + ((pool) * 4))
308#define MVPP2_BM_PHY_ALLOC_REG(pool) (0x6400 + ((pool) * 4))
309#define MVPP2_BM_PHY_ALLOC_GRNTD_MASK BIT(0)
310#define MVPP2_BM_VIRT_ALLOC_REG 0x6440
311#define MVPP22_BM_ADDR_HIGH_ALLOC 0x6444
312#define MVPP22_BM_ADDR_HIGH_PHYS_MASK 0xff
313#define MVPP22_BM_ADDR_HIGH_VIRT_MASK 0xff00
314#define MVPP22_BM_ADDR_HIGH_VIRT_SHIFT 8
315#define MVPP2_BM_PHY_RLS_REG(pool) (0x6480 + ((pool) * 4))
316#define MVPP2_BM_PHY_RLS_MC_BUFF_MASK BIT(0)
317#define MVPP2_BM_PHY_RLS_PRIO_EN_MASK BIT(1)
318#define MVPP2_BM_PHY_RLS_GRNTD_MASK BIT(2)
319#define MVPP2_BM_VIRT_RLS_REG 0x64c0
320#define MVPP22_BM_ADDR_HIGH_RLS_REG 0x64c4
321#define MVPP22_BM_ADDR_HIGH_PHYS_RLS_MASK 0xff
322#define MVPP22_BM_ADDR_HIGH_VIRT_RLS_MASK 0xff00
323#define MVPP22_BM_ADDR_HIGH_VIRT_RLS_SHIFT 8
324
Maxime Chevallierf9d30d52018-07-14 13:29:28 +0200325/* Hit counters registers */
326#define MVPP2_CTRS_IDX 0x7040
327#define MVPP2_CLS_DEC_TBL_HIT_CTR 0x7700
328#define MVPP2_CLS_FLOW_TBL_HIT_CTR 0x7704
329
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200330/* TX Scheduler registers */
331#define MVPP2_TXP_SCHED_PORT_INDEX_REG 0x8000
332#define MVPP2_TXP_SCHED_Q_CMD_REG 0x8004
333#define MVPP2_TXP_SCHED_ENQ_MASK 0xff
334#define MVPP2_TXP_SCHED_DISQ_OFFSET 8
335#define MVPP2_TXP_SCHED_CMD_1_REG 0x8010
Maxime Chevallier4251ea52018-09-24 11:11:06 +0200336#define MVPP2_TXP_SCHED_FIXED_PRIO_REG 0x8014
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200337#define MVPP2_TXP_SCHED_PERIOD_REG 0x8018
338#define MVPP2_TXP_SCHED_MTU_REG 0x801c
339#define MVPP2_TXP_MTU_MAX 0x7FFFF
340#define MVPP2_TXP_SCHED_REFILL_REG 0x8020
341#define MVPP2_TXP_REFILL_TOKENS_ALL_MASK 0x7ffff
342#define MVPP2_TXP_REFILL_PERIOD_ALL_MASK 0x3ff00000
343#define MVPP2_TXP_REFILL_PERIOD_MASK(v) ((v) << 20)
344#define MVPP2_TXP_SCHED_TOKEN_SIZE_REG 0x8024
345#define MVPP2_TXP_TOKEN_SIZE_MAX 0xffffffff
346#define MVPP2_TXQ_SCHED_REFILL_REG(q) (0x8040 + ((q) << 2))
347#define MVPP2_TXQ_REFILL_TOKENS_ALL_MASK 0x7ffff
348#define MVPP2_TXQ_REFILL_PERIOD_ALL_MASK 0x3ff00000
349#define MVPP2_TXQ_REFILL_PERIOD_MASK(v) ((v) << 20)
350#define MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(q) (0x8060 + ((q) << 2))
351#define MVPP2_TXQ_TOKEN_SIZE_MAX 0x7fffffff
352#define MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(q) (0x8080 + ((q) << 2))
353#define MVPP2_TXQ_TOKEN_CNTR_MAX 0xffffffff
354
355/* TX general registers */
356#define MVPP2_TX_SNOOP_REG 0x8800
357#define MVPP2_TX_PORT_FLUSH_REG 0x8810
358#define MVPP2_TX_PORT_FLUSH_MASK(port) (1 << (port))
359
360/* LMS registers */
361#define MVPP2_SRC_ADDR_MIDDLE 0x24
362#define MVPP2_SRC_ADDR_HIGH 0x28
363#define MVPP2_PHY_AN_CFG0_REG 0x34
364#define MVPP2_PHY_AN_STOP_SMI0_MASK BIT(7)
365#define MVPP2_MNG_EXTENDED_GLOBAL_CTRL_REG 0x305c
366#define MVPP2_EXT_GLOBAL_CTRL_DEFAULT 0x27
367
368/* Per-port registers */
369#define MVPP2_GMAC_CTRL_0_REG 0x0
370#define MVPP2_GMAC_PORT_EN_MASK BIT(0)
371#define MVPP2_GMAC_PORT_TYPE_MASK BIT(1)
372#define MVPP2_GMAC_MAX_RX_SIZE_OFFS 2
373#define MVPP2_GMAC_MAX_RX_SIZE_MASK 0x7ffc
374#define MVPP2_GMAC_MIB_CNTR_EN_MASK BIT(15)
375#define MVPP2_GMAC_CTRL_1_REG 0x4
376#define MVPP2_GMAC_PERIODIC_XON_EN_MASK BIT(1)
377#define MVPP2_GMAC_GMII_LB_EN_MASK BIT(5)
378#define MVPP2_GMAC_PCS_LB_EN_BIT 6
379#define MVPP2_GMAC_PCS_LB_EN_MASK BIT(6)
380#define MVPP2_GMAC_SA_LOW_OFFS 7
381#define MVPP2_GMAC_CTRL_2_REG 0x8
382#define MVPP2_GMAC_INBAND_AN_MASK BIT(0)
383#define MVPP2_GMAC_FLOW_CTRL_MASK GENMASK(2, 1)
384#define MVPP2_GMAC_PCS_ENABLE_MASK BIT(3)
385#define MVPP2_GMAC_INTERNAL_CLK_MASK BIT(4)
386#define MVPP2_GMAC_DISABLE_PADDING BIT(5)
387#define MVPP2_GMAC_PORT_RESET_MASK BIT(6)
388#define MVPP2_GMAC_AUTONEG_CONFIG 0xc
389#define MVPP2_GMAC_FORCE_LINK_DOWN BIT(0)
390#define MVPP2_GMAC_FORCE_LINK_PASS BIT(1)
391#define MVPP2_GMAC_IN_BAND_AUTONEG BIT(2)
392#define MVPP2_GMAC_IN_BAND_AUTONEG_BYPASS BIT(3)
393#define MVPP2_GMAC_IN_BAND_RESTART_AN BIT(4)
Antoine Tenart0caa7562019-03-01 11:52:05 +0100394#define MVPP2_GMAC_CONFIG_MII_SPEED BIT(5)
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200395#define MVPP2_GMAC_CONFIG_GMII_SPEED BIT(6)
396#define MVPP2_GMAC_AN_SPEED_EN BIT(7)
397#define MVPP2_GMAC_FC_ADV_EN BIT(9)
398#define MVPP2_GMAC_FC_ADV_ASM_EN BIT(10)
399#define MVPP2_GMAC_FLOW_CTRL_AUTONEG BIT(11)
400#define MVPP2_GMAC_CONFIG_FULL_DUPLEX BIT(12)
401#define MVPP2_GMAC_AN_DUPLEX_EN BIT(13)
402#define MVPP2_GMAC_STATUS0 0x10
403#define MVPP2_GMAC_STATUS0_LINK_UP BIT(0)
404#define MVPP2_GMAC_STATUS0_GMII_SPEED BIT(1)
405#define MVPP2_GMAC_STATUS0_MII_SPEED BIT(2)
406#define MVPP2_GMAC_STATUS0_FULL_DUPLEX BIT(3)
Russell King417f3d02019-02-08 15:35:54 +0000407#define MVPP2_GMAC_STATUS0_RX_PAUSE BIT(4)
408#define MVPP2_GMAC_STATUS0_TX_PAUSE BIT(5)
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200409#define MVPP2_GMAC_STATUS0_AN_COMPLETE BIT(11)
410#define MVPP2_GMAC_PORT_FIFO_CFG_1_REG 0x1c
411#define MVPP2_GMAC_TX_FIFO_MIN_TH_OFFS 6
412#define MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK 0x1fc0
413#define MVPP2_GMAC_TX_FIFO_MIN_TH_MASK(v) (((v) << 6) & \
414 MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK)
415#define MVPP22_GMAC_INT_STAT 0x20
416#define MVPP22_GMAC_INT_STAT_LINK BIT(1)
417#define MVPP22_GMAC_INT_MASK 0x24
418#define MVPP22_GMAC_INT_MASK_LINK_STAT BIT(1)
419#define MVPP22_GMAC_CTRL_4_REG 0x90
420#define MVPP22_CTRL4_EXT_PIN_GMII_SEL BIT(0)
421#define MVPP22_CTRL4_RX_FC_EN BIT(3)
422#define MVPP22_CTRL4_TX_FC_EN BIT(4)
423#define MVPP22_CTRL4_DP_CLK_SEL BIT(5)
424#define MVPP22_CTRL4_SYNC_BYPASS_DIS BIT(6)
425#define MVPP22_CTRL4_QSGMII_BYPASS_ACTIVE BIT(7)
426#define MVPP22_GMAC_INT_SUM_MASK 0xa4
427#define MVPP22_GMAC_INT_SUM_MASK_LINK_STAT BIT(1)
428
429/* Per-port XGMAC registers. PPv2.2 only, only for GOP port 0,
430 * relative to port->base.
431 */
432#define MVPP22_XLG_CTRL0_REG 0x100
433#define MVPP22_XLG_CTRL0_PORT_EN BIT(0)
434#define MVPP22_XLG_CTRL0_MAC_RESET_DIS BIT(1)
Antoine Tenart1970ee92019-03-01 11:52:13 +0100435#define MVPP22_XLG_CTRL0_FORCE_LINK_DOWN BIT(2)
436#define MVPP22_XLG_CTRL0_FORCE_LINK_PASS BIT(3)
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200437#define MVPP22_XLG_CTRL0_RX_FLOW_CTRL_EN BIT(7)
438#define MVPP22_XLG_CTRL0_TX_FLOW_CTRL_EN BIT(8)
439#define MVPP22_XLG_CTRL0_MIB_CNT_DIS BIT(14)
440#define MVPP22_XLG_CTRL1_REG 0x104
441#define MVPP22_XLG_CTRL1_FRAMESIZELIMIT_OFFS 0
442#define MVPP22_XLG_CTRL1_FRAMESIZELIMIT_MASK 0x1fff
443#define MVPP22_XLG_STATUS 0x10c
444#define MVPP22_XLG_STATUS_LINK_UP BIT(0)
445#define MVPP22_XLG_INT_STAT 0x114
446#define MVPP22_XLG_INT_STAT_LINK BIT(1)
447#define MVPP22_XLG_INT_MASK 0x118
448#define MVPP22_XLG_INT_MASK_LINK BIT(1)
449#define MVPP22_XLG_CTRL3_REG 0x11c
450#define MVPP22_XLG_CTRL3_MACMODESELECT_MASK (7 << 13)
451#define MVPP22_XLG_CTRL3_MACMODESELECT_GMAC (0 << 13)
452#define MVPP22_XLG_CTRL3_MACMODESELECT_10G (1 << 13)
453#define MVPP22_XLG_EXT_INT_MASK 0x15c
454#define MVPP22_XLG_EXT_INT_MASK_XLG BIT(1)
455#define MVPP22_XLG_EXT_INT_MASK_GIG BIT(2)
456#define MVPP22_XLG_CTRL4_REG 0x184
457#define MVPP22_XLG_CTRL4_FWD_FC BIT(5)
458#define MVPP22_XLG_CTRL4_FWD_PFC BIT(6)
459#define MVPP22_XLG_CTRL4_MACMODSELECT_GMAC BIT(12)
460#define MVPP22_XLG_CTRL4_EN_IDLE_CHECK BIT(14)
461
462/* SMI registers. PPv2.2 only, relative to priv->iface_base. */
463#define MVPP22_SMI_MISC_CFG_REG 0x1204
464#define MVPP22_SMI_POLLING_EN BIT(10)
465
466#define MVPP22_GMAC_BASE(port) (0x7000 + (port) * 0x1000 + 0xe00)
467
468#define MVPP2_CAUSE_TXQ_SENT_DESC_ALL_MASK 0xff
469
470/* Descriptor ring Macros */
471#define MVPP2_QUEUE_NEXT_DESC(q, index) \
472 (((index) < (q)->last_desc) ? ((index) + 1) : 0)
473
474/* XPCS registers. PPv2.2 only */
475#define MVPP22_MPCS_BASE(port) (0x7000 + (port) * 0x1000)
476#define MVPP22_MPCS_CTRL 0x14
477#define MVPP22_MPCS_CTRL_FWD_ERR_CONN BIT(10)
478#define MVPP22_MPCS_CLK_RESET 0x14c
479#define MAC_CLK_RESET_SD_TX BIT(0)
480#define MAC_CLK_RESET_SD_RX BIT(1)
481#define MAC_CLK_RESET_MAC BIT(2)
482#define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4)
483#define MVPP22_MPCS_CLK_RESET_DIV_SET BIT(11)
484
485/* XPCS registers. PPv2.2 only */
486#define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000)
487#define MVPP22_XPCS_CFG0 0x0
Antoine Tenart7409e662019-03-01 11:52:16 +0100488#define MVPP22_XPCS_CFG0_RESET_DIS BIT(0)
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200489#define MVPP22_XPCS_CFG0_PCS_MODE(n) ((n) << 3)
490#define MVPP22_XPCS_CFG0_ACTIVE_LANE(n) ((n) << 5)
491
492/* System controller registers. Accessed through a regmap. */
493#define GENCONF_SOFT_RESET1 0x1108
494#define GENCONF_SOFT_RESET1_GOP BIT(6)
495#define GENCONF_PORT_CTRL0 0x1110
496#define GENCONF_PORT_CTRL0_BUS_WIDTH_SELECT BIT(1)
497#define GENCONF_PORT_CTRL0_RX_DATA_SAMPLE BIT(29)
498#define GENCONF_PORT_CTRL0_CLK_DIV_PHASE_CLR BIT(31)
499#define GENCONF_PORT_CTRL1 0x1114
500#define GENCONF_PORT_CTRL1_EN(p) BIT(p)
501#define GENCONF_PORT_CTRL1_RESET(p) (BIT(p) << 28)
502#define GENCONF_CTRL0 0x1120
503#define GENCONF_CTRL0_PORT0_RGMII BIT(0)
504#define GENCONF_CTRL0_PORT1_RGMII_MII BIT(1)
505#define GENCONF_CTRL0_PORT1_RGMII BIT(2)
506
507/* Various constants */
508
509/* Coalescing */
510#define MVPP2_TXDONE_COAL_PKTS_THRESH 64
511#define MVPP2_TXDONE_HRTIMER_PERIOD_NS 1000000UL
512#define MVPP2_TXDONE_COAL_USEC 1000
513#define MVPP2_RX_COAL_PKTS 32
514#define MVPP2_RX_COAL_USEC 64
515
516/* The two bytes Marvell header. Either contains a special value used
517 * by Marvell switches when a specific hardware mode is enabled (not
518 * supported by this driver) or is filled automatically by zeroes on
519 * the RX side. Those two bytes being at the front of the Ethernet
520 * header, they allow to have the IP header aligned on a 4 bytes
521 * boundary automatically: the hardware skips those two bytes on its
522 * own.
523 */
524#define MVPP2_MH_SIZE 2
525#define MVPP2_ETH_TYPE_LEN 2
526#define MVPP2_PPPOE_HDR_SIZE 8
527#define MVPP2_VLAN_TAG_LEN 4
528#define MVPP2_VLAN_TAG_EDSA_LEN 8
529
530/* Lbtd 802.3 type */
531#define MVPP2_IP_LBDT_TYPE 0xfffa
532
533#define MVPP2_TX_CSUM_MAX_SIZE 9800
534
535/* Timeout constants */
536#define MVPP2_TX_DISABLE_TIMEOUT_MSEC 1000
537#define MVPP2_TX_PENDING_TIMEOUT_MSEC 1000
538
539#define MVPP2_TX_MTU_MAX 0x7ffff
540
541/* Maximum number of T-CONTs of PON port */
542#define MVPP2_MAX_TCONT 16
543
544/* Maximum number of supported ports */
545#define MVPP2_MAX_PORTS 4
546
547/* Maximum number of TXQs used by single port */
548#define MVPP2_MAX_TXQ 8
549
550/* MVPP2_MAX_TSO_SEGS is the maximum number of fragments to allow in the GSO
551 * skb. As we need a maxium of two descriptors per fragments (1 header, 1 data),
552 * multiply this value by two to count the maximum number of skb descs needed.
553 */
554#define MVPP2_MAX_TSO_SEGS 300
555#define MVPP2_MAX_SKB_DESCS (MVPP2_MAX_TSO_SEGS * 2 + MAX_SKB_FRAGS)
556
Antoine Tenart3f136842019-03-01 11:52:09 +0100557/* Max number of RXQs per port */
558#define MVPP2_PORT_MAX_RXQ 32
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200559
560/* Max number of Rx descriptors */
561#define MVPP2_MAX_RXD_MAX 1024
562#define MVPP2_MAX_RXD_DFLT 128
563
564/* Max number of Tx descriptors */
565#define MVPP2_MAX_TXD_MAX 2048
566#define MVPP2_MAX_TXD_DFLT 1024
567
568/* Amount of Tx descriptors that can be reserved at once by CPU */
569#define MVPP2_CPU_DESC_CHUNK 64
570
571/* Max number of Tx descriptors in each aggregated queue */
572#define MVPP2_AGGR_TXQ_SIZE 256
573
574/* Descriptor aligned size */
575#define MVPP2_DESC_ALIGNED_SIZE 32
576
577/* Descriptor alignment mask */
578#define MVPP2_TX_DESC_ALIGN (MVPP2_DESC_ALIGNED_SIZE - 1)
579
580/* RX FIFO constants */
581#define MVPP2_RX_FIFO_PORT_DATA_SIZE_32KB 0x8000
582#define MVPP2_RX_FIFO_PORT_DATA_SIZE_8KB 0x2000
583#define MVPP2_RX_FIFO_PORT_DATA_SIZE_4KB 0x1000
584#define MVPP2_RX_FIFO_PORT_ATTR_SIZE_32KB 0x200
585#define MVPP2_RX_FIFO_PORT_ATTR_SIZE_8KB 0x80
586#define MVPP2_RX_FIFO_PORT_ATTR_SIZE_4KB 0x40
587#define MVPP2_RX_FIFO_PORT_MIN_PKT 0x80
588
589/* TX FIFO constants */
590#define MVPP22_TX_FIFO_DATA_SIZE_10KB 0xa
591#define MVPP22_TX_FIFO_DATA_SIZE_3KB 0x3
592#define MVPP2_TX_FIFO_THRESHOLD_MIN 256
593#define MVPP2_TX_FIFO_THRESHOLD_10KB \
594 (MVPP22_TX_FIFO_DATA_SIZE_10KB * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
595#define MVPP2_TX_FIFO_THRESHOLD_3KB \
596 (MVPP22_TX_FIFO_DATA_SIZE_3KB * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
597
598/* RX buffer constants */
599#define MVPP2_SKB_SHINFO_SIZE \
600 SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
601
602#define MVPP2_RX_PKT_SIZE(mtu) \
603 ALIGN((mtu) + MVPP2_MH_SIZE + MVPP2_VLAN_TAG_LEN + \
604 ETH_HLEN + ETH_FCS_LEN, cache_line_size())
605
606#define MVPP2_RX_BUF_SIZE(pkt_size) ((pkt_size) + NET_SKB_PAD)
607#define MVPP2_RX_TOTAL_SIZE(buf_size) ((buf_size) + MVPP2_SKB_SHINFO_SIZE)
608#define MVPP2_RX_MAX_PKT_SIZE(total_size) \
609 ((total_size) - NET_SKB_PAD - MVPP2_SKB_SHINFO_SIZE)
610
611#define MVPP2_BIT_TO_BYTE(bit) ((bit) / 8)
Maxime Chevallierbd43d1b2018-06-28 14:42:05 +0200612#define MVPP2_BIT_TO_WORD(bit) ((bit) / 32)
613#define MVPP2_BIT_IN_WORD(bit) ((bit) % 32)
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200614
Maxime Chevallier93c25892019-03-27 09:44:09 +0100615#define MVPP2_N_PRS_FLOWS 52
616
Maxime Chevallier0ad2f532018-07-12 13:54:11 +0200617/* RSS constants */
618#define MVPP22_RSS_TABLE_ENTRIES 32
619
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200620/* IPv6 max L3 address size */
621#define MVPP2_MAX_L3_ADDR_SIZE 16
622
623/* Port flags */
624#define MVPP2_F_LOOPBACK BIT(0)
Antoine Tenarta9aac382018-09-19 11:27:01 +0200625#define MVPP2_F_DT_COMPAT BIT(1)
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200626
627/* Marvell tag types */
628enum mvpp2_tag_type {
629 MVPP2_TAG_TYPE_NONE = 0,
630 MVPP2_TAG_TYPE_MH = 1,
631 MVPP2_TAG_TYPE_DSA = 2,
632 MVPP2_TAG_TYPE_EDSA = 3,
633 MVPP2_TAG_TYPE_VLAN = 4,
634 MVPP2_TAG_TYPE_LAST = 5
635};
636
637/* L2 cast enum */
638enum mvpp2_prs_l2_cast {
639 MVPP2_PRS_L2_UNI_CAST,
640 MVPP2_PRS_L2_MULTI_CAST,
641};
642
643/* L3 cast enum */
644enum mvpp2_prs_l3_cast {
645 MVPP2_PRS_L3_UNI_CAST,
646 MVPP2_PRS_L3_MULTI_CAST,
647 MVPP2_PRS_L3_BROAD_CAST
648};
649
650/* BM constants */
651#define MVPP2_BM_JUMBO_BUF_NUM 512
652#define MVPP2_BM_LONG_BUF_NUM 1024
653#define MVPP2_BM_SHORT_BUF_NUM 2048
654#define MVPP2_BM_POOL_SIZE_MAX (16*1024 - MVPP2_BM_POOL_PTR_ALIGN/4)
655#define MVPP2_BM_POOL_PTR_ALIGN 128
656
657/* BM cookie (32 bits) definition */
658#define MVPP2_BM_COOKIE_POOL_OFFS 8
659#define MVPP2_BM_COOKIE_CPU_OFFS 24
660
661#define MVPP2_BM_SHORT_FRAME_SIZE 512
662#define MVPP2_BM_LONG_FRAME_SIZE 2048
663#define MVPP2_BM_JUMBO_FRAME_SIZE 10240
664/* BM short pool packet size
665 * These value assure that for SWF the total number
666 * of bytes allocated for each buffer will be 512
667 */
668#define MVPP2_BM_SHORT_PKT_SIZE MVPP2_RX_MAX_PKT_SIZE(MVPP2_BM_SHORT_FRAME_SIZE)
669#define MVPP2_BM_LONG_PKT_SIZE MVPP2_RX_MAX_PKT_SIZE(MVPP2_BM_LONG_FRAME_SIZE)
670#define MVPP2_BM_JUMBO_PKT_SIZE MVPP2_RX_MAX_PKT_SIZE(MVPP2_BM_JUMBO_FRAME_SIZE)
671
672#define MVPP21_ADDR_SPACE_SZ 0
673#define MVPP22_ADDR_SPACE_SZ SZ_64K
674
Antoine Tenartcf55ace2018-09-19 11:27:00 +0200675#define MVPP2_MAX_THREADS 9
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200676#define MVPP2_MAX_QVECS MVPP2_MAX_THREADS
677
678/* GMAC MIB Counters register definitions */
679#define MVPP21_MIB_COUNTERS_OFFSET 0x1000
680#define MVPP21_MIB_COUNTERS_PORT_SZ 0x400
681#define MVPP22_MIB_COUNTERS_OFFSET 0x0
682#define MVPP22_MIB_COUNTERS_PORT_SZ 0x100
683
684#define MVPP2_MIB_GOOD_OCTETS_RCVD 0x0
685#define MVPP2_MIB_BAD_OCTETS_RCVD 0x8
686#define MVPP2_MIB_CRC_ERRORS_SENT 0xc
687#define MVPP2_MIB_UNICAST_FRAMES_RCVD 0x10
688#define MVPP2_MIB_BROADCAST_FRAMES_RCVD 0x18
689#define MVPP2_MIB_MULTICAST_FRAMES_RCVD 0x1c
690#define MVPP2_MIB_FRAMES_64_OCTETS 0x20
691#define MVPP2_MIB_FRAMES_65_TO_127_OCTETS 0x24
692#define MVPP2_MIB_FRAMES_128_TO_255_OCTETS 0x28
693#define MVPP2_MIB_FRAMES_256_TO_511_OCTETS 0x2c
694#define MVPP2_MIB_FRAMES_512_TO_1023_OCTETS 0x30
695#define MVPP2_MIB_FRAMES_1024_TO_MAX_OCTETS 0x34
696#define MVPP2_MIB_GOOD_OCTETS_SENT 0x38
697#define MVPP2_MIB_UNICAST_FRAMES_SENT 0x40
698#define MVPP2_MIB_MULTICAST_FRAMES_SENT 0x48
699#define MVPP2_MIB_BROADCAST_FRAMES_SENT 0x4c
700#define MVPP2_MIB_FC_SENT 0x54
701#define MVPP2_MIB_FC_RCVD 0x58
702#define MVPP2_MIB_RX_FIFO_OVERRUN 0x5c
703#define MVPP2_MIB_UNDERSIZE_RCVD 0x60
704#define MVPP2_MIB_FRAGMENTS_RCVD 0x64
705#define MVPP2_MIB_OVERSIZE_RCVD 0x68
706#define MVPP2_MIB_JABBER_RCVD 0x6c
707#define MVPP2_MIB_MAC_RCV_ERROR 0x70
708#define MVPP2_MIB_BAD_CRC_EVENT 0x74
709#define MVPP2_MIB_COLLISION 0x78
710#define MVPP2_MIB_LATE_COLLISION 0x7c
711
712#define MVPP2_MIB_COUNTERS_STATS_DELAY (1 * HZ)
713
714#define MVPP2_DESC_DMA_MASK DMA_BIT_MASK(40)
715
716/* Definitions */
717
718/* Shared Packet Processor resources */
719struct mvpp2 {
720 /* Shared registers' base addresses */
721 void __iomem *lms_base;
722 void __iomem *iface_base;
723
724 /* On PPv2.2, each "software thread" can access the base
725 * register through a separate address space, each 64 KB apart
726 * from each other. Typically, such address spaces will be
727 * used per CPU.
728 */
729 void __iomem *swth_base[MVPP2_MAX_THREADS];
730
731 /* On PPv2.2, some port control registers are located into the system
732 * controller space. These registers are accessible through a regmap.
733 */
734 struct regmap *sysctrl_base;
735
736 /* Common clocks */
737 struct clk *pp_clk;
738 struct clk *gop_clk;
739 struct clk *mg_clk;
740 struct clk *mg_core_clk;
741 struct clk *axi_clk;
742
743 /* List of pointers to port structures */
744 int port_count;
745 struct mvpp2_port *port_list[MVPP2_MAX_PORTS];
746
Antoine Tenarte531f762018-09-19 11:27:10 +0200747 /* Number of Tx threads used */
748 unsigned int nthreads;
749 /* Map of threads needing locking */
750 unsigned long lock_map;
751
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200752 /* Aggregated TXQs */
753 struct mvpp2_tx_queue *aggr_txqs;
754
755 /* BM pools */
756 struct mvpp2_bm_pool *bm_pools;
757
758 /* PRS shadow table */
759 struct mvpp2_prs_shadow *prs_shadow;
760 /* PRS auxiliary table for double vlan entries control */
761 bool *prs_double_vlans;
762
763 /* Tclk value */
764 u32 tclk;
765
766 /* HW version */
767 enum { MVPP21, MVPP22 } hw_version;
768
769 /* Maximum number of RXQs per port */
770 unsigned int max_port_rxqs;
771
772 /* Workqueue to gather hardware statistics */
773 char queue_name[30];
774 struct workqueue_struct *stats_queue;
Maxime Chevallier21da57a2018-07-14 13:29:25 +0200775
776 /* Debugfs root entry */
777 struct dentry *dbgfs_dir;
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200778};
779
780struct mvpp2_pcpu_stats {
781 struct u64_stats_sync syncp;
782 u64 rx_packets;
783 u64 rx_bytes;
784 u64 tx_packets;
785 u64 tx_bytes;
786};
787
788/* Per-CPU port control */
789struct mvpp2_port_pcpu {
790 struct hrtimer tx_done_timer;
791 bool timer_scheduled;
792 /* Tasklet for egress finalization */
793 struct tasklet_struct tx_done_tasklet;
794};
795
796struct mvpp2_queue_vector {
797 int irq;
798 struct napi_struct napi;
799 enum { MVPP2_QUEUE_VECTOR_SHARED, MVPP2_QUEUE_VECTOR_PRIVATE } type;
800 int sw_thread_id;
801 u16 sw_thread_mask;
802 int first_rxq;
803 int nrxqs;
804 u32 pending_cause_rx;
805 struct mvpp2_port *port;
Marc Zyngiera6b3a3f2018-10-30 15:41:00 +0000806 struct cpumask *mask;
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200807};
808
809struct mvpp2_port {
810 u8 id;
811
812 /* Index of the port from the "group of ports" complex point
Antoine Tenart31383c02019-03-01 11:52:04 +0100813 * of view. This is specific to PPv2.2.
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200814 */
815 int gop_id;
816
817 int link_irq;
818
819 struct mvpp2 *priv;
820
821 /* Firmware node associated to the port */
822 struct fwnode_handle *fwnode;
823
824 /* Is a PHY always connected to the port */
825 bool has_phy;
826
827 /* Per-port registers' base address */
828 void __iomem *base;
829 void __iomem *stats_base;
830
831 struct mvpp2_rx_queue **rxqs;
832 unsigned int nrxqs;
833 struct mvpp2_tx_queue **txqs;
834 unsigned int ntxqs;
835 struct net_device *dev;
836
837 int pkt_size;
838
839 /* Per-CPU port control */
840 struct mvpp2_port_pcpu __percpu *pcpu;
841
Antoine Tenarte531f762018-09-19 11:27:10 +0200842 /* Protect the BM refills and the Tx paths when a thread is used on more
843 * than a single CPU.
844 */
845 spinlock_t bm_lock[MVPP2_MAX_THREADS];
846 spinlock_t tx_lock[MVPP2_MAX_THREADS];
847
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200848 /* Flags */
849 unsigned long flags;
850
851 u16 tx_ring_size;
852 u16 rx_ring_size;
853 struct mvpp2_pcpu_stats __percpu *stats;
854 u64 *ethtool_stats;
855
856 /* Per-port work and its lock to gather hardware statistics */
857 struct mutex gather_stats_lock;
858 struct delayed_work stats_work;
859
860 struct device_node *of_node;
861
862 phy_interface_t phy_interface;
863 struct phylink *phylink;
864 struct phy *comphy;
865
866 struct mvpp2_bm_pool *pool_long;
867 struct mvpp2_bm_pool *pool_short;
868
869 /* Index of first port's physical RXQ */
870 u8 first_rxq;
871
872 struct mvpp2_queue_vector qvecs[MVPP2_MAX_QVECS];
873 unsigned int nqvecs;
874 bool has_tx_irqs;
875
876 u32 tx_time_coal;
Antoine Tenart81796422018-07-12 13:54:20 +0200877
878 /* RSS indirection table */
879 u32 indir[MVPP22_RSS_TABLE_ENTRIES];
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200880};
881
882/* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the
883 * layout of the transmit and reception DMA descriptors, and their
884 * layout is therefore defined by the hardware design
885 */
886
887#define MVPP2_TXD_L3_OFF_SHIFT 0
888#define MVPP2_TXD_IP_HLEN_SHIFT 8
889#define MVPP2_TXD_L4_CSUM_FRAG BIT(13)
890#define MVPP2_TXD_L4_CSUM_NOT BIT(14)
891#define MVPP2_TXD_IP_CSUM_DISABLE BIT(15)
892#define MVPP2_TXD_PADDING_DISABLE BIT(23)
893#define MVPP2_TXD_L4_UDP BIT(24)
894#define MVPP2_TXD_L3_IP6 BIT(26)
895#define MVPP2_TXD_L_DESC BIT(28)
896#define MVPP2_TXD_F_DESC BIT(29)
897
898#define MVPP2_RXD_ERR_SUMMARY BIT(15)
899#define MVPP2_RXD_ERR_CODE_MASK (BIT(13) | BIT(14))
900#define MVPP2_RXD_ERR_CRC 0x0
901#define MVPP2_RXD_ERR_OVERRUN BIT(13)
902#define MVPP2_RXD_ERR_RESOURCE (BIT(13) | BIT(14))
903#define MVPP2_RXD_BM_POOL_ID_OFFS 16
904#define MVPP2_RXD_BM_POOL_ID_MASK (BIT(16) | BIT(17) | BIT(18))
905#define MVPP2_RXD_HWF_SYNC BIT(21)
906#define MVPP2_RXD_L4_CSUM_OK BIT(22)
907#define MVPP2_RXD_IP4_HEADER_ERR BIT(24)
908#define MVPP2_RXD_L4_TCP BIT(25)
909#define MVPP2_RXD_L4_UDP BIT(26)
910#define MVPP2_RXD_L3_IP4 BIT(28)
911#define MVPP2_RXD_L3_IP6 BIT(30)
912#define MVPP2_RXD_BUF_HDR BIT(31)
913
914/* HW TX descriptor for PPv2.1 */
915struct mvpp21_tx_desc {
Maxime Chevallier7b9c7d72018-06-28 14:42:04 +0200916 __le32 command; /* Options used by HW for packet transmitting.*/
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200917 u8 packet_offset; /* the offset from the buffer beginning */
918 u8 phys_txq; /* destination queue ID */
Maxime Chevallier7b9c7d72018-06-28 14:42:04 +0200919 __le16 data_size; /* data size of transmitted packet in bytes */
920 __le32 buf_dma_addr; /* physical addr of transmitted buffer */
921 __le32 buf_cookie; /* cookie for access to TX buffer in tx path */
922 __le32 reserved1[3]; /* hw_cmd (for future use, BM, PON, PNC) */
923 __le32 reserved2; /* reserved (for future use) */
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200924};
925
926/* HW RX descriptor for PPv2.1 */
927struct mvpp21_rx_desc {
Maxime Chevallier7b9c7d72018-06-28 14:42:04 +0200928 __le32 status; /* info about received packet */
929 __le16 reserved1; /* parser_info (for future use, PnC) */
930 __le16 data_size; /* size of received packet in bytes */
931 __le32 buf_dma_addr; /* physical address of the buffer */
932 __le32 buf_cookie; /* cookie for access to RX buffer in rx path */
933 __le16 reserved2; /* gem_port_id (for future use, PON) */
934 __le16 reserved3; /* csum_l4 (for future use, PnC) */
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200935 u8 reserved4; /* bm_qset (for future use, BM) */
936 u8 reserved5;
Maxime Chevallier7b9c7d72018-06-28 14:42:04 +0200937 __le16 reserved6; /* classify_info (for future use, PnC) */
938 __le32 reserved7; /* flow_id (for future use, PnC) */
939 __le32 reserved8;
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200940};
941
942/* HW TX descriptor for PPv2.2 */
943struct mvpp22_tx_desc {
Maxime Chevallier7b9c7d72018-06-28 14:42:04 +0200944 __le32 command;
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200945 u8 packet_offset;
946 u8 phys_txq;
Maxime Chevallier7b9c7d72018-06-28 14:42:04 +0200947 __le16 data_size;
948 __le64 reserved1;
949 __le64 buf_dma_addr_ptp;
950 __le64 buf_cookie_misc;
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200951};
952
953/* HW RX descriptor for PPv2.2 */
954struct mvpp22_rx_desc {
Maxime Chevallier7b9c7d72018-06-28 14:42:04 +0200955 __le32 status;
956 __le16 reserved1;
957 __le16 data_size;
958 __le32 reserved2;
959 __le32 reserved3;
960 __le64 buf_dma_addr_key_hash;
961 __le64 buf_cookie_misc;
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200962};
963
964/* Opaque type used by the driver to manipulate the HW TX and RX
965 * descriptors
966 */
967struct mvpp2_tx_desc {
968 union {
969 struct mvpp21_tx_desc pp21;
970 struct mvpp22_tx_desc pp22;
971 };
972};
973
974struct mvpp2_rx_desc {
975 union {
976 struct mvpp21_rx_desc pp21;
977 struct mvpp22_rx_desc pp22;
978 };
979};
980
981struct mvpp2_txq_pcpu_buf {
982 /* Transmitted SKB */
983 struct sk_buff *skb;
984
985 /* Physical address of transmitted buffer */
986 dma_addr_t dma;
987
988 /* Size transmitted */
989 size_t size;
990};
991
992/* Per-CPU Tx queue control */
993struct mvpp2_txq_pcpu {
Antoine Tenart074c74d2018-09-19 11:27:09 +0200994 unsigned int thread;
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +0200995
996 /* Number of Tx DMA descriptors in the descriptor ring */
997 int size;
998
999 /* Number of currently used Tx DMA descriptor in the
1000 * descriptor ring
1001 */
1002 int count;
1003
1004 int wake_threshold;
1005 int stop_threshold;
1006
1007 /* Number of Tx DMA descriptors reserved for each CPU */
1008 int reserved_num;
1009
1010 /* Infos about transmitted buffers */
1011 struct mvpp2_txq_pcpu_buf *buffs;
1012
1013 /* Index of last TX DMA descriptor that was inserted */
1014 int txq_put_index;
1015
1016 /* Index of the TX DMA descriptor to be cleaned up */
1017 int txq_get_index;
1018
1019 /* DMA buffer for TSO headers */
1020 char *tso_headers;
1021 dma_addr_t tso_headers_dma;
1022};
1023
1024struct mvpp2_tx_queue {
1025 /* Physical number of this Tx queue */
1026 u8 id;
1027
1028 /* Logical number of this Tx queue */
1029 u8 log_id;
1030
1031 /* Number of Tx DMA descriptors in the descriptor ring */
1032 int size;
1033
1034 /* Number of currently used Tx DMA descriptor in the descriptor ring */
1035 int count;
1036
1037 /* Per-CPU control of physical Tx queues */
1038 struct mvpp2_txq_pcpu __percpu *pcpu;
1039
1040 u32 done_pkts_coal;
1041
1042 /* Virtual address of thex Tx DMA descriptors array */
1043 struct mvpp2_tx_desc *descs;
1044
1045 /* DMA address of the Tx DMA descriptors array */
1046 dma_addr_t descs_dma;
1047
1048 /* Index of the last Tx DMA descriptor */
1049 int last_desc;
1050
1051 /* Index of the next Tx DMA descriptor to process */
1052 int next_desc_to_proc;
1053};
1054
1055struct mvpp2_rx_queue {
1056 /* RX queue number, in the range 0-31 for physical RXQs */
1057 u8 id;
1058
1059 /* Num of rx descriptors in the rx descriptor ring */
1060 int size;
1061
1062 u32 pkts_coal;
1063 u32 time_coal;
1064
1065 /* Virtual address of the RX DMA descriptors array */
1066 struct mvpp2_rx_desc *descs;
1067
1068 /* DMA address of the RX DMA descriptors array */
1069 dma_addr_t descs_dma;
1070
1071 /* Index of the last RX DMA descriptor */
1072 int last_desc;
1073
1074 /* Index of the next RX DMA descriptor to process */
1075 int next_desc_to_proc;
1076
1077 /* ID of port to which physical RXQ is mapped */
1078 int port;
1079
1080 /* Port's logic RXQ number to which physical RXQ is mapped */
1081 int logic_rxq;
1082};
1083
1084struct mvpp2_bm_pool {
1085 /* Pool number in the range 0-7 */
1086 int id;
1087
1088 /* Buffer Pointers Pool External (BPPE) size */
1089 int size;
1090 /* BPPE size in bytes */
1091 int size_bytes;
1092 /* Number of buffers for this pool */
1093 int buf_num;
1094 /* Pool buffer size */
1095 int buf_size;
1096 /* Packet size */
1097 int pkt_size;
1098 int frag_size;
1099
1100 /* BPPE virtual base address */
1101 u32 *virt_addr;
1102 /* BPPE DMA base address */
1103 dma_addr_t dma_addr;
1104
1105 /* Ports using BM pool */
1106 u32 port_map;
1107};
1108
1109#define IS_TSO_HEADER(txq_pcpu, addr) \
1110 ((addr) >= (txq_pcpu)->tso_headers_dma && \
1111 (addr) < (txq_pcpu)->tso_headers_dma + \
1112 (txq_pcpu)->size * TSO_HEADER_SIZE)
1113
1114#define MVPP2_DRIVER_NAME "mvpp2"
1115#define MVPP2_DRIVER_VERSION "1.0"
1116
1117void mvpp2_write(struct mvpp2 *priv, u32 offset, u32 data);
1118u32 mvpp2_read(struct mvpp2 *priv, u32 offset);
1119
Maxime Chevallier21da57a2018-07-14 13:29:25 +02001120void mvpp2_dbgfs_init(struct mvpp2 *priv, const char *name);
1121
1122void mvpp2_dbgfs_cleanup(struct mvpp2 *priv);
1123
Maxime Chevallierdb9d7d32018-05-31 10:07:43 +02001124#endif