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