2 * Driver for Marvell PPv2 network controller for Armada 375 SoC.
4 * Copyright (C) 2014 Marvell
6 * Marcin Wojtas <mw@semihalf.com>
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.
13 #include <linux/kernel.h>
14 #include <linux/netdevice.h>
15 #include <linux/etherdevice.h>
16 #include <linux/platform_device.h>
17 #include <linux/skbuff.h>
18 #include <linux/inetdevice.h>
19 #include <linux/mbus.h>
20 #include <linux/module.h>
21 #include <linux/interrupt.h>
22 #include <linux/cpumask.h>
24 #include <linux/of_irq.h>
25 #include <linux/of_mdio.h>
26 #include <linux/of_net.h>
27 #include <linux/of_address.h>
28 #include <linux/phy.h>
29 #include <linux/clk.h>
30 #include <linux/hrtimer.h>
31 #include <linux/ktime.h>
32 #include <uapi/linux/ppp_defs.h>
36 /* RX Fifo Registers */
37 #define MVPP2_RX_DATA_FIFO_SIZE_REG(port) (0x00 + 4 * (port))
38 #define MVPP2_RX_ATTR_FIFO_SIZE_REG(port) (0x20 + 4 * (port))
39 #define MVPP2_RX_MIN_PKT_SIZE_REG 0x60
40 #define MVPP2_RX_FIFO_INIT_REG 0x64
42 /* RX DMA Top Registers */
43 #define MVPP2_RX_CTRL_REG(port) (0x140 + 4 * (port))
44 #define MVPP2_RX_LOW_LATENCY_PKT_SIZE(s) (((s) & 0xfff) << 16)
45 #define MVPP2_RX_USE_PSEUDO_FOR_CSUM_MASK BIT(31)
46 #define MVPP2_POOL_BUF_SIZE_REG(pool) (0x180 + 4 * (pool))
47 #define MVPP2_POOL_BUF_SIZE_OFFSET 5
48 #define MVPP2_RXQ_CONFIG_REG(rxq) (0x800 + 4 * (rxq))
49 #define MVPP2_SNOOP_PKT_SIZE_MASK 0x1ff
50 #define MVPP2_SNOOP_BUF_HDR_MASK BIT(9)
51 #define MVPP2_RXQ_POOL_SHORT_OFFS 20
52 #define MVPP2_RXQ_POOL_SHORT_MASK 0x700000
53 #define MVPP2_RXQ_POOL_LONG_OFFS 24
54 #define MVPP2_RXQ_POOL_LONG_MASK 0x7000000
55 #define MVPP2_RXQ_PACKET_OFFSET_OFFS 28
56 #define MVPP2_RXQ_PACKET_OFFSET_MASK 0x70000000
57 #define MVPP2_RXQ_DISABLE_MASK BIT(31)
59 /* Parser Registers */
60 #define MVPP2_PRS_INIT_LOOKUP_REG 0x1000
61 #define MVPP2_PRS_PORT_LU_MAX 0xf
62 #define MVPP2_PRS_PORT_LU_MASK(port) (0xff << ((port) * 4))
63 #define MVPP2_PRS_PORT_LU_VAL(port, val) ((val) << ((port) * 4))
64 #define MVPP2_PRS_INIT_OFFS_REG(port) (0x1004 + ((port) & 4))
65 #define MVPP2_PRS_INIT_OFF_MASK(port) (0x3f << (((port) % 4) * 8))
66 #define MVPP2_PRS_INIT_OFF_VAL(port, val) ((val) << (((port) % 4) * 8))
67 #define MVPP2_PRS_MAX_LOOP_REG(port) (0x100c + ((port) & 4))
68 #define MVPP2_PRS_MAX_LOOP_MASK(port) (0xff << (((port) % 4) * 8))
69 #define MVPP2_PRS_MAX_LOOP_VAL(port, val) ((val) << (((port) % 4) * 8))
70 #define MVPP2_PRS_TCAM_IDX_REG 0x1100
71 #define MVPP2_PRS_TCAM_DATA_REG(idx) (0x1104 + (idx) * 4)
72 #define MVPP2_PRS_TCAM_INV_MASK BIT(31)
73 #define MVPP2_PRS_SRAM_IDX_REG 0x1200
74 #define MVPP2_PRS_SRAM_DATA_REG(idx) (0x1204 + (idx) * 4)
75 #define MVPP2_PRS_TCAM_CTRL_REG 0x1230
76 #define MVPP2_PRS_TCAM_EN_MASK BIT(0)
78 /* Classifier Registers */
79 #define MVPP2_CLS_MODE_REG 0x1800
80 #define MVPP2_CLS_MODE_ACTIVE_MASK BIT(0)
81 #define MVPP2_CLS_PORT_WAY_REG 0x1810
82 #define MVPP2_CLS_PORT_WAY_MASK(port) (1 << (port))
83 #define MVPP2_CLS_LKP_INDEX_REG 0x1814
84 #define MVPP2_CLS_LKP_INDEX_WAY_OFFS 6
85 #define MVPP2_CLS_LKP_TBL_REG 0x1818
86 #define MVPP2_CLS_LKP_TBL_RXQ_MASK 0xff
87 #define MVPP2_CLS_LKP_TBL_LOOKUP_EN_MASK BIT(25)
88 #define MVPP2_CLS_FLOW_INDEX_REG 0x1820
89 #define MVPP2_CLS_FLOW_TBL0_REG 0x1824
90 #define MVPP2_CLS_FLOW_TBL1_REG 0x1828
91 #define MVPP2_CLS_FLOW_TBL2_REG 0x182c
92 #define MVPP2_CLS_OVERSIZE_RXQ_LOW_REG(port) (0x1980 + ((port) * 4))
93 #define MVPP2_CLS_OVERSIZE_RXQ_LOW_BITS 3
94 #define MVPP2_CLS_OVERSIZE_RXQ_LOW_MASK 0x7
95 #define MVPP2_CLS_SWFWD_P2HQ_REG(port) (0x19b0 + ((port) * 4))
96 #define MVPP2_CLS_SWFWD_PCTRL_REG 0x19d0
97 #define MVPP2_CLS_SWFWD_PCTRL_MASK(port) (1 << (port))
99 /* Descriptor Manager Top Registers */
100 #define MVPP2_RXQ_NUM_REG 0x2040
101 #define MVPP2_RXQ_DESC_ADDR_REG 0x2044
102 #define MVPP2_RXQ_DESC_SIZE_REG 0x2048
103 #define MVPP2_RXQ_DESC_SIZE_MASK 0x3ff0
104 #define MVPP2_RXQ_STATUS_UPDATE_REG(rxq) (0x3000 + 4 * (rxq))
105 #define MVPP2_RXQ_NUM_PROCESSED_OFFSET 0
106 #define MVPP2_RXQ_NUM_NEW_OFFSET 16
107 #define MVPP2_RXQ_STATUS_REG(rxq) (0x3400 + 4 * (rxq))
108 #define MVPP2_RXQ_OCCUPIED_MASK 0x3fff
109 #define MVPP2_RXQ_NON_OCCUPIED_OFFSET 16
110 #define MVPP2_RXQ_NON_OCCUPIED_MASK 0x3fff0000
111 #define MVPP2_RXQ_THRESH_REG 0x204c
112 #define MVPP2_OCCUPIED_THRESH_OFFSET 0
113 #define MVPP2_OCCUPIED_THRESH_MASK 0x3fff
114 #define MVPP2_RXQ_INDEX_REG 0x2050
115 #define MVPP2_TXQ_NUM_REG 0x2080
116 #define MVPP2_TXQ_DESC_ADDR_REG 0x2084
117 #define MVPP2_TXQ_DESC_SIZE_REG 0x2088
118 #define MVPP2_TXQ_DESC_SIZE_MASK 0x3ff0
119 #define MVPP2_AGGR_TXQ_UPDATE_REG 0x2090
120 #define MVPP2_TXQ_THRESH_REG 0x2094
121 #define MVPP2_TRANSMITTED_THRESH_OFFSET 16
122 #define MVPP2_TRANSMITTED_THRESH_MASK 0x3fff0000
123 #define MVPP2_TXQ_INDEX_REG 0x2098
124 #define MVPP2_TXQ_PREF_BUF_REG 0x209c
125 #define MVPP2_PREF_BUF_PTR(desc) ((desc) & 0xfff)
126 #define MVPP2_PREF_BUF_SIZE_4 (BIT(12) | BIT(13))
127 #define MVPP2_PREF_BUF_SIZE_16 (BIT(12) | BIT(14))
128 #define MVPP2_PREF_BUF_THRESH(val) ((val) << 17)
129 #define MVPP2_TXQ_DRAIN_EN_MASK BIT(31)
130 #define MVPP2_TXQ_PENDING_REG 0x20a0
131 #define MVPP2_TXQ_PENDING_MASK 0x3fff
132 #define MVPP2_TXQ_INT_STATUS_REG 0x20a4
133 #define MVPP2_TXQ_SENT_REG(txq) (0x3c00 + 4 * (txq))
134 #define MVPP2_TRANSMITTED_COUNT_OFFSET 16
135 #define MVPP2_TRANSMITTED_COUNT_MASK 0x3fff0000
136 #define MVPP2_TXQ_RSVD_REQ_REG 0x20b0
137 #define MVPP2_TXQ_RSVD_REQ_Q_OFFSET 16
138 #define MVPP2_TXQ_RSVD_RSLT_REG 0x20b4
139 #define MVPP2_TXQ_RSVD_RSLT_MASK 0x3fff
140 #define MVPP2_TXQ_RSVD_CLR_REG 0x20b8
141 #define MVPP2_TXQ_RSVD_CLR_OFFSET 16
142 #define MVPP2_AGGR_TXQ_DESC_ADDR_REG(cpu) (0x2100 + 4 * (cpu))
143 #define MVPP2_AGGR_TXQ_DESC_SIZE_REG(cpu) (0x2140 + 4 * (cpu))
144 #define MVPP2_AGGR_TXQ_DESC_SIZE_MASK 0x3ff0
145 #define MVPP2_AGGR_TXQ_STATUS_REG(cpu) (0x2180 + 4 * (cpu))
146 #define MVPP2_AGGR_TXQ_PENDING_MASK 0x3fff
147 #define MVPP2_AGGR_TXQ_INDEX_REG(cpu) (0x21c0 + 4 * (cpu))
149 /* MBUS bridge registers */
150 #define MVPP2_WIN_BASE(w) (0x4000 + ((w) << 2))
151 #define MVPP2_WIN_SIZE(w) (0x4020 + ((w) << 2))
152 #define MVPP2_WIN_REMAP(w) (0x4040 + ((w) << 2))
153 #define MVPP2_BASE_ADDR_ENABLE 0x4060
155 /* Interrupt Cause and Mask registers */
156 #define MVPP2_ISR_RX_THRESHOLD_REG(rxq) (0x5200 + 4 * (rxq))
157 #define MVPP2_ISR_RXQ_GROUP_REG(rxq) (0x5400 + 4 * (rxq))
158 #define MVPP2_ISR_ENABLE_REG(port) (0x5420 + 4 * (port))
159 #define MVPP2_ISR_ENABLE_INTERRUPT(mask) ((mask) & 0xffff)
160 #define MVPP2_ISR_DISABLE_INTERRUPT(mask) (((mask) << 16) & 0xffff0000)
161 #define MVPP2_ISR_RX_TX_CAUSE_REG(port) (0x5480 + 4 * (port))
162 #define MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK 0xffff
163 #define MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK 0xff0000
164 #define MVPP2_CAUSE_RX_FIFO_OVERRUN_MASK BIT(24)
165 #define MVPP2_CAUSE_FCS_ERR_MASK BIT(25)
166 #define MVPP2_CAUSE_TX_FIFO_UNDERRUN_MASK BIT(26)
167 #define MVPP2_CAUSE_TX_EXCEPTION_SUM_MASK BIT(29)
168 #define MVPP2_CAUSE_RX_EXCEPTION_SUM_MASK BIT(30)
169 #define MVPP2_CAUSE_MISC_SUM_MASK BIT(31)
170 #define MVPP2_ISR_RX_TX_MASK_REG(port) (0x54a0 + 4 * (port))
171 #define MVPP2_ISR_PON_RX_TX_MASK_REG 0x54bc
172 #define MVPP2_PON_CAUSE_RXQ_OCCUP_DESC_ALL_MASK 0xffff
173 #define MVPP2_PON_CAUSE_TXP_OCCUP_DESC_ALL_MASK 0x3fc00000
174 #define MVPP2_PON_CAUSE_MISC_SUM_MASK BIT(31)
175 #define MVPP2_ISR_MISC_CAUSE_REG 0x55b0
177 /* Buffer Manager registers */
178 #define MVPP2_BM_POOL_BASE_REG(pool) (0x6000 + ((pool) * 4))
179 #define MVPP2_BM_POOL_BASE_ADDR_MASK 0xfffff80
180 #define MVPP2_BM_POOL_SIZE_REG(pool) (0x6040 + ((pool) * 4))
181 #define MVPP2_BM_POOL_SIZE_MASK 0xfff0
182 #define MVPP2_BM_POOL_READ_PTR_REG(pool) (0x6080 + ((pool) * 4))
183 #define MVPP2_BM_POOL_GET_READ_PTR_MASK 0xfff0
184 #define MVPP2_BM_POOL_PTRS_NUM_REG(pool) (0x60c0 + ((pool) * 4))
185 #define MVPP2_BM_POOL_PTRS_NUM_MASK 0xfff0
186 #define MVPP2_BM_BPPI_READ_PTR_REG(pool) (0x6100 + ((pool) * 4))
187 #define MVPP2_BM_BPPI_PTRS_NUM_REG(pool) (0x6140 + ((pool) * 4))
188 #define MVPP2_BM_BPPI_PTR_NUM_MASK 0x7ff
189 #define MVPP2_BM_BPPI_PREFETCH_FULL_MASK BIT(16)
190 #define MVPP2_BM_POOL_CTRL_REG(pool) (0x6200 + ((pool) * 4))
191 #define MVPP2_BM_START_MASK BIT(0)
192 #define MVPP2_BM_STOP_MASK BIT(1)
193 #define MVPP2_BM_STATE_MASK BIT(4)
194 #define MVPP2_BM_LOW_THRESH_OFFS 8
195 #define MVPP2_BM_LOW_THRESH_MASK 0x7f00
196 #define MVPP2_BM_LOW_THRESH_VALUE(val) ((val) << \
197 MVPP2_BM_LOW_THRESH_OFFS)
198 #define MVPP2_BM_HIGH_THRESH_OFFS 16
199 #define MVPP2_BM_HIGH_THRESH_MASK 0x7f0000
200 #define MVPP2_BM_HIGH_THRESH_VALUE(val) ((val) << \
201 MVPP2_BM_HIGH_THRESH_OFFS)
202 #define MVPP2_BM_INTR_CAUSE_REG(pool) (0x6240 + ((pool) * 4))
203 #define MVPP2_BM_RELEASED_DELAY_MASK BIT(0)
204 #define MVPP2_BM_ALLOC_FAILED_MASK BIT(1)
205 #define MVPP2_BM_BPPE_EMPTY_MASK BIT(2)
206 #define MVPP2_BM_BPPE_FULL_MASK BIT(3)
207 #define MVPP2_BM_AVAILABLE_BP_LOW_MASK BIT(4)
208 #define MVPP2_BM_INTR_MASK_REG(pool) (0x6280 + ((pool) * 4))
209 #define MVPP2_BM_PHY_ALLOC_REG(pool) (0x6400 + ((pool) * 4))
210 #define MVPP2_BM_PHY_ALLOC_GRNTD_MASK BIT(0)
211 #define MVPP2_BM_VIRT_ALLOC_REG 0x6440
212 #define MVPP2_BM_PHY_RLS_REG(pool) (0x6480 + ((pool) * 4))
213 #define MVPP2_BM_PHY_RLS_MC_BUFF_MASK BIT(0)
214 #define MVPP2_BM_PHY_RLS_PRIO_EN_MASK BIT(1)
215 #define MVPP2_BM_PHY_RLS_GRNTD_MASK BIT(2)
216 #define MVPP2_BM_VIRT_RLS_REG 0x64c0
217 #define MVPP2_BM_MC_RLS_REG 0x64c4
218 #define MVPP2_BM_MC_ID_MASK 0xfff
219 #define MVPP2_BM_FORCE_RELEASE_MASK BIT(12)
221 /* TX Scheduler registers */
222 #define MVPP2_TXP_SCHED_PORT_INDEX_REG 0x8000
223 #define MVPP2_TXP_SCHED_Q_CMD_REG 0x8004
224 #define MVPP2_TXP_SCHED_ENQ_MASK 0xff
225 #define MVPP2_TXP_SCHED_DISQ_OFFSET 8
226 #define MVPP2_TXP_SCHED_CMD_1_REG 0x8010
227 #define MVPP2_TXP_SCHED_PERIOD_REG 0x8018
228 #define MVPP2_TXP_SCHED_MTU_REG 0x801c
229 #define MVPP2_TXP_MTU_MAX 0x7FFFF
230 #define MVPP2_TXP_SCHED_REFILL_REG 0x8020
231 #define MVPP2_TXP_REFILL_TOKENS_ALL_MASK 0x7ffff
232 #define MVPP2_TXP_REFILL_PERIOD_ALL_MASK 0x3ff00000
233 #define MVPP2_TXP_REFILL_PERIOD_MASK(v) ((v) << 20)
234 #define MVPP2_TXP_SCHED_TOKEN_SIZE_REG 0x8024
235 #define MVPP2_TXP_TOKEN_SIZE_MAX 0xffffffff
236 #define MVPP2_TXQ_SCHED_REFILL_REG(q) (0x8040 + ((q) << 2))
237 #define MVPP2_TXQ_REFILL_TOKENS_ALL_MASK 0x7ffff
238 #define MVPP2_TXQ_REFILL_PERIOD_ALL_MASK 0x3ff00000
239 #define MVPP2_TXQ_REFILL_PERIOD_MASK(v) ((v) << 20)
240 #define MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(q) (0x8060 + ((q) << 2))
241 #define MVPP2_TXQ_TOKEN_SIZE_MAX 0x7fffffff
242 #define MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(q) (0x8080 + ((q) << 2))
243 #define MVPP2_TXQ_TOKEN_CNTR_MAX 0xffffffff
245 /* TX general registers */
246 #define MVPP2_TX_SNOOP_REG 0x8800
247 #define MVPP2_TX_PORT_FLUSH_REG 0x8810
248 #define MVPP2_TX_PORT_FLUSH_MASK(port) (1 << (port))
251 #define MVPP2_SRC_ADDR_MIDDLE 0x24
252 #define MVPP2_SRC_ADDR_HIGH 0x28
253 #define MVPP2_PHY_AN_CFG0_REG 0x34
254 #define MVPP2_PHY_AN_STOP_SMI0_MASK BIT(7)
255 #define MVPP2_MIB_COUNTERS_BASE(port) (0x1000 + ((port) >> 1) * \
256 0x400 + (port) * 0x400)
257 #define MVPP2_MIB_LATE_COLLISION 0x7c
258 #define MVPP2_ISR_SUM_MASK_REG 0x220c
259 #define MVPP2_MNG_EXTENDED_GLOBAL_CTRL_REG 0x305c
260 #define MVPP2_EXT_GLOBAL_CTRL_DEFAULT 0x27
262 /* Per-port registers */
263 #define MVPP2_GMAC_CTRL_0_REG 0x0
264 #define MVPP2_GMAC_PORT_EN_MASK BIT(0)
265 #define MVPP2_GMAC_MAX_RX_SIZE_OFFS 2
266 #define MVPP2_GMAC_MAX_RX_SIZE_MASK 0x7ffc
267 #define MVPP2_GMAC_MIB_CNTR_EN_MASK BIT(15)
268 #define MVPP2_GMAC_CTRL_1_REG 0x4
269 #define MVPP2_GMAC_PERIODIC_XON_EN_MASK BIT(1)
270 #define MVPP2_GMAC_GMII_LB_EN_MASK BIT(5)
271 #define MVPP2_GMAC_PCS_LB_EN_BIT 6
272 #define MVPP2_GMAC_PCS_LB_EN_MASK BIT(6)
273 #define MVPP2_GMAC_SA_LOW_OFFS 7
274 #define MVPP2_GMAC_CTRL_2_REG 0x8
275 #define MVPP2_GMAC_INBAND_AN_MASK BIT(0)
276 #define MVPP2_GMAC_PCS_ENABLE_MASK BIT(3)
277 #define MVPP2_GMAC_PORT_RGMII_MASK BIT(4)
278 #define MVPP2_GMAC_PORT_RESET_MASK BIT(6)
279 #define MVPP2_GMAC_AUTONEG_CONFIG 0xc
280 #define MVPP2_GMAC_FORCE_LINK_DOWN BIT(0)
281 #define MVPP2_GMAC_FORCE_LINK_PASS BIT(1)
282 #define MVPP2_GMAC_CONFIG_MII_SPEED BIT(5)
283 #define MVPP2_GMAC_CONFIG_GMII_SPEED BIT(6)
284 #define MVPP2_GMAC_AN_SPEED_EN BIT(7)
285 #define MVPP2_GMAC_FC_ADV_EN BIT(9)
286 #define MVPP2_GMAC_CONFIG_FULL_DUPLEX BIT(12)
287 #define MVPP2_GMAC_AN_DUPLEX_EN BIT(13)
288 #define MVPP2_GMAC_PORT_FIFO_CFG_1_REG 0x1c
289 #define MVPP2_GMAC_TX_FIFO_MIN_TH_OFFS 6
290 #define MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK 0x1fc0
291 #define MVPP2_GMAC_TX_FIFO_MIN_TH_MASK(v) (((v) << 6) & \
292 MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK)
294 #define MVPP2_CAUSE_TXQ_SENT_DESC_ALL_MASK 0xff
296 /* Descriptor ring Macros */
297 #define MVPP2_QUEUE_NEXT_DESC(q, index) \
298 (((index) < (q)->last_desc) ? ((index) + 1) : 0)
300 /* Various constants */
303 #define MVPP2_TXDONE_COAL_PKTS_THRESH 15
304 #define MVPP2_TXDONE_HRTIMER_PERIOD_NS 1000000UL
305 #define MVPP2_RX_COAL_PKTS 32
306 #define MVPP2_RX_COAL_USEC 100
308 /* The two bytes Marvell header. Either contains a special value used
309 * by Marvell switches when a specific hardware mode is enabled (not
310 * supported by this driver) or is filled automatically by zeroes on
311 * the RX side. Those two bytes being at the front of the Ethernet
312 * header, they allow to have the IP header aligned on a 4 bytes
313 * boundary automatically: the hardware skips those two bytes on its
316 #define MVPP2_MH_SIZE 2
317 #define MVPP2_ETH_TYPE_LEN 2
318 #define MVPP2_PPPOE_HDR_SIZE 8
319 #define MVPP2_VLAN_TAG_LEN 4
321 /* Lbtd 802.3 type */
322 #define MVPP2_IP_LBDT_TYPE 0xfffa
324 #define MVPP2_TX_CSUM_MAX_SIZE 9800
326 /* Timeout constants */
327 #define MVPP2_TX_DISABLE_TIMEOUT_MSEC 1000
328 #define MVPP2_TX_PENDING_TIMEOUT_MSEC 1000
330 #define MVPP2_TX_MTU_MAX 0x7ffff
332 /* Maximum number of T-CONTs of PON port */
333 #define MVPP2_MAX_TCONT 16
335 /* Maximum number of supported ports */
336 #define MVPP2_MAX_PORTS 4
338 /* Maximum number of TXQs used by single port */
339 #define MVPP2_MAX_TXQ 8
341 /* Maximum number of RXQs used by single port */
342 #define MVPP2_MAX_RXQ 8
344 /* Dfault number of RXQs in use */
345 #define MVPP2_DEFAULT_RXQ 4
347 /* Total number of RXQs available to all ports */
348 #define MVPP2_RXQ_TOTAL_NUM (MVPP2_MAX_PORTS * MVPP2_MAX_RXQ)
350 /* Max number of Rx descriptors */
351 #define MVPP2_MAX_RXD 128
353 /* Max number of Tx descriptors */
354 #define MVPP2_MAX_TXD 1024
356 /* Amount of Tx descriptors that can be reserved at once by CPU */
357 #define MVPP2_CPU_DESC_CHUNK 64
359 /* Max number of Tx descriptors in each aggregated queue */
360 #define MVPP2_AGGR_TXQ_SIZE 256
362 /* Descriptor aligned size */
363 #define MVPP2_DESC_ALIGNED_SIZE 32
365 /* Descriptor alignment mask */
366 #define MVPP2_TX_DESC_ALIGN (MVPP2_DESC_ALIGNED_SIZE - 1)
368 /* RX FIFO constants */
369 #define MVPP2_RX_FIFO_PORT_DATA_SIZE 0x2000
370 #define MVPP2_RX_FIFO_PORT_ATTR_SIZE 0x80
371 #define MVPP2_RX_FIFO_PORT_MIN_PKT 0x80
373 /* RX buffer constants */
374 #define MVPP2_SKB_SHINFO_SIZE \
375 SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
377 #define MVPP2_RX_PKT_SIZE(mtu) \
378 ALIGN((mtu) + MVPP2_MH_SIZE + MVPP2_VLAN_TAG_LEN + \
379 ETH_HLEN + ETH_FCS_LEN, cache_line_size())
381 #define MVPP2_RX_BUF_SIZE(pkt_size) ((pkt_size) + NET_SKB_PAD)
382 #define MVPP2_RX_TOTAL_SIZE(buf_size) ((buf_size) + MVPP2_SKB_SHINFO_SIZE)
383 #define MVPP2_RX_MAX_PKT_SIZE(total_size) \
384 ((total_size) - NET_SKB_PAD - MVPP2_SKB_SHINFO_SIZE)
386 #define MVPP2_BIT_TO_BYTE(bit) ((bit) / 8)
388 /* IPv6 max L3 address size */
389 #define MVPP2_MAX_L3_ADDR_SIZE 16
392 #define MVPP2_F_LOOPBACK BIT(0)
394 /* Marvell tag types */
395 enum mvpp2_tag_type
{
396 MVPP2_TAG_TYPE_NONE
= 0,
397 MVPP2_TAG_TYPE_MH
= 1,
398 MVPP2_TAG_TYPE_DSA
= 2,
399 MVPP2_TAG_TYPE_EDSA
= 3,
400 MVPP2_TAG_TYPE_VLAN
= 4,
401 MVPP2_TAG_TYPE_LAST
= 5
404 /* Parser constants */
405 #define MVPP2_PRS_TCAM_SRAM_SIZE 256
406 #define MVPP2_PRS_TCAM_WORDS 6
407 #define MVPP2_PRS_SRAM_WORDS 4
408 #define MVPP2_PRS_FLOW_ID_SIZE 64
409 #define MVPP2_PRS_FLOW_ID_MASK 0x3f
410 #define MVPP2_PRS_TCAM_ENTRY_INVALID 1
411 #define MVPP2_PRS_TCAM_DSA_TAGGED_BIT BIT(5)
412 #define MVPP2_PRS_IPV4_HEAD 0x40
413 #define MVPP2_PRS_IPV4_HEAD_MASK 0xf0
414 #define MVPP2_PRS_IPV4_MC 0xe0
415 #define MVPP2_PRS_IPV4_MC_MASK 0xf0
416 #define MVPP2_PRS_IPV4_BC_MASK 0xff
417 #define MVPP2_PRS_IPV4_IHL 0x5
418 #define MVPP2_PRS_IPV4_IHL_MASK 0xf
419 #define MVPP2_PRS_IPV6_MC 0xff
420 #define MVPP2_PRS_IPV6_MC_MASK 0xff
421 #define MVPP2_PRS_IPV6_HOP_MASK 0xff
422 #define MVPP2_PRS_TCAM_PROTO_MASK 0xff
423 #define MVPP2_PRS_TCAM_PROTO_MASK_L 0x3f
424 #define MVPP2_PRS_DBL_VLANS_MAX 100
427 * - lookup ID - 4 bits
429 * - additional information - 1 byte
430 * - header data - 8 bytes
431 * The fields are represented by MVPP2_PRS_TCAM_DATA_REG(5)->(0).
433 #define MVPP2_PRS_AI_BITS 8
434 #define MVPP2_PRS_PORT_MASK 0xff
435 #define MVPP2_PRS_LU_MASK 0xf
436 #define MVPP2_PRS_TCAM_DATA_BYTE(offs) \
437 (((offs) - ((offs) % 2)) * 2 + ((offs) % 2))
438 #define MVPP2_PRS_TCAM_DATA_BYTE_EN(offs) \
439 (((offs) * 2) - ((offs) % 2) + 2)
440 #define MVPP2_PRS_TCAM_AI_BYTE 16
441 #define MVPP2_PRS_TCAM_PORT_BYTE 17
442 #define MVPP2_PRS_TCAM_LU_BYTE 20
443 #define MVPP2_PRS_TCAM_EN_OFFS(offs) ((offs) + 2)
444 #define MVPP2_PRS_TCAM_INV_WORD 5
445 /* Tcam entries ID */
446 #define MVPP2_PE_DROP_ALL 0
447 #define MVPP2_PE_FIRST_FREE_TID 1
448 #define MVPP2_PE_LAST_FREE_TID (MVPP2_PRS_TCAM_SRAM_SIZE - 31)
449 #define MVPP2_PE_IP6_EXT_PROTO_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 30)
450 #define MVPP2_PE_MAC_MC_IP6 (MVPP2_PRS_TCAM_SRAM_SIZE - 29)
451 #define MVPP2_PE_IP6_ADDR_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 28)
452 #define MVPP2_PE_IP4_ADDR_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 27)
453 #define MVPP2_PE_LAST_DEFAULT_FLOW (MVPP2_PRS_TCAM_SRAM_SIZE - 26)
454 #define MVPP2_PE_FIRST_DEFAULT_FLOW (MVPP2_PRS_TCAM_SRAM_SIZE - 19)
455 #define MVPP2_PE_EDSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 18)
456 #define MVPP2_PE_EDSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 17)
457 #define MVPP2_PE_DSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 16)
458 #define MVPP2_PE_DSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 15)
459 #define MVPP2_PE_ETYPE_EDSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 14)
460 #define MVPP2_PE_ETYPE_EDSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 13)
461 #define MVPP2_PE_ETYPE_DSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 12)
462 #define MVPP2_PE_ETYPE_DSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 11)
463 #define MVPP2_PE_MH_DEFAULT (MVPP2_PRS_TCAM_SRAM_SIZE - 10)
464 #define MVPP2_PE_DSA_DEFAULT (MVPP2_PRS_TCAM_SRAM_SIZE - 9)
465 #define MVPP2_PE_IP6_PROTO_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 8)
466 #define MVPP2_PE_IP4_PROTO_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 7)
467 #define MVPP2_PE_ETH_TYPE_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 6)
468 #define MVPP2_PE_VLAN_DBL (MVPP2_PRS_TCAM_SRAM_SIZE - 5)
469 #define MVPP2_PE_VLAN_NONE (MVPP2_PRS_TCAM_SRAM_SIZE - 4)
470 #define MVPP2_PE_MAC_MC_ALL (MVPP2_PRS_TCAM_SRAM_SIZE - 3)
471 #define MVPP2_PE_MAC_PROMISCUOUS (MVPP2_PRS_TCAM_SRAM_SIZE - 2)
472 #define MVPP2_PE_MAC_NON_PROMISCUOUS (MVPP2_PRS_TCAM_SRAM_SIZE - 1)
475 * The fields are represented by MVPP2_PRS_TCAM_DATA_REG(3)->(0).
477 #define MVPP2_PRS_SRAM_RI_OFFS 0
478 #define MVPP2_PRS_SRAM_RI_WORD 0
479 #define MVPP2_PRS_SRAM_RI_CTRL_OFFS 32
480 #define MVPP2_PRS_SRAM_RI_CTRL_WORD 1
481 #define MVPP2_PRS_SRAM_RI_CTRL_BITS 32
482 #define MVPP2_PRS_SRAM_SHIFT_OFFS 64
483 #define MVPP2_PRS_SRAM_SHIFT_SIGN_BIT 72
484 #define MVPP2_PRS_SRAM_UDF_OFFS 73
485 #define MVPP2_PRS_SRAM_UDF_BITS 8
486 #define MVPP2_PRS_SRAM_UDF_MASK 0xff
487 #define MVPP2_PRS_SRAM_UDF_SIGN_BIT 81
488 #define MVPP2_PRS_SRAM_UDF_TYPE_OFFS 82
489 #define MVPP2_PRS_SRAM_UDF_TYPE_MASK 0x7
490 #define MVPP2_PRS_SRAM_UDF_TYPE_L3 1
491 #define MVPP2_PRS_SRAM_UDF_TYPE_L4 4
492 #define MVPP2_PRS_SRAM_OP_SEL_SHIFT_OFFS 85
493 #define MVPP2_PRS_SRAM_OP_SEL_SHIFT_MASK 0x3
494 #define MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD 1
495 #define MVPP2_PRS_SRAM_OP_SEL_SHIFT_IP4_ADD 2
496 #define MVPP2_PRS_SRAM_OP_SEL_SHIFT_IP6_ADD 3
497 #define MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS 87
498 #define MVPP2_PRS_SRAM_OP_SEL_UDF_BITS 2
499 #define MVPP2_PRS_SRAM_OP_SEL_UDF_MASK 0x3
500 #define MVPP2_PRS_SRAM_OP_SEL_UDF_ADD 0
501 #define MVPP2_PRS_SRAM_OP_SEL_UDF_IP4_ADD 2
502 #define MVPP2_PRS_SRAM_OP_SEL_UDF_IP6_ADD 3
503 #define MVPP2_PRS_SRAM_OP_SEL_BASE_OFFS 89
504 #define MVPP2_PRS_SRAM_AI_OFFS 90
505 #define MVPP2_PRS_SRAM_AI_CTRL_OFFS 98
506 #define MVPP2_PRS_SRAM_AI_CTRL_BITS 8
507 #define MVPP2_PRS_SRAM_AI_MASK 0xff
508 #define MVPP2_PRS_SRAM_NEXT_LU_OFFS 106
509 #define MVPP2_PRS_SRAM_NEXT_LU_MASK 0xf
510 #define MVPP2_PRS_SRAM_LU_DONE_BIT 110
511 #define MVPP2_PRS_SRAM_LU_GEN_BIT 111
513 /* Sram result info bits assignment */
514 #define MVPP2_PRS_RI_MAC_ME_MASK 0x1
515 #define MVPP2_PRS_RI_DSA_MASK 0x2
516 #define MVPP2_PRS_RI_VLAN_MASK 0xc
517 #define MVPP2_PRS_RI_VLAN_NONE ~(BIT(2) | BIT(3))
518 #define MVPP2_PRS_RI_VLAN_SINGLE BIT(2)
519 #define MVPP2_PRS_RI_VLAN_DOUBLE BIT(3)
520 #define MVPP2_PRS_RI_VLAN_TRIPLE (BIT(2) | BIT(3))
521 #define MVPP2_PRS_RI_CPU_CODE_MASK 0x70
522 #define MVPP2_PRS_RI_CPU_CODE_RX_SPEC BIT(4)
523 #define MVPP2_PRS_RI_L2_CAST_MASK 0x600
524 #define MVPP2_PRS_RI_L2_UCAST ~(BIT(9) | BIT(10))
525 #define MVPP2_PRS_RI_L2_MCAST BIT(9)
526 #define MVPP2_PRS_RI_L2_BCAST BIT(10)
527 #define MVPP2_PRS_RI_PPPOE_MASK 0x800
528 #define MVPP2_PRS_RI_L3_PROTO_MASK 0x7000
529 #define MVPP2_PRS_RI_L3_UN ~(BIT(12) | BIT(13) | BIT(14))
530 #define MVPP2_PRS_RI_L3_IP4 BIT(12)
531 #define MVPP2_PRS_RI_L3_IP4_OPT BIT(13)
532 #define MVPP2_PRS_RI_L3_IP4_OTHER (BIT(12) | BIT(13))
533 #define MVPP2_PRS_RI_L3_IP6 BIT(14)
534 #define MVPP2_PRS_RI_L3_IP6_EXT (BIT(12) | BIT(14))
535 #define MVPP2_PRS_RI_L3_ARP (BIT(13) | BIT(14))
536 #define MVPP2_PRS_RI_L3_ADDR_MASK 0x18000
537 #define MVPP2_PRS_RI_L3_UCAST ~(BIT(15) | BIT(16))
538 #define MVPP2_PRS_RI_L3_MCAST BIT(15)
539 #define MVPP2_PRS_RI_L3_BCAST (BIT(15) | BIT(16))
540 #define MVPP2_PRS_RI_IP_FRAG_MASK 0x20000
541 #define MVPP2_PRS_RI_UDF3_MASK 0x300000
542 #define MVPP2_PRS_RI_UDF3_RX_SPECIAL BIT(21)
543 #define MVPP2_PRS_RI_L4_PROTO_MASK 0x1c00000
544 #define MVPP2_PRS_RI_L4_TCP BIT(22)
545 #define MVPP2_PRS_RI_L4_UDP BIT(23)
546 #define MVPP2_PRS_RI_L4_OTHER (BIT(22) | BIT(23))
547 #define MVPP2_PRS_RI_UDF7_MASK 0x60000000
548 #define MVPP2_PRS_RI_UDF7_IP6_LITE BIT(29)
549 #define MVPP2_PRS_RI_DROP_MASK 0x80000000
551 /* Sram additional info bits assignment */
552 #define MVPP2_PRS_IPV4_DIP_AI_BIT BIT(0)
553 #define MVPP2_PRS_IPV6_NO_EXT_AI_BIT BIT(0)
554 #define MVPP2_PRS_IPV6_EXT_AI_BIT BIT(1)
555 #define MVPP2_PRS_IPV6_EXT_AH_AI_BIT BIT(2)
556 #define MVPP2_PRS_IPV6_EXT_AH_LEN_AI_BIT BIT(3)
557 #define MVPP2_PRS_IPV6_EXT_AH_L4_AI_BIT BIT(4)
558 #define MVPP2_PRS_SINGLE_VLAN_AI 0
559 #define MVPP2_PRS_DBL_VLAN_AI_BIT BIT(7)
562 #define MVPP2_PRS_TAGGED true
563 #define MVPP2_PRS_UNTAGGED false
564 #define MVPP2_PRS_EDSA true
565 #define MVPP2_PRS_DSA false
567 /* MAC entries, shadow udf */
569 MVPP2_PRS_UDF_MAC_DEF
,
570 MVPP2_PRS_UDF_MAC_RANGE
,
571 MVPP2_PRS_UDF_L2_DEF
,
572 MVPP2_PRS_UDF_L2_DEF_COPY
,
573 MVPP2_PRS_UDF_L2_USER
,
577 enum mvpp2_prs_lookup
{
591 enum mvpp2_prs_l3_cast
{
592 MVPP2_PRS_L3_UNI_CAST
,
593 MVPP2_PRS_L3_MULTI_CAST
,
594 MVPP2_PRS_L3_BROAD_CAST
597 /* Classifier constants */
598 #define MVPP2_CLS_FLOWS_TBL_SIZE 512
599 #define MVPP2_CLS_FLOWS_TBL_DATA_WORDS 3
600 #define MVPP2_CLS_LKP_TBL_SIZE 64
603 #define MVPP2_BM_POOLS_NUM 8
604 #define MVPP2_BM_LONG_BUF_NUM 1024
605 #define MVPP2_BM_SHORT_BUF_NUM 2048
606 #define MVPP2_BM_POOL_SIZE_MAX (16*1024 - MVPP2_BM_POOL_PTR_ALIGN/4)
607 #define MVPP2_BM_POOL_PTR_ALIGN 128
608 #define MVPP2_BM_SWF_LONG_POOL(port) ((port > 2) ? 2 : port)
609 #define MVPP2_BM_SWF_SHORT_POOL 3
611 /* BM cookie (32 bits) definition */
612 #define MVPP2_BM_COOKIE_POOL_OFFS 8
613 #define MVPP2_BM_COOKIE_CPU_OFFS 24
615 /* BM short pool packet size
616 * These value assure that for SWF the total number
617 * of bytes allocated for each buffer will be 512
619 #define MVPP2_BM_SHORT_PKT_SIZE MVPP2_RX_MAX_PKT_SIZE(512)
629 /* Shared Packet Processor resources */
631 /* Shared registers' base addresses */
633 void __iomem
*lms_base
;
639 /* List of pointers to port structures */
640 struct mvpp2_port
**port_list
;
642 /* Aggregated TXQs */
643 struct mvpp2_tx_queue
*aggr_txqs
;
646 struct mvpp2_bm_pool
*bm_pools
;
648 /* PRS shadow table */
649 struct mvpp2_prs_shadow
*prs_shadow
;
650 /* PRS auxiliary table for double vlan entries control */
651 bool *prs_double_vlans
;
657 struct mvpp2_pcpu_stats
{
658 struct u64_stats_sync syncp
;
665 /* Per-CPU port control */
666 struct mvpp2_port_pcpu
{
667 struct hrtimer tx_done_timer
;
668 bool timer_scheduled
;
669 /* Tasklet for egress finalization */
670 struct tasklet_struct tx_done_tasklet
;
680 /* Per-port registers' base address */
683 struct mvpp2_rx_queue
**rxqs
;
684 struct mvpp2_tx_queue
**txqs
;
685 struct net_device
*dev
;
689 u32 pending_cause_rx
;
690 struct napi_struct napi
;
692 /* Per-CPU port control */
693 struct mvpp2_port_pcpu __percpu
*pcpu
;
700 struct mvpp2_pcpu_stats __percpu
*stats
;
702 phy_interface_t phy_interface
;
703 struct device_node
*phy_node
;
708 struct mvpp2_bm_pool
*pool_long
;
709 struct mvpp2_bm_pool
*pool_short
;
711 /* Index of first port's physical RXQ */
715 /* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the
716 * layout of the transmit and reception DMA descriptors, and their
717 * layout is therefore defined by the hardware design
720 #define MVPP2_TXD_L3_OFF_SHIFT 0
721 #define MVPP2_TXD_IP_HLEN_SHIFT 8
722 #define MVPP2_TXD_L4_CSUM_FRAG BIT(13)
723 #define MVPP2_TXD_L4_CSUM_NOT BIT(14)
724 #define MVPP2_TXD_IP_CSUM_DISABLE BIT(15)
725 #define MVPP2_TXD_PADDING_DISABLE BIT(23)
726 #define MVPP2_TXD_L4_UDP BIT(24)
727 #define MVPP2_TXD_L3_IP6 BIT(26)
728 #define MVPP2_TXD_L_DESC BIT(28)
729 #define MVPP2_TXD_F_DESC BIT(29)
731 #define MVPP2_RXD_ERR_SUMMARY BIT(15)
732 #define MVPP2_RXD_ERR_CODE_MASK (BIT(13) | BIT(14))
733 #define MVPP2_RXD_ERR_CRC 0x0
734 #define MVPP2_RXD_ERR_OVERRUN BIT(13)
735 #define MVPP2_RXD_ERR_RESOURCE (BIT(13) | BIT(14))
736 #define MVPP2_RXD_BM_POOL_ID_OFFS 16
737 #define MVPP2_RXD_BM_POOL_ID_MASK (BIT(16) | BIT(17) | BIT(18))
738 #define MVPP2_RXD_HWF_SYNC BIT(21)
739 #define MVPP2_RXD_L4_CSUM_OK BIT(22)
740 #define MVPP2_RXD_IP4_HEADER_ERR BIT(24)
741 #define MVPP2_RXD_L4_TCP BIT(25)
742 #define MVPP2_RXD_L4_UDP BIT(26)
743 #define MVPP2_RXD_L3_IP4 BIT(28)
744 #define MVPP2_RXD_L3_IP6 BIT(30)
745 #define MVPP2_RXD_BUF_HDR BIT(31)
747 struct mvpp2_tx_desc
{
748 u32 command
; /* Options used by HW for packet transmitting.*/
749 u8 packet_offset
; /* the offset from the buffer beginning */
750 u8 phys_txq
; /* destination queue ID */
751 u16 data_size
; /* data size of transmitted packet in bytes */
752 u32 buf_phys_addr
; /* physical addr of transmitted buffer */
753 u32 buf_cookie
; /* cookie for access to TX buffer in tx path */
754 u32 reserved1
[3]; /* hw_cmd (for future use, BM, PON, PNC) */
755 u32 reserved2
; /* reserved (for future use) */
758 struct mvpp2_rx_desc
{
759 u32 status
; /* info about received packet */
760 u16 reserved1
; /* parser_info (for future use, PnC) */
761 u16 data_size
; /* size of received packet in bytes */
762 u32 buf_phys_addr
; /* physical address of the buffer */
763 u32 buf_cookie
; /* cookie for access to RX buffer in rx path */
764 u16 reserved2
; /* gem_port_id (for future use, PON) */
765 u16 reserved3
; /* csum_l4 (for future use, PnC) */
766 u8 reserved4
; /* bm_qset (for future use, BM) */
768 u16 reserved6
; /* classify_info (for future use, PnC) */
769 u32 reserved7
; /* flow_id (for future use, PnC) */
773 /* Per-CPU Tx queue control */
774 struct mvpp2_txq_pcpu
{
777 /* Number of Tx DMA descriptors in the descriptor ring */
780 /* Number of currently used Tx DMA descriptor in the
785 /* Number of Tx DMA descriptors reserved for each CPU */
788 /* Array of transmitted skb */
789 struct sk_buff
**tx_skb
;
791 /* Array of transmitted buffers' physical addresses */
792 dma_addr_t
*tx_buffs
;
794 /* Index of last TX DMA descriptor that was inserted */
797 /* Index of the TX DMA descriptor to be cleaned up */
801 struct mvpp2_tx_queue
{
802 /* Physical number of this Tx queue */
805 /* Logical number of this Tx queue */
808 /* Number of Tx DMA descriptors in the descriptor ring */
811 /* Number of currently used Tx DMA descriptor in the descriptor ring */
814 /* Per-CPU control of physical Tx queues */
815 struct mvpp2_txq_pcpu __percpu
*pcpu
;
817 /* Array of transmitted skb */
818 struct sk_buff
**tx_skb
;
822 /* Virtual address of thex Tx DMA descriptors array */
823 struct mvpp2_tx_desc
*descs
;
825 /* DMA address of the Tx DMA descriptors array */
826 dma_addr_t descs_phys
;
828 /* Index of the last Tx DMA descriptor */
831 /* Index of the next Tx DMA descriptor to process */
832 int next_desc_to_proc
;
835 struct mvpp2_rx_queue
{
836 /* RX queue number, in the range 0-31 for physical RXQs */
839 /* Num of rx descriptors in the rx descriptor ring */
845 /* Virtual address of the RX DMA descriptors array */
846 struct mvpp2_rx_desc
*descs
;
848 /* DMA address of the RX DMA descriptors array */
849 dma_addr_t descs_phys
;
851 /* Index of the last RX DMA descriptor */
854 /* Index of the next RX DMA descriptor to process */
855 int next_desc_to_proc
;
857 /* ID of port to which physical RXQ is mapped */
860 /* Port's logic RXQ number to which physical RXQ is mapped */
864 union mvpp2_prs_tcam_entry
{
865 u32 word
[MVPP2_PRS_TCAM_WORDS
];
866 u8 byte
[MVPP2_PRS_TCAM_WORDS
* 4];
869 union mvpp2_prs_sram_entry
{
870 u32 word
[MVPP2_PRS_SRAM_WORDS
];
871 u8 byte
[MVPP2_PRS_SRAM_WORDS
* 4];
874 struct mvpp2_prs_entry
{
876 union mvpp2_prs_tcam_entry tcam
;
877 union mvpp2_prs_sram_entry sram
;
880 struct mvpp2_prs_shadow
{
887 /* User defined offset */
895 struct mvpp2_cls_flow_entry
{
897 u32 data
[MVPP2_CLS_FLOWS_TBL_DATA_WORDS
];
900 struct mvpp2_cls_lookup_entry
{
906 struct mvpp2_bm_pool
{
907 /* Pool number in the range 0-7 */
909 enum mvpp2_bm_type type
;
911 /* Buffer Pointers Pool External (BPPE) size */
913 /* Number of buffers for this pool */
915 /* Pool buffer size */
920 /* BPPE virtual base address */
922 /* BPPE physical base address */
923 dma_addr_t phys_addr
;
925 /* Ports using BM pool */
928 /* Occupied buffers indicator */
933 struct mvpp2_buff_hdr
{
934 u32 next_buff_phys_addr
;
935 u32 next_buff_virt_addr
;
938 u8 reserved1
; /* bm_qset (for future use, BM) */
941 /* Buffer header info bits */
942 #define MVPP2_B_HDR_INFO_MC_ID_MASK 0xfff
943 #define MVPP2_B_HDR_INFO_MC_ID(info) ((info) & MVPP2_B_HDR_INFO_MC_ID_MASK)
944 #define MVPP2_B_HDR_INFO_LAST_OFFS 12
945 #define MVPP2_B_HDR_INFO_LAST_MASK BIT(12)
946 #define MVPP2_B_HDR_INFO_IS_LAST(info) \
947 ((info & MVPP2_B_HDR_INFO_LAST_MASK) >> MVPP2_B_HDR_INFO_LAST_OFFS)
949 /* Static declaractions */
951 /* Number of RXQs used by single port */
952 static int rxq_number
= MVPP2_DEFAULT_RXQ
;
953 /* Number of TXQs used by single port */
954 static int txq_number
= MVPP2_MAX_TXQ
;
956 #define MVPP2_DRIVER_NAME "mvpp2"
957 #define MVPP2_DRIVER_VERSION "1.0"
959 /* Utility/helper methods */
961 static void mvpp2_write(struct mvpp2
*priv
, u32 offset
, u32 data
)
963 writel(data
, priv
->base
+ offset
);
966 static u32
mvpp2_read(struct mvpp2
*priv
, u32 offset
)
968 return readl(priv
->base
+ offset
);
971 static void mvpp2_txq_inc_get(struct mvpp2_txq_pcpu
*txq_pcpu
)
973 txq_pcpu
->txq_get_index
++;
974 if (txq_pcpu
->txq_get_index
== txq_pcpu
->size
)
975 txq_pcpu
->txq_get_index
= 0;
978 static void mvpp2_txq_inc_put(struct mvpp2_txq_pcpu
*txq_pcpu
,
980 struct mvpp2_tx_desc
*tx_desc
)
982 txq_pcpu
->tx_skb
[txq_pcpu
->txq_put_index
] = skb
;
984 txq_pcpu
->tx_buffs
[txq_pcpu
->txq_put_index
] =
985 tx_desc
->buf_phys_addr
;
986 txq_pcpu
->txq_put_index
++;
987 if (txq_pcpu
->txq_put_index
== txq_pcpu
->size
)
988 txq_pcpu
->txq_put_index
= 0;
991 /* Get number of physical egress port */
992 static inline int mvpp2_egress_port(struct mvpp2_port
*port
)
994 return MVPP2_MAX_TCONT
+ port
->id
;
997 /* Get number of physical TXQ */
998 static inline int mvpp2_txq_phys(int port
, int txq
)
1000 return (MVPP2_MAX_TCONT
+ port
) * MVPP2_MAX_TXQ
+ txq
;
1003 /* Parser configuration routines */
1005 /* Update parser tcam and sram hw entries */
1006 static int mvpp2_prs_hw_write(struct mvpp2
*priv
, struct mvpp2_prs_entry
*pe
)
1010 if (pe
->index
> MVPP2_PRS_TCAM_SRAM_SIZE
- 1)
1013 /* Clear entry invalidation bit */
1014 pe
->tcam
.word
[MVPP2_PRS_TCAM_INV_WORD
] &= ~MVPP2_PRS_TCAM_INV_MASK
;
1016 /* Write tcam index - indirect access */
1017 mvpp2_write(priv
, MVPP2_PRS_TCAM_IDX_REG
, pe
->index
);
1018 for (i
= 0; i
< MVPP2_PRS_TCAM_WORDS
; i
++)
1019 mvpp2_write(priv
, MVPP2_PRS_TCAM_DATA_REG(i
), pe
->tcam
.word
[i
]);
1021 /* Write sram index - indirect access */
1022 mvpp2_write(priv
, MVPP2_PRS_SRAM_IDX_REG
, pe
->index
);
1023 for (i
= 0; i
< MVPP2_PRS_SRAM_WORDS
; i
++)
1024 mvpp2_write(priv
, MVPP2_PRS_SRAM_DATA_REG(i
), pe
->sram
.word
[i
]);
1029 /* Read tcam entry from hw */
1030 static int mvpp2_prs_hw_read(struct mvpp2
*priv
, struct mvpp2_prs_entry
*pe
)
1034 if (pe
->index
> MVPP2_PRS_TCAM_SRAM_SIZE
- 1)
1037 /* Write tcam index - indirect access */
1038 mvpp2_write(priv
, MVPP2_PRS_TCAM_IDX_REG
, pe
->index
);
1040 pe
->tcam
.word
[MVPP2_PRS_TCAM_INV_WORD
] = mvpp2_read(priv
,
1041 MVPP2_PRS_TCAM_DATA_REG(MVPP2_PRS_TCAM_INV_WORD
));
1042 if (pe
->tcam
.word
[MVPP2_PRS_TCAM_INV_WORD
] & MVPP2_PRS_TCAM_INV_MASK
)
1043 return MVPP2_PRS_TCAM_ENTRY_INVALID
;
1045 for (i
= 0; i
< MVPP2_PRS_TCAM_WORDS
; i
++)
1046 pe
->tcam
.word
[i
] = mvpp2_read(priv
, MVPP2_PRS_TCAM_DATA_REG(i
));
1048 /* Write sram index - indirect access */
1049 mvpp2_write(priv
, MVPP2_PRS_SRAM_IDX_REG
, pe
->index
);
1050 for (i
= 0; i
< MVPP2_PRS_SRAM_WORDS
; i
++)
1051 pe
->sram
.word
[i
] = mvpp2_read(priv
, MVPP2_PRS_SRAM_DATA_REG(i
));
1056 /* Invalidate tcam hw entry */
1057 static void mvpp2_prs_hw_inv(struct mvpp2
*priv
, int index
)
1059 /* Write index - indirect access */
1060 mvpp2_write(priv
, MVPP2_PRS_TCAM_IDX_REG
, index
);
1061 mvpp2_write(priv
, MVPP2_PRS_TCAM_DATA_REG(MVPP2_PRS_TCAM_INV_WORD
),
1062 MVPP2_PRS_TCAM_INV_MASK
);
1065 /* Enable shadow table entry and set its lookup ID */
1066 static void mvpp2_prs_shadow_set(struct mvpp2
*priv
, int index
, int lu
)
1068 priv
->prs_shadow
[index
].valid
= true;
1069 priv
->prs_shadow
[index
].lu
= lu
;
1072 /* Update ri fields in shadow table entry */
1073 static void mvpp2_prs_shadow_ri_set(struct mvpp2
*priv
, int index
,
1074 unsigned int ri
, unsigned int ri_mask
)
1076 priv
->prs_shadow
[index
].ri_mask
= ri_mask
;
1077 priv
->prs_shadow
[index
].ri
= ri
;
1080 /* Update lookup field in tcam sw entry */
1081 static void mvpp2_prs_tcam_lu_set(struct mvpp2_prs_entry
*pe
, unsigned int lu
)
1083 int enable_off
= MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_LU_BYTE
);
1085 pe
->tcam
.byte
[MVPP2_PRS_TCAM_LU_BYTE
] = lu
;
1086 pe
->tcam
.byte
[enable_off
] = MVPP2_PRS_LU_MASK
;
1089 /* Update mask for single port in tcam sw entry */
1090 static void mvpp2_prs_tcam_port_set(struct mvpp2_prs_entry
*pe
,
1091 unsigned int port
, bool add
)
1093 int enable_off
= MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_PORT_BYTE
);
1096 pe
->tcam
.byte
[enable_off
] &= ~(1 << port
);
1098 pe
->tcam
.byte
[enable_off
] |= 1 << port
;
1101 /* Update port map in tcam sw entry */
1102 static void mvpp2_prs_tcam_port_map_set(struct mvpp2_prs_entry
*pe
,
1105 unsigned char port_mask
= MVPP2_PRS_PORT_MASK
;
1106 int enable_off
= MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_PORT_BYTE
);
1108 pe
->tcam
.byte
[MVPP2_PRS_TCAM_PORT_BYTE
] = 0;
1109 pe
->tcam
.byte
[enable_off
] &= ~port_mask
;
1110 pe
->tcam
.byte
[enable_off
] |= ~ports
& MVPP2_PRS_PORT_MASK
;
1113 /* Obtain port map from tcam sw entry */
1114 static unsigned int mvpp2_prs_tcam_port_map_get(struct mvpp2_prs_entry
*pe
)
1116 int enable_off
= MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_PORT_BYTE
);
1118 return ~(pe
->tcam
.byte
[enable_off
]) & MVPP2_PRS_PORT_MASK
;
1121 /* Set byte of data and its enable bits in tcam sw entry */
1122 static void mvpp2_prs_tcam_data_byte_set(struct mvpp2_prs_entry
*pe
,
1123 unsigned int offs
, unsigned char byte
,
1124 unsigned char enable
)
1126 pe
->tcam
.byte
[MVPP2_PRS_TCAM_DATA_BYTE(offs
)] = byte
;
1127 pe
->tcam
.byte
[MVPP2_PRS_TCAM_DATA_BYTE_EN(offs
)] = enable
;
1130 /* Get byte of data and its enable bits from tcam sw entry */
1131 static void mvpp2_prs_tcam_data_byte_get(struct mvpp2_prs_entry
*pe
,
1132 unsigned int offs
, unsigned char *byte
,
1133 unsigned char *enable
)
1135 *byte
= pe
->tcam
.byte
[MVPP2_PRS_TCAM_DATA_BYTE(offs
)];
1136 *enable
= pe
->tcam
.byte
[MVPP2_PRS_TCAM_DATA_BYTE_EN(offs
)];
1139 /* Compare tcam data bytes with a pattern */
1140 static bool mvpp2_prs_tcam_data_cmp(struct mvpp2_prs_entry
*pe
, int offs
,
1143 int off
= MVPP2_PRS_TCAM_DATA_BYTE(offs
);
1146 tcam_data
= (8 << pe
->tcam
.byte
[off
+ 1]) | pe
->tcam
.byte
[off
];
1147 if (tcam_data
!= data
)
1152 /* Update ai bits in tcam sw entry */
1153 static void mvpp2_prs_tcam_ai_update(struct mvpp2_prs_entry
*pe
,
1154 unsigned int bits
, unsigned int enable
)
1156 int i
, ai_idx
= MVPP2_PRS_TCAM_AI_BYTE
;
1158 for (i
= 0; i
< MVPP2_PRS_AI_BITS
; i
++) {
1160 if (!(enable
& BIT(i
)))
1164 pe
->tcam
.byte
[ai_idx
] |= 1 << i
;
1166 pe
->tcam
.byte
[ai_idx
] &= ~(1 << i
);
1169 pe
->tcam
.byte
[MVPP2_PRS_TCAM_EN_OFFS(ai_idx
)] |= enable
;
1172 /* Get ai bits from tcam sw entry */
1173 static int mvpp2_prs_tcam_ai_get(struct mvpp2_prs_entry
*pe
)
1175 return pe
->tcam
.byte
[MVPP2_PRS_TCAM_AI_BYTE
];
1178 /* Set ethertype in tcam sw entry */
1179 static void mvpp2_prs_match_etype(struct mvpp2_prs_entry
*pe
, int offset
,
1180 unsigned short ethertype
)
1182 mvpp2_prs_tcam_data_byte_set(pe
, offset
+ 0, ethertype
>> 8, 0xff);
1183 mvpp2_prs_tcam_data_byte_set(pe
, offset
+ 1, ethertype
& 0xff, 0xff);
1186 /* Set bits in sram sw entry */
1187 static void mvpp2_prs_sram_bits_set(struct mvpp2_prs_entry
*pe
, int bit_num
,
1190 pe
->sram
.byte
[MVPP2_BIT_TO_BYTE(bit_num
)] |= (val
<< (bit_num
% 8));
1193 /* Clear bits in sram sw entry */
1194 static void mvpp2_prs_sram_bits_clear(struct mvpp2_prs_entry
*pe
, int bit_num
,
1197 pe
->sram
.byte
[MVPP2_BIT_TO_BYTE(bit_num
)] &= ~(val
<< (bit_num
% 8));
1200 /* Update ri bits in sram sw entry */
1201 static void mvpp2_prs_sram_ri_update(struct mvpp2_prs_entry
*pe
,
1202 unsigned int bits
, unsigned int mask
)
1206 for (i
= 0; i
< MVPP2_PRS_SRAM_RI_CTRL_BITS
; i
++) {
1207 int ri_off
= MVPP2_PRS_SRAM_RI_OFFS
;
1209 if (!(mask
& BIT(i
)))
1213 mvpp2_prs_sram_bits_set(pe
, ri_off
+ i
, 1);
1215 mvpp2_prs_sram_bits_clear(pe
, ri_off
+ i
, 1);
1217 mvpp2_prs_sram_bits_set(pe
, MVPP2_PRS_SRAM_RI_CTRL_OFFS
+ i
, 1);
1221 /* Obtain ri bits from sram sw entry */
1222 static int mvpp2_prs_sram_ri_get(struct mvpp2_prs_entry
*pe
)
1224 return pe
->sram
.word
[MVPP2_PRS_SRAM_RI_WORD
];
1227 /* Update ai bits in sram sw entry */
1228 static void mvpp2_prs_sram_ai_update(struct mvpp2_prs_entry
*pe
,
1229 unsigned int bits
, unsigned int mask
)
1232 int ai_off
= MVPP2_PRS_SRAM_AI_OFFS
;
1234 for (i
= 0; i
< MVPP2_PRS_SRAM_AI_CTRL_BITS
; i
++) {
1236 if (!(mask
& BIT(i
)))
1240 mvpp2_prs_sram_bits_set(pe
, ai_off
+ i
, 1);
1242 mvpp2_prs_sram_bits_clear(pe
, ai_off
+ i
, 1);
1244 mvpp2_prs_sram_bits_set(pe
, MVPP2_PRS_SRAM_AI_CTRL_OFFS
+ i
, 1);
1248 /* Read ai bits from sram sw entry */
1249 static int mvpp2_prs_sram_ai_get(struct mvpp2_prs_entry
*pe
)
1252 int ai_off
= MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_AI_OFFS
);
1253 int ai_en_off
= ai_off
+ 1;
1254 int ai_shift
= MVPP2_PRS_SRAM_AI_OFFS
% 8;
1256 bits
= (pe
->sram
.byte
[ai_off
] >> ai_shift
) |
1257 (pe
->sram
.byte
[ai_en_off
] << (8 - ai_shift
));
1262 /* In sram sw entry set lookup ID field of the tcam key to be used in the next
1265 static void mvpp2_prs_sram_next_lu_set(struct mvpp2_prs_entry
*pe
,
1268 int sram_next_off
= MVPP2_PRS_SRAM_NEXT_LU_OFFS
;
1270 mvpp2_prs_sram_bits_clear(pe
, sram_next_off
,
1271 MVPP2_PRS_SRAM_NEXT_LU_MASK
);
1272 mvpp2_prs_sram_bits_set(pe
, sram_next_off
, lu
);
1275 /* In the sram sw entry set sign and value of the next lookup offset
1276 * and the offset value generated to the classifier
1278 static void mvpp2_prs_sram_shift_set(struct mvpp2_prs_entry
*pe
, int shift
,
1283 mvpp2_prs_sram_bits_set(pe
, MVPP2_PRS_SRAM_SHIFT_SIGN_BIT
, 1);
1286 mvpp2_prs_sram_bits_clear(pe
, MVPP2_PRS_SRAM_SHIFT_SIGN_BIT
, 1);
1290 pe
->sram
.byte
[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_SHIFT_OFFS
)] =
1291 (unsigned char)shift
;
1293 /* Reset and set operation */
1294 mvpp2_prs_sram_bits_clear(pe
, MVPP2_PRS_SRAM_OP_SEL_SHIFT_OFFS
,
1295 MVPP2_PRS_SRAM_OP_SEL_SHIFT_MASK
);
1296 mvpp2_prs_sram_bits_set(pe
, MVPP2_PRS_SRAM_OP_SEL_SHIFT_OFFS
, op
);
1298 /* Set base offset as current */
1299 mvpp2_prs_sram_bits_clear(pe
, MVPP2_PRS_SRAM_OP_SEL_BASE_OFFS
, 1);
1302 /* In the sram sw entry set sign and value of the user defined offset
1303 * generated to the classifier
1305 static void mvpp2_prs_sram_offset_set(struct mvpp2_prs_entry
*pe
,
1306 unsigned int type
, int offset
,
1311 mvpp2_prs_sram_bits_set(pe
, MVPP2_PRS_SRAM_UDF_SIGN_BIT
, 1);
1312 offset
= 0 - offset
;
1314 mvpp2_prs_sram_bits_clear(pe
, MVPP2_PRS_SRAM_UDF_SIGN_BIT
, 1);
1318 mvpp2_prs_sram_bits_clear(pe
, MVPP2_PRS_SRAM_UDF_OFFS
,
1319 MVPP2_PRS_SRAM_UDF_MASK
);
1320 mvpp2_prs_sram_bits_set(pe
, MVPP2_PRS_SRAM_UDF_OFFS
, offset
);
1321 pe
->sram
.byte
[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_UDF_OFFS
+
1322 MVPP2_PRS_SRAM_UDF_BITS
)] &=
1323 ~(MVPP2_PRS_SRAM_UDF_MASK
>> (8 - (MVPP2_PRS_SRAM_UDF_OFFS
% 8)));
1324 pe
->sram
.byte
[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_UDF_OFFS
+
1325 MVPP2_PRS_SRAM_UDF_BITS
)] |=
1326 (offset
>> (8 - (MVPP2_PRS_SRAM_UDF_OFFS
% 8)));
1328 /* Set offset type */
1329 mvpp2_prs_sram_bits_clear(pe
, MVPP2_PRS_SRAM_UDF_TYPE_OFFS
,
1330 MVPP2_PRS_SRAM_UDF_TYPE_MASK
);
1331 mvpp2_prs_sram_bits_set(pe
, MVPP2_PRS_SRAM_UDF_TYPE_OFFS
, type
);
1333 /* Set offset operation */
1334 mvpp2_prs_sram_bits_clear(pe
, MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS
,
1335 MVPP2_PRS_SRAM_OP_SEL_UDF_MASK
);
1336 mvpp2_prs_sram_bits_set(pe
, MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS
, op
);
1338 pe
->sram
.byte
[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS
+
1339 MVPP2_PRS_SRAM_OP_SEL_UDF_BITS
)] &=
1340 ~(MVPP2_PRS_SRAM_OP_SEL_UDF_MASK
>>
1341 (8 - (MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS
% 8)));
1343 pe
->sram
.byte
[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS
+
1344 MVPP2_PRS_SRAM_OP_SEL_UDF_BITS
)] |=
1345 (op
>> (8 - (MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS
% 8)));
1347 /* Set base offset as current */
1348 mvpp2_prs_sram_bits_clear(pe
, MVPP2_PRS_SRAM_OP_SEL_BASE_OFFS
, 1);
1351 /* Find parser flow entry */
1352 static struct mvpp2_prs_entry
*mvpp2_prs_flow_find(struct mvpp2
*priv
, int flow
)
1354 struct mvpp2_prs_entry
*pe
;
1357 pe
= kzalloc(sizeof(*pe
), GFP_KERNEL
);
1360 mvpp2_prs_tcam_lu_set(pe
, MVPP2_PRS_LU_FLOWS
);
1362 /* Go through the all entires with MVPP2_PRS_LU_FLOWS */
1363 for (tid
= MVPP2_PRS_TCAM_SRAM_SIZE
- 1; tid
>= 0; tid
--) {
1366 if (!priv
->prs_shadow
[tid
].valid
||
1367 priv
->prs_shadow
[tid
].lu
!= MVPP2_PRS_LU_FLOWS
)
1371 mvpp2_prs_hw_read(priv
, pe
);
1372 bits
= mvpp2_prs_sram_ai_get(pe
);
1374 /* Sram store classification lookup ID in AI bits [5:0] */
1375 if ((bits
& MVPP2_PRS_FLOW_ID_MASK
) == flow
)
1383 /* Return first free tcam index, seeking from start to end */
1384 static int mvpp2_prs_tcam_first_free(struct mvpp2
*priv
, unsigned char start
,
1392 if (end
>= MVPP2_PRS_TCAM_SRAM_SIZE
)
1393 end
= MVPP2_PRS_TCAM_SRAM_SIZE
- 1;
1395 for (tid
= start
; tid
<= end
; tid
++) {
1396 if (!priv
->prs_shadow
[tid
].valid
)
1403 /* Enable/disable dropping all mac da's */
1404 static void mvpp2_prs_mac_drop_all_set(struct mvpp2
*priv
, int port
, bool add
)
1406 struct mvpp2_prs_entry pe
;
1408 if (priv
->prs_shadow
[MVPP2_PE_DROP_ALL
].valid
) {
1409 /* Entry exist - update port only */
1410 pe
.index
= MVPP2_PE_DROP_ALL
;
1411 mvpp2_prs_hw_read(priv
, &pe
);
1413 /* Entry doesn't exist - create new */
1414 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
1415 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_MAC
);
1416 pe
.index
= MVPP2_PE_DROP_ALL
;
1418 /* Non-promiscuous mode for all ports - DROP unknown packets */
1419 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_DROP_MASK
,
1420 MVPP2_PRS_RI_DROP_MASK
);
1422 mvpp2_prs_sram_bits_set(&pe
, MVPP2_PRS_SRAM_LU_GEN_BIT
, 1);
1423 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_FLOWS
);
1425 /* Update shadow table */
1426 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_MAC
);
1428 /* Mask all ports */
1429 mvpp2_prs_tcam_port_map_set(&pe
, 0);
1432 /* Update port mask */
1433 mvpp2_prs_tcam_port_set(&pe
, port
, add
);
1435 mvpp2_prs_hw_write(priv
, &pe
);
1438 /* Set port to promiscuous mode */
1439 static void mvpp2_prs_mac_promisc_set(struct mvpp2
*priv
, int port
, bool add
)
1441 struct mvpp2_prs_entry pe
;
1443 /* Promiscuous mode - Accept unknown packets */
1445 if (priv
->prs_shadow
[MVPP2_PE_MAC_PROMISCUOUS
].valid
) {
1446 /* Entry exist - update port only */
1447 pe
.index
= MVPP2_PE_MAC_PROMISCUOUS
;
1448 mvpp2_prs_hw_read(priv
, &pe
);
1450 /* Entry doesn't exist - create new */
1451 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
1452 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_MAC
);
1453 pe
.index
= MVPP2_PE_MAC_PROMISCUOUS
;
1455 /* Continue - set next lookup */
1456 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_DSA
);
1458 /* Set result info bits */
1459 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L2_UCAST
,
1460 MVPP2_PRS_RI_L2_CAST_MASK
);
1462 /* Shift to ethertype */
1463 mvpp2_prs_sram_shift_set(&pe
, 2 * ETH_ALEN
,
1464 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
1466 /* Mask all ports */
1467 mvpp2_prs_tcam_port_map_set(&pe
, 0);
1469 /* Update shadow table */
1470 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_MAC
);
1473 /* Update port mask */
1474 mvpp2_prs_tcam_port_set(&pe
, port
, add
);
1476 mvpp2_prs_hw_write(priv
, &pe
);
1479 /* Accept multicast */
1480 static void mvpp2_prs_mac_multi_set(struct mvpp2
*priv
, int port
, int index
,
1483 struct mvpp2_prs_entry pe
;
1484 unsigned char da_mc
;
1486 /* Ethernet multicast address first byte is
1487 * 0x01 for IPv4 and 0x33 for IPv6
1489 da_mc
= (index
== MVPP2_PE_MAC_MC_ALL
) ? 0x01 : 0x33;
1491 if (priv
->prs_shadow
[index
].valid
) {
1492 /* Entry exist - update port only */
1494 mvpp2_prs_hw_read(priv
, &pe
);
1496 /* Entry doesn't exist - create new */
1497 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
1498 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_MAC
);
1501 /* Continue - set next lookup */
1502 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_DSA
);
1504 /* Set result info bits */
1505 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L2_MCAST
,
1506 MVPP2_PRS_RI_L2_CAST_MASK
);
1508 /* Update tcam entry data first byte */
1509 mvpp2_prs_tcam_data_byte_set(&pe
, 0, da_mc
, 0xff);
1511 /* Shift to ethertype */
1512 mvpp2_prs_sram_shift_set(&pe
, 2 * ETH_ALEN
,
1513 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
1515 /* Mask all ports */
1516 mvpp2_prs_tcam_port_map_set(&pe
, 0);
1518 /* Update shadow table */
1519 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_MAC
);
1522 /* Update port mask */
1523 mvpp2_prs_tcam_port_set(&pe
, port
, add
);
1525 mvpp2_prs_hw_write(priv
, &pe
);
1528 /* Set entry for dsa packets */
1529 static void mvpp2_prs_dsa_tag_set(struct mvpp2
*priv
, int port
, bool add
,
1530 bool tagged
, bool extend
)
1532 struct mvpp2_prs_entry pe
;
1536 tid
= tagged
? MVPP2_PE_EDSA_TAGGED
: MVPP2_PE_EDSA_UNTAGGED
;
1539 tid
= tagged
? MVPP2_PE_DSA_TAGGED
: MVPP2_PE_DSA_UNTAGGED
;
1543 if (priv
->prs_shadow
[tid
].valid
) {
1544 /* Entry exist - update port only */
1546 mvpp2_prs_hw_read(priv
, &pe
);
1548 /* Entry doesn't exist - create new */
1549 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
1550 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_DSA
);
1553 /* Shift 4 bytes if DSA tag or 8 bytes in case of EDSA tag*/
1554 mvpp2_prs_sram_shift_set(&pe
, shift
,
1555 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
1557 /* Update shadow table */
1558 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_DSA
);
1561 /* Set tagged bit in DSA tag */
1562 mvpp2_prs_tcam_data_byte_set(&pe
, 0,
1563 MVPP2_PRS_TCAM_DSA_TAGGED_BIT
,
1564 MVPP2_PRS_TCAM_DSA_TAGGED_BIT
);
1565 /* Clear all ai bits for next iteration */
1566 mvpp2_prs_sram_ai_update(&pe
, 0,
1567 MVPP2_PRS_SRAM_AI_MASK
);
1568 /* If packet is tagged continue check vlans */
1569 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_VLAN
);
1571 /* Set result info bits to 'no vlans' */
1572 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_VLAN_NONE
,
1573 MVPP2_PRS_RI_VLAN_MASK
);
1574 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_L2
);
1577 /* Mask all ports */
1578 mvpp2_prs_tcam_port_map_set(&pe
, 0);
1581 /* Update port mask */
1582 mvpp2_prs_tcam_port_set(&pe
, port
, add
);
1584 mvpp2_prs_hw_write(priv
, &pe
);
1587 /* Set entry for dsa ethertype */
1588 static void mvpp2_prs_dsa_tag_ethertype_set(struct mvpp2
*priv
, int port
,
1589 bool add
, bool tagged
, bool extend
)
1591 struct mvpp2_prs_entry pe
;
1592 int tid
, shift
, port_mask
;
1595 tid
= tagged
? MVPP2_PE_ETYPE_EDSA_TAGGED
:
1596 MVPP2_PE_ETYPE_EDSA_UNTAGGED
;
1600 tid
= tagged
? MVPP2_PE_ETYPE_DSA_TAGGED
:
1601 MVPP2_PE_ETYPE_DSA_UNTAGGED
;
1602 port_mask
= MVPP2_PRS_PORT_MASK
;
1606 if (priv
->prs_shadow
[tid
].valid
) {
1607 /* Entry exist - update port only */
1609 mvpp2_prs_hw_read(priv
, &pe
);
1611 /* Entry doesn't exist - create new */
1612 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
1613 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_DSA
);
1617 mvpp2_prs_match_etype(&pe
, 0, ETH_P_EDSA
);
1618 mvpp2_prs_match_etype(&pe
, 2, 0);
1620 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_DSA_MASK
,
1621 MVPP2_PRS_RI_DSA_MASK
);
1622 /* Shift ethertype + 2 byte reserved + tag*/
1623 mvpp2_prs_sram_shift_set(&pe
, 2 + MVPP2_ETH_TYPE_LEN
+ shift
,
1624 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
1626 /* Update shadow table */
1627 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_DSA
);
1630 /* Set tagged bit in DSA tag */
1631 mvpp2_prs_tcam_data_byte_set(&pe
,
1632 MVPP2_ETH_TYPE_LEN
+ 2 + 3,
1633 MVPP2_PRS_TCAM_DSA_TAGGED_BIT
,
1634 MVPP2_PRS_TCAM_DSA_TAGGED_BIT
);
1635 /* Clear all ai bits for next iteration */
1636 mvpp2_prs_sram_ai_update(&pe
, 0,
1637 MVPP2_PRS_SRAM_AI_MASK
);
1638 /* If packet is tagged continue check vlans */
1639 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_VLAN
);
1641 /* Set result info bits to 'no vlans' */
1642 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_VLAN_NONE
,
1643 MVPP2_PRS_RI_VLAN_MASK
);
1644 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_L2
);
1646 /* Mask/unmask all ports, depending on dsa type */
1647 mvpp2_prs_tcam_port_map_set(&pe
, port_mask
);
1650 /* Update port mask */
1651 mvpp2_prs_tcam_port_set(&pe
, port
, add
);
1653 mvpp2_prs_hw_write(priv
, &pe
);
1656 /* Search for existing single/triple vlan entry */
1657 static struct mvpp2_prs_entry
*mvpp2_prs_vlan_find(struct mvpp2
*priv
,
1658 unsigned short tpid
, int ai
)
1660 struct mvpp2_prs_entry
*pe
;
1663 pe
= kzalloc(sizeof(*pe
), GFP_KERNEL
);
1666 mvpp2_prs_tcam_lu_set(pe
, MVPP2_PRS_LU_VLAN
);
1668 /* Go through the all entries with MVPP2_PRS_LU_VLAN */
1669 for (tid
= MVPP2_PE_FIRST_FREE_TID
;
1670 tid
<= MVPP2_PE_LAST_FREE_TID
; tid
++) {
1671 unsigned int ri_bits
, ai_bits
;
1674 if (!priv
->prs_shadow
[tid
].valid
||
1675 priv
->prs_shadow
[tid
].lu
!= MVPP2_PRS_LU_VLAN
)
1680 mvpp2_prs_hw_read(priv
, pe
);
1681 match
= mvpp2_prs_tcam_data_cmp(pe
, 0, swab16(tpid
));
1686 ri_bits
= mvpp2_prs_sram_ri_get(pe
);
1687 ri_bits
&= MVPP2_PRS_RI_VLAN_MASK
;
1689 /* Get current ai value from tcam */
1690 ai_bits
= mvpp2_prs_tcam_ai_get(pe
);
1691 /* Clear double vlan bit */
1692 ai_bits
&= ~MVPP2_PRS_DBL_VLAN_AI_BIT
;
1697 if (ri_bits
== MVPP2_PRS_RI_VLAN_SINGLE
||
1698 ri_bits
== MVPP2_PRS_RI_VLAN_TRIPLE
)
1706 /* Add/update single/triple vlan entry */
1707 static int mvpp2_prs_vlan_add(struct mvpp2
*priv
, unsigned short tpid
, int ai
,
1708 unsigned int port_map
)
1710 struct mvpp2_prs_entry
*pe
;
1714 pe
= mvpp2_prs_vlan_find(priv
, tpid
, ai
);
1717 /* Create new tcam entry */
1718 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_LAST_FREE_TID
,
1719 MVPP2_PE_FIRST_FREE_TID
);
1723 pe
= kzalloc(sizeof(*pe
), GFP_KERNEL
);
1727 /* Get last double vlan tid */
1728 for (tid_aux
= MVPP2_PE_LAST_FREE_TID
;
1729 tid_aux
>= MVPP2_PE_FIRST_FREE_TID
; tid_aux
--) {
1730 unsigned int ri_bits
;
1732 if (!priv
->prs_shadow
[tid_aux
].valid
||
1733 priv
->prs_shadow
[tid_aux
].lu
!= MVPP2_PRS_LU_VLAN
)
1736 pe
->index
= tid_aux
;
1737 mvpp2_prs_hw_read(priv
, pe
);
1738 ri_bits
= mvpp2_prs_sram_ri_get(pe
);
1739 if ((ri_bits
& MVPP2_PRS_RI_VLAN_MASK
) ==
1740 MVPP2_PRS_RI_VLAN_DOUBLE
)
1744 if (tid
<= tid_aux
) {
1749 memset(pe
, 0 , sizeof(struct mvpp2_prs_entry
));
1750 mvpp2_prs_tcam_lu_set(pe
, MVPP2_PRS_LU_VLAN
);
1753 mvpp2_prs_match_etype(pe
, 0, tpid
);
1755 mvpp2_prs_sram_next_lu_set(pe
, MVPP2_PRS_LU_L2
);
1756 /* Shift 4 bytes - skip 1 vlan tag */
1757 mvpp2_prs_sram_shift_set(pe
, MVPP2_VLAN_TAG_LEN
,
1758 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
1759 /* Clear all ai bits for next iteration */
1760 mvpp2_prs_sram_ai_update(pe
, 0, MVPP2_PRS_SRAM_AI_MASK
);
1762 if (ai
== MVPP2_PRS_SINGLE_VLAN_AI
) {
1763 mvpp2_prs_sram_ri_update(pe
, MVPP2_PRS_RI_VLAN_SINGLE
,
1764 MVPP2_PRS_RI_VLAN_MASK
);
1766 ai
|= MVPP2_PRS_DBL_VLAN_AI_BIT
;
1767 mvpp2_prs_sram_ri_update(pe
, MVPP2_PRS_RI_VLAN_TRIPLE
,
1768 MVPP2_PRS_RI_VLAN_MASK
);
1770 mvpp2_prs_tcam_ai_update(pe
, ai
, MVPP2_PRS_SRAM_AI_MASK
);
1772 mvpp2_prs_shadow_set(priv
, pe
->index
, MVPP2_PRS_LU_VLAN
);
1774 /* Update ports' mask */
1775 mvpp2_prs_tcam_port_map_set(pe
, port_map
);
1777 mvpp2_prs_hw_write(priv
, pe
);
1785 /* Get first free double vlan ai number */
1786 static int mvpp2_prs_double_vlan_ai_free_get(struct mvpp2
*priv
)
1790 for (i
= 1; i
< MVPP2_PRS_DBL_VLANS_MAX
; i
++) {
1791 if (!priv
->prs_double_vlans
[i
])
1798 /* Search for existing double vlan entry */
1799 static struct mvpp2_prs_entry
*mvpp2_prs_double_vlan_find(struct mvpp2
*priv
,
1800 unsigned short tpid1
,
1801 unsigned short tpid2
)
1803 struct mvpp2_prs_entry
*pe
;
1806 pe
= kzalloc(sizeof(*pe
), GFP_KERNEL
);
1809 mvpp2_prs_tcam_lu_set(pe
, MVPP2_PRS_LU_VLAN
);
1811 /* Go through the all entries with MVPP2_PRS_LU_VLAN */
1812 for (tid
= MVPP2_PE_FIRST_FREE_TID
;
1813 tid
<= MVPP2_PE_LAST_FREE_TID
; tid
++) {
1814 unsigned int ri_mask
;
1817 if (!priv
->prs_shadow
[tid
].valid
||
1818 priv
->prs_shadow
[tid
].lu
!= MVPP2_PRS_LU_VLAN
)
1822 mvpp2_prs_hw_read(priv
, pe
);
1824 match
= mvpp2_prs_tcam_data_cmp(pe
, 0, swab16(tpid1
))
1825 && mvpp2_prs_tcam_data_cmp(pe
, 4, swab16(tpid2
));
1830 ri_mask
= mvpp2_prs_sram_ri_get(pe
) & MVPP2_PRS_RI_VLAN_MASK
;
1831 if (ri_mask
== MVPP2_PRS_RI_VLAN_DOUBLE
)
1839 /* Add or update double vlan entry */
1840 static int mvpp2_prs_double_vlan_add(struct mvpp2
*priv
, unsigned short tpid1
,
1841 unsigned short tpid2
,
1842 unsigned int port_map
)
1844 struct mvpp2_prs_entry
*pe
;
1845 int tid_aux
, tid
, ai
, ret
= 0;
1847 pe
= mvpp2_prs_double_vlan_find(priv
, tpid1
, tpid2
);
1850 /* Create new tcam entry */
1851 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
1852 MVPP2_PE_LAST_FREE_TID
);
1856 pe
= kzalloc(sizeof(*pe
), GFP_KERNEL
);
1860 /* Set ai value for new double vlan entry */
1861 ai
= mvpp2_prs_double_vlan_ai_free_get(priv
);
1867 /* Get first single/triple vlan tid */
1868 for (tid_aux
= MVPP2_PE_FIRST_FREE_TID
;
1869 tid_aux
<= MVPP2_PE_LAST_FREE_TID
; tid_aux
++) {
1870 unsigned int ri_bits
;
1872 if (!priv
->prs_shadow
[tid_aux
].valid
||
1873 priv
->prs_shadow
[tid_aux
].lu
!= MVPP2_PRS_LU_VLAN
)
1876 pe
->index
= tid_aux
;
1877 mvpp2_prs_hw_read(priv
, pe
);
1878 ri_bits
= mvpp2_prs_sram_ri_get(pe
);
1879 ri_bits
&= MVPP2_PRS_RI_VLAN_MASK
;
1880 if (ri_bits
== MVPP2_PRS_RI_VLAN_SINGLE
||
1881 ri_bits
== MVPP2_PRS_RI_VLAN_TRIPLE
)
1885 if (tid
>= tid_aux
) {
1890 memset(pe
, 0, sizeof(struct mvpp2_prs_entry
));
1891 mvpp2_prs_tcam_lu_set(pe
, MVPP2_PRS_LU_VLAN
);
1894 priv
->prs_double_vlans
[ai
] = true;
1896 mvpp2_prs_match_etype(pe
, 0, tpid1
);
1897 mvpp2_prs_match_etype(pe
, 4, tpid2
);
1899 mvpp2_prs_sram_next_lu_set(pe
, MVPP2_PRS_LU_VLAN
);
1900 /* Shift 8 bytes - skip 2 vlan tags */
1901 mvpp2_prs_sram_shift_set(pe
, 2 * MVPP2_VLAN_TAG_LEN
,
1902 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
1903 mvpp2_prs_sram_ri_update(pe
, MVPP2_PRS_RI_VLAN_DOUBLE
,
1904 MVPP2_PRS_RI_VLAN_MASK
);
1905 mvpp2_prs_sram_ai_update(pe
, ai
| MVPP2_PRS_DBL_VLAN_AI_BIT
,
1906 MVPP2_PRS_SRAM_AI_MASK
);
1908 mvpp2_prs_shadow_set(priv
, pe
->index
, MVPP2_PRS_LU_VLAN
);
1911 /* Update ports' mask */
1912 mvpp2_prs_tcam_port_map_set(pe
, port_map
);
1913 mvpp2_prs_hw_write(priv
, pe
);
1920 /* IPv4 header parsing for fragmentation and L4 offset */
1921 static int mvpp2_prs_ip4_proto(struct mvpp2
*priv
, unsigned short proto
,
1922 unsigned int ri
, unsigned int ri_mask
)
1924 struct mvpp2_prs_entry pe
;
1927 if ((proto
!= IPPROTO_TCP
) && (proto
!= IPPROTO_UDP
) &&
1928 (proto
!= IPPROTO_IGMP
))
1931 /* Fragmented packet */
1932 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
1933 MVPP2_PE_LAST_FREE_TID
);
1937 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
1938 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_IP4
);
1941 /* Set next lu to IPv4 */
1942 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_IP4
);
1943 mvpp2_prs_sram_shift_set(&pe
, 12, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
1945 mvpp2_prs_sram_offset_set(&pe
, MVPP2_PRS_SRAM_UDF_TYPE_L4
,
1946 sizeof(struct iphdr
) - 4,
1947 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD
);
1948 mvpp2_prs_sram_ai_update(&pe
, MVPP2_PRS_IPV4_DIP_AI_BIT
,
1949 MVPP2_PRS_IPV4_DIP_AI_BIT
);
1950 mvpp2_prs_sram_ri_update(&pe
, ri
| MVPP2_PRS_RI_IP_FRAG_MASK
,
1951 ri_mask
| MVPP2_PRS_RI_IP_FRAG_MASK
);
1953 mvpp2_prs_tcam_data_byte_set(&pe
, 5, proto
, MVPP2_PRS_TCAM_PROTO_MASK
);
1954 mvpp2_prs_tcam_ai_update(&pe
, 0, MVPP2_PRS_IPV4_DIP_AI_BIT
);
1955 /* Unmask all ports */
1956 mvpp2_prs_tcam_port_map_set(&pe
, MVPP2_PRS_PORT_MASK
);
1958 /* Update shadow table and hw entry */
1959 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_IP4
);
1960 mvpp2_prs_hw_write(priv
, &pe
);
1962 /* Not fragmented packet */
1963 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
1964 MVPP2_PE_LAST_FREE_TID
);
1969 /* Clear ri before updating */
1970 pe
.sram
.word
[MVPP2_PRS_SRAM_RI_WORD
] = 0x0;
1971 pe
.sram
.word
[MVPP2_PRS_SRAM_RI_CTRL_WORD
] = 0x0;
1972 mvpp2_prs_sram_ri_update(&pe
, ri
, ri_mask
);
1974 mvpp2_prs_tcam_data_byte_set(&pe
, 2, 0x00, MVPP2_PRS_TCAM_PROTO_MASK_L
);
1975 mvpp2_prs_tcam_data_byte_set(&pe
, 3, 0x00, MVPP2_PRS_TCAM_PROTO_MASK
);
1977 /* Update shadow table and hw entry */
1978 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_IP4
);
1979 mvpp2_prs_hw_write(priv
, &pe
);
1984 /* IPv4 L3 multicast or broadcast */
1985 static int mvpp2_prs_ip4_cast(struct mvpp2
*priv
, unsigned short l3_cast
)
1987 struct mvpp2_prs_entry pe
;
1990 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
1991 MVPP2_PE_LAST_FREE_TID
);
1995 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
1996 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_IP4
);
2000 case MVPP2_PRS_L3_MULTI_CAST
:
2001 mvpp2_prs_tcam_data_byte_set(&pe
, 0, MVPP2_PRS_IPV4_MC
,
2002 MVPP2_PRS_IPV4_MC_MASK
);
2003 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L3_MCAST
,
2004 MVPP2_PRS_RI_L3_ADDR_MASK
);
2006 case MVPP2_PRS_L3_BROAD_CAST
:
2007 mask
= MVPP2_PRS_IPV4_BC_MASK
;
2008 mvpp2_prs_tcam_data_byte_set(&pe
, 0, mask
, mask
);
2009 mvpp2_prs_tcam_data_byte_set(&pe
, 1, mask
, mask
);
2010 mvpp2_prs_tcam_data_byte_set(&pe
, 2, mask
, mask
);
2011 mvpp2_prs_tcam_data_byte_set(&pe
, 3, mask
, mask
);
2012 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L3_BCAST
,
2013 MVPP2_PRS_RI_L3_ADDR_MASK
);
2019 /* Finished: go to flowid generation */
2020 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_FLOWS
);
2021 mvpp2_prs_sram_bits_set(&pe
, MVPP2_PRS_SRAM_LU_GEN_BIT
, 1);
2023 mvpp2_prs_tcam_ai_update(&pe
, MVPP2_PRS_IPV4_DIP_AI_BIT
,
2024 MVPP2_PRS_IPV4_DIP_AI_BIT
);
2025 /* Unmask all ports */
2026 mvpp2_prs_tcam_port_map_set(&pe
, MVPP2_PRS_PORT_MASK
);
2028 /* Update shadow table and hw entry */
2029 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_IP4
);
2030 mvpp2_prs_hw_write(priv
, &pe
);
2035 /* Set entries for protocols over IPv6 */
2036 static int mvpp2_prs_ip6_proto(struct mvpp2
*priv
, unsigned short proto
,
2037 unsigned int ri
, unsigned int ri_mask
)
2039 struct mvpp2_prs_entry pe
;
2042 if ((proto
!= IPPROTO_TCP
) && (proto
!= IPPROTO_UDP
) &&
2043 (proto
!= IPPROTO_ICMPV6
) && (proto
!= IPPROTO_IPIP
))
2046 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
2047 MVPP2_PE_LAST_FREE_TID
);
2051 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2052 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_IP6
);
2055 /* Finished: go to flowid generation */
2056 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_FLOWS
);
2057 mvpp2_prs_sram_bits_set(&pe
, MVPP2_PRS_SRAM_LU_GEN_BIT
, 1);
2058 mvpp2_prs_sram_ri_update(&pe
, ri
, ri_mask
);
2059 mvpp2_prs_sram_offset_set(&pe
, MVPP2_PRS_SRAM_UDF_TYPE_L4
,
2060 sizeof(struct ipv6hdr
) - 6,
2061 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD
);
2063 mvpp2_prs_tcam_data_byte_set(&pe
, 0, proto
, MVPP2_PRS_TCAM_PROTO_MASK
);
2064 mvpp2_prs_tcam_ai_update(&pe
, MVPP2_PRS_IPV6_NO_EXT_AI_BIT
,
2065 MVPP2_PRS_IPV6_NO_EXT_AI_BIT
);
2066 /* Unmask all ports */
2067 mvpp2_prs_tcam_port_map_set(&pe
, MVPP2_PRS_PORT_MASK
);
2070 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_IP6
);
2071 mvpp2_prs_hw_write(priv
, &pe
);
2076 /* IPv6 L3 multicast entry */
2077 static int mvpp2_prs_ip6_cast(struct mvpp2
*priv
, unsigned short l3_cast
)
2079 struct mvpp2_prs_entry pe
;
2082 if (l3_cast
!= MVPP2_PRS_L3_MULTI_CAST
)
2085 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
2086 MVPP2_PE_LAST_FREE_TID
);
2090 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2091 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_IP6
);
2094 /* Finished: go to flowid generation */
2095 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_IP6
);
2096 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L3_MCAST
,
2097 MVPP2_PRS_RI_L3_ADDR_MASK
);
2098 mvpp2_prs_sram_ai_update(&pe
, MVPP2_PRS_IPV6_NO_EXT_AI_BIT
,
2099 MVPP2_PRS_IPV6_NO_EXT_AI_BIT
);
2100 /* Shift back to IPv6 NH */
2101 mvpp2_prs_sram_shift_set(&pe
, -18, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
2103 mvpp2_prs_tcam_data_byte_set(&pe
, 0, MVPP2_PRS_IPV6_MC
,
2104 MVPP2_PRS_IPV6_MC_MASK
);
2105 mvpp2_prs_tcam_ai_update(&pe
, 0, MVPP2_PRS_IPV6_NO_EXT_AI_BIT
);
2106 /* Unmask all ports */
2107 mvpp2_prs_tcam_port_map_set(&pe
, MVPP2_PRS_PORT_MASK
);
2109 /* Update shadow table and hw entry */
2110 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_IP6
);
2111 mvpp2_prs_hw_write(priv
, &pe
);
2116 /* Parser per-port initialization */
2117 static void mvpp2_prs_hw_port_init(struct mvpp2
*priv
, int port
, int lu_first
,
2118 int lu_max
, int offset
)
2123 val
= mvpp2_read(priv
, MVPP2_PRS_INIT_LOOKUP_REG
);
2124 val
&= ~MVPP2_PRS_PORT_LU_MASK(port
);
2125 val
|= MVPP2_PRS_PORT_LU_VAL(port
, lu_first
);
2126 mvpp2_write(priv
, MVPP2_PRS_INIT_LOOKUP_REG
, val
);
2128 /* Set maximum number of loops for packet received from port */
2129 val
= mvpp2_read(priv
, MVPP2_PRS_MAX_LOOP_REG(port
));
2130 val
&= ~MVPP2_PRS_MAX_LOOP_MASK(port
);
2131 val
|= MVPP2_PRS_MAX_LOOP_VAL(port
, lu_max
);
2132 mvpp2_write(priv
, MVPP2_PRS_MAX_LOOP_REG(port
), val
);
2134 /* Set initial offset for packet header extraction for the first
2137 val
= mvpp2_read(priv
, MVPP2_PRS_INIT_OFFS_REG(port
));
2138 val
&= ~MVPP2_PRS_INIT_OFF_MASK(port
);
2139 val
|= MVPP2_PRS_INIT_OFF_VAL(port
, offset
);
2140 mvpp2_write(priv
, MVPP2_PRS_INIT_OFFS_REG(port
), val
);
2143 /* Default flow entries initialization for all ports */
2144 static void mvpp2_prs_def_flow_init(struct mvpp2
*priv
)
2146 struct mvpp2_prs_entry pe
;
2149 for (port
= 0; port
< MVPP2_MAX_PORTS
; port
++) {
2150 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2151 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_FLOWS
);
2152 pe
.index
= MVPP2_PE_FIRST_DEFAULT_FLOW
- port
;
2154 /* Mask all ports */
2155 mvpp2_prs_tcam_port_map_set(&pe
, 0);
2158 mvpp2_prs_sram_ai_update(&pe
, port
, MVPP2_PRS_FLOW_ID_MASK
);
2159 mvpp2_prs_sram_bits_set(&pe
, MVPP2_PRS_SRAM_LU_DONE_BIT
, 1);
2161 /* Update shadow table and hw entry */
2162 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_FLOWS
);
2163 mvpp2_prs_hw_write(priv
, &pe
);
2167 /* Set default entry for Marvell Header field */
2168 static void mvpp2_prs_mh_init(struct mvpp2
*priv
)
2170 struct mvpp2_prs_entry pe
;
2172 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2174 pe
.index
= MVPP2_PE_MH_DEFAULT
;
2175 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_MH
);
2176 mvpp2_prs_sram_shift_set(&pe
, MVPP2_MH_SIZE
,
2177 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
2178 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_MAC
);
2180 /* Unmask all ports */
2181 mvpp2_prs_tcam_port_map_set(&pe
, MVPP2_PRS_PORT_MASK
);
2183 /* Update shadow table and hw entry */
2184 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_MH
);
2185 mvpp2_prs_hw_write(priv
, &pe
);
2188 /* Set default entires (place holder) for promiscuous, non-promiscuous and
2189 * multicast MAC addresses
2191 static void mvpp2_prs_mac_init(struct mvpp2
*priv
)
2193 struct mvpp2_prs_entry pe
;
2195 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2197 /* Non-promiscuous mode for all ports - DROP unknown packets */
2198 pe
.index
= MVPP2_PE_MAC_NON_PROMISCUOUS
;
2199 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_MAC
);
2201 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_DROP_MASK
,
2202 MVPP2_PRS_RI_DROP_MASK
);
2203 mvpp2_prs_sram_bits_set(&pe
, MVPP2_PRS_SRAM_LU_GEN_BIT
, 1);
2204 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_FLOWS
);
2206 /* Unmask all ports */
2207 mvpp2_prs_tcam_port_map_set(&pe
, MVPP2_PRS_PORT_MASK
);
2209 /* Update shadow table and hw entry */
2210 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_MAC
);
2211 mvpp2_prs_hw_write(priv
, &pe
);
2213 /* place holders only - no ports */
2214 mvpp2_prs_mac_drop_all_set(priv
, 0, false);
2215 mvpp2_prs_mac_promisc_set(priv
, 0, false);
2216 mvpp2_prs_mac_multi_set(priv
, MVPP2_PE_MAC_MC_ALL
, 0, false);
2217 mvpp2_prs_mac_multi_set(priv
, MVPP2_PE_MAC_MC_IP6
, 0, false);
2220 /* Set default entries for various types of dsa packets */
2221 static void mvpp2_prs_dsa_init(struct mvpp2
*priv
)
2223 struct mvpp2_prs_entry pe
;
2225 /* None tagged EDSA entry - place holder */
2226 mvpp2_prs_dsa_tag_set(priv
, 0, false, MVPP2_PRS_UNTAGGED
,
2229 /* Tagged EDSA entry - place holder */
2230 mvpp2_prs_dsa_tag_set(priv
, 0, false, MVPP2_PRS_TAGGED
, MVPP2_PRS_EDSA
);
2232 /* None tagged DSA entry - place holder */
2233 mvpp2_prs_dsa_tag_set(priv
, 0, false, MVPP2_PRS_UNTAGGED
,
2236 /* Tagged DSA entry - place holder */
2237 mvpp2_prs_dsa_tag_set(priv
, 0, false, MVPP2_PRS_TAGGED
, MVPP2_PRS_DSA
);
2239 /* None tagged EDSA ethertype entry - place holder*/
2240 mvpp2_prs_dsa_tag_ethertype_set(priv
, 0, false,
2241 MVPP2_PRS_UNTAGGED
, MVPP2_PRS_EDSA
);
2243 /* Tagged EDSA ethertype entry - place holder*/
2244 mvpp2_prs_dsa_tag_ethertype_set(priv
, 0, false,
2245 MVPP2_PRS_TAGGED
, MVPP2_PRS_EDSA
);
2247 /* None tagged DSA ethertype entry */
2248 mvpp2_prs_dsa_tag_ethertype_set(priv
, 0, true,
2249 MVPP2_PRS_UNTAGGED
, MVPP2_PRS_DSA
);
2251 /* Tagged DSA ethertype entry */
2252 mvpp2_prs_dsa_tag_ethertype_set(priv
, 0, true,
2253 MVPP2_PRS_TAGGED
, MVPP2_PRS_DSA
);
2255 /* Set default entry, in case DSA or EDSA tag not found */
2256 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2257 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_DSA
);
2258 pe
.index
= MVPP2_PE_DSA_DEFAULT
;
2259 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_VLAN
);
2262 mvpp2_prs_sram_shift_set(&pe
, 0, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
2263 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_MAC
);
2265 /* Clear all sram ai bits for next iteration */
2266 mvpp2_prs_sram_ai_update(&pe
, 0, MVPP2_PRS_SRAM_AI_MASK
);
2268 /* Unmask all ports */
2269 mvpp2_prs_tcam_port_map_set(&pe
, MVPP2_PRS_PORT_MASK
);
2271 mvpp2_prs_hw_write(priv
, &pe
);
2274 /* Match basic ethertypes */
2275 static int mvpp2_prs_etype_init(struct mvpp2
*priv
)
2277 struct mvpp2_prs_entry pe
;
2280 /* Ethertype: PPPoE */
2281 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
2282 MVPP2_PE_LAST_FREE_TID
);
2286 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2287 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_L2
);
2290 mvpp2_prs_match_etype(&pe
, 0, ETH_P_PPP_SES
);
2292 mvpp2_prs_sram_shift_set(&pe
, MVPP2_PPPOE_HDR_SIZE
,
2293 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
2294 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_PPPOE
);
2295 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_PPPOE_MASK
,
2296 MVPP2_PRS_RI_PPPOE_MASK
);
2298 /* Update shadow table and hw entry */
2299 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_L2
);
2300 priv
->prs_shadow
[pe
.index
].udf
= MVPP2_PRS_UDF_L2_DEF
;
2301 priv
->prs_shadow
[pe
.index
].finish
= false;
2302 mvpp2_prs_shadow_ri_set(priv
, pe
.index
, MVPP2_PRS_RI_PPPOE_MASK
,
2303 MVPP2_PRS_RI_PPPOE_MASK
);
2304 mvpp2_prs_hw_write(priv
, &pe
);
2306 /* Ethertype: ARP */
2307 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
2308 MVPP2_PE_LAST_FREE_TID
);
2312 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2313 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_L2
);
2316 mvpp2_prs_match_etype(&pe
, 0, ETH_P_ARP
);
2318 /* Generate flow in the next iteration*/
2319 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_FLOWS
);
2320 mvpp2_prs_sram_bits_set(&pe
, MVPP2_PRS_SRAM_LU_GEN_BIT
, 1);
2321 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L3_ARP
,
2322 MVPP2_PRS_RI_L3_PROTO_MASK
);
2324 mvpp2_prs_sram_offset_set(&pe
, MVPP2_PRS_SRAM_UDF_TYPE_L3
,
2326 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD
);
2328 /* Update shadow table and hw entry */
2329 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_L2
);
2330 priv
->prs_shadow
[pe
.index
].udf
= MVPP2_PRS_UDF_L2_DEF
;
2331 priv
->prs_shadow
[pe
.index
].finish
= true;
2332 mvpp2_prs_shadow_ri_set(priv
, pe
.index
, MVPP2_PRS_RI_L3_ARP
,
2333 MVPP2_PRS_RI_L3_PROTO_MASK
);
2334 mvpp2_prs_hw_write(priv
, &pe
);
2336 /* Ethertype: LBTD */
2337 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
2338 MVPP2_PE_LAST_FREE_TID
);
2342 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2343 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_L2
);
2346 mvpp2_prs_match_etype(&pe
, 0, MVPP2_IP_LBDT_TYPE
);
2348 /* Generate flow in the next iteration*/
2349 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_FLOWS
);
2350 mvpp2_prs_sram_bits_set(&pe
, MVPP2_PRS_SRAM_LU_GEN_BIT
, 1);
2351 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_CPU_CODE_RX_SPEC
|
2352 MVPP2_PRS_RI_UDF3_RX_SPECIAL
,
2353 MVPP2_PRS_RI_CPU_CODE_MASK
|
2354 MVPP2_PRS_RI_UDF3_MASK
);
2356 mvpp2_prs_sram_offset_set(&pe
, MVPP2_PRS_SRAM_UDF_TYPE_L3
,
2358 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD
);
2360 /* Update shadow table and hw entry */
2361 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_L2
);
2362 priv
->prs_shadow
[pe
.index
].udf
= MVPP2_PRS_UDF_L2_DEF
;
2363 priv
->prs_shadow
[pe
.index
].finish
= true;
2364 mvpp2_prs_shadow_ri_set(priv
, pe
.index
, MVPP2_PRS_RI_CPU_CODE_RX_SPEC
|
2365 MVPP2_PRS_RI_UDF3_RX_SPECIAL
,
2366 MVPP2_PRS_RI_CPU_CODE_MASK
|
2367 MVPP2_PRS_RI_UDF3_MASK
);
2368 mvpp2_prs_hw_write(priv
, &pe
);
2370 /* Ethertype: IPv4 without options */
2371 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
2372 MVPP2_PE_LAST_FREE_TID
);
2376 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2377 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_L2
);
2380 mvpp2_prs_match_etype(&pe
, 0, ETH_P_IP
);
2381 mvpp2_prs_tcam_data_byte_set(&pe
, MVPP2_ETH_TYPE_LEN
,
2382 MVPP2_PRS_IPV4_HEAD
| MVPP2_PRS_IPV4_IHL
,
2383 MVPP2_PRS_IPV4_HEAD_MASK
|
2384 MVPP2_PRS_IPV4_IHL_MASK
);
2386 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_IP4
);
2387 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L3_IP4
,
2388 MVPP2_PRS_RI_L3_PROTO_MASK
);
2389 /* Skip eth_type + 4 bytes of IP header */
2390 mvpp2_prs_sram_shift_set(&pe
, MVPP2_ETH_TYPE_LEN
+ 4,
2391 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
2393 mvpp2_prs_sram_offset_set(&pe
, MVPP2_PRS_SRAM_UDF_TYPE_L3
,
2395 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD
);
2397 /* Update shadow table and hw entry */
2398 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_L2
);
2399 priv
->prs_shadow
[pe
.index
].udf
= MVPP2_PRS_UDF_L2_DEF
;
2400 priv
->prs_shadow
[pe
.index
].finish
= false;
2401 mvpp2_prs_shadow_ri_set(priv
, pe
.index
, MVPP2_PRS_RI_L3_IP4
,
2402 MVPP2_PRS_RI_L3_PROTO_MASK
);
2403 mvpp2_prs_hw_write(priv
, &pe
);
2405 /* Ethertype: IPv4 with options */
2406 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
2407 MVPP2_PE_LAST_FREE_TID
);
2413 /* Clear tcam data before updating */
2414 pe
.tcam
.byte
[MVPP2_PRS_TCAM_DATA_BYTE(MVPP2_ETH_TYPE_LEN
)] = 0x0;
2415 pe
.tcam
.byte
[MVPP2_PRS_TCAM_DATA_BYTE_EN(MVPP2_ETH_TYPE_LEN
)] = 0x0;
2417 mvpp2_prs_tcam_data_byte_set(&pe
, MVPP2_ETH_TYPE_LEN
,
2418 MVPP2_PRS_IPV4_HEAD
,
2419 MVPP2_PRS_IPV4_HEAD_MASK
);
2421 /* Clear ri before updating */
2422 pe
.sram
.word
[MVPP2_PRS_SRAM_RI_WORD
] = 0x0;
2423 pe
.sram
.word
[MVPP2_PRS_SRAM_RI_CTRL_WORD
] = 0x0;
2424 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L3_IP4_OPT
,
2425 MVPP2_PRS_RI_L3_PROTO_MASK
);
2427 /* Update shadow table and hw entry */
2428 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_L2
);
2429 priv
->prs_shadow
[pe
.index
].udf
= MVPP2_PRS_UDF_L2_DEF
;
2430 priv
->prs_shadow
[pe
.index
].finish
= false;
2431 mvpp2_prs_shadow_ri_set(priv
, pe
.index
, MVPP2_PRS_RI_L3_IP4_OPT
,
2432 MVPP2_PRS_RI_L3_PROTO_MASK
);
2433 mvpp2_prs_hw_write(priv
, &pe
);
2435 /* Ethertype: IPv6 without options */
2436 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
2437 MVPP2_PE_LAST_FREE_TID
);
2441 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2442 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_L2
);
2445 mvpp2_prs_match_etype(&pe
, 0, ETH_P_IPV6
);
2447 /* Skip DIP of IPV6 header */
2448 mvpp2_prs_sram_shift_set(&pe
, MVPP2_ETH_TYPE_LEN
+ 8 +
2449 MVPP2_MAX_L3_ADDR_SIZE
,
2450 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
2451 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_IP6
);
2452 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L3_IP6
,
2453 MVPP2_PRS_RI_L3_PROTO_MASK
);
2455 mvpp2_prs_sram_offset_set(&pe
, MVPP2_PRS_SRAM_UDF_TYPE_L3
,
2457 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD
);
2459 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_L2
);
2460 priv
->prs_shadow
[pe
.index
].udf
= MVPP2_PRS_UDF_L2_DEF
;
2461 priv
->prs_shadow
[pe
.index
].finish
= false;
2462 mvpp2_prs_shadow_ri_set(priv
, pe
.index
, MVPP2_PRS_RI_L3_IP6
,
2463 MVPP2_PRS_RI_L3_PROTO_MASK
);
2464 mvpp2_prs_hw_write(priv
, &pe
);
2466 /* Default entry for MVPP2_PRS_LU_L2 - Unknown ethtype */
2467 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2468 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_L2
);
2469 pe
.index
= MVPP2_PE_ETH_TYPE_UN
;
2471 /* Unmask all ports */
2472 mvpp2_prs_tcam_port_map_set(&pe
, MVPP2_PRS_PORT_MASK
);
2474 /* Generate flow in the next iteration*/
2475 mvpp2_prs_sram_bits_set(&pe
, MVPP2_PRS_SRAM_LU_GEN_BIT
, 1);
2476 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_FLOWS
);
2477 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L3_UN
,
2478 MVPP2_PRS_RI_L3_PROTO_MASK
);
2479 /* Set L3 offset even it's unknown L3 */
2480 mvpp2_prs_sram_offset_set(&pe
, MVPP2_PRS_SRAM_UDF_TYPE_L3
,
2482 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD
);
2484 /* Update shadow table and hw entry */
2485 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_L2
);
2486 priv
->prs_shadow
[pe
.index
].udf
= MVPP2_PRS_UDF_L2_DEF
;
2487 priv
->prs_shadow
[pe
.index
].finish
= true;
2488 mvpp2_prs_shadow_ri_set(priv
, pe
.index
, MVPP2_PRS_RI_L3_UN
,
2489 MVPP2_PRS_RI_L3_PROTO_MASK
);
2490 mvpp2_prs_hw_write(priv
, &pe
);
2495 /* Configure vlan entries and detect up to 2 successive VLAN tags.
2502 static int mvpp2_prs_vlan_init(struct platform_device
*pdev
, struct mvpp2
*priv
)
2504 struct mvpp2_prs_entry pe
;
2507 priv
->prs_double_vlans
= devm_kcalloc(&pdev
->dev
, sizeof(bool),
2508 MVPP2_PRS_DBL_VLANS_MAX
,
2510 if (!priv
->prs_double_vlans
)
2513 /* Double VLAN: 0x8100, 0x88A8 */
2514 err
= mvpp2_prs_double_vlan_add(priv
, ETH_P_8021Q
, ETH_P_8021AD
,
2515 MVPP2_PRS_PORT_MASK
);
2519 /* Double VLAN: 0x8100, 0x8100 */
2520 err
= mvpp2_prs_double_vlan_add(priv
, ETH_P_8021Q
, ETH_P_8021Q
,
2521 MVPP2_PRS_PORT_MASK
);
2525 /* Single VLAN: 0x88a8 */
2526 err
= mvpp2_prs_vlan_add(priv
, ETH_P_8021AD
, MVPP2_PRS_SINGLE_VLAN_AI
,
2527 MVPP2_PRS_PORT_MASK
);
2531 /* Single VLAN: 0x8100 */
2532 err
= mvpp2_prs_vlan_add(priv
, ETH_P_8021Q
, MVPP2_PRS_SINGLE_VLAN_AI
,
2533 MVPP2_PRS_PORT_MASK
);
2537 /* Set default double vlan entry */
2538 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2539 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_VLAN
);
2540 pe
.index
= MVPP2_PE_VLAN_DBL
;
2542 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_L2
);
2543 /* Clear ai for next iterations */
2544 mvpp2_prs_sram_ai_update(&pe
, 0, MVPP2_PRS_SRAM_AI_MASK
);
2545 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_VLAN_DOUBLE
,
2546 MVPP2_PRS_RI_VLAN_MASK
);
2548 mvpp2_prs_tcam_ai_update(&pe
, MVPP2_PRS_DBL_VLAN_AI_BIT
,
2549 MVPP2_PRS_DBL_VLAN_AI_BIT
);
2550 /* Unmask all ports */
2551 mvpp2_prs_tcam_port_map_set(&pe
, MVPP2_PRS_PORT_MASK
);
2553 /* Update shadow table and hw entry */
2554 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_VLAN
);
2555 mvpp2_prs_hw_write(priv
, &pe
);
2557 /* Set default vlan none entry */
2558 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2559 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_VLAN
);
2560 pe
.index
= MVPP2_PE_VLAN_NONE
;
2562 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_L2
);
2563 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_VLAN_NONE
,
2564 MVPP2_PRS_RI_VLAN_MASK
);
2566 /* Unmask all ports */
2567 mvpp2_prs_tcam_port_map_set(&pe
, MVPP2_PRS_PORT_MASK
);
2569 /* Update shadow table and hw entry */
2570 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_VLAN
);
2571 mvpp2_prs_hw_write(priv
, &pe
);
2576 /* Set entries for PPPoE ethertype */
2577 static int mvpp2_prs_pppoe_init(struct mvpp2
*priv
)
2579 struct mvpp2_prs_entry pe
;
2582 /* IPv4 over PPPoE with options */
2583 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
2584 MVPP2_PE_LAST_FREE_TID
);
2588 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2589 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_PPPOE
);
2592 mvpp2_prs_match_etype(&pe
, 0, PPP_IP
);
2594 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_IP4
);
2595 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L3_IP4_OPT
,
2596 MVPP2_PRS_RI_L3_PROTO_MASK
);
2597 /* Skip eth_type + 4 bytes of IP header */
2598 mvpp2_prs_sram_shift_set(&pe
, MVPP2_ETH_TYPE_LEN
+ 4,
2599 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
2601 mvpp2_prs_sram_offset_set(&pe
, MVPP2_PRS_SRAM_UDF_TYPE_L3
,
2603 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD
);
2605 /* Update shadow table and hw entry */
2606 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_PPPOE
);
2607 mvpp2_prs_hw_write(priv
, &pe
);
2609 /* IPv4 over PPPoE without options */
2610 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
2611 MVPP2_PE_LAST_FREE_TID
);
2617 mvpp2_prs_tcam_data_byte_set(&pe
, MVPP2_ETH_TYPE_LEN
,
2618 MVPP2_PRS_IPV4_HEAD
| MVPP2_PRS_IPV4_IHL
,
2619 MVPP2_PRS_IPV4_HEAD_MASK
|
2620 MVPP2_PRS_IPV4_IHL_MASK
);
2622 /* Clear ri before updating */
2623 pe
.sram
.word
[MVPP2_PRS_SRAM_RI_WORD
] = 0x0;
2624 pe
.sram
.word
[MVPP2_PRS_SRAM_RI_CTRL_WORD
] = 0x0;
2625 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L3_IP4
,
2626 MVPP2_PRS_RI_L3_PROTO_MASK
);
2628 /* Update shadow table and hw entry */
2629 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_PPPOE
);
2630 mvpp2_prs_hw_write(priv
, &pe
);
2632 /* IPv6 over PPPoE */
2633 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
2634 MVPP2_PE_LAST_FREE_TID
);
2638 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2639 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_PPPOE
);
2642 mvpp2_prs_match_etype(&pe
, 0, PPP_IPV6
);
2644 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_IP6
);
2645 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L3_IP6
,
2646 MVPP2_PRS_RI_L3_PROTO_MASK
);
2647 /* Skip eth_type + 4 bytes of IPv6 header */
2648 mvpp2_prs_sram_shift_set(&pe
, MVPP2_ETH_TYPE_LEN
+ 4,
2649 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
2651 mvpp2_prs_sram_offset_set(&pe
, MVPP2_PRS_SRAM_UDF_TYPE_L3
,
2653 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD
);
2655 /* Update shadow table and hw entry */
2656 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_PPPOE
);
2657 mvpp2_prs_hw_write(priv
, &pe
);
2659 /* Non-IP over PPPoE */
2660 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
2661 MVPP2_PE_LAST_FREE_TID
);
2665 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2666 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_PPPOE
);
2669 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L3_UN
,
2670 MVPP2_PRS_RI_L3_PROTO_MASK
);
2672 /* Finished: go to flowid generation */
2673 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_FLOWS
);
2674 mvpp2_prs_sram_bits_set(&pe
, MVPP2_PRS_SRAM_LU_GEN_BIT
, 1);
2675 /* Set L3 offset even if it's unknown L3 */
2676 mvpp2_prs_sram_offset_set(&pe
, MVPP2_PRS_SRAM_UDF_TYPE_L3
,
2678 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD
);
2680 /* Update shadow table and hw entry */
2681 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_PPPOE
);
2682 mvpp2_prs_hw_write(priv
, &pe
);
2687 /* Initialize entries for IPv4 */
2688 static int mvpp2_prs_ip4_init(struct mvpp2
*priv
)
2690 struct mvpp2_prs_entry pe
;
2693 /* Set entries for TCP, UDP and IGMP over IPv4 */
2694 err
= mvpp2_prs_ip4_proto(priv
, IPPROTO_TCP
, MVPP2_PRS_RI_L4_TCP
,
2695 MVPP2_PRS_RI_L4_PROTO_MASK
);
2699 err
= mvpp2_prs_ip4_proto(priv
, IPPROTO_UDP
, MVPP2_PRS_RI_L4_UDP
,
2700 MVPP2_PRS_RI_L4_PROTO_MASK
);
2704 err
= mvpp2_prs_ip4_proto(priv
, IPPROTO_IGMP
,
2705 MVPP2_PRS_RI_CPU_CODE_RX_SPEC
|
2706 MVPP2_PRS_RI_UDF3_RX_SPECIAL
,
2707 MVPP2_PRS_RI_CPU_CODE_MASK
|
2708 MVPP2_PRS_RI_UDF3_MASK
);
2712 /* IPv4 Broadcast */
2713 err
= mvpp2_prs_ip4_cast(priv
, MVPP2_PRS_L3_BROAD_CAST
);
2717 /* IPv4 Multicast */
2718 err
= mvpp2_prs_ip4_cast(priv
, MVPP2_PRS_L3_MULTI_CAST
);
2722 /* Default IPv4 entry for unknown protocols */
2723 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2724 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_IP4
);
2725 pe
.index
= MVPP2_PE_IP4_PROTO_UN
;
2727 /* Set next lu to IPv4 */
2728 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_IP4
);
2729 mvpp2_prs_sram_shift_set(&pe
, 12, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
2731 mvpp2_prs_sram_offset_set(&pe
, MVPP2_PRS_SRAM_UDF_TYPE_L4
,
2732 sizeof(struct iphdr
) - 4,
2733 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD
);
2734 mvpp2_prs_sram_ai_update(&pe
, MVPP2_PRS_IPV4_DIP_AI_BIT
,
2735 MVPP2_PRS_IPV4_DIP_AI_BIT
);
2736 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L4_OTHER
,
2737 MVPP2_PRS_RI_L4_PROTO_MASK
);
2739 mvpp2_prs_tcam_ai_update(&pe
, 0, MVPP2_PRS_IPV4_DIP_AI_BIT
);
2740 /* Unmask all ports */
2741 mvpp2_prs_tcam_port_map_set(&pe
, MVPP2_PRS_PORT_MASK
);
2743 /* Update shadow table and hw entry */
2744 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_IP4
);
2745 mvpp2_prs_hw_write(priv
, &pe
);
2747 /* Default IPv4 entry for unicast address */
2748 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2749 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_IP4
);
2750 pe
.index
= MVPP2_PE_IP4_ADDR_UN
;
2752 /* Finished: go to flowid generation */
2753 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_FLOWS
);
2754 mvpp2_prs_sram_bits_set(&pe
, MVPP2_PRS_SRAM_LU_GEN_BIT
, 1);
2755 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L3_UCAST
,
2756 MVPP2_PRS_RI_L3_ADDR_MASK
);
2758 mvpp2_prs_tcam_ai_update(&pe
, MVPP2_PRS_IPV4_DIP_AI_BIT
,
2759 MVPP2_PRS_IPV4_DIP_AI_BIT
);
2760 /* Unmask all ports */
2761 mvpp2_prs_tcam_port_map_set(&pe
, MVPP2_PRS_PORT_MASK
);
2763 /* Update shadow table and hw entry */
2764 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_IP4
);
2765 mvpp2_prs_hw_write(priv
, &pe
);
2770 /* Initialize entries for IPv6 */
2771 static int mvpp2_prs_ip6_init(struct mvpp2
*priv
)
2773 struct mvpp2_prs_entry pe
;
2776 /* Set entries for TCP, UDP and ICMP over IPv6 */
2777 err
= mvpp2_prs_ip6_proto(priv
, IPPROTO_TCP
,
2778 MVPP2_PRS_RI_L4_TCP
,
2779 MVPP2_PRS_RI_L4_PROTO_MASK
);
2783 err
= mvpp2_prs_ip6_proto(priv
, IPPROTO_UDP
,
2784 MVPP2_PRS_RI_L4_UDP
,
2785 MVPP2_PRS_RI_L4_PROTO_MASK
);
2789 err
= mvpp2_prs_ip6_proto(priv
, IPPROTO_ICMPV6
,
2790 MVPP2_PRS_RI_CPU_CODE_RX_SPEC
|
2791 MVPP2_PRS_RI_UDF3_RX_SPECIAL
,
2792 MVPP2_PRS_RI_CPU_CODE_MASK
|
2793 MVPP2_PRS_RI_UDF3_MASK
);
2797 /* IPv4 is the last header. This is similar case as 6-TCP or 17-UDP */
2798 /* Result Info: UDF7=1, DS lite */
2799 err
= mvpp2_prs_ip6_proto(priv
, IPPROTO_IPIP
,
2800 MVPP2_PRS_RI_UDF7_IP6_LITE
,
2801 MVPP2_PRS_RI_UDF7_MASK
);
2805 /* IPv6 multicast */
2806 err
= mvpp2_prs_ip6_cast(priv
, MVPP2_PRS_L3_MULTI_CAST
);
2810 /* Entry for checking hop limit */
2811 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
2812 MVPP2_PE_LAST_FREE_TID
);
2816 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2817 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_IP6
);
2820 /* Finished: go to flowid generation */
2821 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_FLOWS
);
2822 mvpp2_prs_sram_bits_set(&pe
, MVPP2_PRS_SRAM_LU_GEN_BIT
, 1);
2823 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L3_UN
|
2824 MVPP2_PRS_RI_DROP_MASK
,
2825 MVPP2_PRS_RI_L3_PROTO_MASK
|
2826 MVPP2_PRS_RI_DROP_MASK
);
2828 mvpp2_prs_tcam_data_byte_set(&pe
, 1, 0x00, MVPP2_PRS_IPV6_HOP_MASK
);
2829 mvpp2_prs_tcam_ai_update(&pe
, MVPP2_PRS_IPV6_NO_EXT_AI_BIT
,
2830 MVPP2_PRS_IPV6_NO_EXT_AI_BIT
);
2832 /* Update shadow table and hw entry */
2833 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_IP4
);
2834 mvpp2_prs_hw_write(priv
, &pe
);
2836 /* Default IPv6 entry for unknown protocols */
2837 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2838 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_IP6
);
2839 pe
.index
= MVPP2_PE_IP6_PROTO_UN
;
2841 /* Finished: go to flowid generation */
2842 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_FLOWS
);
2843 mvpp2_prs_sram_bits_set(&pe
, MVPP2_PRS_SRAM_LU_GEN_BIT
, 1);
2844 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L4_OTHER
,
2845 MVPP2_PRS_RI_L4_PROTO_MASK
);
2846 /* Set L4 offset relatively to our current place */
2847 mvpp2_prs_sram_offset_set(&pe
, MVPP2_PRS_SRAM_UDF_TYPE_L4
,
2848 sizeof(struct ipv6hdr
) - 4,
2849 MVPP2_PRS_SRAM_OP_SEL_UDF_ADD
);
2851 mvpp2_prs_tcam_ai_update(&pe
, MVPP2_PRS_IPV6_NO_EXT_AI_BIT
,
2852 MVPP2_PRS_IPV6_NO_EXT_AI_BIT
);
2853 /* Unmask all ports */
2854 mvpp2_prs_tcam_port_map_set(&pe
, MVPP2_PRS_PORT_MASK
);
2856 /* Update shadow table and hw entry */
2857 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_IP4
);
2858 mvpp2_prs_hw_write(priv
, &pe
);
2860 /* Default IPv6 entry for unknown ext protocols */
2861 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2862 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_IP6
);
2863 pe
.index
= MVPP2_PE_IP6_EXT_PROTO_UN
;
2865 /* Finished: go to flowid generation */
2866 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_FLOWS
);
2867 mvpp2_prs_sram_bits_set(&pe
, MVPP2_PRS_SRAM_LU_GEN_BIT
, 1);
2868 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L4_OTHER
,
2869 MVPP2_PRS_RI_L4_PROTO_MASK
);
2871 mvpp2_prs_tcam_ai_update(&pe
, MVPP2_PRS_IPV6_EXT_AI_BIT
,
2872 MVPP2_PRS_IPV6_EXT_AI_BIT
);
2873 /* Unmask all ports */
2874 mvpp2_prs_tcam_port_map_set(&pe
, MVPP2_PRS_PORT_MASK
);
2876 /* Update shadow table and hw entry */
2877 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_IP4
);
2878 mvpp2_prs_hw_write(priv
, &pe
);
2880 /* Default IPv6 entry for unicast address */
2881 memset(&pe
, 0, sizeof(struct mvpp2_prs_entry
));
2882 mvpp2_prs_tcam_lu_set(&pe
, MVPP2_PRS_LU_IP6
);
2883 pe
.index
= MVPP2_PE_IP6_ADDR_UN
;
2885 /* Finished: go to IPv6 again */
2886 mvpp2_prs_sram_next_lu_set(&pe
, MVPP2_PRS_LU_IP6
);
2887 mvpp2_prs_sram_ri_update(&pe
, MVPP2_PRS_RI_L3_UCAST
,
2888 MVPP2_PRS_RI_L3_ADDR_MASK
);
2889 mvpp2_prs_sram_ai_update(&pe
, MVPP2_PRS_IPV6_NO_EXT_AI_BIT
,
2890 MVPP2_PRS_IPV6_NO_EXT_AI_BIT
);
2891 /* Shift back to IPV6 NH */
2892 mvpp2_prs_sram_shift_set(&pe
, -18, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
2894 mvpp2_prs_tcam_ai_update(&pe
, 0, MVPP2_PRS_IPV6_NO_EXT_AI_BIT
);
2895 /* Unmask all ports */
2896 mvpp2_prs_tcam_port_map_set(&pe
, MVPP2_PRS_PORT_MASK
);
2898 /* Update shadow table and hw entry */
2899 mvpp2_prs_shadow_set(priv
, pe
.index
, MVPP2_PRS_LU_IP6
);
2900 mvpp2_prs_hw_write(priv
, &pe
);
2905 /* Parser default initialization */
2906 static int mvpp2_prs_default_init(struct platform_device
*pdev
,
2911 /* Enable tcam table */
2912 mvpp2_write(priv
, MVPP2_PRS_TCAM_CTRL_REG
, MVPP2_PRS_TCAM_EN_MASK
);
2914 /* Clear all tcam and sram entries */
2915 for (index
= 0; index
< MVPP2_PRS_TCAM_SRAM_SIZE
; index
++) {
2916 mvpp2_write(priv
, MVPP2_PRS_TCAM_IDX_REG
, index
);
2917 for (i
= 0; i
< MVPP2_PRS_TCAM_WORDS
; i
++)
2918 mvpp2_write(priv
, MVPP2_PRS_TCAM_DATA_REG(i
), 0);
2920 mvpp2_write(priv
, MVPP2_PRS_SRAM_IDX_REG
, index
);
2921 for (i
= 0; i
< MVPP2_PRS_SRAM_WORDS
; i
++)
2922 mvpp2_write(priv
, MVPP2_PRS_SRAM_DATA_REG(i
), 0);
2925 /* Invalidate all tcam entries */
2926 for (index
= 0; index
< MVPP2_PRS_TCAM_SRAM_SIZE
; index
++)
2927 mvpp2_prs_hw_inv(priv
, index
);
2929 priv
->prs_shadow
= devm_kcalloc(&pdev
->dev
, MVPP2_PRS_TCAM_SRAM_SIZE
,
2930 sizeof(struct mvpp2_prs_shadow
),
2932 if (!priv
->prs_shadow
)
2935 /* Always start from lookup = 0 */
2936 for (index
= 0; index
< MVPP2_MAX_PORTS
; index
++)
2937 mvpp2_prs_hw_port_init(priv
, index
, MVPP2_PRS_LU_MH
,
2938 MVPP2_PRS_PORT_LU_MAX
, 0);
2940 mvpp2_prs_def_flow_init(priv
);
2942 mvpp2_prs_mh_init(priv
);
2944 mvpp2_prs_mac_init(priv
);
2946 mvpp2_prs_dsa_init(priv
);
2948 err
= mvpp2_prs_etype_init(priv
);
2952 err
= mvpp2_prs_vlan_init(pdev
, priv
);
2956 err
= mvpp2_prs_pppoe_init(priv
);
2960 err
= mvpp2_prs_ip6_init(priv
);
2964 err
= mvpp2_prs_ip4_init(priv
);
2971 /* Compare MAC DA with tcam entry data */
2972 static bool mvpp2_prs_mac_range_equals(struct mvpp2_prs_entry
*pe
,
2973 const u8
*da
, unsigned char *mask
)
2975 unsigned char tcam_byte
, tcam_mask
;
2978 for (index
= 0; index
< ETH_ALEN
; index
++) {
2979 mvpp2_prs_tcam_data_byte_get(pe
, index
, &tcam_byte
, &tcam_mask
);
2980 if (tcam_mask
!= mask
[index
])
2983 if ((tcam_mask
& tcam_byte
) != (da
[index
] & mask
[index
]))
2990 /* Find tcam entry with matched pair <MAC DA, port> */
2991 static struct mvpp2_prs_entry
*
2992 mvpp2_prs_mac_da_range_find(struct mvpp2
*priv
, int pmap
, const u8
*da
,
2993 unsigned char *mask
, int udf_type
)
2995 struct mvpp2_prs_entry
*pe
;
2998 pe
= kzalloc(sizeof(*pe
), GFP_KERNEL
);
3001 mvpp2_prs_tcam_lu_set(pe
, MVPP2_PRS_LU_MAC
);
3003 /* Go through the all entires with MVPP2_PRS_LU_MAC */
3004 for (tid
= MVPP2_PE_FIRST_FREE_TID
;
3005 tid
<= MVPP2_PE_LAST_FREE_TID
; tid
++) {
3006 unsigned int entry_pmap
;
3008 if (!priv
->prs_shadow
[tid
].valid
||
3009 (priv
->prs_shadow
[tid
].lu
!= MVPP2_PRS_LU_MAC
) ||
3010 (priv
->prs_shadow
[tid
].udf
!= udf_type
))
3014 mvpp2_prs_hw_read(priv
, pe
);
3015 entry_pmap
= mvpp2_prs_tcam_port_map_get(pe
);
3017 if (mvpp2_prs_mac_range_equals(pe
, da
, mask
) &&
3026 /* Update parser's mac da entry */
3027 static int mvpp2_prs_mac_da_accept(struct mvpp2
*priv
, int port
,
3028 const u8
*da
, bool add
)
3030 struct mvpp2_prs_entry
*pe
;
3031 unsigned int pmap
, len
, ri
;
3032 unsigned char mask
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3035 /* Scan TCAM and see if entry with this <MAC DA, port> already exist */
3036 pe
= mvpp2_prs_mac_da_range_find(priv
, (1 << port
), da
, mask
,
3037 MVPP2_PRS_UDF_MAC_DEF
);
3044 /* Create new TCAM entry */
3045 /* Find first range mac entry*/
3046 for (tid
= MVPP2_PE_FIRST_FREE_TID
;
3047 tid
<= MVPP2_PE_LAST_FREE_TID
; tid
++)
3048 if (priv
->prs_shadow
[tid
].valid
&&
3049 (priv
->prs_shadow
[tid
].lu
== MVPP2_PRS_LU_MAC
) &&
3050 (priv
->prs_shadow
[tid
].udf
==
3051 MVPP2_PRS_UDF_MAC_RANGE
))
3054 /* Go through the all entries from first to last */
3055 tid
= mvpp2_prs_tcam_first_free(priv
, MVPP2_PE_FIRST_FREE_TID
,
3060 pe
= kzalloc(sizeof(*pe
), GFP_KERNEL
);
3063 mvpp2_prs_tcam_lu_set(pe
, MVPP2_PRS_LU_MAC
);
3066 /* Mask all ports */
3067 mvpp2_prs_tcam_port_map_set(pe
, 0);
3070 /* Update port mask */
3071 mvpp2_prs_tcam_port_set(pe
, port
, add
);
3073 /* Invalidate the entry if no ports are left enabled */
3074 pmap
= mvpp2_prs_tcam_port_map_get(pe
);
3080 mvpp2_prs_hw_inv(priv
, pe
->index
);
3081 priv
->prs_shadow
[pe
->index
].valid
= false;
3086 /* Continue - set next lookup */
3087 mvpp2_prs_sram_next_lu_set(pe
, MVPP2_PRS_LU_DSA
);
3089 /* Set match on DA */
3092 mvpp2_prs_tcam_data_byte_set(pe
, len
, da
[len
], 0xff);
3094 /* Set result info bits */
3095 if (is_broadcast_ether_addr(da
))
3096 ri
= MVPP2_PRS_RI_L2_BCAST
;
3097 else if (is_multicast_ether_addr(da
))
3098 ri
= MVPP2_PRS_RI_L2_MCAST
;
3100 ri
= MVPP2_PRS_RI_L2_UCAST
| MVPP2_PRS_RI_MAC_ME_MASK
;
3102 mvpp2_prs_sram_ri_update(pe
, ri
, MVPP2_PRS_RI_L2_CAST_MASK
|
3103 MVPP2_PRS_RI_MAC_ME_MASK
);
3104 mvpp2_prs_shadow_ri_set(priv
, pe
->index
, ri
, MVPP2_PRS_RI_L2_CAST_MASK
|
3105 MVPP2_PRS_RI_MAC_ME_MASK
);
3107 /* Shift to ethertype */
3108 mvpp2_prs_sram_shift_set(pe
, 2 * ETH_ALEN
,
3109 MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD
);
3111 /* Update shadow table and hw entry */
3112 priv
->prs_shadow
[pe
->index
].udf
= MVPP2_PRS_UDF_MAC_DEF
;
3113 mvpp2_prs_shadow_set(priv
, pe
->index
, MVPP2_PRS_LU_MAC
);
3114 mvpp2_prs_hw_write(priv
, pe
);
3121 static int mvpp2_prs_update_mac_da(struct net_device
*dev
, const u8
*da
)
3123 struct mvpp2_port
*port
= netdev_priv(dev
);
3126 /* Remove old parser entry */
3127 err
= mvpp2_prs_mac_da_accept(port
->priv
, port
->id
, dev
->dev_addr
,
3132 /* Add new parser entry */
3133 err
= mvpp2_prs_mac_da_accept(port
->priv
, port
->id
, da
, true);
3137 /* Set addr in the device */
3138 ether_addr_copy(dev
->dev_addr
, da
);
3143 /* Delete all port's multicast simple (not range) entries */
3144 static void mvpp2_prs_mcast_del_all(struct mvpp2
*priv
, int port
)
3146 struct mvpp2_prs_entry pe
;
3149 for (tid
= MVPP2_PE_FIRST_FREE_TID
;
3150 tid
<= MVPP2_PE_LAST_FREE_TID
; tid
++) {
3151 unsigned char da
[ETH_ALEN
], da_mask
[ETH_ALEN
];
3153 if (!priv
->prs_shadow
[tid
].valid
||
3154 (priv
->prs_shadow
[tid
].lu
!= MVPP2_PRS_LU_MAC
) ||
3155 (priv
->prs_shadow
[tid
].udf
!= MVPP2_PRS_UDF_MAC_DEF
))
3158 /* Only simple mac entries */
3160 mvpp2_prs_hw_read(priv
, &pe
);
3162 /* Read mac addr from entry */
3163 for (index
= 0; index
< ETH_ALEN
; index
++)
3164 mvpp2_prs_tcam_data_byte_get(&pe
, index
, &da
[index
],
3167 if (is_multicast_ether_addr(da
) && !is_broadcast_ether_addr(da
))
3168 /* Delete this entry */
3169 mvpp2_prs_mac_da_accept(priv
, port
, da
, false);
3173 static int mvpp2_prs_tag_mode_set(struct mvpp2
*priv
, int port
, int type
)
3176 case MVPP2_TAG_TYPE_EDSA
:
3177 /* Add port to EDSA entries */
3178 mvpp2_prs_dsa_tag_set(priv
, port
, true,
3179 MVPP2_PRS_TAGGED
, MVPP2_PRS_EDSA
);
3180 mvpp2_prs_dsa_tag_set(priv
, port
, true,
3181 MVPP2_PRS_UNTAGGED
, MVPP2_PRS_EDSA
);
3182 /* Remove port from DSA entries */
3183 mvpp2_prs_dsa_tag_set(priv
, port
, false,
3184 MVPP2_PRS_TAGGED
, MVPP2_PRS_DSA
);
3185 mvpp2_prs_dsa_tag_set(priv
, port
, false,
3186 MVPP2_PRS_UNTAGGED
, MVPP2_PRS_DSA
);
3189 case MVPP2_TAG_TYPE_DSA
:
3190 /* Add port to DSA entries */
3191 mvpp2_prs_dsa_tag_set(priv
, port
, true,
3192 MVPP2_PRS_TAGGED
, MVPP2_PRS_DSA
);
3193 mvpp2_prs_dsa_tag_set(priv
, port
, true,
3194 MVPP2_PRS_UNTAGGED
, MVPP2_PRS_DSA
);
3195 /* Remove port from EDSA entries */
3196 mvpp2_prs_dsa_tag_set(priv
, port
, false,
3197 MVPP2_PRS_TAGGED
, MVPP2_PRS_EDSA
);
3198 mvpp2_prs_dsa_tag_set(priv
, port
, false,
3199 MVPP2_PRS_UNTAGGED
, MVPP2_PRS_EDSA
);
3202 case MVPP2_TAG_TYPE_MH
:
3203 case MVPP2_TAG_TYPE_NONE
:
3204 /* Remove port form EDSA and DSA entries */
3205 mvpp2_prs_dsa_tag_set(priv
, port
, false,
3206 MVPP2_PRS_TAGGED
, MVPP2_PRS_DSA
);
3207 mvpp2_prs_dsa_tag_set(priv
, port
, false,
3208 MVPP2_PRS_UNTAGGED
, MVPP2_PRS_DSA
);
3209 mvpp2_prs_dsa_tag_set(priv
, port
, false,
3210 MVPP2_PRS_TAGGED
, MVPP2_PRS_EDSA
);
3211 mvpp2_prs_dsa_tag_set(priv
, port
, false,
3212 MVPP2_PRS_UNTAGGED
, MVPP2_PRS_EDSA
);
3216 if ((type
< 0) || (type
> MVPP2_TAG_TYPE_EDSA
))
3223 /* Set prs flow for the port */
3224 static int mvpp2_prs_def_flow(struct mvpp2_port
*port
)
3226 struct mvpp2_prs_entry
*pe
;
3229 pe
= mvpp2_prs_flow_find(port
->priv
, port
->id
);
3231 /* Such entry not exist */
3233 /* Go through the all entires from last to first */
3234 tid
= mvpp2_prs_tcam_first_free(port
->priv
,
3235 MVPP2_PE_LAST_FREE_TID
,
3236 MVPP2_PE_FIRST_FREE_TID
);
3240 pe
= kzalloc(sizeof(*pe
), GFP_KERNEL
);
3244 mvpp2_prs_tcam_lu_set(pe
, MVPP2_PRS_LU_FLOWS
);
3248 mvpp2_prs_sram_ai_update(pe
, port
->id
, MVPP2_PRS_FLOW_ID_MASK
);
3249 mvpp2_prs_sram_bits_set(pe
, MVPP2_PRS_SRAM_LU_DONE_BIT
, 1);
3251 /* Update shadow table */
3252 mvpp2_prs_shadow_set(port
->priv
, pe
->index
, MVPP2_PRS_LU_FLOWS
);
3255 mvpp2_prs_tcam_port_map_set(pe
, (1 << port
->id
));
3256 mvpp2_prs_hw_write(port
->priv
, pe
);
3262 /* Classifier configuration routines */
3264 /* Update classification flow table registers */
3265 static void mvpp2_cls_flow_write(struct mvpp2
*priv
,
3266 struct mvpp2_cls_flow_entry
*fe
)
3268 mvpp2_write(priv
, MVPP2_CLS_FLOW_INDEX_REG
, fe
->index
);
3269 mvpp2_write(priv
, MVPP2_CLS_FLOW_TBL0_REG
, fe
->data
[0]);
3270 mvpp2_write(priv
, MVPP2_CLS_FLOW_TBL1_REG
, fe
->data
[1]);
3271 mvpp2_write(priv
, MVPP2_CLS_FLOW_TBL2_REG
, fe
->data
[2]);
3274 /* Update classification lookup table register */
3275 static void mvpp2_cls_lookup_write(struct mvpp2
*priv
,
3276 struct mvpp2_cls_lookup_entry
*le
)
3280 val
= (le
->way
<< MVPP2_CLS_LKP_INDEX_WAY_OFFS
) | le
->lkpid
;
3281 mvpp2_write(priv
, MVPP2_CLS_LKP_INDEX_REG
, val
);
3282 mvpp2_write(priv
, MVPP2_CLS_LKP_TBL_REG
, le
->data
);
3285 /* Classifier default initialization */
3286 static void mvpp2_cls_init(struct mvpp2
*priv
)
3288 struct mvpp2_cls_lookup_entry le
;
3289 struct mvpp2_cls_flow_entry fe
;
3292 /* Enable classifier */
3293 mvpp2_write(priv
, MVPP2_CLS_MODE_REG
, MVPP2_CLS_MODE_ACTIVE_MASK
);
3295 /* Clear classifier flow table */
3296 memset(&fe
.data
, 0, MVPP2_CLS_FLOWS_TBL_DATA_WORDS
);
3297 for (index
= 0; index
< MVPP2_CLS_FLOWS_TBL_SIZE
; index
++) {
3299 mvpp2_cls_flow_write(priv
, &fe
);
3302 /* Clear classifier lookup table */
3304 for (index
= 0; index
< MVPP2_CLS_LKP_TBL_SIZE
; index
++) {
3307 mvpp2_cls_lookup_write(priv
, &le
);
3310 mvpp2_cls_lookup_write(priv
, &le
);
3314 static void mvpp2_cls_port_config(struct mvpp2_port
*port
)
3316 struct mvpp2_cls_lookup_entry le
;
3319 /* Set way for the port */
3320 val
= mvpp2_read(port
->priv
, MVPP2_CLS_PORT_WAY_REG
);
3321 val
&= ~MVPP2_CLS_PORT_WAY_MASK(port
->id
);
3322 mvpp2_write(port
->priv
, MVPP2_CLS_PORT_WAY_REG
, val
);
3324 /* Pick the entry to be accessed in lookup ID decoding table
3325 * according to the way and lkpid.
3327 le
.lkpid
= port
->id
;
3331 /* Set initial CPU queue for receiving packets */
3332 le
.data
&= ~MVPP2_CLS_LKP_TBL_RXQ_MASK
;
3333 le
.data
|= port
->first_rxq
;
3335 /* Disable classification engines */
3336 le
.data
&= ~MVPP2_CLS_LKP_TBL_LOOKUP_EN_MASK
;
3338 /* Update lookup ID table entry */
3339 mvpp2_cls_lookup_write(port
->priv
, &le
);
3342 /* Set CPU queue number for oversize packets */
3343 static void mvpp2_cls_oversize_rxq_set(struct mvpp2_port
*port
)
3347 mvpp2_write(port
->priv
, MVPP2_CLS_OVERSIZE_RXQ_LOW_REG(port
->id
),
3348 port
->first_rxq
& MVPP2_CLS_OVERSIZE_RXQ_LOW_MASK
);
3350 mvpp2_write(port
->priv
, MVPP2_CLS_SWFWD_P2HQ_REG(port
->id
),
3351 (port
->first_rxq
>> MVPP2_CLS_OVERSIZE_RXQ_LOW_BITS
));
3353 val
= mvpp2_read(port
->priv
, MVPP2_CLS_SWFWD_PCTRL_REG
);
3354 val
|= MVPP2_CLS_SWFWD_PCTRL_MASK(port
->id
);
3355 mvpp2_write(port
->priv
, MVPP2_CLS_SWFWD_PCTRL_REG
, val
);
3358 /* Buffer Manager configuration routines */
3361 static int mvpp2_bm_pool_create(struct platform_device
*pdev
,
3363 struct mvpp2_bm_pool
*bm_pool
, int size
)
3368 size_bytes
= sizeof(u32
) * size
;
3369 bm_pool
->virt_addr
= dma_alloc_coherent(&pdev
->dev
, size_bytes
,
3370 &bm_pool
->phys_addr
,
3372 if (!bm_pool
->virt_addr
)
3375 if (!IS_ALIGNED((u32
)bm_pool
->virt_addr
, MVPP2_BM_POOL_PTR_ALIGN
)) {
3376 dma_free_coherent(&pdev
->dev
, size_bytes
, bm_pool
->virt_addr
,
3377 bm_pool
->phys_addr
);
3378 dev_err(&pdev
->dev
, "BM pool %d is not %d bytes aligned\n",
3379 bm_pool
->id
, MVPP2_BM_POOL_PTR_ALIGN
);
3383 mvpp2_write(priv
, MVPP2_BM_POOL_BASE_REG(bm_pool
->id
),
3384 bm_pool
->phys_addr
);
3385 mvpp2_write(priv
, MVPP2_BM_POOL_SIZE_REG(bm_pool
->id
), size
);
3387 val
= mvpp2_read(priv
, MVPP2_BM_POOL_CTRL_REG(bm_pool
->id
));
3388 val
|= MVPP2_BM_START_MASK
;
3389 mvpp2_write(priv
, MVPP2_BM_POOL_CTRL_REG(bm_pool
->id
), val
);
3391 bm_pool
->type
= MVPP2_BM_FREE
;
3392 bm_pool
->size
= size
;
3393 bm_pool
->pkt_size
= 0;
3394 bm_pool
->buf_num
= 0;
3395 atomic_set(&bm_pool
->in_use
, 0);
3400 /* Set pool buffer size */
3401 static void mvpp2_bm_pool_bufsize_set(struct mvpp2
*priv
,
3402 struct mvpp2_bm_pool
*bm_pool
,
3407 bm_pool
->buf_size
= buf_size
;
3409 val
= ALIGN(buf_size
, 1 << MVPP2_POOL_BUF_SIZE_OFFSET
);
3410 mvpp2_write(priv
, MVPP2_POOL_BUF_SIZE_REG(bm_pool
->id
), val
);
3413 /* Free all buffers from the pool */
3414 static void mvpp2_bm_bufs_free(struct device
*dev
, struct mvpp2
*priv
,
3415 struct mvpp2_bm_pool
*bm_pool
)
3419 for (i
= 0; i
< bm_pool
->buf_num
; i
++) {
3420 dma_addr_t buf_phys_addr
;
3423 /* Get buffer virtual address (indirect access) */
3424 buf_phys_addr
= mvpp2_read(priv
,
3425 MVPP2_BM_PHY_ALLOC_REG(bm_pool
->id
));
3426 vaddr
= mvpp2_read(priv
, MVPP2_BM_VIRT_ALLOC_REG
);
3428 dma_unmap_single(dev
, buf_phys_addr
,
3429 bm_pool
->buf_size
, DMA_FROM_DEVICE
);
3433 dev_kfree_skb_any((struct sk_buff
*)vaddr
);
3436 /* Update BM driver with number of buffers removed from pool */
3437 bm_pool
->buf_num
-= i
;
3441 static int mvpp2_bm_pool_destroy(struct platform_device
*pdev
,
3443 struct mvpp2_bm_pool
*bm_pool
)
3447 mvpp2_bm_bufs_free(&pdev
->dev
, priv
, bm_pool
);
3448 if (bm_pool
->buf_num
) {
3449 WARN(1, "cannot free all buffers in pool %d\n", bm_pool
->id
);
3453 val
= mvpp2_read(priv
, MVPP2_BM_POOL_CTRL_REG(bm_pool
->id
));
3454 val
|= MVPP2_BM_STOP_MASK
;
3455 mvpp2_write(priv
, MVPP2_BM_POOL_CTRL_REG(bm_pool
->id
), val
);
3457 dma_free_coherent(&pdev
->dev
, sizeof(u32
) * bm_pool
->size
,
3459 bm_pool
->phys_addr
);
3463 static int mvpp2_bm_pools_init(struct platform_device
*pdev
,
3467 struct mvpp2_bm_pool
*bm_pool
;
3469 /* Create all pools with maximum size */
3470 size
= MVPP2_BM_POOL_SIZE_MAX
;
3471 for (i
= 0; i
< MVPP2_BM_POOLS_NUM
; i
++) {
3472 bm_pool
= &priv
->bm_pools
[i
];
3474 err
= mvpp2_bm_pool_create(pdev
, priv
, bm_pool
, size
);
3476 goto err_unroll_pools
;
3477 mvpp2_bm_pool_bufsize_set(priv
, bm_pool
, 0);
3482 dev_err(&pdev
->dev
, "failed to create BM pool %d, size %d\n", i
, size
);
3483 for (i
= i
- 1; i
>= 0; i
--)
3484 mvpp2_bm_pool_destroy(pdev
, priv
, &priv
->bm_pools
[i
]);
3488 static int mvpp2_bm_init(struct platform_device
*pdev
, struct mvpp2
*priv
)
3492 for (i
= 0; i
< MVPP2_BM_POOLS_NUM
; i
++) {
3493 /* Mask BM all interrupts */
3494 mvpp2_write(priv
, MVPP2_BM_INTR_MASK_REG(i
), 0);
3495 /* Clear BM cause register */
3496 mvpp2_write(priv
, MVPP2_BM_INTR_CAUSE_REG(i
), 0);
3499 /* Allocate and initialize BM pools */
3500 priv
->bm_pools
= devm_kcalloc(&pdev
->dev
, MVPP2_BM_POOLS_NUM
,
3501 sizeof(struct mvpp2_bm_pool
), GFP_KERNEL
);
3502 if (!priv
->bm_pools
)
3505 err
= mvpp2_bm_pools_init(pdev
, priv
);
3511 /* Attach long pool to rxq */
3512 static void mvpp2_rxq_long_pool_set(struct mvpp2_port
*port
,
3513 int lrxq
, int long_pool
)
3518 /* Get queue physical ID */
3519 prxq
= port
->rxqs
[lrxq
]->id
;
3521 val
= mvpp2_read(port
->priv
, MVPP2_RXQ_CONFIG_REG(prxq
));
3522 val
&= ~MVPP2_RXQ_POOL_LONG_MASK
;
3523 val
|= ((long_pool
<< MVPP2_RXQ_POOL_LONG_OFFS
) &
3524 MVPP2_RXQ_POOL_LONG_MASK
);
3526 mvpp2_write(port
->priv
, MVPP2_RXQ_CONFIG_REG(prxq
), val
);
3529 /* Attach short pool to rxq */
3530 static void mvpp2_rxq_short_pool_set(struct mvpp2_port
*port
,
3531 int lrxq
, int short_pool
)
3536 /* Get queue physical ID */
3537 prxq
= port
->rxqs
[lrxq
]->id
;
3539 val
= mvpp2_read(port
->priv
, MVPP2_RXQ_CONFIG_REG(prxq
));
3540 val
&= ~MVPP2_RXQ_POOL_SHORT_MASK
;
3541 val
|= ((short_pool
<< MVPP2_RXQ_POOL_SHORT_OFFS
) &
3542 MVPP2_RXQ_POOL_SHORT_MASK
);
3544 mvpp2_write(port
->priv
, MVPP2_RXQ_CONFIG_REG(prxq
), val
);
3547 /* Allocate skb for BM pool */
3548 static struct sk_buff
*mvpp2_skb_alloc(struct mvpp2_port
*port
,
3549 struct mvpp2_bm_pool
*bm_pool
,
3550 dma_addr_t
*buf_phys_addr
,
3553 struct sk_buff
*skb
;
3554 dma_addr_t phys_addr
;
3556 skb
= __dev_alloc_skb(bm_pool
->pkt_size
, gfp_mask
);
3560 phys_addr
= dma_map_single(port
->dev
->dev
.parent
, skb
->head
,
3561 MVPP2_RX_BUF_SIZE(bm_pool
->pkt_size
),
3563 if (unlikely(dma_mapping_error(port
->dev
->dev
.parent
, phys_addr
))) {
3564 dev_kfree_skb_any(skb
);
3567 *buf_phys_addr
= phys_addr
;
3572 /* Set pool number in a BM cookie */
3573 static inline u32
mvpp2_bm_cookie_pool_set(u32 cookie
, int pool
)
3577 bm
= cookie
& ~(0xFF << MVPP2_BM_COOKIE_POOL_OFFS
);
3578 bm
|= ((pool
& 0xFF) << MVPP2_BM_COOKIE_POOL_OFFS
);
3583 /* Get pool number from a BM cookie */
3584 static inline int mvpp2_bm_cookie_pool_get(u32 cookie
)
3586 return (cookie
>> MVPP2_BM_COOKIE_POOL_OFFS
) & 0xFF;
3589 /* Release buffer to BM */
3590 static inline void mvpp2_bm_pool_put(struct mvpp2_port
*port
, int pool
,
3591 u32 buf_phys_addr
, u32 buf_virt_addr
)
3593 mvpp2_write(port
->priv
, MVPP2_BM_VIRT_RLS_REG
, buf_virt_addr
);
3594 mvpp2_write(port
->priv
, MVPP2_BM_PHY_RLS_REG(pool
), buf_phys_addr
);
3597 /* Release multicast buffer */
3598 static void mvpp2_bm_pool_mc_put(struct mvpp2_port
*port
, int pool
,
3599 u32 buf_phys_addr
, u32 buf_virt_addr
,
3604 val
|= (mc_id
& MVPP2_BM_MC_ID_MASK
);
3605 mvpp2_write(port
->priv
, MVPP2_BM_MC_RLS_REG
, val
);
3607 mvpp2_bm_pool_put(port
, pool
,
3608 buf_phys_addr
| MVPP2_BM_PHY_RLS_MC_BUFF_MASK
,
3612 /* Refill BM pool */
3613 static void mvpp2_pool_refill(struct mvpp2_port
*port
, u32 bm
,
3614 u32 phys_addr
, u32 cookie
)
3616 int pool
= mvpp2_bm_cookie_pool_get(bm
);
3618 mvpp2_bm_pool_put(port
, pool
, phys_addr
, cookie
);
3621 /* Allocate buffers for the pool */
3622 static int mvpp2_bm_bufs_add(struct mvpp2_port
*port
,
3623 struct mvpp2_bm_pool
*bm_pool
, int buf_num
)
3625 struct sk_buff
*skb
;
3626 int i
, buf_size
, total_size
;
3628 dma_addr_t phys_addr
;
3630 buf_size
= MVPP2_RX_BUF_SIZE(bm_pool
->pkt_size
);
3631 total_size
= MVPP2_RX_TOTAL_SIZE(buf_size
);
3634 (buf_num
+ bm_pool
->buf_num
> bm_pool
->size
)) {
3635 netdev_err(port
->dev
,
3636 "cannot allocate %d buffers for pool %d\n",
3637 buf_num
, bm_pool
->id
);
3641 bm
= mvpp2_bm_cookie_pool_set(0, bm_pool
->id
);
3642 for (i
= 0; i
< buf_num
; i
++) {
3643 skb
= mvpp2_skb_alloc(port
, bm_pool
, &phys_addr
, GFP_KERNEL
);
3647 mvpp2_pool_refill(port
, bm
, (u32
)phys_addr
, (u32
)skb
);
3650 /* Update BM driver with number of buffers added to pool */
3651 bm_pool
->buf_num
+= i
;
3652 bm_pool
->in_use_thresh
= bm_pool
->buf_num
/ 4;
3654 netdev_dbg(port
->dev
,
3655 "%s pool %d: pkt_size=%4d, buf_size=%4d, total_size=%4d\n",
3656 bm_pool
->type
== MVPP2_BM_SWF_SHORT
? "short" : " long",
3657 bm_pool
->id
, bm_pool
->pkt_size
, buf_size
, total_size
);
3659 netdev_dbg(port
->dev
,
3660 "%s pool %d: %d of %d buffers added\n",
3661 bm_pool
->type
== MVPP2_BM_SWF_SHORT
? "short" : " long",
3662 bm_pool
->id
, i
, buf_num
);
3666 /* Notify the driver that BM pool is being used as specific type and return the
3667 * pool pointer on success
3669 static struct mvpp2_bm_pool
*
3670 mvpp2_bm_pool_use(struct mvpp2_port
*port
, int pool
, enum mvpp2_bm_type type
,
3673 struct mvpp2_bm_pool
*new_pool
= &port
->priv
->bm_pools
[pool
];
3676 if (new_pool
->type
!= MVPP2_BM_FREE
&& new_pool
->type
!= type
) {
3677 netdev_err(port
->dev
, "mixing pool types is forbidden\n");
3681 if (new_pool
->type
== MVPP2_BM_FREE
)
3682 new_pool
->type
= type
;
3684 /* Allocate buffers in case BM pool is used as long pool, but packet
3685 * size doesn't match MTU or BM pool hasn't being used yet
3687 if (((type
== MVPP2_BM_SWF_LONG
) && (pkt_size
> new_pool
->pkt_size
)) ||
3688 (new_pool
->pkt_size
== 0)) {
3691 /* Set default buffer number or free all the buffers in case
3692 * the pool is not empty
3694 pkts_num
= new_pool
->buf_num
;
3696 pkts_num
= type
== MVPP2_BM_SWF_LONG
?
3697 MVPP2_BM_LONG_BUF_NUM
:
3698 MVPP2_BM_SHORT_BUF_NUM
;
3700 mvpp2_bm_bufs_free(port
->dev
->dev
.parent
,
3701 port
->priv
, new_pool
);
3703 new_pool
->pkt_size
= pkt_size
;
3705 /* Allocate buffers for this pool */
3706 num
= mvpp2_bm_bufs_add(port
, new_pool
, pkts_num
);
3707 if (num
!= pkts_num
) {
3708 WARN(1, "pool %d: %d of %d allocated\n",
3709 new_pool
->id
, num
, pkts_num
);
3714 mvpp2_bm_pool_bufsize_set(port
->priv
, new_pool
,
3715 MVPP2_RX_BUF_SIZE(new_pool
->pkt_size
));
3720 /* Initialize pools for swf */
3721 static int mvpp2_swf_bm_pool_init(struct mvpp2_port
*port
)
3725 if (!port
->pool_long
) {
3727 mvpp2_bm_pool_use(port
, MVPP2_BM_SWF_LONG_POOL(port
->id
),
3730 if (!port
->pool_long
)
3733 port
->pool_long
->port_map
|= (1 << port
->id
);
3735 for (rxq
= 0; rxq
< rxq_number
; rxq
++)
3736 mvpp2_rxq_long_pool_set(port
, rxq
, port
->pool_long
->id
);
3739 if (!port
->pool_short
) {
3741 mvpp2_bm_pool_use(port
, MVPP2_BM_SWF_SHORT_POOL
,
3743 MVPP2_BM_SHORT_PKT_SIZE
);
3744 if (!port
->pool_short
)
3747 port
->pool_short
->port_map
|= (1 << port
->id
);
3749 for (rxq
= 0; rxq
< rxq_number
; rxq
++)
3750 mvpp2_rxq_short_pool_set(port
, rxq
,
3751 port
->pool_short
->id
);
3757 static int mvpp2_bm_update_mtu(struct net_device
*dev
, int mtu
)
3759 struct mvpp2_port
*port
= netdev_priv(dev
);
3760 struct mvpp2_bm_pool
*port_pool
= port
->pool_long
;
3761 int num
, pkts_num
= port_pool
->buf_num
;
3762 int pkt_size
= MVPP2_RX_PKT_SIZE(mtu
);
3764 /* Update BM pool with new buffer size */
3765 mvpp2_bm_bufs_free(dev
->dev
.parent
, port
->priv
, port_pool
);
3766 if (port_pool
->buf_num
) {
3767 WARN(1, "cannot free all buffers in pool %d\n", port_pool
->id
);
3771 port_pool
->pkt_size
= pkt_size
;
3772 num
= mvpp2_bm_bufs_add(port
, port_pool
, pkts_num
);
3773 if (num
!= pkts_num
) {
3774 WARN(1, "pool %d: %d of %d allocated\n",
3775 port_pool
->id
, num
, pkts_num
);
3779 mvpp2_bm_pool_bufsize_set(port
->priv
, port_pool
,
3780 MVPP2_RX_BUF_SIZE(port_pool
->pkt_size
));
3782 netdev_update_features(dev
);
3786 static inline void mvpp2_interrupts_enable(struct mvpp2_port
*port
)
3788 int cpu
, cpu_mask
= 0;
3790 for_each_present_cpu(cpu
)
3791 cpu_mask
|= 1 << cpu
;
3792 mvpp2_write(port
->priv
, MVPP2_ISR_ENABLE_REG(port
->id
),
3793 MVPP2_ISR_ENABLE_INTERRUPT(cpu_mask
));
3796 static inline void mvpp2_interrupts_disable(struct mvpp2_port
*port
)
3798 int cpu
, cpu_mask
= 0;
3800 for_each_present_cpu(cpu
)
3801 cpu_mask
|= 1 << cpu
;
3802 mvpp2_write(port
->priv
, MVPP2_ISR_ENABLE_REG(port
->id
),
3803 MVPP2_ISR_DISABLE_INTERRUPT(cpu_mask
));
3806 /* Mask the current CPU's Rx/Tx interrupts */
3807 static void mvpp2_interrupts_mask(void *arg
)
3809 struct mvpp2_port
*port
= arg
;
3811 mvpp2_write(port
->priv
, MVPP2_ISR_RX_TX_MASK_REG(port
->id
), 0);
3814 /* Unmask the current CPU's Rx/Tx interrupts */
3815 static void mvpp2_interrupts_unmask(void *arg
)
3817 struct mvpp2_port
*port
= arg
;
3819 mvpp2_write(port
->priv
, MVPP2_ISR_RX_TX_MASK_REG(port
->id
),
3820 (MVPP2_CAUSE_MISC_SUM_MASK
|
3821 MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK
));
3824 /* Port configuration routines */
3826 static void mvpp2_port_mii_set(struct mvpp2_port
*port
)
3830 val
= readl(port
->base
+ MVPP2_GMAC_CTRL_2_REG
);
3832 switch (port
->phy_interface
) {
3833 case PHY_INTERFACE_MODE_SGMII
:
3834 val
|= MVPP2_GMAC_INBAND_AN_MASK
;
3836 case PHY_INTERFACE_MODE_RGMII
:
3837 val
|= MVPP2_GMAC_PORT_RGMII_MASK
;
3839 val
&= ~MVPP2_GMAC_PCS_ENABLE_MASK
;
3842 writel(val
, port
->base
+ MVPP2_GMAC_CTRL_2_REG
);
3845 static void mvpp2_port_fc_adv_enable(struct mvpp2_port
*port
)
3849 val
= readl(port
->base
+ MVPP2_GMAC_AUTONEG_CONFIG
);
3850 val
|= MVPP2_GMAC_FC_ADV_EN
;
3851 writel(val
, port
->base
+ MVPP2_GMAC_AUTONEG_CONFIG
);
3854 static void mvpp2_port_enable(struct mvpp2_port
*port
)
3858 val
= readl(port
->base
+ MVPP2_GMAC_CTRL_0_REG
);
3859 val
|= MVPP2_GMAC_PORT_EN_MASK
;
3860 val
|= MVPP2_GMAC_MIB_CNTR_EN_MASK
;
3861 writel(val
, port
->base
+ MVPP2_GMAC_CTRL_0_REG
);
3864 static void mvpp2_port_disable(struct mvpp2_port
*port
)
3868 val
= readl(port
->base
+ MVPP2_GMAC_CTRL_0_REG
);
3869 val
&= ~(MVPP2_GMAC_PORT_EN_MASK
);
3870 writel(val
, port
->base
+ MVPP2_GMAC_CTRL_0_REG
);
3873 /* Set IEEE 802.3x Flow Control Xon Packet Transmission Mode */
3874 static void mvpp2_port_periodic_xon_disable(struct mvpp2_port
*port
)
3878 val
= readl(port
->base
+ MVPP2_GMAC_CTRL_1_REG
) &
3879 ~MVPP2_GMAC_PERIODIC_XON_EN_MASK
;
3880 writel(val
, port
->base
+ MVPP2_GMAC_CTRL_1_REG
);
3883 /* Configure loopback port */
3884 static void mvpp2_port_loopback_set(struct mvpp2_port
*port
)
3888 val
= readl(port
->base
+ MVPP2_GMAC_CTRL_1_REG
);
3890 if (port
->speed
== 1000)
3891 val
|= MVPP2_GMAC_GMII_LB_EN_MASK
;
3893 val
&= ~MVPP2_GMAC_GMII_LB_EN_MASK
;
3895 if (port
->phy_interface
== PHY_INTERFACE_MODE_SGMII
)
3896 val
|= MVPP2_GMAC_PCS_LB_EN_MASK
;
3898 val
&= ~MVPP2_GMAC_PCS_LB_EN_MASK
;
3900 writel(val
, port
->base
+ MVPP2_GMAC_CTRL_1_REG
);
3903 static void mvpp2_port_reset(struct mvpp2_port
*port
)
3907 val
= readl(port
->base
+ MVPP2_GMAC_CTRL_2_REG
) &
3908 ~MVPP2_GMAC_PORT_RESET_MASK
;
3909 writel(val
, port
->base
+ MVPP2_GMAC_CTRL_2_REG
);
3911 while (readl(port
->base
+ MVPP2_GMAC_CTRL_2_REG
) &
3912 MVPP2_GMAC_PORT_RESET_MASK
)
3916 /* Change maximum receive size of the port */
3917 static inline void mvpp2_gmac_max_rx_size_set(struct mvpp2_port
*port
)
3921 val
= readl(port
->base
+ MVPP2_GMAC_CTRL_0_REG
);
3922 val
&= ~MVPP2_GMAC_MAX_RX_SIZE_MASK
;
3923 val
|= (((port
->pkt_size
- MVPP2_MH_SIZE
) / 2) <<
3924 MVPP2_GMAC_MAX_RX_SIZE_OFFS
);
3925 writel(val
, port
->base
+ MVPP2_GMAC_CTRL_0_REG
);
3928 /* Set defaults to the MVPP2 port */
3929 static void mvpp2_defaults_set(struct mvpp2_port
*port
)
3931 int tx_port_num
, val
, queue
, ptxq
, lrxq
;
3933 /* Configure port to loopback if needed */
3934 if (port
->flags
& MVPP2_F_LOOPBACK
)
3935 mvpp2_port_loopback_set(port
);
3937 /* Update TX FIFO MIN Threshold */
3938 val
= readl(port
->base
+ MVPP2_GMAC_PORT_FIFO_CFG_1_REG
);
3939 val
&= ~MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK
;
3940 /* Min. TX threshold must be less than minimal packet length */
3941 val
|= MVPP2_GMAC_TX_FIFO_MIN_TH_MASK(64 - 4 - 2);
3942 writel(val
, port
->base
+ MVPP2_GMAC_PORT_FIFO_CFG_1_REG
);
3944 /* Disable Legacy WRR, Disable EJP, Release from reset */
3945 tx_port_num
= mvpp2_egress_port(port
);
3946 mvpp2_write(port
->priv
, MVPP2_TXP_SCHED_PORT_INDEX_REG
,
3948 mvpp2_write(port
->priv
, MVPP2_TXP_SCHED_CMD_1_REG
, 0);
3950 /* Close bandwidth for all queues */
3951 for (queue
= 0; queue
< MVPP2_MAX_TXQ
; queue
++) {
3952 ptxq
= mvpp2_txq_phys(port
->id
, queue
);
3953 mvpp2_write(port
->priv
,
3954 MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(ptxq
), 0);
3957 /* Set refill period to 1 usec, refill tokens
3958 * and bucket size to maximum
3960 mvpp2_write(port
->priv
, MVPP2_TXP_SCHED_PERIOD_REG
,
3961 port
->priv
->tclk
/ USEC_PER_SEC
);
3962 val
= mvpp2_read(port
->priv
, MVPP2_TXP_SCHED_REFILL_REG
);
3963 val
&= ~MVPP2_TXP_REFILL_PERIOD_ALL_MASK
;
3964 val
|= MVPP2_TXP_REFILL_PERIOD_MASK(1);
3965 val
|= MVPP2_TXP_REFILL_TOKENS_ALL_MASK
;
3966 mvpp2_write(port
->priv
, MVPP2_TXP_SCHED_REFILL_REG
, val
);
3967 val
= MVPP2_TXP_TOKEN_SIZE_MAX
;
3968 mvpp2_write(port
->priv
, MVPP2_TXP_SCHED_TOKEN_SIZE_REG
, val
);
3970 /* Set MaximumLowLatencyPacketSize value to 256 */
3971 mvpp2_write(port
->priv
, MVPP2_RX_CTRL_REG(port
->id
),
3972 MVPP2_RX_USE_PSEUDO_FOR_CSUM_MASK
|
3973 MVPP2_RX_LOW_LATENCY_PKT_SIZE(256));
3975 /* Enable Rx cache snoop */
3976 for (lrxq
= 0; lrxq
< rxq_number
; lrxq
++) {
3977 queue
= port
->rxqs
[lrxq
]->id
;
3978 val
= mvpp2_read(port
->priv
, MVPP2_RXQ_CONFIG_REG(queue
));
3979 val
|= MVPP2_SNOOP_PKT_SIZE_MASK
|
3980 MVPP2_SNOOP_BUF_HDR_MASK
;
3981 mvpp2_write(port
->priv
, MVPP2_RXQ_CONFIG_REG(queue
), val
);
3984 /* At default, mask all interrupts to all present cpus */
3985 mvpp2_interrupts_disable(port
);
3988 /* Enable/disable receiving packets */
3989 static void mvpp2_ingress_enable(struct mvpp2_port
*port
)
3994 for (lrxq
= 0; lrxq
< rxq_number
; lrxq
++) {
3995 queue
= port
->rxqs
[lrxq
]->id
;
3996 val
= mvpp2_read(port
->priv
, MVPP2_RXQ_CONFIG_REG(queue
));
3997 val
&= ~MVPP2_RXQ_DISABLE_MASK
;
3998 mvpp2_write(port
->priv
, MVPP2_RXQ_CONFIG_REG(queue
), val
);
4002 static void mvpp2_ingress_disable(struct mvpp2_port
*port
)
4007 for (lrxq
= 0; lrxq
< rxq_number
; lrxq
++) {
4008 queue
= port
->rxqs
[lrxq
]->id
;
4009 val
= mvpp2_read(port
->priv
, MVPP2_RXQ_CONFIG_REG(queue
));
4010 val
|= MVPP2_RXQ_DISABLE_MASK
;
4011 mvpp2_write(port
->priv
, MVPP2_RXQ_CONFIG_REG(queue
), val
);
4015 /* Enable transmit via physical egress queue
4016 * - HW starts take descriptors from DRAM
4018 static void mvpp2_egress_enable(struct mvpp2_port
*port
)
4022 int tx_port_num
= mvpp2_egress_port(port
);
4024 /* Enable all initialized TXs. */
4026 for (queue
= 0; queue
< txq_number
; queue
++) {
4027 struct mvpp2_tx_queue
*txq
= port
->txqs
[queue
];
4029 if (txq
->descs
!= NULL
)
4030 qmap
|= (1 << queue
);
4033 mvpp2_write(port
->priv
, MVPP2_TXP_SCHED_PORT_INDEX_REG
, tx_port_num
);
4034 mvpp2_write(port
->priv
, MVPP2_TXP_SCHED_Q_CMD_REG
, qmap
);
4037 /* Disable transmit via physical egress queue
4038 * - HW doesn't take descriptors from DRAM
4040 static void mvpp2_egress_disable(struct mvpp2_port
*port
)
4044 int tx_port_num
= mvpp2_egress_port(port
);
4046 /* Issue stop command for active channels only */
4047 mvpp2_write(port
->priv
, MVPP2_TXP_SCHED_PORT_INDEX_REG
, tx_port_num
);
4048 reg_data
= (mvpp2_read(port
->priv
, MVPP2_TXP_SCHED_Q_CMD_REG
)) &
4049 MVPP2_TXP_SCHED_ENQ_MASK
;
4051 mvpp2_write(port
->priv
, MVPP2_TXP_SCHED_Q_CMD_REG
,
4052 (reg_data
<< MVPP2_TXP_SCHED_DISQ_OFFSET
));
4054 /* Wait for all Tx activity to terminate. */
4057 if (delay
>= MVPP2_TX_DISABLE_TIMEOUT_MSEC
) {
4058 netdev_warn(port
->dev
,
4059 "Tx stop timed out, status=0x%08x\n",
4066 /* Check port TX Command register that all
4067 * Tx queues are stopped
4069 reg_data
= mvpp2_read(port
->priv
, MVPP2_TXP_SCHED_Q_CMD_REG
);
4070 } while (reg_data
& MVPP2_TXP_SCHED_ENQ_MASK
);
4073 /* Rx descriptors helper methods */
4075 /* Get number of Rx descriptors occupied by received packets */
4077 mvpp2_rxq_received(struct mvpp2_port
*port
, int rxq_id
)
4079 u32 val
= mvpp2_read(port
->priv
, MVPP2_RXQ_STATUS_REG(rxq_id
));
4081 return val
& MVPP2_RXQ_OCCUPIED_MASK
;
4084 /* Update Rx queue status with the number of occupied and available
4085 * Rx descriptor slots.
4088 mvpp2_rxq_status_update(struct mvpp2_port
*port
, int rxq_id
,
4089 int used_count
, int free_count
)
4091 /* Decrement the number of used descriptors and increment count
4092 * increment the number of free descriptors.
4094 u32 val
= used_count
| (free_count
<< MVPP2_RXQ_NUM_NEW_OFFSET
);
4096 mvpp2_write(port
->priv
, MVPP2_RXQ_STATUS_UPDATE_REG(rxq_id
), val
);
4099 /* Get pointer to next RX descriptor to be processed by SW */
4100 static inline struct mvpp2_rx_desc
*
4101 mvpp2_rxq_next_desc_get(struct mvpp2_rx_queue
*rxq
)
4103 int rx_desc
= rxq
->next_desc_to_proc
;
4105 rxq
->next_desc_to_proc
= MVPP2_QUEUE_NEXT_DESC(rxq
, rx_desc
);
4106 prefetch(rxq
->descs
+ rxq
->next_desc_to_proc
);
4107 return rxq
->descs
+ rx_desc
;
4110 /* Set rx queue offset */
4111 static void mvpp2_rxq_offset_set(struct mvpp2_port
*port
,
4112 int prxq
, int offset
)
4116 /* Convert offset from bytes to units of 32 bytes */
4117 offset
= offset
>> 5;
4119 val
= mvpp2_read(port
->priv
, MVPP2_RXQ_CONFIG_REG(prxq
));
4120 val
&= ~MVPP2_RXQ_PACKET_OFFSET_MASK
;
4123 val
|= ((offset
<< MVPP2_RXQ_PACKET_OFFSET_OFFS
) &
4124 MVPP2_RXQ_PACKET_OFFSET_MASK
);
4126 mvpp2_write(port
->priv
, MVPP2_RXQ_CONFIG_REG(prxq
), val
);
4129 /* Obtain BM cookie information from descriptor */
4130 static u32
mvpp2_bm_cookie_build(struct mvpp2_rx_desc
*rx_desc
)
4132 int pool
= (rx_desc
->status
& MVPP2_RXD_BM_POOL_ID_MASK
) >>
4133 MVPP2_RXD_BM_POOL_ID_OFFS
;
4134 int cpu
= smp_processor_id();
4136 return ((pool
& 0xFF) << MVPP2_BM_COOKIE_POOL_OFFS
) |
4137 ((cpu
& 0xFF) << MVPP2_BM_COOKIE_CPU_OFFS
);
4140 /* Tx descriptors helper methods */
4142 /* Get number of Tx descriptors waiting to be transmitted by HW */
4143 static int mvpp2_txq_pend_desc_num_get(struct mvpp2_port
*port
,
4144 struct mvpp2_tx_queue
*txq
)
4148 mvpp2_write(port
->priv
, MVPP2_TXQ_NUM_REG
, txq
->id
);
4149 val
= mvpp2_read(port
->priv
, MVPP2_TXQ_PENDING_REG
);
4151 return val
& MVPP2_TXQ_PENDING_MASK
;
4154 /* Get pointer to next Tx descriptor to be processed (send) by HW */
4155 static struct mvpp2_tx_desc
*
4156 mvpp2_txq_next_desc_get(struct mvpp2_tx_queue
*txq
)
4158 int tx_desc
= txq
->next_desc_to_proc
;
4160 txq
->next_desc_to_proc
= MVPP2_QUEUE_NEXT_DESC(txq
, tx_desc
);
4161 return txq
->descs
+ tx_desc
;
4164 /* Update HW with number of aggregated Tx descriptors to be sent */
4165 static void mvpp2_aggr_txq_pend_desc_add(struct mvpp2_port
*port
, int pending
)
4167 /* aggregated access - relevant TXQ number is written in TX desc */
4168 mvpp2_write(port
->priv
, MVPP2_AGGR_TXQ_UPDATE_REG
, pending
);
4172 /* Check if there are enough free descriptors in aggregated txq.
4173 * If not, update the number of occupied descriptors and repeat the check.
4175 static int mvpp2_aggr_desc_num_check(struct mvpp2
*priv
,
4176 struct mvpp2_tx_queue
*aggr_txq
, int num
)
4178 if ((aggr_txq
->count
+ num
) > aggr_txq
->size
) {
4179 /* Update number of occupied aggregated Tx descriptors */
4180 int cpu
= smp_processor_id();
4181 u32 val
= mvpp2_read(priv
, MVPP2_AGGR_TXQ_STATUS_REG(cpu
));
4183 aggr_txq
->count
= val
& MVPP2_AGGR_TXQ_PENDING_MASK
;
4186 if ((aggr_txq
->count
+ num
) > aggr_txq
->size
)
4192 /* Reserved Tx descriptors allocation request */
4193 static int mvpp2_txq_alloc_reserved_desc(struct mvpp2
*priv
,
4194 struct mvpp2_tx_queue
*txq
, int num
)
4198 val
= (txq
->id
<< MVPP2_TXQ_RSVD_REQ_Q_OFFSET
) | num
;
4199 mvpp2_write(priv
, MVPP2_TXQ_RSVD_REQ_REG
, val
);
4201 val
= mvpp2_read(priv
, MVPP2_TXQ_RSVD_RSLT_REG
);
4203 return val
& MVPP2_TXQ_RSVD_RSLT_MASK
;
4206 /* Check if there are enough reserved descriptors for transmission.
4207 * If not, request chunk of reserved descriptors and check again.
4209 static int mvpp2_txq_reserved_desc_num_proc(struct mvpp2
*priv
,
4210 struct mvpp2_tx_queue
*txq
,
4211 struct mvpp2_txq_pcpu
*txq_pcpu
,
4214 int req
, cpu
, desc_count
;
4216 if (txq_pcpu
->reserved_num
>= num
)
4219 /* Not enough descriptors reserved! Update the reserved descriptor
4220 * count and check again.
4224 /* Compute total of used descriptors */
4225 for_each_present_cpu(cpu
) {
4226 struct mvpp2_txq_pcpu
*txq_pcpu_aux
;
4228 txq_pcpu_aux
= per_cpu_ptr(txq
->pcpu
, cpu
);
4229 desc_count
+= txq_pcpu_aux
->count
;
4230 desc_count
+= txq_pcpu_aux
->reserved_num
;
4233 req
= max(MVPP2_CPU_DESC_CHUNK
, num
- txq_pcpu
->reserved_num
);
4237 (txq
->size
- (num_present_cpus() * MVPP2_CPU_DESC_CHUNK
)))
4240 txq_pcpu
->reserved_num
+= mvpp2_txq_alloc_reserved_desc(priv
, txq
, req
);
4242 /* OK, the descriptor cound has been updated: check again. */
4243 if (txq_pcpu
->reserved_num
< num
)
4248 /* Release the last allocated Tx descriptor. Useful to handle DMA
4249 * mapping failures in the Tx path.
4251 static void mvpp2_txq_desc_put(struct mvpp2_tx_queue
*txq
)
4253 if (txq
->next_desc_to_proc
== 0)
4254 txq
->next_desc_to_proc
= txq
->last_desc
- 1;
4256 txq
->next_desc_to_proc
--;
4259 /* Set Tx descriptors fields relevant for CSUM calculation */
4260 static u32
mvpp2_txq_desc_csum(int l3_offs
, int l3_proto
,
4261 int ip_hdr_len
, int l4_proto
)
4265 /* fields: L3_offset, IP_hdrlen, L3_type, G_IPv4_chk,
4266 * G_L4_chk, L4_type required only for checksum calculation
4268 command
= (l3_offs
<< MVPP2_TXD_L3_OFF_SHIFT
);
4269 command
|= (ip_hdr_len
<< MVPP2_TXD_IP_HLEN_SHIFT
);
4270 command
|= MVPP2_TXD_IP_CSUM_DISABLE
;
4272 if (l3_proto
== swab16(ETH_P_IP
)) {
4273 command
&= ~MVPP2_TXD_IP_CSUM_DISABLE
; /* enable IPv4 csum */
4274 command
&= ~MVPP2_TXD_L3_IP6
; /* enable IPv4 */
4276 command
|= MVPP2_TXD_L3_IP6
; /* enable IPv6 */
4279 if (l4_proto
== IPPROTO_TCP
) {
4280 command
&= ~MVPP2_TXD_L4_UDP
; /* enable TCP */
4281 command
&= ~MVPP2_TXD_L4_CSUM_FRAG
; /* generate L4 csum */
4282 } else if (l4_proto
== IPPROTO_UDP
) {
4283 command
|= MVPP2_TXD_L4_UDP
; /* enable UDP */
4284 command
&= ~MVPP2_TXD_L4_CSUM_FRAG
; /* generate L4 csum */
4286 command
|= MVPP2_TXD_L4_CSUM_NOT
;
4292 /* Get number of sent descriptors and decrement counter.
4293 * The number of sent descriptors is returned.
4296 static inline int mvpp2_txq_sent_desc_proc(struct mvpp2_port
*port
,
4297 struct mvpp2_tx_queue
*txq
)
4301 /* Reading status reg resets transmitted descriptor counter */
4302 val
= mvpp2_read(port
->priv
, MVPP2_TXQ_SENT_REG(txq
->id
));
4304 return (val
& MVPP2_TRANSMITTED_COUNT_MASK
) >>
4305 MVPP2_TRANSMITTED_COUNT_OFFSET
;
4308 static void mvpp2_txq_sent_counter_clear(void *arg
)
4310 struct mvpp2_port
*port
= arg
;
4313 for (queue
= 0; queue
< txq_number
; queue
++) {
4314 int id
= port
->txqs
[queue
]->id
;
4316 mvpp2_read(port
->priv
, MVPP2_TXQ_SENT_REG(id
));
4320 /* Set max sizes for Tx queues */
4321 static void mvpp2_txp_max_tx_size_set(struct mvpp2_port
*port
)
4324 int txq
, tx_port_num
;
4326 mtu
= port
->pkt_size
* 8;
4327 if (mtu
> MVPP2_TXP_MTU_MAX
)
4328 mtu
= MVPP2_TXP_MTU_MAX
;
4330 /* WA for wrong Token bucket update: Set MTU value = 3*real MTU value */
4333 /* Indirect access to registers */
4334 tx_port_num
= mvpp2_egress_port(port
);
4335 mvpp2_write(port
->priv
, MVPP2_TXP_SCHED_PORT_INDEX_REG
, tx_port_num
);
4338 val
= mvpp2_read(port
->priv
, MVPP2_TXP_SCHED_MTU_REG
);
4339 val
&= ~MVPP2_TXP_MTU_MAX
;
4341 mvpp2_write(port
->priv
, MVPP2_TXP_SCHED_MTU_REG
, val
);
4343 /* TXP token size and all TXQs token size must be larger that MTU */
4344 val
= mvpp2_read(port
->priv
, MVPP2_TXP_SCHED_TOKEN_SIZE_REG
);
4345 size
= val
& MVPP2_TXP_TOKEN_SIZE_MAX
;
4348 val
&= ~MVPP2_TXP_TOKEN_SIZE_MAX
;
4350 mvpp2_write(port
->priv
, MVPP2_TXP_SCHED_TOKEN_SIZE_REG
, val
);
4353 for (txq
= 0; txq
< txq_number
; txq
++) {
4354 val
= mvpp2_read(port
->priv
,
4355 MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq
));
4356 size
= val
& MVPP2_TXQ_TOKEN_SIZE_MAX
;
4360 val
&= ~MVPP2_TXQ_TOKEN_SIZE_MAX
;
4362 mvpp2_write(port
->priv
,
4363 MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq
),
4369 /* Set the number of packets that will be received before Rx interrupt
4370 * will be generated by HW.
4372 static void mvpp2_rx_pkts_coal_set(struct mvpp2_port
*port
,
4373 struct mvpp2_rx_queue
*rxq
, u32 pkts
)
4377 val
= (pkts
& MVPP2_OCCUPIED_THRESH_MASK
);
4378 mvpp2_write(port
->priv
, MVPP2_RXQ_NUM_REG
, rxq
->id
);
4379 mvpp2_write(port
->priv
, MVPP2_RXQ_THRESH_REG
, val
);
4381 rxq
->pkts_coal
= pkts
;
4384 /* Set the time delay in usec before Rx interrupt */
4385 static void mvpp2_rx_time_coal_set(struct mvpp2_port
*port
,
4386 struct mvpp2_rx_queue
*rxq
, u32 usec
)
4390 val
= (port
->priv
->tclk
/ USEC_PER_SEC
) * usec
;
4391 mvpp2_write(port
->priv
, MVPP2_ISR_RX_THRESHOLD_REG(rxq
->id
), val
);
4393 rxq
->time_coal
= usec
;
4396 /* Free Tx queue skbuffs */
4397 static void mvpp2_txq_bufs_free(struct mvpp2_port
*port
,
4398 struct mvpp2_tx_queue
*txq
,
4399 struct mvpp2_txq_pcpu
*txq_pcpu
, int num
)
4403 for (i
= 0; i
< num
; i
++) {
4404 dma_addr_t buf_phys_addr
=
4405 txq_pcpu
->tx_buffs
[txq_pcpu
->txq_get_index
];
4406 struct sk_buff
*skb
= txq_pcpu
->tx_skb
[txq_pcpu
->txq_get_index
];
4408 mvpp2_txq_inc_get(txq_pcpu
);
4410 dma_unmap_single(port
->dev
->dev
.parent
, buf_phys_addr
,
4411 skb_headlen(skb
), DMA_TO_DEVICE
);
4414 dev_kfree_skb_any(skb
);
4418 static inline struct mvpp2_rx_queue
*mvpp2_get_rx_queue(struct mvpp2_port
*port
,
4421 int queue
= fls(cause
) - 1;
4423 return port
->rxqs
[queue
];
4426 static inline struct mvpp2_tx_queue
*mvpp2_get_tx_queue(struct mvpp2_port
*port
,
4429 int queue
= fls(cause
) - 1;
4431 return port
->txqs
[queue
];
4434 /* Handle end of transmission */
4435 static void mvpp2_txq_done(struct mvpp2_port
*port
, struct mvpp2_tx_queue
*txq
,
4436 struct mvpp2_txq_pcpu
*txq_pcpu
)
4438 struct netdev_queue
*nq
= netdev_get_tx_queue(port
->dev
, txq
->log_id
);
4441 if (txq_pcpu
->cpu
!= smp_processor_id())
4442 netdev_err(port
->dev
, "wrong cpu on the end of Tx processing\n");
4444 tx_done
= mvpp2_txq_sent_desc_proc(port
, txq
);
4447 mvpp2_txq_bufs_free(port
, txq
, txq_pcpu
, tx_done
);
4449 txq_pcpu
->count
-= tx_done
;
4451 if (netif_tx_queue_stopped(nq
))
4452 if (txq_pcpu
->size
- txq_pcpu
->count
>= MAX_SKB_FRAGS
+ 1)
4453 netif_tx_wake_queue(nq
);
4456 static unsigned int mvpp2_tx_done(struct mvpp2_port
*port
, u32 cause
)
4458 struct mvpp2_tx_queue
*txq
;
4459 struct mvpp2_txq_pcpu
*txq_pcpu
;
4460 unsigned int tx_todo
= 0;
4463 txq
= mvpp2_get_tx_queue(port
, cause
);
4467 txq_pcpu
= this_cpu_ptr(txq
->pcpu
);
4469 if (txq_pcpu
->count
) {
4470 mvpp2_txq_done(port
, txq
, txq_pcpu
);
4471 tx_todo
+= txq_pcpu
->count
;
4474 cause
&= ~(1 << txq
->log_id
);
4479 /* Rx/Tx queue initialization/cleanup methods */
4481 /* Allocate and initialize descriptors for aggr TXQ */
4482 static int mvpp2_aggr_txq_init(struct platform_device
*pdev
,
4483 struct mvpp2_tx_queue
*aggr_txq
,
4484 int desc_num
, int cpu
,
4487 /* Allocate memory for TX descriptors */
4488 aggr_txq
->descs
= dma_alloc_coherent(&pdev
->dev
,
4489 desc_num
* MVPP2_DESC_ALIGNED_SIZE
,
4490 &aggr_txq
->descs_phys
, GFP_KERNEL
);
4491 if (!aggr_txq
->descs
)
4494 aggr_txq
->last_desc
= aggr_txq
->size
- 1;
4496 /* Aggr TXQ no reset WA */
4497 aggr_txq
->next_desc_to_proc
= mvpp2_read(priv
,
4498 MVPP2_AGGR_TXQ_INDEX_REG(cpu
));
4500 /* Set Tx descriptors queue starting address */
4501 /* indirect access */
4502 mvpp2_write(priv
, MVPP2_AGGR_TXQ_DESC_ADDR_REG(cpu
),
4503 aggr_txq
->descs_phys
);
4504 mvpp2_write(priv
, MVPP2_AGGR_TXQ_DESC_SIZE_REG(cpu
), desc_num
);
4509 /* Create a specified Rx queue */
4510 static int mvpp2_rxq_init(struct mvpp2_port
*port
,
4511 struct mvpp2_rx_queue
*rxq
)
4514 rxq
->size
= port
->rx_ring_size
;
4516 /* Allocate memory for RX descriptors */
4517 rxq
->descs
= dma_alloc_coherent(port
->dev
->dev
.parent
,
4518 rxq
->size
* MVPP2_DESC_ALIGNED_SIZE
,
4519 &rxq
->descs_phys
, GFP_KERNEL
);
4523 rxq
->last_desc
= rxq
->size
- 1;
4525 /* Zero occupied and non-occupied counters - direct access */
4526 mvpp2_write(port
->priv
, MVPP2_RXQ_STATUS_REG(rxq
->id
), 0);
4528 /* Set Rx descriptors queue starting address - indirect access */
4529 mvpp2_write(port
->priv
, MVPP2_RXQ_NUM_REG
, rxq
->id
);
4530 mvpp2_write(port
->priv
, MVPP2_RXQ_DESC_ADDR_REG
, rxq
->descs_phys
);
4531 mvpp2_write(port
->priv
, MVPP2_RXQ_DESC_SIZE_REG
, rxq
->size
);
4532 mvpp2_write(port
->priv
, MVPP2_RXQ_INDEX_REG
, 0);
4535 mvpp2_rxq_offset_set(port
, rxq
->id
, NET_SKB_PAD
);
4537 /* Set coalescing pkts and time */
4538 mvpp2_rx_pkts_coal_set(port
, rxq
, rxq
->pkts_coal
);
4539 mvpp2_rx_time_coal_set(port
, rxq
, rxq
->time_coal
);
4541 /* Add number of descriptors ready for receiving packets */
4542 mvpp2_rxq_status_update(port
, rxq
->id
, 0, rxq
->size
);
4547 /* Push packets received by the RXQ to BM pool */
4548 static void mvpp2_rxq_drop_pkts(struct mvpp2_port
*port
,
4549 struct mvpp2_rx_queue
*rxq
)
4553 rx_received
= mvpp2_rxq_received(port
, rxq
->id
);
4557 for (i
= 0; i
< rx_received
; i
++) {
4558 struct mvpp2_rx_desc
*rx_desc
= mvpp2_rxq_next_desc_get(rxq
);
4559 u32 bm
= mvpp2_bm_cookie_build(rx_desc
);
4561 mvpp2_pool_refill(port
, bm
, rx_desc
->buf_phys_addr
,
4562 rx_desc
->buf_cookie
);
4564 mvpp2_rxq_status_update(port
, rxq
->id
, rx_received
, rx_received
);
4567 /* Cleanup Rx queue */
4568 static void mvpp2_rxq_deinit(struct mvpp2_port
*port
,
4569 struct mvpp2_rx_queue
*rxq
)
4571 mvpp2_rxq_drop_pkts(port
, rxq
);
4574 dma_free_coherent(port
->dev
->dev
.parent
,
4575 rxq
->size
* MVPP2_DESC_ALIGNED_SIZE
,
4581 rxq
->next_desc_to_proc
= 0;
4582 rxq
->descs_phys
= 0;
4584 /* Clear Rx descriptors queue starting address and size;
4585 * free descriptor number
4587 mvpp2_write(port
->priv
, MVPP2_RXQ_STATUS_REG(rxq
->id
), 0);
4588 mvpp2_write(port
->priv
, MVPP2_RXQ_NUM_REG
, rxq
->id
);
4589 mvpp2_write(port
->priv
, MVPP2_RXQ_DESC_ADDR_REG
, 0);
4590 mvpp2_write(port
->priv
, MVPP2_RXQ_DESC_SIZE_REG
, 0);
4593 /* Create and initialize a Tx queue */
4594 static int mvpp2_txq_init(struct mvpp2_port
*port
,
4595 struct mvpp2_tx_queue
*txq
)
4598 int cpu
, desc
, desc_per_txq
, tx_port_num
;
4599 struct mvpp2_txq_pcpu
*txq_pcpu
;
4601 txq
->size
= port
->tx_ring_size
;
4603 /* Allocate memory for Tx descriptors */
4604 txq
->descs
= dma_alloc_coherent(port
->dev
->dev
.parent
,
4605 txq
->size
* MVPP2_DESC_ALIGNED_SIZE
,
4606 &txq
->descs_phys
, GFP_KERNEL
);
4610 txq
->last_desc
= txq
->size
- 1;
4612 /* Set Tx descriptors queue starting address - indirect access */
4613 mvpp2_write(port
->priv
, MVPP2_TXQ_NUM_REG
, txq
->id
);
4614 mvpp2_write(port
->priv
, MVPP2_TXQ_DESC_ADDR_REG
, txq
->descs_phys
);
4615 mvpp2_write(port
->priv
, MVPP2_TXQ_DESC_SIZE_REG
, txq
->size
&
4616 MVPP2_TXQ_DESC_SIZE_MASK
);
4617 mvpp2_write(port
->priv
, MVPP2_TXQ_INDEX_REG
, 0);
4618 mvpp2_write(port
->priv
, MVPP2_TXQ_RSVD_CLR_REG
,
4619 txq
->id
<< MVPP2_TXQ_RSVD_CLR_OFFSET
);
4620 val
= mvpp2_read(port
->priv
, MVPP2_TXQ_PENDING_REG
);
4621 val
&= ~MVPP2_TXQ_PENDING_MASK
;
4622 mvpp2_write(port
->priv
, MVPP2_TXQ_PENDING_REG
, val
);
4624 /* Calculate base address in prefetch buffer. We reserve 16 descriptors
4625 * for each existing TXQ.
4626 * TCONTS for PON port must be continuous from 0 to MVPP2_MAX_TCONT
4627 * GBE ports assumed to be continious from 0 to MVPP2_MAX_PORTS
4630 desc
= (port
->id
* MVPP2_MAX_TXQ
* desc_per_txq
) +
4631 (txq
->log_id
* desc_per_txq
);
4633 mvpp2_write(port
->priv
, MVPP2_TXQ_PREF_BUF_REG
,
4634 MVPP2_PREF_BUF_PTR(desc
) | MVPP2_PREF_BUF_SIZE_16
|
4635 MVPP2_PREF_BUF_THRESH(desc_per_txq
/2));
4637 /* WRR / EJP configuration - indirect access */
4638 tx_port_num
= mvpp2_egress_port(port
);
4639 mvpp2_write(port
->priv
, MVPP2_TXP_SCHED_PORT_INDEX_REG
, tx_port_num
);
4641 val
= mvpp2_read(port
->priv
, MVPP2_TXQ_SCHED_REFILL_REG(txq
->log_id
));
4642 val
&= ~MVPP2_TXQ_REFILL_PERIOD_ALL_MASK
;
4643 val
|= MVPP2_TXQ_REFILL_PERIOD_MASK(1);
4644 val
|= MVPP2_TXQ_REFILL_TOKENS_ALL_MASK
;
4645 mvpp2_write(port
->priv
, MVPP2_TXQ_SCHED_REFILL_REG(txq
->log_id
), val
);
4647 val
= MVPP2_TXQ_TOKEN_SIZE_MAX
;
4648 mvpp2_write(port
->priv
, MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq
->log_id
),
4651 for_each_present_cpu(cpu
) {
4652 txq_pcpu
= per_cpu_ptr(txq
->pcpu
, cpu
);
4653 txq_pcpu
->size
= txq
->size
;
4654 txq_pcpu
->tx_skb
= kmalloc(txq_pcpu
->size
*
4655 sizeof(*txq_pcpu
->tx_skb
),
4657 if (!txq_pcpu
->tx_skb
)
4660 txq_pcpu
->tx_buffs
= kmalloc(txq_pcpu
->size
*
4661 sizeof(dma_addr_t
), GFP_KERNEL
);
4662 if (!txq_pcpu
->tx_buffs
)
4665 txq_pcpu
->count
= 0;
4666 txq_pcpu
->reserved_num
= 0;
4667 txq_pcpu
->txq_put_index
= 0;
4668 txq_pcpu
->txq_get_index
= 0;
4674 for_each_present_cpu(cpu
) {
4675 txq_pcpu
= per_cpu_ptr(txq
->pcpu
, cpu
);
4676 kfree(txq_pcpu
->tx_skb
);
4677 kfree(txq_pcpu
->tx_buffs
);
4680 dma_free_coherent(port
->dev
->dev
.parent
,
4681 txq
->size
* MVPP2_DESC_ALIGNED_SIZE
,
4682 txq
->descs
, txq
->descs_phys
);
4687 /* Free allocated TXQ resources */
4688 static void mvpp2_txq_deinit(struct mvpp2_port
*port
,
4689 struct mvpp2_tx_queue
*txq
)
4691 struct mvpp2_txq_pcpu
*txq_pcpu
;
4694 for_each_present_cpu(cpu
) {
4695 txq_pcpu
= per_cpu_ptr(txq
->pcpu
, cpu
);
4696 kfree(txq_pcpu
->tx_skb
);
4697 kfree(txq_pcpu
->tx_buffs
);
4701 dma_free_coherent(port
->dev
->dev
.parent
,
4702 txq
->size
* MVPP2_DESC_ALIGNED_SIZE
,
4703 txq
->descs
, txq
->descs_phys
);
4707 txq
->next_desc_to_proc
= 0;
4708 txq
->descs_phys
= 0;
4710 /* Set minimum bandwidth for disabled TXQs */
4711 mvpp2_write(port
->priv
, MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(txq
->id
), 0);
4713 /* Set Tx descriptors queue starting address and size */
4714 mvpp2_write(port
->priv
, MVPP2_TXQ_NUM_REG
, txq
->id
);
4715 mvpp2_write(port
->priv
, MVPP2_TXQ_DESC_ADDR_REG
, 0);
4716 mvpp2_write(port
->priv
, MVPP2_TXQ_DESC_SIZE_REG
, 0);
4719 /* Cleanup Tx ports */
4720 static void mvpp2_txq_clean(struct mvpp2_port
*port
, struct mvpp2_tx_queue
*txq
)
4722 struct mvpp2_txq_pcpu
*txq_pcpu
;
4723 int delay
, pending
, cpu
;
4726 mvpp2_write(port
->priv
, MVPP2_TXQ_NUM_REG
, txq
->id
);
4727 val
= mvpp2_read(port
->priv
, MVPP2_TXQ_PREF_BUF_REG
);
4728 val
|= MVPP2_TXQ_DRAIN_EN_MASK
;
4729 mvpp2_write(port
->priv
, MVPP2_TXQ_PREF_BUF_REG
, val
);
4731 /* The napi queue has been stopped so wait for all packets
4732 * to be transmitted.
4736 if (delay
>= MVPP2_TX_PENDING_TIMEOUT_MSEC
) {
4737 netdev_warn(port
->dev
,
4738 "port %d: cleaning queue %d timed out\n",
4739 port
->id
, txq
->log_id
);
4745 pending
= mvpp2_txq_pend_desc_num_get(port
, txq
);
4748 val
&= ~MVPP2_TXQ_DRAIN_EN_MASK
;
4749 mvpp2_write(port
->priv
, MVPP2_TXQ_PREF_BUF_REG
, val
);
4751 for_each_present_cpu(cpu
) {
4752 txq_pcpu
= per_cpu_ptr(txq
->pcpu
, cpu
);
4754 /* Release all packets */
4755 mvpp2_txq_bufs_free(port
, txq
, txq_pcpu
, txq_pcpu
->count
);
4758 txq_pcpu
->count
= 0;
4759 txq_pcpu
->txq_put_index
= 0;
4760 txq_pcpu
->txq_get_index
= 0;
4764 /* Cleanup all Tx queues */
4765 static void mvpp2_cleanup_txqs(struct mvpp2_port
*port
)
4767 struct mvpp2_tx_queue
*txq
;
4771 val
= mvpp2_read(port
->priv
, MVPP2_TX_PORT_FLUSH_REG
);
4773 /* Reset Tx ports and delete Tx queues */
4774 val
|= MVPP2_TX_PORT_FLUSH_MASK(port
->id
);
4775 mvpp2_write(port
->priv
, MVPP2_TX_PORT_FLUSH_REG
, val
);
4777 for (queue
= 0; queue
< txq_number
; queue
++) {
4778 txq
= port
->txqs
[queue
];
4779 mvpp2_txq_clean(port
, txq
);
4780 mvpp2_txq_deinit(port
, txq
);
4783 on_each_cpu(mvpp2_txq_sent_counter_clear
, port
, 1);
4785 val
&= ~MVPP2_TX_PORT_FLUSH_MASK(port
->id
);
4786 mvpp2_write(port
->priv
, MVPP2_TX_PORT_FLUSH_REG
, val
);
4789 /* Cleanup all Rx queues */
4790 static void mvpp2_cleanup_rxqs(struct mvpp2_port
*port
)
4794 for (queue
= 0; queue
< rxq_number
; queue
++)
4795 mvpp2_rxq_deinit(port
, port
->rxqs
[queue
]);
4798 /* Init all Rx queues for port */
4799 static int mvpp2_setup_rxqs(struct mvpp2_port
*port
)
4803 for (queue
= 0; queue
< rxq_number
; queue
++) {
4804 err
= mvpp2_rxq_init(port
, port
->rxqs
[queue
]);
4811 mvpp2_cleanup_rxqs(port
);
4815 /* Init all tx queues for port */
4816 static int mvpp2_setup_txqs(struct mvpp2_port
*port
)
4818 struct mvpp2_tx_queue
*txq
;
4821 for (queue
= 0; queue
< txq_number
; queue
++) {
4822 txq
= port
->txqs
[queue
];
4823 err
= mvpp2_txq_init(port
, txq
);
4828 on_each_cpu(mvpp2_txq_sent_counter_clear
, port
, 1);
4832 mvpp2_cleanup_txqs(port
);
4836 /* The callback for per-port interrupt */
4837 static irqreturn_t
mvpp2_isr(int irq
, void *dev_id
)
4839 struct mvpp2_port
*port
= (struct mvpp2_port
*)dev_id
;
4841 mvpp2_interrupts_disable(port
);
4843 napi_schedule(&port
->napi
);
4849 static void mvpp2_link_event(struct net_device
*dev
)
4851 struct mvpp2_port
*port
= netdev_priv(dev
);
4852 struct phy_device
*phydev
= dev
->phydev
;
4853 int status_change
= 0;
4857 if ((port
->speed
!= phydev
->speed
) ||
4858 (port
->duplex
!= phydev
->duplex
)) {
4861 val
= readl(port
->base
+ MVPP2_GMAC_AUTONEG_CONFIG
);
4862 val
&= ~(MVPP2_GMAC_CONFIG_MII_SPEED
|
4863 MVPP2_GMAC_CONFIG_GMII_SPEED
|
4864 MVPP2_GMAC_CONFIG_FULL_DUPLEX
|
4865 MVPP2_GMAC_AN_SPEED_EN
|
4866 MVPP2_GMAC_AN_DUPLEX_EN
);
4869 val
|= MVPP2_GMAC_CONFIG_FULL_DUPLEX
;
4871 if (phydev
->speed
== SPEED_1000
)
4872 val
|= MVPP2_GMAC_CONFIG_GMII_SPEED
;
4873 else if (phydev
->speed
== SPEED_100
)
4874 val
|= MVPP2_GMAC_CONFIG_MII_SPEED
;
4876 writel(val
, port
->base
+ MVPP2_GMAC_AUTONEG_CONFIG
);
4878 port
->duplex
= phydev
->duplex
;
4879 port
->speed
= phydev
->speed
;
4883 if (phydev
->link
!= port
->link
) {
4884 if (!phydev
->link
) {
4889 port
->link
= phydev
->link
;
4893 if (status_change
) {
4895 val
= readl(port
->base
+ MVPP2_GMAC_AUTONEG_CONFIG
);
4896 val
|= (MVPP2_GMAC_FORCE_LINK_PASS
|
4897 MVPP2_GMAC_FORCE_LINK_DOWN
);
4898 writel(val
, port
->base
+ MVPP2_GMAC_AUTONEG_CONFIG
);
4899 mvpp2_egress_enable(port
);
4900 mvpp2_ingress_enable(port
);
4902 mvpp2_ingress_disable(port
);
4903 mvpp2_egress_disable(port
);
4905 phy_print_status(phydev
);
4909 static void mvpp2_timer_set(struct mvpp2_port_pcpu
*port_pcpu
)
4913 if (!port_pcpu
->timer_scheduled
) {
4914 port_pcpu
->timer_scheduled
= true;
4915 interval
= ktime_set(0, MVPP2_TXDONE_HRTIMER_PERIOD_NS
);
4916 hrtimer_start(&port_pcpu
->tx_done_timer
, interval
,
4917 HRTIMER_MODE_REL_PINNED
);
4921 static void mvpp2_tx_proc_cb(unsigned long data
)
4923 struct net_device
*dev
= (struct net_device
*)data
;
4924 struct mvpp2_port
*port
= netdev_priv(dev
);
4925 struct mvpp2_port_pcpu
*port_pcpu
= this_cpu_ptr(port
->pcpu
);
4926 unsigned int tx_todo
, cause
;
4928 if (!netif_running(dev
))
4930 port_pcpu
->timer_scheduled
= false;
4932 /* Process all the Tx queues */
4933 cause
= (1 << txq_number
) - 1;
4934 tx_todo
= mvpp2_tx_done(port
, cause
);
4936 /* Set the timer in case not all the packets were processed */
4938 mvpp2_timer_set(port_pcpu
);
4941 static enum hrtimer_restart
mvpp2_hr_timer_cb(struct hrtimer
*timer
)
4943 struct mvpp2_port_pcpu
*port_pcpu
= container_of(timer
,
4944 struct mvpp2_port_pcpu
,
4947 tasklet_schedule(&port_pcpu
->tx_done_tasklet
);
4949 return HRTIMER_NORESTART
;
4952 /* Main RX/TX processing routines */
4954 /* Display more error info */
4955 static void mvpp2_rx_error(struct mvpp2_port
*port
,
4956 struct mvpp2_rx_desc
*rx_desc
)
4958 u32 status
= rx_desc
->status
;
4960 switch (status
& MVPP2_RXD_ERR_CODE_MASK
) {
4961 case MVPP2_RXD_ERR_CRC
:
4962 netdev_err(port
->dev
, "bad rx status %08x (crc error), size=%d\n",
4963 status
, rx_desc
->data_size
);
4965 case MVPP2_RXD_ERR_OVERRUN
:
4966 netdev_err(port
->dev
, "bad rx status %08x (overrun error), size=%d\n",
4967 status
, rx_desc
->data_size
);
4969 case MVPP2_RXD_ERR_RESOURCE
:
4970 netdev_err(port
->dev
, "bad rx status %08x (resource error), size=%d\n",
4971 status
, rx_desc
->data_size
);
4976 /* Handle RX checksum offload */
4977 static void mvpp2_rx_csum(struct mvpp2_port
*port
, u32 status
,
4978 struct sk_buff
*skb
)
4980 if (((status
& MVPP2_RXD_L3_IP4
) &&
4981 !(status
& MVPP2_RXD_IP4_HEADER_ERR
)) ||
4982 (status
& MVPP2_RXD_L3_IP6
))
4983 if (((status
& MVPP2_RXD_L4_UDP
) ||
4984 (status
& MVPP2_RXD_L4_TCP
)) &&
4985 (status
& MVPP2_RXD_L4_CSUM_OK
)) {
4987 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
4991 skb
->ip_summed
= CHECKSUM_NONE
;
4994 /* Reuse skb if possible, or allocate a new skb and add it to BM pool */
4995 static int mvpp2_rx_refill(struct mvpp2_port
*port
,
4996 struct mvpp2_bm_pool
*bm_pool
,
4997 u32 bm
, int is_recycle
)
4999 struct sk_buff
*skb
;
5000 dma_addr_t phys_addr
;
5003 (atomic_read(&bm_pool
->in_use
) < bm_pool
->in_use_thresh
))
5006 /* No recycle or too many buffers are in use, so allocate a new skb */
5007 skb
= mvpp2_skb_alloc(port
, bm_pool
, &phys_addr
, GFP_ATOMIC
);
5011 mvpp2_pool_refill(port
, bm
, (u32
)phys_addr
, (u32
)skb
);
5012 atomic_dec(&bm_pool
->in_use
);
5016 /* Handle tx checksum */
5017 static u32
mvpp2_skb_tx_csum(struct mvpp2_port
*port
, struct sk_buff
*skb
)
5019 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
5023 if (skb
->protocol
== htons(ETH_P_IP
)) {
5024 struct iphdr
*ip4h
= ip_hdr(skb
);
5026 /* Calculate IPv4 checksum and L4 checksum */
5027 ip_hdr_len
= ip4h
->ihl
;
5028 l4_proto
= ip4h
->protocol
;
5029 } else if (skb
->protocol
== htons(ETH_P_IPV6
)) {
5030 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
5032 /* Read l4_protocol from one of IPv6 extra headers */
5033 if (skb_network_header_len(skb
) > 0)
5034 ip_hdr_len
= (skb_network_header_len(skb
) >> 2);
5035 l4_proto
= ip6h
->nexthdr
;
5037 return MVPP2_TXD_L4_CSUM_NOT
;
5040 return mvpp2_txq_desc_csum(skb_network_offset(skb
),
5041 skb
->protocol
, ip_hdr_len
, l4_proto
);
5044 return MVPP2_TXD_L4_CSUM_NOT
| MVPP2_TXD_IP_CSUM_DISABLE
;
5047 static void mvpp2_buff_hdr_rx(struct mvpp2_port
*port
,
5048 struct mvpp2_rx_desc
*rx_desc
)
5050 struct mvpp2_buff_hdr
*buff_hdr
;
5051 struct sk_buff
*skb
;
5052 u32 rx_status
= rx_desc
->status
;
5055 u32 buff_phys_addr_next
;
5056 u32 buff_virt_addr_next
;
5060 pool_id
= (rx_status
& MVPP2_RXD_BM_POOL_ID_MASK
) >>
5061 MVPP2_RXD_BM_POOL_ID_OFFS
;
5062 buff_phys_addr
= rx_desc
->buf_phys_addr
;
5063 buff_virt_addr
= rx_desc
->buf_cookie
;
5066 skb
= (struct sk_buff
*)buff_virt_addr
;
5067 buff_hdr
= (struct mvpp2_buff_hdr
*)skb
->head
;
5069 mc_id
= MVPP2_B_HDR_INFO_MC_ID(buff_hdr
->info
);
5071 buff_phys_addr_next
= buff_hdr
->next_buff_phys_addr
;
5072 buff_virt_addr_next
= buff_hdr
->next_buff_virt_addr
;
5074 /* Release buffer */
5075 mvpp2_bm_pool_mc_put(port
, pool_id
, buff_phys_addr
,
5076 buff_virt_addr
, mc_id
);
5078 buff_phys_addr
= buff_phys_addr_next
;
5079 buff_virt_addr
= buff_virt_addr_next
;
5081 } while (!MVPP2_B_HDR_INFO_IS_LAST(buff_hdr
->info
));
5084 /* Main rx processing */
5085 static int mvpp2_rx(struct mvpp2_port
*port
, int rx_todo
,
5086 struct mvpp2_rx_queue
*rxq
)
5088 struct net_device
*dev
= port
->dev
;
5094 /* Get number of received packets and clamp the to-do */
5095 rx_received
= mvpp2_rxq_received(port
, rxq
->id
);
5096 if (rx_todo
> rx_received
)
5097 rx_todo
= rx_received
;
5099 while (rx_done
< rx_todo
) {
5100 struct mvpp2_rx_desc
*rx_desc
= mvpp2_rxq_next_desc_get(rxq
);
5101 struct mvpp2_bm_pool
*bm_pool
;
5102 struct sk_buff
*skb
;
5103 dma_addr_t phys_addr
;
5105 int pool
, rx_bytes
, err
;
5108 rx_status
= rx_desc
->status
;
5109 rx_bytes
= rx_desc
->data_size
- MVPP2_MH_SIZE
;
5110 phys_addr
= rx_desc
->buf_phys_addr
;
5112 bm
= mvpp2_bm_cookie_build(rx_desc
);
5113 pool
= mvpp2_bm_cookie_pool_get(bm
);
5114 bm_pool
= &port
->priv
->bm_pools
[pool
];
5115 /* Check if buffer header is used */
5116 if (rx_status
& MVPP2_RXD_BUF_HDR
) {
5117 mvpp2_buff_hdr_rx(port
, rx_desc
);
5121 /* In case of an error, release the requested buffer pointer
5122 * to the Buffer Manager. This request process is controlled
5123 * by the hardware, and the information about the buffer is
5124 * comprised by the RX descriptor.
5126 if (rx_status
& MVPP2_RXD_ERR_SUMMARY
) {
5128 dev
->stats
.rx_errors
++;
5129 mvpp2_rx_error(port
, rx_desc
);
5130 /* Return the buffer to the pool */
5131 mvpp2_pool_refill(port
, bm
, rx_desc
->buf_phys_addr
,
5132 rx_desc
->buf_cookie
);
5136 skb
= (struct sk_buff
*)rx_desc
->buf_cookie
;
5138 err
= mvpp2_rx_refill(port
, bm_pool
, bm
, 0);
5140 netdev_err(port
->dev
, "failed to refill BM pools\n");
5141 goto err_drop_frame
;
5144 dma_unmap_single(dev
->dev
.parent
, phys_addr
,
5145 bm_pool
->buf_size
, DMA_FROM_DEVICE
);
5148 rcvd_bytes
+= rx_bytes
;
5149 atomic_inc(&bm_pool
->in_use
);
5151 skb_reserve(skb
, MVPP2_MH_SIZE
);
5152 skb_put(skb
, rx_bytes
);
5153 skb
->protocol
= eth_type_trans(skb
, dev
);
5154 mvpp2_rx_csum(port
, rx_status
, skb
);
5156 napi_gro_receive(&port
->napi
, skb
);
5160 struct mvpp2_pcpu_stats
*stats
= this_cpu_ptr(port
->stats
);
5162 u64_stats_update_begin(&stats
->syncp
);
5163 stats
->rx_packets
+= rcvd_pkts
;
5164 stats
->rx_bytes
+= rcvd_bytes
;
5165 u64_stats_update_end(&stats
->syncp
);
5168 /* Update Rx queue management counters */
5170 mvpp2_rxq_status_update(port
, rxq
->id
, rx_done
, rx_done
);
5176 tx_desc_unmap_put(struct device
*dev
, struct mvpp2_tx_queue
*txq
,
5177 struct mvpp2_tx_desc
*desc
)
5179 dma_unmap_single(dev
, desc
->buf_phys_addr
,
5180 desc
->data_size
, DMA_TO_DEVICE
);
5181 mvpp2_txq_desc_put(txq
);
5184 /* Handle tx fragmentation processing */
5185 static int mvpp2_tx_frag_process(struct mvpp2_port
*port
, struct sk_buff
*skb
,
5186 struct mvpp2_tx_queue
*aggr_txq
,
5187 struct mvpp2_tx_queue
*txq
)
5189 struct mvpp2_txq_pcpu
*txq_pcpu
= this_cpu_ptr(txq
->pcpu
);
5190 struct mvpp2_tx_desc
*tx_desc
;
5192 dma_addr_t buf_phys_addr
;
5194 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
5195 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
5196 void *addr
= page_address(frag
->page
.p
) + frag
->page_offset
;
5198 tx_desc
= mvpp2_txq_next_desc_get(aggr_txq
);
5199 tx_desc
->phys_txq
= txq
->id
;
5200 tx_desc
->data_size
= frag
->size
;
5202 buf_phys_addr
= dma_map_single(port
->dev
->dev
.parent
, addr
,
5205 if (dma_mapping_error(port
->dev
->dev
.parent
, buf_phys_addr
)) {
5206 mvpp2_txq_desc_put(txq
);
5210 tx_desc
->packet_offset
= buf_phys_addr
& MVPP2_TX_DESC_ALIGN
;
5211 tx_desc
->buf_phys_addr
= buf_phys_addr
& (~MVPP2_TX_DESC_ALIGN
);
5213 if (i
== (skb_shinfo(skb
)->nr_frags
- 1)) {
5214 /* Last descriptor */
5215 tx_desc
->command
= MVPP2_TXD_L_DESC
;
5216 mvpp2_txq_inc_put(txq_pcpu
, skb
, tx_desc
);
5218 /* Descriptor in the middle: Not First, Not Last */
5219 tx_desc
->command
= 0;
5220 mvpp2_txq_inc_put(txq_pcpu
, NULL
, tx_desc
);
5227 /* Release all descriptors that were used to map fragments of
5228 * this packet, as well as the corresponding DMA mappings
5230 for (i
= i
- 1; i
>= 0; i
--) {
5231 tx_desc
= txq
->descs
+ i
;
5232 tx_desc_unmap_put(port
->dev
->dev
.parent
, txq
, tx_desc
);
5238 /* Main tx processing */
5239 static int mvpp2_tx(struct sk_buff
*skb
, struct net_device
*dev
)
5241 struct mvpp2_port
*port
= netdev_priv(dev
);
5242 struct mvpp2_tx_queue
*txq
, *aggr_txq
;
5243 struct mvpp2_txq_pcpu
*txq_pcpu
;
5244 struct mvpp2_tx_desc
*tx_desc
;
5245 dma_addr_t buf_phys_addr
;
5250 txq_id
= skb_get_queue_mapping(skb
);
5251 txq
= port
->txqs
[txq_id
];
5252 txq_pcpu
= this_cpu_ptr(txq
->pcpu
);
5253 aggr_txq
= &port
->priv
->aggr_txqs
[smp_processor_id()];
5255 frags
= skb_shinfo(skb
)->nr_frags
+ 1;
5257 /* Check number of available descriptors */
5258 if (mvpp2_aggr_desc_num_check(port
->priv
, aggr_txq
, frags
) ||
5259 mvpp2_txq_reserved_desc_num_proc(port
->priv
, txq
,
5265 /* Get a descriptor for the first part of the packet */
5266 tx_desc
= mvpp2_txq_next_desc_get(aggr_txq
);
5267 tx_desc
->phys_txq
= txq
->id
;
5268 tx_desc
->data_size
= skb_headlen(skb
);
5270 buf_phys_addr
= dma_map_single(dev
->dev
.parent
, skb
->data
,
5271 tx_desc
->data_size
, DMA_TO_DEVICE
);
5272 if (unlikely(dma_mapping_error(dev
->dev
.parent
, buf_phys_addr
))) {
5273 mvpp2_txq_desc_put(txq
);
5277 tx_desc
->packet_offset
= buf_phys_addr
& MVPP2_TX_DESC_ALIGN
;
5278 tx_desc
->buf_phys_addr
= buf_phys_addr
& ~MVPP2_TX_DESC_ALIGN
;
5280 tx_cmd
= mvpp2_skb_tx_csum(port
, skb
);
5283 /* First and Last descriptor */
5284 tx_cmd
|= MVPP2_TXD_F_DESC
| MVPP2_TXD_L_DESC
;
5285 tx_desc
->command
= tx_cmd
;
5286 mvpp2_txq_inc_put(txq_pcpu
, skb
, tx_desc
);
5288 /* First but not Last */
5289 tx_cmd
|= MVPP2_TXD_F_DESC
| MVPP2_TXD_PADDING_DISABLE
;
5290 tx_desc
->command
= tx_cmd
;
5291 mvpp2_txq_inc_put(txq_pcpu
, NULL
, tx_desc
);
5293 /* Continue with other skb fragments */
5294 if (mvpp2_tx_frag_process(port
, skb
, aggr_txq
, txq
)) {
5295 tx_desc_unmap_put(port
->dev
->dev
.parent
, txq
, tx_desc
);
5301 txq_pcpu
->reserved_num
-= frags
;
5302 txq_pcpu
->count
+= frags
;
5303 aggr_txq
->count
+= frags
;
5305 /* Enable transmit */
5307 mvpp2_aggr_txq_pend_desc_add(port
, frags
);
5309 if (txq_pcpu
->size
- txq_pcpu
->count
< MAX_SKB_FRAGS
+ 1) {
5310 struct netdev_queue
*nq
= netdev_get_tx_queue(dev
, txq_id
);
5312 netif_tx_stop_queue(nq
);
5316 struct mvpp2_pcpu_stats
*stats
= this_cpu_ptr(port
->stats
);
5318 u64_stats_update_begin(&stats
->syncp
);
5319 stats
->tx_packets
++;
5320 stats
->tx_bytes
+= skb
->len
;
5321 u64_stats_update_end(&stats
->syncp
);
5323 dev
->stats
.tx_dropped
++;
5324 dev_kfree_skb_any(skb
);
5327 /* Finalize TX processing */
5328 if (txq_pcpu
->count
>= txq
->done_pkts_coal
)
5329 mvpp2_txq_done(port
, txq
, txq_pcpu
);
5331 /* Set the timer in case not all frags were processed */
5332 if (txq_pcpu
->count
<= frags
&& txq_pcpu
->count
> 0) {
5333 struct mvpp2_port_pcpu
*port_pcpu
= this_cpu_ptr(port
->pcpu
);
5335 mvpp2_timer_set(port_pcpu
);
5338 return NETDEV_TX_OK
;
5341 static inline void mvpp2_cause_error(struct net_device
*dev
, int cause
)
5343 if (cause
& MVPP2_CAUSE_FCS_ERR_MASK
)
5344 netdev_err(dev
, "FCS error\n");
5345 if (cause
& MVPP2_CAUSE_RX_FIFO_OVERRUN_MASK
)
5346 netdev_err(dev
, "rx fifo overrun error\n");
5347 if (cause
& MVPP2_CAUSE_TX_FIFO_UNDERRUN_MASK
)
5348 netdev_err(dev
, "tx fifo underrun error\n");
5351 static int mvpp2_poll(struct napi_struct
*napi
, int budget
)
5353 u32 cause_rx_tx
, cause_rx
, cause_misc
;
5355 struct mvpp2_port
*port
= netdev_priv(napi
->dev
);
5357 /* Rx/Tx cause register
5359 * Bits 0-15: each bit indicates received packets on the Rx queue
5360 * (bit 0 is for Rx queue 0).
5362 * Bits 16-23: each bit indicates transmitted packets on the Tx queue
5363 * (bit 16 is for Tx queue 0).
5365 * Each CPU has its own Rx/Tx cause register
5367 cause_rx_tx
= mvpp2_read(port
->priv
,
5368 MVPP2_ISR_RX_TX_CAUSE_REG(port
->id
));
5369 cause_rx_tx
&= ~MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK
;
5370 cause_misc
= cause_rx_tx
& MVPP2_CAUSE_MISC_SUM_MASK
;
5373 mvpp2_cause_error(port
->dev
, cause_misc
);
5375 /* Clear the cause register */
5376 mvpp2_write(port
->priv
, MVPP2_ISR_MISC_CAUSE_REG
, 0);
5377 mvpp2_write(port
->priv
, MVPP2_ISR_RX_TX_CAUSE_REG(port
->id
),
5378 cause_rx_tx
& ~MVPP2_CAUSE_MISC_SUM_MASK
);
5381 cause_rx
= cause_rx_tx
& MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK
;
5383 /* Process RX packets */
5384 cause_rx
|= port
->pending_cause_rx
;
5385 while (cause_rx
&& budget
> 0) {
5387 struct mvpp2_rx_queue
*rxq
;
5389 rxq
= mvpp2_get_rx_queue(port
, cause_rx
);
5393 count
= mvpp2_rx(port
, budget
, rxq
);
5397 /* Clear the bit associated to this Rx queue
5398 * so that next iteration will continue from
5399 * the next Rx queue.
5401 cause_rx
&= ~(1 << rxq
->logic_rxq
);
5407 napi_complete(napi
);
5409 mvpp2_interrupts_enable(port
);
5411 port
->pending_cause_rx
= cause_rx
;
5415 /* Set hw internals when starting port */
5416 static void mvpp2_start_dev(struct mvpp2_port
*port
)
5418 struct net_device
*ndev
= port
->dev
;
5420 mvpp2_gmac_max_rx_size_set(port
);
5421 mvpp2_txp_max_tx_size_set(port
);
5423 napi_enable(&port
->napi
);
5425 /* Enable interrupts on all CPUs */
5426 mvpp2_interrupts_enable(port
);
5428 mvpp2_port_enable(port
);
5429 phy_start(ndev
->phydev
);
5430 netif_tx_start_all_queues(port
->dev
);
5433 /* Set hw internals when stopping port */
5434 static void mvpp2_stop_dev(struct mvpp2_port
*port
)
5436 struct net_device
*ndev
= port
->dev
;
5438 /* Stop new packets from arriving to RXQs */
5439 mvpp2_ingress_disable(port
);
5443 /* Disable interrupts on all CPUs */
5444 mvpp2_interrupts_disable(port
);
5446 napi_disable(&port
->napi
);
5448 netif_carrier_off(port
->dev
);
5449 netif_tx_stop_all_queues(port
->dev
);
5451 mvpp2_egress_disable(port
);
5452 mvpp2_port_disable(port
);
5453 phy_stop(ndev
->phydev
);
5456 /* Return positive if MTU is valid */
5457 static inline int mvpp2_check_mtu_valid(struct net_device
*dev
, int mtu
)
5460 netdev_err(dev
, "cannot change mtu to less than 68\n");
5464 /* 9676 == 9700 - 20 and rounding to 8 */
5466 netdev_info(dev
, "illegal MTU value %d, round to 9676\n", mtu
);
5470 if (!IS_ALIGNED(MVPP2_RX_PKT_SIZE(mtu
), 8)) {
5471 netdev_info(dev
, "illegal MTU value %d, round to %d\n", mtu
,
5472 ALIGN(MVPP2_RX_PKT_SIZE(mtu
), 8));
5473 mtu
= ALIGN(MVPP2_RX_PKT_SIZE(mtu
), 8);
5479 static int mvpp2_check_ringparam_valid(struct net_device
*dev
,
5480 struct ethtool_ringparam
*ring
)
5482 u16 new_rx_pending
= ring
->rx_pending
;
5483 u16 new_tx_pending
= ring
->tx_pending
;
5485 if (ring
->rx_pending
== 0 || ring
->tx_pending
== 0)
5488 if (ring
->rx_pending
> MVPP2_MAX_RXD
)
5489 new_rx_pending
= MVPP2_MAX_RXD
;
5490 else if (!IS_ALIGNED(ring
->rx_pending
, 16))
5491 new_rx_pending
= ALIGN(ring
->rx_pending
, 16);
5493 if (ring
->tx_pending
> MVPP2_MAX_TXD
)
5494 new_tx_pending
= MVPP2_MAX_TXD
;
5495 else if (!IS_ALIGNED(ring
->tx_pending
, 32))
5496 new_tx_pending
= ALIGN(ring
->tx_pending
, 32);
5498 if (ring
->rx_pending
!= new_rx_pending
) {
5499 netdev_info(dev
, "illegal Rx ring size value %d, round to %d\n",
5500 ring
->rx_pending
, new_rx_pending
);
5501 ring
->rx_pending
= new_rx_pending
;
5504 if (ring
->tx_pending
!= new_tx_pending
) {
5505 netdev_info(dev
, "illegal Tx ring size value %d, round to %d\n",
5506 ring
->tx_pending
, new_tx_pending
);
5507 ring
->tx_pending
= new_tx_pending
;
5513 static void mvpp2_get_mac_address(struct mvpp2_port
*port
, unsigned char *addr
)
5515 u32 mac_addr_l
, mac_addr_m
, mac_addr_h
;
5517 mac_addr_l
= readl(port
->base
+ MVPP2_GMAC_CTRL_1_REG
);
5518 mac_addr_m
= readl(port
->priv
->lms_base
+ MVPP2_SRC_ADDR_MIDDLE
);
5519 mac_addr_h
= readl(port
->priv
->lms_base
+ MVPP2_SRC_ADDR_HIGH
);
5520 addr
[0] = (mac_addr_h
>> 24) & 0xFF;
5521 addr
[1] = (mac_addr_h
>> 16) & 0xFF;
5522 addr
[2] = (mac_addr_h
>> 8) & 0xFF;
5523 addr
[3] = mac_addr_h
& 0xFF;
5524 addr
[4] = mac_addr_m
& 0xFF;
5525 addr
[5] = (mac_addr_l
>> MVPP2_GMAC_SA_LOW_OFFS
) & 0xFF;
5528 static int mvpp2_phy_connect(struct mvpp2_port
*port
)
5530 struct phy_device
*phy_dev
;
5532 phy_dev
= of_phy_connect(port
->dev
, port
->phy_node
, mvpp2_link_event
, 0,
5533 port
->phy_interface
);
5535 netdev_err(port
->dev
, "cannot connect to phy\n");
5538 phy_dev
->supported
&= PHY_GBIT_FEATURES
;
5539 phy_dev
->advertising
= phy_dev
->supported
;
5548 static void mvpp2_phy_disconnect(struct mvpp2_port
*port
)
5550 struct net_device
*ndev
= port
->dev
;
5552 phy_disconnect(ndev
->phydev
);
5555 static int mvpp2_open(struct net_device
*dev
)
5557 struct mvpp2_port
*port
= netdev_priv(dev
);
5558 unsigned char mac_bcast
[ETH_ALEN
] = {
5559 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
5562 err
= mvpp2_prs_mac_da_accept(port
->priv
, port
->id
, mac_bcast
, true);
5564 netdev_err(dev
, "mvpp2_prs_mac_da_accept BC failed\n");
5567 err
= mvpp2_prs_mac_da_accept(port
->priv
, port
->id
,
5568 dev
->dev_addr
, true);
5570 netdev_err(dev
, "mvpp2_prs_mac_da_accept MC failed\n");
5573 err
= mvpp2_prs_tag_mode_set(port
->priv
, port
->id
, MVPP2_TAG_TYPE_MH
);
5575 netdev_err(dev
, "mvpp2_prs_tag_mode_set failed\n");
5578 err
= mvpp2_prs_def_flow(port
);
5580 netdev_err(dev
, "mvpp2_prs_def_flow failed\n");
5584 /* Allocate the Rx/Tx queues */
5585 err
= mvpp2_setup_rxqs(port
);
5587 netdev_err(port
->dev
, "cannot allocate Rx queues\n");
5591 err
= mvpp2_setup_txqs(port
);
5593 netdev_err(port
->dev
, "cannot allocate Tx queues\n");
5594 goto err_cleanup_rxqs
;
5597 err
= request_irq(port
->irq
, mvpp2_isr
, 0, dev
->name
, port
);
5599 netdev_err(port
->dev
, "cannot request IRQ %d\n", port
->irq
);
5600 goto err_cleanup_txqs
;
5603 /* In default link is down */
5604 netif_carrier_off(port
->dev
);
5606 err
= mvpp2_phy_connect(port
);
5610 /* Unmask interrupts on all CPUs */
5611 on_each_cpu(mvpp2_interrupts_unmask
, port
, 1);
5613 mvpp2_start_dev(port
);
5618 free_irq(port
->irq
, port
);
5620 mvpp2_cleanup_txqs(port
);
5622 mvpp2_cleanup_rxqs(port
);
5626 static int mvpp2_stop(struct net_device
*dev
)
5628 struct mvpp2_port
*port
= netdev_priv(dev
);
5629 struct mvpp2_port_pcpu
*port_pcpu
;
5632 mvpp2_stop_dev(port
);
5633 mvpp2_phy_disconnect(port
);
5635 /* Mask interrupts on all CPUs */
5636 on_each_cpu(mvpp2_interrupts_mask
, port
, 1);
5638 free_irq(port
->irq
, port
);
5639 for_each_present_cpu(cpu
) {
5640 port_pcpu
= per_cpu_ptr(port
->pcpu
, cpu
);
5642 hrtimer_cancel(&port_pcpu
->tx_done_timer
);
5643 port_pcpu
->timer_scheduled
= false;
5644 tasklet_kill(&port_pcpu
->tx_done_tasklet
);
5646 mvpp2_cleanup_rxqs(port
);
5647 mvpp2_cleanup_txqs(port
);
5652 static void mvpp2_set_rx_mode(struct net_device
*dev
)
5654 struct mvpp2_port
*port
= netdev_priv(dev
);
5655 struct mvpp2
*priv
= port
->priv
;
5656 struct netdev_hw_addr
*ha
;
5658 bool allmulti
= dev
->flags
& IFF_ALLMULTI
;
5660 mvpp2_prs_mac_promisc_set(priv
, id
, dev
->flags
& IFF_PROMISC
);
5661 mvpp2_prs_mac_multi_set(priv
, id
, MVPP2_PE_MAC_MC_ALL
, allmulti
);
5662 mvpp2_prs_mac_multi_set(priv
, id
, MVPP2_PE_MAC_MC_IP6
, allmulti
);
5664 /* Remove all port->id's mcast enries */
5665 mvpp2_prs_mcast_del_all(priv
, id
);
5667 if (allmulti
&& !netdev_mc_empty(dev
)) {
5668 netdev_for_each_mc_addr(ha
, dev
)
5669 mvpp2_prs_mac_da_accept(priv
, id
, ha
->addr
, true);
5673 static int mvpp2_set_mac_address(struct net_device
*dev
, void *p
)
5675 struct mvpp2_port
*port
= netdev_priv(dev
);
5676 const struct sockaddr
*addr
= p
;
5679 if (!is_valid_ether_addr(addr
->sa_data
)) {
5680 err
= -EADDRNOTAVAIL
;
5684 if (!netif_running(dev
)) {
5685 err
= mvpp2_prs_update_mac_da(dev
, addr
->sa_data
);
5688 /* Reconfigure parser to accept the original MAC address */
5689 err
= mvpp2_prs_update_mac_da(dev
, dev
->dev_addr
);
5694 mvpp2_stop_dev(port
);
5696 err
= mvpp2_prs_update_mac_da(dev
, addr
->sa_data
);
5700 /* Reconfigure parser accept the original MAC address */
5701 err
= mvpp2_prs_update_mac_da(dev
, dev
->dev_addr
);
5705 mvpp2_start_dev(port
);
5706 mvpp2_egress_enable(port
);
5707 mvpp2_ingress_enable(port
);
5711 netdev_err(dev
, "fail to change MAC address\n");
5715 static int mvpp2_change_mtu(struct net_device
*dev
, int mtu
)
5717 struct mvpp2_port
*port
= netdev_priv(dev
);
5720 mtu
= mvpp2_check_mtu_valid(dev
, mtu
);
5726 if (!netif_running(dev
)) {
5727 err
= mvpp2_bm_update_mtu(dev
, mtu
);
5729 port
->pkt_size
= MVPP2_RX_PKT_SIZE(mtu
);
5733 /* Reconfigure BM to the original MTU */
5734 err
= mvpp2_bm_update_mtu(dev
, dev
->mtu
);
5739 mvpp2_stop_dev(port
);
5741 err
= mvpp2_bm_update_mtu(dev
, mtu
);
5743 port
->pkt_size
= MVPP2_RX_PKT_SIZE(mtu
);
5747 /* Reconfigure BM to the original MTU */
5748 err
= mvpp2_bm_update_mtu(dev
, dev
->mtu
);
5753 mvpp2_start_dev(port
);
5754 mvpp2_egress_enable(port
);
5755 mvpp2_ingress_enable(port
);
5760 netdev_err(dev
, "fail to change MTU\n");
5764 static struct rtnl_link_stats64
*
5765 mvpp2_get_stats64(struct net_device
*dev
, struct rtnl_link_stats64
*stats
)
5767 struct mvpp2_port
*port
= netdev_priv(dev
);
5771 for_each_possible_cpu(cpu
) {
5772 struct mvpp2_pcpu_stats
*cpu_stats
;
5778 cpu_stats
= per_cpu_ptr(port
->stats
, cpu
);
5780 start
= u64_stats_fetch_begin_irq(&cpu_stats
->syncp
);
5781 rx_packets
= cpu_stats
->rx_packets
;
5782 rx_bytes
= cpu_stats
->rx_bytes
;
5783 tx_packets
= cpu_stats
->tx_packets
;
5784 tx_bytes
= cpu_stats
->tx_bytes
;
5785 } while (u64_stats_fetch_retry_irq(&cpu_stats
->syncp
, start
));
5787 stats
->rx_packets
+= rx_packets
;
5788 stats
->rx_bytes
+= rx_bytes
;
5789 stats
->tx_packets
+= tx_packets
;
5790 stats
->tx_bytes
+= tx_bytes
;
5793 stats
->rx_errors
= dev
->stats
.rx_errors
;
5794 stats
->rx_dropped
= dev
->stats
.rx_dropped
;
5795 stats
->tx_dropped
= dev
->stats
.tx_dropped
;
5800 static int mvpp2_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
5807 ret
= phy_mii_ioctl(dev
->phydev
, ifr
, cmd
);
5809 mvpp2_link_event(dev
);
5814 /* Ethtool methods */
5816 /* Set interrupt coalescing for ethtools */
5817 static int mvpp2_ethtool_set_coalesce(struct net_device
*dev
,
5818 struct ethtool_coalesce
*c
)
5820 struct mvpp2_port
*port
= netdev_priv(dev
);
5823 for (queue
= 0; queue
< rxq_number
; queue
++) {
5824 struct mvpp2_rx_queue
*rxq
= port
->rxqs
[queue
];
5826 rxq
->time_coal
= c
->rx_coalesce_usecs
;
5827 rxq
->pkts_coal
= c
->rx_max_coalesced_frames
;
5828 mvpp2_rx_pkts_coal_set(port
, rxq
, rxq
->pkts_coal
);
5829 mvpp2_rx_time_coal_set(port
, rxq
, rxq
->time_coal
);
5832 for (queue
= 0; queue
< txq_number
; queue
++) {
5833 struct mvpp2_tx_queue
*txq
= port
->txqs
[queue
];
5835 txq
->done_pkts_coal
= c
->tx_max_coalesced_frames
;
5841 /* get coalescing for ethtools */
5842 static int mvpp2_ethtool_get_coalesce(struct net_device
*dev
,
5843 struct ethtool_coalesce
*c
)
5845 struct mvpp2_port
*port
= netdev_priv(dev
);
5847 c
->rx_coalesce_usecs
= port
->rxqs
[0]->time_coal
;
5848 c
->rx_max_coalesced_frames
= port
->rxqs
[0]->pkts_coal
;
5849 c
->tx_max_coalesced_frames
= port
->txqs
[0]->done_pkts_coal
;
5853 static void mvpp2_ethtool_get_drvinfo(struct net_device
*dev
,
5854 struct ethtool_drvinfo
*drvinfo
)
5856 strlcpy(drvinfo
->driver
, MVPP2_DRIVER_NAME
,
5857 sizeof(drvinfo
->driver
));
5858 strlcpy(drvinfo
->version
, MVPP2_DRIVER_VERSION
,
5859 sizeof(drvinfo
->version
));
5860 strlcpy(drvinfo
->bus_info
, dev_name(&dev
->dev
),
5861 sizeof(drvinfo
->bus_info
));
5864 static void mvpp2_ethtool_get_ringparam(struct net_device
*dev
,
5865 struct ethtool_ringparam
*ring
)
5867 struct mvpp2_port
*port
= netdev_priv(dev
);
5869 ring
->rx_max_pending
= MVPP2_MAX_RXD
;
5870 ring
->tx_max_pending
= MVPP2_MAX_TXD
;
5871 ring
->rx_pending
= port
->rx_ring_size
;
5872 ring
->tx_pending
= port
->tx_ring_size
;
5875 static int mvpp2_ethtool_set_ringparam(struct net_device
*dev
,
5876 struct ethtool_ringparam
*ring
)
5878 struct mvpp2_port
*port
= netdev_priv(dev
);
5879 u16 prev_rx_ring_size
= port
->rx_ring_size
;
5880 u16 prev_tx_ring_size
= port
->tx_ring_size
;
5883 err
= mvpp2_check_ringparam_valid(dev
, ring
);
5887 if (!netif_running(dev
)) {
5888 port
->rx_ring_size
= ring
->rx_pending
;
5889 port
->tx_ring_size
= ring
->tx_pending
;
5893 /* The interface is running, so we have to force a
5894 * reallocation of the queues
5896 mvpp2_stop_dev(port
);
5897 mvpp2_cleanup_rxqs(port
);
5898 mvpp2_cleanup_txqs(port
);
5900 port
->rx_ring_size
= ring
->rx_pending
;
5901 port
->tx_ring_size
= ring
->tx_pending
;
5903 err
= mvpp2_setup_rxqs(port
);
5905 /* Reallocate Rx queues with the original ring size */
5906 port
->rx_ring_size
= prev_rx_ring_size
;
5907 ring
->rx_pending
= prev_rx_ring_size
;
5908 err
= mvpp2_setup_rxqs(port
);
5912 err
= mvpp2_setup_txqs(port
);
5914 /* Reallocate Tx queues with the original ring size */
5915 port
->tx_ring_size
= prev_tx_ring_size
;
5916 ring
->tx_pending
= prev_tx_ring_size
;
5917 err
= mvpp2_setup_txqs(port
);
5919 goto err_clean_rxqs
;
5922 mvpp2_start_dev(port
);
5923 mvpp2_egress_enable(port
);
5924 mvpp2_ingress_enable(port
);
5929 mvpp2_cleanup_rxqs(port
);
5931 netdev_err(dev
, "fail to change ring parameters");
5937 static const struct net_device_ops mvpp2_netdev_ops
= {
5938 .ndo_open
= mvpp2_open
,
5939 .ndo_stop
= mvpp2_stop
,
5940 .ndo_start_xmit
= mvpp2_tx
,
5941 .ndo_set_rx_mode
= mvpp2_set_rx_mode
,
5942 .ndo_set_mac_address
= mvpp2_set_mac_address
,
5943 .ndo_change_mtu
= mvpp2_change_mtu
,
5944 .ndo_get_stats64
= mvpp2_get_stats64
,
5945 .ndo_do_ioctl
= mvpp2_ioctl
,
5948 static const struct ethtool_ops mvpp2_eth_tool_ops
= {
5949 .get_link
= ethtool_op_get_link
,
5950 .set_coalesce
= mvpp2_ethtool_set_coalesce
,
5951 .get_coalesce
= mvpp2_ethtool_get_coalesce
,
5952 .get_drvinfo
= mvpp2_ethtool_get_drvinfo
,
5953 .get_ringparam
= mvpp2_ethtool_get_ringparam
,
5954 .set_ringparam
= mvpp2_ethtool_set_ringparam
,
5955 .get_link_ksettings
= phy_ethtool_get_link_ksettings
,
5956 .set_link_ksettings
= phy_ethtool_set_link_ksettings
,
5959 /* Driver initialization */
5961 static void mvpp2_port_power_up(struct mvpp2_port
*port
)
5963 mvpp2_port_mii_set(port
);
5964 mvpp2_port_periodic_xon_disable(port
);
5965 mvpp2_port_fc_adv_enable(port
);
5966 mvpp2_port_reset(port
);
5969 /* Initialize port HW */
5970 static int mvpp2_port_init(struct mvpp2_port
*port
)
5972 struct device
*dev
= port
->dev
->dev
.parent
;
5973 struct mvpp2
*priv
= port
->priv
;
5974 struct mvpp2_txq_pcpu
*txq_pcpu
;
5975 int queue
, cpu
, err
;
5977 if (port
->first_rxq
+ rxq_number
> MVPP2_RXQ_TOTAL_NUM
)
5981 mvpp2_egress_disable(port
);
5982 mvpp2_port_disable(port
);
5984 port
->txqs
= devm_kcalloc(dev
, txq_number
, sizeof(*port
->txqs
),
5989 /* Associate physical Tx queues to this port and initialize.
5990 * The mapping is predefined.
5992 for (queue
= 0; queue
< txq_number
; queue
++) {
5993 int queue_phy_id
= mvpp2_txq_phys(port
->id
, queue
);
5994 struct mvpp2_tx_queue
*txq
;
5996 txq
= devm_kzalloc(dev
, sizeof(*txq
), GFP_KERNEL
);
6000 txq
->pcpu
= alloc_percpu(struct mvpp2_txq_pcpu
);
6003 goto err_free_percpu
;
6006 txq
->id
= queue_phy_id
;
6007 txq
->log_id
= queue
;
6008 txq
->done_pkts_coal
= MVPP2_TXDONE_COAL_PKTS_THRESH
;
6009 for_each_present_cpu(cpu
) {
6010 txq_pcpu
= per_cpu_ptr(txq
->pcpu
, cpu
);
6011 txq_pcpu
->cpu
= cpu
;
6014 port
->txqs
[queue
] = txq
;
6017 port
->rxqs
= devm_kcalloc(dev
, rxq_number
, sizeof(*port
->rxqs
),
6021 goto err_free_percpu
;
6024 /* Allocate and initialize Rx queue for this port */
6025 for (queue
= 0; queue
< rxq_number
; queue
++) {
6026 struct mvpp2_rx_queue
*rxq
;
6028 /* Map physical Rx queue to port's logical Rx queue */
6029 rxq
= devm_kzalloc(dev
, sizeof(*rxq
), GFP_KERNEL
);
6032 goto err_free_percpu
;
6034 /* Map this Rx queue to a physical queue */
6035 rxq
->id
= port
->first_rxq
+ queue
;
6036 rxq
->port
= port
->id
;
6037 rxq
->logic_rxq
= queue
;
6039 port
->rxqs
[queue
] = rxq
;
6042 /* Configure Rx queue group interrupt for this port */
6043 mvpp2_write(priv
, MVPP2_ISR_RXQ_GROUP_REG(port
->id
), rxq_number
);
6045 /* Create Rx descriptor rings */
6046 for (queue
= 0; queue
< rxq_number
; queue
++) {
6047 struct mvpp2_rx_queue
*rxq
= port
->rxqs
[queue
];
6049 rxq
->size
= port
->rx_ring_size
;
6050 rxq
->pkts_coal
= MVPP2_RX_COAL_PKTS
;
6051 rxq
->time_coal
= MVPP2_RX_COAL_USEC
;
6054 mvpp2_ingress_disable(port
);
6056 /* Port default configuration */
6057 mvpp2_defaults_set(port
);
6059 /* Port's classifier configuration */
6060 mvpp2_cls_oversize_rxq_set(port
);
6061 mvpp2_cls_port_config(port
);
6063 /* Provide an initial Rx packet size */
6064 port
->pkt_size
= MVPP2_RX_PKT_SIZE(port
->dev
->mtu
);
6066 /* Initialize pools for swf */
6067 err
= mvpp2_swf_bm_pool_init(port
);
6069 goto err_free_percpu
;
6074 for (queue
= 0; queue
< txq_number
; queue
++) {
6075 if (!port
->txqs
[queue
])
6077 free_percpu(port
->txqs
[queue
]->pcpu
);
6082 /* Ports initialization */
6083 static int mvpp2_port_probe(struct platform_device
*pdev
,
6084 struct device_node
*port_node
,
6086 int *next_first_rxq
)
6088 struct device_node
*phy_node
;
6089 struct mvpp2_port
*port
;
6090 struct mvpp2_port_pcpu
*port_pcpu
;
6091 struct net_device
*dev
;
6092 struct resource
*res
;
6093 const char *dt_mac_addr
;
6094 const char *mac_from
;
6095 char hw_mac_addr
[ETH_ALEN
];
6099 int priv_common_regs_num
= 2;
6102 dev
= alloc_etherdev_mqs(sizeof(struct mvpp2_port
), txq_number
,
6107 phy_node
= of_parse_phandle(port_node
, "phy", 0);
6109 dev_err(&pdev
->dev
, "missing phy\n");
6111 goto err_free_netdev
;
6114 phy_mode
= of_get_phy_mode(port_node
);
6116 dev_err(&pdev
->dev
, "incorrect phy mode\n");
6118 goto err_free_netdev
;
6121 if (of_property_read_u32(port_node
, "port-id", &id
)) {
6123 dev_err(&pdev
->dev
, "missing port-id value\n");
6124 goto err_free_netdev
;
6127 dev
->tx_queue_len
= MVPP2_MAX_TXD
;
6128 dev
->watchdog_timeo
= 5 * HZ
;
6129 dev
->netdev_ops
= &mvpp2_netdev_ops
;
6130 dev
->ethtool_ops
= &mvpp2_eth_tool_ops
;
6132 port
= netdev_priv(dev
);
6134 port
->irq
= irq_of_parse_and_map(port_node
, 0);
6135 if (port
->irq
<= 0) {
6137 goto err_free_netdev
;
6140 if (of_property_read_bool(port_node
, "marvell,loopback"))
6141 port
->flags
|= MVPP2_F_LOOPBACK
;
6145 port
->first_rxq
= *next_first_rxq
;
6146 port
->phy_node
= phy_node
;
6147 port
->phy_interface
= phy_mode
;
6149 res
= platform_get_resource(pdev
, IORESOURCE_MEM
,
6150 priv_common_regs_num
+ id
);
6151 port
->base
= devm_ioremap_resource(&pdev
->dev
, res
);
6152 if (IS_ERR(port
->base
)) {
6153 err
= PTR_ERR(port
->base
);
6157 /* Alloc per-cpu stats */
6158 port
->stats
= netdev_alloc_pcpu_stats(struct mvpp2_pcpu_stats
);
6164 dt_mac_addr
= of_get_mac_address(port_node
);
6165 if (dt_mac_addr
&& is_valid_ether_addr(dt_mac_addr
)) {
6166 mac_from
= "device tree";
6167 ether_addr_copy(dev
->dev_addr
, dt_mac_addr
);
6169 mvpp2_get_mac_address(port
, hw_mac_addr
);
6170 if (is_valid_ether_addr(hw_mac_addr
)) {
6171 mac_from
= "hardware";
6172 ether_addr_copy(dev
->dev_addr
, hw_mac_addr
);
6174 mac_from
= "random";
6175 eth_hw_addr_random(dev
);
6179 port
->tx_ring_size
= MVPP2_MAX_TXD
;
6180 port
->rx_ring_size
= MVPP2_MAX_RXD
;
6182 SET_NETDEV_DEV(dev
, &pdev
->dev
);
6184 err
= mvpp2_port_init(port
);
6186 dev_err(&pdev
->dev
, "failed to init port %d\n", id
);
6187 goto err_free_stats
;
6189 mvpp2_port_power_up(port
);
6191 port
->pcpu
= alloc_percpu(struct mvpp2_port_pcpu
);
6194 goto err_free_txq_pcpu
;
6197 for_each_present_cpu(cpu
) {
6198 port_pcpu
= per_cpu_ptr(port
->pcpu
, cpu
);
6200 hrtimer_init(&port_pcpu
->tx_done_timer
, CLOCK_MONOTONIC
,
6201 HRTIMER_MODE_REL_PINNED
);
6202 port_pcpu
->tx_done_timer
.function
= mvpp2_hr_timer_cb
;
6203 port_pcpu
->timer_scheduled
= false;
6205 tasklet_init(&port_pcpu
->tx_done_tasklet
, mvpp2_tx_proc_cb
,
6206 (unsigned long)dev
);
6209 netif_napi_add(dev
, &port
->napi
, mvpp2_poll
, NAPI_POLL_WEIGHT
);
6210 features
= NETIF_F_SG
| NETIF_F_IP_CSUM
;
6211 dev
->features
= features
| NETIF_F_RXCSUM
;
6212 dev
->hw_features
|= features
| NETIF_F_RXCSUM
| NETIF_F_GRO
;
6213 dev
->vlan_features
|= features
;
6215 err
= register_netdev(dev
);
6217 dev_err(&pdev
->dev
, "failed to register netdev\n");
6218 goto err_free_port_pcpu
;
6220 netdev_info(dev
, "Using %s mac address %pM\n", mac_from
, dev
->dev_addr
);
6222 /* Increment the first Rx queue number to be used by the next port */
6223 *next_first_rxq
+= rxq_number
;
6224 priv
->port_list
[id
] = port
;
6228 free_percpu(port
->pcpu
);
6230 for (i
= 0; i
< txq_number
; i
++)
6231 free_percpu(port
->txqs
[i
]->pcpu
);
6233 free_percpu(port
->stats
);
6235 irq_dispose_mapping(port
->irq
);
6237 of_node_put(phy_node
);
6242 /* Ports removal routine */
6243 static void mvpp2_port_remove(struct mvpp2_port
*port
)
6247 unregister_netdev(port
->dev
);
6248 of_node_put(port
->phy_node
);
6249 free_percpu(port
->pcpu
);
6250 free_percpu(port
->stats
);
6251 for (i
= 0; i
< txq_number
; i
++)
6252 free_percpu(port
->txqs
[i
]->pcpu
);
6253 irq_dispose_mapping(port
->irq
);
6254 free_netdev(port
->dev
);
6257 /* Initialize decoding windows */
6258 static void mvpp2_conf_mbus_windows(const struct mbus_dram_target_info
*dram
,
6264 for (i
= 0; i
< 6; i
++) {
6265 mvpp2_write(priv
, MVPP2_WIN_BASE(i
), 0);
6266 mvpp2_write(priv
, MVPP2_WIN_SIZE(i
), 0);
6269 mvpp2_write(priv
, MVPP2_WIN_REMAP(i
), 0);
6274 for (i
= 0; i
< dram
->num_cs
; i
++) {
6275 const struct mbus_dram_window
*cs
= dram
->cs
+ i
;
6277 mvpp2_write(priv
, MVPP2_WIN_BASE(i
),
6278 (cs
->base
& 0xffff0000) | (cs
->mbus_attr
<< 8) |
6279 dram
->mbus_dram_target_id
);
6281 mvpp2_write(priv
, MVPP2_WIN_SIZE(i
),
6282 (cs
->size
- 1) & 0xffff0000);
6284 win_enable
|= (1 << i
);
6287 mvpp2_write(priv
, MVPP2_BASE_ADDR_ENABLE
, win_enable
);
6290 /* Initialize Rx FIFO's */
6291 static void mvpp2_rx_fifo_init(struct mvpp2
*priv
)
6295 for (port
= 0; port
< MVPP2_MAX_PORTS
; port
++) {
6296 mvpp2_write(priv
, MVPP2_RX_DATA_FIFO_SIZE_REG(port
),
6297 MVPP2_RX_FIFO_PORT_DATA_SIZE
);
6298 mvpp2_write(priv
, MVPP2_RX_ATTR_FIFO_SIZE_REG(port
),
6299 MVPP2_RX_FIFO_PORT_ATTR_SIZE
);
6302 mvpp2_write(priv
, MVPP2_RX_MIN_PKT_SIZE_REG
,
6303 MVPP2_RX_FIFO_PORT_MIN_PKT
);
6304 mvpp2_write(priv
, MVPP2_RX_FIFO_INIT_REG
, 0x1);
6307 /* Initialize network controller common part HW */
6308 static int mvpp2_init(struct platform_device
*pdev
, struct mvpp2
*priv
)
6310 const struct mbus_dram_target_info
*dram_target_info
;
6314 /* Checks for hardware constraints */
6315 if (rxq_number
% 4 || (rxq_number
> MVPP2_MAX_RXQ
) ||
6316 (txq_number
> MVPP2_MAX_TXQ
)) {
6317 dev_err(&pdev
->dev
, "invalid queue size parameter\n");
6321 /* MBUS windows configuration */
6322 dram_target_info
= mv_mbus_dram_info();
6323 if (dram_target_info
)
6324 mvpp2_conf_mbus_windows(dram_target_info
, priv
);
6326 /* Disable HW PHY polling */
6327 val
= readl(priv
->lms_base
+ MVPP2_PHY_AN_CFG0_REG
);
6328 val
|= MVPP2_PHY_AN_STOP_SMI0_MASK
;
6329 writel(val
, priv
->lms_base
+ MVPP2_PHY_AN_CFG0_REG
);
6331 /* Allocate and initialize aggregated TXQs */
6332 priv
->aggr_txqs
= devm_kcalloc(&pdev
->dev
, num_present_cpus(),
6333 sizeof(struct mvpp2_tx_queue
),
6335 if (!priv
->aggr_txqs
)
6338 for_each_present_cpu(i
) {
6339 priv
->aggr_txqs
[i
].id
= i
;
6340 priv
->aggr_txqs
[i
].size
= MVPP2_AGGR_TXQ_SIZE
;
6341 err
= mvpp2_aggr_txq_init(pdev
, &priv
->aggr_txqs
[i
],
6342 MVPP2_AGGR_TXQ_SIZE
, i
, priv
);
6348 mvpp2_rx_fifo_init(priv
);
6350 /* Reset Rx queue group interrupt configuration */
6351 for (i
= 0; i
< MVPP2_MAX_PORTS
; i
++)
6352 mvpp2_write(priv
, MVPP2_ISR_RXQ_GROUP_REG(i
), rxq_number
);
6354 writel(MVPP2_EXT_GLOBAL_CTRL_DEFAULT
,
6355 priv
->lms_base
+ MVPP2_MNG_EXTENDED_GLOBAL_CTRL_REG
);
6357 /* Allow cache snoop when transmiting packets */
6358 mvpp2_write(priv
, MVPP2_TX_SNOOP_REG
, 0x1);
6360 /* Buffer Manager initialization */
6361 err
= mvpp2_bm_init(pdev
, priv
);
6365 /* Parser default initialization */
6366 err
= mvpp2_prs_default_init(pdev
, priv
);
6370 /* Classifier default initialization */
6371 mvpp2_cls_init(priv
);
6376 static int mvpp2_probe(struct platform_device
*pdev
)
6378 struct device_node
*dn
= pdev
->dev
.of_node
;
6379 struct device_node
*port_node
;
6381 struct resource
*res
;
6382 int port_count
, first_rxq
;
6385 priv
= devm_kzalloc(&pdev
->dev
, sizeof(struct mvpp2
), GFP_KERNEL
);
6389 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
6390 priv
->base
= devm_ioremap_resource(&pdev
->dev
, res
);
6391 if (IS_ERR(priv
->base
))
6392 return PTR_ERR(priv
->base
);
6394 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
6395 priv
->lms_base
= devm_ioremap_resource(&pdev
->dev
, res
);
6396 if (IS_ERR(priv
->lms_base
))
6397 return PTR_ERR(priv
->lms_base
);
6399 priv
->pp_clk
= devm_clk_get(&pdev
->dev
, "pp_clk");
6400 if (IS_ERR(priv
->pp_clk
))
6401 return PTR_ERR(priv
->pp_clk
);
6402 err
= clk_prepare_enable(priv
->pp_clk
);
6406 priv
->gop_clk
= devm_clk_get(&pdev
->dev
, "gop_clk");
6407 if (IS_ERR(priv
->gop_clk
)) {
6408 err
= PTR_ERR(priv
->gop_clk
);
6411 err
= clk_prepare_enable(priv
->gop_clk
);
6415 /* Get system's tclk rate */
6416 priv
->tclk
= clk_get_rate(priv
->pp_clk
);
6418 /* Initialize network controller */
6419 err
= mvpp2_init(pdev
, priv
);
6421 dev_err(&pdev
->dev
, "failed to initialize controller\n");
6425 port_count
= of_get_available_child_count(dn
);
6426 if (port_count
== 0) {
6427 dev_err(&pdev
->dev
, "no ports enabled\n");
6432 priv
->port_list
= devm_kcalloc(&pdev
->dev
, port_count
,
6433 sizeof(struct mvpp2_port
*),
6435 if (!priv
->port_list
) {
6440 /* Initialize ports */
6442 for_each_available_child_of_node(dn
, port_node
) {
6443 err
= mvpp2_port_probe(pdev
, port_node
, priv
, &first_rxq
);
6448 platform_set_drvdata(pdev
, priv
);
6452 clk_disable_unprepare(priv
->gop_clk
);
6454 clk_disable_unprepare(priv
->pp_clk
);
6458 static int mvpp2_remove(struct platform_device
*pdev
)
6460 struct mvpp2
*priv
= platform_get_drvdata(pdev
);
6461 struct device_node
*dn
= pdev
->dev
.of_node
;
6462 struct device_node
*port_node
;
6465 for_each_available_child_of_node(dn
, port_node
) {
6466 if (priv
->port_list
[i
])
6467 mvpp2_port_remove(priv
->port_list
[i
]);
6471 for (i
= 0; i
< MVPP2_BM_POOLS_NUM
; i
++) {
6472 struct mvpp2_bm_pool
*bm_pool
= &priv
->bm_pools
[i
];
6474 mvpp2_bm_pool_destroy(pdev
, priv
, bm_pool
);
6477 for_each_present_cpu(i
) {
6478 struct mvpp2_tx_queue
*aggr_txq
= &priv
->aggr_txqs
[i
];
6480 dma_free_coherent(&pdev
->dev
,
6481 MVPP2_AGGR_TXQ_SIZE
* MVPP2_DESC_ALIGNED_SIZE
,
6483 aggr_txq
->descs_phys
);
6486 clk_disable_unprepare(priv
->pp_clk
);
6487 clk_disable_unprepare(priv
->gop_clk
);
6492 static const struct of_device_id mvpp2_match
[] = {
6493 { .compatible
= "marvell,armada-375-pp2" },
6496 MODULE_DEVICE_TABLE(of
, mvpp2_match
);
6498 static struct platform_driver mvpp2_driver
= {
6499 .probe
= mvpp2_probe
,
6500 .remove
= mvpp2_remove
,
6502 .name
= MVPP2_DRIVER_NAME
,
6503 .of_match_table
= mvpp2_match
,
6507 module_platform_driver(mvpp2_driver
);
6509 MODULE_DESCRIPTION("Marvell PPv2 Ethernet Driver - www.marvell.com");
6510 MODULE_AUTHOR("Marcin Wojtas <mw@semihalf.com>");
6511 MODULE_LICENSE("GPL v2");