xref: /linux/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c (revision 0526b56cbc3c489642bd6a5fe4b718dea7ef0ee8)
1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
2 /*
3  * Copyright (c) 2018 Synopsys, Inc. and/or its affiliates.
4  * stmmac XGMAC support.
5  */
6 
7 #include <linux/iopoll.h>
8 #include "stmmac.h"
9 #include "dwxgmac2.h"
10 
11 static int dwxgmac2_dma_reset(void __iomem *ioaddr)
12 {
13 	u32 value = readl(ioaddr + XGMAC_DMA_MODE);
14 
15 	/* DMA SW reset */
16 	writel(value | XGMAC_SWR, ioaddr + XGMAC_DMA_MODE);
17 
18 	return readl_poll_timeout(ioaddr + XGMAC_DMA_MODE, value,
19 				  !(value & XGMAC_SWR), 0, 100000);
20 }
21 
22 static void dwxgmac2_dma_init(void __iomem *ioaddr,
23 			      struct stmmac_dma_cfg *dma_cfg, int atds)
24 {
25 	u32 value = readl(ioaddr + XGMAC_DMA_SYSBUS_MODE);
26 
27 	if (dma_cfg->aal)
28 		value |= XGMAC_AAL;
29 
30 	if (dma_cfg->eame)
31 		value |= XGMAC_EAME;
32 
33 	writel(value, ioaddr + XGMAC_DMA_SYSBUS_MODE);
34 }
35 
36 static void dwxgmac2_dma_init_chan(struct stmmac_priv *priv,
37 				   void __iomem *ioaddr,
38 				   struct stmmac_dma_cfg *dma_cfg, u32 chan)
39 {
40 	u32 value = readl(ioaddr + XGMAC_DMA_CH_CONTROL(chan));
41 
42 	if (dma_cfg->pblx8)
43 		value |= XGMAC_PBLx8;
44 
45 	writel(value, ioaddr + XGMAC_DMA_CH_CONTROL(chan));
46 	writel(XGMAC_DMA_INT_DEFAULT_EN, ioaddr + XGMAC_DMA_CH_INT_EN(chan));
47 }
48 
49 static void dwxgmac2_dma_init_rx_chan(struct stmmac_priv *priv,
50 				      void __iomem *ioaddr,
51 				      struct stmmac_dma_cfg *dma_cfg,
52 				      dma_addr_t phy, u32 chan)
53 {
54 	u32 rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
55 	u32 value;
56 
57 	value = readl(ioaddr + XGMAC_DMA_CH_RX_CONTROL(chan));
58 	value &= ~XGMAC_RxPBL;
59 	value |= (rxpbl << XGMAC_RxPBL_SHIFT) & XGMAC_RxPBL;
60 	writel(value, ioaddr + XGMAC_DMA_CH_RX_CONTROL(chan));
61 
62 	writel(upper_32_bits(phy), ioaddr + XGMAC_DMA_CH_RxDESC_HADDR(chan));
63 	writel(lower_32_bits(phy), ioaddr + XGMAC_DMA_CH_RxDESC_LADDR(chan));
64 }
65 
66 static void dwxgmac2_dma_init_tx_chan(struct stmmac_priv *priv,
67 				      void __iomem *ioaddr,
68 				      struct stmmac_dma_cfg *dma_cfg,
69 				      dma_addr_t phy, u32 chan)
70 {
71 	u32 txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
72 	u32 value;
73 
74 	value = readl(ioaddr + XGMAC_DMA_CH_TX_CONTROL(chan));
75 	value &= ~XGMAC_TxPBL;
76 	value |= (txpbl << XGMAC_TxPBL_SHIFT) & XGMAC_TxPBL;
77 	value |= XGMAC_OSP;
78 	writel(value, ioaddr + XGMAC_DMA_CH_TX_CONTROL(chan));
79 
80 	writel(upper_32_bits(phy), ioaddr + XGMAC_DMA_CH_TxDESC_HADDR(chan));
81 	writel(lower_32_bits(phy), ioaddr + XGMAC_DMA_CH_TxDESC_LADDR(chan));
82 }
83 
84 static void dwxgmac2_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
85 {
86 	u32 value = readl(ioaddr + XGMAC_DMA_SYSBUS_MODE);
87 	int i;
88 
89 	if (axi->axi_lpi_en)
90 		value |= XGMAC_EN_LPI;
91 	if (axi->axi_xit_frm)
92 		value |= XGMAC_LPI_XIT_PKT;
93 
94 	value &= ~XGMAC_WR_OSR_LMT;
95 	value |= (axi->axi_wr_osr_lmt << XGMAC_WR_OSR_LMT_SHIFT) &
96 		XGMAC_WR_OSR_LMT;
97 
98 	value &= ~XGMAC_RD_OSR_LMT;
99 	value |= (axi->axi_rd_osr_lmt << XGMAC_RD_OSR_LMT_SHIFT) &
100 		XGMAC_RD_OSR_LMT;
101 
102 	if (!axi->axi_fb)
103 		value |= XGMAC_UNDEF;
104 
105 	value &= ~XGMAC_BLEN;
106 	for (i = 0; i < AXI_BLEN; i++) {
107 		switch (axi->axi_blen[i]) {
108 		case 256:
109 			value |= XGMAC_BLEN256;
110 			break;
111 		case 128:
112 			value |= XGMAC_BLEN128;
113 			break;
114 		case 64:
115 			value |= XGMAC_BLEN64;
116 			break;
117 		case 32:
118 			value |= XGMAC_BLEN32;
119 			break;
120 		case 16:
121 			value |= XGMAC_BLEN16;
122 			break;
123 		case 8:
124 			value |= XGMAC_BLEN8;
125 			break;
126 		case 4:
127 			value |= XGMAC_BLEN4;
128 			break;
129 		}
130 	}
131 
132 	writel(value, ioaddr + XGMAC_DMA_SYSBUS_MODE);
133 	writel(XGMAC_TDPS, ioaddr + XGMAC_TX_EDMA_CTRL);
134 	writel(XGMAC_RDPS, ioaddr + XGMAC_RX_EDMA_CTRL);
135 }
136 
137 static void dwxgmac2_dma_dump_regs(struct stmmac_priv *priv,
138 				   void __iomem *ioaddr, u32 *reg_space)
139 {
140 	int i;
141 
142 	for (i = (XGMAC_DMA_MODE / 4); i < XGMAC_REGSIZE; i++)
143 		reg_space[i] = readl(ioaddr + i * 4);
144 }
145 
146 static void dwxgmac2_dma_rx_mode(struct stmmac_priv *priv, void __iomem *ioaddr,
147 				 int mode, u32 channel, int fifosz, u8 qmode)
148 {
149 	u32 value = readl(ioaddr + XGMAC_MTL_RXQ_OPMODE(channel));
150 	unsigned int rqs = fifosz / 256 - 1;
151 
152 	if (mode == SF_DMA_MODE) {
153 		value |= XGMAC_RSF;
154 	} else {
155 		value &= ~XGMAC_RSF;
156 		value &= ~XGMAC_RTC;
157 
158 		if (mode <= 64)
159 			value |= 0x0 << XGMAC_RTC_SHIFT;
160 		else if (mode <= 96)
161 			value |= 0x2 << XGMAC_RTC_SHIFT;
162 		else
163 			value |= 0x3 << XGMAC_RTC_SHIFT;
164 	}
165 
166 	value &= ~XGMAC_RQS;
167 	value |= (rqs << XGMAC_RQS_SHIFT) & XGMAC_RQS;
168 
169 	if ((fifosz >= 4096) && (qmode != MTL_QUEUE_AVB)) {
170 		u32 flow = readl(ioaddr + XGMAC_MTL_RXQ_FLOW_CONTROL(channel));
171 		unsigned int rfd, rfa;
172 
173 		value |= XGMAC_EHFC;
174 
175 		/* Set Threshold for Activating Flow Control to min 2 frames,
176 		 * i.e. 1500 * 2 = 3000 bytes.
177 		 *
178 		 * Set Threshold for Deactivating Flow Control to min 1 frame,
179 		 * i.e. 1500 bytes.
180 		 */
181 		switch (fifosz) {
182 		case 4096:
183 			/* This violates the above formula because of FIFO size
184 			 * limit therefore overflow may occur in spite of this.
185 			 */
186 			rfd = 0x03; /* Full-2.5K */
187 			rfa = 0x01; /* Full-1.5K */
188 			break;
189 
190 		default:
191 			rfd = 0x07; /* Full-4.5K */
192 			rfa = 0x04; /* Full-3K */
193 			break;
194 		}
195 
196 		flow &= ~XGMAC_RFD;
197 		flow |= rfd << XGMAC_RFD_SHIFT;
198 
199 		flow &= ~XGMAC_RFA;
200 		flow |= rfa << XGMAC_RFA_SHIFT;
201 
202 		writel(flow, ioaddr + XGMAC_MTL_RXQ_FLOW_CONTROL(channel));
203 	}
204 
205 	writel(value, ioaddr + XGMAC_MTL_RXQ_OPMODE(channel));
206 
207 	/* Enable MTL RX overflow */
208 	value = readl(ioaddr + XGMAC_MTL_QINTEN(channel));
209 	writel(value | XGMAC_RXOIE, ioaddr + XGMAC_MTL_QINTEN(channel));
210 }
211 
212 static void dwxgmac2_dma_tx_mode(struct stmmac_priv *priv, void __iomem *ioaddr,
213 				 int mode, u32 channel, int fifosz, u8 qmode)
214 {
215 	u32 value = readl(ioaddr + XGMAC_MTL_TXQ_OPMODE(channel));
216 	unsigned int tqs = fifosz / 256 - 1;
217 
218 	if (mode == SF_DMA_MODE) {
219 		value |= XGMAC_TSF;
220 	} else {
221 		value &= ~XGMAC_TSF;
222 		value &= ~XGMAC_TTC;
223 
224 		if (mode <= 64)
225 			value |= 0x0 << XGMAC_TTC_SHIFT;
226 		else if (mode <= 96)
227 			value |= 0x2 << XGMAC_TTC_SHIFT;
228 		else if (mode <= 128)
229 			value |= 0x3 << XGMAC_TTC_SHIFT;
230 		else if (mode <= 192)
231 			value |= 0x4 << XGMAC_TTC_SHIFT;
232 		else if (mode <= 256)
233 			value |= 0x5 << XGMAC_TTC_SHIFT;
234 		else if (mode <= 384)
235 			value |= 0x6 << XGMAC_TTC_SHIFT;
236 		else
237 			value |= 0x7 << XGMAC_TTC_SHIFT;
238 	}
239 
240 	/* Use static TC to Queue mapping */
241 	value |= (channel << XGMAC_Q2TCMAP_SHIFT) & XGMAC_Q2TCMAP;
242 
243 	value &= ~XGMAC_TXQEN;
244 	if (qmode != MTL_QUEUE_AVB)
245 		value |= 0x2 << XGMAC_TXQEN_SHIFT;
246 	else
247 		value |= 0x1 << XGMAC_TXQEN_SHIFT;
248 
249 	value &= ~XGMAC_TQS;
250 	value |= (tqs << XGMAC_TQS_SHIFT) & XGMAC_TQS;
251 
252 	writel(value, ioaddr +  XGMAC_MTL_TXQ_OPMODE(channel));
253 }
254 
255 static void dwxgmac2_enable_dma_irq(struct stmmac_priv *priv,
256 				    void __iomem *ioaddr, u32 chan,
257 				    bool rx, bool tx)
258 {
259 	u32 value = readl(ioaddr + XGMAC_DMA_CH_INT_EN(chan));
260 
261 	if (rx)
262 		value |= XGMAC_DMA_INT_DEFAULT_RX;
263 	if (tx)
264 		value |= XGMAC_DMA_INT_DEFAULT_TX;
265 
266 	writel(value, ioaddr + XGMAC_DMA_CH_INT_EN(chan));
267 }
268 
269 static void dwxgmac2_disable_dma_irq(struct stmmac_priv *priv,
270 				     void __iomem *ioaddr, u32 chan,
271 				     bool rx, bool tx)
272 {
273 	u32 value = readl(ioaddr + XGMAC_DMA_CH_INT_EN(chan));
274 
275 	if (rx)
276 		value &= ~XGMAC_DMA_INT_DEFAULT_RX;
277 	if (tx)
278 		value &= ~XGMAC_DMA_INT_DEFAULT_TX;
279 
280 	writel(value, ioaddr + XGMAC_DMA_CH_INT_EN(chan));
281 }
282 
283 static void dwxgmac2_dma_start_tx(struct stmmac_priv *priv,
284 				  void __iomem *ioaddr, u32 chan)
285 {
286 	u32 value;
287 
288 	value = readl(ioaddr + XGMAC_DMA_CH_TX_CONTROL(chan));
289 	value |= XGMAC_TXST;
290 	writel(value, ioaddr + XGMAC_DMA_CH_TX_CONTROL(chan));
291 
292 	value = readl(ioaddr + XGMAC_TX_CONFIG);
293 	value |= XGMAC_CONFIG_TE;
294 	writel(value, ioaddr + XGMAC_TX_CONFIG);
295 }
296 
297 static void dwxgmac2_dma_stop_tx(struct stmmac_priv *priv, void __iomem *ioaddr,
298 				 u32 chan)
299 {
300 	u32 value;
301 
302 	value = readl(ioaddr + XGMAC_DMA_CH_TX_CONTROL(chan));
303 	value &= ~XGMAC_TXST;
304 	writel(value, ioaddr + XGMAC_DMA_CH_TX_CONTROL(chan));
305 
306 	value = readl(ioaddr + XGMAC_TX_CONFIG);
307 	value &= ~XGMAC_CONFIG_TE;
308 	writel(value, ioaddr + XGMAC_TX_CONFIG);
309 }
310 
311 static void dwxgmac2_dma_start_rx(struct stmmac_priv *priv,
312 				  void __iomem *ioaddr, u32 chan)
313 {
314 	u32 value;
315 
316 	value = readl(ioaddr + XGMAC_DMA_CH_RX_CONTROL(chan));
317 	value |= XGMAC_RXST;
318 	writel(value, ioaddr + XGMAC_DMA_CH_RX_CONTROL(chan));
319 
320 	value = readl(ioaddr + XGMAC_RX_CONFIG);
321 	value |= XGMAC_CONFIG_RE;
322 	writel(value, ioaddr + XGMAC_RX_CONFIG);
323 }
324 
325 static void dwxgmac2_dma_stop_rx(struct stmmac_priv *priv, void __iomem *ioaddr,
326 				 u32 chan)
327 {
328 	u32 value;
329 
330 	value = readl(ioaddr + XGMAC_DMA_CH_RX_CONTROL(chan));
331 	value &= ~XGMAC_RXST;
332 	writel(value, ioaddr + XGMAC_DMA_CH_RX_CONTROL(chan));
333 }
334 
335 static int dwxgmac2_dma_interrupt(struct stmmac_priv *priv,
336 				  void __iomem *ioaddr,
337 				  struct stmmac_extra_stats *x, u32 chan,
338 				  u32 dir)
339 {
340 	u32 intr_status = readl(ioaddr + XGMAC_DMA_CH_STATUS(chan));
341 	u32 intr_en = readl(ioaddr + XGMAC_DMA_CH_INT_EN(chan));
342 	int ret = 0;
343 
344 	if (dir == DMA_DIR_RX)
345 		intr_status &= XGMAC_DMA_STATUS_MSK_RX;
346 	else if (dir == DMA_DIR_TX)
347 		intr_status &= XGMAC_DMA_STATUS_MSK_TX;
348 
349 	/* ABNORMAL interrupts */
350 	if (unlikely(intr_status & XGMAC_AIS)) {
351 		if (unlikely(intr_status & XGMAC_RBU)) {
352 			x->rx_buf_unav_irq++;
353 			ret |= handle_rx;
354 		}
355 		if (unlikely(intr_status & XGMAC_TPS)) {
356 			x->tx_process_stopped_irq++;
357 			ret |= tx_hard_error;
358 		}
359 		if (unlikely(intr_status & XGMAC_FBE)) {
360 			x->fatal_bus_error_irq++;
361 			ret |= tx_hard_error;
362 		}
363 	}
364 
365 	/* TX/RX NORMAL interrupts */
366 	if (likely(intr_status & XGMAC_NIS)) {
367 		x->normal_irq_n++;
368 
369 		if (likely(intr_status & XGMAC_RI)) {
370 			x->rx_normal_irq_n++;
371 			ret |= handle_rx;
372 		}
373 		if (likely(intr_status & (XGMAC_TI | XGMAC_TBU))) {
374 			x->tx_normal_irq_n++;
375 			ret |= handle_tx;
376 		}
377 	}
378 
379 	/* Clear interrupts */
380 	writel(intr_en & intr_status, ioaddr + XGMAC_DMA_CH_STATUS(chan));
381 
382 	return ret;
383 }
384 
385 static int dwxgmac2_get_hw_feature(void __iomem *ioaddr,
386 				   struct dma_features *dma_cap)
387 {
388 	u32 hw_cap;
389 
390 	/*  MAC HW feature 0 */
391 	hw_cap = readl(ioaddr + XGMAC_HW_FEATURE0);
392 	dma_cap->vlins = (hw_cap & XGMAC_HWFEAT_SAVLANINS) >> 27;
393 	dma_cap->rx_coe = (hw_cap & XGMAC_HWFEAT_RXCOESEL) >> 16;
394 	dma_cap->tx_coe = (hw_cap & XGMAC_HWFEAT_TXCOESEL) >> 14;
395 	dma_cap->eee = (hw_cap & XGMAC_HWFEAT_EEESEL) >> 13;
396 	dma_cap->atime_stamp = (hw_cap & XGMAC_HWFEAT_TSSEL) >> 12;
397 	dma_cap->av = (hw_cap & XGMAC_HWFEAT_AVSEL) >> 11;
398 	dma_cap->av &= !((hw_cap & XGMAC_HWFEAT_RAVSEL) >> 10);
399 	dma_cap->arpoffsel = (hw_cap & XGMAC_HWFEAT_ARPOFFSEL) >> 9;
400 	dma_cap->rmon = (hw_cap & XGMAC_HWFEAT_MMCSEL) >> 8;
401 	dma_cap->pmt_magic_frame = (hw_cap & XGMAC_HWFEAT_MGKSEL) >> 7;
402 	dma_cap->pmt_remote_wake_up = (hw_cap & XGMAC_HWFEAT_RWKSEL) >> 6;
403 	dma_cap->vlhash = (hw_cap & XGMAC_HWFEAT_VLHASH) >> 4;
404 	dma_cap->mbps_1000 = (hw_cap & XGMAC_HWFEAT_GMIISEL) >> 1;
405 
406 	/* MAC HW feature 1 */
407 	hw_cap = readl(ioaddr + XGMAC_HW_FEATURE1);
408 	dma_cap->l3l4fnum = (hw_cap & XGMAC_HWFEAT_L3L4FNUM) >> 27;
409 	dma_cap->hash_tb_sz = (hw_cap & XGMAC_HWFEAT_HASHTBLSZ) >> 24;
410 	dma_cap->rssen = (hw_cap & XGMAC_HWFEAT_RSSEN) >> 20;
411 	dma_cap->tsoen = (hw_cap & XGMAC_HWFEAT_TSOEN) >> 18;
412 	dma_cap->sphen = (hw_cap & XGMAC_HWFEAT_SPHEN) >> 17;
413 
414 	dma_cap->addr64 = (hw_cap & XGMAC_HWFEAT_ADDR64) >> 14;
415 	switch (dma_cap->addr64) {
416 	case 0:
417 		dma_cap->addr64 = 32;
418 		break;
419 	case 1:
420 		dma_cap->addr64 = 40;
421 		break;
422 	case 2:
423 		dma_cap->addr64 = 48;
424 		break;
425 	default:
426 		dma_cap->addr64 = 32;
427 		break;
428 	}
429 
430 	dma_cap->tx_fifo_size =
431 		128 << ((hw_cap & XGMAC_HWFEAT_TXFIFOSIZE) >> 6);
432 	dma_cap->rx_fifo_size =
433 		128 << ((hw_cap & XGMAC_HWFEAT_RXFIFOSIZE) >> 0);
434 
435 	/* MAC HW feature 2 */
436 	hw_cap = readl(ioaddr + XGMAC_HW_FEATURE2);
437 	dma_cap->pps_out_num = (hw_cap & XGMAC_HWFEAT_PPSOUTNUM) >> 24;
438 	dma_cap->number_tx_channel =
439 		((hw_cap & XGMAC_HWFEAT_TXCHCNT) >> 18) + 1;
440 	dma_cap->number_rx_channel =
441 		((hw_cap & XGMAC_HWFEAT_RXCHCNT) >> 12) + 1;
442 	dma_cap->number_tx_queues =
443 		((hw_cap & XGMAC_HWFEAT_TXQCNT) >> 6) + 1;
444 	dma_cap->number_rx_queues =
445 		((hw_cap & XGMAC_HWFEAT_RXQCNT) >> 0) + 1;
446 
447 	/* MAC HW feature 3 */
448 	hw_cap = readl(ioaddr + XGMAC_HW_FEATURE3);
449 	dma_cap->tbssel = (hw_cap & XGMAC_HWFEAT_TBSSEL) >> 27;
450 	dma_cap->fpesel = (hw_cap & XGMAC_HWFEAT_FPESEL) >> 26;
451 	dma_cap->estwid = (hw_cap & XGMAC_HWFEAT_ESTWID) >> 23;
452 	dma_cap->estdep = (hw_cap & XGMAC_HWFEAT_ESTDEP) >> 20;
453 	dma_cap->estsel = (hw_cap & XGMAC_HWFEAT_ESTSEL) >> 19;
454 	dma_cap->asp = (hw_cap & XGMAC_HWFEAT_ASP) >> 14;
455 	dma_cap->dvlan = (hw_cap & XGMAC_HWFEAT_DVLAN) >> 13;
456 	dma_cap->frpes = (hw_cap & XGMAC_HWFEAT_FRPES) >> 11;
457 	dma_cap->frpbs = (hw_cap & XGMAC_HWFEAT_FRPPB) >> 9;
458 	dma_cap->frpsel = (hw_cap & XGMAC_HWFEAT_FRPSEL) >> 3;
459 
460 	return 0;
461 }
462 
463 static void dwxgmac2_rx_watchdog(struct stmmac_priv *priv, void __iomem *ioaddr,
464 				 u32 riwt, u32 queue)
465 {
466 	writel(riwt & XGMAC_RWT, ioaddr + XGMAC_DMA_CH_Rx_WATCHDOG(queue));
467 }
468 
469 static void dwxgmac2_set_rx_ring_len(struct stmmac_priv *priv,
470 				     void __iomem *ioaddr, u32 len, u32 chan)
471 {
472 	writel(len, ioaddr + XGMAC_DMA_CH_RxDESC_RING_LEN(chan));
473 }
474 
475 static void dwxgmac2_set_tx_ring_len(struct stmmac_priv *priv,
476 				     void __iomem *ioaddr, u32 len, u32 chan)
477 {
478 	writel(len, ioaddr + XGMAC_DMA_CH_TxDESC_RING_LEN(chan));
479 }
480 
481 static void dwxgmac2_set_rx_tail_ptr(struct stmmac_priv *priv,
482 				     void __iomem *ioaddr, u32 ptr, u32 chan)
483 {
484 	writel(ptr, ioaddr + XGMAC_DMA_CH_RxDESC_TAIL_LPTR(chan));
485 }
486 
487 static void dwxgmac2_set_tx_tail_ptr(struct stmmac_priv *priv,
488 				     void __iomem *ioaddr, u32 ptr, u32 chan)
489 {
490 	writel(ptr, ioaddr + XGMAC_DMA_CH_TxDESC_TAIL_LPTR(chan));
491 }
492 
493 static void dwxgmac2_enable_tso(struct stmmac_priv *priv, void __iomem *ioaddr,
494 				bool en, u32 chan)
495 {
496 	u32 value = readl(ioaddr + XGMAC_DMA_CH_TX_CONTROL(chan));
497 
498 	if (en)
499 		value |= XGMAC_TSE;
500 	else
501 		value &= ~XGMAC_TSE;
502 
503 	writel(value, ioaddr + XGMAC_DMA_CH_TX_CONTROL(chan));
504 }
505 
506 static void dwxgmac2_qmode(struct stmmac_priv *priv, void __iomem *ioaddr,
507 			   u32 channel, u8 qmode)
508 {
509 	u32 value = readl(ioaddr + XGMAC_MTL_TXQ_OPMODE(channel));
510 	u32 flow = readl(ioaddr + XGMAC_RX_FLOW_CTRL);
511 
512 	value &= ~XGMAC_TXQEN;
513 	if (qmode != MTL_QUEUE_AVB) {
514 		value |= 0x2 << XGMAC_TXQEN_SHIFT;
515 		writel(0, ioaddr + XGMAC_MTL_TCx_ETS_CONTROL(channel));
516 	} else {
517 		value |= 0x1 << XGMAC_TXQEN_SHIFT;
518 		writel(flow & (~XGMAC_RFE), ioaddr + XGMAC_RX_FLOW_CTRL);
519 	}
520 
521 	writel(value, ioaddr +  XGMAC_MTL_TXQ_OPMODE(channel));
522 }
523 
524 static void dwxgmac2_set_bfsize(struct stmmac_priv *priv, void __iomem *ioaddr,
525 				int bfsize, u32 chan)
526 {
527 	u32 value;
528 
529 	value = readl(ioaddr + XGMAC_DMA_CH_RX_CONTROL(chan));
530 	value &= ~XGMAC_RBSZ;
531 	value |= bfsize << XGMAC_RBSZ_SHIFT;
532 	writel(value, ioaddr + XGMAC_DMA_CH_RX_CONTROL(chan));
533 }
534 
535 static void dwxgmac2_enable_sph(struct stmmac_priv *priv, void __iomem *ioaddr,
536 				bool en, u32 chan)
537 {
538 	u32 value = readl(ioaddr + XGMAC_RX_CONFIG);
539 
540 	value &= ~XGMAC_CONFIG_HDSMS;
541 	value |= XGMAC_CONFIG_HDSMS_256; /* Segment max 256 bytes */
542 	writel(value, ioaddr + XGMAC_RX_CONFIG);
543 
544 	value = readl(ioaddr + XGMAC_DMA_CH_CONTROL(chan));
545 	if (en)
546 		value |= XGMAC_SPH;
547 	else
548 		value &= ~XGMAC_SPH;
549 	writel(value, ioaddr + XGMAC_DMA_CH_CONTROL(chan));
550 }
551 
552 static int dwxgmac2_enable_tbs(struct stmmac_priv *priv, void __iomem *ioaddr,
553 			       bool en, u32 chan)
554 {
555 	u32 value = readl(ioaddr + XGMAC_DMA_CH_TX_CONTROL(chan));
556 
557 	if (en)
558 		value |= XGMAC_EDSE;
559 	else
560 		value &= ~XGMAC_EDSE;
561 
562 	writel(value, ioaddr + XGMAC_DMA_CH_TX_CONTROL(chan));
563 
564 	value = readl(ioaddr + XGMAC_DMA_CH_TX_CONTROL(chan)) & XGMAC_EDSE;
565 	if (en && !value)
566 		return -EIO;
567 
568 	writel(XGMAC_DEF_FTOS, ioaddr + XGMAC_DMA_TBS_CTRL0);
569 	writel(XGMAC_DEF_FTOS, ioaddr + XGMAC_DMA_TBS_CTRL1);
570 	writel(XGMAC_DEF_FTOS, ioaddr + XGMAC_DMA_TBS_CTRL2);
571 	writel(XGMAC_DEF_FTOS, ioaddr + XGMAC_DMA_TBS_CTRL3);
572 	return 0;
573 }
574 
575 const struct stmmac_dma_ops dwxgmac210_dma_ops = {
576 	.reset = dwxgmac2_dma_reset,
577 	.init = dwxgmac2_dma_init,
578 	.init_chan = dwxgmac2_dma_init_chan,
579 	.init_rx_chan = dwxgmac2_dma_init_rx_chan,
580 	.init_tx_chan = dwxgmac2_dma_init_tx_chan,
581 	.axi = dwxgmac2_dma_axi,
582 	.dump_regs = dwxgmac2_dma_dump_regs,
583 	.dma_rx_mode = dwxgmac2_dma_rx_mode,
584 	.dma_tx_mode = dwxgmac2_dma_tx_mode,
585 	.enable_dma_irq = dwxgmac2_enable_dma_irq,
586 	.disable_dma_irq = dwxgmac2_disable_dma_irq,
587 	.start_tx = dwxgmac2_dma_start_tx,
588 	.stop_tx = dwxgmac2_dma_stop_tx,
589 	.start_rx = dwxgmac2_dma_start_rx,
590 	.stop_rx = dwxgmac2_dma_stop_rx,
591 	.dma_interrupt = dwxgmac2_dma_interrupt,
592 	.get_hw_feature = dwxgmac2_get_hw_feature,
593 	.rx_watchdog = dwxgmac2_rx_watchdog,
594 	.set_rx_ring_len = dwxgmac2_set_rx_ring_len,
595 	.set_tx_ring_len = dwxgmac2_set_tx_ring_len,
596 	.set_rx_tail_ptr = dwxgmac2_set_rx_tail_ptr,
597 	.set_tx_tail_ptr = dwxgmac2_set_tx_tail_ptr,
598 	.enable_tso = dwxgmac2_enable_tso,
599 	.qmode = dwxgmac2_qmode,
600 	.set_bfsize = dwxgmac2_set_bfsize,
601 	.enable_sph = dwxgmac2_enable_sph,
602 	.enable_tbs = dwxgmac2_enable_tbs,
603 };
604