blob: 5a1668cdb461c7437cf510b5592f7ab54134b0f7 [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
Marcin Wojtasa75edc72018-01-18 13:31:44 +010013#include <linux/acpi.h>
Marcin Wojtas3f518502014-07-10 16:52:13 -030014#include <linux/kernel.h>
15#include <linux/netdevice.h>
16#include <linux/etherdevice.h>
17#include <linux/platform_device.h>
18#include <linux/skbuff.h>
19#include <linux/inetdevice.h>
20#include <linux/mbus.h>
21#include <linux/module.h>
Antoine Ténartf84bf382017-08-22 19:08:27 +020022#include <linux/mfd/syscon.h>
Marcin Wojtas3f518502014-07-10 16:52:13 -030023#include <linux/interrupt.h>
24#include <linux/cpumask.h>
25#include <linux/of.h>
26#include <linux/of_irq.h>
27#include <linux/of_mdio.h>
28#include <linux/of_net.h>
29#include <linux/of_address.h>
Thomas Petazzonifaca9242017-03-07 16:53:06 +010030#include <linux/of_device.h>
Marcin Wojtas3f518502014-07-10 16:52:13 -030031#include <linux/phy.h>
Antoine Tenart542897d2017-08-30 10:29:15 +020032#include <linux/phy/phy.h>
Marcin Wojtas3f518502014-07-10 16:52:13 -030033#include <linux/clk.h>
Marcin Wojtasedc660f2015-08-06 19:00:30 +020034#include <linux/hrtimer.h>
35#include <linux/ktime.h>
Antoine Ténartf84bf382017-08-22 19:08:27 +020036#include <linux/regmap.h>
Marcin Wojtas3f518502014-07-10 16:52:13 -030037#include <uapi/linux/ppp_defs.h>
38#include <net/ip.h>
39#include <net/ipv6.h>
Antoine Ténart186cd4d2017-08-23 09:46:56 +020040#include <net/tso.h>
Marcin Wojtas3f518502014-07-10 16:52:13 -030041
Antoine Tenart7c10f972017-10-30 11:23:29 +010042/* Fifo Registers */
Marcin Wojtas3f518502014-07-10 16:52:13 -030043#define MVPP2_RX_DATA_FIFO_SIZE_REG(port) (0x00 + 4 * (port))
44#define MVPP2_RX_ATTR_FIFO_SIZE_REG(port) (0x20 + 4 * (port))
45#define MVPP2_RX_MIN_PKT_SIZE_REG 0x60
46#define MVPP2_RX_FIFO_INIT_REG 0x64
Antoine Tenart7c10f972017-10-30 11:23:29 +010047#define MVPP22_TX_FIFO_SIZE_REG(port) (0x8860 + 4 * (port))
Marcin Wojtas3f518502014-07-10 16:52:13 -030048
49/* RX DMA Top Registers */
50#define MVPP2_RX_CTRL_REG(port) (0x140 + 4 * (port))
51#define MVPP2_RX_LOW_LATENCY_PKT_SIZE(s) (((s) & 0xfff) << 16)
52#define MVPP2_RX_USE_PSEUDO_FOR_CSUM_MASK BIT(31)
53#define MVPP2_POOL_BUF_SIZE_REG(pool) (0x180 + 4 * (pool))
54#define MVPP2_POOL_BUF_SIZE_OFFSET 5
55#define MVPP2_RXQ_CONFIG_REG(rxq) (0x800 + 4 * (rxq))
56#define MVPP2_SNOOP_PKT_SIZE_MASK 0x1ff
57#define MVPP2_SNOOP_BUF_HDR_MASK BIT(9)
58#define MVPP2_RXQ_POOL_SHORT_OFFS 20
Thomas Petazzoni5eac8922017-03-07 16:53:10 +010059#define MVPP21_RXQ_POOL_SHORT_MASK 0x700000
60#define MVPP22_RXQ_POOL_SHORT_MASK 0xf00000
Marcin Wojtas3f518502014-07-10 16:52:13 -030061#define MVPP2_RXQ_POOL_LONG_OFFS 24
Thomas Petazzoni5eac8922017-03-07 16:53:10 +010062#define MVPP21_RXQ_POOL_LONG_MASK 0x7000000
63#define MVPP22_RXQ_POOL_LONG_MASK 0xf000000
Marcin Wojtas3f518502014-07-10 16:52:13 -030064#define MVPP2_RXQ_PACKET_OFFSET_OFFS 28
65#define MVPP2_RXQ_PACKET_OFFSET_MASK 0x70000000
66#define MVPP2_RXQ_DISABLE_MASK BIT(31)
67
68/* Parser Registers */
69#define MVPP2_PRS_INIT_LOOKUP_REG 0x1000
70#define MVPP2_PRS_PORT_LU_MAX 0xf
71#define MVPP2_PRS_PORT_LU_MASK(port) (0xff << ((port) * 4))
72#define MVPP2_PRS_PORT_LU_VAL(port, val) ((val) << ((port) * 4))
73#define MVPP2_PRS_INIT_OFFS_REG(port) (0x1004 + ((port) & 4))
74#define MVPP2_PRS_INIT_OFF_MASK(port) (0x3f << (((port) % 4) * 8))
75#define MVPP2_PRS_INIT_OFF_VAL(port, val) ((val) << (((port) % 4) * 8))
76#define MVPP2_PRS_MAX_LOOP_REG(port) (0x100c + ((port) & 4))
77#define MVPP2_PRS_MAX_LOOP_MASK(port) (0xff << (((port) % 4) * 8))
78#define MVPP2_PRS_MAX_LOOP_VAL(port, val) ((val) << (((port) % 4) * 8))
79#define MVPP2_PRS_TCAM_IDX_REG 0x1100
80#define MVPP2_PRS_TCAM_DATA_REG(idx) (0x1104 + (idx) * 4)
81#define MVPP2_PRS_TCAM_INV_MASK BIT(31)
82#define MVPP2_PRS_SRAM_IDX_REG 0x1200
83#define MVPP2_PRS_SRAM_DATA_REG(idx) (0x1204 + (idx) * 4)
84#define MVPP2_PRS_TCAM_CTRL_REG 0x1230
85#define MVPP2_PRS_TCAM_EN_MASK BIT(0)
86
Antoine Tenart1d7d15d2017-10-30 11:23:30 +010087/* RSS Registers */
88#define MVPP22_RSS_INDEX 0x1500
Antoine Tenart8a7b7412017-12-08 10:24:20 +010089#define MVPP22_RSS_INDEX_TABLE_ENTRY(idx) (idx)
Antoine Tenart1d7d15d2017-10-30 11:23:30 +010090#define MVPP22_RSS_INDEX_TABLE(idx) ((idx) << 8)
91#define MVPP22_RSS_INDEX_QUEUE(idx) ((idx) << 16)
92#define MVPP22_RSS_TABLE_ENTRY 0x1508
93#define MVPP22_RSS_TABLE 0x1510
94#define MVPP22_RSS_TABLE_POINTER(p) (p)
95#define MVPP22_RSS_WIDTH 0x150c
96
Marcin Wojtas3f518502014-07-10 16:52:13 -030097/* Classifier Registers */
98#define MVPP2_CLS_MODE_REG 0x1800
99#define MVPP2_CLS_MODE_ACTIVE_MASK BIT(0)
100#define MVPP2_CLS_PORT_WAY_REG 0x1810
101#define MVPP2_CLS_PORT_WAY_MASK(port) (1 << (port))
102#define MVPP2_CLS_LKP_INDEX_REG 0x1814
103#define MVPP2_CLS_LKP_INDEX_WAY_OFFS 6
104#define MVPP2_CLS_LKP_TBL_REG 0x1818
105#define MVPP2_CLS_LKP_TBL_RXQ_MASK 0xff
106#define MVPP2_CLS_LKP_TBL_LOOKUP_EN_MASK BIT(25)
107#define MVPP2_CLS_FLOW_INDEX_REG 0x1820
108#define MVPP2_CLS_FLOW_TBL0_REG 0x1824
109#define MVPP2_CLS_FLOW_TBL1_REG 0x1828
110#define MVPP2_CLS_FLOW_TBL2_REG 0x182c
111#define MVPP2_CLS_OVERSIZE_RXQ_LOW_REG(port) (0x1980 + ((port) * 4))
112#define MVPP2_CLS_OVERSIZE_RXQ_LOW_BITS 3
113#define MVPP2_CLS_OVERSIZE_RXQ_LOW_MASK 0x7
114#define MVPP2_CLS_SWFWD_P2HQ_REG(port) (0x19b0 + ((port) * 4))
115#define MVPP2_CLS_SWFWD_PCTRL_REG 0x19d0
116#define MVPP2_CLS_SWFWD_PCTRL_MASK(port) (1 << (port))
117
118/* Descriptor Manager Top Registers */
119#define MVPP2_RXQ_NUM_REG 0x2040
120#define MVPP2_RXQ_DESC_ADDR_REG 0x2044
Thomas Petazzonib02f31f2017-03-07 16:53:12 +0100121#define MVPP22_DESC_ADDR_OFFS 8
Marcin Wojtas3f518502014-07-10 16:52:13 -0300122#define MVPP2_RXQ_DESC_SIZE_REG 0x2048
123#define MVPP2_RXQ_DESC_SIZE_MASK 0x3ff0
124#define MVPP2_RXQ_STATUS_UPDATE_REG(rxq) (0x3000 + 4 * (rxq))
125#define MVPP2_RXQ_NUM_PROCESSED_OFFSET 0
126#define MVPP2_RXQ_NUM_NEW_OFFSET 16
127#define MVPP2_RXQ_STATUS_REG(rxq) (0x3400 + 4 * (rxq))
128#define MVPP2_RXQ_OCCUPIED_MASK 0x3fff
129#define MVPP2_RXQ_NON_OCCUPIED_OFFSET 16
130#define MVPP2_RXQ_NON_OCCUPIED_MASK 0x3fff0000
131#define MVPP2_RXQ_THRESH_REG 0x204c
132#define MVPP2_OCCUPIED_THRESH_OFFSET 0
133#define MVPP2_OCCUPIED_THRESH_MASK 0x3fff
134#define MVPP2_RXQ_INDEX_REG 0x2050
135#define MVPP2_TXQ_NUM_REG 0x2080
136#define MVPP2_TXQ_DESC_ADDR_REG 0x2084
137#define MVPP2_TXQ_DESC_SIZE_REG 0x2088
138#define MVPP2_TXQ_DESC_SIZE_MASK 0x3ff0
Thomas Petazzoni213f4282017-08-03 10:42:00 +0200139#define MVPP2_TXQ_THRESH_REG 0x2094
140#define MVPP2_TXQ_THRESH_OFFSET 16
141#define MVPP2_TXQ_THRESH_MASK 0x3fff
Marcin Wojtas3f518502014-07-10 16:52:13 -0300142#define MVPP2_AGGR_TXQ_UPDATE_REG 0x2090
Marcin Wojtas3f518502014-07-10 16:52:13 -0300143#define MVPP2_TXQ_INDEX_REG 0x2098
144#define MVPP2_TXQ_PREF_BUF_REG 0x209c
145#define MVPP2_PREF_BUF_PTR(desc) ((desc) & 0xfff)
146#define MVPP2_PREF_BUF_SIZE_4 (BIT(12) | BIT(13))
147#define MVPP2_PREF_BUF_SIZE_16 (BIT(12) | BIT(14))
148#define MVPP2_PREF_BUF_THRESH(val) ((val) << 17)
149#define MVPP2_TXQ_DRAIN_EN_MASK BIT(31)
150#define MVPP2_TXQ_PENDING_REG 0x20a0
151#define MVPP2_TXQ_PENDING_MASK 0x3fff
152#define MVPP2_TXQ_INT_STATUS_REG 0x20a4
153#define MVPP2_TXQ_SENT_REG(txq) (0x3c00 + 4 * (txq))
154#define MVPP2_TRANSMITTED_COUNT_OFFSET 16
155#define MVPP2_TRANSMITTED_COUNT_MASK 0x3fff0000
156#define MVPP2_TXQ_RSVD_REQ_REG 0x20b0
157#define MVPP2_TXQ_RSVD_REQ_Q_OFFSET 16
158#define MVPP2_TXQ_RSVD_RSLT_REG 0x20b4
159#define MVPP2_TXQ_RSVD_RSLT_MASK 0x3fff
160#define MVPP2_TXQ_RSVD_CLR_REG 0x20b8
161#define MVPP2_TXQ_RSVD_CLR_OFFSET 16
162#define MVPP2_AGGR_TXQ_DESC_ADDR_REG(cpu) (0x2100 + 4 * (cpu))
Thomas Petazzonib02f31f2017-03-07 16:53:12 +0100163#define MVPP22_AGGR_TXQ_DESC_ADDR_OFFS 8
Marcin Wojtas3f518502014-07-10 16:52:13 -0300164#define MVPP2_AGGR_TXQ_DESC_SIZE_REG(cpu) (0x2140 + 4 * (cpu))
165#define MVPP2_AGGR_TXQ_DESC_SIZE_MASK 0x3ff0
166#define MVPP2_AGGR_TXQ_STATUS_REG(cpu) (0x2180 + 4 * (cpu))
167#define MVPP2_AGGR_TXQ_PENDING_MASK 0x3fff
168#define MVPP2_AGGR_TXQ_INDEX_REG(cpu) (0x21c0 + 4 * (cpu))
169
170/* MBUS bridge registers */
171#define MVPP2_WIN_BASE(w) (0x4000 + ((w) << 2))
172#define MVPP2_WIN_SIZE(w) (0x4020 + ((w) << 2))
173#define MVPP2_WIN_REMAP(w) (0x4040 + ((w) << 2))
174#define MVPP2_BASE_ADDR_ENABLE 0x4060
175
Thomas Petazzoni6763ce32017-03-07 16:53:15 +0100176/* AXI Bridge Registers */
177#define MVPP22_AXI_BM_WR_ATTR_REG 0x4100
178#define MVPP22_AXI_BM_RD_ATTR_REG 0x4104
179#define MVPP22_AXI_AGGRQ_DESCR_RD_ATTR_REG 0x4110
180#define MVPP22_AXI_TXQ_DESCR_WR_ATTR_REG 0x4114
181#define MVPP22_AXI_TXQ_DESCR_RD_ATTR_REG 0x4118
182#define MVPP22_AXI_RXQ_DESCR_WR_ATTR_REG 0x411c
183#define MVPP22_AXI_RX_DATA_WR_ATTR_REG 0x4120
184#define MVPP22_AXI_TX_DATA_RD_ATTR_REG 0x4130
185#define MVPP22_AXI_RD_NORMAL_CODE_REG 0x4150
186#define MVPP22_AXI_RD_SNOOP_CODE_REG 0x4154
187#define MVPP22_AXI_WR_NORMAL_CODE_REG 0x4160
188#define MVPP22_AXI_WR_SNOOP_CODE_REG 0x4164
189
190/* Values for AXI Bridge registers */
191#define MVPP22_AXI_ATTR_CACHE_OFFS 0
192#define MVPP22_AXI_ATTR_DOMAIN_OFFS 12
193
194#define MVPP22_AXI_CODE_CACHE_OFFS 0
195#define MVPP22_AXI_CODE_DOMAIN_OFFS 4
196
197#define MVPP22_AXI_CODE_CACHE_NON_CACHE 0x3
198#define MVPP22_AXI_CODE_CACHE_WR_CACHE 0x7
199#define MVPP22_AXI_CODE_CACHE_RD_CACHE 0xb
200
201#define MVPP22_AXI_CODE_DOMAIN_OUTER_DOM 2
202#define MVPP22_AXI_CODE_DOMAIN_SYSTEM 3
203
Marcin Wojtas3f518502014-07-10 16:52:13 -0300204/* Interrupt Cause and Mask registers */
Thomas Petazzoni213f4282017-08-03 10:42:00 +0200205#define MVPP2_ISR_TX_THRESHOLD_REG(port) (0x5140 + 4 * (port))
206#define MVPP2_MAX_ISR_TX_THRESHOLD 0xfffff0
207
Marcin Wojtas3f518502014-07-10 16:52:13 -0300208#define MVPP2_ISR_RX_THRESHOLD_REG(rxq) (0x5200 + 4 * (rxq))
Thomas Petazzoniab426762017-02-21 11:28:04 +0100209#define MVPP2_MAX_ISR_RX_THRESHOLD 0xfffff0
Thomas Petazzonieb1e93a2017-08-03 10:41:55 +0200210#define MVPP21_ISR_RXQ_GROUP_REG(port) (0x5400 + 4 * (port))
Thomas Petazzonia73fef12017-03-07 16:53:16 +0100211
Antoine Ténart81b66302017-08-22 19:08:21 +0200212#define MVPP22_ISR_RXQ_GROUP_INDEX_REG 0x5400
Thomas Petazzonia73fef12017-03-07 16:53:16 +0100213#define MVPP22_ISR_RXQ_GROUP_INDEX_SUBGROUP_MASK 0xf
Antoine Ténart81b66302017-08-22 19:08:21 +0200214#define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_MASK 0x380
215#define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_OFFSET 7
Thomas Petazzonia73fef12017-03-07 16:53:16 +0100216
217#define MVPP22_ISR_RXQ_GROUP_INDEX_SUBGROUP_MASK 0xf
Antoine Ténart81b66302017-08-22 19:08:21 +0200218#define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_MASK 0x380
Thomas Petazzonia73fef12017-03-07 16:53:16 +0100219
Antoine Ténart81b66302017-08-22 19:08:21 +0200220#define MVPP22_ISR_RXQ_SUB_GROUP_CONFIG_REG 0x5404
221#define MVPP22_ISR_RXQ_SUB_GROUP_STARTQ_MASK 0x1f
222#define MVPP22_ISR_RXQ_SUB_GROUP_SIZE_MASK 0xf00
223#define MVPP22_ISR_RXQ_SUB_GROUP_SIZE_OFFSET 8
Thomas Petazzonia73fef12017-03-07 16:53:16 +0100224
Marcin Wojtas3f518502014-07-10 16:52:13 -0300225#define MVPP2_ISR_ENABLE_REG(port) (0x5420 + 4 * (port))
226#define MVPP2_ISR_ENABLE_INTERRUPT(mask) ((mask) & 0xffff)
227#define MVPP2_ISR_DISABLE_INTERRUPT(mask) (((mask) << 16) & 0xffff0000)
228#define MVPP2_ISR_RX_TX_CAUSE_REG(port) (0x5480 + 4 * (port))
229#define MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK 0xffff
230#define MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK 0xff0000
Thomas Petazzoni213f4282017-08-03 10:42:00 +0200231#define MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_OFFSET 16
Marcin Wojtas3f518502014-07-10 16:52:13 -0300232#define MVPP2_CAUSE_RX_FIFO_OVERRUN_MASK BIT(24)
233#define MVPP2_CAUSE_FCS_ERR_MASK BIT(25)
234#define MVPP2_CAUSE_TX_FIFO_UNDERRUN_MASK BIT(26)
235#define MVPP2_CAUSE_TX_EXCEPTION_SUM_MASK BIT(29)
236#define MVPP2_CAUSE_RX_EXCEPTION_SUM_MASK BIT(30)
237#define MVPP2_CAUSE_MISC_SUM_MASK BIT(31)
238#define MVPP2_ISR_RX_TX_MASK_REG(port) (0x54a0 + 4 * (port))
239#define MVPP2_ISR_PON_RX_TX_MASK_REG 0x54bc
240#define MVPP2_PON_CAUSE_RXQ_OCCUP_DESC_ALL_MASK 0xffff
241#define MVPP2_PON_CAUSE_TXP_OCCUP_DESC_ALL_MASK 0x3fc00000
242#define MVPP2_PON_CAUSE_MISC_SUM_MASK BIT(31)
243#define MVPP2_ISR_MISC_CAUSE_REG 0x55b0
244
245/* Buffer Manager registers */
246#define MVPP2_BM_POOL_BASE_REG(pool) (0x6000 + ((pool) * 4))
247#define MVPP2_BM_POOL_BASE_ADDR_MASK 0xfffff80
248#define MVPP2_BM_POOL_SIZE_REG(pool) (0x6040 + ((pool) * 4))
249#define MVPP2_BM_POOL_SIZE_MASK 0xfff0
250#define MVPP2_BM_POOL_READ_PTR_REG(pool) (0x6080 + ((pool) * 4))
251#define MVPP2_BM_POOL_GET_READ_PTR_MASK 0xfff0
252#define MVPP2_BM_POOL_PTRS_NUM_REG(pool) (0x60c0 + ((pool) * 4))
253#define MVPP2_BM_POOL_PTRS_NUM_MASK 0xfff0
254#define MVPP2_BM_BPPI_READ_PTR_REG(pool) (0x6100 + ((pool) * 4))
255#define MVPP2_BM_BPPI_PTRS_NUM_REG(pool) (0x6140 + ((pool) * 4))
256#define MVPP2_BM_BPPI_PTR_NUM_MASK 0x7ff
257#define MVPP2_BM_BPPI_PREFETCH_FULL_MASK BIT(16)
258#define MVPP2_BM_POOL_CTRL_REG(pool) (0x6200 + ((pool) * 4))
259#define MVPP2_BM_START_MASK BIT(0)
260#define MVPP2_BM_STOP_MASK BIT(1)
261#define MVPP2_BM_STATE_MASK BIT(4)
262#define MVPP2_BM_LOW_THRESH_OFFS 8
263#define MVPP2_BM_LOW_THRESH_MASK 0x7f00
264#define MVPP2_BM_LOW_THRESH_VALUE(val) ((val) << \
265 MVPP2_BM_LOW_THRESH_OFFS)
266#define MVPP2_BM_HIGH_THRESH_OFFS 16
267#define MVPP2_BM_HIGH_THRESH_MASK 0x7f0000
268#define MVPP2_BM_HIGH_THRESH_VALUE(val) ((val) << \
269 MVPP2_BM_HIGH_THRESH_OFFS)
270#define MVPP2_BM_INTR_CAUSE_REG(pool) (0x6240 + ((pool) * 4))
271#define MVPP2_BM_RELEASED_DELAY_MASK BIT(0)
272#define MVPP2_BM_ALLOC_FAILED_MASK BIT(1)
273#define MVPP2_BM_BPPE_EMPTY_MASK BIT(2)
274#define MVPP2_BM_BPPE_FULL_MASK BIT(3)
275#define MVPP2_BM_AVAILABLE_BP_LOW_MASK BIT(4)
276#define MVPP2_BM_INTR_MASK_REG(pool) (0x6280 + ((pool) * 4))
277#define MVPP2_BM_PHY_ALLOC_REG(pool) (0x6400 + ((pool) * 4))
278#define MVPP2_BM_PHY_ALLOC_GRNTD_MASK BIT(0)
279#define MVPP2_BM_VIRT_ALLOC_REG 0x6440
Thomas Petazzonid01524d2017-03-07 16:53:09 +0100280#define MVPP22_BM_ADDR_HIGH_ALLOC 0x6444
281#define MVPP22_BM_ADDR_HIGH_PHYS_MASK 0xff
282#define MVPP22_BM_ADDR_HIGH_VIRT_MASK 0xff00
283#define MVPP22_BM_ADDR_HIGH_VIRT_SHIFT 8
Marcin Wojtas3f518502014-07-10 16:52:13 -0300284#define MVPP2_BM_PHY_RLS_REG(pool) (0x6480 + ((pool) * 4))
285#define MVPP2_BM_PHY_RLS_MC_BUFF_MASK BIT(0)
286#define MVPP2_BM_PHY_RLS_PRIO_EN_MASK BIT(1)
287#define MVPP2_BM_PHY_RLS_GRNTD_MASK BIT(2)
288#define MVPP2_BM_VIRT_RLS_REG 0x64c0
Thomas Petazzonid01524d2017-03-07 16:53:09 +0100289#define MVPP22_BM_ADDR_HIGH_RLS_REG 0x64c4
290#define MVPP22_BM_ADDR_HIGH_PHYS_RLS_MASK 0xff
Antoine Ténart81b66302017-08-22 19:08:21 +0200291#define MVPP22_BM_ADDR_HIGH_VIRT_RLS_MASK 0xff00
Thomas Petazzonid01524d2017-03-07 16:53:09 +0100292#define MVPP22_BM_ADDR_HIGH_VIRT_RLS_SHIFT 8
Marcin Wojtas3f518502014-07-10 16:52:13 -0300293
294/* TX Scheduler registers */
295#define MVPP2_TXP_SCHED_PORT_INDEX_REG 0x8000
296#define MVPP2_TXP_SCHED_Q_CMD_REG 0x8004
297#define MVPP2_TXP_SCHED_ENQ_MASK 0xff
298#define MVPP2_TXP_SCHED_DISQ_OFFSET 8
299#define MVPP2_TXP_SCHED_CMD_1_REG 0x8010
300#define MVPP2_TXP_SCHED_PERIOD_REG 0x8018
301#define MVPP2_TXP_SCHED_MTU_REG 0x801c
302#define MVPP2_TXP_MTU_MAX 0x7FFFF
303#define MVPP2_TXP_SCHED_REFILL_REG 0x8020
304#define MVPP2_TXP_REFILL_TOKENS_ALL_MASK 0x7ffff
305#define MVPP2_TXP_REFILL_PERIOD_ALL_MASK 0x3ff00000
306#define MVPP2_TXP_REFILL_PERIOD_MASK(v) ((v) << 20)
307#define MVPP2_TXP_SCHED_TOKEN_SIZE_REG 0x8024
308#define MVPP2_TXP_TOKEN_SIZE_MAX 0xffffffff
309#define MVPP2_TXQ_SCHED_REFILL_REG(q) (0x8040 + ((q) << 2))
310#define MVPP2_TXQ_REFILL_TOKENS_ALL_MASK 0x7ffff
311#define MVPP2_TXQ_REFILL_PERIOD_ALL_MASK 0x3ff00000
312#define MVPP2_TXQ_REFILL_PERIOD_MASK(v) ((v) << 20)
313#define MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(q) (0x8060 + ((q) << 2))
314#define MVPP2_TXQ_TOKEN_SIZE_MAX 0x7fffffff
315#define MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(q) (0x8080 + ((q) << 2))
316#define MVPP2_TXQ_TOKEN_CNTR_MAX 0xffffffff
317
318/* TX general registers */
319#define MVPP2_TX_SNOOP_REG 0x8800
320#define MVPP2_TX_PORT_FLUSH_REG 0x8810
321#define MVPP2_TX_PORT_FLUSH_MASK(port) (1 << (port))
322
323/* LMS registers */
324#define MVPP2_SRC_ADDR_MIDDLE 0x24
325#define MVPP2_SRC_ADDR_HIGH 0x28
Marcin Wojtas08a23752014-07-21 13:48:12 -0300326#define MVPP2_PHY_AN_CFG0_REG 0x34
327#define MVPP2_PHY_AN_STOP_SMI0_MASK BIT(7)
Marcin Wojtas3f518502014-07-10 16:52:13 -0300328#define MVPP2_MNG_EXTENDED_GLOBAL_CTRL_REG 0x305c
Thomas Petazzoni31d76772017-02-21 11:28:10 +0100329#define MVPP2_EXT_GLOBAL_CTRL_DEFAULT 0x27
Marcin Wojtas3f518502014-07-10 16:52:13 -0300330
331/* Per-port registers */
332#define MVPP2_GMAC_CTRL_0_REG 0x0
Antoine Ténart81b66302017-08-22 19:08:21 +0200333#define MVPP2_GMAC_PORT_EN_MASK BIT(0)
Antoine Ténart39193572017-08-22 19:08:24 +0200334#define MVPP2_GMAC_PORT_TYPE_MASK BIT(1)
Antoine Ténart81b66302017-08-22 19:08:21 +0200335#define MVPP2_GMAC_MAX_RX_SIZE_OFFS 2
336#define MVPP2_GMAC_MAX_RX_SIZE_MASK 0x7ffc
337#define MVPP2_GMAC_MIB_CNTR_EN_MASK BIT(15)
Marcin Wojtas3f518502014-07-10 16:52:13 -0300338#define MVPP2_GMAC_CTRL_1_REG 0x4
Antoine Ténart81b66302017-08-22 19:08:21 +0200339#define MVPP2_GMAC_PERIODIC_XON_EN_MASK BIT(1)
340#define MVPP2_GMAC_GMII_LB_EN_MASK BIT(5)
341#define MVPP2_GMAC_PCS_LB_EN_BIT 6
342#define MVPP2_GMAC_PCS_LB_EN_MASK BIT(6)
343#define MVPP2_GMAC_SA_LOW_OFFS 7
Marcin Wojtas3f518502014-07-10 16:52:13 -0300344#define MVPP2_GMAC_CTRL_2_REG 0x8
Antoine Ténart81b66302017-08-22 19:08:21 +0200345#define MVPP2_GMAC_INBAND_AN_MASK BIT(0)
Antoine Ténart39193572017-08-22 19:08:24 +0200346#define MVPP2_GMAC_FLOW_CTRL_MASK GENMASK(2, 1)
Antoine Ténart81b66302017-08-22 19:08:21 +0200347#define MVPP2_GMAC_PCS_ENABLE_MASK BIT(3)
Antoine Tenartc7dfc8c2017-09-25 14:59:48 +0200348#define MVPP2_GMAC_INTERNAL_CLK_MASK BIT(4)
Antoine Ténart39193572017-08-22 19:08:24 +0200349#define MVPP2_GMAC_DISABLE_PADDING BIT(5)
Antoine Ténart81b66302017-08-22 19:08:21 +0200350#define MVPP2_GMAC_PORT_RESET_MASK BIT(6)
Marcin Wojtas3f518502014-07-10 16:52:13 -0300351#define MVPP2_GMAC_AUTONEG_CONFIG 0xc
Antoine Ténart81b66302017-08-22 19:08:21 +0200352#define MVPP2_GMAC_FORCE_LINK_DOWN BIT(0)
353#define MVPP2_GMAC_FORCE_LINK_PASS BIT(1)
Antoine Ténart39193572017-08-22 19:08:24 +0200354#define MVPP2_GMAC_IN_BAND_AUTONEG BIT(2)
355#define MVPP2_GMAC_IN_BAND_AUTONEG_BYPASS BIT(3)
Antoine Ténart81b66302017-08-22 19:08:21 +0200356#define MVPP2_GMAC_CONFIG_MII_SPEED BIT(5)
357#define MVPP2_GMAC_CONFIG_GMII_SPEED BIT(6)
358#define MVPP2_GMAC_AN_SPEED_EN BIT(7)
359#define MVPP2_GMAC_FC_ADV_EN BIT(9)
Antoine Ténart39193572017-08-22 19:08:24 +0200360#define MVPP2_GMAC_FLOW_CTRL_AUTONEG BIT(11)
Antoine Ténart81b66302017-08-22 19:08:21 +0200361#define MVPP2_GMAC_CONFIG_FULL_DUPLEX BIT(12)
362#define MVPP2_GMAC_AN_DUPLEX_EN BIT(13)
Antoine Tenartfd3651b2017-09-01 11:04:54 +0200363#define MVPP2_GMAC_STATUS0 0x10
364#define MVPP2_GMAC_STATUS0_LINK_UP BIT(0)
Marcin Wojtas3f518502014-07-10 16:52:13 -0300365#define MVPP2_GMAC_PORT_FIFO_CFG_1_REG 0x1c
Antoine Ténart81b66302017-08-22 19:08:21 +0200366#define MVPP2_GMAC_TX_FIFO_MIN_TH_OFFS 6
367#define MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK 0x1fc0
368#define MVPP2_GMAC_TX_FIFO_MIN_TH_MASK(v) (((v) << 6) & \
Marcin Wojtas3f518502014-07-10 16:52:13 -0300369 MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK)
Antoine Tenartfd3651b2017-09-01 11:04:54 +0200370#define MVPP22_GMAC_INT_STAT 0x20
371#define MVPP22_GMAC_INT_STAT_LINK BIT(1)
372#define MVPP22_GMAC_INT_MASK 0x24
373#define MVPP22_GMAC_INT_MASK_LINK_STAT BIT(1)
Thomas Petazzoni26975822017-03-07 16:53:14 +0100374#define MVPP22_GMAC_CTRL_4_REG 0x90
Antoine Ténart81b66302017-08-22 19:08:21 +0200375#define MVPP22_CTRL4_EXT_PIN_GMII_SEL BIT(0)
376#define MVPP22_CTRL4_DP_CLK_SEL BIT(5)
Antoine Ténart1068ec72017-08-22 19:08:22 +0200377#define MVPP22_CTRL4_SYNC_BYPASS_DIS BIT(6)
Antoine Ténart81b66302017-08-22 19:08:21 +0200378#define MVPP22_CTRL4_QSGMII_BYPASS_ACTIVE BIT(7)
Antoine Tenartfd3651b2017-09-01 11:04:54 +0200379#define MVPP22_GMAC_INT_SUM_MASK 0xa4
380#define MVPP22_GMAC_INT_SUM_MASK_LINK_STAT BIT(1)
Thomas Petazzoni26975822017-03-07 16:53:14 +0100381
382/* Per-port XGMAC registers. PPv2.2 only, only for GOP port 0,
383 * relative to port->base.
384 */
Antoine Ténart725757a2017-06-12 16:01:39 +0200385#define MVPP22_XLG_CTRL0_REG 0x100
Antoine Ténart81b66302017-08-22 19:08:21 +0200386#define MVPP22_XLG_CTRL0_PORT_EN BIT(0)
387#define MVPP22_XLG_CTRL0_MAC_RESET_DIS BIT(1)
Antoine Ténart77321952017-08-22 19:08:25 +0200388#define MVPP22_XLG_CTRL0_RX_FLOW_CTRL_EN BIT(7)
Antoine Ténart81b66302017-08-22 19:08:21 +0200389#define MVPP22_XLG_CTRL0_MIB_CNT_DIS BIT(14)
Stefan Chulski76eb1b12017-08-22 19:08:26 +0200390#define MVPP22_XLG_CTRL1_REG 0x104
Antoine Ténartec15ecd2017-08-25 15:24:46 +0200391#define MVPP22_XLG_CTRL1_FRAMESIZELIMIT_OFFS 0
Stefan Chulski76eb1b12017-08-22 19:08:26 +0200392#define MVPP22_XLG_CTRL1_FRAMESIZELIMIT_MASK 0x1fff
Antoine Tenartfd3651b2017-09-01 11:04:54 +0200393#define MVPP22_XLG_STATUS 0x10c
394#define MVPP22_XLG_STATUS_LINK_UP BIT(0)
395#define MVPP22_XLG_INT_STAT 0x114
396#define MVPP22_XLG_INT_STAT_LINK BIT(1)
397#define MVPP22_XLG_INT_MASK 0x118
398#define MVPP22_XLG_INT_MASK_LINK BIT(1)
Thomas Petazzoni26975822017-03-07 16:53:14 +0100399#define MVPP22_XLG_CTRL3_REG 0x11c
Antoine Ténart81b66302017-08-22 19:08:21 +0200400#define MVPP22_XLG_CTRL3_MACMODESELECT_MASK (7 << 13)
401#define MVPP22_XLG_CTRL3_MACMODESELECT_GMAC (0 << 13)
402#define MVPP22_XLG_CTRL3_MACMODESELECT_10G (1 << 13)
Antoine Tenartfd3651b2017-09-01 11:04:54 +0200403#define MVPP22_XLG_EXT_INT_MASK 0x15c
404#define MVPP22_XLG_EXT_INT_MASK_XLG BIT(1)
405#define MVPP22_XLG_EXT_INT_MASK_GIG BIT(2)
Antoine Ténart77321952017-08-22 19:08:25 +0200406#define MVPP22_XLG_CTRL4_REG 0x184
407#define MVPP22_XLG_CTRL4_FWD_FC BIT(5)
408#define MVPP22_XLG_CTRL4_FWD_PFC BIT(6)
409#define MVPP22_XLG_CTRL4_MACMODSELECT_GMAC BIT(12)
410
Thomas Petazzoni26975822017-03-07 16:53:14 +0100411/* SMI registers. PPv2.2 only, relative to priv->iface_base. */
412#define MVPP22_SMI_MISC_CFG_REG 0x1204
Antoine Ténart81b66302017-08-22 19:08:21 +0200413#define MVPP22_SMI_POLLING_EN BIT(10)
Marcin Wojtas3f518502014-07-10 16:52:13 -0300414
Thomas Petazzonia7868412017-03-07 16:53:13 +0100415#define MVPP22_GMAC_BASE(port) (0x7000 + (port) * 0x1000 + 0xe00)
416
Marcin Wojtas3f518502014-07-10 16:52:13 -0300417#define MVPP2_CAUSE_TXQ_SENT_DESC_ALL_MASK 0xff
418
419/* Descriptor ring Macros */
420#define MVPP2_QUEUE_NEXT_DESC(q, index) \
421 (((index) < (q)->last_desc) ? ((index) + 1) : 0)
422
Antoine Ténartf84bf382017-08-22 19:08:27 +0200423/* XPCS registers. PPv2.2 only */
424#define MVPP22_MPCS_BASE(port) (0x7000 + (port) * 0x1000)
425#define MVPP22_MPCS_CTRL 0x14
426#define MVPP22_MPCS_CTRL_FWD_ERR_CONN BIT(10)
427#define MVPP22_MPCS_CLK_RESET 0x14c
428#define MAC_CLK_RESET_SD_TX BIT(0)
429#define MAC_CLK_RESET_SD_RX BIT(1)
430#define MAC_CLK_RESET_MAC BIT(2)
431#define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4)
432#define MVPP22_MPCS_CLK_RESET_DIV_SET BIT(11)
433
434/* XPCS registers. PPv2.2 only */
435#define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000)
436#define MVPP22_XPCS_CFG0 0x0
437#define MVPP22_XPCS_CFG0_PCS_MODE(n) ((n) << 3)
438#define MVPP22_XPCS_CFG0_ACTIVE_LANE(n) ((n) << 5)
439
440/* System controller registers. Accessed through a regmap. */
441#define GENCONF_SOFT_RESET1 0x1108
442#define GENCONF_SOFT_RESET1_GOP BIT(6)
443#define GENCONF_PORT_CTRL0 0x1110
444#define GENCONF_PORT_CTRL0_BUS_WIDTH_SELECT BIT(1)
445#define GENCONF_PORT_CTRL0_RX_DATA_SAMPLE BIT(29)
446#define GENCONF_PORT_CTRL0_CLK_DIV_PHASE_CLR BIT(31)
447#define GENCONF_PORT_CTRL1 0x1114
448#define GENCONF_PORT_CTRL1_EN(p) BIT(p)
449#define GENCONF_PORT_CTRL1_RESET(p) (BIT(p) << 28)
450#define GENCONF_CTRL0 0x1120
451#define GENCONF_CTRL0_PORT0_RGMII BIT(0)
452#define GENCONF_CTRL0_PORT1_RGMII_MII BIT(1)
453#define GENCONF_CTRL0_PORT1_RGMII BIT(2)
454
Marcin Wojtas3f518502014-07-10 16:52:13 -0300455/* Various constants */
456
457/* Coalescing */
Antoine Tenart86162282017-12-11 09:13:29 +0100458#define MVPP2_TXDONE_COAL_PKTS_THRESH 64
Marcin Wojtasedc660f2015-08-06 19:00:30 +0200459#define MVPP2_TXDONE_HRTIMER_PERIOD_NS 1000000UL
Thomas Petazzoni213f4282017-08-03 10:42:00 +0200460#define MVPP2_TXDONE_COAL_USEC 1000
Marcin Wojtas3f518502014-07-10 16:52:13 -0300461#define MVPP2_RX_COAL_PKTS 32
Antoine Tenart86162282017-12-11 09:13:29 +0100462#define MVPP2_RX_COAL_USEC 64
Marcin Wojtas3f518502014-07-10 16:52:13 -0300463
464/* The two bytes Marvell header. Either contains a special value used
465 * by Marvell switches when a specific hardware mode is enabled (not
466 * supported by this driver) or is filled automatically by zeroes on
467 * the RX side. Those two bytes being at the front of the Ethernet
468 * header, they allow to have the IP header aligned on a 4 bytes
469 * boundary automatically: the hardware skips those two bytes on its
470 * own.
471 */
472#define MVPP2_MH_SIZE 2
473#define MVPP2_ETH_TYPE_LEN 2
474#define MVPP2_PPPOE_HDR_SIZE 8
475#define MVPP2_VLAN_TAG_LEN 4
476
477/* Lbtd 802.3 type */
478#define MVPP2_IP_LBDT_TYPE 0xfffa
479
Marcin Wojtas3f518502014-07-10 16:52:13 -0300480#define MVPP2_TX_CSUM_MAX_SIZE 9800
481
482/* Timeout constants */
483#define MVPP2_TX_DISABLE_TIMEOUT_MSEC 1000
484#define MVPP2_TX_PENDING_TIMEOUT_MSEC 1000
485
486#define MVPP2_TX_MTU_MAX 0x7ffff
487
488/* Maximum number of T-CONTs of PON port */
489#define MVPP2_MAX_TCONT 16
490
491/* Maximum number of supported ports */
492#define MVPP2_MAX_PORTS 4
493
494/* Maximum number of TXQs used by single port */
495#define MVPP2_MAX_TXQ 8
496
Antoine Tenart1d17db02017-10-30 11:23:31 +0100497/* MVPP2_MAX_TSO_SEGS is the maximum number of fragments to allow in the GSO
498 * skb. As we need a maxium of two descriptors per fragments (1 header, 1 data),
499 * multiply this value by two to count the maximum number of skb descs needed.
500 */
501#define MVPP2_MAX_TSO_SEGS 300
502#define MVPP2_MAX_SKB_DESCS (MVPP2_MAX_TSO_SEGS * 2 + MAX_SKB_FRAGS)
503
Marcin Wojtas3f518502014-07-10 16:52:13 -0300504/* Dfault number of RXQs in use */
505#define MVPP2_DEFAULT_RXQ 4
506
Marcin Wojtas3f518502014-07-10 16:52:13 -0300507/* Max number of Rx descriptors */
Yan Markman7cf87e42017-12-11 09:13:26 +0100508#define MVPP2_MAX_RXD_MAX 1024
509#define MVPP2_MAX_RXD_DFLT 128
Marcin Wojtas3f518502014-07-10 16:52:13 -0300510
511/* Max number of Tx descriptors */
Yan Markman7cf87e42017-12-11 09:13:26 +0100512#define MVPP2_MAX_TXD_MAX 2048
513#define MVPP2_MAX_TXD_DFLT 1024
Marcin Wojtas3f518502014-07-10 16:52:13 -0300514
515/* Amount of Tx descriptors that can be reserved at once by CPU */
516#define MVPP2_CPU_DESC_CHUNK 64
517
518/* Max number of Tx descriptors in each aggregated queue */
519#define MVPP2_AGGR_TXQ_SIZE 256
520
521/* Descriptor aligned size */
522#define MVPP2_DESC_ALIGNED_SIZE 32
523
524/* Descriptor alignment mask */
525#define MVPP2_TX_DESC_ALIGN (MVPP2_DESC_ALIGNED_SIZE - 1)
526
527/* RX FIFO constants */
Antoine Tenart2d1d7df2017-10-30 11:23:28 +0100528#define MVPP2_RX_FIFO_PORT_DATA_SIZE_32KB 0x8000
529#define MVPP2_RX_FIFO_PORT_DATA_SIZE_8KB 0x2000
530#define MVPP2_RX_FIFO_PORT_DATA_SIZE_4KB 0x1000
531#define MVPP2_RX_FIFO_PORT_ATTR_SIZE_32KB 0x200
532#define MVPP2_RX_FIFO_PORT_ATTR_SIZE_8KB 0x80
533#define MVPP2_RX_FIFO_PORT_ATTR_SIZE_4KB 0x40
534#define MVPP2_RX_FIFO_PORT_MIN_PKT 0x80
Marcin Wojtas3f518502014-07-10 16:52:13 -0300535
Antoine Tenart7c10f972017-10-30 11:23:29 +0100536/* TX FIFO constants */
537#define MVPP22_TX_FIFO_DATA_SIZE_10KB 0xa
538#define MVPP22_TX_FIFO_DATA_SIZE_3KB 0x3
539
Marcin Wojtas3f518502014-07-10 16:52:13 -0300540/* RX buffer constants */
541#define MVPP2_SKB_SHINFO_SIZE \
542 SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
543
544#define MVPP2_RX_PKT_SIZE(mtu) \
545 ALIGN((mtu) + MVPP2_MH_SIZE + MVPP2_VLAN_TAG_LEN + \
Jisheng Zhang4a0a12d2016-04-01 17:11:05 +0800546 ETH_HLEN + ETH_FCS_LEN, cache_line_size())
Marcin Wojtas3f518502014-07-10 16:52:13 -0300547
548#define MVPP2_RX_BUF_SIZE(pkt_size) ((pkt_size) + NET_SKB_PAD)
549#define MVPP2_RX_TOTAL_SIZE(buf_size) ((buf_size) + MVPP2_SKB_SHINFO_SIZE)
550#define MVPP2_RX_MAX_PKT_SIZE(total_size) \
551 ((total_size) - NET_SKB_PAD - MVPP2_SKB_SHINFO_SIZE)
552
553#define MVPP2_BIT_TO_BYTE(bit) ((bit) / 8)
554
555/* IPv6 max L3 address size */
556#define MVPP2_MAX_L3_ADDR_SIZE 16
557
558/* Port flags */
559#define MVPP2_F_LOOPBACK BIT(0)
560
561/* Marvell tag types */
562enum mvpp2_tag_type {
563 MVPP2_TAG_TYPE_NONE = 0,
564 MVPP2_TAG_TYPE_MH = 1,
565 MVPP2_TAG_TYPE_DSA = 2,
566 MVPP2_TAG_TYPE_EDSA = 3,
567 MVPP2_TAG_TYPE_VLAN = 4,
568 MVPP2_TAG_TYPE_LAST = 5
569};
570
571/* Parser constants */
572#define MVPP2_PRS_TCAM_SRAM_SIZE 256
573#define MVPP2_PRS_TCAM_WORDS 6
574#define MVPP2_PRS_SRAM_WORDS 4
575#define MVPP2_PRS_FLOW_ID_SIZE 64
576#define MVPP2_PRS_FLOW_ID_MASK 0x3f
577#define MVPP2_PRS_TCAM_ENTRY_INVALID 1
578#define MVPP2_PRS_TCAM_DSA_TAGGED_BIT BIT(5)
579#define MVPP2_PRS_IPV4_HEAD 0x40
580#define MVPP2_PRS_IPV4_HEAD_MASK 0xf0
581#define MVPP2_PRS_IPV4_MC 0xe0
582#define MVPP2_PRS_IPV4_MC_MASK 0xf0
583#define MVPP2_PRS_IPV4_BC_MASK 0xff
584#define MVPP2_PRS_IPV4_IHL 0x5
585#define MVPP2_PRS_IPV4_IHL_MASK 0xf
586#define MVPP2_PRS_IPV6_MC 0xff
587#define MVPP2_PRS_IPV6_MC_MASK 0xff
588#define MVPP2_PRS_IPV6_HOP_MASK 0xff
589#define MVPP2_PRS_TCAM_PROTO_MASK 0xff
590#define MVPP2_PRS_TCAM_PROTO_MASK_L 0x3f
591#define MVPP2_PRS_DBL_VLANS_MAX 100
592
593/* Tcam structure:
594 * - lookup ID - 4 bits
595 * - port ID - 1 byte
596 * - additional information - 1 byte
597 * - header data - 8 bytes
598 * The fields are represented by MVPP2_PRS_TCAM_DATA_REG(5)->(0).
599 */
600#define MVPP2_PRS_AI_BITS 8
601#define MVPP2_PRS_PORT_MASK 0xff
602#define MVPP2_PRS_LU_MASK 0xf
603#define MVPP2_PRS_TCAM_DATA_BYTE(offs) \
604 (((offs) - ((offs) % 2)) * 2 + ((offs) % 2))
605#define MVPP2_PRS_TCAM_DATA_BYTE_EN(offs) \
606 (((offs) * 2) - ((offs) % 2) + 2)
607#define MVPP2_PRS_TCAM_AI_BYTE 16
608#define MVPP2_PRS_TCAM_PORT_BYTE 17
609#define MVPP2_PRS_TCAM_LU_BYTE 20
610#define MVPP2_PRS_TCAM_EN_OFFS(offs) ((offs) + 2)
611#define MVPP2_PRS_TCAM_INV_WORD 5
612/* Tcam entries ID */
613#define MVPP2_PE_DROP_ALL 0
614#define MVPP2_PE_FIRST_FREE_TID 1
615#define MVPP2_PE_LAST_FREE_TID (MVPP2_PRS_TCAM_SRAM_SIZE - 31)
616#define MVPP2_PE_IP6_EXT_PROTO_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 30)
617#define MVPP2_PE_MAC_MC_IP6 (MVPP2_PRS_TCAM_SRAM_SIZE - 29)
618#define MVPP2_PE_IP6_ADDR_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 28)
619#define MVPP2_PE_IP4_ADDR_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 27)
620#define MVPP2_PE_LAST_DEFAULT_FLOW (MVPP2_PRS_TCAM_SRAM_SIZE - 26)
621#define MVPP2_PE_FIRST_DEFAULT_FLOW (MVPP2_PRS_TCAM_SRAM_SIZE - 19)
622#define MVPP2_PE_EDSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 18)
623#define MVPP2_PE_EDSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 17)
624#define MVPP2_PE_DSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 16)
625#define MVPP2_PE_DSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 15)
626#define MVPP2_PE_ETYPE_EDSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 14)
627#define MVPP2_PE_ETYPE_EDSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 13)
628#define MVPP2_PE_ETYPE_DSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 12)
629#define MVPP2_PE_ETYPE_DSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 11)
630#define MVPP2_PE_MH_DEFAULT (MVPP2_PRS_TCAM_SRAM_SIZE - 10)
631#define MVPP2_PE_DSA_DEFAULT (MVPP2_PRS_TCAM_SRAM_SIZE - 9)
632#define MVPP2_PE_IP6_PROTO_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 8)
633#define MVPP2_PE_IP4_PROTO_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 7)
634#define MVPP2_PE_ETH_TYPE_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 6)
635#define MVPP2_PE_VLAN_DBL (MVPP2_PRS_TCAM_SRAM_SIZE - 5)
636#define MVPP2_PE_VLAN_NONE (MVPP2_PRS_TCAM_SRAM_SIZE - 4)
637#define MVPP2_PE_MAC_MC_ALL (MVPP2_PRS_TCAM_SRAM_SIZE - 3)
638#define MVPP2_PE_MAC_PROMISCUOUS (MVPP2_PRS_TCAM_SRAM_SIZE - 2)
639#define MVPP2_PE_MAC_NON_PROMISCUOUS (MVPP2_PRS_TCAM_SRAM_SIZE - 1)
640
641/* Sram structure
642 * The fields are represented by MVPP2_PRS_TCAM_DATA_REG(3)->(0).
643 */
644#define MVPP2_PRS_SRAM_RI_OFFS 0
645#define MVPP2_PRS_SRAM_RI_WORD 0
646#define MVPP2_PRS_SRAM_RI_CTRL_OFFS 32
647#define MVPP2_PRS_SRAM_RI_CTRL_WORD 1
648#define MVPP2_PRS_SRAM_RI_CTRL_BITS 32
649#define MVPP2_PRS_SRAM_SHIFT_OFFS 64
650#define MVPP2_PRS_SRAM_SHIFT_SIGN_BIT 72
651#define MVPP2_PRS_SRAM_UDF_OFFS 73
652#define MVPP2_PRS_SRAM_UDF_BITS 8
653#define MVPP2_PRS_SRAM_UDF_MASK 0xff
654#define MVPP2_PRS_SRAM_UDF_SIGN_BIT 81
655#define MVPP2_PRS_SRAM_UDF_TYPE_OFFS 82
656#define MVPP2_PRS_SRAM_UDF_TYPE_MASK 0x7
657#define MVPP2_PRS_SRAM_UDF_TYPE_L3 1
658#define MVPP2_PRS_SRAM_UDF_TYPE_L4 4
659#define MVPP2_PRS_SRAM_OP_SEL_SHIFT_OFFS 85
660#define MVPP2_PRS_SRAM_OP_SEL_SHIFT_MASK 0x3
661#define MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD 1
662#define MVPP2_PRS_SRAM_OP_SEL_SHIFT_IP4_ADD 2
663#define MVPP2_PRS_SRAM_OP_SEL_SHIFT_IP6_ADD 3
664#define MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS 87
665#define MVPP2_PRS_SRAM_OP_SEL_UDF_BITS 2
666#define MVPP2_PRS_SRAM_OP_SEL_UDF_MASK 0x3
667#define MVPP2_PRS_SRAM_OP_SEL_UDF_ADD 0
668#define MVPP2_PRS_SRAM_OP_SEL_UDF_IP4_ADD 2
669#define MVPP2_PRS_SRAM_OP_SEL_UDF_IP6_ADD 3
670#define MVPP2_PRS_SRAM_OP_SEL_BASE_OFFS 89
671#define MVPP2_PRS_SRAM_AI_OFFS 90
672#define MVPP2_PRS_SRAM_AI_CTRL_OFFS 98
673#define MVPP2_PRS_SRAM_AI_CTRL_BITS 8
674#define MVPP2_PRS_SRAM_AI_MASK 0xff
675#define MVPP2_PRS_SRAM_NEXT_LU_OFFS 106
676#define MVPP2_PRS_SRAM_NEXT_LU_MASK 0xf
677#define MVPP2_PRS_SRAM_LU_DONE_BIT 110
678#define MVPP2_PRS_SRAM_LU_GEN_BIT 111
679
680/* Sram result info bits assignment */
681#define MVPP2_PRS_RI_MAC_ME_MASK 0x1
682#define MVPP2_PRS_RI_DSA_MASK 0x2
Thomas Petazzoni8138aff2017-02-21 11:28:11 +0100683#define MVPP2_PRS_RI_VLAN_MASK (BIT(2) | BIT(3))
684#define MVPP2_PRS_RI_VLAN_NONE 0x0
Marcin Wojtas3f518502014-07-10 16:52:13 -0300685#define MVPP2_PRS_RI_VLAN_SINGLE BIT(2)
686#define MVPP2_PRS_RI_VLAN_DOUBLE BIT(3)
687#define MVPP2_PRS_RI_VLAN_TRIPLE (BIT(2) | BIT(3))
688#define MVPP2_PRS_RI_CPU_CODE_MASK 0x70
689#define MVPP2_PRS_RI_CPU_CODE_RX_SPEC BIT(4)
Thomas Petazzoni8138aff2017-02-21 11:28:11 +0100690#define MVPP2_PRS_RI_L2_CAST_MASK (BIT(9) | BIT(10))
691#define MVPP2_PRS_RI_L2_UCAST 0x0
Marcin Wojtas3f518502014-07-10 16:52:13 -0300692#define MVPP2_PRS_RI_L2_MCAST BIT(9)
693#define MVPP2_PRS_RI_L2_BCAST BIT(10)
694#define MVPP2_PRS_RI_PPPOE_MASK 0x800
Thomas Petazzoni8138aff2017-02-21 11:28:11 +0100695#define MVPP2_PRS_RI_L3_PROTO_MASK (BIT(12) | BIT(13) | BIT(14))
696#define MVPP2_PRS_RI_L3_UN 0x0
Marcin Wojtas3f518502014-07-10 16:52:13 -0300697#define MVPP2_PRS_RI_L3_IP4 BIT(12)
698#define MVPP2_PRS_RI_L3_IP4_OPT BIT(13)
699#define MVPP2_PRS_RI_L3_IP4_OTHER (BIT(12) | BIT(13))
700#define MVPP2_PRS_RI_L3_IP6 BIT(14)
701#define MVPP2_PRS_RI_L3_IP6_EXT (BIT(12) | BIT(14))
702#define MVPP2_PRS_RI_L3_ARP (BIT(13) | BIT(14))
Thomas Petazzoni8138aff2017-02-21 11:28:11 +0100703#define MVPP2_PRS_RI_L3_ADDR_MASK (BIT(15) | BIT(16))
704#define MVPP2_PRS_RI_L3_UCAST 0x0
Marcin Wojtas3f518502014-07-10 16:52:13 -0300705#define MVPP2_PRS_RI_L3_MCAST BIT(15)
706#define MVPP2_PRS_RI_L3_BCAST (BIT(15) | BIT(16))
707#define MVPP2_PRS_RI_IP_FRAG_MASK 0x20000
Stefan Chulskiaff3da32017-09-25 14:59:46 +0200708#define MVPP2_PRS_RI_IP_FRAG_TRUE BIT(17)
Marcin Wojtas3f518502014-07-10 16:52:13 -0300709#define MVPP2_PRS_RI_UDF3_MASK 0x300000
710#define MVPP2_PRS_RI_UDF3_RX_SPECIAL BIT(21)
711#define MVPP2_PRS_RI_L4_PROTO_MASK 0x1c00000
712#define MVPP2_PRS_RI_L4_TCP BIT(22)
713#define MVPP2_PRS_RI_L4_UDP BIT(23)
714#define MVPP2_PRS_RI_L4_OTHER (BIT(22) | BIT(23))
715#define MVPP2_PRS_RI_UDF7_MASK 0x60000000
716#define MVPP2_PRS_RI_UDF7_IP6_LITE BIT(29)
717#define MVPP2_PRS_RI_DROP_MASK 0x80000000
718
719/* Sram additional info bits assignment */
720#define MVPP2_PRS_IPV4_DIP_AI_BIT BIT(0)
721#define MVPP2_PRS_IPV6_NO_EXT_AI_BIT BIT(0)
722#define MVPP2_PRS_IPV6_EXT_AI_BIT BIT(1)
723#define MVPP2_PRS_IPV6_EXT_AH_AI_BIT BIT(2)
724#define MVPP2_PRS_IPV6_EXT_AH_LEN_AI_BIT BIT(3)
725#define MVPP2_PRS_IPV6_EXT_AH_L4_AI_BIT BIT(4)
726#define MVPP2_PRS_SINGLE_VLAN_AI 0
727#define MVPP2_PRS_DBL_VLAN_AI_BIT BIT(7)
728
729/* DSA/EDSA type */
730#define MVPP2_PRS_TAGGED true
731#define MVPP2_PRS_UNTAGGED false
732#define MVPP2_PRS_EDSA true
733#define MVPP2_PRS_DSA false
734
735/* MAC entries, shadow udf */
736enum mvpp2_prs_udf {
737 MVPP2_PRS_UDF_MAC_DEF,
738 MVPP2_PRS_UDF_MAC_RANGE,
739 MVPP2_PRS_UDF_L2_DEF,
740 MVPP2_PRS_UDF_L2_DEF_COPY,
741 MVPP2_PRS_UDF_L2_USER,
742};
743
744/* Lookup ID */
745enum mvpp2_prs_lookup {
746 MVPP2_PRS_LU_MH,
747 MVPP2_PRS_LU_MAC,
748 MVPP2_PRS_LU_DSA,
749 MVPP2_PRS_LU_VLAN,
750 MVPP2_PRS_LU_L2,
751 MVPP2_PRS_LU_PPPOE,
752 MVPP2_PRS_LU_IP4,
753 MVPP2_PRS_LU_IP6,
754 MVPP2_PRS_LU_FLOWS,
755 MVPP2_PRS_LU_LAST,
756};
757
758/* L3 cast enum */
759enum mvpp2_prs_l3_cast {
760 MVPP2_PRS_L3_UNI_CAST,
761 MVPP2_PRS_L3_MULTI_CAST,
762 MVPP2_PRS_L3_BROAD_CAST
763};
764
765/* Classifier constants */
766#define MVPP2_CLS_FLOWS_TBL_SIZE 512
767#define MVPP2_CLS_FLOWS_TBL_DATA_WORDS 3
768#define MVPP2_CLS_LKP_TBL_SIZE 64
Antoine Tenart1d7d15d2017-10-30 11:23:30 +0100769#define MVPP2_CLS_RX_QUEUES 256
770
771/* RSS constants */
772#define MVPP22_RSS_TABLE_ENTRIES 32
Marcin Wojtas3f518502014-07-10 16:52:13 -0300773
774/* BM constants */
775#define MVPP2_BM_POOLS_NUM 8
776#define MVPP2_BM_LONG_BUF_NUM 1024
777#define MVPP2_BM_SHORT_BUF_NUM 2048
778#define MVPP2_BM_POOL_SIZE_MAX (16*1024 - MVPP2_BM_POOL_PTR_ALIGN/4)
779#define MVPP2_BM_POOL_PTR_ALIGN 128
780#define MVPP2_BM_SWF_LONG_POOL(port) ((port > 2) ? 2 : port)
781#define MVPP2_BM_SWF_SHORT_POOL 3
782
783/* BM cookie (32 bits) definition */
784#define MVPP2_BM_COOKIE_POOL_OFFS 8
785#define MVPP2_BM_COOKIE_CPU_OFFS 24
786
787/* BM short pool packet size
788 * These value assure that for SWF the total number
789 * of bytes allocated for each buffer will be 512
790 */
791#define MVPP2_BM_SHORT_PKT_SIZE MVPP2_RX_MAX_PKT_SIZE(512)
792
Thomas Petazzonia7868412017-03-07 16:53:13 +0100793#define MVPP21_ADDR_SPACE_SZ 0
794#define MVPP22_ADDR_SPACE_SZ SZ_64K
795
Thomas Petazzonidf089aa2017-08-03 10:41:58 +0200796#define MVPP2_MAX_THREADS 8
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +0200797#define MVPP2_MAX_QVECS MVPP2_MAX_THREADS
Thomas Petazzonia7868412017-03-07 16:53:13 +0100798
Marcin Wojtas3f518502014-07-10 16:52:13 -0300799enum mvpp2_bm_type {
800 MVPP2_BM_FREE,
801 MVPP2_BM_SWF_LONG,
802 MVPP2_BM_SWF_SHORT
803};
804
Miquel Raynal118d6292017-11-06 22:56:53 +0100805/* GMAC MIB Counters register definitions */
806#define MVPP21_MIB_COUNTERS_OFFSET 0x1000
807#define MVPP21_MIB_COUNTERS_PORT_SZ 0x400
808#define MVPP22_MIB_COUNTERS_OFFSET 0x0
809#define MVPP22_MIB_COUNTERS_PORT_SZ 0x100
810
811#define MVPP2_MIB_GOOD_OCTETS_RCVD 0x0
812#define MVPP2_MIB_BAD_OCTETS_RCVD 0x8
813#define MVPP2_MIB_CRC_ERRORS_SENT 0xc
814#define MVPP2_MIB_UNICAST_FRAMES_RCVD 0x10
815#define MVPP2_MIB_BROADCAST_FRAMES_RCVD 0x18
816#define MVPP2_MIB_MULTICAST_FRAMES_RCVD 0x1c
817#define MVPP2_MIB_FRAMES_64_OCTETS 0x20
818#define MVPP2_MIB_FRAMES_65_TO_127_OCTETS 0x24
819#define MVPP2_MIB_FRAMES_128_TO_255_OCTETS 0x28
820#define MVPP2_MIB_FRAMES_256_TO_511_OCTETS 0x2c
821#define MVPP2_MIB_FRAMES_512_TO_1023_OCTETS 0x30
822#define MVPP2_MIB_FRAMES_1024_TO_MAX_OCTETS 0x34
823#define MVPP2_MIB_GOOD_OCTETS_SENT 0x38
824#define MVPP2_MIB_UNICAST_FRAMES_SENT 0x40
825#define MVPP2_MIB_MULTICAST_FRAMES_SENT 0x48
826#define MVPP2_MIB_BROADCAST_FRAMES_SENT 0x4c
827#define MVPP2_MIB_FC_SENT 0x54
828#define MVPP2_MIB_FC_RCVD 0x58
829#define MVPP2_MIB_RX_FIFO_OVERRUN 0x5c
830#define MVPP2_MIB_UNDERSIZE_RCVD 0x60
831#define MVPP2_MIB_FRAGMENTS_RCVD 0x64
832#define MVPP2_MIB_OVERSIZE_RCVD 0x68
833#define MVPP2_MIB_JABBER_RCVD 0x6c
834#define MVPP2_MIB_MAC_RCV_ERROR 0x70
835#define MVPP2_MIB_BAD_CRC_EVENT 0x74
836#define MVPP2_MIB_COLLISION 0x78
837#define MVPP2_MIB_LATE_COLLISION 0x7c
838
839#define MVPP2_MIB_COUNTERS_STATS_DELAY (1 * HZ)
840
Marcin Wojtas3f518502014-07-10 16:52:13 -0300841/* Definitions */
842
843/* Shared Packet Processor resources */
844struct mvpp2 {
845 /* Shared registers' base addresses */
Marcin Wojtas3f518502014-07-10 16:52:13 -0300846 void __iomem *lms_base;
Thomas Petazzonia7868412017-03-07 16:53:13 +0100847 void __iomem *iface_base;
848
Thomas Petazzonidf089aa2017-08-03 10:41:58 +0200849 /* On PPv2.2, each "software thread" can access the base
850 * register through a separate address space, each 64 KB apart
851 * from each other. Typically, such address spaces will be
852 * used per CPU.
Thomas Petazzonia7868412017-03-07 16:53:13 +0100853 */
Thomas Petazzonidf089aa2017-08-03 10:41:58 +0200854 void __iomem *swth_base[MVPP2_MAX_THREADS];
Marcin Wojtas3f518502014-07-10 16:52:13 -0300855
Antoine Ténartf84bf382017-08-22 19:08:27 +0200856 /* On PPv2.2, some port control registers are located into the system
857 * controller space. These registers are accessible through a regmap.
858 */
859 struct regmap *sysctrl_base;
860
Marcin Wojtas3f518502014-07-10 16:52:13 -0300861 /* Common clocks */
862 struct clk *pp_clk;
863 struct clk *gop_clk;
Thomas Petazzonifceb55d2017-03-07 16:53:18 +0100864 struct clk *mg_clk;
Gregory CLEMENT4792ea02017-09-29 14:27:39 +0200865 struct clk *axi_clk;
Marcin Wojtas3f518502014-07-10 16:52:13 -0300866
867 /* List of pointers to port structures */
Miquel Raynal118d6292017-11-06 22:56:53 +0100868 int port_count;
Marcin Wojtasbf147152018-01-18 13:31:42 +0100869 struct mvpp2_port *port_list[MVPP2_MAX_PORTS];
Marcin Wojtas3f518502014-07-10 16:52:13 -0300870
871 /* Aggregated TXQs */
872 struct mvpp2_tx_queue *aggr_txqs;
873
874 /* BM pools */
875 struct mvpp2_bm_pool *bm_pools;
876
877 /* PRS shadow table */
878 struct mvpp2_prs_shadow *prs_shadow;
879 /* PRS auxiliary table for double vlan entries control */
880 bool *prs_double_vlans;
881
882 /* Tclk value */
883 u32 tclk;
Thomas Petazzonifaca9242017-03-07 16:53:06 +0100884
885 /* HW version */
886 enum { MVPP21, MVPP22 } hw_version;
Thomas Petazzoni59b9a312017-03-07 16:53:17 +0100887
888 /* Maximum number of RXQs per port */
889 unsigned int max_port_rxqs;
Miquel Raynal118d6292017-11-06 22:56:53 +0100890
Miquel Raynale5c500e2017-11-08 08:59:40 +0100891 /* Workqueue to gather hardware statistics */
Miquel Raynal118d6292017-11-06 22:56:53 +0100892 char queue_name[30];
893 struct workqueue_struct *stats_queue;
Marcin Wojtas3f518502014-07-10 16:52:13 -0300894};
895
896struct mvpp2_pcpu_stats {
897 struct u64_stats_sync syncp;
898 u64 rx_packets;
899 u64 rx_bytes;
900 u64 tx_packets;
901 u64 tx_bytes;
902};
903
Marcin Wojtasedc660f2015-08-06 19:00:30 +0200904/* Per-CPU port control */
905struct mvpp2_port_pcpu {
906 struct hrtimer tx_done_timer;
907 bool timer_scheduled;
908 /* Tasklet for egress finalization */
909 struct tasklet_struct tx_done_tasklet;
910};
911
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +0200912struct mvpp2_queue_vector {
913 int irq;
914 struct napi_struct napi;
915 enum { MVPP2_QUEUE_VECTOR_SHARED, MVPP2_QUEUE_VECTOR_PRIVATE } type;
916 int sw_thread_id;
917 u16 sw_thread_mask;
918 int first_rxq;
919 int nrxqs;
920 u32 pending_cause_rx;
921 struct mvpp2_port *port;
922};
923
Marcin Wojtas3f518502014-07-10 16:52:13 -0300924struct mvpp2_port {
925 u8 id;
926
Thomas Petazzonia7868412017-03-07 16:53:13 +0100927 /* Index of the port from the "group of ports" complex point
928 * of view
929 */
930 int gop_id;
931
Antoine Tenartfd3651b2017-09-01 11:04:54 +0200932 int link_irq;
933
Marcin Wojtas3f518502014-07-10 16:52:13 -0300934 struct mvpp2 *priv;
935
Marcin Wojtas24812222018-01-18 13:31:43 +0100936 /* Firmware node associated to the port */
937 struct fwnode_handle *fwnode;
938
Marcin Wojtas3f518502014-07-10 16:52:13 -0300939 /* Per-port registers' base address */
940 void __iomem *base;
Miquel Raynal118d6292017-11-06 22:56:53 +0100941 void __iomem *stats_base;
Marcin Wojtas3f518502014-07-10 16:52:13 -0300942
943 struct mvpp2_rx_queue **rxqs;
Thomas Petazzoni09f83972017-08-03 10:41:57 +0200944 unsigned int nrxqs;
Marcin Wojtas3f518502014-07-10 16:52:13 -0300945 struct mvpp2_tx_queue **txqs;
Thomas Petazzoni09f83972017-08-03 10:41:57 +0200946 unsigned int ntxqs;
Marcin Wojtas3f518502014-07-10 16:52:13 -0300947 struct net_device *dev;
948
949 int pkt_size;
950
Marcin Wojtasedc660f2015-08-06 19:00:30 +0200951 /* Per-CPU port control */
952 struct mvpp2_port_pcpu __percpu *pcpu;
953
Marcin Wojtas3f518502014-07-10 16:52:13 -0300954 /* Flags */
955 unsigned long flags;
956
957 u16 tx_ring_size;
958 u16 rx_ring_size;
959 struct mvpp2_pcpu_stats __percpu *stats;
Miquel Raynal118d6292017-11-06 22:56:53 +0100960 u64 *ethtool_stats;
Marcin Wojtas3f518502014-07-10 16:52:13 -0300961
Miquel Raynale5c500e2017-11-08 08:59:40 +0100962 /* Per-port work and its lock to gather hardware statistics */
963 struct mutex gather_stats_lock;
964 struct delayed_work stats_work;
965
Marcin Wojtas3f518502014-07-10 16:52:13 -0300966 phy_interface_t phy_interface;
967 struct device_node *phy_node;
Antoine Tenart542897d2017-08-30 10:29:15 +0200968 struct phy *comphy;
Marcin Wojtas3f518502014-07-10 16:52:13 -0300969 unsigned int link;
970 unsigned int duplex;
971 unsigned int speed;
972
973 struct mvpp2_bm_pool *pool_long;
974 struct mvpp2_bm_pool *pool_short;
975
976 /* Index of first port's physical RXQ */
977 u8 first_rxq;
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +0200978
979 struct mvpp2_queue_vector qvecs[MVPP2_MAX_QVECS];
980 unsigned int nqvecs;
Thomas Petazzoni213f4282017-08-03 10:42:00 +0200981 bool has_tx_irqs;
982
983 u32 tx_time_coal;
Marcin Wojtas3f518502014-07-10 16:52:13 -0300984};
985
986/* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the
987 * layout of the transmit and reception DMA descriptors, and their
988 * layout is therefore defined by the hardware design
989 */
990
991#define MVPP2_TXD_L3_OFF_SHIFT 0
992#define MVPP2_TXD_IP_HLEN_SHIFT 8
993#define MVPP2_TXD_L4_CSUM_FRAG BIT(13)
994#define MVPP2_TXD_L4_CSUM_NOT BIT(14)
995#define MVPP2_TXD_IP_CSUM_DISABLE BIT(15)
996#define MVPP2_TXD_PADDING_DISABLE BIT(23)
997#define MVPP2_TXD_L4_UDP BIT(24)
998#define MVPP2_TXD_L3_IP6 BIT(26)
999#define MVPP2_TXD_L_DESC BIT(28)
1000#define MVPP2_TXD_F_DESC BIT(29)
1001
1002#define MVPP2_RXD_ERR_SUMMARY BIT(15)
1003#define MVPP2_RXD_ERR_CODE_MASK (BIT(13) | BIT(14))
1004#define MVPP2_RXD_ERR_CRC 0x0
1005#define MVPP2_RXD_ERR_OVERRUN BIT(13)
1006#define MVPP2_RXD_ERR_RESOURCE (BIT(13) | BIT(14))
1007#define MVPP2_RXD_BM_POOL_ID_OFFS 16
1008#define MVPP2_RXD_BM_POOL_ID_MASK (BIT(16) | BIT(17) | BIT(18))
1009#define MVPP2_RXD_HWF_SYNC BIT(21)
1010#define MVPP2_RXD_L4_CSUM_OK BIT(22)
1011#define MVPP2_RXD_IP4_HEADER_ERR BIT(24)
1012#define MVPP2_RXD_L4_TCP BIT(25)
1013#define MVPP2_RXD_L4_UDP BIT(26)
1014#define MVPP2_RXD_L3_IP4 BIT(28)
1015#define MVPP2_RXD_L3_IP6 BIT(30)
1016#define MVPP2_RXD_BUF_HDR BIT(31)
1017
Thomas Petazzoni054f6372017-03-07 16:53:07 +01001018/* HW TX descriptor for PPv2.1 */
1019struct mvpp21_tx_desc {
Marcin Wojtas3f518502014-07-10 16:52:13 -03001020 u32 command; /* Options used by HW for packet transmitting.*/
1021 u8 packet_offset; /* the offset from the buffer beginning */
1022 u8 phys_txq; /* destination queue ID */
1023 u16 data_size; /* data size of transmitted packet in bytes */
Thomas Petazzoni20396132017-03-07 16:53:00 +01001024 u32 buf_dma_addr; /* physical addr of transmitted buffer */
Marcin Wojtas3f518502014-07-10 16:52:13 -03001025 u32 buf_cookie; /* cookie for access to TX buffer in tx path */
1026 u32 reserved1[3]; /* hw_cmd (for future use, BM, PON, PNC) */
1027 u32 reserved2; /* reserved (for future use) */
1028};
1029
Thomas Petazzoni054f6372017-03-07 16:53:07 +01001030/* HW RX descriptor for PPv2.1 */
1031struct mvpp21_rx_desc {
Marcin Wojtas3f518502014-07-10 16:52:13 -03001032 u32 status; /* info about received packet */
1033 u16 reserved1; /* parser_info (for future use, PnC) */
1034 u16 data_size; /* size of received packet in bytes */
Thomas Petazzoni20396132017-03-07 16:53:00 +01001035 u32 buf_dma_addr; /* physical address of the buffer */
Marcin Wojtas3f518502014-07-10 16:52:13 -03001036 u32 buf_cookie; /* cookie for access to RX buffer in rx path */
1037 u16 reserved2; /* gem_port_id (for future use, PON) */
1038 u16 reserved3; /* csum_l4 (for future use, PnC) */
1039 u8 reserved4; /* bm_qset (for future use, BM) */
1040 u8 reserved5;
1041 u16 reserved6; /* classify_info (for future use, PnC) */
1042 u32 reserved7; /* flow_id (for future use, PnC) */
1043 u32 reserved8;
1044};
1045
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001046/* HW TX descriptor for PPv2.2 */
1047struct mvpp22_tx_desc {
1048 u32 command;
1049 u8 packet_offset;
1050 u8 phys_txq;
1051 u16 data_size;
1052 u64 reserved1;
1053 u64 buf_dma_addr_ptp;
1054 u64 buf_cookie_misc;
1055};
1056
1057/* HW RX descriptor for PPv2.2 */
1058struct mvpp22_rx_desc {
1059 u32 status;
1060 u16 reserved1;
1061 u16 data_size;
1062 u32 reserved2;
1063 u32 reserved3;
1064 u64 buf_dma_addr_key_hash;
1065 u64 buf_cookie_misc;
1066};
1067
Thomas Petazzoni054f6372017-03-07 16:53:07 +01001068/* Opaque type used by the driver to manipulate the HW TX and RX
1069 * descriptors
1070 */
1071struct mvpp2_tx_desc {
1072 union {
1073 struct mvpp21_tx_desc pp21;
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001074 struct mvpp22_tx_desc pp22;
Thomas Petazzoni054f6372017-03-07 16:53:07 +01001075 };
1076};
1077
1078struct mvpp2_rx_desc {
1079 union {
1080 struct mvpp21_rx_desc pp21;
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001081 struct mvpp22_rx_desc pp22;
Thomas Petazzoni054f6372017-03-07 16:53:07 +01001082 };
1083};
1084
Thomas Petazzoni83544912016-12-21 11:28:49 +01001085struct mvpp2_txq_pcpu_buf {
1086 /* Transmitted SKB */
1087 struct sk_buff *skb;
1088
1089 /* Physical address of transmitted buffer */
Thomas Petazzoni20396132017-03-07 16:53:00 +01001090 dma_addr_t dma;
Thomas Petazzoni83544912016-12-21 11:28:49 +01001091
1092 /* Size transmitted */
1093 size_t size;
1094};
1095
Marcin Wojtas3f518502014-07-10 16:52:13 -03001096/* Per-CPU Tx queue control */
1097struct mvpp2_txq_pcpu {
1098 int cpu;
1099
1100 /* Number of Tx DMA descriptors in the descriptor ring */
1101 int size;
1102
1103 /* Number of currently used Tx DMA descriptor in the
1104 * descriptor ring
1105 */
1106 int count;
1107
Antoine Tenart1d17db02017-10-30 11:23:31 +01001108 int wake_threshold;
1109 int stop_threshold;
1110
Marcin Wojtas3f518502014-07-10 16:52:13 -03001111 /* Number of Tx DMA descriptors reserved for each CPU */
1112 int reserved_num;
1113
Thomas Petazzoni83544912016-12-21 11:28:49 +01001114 /* Infos about transmitted buffers */
1115 struct mvpp2_txq_pcpu_buf *buffs;
Marcin Wojtas71ce3912015-08-06 19:00:29 +02001116
Marcin Wojtas3f518502014-07-10 16:52:13 -03001117 /* Index of last TX DMA descriptor that was inserted */
1118 int txq_put_index;
1119
1120 /* Index of the TX DMA descriptor to be cleaned up */
1121 int txq_get_index;
Antoine Ténart186cd4d2017-08-23 09:46:56 +02001122
1123 /* DMA buffer for TSO headers */
1124 char *tso_headers;
1125 dma_addr_t tso_headers_dma;
Marcin Wojtas3f518502014-07-10 16:52:13 -03001126};
1127
1128struct mvpp2_tx_queue {
1129 /* Physical number of this Tx queue */
1130 u8 id;
1131
1132 /* Logical number of this Tx queue */
1133 u8 log_id;
1134
1135 /* Number of Tx DMA descriptors in the descriptor ring */
1136 int size;
1137
1138 /* Number of currently used Tx DMA descriptor in the descriptor ring */
1139 int count;
1140
1141 /* Per-CPU control of physical Tx queues */
1142 struct mvpp2_txq_pcpu __percpu *pcpu;
1143
Marcin Wojtas3f518502014-07-10 16:52:13 -03001144 u32 done_pkts_coal;
1145
1146 /* Virtual address of thex Tx DMA descriptors array */
1147 struct mvpp2_tx_desc *descs;
1148
1149 /* DMA address of the Tx DMA descriptors array */
Thomas Petazzoni20396132017-03-07 16:53:00 +01001150 dma_addr_t descs_dma;
Marcin Wojtas3f518502014-07-10 16:52:13 -03001151
1152 /* Index of the last Tx DMA descriptor */
1153 int last_desc;
1154
1155 /* Index of the next Tx DMA descriptor to process */
1156 int next_desc_to_proc;
1157};
1158
1159struct mvpp2_rx_queue {
1160 /* RX queue number, in the range 0-31 for physical RXQs */
1161 u8 id;
1162
1163 /* Num of rx descriptors in the rx descriptor ring */
1164 int size;
1165
1166 u32 pkts_coal;
1167 u32 time_coal;
1168
1169 /* Virtual address of the RX DMA descriptors array */
1170 struct mvpp2_rx_desc *descs;
1171
1172 /* DMA address of the RX DMA descriptors array */
Thomas Petazzoni20396132017-03-07 16:53:00 +01001173 dma_addr_t descs_dma;
Marcin Wojtas3f518502014-07-10 16:52:13 -03001174
1175 /* Index of the last RX DMA descriptor */
1176 int last_desc;
1177
1178 /* Index of the next RX DMA descriptor to process */
1179 int next_desc_to_proc;
1180
1181 /* ID of port to which physical RXQ is mapped */
1182 int port;
1183
1184 /* Port's logic RXQ number to which physical RXQ is mapped */
1185 int logic_rxq;
1186};
1187
1188union mvpp2_prs_tcam_entry {
1189 u32 word[MVPP2_PRS_TCAM_WORDS];
1190 u8 byte[MVPP2_PRS_TCAM_WORDS * 4];
1191};
1192
1193union mvpp2_prs_sram_entry {
1194 u32 word[MVPP2_PRS_SRAM_WORDS];
1195 u8 byte[MVPP2_PRS_SRAM_WORDS * 4];
1196};
1197
1198struct mvpp2_prs_entry {
1199 u32 index;
1200 union mvpp2_prs_tcam_entry tcam;
1201 union mvpp2_prs_sram_entry sram;
1202};
1203
1204struct mvpp2_prs_shadow {
1205 bool valid;
1206 bool finish;
1207
1208 /* Lookup ID */
1209 int lu;
1210
1211 /* User defined offset */
1212 int udf;
1213
1214 /* Result info */
1215 u32 ri;
1216 u32 ri_mask;
1217};
1218
1219struct mvpp2_cls_flow_entry {
1220 u32 index;
1221 u32 data[MVPP2_CLS_FLOWS_TBL_DATA_WORDS];
1222};
1223
1224struct mvpp2_cls_lookup_entry {
1225 u32 lkpid;
1226 u32 way;
1227 u32 data;
1228};
1229
1230struct mvpp2_bm_pool {
1231 /* Pool number in the range 0-7 */
1232 int id;
1233 enum mvpp2_bm_type type;
1234
1235 /* Buffer Pointers Pool External (BPPE) size */
1236 int size;
Thomas Petazzonid01524d2017-03-07 16:53:09 +01001237 /* BPPE size in bytes */
1238 int size_bytes;
Marcin Wojtas3f518502014-07-10 16:52:13 -03001239 /* Number of buffers for this pool */
1240 int buf_num;
1241 /* Pool buffer size */
1242 int buf_size;
1243 /* Packet size */
1244 int pkt_size;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01001245 int frag_size;
Marcin Wojtas3f518502014-07-10 16:52:13 -03001246
1247 /* BPPE virtual base address */
1248 u32 *virt_addr;
Thomas Petazzoni20396132017-03-07 16:53:00 +01001249 /* BPPE DMA base address */
1250 dma_addr_t dma_addr;
Marcin Wojtas3f518502014-07-10 16:52:13 -03001251
1252 /* Ports using BM pool */
1253 u32 port_map;
Marcin Wojtas3f518502014-07-10 16:52:13 -03001254};
1255
Antoine Tenart20920262017-10-23 15:24:30 +02001256#define IS_TSO_HEADER(txq_pcpu, addr) \
1257 ((addr) >= (txq_pcpu)->tso_headers_dma && \
1258 (addr) < (txq_pcpu)->tso_headers_dma + \
1259 (txq_pcpu)->size * TSO_HEADER_SIZE)
1260
Thomas Petazzoni213f4282017-08-03 10:42:00 +02001261/* Queue modes */
1262#define MVPP2_QDIST_SINGLE_MODE 0
1263#define MVPP2_QDIST_MULTI_MODE 1
1264
1265static int queue_mode = MVPP2_QDIST_SINGLE_MODE;
1266
1267module_param(queue_mode, int, 0444);
1268MODULE_PARM_DESC(queue_mode, "Set queue_mode (single=0, multi=1)");
1269
Marcin Wojtas3f518502014-07-10 16:52:13 -03001270#define MVPP2_DRIVER_NAME "mvpp2"
1271#define MVPP2_DRIVER_VERSION "1.0"
1272
1273/* Utility/helper methods */
1274
1275static void mvpp2_write(struct mvpp2 *priv, u32 offset, u32 data)
1276{
Thomas Petazzonidf089aa2017-08-03 10:41:58 +02001277 writel(data, priv->swth_base[0] + offset);
Marcin Wojtas3f518502014-07-10 16:52:13 -03001278}
1279
1280static u32 mvpp2_read(struct mvpp2 *priv, u32 offset)
1281{
Thomas Petazzonidf089aa2017-08-03 10:41:58 +02001282 return readl(priv->swth_base[0] + offset);
Thomas Petazzonia7868412017-03-07 16:53:13 +01001283}
1284
1285/* These accessors should be used to access:
1286 *
1287 * - per-CPU registers, where each CPU has its own copy of the
1288 * register.
1289 *
1290 * MVPP2_BM_VIRT_ALLOC_REG
1291 * MVPP2_BM_ADDR_HIGH_ALLOC
1292 * MVPP22_BM_ADDR_HIGH_RLS_REG
1293 * MVPP2_BM_VIRT_RLS_REG
1294 * MVPP2_ISR_RX_TX_CAUSE_REG
1295 * MVPP2_ISR_RX_TX_MASK_REG
1296 * MVPP2_TXQ_NUM_REG
1297 * MVPP2_AGGR_TXQ_UPDATE_REG
1298 * MVPP2_TXQ_RSVD_REQ_REG
1299 * MVPP2_TXQ_RSVD_RSLT_REG
1300 * MVPP2_TXQ_SENT_REG
1301 * MVPP2_RXQ_NUM_REG
1302 *
1303 * - global registers that must be accessed through a specific CPU
1304 * window, because they are related to an access to a per-CPU
1305 * register
1306 *
1307 * MVPP2_BM_PHY_ALLOC_REG (related to MVPP2_BM_VIRT_ALLOC_REG)
1308 * MVPP2_BM_PHY_RLS_REG (related to MVPP2_BM_VIRT_RLS_REG)
1309 * MVPP2_RXQ_THRESH_REG (related to MVPP2_RXQ_NUM_REG)
1310 * MVPP2_RXQ_DESC_ADDR_REG (related to MVPP2_RXQ_NUM_REG)
1311 * MVPP2_RXQ_DESC_SIZE_REG (related to MVPP2_RXQ_NUM_REG)
1312 * MVPP2_RXQ_INDEX_REG (related to MVPP2_RXQ_NUM_REG)
1313 * MVPP2_TXQ_PENDING_REG (related to MVPP2_TXQ_NUM_REG)
1314 * MVPP2_TXQ_DESC_ADDR_REG (related to MVPP2_TXQ_NUM_REG)
1315 * MVPP2_TXQ_DESC_SIZE_REG (related to MVPP2_TXQ_NUM_REG)
1316 * MVPP2_TXQ_INDEX_REG (related to MVPP2_TXQ_NUM_REG)
1317 * MVPP2_TXQ_PENDING_REG (related to MVPP2_TXQ_NUM_REG)
1318 * MVPP2_TXQ_PREF_BUF_REG (related to MVPP2_TXQ_NUM_REG)
1319 * MVPP2_TXQ_PREF_BUF_REG (related to MVPP2_TXQ_NUM_REG)
1320 */
1321static void mvpp2_percpu_write(struct mvpp2 *priv, int cpu,
1322 u32 offset, u32 data)
1323{
Thomas Petazzonidf089aa2017-08-03 10:41:58 +02001324 writel(data, priv->swth_base[cpu] + offset);
Thomas Petazzonia7868412017-03-07 16:53:13 +01001325}
1326
1327static u32 mvpp2_percpu_read(struct mvpp2 *priv, int cpu,
1328 u32 offset)
1329{
Thomas Petazzonidf089aa2017-08-03 10:41:58 +02001330 return readl(priv->swth_base[cpu] + offset);
Marcin Wojtas3f518502014-07-10 16:52:13 -03001331}
1332
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001333static dma_addr_t mvpp2_txdesc_dma_addr_get(struct mvpp2_port *port,
1334 struct mvpp2_tx_desc *tx_desc)
1335{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001336 if (port->priv->hw_version == MVPP21)
1337 return tx_desc->pp21.buf_dma_addr;
1338 else
1339 return tx_desc->pp22.buf_dma_addr_ptp & GENMASK_ULL(40, 0);
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001340}
1341
1342static void mvpp2_txdesc_dma_addr_set(struct mvpp2_port *port,
1343 struct mvpp2_tx_desc *tx_desc,
1344 dma_addr_t dma_addr)
1345{
Antoine Tenart6eb5d372017-10-30 11:23:33 +01001346 dma_addr_t addr, offset;
1347
1348 addr = dma_addr & ~MVPP2_TX_DESC_ALIGN;
1349 offset = dma_addr & MVPP2_TX_DESC_ALIGN;
1350
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001351 if (port->priv->hw_version == MVPP21) {
Antoine Tenart6eb5d372017-10-30 11:23:33 +01001352 tx_desc->pp21.buf_dma_addr = addr;
1353 tx_desc->pp21.packet_offset = offset;
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001354 } else {
Antoine Tenart6eb5d372017-10-30 11:23:33 +01001355 u64 val = (u64)addr;
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001356
1357 tx_desc->pp22.buf_dma_addr_ptp &= ~GENMASK_ULL(40, 0);
1358 tx_desc->pp22.buf_dma_addr_ptp |= val;
Antoine Tenart6eb5d372017-10-30 11:23:33 +01001359 tx_desc->pp22.packet_offset = offset;
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001360 }
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001361}
1362
1363static size_t mvpp2_txdesc_size_get(struct mvpp2_port *port,
1364 struct mvpp2_tx_desc *tx_desc)
1365{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001366 if (port->priv->hw_version == MVPP21)
1367 return tx_desc->pp21.data_size;
1368 else
1369 return tx_desc->pp22.data_size;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001370}
1371
1372static void mvpp2_txdesc_size_set(struct mvpp2_port *port,
1373 struct mvpp2_tx_desc *tx_desc,
1374 size_t size)
1375{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001376 if (port->priv->hw_version == MVPP21)
1377 tx_desc->pp21.data_size = size;
1378 else
1379 tx_desc->pp22.data_size = size;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001380}
1381
1382static void mvpp2_txdesc_txq_set(struct mvpp2_port *port,
1383 struct mvpp2_tx_desc *tx_desc,
1384 unsigned int txq)
1385{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001386 if (port->priv->hw_version == MVPP21)
1387 tx_desc->pp21.phys_txq = txq;
1388 else
1389 tx_desc->pp22.phys_txq = txq;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001390}
1391
1392static void mvpp2_txdesc_cmd_set(struct mvpp2_port *port,
1393 struct mvpp2_tx_desc *tx_desc,
1394 unsigned int command)
1395{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001396 if (port->priv->hw_version == MVPP21)
1397 tx_desc->pp21.command = command;
1398 else
1399 tx_desc->pp22.command = command;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001400}
1401
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001402static unsigned int mvpp2_txdesc_offset_get(struct mvpp2_port *port,
1403 struct mvpp2_tx_desc *tx_desc)
1404{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001405 if (port->priv->hw_version == MVPP21)
1406 return tx_desc->pp21.packet_offset;
1407 else
1408 return tx_desc->pp22.packet_offset;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001409}
1410
1411static dma_addr_t mvpp2_rxdesc_dma_addr_get(struct mvpp2_port *port,
1412 struct mvpp2_rx_desc *rx_desc)
1413{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001414 if (port->priv->hw_version == MVPP21)
1415 return rx_desc->pp21.buf_dma_addr;
1416 else
1417 return rx_desc->pp22.buf_dma_addr_key_hash & GENMASK_ULL(40, 0);
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001418}
1419
1420static unsigned long mvpp2_rxdesc_cookie_get(struct mvpp2_port *port,
1421 struct mvpp2_rx_desc *rx_desc)
1422{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001423 if (port->priv->hw_version == MVPP21)
1424 return rx_desc->pp21.buf_cookie;
1425 else
1426 return rx_desc->pp22.buf_cookie_misc & GENMASK_ULL(40, 0);
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001427}
1428
1429static size_t mvpp2_rxdesc_size_get(struct mvpp2_port *port,
1430 struct mvpp2_rx_desc *rx_desc)
1431{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001432 if (port->priv->hw_version == MVPP21)
1433 return rx_desc->pp21.data_size;
1434 else
1435 return rx_desc->pp22.data_size;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001436}
1437
1438static u32 mvpp2_rxdesc_status_get(struct mvpp2_port *port,
1439 struct mvpp2_rx_desc *rx_desc)
1440{
Thomas Petazzonie7c53592017-03-07 16:53:08 +01001441 if (port->priv->hw_version == MVPP21)
1442 return rx_desc->pp21.status;
1443 else
1444 return rx_desc->pp22.status;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001445}
1446
Marcin Wojtas3f518502014-07-10 16:52:13 -03001447static void mvpp2_txq_inc_get(struct mvpp2_txq_pcpu *txq_pcpu)
1448{
1449 txq_pcpu->txq_get_index++;
1450 if (txq_pcpu->txq_get_index == txq_pcpu->size)
1451 txq_pcpu->txq_get_index = 0;
1452}
1453
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001454static void mvpp2_txq_inc_put(struct mvpp2_port *port,
1455 struct mvpp2_txq_pcpu *txq_pcpu,
Marcin Wojtas71ce3912015-08-06 19:00:29 +02001456 struct sk_buff *skb,
1457 struct mvpp2_tx_desc *tx_desc)
Marcin Wojtas3f518502014-07-10 16:52:13 -03001458{
Thomas Petazzoni83544912016-12-21 11:28:49 +01001459 struct mvpp2_txq_pcpu_buf *tx_buf =
1460 txq_pcpu->buffs + txq_pcpu->txq_put_index;
1461 tx_buf->skb = skb;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01001462 tx_buf->size = mvpp2_txdesc_size_get(port, tx_desc);
1463 tx_buf->dma = mvpp2_txdesc_dma_addr_get(port, tx_desc) +
1464 mvpp2_txdesc_offset_get(port, tx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03001465 txq_pcpu->txq_put_index++;
1466 if (txq_pcpu->txq_put_index == txq_pcpu->size)
1467 txq_pcpu->txq_put_index = 0;
1468}
1469
1470/* Get number of physical egress port */
1471static inline int mvpp2_egress_port(struct mvpp2_port *port)
1472{
1473 return MVPP2_MAX_TCONT + port->id;
1474}
1475
1476/* Get number of physical TXQ */
1477static inline int mvpp2_txq_phys(int port, int txq)
1478{
1479 return (MVPP2_MAX_TCONT + port) * MVPP2_MAX_TXQ + txq;
1480}
1481
1482/* Parser configuration routines */
1483
1484/* Update parser tcam and sram hw entries */
1485static int mvpp2_prs_hw_write(struct mvpp2 *priv, struct mvpp2_prs_entry *pe)
1486{
1487 int i;
1488
1489 if (pe->index > MVPP2_PRS_TCAM_SRAM_SIZE - 1)
1490 return -EINVAL;
1491
1492 /* Clear entry invalidation bit */
1493 pe->tcam.word[MVPP2_PRS_TCAM_INV_WORD] &= ~MVPP2_PRS_TCAM_INV_MASK;
1494
1495 /* Write tcam index - indirect access */
1496 mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, pe->index);
1497 for (i = 0; i < MVPP2_PRS_TCAM_WORDS; i++)
1498 mvpp2_write(priv, MVPP2_PRS_TCAM_DATA_REG(i), pe->tcam.word[i]);
1499
1500 /* Write sram index - indirect access */
1501 mvpp2_write(priv, MVPP2_PRS_SRAM_IDX_REG, pe->index);
1502 for (i = 0; i < MVPP2_PRS_SRAM_WORDS; i++)
1503 mvpp2_write(priv, MVPP2_PRS_SRAM_DATA_REG(i), pe->sram.word[i]);
1504
1505 return 0;
1506}
1507
1508/* Read tcam entry from hw */
1509static int mvpp2_prs_hw_read(struct mvpp2 *priv, struct mvpp2_prs_entry *pe)
1510{
1511 int i;
1512
1513 if (pe->index > MVPP2_PRS_TCAM_SRAM_SIZE - 1)
1514 return -EINVAL;
1515
1516 /* Write tcam index - indirect access */
1517 mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, pe->index);
1518
1519 pe->tcam.word[MVPP2_PRS_TCAM_INV_WORD] = mvpp2_read(priv,
1520 MVPP2_PRS_TCAM_DATA_REG(MVPP2_PRS_TCAM_INV_WORD));
1521 if (pe->tcam.word[MVPP2_PRS_TCAM_INV_WORD] & MVPP2_PRS_TCAM_INV_MASK)
1522 return MVPP2_PRS_TCAM_ENTRY_INVALID;
1523
1524 for (i = 0; i < MVPP2_PRS_TCAM_WORDS; i++)
1525 pe->tcam.word[i] = mvpp2_read(priv, MVPP2_PRS_TCAM_DATA_REG(i));
1526
1527 /* Write sram index - indirect access */
1528 mvpp2_write(priv, MVPP2_PRS_SRAM_IDX_REG, pe->index);
1529 for (i = 0; i < MVPP2_PRS_SRAM_WORDS; i++)
1530 pe->sram.word[i] = mvpp2_read(priv, MVPP2_PRS_SRAM_DATA_REG(i));
1531
1532 return 0;
1533}
1534
1535/* Invalidate tcam hw entry */
1536static void mvpp2_prs_hw_inv(struct mvpp2 *priv, int index)
1537{
1538 /* Write index - indirect access */
1539 mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, index);
1540 mvpp2_write(priv, MVPP2_PRS_TCAM_DATA_REG(MVPP2_PRS_TCAM_INV_WORD),
1541 MVPP2_PRS_TCAM_INV_MASK);
1542}
1543
1544/* Enable shadow table entry and set its lookup ID */
1545static void mvpp2_prs_shadow_set(struct mvpp2 *priv, int index, int lu)
1546{
1547 priv->prs_shadow[index].valid = true;
1548 priv->prs_shadow[index].lu = lu;
1549}
1550
1551/* Update ri fields in shadow table entry */
1552static void mvpp2_prs_shadow_ri_set(struct mvpp2 *priv, int index,
1553 unsigned int ri, unsigned int ri_mask)
1554{
1555 priv->prs_shadow[index].ri_mask = ri_mask;
1556 priv->prs_shadow[index].ri = ri;
1557}
1558
1559/* Update lookup field in tcam sw entry */
1560static void mvpp2_prs_tcam_lu_set(struct mvpp2_prs_entry *pe, unsigned int lu)
1561{
1562 int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_LU_BYTE);
1563
1564 pe->tcam.byte[MVPP2_PRS_TCAM_LU_BYTE] = lu;
1565 pe->tcam.byte[enable_off] = MVPP2_PRS_LU_MASK;
1566}
1567
1568/* Update mask for single port in tcam sw entry */
1569static void mvpp2_prs_tcam_port_set(struct mvpp2_prs_entry *pe,
1570 unsigned int port, bool add)
1571{
1572 int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_PORT_BYTE);
1573
1574 if (add)
1575 pe->tcam.byte[enable_off] &= ~(1 << port);
1576 else
1577 pe->tcam.byte[enable_off] |= 1 << port;
1578}
1579
1580/* Update port map in tcam sw entry */
1581static void mvpp2_prs_tcam_port_map_set(struct mvpp2_prs_entry *pe,
1582 unsigned int ports)
1583{
1584 unsigned char port_mask = MVPP2_PRS_PORT_MASK;
1585 int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_PORT_BYTE);
1586
1587 pe->tcam.byte[MVPP2_PRS_TCAM_PORT_BYTE] = 0;
1588 pe->tcam.byte[enable_off] &= ~port_mask;
1589 pe->tcam.byte[enable_off] |= ~ports & MVPP2_PRS_PORT_MASK;
1590}
1591
1592/* Obtain port map from tcam sw entry */
1593static unsigned int mvpp2_prs_tcam_port_map_get(struct mvpp2_prs_entry *pe)
1594{
1595 int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_PORT_BYTE);
1596
1597 return ~(pe->tcam.byte[enable_off]) & MVPP2_PRS_PORT_MASK;
1598}
1599
1600/* Set byte of data and its enable bits in tcam sw entry */
1601static void mvpp2_prs_tcam_data_byte_set(struct mvpp2_prs_entry *pe,
1602 unsigned int offs, unsigned char byte,
1603 unsigned char enable)
1604{
1605 pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE(offs)] = byte;
1606 pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE_EN(offs)] = enable;
1607}
1608
1609/* Get byte of data and its enable bits from tcam sw entry */
1610static void mvpp2_prs_tcam_data_byte_get(struct mvpp2_prs_entry *pe,
1611 unsigned int offs, unsigned char *byte,
1612 unsigned char *enable)
1613{
1614 *byte = pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE(offs)];
1615 *enable = pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE_EN(offs)];
1616}
1617
1618/* Compare tcam data bytes with a pattern */
1619static bool mvpp2_prs_tcam_data_cmp(struct mvpp2_prs_entry *pe, int offs,
1620 u16 data)
1621{
1622 int off = MVPP2_PRS_TCAM_DATA_BYTE(offs);
1623 u16 tcam_data;
1624
Antoine Tenartef4816f2017-10-24 11:41:26 +02001625 tcam_data = (pe->tcam.byte[off + 1] << 8) | pe->tcam.byte[off];
Marcin Wojtas3f518502014-07-10 16:52:13 -03001626 if (tcam_data != data)
1627 return false;
1628 return true;
1629}
1630
1631/* Update ai bits in tcam sw entry */
1632static void mvpp2_prs_tcam_ai_update(struct mvpp2_prs_entry *pe,
1633 unsigned int bits, unsigned int enable)
1634{
1635 int i, ai_idx = MVPP2_PRS_TCAM_AI_BYTE;
1636
1637 for (i = 0; i < MVPP2_PRS_AI_BITS; i++) {
1638
1639 if (!(enable & BIT(i)))
1640 continue;
1641
1642 if (bits & BIT(i))
1643 pe->tcam.byte[ai_idx] |= 1 << i;
1644 else
1645 pe->tcam.byte[ai_idx] &= ~(1 << i);
1646 }
1647
1648 pe->tcam.byte[MVPP2_PRS_TCAM_EN_OFFS(ai_idx)] |= enable;
1649}
1650
1651/* Get ai bits from tcam sw entry */
1652static int mvpp2_prs_tcam_ai_get(struct mvpp2_prs_entry *pe)
1653{
1654 return pe->tcam.byte[MVPP2_PRS_TCAM_AI_BYTE];
1655}
1656
1657/* Set ethertype in tcam sw entry */
1658static void mvpp2_prs_match_etype(struct mvpp2_prs_entry *pe, int offset,
1659 unsigned short ethertype)
1660{
1661 mvpp2_prs_tcam_data_byte_set(pe, offset + 0, ethertype >> 8, 0xff);
1662 mvpp2_prs_tcam_data_byte_set(pe, offset + 1, ethertype & 0xff, 0xff);
1663}
1664
1665/* Set bits in sram sw entry */
1666static void mvpp2_prs_sram_bits_set(struct mvpp2_prs_entry *pe, int bit_num,
1667 int val)
1668{
1669 pe->sram.byte[MVPP2_BIT_TO_BYTE(bit_num)] |= (val << (bit_num % 8));
1670}
1671
1672/* Clear bits in sram sw entry */
1673static void mvpp2_prs_sram_bits_clear(struct mvpp2_prs_entry *pe, int bit_num,
1674 int val)
1675{
1676 pe->sram.byte[MVPP2_BIT_TO_BYTE(bit_num)] &= ~(val << (bit_num % 8));
1677}
1678
1679/* Update ri bits in sram sw entry */
1680static void mvpp2_prs_sram_ri_update(struct mvpp2_prs_entry *pe,
1681 unsigned int bits, unsigned int mask)
1682{
1683 unsigned int i;
1684
1685 for (i = 0; i < MVPP2_PRS_SRAM_RI_CTRL_BITS; i++) {
1686 int ri_off = MVPP2_PRS_SRAM_RI_OFFS;
1687
1688 if (!(mask & BIT(i)))
1689 continue;
1690
1691 if (bits & BIT(i))
1692 mvpp2_prs_sram_bits_set(pe, ri_off + i, 1);
1693 else
1694 mvpp2_prs_sram_bits_clear(pe, ri_off + i, 1);
1695
1696 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_RI_CTRL_OFFS + i, 1);
1697 }
1698}
1699
1700/* Obtain ri bits from sram sw entry */
1701static int mvpp2_prs_sram_ri_get(struct mvpp2_prs_entry *pe)
1702{
1703 return pe->sram.word[MVPP2_PRS_SRAM_RI_WORD];
1704}
1705
1706/* Update ai bits in sram sw entry */
1707static void mvpp2_prs_sram_ai_update(struct mvpp2_prs_entry *pe,
1708 unsigned int bits, unsigned int mask)
1709{
1710 unsigned int i;
1711 int ai_off = MVPP2_PRS_SRAM_AI_OFFS;
1712
1713 for (i = 0; i < MVPP2_PRS_SRAM_AI_CTRL_BITS; i++) {
1714
1715 if (!(mask & BIT(i)))
1716 continue;
1717
1718 if (bits & BIT(i))
1719 mvpp2_prs_sram_bits_set(pe, ai_off + i, 1);
1720 else
1721 mvpp2_prs_sram_bits_clear(pe, ai_off + i, 1);
1722
1723 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_AI_CTRL_OFFS + i, 1);
1724 }
1725}
1726
1727/* Read ai bits from sram sw entry */
1728static int mvpp2_prs_sram_ai_get(struct mvpp2_prs_entry *pe)
1729{
1730 u8 bits;
1731 int ai_off = MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_AI_OFFS);
1732 int ai_en_off = ai_off + 1;
1733 int ai_shift = MVPP2_PRS_SRAM_AI_OFFS % 8;
1734
1735 bits = (pe->sram.byte[ai_off] >> ai_shift) |
1736 (pe->sram.byte[ai_en_off] << (8 - ai_shift));
1737
1738 return bits;
1739}
1740
1741/* In sram sw entry set lookup ID field of the tcam key to be used in the next
1742 * lookup interation
1743 */
1744static void mvpp2_prs_sram_next_lu_set(struct mvpp2_prs_entry *pe,
1745 unsigned int lu)
1746{
1747 int sram_next_off = MVPP2_PRS_SRAM_NEXT_LU_OFFS;
1748
1749 mvpp2_prs_sram_bits_clear(pe, sram_next_off,
1750 MVPP2_PRS_SRAM_NEXT_LU_MASK);
1751 mvpp2_prs_sram_bits_set(pe, sram_next_off, lu);
1752}
1753
1754/* In the sram sw entry set sign and value of the next lookup offset
1755 * and the offset value generated to the classifier
1756 */
1757static void mvpp2_prs_sram_shift_set(struct mvpp2_prs_entry *pe, int shift,
1758 unsigned int op)
1759{
1760 /* Set sign */
1761 if (shift < 0) {
1762 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_SHIFT_SIGN_BIT, 1);
1763 shift = 0 - shift;
1764 } else {
1765 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_SHIFT_SIGN_BIT, 1);
1766 }
1767
1768 /* Set value */
1769 pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_SHIFT_OFFS)] =
1770 (unsigned char)shift;
1771
1772 /* Reset and set operation */
1773 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_SHIFT_OFFS,
1774 MVPP2_PRS_SRAM_OP_SEL_SHIFT_MASK);
1775 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_OP_SEL_SHIFT_OFFS, op);
1776
1777 /* Set base offset as current */
1778 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_BASE_OFFS, 1);
1779}
1780
1781/* In the sram sw entry set sign and value of the user defined offset
1782 * generated to the classifier
1783 */
1784static void mvpp2_prs_sram_offset_set(struct mvpp2_prs_entry *pe,
1785 unsigned int type, int offset,
1786 unsigned int op)
1787{
1788 /* Set sign */
1789 if (offset < 0) {
1790 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_UDF_SIGN_BIT, 1);
1791 offset = 0 - offset;
1792 } else {
1793 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_UDF_SIGN_BIT, 1);
1794 }
1795
1796 /* Set value */
1797 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_UDF_OFFS,
1798 MVPP2_PRS_SRAM_UDF_MASK);
1799 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_UDF_OFFS, offset);
1800 pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_UDF_OFFS +
1801 MVPP2_PRS_SRAM_UDF_BITS)] &=
1802 ~(MVPP2_PRS_SRAM_UDF_MASK >> (8 - (MVPP2_PRS_SRAM_UDF_OFFS % 8)));
1803 pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_UDF_OFFS +
1804 MVPP2_PRS_SRAM_UDF_BITS)] |=
1805 (offset >> (8 - (MVPP2_PRS_SRAM_UDF_OFFS % 8)));
1806
1807 /* Set offset type */
1808 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_UDF_TYPE_OFFS,
1809 MVPP2_PRS_SRAM_UDF_TYPE_MASK);
1810 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_UDF_TYPE_OFFS, type);
1811
1812 /* Set offset operation */
1813 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS,
1814 MVPP2_PRS_SRAM_OP_SEL_UDF_MASK);
1815 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS, op);
1816
1817 pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS +
1818 MVPP2_PRS_SRAM_OP_SEL_UDF_BITS)] &=
1819 ~(MVPP2_PRS_SRAM_OP_SEL_UDF_MASK >>
1820 (8 - (MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS % 8)));
1821
1822 pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS +
1823 MVPP2_PRS_SRAM_OP_SEL_UDF_BITS)] |=
1824 (op >> (8 - (MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS % 8)));
1825
1826 /* Set base offset as current */
1827 mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_BASE_OFFS, 1);
1828}
1829
1830/* Find parser flow entry */
1831static struct mvpp2_prs_entry *mvpp2_prs_flow_find(struct mvpp2 *priv, int flow)
1832{
1833 struct mvpp2_prs_entry *pe;
1834 int tid;
1835
1836 pe = kzalloc(sizeof(*pe), GFP_KERNEL);
1837 if (!pe)
1838 return NULL;
1839 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_FLOWS);
1840
1841 /* Go through the all entires with MVPP2_PRS_LU_FLOWS */
1842 for (tid = MVPP2_PRS_TCAM_SRAM_SIZE - 1; tid >= 0; tid--) {
1843 u8 bits;
1844
1845 if (!priv->prs_shadow[tid].valid ||
1846 priv->prs_shadow[tid].lu != MVPP2_PRS_LU_FLOWS)
1847 continue;
1848
1849 pe->index = tid;
1850 mvpp2_prs_hw_read(priv, pe);
1851 bits = mvpp2_prs_sram_ai_get(pe);
1852
1853 /* Sram store classification lookup ID in AI bits [5:0] */
1854 if ((bits & MVPP2_PRS_FLOW_ID_MASK) == flow)
1855 return pe;
1856 }
1857 kfree(pe);
1858
1859 return NULL;
1860}
1861
1862/* Return first free tcam index, seeking from start to end */
1863static int mvpp2_prs_tcam_first_free(struct mvpp2 *priv, unsigned char start,
1864 unsigned char end)
1865{
1866 int tid;
1867
1868 if (start > end)
1869 swap(start, end);
1870
1871 if (end >= MVPP2_PRS_TCAM_SRAM_SIZE)
1872 end = MVPP2_PRS_TCAM_SRAM_SIZE - 1;
1873
1874 for (tid = start; tid <= end; tid++) {
1875 if (!priv->prs_shadow[tid].valid)
1876 return tid;
1877 }
1878
1879 return -EINVAL;
1880}
1881
1882/* Enable/disable dropping all mac da's */
1883static void mvpp2_prs_mac_drop_all_set(struct mvpp2 *priv, int port, bool add)
1884{
1885 struct mvpp2_prs_entry pe;
1886
1887 if (priv->prs_shadow[MVPP2_PE_DROP_ALL].valid) {
1888 /* Entry exist - update port only */
1889 pe.index = MVPP2_PE_DROP_ALL;
1890 mvpp2_prs_hw_read(priv, &pe);
1891 } else {
1892 /* Entry doesn't exist - create new */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02001893 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03001894 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC);
1895 pe.index = MVPP2_PE_DROP_ALL;
1896
1897 /* Non-promiscuous mode for all ports - DROP unknown packets */
1898 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_DROP_MASK,
1899 MVPP2_PRS_RI_DROP_MASK);
1900
1901 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
1902 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
1903
1904 /* Update shadow table */
1905 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC);
1906
1907 /* Mask all ports */
1908 mvpp2_prs_tcam_port_map_set(&pe, 0);
1909 }
1910
1911 /* Update port mask */
1912 mvpp2_prs_tcam_port_set(&pe, port, add);
1913
1914 mvpp2_prs_hw_write(priv, &pe);
1915}
1916
1917/* Set port to promiscuous mode */
1918static void mvpp2_prs_mac_promisc_set(struct mvpp2 *priv, int port, bool add)
1919{
1920 struct mvpp2_prs_entry pe;
1921
Joe Perchesdbedd442015-03-06 20:49:12 -08001922 /* Promiscuous mode - Accept unknown packets */
Marcin Wojtas3f518502014-07-10 16:52:13 -03001923
1924 if (priv->prs_shadow[MVPP2_PE_MAC_PROMISCUOUS].valid) {
1925 /* Entry exist - update port only */
1926 pe.index = MVPP2_PE_MAC_PROMISCUOUS;
1927 mvpp2_prs_hw_read(priv, &pe);
1928 } else {
1929 /* Entry doesn't exist - create new */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02001930 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03001931 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC);
1932 pe.index = MVPP2_PE_MAC_PROMISCUOUS;
1933
1934 /* Continue - set next lookup */
1935 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_DSA);
1936
1937 /* Set result info bits */
1938 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L2_UCAST,
1939 MVPP2_PRS_RI_L2_CAST_MASK);
1940
1941 /* Shift to ethertype */
1942 mvpp2_prs_sram_shift_set(&pe, 2 * ETH_ALEN,
1943 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
1944
1945 /* Mask all ports */
1946 mvpp2_prs_tcam_port_map_set(&pe, 0);
1947
1948 /* Update shadow table */
1949 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC);
1950 }
1951
1952 /* Update port mask */
1953 mvpp2_prs_tcam_port_set(&pe, port, add);
1954
1955 mvpp2_prs_hw_write(priv, &pe);
1956}
1957
1958/* Accept multicast */
1959static void mvpp2_prs_mac_multi_set(struct mvpp2 *priv, int port, int index,
1960 bool add)
1961{
1962 struct mvpp2_prs_entry pe;
1963 unsigned char da_mc;
1964
1965 /* Ethernet multicast address first byte is
1966 * 0x01 for IPv4 and 0x33 for IPv6
1967 */
1968 da_mc = (index == MVPP2_PE_MAC_MC_ALL) ? 0x01 : 0x33;
1969
1970 if (priv->prs_shadow[index].valid) {
1971 /* Entry exist - update port only */
1972 pe.index = index;
1973 mvpp2_prs_hw_read(priv, &pe);
1974 } else {
1975 /* Entry doesn't exist - create new */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02001976 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03001977 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC);
1978 pe.index = index;
1979
1980 /* Continue - set next lookup */
1981 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_DSA);
1982
1983 /* Set result info bits */
1984 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L2_MCAST,
1985 MVPP2_PRS_RI_L2_CAST_MASK);
1986
1987 /* Update tcam entry data first byte */
1988 mvpp2_prs_tcam_data_byte_set(&pe, 0, da_mc, 0xff);
1989
1990 /* Shift to ethertype */
1991 mvpp2_prs_sram_shift_set(&pe, 2 * ETH_ALEN,
1992 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
1993
1994 /* Mask all ports */
1995 mvpp2_prs_tcam_port_map_set(&pe, 0);
1996
1997 /* Update shadow table */
1998 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC);
1999 }
2000
2001 /* Update port mask */
2002 mvpp2_prs_tcam_port_set(&pe, port, add);
2003
2004 mvpp2_prs_hw_write(priv, &pe);
2005}
2006
2007/* Set entry for dsa packets */
2008static void mvpp2_prs_dsa_tag_set(struct mvpp2 *priv, int port, bool add,
2009 bool tagged, bool extend)
2010{
2011 struct mvpp2_prs_entry pe;
2012 int tid, shift;
2013
2014 if (extend) {
2015 tid = tagged ? MVPP2_PE_EDSA_TAGGED : MVPP2_PE_EDSA_UNTAGGED;
2016 shift = 8;
2017 } else {
2018 tid = tagged ? MVPP2_PE_DSA_TAGGED : MVPP2_PE_DSA_UNTAGGED;
2019 shift = 4;
2020 }
2021
2022 if (priv->prs_shadow[tid].valid) {
2023 /* Entry exist - update port only */
2024 pe.index = tid;
2025 mvpp2_prs_hw_read(priv, &pe);
2026 } else {
2027 /* Entry doesn't exist - create new */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002028 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002029 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_DSA);
2030 pe.index = tid;
2031
2032 /* Shift 4 bytes if DSA tag or 8 bytes in case of EDSA tag*/
2033 mvpp2_prs_sram_shift_set(&pe, shift,
2034 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2035
2036 /* Update shadow table */
2037 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_DSA);
2038
2039 if (tagged) {
2040 /* Set tagged bit in DSA tag */
2041 mvpp2_prs_tcam_data_byte_set(&pe, 0,
2042 MVPP2_PRS_TCAM_DSA_TAGGED_BIT,
2043 MVPP2_PRS_TCAM_DSA_TAGGED_BIT);
2044 /* Clear all ai bits for next iteration */
2045 mvpp2_prs_sram_ai_update(&pe, 0,
2046 MVPP2_PRS_SRAM_AI_MASK);
2047 /* If packet is tagged continue check vlans */
2048 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_VLAN);
2049 } else {
2050 /* Set result info bits to 'no vlans' */
2051 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_NONE,
2052 MVPP2_PRS_RI_VLAN_MASK);
2053 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2);
2054 }
2055
2056 /* Mask all ports */
2057 mvpp2_prs_tcam_port_map_set(&pe, 0);
2058 }
2059
2060 /* Update port mask */
2061 mvpp2_prs_tcam_port_set(&pe, port, add);
2062
2063 mvpp2_prs_hw_write(priv, &pe);
2064}
2065
2066/* Set entry for dsa ethertype */
2067static void mvpp2_prs_dsa_tag_ethertype_set(struct mvpp2 *priv, int port,
2068 bool add, bool tagged, bool extend)
2069{
2070 struct mvpp2_prs_entry pe;
2071 int tid, shift, port_mask;
2072
2073 if (extend) {
2074 tid = tagged ? MVPP2_PE_ETYPE_EDSA_TAGGED :
2075 MVPP2_PE_ETYPE_EDSA_UNTAGGED;
2076 port_mask = 0;
2077 shift = 8;
2078 } else {
2079 tid = tagged ? MVPP2_PE_ETYPE_DSA_TAGGED :
2080 MVPP2_PE_ETYPE_DSA_UNTAGGED;
2081 port_mask = MVPP2_PRS_PORT_MASK;
2082 shift = 4;
2083 }
2084
2085 if (priv->prs_shadow[tid].valid) {
2086 /* Entry exist - update port only */
2087 pe.index = tid;
2088 mvpp2_prs_hw_read(priv, &pe);
2089 } else {
2090 /* Entry doesn't exist - create new */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002091 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002092 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_DSA);
2093 pe.index = tid;
2094
2095 /* Set ethertype */
2096 mvpp2_prs_match_etype(&pe, 0, ETH_P_EDSA);
2097 mvpp2_prs_match_etype(&pe, 2, 0);
2098
2099 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_DSA_MASK,
2100 MVPP2_PRS_RI_DSA_MASK);
2101 /* Shift ethertype + 2 byte reserved + tag*/
2102 mvpp2_prs_sram_shift_set(&pe, 2 + MVPP2_ETH_TYPE_LEN + shift,
2103 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2104
2105 /* Update shadow table */
2106 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_DSA);
2107
2108 if (tagged) {
2109 /* Set tagged bit in DSA tag */
2110 mvpp2_prs_tcam_data_byte_set(&pe,
2111 MVPP2_ETH_TYPE_LEN + 2 + 3,
2112 MVPP2_PRS_TCAM_DSA_TAGGED_BIT,
2113 MVPP2_PRS_TCAM_DSA_TAGGED_BIT);
2114 /* Clear all ai bits for next iteration */
2115 mvpp2_prs_sram_ai_update(&pe, 0,
2116 MVPP2_PRS_SRAM_AI_MASK);
2117 /* If packet is tagged continue check vlans */
2118 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_VLAN);
2119 } else {
2120 /* Set result info bits to 'no vlans' */
2121 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_NONE,
2122 MVPP2_PRS_RI_VLAN_MASK);
2123 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2);
2124 }
2125 /* Mask/unmask all ports, depending on dsa type */
2126 mvpp2_prs_tcam_port_map_set(&pe, port_mask);
2127 }
2128
2129 /* Update port mask */
2130 mvpp2_prs_tcam_port_set(&pe, port, add);
2131
2132 mvpp2_prs_hw_write(priv, &pe);
2133}
2134
2135/* Search for existing single/triple vlan entry */
2136static struct mvpp2_prs_entry *mvpp2_prs_vlan_find(struct mvpp2 *priv,
2137 unsigned short tpid, int ai)
2138{
2139 struct mvpp2_prs_entry *pe;
2140 int tid;
2141
2142 pe = kzalloc(sizeof(*pe), GFP_KERNEL);
2143 if (!pe)
2144 return NULL;
2145 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN);
2146
2147 /* Go through the all entries with MVPP2_PRS_LU_VLAN */
2148 for (tid = MVPP2_PE_FIRST_FREE_TID;
2149 tid <= MVPP2_PE_LAST_FREE_TID; tid++) {
2150 unsigned int ri_bits, ai_bits;
2151 bool match;
2152
2153 if (!priv->prs_shadow[tid].valid ||
2154 priv->prs_shadow[tid].lu != MVPP2_PRS_LU_VLAN)
2155 continue;
2156
2157 pe->index = tid;
2158
2159 mvpp2_prs_hw_read(priv, pe);
2160 match = mvpp2_prs_tcam_data_cmp(pe, 0, swab16(tpid));
2161 if (!match)
2162 continue;
2163
2164 /* Get vlan type */
2165 ri_bits = mvpp2_prs_sram_ri_get(pe);
2166 ri_bits &= MVPP2_PRS_RI_VLAN_MASK;
2167
2168 /* Get current ai value from tcam */
2169 ai_bits = mvpp2_prs_tcam_ai_get(pe);
2170 /* Clear double vlan bit */
2171 ai_bits &= ~MVPP2_PRS_DBL_VLAN_AI_BIT;
2172
2173 if (ai != ai_bits)
2174 continue;
2175
2176 if (ri_bits == MVPP2_PRS_RI_VLAN_SINGLE ||
2177 ri_bits == MVPP2_PRS_RI_VLAN_TRIPLE)
2178 return pe;
2179 }
2180 kfree(pe);
2181
2182 return NULL;
2183}
2184
2185/* Add/update single/triple vlan entry */
2186static int mvpp2_prs_vlan_add(struct mvpp2 *priv, unsigned short tpid, int ai,
2187 unsigned int port_map)
2188{
2189 struct mvpp2_prs_entry *pe;
2190 int tid_aux, tid;
Sudip Mukherjee43737472014-11-01 16:59:34 +05302191 int ret = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03002192
2193 pe = mvpp2_prs_vlan_find(priv, tpid, ai);
2194
2195 if (!pe) {
2196 /* Create new tcam entry */
2197 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_LAST_FREE_TID,
2198 MVPP2_PE_FIRST_FREE_TID);
2199 if (tid < 0)
2200 return tid;
2201
2202 pe = kzalloc(sizeof(*pe), GFP_KERNEL);
2203 if (!pe)
2204 return -ENOMEM;
2205
2206 /* Get last double vlan tid */
2207 for (tid_aux = MVPP2_PE_LAST_FREE_TID;
2208 tid_aux >= MVPP2_PE_FIRST_FREE_TID; tid_aux--) {
2209 unsigned int ri_bits;
2210
2211 if (!priv->prs_shadow[tid_aux].valid ||
2212 priv->prs_shadow[tid_aux].lu != MVPP2_PRS_LU_VLAN)
2213 continue;
2214
2215 pe->index = tid_aux;
2216 mvpp2_prs_hw_read(priv, pe);
2217 ri_bits = mvpp2_prs_sram_ri_get(pe);
2218 if ((ri_bits & MVPP2_PRS_RI_VLAN_MASK) ==
2219 MVPP2_PRS_RI_VLAN_DOUBLE)
2220 break;
2221 }
2222
Sudip Mukherjee43737472014-11-01 16:59:34 +05302223 if (tid <= tid_aux) {
2224 ret = -EINVAL;
Markus Elfringf9fd0e32017-04-17 13:50:35 +02002225 goto free_pe;
Sudip Mukherjee43737472014-11-01 16:59:34 +05302226 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03002227
Markus Elfringbd6aaf52017-04-17 10:40:32 +02002228 memset(pe, 0, sizeof(*pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002229 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN);
2230 pe->index = tid;
2231
2232 mvpp2_prs_match_etype(pe, 0, tpid);
2233
2234 mvpp2_prs_sram_next_lu_set(pe, MVPP2_PRS_LU_L2);
2235 /* Shift 4 bytes - skip 1 vlan tag */
2236 mvpp2_prs_sram_shift_set(pe, MVPP2_VLAN_TAG_LEN,
2237 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2238 /* Clear all ai bits for next iteration */
2239 mvpp2_prs_sram_ai_update(pe, 0, MVPP2_PRS_SRAM_AI_MASK);
2240
2241 if (ai == MVPP2_PRS_SINGLE_VLAN_AI) {
2242 mvpp2_prs_sram_ri_update(pe, MVPP2_PRS_RI_VLAN_SINGLE,
2243 MVPP2_PRS_RI_VLAN_MASK);
2244 } else {
2245 ai |= MVPP2_PRS_DBL_VLAN_AI_BIT;
2246 mvpp2_prs_sram_ri_update(pe, MVPP2_PRS_RI_VLAN_TRIPLE,
2247 MVPP2_PRS_RI_VLAN_MASK);
2248 }
2249 mvpp2_prs_tcam_ai_update(pe, ai, MVPP2_PRS_SRAM_AI_MASK);
2250
2251 mvpp2_prs_shadow_set(priv, pe->index, MVPP2_PRS_LU_VLAN);
2252 }
2253 /* Update ports' mask */
2254 mvpp2_prs_tcam_port_map_set(pe, port_map);
2255
2256 mvpp2_prs_hw_write(priv, pe);
Markus Elfringf9fd0e32017-04-17 13:50:35 +02002257free_pe:
Marcin Wojtas3f518502014-07-10 16:52:13 -03002258 kfree(pe);
2259
Sudip Mukherjee43737472014-11-01 16:59:34 +05302260 return ret;
Marcin Wojtas3f518502014-07-10 16:52:13 -03002261}
2262
2263/* Get first free double vlan ai number */
2264static int mvpp2_prs_double_vlan_ai_free_get(struct mvpp2 *priv)
2265{
2266 int i;
2267
2268 for (i = 1; i < MVPP2_PRS_DBL_VLANS_MAX; i++) {
2269 if (!priv->prs_double_vlans[i])
2270 return i;
2271 }
2272
2273 return -EINVAL;
2274}
2275
2276/* Search for existing double vlan entry */
2277static struct mvpp2_prs_entry *mvpp2_prs_double_vlan_find(struct mvpp2 *priv,
2278 unsigned short tpid1,
2279 unsigned short tpid2)
2280{
2281 struct mvpp2_prs_entry *pe;
2282 int tid;
2283
2284 pe = kzalloc(sizeof(*pe), GFP_KERNEL);
2285 if (!pe)
2286 return NULL;
2287 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN);
2288
2289 /* Go through the all entries with MVPP2_PRS_LU_VLAN */
2290 for (tid = MVPP2_PE_FIRST_FREE_TID;
2291 tid <= MVPP2_PE_LAST_FREE_TID; tid++) {
2292 unsigned int ri_mask;
2293 bool match;
2294
2295 if (!priv->prs_shadow[tid].valid ||
2296 priv->prs_shadow[tid].lu != MVPP2_PRS_LU_VLAN)
2297 continue;
2298
2299 pe->index = tid;
2300 mvpp2_prs_hw_read(priv, pe);
2301
2302 match = mvpp2_prs_tcam_data_cmp(pe, 0, swab16(tpid1))
2303 && mvpp2_prs_tcam_data_cmp(pe, 4, swab16(tpid2));
2304
2305 if (!match)
2306 continue;
2307
2308 ri_mask = mvpp2_prs_sram_ri_get(pe) & MVPP2_PRS_RI_VLAN_MASK;
2309 if (ri_mask == MVPP2_PRS_RI_VLAN_DOUBLE)
2310 return pe;
2311 }
2312 kfree(pe);
2313
2314 return NULL;
2315}
2316
2317/* Add or update double vlan entry */
2318static int mvpp2_prs_double_vlan_add(struct mvpp2 *priv, unsigned short tpid1,
2319 unsigned short tpid2,
2320 unsigned int port_map)
2321{
2322 struct mvpp2_prs_entry *pe;
Sudip Mukherjee43737472014-11-01 16:59:34 +05302323 int tid_aux, tid, ai, ret = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03002324
2325 pe = mvpp2_prs_double_vlan_find(priv, tpid1, tpid2);
2326
2327 if (!pe) {
2328 /* Create new tcam entry */
2329 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2330 MVPP2_PE_LAST_FREE_TID);
2331 if (tid < 0)
2332 return tid;
2333
2334 pe = kzalloc(sizeof(*pe), GFP_KERNEL);
2335 if (!pe)
2336 return -ENOMEM;
2337
2338 /* Set ai value for new double vlan entry */
2339 ai = mvpp2_prs_double_vlan_ai_free_get(priv);
Sudip Mukherjee43737472014-11-01 16:59:34 +05302340 if (ai < 0) {
2341 ret = ai;
Markus Elfringc9a7e122017-04-17 13:03:49 +02002342 goto free_pe;
Sudip Mukherjee43737472014-11-01 16:59:34 +05302343 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03002344
2345 /* Get first single/triple vlan tid */
2346 for (tid_aux = MVPP2_PE_FIRST_FREE_TID;
2347 tid_aux <= MVPP2_PE_LAST_FREE_TID; tid_aux++) {
2348 unsigned int ri_bits;
2349
2350 if (!priv->prs_shadow[tid_aux].valid ||
2351 priv->prs_shadow[tid_aux].lu != MVPP2_PRS_LU_VLAN)
2352 continue;
2353
2354 pe->index = tid_aux;
2355 mvpp2_prs_hw_read(priv, pe);
2356 ri_bits = mvpp2_prs_sram_ri_get(pe);
2357 ri_bits &= MVPP2_PRS_RI_VLAN_MASK;
2358 if (ri_bits == MVPP2_PRS_RI_VLAN_SINGLE ||
2359 ri_bits == MVPP2_PRS_RI_VLAN_TRIPLE)
2360 break;
2361 }
2362
Sudip Mukherjee43737472014-11-01 16:59:34 +05302363 if (tid >= tid_aux) {
2364 ret = -ERANGE;
Markus Elfringc9a7e122017-04-17 13:03:49 +02002365 goto free_pe;
Sudip Mukherjee43737472014-11-01 16:59:34 +05302366 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03002367
Markus Elfringbd6aaf52017-04-17 10:40:32 +02002368 memset(pe, 0, sizeof(*pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002369 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN);
2370 pe->index = tid;
2371
2372 priv->prs_double_vlans[ai] = true;
2373
2374 mvpp2_prs_match_etype(pe, 0, tpid1);
2375 mvpp2_prs_match_etype(pe, 4, tpid2);
2376
2377 mvpp2_prs_sram_next_lu_set(pe, MVPP2_PRS_LU_VLAN);
2378 /* Shift 8 bytes - skip 2 vlan tags */
2379 mvpp2_prs_sram_shift_set(pe, 2 * MVPP2_VLAN_TAG_LEN,
2380 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2381 mvpp2_prs_sram_ri_update(pe, MVPP2_PRS_RI_VLAN_DOUBLE,
2382 MVPP2_PRS_RI_VLAN_MASK);
2383 mvpp2_prs_sram_ai_update(pe, ai | MVPP2_PRS_DBL_VLAN_AI_BIT,
2384 MVPP2_PRS_SRAM_AI_MASK);
2385
2386 mvpp2_prs_shadow_set(priv, pe->index, MVPP2_PRS_LU_VLAN);
2387 }
2388
2389 /* Update ports' mask */
2390 mvpp2_prs_tcam_port_map_set(pe, port_map);
2391 mvpp2_prs_hw_write(priv, pe);
Markus Elfringc9a7e122017-04-17 13:03:49 +02002392free_pe:
Marcin Wojtas3f518502014-07-10 16:52:13 -03002393 kfree(pe);
Sudip Mukherjee43737472014-11-01 16:59:34 +05302394 return ret;
Marcin Wojtas3f518502014-07-10 16:52:13 -03002395}
2396
2397/* IPv4 header parsing for fragmentation and L4 offset */
2398static int mvpp2_prs_ip4_proto(struct mvpp2 *priv, unsigned short proto,
2399 unsigned int ri, unsigned int ri_mask)
2400{
2401 struct mvpp2_prs_entry pe;
2402 int tid;
2403
2404 if ((proto != IPPROTO_TCP) && (proto != IPPROTO_UDP) &&
2405 (proto != IPPROTO_IGMP))
2406 return -EINVAL;
2407
Stefan Chulskiaff3da32017-09-25 14:59:46 +02002408 /* Not fragmented packet */
Marcin Wojtas3f518502014-07-10 16:52:13 -03002409 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2410 MVPP2_PE_LAST_FREE_TID);
2411 if (tid < 0)
2412 return tid;
2413
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002414 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002415 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4);
2416 pe.index = tid;
2417
2418 /* Set next lu to IPv4 */
2419 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4);
2420 mvpp2_prs_sram_shift_set(&pe, 12, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2421 /* Set L4 offset */
2422 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4,
2423 sizeof(struct iphdr) - 4,
2424 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
2425 mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT,
2426 MVPP2_PRS_IPV4_DIP_AI_BIT);
Stefan Chulskiaff3da32017-09-25 14:59:46 +02002427 mvpp2_prs_sram_ri_update(&pe, ri, ri_mask | MVPP2_PRS_RI_IP_FRAG_MASK);
2428
2429 mvpp2_prs_tcam_data_byte_set(&pe, 2, 0x00,
2430 MVPP2_PRS_TCAM_PROTO_MASK_L);
2431 mvpp2_prs_tcam_data_byte_set(&pe, 3, 0x00,
2432 MVPP2_PRS_TCAM_PROTO_MASK);
Marcin Wojtas3f518502014-07-10 16:52:13 -03002433
2434 mvpp2_prs_tcam_data_byte_set(&pe, 5, proto, MVPP2_PRS_TCAM_PROTO_MASK);
2435 mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV4_DIP_AI_BIT);
2436 /* Unmask all ports */
2437 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2438
2439 /* Update shadow table and hw entry */
2440 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
2441 mvpp2_prs_hw_write(priv, &pe);
2442
Stefan Chulskiaff3da32017-09-25 14:59:46 +02002443 /* Fragmented packet */
Marcin Wojtas3f518502014-07-10 16:52:13 -03002444 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2445 MVPP2_PE_LAST_FREE_TID);
2446 if (tid < 0)
2447 return tid;
2448
2449 pe.index = tid;
2450 /* Clear ri before updating */
2451 pe.sram.word[MVPP2_PRS_SRAM_RI_WORD] = 0x0;
2452 pe.sram.word[MVPP2_PRS_SRAM_RI_CTRL_WORD] = 0x0;
2453 mvpp2_prs_sram_ri_update(&pe, ri, ri_mask);
2454
Stefan Chulskiaff3da32017-09-25 14:59:46 +02002455 mvpp2_prs_sram_ri_update(&pe, ri | MVPP2_PRS_RI_IP_FRAG_TRUE,
2456 ri_mask | MVPP2_PRS_RI_IP_FRAG_MASK);
2457
2458 mvpp2_prs_tcam_data_byte_set(&pe, 2, 0x00, 0x0);
2459 mvpp2_prs_tcam_data_byte_set(&pe, 3, 0x00, 0x0);
Marcin Wojtas3f518502014-07-10 16:52:13 -03002460
2461 /* Update shadow table and hw entry */
2462 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
2463 mvpp2_prs_hw_write(priv, &pe);
2464
2465 return 0;
2466}
2467
2468/* IPv4 L3 multicast or broadcast */
2469static int mvpp2_prs_ip4_cast(struct mvpp2 *priv, unsigned short l3_cast)
2470{
2471 struct mvpp2_prs_entry pe;
2472 int mask, tid;
2473
2474 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2475 MVPP2_PE_LAST_FREE_TID);
2476 if (tid < 0)
2477 return tid;
2478
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002479 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002480 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4);
2481 pe.index = tid;
2482
2483 switch (l3_cast) {
2484 case MVPP2_PRS_L3_MULTI_CAST:
2485 mvpp2_prs_tcam_data_byte_set(&pe, 0, MVPP2_PRS_IPV4_MC,
2486 MVPP2_PRS_IPV4_MC_MASK);
2487 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_MCAST,
2488 MVPP2_PRS_RI_L3_ADDR_MASK);
2489 break;
2490 case MVPP2_PRS_L3_BROAD_CAST:
2491 mask = MVPP2_PRS_IPV4_BC_MASK;
2492 mvpp2_prs_tcam_data_byte_set(&pe, 0, mask, mask);
2493 mvpp2_prs_tcam_data_byte_set(&pe, 1, mask, mask);
2494 mvpp2_prs_tcam_data_byte_set(&pe, 2, mask, mask);
2495 mvpp2_prs_tcam_data_byte_set(&pe, 3, mask, mask);
2496 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_BCAST,
2497 MVPP2_PRS_RI_L3_ADDR_MASK);
2498 break;
2499 default:
2500 return -EINVAL;
2501 }
2502
2503 /* Finished: go to flowid generation */
2504 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
2505 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
2506
2507 mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT,
2508 MVPP2_PRS_IPV4_DIP_AI_BIT);
2509 /* Unmask all ports */
2510 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2511
2512 /* Update shadow table and hw entry */
2513 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
2514 mvpp2_prs_hw_write(priv, &pe);
2515
2516 return 0;
2517}
2518
2519/* Set entries for protocols over IPv6 */
2520static int mvpp2_prs_ip6_proto(struct mvpp2 *priv, unsigned short proto,
2521 unsigned int ri, unsigned int ri_mask)
2522{
2523 struct mvpp2_prs_entry pe;
2524 int tid;
2525
2526 if ((proto != IPPROTO_TCP) && (proto != IPPROTO_UDP) &&
2527 (proto != IPPROTO_ICMPV6) && (proto != IPPROTO_IPIP))
2528 return -EINVAL;
2529
2530 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2531 MVPP2_PE_LAST_FREE_TID);
2532 if (tid < 0)
2533 return tid;
2534
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002535 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002536 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6);
2537 pe.index = tid;
2538
2539 /* Finished: go to flowid generation */
2540 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
2541 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
2542 mvpp2_prs_sram_ri_update(&pe, ri, ri_mask);
2543 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4,
2544 sizeof(struct ipv6hdr) - 6,
2545 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
2546
2547 mvpp2_prs_tcam_data_byte_set(&pe, 0, proto, MVPP2_PRS_TCAM_PROTO_MASK);
2548 mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT,
2549 MVPP2_PRS_IPV6_NO_EXT_AI_BIT);
2550 /* Unmask all ports */
2551 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2552
2553 /* Write HW */
2554 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP6);
2555 mvpp2_prs_hw_write(priv, &pe);
2556
2557 return 0;
2558}
2559
2560/* IPv6 L3 multicast entry */
2561static int mvpp2_prs_ip6_cast(struct mvpp2 *priv, unsigned short l3_cast)
2562{
2563 struct mvpp2_prs_entry pe;
2564 int tid;
2565
2566 if (l3_cast != MVPP2_PRS_L3_MULTI_CAST)
2567 return -EINVAL;
2568
2569 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2570 MVPP2_PE_LAST_FREE_TID);
2571 if (tid < 0)
2572 return tid;
2573
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_IP6);
2576 pe.index = tid;
2577
2578 /* Finished: go to flowid generation */
2579 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6);
2580 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_MCAST,
2581 MVPP2_PRS_RI_L3_ADDR_MASK);
2582 mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT,
2583 MVPP2_PRS_IPV6_NO_EXT_AI_BIT);
2584 /* Shift back to IPv6 NH */
2585 mvpp2_prs_sram_shift_set(&pe, -18, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2586
2587 mvpp2_prs_tcam_data_byte_set(&pe, 0, MVPP2_PRS_IPV6_MC,
2588 MVPP2_PRS_IPV6_MC_MASK);
2589 mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV6_NO_EXT_AI_BIT);
2590 /* Unmask all ports */
2591 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2592
2593 /* Update shadow table and hw entry */
2594 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP6);
2595 mvpp2_prs_hw_write(priv, &pe);
2596
2597 return 0;
2598}
2599
2600/* Parser per-port initialization */
2601static void mvpp2_prs_hw_port_init(struct mvpp2 *priv, int port, int lu_first,
2602 int lu_max, int offset)
2603{
2604 u32 val;
2605
2606 /* Set lookup ID */
2607 val = mvpp2_read(priv, MVPP2_PRS_INIT_LOOKUP_REG);
2608 val &= ~MVPP2_PRS_PORT_LU_MASK(port);
2609 val |= MVPP2_PRS_PORT_LU_VAL(port, lu_first);
2610 mvpp2_write(priv, MVPP2_PRS_INIT_LOOKUP_REG, val);
2611
2612 /* Set maximum number of loops for packet received from port */
2613 val = mvpp2_read(priv, MVPP2_PRS_MAX_LOOP_REG(port));
2614 val &= ~MVPP2_PRS_MAX_LOOP_MASK(port);
2615 val |= MVPP2_PRS_MAX_LOOP_VAL(port, lu_max);
2616 mvpp2_write(priv, MVPP2_PRS_MAX_LOOP_REG(port), val);
2617
2618 /* Set initial offset for packet header extraction for the first
2619 * searching loop
2620 */
2621 val = mvpp2_read(priv, MVPP2_PRS_INIT_OFFS_REG(port));
2622 val &= ~MVPP2_PRS_INIT_OFF_MASK(port);
2623 val |= MVPP2_PRS_INIT_OFF_VAL(port, offset);
2624 mvpp2_write(priv, MVPP2_PRS_INIT_OFFS_REG(port), val);
2625}
2626
2627/* Default flow entries initialization for all ports */
2628static void mvpp2_prs_def_flow_init(struct mvpp2 *priv)
2629{
2630 struct mvpp2_prs_entry pe;
2631 int port;
2632
2633 for (port = 0; port < MVPP2_MAX_PORTS; port++) {
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002634 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002635 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
2636 pe.index = MVPP2_PE_FIRST_DEFAULT_FLOW - port;
2637
2638 /* Mask all ports */
2639 mvpp2_prs_tcam_port_map_set(&pe, 0);
2640
2641 /* Set flow ID*/
2642 mvpp2_prs_sram_ai_update(&pe, port, MVPP2_PRS_FLOW_ID_MASK);
2643 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_DONE_BIT, 1);
2644
2645 /* Update shadow table and hw entry */
2646 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_FLOWS);
2647 mvpp2_prs_hw_write(priv, &pe);
2648 }
2649}
2650
2651/* Set default entry for Marvell Header field */
2652static void mvpp2_prs_mh_init(struct mvpp2 *priv)
2653{
2654 struct mvpp2_prs_entry pe;
2655
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002656 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002657
2658 pe.index = MVPP2_PE_MH_DEFAULT;
2659 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MH);
2660 mvpp2_prs_sram_shift_set(&pe, MVPP2_MH_SIZE,
2661 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2662 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_MAC);
2663
2664 /* Unmask all ports */
2665 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2666
2667 /* Update shadow table and hw entry */
2668 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MH);
2669 mvpp2_prs_hw_write(priv, &pe);
2670}
2671
2672/* Set default entires (place holder) for promiscuous, non-promiscuous and
2673 * multicast MAC addresses
2674 */
2675static void mvpp2_prs_mac_init(struct mvpp2 *priv)
2676{
2677 struct mvpp2_prs_entry pe;
2678
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002679 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002680
2681 /* Non-promiscuous mode for all ports - DROP unknown packets */
2682 pe.index = MVPP2_PE_MAC_NON_PROMISCUOUS;
2683 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC);
2684
2685 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_DROP_MASK,
2686 MVPP2_PRS_RI_DROP_MASK);
2687 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
2688 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
2689
2690 /* Unmask all ports */
2691 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2692
2693 /* Update shadow table and hw entry */
2694 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC);
2695 mvpp2_prs_hw_write(priv, &pe);
2696
2697 /* place holders only - no ports */
2698 mvpp2_prs_mac_drop_all_set(priv, 0, false);
2699 mvpp2_prs_mac_promisc_set(priv, 0, false);
Antoine Tenart20746d72017-10-24 11:41:27 +02002700 mvpp2_prs_mac_multi_set(priv, 0, MVPP2_PE_MAC_MC_ALL, false);
2701 mvpp2_prs_mac_multi_set(priv, 0, MVPP2_PE_MAC_MC_IP6, false);
Marcin Wojtas3f518502014-07-10 16:52:13 -03002702}
2703
2704/* Set default entries for various types of dsa packets */
2705static void mvpp2_prs_dsa_init(struct mvpp2 *priv)
2706{
2707 struct mvpp2_prs_entry pe;
2708
2709 /* None tagged EDSA entry - place holder */
2710 mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_UNTAGGED,
2711 MVPP2_PRS_EDSA);
2712
2713 /* Tagged EDSA entry - place holder */
2714 mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA);
2715
2716 /* None tagged DSA entry - place holder */
2717 mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_UNTAGGED,
2718 MVPP2_PRS_DSA);
2719
2720 /* Tagged DSA entry - place holder */
2721 mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_TAGGED, MVPP2_PRS_DSA);
2722
2723 /* None tagged EDSA ethertype entry - place holder*/
2724 mvpp2_prs_dsa_tag_ethertype_set(priv, 0, false,
2725 MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA);
2726
2727 /* Tagged EDSA ethertype entry - place holder*/
2728 mvpp2_prs_dsa_tag_ethertype_set(priv, 0, false,
2729 MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA);
2730
2731 /* None tagged DSA ethertype entry */
2732 mvpp2_prs_dsa_tag_ethertype_set(priv, 0, true,
2733 MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA);
2734
2735 /* Tagged DSA ethertype entry */
2736 mvpp2_prs_dsa_tag_ethertype_set(priv, 0, true,
2737 MVPP2_PRS_TAGGED, MVPP2_PRS_DSA);
2738
2739 /* Set default entry, in case DSA or EDSA tag not found */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002740 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002741 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_DSA);
2742 pe.index = MVPP2_PE_DSA_DEFAULT;
2743 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_VLAN);
2744
2745 /* Shift 0 bytes */
2746 mvpp2_prs_sram_shift_set(&pe, 0, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2747 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC);
2748
2749 /* Clear all sram ai bits for next iteration */
2750 mvpp2_prs_sram_ai_update(&pe, 0, MVPP2_PRS_SRAM_AI_MASK);
2751
2752 /* Unmask all ports */
2753 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2754
2755 mvpp2_prs_hw_write(priv, &pe);
2756}
2757
2758/* Match basic ethertypes */
2759static int mvpp2_prs_etype_init(struct mvpp2 *priv)
2760{
2761 struct mvpp2_prs_entry pe;
2762 int tid;
2763
2764 /* Ethertype: PPPoE */
2765 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2766 MVPP2_PE_LAST_FREE_TID);
2767 if (tid < 0)
2768 return tid;
2769
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002770 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002771 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
2772 pe.index = tid;
2773
2774 mvpp2_prs_match_etype(&pe, 0, ETH_P_PPP_SES);
2775
2776 mvpp2_prs_sram_shift_set(&pe, MVPP2_PPPOE_HDR_SIZE,
2777 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2778 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_PPPOE);
2779 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_PPPOE_MASK,
2780 MVPP2_PRS_RI_PPPOE_MASK);
2781
2782 /* Update shadow table and hw entry */
2783 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
2784 priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
2785 priv->prs_shadow[pe.index].finish = false;
2786 mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_PPPOE_MASK,
2787 MVPP2_PRS_RI_PPPOE_MASK);
2788 mvpp2_prs_hw_write(priv, &pe);
2789
2790 /* Ethertype: ARP */
2791 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2792 MVPP2_PE_LAST_FREE_TID);
2793 if (tid < 0)
2794 return tid;
2795
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002796 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002797 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
2798 pe.index = tid;
2799
2800 mvpp2_prs_match_etype(&pe, 0, ETH_P_ARP);
2801
2802 /* Generate flow in the next iteration*/
2803 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
2804 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
2805 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_ARP,
2806 MVPP2_PRS_RI_L3_PROTO_MASK);
2807 /* Set L3 offset */
2808 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
2809 MVPP2_ETH_TYPE_LEN,
2810 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
2811
2812 /* Update shadow table and hw entry */
2813 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
2814 priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
2815 priv->prs_shadow[pe.index].finish = true;
2816 mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_ARP,
2817 MVPP2_PRS_RI_L3_PROTO_MASK);
2818 mvpp2_prs_hw_write(priv, &pe);
2819
2820 /* Ethertype: LBTD */
2821 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2822 MVPP2_PE_LAST_FREE_TID);
2823 if (tid < 0)
2824 return tid;
2825
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002826 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002827 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
2828 pe.index = tid;
2829
2830 mvpp2_prs_match_etype(&pe, 0, MVPP2_IP_LBDT_TYPE);
2831
2832 /* Generate flow in the next iteration*/
2833 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
2834 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
2835 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_CPU_CODE_RX_SPEC |
2836 MVPP2_PRS_RI_UDF3_RX_SPECIAL,
2837 MVPP2_PRS_RI_CPU_CODE_MASK |
2838 MVPP2_PRS_RI_UDF3_MASK);
2839 /* Set L3 offset */
2840 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
2841 MVPP2_ETH_TYPE_LEN,
2842 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
2843
2844 /* Update shadow table and hw entry */
2845 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
2846 priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
2847 priv->prs_shadow[pe.index].finish = true;
2848 mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_CPU_CODE_RX_SPEC |
2849 MVPP2_PRS_RI_UDF3_RX_SPECIAL,
2850 MVPP2_PRS_RI_CPU_CODE_MASK |
2851 MVPP2_PRS_RI_UDF3_MASK);
2852 mvpp2_prs_hw_write(priv, &pe);
2853
2854 /* Ethertype: IPv4 without options */
2855 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2856 MVPP2_PE_LAST_FREE_TID);
2857 if (tid < 0)
2858 return tid;
2859
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002860 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002861 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
2862 pe.index = tid;
2863
2864 mvpp2_prs_match_etype(&pe, 0, ETH_P_IP);
2865 mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN,
2866 MVPP2_PRS_IPV4_HEAD | MVPP2_PRS_IPV4_IHL,
2867 MVPP2_PRS_IPV4_HEAD_MASK |
2868 MVPP2_PRS_IPV4_IHL_MASK);
2869
2870 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4);
2871 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4,
2872 MVPP2_PRS_RI_L3_PROTO_MASK);
2873 /* Skip eth_type + 4 bytes of IP header */
2874 mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 4,
2875 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2876 /* Set L3 offset */
2877 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
2878 MVPP2_ETH_TYPE_LEN,
2879 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
2880
2881 /* Update shadow table and hw entry */
2882 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
2883 priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
2884 priv->prs_shadow[pe.index].finish = false;
2885 mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_IP4,
2886 MVPP2_PRS_RI_L3_PROTO_MASK);
2887 mvpp2_prs_hw_write(priv, &pe);
2888
2889 /* Ethertype: IPv4 with options */
2890 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2891 MVPP2_PE_LAST_FREE_TID);
2892 if (tid < 0)
2893 return tid;
2894
2895 pe.index = tid;
2896
2897 /* Clear tcam data before updating */
2898 pe.tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE(MVPP2_ETH_TYPE_LEN)] = 0x0;
2899 pe.tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE_EN(MVPP2_ETH_TYPE_LEN)] = 0x0;
2900
2901 mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN,
2902 MVPP2_PRS_IPV4_HEAD,
2903 MVPP2_PRS_IPV4_HEAD_MASK);
2904
2905 /* Clear ri before updating */
2906 pe.sram.word[MVPP2_PRS_SRAM_RI_WORD] = 0x0;
2907 pe.sram.word[MVPP2_PRS_SRAM_RI_CTRL_WORD] = 0x0;
2908 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4_OPT,
2909 MVPP2_PRS_RI_L3_PROTO_MASK);
2910
2911 /* Update shadow table and hw entry */
2912 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
2913 priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
2914 priv->prs_shadow[pe.index].finish = false;
2915 mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_IP4_OPT,
2916 MVPP2_PRS_RI_L3_PROTO_MASK);
2917 mvpp2_prs_hw_write(priv, &pe);
2918
2919 /* Ethertype: IPv6 without options */
2920 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
2921 MVPP2_PE_LAST_FREE_TID);
2922 if (tid < 0)
2923 return tid;
2924
Markus Elfringc5b2ce22017-04-17 10:30:29 +02002925 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03002926 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
2927 pe.index = tid;
2928
2929 mvpp2_prs_match_etype(&pe, 0, ETH_P_IPV6);
2930
2931 /* Skip DIP of IPV6 header */
2932 mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 8 +
2933 MVPP2_MAX_L3_ADDR_SIZE,
2934 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
2935 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6);
2936 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP6,
2937 MVPP2_PRS_RI_L3_PROTO_MASK);
2938 /* Set L3 offset */
2939 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
2940 MVPP2_ETH_TYPE_LEN,
2941 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
2942
2943 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
2944 priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
2945 priv->prs_shadow[pe.index].finish = false;
2946 mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_IP6,
2947 MVPP2_PRS_RI_L3_PROTO_MASK);
2948 mvpp2_prs_hw_write(priv, &pe);
2949
2950 /* Default entry for MVPP2_PRS_LU_L2 - Unknown ethtype */
2951 memset(&pe, 0, sizeof(struct mvpp2_prs_entry));
2952 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
2953 pe.index = MVPP2_PE_ETH_TYPE_UN;
2954
2955 /* Unmask all ports */
2956 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
2957
2958 /* Generate flow in the next iteration*/
2959 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
2960 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
2961 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UN,
2962 MVPP2_PRS_RI_L3_PROTO_MASK);
2963 /* Set L3 offset even it's unknown L3 */
2964 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
2965 MVPP2_ETH_TYPE_LEN,
2966 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
2967
2968 /* Update shadow table and hw entry */
2969 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
2970 priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
2971 priv->prs_shadow[pe.index].finish = true;
2972 mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_UN,
2973 MVPP2_PRS_RI_L3_PROTO_MASK);
2974 mvpp2_prs_hw_write(priv, &pe);
2975
2976 return 0;
2977}
2978
2979/* Configure vlan entries and detect up to 2 successive VLAN tags.
2980 * Possible options:
2981 * 0x8100, 0x88A8
2982 * 0x8100, 0x8100
2983 * 0x8100
2984 * 0x88A8
2985 */
2986static int mvpp2_prs_vlan_init(struct platform_device *pdev, struct mvpp2 *priv)
2987{
2988 struct mvpp2_prs_entry pe;
2989 int err;
2990
2991 priv->prs_double_vlans = devm_kcalloc(&pdev->dev, sizeof(bool),
2992 MVPP2_PRS_DBL_VLANS_MAX,
2993 GFP_KERNEL);
2994 if (!priv->prs_double_vlans)
2995 return -ENOMEM;
2996
2997 /* Double VLAN: 0x8100, 0x88A8 */
2998 err = mvpp2_prs_double_vlan_add(priv, ETH_P_8021Q, ETH_P_8021AD,
2999 MVPP2_PRS_PORT_MASK);
3000 if (err)
3001 return err;
3002
3003 /* Double VLAN: 0x8100, 0x8100 */
3004 err = mvpp2_prs_double_vlan_add(priv, ETH_P_8021Q, ETH_P_8021Q,
3005 MVPP2_PRS_PORT_MASK);
3006 if (err)
3007 return err;
3008
3009 /* Single VLAN: 0x88a8 */
3010 err = mvpp2_prs_vlan_add(priv, ETH_P_8021AD, MVPP2_PRS_SINGLE_VLAN_AI,
3011 MVPP2_PRS_PORT_MASK);
3012 if (err)
3013 return err;
3014
3015 /* Single VLAN: 0x8100 */
3016 err = mvpp2_prs_vlan_add(priv, ETH_P_8021Q, MVPP2_PRS_SINGLE_VLAN_AI,
3017 MVPP2_PRS_PORT_MASK);
3018 if (err)
3019 return err;
3020
3021 /* Set default double vlan entry */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003022 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003023 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_VLAN);
3024 pe.index = MVPP2_PE_VLAN_DBL;
3025
3026 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2);
3027 /* Clear ai for next iterations */
3028 mvpp2_prs_sram_ai_update(&pe, 0, MVPP2_PRS_SRAM_AI_MASK);
3029 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_DOUBLE,
3030 MVPP2_PRS_RI_VLAN_MASK);
3031
3032 mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_DBL_VLAN_AI_BIT,
3033 MVPP2_PRS_DBL_VLAN_AI_BIT);
3034 /* Unmask all ports */
3035 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
3036
3037 /* Update shadow table and hw entry */
3038 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_VLAN);
3039 mvpp2_prs_hw_write(priv, &pe);
3040
3041 /* Set default vlan none entry */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003042 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003043 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_VLAN);
3044 pe.index = MVPP2_PE_VLAN_NONE;
3045
3046 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2);
3047 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_NONE,
3048 MVPP2_PRS_RI_VLAN_MASK);
3049
3050 /* Unmask all ports */
3051 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
3052
3053 /* Update shadow table and hw entry */
3054 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_VLAN);
3055 mvpp2_prs_hw_write(priv, &pe);
3056
3057 return 0;
3058}
3059
3060/* Set entries for PPPoE ethertype */
3061static int mvpp2_prs_pppoe_init(struct mvpp2 *priv)
3062{
3063 struct mvpp2_prs_entry pe;
3064 int tid;
3065
3066 /* IPv4 over PPPoE with options */
3067 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
3068 MVPP2_PE_LAST_FREE_TID);
3069 if (tid < 0)
3070 return tid;
3071
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003072 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003073 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_PPPOE);
3074 pe.index = tid;
3075
3076 mvpp2_prs_match_etype(&pe, 0, PPP_IP);
3077
3078 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4);
3079 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4_OPT,
3080 MVPP2_PRS_RI_L3_PROTO_MASK);
3081 /* Skip eth_type + 4 bytes of IP header */
3082 mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 4,
3083 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
3084 /* Set L3 offset */
3085 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
3086 MVPP2_ETH_TYPE_LEN,
3087 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
3088
3089 /* Update shadow table and hw entry */
3090 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE);
3091 mvpp2_prs_hw_write(priv, &pe);
3092
3093 /* IPv4 over PPPoE without options */
3094 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
3095 MVPP2_PE_LAST_FREE_TID);
3096 if (tid < 0)
3097 return tid;
3098
3099 pe.index = tid;
3100
3101 mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN,
3102 MVPP2_PRS_IPV4_HEAD | MVPP2_PRS_IPV4_IHL,
3103 MVPP2_PRS_IPV4_HEAD_MASK |
3104 MVPP2_PRS_IPV4_IHL_MASK);
3105
3106 /* Clear ri before updating */
3107 pe.sram.word[MVPP2_PRS_SRAM_RI_WORD] = 0x0;
3108 pe.sram.word[MVPP2_PRS_SRAM_RI_CTRL_WORD] = 0x0;
3109 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4,
3110 MVPP2_PRS_RI_L3_PROTO_MASK);
3111
3112 /* Update shadow table and hw entry */
3113 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE);
3114 mvpp2_prs_hw_write(priv, &pe);
3115
3116 /* IPv6 over PPPoE */
3117 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
3118 MVPP2_PE_LAST_FREE_TID);
3119 if (tid < 0)
3120 return tid;
3121
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003122 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003123 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_PPPOE);
3124 pe.index = tid;
3125
3126 mvpp2_prs_match_etype(&pe, 0, PPP_IPV6);
3127
3128 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6);
3129 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP6,
3130 MVPP2_PRS_RI_L3_PROTO_MASK);
3131 /* Skip eth_type + 4 bytes of IPv6 header */
3132 mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 4,
3133 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
3134 /* Set L3 offset */
3135 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
3136 MVPP2_ETH_TYPE_LEN,
3137 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
3138
3139 /* Update shadow table and hw entry */
3140 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE);
3141 mvpp2_prs_hw_write(priv, &pe);
3142
3143 /* Non-IP over PPPoE */
3144 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
3145 MVPP2_PE_LAST_FREE_TID);
3146 if (tid < 0)
3147 return tid;
3148
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003149 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003150 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_PPPOE);
3151 pe.index = tid;
3152
3153 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UN,
3154 MVPP2_PRS_RI_L3_PROTO_MASK);
3155
3156 /* Finished: go to flowid generation */
3157 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
3158 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
3159 /* Set L3 offset even if it's unknown L3 */
3160 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
3161 MVPP2_ETH_TYPE_LEN,
3162 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
3163
3164 /* Update shadow table and hw entry */
3165 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE);
3166 mvpp2_prs_hw_write(priv, &pe);
3167
3168 return 0;
3169}
3170
3171/* Initialize entries for IPv4 */
3172static int mvpp2_prs_ip4_init(struct mvpp2 *priv)
3173{
3174 struct mvpp2_prs_entry pe;
3175 int err;
3176
3177 /* Set entries for TCP, UDP and IGMP over IPv4 */
3178 err = mvpp2_prs_ip4_proto(priv, IPPROTO_TCP, MVPP2_PRS_RI_L4_TCP,
3179 MVPP2_PRS_RI_L4_PROTO_MASK);
3180 if (err)
3181 return err;
3182
3183 err = mvpp2_prs_ip4_proto(priv, IPPROTO_UDP, MVPP2_PRS_RI_L4_UDP,
3184 MVPP2_PRS_RI_L4_PROTO_MASK);
3185 if (err)
3186 return err;
3187
3188 err = mvpp2_prs_ip4_proto(priv, IPPROTO_IGMP,
3189 MVPP2_PRS_RI_CPU_CODE_RX_SPEC |
3190 MVPP2_PRS_RI_UDF3_RX_SPECIAL,
3191 MVPP2_PRS_RI_CPU_CODE_MASK |
3192 MVPP2_PRS_RI_UDF3_MASK);
3193 if (err)
3194 return err;
3195
3196 /* IPv4 Broadcast */
3197 err = mvpp2_prs_ip4_cast(priv, MVPP2_PRS_L3_BROAD_CAST);
3198 if (err)
3199 return err;
3200
3201 /* IPv4 Multicast */
3202 err = mvpp2_prs_ip4_cast(priv, MVPP2_PRS_L3_MULTI_CAST);
3203 if (err)
3204 return err;
3205
3206 /* Default IPv4 entry for unknown protocols */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003207 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003208 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4);
3209 pe.index = MVPP2_PE_IP4_PROTO_UN;
3210
3211 /* Set next lu to IPv4 */
3212 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4);
3213 mvpp2_prs_sram_shift_set(&pe, 12, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
3214 /* Set L4 offset */
3215 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4,
3216 sizeof(struct iphdr) - 4,
3217 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
3218 mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT,
3219 MVPP2_PRS_IPV4_DIP_AI_BIT);
3220 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L4_OTHER,
3221 MVPP2_PRS_RI_L4_PROTO_MASK);
3222
3223 mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV4_DIP_AI_BIT);
3224 /* Unmask all ports */
3225 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
3226
3227 /* Update shadow table and hw entry */
3228 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
3229 mvpp2_prs_hw_write(priv, &pe);
3230
3231 /* Default IPv4 entry for unicast address */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003232 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003233 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4);
3234 pe.index = MVPP2_PE_IP4_ADDR_UN;
3235
3236 /* Finished: go to flowid generation */
3237 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
3238 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
3239 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UCAST,
3240 MVPP2_PRS_RI_L3_ADDR_MASK);
3241
3242 mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT,
3243 MVPP2_PRS_IPV4_DIP_AI_BIT);
3244 /* Unmask all ports */
3245 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
3246
3247 /* Update shadow table and hw entry */
3248 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
3249 mvpp2_prs_hw_write(priv, &pe);
3250
3251 return 0;
3252}
3253
3254/* Initialize entries for IPv6 */
3255static int mvpp2_prs_ip6_init(struct mvpp2 *priv)
3256{
3257 struct mvpp2_prs_entry pe;
3258 int tid, err;
3259
3260 /* Set entries for TCP, UDP and ICMP over IPv6 */
3261 err = mvpp2_prs_ip6_proto(priv, IPPROTO_TCP,
3262 MVPP2_PRS_RI_L4_TCP,
3263 MVPP2_PRS_RI_L4_PROTO_MASK);
3264 if (err)
3265 return err;
3266
3267 err = mvpp2_prs_ip6_proto(priv, IPPROTO_UDP,
3268 MVPP2_PRS_RI_L4_UDP,
3269 MVPP2_PRS_RI_L4_PROTO_MASK);
3270 if (err)
3271 return err;
3272
3273 err = mvpp2_prs_ip6_proto(priv, IPPROTO_ICMPV6,
3274 MVPP2_PRS_RI_CPU_CODE_RX_SPEC |
3275 MVPP2_PRS_RI_UDF3_RX_SPECIAL,
3276 MVPP2_PRS_RI_CPU_CODE_MASK |
3277 MVPP2_PRS_RI_UDF3_MASK);
3278 if (err)
3279 return err;
3280
3281 /* IPv4 is the last header. This is similar case as 6-TCP or 17-UDP */
3282 /* Result Info: UDF7=1, DS lite */
3283 err = mvpp2_prs_ip6_proto(priv, IPPROTO_IPIP,
3284 MVPP2_PRS_RI_UDF7_IP6_LITE,
3285 MVPP2_PRS_RI_UDF7_MASK);
3286 if (err)
3287 return err;
3288
3289 /* IPv6 multicast */
3290 err = mvpp2_prs_ip6_cast(priv, MVPP2_PRS_L3_MULTI_CAST);
3291 if (err)
3292 return err;
3293
3294 /* Entry for checking hop limit */
3295 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
3296 MVPP2_PE_LAST_FREE_TID);
3297 if (tid < 0)
3298 return tid;
3299
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003300 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003301 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6);
3302 pe.index = tid;
3303
3304 /* Finished: go to flowid generation */
3305 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
3306 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
3307 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UN |
3308 MVPP2_PRS_RI_DROP_MASK,
3309 MVPP2_PRS_RI_L3_PROTO_MASK |
3310 MVPP2_PRS_RI_DROP_MASK);
3311
3312 mvpp2_prs_tcam_data_byte_set(&pe, 1, 0x00, MVPP2_PRS_IPV6_HOP_MASK);
3313 mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT,
3314 MVPP2_PRS_IPV6_NO_EXT_AI_BIT);
3315
3316 /* Update shadow table and hw entry */
3317 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
3318 mvpp2_prs_hw_write(priv, &pe);
3319
3320 /* Default IPv6 entry for unknown protocols */
Markus Elfringc5b2ce22017-04-17 10:30:29 +02003321 memset(&pe, 0, sizeof(pe));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003322 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6);
3323 pe.index = MVPP2_PE_IP6_PROTO_UN;
3324
3325 /* Finished: go to flowid generation */
3326 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
3327 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
3328 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L4_OTHER,
3329 MVPP2_PRS_RI_L4_PROTO_MASK);
3330 /* Set L4 offset relatively to our current place */
3331 mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4,
3332 sizeof(struct ipv6hdr) - 4,
3333 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
3334
3335 mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT,
3336 MVPP2_PRS_IPV6_NO_EXT_AI_BIT);
3337 /* Unmask all ports */
3338 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
3339
3340 /* Update shadow table and hw entry */
3341 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
3342 mvpp2_prs_hw_write(priv, &pe);
3343
3344 /* Default IPv6 entry for unknown ext protocols */
3345 memset(&pe, 0, sizeof(struct mvpp2_prs_entry));
3346 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6);
3347 pe.index = MVPP2_PE_IP6_EXT_PROTO_UN;
3348
3349 /* Finished: go to flowid generation */
3350 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
3351 mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
3352 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L4_OTHER,
3353 MVPP2_PRS_RI_L4_PROTO_MASK);
3354
3355 mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_EXT_AI_BIT,
3356 MVPP2_PRS_IPV6_EXT_AI_BIT);
3357 /* Unmask all ports */
3358 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
3359
3360 /* Update shadow table and hw entry */
3361 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4);
3362 mvpp2_prs_hw_write(priv, &pe);
3363
3364 /* Default IPv6 entry for unicast address */
3365 memset(&pe, 0, sizeof(struct mvpp2_prs_entry));
3366 mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6);
3367 pe.index = MVPP2_PE_IP6_ADDR_UN;
3368
3369 /* Finished: go to IPv6 again */
3370 mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6);
3371 mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UCAST,
3372 MVPP2_PRS_RI_L3_ADDR_MASK);
3373 mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT,
3374 MVPP2_PRS_IPV6_NO_EXT_AI_BIT);
3375 /* Shift back to IPV6 NH */
3376 mvpp2_prs_sram_shift_set(&pe, -18, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
3377
3378 mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV6_NO_EXT_AI_BIT);
3379 /* Unmask all ports */
3380 mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK);
3381
3382 /* Update shadow table and hw entry */
3383 mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP6);
3384 mvpp2_prs_hw_write(priv, &pe);
3385
3386 return 0;
3387}
3388
3389/* Parser default initialization */
3390static int mvpp2_prs_default_init(struct platform_device *pdev,
3391 struct mvpp2 *priv)
3392{
3393 int err, index, i;
3394
3395 /* Enable tcam table */
3396 mvpp2_write(priv, MVPP2_PRS_TCAM_CTRL_REG, MVPP2_PRS_TCAM_EN_MASK);
3397
3398 /* Clear all tcam and sram entries */
3399 for (index = 0; index < MVPP2_PRS_TCAM_SRAM_SIZE; index++) {
3400 mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, index);
3401 for (i = 0; i < MVPP2_PRS_TCAM_WORDS; i++)
3402 mvpp2_write(priv, MVPP2_PRS_TCAM_DATA_REG(i), 0);
3403
3404 mvpp2_write(priv, MVPP2_PRS_SRAM_IDX_REG, index);
3405 for (i = 0; i < MVPP2_PRS_SRAM_WORDS; i++)
3406 mvpp2_write(priv, MVPP2_PRS_SRAM_DATA_REG(i), 0);
3407 }
3408
3409 /* Invalidate all tcam entries */
3410 for (index = 0; index < MVPP2_PRS_TCAM_SRAM_SIZE; index++)
3411 mvpp2_prs_hw_inv(priv, index);
3412
3413 priv->prs_shadow = devm_kcalloc(&pdev->dev, MVPP2_PRS_TCAM_SRAM_SIZE,
Markus Elfring37df25e2017-04-17 09:12:34 +02003414 sizeof(*priv->prs_shadow),
Marcin Wojtas3f518502014-07-10 16:52:13 -03003415 GFP_KERNEL);
3416 if (!priv->prs_shadow)
3417 return -ENOMEM;
3418
3419 /* Always start from lookup = 0 */
3420 for (index = 0; index < MVPP2_MAX_PORTS; index++)
3421 mvpp2_prs_hw_port_init(priv, index, MVPP2_PRS_LU_MH,
3422 MVPP2_PRS_PORT_LU_MAX, 0);
3423
3424 mvpp2_prs_def_flow_init(priv);
3425
3426 mvpp2_prs_mh_init(priv);
3427
3428 mvpp2_prs_mac_init(priv);
3429
3430 mvpp2_prs_dsa_init(priv);
3431
3432 err = mvpp2_prs_etype_init(priv);
3433 if (err)
3434 return err;
3435
3436 err = mvpp2_prs_vlan_init(pdev, priv);
3437 if (err)
3438 return err;
3439
3440 err = mvpp2_prs_pppoe_init(priv);
3441 if (err)
3442 return err;
3443
3444 err = mvpp2_prs_ip6_init(priv);
3445 if (err)
3446 return err;
3447
3448 err = mvpp2_prs_ip4_init(priv);
3449 if (err)
3450 return err;
3451
3452 return 0;
3453}
3454
3455/* Compare MAC DA with tcam entry data */
3456static bool mvpp2_prs_mac_range_equals(struct mvpp2_prs_entry *pe,
3457 const u8 *da, unsigned char *mask)
3458{
3459 unsigned char tcam_byte, tcam_mask;
3460 int index;
3461
3462 for (index = 0; index < ETH_ALEN; index++) {
3463 mvpp2_prs_tcam_data_byte_get(pe, index, &tcam_byte, &tcam_mask);
3464 if (tcam_mask != mask[index])
3465 return false;
3466
3467 if ((tcam_mask & tcam_byte) != (da[index] & mask[index]))
3468 return false;
3469 }
3470
3471 return true;
3472}
3473
3474/* Find tcam entry with matched pair <MAC DA, port> */
3475static struct mvpp2_prs_entry *
3476mvpp2_prs_mac_da_range_find(struct mvpp2 *priv, int pmap, const u8 *da,
3477 unsigned char *mask, int udf_type)
3478{
3479 struct mvpp2_prs_entry *pe;
3480 int tid;
3481
Antoine Tenart239dd4e2017-10-24 11:41:28 +02003482 pe = kzalloc(sizeof(*pe), GFP_ATOMIC);
Marcin Wojtas3f518502014-07-10 16:52:13 -03003483 if (!pe)
3484 return NULL;
3485 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_MAC);
3486
3487 /* Go through the all entires with MVPP2_PRS_LU_MAC */
3488 for (tid = MVPP2_PE_FIRST_FREE_TID;
3489 tid <= MVPP2_PE_LAST_FREE_TID; tid++) {
3490 unsigned int entry_pmap;
3491
3492 if (!priv->prs_shadow[tid].valid ||
3493 (priv->prs_shadow[tid].lu != MVPP2_PRS_LU_MAC) ||
3494 (priv->prs_shadow[tid].udf != udf_type))
3495 continue;
3496
3497 pe->index = tid;
3498 mvpp2_prs_hw_read(priv, pe);
3499 entry_pmap = mvpp2_prs_tcam_port_map_get(pe);
3500
3501 if (mvpp2_prs_mac_range_equals(pe, da, mask) &&
3502 entry_pmap == pmap)
3503 return pe;
3504 }
3505 kfree(pe);
3506
3507 return NULL;
3508}
3509
3510/* Update parser's mac da entry */
3511static int mvpp2_prs_mac_da_accept(struct mvpp2 *priv, int port,
3512 const u8 *da, bool add)
3513{
3514 struct mvpp2_prs_entry *pe;
3515 unsigned int pmap, len, ri;
3516 unsigned char mask[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3517 int tid;
3518
3519 /* Scan TCAM and see if entry with this <MAC DA, port> already exist */
3520 pe = mvpp2_prs_mac_da_range_find(priv, (1 << port), da, mask,
3521 MVPP2_PRS_UDF_MAC_DEF);
3522
3523 /* No such entry */
3524 if (!pe) {
3525 if (!add)
3526 return 0;
3527
3528 /* Create new TCAM entry */
3529 /* Find first range mac entry*/
3530 for (tid = MVPP2_PE_FIRST_FREE_TID;
3531 tid <= MVPP2_PE_LAST_FREE_TID; tid++)
3532 if (priv->prs_shadow[tid].valid &&
3533 (priv->prs_shadow[tid].lu == MVPP2_PRS_LU_MAC) &&
3534 (priv->prs_shadow[tid].udf ==
3535 MVPP2_PRS_UDF_MAC_RANGE))
3536 break;
3537
3538 /* Go through the all entries from first to last */
3539 tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
3540 tid - 1);
3541 if (tid < 0)
3542 return tid;
3543
Antoine Tenart239dd4e2017-10-24 11:41:28 +02003544 pe = kzalloc(sizeof(*pe), GFP_ATOMIC);
Marcin Wojtas3f518502014-07-10 16:52:13 -03003545 if (!pe)
Amitoj Kaur Chawlac2bb7bc2016-02-04 19:25:26 +05303546 return -ENOMEM;
Marcin Wojtas3f518502014-07-10 16:52:13 -03003547 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_MAC);
3548 pe->index = tid;
3549
3550 /* Mask all ports */
3551 mvpp2_prs_tcam_port_map_set(pe, 0);
3552 }
3553
3554 /* Update port mask */
3555 mvpp2_prs_tcam_port_set(pe, port, add);
3556
3557 /* Invalidate the entry if no ports are left enabled */
3558 pmap = mvpp2_prs_tcam_port_map_get(pe);
3559 if (pmap == 0) {
3560 if (add) {
3561 kfree(pe);
Amitoj Kaur Chawlac2bb7bc2016-02-04 19:25:26 +05303562 return -EINVAL;
Marcin Wojtas3f518502014-07-10 16:52:13 -03003563 }
3564 mvpp2_prs_hw_inv(priv, pe->index);
3565 priv->prs_shadow[pe->index].valid = false;
3566 kfree(pe);
3567 return 0;
3568 }
3569
3570 /* Continue - set next lookup */
3571 mvpp2_prs_sram_next_lu_set(pe, MVPP2_PRS_LU_DSA);
3572
3573 /* Set match on DA */
3574 len = ETH_ALEN;
3575 while (len--)
3576 mvpp2_prs_tcam_data_byte_set(pe, len, da[len], 0xff);
3577
3578 /* Set result info bits */
3579 if (is_broadcast_ether_addr(da))
3580 ri = MVPP2_PRS_RI_L2_BCAST;
3581 else if (is_multicast_ether_addr(da))
3582 ri = MVPP2_PRS_RI_L2_MCAST;
3583 else
3584 ri = MVPP2_PRS_RI_L2_UCAST | MVPP2_PRS_RI_MAC_ME_MASK;
3585
3586 mvpp2_prs_sram_ri_update(pe, ri, MVPP2_PRS_RI_L2_CAST_MASK |
3587 MVPP2_PRS_RI_MAC_ME_MASK);
3588 mvpp2_prs_shadow_ri_set(priv, pe->index, ri, MVPP2_PRS_RI_L2_CAST_MASK |
3589 MVPP2_PRS_RI_MAC_ME_MASK);
3590
3591 /* Shift to ethertype */
3592 mvpp2_prs_sram_shift_set(pe, 2 * ETH_ALEN,
3593 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
3594
3595 /* Update shadow table and hw entry */
3596 priv->prs_shadow[pe->index].udf = MVPP2_PRS_UDF_MAC_DEF;
3597 mvpp2_prs_shadow_set(priv, pe->index, MVPP2_PRS_LU_MAC);
3598 mvpp2_prs_hw_write(priv, pe);
3599
3600 kfree(pe);
3601
3602 return 0;
3603}
3604
3605static int mvpp2_prs_update_mac_da(struct net_device *dev, const u8 *da)
3606{
3607 struct mvpp2_port *port = netdev_priv(dev);
3608 int err;
3609
3610 /* Remove old parser entry */
3611 err = mvpp2_prs_mac_da_accept(port->priv, port->id, dev->dev_addr,
3612 false);
3613 if (err)
3614 return err;
3615
3616 /* Add new parser entry */
3617 err = mvpp2_prs_mac_da_accept(port->priv, port->id, da, true);
3618 if (err)
3619 return err;
3620
3621 /* Set addr in the device */
3622 ether_addr_copy(dev->dev_addr, da);
3623
3624 return 0;
3625}
3626
3627/* Delete all port's multicast simple (not range) entries */
3628static void mvpp2_prs_mcast_del_all(struct mvpp2 *priv, int port)
3629{
3630 struct mvpp2_prs_entry pe;
3631 int index, tid;
3632
3633 for (tid = MVPP2_PE_FIRST_FREE_TID;
3634 tid <= MVPP2_PE_LAST_FREE_TID; tid++) {
3635 unsigned char da[ETH_ALEN], da_mask[ETH_ALEN];
3636
3637 if (!priv->prs_shadow[tid].valid ||
3638 (priv->prs_shadow[tid].lu != MVPP2_PRS_LU_MAC) ||
3639 (priv->prs_shadow[tid].udf != MVPP2_PRS_UDF_MAC_DEF))
3640 continue;
3641
3642 /* Only simple mac entries */
3643 pe.index = tid;
3644 mvpp2_prs_hw_read(priv, &pe);
3645
3646 /* Read mac addr from entry */
3647 for (index = 0; index < ETH_ALEN; index++)
3648 mvpp2_prs_tcam_data_byte_get(&pe, index, &da[index],
3649 &da_mask[index]);
3650
3651 if (is_multicast_ether_addr(da) && !is_broadcast_ether_addr(da))
3652 /* Delete this entry */
3653 mvpp2_prs_mac_da_accept(priv, port, da, false);
3654 }
3655}
3656
3657static int mvpp2_prs_tag_mode_set(struct mvpp2 *priv, int port, int type)
3658{
3659 switch (type) {
3660 case MVPP2_TAG_TYPE_EDSA:
3661 /* Add port to EDSA entries */
3662 mvpp2_prs_dsa_tag_set(priv, port, true,
3663 MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA);
3664 mvpp2_prs_dsa_tag_set(priv, port, true,
3665 MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA);
3666 /* Remove port from DSA entries */
3667 mvpp2_prs_dsa_tag_set(priv, port, false,
3668 MVPP2_PRS_TAGGED, MVPP2_PRS_DSA);
3669 mvpp2_prs_dsa_tag_set(priv, port, false,
3670 MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA);
3671 break;
3672
3673 case MVPP2_TAG_TYPE_DSA:
3674 /* Add port to DSA entries */
3675 mvpp2_prs_dsa_tag_set(priv, port, true,
3676 MVPP2_PRS_TAGGED, MVPP2_PRS_DSA);
3677 mvpp2_prs_dsa_tag_set(priv, port, true,
3678 MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA);
3679 /* Remove port from EDSA entries */
3680 mvpp2_prs_dsa_tag_set(priv, port, false,
3681 MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA);
3682 mvpp2_prs_dsa_tag_set(priv, port, false,
3683 MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA);
3684 break;
3685
3686 case MVPP2_TAG_TYPE_MH:
3687 case MVPP2_TAG_TYPE_NONE:
3688 /* Remove port form EDSA and DSA entries */
3689 mvpp2_prs_dsa_tag_set(priv, port, false,
3690 MVPP2_PRS_TAGGED, MVPP2_PRS_DSA);
3691 mvpp2_prs_dsa_tag_set(priv, port, false,
3692 MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA);
3693 mvpp2_prs_dsa_tag_set(priv, port, false,
3694 MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA);
3695 mvpp2_prs_dsa_tag_set(priv, port, false,
3696 MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA);
3697 break;
3698
3699 default:
3700 if ((type < 0) || (type > MVPP2_TAG_TYPE_EDSA))
3701 return -EINVAL;
3702 }
3703
3704 return 0;
3705}
3706
3707/* Set prs flow for the port */
3708static int mvpp2_prs_def_flow(struct mvpp2_port *port)
3709{
3710 struct mvpp2_prs_entry *pe;
3711 int tid;
3712
3713 pe = mvpp2_prs_flow_find(port->priv, port->id);
3714
3715 /* Such entry not exist */
3716 if (!pe) {
3717 /* Go through the all entires from last to first */
3718 tid = mvpp2_prs_tcam_first_free(port->priv,
3719 MVPP2_PE_LAST_FREE_TID,
3720 MVPP2_PE_FIRST_FREE_TID);
3721 if (tid < 0)
3722 return tid;
3723
3724 pe = kzalloc(sizeof(*pe), GFP_KERNEL);
3725 if (!pe)
3726 return -ENOMEM;
3727
3728 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_FLOWS);
3729 pe->index = tid;
3730
3731 /* Set flow ID*/
3732 mvpp2_prs_sram_ai_update(pe, port->id, MVPP2_PRS_FLOW_ID_MASK);
3733 mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_LU_DONE_BIT, 1);
3734
3735 /* Update shadow table */
3736 mvpp2_prs_shadow_set(port->priv, pe->index, MVPP2_PRS_LU_FLOWS);
3737 }
3738
3739 mvpp2_prs_tcam_port_map_set(pe, (1 << port->id));
3740 mvpp2_prs_hw_write(port->priv, pe);
3741 kfree(pe);
3742
3743 return 0;
3744}
3745
3746/* Classifier configuration routines */
3747
3748/* Update classification flow table registers */
3749static void mvpp2_cls_flow_write(struct mvpp2 *priv,
3750 struct mvpp2_cls_flow_entry *fe)
3751{
3752 mvpp2_write(priv, MVPP2_CLS_FLOW_INDEX_REG, fe->index);
3753 mvpp2_write(priv, MVPP2_CLS_FLOW_TBL0_REG, fe->data[0]);
3754 mvpp2_write(priv, MVPP2_CLS_FLOW_TBL1_REG, fe->data[1]);
3755 mvpp2_write(priv, MVPP2_CLS_FLOW_TBL2_REG, fe->data[2]);
3756}
3757
3758/* Update classification lookup table register */
3759static void mvpp2_cls_lookup_write(struct mvpp2 *priv,
3760 struct mvpp2_cls_lookup_entry *le)
3761{
3762 u32 val;
3763
3764 val = (le->way << MVPP2_CLS_LKP_INDEX_WAY_OFFS) | le->lkpid;
3765 mvpp2_write(priv, MVPP2_CLS_LKP_INDEX_REG, val);
3766 mvpp2_write(priv, MVPP2_CLS_LKP_TBL_REG, le->data);
3767}
3768
3769/* Classifier default initialization */
3770static void mvpp2_cls_init(struct mvpp2 *priv)
3771{
3772 struct mvpp2_cls_lookup_entry le;
3773 struct mvpp2_cls_flow_entry fe;
3774 int index;
3775
3776 /* Enable classifier */
3777 mvpp2_write(priv, MVPP2_CLS_MODE_REG, MVPP2_CLS_MODE_ACTIVE_MASK);
3778
3779 /* Clear classifier flow table */
Arnd Bergmanne8f967c2016-11-24 17:28:12 +01003780 memset(&fe.data, 0, sizeof(fe.data));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003781 for (index = 0; index < MVPP2_CLS_FLOWS_TBL_SIZE; index++) {
3782 fe.index = index;
3783 mvpp2_cls_flow_write(priv, &fe);
3784 }
3785
3786 /* Clear classifier lookup table */
3787 le.data = 0;
3788 for (index = 0; index < MVPP2_CLS_LKP_TBL_SIZE; index++) {
3789 le.lkpid = index;
3790 le.way = 0;
3791 mvpp2_cls_lookup_write(priv, &le);
3792
3793 le.way = 1;
3794 mvpp2_cls_lookup_write(priv, &le);
3795 }
3796}
3797
3798static void mvpp2_cls_port_config(struct mvpp2_port *port)
3799{
3800 struct mvpp2_cls_lookup_entry le;
3801 u32 val;
3802
3803 /* Set way for the port */
3804 val = mvpp2_read(port->priv, MVPP2_CLS_PORT_WAY_REG);
3805 val &= ~MVPP2_CLS_PORT_WAY_MASK(port->id);
3806 mvpp2_write(port->priv, MVPP2_CLS_PORT_WAY_REG, val);
3807
3808 /* Pick the entry to be accessed in lookup ID decoding table
3809 * according to the way and lkpid.
3810 */
3811 le.lkpid = port->id;
3812 le.way = 0;
3813 le.data = 0;
3814
3815 /* Set initial CPU queue for receiving packets */
3816 le.data &= ~MVPP2_CLS_LKP_TBL_RXQ_MASK;
3817 le.data |= port->first_rxq;
3818
3819 /* Disable classification engines */
3820 le.data &= ~MVPP2_CLS_LKP_TBL_LOOKUP_EN_MASK;
3821
3822 /* Update lookup ID table entry */
3823 mvpp2_cls_lookup_write(port->priv, &le);
3824}
3825
3826/* Set CPU queue number for oversize packets */
3827static void mvpp2_cls_oversize_rxq_set(struct mvpp2_port *port)
3828{
3829 u32 val;
3830
3831 mvpp2_write(port->priv, MVPP2_CLS_OVERSIZE_RXQ_LOW_REG(port->id),
3832 port->first_rxq & MVPP2_CLS_OVERSIZE_RXQ_LOW_MASK);
3833
3834 mvpp2_write(port->priv, MVPP2_CLS_SWFWD_P2HQ_REG(port->id),
3835 (port->first_rxq >> MVPP2_CLS_OVERSIZE_RXQ_LOW_BITS));
3836
3837 val = mvpp2_read(port->priv, MVPP2_CLS_SWFWD_PCTRL_REG);
3838 val |= MVPP2_CLS_SWFWD_PCTRL_MASK(port->id);
3839 mvpp2_write(port->priv, MVPP2_CLS_SWFWD_PCTRL_REG, val);
3840}
3841
Thomas Petazzoni0e037282017-02-21 11:28:12 +01003842static void *mvpp2_frag_alloc(const struct mvpp2_bm_pool *pool)
3843{
3844 if (likely(pool->frag_size <= PAGE_SIZE))
3845 return netdev_alloc_frag(pool->frag_size);
3846 else
3847 return kmalloc(pool->frag_size, GFP_ATOMIC);
3848}
3849
3850static void mvpp2_frag_free(const struct mvpp2_bm_pool *pool, void *data)
3851{
3852 if (likely(pool->frag_size <= PAGE_SIZE))
3853 skb_free_frag(data);
3854 else
3855 kfree(data);
3856}
3857
Marcin Wojtas3f518502014-07-10 16:52:13 -03003858/* Buffer Manager configuration routines */
3859
3860/* Create pool */
3861static int mvpp2_bm_pool_create(struct platform_device *pdev,
3862 struct mvpp2 *priv,
3863 struct mvpp2_bm_pool *bm_pool, int size)
3864{
Marcin Wojtas3f518502014-07-10 16:52:13 -03003865 u32 val;
3866
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003867 /* Number of buffer pointers must be a multiple of 16, as per
3868 * hardware constraints
3869 */
3870 if (!IS_ALIGNED(size, 16))
3871 return -EINVAL;
3872
3873 /* PPv2.1 needs 8 bytes per buffer pointer, PPv2.2 needs 16
3874 * bytes per buffer pointer
3875 */
3876 if (priv->hw_version == MVPP21)
3877 bm_pool->size_bytes = 2 * sizeof(u32) * size;
3878 else
3879 bm_pool->size_bytes = 2 * sizeof(u64) * size;
3880
3881 bm_pool->virt_addr = dma_alloc_coherent(&pdev->dev, bm_pool->size_bytes,
Thomas Petazzoni20396132017-03-07 16:53:00 +01003882 &bm_pool->dma_addr,
Marcin Wojtas3f518502014-07-10 16:52:13 -03003883 GFP_KERNEL);
3884 if (!bm_pool->virt_addr)
3885 return -ENOMEM;
3886
Thomas Petazzonid3158802017-02-21 11:28:13 +01003887 if (!IS_ALIGNED((unsigned long)bm_pool->virt_addr,
3888 MVPP2_BM_POOL_PTR_ALIGN)) {
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003889 dma_free_coherent(&pdev->dev, bm_pool->size_bytes,
3890 bm_pool->virt_addr, bm_pool->dma_addr);
Marcin Wojtas3f518502014-07-10 16:52:13 -03003891 dev_err(&pdev->dev, "BM pool %d is not %d bytes aligned\n",
3892 bm_pool->id, MVPP2_BM_POOL_PTR_ALIGN);
3893 return -ENOMEM;
3894 }
3895
3896 mvpp2_write(priv, MVPP2_BM_POOL_BASE_REG(bm_pool->id),
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003897 lower_32_bits(bm_pool->dma_addr));
Marcin Wojtas3f518502014-07-10 16:52:13 -03003898 mvpp2_write(priv, MVPP2_BM_POOL_SIZE_REG(bm_pool->id), size);
3899
3900 val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id));
3901 val |= MVPP2_BM_START_MASK;
3902 mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val);
3903
3904 bm_pool->type = MVPP2_BM_FREE;
3905 bm_pool->size = size;
3906 bm_pool->pkt_size = 0;
3907 bm_pool->buf_num = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03003908
3909 return 0;
3910}
3911
3912/* Set pool buffer size */
3913static void mvpp2_bm_pool_bufsize_set(struct mvpp2 *priv,
3914 struct mvpp2_bm_pool *bm_pool,
3915 int buf_size)
3916{
3917 u32 val;
3918
3919 bm_pool->buf_size = buf_size;
3920
3921 val = ALIGN(buf_size, 1 << MVPP2_POOL_BUF_SIZE_OFFSET);
3922 mvpp2_write(priv, MVPP2_POOL_BUF_SIZE_REG(bm_pool->id), val);
3923}
3924
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003925static void mvpp2_bm_bufs_get_addrs(struct device *dev, struct mvpp2 *priv,
3926 struct mvpp2_bm_pool *bm_pool,
3927 dma_addr_t *dma_addr,
3928 phys_addr_t *phys_addr)
3929{
Thomas Petazzonia704bb52017-06-10 23:18:22 +02003930 int cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01003931
3932 *dma_addr = mvpp2_percpu_read(priv, cpu,
3933 MVPP2_BM_PHY_ALLOC_REG(bm_pool->id));
3934 *phys_addr = mvpp2_percpu_read(priv, cpu, MVPP2_BM_VIRT_ALLOC_REG);
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003935
3936 if (priv->hw_version == MVPP22) {
3937 u32 val;
3938 u32 dma_addr_highbits, phys_addr_highbits;
3939
Thomas Petazzonia7868412017-03-07 16:53:13 +01003940 val = mvpp2_percpu_read(priv, cpu, MVPP22_BM_ADDR_HIGH_ALLOC);
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003941 dma_addr_highbits = (val & MVPP22_BM_ADDR_HIGH_PHYS_MASK);
3942 phys_addr_highbits = (val & MVPP22_BM_ADDR_HIGH_VIRT_MASK) >>
3943 MVPP22_BM_ADDR_HIGH_VIRT_SHIFT;
3944
3945 if (sizeof(dma_addr_t) == 8)
3946 *dma_addr |= (u64)dma_addr_highbits << 32;
3947
3948 if (sizeof(phys_addr_t) == 8)
3949 *phys_addr |= (u64)phys_addr_highbits << 32;
3950 }
Thomas Petazzonia704bb52017-06-10 23:18:22 +02003951
3952 put_cpu();
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003953}
3954
Ezequiel Garcia7861f122014-07-21 13:48:14 -03003955/* Free all buffers from the pool */
Marcin Wojtas4229d502015-12-03 15:20:50 +01003956static void mvpp2_bm_bufs_free(struct device *dev, struct mvpp2 *priv,
3957 struct mvpp2_bm_pool *bm_pool)
Marcin Wojtas3f518502014-07-10 16:52:13 -03003958{
3959 int i;
3960
Ezequiel Garcia7861f122014-07-21 13:48:14 -03003961 for (i = 0; i < bm_pool->buf_num; i++) {
Thomas Petazzoni20396132017-03-07 16:53:00 +01003962 dma_addr_t buf_dma_addr;
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01003963 phys_addr_t buf_phys_addr;
3964 void *data;
Marcin Wojtas3f518502014-07-10 16:52:13 -03003965
Thomas Petazzonid01524d2017-03-07 16:53:09 +01003966 mvpp2_bm_bufs_get_addrs(dev, priv, bm_pool,
3967 &buf_dma_addr, &buf_phys_addr);
Marcin Wojtas4229d502015-12-03 15:20:50 +01003968
Thomas Petazzoni20396132017-03-07 16:53:00 +01003969 dma_unmap_single(dev, buf_dma_addr,
Marcin Wojtas4229d502015-12-03 15:20:50 +01003970 bm_pool->buf_size, DMA_FROM_DEVICE);
3971
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01003972 data = (void *)phys_to_virt(buf_phys_addr);
3973 if (!data)
Marcin Wojtas3f518502014-07-10 16:52:13 -03003974 break;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01003975
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01003976 mvpp2_frag_free(bm_pool, data);
Marcin Wojtas3f518502014-07-10 16:52:13 -03003977 }
3978
3979 /* Update BM driver with number of buffers removed from pool */
3980 bm_pool->buf_num -= i;
Marcin Wojtas3f518502014-07-10 16:52:13 -03003981}
3982
3983/* Cleanup pool */
3984static int mvpp2_bm_pool_destroy(struct platform_device *pdev,
3985 struct mvpp2 *priv,
3986 struct mvpp2_bm_pool *bm_pool)
3987{
Marcin Wojtas3f518502014-07-10 16:52:13 -03003988 u32 val;
3989
Marcin Wojtas4229d502015-12-03 15:20:50 +01003990 mvpp2_bm_bufs_free(&pdev->dev, priv, bm_pool);
Ezequiel Garciad74c96c2014-07-21 13:48:13 -03003991 if (bm_pool->buf_num) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03003992 WARN(1, "cannot free all buffers in pool %d\n", bm_pool->id);
3993 return 0;
3994 }
3995
3996 val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id));
3997 val |= MVPP2_BM_STOP_MASK;
3998 mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val);
3999
Thomas Petazzonid01524d2017-03-07 16:53:09 +01004000 dma_free_coherent(&pdev->dev, bm_pool->size_bytes,
Marcin Wojtas3f518502014-07-10 16:52:13 -03004001 bm_pool->virt_addr,
Thomas Petazzoni20396132017-03-07 16:53:00 +01004002 bm_pool->dma_addr);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004003 return 0;
4004}
4005
4006static int mvpp2_bm_pools_init(struct platform_device *pdev,
4007 struct mvpp2 *priv)
4008{
4009 int i, err, size;
4010 struct mvpp2_bm_pool *bm_pool;
4011
4012 /* Create all pools with maximum size */
4013 size = MVPP2_BM_POOL_SIZE_MAX;
4014 for (i = 0; i < MVPP2_BM_POOLS_NUM; i++) {
4015 bm_pool = &priv->bm_pools[i];
4016 bm_pool->id = i;
4017 err = mvpp2_bm_pool_create(pdev, priv, bm_pool, size);
4018 if (err)
4019 goto err_unroll_pools;
4020 mvpp2_bm_pool_bufsize_set(priv, bm_pool, 0);
4021 }
4022 return 0;
4023
4024err_unroll_pools:
4025 dev_err(&pdev->dev, "failed to create BM pool %d, size %d\n", i, size);
4026 for (i = i - 1; i >= 0; i--)
4027 mvpp2_bm_pool_destroy(pdev, priv, &priv->bm_pools[i]);
4028 return err;
4029}
4030
4031static int mvpp2_bm_init(struct platform_device *pdev, struct mvpp2 *priv)
4032{
4033 int i, err;
4034
4035 for (i = 0; i < MVPP2_BM_POOLS_NUM; i++) {
4036 /* Mask BM all interrupts */
4037 mvpp2_write(priv, MVPP2_BM_INTR_MASK_REG(i), 0);
4038 /* Clear BM cause register */
4039 mvpp2_write(priv, MVPP2_BM_INTR_CAUSE_REG(i), 0);
4040 }
4041
4042 /* Allocate and initialize BM pools */
4043 priv->bm_pools = devm_kcalloc(&pdev->dev, MVPP2_BM_POOLS_NUM,
Markus Elfring81f915e2017-04-17 09:06:33 +02004044 sizeof(*priv->bm_pools), GFP_KERNEL);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004045 if (!priv->bm_pools)
4046 return -ENOMEM;
4047
4048 err = mvpp2_bm_pools_init(pdev, priv);
4049 if (err < 0)
4050 return err;
4051 return 0;
4052}
4053
4054/* Attach long pool to rxq */
4055static void mvpp2_rxq_long_pool_set(struct mvpp2_port *port,
4056 int lrxq, int long_pool)
4057{
Thomas Petazzoni5eac8922017-03-07 16:53:10 +01004058 u32 val, mask;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004059 int prxq;
4060
4061 /* Get queue physical ID */
4062 prxq = port->rxqs[lrxq]->id;
4063
Thomas Petazzoni5eac8922017-03-07 16:53:10 +01004064 if (port->priv->hw_version == MVPP21)
4065 mask = MVPP21_RXQ_POOL_LONG_MASK;
4066 else
4067 mask = MVPP22_RXQ_POOL_LONG_MASK;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004068
Thomas Petazzoni5eac8922017-03-07 16:53:10 +01004069 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(prxq));
4070 val &= ~mask;
4071 val |= (long_pool << MVPP2_RXQ_POOL_LONG_OFFS) & mask;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004072 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(prxq), val);
4073}
4074
4075/* Attach short pool to rxq */
4076static void mvpp2_rxq_short_pool_set(struct mvpp2_port *port,
4077 int lrxq, int short_pool)
4078{
Thomas Petazzoni5eac8922017-03-07 16:53:10 +01004079 u32 val, mask;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004080 int prxq;
4081
4082 /* Get queue physical ID */
4083 prxq = port->rxqs[lrxq]->id;
4084
Thomas Petazzoni5eac8922017-03-07 16:53:10 +01004085 if (port->priv->hw_version == MVPP21)
4086 mask = MVPP21_RXQ_POOL_SHORT_MASK;
4087 else
4088 mask = MVPP22_RXQ_POOL_SHORT_MASK;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004089
Thomas Petazzoni5eac8922017-03-07 16:53:10 +01004090 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(prxq));
4091 val &= ~mask;
4092 val |= (short_pool << MVPP2_RXQ_POOL_SHORT_OFFS) & mask;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004093 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(prxq), val);
4094}
4095
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004096static void *mvpp2_buf_alloc(struct mvpp2_port *port,
4097 struct mvpp2_bm_pool *bm_pool,
Thomas Petazzoni20396132017-03-07 16:53:00 +01004098 dma_addr_t *buf_dma_addr,
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01004099 phys_addr_t *buf_phys_addr,
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004100 gfp_t gfp_mask)
Marcin Wojtas3f518502014-07-10 16:52:13 -03004101{
Thomas Petazzoni20396132017-03-07 16:53:00 +01004102 dma_addr_t dma_addr;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004103 void *data;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004104
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004105 data = mvpp2_frag_alloc(bm_pool);
4106 if (!data)
Marcin Wojtas3f518502014-07-10 16:52:13 -03004107 return NULL;
4108
Thomas Petazzoni20396132017-03-07 16:53:00 +01004109 dma_addr = dma_map_single(port->dev->dev.parent, data,
4110 MVPP2_RX_BUF_SIZE(bm_pool->pkt_size),
4111 DMA_FROM_DEVICE);
4112 if (unlikely(dma_mapping_error(port->dev->dev.parent, dma_addr))) {
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004113 mvpp2_frag_free(bm_pool, data);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004114 return NULL;
4115 }
Thomas Petazzoni20396132017-03-07 16:53:00 +01004116 *buf_dma_addr = dma_addr;
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01004117 *buf_phys_addr = virt_to_phys(data);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004118
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004119 return data;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004120}
4121
Marcin Wojtas3f518502014-07-10 16:52:13 -03004122/* Release buffer to BM */
4123static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool,
Thomas Petazzoni20396132017-03-07 16:53:00 +01004124 dma_addr_t buf_dma_addr,
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01004125 phys_addr_t buf_phys_addr)
Marcin Wojtas3f518502014-07-10 16:52:13 -03004126{
Thomas Petazzonia704bb52017-06-10 23:18:22 +02004127 int cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01004128
Thomas Petazzonid01524d2017-03-07 16:53:09 +01004129 if (port->priv->hw_version == MVPP22) {
4130 u32 val = 0;
4131
4132 if (sizeof(dma_addr_t) == 8)
4133 val |= upper_32_bits(buf_dma_addr) &
4134 MVPP22_BM_ADDR_HIGH_PHYS_RLS_MASK;
4135
4136 if (sizeof(phys_addr_t) == 8)
4137 val |= (upper_32_bits(buf_phys_addr)
4138 << MVPP22_BM_ADDR_HIGH_VIRT_RLS_SHIFT) &
4139 MVPP22_BM_ADDR_HIGH_VIRT_RLS_MASK;
4140
Thomas Petazzonia7868412017-03-07 16:53:13 +01004141 mvpp2_percpu_write(port->priv, cpu,
4142 MVPP22_BM_ADDR_HIGH_RLS_REG, val);
Thomas Petazzonid01524d2017-03-07 16:53:09 +01004143 }
4144
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01004145 /* MVPP2_BM_VIRT_RLS_REG is not interpreted by HW, and simply
4146 * returned in the "cookie" field of the RX
4147 * descriptor. Instead of storing the virtual address, we
4148 * store the physical address
4149 */
Thomas Petazzonia7868412017-03-07 16:53:13 +01004150 mvpp2_percpu_write(port->priv, cpu,
4151 MVPP2_BM_VIRT_RLS_REG, buf_phys_addr);
4152 mvpp2_percpu_write(port->priv, cpu,
4153 MVPP2_BM_PHY_RLS_REG(pool), buf_dma_addr);
Thomas Petazzonia704bb52017-06-10 23:18:22 +02004154
4155 put_cpu();
Marcin Wojtas3f518502014-07-10 16:52:13 -03004156}
4157
Marcin Wojtas3f518502014-07-10 16:52:13 -03004158/* Allocate buffers for the pool */
4159static int mvpp2_bm_bufs_add(struct mvpp2_port *port,
4160 struct mvpp2_bm_pool *bm_pool, int buf_num)
4161{
Marcin Wojtas3f518502014-07-10 16:52:13 -03004162 int i, buf_size, total_size;
Thomas Petazzoni20396132017-03-07 16:53:00 +01004163 dma_addr_t dma_addr;
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01004164 phys_addr_t phys_addr;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004165 void *buf;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004166
4167 buf_size = MVPP2_RX_BUF_SIZE(bm_pool->pkt_size);
4168 total_size = MVPP2_RX_TOTAL_SIZE(buf_size);
4169
4170 if (buf_num < 0 ||
4171 (buf_num + bm_pool->buf_num > bm_pool->size)) {
4172 netdev_err(port->dev,
4173 "cannot allocate %d buffers for pool %d\n",
4174 buf_num, bm_pool->id);
4175 return 0;
4176 }
4177
Marcin Wojtas3f518502014-07-10 16:52:13 -03004178 for (i = 0; i < buf_num; i++) {
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01004179 buf = mvpp2_buf_alloc(port, bm_pool, &dma_addr,
4180 &phys_addr, GFP_KERNEL);
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004181 if (!buf)
Marcin Wojtas3f518502014-07-10 16:52:13 -03004182 break;
4183
Thomas Petazzoni20396132017-03-07 16:53:00 +01004184 mvpp2_bm_pool_put(port, bm_pool->id, dma_addr,
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01004185 phys_addr);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004186 }
4187
4188 /* Update BM driver with number of buffers added to pool */
4189 bm_pool->buf_num += i;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004190
4191 netdev_dbg(port->dev,
4192 "%s pool %d: pkt_size=%4d, buf_size=%4d, total_size=%4d\n",
4193 bm_pool->type == MVPP2_BM_SWF_SHORT ? "short" : " long",
4194 bm_pool->id, bm_pool->pkt_size, buf_size, total_size);
4195
4196 netdev_dbg(port->dev,
4197 "%s pool %d: %d of %d buffers added\n",
4198 bm_pool->type == MVPP2_BM_SWF_SHORT ? "short" : " long",
4199 bm_pool->id, i, buf_num);
4200 return i;
4201}
4202
4203/* Notify the driver that BM pool is being used as specific type and return the
4204 * pool pointer on success
4205 */
4206static struct mvpp2_bm_pool *
4207mvpp2_bm_pool_use(struct mvpp2_port *port, int pool, enum mvpp2_bm_type type,
4208 int pkt_size)
4209{
Marcin Wojtas3f518502014-07-10 16:52:13 -03004210 struct mvpp2_bm_pool *new_pool = &port->priv->bm_pools[pool];
4211 int num;
4212
4213 if (new_pool->type != MVPP2_BM_FREE && new_pool->type != type) {
4214 netdev_err(port->dev, "mixing pool types is forbidden\n");
4215 return NULL;
4216 }
4217
Marcin Wojtas3f518502014-07-10 16:52:13 -03004218 if (new_pool->type == MVPP2_BM_FREE)
4219 new_pool->type = type;
4220
4221 /* Allocate buffers in case BM pool is used as long pool, but packet
4222 * size doesn't match MTU or BM pool hasn't being used yet
4223 */
4224 if (((type == MVPP2_BM_SWF_LONG) && (pkt_size > new_pool->pkt_size)) ||
4225 (new_pool->pkt_size == 0)) {
4226 int pkts_num;
4227
4228 /* Set default buffer number or free all the buffers in case
4229 * the pool is not empty
4230 */
4231 pkts_num = new_pool->buf_num;
4232 if (pkts_num == 0)
4233 pkts_num = type == MVPP2_BM_SWF_LONG ?
4234 MVPP2_BM_LONG_BUF_NUM :
4235 MVPP2_BM_SHORT_BUF_NUM;
4236 else
Marcin Wojtas4229d502015-12-03 15:20:50 +01004237 mvpp2_bm_bufs_free(port->dev->dev.parent,
4238 port->priv, new_pool);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004239
4240 new_pool->pkt_size = pkt_size;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004241 new_pool->frag_size =
4242 SKB_DATA_ALIGN(MVPP2_RX_BUF_SIZE(pkt_size)) +
4243 MVPP2_SKB_SHINFO_SIZE;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004244
4245 /* Allocate buffers for this pool */
4246 num = mvpp2_bm_bufs_add(port, new_pool, pkts_num);
4247 if (num != pkts_num) {
4248 WARN(1, "pool %d: %d of %d allocated\n",
4249 new_pool->id, num, pkts_num);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004250 return NULL;
4251 }
4252 }
4253
4254 mvpp2_bm_pool_bufsize_set(port->priv, new_pool,
4255 MVPP2_RX_BUF_SIZE(new_pool->pkt_size));
4256
Marcin Wojtas3f518502014-07-10 16:52:13 -03004257 return new_pool;
4258}
4259
4260/* Initialize pools for swf */
4261static int mvpp2_swf_bm_pool_init(struct mvpp2_port *port)
4262{
Marcin Wojtas3f518502014-07-10 16:52:13 -03004263 int rxq;
4264
4265 if (!port->pool_long) {
4266 port->pool_long =
4267 mvpp2_bm_pool_use(port, MVPP2_BM_SWF_LONG_POOL(port->id),
4268 MVPP2_BM_SWF_LONG,
4269 port->pkt_size);
4270 if (!port->pool_long)
4271 return -ENOMEM;
4272
Marcin Wojtas3f518502014-07-10 16:52:13 -03004273 port->pool_long->port_map |= (1 << port->id);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004274
Thomas Petazzoni09f83972017-08-03 10:41:57 +02004275 for (rxq = 0; rxq < port->nrxqs; rxq++)
Marcin Wojtas3f518502014-07-10 16:52:13 -03004276 mvpp2_rxq_long_pool_set(port, rxq, port->pool_long->id);
4277 }
4278
4279 if (!port->pool_short) {
4280 port->pool_short =
4281 mvpp2_bm_pool_use(port, MVPP2_BM_SWF_SHORT_POOL,
4282 MVPP2_BM_SWF_SHORT,
4283 MVPP2_BM_SHORT_PKT_SIZE);
4284 if (!port->pool_short)
4285 return -ENOMEM;
4286
Marcin Wojtas3f518502014-07-10 16:52:13 -03004287 port->pool_short->port_map |= (1 << port->id);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004288
Thomas Petazzoni09f83972017-08-03 10:41:57 +02004289 for (rxq = 0; rxq < port->nrxqs; rxq++)
Marcin Wojtas3f518502014-07-10 16:52:13 -03004290 mvpp2_rxq_short_pool_set(port, rxq,
4291 port->pool_short->id);
4292 }
4293
4294 return 0;
4295}
4296
4297static int mvpp2_bm_update_mtu(struct net_device *dev, int mtu)
4298{
4299 struct mvpp2_port *port = netdev_priv(dev);
4300 struct mvpp2_bm_pool *port_pool = port->pool_long;
4301 int num, pkts_num = port_pool->buf_num;
4302 int pkt_size = MVPP2_RX_PKT_SIZE(mtu);
4303
4304 /* Update BM pool with new buffer size */
Marcin Wojtas4229d502015-12-03 15:20:50 +01004305 mvpp2_bm_bufs_free(dev->dev.parent, port->priv, port_pool);
Ezequiel Garciad74c96c2014-07-21 13:48:13 -03004306 if (port_pool->buf_num) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03004307 WARN(1, "cannot free all buffers in pool %d\n", port_pool->id);
4308 return -EIO;
4309 }
4310
4311 port_pool->pkt_size = pkt_size;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01004312 port_pool->frag_size = SKB_DATA_ALIGN(MVPP2_RX_BUF_SIZE(pkt_size)) +
4313 MVPP2_SKB_SHINFO_SIZE;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004314 num = mvpp2_bm_bufs_add(port, port_pool, pkts_num);
4315 if (num != pkts_num) {
4316 WARN(1, "pool %d: %d of %d allocated\n",
4317 port_pool->id, num, pkts_num);
4318 return -EIO;
4319 }
4320
4321 mvpp2_bm_pool_bufsize_set(port->priv, port_pool,
4322 MVPP2_RX_BUF_SIZE(port_pool->pkt_size));
4323 dev->mtu = mtu;
4324 netdev_update_features(dev);
4325 return 0;
4326}
4327
4328static inline void mvpp2_interrupts_enable(struct mvpp2_port *port)
4329{
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02004330 int i, sw_thread_mask = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004331
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02004332 for (i = 0; i < port->nqvecs; i++)
4333 sw_thread_mask |= port->qvecs[i].sw_thread_mask;
4334
Marcin Wojtas3f518502014-07-10 16:52:13 -03004335 mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id),
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02004336 MVPP2_ISR_ENABLE_INTERRUPT(sw_thread_mask));
Marcin Wojtas3f518502014-07-10 16:52:13 -03004337}
4338
4339static inline void mvpp2_interrupts_disable(struct mvpp2_port *port)
4340{
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02004341 int i, sw_thread_mask = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004342
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02004343 for (i = 0; i < port->nqvecs; i++)
4344 sw_thread_mask |= port->qvecs[i].sw_thread_mask;
4345
Marcin Wojtas3f518502014-07-10 16:52:13 -03004346 mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id),
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02004347 MVPP2_ISR_DISABLE_INTERRUPT(sw_thread_mask));
4348}
4349
4350static inline void mvpp2_qvec_interrupt_enable(struct mvpp2_queue_vector *qvec)
4351{
4352 struct mvpp2_port *port = qvec->port;
4353
4354 mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id),
4355 MVPP2_ISR_ENABLE_INTERRUPT(qvec->sw_thread_mask));
4356}
4357
4358static inline void mvpp2_qvec_interrupt_disable(struct mvpp2_queue_vector *qvec)
4359{
4360 struct mvpp2_port *port = qvec->port;
4361
4362 mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id),
4363 MVPP2_ISR_DISABLE_INTERRUPT(qvec->sw_thread_mask));
Marcin Wojtas3f518502014-07-10 16:52:13 -03004364}
4365
Thomas Petazzonie0af22d2017-06-22 14:23:18 +02004366/* Mask the current CPU's Rx/Tx interrupts
4367 * Called by on_each_cpu(), guaranteed to run with migration disabled,
4368 * using smp_processor_id() is OK.
4369 */
Marcin Wojtas3f518502014-07-10 16:52:13 -03004370static void mvpp2_interrupts_mask(void *arg)
4371{
4372 struct mvpp2_port *port = arg;
4373
Thomas Petazzonia7868412017-03-07 16:53:13 +01004374 mvpp2_percpu_write(port->priv, smp_processor_id(),
4375 MVPP2_ISR_RX_TX_MASK_REG(port->id), 0);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004376}
4377
Thomas Petazzonie0af22d2017-06-22 14:23:18 +02004378/* Unmask the current CPU's Rx/Tx interrupts.
4379 * Called by on_each_cpu(), guaranteed to run with migration disabled,
4380 * using smp_processor_id() is OK.
4381 */
Marcin Wojtas3f518502014-07-10 16:52:13 -03004382static void mvpp2_interrupts_unmask(void *arg)
4383{
4384 struct mvpp2_port *port = arg;
Thomas Petazzoni213f4282017-08-03 10:42:00 +02004385 u32 val;
4386
4387 val = MVPP2_CAUSE_MISC_SUM_MASK |
4388 MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK;
4389 if (port->has_tx_irqs)
4390 val |= MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK;
Marcin Wojtas3f518502014-07-10 16:52:13 -03004391
Thomas Petazzonia7868412017-03-07 16:53:13 +01004392 mvpp2_percpu_write(port->priv, smp_processor_id(),
Thomas Petazzoni213f4282017-08-03 10:42:00 +02004393 MVPP2_ISR_RX_TX_MASK_REG(port->id), val);
4394}
4395
4396static void
4397mvpp2_shared_interrupt_mask_unmask(struct mvpp2_port *port, bool mask)
4398{
4399 u32 val;
4400 int i;
4401
4402 if (port->priv->hw_version != MVPP22)
4403 return;
4404
4405 if (mask)
4406 val = 0;
4407 else
4408 val = MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK;
4409
4410 for (i = 0; i < port->nqvecs; i++) {
4411 struct mvpp2_queue_vector *v = port->qvecs + i;
4412
4413 if (v->type != MVPP2_QUEUE_VECTOR_SHARED)
4414 continue;
4415
4416 mvpp2_percpu_write(port->priv, v->sw_thread_id,
4417 MVPP2_ISR_RX_TX_MASK_REG(port->id), val);
4418 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03004419}
4420
4421/* Port configuration routines */
4422
Antoine Ténartf84bf382017-08-22 19:08:27 +02004423static void mvpp22_gop_init_rgmii(struct mvpp2_port *port)
4424{
4425 struct mvpp2 *priv = port->priv;
4426 u32 val;
4427
4428 regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL0, &val);
4429 val |= GENCONF_PORT_CTRL0_BUS_WIDTH_SELECT;
4430 regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL0, val);
4431
4432 regmap_read(priv->sysctrl_base, GENCONF_CTRL0, &val);
4433 if (port->gop_id == 2)
4434 val |= GENCONF_CTRL0_PORT0_RGMII | GENCONF_CTRL0_PORT1_RGMII;
4435 else if (port->gop_id == 3)
4436 val |= GENCONF_CTRL0_PORT1_RGMII_MII;
4437 regmap_write(priv->sysctrl_base, GENCONF_CTRL0, val);
4438}
4439
4440static void mvpp22_gop_init_sgmii(struct mvpp2_port *port)
4441{
4442 struct mvpp2 *priv = port->priv;
4443 u32 val;
4444
4445 regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL0, &val);
4446 val |= GENCONF_PORT_CTRL0_BUS_WIDTH_SELECT |
4447 GENCONF_PORT_CTRL0_RX_DATA_SAMPLE;
4448 regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL0, val);
4449
4450 if (port->gop_id > 1) {
4451 regmap_read(priv->sysctrl_base, GENCONF_CTRL0, &val);
4452 if (port->gop_id == 2)
4453 val &= ~GENCONF_CTRL0_PORT0_RGMII;
4454 else if (port->gop_id == 3)
4455 val &= ~GENCONF_CTRL0_PORT1_RGMII_MII;
4456 regmap_write(priv->sysctrl_base, GENCONF_CTRL0, val);
4457 }
4458}
4459
4460static void mvpp22_gop_init_10gkr(struct mvpp2_port *port)
4461{
4462 struct mvpp2 *priv = port->priv;
4463 void __iomem *mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id);
4464 void __iomem *xpcs = priv->iface_base + MVPP22_XPCS_BASE(port->gop_id);
4465 u32 val;
4466
4467 /* XPCS */
4468 val = readl(xpcs + MVPP22_XPCS_CFG0);
4469 val &= ~(MVPP22_XPCS_CFG0_PCS_MODE(0x3) |
4470 MVPP22_XPCS_CFG0_ACTIVE_LANE(0x3));
4471 val |= MVPP22_XPCS_CFG0_ACTIVE_LANE(2);
4472 writel(val, xpcs + MVPP22_XPCS_CFG0);
4473
4474 /* MPCS */
4475 val = readl(mpcs + MVPP22_MPCS_CTRL);
4476 val &= ~MVPP22_MPCS_CTRL_FWD_ERR_CONN;
4477 writel(val, mpcs + MVPP22_MPCS_CTRL);
4478
4479 val = readl(mpcs + MVPP22_MPCS_CLK_RESET);
4480 val &= ~(MVPP22_MPCS_CLK_RESET_DIV_RATIO(0x7) | MAC_CLK_RESET_MAC |
4481 MAC_CLK_RESET_SD_RX | MAC_CLK_RESET_SD_TX);
4482 val |= MVPP22_MPCS_CLK_RESET_DIV_RATIO(1);
4483 writel(val, mpcs + MVPP22_MPCS_CLK_RESET);
4484
4485 val &= ~MVPP22_MPCS_CLK_RESET_DIV_SET;
4486 val |= MAC_CLK_RESET_MAC | MAC_CLK_RESET_SD_RX | MAC_CLK_RESET_SD_TX;
4487 writel(val, mpcs + MVPP22_MPCS_CLK_RESET);
4488}
4489
4490static int mvpp22_gop_init(struct mvpp2_port *port)
4491{
4492 struct mvpp2 *priv = port->priv;
4493 u32 val;
4494
4495 if (!priv->sysctrl_base)
4496 return 0;
4497
4498 switch (port->phy_interface) {
4499 case PHY_INTERFACE_MODE_RGMII:
4500 case PHY_INTERFACE_MODE_RGMII_ID:
4501 case PHY_INTERFACE_MODE_RGMII_RXID:
4502 case PHY_INTERFACE_MODE_RGMII_TXID:
4503 if (port->gop_id == 0)
4504 goto invalid_conf;
4505 mvpp22_gop_init_rgmii(port);
4506 break;
4507 case PHY_INTERFACE_MODE_SGMII:
4508 mvpp22_gop_init_sgmii(port);
4509 break;
4510 case PHY_INTERFACE_MODE_10GKR:
4511 if (port->gop_id != 0)
4512 goto invalid_conf;
4513 mvpp22_gop_init_10gkr(port);
4514 break;
4515 default:
4516 goto unsupported_conf;
4517 }
4518
4519 regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL1, &val);
4520 val |= GENCONF_PORT_CTRL1_RESET(port->gop_id) |
4521 GENCONF_PORT_CTRL1_EN(port->gop_id);
4522 regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL1, val);
4523
4524 regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL0, &val);
4525 val |= GENCONF_PORT_CTRL0_CLK_DIV_PHASE_CLR;
4526 regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL0, val);
4527
4528 regmap_read(priv->sysctrl_base, GENCONF_SOFT_RESET1, &val);
4529 val |= GENCONF_SOFT_RESET1_GOP;
4530 regmap_write(priv->sysctrl_base, GENCONF_SOFT_RESET1, val);
4531
4532unsupported_conf:
4533 return 0;
4534
4535invalid_conf:
4536 netdev_err(port->dev, "Invalid port configuration\n");
4537 return -EINVAL;
4538}
4539
Antoine Tenartfd3651b2017-09-01 11:04:54 +02004540static void mvpp22_gop_unmask_irq(struct mvpp2_port *port)
4541{
4542 u32 val;
4543
4544 if (phy_interface_mode_is_rgmii(port->phy_interface) ||
4545 port->phy_interface == PHY_INTERFACE_MODE_SGMII) {
4546 /* Enable the GMAC link status irq for this port */
4547 val = readl(port->base + MVPP22_GMAC_INT_SUM_MASK);
4548 val |= MVPP22_GMAC_INT_SUM_MASK_LINK_STAT;
4549 writel(val, port->base + MVPP22_GMAC_INT_SUM_MASK);
4550 }
4551
4552 if (port->gop_id == 0) {
4553 /* Enable the XLG/GIG irqs for this port */
4554 val = readl(port->base + MVPP22_XLG_EXT_INT_MASK);
4555 if (port->phy_interface == PHY_INTERFACE_MODE_10GKR)
4556 val |= MVPP22_XLG_EXT_INT_MASK_XLG;
4557 else
4558 val |= MVPP22_XLG_EXT_INT_MASK_GIG;
4559 writel(val, port->base + MVPP22_XLG_EXT_INT_MASK);
4560 }
4561}
4562
4563static void mvpp22_gop_mask_irq(struct mvpp2_port *port)
4564{
4565 u32 val;
4566
4567 if (port->gop_id == 0) {
4568 val = readl(port->base + MVPP22_XLG_EXT_INT_MASK);
4569 val &= ~(MVPP22_XLG_EXT_INT_MASK_XLG |
4570 MVPP22_XLG_EXT_INT_MASK_GIG);
4571 writel(val, port->base + MVPP22_XLG_EXT_INT_MASK);
4572 }
4573
4574 if (phy_interface_mode_is_rgmii(port->phy_interface) ||
4575 port->phy_interface == PHY_INTERFACE_MODE_SGMII) {
4576 val = readl(port->base + MVPP22_GMAC_INT_SUM_MASK);
4577 val &= ~MVPP22_GMAC_INT_SUM_MASK_LINK_STAT;
4578 writel(val, port->base + MVPP22_GMAC_INT_SUM_MASK);
4579 }
4580}
4581
4582static void mvpp22_gop_setup_irq(struct mvpp2_port *port)
4583{
4584 u32 val;
4585
4586 if (phy_interface_mode_is_rgmii(port->phy_interface) ||
4587 port->phy_interface == PHY_INTERFACE_MODE_SGMII) {
4588 val = readl(port->base + MVPP22_GMAC_INT_MASK);
4589 val |= MVPP22_GMAC_INT_MASK_LINK_STAT;
4590 writel(val, port->base + MVPP22_GMAC_INT_MASK);
4591 }
4592
4593 if (port->gop_id == 0) {
4594 val = readl(port->base + MVPP22_XLG_INT_MASK);
4595 val |= MVPP22_XLG_INT_MASK_LINK;
4596 writel(val, port->base + MVPP22_XLG_INT_MASK);
4597 }
4598
4599 mvpp22_gop_unmask_irq(port);
4600}
4601
Antoine Tenart542897d2017-08-30 10:29:15 +02004602static int mvpp22_comphy_init(struct mvpp2_port *port)
4603{
4604 enum phy_mode mode;
4605 int ret;
4606
4607 if (!port->comphy)
4608 return 0;
4609
4610 switch (port->phy_interface) {
4611 case PHY_INTERFACE_MODE_SGMII:
4612 mode = PHY_MODE_SGMII;
4613 break;
4614 case PHY_INTERFACE_MODE_10GKR:
4615 mode = PHY_MODE_10GKR;
4616 break;
4617 default:
4618 return -EINVAL;
4619 }
4620
4621 ret = phy_set_mode(port->comphy, mode);
4622 if (ret)
4623 return ret;
4624
4625 return phy_power_on(port->comphy);
4626}
4627
Antoine Ténart39193572017-08-22 19:08:24 +02004628static void mvpp2_port_mii_gmac_configure_mode(struct mvpp2_port *port)
4629{
4630 u32 val;
4631
4632 if (port->phy_interface == PHY_INTERFACE_MODE_SGMII) {
4633 val = readl(port->base + MVPP22_GMAC_CTRL_4_REG);
4634 val |= MVPP22_CTRL4_SYNC_BYPASS_DIS | MVPP22_CTRL4_DP_CLK_SEL |
4635 MVPP22_CTRL4_QSGMII_BYPASS_ACTIVE;
4636 val &= ~MVPP22_CTRL4_EXT_PIN_GMII_SEL;
4637 writel(val, port->base + MVPP22_GMAC_CTRL_4_REG);
Antoine Tenart1df22702017-09-01 11:04:52 +02004638 } else if (phy_interface_mode_is_rgmii(port->phy_interface)) {
Antoine Ténart39193572017-08-22 19:08:24 +02004639 val = readl(port->base + MVPP22_GMAC_CTRL_4_REG);
4640 val |= MVPP22_CTRL4_EXT_PIN_GMII_SEL |
4641 MVPP22_CTRL4_SYNC_BYPASS_DIS |
4642 MVPP22_CTRL4_QSGMII_BYPASS_ACTIVE;
4643 val &= ~MVPP22_CTRL4_DP_CLK_SEL;
4644 writel(val, port->base + MVPP22_GMAC_CTRL_4_REG);
Antoine Ténart39193572017-08-22 19:08:24 +02004645 }
4646
4647 /* The port is connected to a copper PHY */
4648 val = readl(port->base + MVPP2_GMAC_CTRL_0_REG);
4649 val &= ~MVPP2_GMAC_PORT_TYPE_MASK;
4650 writel(val, port->base + MVPP2_GMAC_CTRL_0_REG);
4651
4652 val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG);
4653 val |= MVPP2_GMAC_IN_BAND_AUTONEG_BYPASS |
4654 MVPP2_GMAC_AN_SPEED_EN | MVPP2_GMAC_FLOW_CTRL_AUTONEG |
4655 MVPP2_GMAC_AN_DUPLEX_EN;
4656 if (port->phy_interface == PHY_INTERFACE_MODE_SGMII)
4657 val |= MVPP2_GMAC_IN_BAND_AUTONEG;
4658 writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG);
4659}
4660
4661static void mvpp2_port_mii_gmac_configure(struct mvpp2_port *port)
4662{
4663 u32 val;
4664
4665 /* Force link down */
4666 val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG);
4667 val &= ~MVPP2_GMAC_FORCE_LINK_PASS;
4668 val |= MVPP2_GMAC_FORCE_LINK_DOWN;
4669 writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG);
4670
4671 /* Set the GMAC in a reset state */
4672 val = readl(port->base + MVPP2_GMAC_CTRL_2_REG);
4673 val |= MVPP2_GMAC_PORT_RESET_MASK;
4674 writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
4675
4676 /* Configure the PCS and in-band AN */
4677 val = readl(port->base + MVPP2_GMAC_CTRL_2_REG);
4678 if (port->phy_interface == PHY_INTERFACE_MODE_SGMII) {
4679 val |= MVPP2_GMAC_INBAND_AN_MASK | MVPP2_GMAC_PCS_ENABLE_MASK;
Antoine Tenart1df22702017-09-01 11:04:52 +02004680 } else if (phy_interface_mode_is_rgmii(port->phy_interface)) {
Antoine Ténart39193572017-08-22 19:08:24 +02004681 val &= ~MVPP2_GMAC_PCS_ENABLE_MASK;
Antoine Ténart39193572017-08-22 19:08:24 +02004682 }
4683 writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
4684
4685 mvpp2_port_mii_gmac_configure_mode(port);
4686
4687 /* Unset the GMAC reset state */
4688 val = readl(port->base + MVPP2_GMAC_CTRL_2_REG);
4689 val &= ~MVPP2_GMAC_PORT_RESET_MASK;
4690 writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
4691
4692 /* Stop forcing link down */
4693 val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG);
4694 val &= ~MVPP2_GMAC_FORCE_LINK_DOWN;
4695 writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG);
4696}
4697
Antoine Ténart77321952017-08-22 19:08:25 +02004698static void mvpp2_port_mii_xlg_configure(struct mvpp2_port *port)
4699{
4700 u32 val;
4701
4702 if (port->gop_id != 0)
4703 return;
4704
4705 val = readl(port->base + MVPP22_XLG_CTRL0_REG);
4706 val |= MVPP22_XLG_CTRL0_RX_FLOW_CTRL_EN;
4707 writel(val, port->base + MVPP22_XLG_CTRL0_REG);
4708
4709 val = readl(port->base + MVPP22_XLG_CTRL4_REG);
4710 val &= ~MVPP22_XLG_CTRL4_MACMODSELECT_GMAC;
4711 val |= MVPP22_XLG_CTRL4_FWD_FC | MVPP22_XLG_CTRL4_FWD_PFC;
4712 writel(val, port->base + MVPP22_XLG_CTRL4_REG);
4713}
4714
Thomas Petazzoni26975822017-03-07 16:53:14 +01004715static void mvpp22_port_mii_set(struct mvpp2_port *port)
4716{
4717 u32 val;
4718
Thomas Petazzoni26975822017-03-07 16:53:14 +01004719 /* Only GOP port 0 has an XLG MAC */
4720 if (port->gop_id == 0) {
4721 val = readl(port->base + MVPP22_XLG_CTRL3_REG);
4722 val &= ~MVPP22_XLG_CTRL3_MACMODESELECT_MASK;
Antoine Ténart725757a2017-06-12 16:01:39 +02004723
4724 if (port->phy_interface == PHY_INTERFACE_MODE_XAUI ||
4725 port->phy_interface == PHY_INTERFACE_MODE_10GKR)
4726 val |= MVPP22_XLG_CTRL3_MACMODESELECT_10G;
4727 else
4728 val |= MVPP22_XLG_CTRL3_MACMODESELECT_GMAC;
4729
Thomas Petazzoni26975822017-03-07 16:53:14 +01004730 writel(val, port->base + MVPP22_XLG_CTRL3_REG);
4731 }
Thomas Petazzoni26975822017-03-07 16:53:14 +01004732}
4733
Marcin Wojtas3f518502014-07-10 16:52:13 -03004734static void mvpp2_port_mii_set(struct mvpp2_port *port)
4735{
Thomas Petazzoni26975822017-03-07 16:53:14 +01004736 if (port->priv->hw_version == MVPP22)
4737 mvpp22_port_mii_set(port);
4738
Antoine Tenart1df22702017-09-01 11:04:52 +02004739 if (phy_interface_mode_is_rgmii(port->phy_interface) ||
Antoine Ténart39193572017-08-22 19:08:24 +02004740 port->phy_interface == PHY_INTERFACE_MODE_SGMII)
4741 mvpp2_port_mii_gmac_configure(port);
Antoine Ténart77321952017-08-22 19:08:25 +02004742 else if (port->phy_interface == PHY_INTERFACE_MODE_10GKR)
4743 mvpp2_port_mii_xlg_configure(port);
Marcin Wojtas08a23752014-07-21 13:48:12 -03004744}
4745
4746static void mvpp2_port_fc_adv_enable(struct mvpp2_port *port)
4747{
4748 u32 val;
4749
4750 val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG);
4751 val |= MVPP2_GMAC_FC_ADV_EN;
4752 writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004753}
4754
4755static void mvpp2_port_enable(struct mvpp2_port *port)
4756{
4757 u32 val;
4758
Antoine Ténart725757a2017-06-12 16:01:39 +02004759 /* Only GOP port 0 has an XLG MAC */
4760 if (port->gop_id == 0 &&
4761 (port->phy_interface == PHY_INTERFACE_MODE_XAUI ||
4762 port->phy_interface == PHY_INTERFACE_MODE_10GKR)) {
4763 val = readl(port->base + MVPP22_XLG_CTRL0_REG);
4764 val |= MVPP22_XLG_CTRL0_PORT_EN |
4765 MVPP22_XLG_CTRL0_MAC_RESET_DIS;
4766 val &= ~MVPP22_XLG_CTRL0_MIB_CNT_DIS;
4767 writel(val, port->base + MVPP22_XLG_CTRL0_REG);
4768 } else {
4769 val = readl(port->base + MVPP2_GMAC_CTRL_0_REG);
4770 val |= MVPP2_GMAC_PORT_EN_MASK;
4771 val |= MVPP2_GMAC_MIB_CNTR_EN_MASK;
4772 writel(val, port->base + MVPP2_GMAC_CTRL_0_REG);
4773 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03004774}
4775
4776static void mvpp2_port_disable(struct mvpp2_port *port)
4777{
4778 u32 val;
4779
Antoine Ténart725757a2017-06-12 16:01:39 +02004780 /* Only GOP port 0 has an XLG MAC */
4781 if (port->gop_id == 0 &&
4782 (port->phy_interface == PHY_INTERFACE_MODE_XAUI ||
4783 port->phy_interface == PHY_INTERFACE_MODE_10GKR)) {
4784 val = readl(port->base + MVPP22_XLG_CTRL0_REG);
4785 val &= ~(MVPP22_XLG_CTRL0_PORT_EN |
4786 MVPP22_XLG_CTRL0_MAC_RESET_DIS);
4787 writel(val, port->base + MVPP22_XLG_CTRL0_REG);
4788 } else {
4789 val = readl(port->base + MVPP2_GMAC_CTRL_0_REG);
4790 val &= ~(MVPP2_GMAC_PORT_EN_MASK);
4791 writel(val, port->base + MVPP2_GMAC_CTRL_0_REG);
4792 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03004793}
4794
4795/* Set IEEE 802.3x Flow Control Xon Packet Transmission Mode */
4796static void mvpp2_port_periodic_xon_disable(struct mvpp2_port *port)
4797{
4798 u32 val;
4799
4800 val = readl(port->base + MVPP2_GMAC_CTRL_1_REG) &
4801 ~MVPP2_GMAC_PERIODIC_XON_EN_MASK;
4802 writel(val, port->base + MVPP2_GMAC_CTRL_1_REG);
4803}
4804
4805/* Configure loopback port */
4806static void mvpp2_port_loopback_set(struct mvpp2_port *port)
4807{
4808 u32 val;
4809
4810 val = readl(port->base + MVPP2_GMAC_CTRL_1_REG);
4811
4812 if (port->speed == 1000)
4813 val |= MVPP2_GMAC_GMII_LB_EN_MASK;
4814 else
4815 val &= ~MVPP2_GMAC_GMII_LB_EN_MASK;
4816
4817 if (port->phy_interface == PHY_INTERFACE_MODE_SGMII)
4818 val |= MVPP2_GMAC_PCS_LB_EN_MASK;
4819 else
4820 val &= ~MVPP2_GMAC_PCS_LB_EN_MASK;
4821
4822 writel(val, port->base + MVPP2_GMAC_CTRL_1_REG);
4823}
4824
Miquel Raynal118d6292017-11-06 22:56:53 +01004825struct mvpp2_ethtool_counter {
4826 unsigned int offset;
4827 const char string[ETH_GSTRING_LEN];
4828 bool reg_is_64b;
4829};
4830
4831static u64 mvpp2_read_count(struct mvpp2_port *port,
4832 const struct mvpp2_ethtool_counter *counter)
4833{
4834 u64 val;
4835
4836 val = readl(port->stats_base + counter->offset);
4837 if (counter->reg_is_64b)
4838 val += (u64)readl(port->stats_base + counter->offset + 4) << 32;
4839
4840 return val;
4841}
4842
4843/* Due to the fact that software statistics and hardware statistics are, by
4844 * design, incremented at different moments in the chain of packet processing,
4845 * it is very likely that incoming packets could have been dropped after being
4846 * counted by hardware but before reaching software statistics (most probably
4847 * multicast packets), and in the oppposite way, during transmission, FCS bytes
4848 * are added in between as well as TSO skb will be split and header bytes added.
4849 * Hence, statistics gathered from userspace with ifconfig (software) and
4850 * ethtool (hardware) cannot be compared.
4851 */
4852static const struct mvpp2_ethtool_counter mvpp2_ethtool_regs[] = {
4853 { MVPP2_MIB_GOOD_OCTETS_RCVD, "good_octets_received", true },
4854 { MVPP2_MIB_BAD_OCTETS_RCVD, "bad_octets_received" },
4855 { MVPP2_MIB_CRC_ERRORS_SENT, "crc_errors_sent" },
4856 { MVPP2_MIB_UNICAST_FRAMES_RCVD, "unicast_frames_received" },
4857 { MVPP2_MIB_BROADCAST_FRAMES_RCVD, "broadcast_frames_received" },
4858 { MVPP2_MIB_MULTICAST_FRAMES_RCVD, "multicast_frames_received" },
4859 { MVPP2_MIB_FRAMES_64_OCTETS, "frames_64_octets" },
4860 { MVPP2_MIB_FRAMES_65_TO_127_OCTETS, "frames_65_to_127_octet" },
4861 { MVPP2_MIB_FRAMES_128_TO_255_OCTETS, "frames_128_to_255_octet" },
4862 { MVPP2_MIB_FRAMES_256_TO_511_OCTETS, "frames_256_to_511_octet" },
4863 { MVPP2_MIB_FRAMES_512_TO_1023_OCTETS, "frames_512_to_1023_octet" },
4864 { MVPP2_MIB_FRAMES_1024_TO_MAX_OCTETS, "frames_1024_to_max_octet" },
4865 { MVPP2_MIB_GOOD_OCTETS_SENT, "good_octets_sent", true },
4866 { MVPP2_MIB_UNICAST_FRAMES_SENT, "unicast_frames_sent" },
4867 { MVPP2_MIB_MULTICAST_FRAMES_SENT, "multicast_frames_sent" },
4868 { MVPP2_MIB_BROADCAST_FRAMES_SENT, "broadcast_frames_sent" },
4869 { MVPP2_MIB_FC_SENT, "fc_sent" },
4870 { MVPP2_MIB_FC_RCVD, "fc_received" },
4871 { MVPP2_MIB_RX_FIFO_OVERRUN, "rx_fifo_overrun" },
4872 { MVPP2_MIB_UNDERSIZE_RCVD, "undersize_received" },
4873 { MVPP2_MIB_FRAGMENTS_RCVD, "fragments_received" },
4874 { MVPP2_MIB_OVERSIZE_RCVD, "oversize_received" },
4875 { MVPP2_MIB_JABBER_RCVD, "jabber_received" },
4876 { MVPP2_MIB_MAC_RCV_ERROR, "mac_receive_error" },
4877 { MVPP2_MIB_BAD_CRC_EVENT, "bad_crc_event" },
4878 { MVPP2_MIB_COLLISION, "collision" },
4879 { MVPP2_MIB_LATE_COLLISION, "late_collision" },
4880};
4881
4882static void mvpp2_ethtool_get_strings(struct net_device *netdev, u32 sset,
4883 u8 *data)
4884{
4885 if (sset == ETH_SS_STATS) {
4886 int i;
4887
4888 for (i = 0; i < ARRAY_SIZE(mvpp2_ethtool_regs); i++)
4889 memcpy(data + i * ETH_GSTRING_LEN,
4890 &mvpp2_ethtool_regs[i].string, ETH_GSTRING_LEN);
4891 }
4892}
4893
4894static void mvpp2_gather_hw_statistics(struct work_struct *work)
4895{
4896 struct delayed_work *del_work = to_delayed_work(work);
Miquel Raynale5c500e2017-11-08 08:59:40 +01004897 struct mvpp2_port *port = container_of(del_work, struct mvpp2_port,
4898 stats_work);
Miquel Raynal118d6292017-11-06 22:56:53 +01004899 u64 *pstats;
Miquel Raynale5c500e2017-11-08 08:59:40 +01004900 int i;
Miquel Raynal118d6292017-11-06 22:56:53 +01004901
Miquel Raynale5c500e2017-11-08 08:59:40 +01004902 mutex_lock(&port->gather_stats_lock);
Miquel Raynal118d6292017-11-06 22:56:53 +01004903
Miquel Raynale5c500e2017-11-08 08:59:40 +01004904 pstats = port->ethtool_stats;
4905 for (i = 0; i < ARRAY_SIZE(mvpp2_ethtool_regs); i++)
4906 *pstats++ += mvpp2_read_count(port, &mvpp2_ethtool_regs[i]);
Miquel Raynal118d6292017-11-06 22:56:53 +01004907
4908 /* No need to read again the counters right after this function if it
4909 * was called asynchronously by the user (ie. use of ethtool).
4910 */
Miquel Raynale5c500e2017-11-08 08:59:40 +01004911 cancel_delayed_work(&port->stats_work);
4912 queue_delayed_work(port->priv->stats_queue, &port->stats_work,
Miquel Raynal118d6292017-11-06 22:56:53 +01004913 MVPP2_MIB_COUNTERS_STATS_DELAY);
4914
Miquel Raynale5c500e2017-11-08 08:59:40 +01004915 mutex_unlock(&port->gather_stats_lock);
Miquel Raynal118d6292017-11-06 22:56:53 +01004916}
4917
4918static void mvpp2_ethtool_get_stats(struct net_device *dev,
4919 struct ethtool_stats *stats, u64 *data)
4920{
4921 struct mvpp2_port *port = netdev_priv(dev);
4922
Miquel Raynale5c500e2017-11-08 08:59:40 +01004923 /* Update statistics for the given port, then take the lock to avoid
4924 * concurrent accesses on the ethtool_stats structure during its copy.
4925 */
4926 mvpp2_gather_hw_statistics(&port->stats_work.work);
Miquel Raynal118d6292017-11-06 22:56:53 +01004927
Miquel Raynale5c500e2017-11-08 08:59:40 +01004928 mutex_lock(&port->gather_stats_lock);
Miquel Raynal118d6292017-11-06 22:56:53 +01004929 memcpy(data, port->ethtool_stats,
4930 sizeof(u64) * ARRAY_SIZE(mvpp2_ethtool_regs));
Miquel Raynale5c500e2017-11-08 08:59:40 +01004931 mutex_unlock(&port->gather_stats_lock);
Miquel Raynal118d6292017-11-06 22:56:53 +01004932}
4933
4934static int mvpp2_ethtool_get_sset_count(struct net_device *dev, int sset)
4935{
4936 if (sset == ETH_SS_STATS)
4937 return ARRAY_SIZE(mvpp2_ethtool_regs);
4938
4939 return -EOPNOTSUPP;
4940}
4941
Marcin Wojtas3f518502014-07-10 16:52:13 -03004942static void mvpp2_port_reset(struct mvpp2_port *port)
4943{
4944 u32 val;
Miquel Raynal118d6292017-11-06 22:56:53 +01004945 unsigned int i;
4946
4947 /* Read the GOP statistics to reset the hardware counters */
4948 for (i = 0; i < ARRAY_SIZE(mvpp2_ethtool_regs); i++)
4949 mvpp2_read_count(port, &mvpp2_ethtool_regs[i]);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004950
4951 val = readl(port->base + MVPP2_GMAC_CTRL_2_REG) &
4952 ~MVPP2_GMAC_PORT_RESET_MASK;
4953 writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
4954
4955 while (readl(port->base + MVPP2_GMAC_CTRL_2_REG) &
4956 MVPP2_GMAC_PORT_RESET_MASK)
4957 continue;
4958}
4959
4960/* Change maximum receive size of the port */
4961static inline void mvpp2_gmac_max_rx_size_set(struct mvpp2_port *port)
4962{
4963 u32 val;
4964
4965 val = readl(port->base + MVPP2_GMAC_CTRL_0_REG);
4966 val &= ~MVPP2_GMAC_MAX_RX_SIZE_MASK;
4967 val |= (((port->pkt_size - MVPP2_MH_SIZE) / 2) <<
4968 MVPP2_GMAC_MAX_RX_SIZE_OFFS);
4969 writel(val, port->base + MVPP2_GMAC_CTRL_0_REG);
4970}
4971
Stefan Chulski76eb1b12017-08-22 19:08:26 +02004972/* Change maximum receive size of the port */
4973static inline void mvpp2_xlg_max_rx_size_set(struct mvpp2_port *port)
4974{
4975 u32 val;
4976
4977 val = readl(port->base + MVPP22_XLG_CTRL1_REG);
4978 val &= ~MVPP22_XLG_CTRL1_FRAMESIZELIMIT_MASK;
4979 val |= ((port->pkt_size - MVPP2_MH_SIZE) / 2) <<
Antoine Ténartec15ecd2017-08-25 15:24:46 +02004980 MVPP22_XLG_CTRL1_FRAMESIZELIMIT_OFFS;
Stefan Chulski76eb1b12017-08-22 19:08:26 +02004981 writel(val, port->base + MVPP22_XLG_CTRL1_REG);
4982}
4983
Marcin Wojtas3f518502014-07-10 16:52:13 -03004984/* Set defaults to the MVPP2 port */
4985static void mvpp2_defaults_set(struct mvpp2_port *port)
4986{
4987 int tx_port_num, val, queue, ptxq, lrxq;
4988
Thomas Petazzoni3d9017d2017-03-07 16:53:11 +01004989 if (port->priv->hw_version == MVPP21) {
4990 /* Configure port to loopback if needed */
4991 if (port->flags & MVPP2_F_LOOPBACK)
4992 mvpp2_port_loopback_set(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03004993
Thomas Petazzoni3d9017d2017-03-07 16:53:11 +01004994 /* Update TX FIFO MIN Threshold */
4995 val = readl(port->base + MVPP2_GMAC_PORT_FIFO_CFG_1_REG);
4996 val &= ~MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK;
4997 /* Min. TX threshold must be less than minimal packet length */
4998 val |= MVPP2_GMAC_TX_FIFO_MIN_TH_MASK(64 - 4 - 2);
4999 writel(val, port->base + MVPP2_GMAC_PORT_FIFO_CFG_1_REG);
5000 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03005001
5002 /* Disable Legacy WRR, Disable EJP, Release from reset */
5003 tx_port_num = mvpp2_egress_port(port);
5004 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG,
5005 tx_port_num);
5006 mvpp2_write(port->priv, MVPP2_TXP_SCHED_CMD_1_REG, 0);
5007
5008 /* Close bandwidth for all queues */
5009 for (queue = 0; queue < MVPP2_MAX_TXQ; queue++) {
5010 ptxq = mvpp2_txq_phys(port->id, queue);
5011 mvpp2_write(port->priv,
5012 MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(ptxq), 0);
5013 }
5014
5015 /* Set refill period to 1 usec, refill tokens
5016 * and bucket size to maximum
5017 */
5018 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PERIOD_REG,
5019 port->priv->tclk / USEC_PER_SEC);
5020 val = mvpp2_read(port->priv, MVPP2_TXP_SCHED_REFILL_REG);
5021 val &= ~MVPP2_TXP_REFILL_PERIOD_ALL_MASK;
5022 val |= MVPP2_TXP_REFILL_PERIOD_MASK(1);
5023 val |= MVPP2_TXP_REFILL_TOKENS_ALL_MASK;
5024 mvpp2_write(port->priv, MVPP2_TXP_SCHED_REFILL_REG, val);
5025 val = MVPP2_TXP_TOKEN_SIZE_MAX;
5026 mvpp2_write(port->priv, MVPP2_TXP_SCHED_TOKEN_SIZE_REG, val);
5027
5028 /* Set MaximumLowLatencyPacketSize value to 256 */
5029 mvpp2_write(port->priv, MVPP2_RX_CTRL_REG(port->id),
5030 MVPP2_RX_USE_PSEUDO_FOR_CSUM_MASK |
5031 MVPP2_RX_LOW_LATENCY_PKT_SIZE(256));
5032
5033 /* Enable Rx cache snoop */
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005034 for (lrxq = 0; lrxq < port->nrxqs; lrxq++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005035 queue = port->rxqs[lrxq]->id;
5036 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(queue));
5037 val |= MVPP2_SNOOP_PKT_SIZE_MASK |
5038 MVPP2_SNOOP_BUF_HDR_MASK;
5039 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(queue), val);
5040 }
5041
5042 /* At default, mask all interrupts to all present cpus */
5043 mvpp2_interrupts_disable(port);
5044}
5045
5046/* Enable/disable receiving packets */
5047static void mvpp2_ingress_enable(struct mvpp2_port *port)
5048{
5049 u32 val;
5050 int lrxq, queue;
5051
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005052 for (lrxq = 0; lrxq < port->nrxqs; lrxq++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005053 queue = port->rxqs[lrxq]->id;
5054 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(queue));
5055 val &= ~MVPP2_RXQ_DISABLE_MASK;
5056 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(queue), val);
5057 }
5058}
5059
5060static void mvpp2_ingress_disable(struct mvpp2_port *port)
5061{
5062 u32 val;
5063 int lrxq, queue;
5064
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005065 for (lrxq = 0; lrxq < port->nrxqs; lrxq++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005066 queue = port->rxqs[lrxq]->id;
5067 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(queue));
5068 val |= MVPP2_RXQ_DISABLE_MASK;
5069 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(queue), val);
5070 }
5071}
5072
5073/* Enable transmit via physical egress queue
5074 * - HW starts take descriptors from DRAM
5075 */
5076static void mvpp2_egress_enable(struct mvpp2_port *port)
5077{
5078 u32 qmap;
5079 int queue;
5080 int tx_port_num = mvpp2_egress_port(port);
5081
5082 /* Enable all initialized TXs. */
5083 qmap = 0;
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005084 for (queue = 0; queue < port->ntxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005085 struct mvpp2_tx_queue *txq = port->txqs[queue];
5086
Markus Elfringdbbb2f02017-04-17 14:07:52 +02005087 if (txq->descs)
Marcin Wojtas3f518502014-07-10 16:52:13 -03005088 qmap |= (1 << queue);
5089 }
5090
5091 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num);
5092 mvpp2_write(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG, qmap);
5093}
5094
5095/* Disable transmit via physical egress queue
5096 * - HW doesn't take descriptors from DRAM
5097 */
5098static void mvpp2_egress_disable(struct mvpp2_port *port)
5099{
5100 u32 reg_data;
5101 int delay;
5102 int tx_port_num = mvpp2_egress_port(port);
5103
5104 /* Issue stop command for active channels only */
5105 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num);
5106 reg_data = (mvpp2_read(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG)) &
5107 MVPP2_TXP_SCHED_ENQ_MASK;
5108 if (reg_data != 0)
5109 mvpp2_write(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG,
5110 (reg_data << MVPP2_TXP_SCHED_DISQ_OFFSET));
5111
5112 /* Wait for all Tx activity to terminate. */
5113 delay = 0;
5114 do {
5115 if (delay >= MVPP2_TX_DISABLE_TIMEOUT_MSEC) {
5116 netdev_warn(port->dev,
5117 "Tx stop timed out, status=0x%08x\n",
5118 reg_data);
5119 break;
5120 }
5121 mdelay(1);
5122 delay++;
5123
5124 /* Check port TX Command register that all
5125 * Tx queues are stopped
5126 */
5127 reg_data = mvpp2_read(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG);
5128 } while (reg_data & MVPP2_TXP_SCHED_ENQ_MASK);
5129}
5130
5131/* Rx descriptors helper methods */
5132
5133/* Get number of Rx descriptors occupied by received packets */
5134static inline int
5135mvpp2_rxq_received(struct mvpp2_port *port, int rxq_id)
5136{
5137 u32 val = mvpp2_read(port->priv, MVPP2_RXQ_STATUS_REG(rxq_id));
5138
5139 return val & MVPP2_RXQ_OCCUPIED_MASK;
5140}
5141
5142/* Update Rx queue status with the number of occupied and available
5143 * Rx descriptor slots.
5144 */
5145static inline void
5146mvpp2_rxq_status_update(struct mvpp2_port *port, int rxq_id,
5147 int used_count, int free_count)
5148{
5149 /* Decrement the number of used descriptors and increment count
5150 * increment the number of free descriptors.
5151 */
5152 u32 val = used_count | (free_count << MVPP2_RXQ_NUM_NEW_OFFSET);
5153
5154 mvpp2_write(port->priv, MVPP2_RXQ_STATUS_UPDATE_REG(rxq_id), val);
5155}
5156
5157/* Get pointer to next RX descriptor to be processed by SW */
5158static inline struct mvpp2_rx_desc *
5159mvpp2_rxq_next_desc_get(struct mvpp2_rx_queue *rxq)
5160{
5161 int rx_desc = rxq->next_desc_to_proc;
5162
5163 rxq->next_desc_to_proc = MVPP2_QUEUE_NEXT_DESC(rxq, rx_desc);
5164 prefetch(rxq->descs + rxq->next_desc_to_proc);
5165 return rxq->descs + rx_desc;
5166}
5167
5168/* Set rx queue offset */
5169static void mvpp2_rxq_offset_set(struct mvpp2_port *port,
5170 int prxq, int offset)
5171{
5172 u32 val;
5173
5174 /* Convert offset from bytes to units of 32 bytes */
5175 offset = offset >> 5;
5176
5177 val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(prxq));
5178 val &= ~MVPP2_RXQ_PACKET_OFFSET_MASK;
5179
5180 /* Offset is in */
5181 val |= ((offset << MVPP2_RXQ_PACKET_OFFSET_OFFS) &
5182 MVPP2_RXQ_PACKET_OFFSET_MASK);
5183
5184 mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(prxq), val);
5185}
5186
Marcin Wojtas3f518502014-07-10 16:52:13 -03005187/* Tx descriptors helper methods */
5188
Marcin Wojtas3f518502014-07-10 16:52:13 -03005189/* Get pointer to next Tx descriptor to be processed (send) by HW */
5190static struct mvpp2_tx_desc *
5191mvpp2_txq_next_desc_get(struct mvpp2_tx_queue *txq)
5192{
5193 int tx_desc = txq->next_desc_to_proc;
5194
5195 txq->next_desc_to_proc = MVPP2_QUEUE_NEXT_DESC(txq, tx_desc);
5196 return txq->descs + tx_desc;
5197}
5198
Thomas Petazzonie0af22d2017-06-22 14:23:18 +02005199/* Update HW with number of aggregated Tx descriptors to be sent
5200 *
5201 * Called only from mvpp2_tx(), so migration is disabled, using
5202 * smp_processor_id() is OK.
5203 */
Marcin Wojtas3f518502014-07-10 16:52:13 -03005204static void mvpp2_aggr_txq_pend_desc_add(struct mvpp2_port *port, int pending)
5205{
5206 /* aggregated access - relevant TXQ number is written in TX desc */
Thomas Petazzonia7868412017-03-07 16:53:13 +01005207 mvpp2_percpu_write(port->priv, smp_processor_id(),
5208 MVPP2_AGGR_TXQ_UPDATE_REG, pending);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005209}
5210
5211
5212/* Check if there are enough free descriptors in aggregated txq.
5213 * If not, update the number of occupied descriptors and repeat the check.
Thomas Petazzonie0af22d2017-06-22 14:23:18 +02005214 *
5215 * Called only from mvpp2_tx(), so migration is disabled, using
5216 * smp_processor_id() is OK.
Marcin Wojtas3f518502014-07-10 16:52:13 -03005217 */
5218static int mvpp2_aggr_desc_num_check(struct mvpp2 *priv,
5219 struct mvpp2_tx_queue *aggr_txq, int num)
5220{
Antoine Tenart02856a32017-10-30 11:23:32 +01005221 if ((aggr_txq->count + num) > MVPP2_AGGR_TXQ_SIZE) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005222 /* Update number of occupied aggregated Tx descriptors */
5223 int cpu = smp_processor_id();
5224 u32 val = mvpp2_read(priv, MVPP2_AGGR_TXQ_STATUS_REG(cpu));
5225
5226 aggr_txq->count = val & MVPP2_AGGR_TXQ_PENDING_MASK;
5227 }
5228
Antoine Tenart02856a32017-10-30 11:23:32 +01005229 if ((aggr_txq->count + num) > MVPP2_AGGR_TXQ_SIZE)
Marcin Wojtas3f518502014-07-10 16:52:13 -03005230 return -ENOMEM;
5231
5232 return 0;
5233}
5234
Thomas Petazzonie0af22d2017-06-22 14:23:18 +02005235/* Reserved Tx descriptors allocation request
5236 *
5237 * Called only from mvpp2_txq_reserved_desc_num_proc(), itself called
5238 * only by mvpp2_tx(), so migration is disabled, using
5239 * smp_processor_id() is OK.
5240 */
Marcin Wojtas3f518502014-07-10 16:52:13 -03005241static int mvpp2_txq_alloc_reserved_desc(struct mvpp2 *priv,
5242 struct mvpp2_tx_queue *txq, int num)
5243{
5244 u32 val;
Thomas Petazzonia7868412017-03-07 16:53:13 +01005245 int cpu = smp_processor_id();
Marcin Wojtas3f518502014-07-10 16:52:13 -03005246
5247 val = (txq->id << MVPP2_TXQ_RSVD_REQ_Q_OFFSET) | num;
Thomas Petazzonia7868412017-03-07 16:53:13 +01005248 mvpp2_percpu_write(priv, cpu, MVPP2_TXQ_RSVD_REQ_REG, val);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005249
Thomas Petazzonia7868412017-03-07 16:53:13 +01005250 val = mvpp2_percpu_read(priv, cpu, MVPP2_TXQ_RSVD_RSLT_REG);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005251
5252 return val & MVPP2_TXQ_RSVD_RSLT_MASK;
5253}
5254
5255/* Check if there are enough reserved descriptors for transmission.
5256 * If not, request chunk of reserved descriptors and check again.
5257 */
5258static int mvpp2_txq_reserved_desc_num_proc(struct mvpp2 *priv,
5259 struct mvpp2_tx_queue *txq,
5260 struct mvpp2_txq_pcpu *txq_pcpu,
5261 int num)
5262{
5263 int req, cpu, desc_count;
5264
5265 if (txq_pcpu->reserved_num >= num)
5266 return 0;
5267
5268 /* Not enough descriptors reserved! Update the reserved descriptor
5269 * count and check again.
5270 */
5271
5272 desc_count = 0;
5273 /* Compute total of used descriptors */
5274 for_each_present_cpu(cpu) {
5275 struct mvpp2_txq_pcpu *txq_pcpu_aux;
5276
5277 txq_pcpu_aux = per_cpu_ptr(txq->pcpu, cpu);
5278 desc_count += txq_pcpu_aux->count;
5279 desc_count += txq_pcpu_aux->reserved_num;
5280 }
5281
5282 req = max(MVPP2_CPU_DESC_CHUNK, num - txq_pcpu->reserved_num);
5283 desc_count += req;
5284
5285 if (desc_count >
5286 (txq->size - (num_present_cpus() * MVPP2_CPU_DESC_CHUNK)))
5287 return -ENOMEM;
5288
5289 txq_pcpu->reserved_num += mvpp2_txq_alloc_reserved_desc(priv, txq, req);
5290
5291 /* OK, the descriptor cound has been updated: check again. */
5292 if (txq_pcpu->reserved_num < num)
5293 return -ENOMEM;
5294 return 0;
5295}
5296
5297/* Release the last allocated Tx descriptor. Useful to handle DMA
5298 * mapping failures in the Tx path.
5299 */
5300static void mvpp2_txq_desc_put(struct mvpp2_tx_queue *txq)
5301{
5302 if (txq->next_desc_to_proc == 0)
5303 txq->next_desc_to_proc = txq->last_desc - 1;
5304 else
5305 txq->next_desc_to_proc--;
5306}
5307
5308/* Set Tx descriptors fields relevant for CSUM calculation */
5309static u32 mvpp2_txq_desc_csum(int l3_offs, int l3_proto,
5310 int ip_hdr_len, int l4_proto)
5311{
5312 u32 command;
5313
5314 /* fields: L3_offset, IP_hdrlen, L3_type, G_IPv4_chk,
5315 * G_L4_chk, L4_type required only for checksum calculation
5316 */
5317 command = (l3_offs << MVPP2_TXD_L3_OFF_SHIFT);
5318 command |= (ip_hdr_len << MVPP2_TXD_IP_HLEN_SHIFT);
5319 command |= MVPP2_TXD_IP_CSUM_DISABLE;
5320
5321 if (l3_proto == swab16(ETH_P_IP)) {
5322 command &= ~MVPP2_TXD_IP_CSUM_DISABLE; /* enable IPv4 csum */
5323 command &= ~MVPP2_TXD_L3_IP6; /* enable IPv4 */
5324 } else {
5325 command |= MVPP2_TXD_L3_IP6; /* enable IPv6 */
5326 }
5327
5328 if (l4_proto == IPPROTO_TCP) {
5329 command &= ~MVPP2_TXD_L4_UDP; /* enable TCP */
5330 command &= ~MVPP2_TXD_L4_CSUM_FRAG; /* generate L4 csum */
5331 } else if (l4_proto == IPPROTO_UDP) {
5332 command |= MVPP2_TXD_L4_UDP; /* enable UDP */
5333 command &= ~MVPP2_TXD_L4_CSUM_FRAG; /* generate L4 csum */
5334 } else {
5335 command |= MVPP2_TXD_L4_CSUM_NOT;
5336 }
5337
5338 return command;
5339}
5340
5341/* Get number of sent descriptors and decrement counter.
5342 * The number of sent descriptors is returned.
5343 * Per-CPU access
Thomas Petazzonie0af22d2017-06-22 14:23:18 +02005344 *
5345 * Called only from mvpp2_txq_done(), called from mvpp2_tx()
5346 * (migration disabled) and from the TX completion tasklet (migration
5347 * disabled) so using smp_processor_id() is OK.
Marcin Wojtas3f518502014-07-10 16:52:13 -03005348 */
5349static inline int mvpp2_txq_sent_desc_proc(struct mvpp2_port *port,
5350 struct mvpp2_tx_queue *txq)
5351{
5352 u32 val;
5353
5354 /* Reading status reg resets transmitted descriptor counter */
Thomas Petazzonia7868412017-03-07 16:53:13 +01005355 val = mvpp2_percpu_read(port->priv, smp_processor_id(),
5356 MVPP2_TXQ_SENT_REG(txq->id));
Marcin Wojtas3f518502014-07-10 16:52:13 -03005357
5358 return (val & MVPP2_TRANSMITTED_COUNT_MASK) >>
5359 MVPP2_TRANSMITTED_COUNT_OFFSET;
5360}
5361
Thomas Petazzonie0af22d2017-06-22 14:23:18 +02005362/* Called through on_each_cpu(), so runs on all CPUs, with migration
5363 * disabled, therefore using smp_processor_id() is OK.
5364 */
Marcin Wojtas3f518502014-07-10 16:52:13 -03005365static void mvpp2_txq_sent_counter_clear(void *arg)
5366{
5367 struct mvpp2_port *port = arg;
5368 int queue;
5369
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005370 for (queue = 0; queue < port->ntxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005371 int id = port->txqs[queue]->id;
5372
Thomas Petazzonia7868412017-03-07 16:53:13 +01005373 mvpp2_percpu_read(port->priv, smp_processor_id(),
5374 MVPP2_TXQ_SENT_REG(id));
Marcin Wojtas3f518502014-07-10 16:52:13 -03005375 }
5376}
5377
5378/* Set max sizes for Tx queues */
5379static void mvpp2_txp_max_tx_size_set(struct mvpp2_port *port)
5380{
5381 u32 val, size, mtu;
5382 int txq, tx_port_num;
5383
5384 mtu = port->pkt_size * 8;
5385 if (mtu > MVPP2_TXP_MTU_MAX)
5386 mtu = MVPP2_TXP_MTU_MAX;
5387
5388 /* WA for wrong Token bucket update: Set MTU value = 3*real MTU value */
5389 mtu = 3 * mtu;
5390
5391 /* Indirect access to registers */
5392 tx_port_num = mvpp2_egress_port(port);
5393 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num);
5394
5395 /* Set MTU */
5396 val = mvpp2_read(port->priv, MVPP2_TXP_SCHED_MTU_REG);
5397 val &= ~MVPP2_TXP_MTU_MAX;
5398 val |= mtu;
5399 mvpp2_write(port->priv, MVPP2_TXP_SCHED_MTU_REG, val);
5400
5401 /* TXP token size and all TXQs token size must be larger that MTU */
5402 val = mvpp2_read(port->priv, MVPP2_TXP_SCHED_TOKEN_SIZE_REG);
5403 size = val & MVPP2_TXP_TOKEN_SIZE_MAX;
5404 if (size < mtu) {
5405 size = mtu;
5406 val &= ~MVPP2_TXP_TOKEN_SIZE_MAX;
5407 val |= size;
5408 mvpp2_write(port->priv, MVPP2_TXP_SCHED_TOKEN_SIZE_REG, val);
5409 }
5410
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005411 for (txq = 0; txq < port->ntxqs; txq++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005412 val = mvpp2_read(port->priv,
5413 MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq));
5414 size = val & MVPP2_TXQ_TOKEN_SIZE_MAX;
5415
5416 if (size < mtu) {
5417 size = mtu;
5418 val &= ~MVPP2_TXQ_TOKEN_SIZE_MAX;
5419 val |= size;
5420 mvpp2_write(port->priv,
5421 MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq),
5422 val);
5423 }
5424 }
5425}
5426
5427/* Set the number of packets that will be received before Rx interrupt
5428 * will be generated by HW.
5429 */
5430static void mvpp2_rx_pkts_coal_set(struct mvpp2_port *port,
Thomas Petazzonid63f9e42017-02-21 11:28:02 +01005431 struct mvpp2_rx_queue *rxq)
Marcin Wojtas3f518502014-07-10 16:52:13 -03005432{
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005433 int cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01005434
Thomas Petazzonif8b0d5f2017-02-21 11:28:03 +01005435 if (rxq->pkts_coal > MVPP2_OCCUPIED_THRESH_MASK)
5436 rxq->pkts_coal = MVPP2_OCCUPIED_THRESH_MASK;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005437
Thomas Petazzonia7868412017-03-07 16:53:13 +01005438 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_NUM_REG, rxq->id);
5439 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_THRESH_REG,
5440 rxq->pkts_coal);
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005441
5442 put_cpu();
Marcin Wojtas3f518502014-07-10 16:52:13 -03005443}
5444
Thomas Petazzoni213f4282017-08-03 10:42:00 +02005445/* For some reason in the LSP this is done on each CPU. Why ? */
5446static void mvpp2_tx_pkts_coal_set(struct mvpp2_port *port,
5447 struct mvpp2_tx_queue *txq)
5448{
5449 int cpu = get_cpu();
5450 u32 val;
5451
5452 if (txq->done_pkts_coal > MVPP2_TXQ_THRESH_MASK)
5453 txq->done_pkts_coal = MVPP2_TXQ_THRESH_MASK;
5454
5455 val = (txq->done_pkts_coal << MVPP2_TXQ_THRESH_OFFSET);
5456 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_NUM_REG, txq->id);
5457 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_THRESH_REG, val);
5458
5459 put_cpu();
5460}
5461
Thomas Petazzoniab426762017-02-21 11:28:04 +01005462static u32 mvpp2_usec_to_cycles(u32 usec, unsigned long clk_hz)
5463{
5464 u64 tmp = (u64)clk_hz * usec;
5465
5466 do_div(tmp, USEC_PER_SEC);
5467
5468 return tmp > U32_MAX ? U32_MAX : tmp;
5469}
5470
5471static u32 mvpp2_cycles_to_usec(u32 cycles, unsigned long clk_hz)
5472{
5473 u64 tmp = (u64)cycles * USEC_PER_SEC;
5474
5475 do_div(tmp, clk_hz);
5476
5477 return tmp > U32_MAX ? U32_MAX : tmp;
5478}
5479
Marcin Wojtas3f518502014-07-10 16:52:13 -03005480/* Set the time delay in usec before Rx interrupt */
5481static void mvpp2_rx_time_coal_set(struct mvpp2_port *port,
Thomas Petazzonid63f9e42017-02-21 11:28:02 +01005482 struct mvpp2_rx_queue *rxq)
Marcin Wojtas3f518502014-07-10 16:52:13 -03005483{
Thomas Petazzoniab426762017-02-21 11:28:04 +01005484 unsigned long freq = port->priv->tclk;
5485 u32 val = mvpp2_usec_to_cycles(rxq->time_coal, freq);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005486
Thomas Petazzoniab426762017-02-21 11:28:04 +01005487 if (val > MVPP2_MAX_ISR_RX_THRESHOLD) {
5488 rxq->time_coal =
5489 mvpp2_cycles_to_usec(MVPP2_MAX_ISR_RX_THRESHOLD, freq);
5490
5491 /* re-evaluate to get actual register value */
5492 val = mvpp2_usec_to_cycles(rxq->time_coal, freq);
5493 }
5494
Marcin Wojtas3f518502014-07-10 16:52:13 -03005495 mvpp2_write(port->priv, MVPP2_ISR_RX_THRESHOLD_REG(rxq->id), val);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005496}
5497
Thomas Petazzoni213f4282017-08-03 10:42:00 +02005498static void mvpp2_tx_time_coal_set(struct mvpp2_port *port)
5499{
5500 unsigned long freq = port->priv->tclk;
5501 u32 val = mvpp2_usec_to_cycles(port->tx_time_coal, freq);
5502
5503 if (val > MVPP2_MAX_ISR_TX_THRESHOLD) {
5504 port->tx_time_coal =
5505 mvpp2_cycles_to_usec(MVPP2_MAX_ISR_TX_THRESHOLD, freq);
5506
5507 /* re-evaluate to get actual register value */
5508 val = mvpp2_usec_to_cycles(port->tx_time_coal, freq);
5509 }
5510
5511 mvpp2_write(port->priv, MVPP2_ISR_TX_THRESHOLD_REG(port->id), val);
5512}
5513
Marcin Wojtas3f518502014-07-10 16:52:13 -03005514/* Free Tx queue skbuffs */
5515static void mvpp2_txq_bufs_free(struct mvpp2_port *port,
5516 struct mvpp2_tx_queue *txq,
5517 struct mvpp2_txq_pcpu *txq_pcpu, int num)
5518{
5519 int i;
5520
5521 for (i = 0; i < num; i++) {
Thomas Petazzoni83544912016-12-21 11:28:49 +01005522 struct mvpp2_txq_pcpu_buf *tx_buf =
5523 txq_pcpu->buffs + txq_pcpu->txq_get_index;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005524
Antoine Tenart20920262017-10-23 15:24:30 +02005525 if (!IS_TSO_HEADER(txq_pcpu, tx_buf->dma))
5526 dma_unmap_single(port->dev->dev.parent, tx_buf->dma,
5527 tx_buf->size, DMA_TO_DEVICE);
Thomas Petazzoni36fb7432017-02-21 11:28:05 +01005528 if (tx_buf->skb)
5529 dev_kfree_skb_any(tx_buf->skb);
5530
5531 mvpp2_txq_inc_get(txq_pcpu);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005532 }
5533}
5534
5535static inline struct mvpp2_rx_queue *mvpp2_get_rx_queue(struct mvpp2_port *port,
5536 u32 cause)
5537{
5538 int queue = fls(cause) - 1;
5539
5540 return port->rxqs[queue];
5541}
5542
5543static inline struct mvpp2_tx_queue *mvpp2_get_tx_queue(struct mvpp2_port *port,
5544 u32 cause)
5545{
Marcin Wojtasedc660f2015-08-06 19:00:30 +02005546 int queue = fls(cause) - 1;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005547
5548 return port->txqs[queue];
5549}
5550
5551/* Handle end of transmission */
5552static void mvpp2_txq_done(struct mvpp2_port *port, struct mvpp2_tx_queue *txq,
5553 struct mvpp2_txq_pcpu *txq_pcpu)
5554{
5555 struct netdev_queue *nq = netdev_get_tx_queue(port->dev, txq->log_id);
5556 int tx_done;
5557
5558 if (txq_pcpu->cpu != smp_processor_id())
5559 netdev_err(port->dev, "wrong cpu on the end of Tx processing\n");
5560
5561 tx_done = mvpp2_txq_sent_desc_proc(port, txq);
5562 if (!tx_done)
5563 return;
5564 mvpp2_txq_bufs_free(port, txq, txq_pcpu, tx_done);
5565
5566 txq_pcpu->count -= tx_done;
5567
5568 if (netif_tx_queue_stopped(nq))
Antoine Tenart1d17db02017-10-30 11:23:31 +01005569 if (txq_pcpu->count <= txq_pcpu->wake_threshold)
Marcin Wojtas3f518502014-07-10 16:52:13 -03005570 netif_tx_wake_queue(nq);
5571}
5572
Thomas Petazzoni213f4282017-08-03 10:42:00 +02005573static unsigned int mvpp2_tx_done(struct mvpp2_port *port, u32 cause,
5574 int cpu)
Marcin Wojtasedc660f2015-08-06 19:00:30 +02005575{
5576 struct mvpp2_tx_queue *txq;
5577 struct mvpp2_txq_pcpu *txq_pcpu;
5578 unsigned int tx_todo = 0;
5579
5580 while (cause) {
5581 txq = mvpp2_get_tx_queue(port, cause);
5582 if (!txq)
5583 break;
5584
Thomas Petazzoni213f4282017-08-03 10:42:00 +02005585 txq_pcpu = per_cpu_ptr(txq->pcpu, cpu);
Marcin Wojtasedc660f2015-08-06 19:00:30 +02005586
5587 if (txq_pcpu->count) {
5588 mvpp2_txq_done(port, txq, txq_pcpu);
5589 tx_todo += txq_pcpu->count;
5590 }
5591
5592 cause &= ~(1 << txq->log_id);
5593 }
5594 return tx_todo;
5595}
5596
Marcin Wojtas3f518502014-07-10 16:52:13 -03005597/* Rx/Tx queue initialization/cleanup methods */
5598
5599/* Allocate and initialize descriptors for aggr TXQ */
5600static int mvpp2_aggr_txq_init(struct platform_device *pdev,
Antoine Ténart85affd72017-08-23 09:46:55 +02005601 struct mvpp2_tx_queue *aggr_txq, int cpu,
Marcin Wojtas3f518502014-07-10 16:52:13 -03005602 struct mvpp2 *priv)
5603{
Thomas Petazzonib02f31f2017-03-07 16:53:12 +01005604 u32 txq_dma;
5605
Marcin Wojtas3f518502014-07-10 16:52:13 -03005606 /* Allocate memory for TX descriptors */
Yan Markmana154f8e2017-11-30 10:49:46 +01005607 aggr_txq->descs = dma_zalloc_coherent(&pdev->dev,
Antoine Ténart85affd72017-08-23 09:46:55 +02005608 MVPP2_AGGR_TXQ_SIZE * MVPP2_DESC_ALIGNED_SIZE,
Thomas Petazzoni20396132017-03-07 16:53:00 +01005609 &aggr_txq->descs_dma, GFP_KERNEL);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005610 if (!aggr_txq->descs)
5611 return -ENOMEM;
5612
Antoine Tenart02856a32017-10-30 11:23:32 +01005613 aggr_txq->last_desc = MVPP2_AGGR_TXQ_SIZE - 1;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005614
5615 /* Aggr TXQ no reset WA */
5616 aggr_txq->next_desc_to_proc = mvpp2_read(priv,
5617 MVPP2_AGGR_TXQ_INDEX_REG(cpu));
5618
Thomas Petazzonib02f31f2017-03-07 16:53:12 +01005619 /* Set Tx descriptors queue starting address indirect
5620 * access
5621 */
5622 if (priv->hw_version == MVPP21)
5623 txq_dma = aggr_txq->descs_dma;
5624 else
5625 txq_dma = aggr_txq->descs_dma >>
5626 MVPP22_AGGR_TXQ_DESC_ADDR_OFFS;
5627
5628 mvpp2_write(priv, MVPP2_AGGR_TXQ_DESC_ADDR_REG(cpu), txq_dma);
Antoine Ténart85affd72017-08-23 09:46:55 +02005629 mvpp2_write(priv, MVPP2_AGGR_TXQ_DESC_SIZE_REG(cpu),
5630 MVPP2_AGGR_TXQ_SIZE);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005631
5632 return 0;
5633}
5634
5635/* Create a specified Rx queue */
5636static int mvpp2_rxq_init(struct mvpp2_port *port,
5637 struct mvpp2_rx_queue *rxq)
5638
5639{
Thomas Petazzonib02f31f2017-03-07 16:53:12 +01005640 u32 rxq_dma;
Thomas Petazzonia7868412017-03-07 16:53:13 +01005641 int cpu;
Thomas Petazzonib02f31f2017-03-07 16:53:12 +01005642
Marcin Wojtas3f518502014-07-10 16:52:13 -03005643 rxq->size = port->rx_ring_size;
5644
5645 /* Allocate memory for RX descriptors */
5646 rxq->descs = dma_alloc_coherent(port->dev->dev.parent,
5647 rxq->size * MVPP2_DESC_ALIGNED_SIZE,
Thomas Petazzoni20396132017-03-07 16:53:00 +01005648 &rxq->descs_dma, GFP_KERNEL);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005649 if (!rxq->descs)
5650 return -ENOMEM;
5651
Marcin Wojtas3f518502014-07-10 16:52:13 -03005652 rxq->last_desc = rxq->size - 1;
5653
5654 /* Zero occupied and non-occupied counters - direct access */
5655 mvpp2_write(port->priv, MVPP2_RXQ_STATUS_REG(rxq->id), 0);
5656
5657 /* Set Rx descriptors queue starting address - indirect access */
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005658 cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01005659 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_NUM_REG, rxq->id);
Thomas Petazzonib02f31f2017-03-07 16:53:12 +01005660 if (port->priv->hw_version == MVPP21)
5661 rxq_dma = rxq->descs_dma;
5662 else
5663 rxq_dma = rxq->descs_dma >> MVPP22_DESC_ADDR_OFFS;
Thomas Petazzonia7868412017-03-07 16:53:13 +01005664 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_DESC_ADDR_REG, rxq_dma);
5665 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_DESC_SIZE_REG, rxq->size);
5666 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_INDEX_REG, 0);
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005667 put_cpu();
Marcin Wojtas3f518502014-07-10 16:52:13 -03005668
5669 /* Set Offset */
5670 mvpp2_rxq_offset_set(port, rxq->id, NET_SKB_PAD);
5671
5672 /* Set coalescing pkts and time */
Thomas Petazzonid63f9e42017-02-21 11:28:02 +01005673 mvpp2_rx_pkts_coal_set(port, rxq);
5674 mvpp2_rx_time_coal_set(port, rxq);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005675
5676 /* Add number of descriptors ready for receiving packets */
5677 mvpp2_rxq_status_update(port, rxq->id, 0, rxq->size);
5678
5679 return 0;
5680}
5681
5682/* Push packets received by the RXQ to BM pool */
5683static void mvpp2_rxq_drop_pkts(struct mvpp2_port *port,
5684 struct mvpp2_rx_queue *rxq)
5685{
5686 int rx_received, i;
5687
5688 rx_received = mvpp2_rxq_received(port, rxq->id);
5689 if (!rx_received)
5690 return;
5691
5692 for (i = 0; i < rx_received; i++) {
5693 struct mvpp2_rx_desc *rx_desc = mvpp2_rxq_next_desc_get(rxq);
Thomas Petazzoni56b8aae2017-06-10 23:18:21 +02005694 u32 status = mvpp2_rxdesc_status_get(port, rx_desc);
5695 int pool;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005696
Thomas Petazzoni56b8aae2017-06-10 23:18:21 +02005697 pool = (status & MVPP2_RXD_BM_POOL_ID_MASK) >>
5698 MVPP2_RXD_BM_POOL_ID_OFFS;
5699
Thomas Petazzoni7d7627b2017-06-22 14:23:20 +02005700 mvpp2_bm_pool_put(port, pool,
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01005701 mvpp2_rxdesc_dma_addr_get(port, rx_desc),
5702 mvpp2_rxdesc_cookie_get(port, rx_desc));
Marcin Wojtas3f518502014-07-10 16:52:13 -03005703 }
5704 mvpp2_rxq_status_update(port, rxq->id, rx_received, rx_received);
5705}
5706
5707/* Cleanup Rx queue */
5708static void mvpp2_rxq_deinit(struct mvpp2_port *port,
5709 struct mvpp2_rx_queue *rxq)
5710{
Thomas Petazzonia7868412017-03-07 16:53:13 +01005711 int cpu;
5712
Marcin Wojtas3f518502014-07-10 16:52:13 -03005713 mvpp2_rxq_drop_pkts(port, rxq);
5714
5715 if (rxq->descs)
5716 dma_free_coherent(port->dev->dev.parent,
5717 rxq->size * MVPP2_DESC_ALIGNED_SIZE,
5718 rxq->descs,
Thomas Petazzoni20396132017-03-07 16:53:00 +01005719 rxq->descs_dma);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005720
5721 rxq->descs = NULL;
5722 rxq->last_desc = 0;
5723 rxq->next_desc_to_proc = 0;
Thomas Petazzoni20396132017-03-07 16:53:00 +01005724 rxq->descs_dma = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005725
5726 /* Clear Rx descriptors queue starting address and size;
5727 * free descriptor number
5728 */
5729 mvpp2_write(port->priv, MVPP2_RXQ_STATUS_REG(rxq->id), 0);
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005730 cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01005731 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_NUM_REG, rxq->id);
5732 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_DESC_ADDR_REG, 0);
5733 mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_DESC_SIZE_REG, 0);
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005734 put_cpu();
Marcin Wojtas3f518502014-07-10 16:52:13 -03005735}
5736
5737/* Create and initialize a Tx queue */
5738static int mvpp2_txq_init(struct mvpp2_port *port,
5739 struct mvpp2_tx_queue *txq)
5740{
5741 u32 val;
5742 int cpu, desc, desc_per_txq, tx_port_num;
5743 struct mvpp2_txq_pcpu *txq_pcpu;
5744
5745 txq->size = port->tx_ring_size;
5746
5747 /* Allocate memory for Tx descriptors */
5748 txq->descs = dma_alloc_coherent(port->dev->dev.parent,
5749 txq->size * MVPP2_DESC_ALIGNED_SIZE,
Thomas Petazzoni20396132017-03-07 16:53:00 +01005750 &txq->descs_dma, GFP_KERNEL);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005751 if (!txq->descs)
5752 return -ENOMEM;
5753
Marcin Wojtas3f518502014-07-10 16:52:13 -03005754 txq->last_desc = txq->size - 1;
5755
5756 /* Set Tx descriptors queue starting address - indirect access */
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005757 cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01005758 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_NUM_REG, txq->id);
5759 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_DESC_ADDR_REG,
5760 txq->descs_dma);
5761 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_DESC_SIZE_REG,
5762 txq->size & MVPP2_TXQ_DESC_SIZE_MASK);
5763 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_INDEX_REG, 0);
5764 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_RSVD_CLR_REG,
5765 txq->id << MVPP2_TXQ_RSVD_CLR_OFFSET);
5766 val = mvpp2_percpu_read(port->priv, cpu, MVPP2_TXQ_PENDING_REG);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005767 val &= ~MVPP2_TXQ_PENDING_MASK;
Thomas Petazzonia7868412017-03-07 16:53:13 +01005768 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_PENDING_REG, val);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005769
5770 /* Calculate base address in prefetch buffer. We reserve 16 descriptors
5771 * for each existing TXQ.
5772 * TCONTS for PON port must be continuous from 0 to MVPP2_MAX_TCONT
5773 * GBE ports assumed to be continious from 0 to MVPP2_MAX_PORTS
5774 */
5775 desc_per_txq = 16;
5776 desc = (port->id * MVPP2_MAX_TXQ * desc_per_txq) +
5777 (txq->log_id * desc_per_txq);
5778
Thomas Petazzonia7868412017-03-07 16:53:13 +01005779 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_PREF_BUF_REG,
5780 MVPP2_PREF_BUF_PTR(desc) | MVPP2_PREF_BUF_SIZE_16 |
5781 MVPP2_PREF_BUF_THRESH(desc_per_txq / 2));
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005782 put_cpu();
Marcin Wojtas3f518502014-07-10 16:52:13 -03005783
5784 /* WRR / EJP configuration - indirect access */
5785 tx_port_num = mvpp2_egress_port(port);
5786 mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num);
5787
5788 val = mvpp2_read(port->priv, MVPP2_TXQ_SCHED_REFILL_REG(txq->log_id));
5789 val &= ~MVPP2_TXQ_REFILL_PERIOD_ALL_MASK;
5790 val |= MVPP2_TXQ_REFILL_PERIOD_MASK(1);
5791 val |= MVPP2_TXQ_REFILL_TOKENS_ALL_MASK;
5792 mvpp2_write(port->priv, MVPP2_TXQ_SCHED_REFILL_REG(txq->log_id), val);
5793
5794 val = MVPP2_TXQ_TOKEN_SIZE_MAX;
5795 mvpp2_write(port->priv, MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq->log_id),
5796 val);
5797
5798 for_each_present_cpu(cpu) {
5799 txq_pcpu = per_cpu_ptr(txq->pcpu, cpu);
5800 txq_pcpu->size = txq->size;
Markus Elfring02c91ec2017-04-17 08:09:07 +02005801 txq_pcpu->buffs = kmalloc_array(txq_pcpu->size,
5802 sizeof(*txq_pcpu->buffs),
5803 GFP_KERNEL);
Thomas Petazzoni83544912016-12-21 11:28:49 +01005804 if (!txq_pcpu->buffs)
Antoine Tenartba2d8d82017-11-28 14:19:48 +01005805 return -ENOMEM;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005806
5807 txq_pcpu->count = 0;
5808 txq_pcpu->reserved_num = 0;
5809 txq_pcpu->txq_put_index = 0;
5810 txq_pcpu->txq_get_index = 0;
Antoine Tenartb70d4a52017-12-11 09:13:25 +01005811 txq_pcpu->tso_headers = NULL;
Antoine Ténart186cd4d2017-08-23 09:46:56 +02005812
Antoine Tenart1d17db02017-10-30 11:23:31 +01005813 txq_pcpu->stop_threshold = txq->size - MVPP2_MAX_SKB_DESCS;
5814 txq_pcpu->wake_threshold = txq_pcpu->stop_threshold / 2;
5815
Antoine Ténart186cd4d2017-08-23 09:46:56 +02005816 txq_pcpu->tso_headers =
5817 dma_alloc_coherent(port->dev->dev.parent,
Yan Markman822eaf72017-10-23 15:24:29 +02005818 txq_pcpu->size * TSO_HEADER_SIZE,
Antoine Ténart186cd4d2017-08-23 09:46:56 +02005819 &txq_pcpu->tso_headers_dma,
5820 GFP_KERNEL);
5821 if (!txq_pcpu->tso_headers)
Antoine Tenartba2d8d82017-11-28 14:19:48 +01005822 return -ENOMEM;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005823 }
5824
5825 return 0;
5826}
5827
5828/* Free allocated TXQ resources */
5829static void mvpp2_txq_deinit(struct mvpp2_port *port,
5830 struct mvpp2_tx_queue *txq)
5831{
5832 struct mvpp2_txq_pcpu *txq_pcpu;
5833 int cpu;
5834
5835 for_each_present_cpu(cpu) {
5836 txq_pcpu = per_cpu_ptr(txq->pcpu, cpu);
Thomas Petazzoni83544912016-12-21 11:28:49 +01005837 kfree(txq_pcpu->buffs);
Antoine Ténart186cd4d2017-08-23 09:46:56 +02005838
Antoine Tenartb70d4a52017-12-11 09:13:25 +01005839 if (txq_pcpu->tso_headers)
5840 dma_free_coherent(port->dev->dev.parent,
5841 txq_pcpu->size * TSO_HEADER_SIZE,
5842 txq_pcpu->tso_headers,
5843 txq_pcpu->tso_headers_dma);
5844
5845 txq_pcpu->tso_headers = NULL;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005846 }
5847
5848 if (txq->descs)
5849 dma_free_coherent(port->dev->dev.parent,
5850 txq->size * MVPP2_DESC_ALIGNED_SIZE,
Thomas Petazzoni20396132017-03-07 16:53:00 +01005851 txq->descs, txq->descs_dma);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005852
5853 txq->descs = NULL;
5854 txq->last_desc = 0;
5855 txq->next_desc_to_proc = 0;
Thomas Petazzoni20396132017-03-07 16:53:00 +01005856 txq->descs_dma = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005857
5858 /* Set minimum bandwidth for disabled TXQs */
5859 mvpp2_write(port->priv, MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(txq->id), 0);
5860
5861 /* Set Tx descriptors queue starting address and size */
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005862 cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01005863 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_NUM_REG, txq->id);
5864 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_DESC_ADDR_REG, 0);
5865 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_DESC_SIZE_REG, 0);
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005866 put_cpu();
Marcin Wojtas3f518502014-07-10 16:52:13 -03005867}
5868
5869/* Cleanup Tx ports */
5870static void mvpp2_txq_clean(struct mvpp2_port *port, struct mvpp2_tx_queue *txq)
5871{
5872 struct mvpp2_txq_pcpu *txq_pcpu;
5873 int delay, pending, cpu;
5874 u32 val;
5875
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005876 cpu = get_cpu();
Thomas Petazzonia7868412017-03-07 16:53:13 +01005877 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_NUM_REG, txq->id);
5878 val = mvpp2_percpu_read(port->priv, cpu, MVPP2_TXQ_PREF_BUF_REG);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005879 val |= MVPP2_TXQ_DRAIN_EN_MASK;
Thomas Petazzonia7868412017-03-07 16:53:13 +01005880 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_PREF_BUF_REG, val);
Marcin Wojtas3f518502014-07-10 16:52:13 -03005881
5882 /* The napi queue has been stopped so wait for all packets
5883 * to be transmitted.
5884 */
5885 delay = 0;
5886 do {
5887 if (delay >= MVPP2_TX_PENDING_TIMEOUT_MSEC) {
5888 netdev_warn(port->dev,
5889 "port %d: cleaning queue %d timed out\n",
5890 port->id, txq->log_id);
5891 break;
5892 }
5893 mdelay(1);
5894 delay++;
5895
Thomas Petazzonia7868412017-03-07 16:53:13 +01005896 pending = mvpp2_percpu_read(port->priv, cpu,
5897 MVPP2_TXQ_PENDING_REG);
5898 pending &= MVPP2_TXQ_PENDING_MASK;
Marcin Wojtas3f518502014-07-10 16:52:13 -03005899 } while (pending);
5900
5901 val &= ~MVPP2_TXQ_DRAIN_EN_MASK;
Thomas Petazzonia7868412017-03-07 16:53:13 +01005902 mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_PREF_BUF_REG, val);
Thomas Petazzonia704bb52017-06-10 23:18:22 +02005903 put_cpu();
Marcin Wojtas3f518502014-07-10 16:52:13 -03005904
5905 for_each_present_cpu(cpu) {
5906 txq_pcpu = per_cpu_ptr(txq->pcpu, cpu);
5907
5908 /* Release all packets */
5909 mvpp2_txq_bufs_free(port, txq, txq_pcpu, txq_pcpu->count);
5910
5911 /* Reset queue */
5912 txq_pcpu->count = 0;
5913 txq_pcpu->txq_put_index = 0;
5914 txq_pcpu->txq_get_index = 0;
5915 }
5916}
5917
5918/* Cleanup all Tx queues */
5919static void mvpp2_cleanup_txqs(struct mvpp2_port *port)
5920{
5921 struct mvpp2_tx_queue *txq;
5922 int queue;
5923 u32 val;
5924
5925 val = mvpp2_read(port->priv, MVPP2_TX_PORT_FLUSH_REG);
5926
5927 /* Reset Tx ports and delete Tx queues */
5928 val |= MVPP2_TX_PORT_FLUSH_MASK(port->id);
5929 mvpp2_write(port->priv, MVPP2_TX_PORT_FLUSH_REG, val);
5930
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005931 for (queue = 0; queue < port->ntxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005932 txq = port->txqs[queue];
5933 mvpp2_txq_clean(port, txq);
5934 mvpp2_txq_deinit(port, txq);
5935 }
5936
5937 on_each_cpu(mvpp2_txq_sent_counter_clear, port, 1);
5938
5939 val &= ~MVPP2_TX_PORT_FLUSH_MASK(port->id);
5940 mvpp2_write(port->priv, MVPP2_TX_PORT_FLUSH_REG, val);
5941}
5942
5943/* Cleanup all Rx queues */
5944static void mvpp2_cleanup_rxqs(struct mvpp2_port *port)
5945{
5946 int queue;
5947
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005948 for (queue = 0; queue < port->nrxqs; queue++)
Marcin Wojtas3f518502014-07-10 16:52:13 -03005949 mvpp2_rxq_deinit(port, port->rxqs[queue]);
5950}
5951
5952/* Init all Rx queues for port */
5953static int mvpp2_setup_rxqs(struct mvpp2_port *port)
5954{
5955 int queue, err;
5956
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005957 for (queue = 0; queue < port->nrxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005958 err = mvpp2_rxq_init(port, port->rxqs[queue]);
5959 if (err)
5960 goto err_cleanup;
5961 }
5962 return 0;
5963
5964err_cleanup:
5965 mvpp2_cleanup_rxqs(port);
5966 return err;
5967}
5968
5969/* Init all tx queues for port */
5970static int mvpp2_setup_txqs(struct mvpp2_port *port)
5971{
5972 struct mvpp2_tx_queue *txq;
5973 int queue, err;
5974
Thomas Petazzoni09f83972017-08-03 10:41:57 +02005975 for (queue = 0; queue < port->ntxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03005976 txq = port->txqs[queue];
5977 err = mvpp2_txq_init(port, txq);
5978 if (err)
5979 goto err_cleanup;
5980 }
5981
Thomas Petazzoni213f4282017-08-03 10:42:00 +02005982 if (port->has_tx_irqs) {
5983 mvpp2_tx_time_coal_set(port);
5984 for (queue = 0; queue < port->ntxqs; queue++) {
5985 txq = port->txqs[queue];
5986 mvpp2_tx_pkts_coal_set(port, txq);
5987 }
5988 }
5989
Marcin Wojtas3f518502014-07-10 16:52:13 -03005990 on_each_cpu(mvpp2_txq_sent_counter_clear, port, 1);
5991 return 0;
5992
5993err_cleanup:
5994 mvpp2_cleanup_txqs(port);
5995 return err;
5996}
5997
5998/* The callback for per-port interrupt */
5999static irqreturn_t mvpp2_isr(int irq, void *dev_id)
6000{
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006001 struct mvpp2_queue_vector *qv = dev_id;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006002
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006003 mvpp2_qvec_interrupt_disable(qv);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006004
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006005 napi_schedule(&qv->napi);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006006
6007 return IRQ_HANDLED;
6008}
6009
Antoine Tenartfd3651b2017-09-01 11:04:54 +02006010/* Per-port interrupt for link status changes */
6011static irqreturn_t mvpp2_link_status_isr(int irq, void *dev_id)
6012{
6013 struct mvpp2_port *port = (struct mvpp2_port *)dev_id;
6014 struct net_device *dev = port->dev;
6015 bool event = false, link = false;
6016 u32 val;
6017
6018 mvpp22_gop_mask_irq(port);
6019
6020 if (port->gop_id == 0 &&
6021 port->phy_interface == PHY_INTERFACE_MODE_10GKR) {
6022 val = readl(port->base + MVPP22_XLG_INT_STAT);
6023 if (val & MVPP22_XLG_INT_STAT_LINK) {
6024 event = true;
6025 val = readl(port->base + MVPP22_XLG_STATUS);
6026 if (val & MVPP22_XLG_STATUS_LINK_UP)
6027 link = true;
6028 }
6029 } else if (phy_interface_mode_is_rgmii(port->phy_interface) ||
6030 port->phy_interface == PHY_INTERFACE_MODE_SGMII) {
6031 val = readl(port->base + MVPP22_GMAC_INT_STAT);
6032 if (val & MVPP22_GMAC_INT_STAT_LINK) {
6033 event = true;
6034 val = readl(port->base + MVPP2_GMAC_STATUS0);
6035 if (val & MVPP2_GMAC_STATUS0_LINK_UP)
6036 link = true;
6037 }
6038 }
6039
6040 if (!netif_running(dev) || !event)
6041 goto handled;
6042
6043 if (link) {
6044 mvpp2_interrupts_enable(port);
6045
6046 mvpp2_egress_enable(port);
6047 mvpp2_ingress_enable(port);
6048 netif_carrier_on(dev);
6049 netif_tx_wake_all_queues(dev);
6050 } else {
6051 netif_tx_stop_all_queues(dev);
6052 netif_carrier_off(dev);
6053 mvpp2_ingress_disable(port);
6054 mvpp2_egress_disable(port);
6055
6056 mvpp2_interrupts_disable(port);
6057 }
6058
6059handled:
6060 mvpp22_gop_unmask_irq(port);
6061 return IRQ_HANDLED;
6062}
6063
Antoine Tenart65a2c092017-08-30 10:29:18 +02006064static void mvpp2_gmac_set_autoneg(struct mvpp2_port *port,
6065 struct phy_device *phydev)
6066{
6067 u32 val;
6068
6069 if (port->phy_interface != PHY_INTERFACE_MODE_RGMII &&
6070 port->phy_interface != PHY_INTERFACE_MODE_RGMII_ID &&
6071 port->phy_interface != PHY_INTERFACE_MODE_RGMII_RXID &&
6072 port->phy_interface != PHY_INTERFACE_MODE_RGMII_TXID &&
6073 port->phy_interface != PHY_INTERFACE_MODE_SGMII)
6074 return;
6075
6076 val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG);
6077 val &= ~(MVPP2_GMAC_CONFIG_MII_SPEED |
6078 MVPP2_GMAC_CONFIG_GMII_SPEED |
6079 MVPP2_GMAC_CONFIG_FULL_DUPLEX |
6080 MVPP2_GMAC_AN_SPEED_EN |
6081 MVPP2_GMAC_AN_DUPLEX_EN);
6082
6083 if (phydev->duplex)
6084 val |= MVPP2_GMAC_CONFIG_FULL_DUPLEX;
6085
6086 if (phydev->speed == SPEED_1000)
6087 val |= MVPP2_GMAC_CONFIG_GMII_SPEED;
6088 else if (phydev->speed == SPEED_100)
6089 val |= MVPP2_GMAC_CONFIG_MII_SPEED;
6090
6091 writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG);
Antoine Tenart65a2c092017-08-30 10:29:18 +02006092}
6093
Marcin Wojtas3f518502014-07-10 16:52:13 -03006094/* Adjust link */
6095static void mvpp2_link_event(struct net_device *dev)
6096{
6097 struct mvpp2_port *port = netdev_priv(dev);
Philippe Reynes8e072692016-06-28 00:08:11 +02006098 struct phy_device *phydev = dev->phydev;
Antoine Tenart89273bc2017-08-30 10:29:19 +02006099 bool link_reconfigured = false;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006100 u32 val;
6101
6102 if (phydev->link) {
Antoine Tenart89273bc2017-08-30 10:29:19 +02006103 if (port->phy_interface != phydev->interface && port->comphy) {
6104 /* disable current port for reconfiguration */
6105 mvpp2_interrupts_disable(port);
6106 netif_carrier_off(port->dev);
6107 mvpp2_port_disable(port);
6108 phy_power_off(port->comphy);
6109
6110 /* comphy reconfiguration */
6111 port->phy_interface = phydev->interface;
6112 mvpp22_comphy_init(port);
6113
6114 /* gop/mac reconfiguration */
6115 mvpp22_gop_init(port);
6116 mvpp2_port_mii_set(port);
6117
6118 link_reconfigured = true;
6119 }
6120
Marcin Wojtas3f518502014-07-10 16:52:13 -03006121 if ((port->speed != phydev->speed) ||
6122 (port->duplex != phydev->duplex)) {
Antoine Tenart65a2c092017-08-30 10:29:18 +02006123 mvpp2_gmac_set_autoneg(port, phydev);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006124
6125 port->duplex = phydev->duplex;
6126 port->speed = phydev->speed;
6127 }
6128 }
6129
Antoine Tenart89273bc2017-08-30 10:29:19 +02006130 if (phydev->link != port->link || link_reconfigured) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03006131 port->link = phydev->link;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006132
Marcin Wojtas3f518502014-07-10 16:52:13 -03006133 if (phydev->link) {
Antoine Tenart65a2c092017-08-30 10:29:18 +02006134 if (port->phy_interface == PHY_INTERFACE_MODE_RGMII ||
6135 port->phy_interface == PHY_INTERFACE_MODE_RGMII_ID ||
6136 port->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID ||
6137 port->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID ||
6138 port->phy_interface == PHY_INTERFACE_MODE_SGMII) {
6139 val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG);
6140 val |= (MVPP2_GMAC_FORCE_LINK_PASS |
6141 MVPP2_GMAC_FORCE_LINK_DOWN);
6142 writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG);
6143 }
Antoine Tenartf55744a2017-08-30 10:29:17 +02006144
6145 mvpp2_interrupts_enable(port);
6146 mvpp2_port_enable(port);
6147
Marcin Wojtas3f518502014-07-10 16:52:13 -03006148 mvpp2_egress_enable(port);
6149 mvpp2_ingress_enable(port);
Antoine Tenartf55744a2017-08-30 10:29:17 +02006150 netif_carrier_on(dev);
6151 netif_tx_wake_all_queues(dev);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006152 } else {
Antoine Tenart968b2112017-08-30 10:29:16 +02006153 port->duplex = -1;
6154 port->speed = 0;
6155
Antoine Tenartf55744a2017-08-30 10:29:17 +02006156 netif_tx_stop_all_queues(dev);
6157 netif_carrier_off(dev);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006158 mvpp2_ingress_disable(port);
6159 mvpp2_egress_disable(port);
Antoine Tenartf55744a2017-08-30 10:29:17 +02006160
6161 mvpp2_port_disable(port);
6162 mvpp2_interrupts_disable(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006163 }
Antoine Tenart968b2112017-08-30 10:29:16 +02006164
Marcin Wojtas3f518502014-07-10 16:52:13 -03006165 phy_print_status(phydev);
6166 }
6167}
6168
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006169static void mvpp2_timer_set(struct mvpp2_port_pcpu *port_pcpu)
6170{
6171 ktime_t interval;
6172
6173 if (!port_pcpu->timer_scheduled) {
6174 port_pcpu->timer_scheduled = true;
Thomas Gleixner8b0e1952016-12-25 12:30:41 +01006175 interval = MVPP2_TXDONE_HRTIMER_PERIOD_NS;
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006176 hrtimer_start(&port_pcpu->tx_done_timer, interval,
6177 HRTIMER_MODE_REL_PINNED);
6178 }
6179}
6180
6181static void mvpp2_tx_proc_cb(unsigned long data)
6182{
6183 struct net_device *dev = (struct net_device *)data;
6184 struct mvpp2_port *port = netdev_priv(dev);
6185 struct mvpp2_port_pcpu *port_pcpu = this_cpu_ptr(port->pcpu);
6186 unsigned int tx_todo, cause;
6187
6188 if (!netif_running(dev))
6189 return;
6190 port_pcpu->timer_scheduled = false;
6191
6192 /* Process all the Tx queues */
Thomas Petazzoni09f83972017-08-03 10:41:57 +02006193 cause = (1 << port->ntxqs) - 1;
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006194 tx_todo = mvpp2_tx_done(port, cause, smp_processor_id());
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006195
6196 /* Set the timer in case not all the packets were processed */
6197 if (tx_todo)
6198 mvpp2_timer_set(port_pcpu);
6199}
6200
6201static enum hrtimer_restart mvpp2_hr_timer_cb(struct hrtimer *timer)
6202{
6203 struct mvpp2_port_pcpu *port_pcpu = container_of(timer,
6204 struct mvpp2_port_pcpu,
6205 tx_done_timer);
6206
6207 tasklet_schedule(&port_pcpu->tx_done_tasklet);
6208
6209 return HRTIMER_NORESTART;
6210}
6211
Marcin Wojtas3f518502014-07-10 16:52:13 -03006212/* Main RX/TX processing routines */
6213
6214/* Display more error info */
6215static void mvpp2_rx_error(struct mvpp2_port *port,
6216 struct mvpp2_rx_desc *rx_desc)
6217{
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006218 u32 status = mvpp2_rxdesc_status_get(port, rx_desc);
6219 size_t sz = mvpp2_rxdesc_size_get(port, rx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006220
6221 switch (status & MVPP2_RXD_ERR_CODE_MASK) {
6222 case MVPP2_RXD_ERR_CRC:
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006223 netdev_err(port->dev, "bad rx status %08x (crc error), size=%zu\n",
6224 status, sz);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006225 break;
6226 case MVPP2_RXD_ERR_OVERRUN:
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006227 netdev_err(port->dev, "bad rx status %08x (overrun error), size=%zu\n",
6228 status, sz);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006229 break;
6230 case MVPP2_RXD_ERR_RESOURCE:
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006231 netdev_err(port->dev, "bad rx status %08x (resource error), size=%zu\n",
6232 status, sz);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006233 break;
6234 }
6235}
6236
6237/* Handle RX checksum offload */
6238static void mvpp2_rx_csum(struct mvpp2_port *port, u32 status,
6239 struct sk_buff *skb)
6240{
6241 if (((status & MVPP2_RXD_L3_IP4) &&
6242 !(status & MVPP2_RXD_IP4_HEADER_ERR)) ||
6243 (status & MVPP2_RXD_L3_IP6))
6244 if (((status & MVPP2_RXD_L4_UDP) ||
6245 (status & MVPP2_RXD_L4_TCP)) &&
6246 (status & MVPP2_RXD_L4_CSUM_OK)) {
6247 skb->csum = 0;
6248 skb->ip_summed = CHECKSUM_UNNECESSARY;
6249 return;
6250 }
6251
6252 skb->ip_summed = CHECKSUM_NONE;
6253}
6254
6255/* Reuse skb if possible, or allocate a new skb and add it to BM pool */
6256static int mvpp2_rx_refill(struct mvpp2_port *port,
Thomas Petazzoni56b8aae2017-06-10 23:18:21 +02006257 struct mvpp2_bm_pool *bm_pool, int pool)
Marcin Wojtas3f518502014-07-10 16:52:13 -03006258{
Thomas Petazzoni20396132017-03-07 16:53:00 +01006259 dma_addr_t dma_addr;
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01006260 phys_addr_t phys_addr;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01006261 void *buf;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006262
Marcin Wojtas3f518502014-07-10 16:52:13 -03006263 /* No recycle or too many buffers are in use, so allocate a new skb */
Thomas Petazzoni4e4a1052017-03-07 16:53:04 +01006264 buf = mvpp2_buf_alloc(port, bm_pool, &dma_addr, &phys_addr,
6265 GFP_ATOMIC);
Thomas Petazzoni0e037282017-02-21 11:28:12 +01006266 if (!buf)
Marcin Wojtas3f518502014-07-10 16:52:13 -03006267 return -ENOMEM;
6268
Thomas Petazzoni7d7627b2017-06-22 14:23:20 +02006269 mvpp2_bm_pool_put(port, pool, dma_addr, phys_addr);
Thomas Petazzoni7ef7e1d2017-02-21 11:28:07 +01006270
Marcin Wojtas3f518502014-07-10 16:52:13 -03006271 return 0;
6272}
6273
6274/* Handle tx checksum */
6275static u32 mvpp2_skb_tx_csum(struct mvpp2_port *port, struct sk_buff *skb)
6276{
6277 if (skb->ip_summed == CHECKSUM_PARTIAL) {
6278 int ip_hdr_len = 0;
6279 u8 l4_proto;
6280
6281 if (skb->protocol == htons(ETH_P_IP)) {
6282 struct iphdr *ip4h = ip_hdr(skb);
6283
6284 /* Calculate IPv4 checksum and L4 checksum */
6285 ip_hdr_len = ip4h->ihl;
6286 l4_proto = ip4h->protocol;
6287 } else if (skb->protocol == htons(ETH_P_IPV6)) {
6288 struct ipv6hdr *ip6h = ipv6_hdr(skb);
6289
6290 /* Read l4_protocol from one of IPv6 extra headers */
6291 if (skb_network_header_len(skb) > 0)
6292 ip_hdr_len = (skb_network_header_len(skb) >> 2);
6293 l4_proto = ip6h->nexthdr;
6294 } else {
6295 return MVPP2_TXD_L4_CSUM_NOT;
6296 }
6297
6298 return mvpp2_txq_desc_csum(skb_network_offset(skb),
6299 skb->protocol, ip_hdr_len, l4_proto);
6300 }
6301
6302 return MVPP2_TXD_L4_CSUM_NOT | MVPP2_TXD_IP_CSUM_DISABLE;
6303}
6304
Marcin Wojtas3f518502014-07-10 16:52:13 -03006305/* Main rx processing */
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006306static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi,
6307 int rx_todo, struct mvpp2_rx_queue *rxq)
Marcin Wojtas3f518502014-07-10 16:52:13 -03006308{
6309 struct net_device *dev = port->dev;
Marcin Wojtasb5015852015-12-03 15:20:51 +01006310 int rx_received;
6311 int rx_done = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006312 u32 rcvd_pkts = 0;
6313 u32 rcvd_bytes = 0;
6314
6315 /* Get number of received packets and clamp the to-do */
6316 rx_received = mvpp2_rxq_received(port, rxq->id);
6317 if (rx_todo > rx_received)
6318 rx_todo = rx_received;
6319
Marcin Wojtasb5015852015-12-03 15:20:51 +01006320 while (rx_done < rx_todo) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03006321 struct mvpp2_rx_desc *rx_desc = mvpp2_rxq_next_desc_get(rxq);
6322 struct mvpp2_bm_pool *bm_pool;
6323 struct sk_buff *skb;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01006324 unsigned int frag_size;
Thomas Petazzoni20396132017-03-07 16:53:00 +01006325 dma_addr_t dma_addr;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006326 phys_addr_t phys_addr;
Thomas Petazzoni56b8aae2017-06-10 23:18:21 +02006327 u32 rx_status;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006328 int pool, rx_bytes, err;
Thomas Petazzoni0e037282017-02-21 11:28:12 +01006329 void *data;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006330
Marcin Wojtasb5015852015-12-03 15:20:51 +01006331 rx_done++;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006332 rx_status = mvpp2_rxdesc_status_get(port, rx_desc);
6333 rx_bytes = mvpp2_rxdesc_size_get(port, rx_desc);
6334 rx_bytes -= MVPP2_MH_SIZE;
6335 dma_addr = mvpp2_rxdesc_dma_addr_get(port, rx_desc);
6336 phys_addr = mvpp2_rxdesc_cookie_get(port, rx_desc);
6337 data = (void *)phys_to_virt(phys_addr);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006338
Thomas Petazzoni56b8aae2017-06-10 23:18:21 +02006339 pool = (rx_status & MVPP2_RXD_BM_POOL_ID_MASK) >>
6340 MVPP2_RXD_BM_POOL_ID_OFFS;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006341 bm_pool = &port->priv->bm_pools[pool];
Marcin Wojtas3f518502014-07-10 16:52:13 -03006342
6343 /* In case of an error, release the requested buffer pointer
6344 * to the Buffer Manager. This request process is controlled
6345 * by the hardware, and the information about the buffer is
6346 * comprised by the RX descriptor.
6347 */
6348 if (rx_status & MVPP2_RXD_ERR_SUMMARY) {
Markus Elfring8a524882017-04-17 10:52:02 +02006349err_drop_frame:
Marcin Wojtas3f518502014-07-10 16:52:13 -03006350 dev->stats.rx_errors++;
6351 mvpp2_rx_error(port, rx_desc);
Marcin Wojtasb5015852015-12-03 15:20:51 +01006352 /* Return the buffer to the pool */
Thomas Petazzoni7d7627b2017-06-22 14:23:20 +02006353 mvpp2_bm_pool_put(port, pool, dma_addr, phys_addr);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006354 continue;
6355 }
6356
Thomas Petazzoni0e037282017-02-21 11:28:12 +01006357 if (bm_pool->frag_size > PAGE_SIZE)
6358 frag_size = 0;
6359 else
6360 frag_size = bm_pool->frag_size;
6361
6362 skb = build_skb(data, frag_size);
6363 if (!skb) {
6364 netdev_warn(port->dev, "skb build failed\n");
6365 goto err_drop_frame;
6366 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03006367
Thomas Petazzoni56b8aae2017-06-10 23:18:21 +02006368 err = mvpp2_rx_refill(port, bm_pool, pool);
Marcin Wojtasb5015852015-12-03 15:20:51 +01006369 if (err) {
6370 netdev_err(port->dev, "failed to refill BM pools\n");
6371 goto err_drop_frame;
6372 }
6373
Thomas Petazzoni20396132017-03-07 16:53:00 +01006374 dma_unmap_single(dev->dev.parent, dma_addr,
Marcin Wojtas4229d502015-12-03 15:20:50 +01006375 bm_pool->buf_size, DMA_FROM_DEVICE);
6376
Marcin Wojtas3f518502014-07-10 16:52:13 -03006377 rcvd_pkts++;
6378 rcvd_bytes += rx_bytes;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006379
Thomas Petazzoni0e037282017-02-21 11:28:12 +01006380 skb_reserve(skb, MVPP2_MH_SIZE + NET_SKB_PAD);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006381 skb_put(skb, rx_bytes);
6382 skb->protocol = eth_type_trans(skb, dev);
6383 mvpp2_rx_csum(port, rx_status, skb);
6384
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006385 napi_gro_receive(napi, skb);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006386 }
6387
6388 if (rcvd_pkts) {
6389 struct mvpp2_pcpu_stats *stats = this_cpu_ptr(port->stats);
6390
6391 u64_stats_update_begin(&stats->syncp);
6392 stats->rx_packets += rcvd_pkts;
6393 stats->rx_bytes += rcvd_bytes;
6394 u64_stats_update_end(&stats->syncp);
6395 }
6396
6397 /* Update Rx queue management counters */
6398 wmb();
Marcin Wojtasb5015852015-12-03 15:20:51 +01006399 mvpp2_rxq_status_update(port, rxq->id, rx_done, rx_done);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006400
6401 return rx_todo;
6402}
6403
6404static inline void
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006405tx_desc_unmap_put(struct mvpp2_port *port, struct mvpp2_tx_queue *txq,
Marcin Wojtas3f518502014-07-10 16:52:13 -03006406 struct mvpp2_tx_desc *desc)
6407{
Antoine Tenart20920262017-10-23 15:24:30 +02006408 struct mvpp2_txq_pcpu *txq_pcpu = this_cpu_ptr(txq->pcpu);
6409
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006410 dma_addr_t buf_dma_addr =
6411 mvpp2_txdesc_dma_addr_get(port, desc);
6412 size_t buf_sz =
6413 mvpp2_txdesc_size_get(port, desc);
Antoine Tenart20920262017-10-23 15:24:30 +02006414 if (!IS_TSO_HEADER(txq_pcpu, buf_dma_addr))
6415 dma_unmap_single(port->dev->dev.parent, buf_dma_addr,
6416 buf_sz, DMA_TO_DEVICE);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006417 mvpp2_txq_desc_put(txq);
6418}
6419
6420/* Handle tx fragmentation processing */
6421static int mvpp2_tx_frag_process(struct mvpp2_port *port, struct sk_buff *skb,
6422 struct mvpp2_tx_queue *aggr_txq,
6423 struct mvpp2_tx_queue *txq)
6424{
6425 struct mvpp2_txq_pcpu *txq_pcpu = this_cpu_ptr(txq->pcpu);
6426 struct mvpp2_tx_desc *tx_desc;
6427 int i;
Thomas Petazzoni20396132017-03-07 16:53:00 +01006428 dma_addr_t buf_dma_addr;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006429
6430 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
6431 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
6432 void *addr = page_address(frag->page.p) + frag->page_offset;
6433
6434 tx_desc = mvpp2_txq_next_desc_get(aggr_txq);
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006435 mvpp2_txdesc_txq_set(port, tx_desc, txq->id);
6436 mvpp2_txdesc_size_set(port, tx_desc, frag->size);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006437
Thomas Petazzoni20396132017-03-07 16:53:00 +01006438 buf_dma_addr = dma_map_single(port->dev->dev.parent, addr,
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006439 frag->size,
6440 DMA_TO_DEVICE);
Thomas Petazzoni20396132017-03-07 16:53:00 +01006441 if (dma_mapping_error(port->dev->dev.parent, buf_dma_addr)) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03006442 mvpp2_txq_desc_put(txq);
Markus Elfring32bae632017-04-17 11:36:34 +02006443 goto cleanup;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006444 }
6445
Antoine Tenart6eb5d372017-10-30 11:23:33 +01006446 mvpp2_txdesc_dma_addr_set(port, tx_desc, buf_dma_addr);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006447
6448 if (i == (skb_shinfo(skb)->nr_frags - 1)) {
6449 /* Last descriptor */
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006450 mvpp2_txdesc_cmd_set(port, tx_desc,
6451 MVPP2_TXD_L_DESC);
6452 mvpp2_txq_inc_put(port, txq_pcpu, skb, tx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006453 } else {
6454 /* Descriptor in the middle: Not First, Not Last */
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006455 mvpp2_txdesc_cmd_set(port, tx_desc, 0);
6456 mvpp2_txq_inc_put(port, txq_pcpu, NULL, tx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006457 }
6458 }
6459
6460 return 0;
Markus Elfring32bae632017-04-17 11:36:34 +02006461cleanup:
Marcin Wojtas3f518502014-07-10 16:52:13 -03006462 /* Release all descriptors that were used to map fragments of
6463 * this packet, as well as the corresponding DMA mappings
6464 */
6465 for (i = i - 1; i >= 0; i--) {
6466 tx_desc = txq->descs + i;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006467 tx_desc_unmap_put(port, txq, tx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006468 }
6469
6470 return -ENOMEM;
6471}
6472
Antoine Ténart186cd4d2017-08-23 09:46:56 +02006473static inline void mvpp2_tso_put_hdr(struct sk_buff *skb,
6474 struct net_device *dev,
6475 struct mvpp2_tx_queue *txq,
6476 struct mvpp2_tx_queue *aggr_txq,
6477 struct mvpp2_txq_pcpu *txq_pcpu,
6478 int hdr_sz)
6479{
6480 struct mvpp2_port *port = netdev_priv(dev);
6481 struct mvpp2_tx_desc *tx_desc = mvpp2_txq_next_desc_get(aggr_txq);
6482 dma_addr_t addr;
6483
6484 mvpp2_txdesc_txq_set(port, tx_desc, txq->id);
6485 mvpp2_txdesc_size_set(port, tx_desc, hdr_sz);
6486
6487 addr = txq_pcpu->tso_headers_dma +
6488 txq_pcpu->txq_put_index * TSO_HEADER_SIZE;
Antoine Tenart6eb5d372017-10-30 11:23:33 +01006489 mvpp2_txdesc_dma_addr_set(port, tx_desc, addr);
Antoine Ténart186cd4d2017-08-23 09:46:56 +02006490
6491 mvpp2_txdesc_cmd_set(port, tx_desc, mvpp2_skb_tx_csum(port, skb) |
6492 MVPP2_TXD_F_DESC |
6493 MVPP2_TXD_PADDING_DISABLE);
6494 mvpp2_txq_inc_put(port, txq_pcpu, NULL, tx_desc);
6495}
6496
6497static inline int mvpp2_tso_put_data(struct sk_buff *skb,
6498 struct net_device *dev, struct tso_t *tso,
6499 struct mvpp2_tx_queue *txq,
6500 struct mvpp2_tx_queue *aggr_txq,
6501 struct mvpp2_txq_pcpu *txq_pcpu,
6502 int sz, bool left, bool last)
6503{
6504 struct mvpp2_port *port = netdev_priv(dev);
6505 struct mvpp2_tx_desc *tx_desc = mvpp2_txq_next_desc_get(aggr_txq);
6506 dma_addr_t buf_dma_addr;
6507
6508 mvpp2_txdesc_txq_set(port, tx_desc, txq->id);
6509 mvpp2_txdesc_size_set(port, tx_desc, sz);
6510
6511 buf_dma_addr = dma_map_single(dev->dev.parent, tso->data, sz,
6512 DMA_TO_DEVICE);
6513 if (unlikely(dma_mapping_error(dev->dev.parent, buf_dma_addr))) {
6514 mvpp2_txq_desc_put(txq);
6515 return -ENOMEM;
6516 }
6517
Antoine Tenart6eb5d372017-10-30 11:23:33 +01006518 mvpp2_txdesc_dma_addr_set(port, tx_desc, buf_dma_addr);
Antoine Ténart186cd4d2017-08-23 09:46:56 +02006519
6520 if (!left) {
6521 mvpp2_txdesc_cmd_set(port, tx_desc, MVPP2_TXD_L_DESC);
6522 if (last) {
6523 mvpp2_txq_inc_put(port, txq_pcpu, skb, tx_desc);
6524 return 0;
6525 }
6526 } else {
6527 mvpp2_txdesc_cmd_set(port, tx_desc, 0);
6528 }
6529
6530 mvpp2_txq_inc_put(port, txq_pcpu, NULL, tx_desc);
6531 return 0;
6532}
6533
6534static int mvpp2_tx_tso(struct sk_buff *skb, struct net_device *dev,
6535 struct mvpp2_tx_queue *txq,
6536 struct mvpp2_tx_queue *aggr_txq,
6537 struct mvpp2_txq_pcpu *txq_pcpu)
6538{
6539 struct mvpp2_port *port = netdev_priv(dev);
6540 struct tso_t tso;
6541 int hdr_sz = skb_transport_offset(skb) + tcp_hdrlen(skb);
6542 int i, len, descs = 0;
6543
6544 /* Check number of available descriptors */
6545 if (mvpp2_aggr_desc_num_check(port->priv, aggr_txq,
6546 tso_count_descs(skb)) ||
6547 mvpp2_txq_reserved_desc_num_proc(port->priv, txq, txq_pcpu,
6548 tso_count_descs(skb)))
6549 return 0;
6550
6551 tso_start(skb, &tso);
6552 len = skb->len - hdr_sz;
6553 while (len > 0) {
6554 int left = min_t(int, skb_shinfo(skb)->gso_size, len);
6555 char *hdr = txq_pcpu->tso_headers +
6556 txq_pcpu->txq_put_index * TSO_HEADER_SIZE;
6557
6558 len -= left;
6559 descs++;
6560
6561 tso_build_hdr(skb, hdr, &tso, left, len == 0);
6562 mvpp2_tso_put_hdr(skb, dev, txq, aggr_txq, txq_pcpu, hdr_sz);
6563
6564 while (left > 0) {
6565 int sz = min_t(int, tso.size, left);
6566 left -= sz;
6567 descs++;
6568
6569 if (mvpp2_tso_put_data(skb, dev, &tso, txq, aggr_txq,
6570 txq_pcpu, sz, left, len == 0))
6571 goto release;
6572 tso_build_data(skb, &tso, sz);
6573 }
6574 }
6575
6576 return descs;
6577
6578release:
6579 for (i = descs - 1; i >= 0; i--) {
6580 struct mvpp2_tx_desc *tx_desc = txq->descs + i;
6581 tx_desc_unmap_put(port, txq, tx_desc);
6582 }
6583 return 0;
6584}
6585
Marcin Wojtas3f518502014-07-10 16:52:13 -03006586/* Main tx processing */
6587static int mvpp2_tx(struct sk_buff *skb, struct net_device *dev)
6588{
6589 struct mvpp2_port *port = netdev_priv(dev);
6590 struct mvpp2_tx_queue *txq, *aggr_txq;
6591 struct mvpp2_txq_pcpu *txq_pcpu;
6592 struct mvpp2_tx_desc *tx_desc;
Thomas Petazzoni20396132017-03-07 16:53:00 +01006593 dma_addr_t buf_dma_addr;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006594 int frags = 0;
6595 u16 txq_id;
6596 u32 tx_cmd;
6597
6598 txq_id = skb_get_queue_mapping(skb);
6599 txq = port->txqs[txq_id];
6600 txq_pcpu = this_cpu_ptr(txq->pcpu);
6601 aggr_txq = &port->priv->aggr_txqs[smp_processor_id()];
6602
Antoine Ténart186cd4d2017-08-23 09:46:56 +02006603 if (skb_is_gso(skb)) {
6604 frags = mvpp2_tx_tso(skb, dev, txq, aggr_txq, txq_pcpu);
6605 goto out;
6606 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03006607 frags = skb_shinfo(skb)->nr_frags + 1;
6608
6609 /* Check number of available descriptors */
6610 if (mvpp2_aggr_desc_num_check(port->priv, aggr_txq, frags) ||
6611 mvpp2_txq_reserved_desc_num_proc(port->priv, txq,
6612 txq_pcpu, frags)) {
6613 frags = 0;
6614 goto out;
6615 }
6616
6617 /* Get a descriptor for the first part of the packet */
6618 tx_desc = mvpp2_txq_next_desc_get(aggr_txq);
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006619 mvpp2_txdesc_txq_set(port, tx_desc, txq->id);
6620 mvpp2_txdesc_size_set(port, tx_desc, skb_headlen(skb));
Marcin Wojtas3f518502014-07-10 16:52:13 -03006621
Thomas Petazzoni20396132017-03-07 16:53:00 +01006622 buf_dma_addr = dma_map_single(dev->dev.parent, skb->data,
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006623 skb_headlen(skb), DMA_TO_DEVICE);
Thomas Petazzoni20396132017-03-07 16:53:00 +01006624 if (unlikely(dma_mapping_error(dev->dev.parent, buf_dma_addr))) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03006625 mvpp2_txq_desc_put(txq);
6626 frags = 0;
6627 goto out;
6628 }
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006629
Antoine Tenart6eb5d372017-10-30 11:23:33 +01006630 mvpp2_txdesc_dma_addr_set(port, tx_desc, buf_dma_addr);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006631
6632 tx_cmd = mvpp2_skb_tx_csum(port, skb);
6633
6634 if (frags == 1) {
6635 /* First and Last descriptor */
6636 tx_cmd |= MVPP2_TXD_F_DESC | MVPP2_TXD_L_DESC;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006637 mvpp2_txdesc_cmd_set(port, tx_desc, tx_cmd);
6638 mvpp2_txq_inc_put(port, txq_pcpu, skb, tx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006639 } else {
6640 /* First but not Last */
6641 tx_cmd |= MVPP2_TXD_F_DESC | MVPP2_TXD_PADDING_DISABLE;
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006642 mvpp2_txdesc_cmd_set(port, tx_desc, tx_cmd);
6643 mvpp2_txq_inc_put(port, txq_pcpu, NULL, tx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006644
6645 /* Continue with other skb fragments */
6646 if (mvpp2_tx_frag_process(port, skb, aggr_txq, txq)) {
Thomas Petazzoniac3dd2772017-03-07 16:53:05 +01006647 tx_desc_unmap_put(port, txq, tx_desc);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006648 frags = 0;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006649 }
6650 }
6651
Marcin Wojtas3f518502014-07-10 16:52:13 -03006652out:
6653 if (frags > 0) {
6654 struct mvpp2_pcpu_stats *stats = this_cpu_ptr(port->stats);
Antoine Ténart186cd4d2017-08-23 09:46:56 +02006655 struct netdev_queue *nq = netdev_get_tx_queue(dev, txq_id);
6656
6657 txq_pcpu->reserved_num -= frags;
6658 txq_pcpu->count += frags;
6659 aggr_txq->count += frags;
6660
6661 /* Enable transmit */
6662 wmb();
6663 mvpp2_aggr_txq_pend_desc_add(port, frags);
6664
Antoine Tenart1d17db02017-10-30 11:23:31 +01006665 if (txq_pcpu->count >= txq_pcpu->stop_threshold)
Antoine Ténart186cd4d2017-08-23 09:46:56 +02006666 netif_tx_stop_queue(nq);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006667
6668 u64_stats_update_begin(&stats->syncp);
6669 stats->tx_packets++;
6670 stats->tx_bytes += skb->len;
6671 u64_stats_update_end(&stats->syncp);
6672 } else {
6673 dev->stats.tx_dropped++;
6674 dev_kfree_skb_any(skb);
6675 }
6676
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006677 /* Finalize TX processing */
Antoine Tenart082297e2017-10-23 15:24:31 +02006678 if (!port->has_tx_irqs && txq_pcpu->count >= txq->done_pkts_coal)
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006679 mvpp2_txq_done(port, txq, txq_pcpu);
6680
6681 /* Set the timer in case not all frags were processed */
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006682 if (!port->has_tx_irqs && txq_pcpu->count <= frags &&
6683 txq_pcpu->count > 0) {
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006684 struct mvpp2_port_pcpu *port_pcpu = this_cpu_ptr(port->pcpu);
6685
6686 mvpp2_timer_set(port_pcpu);
6687 }
6688
Marcin Wojtas3f518502014-07-10 16:52:13 -03006689 return NETDEV_TX_OK;
6690}
6691
6692static inline void mvpp2_cause_error(struct net_device *dev, int cause)
6693{
6694 if (cause & MVPP2_CAUSE_FCS_ERR_MASK)
6695 netdev_err(dev, "FCS error\n");
6696 if (cause & MVPP2_CAUSE_RX_FIFO_OVERRUN_MASK)
6697 netdev_err(dev, "rx fifo overrun error\n");
6698 if (cause & MVPP2_CAUSE_TX_FIFO_UNDERRUN_MASK)
6699 netdev_err(dev, "tx fifo underrun error\n");
6700}
6701
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006702static int mvpp2_poll(struct napi_struct *napi, int budget)
Marcin Wojtas3f518502014-07-10 16:52:13 -03006703{
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006704 u32 cause_rx_tx, cause_rx, cause_tx, cause_misc;
Marcin Wojtasedc660f2015-08-06 19:00:30 +02006705 int rx_done = 0;
6706 struct mvpp2_port *port = netdev_priv(napi->dev);
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006707 struct mvpp2_queue_vector *qv;
Thomas Petazzonia7868412017-03-07 16:53:13 +01006708 int cpu = smp_processor_id();
Marcin Wojtas3f518502014-07-10 16:52:13 -03006709
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006710 qv = container_of(napi, struct mvpp2_queue_vector, napi);
6711
Marcin Wojtas3f518502014-07-10 16:52:13 -03006712 /* Rx/Tx cause register
6713 *
6714 * Bits 0-15: each bit indicates received packets on the Rx queue
6715 * (bit 0 is for Rx queue 0).
6716 *
6717 * Bits 16-23: each bit indicates transmitted packets on the Tx queue
6718 * (bit 16 is for Tx queue 0).
6719 *
6720 * Each CPU has its own Rx/Tx cause register
6721 */
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006722 cause_rx_tx = mvpp2_percpu_read(port->priv, qv->sw_thread_id,
Thomas Petazzonia7868412017-03-07 16:53:13 +01006723 MVPP2_ISR_RX_TX_CAUSE_REG(port->id));
Marcin Wojtas3f518502014-07-10 16:52:13 -03006724
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006725 cause_misc = cause_rx_tx & MVPP2_CAUSE_MISC_SUM_MASK;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006726 if (cause_misc) {
6727 mvpp2_cause_error(port->dev, cause_misc);
6728
6729 /* Clear the cause register */
6730 mvpp2_write(port->priv, MVPP2_ISR_MISC_CAUSE_REG, 0);
Thomas Petazzonia7868412017-03-07 16:53:13 +01006731 mvpp2_percpu_write(port->priv, cpu,
6732 MVPP2_ISR_RX_TX_CAUSE_REG(port->id),
6733 cause_rx_tx & ~MVPP2_CAUSE_MISC_SUM_MASK);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006734 }
6735
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006736 cause_tx = cause_rx_tx & MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK;
6737 if (cause_tx) {
6738 cause_tx >>= MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_OFFSET;
6739 mvpp2_tx_done(port, cause_tx, qv->sw_thread_id);
6740 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03006741
6742 /* Process RX packets */
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006743 cause_rx = cause_rx_tx & MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK;
6744 cause_rx <<= qv->first_rxq;
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006745 cause_rx |= qv->pending_cause_rx;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006746 while (cause_rx && budget > 0) {
6747 int count;
6748 struct mvpp2_rx_queue *rxq;
6749
6750 rxq = mvpp2_get_rx_queue(port, cause_rx);
6751 if (!rxq)
6752 break;
6753
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006754 count = mvpp2_rx(port, napi, budget, rxq);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006755 rx_done += count;
6756 budget -= count;
6757 if (budget > 0) {
6758 /* Clear the bit associated to this Rx queue
6759 * so that next iteration will continue from
6760 * the next Rx queue.
6761 */
6762 cause_rx &= ~(1 << rxq->logic_rxq);
6763 }
6764 }
6765
6766 if (budget > 0) {
6767 cause_rx = 0;
Eric Dumazet6ad20162017-01-30 08:22:01 -08006768 napi_complete_done(napi, rx_done);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006769
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006770 mvpp2_qvec_interrupt_enable(qv);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006771 }
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006772 qv->pending_cause_rx = cause_rx;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006773 return rx_done;
6774}
6775
6776/* Set hw internals when starting port */
6777static void mvpp2_start_dev(struct mvpp2_port *port)
6778{
Philippe Reynes8e072692016-06-28 00:08:11 +02006779 struct net_device *ndev = port->dev;
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006780 int i;
Philippe Reynes8e072692016-06-28 00:08:11 +02006781
Stefan Chulski76eb1b12017-08-22 19:08:26 +02006782 if (port->gop_id == 0 &&
6783 (port->phy_interface == PHY_INTERFACE_MODE_XAUI ||
6784 port->phy_interface == PHY_INTERFACE_MODE_10GKR))
6785 mvpp2_xlg_max_rx_size_set(port);
6786 else
6787 mvpp2_gmac_max_rx_size_set(port);
6788
Marcin Wojtas3f518502014-07-10 16:52:13 -03006789 mvpp2_txp_max_tx_size_set(port);
6790
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006791 for (i = 0; i < port->nqvecs; i++)
6792 napi_enable(&port->qvecs[i].napi);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006793
6794 /* Enable interrupts on all CPUs */
6795 mvpp2_interrupts_enable(port);
6796
Antoine Tenart542897d2017-08-30 10:29:15 +02006797 if (port->priv->hw_version == MVPP22) {
6798 mvpp22_comphy_init(port);
Antoine Ténartf84bf382017-08-22 19:08:27 +02006799 mvpp22_gop_init(port);
Antoine Tenart542897d2017-08-30 10:29:15 +02006800 }
Antoine Ténartf84bf382017-08-22 19:08:27 +02006801
Antoine Ténart2055d622017-08-22 19:08:23 +02006802 mvpp2_port_mii_set(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006803 mvpp2_port_enable(port);
Antoine Tenart5997c862017-09-01 11:04:53 +02006804 if (ndev->phydev)
6805 phy_start(ndev->phydev);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006806 netif_tx_start_all_queues(port->dev);
6807}
6808
6809/* Set hw internals when stopping port */
6810static void mvpp2_stop_dev(struct mvpp2_port *port)
6811{
Philippe Reynes8e072692016-06-28 00:08:11 +02006812 struct net_device *ndev = port->dev;
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006813 int i;
Philippe Reynes8e072692016-06-28 00:08:11 +02006814
Marcin Wojtas3f518502014-07-10 16:52:13 -03006815 /* Stop new packets from arriving to RXQs */
6816 mvpp2_ingress_disable(port);
6817
6818 mdelay(10);
6819
6820 /* Disable interrupts on all CPUs */
6821 mvpp2_interrupts_disable(port);
6822
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006823 for (i = 0; i < port->nqvecs; i++)
6824 napi_disable(&port->qvecs[i].napi);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006825
6826 netif_carrier_off(port->dev);
6827 netif_tx_stop_all_queues(port->dev);
6828
6829 mvpp2_egress_disable(port);
6830 mvpp2_port_disable(port);
Antoine Tenart5997c862017-09-01 11:04:53 +02006831 if (ndev->phydev)
6832 phy_stop(ndev->phydev);
Antoine Tenart542897d2017-08-30 10:29:15 +02006833 phy_power_off(port->comphy);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006834}
6835
Marcin Wojtas3f518502014-07-10 16:52:13 -03006836static int mvpp2_check_ringparam_valid(struct net_device *dev,
6837 struct ethtool_ringparam *ring)
6838{
6839 u16 new_rx_pending = ring->rx_pending;
6840 u16 new_tx_pending = ring->tx_pending;
6841
6842 if (ring->rx_pending == 0 || ring->tx_pending == 0)
6843 return -EINVAL;
6844
Yan Markman7cf87e42017-12-11 09:13:26 +01006845 if (ring->rx_pending > MVPP2_MAX_RXD_MAX)
6846 new_rx_pending = MVPP2_MAX_RXD_MAX;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006847 else if (!IS_ALIGNED(ring->rx_pending, 16))
6848 new_rx_pending = ALIGN(ring->rx_pending, 16);
6849
Yan Markman7cf87e42017-12-11 09:13:26 +01006850 if (ring->tx_pending > MVPP2_MAX_TXD_MAX)
6851 new_tx_pending = MVPP2_MAX_TXD_MAX;
Marcin Wojtas3f518502014-07-10 16:52:13 -03006852 else if (!IS_ALIGNED(ring->tx_pending, 32))
6853 new_tx_pending = ALIGN(ring->tx_pending, 32);
6854
Antoine Tenart76e583c2017-11-28 14:19:51 +01006855 /* The Tx ring size cannot be smaller than the minimum number of
6856 * descriptors needed for TSO.
6857 */
6858 if (new_tx_pending < MVPP2_MAX_SKB_DESCS)
6859 new_tx_pending = ALIGN(MVPP2_MAX_SKB_DESCS, 32);
6860
Marcin Wojtas3f518502014-07-10 16:52:13 -03006861 if (ring->rx_pending != new_rx_pending) {
6862 netdev_info(dev, "illegal Rx ring size value %d, round to %d\n",
6863 ring->rx_pending, new_rx_pending);
6864 ring->rx_pending = new_rx_pending;
6865 }
6866
6867 if (ring->tx_pending != new_tx_pending) {
6868 netdev_info(dev, "illegal Tx ring size value %d, round to %d\n",
6869 ring->tx_pending, new_tx_pending);
6870 ring->tx_pending = new_tx_pending;
6871 }
6872
6873 return 0;
6874}
6875
Thomas Petazzoni26975822017-03-07 16:53:14 +01006876static void mvpp21_get_mac_address(struct mvpp2_port *port, unsigned char *addr)
Marcin Wojtas3f518502014-07-10 16:52:13 -03006877{
6878 u32 mac_addr_l, mac_addr_m, mac_addr_h;
6879
6880 mac_addr_l = readl(port->base + MVPP2_GMAC_CTRL_1_REG);
6881 mac_addr_m = readl(port->priv->lms_base + MVPP2_SRC_ADDR_MIDDLE);
6882 mac_addr_h = readl(port->priv->lms_base + MVPP2_SRC_ADDR_HIGH);
6883 addr[0] = (mac_addr_h >> 24) & 0xFF;
6884 addr[1] = (mac_addr_h >> 16) & 0xFF;
6885 addr[2] = (mac_addr_h >> 8) & 0xFF;
6886 addr[3] = mac_addr_h & 0xFF;
6887 addr[4] = mac_addr_m & 0xFF;
6888 addr[5] = (mac_addr_l >> MVPP2_GMAC_SA_LOW_OFFS) & 0xFF;
6889}
6890
6891static int mvpp2_phy_connect(struct mvpp2_port *port)
6892{
6893 struct phy_device *phy_dev;
6894
Antoine Tenart5997c862017-09-01 11:04:53 +02006895 /* No PHY is attached */
6896 if (!port->phy_node)
6897 return 0;
6898
Marcin Wojtas3f518502014-07-10 16:52:13 -03006899 phy_dev = of_phy_connect(port->dev, port->phy_node, mvpp2_link_event, 0,
6900 port->phy_interface);
6901 if (!phy_dev) {
6902 netdev_err(port->dev, "cannot connect to phy\n");
6903 return -ENODEV;
6904 }
6905 phy_dev->supported &= PHY_GBIT_FEATURES;
6906 phy_dev->advertising = phy_dev->supported;
6907
Marcin Wojtas3f518502014-07-10 16:52:13 -03006908 port->link = 0;
6909 port->duplex = 0;
6910 port->speed = 0;
6911
6912 return 0;
6913}
6914
6915static void mvpp2_phy_disconnect(struct mvpp2_port *port)
6916{
Philippe Reynes8e072692016-06-28 00:08:11 +02006917 struct net_device *ndev = port->dev;
6918
Antoine Tenart5997c862017-09-01 11:04:53 +02006919 if (!ndev->phydev)
6920 return;
6921
Philippe Reynes8e072692016-06-28 00:08:11 +02006922 phy_disconnect(ndev->phydev);
Marcin Wojtas3f518502014-07-10 16:52:13 -03006923}
6924
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006925static int mvpp2_irqs_init(struct mvpp2_port *port)
6926{
6927 int err, i;
6928
6929 for (i = 0; i < port->nqvecs; i++) {
6930 struct mvpp2_queue_vector *qv = port->qvecs + i;
6931
Marc Zyngier13c249a2017-11-04 12:33:47 +00006932 if (qv->type == MVPP2_QUEUE_VECTOR_PRIVATE)
6933 irq_set_status_flags(qv->irq, IRQ_NO_BALANCING);
6934
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006935 err = request_irq(qv->irq, mvpp2_isr, 0, port->dev->name, qv);
6936 if (err)
6937 goto err;
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006938
6939 if (qv->type == MVPP2_QUEUE_VECTOR_PRIVATE)
6940 irq_set_affinity_hint(qv->irq,
6941 cpumask_of(qv->sw_thread_id));
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006942 }
6943
6944 return 0;
6945err:
6946 for (i = 0; i < port->nqvecs; i++) {
6947 struct mvpp2_queue_vector *qv = port->qvecs + i;
6948
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006949 irq_set_affinity_hint(qv->irq, NULL);
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006950 free_irq(qv->irq, qv);
6951 }
6952
6953 return err;
6954}
6955
6956static void mvpp2_irqs_deinit(struct mvpp2_port *port)
6957{
6958 int i;
6959
6960 for (i = 0; i < port->nqvecs; i++) {
6961 struct mvpp2_queue_vector *qv = port->qvecs + i;
6962
Thomas Petazzoni213f4282017-08-03 10:42:00 +02006963 irq_set_affinity_hint(qv->irq, NULL);
Marc Zyngier13c249a2017-11-04 12:33:47 +00006964 irq_clear_status_flags(qv->irq, IRQ_NO_BALANCING);
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02006965 free_irq(qv->irq, qv);
6966 }
6967}
6968
Antoine Tenart1d7d15d2017-10-30 11:23:30 +01006969static void mvpp22_init_rss(struct mvpp2_port *port)
6970{
6971 struct mvpp2 *priv = port->priv;
6972 int i;
6973
6974 /* Set the table width: replace the whole classifier Rx queue number
6975 * with the ones configured in RSS table entries.
6976 */
6977 mvpp2_write(priv, MVPP22_RSS_INDEX, MVPP22_RSS_INDEX_TABLE(0));
6978 mvpp2_write(priv, MVPP22_RSS_WIDTH, 8);
6979
6980 /* Loop through the classifier Rx Queues and map them to a RSS table.
6981 * Map them all to the first table (0) by default.
6982 */
6983 for (i = 0; i < MVPP2_CLS_RX_QUEUES; i++) {
6984 mvpp2_write(priv, MVPP22_RSS_INDEX, MVPP22_RSS_INDEX_QUEUE(i));
6985 mvpp2_write(priv, MVPP22_RSS_TABLE,
6986 MVPP22_RSS_TABLE_POINTER(0));
6987 }
6988
6989 /* Configure the first table to evenly distribute the packets across
6990 * real Rx Queues. The table entries map a hash to an port Rx Queue.
6991 */
6992 for (i = 0; i < MVPP22_RSS_TABLE_ENTRIES; i++) {
6993 u32 sel = MVPP22_RSS_INDEX_TABLE(0) |
6994 MVPP22_RSS_INDEX_TABLE_ENTRY(i);
6995 mvpp2_write(priv, MVPP22_RSS_INDEX, sel);
6996
6997 mvpp2_write(priv, MVPP22_RSS_TABLE_ENTRY, i % port->nrxqs);
6998 }
6999
7000}
7001
Marcin Wojtas3f518502014-07-10 16:52:13 -03007002static int mvpp2_open(struct net_device *dev)
7003{
7004 struct mvpp2_port *port = netdev_priv(dev);
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007005 struct mvpp2 *priv = port->priv;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007006 unsigned char mac_bcast[ETH_ALEN] = {
7007 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
7008 int err;
7009
7010 err = mvpp2_prs_mac_da_accept(port->priv, port->id, mac_bcast, true);
7011 if (err) {
7012 netdev_err(dev, "mvpp2_prs_mac_da_accept BC failed\n");
7013 return err;
7014 }
7015 err = mvpp2_prs_mac_da_accept(port->priv, port->id,
7016 dev->dev_addr, true);
7017 if (err) {
7018 netdev_err(dev, "mvpp2_prs_mac_da_accept MC failed\n");
7019 return err;
7020 }
7021 err = mvpp2_prs_tag_mode_set(port->priv, port->id, MVPP2_TAG_TYPE_MH);
7022 if (err) {
7023 netdev_err(dev, "mvpp2_prs_tag_mode_set failed\n");
7024 return err;
7025 }
7026 err = mvpp2_prs_def_flow(port);
7027 if (err) {
7028 netdev_err(dev, "mvpp2_prs_def_flow failed\n");
7029 return err;
7030 }
7031
7032 /* Allocate the Rx/Tx queues */
7033 err = mvpp2_setup_rxqs(port);
7034 if (err) {
7035 netdev_err(port->dev, "cannot allocate Rx queues\n");
7036 return err;
7037 }
7038
7039 err = mvpp2_setup_txqs(port);
7040 if (err) {
7041 netdev_err(port->dev, "cannot allocate Tx queues\n");
7042 goto err_cleanup_rxqs;
7043 }
7044
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007045 err = mvpp2_irqs_init(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007046 if (err) {
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007047 netdev_err(port->dev, "cannot init IRQs\n");
Marcin Wojtas3f518502014-07-10 16:52:13 -03007048 goto err_cleanup_txqs;
7049 }
7050
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007051 if (priv->hw_version == MVPP22 && !port->phy_node && port->link_irq) {
7052 err = request_irq(port->link_irq, mvpp2_link_status_isr, 0,
7053 dev->name, port);
7054 if (err) {
7055 netdev_err(port->dev, "cannot request link IRQ %d\n",
7056 port->link_irq);
7057 goto err_free_irq;
7058 }
7059
7060 mvpp22_gop_setup_irq(port);
7061 }
7062
Marcin Wojtas3f518502014-07-10 16:52:13 -03007063 /* In default link is down */
7064 netif_carrier_off(port->dev);
7065
7066 err = mvpp2_phy_connect(port);
7067 if (err < 0)
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007068 goto err_free_link_irq;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007069
7070 /* Unmask interrupts on all CPUs */
7071 on_each_cpu(mvpp2_interrupts_unmask, port, 1);
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007072 mvpp2_shared_interrupt_mask_unmask(port, false);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007073
7074 mvpp2_start_dev(port);
7075
Antoine Tenart1d7d15d2017-10-30 11:23:30 +01007076 if (priv->hw_version == MVPP22)
7077 mvpp22_init_rss(port);
7078
Miquel Raynal118d6292017-11-06 22:56:53 +01007079 /* Start hardware statistics gathering */
Miquel Raynale5c500e2017-11-08 08:59:40 +01007080 queue_delayed_work(priv->stats_queue, &port->stats_work,
Miquel Raynal118d6292017-11-06 22:56:53 +01007081 MVPP2_MIB_COUNTERS_STATS_DELAY);
7082
Marcin Wojtas3f518502014-07-10 16:52:13 -03007083 return 0;
7084
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007085err_free_link_irq:
7086 if (priv->hw_version == MVPP22 && !port->phy_node && port->link_irq)
7087 free_irq(port->link_irq, port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007088err_free_irq:
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007089 mvpp2_irqs_deinit(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007090err_cleanup_txqs:
7091 mvpp2_cleanup_txqs(port);
7092err_cleanup_rxqs:
7093 mvpp2_cleanup_rxqs(port);
7094 return err;
7095}
7096
7097static int mvpp2_stop(struct net_device *dev)
7098{
7099 struct mvpp2_port *port = netdev_priv(dev);
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007100 struct mvpp2_port_pcpu *port_pcpu;
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007101 struct mvpp2 *priv = port->priv;
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007102 int cpu;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007103
7104 mvpp2_stop_dev(port);
7105 mvpp2_phy_disconnect(port);
7106
7107 /* Mask interrupts on all CPUs */
7108 on_each_cpu(mvpp2_interrupts_mask, port, 1);
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007109 mvpp2_shared_interrupt_mask_unmask(port, true);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007110
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007111 if (priv->hw_version == MVPP22 && !port->phy_node && port->link_irq)
7112 free_irq(port->link_irq, port);
7113
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007114 mvpp2_irqs_deinit(port);
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007115 if (!port->has_tx_irqs) {
7116 for_each_present_cpu(cpu) {
7117 port_pcpu = per_cpu_ptr(port->pcpu, cpu);
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007118
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007119 hrtimer_cancel(&port_pcpu->tx_done_timer);
7120 port_pcpu->timer_scheduled = false;
7121 tasklet_kill(&port_pcpu->tx_done_tasklet);
7122 }
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007123 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03007124 mvpp2_cleanup_rxqs(port);
7125 mvpp2_cleanup_txqs(port);
7126
Miquel Raynale5c500e2017-11-08 08:59:40 +01007127 cancel_delayed_work_sync(&port->stats_work);
Miquel Raynal118d6292017-11-06 22:56:53 +01007128
Marcin Wojtas3f518502014-07-10 16:52:13 -03007129 return 0;
7130}
7131
7132static void mvpp2_set_rx_mode(struct net_device *dev)
7133{
7134 struct mvpp2_port *port = netdev_priv(dev);
7135 struct mvpp2 *priv = port->priv;
7136 struct netdev_hw_addr *ha;
7137 int id = port->id;
7138 bool allmulti = dev->flags & IFF_ALLMULTI;
7139
Mikulas Patocka7ac8ff92018-02-11 18:10:28 -05007140retry:
Marcin Wojtas3f518502014-07-10 16:52:13 -03007141 mvpp2_prs_mac_promisc_set(priv, id, dev->flags & IFF_PROMISC);
7142 mvpp2_prs_mac_multi_set(priv, id, MVPP2_PE_MAC_MC_ALL, allmulti);
7143 mvpp2_prs_mac_multi_set(priv, id, MVPP2_PE_MAC_MC_IP6, allmulti);
7144
7145 /* Remove all port->id's mcast enries */
7146 mvpp2_prs_mcast_del_all(priv, id);
7147
Mikulas Patocka7ac8ff92018-02-11 18:10:28 -05007148 if (!allmulti) {
7149 netdev_for_each_mc_addr(ha, dev) {
7150 if (mvpp2_prs_mac_da_accept(priv, id, ha->addr, true)) {
7151 allmulti = true;
7152 goto retry;
7153 }
7154 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03007155 }
7156}
7157
7158static int mvpp2_set_mac_address(struct net_device *dev, void *p)
7159{
7160 struct mvpp2_port *port = netdev_priv(dev);
7161 const struct sockaddr *addr = p;
7162 int err;
7163
7164 if (!is_valid_ether_addr(addr->sa_data)) {
7165 err = -EADDRNOTAVAIL;
Markus Elfringc1175542017-04-17 11:10:47 +02007166 goto log_error;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007167 }
7168
7169 if (!netif_running(dev)) {
7170 err = mvpp2_prs_update_mac_da(dev, addr->sa_data);
7171 if (!err)
7172 return 0;
7173 /* Reconfigure parser to accept the original MAC address */
7174 err = mvpp2_prs_update_mac_da(dev, dev->dev_addr);
7175 if (err)
Markus Elfringc1175542017-04-17 11:10:47 +02007176 goto log_error;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007177 }
7178
7179 mvpp2_stop_dev(port);
7180
7181 err = mvpp2_prs_update_mac_da(dev, addr->sa_data);
7182 if (!err)
7183 goto out_start;
7184
7185 /* Reconfigure parser accept the original MAC address */
7186 err = mvpp2_prs_update_mac_da(dev, dev->dev_addr);
7187 if (err)
Markus Elfringc1175542017-04-17 11:10:47 +02007188 goto log_error;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007189out_start:
7190 mvpp2_start_dev(port);
7191 mvpp2_egress_enable(port);
7192 mvpp2_ingress_enable(port);
7193 return 0;
Markus Elfringc1175542017-04-17 11:10:47 +02007194log_error:
Markus Elfringdfd42402017-04-17 11:20:41 +02007195 netdev_err(dev, "failed to change MAC address\n");
Marcin Wojtas3f518502014-07-10 16:52:13 -03007196 return err;
7197}
7198
7199static int mvpp2_change_mtu(struct net_device *dev, int mtu)
7200{
7201 struct mvpp2_port *port = netdev_priv(dev);
7202 int err;
7203
Jarod Wilson57779872016-10-17 15:54:06 -04007204 if (!IS_ALIGNED(MVPP2_RX_PKT_SIZE(mtu), 8)) {
7205 netdev_info(dev, "illegal MTU value %d, round to %d\n", mtu,
7206 ALIGN(MVPP2_RX_PKT_SIZE(mtu), 8));
7207 mtu = ALIGN(MVPP2_RX_PKT_SIZE(mtu), 8);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007208 }
7209
7210 if (!netif_running(dev)) {
7211 err = mvpp2_bm_update_mtu(dev, mtu);
7212 if (!err) {
7213 port->pkt_size = MVPP2_RX_PKT_SIZE(mtu);
7214 return 0;
7215 }
7216
7217 /* Reconfigure BM to the original MTU */
7218 err = mvpp2_bm_update_mtu(dev, dev->mtu);
7219 if (err)
Markus Elfringc1175542017-04-17 11:10:47 +02007220 goto log_error;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007221 }
7222
7223 mvpp2_stop_dev(port);
7224
7225 err = mvpp2_bm_update_mtu(dev, mtu);
7226 if (!err) {
7227 port->pkt_size = MVPP2_RX_PKT_SIZE(mtu);
7228 goto out_start;
7229 }
7230
7231 /* Reconfigure BM to the original MTU */
7232 err = mvpp2_bm_update_mtu(dev, dev->mtu);
7233 if (err)
Markus Elfringc1175542017-04-17 11:10:47 +02007234 goto log_error;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007235
7236out_start:
7237 mvpp2_start_dev(port);
7238 mvpp2_egress_enable(port);
7239 mvpp2_ingress_enable(port);
7240
7241 return 0;
Markus Elfringc1175542017-04-17 11:10:47 +02007242log_error:
Markus Elfringdfd42402017-04-17 11:20:41 +02007243 netdev_err(dev, "failed to change MTU\n");
Marcin Wojtas3f518502014-07-10 16:52:13 -03007244 return err;
7245}
7246
stephen hemmingerbc1f4472017-01-06 19:12:52 -08007247static void
Marcin Wojtas3f518502014-07-10 16:52:13 -03007248mvpp2_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
7249{
7250 struct mvpp2_port *port = netdev_priv(dev);
7251 unsigned int start;
7252 int cpu;
7253
7254 for_each_possible_cpu(cpu) {
7255 struct mvpp2_pcpu_stats *cpu_stats;
7256 u64 rx_packets;
7257 u64 rx_bytes;
7258 u64 tx_packets;
7259 u64 tx_bytes;
7260
7261 cpu_stats = per_cpu_ptr(port->stats, cpu);
7262 do {
7263 start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
7264 rx_packets = cpu_stats->rx_packets;
7265 rx_bytes = cpu_stats->rx_bytes;
7266 tx_packets = cpu_stats->tx_packets;
7267 tx_bytes = cpu_stats->tx_bytes;
7268 } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
7269
7270 stats->rx_packets += rx_packets;
7271 stats->rx_bytes += rx_bytes;
7272 stats->tx_packets += tx_packets;
7273 stats->tx_bytes += tx_bytes;
7274 }
7275
7276 stats->rx_errors = dev->stats.rx_errors;
7277 stats->rx_dropped = dev->stats.rx_dropped;
7278 stats->tx_dropped = dev->stats.tx_dropped;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007279}
7280
Thomas Petazzonibd695a52014-07-27 23:21:36 +02007281static int mvpp2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
7282{
Thomas Petazzonibd695a52014-07-27 23:21:36 +02007283 int ret;
7284
Philippe Reynes8e072692016-06-28 00:08:11 +02007285 if (!dev->phydev)
Thomas Petazzonibd695a52014-07-27 23:21:36 +02007286 return -ENOTSUPP;
7287
Philippe Reynes8e072692016-06-28 00:08:11 +02007288 ret = phy_mii_ioctl(dev->phydev, ifr, cmd);
Thomas Petazzonibd695a52014-07-27 23:21:36 +02007289 if (!ret)
7290 mvpp2_link_event(dev);
7291
7292 return ret;
7293}
7294
Marcin Wojtas3f518502014-07-10 16:52:13 -03007295/* Ethtool methods */
7296
Marcin Wojtas3f518502014-07-10 16:52:13 -03007297/* Set interrupt coalescing for ethtools */
7298static int mvpp2_ethtool_set_coalesce(struct net_device *dev,
7299 struct ethtool_coalesce *c)
7300{
7301 struct mvpp2_port *port = netdev_priv(dev);
7302 int queue;
7303
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007304 for (queue = 0; queue < port->nrxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03007305 struct mvpp2_rx_queue *rxq = port->rxqs[queue];
7306
7307 rxq->time_coal = c->rx_coalesce_usecs;
7308 rxq->pkts_coal = c->rx_max_coalesced_frames;
Thomas Petazzonid63f9e42017-02-21 11:28:02 +01007309 mvpp2_rx_pkts_coal_set(port, rxq);
7310 mvpp2_rx_time_coal_set(port, rxq);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007311 }
7312
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007313 if (port->has_tx_irqs) {
7314 port->tx_time_coal = c->tx_coalesce_usecs;
7315 mvpp2_tx_time_coal_set(port);
7316 }
7317
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007318 for (queue = 0; queue < port->ntxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03007319 struct mvpp2_tx_queue *txq = port->txqs[queue];
7320
7321 txq->done_pkts_coal = c->tx_max_coalesced_frames;
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007322
7323 if (port->has_tx_irqs)
7324 mvpp2_tx_pkts_coal_set(port, txq);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007325 }
7326
Marcin Wojtas3f518502014-07-10 16:52:13 -03007327 return 0;
7328}
7329
7330/* get coalescing for ethtools */
7331static int mvpp2_ethtool_get_coalesce(struct net_device *dev,
7332 struct ethtool_coalesce *c)
7333{
7334 struct mvpp2_port *port = netdev_priv(dev);
7335
Antoine Tenart385c2842017-12-11 09:13:27 +01007336 c->rx_coalesce_usecs = port->rxqs[0]->time_coal;
7337 c->rx_max_coalesced_frames = port->rxqs[0]->pkts_coal;
7338 c->tx_max_coalesced_frames = port->txqs[0]->done_pkts_coal;
Antoine Tenart24b28cc2017-12-11 09:13:28 +01007339 c->tx_coalesce_usecs = port->tx_time_coal;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007340 return 0;
7341}
7342
7343static void mvpp2_ethtool_get_drvinfo(struct net_device *dev,
7344 struct ethtool_drvinfo *drvinfo)
7345{
7346 strlcpy(drvinfo->driver, MVPP2_DRIVER_NAME,
7347 sizeof(drvinfo->driver));
7348 strlcpy(drvinfo->version, MVPP2_DRIVER_VERSION,
7349 sizeof(drvinfo->version));
7350 strlcpy(drvinfo->bus_info, dev_name(&dev->dev),
7351 sizeof(drvinfo->bus_info));
7352}
7353
7354static void mvpp2_ethtool_get_ringparam(struct net_device *dev,
7355 struct ethtool_ringparam *ring)
7356{
7357 struct mvpp2_port *port = netdev_priv(dev);
7358
Yan Markman7cf87e42017-12-11 09:13:26 +01007359 ring->rx_max_pending = MVPP2_MAX_RXD_MAX;
7360 ring->tx_max_pending = MVPP2_MAX_TXD_MAX;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007361 ring->rx_pending = port->rx_ring_size;
7362 ring->tx_pending = port->tx_ring_size;
7363}
7364
7365static int mvpp2_ethtool_set_ringparam(struct net_device *dev,
7366 struct ethtool_ringparam *ring)
7367{
7368 struct mvpp2_port *port = netdev_priv(dev);
7369 u16 prev_rx_ring_size = port->rx_ring_size;
7370 u16 prev_tx_ring_size = port->tx_ring_size;
7371 int err;
7372
7373 err = mvpp2_check_ringparam_valid(dev, ring);
7374 if (err)
7375 return err;
7376
7377 if (!netif_running(dev)) {
7378 port->rx_ring_size = ring->rx_pending;
7379 port->tx_ring_size = ring->tx_pending;
7380 return 0;
7381 }
7382
7383 /* The interface is running, so we have to force a
7384 * reallocation of the queues
7385 */
7386 mvpp2_stop_dev(port);
7387 mvpp2_cleanup_rxqs(port);
7388 mvpp2_cleanup_txqs(port);
7389
7390 port->rx_ring_size = ring->rx_pending;
7391 port->tx_ring_size = ring->tx_pending;
7392
7393 err = mvpp2_setup_rxqs(port);
7394 if (err) {
7395 /* Reallocate Rx queues with the original ring size */
7396 port->rx_ring_size = prev_rx_ring_size;
7397 ring->rx_pending = prev_rx_ring_size;
7398 err = mvpp2_setup_rxqs(port);
7399 if (err)
7400 goto err_out;
7401 }
7402 err = mvpp2_setup_txqs(port);
7403 if (err) {
7404 /* Reallocate Tx queues with the original ring size */
7405 port->tx_ring_size = prev_tx_ring_size;
7406 ring->tx_pending = prev_tx_ring_size;
7407 err = mvpp2_setup_txqs(port);
7408 if (err)
7409 goto err_clean_rxqs;
7410 }
7411
7412 mvpp2_start_dev(port);
7413 mvpp2_egress_enable(port);
7414 mvpp2_ingress_enable(port);
7415
7416 return 0;
7417
7418err_clean_rxqs:
7419 mvpp2_cleanup_rxqs(port);
7420err_out:
Markus Elfringdfd42402017-04-17 11:20:41 +02007421 netdev_err(dev, "failed to change ring parameters");
Marcin Wojtas3f518502014-07-10 16:52:13 -03007422 return err;
7423}
7424
7425/* Device ops */
7426
7427static const struct net_device_ops mvpp2_netdev_ops = {
7428 .ndo_open = mvpp2_open,
7429 .ndo_stop = mvpp2_stop,
7430 .ndo_start_xmit = mvpp2_tx,
7431 .ndo_set_rx_mode = mvpp2_set_rx_mode,
7432 .ndo_set_mac_address = mvpp2_set_mac_address,
7433 .ndo_change_mtu = mvpp2_change_mtu,
7434 .ndo_get_stats64 = mvpp2_get_stats64,
Thomas Petazzonibd695a52014-07-27 23:21:36 +02007435 .ndo_do_ioctl = mvpp2_ioctl,
Marcin Wojtas3f518502014-07-10 16:52:13 -03007436};
7437
7438static const struct ethtool_ops mvpp2_eth_tool_ops = {
Florian Fainelli00606c42016-11-15 11:19:48 -08007439 .nway_reset = phy_ethtool_nway_reset,
Marcin Wojtas3f518502014-07-10 16:52:13 -03007440 .get_link = ethtool_op_get_link,
Marcin Wojtas3f518502014-07-10 16:52:13 -03007441 .set_coalesce = mvpp2_ethtool_set_coalesce,
7442 .get_coalesce = mvpp2_ethtool_get_coalesce,
7443 .get_drvinfo = mvpp2_ethtool_get_drvinfo,
7444 .get_ringparam = mvpp2_ethtool_get_ringparam,
7445 .set_ringparam = mvpp2_ethtool_set_ringparam,
Miquel Raynal118d6292017-11-06 22:56:53 +01007446 .get_strings = mvpp2_ethtool_get_strings,
7447 .get_ethtool_stats = mvpp2_ethtool_get_stats,
7448 .get_sset_count = mvpp2_ethtool_get_sset_count,
Philippe Reynesfb773e92016-06-28 00:08:12 +02007449 .get_link_ksettings = phy_ethtool_get_link_ksettings,
7450 .set_link_ksettings = phy_ethtool_set_link_ksettings,
Marcin Wojtas3f518502014-07-10 16:52:13 -03007451};
7452
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007453/* Used for PPv2.1, or PPv2.2 with the old Device Tree binding that
7454 * had a single IRQ defined per-port.
7455 */
7456static int mvpp2_simple_queue_vectors_init(struct mvpp2_port *port,
7457 struct device_node *port_node)
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007458{
7459 struct mvpp2_queue_vector *v = &port->qvecs[0];
7460
7461 v->first_rxq = 0;
7462 v->nrxqs = port->nrxqs;
7463 v->type = MVPP2_QUEUE_VECTOR_SHARED;
7464 v->sw_thread_id = 0;
7465 v->sw_thread_mask = *cpumask_bits(cpu_online_mask);
7466 v->port = port;
7467 v->irq = irq_of_parse_and_map(port_node, 0);
7468 if (v->irq <= 0)
7469 return -EINVAL;
7470 netif_napi_add(port->dev, &v->napi, mvpp2_poll,
7471 NAPI_POLL_WEIGHT);
7472
7473 port->nqvecs = 1;
7474
7475 return 0;
7476}
7477
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007478static int mvpp2_multi_queue_vectors_init(struct mvpp2_port *port,
7479 struct device_node *port_node)
7480{
7481 struct mvpp2_queue_vector *v;
7482 int i, ret;
7483
7484 port->nqvecs = num_possible_cpus();
7485 if (queue_mode == MVPP2_QDIST_SINGLE_MODE)
7486 port->nqvecs += 1;
7487
7488 for (i = 0; i < port->nqvecs; i++) {
7489 char irqname[16];
7490
7491 v = port->qvecs + i;
7492
7493 v->port = port;
7494 v->type = MVPP2_QUEUE_VECTOR_PRIVATE;
7495 v->sw_thread_id = i;
7496 v->sw_thread_mask = BIT(i);
7497
7498 snprintf(irqname, sizeof(irqname), "tx-cpu%d", i);
7499
7500 if (queue_mode == MVPP2_QDIST_MULTI_MODE) {
7501 v->first_rxq = i * MVPP2_DEFAULT_RXQ;
7502 v->nrxqs = MVPP2_DEFAULT_RXQ;
7503 } else if (queue_mode == MVPP2_QDIST_SINGLE_MODE &&
7504 i == (port->nqvecs - 1)) {
7505 v->first_rxq = 0;
7506 v->nrxqs = port->nrxqs;
7507 v->type = MVPP2_QUEUE_VECTOR_SHARED;
7508 strncpy(irqname, "rx-shared", sizeof(irqname));
7509 }
7510
Marcin Wojtasa75edc72018-01-18 13:31:44 +01007511 if (port_node)
7512 v->irq = of_irq_get_byname(port_node, irqname);
7513 else
7514 v->irq = fwnode_irq_get(port->fwnode, i);
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007515 if (v->irq <= 0) {
7516 ret = -EINVAL;
7517 goto err;
7518 }
7519
7520 netif_napi_add(port->dev, &v->napi, mvpp2_poll,
7521 NAPI_POLL_WEIGHT);
7522 }
7523
7524 return 0;
7525
7526err:
7527 for (i = 0; i < port->nqvecs; i++)
7528 irq_dispose_mapping(port->qvecs[i].irq);
7529 return ret;
7530}
7531
7532static int mvpp2_queue_vectors_init(struct mvpp2_port *port,
7533 struct device_node *port_node)
7534{
7535 if (port->has_tx_irqs)
7536 return mvpp2_multi_queue_vectors_init(port, port_node);
7537 else
7538 return mvpp2_simple_queue_vectors_init(port, port_node);
7539}
7540
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007541static void mvpp2_queue_vectors_deinit(struct mvpp2_port *port)
7542{
7543 int i;
7544
7545 for (i = 0; i < port->nqvecs; i++)
7546 irq_dispose_mapping(port->qvecs[i].irq);
7547}
7548
7549/* Configure Rx queue group interrupt for this port */
7550static void mvpp2_rx_irqs_setup(struct mvpp2_port *port)
7551{
7552 struct mvpp2 *priv = port->priv;
7553 u32 val;
7554 int i;
7555
7556 if (priv->hw_version == MVPP21) {
7557 mvpp2_write(priv, MVPP21_ISR_RXQ_GROUP_REG(port->id),
7558 port->nrxqs);
7559 return;
7560 }
7561
7562 /* Handle the more complicated PPv2.2 case */
7563 for (i = 0; i < port->nqvecs; i++) {
7564 struct mvpp2_queue_vector *qv = port->qvecs + i;
7565
7566 if (!qv->nrxqs)
7567 continue;
7568
7569 val = qv->sw_thread_id;
7570 val |= port->id << MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_OFFSET;
7571 mvpp2_write(priv, MVPP22_ISR_RXQ_GROUP_INDEX_REG, val);
7572
7573 val = qv->first_rxq;
7574 val |= qv->nrxqs << MVPP22_ISR_RXQ_SUB_GROUP_SIZE_OFFSET;
7575 mvpp2_write(priv, MVPP22_ISR_RXQ_SUB_GROUP_CONFIG_REG, val);
7576 }
7577}
7578
Marcin Wojtas3f518502014-07-10 16:52:13 -03007579/* Initialize port HW */
7580static int mvpp2_port_init(struct mvpp2_port *port)
7581{
7582 struct device *dev = port->dev->dev.parent;
7583 struct mvpp2 *priv = port->priv;
7584 struct mvpp2_txq_pcpu *txq_pcpu;
7585 int queue, cpu, err;
7586
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007587 /* Checks for hardware constraints */
7588 if (port->first_rxq + port->nrxqs >
Thomas Petazzoni59b9a312017-03-07 16:53:17 +01007589 MVPP2_MAX_PORTS * priv->max_port_rxqs)
Marcin Wojtas3f518502014-07-10 16:52:13 -03007590 return -EINVAL;
7591
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007592 if (port->nrxqs % 4 || (port->nrxqs > priv->max_port_rxqs) ||
7593 (port->ntxqs > MVPP2_MAX_TXQ))
7594 return -EINVAL;
7595
Marcin Wojtas3f518502014-07-10 16:52:13 -03007596 /* Disable port */
7597 mvpp2_egress_disable(port);
7598 mvpp2_port_disable(port);
7599
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007600 port->tx_time_coal = MVPP2_TXDONE_COAL_USEC;
7601
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007602 port->txqs = devm_kcalloc(dev, port->ntxqs, sizeof(*port->txqs),
Marcin Wojtas3f518502014-07-10 16:52:13 -03007603 GFP_KERNEL);
7604 if (!port->txqs)
7605 return -ENOMEM;
7606
7607 /* Associate physical Tx queues to this port and initialize.
7608 * The mapping is predefined.
7609 */
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007610 for (queue = 0; queue < port->ntxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03007611 int queue_phy_id = mvpp2_txq_phys(port->id, queue);
7612 struct mvpp2_tx_queue *txq;
7613
7614 txq = devm_kzalloc(dev, sizeof(*txq), GFP_KERNEL);
Christophe Jaillet177c8d12017-02-19 10:19:57 +01007615 if (!txq) {
7616 err = -ENOMEM;
7617 goto err_free_percpu;
7618 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03007619
7620 txq->pcpu = alloc_percpu(struct mvpp2_txq_pcpu);
7621 if (!txq->pcpu) {
7622 err = -ENOMEM;
7623 goto err_free_percpu;
7624 }
7625
7626 txq->id = queue_phy_id;
7627 txq->log_id = queue;
7628 txq->done_pkts_coal = MVPP2_TXDONE_COAL_PKTS_THRESH;
7629 for_each_present_cpu(cpu) {
7630 txq_pcpu = per_cpu_ptr(txq->pcpu, cpu);
7631 txq_pcpu->cpu = cpu;
7632 }
7633
7634 port->txqs[queue] = txq;
7635 }
7636
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007637 port->rxqs = devm_kcalloc(dev, port->nrxqs, sizeof(*port->rxqs),
Marcin Wojtas3f518502014-07-10 16:52:13 -03007638 GFP_KERNEL);
7639 if (!port->rxqs) {
7640 err = -ENOMEM;
7641 goto err_free_percpu;
7642 }
7643
7644 /* Allocate and initialize Rx queue for this port */
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007645 for (queue = 0; queue < port->nrxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03007646 struct mvpp2_rx_queue *rxq;
7647
7648 /* Map physical Rx queue to port's logical Rx queue */
7649 rxq = devm_kzalloc(dev, sizeof(*rxq), GFP_KERNEL);
Jisheng Zhangd82b0c22016-03-31 17:01:23 +08007650 if (!rxq) {
7651 err = -ENOMEM;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007652 goto err_free_percpu;
Jisheng Zhangd82b0c22016-03-31 17:01:23 +08007653 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03007654 /* Map this Rx queue to a physical queue */
7655 rxq->id = port->first_rxq + queue;
7656 rxq->port = port->id;
7657 rxq->logic_rxq = queue;
7658
7659 port->rxqs[queue] = rxq;
7660 }
7661
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007662 mvpp2_rx_irqs_setup(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007663
7664 /* Create Rx descriptor rings */
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007665 for (queue = 0; queue < port->nrxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03007666 struct mvpp2_rx_queue *rxq = port->rxqs[queue];
7667
7668 rxq->size = port->rx_ring_size;
7669 rxq->pkts_coal = MVPP2_RX_COAL_PKTS;
7670 rxq->time_coal = MVPP2_RX_COAL_USEC;
7671 }
7672
7673 mvpp2_ingress_disable(port);
7674
7675 /* Port default configuration */
7676 mvpp2_defaults_set(port);
7677
7678 /* Port's classifier configuration */
7679 mvpp2_cls_oversize_rxq_set(port);
7680 mvpp2_cls_port_config(port);
7681
7682 /* Provide an initial Rx packet size */
7683 port->pkt_size = MVPP2_RX_PKT_SIZE(port->dev->mtu);
7684
7685 /* Initialize pools for swf */
7686 err = mvpp2_swf_bm_pool_init(port);
7687 if (err)
7688 goto err_free_percpu;
7689
7690 return 0;
7691
7692err_free_percpu:
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007693 for (queue = 0; queue < port->ntxqs; queue++) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03007694 if (!port->txqs[queue])
7695 continue;
7696 free_percpu(port->txqs[queue]->pcpu);
7697 }
7698 return err;
7699}
7700
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007701/* Checks if the port DT description has the TX interrupts
7702 * described. On PPv2.1, there are no such interrupts. On PPv2.2,
7703 * there are available, but we need to keep support for old DTs.
7704 */
7705static bool mvpp2_port_has_tx_irqs(struct mvpp2 *priv,
7706 struct device_node *port_node)
7707{
7708 char *irqs[5] = { "rx-shared", "tx-cpu0", "tx-cpu1",
7709 "tx-cpu2", "tx-cpu3" };
7710 int ret, i;
7711
7712 if (priv->hw_version == MVPP21)
7713 return false;
7714
7715 for (i = 0; i < 5; i++) {
7716 ret = of_property_match_string(port_node, "interrupt-names",
7717 irqs[i]);
7718 if (ret < 0)
7719 return false;
7720 }
7721
7722 return true;
7723}
7724
Antoine Tenart3ba8c812017-09-02 11:06:47 +02007725static void mvpp2_port_copy_mac_addr(struct net_device *dev, struct mvpp2 *priv,
Marcin Wojtas24812222018-01-18 13:31:43 +01007726 struct fwnode_handle *fwnode,
Antoine Tenart3ba8c812017-09-02 11:06:47 +02007727 char **mac_from)
7728{
7729 struct mvpp2_port *port = netdev_priv(dev);
7730 char hw_mac_addr[ETH_ALEN] = {0};
Marcin Wojtas24812222018-01-18 13:31:43 +01007731 char fw_mac_addr[ETH_ALEN];
Antoine Tenart3ba8c812017-09-02 11:06:47 +02007732
Marcin Wojtas24812222018-01-18 13:31:43 +01007733 if (fwnode_get_mac_address(fwnode, fw_mac_addr, ETH_ALEN)) {
7734 *mac_from = "firmware node";
7735 ether_addr_copy(dev->dev_addr, fw_mac_addr);
Antoine Tenart688cbaf2017-09-02 11:06:49 +02007736 return;
Antoine Tenart3ba8c812017-09-02 11:06:47 +02007737 }
Antoine Tenart688cbaf2017-09-02 11:06:49 +02007738
7739 if (priv->hw_version == MVPP21) {
7740 mvpp21_get_mac_address(port, hw_mac_addr);
7741 if (is_valid_ether_addr(hw_mac_addr)) {
7742 *mac_from = "hardware";
7743 ether_addr_copy(dev->dev_addr, hw_mac_addr);
7744 return;
7745 }
7746 }
7747
7748 *mac_from = "random";
7749 eth_hw_addr_random(dev);
Antoine Tenart3ba8c812017-09-02 11:06:47 +02007750}
7751
Marcin Wojtas3f518502014-07-10 16:52:13 -03007752/* Ports initialization */
7753static int mvpp2_port_probe(struct platform_device *pdev,
Marcin Wojtas24812222018-01-18 13:31:43 +01007754 struct fwnode_handle *port_fwnode,
Marcin Wojtasbf147152018-01-18 13:31:42 +01007755 struct mvpp2 *priv)
Marcin Wojtas3f518502014-07-10 16:52:13 -03007756{
7757 struct device_node *phy_node;
Marcin Wojtasa75edc72018-01-18 13:31:44 +01007758 struct phy *comphy = NULL;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007759 struct mvpp2_port *port;
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007760 struct mvpp2_port_pcpu *port_pcpu;
Marcin Wojtas24812222018-01-18 13:31:43 +01007761 struct device_node *port_node = to_of_node(port_fwnode);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007762 struct net_device *dev;
7763 struct resource *res;
Antoine Tenart3ba8c812017-09-02 11:06:47 +02007764 char *mac_from = "";
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007765 unsigned int ntxqs, nrxqs;
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007766 bool has_tx_irqs;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007767 u32 id;
7768 int features;
7769 int phy_mode;
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007770 int err, i, cpu;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007771
Marcin Wojtasa75edc72018-01-18 13:31:44 +01007772 if (port_node) {
7773 has_tx_irqs = mvpp2_port_has_tx_irqs(priv, port_node);
7774 } else {
7775 has_tx_irqs = true;
7776 queue_mode = MVPP2_QDIST_MULTI_MODE;
7777 }
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007778
7779 if (!has_tx_irqs)
7780 queue_mode = MVPP2_QDIST_SINGLE_MODE;
7781
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007782 ntxqs = MVPP2_MAX_TXQ;
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007783 if (priv->hw_version == MVPP22 && queue_mode == MVPP2_QDIST_MULTI_MODE)
7784 nrxqs = MVPP2_DEFAULT_RXQ * num_possible_cpus();
7785 else
7786 nrxqs = MVPP2_DEFAULT_RXQ;
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007787
7788 dev = alloc_etherdev_mqs(sizeof(*port), ntxqs, nrxqs);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007789 if (!dev)
7790 return -ENOMEM;
7791
Marcin Wojtasa75edc72018-01-18 13:31:44 +01007792 if (port_node)
7793 phy_node = of_parse_phandle(port_node, "phy", 0);
7794 else
7795 phy_node = NULL;
7796
Marcin Wojtas24812222018-01-18 13:31:43 +01007797 phy_mode = fwnode_get_phy_mode(port_fwnode);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007798 if (phy_mode < 0) {
7799 dev_err(&pdev->dev, "incorrect phy mode\n");
7800 err = phy_mode;
7801 goto err_free_netdev;
7802 }
7803
Marcin Wojtasa75edc72018-01-18 13:31:44 +01007804 if (port_node) {
7805 comphy = devm_of_phy_get(&pdev->dev, port_node, NULL);
7806 if (IS_ERR(comphy)) {
7807 if (PTR_ERR(comphy) == -EPROBE_DEFER) {
7808 err = -EPROBE_DEFER;
7809 goto err_free_netdev;
7810 }
7811 comphy = NULL;
Antoine Tenart542897d2017-08-30 10:29:15 +02007812 }
Antoine Tenart542897d2017-08-30 10:29:15 +02007813 }
7814
Marcin Wojtas24812222018-01-18 13:31:43 +01007815 if (fwnode_property_read_u32(port_fwnode, "port-id", &id)) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03007816 err = -EINVAL;
7817 dev_err(&pdev->dev, "missing port-id value\n");
7818 goto err_free_netdev;
7819 }
7820
Yan Markman7cf87e42017-12-11 09:13:26 +01007821 dev->tx_queue_len = MVPP2_MAX_TXD_MAX;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007822 dev->watchdog_timeo = 5 * HZ;
7823 dev->netdev_ops = &mvpp2_netdev_ops;
7824 dev->ethtool_ops = &mvpp2_eth_tool_ops;
7825
7826 port = netdev_priv(dev);
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007827 port->dev = dev;
Marcin Wojtasa75edc72018-01-18 13:31:44 +01007828 port->fwnode = port_fwnode;
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007829 port->ntxqs = ntxqs;
7830 port->nrxqs = nrxqs;
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007831 port->priv = priv;
7832 port->has_tx_irqs = has_tx_irqs;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007833
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007834 err = mvpp2_queue_vectors_init(port, port_node);
7835 if (err)
Marcin Wojtas3f518502014-07-10 16:52:13 -03007836 goto err_free_netdev;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007837
Marcin Wojtasa75edc72018-01-18 13:31:44 +01007838 if (port_node)
7839 port->link_irq = of_irq_get_byname(port_node, "link");
7840 else
7841 port->link_irq = fwnode_irq_get(port_fwnode, port->nqvecs + 1);
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007842 if (port->link_irq == -EPROBE_DEFER) {
7843 err = -EPROBE_DEFER;
7844 goto err_deinit_qvecs;
7845 }
7846 if (port->link_irq <= 0)
7847 /* the link irq is optional */
7848 port->link_irq = 0;
7849
Marcin Wojtas24812222018-01-18 13:31:43 +01007850 if (fwnode_property_read_bool(port_fwnode, "marvell,loopback"))
Marcin Wojtas3f518502014-07-10 16:52:13 -03007851 port->flags |= MVPP2_F_LOOPBACK;
7852
Marcin Wojtas3f518502014-07-10 16:52:13 -03007853 port->id = id;
Thomas Petazzoni59b9a312017-03-07 16:53:17 +01007854 if (priv->hw_version == MVPP21)
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007855 port->first_rxq = port->id * port->nrxqs;
Thomas Petazzoni59b9a312017-03-07 16:53:17 +01007856 else
7857 port->first_rxq = port->id * priv->max_port_rxqs;
7858
Marcin Wojtas3f518502014-07-10 16:52:13 -03007859 port->phy_node = phy_node;
7860 port->phy_interface = phy_mode;
Antoine Tenart542897d2017-08-30 10:29:15 +02007861 port->comphy = comphy;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007862
Thomas Petazzonia7868412017-03-07 16:53:13 +01007863 if (priv->hw_version == MVPP21) {
7864 res = platform_get_resource(pdev, IORESOURCE_MEM, 2 + id);
7865 port->base = devm_ioremap_resource(&pdev->dev, res);
7866 if (IS_ERR(port->base)) {
7867 err = PTR_ERR(port->base);
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007868 goto err_free_irq;
Thomas Petazzonia7868412017-03-07 16:53:13 +01007869 }
Miquel Raynal118d6292017-11-06 22:56:53 +01007870
7871 port->stats_base = port->priv->lms_base +
7872 MVPP21_MIB_COUNTERS_OFFSET +
7873 port->gop_id * MVPP21_MIB_COUNTERS_PORT_SZ;
Thomas Petazzonia7868412017-03-07 16:53:13 +01007874 } else {
Marcin Wojtas24812222018-01-18 13:31:43 +01007875 if (fwnode_property_read_u32(port_fwnode, "gop-port-id",
7876 &port->gop_id)) {
Thomas Petazzonia7868412017-03-07 16:53:13 +01007877 err = -EINVAL;
7878 dev_err(&pdev->dev, "missing gop-port-id value\n");
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007879 goto err_deinit_qvecs;
Thomas Petazzonia7868412017-03-07 16:53:13 +01007880 }
7881
7882 port->base = priv->iface_base + MVPP22_GMAC_BASE(port->gop_id);
Miquel Raynal118d6292017-11-06 22:56:53 +01007883 port->stats_base = port->priv->iface_base +
7884 MVPP22_MIB_COUNTERS_OFFSET +
7885 port->gop_id * MVPP22_MIB_COUNTERS_PORT_SZ;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007886 }
7887
Miquel Raynal118d6292017-11-06 22:56:53 +01007888 /* Alloc per-cpu and ethtool stats */
Marcin Wojtas3f518502014-07-10 16:52:13 -03007889 port->stats = netdev_alloc_pcpu_stats(struct mvpp2_pcpu_stats);
7890 if (!port->stats) {
7891 err = -ENOMEM;
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007892 goto err_free_irq;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007893 }
7894
Miquel Raynal118d6292017-11-06 22:56:53 +01007895 port->ethtool_stats = devm_kcalloc(&pdev->dev,
7896 ARRAY_SIZE(mvpp2_ethtool_regs),
7897 sizeof(u64), GFP_KERNEL);
7898 if (!port->ethtool_stats) {
7899 err = -ENOMEM;
7900 goto err_free_stats;
7901 }
7902
Miquel Raynale5c500e2017-11-08 08:59:40 +01007903 mutex_init(&port->gather_stats_lock);
7904 INIT_DELAYED_WORK(&port->stats_work, mvpp2_gather_hw_statistics);
7905
Marcin Wojtas24812222018-01-18 13:31:43 +01007906 mvpp2_port_copy_mac_addr(dev, priv, port_fwnode, &mac_from);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007907
Yan Markman7cf87e42017-12-11 09:13:26 +01007908 port->tx_ring_size = MVPP2_MAX_TXD_DFLT;
7909 port->rx_ring_size = MVPP2_MAX_RXD_DFLT;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007910 SET_NETDEV_DEV(dev, &pdev->dev);
7911
7912 err = mvpp2_port_init(port);
7913 if (err < 0) {
7914 dev_err(&pdev->dev, "failed to init port %d\n", id);
7915 goto err_free_stats;
7916 }
Thomas Petazzoni26975822017-03-07 16:53:14 +01007917
Thomas Petazzoni26975822017-03-07 16:53:14 +01007918 mvpp2_port_periodic_xon_disable(port);
7919
7920 if (priv->hw_version == MVPP21)
7921 mvpp2_port_fc_adv_enable(port);
7922
7923 mvpp2_port_reset(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007924
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007925 port->pcpu = alloc_percpu(struct mvpp2_port_pcpu);
7926 if (!port->pcpu) {
7927 err = -ENOMEM;
7928 goto err_free_txq_pcpu;
7929 }
7930
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007931 if (!port->has_tx_irqs) {
7932 for_each_present_cpu(cpu) {
7933 port_pcpu = per_cpu_ptr(port->pcpu, cpu);
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007934
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007935 hrtimer_init(&port_pcpu->tx_done_timer, CLOCK_MONOTONIC,
7936 HRTIMER_MODE_REL_PINNED);
7937 port_pcpu->tx_done_timer.function = mvpp2_hr_timer_cb;
7938 port_pcpu->timer_scheduled = false;
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007939
Thomas Petazzoni213f4282017-08-03 10:42:00 +02007940 tasklet_init(&port_pcpu->tx_done_tasklet,
7941 mvpp2_tx_proc_cb,
7942 (unsigned long)dev);
7943 }
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007944 }
7945
Antoine Ténart186cd4d2017-08-23 09:46:56 +02007946 features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007947 dev->features = features | NETIF_F_RXCSUM;
7948 dev->hw_features |= features | NETIF_F_RXCSUM | NETIF_F_GRO;
7949 dev->vlan_features |= features;
Antoine Tenart1d17db02017-10-30 11:23:31 +01007950 dev->gso_max_segs = MVPP2_MAX_TSO_SEGS;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007951
Jarod Wilson57779872016-10-17 15:54:06 -04007952 /* MTU range: 68 - 9676 */
7953 dev->min_mtu = ETH_MIN_MTU;
7954 /* 9676 == 9700 - 20 and rounding to 8 */
7955 dev->max_mtu = 9676;
7956
Marcin Wojtas3f518502014-07-10 16:52:13 -03007957 err = register_netdev(dev);
7958 if (err < 0) {
7959 dev_err(&pdev->dev, "failed to register netdev\n");
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007960 goto err_free_port_pcpu;
Marcin Wojtas3f518502014-07-10 16:52:13 -03007961 }
7962 netdev_info(dev, "Using %s mac address %pM\n", mac_from, dev->dev_addr);
7963
Marcin Wojtasbf147152018-01-18 13:31:42 +01007964 priv->port_list[priv->port_count++] = port;
7965
Marcin Wojtas3f518502014-07-10 16:52:13 -03007966 return 0;
7967
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007968err_free_port_pcpu:
7969 free_percpu(port->pcpu);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007970err_free_txq_pcpu:
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007971 for (i = 0; i < port->ntxqs; i++)
Marcin Wojtas3f518502014-07-10 16:52:13 -03007972 free_percpu(port->txqs[i]->pcpu);
7973err_free_stats:
7974 free_percpu(port->stats);
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007975err_free_irq:
7976 if (port->link_irq)
7977 irq_dispose_mapping(port->link_irq);
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007978err_deinit_qvecs:
7979 mvpp2_queue_vectors_deinit(port);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007980err_free_netdev:
Peter Chenccb80392016-08-01 15:02:37 +08007981 of_node_put(phy_node);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007982 free_netdev(dev);
7983 return err;
7984}
7985
7986/* Ports removal routine */
7987static void mvpp2_port_remove(struct mvpp2_port *port)
7988{
7989 int i;
7990
7991 unregister_netdev(port->dev);
Peter Chenccb80392016-08-01 15:02:37 +08007992 of_node_put(port->phy_node);
Marcin Wojtasedc660f2015-08-06 19:00:30 +02007993 free_percpu(port->pcpu);
Marcin Wojtas3f518502014-07-10 16:52:13 -03007994 free_percpu(port->stats);
Thomas Petazzoni09f83972017-08-03 10:41:57 +02007995 for (i = 0; i < port->ntxqs; i++)
Marcin Wojtas3f518502014-07-10 16:52:13 -03007996 free_percpu(port->txqs[i]->pcpu);
Thomas Petazzoni591f4cf2017-08-03 10:41:59 +02007997 mvpp2_queue_vectors_deinit(port);
Antoine Tenartfd3651b2017-09-01 11:04:54 +02007998 if (port->link_irq)
7999 irq_dispose_mapping(port->link_irq);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008000 free_netdev(port->dev);
8001}
8002
8003/* Initialize decoding windows */
8004static void mvpp2_conf_mbus_windows(const struct mbus_dram_target_info *dram,
8005 struct mvpp2 *priv)
8006{
8007 u32 win_enable;
8008 int i;
8009
8010 for (i = 0; i < 6; i++) {
8011 mvpp2_write(priv, MVPP2_WIN_BASE(i), 0);
8012 mvpp2_write(priv, MVPP2_WIN_SIZE(i), 0);
8013
8014 if (i < 4)
8015 mvpp2_write(priv, MVPP2_WIN_REMAP(i), 0);
8016 }
8017
8018 win_enable = 0;
8019
8020 for (i = 0; i < dram->num_cs; i++) {
8021 const struct mbus_dram_window *cs = dram->cs + i;
8022
8023 mvpp2_write(priv, MVPP2_WIN_BASE(i),
8024 (cs->base & 0xffff0000) | (cs->mbus_attr << 8) |
8025 dram->mbus_dram_target_id);
8026
8027 mvpp2_write(priv, MVPP2_WIN_SIZE(i),
8028 (cs->size - 1) & 0xffff0000);
8029
8030 win_enable |= (1 << i);
8031 }
8032
8033 mvpp2_write(priv, MVPP2_BASE_ADDR_ENABLE, win_enable);
8034}
8035
8036/* Initialize Rx FIFO's */
8037static void mvpp2_rx_fifo_init(struct mvpp2 *priv)
8038{
8039 int port;
8040
8041 for (port = 0; port < MVPP2_MAX_PORTS; port++) {
8042 mvpp2_write(priv, MVPP2_RX_DATA_FIFO_SIZE_REG(port),
Antoine Tenart2d1d7df2017-10-30 11:23:28 +01008043 MVPP2_RX_FIFO_PORT_DATA_SIZE_4KB);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008044 mvpp2_write(priv, MVPP2_RX_ATTR_FIFO_SIZE_REG(port),
Antoine Tenart2d1d7df2017-10-30 11:23:28 +01008045 MVPP2_RX_FIFO_PORT_ATTR_SIZE_4KB);
8046 }
8047
8048 mvpp2_write(priv, MVPP2_RX_MIN_PKT_SIZE_REG,
8049 MVPP2_RX_FIFO_PORT_MIN_PKT);
8050 mvpp2_write(priv, MVPP2_RX_FIFO_INIT_REG, 0x1);
8051}
8052
8053static void mvpp22_rx_fifo_init(struct mvpp2 *priv)
8054{
8055 int port;
8056
8057 /* The FIFO size parameters are set depending on the maximum speed a
8058 * given port can handle:
8059 * - Port 0: 10Gbps
8060 * - Port 1: 2.5Gbps
8061 * - Ports 2 and 3: 1Gbps
8062 */
8063
8064 mvpp2_write(priv, MVPP2_RX_DATA_FIFO_SIZE_REG(0),
8065 MVPP2_RX_FIFO_PORT_DATA_SIZE_32KB);
8066 mvpp2_write(priv, MVPP2_RX_ATTR_FIFO_SIZE_REG(0),
8067 MVPP2_RX_FIFO_PORT_ATTR_SIZE_32KB);
8068
8069 mvpp2_write(priv, MVPP2_RX_DATA_FIFO_SIZE_REG(1),
8070 MVPP2_RX_FIFO_PORT_DATA_SIZE_8KB);
8071 mvpp2_write(priv, MVPP2_RX_ATTR_FIFO_SIZE_REG(1),
8072 MVPP2_RX_FIFO_PORT_ATTR_SIZE_8KB);
8073
8074 for (port = 2; port < MVPP2_MAX_PORTS; port++) {
8075 mvpp2_write(priv, MVPP2_RX_DATA_FIFO_SIZE_REG(port),
8076 MVPP2_RX_FIFO_PORT_DATA_SIZE_4KB);
8077 mvpp2_write(priv, MVPP2_RX_ATTR_FIFO_SIZE_REG(port),
8078 MVPP2_RX_FIFO_PORT_ATTR_SIZE_4KB);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008079 }
8080
8081 mvpp2_write(priv, MVPP2_RX_MIN_PKT_SIZE_REG,
8082 MVPP2_RX_FIFO_PORT_MIN_PKT);
8083 mvpp2_write(priv, MVPP2_RX_FIFO_INIT_REG, 0x1);
8084}
8085
Antoine Tenart7c10f972017-10-30 11:23:29 +01008086/* Initialize Tx FIFO's */
8087static void mvpp22_tx_fifo_init(struct mvpp2 *priv)
8088{
8089 int port;
8090
8091 for (port = 0; port < MVPP2_MAX_PORTS; port++)
8092 mvpp2_write(priv, MVPP22_TX_FIFO_SIZE_REG(port),
8093 MVPP22_TX_FIFO_DATA_SIZE_3KB);
8094}
8095
Thomas Petazzoni6763ce32017-03-07 16:53:15 +01008096static void mvpp2_axi_init(struct mvpp2 *priv)
8097{
8098 u32 val, rdval, wrval;
8099
8100 mvpp2_write(priv, MVPP22_BM_ADDR_HIGH_RLS_REG, 0x0);
8101
8102 /* AXI Bridge Configuration */
8103
8104 rdval = MVPP22_AXI_CODE_CACHE_RD_CACHE
8105 << MVPP22_AXI_ATTR_CACHE_OFFS;
8106 rdval |= MVPP22_AXI_CODE_DOMAIN_OUTER_DOM
8107 << MVPP22_AXI_ATTR_DOMAIN_OFFS;
8108
8109 wrval = MVPP22_AXI_CODE_CACHE_WR_CACHE
8110 << MVPP22_AXI_ATTR_CACHE_OFFS;
8111 wrval |= MVPP22_AXI_CODE_DOMAIN_OUTER_DOM
8112 << MVPP22_AXI_ATTR_DOMAIN_OFFS;
8113
8114 /* BM */
8115 mvpp2_write(priv, MVPP22_AXI_BM_WR_ATTR_REG, wrval);
8116 mvpp2_write(priv, MVPP22_AXI_BM_RD_ATTR_REG, rdval);
8117
8118 /* Descriptors */
8119 mvpp2_write(priv, MVPP22_AXI_AGGRQ_DESCR_RD_ATTR_REG, rdval);
8120 mvpp2_write(priv, MVPP22_AXI_TXQ_DESCR_WR_ATTR_REG, wrval);
8121 mvpp2_write(priv, MVPP22_AXI_TXQ_DESCR_RD_ATTR_REG, rdval);
8122 mvpp2_write(priv, MVPP22_AXI_RXQ_DESCR_WR_ATTR_REG, wrval);
8123
8124 /* Buffer Data */
8125 mvpp2_write(priv, MVPP22_AXI_TX_DATA_RD_ATTR_REG, rdval);
8126 mvpp2_write(priv, MVPP22_AXI_RX_DATA_WR_ATTR_REG, wrval);
8127
8128 val = MVPP22_AXI_CODE_CACHE_NON_CACHE
8129 << MVPP22_AXI_CODE_CACHE_OFFS;
8130 val |= MVPP22_AXI_CODE_DOMAIN_SYSTEM
8131 << MVPP22_AXI_CODE_DOMAIN_OFFS;
8132 mvpp2_write(priv, MVPP22_AXI_RD_NORMAL_CODE_REG, val);
8133 mvpp2_write(priv, MVPP22_AXI_WR_NORMAL_CODE_REG, val);
8134
8135 val = MVPP22_AXI_CODE_CACHE_RD_CACHE
8136 << MVPP22_AXI_CODE_CACHE_OFFS;
8137 val |= MVPP22_AXI_CODE_DOMAIN_OUTER_DOM
8138 << MVPP22_AXI_CODE_DOMAIN_OFFS;
8139
8140 mvpp2_write(priv, MVPP22_AXI_RD_SNOOP_CODE_REG, val);
8141
8142 val = MVPP22_AXI_CODE_CACHE_WR_CACHE
8143 << MVPP22_AXI_CODE_CACHE_OFFS;
8144 val |= MVPP22_AXI_CODE_DOMAIN_OUTER_DOM
8145 << MVPP22_AXI_CODE_DOMAIN_OFFS;
8146
8147 mvpp2_write(priv, MVPP22_AXI_WR_SNOOP_CODE_REG, val);
8148}
8149
Marcin Wojtas3f518502014-07-10 16:52:13 -03008150/* Initialize network controller common part HW */
8151static int mvpp2_init(struct platform_device *pdev, struct mvpp2 *priv)
8152{
8153 const struct mbus_dram_target_info *dram_target_info;
8154 int err, i;
Marcin Wojtas08a23752014-07-21 13:48:12 -03008155 u32 val;
Marcin Wojtas3f518502014-07-10 16:52:13 -03008156
Marcin Wojtas3f518502014-07-10 16:52:13 -03008157 /* MBUS windows configuration */
8158 dram_target_info = mv_mbus_dram_info();
8159 if (dram_target_info)
8160 mvpp2_conf_mbus_windows(dram_target_info, priv);
8161
Thomas Petazzoni6763ce32017-03-07 16:53:15 +01008162 if (priv->hw_version == MVPP22)
8163 mvpp2_axi_init(priv);
8164
Marcin Wojtas08a23752014-07-21 13:48:12 -03008165 /* Disable HW PHY polling */
Thomas Petazzoni26975822017-03-07 16:53:14 +01008166 if (priv->hw_version == MVPP21) {
8167 val = readl(priv->lms_base + MVPP2_PHY_AN_CFG0_REG);
8168 val |= MVPP2_PHY_AN_STOP_SMI0_MASK;
8169 writel(val, priv->lms_base + MVPP2_PHY_AN_CFG0_REG);
8170 } else {
8171 val = readl(priv->iface_base + MVPP22_SMI_MISC_CFG_REG);
8172 val &= ~MVPP22_SMI_POLLING_EN;
8173 writel(val, priv->iface_base + MVPP22_SMI_MISC_CFG_REG);
8174 }
Marcin Wojtas08a23752014-07-21 13:48:12 -03008175
Marcin Wojtas3f518502014-07-10 16:52:13 -03008176 /* Allocate and initialize aggregated TXQs */
8177 priv->aggr_txqs = devm_kcalloc(&pdev->dev, num_present_cpus(),
Markus Elfringd7ce3ce2017-04-17 08:48:23 +02008178 sizeof(*priv->aggr_txqs),
Marcin Wojtas3f518502014-07-10 16:52:13 -03008179 GFP_KERNEL);
8180 if (!priv->aggr_txqs)
8181 return -ENOMEM;
8182
8183 for_each_present_cpu(i) {
8184 priv->aggr_txqs[i].id = i;
8185 priv->aggr_txqs[i].size = MVPP2_AGGR_TXQ_SIZE;
Antoine Ténart85affd72017-08-23 09:46:55 +02008186 err = mvpp2_aggr_txq_init(pdev, &priv->aggr_txqs[i], i, priv);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008187 if (err < 0)
8188 return err;
8189 }
8190
Antoine Tenart7c10f972017-10-30 11:23:29 +01008191 /* Fifo Init */
8192 if (priv->hw_version == MVPP21) {
Antoine Tenart2d1d7df2017-10-30 11:23:28 +01008193 mvpp2_rx_fifo_init(priv);
Antoine Tenart7c10f972017-10-30 11:23:29 +01008194 } else {
Antoine Tenart2d1d7df2017-10-30 11:23:28 +01008195 mvpp22_rx_fifo_init(priv);
Antoine Tenart7c10f972017-10-30 11:23:29 +01008196 mvpp22_tx_fifo_init(priv);
8197 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03008198
Thomas Petazzoni26975822017-03-07 16:53:14 +01008199 if (priv->hw_version == MVPP21)
8200 writel(MVPP2_EXT_GLOBAL_CTRL_DEFAULT,
8201 priv->lms_base + MVPP2_MNG_EXTENDED_GLOBAL_CTRL_REG);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008202
8203 /* Allow cache snoop when transmiting packets */
8204 mvpp2_write(priv, MVPP2_TX_SNOOP_REG, 0x1);
8205
8206 /* Buffer Manager initialization */
8207 err = mvpp2_bm_init(pdev, priv);
8208 if (err < 0)
8209 return err;
8210
8211 /* Parser default initialization */
8212 err = mvpp2_prs_default_init(pdev, priv);
8213 if (err < 0)
8214 return err;
8215
8216 /* Classifier default initialization */
8217 mvpp2_cls_init(priv);
8218
8219 return 0;
8220}
8221
8222static int mvpp2_probe(struct platform_device *pdev)
8223{
Marcin Wojtasa75edc72018-01-18 13:31:44 +01008224 const struct acpi_device_id *acpi_id;
Marcin Wojtas24812222018-01-18 13:31:43 +01008225 struct fwnode_handle *fwnode = pdev->dev.fwnode;
8226 struct fwnode_handle *port_fwnode;
Marcin Wojtas3f518502014-07-10 16:52:13 -03008227 struct mvpp2 *priv;
8228 struct resource *res;
Thomas Petazzonia7868412017-03-07 16:53:13 +01008229 void __iomem *base;
Miquel Raynal118d6292017-11-06 22:56:53 +01008230 int i;
Marcin Wojtas3f518502014-07-10 16:52:13 -03008231 int err;
8232
Markus Elfring0b92e592017-04-17 08:38:32 +02008233 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008234 if (!priv)
8235 return -ENOMEM;
8236
Marcin Wojtasa75edc72018-01-18 13:31:44 +01008237 if (has_acpi_companion(&pdev->dev)) {
8238 acpi_id = acpi_match_device(pdev->dev.driver->acpi_match_table,
8239 &pdev->dev);
8240 priv->hw_version = (unsigned long)acpi_id->driver_data;
8241 } else {
8242 priv->hw_version =
8243 (unsigned long)of_device_get_match_data(&pdev->dev);
8244 }
Thomas Petazzonifaca9242017-03-07 16:53:06 +01008245
Marcin Wojtas3f518502014-07-10 16:52:13 -03008246 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Thomas Petazzonia7868412017-03-07 16:53:13 +01008247 base = devm_ioremap_resource(&pdev->dev, res);
8248 if (IS_ERR(base))
8249 return PTR_ERR(base);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008250
Thomas Petazzonia7868412017-03-07 16:53:13 +01008251 if (priv->hw_version == MVPP21) {
8252 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
8253 priv->lms_base = devm_ioremap_resource(&pdev->dev, res);
8254 if (IS_ERR(priv->lms_base))
8255 return PTR_ERR(priv->lms_base);
8256 } else {
8257 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
Marcin Wojtasa75edc72018-01-18 13:31:44 +01008258 if (has_acpi_companion(&pdev->dev)) {
8259 /* In case the MDIO memory region is declared in
8260 * the ACPI, it can already appear as 'in-use'
8261 * in the OS. Because it is overlapped by second
8262 * region of the network controller, make
8263 * sure it is released, before requesting it again.
8264 * The care is taken by mvpp2 driver to avoid
8265 * concurrent access to this memory region.
8266 */
8267 release_resource(res);
8268 }
Thomas Petazzonia7868412017-03-07 16:53:13 +01008269 priv->iface_base = devm_ioremap_resource(&pdev->dev, res);
8270 if (IS_ERR(priv->iface_base))
8271 return PTR_ERR(priv->iface_base);
Marcin Wojtasa75edc72018-01-18 13:31:44 +01008272 }
Antoine Ténartf84bf382017-08-22 19:08:27 +02008273
Marcin Wojtasa75edc72018-01-18 13:31:44 +01008274 if (priv->hw_version == MVPP22 && dev_of_node(&pdev->dev)) {
Antoine Ténartf84bf382017-08-22 19:08:27 +02008275 priv->sysctrl_base =
8276 syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
8277 "marvell,system-controller");
8278 if (IS_ERR(priv->sysctrl_base))
8279 /* The system controller regmap is optional for dt
8280 * compatibility reasons. When not provided, the
8281 * configuration of the GoP relies on the
8282 * firmware/bootloader.
8283 */
8284 priv->sysctrl_base = NULL;
Thomas Petazzonia7868412017-03-07 16:53:13 +01008285 }
8286
Thomas Petazzonidf089aa2017-08-03 10:41:58 +02008287 for (i = 0; i < MVPP2_MAX_THREADS; i++) {
Thomas Petazzonia7868412017-03-07 16:53:13 +01008288 u32 addr_space_sz;
8289
8290 addr_space_sz = (priv->hw_version == MVPP21 ?
8291 MVPP21_ADDR_SPACE_SZ : MVPP22_ADDR_SPACE_SZ);
Thomas Petazzonidf089aa2017-08-03 10:41:58 +02008292 priv->swth_base[i] = base + i * addr_space_sz;
Thomas Petazzonia7868412017-03-07 16:53:13 +01008293 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03008294
Thomas Petazzoni59b9a312017-03-07 16:53:17 +01008295 if (priv->hw_version == MVPP21)
8296 priv->max_port_rxqs = 8;
8297 else
8298 priv->max_port_rxqs = 32;
8299
Marcin Wojtasa75edc72018-01-18 13:31:44 +01008300 if (dev_of_node(&pdev->dev)) {
8301 priv->pp_clk = devm_clk_get(&pdev->dev, "pp_clk");
8302 if (IS_ERR(priv->pp_clk))
8303 return PTR_ERR(priv->pp_clk);
8304 err = clk_prepare_enable(priv->pp_clk);
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008305 if (err < 0)
Marcin Wojtasa75edc72018-01-18 13:31:44 +01008306 return err;
8307
8308 priv->gop_clk = devm_clk_get(&pdev->dev, "gop_clk");
8309 if (IS_ERR(priv->gop_clk)) {
8310 err = PTR_ERR(priv->gop_clk);
8311 goto err_pp_clk;
8312 }
8313 err = clk_prepare_enable(priv->gop_clk);
8314 if (err < 0)
8315 goto err_pp_clk;
8316
8317 if (priv->hw_version == MVPP22) {
8318 priv->mg_clk = devm_clk_get(&pdev->dev, "mg_clk");
8319 if (IS_ERR(priv->mg_clk)) {
8320 err = PTR_ERR(priv->mg_clk);
8321 goto err_gop_clk;
8322 }
8323
8324 err = clk_prepare_enable(priv->mg_clk);
8325 if (err < 0)
8326 goto err_gop_clk;
8327 }
Gregory CLEMENT4792ea02017-09-29 14:27:39 +02008328
8329 priv->axi_clk = devm_clk_get(&pdev->dev, "axi_clk");
8330 if (IS_ERR(priv->axi_clk)) {
8331 err = PTR_ERR(priv->axi_clk);
8332 if (err == -EPROBE_DEFER)
8333 goto err_gop_clk;
8334 priv->axi_clk = NULL;
8335 } else {
8336 err = clk_prepare_enable(priv->axi_clk);
8337 if (err < 0)
8338 goto err_gop_clk;
8339 }
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008340
Marcin Wojtasa75edc72018-01-18 13:31:44 +01008341 /* Get system's tclk rate */
8342 priv->tclk = clk_get_rate(priv->pp_clk);
8343 } else if (device_property_read_u32(&pdev->dev, "clock-frequency",
8344 &priv->tclk)) {
8345 dev_err(&pdev->dev, "missing clock-frequency value\n");
8346 return -EINVAL;
8347 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03008348
Thomas Petazzoni2067e0a2017-03-07 16:53:19 +01008349 if (priv->hw_version == MVPP22) {
8350 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(40));
8351 if (err)
8352 goto err_mg_clk;
8353 /* Sadly, the BM pools all share the same register to
8354 * store the high 32 bits of their address. So they
8355 * must all have the same high 32 bits, which forces
8356 * us to restrict coherent memory to DMA_BIT_MASK(32).
8357 */
8358 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
8359 if (err)
8360 goto err_mg_clk;
8361 }
8362
Marcin Wojtas3f518502014-07-10 16:52:13 -03008363 /* Initialize network controller */
8364 err = mvpp2_init(pdev, priv);
8365 if (err < 0) {
8366 dev_err(&pdev->dev, "failed to initialize controller\n");
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008367 goto err_mg_clk;
Marcin Wojtas3f518502014-07-10 16:52:13 -03008368 }
8369
Marcin Wojtasbf147152018-01-18 13:31:42 +01008370 /* Initialize ports */
Marcin Wojtas24812222018-01-18 13:31:43 +01008371 fwnode_for_each_available_child_node(fwnode, port_fwnode) {
8372 err = mvpp2_port_probe(pdev, port_fwnode, priv);
Marcin Wojtasbf147152018-01-18 13:31:42 +01008373 if (err < 0)
8374 goto err_port_probe;
8375 }
8376
Miquel Raynal118d6292017-11-06 22:56:53 +01008377 if (priv->port_count == 0) {
Marcin Wojtas3f518502014-07-10 16:52:13 -03008378 dev_err(&pdev->dev, "no ports enabled\n");
Wei Yongjun575a1932014-07-20 22:02:43 +08008379 err = -ENODEV;
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008380 goto err_mg_clk;
Marcin Wojtas3f518502014-07-10 16:52:13 -03008381 }
8382
Miquel Raynal118d6292017-11-06 22:56:53 +01008383 /* Statistics must be gathered regularly because some of them (like
8384 * packets counters) are 32-bit registers and could overflow quite
8385 * quickly. For instance, a 10Gb link used at full bandwidth with the
8386 * smallest packets (64B) will overflow a 32-bit counter in less than
8387 * 30 seconds. Then, use a workqueue to fill 64-bit counters.
8388 */
Miquel Raynal118d6292017-11-06 22:56:53 +01008389 snprintf(priv->queue_name, sizeof(priv->queue_name),
8390 "stats-wq-%s%s", netdev_name(priv->port_list[0]->dev),
8391 priv->port_count > 1 ? "+" : "");
8392 priv->stats_queue = create_singlethread_workqueue(priv->queue_name);
8393 if (!priv->stats_queue) {
8394 err = -ENOMEM;
Antoine Tenart26146b02017-11-28 14:19:49 +01008395 goto err_port_probe;
Miquel Raynal118d6292017-11-06 22:56:53 +01008396 }
8397
Marcin Wojtas3f518502014-07-10 16:52:13 -03008398 platform_set_drvdata(pdev, priv);
8399 return 0;
8400
Antoine Tenart26146b02017-11-28 14:19:49 +01008401err_port_probe:
8402 i = 0;
Marcin Wojtas24812222018-01-18 13:31:43 +01008403 fwnode_for_each_available_child_node(fwnode, port_fwnode) {
Antoine Tenart26146b02017-11-28 14:19:49 +01008404 if (priv->port_list[i])
8405 mvpp2_port_remove(priv->port_list[i]);
8406 i++;
8407 }
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008408err_mg_clk:
Gregory CLEMENT4792ea02017-09-29 14:27:39 +02008409 clk_disable_unprepare(priv->axi_clk);
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008410 if (priv->hw_version == MVPP22)
8411 clk_disable_unprepare(priv->mg_clk);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008412err_gop_clk:
8413 clk_disable_unprepare(priv->gop_clk);
8414err_pp_clk:
8415 clk_disable_unprepare(priv->pp_clk);
8416 return err;
8417}
8418
8419static int mvpp2_remove(struct platform_device *pdev)
8420{
8421 struct mvpp2 *priv = platform_get_drvdata(pdev);
Marcin Wojtas24812222018-01-18 13:31:43 +01008422 struct fwnode_handle *fwnode = pdev->dev.fwnode;
8423 struct fwnode_handle *port_fwnode;
Marcin Wojtas3f518502014-07-10 16:52:13 -03008424 int i = 0;
8425
Miquel Raynale5c500e2017-11-08 08:59:40 +01008426 flush_workqueue(priv->stats_queue);
Miquel Raynal118d6292017-11-06 22:56:53 +01008427 destroy_workqueue(priv->stats_queue);
Miquel Raynal118d6292017-11-06 22:56:53 +01008428
Marcin Wojtas24812222018-01-18 13:31:43 +01008429 fwnode_for_each_available_child_node(fwnode, port_fwnode) {
Miquel Raynale5c500e2017-11-08 08:59:40 +01008430 if (priv->port_list[i]) {
8431 mutex_destroy(&priv->port_list[i]->gather_stats_lock);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008432 mvpp2_port_remove(priv->port_list[i]);
Miquel Raynale5c500e2017-11-08 08:59:40 +01008433 }
Marcin Wojtas3f518502014-07-10 16:52:13 -03008434 i++;
8435 }
8436
8437 for (i = 0; i < MVPP2_BM_POOLS_NUM; i++) {
8438 struct mvpp2_bm_pool *bm_pool = &priv->bm_pools[i];
8439
8440 mvpp2_bm_pool_destroy(pdev, priv, bm_pool);
8441 }
8442
8443 for_each_present_cpu(i) {
8444 struct mvpp2_tx_queue *aggr_txq = &priv->aggr_txqs[i];
8445
8446 dma_free_coherent(&pdev->dev,
8447 MVPP2_AGGR_TXQ_SIZE * MVPP2_DESC_ALIGNED_SIZE,
8448 aggr_txq->descs,
Thomas Petazzoni20396132017-03-07 16:53:00 +01008449 aggr_txq->descs_dma);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008450 }
8451
Marcin Wojtasa75edc72018-01-18 13:31:44 +01008452 if (is_acpi_node(port_fwnode))
8453 return 0;
8454
Gregory CLEMENT4792ea02017-09-29 14:27:39 +02008455 clk_disable_unprepare(priv->axi_clk);
Thomas Petazzonifceb55d2017-03-07 16:53:18 +01008456 clk_disable_unprepare(priv->mg_clk);
Marcin Wojtas3f518502014-07-10 16:52:13 -03008457 clk_disable_unprepare(priv->pp_clk);
8458 clk_disable_unprepare(priv->gop_clk);
8459
8460 return 0;
8461}
8462
8463static const struct of_device_id mvpp2_match[] = {
Thomas Petazzonifaca9242017-03-07 16:53:06 +01008464 {
8465 .compatible = "marvell,armada-375-pp2",
8466 .data = (void *)MVPP21,
8467 },
Thomas Petazzonifc5e1552017-03-07 16:53:20 +01008468 {
8469 .compatible = "marvell,armada-7k-pp22",
8470 .data = (void *)MVPP22,
8471 },
Marcin Wojtas3f518502014-07-10 16:52:13 -03008472 { }
8473};
8474MODULE_DEVICE_TABLE(of, mvpp2_match);
8475
Marcin Wojtasa75edc72018-01-18 13:31:44 +01008476static const struct acpi_device_id mvpp2_acpi_match[] = {
8477 { "MRVL0110", MVPP22 },
8478 { },
8479};
8480MODULE_DEVICE_TABLE(acpi, mvpp2_acpi_match);
8481
Marcin Wojtas3f518502014-07-10 16:52:13 -03008482static struct platform_driver mvpp2_driver = {
8483 .probe = mvpp2_probe,
8484 .remove = mvpp2_remove,
8485 .driver = {
8486 .name = MVPP2_DRIVER_NAME,
8487 .of_match_table = mvpp2_match,
Marcin Wojtasa75edc72018-01-18 13:31:44 +01008488 .acpi_match_table = ACPI_PTR(mvpp2_acpi_match),
Marcin Wojtas3f518502014-07-10 16:52:13 -03008489 },
8490};
8491
8492module_platform_driver(mvpp2_driver);
8493
8494MODULE_DESCRIPTION("Marvell PPv2 Ethernet Driver - www.marvell.com");
8495MODULE_AUTHOR("Marcin Wojtas <mw@semihalf.com>");
Ezequiel Garciac6340992014-07-14 10:34:47 -03008496MODULE_LICENSE("GPL v2");