]>
Commit | Line | Data |
---|---|---|
3f518509 MW |
1 | /* |
2 | * Driver for Marvell PPv2 network controller for Armada 375 SoC. | |
3 | * | |
4 | * Copyright (C) 2014 Marvell | |
5 | * | |
6 | * Marcin Wojtas <mw@semihalf.com> | |
7 | * | |
8 | * This file is licensed under the terms of the GNU General Public | |
9 | * License version 2. This program is licensed "as is" without any | |
10 | * warranty of any kind, whether express or implied. | |
11 | */ | |
12 | ||
13 | #include <linux/kernel.h> | |
14 | #include <linux/netdevice.h> | |
15 | #include <linux/etherdevice.h> | |
16 | #include <linux/platform_device.h> | |
17 | #include <linux/skbuff.h> | |
18 | #include <linux/inetdevice.h> | |
19 | #include <linux/mbus.h> | |
20 | #include <linux/module.h> | |
f84bf386 | 21 | #include <linux/mfd/syscon.h> |
3f518509 MW |
22 | #include <linux/interrupt.h> |
23 | #include <linux/cpumask.h> | |
24 | #include <linux/of.h> | |
25 | #include <linux/of_irq.h> | |
26 | #include <linux/of_mdio.h> | |
27 | #include <linux/of_net.h> | |
28 | #include <linux/of_address.h> | |
faca9247 | 29 | #include <linux/of_device.h> |
3f518509 | 30 | #include <linux/phy.h> |
542897d9 | 31 | #include <linux/phy/phy.h> |
3f518509 | 32 | #include <linux/clk.h> |
edc660fa MW |
33 | #include <linux/hrtimer.h> |
34 | #include <linux/ktime.h> | |
f84bf386 | 35 | #include <linux/regmap.h> |
3f518509 MW |
36 | #include <uapi/linux/ppp_defs.h> |
37 | #include <net/ip.h> | |
38 | #include <net/ipv6.h> | |
186cd4d4 | 39 | #include <net/tso.h> |
3f518509 MW |
40 | |
41 | /* RX Fifo Registers */ | |
42 | #define MVPP2_RX_DATA_FIFO_SIZE_REG(port) (0x00 + 4 * (port)) | |
43 | #define MVPP2_RX_ATTR_FIFO_SIZE_REG(port) (0x20 + 4 * (port)) | |
44 | #define MVPP2_RX_MIN_PKT_SIZE_REG 0x60 | |
45 | #define MVPP2_RX_FIFO_INIT_REG 0x64 | |
46 | ||
47 | /* RX DMA Top Registers */ | |
48 | #define MVPP2_RX_CTRL_REG(port) (0x140 + 4 * (port)) | |
49 | #define MVPP2_RX_LOW_LATENCY_PKT_SIZE(s) (((s) & 0xfff) << 16) | |
50 | #define MVPP2_RX_USE_PSEUDO_FOR_CSUM_MASK BIT(31) | |
51 | #define MVPP2_POOL_BUF_SIZE_REG(pool) (0x180 + 4 * (pool)) | |
52 | #define MVPP2_POOL_BUF_SIZE_OFFSET 5 | |
53 | #define MVPP2_RXQ_CONFIG_REG(rxq) (0x800 + 4 * (rxq)) | |
54 | #define MVPP2_SNOOP_PKT_SIZE_MASK 0x1ff | |
55 | #define MVPP2_SNOOP_BUF_HDR_MASK BIT(9) | |
56 | #define MVPP2_RXQ_POOL_SHORT_OFFS 20 | |
5eac892a TP |
57 | #define MVPP21_RXQ_POOL_SHORT_MASK 0x700000 |
58 | #define MVPP22_RXQ_POOL_SHORT_MASK 0xf00000 | |
3f518509 | 59 | #define MVPP2_RXQ_POOL_LONG_OFFS 24 |
5eac892a TP |
60 | #define MVPP21_RXQ_POOL_LONG_MASK 0x7000000 |
61 | #define MVPP22_RXQ_POOL_LONG_MASK 0xf000000 | |
3f518509 MW |
62 | #define MVPP2_RXQ_PACKET_OFFSET_OFFS 28 |
63 | #define MVPP2_RXQ_PACKET_OFFSET_MASK 0x70000000 | |
64 | #define MVPP2_RXQ_DISABLE_MASK BIT(31) | |
65 | ||
66 | /* Parser Registers */ | |
67 | #define MVPP2_PRS_INIT_LOOKUP_REG 0x1000 | |
68 | #define MVPP2_PRS_PORT_LU_MAX 0xf | |
69 | #define MVPP2_PRS_PORT_LU_MASK(port) (0xff << ((port) * 4)) | |
70 | #define MVPP2_PRS_PORT_LU_VAL(port, val) ((val) << ((port) * 4)) | |
71 | #define MVPP2_PRS_INIT_OFFS_REG(port) (0x1004 + ((port) & 4)) | |
72 | #define MVPP2_PRS_INIT_OFF_MASK(port) (0x3f << (((port) % 4) * 8)) | |
73 | #define MVPP2_PRS_INIT_OFF_VAL(port, val) ((val) << (((port) % 4) * 8)) | |
74 | #define MVPP2_PRS_MAX_LOOP_REG(port) (0x100c + ((port) & 4)) | |
75 | #define MVPP2_PRS_MAX_LOOP_MASK(port) (0xff << (((port) % 4) * 8)) | |
76 | #define MVPP2_PRS_MAX_LOOP_VAL(port, val) ((val) << (((port) % 4) * 8)) | |
77 | #define MVPP2_PRS_TCAM_IDX_REG 0x1100 | |
78 | #define MVPP2_PRS_TCAM_DATA_REG(idx) (0x1104 + (idx) * 4) | |
79 | #define MVPP2_PRS_TCAM_INV_MASK BIT(31) | |
80 | #define MVPP2_PRS_SRAM_IDX_REG 0x1200 | |
81 | #define MVPP2_PRS_SRAM_DATA_REG(idx) (0x1204 + (idx) * 4) | |
82 | #define MVPP2_PRS_TCAM_CTRL_REG 0x1230 | |
83 | #define MVPP2_PRS_TCAM_EN_MASK BIT(0) | |
84 | ||
85 | /* Classifier Registers */ | |
86 | #define MVPP2_CLS_MODE_REG 0x1800 | |
87 | #define MVPP2_CLS_MODE_ACTIVE_MASK BIT(0) | |
88 | #define MVPP2_CLS_PORT_WAY_REG 0x1810 | |
89 | #define MVPP2_CLS_PORT_WAY_MASK(port) (1 << (port)) | |
90 | #define MVPP2_CLS_LKP_INDEX_REG 0x1814 | |
91 | #define MVPP2_CLS_LKP_INDEX_WAY_OFFS 6 | |
92 | #define MVPP2_CLS_LKP_TBL_REG 0x1818 | |
93 | #define MVPP2_CLS_LKP_TBL_RXQ_MASK 0xff | |
94 | #define MVPP2_CLS_LKP_TBL_LOOKUP_EN_MASK BIT(25) | |
95 | #define MVPP2_CLS_FLOW_INDEX_REG 0x1820 | |
96 | #define MVPP2_CLS_FLOW_TBL0_REG 0x1824 | |
97 | #define MVPP2_CLS_FLOW_TBL1_REG 0x1828 | |
98 | #define MVPP2_CLS_FLOW_TBL2_REG 0x182c | |
99 | #define MVPP2_CLS_OVERSIZE_RXQ_LOW_REG(port) (0x1980 + ((port) * 4)) | |
100 | #define MVPP2_CLS_OVERSIZE_RXQ_LOW_BITS 3 | |
101 | #define MVPP2_CLS_OVERSIZE_RXQ_LOW_MASK 0x7 | |
102 | #define MVPP2_CLS_SWFWD_P2HQ_REG(port) (0x19b0 + ((port) * 4)) | |
103 | #define MVPP2_CLS_SWFWD_PCTRL_REG 0x19d0 | |
104 | #define MVPP2_CLS_SWFWD_PCTRL_MASK(port) (1 << (port)) | |
105 | ||
106 | /* Descriptor Manager Top Registers */ | |
107 | #define MVPP2_RXQ_NUM_REG 0x2040 | |
108 | #define MVPP2_RXQ_DESC_ADDR_REG 0x2044 | |
b02f31fb | 109 | #define MVPP22_DESC_ADDR_OFFS 8 |
3f518509 MW |
110 | #define MVPP2_RXQ_DESC_SIZE_REG 0x2048 |
111 | #define MVPP2_RXQ_DESC_SIZE_MASK 0x3ff0 | |
112 | #define MVPP2_RXQ_STATUS_UPDATE_REG(rxq) (0x3000 + 4 * (rxq)) | |
113 | #define MVPP2_RXQ_NUM_PROCESSED_OFFSET 0 | |
114 | #define MVPP2_RXQ_NUM_NEW_OFFSET 16 | |
115 | #define MVPP2_RXQ_STATUS_REG(rxq) (0x3400 + 4 * (rxq)) | |
116 | #define MVPP2_RXQ_OCCUPIED_MASK 0x3fff | |
117 | #define MVPP2_RXQ_NON_OCCUPIED_OFFSET 16 | |
118 | #define MVPP2_RXQ_NON_OCCUPIED_MASK 0x3fff0000 | |
119 | #define MVPP2_RXQ_THRESH_REG 0x204c | |
120 | #define MVPP2_OCCUPIED_THRESH_OFFSET 0 | |
121 | #define MVPP2_OCCUPIED_THRESH_MASK 0x3fff | |
122 | #define MVPP2_RXQ_INDEX_REG 0x2050 | |
123 | #define MVPP2_TXQ_NUM_REG 0x2080 | |
124 | #define MVPP2_TXQ_DESC_ADDR_REG 0x2084 | |
125 | #define MVPP2_TXQ_DESC_SIZE_REG 0x2088 | |
126 | #define MVPP2_TXQ_DESC_SIZE_MASK 0x3ff0 | |
213f428f TP |
127 | #define MVPP2_TXQ_THRESH_REG 0x2094 |
128 | #define MVPP2_TXQ_THRESH_OFFSET 16 | |
129 | #define MVPP2_TXQ_THRESH_MASK 0x3fff | |
3f518509 | 130 | #define MVPP2_AGGR_TXQ_UPDATE_REG 0x2090 |
3f518509 MW |
131 | #define MVPP2_TXQ_INDEX_REG 0x2098 |
132 | #define MVPP2_TXQ_PREF_BUF_REG 0x209c | |
133 | #define MVPP2_PREF_BUF_PTR(desc) ((desc) & 0xfff) | |
134 | #define MVPP2_PREF_BUF_SIZE_4 (BIT(12) | BIT(13)) | |
135 | #define MVPP2_PREF_BUF_SIZE_16 (BIT(12) | BIT(14)) | |
136 | #define MVPP2_PREF_BUF_THRESH(val) ((val) << 17) | |
137 | #define MVPP2_TXQ_DRAIN_EN_MASK BIT(31) | |
138 | #define MVPP2_TXQ_PENDING_REG 0x20a0 | |
139 | #define MVPP2_TXQ_PENDING_MASK 0x3fff | |
140 | #define MVPP2_TXQ_INT_STATUS_REG 0x20a4 | |
141 | #define MVPP2_TXQ_SENT_REG(txq) (0x3c00 + 4 * (txq)) | |
142 | #define MVPP2_TRANSMITTED_COUNT_OFFSET 16 | |
143 | #define MVPP2_TRANSMITTED_COUNT_MASK 0x3fff0000 | |
144 | #define MVPP2_TXQ_RSVD_REQ_REG 0x20b0 | |
145 | #define MVPP2_TXQ_RSVD_REQ_Q_OFFSET 16 | |
146 | #define MVPP2_TXQ_RSVD_RSLT_REG 0x20b4 | |
147 | #define MVPP2_TXQ_RSVD_RSLT_MASK 0x3fff | |
148 | #define MVPP2_TXQ_RSVD_CLR_REG 0x20b8 | |
149 | #define MVPP2_TXQ_RSVD_CLR_OFFSET 16 | |
150 | #define MVPP2_AGGR_TXQ_DESC_ADDR_REG(cpu) (0x2100 + 4 * (cpu)) | |
b02f31fb | 151 | #define MVPP22_AGGR_TXQ_DESC_ADDR_OFFS 8 |
3f518509 MW |
152 | #define MVPP2_AGGR_TXQ_DESC_SIZE_REG(cpu) (0x2140 + 4 * (cpu)) |
153 | #define MVPP2_AGGR_TXQ_DESC_SIZE_MASK 0x3ff0 | |
154 | #define MVPP2_AGGR_TXQ_STATUS_REG(cpu) (0x2180 + 4 * (cpu)) | |
155 | #define MVPP2_AGGR_TXQ_PENDING_MASK 0x3fff | |
156 | #define MVPP2_AGGR_TXQ_INDEX_REG(cpu) (0x21c0 + 4 * (cpu)) | |
157 | ||
158 | /* MBUS bridge registers */ | |
159 | #define MVPP2_WIN_BASE(w) (0x4000 + ((w) << 2)) | |
160 | #define MVPP2_WIN_SIZE(w) (0x4020 + ((w) << 2)) | |
161 | #define MVPP2_WIN_REMAP(w) (0x4040 + ((w) << 2)) | |
162 | #define MVPP2_BASE_ADDR_ENABLE 0x4060 | |
163 | ||
6763ce31 TP |
164 | /* AXI Bridge Registers */ |
165 | #define MVPP22_AXI_BM_WR_ATTR_REG 0x4100 | |
166 | #define MVPP22_AXI_BM_RD_ATTR_REG 0x4104 | |
167 | #define MVPP22_AXI_AGGRQ_DESCR_RD_ATTR_REG 0x4110 | |
168 | #define MVPP22_AXI_TXQ_DESCR_WR_ATTR_REG 0x4114 | |
169 | #define MVPP22_AXI_TXQ_DESCR_RD_ATTR_REG 0x4118 | |
170 | #define MVPP22_AXI_RXQ_DESCR_WR_ATTR_REG 0x411c | |
171 | #define MVPP22_AXI_RX_DATA_WR_ATTR_REG 0x4120 | |
172 | #define MVPP22_AXI_TX_DATA_RD_ATTR_REG 0x4130 | |
173 | #define MVPP22_AXI_RD_NORMAL_CODE_REG 0x4150 | |
174 | #define MVPP22_AXI_RD_SNOOP_CODE_REG 0x4154 | |
175 | #define MVPP22_AXI_WR_NORMAL_CODE_REG 0x4160 | |
176 | #define MVPP22_AXI_WR_SNOOP_CODE_REG 0x4164 | |
177 | ||
178 | /* Values for AXI Bridge registers */ | |
179 | #define MVPP22_AXI_ATTR_CACHE_OFFS 0 | |
180 | #define MVPP22_AXI_ATTR_DOMAIN_OFFS 12 | |
181 | ||
182 | #define MVPP22_AXI_CODE_CACHE_OFFS 0 | |
183 | #define MVPP22_AXI_CODE_DOMAIN_OFFS 4 | |
184 | ||
185 | #define MVPP22_AXI_CODE_CACHE_NON_CACHE 0x3 | |
186 | #define MVPP22_AXI_CODE_CACHE_WR_CACHE 0x7 | |
187 | #define MVPP22_AXI_CODE_CACHE_RD_CACHE 0xb | |
188 | ||
189 | #define MVPP22_AXI_CODE_DOMAIN_OUTER_DOM 2 | |
190 | #define MVPP22_AXI_CODE_DOMAIN_SYSTEM 3 | |
191 | ||
3f518509 | 192 | /* Interrupt Cause and Mask registers */ |
213f428f TP |
193 | #define MVPP2_ISR_TX_THRESHOLD_REG(port) (0x5140 + 4 * (port)) |
194 | #define MVPP2_MAX_ISR_TX_THRESHOLD 0xfffff0 | |
195 | ||
3f518509 | 196 | #define MVPP2_ISR_RX_THRESHOLD_REG(rxq) (0x5200 + 4 * (rxq)) |
ab42676a | 197 | #define MVPP2_MAX_ISR_RX_THRESHOLD 0xfffff0 |
eb1e93a1 | 198 | #define MVPP21_ISR_RXQ_GROUP_REG(port) (0x5400 + 4 * (port)) |
a73fef10 | 199 | |
81b6630f | 200 | #define MVPP22_ISR_RXQ_GROUP_INDEX_REG 0x5400 |
a73fef10 | 201 | #define MVPP22_ISR_RXQ_GROUP_INDEX_SUBGROUP_MASK 0xf |
81b6630f AT |
202 | #define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_MASK 0x380 |
203 | #define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_OFFSET 7 | |
a73fef10 TP |
204 | |
205 | #define MVPP22_ISR_RXQ_GROUP_INDEX_SUBGROUP_MASK 0xf | |
81b6630f | 206 | #define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_MASK 0x380 |
a73fef10 | 207 | |
81b6630f AT |
208 | #define MVPP22_ISR_RXQ_SUB_GROUP_CONFIG_REG 0x5404 |
209 | #define MVPP22_ISR_RXQ_SUB_GROUP_STARTQ_MASK 0x1f | |
210 | #define MVPP22_ISR_RXQ_SUB_GROUP_SIZE_MASK 0xf00 | |
211 | #define MVPP22_ISR_RXQ_SUB_GROUP_SIZE_OFFSET 8 | |
a73fef10 | 212 | |
3f518509 MW |
213 | #define MVPP2_ISR_ENABLE_REG(port) (0x5420 + 4 * (port)) |
214 | #define MVPP2_ISR_ENABLE_INTERRUPT(mask) ((mask) & 0xffff) | |
215 | #define MVPP2_ISR_DISABLE_INTERRUPT(mask) (((mask) << 16) & 0xffff0000) | |
216 | #define MVPP2_ISR_RX_TX_CAUSE_REG(port) (0x5480 + 4 * (port)) | |
217 | #define MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK 0xffff | |
218 | #define MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK 0xff0000 | |
213f428f | 219 | #define MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_OFFSET 16 |
3f518509 MW |
220 | #define MVPP2_CAUSE_RX_FIFO_OVERRUN_MASK BIT(24) |
221 | #define MVPP2_CAUSE_FCS_ERR_MASK BIT(25) | |
222 | #define MVPP2_CAUSE_TX_FIFO_UNDERRUN_MASK BIT(26) | |
223 | #define MVPP2_CAUSE_TX_EXCEPTION_SUM_MASK BIT(29) | |
224 | #define MVPP2_CAUSE_RX_EXCEPTION_SUM_MASK BIT(30) | |
225 | #define MVPP2_CAUSE_MISC_SUM_MASK BIT(31) | |
226 | #define MVPP2_ISR_RX_TX_MASK_REG(port) (0x54a0 + 4 * (port)) | |
227 | #define MVPP2_ISR_PON_RX_TX_MASK_REG 0x54bc | |
228 | #define MVPP2_PON_CAUSE_RXQ_OCCUP_DESC_ALL_MASK 0xffff | |
229 | #define MVPP2_PON_CAUSE_TXP_OCCUP_DESC_ALL_MASK 0x3fc00000 | |
230 | #define MVPP2_PON_CAUSE_MISC_SUM_MASK BIT(31) | |
231 | #define MVPP2_ISR_MISC_CAUSE_REG 0x55b0 | |
232 | ||
233 | /* Buffer Manager registers */ | |
234 | #define MVPP2_BM_POOL_BASE_REG(pool) (0x6000 + ((pool) * 4)) | |
235 | #define MVPP2_BM_POOL_BASE_ADDR_MASK 0xfffff80 | |
236 | #define MVPP2_BM_POOL_SIZE_REG(pool) (0x6040 + ((pool) * 4)) | |
237 | #define MVPP2_BM_POOL_SIZE_MASK 0xfff0 | |
238 | #define MVPP2_BM_POOL_READ_PTR_REG(pool) (0x6080 + ((pool) * 4)) | |
239 | #define MVPP2_BM_POOL_GET_READ_PTR_MASK 0xfff0 | |
240 | #define MVPP2_BM_POOL_PTRS_NUM_REG(pool) (0x60c0 + ((pool) * 4)) | |
241 | #define MVPP2_BM_POOL_PTRS_NUM_MASK 0xfff0 | |
242 | #define MVPP2_BM_BPPI_READ_PTR_REG(pool) (0x6100 + ((pool) * 4)) | |
243 | #define MVPP2_BM_BPPI_PTRS_NUM_REG(pool) (0x6140 + ((pool) * 4)) | |
244 | #define MVPP2_BM_BPPI_PTR_NUM_MASK 0x7ff | |
245 | #define MVPP2_BM_BPPI_PREFETCH_FULL_MASK BIT(16) | |
246 | #define MVPP2_BM_POOL_CTRL_REG(pool) (0x6200 + ((pool) * 4)) | |
247 | #define MVPP2_BM_START_MASK BIT(0) | |
248 | #define MVPP2_BM_STOP_MASK BIT(1) | |
249 | #define MVPP2_BM_STATE_MASK BIT(4) | |
250 | #define MVPP2_BM_LOW_THRESH_OFFS 8 | |
251 | #define MVPP2_BM_LOW_THRESH_MASK 0x7f00 | |
252 | #define MVPP2_BM_LOW_THRESH_VALUE(val) ((val) << \ | |
253 | MVPP2_BM_LOW_THRESH_OFFS) | |
254 | #define MVPP2_BM_HIGH_THRESH_OFFS 16 | |
255 | #define MVPP2_BM_HIGH_THRESH_MASK 0x7f0000 | |
256 | #define MVPP2_BM_HIGH_THRESH_VALUE(val) ((val) << \ | |
257 | MVPP2_BM_HIGH_THRESH_OFFS) | |
258 | #define MVPP2_BM_INTR_CAUSE_REG(pool) (0x6240 + ((pool) * 4)) | |
259 | #define MVPP2_BM_RELEASED_DELAY_MASK BIT(0) | |
260 | #define MVPP2_BM_ALLOC_FAILED_MASK BIT(1) | |
261 | #define MVPP2_BM_BPPE_EMPTY_MASK BIT(2) | |
262 | #define MVPP2_BM_BPPE_FULL_MASK BIT(3) | |
263 | #define MVPP2_BM_AVAILABLE_BP_LOW_MASK BIT(4) | |
264 | #define MVPP2_BM_INTR_MASK_REG(pool) (0x6280 + ((pool) * 4)) | |
265 | #define MVPP2_BM_PHY_ALLOC_REG(pool) (0x6400 + ((pool) * 4)) | |
266 | #define MVPP2_BM_PHY_ALLOC_GRNTD_MASK BIT(0) | |
267 | #define MVPP2_BM_VIRT_ALLOC_REG 0x6440 | |
d01524d8 TP |
268 | #define MVPP22_BM_ADDR_HIGH_ALLOC 0x6444 |
269 | #define MVPP22_BM_ADDR_HIGH_PHYS_MASK 0xff | |
270 | #define MVPP22_BM_ADDR_HIGH_VIRT_MASK 0xff00 | |
271 | #define MVPP22_BM_ADDR_HIGH_VIRT_SHIFT 8 | |
3f518509 MW |
272 | #define MVPP2_BM_PHY_RLS_REG(pool) (0x6480 + ((pool) * 4)) |
273 | #define MVPP2_BM_PHY_RLS_MC_BUFF_MASK BIT(0) | |
274 | #define MVPP2_BM_PHY_RLS_PRIO_EN_MASK BIT(1) | |
275 | #define MVPP2_BM_PHY_RLS_GRNTD_MASK BIT(2) | |
276 | #define MVPP2_BM_VIRT_RLS_REG 0x64c0 | |
d01524d8 TP |
277 | #define MVPP22_BM_ADDR_HIGH_RLS_REG 0x64c4 |
278 | #define MVPP22_BM_ADDR_HIGH_PHYS_RLS_MASK 0xff | |
81b6630f | 279 | #define MVPP22_BM_ADDR_HIGH_VIRT_RLS_MASK 0xff00 |
d01524d8 | 280 | #define MVPP22_BM_ADDR_HIGH_VIRT_RLS_SHIFT 8 |
3f518509 MW |
281 | |
282 | /* TX Scheduler registers */ | |
283 | #define MVPP2_TXP_SCHED_PORT_INDEX_REG 0x8000 | |
284 | #define MVPP2_TXP_SCHED_Q_CMD_REG 0x8004 | |
285 | #define MVPP2_TXP_SCHED_ENQ_MASK 0xff | |
286 | #define MVPP2_TXP_SCHED_DISQ_OFFSET 8 | |
287 | #define MVPP2_TXP_SCHED_CMD_1_REG 0x8010 | |
288 | #define MVPP2_TXP_SCHED_PERIOD_REG 0x8018 | |
289 | #define MVPP2_TXP_SCHED_MTU_REG 0x801c | |
290 | #define MVPP2_TXP_MTU_MAX 0x7FFFF | |
291 | #define MVPP2_TXP_SCHED_REFILL_REG 0x8020 | |
292 | #define MVPP2_TXP_REFILL_TOKENS_ALL_MASK 0x7ffff | |
293 | #define MVPP2_TXP_REFILL_PERIOD_ALL_MASK 0x3ff00000 | |
294 | #define MVPP2_TXP_REFILL_PERIOD_MASK(v) ((v) << 20) | |
295 | #define MVPP2_TXP_SCHED_TOKEN_SIZE_REG 0x8024 | |
296 | #define MVPP2_TXP_TOKEN_SIZE_MAX 0xffffffff | |
297 | #define MVPP2_TXQ_SCHED_REFILL_REG(q) (0x8040 + ((q) << 2)) | |
298 | #define MVPP2_TXQ_REFILL_TOKENS_ALL_MASK 0x7ffff | |
299 | #define MVPP2_TXQ_REFILL_PERIOD_ALL_MASK 0x3ff00000 | |
300 | #define MVPP2_TXQ_REFILL_PERIOD_MASK(v) ((v) << 20) | |
301 | #define MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(q) (0x8060 + ((q) << 2)) | |
302 | #define MVPP2_TXQ_TOKEN_SIZE_MAX 0x7fffffff | |
303 | #define MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(q) (0x8080 + ((q) << 2)) | |
304 | #define MVPP2_TXQ_TOKEN_CNTR_MAX 0xffffffff | |
305 | ||
306 | /* TX general registers */ | |
307 | #define MVPP2_TX_SNOOP_REG 0x8800 | |
308 | #define MVPP2_TX_PORT_FLUSH_REG 0x8810 | |
309 | #define MVPP2_TX_PORT_FLUSH_MASK(port) (1 << (port)) | |
310 | ||
311 | /* LMS registers */ | |
312 | #define MVPP2_SRC_ADDR_MIDDLE 0x24 | |
313 | #define MVPP2_SRC_ADDR_HIGH 0x28 | |
08a23755 MW |
314 | #define MVPP2_PHY_AN_CFG0_REG 0x34 |
315 | #define MVPP2_PHY_AN_STOP_SMI0_MASK BIT(7) | |
3f518509 | 316 | #define MVPP2_MNG_EXTENDED_GLOBAL_CTRL_REG 0x305c |
31d7677b | 317 | #define MVPP2_EXT_GLOBAL_CTRL_DEFAULT 0x27 |
3f518509 MW |
318 | |
319 | /* Per-port registers */ | |
320 | #define MVPP2_GMAC_CTRL_0_REG 0x0 | |
81b6630f | 321 | #define MVPP2_GMAC_PORT_EN_MASK BIT(0) |
3919357f | 322 | #define MVPP2_GMAC_PORT_TYPE_MASK BIT(1) |
81b6630f AT |
323 | #define MVPP2_GMAC_MAX_RX_SIZE_OFFS 2 |
324 | #define MVPP2_GMAC_MAX_RX_SIZE_MASK 0x7ffc | |
325 | #define MVPP2_GMAC_MIB_CNTR_EN_MASK BIT(15) | |
3f518509 | 326 | #define MVPP2_GMAC_CTRL_1_REG 0x4 |
81b6630f AT |
327 | #define MVPP2_GMAC_PERIODIC_XON_EN_MASK BIT(1) |
328 | #define MVPP2_GMAC_GMII_LB_EN_MASK BIT(5) | |
329 | #define MVPP2_GMAC_PCS_LB_EN_BIT 6 | |
330 | #define MVPP2_GMAC_PCS_LB_EN_MASK BIT(6) | |
331 | #define MVPP2_GMAC_SA_LOW_OFFS 7 | |
3f518509 | 332 | #define MVPP2_GMAC_CTRL_2_REG 0x8 |
81b6630f | 333 | #define MVPP2_GMAC_INBAND_AN_MASK BIT(0) |
3919357f | 334 | #define MVPP2_GMAC_FLOW_CTRL_MASK GENMASK(2, 1) |
81b6630f | 335 | #define MVPP2_GMAC_PCS_ENABLE_MASK BIT(3) |
c7dfc8c8 | 336 | #define MVPP2_GMAC_INTERNAL_CLK_MASK BIT(4) |
3919357f | 337 | #define MVPP2_GMAC_DISABLE_PADDING BIT(5) |
81b6630f | 338 | #define MVPP2_GMAC_PORT_RESET_MASK BIT(6) |
3f518509 | 339 | #define MVPP2_GMAC_AUTONEG_CONFIG 0xc |
81b6630f AT |
340 | #define MVPP2_GMAC_FORCE_LINK_DOWN BIT(0) |
341 | #define MVPP2_GMAC_FORCE_LINK_PASS BIT(1) | |
3919357f AT |
342 | #define MVPP2_GMAC_IN_BAND_AUTONEG BIT(2) |
343 | #define MVPP2_GMAC_IN_BAND_AUTONEG_BYPASS BIT(3) | |
81b6630f AT |
344 | #define MVPP2_GMAC_CONFIG_MII_SPEED BIT(5) |
345 | #define MVPP2_GMAC_CONFIG_GMII_SPEED BIT(6) | |
346 | #define MVPP2_GMAC_AN_SPEED_EN BIT(7) | |
347 | #define MVPP2_GMAC_FC_ADV_EN BIT(9) | |
3919357f | 348 | #define MVPP2_GMAC_FLOW_CTRL_AUTONEG BIT(11) |
81b6630f AT |
349 | #define MVPP2_GMAC_CONFIG_FULL_DUPLEX BIT(12) |
350 | #define MVPP2_GMAC_AN_DUPLEX_EN BIT(13) | |
fd3651b2 AT |
351 | #define MVPP2_GMAC_STATUS0 0x10 |
352 | #define MVPP2_GMAC_STATUS0_LINK_UP BIT(0) | |
3f518509 | 353 | #define MVPP2_GMAC_PORT_FIFO_CFG_1_REG 0x1c |
81b6630f AT |
354 | #define MVPP2_GMAC_TX_FIFO_MIN_TH_OFFS 6 |
355 | #define MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK 0x1fc0 | |
356 | #define MVPP2_GMAC_TX_FIFO_MIN_TH_MASK(v) (((v) << 6) & \ | |
3f518509 | 357 | MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK) |
fd3651b2 AT |
358 | #define MVPP22_GMAC_INT_STAT 0x20 |
359 | #define MVPP22_GMAC_INT_STAT_LINK BIT(1) | |
360 | #define MVPP22_GMAC_INT_MASK 0x24 | |
361 | #define MVPP22_GMAC_INT_MASK_LINK_STAT BIT(1) | |
26975821 | 362 | #define MVPP22_GMAC_CTRL_4_REG 0x90 |
81b6630f AT |
363 | #define MVPP22_CTRL4_EXT_PIN_GMII_SEL BIT(0) |
364 | #define MVPP22_CTRL4_DP_CLK_SEL BIT(5) | |
1068ec79 | 365 | #define MVPP22_CTRL4_SYNC_BYPASS_DIS BIT(6) |
81b6630f | 366 | #define MVPP22_CTRL4_QSGMII_BYPASS_ACTIVE BIT(7) |
fd3651b2 AT |
367 | #define MVPP22_GMAC_INT_SUM_MASK 0xa4 |
368 | #define MVPP22_GMAC_INT_SUM_MASK_LINK_STAT BIT(1) | |
26975821 TP |
369 | |
370 | /* Per-port XGMAC registers. PPv2.2 only, only for GOP port 0, | |
371 | * relative to port->base. | |
372 | */ | |
725757ae | 373 | #define MVPP22_XLG_CTRL0_REG 0x100 |
81b6630f AT |
374 | #define MVPP22_XLG_CTRL0_PORT_EN BIT(0) |
375 | #define MVPP22_XLG_CTRL0_MAC_RESET_DIS BIT(1) | |
77321959 | 376 | #define MVPP22_XLG_CTRL0_RX_FLOW_CTRL_EN BIT(7) |
81b6630f | 377 | #define MVPP22_XLG_CTRL0_MIB_CNT_DIS BIT(14) |
76eb1b1d | 378 | #define MVPP22_XLG_CTRL1_REG 0x104 |
ec15ecde | 379 | #define MVPP22_XLG_CTRL1_FRAMESIZELIMIT_OFFS 0 |
76eb1b1d | 380 | #define MVPP22_XLG_CTRL1_FRAMESIZELIMIT_MASK 0x1fff |
fd3651b2 AT |
381 | #define MVPP22_XLG_STATUS 0x10c |
382 | #define MVPP22_XLG_STATUS_LINK_UP BIT(0) | |
383 | #define MVPP22_XLG_INT_STAT 0x114 | |
384 | #define MVPP22_XLG_INT_STAT_LINK BIT(1) | |
385 | #define MVPP22_XLG_INT_MASK 0x118 | |
386 | #define MVPP22_XLG_INT_MASK_LINK BIT(1) | |
26975821 | 387 | #define MVPP22_XLG_CTRL3_REG 0x11c |
81b6630f AT |
388 | #define MVPP22_XLG_CTRL3_MACMODESELECT_MASK (7 << 13) |
389 | #define MVPP22_XLG_CTRL3_MACMODESELECT_GMAC (0 << 13) | |
390 | #define MVPP22_XLG_CTRL3_MACMODESELECT_10G (1 << 13) | |
fd3651b2 AT |
391 | #define MVPP22_XLG_EXT_INT_MASK 0x15c |
392 | #define MVPP22_XLG_EXT_INT_MASK_XLG BIT(1) | |
393 | #define MVPP22_XLG_EXT_INT_MASK_GIG BIT(2) | |
77321959 AT |
394 | #define MVPP22_XLG_CTRL4_REG 0x184 |
395 | #define MVPP22_XLG_CTRL4_FWD_FC BIT(5) | |
396 | #define MVPP22_XLG_CTRL4_FWD_PFC BIT(6) | |
397 | #define MVPP22_XLG_CTRL4_MACMODSELECT_GMAC BIT(12) | |
398 | ||
26975821 TP |
399 | /* SMI registers. PPv2.2 only, relative to priv->iface_base. */ |
400 | #define MVPP22_SMI_MISC_CFG_REG 0x1204 | |
81b6630f | 401 | #define MVPP22_SMI_POLLING_EN BIT(10) |
3f518509 | 402 | |
a786841d TP |
403 | #define MVPP22_GMAC_BASE(port) (0x7000 + (port) * 0x1000 + 0xe00) |
404 | ||
3f518509 MW |
405 | #define MVPP2_CAUSE_TXQ_SENT_DESC_ALL_MASK 0xff |
406 | ||
407 | /* Descriptor ring Macros */ | |
408 | #define MVPP2_QUEUE_NEXT_DESC(q, index) \ | |
409 | (((index) < (q)->last_desc) ? ((index) + 1) : 0) | |
410 | ||
f84bf386 AT |
411 | /* XPCS registers. PPv2.2 only */ |
412 | #define MVPP22_MPCS_BASE(port) (0x7000 + (port) * 0x1000) | |
413 | #define MVPP22_MPCS_CTRL 0x14 | |
414 | #define MVPP22_MPCS_CTRL_FWD_ERR_CONN BIT(10) | |
415 | #define MVPP22_MPCS_CLK_RESET 0x14c | |
416 | #define MAC_CLK_RESET_SD_TX BIT(0) | |
417 | #define MAC_CLK_RESET_SD_RX BIT(1) | |
418 | #define MAC_CLK_RESET_MAC BIT(2) | |
419 | #define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4) | |
420 | #define MVPP22_MPCS_CLK_RESET_DIV_SET BIT(11) | |
421 | ||
422 | /* XPCS registers. PPv2.2 only */ | |
423 | #define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000) | |
424 | #define MVPP22_XPCS_CFG0 0x0 | |
425 | #define MVPP22_XPCS_CFG0_PCS_MODE(n) ((n) << 3) | |
426 | #define MVPP22_XPCS_CFG0_ACTIVE_LANE(n) ((n) << 5) | |
427 | ||
428 | /* System controller registers. Accessed through a regmap. */ | |
429 | #define GENCONF_SOFT_RESET1 0x1108 | |
430 | #define GENCONF_SOFT_RESET1_GOP BIT(6) | |
431 | #define GENCONF_PORT_CTRL0 0x1110 | |
432 | #define GENCONF_PORT_CTRL0_BUS_WIDTH_SELECT BIT(1) | |
433 | #define GENCONF_PORT_CTRL0_RX_DATA_SAMPLE BIT(29) | |
434 | #define GENCONF_PORT_CTRL0_CLK_DIV_PHASE_CLR BIT(31) | |
435 | #define GENCONF_PORT_CTRL1 0x1114 | |
436 | #define GENCONF_PORT_CTRL1_EN(p) BIT(p) | |
437 | #define GENCONF_PORT_CTRL1_RESET(p) (BIT(p) << 28) | |
438 | #define GENCONF_CTRL0 0x1120 | |
439 | #define GENCONF_CTRL0_PORT0_RGMII BIT(0) | |
440 | #define GENCONF_CTRL0_PORT1_RGMII_MII BIT(1) | |
441 | #define GENCONF_CTRL0_PORT1_RGMII BIT(2) | |
442 | ||
3f518509 MW |
443 | /* Various constants */ |
444 | ||
445 | /* Coalescing */ | |
446 | #define MVPP2_TXDONE_COAL_PKTS_THRESH 15 | |
edc660fa | 447 | #define MVPP2_TXDONE_HRTIMER_PERIOD_NS 1000000UL |
213f428f | 448 | #define MVPP2_TXDONE_COAL_USEC 1000 |
3f518509 MW |
449 | #define MVPP2_RX_COAL_PKTS 32 |
450 | #define MVPP2_RX_COAL_USEC 100 | |
451 | ||
452 | /* The two bytes Marvell header. Either contains a special value used | |
453 | * by Marvell switches when a specific hardware mode is enabled (not | |
454 | * supported by this driver) or is filled automatically by zeroes on | |
455 | * the RX side. Those two bytes being at the front of the Ethernet | |
456 | * header, they allow to have the IP header aligned on a 4 bytes | |
457 | * boundary automatically: the hardware skips those two bytes on its | |
458 | * own. | |
459 | */ | |
460 | #define MVPP2_MH_SIZE 2 | |
461 | #define MVPP2_ETH_TYPE_LEN 2 | |
462 | #define MVPP2_PPPOE_HDR_SIZE 8 | |
463 | #define MVPP2_VLAN_TAG_LEN 4 | |
464 | ||
465 | /* Lbtd 802.3 type */ | |
466 | #define MVPP2_IP_LBDT_TYPE 0xfffa | |
467 | ||
3f518509 MW |
468 | #define MVPP2_TX_CSUM_MAX_SIZE 9800 |
469 | ||
470 | /* Timeout constants */ | |
471 | #define MVPP2_TX_DISABLE_TIMEOUT_MSEC 1000 | |
472 | #define MVPP2_TX_PENDING_TIMEOUT_MSEC 1000 | |
473 | ||
474 | #define MVPP2_TX_MTU_MAX 0x7ffff | |
475 | ||
476 | /* Maximum number of T-CONTs of PON port */ | |
477 | #define MVPP2_MAX_TCONT 16 | |
478 | ||
479 | /* Maximum number of supported ports */ | |
480 | #define MVPP2_MAX_PORTS 4 | |
481 | ||
482 | /* Maximum number of TXQs used by single port */ | |
483 | #define MVPP2_MAX_TXQ 8 | |
484 | ||
3f518509 MW |
485 | /* Dfault number of RXQs in use */ |
486 | #define MVPP2_DEFAULT_RXQ 4 | |
487 | ||
3f518509 MW |
488 | /* Max number of Rx descriptors */ |
489 | #define MVPP2_MAX_RXD 128 | |
490 | ||
491 | /* Max number of Tx descriptors */ | |
492 | #define MVPP2_MAX_TXD 1024 | |
493 | ||
494 | /* Amount of Tx descriptors that can be reserved at once by CPU */ | |
495 | #define MVPP2_CPU_DESC_CHUNK 64 | |
496 | ||
497 | /* Max number of Tx descriptors in each aggregated queue */ | |
498 | #define MVPP2_AGGR_TXQ_SIZE 256 | |
499 | ||
500 | /* Descriptor aligned size */ | |
501 | #define MVPP2_DESC_ALIGNED_SIZE 32 | |
502 | ||
503 | /* Descriptor alignment mask */ | |
504 | #define MVPP2_TX_DESC_ALIGN (MVPP2_DESC_ALIGNED_SIZE - 1) | |
505 | ||
506 | /* RX FIFO constants */ | |
507 | #define MVPP2_RX_FIFO_PORT_DATA_SIZE 0x2000 | |
508 | #define MVPP2_RX_FIFO_PORT_ATTR_SIZE 0x80 | |
509 | #define MVPP2_RX_FIFO_PORT_MIN_PKT 0x80 | |
510 | ||
511 | /* RX buffer constants */ | |
512 | #define MVPP2_SKB_SHINFO_SIZE \ | |
513 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) | |
514 | ||
515 | #define MVPP2_RX_PKT_SIZE(mtu) \ | |
516 | ALIGN((mtu) + MVPP2_MH_SIZE + MVPP2_VLAN_TAG_LEN + \ | |
4a0a12d2 | 517 | ETH_HLEN + ETH_FCS_LEN, cache_line_size()) |
3f518509 MW |
518 | |
519 | #define MVPP2_RX_BUF_SIZE(pkt_size) ((pkt_size) + NET_SKB_PAD) | |
520 | #define MVPP2_RX_TOTAL_SIZE(buf_size) ((buf_size) + MVPP2_SKB_SHINFO_SIZE) | |
521 | #define MVPP2_RX_MAX_PKT_SIZE(total_size) \ | |
522 | ((total_size) - NET_SKB_PAD - MVPP2_SKB_SHINFO_SIZE) | |
523 | ||
524 | #define MVPP2_BIT_TO_BYTE(bit) ((bit) / 8) | |
525 | ||
526 | /* IPv6 max L3 address size */ | |
527 | #define MVPP2_MAX_L3_ADDR_SIZE 16 | |
528 | ||
529 | /* Port flags */ | |
530 | #define MVPP2_F_LOOPBACK BIT(0) | |
531 | ||
532 | /* Marvell tag types */ | |
533 | enum mvpp2_tag_type { | |
534 | MVPP2_TAG_TYPE_NONE = 0, | |
535 | MVPP2_TAG_TYPE_MH = 1, | |
536 | MVPP2_TAG_TYPE_DSA = 2, | |
537 | MVPP2_TAG_TYPE_EDSA = 3, | |
538 | MVPP2_TAG_TYPE_VLAN = 4, | |
539 | MVPP2_TAG_TYPE_LAST = 5 | |
540 | }; | |
541 | ||
542 | /* Parser constants */ | |
543 | #define MVPP2_PRS_TCAM_SRAM_SIZE 256 | |
544 | #define MVPP2_PRS_TCAM_WORDS 6 | |
545 | #define MVPP2_PRS_SRAM_WORDS 4 | |
546 | #define MVPP2_PRS_FLOW_ID_SIZE 64 | |
547 | #define MVPP2_PRS_FLOW_ID_MASK 0x3f | |
548 | #define MVPP2_PRS_TCAM_ENTRY_INVALID 1 | |
549 | #define MVPP2_PRS_TCAM_DSA_TAGGED_BIT BIT(5) | |
550 | #define MVPP2_PRS_IPV4_HEAD 0x40 | |
551 | #define MVPP2_PRS_IPV4_HEAD_MASK 0xf0 | |
552 | #define MVPP2_PRS_IPV4_MC 0xe0 | |
553 | #define MVPP2_PRS_IPV4_MC_MASK 0xf0 | |
554 | #define MVPP2_PRS_IPV4_BC_MASK 0xff | |
555 | #define MVPP2_PRS_IPV4_IHL 0x5 | |
556 | #define MVPP2_PRS_IPV4_IHL_MASK 0xf | |
557 | #define MVPP2_PRS_IPV6_MC 0xff | |
558 | #define MVPP2_PRS_IPV6_MC_MASK 0xff | |
559 | #define MVPP2_PRS_IPV6_HOP_MASK 0xff | |
560 | #define MVPP2_PRS_TCAM_PROTO_MASK 0xff | |
561 | #define MVPP2_PRS_TCAM_PROTO_MASK_L 0x3f | |
562 | #define MVPP2_PRS_DBL_VLANS_MAX 100 | |
563 | ||
564 | /* Tcam structure: | |
565 | * - lookup ID - 4 bits | |
566 | * - port ID - 1 byte | |
567 | * - additional information - 1 byte | |
568 | * - header data - 8 bytes | |
569 | * The fields are represented by MVPP2_PRS_TCAM_DATA_REG(5)->(0). | |
570 | */ | |
571 | #define MVPP2_PRS_AI_BITS 8 | |
572 | #define MVPP2_PRS_PORT_MASK 0xff | |
573 | #define MVPP2_PRS_LU_MASK 0xf | |
574 | #define MVPP2_PRS_TCAM_DATA_BYTE(offs) \ | |
575 | (((offs) - ((offs) % 2)) * 2 + ((offs) % 2)) | |
576 | #define MVPP2_PRS_TCAM_DATA_BYTE_EN(offs) \ | |
577 | (((offs) * 2) - ((offs) % 2) + 2) | |
578 | #define MVPP2_PRS_TCAM_AI_BYTE 16 | |
579 | #define MVPP2_PRS_TCAM_PORT_BYTE 17 | |
580 | #define MVPP2_PRS_TCAM_LU_BYTE 20 | |
581 | #define MVPP2_PRS_TCAM_EN_OFFS(offs) ((offs) + 2) | |
582 | #define MVPP2_PRS_TCAM_INV_WORD 5 | |
583 | /* Tcam entries ID */ | |
584 | #define MVPP2_PE_DROP_ALL 0 | |
585 | #define MVPP2_PE_FIRST_FREE_TID 1 | |
586 | #define MVPP2_PE_LAST_FREE_TID (MVPP2_PRS_TCAM_SRAM_SIZE - 31) | |
587 | #define MVPP2_PE_IP6_EXT_PROTO_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 30) | |
588 | #define MVPP2_PE_MAC_MC_IP6 (MVPP2_PRS_TCAM_SRAM_SIZE - 29) | |
589 | #define MVPP2_PE_IP6_ADDR_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 28) | |
590 | #define MVPP2_PE_IP4_ADDR_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 27) | |
591 | #define MVPP2_PE_LAST_DEFAULT_FLOW (MVPP2_PRS_TCAM_SRAM_SIZE - 26) | |
592 | #define MVPP2_PE_FIRST_DEFAULT_FLOW (MVPP2_PRS_TCAM_SRAM_SIZE - 19) | |
593 | #define MVPP2_PE_EDSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 18) | |
594 | #define MVPP2_PE_EDSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 17) | |
595 | #define MVPP2_PE_DSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 16) | |
596 | #define MVPP2_PE_DSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 15) | |
597 | #define MVPP2_PE_ETYPE_EDSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 14) | |
598 | #define MVPP2_PE_ETYPE_EDSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 13) | |
599 | #define MVPP2_PE_ETYPE_DSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 12) | |
600 | #define MVPP2_PE_ETYPE_DSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 11) | |
601 | #define MVPP2_PE_MH_DEFAULT (MVPP2_PRS_TCAM_SRAM_SIZE - 10) | |
602 | #define MVPP2_PE_DSA_DEFAULT (MVPP2_PRS_TCAM_SRAM_SIZE - 9) | |
603 | #define MVPP2_PE_IP6_PROTO_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 8) | |
604 | #define MVPP2_PE_IP4_PROTO_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 7) | |
605 | #define MVPP2_PE_ETH_TYPE_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 6) | |
606 | #define MVPP2_PE_VLAN_DBL (MVPP2_PRS_TCAM_SRAM_SIZE - 5) | |
607 | #define MVPP2_PE_VLAN_NONE (MVPP2_PRS_TCAM_SRAM_SIZE - 4) | |
608 | #define MVPP2_PE_MAC_MC_ALL (MVPP2_PRS_TCAM_SRAM_SIZE - 3) | |
609 | #define MVPP2_PE_MAC_PROMISCUOUS (MVPP2_PRS_TCAM_SRAM_SIZE - 2) | |
610 | #define MVPP2_PE_MAC_NON_PROMISCUOUS (MVPP2_PRS_TCAM_SRAM_SIZE - 1) | |
611 | ||
612 | /* Sram structure | |
613 | * The fields are represented by MVPP2_PRS_TCAM_DATA_REG(3)->(0). | |
614 | */ | |
615 | #define MVPP2_PRS_SRAM_RI_OFFS 0 | |
616 | #define MVPP2_PRS_SRAM_RI_WORD 0 | |
617 | #define MVPP2_PRS_SRAM_RI_CTRL_OFFS 32 | |
618 | #define MVPP2_PRS_SRAM_RI_CTRL_WORD 1 | |
619 | #define MVPP2_PRS_SRAM_RI_CTRL_BITS 32 | |
620 | #define MVPP2_PRS_SRAM_SHIFT_OFFS 64 | |
621 | #define MVPP2_PRS_SRAM_SHIFT_SIGN_BIT 72 | |
622 | #define MVPP2_PRS_SRAM_UDF_OFFS 73 | |
623 | #define MVPP2_PRS_SRAM_UDF_BITS 8 | |
624 | #define MVPP2_PRS_SRAM_UDF_MASK 0xff | |
625 | #define MVPP2_PRS_SRAM_UDF_SIGN_BIT 81 | |
626 | #define MVPP2_PRS_SRAM_UDF_TYPE_OFFS 82 | |
627 | #define MVPP2_PRS_SRAM_UDF_TYPE_MASK 0x7 | |
628 | #define MVPP2_PRS_SRAM_UDF_TYPE_L3 1 | |
629 | #define MVPP2_PRS_SRAM_UDF_TYPE_L4 4 | |
630 | #define MVPP2_PRS_SRAM_OP_SEL_SHIFT_OFFS 85 | |
631 | #define MVPP2_PRS_SRAM_OP_SEL_SHIFT_MASK 0x3 | |
632 | #define MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD 1 | |
633 | #define MVPP2_PRS_SRAM_OP_SEL_SHIFT_IP4_ADD 2 | |
634 | #define MVPP2_PRS_SRAM_OP_SEL_SHIFT_IP6_ADD 3 | |
635 | #define MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS 87 | |
636 | #define MVPP2_PRS_SRAM_OP_SEL_UDF_BITS 2 | |
637 | #define MVPP2_PRS_SRAM_OP_SEL_UDF_MASK 0x3 | |
638 | #define MVPP2_PRS_SRAM_OP_SEL_UDF_ADD 0 | |
639 | #define MVPP2_PRS_SRAM_OP_SEL_UDF_IP4_ADD 2 | |
640 | #define MVPP2_PRS_SRAM_OP_SEL_UDF_IP6_ADD 3 | |
641 | #define MVPP2_PRS_SRAM_OP_SEL_BASE_OFFS 89 | |
642 | #define MVPP2_PRS_SRAM_AI_OFFS 90 | |
643 | #define MVPP2_PRS_SRAM_AI_CTRL_OFFS 98 | |
644 | #define MVPP2_PRS_SRAM_AI_CTRL_BITS 8 | |
645 | #define MVPP2_PRS_SRAM_AI_MASK 0xff | |
646 | #define MVPP2_PRS_SRAM_NEXT_LU_OFFS 106 | |
647 | #define MVPP2_PRS_SRAM_NEXT_LU_MASK 0xf | |
648 | #define MVPP2_PRS_SRAM_LU_DONE_BIT 110 | |
649 | #define MVPP2_PRS_SRAM_LU_GEN_BIT 111 | |
650 | ||
651 | /* Sram result info bits assignment */ | |
652 | #define MVPP2_PRS_RI_MAC_ME_MASK 0x1 | |
653 | #define MVPP2_PRS_RI_DSA_MASK 0x2 | |
8138affc TP |
654 | #define MVPP2_PRS_RI_VLAN_MASK (BIT(2) | BIT(3)) |
655 | #define MVPP2_PRS_RI_VLAN_NONE 0x0 | |
3f518509 MW |
656 | #define MVPP2_PRS_RI_VLAN_SINGLE BIT(2) |
657 | #define MVPP2_PRS_RI_VLAN_DOUBLE BIT(3) | |
658 | #define MVPP2_PRS_RI_VLAN_TRIPLE (BIT(2) | BIT(3)) | |
659 | #define MVPP2_PRS_RI_CPU_CODE_MASK 0x70 | |
660 | #define MVPP2_PRS_RI_CPU_CODE_RX_SPEC BIT(4) | |
8138affc TP |
661 | #define MVPP2_PRS_RI_L2_CAST_MASK (BIT(9) | BIT(10)) |
662 | #define MVPP2_PRS_RI_L2_UCAST 0x0 | |
3f518509 MW |
663 | #define MVPP2_PRS_RI_L2_MCAST BIT(9) |
664 | #define MVPP2_PRS_RI_L2_BCAST BIT(10) | |
665 | #define MVPP2_PRS_RI_PPPOE_MASK 0x800 | |
8138affc TP |
666 | #define MVPP2_PRS_RI_L3_PROTO_MASK (BIT(12) | BIT(13) | BIT(14)) |
667 | #define MVPP2_PRS_RI_L3_UN 0x0 | |
3f518509 MW |
668 | #define MVPP2_PRS_RI_L3_IP4 BIT(12) |
669 | #define MVPP2_PRS_RI_L3_IP4_OPT BIT(13) | |
670 | #define MVPP2_PRS_RI_L3_IP4_OTHER (BIT(12) | BIT(13)) | |
671 | #define MVPP2_PRS_RI_L3_IP6 BIT(14) | |
672 | #define MVPP2_PRS_RI_L3_IP6_EXT (BIT(12) | BIT(14)) | |
673 | #define MVPP2_PRS_RI_L3_ARP (BIT(13) | BIT(14)) | |
8138affc TP |
674 | #define MVPP2_PRS_RI_L3_ADDR_MASK (BIT(15) | BIT(16)) |
675 | #define MVPP2_PRS_RI_L3_UCAST 0x0 | |
3f518509 MW |
676 | #define MVPP2_PRS_RI_L3_MCAST BIT(15) |
677 | #define MVPP2_PRS_RI_L3_BCAST (BIT(15) | BIT(16)) | |
678 | #define MVPP2_PRS_RI_IP_FRAG_MASK 0x20000 | |
aff3da39 | 679 | #define MVPP2_PRS_RI_IP_FRAG_TRUE BIT(17) |
3f518509 MW |
680 | #define MVPP2_PRS_RI_UDF3_MASK 0x300000 |
681 | #define MVPP2_PRS_RI_UDF3_RX_SPECIAL BIT(21) | |
682 | #define MVPP2_PRS_RI_L4_PROTO_MASK 0x1c00000 | |
683 | #define MVPP2_PRS_RI_L4_TCP BIT(22) | |
684 | #define MVPP2_PRS_RI_L4_UDP BIT(23) | |
685 | #define MVPP2_PRS_RI_L4_OTHER (BIT(22) | BIT(23)) | |
686 | #define MVPP2_PRS_RI_UDF7_MASK 0x60000000 | |
687 | #define MVPP2_PRS_RI_UDF7_IP6_LITE BIT(29) | |
688 | #define MVPP2_PRS_RI_DROP_MASK 0x80000000 | |
689 | ||
690 | /* Sram additional info bits assignment */ | |
691 | #define MVPP2_PRS_IPV4_DIP_AI_BIT BIT(0) | |
692 | #define MVPP2_PRS_IPV6_NO_EXT_AI_BIT BIT(0) | |
693 | #define MVPP2_PRS_IPV6_EXT_AI_BIT BIT(1) | |
694 | #define MVPP2_PRS_IPV6_EXT_AH_AI_BIT BIT(2) | |
695 | #define MVPP2_PRS_IPV6_EXT_AH_LEN_AI_BIT BIT(3) | |
696 | #define MVPP2_PRS_IPV6_EXT_AH_L4_AI_BIT BIT(4) | |
697 | #define MVPP2_PRS_SINGLE_VLAN_AI 0 | |
698 | #define MVPP2_PRS_DBL_VLAN_AI_BIT BIT(7) | |
699 | ||
700 | /* DSA/EDSA type */ | |
701 | #define MVPP2_PRS_TAGGED true | |
702 | #define MVPP2_PRS_UNTAGGED false | |
703 | #define MVPP2_PRS_EDSA true | |
704 | #define MVPP2_PRS_DSA false | |
705 | ||
706 | /* MAC entries, shadow udf */ | |
707 | enum mvpp2_prs_udf { | |
708 | MVPP2_PRS_UDF_MAC_DEF, | |
709 | MVPP2_PRS_UDF_MAC_RANGE, | |
710 | MVPP2_PRS_UDF_L2_DEF, | |
711 | MVPP2_PRS_UDF_L2_DEF_COPY, | |
712 | MVPP2_PRS_UDF_L2_USER, | |
713 | }; | |
714 | ||
715 | /* Lookup ID */ | |
716 | enum mvpp2_prs_lookup { | |
717 | MVPP2_PRS_LU_MH, | |
718 | MVPP2_PRS_LU_MAC, | |
719 | MVPP2_PRS_LU_DSA, | |
720 | MVPP2_PRS_LU_VLAN, | |
721 | MVPP2_PRS_LU_L2, | |
722 | MVPP2_PRS_LU_PPPOE, | |
723 | MVPP2_PRS_LU_IP4, | |
724 | MVPP2_PRS_LU_IP6, | |
725 | MVPP2_PRS_LU_FLOWS, | |
726 | MVPP2_PRS_LU_LAST, | |
727 | }; | |
728 | ||
729 | /* L3 cast enum */ | |
730 | enum mvpp2_prs_l3_cast { | |
731 | MVPP2_PRS_L3_UNI_CAST, | |
732 | MVPP2_PRS_L3_MULTI_CAST, | |
733 | MVPP2_PRS_L3_BROAD_CAST | |
734 | }; | |
735 | ||
736 | /* Classifier constants */ | |
737 | #define MVPP2_CLS_FLOWS_TBL_SIZE 512 | |
738 | #define MVPP2_CLS_FLOWS_TBL_DATA_WORDS 3 | |
739 | #define MVPP2_CLS_LKP_TBL_SIZE 64 | |
740 | ||
741 | /* BM constants */ | |
742 | #define MVPP2_BM_POOLS_NUM 8 | |
743 | #define MVPP2_BM_LONG_BUF_NUM 1024 | |
744 | #define MVPP2_BM_SHORT_BUF_NUM 2048 | |
745 | #define MVPP2_BM_POOL_SIZE_MAX (16*1024 - MVPP2_BM_POOL_PTR_ALIGN/4) | |
746 | #define MVPP2_BM_POOL_PTR_ALIGN 128 | |
747 | #define MVPP2_BM_SWF_LONG_POOL(port) ((port > 2) ? 2 : port) | |
748 | #define MVPP2_BM_SWF_SHORT_POOL 3 | |
749 | ||
750 | /* BM cookie (32 bits) definition */ | |
751 | #define MVPP2_BM_COOKIE_POOL_OFFS 8 | |
752 | #define MVPP2_BM_COOKIE_CPU_OFFS 24 | |
753 | ||
754 | /* BM short pool packet size | |
755 | * These value assure that for SWF the total number | |
756 | * of bytes allocated for each buffer will be 512 | |
757 | */ | |
758 | #define MVPP2_BM_SHORT_PKT_SIZE MVPP2_RX_MAX_PKT_SIZE(512) | |
759 | ||
a786841d TP |
760 | #define MVPP21_ADDR_SPACE_SZ 0 |
761 | #define MVPP22_ADDR_SPACE_SZ SZ_64K | |
762 | ||
df089aa0 | 763 | #define MVPP2_MAX_THREADS 8 |
591f4cfa | 764 | #define MVPP2_MAX_QVECS MVPP2_MAX_THREADS |
a786841d | 765 | |
3f518509 MW |
766 | enum mvpp2_bm_type { |
767 | MVPP2_BM_FREE, | |
768 | MVPP2_BM_SWF_LONG, | |
769 | MVPP2_BM_SWF_SHORT | |
770 | }; | |
771 | ||
772 | /* Definitions */ | |
773 | ||
774 | /* Shared Packet Processor resources */ | |
775 | struct mvpp2 { | |
776 | /* Shared registers' base addresses */ | |
3f518509 | 777 | void __iomem *lms_base; |
a786841d TP |
778 | void __iomem *iface_base; |
779 | ||
df089aa0 TP |
780 | /* On PPv2.2, each "software thread" can access the base |
781 | * register through a separate address space, each 64 KB apart | |
782 | * from each other. Typically, such address spaces will be | |
783 | * used per CPU. | |
a786841d | 784 | */ |
df089aa0 | 785 | void __iomem *swth_base[MVPP2_MAX_THREADS]; |
3f518509 | 786 | |
f84bf386 AT |
787 | /* On PPv2.2, some port control registers are located into the system |
788 | * controller space. These registers are accessible through a regmap. | |
789 | */ | |
790 | struct regmap *sysctrl_base; | |
791 | ||
3f518509 MW |
792 | /* Common clocks */ |
793 | struct clk *pp_clk; | |
794 | struct clk *gop_clk; | |
fceb55d4 | 795 | struct clk *mg_clk; |
4792ea04 | 796 | struct clk *axi_clk; |
3f518509 MW |
797 | |
798 | /* List of pointers to port structures */ | |
799 | struct mvpp2_port **port_list; | |
800 | ||
801 | /* Aggregated TXQs */ | |
802 | struct mvpp2_tx_queue *aggr_txqs; | |
803 | ||
804 | /* BM pools */ | |
805 | struct mvpp2_bm_pool *bm_pools; | |
806 | ||
807 | /* PRS shadow table */ | |
808 | struct mvpp2_prs_shadow *prs_shadow; | |
809 | /* PRS auxiliary table for double vlan entries control */ | |
810 | bool *prs_double_vlans; | |
811 | ||
812 | /* Tclk value */ | |
813 | u32 tclk; | |
faca9247 TP |
814 | |
815 | /* HW version */ | |
816 | enum { MVPP21, MVPP22 } hw_version; | |
59b9a31e TP |
817 | |
818 | /* Maximum number of RXQs per port */ | |
819 | unsigned int max_port_rxqs; | |
3f518509 MW |
820 | }; |
821 | ||
822 | struct mvpp2_pcpu_stats { | |
823 | struct u64_stats_sync syncp; | |
824 | u64 rx_packets; | |
825 | u64 rx_bytes; | |
826 | u64 tx_packets; | |
827 | u64 tx_bytes; | |
828 | }; | |
829 | ||
edc660fa MW |
830 | /* Per-CPU port control */ |
831 | struct mvpp2_port_pcpu { | |
832 | struct hrtimer tx_done_timer; | |
833 | bool timer_scheduled; | |
834 | /* Tasklet for egress finalization */ | |
835 | struct tasklet_struct tx_done_tasklet; | |
836 | }; | |
837 | ||
591f4cfa TP |
838 | struct mvpp2_queue_vector { |
839 | int irq; | |
840 | struct napi_struct napi; | |
841 | enum { MVPP2_QUEUE_VECTOR_SHARED, MVPP2_QUEUE_VECTOR_PRIVATE } type; | |
842 | int sw_thread_id; | |
843 | u16 sw_thread_mask; | |
844 | int first_rxq; | |
845 | int nrxqs; | |
846 | u32 pending_cause_rx; | |
847 | struct mvpp2_port *port; | |
848 | }; | |
849 | ||
3f518509 MW |
850 | struct mvpp2_port { |
851 | u8 id; | |
852 | ||
a786841d TP |
853 | /* Index of the port from the "group of ports" complex point |
854 | * of view | |
855 | */ | |
856 | int gop_id; | |
857 | ||
fd3651b2 AT |
858 | int link_irq; |
859 | ||
3f518509 MW |
860 | struct mvpp2 *priv; |
861 | ||
862 | /* Per-port registers' base address */ | |
863 | void __iomem *base; | |
864 | ||
865 | struct mvpp2_rx_queue **rxqs; | |
09f83975 | 866 | unsigned int nrxqs; |
3f518509 | 867 | struct mvpp2_tx_queue **txqs; |
09f83975 | 868 | unsigned int ntxqs; |
3f518509 MW |
869 | struct net_device *dev; |
870 | ||
871 | int pkt_size; | |
872 | ||
edc660fa MW |
873 | /* Per-CPU port control */ |
874 | struct mvpp2_port_pcpu __percpu *pcpu; | |
875 | ||
3f518509 MW |
876 | /* Flags */ |
877 | unsigned long flags; | |
878 | ||
879 | u16 tx_ring_size; | |
880 | u16 rx_ring_size; | |
881 | struct mvpp2_pcpu_stats __percpu *stats; | |
882 | ||
3f518509 MW |
883 | phy_interface_t phy_interface; |
884 | struct device_node *phy_node; | |
542897d9 | 885 | struct phy *comphy; |
3f518509 MW |
886 | unsigned int link; |
887 | unsigned int duplex; | |
888 | unsigned int speed; | |
889 | ||
890 | struct mvpp2_bm_pool *pool_long; | |
891 | struct mvpp2_bm_pool *pool_short; | |
892 | ||
893 | /* Index of first port's physical RXQ */ | |
894 | u8 first_rxq; | |
591f4cfa TP |
895 | |
896 | struct mvpp2_queue_vector qvecs[MVPP2_MAX_QVECS]; | |
897 | unsigned int nqvecs; | |
213f428f TP |
898 | bool has_tx_irqs; |
899 | ||
900 | u32 tx_time_coal; | |
3f518509 MW |
901 | }; |
902 | ||
903 | /* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the | |
904 | * layout of the transmit and reception DMA descriptors, and their | |
905 | * layout is therefore defined by the hardware design | |
906 | */ | |
907 | ||
908 | #define MVPP2_TXD_L3_OFF_SHIFT 0 | |
909 | #define MVPP2_TXD_IP_HLEN_SHIFT 8 | |
910 | #define MVPP2_TXD_L4_CSUM_FRAG BIT(13) | |
911 | #define MVPP2_TXD_L4_CSUM_NOT BIT(14) | |
912 | #define MVPP2_TXD_IP_CSUM_DISABLE BIT(15) | |
913 | #define MVPP2_TXD_PADDING_DISABLE BIT(23) | |
914 | #define MVPP2_TXD_L4_UDP BIT(24) | |
915 | #define MVPP2_TXD_L3_IP6 BIT(26) | |
916 | #define MVPP2_TXD_L_DESC BIT(28) | |
917 | #define MVPP2_TXD_F_DESC BIT(29) | |
918 | ||
919 | #define MVPP2_RXD_ERR_SUMMARY BIT(15) | |
920 | #define MVPP2_RXD_ERR_CODE_MASK (BIT(13) | BIT(14)) | |
921 | #define MVPP2_RXD_ERR_CRC 0x0 | |
922 | #define MVPP2_RXD_ERR_OVERRUN BIT(13) | |
923 | #define MVPP2_RXD_ERR_RESOURCE (BIT(13) | BIT(14)) | |
924 | #define MVPP2_RXD_BM_POOL_ID_OFFS 16 | |
925 | #define MVPP2_RXD_BM_POOL_ID_MASK (BIT(16) | BIT(17) | BIT(18)) | |
926 | #define MVPP2_RXD_HWF_SYNC BIT(21) | |
927 | #define MVPP2_RXD_L4_CSUM_OK BIT(22) | |
928 | #define MVPP2_RXD_IP4_HEADER_ERR BIT(24) | |
929 | #define MVPP2_RXD_L4_TCP BIT(25) | |
930 | #define MVPP2_RXD_L4_UDP BIT(26) | |
931 | #define MVPP2_RXD_L3_IP4 BIT(28) | |
932 | #define MVPP2_RXD_L3_IP6 BIT(30) | |
933 | #define MVPP2_RXD_BUF_HDR BIT(31) | |
934 | ||
054f6372 TP |
935 | /* HW TX descriptor for PPv2.1 */ |
936 | struct mvpp21_tx_desc { | |
3f518509 MW |
937 | u32 command; /* Options used by HW for packet transmitting.*/ |
938 | u8 packet_offset; /* the offset from the buffer beginning */ | |
939 | u8 phys_txq; /* destination queue ID */ | |
940 | u16 data_size; /* data size of transmitted packet in bytes */ | |
20396136 | 941 | u32 buf_dma_addr; /* physical addr of transmitted buffer */ |
3f518509 MW |
942 | u32 buf_cookie; /* cookie for access to TX buffer in tx path */ |
943 | u32 reserved1[3]; /* hw_cmd (for future use, BM, PON, PNC) */ | |
944 | u32 reserved2; /* reserved (for future use) */ | |
945 | }; | |
946 | ||
054f6372 TP |
947 | /* HW RX descriptor for PPv2.1 */ |
948 | struct mvpp21_rx_desc { | |
3f518509 MW |
949 | u32 status; /* info about received packet */ |
950 | u16 reserved1; /* parser_info (for future use, PnC) */ | |
951 | u16 data_size; /* size of received packet in bytes */ | |
20396136 | 952 | u32 buf_dma_addr; /* physical address of the buffer */ |
3f518509 MW |
953 | u32 buf_cookie; /* cookie for access to RX buffer in rx path */ |
954 | u16 reserved2; /* gem_port_id (for future use, PON) */ | |
955 | u16 reserved3; /* csum_l4 (for future use, PnC) */ | |
956 | u8 reserved4; /* bm_qset (for future use, BM) */ | |
957 | u8 reserved5; | |
958 | u16 reserved6; /* classify_info (for future use, PnC) */ | |
959 | u32 reserved7; /* flow_id (for future use, PnC) */ | |
960 | u32 reserved8; | |
961 | }; | |
962 | ||
e7c5359f TP |
963 | /* HW TX descriptor for PPv2.2 */ |
964 | struct mvpp22_tx_desc { | |
965 | u32 command; | |
966 | u8 packet_offset; | |
967 | u8 phys_txq; | |
968 | u16 data_size; | |
969 | u64 reserved1; | |
970 | u64 buf_dma_addr_ptp; | |
971 | u64 buf_cookie_misc; | |
972 | }; | |
973 | ||
974 | /* HW RX descriptor for PPv2.2 */ | |
975 | struct mvpp22_rx_desc { | |
976 | u32 status; | |
977 | u16 reserved1; | |
978 | u16 data_size; | |
979 | u32 reserved2; | |
980 | u32 reserved3; | |
981 | u64 buf_dma_addr_key_hash; | |
982 | u64 buf_cookie_misc; | |
983 | }; | |
984 | ||
054f6372 TP |
985 | /* Opaque type used by the driver to manipulate the HW TX and RX |
986 | * descriptors | |
987 | */ | |
988 | struct mvpp2_tx_desc { | |
989 | union { | |
990 | struct mvpp21_tx_desc pp21; | |
e7c5359f | 991 | struct mvpp22_tx_desc pp22; |
054f6372 TP |
992 | }; |
993 | }; | |
994 | ||
995 | struct mvpp2_rx_desc { | |
996 | union { | |
997 | struct mvpp21_rx_desc pp21; | |
e7c5359f | 998 | struct mvpp22_rx_desc pp22; |
054f6372 TP |
999 | }; |
1000 | }; | |
1001 | ||
8354491c TP |
1002 | struct mvpp2_txq_pcpu_buf { |
1003 | /* Transmitted SKB */ | |
1004 | struct sk_buff *skb; | |
1005 | ||
1006 | /* Physical address of transmitted buffer */ | |
20396136 | 1007 | dma_addr_t dma; |
8354491c TP |
1008 | |
1009 | /* Size transmitted */ | |
1010 | size_t size; | |
1011 | }; | |
1012 | ||
3f518509 MW |
1013 | /* Per-CPU Tx queue control */ |
1014 | struct mvpp2_txq_pcpu { | |
1015 | int cpu; | |
1016 | ||
1017 | /* Number of Tx DMA descriptors in the descriptor ring */ | |
1018 | int size; | |
1019 | ||
1020 | /* Number of currently used Tx DMA descriptor in the | |
1021 | * descriptor ring | |
1022 | */ | |
1023 | int count; | |
1024 | ||
1025 | /* Number of Tx DMA descriptors reserved for each CPU */ | |
1026 | int reserved_num; | |
1027 | ||
8354491c TP |
1028 | /* Infos about transmitted buffers */ |
1029 | struct mvpp2_txq_pcpu_buf *buffs; | |
71ce391d | 1030 | |
3f518509 MW |
1031 | /* Index of last TX DMA descriptor that was inserted */ |
1032 | int txq_put_index; | |
1033 | ||
1034 | /* Index of the TX DMA descriptor to be cleaned up */ | |
1035 | int txq_get_index; | |
186cd4d4 AT |
1036 | |
1037 | /* DMA buffer for TSO headers */ | |
1038 | char *tso_headers; | |
1039 | dma_addr_t tso_headers_dma; | |
3f518509 MW |
1040 | }; |
1041 | ||
1042 | struct mvpp2_tx_queue { | |
1043 | /* Physical number of this Tx queue */ | |
1044 | u8 id; | |
1045 | ||
1046 | /* Logical number of this Tx queue */ | |
1047 | u8 log_id; | |
1048 | ||
1049 | /* Number of Tx DMA descriptors in the descriptor ring */ | |
1050 | int size; | |
1051 | ||
1052 | /* Number of currently used Tx DMA descriptor in the descriptor ring */ | |
1053 | int count; | |
1054 | ||
1055 | /* Per-CPU control of physical Tx queues */ | |
1056 | struct mvpp2_txq_pcpu __percpu *pcpu; | |
1057 | ||
3f518509 MW |
1058 | u32 done_pkts_coal; |
1059 | ||
1060 | /* Virtual address of thex Tx DMA descriptors array */ | |
1061 | struct mvpp2_tx_desc *descs; | |
1062 | ||
1063 | /* DMA address of the Tx DMA descriptors array */ | |
20396136 | 1064 | dma_addr_t descs_dma; |
3f518509 MW |
1065 | |
1066 | /* Index of the last Tx DMA descriptor */ | |
1067 | int last_desc; | |
1068 | ||
1069 | /* Index of the next Tx DMA descriptor to process */ | |
1070 | int next_desc_to_proc; | |
1071 | }; | |
1072 | ||
1073 | struct mvpp2_rx_queue { | |
1074 | /* RX queue number, in the range 0-31 for physical RXQs */ | |
1075 | u8 id; | |
1076 | ||
1077 | /* Num of rx descriptors in the rx descriptor ring */ | |
1078 | int size; | |
1079 | ||
1080 | u32 pkts_coal; | |
1081 | u32 time_coal; | |
1082 | ||
1083 | /* Virtual address of the RX DMA descriptors array */ | |
1084 | struct mvpp2_rx_desc *descs; | |
1085 | ||
1086 | /* DMA address of the RX DMA descriptors array */ | |
20396136 | 1087 | dma_addr_t descs_dma; |
3f518509 MW |
1088 | |
1089 | /* Index of the last RX DMA descriptor */ | |
1090 | int last_desc; | |
1091 | ||
1092 | /* Index of the next RX DMA descriptor to process */ | |
1093 | int next_desc_to_proc; | |
1094 | ||
1095 | /* ID of port to which physical RXQ is mapped */ | |
1096 | int port; | |
1097 | ||
1098 | /* Port's logic RXQ number to which physical RXQ is mapped */ | |
1099 | int logic_rxq; | |
1100 | }; | |
1101 | ||
1102 | union mvpp2_prs_tcam_entry { | |
1103 | u32 word[MVPP2_PRS_TCAM_WORDS]; | |
1104 | u8 byte[MVPP2_PRS_TCAM_WORDS * 4]; | |
1105 | }; | |
1106 | ||
1107 | union mvpp2_prs_sram_entry { | |
1108 | u32 word[MVPP2_PRS_SRAM_WORDS]; | |
1109 | u8 byte[MVPP2_PRS_SRAM_WORDS * 4]; | |
1110 | }; | |
1111 | ||
1112 | struct mvpp2_prs_entry { | |
1113 | u32 index; | |
1114 | union mvpp2_prs_tcam_entry tcam; | |
1115 | union mvpp2_prs_sram_entry sram; | |
1116 | }; | |
1117 | ||
1118 | struct mvpp2_prs_shadow { | |
1119 | bool valid; | |
1120 | bool finish; | |
1121 | ||
1122 | /* Lookup ID */ | |
1123 | int lu; | |
1124 | ||
1125 | /* User defined offset */ | |
1126 | int udf; | |
1127 | ||
1128 | /* Result info */ | |
1129 | u32 ri; | |
1130 | u32 ri_mask; | |
1131 | }; | |
1132 | ||
1133 | struct mvpp2_cls_flow_entry { | |
1134 | u32 index; | |
1135 | u32 data[MVPP2_CLS_FLOWS_TBL_DATA_WORDS]; | |
1136 | }; | |
1137 | ||
1138 | struct mvpp2_cls_lookup_entry { | |
1139 | u32 lkpid; | |
1140 | u32 way; | |
1141 | u32 data; | |
1142 | }; | |
1143 | ||
1144 | struct mvpp2_bm_pool { | |
1145 | /* Pool number in the range 0-7 */ | |
1146 | int id; | |
1147 | enum mvpp2_bm_type type; | |
1148 | ||
1149 | /* Buffer Pointers Pool External (BPPE) size */ | |
1150 | int size; | |
d01524d8 TP |
1151 | /* BPPE size in bytes */ |
1152 | int size_bytes; | |
3f518509 MW |
1153 | /* Number of buffers for this pool */ |
1154 | int buf_num; | |
1155 | /* Pool buffer size */ | |
1156 | int buf_size; | |
1157 | /* Packet size */ | |
1158 | int pkt_size; | |
0e037281 | 1159 | int frag_size; |
3f518509 MW |
1160 | |
1161 | /* BPPE virtual base address */ | |
1162 | u32 *virt_addr; | |
20396136 TP |
1163 | /* BPPE DMA base address */ |
1164 | dma_addr_t dma_addr; | |
3f518509 MW |
1165 | |
1166 | /* Ports using BM pool */ | |
1167 | u32 port_map; | |
3f518509 MW |
1168 | }; |
1169 | ||
20920267 AT |
1170 | #define IS_TSO_HEADER(txq_pcpu, addr) \ |
1171 | ((addr) >= (txq_pcpu)->tso_headers_dma && \ | |
1172 | (addr) < (txq_pcpu)->tso_headers_dma + \ | |
1173 | (txq_pcpu)->size * TSO_HEADER_SIZE) | |
1174 | ||
213f428f TP |
1175 | /* Queue modes */ |
1176 | #define MVPP2_QDIST_SINGLE_MODE 0 | |
1177 | #define MVPP2_QDIST_MULTI_MODE 1 | |
1178 | ||
1179 | static int queue_mode = MVPP2_QDIST_SINGLE_MODE; | |
1180 | ||
1181 | module_param(queue_mode, int, 0444); | |
1182 | MODULE_PARM_DESC(queue_mode, "Set queue_mode (single=0, multi=1)"); | |
1183 | ||
3f518509 MW |
1184 | #define MVPP2_DRIVER_NAME "mvpp2" |
1185 | #define MVPP2_DRIVER_VERSION "1.0" | |
1186 | ||
1187 | /* Utility/helper methods */ | |
1188 | ||
1189 | static void mvpp2_write(struct mvpp2 *priv, u32 offset, u32 data) | |
1190 | { | |
df089aa0 | 1191 | writel(data, priv->swth_base[0] + offset); |
3f518509 MW |
1192 | } |
1193 | ||
1194 | static u32 mvpp2_read(struct mvpp2 *priv, u32 offset) | |
1195 | { | |
df089aa0 | 1196 | return readl(priv->swth_base[0] + offset); |
a786841d TP |
1197 | } |
1198 | ||
1199 | /* These accessors should be used to access: | |
1200 | * | |
1201 | * - per-CPU registers, where each CPU has its own copy of the | |
1202 | * register. | |
1203 | * | |
1204 | * MVPP2_BM_VIRT_ALLOC_REG | |
1205 | * MVPP2_BM_ADDR_HIGH_ALLOC | |
1206 | * MVPP22_BM_ADDR_HIGH_RLS_REG | |
1207 | * MVPP2_BM_VIRT_RLS_REG | |
1208 | * MVPP2_ISR_RX_TX_CAUSE_REG | |
1209 | * MVPP2_ISR_RX_TX_MASK_REG | |
1210 | * MVPP2_TXQ_NUM_REG | |
1211 | * MVPP2_AGGR_TXQ_UPDATE_REG | |
1212 | * MVPP2_TXQ_RSVD_REQ_REG | |
1213 | * MVPP2_TXQ_RSVD_RSLT_REG | |
1214 | * MVPP2_TXQ_SENT_REG | |
1215 | * MVPP2_RXQ_NUM_REG | |
1216 | * | |
1217 | * - global registers that must be accessed through a specific CPU | |
1218 | * window, because they are related to an access to a per-CPU | |
1219 | * register | |
1220 | * | |
1221 | * MVPP2_BM_PHY_ALLOC_REG (related to MVPP2_BM_VIRT_ALLOC_REG) | |
1222 | * MVPP2_BM_PHY_RLS_REG (related to MVPP2_BM_VIRT_RLS_REG) | |
1223 | * MVPP2_RXQ_THRESH_REG (related to MVPP2_RXQ_NUM_REG) | |
1224 | * MVPP2_RXQ_DESC_ADDR_REG (related to MVPP2_RXQ_NUM_REG) | |
1225 | * MVPP2_RXQ_DESC_SIZE_REG (related to MVPP2_RXQ_NUM_REG) | |
1226 | * MVPP2_RXQ_INDEX_REG (related to MVPP2_RXQ_NUM_REG) | |
1227 | * MVPP2_TXQ_PENDING_REG (related to MVPP2_TXQ_NUM_REG) | |
1228 | * MVPP2_TXQ_DESC_ADDR_REG (related to MVPP2_TXQ_NUM_REG) | |
1229 | * MVPP2_TXQ_DESC_SIZE_REG (related to MVPP2_TXQ_NUM_REG) | |
1230 | * MVPP2_TXQ_INDEX_REG (related to MVPP2_TXQ_NUM_REG) | |
1231 | * MVPP2_TXQ_PENDING_REG (related to MVPP2_TXQ_NUM_REG) | |
1232 | * MVPP2_TXQ_PREF_BUF_REG (related to MVPP2_TXQ_NUM_REG) | |
1233 | * MVPP2_TXQ_PREF_BUF_REG (related to MVPP2_TXQ_NUM_REG) | |
1234 | */ | |
1235 | static void mvpp2_percpu_write(struct mvpp2 *priv, int cpu, | |
1236 | u32 offset, u32 data) | |
1237 | { | |
df089aa0 | 1238 | writel(data, priv->swth_base[cpu] + offset); |
a786841d TP |
1239 | } |
1240 | ||
1241 | static u32 mvpp2_percpu_read(struct mvpp2 *priv, int cpu, | |
1242 | u32 offset) | |
1243 | { | |
df089aa0 | 1244 | return readl(priv->swth_base[cpu] + offset); |
3f518509 MW |
1245 | } |
1246 | ||
ac3dd277 TP |
1247 | static dma_addr_t mvpp2_txdesc_dma_addr_get(struct mvpp2_port *port, |
1248 | struct mvpp2_tx_desc *tx_desc) | |
1249 | { | |
e7c5359f TP |
1250 | if (port->priv->hw_version == MVPP21) |
1251 | return tx_desc->pp21.buf_dma_addr; | |
1252 | else | |
1253 | return tx_desc->pp22.buf_dma_addr_ptp & GENMASK_ULL(40, 0); | |
ac3dd277 TP |
1254 | } |
1255 | ||
1256 | static void mvpp2_txdesc_dma_addr_set(struct mvpp2_port *port, | |
1257 | struct mvpp2_tx_desc *tx_desc, | |
1258 | dma_addr_t dma_addr) | |
1259 | { | |
e7c5359f TP |
1260 | if (port->priv->hw_version == MVPP21) { |
1261 | tx_desc->pp21.buf_dma_addr = dma_addr; | |
1262 | } else { | |
1263 | u64 val = (u64)dma_addr; | |
1264 | ||
1265 | tx_desc->pp22.buf_dma_addr_ptp &= ~GENMASK_ULL(40, 0); | |
1266 | tx_desc->pp22.buf_dma_addr_ptp |= val; | |
1267 | } | |
ac3dd277 TP |
1268 | } |
1269 | ||
1270 | static size_t mvpp2_txdesc_size_get(struct mvpp2_port *port, | |
1271 | struct mvpp2_tx_desc *tx_desc) | |
1272 | { | |
e7c5359f TP |
1273 | if (port->priv->hw_version == MVPP21) |
1274 | return tx_desc->pp21.data_size; | |
1275 | else | |
1276 | return tx_desc->pp22.data_size; | |
ac3dd277 TP |
1277 | } |
1278 | ||
1279 | static void mvpp2_txdesc_size_set(struct mvpp2_port *port, | |
1280 | struct mvpp2_tx_desc *tx_desc, | |
1281 | size_t size) | |
1282 | { | |
e7c5359f TP |
1283 | if (port->priv->hw_version == MVPP21) |
1284 | tx_desc->pp21.data_size = size; | |
1285 | else | |
1286 | tx_desc->pp22.data_size = size; | |
ac3dd277 TP |
1287 | } |
1288 | ||
1289 | static void mvpp2_txdesc_txq_set(struct mvpp2_port *port, | |
1290 | struct mvpp2_tx_desc *tx_desc, | |
1291 | unsigned int txq) | |
1292 | { | |
e7c5359f TP |
1293 | if (port->priv->hw_version == MVPP21) |
1294 | tx_desc->pp21.phys_txq = txq; | |
1295 | else | |
1296 | tx_desc->pp22.phys_txq = txq; | |
ac3dd277 TP |
1297 | } |
1298 | ||
1299 | static void mvpp2_txdesc_cmd_set(struct mvpp2_port *port, | |
1300 | struct mvpp2_tx_desc *tx_desc, | |
1301 | unsigned int command) | |
1302 | { | |
e7c5359f TP |
1303 | if (port->priv->hw_version == MVPP21) |
1304 | tx_desc->pp21.command = command; | |
1305 | else | |
1306 | tx_desc->pp22.command = command; | |
ac3dd277 TP |
1307 | } |
1308 | ||
1309 | static void mvpp2_txdesc_offset_set(struct mvpp2_port *port, | |
1310 | struct mvpp2_tx_desc *tx_desc, | |
1311 | unsigned int offset) | |
1312 | { | |
e7c5359f TP |
1313 | if (port->priv->hw_version == MVPP21) |
1314 | tx_desc->pp21.packet_offset = offset; | |
1315 | else | |
1316 | tx_desc->pp22.packet_offset = offset; | |
ac3dd277 TP |
1317 | } |
1318 | ||
1319 | static unsigned int mvpp2_txdesc_offset_get(struct mvpp2_port *port, | |
1320 | struct mvpp2_tx_desc *tx_desc) | |
1321 | { | |
e7c5359f TP |
1322 | if (port->priv->hw_version == MVPP21) |
1323 | return tx_desc->pp21.packet_offset; | |
1324 | else | |
1325 | return tx_desc->pp22.packet_offset; | |
ac3dd277 TP |
1326 | } |
1327 | ||
1328 | static dma_addr_t mvpp2_rxdesc_dma_addr_get(struct mvpp2_port *port, | |
1329 | struct mvpp2_rx_desc *rx_desc) | |
1330 | { | |
e7c5359f TP |
1331 | if (port->priv->hw_version == MVPP21) |
1332 | return rx_desc->pp21.buf_dma_addr; | |
1333 | else | |
1334 | return rx_desc->pp22.buf_dma_addr_key_hash & GENMASK_ULL(40, 0); | |
ac3dd277 TP |
1335 | } |
1336 | ||
1337 | static unsigned long mvpp2_rxdesc_cookie_get(struct mvpp2_port *port, | |
1338 | struct mvpp2_rx_desc *rx_desc) | |
1339 | { | |
e7c5359f TP |
1340 | if (port->priv->hw_version == MVPP21) |
1341 | return rx_desc->pp21.buf_cookie; | |
1342 | else | |
1343 | return rx_desc->pp22.buf_cookie_misc & GENMASK_ULL(40, 0); | |
ac3dd277 TP |
1344 | } |
1345 | ||
1346 | static size_t mvpp2_rxdesc_size_get(struct mvpp2_port *port, | |
1347 | struct mvpp2_rx_desc *rx_desc) | |
1348 | { | |
e7c5359f TP |
1349 | if (port->priv->hw_version == MVPP21) |
1350 | return rx_desc->pp21.data_size; | |
1351 | else | |
1352 | return rx_desc->pp22.data_size; | |
ac3dd277 TP |
1353 | } |
1354 | ||
1355 | static u32 mvpp2_rxdesc_status_get(struct mvpp2_port *port, | |
1356 | struct mvpp2_rx_desc *rx_desc) | |
1357 | { | |
e7c5359f TP |
1358 | if (port->priv->hw_version == MVPP21) |
1359 | return rx_desc->pp21.status; | |
1360 | else | |
1361 | return rx_desc->pp22.status; | |
ac3dd277 TP |
1362 | } |
1363 | ||
3f518509 MW |
1364 | static void mvpp2_txq_inc_get(struct mvpp2_txq_pcpu *txq_pcpu) |
1365 | { | |
1366 | txq_pcpu->txq_get_index++; | |
1367 | if (txq_pcpu->txq_get_index == txq_pcpu->size) | |
1368 | txq_pcpu->txq_get_index = 0; | |
1369 | } | |
1370 | ||
ac3dd277 TP |
1371 | static void mvpp2_txq_inc_put(struct mvpp2_port *port, |
1372 | struct mvpp2_txq_pcpu *txq_pcpu, | |
71ce391d MW |
1373 | struct sk_buff *skb, |
1374 | struct mvpp2_tx_desc *tx_desc) | |
3f518509 | 1375 | { |
8354491c TP |
1376 | struct mvpp2_txq_pcpu_buf *tx_buf = |
1377 | txq_pcpu->buffs + txq_pcpu->txq_put_index; | |
1378 | tx_buf->skb = skb; | |
ac3dd277 TP |
1379 | tx_buf->size = mvpp2_txdesc_size_get(port, tx_desc); |
1380 | tx_buf->dma = mvpp2_txdesc_dma_addr_get(port, tx_desc) + | |
1381 | mvpp2_txdesc_offset_get(port, tx_desc); | |
3f518509 MW |
1382 | txq_pcpu->txq_put_index++; |
1383 | if (txq_pcpu->txq_put_index == txq_pcpu->size) | |
1384 | txq_pcpu->txq_put_index = 0; | |
1385 | } | |
1386 | ||
1387 | /* Get number of physical egress port */ | |
1388 | static inline int mvpp2_egress_port(struct mvpp2_port *port) | |
1389 | { | |
1390 | return MVPP2_MAX_TCONT + port->id; | |
1391 | } | |
1392 | ||
1393 | /* Get number of physical TXQ */ | |
1394 | static inline int mvpp2_txq_phys(int port, int txq) | |
1395 | { | |
1396 | return (MVPP2_MAX_TCONT + port) * MVPP2_MAX_TXQ + txq; | |
1397 | } | |
1398 | ||
1399 | /* Parser configuration routines */ | |
1400 | ||
1401 | /* Update parser tcam and sram hw entries */ | |
1402 | static int mvpp2_prs_hw_write(struct mvpp2 *priv, struct mvpp2_prs_entry *pe) | |
1403 | { | |
1404 | int i; | |
1405 | ||
1406 | if (pe->index > MVPP2_PRS_TCAM_SRAM_SIZE - 1) | |
1407 | return -EINVAL; | |
1408 | ||
1409 | /* Clear entry invalidation bit */ | |
1410 | pe->tcam.word[MVPP2_PRS_TCAM_INV_WORD] &= ~MVPP2_PRS_TCAM_INV_MASK; | |
1411 | ||
1412 | /* Write tcam index - indirect access */ | |
1413 | mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, pe->index); | |
1414 | for (i = 0; i < MVPP2_PRS_TCAM_WORDS; i++) | |
1415 | mvpp2_write(priv, MVPP2_PRS_TCAM_DATA_REG(i), pe->tcam.word[i]); | |
1416 | ||
1417 | /* Write sram index - indirect access */ | |
1418 | mvpp2_write(priv, MVPP2_PRS_SRAM_IDX_REG, pe->index); | |
1419 | for (i = 0; i < MVPP2_PRS_SRAM_WORDS; i++) | |
1420 | mvpp2_write(priv, MVPP2_PRS_SRAM_DATA_REG(i), pe->sram.word[i]); | |
1421 | ||
1422 | return 0; | |
1423 | } | |
1424 | ||
1425 | /* Read tcam entry from hw */ | |
1426 | static int mvpp2_prs_hw_read(struct mvpp2 *priv, struct mvpp2_prs_entry *pe) | |
1427 | { | |
1428 | int i; | |
1429 | ||
1430 | if (pe->index > MVPP2_PRS_TCAM_SRAM_SIZE - 1) | |
1431 | return -EINVAL; | |
1432 | ||
1433 | /* Write tcam index - indirect access */ | |
1434 | mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, pe->index); | |
1435 | ||
1436 | pe->tcam.word[MVPP2_PRS_TCAM_INV_WORD] = mvpp2_read(priv, | |
1437 | MVPP2_PRS_TCAM_DATA_REG(MVPP2_PRS_TCAM_INV_WORD)); | |
1438 | if (pe->tcam.word[MVPP2_PRS_TCAM_INV_WORD] & MVPP2_PRS_TCAM_INV_MASK) | |
1439 | return MVPP2_PRS_TCAM_ENTRY_INVALID; | |
1440 | ||
1441 | for (i = 0; i < MVPP2_PRS_TCAM_WORDS; i++) | |
1442 | pe->tcam.word[i] = mvpp2_read(priv, MVPP2_PRS_TCAM_DATA_REG(i)); | |
1443 | ||
1444 | /* Write sram index - indirect access */ | |
1445 | mvpp2_write(priv, MVPP2_PRS_SRAM_IDX_REG, pe->index); | |
1446 | for (i = 0; i < MVPP2_PRS_SRAM_WORDS; i++) | |
1447 | pe->sram.word[i] = mvpp2_read(priv, MVPP2_PRS_SRAM_DATA_REG(i)); | |
1448 | ||
1449 | return 0; | |
1450 | } | |
1451 | ||
1452 | /* Invalidate tcam hw entry */ | |
1453 | static void mvpp2_prs_hw_inv(struct mvpp2 *priv, int index) | |
1454 | { | |
1455 | /* Write index - indirect access */ | |
1456 | mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, index); | |
1457 | mvpp2_write(priv, MVPP2_PRS_TCAM_DATA_REG(MVPP2_PRS_TCAM_INV_WORD), | |
1458 | MVPP2_PRS_TCAM_INV_MASK); | |
1459 | } | |
1460 | ||
1461 | /* Enable shadow table entry and set its lookup ID */ | |
1462 | static void mvpp2_prs_shadow_set(struct mvpp2 *priv, int index, int lu) | |
1463 | { | |
1464 | priv->prs_shadow[index].valid = true; | |
1465 | priv->prs_shadow[index].lu = lu; | |
1466 | } | |
1467 | ||
1468 | /* Update ri fields in shadow table entry */ | |
1469 | static void mvpp2_prs_shadow_ri_set(struct mvpp2 *priv, int index, | |
1470 | unsigned int ri, unsigned int ri_mask) | |
1471 | { | |
1472 | priv->prs_shadow[index].ri_mask = ri_mask; | |
1473 | priv->prs_shadow[index].ri = ri; | |
1474 | } | |
1475 | ||
1476 | /* Update lookup field in tcam sw entry */ | |
1477 | static void mvpp2_prs_tcam_lu_set(struct mvpp2_prs_entry *pe, unsigned int lu) | |
1478 | { | |
1479 | int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_LU_BYTE); | |
1480 | ||
1481 | pe->tcam.byte[MVPP2_PRS_TCAM_LU_BYTE] = lu; | |
1482 | pe->tcam.byte[enable_off] = MVPP2_PRS_LU_MASK; | |
1483 | } | |
1484 | ||
1485 | /* Update mask for single port in tcam sw entry */ | |
1486 | static void mvpp2_prs_tcam_port_set(struct mvpp2_prs_entry *pe, | |
1487 | unsigned int port, bool add) | |
1488 | { | |
1489 | int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_PORT_BYTE); | |
1490 | ||
1491 | if (add) | |
1492 | pe->tcam.byte[enable_off] &= ~(1 << port); | |
1493 | else | |
1494 | pe->tcam.byte[enable_off] |= 1 << port; | |
1495 | } | |
1496 | ||
1497 | /* Update port map in tcam sw entry */ | |
1498 | static void mvpp2_prs_tcam_port_map_set(struct mvpp2_prs_entry *pe, | |
1499 | unsigned int ports) | |
1500 | { | |
1501 | unsigned char port_mask = MVPP2_PRS_PORT_MASK; | |
1502 | int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_PORT_BYTE); | |
1503 | ||
1504 | pe->tcam.byte[MVPP2_PRS_TCAM_PORT_BYTE] = 0; | |
1505 | pe->tcam.byte[enable_off] &= ~port_mask; | |
1506 | pe->tcam.byte[enable_off] |= ~ports & MVPP2_PRS_PORT_MASK; | |
1507 | } | |
1508 | ||
1509 | /* Obtain port map from tcam sw entry */ | |
1510 | static unsigned int mvpp2_prs_tcam_port_map_get(struct mvpp2_prs_entry *pe) | |
1511 | { | |
1512 | int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_PORT_BYTE); | |
1513 | ||
1514 | return ~(pe->tcam.byte[enable_off]) & MVPP2_PRS_PORT_MASK; | |
1515 | } | |
1516 | ||
1517 | /* Set byte of data and its enable bits in tcam sw entry */ | |
1518 | static void mvpp2_prs_tcam_data_byte_set(struct mvpp2_prs_entry *pe, | |
1519 | unsigned int offs, unsigned char byte, | |
1520 | unsigned char enable) | |
1521 | { | |
1522 | pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE(offs)] = byte; | |
1523 | pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE_EN(offs)] = enable; | |
1524 | } | |
1525 | ||
1526 | /* Get byte of data and its enable bits from tcam sw entry */ | |
1527 | static void mvpp2_prs_tcam_data_byte_get(struct mvpp2_prs_entry *pe, | |
1528 | unsigned int offs, unsigned char *byte, | |
1529 | unsigned char *enable) | |
1530 | { | |
1531 | *byte = pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE(offs)]; | |
1532 | *enable = pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE_EN(offs)]; | |
1533 | } | |
1534 | ||
1535 | /* Compare tcam data bytes with a pattern */ | |
1536 | static bool mvpp2_prs_tcam_data_cmp(struct mvpp2_prs_entry *pe, int offs, | |
1537 | u16 data) | |
1538 | { | |
1539 | int off = MVPP2_PRS_TCAM_DATA_BYTE(offs); | |
1540 | u16 tcam_data; | |
1541 | ||
ef4816f0 | 1542 | tcam_data = (pe->tcam.byte[off + 1] << 8) | pe->tcam.byte[off]; |
3f518509 MW |
1543 | if (tcam_data != data) |
1544 | return false; | |
1545 | return true; | |
1546 | } | |
1547 | ||
1548 | /* Update ai bits in tcam sw entry */ | |
1549 | static void mvpp2_prs_tcam_ai_update(struct mvpp2_prs_entry *pe, | |
1550 | unsigned int bits, unsigned int enable) | |
1551 | { | |
1552 | int i, ai_idx = MVPP2_PRS_TCAM_AI_BYTE; | |
1553 | ||
1554 | for (i = 0; i < MVPP2_PRS_AI_BITS; i++) { | |
1555 | ||
1556 | if (!(enable & BIT(i))) | |
1557 | continue; | |
1558 | ||
1559 | if (bits & BIT(i)) | |
1560 | pe->tcam.byte[ai_idx] |= 1 << i; | |
1561 | else | |
1562 | pe->tcam.byte[ai_idx] &= ~(1 << i); | |
1563 | } | |
1564 | ||
1565 | pe->tcam.byte[MVPP2_PRS_TCAM_EN_OFFS(ai_idx)] |= enable; | |
1566 | } | |
1567 | ||
1568 | /* Get ai bits from tcam sw entry */ | |
1569 | static int mvpp2_prs_tcam_ai_get(struct mvpp2_prs_entry *pe) | |
1570 | { | |
1571 | return pe->tcam.byte[MVPP2_PRS_TCAM_AI_BYTE]; | |
1572 | } | |
1573 | ||
1574 | /* Set ethertype in tcam sw entry */ | |
1575 | static void mvpp2_prs_match_etype(struct mvpp2_prs_entry *pe, int offset, | |
1576 | unsigned short ethertype) | |
1577 | { | |
1578 | mvpp2_prs_tcam_data_byte_set(pe, offset + 0, ethertype >> 8, 0xff); | |
1579 | mvpp2_prs_tcam_data_byte_set(pe, offset + 1, ethertype & 0xff, 0xff); | |
1580 | } | |
1581 | ||
1582 | /* Set bits in sram sw entry */ | |
1583 | static void mvpp2_prs_sram_bits_set(struct mvpp2_prs_entry *pe, int bit_num, | |
1584 | int val) | |
1585 | { | |
1586 | pe->sram.byte[MVPP2_BIT_TO_BYTE(bit_num)] |= (val << (bit_num % 8)); | |
1587 | } | |
1588 | ||
1589 | /* Clear bits in sram sw entry */ | |
1590 | static void mvpp2_prs_sram_bits_clear(struct mvpp2_prs_entry *pe, int bit_num, | |
1591 | int val) | |
1592 | { | |
1593 | pe->sram.byte[MVPP2_BIT_TO_BYTE(bit_num)] &= ~(val << (bit_num % 8)); | |
1594 | } | |
1595 | ||
1596 | /* Update ri bits in sram sw entry */ | |
1597 | static void mvpp2_prs_sram_ri_update(struct mvpp2_prs_entry *pe, | |
1598 | unsigned int bits, unsigned int mask) | |
1599 | { | |
1600 | unsigned int i; | |
1601 | ||
1602 | for (i = 0; i < MVPP2_PRS_SRAM_RI_CTRL_BITS; i++) { | |
1603 | int ri_off = MVPP2_PRS_SRAM_RI_OFFS; | |
1604 | ||
1605 | if (!(mask & BIT(i))) | |
1606 | continue; | |
1607 | ||
1608 | if (bits & BIT(i)) | |
1609 | mvpp2_prs_sram_bits_set(pe, ri_off + i, 1); | |
1610 | else | |
1611 | mvpp2_prs_sram_bits_clear(pe, ri_off + i, 1); | |
1612 | ||
1613 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_RI_CTRL_OFFS + i, 1); | |
1614 | } | |
1615 | } | |
1616 | ||
1617 | /* Obtain ri bits from sram sw entry */ | |
1618 | static int mvpp2_prs_sram_ri_get(struct mvpp2_prs_entry *pe) | |
1619 | { | |
1620 | return pe->sram.word[MVPP2_PRS_SRAM_RI_WORD]; | |
1621 | } | |
1622 | ||
1623 | /* Update ai bits in sram sw entry */ | |
1624 | static void mvpp2_prs_sram_ai_update(struct mvpp2_prs_entry *pe, | |
1625 | unsigned int bits, unsigned int mask) | |
1626 | { | |
1627 | unsigned int i; | |
1628 | int ai_off = MVPP2_PRS_SRAM_AI_OFFS; | |
1629 | ||
1630 | for (i = 0; i < MVPP2_PRS_SRAM_AI_CTRL_BITS; i++) { | |
1631 | ||
1632 | if (!(mask & BIT(i))) | |
1633 | continue; | |
1634 | ||
1635 | if (bits & BIT(i)) | |
1636 | mvpp2_prs_sram_bits_set(pe, ai_off + i, 1); | |
1637 | else | |
1638 | mvpp2_prs_sram_bits_clear(pe, ai_off + i, 1); | |
1639 | ||
1640 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_AI_CTRL_OFFS + i, 1); | |
1641 | } | |
1642 | } | |
1643 | ||
1644 | /* Read ai bits from sram sw entry */ | |
1645 | static int mvpp2_prs_sram_ai_get(struct mvpp2_prs_entry *pe) | |
1646 | { | |
1647 | u8 bits; | |
1648 | int ai_off = MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_AI_OFFS); | |
1649 | int ai_en_off = ai_off + 1; | |
1650 | int ai_shift = MVPP2_PRS_SRAM_AI_OFFS % 8; | |
1651 | ||
1652 | bits = (pe->sram.byte[ai_off] >> ai_shift) | | |
1653 | (pe->sram.byte[ai_en_off] << (8 - ai_shift)); | |
1654 | ||
1655 | return bits; | |
1656 | } | |
1657 | ||
1658 | /* In sram sw entry set lookup ID field of the tcam key to be used in the next | |
1659 | * lookup interation | |
1660 | */ | |
1661 | static void mvpp2_prs_sram_next_lu_set(struct mvpp2_prs_entry *pe, | |
1662 | unsigned int lu) | |
1663 | { | |
1664 | int sram_next_off = MVPP2_PRS_SRAM_NEXT_LU_OFFS; | |
1665 | ||
1666 | mvpp2_prs_sram_bits_clear(pe, sram_next_off, | |
1667 | MVPP2_PRS_SRAM_NEXT_LU_MASK); | |
1668 | mvpp2_prs_sram_bits_set(pe, sram_next_off, lu); | |
1669 | } | |
1670 | ||
1671 | /* In the sram sw entry set sign and value of the next lookup offset | |
1672 | * and the offset value generated to the classifier | |
1673 | */ | |
1674 | static void mvpp2_prs_sram_shift_set(struct mvpp2_prs_entry *pe, int shift, | |
1675 | unsigned int op) | |
1676 | { | |
1677 | /* Set sign */ | |
1678 | if (shift < 0) { | |
1679 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_SHIFT_SIGN_BIT, 1); | |
1680 | shift = 0 - shift; | |
1681 | } else { | |
1682 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_SHIFT_SIGN_BIT, 1); | |
1683 | } | |
1684 | ||
1685 | /* Set value */ | |
1686 | pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_SHIFT_OFFS)] = | |
1687 | (unsigned char)shift; | |
1688 | ||
1689 | /* Reset and set operation */ | |
1690 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_SHIFT_OFFS, | |
1691 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_MASK); | |
1692 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_OP_SEL_SHIFT_OFFS, op); | |
1693 | ||
1694 | /* Set base offset as current */ | |
1695 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_BASE_OFFS, 1); | |
1696 | } | |
1697 | ||
1698 | /* In the sram sw entry set sign and value of the user defined offset | |
1699 | * generated to the classifier | |
1700 | */ | |
1701 | static void mvpp2_prs_sram_offset_set(struct mvpp2_prs_entry *pe, | |
1702 | unsigned int type, int offset, | |
1703 | unsigned int op) | |
1704 | { | |
1705 | /* Set sign */ | |
1706 | if (offset < 0) { | |
1707 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_UDF_SIGN_BIT, 1); | |
1708 | offset = 0 - offset; | |
1709 | } else { | |
1710 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_UDF_SIGN_BIT, 1); | |
1711 | } | |
1712 | ||
1713 | /* Set value */ | |
1714 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_UDF_OFFS, | |
1715 | MVPP2_PRS_SRAM_UDF_MASK); | |
1716 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_UDF_OFFS, offset); | |
1717 | pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_UDF_OFFS + | |
1718 | MVPP2_PRS_SRAM_UDF_BITS)] &= | |
1719 | ~(MVPP2_PRS_SRAM_UDF_MASK >> (8 - (MVPP2_PRS_SRAM_UDF_OFFS % 8))); | |
1720 | pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_UDF_OFFS + | |
1721 | MVPP2_PRS_SRAM_UDF_BITS)] |= | |
1722 | (offset >> (8 - (MVPP2_PRS_SRAM_UDF_OFFS % 8))); | |
1723 | ||
1724 | /* Set offset type */ | |
1725 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_UDF_TYPE_OFFS, | |
1726 | MVPP2_PRS_SRAM_UDF_TYPE_MASK); | |
1727 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_UDF_TYPE_OFFS, type); | |
1728 | ||
1729 | /* Set offset operation */ | |
1730 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS, | |
1731 | MVPP2_PRS_SRAM_OP_SEL_UDF_MASK); | |
1732 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS, op); | |
1733 | ||
1734 | pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS + | |
1735 | MVPP2_PRS_SRAM_OP_SEL_UDF_BITS)] &= | |
1736 | ~(MVPP2_PRS_SRAM_OP_SEL_UDF_MASK >> | |
1737 | (8 - (MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS % 8))); | |
1738 | ||
1739 | pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS + | |
1740 | MVPP2_PRS_SRAM_OP_SEL_UDF_BITS)] |= | |
1741 | (op >> (8 - (MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS % 8))); | |
1742 | ||
1743 | /* Set base offset as current */ | |
1744 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_BASE_OFFS, 1); | |
1745 | } | |
1746 | ||
1747 | /* Find parser flow entry */ | |
1748 | static struct mvpp2_prs_entry *mvpp2_prs_flow_find(struct mvpp2 *priv, int flow) | |
1749 | { | |
1750 | struct mvpp2_prs_entry *pe; | |
1751 | int tid; | |
1752 | ||
1753 | pe = kzalloc(sizeof(*pe), GFP_KERNEL); | |
1754 | if (!pe) | |
1755 | return NULL; | |
1756 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_FLOWS); | |
1757 | ||
1758 | /* Go through the all entires with MVPP2_PRS_LU_FLOWS */ | |
1759 | for (tid = MVPP2_PRS_TCAM_SRAM_SIZE - 1; tid >= 0; tid--) { | |
1760 | u8 bits; | |
1761 | ||
1762 | if (!priv->prs_shadow[tid].valid || | |
1763 | priv->prs_shadow[tid].lu != MVPP2_PRS_LU_FLOWS) | |
1764 | continue; | |
1765 | ||
1766 | pe->index = tid; | |
1767 | mvpp2_prs_hw_read(priv, pe); | |
1768 | bits = mvpp2_prs_sram_ai_get(pe); | |
1769 | ||
1770 | /* Sram store classification lookup ID in AI bits [5:0] */ | |
1771 | if ((bits & MVPP2_PRS_FLOW_ID_MASK) == flow) | |
1772 | return pe; | |
1773 | } | |
1774 | kfree(pe); | |
1775 | ||
1776 | return NULL; | |
1777 | } | |
1778 | ||
1779 | /* Return first free tcam index, seeking from start to end */ | |
1780 | static int mvpp2_prs_tcam_first_free(struct mvpp2 *priv, unsigned char start, | |
1781 | unsigned char end) | |
1782 | { | |
1783 | int tid; | |
1784 | ||
1785 | if (start > end) | |
1786 | swap(start, end); | |
1787 | ||
1788 | if (end >= MVPP2_PRS_TCAM_SRAM_SIZE) | |
1789 | end = MVPP2_PRS_TCAM_SRAM_SIZE - 1; | |
1790 | ||
1791 | for (tid = start; tid <= end; tid++) { | |
1792 | if (!priv->prs_shadow[tid].valid) | |
1793 | return tid; | |
1794 | } | |
1795 | ||
1796 | return -EINVAL; | |
1797 | } | |
1798 | ||
1799 | /* Enable/disable dropping all mac da's */ | |
1800 | static void mvpp2_prs_mac_drop_all_set(struct mvpp2 *priv, int port, bool add) | |
1801 | { | |
1802 | struct mvpp2_prs_entry pe; | |
1803 | ||
1804 | if (priv->prs_shadow[MVPP2_PE_DROP_ALL].valid) { | |
1805 | /* Entry exist - update port only */ | |
1806 | pe.index = MVPP2_PE_DROP_ALL; | |
1807 | mvpp2_prs_hw_read(priv, &pe); | |
1808 | } else { | |
1809 | /* Entry doesn't exist - create new */ | |
c5b2ce24 | 1810 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
1811 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC); |
1812 | pe.index = MVPP2_PE_DROP_ALL; | |
1813 | ||
1814 | /* Non-promiscuous mode for all ports - DROP unknown packets */ | |
1815 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_DROP_MASK, | |
1816 | MVPP2_PRS_RI_DROP_MASK); | |
1817 | ||
1818 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); | |
1819 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); | |
1820 | ||
1821 | /* Update shadow table */ | |
1822 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC); | |
1823 | ||
1824 | /* Mask all ports */ | |
1825 | mvpp2_prs_tcam_port_map_set(&pe, 0); | |
1826 | } | |
1827 | ||
1828 | /* Update port mask */ | |
1829 | mvpp2_prs_tcam_port_set(&pe, port, add); | |
1830 | ||
1831 | mvpp2_prs_hw_write(priv, &pe); | |
1832 | } | |
1833 | ||
1834 | /* Set port to promiscuous mode */ | |
1835 | static void mvpp2_prs_mac_promisc_set(struct mvpp2 *priv, int port, bool add) | |
1836 | { | |
1837 | struct mvpp2_prs_entry pe; | |
1838 | ||
dbedd44e | 1839 | /* Promiscuous mode - Accept unknown packets */ |
3f518509 MW |
1840 | |
1841 | if (priv->prs_shadow[MVPP2_PE_MAC_PROMISCUOUS].valid) { | |
1842 | /* Entry exist - update port only */ | |
1843 | pe.index = MVPP2_PE_MAC_PROMISCUOUS; | |
1844 | mvpp2_prs_hw_read(priv, &pe); | |
1845 | } else { | |
1846 | /* Entry doesn't exist - create new */ | |
c5b2ce24 | 1847 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
1848 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC); |
1849 | pe.index = MVPP2_PE_MAC_PROMISCUOUS; | |
1850 | ||
1851 | /* Continue - set next lookup */ | |
1852 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_DSA); | |
1853 | ||
1854 | /* Set result info bits */ | |
1855 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L2_UCAST, | |
1856 | MVPP2_PRS_RI_L2_CAST_MASK); | |
1857 | ||
1858 | /* Shift to ethertype */ | |
1859 | mvpp2_prs_sram_shift_set(&pe, 2 * ETH_ALEN, | |
1860 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
1861 | ||
1862 | /* Mask all ports */ | |
1863 | mvpp2_prs_tcam_port_map_set(&pe, 0); | |
1864 | ||
1865 | /* Update shadow table */ | |
1866 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC); | |
1867 | } | |
1868 | ||
1869 | /* Update port mask */ | |
1870 | mvpp2_prs_tcam_port_set(&pe, port, add); | |
1871 | ||
1872 | mvpp2_prs_hw_write(priv, &pe); | |
1873 | } | |
1874 | ||
1875 | /* Accept multicast */ | |
1876 | static void mvpp2_prs_mac_multi_set(struct mvpp2 *priv, int port, int index, | |
1877 | bool add) | |
1878 | { | |
1879 | struct mvpp2_prs_entry pe; | |
1880 | unsigned char da_mc; | |
1881 | ||
1882 | /* Ethernet multicast address first byte is | |
1883 | * 0x01 for IPv4 and 0x33 for IPv6 | |
1884 | */ | |
1885 | da_mc = (index == MVPP2_PE_MAC_MC_ALL) ? 0x01 : 0x33; | |
1886 | ||
1887 | if (priv->prs_shadow[index].valid) { | |
1888 | /* Entry exist - update port only */ | |
1889 | pe.index = index; | |
1890 | mvpp2_prs_hw_read(priv, &pe); | |
1891 | } else { | |
1892 | /* Entry doesn't exist - create new */ | |
c5b2ce24 | 1893 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
1894 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC); |
1895 | pe.index = index; | |
1896 | ||
1897 | /* Continue - set next lookup */ | |
1898 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_DSA); | |
1899 | ||
1900 | /* Set result info bits */ | |
1901 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L2_MCAST, | |
1902 | MVPP2_PRS_RI_L2_CAST_MASK); | |
1903 | ||
1904 | /* Update tcam entry data first byte */ | |
1905 | mvpp2_prs_tcam_data_byte_set(&pe, 0, da_mc, 0xff); | |
1906 | ||
1907 | /* Shift to ethertype */ | |
1908 | mvpp2_prs_sram_shift_set(&pe, 2 * ETH_ALEN, | |
1909 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
1910 | ||
1911 | /* Mask all ports */ | |
1912 | mvpp2_prs_tcam_port_map_set(&pe, 0); | |
1913 | ||
1914 | /* Update shadow table */ | |
1915 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC); | |
1916 | } | |
1917 | ||
1918 | /* Update port mask */ | |
1919 | mvpp2_prs_tcam_port_set(&pe, port, add); | |
1920 | ||
1921 | mvpp2_prs_hw_write(priv, &pe); | |
1922 | } | |
1923 | ||
1924 | /* Set entry for dsa packets */ | |
1925 | static void mvpp2_prs_dsa_tag_set(struct mvpp2 *priv, int port, bool add, | |
1926 | bool tagged, bool extend) | |
1927 | { | |
1928 | struct mvpp2_prs_entry pe; | |
1929 | int tid, shift; | |
1930 | ||
1931 | if (extend) { | |
1932 | tid = tagged ? MVPP2_PE_EDSA_TAGGED : MVPP2_PE_EDSA_UNTAGGED; | |
1933 | shift = 8; | |
1934 | } else { | |
1935 | tid = tagged ? MVPP2_PE_DSA_TAGGED : MVPP2_PE_DSA_UNTAGGED; | |
1936 | shift = 4; | |
1937 | } | |
1938 | ||
1939 | if (priv->prs_shadow[tid].valid) { | |
1940 | /* Entry exist - update port only */ | |
1941 | pe.index = tid; | |
1942 | mvpp2_prs_hw_read(priv, &pe); | |
1943 | } else { | |
1944 | /* Entry doesn't exist - create new */ | |
c5b2ce24 | 1945 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
1946 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_DSA); |
1947 | pe.index = tid; | |
1948 | ||
1949 | /* Shift 4 bytes if DSA tag or 8 bytes in case of EDSA tag*/ | |
1950 | mvpp2_prs_sram_shift_set(&pe, shift, | |
1951 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
1952 | ||
1953 | /* Update shadow table */ | |
1954 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_DSA); | |
1955 | ||
1956 | if (tagged) { | |
1957 | /* Set tagged bit in DSA tag */ | |
1958 | mvpp2_prs_tcam_data_byte_set(&pe, 0, | |
1959 | MVPP2_PRS_TCAM_DSA_TAGGED_BIT, | |
1960 | MVPP2_PRS_TCAM_DSA_TAGGED_BIT); | |
1961 | /* Clear all ai bits for next iteration */ | |
1962 | mvpp2_prs_sram_ai_update(&pe, 0, | |
1963 | MVPP2_PRS_SRAM_AI_MASK); | |
1964 | /* If packet is tagged continue check vlans */ | |
1965 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_VLAN); | |
1966 | } else { | |
1967 | /* Set result info bits to 'no vlans' */ | |
1968 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_NONE, | |
1969 | MVPP2_PRS_RI_VLAN_MASK); | |
1970 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2); | |
1971 | } | |
1972 | ||
1973 | /* Mask all ports */ | |
1974 | mvpp2_prs_tcam_port_map_set(&pe, 0); | |
1975 | } | |
1976 | ||
1977 | /* Update port mask */ | |
1978 | mvpp2_prs_tcam_port_set(&pe, port, add); | |
1979 | ||
1980 | mvpp2_prs_hw_write(priv, &pe); | |
1981 | } | |
1982 | ||
1983 | /* Set entry for dsa ethertype */ | |
1984 | static void mvpp2_prs_dsa_tag_ethertype_set(struct mvpp2 *priv, int port, | |
1985 | bool add, bool tagged, bool extend) | |
1986 | { | |
1987 | struct mvpp2_prs_entry pe; | |
1988 | int tid, shift, port_mask; | |
1989 | ||
1990 | if (extend) { | |
1991 | tid = tagged ? MVPP2_PE_ETYPE_EDSA_TAGGED : | |
1992 | MVPP2_PE_ETYPE_EDSA_UNTAGGED; | |
1993 | port_mask = 0; | |
1994 | shift = 8; | |
1995 | } else { | |
1996 | tid = tagged ? MVPP2_PE_ETYPE_DSA_TAGGED : | |
1997 | MVPP2_PE_ETYPE_DSA_UNTAGGED; | |
1998 | port_mask = MVPP2_PRS_PORT_MASK; | |
1999 | shift = 4; | |
2000 | } | |
2001 | ||
2002 | if (priv->prs_shadow[tid].valid) { | |
2003 | /* Entry exist - update port only */ | |
2004 | pe.index = tid; | |
2005 | mvpp2_prs_hw_read(priv, &pe); | |
2006 | } else { | |
2007 | /* Entry doesn't exist - create new */ | |
c5b2ce24 | 2008 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2009 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_DSA); |
2010 | pe.index = tid; | |
2011 | ||
2012 | /* Set ethertype */ | |
2013 | mvpp2_prs_match_etype(&pe, 0, ETH_P_EDSA); | |
2014 | mvpp2_prs_match_etype(&pe, 2, 0); | |
2015 | ||
2016 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_DSA_MASK, | |
2017 | MVPP2_PRS_RI_DSA_MASK); | |
2018 | /* Shift ethertype + 2 byte reserved + tag*/ | |
2019 | mvpp2_prs_sram_shift_set(&pe, 2 + MVPP2_ETH_TYPE_LEN + shift, | |
2020 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
2021 | ||
2022 | /* Update shadow table */ | |
2023 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_DSA); | |
2024 | ||
2025 | if (tagged) { | |
2026 | /* Set tagged bit in DSA tag */ | |
2027 | mvpp2_prs_tcam_data_byte_set(&pe, | |
2028 | MVPP2_ETH_TYPE_LEN + 2 + 3, | |
2029 | MVPP2_PRS_TCAM_DSA_TAGGED_BIT, | |
2030 | MVPP2_PRS_TCAM_DSA_TAGGED_BIT); | |
2031 | /* Clear all ai bits for next iteration */ | |
2032 | mvpp2_prs_sram_ai_update(&pe, 0, | |
2033 | MVPP2_PRS_SRAM_AI_MASK); | |
2034 | /* If packet is tagged continue check vlans */ | |
2035 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_VLAN); | |
2036 | } else { | |
2037 | /* Set result info bits to 'no vlans' */ | |
2038 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_NONE, | |
2039 | MVPP2_PRS_RI_VLAN_MASK); | |
2040 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2); | |
2041 | } | |
2042 | /* Mask/unmask all ports, depending on dsa type */ | |
2043 | mvpp2_prs_tcam_port_map_set(&pe, port_mask); | |
2044 | } | |
2045 | ||
2046 | /* Update port mask */ | |
2047 | mvpp2_prs_tcam_port_set(&pe, port, add); | |
2048 | ||
2049 | mvpp2_prs_hw_write(priv, &pe); | |
2050 | } | |
2051 | ||
2052 | /* Search for existing single/triple vlan entry */ | |
2053 | static struct mvpp2_prs_entry *mvpp2_prs_vlan_find(struct mvpp2 *priv, | |
2054 | unsigned short tpid, int ai) | |
2055 | { | |
2056 | struct mvpp2_prs_entry *pe; | |
2057 | int tid; | |
2058 | ||
2059 | pe = kzalloc(sizeof(*pe), GFP_KERNEL); | |
2060 | if (!pe) | |
2061 | return NULL; | |
2062 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN); | |
2063 | ||
2064 | /* Go through the all entries with MVPP2_PRS_LU_VLAN */ | |
2065 | for (tid = MVPP2_PE_FIRST_FREE_TID; | |
2066 | tid <= MVPP2_PE_LAST_FREE_TID; tid++) { | |
2067 | unsigned int ri_bits, ai_bits; | |
2068 | bool match; | |
2069 | ||
2070 | if (!priv->prs_shadow[tid].valid || | |
2071 | priv->prs_shadow[tid].lu != MVPP2_PRS_LU_VLAN) | |
2072 | continue; | |
2073 | ||
2074 | pe->index = tid; | |
2075 | ||
2076 | mvpp2_prs_hw_read(priv, pe); | |
2077 | match = mvpp2_prs_tcam_data_cmp(pe, 0, swab16(tpid)); | |
2078 | if (!match) | |
2079 | continue; | |
2080 | ||
2081 | /* Get vlan type */ | |
2082 | ri_bits = mvpp2_prs_sram_ri_get(pe); | |
2083 | ri_bits &= MVPP2_PRS_RI_VLAN_MASK; | |
2084 | ||
2085 | /* Get current ai value from tcam */ | |
2086 | ai_bits = mvpp2_prs_tcam_ai_get(pe); | |
2087 | /* Clear double vlan bit */ | |
2088 | ai_bits &= ~MVPP2_PRS_DBL_VLAN_AI_BIT; | |
2089 | ||
2090 | if (ai != ai_bits) | |
2091 | continue; | |
2092 | ||
2093 | if (ri_bits == MVPP2_PRS_RI_VLAN_SINGLE || | |
2094 | ri_bits == MVPP2_PRS_RI_VLAN_TRIPLE) | |
2095 | return pe; | |
2096 | } | |
2097 | kfree(pe); | |
2098 | ||
2099 | return NULL; | |
2100 | } | |
2101 | ||
2102 | /* Add/update single/triple vlan entry */ | |
2103 | static int mvpp2_prs_vlan_add(struct mvpp2 *priv, unsigned short tpid, int ai, | |
2104 | unsigned int port_map) | |
2105 | { | |
2106 | struct mvpp2_prs_entry *pe; | |
2107 | int tid_aux, tid; | |
43737473 | 2108 | int ret = 0; |
3f518509 MW |
2109 | |
2110 | pe = mvpp2_prs_vlan_find(priv, tpid, ai); | |
2111 | ||
2112 | if (!pe) { | |
2113 | /* Create new tcam entry */ | |
2114 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_LAST_FREE_TID, | |
2115 | MVPP2_PE_FIRST_FREE_TID); | |
2116 | if (tid < 0) | |
2117 | return tid; | |
2118 | ||
2119 | pe = kzalloc(sizeof(*pe), GFP_KERNEL); | |
2120 | if (!pe) | |
2121 | return -ENOMEM; | |
2122 | ||
2123 | /* Get last double vlan tid */ | |
2124 | for (tid_aux = MVPP2_PE_LAST_FREE_TID; | |
2125 | tid_aux >= MVPP2_PE_FIRST_FREE_TID; tid_aux--) { | |
2126 | unsigned int ri_bits; | |
2127 | ||
2128 | if (!priv->prs_shadow[tid_aux].valid || | |
2129 | priv->prs_shadow[tid_aux].lu != MVPP2_PRS_LU_VLAN) | |
2130 | continue; | |
2131 | ||
2132 | pe->index = tid_aux; | |
2133 | mvpp2_prs_hw_read(priv, pe); | |
2134 | ri_bits = mvpp2_prs_sram_ri_get(pe); | |
2135 | if ((ri_bits & MVPP2_PRS_RI_VLAN_MASK) == | |
2136 | MVPP2_PRS_RI_VLAN_DOUBLE) | |
2137 | break; | |
2138 | } | |
2139 | ||
43737473 SM |
2140 | if (tid <= tid_aux) { |
2141 | ret = -EINVAL; | |
f9fd0e34 | 2142 | goto free_pe; |
43737473 | 2143 | } |
3f518509 | 2144 | |
bd6aaf55 | 2145 | memset(pe, 0, sizeof(*pe)); |
3f518509 MW |
2146 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN); |
2147 | pe->index = tid; | |
2148 | ||
2149 | mvpp2_prs_match_etype(pe, 0, tpid); | |
2150 | ||
2151 | mvpp2_prs_sram_next_lu_set(pe, MVPP2_PRS_LU_L2); | |
2152 | /* Shift 4 bytes - skip 1 vlan tag */ | |
2153 | mvpp2_prs_sram_shift_set(pe, MVPP2_VLAN_TAG_LEN, | |
2154 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
2155 | /* Clear all ai bits for next iteration */ | |
2156 | mvpp2_prs_sram_ai_update(pe, 0, MVPP2_PRS_SRAM_AI_MASK); | |
2157 | ||
2158 | if (ai == MVPP2_PRS_SINGLE_VLAN_AI) { | |
2159 | mvpp2_prs_sram_ri_update(pe, MVPP2_PRS_RI_VLAN_SINGLE, | |
2160 | MVPP2_PRS_RI_VLAN_MASK); | |
2161 | } else { | |
2162 | ai |= MVPP2_PRS_DBL_VLAN_AI_BIT; | |
2163 | mvpp2_prs_sram_ri_update(pe, MVPP2_PRS_RI_VLAN_TRIPLE, | |
2164 | MVPP2_PRS_RI_VLAN_MASK); | |
2165 | } | |
2166 | mvpp2_prs_tcam_ai_update(pe, ai, MVPP2_PRS_SRAM_AI_MASK); | |
2167 | ||
2168 | mvpp2_prs_shadow_set(priv, pe->index, MVPP2_PRS_LU_VLAN); | |
2169 | } | |
2170 | /* Update ports' mask */ | |
2171 | mvpp2_prs_tcam_port_map_set(pe, port_map); | |
2172 | ||
2173 | mvpp2_prs_hw_write(priv, pe); | |
f9fd0e34 | 2174 | free_pe: |
3f518509 MW |
2175 | kfree(pe); |
2176 | ||
43737473 | 2177 | return ret; |
3f518509 MW |
2178 | } |
2179 | ||
2180 | /* Get first free double vlan ai number */ | |
2181 | static int mvpp2_prs_double_vlan_ai_free_get(struct mvpp2 *priv) | |
2182 | { | |
2183 | int i; | |
2184 | ||
2185 | for (i = 1; i < MVPP2_PRS_DBL_VLANS_MAX; i++) { | |
2186 | if (!priv->prs_double_vlans[i]) | |
2187 | return i; | |
2188 | } | |
2189 | ||
2190 | return -EINVAL; | |
2191 | } | |
2192 | ||
2193 | /* Search for existing double vlan entry */ | |
2194 | static struct mvpp2_prs_entry *mvpp2_prs_double_vlan_find(struct mvpp2 *priv, | |
2195 | unsigned short tpid1, | |
2196 | unsigned short tpid2) | |
2197 | { | |
2198 | struct mvpp2_prs_entry *pe; | |
2199 | int tid; | |
2200 | ||
2201 | pe = kzalloc(sizeof(*pe), GFP_KERNEL); | |
2202 | if (!pe) | |
2203 | return NULL; | |
2204 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN); | |
2205 | ||
2206 | /* Go through the all entries with MVPP2_PRS_LU_VLAN */ | |
2207 | for (tid = MVPP2_PE_FIRST_FREE_TID; | |
2208 | tid <= MVPP2_PE_LAST_FREE_TID; tid++) { | |
2209 | unsigned int ri_mask; | |
2210 | bool match; | |
2211 | ||
2212 | if (!priv->prs_shadow[tid].valid || | |
2213 | priv->prs_shadow[tid].lu != MVPP2_PRS_LU_VLAN) | |
2214 | continue; | |
2215 | ||
2216 | pe->index = tid; | |
2217 | mvpp2_prs_hw_read(priv, pe); | |
2218 | ||
2219 | match = mvpp2_prs_tcam_data_cmp(pe, 0, swab16(tpid1)) | |
2220 | && mvpp2_prs_tcam_data_cmp(pe, 4, swab16(tpid2)); | |
2221 | ||
2222 | if (!match) | |
2223 | continue; | |
2224 | ||
2225 | ri_mask = mvpp2_prs_sram_ri_get(pe) & MVPP2_PRS_RI_VLAN_MASK; | |
2226 | if (ri_mask == MVPP2_PRS_RI_VLAN_DOUBLE) | |
2227 | return pe; | |
2228 | } | |
2229 | kfree(pe); | |
2230 | ||
2231 | return NULL; | |
2232 | } | |
2233 | ||
2234 | /* Add or update double vlan entry */ | |
2235 | static int mvpp2_prs_double_vlan_add(struct mvpp2 *priv, unsigned short tpid1, | |
2236 | unsigned short tpid2, | |
2237 | unsigned int port_map) | |
2238 | { | |
2239 | struct mvpp2_prs_entry *pe; | |
43737473 | 2240 | int tid_aux, tid, ai, ret = 0; |
3f518509 MW |
2241 | |
2242 | pe = mvpp2_prs_double_vlan_find(priv, tpid1, tpid2); | |
2243 | ||
2244 | if (!pe) { | |
2245 | /* Create new tcam entry */ | |
2246 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
2247 | MVPP2_PE_LAST_FREE_TID); | |
2248 | if (tid < 0) | |
2249 | return tid; | |
2250 | ||
2251 | pe = kzalloc(sizeof(*pe), GFP_KERNEL); | |
2252 | if (!pe) | |
2253 | return -ENOMEM; | |
2254 | ||
2255 | /* Set ai value for new double vlan entry */ | |
2256 | ai = mvpp2_prs_double_vlan_ai_free_get(priv); | |
43737473 SM |
2257 | if (ai < 0) { |
2258 | ret = ai; | |
c9a7e120 | 2259 | goto free_pe; |
43737473 | 2260 | } |
3f518509 MW |
2261 | |
2262 | /* Get first single/triple vlan tid */ | |
2263 | for (tid_aux = MVPP2_PE_FIRST_FREE_TID; | |
2264 | tid_aux <= MVPP2_PE_LAST_FREE_TID; tid_aux++) { | |
2265 | unsigned int ri_bits; | |
2266 | ||
2267 | if (!priv->prs_shadow[tid_aux].valid || | |
2268 | priv->prs_shadow[tid_aux].lu != MVPP2_PRS_LU_VLAN) | |
2269 | continue; | |
2270 | ||
2271 | pe->index = tid_aux; | |
2272 | mvpp2_prs_hw_read(priv, pe); | |
2273 | ri_bits = mvpp2_prs_sram_ri_get(pe); | |
2274 | ri_bits &= MVPP2_PRS_RI_VLAN_MASK; | |
2275 | if (ri_bits == MVPP2_PRS_RI_VLAN_SINGLE || | |
2276 | ri_bits == MVPP2_PRS_RI_VLAN_TRIPLE) | |
2277 | break; | |
2278 | } | |
2279 | ||
43737473 SM |
2280 | if (tid >= tid_aux) { |
2281 | ret = -ERANGE; | |
c9a7e120 | 2282 | goto free_pe; |
43737473 | 2283 | } |
3f518509 | 2284 | |
bd6aaf55 | 2285 | memset(pe, 0, sizeof(*pe)); |
3f518509 MW |
2286 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN); |
2287 | pe->index = tid; | |
2288 | ||
2289 | priv->prs_double_vlans[ai] = true; | |
2290 | ||
2291 | mvpp2_prs_match_etype(pe, 0, tpid1); | |
2292 | mvpp2_prs_match_etype(pe, 4, tpid2); | |
2293 | ||
2294 | mvpp2_prs_sram_next_lu_set(pe, MVPP2_PRS_LU_VLAN); | |
2295 | /* Shift 8 bytes - skip 2 vlan tags */ | |
2296 | mvpp2_prs_sram_shift_set(pe, 2 * MVPP2_VLAN_TAG_LEN, | |
2297 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
2298 | mvpp2_prs_sram_ri_update(pe, MVPP2_PRS_RI_VLAN_DOUBLE, | |
2299 | MVPP2_PRS_RI_VLAN_MASK); | |
2300 | mvpp2_prs_sram_ai_update(pe, ai | MVPP2_PRS_DBL_VLAN_AI_BIT, | |
2301 | MVPP2_PRS_SRAM_AI_MASK); | |
2302 | ||
2303 | mvpp2_prs_shadow_set(priv, pe->index, MVPP2_PRS_LU_VLAN); | |
2304 | } | |
2305 | ||
2306 | /* Update ports' mask */ | |
2307 | mvpp2_prs_tcam_port_map_set(pe, port_map); | |
2308 | mvpp2_prs_hw_write(priv, pe); | |
c9a7e120 | 2309 | free_pe: |
3f518509 | 2310 | kfree(pe); |
43737473 | 2311 | return ret; |
3f518509 MW |
2312 | } |
2313 | ||
2314 | /* IPv4 header parsing for fragmentation and L4 offset */ | |
2315 | static int mvpp2_prs_ip4_proto(struct mvpp2 *priv, unsigned short proto, | |
2316 | unsigned int ri, unsigned int ri_mask) | |
2317 | { | |
2318 | struct mvpp2_prs_entry pe; | |
2319 | int tid; | |
2320 | ||
2321 | if ((proto != IPPROTO_TCP) && (proto != IPPROTO_UDP) && | |
2322 | (proto != IPPROTO_IGMP)) | |
2323 | return -EINVAL; | |
2324 | ||
aff3da39 | 2325 | /* Not fragmented packet */ |
3f518509 MW |
2326 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
2327 | MVPP2_PE_LAST_FREE_TID); | |
2328 | if (tid < 0) | |
2329 | return tid; | |
2330 | ||
c5b2ce24 | 2331 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2332 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4); |
2333 | pe.index = tid; | |
2334 | ||
2335 | /* Set next lu to IPv4 */ | |
2336 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4); | |
2337 | mvpp2_prs_sram_shift_set(&pe, 12, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
2338 | /* Set L4 offset */ | |
2339 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4, | |
2340 | sizeof(struct iphdr) - 4, | |
2341 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); | |
2342 | mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT, | |
2343 | MVPP2_PRS_IPV4_DIP_AI_BIT); | |
aff3da39 SC |
2344 | mvpp2_prs_sram_ri_update(&pe, ri, ri_mask | MVPP2_PRS_RI_IP_FRAG_MASK); |
2345 | ||
2346 | mvpp2_prs_tcam_data_byte_set(&pe, 2, 0x00, | |
2347 | MVPP2_PRS_TCAM_PROTO_MASK_L); | |
2348 | mvpp2_prs_tcam_data_byte_set(&pe, 3, 0x00, | |
2349 | MVPP2_PRS_TCAM_PROTO_MASK); | |
3f518509 MW |
2350 | |
2351 | mvpp2_prs_tcam_data_byte_set(&pe, 5, proto, MVPP2_PRS_TCAM_PROTO_MASK); | |
2352 | mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV4_DIP_AI_BIT); | |
2353 | /* Unmask all ports */ | |
2354 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); | |
2355 | ||
2356 | /* Update shadow table and hw entry */ | |
2357 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); | |
2358 | mvpp2_prs_hw_write(priv, &pe); | |
2359 | ||
aff3da39 | 2360 | /* Fragmented packet */ |
3f518509 MW |
2361 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
2362 | MVPP2_PE_LAST_FREE_TID); | |
2363 | if (tid < 0) | |
2364 | return tid; | |
2365 | ||
2366 | pe.index = tid; | |
2367 | /* Clear ri before updating */ | |
2368 | pe.sram.word[MVPP2_PRS_SRAM_RI_WORD] = 0x0; | |
2369 | pe.sram.word[MVPP2_PRS_SRAM_RI_CTRL_WORD] = 0x0; | |
2370 | mvpp2_prs_sram_ri_update(&pe, ri, ri_mask); | |
2371 | ||
aff3da39 SC |
2372 | mvpp2_prs_sram_ri_update(&pe, ri | MVPP2_PRS_RI_IP_FRAG_TRUE, |
2373 | ri_mask | MVPP2_PRS_RI_IP_FRAG_MASK); | |
2374 | ||
2375 | mvpp2_prs_tcam_data_byte_set(&pe, 2, 0x00, 0x0); | |
2376 | mvpp2_prs_tcam_data_byte_set(&pe, 3, 0x00, 0x0); | |
3f518509 MW |
2377 | |
2378 | /* Update shadow table and hw entry */ | |
2379 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); | |
2380 | mvpp2_prs_hw_write(priv, &pe); | |
2381 | ||
2382 | return 0; | |
2383 | } | |
2384 | ||
2385 | /* IPv4 L3 multicast or broadcast */ | |
2386 | static int mvpp2_prs_ip4_cast(struct mvpp2 *priv, unsigned short l3_cast) | |
2387 | { | |
2388 | struct mvpp2_prs_entry pe; | |
2389 | int mask, tid; | |
2390 | ||
2391 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
2392 | MVPP2_PE_LAST_FREE_TID); | |
2393 | if (tid < 0) | |
2394 | return tid; | |
2395 | ||
c5b2ce24 | 2396 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2397 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4); |
2398 | pe.index = tid; | |
2399 | ||
2400 | switch (l3_cast) { | |
2401 | case MVPP2_PRS_L3_MULTI_CAST: | |
2402 | mvpp2_prs_tcam_data_byte_set(&pe, 0, MVPP2_PRS_IPV4_MC, | |
2403 | MVPP2_PRS_IPV4_MC_MASK); | |
2404 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_MCAST, | |
2405 | MVPP2_PRS_RI_L3_ADDR_MASK); | |
2406 | break; | |
2407 | case MVPP2_PRS_L3_BROAD_CAST: | |
2408 | mask = MVPP2_PRS_IPV4_BC_MASK; | |
2409 | mvpp2_prs_tcam_data_byte_set(&pe, 0, mask, mask); | |
2410 | mvpp2_prs_tcam_data_byte_set(&pe, 1, mask, mask); | |
2411 | mvpp2_prs_tcam_data_byte_set(&pe, 2, mask, mask); | |
2412 | mvpp2_prs_tcam_data_byte_set(&pe, 3, mask, mask); | |
2413 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_BCAST, | |
2414 | MVPP2_PRS_RI_L3_ADDR_MASK); | |
2415 | break; | |
2416 | default: | |
2417 | return -EINVAL; | |
2418 | } | |
2419 | ||
2420 | /* Finished: go to flowid generation */ | |
2421 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); | |
2422 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); | |
2423 | ||
2424 | mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT, | |
2425 | MVPP2_PRS_IPV4_DIP_AI_BIT); | |
2426 | /* Unmask all ports */ | |
2427 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); | |
2428 | ||
2429 | /* Update shadow table and hw entry */ | |
2430 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); | |
2431 | mvpp2_prs_hw_write(priv, &pe); | |
2432 | ||
2433 | return 0; | |
2434 | } | |
2435 | ||
2436 | /* Set entries for protocols over IPv6 */ | |
2437 | static int mvpp2_prs_ip6_proto(struct mvpp2 *priv, unsigned short proto, | |
2438 | unsigned int ri, unsigned int ri_mask) | |
2439 | { | |
2440 | struct mvpp2_prs_entry pe; | |
2441 | int tid; | |
2442 | ||
2443 | if ((proto != IPPROTO_TCP) && (proto != IPPROTO_UDP) && | |
2444 | (proto != IPPROTO_ICMPV6) && (proto != IPPROTO_IPIP)) | |
2445 | return -EINVAL; | |
2446 | ||
2447 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
2448 | MVPP2_PE_LAST_FREE_TID); | |
2449 | if (tid < 0) | |
2450 | return tid; | |
2451 | ||
c5b2ce24 | 2452 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2453 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6); |
2454 | pe.index = tid; | |
2455 | ||
2456 | /* Finished: go to flowid generation */ | |
2457 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); | |
2458 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); | |
2459 | mvpp2_prs_sram_ri_update(&pe, ri, ri_mask); | |
2460 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4, | |
2461 | sizeof(struct ipv6hdr) - 6, | |
2462 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); | |
2463 | ||
2464 | mvpp2_prs_tcam_data_byte_set(&pe, 0, proto, MVPP2_PRS_TCAM_PROTO_MASK); | |
2465 | mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT, | |
2466 | MVPP2_PRS_IPV6_NO_EXT_AI_BIT); | |
2467 | /* Unmask all ports */ | |
2468 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); | |
2469 | ||
2470 | /* Write HW */ | |
2471 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP6); | |
2472 | mvpp2_prs_hw_write(priv, &pe); | |
2473 | ||
2474 | return 0; | |
2475 | } | |
2476 | ||
2477 | /* IPv6 L3 multicast entry */ | |
2478 | static int mvpp2_prs_ip6_cast(struct mvpp2 *priv, unsigned short l3_cast) | |
2479 | { | |
2480 | struct mvpp2_prs_entry pe; | |
2481 | int tid; | |
2482 | ||
2483 | if (l3_cast != MVPP2_PRS_L3_MULTI_CAST) | |
2484 | return -EINVAL; | |
2485 | ||
2486 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
2487 | MVPP2_PE_LAST_FREE_TID); | |
2488 | if (tid < 0) | |
2489 | return tid; | |
2490 | ||
c5b2ce24 | 2491 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2492 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6); |
2493 | pe.index = tid; | |
2494 | ||
2495 | /* Finished: go to flowid generation */ | |
2496 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6); | |
2497 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_MCAST, | |
2498 | MVPP2_PRS_RI_L3_ADDR_MASK); | |
2499 | mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT, | |
2500 | MVPP2_PRS_IPV6_NO_EXT_AI_BIT); | |
2501 | /* Shift back to IPv6 NH */ | |
2502 | mvpp2_prs_sram_shift_set(&pe, -18, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
2503 | ||
2504 | mvpp2_prs_tcam_data_byte_set(&pe, 0, MVPP2_PRS_IPV6_MC, | |
2505 | MVPP2_PRS_IPV6_MC_MASK); | |
2506 | mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV6_NO_EXT_AI_BIT); | |
2507 | /* Unmask all ports */ | |
2508 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); | |
2509 | ||
2510 | /* Update shadow table and hw entry */ | |
2511 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP6); | |
2512 | mvpp2_prs_hw_write(priv, &pe); | |
2513 | ||
2514 | return 0; | |
2515 | } | |
2516 | ||
2517 | /* Parser per-port initialization */ | |
2518 | static void mvpp2_prs_hw_port_init(struct mvpp2 *priv, int port, int lu_first, | |
2519 | int lu_max, int offset) | |
2520 | { | |
2521 | u32 val; | |
2522 | ||
2523 | /* Set lookup ID */ | |
2524 | val = mvpp2_read(priv, MVPP2_PRS_INIT_LOOKUP_REG); | |
2525 | val &= ~MVPP2_PRS_PORT_LU_MASK(port); | |
2526 | val |= MVPP2_PRS_PORT_LU_VAL(port, lu_first); | |
2527 | mvpp2_write(priv, MVPP2_PRS_INIT_LOOKUP_REG, val); | |
2528 | ||
2529 | /* Set maximum number of loops for packet received from port */ | |
2530 | val = mvpp2_read(priv, MVPP2_PRS_MAX_LOOP_REG(port)); | |
2531 | val &= ~MVPP2_PRS_MAX_LOOP_MASK(port); | |
2532 | val |= MVPP2_PRS_MAX_LOOP_VAL(port, lu_max); | |
2533 | mvpp2_write(priv, MVPP2_PRS_MAX_LOOP_REG(port), val); | |
2534 | ||
2535 | /* Set initial offset for packet header extraction for the first | |
2536 | * searching loop | |
2537 | */ | |
2538 | val = mvpp2_read(priv, MVPP2_PRS_INIT_OFFS_REG(port)); | |
2539 | val &= ~MVPP2_PRS_INIT_OFF_MASK(port); | |
2540 | val |= MVPP2_PRS_INIT_OFF_VAL(port, offset); | |
2541 | mvpp2_write(priv, MVPP2_PRS_INIT_OFFS_REG(port), val); | |
2542 | } | |
2543 | ||
2544 | /* Default flow entries initialization for all ports */ | |
2545 | static void mvpp2_prs_def_flow_init(struct mvpp2 *priv) | |
2546 | { | |
2547 | struct mvpp2_prs_entry pe; | |
2548 | int port; | |
2549 | ||
2550 | for (port = 0; port < MVPP2_MAX_PORTS; port++) { | |
c5b2ce24 | 2551 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2552 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_FLOWS); |
2553 | pe.index = MVPP2_PE_FIRST_DEFAULT_FLOW - port; | |
2554 | ||
2555 | /* Mask all ports */ | |
2556 | mvpp2_prs_tcam_port_map_set(&pe, 0); | |
2557 | ||
2558 | /* Set flow ID*/ | |
2559 | mvpp2_prs_sram_ai_update(&pe, port, MVPP2_PRS_FLOW_ID_MASK); | |
2560 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_DONE_BIT, 1); | |
2561 | ||
2562 | /* Update shadow table and hw entry */ | |
2563 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_FLOWS); | |
2564 | mvpp2_prs_hw_write(priv, &pe); | |
2565 | } | |
2566 | } | |
2567 | ||
2568 | /* Set default entry for Marvell Header field */ | |
2569 | static void mvpp2_prs_mh_init(struct mvpp2 *priv) | |
2570 | { | |
2571 | struct mvpp2_prs_entry pe; | |
2572 | ||
c5b2ce24 | 2573 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2574 | |
2575 | pe.index = MVPP2_PE_MH_DEFAULT; | |
2576 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MH); | |
2577 | mvpp2_prs_sram_shift_set(&pe, MVPP2_MH_SIZE, | |
2578 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
2579 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_MAC); | |
2580 | ||
2581 | /* Unmask all ports */ | |
2582 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); | |
2583 | ||
2584 | /* Update shadow table and hw entry */ | |
2585 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MH); | |
2586 | mvpp2_prs_hw_write(priv, &pe); | |
2587 | } | |
2588 | ||
2589 | /* Set default entires (place holder) for promiscuous, non-promiscuous and | |
2590 | * multicast MAC addresses | |
2591 | */ | |
2592 | static void mvpp2_prs_mac_init(struct mvpp2 *priv) | |
2593 | { | |
2594 | struct mvpp2_prs_entry pe; | |
2595 | ||
c5b2ce24 | 2596 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2597 | |
2598 | /* Non-promiscuous mode for all ports - DROP unknown packets */ | |
2599 | pe.index = MVPP2_PE_MAC_NON_PROMISCUOUS; | |
2600 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC); | |
2601 | ||
2602 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_DROP_MASK, | |
2603 | MVPP2_PRS_RI_DROP_MASK); | |
2604 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); | |
2605 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); | |
2606 | ||
2607 | /* Unmask all ports */ | |
2608 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); | |
2609 | ||
2610 | /* Update shadow table and hw entry */ | |
2611 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC); | |
2612 | mvpp2_prs_hw_write(priv, &pe); | |
2613 | ||
2614 | /* place holders only - no ports */ | |
2615 | mvpp2_prs_mac_drop_all_set(priv, 0, false); | |
2616 | mvpp2_prs_mac_promisc_set(priv, 0, false); | |
20746d71 AT |
2617 | mvpp2_prs_mac_multi_set(priv, 0, MVPP2_PE_MAC_MC_ALL, false); |
2618 | mvpp2_prs_mac_multi_set(priv, 0, MVPP2_PE_MAC_MC_IP6, false); | |
3f518509 MW |
2619 | } |
2620 | ||
2621 | /* Set default entries for various types of dsa packets */ | |
2622 | static void mvpp2_prs_dsa_init(struct mvpp2 *priv) | |
2623 | { | |
2624 | struct mvpp2_prs_entry pe; | |
2625 | ||
2626 | /* None tagged EDSA entry - place holder */ | |
2627 | mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_UNTAGGED, | |
2628 | MVPP2_PRS_EDSA); | |
2629 | ||
2630 | /* Tagged EDSA entry - place holder */ | |
2631 | mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA); | |
2632 | ||
2633 | /* None tagged DSA entry - place holder */ | |
2634 | mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_UNTAGGED, | |
2635 | MVPP2_PRS_DSA); | |
2636 | ||
2637 | /* Tagged DSA entry - place holder */ | |
2638 | mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_TAGGED, MVPP2_PRS_DSA); | |
2639 | ||
2640 | /* None tagged EDSA ethertype entry - place holder*/ | |
2641 | mvpp2_prs_dsa_tag_ethertype_set(priv, 0, false, | |
2642 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA); | |
2643 | ||
2644 | /* Tagged EDSA ethertype entry - place holder*/ | |
2645 | mvpp2_prs_dsa_tag_ethertype_set(priv, 0, false, | |
2646 | MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA); | |
2647 | ||
2648 | /* None tagged DSA ethertype entry */ | |
2649 | mvpp2_prs_dsa_tag_ethertype_set(priv, 0, true, | |
2650 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA); | |
2651 | ||
2652 | /* Tagged DSA ethertype entry */ | |
2653 | mvpp2_prs_dsa_tag_ethertype_set(priv, 0, true, | |
2654 | MVPP2_PRS_TAGGED, MVPP2_PRS_DSA); | |
2655 | ||
2656 | /* Set default entry, in case DSA or EDSA tag not found */ | |
c5b2ce24 | 2657 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2658 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_DSA); |
2659 | pe.index = MVPP2_PE_DSA_DEFAULT; | |
2660 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_VLAN); | |
2661 | ||
2662 | /* Shift 0 bytes */ | |
2663 | mvpp2_prs_sram_shift_set(&pe, 0, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
2664 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC); | |
2665 | ||
2666 | /* Clear all sram ai bits for next iteration */ | |
2667 | mvpp2_prs_sram_ai_update(&pe, 0, MVPP2_PRS_SRAM_AI_MASK); | |
2668 | ||
2669 | /* Unmask all ports */ | |
2670 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); | |
2671 | ||
2672 | mvpp2_prs_hw_write(priv, &pe); | |
2673 | } | |
2674 | ||
2675 | /* Match basic ethertypes */ | |
2676 | static int mvpp2_prs_etype_init(struct mvpp2 *priv) | |
2677 | { | |
2678 | struct mvpp2_prs_entry pe; | |
2679 | int tid; | |
2680 | ||
2681 | /* Ethertype: PPPoE */ | |
2682 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
2683 | MVPP2_PE_LAST_FREE_TID); | |
2684 | if (tid < 0) | |
2685 | return tid; | |
2686 | ||
c5b2ce24 | 2687 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2688 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2); |
2689 | pe.index = tid; | |
2690 | ||
2691 | mvpp2_prs_match_etype(&pe, 0, ETH_P_PPP_SES); | |
2692 | ||
2693 | mvpp2_prs_sram_shift_set(&pe, MVPP2_PPPOE_HDR_SIZE, | |
2694 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
2695 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_PPPOE); | |
2696 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_PPPOE_MASK, | |
2697 | MVPP2_PRS_RI_PPPOE_MASK); | |
2698 | ||
2699 | /* Update shadow table and hw entry */ | |
2700 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2); | |
2701 | priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF; | |
2702 | priv->prs_shadow[pe.index].finish = false; | |
2703 | mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_PPPOE_MASK, | |
2704 | MVPP2_PRS_RI_PPPOE_MASK); | |
2705 | mvpp2_prs_hw_write(priv, &pe); | |
2706 | ||
2707 | /* Ethertype: ARP */ | |
2708 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
2709 | MVPP2_PE_LAST_FREE_TID); | |
2710 | if (tid < 0) | |
2711 | return tid; | |
2712 | ||
c5b2ce24 | 2713 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2714 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2); |
2715 | pe.index = tid; | |
2716 | ||
2717 | mvpp2_prs_match_etype(&pe, 0, ETH_P_ARP); | |
2718 | ||
2719 | /* Generate flow in the next iteration*/ | |
2720 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); | |
2721 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); | |
2722 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_ARP, | |
2723 | MVPP2_PRS_RI_L3_PROTO_MASK); | |
2724 | /* Set L3 offset */ | |
2725 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, | |
2726 | MVPP2_ETH_TYPE_LEN, | |
2727 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); | |
2728 | ||
2729 | /* Update shadow table and hw entry */ | |
2730 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2); | |
2731 | priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF; | |
2732 | priv->prs_shadow[pe.index].finish = true; | |
2733 | mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_ARP, | |
2734 | MVPP2_PRS_RI_L3_PROTO_MASK); | |
2735 | mvpp2_prs_hw_write(priv, &pe); | |
2736 | ||
2737 | /* Ethertype: LBTD */ | |
2738 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
2739 | MVPP2_PE_LAST_FREE_TID); | |
2740 | if (tid < 0) | |
2741 | return tid; | |
2742 | ||
c5b2ce24 | 2743 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2744 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2); |
2745 | pe.index = tid; | |
2746 | ||
2747 | mvpp2_prs_match_etype(&pe, 0, MVPP2_IP_LBDT_TYPE); | |
2748 | ||
2749 | /* Generate flow in the next iteration*/ | |
2750 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); | |
2751 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); | |
2752 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_CPU_CODE_RX_SPEC | | |
2753 | MVPP2_PRS_RI_UDF3_RX_SPECIAL, | |
2754 | MVPP2_PRS_RI_CPU_CODE_MASK | | |
2755 | MVPP2_PRS_RI_UDF3_MASK); | |
2756 | /* Set L3 offset */ | |
2757 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, | |
2758 | MVPP2_ETH_TYPE_LEN, | |
2759 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); | |
2760 | ||
2761 | /* Update shadow table and hw entry */ | |
2762 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2); | |
2763 | priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF; | |
2764 | priv->prs_shadow[pe.index].finish = true; | |
2765 | mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_CPU_CODE_RX_SPEC | | |
2766 | MVPP2_PRS_RI_UDF3_RX_SPECIAL, | |
2767 | MVPP2_PRS_RI_CPU_CODE_MASK | | |
2768 | MVPP2_PRS_RI_UDF3_MASK); | |
2769 | mvpp2_prs_hw_write(priv, &pe); | |
2770 | ||
2771 | /* Ethertype: IPv4 without options */ | |
2772 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
2773 | MVPP2_PE_LAST_FREE_TID); | |
2774 | if (tid < 0) | |
2775 | return tid; | |
2776 | ||
c5b2ce24 | 2777 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2778 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2); |
2779 | pe.index = tid; | |
2780 | ||
2781 | mvpp2_prs_match_etype(&pe, 0, ETH_P_IP); | |
2782 | mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN, | |
2783 | MVPP2_PRS_IPV4_HEAD | MVPP2_PRS_IPV4_IHL, | |
2784 | MVPP2_PRS_IPV4_HEAD_MASK | | |
2785 | MVPP2_PRS_IPV4_IHL_MASK); | |
2786 | ||
2787 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4); | |
2788 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4, | |
2789 | MVPP2_PRS_RI_L3_PROTO_MASK); | |
2790 | /* Skip eth_type + 4 bytes of IP header */ | |
2791 | mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 4, | |
2792 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
2793 | /* Set L3 offset */ | |
2794 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, | |
2795 | MVPP2_ETH_TYPE_LEN, | |
2796 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); | |
2797 | ||
2798 | /* Update shadow table and hw entry */ | |
2799 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2); | |
2800 | priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF; | |
2801 | priv->prs_shadow[pe.index].finish = false; | |
2802 | mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_IP4, | |
2803 | MVPP2_PRS_RI_L3_PROTO_MASK); | |
2804 | mvpp2_prs_hw_write(priv, &pe); | |
2805 | ||
2806 | /* Ethertype: IPv4 with options */ | |
2807 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
2808 | MVPP2_PE_LAST_FREE_TID); | |
2809 | if (tid < 0) | |
2810 | return tid; | |
2811 | ||
2812 | pe.index = tid; | |
2813 | ||
2814 | /* Clear tcam data before updating */ | |
2815 | pe.tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE(MVPP2_ETH_TYPE_LEN)] = 0x0; | |
2816 | pe.tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE_EN(MVPP2_ETH_TYPE_LEN)] = 0x0; | |
2817 | ||
2818 | mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN, | |
2819 | MVPP2_PRS_IPV4_HEAD, | |
2820 | MVPP2_PRS_IPV4_HEAD_MASK); | |
2821 | ||
2822 | /* Clear ri before updating */ | |
2823 | pe.sram.word[MVPP2_PRS_SRAM_RI_WORD] = 0x0; | |
2824 | pe.sram.word[MVPP2_PRS_SRAM_RI_CTRL_WORD] = 0x0; | |
2825 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4_OPT, | |
2826 | MVPP2_PRS_RI_L3_PROTO_MASK); | |
2827 | ||
2828 | /* Update shadow table and hw entry */ | |
2829 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2); | |
2830 | priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF; | |
2831 | priv->prs_shadow[pe.index].finish = false; | |
2832 | mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_IP4_OPT, | |
2833 | MVPP2_PRS_RI_L3_PROTO_MASK); | |
2834 | mvpp2_prs_hw_write(priv, &pe); | |
2835 | ||
2836 | /* Ethertype: IPv6 without options */ | |
2837 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
2838 | MVPP2_PE_LAST_FREE_TID); | |
2839 | if (tid < 0) | |
2840 | return tid; | |
2841 | ||
c5b2ce24 | 2842 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2843 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2); |
2844 | pe.index = tid; | |
2845 | ||
2846 | mvpp2_prs_match_etype(&pe, 0, ETH_P_IPV6); | |
2847 | ||
2848 | /* Skip DIP of IPV6 header */ | |
2849 | mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 8 + | |
2850 | MVPP2_MAX_L3_ADDR_SIZE, | |
2851 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
2852 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6); | |
2853 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP6, | |
2854 | MVPP2_PRS_RI_L3_PROTO_MASK); | |
2855 | /* Set L3 offset */ | |
2856 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, | |
2857 | MVPP2_ETH_TYPE_LEN, | |
2858 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); | |
2859 | ||
2860 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2); | |
2861 | priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF; | |
2862 | priv->prs_shadow[pe.index].finish = false; | |
2863 | mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_IP6, | |
2864 | MVPP2_PRS_RI_L3_PROTO_MASK); | |
2865 | mvpp2_prs_hw_write(priv, &pe); | |
2866 | ||
2867 | /* Default entry for MVPP2_PRS_LU_L2 - Unknown ethtype */ | |
2868 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); | |
2869 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2); | |
2870 | pe.index = MVPP2_PE_ETH_TYPE_UN; | |
2871 | ||
2872 | /* Unmask all ports */ | |
2873 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); | |
2874 | ||
2875 | /* Generate flow in the next iteration*/ | |
2876 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); | |
2877 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); | |
2878 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UN, | |
2879 | MVPP2_PRS_RI_L3_PROTO_MASK); | |
2880 | /* Set L3 offset even it's unknown L3 */ | |
2881 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, | |
2882 | MVPP2_ETH_TYPE_LEN, | |
2883 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); | |
2884 | ||
2885 | /* Update shadow table and hw entry */ | |
2886 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2); | |
2887 | priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF; | |
2888 | priv->prs_shadow[pe.index].finish = true; | |
2889 | mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_UN, | |
2890 | MVPP2_PRS_RI_L3_PROTO_MASK); | |
2891 | mvpp2_prs_hw_write(priv, &pe); | |
2892 | ||
2893 | return 0; | |
2894 | } | |
2895 | ||
2896 | /* Configure vlan entries and detect up to 2 successive VLAN tags. | |
2897 | * Possible options: | |
2898 | * 0x8100, 0x88A8 | |
2899 | * 0x8100, 0x8100 | |
2900 | * 0x8100 | |
2901 | * 0x88A8 | |
2902 | */ | |
2903 | static int mvpp2_prs_vlan_init(struct platform_device *pdev, struct mvpp2 *priv) | |
2904 | { | |
2905 | struct mvpp2_prs_entry pe; | |
2906 | int err; | |
2907 | ||
2908 | priv->prs_double_vlans = devm_kcalloc(&pdev->dev, sizeof(bool), | |
2909 | MVPP2_PRS_DBL_VLANS_MAX, | |
2910 | GFP_KERNEL); | |
2911 | if (!priv->prs_double_vlans) | |
2912 | return -ENOMEM; | |
2913 | ||
2914 | /* Double VLAN: 0x8100, 0x88A8 */ | |
2915 | err = mvpp2_prs_double_vlan_add(priv, ETH_P_8021Q, ETH_P_8021AD, | |
2916 | MVPP2_PRS_PORT_MASK); | |
2917 | if (err) | |
2918 | return err; | |
2919 | ||
2920 | /* Double VLAN: 0x8100, 0x8100 */ | |
2921 | err = mvpp2_prs_double_vlan_add(priv, ETH_P_8021Q, ETH_P_8021Q, | |
2922 | MVPP2_PRS_PORT_MASK); | |
2923 | if (err) | |
2924 | return err; | |
2925 | ||
2926 | /* Single VLAN: 0x88a8 */ | |
2927 | err = mvpp2_prs_vlan_add(priv, ETH_P_8021AD, MVPP2_PRS_SINGLE_VLAN_AI, | |
2928 | MVPP2_PRS_PORT_MASK); | |
2929 | if (err) | |
2930 | return err; | |
2931 | ||
2932 | /* Single VLAN: 0x8100 */ | |
2933 | err = mvpp2_prs_vlan_add(priv, ETH_P_8021Q, MVPP2_PRS_SINGLE_VLAN_AI, | |
2934 | MVPP2_PRS_PORT_MASK); | |
2935 | if (err) | |
2936 | return err; | |
2937 | ||
2938 | /* Set default double vlan entry */ | |
c5b2ce24 | 2939 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2940 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_VLAN); |
2941 | pe.index = MVPP2_PE_VLAN_DBL; | |
2942 | ||
2943 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2); | |
2944 | /* Clear ai for next iterations */ | |
2945 | mvpp2_prs_sram_ai_update(&pe, 0, MVPP2_PRS_SRAM_AI_MASK); | |
2946 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_DOUBLE, | |
2947 | MVPP2_PRS_RI_VLAN_MASK); | |
2948 | ||
2949 | mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_DBL_VLAN_AI_BIT, | |
2950 | MVPP2_PRS_DBL_VLAN_AI_BIT); | |
2951 | /* Unmask all ports */ | |
2952 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); | |
2953 | ||
2954 | /* Update shadow table and hw entry */ | |
2955 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_VLAN); | |
2956 | mvpp2_prs_hw_write(priv, &pe); | |
2957 | ||
2958 | /* Set default vlan none entry */ | |
c5b2ce24 | 2959 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2960 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_VLAN); |
2961 | pe.index = MVPP2_PE_VLAN_NONE; | |
2962 | ||
2963 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2); | |
2964 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_NONE, | |
2965 | MVPP2_PRS_RI_VLAN_MASK); | |
2966 | ||
2967 | /* Unmask all ports */ | |
2968 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); | |
2969 | ||
2970 | /* Update shadow table and hw entry */ | |
2971 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_VLAN); | |
2972 | mvpp2_prs_hw_write(priv, &pe); | |
2973 | ||
2974 | return 0; | |
2975 | } | |
2976 | ||
2977 | /* Set entries for PPPoE ethertype */ | |
2978 | static int mvpp2_prs_pppoe_init(struct mvpp2 *priv) | |
2979 | { | |
2980 | struct mvpp2_prs_entry pe; | |
2981 | int tid; | |
2982 | ||
2983 | /* IPv4 over PPPoE with options */ | |
2984 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
2985 | MVPP2_PE_LAST_FREE_TID); | |
2986 | if (tid < 0) | |
2987 | return tid; | |
2988 | ||
c5b2ce24 | 2989 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
2990 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_PPPOE); |
2991 | pe.index = tid; | |
2992 | ||
2993 | mvpp2_prs_match_etype(&pe, 0, PPP_IP); | |
2994 | ||
2995 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4); | |
2996 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4_OPT, | |
2997 | MVPP2_PRS_RI_L3_PROTO_MASK); | |
2998 | /* Skip eth_type + 4 bytes of IP header */ | |
2999 | mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 4, | |
3000 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
3001 | /* Set L3 offset */ | |
3002 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, | |
3003 | MVPP2_ETH_TYPE_LEN, | |
3004 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); | |
3005 | ||
3006 | /* Update shadow table and hw entry */ | |
3007 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE); | |
3008 | mvpp2_prs_hw_write(priv, &pe); | |
3009 | ||
3010 | /* IPv4 over PPPoE without options */ | |
3011 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
3012 | MVPP2_PE_LAST_FREE_TID); | |
3013 | if (tid < 0) | |
3014 | return tid; | |
3015 | ||
3016 | pe.index = tid; | |
3017 | ||
3018 | mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN, | |
3019 | MVPP2_PRS_IPV4_HEAD | MVPP2_PRS_IPV4_IHL, | |
3020 | MVPP2_PRS_IPV4_HEAD_MASK | | |
3021 | MVPP2_PRS_IPV4_IHL_MASK); | |
3022 | ||
3023 | /* Clear ri before updating */ | |
3024 | pe.sram.word[MVPP2_PRS_SRAM_RI_WORD] = 0x0; | |
3025 | pe.sram.word[MVPP2_PRS_SRAM_RI_CTRL_WORD] = 0x0; | |
3026 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4, | |
3027 | MVPP2_PRS_RI_L3_PROTO_MASK); | |
3028 | ||
3029 | /* Update shadow table and hw entry */ | |
3030 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE); | |
3031 | mvpp2_prs_hw_write(priv, &pe); | |
3032 | ||
3033 | /* IPv6 over PPPoE */ | |
3034 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
3035 | MVPP2_PE_LAST_FREE_TID); | |
3036 | if (tid < 0) | |
3037 | return tid; | |
3038 | ||
c5b2ce24 | 3039 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
3040 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_PPPOE); |
3041 | pe.index = tid; | |
3042 | ||
3043 | mvpp2_prs_match_etype(&pe, 0, PPP_IPV6); | |
3044 | ||
3045 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6); | |
3046 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP6, | |
3047 | MVPP2_PRS_RI_L3_PROTO_MASK); | |
3048 | /* Skip eth_type + 4 bytes of IPv6 header */ | |
3049 | mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 4, | |
3050 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
3051 | /* Set L3 offset */ | |
3052 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, | |
3053 | MVPP2_ETH_TYPE_LEN, | |
3054 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); | |
3055 | ||
3056 | /* Update shadow table and hw entry */ | |
3057 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE); | |
3058 | mvpp2_prs_hw_write(priv, &pe); | |
3059 | ||
3060 | /* Non-IP over PPPoE */ | |
3061 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
3062 | MVPP2_PE_LAST_FREE_TID); | |
3063 | if (tid < 0) | |
3064 | return tid; | |
3065 | ||
c5b2ce24 | 3066 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
3067 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_PPPOE); |
3068 | pe.index = tid; | |
3069 | ||
3070 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UN, | |
3071 | MVPP2_PRS_RI_L3_PROTO_MASK); | |
3072 | ||
3073 | /* Finished: go to flowid generation */ | |
3074 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); | |
3075 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); | |
3076 | /* Set L3 offset even if it's unknown L3 */ | |
3077 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, | |
3078 | MVPP2_ETH_TYPE_LEN, | |
3079 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); | |
3080 | ||
3081 | /* Update shadow table and hw entry */ | |
3082 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE); | |
3083 | mvpp2_prs_hw_write(priv, &pe); | |
3084 | ||
3085 | return 0; | |
3086 | } | |
3087 | ||
3088 | /* Initialize entries for IPv4 */ | |
3089 | static int mvpp2_prs_ip4_init(struct mvpp2 *priv) | |
3090 | { | |
3091 | struct mvpp2_prs_entry pe; | |
3092 | int err; | |
3093 | ||
3094 | /* Set entries for TCP, UDP and IGMP over IPv4 */ | |
3095 | err = mvpp2_prs_ip4_proto(priv, IPPROTO_TCP, MVPP2_PRS_RI_L4_TCP, | |
3096 | MVPP2_PRS_RI_L4_PROTO_MASK); | |
3097 | if (err) | |
3098 | return err; | |
3099 | ||
3100 | err = mvpp2_prs_ip4_proto(priv, IPPROTO_UDP, MVPP2_PRS_RI_L4_UDP, | |
3101 | MVPP2_PRS_RI_L4_PROTO_MASK); | |
3102 | if (err) | |
3103 | return err; | |
3104 | ||
3105 | err = mvpp2_prs_ip4_proto(priv, IPPROTO_IGMP, | |
3106 | MVPP2_PRS_RI_CPU_CODE_RX_SPEC | | |
3107 | MVPP2_PRS_RI_UDF3_RX_SPECIAL, | |
3108 | MVPP2_PRS_RI_CPU_CODE_MASK | | |
3109 | MVPP2_PRS_RI_UDF3_MASK); | |
3110 | if (err) | |
3111 | return err; | |
3112 | ||
3113 | /* IPv4 Broadcast */ | |
3114 | err = mvpp2_prs_ip4_cast(priv, MVPP2_PRS_L3_BROAD_CAST); | |
3115 | if (err) | |
3116 | return err; | |
3117 | ||
3118 | /* IPv4 Multicast */ | |
3119 | err = mvpp2_prs_ip4_cast(priv, MVPP2_PRS_L3_MULTI_CAST); | |
3120 | if (err) | |
3121 | return err; | |
3122 | ||
3123 | /* Default IPv4 entry for unknown protocols */ | |
c5b2ce24 | 3124 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
3125 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4); |
3126 | pe.index = MVPP2_PE_IP4_PROTO_UN; | |
3127 | ||
3128 | /* Set next lu to IPv4 */ | |
3129 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4); | |
3130 | mvpp2_prs_sram_shift_set(&pe, 12, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
3131 | /* Set L4 offset */ | |
3132 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4, | |
3133 | sizeof(struct iphdr) - 4, | |
3134 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); | |
3135 | mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT, | |
3136 | MVPP2_PRS_IPV4_DIP_AI_BIT); | |
3137 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L4_OTHER, | |
3138 | MVPP2_PRS_RI_L4_PROTO_MASK); | |
3139 | ||
3140 | mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV4_DIP_AI_BIT); | |
3141 | /* Unmask all ports */ | |
3142 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); | |
3143 | ||
3144 | /* Update shadow table and hw entry */ | |
3145 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); | |
3146 | mvpp2_prs_hw_write(priv, &pe); | |
3147 | ||
3148 | /* Default IPv4 entry for unicast address */ | |
c5b2ce24 | 3149 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
3150 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4); |
3151 | pe.index = MVPP2_PE_IP4_ADDR_UN; | |
3152 | ||
3153 | /* Finished: go to flowid generation */ | |
3154 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); | |
3155 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); | |
3156 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UCAST, | |
3157 | MVPP2_PRS_RI_L3_ADDR_MASK); | |
3158 | ||
3159 | mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT, | |
3160 | MVPP2_PRS_IPV4_DIP_AI_BIT); | |
3161 | /* Unmask all ports */ | |
3162 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); | |
3163 | ||
3164 | /* Update shadow table and hw entry */ | |
3165 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); | |
3166 | mvpp2_prs_hw_write(priv, &pe); | |
3167 | ||
3168 | return 0; | |
3169 | } | |
3170 | ||
3171 | /* Initialize entries for IPv6 */ | |
3172 | static int mvpp2_prs_ip6_init(struct mvpp2 *priv) | |
3173 | { | |
3174 | struct mvpp2_prs_entry pe; | |
3175 | int tid, err; | |
3176 | ||
3177 | /* Set entries for TCP, UDP and ICMP over IPv6 */ | |
3178 | err = mvpp2_prs_ip6_proto(priv, IPPROTO_TCP, | |
3179 | MVPP2_PRS_RI_L4_TCP, | |
3180 | MVPP2_PRS_RI_L4_PROTO_MASK); | |
3181 | if (err) | |
3182 | return err; | |
3183 | ||
3184 | err = mvpp2_prs_ip6_proto(priv, IPPROTO_UDP, | |
3185 | MVPP2_PRS_RI_L4_UDP, | |
3186 | MVPP2_PRS_RI_L4_PROTO_MASK); | |
3187 | if (err) | |
3188 | return err; | |
3189 | ||
3190 | err = mvpp2_prs_ip6_proto(priv, IPPROTO_ICMPV6, | |
3191 | MVPP2_PRS_RI_CPU_CODE_RX_SPEC | | |
3192 | MVPP2_PRS_RI_UDF3_RX_SPECIAL, | |
3193 | MVPP2_PRS_RI_CPU_CODE_MASK | | |
3194 | MVPP2_PRS_RI_UDF3_MASK); | |
3195 | if (err) | |
3196 | return err; | |
3197 | ||
3198 | /* IPv4 is the last header. This is similar case as 6-TCP or 17-UDP */ | |
3199 | /* Result Info: UDF7=1, DS lite */ | |
3200 | err = mvpp2_prs_ip6_proto(priv, IPPROTO_IPIP, | |
3201 | MVPP2_PRS_RI_UDF7_IP6_LITE, | |
3202 | MVPP2_PRS_RI_UDF7_MASK); | |
3203 | if (err) | |
3204 | return err; | |
3205 | ||
3206 | /* IPv6 multicast */ | |
3207 | err = mvpp2_prs_ip6_cast(priv, MVPP2_PRS_L3_MULTI_CAST); | |
3208 | if (err) | |
3209 | return err; | |
3210 | ||
3211 | /* Entry for checking hop limit */ | |
3212 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
3213 | MVPP2_PE_LAST_FREE_TID); | |
3214 | if (tid < 0) | |
3215 | return tid; | |
3216 | ||
c5b2ce24 | 3217 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
3218 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6); |
3219 | pe.index = tid; | |
3220 | ||
3221 | /* Finished: go to flowid generation */ | |
3222 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); | |
3223 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); | |
3224 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UN | | |
3225 | MVPP2_PRS_RI_DROP_MASK, | |
3226 | MVPP2_PRS_RI_L3_PROTO_MASK | | |
3227 | MVPP2_PRS_RI_DROP_MASK); | |
3228 | ||
3229 | mvpp2_prs_tcam_data_byte_set(&pe, 1, 0x00, MVPP2_PRS_IPV6_HOP_MASK); | |
3230 | mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT, | |
3231 | MVPP2_PRS_IPV6_NO_EXT_AI_BIT); | |
3232 | ||
3233 | /* Update shadow table and hw entry */ | |
3234 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); | |
3235 | mvpp2_prs_hw_write(priv, &pe); | |
3236 | ||
3237 | /* Default IPv6 entry for unknown protocols */ | |
c5b2ce24 | 3238 | memset(&pe, 0, sizeof(pe)); |
3f518509 MW |
3239 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6); |
3240 | pe.index = MVPP2_PE_IP6_PROTO_UN; | |
3241 | ||
3242 | /* Finished: go to flowid generation */ | |
3243 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); | |
3244 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); | |
3245 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L4_OTHER, | |
3246 | MVPP2_PRS_RI_L4_PROTO_MASK); | |
3247 | /* Set L4 offset relatively to our current place */ | |
3248 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4, | |
3249 | sizeof(struct ipv6hdr) - 4, | |
3250 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); | |
3251 | ||
3252 | mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT, | |
3253 | MVPP2_PRS_IPV6_NO_EXT_AI_BIT); | |
3254 | /* Unmask all ports */ | |
3255 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); | |
3256 | ||
3257 | /* Update shadow table and hw entry */ | |
3258 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); | |
3259 | mvpp2_prs_hw_write(priv, &pe); | |
3260 | ||
3261 | /* Default IPv6 entry for unknown ext protocols */ | |
3262 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); | |
3263 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6); | |
3264 | pe.index = MVPP2_PE_IP6_EXT_PROTO_UN; | |
3265 | ||
3266 | /* Finished: go to flowid generation */ | |
3267 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); | |
3268 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); | |
3269 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L4_OTHER, | |
3270 | MVPP2_PRS_RI_L4_PROTO_MASK); | |
3271 | ||
3272 | mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_EXT_AI_BIT, | |
3273 | MVPP2_PRS_IPV6_EXT_AI_BIT); | |
3274 | /* Unmask all ports */ | |
3275 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); | |
3276 | ||
3277 | /* Update shadow table and hw entry */ | |
3278 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); | |
3279 | mvpp2_prs_hw_write(priv, &pe); | |
3280 | ||
3281 | /* Default IPv6 entry for unicast address */ | |
3282 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); | |
3283 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6); | |
3284 | pe.index = MVPP2_PE_IP6_ADDR_UN; | |
3285 | ||
3286 | /* Finished: go to IPv6 again */ | |
3287 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6); | |
3288 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UCAST, | |
3289 | MVPP2_PRS_RI_L3_ADDR_MASK); | |
3290 | mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT, | |
3291 | MVPP2_PRS_IPV6_NO_EXT_AI_BIT); | |
3292 | /* Shift back to IPV6 NH */ | |
3293 | mvpp2_prs_sram_shift_set(&pe, -18, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
3294 | ||
3295 | mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV6_NO_EXT_AI_BIT); | |
3296 | /* Unmask all ports */ | |
3297 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); | |
3298 | ||
3299 | /* Update shadow table and hw entry */ | |
3300 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP6); | |
3301 | mvpp2_prs_hw_write(priv, &pe); | |
3302 | ||
3303 | return 0; | |
3304 | } | |
3305 | ||
3306 | /* Parser default initialization */ | |
3307 | static int mvpp2_prs_default_init(struct platform_device *pdev, | |
3308 | struct mvpp2 *priv) | |
3309 | { | |
3310 | int err, index, i; | |
3311 | ||
3312 | /* Enable tcam table */ | |
3313 | mvpp2_write(priv, MVPP2_PRS_TCAM_CTRL_REG, MVPP2_PRS_TCAM_EN_MASK); | |
3314 | ||
3315 | /* Clear all tcam and sram entries */ | |
3316 | for (index = 0; index < MVPP2_PRS_TCAM_SRAM_SIZE; index++) { | |
3317 | mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, index); | |
3318 | for (i = 0; i < MVPP2_PRS_TCAM_WORDS; i++) | |
3319 | mvpp2_write(priv, MVPP2_PRS_TCAM_DATA_REG(i), 0); | |
3320 | ||
3321 | mvpp2_write(priv, MVPP2_PRS_SRAM_IDX_REG, index); | |
3322 | for (i = 0; i < MVPP2_PRS_SRAM_WORDS; i++) | |
3323 | mvpp2_write(priv, MVPP2_PRS_SRAM_DATA_REG(i), 0); | |
3324 | } | |
3325 | ||
3326 | /* Invalidate all tcam entries */ | |
3327 | for (index = 0; index < MVPP2_PRS_TCAM_SRAM_SIZE; index++) | |
3328 | mvpp2_prs_hw_inv(priv, index); | |
3329 | ||
3330 | priv->prs_shadow = devm_kcalloc(&pdev->dev, MVPP2_PRS_TCAM_SRAM_SIZE, | |
37df25e8 | 3331 | sizeof(*priv->prs_shadow), |
3f518509 MW |
3332 | GFP_KERNEL); |
3333 | if (!priv->prs_shadow) | |
3334 | return -ENOMEM; | |
3335 | ||
3336 | /* Always start from lookup = 0 */ | |
3337 | for (index = 0; index < MVPP2_MAX_PORTS; index++) | |
3338 | mvpp2_prs_hw_port_init(priv, index, MVPP2_PRS_LU_MH, | |
3339 | MVPP2_PRS_PORT_LU_MAX, 0); | |
3340 | ||
3341 | mvpp2_prs_def_flow_init(priv); | |
3342 | ||
3343 | mvpp2_prs_mh_init(priv); | |
3344 | ||
3345 | mvpp2_prs_mac_init(priv); | |
3346 | ||
3347 | mvpp2_prs_dsa_init(priv); | |
3348 | ||
3349 | err = mvpp2_prs_etype_init(priv); | |
3350 | if (err) | |
3351 | return err; | |
3352 | ||
3353 | err = mvpp2_prs_vlan_init(pdev, priv); | |
3354 | if (err) | |
3355 | return err; | |
3356 | ||
3357 | err = mvpp2_prs_pppoe_init(priv); | |
3358 | if (err) | |
3359 | return err; | |
3360 | ||
3361 | err = mvpp2_prs_ip6_init(priv); | |
3362 | if (err) | |
3363 | return err; | |
3364 | ||
3365 | err = mvpp2_prs_ip4_init(priv); | |
3366 | if (err) | |
3367 | return err; | |
3368 | ||
3369 | return 0; | |
3370 | } | |
3371 | ||
3372 | /* Compare MAC DA with tcam entry data */ | |
3373 | static bool mvpp2_prs_mac_range_equals(struct mvpp2_prs_entry *pe, | |
3374 | const u8 *da, unsigned char *mask) | |
3375 | { | |
3376 | unsigned char tcam_byte, tcam_mask; | |
3377 | int index; | |
3378 | ||
3379 | for (index = 0; index < ETH_ALEN; index++) { | |
3380 | mvpp2_prs_tcam_data_byte_get(pe, index, &tcam_byte, &tcam_mask); | |
3381 | if (tcam_mask != mask[index]) | |
3382 | return false; | |
3383 | ||
3384 | if ((tcam_mask & tcam_byte) != (da[index] & mask[index])) | |
3385 | return false; | |
3386 | } | |
3387 | ||
3388 | return true; | |
3389 | } | |
3390 | ||
3391 | /* Find tcam entry with matched pair <MAC DA, port> */ | |
3392 | static struct mvpp2_prs_entry * | |
3393 | mvpp2_prs_mac_da_range_find(struct mvpp2 *priv, int pmap, const u8 *da, | |
3394 | unsigned char *mask, int udf_type) | |
3395 | { | |
3396 | struct mvpp2_prs_entry *pe; | |
3397 | int tid; | |
3398 | ||
239dd4ee | 3399 | pe = kzalloc(sizeof(*pe), GFP_ATOMIC); |
3f518509 MW |
3400 | if (!pe) |
3401 | return NULL; | |
3402 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_MAC); | |
3403 | ||
3404 | /* Go through the all entires with MVPP2_PRS_LU_MAC */ | |
3405 | for (tid = MVPP2_PE_FIRST_FREE_TID; | |
3406 | tid <= MVPP2_PE_LAST_FREE_TID; tid++) { | |
3407 | unsigned int entry_pmap; | |
3408 | ||
3409 | if (!priv->prs_shadow[tid].valid || | |
3410 | (priv->prs_shadow[tid].lu != MVPP2_PRS_LU_MAC) || | |
3411 | (priv->prs_shadow[tid].udf != udf_type)) | |
3412 | continue; | |
3413 | ||
3414 | pe->index = tid; | |
3415 | mvpp2_prs_hw_read(priv, pe); | |
3416 | entry_pmap = mvpp2_prs_tcam_port_map_get(pe); | |
3417 | ||
3418 | if (mvpp2_prs_mac_range_equals(pe, da, mask) && | |
3419 | entry_pmap == pmap) | |
3420 | return pe; | |
3421 | } | |
3422 | kfree(pe); | |
3423 | ||
3424 | return NULL; | |
3425 | } | |
3426 | ||
3427 | /* Update parser's mac da entry */ | |
3428 | static int mvpp2_prs_mac_da_accept(struct mvpp2 *priv, int port, | |
3429 | const u8 *da, bool add) | |
3430 | { | |
3431 | struct mvpp2_prs_entry *pe; | |
3432 | unsigned int pmap, len, ri; | |
3433 | unsigned char mask[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
3434 | int tid; | |
3435 | ||
3436 | /* Scan TCAM and see if entry with this <MAC DA, port> already exist */ | |
3437 | pe = mvpp2_prs_mac_da_range_find(priv, (1 << port), da, mask, | |
3438 | MVPP2_PRS_UDF_MAC_DEF); | |
3439 | ||
3440 | /* No such entry */ | |
3441 | if (!pe) { | |
3442 | if (!add) | |
3443 | return 0; | |
3444 | ||
3445 | /* Create new TCAM entry */ | |
3446 | /* Find first range mac entry*/ | |
3447 | for (tid = MVPP2_PE_FIRST_FREE_TID; | |
3448 | tid <= MVPP2_PE_LAST_FREE_TID; tid++) | |
3449 | if (priv->prs_shadow[tid].valid && | |
3450 | (priv->prs_shadow[tid].lu == MVPP2_PRS_LU_MAC) && | |
3451 | (priv->prs_shadow[tid].udf == | |
3452 | MVPP2_PRS_UDF_MAC_RANGE)) | |
3453 | break; | |
3454 | ||
3455 | /* Go through the all entries from first to last */ | |
3456 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, | |
3457 | tid - 1); | |
3458 | if (tid < 0) | |
3459 | return tid; | |
3460 | ||
239dd4ee | 3461 | pe = kzalloc(sizeof(*pe), GFP_ATOMIC); |
3f518509 | 3462 | if (!pe) |
c2bb7bc5 | 3463 | return -ENOMEM; |
3f518509 MW |
3464 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_MAC); |
3465 | pe->index = tid; | |
3466 | ||
3467 | /* Mask all ports */ | |
3468 | mvpp2_prs_tcam_port_map_set(pe, 0); | |
3469 | } | |
3470 | ||
3471 | /* Update port mask */ | |
3472 | mvpp2_prs_tcam_port_set(pe, port, add); | |
3473 | ||
3474 | /* Invalidate the entry if no ports are left enabled */ | |
3475 | pmap = mvpp2_prs_tcam_port_map_get(pe); | |
3476 | if (pmap == 0) { | |
3477 | if (add) { | |
3478 | kfree(pe); | |
c2bb7bc5 | 3479 | return -EINVAL; |
3f518509 MW |
3480 | } |
3481 | mvpp2_prs_hw_inv(priv, pe->index); | |
3482 | priv->prs_shadow[pe->index].valid = false; | |
3483 | kfree(pe); | |
3484 | return 0; | |
3485 | } | |
3486 | ||
3487 | /* Continue - set next lookup */ | |
3488 | mvpp2_prs_sram_next_lu_set(pe, MVPP2_PRS_LU_DSA); | |
3489 | ||
3490 | /* Set match on DA */ | |
3491 | len = ETH_ALEN; | |
3492 | while (len--) | |
3493 | mvpp2_prs_tcam_data_byte_set(pe, len, da[len], 0xff); | |
3494 | ||
3495 | /* Set result info bits */ | |
3496 | if (is_broadcast_ether_addr(da)) | |
3497 | ri = MVPP2_PRS_RI_L2_BCAST; | |
3498 | else if (is_multicast_ether_addr(da)) | |
3499 | ri = MVPP2_PRS_RI_L2_MCAST; | |
3500 | else | |
3501 | ri = MVPP2_PRS_RI_L2_UCAST | MVPP2_PRS_RI_MAC_ME_MASK; | |
3502 | ||
3503 | mvpp2_prs_sram_ri_update(pe, ri, MVPP2_PRS_RI_L2_CAST_MASK | | |
3504 | MVPP2_PRS_RI_MAC_ME_MASK); | |
3505 | mvpp2_prs_shadow_ri_set(priv, pe->index, ri, MVPP2_PRS_RI_L2_CAST_MASK | | |
3506 | MVPP2_PRS_RI_MAC_ME_MASK); | |
3507 | ||
3508 | /* Shift to ethertype */ | |
3509 | mvpp2_prs_sram_shift_set(pe, 2 * ETH_ALEN, | |
3510 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); | |
3511 | ||
3512 | /* Update shadow table and hw entry */ | |
3513 | priv->prs_shadow[pe->index].udf = MVPP2_PRS_UDF_MAC_DEF; | |
3514 | mvpp2_prs_shadow_set(priv, pe->index, MVPP2_PRS_LU_MAC); | |
3515 | mvpp2_prs_hw_write(priv, pe); | |
3516 | ||
3517 | kfree(pe); | |
3518 | ||
3519 | return 0; | |
3520 | } | |
3521 | ||
3522 | static int mvpp2_prs_update_mac_da(struct net_device *dev, const u8 *da) | |
3523 | { | |
3524 | struct mvpp2_port *port = netdev_priv(dev); | |
3525 | int err; | |
3526 | ||
3527 | /* Remove old parser entry */ | |
3528 | err = mvpp2_prs_mac_da_accept(port->priv, port->id, dev->dev_addr, | |
3529 | false); | |
3530 | if (err) | |
3531 | return err; | |
3532 | ||
3533 | /* Add new parser entry */ | |
3534 | err = mvpp2_prs_mac_da_accept(port->priv, port->id, da, true); | |
3535 | if (err) | |
3536 | return err; | |
3537 | ||
3538 | /* Set addr in the device */ | |
3539 | ether_addr_copy(dev->dev_addr, da); | |
3540 | ||
3541 | return 0; | |
3542 | } | |
3543 | ||
3544 | /* Delete all port's multicast simple (not range) entries */ | |
3545 | static void mvpp2_prs_mcast_del_all(struct mvpp2 *priv, int port) | |
3546 | { | |
3547 | struct mvpp2_prs_entry pe; | |
3548 | int index, tid; | |
3549 | ||
3550 | for (tid = MVPP2_PE_FIRST_FREE_TID; | |
3551 | tid <= MVPP2_PE_LAST_FREE_TID; tid++) { | |
3552 | unsigned char da[ETH_ALEN], da_mask[ETH_ALEN]; | |
3553 | ||
3554 | if (!priv->prs_shadow[tid].valid || | |
3555 | (priv->prs_shadow[tid].lu != MVPP2_PRS_LU_MAC) || | |
3556 | (priv->prs_shadow[tid].udf != MVPP2_PRS_UDF_MAC_DEF)) | |
3557 | continue; | |
3558 | ||
3559 | /* Only simple mac entries */ | |
3560 | pe.index = tid; | |
3561 | mvpp2_prs_hw_read(priv, &pe); | |
3562 | ||
3563 | /* Read mac addr from entry */ | |
3564 | for (index = 0; index < ETH_ALEN; index++) | |
3565 | mvpp2_prs_tcam_data_byte_get(&pe, index, &da[index], | |
3566 | &da_mask[index]); | |
3567 | ||
3568 | if (is_multicast_ether_addr(da) && !is_broadcast_ether_addr(da)) | |
3569 | /* Delete this entry */ | |
3570 | mvpp2_prs_mac_da_accept(priv, port, da, false); | |
3571 | } | |
3572 | } | |
3573 | ||
3574 | static int mvpp2_prs_tag_mode_set(struct mvpp2 *priv, int port, int type) | |
3575 | { | |
3576 | switch (type) { | |
3577 | case MVPP2_TAG_TYPE_EDSA: | |
3578 | /* Add port to EDSA entries */ | |
3579 | mvpp2_prs_dsa_tag_set(priv, port, true, | |
3580 | MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA); | |
3581 | mvpp2_prs_dsa_tag_set(priv, port, true, | |
3582 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA); | |
3583 | /* Remove port from DSA entries */ | |
3584 | mvpp2_prs_dsa_tag_set(priv, port, false, | |
3585 | MVPP2_PRS_TAGGED, MVPP2_PRS_DSA); | |
3586 | mvpp2_prs_dsa_tag_set(priv, port, false, | |
3587 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA); | |
3588 | break; | |
3589 | ||
3590 | case MVPP2_TAG_TYPE_DSA: | |
3591 | /* Add port to DSA entries */ | |
3592 | mvpp2_prs_dsa_tag_set(priv, port, true, | |
3593 | MVPP2_PRS_TAGGED, MVPP2_PRS_DSA); | |
3594 | mvpp2_prs_dsa_tag_set(priv, port, true, | |
3595 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA); | |
3596 | /* Remove port from EDSA entries */ | |
3597 | mvpp2_prs_dsa_tag_set(priv, port, false, | |
3598 | MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA); | |
3599 | mvpp2_prs_dsa_tag_set(priv, port, false, | |
3600 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA); | |
3601 | break; | |
3602 | ||
3603 | case MVPP2_TAG_TYPE_MH: | |
3604 | case MVPP2_TAG_TYPE_NONE: | |
3605 | /* Remove port form EDSA and DSA entries */ | |
3606 | mvpp2_prs_dsa_tag_set(priv, port, false, | |
3607 | MVPP2_PRS_TAGGED, MVPP2_PRS_DSA); | |
3608 | mvpp2_prs_dsa_tag_set(priv, port, false, | |
3609 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA); | |
3610 | mvpp2_prs_dsa_tag_set(priv, port, false, | |
3611 | MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA); | |
3612 | mvpp2_prs_dsa_tag_set(priv, port, false, | |
3613 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA); | |
3614 | break; | |
3615 | ||
3616 | default: | |
3617 | if ((type < 0) || (type > MVPP2_TAG_TYPE_EDSA)) | |
3618 | return -EINVAL; | |
3619 | } | |
3620 | ||
3621 | return 0; | |
3622 | } | |
3623 | ||
3624 | /* Set prs flow for the port */ | |
3625 | static int mvpp2_prs_def_flow(struct mvpp2_port *port) | |
3626 | { | |
3627 | struct mvpp2_prs_entry *pe; | |
3628 | int tid; | |
3629 | ||
3630 | pe = mvpp2_prs_flow_find(port->priv, port->id); | |
3631 | ||
3632 | /* Such entry not exist */ | |
3633 | if (!pe) { | |
3634 | /* Go through the all entires from last to first */ | |
3635 | tid = mvpp2_prs_tcam_first_free(port->priv, | |
3636 | MVPP2_PE_LAST_FREE_TID, | |
3637 | MVPP2_PE_FIRST_FREE_TID); | |
3638 | if (tid < 0) | |
3639 | return tid; | |
3640 | ||
3641 | pe = kzalloc(sizeof(*pe), GFP_KERNEL); | |
3642 | if (!pe) | |
3643 | return -ENOMEM; | |
3644 | ||
3645 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_FLOWS); | |
3646 | pe->index = tid; | |
3647 | ||
3648 | /* Set flow ID*/ | |
3649 | mvpp2_prs_sram_ai_update(pe, port->id, MVPP2_PRS_FLOW_ID_MASK); | |
3650 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_LU_DONE_BIT, 1); | |
3651 | ||
3652 | /* Update shadow table */ | |
3653 | mvpp2_prs_shadow_set(port->priv, pe->index, MVPP2_PRS_LU_FLOWS); | |
3654 | } | |
3655 | ||
3656 | mvpp2_prs_tcam_port_map_set(pe, (1 << port->id)); | |
3657 | mvpp2_prs_hw_write(port->priv, pe); | |
3658 | kfree(pe); | |
3659 | ||
3660 | return 0; | |
3661 | } | |
3662 | ||
3663 | /* Classifier configuration routines */ | |
3664 | ||
3665 | /* Update classification flow table registers */ | |
3666 | static void mvpp2_cls_flow_write(struct mvpp2 *priv, | |
3667 | struct mvpp2_cls_flow_entry *fe) | |
3668 | { | |
3669 | mvpp2_write(priv, MVPP2_CLS_FLOW_INDEX_REG, fe->index); | |
3670 | mvpp2_write(priv, MVPP2_CLS_FLOW_TBL0_REG, fe->data[0]); | |
3671 | mvpp2_write(priv, MVPP2_CLS_FLOW_TBL1_REG, fe->data[1]); | |
3672 | mvpp2_write(priv, MVPP2_CLS_FLOW_TBL2_REG, fe->data[2]); | |
3673 | } | |
3674 | ||
3675 | /* Update classification lookup table register */ | |
3676 | static void mvpp2_cls_lookup_write(struct mvpp2 *priv, | |
3677 | struct mvpp2_cls_lookup_entry *le) | |
3678 | { | |
3679 | u32 val; | |
3680 | ||
3681 | val = (le->way << MVPP2_CLS_LKP_INDEX_WAY_OFFS) | le->lkpid; | |
3682 | mvpp2_write(priv, MVPP2_CLS_LKP_INDEX_REG, val); | |
3683 | mvpp2_write(priv, MVPP2_CLS_LKP_TBL_REG, le->data); | |
3684 | } | |
3685 | ||
3686 | /* Classifier default initialization */ | |
3687 | static void mvpp2_cls_init(struct mvpp2 *priv) | |
3688 | { | |
3689 | struct mvpp2_cls_lookup_entry le; | |
3690 | struct mvpp2_cls_flow_entry fe; | |
3691 | int index; | |
3692 | ||
3693 | /* Enable classifier */ | |
3694 | mvpp2_write(priv, MVPP2_CLS_MODE_REG, MVPP2_CLS_MODE_ACTIVE_MASK); | |
3695 | ||
3696 | /* Clear classifier flow table */ | |
e8f967c3 | 3697 | memset(&fe.data, 0, sizeof(fe.data)); |
3f518509 MW |
3698 | for (index = 0; index < MVPP2_CLS_FLOWS_TBL_SIZE; index++) { |
3699 | fe.index = index; | |
3700 | mvpp2_cls_flow_write(priv, &fe); | |
3701 | } | |
3702 | ||
3703 | /* Clear classifier lookup table */ | |
3704 | le.data = 0; | |
3705 | for (index = 0; index < MVPP2_CLS_LKP_TBL_SIZE; index++) { | |
3706 | le.lkpid = index; | |
3707 | le.way = 0; | |
3708 | mvpp2_cls_lookup_write(priv, &le); | |
3709 | ||
3710 | le.way = 1; | |
3711 | mvpp2_cls_lookup_write(priv, &le); | |
3712 | } | |
3713 | } | |
3714 | ||
3715 | static void mvpp2_cls_port_config(struct mvpp2_port *port) | |
3716 | { | |
3717 | struct mvpp2_cls_lookup_entry le; | |
3718 | u32 val; | |
3719 | ||
3720 | /* Set way for the port */ | |
3721 | val = mvpp2_read(port->priv, MVPP2_CLS_PORT_WAY_REG); | |
3722 | val &= ~MVPP2_CLS_PORT_WAY_MASK(port->id); | |
3723 | mvpp2_write(port->priv, MVPP2_CLS_PORT_WAY_REG, val); | |
3724 | ||
3725 | /* Pick the entry to be accessed in lookup ID decoding table | |
3726 | * according to the way and lkpid. | |
3727 | */ | |
3728 | le.lkpid = port->id; | |
3729 | le.way = 0; | |
3730 | le.data = 0; | |
3731 | ||
3732 | /* Set initial CPU queue for receiving packets */ | |
3733 | le.data &= ~MVPP2_CLS_LKP_TBL_RXQ_MASK; | |
3734 | le.data |= port->first_rxq; | |
3735 | ||
3736 | /* Disable classification engines */ | |
3737 | le.data &= ~MVPP2_CLS_LKP_TBL_LOOKUP_EN_MASK; | |
3738 | ||
3739 | /* Update lookup ID table entry */ | |
3740 | mvpp2_cls_lookup_write(port->priv, &le); | |
3741 | } | |
3742 | ||
3743 | /* Set CPU queue number for oversize packets */ | |
3744 | static void mvpp2_cls_oversize_rxq_set(struct mvpp2_port *port) | |
3745 | { | |
3746 | u32 val; | |
3747 | ||
3748 | mvpp2_write(port->priv, MVPP2_CLS_OVERSIZE_RXQ_LOW_REG(port->id), | |
3749 | port->first_rxq & MVPP2_CLS_OVERSIZE_RXQ_LOW_MASK); | |
3750 | ||
3751 | mvpp2_write(port->priv, MVPP2_CLS_SWFWD_P2HQ_REG(port->id), | |
3752 | (port->first_rxq >> MVPP2_CLS_OVERSIZE_RXQ_LOW_BITS)); | |
3753 | ||
3754 | val = mvpp2_read(port->priv, MVPP2_CLS_SWFWD_PCTRL_REG); | |
3755 | val |= MVPP2_CLS_SWFWD_PCTRL_MASK(port->id); | |
3756 | mvpp2_write(port->priv, MVPP2_CLS_SWFWD_PCTRL_REG, val); | |
3757 | } | |
3758 | ||
0e037281 TP |
3759 | static void *mvpp2_frag_alloc(const struct mvpp2_bm_pool *pool) |
3760 | { | |
3761 | if (likely(pool->frag_size <= PAGE_SIZE)) | |
3762 | return netdev_alloc_frag(pool->frag_size); | |
3763 | else | |
3764 | return kmalloc(pool->frag_size, GFP_ATOMIC); | |
3765 | } | |
3766 | ||
3767 | static void mvpp2_frag_free(const struct mvpp2_bm_pool *pool, void *data) | |
3768 | { | |
3769 | if (likely(pool->frag_size <= PAGE_SIZE)) | |
3770 | skb_free_frag(data); | |
3771 | else | |
3772 | kfree(data); | |
3773 | } | |
3774 | ||
3f518509 MW |
3775 | /* Buffer Manager configuration routines */ |
3776 | ||
3777 | /* Create pool */ | |
3778 | static int mvpp2_bm_pool_create(struct platform_device *pdev, | |
3779 | struct mvpp2 *priv, | |
3780 | struct mvpp2_bm_pool *bm_pool, int size) | |
3781 | { | |
3f518509 MW |
3782 | u32 val; |
3783 | ||
d01524d8 TP |
3784 | /* Number of buffer pointers must be a multiple of 16, as per |
3785 | * hardware constraints | |
3786 | */ | |
3787 | if (!IS_ALIGNED(size, 16)) | |
3788 | return -EINVAL; | |
3789 | ||
3790 | /* PPv2.1 needs 8 bytes per buffer pointer, PPv2.2 needs 16 | |
3791 | * bytes per buffer pointer | |
3792 | */ | |
3793 | if (priv->hw_version == MVPP21) | |
3794 | bm_pool->size_bytes = 2 * sizeof(u32) * size; | |
3795 | else | |
3796 | bm_pool->size_bytes = 2 * sizeof(u64) * size; | |
3797 | ||
3798 | bm_pool->virt_addr = dma_alloc_coherent(&pdev->dev, bm_pool->size_bytes, | |
20396136 | 3799 | &bm_pool->dma_addr, |
3f518509 MW |
3800 | GFP_KERNEL); |
3801 | if (!bm_pool->virt_addr) | |
3802 | return -ENOMEM; | |
3803 | ||
d3158807 TP |
3804 | if (!IS_ALIGNED((unsigned long)bm_pool->virt_addr, |
3805 | MVPP2_BM_POOL_PTR_ALIGN)) { | |
d01524d8 TP |
3806 | dma_free_coherent(&pdev->dev, bm_pool->size_bytes, |
3807 | bm_pool->virt_addr, bm_pool->dma_addr); | |
3f518509 MW |
3808 | dev_err(&pdev->dev, "BM pool %d is not %d bytes aligned\n", |
3809 | bm_pool->id, MVPP2_BM_POOL_PTR_ALIGN); | |
3810 | return -ENOMEM; | |
3811 | } | |
3812 | ||
3813 | mvpp2_write(priv, MVPP2_BM_POOL_BASE_REG(bm_pool->id), | |
d01524d8 | 3814 | lower_32_bits(bm_pool->dma_addr)); |
3f518509 MW |
3815 | mvpp2_write(priv, MVPP2_BM_POOL_SIZE_REG(bm_pool->id), size); |
3816 | ||
3817 | val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id)); | |
3818 | val |= MVPP2_BM_START_MASK; | |
3819 | mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val); | |
3820 | ||
3821 | bm_pool->type = MVPP2_BM_FREE; | |
3822 | bm_pool->size = size; | |
3823 | bm_pool->pkt_size = 0; | |
3824 | bm_pool->buf_num = 0; | |
3f518509 MW |
3825 | |
3826 | return 0; | |
3827 | } | |
3828 | ||
3829 | /* Set pool buffer size */ | |
3830 | static void mvpp2_bm_pool_bufsize_set(struct mvpp2 *priv, | |
3831 | struct mvpp2_bm_pool *bm_pool, | |
3832 | int buf_size) | |
3833 | { | |
3834 | u32 val; | |
3835 | ||
3836 | bm_pool->buf_size = buf_size; | |
3837 | ||
3838 | val = ALIGN(buf_size, 1 << MVPP2_POOL_BUF_SIZE_OFFSET); | |
3839 | mvpp2_write(priv, MVPP2_POOL_BUF_SIZE_REG(bm_pool->id), val); | |
3840 | } | |
3841 | ||
d01524d8 TP |
3842 | static void mvpp2_bm_bufs_get_addrs(struct device *dev, struct mvpp2 *priv, |
3843 | struct mvpp2_bm_pool *bm_pool, | |
3844 | dma_addr_t *dma_addr, | |
3845 | phys_addr_t *phys_addr) | |
3846 | { | |
a704bb5c | 3847 | int cpu = get_cpu(); |
a786841d TP |
3848 | |
3849 | *dma_addr = mvpp2_percpu_read(priv, cpu, | |
3850 | MVPP2_BM_PHY_ALLOC_REG(bm_pool->id)); | |
3851 | *phys_addr = mvpp2_percpu_read(priv, cpu, MVPP2_BM_VIRT_ALLOC_REG); | |
d01524d8 TP |
3852 | |
3853 | if (priv->hw_version == MVPP22) { | |
3854 | u32 val; | |
3855 | u32 dma_addr_highbits, phys_addr_highbits; | |
3856 | ||
a786841d | 3857 | val = mvpp2_percpu_read(priv, cpu, MVPP22_BM_ADDR_HIGH_ALLOC); |
d01524d8 TP |
3858 | dma_addr_highbits = (val & MVPP22_BM_ADDR_HIGH_PHYS_MASK); |
3859 | phys_addr_highbits = (val & MVPP22_BM_ADDR_HIGH_VIRT_MASK) >> | |
3860 | MVPP22_BM_ADDR_HIGH_VIRT_SHIFT; | |
3861 | ||
3862 | if (sizeof(dma_addr_t) == 8) | |
3863 | *dma_addr |= (u64)dma_addr_highbits << 32; | |
3864 | ||
3865 | if (sizeof(phys_addr_t) == 8) | |
3866 | *phys_addr |= (u64)phys_addr_highbits << 32; | |
3867 | } | |
a704bb5c TP |
3868 | |
3869 | put_cpu(); | |
d01524d8 TP |
3870 | } |
3871 | ||
7861f12b | 3872 | /* Free all buffers from the pool */ |
4229d502 MW |
3873 | static void mvpp2_bm_bufs_free(struct device *dev, struct mvpp2 *priv, |
3874 | struct mvpp2_bm_pool *bm_pool) | |
3f518509 MW |
3875 | { |
3876 | int i; | |
3877 | ||
7861f12b | 3878 | for (i = 0; i < bm_pool->buf_num; i++) { |
20396136 | 3879 | dma_addr_t buf_dma_addr; |
4e4a105f TP |
3880 | phys_addr_t buf_phys_addr; |
3881 | void *data; | |
3f518509 | 3882 | |
d01524d8 TP |
3883 | mvpp2_bm_bufs_get_addrs(dev, priv, bm_pool, |
3884 | &buf_dma_addr, &buf_phys_addr); | |
4229d502 | 3885 | |
20396136 | 3886 | dma_unmap_single(dev, buf_dma_addr, |
4229d502 MW |
3887 | bm_pool->buf_size, DMA_FROM_DEVICE); |
3888 | ||
4e4a105f TP |
3889 | data = (void *)phys_to_virt(buf_phys_addr); |
3890 | if (!data) | |
3f518509 | 3891 | break; |
0e037281 | 3892 | |
4e4a105f | 3893 | mvpp2_frag_free(bm_pool, data); |
3f518509 MW |
3894 | } |
3895 | ||
3896 | /* Update BM driver with number of buffers removed from pool */ | |
3897 | bm_pool->buf_num -= i; | |
3f518509 MW |
3898 | } |
3899 | ||
3900 | /* Cleanup pool */ | |
3901 | static int mvpp2_bm_pool_destroy(struct platform_device *pdev, | |
3902 | struct mvpp2 *priv, | |
3903 | struct mvpp2_bm_pool *bm_pool) | |
3904 | { | |
3f518509 MW |
3905 | u32 val; |
3906 | ||
4229d502 | 3907 | mvpp2_bm_bufs_free(&pdev->dev, priv, bm_pool); |
d74c96c1 | 3908 | if (bm_pool->buf_num) { |
3f518509 MW |
3909 | WARN(1, "cannot free all buffers in pool %d\n", bm_pool->id); |
3910 | return 0; | |
3911 | } | |
3912 | ||
3913 | val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id)); | |
3914 | val |= MVPP2_BM_STOP_MASK; | |
3915 | mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val); | |
3916 | ||
d01524d8 | 3917 | dma_free_coherent(&pdev->dev, bm_pool->size_bytes, |
3f518509 | 3918 | bm_pool->virt_addr, |
20396136 | 3919 | bm_pool->dma_addr); |
3f518509 MW |
3920 | return 0; |
3921 | } | |
3922 | ||
3923 | static int mvpp2_bm_pools_init(struct platform_device *pdev, | |
3924 | struct mvpp2 *priv) | |
3925 | { | |
3926 | int i, err, size; | |
3927 | struct mvpp2_bm_pool *bm_pool; | |
3928 | ||
3929 | /* Create all pools with maximum size */ | |
3930 | size = MVPP2_BM_POOL_SIZE_MAX; | |
3931 | for (i = 0; i < MVPP2_BM_POOLS_NUM; i++) { | |
3932 | bm_pool = &priv->bm_pools[i]; | |
3933 | bm_pool->id = i; | |
3934 | err = mvpp2_bm_pool_create(pdev, priv, bm_pool, size); | |
3935 | if (err) | |
3936 | goto err_unroll_pools; | |
3937 | mvpp2_bm_pool_bufsize_set(priv, bm_pool, 0); | |
3938 | } | |
3939 | return 0; | |
3940 | ||
3941 | err_unroll_pools: | |
3942 | dev_err(&pdev->dev, "failed to create BM pool %d, size %d\n", i, size); | |
3943 | for (i = i - 1; i >= 0; i--) | |
3944 | mvpp2_bm_pool_destroy(pdev, priv, &priv->bm_pools[i]); | |
3945 | return err; | |
3946 | } | |
3947 | ||
3948 | static int mvpp2_bm_init(struct platform_device *pdev, struct mvpp2 *priv) | |
3949 | { | |
3950 | int i, err; | |
3951 | ||
3952 | for (i = 0; i < MVPP2_BM_POOLS_NUM; i++) { | |
3953 | /* Mask BM all interrupts */ | |
3954 | mvpp2_write(priv, MVPP2_BM_INTR_MASK_REG(i), 0); | |
3955 | /* Clear BM cause register */ | |
3956 | mvpp2_write(priv, MVPP2_BM_INTR_CAUSE_REG(i), 0); | |
3957 | } | |
3958 | ||
3959 | /* Allocate and initialize BM pools */ | |
3960 | priv->bm_pools = devm_kcalloc(&pdev->dev, MVPP2_BM_POOLS_NUM, | |
81f915eb | 3961 | sizeof(*priv->bm_pools), GFP_KERNEL); |
3f518509 MW |
3962 | if (!priv->bm_pools) |
3963 | return -ENOMEM; | |
3964 | ||
3965 | err = mvpp2_bm_pools_init(pdev, priv); | |
3966 | if (err < 0) | |
3967 | return err; | |
3968 | return 0; | |
3969 | } | |
3970 | ||
3971 | /* Attach long pool to rxq */ | |
3972 | static void mvpp2_rxq_long_pool_set(struct mvpp2_port *port, | |
3973 | int lrxq, int long_pool) | |
3974 | { | |
5eac892a | 3975 | u32 val, mask; |
3f518509 MW |
3976 | int prxq; |
3977 | ||
3978 | /* Get queue physical ID */ | |
3979 | prxq = port->rxqs[lrxq]->id; | |
3980 | ||
5eac892a TP |
3981 | if (port->priv->hw_version == MVPP21) |
3982 | mask = MVPP21_RXQ_POOL_LONG_MASK; | |
3983 | else | |
3984 | mask = MVPP22_RXQ_POOL_LONG_MASK; | |
3f518509 | 3985 | |
5eac892a TP |
3986 | val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(prxq)); |
3987 | val &= ~mask; | |
3988 | val |= (long_pool << MVPP2_RXQ_POOL_LONG_OFFS) & mask; | |
3f518509 MW |
3989 | mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(prxq), val); |
3990 | } | |
3991 | ||
3992 | /* Attach short pool to rxq */ | |
3993 | static void mvpp2_rxq_short_pool_set(struct mvpp2_port *port, | |
3994 | int lrxq, int short_pool) | |
3995 | { | |
5eac892a | 3996 | u32 val, mask; |
3f518509 MW |
3997 | int prxq; |
3998 | ||
3999 | /* Get queue physical ID */ | |
4000 | prxq = port->rxqs[lrxq]->id; | |
4001 | ||
5eac892a TP |
4002 | if (port->priv->hw_version == MVPP21) |
4003 | mask = MVPP21_RXQ_POOL_SHORT_MASK; | |
4004 | else | |
4005 | mask = MVPP22_RXQ_POOL_SHORT_MASK; | |
3f518509 | 4006 | |
5eac892a TP |
4007 | val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(prxq)); |
4008 | val &= ~mask; | |
4009 | val |= (short_pool << MVPP2_RXQ_POOL_SHORT_OFFS) & mask; | |
3f518509 MW |
4010 | mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(prxq), val); |
4011 | } | |
4012 | ||
0e037281 TP |
4013 | static void *mvpp2_buf_alloc(struct mvpp2_port *port, |
4014 | struct mvpp2_bm_pool *bm_pool, | |
20396136 | 4015 | dma_addr_t *buf_dma_addr, |
4e4a105f | 4016 | phys_addr_t *buf_phys_addr, |
0e037281 | 4017 | gfp_t gfp_mask) |
3f518509 | 4018 | { |
20396136 | 4019 | dma_addr_t dma_addr; |
0e037281 | 4020 | void *data; |
3f518509 | 4021 | |
0e037281 TP |
4022 | data = mvpp2_frag_alloc(bm_pool); |
4023 | if (!data) | |
3f518509 MW |
4024 | return NULL; |
4025 | ||
20396136 TP |
4026 | dma_addr = dma_map_single(port->dev->dev.parent, data, |
4027 | MVPP2_RX_BUF_SIZE(bm_pool->pkt_size), | |
4028 | DMA_FROM_DEVICE); | |
4029 | if (unlikely(dma_mapping_error(port->dev->dev.parent, dma_addr))) { | |
0e037281 | 4030 | mvpp2_frag_free(bm_pool, data); |
3f518509 MW |
4031 | return NULL; |
4032 | } | |
20396136 | 4033 | *buf_dma_addr = dma_addr; |
4e4a105f | 4034 | *buf_phys_addr = virt_to_phys(data); |
3f518509 | 4035 | |
0e037281 | 4036 | return data; |
3f518509 MW |
4037 | } |
4038 | ||
3f518509 MW |
4039 | /* Release buffer to BM */ |
4040 | static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool, | |
20396136 | 4041 | dma_addr_t buf_dma_addr, |
4e4a105f | 4042 | phys_addr_t buf_phys_addr) |
3f518509 | 4043 | { |
a704bb5c | 4044 | int cpu = get_cpu(); |
a786841d | 4045 | |
d01524d8 TP |
4046 | if (port->priv->hw_version == MVPP22) { |
4047 | u32 val = 0; | |
4048 | ||
4049 | if (sizeof(dma_addr_t) == 8) | |
4050 | val |= upper_32_bits(buf_dma_addr) & | |
4051 | MVPP22_BM_ADDR_HIGH_PHYS_RLS_MASK; | |
4052 | ||
4053 | if (sizeof(phys_addr_t) == 8) | |
4054 | val |= (upper_32_bits(buf_phys_addr) | |
4055 | << MVPP22_BM_ADDR_HIGH_VIRT_RLS_SHIFT) & | |
4056 | MVPP22_BM_ADDR_HIGH_VIRT_RLS_MASK; | |
4057 | ||
a786841d TP |
4058 | mvpp2_percpu_write(port->priv, cpu, |
4059 | MVPP22_BM_ADDR_HIGH_RLS_REG, val); | |
d01524d8 TP |
4060 | } |
4061 | ||
4e4a105f TP |
4062 | /* MVPP2_BM_VIRT_RLS_REG is not interpreted by HW, and simply |
4063 | * returned in the "cookie" field of the RX | |
4064 | * descriptor. Instead of storing the virtual address, we | |
4065 | * store the physical address | |
4066 | */ | |
a786841d TP |
4067 | mvpp2_percpu_write(port->priv, cpu, |
4068 | MVPP2_BM_VIRT_RLS_REG, buf_phys_addr); | |
4069 | mvpp2_percpu_write(port->priv, cpu, | |
4070 | MVPP2_BM_PHY_RLS_REG(pool), buf_dma_addr); | |
a704bb5c TP |
4071 | |
4072 | put_cpu(); | |
3f518509 MW |
4073 | } |
4074 | ||
3f518509 MW |
4075 | /* Allocate buffers for the pool */ |
4076 | static int mvpp2_bm_bufs_add(struct mvpp2_port *port, | |
4077 | struct mvpp2_bm_pool *bm_pool, int buf_num) | |
4078 | { | |
3f518509 | 4079 | int i, buf_size, total_size; |
20396136 | 4080 | dma_addr_t dma_addr; |
4e4a105f | 4081 | phys_addr_t phys_addr; |
0e037281 | 4082 | void *buf; |
3f518509 MW |
4083 | |
4084 | buf_size = MVPP2_RX_BUF_SIZE(bm_pool->pkt_size); | |
4085 | total_size = MVPP2_RX_TOTAL_SIZE(buf_size); | |
4086 | ||
4087 | if (buf_num < 0 || | |
4088 | (buf_num + bm_pool->buf_num > bm_pool->size)) { | |
4089 | netdev_err(port->dev, | |
4090 | "cannot allocate %d buffers for pool %d\n", | |
4091 | buf_num, bm_pool->id); | |
4092 | return 0; | |
4093 | } | |
4094 | ||
3f518509 | 4095 | for (i = 0; i < buf_num; i++) { |
4e4a105f TP |
4096 | buf = mvpp2_buf_alloc(port, bm_pool, &dma_addr, |
4097 | &phys_addr, GFP_KERNEL); | |
0e037281 | 4098 | if (!buf) |
3f518509 MW |
4099 | break; |
4100 | ||
20396136 | 4101 | mvpp2_bm_pool_put(port, bm_pool->id, dma_addr, |
4e4a105f | 4102 | phys_addr); |
3f518509 MW |
4103 | } |
4104 | ||
4105 | /* Update BM driver with number of buffers added to pool */ | |
4106 | bm_pool->buf_num += i; | |
3f518509 MW |
4107 | |
4108 | netdev_dbg(port->dev, | |
4109 | "%s pool %d: pkt_size=%4d, buf_size=%4d, total_size=%4d\n", | |
4110 | bm_pool->type == MVPP2_BM_SWF_SHORT ? "short" : " long", | |
4111 | bm_pool->id, bm_pool->pkt_size, buf_size, total_size); | |
4112 | ||
4113 | netdev_dbg(port->dev, | |
4114 | "%s pool %d: %d of %d buffers added\n", | |
4115 | bm_pool->type == MVPP2_BM_SWF_SHORT ? "short" : " long", | |
4116 | bm_pool->id, i, buf_num); | |
4117 | return i; | |
4118 | } | |
4119 | ||
4120 | /* Notify the driver that BM pool is being used as specific type and return the | |
4121 | * pool pointer on success | |
4122 | */ | |
4123 | static struct mvpp2_bm_pool * | |
4124 | mvpp2_bm_pool_use(struct mvpp2_port *port, int pool, enum mvpp2_bm_type type, | |
4125 | int pkt_size) | |
4126 | { | |
3f518509 MW |
4127 | struct mvpp2_bm_pool *new_pool = &port->priv->bm_pools[pool]; |
4128 | int num; | |
4129 | ||
4130 | if (new_pool->type != MVPP2_BM_FREE && new_pool->type != type) { | |
4131 | netdev_err(port->dev, "mixing pool types is forbidden\n"); | |
4132 | return NULL; | |
4133 | } | |
4134 | ||
3f518509 MW |
4135 | if (new_pool->type == MVPP2_BM_FREE) |
4136 | new_pool->type = type; | |
4137 | ||
4138 | /* Allocate buffers in case BM pool is used as long pool, but packet | |
4139 | * size doesn't match MTU or BM pool hasn't being used yet | |
4140 | */ | |
4141 | if (((type == MVPP2_BM_SWF_LONG) && (pkt_size > new_pool->pkt_size)) || | |
4142 | (new_pool->pkt_size == 0)) { | |
4143 | int pkts_num; | |
4144 | ||
4145 | /* Set default buffer number or free all the buffers in case | |
4146 | * the pool is not empty | |
4147 | */ | |
4148 | pkts_num = new_pool->buf_num; | |
4149 | if (pkts_num == 0) | |
4150 | pkts_num = type == MVPP2_BM_SWF_LONG ? | |
4151 | MVPP2_BM_LONG_BUF_NUM : | |
4152 | MVPP2_BM_SHORT_BUF_NUM; | |
4153 | else | |
4229d502 MW |
4154 | mvpp2_bm_bufs_free(port->dev->dev.parent, |
4155 | port->priv, new_pool); | |
3f518509 MW |
4156 | |
4157 | new_pool->pkt_size = pkt_size; | |
0e037281 TP |
4158 | new_pool->frag_size = |
4159 | SKB_DATA_ALIGN(MVPP2_RX_BUF_SIZE(pkt_size)) + | |
4160 | MVPP2_SKB_SHINFO_SIZE; | |
3f518509 MW |
4161 | |
4162 | /* Allocate buffers for this pool */ | |
4163 | num = mvpp2_bm_bufs_add(port, new_pool, pkts_num); | |
4164 | if (num != pkts_num) { | |
4165 | WARN(1, "pool %d: %d of %d allocated\n", | |
4166 | new_pool->id, num, pkts_num); | |
3f518509 MW |
4167 | return NULL; |
4168 | } | |
4169 | } | |
4170 | ||
4171 | mvpp2_bm_pool_bufsize_set(port->priv, new_pool, | |
4172 | MVPP2_RX_BUF_SIZE(new_pool->pkt_size)); | |
4173 | ||
3f518509 MW |
4174 | return new_pool; |
4175 | } | |
4176 | ||
4177 | /* Initialize pools for swf */ | |
4178 | static int mvpp2_swf_bm_pool_init(struct mvpp2_port *port) | |
4179 | { | |
3f518509 MW |
4180 | int rxq; |
4181 | ||
4182 | if (!port->pool_long) { | |
4183 | port->pool_long = | |
4184 | mvpp2_bm_pool_use(port, MVPP2_BM_SWF_LONG_POOL(port->id), | |
4185 | MVPP2_BM_SWF_LONG, | |
4186 | port->pkt_size); | |
4187 | if (!port->pool_long) | |
4188 | return -ENOMEM; | |
4189 | ||
3f518509 | 4190 | port->pool_long->port_map |= (1 << port->id); |
3f518509 | 4191 | |
09f83975 | 4192 | for (rxq = 0; rxq < port->nrxqs; rxq++) |
3f518509 MW |
4193 | mvpp2_rxq_long_pool_set(port, rxq, port->pool_long->id); |
4194 | } | |
4195 | ||
4196 | if (!port->pool_short) { | |
4197 | port->pool_short = | |
4198 | mvpp2_bm_pool_use(port, MVPP2_BM_SWF_SHORT_POOL, | |
4199 | MVPP2_BM_SWF_SHORT, | |
4200 | MVPP2_BM_SHORT_PKT_SIZE); | |
4201 | if (!port->pool_short) | |
4202 | return -ENOMEM; | |
4203 | ||
3f518509 | 4204 | port->pool_short->port_map |= (1 << port->id); |
3f518509 | 4205 | |
09f83975 | 4206 | for (rxq = 0; rxq < port->nrxqs; rxq++) |
3f518509 MW |
4207 | mvpp2_rxq_short_pool_set(port, rxq, |
4208 | port->pool_short->id); | |
4209 | } | |
4210 | ||
4211 | return 0; | |
4212 | } | |
4213 | ||
4214 | static int mvpp2_bm_update_mtu(struct net_device *dev, int mtu) | |
4215 | { | |
4216 | struct mvpp2_port *port = netdev_priv(dev); | |
4217 | struct mvpp2_bm_pool *port_pool = port->pool_long; | |
4218 | int num, pkts_num = port_pool->buf_num; | |
4219 | int pkt_size = MVPP2_RX_PKT_SIZE(mtu); | |
4220 | ||
4221 | /* Update BM pool with new buffer size */ | |
4229d502 | 4222 | mvpp2_bm_bufs_free(dev->dev.parent, port->priv, port_pool); |
d74c96c1 | 4223 | if (port_pool->buf_num) { |
3f518509 MW |
4224 | WARN(1, "cannot free all buffers in pool %d\n", port_pool->id); |
4225 | return -EIO; | |
4226 | } | |
4227 | ||
4228 | port_pool->pkt_size = pkt_size; | |
0e037281 TP |
4229 | port_pool->frag_size = SKB_DATA_ALIGN(MVPP2_RX_BUF_SIZE(pkt_size)) + |
4230 | MVPP2_SKB_SHINFO_SIZE; | |
3f518509 MW |
4231 | num = mvpp2_bm_bufs_add(port, port_pool, pkts_num); |
4232 | if (num != pkts_num) { | |
4233 | WARN(1, "pool %d: %d of %d allocated\n", | |
4234 | port_pool->id, num, pkts_num); | |
4235 | return -EIO; | |
4236 | } | |
4237 | ||
4238 | mvpp2_bm_pool_bufsize_set(port->priv, port_pool, | |
4239 | MVPP2_RX_BUF_SIZE(port_pool->pkt_size)); | |
4240 | dev->mtu = mtu; | |
4241 | netdev_update_features(dev); | |
4242 | return 0; | |
4243 | } | |
4244 | ||
4245 | static inline void mvpp2_interrupts_enable(struct mvpp2_port *port) | |
4246 | { | |
591f4cfa TP |
4247 | int i, sw_thread_mask = 0; |
4248 | ||
4249 | for (i = 0; i < port->nqvecs; i++) | |
4250 | sw_thread_mask |= port->qvecs[i].sw_thread_mask; | |
3f518509 | 4251 | |
3f518509 | 4252 | mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id), |
591f4cfa | 4253 | MVPP2_ISR_ENABLE_INTERRUPT(sw_thread_mask)); |
3f518509 MW |
4254 | } |
4255 | ||
4256 | static inline void mvpp2_interrupts_disable(struct mvpp2_port *port) | |
4257 | { | |
591f4cfa TP |
4258 | int i, sw_thread_mask = 0; |
4259 | ||
4260 | for (i = 0; i < port->nqvecs; i++) | |
4261 | sw_thread_mask |= port->qvecs[i].sw_thread_mask; | |
4262 | ||
4263 | mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id), | |
4264 | MVPP2_ISR_DISABLE_INTERRUPT(sw_thread_mask)); | |
4265 | } | |
4266 | ||
4267 | static inline void mvpp2_qvec_interrupt_enable(struct mvpp2_queue_vector *qvec) | |
4268 | { | |
4269 | struct mvpp2_port *port = qvec->port; | |
3f518509 | 4270 | |
3f518509 | 4271 | mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id), |
591f4cfa TP |
4272 | MVPP2_ISR_ENABLE_INTERRUPT(qvec->sw_thread_mask)); |
4273 | } | |
4274 | ||
4275 | static inline void mvpp2_qvec_interrupt_disable(struct mvpp2_queue_vector *qvec) | |
4276 | { | |
4277 | struct mvpp2_port *port = qvec->port; | |
4278 | ||
4279 | mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id), | |
4280 | MVPP2_ISR_DISABLE_INTERRUPT(qvec->sw_thread_mask)); | |
3f518509 MW |
4281 | } |
4282 | ||
e0af22d9 TP |
4283 | /* Mask the current CPU's Rx/Tx interrupts |
4284 | * Called by on_each_cpu(), guaranteed to run with migration disabled, | |
4285 | * using smp_processor_id() is OK. | |
4286 | */ | |
3f518509 MW |
4287 | static void mvpp2_interrupts_mask(void *arg) |
4288 | { | |
4289 | struct mvpp2_port *port = arg; | |
4290 | ||
a786841d TP |
4291 | mvpp2_percpu_write(port->priv, smp_processor_id(), |
4292 | MVPP2_ISR_RX_TX_MASK_REG(port->id), 0); | |
3f518509 MW |
4293 | } |
4294 | ||
e0af22d9 TP |
4295 | /* Unmask the current CPU's Rx/Tx interrupts. |
4296 | * Called by on_each_cpu(), guaranteed to run with migration disabled, | |
4297 | * using smp_processor_id() is OK. | |
4298 | */ | |
3f518509 MW |
4299 | static void mvpp2_interrupts_unmask(void *arg) |
4300 | { | |
4301 | struct mvpp2_port *port = arg; | |
213f428f TP |
4302 | u32 val; |
4303 | ||
4304 | val = MVPP2_CAUSE_MISC_SUM_MASK | | |
4305 | MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK; | |
4306 | if (port->has_tx_irqs) | |
4307 | val |= MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK; | |
3f518509 | 4308 | |
a786841d | 4309 | mvpp2_percpu_write(port->priv, smp_processor_id(), |
213f428f TP |
4310 | MVPP2_ISR_RX_TX_MASK_REG(port->id), val); |
4311 | } | |
4312 | ||
4313 | static void | |
4314 | mvpp2_shared_interrupt_mask_unmask(struct mvpp2_port *port, bool mask) | |
4315 | { | |
4316 | u32 val; | |
4317 | int i; | |
4318 | ||
4319 | if (port->priv->hw_version != MVPP22) | |
4320 | return; | |
4321 | ||
4322 | if (mask) | |
4323 | val = 0; | |
4324 | else | |
4325 | val = MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK; | |
4326 | ||
4327 | for (i = 0; i < port->nqvecs; i++) { | |
4328 | struct mvpp2_queue_vector *v = port->qvecs + i; | |
4329 | ||
4330 | if (v->type != MVPP2_QUEUE_VECTOR_SHARED) | |
4331 | continue; | |
4332 | ||
4333 | mvpp2_percpu_write(port->priv, v->sw_thread_id, | |
4334 | MVPP2_ISR_RX_TX_MASK_REG(port->id), val); | |
4335 | } | |
3f518509 MW |
4336 | } |
4337 | ||
4338 | /* Port configuration routines */ | |
4339 | ||
f84bf386 AT |
4340 | static void mvpp22_gop_init_rgmii(struct mvpp2_port *port) |
4341 | { | |
4342 | struct mvpp2 *priv = port->priv; | |
4343 | u32 val; | |
4344 | ||
4345 | regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL0, &val); | |
4346 | val |= GENCONF_PORT_CTRL0_BUS_WIDTH_SELECT; | |
4347 | regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL0, val); | |
4348 | ||
4349 | regmap_read(priv->sysctrl_base, GENCONF_CTRL0, &val); | |
4350 | if (port->gop_id == 2) | |
4351 | val |= GENCONF_CTRL0_PORT0_RGMII | GENCONF_CTRL0_PORT1_RGMII; | |
4352 | else if (port->gop_id == 3) | |
4353 | val |= GENCONF_CTRL0_PORT1_RGMII_MII; | |
4354 | regmap_write(priv->sysctrl_base, GENCONF_CTRL0, val); | |
4355 | } | |
4356 | ||
4357 | static void mvpp22_gop_init_sgmii(struct mvpp2_port *port) | |
4358 | { | |
4359 | struct mvpp2 *priv = port->priv; | |
4360 | u32 val; | |
4361 | ||
4362 | regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL0, &val); | |
4363 | val |= GENCONF_PORT_CTRL0_BUS_WIDTH_SELECT | | |
4364 | GENCONF_PORT_CTRL0_RX_DATA_SAMPLE; | |
4365 | regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL0, val); | |
4366 | ||
4367 | if (port->gop_id > 1) { | |
4368 | regmap_read(priv->sysctrl_base, GENCONF_CTRL0, &val); | |
4369 | if (port->gop_id == 2) | |
4370 | val &= ~GENCONF_CTRL0_PORT0_RGMII; | |
4371 | else if (port->gop_id == 3) | |
4372 | val &= ~GENCONF_CTRL0_PORT1_RGMII_MII; | |
4373 | regmap_write(priv->sysctrl_base, GENCONF_CTRL0, val); | |
4374 | } | |
4375 | } | |
4376 | ||
4377 | static void mvpp22_gop_init_10gkr(struct mvpp2_port *port) | |
4378 | { | |
4379 | struct mvpp2 *priv = port->priv; | |
4380 | void __iomem *mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id); | |
4381 | void __iomem *xpcs = priv->iface_base + MVPP22_XPCS_BASE(port->gop_id); | |
4382 | u32 val; | |
4383 | ||
4384 | /* XPCS */ | |
4385 | val = readl(xpcs + MVPP22_XPCS_CFG0); | |
4386 | val &= ~(MVPP22_XPCS_CFG0_PCS_MODE(0x3) | | |
4387 | MVPP22_XPCS_CFG0_ACTIVE_LANE(0x3)); | |
4388 | val |= MVPP22_XPCS_CFG0_ACTIVE_LANE(2); | |
4389 | writel(val, xpcs + MVPP22_XPCS_CFG0); | |
4390 | ||
4391 | /* MPCS */ | |
4392 | val = readl(mpcs + MVPP22_MPCS_CTRL); | |
4393 | val &= ~MVPP22_MPCS_CTRL_FWD_ERR_CONN; | |
4394 | writel(val, mpcs + MVPP22_MPCS_CTRL); | |
4395 | ||
4396 | val = readl(mpcs + MVPP22_MPCS_CLK_RESET); | |
4397 | val &= ~(MVPP22_MPCS_CLK_RESET_DIV_RATIO(0x7) | MAC_CLK_RESET_MAC | | |
4398 | MAC_CLK_RESET_SD_RX | MAC_CLK_RESET_SD_TX); | |
4399 | val |= MVPP22_MPCS_CLK_RESET_DIV_RATIO(1); | |
4400 | writel(val, mpcs + MVPP22_MPCS_CLK_RESET); | |
4401 | ||
4402 | val &= ~MVPP22_MPCS_CLK_RESET_DIV_SET; | |
4403 | val |= MAC_CLK_RESET_MAC | MAC_CLK_RESET_SD_RX | MAC_CLK_RESET_SD_TX; | |
4404 | writel(val, mpcs + MVPP22_MPCS_CLK_RESET); | |
4405 | } | |
4406 | ||
4407 | static int mvpp22_gop_init(struct mvpp2_port *port) | |
4408 | { | |
4409 | struct mvpp2 *priv = port->priv; | |
4410 | u32 val; | |
4411 | ||
4412 | if (!priv->sysctrl_base) | |
4413 | return 0; | |
4414 | ||
4415 | switch (port->phy_interface) { | |
4416 | case PHY_INTERFACE_MODE_RGMII: | |
4417 | case PHY_INTERFACE_MODE_RGMII_ID: | |
4418 | case PHY_INTERFACE_MODE_RGMII_RXID: | |
4419 | case PHY_INTERFACE_MODE_RGMII_TXID: | |
4420 | if (port->gop_id == 0) | |
4421 | goto invalid_conf; | |
4422 | mvpp22_gop_init_rgmii(port); | |
4423 | break; | |
4424 | case PHY_INTERFACE_MODE_SGMII: | |
4425 | mvpp22_gop_init_sgmii(port); | |
4426 | break; | |
4427 | case PHY_INTERFACE_MODE_10GKR: | |
4428 | if (port->gop_id != 0) | |
4429 | goto invalid_conf; | |
4430 | mvpp22_gop_init_10gkr(port); | |
4431 | break; | |
4432 | default: | |
4433 | goto unsupported_conf; | |
4434 | } | |
4435 | ||
4436 | regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL1, &val); | |
4437 | val |= GENCONF_PORT_CTRL1_RESET(port->gop_id) | | |
4438 | GENCONF_PORT_CTRL1_EN(port->gop_id); | |
4439 | regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL1, val); | |
4440 | ||
4441 | regmap_read(priv->sysctrl_base, GENCONF_PORT_CTRL0, &val); | |
4442 | val |= GENCONF_PORT_CTRL0_CLK_DIV_PHASE_CLR; | |
4443 | regmap_write(priv->sysctrl_base, GENCONF_PORT_CTRL0, val); | |
4444 | ||
4445 | regmap_read(priv->sysctrl_base, GENCONF_SOFT_RESET1, &val); | |
4446 | val |= GENCONF_SOFT_RESET1_GOP; | |
4447 | regmap_write(priv->sysctrl_base, GENCONF_SOFT_RESET1, val); | |
4448 | ||
4449 | unsupported_conf: | |
4450 | return 0; | |
4451 | ||
4452 | invalid_conf: | |
4453 | netdev_err(port->dev, "Invalid port configuration\n"); | |
4454 | return -EINVAL; | |
4455 | } | |
4456 | ||
fd3651b2 AT |
4457 | static void mvpp22_gop_unmask_irq(struct mvpp2_port *port) |
4458 | { | |
4459 | u32 val; | |
4460 | ||
4461 | if (phy_interface_mode_is_rgmii(port->phy_interface) || | |
4462 | port->phy_interface == PHY_INTERFACE_MODE_SGMII) { | |
4463 | /* Enable the GMAC link status irq for this port */ | |
4464 | val = readl(port->base + MVPP22_GMAC_INT_SUM_MASK); | |
4465 | val |= MVPP22_GMAC_INT_SUM_MASK_LINK_STAT; | |
4466 | writel(val, port->base + MVPP22_GMAC_INT_SUM_MASK); | |
4467 | } | |
4468 | ||
4469 | if (port->gop_id == 0) { | |
4470 | /* Enable the XLG/GIG irqs for this port */ | |
4471 | val = readl(port->base + MVPP22_XLG_EXT_INT_MASK); | |
4472 | if (port->phy_interface == PHY_INTERFACE_MODE_10GKR) | |
4473 | val |= MVPP22_XLG_EXT_INT_MASK_XLG; | |
4474 | else | |
4475 | val |= MVPP22_XLG_EXT_INT_MASK_GIG; | |
4476 | writel(val, port->base + MVPP22_XLG_EXT_INT_MASK); | |
4477 | } | |
4478 | } | |
4479 | ||
4480 | static void mvpp22_gop_mask_irq(struct mvpp2_port *port) | |
4481 | { | |
4482 | u32 val; | |
4483 | ||
4484 | if (port->gop_id == 0) { | |
4485 | val = readl(port->base + MVPP22_XLG_EXT_INT_MASK); | |
4486 | val &= ~(MVPP22_XLG_EXT_INT_MASK_XLG | | |
4487 | MVPP22_XLG_EXT_INT_MASK_GIG); | |
4488 | writel(val, port->base + MVPP22_XLG_EXT_INT_MASK); | |
4489 | } | |
4490 | ||
4491 | if (phy_interface_mode_is_rgmii(port->phy_interface) || | |
4492 | port->phy_interface == PHY_INTERFACE_MODE_SGMII) { | |
4493 | val = readl(port->base + MVPP22_GMAC_INT_SUM_MASK); | |
4494 | val &= ~MVPP22_GMAC_INT_SUM_MASK_LINK_STAT; | |
4495 | writel(val, port->base + MVPP22_GMAC_INT_SUM_MASK); | |
4496 | } | |
4497 | } | |
4498 | ||
4499 | static void mvpp22_gop_setup_irq(struct mvpp2_port *port) | |
4500 | { | |
4501 | u32 val; | |
4502 | ||
4503 | if (phy_interface_mode_is_rgmii(port->phy_interface) || | |
4504 | port->phy_interface == PHY_INTERFACE_MODE_SGMII) { | |
4505 | val = readl(port->base + MVPP22_GMAC_INT_MASK); | |
4506 | val |= MVPP22_GMAC_INT_MASK_LINK_STAT; | |
4507 | writel(val, port->base + MVPP22_GMAC_INT_MASK); | |
4508 | } | |
4509 | ||
4510 | if (port->gop_id == 0) { | |
4511 | val = readl(port->base + MVPP22_XLG_INT_MASK); | |
4512 | val |= MVPP22_XLG_INT_MASK_LINK; | |
4513 | writel(val, port->base + MVPP22_XLG_INT_MASK); | |
4514 | } | |
4515 | ||
4516 | mvpp22_gop_unmask_irq(port); | |
4517 | } | |
4518 | ||
542897d9 AT |
4519 | static int mvpp22_comphy_init(struct mvpp2_port *port) |
4520 | { | |
4521 | enum phy_mode mode; | |
4522 | int ret; | |
4523 | ||
4524 | if (!port->comphy) | |
4525 | return 0; | |
4526 | ||
4527 | switch (port->phy_interface) { | |
4528 | case PHY_INTERFACE_MODE_SGMII: | |
4529 | mode = PHY_MODE_SGMII; | |
4530 | break; | |
4531 | case PHY_INTERFACE_MODE_10GKR: | |
4532 | mode = PHY_MODE_10GKR; | |
4533 | break; | |
4534 | default: | |
4535 | return -EINVAL; | |
4536 | } | |
4537 | ||
4538 | ret = phy_set_mode(port->comphy, mode); | |
4539 | if (ret) | |
4540 | return ret; | |
4541 | ||
4542 | return phy_power_on(port->comphy); | |
4543 | } | |
4544 | ||
3919357f AT |
4545 | static void mvpp2_port_mii_gmac_configure_mode(struct mvpp2_port *port) |
4546 | { | |
4547 | u32 val; | |
4548 | ||
4549 | if (port->phy_interface == PHY_INTERFACE_MODE_SGMII) { | |
4550 | val = readl(port->base + MVPP22_GMAC_CTRL_4_REG); | |
4551 | val |= MVPP22_CTRL4_SYNC_BYPASS_DIS | MVPP22_CTRL4_DP_CLK_SEL | | |
4552 | MVPP22_CTRL4_QSGMII_BYPASS_ACTIVE; | |
4553 | val &= ~MVPP22_CTRL4_EXT_PIN_GMII_SEL; | |
4554 | writel(val, port->base + MVPP22_GMAC_CTRL_4_REG); | |
4555 | ||
4556 | val = readl(port->base + MVPP2_GMAC_CTRL_2_REG); | |
4557 | val |= MVPP2_GMAC_DISABLE_PADDING; | |
4558 | val &= ~MVPP2_GMAC_FLOW_CTRL_MASK; | |
4559 | writel(val, port->base + MVPP2_GMAC_CTRL_2_REG); | |
1df2270d | 4560 | } else if (phy_interface_mode_is_rgmii(port->phy_interface)) { |
3919357f AT |
4561 | val = readl(port->base + MVPP22_GMAC_CTRL_4_REG); |
4562 | val |= MVPP22_CTRL4_EXT_PIN_GMII_SEL | | |
4563 | MVPP22_CTRL4_SYNC_BYPASS_DIS | | |
4564 | MVPP22_CTRL4_QSGMII_BYPASS_ACTIVE; | |
4565 | val &= ~MVPP22_CTRL4_DP_CLK_SEL; | |
4566 | writel(val, port->base + MVPP22_GMAC_CTRL_4_REG); | |
4567 | ||
4568 | val = readl(port->base + MVPP2_GMAC_CTRL_2_REG); | |
4569 | val &= ~MVPP2_GMAC_DISABLE_PADDING; | |
4570 | writel(val, port->base + MVPP2_GMAC_CTRL_2_REG); | |
4571 | } | |
4572 | ||
4573 | /* The port is connected to a copper PHY */ | |
4574 | val = readl(port->base + MVPP2_GMAC_CTRL_0_REG); | |
4575 | val &= ~MVPP2_GMAC_PORT_TYPE_MASK; | |
4576 | writel(val, port->base + MVPP2_GMAC_CTRL_0_REG); | |
4577 | ||
4578 | val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG); | |
4579 | val |= MVPP2_GMAC_IN_BAND_AUTONEG_BYPASS | | |
4580 | MVPP2_GMAC_AN_SPEED_EN | MVPP2_GMAC_FLOW_CTRL_AUTONEG | | |
4581 | MVPP2_GMAC_AN_DUPLEX_EN; | |
4582 | if (port->phy_interface == PHY_INTERFACE_MODE_SGMII) | |
4583 | val |= MVPP2_GMAC_IN_BAND_AUTONEG; | |
4584 | writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG); | |
4585 | } | |
4586 | ||
4587 | static void mvpp2_port_mii_gmac_configure(struct mvpp2_port *port) | |
4588 | { | |
4589 | u32 val; | |
4590 | ||
4591 | /* Force link down */ | |
4592 | val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG); | |
4593 | val &= ~MVPP2_GMAC_FORCE_LINK_PASS; | |
4594 | val |= MVPP2_GMAC_FORCE_LINK_DOWN; | |
4595 | writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG); | |
4596 | ||
4597 | /* Set the GMAC in a reset state */ | |
4598 | val = readl(port->base + MVPP2_GMAC_CTRL_2_REG); | |
4599 | val |= MVPP2_GMAC_PORT_RESET_MASK; | |
4600 | writel(val, port->base + MVPP2_GMAC_CTRL_2_REG); | |
4601 | ||
4602 | /* Configure the PCS and in-band AN */ | |
4603 | val = readl(port->base + MVPP2_GMAC_CTRL_2_REG); | |
4604 | if (port->phy_interface == PHY_INTERFACE_MODE_SGMII) { | |
4605 | val |= MVPP2_GMAC_INBAND_AN_MASK | MVPP2_GMAC_PCS_ENABLE_MASK; | |
1df2270d | 4606 | } else if (phy_interface_mode_is_rgmii(port->phy_interface)) { |
3919357f | 4607 | val &= ~MVPP2_GMAC_PCS_ENABLE_MASK; |
3919357f AT |
4608 | } |
4609 | writel(val, port->base + MVPP2_GMAC_CTRL_2_REG); | |
4610 | ||
4611 | mvpp2_port_mii_gmac_configure_mode(port); | |
4612 | ||
4613 | /* Unset the GMAC reset state */ | |
4614 | val = readl(port->base + MVPP2_GMAC_CTRL_2_REG); | |
4615 | val &= ~MVPP2_GMAC_PORT_RESET_MASK; | |
4616 | writel(val, port->base + MVPP2_GMAC_CTRL_2_REG); | |
4617 | ||
4618 | /* Stop forcing link down */ | |
4619 | val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG); | |
4620 | val &= ~MVPP2_GMAC_FORCE_LINK_DOWN; | |
4621 | writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG); | |
4622 | } | |
4623 | ||
77321959 AT |
4624 | static void mvpp2_port_mii_xlg_configure(struct mvpp2_port *port) |
4625 | { | |
4626 | u32 val; | |
4627 | ||
4628 | if (port->gop_id != 0) | |
4629 | return; | |
4630 | ||
4631 | val = readl(port->base + MVPP22_XLG_CTRL0_REG); | |
4632 | val |= MVPP22_XLG_CTRL0_RX_FLOW_CTRL_EN; | |
4633 | writel(val, port->base + MVPP22_XLG_CTRL0_REG); | |
4634 | ||
4635 | val = readl(port->base + MVPP22_XLG_CTRL4_REG); | |
4636 | val &= ~MVPP22_XLG_CTRL4_MACMODSELECT_GMAC; | |
4637 | val |= MVPP22_XLG_CTRL4_FWD_FC | MVPP22_XLG_CTRL4_FWD_PFC; | |
4638 | writel(val, port->base + MVPP22_XLG_CTRL4_REG); | |
4639 | } | |
4640 | ||
26975821 TP |
4641 | static void mvpp22_port_mii_set(struct mvpp2_port *port) |
4642 | { | |
4643 | u32 val; | |
4644 | ||
26975821 TP |
4645 | /* Only GOP port 0 has an XLG MAC */ |
4646 | if (port->gop_id == 0) { | |
4647 | val = readl(port->base + MVPP22_XLG_CTRL3_REG); | |
4648 | val &= ~MVPP22_XLG_CTRL3_MACMODESELECT_MASK; | |
725757ae AT |
4649 | |
4650 | if (port->phy_interface == PHY_INTERFACE_MODE_XAUI || | |
4651 | port->phy_interface == PHY_INTERFACE_MODE_10GKR) | |
4652 | val |= MVPP22_XLG_CTRL3_MACMODESELECT_10G; | |
4653 | else | |
4654 | val |= MVPP22_XLG_CTRL3_MACMODESELECT_GMAC; | |
4655 | ||
26975821 TP |
4656 | writel(val, port->base + MVPP22_XLG_CTRL3_REG); |
4657 | } | |
26975821 TP |
4658 | } |
4659 | ||
3f518509 MW |
4660 | static void mvpp2_port_mii_set(struct mvpp2_port *port) |
4661 | { | |
26975821 TP |
4662 | if (port->priv->hw_version == MVPP22) |
4663 | mvpp22_port_mii_set(port); | |
4664 | ||
1df2270d | 4665 | if (phy_interface_mode_is_rgmii(port->phy_interface) || |
3919357f AT |
4666 | port->phy_interface == PHY_INTERFACE_MODE_SGMII) |
4667 | mvpp2_port_mii_gmac_configure(port); | |
77321959 AT |
4668 | else if (port->phy_interface == PHY_INTERFACE_MODE_10GKR) |
4669 | mvpp2_port_mii_xlg_configure(port); | |
08a23755 | 4670 | } |
3f518509 | 4671 | |
08a23755 MW |
4672 | static void mvpp2_port_fc_adv_enable(struct mvpp2_port *port) |
4673 | { | |
4674 | u32 val; | |
4675 | ||
4676 | val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG); | |
4677 | val |= MVPP2_GMAC_FC_ADV_EN; | |
4678 | writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG); | |
3f518509 MW |
4679 | } |
4680 | ||
4681 | static void mvpp2_port_enable(struct mvpp2_port *port) | |
4682 | { | |
4683 | u32 val; | |
4684 | ||
725757ae AT |
4685 | /* Only GOP port 0 has an XLG MAC */ |
4686 | if (port->gop_id == 0 && | |
4687 | (port->phy_interface == PHY_INTERFACE_MODE_XAUI || | |
4688 | port->phy_interface == PHY_INTERFACE_MODE_10GKR)) { | |
4689 | val = readl(port->base + MVPP22_XLG_CTRL0_REG); | |
4690 | val |= MVPP22_XLG_CTRL0_PORT_EN | | |
4691 | MVPP22_XLG_CTRL0_MAC_RESET_DIS; | |
4692 | val &= ~MVPP22_XLG_CTRL0_MIB_CNT_DIS; | |
4693 | writel(val, port->base + MVPP22_XLG_CTRL0_REG); | |
4694 | } else { | |
4695 | val = readl(port->base + MVPP2_GMAC_CTRL_0_REG); | |
4696 | val |= MVPP2_GMAC_PORT_EN_MASK; | |
4697 | val |= MVPP2_GMAC_MIB_CNTR_EN_MASK; | |
4698 | writel(val, port->base + MVPP2_GMAC_CTRL_0_REG); | |
4699 | } | |
3f518509 MW |
4700 | } |
4701 | ||
4702 | static void mvpp2_port_disable(struct mvpp2_port *port) | |
4703 | { | |
4704 | u32 val; | |
4705 | ||
725757ae AT |
4706 | /* Only GOP port 0 has an XLG MAC */ |
4707 | if (port->gop_id == 0 && | |
4708 | (port->phy_interface == PHY_INTERFACE_MODE_XAUI || | |
4709 | port->phy_interface == PHY_INTERFACE_MODE_10GKR)) { | |
4710 | val = readl(port->base + MVPP22_XLG_CTRL0_REG); | |
4711 | val &= ~(MVPP22_XLG_CTRL0_PORT_EN | | |
4712 | MVPP22_XLG_CTRL0_MAC_RESET_DIS); | |
4713 | writel(val, port->base + MVPP22_XLG_CTRL0_REG); | |
4714 | } else { | |
4715 | val = readl(port->base + MVPP2_GMAC_CTRL_0_REG); | |
4716 | val &= ~(MVPP2_GMAC_PORT_EN_MASK); | |
4717 | writel(val, port->base + MVPP2_GMAC_CTRL_0_REG); | |
4718 | } | |
3f518509 MW |
4719 | } |
4720 | ||
4721 | /* Set IEEE 802.3x Flow Control Xon Packet Transmission Mode */ | |
4722 | static void mvpp2_port_periodic_xon_disable(struct mvpp2_port *port) | |
4723 | { | |
4724 | u32 val; | |
4725 | ||
4726 | val = readl(port->base + MVPP2_GMAC_CTRL_1_REG) & | |
4727 | ~MVPP2_GMAC_PERIODIC_XON_EN_MASK; | |
4728 | writel(val, port->base + MVPP2_GMAC_CTRL_1_REG); | |
4729 | } | |
4730 | ||
4731 | /* Configure loopback port */ | |
4732 | static void mvpp2_port_loopback_set(struct mvpp2_port *port) | |
4733 | { | |
4734 | u32 val; | |
4735 | ||
4736 | val = readl(port->base + MVPP2_GMAC_CTRL_1_REG); | |
4737 | ||
4738 | if (port->speed == 1000) | |
4739 | val |= MVPP2_GMAC_GMII_LB_EN_MASK; | |
4740 | else | |
4741 | val &= ~MVPP2_GMAC_GMII_LB_EN_MASK; | |
4742 | ||
4743 | if (port->phy_interface == PHY_INTERFACE_MODE_SGMII) | |
4744 | val |= MVPP2_GMAC_PCS_LB_EN_MASK; | |
4745 | else | |
4746 | val &= ~MVPP2_GMAC_PCS_LB_EN_MASK; | |
4747 | ||
4748 | writel(val, port->base + MVPP2_GMAC_CTRL_1_REG); | |
4749 | } | |
4750 | ||
4751 | static void mvpp2_port_reset(struct mvpp2_port *port) | |
4752 | { | |
4753 | u32 val; | |
4754 | ||
4755 | val = readl(port->base + MVPP2_GMAC_CTRL_2_REG) & | |
4756 | ~MVPP2_GMAC_PORT_RESET_MASK; | |
4757 | writel(val, port->base + MVPP2_GMAC_CTRL_2_REG); | |
4758 | ||
4759 | while (readl(port->base + MVPP2_GMAC_CTRL_2_REG) & | |
4760 | MVPP2_GMAC_PORT_RESET_MASK) | |
4761 | continue; | |
4762 | } | |
4763 | ||
4764 | /* Change maximum receive size of the port */ | |
4765 | static inline void mvpp2_gmac_max_rx_size_set(struct mvpp2_port *port) | |
4766 | { | |
4767 | u32 val; | |
4768 | ||
4769 | val = readl(port->base + MVPP2_GMAC_CTRL_0_REG); | |
4770 | val &= ~MVPP2_GMAC_MAX_RX_SIZE_MASK; | |
4771 | val |= (((port->pkt_size - MVPP2_MH_SIZE) / 2) << | |
4772 | MVPP2_GMAC_MAX_RX_SIZE_OFFS); | |
4773 | writel(val, port->base + MVPP2_GMAC_CTRL_0_REG); | |
4774 | } | |
4775 | ||
76eb1b1d SC |
4776 | /* Change maximum receive size of the port */ |
4777 | static inline void mvpp2_xlg_max_rx_size_set(struct mvpp2_port *port) | |
4778 | { | |
4779 | u32 val; | |
4780 | ||
4781 | val = readl(port->base + MVPP22_XLG_CTRL1_REG); | |
4782 | val &= ~MVPP22_XLG_CTRL1_FRAMESIZELIMIT_MASK; | |
4783 | val |= ((port->pkt_size - MVPP2_MH_SIZE) / 2) << | |
ec15ecde | 4784 | MVPP22_XLG_CTRL1_FRAMESIZELIMIT_OFFS; |
76eb1b1d SC |
4785 | writel(val, port->base + MVPP22_XLG_CTRL1_REG); |
4786 | } | |
4787 | ||
3f518509 MW |
4788 | /* Set defaults to the MVPP2 port */ |
4789 | static void mvpp2_defaults_set(struct mvpp2_port *port) | |
4790 | { | |
4791 | int tx_port_num, val, queue, ptxq, lrxq; | |
4792 | ||
3d9017d9 TP |
4793 | if (port->priv->hw_version == MVPP21) { |
4794 | /* Configure port to loopback if needed */ | |
4795 | if (port->flags & MVPP2_F_LOOPBACK) | |
4796 | mvpp2_port_loopback_set(port); | |
4797 | ||
4798 | /* Update TX FIFO MIN Threshold */ | |
4799 | val = readl(port->base + MVPP2_GMAC_PORT_FIFO_CFG_1_REG); | |
4800 | val &= ~MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK; | |
4801 | /* Min. TX threshold must be less than minimal packet length */ | |
4802 | val |= MVPP2_GMAC_TX_FIFO_MIN_TH_MASK(64 - 4 - 2); | |
4803 | writel(val, port->base + MVPP2_GMAC_PORT_FIFO_CFG_1_REG); | |
4804 | } | |
3f518509 MW |
4805 | |
4806 | /* Disable Legacy WRR, Disable EJP, Release from reset */ | |
4807 | tx_port_num = mvpp2_egress_port(port); | |
4808 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, | |
4809 | tx_port_num); | |
4810 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_CMD_1_REG, 0); | |
4811 | ||
4812 | /* Close bandwidth for all queues */ | |
4813 | for (queue = 0; queue < MVPP2_MAX_TXQ; queue++) { | |
4814 | ptxq = mvpp2_txq_phys(port->id, queue); | |
4815 | mvpp2_write(port->priv, | |
4816 | MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(ptxq), 0); | |
4817 | } | |
4818 | ||
4819 | /* Set refill period to 1 usec, refill tokens | |
4820 | * and bucket size to maximum | |
4821 | */ | |
4822 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_PERIOD_REG, | |
4823 | port->priv->tclk / USEC_PER_SEC); | |
4824 | val = mvpp2_read(port->priv, MVPP2_TXP_SCHED_REFILL_REG); | |
4825 | val &= ~MVPP2_TXP_REFILL_PERIOD_ALL_MASK; | |
4826 | val |= MVPP2_TXP_REFILL_PERIOD_MASK(1); | |
4827 | val |= MVPP2_TXP_REFILL_TOKENS_ALL_MASK; | |
4828 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_REFILL_REG, val); | |
4829 | val = MVPP2_TXP_TOKEN_SIZE_MAX; | |
4830 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_TOKEN_SIZE_REG, val); | |
4831 | ||
4832 | /* Set MaximumLowLatencyPacketSize value to 256 */ | |
4833 | mvpp2_write(port->priv, MVPP2_RX_CTRL_REG(port->id), | |
4834 | MVPP2_RX_USE_PSEUDO_FOR_CSUM_MASK | | |
4835 | MVPP2_RX_LOW_LATENCY_PKT_SIZE(256)); | |
4836 | ||
4837 | /* Enable Rx cache snoop */ | |
09f83975 | 4838 | for (lrxq = 0; lrxq < port->nrxqs; lrxq++) { |
3f518509 MW |
4839 | queue = port->rxqs[lrxq]->id; |
4840 | val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(queue)); | |
4841 | val |= MVPP2_SNOOP_PKT_SIZE_MASK | | |
4842 | MVPP2_SNOOP_BUF_HDR_MASK; | |
4843 | mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(queue), val); | |
4844 | } | |
4845 | ||
4846 | /* At default, mask all interrupts to all present cpus */ | |
4847 | mvpp2_interrupts_disable(port); | |
4848 | } | |
4849 | ||
4850 | /* Enable/disable receiving packets */ | |
4851 | static void mvpp2_ingress_enable(struct mvpp2_port *port) | |
4852 | { | |
4853 | u32 val; | |
4854 | int lrxq, queue; | |
4855 | ||
09f83975 | 4856 | for (lrxq = 0; lrxq < port->nrxqs; lrxq++) { |
3f518509 MW |
4857 | queue = port->rxqs[lrxq]->id; |
4858 | val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(queue)); | |
4859 | val &= ~MVPP2_RXQ_DISABLE_MASK; | |
4860 | mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(queue), val); | |
4861 | } | |
4862 | } | |
4863 | ||
4864 | static void mvpp2_ingress_disable(struct mvpp2_port *port) | |
4865 | { | |
4866 | u32 val; | |
4867 | int lrxq, queue; | |
4868 | ||
09f83975 | 4869 | for (lrxq = 0; lrxq < port->nrxqs; lrxq++) { |
3f518509 MW |
4870 | queue = port->rxqs[lrxq]->id; |
4871 | val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(queue)); | |
4872 | val |= MVPP2_RXQ_DISABLE_MASK; | |
4873 | mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(queue), val); | |
4874 | } | |
4875 | } | |
4876 | ||
4877 | /* Enable transmit via physical egress queue | |
4878 | * - HW starts take descriptors from DRAM | |
4879 | */ | |
4880 | static void mvpp2_egress_enable(struct mvpp2_port *port) | |
4881 | { | |
4882 | u32 qmap; | |
4883 | int queue; | |
4884 | int tx_port_num = mvpp2_egress_port(port); | |
4885 | ||
4886 | /* Enable all initialized TXs. */ | |
4887 | qmap = 0; | |
09f83975 | 4888 | for (queue = 0; queue < port->ntxqs; queue++) { |
3f518509 MW |
4889 | struct mvpp2_tx_queue *txq = port->txqs[queue]; |
4890 | ||
dbbb2f03 | 4891 | if (txq->descs) |
3f518509 MW |
4892 | qmap |= (1 << queue); |
4893 | } | |
4894 | ||
4895 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num); | |
4896 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG, qmap); | |
4897 | } | |
4898 | ||
4899 | /* Disable transmit via physical egress queue | |
4900 | * - HW doesn't take descriptors from DRAM | |
4901 | */ | |
4902 | static void mvpp2_egress_disable(struct mvpp2_port *port) | |
4903 | { | |
4904 | u32 reg_data; | |
4905 | int delay; | |
4906 | int tx_port_num = mvpp2_egress_port(port); | |
4907 | ||
4908 | /* Issue stop command for active channels only */ | |
4909 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num); | |
4910 | reg_data = (mvpp2_read(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG)) & | |
4911 | MVPP2_TXP_SCHED_ENQ_MASK; | |
4912 | if (reg_data != 0) | |
4913 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG, | |
4914 | (reg_data << MVPP2_TXP_SCHED_DISQ_OFFSET)); | |
4915 | ||
4916 | /* Wait for all Tx activity to terminate. */ | |
4917 | delay = 0; | |
4918 | do { | |
4919 | if (delay >= MVPP2_TX_DISABLE_TIMEOUT_MSEC) { | |
4920 | netdev_warn(port->dev, | |
4921 | "Tx stop timed out, status=0x%08x\n", | |
4922 | reg_data); | |
4923 | break; | |
4924 | } | |
4925 | mdelay(1); | |
4926 | delay++; | |
4927 | ||
4928 | /* Check port TX Command register that all | |
4929 | * Tx queues are stopped | |
4930 | */ | |
4931 | reg_data = mvpp2_read(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG); | |
4932 | } while (reg_data & MVPP2_TXP_SCHED_ENQ_MASK); | |
4933 | } | |
4934 | ||
4935 | /* Rx descriptors helper methods */ | |
4936 | ||
4937 | /* Get number of Rx descriptors occupied by received packets */ | |
4938 | static inline int | |
4939 | mvpp2_rxq_received(struct mvpp2_port *port, int rxq_id) | |
4940 | { | |
4941 | u32 val = mvpp2_read(port->priv, MVPP2_RXQ_STATUS_REG(rxq_id)); | |
4942 | ||
4943 | return val & MVPP2_RXQ_OCCUPIED_MASK; | |
4944 | } | |
4945 | ||
4946 | /* Update Rx queue status with the number of occupied and available | |
4947 | * Rx descriptor slots. | |
4948 | */ | |
4949 | static inline void | |
4950 | mvpp2_rxq_status_update(struct mvpp2_port *port, int rxq_id, | |
4951 | int used_count, int free_count) | |
4952 | { | |
4953 | /* Decrement the number of used descriptors and increment count | |
4954 | * increment the number of free descriptors. | |
4955 | */ | |
4956 | u32 val = used_count | (free_count << MVPP2_RXQ_NUM_NEW_OFFSET); | |
4957 | ||
4958 | mvpp2_write(port->priv, MVPP2_RXQ_STATUS_UPDATE_REG(rxq_id), val); | |
4959 | } | |
4960 | ||
4961 | /* Get pointer to next RX descriptor to be processed by SW */ | |
4962 | static inline struct mvpp2_rx_desc * | |
4963 | mvpp2_rxq_next_desc_get(struct mvpp2_rx_queue *rxq) | |
4964 | { | |
4965 | int rx_desc = rxq->next_desc_to_proc; | |
4966 | ||
4967 | rxq->next_desc_to_proc = MVPP2_QUEUE_NEXT_DESC(rxq, rx_desc); | |
4968 | prefetch(rxq->descs + rxq->next_desc_to_proc); | |
4969 | return rxq->descs + rx_desc; | |
4970 | } | |
4971 | ||
4972 | /* Set rx queue offset */ | |
4973 | static void mvpp2_rxq_offset_set(struct mvpp2_port *port, | |
4974 | int prxq, int offset) | |
4975 | { | |
4976 | u32 val; | |
4977 | ||
4978 | /* Convert offset from bytes to units of 32 bytes */ | |
4979 | offset = offset >> 5; | |
4980 | ||
4981 | val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(prxq)); | |
4982 | val &= ~MVPP2_RXQ_PACKET_OFFSET_MASK; | |
4983 | ||
4984 | /* Offset is in */ | |
4985 | val |= ((offset << MVPP2_RXQ_PACKET_OFFSET_OFFS) & | |
4986 | MVPP2_RXQ_PACKET_OFFSET_MASK); | |
4987 | ||
4988 | mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(prxq), val); | |
4989 | } | |
4990 | ||
3f518509 MW |
4991 | /* Tx descriptors helper methods */ |
4992 | ||
3f518509 MW |
4993 | /* Get pointer to next Tx descriptor to be processed (send) by HW */ |
4994 | static struct mvpp2_tx_desc * | |
4995 | mvpp2_txq_next_desc_get(struct mvpp2_tx_queue *txq) | |
4996 | { | |
4997 | int tx_desc = txq->next_desc_to_proc; | |
4998 | ||
4999 | txq->next_desc_to_proc = MVPP2_QUEUE_NEXT_DESC(txq, tx_desc); | |
5000 | return txq->descs + tx_desc; | |
5001 | } | |
5002 | ||
e0af22d9 TP |
5003 | /* Update HW with number of aggregated Tx descriptors to be sent |
5004 | * | |
5005 | * Called only from mvpp2_tx(), so migration is disabled, using | |
5006 | * smp_processor_id() is OK. | |
5007 | */ | |
3f518509 MW |
5008 | static void mvpp2_aggr_txq_pend_desc_add(struct mvpp2_port *port, int pending) |
5009 | { | |
5010 | /* aggregated access - relevant TXQ number is written in TX desc */ | |
a786841d TP |
5011 | mvpp2_percpu_write(port->priv, smp_processor_id(), |
5012 | MVPP2_AGGR_TXQ_UPDATE_REG, pending); | |
3f518509 MW |
5013 | } |
5014 | ||
5015 | ||
5016 | /* Check if there are enough free descriptors in aggregated txq. | |
5017 | * If not, update the number of occupied descriptors and repeat the check. | |
e0af22d9 TP |
5018 | * |
5019 | * Called only from mvpp2_tx(), so migration is disabled, using | |
5020 | * smp_processor_id() is OK. | |
3f518509 MW |
5021 | */ |
5022 | static int mvpp2_aggr_desc_num_check(struct mvpp2 *priv, | |
5023 | struct mvpp2_tx_queue *aggr_txq, int num) | |
5024 | { | |
5025 | if ((aggr_txq->count + num) > aggr_txq->size) { | |
5026 | /* Update number of occupied aggregated Tx descriptors */ | |
5027 | int cpu = smp_processor_id(); | |
5028 | u32 val = mvpp2_read(priv, MVPP2_AGGR_TXQ_STATUS_REG(cpu)); | |
5029 | ||
5030 | aggr_txq->count = val & MVPP2_AGGR_TXQ_PENDING_MASK; | |
5031 | } | |
5032 | ||
5033 | if ((aggr_txq->count + num) > aggr_txq->size) | |
5034 | return -ENOMEM; | |
5035 | ||
5036 | return 0; | |
5037 | } | |
5038 | ||
e0af22d9 TP |
5039 | /* Reserved Tx descriptors allocation request |
5040 | * | |
5041 | * Called only from mvpp2_txq_reserved_desc_num_proc(), itself called | |
5042 | * only by mvpp2_tx(), so migration is disabled, using | |
5043 | * smp_processor_id() is OK. | |
5044 | */ | |
3f518509 MW |
5045 | static int mvpp2_txq_alloc_reserved_desc(struct mvpp2 *priv, |
5046 | struct mvpp2_tx_queue *txq, int num) | |
5047 | { | |
5048 | u32 val; | |
a786841d | 5049 | int cpu = smp_processor_id(); |
3f518509 MW |
5050 | |
5051 | val = (txq->id << MVPP2_TXQ_RSVD_REQ_Q_OFFSET) | num; | |
a786841d | 5052 | mvpp2_percpu_write(priv, cpu, MVPP2_TXQ_RSVD_REQ_REG, val); |
3f518509 | 5053 | |
a786841d | 5054 | val = mvpp2_percpu_read(priv, cpu, MVPP2_TXQ_RSVD_RSLT_REG); |
3f518509 MW |
5055 | |
5056 | return val & MVPP2_TXQ_RSVD_RSLT_MASK; | |
5057 | } | |
5058 | ||
5059 | /* Check if there are enough reserved descriptors for transmission. | |
5060 | * If not, request chunk of reserved descriptors and check again. | |
5061 | */ | |
5062 | static int mvpp2_txq_reserved_desc_num_proc(struct mvpp2 *priv, | |
5063 | struct mvpp2_tx_queue *txq, | |
5064 | struct mvpp2_txq_pcpu *txq_pcpu, | |
5065 | int num) | |
5066 | { | |
5067 | int req, cpu, desc_count; | |
5068 | ||
5069 | if (txq_pcpu->reserved_num >= num) | |
5070 | return 0; | |
5071 | ||
5072 | /* Not enough descriptors reserved! Update the reserved descriptor | |
5073 | * count and check again. | |
5074 | */ | |
5075 | ||
5076 | desc_count = 0; | |
5077 | /* Compute total of used descriptors */ | |
5078 | for_each_present_cpu(cpu) { | |
5079 | struct mvpp2_txq_pcpu *txq_pcpu_aux; | |
5080 | ||
5081 | txq_pcpu_aux = per_cpu_ptr(txq->pcpu, cpu); | |
5082 | desc_count += txq_pcpu_aux->count; | |
5083 | desc_count += txq_pcpu_aux->reserved_num; | |
5084 | } | |
5085 | ||
5086 | req = max(MVPP2_CPU_DESC_CHUNK, num - txq_pcpu->reserved_num); | |
5087 | desc_count += req; | |
5088 | ||
5089 | if (desc_count > | |
5090 | (txq->size - (num_present_cpus() * MVPP2_CPU_DESC_CHUNK))) | |
5091 | return -ENOMEM; | |
5092 | ||
5093 | txq_pcpu->reserved_num += mvpp2_txq_alloc_reserved_desc(priv, txq, req); | |
5094 | ||
5095 | /* OK, the descriptor cound has been updated: check again. */ | |
5096 | if (txq_pcpu->reserved_num < num) | |
5097 | return -ENOMEM; | |
5098 | return 0; | |
5099 | } | |
5100 | ||
5101 | /* Release the last allocated Tx descriptor. Useful to handle DMA | |
5102 | * mapping failures in the Tx path. | |
5103 | */ | |
5104 | static void mvpp2_txq_desc_put(struct mvpp2_tx_queue *txq) | |
5105 | { | |
5106 | if (txq->next_desc_to_proc == 0) | |
5107 | txq->next_desc_to_proc = txq->last_desc - 1; | |
5108 | else | |
5109 | txq->next_desc_to_proc--; | |
5110 | } | |
5111 | ||
5112 | /* Set Tx descriptors fields relevant for CSUM calculation */ | |
5113 | static u32 mvpp2_txq_desc_csum(int l3_offs, int l3_proto, | |
5114 | int ip_hdr_len, int l4_proto) | |
5115 | { | |
5116 | u32 command; | |
5117 | ||
5118 | /* fields: L3_offset, IP_hdrlen, L3_type, G_IPv4_chk, | |
5119 | * G_L4_chk, L4_type required only for checksum calculation | |
5120 | */ | |
5121 | command = (l3_offs << MVPP2_TXD_L3_OFF_SHIFT); | |
5122 | command |= (ip_hdr_len << MVPP2_TXD_IP_HLEN_SHIFT); | |
5123 | command |= MVPP2_TXD_IP_CSUM_DISABLE; | |
5124 | ||
5125 | if (l3_proto == swab16(ETH_P_IP)) { | |
5126 | command &= ~MVPP2_TXD_IP_CSUM_DISABLE; /* enable IPv4 csum */ | |
5127 | command &= ~MVPP2_TXD_L3_IP6; /* enable IPv4 */ | |
5128 | } else { | |
5129 | command |= MVPP2_TXD_L3_IP6; /* enable IPv6 */ | |
5130 | } | |
5131 | ||
5132 | if (l4_proto == IPPROTO_TCP) { | |
5133 | command &= ~MVPP2_TXD_L4_UDP; /* enable TCP */ | |
5134 | command &= ~MVPP2_TXD_L4_CSUM_FRAG; /* generate L4 csum */ | |
5135 | } else if (l4_proto == IPPROTO_UDP) { | |
5136 | command |= MVPP2_TXD_L4_UDP; /* enable UDP */ | |
5137 | command &= ~MVPP2_TXD_L4_CSUM_FRAG; /* generate L4 csum */ | |
5138 | } else { | |
5139 | command |= MVPP2_TXD_L4_CSUM_NOT; | |
5140 | } | |
5141 | ||
5142 | return command; | |
5143 | } | |
5144 | ||
5145 | /* Get number of sent descriptors and decrement counter. | |
5146 | * The number of sent descriptors is returned. | |
5147 | * Per-CPU access | |
e0af22d9 TP |
5148 | * |
5149 | * Called only from mvpp2_txq_done(), called from mvpp2_tx() | |
5150 | * (migration disabled) and from the TX completion tasklet (migration | |
5151 | * disabled) so using smp_processor_id() is OK. | |
3f518509 MW |
5152 | */ |
5153 | static inline int mvpp2_txq_sent_desc_proc(struct mvpp2_port *port, | |
5154 | struct mvpp2_tx_queue *txq) | |
5155 | { | |
5156 | u32 val; | |
5157 | ||
5158 | /* Reading status reg resets transmitted descriptor counter */ | |
a786841d TP |
5159 | val = mvpp2_percpu_read(port->priv, smp_processor_id(), |
5160 | MVPP2_TXQ_SENT_REG(txq->id)); | |
3f518509 MW |
5161 | |
5162 | return (val & MVPP2_TRANSMITTED_COUNT_MASK) >> | |
5163 | MVPP2_TRANSMITTED_COUNT_OFFSET; | |
5164 | } | |
5165 | ||
e0af22d9 TP |
5166 | /* Called through on_each_cpu(), so runs on all CPUs, with migration |
5167 | * disabled, therefore using smp_processor_id() is OK. | |
5168 | */ | |
3f518509 MW |
5169 | static void mvpp2_txq_sent_counter_clear(void *arg) |
5170 | { | |
5171 | struct mvpp2_port *port = arg; | |
5172 | int queue; | |
5173 | ||
09f83975 | 5174 | for (queue = 0; queue < port->ntxqs; queue++) { |
3f518509 MW |
5175 | int id = port->txqs[queue]->id; |
5176 | ||
a786841d TP |
5177 | mvpp2_percpu_read(port->priv, smp_processor_id(), |
5178 | MVPP2_TXQ_SENT_REG(id)); | |
3f518509 MW |
5179 | } |
5180 | } | |
5181 | ||
5182 | /* Set max sizes for Tx queues */ | |
5183 | static void mvpp2_txp_max_tx_size_set(struct mvpp2_port *port) | |
5184 | { | |
5185 | u32 val, size, mtu; | |
5186 | int txq, tx_port_num; | |
5187 | ||
5188 | mtu = port->pkt_size * 8; | |
5189 | if (mtu > MVPP2_TXP_MTU_MAX) | |
5190 | mtu = MVPP2_TXP_MTU_MAX; | |
5191 | ||
5192 | /* WA for wrong Token bucket update: Set MTU value = 3*real MTU value */ | |
5193 | mtu = 3 * mtu; | |
5194 | ||
5195 | /* Indirect access to registers */ | |
5196 | tx_port_num = mvpp2_egress_port(port); | |
5197 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num); | |
5198 | ||
5199 | /* Set MTU */ | |
5200 | val = mvpp2_read(port->priv, MVPP2_TXP_SCHED_MTU_REG); | |
5201 | val &= ~MVPP2_TXP_MTU_MAX; | |
5202 | val |= mtu; | |
5203 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_MTU_REG, val); | |
5204 | ||
5205 | /* TXP token size and all TXQs token size must be larger that MTU */ | |
5206 | val = mvpp2_read(port->priv, MVPP2_TXP_SCHED_TOKEN_SIZE_REG); | |
5207 | size = val & MVPP2_TXP_TOKEN_SIZE_MAX; | |
5208 | if (size < mtu) { | |
5209 | size = mtu; | |
5210 | val &= ~MVPP2_TXP_TOKEN_SIZE_MAX; | |
5211 | val |= size; | |
5212 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_TOKEN_SIZE_REG, val); | |
5213 | } | |
5214 | ||
09f83975 | 5215 | for (txq = 0; txq < port->ntxqs; txq++) { |
3f518509 MW |
5216 | val = mvpp2_read(port->priv, |
5217 | MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq)); | |
5218 | size = val & MVPP2_TXQ_TOKEN_SIZE_MAX; | |
5219 | ||
5220 | if (size < mtu) { | |
5221 | size = mtu; | |
5222 | val &= ~MVPP2_TXQ_TOKEN_SIZE_MAX; | |
5223 | val |= size; | |
5224 | mvpp2_write(port->priv, | |
5225 | MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq), | |
5226 | val); | |
5227 | } | |
5228 | } | |
5229 | } | |
5230 | ||
5231 | /* Set the number of packets that will be received before Rx interrupt | |
5232 | * will be generated by HW. | |
5233 | */ | |
5234 | static void mvpp2_rx_pkts_coal_set(struct mvpp2_port *port, | |
d63f9e41 | 5235 | struct mvpp2_rx_queue *rxq) |
3f518509 | 5236 | { |
a704bb5c | 5237 | int cpu = get_cpu(); |
a786841d | 5238 | |
f8b0d5f8 TP |
5239 | if (rxq->pkts_coal > MVPP2_OCCUPIED_THRESH_MASK) |
5240 | rxq->pkts_coal = MVPP2_OCCUPIED_THRESH_MASK; | |
3f518509 | 5241 | |
a786841d TP |
5242 | mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_NUM_REG, rxq->id); |
5243 | mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_THRESH_REG, | |
5244 | rxq->pkts_coal); | |
a704bb5c TP |
5245 | |
5246 | put_cpu(); | |
3f518509 MW |
5247 | } |
5248 | ||
213f428f TP |
5249 | /* For some reason in the LSP this is done on each CPU. Why ? */ |
5250 | static void mvpp2_tx_pkts_coal_set(struct mvpp2_port *port, | |
5251 | struct mvpp2_tx_queue *txq) | |
5252 | { | |
5253 | int cpu = get_cpu(); | |
5254 | u32 val; | |
5255 | ||
5256 | if (txq->done_pkts_coal > MVPP2_TXQ_THRESH_MASK) | |
5257 | txq->done_pkts_coal = MVPP2_TXQ_THRESH_MASK; | |
5258 | ||
5259 | val = (txq->done_pkts_coal << MVPP2_TXQ_THRESH_OFFSET); | |
5260 | mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_NUM_REG, txq->id); | |
5261 | mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_THRESH_REG, val); | |
5262 | ||
5263 | put_cpu(); | |
5264 | } | |
5265 | ||
ab42676a TP |
5266 | static u32 mvpp2_usec_to_cycles(u32 usec, unsigned long clk_hz) |
5267 | { | |
5268 | u64 tmp = (u64)clk_hz * usec; | |
5269 | ||
5270 | do_div(tmp, USEC_PER_SEC); | |
5271 | ||
5272 | return tmp > U32_MAX ? U32_MAX : tmp; | |
5273 | } | |
5274 | ||
5275 | static u32 mvpp2_cycles_to_usec(u32 cycles, unsigned long clk_hz) | |
5276 | { | |
5277 | u64 tmp = (u64)cycles * USEC_PER_SEC; | |
5278 | ||
5279 | do_div(tmp, clk_hz); | |
5280 | ||
5281 | return tmp > U32_MAX ? U32_MAX : tmp; | |
5282 | } | |
5283 | ||
3f518509 MW |
5284 | /* Set the time delay in usec before Rx interrupt */ |
5285 | static void mvpp2_rx_time_coal_set(struct mvpp2_port *port, | |
d63f9e41 | 5286 | struct mvpp2_rx_queue *rxq) |
3f518509 | 5287 | { |
ab42676a TP |
5288 | unsigned long freq = port->priv->tclk; |
5289 | u32 val = mvpp2_usec_to_cycles(rxq->time_coal, freq); | |
5290 | ||
5291 | if (val > MVPP2_MAX_ISR_RX_THRESHOLD) { | |
5292 | rxq->time_coal = | |
5293 | mvpp2_cycles_to_usec(MVPP2_MAX_ISR_RX_THRESHOLD, freq); | |
5294 | ||
5295 | /* re-evaluate to get actual register value */ | |
5296 | val = mvpp2_usec_to_cycles(rxq->time_coal, freq); | |
5297 | } | |
3f518509 | 5298 | |
3f518509 | 5299 | mvpp2_write(port->priv, MVPP2_ISR_RX_THRESHOLD_REG(rxq->id), val); |
3f518509 MW |
5300 | } |
5301 | ||
213f428f TP |
5302 | static void mvpp2_tx_time_coal_set(struct mvpp2_port *port) |
5303 | { | |
5304 | unsigned long freq = port->priv->tclk; | |
5305 | u32 val = mvpp2_usec_to_cycles(port->tx_time_coal, freq); | |
5306 | ||
5307 | if (val > MVPP2_MAX_ISR_TX_THRESHOLD) { | |
5308 | port->tx_time_coal = | |
5309 | mvpp2_cycles_to_usec(MVPP2_MAX_ISR_TX_THRESHOLD, freq); | |
5310 | ||
5311 | /* re-evaluate to get actual register value */ | |
5312 | val = mvpp2_usec_to_cycles(port->tx_time_coal, freq); | |
5313 | } | |
5314 | ||
5315 | mvpp2_write(port->priv, MVPP2_ISR_TX_THRESHOLD_REG(port->id), val); | |
5316 | } | |
5317 | ||
3f518509 MW |
5318 | /* Free Tx queue skbuffs */ |
5319 | static void mvpp2_txq_bufs_free(struct mvpp2_port *port, | |
5320 | struct mvpp2_tx_queue *txq, | |
5321 | struct mvpp2_txq_pcpu *txq_pcpu, int num) | |
5322 | { | |
5323 | int i; | |
5324 | ||
5325 | for (i = 0; i < num; i++) { | |
8354491c TP |
5326 | struct mvpp2_txq_pcpu_buf *tx_buf = |
5327 | txq_pcpu->buffs + txq_pcpu->txq_get_index; | |
3f518509 | 5328 | |
20920267 AT |
5329 | if (!IS_TSO_HEADER(txq_pcpu, tx_buf->dma)) |
5330 | dma_unmap_single(port->dev->dev.parent, tx_buf->dma, | |
5331 | tx_buf->size, DMA_TO_DEVICE); | |
36fb7435 TP |
5332 | if (tx_buf->skb) |
5333 | dev_kfree_skb_any(tx_buf->skb); | |
5334 | ||
5335 | mvpp2_txq_inc_get(txq_pcpu); | |
3f518509 MW |
5336 | } |
5337 | } | |
5338 | ||
5339 | static inline struct mvpp2_rx_queue *mvpp2_get_rx_queue(struct mvpp2_port *port, | |
5340 | u32 cause) | |
5341 | { | |
5342 | int queue = fls(cause) - 1; | |
5343 | ||
5344 | return port->rxqs[queue]; | |
5345 | } | |
5346 | ||
5347 | static inline struct mvpp2_tx_queue *mvpp2_get_tx_queue(struct mvpp2_port *port, | |
5348 | u32 cause) | |
5349 | { | |
edc660fa | 5350 | int queue = fls(cause) - 1; |
3f518509 MW |
5351 | |
5352 | return port->txqs[queue]; | |
5353 | } | |
5354 | ||
5355 | /* Handle end of transmission */ | |
5356 | static void mvpp2_txq_done(struct mvpp2_port *port, struct mvpp2_tx_queue *txq, | |
5357 | struct mvpp2_txq_pcpu *txq_pcpu) | |
5358 | { | |
5359 | struct netdev_queue *nq = netdev_get_tx_queue(port->dev, txq->log_id); | |
5360 | int tx_done; | |
5361 | ||
5362 | if (txq_pcpu->cpu != smp_processor_id()) | |
5363 | netdev_err(port->dev, "wrong cpu on the end of Tx processing\n"); | |
5364 | ||
5365 | tx_done = mvpp2_txq_sent_desc_proc(port, txq); | |
5366 | if (!tx_done) | |
5367 | return; | |
5368 | mvpp2_txq_bufs_free(port, txq, txq_pcpu, tx_done); | |
5369 | ||
5370 | txq_pcpu->count -= tx_done; | |
5371 | ||
5372 | if (netif_tx_queue_stopped(nq)) | |
5373 | if (txq_pcpu->size - txq_pcpu->count >= MAX_SKB_FRAGS + 1) | |
5374 | netif_tx_wake_queue(nq); | |
5375 | } | |
5376 | ||
213f428f TP |
5377 | static unsigned int mvpp2_tx_done(struct mvpp2_port *port, u32 cause, |
5378 | int cpu) | |
edc660fa MW |
5379 | { |
5380 | struct mvpp2_tx_queue *txq; | |
5381 | struct mvpp2_txq_pcpu *txq_pcpu; | |
5382 | unsigned int tx_todo = 0; | |
5383 | ||
5384 | while (cause) { | |
5385 | txq = mvpp2_get_tx_queue(port, cause); | |
5386 | if (!txq) | |
5387 | break; | |
5388 | ||
213f428f | 5389 | txq_pcpu = per_cpu_ptr(txq->pcpu, cpu); |
edc660fa MW |
5390 | |
5391 | if (txq_pcpu->count) { | |
5392 | mvpp2_txq_done(port, txq, txq_pcpu); | |
5393 | tx_todo += txq_pcpu->count; | |
5394 | } | |
5395 | ||
5396 | cause &= ~(1 << txq->log_id); | |
5397 | } | |
5398 | return tx_todo; | |
5399 | } | |
5400 | ||
3f518509 MW |
5401 | /* Rx/Tx queue initialization/cleanup methods */ |
5402 | ||
5403 | /* Allocate and initialize descriptors for aggr TXQ */ | |
5404 | static int mvpp2_aggr_txq_init(struct platform_device *pdev, | |
85affd7e | 5405 | struct mvpp2_tx_queue *aggr_txq, int cpu, |
3f518509 MW |
5406 | struct mvpp2 *priv) |
5407 | { | |
b02f31fb TP |
5408 | u32 txq_dma; |
5409 | ||
3f518509 MW |
5410 | /* Allocate memory for TX descriptors */ |
5411 | aggr_txq->descs = dma_alloc_coherent(&pdev->dev, | |
85affd7e | 5412 | MVPP2_AGGR_TXQ_SIZE * MVPP2_DESC_ALIGNED_SIZE, |
20396136 | 5413 | &aggr_txq->descs_dma, GFP_KERNEL); |
3f518509 MW |
5414 | if (!aggr_txq->descs) |
5415 | return -ENOMEM; | |
5416 | ||
3f518509 MW |
5417 | aggr_txq->last_desc = aggr_txq->size - 1; |
5418 | ||
5419 | /* Aggr TXQ no reset WA */ | |
5420 | aggr_txq->next_desc_to_proc = mvpp2_read(priv, | |
5421 | MVPP2_AGGR_TXQ_INDEX_REG(cpu)); | |
5422 | ||
b02f31fb TP |
5423 | /* Set Tx descriptors queue starting address indirect |
5424 | * access | |
5425 | */ | |
5426 | if (priv->hw_version == MVPP21) | |
5427 | txq_dma = aggr_txq->descs_dma; | |
5428 | else | |
5429 | txq_dma = aggr_txq->descs_dma >> | |
5430 | MVPP22_AGGR_TXQ_DESC_ADDR_OFFS; | |
5431 | ||
5432 | mvpp2_write(priv, MVPP2_AGGR_TXQ_DESC_ADDR_REG(cpu), txq_dma); | |
85affd7e AT |
5433 | mvpp2_write(priv, MVPP2_AGGR_TXQ_DESC_SIZE_REG(cpu), |
5434 | MVPP2_AGGR_TXQ_SIZE); | |
3f518509 MW |
5435 | |
5436 | return 0; | |
5437 | } | |
5438 | ||
5439 | /* Create a specified Rx queue */ | |
5440 | static int mvpp2_rxq_init(struct mvpp2_port *port, | |
5441 | struct mvpp2_rx_queue *rxq) | |
5442 | ||
5443 | { | |
b02f31fb | 5444 | u32 rxq_dma; |
a786841d | 5445 | int cpu; |
b02f31fb | 5446 | |
3f518509 MW |
5447 | rxq->size = port->rx_ring_size; |
5448 | ||
5449 | /* Allocate memory for RX descriptors */ | |
5450 | rxq->descs = dma_alloc_coherent(port->dev->dev.parent, | |
5451 | rxq->size * MVPP2_DESC_ALIGNED_SIZE, | |
20396136 | 5452 | &rxq->descs_dma, GFP_KERNEL); |
3f518509 MW |
5453 | if (!rxq->descs) |
5454 | return -ENOMEM; | |
5455 | ||
3f518509 MW |
5456 | rxq->last_desc = rxq->size - 1; |
5457 | ||
5458 | /* Zero occupied and non-occupied counters - direct access */ | |
5459 | mvpp2_write(port->priv, MVPP2_RXQ_STATUS_REG(rxq->id), 0); | |
5460 | ||
5461 | /* Set Rx descriptors queue starting address - indirect access */ | |
a704bb5c | 5462 | cpu = get_cpu(); |
a786841d | 5463 | mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_NUM_REG, rxq->id); |
b02f31fb TP |
5464 | if (port->priv->hw_version == MVPP21) |
5465 | rxq_dma = rxq->descs_dma; | |
5466 | else | |
5467 | rxq_dma = rxq->descs_dma >> MVPP22_DESC_ADDR_OFFS; | |
a786841d TP |
5468 | mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_DESC_ADDR_REG, rxq_dma); |
5469 | mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_DESC_SIZE_REG, rxq->size); | |
5470 | mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_INDEX_REG, 0); | |
a704bb5c | 5471 | put_cpu(); |
3f518509 MW |
5472 | |
5473 | /* Set Offset */ | |
5474 | mvpp2_rxq_offset_set(port, rxq->id, NET_SKB_PAD); | |
5475 | ||
5476 | /* Set coalescing pkts and time */ | |
d63f9e41 TP |
5477 | mvpp2_rx_pkts_coal_set(port, rxq); |
5478 | mvpp2_rx_time_coal_set(port, rxq); | |
3f518509 MW |
5479 | |
5480 | /* Add number of descriptors ready for receiving packets */ | |
5481 | mvpp2_rxq_status_update(port, rxq->id, 0, rxq->size); | |
5482 | ||
5483 | return 0; | |
5484 | } | |
5485 | ||
5486 | /* Push packets received by the RXQ to BM pool */ | |
5487 | static void mvpp2_rxq_drop_pkts(struct mvpp2_port *port, | |
5488 | struct mvpp2_rx_queue *rxq) | |
5489 | { | |
5490 | int rx_received, i; | |
5491 | ||
5492 | rx_received = mvpp2_rxq_received(port, rxq->id); | |
5493 | if (!rx_received) | |
5494 | return; | |
5495 | ||
5496 | for (i = 0; i < rx_received; i++) { | |
5497 | struct mvpp2_rx_desc *rx_desc = mvpp2_rxq_next_desc_get(rxq); | |
56b8aae9 TP |
5498 | u32 status = mvpp2_rxdesc_status_get(port, rx_desc); |
5499 | int pool; | |
5500 | ||
5501 | pool = (status & MVPP2_RXD_BM_POOL_ID_MASK) >> | |
5502 | MVPP2_RXD_BM_POOL_ID_OFFS; | |
3f518509 | 5503 | |
7d7627ba | 5504 | mvpp2_bm_pool_put(port, pool, |
ac3dd277 TP |
5505 | mvpp2_rxdesc_dma_addr_get(port, rx_desc), |
5506 | mvpp2_rxdesc_cookie_get(port, rx_desc)); | |
3f518509 MW |
5507 | } |
5508 | mvpp2_rxq_status_update(port, rxq->id, rx_received, rx_received); | |
5509 | } | |
5510 | ||
5511 | /* Cleanup Rx queue */ | |
5512 | static void mvpp2_rxq_deinit(struct mvpp2_port *port, | |
5513 | struct mvpp2_rx_queue *rxq) | |
5514 | { | |
a786841d TP |
5515 | int cpu; |
5516 | ||
3f518509 MW |
5517 | mvpp2_rxq_drop_pkts(port, rxq); |
5518 | ||
5519 | if (rxq->descs) | |
5520 | dma_free_coherent(port->dev->dev.parent, | |
5521 | rxq->size * MVPP2_DESC_ALIGNED_SIZE, | |
5522 | rxq->descs, | |
20396136 | 5523 | rxq->descs_dma); |
3f518509 MW |
5524 | |
5525 | rxq->descs = NULL; | |
5526 | rxq->last_desc = 0; | |
5527 | rxq->next_desc_to_proc = 0; | |
20396136 | 5528 | rxq->descs_dma = 0; |
3f518509 MW |
5529 | |
5530 | /* Clear Rx descriptors queue starting address and size; | |
5531 | * free descriptor number | |
5532 | */ | |
5533 | mvpp2_write(port->priv, MVPP2_RXQ_STATUS_REG(rxq->id), 0); | |
a704bb5c | 5534 | cpu = get_cpu(); |
a786841d TP |
5535 | mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_NUM_REG, rxq->id); |
5536 | mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_DESC_ADDR_REG, 0); | |
5537 | mvpp2_percpu_write(port->priv, cpu, MVPP2_RXQ_DESC_SIZE_REG, 0); | |
a704bb5c | 5538 | put_cpu(); |
3f518509 MW |
5539 | } |
5540 | ||
5541 | /* Create and initialize a Tx queue */ | |
5542 | static int mvpp2_txq_init(struct mvpp2_port *port, | |
5543 | struct mvpp2_tx_queue *txq) | |
5544 | { | |
5545 | u32 val; | |
5546 | int cpu, desc, desc_per_txq, tx_port_num; | |
5547 | struct mvpp2_txq_pcpu *txq_pcpu; | |
5548 | ||
5549 | txq->size = port->tx_ring_size; | |
5550 | ||
5551 | /* Allocate memory for Tx descriptors */ | |
5552 | txq->descs = dma_alloc_coherent(port->dev->dev.parent, | |
5553 | txq->size * MVPP2_DESC_ALIGNED_SIZE, | |
20396136 | 5554 | &txq->descs_dma, GFP_KERNEL); |
3f518509 MW |
5555 | if (!txq->descs) |
5556 | return -ENOMEM; | |
5557 | ||
3f518509 MW |
5558 | txq->last_desc = txq->size - 1; |
5559 | ||
5560 | /* Set Tx descriptors queue starting address - indirect access */ | |
a704bb5c | 5561 | cpu = get_cpu(); |
a786841d TP |
5562 | mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_NUM_REG, txq->id); |
5563 | mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_DESC_ADDR_REG, | |
5564 | txq->descs_dma); | |
5565 | mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_DESC_SIZE_REG, | |
5566 | txq->size & MVPP2_TXQ_DESC_SIZE_MASK); | |
5567 | mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_INDEX_REG, 0); | |
5568 | mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_RSVD_CLR_REG, | |
5569 | txq->id << MVPP2_TXQ_RSVD_CLR_OFFSET); | |
5570 | val = mvpp2_percpu_read(port->priv, cpu, MVPP2_TXQ_PENDING_REG); | |
3f518509 | 5571 | val &= ~MVPP2_TXQ_PENDING_MASK; |
a786841d | 5572 | mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_PENDING_REG, val); |
3f518509 MW |
5573 | |
5574 | /* Calculate base address in prefetch buffer. We reserve 16 descriptors | |
5575 | * for each existing TXQ. | |
5576 | * TCONTS for PON port must be continuous from 0 to MVPP2_MAX_TCONT | |
5577 | * GBE ports assumed to be continious from 0 to MVPP2_MAX_PORTS | |
5578 | */ | |
5579 | desc_per_txq = 16; | |
5580 | desc = (port->id * MVPP2_MAX_TXQ * desc_per_txq) + | |
5581 | (txq->log_id * desc_per_txq); | |
5582 | ||
a786841d TP |
5583 | mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_PREF_BUF_REG, |
5584 | MVPP2_PREF_BUF_PTR(desc) | MVPP2_PREF_BUF_SIZE_16 | | |
5585 | MVPP2_PREF_BUF_THRESH(desc_per_txq / 2)); | |
a704bb5c | 5586 | put_cpu(); |
3f518509 MW |
5587 | |
5588 | /* WRR / EJP configuration - indirect access */ | |
5589 | tx_port_num = mvpp2_egress_port(port); | |
5590 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num); | |
5591 | ||
5592 | val = mvpp2_read(port->priv, MVPP2_TXQ_SCHED_REFILL_REG(txq->log_id)); | |
5593 | val &= ~MVPP2_TXQ_REFILL_PERIOD_ALL_MASK; | |
5594 | val |= MVPP2_TXQ_REFILL_PERIOD_MASK(1); | |
5595 | val |= MVPP2_TXQ_REFILL_TOKENS_ALL_MASK; | |
5596 | mvpp2_write(port->priv, MVPP2_TXQ_SCHED_REFILL_REG(txq->log_id), val); | |
5597 | ||
5598 | val = MVPP2_TXQ_TOKEN_SIZE_MAX; | |
5599 | mvpp2_write(port->priv, MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq->log_id), | |
5600 | val); | |
5601 | ||
5602 | for_each_present_cpu(cpu) { | |
5603 | txq_pcpu = per_cpu_ptr(txq->pcpu, cpu); | |
5604 | txq_pcpu->size = txq->size; | |
02c91ece ME |
5605 | txq_pcpu->buffs = kmalloc_array(txq_pcpu->size, |
5606 | sizeof(*txq_pcpu->buffs), | |
5607 | GFP_KERNEL); | |
8354491c | 5608 | if (!txq_pcpu->buffs) |
20b1e16e | 5609 | goto cleanup; |
3f518509 MW |
5610 | |
5611 | txq_pcpu->count = 0; | |
5612 | txq_pcpu->reserved_num = 0; | |
5613 | txq_pcpu->txq_put_index = 0; | |
5614 | txq_pcpu->txq_get_index = 0; | |
186cd4d4 AT |
5615 | |
5616 | txq_pcpu->tso_headers = | |
5617 | dma_alloc_coherent(port->dev->dev.parent, | |
822eaf7c | 5618 | txq_pcpu->size * TSO_HEADER_SIZE, |
186cd4d4 AT |
5619 | &txq_pcpu->tso_headers_dma, |
5620 | GFP_KERNEL); | |
5621 | if (!txq_pcpu->tso_headers) | |
5622 | goto cleanup; | |
3f518509 MW |
5623 | } |
5624 | ||
5625 | return 0; | |
20b1e16e | 5626 | cleanup: |
71ce391d MW |
5627 | for_each_present_cpu(cpu) { |
5628 | txq_pcpu = per_cpu_ptr(txq->pcpu, cpu); | |
8354491c | 5629 | kfree(txq_pcpu->buffs); |
186cd4d4 AT |
5630 | |
5631 | dma_free_coherent(port->dev->dev.parent, | |
822eaf7c | 5632 | txq_pcpu->size * TSO_HEADER_SIZE, |
186cd4d4 AT |
5633 | txq_pcpu->tso_headers, |
5634 | txq_pcpu->tso_headers_dma); | |
71ce391d MW |
5635 | } |
5636 | ||
5637 | dma_free_coherent(port->dev->dev.parent, | |
5638 | txq->size * MVPP2_DESC_ALIGNED_SIZE, | |
20396136 | 5639 | txq->descs, txq->descs_dma); |
71ce391d MW |
5640 | |
5641 | return -ENOMEM; | |
3f518509 MW |
5642 | } |
5643 | ||
5644 | /* Free allocated TXQ resources */ | |
5645 | static void mvpp2_txq_deinit(struct mvpp2_port *port, | |
5646 | struct mvpp2_tx_queue *txq) | |
5647 | { | |
5648 | struct mvpp2_txq_pcpu *txq_pcpu; | |
5649 | int cpu; | |
5650 | ||
5651 | for_each_present_cpu(cpu) { | |
5652 | txq_pcpu = per_cpu_ptr(txq->pcpu, cpu); | |
8354491c | 5653 | kfree(txq_pcpu->buffs); |
186cd4d4 AT |
5654 | |
5655 | dma_free_coherent(port->dev->dev.parent, | |
822eaf7c | 5656 | txq_pcpu->size * TSO_HEADER_SIZE, |
186cd4d4 AT |
5657 | txq_pcpu->tso_headers, |
5658 | txq_pcpu->tso_headers_dma); | |
3f518509 MW |
5659 | } |
5660 | ||
5661 | if (txq->descs) | |
5662 | dma_free_coherent(port->dev->dev.parent, | |
5663 | txq->size * MVPP2_DESC_ALIGNED_SIZE, | |
20396136 | 5664 | txq->descs, txq->descs_dma); |
3f518509 MW |
5665 | |
5666 | txq->descs = NULL; | |
5667 | txq->last_desc = 0; | |
5668 | txq->next_desc_to_proc = 0; | |
20396136 | 5669 | txq->descs_dma = 0; |
3f518509 MW |
5670 | |
5671 | /* Set minimum bandwidth for disabled TXQs */ | |
5672 | mvpp2_write(port->priv, MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(txq->id), 0); | |
5673 | ||
5674 | /* Set Tx descriptors queue starting address and size */ | |
a704bb5c | 5675 | cpu = get_cpu(); |
a786841d TP |
5676 | mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_NUM_REG, txq->id); |
5677 | mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_DESC_ADDR_REG, 0); | |
5678 | mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_DESC_SIZE_REG, 0); | |
a704bb5c | 5679 | put_cpu(); |
3f518509 MW |
5680 | } |
5681 | ||
5682 | /* Cleanup Tx ports */ | |
5683 | static void mvpp2_txq_clean(struct mvpp2_port *port, struct mvpp2_tx_queue *txq) | |
5684 | { | |
5685 | struct mvpp2_txq_pcpu *txq_pcpu; | |
5686 | int delay, pending, cpu; | |
5687 | u32 val; | |
5688 | ||
a704bb5c | 5689 | cpu = get_cpu(); |
a786841d TP |
5690 | mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_NUM_REG, txq->id); |
5691 | val = mvpp2_percpu_read(port->priv, cpu, MVPP2_TXQ_PREF_BUF_REG); | |
3f518509 | 5692 | val |= MVPP2_TXQ_DRAIN_EN_MASK; |
a786841d | 5693 | mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_PREF_BUF_REG, val); |
3f518509 MW |
5694 | |
5695 | /* The napi queue has been stopped so wait for all packets | |
5696 | * to be transmitted. | |
5697 | */ | |
5698 | delay = 0; | |
5699 | do { | |
5700 | if (delay >= MVPP2_TX_PENDING_TIMEOUT_MSEC) { | |
5701 | netdev_warn(port->dev, | |
5702 | "port %d: cleaning queue %d timed out\n", | |
5703 | port->id, txq->log_id); | |
5704 | break; | |
5705 | } | |
5706 | mdelay(1); | |
5707 | delay++; | |
5708 | ||
a786841d TP |
5709 | pending = mvpp2_percpu_read(port->priv, cpu, |
5710 | MVPP2_TXQ_PENDING_REG); | |
5711 | pending &= MVPP2_TXQ_PENDING_MASK; | |
3f518509 MW |
5712 | } while (pending); |
5713 | ||
5714 | val &= ~MVPP2_TXQ_DRAIN_EN_MASK; | |
a786841d | 5715 | mvpp2_percpu_write(port->priv, cpu, MVPP2_TXQ_PREF_BUF_REG, val); |
a704bb5c | 5716 | put_cpu(); |
3f518509 MW |
5717 | |
5718 | for_each_present_cpu(cpu) { | |
5719 | txq_pcpu = per_cpu_ptr(txq->pcpu, cpu); | |
5720 | ||
5721 | /* Release all packets */ | |
5722 | mvpp2_txq_bufs_free(port, txq, txq_pcpu, txq_pcpu->count); | |
5723 | ||
5724 | /* Reset queue */ | |
5725 | txq_pcpu->count = 0; | |
5726 | txq_pcpu->txq_put_index = 0; | |
5727 | txq_pcpu->txq_get_index = 0; | |
5728 | } | |
5729 | } | |
5730 | ||
5731 | /* Cleanup all Tx queues */ | |
5732 | static void mvpp2_cleanup_txqs(struct mvpp2_port *port) | |
5733 | { | |
5734 | struct mvpp2_tx_queue *txq; | |
5735 | int queue; | |
5736 | u32 val; | |
5737 | ||
5738 | val = mvpp2_read(port->priv, MVPP2_TX_PORT_FLUSH_REG); | |
5739 | ||
5740 | /* Reset Tx ports and delete Tx queues */ | |
5741 | val |= MVPP2_TX_PORT_FLUSH_MASK(port->id); | |
5742 | mvpp2_write(port->priv, MVPP2_TX_PORT_FLUSH_REG, val); | |
5743 | ||
09f83975 | 5744 | for (queue = 0; queue < port->ntxqs; queue++) { |
3f518509 MW |
5745 | txq = port->txqs[queue]; |
5746 | mvpp2_txq_clean(port, txq); | |
5747 | mvpp2_txq_deinit(port, txq); | |
5748 | } | |
5749 | ||
5750 | on_each_cpu(mvpp2_txq_sent_counter_clear, port, 1); | |
5751 | ||
5752 | val &= ~MVPP2_TX_PORT_FLUSH_MASK(port->id); | |
5753 | mvpp2_write(port->priv, MVPP2_TX_PORT_FLUSH_REG, val); | |
5754 | } | |
5755 | ||
5756 | /* Cleanup all Rx queues */ | |
5757 | static void mvpp2_cleanup_rxqs(struct mvpp2_port *port) | |
5758 | { | |
5759 | int queue; | |
5760 | ||
09f83975 | 5761 | for (queue = 0; queue < port->nrxqs; queue++) |
3f518509 MW |
5762 | mvpp2_rxq_deinit(port, port->rxqs[queue]); |
5763 | } | |
5764 | ||
5765 | /* Init all Rx queues for port */ | |
5766 | static int mvpp2_setup_rxqs(struct mvpp2_port *port) | |
5767 | { | |
5768 | int queue, err; | |
5769 | ||
09f83975 | 5770 | for (queue = 0; queue < port->nrxqs; queue++) { |
3f518509 MW |
5771 | err = mvpp2_rxq_init(port, port->rxqs[queue]); |
5772 | if (err) | |
5773 | goto err_cleanup; | |
5774 | } | |
5775 | return 0; | |
5776 | ||
5777 | err_cleanup: | |
5778 | mvpp2_cleanup_rxqs(port); | |
5779 | return err; | |
5780 | } | |
5781 | ||
5782 | /* Init all tx queues for port */ | |
5783 | static int mvpp2_setup_txqs(struct mvpp2_port *port) | |
5784 | { | |
5785 | struct mvpp2_tx_queue *txq; | |
5786 | int queue, err; | |
5787 | ||
09f83975 | 5788 | for (queue = 0; queue < port->ntxqs; queue++) { |
3f518509 MW |
5789 | txq = port->txqs[queue]; |
5790 | err = mvpp2_txq_init(port, txq); | |
5791 | if (err) | |
5792 | goto err_cleanup; | |
5793 | } | |
5794 | ||
213f428f TP |
5795 | if (port->has_tx_irqs) { |
5796 | mvpp2_tx_time_coal_set(port); | |
5797 | for (queue = 0; queue < port->ntxqs; queue++) { | |
5798 | txq = port->txqs[queue]; | |
5799 | mvpp2_tx_pkts_coal_set(port, txq); | |
5800 | } | |
5801 | } | |
5802 | ||
3f518509 MW |
5803 | on_each_cpu(mvpp2_txq_sent_counter_clear, port, 1); |
5804 | return 0; | |
5805 | ||
5806 | err_cleanup: | |
5807 | mvpp2_cleanup_txqs(port); | |
5808 | return err; | |
5809 | } | |
5810 | ||
5811 | /* The callback for per-port interrupt */ | |
5812 | static irqreturn_t mvpp2_isr(int irq, void *dev_id) | |
5813 | { | |
591f4cfa | 5814 | struct mvpp2_queue_vector *qv = dev_id; |
3f518509 | 5815 | |
591f4cfa | 5816 | mvpp2_qvec_interrupt_disable(qv); |
3f518509 | 5817 | |
591f4cfa | 5818 | napi_schedule(&qv->napi); |
3f518509 MW |
5819 | |
5820 | return IRQ_HANDLED; | |
5821 | } | |
5822 | ||
fd3651b2 AT |
5823 | /* Per-port interrupt for link status changes */ |
5824 | static irqreturn_t mvpp2_link_status_isr(int irq, void *dev_id) | |
5825 | { | |
5826 | struct mvpp2_port *port = (struct mvpp2_port *)dev_id; | |
5827 | struct net_device *dev = port->dev; | |
5828 | bool event = false, link = false; | |
5829 | u32 val; | |
5830 | ||
5831 | mvpp22_gop_mask_irq(port); | |
5832 | ||
5833 | if (port->gop_id == 0 && | |
5834 | port->phy_interface == PHY_INTERFACE_MODE_10GKR) { | |
5835 | val = readl(port->base + MVPP22_XLG_INT_STAT); | |
5836 | if (val & MVPP22_XLG_INT_STAT_LINK) { | |
5837 | event = true; | |
5838 | val = readl(port->base + MVPP22_XLG_STATUS); | |
5839 | if (val & MVPP22_XLG_STATUS_LINK_UP) | |
5840 | link = true; | |
5841 | } | |
5842 | } else if (phy_interface_mode_is_rgmii(port->phy_interface) || | |
5843 | port->phy_interface == PHY_INTERFACE_MODE_SGMII) { | |
5844 | val = readl(port->base + MVPP22_GMAC_INT_STAT); | |
5845 | if (val & MVPP22_GMAC_INT_STAT_LINK) { | |
5846 | event = true; | |
5847 | val = readl(port->base + MVPP2_GMAC_STATUS0); | |
5848 | if (val & MVPP2_GMAC_STATUS0_LINK_UP) | |
5849 | link = true; | |
5850 | } | |
5851 | } | |
5852 | ||
5853 | if (!netif_running(dev) || !event) | |
5854 | goto handled; | |
5855 | ||
5856 | if (link) { | |
5857 | mvpp2_interrupts_enable(port); | |
5858 | ||
5859 | mvpp2_egress_enable(port); | |
5860 | mvpp2_ingress_enable(port); | |
5861 | netif_carrier_on(dev); | |
5862 | netif_tx_wake_all_queues(dev); | |
5863 | } else { | |
5864 | netif_tx_stop_all_queues(dev); | |
5865 | netif_carrier_off(dev); | |
5866 | mvpp2_ingress_disable(port); | |
5867 | mvpp2_egress_disable(port); | |
5868 | ||
5869 | mvpp2_interrupts_disable(port); | |
5870 | } | |
5871 | ||
5872 | handled: | |
5873 | mvpp22_gop_unmask_irq(port); | |
5874 | return IRQ_HANDLED; | |
5875 | } | |
5876 | ||
65a2c09a AT |
5877 | static void mvpp2_gmac_set_autoneg(struct mvpp2_port *port, |
5878 | struct phy_device *phydev) | |
5879 | { | |
5880 | u32 val; | |
5881 | ||
5882 | if (port->phy_interface != PHY_INTERFACE_MODE_RGMII && | |
5883 | port->phy_interface != PHY_INTERFACE_MODE_RGMII_ID && | |
5884 | port->phy_interface != PHY_INTERFACE_MODE_RGMII_RXID && | |
5885 | port->phy_interface != PHY_INTERFACE_MODE_RGMII_TXID && | |
5886 | port->phy_interface != PHY_INTERFACE_MODE_SGMII) | |
5887 | return; | |
5888 | ||
5889 | val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG); | |
5890 | val &= ~(MVPP2_GMAC_CONFIG_MII_SPEED | | |
5891 | MVPP2_GMAC_CONFIG_GMII_SPEED | | |
5892 | MVPP2_GMAC_CONFIG_FULL_DUPLEX | | |
5893 | MVPP2_GMAC_AN_SPEED_EN | | |
5894 | MVPP2_GMAC_AN_DUPLEX_EN); | |
5895 | ||
5896 | if (phydev->duplex) | |
5897 | val |= MVPP2_GMAC_CONFIG_FULL_DUPLEX; | |
5898 | ||
5899 | if (phydev->speed == SPEED_1000) | |
5900 | val |= MVPP2_GMAC_CONFIG_GMII_SPEED; | |
5901 | else if (phydev->speed == SPEED_100) | |
5902 | val |= MVPP2_GMAC_CONFIG_MII_SPEED; | |
5903 | ||
5904 | writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG); | |
65a2c09a AT |
5905 | } |
5906 | ||
3f518509 MW |
5907 | /* Adjust link */ |
5908 | static void mvpp2_link_event(struct net_device *dev) | |
5909 | { | |
5910 | struct mvpp2_port *port = netdev_priv(dev); | |
8e07269d | 5911 | struct phy_device *phydev = dev->phydev; |
89273bc0 | 5912 | bool link_reconfigured = false; |
3f518509 MW |
5913 | u32 val; |
5914 | ||
5915 | if (phydev->link) { | |
89273bc0 AT |
5916 | if (port->phy_interface != phydev->interface && port->comphy) { |
5917 | /* disable current port for reconfiguration */ | |
5918 | mvpp2_interrupts_disable(port); | |
5919 | netif_carrier_off(port->dev); | |
5920 | mvpp2_port_disable(port); | |
5921 | phy_power_off(port->comphy); | |
5922 | ||
5923 | /* comphy reconfiguration */ | |
5924 | port->phy_interface = phydev->interface; | |
5925 | mvpp22_comphy_init(port); | |
5926 | ||
5927 | /* gop/mac reconfiguration */ | |
5928 | mvpp22_gop_init(port); | |
5929 | mvpp2_port_mii_set(port); | |
5930 | ||
5931 | link_reconfigured = true; | |
5932 | } | |
5933 | ||
3f518509 MW |
5934 | if ((port->speed != phydev->speed) || |
5935 | (port->duplex != phydev->duplex)) { | |
65a2c09a | 5936 | mvpp2_gmac_set_autoneg(port, phydev); |
3f518509 MW |
5937 | |
5938 | port->duplex = phydev->duplex; | |
5939 | port->speed = phydev->speed; | |
5940 | } | |
5941 | } | |
5942 | ||
89273bc0 | 5943 | if (phydev->link != port->link || link_reconfigured) { |
3f518509 | 5944 | port->link = phydev->link; |
3f518509 | 5945 | |
3f518509 | 5946 | if (phydev->link) { |
65a2c09a AT |
5947 | if (port->phy_interface == PHY_INTERFACE_MODE_RGMII || |
5948 | port->phy_interface == PHY_INTERFACE_MODE_RGMII_ID || | |
5949 | port->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID || | |
5950 | port->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID || | |
5951 | port->phy_interface == PHY_INTERFACE_MODE_SGMII) { | |
5952 | val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG); | |
5953 | val |= (MVPP2_GMAC_FORCE_LINK_PASS | | |
5954 | MVPP2_GMAC_FORCE_LINK_DOWN); | |
5955 | writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG); | |
5956 | } | |
f55744ad AT |
5957 | |
5958 | mvpp2_interrupts_enable(port); | |
5959 | mvpp2_port_enable(port); | |
5960 | ||
3f518509 MW |
5961 | mvpp2_egress_enable(port); |
5962 | mvpp2_ingress_enable(port); | |
f55744ad AT |
5963 | netif_carrier_on(dev); |
5964 | netif_tx_wake_all_queues(dev); | |
3f518509 | 5965 | } else { |
968b211c AT |
5966 | port->duplex = -1; |
5967 | port->speed = 0; | |
5968 | ||
f55744ad AT |
5969 | netif_tx_stop_all_queues(dev); |
5970 | netif_carrier_off(dev); | |
3f518509 MW |
5971 | mvpp2_ingress_disable(port); |
5972 | mvpp2_egress_disable(port); | |
f55744ad AT |
5973 | |
5974 | mvpp2_port_disable(port); | |
5975 | mvpp2_interrupts_disable(port); | |
3f518509 | 5976 | } |
968b211c | 5977 | |
3f518509 MW |
5978 | phy_print_status(phydev); |
5979 | } | |
5980 | } | |
5981 | ||
edc660fa MW |
5982 | static void mvpp2_timer_set(struct mvpp2_port_pcpu *port_pcpu) |
5983 | { | |
5984 | ktime_t interval; | |
5985 | ||
5986 | if (!port_pcpu->timer_scheduled) { | |
5987 | port_pcpu->timer_scheduled = true; | |
8b0e1953 | 5988 | interval = MVPP2_TXDONE_HRTIMER_PERIOD_NS; |
edc660fa MW |
5989 | hrtimer_start(&port_pcpu->tx_done_timer, interval, |
5990 | HRTIMER_MODE_REL_PINNED); | |
5991 | } | |
5992 | } | |
5993 | ||
5994 | static void mvpp2_tx_proc_cb(unsigned long data) | |
5995 | { | |
5996 | struct net_device *dev = (struct net_device *)data; | |
5997 | struct mvpp2_port *port = netdev_priv(dev); | |
5998 | struct mvpp2_port_pcpu *port_pcpu = this_cpu_ptr(port->pcpu); | |
5999 | unsigned int tx_todo, cause; | |
6000 | ||
6001 | if (!netif_running(dev)) | |
6002 | return; | |
6003 | port_pcpu->timer_scheduled = false; | |
6004 | ||
6005 | /* Process all the Tx queues */ | |
09f83975 | 6006 | cause = (1 << port->ntxqs) - 1; |
213f428f | 6007 | tx_todo = mvpp2_tx_done(port, cause, smp_processor_id()); |
edc660fa MW |
6008 | |
6009 | /* Set the timer in case not all the packets were processed */ | |
6010 | if (tx_todo) | |
6011 | mvpp2_timer_set(port_pcpu); | |
6012 | } | |
6013 | ||
6014 | static enum hrtimer_restart mvpp2_hr_timer_cb(struct hrtimer *timer) | |
6015 | { | |
6016 | struct mvpp2_port_pcpu *port_pcpu = container_of(timer, | |
6017 | struct mvpp2_port_pcpu, | |
6018 | tx_done_timer); | |
6019 | ||
6020 | tasklet_schedule(&port_pcpu->tx_done_tasklet); | |
6021 | ||
6022 | return HRTIMER_NORESTART; | |
6023 | } | |
6024 | ||
3f518509 MW |
6025 | /* Main RX/TX processing routines */ |
6026 | ||
6027 | /* Display more error info */ | |
6028 | static void mvpp2_rx_error(struct mvpp2_port *port, | |
6029 | struct mvpp2_rx_desc *rx_desc) | |
6030 | { | |
ac3dd277 TP |
6031 | u32 status = mvpp2_rxdesc_status_get(port, rx_desc); |
6032 | size_t sz = mvpp2_rxdesc_size_get(port, rx_desc); | |
3f518509 MW |
6033 | |
6034 | switch (status & MVPP2_RXD_ERR_CODE_MASK) { | |
6035 | case MVPP2_RXD_ERR_CRC: | |
ac3dd277 TP |
6036 | netdev_err(port->dev, "bad rx status %08x (crc error), size=%zu\n", |
6037 | status, sz); | |
3f518509 MW |
6038 | break; |
6039 | case MVPP2_RXD_ERR_OVERRUN: | |
ac3dd277 TP |
6040 | netdev_err(port->dev, "bad rx status %08x (overrun error), size=%zu\n", |
6041 | status, sz); | |
3f518509 MW |
6042 | break; |
6043 | case MVPP2_RXD_ERR_RESOURCE: | |
ac3dd277 TP |
6044 | netdev_err(port->dev, "bad rx status %08x (resource error), size=%zu\n", |
6045 | status, sz); | |
3f518509 MW |
6046 | break; |
6047 | } | |
6048 | } | |
6049 | ||
6050 | /* Handle RX checksum offload */ | |
6051 | static void mvpp2_rx_csum(struct mvpp2_port *port, u32 status, | |
6052 | struct sk_buff *skb) | |
6053 | { | |
6054 | if (((status & MVPP2_RXD_L3_IP4) && | |
6055 | !(status & MVPP2_RXD_IP4_HEADER_ERR)) || | |
6056 | (status & MVPP2_RXD_L3_IP6)) | |
6057 | if (((status & MVPP2_RXD_L4_UDP) || | |
6058 | (status & MVPP2_RXD_L4_TCP)) && | |
6059 | (status & MVPP2_RXD_L4_CSUM_OK)) { | |
6060 | skb->csum = 0; | |
6061 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
6062 | return; | |
6063 | } | |
6064 | ||
6065 | skb->ip_summed = CHECKSUM_NONE; | |
6066 | } | |
6067 | ||
6068 | /* Reuse skb if possible, or allocate a new skb and add it to BM pool */ | |
6069 | static int mvpp2_rx_refill(struct mvpp2_port *port, | |
56b8aae9 | 6070 | struct mvpp2_bm_pool *bm_pool, int pool) |
3f518509 | 6071 | { |
20396136 | 6072 | dma_addr_t dma_addr; |
4e4a105f | 6073 | phys_addr_t phys_addr; |
0e037281 | 6074 | void *buf; |
3f518509 | 6075 | |
3f518509 | 6076 | /* No recycle or too many buffers are in use, so allocate a new skb */ |
4e4a105f TP |
6077 | buf = mvpp2_buf_alloc(port, bm_pool, &dma_addr, &phys_addr, |
6078 | GFP_ATOMIC); | |
0e037281 | 6079 | if (!buf) |
3f518509 MW |
6080 | return -ENOMEM; |
6081 | ||
7d7627ba | 6082 | mvpp2_bm_pool_put(port, pool, dma_addr, phys_addr); |
7ef7e1d9 | 6083 | |
3f518509 MW |
6084 | return 0; |
6085 | } | |
6086 | ||
6087 | /* Handle tx checksum */ | |
6088 | static u32 mvpp2_skb_tx_csum(struct mvpp2_port *port, struct sk_buff *skb) | |
6089 | { | |
6090 | if (skb->ip_summed == CHECKSUM_PARTIAL) { | |
6091 | int ip_hdr_len = 0; | |
6092 | u8 l4_proto; | |
6093 | ||
6094 | if (skb->protocol == htons(ETH_P_IP)) { | |
6095 | struct iphdr *ip4h = ip_hdr(skb); | |
6096 | ||
6097 | /* Calculate IPv4 checksum and L4 checksum */ | |
6098 | ip_hdr_len = ip4h->ihl; | |
6099 | l4_proto = ip4h->protocol; | |
6100 | } else if (skb->protocol == htons(ETH_P_IPV6)) { | |
6101 | struct ipv6hdr *ip6h = ipv6_hdr(skb); | |
6102 | ||
6103 | /* Read l4_protocol from one of IPv6 extra headers */ | |
6104 | if (skb_network_header_len(skb) > 0) | |
6105 | ip_hdr_len = (skb_network_header_len(skb) >> 2); | |
6106 | l4_proto = ip6h->nexthdr; | |
6107 | } else { | |
6108 | return MVPP2_TXD_L4_CSUM_NOT; | |
6109 | } | |
6110 | ||
6111 | return mvpp2_txq_desc_csum(skb_network_offset(skb), | |
6112 | skb->protocol, ip_hdr_len, l4_proto); | |
6113 | } | |
6114 | ||
6115 | return MVPP2_TXD_L4_CSUM_NOT | MVPP2_TXD_IP_CSUM_DISABLE; | |
6116 | } | |
6117 | ||
3f518509 | 6118 | /* Main rx processing */ |
591f4cfa TP |
6119 | static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi, |
6120 | int rx_todo, struct mvpp2_rx_queue *rxq) | |
3f518509 MW |
6121 | { |
6122 | struct net_device *dev = port->dev; | |
b5015854 MW |
6123 | int rx_received; |
6124 | int rx_done = 0; | |
3f518509 MW |
6125 | u32 rcvd_pkts = 0; |
6126 | u32 rcvd_bytes = 0; | |
6127 | ||
6128 | /* Get number of received packets and clamp the to-do */ | |
6129 | rx_received = mvpp2_rxq_received(port, rxq->id); | |
6130 | if (rx_todo > rx_received) | |
6131 | rx_todo = rx_received; | |
6132 | ||
b5015854 | 6133 | while (rx_done < rx_todo) { |
3f518509 MW |
6134 | struct mvpp2_rx_desc *rx_desc = mvpp2_rxq_next_desc_get(rxq); |
6135 | struct mvpp2_bm_pool *bm_pool; | |
6136 | struct sk_buff *skb; | |
0e037281 | 6137 | unsigned int frag_size; |
20396136 | 6138 | dma_addr_t dma_addr; |
ac3dd277 | 6139 | phys_addr_t phys_addr; |
56b8aae9 | 6140 | u32 rx_status; |
3f518509 | 6141 | int pool, rx_bytes, err; |
0e037281 | 6142 | void *data; |
3f518509 | 6143 | |
b5015854 | 6144 | rx_done++; |
ac3dd277 TP |
6145 | rx_status = mvpp2_rxdesc_status_get(port, rx_desc); |
6146 | rx_bytes = mvpp2_rxdesc_size_get(port, rx_desc); | |
6147 | rx_bytes -= MVPP2_MH_SIZE; | |
6148 | dma_addr = mvpp2_rxdesc_dma_addr_get(port, rx_desc); | |
6149 | phys_addr = mvpp2_rxdesc_cookie_get(port, rx_desc); | |
6150 | data = (void *)phys_to_virt(phys_addr); | |
6151 | ||
56b8aae9 TP |
6152 | pool = (rx_status & MVPP2_RXD_BM_POOL_ID_MASK) >> |
6153 | MVPP2_RXD_BM_POOL_ID_OFFS; | |
3f518509 | 6154 | bm_pool = &port->priv->bm_pools[pool]; |
3f518509 MW |
6155 | |
6156 | /* In case of an error, release the requested buffer pointer | |
6157 | * to the Buffer Manager. This request process is controlled | |
6158 | * by the hardware, and the information about the buffer is | |
6159 | * comprised by the RX descriptor. | |
6160 | */ | |
6161 | if (rx_status & MVPP2_RXD_ERR_SUMMARY) { | |
8a52488b | 6162 | err_drop_frame: |
3f518509 MW |
6163 | dev->stats.rx_errors++; |
6164 | mvpp2_rx_error(port, rx_desc); | |
b5015854 | 6165 | /* Return the buffer to the pool */ |
7d7627ba | 6166 | mvpp2_bm_pool_put(port, pool, dma_addr, phys_addr); |
3f518509 MW |
6167 | continue; |
6168 | } | |
6169 | ||
0e037281 TP |
6170 | if (bm_pool->frag_size > PAGE_SIZE) |
6171 | frag_size = 0; | |
6172 | else | |
6173 | frag_size = bm_pool->frag_size; | |
6174 | ||
6175 | skb = build_skb(data, frag_size); | |
6176 | if (!skb) { | |
6177 | netdev_warn(port->dev, "skb build failed\n"); | |
6178 | goto err_drop_frame; | |
6179 | } | |
3f518509 | 6180 | |
56b8aae9 | 6181 | err = mvpp2_rx_refill(port, bm_pool, pool); |
b5015854 MW |
6182 | if (err) { |
6183 | netdev_err(port->dev, "failed to refill BM pools\n"); | |
6184 | goto err_drop_frame; | |
6185 | } | |
6186 | ||
20396136 | 6187 | dma_unmap_single(dev->dev.parent, dma_addr, |
4229d502 MW |
6188 | bm_pool->buf_size, DMA_FROM_DEVICE); |
6189 | ||
3f518509 MW |
6190 | rcvd_pkts++; |
6191 | rcvd_bytes += rx_bytes; | |
3f518509 | 6192 | |
0e037281 | 6193 | skb_reserve(skb, MVPP2_MH_SIZE + NET_SKB_PAD); |
3f518509 MW |
6194 | skb_put(skb, rx_bytes); |
6195 | skb->protocol = eth_type_trans(skb, dev); | |
6196 | mvpp2_rx_csum(port, rx_status, skb); | |
6197 | ||
591f4cfa | 6198 | napi_gro_receive(napi, skb); |
3f518509 MW |
6199 | } |
6200 | ||
6201 | if (rcvd_pkts) { | |
6202 | struct mvpp2_pcpu_stats *stats = this_cpu_ptr(port->stats); | |
6203 | ||
6204 | u64_stats_update_begin(&stats->syncp); | |
6205 | stats->rx_packets += rcvd_pkts; | |
6206 | stats->rx_bytes += rcvd_bytes; | |
6207 | u64_stats_update_end(&stats->syncp); | |
6208 | } | |
6209 | ||
6210 | /* Update Rx queue management counters */ | |
6211 | wmb(); | |
b5015854 | 6212 | mvpp2_rxq_status_update(port, rxq->id, rx_done, rx_done); |
3f518509 MW |
6213 | |
6214 | return rx_todo; | |
6215 | } | |
6216 | ||
6217 | static inline void | |
ac3dd277 | 6218 | tx_desc_unmap_put(struct mvpp2_port *port, struct mvpp2_tx_queue *txq, |
3f518509 MW |
6219 | struct mvpp2_tx_desc *desc) |
6220 | { | |
20920267 AT |
6221 | struct mvpp2_txq_pcpu *txq_pcpu = this_cpu_ptr(txq->pcpu); |
6222 | ||
ac3dd277 TP |
6223 | dma_addr_t buf_dma_addr = |
6224 | mvpp2_txdesc_dma_addr_get(port, desc); | |
6225 | size_t buf_sz = | |
6226 | mvpp2_txdesc_size_get(port, desc); | |
20920267 AT |
6227 | if (!IS_TSO_HEADER(txq_pcpu, buf_dma_addr)) |
6228 | dma_unmap_single(port->dev->dev.parent, buf_dma_addr, | |
6229 | buf_sz, DMA_TO_DEVICE); | |
3f518509 MW |
6230 | mvpp2_txq_desc_put(txq); |
6231 | } | |
6232 | ||
6233 | /* Handle tx fragmentation processing */ | |
6234 | static int mvpp2_tx_frag_process(struct mvpp2_port *port, struct sk_buff *skb, | |
6235 | struct mvpp2_tx_queue *aggr_txq, | |
6236 | struct mvpp2_tx_queue *txq) | |
6237 | { | |
6238 | struct mvpp2_txq_pcpu *txq_pcpu = this_cpu_ptr(txq->pcpu); | |
6239 | struct mvpp2_tx_desc *tx_desc; | |
6240 | int i; | |
20396136 | 6241 | dma_addr_t buf_dma_addr; |
3f518509 MW |
6242 | |
6243 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | |
6244 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | |
6245 | void *addr = page_address(frag->page.p) + frag->page_offset; | |
6246 | ||
6247 | tx_desc = mvpp2_txq_next_desc_get(aggr_txq); | |
ac3dd277 TP |
6248 | mvpp2_txdesc_txq_set(port, tx_desc, txq->id); |
6249 | mvpp2_txdesc_size_set(port, tx_desc, frag->size); | |
3f518509 | 6250 | |
20396136 | 6251 | buf_dma_addr = dma_map_single(port->dev->dev.parent, addr, |
ac3dd277 TP |
6252 | frag->size, |
6253 | DMA_TO_DEVICE); | |
20396136 | 6254 | if (dma_mapping_error(port->dev->dev.parent, buf_dma_addr)) { |
3f518509 | 6255 | mvpp2_txq_desc_put(txq); |
32bae631 | 6256 | goto cleanup; |
3f518509 MW |
6257 | } |
6258 | ||
ac3dd277 TP |
6259 | mvpp2_txdesc_offset_set(port, tx_desc, |
6260 | buf_dma_addr & MVPP2_TX_DESC_ALIGN); | |
6261 | mvpp2_txdesc_dma_addr_set(port, tx_desc, | |
6262 | buf_dma_addr & ~MVPP2_TX_DESC_ALIGN); | |
3f518509 MW |
6263 | |
6264 | if (i == (skb_shinfo(skb)->nr_frags - 1)) { | |
6265 | /* Last descriptor */ | |
ac3dd277 TP |
6266 | mvpp2_txdesc_cmd_set(port, tx_desc, |
6267 | MVPP2_TXD_L_DESC); | |
6268 | mvpp2_txq_inc_put(port, txq_pcpu, skb, tx_desc); | |
3f518509 MW |
6269 | } else { |
6270 | /* Descriptor in the middle: Not First, Not Last */ | |
ac3dd277 TP |
6271 | mvpp2_txdesc_cmd_set(port, tx_desc, 0); |
6272 | mvpp2_txq_inc_put(port, txq_pcpu, NULL, tx_desc); | |
3f518509 MW |
6273 | } |
6274 | } | |
6275 | ||
6276 | return 0; | |
32bae631 | 6277 | cleanup: |
3f518509 MW |
6278 | /* Release all descriptors that were used to map fragments of |
6279 | * this packet, as well as the corresponding DMA mappings | |
6280 | */ | |
6281 | for (i = i - 1; i >= 0; i--) { | |
6282 | tx_desc = txq->descs + i; | |
ac3dd277 | 6283 | tx_desc_unmap_put(port, txq, tx_desc); |
3f518509 MW |
6284 | } |
6285 | ||
6286 | return -ENOMEM; | |
6287 | } | |
6288 | ||
186cd4d4 AT |
6289 | static inline void mvpp2_tso_put_hdr(struct sk_buff *skb, |
6290 | struct net_device *dev, | |
6291 | struct mvpp2_tx_queue *txq, | |
6292 | struct mvpp2_tx_queue *aggr_txq, | |
6293 | struct mvpp2_txq_pcpu *txq_pcpu, | |
6294 | int hdr_sz) | |
6295 | { | |
6296 | struct mvpp2_port *port = netdev_priv(dev); | |
6297 | struct mvpp2_tx_desc *tx_desc = mvpp2_txq_next_desc_get(aggr_txq); | |
6298 | dma_addr_t addr; | |
6299 | ||
6300 | mvpp2_txdesc_txq_set(port, tx_desc, txq->id); | |
6301 | mvpp2_txdesc_size_set(port, tx_desc, hdr_sz); | |
6302 | ||
6303 | addr = txq_pcpu->tso_headers_dma + | |
6304 | txq_pcpu->txq_put_index * TSO_HEADER_SIZE; | |
6305 | mvpp2_txdesc_offset_set(port, tx_desc, addr & MVPP2_TX_DESC_ALIGN); | |
6306 | mvpp2_txdesc_dma_addr_set(port, tx_desc, addr & ~MVPP2_TX_DESC_ALIGN); | |
6307 | ||
6308 | mvpp2_txdesc_cmd_set(port, tx_desc, mvpp2_skb_tx_csum(port, skb) | | |
6309 | MVPP2_TXD_F_DESC | | |
6310 | MVPP2_TXD_PADDING_DISABLE); | |
6311 | mvpp2_txq_inc_put(port, txq_pcpu, NULL, tx_desc); | |
6312 | } | |
6313 | ||
6314 | static inline int mvpp2_tso_put_data(struct sk_buff *skb, | |
6315 | struct net_device *dev, struct tso_t *tso, | |
6316 | struct mvpp2_tx_queue *txq, | |
6317 | struct mvpp2_tx_queue *aggr_txq, | |
6318 | struct mvpp2_txq_pcpu *txq_pcpu, | |
6319 | int sz, bool left, bool last) | |
6320 | { | |
6321 | struct mvpp2_port *port = netdev_priv(dev); | |
6322 | struct mvpp2_tx_desc *tx_desc = mvpp2_txq_next_desc_get(aggr_txq); | |
6323 | dma_addr_t buf_dma_addr; | |
6324 | ||
6325 | mvpp2_txdesc_txq_set(port, tx_desc, txq->id); | |
6326 | mvpp2_txdesc_size_set(port, tx_desc, sz); | |
6327 | ||
6328 | buf_dma_addr = dma_map_single(dev->dev.parent, tso->data, sz, | |
6329 | DMA_TO_DEVICE); | |
6330 | if (unlikely(dma_mapping_error(dev->dev.parent, buf_dma_addr))) { | |
6331 | mvpp2_txq_desc_put(txq); | |
6332 | return -ENOMEM; | |
6333 | } | |
6334 | ||
6335 | mvpp2_txdesc_offset_set(port, tx_desc, | |
6336 | buf_dma_addr & MVPP2_TX_DESC_ALIGN); | |
6337 | mvpp2_txdesc_dma_addr_set(port, tx_desc, | |
6338 | buf_dma_addr & ~MVPP2_TX_DESC_ALIGN); | |
6339 | ||
6340 | if (!left) { | |
6341 | mvpp2_txdesc_cmd_set(port, tx_desc, MVPP2_TXD_L_DESC); | |
6342 | if (last) { | |
6343 | mvpp2_txq_inc_put(port, txq_pcpu, skb, tx_desc); | |
6344 | return 0; | |
6345 | } | |
6346 | } else { | |
6347 | mvpp2_txdesc_cmd_set(port, tx_desc, 0); | |
6348 | } | |
6349 | ||
6350 | mvpp2_txq_inc_put(port, txq_pcpu, NULL, tx_desc); | |
6351 | return 0; | |
6352 | } | |
6353 | ||
6354 | static int mvpp2_tx_tso(struct sk_buff *skb, struct net_device *dev, | |
6355 | struct mvpp2_tx_queue *txq, | |
6356 | struct mvpp2_tx_queue *aggr_txq, | |
6357 | struct mvpp2_txq_pcpu *txq_pcpu) | |
6358 | { | |
6359 | struct mvpp2_port *port = netdev_priv(dev); | |
6360 | struct tso_t tso; | |
6361 | int hdr_sz = skb_transport_offset(skb) + tcp_hdrlen(skb); | |
6362 | int i, len, descs = 0; | |
6363 | ||
6364 | /* Check number of available descriptors */ | |
6365 | if (mvpp2_aggr_desc_num_check(port->priv, aggr_txq, | |
6366 | tso_count_descs(skb)) || | |
6367 | mvpp2_txq_reserved_desc_num_proc(port->priv, txq, txq_pcpu, | |
6368 | tso_count_descs(skb))) | |
6369 | return 0; | |
6370 | ||
6371 | tso_start(skb, &tso); | |
6372 | len = skb->len - hdr_sz; | |
6373 | while (len > 0) { | |
6374 | int left = min_t(int, skb_shinfo(skb)->gso_size, len); | |
6375 | char *hdr = txq_pcpu->tso_headers + | |
6376 | txq_pcpu->txq_put_index * TSO_HEADER_SIZE; | |
6377 | ||
6378 | len -= left; | |
6379 | descs++; | |
6380 | ||
6381 | tso_build_hdr(skb, hdr, &tso, left, len == 0); | |
6382 | mvpp2_tso_put_hdr(skb, dev, txq, aggr_txq, txq_pcpu, hdr_sz); | |
6383 | ||
6384 | while (left > 0) { | |
6385 | int sz = min_t(int, tso.size, left); | |
6386 | left -= sz; | |
6387 | descs++; | |
6388 | ||
6389 | if (mvpp2_tso_put_data(skb, dev, &tso, txq, aggr_txq, | |
6390 | txq_pcpu, sz, left, len == 0)) | |
6391 | goto release; | |
6392 | tso_build_data(skb, &tso, sz); | |
6393 | } | |
6394 | } | |
6395 | ||
6396 | return descs; | |
6397 | ||
6398 | release: | |
6399 | for (i = descs - 1; i >= 0; i--) { | |
6400 | struct mvpp2_tx_desc *tx_desc = txq->descs + i; | |
6401 | tx_desc_unmap_put(port, txq, tx_desc); | |
6402 | } | |
6403 | return 0; | |
6404 | } | |
6405 | ||
3f518509 MW |
6406 | /* Main tx processing */ |
6407 | static int mvpp2_tx(struct sk_buff *skb, struct net_device *dev) | |
6408 | { | |
6409 | struct mvpp2_port *port = netdev_priv(dev); | |
6410 | struct mvpp2_tx_queue *txq, *aggr_txq; | |
6411 | struct mvpp2_txq_pcpu *txq_pcpu; | |
6412 | struct mvpp2_tx_desc *tx_desc; | |
20396136 | 6413 | dma_addr_t buf_dma_addr; |
3f518509 MW |
6414 | int frags = 0; |
6415 | u16 txq_id; | |
6416 | u32 tx_cmd; | |
6417 | ||
6418 | txq_id = skb_get_queue_mapping(skb); | |
6419 | txq = port->txqs[txq_id]; | |
6420 | txq_pcpu = this_cpu_ptr(txq->pcpu); | |
6421 | aggr_txq = &port->priv->aggr_txqs[smp_processor_id()]; | |
6422 | ||
186cd4d4 AT |
6423 | if (skb_is_gso(skb)) { |
6424 | frags = mvpp2_tx_tso(skb, dev, txq, aggr_txq, txq_pcpu); | |
6425 | goto out; | |
6426 | } | |
3f518509 MW |
6427 | frags = skb_shinfo(skb)->nr_frags + 1; |
6428 | ||
6429 | /* Check number of available descriptors */ | |
6430 | if (mvpp2_aggr_desc_num_check(port->priv, aggr_txq, frags) || | |
6431 | mvpp2_txq_reserved_desc_num_proc(port->priv, txq, | |
6432 | txq_pcpu, frags)) { | |
6433 | frags = 0; | |
6434 | goto out; | |
6435 | } | |
6436 | ||
6437 | /* Get a descriptor for the first part of the packet */ | |
6438 | tx_desc = mvpp2_txq_next_desc_get(aggr_txq); | |
ac3dd277 TP |
6439 | mvpp2_txdesc_txq_set(port, tx_desc, txq->id); |
6440 | mvpp2_txdesc_size_set(port, tx_desc, skb_headlen(skb)); | |
3f518509 | 6441 | |
20396136 | 6442 | buf_dma_addr = dma_map_single(dev->dev.parent, skb->data, |
ac3dd277 | 6443 | skb_headlen(skb), DMA_TO_DEVICE); |
20396136 | 6444 | if (unlikely(dma_mapping_error(dev->dev.parent, buf_dma_addr))) { |
3f518509 MW |
6445 | mvpp2_txq_desc_put(txq); |
6446 | frags = 0; | |
6447 | goto out; | |
6448 | } | |
ac3dd277 TP |
6449 | |
6450 | mvpp2_txdesc_offset_set(port, tx_desc, | |
6451 | buf_dma_addr & MVPP2_TX_DESC_ALIGN); | |
6452 | mvpp2_txdesc_dma_addr_set(port, tx_desc, | |
6453 | buf_dma_addr & ~MVPP2_TX_DESC_ALIGN); | |
3f518509 MW |
6454 | |
6455 | tx_cmd = mvpp2_skb_tx_csum(port, skb); | |
6456 | ||
6457 | if (frags == 1) { | |
6458 | /* First and Last descriptor */ | |
6459 | tx_cmd |= MVPP2_TXD_F_DESC | MVPP2_TXD_L_DESC; | |
ac3dd277 TP |
6460 | mvpp2_txdesc_cmd_set(port, tx_desc, tx_cmd); |
6461 | mvpp2_txq_inc_put(port, txq_pcpu, skb, tx_desc); | |
3f518509 MW |
6462 | } else { |
6463 | /* First but not Last */ | |
6464 | tx_cmd |= MVPP2_TXD_F_DESC | MVPP2_TXD_PADDING_DISABLE; | |
ac3dd277 TP |
6465 | mvpp2_txdesc_cmd_set(port, tx_desc, tx_cmd); |
6466 | mvpp2_txq_inc_put(port, txq_pcpu, NULL, tx_desc); | |
3f518509 MW |
6467 | |
6468 | /* Continue with other skb fragments */ | |
6469 | if (mvpp2_tx_frag_process(port, skb, aggr_txq, txq)) { | |
ac3dd277 | 6470 | tx_desc_unmap_put(port, txq, tx_desc); |
3f518509 | 6471 | frags = 0; |
3f518509 MW |
6472 | } |
6473 | } | |
6474 | ||
3f518509 MW |
6475 | out: |
6476 | if (frags > 0) { | |
6477 | struct mvpp2_pcpu_stats *stats = this_cpu_ptr(port->stats); | |
186cd4d4 AT |
6478 | struct netdev_queue *nq = netdev_get_tx_queue(dev, txq_id); |
6479 | ||
6480 | txq_pcpu->reserved_num -= frags; | |
6481 | txq_pcpu->count += frags; | |
6482 | aggr_txq->count += frags; | |
6483 | ||
6484 | /* Enable transmit */ | |
6485 | wmb(); | |
6486 | mvpp2_aggr_txq_pend_desc_add(port, frags); | |
6487 | ||
6488 | if (txq_pcpu->size - txq_pcpu->count < MAX_SKB_FRAGS + 1) | |
6489 | netif_tx_stop_queue(nq); | |
3f518509 MW |
6490 | |
6491 | u64_stats_update_begin(&stats->syncp); | |
6492 | stats->tx_packets++; | |
6493 | stats->tx_bytes += skb->len; | |
6494 | u64_stats_update_end(&stats->syncp); | |
6495 | } else { | |
6496 | dev->stats.tx_dropped++; | |
6497 | dev_kfree_skb_any(skb); | |
6498 | } | |
6499 | ||
edc660fa | 6500 | /* Finalize TX processing */ |
082297e6 | 6501 | if (!port->has_tx_irqs && txq_pcpu->count >= txq->done_pkts_coal) |
edc660fa MW |
6502 | mvpp2_txq_done(port, txq, txq_pcpu); |
6503 | ||
6504 | /* Set the timer in case not all frags were processed */ | |
213f428f TP |
6505 | if (!port->has_tx_irqs && txq_pcpu->count <= frags && |
6506 | txq_pcpu->count > 0) { | |
edc660fa MW |
6507 | struct mvpp2_port_pcpu *port_pcpu = this_cpu_ptr(port->pcpu); |
6508 | ||
6509 | mvpp2_timer_set(port_pcpu); | |
6510 | } | |
6511 | ||
3f518509 MW |
6512 | return NETDEV_TX_OK; |
6513 | } | |
6514 | ||
6515 | static inline void mvpp2_cause_error(struct net_device *dev, int cause) | |
6516 | { | |
6517 | if (cause & MVPP2_CAUSE_FCS_ERR_MASK) | |
6518 | netdev_err(dev, "FCS error\n"); | |
6519 | if (cause & MVPP2_CAUSE_RX_FIFO_OVERRUN_MASK) | |
6520 | netdev_err(dev, "rx fifo overrun error\n"); | |
6521 | if (cause & MVPP2_CAUSE_TX_FIFO_UNDERRUN_MASK) | |
6522 | netdev_err(dev, "tx fifo underrun error\n"); | |
6523 | } | |
6524 | ||
edc660fa | 6525 | static int mvpp2_poll(struct napi_struct *napi, int budget) |
3f518509 | 6526 | { |
213f428f | 6527 | u32 cause_rx_tx, cause_rx, cause_tx, cause_misc; |
edc660fa MW |
6528 | int rx_done = 0; |
6529 | struct mvpp2_port *port = netdev_priv(napi->dev); | |
591f4cfa | 6530 | struct mvpp2_queue_vector *qv; |
a786841d | 6531 | int cpu = smp_processor_id(); |
3f518509 | 6532 | |
591f4cfa TP |
6533 | qv = container_of(napi, struct mvpp2_queue_vector, napi); |
6534 | ||
3f518509 MW |
6535 | /* Rx/Tx cause register |
6536 | * | |
6537 | * Bits 0-15: each bit indicates received packets on the Rx queue | |
6538 | * (bit 0 is for Rx queue 0). | |
6539 | * | |
6540 | * Bits 16-23: each bit indicates transmitted packets on the Tx queue | |
6541 | * (bit 16 is for Tx queue 0). | |
6542 | * | |
6543 | * Each CPU has its own Rx/Tx cause register | |
6544 | */ | |
213f428f | 6545 | cause_rx_tx = mvpp2_percpu_read(port->priv, qv->sw_thread_id, |
a786841d | 6546 | MVPP2_ISR_RX_TX_CAUSE_REG(port->id)); |
3f518509 | 6547 | |
213f428f | 6548 | cause_misc = cause_rx_tx & MVPP2_CAUSE_MISC_SUM_MASK; |
3f518509 MW |
6549 | if (cause_misc) { |
6550 | mvpp2_cause_error(port->dev, cause_misc); | |
6551 | ||
6552 | /* Clear the cause register */ | |
6553 | mvpp2_write(port->priv, MVPP2_ISR_MISC_CAUSE_REG, 0); | |
a786841d TP |
6554 | mvpp2_percpu_write(port->priv, cpu, |
6555 | MVPP2_ISR_RX_TX_CAUSE_REG(port->id), | |
6556 | cause_rx_tx & ~MVPP2_CAUSE_MISC_SUM_MASK); | |
3f518509 MW |
6557 | } |
6558 | ||
213f428f TP |
6559 | cause_tx = cause_rx_tx & MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK; |
6560 | if (cause_tx) { | |
6561 | cause_tx >>= MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_OFFSET; | |
6562 | mvpp2_tx_done(port, cause_tx, qv->sw_thread_id); | |
6563 | } | |
3f518509 MW |
6564 | |
6565 | /* Process RX packets */ | |
213f428f TP |
6566 | cause_rx = cause_rx_tx & MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK; |
6567 | cause_rx <<= qv->first_rxq; | |
591f4cfa | 6568 | cause_rx |= qv->pending_cause_rx; |
3f518509 MW |
6569 | while (cause_rx && budget > 0) { |
6570 | int count; | |
6571 | struct mvpp2_rx_queue *rxq; | |
6572 | ||
6573 | rxq = mvpp2_get_rx_queue(port, cause_rx); | |
6574 | if (!rxq) | |
6575 | break; | |
6576 | ||
591f4cfa | 6577 | count = mvpp2_rx(port, napi, budget, rxq); |
3f518509 MW |
6578 | rx_done += count; |
6579 | budget -= count; | |
6580 | if (budget > 0) { | |
6581 | /* Clear the bit associated to this Rx queue | |
6582 | * so that next iteration will continue from | |
6583 | * the next Rx queue. | |
6584 | */ | |
6585 | cause_rx &= ~(1 << rxq->logic_rxq); | |
6586 | } | |
6587 | } | |
6588 | ||
6589 | if (budget > 0) { | |
6590 | cause_rx = 0; | |
6ad20165 | 6591 | napi_complete_done(napi, rx_done); |
3f518509 | 6592 | |
591f4cfa | 6593 | mvpp2_qvec_interrupt_enable(qv); |
3f518509 | 6594 | } |
591f4cfa | 6595 | qv->pending_cause_rx = cause_rx; |
3f518509 MW |
6596 | return rx_done; |
6597 | } | |
6598 | ||
6599 | /* Set hw internals when starting port */ | |
6600 | static void mvpp2_start_dev(struct mvpp2_port *port) | |
6601 | { | |
8e07269d | 6602 | struct net_device *ndev = port->dev; |
591f4cfa | 6603 | int i; |
8e07269d | 6604 | |
76eb1b1d SC |
6605 | if (port->gop_id == 0 && |
6606 | (port->phy_interface == PHY_INTERFACE_MODE_XAUI || | |
6607 | port->phy_interface == PHY_INTERFACE_MODE_10GKR)) | |
6608 | mvpp2_xlg_max_rx_size_set(port); | |
6609 | else | |
6610 | mvpp2_gmac_max_rx_size_set(port); | |
6611 | ||
3f518509 MW |
6612 | mvpp2_txp_max_tx_size_set(port); |
6613 | ||
591f4cfa TP |
6614 | for (i = 0; i < port->nqvecs; i++) |
6615 | napi_enable(&port->qvecs[i].napi); | |
3f518509 MW |
6616 | |
6617 | /* Enable interrupts on all CPUs */ | |
6618 | mvpp2_interrupts_enable(port); | |
6619 | ||
542897d9 AT |
6620 | if (port->priv->hw_version == MVPP22) { |
6621 | mvpp22_comphy_init(port); | |
f84bf386 | 6622 | mvpp22_gop_init(port); |
542897d9 | 6623 | } |
f84bf386 | 6624 | |
2055d626 | 6625 | mvpp2_port_mii_set(port); |
3f518509 | 6626 | mvpp2_port_enable(port); |
5997c86b AT |
6627 | if (ndev->phydev) |
6628 | phy_start(ndev->phydev); | |
3f518509 MW |
6629 | netif_tx_start_all_queues(port->dev); |
6630 | } | |
6631 | ||
6632 | /* Set hw internals when stopping port */ | |
6633 | static void mvpp2_stop_dev(struct mvpp2_port *port) | |
6634 | { | |
8e07269d | 6635 | struct net_device *ndev = port->dev; |
591f4cfa | 6636 | int i; |
8e07269d | 6637 | |
3f518509 MW |
6638 | /* Stop new packets from arriving to RXQs */ |
6639 | mvpp2_ingress_disable(port); | |
6640 | ||
6641 | mdelay(10); | |
6642 | ||
6643 | /* Disable interrupts on all CPUs */ | |
6644 | mvpp2_interrupts_disable(port); | |
6645 | ||
591f4cfa TP |
6646 | for (i = 0; i < port->nqvecs; i++) |
6647 | napi_disable(&port->qvecs[i].napi); | |
3f518509 MW |
6648 | |
6649 | netif_carrier_off(port->dev); | |
6650 | netif_tx_stop_all_queues(port->dev); | |
6651 | ||
6652 | mvpp2_egress_disable(port); | |
6653 | mvpp2_port_disable(port); | |
5997c86b AT |
6654 | if (ndev->phydev) |
6655 | phy_stop(ndev->phydev); | |
542897d9 | 6656 | phy_power_off(port->comphy); |
3f518509 MW |
6657 | } |
6658 | ||
3f518509 MW |
6659 | static int mvpp2_check_ringparam_valid(struct net_device *dev, |
6660 | struct ethtool_ringparam *ring) | |
6661 | { | |
6662 | u16 new_rx_pending = ring->rx_pending; | |
6663 | u16 new_tx_pending = ring->tx_pending; | |
6664 | ||
6665 | if (ring->rx_pending == 0 || ring->tx_pending == 0) | |
6666 | return -EINVAL; | |
6667 | ||
6668 | if (ring->rx_pending > MVPP2_MAX_RXD) | |
6669 | new_rx_pending = MVPP2_MAX_RXD; | |
6670 | else if (!IS_ALIGNED(ring->rx_pending, 16)) | |
6671 | new_rx_pending = ALIGN(ring->rx_pending, 16); | |
6672 | ||
6673 | if (ring->tx_pending > MVPP2_MAX_TXD) | |
6674 | new_tx_pending = MVPP2_MAX_TXD; | |
6675 | else if (!IS_ALIGNED(ring->tx_pending, 32)) | |
6676 | new_tx_pending = ALIGN(ring->tx_pending, 32); | |
6677 | ||
6678 | if (ring->rx_pending != new_rx_pending) { | |
6679 | netdev_info(dev, "illegal Rx ring size value %d, round to %d\n", | |
6680 | ring->rx_pending, new_rx_pending); | |
6681 | ring->rx_pending = new_rx_pending; | |
6682 | } | |
6683 | ||
6684 | if (ring->tx_pending != new_tx_pending) { | |
6685 | netdev_info(dev, "illegal Tx ring size value %d, round to %d\n", | |
6686 | ring->tx_pending, new_tx_pending); | |
6687 | ring->tx_pending = new_tx_pending; | |
6688 | } | |
6689 | ||
6690 | return 0; | |
6691 | } | |
6692 | ||
26975821 | 6693 | static void mvpp21_get_mac_address(struct mvpp2_port *port, unsigned char *addr) |
3f518509 MW |
6694 | { |
6695 | u32 mac_addr_l, mac_addr_m, mac_addr_h; | |
6696 | ||
6697 | mac_addr_l = readl(port->base + MVPP2_GMAC_CTRL_1_REG); | |
6698 | mac_addr_m = readl(port->priv->lms_base + MVPP2_SRC_ADDR_MIDDLE); | |
6699 | mac_addr_h = readl(port->priv->lms_base + MVPP2_SRC_ADDR_HIGH); | |
6700 | addr[0] = (mac_addr_h >> 24) & 0xFF; | |
6701 | addr[1] = (mac_addr_h >> 16) & 0xFF; | |
6702 | addr[2] = (mac_addr_h >> 8) & 0xFF; | |
6703 | addr[3] = mac_addr_h & 0xFF; | |
6704 | addr[4] = mac_addr_m & 0xFF; | |
6705 | addr[5] = (mac_addr_l >> MVPP2_GMAC_SA_LOW_OFFS) & 0xFF; | |
6706 | } | |
6707 | ||
6708 | static int mvpp2_phy_connect(struct mvpp2_port *port) | |
6709 | { | |
6710 | struct phy_device *phy_dev; | |
6711 | ||
5997c86b AT |
6712 | /* No PHY is attached */ |
6713 | if (!port->phy_node) | |
6714 | return 0; | |
6715 | ||
3f518509 MW |
6716 | phy_dev = of_phy_connect(port->dev, port->phy_node, mvpp2_link_event, 0, |
6717 | port->phy_interface); | |
6718 | if (!phy_dev) { | |
6719 | netdev_err(port->dev, "cannot connect to phy\n"); | |
6720 | return -ENODEV; | |
6721 | } | |
6722 | phy_dev->supported &= PHY_GBIT_FEATURES; | |
6723 | phy_dev->advertising = phy_dev->supported; | |
6724 | ||
3f518509 MW |
6725 | port->link = 0; |
6726 | port->duplex = 0; | |
6727 | port->speed = 0; | |
6728 | ||
6729 | return 0; | |
6730 | } | |
6731 | ||
6732 | static void mvpp2_phy_disconnect(struct mvpp2_port *port) | |
6733 | { | |
8e07269d PR |
6734 | struct net_device *ndev = port->dev; |
6735 | ||
5997c86b AT |
6736 | if (!ndev->phydev) |
6737 | return; | |
6738 | ||
8e07269d | 6739 | phy_disconnect(ndev->phydev); |
3f518509 MW |
6740 | } |
6741 | ||
591f4cfa TP |
6742 | static int mvpp2_irqs_init(struct mvpp2_port *port) |
6743 | { | |
6744 | int err, i; | |
6745 | ||
6746 | for (i = 0; i < port->nqvecs; i++) { | |
6747 | struct mvpp2_queue_vector *qv = port->qvecs + i; | |
6748 | ||
6749 | err = request_irq(qv->irq, mvpp2_isr, 0, port->dev->name, qv); | |
6750 | if (err) | |
6751 | goto err; | |
213f428f TP |
6752 | |
6753 | if (qv->type == MVPP2_QUEUE_VECTOR_PRIVATE) | |
6754 | irq_set_affinity_hint(qv->irq, | |
6755 | cpumask_of(qv->sw_thread_id)); | |
591f4cfa TP |
6756 | } |
6757 | ||
6758 | return 0; | |
6759 | err: | |
6760 | for (i = 0; i < port->nqvecs; i++) { | |
6761 | struct mvpp2_queue_vector *qv = port->qvecs + i; | |
6762 | ||
213f428f | 6763 | irq_set_affinity_hint(qv->irq, NULL); |
591f4cfa TP |
6764 | free_irq(qv->irq, qv); |
6765 | } | |
6766 | ||
6767 | return err; | |
6768 | } | |
6769 | ||
6770 | static void mvpp2_irqs_deinit(struct mvpp2_port *port) | |
6771 | { | |
6772 | int i; | |
6773 | ||
6774 | for (i = 0; i < port->nqvecs; i++) { | |
6775 | struct mvpp2_queue_vector *qv = port->qvecs + i; | |
6776 | ||
213f428f | 6777 | irq_set_affinity_hint(qv->irq, NULL); |
591f4cfa TP |
6778 | free_irq(qv->irq, qv); |
6779 | } | |
6780 | } | |
6781 | ||
3f518509 MW |
6782 | static int mvpp2_open(struct net_device *dev) |
6783 | { | |
6784 | struct mvpp2_port *port = netdev_priv(dev); | |
fd3651b2 | 6785 | struct mvpp2 *priv = port->priv; |
3f518509 MW |
6786 | unsigned char mac_bcast[ETH_ALEN] = { |
6787 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
6788 | int err; | |
6789 | ||
6790 | err = mvpp2_prs_mac_da_accept(port->priv, port->id, mac_bcast, true); | |
6791 | if (err) { | |
6792 | netdev_err(dev, "mvpp2_prs_mac_da_accept BC failed\n"); | |
6793 | return err; | |
6794 | } | |
6795 | err = mvpp2_prs_mac_da_accept(port->priv, port->id, | |
6796 | dev->dev_addr, true); | |
6797 | if (err) { | |
6798 | netdev_err(dev, "mvpp2_prs_mac_da_accept MC failed\n"); | |
6799 | return err; | |
6800 | } | |
6801 | err = mvpp2_prs_tag_mode_set(port->priv, port->id, MVPP2_TAG_TYPE_MH); | |
6802 | if (err) { | |
6803 | netdev_err(dev, "mvpp2_prs_tag_mode_set failed\n"); | |
6804 | return err; | |
6805 | } | |
6806 | err = mvpp2_prs_def_flow(port); | |
6807 | if (err) { | |
6808 | netdev_err(dev, "mvpp2_prs_def_flow failed\n"); | |
6809 | return err; | |
6810 | } | |
6811 | ||
6812 | /* Allocate the Rx/Tx queues */ | |
6813 | err = mvpp2_setup_rxqs(port); | |
6814 | if (err) { | |
6815 | netdev_err(port->dev, "cannot allocate Rx queues\n"); | |
6816 | return err; | |
6817 | } | |
6818 | ||
6819 | err = mvpp2_setup_txqs(port); | |
6820 | if (err) { | |
6821 | netdev_err(port->dev, "cannot allocate Tx queues\n"); | |
6822 | goto err_cleanup_rxqs; | |
6823 | } | |
6824 | ||
591f4cfa | 6825 | err = mvpp2_irqs_init(port); |
3f518509 | 6826 | if (err) { |
591f4cfa | 6827 | netdev_err(port->dev, "cannot init IRQs\n"); |
3f518509 MW |
6828 | goto err_cleanup_txqs; |
6829 | } | |
6830 | ||
fd3651b2 AT |
6831 | if (priv->hw_version == MVPP22 && !port->phy_node && port->link_irq) { |
6832 | err = request_irq(port->link_irq, mvpp2_link_status_isr, 0, | |
6833 | dev->name, port); | |
6834 | if (err) { | |
6835 | netdev_err(port->dev, "cannot request link IRQ %d\n", | |
6836 | port->link_irq); | |
6837 | goto err_free_irq; | |
6838 | } | |
6839 | ||
6840 | mvpp22_gop_setup_irq(port); | |
6841 | } | |
6842 | ||
3f518509 MW |
6843 | /* In default link is down */ |
6844 | netif_carrier_off(port->dev); | |
6845 | ||
6846 | err = mvpp2_phy_connect(port); | |
6847 | if (err < 0) | |
fd3651b2 | 6848 | goto err_free_link_irq; |
3f518509 MW |
6849 | |
6850 | /* Unmask interrupts on all CPUs */ | |
6851 | on_each_cpu(mvpp2_interrupts_unmask, port, 1); | |
213f428f | 6852 | mvpp2_shared_interrupt_mask_unmask(port, false); |
3f518509 MW |
6853 | |
6854 | mvpp2_start_dev(port); | |
6855 | ||
6856 | return 0; | |
6857 | ||
fd3651b2 AT |
6858 | err_free_link_irq: |
6859 | if (priv->hw_version == MVPP22 && !port->phy_node && port->link_irq) | |
6860 | free_irq(port->link_irq, port); | |
3f518509 | 6861 | err_free_irq: |
591f4cfa | 6862 | mvpp2_irqs_deinit(port); |
3f518509 MW |
6863 | err_cleanup_txqs: |
6864 | mvpp2_cleanup_txqs(port); | |
6865 | err_cleanup_rxqs: | |
6866 | mvpp2_cleanup_rxqs(port); | |
6867 | return err; | |
6868 | } | |
6869 | ||
6870 | static int mvpp2_stop(struct net_device *dev) | |
6871 | { | |
6872 | struct mvpp2_port *port = netdev_priv(dev); | |
edc660fa | 6873 | struct mvpp2_port_pcpu *port_pcpu; |
fd3651b2 | 6874 | struct mvpp2 *priv = port->priv; |
edc660fa | 6875 | int cpu; |
3f518509 MW |
6876 | |
6877 | mvpp2_stop_dev(port); | |
6878 | mvpp2_phy_disconnect(port); | |
6879 | ||
6880 | /* Mask interrupts on all CPUs */ | |
6881 | on_each_cpu(mvpp2_interrupts_mask, port, 1); | |
213f428f | 6882 | mvpp2_shared_interrupt_mask_unmask(port, true); |
3f518509 | 6883 | |
fd3651b2 AT |
6884 | if (priv->hw_version == MVPP22 && !port->phy_node && port->link_irq) |
6885 | free_irq(port->link_irq, port); | |
6886 | ||
591f4cfa | 6887 | mvpp2_irqs_deinit(port); |
213f428f TP |
6888 | if (!port->has_tx_irqs) { |
6889 | for_each_present_cpu(cpu) { | |
6890 | port_pcpu = per_cpu_ptr(port->pcpu, cpu); | |
edc660fa | 6891 | |
213f428f TP |
6892 | hrtimer_cancel(&port_pcpu->tx_done_timer); |
6893 | port_pcpu->timer_scheduled = false; | |
6894 | tasklet_kill(&port_pcpu->tx_done_tasklet); | |
6895 | } | |
edc660fa | 6896 | } |
3f518509 MW |
6897 | mvpp2_cleanup_rxqs(port); |
6898 | mvpp2_cleanup_txqs(port); | |
6899 | ||
6900 | return 0; | |
6901 | } | |
6902 | ||
6903 | static void mvpp2_set_rx_mode(struct net_device *dev) | |
6904 | { | |
6905 | struct mvpp2_port *port = netdev_priv(dev); | |
6906 | struct mvpp2 *priv = port->priv; | |
6907 | struct netdev_hw_addr *ha; | |
6908 | int id = port->id; | |
6909 | bool allmulti = dev->flags & IFF_ALLMULTI; | |
6910 | ||
6911 | mvpp2_prs_mac_promisc_set(priv, id, dev->flags & IFF_PROMISC); | |
6912 | mvpp2_prs_mac_multi_set(priv, id, MVPP2_PE_MAC_MC_ALL, allmulti); | |
6913 | mvpp2_prs_mac_multi_set(priv, id, MVPP2_PE_MAC_MC_IP6, allmulti); | |
6914 | ||
6915 | /* Remove all port->id's mcast enries */ | |
6916 | mvpp2_prs_mcast_del_all(priv, id); | |
6917 | ||
6918 | if (allmulti && !netdev_mc_empty(dev)) { | |
6919 | netdev_for_each_mc_addr(ha, dev) | |
6920 | mvpp2_prs_mac_da_accept(priv, id, ha->addr, true); | |
6921 | } | |
6922 | } | |
6923 | ||
6924 | static int mvpp2_set_mac_address(struct net_device *dev, void *p) | |
6925 | { | |
6926 | struct mvpp2_port *port = netdev_priv(dev); | |
6927 | const struct sockaddr *addr = p; | |
6928 | int err; | |
6929 | ||
6930 | if (!is_valid_ether_addr(addr->sa_data)) { | |
6931 | err = -EADDRNOTAVAIL; | |
c1175547 | 6932 | goto log_error; |
3f518509 MW |
6933 | } |
6934 | ||
6935 | if (!netif_running(dev)) { | |
6936 | err = mvpp2_prs_update_mac_da(dev, addr->sa_data); | |
6937 | if (!err) | |
6938 | return 0; | |
6939 | /* Reconfigure parser to accept the original MAC address */ | |
6940 | err = mvpp2_prs_update_mac_da(dev, dev->dev_addr); | |
6941 | if (err) | |
c1175547 | 6942 | goto log_error; |
3f518509 MW |
6943 | } |
6944 | ||
6945 | mvpp2_stop_dev(port); | |
6946 | ||
6947 | err = mvpp2_prs_update_mac_da(dev, addr->sa_data); | |
6948 | if (!err) | |
6949 | goto out_start; | |
6950 | ||
6951 | /* Reconfigure parser accept the original MAC address */ | |
6952 | err = mvpp2_prs_update_mac_da(dev, dev->dev_addr); | |
6953 | if (err) | |
c1175547 | 6954 | goto log_error; |
3f518509 MW |
6955 | out_start: |
6956 | mvpp2_start_dev(port); | |
6957 | mvpp2_egress_enable(port); | |
6958 | mvpp2_ingress_enable(port); | |
6959 | return 0; | |
c1175547 | 6960 | log_error: |
dfd4240a | 6961 | netdev_err(dev, "failed to change MAC address\n"); |
3f518509 MW |
6962 | return err; |
6963 | } | |
6964 | ||
6965 | static int mvpp2_change_mtu(struct net_device *dev, int mtu) | |
6966 | { | |
6967 | struct mvpp2_port *port = netdev_priv(dev); | |
6968 | int err; | |
6969 | ||
5777987e JW |
6970 | if (!IS_ALIGNED(MVPP2_RX_PKT_SIZE(mtu), 8)) { |
6971 | netdev_info(dev, "illegal MTU value %d, round to %d\n", mtu, | |
6972 | ALIGN(MVPP2_RX_PKT_SIZE(mtu), 8)); | |
6973 | mtu = ALIGN(MVPP2_RX_PKT_SIZE(mtu), 8); | |
3f518509 MW |
6974 | } |
6975 | ||
6976 | if (!netif_running(dev)) { | |
6977 | err = mvpp2_bm_update_mtu(dev, mtu); | |
6978 | if (!err) { | |
6979 | port->pkt_size = MVPP2_RX_PKT_SIZE(mtu); | |
6980 | return 0; | |
6981 | } | |
6982 | ||
6983 | /* Reconfigure BM to the original MTU */ | |
6984 | err = mvpp2_bm_update_mtu(dev, dev->mtu); | |
6985 | if (err) | |
c1175547 | 6986 | goto log_error; |
3f518509 MW |
6987 | } |
6988 | ||
6989 | mvpp2_stop_dev(port); | |
6990 | ||
6991 | err = mvpp2_bm_update_mtu(dev, mtu); | |
6992 | if (!err) { | |
6993 | port->pkt_size = MVPP2_RX_PKT_SIZE(mtu); | |
6994 | goto out_start; | |
6995 | } | |
6996 | ||
6997 | /* Reconfigure BM to the original MTU */ | |
6998 | err = mvpp2_bm_update_mtu(dev, dev->mtu); | |
6999 | if (err) | |
c1175547 | 7000 | goto log_error; |
3f518509 MW |
7001 | |
7002 | out_start: | |
7003 | mvpp2_start_dev(port); | |
7004 | mvpp2_egress_enable(port); | |
7005 | mvpp2_ingress_enable(port); | |
7006 | ||
7007 | return 0; | |
c1175547 | 7008 | log_error: |
dfd4240a | 7009 | netdev_err(dev, "failed to change MTU\n"); |
3f518509 MW |
7010 | return err; |
7011 | } | |
7012 | ||
bc1f4470 | 7013 | static void |
3f518509 MW |
7014 | mvpp2_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
7015 | { | |
7016 | struct mvpp2_port *port = netdev_priv(dev); | |
7017 | unsigned int start; | |
7018 | int cpu; | |
7019 | ||
7020 | for_each_possible_cpu(cpu) { | |
7021 | struct mvpp2_pcpu_stats *cpu_stats; | |
7022 | u64 rx_packets; | |
7023 | u64 rx_bytes; | |
7024 | u64 tx_packets; | |
7025 | u64 tx_bytes; | |
7026 | ||
7027 | cpu_stats = per_cpu_ptr(port->stats, cpu); | |
7028 | do { | |
7029 | start = u64_stats_fetch_begin_irq(&cpu_stats->syncp); | |
7030 | rx_packets = cpu_stats->rx_packets; | |
7031 | rx_bytes = cpu_stats->rx_bytes; | |
7032 | tx_packets = cpu_stats->tx_packets; | |
7033 | tx_bytes = cpu_stats->tx_bytes; | |
7034 | } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start)); | |
7035 | ||
7036 | stats->rx_packets += rx_packets; | |
7037 | stats->rx_bytes += rx_bytes; | |
7038 | stats->tx_packets += tx_packets; | |
7039 | stats->tx_bytes += tx_bytes; | |
7040 | } | |
7041 | ||
7042 | stats->rx_errors = dev->stats.rx_errors; | |
7043 | stats->rx_dropped = dev->stats.rx_dropped; | |
7044 | stats->tx_dropped = dev->stats.tx_dropped; | |
3f518509 MW |
7045 | } |
7046 | ||
bd695a5f TP |
7047 | static int mvpp2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
7048 | { | |
bd695a5f TP |
7049 | int ret; |
7050 | ||
8e07269d | 7051 | if (!dev->phydev) |
bd695a5f TP |
7052 | return -ENOTSUPP; |
7053 | ||
8e07269d | 7054 | ret = phy_mii_ioctl(dev->phydev, ifr, cmd); |
bd695a5f TP |
7055 | if (!ret) |
7056 | mvpp2_link_event(dev); | |
7057 | ||
7058 | return ret; | |
7059 | } | |
7060 | ||
3f518509 MW |
7061 | /* Ethtool methods */ |
7062 | ||
3f518509 MW |
7063 | /* Set interrupt coalescing for ethtools */ |
7064 | static int mvpp2_ethtool_set_coalesce(struct net_device *dev, | |
7065 | struct ethtool_coalesce *c) | |
7066 | { | |
7067 | struct mvpp2_port *port = netdev_priv(dev); | |
7068 | int queue; | |
7069 | ||
09f83975 | 7070 | for (queue = 0; queue < port->nrxqs; queue++) { |
3f518509 MW |
7071 | struct mvpp2_rx_queue *rxq = port->rxqs[queue]; |
7072 | ||
7073 | rxq->time_coal = c->rx_coalesce_usecs; | |
7074 | rxq->pkts_coal = c->rx_max_coalesced_frames; | |
d63f9e41 TP |
7075 | mvpp2_rx_pkts_coal_set(port, rxq); |
7076 | mvpp2_rx_time_coal_set(port, rxq); | |
3f518509 MW |
7077 | } |
7078 | ||
213f428f TP |
7079 | if (port->has_tx_irqs) { |
7080 | port->tx_time_coal = c->tx_coalesce_usecs; | |
7081 | mvpp2_tx_time_coal_set(port); | |
7082 | } | |
7083 | ||
09f83975 | 7084 | for (queue = 0; queue < port->ntxqs; queue++) { |
3f518509 MW |
7085 | struct mvpp2_tx_queue *txq = port->txqs[queue]; |
7086 | ||
7087 | txq->done_pkts_coal = c->tx_max_coalesced_frames; | |
213f428f TP |
7088 | |
7089 | if (port->has_tx_irqs) | |
7090 | mvpp2_tx_pkts_coal_set(port, txq); | |
3f518509 MW |
7091 | } |
7092 | ||
3f518509 MW |
7093 | return 0; |
7094 | } | |
7095 | ||
7096 | /* get coalescing for ethtools */ | |
7097 | static int mvpp2_ethtool_get_coalesce(struct net_device *dev, | |
7098 | struct ethtool_coalesce *c) | |
7099 | { | |
7100 | struct mvpp2_port *port = netdev_priv(dev); | |
7101 | ||
7102 | c->rx_coalesce_usecs = port->rxqs[0]->time_coal; | |
7103 | c->rx_max_coalesced_frames = port->rxqs[0]->pkts_coal; | |
7104 | c->tx_max_coalesced_frames = port->txqs[0]->done_pkts_coal; | |
7105 | return 0; | |
7106 | } | |
7107 | ||
7108 | static void mvpp2_ethtool_get_drvinfo(struct net_device *dev, | |
7109 | struct ethtool_drvinfo *drvinfo) | |
7110 | { | |
7111 | strlcpy(drvinfo->driver, MVPP2_DRIVER_NAME, | |
7112 | sizeof(drvinfo->driver)); | |
7113 | strlcpy(drvinfo->version, MVPP2_DRIVER_VERSION, | |
7114 | sizeof(drvinfo->version)); | |
7115 | strlcpy(drvinfo->bus_info, dev_name(&dev->dev), | |
7116 | sizeof(drvinfo->bus_info)); | |
7117 | } | |
7118 | ||
7119 | static void mvpp2_ethtool_get_ringparam(struct net_device *dev, | |
7120 | struct ethtool_ringparam *ring) | |
7121 | { | |
7122 | struct mvpp2_port *port = netdev_priv(dev); | |
7123 | ||
7124 | ring->rx_max_pending = MVPP2_MAX_RXD; | |
7125 | ring->tx_max_pending = MVPP2_MAX_TXD; | |
7126 | ring->rx_pending = port->rx_ring_size; | |
7127 | ring->tx_pending = port->tx_ring_size; | |
7128 | } | |
7129 | ||
7130 | static int mvpp2_ethtool_set_ringparam(struct net_device *dev, | |
7131 | struct ethtool_ringparam *ring) | |
7132 | { | |
7133 | struct mvpp2_port *port = netdev_priv(dev); | |
7134 | u16 prev_rx_ring_size = port->rx_ring_size; | |
7135 | u16 prev_tx_ring_size = port->tx_ring_size; | |
7136 | int err; | |
7137 | ||
7138 | err = mvpp2_check_ringparam_valid(dev, ring); | |
7139 | if (err) | |
7140 | return err; | |
7141 | ||
7142 | if (!netif_running(dev)) { | |
7143 | port->rx_ring_size = ring->rx_pending; | |
7144 | port->tx_ring_size = ring->tx_pending; | |
7145 | return 0; | |
7146 | } | |
7147 | ||
7148 | /* The interface is running, so we have to force a | |
7149 | * reallocation of the queues | |
7150 | */ | |
7151 | mvpp2_stop_dev(port); | |
7152 | mvpp2_cleanup_rxqs(port); | |
7153 | mvpp2_cleanup_txqs(port); | |
7154 | ||
7155 | port->rx_ring_size = ring->rx_pending; | |
7156 | port->tx_ring_size = ring->tx_pending; | |
7157 | ||
7158 | err = mvpp2_setup_rxqs(port); | |
7159 | if (err) { | |
7160 | /* Reallocate Rx queues with the original ring size */ | |
7161 | port->rx_ring_size = prev_rx_ring_size; | |
7162 | ring->rx_pending = prev_rx_ring_size; | |
7163 | err = mvpp2_setup_rxqs(port); | |
7164 | if (err) | |
7165 | goto err_out; | |
7166 | } | |
7167 | err = mvpp2_setup_txqs(port); | |
7168 | if (err) { | |
7169 | /* Reallocate Tx queues with the original ring size */ | |
7170 | port->tx_ring_size = prev_tx_ring_size; | |
7171 | ring->tx_pending = prev_tx_ring_size; | |
7172 | err = mvpp2_setup_txqs(port); | |
7173 | if (err) | |
7174 | goto err_clean_rxqs; | |
7175 | } | |
7176 | ||
7177 | mvpp2_start_dev(port); | |
7178 | mvpp2_egress_enable(port); | |
7179 | mvpp2_ingress_enable(port); | |
7180 | ||
7181 | return 0; | |
7182 | ||
7183 | err_clean_rxqs: | |
7184 | mvpp2_cleanup_rxqs(port); | |
7185 | err_out: | |
dfd4240a | 7186 | netdev_err(dev, "failed to change ring parameters"); |
3f518509 MW |
7187 | return err; |
7188 | } | |
7189 | ||
7190 | /* Device ops */ | |
7191 | ||
7192 | static const struct net_device_ops mvpp2_netdev_ops = { | |
7193 | .ndo_open = mvpp2_open, | |
7194 | .ndo_stop = mvpp2_stop, | |
7195 | .ndo_start_xmit = mvpp2_tx, | |
7196 | .ndo_set_rx_mode = mvpp2_set_rx_mode, | |
7197 | .ndo_set_mac_address = mvpp2_set_mac_address, | |
7198 | .ndo_change_mtu = mvpp2_change_mtu, | |
7199 | .ndo_get_stats64 = mvpp2_get_stats64, | |
bd695a5f | 7200 | .ndo_do_ioctl = mvpp2_ioctl, |
3f518509 MW |
7201 | }; |
7202 | ||
7203 | static const struct ethtool_ops mvpp2_eth_tool_ops = { | |
00606c49 | 7204 | .nway_reset = phy_ethtool_nway_reset, |
3f518509 | 7205 | .get_link = ethtool_op_get_link, |
3f518509 MW |
7206 | .set_coalesce = mvpp2_ethtool_set_coalesce, |
7207 | .get_coalesce = mvpp2_ethtool_get_coalesce, | |
7208 | .get_drvinfo = mvpp2_ethtool_get_drvinfo, | |
7209 | .get_ringparam = mvpp2_ethtool_get_ringparam, | |
7210 | .set_ringparam = mvpp2_ethtool_set_ringparam, | |
fb773e97 PR |
7211 | .get_link_ksettings = phy_ethtool_get_link_ksettings, |
7212 | .set_link_ksettings = phy_ethtool_set_link_ksettings, | |
3f518509 MW |
7213 | }; |
7214 | ||
213f428f TP |
7215 | /* Used for PPv2.1, or PPv2.2 with the old Device Tree binding that |
7216 | * had a single IRQ defined per-port. | |
7217 | */ | |
7218 | static int mvpp2_simple_queue_vectors_init(struct mvpp2_port *port, | |
7219 | struct device_node *port_node) | |
591f4cfa TP |
7220 | { |
7221 | struct mvpp2_queue_vector *v = &port->qvecs[0]; | |
7222 | ||
7223 | v->first_rxq = 0; | |
7224 | v->nrxqs = port->nrxqs; | |
7225 | v->type = MVPP2_QUEUE_VECTOR_SHARED; | |
7226 | v->sw_thread_id = 0; | |
7227 | v->sw_thread_mask = *cpumask_bits(cpu_online_mask); | |
7228 | v->port = port; | |
7229 | v->irq = irq_of_parse_and_map(port_node, 0); | |
7230 | if (v->irq <= 0) | |
7231 | return -EINVAL; | |
7232 | netif_napi_add(port->dev, &v->napi, mvpp2_poll, | |
7233 | NAPI_POLL_WEIGHT); | |
7234 | ||
7235 | port->nqvecs = 1; | |
7236 | ||
7237 | return 0; | |
7238 | } | |
7239 | ||
213f428f TP |
7240 | static int mvpp2_multi_queue_vectors_init(struct mvpp2_port *port, |
7241 | struct device_node *port_node) | |
7242 | { | |
7243 | struct mvpp2_queue_vector *v; | |
7244 | int i, ret; | |
7245 | ||
7246 | port->nqvecs = num_possible_cpus(); | |
7247 | if (queue_mode == MVPP2_QDIST_SINGLE_MODE) | |
7248 | port->nqvecs += 1; | |
7249 | ||
7250 | for (i = 0; i < port->nqvecs; i++) { | |
7251 | char irqname[16]; | |
7252 | ||
7253 | v = port->qvecs + i; | |
7254 | ||
7255 | v->port = port; | |
7256 | v->type = MVPP2_QUEUE_VECTOR_PRIVATE; | |
7257 | v->sw_thread_id = i; | |
7258 | v->sw_thread_mask = BIT(i); | |
7259 | ||
7260 | snprintf(irqname, sizeof(irqname), "tx-cpu%d", i); | |
7261 | ||
7262 | if (queue_mode == MVPP2_QDIST_MULTI_MODE) { | |
7263 | v->first_rxq = i * MVPP2_DEFAULT_RXQ; | |
7264 | v->nrxqs = MVPP2_DEFAULT_RXQ; | |
7265 | } else if (queue_mode == MVPP2_QDIST_SINGLE_MODE && | |
7266 | i == (port->nqvecs - 1)) { | |
7267 | v->first_rxq = 0; | |
7268 | v->nrxqs = port->nrxqs; | |
7269 | v->type = MVPP2_QUEUE_VECTOR_SHARED; | |
7270 | strncpy(irqname, "rx-shared", sizeof(irqname)); | |
7271 | } | |
7272 | ||
7273 | v->irq = of_irq_get_byname(port_node, irqname); | |
7274 | if (v->irq <= 0) { | |
7275 | ret = -EINVAL; | |
7276 | goto err; | |
7277 | } | |
7278 | ||
7279 | netif_napi_add(port->dev, &v->napi, mvpp2_poll, | |
7280 | NAPI_POLL_WEIGHT); | |
7281 | } | |
7282 | ||
7283 | return 0; | |
7284 | ||
7285 | err: | |
7286 | for (i = 0; i < port->nqvecs; i++) | |
7287 | irq_dispose_mapping(port->qvecs[i].irq); | |
7288 | return ret; | |
7289 | } | |
7290 | ||
7291 | static int mvpp2_queue_vectors_init(struct mvpp2_port *port, | |
7292 | struct device_node *port_node) | |
7293 | { | |
7294 | if (port->has_tx_irqs) | |
7295 | return mvpp2_multi_queue_vectors_init(port, port_node); | |
7296 | else | |
7297 | return mvpp2_simple_queue_vectors_init(port, port_node); | |
7298 | } | |
7299 | ||
591f4cfa TP |
7300 | static void mvpp2_queue_vectors_deinit(struct mvpp2_port *port) |
7301 | { | |
7302 | int i; | |
7303 | ||
7304 | for (i = 0; i < port->nqvecs; i++) | |
7305 | irq_dispose_mapping(port->qvecs[i].irq); | |
7306 | } | |
7307 | ||
7308 | /* Configure Rx queue group interrupt for this port */ | |
7309 | static void mvpp2_rx_irqs_setup(struct mvpp2_port *port) | |
7310 | { | |
7311 | struct mvpp2 *priv = port->priv; | |
7312 | u32 val; | |
7313 | int i; | |
7314 | ||
7315 | if (priv->hw_version == MVPP21) { | |
7316 | mvpp2_write(priv, MVPP21_ISR_RXQ_GROUP_REG(port->id), | |
7317 | port->nrxqs); | |
7318 | return; | |
7319 | } | |
7320 | ||
7321 | /* Handle the more complicated PPv2.2 case */ | |
7322 | for (i = 0; i < port->nqvecs; i++) { | |
7323 | struct mvpp2_queue_vector *qv = port->qvecs + i; | |
7324 | ||
7325 | if (!qv->nrxqs) | |
7326 | continue; | |
7327 | ||
7328 | val = qv->sw_thread_id; | |
7329 | val |= port->id << MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_OFFSET; | |
7330 | mvpp2_write(priv, MVPP22_ISR_RXQ_GROUP_INDEX_REG, val); | |
7331 | ||
7332 | val = qv->first_rxq; | |
7333 | val |= qv->nrxqs << MVPP22_ISR_RXQ_SUB_GROUP_SIZE_OFFSET; | |
7334 | mvpp2_write(priv, MVPP22_ISR_RXQ_SUB_GROUP_CONFIG_REG, val); | |
7335 | } | |
7336 | } | |
7337 | ||
3f518509 MW |
7338 | /* Initialize port HW */ |
7339 | static int mvpp2_port_init(struct mvpp2_port *port) | |
7340 | { | |
7341 | struct device *dev = port->dev->dev.parent; | |
7342 | struct mvpp2 *priv = port->priv; | |
7343 | struct mvpp2_txq_pcpu *txq_pcpu; | |
7344 | int queue, cpu, err; | |
7345 | ||
09f83975 TP |
7346 | /* Checks for hardware constraints */ |
7347 | if (port->first_rxq + port->nrxqs > | |
59b9a31e | 7348 | MVPP2_MAX_PORTS * priv->max_port_rxqs) |
3f518509 MW |
7349 | return -EINVAL; |
7350 | ||
09f83975 TP |
7351 | if (port->nrxqs % 4 || (port->nrxqs > priv->max_port_rxqs) || |
7352 | (port->ntxqs > MVPP2_MAX_TXQ)) | |
7353 | return -EINVAL; | |
7354 | ||
3f518509 MW |
7355 | /* Disable port */ |
7356 | mvpp2_egress_disable(port); | |
7357 | mvpp2_port_disable(port); | |
7358 | ||
213f428f TP |
7359 | port->tx_time_coal = MVPP2_TXDONE_COAL_USEC; |
7360 | ||
09f83975 | 7361 | port->txqs = devm_kcalloc(dev, port->ntxqs, sizeof(*port->txqs), |
3f518509 MW |
7362 | GFP_KERNEL); |
7363 | if (!port->txqs) | |
7364 | return -ENOMEM; | |
7365 | ||
7366 | /* Associate physical Tx queues to this port and initialize. | |
7367 | * The mapping is predefined. | |
7368 | */ | |
09f83975 | 7369 | for (queue = 0; queue < port->ntxqs; queue++) { |
3f518509 MW |
7370 | int queue_phy_id = mvpp2_txq_phys(port->id, queue); |
7371 | struct mvpp2_tx_queue *txq; | |
7372 | ||
7373 | txq = devm_kzalloc(dev, sizeof(*txq), GFP_KERNEL); | |
177c8d1c CJ |
7374 | if (!txq) { |
7375 | err = -ENOMEM; | |
7376 | goto err_free_percpu; | |
7377 | } | |
3f518509 MW |
7378 | |
7379 | txq->pcpu = alloc_percpu(struct mvpp2_txq_pcpu); | |
7380 | if (!txq->pcpu) { | |
7381 | err = -ENOMEM; | |
7382 | goto err_free_percpu; | |
7383 | } | |
7384 | ||
7385 | txq->id = queue_phy_id; | |
7386 | txq->log_id = queue; | |
7387 | txq->done_pkts_coal = MVPP2_TXDONE_COAL_PKTS_THRESH; | |
7388 | for_each_present_cpu(cpu) { | |
7389 | txq_pcpu = per_cpu_ptr(txq->pcpu, cpu); | |
7390 | txq_pcpu->cpu = cpu; | |
7391 | } | |
7392 | ||
7393 | port->txqs[queue] = txq; | |
7394 | } | |
7395 | ||
09f83975 | 7396 | port->rxqs = devm_kcalloc(dev, port->nrxqs, sizeof(*port->rxqs), |
3f518509 MW |
7397 | GFP_KERNEL); |
7398 | if (!port->rxqs) { | |
7399 | err = -ENOMEM; | |
7400 | goto err_free_percpu; | |
7401 | } | |
7402 | ||
7403 | /* Allocate and initialize Rx queue for this port */ | |
09f83975 | 7404 | for (queue = 0; queue < port->nrxqs; queue++) { |
3f518509 MW |
7405 | struct mvpp2_rx_queue *rxq; |
7406 | ||
7407 | /* Map physical Rx queue to port's logical Rx queue */ | |
7408 | rxq = devm_kzalloc(dev, sizeof(*rxq), GFP_KERNEL); | |
d82b0c21 JZ |
7409 | if (!rxq) { |
7410 | err = -ENOMEM; | |
3f518509 | 7411 | goto err_free_percpu; |
d82b0c21 | 7412 | } |
3f518509 MW |
7413 | /* Map this Rx queue to a physical queue */ |
7414 | rxq->id = port->first_rxq + queue; | |
7415 | rxq->port = port->id; | |
7416 | rxq->logic_rxq = queue; | |
7417 | ||
7418 | port->rxqs[queue] = rxq; | |
7419 | } | |
7420 | ||
591f4cfa | 7421 | mvpp2_rx_irqs_setup(port); |
3f518509 MW |
7422 | |
7423 | /* Create Rx descriptor rings */ | |
09f83975 | 7424 | for (queue = 0; queue < port->nrxqs; queue++) { |
3f518509 MW |
7425 | struct mvpp2_rx_queue *rxq = port->rxqs[queue]; |
7426 | ||
7427 | rxq->size = port->rx_ring_size; | |
7428 | rxq->pkts_coal = MVPP2_RX_COAL_PKTS; | |
7429 | rxq->time_coal = MVPP2_RX_COAL_USEC; | |
7430 | } | |
7431 | ||
7432 | mvpp2_ingress_disable(port); | |
7433 | ||
7434 | /* Port default configuration */ | |
7435 | mvpp2_defaults_set(port); | |
7436 | ||
7437 | /* Port's classifier configuration */ | |
7438 | mvpp2_cls_oversize_rxq_set(port); | |
7439 | mvpp2_cls_port_config(port); | |
7440 | ||
7441 | /* Provide an initial Rx packet size */ | |
7442 | port->pkt_size = MVPP2_RX_PKT_SIZE(port->dev->mtu); | |
7443 | ||
7444 | /* Initialize pools for swf */ | |
7445 | err = mvpp2_swf_bm_pool_init(port); | |
7446 | if (err) | |
7447 | goto err_free_percpu; | |
7448 | ||
7449 | return 0; | |
7450 | ||
7451 | err_free_percpu: | |
09f83975 | 7452 | for (queue = 0; queue < port->ntxqs; queue++) { |
3f518509 MW |
7453 | if (!port->txqs[queue]) |
7454 | continue; | |
7455 | free_percpu(port->txqs[queue]->pcpu); | |
7456 | } | |
7457 | return err; | |
7458 | } | |
7459 | ||
213f428f TP |
7460 | /* Checks if the port DT description has the TX interrupts |
7461 | * described. On PPv2.1, there are no such interrupts. On PPv2.2, | |
7462 | * there are available, but we need to keep support for old DTs. | |
7463 | */ | |
7464 | static bool mvpp2_port_has_tx_irqs(struct mvpp2 *priv, | |
7465 | struct device_node *port_node) | |
7466 | { | |
7467 | char *irqs[5] = { "rx-shared", "tx-cpu0", "tx-cpu1", | |
7468 | "tx-cpu2", "tx-cpu3" }; | |
7469 | int ret, i; | |
7470 | ||
7471 | if (priv->hw_version == MVPP21) | |
7472 | return false; | |
7473 | ||
7474 | for (i = 0; i < 5; i++) { | |
7475 | ret = of_property_match_string(port_node, "interrupt-names", | |
7476 | irqs[i]); | |
7477 | if (ret < 0) | |
7478 | return false; | |
7479 | } | |
7480 | ||
7481 | return true; | |
7482 | } | |
7483 | ||
3ba8c81e AT |
7484 | static void mvpp2_port_copy_mac_addr(struct net_device *dev, struct mvpp2 *priv, |
7485 | struct device_node *port_node, | |
7486 | char **mac_from) | |
7487 | { | |
7488 | struct mvpp2_port *port = netdev_priv(dev); | |
7489 | char hw_mac_addr[ETH_ALEN] = {0}; | |
7490 | const char *dt_mac_addr; | |
7491 | ||
7492 | dt_mac_addr = of_get_mac_address(port_node); | |
7493 | if (dt_mac_addr && is_valid_ether_addr(dt_mac_addr)) { | |
7494 | *mac_from = "device tree"; | |
7495 | ether_addr_copy(dev->dev_addr, dt_mac_addr); | |
688cbaf2 AT |
7496 | return; |
7497 | } | |
d2a6e48e | 7498 | |
688cbaf2 AT |
7499 | if (priv->hw_version == MVPP21) { |
7500 | mvpp21_get_mac_address(port, hw_mac_addr); | |
7501 | if (is_valid_ether_addr(hw_mac_addr)) { | |
7502 | *mac_from = "hardware"; | |
7503 | ether_addr_copy(dev->dev_addr, hw_mac_addr); | |
7504 | return; | |
7505 | } | |
3ba8c81e | 7506 | } |
688cbaf2 AT |
7507 | |
7508 | *mac_from = "random"; | |
7509 | eth_hw_addr_random(dev); | |
3ba8c81e AT |
7510 | } |
7511 | ||
3f518509 MW |
7512 | /* Ports initialization */ |
7513 | static int mvpp2_port_probe(struct platform_device *pdev, | |
7514 | struct device_node *port_node, | |
6bf69a1d | 7515 | struct mvpp2 *priv, int index) |
3f518509 MW |
7516 | { |
7517 | struct device_node *phy_node; | |
542897d9 | 7518 | struct phy *comphy; |
3f518509 | 7519 | struct mvpp2_port *port; |
edc660fa | 7520 | struct mvpp2_port_pcpu *port_pcpu; |
3f518509 MW |
7521 | struct net_device *dev; |
7522 | struct resource *res; | |
3ba8c81e | 7523 | char *mac_from = ""; |
09f83975 | 7524 | unsigned int ntxqs, nrxqs; |
213f428f | 7525 | bool has_tx_irqs; |
3f518509 MW |
7526 | u32 id; |
7527 | int features; | |
7528 | int phy_mode; | |
edc660fa | 7529 | int err, i, cpu; |
3f518509 | 7530 | |
213f428f TP |
7531 | has_tx_irqs = mvpp2_port_has_tx_irqs(priv, port_node); |
7532 | ||
7533 | if (!has_tx_irqs) | |
7534 | queue_mode = MVPP2_QDIST_SINGLE_MODE; | |
7535 | ||
09f83975 | 7536 | ntxqs = MVPP2_MAX_TXQ; |
213f428f TP |
7537 | if (priv->hw_version == MVPP22 && queue_mode == MVPP2_QDIST_MULTI_MODE) |
7538 | nrxqs = MVPP2_DEFAULT_RXQ * num_possible_cpus(); | |
7539 | else | |
7540 | nrxqs = MVPP2_DEFAULT_RXQ; | |
09f83975 TP |
7541 | |
7542 | dev = alloc_etherdev_mqs(sizeof(*port), ntxqs, nrxqs); | |
3f518509 MW |
7543 | if (!dev) |
7544 | return -ENOMEM; | |
7545 | ||
7546 | phy_node = of_parse_phandle(port_node, "phy", 0); | |
3f518509 MW |
7547 | phy_mode = of_get_phy_mode(port_node); |
7548 | if (phy_mode < 0) { | |
7549 | dev_err(&pdev->dev, "incorrect phy mode\n"); | |
7550 | err = phy_mode; | |
7551 | goto err_free_netdev; | |
7552 | } | |
7553 | ||
542897d9 AT |
7554 | comphy = devm_of_phy_get(&pdev->dev, port_node, NULL); |
7555 | if (IS_ERR(comphy)) { | |
7556 | if (PTR_ERR(comphy) == -EPROBE_DEFER) { | |
7557 | err = -EPROBE_DEFER; | |
7558 | goto err_free_netdev; | |
7559 | } | |
7560 | comphy = NULL; | |
7561 | } | |
7562 | ||
3f518509 MW |
7563 | if (of_property_read_u32(port_node, "port-id", &id)) { |
7564 | err = -EINVAL; | |
7565 | dev_err(&pdev->dev, "missing port-id value\n"); | |
7566 | goto err_free_netdev; | |
7567 | } | |
7568 | ||
7569 | dev->tx_queue_len = MVPP2_MAX_TXD; | |
7570 | dev->watchdog_timeo = 5 * HZ; | |
7571 | dev->netdev_ops = &mvpp2_netdev_ops; | |
7572 | dev->ethtool_ops = &mvpp2_eth_tool_ops; | |
7573 | ||
7574 | port = netdev_priv(dev); | |
591f4cfa | 7575 | port->dev = dev; |
09f83975 TP |
7576 | port->ntxqs = ntxqs; |
7577 | port->nrxqs = nrxqs; | |
213f428f TP |
7578 | port->priv = priv; |
7579 | port->has_tx_irqs = has_tx_irqs; | |
3f518509 | 7580 | |
591f4cfa TP |
7581 | err = mvpp2_queue_vectors_init(port, port_node); |
7582 | if (err) | |
3f518509 | 7583 | goto err_free_netdev; |
3f518509 | 7584 | |
fd3651b2 AT |
7585 | port->link_irq = of_irq_get_byname(port_node, "link"); |
7586 | if (port->link_irq == -EPROBE_DEFER) { | |
7587 | err = -EPROBE_DEFER; | |
7588 | goto err_deinit_qvecs; | |
7589 | } | |
7590 | if (port->link_irq <= 0) | |
7591 | /* the link irq is optional */ | |
7592 | port->link_irq = 0; | |
7593 | ||
3f518509 MW |
7594 | if (of_property_read_bool(port_node, "marvell,loopback")) |
7595 | port->flags |= MVPP2_F_LOOPBACK; | |
7596 | ||
3f518509 | 7597 | port->id = id; |
59b9a31e | 7598 | if (priv->hw_version == MVPP21) |
09f83975 | 7599 | port->first_rxq = port->id * port->nrxqs; |
59b9a31e TP |
7600 | else |
7601 | port->first_rxq = port->id * priv->max_port_rxqs; | |
7602 | ||
3f518509 MW |
7603 | port->phy_node = phy_node; |
7604 | port->phy_interface = phy_mode; | |
542897d9 | 7605 | port->comphy = comphy; |
3f518509 | 7606 | |
a786841d TP |
7607 | if (priv->hw_version == MVPP21) { |
7608 | res = platform_get_resource(pdev, IORESOURCE_MEM, 2 + id); | |
7609 | port->base = devm_ioremap_resource(&pdev->dev, res); | |
7610 | if (IS_ERR(port->base)) { | |
7611 | err = PTR_ERR(port->base); | |
fd3651b2 | 7612 | goto err_free_irq; |
a786841d TP |
7613 | } |
7614 | } else { | |
7615 | if (of_property_read_u32(port_node, "gop-port-id", | |
7616 | &port->gop_id)) { | |
7617 | err = -EINVAL; | |
7618 | dev_err(&pdev->dev, "missing gop-port-id value\n"); | |
591f4cfa | 7619 | goto err_deinit_qvecs; |
a786841d TP |
7620 | } |
7621 | ||
7622 | port->base = priv->iface_base + MVPP22_GMAC_BASE(port->gop_id); | |
3f518509 MW |
7623 | } |
7624 | ||
7625 | /* Alloc per-cpu stats */ | |
7626 | port->stats = netdev_alloc_pcpu_stats(struct mvpp2_pcpu_stats); | |
7627 | if (!port->stats) { | |
7628 | err = -ENOMEM; | |
fd3651b2 | 7629 | goto err_free_irq; |
3f518509 MW |
7630 | } |
7631 | ||
3ba8c81e | 7632 | mvpp2_port_copy_mac_addr(dev, priv, port_node, &mac_from); |
3f518509 MW |
7633 | |
7634 | port->tx_ring_size = MVPP2_MAX_TXD; | |
7635 | port->rx_ring_size = MVPP2_MAX_RXD; | |
3f518509 MW |
7636 | SET_NETDEV_DEV(dev, &pdev->dev); |
7637 | ||
7638 | err = mvpp2_port_init(port); | |
7639 | if (err < 0) { | |
7640 | dev_err(&pdev->dev, "failed to init port %d\n", id); | |
7641 | goto err_free_stats; | |
7642 | } | |
26975821 | 7643 | |
26975821 TP |
7644 | mvpp2_port_periodic_xon_disable(port); |
7645 | ||
7646 | if (priv->hw_version == MVPP21) | |
7647 | mvpp2_port_fc_adv_enable(port); | |
7648 | ||
7649 | mvpp2_port_reset(port); | |
3f518509 | 7650 | |
edc660fa MW |
7651 | port->pcpu = alloc_percpu(struct mvpp2_port_pcpu); |
7652 | if (!port->pcpu) { | |
7653 | err = -ENOMEM; | |
7654 | goto err_free_txq_pcpu; | |
7655 | } | |
7656 | ||
213f428f TP |
7657 | if (!port->has_tx_irqs) { |
7658 | for_each_present_cpu(cpu) { | |
7659 | port_pcpu = per_cpu_ptr(port->pcpu, cpu); | |
edc660fa | 7660 | |
213f428f TP |
7661 | hrtimer_init(&port_pcpu->tx_done_timer, CLOCK_MONOTONIC, |
7662 | HRTIMER_MODE_REL_PINNED); | |
7663 | port_pcpu->tx_done_timer.function = mvpp2_hr_timer_cb; | |
7664 | port_pcpu->timer_scheduled = false; | |
edc660fa | 7665 | |
213f428f TP |
7666 | tasklet_init(&port_pcpu->tx_done_tasklet, |
7667 | mvpp2_tx_proc_cb, | |
7668 | (unsigned long)dev); | |
7669 | } | |
edc660fa MW |
7670 | } |
7671 | ||
186cd4d4 | 7672 | features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO; |
3f518509 MW |
7673 | dev->features = features | NETIF_F_RXCSUM; |
7674 | dev->hw_features |= features | NETIF_F_RXCSUM | NETIF_F_GRO; | |
7675 | dev->vlan_features |= features; | |
7676 | ||
5777987e JW |
7677 | /* MTU range: 68 - 9676 */ |
7678 | dev->min_mtu = ETH_MIN_MTU; | |
7679 | /* 9676 == 9700 - 20 and rounding to 8 */ | |
7680 | dev->max_mtu = 9676; | |
7681 | ||
3f518509 MW |
7682 | err = register_netdev(dev); |
7683 | if (err < 0) { | |
7684 | dev_err(&pdev->dev, "failed to register netdev\n"); | |
edc660fa | 7685 | goto err_free_port_pcpu; |
3f518509 MW |
7686 | } |
7687 | netdev_info(dev, "Using %s mac address %pM\n", mac_from, dev->dev_addr); | |
7688 | ||
6bf69a1d | 7689 | priv->port_list[index] = port; |
3f518509 MW |
7690 | return 0; |
7691 | ||
edc660fa MW |
7692 | err_free_port_pcpu: |
7693 | free_percpu(port->pcpu); | |
3f518509 | 7694 | err_free_txq_pcpu: |
09f83975 | 7695 | for (i = 0; i < port->ntxqs; i++) |
3f518509 MW |
7696 | free_percpu(port->txqs[i]->pcpu); |
7697 | err_free_stats: | |
7698 | free_percpu(port->stats); | |
fd3651b2 AT |
7699 | err_free_irq: |
7700 | if (port->link_irq) | |
7701 | irq_dispose_mapping(port->link_irq); | |
591f4cfa TP |
7702 | err_deinit_qvecs: |
7703 | mvpp2_queue_vectors_deinit(port); | |
3f518509 | 7704 | err_free_netdev: |
ccb80393 | 7705 | of_node_put(phy_node); |
3f518509 MW |
7706 | free_netdev(dev); |
7707 | return err; | |
7708 | } | |
7709 | ||
7710 | /* Ports removal routine */ | |
7711 | static void mvpp2_port_remove(struct mvpp2_port *port) | |
7712 | { | |
7713 | int i; | |
7714 | ||
7715 | unregister_netdev(port->dev); | |
ccb80393 | 7716 | of_node_put(port->phy_node); |
edc660fa | 7717 | free_percpu(port->pcpu); |
3f518509 | 7718 | free_percpu(port->stats); |
09f83975 | 7719 | for (i = 0; i < port->ntxqs; i++) |
3f518509 | 7720 | free_percpu(port->txqs[i]->pcpu); |
591f4cfa | 7721 | mvpp2_queue_vectors_deinit(port); |
fd3651b2 AT |
7722 | if (port->link_irq) |
7723 | irq_dispose_mapping(port->link_irq); | |
3f518509 MW |
7724 | free_netdev(port->dev); |
7725 | } | |
7726 | ||
7727 | /* Initialize decoding windows */ | |
7728 | static void mvpp2_conf_mbus_windows(const struct mbus_dram_target_info *dram, | |
7729 | struct mvpp2 *priv) | |
7730 | { | |
7731 | u32 win_enable; | |
7732 | int i; | |
7733 | ||
7734 | for (i = 0; i < 6; i++) { | |
7735 | mvpp2_write(priv, MVPP2_WIN_BASE(i), 0); | |
7736 | mvpp2_write(priv, MVPP2_WIN_SIZE(i), 0); | |
7737 | ||
7738 | if (i < 4) | |
7739 | mvpp2_write(priv, MVPP2_WIN_REMAP(i), 0); | |
7740 | } | |
7741 | ||
7742 | win_enable = 0; | |
7743 | ||
7744 | for (i = 0; i < dram->num_cs; i++) { | |
7745 | const struct mbus_dram_window *cs = dram->cs + i; | |
7746 | ||
7747 | mvpp2_write(priv, MVPP2_WIN_BASE(i), | |
7748 | (cs->base & 0xffff0000) | (cs->mbus_attr << 8) | | |
7749 | dram->mbus_dram_target_id); | |
7750 | ||
7751 | mvpp2_write(priv, MVPP2_WIN_SIZE(i), | |
7752 | (cs->size - 1) & 0xffff0000); | |
7753 | ||
7754 | win_enable |= (1 << i); | |
7755 | } | |
7756 | ||
7757 | mvpp2_write(priv, MVPP2_BASE_ADDR_ENABLE, win_enable); | |
7758 | } | |
7759 | ||
7760 | /* Initialize Rx FIFO's */ | |
7761 | static void mvpp2_rx_fifo_init(struct mvpp2 *priv) | |
7762 | { | |
7763 | int port; | |
7764 | ||
7765 | for (port = 0; port < MVPP2_MAX_PORTS; port++) { | |
7766 | mvpp2_write(priv, MVPP2_RX_DATA_FIFO_SIZE_REG(port), | |
7767 | MVPP2_RX_FIFO_PORT_DATA_SIZE); | |
7768 | mvpp2_write(priv, MVPP2_RX_ATTR_FIFO_SIZE_REG(port), | |
7769 | MVPP2_RX_FIFO_PORT_ATTR_SIZE); | |
7770 | } | |
7771 | ||
7772 | mvpp2_write(priv, MVPP2_RX_MIN_PKT_SIZE_REG, | |
7773 | MVPP2_RX_FIFO_PORT_MIN_PKT); | |
7774 | mvpp2_write(priv, MVPP2_RX_FIFO_INIT_REG, 0x1); | |
7775 | } | |
7776 | ||
6763ce31 TP |
7777 | static void mvpp2_axi_init(struct mvpp2 *priv) |
7778 | { | |
7779 | u32 val, rdval, wrval; | |
7780 | ||
7781 | mvpp2_write(priv, MVPP22_BM_ADDR_HIGH_RLS_REG, 0x0); | |
7782 | ||
7783 | /* AXI Bridge Configuration */ | |
7784 | ||
7785 | rdval = MVPP22_AXI_CODE_CACHE_RD_CACHE | |
7786 | << MVPP22_AXI_ATTR_CACHE_OFFS; | |
7787 | rdval |= MVPP22_AXI_CODE_DOMAIN_OUTER_DOM | |
7788 | << MVPP22_AXI_ATTR_DOMAIN_OFFS; | |
7789 | ||
7790 | wrval = MVPP22_AXI_CODE_CACHE_WR_CACHE | |
7791 | << MVPP22_AXI_ATTR_CACHE_OFFS; | |
7792 | wrval |= MVPP22_AXI_CODE_DOMAIN_OUTER_DOM | |
7793 | << MVPP22_AXI_ATTR_DOMAIN_OFFS; | |
7794 | ||
7795 | /* BM */ | |
7796 | mvpp2_write(priv, MVPP22_AXI_BM_WR_ATTR_REG, wrval); | |
7797 | mvpp2_write(priv, MVPP22_AXI_BM_RD_ATTR_REG, rdval); | |
7798 | ||
7799 | /* Descriptors */ | |
7800 | mvpp2_write(priv, MVPP22_AXI_AGGRQ_DESCR_RD_ATTR_REG, rdval); | |
7801 | mvpp2_write(priv, MVPP22_AXI_TXQ_DESCR_WR_ATTR_REG, wrval); | |
7802 | mvpp2_write(priv, MVPP22_AXI_TXQ_DESCR_RD_ATTR_REG, rdval); | |
7803 | mvpp2_write(priv, MVPP22_AXI_RXQ_DESCR_WR_ATTR_REG, wrval); | |
7804 | ||
7805 | /* Buffer Data */ | |
7806 | mvpp2_write(priv, MVPP22_AXI_TX_DATA_RD_ATTR_REG, rdval); | |
7807 | mvpp2_write(priv, MVPP22_AXI_RX_DATA_WR_ATTR_REG, wrval); | |
7808 | ||
7809 | val = MVPP22_AXI_CODE_CACHE_NON_CACHE | |
7810 | << MVPP22_AXI_CODE_CACHE_OFFS; | |
7811 | val |= MVPP22_AXI_CODE_DOMAIN_SYSTEM | |
7812 | << MVPP22_AXI_CODE_DOMAIN_OFFS; | |
7813 | mvpp2_write(priv, MVPP22_AXI_RD_NORMAL_CODE_REG, val); | |
7814 | mvpp2_write(priv, MVPP22_AXI_WR_NORMAL_CODE_REG, val); | |
7815 | ||
7816 | val = MVPP22_AXI_CODE_CACHE_RD_CACHE | |
7817 | << MVPP22_AXI_CODE_CACHE_OFFS; | |
7818 | val |= MVPP22_AXI_CODE_DOMAIN_OUTER_DOM | |
7819 | << MVPP22_AXI_CODE_DOMAIN_OFFS; | |
7820 | ||
7821 | mvpp2_write(priv, MVPP22_AXI_RD_SNOOP_CODE_REG, val); | |
7822 | ||
7823 | val = MVPP22_AXI_CODE_CACHE_WR_CACHE | |
7824 | << MVPP22_AXI_CODE_CACHE_OFFS; | |
7825 | val |= MVPP22_AXI_CODE_DOMAIN_OUTER_DOM | |
7826 | << MVPP22_AXI_CODE_DOMAIN_OFFS; | |
7827 | ||
7828 | mvpp2_write(priv, MVPP22_AXI_WR_SNOOP_CODE_REG, val); | |
7829 | } | |
7830 | ||
3f518509 MW |
7831 | /* Initialize network controller common part HW */ |
7832 | static int mvpp2_init(struct platform_device *pdev, struct mvpp2 *priv) | |
7833 | { | |
7834 | const struct mbus_dram_target_info *dram_target_info; | |
7835 | int err, i; | |
08a23755 | 7836 | u32 val; |
3f518509 | 7837 | |
3f518509 MW |
7838 | /* MBUS windows configuration */ |
7839 | dram_target_info = mv_mbus_dram_info(); | |
7840 | if (dram_target_info) | |
7841 | mvpp2_conf_mbus_windows(dram_target_info, priv); | |
7842 | ||
6763ce31 TP |
7843 | if (priv->hw_version == MVPP22) |
7844 | mvpp2_axi_init(priv); | |
7845 | ||
08a23755 | 7846 | /* Disable HW PHY polling */ |
26975821 TP |
7847 | if (priv->hw_version == MVPP21) { |
7848 | val = readl(priv->lms_base + MVPP2_PHY_AN_CFG0_REG); | |
7849 | val |= MVPP2_PHY_AN_STOP_SMI0_MASK; | |
7850 | writel(val, priv->lms_base + MVPP2_PHY_AN_CFG0_REG); | |
7851 | } else { | |
7852 | val = readl(priv->iface_base + MVPP22_SMI_MISC_CFG_REG); | |
7853 | val &= ~MVPP22_SMI_POLLING_EN; | |
7854 | writel(val, priv->iface_base + MVPP22_SMI_MISC_CFG_REG); | |
7855 | } | |
08a23755 | 7856 | |
3f518509 MW |
7857 | /* Allocate and initialize aggregated TXQs */ |
7858 | priv->aggr_txqs = devm_kcalloc(&pdev->dev, num_present_cpus(), | |
d7ce3cec | 7859 | sizeof(*priv->aggr_txqs), |
3f518509 MW |
7860 | GFP_KERNEL); |
7861 | if (!priv->aggr_txqs) | |
7862 | return -ENOMEM; | |
7863 | ||
7864 | for_each_present_cpu(i) { | |
7865 | priv->aggr_txqs[i].id = i; | |
7866 | priv->aggr_txqs[i].size = MVPP2_AGGR_TXQ_SIZE; | |
85affd7e | 7867 | err = mvpp2_aggr_txq_init(pdev, &priv->aggr_txqs[i], i, priv); |
3f518509 MW |
7868 | if (err < 0) |
7869 | return err; | |
7870 | } | |
7871 | ||
7872 | /* Rx Fifo Init */ | |
7873 | mvpp2_rx_fifo_init(priv); | |
7874 | ||
26975821 TP |
7875 | if (priv->hw_version == MVPP21) |
7876 | writel(MVPP2_EXT_GLOBAL_CTRL_DEFAULT, | |
7877 | priv->lms_base + MVPP2_MNG_EXTENDED_GLOBAL_CTRL_REG); | |
3f518509 MW |
7878 | |
7879 | /* Allow cache snoop when transmiting packets */ | |
7880 | mvpp2_write(priv, MVPP2_TX_SNOOP_REG, 0x1); | |
7881 | ||
7882 | /* Buffer Manager initialization */ | |
7883 | err = mvpp2_bm_init(pdev, priv); | |
7884 | if (err < 0) | |
7885 | return err; | |
7886 | ||
7887 | /* Parser default initialization */ | |
7888 | err = mvpp2_prs_default_init(pdev, priv); | |
7889 | if (err < 0) | |
7890 | return err; | |
7891 | ||
7892 | /* Classifier default initialization */ | |
7893 | mvpp2_cls_init(priv); | |
7894 | ||
7895 | return 0; | |
7896 | } | |
7897 | ||
7898 | static int mvpp2_probe(struct platform_device *pdev) | |
7899 | { | |
7900 | struct device_node *dn = pdev->dev.of_node; | |
7901 | struct device_node *port_node; | |
7902 | struct mvpp2 *priv; | |
7903 | struct resource *res; | |
a786841d | 7904 | void __iomem *base; |
df089aa0 | 7905 | int port_count, i; |
3f518509 MW |
7906 | int err; |
7907 | ||
0b92e594 | 7908 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
3f518509 MW |
7909 | if (!priv) |
7910 | return -ENOMEM; | |
7911 | ||
faca9247 TP |
7912 | priv->hw_version = |
7913 | (unsigned long)of_device_get_match_data(&pdev->dev); | |
7914 | ||
3f518509 | 7915 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
a786841d TP |
7916 | base = devm_ioremap_resource(&pdev->dev, res); |
7917 | if (IS_ERR(base)) | |
7918 | return PTR_ERR(base); | |
7919 | ||
7920 | if (priv->hw_version == MVPP21) { | |
7921 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | |
7922 | priv->lms_base = devm_ioremap_resource(&pdev->dev, res); | |
7923 | if (IS_ERR(priv->lms_base)) | |
7924 | return PTR_ERR(priv->lms_base); | |
7925 | } else { | |
7926 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | |
7927 | priv->iface_base = devm_ioremap_resource(&pdev->dev, res); | |
7928 | if (IS_ERR(priv->iface_base)) | |
7929 | return PTR_ERR(priv->iface_base); | |
f84bf386 AT |
7930 | |
7931 | priv->sysctrl_base = | |
7932 | syscon_regmap_lookup_by_phandle(pdev->dev.of_node, | |
7933 | "marvell,system-controller"); | |
7934 | if (IS_ERR(priv->sysctrl_base)) | |
7935 | /* The system controller regmap is optional for dt | |
7936 | * compatibility reasons. When not provided, the | |
7937 | * configuration of the GoP relies on the | |
7938 | * firmware/bootloader. | |
7939 | */ | |
7940 | priv->sysctrl_base = NULL; | |
a786841d TP |
7941 | } |
7942 | ||
df089aa0 | 7943 | for (i = 0; i < MVPP2_MAX_THREADS; i++) { |
a786841d TP |
7944 | u32 addr_space_sz; |
7945 | ||
7946 | addr_space_sz = (priv->hw_version == MVPP21 ? | |
7947 | MVPP21_ADDR_SPACE_SZ : MVPP22_ADDR_SPACE_SZ); | |
df089aa0 | 7948 | priv->swth_base[i] = base + i * addr_space_sz; |
a786841d | 7949 | } |
3f518509 | 7950 | |
59b9a31e TP |
7951 | if (priv->hw_version == MVPP21) |
7952 | priv->max_port_rxqs = 8; | |
7953 | else | |
7954 | priv->max_port_rxqs = 32; | |
7955 | ||
3f518509 MW |
7956 | priv->pp_clk = devm_clk_get(&pdev->dev, "pp_clk"); |
7957 | if (IS_ERR(priv->pp_clk)) | |
7958 | return PTR_ERR(priv->pp_clk); | |
7959 | err = clk_prepare_enable(priv->pp_clk); | |
7960 | if (err < 0) | |
7961 | return err; | |
7962 | ||
7963 | priv->gop_clk = devm_clk_get(&pdev->dev, "gop_clk"); | |
7964 | if (IS_ERR(priv->gop_clk)) { | |
7965 | err = PTR_ERR(priv->gop_clk); | |
7966 | goto err_pp_clk; | |
7967 | } | |
7968 | err = clk_prepare_enable(priv->gop_clk); | |
7969 | if (err < 0) | |
7970 | goto err_pp_clk; | |
7971 | ||
fceb55d4 TP |
7972 | if (priv->hw_version == MVPP22) { |
7973 | priv->mg_clk = devm_clk_get(&pdev->dev, "mg_clk"); | |
7974 | if (IS_ERR(priv->mg_clk)) { | |
7975 | err = PTR_ERR(priv->mg_clk); | |
7976 | goto err_gop_clk; | |
7977 | } | |
7978 | ||
7979 | err = clk_prepare_enable(priv->mg_clk); | |
7980 | if (err < 0) | |
7981 | goto err_gop_clk; | |
4792ea04 GC |
7982 | |
7983 | priv->axi_clk = devm_clk_get(&pdev->dev, "axi_clk"); | |
7984 | if (IS_ERR(priv->axi_clk)) { | |
7985 | err = PTR_ERR(priv->axi_clk); | |
7986 | if (err == -EPROBE_DEFER) | |
7987 | goto err_gop_clk; | |
7988 | priv->axi_clk = NULL; | |
7989 | } else { | |
7990 | err = clk_prepare_enable(priv->axi_clk); | |
7991 | if (err < 0) | |
7992 | goto err_gop_clk; | |
7993 | } | |
fceb55d4 TP |
7994 | } |
7995 | ||
3f518509 MW |
7996 | /* Get system's tclk rate */ |
7997 | priv->tclk = clk_get_rate(priv->pp_clk); | |
7998 | ||
2067e0a1 TP |
7999 | if (priv->hw_version == MVPP22) { |
8000 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(40)); | |
8001 | if (err) | |
8002 | goto err_mg_clk; | |
8003 | /* Sadly, the BM pools all share the same register to | |
8004 | * store the high 32 bits of their address. So they | |
8005 | * must all have the same high 32 bits, which forces | |
8006 | * us to restrict coherent memory to DMA_BIT_MASK(32). | |
8007 | */ | |
8008 | err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); | |
8009 | if (err) | |
8010 | goto err_mg_clk; | |
8011 | } | |
8012 | ||
3f518509 MW |
8013 | /* Initialize network controller */ |
8014 | err = mvpp2_init(pdev, priv); | |
8015 | if (err < 0) { | |
8016 | dev_err(&pdev->dev, "failed to initialize controller\n"); | |
fceb55d4 | 8017 | goto err_mg_clk; |
3f518509 MW |
8018 | } |
8019 | ||
8020 | port_count = of_get_available_child_count(dn); | |
8021 | if (port_count == 0) { | |
8022 | dev_err(&pdev->dev, "no ports enabled\n"); | |
575a1935 | 8023 | err = -ENODEV; |
fceb55d4 | 8024 | goto err_mg_clk; |
3f518509 MW |
8025 | } |
8026 | ||
8027 | priv->port_list = devm_kcalloc(&pdev->dev, port_count, | |
0b92e594 ME |
8028 | sizeof(*priv->port_list), |
8029 | GFP_KERNEL); | |
3f518509 MW |
8030 | if (!priv->port_list) { |
8031 | err = -ENOMEM; | |
fceb55d4 | 8032 | goto err_mg_clk; |
3f518509 MW |
8033 | } |
8034 | ||
8035 | /* Initialize ports */ | |
6bf69a1d | 8036 | i = 0; |
3f518509 | 8037 | for_each_available_child_of_node(dn, port_node) { |
6bf69a1d | 8038 | err = mvpp2_port_probe(pdev, port_node, priv, i); |
3f518509 | 8039 | if (err < 0) |
fceb55d4 | 8040 | goto err_mg_clk; |
6bf69a1d | 8041 | i++; |
3f518509 MW |
8042 | } |
8043 | ||
8044 | platform_set_drvdata(pdev, priv); | |
8045 | return 0; | |
8046 | ||
fceb55d4 | 8047 | err_mg_clk: |
4792ea04 | 8048 | clk_disable_unprepare(priv->axi_clk); |
fceb55d4 TP |
8049 | if (priv->hw_version == MVPP22) |
8050 | clk_disable_unprepare(priv->mg_clk); | |
3f518509 MW |
8051 | err_gop_clk: |
8052 | clk_disable_unprepare(priv->gop_clk); | |
8053 | err_pp_clk: | |
8054 | clk_disable_unprepare(priv->pp_clk); | |
8055 | return err; | |
8056 | } | |
8057 | ||
8058 | static int mvpp2_remove(struct platform_device *pdev) | |
8059 | { | |
8060 | struct mvpp2 *priv = platform_get_drvdata(pdev); | |
8061 | struct device_node *dn = pdev->dev.of_node; | |
8062 | struct device_node *port_node; | |
8063 | int i = 0; | |
8064 | ||
8065 | for_each_available_child_of_node(dn, port_node) { | |
8066 | if (priv->port_list[i]) | |
8067 | mvpp2_port_remove(priv->port_list[i]); | |
8068 | i++; | |
8069 | } | |
8070 | ||
8071 | for (i = 0; i < MVPP2_BM_POOLS_NUM; i++) { | |
8072 | struct mvpp2_bm_pool *bm_pool = &priv->bm_pools[i]; | |
8073 | ||
8074 | mvpp2_bm_pool_destroy(pdev, priv, bm_pool); | |
8075 | } | |
8076 | ||
8077 | for_each_present_cpu(i) { | |
8078 | struct mvpp2_tx_queue *aggr_txq = &priv->aggr_txqs[i]; | |
8079 | ||
8080 | dma_free_coherent(&pdev->dev, | |
8081 | MVPP2_AGGR_TXQ_SIZE * MVPP2_DESC_ALIGNED_SIZE, | |
8082 | aggr_txq->descs, | |
20396136 | 8083 | aggr_txq->descs_dma); |
3f518509 MW |
8084 | } |
8085 | ||
4792ea04 | 8086 | clk_disable_unprepare(priv->axi_clk); |
fceb55d4 | 8087 | clk_disable_unprepare(priv->mg_clk); |
3f518509 MW |
8088 | clk_disable_unprepare(priv->pp_clk); |
8089 | clk_disable_unprepare(priv->gop_clk); | |
8090 | ||
8091 | return 0; | |
8092 | } | |
8093 | ||
8094 | static const struct of_device_id mvpp2_match[] = { | |
faca9247 TP |
8095 | { |
8096 | .compatible = "marvell,armada-375-pp2", | |
8097 | .data = (void *)MVPP21, | |
8098 | }, | |
fc5e1550 TP |
8099 | { |
8100 | .compatible = "marvell,armada-7k-pp22", | |
8101 | .data = (void *)MVPP22, | |
8102 | }, | |
3f518509 MW |
8103 | { } |
8104 | }; | |
8105 | MODULE_DEVICE_TABLE(of, mvpp2_match); | |
8106 | ||
8107 | static struct platform_driver mvpp2_driver = { | |
8108 | .probe = mvpp2_probe, | |
8109 | .remove = mvpp2_remove, | |
8110 | .driver = { | |
8111 | .name = MVPP2_DRIVER_NAME, | |
8112 | .of_match_table = mvpp2_match, | |
8113 | }, | |
8114 | }; | |
8115 | ||
8116 | module_platform_driver(mvpp2_driver); | |
8117 | ||
8118 | MODULE_DESCRIPTION("Marvell PPv2 Ethernet Driver - www.marvell.com"); | |
8119 | MODULE_AUTHOR("Marcin Wojtas <mw@semihalf.com>"); | |
c634099d | 8120 | MODULE_LICENSE("GPL v2"); |