blob: 54d80df1c1ac246b67f7ee950ebcca140087c43a [file] [log] [blame]
Marcin Wojtas3f518502014-07-10 16:52:13 -03001/*
2 * Driver 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
13#include <linux/kernel.h>
14#include <linux/netdevice.h>
15#include <linux/etherdevice.h>
16#include <linux/platform_device.h>
17#include <linux/skbuff.h>
18#include <linux/inetdevice.h>
19#include <linux/mbus.h>
20#include <linux/module.h>
Antoine Ténartf84bf382017-08-22 19:08:27 +020021#include <linux/mfd/syscon.h>
Marcin Wojtas3f518502014-07-10 16:52:13 -030022#include <linux/interrupt.h>
23#include <linux/cpumask.h>
24#include <linux/of.h>
25#include <linux/of_irq.h>
26#include <linux/of_mdio.h>
27#include <linux/of_net.h>
28#include <linux/of_address.h>
Thomas Petazzonifaca9242017-03-07 16:53:06 +010029#include <linux/of_device.h>
Marcin Wojtas3f518502014-07-10 16:52:13 -030030#include <linux/phy.h>
Antoine Tenart542897d2017-08-30 10:29:15 +020031#include <linux/phy/phy.h>
Marcin Wojtas3f518502014-07-10 16:52:13 -030032#include <linux/clk.h>
Marcin Wojtasedc660f2015-08-06 19:00:30 +020033#include <linux/hrtimer.h>
34#include <linux/ktime.h>
Antoine Ténartf84bf382017-08-22 19:08:27 +020035#include <linux/regmap.h>
Marcin Wojtas3f518502014-07-10 16:52:13 -030036#include <uapi/linux/ppp_defs.h>
37#include <net/ip.h>
38#include <net/ipv6.h>
Antoine Ténart186cd4d2017-08-23 09:46:56 +020039#include <net/tso.h>
Marcin Wojtas3f518502014-07-10 16:52:13 -030040
Antoine Tenart7c10f972017-10-30 11:23:29 +010041/* Fifo Registers */
Marcin Wojtas3f518502014-07-10 16:52:13 -030042#define MVPP2_RX_DATA_FIFO_SIZE_REG(port) (0x00 + 4 * (port))
43#define MVPP2_RX_ATTR_FIFO_SIZE_REG(port) (0x20 + 4 * (port))
44#define MVPP2_RX_MIN_PKT_SIZE_REG 0x60
45#define MVPP2_RX_FIFO_INIT_REG 0x64
Antoine Tenart7c10f972017-10-30 11:23:29 +010046#define MVPP22_TX_FIFO_SIZE_REG(port) (0x8860 + 4 * (port))
Marcin Wojtas3f518502014-07-10 16:52:13 -030047
48/* RX DMA Top Registers */
49#define MVPP2_RX_CTRL_REG(port) (0x140 + 4 * (port))
50#define MVPP2_RX_LOW_LATENCY_PKT_SIZE(s) (((s) & 0xfff) << 16)
51#define MVPP2_RX_USE_PSEUDO_FOR_CSUM_MASK BIT(31)
52#define MVPP2_POOL_BUF_SIZE_REG(pool) (0x180 + 4 * (pool))
53#define MVPP2_POOL_BUF_SIZE_OFFSET 5
54#define MVPP2_RXQ_CONFIG_REG(rxq) (0x800 + 4 * (rxq))
55#define MVPP2_SNOOP_PKT_SIZE_MASK 0x1ff
56#define MVPP2_SNOOP_BUF_HDR_MASK BIT(9)
57#define MVPP2_RXQ_POOL_SHORT_OFFS 20
Thomas Petazzoni5eac8922017-03-07 16:53:10 +010058#define MVPP21_RXQ_POOL_SHORT_MASK 0x700000
59#define MVPP22_RXQ_POOL_SHORT_MASK 0xf00000
Marcin Wojtas3f518502014-07-10 16:52:13 -030060#define MVPP2_RXQ_POOL_LONG_OFFS 24
Thomas Petazzoni5eac8922017-03-07 16:53:10 +010061#define MVPP21_RXQ_POOL_LONG_MASK 0x7000000
62#define MVPP22_RXQ_POOL_LONG_MASK 0xf000000
Marcin Wojtas3f518502014-07-10 16:52:13 -030063#define MVPP2_RXQ_PACKET_OFFSET_OFFS 28
64#define MVPP2_RXQ_PACKET_OFFSET_MASK 0x70000000
65#define MVPP2_RXQ_DISABLE_MASK BIT(31)
66
67/* Parser Registers */
68#define MVPP2_PRS_INIT_LOOKUP_REG 0x1000
69#define MVPP2_PRS_PORT_LU_MAX 0xf
70#define MVPP2_PRS_PORT_LU_MASK(port) (0xff << ((port) * 4))
71#define MVPP2_PRS_PORT_LU_VAL(port, val) ((val) << ((port) * 4))
72#define MVPP2_PRS_INIT_OFFS_REG(port) (0x1004 + ((port) & 4))
73#define MVPP2_PRS_INIT_OFF_MASK(port) (0x3f << (((port) % 4) * 8))
74#define MVPP2_PRS_INIT_OFF_VAL(port, val) ((val) << (((port) % 4) * 8))
75#define MVPP2_PRS_MAX_LOOP_REG(port) (0x100c + ((port) & 4))
76#define MVPP2_PRS_MAX_LOOP_MASK(port) (0xff << (((port) % 4) * 8))
77#define MVPP2_PRS_MAX_LOOP_VAL(port, val) ((val) << (((port) % 4) * 8))
78#define MVPP2_PRS_TCAM_IDX_REG 0x1100
79#define MVPP2_PRS_TCAM_DATA_REG(idx) (0x1104 + (idx) * 4)
80#define MVPP2_PRS_TCAM_INV_MASK BIT(31)
81#define MVPP2_PRS_SRAM_IDX_REG 0x1200
82#define MVPP2_PRS_SRAM_DATA_REG(idx) (0x1204 + (idx) * 4)
83#define MVPP2_PRS_TCAM_CTRL_REG 0x1230
84#define MVPP2_PRS_TCAM_EN_MASK BIT(0)
85
Antoine Tenart1d7d15d2017-10-30 11:23:30 +010086/* RSS Registers */
87#define MVPP22_RSS_INDEX 0x1500
88#define MVPP22_RSS_INDEX_TABLE_ENTRY(idx) ((idx) << 8)
89#define MVPP22_RSS_INDEX_TABLE(idx) ((idx) << 8)
90#define MVPP22_RSS_INDEX_QUEUE(idx) ((idx) << 16)
91#define MVPP22_RSS_TABLE_ENTRY 0x1508
92#define MVPP22_RSS_TABLE 0x1510
93#define MVPP22_RSS_TABLE_POINTER(p) (p)
94#define MVPP22_RSS_WIDTH 0x150c
95
Marcin Wojtas3f518502014-07-10 16:52:13 -030096/* Classifier Registers */
97#define MVPP2_CLS_MODE_REG 0x1800
98#define MVPP2_CLS_MODE_ACTIVE_MASK BIT(0)
99#define MVPP2_CLS_PORT_WAY_REG 0x1810
100#define MVPP2_CLS_PORT_WAY_MASK(port) (1 << (port))
101#define MVPP2_CLS_LKP_INDEX_REG 0x1814
102#define MVPP2_CLS_LKP_INDEX_WAY_OFFS 6
103#define MVPP2_CLS_LKP_TBL_REG 0x1818
104#define MVPP2_CLS_LKP_TBL_RXQ_MASK 0xff
105#define MVPP2_CLS_LKP_TBL_LOOKUP_EN_MASK BIT(25)
106#define MVPP2_CLS_FLOW_INDEX_REG 0x1820
107#define MVPP2_CLS_FLOW_TBL0_REG 0x1824
108#define MVPP2_CLS_FLOW_TBL1_REG 0x1828
109#define MVPP2_CLS_FLOW_TBL2_REG 0x182c
110#define MVPP2_CLS_OVERSIZE_RXQ_LOW_REG(port) (0x1980 + ((port) * 4))
111#define MVPP2_CLS_OVERSIZE_RXQ_LOW_BITS 3
112#define MVPP2_CLS_OVERSIZE_RXQ_LOW_MASK 0x7
113#define MVPP2_CLS_SWFWD_P2HQ_REG(port) (0x19b0 + ((port) * 4))
114#define MVPP2_CLS_SWFWD_PCTRL_REG 0x19d0
115#define MVPP2_CLS_SWFWD_PCTRL_MASK(port) (1 << (port))
116
117/* Descriptor Manager Top Registers */
118#define MVPP2_RXQ_NUM_REG 0x2040
119#define MVPP2_RXQ_DESC_ADDR_REG 0x2044
Thomas Petazzonib02f31f2017-03-07 16:53:12 +0100120#define MVPP22_DESC_ADDR_OFFS 8
Marcin Wojtas3f518502014-07-10 16:52:13 -0300121#define MVPP2_RXQ_DESC_SIZE_REG 0x2048
122#define MVPP2_RXQ_DESC_SIZE_MASK 0x3ff0
123#define MVPP2_RXQ_STATUS_UPDATE_REG(rxq) (0x3000 + 4 * (rxq))
124#define MVPP2_RXQ_NUM_PROCESSED_OFFSET 0
125#define MVPP2_RXQ_NUM_NEW_OFFSET 16
126#define MVPP2_RXQ_STATUS_REG(rxq) (0x3400 + 4 * (rxq))
127#define MVPP2_RXQ_OCCUPIED_MASK 0x3fff
128#define MVPP2_RXQ_NON_OCCUPIED_OFFSET 16
129#define MVPP2_RXQ_NON_OCCUPIED_MASK 0x3fff0000
130#define MVPP2_RXQ_THRESH_REG 0x204c
131#define MVPP2_OCCUPIED_THRESH_OFFSET 0
132#define MVPP2_OCCUPIED_THRESH_MASK 0x3fff
133#define MVPP2_RXQ_INDEX_REG 0x2050
134#define MVPP2_TXQ_NUM_REG 0x2080
135#define MVPP2_TXQ_DESC_ADDR_REG 0x2084
136#define MVPP2_TXQ_DESC_SIZE_REG 0x2088
137#define MVPP2_TXQ_DESC_SIZE_MASK 0x3ff0
Thomas Petazzoni213f4282017-08-03 10:42:00 +0200138#define MVPP2_TXQ_THRESH_REG 0x2094
139#define MVPP2_TXQ_THRESH_OFFSET 16
140#define MVPP2_TXQ_THRESH_MASK 0x3fff
Marcin Wojtas3f518502014-07-10 16:52:13 -0300141#define MVPP2_AGGR_TXQ_UPDATE_REG 0x2090
Marcin Wojtas3f518502014-07-10 16:52:13 -0300142#define MVPP2_TXQ_INDEX_REG 0x2098
143#define MVPP2_TXQ_PREF_BUF_REG 0x209c
144#define MVPP2_PREF_BUF_PTR(desc) ((desc) & 0xfff)
145#define MVPP2_PREF_BUF_SIZE_4 (BIT(12) | BIT(13))
146#define MVPP2_PREF_BUF_SIZE_16 (BIT(12) | BIT(14))
147#define MVPP2_PREF_BUF_THRESH(val) ((val) << 17)
148#define MVPP2_TXQ_DRAIN_EN_MASK BIT(31)
149#define MVPP2_TXQ_PENDING_REG 0x20a0
150#define MVPP2_TXQ_PENDING_MASK 0x3fff
151#define MVPP2_TXQ_INT_STATUS_REG 0x20a4
152#define MVPP2_TXQ_SENT_REG(txq) (0x3c00 + 4 * (txq))
153#define MVPP2_TRANSMITTED_COUNT_OFFSET 16
154#define MVPP2_TRANSMITTED_COUNT_MASK 0x3fff0000
155#define MVPP2_TXQ_RSVD_REQ_REG 0x20b0
156#define MVPP2_TXQ_RSVD_REQ_Q_OFFSET 16
157#define MVPP2_TXQ_RSVD_RSLT_REG 0x20b4
158#define MVPP2_TXQ_RSVD_RSLT_MASK 0x3fff
159#define MVPP2_TXQ_RSVD_CLR_REG 0x20b8
160#define MVPP2_TXQ_RSVD_CLR_OFFSET 16
161#define MVPP2_AGGR_TXQ_DESC_ADDR_REG(cpu) (0x2100 + 4 * (cpu))
Thomas Petazzonib02f31f2017-03-07 16:53:12 +0100162#define MVPP22_AGGR_TXQ_DESC_ADDR_OFFS 8
Marcin Wojtas3f518502014-07-10 16:52:13 -0300163#define MVPP2_AGGR_TXQ_DESC_SIZE_REG(cpu) (0x2140 + 4 * (cpu))
164#define MVPP2_AGGR_TXQ_DESC_SIZE_MASK 0x3ff0
165#define MVPP2_AGGR_TXQ_STATUS_REG(cpu) (0x2180 + 4 * (cpu))
166#define MVPP2_AGGR_TXQ_PENDING_MASK 0x3fff
167#define MVPP2_AGGR_TXQ_INDEX_REG(cpu) (0x21c0 + 4 * (cpu))
168
169/* MBUS bridge registers */
170#define MVPP2_WIN_BASE(w) (0x4000 + ((w) << 2))
171#define MVPP2_WIN_SIZE(w) (0x4020 + ((w) << 2))
172#define MVPP2_WIN_REMAP(w) (0x4040 + ((w) << 2))
173#define MVPP2_BASE_ADDR_ENABLE 0x4060
174
Thomas Petazzoni6763ce32017-03-07 16:53:15 +0100175/* AXI Bridge Registers */
176#define MVPP22_AXI_BM_WR_ATTR_REG 0x4100
177#define MVPP22_AXI_BM_RD_ATTR_REG 0x4104
178#define MVPP22_AXI_AGGRQ_DESCR_RD_ATTR_REG 0x4110
179#define MVPP22_AXI_TXQ_DESCR_WR_ATTR_REG 0x4114
180#define MVPP22_AXI_TXQ_DESCR_RD_ATTR_REG 0x4118
181#define MVPP22_AXI_RXQ_DESCR_WR_ATTR_REG 0x411c
182#define MVPP22_AXI_RX_DATA_WR_ATTR_REG 0x4120
183#define MVPP22_AXI_TX_DATA_RD_ATTR_REG 0x4130
184#define MVPP22_AXI_RD_NORMAL_CODE_REG 0x4150
185#define MVPP22_AXI_RD_SNOOP_CODE_REG 0x4154
186#define MVPP22_AXI_WR_NORMAL_CODE_REG 0x4160
187#define MVPP22_AXI_WR_SNOOP_CODE_REG 0x4164
188
189/* Values for AXI Bridge registers */
190#define MVPP22_AXI_ATTR_CACHE_OFFS 0
191#define MVPP22_AXI_ATTR_DOMAIN_OFFS 12
192
193#define MVPP22_AXI_CODE_CACHE_OFFS 0
194#define MVPP22_AXI_CODE_DOMAIN_OFFS 4
195
196#define MVPP22_AXI_CODE_CACHE_NON_CACHE 0x3
197#define MVPP22_AXI_CODE_CACHE_WR_CACHE 0x7
198#define MVPP22_AXI_CODE_CACHE_RD_CACHE 0xb
199
200#define MVPP22_AXI_CODE_DOMAIN_OUTER_DOM 2
201#define MVPP22_AXI_CODE_DOMAIN_SYSTEM 3
202
Marcin Wojtas3f518502014-07-10 16:52:13 -0300203/* Interrupt Cause and Mask registers */
Thomas Petazzoni213f4282017-08-03 10:42:00 +0200204#define MVPP2_ISR_TX_THRESHOLD_REG(port) (0x5140 + 4 * (port))
205#define MVPP2_MAX_ISR_TX_THRESHOLD 0xfffff0
206
Marcin Wojtas3f518502014-07-10 16:52:13 -0300207#define MVPP2_ISR_RX_THRESHOLD_REG(rxq) (0x5200 + 4 * (rxq))
Thomas Petazzoniab426762017-02-21 11:28:04 +0100208#define MVPP2_MAX_ISR_RX_THRESHOLD 0xfffff0
Thomas Petazzonieb1e93a2017-08-03 10:41:55 +0200209#define MVPP21_ISR_RXQ_GROUP_REG(port) (0x5400 + 4 * (port))
Thomas Petazzonia73fef12017-03-07 16:53:16 +0100210
Antoine Ténart81b66302017-08-22 19:08:21 +0200211#define MVPP22_ISR_RXQ_GROUP_INDEX_REG 0x5400
Thomas Petazzonia73fef12017-03-07 16:53:16 +0100212#define MVPP22_ISR_RXQ_GROUP_INDEX_SUBGROUP_MASK 0xf
Antoine Ténart81b66302017-08-22 19:08:21 +0200213#define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_MASK 0x380
214#define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_OFFSET 7
Thomas Petazzonia73fef12017-03-07 16:53:16 +0100215
216#define MVPP22_ISR_RXQ_GROUP_INDEX_SUBGROUP_MASK 0xf
Antoine Ténart81b66302017-08-22 19:08:21 +0200217#define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_MASK 0x380
Thomas Petazzonia73fef12017-03-07 16:53:16 +0100218
Antoine Ténart81b66302017-08-22 19:08:21 +0200219#define MVPP22_ISR_RXQ_SUB_GROUP_CONFIG_REG 0x5404
220#define MVPP22_ISR_RXQ_SUB_GROUP_STARTQ_MASK 0x1f
221#define MVPP22_ISR_RXQ_SUB_GROUP_SIZE_MASK 0xf00
222#define MVPP22_ISR_RXQ_SUB_GROUP_SIZE_OFFSET 8
Thomas Petazzonia73fef12017-03-07 16:53:16 +0100223
Marcin Wojtas3f518502014-07-10 16:52:13 -0300224#define MVPP2_ISR_ENABLE_REG(port) (0x5420 + 4 * (port))
225#define MVPP2_ISR_ENABLE_INTERRUPT(mask) ((mask) & 0xffff)
226#define MVPP2_ISR_DISABLE_INTERRUPT(mask) (((mask) << 16) & 0xffff0000)
227#define MVPP2_ISR_RX_TX_CAUSE_REG(port) (0x5480 + 4 * (port))
228#define MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK 0xffff
229#define MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK 0xff0000
Thomas Petazzoni213f4282017-08-03 10:42:00 +0200230#define MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_OFFSET 16
Marcin Wojtas3f518502014-07-10 16:52:13 -0300231#define MVPP2_CAUSE_RX_FIFO_OVERRUN_MASK BIT(24)
232#define MVPP2_CAUSE_FCS_ERR_MASK BIT(25)
233#define MVPP2_CAUSE_TX_FIFO_UNDERRUN_MASK BIT(26)
234#define MVPP2_CAUSE_TX_EXCEPTION_SUM_MASK BIT(29)
235#define MVPP2_CAUSE_RX_EXCEPTION_SUM_MASK BIT(30)
236#define MVPP2_CAUSE_MISC_SUM_MASK BIT(31)
237#define MVPP2_ISR_RX_TX_MASK_REG(port) (0x54a0 + 4 * (port))
238#define MVPP2_ISR_PON_RX_TX_MASK_REG 0x54bc
239#define MVPP2_PON_CAUSE_RXQ_OCCUP_DESC_ALL_MASK 0xffff
240#define MVPP2_PON_CAUSE_TXP_OCCUP_DESC_ALL_MASK 0x3fc00000
241#define MVPP2_PON_CAUSE_MISC_SUM_MASK BIT(31)
242#define MVPP2_ISR_MISC_CAUSE_REG 0x55b0
243
244/* Buffer Manager registers */
245#define MVPP2_BM_POOL_BASE_REG(pool) (0x6000 + ((pool) * 4))
246#define MVPP2_BM_POOL_BASE_ADDR_MASK 0xfffff80
247#define MVPP2_BM_POOL_SIZE_REG(pool) (0x6040 + ((pool) * 4))
248#define MVPP2_BM_POOL_SIZE_MASK 0xfff0
249#define MVPP2_BM_POOL_READ_PTR_REG(pool) (0x6080 + ((pool) * 4))
250#define MVPP2_BM_POOL_GET_READ_PTR_MASK 0xfff0
251#define MVPP2_BM_POOL_PTRS_NUM_REG(pool) (0x60c0 + ((pool) * 4))
252#define MVPP2_BM_POOL_PTRS_NUM_MASK 0xfff0
253#define MVPP2_BM_BPPI_READ_PTR_REG(pool) (0x6100 + ((pool) * 4))
254#define MVPP2_BM_BPPI_PTRS_NUM_REG(pool) (0x6140 + ((pool) * 4))
255#define MVPP2_BM_BPPI_PTR_NUM_MASK 0x7ff
256#define MVPP2_BM_BPPI_PREFETCH_FULL_MASK BIT(16)
257#define MVPP2_BM_POOL_CTRL_REG(pool) (0x6200 + ((pool) * 4))
258#define MVPP2_BM_START_MASK BIT(0)
259#define MVPP2_BM_STOP_MASK BIT(1)
260#define MVPP2_BM_STATE_MASK BIT(4)
261#define MVPP2_BM_LOW_THRESH_OFFS 8
262#define MVPP2_BM_LOW_THRESH_MASK 0x7f00
263#define MVPP2_BM_LOW_THRESH_VALUE(val) ((val) << \
264 MVPP2_BM_LOW_THRESH_OFFS)
265#define MVPP2_BM_HIGH_THRESH_OFFS 16
266#define MVPP2_BM_HIGH_THRESH_MASK 0x7f0000
267#define MVPP2_BM_HIGH_THRESH_VALUE(val) ((val) << \
268 MVPP2_BM_HIGH_THRESH_OFFS)
269#define MVPP2_BM_INTR_CAUSE_REG(pool) (0x6240 + ((pool) * 4))
270#define MVPP2_BM_RELEASED_DELAY_MASK BIT(0)
271#define MVPP2_BM_ALLOC_FAILED_MASK BIT(1)
272#define MVPP2_BM_BPPE_EMPTY_MASK BIT(2)
273#define MVPP2_BM_BPPE_FULL_MASK BIT(3)
274#define MVPP2_BM_AVAILABLE_BP_LOW_MASK BIT(4)
275#define MVPP2_BM_INTR_MASK_REG(pool) (0x6280 + ((pool) * 4))
276#define MVPP2_BM_PHY_ALLOC_REG(pool) (0x6400 + ((pool) * 4))
277#define MVPP2_BM_PHY_ALLOC_GRNTD_MASK BIT(0)
278#define MVPP2_BM_VIRT_ALLOC_REG 0x6440
Thomas Petazzonid01524d2017-03-07 16:53:09 +0100279#define MVPP22_BM_ADDR_HIGH_ALLOC 0x6444
280#define MVPP22_BM_ADDR_HIGH_PHYS_MASK 0xff
281#define MVPP22_BM_ADDR_HIGH_VIRT_MASK 0xff00
282#define MVPP22_BM_ADDR_HIGH_VIRT_SHIFT 8
Marcin Wojtas3f518502014-07-10 16:52:13 -0300283#define MVPP2_BM_PHY_RLS_REG(pool) (0x6480 + ((pool) * 4))
284#define MVPP2_BM_PHY_RLS_MC_BUFF_MASK BIT(0)
285#define MVPP2_BM_PHY_RLS_PRIO_EN_MASK BIT(1)
286#define MVPP2_BM_PHY_RLS_GRNTD_MASK BIT(2)
287#define MVPP2_BM_VIRT_RLS_REG 0x64c0
Thomas Petazzonid01524d2017-03-07 16:53:09 +0100288#define MVPP22_BM_ADDR_HIGH_RLS_REG 0x64c4
289#define MVPP22_BM_ADDR_HIGH_PHYS_RLS_MASK 0xff
Antoine Ténart81b66302017-08-22 19:08:21 +0200290#define MVPP22_BM_ADDR_HIGH_VIRT_RLS_MASK 0xff00
Thomas Petazzonid01524d2017-03-07 16:53:09 +0100291#define MVPP22_BM_ADDR_HIGH_VIRT_RLS_SHIFT 8
Marcin Wojtas3f518502014-07-10 16:52:13 -0300292
293/* TX Scheduler registers */
294#define MVPP2_TXP_SCHED_PORT_INDEX_REG 0x8000
295#define MVPP2_TXP_SCHED_Q_CMD_REG 0x8004
296#define MVPP2_TXP_SCHED_ENQ_MASK 0xff
297#define MVPP2_TXP_SCHED_DISQ_OFFSET 8
298#define MVPP2_TXP_SCHED_CMD_1_REG 0x8010
299#define MVPP2_TXP_SCHED_PERIOD_REG 0x8018
300#define MVPP2_TXP_SCHED_MTU_REG 0x801c
301#define MVPP2_TXP_MTU_MAX 0x7FFFF
302#define MVPP2_TXP_SCHED_REFILL_REG 0x8020
303#define MVPP2_TXP_REFILL_TOKENS_ALL_MASK 0x7ffff
304#define MVPP2_TXP_REFILL_PERIOD_ALL_MASK 0x3ff00000
305#define MVPP2_TXP_REFILL_PERIOD_MASK(v) ((v) << 20)
306#define MVPP2_TXP_SCHED_TOKEN_SIZE_REG 0x8024
307#define MVPP2_TXP_TOKEN_SIZE_MAX 0xffffffff
308#define MVPP2_TXQ_SCHED_REFILL_REG(q) (0x8040 + ((q) << 2))
309#define MVPP2_TXQ_REFILL_TOKENS_ALL_MASK 0x7ffff
310#define MVPP2_TXQ_REFILL_PERIOD_ALL_MASK 0x3ff00000
311#define MVPP2_TXQ_REFILL_PERIOD_MASK(v) ((v) << 20)
312#define MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(q) (0x8060 + ((q) << 2))
313#define MVPP2_TXQ_TOKEN_SIZE_MAX 0x7fffffff
314#define MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(q) (0x8080 + ((q) << 2))
315#define MVPP2_TXQ_TOKEN_CNTR_MAX 0xffffffff
316
317/* TX general registers */
318#define MVPP2_TX_SNOOP_REG 0x8800
319#define MVPP2_TX_PORT_FLUSH_REG 0x8810
320#define MVPP2_TX_PORT_FLUSH_MASK(port) (1 << (port))
321
322/* LMS registers */
323#define MVPP2_SRC_ADDR_MIDDLE 0x24
324#define MVPP2_SRC_ADDR_HIGH 0x28
Marcin Wojtas08a23752014-07-21 13:48:12 -0300325#define MVPP2_PHY_AN_CFG0_REG 0x34
326#define MVPP2_PHY_AN_STOP_SMI0_MASK BIT(7)
Marcin Wojtas3f518502014-07-10 16:52:13 -0300327#define MVPP2_MNG_EXTENDED_GLOBAL_CTRL_REG 0x305c
Thomas Petazzoni31d76772017-02-21 11:28:10 +0100328#define MVPP2_EXT_GLOBAL_CTRL_DEFAULT 0x27
Marcin Wojtas3f518502014-07-10 16:52:13 -0300329
330/* Per-port registers */
331#define MVPP2_GMAC_CTRL_0_REG 0x0
Antoine Ténart81b66302017-08-22 19:08:21 +0200332#define MVPP2_GMAC_PORT_EN_MASK BIT(0)
Antoine Ténart39193572017-08-22 19:08:24 +0200333#define MVPP2_GMAC_PORT_TYPE_MASK BIT(1)
Antoine Ténart81b66302017-08-22 19:08:21 +0200334#define MVPP2_GMAC_MAX_RX_SIZE_OFFS 2
335#define MVPP2_GMAC_MAX_RX_SIZE_MASK 0x7ffc
336#define MVPP2_GMAC_MIB_CNTR_EN_MASK BIT(15)
Marcin Wojtas3f518502014-07-10 16:52:13 -0300337#define MVPP2_GMAC_CTRL_1_REG 0x4
Antoine Ténart81b66302017-08-22 19:08:21 +0200338#define MVPP2_GMAC_PERIODIC_XON_EN_MASK BIT(1)
339#define MVPP2_GMAC_GMII_LB_EN_MASK BIT(5)
340#define MVPP2_GMAC_PCS_LB_EN_BIT 6
341#define MVPP2_GMAC_PCS_LB_EN_MASK BIT(6)
342#define MVPP2_GMAC_SA_LOW_OFFS 7
Marcin Wojtas3f518502014-07-10 16:52:13 -0300343#define MVPP2_GMAC_CTRL_2_REG 0x8
Antoine Ténart81b66302017-08-22 19:08:21 +0200344#define MVPP2_GMAC_INBAND_AN_MASK BIT(0)
Antoine Ténart39193572017-08-22 19:08:24 +0200345#define MVPP2_GMAC_FLOW_CTRL_MASK GENMASK(2, 1)
Antoine Ténart81b66302017-08-22 19:08:21 +0200346#define MVPP2_GMAC_PCS_ENABLE_MASK BIT(3)
Antoine Tenartc7dfc8c2017-09-25 14:59:48 +0200347#define MVPP2_GMAC_INTERNAL_CLK_MASK BIT(4)
Antoine Ténart39193572017-08-22 19:08:24 +0200348#define MVPP2_GMAC_DISABLE_PADDING BIT(5)
Antoine Ténart81b66302017-08-22 19:08:21 +0200349#define MVPP2_GMAC_PORT_RESET_MASK BIT(6)
Marcin Wojtas3f518502014-07-10 16:52:13 -0300350#define MVPP2_GMAC_AUTONEG_CONFIG 0xc
Antoine Ténart81b66302017-08-22 19:08:21 +0200351#define MVPP2_GMAC_FORCE_LINK_DOWN BIT(0)
352#define MVPP2_GMAC_FORCE_LINK_PASS BIT(1)
Antoine Ténart39193572017-08-22 19:08:24 +0200353#define MVPP2_GMAC_IN_BAND_AUTONEG BIT(2)
354#define MVPP2_GMAC_IN_BAND_AUTONEG_BYPASS BIT(3)
Antoine Ténart81b66302017-08-22 19:08:21 +0200355#define MVPP2_GMAC_CONFIG_MII_SPEED BIT(5)
356#define MVPP2_GMAC_CONFIG_GMII_SPEED BIT(6)
357#define MVPP2_GMAC_AN_SPEED_EN BIT(7)
358#define MVPP2_GMAC_FC_ADV_EN BIT(9)
Antoine Ténart39193572017-08-22 19:08:24 +0200359#define MVPP2_GMAC_FLOW_CTRL_AUTONEG BIT(11)
Antoine Ténart81b66302017-08-22 19:08:21 +0200360#define MVPP2_GMAC_CONFIG_FULL_DUPLEX BIT(12)
361#define MVPP2_GMAC_AN_DUPLEX_EN BIT(13)
Antoine Tenartfd3651b2017-09-01 11:04:54 +0200362#define MVPP2_GMAC_STATUS0 0x10
363#define MVPP2_GMAC_STATUS0_LINK_UP BIT(0)
Marcin Wojtas3f518502014-07-10 16:52:13 -0300364#define MVPP2_GMAC_PORT_FIFO_CFG_1_REG 0x1c
Antoine Ténart81b66302017-08-22 19:08:21 +0200365#define MVPP2_GMAC_TX_FIFO_MIN_TH_OFFS 6
366#define MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK 0x1fc0
367#define MVPP2_GMAC_TX_FIFO_MIN_TH_MASK(v) (((v) << 6) & \
Marcin Wojtas3f518502014-07-10 16:52:13 -0300368 MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK)
Antoine Tenartfd3651b2017-09-01 11:04:54 +0200369#define MVPP22_GMAC_INT_STAT 0x20
370#define MVPP22_GMAC_INT_STAT_LINK BIT(1)
371#define MVPP22_GMAC_INT_MASK 0x24
372#define MVPP22_GMAC_INT_MASK_LINK_STAT BIT(1)
Thomas Petazzoni26975822017-03-07 16:53:14 +0100373#define MVPP22_GMAC_CTRL_4_REG 0x90
Antoine Ténart81b66302017-08-22 19:08:21 +0200374#define MVPP22_CTRL4_EXT_PIN_GMII_SEL BIT(0)
375#define MVPP22_CTRL4_DP_CLK_SEL BIT(5)
Antoine Ténart1068ec72017-08-22 19:08:22 +0200376#define MVPP22_CTRL4_SYNC_BYPASS_DIS BIT(6)
Antoine Ténart81b66302017-08-22 19:08:21 +0200377#define MVPP22_CTRL4_QSGMII_BYPASS_ACTIVE BIT(7)
Antoine Tenartfd3651b2017-09-01 11:04:54 +0200378#define MVPP22_GMAC_INT_SUM_MASK 0xa4
379#define MVPP22_GMAC_INT_SUM_MASK_LINK_STAT BIT(1)
Thomas Petazzoni26975822017-03-07 16:53:14 +0100380
381/* Per-port XGMAC registers. PPv2.2 only, only for GOP port 0,
382 * relative to port->base.
383 */
Antoine Ténart725757a2017-06-12 16:01:39 +0200384#define MVPP22_XLG_CTRL0_REG 0x100
Antoine Ténart81b66302017-08-22 19:08:21 +0200385#define MVPP22_XLG_CTRL0_PORT_EN BIT(0)
386#define MVPP22_XLG_CTRL0_MAC_RESET_DIS BIT(1)
Antoine Ténart77321952017-08-22 19:08:25 +0200387#define MVPP22_XLG_CTRL0_RX_FLOW_CTRL_EN BIT(7)
Antoine Ténart81b66302017-08-22 19:08:21 +0200388#define MVPP22_XLG_CTRL0_MIB_CNT_DIS BIT(14)
Stefan Chulski76eb1b12017-08-22 19:08:26 +0200389#define MVPP22_XLG_CTRL1_REG 0x104
Antoine Ténartec15ecd2017-08-25 15:24:46 +0200390#define MVPP22_XLG_CTRL1_FRAMESIZELIMIT_OFFS 0
Stefan Chulski76eb1b12017-08-22 19:08:26 +0200391#define MVPP22_XLG_CTRL1_FRAMESIZELIMIT_MASK 0x1fff
Antoine Tenartfd3651b2017-09-01 11:04:54 +0200392#define MVPP22_XLG_STATUS 0x10c
393#define MVPP22_XLG_STATUS_LINK_UP BIT(0)
394#define MVPP22_XLG_INT_STAT 0x114
395#define MVPP22_XLG_INT_STAT_LINK BIT(1)
396#define MVPP22_XLG_INT_MASK 0x118
397#define MVPP22_XLG_INT_MASK_LINK BIT(1)
Thomas Petazzoni26975822017-03-07 16:53:14 +0100398#define MVPP22_XLG_CTRL3_REG 0x11c
Antoine Ténart81b66302017-08-22 19:08:21 +0200399#define MVPP22_XLG_CTRL3_MACMODESELECT_MASK (7 << 13)
400#define MVPP22_XLG_CTRL3_MACMODESELECT_GMAC (0 << 13)
401#define MVPP22_XLG_CTRL3_MACMODESELECT_10G (1 << 13)
Antoine Tenartfd3651b2017-09-01 11:04:54 +0200402#define MVPP22_XLG_EXT_INT_MASK 0x15c
403#define MVPP22_XLG_EXT_INT_MASK_XLG BIT(1)
404#define MVPP22_XLG_EXT_INT_MASK_GIG BIT(2)
Antoine Ténart77321952017-08-22 19:08:25 +0200405#define MVPP22_XLG_CTRL4_REG 0x184
406#define MVPP22_XLG_CTRL4_FWD_FC BIT(5)
407#define MVPP22_XLG_CTRL4_FWD_PFC BIT(6)
408#define MVPP22_XLG_CTRL4_MACMODSELECT_GMAC BIT(12)
409
Thomas Petazzoni26975822017-03-07 16:53:14 +0100410/* SMI registers. PPv2.2 only, relative to priv->iface_base. */
411#define MVPP22_SMI_MISC_CFG_REG 0x1204
Antoine Ténart81b66302017-08-22 19:08:21 +0200412#define MVPP22_SMI_POLLING_EN BIT(10)
Marcin Wojtas3f518502014-07-10 16:52:13 -0300413
Thomas Petazzonia7868412017-03-07 16:53:13 +0100414#define MVPP22_GMAC_BASE(port) (0x7000 + (port) * 0x1000 + 0xe00)
415
Marcin Wojtas3f518502014-07-10 16:52:13 -0300416#define MVPP2_CAUSE_TXQ_SENT_DESC_ALL_MASK 0xff
417
418/* Descriptor ring Macros */
419#define MVPP2_QUEUE_NEXT_DESC(q, index) \
420 (((index) < (q)->last_desc) ? ((index) + 1) : 0)
421
Antoine Ténartf84bf382017-08-22 19:08:27 +0200422/* XPCS registers. PPv2.2 only */
423#define MVPP22_MPCS_BASE(port) (0x7000 + (port) * 0x1000)
424#define MVPP22_MPCS_CTRL 0x14
425#define MVPP22_MPCS_CTRL_FWD_ERR_CONN BIT(10)
426#define MVPP22_MPCS_CLK_RESET 0x14c
427#define MAC_CLK_RESET_SD_TX BIT(0)
428#define MAC_CLK_RESET_SD_RX BIT(1)
429#define MAC_CLK_RESET_MAC BIT(2)
430#define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4)
431#define MVPP22_MPCS_CLK_RESET_DIV_SET BIT(11)
432
433/* XPCS registers. PPv2.2 only */
434#define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000)
435#define MVPP22_XPCS_CFG0 0x0
436#define MVPP22_XPCS_CFG0_PCS_MODE(n) ((n) << 3)
437#define MVPP22_XPCS_CFG0_ACTIVE_LANE(n) ((n) << 5)
438
439/* System controller registers. Accessed through a regmap. */
440#define GENCONF_SOFT_RESET1 0x1108
441#define GENCONF_SOFT_RESET1_GOP BIT(6)
442#define GENCONF_PORT_CTRL0 0x1110
443#define GENCONF_PORT_CTRL0_BUS_WIDTH_SELECT BIT(1)
444#define GENCONF_PORT_CTRL0_RX_DATA_SAMPLE BIT(29)
445#define GENCONF_PORT_CTRL0_CLK_DIV_PHASE_CLR BIT(31)
446#define GENCONF_PORT_CTRL1 0x1114
447#define GENCONF_PORT_CTRL1_EN(p) BIT(p)
448#define GENCONF_PORT_CTRL1_RESET(p) (BIT(p) << 28)
449#define GENCONF_CTRL0 0x1120
450#define GENCONF_CTRL0_PORT0_RGMII BIT(0)
451#define GENCONF_CTRL0_PORT1_RGMII_MII BIT(1)
452#define GENCONF_CTRL0_PORT1_RGMII BIT(2)
453
Marcin Wojtas3f518502014-07-10 16:52:13 -0300454/* Various constants */
455
456/* Coalescing */
457#define MVPP2_TXDONE_COAL_PKTS_THRESH 15
Marcin Wojtasedc660f2015-08-06 19:00:30 +0200458#define MVPP2_TXDONE_HRTIMER_PERIOD_NS 1000000UL
Thomas Petazzoni213f4282017-08-03 10:42:00 +0200459#define MVPP2_TXDONE_COAL_USEC 1000
Marcin Wojtas3f518502014-07-10 16:52:13 -0300460#define MVPP2_RX_COAL_PKTS 32
461#define MVPP2_RX_COAL_USEC 100
462
463/* The two bytes Marvell header. Either contains a special value used
464 * by Marvell switches when a specific hardware mode is enabled (not
465 * supported by this driver) or is filled automatically by zeroes on
466 * the RX side. Those two bytes being at the front of the Ethernet
467 * header, they allow to have the IP header aligned on a 4 bytes
468 * boundary automatically: the hardware skips those two bytes on its
469 * own.
470 */
471#define MVPP2_MH_SIZE 2
472#define MVPP2_ETH_TYPE_LEN 2
473#define MVPP2_PPPOE_HDR_SIZE 8
474#define MVPP2_VLAN_TAG_LEN 4
475
476/* Lbtd 802.3 type */
477#define MVPP2_IP_LBDT_TYPE 0xfffa
478
Marcin Wojtas3f518502014-07-10 16:52:13 -0300479#define MVPP2_TX_CSUM_MAX_SIZE 9800
480
481/* Timeout constants */
482#define MVPP2_TX_DISABLE_TIMEOUT_MSEC 1000
483#define MVPP2_TX_PENDING_TIMEOUT_MSEC 1000
484
485#define MVPP2_TX_MTU_MAX 0x7ffff
486
487/* Maximum number of T-CONTs of PON port */
488#define MVPP2_MAX_TCONT 16
489
490/* Maximum number of supported ports */
491#define MVPP2_MAX_PORTS 4
492
493/* Maximum number of TXQs used by single port */
494#define MVPP2_MAX_TXQ 8
495
Marcin Wojtas3f518502014-07-10 16:52:13 -0300496/* Dfault number of RXQs in use */
497#define MVPP2_DEFAULT_RXQ 4
498
Marcin Wojtas3f518502014-07-10 16:52:13 -0300499/* Max number of Rx descriptors */
500#define MVPP2_MAX_RXD 128
501
502/* Max number of Tx descriptors */
503#define MVPP2_MAX_TXD 1024
504
505/* Amount of Tx descriptors that can be reserved at once by CPU */
506#define MVPP2_CPU_DESC_CHUNK 64
507
508/* Max number of Tx descriptors in each aggregated queue */
509#define MVPP2_AGGR_TXQ_SIZE 256
510
511/* Descriptor aligned size */
512#define MVPP2_DESC_ALIGNED_SIZE 32
513
514/* Descriptor alignment mask */
515#define MVPP2_TX_DESC_ALIGN (MVPP2_DESC_ALIGNED_SIZE - 1)
516
517/* RX FIFO constants */
Antoine Tenart2d1d7df2017-10-30 11:23:28 +0100518#define MVPP2_RX_FIFO_PORT_DATA_SIZE_32KB 0x8000
519#define MVPP2_RX_FIFO_PORT_DATA_SIZE_8KB 0x2000
520#define MVPP2_RX_FIFO_PORT_DATA_SIZE_4KB 0x1000
521#define MVPP2_RX_FIFO_PORT_ATTR_SIZE_32KB 0x200
522#define MVPP2_RX_FIFO_PORT_ATTR_SIZE_8KB 0x80
523#define MVPP2_RX_FIFO_PORT_ATTR_SIZE_4KB 0x40
524#define MVPP2_RX_FIFO_PORT_MIN_PKT 0x80
Marcin Wojtas3f518502014-07-10 16:52:13 -0300525
Antoine Tenart7c10f972017-10-30 11:23:29 +0100526/* TX FIFO constants */
527#define MVPP22_TX_FIFO_DATA_SIZE_10KB 0xa
528#define MVPP22_TX_FIFO_DATA_SIZE_3KB 0x3
529
Marcin Wojtas3f518502014-07-10 16:52:13 -0300530/* RX buffer constants */
531#define MVPP2_SKB_SHINFO_SIZE \
532 SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
533
534#define MVPP2_RX_PKT_SIZE(mtu) \
535 ALIGN((mtu) + MVPP2_MH_SIZE + MVPP2_VLAN_TAG_LEN + \
Jisheng Zhang4a0a12d2016-04-01 17:11:05 +0800536 ETH_HLEN + ETH_FCS_LEN, cache_line_size())
Marcin Wojtas3f518502014-07-10 16:52:13 -0300537
538#define MVPP2_RX_BUF_SIZE(pkt_size) ((pkt_size) + NET_SKB_PAD)
539#define MVPP2_RX_TOTAL_SIZE(buf_size) ((buf_size) + MVPP2_SKB_SHINFO_SIZE)
540#define MVPP2_RX_MAX_PKT_SIZE(total_size) \
541 ((total_size) - NET_SKB_PAD - MVPP2_SKB_SHINFO_SIZE)
542
543#define MVPP2_BIT_TO_BYTE(bit) ((bit) / 8)
544
545/* IPv6 max L3 address size */
546#define MVPP2_MAX_L3_ADDR_SIZE 16
547
548/* Port flags */
549#define MVPP2_F_LOOPBACK BIT(0)
550
551/* Marvell tag types */
552enum mvpp2_tag_type {
553 MVPP2_TAG_TYPE_NONE = 0,
554 MVPP2_TAG_TYPE_MH = 1,
555 MVPP2_TAG_TYPE_DSA = 2,
556 MVPP2_TAG_TYPE_EDSA = 3,
557 MVPP2_TAG_TYPE_VLAN = 4,
558 MVPP2_TAG_TYPE_LAST = 5
559};
560
561/* Parser constants */
562#define MVPP2_PRS_TCAM_SRAM_SIZE 256
563#define MVPP2_PRS_TCAM_WORDS 6
564#define MVPP2_PRS_SRAM_WORDS 4
565#define MVPP2_PRS_FLOW_ID_SIZE 64
566#define MVPP2_PRS_FLOW_ID_MASK 0x3f
567#define MVPP2_PRS_TCAM_ENTRY_INVALID 1
568#define MVPP2_PRS_TCAM_DSA_TAGGED_BIT BIT(5)
569#define MVPP2_PRS_IPV4_HEAD 0x40
570#define MVPP2_PRS_IPV4_HEAD_MASK 0xf0
571#define MVPP2_PRS_IPV4_MC 0xe0
572#define MVPP2_PRS_IPV4_MC_MASK 0xf0
573#define MVPP2_PRS_IPV4_BC_MASK 0xff
574#define MVPP2_PRS_IPV4_IHL 0x5
575#define MVPP2_PRS_IPV4_IHL_MASK 0xf
576#define MVPP2_PRS_IPV6_MC 0xff
577#define MVPP2_PRS_IPV6_MC_MASK 0xff
578#define MVPP2_PRS_IPV6_HOP_MASK 0xff
579#define MVPP2_PRS_TCAM_PROTO_MASK 0xff
580#define MVPP2_PRS_TCAM_PROTO_MASK_L 0x3f
581#define MVPP2_PRS_DBL_VLANS_MAX 100
582
583/* Tcam structure:
584 * - lookup ID - 4 bits
585 * - port ID - 1 byte
586 * - additional information - 1 byte
587 * - header data - 8 bytes
588 * The fields are represented by MVPP2_PRS_TCAM_DATA_REG(5)->(0).
589 */
590#define MVPP2_PRS_AI_BITS 8
591#define MVPP2_PRS_PORT_MASK 0xff
592#define MVPP2_PRS_LU_MASK 0xf
593#define MVPP2_PRS_TCAM_DATA_BYTE(offs) \
594 (((offs) - ((offs) % 2)) * 2 + ((offs) % 2))
595#define MVPP2_PRS_TCAM_DATA_BYTE_EN(offs) \
596 (((offs) * 2) - ((offs) % 2) + 2)
597#define MVPP2_PRS_TCAM_AI_BYTE 16
598#define MVPP2_PRS_TCAM_PORT_BYTE 17
599#define MVPP2_PRS_TCAM_LU_BYTE 20
600#define MVPP2_PRS_TCAM_EN_OFFS(offs) ((offs) + 2)
601#define MVPP2_PRS_TCAM_INV_WORD 5
602/* Tcam entries ID */
603#define MVPP2_PE_DROP_ALL 0
604#define MVPP2_PE_FIRST_FREE_TID 1
605#define MVPP2_PE_LAST_FREE_TID (MVPP2_PRS_TCAM_SRAM_SIZE - 31)
606#define MVPP2_PE_IP6_EXT_PROTO_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 30)
607#define MVPP2_PE_MAC_MC_IP6 (MVPP2_PRS_TCAM_SRAM_SIZE - 29)
608#define MVPP2_PE_IP6_ADDR_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 28)
609#define MVPP2_PE_IP4_ADDR_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 27)
610#define MVPP2_PE_LAST_DEFAULT_FLOW (MVPP2_PRS_TCAM_SRAM_SIZE - 26)
611#define MVPP2_PE_FIRST_DEFAULT_FLOW (MVPP2_PRS_TCAM_SRAM_SIZE - 19)
612#define MVPP2_PE_EDSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 18)
613#define MVPP2_PE_EDSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 17)
614#define MVPP2_PE_DSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 16)
615#define MVPP2_PE_DSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 15)
616#define MVPP2_PE_ETYPE_EDSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 14)
617#define MVPP2_PE_ETYPE_EDSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 13)
618#define MVPP2_PE_ETYPE_DSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 12)
619#define MVPP2_PE_ETYPE_DSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 11)
620#define MVPP2_PE_MH_DEFAULT (MVPP2_PRS_TCAM_SRAM_SIZE - 10)
621#define MVPP2_PE_DSA_DEFAULT (MVPP2_PRS_TCAM_SRAM_SIZE - 9)
622#define MVPP2_PE_IP6_PROTO_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 8)
623#define MVPP2_PE_IP4_PROTO_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 7)
624#define MVPP2_PE_ETH_TYPE_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 6)
625#define MVPP2_PE_VLAN_DBL (MVPP2_PRS_TCAM_SRAM_SIZE - 5)
626#define MVPP2_PE_VLAN_NONE (MVPP2_PRS_TCAM_SRAM_SIZE - 4)
627#define MVPP2_PE_MAC_MC_ALL (MVPP2_PRS_TCAM_SRAM_SIZE - 3)
628#define MVPP2_PE_MAC_PROMISCUOUS (MVPP2_PRS_TCAM_SRAM_SIZE - 2)
629#define MVPP2_PE_MAC_NON_PROMISCUOUS (MVPP2_PRS_TCAM_SRAM_SIZE - 1)
630
631/* Sram structure
632 * The fields are represented by MVPP2_PRS_TCAM_DATA_REG(3)->(0).
633 */
634#define MVPP2_PRS_SRAM_RI_OFFS 0
635#define MVPP2_PRS_SRAM_RI_WORD 0
636#define MVPP2_PRS_SRAM_RI_CTRL_OFFS 32
637#define MVPP2_PRS_SRAM_RI_CTRL_WORD 1
638#define MVPP2_PRS_SRAM_RI_CTRL_BITS 32
639#define MVPP2_PRS_SRAM_SHIFT_OFFS 64
640#define MVPP2_PRS_SRAM_SHIFT_SIGN_BIT 72
641#define MVPP2_PRS_SRAM_UDF_OFFS 73
642#define MVPP2_PRS_SRAM_UDF_BITS 8
643#define MVPP2_PRS_SRAM_UDF_MASK 0xff
644#define MVPP2_PRS_SRAM_UDF_SIGN_BIT 81
645#define MVPP2_PRS_SRAM_UDF_TYPE_OFFS 82
646#define MVPP2_PRS_SRAM_UDF_TYPE_MASK 0x7
647#define MVPP2_PRS_SRAM_UDF_TYPE_L3 1
648#define MVPP2_PRS_SRAM_UDF_TYPE_L4 4
649#define MVPP2_PRS_SRAM_OP_SEL_SHIFT_OFFS 85
650#define MVPP2_PRS_SRAM_OP_SEL_SHIFT_MASK 0x3
651#define MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD 1
652#define MVPP2_PRS_SRAM_OP_SEL_SHIFT_IP4_ADD 2
653#define MVPP2_PRS_SRAM_OP_SEL_SHIFT_IP6_ADD 3
654#define MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS 87
655#define MVPP2_PRS_SRAM_OP_SEL_UDF_BITS 2
656#define MVPP2_PRS_SRAM_OP_SEL_UDF_MASK 0x3
657#define MVPP2_PRS_SRAM_OP_SEL_UDF_ADD 0
658#define MVPP2_PRS_SRAM_OP_SEL_UDF_IP4_ADD 2
659#define MVPP2_PRS_SRAM_OP_SEL_UDF_IP6_ADD 3
660#define MVPP2_PRS_SRAM_OP_SEL_BASE_OFFS 89
661#define MVPP2_PRS_SRAM_AI_OFFS 90
662#define MVPP2_PRS_SRAM_AI_CTRL_OFFS 98
663#define MVPP2_PRS_SRAM_AI_CTRL_BITS 8
664#define MVPP2_PRS_SRAM_AI_MASK 0xff
665#define MVPP2_PRS_SRAM_NEXT_LU_OFFS 106
666#define MVPP2_PRS_SRAM_NEXT_LU_MASK 0xf
667#define MVPP2_PRS_SRAM_LU_DONE_BIT 110
668#define MVPP2_PRS_SRAM_LU_GEN_BIT 111
669
670/* Sram result info bits assignment */
671#define MVPP2_PRS_RI_MAC_ME_MASK 0x1
672#define MVPP2_PRS_RI_DSA_MASK 0x2
Thomas Petazzoni8138aff2017-02-21 11:28:11 +0100673#define MVPP2_PRS_RI_VLAN_MASK (BIT(2) | BIT(3))
674#define MVPP2_PRS_RI_VLAN_NONE 0x0
Marcin Wojtas3f518502014-07-10 16:52:13 -0300675#define MVPP2_PRS_RI_VLAN_SINGLE BIT(2)
676#define MVPP2_PRS_RI_VLAN_DOUBLE BIT(3)
677#define MVPP2_PRS_RI_VLAN_TRIPLE (BIT(2) | BIT(3))
678#define MVPP2_PRS_RI_CPU_CODE_MASK 0x70
679#define MVPP2_PRS_RI_CPU_CODE_RX_SPEC BIT(4)
Thomas Petazzoni8138aff2017-02-21 11:28:11 +0100680#define MVPP2_PRS_RI_L2_CAST_MASK (BIT(9) | BIT(10))
681#define MVPP2_PRS_RI_L2_UCAST 0x0
Marcin Wojtas3f518502014-07-10 16:52:13 -0300682#define MVPP2_PRS_RI_L2_MCAST BIT(9)
683#define MVPP2_PRS_RI_L2_BCAST BIT(10)
684#define MVPP2_PRS_RI_PPPOE_MASK 0x800
Thomas Petazzoni8138aff2017-02-21 11:28:11 +0100685#define MVPP2_PRS_RI_L3_PROTO_MASK (BIT(12) | BIT(13) | BIT(14))
686#define MVPP2_PRS_RI_L3_UN 0x0
Marcin Wojtas3f518502014-07-10 16:52:13 -0300687#define MVPP2_PRS_RI_L3_IP4 BIT(12)
688#define MVPP2_PRS_RI_L3_IP4_OPT BIT(13)
689#define MVPP2_PRS_RI_L3_IP4_OTHER (BIT(12) | BIT(13))
690#define MVPP2_PRS_RI_L3_IP6 BIT(14)
691#define MVPP2_PRS_RI_L3_IP6_EXT (BIT(12) | BIT(14))
692#define MVPP2_PRS_RI_L3_ARP (BIT(13) | BIT(14))
Thomas Petazzoni8138aff2017-02-21 11:28:11 +0100693#define MVPP2_PRS_RI_L3_ADDR_MASK (BIT(15) | BIT(16))
694#define MVPP2_PRS_RI_L3_UCAST 0x0
Marcin Wojtas3f518502014-07-10 16:52:13 -0300695#define MVPP2_PRS_RI_L3_MCAST BIT(15)
696#define MVPP2_PRS_RI_L3_BCAST (BIT(15) | BIT(16))
697#define MVPP2_PRS_RI_IP_FRAG_MASK 0x20000
Stefan Chulskiaff3da32017-09-25 14:59:46 +0200698#define MVPP2_PRS_RI_IP_FRAG_TRUE BIT(17)
Marcin Wojtas3f518502014-07-10 16:52:13 -0300699#define MVPP2_PRS_RI_UDF3_MASK 0x300000
700#define MVPP2_PRS_RI_UDF3_RX_SPECIAL BIT(21)
701#define MVPP2_PRS_RI_L4_PROTO_MASK 0x1c00000
702#define MVPP2_PRS_RI_L4_TCP BIT(22)
703#define MVPP2_PRS_RI_L4_UDP BIT(23)
704#define MVPP2_PRS_RI_L4_OTHER (BIT(22) | BIT(23))
705#define MVPP2_PRS_RI_UDF7_MASK 0x60000000
706#define MVPP2_PRS_RI_UDF7_IP6_LITE BIT(29)
707#define MVPP2_PRS_RI_DROP_MASK 0x80000000
708
709/* Sram additional info bits assignment */
710#define MVPP2_PRS_IPV4_DIP_AI_BIT BIT(0)
711#define MVPP2_PRS_IPV6_NO_EXT_AI_BIT BIT(0)
712#define MVPP2_PRS_IPV6_EXT_AI_BIT BIT(1)
713#define MVPP2_PRS_IPV6_EXT_AH_AI_BIT BIT(2)
714#define MVPP2_PRS_IPV6_EXT_AH_LEN_AI_BIT BIT(3)
715#define MVPP2_PRS_IPV6_EXT_AH_L4_AI_BIT BIT(4)
716#define MVPP2_PRS_SINGLE_VLAN_AI 0
717#define MVPP2_PRS_DBL_VLAN_AI_BIT BIT(7)
718
719/* DSA/EDSA type */
720#define MVPP2_PRS_TAGGED true
721#define MVPP2_PRS_UNTAGGED false
722#define MVPP2_PRS_EDSA true
723#define MVPP2_PRS_DSA false
724
725/* MAC entries, shadow udf */
726enum mvpp2_prs_udf {
727 MVPP2_PRS_UDF_MAC_DEF,
728 MVPP2_PRS_UDF_MAC_RANGE,
729 MVPP2_PRS_UDF_L2_DEF,
730 MVPP2_PRS_UDF_L2_DEF_COPY,
731 MVPP2_PRS_UDF_L2_USER,
732};
733
734/* Lookup ID */
735enum mvpp2_prs_lookup {
736 MVPP2_PRS_LU_MH,
737 MVPP2_PRS_LU_MAC,
738 MVPP2_PRS_LU_DSA,
739 MVPP2_PRS_LU_VLAN,
740 MVPP2_PRS_LU_L2,
741 MVPP2_PRS_LU_PPPOE,
742 MVPP2_PRS_LU_IP4,
743 MVPP2_PRS_LU_IP6,
744 MVPP2_PRS_LU_FLOWS,
745 MVPP2_PRS_LU_LAST,
746};
747
748/* L3 cast enum */
749enum mvpp2_prs_l3_cast {
750 MVPP2_PRS_L3_UNI_CAST,
751 MVPP2_PRS_L3_MULTI_CAST,
752 MVPP2_PRS_L3_BROAD_CAST
753};
754
755/* Classifier constants */
756#define MVPP2_CLS_FLOWS_TBL_SIZE 512
757#define MVPP2_CLS_FLOWS_TBL_DATA_WORDS 3
758#define MVPP2_CLS_LKP_TBL_SIZE 64
Antoine Tenart1d7d15d2017-10-30 11:23:30 +0100759#define MVPP2_CLS_RX_QUEUES 256
760
761/* RSS constants */
762#define MVPP22_RSS_TABLE_ENTRIES 32
Marcin Wojtas3f518502014-07-10 16:52:13 -0300763
764/* BM constants */
765#define MVPP2_BM_POOLS_NUM 8
766#define MVPP2_BM_LONG_BUF_NUM 1024
767#define MVPP2_BM_SHORT_BUF_NUM 2048
768#define MVPP2_BM_POOL_SIZE_MAX (16*1024 - MVPP2_BM_POOL_PTR_ALIGN/4)
769#define MVPP2_BM_POOL_PTR_ALIGN 128
770#define MVPP2_BM_SWF_LONG_POOL(port) ((port > 2) ? 2 : port)
771#define MVPP2_BM_SWF_SHORT_POOL 3
772
773/* BM cookie (32 bits) definition */
774#define MVPP2_BM_COOKIE_POOL_OFFS 8
775#define MVPP2_BM_COOKIE_CPU_OFFS 24
776
777/* BM short pool packet size
778 * These value assure that for SWF the total number
779 * of bytes allocated for each buffer will be 512
780 */
781#define MVPP2_BM_SHORT_PKT_SIZE MVPP2_RX_MAX_PKT_SIZE(512)
782
Thomas Petazzonia7868412017-03-07 16:53:13 +0100783#define MVPP21_ADDR_SPACE_SZ 0
784#define MVPP22_ADDR_SPACE_SZ SZ_64K
785
Thomas Petazzonidf089aa2017-08-03 10:41:58 +0200786#define MVPP2_MAX_THREADS 8
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +0200787#define MVPP2_MAX_QVECS MVPP2_MAX_THREADS
Thomas Petazzonia7868412017-03-07 16:53:13 +0100788
Marcin Wojtas3f518502014-07-10 16:52:13 -0300789enum mvpp2_bm_type {
790 MVPP2_BM_FREE,
791 MVPP2_BM_SWF_LONG,
792 MVPP2_BM_SWF_SHORT
793};
794
795/* Definitions */
796
797/* Shared Packet Processor resources */
798struct mvpp2 {
799 /* Shared registers' base addresses */
Marcin Wojtas3f518502014-07-10 16:52:13 -0300800 void __iomem *lms_base;
Thomas Petazzonia7868412017-03-07 16:53:13 +0100801 void __iomem *iface_base;
802
Thomas Petazzonidf089aa2017-08-03 10:41:58 +0200803 /* On PPv2.2, each "software thread" can access the base
804 * register through a separate address space, each 64 KB apart
805 * from each other. Typically, such address spaces will be
806 * used per CPU.
Thomas Petazzonia7868412017-03-07 16:53:13 +0100807 */
Thomas Petazzonidf089aa2017-08-03 10:41:58 +0200808 void __iomem *swth_base[MVPP2_MAX_THREADS];
Marcin Wojtas3f518502014-07-10 16:52:13 -0300809
Antoine Ténartf84bf382017-08-22 19:08:27 +0200810 /* On PPv2.2, some port control registers are located into the system
811 * controller space. These registers are accessible through a regmap.
812 */
813 struct regmap *sysctrl_base;
814
Marcin Wojtas3f518502014-07-10 16:52:13 -0300815 /* Common clocks */
816 struct clk *pp_clk;
817 struct clk *gop_clk;
Thomas Petazzonifceb55d2017-03-07 16:53:18 +0100818 struct clk *mg_clk;
Gregory CLEMENT4792ea02017-09-29 14:27:39 +0200819 struct clk *axi_clk;
Marcin Wojtas3f518502014-07-10 16:52:13 -0300820
821 /* List of pointers to port structures */
822 struct mvpp2_port **port_list;
823
824 /* Aggregated TXQs */
825 struct mvpp2_tx_queue *aggr_txqs;
826
827 /* BM pools */
828 struct mvpp2_bm_pool *bm_pools;
829
830 /* PRS shadow table */
831 struct mvpp2_prs_shadow *prs_shadow;
832 /* PRS auxiliary table for double vlan entries control */
833 bool *prs_double_vlans;
834
835 /* Tclk value */
836 u32 tclk;
Thomas Petazzonifaca9242017-03-07 16:53:06 +0100837
838 /* HW version */
839 enum { MVPP21, MVPP22 } hw_version;
Thomas Petazzoni59b9a312017-03-07 16:53:17 +0100840
841 /* Maximum number of RXQs per port */
842 unsigned int max_port_rxqs;
Marcin Wojtas3f518502014-07-10 16:52:13 -0300843};
844
845struct mvpp2_pcpu_stats {
846 struct u64_stats_sync syncp;
847 u64 rx_packets;
848 u64 rx_bytes;
849 u64 tx_packets;
850 u64 tx_bytes;
851};
852
Marcin Wojtasedc660f2015-08-06 19:00:30 +0200853/* Per-CPU port control */
854struct mvpp2_port_pcpu {
855 struct hrtimer tx_done_timer;
856 bool timer_scheduled;
857 /* Tasklet for egress finalization */
858 struct tasklet_struct tx_done_tasklet;
859};
860
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +0200861struct mvpp2_queue_vector {
862 int irq;
863 struct napi_struct napi;
864 enum { MVPP2_QUEUE_VECTOR_SHARED, MVPP2_QUEUE_VECTOR_PRIVATE } type;
865 int sw_thread_id;
866 u16 sw_thread_mask;
867 int first_rxq;
868 int nrxqs;
869 u32 pending_cause_rx;
870 struct mvpp2_port *port;
871};
872
Marcin Wojtas3f518502014-07-10 16:52:13 -0300873struct mvpp2_port {
874 u8 id;
875
Thomas Petazzonia7868412017-03-07 16:53:13 +0100876 /* Index of the port from the "group of ports" complex point
877 * of view
878 */
879 int gop_id;
880
Antoine Tenartfd3651b2017-09-01 11:04:54 +0200881 int link_irq;
882
Marcin Wojtas3f518502014-07-10 16:52:13 -0300883 struct mvpp2 *priv;
884
885 /* Per-port registers' base address */
886 void __iomem *base;
887
888 struct mvpp2_rx_queue **rxqs;
Thomas Petazzoni09f83972017-08-03 10:41:57 +0200889 unsigned int nrxqs;
Marcin Wojtas3f518502014-07-10 16:52:13 -0300890 struct mvpp2_tx_queue **txqs;
Thomas Petazzoni09f83972017-08-03 10:41:57 +0200891 unsigned int ntxqs;
Marcin Wojtas3f518502014-07-10 16:52:13 -0300892 struct net_device *dev;
893
894 int pkt_size;
895
Marcin Wojtasedc660f2015-08-06 19:00:30 +0200896 /* Per-CPU port control */
897 struct mvpp2_port_pcpu __percpu *pcpu;
898
Marcin Wojtas3f518502014-07-10 16:52:13 -0300899 /* Flags */
900 unsigned long flags;
901
902 u16 tx_ring_size;
903 u16 rx_ring_size;
904 struct mvpp2_pcpu_stats __percpu *stats;
905
Marcin Wojtas3f518502014-07-10 16:52:13 -0300906 phy_interface_t phy_interface;
907 struct device_node *phy_node;
Antoine Tenart542897d2017-08-30 10:29:15 +0200908 struct phy *comphy;
Marcin Wojtas3f518502014-07-10 16:52:13 -0300909 unsigned int link;
910 unsigned int duplex;
911 unsigned int speed;
912
913 struct mvpp2_bm_pool *pool_long;
914 struct mvpp2_bm_pool *pool_short;
915
916 /* Index of first port's physical RXQ */
917 u8 first_rxq;
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +0200918
919 struct mvpp2_queue_vector qvecs[MVPP2_MAX_QVECS];
920 unsigned int nqvecs;
Thomas Petazzoni213f4282017-08-03 10:42:00 +0200921 bool has_tx_irqs;
922
923 u32 tx_time_coal;
Marcin Wojtas3f518502014-07-10 16:52:13 -0300924};
925
926/* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the
927 * layout of the transmit and reception DMA descriptors, and their
928 * layout is therefore defined by the hardware design
929 */
930
931#define MVPP2_TXD_L3_OFF_SHIFT 0
932#define MVPP2_TXD_IP_HLEN_SHIFT 8
933#define MVPP2_TXD_L4_CSUM_FRAG BIT(13)
934#define MVPP2_TXD_L4_CSUM_NOT BIT(14)
935#define MVPP2_TXD_IP_CSUM_DISABLE BIT(15)
936#define MVPP2_TXD_PADDING_DISABLE BIT(23)
937#define MVPP2_TXD_L4_UDP BIT(24)
938#define MVPP2_TXD_L3_IP6 BIT(26)
939#define MVPP2_TXD_L_DESC BIT(28)
940#define MVPP2_TXD_F_DESC BIT(29)
941
942#define MVPP2_RXD_ERR_SUMMARY BIT(15)
943#define MVPP2_RXD_ERR_CODE_MASK (BIT(13) | BIT(14))
944#define MVPP2_RXD_ERR_CRC 0x0
945#define MVPP2_RXD_ERR_OVERRUN BIT(13)
946#define MVPP2_RXD_ERR_RESOURCE (BIT(13) | BIT(14))
947#define MVPP2_RXD_BM_POOL_ID_OFFS 16
948#define MVPP2_RXD_BM_POOL_ID_MASK (BIT(16) | BIT(17) | BIT(18))
949#define MVPP2_RXD_HWF_SYNC BIT(21)
950#define MVPP2_RXD_L4_CSUM_OK BIT(22)
951#define MVPP2_RXD_IP4_HEADER_ERR BIT(24)
952#define MVPP2_RXD_L4_TCP BIT(25)
953#define MVPP2_RXD_L4_UDP BIT(26)
954#define MVPP2_RXD_L3_IP4 BIT(28)
955#define MVPP2_RXD_L3_IP6 BIT(30)
956#define MVPP2_RXD_BUF_HDR BIT(31)
957
Thomas Petazzoni054f6372017-03-07 16:53:07 +0100958/* HW TX descriptor for PPv2.1 */
959struct mvpp21_tx_desc {
Marcin Wojtas3f518502014-07-10 16:52:13 -0300960 u32 command; /* Options used by HW for packet transmitting.*/
961 u8 packet_offset; /* the offset from the buffer beginning */
962 u8 phys_txq; /* destination queue ID */
963 u16 data_size; /* data size of transmitted packet in bytes */
Thomas Petazzoni20396132017-03-07 16:53:00 +0100964 u32 buf_dma_addr; /* physical addr of transmitted buffer */
Marcin Wojtas3f518502014-07-10 16:52:13 -0300965 u32 buf_cookie; /* cookie for access to TX buffer in tx path */
966 u32 reserved1[3]; /* hw_cmd (for future use, BM, PON, PNC) */
967 u32 reserved2; /* reserved (for future use) */
968};
969
Thomas Petazzoni054f6372017-03-07 16:53:07 +0100970/* HW RX descriptor for PPv2.1 */
971struct mvpp21_rx_desc {
Marcin Wojtas3f518502014-07-10 16:52:13 -0300972 u32 status; /* info about received packet */
973 u16 reserved1; /* parser_info (for future use, PnC) */
974 u16 data_size; /* size of received packet in bytes */
Thomas Petazzoni20396132017-03-07 16:53:00 +0100975 u32 buf_dma_addr; /* physical address of the buffer */
Marcin Wojtas3f518502014-07-10 16:52:13 -0300976 u32 buf_cookie; /* cookie for access to RX buffer in rx path */
977 u16 reserved2; /* gem_port_id (for future use, PON) */
978 u16 reserved3; /* csum_l4 (for future use, PnC) */
979 u8 reserved4; /* bm_qset (for future use, BM) */
980 u8 reserved5;
981 u16 reserved6; /* classify_info (for future use, PnC) */
982 u32 reserved7; /* flow_id (for future use, PnC) */
983 u32 reserved8;
984};
985
Thomas Petazzonie7c53592017-03-07 16:53:08 +0100986/* HW TX descriptor for PPv2.2 */
987struct mvpp22_tx_desc {
988 u32 command;
989 u8 packet_offset;
990 u8 phys_txq;
991 u16 data_size;
992 u64 reserved1;
993 u64 buf_dma_addr_ptp;
994 u64 buf_cookie_misc;
995};
996
997/* HW RX descriptor for PPv2.2 */
998struct mvpp22_rx_desc {
999 u32 status;
1000 u16 reserved1;
1001 u16 data_size;
1002 u32 reserved2;
1003 u32 reserved3;
1004 u64 buf_dma_addr_key_hash;
1005 u64 buf_cookie_misc;
1006};
1007
Thomas Petazzoni054f6372017-03-07 16:53:07 +01001008/* Opaque type used by the driver to manipulate the HW TX and RX
1009 * descriptors
1010 */
1011struct mvpp2_tx_desc {
1012 union {
1013 struct mvpp21_tx_desc pp21;
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001014 struct mvpp22_tx_desc pp22;
Thomas Petazzoni054f6372017-03-07 16:53:07 +01001015 };
1016};
1017
1018struct mvpp2_rx_desc {
1019 union {
1020 struct mvpp21_rx_desc pp21;
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001021 struct mvpp22_rx_desc pp22;
Thomas Petazzoni054f6372017-03-07 16:53:07 +01001022 };
1023};
1024
Thomas Petazzoni83544912016-12-21 11:28:49 +01001025struct mvpp2_txq_pcpu_buf {
1026 /* Transmitted SKB */
1027 struct sk_buff *skb;
1028
1029 /* Physical address of transmitted buffer */
Thomas Petazzoni20396132017-03-07 16:53:00 +01001030 dma_addr_t dma;
Thomas Petazzoni83544912016-12-21 11:28:49 +01001031
1032 /* Size transmitted */
1033 size_t size;
1034};
1035
Marcin Wojtas3f518502014-07-10 16:52:13 -03001036/* Per-CPU Tx queue control */
1037struct mvpp2_txq_pcpu {
1038 int cpu;
1039
1040 /* Number of Tx DMA descriptors in the descriptor ring */
1041 int size;
1042
1043 /* Number of currently used Tx DMA descriptor in the
1044 * descriptor ring
1045 */
1046 int count;
1047
1048 /* Number of Tx DMA descriptors reserved for each CPU */
1049 int reserved_num;
1050
Thomas Petazzoni83544912016-12-21 11:28:49 +01001051 /* Infos about transmitted buffers */
1052 struct mvpp2_txq_pcpu_buf *buffs;
Marcin Wojtas71ce3912015-08-06 19:00:29 +02001053
Marcin Wojtas3f518502014-07-10 16:52:13 -03001054 /* Index of last TX DMA descriptor that was inserted */
1055 int txq_put_index;
1056
1057 /* Index of the TX DMA descriptor to be cleaned up */
1058 int txq_get_index;
Antoine Ténart186cd4d2017-08-23 09:46:56 +02001059
1060 /* DMA buffer for TSO headers */
1061 char *tso_headers;
1062 dma_addr_t tso_headers_dma;
Marcin Wojtas3f518502014-07-10 16:52:13 -03001063};
1064
1065struct mvpp2_tx_queue {
1066 /* Physical number of this Tx queue */
1067 u8 id;
1068
1069 /* Logical number of this Tx queue */
1070 u8 log_id;
1071
1072 /* Number of Tx DMA descriptors in the descriptor ring */
1073 int size;
1074
1075 /* Number of currently used Tx DMA descriptor in the descriptor ring */
1076 int count;
1077
1078 /* Per-CPU control of physical Tx queues */
1079 struct mvpp2_txq_pcpu __percpu *pcpu;
1080
Marcin Wojtas3f518502014-07-10 16:52:13 -03001081 u32 done_pkts_coal;
1082
1083 /* Virtual address of thex Tx DMA descriptors array */
1084 struct mvpp2_tx_desc *descs;
1085
1086 /* DMA address of the Tx DMA descriptors array */
Thomas Petazzoni20396132017-03-07 16:53:00 +01001087 dma_addr_t descs_dma;
Marcin Wojtas3f518502014-07-10 16:52:13 -03001088
1089 /* Index of the last Tx DMA descriptor */
1090 int last_desc;
1091
1092 /* Index of the next Tx DMA descriptor to process */
1093 int next_desc_to_proc;
1094};
1095
1096struct mvpp2_rx_queue {
1097 /* RX queue number, in the range 0-31 for physical RXQs */
1098 u8 id;
1099
1100 /* Num of rx descriptors in the rx descriptor ring */
1101 int size;
1102
1103 u32 pkts_coal;
1104 u32 time_coal;
1105
1106 /* Virtual address of the RX DMA descriptors array */
1107 struct mvpp2_rx_desc *descs;
1108
1109 /* DMA address of the RX DMA descriptors array */
Thomas Petazzoni20396132017-03-07 16:53:00 +01001110 dma_addr_t descs_dma;
Marcin Wojtas3f518502014-07-10 16:52:13 -03001111
1112 /* Index of the last RX DMA descriptor */
1113 int last_desc;
1114
1115 /* Index of the next RX DMA descriptor to process */
1116 int next_desc_to_proc;
1117
1118 /* ID of port to which physical RXQ is mapped */
1119 int port;
1120
1121 /* Port's logic RXQ number to which physical RXQ is mapped */
1122 int logic_rxq;
1123};
1124
1125union mvpp2_prs_tcam_entry {
1126 u32 word[MVPP2_PRS_TCAM_WORDS];
1127 u8 byte[MVPP2_PRS_TCAM_WORDS * 4];
1128};
1129
1130union mvpp2_prs_sram_entry {
1131 u32 word[MVPP2_PRS_SRAM_WORDS];
1132 u8 byte[MVPP2_PRS_SRAM_WORDS * 4];
1133};
1134
1135struct mvpp2_prs_entry {
1136 u32 index;
1137 union mvpp2_prs_tcam_entry tcam;
1138 union mvpp2_prs_sram_entry sram;
1139};
1140
1141struct mvpp2_prs_shadow {
1142 bool valid;
1143 bool finish;
1144
1145 /* Lookup ID */
1146 int lu;
1147
1148 /* User defined offset */
1149 int udf;
1150
1151 /* Result info */
1152 u32 ri;
1153 u32 ri_mask;
1154};
1155
1156struct mvpp2_cls_flow_entry {
1157 u32 index;
1158 u32 data[MVPP2_CLS_FLOWS_TBL_DATA_WORDS];
1159};
1160
1161struct mvpp2_cls_lookup_entry {
1162 u32 lkpid;
1163 u32 way;
1164 u32 data;
1165};
1166
1167struct mvpp2_bm_pool {
1168 /* Pool number in the range 0-7 */
1169 int id;
1170 enum mvpp2_bm_type type;
1171
1172 /* Buffer Pointers Pool External (BPPE) size */
1173 int size;
Thomas Petazzonid01524d2017-03-07 16:53:09 +01001174 /* BPPE size in bytes */
1175 int size_bytes;
Marcin Wojtas3f518502014-07-10 16:52:13 -03001176 /* Number of buffers for this pool */
1177 int buf_num;
1178 /* Pool buffer size */
1179 int buf_size;
1180 /* Packet size */
1181 int pkt_size;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01001182 int frag_size;
Marcin Wojtas3f518502014-07-10 16:52:13 -03001183
1184 /* BPPE virtual base address */
1185 u32 *virt_addr;
Thomas Petazzoni20396132017-03-07 16:53:00 +01001186 /* BPPE DMA base address */
1187 dma_addr_t dma_addr;
Marcin Wojtas3f518502014-07-10 16:52:13 -03001188
1189 /* Ports using BM pool */
1190 u32 port_map;
Marcin Wojtas3f518502014-07-10 16:52:13 -03001191};
1192
Antoine Tenart20920262017-10-23 15:24:30 +02001193#define IS_TSO_HEADER(txq_pcpu, addr) \
1194 ((addr) >= (txq_pcpu)->tso_headers_dma && \
1195 (addr) < (txq_pcpu)->tso_headers_dma + \
1196 (txq_pcpu)->size * TSO_HEADER_SIZE)
1197
Thomas Petazzoni213f4282017-08-03 10:42:00 +02001198/* Queue modes */
1199#define MVPP2_QDIST_SINGLE_MODE 0
1200#define MVPP2_QDIST_MULTI_MODE 1
1201
1202static int queue_mode = MVPP2_QDIST_SINGLE_MODE;
1203
1204module_param(queue_mode, int, 0444);
1205MODULE_PARM_DESC(queue_mode, "Set queue_mode (single=0, multi=1)");
1206
Marcin Wojtas3f518502014-07-10 16:52:13 -03001207#define MVPP2_DRIVER_NAME "mvpp2"
1208#define MVPP2_DRIVER_VERSION "1.0"
1209
1210/* Utility/helper methods */
1211
1212static void mvpp2_write(struct mvpp2 *priv, u32 offset, u32 data)
1213{
Thomas Petazzonidf089aa2017-08-03 10:41:58 +02001214 writel(data, priv->swth_base[0] + offset);
Marcin Wojtas3f518502014-07-10 16:52:13 -03001215}
1216
1217static u32 mvpp2_read(struct mvpp2 *priv, u32 offset)
1218{
Thomas Petazzonidf089aa2017-08-03 10:41:58 +02001219 return readl(priv->swth_base[0] + offset);
Thomas Petazzonia7868412017-03-07 16:53:13 +01001220}
1221
1222/* These accessors should be used to access:
1223 *
1224 * - per-CPU registers, where each CPU has its own copy of the
1225 * register.
1226 *
1227 * MVPP2_BM_VIRT_ALLOC_REG
1228 * MVPP2_BM_ADDR_HIGH_ALLOC
1229 * MVPP22_BM_ADDR_HIGH_RLS_REG
1230 * MVPP2_BM_VIRT_RLS_REG
1231 * MVPP2_ISR_RX_TX_CAUSE_REG
1232 * MVPP2_ISR_RX_TX_MASK_REG
1233 * MVPP2_TXQ_NUM_REG
1234 * MVPP2_AGGR_TXQ_UPDATE_REG
1235 * MVPP2_TXQ_RSVD_REQ_REG
1236 * MVPP2_TXQ_RSVD_RSLT_REG
1237 * MVPP2_TXQ_SENT_REG
1238 * MVPP2_RXQ_NUM_REG
1239 *
1240 * - global registers that must be accessed through a specific CPU
1241 * window, because they are related to an access to a per-CPU
1242 * register
1243 *
1244 * MVPP2_BM_PHY_ALLOC_REG (related to MVPP2_BM_VIRT_ALLOC_REG)
1245 * MVPP2_BM_PHY_RLS_REG (related to MVPP2_BM_VIRT_RLS_REG)
1246 * MVPP2_RXQ_THRESH_REG (related to MVPP2_RXQ_NUM_REG)
1247 * MVPP2_RXQ_DESC_ADDR_REG (related to MVPP2_RXQ_NUM_REG)
1248 * MVPP2_RXQ_DESC_SIZE_REG (related to MVPP2_RXQ_NUM_REG)
1249 * MVPP2_RXQ_INDEX_REG (related to MVPP2_RXQ_NUM_REG)
1250 * MVPP2_TXQ_PENDING_REG (related to MVPP2_TXQ_NUM_REG)
1251 * MVPP2_TXQ_DESC_ADDR_REG (related to MVPP2_TXQ_NUM_REG)
1252 * MVPP2_TXQ_DESC_SIZE_REG (related to MVPP2_TXQ_NUM_REG)
1253 * MVPP2_TXQ_INDEX_REG (related to MVPP2_TXQ_NUM_REG)
1254 * MVPP2_TXQ_PENDING_REG (related to MVPP2_TXQ_NUM_REG)
1255 * MVPP2_TXQ_PREF_BUF_REG (related to MVPP2_TXQ_NUM_REG)
1256 * MVPP2_TXQ_PREF_BUF_REG (related to MVPP2_TXQ_NUM_REG)
1257 */
1258static void mvpp2_percpu_write(struct mvpp2 *priv, int cpu,
1259 u32 offset, u32 data)
1260{
Thomas Petazzonidf089aa2017-08-03 10:41:58 +02001261 writel(data, priv->swth_base[cpu] + offset);
Thomas Petazzonia7868412017-03-07 16:53:13 +01001262}
1263
1264static u32 mvpp2_percpu_read(struct mvpp2 *priv, int cpu,
1265 u32 offset)
1266{
Thomas Petazzonidf089aa2017-08-03 10:41:58 +02001267 return readl(priv->swth_base[cpu] + offset);
Marcin Wojtas3f518502014-07-10 16:52:13 -03001268}
1269
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001270static dma_addr_t mvpp2_txdesc_dma_addr_get(struct mvpp2_port *port,
1271 struct mvpp2_tx_desc *tx_desc)
1272{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001273 if (port->priv->hw_version == MVPP21)
1274 return tx_desc->pp21.buf_dma_addr;
1275 else
1276 return tx_desc->pp22.buf_dma_addr_ptp & GENMASK_ULL(40, 0);
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001277}
1278
1279static void mvpp2_txdesc_dma_addr_set(struct mvpp2_port *port,
1280 struct mvpp2_tx_desc *tx_desc,
1281 dma_addr_t dma_addr)
1282{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001283 if (port->priv->hw_version == MVPP21) {
1284 tx_desc->pp21.buf_dma_addr = dma_addr;
1285 } else {
1286 u64 val = (u64)dma_addr;
1287
1288 tx_desc->pp22.buf_dma_addr_ptp &= ~GENMASK_ULL(40, 0);
1289 tx_desc->pp22.buf_dma_addr_ptp |= val;
1290 }
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001291}
1292
1293static size_t mvpp2_txdesc_size_get(struct mvpp2_port *port,
1294 struct mvpp2_tx_desc *tx_desc)
1295{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001296 if (port->priv->hw_version == MVPP21)
1297 return tx_desc->pp21.data_size;
1298 else
1299 return tx_desc->pp22.data_size;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001300}
1301
1302static void mvpp2_txdesc_size_set(struct mvpp2_port *port,
1303 struct mvpp2_tx_desc *tx_desc,
1304 size_t size)
1305{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001306 if (port->priv->hw_version == MVPP21)
1307 tx_desc->pp21.data_size = size;
1308 else
1309 tx_desc->pp22.data_size = size;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001310}
1311
1312static void mvpp2_txdesc_txq_set(struct mvpp2_port *port,
1313 struct mvpp2_tx_desc *tx_desc,
1314 unsigned int txq)
1315{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001316 if (port->priv->hw_version == MVPP21)
1317 tx_desc->pp21.phys_txq = txq;
1318 else
1319 tx_desc->pp22.phys_txq = txq;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001320}
1321
1322static void mvpp2_txdesc_cmd_set(struct mvpp2_port *port,
1323 struct mvpp2_tx_desc *tx_desc,
1324 unsigned int command)
1325{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001326 if (port->priv->hw_version == MVPP21)
1327 tx_desc->pp21.command = command;
1328 else
1329 tx_desc->pp22.command = command;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001330}
1331
1332static void mvpp2_txdesc_offset_set(struct mvpp2_port *port,
1333 struct mvpp2_tx_desc *tx_desc,
1334 unsigned int offset)
1335{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001336 if (port->priv->hw_version == MVPP21)
1337 tx_desc->pp21.packet_offset = offset;
1338 else
1339 tx_desc->pp22.packet_offset = offset;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001340}
1341
1342static unsigned int mvpp2_txdesc_offset_get(struct mvpp2_port *port,
1343 struct mvpp2_tx_desc *tx_desc)
1344{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001345 if (port->priv->hw_version == MVPP21)
1346 return tx_desc->pp21.packet_offset;
1347 else
1348 return tx_desc->pp22.packet_offset;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001349}
1350
1351static dma_addr_t mvpp2_rxdesc_dma_addr_get(struct mvpp2_port *port,
1352 struct mvpp2_rx_desc *rx_desc)
1353{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001354 if (port->priv->hw_version == MVPP21)
1355 return rx_desc->pp21.buf_dma_addr;
1356 else
1357 return rx_desc->pp22.buf_dma_addr_key_hash & GENMASK_ULL(40, 0);
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001358}
1359
1360static unsigned long mvpp2_rxdesc_cookie_get(struct mvpp2_port *port,
1361 struct mvpp2_rx_desc *rx_desc)
1362{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001363 if (port->priv->hw_version == MVPP21)
1364 return rx_desc->pp21.buf_cookie;
1365 else
1366 return rx_desc->pp22.buf_cookie_misc & GENMASK_ULL(40, 0);
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001367}
1368
1369static size_t mvpp2_rxdesc_size_get(struct mvpp2_port *port,
1370 struct mvpp2_rx_desc *rx_desc)
1371{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001372 if (port->priv->hw_version == MVPP21)
1373 return rx_desc->pp21.data_size;
1374 else
1375 return rx_desc->pp22.data_size;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001376}
1377
1378static u32 mvpp2_rxdesc_status_get(struct mvpp2_port *port,
1379 struct mvpp2_rx_desc *rx_desc)
1380{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001381 if (port->priv->hw_version == MVPP21)
1382 return rx_desc->pp21.status;
1383 else
1384 return rx_desc->pp22.status;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001385}
1386
Marcin Wojtas3f518502014-07-10 16:52:13 -03001387static void mvpp2_txq_inc_get(struct mvpp2_txq_pcpu *txq_pcpu)
1388{
1389 txq_pcpu->txq_get_index++;
1390 if (txq_pcpu->txq_get_index == txq_pcpu->size)
1391 txq_pcpu->txq_get_index = 0;
1392}
1393
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001394static void mvpp2_txq_inc_put(struct mvpp2_port *port,
1395 struct mvpp2_txq_pcpu *txq_pcpu,
Marcin Wojtas71ce3912015-08-06 19:00:29 +02001396 struct sk_buff *skb,
1397 struct mvpp2_tx_desc *tx_desc)
Marcin Wojtas3f518502014-07-10 16:52:13 -03001398{
Thomas Petazzoni83544912016-12-21 11:28:49 +01001399 struct mvpp2_txq_pcpu_buf *tx_buf =
1400 txq_pcpu->buffs + txq_pcpu->txq_put_index;
1401 tx_buf->skb = skb;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001402 tx_buf->size = mvpp2_txdesc_size_get(port, tx_desc);
1403 tx_buf->dma = mvpp2_txdesc_dma_addr_get(port, tx_desc) +
1404 mvpp2_txdesc_offset_get(port, tx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03001405 txq_pcpu->txq_put_index++;
1406 if (txq_pcpu->txq_put_index == txq_pcpu->size)
1407 txq_pcpu->txq_put_index = 0;
1408}
1409
1410/* Get number of physical egress port */
1411static inline int mvpp2_egress_port(struct mvpp2_port *port)
1412{
1413 return MVPP2_MAX_TCONT + port->id;
1414}
1415
1416/* Get number of physical TXQ */
1417static inline int mvpp2_txq_phys(int port, int txq)
1418{
1419 return (MVPP2_MAX_TCONT + port) * MVPP2_MAX_TXQ + txq;
1420}
1421
1422/* Parser configuration routines */
1423
1424/* Update parser tcam and sram hw entries */
1425static int mvpp2_prs_hw_write(struct mvpp2 *priv, struct mvpp2_prs_entry *pe)
1426{
1427 int i;
1428
1429 if (pe->index > MVPP2_PRS_TCAM_SRAM_SIZE - 1)
1430 return -EINVAL;
1431
1432 /* Clear entry invalidation bit */
1433 pe->tcam.word[MVPP2_PRS_TCAM_INV_WORD] &= ~MVPP2_PRS_TCAM_INV_MASK;
1434
1435 /* Write tcam index - indirect access */
1436 mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, pe->index);
1437 for (i = 0; i < MVPP2_PRS_TCAM_WORDS; i++)
1438 mvpp2_write(priv, MVPP2_PRS_TCAM_DATA_REG(i), pe->tcam.word[i]);
1439
1440 /* Write sram index - indirect access */
1441 mvpp2_write(priv, MVPP2_PRS_SRAM_IDX_REG, pe->index);
1442 for (i = 0; i < MVPP2_PRS_SRAM_WORDS; i++)
1443 mvpp2_write(priv, MVPP2_PRS_SRAM_DATA_REG(i), pe->sram.word[i]);
1444
1445 return 0;
1446}
1447
1448/* Read tcam entry from hw */
1449static int mvpp2_prs_hw_read(struct mvpp2 *priv, struct mvpp2_prs_entry *pe)
1450{
1451 int i;
1452
1453 if (pe->index > MVPP2_PRS_TCAM_SRAM_SIZE - 1)
1454 return -EINVAL;
1455
1456 /* Write tcam index - indirect access */
1457 mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, pe->index);
1458
1459 pe->tcam.word[MVPP2_PRS_TCAM_INV_WORD] = mvpp2_read(priv,
1460 MVPP2_PRS_TCAM_DATA_REG(MVPP2_PRS_TCAM_INV_WORD));
1461 if (pe->tcam.word[MVPP2_PRS_TCAM_INV_WORD] & MVPP2_PRS_TCAM_INV_MASK)
1462 return MVPP2_PRS_TCAM_ENTRY_INVALID;
1463
1464 for (i = 0; i < MVPP2_PRS_TCAM_WORDS; i++)
1465 pe->tcam.word[i] = mvpp2_read(priv, MVPP2_PRS_TCAM_DATA_REG(i));
1466
1467 /* Write sram index - indirect access */
1468 mvpp2_write(priv, MVPP2_PRS_SRAM_IDX_REG, pe->index);
1469 for (i = 0; i < MVPP2_PRS_SRAM_WORDS; i++)
1470 pe->sram.word[i] = mvpp2_read(priv, MVPP2_PRS_SRAM_DATA_REG(i));
1471
1472 return 0;
1473}
1474
1475/* Invalidate tcam hw entry */
1476static void mvpp2_prs_hw_inv(struct mvpp2 *priv, int index)
1477{
1478 /* Write index - indirect access */
1479 mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, index);
1480 mvpp2_write(priv, MVPP2_PRS_TCAM_DATA_REG(MVPP2_PRS_TCAM_INV_WORD),
1481 MVPP2_PRS_TCAM_INV_MASK);
1482}
1483
1484/* Enable shadow table entry and set its lookup ID */
1485static void mvpp2_prs_shadow_set(struct mvpp2 *priv, int index, int lu)
1486{
1487 priv->prs_shadow[index].valid = true;
1488 priv->prs_shadow[index].lu = lu;
1489}
1490
1491/* Update ri fields in shadow table entry */
1492static void mvpp2_prs_shadow_ri_set(struct mvpp2 *priv, int index,
1493 unsigned int ri, unsigned int ri_mask)
1494{
1495 priv->prs_shadow[index].ri_mask = ri_mask;
1496 priv->prs_shadow[index].ri = ri;
1497}
1498
1499/* Update lookup field in tcam sw entry */
1500static void mvpp2_prs_tcam_lu_set(struct mvpp2_prs_entry *pe, unsigned int lu)
1501{
1502 int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_LU_BYTE);
1503
1504 pe->tcam.byte[MVPP2_PRS_TCAM_LU_BYTE] = lu;
1505 pe->tcam.byte[enable_off] = MVPP2_PRS_LU_MASK;
1506}
1507
1508/* Update mask for single port in tcam sw entry */
1509static void mvpp2_prs_tcam_port_set(struct mvpp2_prs_entry *pe,
1510 unsigned int port, bool add)
1511{
1512 int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_PORT_BYTE);
1513
1514 if (add)
1515 pe->tcam.byte[enable_off] &= ~(1 << port);
1516 else
1517 pe->tcam.byte[enable_off] |= 1 << port;
1518}
1519
1520/* Update port map in tcam sw entry */
1521static void mvpp2_prs_tcam_port_map_set(struct mvpp2_prs_entry *pe,
1522 unsigned int ports)
1523{
1524 unsigned char port_mask = MVPP2_PRS_PORT_MASK;
1525 int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_PORT_BYTE);
1526
1527 pe->tcam.byte[MVPP2_PRS_TCAM_PORT_BYTE] = 0;
1528 pe->tcam.byte[enable_off] &= ~port_mask;
1529 pe->tcam.byte[enable_off] |= ~ports & MVPP2_PRS_PORT_MASK;
1530}
1531
1532/* Obtain port map from tcam sw entry */
1533static unsigned int mvpp2_prs_tcam_port_map_get(struct mvpp2_prs_entry *pe)
1534{
1535 int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_PORT_BYTE);
1536
1537 return ~(pe->tcam.byte[enable_off]) & MVPP2_PRS_PORT_MASK;
1538}
1539
1540/* Set byte of data and its enable bits in tcam sw entry */
1541static void mvpp2_prs_tcam_data_byte_set(struct mvpp2_prs_entry *pe,
1542 unsigned int offs, unsigned char byte,
1543 unsigned char enable)
1544{
1545 pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE(offs)] = byte;
1546 pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE_EN(offs)] = enable;
1547}
1548
1549/* Get byte of data and its enable bits from tcam sw entry */
1550static void mvpp2_prs_tcam_data_byte_get(struct mvpp2_prs_entry *pe,
1551 unsigned int offs, unsigned char *byte,
1552 unsigned char *enable)
1553{
1554 *byte = pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE(offs)];
1555 *enable = pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE_EN(offs)];
1556}
1557
1558/* Compare tcam data bytes with a pattern */
1559static bool mvpp2_prs_tcam_data_cmp(struct mvpp2_prs_entry *pe, int offs,
1560 u16 data)
1561{
1562 int off = MVPP2_PRS_TCAM_DATA_BYTE(offs);
1563 u16 tcam_data;
1564
Antoine Tenartef4816f2017-10-24 11:41:26 +02001565 tcam_data = (pe->tcam.byte[off + 1] << 8) | pe->tcam.byte[off];
Marcin Wojtas3f518502014-07-10 16:52:13 -03001566 if (tcam_data != data)
1567 return false;
1568 return true;
1569}
1570
1571/* Update ai bits in tcam sw entry */
1572static void mvpp2_prs_tcam_ai_update(struct mvpp2_prs_entry *pe,
1573 unsigned int bits, unsigned int enable)
1574{
1575 int i, ai_idx = MVPP2_PRS_TCAM_AI_BYTE;
1576
1577 for (i = 0; i < MVPP2_PRS_AI_BITS; i++) {
1578
1579 if (!(enable & BIT(i)))
1580 continue;
1581
1582 if (bits & BIT(i))
1583 pe->tcam.byte[ai_idx] |= 1 << i;
1584 else
1585 pe->tcam.byte[ai_idx] &= ~(1 << i);
1586 }
1587
1588 pe->tcam.byte[MVPP2_PRS_TCAM_EN_OFFS(ai_idx)] |= enable;
1589}
1590
1591/* Get ai bits from tcam sw entry */
1592static int mvpp2_prs_tcam_ai_get(struct mvpp2_prs_entry *pe)
1593{
1594 return pe->tcam.byte[MVPP2_PRS_TCAM_AI_BYTE];
1595}
1596
1597/* Set ethertype in tcam sw entry */
1598static void mvpp2_prs_match_etype(struct mvpp2_prs_entry *pe, int offset,
1599 unsigned short ethertype)
1600{
1601 mvpp2_prs_tcam_data_byte_set(pe, offset + 0, ethertype >> 8, 0xff);
1602 mvpp2_prs_tcam_data_byte_set(pe, offset + 1, ethertype & 0xff, 0xff);
1603}
1604
1605/* Set bits in sram sw entry */
1606static void mvpp2_prs_sram_bits_set(struct mvpp2_prs_entry *pe, int bit_num,
1607 int val)
1608{
1609 pe->sram.byte[MVPP2_BIT_TO_BYTE(bit_num)] |= (val << (bit_num % 8));
1610}
1611
1612/* Clear bits in sram sw entry */
1613static void mvpp2_prs_sram_bits_clear(struct mvpp2_prs_entry *pe, int bit_num,
1614 int val)
1615{
1616 pe->sram.byte[MVPP2_BIT_TO_BYTE(bit_num)] &= ~(val << (bit_num % 8));
1617}
1618
1619/* Update ri bits in sram sw entry */
1620static void mvpp2_prs_sram_ri_update(struct mvpp2_prs_entry *pe,
1621 unsigned int bits, unsigned int mask)
1622{
1623 unsigned int i;
1624
1625 for (i = 0; i < MVPP2_PRS_SRAM_RI_CTRL_BITS; i++) {
1626 int ri_off = MVPP2_PRS_SRAM_RI_OFFS;
1627
1628 if (!(mask & BIT(i)))
1629 continue;
1630
1631 if (bits & BIT(i))
1632 mvpp2_prs_sram_bits_set(pe, ri_off + i, 1);
1633 else
1634 mvpp2_prs_sram_bits_clear(pe, ri_off + i, 1);
1635
1636 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_RI_CTRL_OFFS + i, 1);
1637 }
1638}
1639
1640/* Obtain ri bits from sram sw entry */
1641static int mvpp2_prs_sram_ri_get(struct mvpp2_prs_entry *pe)
1642{
1643 return pe->sram.word[MVPP2_PRS_SRAM_RI_WORD];
1644}
1645
1646/* Update ai bits in sram sw entry */
1647static void mvpp2_prs_sram_ai_update(struct mvpp2_prs_entry *pe,
1648 unsigned int bits, unsigned int mask)
1649{
1650 unsigned int i;
1651 int ai_off = MVPP2_PRS_SRAM_AI_OFFS;
1652
1653 for (i = 0; i < MVPP2_PRS_SRAM_AI_CTRL_BITS; i++) {
1654
1655 if (!(mask & BIT(i)))
1656 continue;
1657
1658 if (bits & BIT(i))
1659 mvpp2_prs_sram_bits_set(pe, ai_off + i, 1);
1660 else
1661 mvpp2_prs_sram_bits_clear(pe, ai_off + i, 1);
1662
1663 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_AI_CTRL_OFFS + i, 1);
1664 }
1665}
1666
1667/* Read ai bits from sram sw entry */
1668static int mvpp2_prs_sram_ai_get(struct mvpp2_prs_entry *pe)
1669{
1670 u8 bits;
1671 int ai_off = MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_AI_OFFS);
1672 int ai_en_off = ai_off + 1;
1673 int ai_shift = MVPP2_PRS_SRAM_AI_OFFS % 8;
1674
1675 bits = (pe->sram.byte[ai_off] >> ai_shift) |
1676 (pe->sram.byte[ai_en_off] << (8 - ai_shift));
1677
1678 return bits;
1679}
1680
1681/* In sram sw entry set lookup ID field of the tcam key to be used in the next
1682 * lookup interation
1683 */
1684static void mvpp2_prs_sram_next_lu_set(struct mvpp2_prs_entry *pe,
1685 unsigned int lu)
1686{
1687 int sram_next_off = MVPP2_PRS_SRAM_NEXT_LU_OFFS;
1688
1689 mvpp2_prs_sram_bits_clear(pe, sram_next_off,
1690 MVPP2_PRS_SRAM_NEXT_LU_MASK);
1691 mvpp2_prs_sram_bits_set(pe, sram_next_off, lu);
1692}
1693
1694/* In the sram sw entry set sign and value of the next lookup offset
1695 * and the offset value generated to the classifier
1696 */
1697static void mvpp2_prs_sram_shift_set(struct mvpp2_prs_entry *pe, int shift,
1698 unsigned int op)
1699{
1700 /* Set sign */
1701 if (shift < 0) {
1702 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_SHIFT_SIGN_BIT, 1);
1703 shift = 0 - shift;
1704 } else {
1705 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_SHIFT_SIGN_BIT, 1);
1706 }
1707
1708 /* Set value */
1709 pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_SHIFT_OFFS)] =
1710 (unsigned char)shift;
1711
1712 /* Reset and set operation */
1713 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_SHIFT_OFFS,
1714 MVPP2_PRS_SRAM_OP_SEL_SHIFT_MASK);
1715 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_OP_SEL_SHIFT_OFFS, op);
1716
1717 /* Set base offset as current */
1718 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_BASE_OFFS, 1);
1719}
1720
1721/* In the sram sw entry set sign and value of the user defined offset
1722 * generated to the classifier
1723 */
1724static void mvpp2_prs_sram_offset_set(struct mvpp2_prs_entry *pe,
1725 unsigned int type, int offset,
1726 unsigned int op)
1727{
1728 /* Set sign */
1729 if (offset < 0) {
1730 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_UDF_SIGN_BIT, 1);
1731 offset = 0 - offset;
1732 } else {
1733 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_UDF_SIGN_BIT, 1);
1734 }
1735
1736 /* Set value */
1737 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_UDF_OFFS,
1738 MVPP2_PRS_SRAM_UDF_MASK);
1739 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_UDF_OFFS, offset);
1740 pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_UDF_OFFS +
1741 MVPP2_PRS_SRAM_UDF_BITS)] &=
1742 ~(MVPP2_PRS_SRAM_UDF_MASK >> (8 - (MVPP2_PRS_SRAM_UDF_OFFS % 8)));
1743 pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_UDF_OFFS +
1744 MVPP2_PRS_SRAM_UDF_BITS)] |=
1745 (offset >> (8 - (MVPP2_PRS_SRAM_UDF_OFFS % 8)));
1746
1747 /* Set offset type */
1748 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_UDF_TYPE_OFFS,
1749 MVPP2_PRS_SRAM_UDF_TYPE_MASK);
1750 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_UDF_TYPE_OFFS, type);
1751
1752 /* Set offset operation */
1753 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS,
1754 MVPP2_PRS_SRAM_OP_SEL_UDF_MASK);
1755 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS, op);
1756
1757 pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS +
1758 MVPP2_PRS_SRAM_OP_SEL_UDF_BITS)] &=
1759 ~(MVPP2_PRS_SRAM_OP_SEL_UDF_MASK >>
1760 (8 - (MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS % 8)));
1761
1762 pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS +
1763 MVPP2_PRS_SRAM_OP_SEL_UDF_BITS)] |=
1764 (op >> (8 - (MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS % 8)));
1765
1766 /* Set base offset as current */
1767 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_BASE_OFFS, 1);
1768}
1769
1770/* Find parser flow entry */
1771static struct mvpp2_prs_entry *mvpp2_prs_flow_find(struct mvpp2 *priv, int flow)
1772{
1773 struct mvpp2_prs_entry *pe;
1774 int tid;
1775
1776 pe = kzalloc(sizeof(*pe), GFP_KERNEL);
1777 if (!pe)
1778 return NULL;
1779 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_FLOWS);
1780
1781 /* Go through the all entires with MVPP2_PRS_LU_FLOWS */
1782 for (tid = MVPP2_PRS_TCAM_SRAM_SIZE - 1; tid >= 0; tid--) {
1783 u8 bits;
1784
1785 if (!priv->prs_shadow[tid].valid ||
1786 priv->prs_shadow[tid].lu != MVPP2_PRS_LU_FLOWS)
1787 continue;
1788
1789 pe->index = tid;
1790 mvpp2_prs_hw_read(priv, pe);
1791 bits = mvpp2_prs_sram_ai_get(pe);
1792
1793 /* Sram store classification lookup ID in AI bits [5:0] */
1794 if ((bits & MVPP2_PRS_FLOW_ID_MASK) == flow)
1795 return pe;
1796 }
1797 kfree(pe);
1798
1799 return NULL;
1800}
1801
1802/* Return first free tcam index, seeking from start to end */
1803static int mvpp2_prs_tcam_first_free(struct mvpp2 *priv, unsigned char start,
1804 unsigned char end)
1805{
1806 int tid;
1807
1808 if (start > end)
1809 swap(start, end);
1810
1811 if (end >= MVPP2_PRS_TCAM_SRAM_SIZE)
1812 end = MVPP2_PRS_TCAM_SRAM_SIZE - 1;
1813
1814 for (tid = start; tid <= end; tid++) {
1815 if (!priv->prs_shadow[tid].valid)
1816 return tid;
1817 }
1818
1819 return -EINVAL;
1820}
1821
1822/* Enable/disable dropping all mac da's */
1823static void mvpp2_prs_mac_drop_all_set(struct mvpp2 *priv, int port, bool add)
1824{
1825 struct mvpp2_prs_entry pe;
1826
1827 if (priv->prs_shadow[MVPP2_PE_DROP_ALL].valid) {
1828 /* Entry exist - update port only */
1829 pe.index = MVPP2_PE_DROP_ALL;
1830 mvpp2_prs_hw_read(priv, &pe);
1831 } else {
1832 /* Entry doesn't exist - create new */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02001833 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03001834 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC);
1835 pe.index = MVPP2_PE_DROP_ALL;
1836
1837 /* Non-promiscuous mode for all ports - DROP unknown packets */
1838 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_DROP_MASK,
1839 MVPP2_PRS_RI_DROP_MASK);
1840
1841 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
1842 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
1843
1844 /* Update shadow table */
1845 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC);
1846
1847 /* Mask all ports */
1848 mvpp2_prs_tcam_port_map_set(&pe, 0);
1849 }
1850
1851 /* Update port mask */
1852 mvpp2_prs_tcam_port_set(&pe, port, add);
1853
1854 mvpp2_prs_hw_write(priv, &pe);
1855}
1856
1857/* Set port to promiscuous mode */
1858static void mvpp2_prs_mac_promisc_set(struct mvpp2 *priv, int port, bool add)
1859{
1860 struct mvpp2_prs_entry pe;
1861
Joe Perchesdbedd442015-03-06 20:49:12 -08001862 /* Promiscuous mode - Accept unknown packets */
Marcin Wojtas3f518502014-07-10 16:52:13 -03001863
1864 if (priv->prs_shadow[MVPP2_PE_MAC_PROMISCUOUS].valid) {
1865 /* Entry exist - update port only */
1866 pe.index = MVPP2_PE_MAC_PROMISCUOUS;
1867 mvpp2_prs_hw_read(priv, &pe);
1868 } else {
1869 /* Entry doesn't exist - create new */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02001870 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03001871 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC);
1872 pe.index = MVPP2_PE_MAC_PROMISCUOUS;
1873
1874 /* Continue - set next lookup */
1875 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_DSA);
1876
1877 /* Set result info bits */
1878 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L2_UCAST,
1879 MVPP2_PRS_RI_L2_CAST_MASK);
1880
1881 /* Shift to ethertype */
1882 mvpp2_prs_sram_shift_set(&pe, 2 * ETH_ALEN,
1883 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
1884
1885 /* Mask all ports */
1886 mvpp2_prs_tcam_port_map_set(&pe, 0);
1887
1888 /* Update shadow table */
1889 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC);
1890 }
1891
1892 /* Update port mask */
1893 mvpp2_prs_tcam_port_set(&pe, port, add);
1894
1895 mvpp2_prs_hw_write(priv, &pe);
1896}
1897
1898/* Accept multicast */
1899static void mvpp2_prs_mac_multi_set(struct mvpp2 *priv, int port, int index,
1900 bool add)
1901{
1902 struct mvpp2_prs_entry pe;
1903 unsigned char da_mc;
1904
1905 /* Ethernet multicast address first byte is
1906 * 0x01 for IPv4 and 0x33 for IPv6
1907 */
1908 da_mc = (index == MVPP2_PE_MAC_MC_ALL) ? 0x01 : 0x33;
1909
1910 if (priv->prs_shadow[index].valid) {
1911 /* Entry exist - update port only */
1912 pe.index = index;
1913 mvpp2_prs_hw_read(priv, &pe);
1914 } else {
1915 /* Entry doesn't exist - create new */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02001916 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03001917 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC);
1918 pe.index = index;
1919
1920 /* Continue - set next lookup */
1921 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_DSA);
1922
1923 /* Set result info bits */
1924 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L2_MCAST,
1925 MVPP2_PRS_RI_L2_CAST_MASK);
1926
1927 /* Update tcam entry data first byte */
1928 mvpp2_prs_tcam_data_byte_set(&pe, 0, da_mc, 0xff);
1929
1930 /* Shift to ethertype */
1931 mvpp2_prs_sram_shift_set(&pe, 2 * ETH_ALEN,
1932 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
1933
1934 /* Mask all ports */
1935 mvpp2_prs_tcam_port_map_set(&pe, 0);
1936
1937 /* Update shadow table */
1938 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC);
1939 }
1940
1941 /* Update port mask */
1942 mvpp2_prs_tcam_port_set(&pe, port, add);
1943
1944 mvpp2_prs_hw_write(priv, &pe);
1945}
1946
1947/* Set entry for dsa packets */
1948static void mvpp2_prs_dsa_tag_set(struct mvpp2 *priv, int port, bool add,
1949 bool tagged, bool extend)
1950{
1951 struct mvpp2_prs_entry pe;
1952 int tid, shift;
1953
1954 if (extend) {
1955 tid = tagged ? MVPP2_PE_EDSA_TAGGED : MVPP2_PE_EDSA_UNTAGGED;
1956 shift = 8;
1957 } else {
1958 tid = tagged ? MVPP2_PE_DSA_TAGGED : MVPP2_PE_DSA_UNTAGGED;
1959 shift = 4;
1960 }
1961
1962 if (priv->prs_shadow[tid].valid) {
1963 /* Entry exist - update port only */
1964 pe.index = tid;
1965 mvpp2_prs_hw_read(priv, &pe);
1966 } else {
1967 /* Entry doesn't exist - create new */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02001968 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03001969 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_DSA);
1970 pe.index = tid;
1971
1972 /* Shift 4 bytes if DSA tag or 8 bytes in case of EDSA tag*/
1973 mvpp2_prs_sram_shift_set(&pe, shift,
1974 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
1975
1976 /* Update shadow table */
1977 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_DSA);
1978
1979 if (tagged) {
1980 /* Set tagged bit in DSA tag */
1981 mvpp2_prs_tcam_data_byte_set(&pe, 0,
1982 MVPP2_PRS_TCAM_DSA_TAGGED_BIT,
1983 MVPP2_PRS_TCAM_DSA_TAGGED_BIT);
1984 /* Clear all ai bits for next iteration */
1985 mvpp2_prs_sram_ai_update(&pe, 0,
1986 MVPP2_PRS_SRAM_AI_MASK);
1987 /* If packet is tagged continue check vlans */
1988 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_VLAN);
1989 } else {
1990 /* Set result info bits to 'no vlans' */
1991 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_NONE,
1992 MVPP2_PRS_RI_VLAN_MASK);
1993 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2);
1994 }
1995
1996 /* Mask all ports */
1997 mvpp2_prs_tcam_port_map_set(&pe, 0);
1998 }
1999
2000 /* Update port mask */
2001 mvpp2_prs_tcam_port_set(&pe, port, add);
2002
2003 mvpp2_prs_hw_write(priv, &pe);
2004}
2005
2006/* Set entry for dsa ethertype */
2007static void mvpp2_prs_dsa_tag_ethertype_set(struct mvpp2 *priv, int port,
2008 bool add, bool tagged, bool extend)
2009{
2010 struct mvpp2_prs_entry pe;
2011 int tid, shift, port_mask;
2012
2013 if (extend) {
2014 tid = tagged ? MVPP2_PE_ETYPE_EDSA_TAGGED :
2015 MVPP2_PE_ETYPE_EDSA_UNTAGGED;
2016 port_mask = 0;
2017 shift = 8;
2018 } else {
2019 tid = tagged ? MVPP2_PE_ETYPE_DSA_TAGGED :
2020 MVPP2_PE_ETYPE_DSA_UNTAGGED;
2021 port_mask = MVPP2_PRS_PORT_MASK;
2022 shift = 4;
2023 }
2024
2025 if (priv->prs_shadow[tid].valid) {
2026 /* Entry exist - update port only */
2027 pe.index = tid;
2028 mvpp2_prs_hw_read(priv, &pe);
2029 } else {
2030 /* Entry doesn't exist - create new */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002031 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002032 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_DSA);
2033 pe.index = tid;
2034
2035 /* Set ethertype */
2036 mvpp2_prs_match_etype(&pe, 0, ETH_P_EDSA);
2037 mvpp2_prs_match_etype(&pe, 2, 0);
2038
2039 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_DSA_MASK,
2040 MVPP2_PRS_RI_DSA_MASK);
2041 /* Shift ethertype + 2 byte reserved + tag*/
2042 mvpp2_prs_sram_shift_set(&pe, 2 + MVPP2_ETH_TYPE_LEN + shift,
2043 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2044
2045 /* Update shadow table */
2046 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_DSA);
2047
2048 if (tagged) {
2049 /* Set tagged bit in DSA tag */
2050 mvpp2_prs_tcam_data_byte_set(&pe,
2051 MVPP2_ETH_TYPE_LEN + 2 + 3,
2052 MVPP2_PRS_TCAM_DSA_TAGGED_BIT,
2053 MVPP2_PRS_TCAM_DSA_TAGGED_BIT);
2054 /* Clear all ai bits for next iteration */
2055 mvpp2_prs_sram_ai_update(&pe, 0,
2056 MVPP2_PRS_SRAM_AI_MASK);
2057 /* If packet is tagged continue check vlans */
2058 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_VLAN);
2059 } else {
2060 /* Set result info bits to 'no vlans' */
2061 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_NONE,
2062 MVPP2_PRS_RI_VLAN_MASK);
2063 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2);
2064 }
2065 /* Mask/unmask all ports, depending on dsa type */
2066 mvpp2_prs_tcam_port_map_set(&pe, port_mask);
2067 }
2068
2069 /* Update port mask */
2070 mvpp2_prs_tcam_port_set(&pe, port, add);
2071
2072 mvpp2_prs_hw_write(priv, &pe);
2073}
2074
2075/* Search for existing single/triple vlan entry */
2076static struct mvpp2_prs_entry *mvpp2_prs_vlan_find(struct mvpp2 *priv,
2077 unsigned short tpid, int ai)
2078{
2079 struct mvpp2_prs_entry *pe;
2080 int tid;
2081
2082 pe = kzalloc(sizeof(*pe), GFP_KERNEL);
2083 if (!pe)
2084 return NULL;
2085 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN);
2086
2087 /* Go through the all entries with MVPP2_PRS_LU_VLAN */
2088 for (tid = MVPP2_PE_FIRST_FREE_TID;
2089 tid <= MVPP2_PE_LAST_FREE_TID; tid++) {
2090 unsigned int ri_bits, ai_bits;
2091 bool match;
2092
2093 if (!priv->prs_shadow[tid].valid ||
2094 priv->prs_shadow[tid].lu != MVPP2_PRS_LU_VLAN)
2095 continue;
2096
2097 pe->index = tid;
2098
2099 mvpp2_prs_hw_read(priv, pe);
2100 match = mvpp2_prs_tcam_data_cmp(pe, 0, swab16(tpid));
2101 if (!match)
2102 continue;
2103
2104 /* Get vlan type */
2105 ri_bits = mvpp2_prs_sram_ri_get(pe);
2106 ri_bits &= MVPP2_PRS_RI_VLAN_MASK;
2107
2108 /* Get current ai value from tcam */
2109 ai_bits = mvpp2_prs_tcam_ai_get(pe);
2110 /* Clear double vlan bit */
2111 ai_bits &= ~MVPP2_PRS_DBL_VLAN_AI_BIT;
2112
2113 if (ai != ai_bits)
2114 continue;
2115
2116 if (ri_bits == MVPP2_PRS_RI_VLAN_SINGLE ||
2117 ri_bits == MVPP2_PRS_RI_VLAN_TRIPLE)
2118 return pe;
2119 }
2120 kfree(pe);
2121
2122 return NULL;
2123}
2124
2125/* Add/update single/triple vlan entry */
2126static int mvpp2_prs_vlan_add(struct mvpp2 *priv, unsigned short tpid, int ai,
2127 unsigned int port_map)
2128{
2129 struct mvpp2_prs_entry *pe;
2130 int tid_aux, tid;
Sudip Mukherjee43737472014-11-01 16:59:34 +05302131 int ret = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03002132
2133 pe = mvpp2_prs_vlan_find(priv, tpid, ai);
2134
2135 if (!pe) {
2136 /* Create new tcam entry */
2137 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_LAST_FREE_TID,
2138 MVPP2_PE_FIRST_FREE_TID);
2139 if (tid < 0)
2140 return tid;
2141
2142 pe = kzalloc(sizeof(*pe), GFP_KERNEL);
2143 if (!pe)
2144 return -ENOMEM;
2145
2146 /* Get last double vlan tid */
2147 for (tid_aux = MVPP2_PE_LAST_FREE_TID;
2148 tid_aux >= MVPP2_PE_FIRST_FREE_TID; tid_aux--) {
2149 unsigned int ri_bits;
2150
2151 if (!priv->prs_shadow[tid_aux].valid ||
2152 priv->prs_shadow[tid_aux].lu != MVPP2_PRS_LU_VLAN)
2153 continue;
2154
2155 pe->index = tid_aux;
2156 mvpp2_prs_hw_read(priv, pe);
2157 ri_bits = mvpp2_prs_sram_ri_get(pe);
2158 if ((ri_bits & MVPP2_PRS_RI_VLAN_MASK) ==
2159 MVPP2_PRS_RI_VLAN_DOUBLE)
2160 break;
2161 }
2162
Sudip Mukherjee43737472014-11-01 16:59:34 +05302163 if (tid <= tid_aux) {
2164 ret = -EINVAL;
Markus Elfringf9fd0e32017-04-17 13:50:35 +02002165 goto free_pe;
Sudip Mukherjee43737472014-11-01 16:59:34 +05302166 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03002167
Markus Elfringbd6aaf52017-04-17 10:40:32 +02002168 memset(pe, 0, sizeof(*pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002169 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN);
2170 pe->index = tid;
2171
2172 mvpp2_prs_match_etype(pe, 0, tpid);
2173
2174 mvpp2_prs_sram_next_lu_set(pe, MVPP2_PRS_LU_L2);
2175 /* Shift 4 bytes - skip 1 vlan tag */
2176 mvpp2_prs_sram_shift_set(pe, MVPP2_VLAN_TAG_LEN,
2177 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2178 /* Clear all ai bits for next iteration */
2179 mvpp2_prs_sram_ai_update(pe, 0, MVPP2_PRS_SRAM_AI_MASK);
2180
2181 if (ai == MVPP2_PRS_SINGLE_VLAN_AI) {
2182 mvpp2_prs_sram_ri_update(pe, MVPP2_PRS_RI_VLAN_SINGLE,
2183 MVPP2_PRS_RI_VLAN_MASK);
2184 } else {
2185 ai |= MVPP2_PRS_DBL_VLAN_AI_BIT;
2186 mvpp2_prs_sram_ri_update(pe, MVPP2_PRS_RI_VLAN_TRIPLE,
2187 MVPP2_PRS_RI_VLAN_MASK);
2188 }
2189 mvpp2_prs_tcam_ai_update(pe, ai, MVPP2_PRS_SRAM_AI_MASK);
2190
2191 mvpp2_prs_shadow_set(priv, pe->index, MVPP2_PRS_LU_VLAN);
2192 }
2193 /* Update ports' mask */
2194 mvpp2_prs_tcam_port_map_set(pe, port_map);
2195
2196 mvpp2_prs_hw_write(priv, pe);
Markus Elfringf9fd0e32017-04-17 13:50:35 +02002197free_pe:
Marcin Wojtas3f518502014-07-10 16:52:13 -03002198 kfree(pe);
2199
Sudip Mukherjee43737472014-11-01 16:59:34 +05302200 return ret;
Marcin Wojtas3f518502014-07-10 16:52:13 -03002201}
2202
2203/* Get first free double vlan ai number */
2204static int mvpp2_prs_double_vlan_ai_free_get(struct mvpp2 *priv)
2205{
2206 int i;
2207
2208 for (i = 1; i < MVPP2_PRS_DBL_VLANS_MAX; i++) {
2209 if (!priv->prs_double_vlans[i])
2210 return i;
2211 }
2212
2213 return -EINVAL;
2214}
2215
2216/* Search for existing double vlan entry */
2217static struct mvpp2_prs_entry *mvpp2_prs_double_vlan_find(struct mvpp2 *priv,
2218 unsigned short tpid1,
2219 unsigned short tpid2)
2220{
2221 struct mvpp2_prs_entry *pe;
2222 int tid;
2223
2224 pe = kzalloc(sizeof(*pe), GFP_KERNEL);
2225 if (!pe)
2226 return NULL;
2227 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN);
2228
2229 /* Go through the all entries with MVPP2_PRS_LU_VLAN */
2230 for (tid = MVPP2_PE_FIRST_FREE_TID;
2231 tid <= MVPP2_PE_LAST_FREE_TID; tid++) {
2232 unsigned int ri_mask;
2233 bool match;
2234
2235 if (!priv->prs_shadow[tid].valid ||
2236 priv->prs_shadow[tid].lu != MVPP2_PRS_LU_VLAN)
2237 continue;
2238
2239 pe->index = tid;
2240 mvpp2_prs_hw_read(priv, pe);
2241
2242 match = mvpp2_prs_tcam_data_cmp(pe, 0, swab16(tpid1))
2243 && mvpp2_prs_tcam_data_cmp(pe, 4, swab16(tpid2));
2244
2245 if (!match)
2246 continue;
2247
2248 ri_mask = mvpp2_prs_sram_ri_get(pe) & MVPP2_PRS_RI_VLAN_MASK;
2249 if (ri_mask == MVPP2_PRS_RI_VLAN_DOUBLE)
2250 return pe;
2251 }
2252 kfree(pe);
2253
2254 return NULL;
2255}
2256
2257/* Add or update double vlan entry */
2258static int mvpp2_prs_double_vlan_add(struct mvpp2 *priv, unsigned short tpid1,
2259 unsigned short tpid2,
2260 unsigned int port_map)
2261{
2262 struct mvpp2_prs_entry *pe;
Sudip Mukherjee43737472014-11-01 16:59:34 +05302263 int tid_aux, tid, ai, ret = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03002264
2265 pe = mvpp2_prs_double_vlan_find(priv, tpid1, tpid2);
2266
2267 if (!pe) {
2268 /* Create new tcam entry */
2269 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2270 MVPP2_PE_LAST_FREE_TID);
2271 if (tid < 0)
2272 return tid;
2273
2274 pe = kzalloc(sizeof(*pe), GFP_KERNEL);
2275 if (!pe)
2276 return -ENOMEM;
2277
2278 /* Set ai value for new double vlan entry */
2279 ai = mvpp2_prs_double_vlan_ai_free_get(priv);
Sudip Mukherjee43737472014-11-01 16:59:34 +05302280 if (ai < 0) {
2281 ret = ai;
Markus Elfringc9a7e122017-04-17 13:03:49 +02002282 goto free_pe;
Sudip Mukherjee43737472014-11-01 16:59:34 +05302283 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03002284
2285 /* Get first single/triple vlan tid */
2286 for (tid_aux = MVPP2_PE_FIRST_FREE_TID;
2287 tid_aux <= MVPP2_PE_LAST_FREE_TID; tid_aux++) {
2288 unsigned int ri_bits;
2289
2290 if (!priv->prs_shadow[tid_aux].valid ||
2291 priv->prs_shadow[tid_aux].lu != MVPP2_PRS_LU_VLAN)
2292 continue;
2293
2294 pe->index = tid_aux;
2295 mvpp2_prs_hw_read(priv, pe);
2296 ri_bits = mvpp2_prs_sram_ri_get(pe);
2297 ri_bits &= MVPP2_PRS_RI_VLAN_MASK;
2298 if (ri_bits == MVPP2_PRS_RI_VLAN_SINGLE ||
2299 ri_bits == MVPP2_PRS_RI_VLAN_TRIPLE)
2300 break;
2301 }
2302
Sudip Mukherjee43737472014-11-01 16:59:34 +05302303 if (tid >= tid_aux) {
2304 ret = -ERANGE;
Markus Elfringc9a7e122017-04-17 13:03:49 +02002305 goto free_pe;
Sudip Mukherjee43737472014-11-01 16:59:34 +05302306 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03002307
Markus Elfringbd6aaf52017-04-17 10:40:32 +02002308 memset(pe, 0, sizeof(*pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002309 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN);
2310 pe->index = tid;
2311
2312 priv->prs_double_vlans[ai] = true;
2313
2314 mvpp2_prs_match_etype(pe, 0, tpid1);
2315 mvpp2_prs_match_etype(pe, 4, tpid2);
2316
2317 mvpp2_prs_sram_next_lu_set(pe, MVPP2_PRS_LU_VLAN);
2318 /* Shift 8 bytes - skip 2 vlan tags */
2319 mvpp2_prs_sram_shift_set(pe, 2 * MVPP2_VLAN_TAG_LEN,
2320 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2321 mvpp2_prs_sram_ri_update(pe, MVPP2_PRS_RI_VLAN_DOUBLE,
2322 MVPP2_PRS_RI_VLAN_MASK);
2323 mvpp2_prs_sram_ai_update(pe, ai | MVPP2_PRS_DBL_VLAN_AI_BIT,
2324 MVPP2_PRS_SRAM_AI_MASK);
2325
2326 mvpp2_prs_shadow_set(priv, pe->index, MVPP2_PRS_LU_VLAN);
2327 }
2328
2329 /* Update ports' mask */
2330 mvpp2_prs_tcam_port_map_set(pe, port_map);
2331 mvpp2_prs_hw_write(priv, pe);
Markus Elfringc9a7e122017-04-17 13:03:49 +02002332free_pe:
Marcin Wojtas3f518502014-07-10 16:52:13 -03002333 kfree(pe);
Sudip Mukherjee43737472014-11-01 16:59:34 +05302334 return ret;
Marcin Wojtas3f518502014-07-10 16:52:13 -03002335}
2336
2337/* IPv4 header parsing for fragmentation and L4 offset */
2338static int mvpp2_prs_ip4_proto(struct mvpp2 *priv, unsigned short proto,
2339 unsigned int ri, unsigned int ri_mask)
2340{
2341 struct mvpp2_prs_entry pe;
2342 int tid;
2343
2344 if ((proto != IPPROTO_TCP) && (proto != IPPROTO_UDP) &&
2345 (proto != IPPROTO_IGMP))
2346 return -EINVAL;
2347
Stefan Chulskiaff3da32017-09-25 14:59:46 +02002348 /* Not fragmented packet */
Marcin Wojtas3f518502014-07-10 16:52:13 -03002349 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2350 MVPP2_PE_LAST_FREE_TID);
2351 if (tid < 0)
2352 return tid;
2353
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002354 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002355 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4);
2356 pe.index = tid;
2357
2358 /* Set next lu to IPv4 */
2359 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4);
2360 mvpp2_prs_sram_shift_set(&pe, 12, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2361 /* Set L4 offset */
2362 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4,
2363 sizeof(struct iphdr) - 4,
2364 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
2365 mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT,
2366 MVPP2_PRS_IPV4_DIP_AI_BIT);
Stefan Chulskiaff3da32017-09-25 14:59:46 +02002367 mvpp2_prs_sram_ri_update(&pe, ri, ri_mask | MVPP2_PRS_RI_IP_FRAG_MASK);
2368
2369 mvpp2_prs_tcam_data_byte_set(&pe, 2, 0x00,
2370 MVPP2_PRS_TCAM_PROTO_MASK_L);
2371 mvpp2_prs_tcam_data_byte_set(&pe, 3, 0x00,
2372 MVPP2_PRS_TCAM_PROTO_MASK);
Marcin Wojtas3f518502014-07-10 16:52:13 -03002373
2374 mvpp2_prs_tcam_data_byte_set(&pe, 5, proto, MVPP2_PRS_TCAM_PROTO_MASK);
2375 mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV4_DIP_AI_BIT);
2376 /* Unmask all ports */
2377 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2378
2379 /* Update shadow table and hw entry */
2380 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
2381 mvpp2_prs_hw_write(priv, &pe);
2382
Stefan Chulskiaff3da32017-09-25 14:59:46 +02002383 /* Fragmented packet */
Marcin Wojtas3f518502014-07-10 16:52:13 -03002384 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2385 MVPP2_PE_LAST_FREE_TID);
2386 if (tid < 0)
2387 return tid;
2388
2389 pe.index = tid;
2390 /* Clear ri before updating */
2391 pe.sram.word[MVPP2_PRS_SRAM_RI_WORD] = 0x0;
2392 pe.sram.word[MVPP2_PRS_SRAM_RI_CTRL_WORD] = 0x0;
2393 mvpp2_prs_sram_ri_update(&pe, ri, ri_mask);
2394
Stefan Chulskiaff3da32017-09-25 14:59:46 +02002395 mvpp2_prs_sram_ri_update(&pe, ri | MVPP2_PRS_RI_IP_FRAG_TRUE,
2396 ri_mask | MVPP2_PRS_RI_IP_FRAG_MASK);
2397
2398 mvpp2_prs_tcam_data_byte_set(&pe, 2, 0x00, 0x0);
2399 mvpp2_prs_tcam_data_byte_set(&pe, 3, 0x00, 0x0);
Marcin Wojtas3f518502014-07-10 16:52:13 -03002400
2401 /* Update shadow table and hw entry */
2402 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
2403 mvpp2_prs_hw_write(priv, &pe);
2404
2405 return 0;
2406}
2407
2408/* IPv4 L3 multicast or broadcast */
2409static int mvpp2_prs_ip4_cast(struct mvpp2 *priv, unsigned short l3_cast)
2410{
2411 struct mvpp2_prs_entry pe;
2412 int mask, tid;
2413
2414 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2415 MVPP2_PE_LAST_FREE_TID);
2416 if (tid < 0)
2417 return tid;
2418
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002419 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002420 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4);
2421 pe.index = tid;
2422
2423 switch (l3_cast) {
2424 case MVPP2_PRS_L3_MULTI_CAST:
2425 mvpp2_prs_tcam_data_byte_set(&pe, 0, MVPP2_PRS_IPV4_MC,
2426 MVPP2_PRS_IPV4_MC_MASK);
2427 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_MCAST,
2428 MVPP2_PRS_RI_L3_ADDR_MASK);
2429 break;
2430 case MVPP2_PRS_L3_BROAD_CAST:
2431 mask = MVPP2_PRS_IPV4_BC_MASK;
2432 mvpp2_prs_tcam_data_byte_set(&pe, 0, mask, mask);
2433 mvpp2_prs_tcam_data_byte_set(&pe, 1, mask, mask);
2434 mvpp2_prs_tcam_data_byte_set(&pe, 2, mask, mask);
2435 mvpp2_prs_tcam_data_byte_set(&pe, 3, mask, mask);
2436 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_BCAST,
2437 MVPP2_PRS_RI_L3_ADDR_MASK);
2438 break;
2439 default:
2440 return -EINVAL;
2441 }
2442
2443 /* Finished: go to flowid generation */
2444 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
2445 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
2446
2447 mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT,
2448 MVPP2_PRS_IPV4_DIP_AI_BIT);
2449 /* Unmask all ports */
2450 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2451
2452 /* Update shadow table and hw entry */
2453 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
2454 mvpp2_prs_hw_write(priv, &pe);
2455
2456 return 0;
2457}
2458
2459/* Set entries for protocols over IPv6 */
2460static int mvpp2_prs_ip6_proto(struct mvpp2 *priv, unsigned short proto,
2461 unsigned int ri, unsigned int ri_mask)
2462{
2463 struct mvpp2_prs_entry pe;
2464 int tid;
2465
2466 if ((proto != IPPROTO_TCP) && (proto != IPPROTO_UDP) &&
2467 (proto != IPPROTO_ICMPV6) && (proto != IPPROTO_IPIP))
2468 return -EINVAL;
2469
2470 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2471 MVPP2_PE_LAST_FREE_TID);
2472 if (tid < 0)
2473 return tid;
2474
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002475 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002476 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6);
2477 pe.index = tid;
2478
2479 /* Finished: go to flowid generation */
2480 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
2481 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
2482 mvpp2_prs_sram_ri_update(&pe, ri, ri_mask);
2483 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4,
2484 sizeof(struct ipv6hdr) - 6,
2485 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
2486
2487 mvpp2_prs_tcam_data_byte_set(&pe, 0, proto, MVPP2_PRS_TCAM_PROTO_MASK);
2488 mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT,
2489 MVPP2_PRS_IPV6_NO_EXT_AI_BIT);
2490 /* Unmask all ports */
2491 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2492
2493 /* Write HW */
2494 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP6);
2495 mvpp2_prs_hw_write(priv, &pe);
2496
2497 return 0;
2498}
2499
2500/* IPv6 L3 multicast entry */
2501static int mvpp2_prs_ip6_cast(struct mvpp2 *priv, unsigned short l3_cast)
2502{
2503 struct mvpp2_prs_entry pe;
2504 int tid;
2505
2506 if (l3_cast != MVPP2_PRS_L3_MULTI_CAST)
2507 return -EINVAL;
2508
2509 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2510 MVPP2_PE_LAST_FREE_TID);
2511 if (tid < 0)
2512 return tid;
2513
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002514 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002515 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6);
2516 pe.index = tid;
2517
2518 /* Finished: go to flowid generation */
2519 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6);
2520 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_MCAST,
2521 MVPP2_PRS_RI_L3_ADDR_MASK);
2522 mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT,
2523 MVPP2_PRS_IPV6_NO_EXT_AI_BIT);
2524 /* Shift back to IPv6 NH */
2525 mvpp2_prs_sram_shift_set(&pe, -18, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2526
2527 mvpp2_prs_tcam_data_byte_set(&pe, 0, MVPP2_PRS_IPV6_MC,
2528 MVPP2_PRS_IPV6_MC_MASK);
2529 mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV6_NO_EXT_AI_BIT);
2530 /* Unmask all ports */
2531 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2532
2533 /* Update shadow table and hw entry */
2534 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP6);
2535 mvpp2_prs_hw_write(priv, &pe);
2536
2537 return 0;
2538}
2539
2540/* Parser per-port initialization */
2541static void mvpp2_prs_hw_port_init(struct mvpp2 *priv, int port, int lu_first,
2542 int lu_max, int offset)
2543{
2544 u32 val;
2545
2546 /* Set lookup ID */
2547 val = mvpp2_read(priv, MVPP2_PRS_INIT_LOOKUP_REG);
2548 val &= ~MVPP2_PRS_PORT_LU_MASK(port);
2549 val |= MVPP2_PRS_PORT_LU_VAL(port, lu_first);
2550 mvpp2_write(priv, MVPP2_PRS_INIT_LOOKUP_REG, val);
2551
2552 /* Set maximum number of loops for packet received from port */
2553 val = mvpp2_read(priv, MVPP2_PRS_MAX_LOOP_REG(port));
2554 val &= ~MVPP2_PRS_MAX_LOOP_MASK(port);
2555 val |= MVPP2_PRS_MAX_LOOP_VAL(port, lu_max);
2556 mvpp2_write(priv, MVPP2_PRS_MAX_LOOP_REG(port), val);
2557
2558 /* Set initial offset for packet header extraction for the first
2559 * searching loop
2560 */
2561 val = mvpp2_read(priv, MVPP2_PRS_INIT_OFFS_REG(port));
2562 val &= ~MVPP2_PRS_INIT_OFF_MASK(port);
2563 val |= MVPP2_PRS_INIT_OFF_VAL(port, offset);
2564 mvpp2_write(priv, MVPP2_PRS_INIT_OFFS_REG(port), val);
2565}
2566
2567/* Default flow entries initialization for all ports */
2568static void mvpp2_prs_def_flow_init(struct mvpp2 *priv)
2569{
2570 struct mvpp2_prs_entry pe;
2571 int port;
2572
2573 for (port = 0; port < MVPP2_MAX_PORTS; port++) {
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002574 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002575 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
2576 pe.index = MVPP2_PE_FIRST_DEFAULT_FLOW - port;
2577
2578 /* Mask all ports */
2579 mvpp2_prs_tcam_port_map_set(&pe, 0);
2580
2581 /* Set flow ID*/
2582 mvpp2_prs_sram_ai_update(&pe, port, MVPP2_PRS_FLOW_ID_MASK);
2583 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_DONE_BIT, 1);
2584
2585 /* Update shadow table and hw entry */
2586 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_FLOWS);
2587 mvpp2_prs_hw_write(priv, &pe);
2588 }
2589}
2590
2591/* Set default entry for Marvell Header field */
2592static void mvpp2_prs_mh_init(struct mvpp2 *priv)
2593{
2594 struct mvpp2_prs_entry pe;
2595
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002596 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002597
2598 pe.index = MVPP2_PE_MH_DEFAULT;
2599 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MH);
2600 mvpp2_prs_sram_shift_set(&pe, MVPP2_MH_SIZE,
2601 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2602 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_MAC);
2603
2604 /* Unmask all ports */
2605 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2606
2607 /* Update shadow table and hw entry */
2608 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MH);
2609 mvpp2_prs_hw_write(priv, &pe);
2610}
2611
2612/* Set default entires (place holder) for promiscuous, non-promiscuous and
2613 * multicast MAC addresses
2614 */
2615static void mvpp2_prs_mac_init(struct mvpp2 *priv)
2616{
2617 struct mvpp2_prs_entry pe;
2618
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002619 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002620
2621 /* Non-promiscuous mode for all ports - DROP unknown packets */
2622 pe.index = MVPP2_PE_MAC_NON_PROMISCUOUS;
2623 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC);
2624
2625 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_DROP_MASK,
2626 MVPP2_PRS_RI_DROP_MASK);
2627 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
2628 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
2629
2630 /* Unmask all ports */
2631 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2632
2633 /* Update shadow table and hw entry */
2634 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC);
2635 mvpp2_prs_hw_write(priv, &pe);
2636
2637 /* place holders only - no ports */
2638 mvpp2_prs_mac_drop_all_set(priv, 0, false);
2639 mvpp2_prs_mac_promisc_set(priv, 0, false);
Antoine Tenart20746d72017-10-24 11:41:27 +02002640 mvpp2_prs_mac_multi_set(priv, 0, MVPP2_PE_MAC_MC_ALL, false);
2641 mvpp2_prs_mac_multi_set(priv, 0, MVPP2_PE_MAC_MC_IP6, false);
Marcin Wojtas3f518502014-07-10 16:52:13 -03002642}
2643
2644/* Set default entries for various types of dsa packets */
2645static void mvpp2_prs_dsa_init(struct mvpp2 *priv)
2646{
2647 struct mvpp2_prs_entry pe;
2648
2649 /* None tagged EDSA entry - place holder */
2650 mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_UNTAGGED,
2651 MVPP2_PRS_EDSA);
2652
2653 /* Tagged EDSA entry - place holder */
2654 mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA);
2655
2656 /* None tagged DSA entry - place holder */
2657 mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_UNTAGGED,
2658 MVPP2_PRS_DSA);
2659
2660 /* Tagged DSA entry - place holder */
2661 mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_TAGGED, MVPP2_PRS_DSA);
2662
2663 /* None tagged EDSA ethertype entry - place holder*/
2664 mvpp2_prs_dsa_tag_ethertype_set(priv, 0, false,
2665 MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA);
2666
2667 /* Tagged EDSA ethertype entry - place holder*/
2668 mvpp2_prs_dsa_tag_ethertype_set(priv, 0, false,
2669 MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA);
2670
2671 /* None tagged DSA ethertype entry */
2672 mvpp2_prs_dsa_tag_ethertype_set(priv, 0, true,
2673 MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA);
2674
2675 /* Tagged DSA ethertype entry */
2676 mvpp2_prs_dsa_tag_ethertype_set(priv, 0, true,
2677 MVPP2_PRS_TAGGED, MVPP2_PRS_DSA);
2678
2679 /* Set default entry, in case DSA or EDSA tag not found */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002680 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002681 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_DSA);
2682 pe.index = MVPP2_PE_DSA_DEFAULT;
2683 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_VLAN);
2684
2685 /* Shift 0 bytes */
2686 mvpp2_prs_sram_shift_set(&pe, 0, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2687 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC);
2688
2689 /* Clear all sram ai bits for next iteration */
2690 mvpp2_prs_sram_ai_update(&pe, 0, MVPP2_PRS_SRAM_AI_MASK);
2691
2692 /* Unmask all ports */
2693 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2694
2695 mvpp2_prs_hw_write(priv, &pe);
2696}
2697
2698/* Match basic ethertypes */
2699static int mvpp2_prs_etype_init(struct mvpp2 *priv)
2700{
2701 struct mvpp2_prs_entry pe;
2702 int tid;
2703
2704 /* Ethertype: PPPoE */
2705 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2706 MVPP2_PE_LAST_FREE_TID);
2707 if (tid < 0)
2708 return tid;
2709
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002710 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002711 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
2712 pe.index = tid;
2713
2714 mvpp2_prs_match_etype(&pe, 0, ETH_P_PPP_SES);
2715
2716 mvpp2_prs_sram_shift_set(&pe, MVPP2_PPPOE_HDR_SIZE,
2717 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2718 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_PPPOE);
2719 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_PPPOE_MASK,
2720 MVPP2_PRS_RI_PPPOE_MASK);
2721
2722 /* Update shadow table and hw entry */
2723 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
2724 priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
2725 priv->prs_shadow[pe.index].finish = false;
2726 mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_PPPOE_MASK,
2727 MVPP2_PRS_RI_PPPOE_MASK);
2728 mvpp2_prs_hw_write(priv, &pe);
2729
2730 /* Ethertype: ARP */
2731 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2732 MVPP2_PE_LAST_FREE_TID);
2733 if (tid < 0)
2734 return tid;
2735
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002736 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002737 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
2738 pe.index = tid;
2739
2740 mvpp2_prs_match_etype(&pe, 0, ETH_P_ARP);
2741
2742 /* Generate flow in the next iteration*/
2743 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
2744 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
2745 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_ARP,
2746 MVPP2_PRS_RI_L3_PROTO_MASK);
2747 /* Set L3 offset */
2748 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
2749 MVPP2_ETH_TYPE_LEN,
2750 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
2751
2752 /* Update shadow table and hw entry */
2753 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
2754 priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
2755 priv->prs_shadow[pe.index].finish = true;
2756 mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_ARP,
2757 MVPP2_PRS_RI_L3_PROTO_MASK);
2758 mvpp2_prs_hw_write(priv, &pe);
2759
2760 /* Ethertype: LBTD */
2761 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2762 MVPP2_PE_LAST_FREE_TID);
2763 if (tid < 0)
2764 return tid;
2765
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002766 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002767 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
2768 pe.index = tid;
2769
2770 mvpp2_prs_match_etype(&pe, 0, MVPP2_IP_LBDT_TYPE);
2771
2772 /* Generate flow in the next iteration*/
2773 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
2774 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
2775 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_CPU_CODE_RX_SPEC |
2776 MVPP2_PRS_RI_UDF3_RX_SPECIAL,
2777 MVPP2_PRS_RI_CPU_CODE_MASK |
2778 MVPP2_PRS_RI_UDF3_MASK);
2779 /* Set L3 offset */
2780 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
2781 MVPP2_ETH_TYPE_LEN,
2782 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
2783
2784 /* Update shadow table and hw entry */
2785 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
2786 priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
2787 priv->prs_shadow[pe.index].finish = true;
2788 mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_CPU_CODE_RX_SPEC |
2789 MVPP2_PRS_RI_UDF3_RX_SPECIAL,
2790 MVPP2_PRS_RI_CPU_CODE_MASK |
2791 MVPP2_PRS_RI_UDF3_MASK);
2792 mvpp2_prs_hw_write(priv, &pe);
2793
2794 /* Ethertype: IPv4 without options */
2795 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2796 MVPP2_PE_LAST_FREE_TID);
2797 if (tid < 0)
2798 return tid;
2799
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002800 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002801 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
2802 pe.index = tid;
2803
2804 mvpp2_prs_match_etype(&pe, 0, ETH_P_IP);
2805 mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN,
2806 MVPP2_PRS_IPV4_HEAD | MVPP2_PRS_IPV4_IHL,
2807 MVPP2_PRS_IPV4_HEAD_MASK |
2808 MVPP2_PRS_IPV4_IHL_MASK);
2809
2810 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4);
2811 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4,
2812 MVPP2_PRS_RI_L3_PROTO_MASK);
2813 /* Skip eth_type + 4 bytes of IP header */
2814 mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 4,
2815 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2816 /* Set L3 offset */
2817 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
2818 MVPP2_ETH_TYPE_LEN,
2819 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
2820
2821 /* Update shadow table and hw entry */
2822 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
2823 priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
2824 priv->prs_shadow[pe.index].finish = false;
2825 mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_IP4,
2826 MVPP2_PRS_RI_L3_PROTO_MASK);
2827 mvpp2_prs_hw_write(priv, &pe);
2828
2829 /* Ethertype: IPv4 with options */
2830 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2831 MVPP2_PE_LAST_FREE_TID);
2832 if (tid < 0)
2833 return tid;
2834
2835 pe.index = tid;
2836
2837 /* Clear tcam data before updating */
2838 pe.tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE(MVPP2_ETH_TYPE_LEN)] = 0x0;
2839 pe.tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE_EN(MVPP2_ETH_TYPE_LEN)] = 0x0;
2840
2841 mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN,
2842 MVPP2_PRS_IPV4_HEAD,
2843 MVPP2_PRS_IPV4_HEAD_MASK);
2844
2845 /* Clear ri before updating */
2846 pe.sram.word[MVPP2_PRS_SRAM_RI_WORD] = 0x0;
2847 pe.sram.word[MVPP2_PRS_SRAM_RI_CTRL_WORD] = 0x0;
2848 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4_OPT,
2849 MVPP2_PRS_RI_L3_PROTO_MASK);
2850
2851 /* Update shadow table and hw entry */
2852 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
2853 priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
2854 priv->prs_shadow[pe.index].finish = false;
2855 mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_IP4_OPT,
2856 MVPP2_PRS_RI_L3_PROTO_MASK);
2857 mvpp2_prs_hw_write(priv, &pe);
2858
2859 /* Ethertype: IPv6 without options */
2860 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2861 MVPP2_PE_LAST_FREE_TID);
2862 if (tid < 0)
2863 return tid;
2864
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002865 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002866 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
2867 pe.index = tid;
2868
2869 mvpp2_prs_match_etype(&pe, 0, ETH_P_IPV6);
2870
2871 /* Skip DIP of IPV6 header */
2872 mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 8 +
2873 MVPP2_MAX_L3_ADDR_SIZE,
2874 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2875 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6);
2876 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP6,
2877 MVPP2_PRS_RI_L3_PROTO_MASK);
2878 /* Set L3 offset */
2879 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
2880 MVPP2_ETH_TYPE_LEN,
2881 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
2882
2883 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
2884 priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
2885 priv->prs_shadow[pe.index].finish = false;
2886 mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_IP6,
2887 MVPP2_PRS_RI_L3_PROTO_MASK);
2888 mvpp2_prs_hw_write(priv, &pe);
2889
2890 /* Default entry for MVPP2_PRS_LU_L2 - Unknown ethtype */
2891 memset(&pe, 0, sizeof(struct mvpp2_prs_entry));
2892 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
2893 pe.index = MVPP2_PE_ETH_TYPE_UN;
2894
2895 /* Unmask all ports */
2896 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2897
2898 /* Generate flow in the next iteration*/
2899 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
2900 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
2901 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UN,
2902 MVPP2_PRS_RI_L3_PROTO_MASK);
2903 /* Set L3 offset even it's unknown L3 */
2904 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
2905 MVPP2_ETH_TYPE_LEN,
2906 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
2907
2908 /* Update shadow table and hw entry */
2909 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
2910 priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
2911 priv->prs_shadow[pe.index].finish = true;
2912 mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_UN,
2913 MVPP2_PRS_RI_L3_PROTO_MASK);
2914 mvpp2_prs_hw_write(priv, &pe);
2915
2916 return 0;
2917}
2918
2919/* Configure vlan entries and detect up to 2 successive VLAN tags.
2920 * Possible options:
2921 * 0x8100, 0x88A8
2922 * 0x8100, 0x8100
2923 * 0x8100
2924 * 0x88A8
2925 */
2926static int mvpp2_prs_vlan_init(struct platform_device *pdev, struct mvpp2 *priv)
2927{
2928 struct mvpp2_prs_entry pe;
2929 int err;
2930
2931 priv->prs_double_vlans = devm_kcalloc(&pdev->dev, sizeof(bool),
2932 MVPP2_PRS_DBL_VLANS_MAX,
2933 GFP_KERNEL);
2934 if (!priv->prs_double_vlans)
2935 return -ENOMEM;
2936
2937 /* Double VLAN: 0x8100, 0x88A8 */
2938 err = mvpp2_prs_double_vlan_add(priv, ETH_P_8021Q, ETH_P_8021AD,
2939 MVPP2_PRS_PORT_MASK);
2940 if (err)
2941 return err;
2942
2943 /* Double VLAN: 0x8100, 0x8100 */
2944 err = mvpp2_prs_double_vlan_add(priv, ETH_P_8021Q, ETH_P_8021Q,
2945 MVPP2_PRS_PORT_MASK);
2946 if (err)
2947 return err;
2948
2949 /* Single VLAN: 0x88a8 */
2950 err = mvpp2_prs_vlan_add(priv, ETH_P_8021AD, MVPP2_PRS_SINGLE_VLAN_AI,
2951 MVPP2_PRS_PORT_MASK);
2952 if (err)
2953 return err;
2954
2955 /* Single VLAN: 0x8100 */
2956 err = mvpp2_prs_vlan_add(priv, ETH_P_8021Q, MVPP2_PRS_SINGLE_VLAN_AI,
2957 MVPP2_PRS_PORT_MASK);
2958 if (err)
2959 return err;
2960
2961 /* Set default double vlan entry */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002962 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002963 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_VLAN);
2964 pe.index = MVPP2_PE_VLAN_DBL;
2965
2966 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2);
2967 /* Clear ai for next iterations */
2968 mvpp2_prs_sram_ai_update(&pe, 0, MVPP2_PRS_SRAM_AI_MASK);
2969 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_DOUBLE,
2970 MVPP2_PRS_RI_VLAN_MASK);
2971
2972 mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_DBL_VLAN_AI_BIT,
2973 MVPP2_PRS_DBL_VLAN_AI_BIT);
2974 /* Unmask all ports */
2975 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2976
2977 /* Update shadow table and hw entry */
2978 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_VLAN);
2979 mvpp2_prs_hw_write(priv, &pe);
2980
2981 /* Set default vlan none entry */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002982 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002983 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_VLAN);
2984 pe.index = MVPP2_PE_VLAN_NONE;
2985
2986 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2);
2987 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_NONE,
2988 MVPP2_PRS_RI_VLAN_MASK);
2989
2990 /* Unmask all ports */
2991 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2992
2993 /* Update shadow table and hw entry */
2994 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_VLAN);
2995 mvpp2_prs_hw_write(priv, &pe);
2996
2997 return 0;
2998}
2999
3000/* Set entries for PPPoE ethertype */
3001static int mvpp2_prs_pppoe_init(struct mvpp2 *priv)
3002{
3003 struct mvpp2_prs_entry pe;
3004 int tid;
3005
3006 /* IPv4 over PPPoE with options */
3007 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
3008 MVPP2_PE_LAST_FREE_TID);
3009 if (tid < 0)
3010 return tid;
3011
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003012 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003013 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_PPPOE);
3014 pe.index = tid;
3015
3016 mvpp2_prs_match_etype(&pe, 0, PPP_IP);
3017
3018 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4);
3019 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4_OPT,
3020 MVPP2_PRS_RI_L3_PROTO_MASK);
3021 /* Skip eth_type + 4 bytes of IP header */
3022 mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 4,
3023 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
3024 /* Set L3 offset */
3025 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
3026 MVPP2_ETH_TYPE_LEN,
3027 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
3028
3029 /* Update shadow table and hw entry */
3030 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE);
3031 mvpp2_prs_hw_write(priv, &pe);
3032
3033 /* IPv4 over PPPoE without options */
3034 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
3035 MVPP2_PE_LAST_FREE_TID);
3036 if (tid < 0)
3037 return tid;
3038
3039 pe.index = tid;
3040
3041 mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN,
3042 MVPP2_PRS_IPV4_HEAD | MVPP2_PRS_IPV4_IHL,
3043 MVPP2_PRS_IPV4_HEAD_MASK |
3044 MVPP2_PRS_IPV4_IHL_MASK);
3045
3046 /* Clear ri before updating */
3047 pe.sram.word[MVPP2_PRS_SRAM_RI_WORD] = 0x0;
3048 pe.sram.word[MVPP2_PRS_SRAM_RI_CTRL_WORD] = 0x0;
3049 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4,
3050 MVPP2_PRS_RI_L3_PROTO_MASK);
3051
3052 /* Update shadow table and hw entry */
3053 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE);
3054 mvpp2_prs_hw_write(priv, &pe);
3055
3056 /* IPv6 over PPPoE */
3057 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
3058 MVPP2_PE_LAST_FREE_TID);
3059 if (tid < 0)
3060 return tid;
3061
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003062 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003063 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_PPPOE);
3064 pe.index = tid;
3065
3066 mvpp2_prs_match_etype(&pe, 0, PPP_IPV6);
3067
3068 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6);
3069 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP6,
3070 MVPP2_PRS_RI_L3_PROTO_MASK);
3071 /* Skip eth_type + 4 bytes of IPv6 header */
3072 mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 4,
3073 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
3074 /* Set L3 offset */
3075 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
3076 MVPP2_ETH_TYPE_LEN,
3077 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
3078
3079 /* Update shadow table and hw entry */
3080 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE);
3081 mvpp2_prs_hw_write(priv, &pe);
3082
3083 /* Non-IP over PPPoE */
3084 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
3085 MVPP2_PE_LAST_FREE_TID);
3086 if (tid < 0)
3087 return tid;
3088
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003089 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003090 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_PPPOE);
3091 pe.index = tid;
3092
3093 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UN,
3094 MVPP2_PRS_RI_L3_PROTO_MASK);
3095
3096 /* Finished: go to flowid generation */
3097 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
3098 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
3099 /* Set L3 offset even if it's unknown L3 */
3100 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
3101 MVPP2_ETH_TYPE_LEN,
3102 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
3103
3104 /* Update shadow table and hw entry */
3105 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE);
3106 mvpp2_prs_hw_write(priv, &pe);
3107
3108 return 0;
3109}
3110
3111/* Initialize entries for IPv4 */
3112static int mvpp2_prs_ip4_init(struct mvpp2 *priv)
3113{
3114 struct mvpp2_prs_entry pe;
3115 int err;
3116
3117 /* Set entries for TCP, UDP and IGMP over IPv4 */
3118 err = mvpp2_prs_ip4_proto(priv, IPPROTO_TCP, MVPP2_PRS_RI_L4_TCP,
3119 MVPP2_PRS_RI_L4_PROTO_MASK);
3120 if (err)
3121 return err;
3122
3123 err = mvpp2_prs_ip4_proto(priv, IPPROTO_UDP, MVPP2_PRS_RI_L4_UDP,
3124 MVPP2_PRS_RI_L4_PROTO_MASK);
3125 if (err)
3126 return err;
3127
3128 err = mvpp2_prs_ip4_proto(priv, IPPROTO_IGMP,
3129 MVPP2_PRS_RI_CPU_CODE_RX_SPEC |
3130 MVPP2_PRS_RI_UDF3_RX_SPECIAL,
3131 MVPP2_PRS_RI_CPU_CODE_MASK |
3132 MVPP2_PRS_RI_UDF3_MASK);
3133 if (err)
3134 return err;
3135
3136 /* IPv4 Broadcast */
3137 err = mvpp2_prs_ip4_cast(priv, MVPP2_PRS_L3_BROAD_CAST);
3138 if (err)
3139 return err;
3140
3141 /* IPv4 Multicast */
3142 err = mvpp2_prs_ip4_cast(priv, MVPP2_PRS_L3_MULTI_CAST);
3143 if (err)
3144 return err;
3145
3146 /* Default IPv4 entry for unknown protocols */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003147 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003148 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4);
3149 pe.index = MVPP2_PE_IP4_PROTO_UN;
3150
3151 /* Set next lu to IPv4 */
3152 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4);
3153 mvpp2_prs_sram_shift_set(&pe, 12, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
3154 /* Set L4 offset */
3155 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4,
3156 sizeof(struct iphdr) - 4,
3157 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
3158 mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT,
3159 MVPP2_PRS_IPV4_DIP_AI_BIT);
3160 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L4_OTHER,
3161 MVPP2_PRS_RI_L4_PROTO_MASK);
3162
3163 mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV4_DIP_AI_BIT);
3164 /* Unmask all ports */
3165 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
3166
3167 /* Update shadow table and hw entry */
3168 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
3169 mvpp2_prs_hw_write(priv, &pe);
3170
3171 /* Default IPv4 entry for unicast address */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003172 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003173 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4);
3174 pe.index = MVPP2_PE_IP4_ADDR_UN;
3175
3176 /* Finished: go to flowid generation */
3177 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
3178 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
3179 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UCAST,
3180 MVPP2_PRS_RI_L3_ADDR_MASK);
3181
3182 mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT,
3183 MVPP2_PRS_IPV4_DIP_AI_BIT);
3184 /* Unmask all ports */
3185 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
3186
3187 /* Update shadow table and hw entry */
3188 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
3189 mvpp2_prs_hw_write(priv, &pe);
3190
3191 return 0;
3192}
3193
3194/* Initialize entries for IPv6 */
3195static int mvpp2_prs_ip6_init(struct mvpp2 *priv)
3196{
3197 struct mvpp2_prs_entry pe;
3198 int tid, err;
3199
3200 /* Set entries for TCP, UDP and ICMP over IPv6 */
3201 err = mvpp2_prs_ip6_proto(priv, IPPROTO_TCP,
3202 MVPP2_PRS_RI_L4_TCP,
3203 MVPP2_PRS_RI_L4_PROTO_MASK);
3204 if (err)
3205 return err;
3206
3207 err = mvpp2_prs_ip6_proto(priv, IPPROTO_UDP,
3208 MVPP2_PRS_RI_L4_UDP,
3209 MVPP2_PRS_RI_L4_PROTO_MASK);
3210 if (err)
3211 return err;
3212
3213 err = mvpp2_prs_ip6_proto(priv, IPPROTO_ICMPV6,
3214 MVPP2_PRS_RI_CPU_CODE_RX_SPEC |
3215 MVPP2_PRS_RI_UDF3_RX_SPECIAL,
3216 MVPP2_PRS_RI_CPU_CODE_MASK |
3217 MVPP2_PRS_RI_UDF3_MASK);
3218 if (err)
3219 return err;
3220
3221 /* IPv4 is the last header. This is similar case as 6-TCP or 17-UDP */
3222 /* Result Info: UDF7=1, DS lite */
3223 err = mvpp2_prs_ip6_proto(priv, IPPROTO_IPIP,
3224 MVPP2_PRS_RI_UDF7_IP6_LITE,
3225 MVPP2_PRS_RI_UDF7_MASK);
3226 if (err)
3227 return err;
3228
3229 /* IPv6 multicast */
3230 err = mvpp2_prs_ip6_cast(priv, MVPP2_PRS_L3_MULTI_CAST);
3231 if (err)
3232 return err;
3233
3234 /* Entry for checking hop limit */
3235 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
3236 MVPP2_PE_LAST_FREE_TID);
3237 if (tid < 0)
3238 return tid;
3239
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003240 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003241 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6);
3242 pe.index = tid;
3243
3244 /* Finished: go to flowid generation */
3245 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
3246 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
3247 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UN |
3248 MVPP2_PRS_RI_DROP_MASK,
3249 MVPP2_PRS_RI_L3_PROTO_MASK |
3250 MVPP2_PRS_RI_DROP_MASK);
3251
3252 mvpp2_prs_tcam_data_byte_set(&pe, 1, 0x00, MVPP2_PRS_IPV6_HOP_MASK);
3253 mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT,
3254 MVPP2_PRS_IPV6_NO_EXT_AI_BIT);
3255
3256 /* Update shadow table and hw entry */
3257 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
3258 mvpp2_prs_hw_write(priv, &pe);
3259
3260 /* Default IPv6 entry for unknown protocols */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003261 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003262 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6);
3263 pe.index = MVPP2_PE_IP6_PROTO_UN;
3264
3265 /* Finished: go to flowid generation */
3266 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
3267 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
3268 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L4_OTHER,
3269 MVPP2_PRS_RI_L4_PROTO_MASK);
3270 /* Set L4 offset relatively to our current place */
3271 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4,
3272 sizeof(struct ipv6hdr) - 4,
3273 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
3274
3275 mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT,
3276 MVPP2_PRS_IPV6_NO_EXT_AI_BIT);
3277 /* Unmask all ports */
3278 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
3279
3280 /* Update shadow table and hw entry */
3281 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
3282 mvpp2_prs_hw_write(priv, &pe);
3283
3284 /* Default IPv6 entry for unknown ext protocols */
3285 memset(&pe, 0, sizeof(struct mvpp2_prs_entry));
3286 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6);
3287 pe.index = MVPP2_PE_IP6_EXT_PROTO_UN;
3288
3289 /* Finished: go to flowid generation */
3290 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
3291 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
3292 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L4_OTHER,
3293 MVPP2_PRS_RI_L4_PROTO_MASK);
3294
3295 mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_EXT_AI_BIT,
3296 MVPP2_PRS_IPV6_EXT_AI_BIT);
3297 /* Unmask all ports */
3298 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
3299
3300 /* Update shadow table and hw entry */
3301 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
3302 mvpp2_prs_hw_write(priv, &pe);
3303
3304 /* Default IPv6 entry for unicast address */
3305 memset(&pe, 0, sizeof(struct mvpp2_prs_entry));
3306 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6);
3307 pe.index = MVPP2_PE_IP6_ADDR_UN;
3308
3309 /* Finished: go to IPv6 again */
3310 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6);
3311 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UCAST,
3312 MVPP2_PRS_RI_L3_ADDR_MASK);
3313 mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT,
3314 MVPP2_PRS_IPV6_NO_EXT_AI_BIT);
3315 /* Shift back to IPV6 NH */
3316 mvpp2_prs_sram_shift_set(&pe, -18, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
3317
3318 mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV6_NO_EXT_AI_BIT);
3319 /* Unmask all ports */
3320 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
3321
3322 /* Update shadow table and hw entry */
3323 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP6);
3324 mvpp2_prs_hw_write(priv, &pe);
3325
3326 return 0;
3327}
3328
3329/* Parser default initialization */
3330static int mvpp2_prs_default_init(struct platform_device *pdev,
3331 struct mvpp2 *priv)
3332{
3333 int err, index, i;
3334
3335 /* Enable tcam table */
3336 mvpp2_write(priv, MVPP2_PRS_TCAM_CTRL_REG, MVPP2_PRS_TCAM_EN_MASK);
3337
3338 /* Clear all tcam and sram entries */
3339 for (index = 0; index < MVPP2_PRS_TCAM_SRAM_SIZE; index++) {
3340 mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, index);
3341 for (i = 0; i < MVPP2_PRS_TCAM_WORDS; i++)
3342 mvpp2_write(priv, MVPP2_PRS_TCAM_DATA_REG(i), 0);
3343
3344 mvpp2_write(priv, MVPP2_PRS_SRAM_IDX_REG, index);
3345 for (i = 0; i < MVPP2_PRS_SRAM_WORDS; i++)
3346 mvpp2_write(priv, MVPP2_PRS_SRAM_DATA_REG(i), 0);
3347 }
3348
3349 /* Invalidate all tcam entries */
3350 for (index = 0; index < MVPP2_PRS_TCAM_SRAM_SIZE; index++)
3351 mvpp2_prs_hw_inv(priv, index);
3352
3353 priv->prs_shadow = devm_kcalloc(&pdev->dev, MVPP2_PRS_TCAM_SRAM_SIZE,
Markus Elfring37df25e2017-04-17 09:12:34 +02003354 sizeof(*priv->prs_shadow),
Marcin Wojtas3f518502014-07-10 16:52:13 -03003355 GFP_KERNEL);
3356 if (!priv->prs_shadow)
3357 return -ENOMEM;
3358
3359 /* Always start from lookup = 0 */
3360 for (index = 0; index < MVPP2_MAX_PORTS; index++)
3361 mvpp2_prs_hw_port_init(priv, index, MVPP2_PRS_LU_MH,
3362 MVPP2_PRS_PORT_LU_MAX, 0);
3363
3364 mvpp2_prs_def_flow_init(priv);
3365
3366 mvpp2_prs_mh_init(priv);
3367
3368 mvpp2_prs_mac_init(priv);
3369
3370 mvpp2_prs_dsa_init(priv);
3371
3372 err = mvpp2_prs_etype_init(priv);
3373 if (err)
3374 return err;
3375
3376 err = mvpp2_prs_vlan_init(pdev, priv);
3377 if (err)
3378 return err;
3379
3380 err = mvpp2_prs_pppoe_init(priv);
3381 if (err)
3382 return err;
3383
3384 err = mvpp2_prs_ip6_init(priv);
3385 if (err)
3386 return err;
3387
3388 err = mvpp2_prs_ip4_init(priv);
3389 if (err)
3390 return err;
3391
3392 return 0;
3393}
3394
3395/* Compare MAC DA with tcam entry data */
3396static bool mvpp2_prs_mac_range_equals(struct mvpp2_prs_entry *pe,
3397 const u8 *da, unsigned char *mask)
3398{
3399 unsigned char tcam_byte, tcam_mask;
3400 int index;
3401
3402 for (index = 0; index < ETH_ALEN; index++) {
3403 mvpp2_prs_tcam_data_byte_get(pe, index, &tcam_byte, &tcam_mask);
3404 if (tcam_mask != mask[index])
3405 return false;
3406
3407 if ((tcam_mask & tcam_byte) != (da[index] & mask[index]))
3408 return false;
3409 }
3410
3411 return true;
3412}
3413
3414/* Find tcam entry with matched pair <MAC DA, port> */
3415static struct mvpp2_prs_entry *
3416mvpp2_prs_mac_da_range_find(struct mvpp2 *priv, int pmap, const u8 *da,
3417 unsigned char *mask, int udf_type)
3418{
3419 struct mvpp2_prs_entry *pe;
3420 int tid;
3421
Antoine Tenart239dd4e2017-10-24 11:41:28 +02003422 pe = kzalloc(sizeof(*pe), GFP_ATOMIC);
Marcin Wojtas3f518502014-07-10 16:52:13 -03003423 if (!pe)
3424 return NULL;
3425 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_MAC);
3426
3427 /* Go through the all entires with MVPP2_PRS_LU_MAC */
3428 for (tid = MVPP2_PE_FIRST_FREE_TID;
3429 tid <= MVPP2_PE_LAST_FREE_TID; tid++) {
3430 unsigned int entry_pmap;
3431
3432 if (!priv->prs_shadow[tid].valid ||
3433 (priv->prs_shadow[tid].lu != MVPP2_PRS_LU_MAC) ||
3434 (priv->prs_shadow[tid].udf != udf_type))
3435 continue;
3436
3437 pe->index = tid;
3438 mvpp2_prs_hw_read(priv, pe);
3439 entry_pmap = mvpp2_prs_tcam_port_map_get(pe);
3440
3441 if (mvpp2_prs_mac_range_equals(pe, da, mask) &&
3442 entry_pmap == pmap)
3443 return pe;
3444 }
3445 kfree(pe);
3446
3447 return NULL;
3448}
3449
3450/* Update parser's mac da entry */
3451static int mvpp2_prs_mac_da_accept(struct mvpp2 *priv, int port,
3452 const u8 *da, bool add)
3453{
3454 struct mvpp2_prs_entry *pe;
3455 unsigned int pmap, len, ri;
3456 unsigned char mask[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3457 int tid;
3458
3459 /* Scan TCAM and see if entry with this <MAC DA, port> already exist */
3460 pe = mvpp2_prs_mac_da_range_find(priv, (1 << port), da, mask,
3461 MVPP2_PRS_UDF_MAC_DEF);
3462
3463 /* No such entry */
3464 if (!pe) {
3465 if (!add)
3466 return 0;
3467
3468 /* Create new TCAM entry */
3469 /* Find first range mac entry*/
3470 for (tid = MVPP2_PE_FIRST_FREE_TID;
3471 tid <= MVPP2_PE_LAST_FREE_TID; tid++)
3472 if (priv->prs_shadow[tid].valid &&
3473 (priv->prs_shadow[tid].lu == MVPP2_PRS_LU_MAC) &&
3474 (priv->prs_shadow[tid].udf ==
3475 MVPP2_PRS_UDF_MAC_RANGE))
3476 break;
3477
3478 /* Go through the all entries from first to last */
3479 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
3480 tid - 1);
3481 if (tid < 0)
3482 return tid;
3483
Antoine Tenart239dd4e2017-10-24 11:41:28 +02003484 pe = kzalloc(sizeof(*pe), GFP_ATOMIC);
Marcin Wojtas3f518502014-07-10 16:52:13 -03003485 if (!pe)
Amitoj Kaur Chawlac2bb7bc2016-02-04 19:25:26 +05303486 return -ENOMEM;
Marcin Wojtas3f518502014-07-10 16:52:13 -03003487 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_MAC);
3488 pe->index = tid;
3489
3490 /* Mask all ports */
3491 mvpp2_prs_tcam_port_map_set(pe, 0);
3492 }
3493
3494 /* Update port mask */
3495 mvpp2_prs_tcam_port_set(pe, port, add);
3496
3497 /* Invalidate the entry if no ports are left enabled */
3498 pmap = mvpp2_prs_tcam_port_map_get(pe);
3499 if (pmap == 0) {
3500 if (add) {
3501 kfree(pe);
Amitoj Kaur Chawlac2bb7bc2016-02-04 19:25:26 +05303502 return -EINVAL;
Marcin Wojtas3f518502014-07-10 16:52:13 -03003503 }
3504 mvpp2_prs_hw_inv(priv, pe->index);
3505 priv->prs_shadow[pe->index].valid = false;
3506 kfree(pe);
3507 return 0;
3508 }
3509
3510 /* Continue - set next lookup */
3511 mvpp2_prs_sram_next_lu_set(pe, MVPP2_PRS_LU_DSA);
3512
3513 /* Set match on DA */
3514 len = ETH_ALEN;
3515 while (len--)
3516 mvpp2_prs_tcam_data_byte_set(pe, len, da[len], 0xff);
3517
3518 /* Set result info bits */
3519 if (is_broadcast_ether_addr(da))
3520 ri = MVPP2_PRS_RI_L2_BCAST;
3521 else if (is_multicast_ether_addr(da))
3522 ri = MVPP2_PRS_RI_L2_MCAST;
3523 else
3524 ri = MVPP2_PRS_RI_L2_UCAST | MVPP2_PRS_RI_MAC_ME_MASK;
3525
3526 mvpp2_prs_sram_ri_update(pe, ri, MVPP2_PRS_RI_L2_CAST_MASK |
3527 MVPP2_PRS_RI_MAC_ME_MASK);
3528 mvpp2_prs_shadow_ri_set(priv, pe->index, ri, MVPP2_PRS_RI_L2_CAST_MASK |
3529 MVPP2_PRS_RI_MAC_ME_MASK);
3530
3531 /* Shift to ethertype */
3532 mvpp2_prs_sram_shift_set(pe, 2 * ETH_ALEN,
3533 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
3534
3535 /* Update shadow table and hw entry */
3536 priv->prs_shadow[pe->index].udf = MVPP2_PRS_UDF_MAC_DEF;
3537 mvpp2_prs_shadow_set(priv, pe->index, MVPP2_PRS_LU_MAC);
3538 mvpp2_prs_hw_write(priv, pe);
3539
3540 kfree(pe);
3541
3542 return 0;
3543}
3544
3545static int mvpp2_prs_update_mac_da(struct net_device *dev, const u8 *da)
3546{
3547 struct mvpp2_port *port = netdev_priv(dev);
3548 int err;
3549
3550 /* Remove old parser entry */
3551 err = mvpp2_prs_mac_da_accept(port->priv, port->id, dev->dev_addr,
3552 false);
3553 if (err)
3554 return err;
3555
3556 /* Add new parser entry */
3557 err = mvpp2_prs_mac_da_accept(port->priv, port->id, da, true);
3558 if (err)
3559 return err;
3560
3561 /* Set addr in the device */
3562 ether_addr_copy(dev->dev_addr, da);
3563
3564 return 0;
3565}
3566
3567/* Delete all port's multicast simple (not range) entries */
3568static void mvpp2_prs_mcast_del_all(struct mvpp2 *priv, int port)
3569{
3570 struct mvpp2_prs_entry pe;
3571 int index, tid;
3572
3573 for (tid = MVPP2_PE_FIRST_FREE_TID;
3574 tid <= MVPP2_PE_LAST_FREE_TID; tid++) {
3575 unsigned char da[ETH_ALEN], da_mask[ETH_ALEN];
3576
3577 if (!priv->prs_shadow[tid].valid ||
3578 (priv->prs_shadow[tid].lu != MVPP2_PRS_LU_MAC) ||
3579 (priv->prs_shadow[tid].udf != MVPP2_PRS_UDF_MAC_DEF))
3580 continue;
3581
3582 /* Only simple mac entries */
3583 pe.index = tid;
3584 mvpp2_prs_hw_read(priv, &pe);
3585
3586 /* Read mac addr from entry */
3587 for (index = 0; index < ETH_ALEN; index++)
3588 mvpp2_prs_tcam_data_byte_get(&pe, index, &da[index],
3589 &da_mask[index]);
3590
3591 if (is_multicast_ether_addr(da) && !is_broadcast_ether_addr(da))
3592 /* Delete this entry */
3593 mvpp2_prs_mac_da_accept(priv, port, da, false);
3594 }
3595}
3596
3597static int mvpp2_prs_tag_mode_set(struct mvpp2 *priv, int port, int type)
3598{
3599 switch (type) {
3600 case MVPP2_TAG_TYPE_EDSA:
3601 /* Add port to EDSA entries */
3602 mvpp2_prs_dsa_tag_set(priv, port, true,
3603 MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA);
3604 mvpp2_prs_dsa_tag_set(priv, port, true,
3605 MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA);
3606 /* Remove port from DSA entries */
3607 mvpp2_prs_dsa_tag_set(priv, port, false,
3608 MVPP2_PRS_TAGGED, MVPP2_PRS_DSA);
3609 mvpp2_prs_dsa_tag_set(priv, port, false,
3610 MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA);
3611 break;
3612
3613 case MVPP2_TAG_TYPE_DSA:
3614 /* Add port to DSA entries */
3615 mvpp2_prs_dsa_tag_set(priv, port, true,
3616 MVPP2_PRS_TAGGED, MVPP2_PRS_DSA);
3617 mvpp2_prs_dsa_tag_set(priv, port, true,
3618 MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA);
3619 /* Remove port from EDSA entries */
3620 mvpp2_prs_dsa_tag_set(priv, port, false,
3621 MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA);
3622 mvpp2_prs_dsa_tag_set(priv, port, false,
3623 MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA);
3624 break;
3625
3626 case MVPP2_TAG_TYPE_MH:
3627 case MVPP2_TAG_TYPE_NONE:
3628 /* Remove port form EDSA and DSA entries */
3629 mvpp2_prs_dsa_tag_set(priv, port, false,
3630 MVPP2_PRS_TAGGED, MVPP2_PRS_DSA);
3631 mvpp2_prs_dsa_tag_set(priv, port, false,
3632 MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA);
3633 mvpp2_prs_dsa_tag_set(priv, port, false,
3634 MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA);
3635 mvpp2_prs_dsa_tag_set(priv, port, false,
3636 MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA);
3637 break;
3638
3639 default:
3640 if ((type < 0) || (type > MVPP2_TAG_TYPE_EDSA))
3641 return -EINVAL;
3642 }
3643
3644 return 0;
3645}
3646
3647/* Set prs flow for the port */
3648static int mvpp2_prs_def_flow(struct mvpp2_port *port)
3649{
3650 struct mvpp2_prs_entry *pe;
3651 int tid;
3652
3653 pe = mvpp2_prs_flow_find(port->priv, port->id);
3654
3655 /* Such entry not exist */
3656 if (!pe) {
3657 /* Go through the all entires from last to first */
3658 tid = mvpp2_prs_tcam_first_free(port->priv,
3659 MVPP2_PE_LAST_FREE_TID,
3660 MVPP2_PE_FIRST_FREE_TID);
3661 if (tid < 0)
3662 return tid;
3663
3664 pe = kzalloc(sizeof(*pe), GFP_KERNEL);
3665 if (!pe)
3666 return -ENOMEM;
3667
3668 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_FLOWS);
3669 pe->index = tid;
3670
3671 /* Set flow ID*/
3672 mvpp2_prs_sram_ai_update(pe, port->id, MVPP2_PRS_FLOW_ID_MASK);
3673 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_LU_DONE_BIT, 1);
3674
3675 /* Update shadow table */
3676 mvpp2_prs_shadow_set(port->priv, pe->index, MVPP2_PRS_LU_FLOWS);
3677 }
3678
3679 mvpp2_prs_tcam_port_map_set(pe, (1 << port->id));
3680 mvpp2_prs_hw_write(port->priv, pe);
3681 kfree(pe);
3682
3683 return 0;
3684}
3685
3686/* Classifier configuration routines */
3687
3688/* Update classification flow table registers */
3689static void mvpp2_cls_flow_write(struct mvpp2 *priv,
3690 struct mvpp2_cls_flow_entry *fe)
3691{
3692 mvpp2_write(priv, MVPP2_CLS_FLOW_INDEX_REG, fe->index);
3693 mvpp2_write(priv, MVPP2_CLS_FLOW_TBL0_REG, fe->data[0]);
3694 mvpp2_write(priv, MVPP2_CLS_FLOW_TBL1_REG, fe->data[1]);
3695 mvpp2_write(priv, MVPP2_CLS_FLOW_TBL2_REG, fe->data[2]);
3696}
3697
3698/* Update classification lookup table register */
3699static void mvpp2_cls_lookup_write(struct mvpp2 *priv,
3700 struct mvpp2_cls_lookup_entry *le)
3701{
3702 u32 val;
3703
3704 val = (le->way << MVPP2_CLS_LKP_INDEX_WAY_OFFS) | le->lkpid;
3705 mvpp2_write(priv, MVPP2_CLS_LKP_INDEX_REG, val);
3706 mvpp2_write(priv, MVPP2_CLS_LKP_TBL_REG, le->data);
3707}
3708
3709/* Classifier default initialization */
3710static void mvpp2_cls_init(struct mvpp2 *priv)
3711{
3712 struct mvpp2_cls_lookup_entry le;
3713 struct mvpp2_cls_flow_entry fe;
3714 int index;
3715
3716 /* Enable classifier */
3717 mvpp2_write(priv, MVPP2_CLS_MODE_REG, MVPP2_CLS_MODE_ACTIVE_MASK);
3718
3719 /* Clear classifier flow table */
Arnd Bergmanne8f967c2016-11-24 17:28:12 +01003720 memset(&fe.data, 0, sizeof(fe.data));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003721 for (index = 0; index < MVPP2_CLS_FLOWS_TBL_SIZE; index++) {
3722 fe.index = index;
3723 mvpp2_cls_flow_write(priv, &fe);
3724 }
3725
3726 /* Clear classifier lookup table */
3727 le.data = 0;
3728 for (index = 0; index < MVPP2_CLS_LKP_TBL_SIZE; index++) {
3729 le.lkpid = index;
3730 le.way = 0;
3731 mvpp2_cls_lookup_write(priv, &le);
3732
3733 le.way = 1;
3734 mvpp2_cls_lookup_write(priv, &le);
3735 }
3736}
3737
3738static void mvpp2_cls_port_config(struct mvpp2_port *port)
3739{
3740 struct mvpp2_cls_lookup_entry le;
3741 u32 val;
3742
3743 /* Set way for the port */
3744 val = mvpp2_read(port->priv, MVPP2_CLS_PORT_WAY_REG);
3745 val &= ~MVPP2_CLS_PORT_WAY_MASK(port->id);
3746 mvpp2_write(port->priv, MVPP2_CLS_PORT_WAY_REG, val);
3747
3748 /* Pick the entry to be accessed in lookup ID decoding table
3749 * according to the way and lkpid.
3750 */
3751 le.lkpid = port->id;
3752 le.way = 0;
3753 le.data = 0;
3754
3755 /* Set initial CPU queue for receiving packets */
3756 le.data &= ~MVPP2_CLS_LKP_TBL_RXQ_MASK;
3757 le.data |= port->first_rxq;
3758
3759 /* Disable classification engines */
3760 le.data &= ~MVPP2_CLS_LKP_TBL_LOOKUP_EN_MASK;
3761
3762 /* Update lookup ID table entry */
3763 mvpp2_cls_lookup_write(port->priv, &le);
3764}
3765
3766/* Set CPU queue number for oversize packets */
3767static void mvpp2_cls_oversize_rxq_set(struct mvpp2_port *port)
3768{
3769 u32 val;
3770
3771 mvpp2_write(port->priv, MVPP2_CLS_OVERSIZE_RXQ_LOW_REG(port->id),
3772 port->first_rxq & MVPP2_CLS_OVERSIZE_RXQ_LOW_MASK);
3773
3774 mvpp2_write(port->priv, MVPP2_CLS_SWFWD_P2HQ_REG(port->id),
3775 (port->first_rxq >> MVPP2_CLS_OVERSIZE_RXQ_LOW_BITS));
3776
3777 val = mvpp2_read(port->priv, MVPP2_CLS_SWFWD_PCTRL_REG);
3778 val |= MVPP2_CLS_SWFWD_PCTRL_MASK(port->id);
3779 mvpp2_write(port->priv, MVPP2_CLS_SWFWD_PCTRL_REG, val);
3780}
3781
Thomas Petazzoni0e037282017-02-21 11:28:12 +01003782static void *mvpp2_frag_alloc(const struct mvpp2_bm_pool *pool)
3783{
3784 if (likely(pool->frag_size <= PAGE_SIZE))
3785 return netdev_alloc_frag(pool->frag_size);
3786 else
3787 return kmalloc(pool->frag_size, GFP_ATOMIC);
3788}
3789
3790static void mvpp2_frag_free(const struct mvpp2_bm_pool *pool, void *data)
3791{
3792 if (likely(pool->frag_size <= PAGE_SIZE))
3793 skb_free_frag(data);
3794 else
3795 kfree(data);
3796}
3797
Marcin Wojtas3f518502014-07-10 16:52:13 -03003798/* Buffer Manager configuration routines */
3799
3800/* Create pool */
3801static int mvpp2_bm_pool_create(struct platform_device *pdev,
3802 struct mvpp2 *priv,
3803 struct mvpp2_bm_pool *bm_pool, int size)
3804{
Marcin Wojtas3f518502014-07-10 16:52:13 -03003805 u32 val;
3806
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003807 /* Number of buffer pointers must be a multiple of 16, as per
3808 * hardware constraints
3809 */
3810 if (!IS_ALIGNED(size, 16))
3811 return -EINVAL;
3812
3813 /* PPv2.1 needs 8 bytes per buffer pointer, PPv2.2 needs 16
3814 * bytes per buffer pointer
3815 */
3816 if (priv->hw_version == MVPP21)
3817 bm_pool->size_bytes = 2 * sizeof(u32) * size;
3818 else
3819 bm_pool->size_bytes = 2 * sizeof(u64) * size;
3820
3821 bm_pool->virt_addr = dma_alloc_coherent(&pdev->dev, bm_pool->size_bytes,
Thomas Petazzoni20396132017-03-07 16:53:00 +01003822 &bm_pool->dma_addr,
Marcin Wojtas3f518502014-07-10 16:52:13 -03003823 GFP_KERNEL);
3824 if (!bm_pool->virt_addr)
3825 return -ENOMEM;
3826
Thomas Petazzonid3158802017-02-21 11:28:13 +01003827 if (!IS_ALIGNED((unsigned long)bm_pool->virt_addr,
3828 MVPP2_BM_POOL_PTR_ALIGN)) {
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003829 dma_free_coherent(&pdev->dev, bm_pool->size_bytes,
3830 bm_pool->virt_addr, bm_pool->dma_addr);
Marcin Wojtas3f518502014-07-10 16:52:13 -03003831 dev_err(&pdev->dev, "BM pool %d is not %d bytes aligned\n",
3832 bm_pool->id, MVPP2_BM_POOL_PTR_ALIGN);
3833 return -ENOMEM;
3834 }
3835
3836 mvpp2_write(priv, MVPP2_BM_POOL_BASE_REG(bm_pool->id),
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003837 lower_32_bits(bm_pool->dma_addr));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003838 mvpp2_write(priv, MVPP2_BM_POOL_SIZE_REG(bm_pool->id), size);
3839
3840 val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id));
3841 val |= MVPP2_BM_START_MASK;
3842 mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val);
3843
3844 bm_pool->type = MVPP2_BM_FREE;
3845 bm_pool->size = size;
3846 bm_pool->pkt_size = 0;
3847 bm_pool->buf_num = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03003848
3849 return 0;
3850}
3851
3852/* Set pool buffer size */
3853static void mvpp2_bm_pool_bufsize_set(struct mvpp2 *priv,
3854 struct mvpp2_bm_pool *bm_pool,
3855 int buf_size)
3856{
3857 u32 val;
3858
3859 bm_pool->buf_size = buf_size;
3860
3861 val = ALIGN(buf_size, 1 << MVPP2_POOL_BUF_SIZE_OFFSET);
3862 mvpp2_write(priv, MVPP2_POOL_BUF_SIZE_REG(bm_pool->id), val);
3863}
3864
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003865static void mvpp2_bm_bufs_get_addrs(struct device *dev, struct mvpp2 *priv,
3866 struct mvpp2_bm_pool *bm_pool,
3867 dma_addr_t *dma_addr,
3868 phys_addr_t *phys_addr)
3869{
Thomas Petazzonia704bb52017-06-10 23:18:22 +02003870 int cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01003871
3872 *dma_addr = mvpp2_percpu_read(priv, cpu,
3873 MVPP2_BM_PHY_ALLOC_REG(bm_pool->id));
3874 *phys_addr = mvpp2_percpu_read(priv, cpu, MVPP2_BM_VIRT_ALLOC_REG);
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003875
3876 if (priv->hw_version == MVPP22) {
3877 u32 val;
3878 u32 dma_addr_highbits, phys_addr_highbits;
3879
Thomas Petazzonia7868412017-03-07 16:53:13 +01003880 val = mvpp2_percpu_read(priv, cpu, MVPP22_BM_ADDR_HIGH_ALLOC);
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003881 dma_addr_highbits = (val & MVPP22_BM_ADDR_HIGH_PHYS_MASK);
3882 phys_addr_highbits = (val & MVPP22_BM_ADDR_HIGH_VIRT_MASK) >>
3883 MVPP22_BM_ADDR_HIGH_VIRT_SHIFT;
3884
3885 if (sizeof(dma_addr_t) == 8)
3886 *dma_addr |= (u64)dma_addr_highbits << 32;
3887
3888 if (sizeof(phys_addr_t) == 8)
3889 *phys_addr |= (u64)phys_addr_highbits << 32;
3890 }
Thomas Petazzonia704bb52017-06-10 23:18:22 +02003891
3892 put_cpu();
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003893}
3894
Ezequiel Garcia7861f122014-07-21 13:48:14 -03003895/* Free all buffers from the pool */
Marcin Wojtas4229d502015-12-03 15:20:50 +01003896static void mvpp2_bm_bufs_free(struct device *dev, struct mvpp2 *priv,
3897 struct mvpp2_bm_pool *bm_pool)
Marcin Wojtas3f518502014-07-10 16:52:13 -03003898{
3899 int i;
3900
Ezequiel Garcia7861f122014-07-21 13:48:14 -03003901 for (i = 0; i < bm_pool->buf_num; i++) {
Thomas Petazzoni20396132017-03-07 16:53:00 +01003902 dma_addr_t buf_dma_addr;
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01003903 phys_addr_t buf_phys_addr;
3904 void *data;
Marcin Wojtas3f518502014-07-10 16:52:13 -03003905
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003906 mvpp2_bm_bufs_get_addrs(dev, priv, bm_pool,
3907 &buf_dma_addr, &buf_phys_addr);
Marcin Wojtas4229d502015-12-03 15:20:50 +01003908
Thomas Petazzoni20396132017-03-07 16:53:00 +01003909 dma_unmap_single(dev, buf_dma_addr,
Marcin Wojtas4229d502015-12-03 15:20:50 +01003910 bm_pool->buf_size, DMA_FROM_DEVICE);
3911
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01003912 data = (void *)phys_to_virt(buf_phys_addr);
3913 if (!data)
Marcin Wojtas3f518502014-07-10 16:52:13 -03003914 break;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01003915
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01003916 mvpp2_frag_free(bm_pool, data);
Marcin Wojtas3f518502014-07-10 16:52:13 -03003917 }
3918
3919 /* Update BM driver with number of buffers removed from pool */
3920 bm_pool->buf_num -= i;
Marcin Wojtas3f518502014-07-10 16:52:13 -03003921}
3922
3923/* Cleanup pool */
3924static int mvpp2_bm_pool_destroy(struct platform_device *pdev,
3925 struct mvpp2 *priv,
3926 struct mvpp2_bm_pool *bm_pool)
3927{
Marcin Wojtas3f518502014-07-10 16:52:13 -03003928 u32 val;
3929
Marcin Wojtas4229d502015-12-03 15:20:50 +01003930 mvpp2_bm_bufs_free(&pdev->dev, priv, bm_pool);
Ezequiel Garciad74c96c2014-07-21 13:48:13 -03003931 if (bm_pool->buf_num) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03003932 WARN(1, "cannot free all buffers in pool %d\n", bm_pool->id);
3933 return 0;
3934 }
3935
3936 val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id));
3937 val |= MVPP2_BM_STOP_MASK;
3938 mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val);
3939
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003940 dma_free_coherent(&pdev->dev, bm_pool->size_bytes,
Marcin Wojtas3f518502014-07-10 16:52:13 -03003941 bm_pool->virt_addr,
Thomas Petazzoni20396132017-03-07 16:53:00 +01003942 bm_pool->dma_addr);
Marcin Wojtas3f518502014-07-10 16:52:13 -03003943 return 0;
3944}
3945
3946static int mvpp2_bm_pools_init(struct platform_device *pdev,
3947 struct mvpp2 *priv)
3948{
3949 int i, err, size;
3950 struct mvpp2_bm_pool *bm_pool;
3951
3952 /* Create all pools with maximum size */
3953 size = MVPP2_BM_POOL_SIZE_MAX;
3954 for (i = 0; i < MVPP2_BM_POOLS_NUM; i++) {
3955 bm_pool = &priv->bm_pools[i];
3956 bm_pool->id = i;
3957 err = mvpp2_bm_pool_create(pdev, priv, bm_pool, size);
3958 if (err)
3959 goto err_unroll_pools;
3960 mvpp2_bm_pool_bufsize_set(priv, bm_pool, 0);
3961 }
3962 return 0;
3963
3964err_unroll_pools:
3965 dev_err(&pdev->dev, "failed to create BM pool %d, size %d\n", i, size);
3966 for (i = i - 1; i >= 0; i--)
3967 mvpp2_bm_pool_destroy(pdev, priv, &priv->bm_pools[i]);
3968 return err;
3969}
3970
3971static int mvpp2_bm_init(struct platform_device *pdev, struct mvpp2 *priv)
3972{
3973 int i, err;
3974
3975 for (i = 0; i < MVPP2_BM_POOLS_NUM; i++) {
3976 /* Mask BM all interrupts */
3977 mvpp2_write(priv, MVPP2_BM_INTR_MASK_REG(i), 0);
3978 /* Clear BM cause register */
3979 mvpp2_write(priv, MVPP2_BM_INTR_CAUSE_REG(i), 0);
3980 }
3981
3982 /* Allocate and initialize BM pools */
3983 priv->bm_pools = devm_kcalloc(&pdev->dev, MVPP2_BM_POOLS_NUM,
Markus Elfring81f915e2017-04-17 09:06:33 +02003984 sizeof(*priv->bm_pools), GFP_KERNEL);
Marcin Wojtas3f518502014-07-10 16:52:13 -03003985 if (!priv->bm_pools)
3986 return -ENOMEM;
3987
3988 err = mvpp2_bm_pools_init(pdev, priv);
3989 if (err < 0)
3990 return err;
3991 return 0;
3992}
3993
3994/* Attach long pool to rxq */
3995static void mvpp2_rxq_long_pool_set(struct mvpp2_port *port,
3996 int lrxq, int long_pool)
3997{
Thomas Petazzoni5eac8922017-03-07 16:53:10 +01003998 u32 val, mask;
Marcin Wojtas3f518502014-07-10 16:52:13 -03003999 int prxq;
4000
4001 /* Get queue physical ID */
4002 prxq = port->rxqs[lrxq]->id;
4003
Thomas Petazzoni5eac8922017-03-07 16:53:10 +01004004 if (port->priv->hw_version == MVPP21)
4005 mask = MVPP21_RXQ_POOL_LONG_MASK;
4006 else
4007 mask = MVPP22_RXQ_POOL_LONG_MASK;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004008
Thomas Petazzoni5eac8922017-03-07 16:53:10 +01004009 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(prxq));
4010 val &= ~mask;
4011 val |= (long_pool << MVPP2_RXQ_POOL_LONG_OFFS) & mask;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004012 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(prxq), val);
4013}
4014
4015/* Attach short pool to rxq */
4016static void mvpp2_rxq_short_pool_set(struct mvpp2_port *port,
4017 int lrxq, int short_pool)
4018{
Thomas Petazzoni5eac8922017-03-07 16:53:10 +01004019 u32 val, mask;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004020 int prxq;
4021
4022 /* Get queue physical ID */
4023 prxq = port->rxqs[lrxq]->id;
4024
Thomas Petazzoni5eac8922017-03-07 16:53:10 +01004025 if (port->priv->hw_version == MVPP21)
4026 mask = MVPP21_RXQ_POOL_SHORT_MASK;
4027 else
4028 mask = MVPP22_RXQ_POOL_SHORT_MASK;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004029
Thomas Petazzoni5eac8922017-03-07 16:53:10 +01004030 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(prxq));
4031 val &= ~mask;
4032 val |= (short_pool << MVPP2_RXQ_POOL_SHORT_OFFS) & mask;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004033 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(prxq), val);
4034}
4035
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004036static void *mvpp2_buf_alloc(struct mvpp2_port *port,
4037 struct mvpp2_bm_pool *bm_pool,
Thomas Petazzoni20396132017-03-07 16:53:00 +01004038 dma_addr_t *buf_dma_addr,
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01004039 phys_addr_t *buf_phys_addr,
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004040 gfp_t gfp_mask)
Marcin Wojtas3f518502014-07-10 16:52:13 -03004041{
Thomas Petazzoni20396132017-03-07 16:53:00 +01004042 dma_addr_t dma_addr;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004043 void *data;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004044
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004045 data = mvpp2_frag_alloc(bm_pool);
4046 if (!data)
Marcin Wojtas3f518502014-07-10 16:52:13 -03004047 return NULL;
4048
Thomas Petazzoni20396132017-03-07 16:53:00 +01004049 dma_addr = dma_map_single(port->dev->dev.parent, data,
4050 MVPP2_RX_BUF_SIZE(bm_pool->pkt_size),
4051 DMA_FROM_DEVICE);
4052 if (unlikely(dma_mapping_error(port->dev->dev.parent, dma_addr))) {
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004053 mvpp2_frag_free(bm_pool, data);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004054 return NULL;
4055 }
Thomas Petazzoni20396132017-03-07 16:53:00 +01004056 *buf_dma_addr = dma_addr;
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01004057 *buf_phys_addr = virt_to_phys(data);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004058
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004059 return data;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004060}
4061
Marcin Wojtas3f518502014-07-10 16:52:13 -03004062/* Release buffer to BM */
4063static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool,
Thomas Petazzoni20396132017-03-07 16:53:00 +01004064 dma_addr_t buf_dma_addr,
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01004065 phys_addr_t buf_phys_addr)
Marcin Wojtas3f518502014-07-10 16:52:13 -03004066{
Thomas Petazzonia704bb52017-06-10 23:18:22 +02004067 int cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01004068
Thomas Petazzonid01524d2017-03-07 16:53:09 +01004069 if (port->priv->hw_version == MVPP22) {
4070 u32 val = 0;
4071
4072 if (sizeof(dma_addr_t) == 8)
4073 val |= upper_32_bits(buf_dma_addr) &
4074 MVPP22_BM_ADDR_HIGH_PHYS_RLS_MASK;
4075
4076 if (sizeof(phys_addr_t) == 8)
4077 val |= (upper_32_bits(buf_phys_addr)
4078 << MVPP22_BM_ADDR_HIGH_VIRT_RLS_SHIFT) &
4079 MVPP22_BM_ADDR_HIGH_VIRT_RLS_MASK;
4080
Thomas Petazzonia7868412017-03-07 16:53:13 +01004081 mvpp2_percpu_write(port->priv, cpu,
4082 MVPP22_BM_ADDR_HIGH_RLS_REG, val);
Thomas Petazzonid01524d2017-03-07 16:53:09 +01004083 }
4084
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01004085 /* MVPP2_BM_VIRT_RLS_REG is not interpreted by HW, and simply
4086 * returned in the "cookie" field of the RX
4087 * descriptor. Instead of storing the virtual address, we
4088 * store the physical address
4089 */
Thomas Petazzonia7868412017-03-07 16:53:13 +01004090 mvpp2_percpu_write(port->priv, cpu,
4091 MVPP2_BM_VIRT_RLS_REG, buf_phys_addr);
4092 mvpp2_percpu_write(port->priv, cpu,
4093 MVPP2_BM_PHY_RLS_REG(pool), buf_dma_addr);
Thomas Petazzonia704bb52017-06-10 23:18:22 +02004094
4095 put_cpu();
Marcin Wojtas3f518502014-07-10 16:52:13 -03004096}
4097
Marcin Wojtas3f518502014-07-10 16:52:13 -03004098/* Allocate buffers for the pool */
4099static int mvpp2_bm_bufs_add(struct mvpp2_port *port,
4100 struct mvpp2_bm_pool *bm_pool, int buf_num)
4101{
Marcin Wojtas3f518502014-07-10 16:52:13 -03004102 int i, buf_size, total_size;
Thomas Petazzoni20396132017-03-07 16:53:00 +01004103 dma_addr_t dma_addr;
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01004104 phys_addr_t phys_addr;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004105 void *buf;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004106
4107 buf_size = MVPP2_RX_BUF_SIZE(bm_pool->pkt_size);
4108 total_size = MVPP2_RX_TOTAL_SIZE(buf_size);
4109
4110 if (buf_num < 0 ||
4111 (buf_num + bm_pool->buf_num > bm_pool->size)) {
4112 netdev_err(port->dev,
4113 "cannot allocate %d buffers for pool %d\n",
4114 buf_num, bm_pool->id);
4115 return 0;
4116 }
4117
Marcin Wojtas3f518502014-07-10 16:52:13 -03004118 for (i = 0; i < buf_num; i++) {
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01004119 buf = mvpp2_buf_alloc(port, bm_pool, &dma_addr,
4120 &phys_addr, GFP_KERNEL);
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004121 if (!buf)
Marcin Wojtas3f518502014-07-10 16:52:13 -03004122 break;
4123
Thomas Petazzoni20396132017-03-07 16:53:00 +01004124 mvpp2_bm_pool_put(port, bm_pool->id, dma_addr,
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01004125 phys_addr);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004126 }
4127
4128 /* Update BM driver with number of buffers added to pool */
4129 bm_pool->buf_num += i;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004130
4131 netdev_dbg(port->dev,
4132 "%s pool %d: pkt_size=%4d, buf_size=%4d, total_size=%4d\n",
4133 bm_pool->type == MVPP2_BM_SWF_SHORT ? "short" : " long",
4134 bm_pool->id, bm_pool->pkt_size, buf_size, total_size);
4135
4136 netdev_dbg(port->dev,
4137 "%s pool %d: %d of %d buffers added\n",
4138 bm_pool->type == MVPP2_BM_SWF_SHORT ? "short" : " long",
4139 bm_pool->id, i, buf_num);
4140 return i;
4141}
4142
4143/* Notify the driver that BM pool is being used as specific type and return the
4144 * pool pointer on success
4145 */
4146static struct mvpp2_bm_pool *
4147mvpp2_bm_pool_use(struct mvpp2_port *port, int pool, enum mvpp2_bm_type type,
4148 int pkt_size)
4149{
Marcin Wojtas3f518502014-07-10 16:52:13 -03004150 struct mvpp2_bm_pool *new_pool = &port->priv->bm_pools[pool];
4151 int num;
4152
4153 if (new_pool->type != MVPP2_BM_FREE && new_pool->type != type) {
4154 netdev_err(port->dev, "mixing pool types is forbidden\n");
4155 return NULL;
4156 }
4157
Marcin Wojtas3f518502014-07-10 16:52:13 -03004158 if (new_pool->type == MVPP2_BM_FREE)
4159 new_pool->type = type;
4160
4161 /* Allocate buffers in case BM pool is used as long pool, but packet
4162 * size doesn't match MTU or BM pool hasn't being used yet
4163 */
4164 if (((type == MVPP2_BM_SWF_LONG) && (pkt_size > new_pool->pkt_size)) ||
4165 (new_pool->pkt_size == 0)) {
4166 int pkts_num;
4167
4168 /* Set default buffer number or free all the buffers in case
4169 * the pool is not empty
4170 */
4171 pkts_num = new_pool->buf_num;
4172 if (pkts_num == 0)
4173 pkts_num = type == MVPP2_BM_SWF_LONG ?
4174 MVPP2_BM_LONG_BUF_NUM :
4175 MVPP2_BM_SHORT_BUF_NUM;
4176 else
Marcin Wojtas4229d502015-12-03 15:20:50 +01004177 mvpp2_bm_bufs_free(port->dev->dev.parent,
4178 port->priv, new_pool);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004179
4180 new_pool->pkt_size = pkt_size;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004181 new_pool->frag_size =
4182 SKB_DATA_ALIGN(MVPP2_RX_BUF_SIZE(pkt_size)) +
4183 MVPP2_SKB_SHINFO_SIZE;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004184
4185 /* Allocate buffers for this pool */
4186 num = mvpp2_bm_bufs_add(port, new_pool, pkts_num);
4187 if (num != pkts_num) {
4188 WARN(1, "pool %d: %d of %d allocated\n",
4189 new_pool->id, num, pkts_num);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004190 return NULL;
4191 }
4192 }
4193
4194 mvpp2_bm_pool_bufsize_set(port->priv, new_pool,
4195 MVPP2_RX_BUF_SIZE(new_pool->pkt_size));
4196
Marcin Wojtas3f518502014-07-10 16:52:13 -03004197 return new_pool;
4198}
4199
4200/* Initialize pools for swf */
4201static int mvpp2_swf_bm_pool_init(struct mvpp2_port *port)
4202{
Marcin Wojtas3f518502014-07-10 16:52:13 -03004203 int rxq;
4204
4205 if (!port->pool_long) {
4206 port->pool_long =
4207 mvpp2_bm_pool_use(port, MVPP2_BM_SWF_LONG_POOL(port->id),
4208 MVPP2_BM_SWF_LONG,
4209 port->pkt_size);
4210 if (!port->pool_long)
4211 return -ENOMEM;
4212
Marcin Wojtas3f518502014-07-10 16:52:13 -03004213 port->pool_long->port_map |= (1 << port->id);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004214
Thomas Petazzoni09f83972017-08-03 10:41:57 +02004215 for (rxq = 0; rxq < port->nrxqs; rxq++)
Marcin Wojtas3f518502014-07-10 16:52:13 -03004216 mvpp2_rxq_long_pool_set(port, rxq, port->pool_long->id);
4217 }
4218
4219 if (!port->pool_short) {
4220 port->pool_short =
4221 mvpp2_bm_pool_use(port, MVPP2_BM_SWF_SHORT_POOL,
4222 MVPP2_BM_SWF_SHORT,
4223 MVPP2_BM_SHORT_PKT_SIZE);
4224 if (!port->pool_short)
4225 return -ENOMEM;
4226
Marcin Wojtas3f518502014-07-10 16:52:13 -03004227 port->pool_short->port_map |= (1 << port->id);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004228
Thomas Petazzoni09f83972017-08-03 10:41:57 +02004229 for (rxq = 0; rxq < port->nrxqs; rxq++)
Marcin Wojtas3f518502014-07-10 16:52:13 -03004230 mvpp2_rxq_short_pool_set(port, rxq,
4231 port->pool_short->id);
4232 }
4233
4234 return 0;
4235}
4236
4237static int mvpp2_bm_update_mtu(struct net_device *dev, int mtu)
4238{
4239 struct mvpp2_port *port = netdev_priv(dev);
4240 struct mvpp2_bm_pool *port_pool = port->pool_long;
4241 int num, pkts_num = port_pool->buf_num;
4242 int pkt_size = MVPP2_RX_PKT_SIZE(mtu);
4243
4244 /* Update BM pool with new buffer size */
Marcin Wojtas4229d502015-12-03 15:20:50 +01004245 mvpp2_bm_bufs_free(dev->dev.parent, port->priv, port_pool);
Ezequiel Garciad74c96c2014-07-21 13:48:13 -03004246 if (port_pool->buf_num) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03004247 WARN(1, "cannot free all buffers in pool %d\n", port_pool->id);
4248 return -EIO;
4249 }
4250
4251 port_pool->pkt_size = pkt_size;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004252 port_pool->frag_size = SKB_DATA_ALIGN(MVPP2_RX_BUF_SIZE(pkt_size)) +
4253 MVPP2_SKB_SHINFO_SIZE;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004254 num = mvpp2_bm_bufs_add(port, port_pool, pkts_num);
4255 if (num != pkts_num) {
4256 WARN(1, "pool %d: %d of %d allocated\n",
4257 port_pool->id, num, pkts_num);
4258 return -EIO;
4259 }
4260
4261 mvpp2_bm_pool_bufsize_set(port->priv, port_pool,
4262 MVPP2_RX_BUF_SIZE(port_pool->pkt_size));
4263 dev->mtu = mtu;
4264 netdev_update_features(dev);
4265 return 0;
4266}
4267
4268static inline void mvpp2_interrupts_enable(struct mvpp2_port *port)
4269{
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02004270 int i, sw_thread_mask = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004271
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02004272 for (i = 0; i < port->nqvecs; i++)
4273 sw_thread_mask |= port->qvecs[i].sw_thread_mask;
4274
Marcin Wojtas3f518502014-07-10 16:52:13 -03004275 mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id),
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02004276 MVPP2_ISR_ENABLE_INTERRUPT(sw_thread_mask));
Marcin Wojtas3f518502014-07-10 16:52:13 -03004277}
4278
4279static inline void mvpp2_interrupts_disable(struct mvpp2_port *port)
4280{
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02004281 int i, sw_thread_mask = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004282
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02004283 for (i = 0; i < port->nqvecs; i++)
4284 sw_thread_mask |= port->qvecs[i].sw_thread_mask;
4285
Marcin Wojtas3f518502014-07-10 16:52:13 -03004286 mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id),
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02004287 MVPP2_ISR_DISABLE_INTERRUPT(sw_thread_mask));
4288}
4289
4290static inline void mvpp2_qvec_interrupt_enable(struct mvpp2_queue_vector *qvec)
4291{
4292 struct mvpp2_port *port = qvec->port;
4293
4294 mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id),
4295 MVPP2_ISR_ENABLE_INTERRUPT(qvec->sw_thread_mask));
4296}
4297
4298static inline void mvpp2_qvec_interrupt_disable(struct mvpp2_queue_vector *qvec)
4299{
4300 struct mvpp2_port *port = qvec->port;
4301
4302 mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id),
4303 MVPP2_ISR_DISABLE_INTERRUPT(qvec->sw_thread_mask));
Marcin Wojtas3f518502014-07-10 16:52:13 -03004304}
4305
Thomas Petazzonie0af22d2017-06-22 14:23:18 +02004306/* Mask the current CPU's Rx/Tx interrupts
4307 * Called by on_each_cpu(), guaranteed to run with migration disabled,
4308 * using smp_processor_id() is OK.
4309 */
Marcin Wojtas3f518502014-07-10 16:52:13 -03004310static void mvpp2_interrupts_mask(void *arg)
4311{
4312 struct mvpp2_port *port = arg;
4313
Thomas Petazzonia7868412017-03-07 16:53:13 +01004314 mvpp2_percpu_write(port->priv, smp_processor_id(),
4315 MVPP2_ISR_RX_TX_MASK_REG(port->id), 0);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004316}
4317
Thomas Petazzonie0af22d2017-06-22 14:23:18 +02004318/* Unmask the current CPU's Rx/Tx interrupts.
4319 * Called by on_each_cpu(), guaranteed to run with migration disabled,
4320 * using smp_processor_id() is OK.
4321 */
Marcin Wojtas3f518502014-07-10 16:52:13 -03004322static void mvpp2_interrupts_unmask(void *arg)
4323{
4324 struct mvpp2_port *port = arg;
Thomas Petazzoni213f4282017-08-03 10:42:00 +02004325 u32 val;
4326
4327 val = MVPP2_CAUSE_MISC_SUM_MASK |
4328 MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK;
4329 if (port->has_tx_irqs)
4330 val |= MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004331
Thomas Petazzonia7868412017-03-07 16:53:13 +01004332 mvpp2_percpu_write(port->priv, smp_processor_id(),
Thomas Petazzoni213f4282017-08-03 10:42:00 +02004333 MVPP2_ISR_RX_TX_MASK_REG(port->id), val);
4334}
4335
4336static void
4337mvpp2_shared_interrupt_mask_unmask(struct mvpp2_port *port, bool mask)
4338{
4339 u32 val;
4340 int i;
4341
4342 if (port->priv->hw_version != MVPP22)
4343 return;
4344
4345 if (mask)
4346 val = 0;
4347 else
4348 val = MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK;
4349
4350 for (i = 0; i < port->nqvecs; i++) {
4351 struct mvpp2_queue_vector *v = port->qvecs + i;
4352
4353 if (v->type != MVPP2_QUEUE_VECTOR_SHARED)
4354 continue;
4355
4356 mvpp2_percpu_write(port->priv, v->sw_thread_id,
4357 MVPP2_ISR_RX_TX_MASK_REG(port->id), val);
4358 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03004359}
4360
4361/* Port configuration routines */
4362
Antoine Ténartf84bf382017-08-22 19:08:27 +02004363static void mvpp22_gop_init_rgmii(struct mvpp2_port *port)
4364{
4365 struct mvpp2 *priv = port->priv;
4366 u32 val;
4367
4368 regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL0, &val);
4369 val |= GENCONF_PORT_CTRL0_BUS_WIDTH_SELECT;
4370 regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL0, val);
4371
4372 regmap_read(priv->sysctrl_base, GENCONF_CTRL0, &val);
4373 if (port->gop_id == 2)
4374 val |= GENCONF_CTRL0_PORT0_RGMII | GENCONF_CTRL0_PORT1_RGMII;
4375 else if (port->gop_id == 3)
4376 val |= GENCONF_CTRL0_PORT1_RGMII_MII;
4377 regmap_write(priv->sysctrl_base, GENCONF_CTRL0, val);
4378}
4379
4380static void mvpp22_gop_init_sgmii(struct mvpp2_port *port)
4381{
4382 struct mvpp2 *priv = port->priv;
4383 u32 val;
4384
4385 regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL0, &val);
4386 val |= GENCONF_PORT_CTRL0_BUS_WIDTH_SELECT |
4387 GENCONF_PORT_CTRL0_RX_DATA_SAMPLE;
4388 regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL0, val);
4389
4390 if (port->gop_id > 1) {
4391 regmap_read(priv->sysctrl_base, GENCONF_CTRL0, &val);
4392 if (port->gop_id == 2)
4393 val &= ~GENCONF_CTRL0_PORT0_RGMII;
4394 else if (port->gop_id == 3)
4395 val &= ~GENCONF_CTRL0_PORT1_RGMII_MII;
4396 regmap_write(priv->sysctrl_base, GENCONF_CTRL0, val);
4397 }
4398}
4399
4400static void mvpp22_gop_init_10gkr(struct mvpp2_port *port)
4401{
4402 struct mvpp2 *priv = port->priv;
4403 void __iomem *mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id);
4404 void __iomem *xpcs = priv->iface_base + MVPP22_XPCS_BASE(port->gop_id);
4405 u32 val;
4406
4407 /* XPCS */
4408 val = readl(xpcs + MVPP22_XPCS_CFG0);
4409 val &= ~(MVPP22_XPCS_CFG0_PCS_MODE(0x3) |
4410 MVPP22_XPCS_CFG0_ACTIVE_LANE(0x3));
4411 val |= MVPP22_XPCS_CFG0_ACTIVE_LANE(2);
4412 writel(val, xpcs + MVPP22_XPCS_CFG0);
4413
4414 /* MPCS */
4415 val = readl(mpcs + MVPP22_MPCS_CTRL);
4416 val &= ~MVPP22_MPCS_CTRL_FWD_ERR_CONN;
4417 writel(val, mpcs + MVPP22_MPCS_CTRL);
4418
4419 val = readl(mpcs + MVPP22_MPCS_CLK_RESET);
4420 val &= ~(MVPP22_MPCS_CLK_RESET_DIV_RATIO(0x7) | MAC_CLK_RESET_MAC |
4421 MAC_CLK_RESET_SD_RX | MAC_CLK_RESET_SD_TX);
4422 val |= MVPP22_MPCS_CLK_RESET_DIV_RATIO(1);
4423 writel(val, mpcs + MVPP22_MPCS_CLK_RESET);
4424
4425 val &= ~MVPP22_MPCS_CLK_RESET_DIV_SET;
4426 val |= MAC_CLK_RESET_MAC | MAC_CLK_RESET_SD_RX | MAC_CLK_RESET_SD_TX;
4427 writel(val, mpcs + MVPP22_MPCS_CLK_RESET);
4428}
4429
4430static int mvpp22_gop_init(struct mvpp2_port *port)
4431{
4432 struct mvpp2 *priv = port->priv;
4433 u32 val;
4434
4435 if (!priv->sysctrl_base)
4436 return 0;
4437
4438 switch (port->phy_interface) {
4439 case PHY_INTERFACE_MODE_RGMII:
4440 case PHY_INTERFACE_MODE_RGMII_ID:
4441 case PHY_INTERFACE_MODE_RGMII_RXID:
4442 case PHY_INTERFACE_MODE_RGMII_TXID:
4443 if (port->gop_id == 0)
4444 goto invalid_conf;
4445 mvpp22_gop_init_rgmii(port);
4446 break;
4447 case PHY_INTERFACE_MODE_SGMII:
4448 mvpp22_gop_init_sgmii(port);
4449 break;
4450 case PHY_INTERFACE_MODE_10GKR:
4451 if (port->gop_id != 0)
4452 goto invalid_conf;
4453 mvpp22_gop_init_10gkr(port);
4454 break;
4455 default:
4456 goto unsupported_conf;
4457 }
4458
4459 regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL1, &val);
4460 val |= GENCONF_PORT_CTRL1_RESET(port->gop_id) |
4461 GENCONF_PORT_CTRL1_EN(port->gop_id);
4462 regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL1, val);
4463
4464 regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL0, &val);
4465 val |= GENCONF_PORT_CTRL0_CLK_DIV_PHASE_CLR;
4466 regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL0, val);
4467
4468 regmap_read(priv->sysctrl_base, GENCONF_SOFT_RESET1, &val);
4469 val |= GENCONF_SOFT_RESET1_GOP;
4470 regmap_write(priv->sysctrl_base, GENCONF_SOFT_RESET1, val);
4471
4472unsupported_conf:
4473 return 0;
4474
4475invalid_conf:
4476 netdev_err(port->dev, "Invalid port configuration\n");
4477 return -EINVAL;
4478}
4479
Antoine Tenartfd3651b2017-09-01 11:04:54 +02004480static void mvpp22_gop_unmask_irq(struct mvpp2_port *port)
4481{
4482 u32 val;
4483
4484 if (phy_interface_mode_is_rgmii(port->phy_interface) ||
4485 port->phy_interface == PHY_INTERFACE_MODE_SGMII) {
4486 /* Enable the GMAC link status irq for this port */
4487 val = readl(port->base + MVPP22_GMAC_INT_SUM_MASK);
4488 val |= MVPP22_GMAC_INT_SUM_MASK_LINK_STAT;
4489 writel(val, port->base + MVPP22_GMAC_INT_SUM_MASK);
4490 }
4491
4492 if (port->gop_id == 0) {
4493 /* Enable the XLG/GIG irqs for this port */
4494 val = readl(port->base + MVPP22_XLG_EXT_INT_MASK);
4495 if (port->phy_interface == PHY_INTERFACE_MODE_10GKR)
4496 val |= MVPP22_XLG_EXT_INT_MASK_XLG;
4497 else
4498 val |= MVPP22_XLG_EXT_INT_MASK_GIG;
4499 writel(val, port->base + MVPP22_XLG_EXT_INT_MASK);
4500 }
4501}
4502
4503static void mvpp22_gop_mask_irq(struct mvpp2_port *port)
4504{
4505 u32 val;
4506
4507 if (port->gop_id == 0) {
4508 val = readl(port->base + MVPP22_XLG_EXT_INT_MASK);
4509 val &= ~(MVPP22_XLG_EXT_INT_MASK_XLG |
4510 MVPP22_XLG_EXT_INT_MASK_GIG);
4511 writel(val, port->base + MVPP22_XLG_EXT_INT_MASK);
4512 }
4513
4514 if (phy_interface_mode_is_rgmii(port->phy_interface) ||
4515 port->phy_interface == PHY_INTERFACE_MODE_SGMII) {
4516 val = readl(port->base + MVPP22_GMAC_INT_SUM_MASK);
4517 val &= ~MVPP22_GMAC_INT_SUM_MASK_LINK_STAT;
4518 writel(val, port->base + MVPP22_GMAC_INT_SUM_MASK);
4519 }
4520}
4521
4522static void mvpp22_gop_setup_irq(struct mvpp2_port *port)
4523{
4524 u32 val;
4525
4526 if (phy_interface_mode_is_rgmii(port->phy_interface) ||
4527 port->phy_interface == PHY_INTERFACE_MODE_SGMII) {
4528 val = readl(port->base + MVPP22_GMAC_INT_MASK);
4529 val |= MVPP22_GMAC_INT_MASK_LINK_STAT;
4530 writel(val, port->base + MVPP22_GMAC_INT_MASK);
4531 }
4532
4533 if (port->gop_id == 0) {
4534 val = readl(port->base + MVPP22_XLG_INT_MASK);
4535 val |= MVPP22_XLG_INT_MASK_LINK;
4536 writel(val, port->base + MVPP22_XLG_INT_MASK);
4537 }
4538
4539 mvpp22_gop_unmask_irq(port);
4540}
4541
Antoine Tenart542897d2017-08-30 10:29:15 +02004542static int mvpp22_comphy_init(struct mvpp2_port *port)
4543{
4544 enum phy_mode mode;
4545 int ret;
4546
4547 if (!port->comphy)
4548 return 0;
4549
4550 switch (port->phy_interface) {
4551 case PHY_INTERFACE_MODE_SGMII:
4552 mode = PHY_MODE_SGMII;
4553 break;
4554 case PHY_INTERFACE_MODE_10GKR:
4555 mode = PHY_MODE_10GKR;
4556 break;
4557 default:
4558 return -EINVAL;
4559 }
4560
4561 ret = phy_set_mode(port->comphy, mode);
4562 if (ret)
4563 return ret;
4564
4565 return phy_power_on(port->comphy);
4566}
4567
Antoine Ténart39193572017-08-22 19:08:24 +02004568static void mvpp2_port_mii_gmac_configure_mode(struct mvpp2_port *port)
4569{
4570 u32 val;
4571
4572 if (port->phy_interface == PHY_INTERFACE_MODE_SGMII) {
4573 val = readl(port->base + MVPP22_GMAC_CTRL_4_REG);
4574 val |= MVPP22_CTRL4_SYNC_BYPASS_DIS | MVPP22_CTRL4_DP_CLK_SEL |
4575 MVPP22_CTRL4_QSGMII_BYPASS_ACTIVE;
4576 val &= ~MVPP22_CTRL4_EXT_PIN_GMII_SEL;
4577 writel(val, port->base + MVPP22_GMAC_CTRL_4_REG);
4578
4579 val = readl(port->base + MVPP2_GMAC_CTRL_2_REG);
4580 val |= MVPP2_GMAC_DISABLE_PADDING;
4581 val &= ~MVPP2_GMAC_FLOW_CTRL_MASK;
4582 writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
Antoine Tenart1df22702017-09-01 11:04:52 +02004583 } else if (phy_interface_mode_is_rgmii(port->phy_interface)) {
Antoine Ténart39193572017-08-22 19:08:24 +02004584 val = readl(port->base + MVPP22_GMAC_CTRL_4_REG);
4585 val |= MVPP22_CTRL4_EXT_PIN_GMII_SEL |
4586 MVPP22_CTRL4_SYNC_BYPASS_DIS |
4587 MVPP22_CTRL4_QSGMII_BYPASS_ACTIVE;
4588 val &= ~MVPP22_CTRL4_DP_CLK_SEL;
4589 writel(val, port->base + MVPP22_GMAC_CTRL_4_REG);
4590
4591 val = readl(port->base + MVPP2_GMAC_CTRL_2_REG);
4592 val &= ~MVPP2_GMAC_DISABLE_PADDING;
4593 writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
4594 }
4595
4596 /* The port is connected to a copper PHY */
4597 val = readl(port->base + MVPP2_GMAC_CTRL_0_REG);
4598 val &= ~MVPP2_GMAC_PORT_TYPE_MASK;
4599 writel(val, port->base + MVPP2_GMAC_CTRL_0_REG);
4600
4601 val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG);
4602 val |= MVPP2_GMAC_IN_BAND_AUTONEG_BYPASS |
4603 MVPP2_GMAC_AN_SPEED_EN | MVPP2_GMAC_FLOW_CTRL_AUTONEG |
4604 MVPP2_GMAC_AN_DUPLEX_EN;
4605 if (port->phy_interface == PHY_INTERFACE_MODE_SGMII)
4606 val |= MVPP2_GMAC_IN_BAND_AUTONEG;
4607 writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG);
4608}
4609
4610static void mvpp2_port_mii_gmac_configure(struct mvpp2_port *port)
4611{
4612 u32 val;
4613
4614 /* Force link down */
4615 val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG);
4616 val &= ~MVPP2_GMAC_FORCE_LINK_PASS;
4617 val |= MVPP2_GMAC_FORCE_LINK_DOWN;
4618 writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG);
4619
4620 /* Set the GMAC in a reset state */
4621 val = readl(port->base + MVPP2_GMAC_CTRL_2_REG);
4622 val |= MVPP2_GMAC_PORT_RESET_MASK;
4623 writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
4624
4625 /* Configure the PCS and in-band AN */
4626 val = readl(port->base + MVPP2_GMAC_CTRL_2_REG);
4627 if (port->phy_interface == PHY_INTERFACE_MODE_SGMII) {
4628 val |= MVPP2_GMAC_INBAND_AN_MASK | MVPP2_GMAC_PCS_ENABLE_MASK;
Antoine Tenart1df22702017-09-01 11:04:52 +02004629 } else if (phy_interface_mode_is_rgmii(port->phy_interface)) {
Antoine Ténart39193572017-08-22 19:08:24 +02004630 val &= ~MVPP2_GMAC_PCS_ENABLE_MASK;
Antoine Ténart39193572017-08-22 19:08:24 +02004631 }
4632 writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
4633
4634 mvpp2_port_mii_gmac_configure_mode(port);
4635
4636 /* Unset the GMAC reset state */
4637 val = readl(port->base + MVPP2_GMAC_CTRL_2_REG);
4638 val &= ~MVPP2_GMAC_PORT_RESET_MASK;
4639 writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
4640
4641 /* Stop forcing link down */
4642 val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG);
4643 val &= ~MVPP2_GMAC_FORCE_LINK_DOWN;
4644 writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG);
4645}
4646
Antoine Ténart77321952017-08-22 19:08:25 +02004647static void mvpp2_port_mii_xlg_configure(struct mvpp2_port *port)
4648{
4649 u32 val;
4650
4651 if (port->gop_id != 0)
4652 return;
4653
4654 val = readl(port->base + MVPP22_XLG_CTRL0_REG);
4655 val |= MVPP22_XLG_CTRL0_RX_FLOW_CTRL_EN;
4656 writel(val, port->base + MVPP22_XLG_CTRL0_REG);
4657
4658 val = readl(port->base + MVPP22_XLG_CTRL4_REG);
4659 val &= ~MVPP22_XLG_CTRL4_MACMODSELECT_GMAC;
4660 val |= MVPP22_XLG_CTRL4_FWD_FC | MVPP22_XLG_CTRL4_FWD_PFC;
4661 writel(val, port->base + MVPP22_XLG_CTRL4_REG);
4662}
4663
Thomas Petazzoni26975822017-03-07 16:53:14 +01004664static void mvpp22_port_mii_set(struct mvpp2_port *port)
4665{
4666 u32 val;
4667
Thomas Petazzoni26975822017-03-07 16:53:14 +01004668 /* Only GOP port 0 has an XLG MAC */
4669 if (port->gop_id == 0) {
4670 val = readl(port->base + MVPP22_XLG_CTRL3_REG);
4671 val &= ~MVPP22_XLG_CTRL3_MACMODESELECT_MASK;
Antoine Ténart725757a2017-06-12 16:01:39 +02004672
4673 if (port->phy_interface == PHY_INTERFACE_MODE_XAUI ||
4674 port->phy_interface == PHY_INTERFACE_MODE_10GKR)
4675 val |= MVPP22_XLG_CTRL3_MACMODESELECT_10G;
4676 else
4677 val |= MVPP22_XLG_CTRL3_MACMODESELECT_GMAC;
4678
Thomas Petazzoni26975822017-03-07 16:53:14 +01004679 writel(val, port->base + MVPP22_XLG_CTRL3_REG);
4680 }
Thomas Petazzoni26975822017-03-07 16:53:14 +01004681}
4682
Marcin Wojtas3f518502014-07-10 16:52:13 -03004683static void mvpp2_port_mii_set(struct mvpp2_port *port)
4684{
Thomas Petazzoni26975822017-03-07 16:53:14 +01004685 if (port->priv->hw_version == MVPP22)
4686 mvpp22_port_mii_set(port);
4687
Antoine Tenart1df22702017-09-01 11:04:52 +02004688 if (phy_interface_mode_is_rgmii(port->phy_interface) ||
Antoine Ténart39193572017-08-22 19:08:24 +02004689 port->phy_interface == PHY_INTERFACE_MODE_SGMII)
4690 mvpp2_port_mii_gmac_configure(port);
Antoine Ténart77321952017-08-22 19:08:25 +02004691 else if (port->phy_interface == PHY_INTERFACE_MODE_10GKR)
4692 mvpp2_port_mii_xlg_configure(port);
Marcin Wojtas08a23752014-07-21 13:48:12 -03004693}
4694
4695static void mvpp2_port_fc_adv_enable(struct mvpp2_port *port)
4696{
4697 u32 val;
4698
4699 val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG);
4700 val |= MVPP2_GMAC_FC_ADV_EN;
4701 writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004702}
4703
4704static void mvpp2_port_enable(struct mvpp2_port *port)
4705{
4706 u32 val;
4707
Antoine Ténart725757a2017-06-12 16:01:39 +02004708 /* Only GOP port 0 has an XLG MAC */
4709 if (port->gop_id == 0 &&
4710 (port->phy_interface == PHY_INTERFACE_MODE_XAUI ||
4711 port->phy_interface == PHY_INTERFACE_MODE_10GKR)) {
4712 val = readl(port->base + MVPP22_XLG_CTRL0_REG);
4713 val |= MVPP22_XLG_CTRL0_PORT_EN |
4714 MVPP22_XLG_CTRL0_MAC_RESET_DIS;
4715 val &= ~MVPP22_XLG_CTRL0_MIB_CNT_DIS;
4716 writel(val, port->base + MVPP22_XLG_CTRL0_REG);
4717 } else {
4718 val = readl(port->base + MVPP2_GMAC_CTRL_0_REG);
4719 val |= MVPP2_GMAC_PORT_EN_MASK;
4720 val |= MVPP2_GMAC_MIB_CNTR_EN_MASK;
4721 writel(val, port->base + MVPP2_GMAC_CTRL_0_REG);
4722 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03004723}
4724
4725static void mvpp2_port_disable(struct mvpp2_port *port)
4726{
4727 u32 val;
4728
Antoine Ténart725757a2017-06-12 16:01:39 +02004729 /* Only GOP port 0 has an XLG MAC */
4730 if (port->gop_id == 0 &&
4731 (port->phy_interface == PHY_INTERFACE_MODE_XAUI ||
4732 port->phy_interface == PHY_INTERFACE_MODE_10GKR)) {
4733 val = readl(port->base + MVPP22_XLG_CTRL0_REG);
4734 val &= ~(MVPP22_XLG_CTRL0_PORT_EN |
4735 MVPP22_XLG_CTRL0_MAC_RESET_DIS);
4736 writel(val, port->base + MVPP22_XLG_CTRL0_REG);
4737 } else {
4738 val = readl(port->base + MVPP2_GMAC_CTRL_0_REG);
4739 val &= ~(MVPP2_GMAC_PORT_EN_MASK);
4740 writel(val, port->base + MVPP2_GMAC_CTRL_0_REG);
4741 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03004742}
4743
4744/* Set IEEE 802.3x Flow Control Xon Packet Transmission Mode */
4745static void mvpp2_port_periodic_xon_disable(struct mvpp2_port *port)
4746{
4747 u32 val;
4748
4749 val = readl(port->base + MVPP2_GMAC_CTRL_1_REG) &
4750 ~MVPP2_GMAC_PERIODIC_XON_EN_MASK;
4751 writel(val, port->base + MVPP2_GMAC_CTRL_1_REG);
4752}
4753
4754/* Configure loopback port */
4755static void mvpp2_port_loopback_set(struct mvpp2_port *port)
4756{
4757 u32 val;
4758
4759 val = readl(port->base + MVPP2_GMAC_CTRL_1_REG);
4760
4761 if (port->speed == 1000)
4762 val |= MVPP2_GMAC_GMII_LB_EN_MASK;
4763 else
4764 val &= ~MVPP2_GMAC_GMII_LB_EN_MASK;
4765
4766 if (port->phy_interface == PHY_INTERFACE_MODE_SGMII)
4767 val |= MVPP2_GMAC_PCS_LB_EN_MASK;
4768 else
4769 val &= ~MVPP2_GMAC_PCS_LB_EN_MASK;
4770
4771 writel(val, port->base + MVPP2_GMAC_CTRL_1_REG);
4772}
4773
4774static void mvpp2_port_reset(struct mvpp2_port *port)
4775{
4776 u32 val;
4777
4778 val = readl(port->base + MVPP2_GMAC_CTRL_2_REG) &
4779 ~MVPP2_GMAC_PORT_RESET_MASK;
4780 writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
4781
4782 while (readl(port->base + MVPP2_GMAC_CTRL_2_REG) &
4783 MVPP2_GMAC_PORT_RESET_MASK)
4784 continue;
4785}
4786
4787/* Change maximum receive size of the port */
4788static inline void mvpp2_gmac_max_rx_size_set(struct mvpp2_port *port)
4789{
4790 u32 val;
4791
4792 val = readl(port->base + MVPP2_GMAC_CTRL_0_REG);
4793 val &= ~MVPP2_GMAC_MAX_RX_SIZE_MASK;
4794 val |= (((port->pkt_size - MVPP2_MH_SIZE) / 2) <<
4795 MVPP2_GMAC_MAX_RX_SIZE_OFFS);
4796 writel(val, port->base + MVPP2_GMAC_CTRL_0_REG);
4797}
4798
Stefan Chulski76eb1b12017-08-22 19:08:26 +02004799/* Change maximum receive size of the port */
4800static inline void mvpp2_xlg_max_rx_size_set(struct mvpp2_port *port)
4801{
4802 u32 val;
4803
4804 val = readl(port->base + MVPP22_XLG_CTRL1_REG);
4805 val &= ~MVPP22_XLG_CTRL1_FRAMESIZELIMIT_MASK;
4806 val |= ((port->pkt_size - MVPP2_MH_SIZE) / 2) <<
Antoine Ténartec15ecd2017-08-25 15:24:46 +02004807 MVPP22_XLG_CTRL1_FRAMESIZELIMIT_OFFS;
Stefan Chulski76eb1b12017-08-22 19:08:26 +02004808 writel(val, port->base + MVPP22_XLG_CTRL1_REG);
4809}
4810
Marcin Wojtas3f518502014-07-10 16:52:13 -03004811/* Set defaults to the MVPP2 port */
4812static void mvpp2_defaults_set(struct mvpp2_port *port)
4813{
4814 int tx_port_num, val, queue, ptxq, lrxq;
4815
Thomas Petazzoni3d9017d2017-03-07 16:53:11 +01004816 if (port->priv->hw_version == MVPP21) {
4817 /* Configure port to loopback if needed */
4818 if (port->flags & MVPP2_F_LOOPBACK)
4819 mvpp2_port_loopback_set(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004820
Thomas Petazzoni3d9017d2017-03-07 16:53:11 +01004821 /* Update TX FIFO MIN Threshold */
4822 val = readl(port->base + MVPP2_GMAC_PORT_FIFO_CFG_1_REG);
4823 val &= ~MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK;
4824 /* Min. TX threshold must be less than minimal packet length */
4825 val |= MVPP2_GMAC_TX_FIFO_MIN_TH_MASK(64 - 4 - 2);
4826 writel(val, port->base + MVPP2_GMAC_PORT_FIFO_CFG_1_REG);
4827 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03004828
4829 /* Disable Legacy WRR, Disable EJP, Release from reset */
4830 tx_port_num = mvpp2_egress_port(port);
4831 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG,
4832 tx_port_num);
4833 mvpp2_write(port->priv, MVPP2_TXP_SCHED_CMD_1_REG, 0);
4834
4835 /* Close bandwidth for all queues */
4836 for (queue = 0; queue < MVPP2_MAX_TXQ; queue++) {
4837 ptxq = mvpp2_txq_phys(port->id, queue);
4838 mvpp2_write(port->priv,
4839 MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(ptxq), 0);
4840 }
4841
4842 /* Set refill period to 1 usec, refill tokens
4843 * and bucket size to maximum
4844 */
4845 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PERIOD_REG,
4846 port->priv->tclk / USEC_PER_SEC);
4847 val = mvpp2_read(port->priv, MVPP2_TXP_SCHED_REFILL_REG);
4848 val &= ~MVPP2_TXP_REFILL_PERIOD_ALL_MASK;
4849 val |= MVPP2_TXP_REFILL_PERIOD_MASK(1);
4850 val |= MVPP2_TXP_REFILL_TOKENS_ALL_MASK;
4851 mvpp2_write(port->priv, MVPP2_TXP_SCHED_REFILL_REG, val);
4852 val = MVPP2_TXP_TOKEN_SIZE_MAX;
4853 mvpp2_write(port->priv, MVPP2_TXP_SCHED_TOKEN_SIZE_REG, val);
4854
4855 /* Set MaximumLowLatencyPacketSize value to 256 */
4856 mvpp2_write(port->priv, MVPP2_RX_CTRL_REG(port->id),
4857 MVPP2_RX_USE_PSEUDO_FOR_CSUM_MASK |
4858 MVPP2_RX_LOW_LATENCY_PKT_SIZE(256));
4859
4860 /* Enable Rx cache snoop */
Thomas Petazzoni09f83972017-08-03 10:41:57 +02004861 for (lrxq = 0; lrxq < port->nrxqs; lrxq++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03004862 queue = port->rxqs[lrxq]->id;
4863 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(queue));
4864 val |= MVPP2_SNOOP_PKT_SIZE_MASK |
4865 MVPP2_SNOOP_BUF_HDR_MASK;
4866 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(queue), val);
4867 }
4868
4869 /* At default, mask all interrupts to all present cpus */
4870 mvpp2_interrupts_disable(port);
4871}
4872
4873/* Enable/disable receiving packets */
4874static void mvpp2_ingress_enable(struct mvpp2_port *port)
4875{
4876 u32 val;
4877 int lrxq, queue;
4878
Thomas Petazzoni09f83972017-08-03 10:41:57 +02004879 for (lrxq = 0; lrxq < port->nrxqs; lrxq++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03004880 queue = port->rxqs[lrxq]->id;
4881 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(queue));
4882 val &= ~MVPP2_RXQ_DISABLE_MASK;
4883 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(queue), val);
4884 }
4885}
4886
4887static void mvpp2_ingress_disable(struct mvpp2_port *port)
4888{
4889 u32 val;
4890 int lrxq, queue;
4891
Thomas Petazzoni09f83972017-08-03 10:41:57 +02004892 for (lrxq = 0; lrxq < port->nrxqs; lrxq++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03004893 queue = port->rxqs[lrxq]->id;
4894 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(queue));
4895 val |= MVPP2_RXQ_DISABLE_MASK;
4896 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(queue), val);
4897 }
4898}
4899
4900/* Enable transmit via physical egress queue
4901 * - HW starts take descriptors from DRAM
4902 */
4903static void mvpp2_egress_enable(struct mvpp2_port *port)
4904{
4905 u32 qmap;
4906 int queue;
4907 int tx_port_num = mvpp2_egress_port(port);
4908
4909 /* Enable all initialized TXs. */
4910 qmap = 0;
Thomas Petazzoni09f83972017-08-03 10:41:57 +02004911 for (queue = 0; queue < port->ntxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03004912 struct mvpp2_tx_queue *txq = port->txqs[queue];
4913
Markus Elfringdbbb2f02017-04-17 14:07:52 +02004914 if (txq->descs)
Marcin Wojtas3f518502014-07-10 16:52:13 -03004915 qmap |= (1 << queue);
4916 }
4917
4918 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num);
4919 mvpp2_write(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG, qmap);
4920}
4921
4922/* Disable transmit via physical egress queue
4923 * - HW doesn't take descriptors from DRAM
4924 */
4925static void mvpp2_egress_disable(struct mvpp2_port *port)
4926{
4927 u32 reg_data;
4928 int delay;
4929 int tx_port_num = mvpp2_egress_port(port);
4930
4931 /* Issue stop command for active channels only */
4932 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num);
4933 reg_data = (mvpp2_read(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG)) &
4934 MVPP2_TXP_SCHED_ENQ_MASK;
4935 if (reg_data != 0)
4936 mvpp2_write(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG,
4937 (reg_data << MVPP2_TXP_SCHED_DISQ_OFFSET));
4938
4939 /* Wait for all Tx activity to terminate. */
4940 delay = 0;
4941 do {
4942 if (delay >= MVPP2_TX_DISABLE_TIMEOUT_MSEC) {
4943 netdev_warn(port->dev,
4944 "Tx stop timed out, status=0x%08x\n",
4945 reg_data);
4946 break;
4947 }
4948 mdelay(1);
4949 delay++;
4950
4951 /* Check port TX Command register that all
4952 * Tx queues are stopped
4953 */
4954 reg_data = mvpp2_read(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG);
4955 } while (reg_data & MVPP2_TXP_SCHED_ENQ_MASK);
4956}
4957
4958/* Rx descriptors helper methods */
4959
4960/* Get number of Rx descriptors occupied by received packets */
4961static inline int
4962mvpp2_rxq_received(struct mvpp2_port *port, int rxq_id)
4963{
4964 u32 val = mvpp2_read(port->priv, MVPP2_RXQ_STATUS_REG(rxq_id));
4965
4966 return val & MVPP2_RXQ_OCCUPIED_MASK;
4967}
4968
4969/* Update Rx queue status with the number of occupied and available
4970 * Rx descriptor slots.
4971 */
4972static inline void
4973mvpp2_rxq_status_update(struct mvpp2_port *port, int rxq_id,
4974 int used_count, int free_count)
4975{
4976 /* Decrement the number of used descriptors and increment count
4977 * increment the number of free descriptors.
4978 */
4979 u32 val = used_count | (free_count << MVPP2_RXQ_NUM_NEW_OFFSET);
4980
4981 mvpp2_write(port->priv, MVPP2_RXQ_STATUS_UPDATE_REG(rxq_id), val);
4982}
4983
4984/* Get pointer to next RX descriptor to be processed by SW */
4985static inline struct mvpp2_rx_desc *
4986mvpp2_rxq_next_desc_get(struct mvpp2_rx_queue *rxq)
4987{
4988 int rx_desc = rxq->next_desc_to_proc;
4989
4990 rxq->next_desc_to_proc = MVPP2_QUEUE_NEXT_DESC(rxq, rx_desc);
4991 prefetch(rxq->descs + rxq->next_desc_to_proc);
4992 return rxq->descs + rx_desc;
4993}
4994
4995/* Set rx queue offset */
4996static void mvpp2_rxq_offset_set(struct mvpp2_port *port,
4997 int prxq, int offset)
4998{
4999 u32 val;
5000
5001 /* Convert offset from bytes to units of 32 bytes */
5002 offset = offset >> 5;
5003
5004 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(prxq));
5005 val &= ~MVPP2_RXQ_PACKET_OFFSET_MASK;
5006
5007 /* Offset is in */
5008 val |= ((offset << MVPP2_RXQ_PACKET_OFFSET_OFFS) &
5009 MVPP2_RXQ_PACKET_OFFSET_MASK);
5010
5011 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(prxq), val);
5012}
5013
Marcin Wojtas3f518502014-07-10 16:52:13 -03005014/* Tx descriptors helper methods */
5015
Marcin Wojtas3f518502014-07-10 16:52:13 -03005016/* Get pointer to next Tx descriptor to be processed (send) by HW */
5017static struct mvpp2_tx_desc *
5018mvpp2_txq_next_desc_get(struct mvpp2_tx_queue *txq)
5019{
5020 int tx_desc = txq->next_desc_to_proc;
5021
5022 txq->next_desc_to_proc = MVPP2_QUEUE_NEXT_DESC(txq, tx_desc);
5023 return txq->descs + tx_desc;
5024}
5025
Thomas Petazzonie0af22d2017-06-22 14:23:18 +02005026/* Update HW with number of aggregated Tx descriptors to be sent
5027 *
5028 * Called only from mvpp2_tx(), so migration is disabled, using
5029 * smp_processor_id() is OK.
5030 */
Marcin Wojtas3f518502014-07-10 16:52:13 -03005031static void mvpp2_aggr_txq_pend_desc_add(struct mvpp2_port *port, int pending)
5032{
5033 /* aggregated access - relevant TXQ number is written in TX desc */
Thomas Petazzonia7868412017-03-07 16:53:13 +01005034 mvpp2_percpu_write(port->priv, smp_processor_id(),
5035 MVPP2_AGGR_TXQ_UPDATE_REG, pending);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005036}
5037
5038
5039/* Check if there are enough free descriptors in aggregated txq.
5040 * If not, update the number of occupied descriptors and repeat the check.
Thomas Petazzonie0af22d2017-06-22 14:23:18 +02005041 *
5042 * Called only from mvpp2_tx(), so migration is disabled, using
5043 * smp_processor_id() is OK.
Marcin Wojtas3f518502014-07-10 16:52:13 -03005044 */
5045static int mvpp2_aggr_desc_num_check(struct mvpp2 *priv,
5046 struct mvpp2_tx_queue *aggr_txq, int num)
5047{
5048 if ((aggr_txq->count + num) > aggr_txq->size) {
5049 /* Update number of occupied aggregated Tx descriptors */
5050 int cpu = smp_processor_id();
5051 u32 val = mvpp2_read(priv, MVPP2_AGGR_TXQ_STATUS_REG(cpu));
5052
5053 aggr_txq->count = val & MVPP2_AGGR_TXQ_PENDING_MASK;
5054 }
5055
5056 if ((aggr_txq->count + num) > aggr_txq->size)
5057 return -ENOMEM;
5058
5059 return 0;
5060}
5061
Thomas Petazzonie0af22d2017-06-22 14:23:18 +02005062/* Reserved Tx descriptors allocation request
5063 *
5064 * Called only from mvpp2_txq_reserved_desc_num_proc(), itself called
5065 * only by mvpp2_tx(), so migration is disabled, using
5066 * smp_processor_id() is OK.
5067 */
Marcin Wojtas3f518502014-07-10 16:52:13 -03005068static int mvpp2_txq_alloc_reserved_desc(struct mvpp2 *priv,
5069 struct mvpp2_tx_queue *txq, int num)
5070{
5071 u32 val;
Thomas Petazzonia7868412017-03-07 16:53:13 +01005072 int cpu = smp_processor_id();
Marcin Wojtas3f518502014-07-10 16:52:13 -03005073
5074 val = (txq->id << MVPP2_TXQ_RSVD_REQ_Q_OFFSET) | num;
Thomas Petazzonia7868412017-03-07 16:53:13 +01005075 mvpp2_percpu_write(priv, cpu, MVPP2_TXQ_RSVD_REQ_REG, val);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005076
Thomas Petazzonia7868412017-03-07 16:53:13 +01005077 val = mvpp2_percpu_read(priv, cpu, MVPP2_TXQ_RSVD_RSLT_REG);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005078
5079 return val & MVPP2_TXQ_RSVD_RSLT_MASK;
5080}
5081
5082/* Check if there are enough reserved descriptors for transmission.
5083 * If not, request chunk of reserved descriptors and check again.
5084 */
5085static int mvpp2_txq_reserved_desc_num_proc(struct mvpp2 *priv,
5086 struct mvpp2_tx_queue *txq,
5087 struct mvpp2_txq_pcpu *txq_pcpu,
5088 int num)
5089{
5090 int req, cpu, desc_count;
5091
5092 if (txq_pcpu->reserved_num >= num)
5093 return 0;
5094
5095 /* Not enough descriptors reserved! Update the reserved descriptor
5096 * count and check again.
5097 */
5098
5099 desc_count = 0;
5100 /* Compute total of used descriptors */
5101 for_each_present_cpu(cpu) {
5102 struct mvpp2_txq_pcpu *txq_pcpu_aux;
5103
5104 txq_pcpu_aux = per_cpu_ptr(txq->pcpu, cpu);
5105 desc_count += txq_pcpu_aux->count;
5106 desc_count += txq_pcpu_aux->reserved_num;
5107 }
5108
5109 req = max(MVPP2_CPU_DESC_CHUNK, num - txq_pcpu->reserved_num);
5110 desc_count += req;
5111
5112 if (desc_count >
5113 (txq->size - (num_present_cpus() * MVPP2_CPU_DESC_CHUNK)))
5114 return -ENOMEM;
5115
5116 txq_pcpu->reserved_num += mvpp2_txq_alloc_reserved_desc(priv, txq, req);
5117
5118 /* OK, the descriptor cound has been updated: check again. */
5119 if (txq_pcpu->reserved_num < num)
5120 return -ENOMEM;
5121 return 0;
5122}
5123
5124/* Release the last allocated Tx descriptor. Useful to handle DMA
5125 * mapping failures in the Tx path.
5126 */
5127static void mvpp2_txq_desc_put(struct mvpp2_tx_queue *txq)
5128{
5129 if (txq->next_desc_to_proc == 0)
5130 txq->next_desc_to_proc = txq->last_desc - 1;
5131 else
5132 txq->next_desc_to_proc--;
5133}
5134
5135/* Set Tx descriptors fields relevant for CSUM calculation */
5136static u32 mvpp2_txq_desc_csum(int l3_offs, int l3_proto,
5137 int ip_hdr_len, int l4_proto)
5138{
5139 u32 command;
5140
5141 /* fields: L3_offset, IP_hdrlen, L3_type, G_IPv4_chk,
5142 * G_L4_chk, L4_type required only for checksum calculation
5143 */
5144 command = (l3_offs << MVPP2_TXD_L3_OFF_SHIFT);
5145 command |= (ip_hdr_len << MVPP2_TXD_IP_HLEN_SHIFT);
5146 command |= MVPP2_TXD_IP_CSUM_DISABLE;
5147
5148 if (l3_proto == swab16(ETH_P_IP)) {
5149 command &= ~MVPP2_TXD_IP_CSUM_DISABLE; /* enable IPv4 csum */
5150 command &= ~MVPP2_TXD_L3_IP6; /* enable IPv4 */
5151 } else {
5152 command |= MVPP2_TXD_L3_IP6; /* enable IPv6 */
5153 }
5154
5155 if (l4_proto == IPPROTO_TCP) {
5156 command &= ~MVPP2_TXD_L4_UDP; /* enable TCP */
5157 command &= ~MVPP2_TXD_L4_CSUM_FRAG; /* generate L4 csum */
5158 } else if (l4_proto == IPPROTO_UDP) {
5159 command |= MVPP2_TXD_L4_UDP; /* enable UDP */
5160 command &= ~MVPP2_TXD_L4_CSUM_FRAG; /* generate L4 csum */
5161 } else {
5162 command |= MVPP2_TXD_L4_CSUM_NOT;
5163 }
5164
5165 return command;
5166}
5167
5168/* Get number of sent descriptors and decrement counter.
5169 * The number of sent descriptors is returned.
5170 * Per-CPU access
Thomas Petazzonie0af22d2017-06-22 14:23:18 +02005171 *
5172 * Called only from mvpp2_txq_done(), called from mvpp2_tx()
5173 * (migration disabled) and from the TX completion tasklet (migration
5174 * disabled) so using smp_processor_id() is OK.
Marcin Wojtas3f518502014-07-10 16:52:13 -03005175 */
5176static inline int mvpp2_txq_sent_desc_proc(struct mvpp2_port *port,
5177 struct mvpp2_tx_queue *txq)
5178{
5179 u32 val;
5180
5181 /* Reading status reg resets transmitted descriptor counter */
Thomas Petazzonia7868412017-03-07 16:53:13 +01005182 val = mvpp2_percpu_read(port->priv, smp_processor_id(),
5183 MVPP2_TXQ_SENT_REG(txq->id));
Marcin Wojtas3f518502014-07-10 16:52:13 -03005184
5185 return (val & MVPP2_TRANSMITTED_COUNT_MASK) >>
5186 MVPP2_TRANSMITTED_COUNT_OFFSET;
5187}
5188
Thomas Petazzonie0af22d2017-06-22 14:23:18 +02005189/* Called through on_each_cpu(), so runs on all CPUs, with migration
5190 * disabled, therefore using smp_processor_id() is OK.
5191 */
Marcin Wojtas3f518502014-07-10 16:52:13 -03005192static void mvpp2_txq_sent_counter_clear(void *arg)
5193{
5194 struct mvpp2_port *port = arg;
5195 int queue;
5196
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005197 for (queue = 0; queue < port->ntxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005198 int id = port->txqs[queue]->id;
5199
Thomas Petazzonia7868412017-03-07 16:53:13 +01005200 mvpp2_percpu_read(port->priv, smp_processor_id(),
5201 MVPP2_TXQ_SENT_REG(id));
Marcin Wojtas3f518502014-07-10 16:52:13 -03005202 }
5203}
5204
5205/* Set max sizes for Tx queues */
5206static void mvpp2_txp_max_tx_size_set(struct mvpp2_port *port)
5207{
5208 u32 val, size, mtu;
5209 int txq, tx_port_num;
5210
5211 mtu = port->pkt_size * 8;
5212 if (mtu > MVPP2_TXP_MTU_MAX)
5213 mtu = MVPP2_TXP_MTU_MAX;
5214
5215 /* WA for wrong Token bucket update: Set MTU value = 3*real MTU value */
5216 mtu = 3 * mtu;
5217
5218 /* Indirect access to registers */
5219 tx_port_num = mvpp2_egress_port(port);
5220 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num);
5221
5222 /* Set MTU */
5223 val = mvpp2_read(port->priv, MVPP2_TXP_SCHED_MTU_REG);
5224 val &= ~MVPP2_TXP_MTU_MAX;
5225 val |= mtu;
5226 mvpp2_write(port->priv, MVPP2_TXP_SCHED_MTU_REG, val);
5227
5228 /* TXP token size and all TXQs token size must be larger that MTU */
5229 val = mvpp2_read(port->priv, MVPP2_TXP_SCHED_TOKEN_SIZE_REG);
5230 size = val & MVPP2_TXP_TOKEN_SIZE_MAX;
5231 if (size < mtu) {
5232 size = mtu;
5233 val &= ~MVPP2_TXP_TOKEN_SIZE_MAX;
5234 val |= size;
5235 mvpp2_write(port->priv, MVPP2_TXP_SCHED_TOKEN_SIZE_REG, val);
5236 }
5237
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005238 for (txq = 0; txq < port->ntxqs; txq++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005239 val = mvpp2_read(port->priv,
5240 MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq));
5241 size = val & MVPP2_TXQ_TOKEN_SIZE_MAX;
5242
5243 if (size < mtu) {
5244 size = mtu;
5245 val &= ~MVPP2_TXQ_TOKEN_SIZE_MAX;
5246 val |= size;
5247 mvpp2_write(port->priv,
5248 MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq),
5249 val);
5250 }
5251 }
5252}
5253
5254/* Set the number of packets that will be received before Rx interrupt
5255 * will be generated by HW.
5256 */
5257static void mvpp2_rx_pkts_coal_set(struct mvpp2_port *port,
Thomas Petazzonid63f9e42017-02-21 11:28:02 +01005258 struct mvpp2_rx_queue *rxq)
Marcin Wojtas3f518502014-07-10 16:52:13 -03005259{
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005260 int cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01005261
Thomas Petazzonif8b0d5f2017-02-21 11:28:03 +01005262 if (rxq->pkts_coal > MVPP2_OCCUPIED_THRESH_MASK)
5263 rxq->pkts_coal = MVPP2_OCCUPIED_THRESH_MASK;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005264
Thomas Petazzonia7868412017-03-07 16:53:13 +01005265 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_NUM_REG, rxq->id);
5266 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_THRESH_REG,
5267 rxq->pkts_coal);
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005268
5269 put_cpu();
Marcin Wojtas3f518502014-07-10 16:52:13 -03005270}
5271
Thomas Petazzoni213f4282017-08-03 10:42:00 +02005272/* For some reason in the LSP this is done on each CPU. Why ? */
5273static void mvpp2_tx_pkts_coal_set(struct mvpp2_port *port,
5274 struct mvpp2_tx_queue *txq)
5275{
5276 int cpu = get_cpu();
5277 u32 val;
5278
5279 if (txq->done_pkts_coal > MVPP2_TXQ_THRESH_MASK)
5280 txq->done_pkts_coal = MVPP2_TXQ_THRESH_MASK;
5281
5282 val = (txq->done_pkts_coal << MVPP2_TXQ_THRESH_OFFSET);
5283 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_NUM_REG, txq->id);
5284 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_THRESH_REG, val);
5285
5286 put_cpu();
5287}
5288
Thomas Petazzoniab426762017-02-21 11:28:04 +01005289static u32 mvpp2_usec_to_cycles(u32 usec, unsigned long clk_hz)
5290{
5291 u64 tmp = (u64)clk_hz * usec;
5292
5293 do_div(tmp, USEC_PER_SEC);
5294
5295 return tmp > U32_MAX ? U32_MAX : tmp;
5296}
5297
5298static u32 mvpp2_cycles_to_usec(u32 cycles, unsigned long clk_hz)
5299{
5300 u64 tmp = (u64)cycles * USEC_PER_SEC;
5301
5302 do_div(tmp, clk_hz);
5303
5304 return tmp > U32_MAX ? U32_MAX : tmp;
5305}
5306
Marcin Wojtas3f518502014-07-10 16:52:13 -03005307/* Set the time delay in usec before Rx interrupt */
5308static void mvpp2_rx_time_coal_set(struct mvpp2_port *port,
Thomas Petazzonid63f9e42017-02-21 11:28:02 +01005309 struct mvpp2_rx_queue *rxq)
Marcin Wojtas3f518502014-07-10 16:52:13 -03005310{
Thomas Petazzoniab426762017-02-21 11:28:04 +01005311 unsigned long freq = port->priv->tclk;
5312 u32 val = mvpp2_usec_to_cycles(rxq->time_coal, freq);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005313
Thomas Petazzoniab426762017-02-21 11:28:04 +01005314 if (val > MVPP2_MAX_ISR_RX_THRESHOLD) {
5315 rxq->time_coal =
5316 mvpp2_cycles_to_usec(MVPP2_MAX_ISR_RX_THRESHOLD, freq);
5317
5318 /* re-evaluate to get actual register value */
5319 val = mvpp2_usec_to_cycles(rxq->time_coal, freq);
5320 }
5321
Marcin Wojtas3f518502014-07-10 16:52:13 -03005322 mvpp2_write(port->priv, MVPP2_ISR_RX_THRESHOLD_REG(rxq->id), val);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005323}
5324
Thomas Petazzoni213f4282017-08-03 10:42:00 +02005325static void mvpp2_tx_time_coal_set(struct mvpp2_port *port)
5326{
5327 unsigned long freq = port->priv->tclk;
5328 u32 val = mvpp2_usec_to_cycles(port->tx_time_coal, freq);
5329
5330 if (val > MVPP2_MAX_ISR_TX_THRESHOLD) {
5331 port->tx_time_coal =
5332 mvpp2_cycles_to_usec(MVPP2_MAX_ISR_TX_THRESHOLD, freq);
5333
5334 /* re-evaluate to get actual register value */
5335 val = mvpp2_usec_to_cycles(port->tx_time_coal, freq);
5336 }
5337
5338 mvpp2_write(port->priv, MVPP2_ISR_TX_THRESHOLD_REG(port->id), val);
5339}
5340
Marcin Wojtas3f518502014-07-10 16:52:13 -03005341/* Free Tx queue skbuffs */
5342static void mvpp2_txq_bufs_free(struct mvpp2_port *port,
5343 struct mvpp2_tx_queue *txq,
5344 struct mvpp2_txq_pcpu *txq_pcpu, int num)
5345{
5346 int i;
5347
5348 for (i = 0; i < num; i++) {
Thomas Petazzoni83544912016-12-21 11:28:49 +01005349 struct mvpp2_txq_pcpu_buf *tx_buf =
5350 txq_pcpu->buffs + txq_pcpu->txq_get_index;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005351
Antoine Tenart20920262017-10-23 15:24:30 +02005352 if (!IS_TSO_HEADER(txq_pcpu, tx_buf->dma))
5353 dma_unmap_single(port->dev->dev.parent, tx_buf->dma,
5354 tx_buf->size, DMA_TO_DEVICE);
Thomas Petazzoni36fb7432017-02-21 11:28:05 +01005355 if (tx_buf->skb)
5356 dev_kfree_skb_any(tx_buf->skb);
5357
5358 mvpp2_txq_inc_get(txq_pcpu);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005359 }
5360}
5361
5362static inline struct mvpp2_rx_queue *mvpp2_get_rx_queue(struct mvpp2_port *port,
5363 u32 cause)
5364{
5365 int queue = fls(cause) - 1;
5366
5367 return port->rxqs[queue];
5368}
5369
5370static inline struct mvpp2_tx_queue *mvpp2_get_tx_queue(struct mvpp2_port *port,
5371 u32 cause)
5372{
Marcin Wojtasedc660f2015-08-06 19:00:30 +02005373 int queue = fls(cause) - 1;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005374
5375 return port->txqs[queue];
5376}
5377
5378/* Handle end of transmission */
5379static void mvpp2_txq_done(struct mvpp2_port *port, struct mvpp2_tx_queue *txq,
5380 struct mvpp2_txq_pcpu *txq_pcpu)
5381{
5382 struct netdev_queue *nq = netdev_get_tx_queue(port->dev, txq->log_id);
5383 int tx_done;
5384
5385 if (txq_pcpu->cpu != smp_processor_id())
5386 netdev_err(port->dev, "wrong cpu on the end of Tx processing\n");
5387
5388 tx_done = mvpp2_txq_sent_desc_proc(port, txq);
5389 if (!tx_done)
5390 return;
5391 mvpp2_txq_bufs_free(port, txq, txq_pcpu, tx_done);
5392
5393 txq_pcpu->count -= tx_done;
5394
5395 if (netif_tx_queue_stopped(nq))
5396 if (txq_pcpu->size - txq_pcpu->count >= MAX_SKB_FRAGS + 1)
5397 netif_tx_wake_queue(nq);
5398}
5399
Thomas Petazzoni213f4282017-08-03 10:42:00 +02005400static unsigned int mvpp2_tx_done(struct mvpp2_port *port, u32 cause,
5401 int cpu)
Marcin Wojtasedc660f2015-08-06 19:00:30 +02005402{
5403 struct mvpp2_tx_queue *txq;
5404 struct mvpp2_txq_pcpu *txq_pcpu;
5405 unsigned int tx_todo = 0;
5406
5407 while (cause) {
5408 txq = mvpp2_get_tx_queue(port, cause);
5409 if (!txq)
5410 break;
5411
Thomas Petazzoni213f4282017-08-03 10:42:00 +02005412 txq_pcpu = per_cpu_ptr(txq->pcpu, cpu);
Marcin Wojtasedc660f2015-08-06 19:00:30 +02005413
5414 if (txq_pcpu->count) {
5415 mvpp2_txq_done(port, txq, txq_pcpu);
5416 tx_todo += txq_pcpu->count;
5417 }
5418
5419 cause &= ~(1 << txq->log_id);
5420 }
5421 return tx_todo;
5422}
5423
Marcin Wojtas3f518502014-07-10 16:52:13 -03005424/* Rx/Tx queue initialization/cleanup methods */
5425
5426/* Allocate and initialize descriptors for aggr TXQ */
5427static int mvpp2_aggr_txq_init(struct platform_device *pdev,
Antoine Ténart85affd72017-08-23 09:46:55 +02005428 struct mvpp2_tx_queue *aggr_txq, int cpu,
Marcin Wojtas3f518502014-07-10 16:52:13 -03005429 struct mvpp2 *priv)
5430{
Thomas Petazzonib02f31f2017-03-07 16:53:12 +01005431 u32 txq_dma;
5432
Marcin Wojtas3f518502014-07-10 16:52:13 -03005433 /* Allocate memory for TX descriptors */
5434 aggr_txq->descs = dma_alloc_coherent(&pdev->dev,
Antoine Ténart85affd72017-08-23 09:46:55 +02005435 MVPP2_AGGR_TXQ_SIZE * MVPP2_DESC_ALIGNED_SIZE,
Thomas Petazzoni20396132017-03-07 16:53:00 +01005436 &aggr_txq->descs_dma, GFP_KERNEL);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005437 if (!aggr_txq->descs)
5438 return -ENOMEM;
5439
Marcin Wojtas3f518502014-07-10 16:52:13 -03005440 aggr_txq->last_desc = aggr_txq->size - 1;
5441
5442 /* Aggr TXQ no reset WA */
5443 aggr_txq->next_desc_to_proc = mvpp2_read(priv,
5444 MVPP2_AGGR_TXQ_INDEX_REG(cpu));
5445
Thomas Petazzonib02f31f2017-03-07 16:53:12 +01005446 /* Set Tx descriptors queue starting address indirect
5447 * access
5448 */
5449 if (priv->hw_version == MVPP21)
5450 txq_dma = aggr_txq->descs_dma;
5451 else
5452 txq_dma = aggr_txq->descs_dma >>
5453 MVPP22_AGGR_TXQ_DESC_ADDR_OFFS;
5454
5455 mvpp2_write(priv, MVPP2_AGGR_TXQ_DESC_ADDR_REG(cpu), txq_dma);
Antoine Ténart85affd72017-08-23 09:46:55 +02005456 mvpp2_write(priv, MVPP2_AGGR_TXQ_DESC_SIZE_REG(cpu),
5457 MVPP2_AGGR_TXQ_SIZE);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005458
5459 return 0;
5460}
5461
5462/* Create a specified Rx queue */
5463static int mvpp2_rxq_init(struct mvpp2_port *port,
5464 struct mvpp2_rx_queue *rxq)
5465
5466{
Thomas Petazzonib02f31f2017-03-07 16:53:12 +01005467 u32 rxq_dma;
Thomas Petazzonia7868412017-03-07 16:53:13 +01005468 int cpu;
Thomas Petazzonib02f31f2017-03-07 16:53:12 +01005469
Marcin Wojtas3f518502014-07-10 16:52:13 -03005470 rxq->size = port->rx_ring_size;
5471
5472 /* Allocate memory for RX descriptors */
5473 rxq->descs = dma_alloc_coherent(port->dev->dev.parent,
5474 rxq->size * MVPP2_DESC_ALIGNED_SIZE,
Thomas Petazzoni20396132017-03-07 16:53:00 +01005475 &rxq->descs_dma, GFP_KERNEL);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005476 if (!rxq->descs)
5477 return -ENOMEM;
5478
Marcin Wojtas3f518502014-07-10 16:52:13 -03005479 rxq->last_desc = rxq->size - 1;
5480
5481 /* Zero occupied and non-occupied counters - direct access */
5482 mvpp2_write(port->priv, MVPP2_RXQ_STATUS_REG(rxq->id), 0);
5483
5484 /* Set Rx descriptors queue starting address - indirect access */
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005485 cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01005486 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_NUM_REG, rxq->id);
Thomas Petazzonib02f31f2017-03-07 16:53:12 +01005487 if (port->priv->hw_version == MVPP21)
5488 rxq_dma = rxq->descs_dma;
5489 else
5490 rxq_dma = rxq->descs_dma >> MVPP22_DESC_ADDR_OFFS;
Thomas Petazzonia7868412017-03-07 16:53:13 +01005491 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_DESC_ADDR_REG, rxq_dma);
5492 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_DESC_SIZE_REG, rxq->size);
5493 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_INDEX_REG, 0);
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005494 put_cpu();
Marcin Wojtas3f518502014-07-10 16:52:13 -03005495
5496 /* Set Offset */
5497 mvpp2_rxq_offset_set(port, rxq->id, NET_SKB_PAD);
5498
5499 /* Set coalescing pkts and time */
Thomas Petazzonid63f9e42017-02-21 11:28:02 +01005500 mvpp2_rx_pkts_coal_set(port, rxq);
5501 mvpp2_rx_time_coal_set(port, rxq);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005502
5503 /* Add number of descriptors ready for receiving packets */
5504 mvpp2_rxq_status_update(port, rxq->id, 0, rxq->size);
5505
5506 return 0;
5507}
5508
5509/* Push packets received by the RXQ to BM pool */
5510static void mvpp2_rxq_drop_pkts(struct mvpp2_port *port,
5511 struct mvpp2_rx_queue *rxq)
5512{
5513 int rx_received, i;
5514
5515 rx_received = mvpp2_rxq_received(port, rxq->id);
5516 if (!rx_received)
5517 return;
5518
5519 for (i = 0; i < rx_received; i++) {
5520 struct mvpp2_rx_desc *rx_desc = mvpp2_rxq_next_desc_get(rxq);
Thomas Petazzoni56b8aae2017-06-10 23:18:21 +02005521 u32 status = mvpp2_rxdesc_status_get(port, rx_desc);
5522 int pool;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005523
Thomas Petazzoni56b8aae2017-06-10 23:18:21 +02005524 pool = (status & MVPP2_RXD_BM_POOL_ID_MASK) >>
5525 MVPP2_RXD_BM_POOL_ID_OFFS;
5526
Thomas Petazzoni7d7627b2017-06-22 14:23:20 +02005527 mvpp2_bm_pool_put(port, pool,
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01005528 mvpp2_rxdesc_dma_addr_get(port, rx_desc),
5529 mvpp2_rxdesc_cookie_get(port, rx_desc));
Marcin Wojtas3f518502014-07-10 16:52:13 -03005530 }
5531 mvpp2_rxq_status_update(port, rxq->id, rx_received, rx_received);
5532}
5533
5534/* Cleanup Rx queue */
5535static void mvpp2_rxq_deinit(struct mvpp2_port *port,
5536 struct mvpp2_rx_queue *rxq)
5537{
Thomas Petazzonia7868412017-03-07 16:53:13 +01005538 int cpu;
5539
Marcin Wojtas3f518502014-07-10 16:52:13 -03005540 mvpp2_rxq_drop_pkts(port, rxq);
5541
5542 if (rxq->descs)
5543 dma_free_coherent(port->dev->dev.parent,
5544 rxq->size * MVPP2_DESC_ALIGNED_SIZE,
5545 rxq->descs,
Thomas Petazzoni20396132017-03-07 16:53:00 +01005546 rxq->descs_dma);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005547
5548 rxq->descs = NULL;
5549 rxq->last_desc = 0;
5550 rxq->next_desc_to_proc = 0;
Thomas Petazzoni20396132017-03-07 16:53:00 +01005551 rxq->descs_dma = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005552
5553 /* Clear Rx descriptors queue starting address and size;
5554 * free descriptor number
5555 */
5556 mvpp2_write(port->priv, MVPP2_RXQ_STATUS_REG(rxq->id), 0);
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005557 cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01005558 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_NUM_REG, rxq->id);
5559 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_DESC_ADDR_REG, 0);
5560 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_DESC_SIZE_REG, 0);
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005561 put_cpu();
Marcin Wojtas3f518502014-07-10 16:52:13 -03005562}
5563
5564/* Create and initialize a Tx queue */
5565static int mvpp2_txq_init(struct mvpp2_port *port,
5566 struct mvpp2_tx_queue *txq)
5567{
5568 u32 val;
5569 int cpu, desc, desc_per_txq, tx_port_num;
5570 struct mvpp2_txq_pcpu *txq_pcpu;
5571
5572 txq->size = port->tx_ring_size;
5573
5574 /* Allocate memory for Tx descriptors */
5575 txq->descs = dma_alloc_coherent(port->dev->dev.parent,
5576 txq->size * MVPP2_DESC_ALIGNED_SIZE,
Thomas Petazzoni20396132017-03-07 16:53:00 +01005577 &txq->descs_dma, GFP_KERNEL);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005578 if (!txq->descs)
5579 return -ENOMEM;
5580
Marcin Wojtas3f518502014-07-10 16:52:13 -03005581 txq->last_desc = txq->size - 1;
5582
5583 /* Set Tx descriptors queue starting address - indirect access */
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005584 cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01005585 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_NUM_REG, txq->id);
5586 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_DESC_ADDR_REG,
5587 txq->descs_dma);
5588 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_DESC_SIZE_REG,
5589 txq->size & MVPP2_TXQ_DESC_SIZE_MASK);
5590 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_INDEX_REG, 0);
5591 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_RSVD_CLR_REG,
5592 txq->id << MVPP2_TXQ_RSVD_CLR_OFFSET);
5593 val = mvpp2_percpu_read(port->priv, cpu, MVPP2_TXQ_PENDING_REG);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005594 val &= ~MVPP2_TXQ_PENDING_MASK;
Thomas Petazzonia7868412017-03-07 16:53:13 +01005595 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_PENDING_REG, val);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005596
5597 /* Calculate base address in prefetch buffer. We reserve 16 descriptors
5598 * for each existing TXQ.
5599 * TCONTS for PON port must be continuous from 0 to MVPP2_MAX_TCONT
5600 * GBE ports assumed to be continious from 0 to MVPP2_MAX_PORTS
5601 */
5602 desc_per_txq = 16;
5603 desc = (port->id * MVPP2_MAX_TXQ * desc_per_txq) +
5604 (txq->log_id * desc_per_txq);
5605
Thomas Petazzonia7868412017-03-07 16:53:13 +01005606 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_PREF_BUF_REG,
5607 MVPP2_PREF_BUF_PTR(desc) | MVPP2_PREF_BUF_SIZE_16 |
5608 MVPP2_PREF_BUF_THRESH(desc_per_txq / 2));
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005609 put_cpu();
Marcin Wojtas3f518502014-07-10 16:52:13 -03005610
5611 /* WRR / EJP configuration - indirect access */
5612 tx_port_num = mvpp2_egress_port(port);
5613 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num);
5614
5615 val = mvpp2_read(port->priv, MVPP2_TXQ_SCHED_REFILL_REG(txq->log_id));
5616 val &= ~MVPP2_TXQ_REFILL_PERIOD_ALL_MASK;
5617 val |= MVPP2_TXQ_REFILL_PERIOD_MASK(1);
5618 val |= MVPP2_TXQ_REFILL_TOKENS_ALL_MASK;
5619 mvpp2_write(port->priv, MVPP2_TXQ_SCHED_REFILL_REG(txq->log_id), val);
5620
5621 val = MVPP2_TXQ_TOKEN_SIZE_MAX;
5622 mvpp2_write(port->priv, MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq->log_id),
5623 val);
5624
5625 for_each_present_cpu(cpu) {
5626 txq_pcpu = per_cpu_ptr(txq->pcpu, cpu);
5627 txq_pcpu->size = txq->size;
Markus Elfring02c91ec2017-04-17 08:09:07 +02005628 txq_pcpu->buffs = kmalloc_array(txq_pcpu->size,
5629 sizeof(*txq_pcpu->buffs),
5630 GFP_KERNEL);
Thomas Petazzoni83544912016-12-21 11:28:49 +01005631 if (!txq_pcpu->buffs)
Markus Elfring20b1e162017-04-17 12:58:33 +02005632 goto cleanup;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005633
5634 txq_pcpu->count = 0;
5635 txq_pcpu->reserved_num = 0;
5636 txq_pcpu->txq_put_index = 0;
5637 txq_pcpu->txq_get_index = 0;
Antoine Ténart186cd4d2017-08-23 09:46:56 +02005638
5639 txq_pcpu->tso_headers =
5640 dma_alloc_coherent(port->dev->dev.parent,
Yan Markman822eaf72017-10-23 15:24:29 +02005641 txq_pcpu->size * TSO_HEADER_SIZE,
Antoine Ténart186cd4d2017-08-23 09:46:56 +02005642 &txq_pcpu->tso_headers_dma,
5643 GFP_KERNEL);
5644 if (!txq_pcpu->tso_headers)
5645 goto cleanup;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005646 }
5647
5648 return 0;
Markus Elfring20b1e162017-04-17 12:58:33 +02005649cleanup:
Marcin Wojtas71ce3912015-08-06 19:00:29 +02005650 for_each_present_cpu(cpu) {
5651 txq_pcpu = per_cpu_ptr(txq->pcpu, cpu);
Thomas Petazzoni83544912016-12-21 11:28:49 +01005652 kfree(txq_pcpu->buffs);
Antoine Ténart186cd4d2017-08-23 09:46:56 +02005653
5654 dma_free_coherent(port->dev->dev.parent,
Yan Markman822eaf72017-10-23 15:24:29 +02005655 txq_pcpu->size * TSO_HEADER_SIZE,
Antoine Ténart186cd4d2017-08-23 09:46:56 +02005656 txq_pcpu->tso_headers,
5657 txq_pcpu->tso_headers_dma);
Marcin Wojtas71ce3912015-08-06 19:00:29 +02005658 }
5659
5660 dma_free_coherent(port->dev->dev.parent,
5661 txq->size * MVPP2_DESC_ALIGNED_SIZE,
Thomas Petazzoni20396132017-03-07 16:53:00 +01005662 txq->descs, txq->descs_dma);
Marcin Wojtas71ce3912015-08-06 19:00:29 +02005663
5664 return -ENOMEM;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005665}
5666
5667/* Free allocated TXQ resources */
5668static void mvpp2_txq_deinit(struct mvpp2_port *port,
5669 struct mvpp2_tx_queue *txq)
5670{
5671 struct mvpp2_txq_pcpu *txq_pcpu;
5672 int cpu;
5673
5674 for_each_present_cpu(cpu) {
5675 txq_pcpu = per_cpu_ptr(txq->pcpu, cpu);
Thomas Petazzoni83544912016-12-21 11:28:49 +01005676 kfree(txq_pcpu->buffs);
Antoine Ténart186cd4d2017-08-23 09:46:56 +02005677
5678 dma_free_coherent(port->dev->dev.parent,
Yan Markman822eaf72017-10-23 15:24:29 +02005679 txq_pcpu->size * TSO_HEADER_SIZE,
Antoine Ténart186cd4d2017-08-23 09:46:56 +02005680 txq_pcpu->tso_headers,
5681 txq_pcpu->tso_headers_dma);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005682 }
5683
5684 if (txq->descs)
5685 dma_free_coherent(port->dev->dev.parent,
5686 txq->size * MVPP2_DESC_ALIGNED_SIZE,
Thomas Petazzoni20396132017-03-07 16:53:00 +01005687 txq->descs, txq->descs_dma);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005688
5689 txq->descs = NULL;
5690 txq->last_desc = 0;
5691 txq->next_desc_to_proc = 0;
Thomas Petazzoni20396132017-03-07 16:53:00 +01005692 txq->descs_dma = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005693
5694 /* Set minimum bandwidth for disabled TXQs */
5695 mvpp2_write(port->priv, MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(txq->id), 0);
5696
5697 /* Set Tx descriptors queue starting address and size */
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005698 cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01005699 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_NUM_REG, txq->id);
5700 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_DESC_ADDR_REG, 0);
5701 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_DESC_SIZE_REG, 0);
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005702 put_cpu();
Marcin Wojtas3f518502014-07-10 16:52:13 -03005703}
5704
5705/* Cleanup Tx ports */
5706static void mvpp2_txq_clean(struct mvpp2_port *port, struct mvpp2_tx_queue *txq)
5707{
5708 struct mvpp2_txq_pcpu *txq_pcpu;
5709 int delay, pending, cpu;
5710 u32 val;
5711
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005712 cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01005713 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_NUM_REG, txq->id);
5714 val = mvpp2_percpu_read(port->priv, cpu, MVPP2_TXQ_PREF_BUF_REG);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005715 val |= MVPP2_TXQ_DRAIN_EN_MASK;
Thomas Petazzonia7868412017-03-07 16:53:13 +01005716 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_PREF_BUF_REG, val);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005717
5718 /* The napi queue has been stopped so wait for all packets
5719 * to be transmitted.
5720 */
5721 delay = 0;
5722 do {
5723 if (delay >= MVPP2_TX_PENDING_TIMEOUT_MSEC) {
5724 netdev_warn(port->dev,
5725 "port %d: cleaning queue %d timed out\n",
5726 port->id, txq->log_id);
5727 break;
5728 }
5729 mdelay(1);
5730 delay++;
5731
Thomas Petazzonia7868412017-03-07 16:53:13 +01005732 pending = mvpp2_percpu_read(port->priv, cpu,
5733 MVPP2_TXQ_PENDING_REG);
5734 pending &= MVPP2_TXQ_PENDING_MASK;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005735 } while (pending);
5736
5737 val &= ~MVPP2_TXQ_DRAIN_EN_MASK;
Thomas Petazzonia7868412017-03-07 16:53:13 +01005738 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_PREF_BUF_REG, val);
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005739 put_cpu();
Marcin Wojtas3f518502014-07-10 16:52:13 -03005740
5741 for_each_present_cpu(cpu) {
5742 txq_pcpu = per_cpu_ptr(txq->pcpu, cpu);
5743
5744 /* Release all packets */
5745 mvpp2_txq_bufs_free(port, txq, txq_pcpu, txq_pcpu->count);
5746
5747 /* Reset queue */
5748 txq_pcpu->count = 0;
5749 txq_pcpu->txq_put_index = 0;
5750 txq_pcpu->txq_get_index = 0;
5751 }
5752}
5753
5754/* Cleanup all Tx queues */
5755static void mvpp2_cleanup_txqs(struct mvpp2_port *port)
5756{
5757 struct mvpp2_tx_queue *txq;
5758 int queue;
5759 u32 val;
5760
5761 val = mvpp2_read(port->priv, MVPP2_TX_PORT_FLUSH_REG);
5762
5763 /* Reset Tx ports and delete Tx queues */
5764 val |= MVPP2_TX_PORT_FLUSH_MASK(port->id);
5765 mvpp2_write(port->priv, MVPP2_TX_PORT_FLUSH_REG, val);
5766
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005767 for (queue = 0; queue < port->ntxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005768 txq = port->txqs[queue];
5769 mvpp2_txq_clean(port, txq);
5770 mvpp2_txq_deinit(port, txq);
5771 }
5772
5773 on_each_cpu(mvpp2_txq_sent_counter_clear, port, 1);
5774
5775 val &= ~MVPP2_TX_PORT_FLUSH_MASK(port->id);
5776 mvpp2_write(port->priv, MVPP2_TX_PORT_FLUSH_REG, val);
5777}
5778
5779/* Cleanup all Rx queues */
5780static void mvpp2_cleanup_rxqs(struct mvpp2_port *port)
5781{
5782 int queue;
5783
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005784 for (queue = 0; queue < port->nrxqs; queue++)
Marcin Wojtas3f518502014-07-10 16:52:13 -03005785 mvpp2_rxq_deinit(port, port->rxqs[queue]);
5786}
5787
5788/* Init all Rx queues for port */
5789static int mvpp2_setup_rxqs(struct mvpp2_port *port)
5790{
5791 int queue, err;
5792
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005793 for (queue = 0; queue < port->nrxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005794 err = mvpp2_rxq_init(port, port->rxqs[queue]);
5795 if (err)
5796 goto err_cleanup;
5797 }
5798 return 0;
5799
5800err_cleanup:
5801 mvpp2_cleanup_rxqs(port);
5802 return err;
5803}
5804
5805/* Init all tx queues for port */
5806static int mvpp2_setup_txqs(struct mvpp2_port *port)
5807{
5808 struct mvpp2_tx_queue *txq;
5809 int queue, err;
5810
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005811 for (queue = 0; queue < port->ntxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005812 txq = port->txqs[queue];
5813 err = mvpp2_txq_init(port, txq);
5814 if (err)
5815 goto err_cleanup;
5816 }
5817
Thomas Petazzoni213f4282017-08-03 10:42:00 +02005818 if (port->has_tx_irqs) {
5819 mvpp2_tx_time_coal_set(port);
5820 for (queue = 0; queue < port->ntxqs; queue++) {
5821 txq = port->txqs[queue];
5822 mvpp2_tx_pkts_coal_set(port, txq);
5823 }
5824 }
5825
Marcin Wojtas3f518502014-07-10 16:52:13 -03005826 on_each_cpu(mvpp2_txq_sent_counter_clear, port, 1);
5827 return 0;
5828
5829err_cleanup:
5830 mvpp2_cleanup_txqs(port);
5831 return err;
5832}
5833
5834/* The callback for per-port interrupt */
5835static irqreturn_t mvpp2_isr(int irq, void *dev_id)
5836{
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02005837 struct mvpp2_queue_vector *qv = dev_id;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005838
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02005839 mvpp2_qvec_interrupt_disable(qv);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005840
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02005841 napi_schedule(&qv->napi);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005842
5843 return IRQ_HANDLED;
5844}
5845
Antoine Tenartfd3651b2017-09-01 11:04:54 +02005846/* Per-port interrupt for link status changes */
5847static irqreturn_t mvpp2_link_status_isr(int irq, void *dev_id)
5848{
5849 struct mvpp2_port *port = (struct mvpp2_port *)dev_id;
5850 struct net_device *dev = port->dev;
5851 bool event = false, link = false;
5852 u32 val;
5853
5854 mvpp22_gop_mask_irq(port);
5855
5856 if (port->gop_id == 0 &&
5857 port->phy_interface == PHY_INTERFACE_MODE_10GKR) {
5858 val = readl(port->base + MVPP22_XLG_INT_STAT);
5859 if (val & MVPP22_XLG_INT_STAT_LINK) {
5860 event = true;
5861 val = readl(port->base + MVPP22_XLG_STATUS);
5862 if (val & MVPP22_XLG_STATUS_LINK_UP)
5863 link = true;
5864 }
5865 } else if (phy_interface_mode_is_rgmii(port->phy_interface) ||
5866 port->phy_interface == PHY_INTERFACE_MODE_SGMII) {
5867 val = readl(port->base + MVPP22_GMAC_INT_STAT);
5868 if (val & MVPP22_GMAC_INT_STAT_LINK) {
5869 event = true;
5870 val = readl(port->base + MVPP2_GMAC_STATUS0);
5871 if (val & MVPP2_GMAC_STATUS0_LINK_UP)
5872 link = true;
5873 }
5874 }
5875
5876 if (!netif_running(dev) || !event)
5877 goto handled;
5878
5879 if (link) {
5880 mvpp2_interrupts_enable(port);
5881
5882 mvpp2_egress_enable(port);
5883 mvpp2_ingress_enable(port);
5884 netif_carrier_on(dev);
5885 netif_tx_wake_all_queues(dev);
5886 } else {
5887 netif_tx_stop_all_queues(dev);
5888 netif_carrier_off(dev);
5889 mvpp2_ingress_disable(port);
5890 mvpp2_egress_disable(port);
5891
5892 mvpp2_interrupts_disable(port);
5893 }
5894
5895handled:
5896 mvpp22_gop_unmask_irq(port);
5897 return IRQ_HANDLED;
5898}
5899
Antoine Tenart65a2c092017-08-30 10:29:18 +02005900static void mvpp2_gmac_set_autoneg(struct mvpp2_port *port,
5901 struct phy_device *phydev)
5902{
5903 u32 val;
5904
5905 if (port->phy_interface != PHY_INTERFACE_MODE_RGMII &&
5906 port->phy_interface != PHY_INTERFACE_MODE_RGMII_ID &&
5907 port->phy_interface != PHY_INTERFACE_MODE_RGMII_RXID &&
5908 port->phy_interface != PHY_INTERFACE_MODE_RGMII_TXID &&
5909 port->phy_interface != PHY_INTERFACE_MODE_SGMII)
5910 return;
5911
5912 val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG);
5913 val &= ~(MVPP2_GMAC_CONFIG_MII_SPEED |
5914 MVPP2_GMAC_CONFIG_GMII_SPEED |
5915 MVPP2_GMAC_CONFIG_FULL_DUPLEX |
5916 MVPP2_GMAC_AN_SPEED_EN |
5917 MVPP2_GMAC_AN_DUPLEX_EN);
5918
5919 if (phydev->duplex)
5920 val |= MVPP2_GMAC_CONFIG_FULL_DUPLEX;
5921
5922 if (phydev->speed == SPEED_1000)
5923 val |= MVPP2_GMAC_CONFIG_GMII_SPEED;
5924 else if (phydev->speed == SPEED_100)
5925 val |= MVPP2_GMAC_CONFIG_MII_SPEED;
5926
5927 writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG);
Antoine Tenart65a2c092017-08-30 10:29:18 +02005928}
5929
Marcin Wojtas3f518502014-07-10 16:52:13 -03005930/* Adjust link */
5931static void mvpp2_link_event(struct net_device *dev)
5932{
5933 struct mvpp2_port *port = netdev_priv(dev);
Philippe Reynes8e072692016-06-28 00:08:11 +02005934 struct phy_device *phydev = dev->phydev;
Antoine Tenart89273bc2017-08-30 10:29:19 +02005935 bool link_reconfigured = false;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005936 u32 val;
5937
5938 if (phydev->link) {
Antoine Tenart89273bc2017-08-30 10:29:19 +02005939 if (port->phy_interface != phydev->interface && port->comphy) {
5940 /* disable current port for reconfiguration */
5941 mvpp2_interrupts_disable(port);
5942 netif_carrier_off(port->dev);
5943 mvpp2_port_disable(port);
5944 phy_power_off(port->comphy);
5945
5946 /* comphy reconfiguration */
5947 port->phy_interface = phydev->interface;
5948 mvpp22_comphy_init(port);
5949
5950 /* gop/mac reconfiguration */
5951 mvpp22_gop_init(port);
5952 mvpp2_port_mii_set(port);
5953
5954 link_reconfigured = true;
5955 }
5956
Marcin Wojtas3f518502014-07-10 16:52:13 -03005957 if ((port->speed != phydev->speed) ||
5958 (port->duplex != phydev->duplex)) {
Antoine Tenart65a2c092017-08-30 10:29:18 +02005959 mvpp2_gmac_set_autoneg(port, phydev);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005960
5961 port->duplex = phydev->duplex;
5962 port->speed = phydev->speed;
5963 }
5964 }
5965
Antoine Tenart89273bc2017-08-30 10:29:19 +02005966 if (phydev->link != port->link || link_reconfigured) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005967 port->link = phydev->link;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005968
Marcin Wojtas3f518502014-07-10 16:52:13 -03005969 if (phydev->link) {
Antoine Tenart65a2c092017-08-30 10:29:18 +02005970 if (port->phy_interface == PHY_INTERFACE_MODE_RGMII ||
5971 port->phy_interface == PHY_INTERFACE_MODE_RGMII_ID ||
5972 port->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID ||
5973 port->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID ||
5974 port->phy_interface == PHY_INTERFACE_MODE_SGMII) {
5975 val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG);
5976 val |= (MVPP2_GMAC_FORCE_LINK_PASS |
5977 MVPP2_GMAC_FORCE_LINK_DOWN);
5978 writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG);
5979 }
Antoine Tenartf55744a2017-08-30 10:29:17 +02005980
5981 mvpp2_interrupts_enable(port);
5982 mvpp2_port_enable(port);
5983
Marcin Wojtas3f518502014-07-10 16:52:13 -03005984 mvpp2_egress_enable(port);
5985 mvpp2_ingress_enable(port);
Antoine Tenartf55744a2017-08-30 10:29:17 +02005986 netif_carrier_on(dev);
5987 netif_tx_wake_all_queues(dev);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005988 } else {
Antoine Tenart968b2112017-08-30 10:29:16 +02005989 port->duplex = -1;
5990 port->speed = 0;
5991
Antoine Tenartf55744a2017-08-30 10:29:17 +02005992 netif_tx_stop_all_queues(dev);
5993 netif_carrier_off(dev);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005994 mvpp2_ingress_disable(port);
5995 mvpp2_egress_disable(port);
Antoine Tenartf55744a2017-08-30 10:29:17 +02005996
5997 mvpp2_port_disable(port);
5998 mvpp2_interrupts_disable(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005999 }
Antoine Tenart968b2112017-08-30 10:29:16 +02006000
Marcin Wojtas3f518502014-07-10 16:52:13 -03006001 phy_print_status(phydev);
6002 }
6003}
6004
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006005static void mvpp2_timer_set(struct mvpp2_port_pcpu *port_pcpu)
6006{
6007 ktime_t interval;
6008
6009 if (!port_pcpu->timer_scheduled) {
6010 port_pcpu->timer_scheduled = true;
Thomas Gleixner8b0e1952016-12-25 12:30:41 +01006011 interval = MVPP2_TXDONE_HRTIMER_PERIOD_NS;
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006012 hrtimer_start(&port_pcpu->tx_done_timer, interval,
6013 HRTIMER_MODE_REL_PINNED);
6014 }
6015}
6016
6017static void mvpp2_tx_proc_cb(unsigned long data)
6018{
6019 struct net_device *dev = (struct net_device *)data;
6020 struct mvpp2_port *port = netdev_priv(dev);
6021 struct mvpp2_port_pcpu *port_pcpu = this_cpu_ptr(port->pcpu);
6022 unsigned int tx_todo, cause;
6023
6024 if (!netif_running(dev))
6025 return;
6026 port_pcpu->timer_scheduled = false;
6027
6028 /* Process all the Tx queues */
Thomas Petazzoni09f83972017-08-03 10:41:57 +02006029 cause = (1 << port->ntxqs) - 1;
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006030 tx_todo = mvpp2_tx_done(port, cause, smp_processor_id());
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006031
6032 /* Set the timer in case not all the packets were processed */
6033 if (tx_todo)
6034 mvpp2_timer_set(port_pcpu);
6035}
6036
6037static enum hrtimer_restart mvpp2_hr_timer_cb(struct hrtimer *timer)
6038{
6039 struct mvpp2_port_pcpu *port_pcpu = container_of(timer,
6040 struct mvpp2_port_pcpu,
6041 tx_done_timer);
6042
6043 tasklet_schedule(&port_pcpu->tx_done_tasklet);
6044
6045 return HRTIMER_NORESTART;
6046}
6047
Marcin Wojtas3f518502014-07-10 16:52:13 -03006048/* Main RX/TX processing routines */
6049
6050/* Display more error info */
6051static void mvpp2_rx_error(struct mvpp2_port *port,
6052 struct mvpp2_rx_desc *rx_desc)
6053{
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006054 u32 status = mvpp2_rxdesc_status_get(port, rx_desc);
6055 size_t sz = mvpp2_rxdesc_size_get(port, rx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006056
6057 switch (status & MVPP2_RXD_ERR_CODE_MASK) {
6058 case MVPP2_RXD_ERR_CRC:
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006059 netdev_err(port->dev, "bad rx status %08x (crc error), size=%zu\n",
6060 status, sz);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006061 break;
6062 case MVPP2_RXD_ERR_OVERRUN:
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006063 netdev_err(port->dev, "bad rx status %08x (overrun error), size=%zu\n",
6064 status, sz);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006065 break;
6066 case MVPP2_RXD_ERR_RESOURCE:
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006067 netdev_err(port->dev, "bad rx status %08x (resource error), size=%zu\n",
6068 status, sz);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006069 break;
6070 }
6071}
6072
6073/* Handle RX checksum offload */
6074static void mvpp2_rx_csum(struct mvpp2_port *port, u32 status,
6075 struct sk_buff *skb)
6076{
6077 if (((status & MVPP2_RXD_L3_IP4) &&
6078 !(status & MVPP2_RXD_IP4_HEADER_ERR)) ||
6079 (status & MVPP2_RXD_L3_IP6))
6080 if (((status & MVPP2_RXD_L4_UDP) ||
6081 (status & MVPP2_RXD_L4_TCP)) &&
6082 (status & MVPP2_RXD_L4_CSUM_OK)) {
6083 skb->csum = 0;
6084 skb->ip_summed = CHECKSUM_UNNECESSARY;
6085 return;
6086 }
6087
6088 skb->ip_summed = CHECKSUM_NONE;
6089}
6090
6091/* Reuse skb if possible, or allocate a new skb and add it to BM pool */
6092static int mvpp2_rx_refill(struct mvpp2_port *port,
Thomas Petazzoni56b8aae2017-06-10 23:18:21 +02006093 struct mvpp2_bm_pool *bm_pool, int pool)
Marcin Wojtas3f518502014-07-10 16:52:13 -03006094{
Thomas Petazzoni20396132017-03-07 16:53:00 +01006095 dma_addr_t dma_addr;
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01006096 phys_addr_t phys_addr;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01006097 void *buf;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006098
Marcin Wojtas3f518502014-07-10 16:52:13 -03006099 /* No recycle or too many buffers are in use, so allocate a new skb */
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01006100 buf = mvpp2_buf_alloc(port, bm_pool, &dma_addr, &phys_addr,
6101 GFP_ATOMIC);
Thomas Petazzoni0e037282017-02-21 11:28:12 +01006102 if (!buf)
Marcin Wojtas3f518502014-07-10 16:52:13 -03006103 return -ENOMEM;
6104
Thomas Petazzoni7d7627b2017-06-22 14:23:20 +02006105 mvpp2_bm_pool_put(port, pool, dma_addr, phys_addr);
Thomas Petazzoni7ef7e1d2017-02-21 11:28:07 +01006106
Marcin Wojtas3f518502014-07-10 16:52:13 -03006107 return 0;
6108}
6109
6110/* Handle tx checksum */
6111static u32 mvpp2_skb_tx_csum(struct mvpp2_port *port, struct sk_buff *skb)
6112{
6113 if (skb->ip_summed == CHECKSUM_PARTIAL) {
6114 int ip_hdr_len = 0;
6115 u8 l4_proto;
6116
6117 if (skb->protocol == htons(ETH_P_IP)) {
6118 struct iphdr *ip4h = ip_hdr(skb);
6119
6120 /* Calculate IPv4 checksum and L4 checksum */
6121 ip_hdr_len = ip4h->ihl;
6122 l4_proto = ip4h->protocol;
6123 } else if (skb->protocol == htons(ETH_P_IPV6)) {
6124 struct ipv6hdr *ip6h = ipv6_hdr(skb);
6125
6126 /* Read l4_protocol from one of IPv6 extra headers */
6127 if (skb_network_header_len(skb) > 0)
6128 ip_hdr_len = (skb_network_header_len(skb) >> 2);
6129 l4_proto = ip6h->nexthdr;
6130 } else {
6131 return MVPP2_TXD_L4_CSUM_NOT;
6132 }
6133
6134 return mvpp2_txq_desc_csum(skb_network_offset(skb),
6135 skb->protocol, ip_hdr_len, l4_proto);
6136 }
6137
6138 return MVPP2_TXD_L4_CSUM_NOT | MVPP2_TXD_IP_CSUM_DISABLE;
6139}
6140
Marcin Wojtas3f518502014-07-10 16:52:13 -03006141/* Main rx processing */
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006142static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi,
6143 int rx_todo, struct mvpp2_rx_queue *rxq)
Marcin Wojtas3f518502014-07-10 16:52:13 -03006144{
6145 struct net_device *dev = port->dev;
Marcin Wojtasb5015852015-12-03 15:20:51 +01006146 int rx_received;
6147 int rx_done = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006148 u32 rcvd_pkts = 0;
6149 u32 rcvd_bytes = 0;
6150
6151 /* Get number of received packets and clamp the to-do */
6152 rx_received = mvpp2_rxq_received(port, rxq->id);
6153 if (rx_todo > rx_received)
6154 rx_todo = rx_received;
6155
Marcin Wojtasb5015852015-12-03 15:20:51 +01006156 while (rx_done < rx_todo) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03006157 struct mvpp2_rx_desc *rx_desc = mvpp2_rxq_next_desc_get(rxq);
6158 struct mvpp2_bm_pool *bm_pool;
6159 struct sk_buff *skb;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01006160 unsigned int frag_size;
Thomas Petazzoni20396132017-03-07 16:53:00 +01006161 dma_addr_t dma_addr;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006162 phys_addr_t phys_addr;
Thomas Petazzoni56b8aae2017-06-10 23:18:21 +02006163 u32 rx_status;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006164 int pool, rx_bytes, err;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01006165 void *data;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006166
Marcin Wojtasb5015852015-12-03 15:20:51 +01006167 rx_done++;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006168 rx_status = mvpp2_rxdesc_status_get(port, rx_desc);
6169 rx_bytes = mvpp2_rxdesc_size_get(port, rx_desc);
6170 rx_bytes -= MVPP2_MH_SIZE;
6171 dma_addr = mvpp2_rxdesc_dma_addr_get(port, rx_desc);
6172 phys_addr = mvpp2_rxdesc_cookie_get(port, rx_desc);
6173 data = (void *)phys_to_virt(phys_addr);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006174
Thomas Petazzoni56b8aae2017-06-10 23:18:21 +02006175 pool = (rx_status & MVPP2_RXD_BM_POOL_ID_MASK) >>
6176 MVPP2_RXD_BM_POOL_ID_OFFS;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006177 bm_pool = &port->priv->bm_pools[pool];
Marcin Wojtas3f518502014-07-10 16:52:13 -03006178
6179 /* In case of an error, release the requested buffer pointer
6180 * to the Buffer Manager. This request process is controlled
6181 * by the hardware, and the information about the buffer is
6182 * comprised by the RX descriptor.
6183 */
6184 if (rx_status & MVPP2_RXD_ERR_SUMMARY) {
Markus Elfring8a524882017-04-17 10:52:02 +02006185err_drop_frame:
Marcin Wojtas3f518502014-07-10 16:52:13 -03006186 dev->stats.rx_errors++;
6187 mvpp2_rx_error(port, rx_desc);
Marcin Wojtasb5015852015-12-03 15:20:51 +01006188 /* Return the buffer to the pool */
Thomas Petazzoni7d7627b2017-06-22 14:23:20 +02006189 mvpp2_bm_pool_put(port, pool, dma_addr, phys_addr);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006190 continue;
6191 }
6192
Thomas Petazzoni0e037282017-02-21 11:28:12 +01006193 if (bm_pool->frag_size > PAGE_SIZE)
6194 frag_size = 0;
6195 else
6196 frag_size = bm_pool->frag_size;
6197
6198 skb = build_skb(data, frag_size);
6199 if (!skb) {
6200 netdev_warn(port->dev, "skb build failed\n");
6201 goto err_drop_frame;
6202 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03006203
Thomas Petazzoni56b8aae2017-06-10 23:18:21 +02006204 err = mvpp2_rx_refill(port, bm_pool, pool);
Marcin Wojtasb5015852015-12-03 15:20:51 +01006205 if (err) {
6206 netdev_err(port->dev, "failed to refill BM pools\n");
6207 goto err_drop_frame;
6208 }
6209
Thomas Petazzoni20396132017-03-07 16:53:00 +01006210 dma_unmap_single(dev->dev.parent, dma_addr,
Marcin Wojtas4229d502015-12-03 15:20:50 +01006211 bm_pool->buf_size, DMA_FROM_DEVICE);
6212
Marcin Wojtas3f518502014-07-10 16:52:13 -03006213 rcvd_pkts++;
6214 rcvd_bytes += rx_bytes;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006215
Thomas Petazzoni0e037282017-02-21 11:28:12 +01006216 skb_reserve(skb, MVPP2_MH_SIZE + NET_SKB_PAD);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006217 skb_put(skb, rx_bytes);
6218 skb->protocol = eth_type_trans(skb, dev);
6219 mvpp2_rx_csum(port, rx_status, skb);
6220
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006221 napi_gro_receive(napi, skb);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006222 }
6223
6224 if (rcvd_pkts) {
6225 struct mvpp2_pcpu_stats *stats = this_cpu_ptr(port->stats);
6226
6227 u64_stats_update_begin(&stats->syncp);
6228 stats->rx_packets += rcvd_pkts;
6229 stats->rx_bytes += rcvd_bytes;
6230 u64_stats_update_end(&stats->syncp);
6231 }
6232
6233 /* Update Rx queue management counters */
6234 wmb();
Marcin Wojtasb5015852015-12-03 15:20:51 +01006235 mvpp2_rxq_status_update(port, rxq->id, rx_done, rx_done);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006236
6237 return rx_todo;
6238}
6239
6240static inline void
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006241tx_desc_unmap_put(struct mvpp2_port *port, struct mvpp2_tx_queue *txq,
Marcin Wojtas3f518502014-07-10 16:52:13 -03006242 struct mvpp2_tx_desc *desc)
6243{
Antoine Tenart20920262017-10-23 15:24:30 +02006244 struct mvpp2_txq_pcpu *txq_pcpu = this_cpu_ptr(txq->pcpu);
6245
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006246 dma_addr_t buf_dma_addr =
6247 mvpp2_txdesc_dma_addr_get(port, desc);
6248 size_t buf_sz =
6249 mvpp2_txdesc_size_get(port, desc);
Antoine Tenart20920262017-10-23 15:24:30 +02006250 if (!IS_TSO_HEADER(txq_pcpu, buf_dma_addr))
6251 dma_unmap_single(port->dev->dev.parent, buf_dma_addr,
6252 buf_sz, DMA_TO_DEVICE);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006253 mvpp2_txq_desc_put(txq);
6254}
6255
6256/* Handle tx fragmentation processing */
6257static int mvpp2_tx_frag_process(struct mvpp2_port *port, struct sk_buff *skb,
6258 struct mvpp2_tx_queue *aggr_txq,
6259 struct mvpp2_tx_queue *txq)
6260{
6261 struct mvpp2_txq_pcpu *txq_pcpu = this_cpu_ptr(txq->pcpu);
6262 struct mvpp2_tx_desc *tx_desc;
6263 int i;
Thomas Petazzoni20396132017-03-07 16:53:00 +01006264 dma_addr_t buf_dma_addr;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006265
6266 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
6267 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
6268 void *addr = page_address(frag->page.p) + frag->page_offset;
6269
6270 tx_desc = mvpp2_txq_next_desc_get(aggr_txq);
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006271 mvpp2_txdesc_txq_set(port, tx_desc, txq->id);
6272 mvpp2_txdesc_size_set(port, tx_desc, frag->size);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006273
Thomas Petazzoni20396132017-03-07 16:53:00 +01006274 buf_dma_addr = dma_map_single(port->dev->dev.parent, addr,
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006275 frag->size,
6276 DMA_TO_DEVICE);
Thomas Petazzoni20396132017-03-07 16:53:00 +01006277 if (dma_mapping_error(port->dev->dev.parent, buf_dma_addr)) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03006278 mvpp2_txq_desc_put(txq);
Markus Elfring32bae632017-04-17 11:36:34 +02006279 goto cleanup;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006280 }
6281
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006282 mvpp2_txdesc_offset_set(port, tx_desc,
6283 buf_dma_addr & MVPP2_TX_DESC_ALIGN);
6284 mvpp2_txdesc_dma_addr_set(port, tx_desc,
6285 buf_dma_addr & ~MVPP2_TX_DESC_ALIGN);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006286
6287 if (i == (skb_shinfo(skb)->nr_frags - 1)) {
6288 /* Last descriptor */
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006289 mvpp2_txdesc_cmd_set(port, tx_desc,
6290 MVPP2_TXD_L_DESC);
6291 mvpp2_txq_inc_put(port, txq_pcpu, skb, tx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006292 } else {
6293 /* Descriptor in the middle: Not First, Not Last */
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006294 mvpp2_txdesc_cmd_set(port, tx_desc, 0);
6295 mvpp2_txq_inc_put(port, txq_pcpu, NULL, tx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006296 }
6297 }
6298
6299 return 0;
Markus Elfring32bae632017-04-17 11:36:34 +02006300cleanup:
Marcin Wojtas3f518502014-07-10 16:52:13 -03006301 /* Release all descriptors that were used to map fragments of
6302 * this packet, as well as the corresponding DMA mappings
6303 */
6304 for (i = i - 1; i >= 0; i--) {
6305 tx_desc = txq->descs + i;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006306 tx_desc_unmap_put(port, txq, tx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006307 }
6308
6309 return -ENOMEM;
6310}
6311
Antoine Ténart186cd4d2017-08-23 09:46:56 +02006312static inline void mvpp2_tso_put_hdr(struct sk_buff *skb,
6313 struct net_device *dev,
6314 struct mvpp2_tx_queue *txq,
6315 struct mvpp2_tx_queue *aggr_txq,
6316 struct mvpp2_txq_pcpu *txq_pcpu,
6317 int hdr_sz)
6318{
6319 struct mvpp2_port *port = netdev_priv(dev);
6320 struct mvpp2_tx_desc *tx_desc = mvpp2_txq_next_desc_get(aggr_txq);
6321 dma_addr_t addr;
6322
6323 mvpp2_txdesc_txq_set(port, tx_desc, txq->id);
6324 mvpp2_txdesc_size_set(port, tx_desc, hdr_sz);
6325
6326 addr = txq_pcpu->tso_headers_dma +
6327 txq_pcpu->txq_put_index * TSO_HEADER_SIZE;
6328 mvpp2_txdesc_offset_set(port, tx_desc, addr & MVPP2_TX_DESC_ALIGN);
6329 mvpp2_txdesc_dma_addr_set(port, tx_desc, addr & ~MVPP2_TX_DESC_ALIGN);
6330
6331 mvpp2_txdesc_cmd_set(port, tx_desc, mvpp2_skb_tx_csum(port, skb) |
6332 MVPP2_TXD_F_DESC |
6333 MVPP2_TXD_PADDING_DISABLE);
6334 mvpp2_txq_inc_put(port, txq_pcpu, NULL, tx_desc);
6335}
6336
6337static inline int mvpp2_tso_put_data(struct sk_buff *skb,
6338 struct net_device *dev, struct tso_t *tso,
6339 struct mvpp2_tx_queue *txq,
6340 struct mvpp2_tx_queue *aggr_txq,
6341 struct mvpp2_txq_pcpu *txq_pcpu,
6342 int sz, bool left, bool last)
6343{
6344 struct mvpp2_port *port = netdev_priv(dev);
6345 struct mvpp2_tx_desc *tx_desc = mvpp2_txq_next_desc_get(aggr_txq);
6346 dma_addr_t buf_dma_addr;
6347
6348 mvpp2_txdesc_txq_set(port, tx_desc, txq->id);
6349 mvpp2_txdesc_size_set(port, tx_desc, sz);
6350
6351 buf_dma_addr = dma_map_single(dev->dev.parent, tso->data, sz,
6352 DMA_TO_DEVICE);
6353 if (unlikely(dma_mapping_error(dev->dev.parent, buf_dma_addr))) {
6354 mvpp2_txq_desc_put(txq);
6355 return -ENOMEM;
6356 }
6357
6358 mvpp2_txdesc_offset_set(port, tx_desc,
6359 buf_dma_addr & MVPP2_TX_DESC_ALIGN);
6360 mvpp2_txdesc_dma_addr_set(port, tx_desc,
6361 buf_dma_addr & ~MVPP2_TX_DESC_ALIGN);
6362
6363 if (!left) {
6364 mvpp2_txdesc_cmd_set(port, tx_desc, MVPP2_TXD_L_DESC);
6365 if (last) {
6366 mvpp2_txq_inc_put(port, txq_pcpu, skb, tx_desc);
6367 return 0;
6368 }
6369 } else {
6370 mvpp2_txdesc_cmd_set(port, tx_desc, 0);
6371 }
6372
6373 mvpp2_txq_inc_put(port, txq_pcpu, NULL, tx_desc);
6374 return 0;
6375}
6376
6377static int mvpp2_tx_tso(struct sk_buff *skb, struct net_device *dev,
6378 struct mvpp2_tx_queue *txq,
6379 struct mvpp2_tx_queue *aggr_txq,
6380 struct mvpp2_txq_pcpu *txq_pcpu)
6381{
6382 struct mvpp2_port *port = netdev_priv(dev);
6383 struct tso_t tso;
6384 int hdr_sz = skb_transport_offset(skb) + tcp_hdrlen(skb);
6385 int i, len, descs = 0;
6386
6387 /* Check number of available descriptors */
6388 if (mvpp2_aggr_desc_num_check(port->priv, aggr_txq,
6389 tso_count_descs(skb)) ||
6390 mvpp2_txq_reserved_desc_num_proc(port->priv, txq, txq_pcpu,
6391 tso_count_descs(skb)))
6392 return 0;
6393
6394 tso_start(skb, &tso);
6395 len = skb->len - hdr_sz;
6396 while (len > 0) {
6397 int left = min_t(int, skb_shinfo(skb)->gso_size, len);
6398 char *hdr = txq_pcpu->tso_headers +
6399 txq_pcpu->txq_put_index * TSO_HEADER_SIZE;
6400
6401 len -= left;
6402 descs++;
6403
6404 tso_build_hdr(skb, hdr, &tso, left, len == 0);
6405 mvpp2_tso_put_hdr(skb, dev, txq, aggr_txq, txq_pcpu, hdr_sz);
6406
6407 while (left > 0) {
6408 int sz = min_t(int, tso.size, left);
6409 left -= sz;
6410 descs++;
6411
6412 if (mvpp2_tso_put_data(skb, dev, &tso, txq, aggr_txq,
6413 txq_pcpu, sz, left, len == 0))
6414 goto release;
6415 tso_build_data(skb, &tso, sz);
6416 }
6417 }
6418
6419 return descs;
6420
6421release:
6422 for (i = descs - 1; i >= 0; i--) {
6423 struct mvpp2_tx_desc *tx_desc = txq->descs + i;
6424 tx_desc_unmap_put(port, txq, tx_desc);
6425 }
6426 return 0;
6427}
6428
Marcin Wojtas3f518502014-07-10 16:52:13 -03006429/* Main tx processing */
6430static int mvpp2_tx(struct sk_buff *skb, struct net_device *dev)
6431{
6432 struct mvpp2_port *port = netdev_priv(dev);
6433 struct mvpp2_tx_queue *txq, *aggr_txq;
6434 struct mvpp2_txq_pcpu *txq_pcpu;
6435 struct mvpp2_tx_desc *tx_desc;
Thomas Petazzoni20396132017-03-07 16:53:00 +01006436 dma_addr_t buf_dma_addr;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006437 int frags = 0;
6438 u16 txq_id;
6439 u32 tx_cmd;
6440
6441 txq_id = skb_get_queue_mapping(skb);
6442 txq = port->txqs[txq_id];
6443 txq_pcpu = this_cpu_ptr(txq->pcpu);
6444 aggr_txq = &port->priv->aggr_txqs[smp_processor_id()];
6445
Antoine Ténart186cd4d2017-08-23 09:46:56 +02006446 if (skb_is_gso(skb)) {
6447 frags = mvpp2_tx_tso(skb, dev, txq, aggr_txq, txq_pcpu);
6448 goto out;
6449 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03006450 frags = skb_shinfo(skb)->nr_frags + 1;
6451
6452 /* Check number of available descriptors */
6453 if (mvpp2_aggr_desc_num_check(port->priv, aggr_txq, frags) ||
6454 mvpp2_txq_reserved_desc_num_proc(port->priv, txq,
6455 txq_pcpu, frags)) {
6456 frags = 0;
6457 goto out;
6458 }
6459
6460 /* Get a descriptor for the first part of the packet */
6461 tx_desc = mvpp2_txq_next_desc_get(aggr_txq);
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006462 mvpp2_txdesc_txq_set(port, tx_desc, txq->id);
6463 mvpp2_txdesc_size_set(port, tx_desc, skb_headlen(skb));
Marcin Wojtas3f518502014-07-10 16:52:13 -03006464
Thomas Petazzoni20396132017-03-07 16:53:00 +01006465 buf_dma_addr = dma_map_single(dev->dev.parent, skb->data,
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006466 skb_headlen(skb), DMA_TO_DEVICE);
Thomas Petazzoni20396132017-03-07 16:53:00 +01006467 if (unlikely(dma_mapping_error(dev->dev.parent, buf_dma_addr))) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03006468 mvpp2_txq_desc_put(txq);
6469 frags = 0;
6470 goto out;
6471 }
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006472
6473 mvpp2_txdesc_offset_set(port, tx_desc,
6474 buf_dma_addr & MVPP2_TX_DESC_ALIGN);
6475 mvpp2_txdesc_dma_addr_set(port, tx_desc,
6476 buf_dma_addr & ~MVPP2_TX_DESC_ALIGN);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006477
6478 tx_cmd = mvpp2_skb_tx_csum(port, skb);
6479
6480 if (frags == 1) {
6481 /* First and Last descriptor */
6482 tx_cmd |= MVPP2_TXD_F_DESC | MVPP2_TXD_L_DESC;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006483 mvpp2_txdesc_cmd_set(port, tx_desc, tx_cmd);
6484 mvpp2_txq_inc_put(port, txq_pcpu, skb, tx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006485 } else {
6486 /* First but not Last */
6487 tx_cmd |= MVPP2_TXD_F_DESC | MVPP2_TXD_PADDING_DISABLE;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006488 mvpp2_txdesc_cmd_set(port, tx_desc, tx_cmd);
6489 mvpp2_txq_inc_put(port, txq_pcpu, NULL, tx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006490
6491 /* Continue with other skb fragments */
6492 if (mvpp2_tx_frag_process(port, skb, aggr_txq, txq)) {
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006493 tx_desc_unmap_put(port, txq, tx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006494 frags = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006495 }
6496 }
6497
Marcin Wojtas3f518502014-07-10 16:52:13 -03006498out:
6499 if (frags > 0) {
6500 struct mvpp2_pcpu_stats *stats = this_cpu_ptr(port->stats);
Antoine Ténart186cd4d2017-08-23 09:46:56 +02006501 struct netdev_queue *nq = netdev_get_tx_queue(dev, txq_id);
6502
6503 txq_pcpu->reserved_num -= frags;
6504 txq_pcpu->count += frags;
6505 aggr_txq->count += frags;
6506
6507 /* Enable transmit */
6508 wmb();
6509 mvpp2_aggr_txq_pend_desc_add(port, frags);
6510
6511 if (txq_pcpu->size - txq_pcpu->count < MAX_SKB_FRAGS + 1)
6512 netif_tx_stop_queue(nq);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006513
6514 u64_stats_update_begin(&stats->syncp);
6515 stats->tx_packets++;
6516 stats->tx_bytes += skb->len;
6517 u64_stats_update_end(&stats->syncp);
6518 } else {
6519 dev->stats.tx_dropped++;
6520 dev_kfree_skb_any(skb);
6521 }
6522
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006523 /* Finalize TX processing */
Antoine Tenart082297e2017-10-23 15:24:31 +02006524 if (!port->has_tx_irqs && txq_pcpu->count >= txq->done_pkts_coal)
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006525 mvpp2_txq_done(port, txq, txq_pcpu);
6526
6527 /* Set the timer in case not all frags were processed */
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006528 if (!port->has_tx_irqs && txq_pcpu->count <= frags &&
6529 txq_pcpu->count > 0) {
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006530 struct mvpp2_port_pcpu *port_pcpu = this_cpu_ptr(port->pcpu);
6531
6532 mvpp2_timer_set(port_pcpu);
6533 }
6534
Marcin Wojtas3f518502014-07-10 16:52:13 -03006535 return NETDEV_TX_OK;
6536}
6537
6538static inline void mvpp2_cause_error(struct net_device *dev, int cause)
6539{
6540 if (cause & MVPP2_CAUSE_FCS_ERR_MASK)
6541 netdev_err(dev, "FCS error\n");
6542 if (cause & MVPP2_CAUSE_RX_FIFO_OVERRUN_MASK)
6543 netdev_err(dev, "rx fifo overrun error\n");
6544 if (cause & MVPP2_CAUSE_TX_FIFO_UNDERRUN_MASK)
6545 netdev_err(dev, "tx fifo underrun error\n");
6546}
6547
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006548static int mvpp2_poll(struct napi_struct *napi, int budget)
Marcin Wojtas3f518502014-07-10 16:52:13 -03006549{
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006550 u32 cause_rx_tx, cause_rx, cause_tx, cause_misc;
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006551 int rx_done = 0;
6552 struct mvpp2_port *port = netdev_priv(napi->dev);
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006553 struct mvpp2_queue_vector *qv;
Thomas Petazzonia7868412017-03-07 16:53:13 +01006554 int cpu = smp_processor_id();
Marcin Wojtas3f518502014-07-10 16:52:13 -03006555
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006556 qv = container_of(napi, struct mvpp2_queue_vector, napi);
6557
Marcin Wojtas3f518502014-07-10 16:52:13 -03006558 /* Rx/Tx cause register
6559 *
6560 * Bits 0-15: each bit indicates received packets on the Rx queue
6561 * (bit 0 is for Rx queue 0).
6562 *
6563 * Bits 16-23: each bit indicates transmitted packets on the Tx queue
6564 * (bit 16 is for Tx queue 0).
6565 *
6566 * Each CPU has its own Rx/Tx cause register
6567 */
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006568 cause_rx_tx = mvpp2_percpu_read(port->priv, qv->sw_thread_id,
Thomas Petazzonia7868412017-03-07 16:53:13 +01006569 MVPP2_ISR_RX_TX_CAUSE_REG(port->id));
Marcin Wojtas3f518502014-07-10 16:52:13 -03006570
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006571 cause_misc = cause_rx_tx & MVPP2_CAUSE_MISC_SUM_MASK;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006572 if (cause_misc) {
6573 mvpp2_cause_error(port->dev, cause_misc);
6574
6575 /* Clear the cause register */
6576 mvpp2_write(port->priv, MVPP2_ISR_MISC_CAUSE_REG, 0);
Thomas Petazzonia7868412017-03-07 16:53:13 +01006577 mvpp2_percpu_write(port->priv, cpu,
6578 MVPP2_ISR_RX_TX_CAUSE_REG(port->id),
6579 cause_rx_tx & ~MVPP2_CAUSE_MISC_SUM_MASK);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006580 }
6581
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006582 cause_tx = cause_rx_tx & MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK;
6583 if (cause_tx) {
6584 cause_tx >>= MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_OFFSET;
6585 mvpp2_tx_done(port, cause_tx, qv->sw_thread_id);
6586 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03006587
6588 /* Process RX packets */
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006589 cause_rx = cause_rx_tx & MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK;
6590 cause_rx <<= qv->first_rxq;
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006591 cause_rx |= qv->pending_cause_rx;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006592 while (cause_rx && budget > 0) {
6593 int count;
6594 struct mvpp2_rx_queue *rxq;
6595
6596 rxq = mvpp2_get_rx_queue(port, cause_rx);
6597 if (!rxq)
6598 break;
6599
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006600 count = mvpp2_rx(port, napi, budget, rxq);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006601 rx_done += count;
6602 budget -= count;
6603 if (budget > 0) {
6604 /* Clear the bit associated to this Rx queue
6605 * so that next iteration will continue from
6606 * the next Rx queue.
6607 */
6608 cause_rx &= ~(1 << rxq->logic_rxq);
6609 }
6610 }
6611
6612 if (budget > 0) {
6613 cause_rx = 0;
Eric Dumazet6ad20162017-01-30 08:22:01 -08006614 napi_complete_done(napi, rx_done);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006615
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006616 mvpp2_qvec_interrupt_enable(qv);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006617 }
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006618 qv->pending_cause_rx = cause_rx;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006619 return rx_done;
6620}
6621
6622/* Set hw internals when starting port */
6623static void mvpp2_start_dev(struct mvpp2_port *port)
6624{
Philippe Reynes8e072692016-06-28 00:08:11 +02006625 struct net_device *ndev = port->dev;
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006626 int i;
Philippe Reynes8e072692016-06-28 00:08:11 +02006627
Stefan Chulski76eb1b12017-08-22 19:08:26 +02006628 if (port->gop_id == 0 &&
6629 (port->phy_interface == PHY_INTERFACE_MODE_XAUI ||
6630 port->phy_interface == PHY_INTERFACE_MODE_10GKR))
6631 mvpp2_xlg_max_rx_size_set(port);
6632 else
6633 mvpp2_gmac_max_rx_size_set(port);
6634
Marcin Wojtas3f518502014-07-10 16:52:13 -03006635 mvpp2_txp_max_tx_size_set(port);
6636
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006637 for (i = 0; i < port->nqvecs; i++)
6638 napi_enable(&port->qvecs[i].napi);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006639
6640 /* Enable interrupts on all CPUs */
6641 mvpp2_interrupts_enable(port);
6642
Antoine Tenart542897d2017-08-30 10:29:15 +02006643 if (port->priv->hw_version == MVPP22) {
6644 mvpp22_comphy_init(port);
Antoine Ténartf84bf382017-08-22 19:08:27 +02006645 mvpp22_gop_init(port);
Antoine Tenart542897d2017-08-30 10:29:15 +02006646 }
Antoine Ténartf84bf382017-08-22 19:08:27 +02006647
Antoine Ténart2055d622017-08-22 19:08:23 +02006648 mvpp2_port_mii_set(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006649 mvpp2_port_enable(port);
Antoine Tenart5997c862017-09-01 11:04:53 +02006650 if (ndev->phydev)
6651 phy_start(ndev->phydev);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006652 netif_tx_start_all_queues(port->dev);
6653}
6654
6655/* Set hw internals when stopping port */
6656static void mvpp2_stop_dev(struct mvpp2_port *port)
6657{
Philippe Reynes8e072692016-06-28 00:08:11 +02006658 struct net_device *ndev = port->dev;
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006659 int i;
Philippe Reynes8e072692016-06-28 00:08:11 +02006660
Marcin Wojtas3f518502014-07-10 16:52:13 -03006661 /* Stop new packets from arriving to RXQs */
6662 mvpp2_ingress_disable(port);
6663
6664 mdelay(10);
6665
6666 /* Disable interrupts on all CPUs */
6667 mvpp2_interrupts_disable(port);
6668
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006669 for (i = 0; i < port->nqvecs; i++)
6670 napi_disable(&port->qvecs[i].napi);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006671
6672 netif_carrier_off(port->dev);
6673 netif_tx_stop_all_queues(port->dev);
6674
6675 mvpp2_egress_disable(port);
6676 mvpp2_port_disable(port);
Antoine Tenart5997c862017-09-01 11:04:53 +02006677 if (ndev->phydev)
6678 phy_stop(ndev->phydev);
Antoine Tenart542897d2017-08-30 10:29:15 +02006679 phy_power_off(port->comphy);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006680}
6681
Marcin Wojtas3f518502014-07-10 16:52:13 -03006682static int mvpp2_check_ringparam_valid(struct net_device *dev,
6683 struct ethtool_ringparam *ring)
6684{
6685 u16 new_rx_pending = ring->rx_pending;
6686 u16 new_tx_pending = ring->tx_pending;
6687
6688 if (ring->rx_pending == 0 || ring->tx_pending == 0)
6689 return -EINVAL;
6690
6691 if (ring->rx_pending > MVPP2_MAX_RXD)
6692 new_rx_pending = MVPP2_MAX_RXD;
6693 else if (!IS_ALIGNED(ring->rx_pending, 16))
6694 new_rx_pending = ALIGN(ring->rx_pending, 16);
6695
6696 if (ring->tx_pending > MVPP2_MAX_TXD)
6697 new_tx_pending = MVPP2_MAX_TXD;
6698 else if (!IS_ALIGNED(ring->tx_pending, 32))
6699 new_tx_pending = ALIGN(ring->tx_pending, 32);
6700
6701 if (ring->rx_pending != new_rx_pending) {
6702 netdev_info(dev, "illegal Rx ring size value %d, round to %d\n",
6703 ring->rx_pending, new_rx_pending);
6704 ring->rx_pending = new_rx_pending;
6705 }
6706
6707 if (ring->tx_pending != new_tx_pending) {
6708 netdev_info(dev, "illegal Tx ring size value %d, round to %d\n",
6709 ring->tx_pending, new_tx_pending);
6710 ring->tx_pending = new_tx_pending;
6711 }
6712
6713 return 0;
6714}
6715
Thomas Petazzoni26975822017-03-07 16:53:14 +01006716static void mvpp21_get_mac_address(struct mvpp2_port *port, unsigned char *addr)
Marcin Wojtas3f518502014-07-10 16:52:13 -03006717{
6718 u32 mac_addr_l, mac_addr_m, mac_addr_h;
6719
6720 mac_addr_l = readl(port->base + MVPP2_GMAC_CTRL_1_REG);
6721 mac_addr_m = readl(port->priv->lms_base + MVPP2_SRC_ADDR_MIDDLE);
6722 mac_addr_h = readl(port->priv->lms_base + MVPP2_SRC_ADDR_HIGH);
6723 addr[0] = (mac_addr_h >> 24) & 0xFF;
6724 addr[1] = (mac_addr_h >> 16) & 0xFF;
6725 addr[2] = (mac_addr_h >> 8) & 0xFF;
6726 addr[3] = mac_addr_h & 0xFF;
6727 addr[4] = mac_addr_m & 0xFF;
6728 addr[5] = (mac_addr_l >> MVPP2_GMAC_SA_LOW_OFFS) & 0xFF;
6729}
6730
6731static int mvpp2_phy_connect(struct mvpp2_port *port)
6732{
6733 struct phy_device *phy_dev;
6734
Antoine Tenart5997c862017-09-01 11:04:53 +02006735 /* No PHY is attached */
6736 if (!port->phy_node)
6737 return 0;
6738
Marcin Wojtas3f518502014-07-10 16:52:13 -03006739 phy_dev = of_phy_connect(port->dev, port->phy_node, mvpp2_link_event, 0,
6740 port->phy_interface);
6741 if (!phy_dev) {
6742 netdev_err(port->dev, "cannot connect to phy\n");
6743 return -ENODEV;
6744 }
6745 phy_dev->supported &= PHY_GBIT_FEATURES;
6746 phy_dev->advertising = phy_dev->supported;
6747
Marcin Wojtas3f518502014-07-10 16:52:13 -03006748 port->link = 0;
6749 port->duplex = 0;
6750 port->speed = 0;
6751
6752 return 0;
6753}
6754
6755static void mvpp2_phy_disconnect(struct mvpp2_port *port)
6756{
Philippe Reynes8e072692016-06-28 00:08:11 +02006757 struct net_device *ndev = port->dev;
6758
Antoine Tenart5997c862017-09-01 11:04:53 +02006759 if (!ndev->phydev)
6760 return;
6761
Philippe Reynes8e072692016-06-28 00:08:11 +02006762 phy_disconnect(ndev->phydev);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006763}
6764
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006765static int mvpp2_irqs_init(struct mvpp2_port *port)
6766{
6767 int err, i;
6768
6769 for (i = 0; i < port->nqvecs; i++) {
6770 struct mvpp2_queue_vector *qv = port->qvecs + i;
6771
6772 err = request_irq(qv->irq, mvpp2_isr, 0, port->dev->name, qv);
6773 if (err)
6774 goto err;
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006775
6776 if (qv->type == MVPP2_QUEUE_VECTOR_PRIVATE)
6777 irq_set_affinity_hint(qv->irq,
6778 cpumask_of(qv->sw_thread_id));
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006779 }
6780
6781 return 0;
6782err:
6783 for (i = 0; i < port->nqvecs; i++) {
6784 struct mvpp2_queue_vector *qv = port->qvecs + i;
6785
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006786 irq_set_affinity_hint(qv->irq, NULL);
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006787 free_irq(qv->irq, qv);
6788 }
6789
6790 return err;
6791}
6792
6793static void mvpp2_irqs_deinit(struct mvpp2_port *port)
6794{
6795 int i;
6796
6797 for (i = 0; i < port->nqvecs; i++) {
6798 struct mvpp2_queue_vector *qv = port->qvecs + i;
6799
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006800 irq_set_affinity_hint(qv->irq, NULL);
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006801 free_irq(qv->irq, qv);
6802 }
6803}
6804
Antoine Tenart1d7d15d2017-10-30 11:23:30 +01006805static void mvpp22_init_rss(struct mvpp2_port *port)
6806{
6807 struct mvpp2 *priv = port->priv;
6808 int i;
6809
6810 /* Set the table width: replace the whole classifier Rx queue number
6811 * with the ones configured in RSS table entries.
6812 */
6813 mvpp2_write(priv, MVPP22_RSS_INDEX, MVPP22_RSS_INDEX_TABLE(0));
6814 mvpp2_write(priv, MVPP22_RSS_WIDTH, 8);
6815
6816 /* Loop through the classifier Rx Queues and map them to a RSS table.
6817 * Map them all to the first table (0) by default.
6818 */
6819 for (i = 0; i < MVPP2_CLS_RX_QUEUES; i++) {
6820 mvpp2_write(priv, MVPP22_RSS_INDEX, MVPP22_RSS_INDEX_QUEUE(i));
6821 mvpp2_write(priv, MVPP22_RSS_TABLE,
6822 MVPP22_RSS_TABLE_POINTER(0));
6823 }
6824
6825 /* Configure the first table to evenly distribute the packets across
6826 * real Rx Queues. The table entries map a hash to an port Rx Queue.
6827 */
6828 for (i = 0; i < MVPP22_RSS_TABLE_ENTRIES; i++) {
6829 u32 sel = MVPP22_RSS_INDEX_TABLE(0) |
6830 MVPP22_RSS_INDEX_TABLE_ENTRY(i);
6831 mvpp2_write(priv, MVPP22_RSS_INDEX, sel);
6832
6833 mvpp2_write(priv, MVPP22_RSS_TABLE_ENTRY, i % port->nrxqs);
6834 }
6835
6836}
6837
Marcin Wojtas3f518502014-07-10 16:52:13 -03006838static int mvpp2_open(struct net_device *dev)
6839{
6840 struct mvpp2_port *port = netdev_priv(dev);
Antoine Tenartfd3651b2017-09-01 11:04:54 +02006841 struct mvpp2 *priv = port->priv;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006842 unsigned char mac_bcast[ETH_ALEN] = {
6843 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
6844 int err;
6845
6846 err = mvpp2_prs_mac_da_accept(port->priv, port->id, mac_bcast, true);
6847 if (err) {
6848 netdev_err(dev, "mvpp2_prs_mac_da_accept BC failed\n");
6849 return err;
6850 }
6851 err = mvpp2_prs_mac_da_accept(port->priv, port->id,
6852 dev->dev_addr, true);
6853 if (err) {
6854 netdev_err(dev, "mvpp2_prs_mac_da_accept MC failed\n");
6855 return err;
6856 }
6857 err = mvpp2_prs_tag_mode_set(port->priv, port->id, MVPP2_TAG_TYPE_MH);
6858 if (err) {
6859 netdev_err(dev, "mvpp2_prs_tag_mode_set failed\n");
6860 return err;
6861 }
6862 err = mvpp2_prs_def_flow(port);
6863 if (err) {
6864 netdev_err(dev, "mvpp2_prs_def_flow failed\n");
6865 return err;
6866 }
6867
6868 /* Allocate the Rx/Tx queues */
6869 err = mvpp2_setup_rxqs(port);
6870 if (err) {
6871 netdev_err(port->dev, "cannot allocate Rx queues\n");
6872 return err;
6873 }
6874
6875 err = mvpp2_setup_txqs(port);
6876 if (err) {
6877 netdev_err(port->dev, "cannot allocate Tx queues\n");
6878 goto err_cleanup_rxqs;
6879 }
6880
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006881 err = mvpp2_irqs_init(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006882 if (err) {
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006883 netdev_err(port->dev, "cannot init IRQs\n");
Marcin Wojtas3f518502014-07-10 16:52:13 -03006884 goto err_cleanup_txqs;
6885 }
6886
Antoine Tenartfd3651b2017-09-01 11:04:54 +02006887 if (priv->hw_version == MVPP22 && !port->phy_node && port->link_irq) {
6888 err = request_irq(port->link_irq, mvpp2_link_status_isr, 0,
6889 dev->name, port);
6890 if (err) {
6891 netdev_err(port->dev, "cannot request link IRQ %d\n",
6892 port->link_irq);
6893 goto err_free_irq;
6894 }
6895
6896 mvpp22_gop_setup_irq(port);
6897 }
6898
Marcin Wojtas3f518502014-07-10 16:52:13 -03006899 /* In default link is down */
6900 netif_carrier_off(port->dev);
6901
6902 err = mvpp2_phy_connect(port);
6903 if (err < 0)
Antoine Tenartfd3651b2017-09-01 11:04:54 +02006904 goto err_free_link_irq;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006905
6906 /* Unmask interrupts on all CPUs */
6907 on_each_cpu(mvpp2_interrupts_unmask, port, 1);
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006908 mvpp2_shared_interrupt_mask_unmask(port, false);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006909
6910 mvpp2_start_dev(port);
6911
Antoine Tenart1d7d15d2017-10-30 11:23:30 +01006912 if (priv->hw_version == MVPP22)
6913 mvpp22_init_rss(port);
6914
Marcin Wojtas3f518502014-07-10 16:52:13 -03006915 return 0;
6916
Antoine Tenartfd3651b2017-09-01 11:04:54 +02006917err_free_link_irq:
6918 if (priv->hw_version == MVPP22 && !port->phy_node && port->link_irq)
6919 free_irq(port->link_irq, port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006920err_free_irq:
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006921 mvpp2_irqs_deinit(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006922err_cleanup_txqs:
6923 mvpp2_cleanup_txqs(port);
6924err_cleanup_rxqs:
6925 mvpp2_cleanup_rxqs(port);
6926 return err;
6927}
6928
6929static int mvpp2_stop(struct net_device *dev)
6930{
6931 struct mvpp2_port *port = netdev_priv(dev);
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006932 struct mvpp2_port_pcpu *port_pcpu;
Antoine Tenartfd3651b2017-09-01 11:04:54 +02006933 struct mvpp2 *priv = port->priv;
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006934 int cpu;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006935
6936 mvpp2_stop_dev(port);
6937 mvpp2_phy_disconnect(port);
6938
6939 /* Mask interrupts on all CPUs */
6940 on_each_cpu(mvpp2_interrupts_mask, port, 1);
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006941 mvpp2_shared_interrupt_mask_unmask(port, true);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006942
Antoine Tenartfd3651b2017-09-01 11:04:54 +02006943 if (priv->hw_version == MVPP22 && !port->phy_node && port->link_irq)
6944 free_irq(port->link_irq, port);
6945
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006946 mvpp2_irqs_deinit(port);
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006947 if (!port->has_tx_irqs) {
6948 for_each_present_cpu(cpu) {
6949 port_pcpu = per_cpu_ptr(port->pcpu, cpu);
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006950
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006951 hrtimer_cancel(&port_pcpu->tx_done_timer);
6952 port_pcpu->timer_scheduled = false;
6953 tasklet_kill(&port_pcpu->tx_done_tasklet);
6954 }
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006955 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03006956 mvpp2_cleanup_rxqs(port);
6957 mvpp2_cleanup_txqs(port);
6958
6959 return 0;
6960}
6961
6962static void mvpp2_set_rx_mode(struct net_device *dev)
6963{
6964 struct mvpp2_port *port = netdev_priv(dev);
6965 struct mvpp2 *priv = port->priv;
6966 struct netdev_hw_addr *ha;
6967 int id = port->id;
6968 bool allmulti = dev->flags & IFF_ALLMULTI;
6969
6970 mvpp2_prs_mac_promisc_set(priv, id, dev->flags & IFF_PROMISC);
6971 mvpp2_prs_mac_multi_set(priv, id, MVPP2_PE_MAC_MC_ALL, allmulti);
6972 mvpp2_prs_mac_multi_set(priv, id, MVPP2_PE_MAC_MC_IP6, allmulti);
6973
6974 /* Remove all port->id's mcast enries */
6975 mvpp2_prs_mcast_del_all(priv, id);
6976
6977 if (allmulti && !netdev_mc_empty(dev)) {
6978 netdev_for_each_mc_addr(ha, dev)
6979 mvpp2_prs_mac_da_accept(priv, id, ha->addr, true);
6980 }
6981}
6982
6983static int mvpp2_set_mac_address(struct net_device *dev, void *p)
6984{
6985 struct mvpp2_port *port = netdev_priv(dev);
6986 const struct sockaddr *addr = p;
6987 int err;
6988
6989 if (!is_valid_ether_addr(addr->sa_data)) {
6990 err = -EADDRNOTAVAIL;
Markus Elfringc1175542017-04-17 11:10:47 +02006991 goto log_error;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006992 }
6993
6994 if (!netif_running(dev)) {
6995 err = mvpp2_prs_update_mac_da(dev, addr->sa_data);
6996 if (!err)
6997 return 0;
6998 /* Reconfigure parser to accept the original MAC address */
6999 err = mvpp2_prs_update_mac_da(dev, dev->dev_addr);
7000 if (err)
Markus Elfringc1175542017-04-17 11:10:47 +02007001 goto log_error;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007002 }
7003
7004 mvpp2_stop_dev(port);
7005
7006 err = mvpp2_prs_update_mac_da(dev, addr->sa_data);
7007 if (!err)
7008 goto out_start;
7009
7010 /* Reconfigure parser accept the original MAC address */
7011 err = mvpp2_prs_update_mac_da(dev, dev->dev_addr);
7012 if (err)
Markus Elfringc1175542017-04-17 11:10:47 +02007013 goto log_error;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007014out_start:
7015 mvpp2_start_dev(port);
7016 mvpp2_egress_enable(port);
7017 mvpp2_ingress_enable(port);
7018 return 0;
Markus Elfringc1175542017-04-17 11:10:47 +02007019log_error:
Markus Elfringdfd42402017-04-17 11:20:41 +02007020 netdev_err(dev, "failed to change MAC address\n");
Marcin Wojtas3f518502014-07-10 16:52:13 -03007021 return err;
7022}
7023
7024static int mvpp2_change_mtu(struct net_device *dev, int mtu)
7025{
7026 struct mvpp2_port *port = netdev_priv(dev);
7027 int err;
7028
Jarod Wilson57779872016-10-17 15:54:06 -04007029 if (!IS_ALIGNED(MVPP2_RX_PKT_SIZE(mtu), 8)) {
7030 netdev_info(dev, "illegal MTU value %d, round to %d\n", mtu,
7031 ALIGN(MVPP2_RX_PKT_SIZE(mtu), 8));
7032 mtu = ALIGN(MVPP2_RX_PKT_SIZE(mtu), 8);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007033 }
7034
7035 if (!netif_running(dev)) {
7036 err = mvpp2_bm_update_mtu(dev, mtu);
7037 if (!err) {
7038 port->pkt_size = MVPP2_RX_PKT_SIZE(mtu);
7039 return 0;
7040 }
7041
7042 /* Reconfigure BM to the original MTU */
7043 err = mvpp2_bm_update_mtu(dev, dev->mtu);
7044 if (err)
Markus Elfringc1175542017-04-17 11:10:47 +02007045 goto log_error;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007046 }
7047
7048 mvpp2_stop_dev(port);
7049
7050 err = mvpp2_bm_update_mtu(dev, mtu);
7051 if (!err) {
7052 port->pkt_size = MVPP2_RX_PKT_SIZE(mtu);
7053 goto out_start;
7054 }
7055
7056 /* Reconfigure BM to the original MTU */
7057 err = mvpp2_bm_update_mtu(dev, dev->mtu);
7058 if (err)
Markus Elfringc1175542017-04-17 11:10:47 +02007059 goto log_error;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007060
7061out_start:
7062 mvpp2_start_dev(port);
7063 mvpp2_egress_enable(port);
7064 mvpp2_ingress_enable(port);
7065
7066 return 0;
Markus Elfringc1175542017-04-17 11:10:47 +02007067log_error:
Markus Elfringdfd42402017-04-17 11:20:41 +02007068 netdev_err(dev, "failed to change MTU\n");
Marcin Wojtas3f518502014-07-10 16:52:13 -03007069 return err;
7070}
7071
stephen hemmingerbc1f4472017-01-06 19:12:52 -08007072static void
Marcin Wojtas3f518502014-07-10 16:52:13 -03007073mvpp2_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
7074{
7075 struct mvpp2_port *port = netdev_priv(dev);
7076 unsigned int start;
7077 int cpu;
7078
7079 for_each_possible_cpu(cpu) {
7080 struct mvpp2_pcpu_stats *cpu_stats;
7081 u64 rx_packets;
7082 u64 rx_bytes;
7083 u64 tx_packets;
7084 u64 tx_bytes;
7085
7086 cpu_stats = per_cpu_ptr(port->stats, cpu);
7087 do {
7088 start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
7089 rx_packets = cpu_stats->rx_packets;
7090 rx_bytes = cpu_stats->rx_bytes;
7091 tx_packets = cpu_stats->tx_packets;
7092 tx_bytes = cpu_stats->tx_bytes;
7093 } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
7094
7095 stats->rx_packets += rx_packets;
7096 stats->rx_bytes += rx_bytes;
7097 stats->tx_packets += tx_packets;
7098 stats->tx_bytes += tx_bytes;
7099 }
7100
7101 stats->rx_errors = dev->stats.rx_errors;
7102 stats->rx_dropped = dev->stats.rx_dropped;
7103 stats->tx_dropped = dev->stats.tx_dropped;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007104}
7105
Thomas Petazzonibd695a52014-07-27 23:21:36 +02007106static int mvpp2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
7107{
Thomas Petazzonibd695a52014-07-27 23:21:36 +02007108 int ret;
7109
Philippe Reynes8e072692016-06-28 00:08:11 +02007110 if (!dev->phydev)
Thomas Petazzonibd695a52014-07-27 23:21:36 +02007111 return -ENOTSUPP;
7112
Philippe Reynes8e072692016-06-28 00:08:11 +02007113 ret = phy_mii_ioctl(dev->phydev, ifr, cmd);
Thomas Petazzonibd695a52014-07-27 23:21:36 +02007114 if (!ret)
7115 mvpp2_link_event(dev);
7116
7117 return ret;
7118}
7119
Marcin Wojtas3f518502014-07-10 16:52:13 -03007120/* Ethtool methods */
7121
Marcin Wojtas3f518502014-07-10 16:52:13 -03007122/* Set interrupt coalescing for ethtools */
7123static int mvpp2_ethtool_set_coalesce(struct net_device *dev,
7124 struct ethtool_coalesce *c)
7125{
7126 struct mvpp2_port *port = netdev_priv(dev);
7127 int queue;
7128
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007129 for (queue = 0; queue < port->nrxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03007130 struct mvpp2_rx_queue *rxq = port->rxqs[queue];
7131
7132 rxq->time_coal = c->rx_coalesce_usecs;
7133 rxq->pkts_coal = c->rx_max_coalesced_frames;
Thomas Petazzonid63f9e42017-02-21 11:28:02 +01007134 mvpp2_rx_pkts_coal_set(port, rxq);
7135 mvpp2_rx_time_coal_set(port, rxq);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007136 }
7137
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007138 if (port->has_tx_irqs) {
7139 port->tx_time_coal = c->tx_coalesce_usecs;
7140 mvpp2_tx_time_coal_set(port);
7141 }
7142
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007143 for (queue = 0; queue < port->ntxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03007144 struct mvpp2_tx_queue *txq = port->txqs[queue];
7145
7146 txq->done_pkts_coal = c->tx_max_coalesced_frames;
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007147
7148 if (port->has_tx_irqs)
7149 mvpp2_tx_pkts_coal_set(port, txq);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007150 }
7151
Marcin Wojtas3f518502014-07-10 16:52:13 -03007152 return 0;
7153}
7154
7155/* get coalescing for ethtools */
7156static int mvpp2_ethtool_get_coalesce(struct net_device *dev,
7157 struct ethtool_coalesce *c)
7158{
7159 struct mvpp2_port *port = netdev_priv(dev);
7160
7161 c->rx_coalesce_usecs = port->rxqs[0]->time_coal;
7162 c->rx_max_coalesced_frames = port->rxqs[0]->pkts_coal;
7163 c->tx_max_coalesced_frames = port->txqs[0]->done_pkts_coal;
7164 return 0;
7165}
7166
7167static void mvpp2_ethtool_get_drvinfo(struct net_device *dev,
7168 struct ethtool_drvinfo *drvinfo)
7169{
7170 strlcpy(drvinfo->driver, MVPP2_DRIVER_NAME,
7171 sizeof(drvinfo->driver));
7172 strlcpy(drvinfo->version, MVPP2_DRIVER_VERSION,
7173 sizeof(drvinfo->version));
7174 strlcpy(drvinfo->bus_info, dev_name(&dev->dev),
7175 sizeof(drvinfo->bus_info));
7176}
7177
7178static void mvpp2_ethtool_get_ringparam(struct net_device *dev,
7179 struct ethtool_ringparam *ring)
7180{
7181 struct mvpp2_port *port = netdev_priv(dev);
7182
7183 ring->rx_max_pending = MVPP2_MAX_RXD;
7184 ring->tx_max_pending = MVPP2_MAX_TXD;
7185 ring->rx_pending = port->rx_ring_size;
7186 ring->tx_pending = port->tx_ring_size;
7187}
7188
7189static int mvpp2_ethtool_set_ringparam(struct net_device *dev,
7190 struct ethtool_ringparam *ring)
7191{
7192 struct mvpp2_port *port = netdev_priv(dev);
7193 u16 prev_rx_ring_size = port->rx_ring_size;
7194 u16 prev_tx_ring_size = port->tx_ring_size;
7195 int err;
7196
7197 err = mvpp2_check_ringparam_valid(dev, ring);
7198 if (err)
7199 return err;
7200
7201 if (!netif_running(dev)) {
7202 port->rx_ring_size = ring->rx_pending;
7203 port->tx_ring_size = ring->tx_pending;
7204 return 0;
7205 }
7206
7207 /* The interface is running, so we have to force a
7208 * reallocation of the queues
7209 */
7210 mvpp2_stop_dev(port);
7211 mvpp2_cleanup_rxqs(port);
7212 mvpp2_cleanup_txqs(port);
7213
7214 port->rx_ring_size = ring->rx_pending;
7215 port->tx_ring_size = ring->tx_pending;
7216
7217 err = mvpp2_setup_rxqs(port);
7218 if (err) {
7219 /* Reallocate Rx queues with the original ring size */
7220 port->rx_ring_size = prev_rx_ring_size;
7221 ring->rx_pending = prev_rx_ring_size;
7222 err = mvpp2_setup_rxqs(port);
7223 if (err)
7224 goto err_out;
7225 }
7226 err = mvpp2_setup_txqs(port);
7227 if (err) {
7228 /* Reallocate Tx queues with the original ring size */
7229 port->tx_ring_size = prev_tx_ring_size;
7230 ring->tx_pending = prev_tx_ring_size;
7231 err = mvpp2_setup_txqs(port);
7232 if (err)
7233 goto err_clean_rxqs;
7234 }
7235
7236 mvpp2_start_dev(port);
7237 mvpp2_egress_enable(port);
7238 mvpp2_ingress_enable(port);
7239
7240 return 0;
7241
7242err_clean_rxqs:
7243 mvpp2_cleanup_rxqs(port);
7244err_out:
Markus Elfringdfd42402017-04-17 11:20:41 +02007245 netdev_err(dev, "failed to change ring parameters");
Marcin Wojtas3f518502014-07-10 16:52:13 -03007246 return err;
7247}
7248
7249/* Device ops */
7250
7251static const struct net_device_ops mvpp2_netdev_ops = {
7252 .ndo_open = mvpp2_open,
7253 .ndo_stop = mvpp2_stop,
7254 .ndo_start_xmit = mvpp2_tx,
7255 .ndo_set_rx_mode = mvpp2_set_rx_mode,
7256 .ndo_set_mac_address = mvpp2_set_mac_address,
7257 .ndo_change_mtu = mvpp2_change_mtu,
7258 .ndo_get_stats64 = mvpp2_get_stats64,
Thomas Petazzonibd695a52014-07-27 23:21:36 +02007259 .ndo_do_ioctl = mvpp2_ioctl,
Marcin Wojtas3f518502014-07-10 16:52:13 -03007260};
7261
7262static const struct ethtool_ops mvpp2_eth_tool_ops = {
Florian Fainelli00606c42016-11-15 11:19:48 -08007263 .nway_reset = phy_ethtool_nway_reset,
Marcin Wojtas3f518502014-07-10 16:52:13 -03007264 .get_link = ethtool_op_get_link,
Marcin Wojtas3f518502014-07-10 16:52:13 -03007265 .set_coalesce = mvpp2_ethtool_set_coalesce,
7266 .get_coalesce = mvpp2_ethtool_get_coalesce,
7267 .get_drvinfo = mvpp2_ethtool_get_drvinfo,
7268 .get_ringparam = mvpp2_ethtool_get_ringparam,
7269 .set_ringparam = mvpp2_ethtool_set_ringparam,
Philippe Reynesfb773e92016-06-28 00:08:12 +02007270 .get_link_ksettings = phy_ethtool_get_link_ksettings,
7271 .set_link_ksettings = phy_ethtool_set_link_ksettings,
Marcin Wojtas3f518502014-07-10 16:52:13 -03007272};
7273
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007274/* Used for PPv2.1, or PPv2.2 with the old Device Tree binding that
7275 * had a single IRQ defined per-port.
7276 */
7277static int mvpp2_simple_queue_vectors_init(struct mvpp2_port *port,
7278 struct device_node *port_node)
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007279{
7280 struct mvpp2_queue_vector *v = &port->qvecs[0];
7281
7282 v->first_rxq = 0;
7283 v->nrxqs = port->nrxqs;
7284 v->type = MVPP2_QUEUE_VECTOR_SHARED;
7285 v->sw_thread_id = 0;
7286 v->sw_thread_mask = *cpumask_bits(cpu_online_mask);
7287 v->port = port;
7288 v->irq = irq_of_parse_and_map(port_node, 0);
7289 if (v->irq <= 0)
7290 return -EINVAL;
7291 netif_napi_add(port->dev, &v->napi, mvpp2_poll,
7292 NAPI_POLL_WEIGHT);
7293
7294 port->nqvecs = 1;
7295
7296 return 0;
7297}
7298
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007299static int mvpp2_multi_queue_vectors_init(struct mvpp2_port *port,
7300 struct device_node *port_node)
7301{
7302 struct mvpp2_queue_vector *v;
7303 int i, ret;
7304
7305 port->nqvecs = num_possible_cpus();
7306 if (queue_mode == MVPP2_QDIST_SINGLE_MODE)
7307 port->nqvecs += 1;
7308
7309 for (i = 0; i < port->nqvecs; i++) {
7310 char irqname[16];
7311
7312 v = port->qvecs + i;
7313
7314 v->port = port;
7315 v->type = MVPP2_QUEUE_VECTOR_PRIVATE;
7316 v->sw_thread_id = i;
7317 v->sw_thread_mask = BIT(i);
7318
7319 snprintf(irqname, sizeof(irqname), "tx-cpu%d", i);
7320
7321 if (queue_mode == MVPP2_QDIST_MULTI_MODE) {
7322 v->first_rxq = i * MVPP2_DEFAULT_RXQ;
7323 v->nrxqs = MVPP2_DEFAULT_RXQ;
7324 } else if (queue_mode == MVPP2_QDIST_SINGLE_MODE &&
7325 i == (port->nqvecs - 1)) {
7326 v->first_rxq = 0;
7327 v->nrxqs = port->nrxqs;
7328 v->type = MVPP2_QUEUE_VECTOR_SHARED;
7329 strncpy(irqname, "rx-shared", sizeof(irqname));
7330 }
7331
7332 v->irq = of_irq_get_byname(port_node, irqname);
7333 if (v->irq <= 0) {
7334 ret = -EINVAL;
7335 goto err;
7336 }
7337
7338 netif_napi_add(port->dev, &v->napi, mvpp2_poll,
7339 NAPI_POLL_WEIGHT);
7340 }
7341
7342 return 0;
7343
7344err:
7345 for (i = 0; i < port->nqvecs; i++)
7346 irq_dispose_mapping(port->qvecs[i].irq);
7347 return ret;
7348}
7349
7350static int mvpp2_queue_vectors_init(struct mvpp2_port *port,
7351 struct device_node *port_node)
7352{
7353 if (port->has_tx_irqs)
7354 return mvpp2_multi_queue_vectors_init(port, port_node);
7355 else
7356 return mvpp2_simple_queue_vectors_init(port, port_node);
7357}
7358
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007359static void mvpp2_queue_vectors_deinit(struct mvpp2_port *port)
7360{
7361 int i;
7362
7363 for (i = 0; i < port->nqvecs; i++)
7364 irq_dispose_mapping(port->qvecs[i].irq);
7365}
7366
7367/* Configure Rx queue group interrupt for this port */
7368static void mvpp2_rx_irqs_setup(struct mvpp2_port *port)
7369{
7370 struct mvpp2 *priv = port->priv;
7371 u32 val;
7372 int i;
7373
7374 if (priv->hw_version == MVPP21) {
7375 mvpp2_write(priv, MVPP21_ISR_RXQ_GROUP_REG(port->id),
7376 port->nrxqs);
7377 return;
7378 }
7379
7380 /* Handle the more complicated PPv2.2 case */
7381 for (i = 0; i < port->nqvecs; i++) {
7382 struct mvpp2_queue_vector *qv = port->qvecs + i;
7383
7384 if (!qv->nrxqs)
7385 continue;
7386
7387 val = qv->sw_thread_id;
7388 val |= port->id << MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_OFFSET;
7389 mvpp2_write(priv, MVPP22_ISR_RXQ_GROUP_INDEX_REG, val);
7390
7391 val = qv->first_rxq;
7392 val |= qv->nrxqs << MVPP22_ISR_RXQ_SUB_GROUP_SIZE_OFFSET;
7393 mvpp2_write(priv, MVPP22_ISR_RXQ_SUB_GROUP_CONFIG_REG, val);
7394 }
7395}
7396
Marcin Wojtas3f518502014-07-10 16:52:13 -03007397/* Initialize port HW */
7398static int mvpp2_port_init(struct mvpp2_port *port)
7399{
7400 struct device *dev = port->dev->dev.parent;
7401 struct mvpp2 *priv = port->priv;
7402 struct mvpp2_txq_pcpu *txq_pcpu;
7403 int queue, cpu, err;
7404
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007405 /* Checks for hardware constraints */
7406 if (port->first_rxq + port->nrxqs >
Thomas Petazzoni59b9a312017-03-07 16:53:17 +01007407 MVPP2_MAX_PORTS * priv->max_port_rxqs)
Marcin Wojtas3f518502014-07-10 16:52:13 -03007408 return -EINVAL;
7409
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007410 if (port->nrxqs % 4 || (port->nrxqs > priv->max_port_rxqs) ||
7411 (port->ntxqs > MVPP2_MAX_TXQ))
7412 return -EINVAL;
7413
Marcin Wojtas3f518502014-07-10 16:52:13 -03007414 /* Disable port */
7415 mvpp2_egress_disable(port);
7416 mvpp2_port_disable(port);
7417
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007418 port->tx_time_coal = MVPP2_TXDONE_COAL_USEC;
7419
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007420 port->txqs = devm_kcalloc(dev, port->ntxqs, sizeof(*port->txqs),
Marcin Wojtas3f518502014-07-10 16:52:13 -03007421 GFP_KERNEL);
7422 if (!port->txqs)
7423 return -ENOMEM;
7424
7425 /* Associate physical Tx queues to this port and initialize.
7426 * The mapping is predefined.
7427 */
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007428 for (queue = 0; queue < port->ntxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03007429 int queue_phy_id = mvpp2_txq_phys(port->id, queue);
7430 struct mvpp2_tx_queue *txq;
7431
7432 txq = devm_kzalloc(dev, sizeof(*txq), GFP_KERNEL);
Christophe Jaillet177c8d12017-02-19 10:19:57 +01007433 if (!txq) {
7434 err = -ENOMEM;
7435 goto err_free_percpu;
7436 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03007437
7438 txq->pcpu = alloc_percpu(struct mvpp2_txq_pcpu);
7439 if (!txq->pcpu) {
7440 err = -ENOMEM;
7441 goto err_free_percpu;
7442 }
7443
7444 txq->id = queue_phy_id;
7445 txq->log_id = queue;
7446 txq->done_pkts_coal = MVPP2_TXDONE_COAL_PKTS_THRESH;
7447 for_each_present_cpu(cpu) {
7448 txq_pcpu = per_cpu_ptr(txq->pcpu, cpu);
7449 txq_pcpu->cpu = cpu;
7450 }
7451
7452 port->txqs[queue] = txq;
7453 }
7454
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007455 port->rxqs = devm_kcalloc(dev, port->nrxqs, sizeof(*port->rxqs),
Marcin Wojtas3f518502014-07-10 16:52:13 -03007456 GFP_KERNEL);
7457 if (!port->rxqs) {
7458 err = -ENOMEM;
7459 goto err_free_percpu;
7460 }
7461
7462 /* Allocate and initialize Rx queue for this port */
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007463 for (queue = 0; queue < port->nrxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03007464 struct mvpp2_rx_queue *rxq;
7465
7466 /* Map physical Rx queue to port's logical Rx queue */
7467 rxq = devm_kzalloc(dev, sizeof(*rxq), GFP_KERNEL);
Jisheng Zhangd82b0c22016-03-31 17:01:23 +08007468 if (!rxq) {
7469 err = -ENOMEM;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007470 goto err_free_percpu;
Jisheng Zhangd82b0c22016-03-31 17:01:23 +08007471 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03007472 /* Map this Rx queue to a physical queue */
7473 rxq->id = port->first_rxq + queue;
7474 rxq->port = port->id;
7475 rxq->logic_rxq = queue;
7476
7477 port->rxqs[queue] = rxq;
7478 }
7479
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007480 mvpp2_rx_irqs_setup(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007481
7482 /* Create Rx descriptor rings */
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007483 for (queue = 0; queue < port->nrxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03007484 struct mvpp2_rx_queue *rxq = port->rxqs[queue];
7485
7486 rxq->size = port->rx_ring_size;
7487 rxq->pkts_coal = MVPP2_RX_COAL_PKTS;
7488 rxq->time_coal = MVPP2_RX_COAL_USEC;
7489 }
7490
7491 mvpp2_ingress_disable(port);
7492
7493 /* Port default configuration */
7494 mvpp2_defaults_set(port);
7495
7496 /* Port's classifier configuration */
7497 mvpp2_cls_oversize_rxq_set(port);
7498 mvpp2_cls_port_config(port);
7499
7500 /* Provide an initial Rx packet size */
7501 port->pkt_size = MVPP2_RX_PKT_SIZE(port->dev->mtu);
7502
7503 /* Initialize pools for swf */
7504 err = mvpp2_swf_bm_pool_init(port);
7505 if (err)
7506 goto err_free_percpu;
7507
7508 return 0;
7509
7510err_free_percpu:
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007511 for (queue = 0; queue < port->ntxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03007512 if (!port->txqs[queue])
7513 continue;
7514 free_percpu(port->txqs[queue]->pcpu);
7515 }
7516 return err;
7517}
7518
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007519/* Checks if the port DT description has the TX interrupts
7520 * described. On PPv2.1, there are no such interrupts. On PPv2.2,
7521 * there are available, but we need to keep support for old DTs.
7522 */
7523static bool mvpp2_port_has_tx_irqs(struct mvpp2 *priv,
7524 struct device_node *port_node)
7525{
7526 char *irqs[5] = { "rx-shared", "tx-cpu0", "tx-cpu1",
7527 "tx-cpu2", "tx-cpu3" };
7528 int ret, i;
7529
7530 if (priv->hw_version == MVPP21)
7531 return false;
7532
7533 for (i = 0; i < 5; i++) {
7534 ret = of_property_match_string(port_node, "interrupt-names",
7535 irqs[i]);
7536 if (ret < 0)
7537 return false;
7538 }
7539
7540 return true;
7541}
7542
Antoine Tenart3ba8c812017-09-02 11:06:47 +02007543static void mvpp2_port_copy_mac_addr(struct net_device *dev, struct mvpp2 *priv,
7544 struct device_node *port_node,
7545 char **mac_from)
7546{
7547 struct mvpp2_port *port = netdev_priv(dev);
7548 char hw_mac_addr[ETH_ALEN] = {0};
7549 const char *dt_mac_addr;
7550
7551 dt_mac_addr = of_get_mac_address(port_node);
7552 if (dt_mac_addr && is_valid_ether_addr(dt_mac_addr)) {
7553 *mac_from = "device tree";
7554 ether_addr_copy(dev->dev_addr, dt_mac_addr);
Antoine Tenart688cbaf2017-09-02 11:06:49 +02007555 return;
Antoine Tenart3ba8c812017-09-02 11:06:47 +02007556 }
Antoine Tenart688cbaf2017-09-02 11:06:49 +02007557
7558 if (priv->hw_version == MVPP21) {
7559 mvpp21_get_mac_address(port, hw_mac_addr);
7560 if (is_valid_ether_addr(hw_mac_addr)) {
7561 *mac_from = "hardware";
7562 ether_addr_copy(dev->dev_addr, hw_mac_addr);
7563 return;
7564 }
7565 }
7566
7567 *mac_from = "random";
7568 eth_hw_addr_random(dev);
Antoine Tenart3ba8c812017-09-02 11:06:47 +02007569}
7570
Marcin Wojtas3f518502014-07-10 16:52:13 -03007571/* Ports initialization */
7572static int mvpp2_port_probe(struct platform_device *pdev,
7573 struct device_node *port_node,
Yan Markman6bf69a12017-09-25 14:59:47 +02007574 struct mvpp2 *priv, int index)
Marcin Wojtas3f518502014-07-10 16:52:13 -03007575{
7576 struct device_node *phy_node;
Antoine Tenart542897d2017-08-30 10:29:15 +02007577 struct phy *comphy;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007578 struct mvpp2_port *port;
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007579 struct mvpp2_port_pcpu *port_pcpu;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007580 struct net_device *dev;
7581 struct resource *res;
Antoine Tenart3ba8c812017-09-02 11:06:47 +02007582 char *mac_from = "";
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007583 unsigned int ntxqs, nrxqs;
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007584 bool has_tx_irqs;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007585 u32 id;
7586 int features;
7587 int phy_mode;
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007588 int err, i, cpu;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007589
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007590 has_tx_irqs = mvpp2_port_has_tx_irqs(priv, port_node);
7591
7592 if (!has_tx_irqs)
7593 queue_mode = MVPP2_QDIST_SINGLE_MODE;
7594
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007595 ntxqs = MVPP2_MAX_TXQ;
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007596 if (priv->hw_version == MVPP22 && queue_mode == MVPP2_QDIST_MULTI_MODE)
7597 nrxqs = MVPP2_DEFAULT_RXQ * num_possible_cpus();
7598 else
7599 nrxqs = MVPP2_DEFAULT_RXQ;
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007600
7601 dev = alloc_etherdev_mqs(sizeof(*port), ntxqs, nrxqs);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007602 if (!dev)
7603 return -ENOMEM;
7604
7605 phy_node = of_parse_phandle(port_node, "phy", 0);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007606 phy_mode = of_get_phy_mode(port_node);
7607 if (phy_mode < 0) {
7608 dev_err(&pdev->dev, "incorrect phy mode\n");
7609 err = phy_mode;
7610 goto err_free_netdev;
7611 }
7612
Antoine Tenart542897d2017-08-30 10:29:15 +02007613 comphy = devm_of_phy_get(&pdev->dev, port_node, NULL);
7614 if (IS_ERR(comphy)) {
7615 if (PTR_ERR(comphy) == -EPROBE_DEFER) {
7616 err = -EPROBE_DEFER;
7617 goto err_free_netdev;
7618 }
7619 comphy = NULL;
7620 }
7621
Marcin Wojtas3f518502014-07-10 16:52:13 -03007622 if (of_property_read_u32(port_node, "port-id", &id)) {
7623 err = -EINVAL;
7624 dev_err(&pdev->dev, "missing port-id value\n");
7625 goto err_free_netdev;
7626 }
7627
7628 dev->tx_queue_len = MVPP2_MAX_TXD;
7629 dev->watchdog_timeo = 5 * HZ;
7630 dev->netdev_ops = &mvpp2_netdev_ops;
7631 dev->ethtool_ops = &mvpp2_eth_tool_ops;
7632
7633 port = netdev_priv(dev);
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007634 port->dev = dev;
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007635 port->ntxqs = ntxqs;
7636 port->nrxqs = nrxqs;
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007637 port->priv = priv;
7638 port->has_tx_irqs = has_tx_irqs;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007639
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007640 err = mvpp2_queue_vectors_init(port, port_node);
7641 if (err)
Marcin Wojtas3f518502014-07-10 16:52:13 -03007642 goto err_free_netdev;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007643
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007644 port->link_irq = of_irq_get_byname(port_node, "link");
7645 if (port->link_irq == -EPROBE_DEFER) {
7646 err = -EPROBE_DEFER;
7647 goto err_deinit_qvecs;
7648 }
7649 if (port->link_irq <= 0)
7650 /* the link irq is optional */
7651 port->link_irq = 0;
7652
Marcin Wojtas3f518502014-07-10 16:52:13 -03007653 if (of_property_read_bool(port_node, "marvell,loopback"))
7654 port->flags |= MVPP2_F_LOOPBACK;
7655
Marcin Wojtas3f518502014-07-10 16:52:13 -03007656 port->id = id;
Thomas Petazzoni59b9a312017-03-07 16:53:17 +01007657 if (priv->hw_version == MVPP21)
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007658 port->first_rxq = port->id * port->nrxqs;
Thomas Petazzoni59b9a312017-03-07 16:53:17 +01007659 else
7660 port->first_rxq = port->id * priv->max_port_rxqs;
7661
Marcin Wojtas3f518502014-07-10 16:52:13 -03007662 port->phy_node = phy_node;
7663 port->phy_interface = phy_mode;
Antoine Tenart542897d2017-08-30 10:29:15 +02007664 port->comphy = comphy;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007665
Thomas Petazzonia7868412017-03-07 16:53:13 +01007666 if (priv->hw_version == MVPP21) {
7667 res = platform_get_resource(pdev, IORESOURCE_MEM, 2 + id);
7668 port->base = devm_ioremap_resource(&pdev->dev, res);
7669 if (IS_ERR(port->base)) {
7670 err = PTR_ERR(port->base);
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007671 goto err_free_irq;
Thomas Petazzonia7868412017-03-07 16:53:13 +01007672 }
7673 } else {
7674 if (of_property_read_u32(port_node, "gop-port-id",
7675 &port->gop_id)) {
7676 err = -EINVAL;
7677 dev_err(&pdev->dev, "missing gop-port-id value\n");
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007678 goto err_deinit_qvecs;
Thomas Petazzonia7868412017-03-07 16:53:13 +01007679 }
7680
7681 port->base = priv->iface_base + MVPP22_GMAC_BASE(port->gop_id);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007682 }
7683
7684 /* Alloc per-cpu stats */
7685 port->stats = netdev_alloc_pcpu_stats(struct mvpp2_pcpu_stats);
7686 if (!port->stats) {
7687 err = -ENOMEM;
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007688 goto err_free_irq;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007689 }
7690
Antoine Tenart3ba8c812017-09-02 11:06:47 +02007691 mvpp2_port_copy_mac_addr(dev, priv, port_node, &mac_from);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007692
7693 port->tx_ring_size = MVPP2_MAX_TXD;
7694 port->rx_ring_size = MVPP2_MAX_RXD;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007695 SET_NETDEV_DEV(dev, &pdev->dev);
7696
7697 err = mvpp2_port_init(port);
7698 if (err < 0) {
7699 dev_err(&pdev->dev, "failed to init port %d\n", id);
7700 goto err_free_stats;
7701 }
Thomas Petazzoni26975822017-03-07 16:53:14 +01007702
Thomas Petazzoni26975822017-03-07 16:53:14 +01007703 mvpp2_port_periodic_xon_disable(port);
7704
7705 if (priv->hw_version == MVPP21)
7706 mvpp2_port_fc_adv_enable(port);
7707
7708 mvpp2_port_reset(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007709
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007710 port->pcpu = alloc_percpu(struct mvpp2_port_pcpu);
7711 if (!port->pcpu) {
7712 err = -ENOMEM;
7713 goto err_free_txq_pcpu;
7714 }
7715
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007716 if (!port->has_tx_irqs) {
7717 for_each_present_cpu(cpu) {
7718 port_pcpu = per_cpu_ptr(port->pcpu, cpu);
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007719
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007720 hrtimer_init(&port_pcpu->tx_done_timer, CLOCK_MONOTONIC,
7721 HRTIMER_MODE_REL_PINNED);
7722 port_pcpu->tx_done_timer.function = mvpp2_hr_timer_cb;
7723 port_pcpu->timer_scheduled = false;
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007724
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007725 tasklet_init(&port_pcpu->tx_done_tasklet,
7726 mvpp2_tx_proc_cb,
7727 (unsigned long)dev);
7728 }
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007729 }
7730
Antoine Ténart186cd4d2017-08-23 09:46:56 +02007731 features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007732 dev->features = features | NETIF_F_RXCSUM;
7733 dev->hw_features |= features | NETIF_F_RXCSUM | NETIF_F_GRO;
7734 dev->vlan_features |= features;
7735
Jarod Wilson57779872016-10-17 15:54:06 -04007736 /* MTU range: 68 - 9676 */
7737 dev->min_mtu = ETH_MIN_MTU;
7738 /* 9676 == 9700 - 20 and rounding to 8 */
7739 dev->max_mtu = 9676;
7740
Marcin Wojtas3f518502014-07-10 16:52:13 -03007741 err = register_netdev(dev);
7742 if (err < 0) {
7743 dev_err(&pdev->dev, "failed to register netdev\n");
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007744 goto err_free_port_pcpu;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007745 }
7746 netdev_info(dev, "Using %s mac address %pM\n", mac_from, dev->dev_addr);
7747
Yan Markman6bf69a12017-09-25 14:59:47 +02007748 priv->port_list[index] = port;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007749 return 0;
7750
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007751err_free_port_pcpu:
7752 free_percpu(port->pcpu);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007753err_free_txq_pcpu:
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007754 for (i = 0; i < port->ntxqs; i++)
Marcin Wojtas3f518502014-07-10 16:52:13 -03007755 free_percpu(port->txqs[i]->pcpu);
7756err_free_stats:
7757 free_percpu(port->stats);
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007758err_free_irq:
7759 if (port->link_irq)
7760 irq_dispose_mapping(port->link_irq);
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007761err_deinit_qvecs:
7762 mvpp2_queue_vectors_deinit(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007763err_free_netdev:
Peter Chenccb80392016-08-01 15:02:37 +08007764 of_node_put(phy_node);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007765 free_netdev(dev);
7766 return err;
7767}
7768
7769/* Ports removal routine */
7770static void mvpp2_port_remove(struct mvpp2_port *port)
7771{
7772 int i;
7773
7774 unregister_netdev(port->dev);
Peter Chenccb80392016-08-01 15:02:37 +08007775 of_node_put(port->phy_node);
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007776 free_percpu(port->pcpu);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007777 free_percpu(port->stats);
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007778 for (i = 0; i < port->ntxqs; i++)
Marcin Wojtas3f518502014-07-10 16:52:13 -03007779 free_percpu(port->txqs[i]->pcpu);
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007780 mvpp2_queue_vectors_deinit(port);
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007781 if (port->link_irq)
7782 irq_dispose_mapping(port->link_irq);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007783 free_netdev(port->dev);
7784}
7785
7786/* Initialize decoding windows */
7787static void mvpp2_conf_mbus_windows(const struct mbus_dram_target_info *dram,
7788 struct mvpp2 *priv)
7789{
7790 u32 win_enable;
7791 int i;
7792
7793 for (i = 0; i < 6; i++) {
7794 mvpp2_write(priv, MVPP2_WIN_BASE(i), 0);
7795 mvpp2_write(priv, MVPP2_WIN_SIZE(i), 0);
7796
7797 if (i < 4)
7798 mvpp2_write(priv, MVPP2_WIN_REMAP(i), 0);
7799 }
7800
7801 win_enable = 0;
7802
7803 for (i = 0; i < dram->num_cs; i++) {
7804 const struct mbus_dram_window *cs = dram->cs + i;
7805
7806 mvpp2_write(priv, MVPP2_WIN_BASE(i),
7807 (cs->base & 0xffff0000) | (cs->mbus_attr << 8) |
7808 dram->mbus_dram_target_id);
7809
7810 mvpp2_write(priv, MVPP2_WIN_SIZE(i),
7811 (cs->size - 1) & 0xffff0000);
7812
7813 win_enable |= (1 << i);
7814 }
7815
7816 mvpp2_write(priv, MVPP2_BASE_ADDR_ENABLE, win_enable);
7817}
7818
7819/* Initialize Rx FIFO's */
7820static void mvpp2_rx_fifo_init(struct mvpp2 *priv)
7821{
7822 int port;
7823
7824 for (port = 0; port < MVPP2_MAX_PORTS; port++) {
7825 mvpp2_write(priv, MVPP2_RX_DATA_FIFO_SIZE_REG(port),
Antoine Tenart2d1d7df2017-10-30 11:23:28 +01007826 MVPP2_RX_FIFO_PORT_DATA_SIZE_4KB);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007827 mvpp2_write(priv, MVPP2_RX_ATTR_FIFO_SIZE_REG(port),
Antoine Tenart2d1d7df2017-10-30 11:23:28 +01007828 MVPP2_RX_FIFO_PORT_ATTR_SIZE_4KB);
7829 }
7830
7831 mvpp2_write(priv, MVPP2_RX_MIN_PKT_SIZE_REG,
7832 MVPP2_RX_FIFO_PORT_MIN_PKT);
7833 mvpp2_write(priv, MVPP2_RX_FIFO_INIT_REG, 0x1);
7834}
7835
7836static void mvpp22_rx_fifo_init(struct mvpp2 *priv)
7837{
7838 int port;
7839
7840 /* The FIFO size parameters are set depending on the maximum speed a
7841 * given port can handle:
7842 * - Port 0: 10Gbps
7843 * - Port 1: 2.5Gbps
7844 * - Ports 2 and 3: 1Gbps
7845 */
7846
7847 mvpp2_write(priv, MVPP2_RX_DATA_FIFO_SIZE_REG(0),
7848 MVPP2_RX_FIFO_PORT_DATA_SIZE_32KB);
7849 mvpp2_write(priv, MVPP2_RX_ATTR_FIFO_SIZE_REG(0),
7850 MVPP2_RX_FIFO_PORT_ATTR_SIZE_32KB);
7851
7852 mvpp2_write(priv, MVPP2_RX_DATA_FIFO_SIZE_REG(1),
7853 MVPP2_RX_FIFO_PORT_DATA_SIZE_8KB);
7854 mvpp2_write(priv, MVPP2_RX_ATTR_FIFO_SIZE_REG(1),
7855 MVPP2_RX_FIFO_PORT_ATTR_SIZE_8KB);
7856
7857 for (port = 2; port < MVPP2_MAX_PORTS; port++) {
7858 mvpp2_write(priv, MVPP2_RX_DATA_FIFO_SIZE_REG(port),
7859 MVPP2_RX_FIFO_PORT_DATA_SIZE_4KB);
7860 mvpp2_write(priv, MVPP2_RX_ATTR_FIFO_SIZE_REG(port),
7861 MVPP2_RX_FIFO_PORT_ATTR_SIZE_4KB);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007862 }
7863
7864 mvpp2_write(priv, MVPP2_RX_MIN_PKT_SIZE_REG,
7865 MVPP2_RX_FIFO_PORT_MIN_PKT);
7866 mvpp2_write(priv, MVPP2_RX_FIFO_INIT_REG, 0x1);
7867}
7868
Antoine Tenart7c10f972017-10-30 11:23:29 +01007869/* Initialize Tx FIFO's */
7870static void mvpp22_tx_fifo_init(struct mvpp2 *priv)
7871{
7872 int port;
7873
7874 for (port = 0; port < MVPP2_MAX_PORTS; port++)
7875 mvpp2_write(priv, MVPP22_TX_FIFO_SIZE_REG(port),
7876 MVPP22_TX_FIFO_DATA_SIZE_3KB);
7877}
7878
Thomas Petazzoni6763ce32017-03-07 16:53:15 +01007879static void mvpp2_axi_init(struct mvpp2 *priv)
7880{
7881 u32 val, rdval, wrval;
7882
7883 mvpp2_write(priv, MVPP22_BM_ADDR_HIGH_RLS_REG, 0x0);
7884
7885 /* AXI Bridge Configuration */
7886
7887 rdval = MVPP22_AXI_CODE_CACHE_RD_CACHE
7888 << MVPP22_AXI_ATTR_CACHE_OFFS;
7889 rdval |= MVPP22_AXI_CODE_DOMAIN_OUTER_DOM
7890 << MVPP22_AXI_ATTR_DOMAIN_OFFS;
7891
7892 wrval = MVPP22_AXI_CODE_CACHE_WR_CACHE
7893 << MVPP22_AXI_ATTR_CACHE_OFFS;
7894 wrval |= MVPP22_AXI_CODE_DOMAIN_OUTER_DOM
7895 << MVPP22_AXI_ATTR_DOMAIN_OFFS;
7896
7897 /* BM */
7898 mvpp2_write(priv, MVPP22_AXI_BM_WR_ATTR_REG, wrval);
7899 mvpp2_write(priv, MVPP22_AXI_BM_RD_ATTR_REG, rdval);
7900
7901 /* Descriptors */
7902 mvpp2_write(priv, MVPP22_AXI_AGGRQ_DESCR_RD_ATTR_REG, rdval);
7903 mvpp2_write(priv, MVPP22_AXI_TXQ_DESCR_WR_ATTR_REG, wrval);
7904 mvpp2_write(priv, MVPP22_AXI_TXQ_DESCR_RD_ATTR_REG, rdval);
7905 mvpp2_write(priv, MVPP22_AXI_RXQ_DESCR_WR_ATTR_REG, wrval);
7906
7907 /* Buffer Data */
7908 mvpp2_write(priv, MVPP22_AXI_TX_DATA_RD_ATTR_REG, rdval);
7909 mvpp2_write(priv, MVPP22_AXI_RX_DATA_WR_ATTR_REG, wrval);
7910
7911 val = MVPP22_AXI_CODE_CACHE_NON_CACHE
7912 << MVPP22_AXI_CODE_CACHE_OFFS;
7913 val |= MVPP22_AXI_CODE_DOMAIN_SYSTEM
7914 << MVPP22_AXI_CODE_DOMAIN_OFFS;
7915 mvpp2_write(priv, MVPP22_AXI_RD_NORMAL_CODE_REG, val);
7916 mvpp2_write(priv, MVPP22_AXI_WR_NORMAL_CODE_REG, val);
7917
7918 val = MVPP22_AXI_CODE_CACHE_RD_CACHE
7919 << MVPP22_AXI_CODE_CACHE_OFFS;
7920 val |= MVPP22_AXI_CODE_DOMAIN_OUTER_DOM
7921 << MVPP22_AXI_CODE_DOMAIN_OFFS;
7922
7923 mvpp2_write(priv, MVPP22_AXI_RD_SNOOP_CODE_REG, val);
7924
7925 val = MVPP22_AXI_CODE_CACHE_WR_CACHE
7926 << MVPP22_AXI_CODE_CACHE_OFFS;
7927 val |= MVPP22_AXI_CODE_DOMAIN_OUTER_DOM
7928 << MVPP22_AXI_CODE_DOMAIN_OFFS;
7929
7930 mvpp2_write(priv, MVPP22_AXI_WR_SNOOP_CODE_REG, val);
7931}
7932
Marcin Wojtas3f518502014-07-10 16:52:13 -03007933/* Initialize network controller common part HW */
7934static int mvpp2_init(struct platform_device *pdev, struct mvpp2 *priv)
7935{
7936 const struct mbus_dram_target_info *dram_target_info;
7937 int err, i;
Marcin Wojtas08a23752014-07-21 13:48:12 -03007938 u32 val;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007939
Marcin Wojtas3f518502014-07-10 16:52:13 -03007940 /* MBUS windows configuration */
7941 dram_target_info = mv_mbus_dram_info();
7942 if (dram_target_info)
7943 mvpp2_conf_mbus_windows(dram_target_info, priv);
7944
Thomas Petazzoni6763ce32017-03-07 16:53:15 +01007945 if (priv->hw_version == MVPP22)
7946 mvpp2_axi_init(priv);
7947
Marcin Wojtas08a23752014-07-21 13:48:12 -03007948 /* Disable HW PHY polling */
Thomas Petazzoni26975822017-03-07 16:53:14 +01007949 if (priv->hw_version == MVPP21) {
7950 val = readl(priv->lms_base + MVPP2_PHY_AN_CFG0_REG);
7951 val |= MVPP2_PHY_AN_STOP_SMI0_MASK;
7952 writel(val, priv->lms_base + MVPP2_PHY_AN_CFG0_REG);
7953 } else {
7954 val = readl(priv->iface_base + MVPP22_SMI_MISC_CFG_REG);
7955 val &= ~MVPP22_SMI_POLLING_EN;
7956 writel(val, priv->iface_base + MVPP22_SMI_MISC_CFG_REG);
7957 }
Marcin Wojtas08a23752014-07-21 13:48:12 -03007958
Marcin Wojtas3f518502014-07-10 16:52:13 -03007959 /* Allocate and initialize aggregated TXQs */
7960 priv->aggr_txqs = devm_kcalloc(&pdev->dev, num_present_cpus(),
Markus Elfringd7ce3ce2017-04-17 08:48:23 +02007961 sizeof(*priv->aggr_txqs),
Marcin Wojtas3f518502014-07-10 16:52:13 -03007962 GFP_KERNEL);
7963 if (!priv->aggr_txqs)
7964 return -ENOMEM;
7965
7966 for_each_present_cpu(i) {
7967 priv->aggr_txqs[i].id = i;
7968 priv->aggr_txqs[i].size = MVPP2_AGGR_TXQ_SIZE;
Antoine Ténart85affd72017-08-23 09:46:55 +02007969 err = mvpp2_aggr_txq_init(pdev, &priv->aggr_txqs[i], i, priv);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007970 if (err < 0)
7971 return err;
7972 }
7973
Antoine Tenart7c10f972017-10-30 11:23:29 +01007974 /* Fifo Init */
7975 if (priv->hw_version == MVPP21) {
Antoine Tenart2d1d7df2017-10-30 11:23:28 +01007976 mvpp2_rx_fifo_init(priv);
Antoine Tenart7c10f972017-10-30 11:23:29 +01007977 } else {
Antoine Tenart2d1d7df2017-10-30 11:23:28 +01007978 mvpp22_rx_fifo_init(priv);
Antoine Tenart7c10f972017-10-30 11:23:29 +01007979 mvpp22_tx_fifo_init(priv);
7980 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03007981
Thomas Petazzoni26975822017-03-07 16:53:14 +01007982 if (priv->hw_version == MVPP21)
7983 writel(MVPP2_EXT_GLOBAL_CTRL_DEFAULT,
7984 priv->lms_base + MVPP2_MNG_EXTENDED_GLOBAL_CTRL_REG);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007985
7986 /* Allow cache snoop when transmiting packets */
7987 mvpp2_write(priv, MVPP2_TX_SNOOP_REG, 0x1);
7988
7989 /* Buffer Manager initialization */
7990 err = mvpp2_bm_init(pdev, priv);
7991 if (err < 0)
7992 return err;
7993
7994 /* Parser default initialization */
7995 err = mvpp2_prs_default_init(pdev, priv);
7996 if (err < 0)
7997 return err;
7998
7999 /* Classifier default initialization */
8000 mvpp2_cls_init(priv);
8001
8002 return 0;
8003}
8004
8005static int mvpp2_probe(struct platform_device *pdev)
8006{
8007 struct device_node *dn = pdev->dev.of_node;
8008 struct device_node *port_node;
8009 struct mvpp2 *priv;
8010 struct resource *res;
Thomas Petazzonia7868412017-03-07 16:53:13 +01008011 void __iomem *base;
Thomas Petazzonidf089aa2017-08-03 10:41:58 +02008012 int port_count, i;
Marcin Wojtas3f518502014-07-10 16:52:13 -03008013 int err;
8014
Markus Elfring0b92e592017-04-17 08:38:32 +02008015 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008016 if (!priv)
8017 return -ENOMEM;
8018
Thomas Petazzonifaca9242017-03-07 16:53:06 +01008019 priv->hw_version =
8020 (unsigned long)of_device_get_match_data(&pdev->dev);
8021
Marcin Wojtas3f518502014-07-10 16:52:13 -03008022 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Thomas Petazzonia7868412017-03-07 16:53:13 +01008023 base = devm_ioremap_resource(&pdev->dev, res);
8024 if (IS_ERR(base))
8025 return PTR_ERR(base);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008026
Thomas Petazzonia7868412017-03-07 16:53:13 +01008027 if (priv->hw_version == MVPP21) {
8028 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
8029 priv->lms_base = devm_ioremap_resource(&pdev->dev, res);
8030 if (IS_ERR(priv->lms_base))
8031 return PTR_ERR(priv->lms_base);
8032 } else {
8033 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
8034 priv->iface_base = devm_ioremap_resource(&pdev->dev, res);
8035 if (IS_ERR(priv->iface_base))
8036 return PTR_ERR(priv->iface_base);
Antoine Ténartf84bf382017-08-22 19:08:27 +02008037
8038 priv->sysctrl_base =
8039 syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
8040 "marvell,system-controller");
8041 if (IS_ERR(priv->sysctrl_base))
8042 /* The system controller regmap is optional for dt
8043 * compatibility reasons. When not provided, the
8044 * configuration of the GoP relies on the
8045 * firmware/bootloader.
8046 */
8047 priv->sysctrl_base = NULL;
Thomas Petazzonia7868412017-03-07 16:53:13 +01008048 }
8049
Thomas Petazzonidf089aa2017-08-03 10:41:58 +02008050 for (i = 0; i < MVPP2_MAX_THREADS; i++) {
Thomas Petazzonia7868412017-03-07 16:53:13 +01008051 u32 addr_space_sz;
8052
8053 addr_space_sz = (priv->hw_version == MVPP21 ?
8054 MVPP21_ADDR_SPACE_SZ : MVPP22_ADDR_SPACE_SZ);
Thomas Petazzonidf089aa2017-08-03 10:41:58 +02008055 priv->swth_base[i] = base + i * addr_space_sz;
Thomas Petazzonia7868412017-03-07 16:53:13 +01008056 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03008057
Thomas Petazzoni59b9a312017-03-07 16:53:17 +01008058 if (priv->hw_version == MVPP21)
8059 priv->max_port_rxqs = 8;
8060 else
8061 priv->max_port_rxqs = 32;
8062
Marcin Wojtas3f518502014-07-10 16:52:13 -03008063 priv->pp_clk = devm_clk_get(&pdev->dev, "pp_clk");
8064 if (IS_ERR(priv->pp_clk))
8065 return PTR_ERR(priv->pp_clk);
8066 err = clk_prepare_enable(priv->pp_clk);
8067 if (err < 0)
8068 return err;
8069
8070 priv->gop_clk = devm_clk_get(&pdev->dev, "gop_clk");
8071 if (IS_ERR(priv->gop_clk)) {
8072 err = PTR_ERR(priv->gop_clk);
8073 goto err_pp_clk;
8074 }
8075 err = clk_prepare_enable(priv->gop_clk);
8076 if (err < 0)
8077 goto err_pp_clk;
8078
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008079 if (priv->hw_version == MVPP22) {
8080 priv->mg_clk = devm_clk_get(&pdev->dev, "mg_clk");
8081 if (IS_ERR(priv->mg_clk)) {
8082 err = PTR_ERR(priv->mg_clk);
8083 goto err_gop_clk;
8084 }
8085
8086 err = clk_prepare_enable(priv->mg_clk);
8087 if (err < 0)
8088 goto err_gop_clk;
Gregory CLEMENT4792ea02017-09-29 14:27:39 +02008089
8090 priv->axi_clk = devm_clk_get(&pdev->dev, "axi_clk");
8091 if (IS_ERR(priv->axi_clk)) {
8092 err = PTR_ERR(priv->axi_clk);
8093 if (err == -EPROBE_DEFER)
8094 goto err_gop_clk;
8095 priv->axi_clk = NULL;
8096 } else {
8097 err = clk_prepare_enable(priv->axi_clk);
8098 if (err < 0)
8099 goto err_gop_clk;
8100 }
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008101 }
8102
Marcin Wojtas3f518502014-07-10 16:52:13 -03008103 /* Get system's tclk rate */
8104 priv->tclk = clk_get_rate(priv->pp_clk);
8105
Thomas Petazzoni2067e0a2017-03-07 16:53:19 +01008106 if (priv->hw_version == MVPP22) {
8107 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(40));
8108 if (err)
8109 goto err_mg_clk;
8110 /* Sadly, the BM pools all share the same register to
8111 * store the high 32 bits of their address. So they
8112 * must all have the same high 32 bits, which forces
8113 * us to restrict coherent memory to DMA_BIT_MASK(32).
8114 */
8115 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
8116 if (err)
8117 goto err_mg_clk;
8118 }
8119
Marcin Wojtas3f518502014-07-10 16:52:13 -03008120 /* Initialize network controller */
8121 err = mvpp2_init(pdev, priv);
8122 if (err < 0) {
8123 dev_err(&pdev->dev, "failed to initialize controller\n");
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008124 goto err_mg_clk;
Marcin Wojtas3f518502014-07-10 16:52:13 -03008125 }
8126
8127 port_count = of_get_available_child_count(dn);
8128 if (port_count == 0) {
8129 dev_err(&pdev->dev, "no ports enabled\n");
Wei Yongjun575a1932014-07-20 22:02:43 +08008130 err = -ENODEV;
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008131 goto err_mg_clk;
Marcin Wojtas3f518502014-07-10 16:52:13 -03008132 }
8133
8134 priv->port_list = devm_kcalloc(&pdev->dev, port_count,
Markus Elfring0b92e592017-04-17 08:38:32 +02008135 sizeof(*priv->port_list),
8136 GFP_KERNEL);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008137 if (!priv->port_list) {
8138 err = -ENOMEM;
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008139 goto err_mg_clk;
Marcin Wojtas3f518502014-07-10 16:52:13 -03008140 }
8141
8142 /* Initialize ports */
Yan Markman6bf69a12017-09-25 14:59:47 +02008143 i = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03008144 for_each_available_child_of_node(dn, port_node) {
Yan Markman6bf69a12017-09-25 14:59:47 +02008145 err = mvpp2_port_probe(pdev, port_node, priv, i);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008146 if (err < 0)
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008147 goto err_mg_clk;
Yan Markman6bf69a12017-09-25 14:59:47 +02008148 i++;
Marcin Wojtas3f518502014-07-10 16:52:13 -03008149 }
8150
8151 platform_set_drvdata(pdev, priv);
8152 return 0;
8153
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008154err_mg_clk:
Gregory CLEMENT4792ea02017-09-29 14:27:39 +02008155 clk_disable_unprepare(priv->axi_clk);
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008156 if (priv->hw_version == MVPP22)
8157 clk_disable_unprepare(priv->mg_clk);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008158err_gop_clk:
8159 clk_disable_unprepare(priv->gop_clk);
8160err_pp_clk:
8161 clk_disable_unprepare(priv->pp_clk);
8162 return err;
8163}
8164
8165static int mvpp2_remove(struct platform_device *pdev)
8166{
8167 struct mvpp2 *priv = platform_get_drvdata(pdev);
8168 struct device_node *dn = pdev->dev.of_node;
8169 struct device_node *port_node;
8170 int i = 0;
8171
8172 for_each_available_child_of_node(dn, port_node) {
8173 if (priv->port_list[i])
8174 mvpp2_port_remove(priv->port_list[i]);
8175 i++;
8176 }
8177
8178 for (i = 0; i < MVPP2_BM_POOLS_NUM; i++) {
8179 struct mvpp2_bm_pool *bm_pool = &priv->bm_pools[i];
8180
8181 mvpp2_bm_pool_destroy(pdev, priv, bm_pool);
8182 }
8183
8184 for_each_present_cpu(i) {
8185 struct mvpp2_tx_queue *aggr_txq = &priv->aggr_txqs[i];
8186
8187 dma_free_coherent(&pdev->dev,
8188 MVPP2_AGGR_TXQ_SIZE * MVPP2_DESC_ALIGNED_SIZE,
8189 aggr_txq->descs,
Thomas Petazzoni20396132017-03-07 16:53:00 +01008190 aggr_txq->descs_dma);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008191 }
8192
Gregory CLEMENT4792ea02017-09-29 14:27:39 +02008193 clk_disable_unprepare(priv->axi_clk);
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008194 clk_disable_unprepare(priv->mg_clk);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008195 clk_disable_unprepare(priv->pp_clk);
8196 clk_disable_unprepare(priv->gop_clk);
8197
8198 return 0;
8199}
8200
8201static const struct of_device_id mvpp2_match[] = {
Thomas Petazzonifaca9242017-03-07 16:53:06 +01008202 {
8203 .compatible = "marvell,armada-375-pp2",
8204 .data = (void *)MVPP21,
8205 },
Thomas Petazzonifc5e1552017-03-07 16:53:20 +01008206 {
8207 .compatible = "marvell,armada-7k-pp22",
8208 .data = (void *)MVPP22,
8209 },
Marcin Wojtas3f518502014-07-10 16:52:13 -03008210 { }
8211};
8212MODULE_DEVICE_TABLE(of, mvpp2_match);
8213
8214static struct platform_driver mvpp2_driver = {
8215 .probe = mvpp2_probe,
8216 .remove = mvpp2_remove,
8217 .driver = {
8218 .name = MVPP2_DRIVER_NAME,
8219 .of_match_table = mvpp2_match,
8220 },
8221};
8222
8223module_platform_driver(mvpp2_driver);
8224
8225MODULE_DESCRIPTION("Marvell PPv2 Ethernet Driver - www.marvell.com");
8226MODULE_AUTHOR("Marcin Wojtas <mw@semihalf.com>");
Ezequiel Garciac6340992014-07-14 10:34:47 -03008227MODULE_LICENSE("GPL v2");