Skip to content

Commit 1015133

Browse files
committed
Merge branch 'stmmac-Clean-up-and-tune-up'
Jose Abreu says: ==================== net: stmmac: Clean-up and tune-up This targets to uniformize the handling of the different GMAC versions in stmmac_main.c file and also tune-up the HW. Currently there are some if/else conditions in the main source file which calls different callbacks depending on the ID of GMAC. With the introducion of a generic HW interface handling which automatically selects the GMAC callbacks to be used, it is now unpleasant to see if conditions in the main code because this should be completely agnostic of the GMAC version. This series removes most of these conditions. There are some if conditions that remain untouched but the callbacks handling are now uniformized. Tested in GMAC5, hope I didn't break any previous versions. Please check [1] for performance analisys of patches 3-12. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 538e2de + 61fac60 commit 1015133

File tree

12 files changed

+325
-230
lines changed

12 files changed

+325
-230
lines changed

drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,28 @@ static int sun8i_dwmac_dma_reset(void __iomem *ioaddr)
276276
* Called from stmmac via stmmac_dma_ops->init
277277
*/
278278
static void sun8i_dwmac_dma_init(void __iomem *ioaddr,
279-
struct stmmac_dma_cfg *dma_cfg,
280-
u32 dma_tx, u32 dma_rx, int atds)
279+
struct stmmac_dma_cfg *dma_cfg, int atds)
281280
{
282-
/* Write TX and RX descriptors address */
283-
writel(dma_rx, ioaddr + EMAC_RX_DESC_LIST);
284-
writel(dma_tx, ioaddr + EMAC_TX_DESC_LIST);
285-
286281
writel(EMAC_RX_INT | EMAC_TX_INT, ioaddr + EMAC_INT_EN);
287282
writel(0x1FFFFFF, ioaddr + EMAC_INT_STA);
288283
}
289284

285+
static void sun8i_dwmac_dma_init_rx(void __iomem *ioaddr,
286+
struct stmmac_dma_cfg *dma_cfg,
287+
u32 dma_rx_phy, u32 chan)
288+
{
289+
/* Write RX descriptors address */
290+
writel(dma_rx_phy, ioaddr + EMAC_RX_DESC_LIST);
291+
}
292+
293+
static void sun8i_dwmac_dma_init_tx(void __iomem *ioaddr,
294+
struct stmmac_dma_cfg *dma_cfg,
295+
u32 dma_tx_phy, u32 chan)
296+
{
297+
/* Write TX descriptors address */
298+
writel(dma_tx_phy, ioaddr + EMAC_TX_DESC_LIST);
299+
}
300+
290301
/* sun8i_dwmac_dump_regs() - Dump EMAC address space
291302
* Called from stmmac_dma_ops->dump_regs
292303
* Used for ethtool
@@ -437,13 +448,36 @@ static int sun8i_dwmac_dma_interrupt(void __iomem *ioaddr,
437448
return ret;
438449
}
439450

440-
static void sun8i_dwmac_dma_operation_mode(void __iomem *ioaddr, int txmode,
441-
int rxmode, int rxfifosz)
451+
static void sun8i_dwmac_dma_operation_mode_rx(void __iomem *ioaddr, int mode,
452+
u32 channel, int fifosz, u8 qmode)
453+
{
454+
u32 v;
455+
456+
v = readl(ioaddr + EMAC_RX_CTL1);
457+
if (mode == SF_DMA_MODE) {
458+
v |= EMAC_RX_MD;
459+
} else {
460+
v &= ~EMAC_RX_MD;
461+
v &= ~EMAC_RX_TH_MASK;
462+
if (mode < 32)
463+
v |= EMAC_RX_TH_32;
464+
else if (mode < 64)
465+
v |= EMAC_RX_TH_64;
466+
else if (mode < 96)
467+
v |= EMAC_RX_TH_96;
468+
else if (mode < 128)
469+
v |= EMAC_RX_TH_128;
470+
}
471+
writel(v, ioaddr + EMAC_RX_CTL1);
472+
}
473+
474+
static void sun8i_dwmac_dma_operation_mode_tx(void __iomem *ioaddr, int mode,
475+
u32 channel, int fifosz, u8 qmode)
442476
{
443477
u32 v;
444478

445479
v = readl(ioaddr + EMAC_TX_CTL1);
446-
if (txmode == SF_DMA_MODE) {
480+
if (mode == SF_DMA_MODE) {
447481
v |= EMAC_TX_MD;
448482
/* Undocumented bit (called TX_NEXT_FRM in BSP), the original
449483
* comment is
@@ -454,40 +488,26 @@ static void sun8i_dwmac_dma_operation_mode(void __iomem *ioaddr, int txmode,
454488
} else {
455489
v &= ~EMAC_TX_MD;
456490
v &= ~EMAC_TX_TH_MASK;
457-
if (txmode < 64)
491+
if (mode < 64)
458492
v |= EMAC_TX_TH_64;
459-
else if (txmode < 128)
493+
else if (mode < 128)
460494
v |= EMAC_TX_TH_128;
461-
else if (txmode < 192)
495+
else if (mode < 192)
462496
v |= EMAC_TX_TH_192;
463-
else if (txmode < 256)
497+
else if (mode < 256)
464498
v |= EMAC_TX_TH_256;
465499
}
466500
writel(v, ioaddr + EMAC_TX_CTL1);
467-
468-
v = readl(ioaddr + EMAC_RX_CTL1);
469-
if (rxmode == SF_DMA_MODE) {
470-
v |= EMAC_RX_MD;
471-
} else {
472-
v &= ~EMAC_RX_MD;
473-
v &= ~EMAC_RX_TH_MASK;
474-
if (rxmode < 32)
475-
v |= EMAC_RX_TH_32;
476-
else if (rxmode < 64)
477-
v |= EMAC_RX_TH_64;
478-
else if (rxmode < 96)
479-
v |= EMAC_RX_TH_96;
480-
else if (rxmode < 128)
481-
v |= EMAC_RX_TH_128;
482-
}
483-
writel(v, ioaddr + EMAC_RX_CTL1);
484501
}
485502

486503
static const struct stmmac_dma_ops sun8i_dwmac_dma_ops = {
487504
.reset = sun8i_dwmac_dma_reset,
488505
.init = sun8i_dwmac_dma_init,
506+
.init_rx_chan = sun8i_dwmac_dma_init_rx,
507+
.init_tx_chan = sun8i_dwmac_dma_init_tx,
489508
.dump_regs = sun8i_dwmac_dump_regs,
490-
.dma_mode = sun8i_dwmac_dma_operation_mode,
509+
.dma_rx_mode = sun8i_dwmac_dma_operation_mode_rx,
510+
.dma_tx_mode = sun8i_dwmac_dma_operation_mode_tx,
491511
.enable_dma_transmission = sun8i_dwmac_enable_dma_transmission,
492512
.enable_dma_irq = sun8i_dwmac_enable_dma_irq,
493513
.disable_dma_irq = sun8i_dwmac_disable_dma_irq,

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
8181
}
8282

8383
static void dwmac1000_dma_init(void __iomem *ioaddr,
84-
struct stmmac_dma_cfg *dma_cfg,
85-
u32 dma_tx, u32 dma_rx, int atds)
84+
struct stmmac_dma_cfg *dma_cfg, int atds)
8685
{
8786
u32 value = readl(ioaddr + DMA_BUS_MODE);
8887
int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
@@ -119,12 +118,22 @@ static void dwmac1000_dma_init(void __iomem *ioaddr,
119118

120119
/* Mask interrupts by writing to CSR7 */
121120
writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
121+
}
122122

123-
/* RX/TX descriptor base address lists must be written into
124-
* DMA CSR3 and CSR4, respectively
125-
*/
126-
writel(dma_tx, ioaddr + DMA_TX_BASE_ADDR);
127-
writel(dma_rx, ioaddr + DMA_RCV_BASE_ADDR);
123+
static void dwmac1000_dma_init_rx(void __iomem *ioaddr,
124+
struct stmmac_dma_cfg *dma_cfg,
125+
u32 dma_rx_phy, u32 chan)
126+
{
127+
/* RX descriptor base address list must be written into DMA CSR3 */
128+
writel(dma_rx_phy, ioaddr + DMA_RCV_BASE_ADDR);
129+
}
130+
131+
static void dwmac1000_dma_init_tx(void __iomem *ioaddr,
132+
struct stmmac_dma_cfg *dma_cfg,
133+
u32 dma_tx_phy, u32 chan)
134+
{
135+
/* TX descriptor base address list must be written into DMA CSR4 */
136+
writel(dma_tx_phy, ioaddr + DMA_TX_BASE_ADDR);
128137
}
129138

130139
static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz)
@@ -148,12 +157,40 @@ static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz)
148157
return csr6;
149158
}
150159

151-
static void dwmac1000_dma_operation_mode(void __iomem *ioaddr, int txmode,
152-
int rxmode, int rxfifosz)
160+
static void dwmac1000_dma_operation_mode_rx(void __iomem *ioaddr, int mode,
161+
u32 channel, int fifosz, u8 qmode)
162+
{
163+
u32 csr6 = readl(ioaddr + DMA_CONTROL);
164+
165+
if (mode == SF_DMA_MODE) {
166+
pr_debug("GMAC: enable RX store and forward mode\n");
167+
csr6 |= DMA_CONTROL_RSF;
168+
} else {
169+
pr_debug("GMAC: disable RX SF mode (threshold %d)\n", mode);
170+
csr6 &= ~DMA_CONTROL_RSF;
171+
csr6 &= DMA_CONTROL_TC_RX_MASK;
172+
if (mode <= 32)
173+
csr6 |= DMA_CONTROL_RTC_32;
174+
else if (mode <= 64)
175+
csr6 |= DMA_CONTROL_RTC_64;
176+
else if (mode <= 96)
177+
csr6 |= DMA_CONTROL_RTC_96;
178+
else
179+
csr6 |= DMA_CONTROL_RTC_128;
180+
}
181+
182+
/* Configure flow control based on rx fifo size */
183+
csr6 = dwmac1000_configure_fc(csr6, fifosz);
184+
185+
writel(csr6, ioaddr + DMA_CONTROL);
186+
}
187+
188+
static void dwmac1000_dma_operation_mode_tx(void __iomem *ioaddr, int mode,
189+
u32 channel, int fifosz, u8 qmode)
153190
{
154191
u32 csr6 = readl(ioaddr + DMA_CONTROL);
155192

156-
if (txmode == SF_DMA_MODE) {
193+
if (mode == SF_DMA_MODE) {
157194
pr_debug("GMAC: enable TX store and forward mode\n");
158195
/* Transmit COE type 2 cannot be done in cut-through mode. */
159196
csr6 |= DMA_CONTROL_TSF;
@@ -162,42 +199,22 @@ static void dwmac1000_dma_operation_mode(void __iomem *ioaddr, int txmode,
162199
*/
163200
csr6 |= DMA_CONTROL_OSF;
164201
} else {
165-
pr_debug("GMAC: disabling TX SF (threshold %d)\n", txmode);
202+
pr_debug("GMAC: disabling TX SF (threshold %d)\n", mode);
166203
csr6 &= ~DMA_CONTROL_TSF;
167204
csr6 &= DMA_CONTROL_TC_TX_MASK;
168205
/* Set the transmit threshold */
169-
if (txmode <= 32)
206+
if (mode <= 32)
170207
csr6 |= DMA_CONTROL_TTC_32;
171-
else if (txmode <= 64)
208+
else if (mode <= 64)
172209
csr6 |= DMA_CONTROL_TTC_64;
173-
else if (txmode <= 128)
210+
else if (mode <= 128)
174211
csr6 |= DMA_CONTROL_TTC_128;
175-
else if (txmode <= 192)
212+
else if (mode <= 192)
176213
csr6 |= DMA_CONTROL_TTC_192;
177214
else
178215
csr6 |= DMA_CONTROL_TTC_256;
179216
}
180217

181-
if (rxmode == SF_DMA_MODE) {
182-
pr_debug("GMAC: enable RX store and forward mode\n");
183-
csr6 |= DMA_CONTROL_RSF;
184-
} else {
185-
pr_debug("GMAC: disable RX SF mode (threshold %d)\n", rxmode);
186-
csr6 &= ~DMA_CONTROL_RSF;
187-
csr6 &= DMA_CONTROL_TC_RX_MASK;
188-
if (rxmode <= 32)
189-
csr6 |= DMA_CONTROL_RTC_32;
190-
else if (rxmode <= 64)
191-
csr6 |= DMA_CONTROL_RTC_64;
192-
else if (rxmode <= 96)
193-
csr6 |= DMA_CONTROL_RTC_96;
194-
else
195-
csr6 |= DMA_CONTROL_RTC_128;
196-
}
197-
198-
/* Configure flow control based on rx fifo size */
199-
csr6 = dwmac1000_configure_fc(csr6, rxfifosz);
200-
201218
writel(csr6, ioaddr + DMA_CONTROL);
202219
}
203220

@@ -256,9 +273,12 @@ static void dwmac1000_rx_watchdog(void __iomem *ioaddr, u32 riwt,
256273
const struct stmmac_dma_ops dwmac1000_dma_ops = {
257274
.reset = dwmac_dma_reset,
258275
.init = dwmac1000_dma_init,
276+
.init_rx_chan = dwmac1000_dma_init_rx,
277+
.init_tx_chan = dwmac1000_dma_init_tx,
259278
.axi = dwmac1000_dma_axi,
260279
.dump_regs = dwmac1000_dump_dma_regs,
261-
.dma_mode = dwmac1000_dma_operation_mode,
280+
.dma_rx_mode = dwmac1000_dma_operation_mode_rx,
281+
.dma_tx_mode = dwmac1000_dma_operation_mode_tx,
262282
.enable_dma_transmission = dwmac_enable_dma_transmission,
263283
.enable_dma_irq = dwmac_enable_dma_irq,
264284
.disable_dma_irq = dwmac_disable_dma_irq,

drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,45 @@
2929
#include "dwmac_dma.h"
3030

3131
static void dwmac100_dma_init(void __iomem *ioaddr,
32-
struct stmmac_dma_cfg *dma_cfg,
33-
u32 dma_tx, u32 dma_rx, int atds)
32+
struct stmmac_dma_cfg *dma_cfg, int atds)
3433
{
3534
/* Enable Application Access by writing to DMA CSR0 */
3635
writel(DMA_BUS_MODE_DEFAULT | (dma_cfg->pbl << DMA_BUS_MODE_PBL_SHIFT),
3736
ioaddr + DMA_BUS_MODE);
3837

3938
/* Mask interrupts by writing to CSR7 */
4039
writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
40+
}
4141

42-
/* RX/TX descriptor base addr lists must be written into
43-
* DMA CSR3 and CSR4, respectively
44-
*/
45-
writel(dma_tx, ioaddr + DMA_TX_BASE_ADDR);
46-
writel(dma_rx, ioaddr + DMA_RCV_BASE_ADDR);
42+
static void dwmac100_dma_init_rx(void __iomem *ioaddr,
43+
struct stmmac_dma_cfg *dma_cfg,
44+
u32 dma_rx_phy, u32 chan)
45+
{
46+
/* RX descriptor base addr lists must be written into DMA CSR3 */
47+
writel(dma_rx_phy, ioaddr + DMA_RCV_BASE_ADDR);
48+
}
49+
50+
static void dwmac100_dma_init_tx(void __iomem *ioaddr,
51+
struct stmmac_dma_cfg *dma_cfg,
52+
u32 dma_tx_phy, u32 chan)
53+
{
54+
/* TX descriptor base addr lists must be written into DMA CSR4 */
55+
writel(dma_tx_phy, ioaddr + DMA_TX_BASE_ADDR);
4756
}
4857

4958
/* Store and Forward capability is not used at all.
5059
*
5160
* The transmit threshold can be programmed by setting the TTC bits in the DMA
5261
* control register.
5362
*/
54-
static void dwmac100_dma_operation_mode(void __iomem *ioaddr, int txmode,
55-
int rxmode, int rxfifosz)
63+
static void dwmac100_dma_operation_mode_tx(void __iomem *ioaddr, int mode,
64+
u32 channel, int fifosz, u8 qmode)
5665
{
5766
u32 csr6 = readl(ioaddr + DMA_CONTROL);
5867

59-
if (txmode <= 32)
68+
if (mode <= 32)
6069
csr6 |= DMA_CONTROL_TTC_32;
61-
else if (txmode <= 64)
70+
else if (mode <= 64)
6271
csr6 |= DMA_CONTROL_TTC_64;
6372
else
6473
csr6 |= DMA_CONTROL_TTC_128;
@@ -112,8 +121,10 @@ static void dwmac100_dma_diagnostic_fr(void *data, struct stmmac_extra_stats *x,
112121
const struct stmmac_dma_ops dwmac100_dma_ops = {
113122
.reset = dwmac_dma_reset,
114123
.init = dwmac100_dma_init,
124+
.init_rx_chan = dwmac100_dma_init_rx,
125+
.init_tx_chan = dwmac100_dma_init_tx,
115126
.dump_regs = dwmac100_dump_dma_regs,
116-
.dma_mode = dwmac100_dma_operation_mode,
127+
.dma_tx_mode = dwmac100_dma_operation_mode_tx,
117128
.dma_diagnostic_fr = dwmac100_dma_diagnostic_fr,
118129
.enable_dma_transmission = dwmac_enable_dma_transmission,
119130
.enable_dma_irq = dwmac_enable_dma_irq,

drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,12 @@ static void dwmac4_set_tx_owner(struct dma_desc *p)
189189
p->des3 |= cpu_to_le32(TDES3_OWN);
190190
}
191191

192-
static void dwmac4_set_rx_owner(struct dma_desc *p)
192+
static void dwmac4_set_rx_owner(struct dma_desc *p, int disable_rx_ic)
193193
{
194-
p->des3 |= cpu_to_le32(RDES3_OWN);
194+
p->des3 = cpu_to_le32(RDES3_OWN | RDES3_BUFFER1_VALID_ADDR);
195+
196+
if (!disable_rx_ic)
197+
p->des3 |= cpu_to_le32(RDES3_INT_ON_COMPLETION_EN);
195198
}
196199

197200
static int dwmac4_get_tx_ls(struct dma_desc *p)
@@ -292,10 +295,7 @@ static int dwmac4_wrback_get_rx_timestamp_status(void *desc, void *next_desc,
292295
static void dwmac4_rd_init_rx_desc(struct dma_desc *p, int disable_rx_ic,
293296
int mode, int end)
294297
{
295-
p->des3 = cpu_to_le32(RDES3_OWN | RDES3_BUFFER1_VALID_ADDR);
296-
297-
if (!disable_rx_ic)
298-
p->des3 |= cpu_to_le32(RDES3_INT_ON_COMPLETION_EN);
298+
dwmac4_set_rx_owner(p, disable_rx_ic);
299299
}
300300

301301
static void dwmac4_rd_init_tx_desc(struct dma_desc *p, int mode, int end)
@@ -424,6 +424,25 @@ static void dwmac4_set_mss_ctxt(struct dma_desc *p, unsigned int mss)
424424
p->des3 = cpu_to_le32(TDES3_CONTEXT_TYPE | TDES3_CTXT_TCMSSV);
425425
}
426426

427+
static void dwmac4_get_addr(struct dma_desc *p, unsigned int *addr)
428+
{
429+
*addr = le32_to_cpu(p->des0);
430+
}
431+
432+
static void dwmac4_set_addr(struct dma_desc *p, dma_addr_t addr)
433+
{
434+
p->des0 = cpu_to_le32(addr);
435+
p->des1 = 0;
436+
}
437+
438+
static void dwmac4_clear(struct dma_desc *p)
439+
{
440+
p->des0 = 0;
441+
p->des1 = 0;
442+
p->des2 = 0;
443+
p->des3 = 0;
444+
}
445+
427446
const struct stmmac_desc_ops dwmac4_desc_ops = {
428447
.tx_status = dwmac4_wrback_get_tx_status,
429448
.rx_status = dwmac4_wrback_get_rx_status,
@@ -445,6 +464,9 @@ const struct stmmac_desc_ops dwmac4_desc_ops = {
445464
.init_tx_desc = dwmac4_rd_init_tx_desc,
446465
.display_ring = dwmac4_display_ring,
447466
.set_mss = dwmac4_set_mss_ctxt,
467+
.get_addr = dwmac4_get_addr,
468+
.set_addr = dwmac4_set_addr,
469+
.clear = dwmac4_clear,
448470
};
449471

450472
const struct stmmac_mode_ops dwmac4_ring_mode_ops = { };

0 commit comments

Comments
 (0)