blob: 117c3a5288f01a586201f642349d7ececf24bd60 [file] [log] [blame]
Alexandre TORGUE48863ce2016-04-01 11:37:30 +02001/*
2 * This is the driver for the GMAC on-chip Ethernet controller for ST SoCs.
3 * DWC Ether MAC version 4.xx has been used for developing this code.
4 *
5 * This contains the functions to handle the dma.
6 *
7 * Copyright (C) 2015 STMicroelectronics Ltd
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms and conditions of the GNU General Public License,
11 * version 2, as published by the Free Software Foundation.
12 *
13 * Author: Alexandre Torgue <alexandre.torgue@st.com>
14 */
15
16#include <linux/io.h>
17#include "dwmac4.h"
18#include "dwmac4_dma.h"
19
20static void dwmac4_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
21{
22 u32 value = readl(ioaddr + DMA_SYS_BUS_MODE);
23 int i;
24
25 pr_info("dwmac4: Master AXI performs %s burst length\n",
26 (value & DMA_SYS_BUS_FB) ? "fixed" : "any");
27
28 if (axi->axi_lpi_en)
29 value |= DMA_AXI_EN_LPI;
30 if (axi->axi_xit_frm)
31 value |= DMA_AXI_LPI_XIT_FRM;
32
Niklas Cassel6b3374c2016-12-05 18:12:54 +010033 value &= ~DMA_AXI_WR_OSR_LMT;
Alexandre TORGUE48863ce2016-04-01 11:37:30 +020034 value |= (axi->axi_wr_osr_lmt & DMA_AXI_OSR_MAX) <<
35 DMA_AXI_WR_OSR_LMT_SHIFT;
36
Niklas Cassel6b3374c2016-12-05 18:12:54 +010037 value &= ~DMA_AXI_RD_OSR_LMT;
Alexandre TORGUE48863ce2016-04-01 11:37:30 +020038 value |= (axi->axi_rd_osr_lmt & DMA_AXI_OSR_MAX) <<
39 DMA_AXI_RD_OSR_LMT_SHIFT;
40
41 /* Depending on the UNDEF bit the Master AXI will perform any burst
42 * length according to the BLEN programmed (by default all BLEN are
43 * set).
44 */
45 for (i = 0; i < AXI_BLEN; i++) {
46 switch (axi->axi_blen[i]) {
47 case 256:
48 value |= DMA_AXI_BLEN256;
49 break;
50 case 128:
51 value |= DMA_AXI_BLEN128;
52 break;
53 case 64:
54 value |= DMA_AXI_BLEN64;
55 break;
56 case 32:
57 value |= DMA_AXI_BLEN32;
58 break;
59 case 16:
60 value |= DMA_AXI_BLEN16;
61 break;
62 case 8:
63 value |= DMA_AXI_BLEN8;
64 break;
65 case 4:
66 value |= DMA_AXI_BLEN4;
67 break;
68 }
69 }
70
71 writel(value, ioaddr + DMA_SYS_BUS_MODE);
72}
73
Colin Ian King72de4652017-06-22 17:17:29 +010074static void dwmac4_dma_init_rx_chan(void __iomem *ioaddr,
75 struct stmmac_dma_cfg *dma_cfg,
76 u32 dma_rx_phy, u32 chan)
Alexandre TORGUE48863ce2016-04-01 11:37:30 +020077{
78 u32 value;
Joao Pinto47f2a9c2017-03-15 11:04:53 +000079 u32 rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
Alexandre TORGUE48863ce2016-04-01 11:37:30 +020080
Joao Pinto47f2a9c2017-03-15 11:04:53 +000081 value = readl(ioaddr + DMA_CHAN_RX_CONTROL(chan));
82 value = value | (rxpbl << DMA_BUS_MODE_RPBL_SHIFT);
83 writel(value, ioaddr + DMA_CHAN_RX_CONTROL(chan));
84
85 writel(dma_rx_phy, ioaddr + DMA_CHAN_RX_BASE_ADDR(chan));
86}
87
Colin Ian King72de4652017-06-22 17:17:29 +010088static void dwmac4_dma_init_tx_chan(void __iomem *ioaddr,
89 struct stmmac_dma_cfg *dma_cfg,
90 u32 dma_tx_phy, u32 chan)
Joao Pinto47f2a9c2017-03-15 11:04:53 +000091{
92 u32 value;
93 u32 txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
94
95 value = readl(ioaddr + DMA_CHAN_TX_CONTROL(chan));
96 value = value | (txpbl << DMA_BUS_MODE_PBL_SHIFT);
97 writel(value, ioaddr + DMA_CHAN_TX_CONTROL(chan));
98
99 writel(dma_tx_phy, ioaddr + DMA_CHAN_TX_BASE_ADDR(chan));
100}
101
Colin Ian King72de4652017-06-22 17:17:29 +0100102static void dwmac4_dma_init_channel(void __iomem *ioaddr,
103 struct stmmac_dma_cfg *dma_cfg, u32 chan)
Joao Pinto47f2a9c2017-03-15 11:04:53 +0000104{
105 u32 value;
106
107 /* common channel control register config */
108 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
Niklas Cassel4022d032016-12-07 15:20:08 +0100109 if (dma_cfg->pblx8)
110 value = value | DMA_BUS_MODE_PBL;
Joao Pinto47f2a9c2017-03-15 11:04:53 +0000111 writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200112
113 /* Mask interrupts by writing to CSR7 */
Joao Pinto47f2a9c2017-03-15 11:04:53 +0000114 writel(DMA_CHAN_INTR_DEFAULT_MASK,
115 ioaddr + DMA_CHAN_INTR_ENA(chan));
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200116}
117
Niklas Cassel50ca9032016-12-07 15:20:04 +0100118static void dwmac4_dma_init(void __iomem *ioaddr,
119 struct stmmac_dma_cfg *dma_cfg,
120 u32 dma_tx, u32 dma_rx, int atds)
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200121{
122 u32 value = readl(ioaddr + DMA_SYS_BUS_MODE);
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200123
124 /* Set the Fixed burst mode */
Niklas Cassel50ca9032016-12-07 15:20:04 +0100125 if (dma_cfg->fixed_burst)
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200126 value |= DMA_SYS_BUS_FB;
127
128 /* Mixed Burst has no effect when fb is set */
Niklas Cassel50ca9032016-12-07 15:20:04 +0100129 if (dma_cfg->mixed_burst)
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200130 value |= DMA_SYS_BUS_MB;
131
Niklas Cassel50ca9032016-12-07 15:20:04 +0100132 if (dma_cfg->aal)
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200133 value |= DMA_SYS_BUS_AAL;
134
135 writel(value, ioaddr + DMA_SYS_BUS_MODE);
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200136}
137
LABBE Corentinfbf68222017-02-23 14:12:25 +0100138static void _dwmac4_dump_dma_regs(void __iomem *ioaddr, u32 channel,
139 u32 *reg_space)
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200140{
LABBE Corentinfbf68222017-02-23 14:12:25 +0100141 reg_space[DMA_CHAN_CONTROL(channel) / 4] =
142 readl(ioaddr + DMA_CHAN_CONTROL(channel));
143 reg_space[DMA_CHAN_TX_CONTROL(channel) / 4] =
144 readl(ioaddr + DMA_CHAN_TX_CONTROL(channel));
145 reg_space[DMA_CHAN_RX_CONTROL(channel) / 4] =
146 readl(ioaddr + DMA_CHAN_RX_CONTROL(channel));
147 reg_space[DMA_CHAN_TX_BASE_ADDR(channel) / 4] =
148 readl(ioaddr + DMA_CHAN_TX_BASE_ADDR(channel));
149 reg_space[DMA_CHAN_RX_BASE_ADDR(channel) / 4] =
150 readl(ioaddr + DMA_CHAN_RX_BASE_ADDR(channel));
151 reg_space[DMA_CHAN_TX_END_ADDR(channel) / 4] =
152 readl(ioaddr + DMA_CHAN_TX_END_ADDR(channel));
153 reg_space[DMA_CHAN_RX_END_ADDR(channel) / 4] =
154 readl(ioaddr + DMA_CHAN_RX_END_ADDR(channel));
155 reg_space[DMA_CHAN_TX_RING_LEN(channel) / 4] =
156 readl(ioaddr + DMA_CHAN_TX_RING_LEN(channel));
157 reg_space[DMA_CHAN_RX_RING_LEN(channel) / 4] =
158 readl(ioaddr + DMA_CHAN_RX_RING_LEN(channel));
159 reg_space[DMA_CHAN_INTR_ENA(channel) / 4] =
160 readl(ioaddr + DMA_CHAN_INTR_ENA(channel));
161 reg_space[DMA_CHAN_RX_WATCHDOG(channel) / 4] =
162 readl(ioaddr + DMA_CHAN_RX_WATCHDOG(channel));
163 reg_space[DMA_CHAN_SLOT_CTRL_STATUS(channel) / 4] =
164 readl(ioaddr + DMA_CHAN_SLOT_CTRL_STATUS(channel));
165 reg_space[DMA_CHAN_CUR_TX_DESC(channel) / 4] =
166 readl(ioaddr + DMA_CHAN_CUR_TX_DESC(channel));
167 reg_space[DMA_CHAN_CUR_RX_DESC(channel) / 4] =
168 readl(ioaddr + DMA_CHAN_CUR_RX_DESC(channel));
169 reg_space[DMA_CHAN_CUR_TX_BUF_ADDR(channel) / 4] =
170 readl(ioaddr + DMA_CHAN_CUR_TX_BUF_ADDR(channel));
171 reg_space[DMA_CHAN_CUR_RX_BUF_ADDR(channel) / 4] =
172 readl(ioaddr + DMA_CHAN_CUR_RX_BUF_ADDR(channel));
173 reg_space[DMA_CHAN_STATUS(channel) / 4] =
174 readl(ioaddr + DMA_CHAN_STATUS(channel));
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200175}
176
LABBE Corentinfbf68222017-02-23 14:12:25 +0100177static void dwmac4_dump_dma_regs(void __iomem *ioaddr, u32 *reg_space)
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200178{
179 int i;
180
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200181 for (i = 0; i < DMA_CHANNEL_NB_MAX; i++)
LABBE Corentinfbf68222017-02-23 14:12:25 +0100182 _dwmac4_dump_dma_regs(ioaddr, i, reg_space);
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200183}
184
Joao Pinto3c55d4d2017-03-15 11:04:50 +0000185static void dwmac4_rx_watchdog(void __iomem *ioaddr, u32 riwt, u32 number_chan)
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200186{
Joao Pinto3c55d4d2017-03-15 11:04:50 +0000187 u32 chan;
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200188
Joao Pinto3c55d4d2017-03-15 11:04:50 +0000189 for (chan = 0; chan < number_chan; chan++)
190 writel(riwt, ioaddr + DMA_CHAN_RX_WATCHDOG(chan));
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200191}
192
Joao Pinto6deee222017-03-15 11:04:45 +0000193static void dwmac4_dma_rx_chan_op_mode(void __iomem *ioaddr, int mode,
Jose Abreua0daae12017-10-13 10:58:37 +0100194 u32 channel, int fifosz, u8 qmode)
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200195{
Joao Pinto6deee222017-03-15 11:04:45 +0000196 unsigned int rqs = fifosz / 256 - 1;
197 u32 mtl_rx_op, mtl_rx_int;
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200198
199 mtl_rx_op = readl(ioaddr + MTL_CHAN_RX_OP_MODE(channel));
200
Joao Pinto6deee222017-03-15 11:04:45 +0000201 if (mode == SF_DMA_MODE) {
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200202 pr_debug("GMAC: enable RX store and forward mode\n");
203 mtl_rx_op |= MTL_OP_MODE_RSF;
204 } else {
Joao Pinto6deee222017-03-15 11:04:45 +0000205 pr_debug("GMAC: disable RX SF mode (threshold %d)\n", mode);
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200206 mtl_rx_op &= ~MTL_OP_MODE_RSF;
207 mtl_rx_op &= MTL_OP_MODE_RTC_MASK;
Joao Pinto6deee222017-03-15 11:04:45 +0000208 if (mode <= 32)
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200209 mtl_rx_op |= MTL_OP_MODE_RTC_32;
Joao Pinto6deee222017-03-15 11:04:45 +0000210 else if (mode <= 64)
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200211 mtl_rx_op |= MTL_OP_MODE_RTC_64;
Joao Pinto6deee222017-03-15 11:04:45 +0000212 else if (mode <= 96)
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200213 mtl_rx_op |= MTL_OP_MODE_RTC_96;
214 else
215 mtl_rx_op |= MTL_OP_MODE_RTC_128;
216 }
217
Thierry Reding356b7552017-03-10 17:34:59 +0100218 mtl_rx_op &= ~MTL_OP_MODE_RQS_MASK;
219 mtl_rx_op |= rqs << MTL_OP_MODE_RQS_SHIFT;
220
Jose Abreua0daae12017-10-13 10:58:37 +0100221 /* Enable flow control only if each channel gets 4 KiB or more FIFO and
222 * only if channel is not an AVB channel.
223 */
224 if ((fifosz >= 4096) && (qmode != MTL_QUEUE_AVB)) {
Thierry Reding356b7552017-03-10 17:34:59 +0100225 unsigned int rfd, rfa;
226
227 mtl_rx_op |= MTL_OP_MODE_EHFC;
228
229 /* Set Threshold for Activating Flow Control to min 2 frames,
230 * i.e. 1500 * 2 = 3000 bytes.
231 *
232 * Set Threshold for Deactivating Flow Control to min 1 frame,
233 * i.e. 1500 bytes.
234 */
Joao Pinto6deee222017-03-15 11:04:45 +0000235 switch (fifosz) {
Thierry Reding356b7552017-03-10 17:34:59 +0100236 case 4096:
237 /* This violates the above formula because of FIFO size
238 * limit therefore overflow may occur in spite of this.
239 */
240 rfd = 0x03; /* Full-2.5K */
241 rfa = 0x01; /* Full-1.5K */
242 break;
243
244 case 8192:
245 rfd = 0x06; /* Full-4K */
246 rfa = 0x0a; /* Full-6K */
247 break;
248
249 case 16384:
250 rfd = 0x06; /* Full-4K */
251 rfa = 0x12; /* Full-10K */
252 break;
253
254 default:
255 rfd = 0x06; /* Full-4K */
256 rfa = 0x1e; /* Full-16K */
257 break;
258 }
259
260 mtl_rx_op &= ~MTL_OP_MODE_RFD_MASK;
261 mtl_rx_op |= rfd << MTL_OP_MODE_RFD_SHIFT;
262
263 mtl_rx_op &= ~MTL_OP_MODE_RFA_MASK;
264 mtl_rx_op |= rfa << MTL_OP_MODE_RFA_SHIFT;
265 }
266
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200267 writel(mtl_rx_op, ioaddr + MTL_CHAN_RX_OP_MODE(channel));
268
269 /* Enable MTL RX overflow */
270 mtl_rx_int = readl(ioaddr + MTL_CHAN_INT_CTRL(channel));
271 writel(mtl_rx_int | MTL_RX_OVERFLOW_INT_EN,
272 ioaddr + MTL_CHAN_INT_CTRL(channel));
273}
274
Joao Pinto6deee222017-03-15 11:04:45 +0000275static void dwmac4_dma_tx_chan_op_mode(void __iomem *ioaddr, int mode,
Jose Abreua0daae12017-10-13 10:58:37 +0100276 u32 channel, int fifosz, u8 qmode)
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200277{
Joao Pinto6deee222017-03-15 11:04:45 +0000278 u32 mtl_tx_op = readl(ioaddr + MTL_CHAN_TX_OP_MODE(channel));
Jose Abreu52a76232017-10-13 10:58:36 +0100279 unsigned int tqs = fifosz / 256 - 1;
Joao Pinto6deee222017-03-15 11:04:45 +0000280
281 if (mode == SF_DMA_MODE) {
282 pr_debug("GMAC: enable TX store and forward mode\n");
283 /* Transmit COE type 2 cannot be done in cut-through mode. */
284 mtl_tx_op |= MTL_OP_MODE_TSF;
285 } else {
286 pr_debug("GMAC: disabling TX SF (threshold %d)\n", mode);
287 mtl_tx_op &= ~MTL_OP_MODE_TSF;
288 mtl_tx_op &= MTL_OP_MODE_TTC_MASK;
289 /* Set the transmit threshold */
290 if (mode <= 32)
291 mtl_tx_op |= MTL_OP_MODE_TTC_32;
292 else if (mode <= 64)
293 mtl_tx_op |= MTL_OP_MODE_TTC_64;
294 else if (mode <= 96)
295 mtl_tx_op |= MTL_OP_MODE_TTC_96;
296 else if (mode <= 128)
297 mtl_tx_op |= MTL_OP_MODE_TTC_128;
298 else if (mode <= 192)
299 mtl_tx_op |= MTL_OP_MODE_TTC_192;
300 else if (mode <= 256)
301 mtl_tx_op |= MTL_OP_MODE_TTC_256;
302 else if (mode <= 384)
303 mtl_tx_op |= MTL_OP_MODE_TTC_384;
304 else
305 mtl_tx_op |= MTL_OP_MODE_TTC_512;
306 }
307 /* For an IP with DWC_EQOS_NUM_TXQ == 1, the fields TXQEN and TQS are RO
308 * with reset values: TXQEN on, TQS == DWC_EQOS_TXFIFO_SIZE.
309 * For an IP with DWC_EQOS_NUM_TXQ > 1, the fields TXQEN and TQS are R/W
310 * with reset values: TXQEN off, TQS 256 bytes.
311 *
Jose Abreu52a76232017-10-13 10:58:36 +0100312 * TXQEN must be written for multi-channel operation and TQS must
313 * reflect the available fifo size per queue (total fifo size / number
314 * of enabled queues).
Joao Pinto6deee222017-03-15 11:04:45 +0000315 */
Jose Abreua0daae12017-10-13 10:58:37 +0100316 mtl_tx_op &= ~MTL_OP_MODE_TXQEN_MASK;
317 if (qmode != MTL_QUEUE_AVB)
318 mtl_tx_op |= MTL_OP_MODE_TXQEN;
319 else
320 mtl_tx_op |= MTL_OP_MODE_TXQEN_AV;
Jose Abreu52a76232017-10-13 10:58:36 +0100321 mtl_tx_op &= ~MTL_OP_MODE_TQS_MASK;
322 mtl_tx_op |= tqs << MTL_OP_MODE_TQS_SHIFT;
323
Joao Pinto6deee222017-03-15 11:04:45 +0000324 writel(mtl_tx_op, ioaddr + MTL_CHAN_TX_OP_MODE(channel));
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200325}
326
327static void dwmac4_get_hw_feature(void __iomem *ioaddr,
328 struct dma_features *dma_cap)
329{
330 u32 hw_cap = readl(ioaddr + GMAC_HW_FEATURE0);
331
332 /* MAC HW feature0 */
333 dma_cap->mbps_10_100 = (hw_cap & GMAC_HW_FEAT_MIISEL);
334 dma_cap->mbps_1000 = (hw_cap & GMAC_HW_FEAT_GMIISEL) >> 1;
335 dma_cap->half_duplex = (hw_cap & GMAC_HW_FEAT_HDSEL) >> 2;
336 dma_cap->hash_filter = (hw_cap & GMAC_HW_FEAT_VLHASH) >> 4;
337 dma_cap->multi_addr = (hw_cap & GMAC_HW_FEAT_ADDMAC) >> 18;
338 dma_cap->pcs = (hw_cap & GMAC_HW_FEAT_PCSSEL) >> 3;
339 dma_cap->sma_mdio = (hw_cap & GMAC_HW_FEAT_SMASEL) >> 5;
340 dma_cap->pmt_remote_wake_up = (hw_cap & GMAC_HW_FEAT_RWKSEL) >> 6;
341 dma_cap->pmt_magic_frame = (hw_cap & GMAC_HW_FEAT_MGKSEL) >> 7;
342 /* MMC */
343 dma_cap->rmon = (hw_cap & GMAC_HW_FEAT_MMCSEL) >> 8;
344 /* IEEE 1588-2008 */
345 dma_cap->atime_stamp = (hw_cap & GMAC_HW_FEAT_TSSEL) >> 12;
346 /* 802.3az - Energy-Efficient Ethernet (EEE) */
347 dma_cap->eee = (hw_cap & GMAC_HW_FEAT_EEESEL) >> 13;
348 /* TX and RX csum */
349 dma_cap->tx_coe = (hw_cap & GMAC_HW_FEAT_TXCOSEL) >> 14;
350 dma_cap->rx_coe = (hw_cap & GMAC_HW_FEAT_RXCOESEL) >> 16;
351
352 /* MAC HW feature1 */
353 hw_cap = readl(ioaddr + GMAC_HW_FEATURE1);
354 dma_cap->av = (hw_cap & GMAC_HW_FEAT_AVSEL) >> 20;
355 dma_cap->tsoen = (hw_cap & GMAC_HW_TSOEN) >> 18;
Thierry Reding11fbf812017-03-10 17:34:58 +0100356 /* RX and TX FIFO sizes are encoded as log2(n / 128). Undo that by
357 * shifting and store the sizes in bytes.
358 */
359 dma_cap->tx_fifo_size = 128 << ((hw_cap & GMAC_HW_TXFIFOSIZE) >> 6);
360 dma_cap->rx_fifo_size = 128 << ((hw_cap & GMAC_HW_RXFIFOSIZE) >> 0);
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200361 /* MAC HW feature2 */
362 hw_cap = readl(ioaddr + GMAC_HW_FEATURE2);
363 /* TX and RX number of channels */
364 dma_cap->number_rx_channel =
365 ((hw_cap & GMAC_HW_FEAT_RXCHCNT) >> 12) + 1;
366 dma_cap->number_tx_channel =
367 ((hw_cap & GMAC_HW_FEAT_TXCHCNT) >> 18) + 1;
jpinto9eb12472016-12-28 12:57:48 +0000368 /* TX and RX number of queues */
369 dma_cap->number_rx_queues =
370 ((hw_cap & GMAC_HW_FEAT_RXQCNT) >> 0) + 1;
371 dma_cap->number_tx_queues =
372 ((hw_cap & GMAC_HW_FEAT_TXQCNT) >> 6) + 1;
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200373
374 /* IEEE 1588-2002 */
375 dma_cap->time_stamp = 0;
Jose Abreu8bf993a2018-03-29 10:40:19 +0100376
377 /* MAC HW feature3 */
378 hw_cap = readl(ioaddr + GMAC_HW_FEATURE3);
379
380 /* 5.10 Features */
381 dma_cap->asp = (hw_cap & GMAC_HW_FEAT_ASP) >> 28;
Jose Abreu4dbbe8d2018-05-04 10:01:38 +0100382 dma_cap->frpes = (hw_cap & GMAC_HW_FEAT_FRPES) >> 13;
383 dma_cap->frpbs = (hw_cap & GMAC_HW_FEAT_FRPBS) >> 11;
384 dma_cap->frpsel = (hw_cap & GMAC_HW_FEAT_FRPSEL) >> 10;
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200385}
386
387/* Enable/disable TSO feature and set MSS */
388static void dwmac4_enable_tso(void __iomem *ioaddr, bool en, u32 chan)
389{
390 u32 value;
391
392 if (en) {
393 /* enable TSO */
394 value = readl(ioaddr + DMA_CHAN_TX_CONTROL(chan));
395 writel(value | DMA_CONTROL_TSE,
396 ioaddr + DMA_CHAN_TX_CONTROL(chan));
397 } else {
398 /* enable TSO */
399 value = readl(ioaddr + DMA_CHAN_TX_CONTROL(chan));
400 writel(value & ~DMA_CONTROL_TSE,
401 ioaddr + DMA_CHAN_TX_CONTROL(chan));
402 }
403}
404
405const struct stmmac_dma_ops dwmac4_dma_ops = {
406 .reset = dwmac4_dma_reset,
407 .init = dwmac4_dma_init,
Joao Pinto47f2a9c2017-03-15 11:04:53 +0000408 .init_chan = dwmac4_dma_init_channel,
409 .init_rx_chan = dwmac4_dma_init_rx_chan,
410 .init_tx_chan = dwmac4_dma_init_tx_chan,
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200411 .axi = dwmac4_dma_axi,
412 .dump_regs = dwmac4_dump_dma_regs,
Joao Pinto6deee222017-03-15 11:04:45 +0000413 .dma_rx_mode = dwmac4_dma_rx_chan_op_mode,
414 .dma_tx_mode = dwmac4_dma_tx_chan_op_mode,
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200415 .enable_dma_irq = dwmac4_enable_dma_irq,
416 .disable_dma_irq = dwmac4_disable_dma_irq,
417 .start_tx = dwmac4_dma_start_tx,
418 .stop_tx = dwmac4_dma_stop_tx,
419 .start_rx = dwmac4_dma_start_rx,
420 .stop_rx = dwmac4_dma_stop_rx,
421 .dma_interrupt = dwmac4_dma_interrupt,
422 .get_hw_feature = dwmac4_get_hw_feature,
423 .rx_watchdog = dwmac4_rx_watchdog,
424 .set_rx_ring_len = dwmac4_set_rx_ring_len,
425 .set_tx_ring_len = dwmac4_set_tx_ring_len,
426 .set_rx_tail_ptr = dwmac4_set_rx_tail_ptr,
427 .set_tx_tail_ptr = dwmac4_set_tx_tail_ptr,
428 .enable_tso = dwmac4_enable_tso,
429};
430
431const struct stmmac_dma_ops dwmac410_dma_ops = {
432 .reset = dwmac4_dma_reset,
433 .init = dwmac4_dma_init,
Joao Pinto47f2a9c2017-03-15 11:04:53 +0000434 .init_chan = dwmac4_dma_init_channel,
435 .init_rx_chan = dwmac4_dma_init_rx_chan,
436 .init_tx_chan = dwmac4_dma_init_tx_chan,
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200437 .axi = dwmac4_dma_axi,
438 .dump_regs = dwmac4_dump_dma_regs,
Joao Pinto6deee222017-03-15 11:04:45 +0000439 .dma_rx_mode = dwmac4_dma_rx_chan_op_mode,
440 .dma_tx_mode = dwmac4_dma_tx_chan_op_mode,
Alexandre TORGUE48863ce2016-04-01 11:37:30 +0200441 .enable_dma_irq = dwmac410_enable_dma_irq,
442 .disable_dma_irq = dwmac4_disable_dma_irq,
443 .start_tx = dwmac4_dma_start_tx,
444 .stop_tx = dwmac4_dma_stop_tx,
445 .start_rx = dwmac4_dma_start_rx,
446 .stop_rx = dwmac4_dma_stop_rx,
447 .dma_interrupt = dwmac4_dma_interrupt,
448 .get_hw_feature = dwmac4_get_hw_feature,
449 .rx_watchdog = dwmac4_rx_watchdog,
450 .set_rx_ring_len = dwmac4_set_rx_ring_len,
451 .set_tx_ring_len = dwmac4_set_tx_ring_len,
452 .set_rx_tail_ptr = dwmac4_set_rx_tail_ptr,
453 .set_tx_tail_ptr = dwmac4_set_tx_tail_ptr,
454 .enable_tso = dwmac4_enable_tso,
455};