Skip to content

Commit 2c520b1

Browse files
joabreudavem330
authored andcommitted
net: stmmac: Switch stmmac_mode_ops to generic HW Interface Helpers
Switch stmmac_mode_ops to generic Hardware Interface Helpers instead of using hard-coded callbacks. This makes the code more readable and more flexible. No functional change. Signed-off-by: Jose Abreu <[email protected]> Cc: David S. Miller <[email protected]> Cc: Joao Pinto <[email protected]> Cc: Giuseppe Cavallaro <[email protected]> Cc: Alexandre Torgue <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cc4c900 commit 2c520b1

File tree

5 files changed

+68
-58
lines changed

5 files changed

+68
-58
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include "stmmac.h"
2626

27-
static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
27+
static int jumbo_frm(void *p, struct sk_buff *skb, int csum)
2828
{
2929
struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)p;
3030
unsigned int nopaged_len = skb_headlen(skb);
@@ -93,7 +93,7 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
9393
return entry;
9494
}
9595

96-
static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc)
96+
static unsigned int is_jumbo_frm(int len, int enh_desc)
9797
{
9898
unsigned int ret = 0;
9999

@@ -105,7 +105,7 @@ static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc)
105105
return ret;
106106
}
107107

108-
static void stmmac_init_dma_chain(void *des, dma_addr_t phy_addr,
108+
static void init_dma_chain(void *des, dma_addr_t phy_addr,
109109
unsigned int size, unsigned int extend_desc)
110110
{
111111
/*
@@ -135,7 +135,7 @@ static void stmmac_init_dma_chain(void *des, dma_addr_t phy_addr,
135135
}
136136
}
137137

138-
static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
138+
static void refill_desc3(void *priv_ptr, struct dma_desc *p)
139139
{
140140
struct stmmac_rx_queue *rx_q = (struct stmmac_rx_queue *)priv_ptr;
141141
struct stmmac_priv *priv = rx_q->priv_data;
@@ -151,7 +151,7 @@ static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
151151
sizeof(struct dma_desc)));
152152
}
153153

154-
static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
154+
static void clean_desc3(void *priv_ptr, struct dma_desc *p)
155155
{
156156
struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)priv_ptr;
157157
struct stmmac_priv *priv = tx_q->priv_data;
@@ -169,9 +169,9 @@ static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
169169
}
170170

171171
const struct stmmac_mode_ops chain_mode_ops = {
172-
.init = stmmac_init_dma_chain,
173-
.is_jumbo_frm = stmmac_is_jumbo_frm,
174-
.jumbo_frm = stmmac_jumbo_frm,
175-
.refill_desc3 = stmmac_refill_desc3,
176-
.clean_desc3 = stmmac_clean_desc3,
172+
.init = init_dma_chain,
173+
.is_jumbo_frm = is_jumbo_frm,
174+
.jumbo_frm = jumbo_frm,
175+
.refill_desc3 = refill_desc3,
176+
.clean_desc3 = clean_desc3,
177177
};

drivers/net/ethernet/stmicro/stmmac/common.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -405,18 +405,6 @@ struct mii_regs {
405405
unsigned int clk_csr_mask;
406406
};
407407

408-
/* Helpers to manage the descriptors for chain and ring modes */
409-
struct stmmac_mode_ops {
410-
void (*init) (void *des, dma_addr_t phy_addr, unsigned int size,
411-
unsigned int extend_desc);
412-
unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
413-
int (*jumbo_frm)(void *priv, struct sk_buff *skb, int csum);
414-
int (*set_16kib_bfsize)(int mtu);
415-
void (*init_desc3)(struct dma_desc *p);
416-
void (*refill_desc3) (void *priv, struct dma_desc *p);
417-
void (*clean_desc3) (void *priv, struct dma_desc *p);
418-
};
419-
420408
struct mac_device_info {
421409
const struct stmmac_ops *mac;
422410
const struct stmmac_desc_ops *desc;

drivers/net/ethernet/stmicro/stmmac/hwif.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,4 +391,31 @@ struct stmmac_hwtimestamp {
391391
#define stmmac_get_systime(__priv, __args...) \
392392
stmmac_do_void_callback(__priv, ptp, get_systime, __args)
393393

394+
/* Helpers to manage the descriptors for chain and ring modes */
395+
struct stmmac_mode_ops {
396+
void (*init) (void *des, dma_addr_t phy_addr, unsigned int size,
397+
unsigned int extend_desc);
398+
unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
399+
int (*jumbo_frm)(void *priv, struct sk_buff *skb, int csum);
400+
int (*set_16kib_bfsize)(int mtu);
401+
void (*init_desc3)(struct dma_desc *p);
402+
void (*refill_desc3) (void *priv, struct dma_desc *p);
403+
void (*clean_desc3) (void *priv, struct dma_desc *p);
404+
};
405+
406+
#define stmmac_mode_init(__priv, __args...) \
407+
stmmac_do_void_callback(__priv, mode, init, __args)
408+
#define stmmac_is_jumbo_frm(__priv, __args...) \
409+
stmmac_do_callback(__priv, mode, is_jumbo_frm, __args)
410+
#define stmmac_jumbo_frm(__priv, __args...) \
411+
stmmac_do_callback(__priv, mode, jumbo_frm, __args)
412+
#define stmmac_set_16kib_bfsize(__priv, __args...) \
413+
stmmac_do_callback(__priv, mode, set_16kib_bfsize, __args)
414+
#define stmmac_init_desc3(__priv, __args...) \
415+
stmmac_do_void_callback(__priv, mode, init_desc3, __args)
416+
#define stmmac_refill_desc3(__priv, __args...) \
417+
stmmac_do_void_callback(__priv, mode, refill_desc3, __args)
418+
#define stmmac_clean_desc3(__priv, __args...) \
419+
stmmac_do_void_callback(__priv, mode, clean_desc3, __args)
420+
394421
#endif /* __STMMAC_HWIF_H__ */

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include "stmmac.h"
2626

27-
static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
27+
static int jumbo_frm(void *p, struct sk_buff *skb, int csum)
2828
{
2929
struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)p;
3030
unsigned int nopaged_len = skb_headlen(skb);
@@ -99,7 +99,7 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
9999
return entry;
100100
}
101101

102-
static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc)
102+
static unsigned int is_jumbo_frm(int len, int enh_desc)
103103
{
104104
unsigned int ret = 0;
105105

@@ -109,7 +109,7 @@ static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc)
109109
return ret;
110110
}
111111

112-
static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
112+
static void refill_desc3(void *priv_ptr, struct dma_desc *p)
113113
{
114114
struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr;
115115

@@ -119,12 +119,12 @@ static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
119119
}
120120

121121
/* In ring mode we need to fill the desc3 because it is used as buffer */
122-
static void stmmac_init_desc3(struct dma_desc *p)
122+
static void init_desc3(struct dma_desc *p)
123123
{
124124
p->des3 = cpu_to_le32(le32_to_cpu(p->des2) + BUF_SIZE_8KiB);
125125
}
126126

127-
static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
127+
static void clean_desc3(void *priv_ptr, struct dma_desc *p)
128128
{
129129
struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)priv_ptr;
130130
struct stmmac_priv *priv = tx_q->priv_data;
@@ -137,7 +137,7 @@ static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
137137
p->des3 = 0;
138138
}
139139

140-
static int stmmac_set_16kib_bfsize(int mtu)
140+
static int set_16kib_bfsize(int mtu)
141141
{
142142
int ret = 0;
143143
if (unlikely(mtu >= BUF_SIZE_8KiB))
@@ -146,10 +146,10 @@ static int stmmac_set_16kib_bfsize(int mtu)
146146
}
147147

148148
const struct stmmac_mode_ops ring_mode_ops = {
149-
.is_jumbo_frm = stmmac_is_jumbo_frm,
150-
.jumbo_frm = stmmac_jumbo_frm,
151-
.refill_desc3 = stmmac_refill_desc3,
152-
.init_desc3 = stmmac_init_desc3,
153-
.clean_desc3 = stmmac_clean_desc3,
154-
.set_16kib_bfsize = stmmac_set_16kib_bfsize,
149+
.is_jumbo_frm = is_jumbo_frm,
150+
.jumbo_frm = jumbo_frm,
151+
.refill_desc3 = refill_desc3,
152+
.init_desc3 = init_desc3,
153+
.clean_desc3 = clean_desc3,
154+
.set_16kib_bfsize = set_16kib_bfsize,
155155
};

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

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,9 +1161,8 @@ static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p,
11611161
else
11621162
p->des2 = cpu_to_le32(rx_q->rx_skbuff_dma[i]);
11631163

1164-
if ((priv->hw->mode->init_desc3) &&
1165-
(priv->dma_buf_sz == BUF_SIZE_16KiB))
1166-
priv->hw->mode->init_desc3(p);
1164+
if (priv->dma_buf_sz == BUF_SIZE_16KiB)
1165+
stmmac_init_desc3(priv, p);
11671166

11681167
return 0;
11691168
}
@@ -1229,13 +1228,14 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags)
12291228
{
12301229
struct stmmac_priv *priv = netdev_priv(dev);
12311230
u32 rx_count = priv->plat->rx_queues_to_use;
1232-
unsigned int bfsize = 0;
12331231
int ret = -ENOMEM;
1232+
int bfsize = 0;
12341233
int queue;
12351234
int i;
12361235

1237-
if (priv->hw->mode->set_16kib_bfsize)
1238-
bfsize = priv->hw->mode->set_16kib_bfsize(dev->mtu);
1236+
bfsize = stmmac_set_16kib_bfsize(priv, dev->mtu);
1237+
if (bfsize < 0)
1238+
bfsize = 0;
12391239

12401240
if (bfsize < BUF_SIZE_16KiB)
12411241
bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz);
@@ -1279,13 +1279,11 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags)
12791279
/* Setup the chained descriptor addresses */
12801280
if (priv->mode == STMMAC_CHAIN_MODE) {
12811281
if (priv->extend_desc)
1282-
priv->hw->mode->init(rx_q->dma_erx,
1283-
rx_q->dma_rx_phy,
1284-
DMA_RX_SIZE, 1);
1282+
stmmac_mode_init(priv, rx_q->dma_erx,
1283+
rx_q->dma_rx_phy, DMA_RX_SIZE, 1);
12851284
else
1286-
priv->hw->mode->init(rx_q->dma_rx,
1287-
rx_q->dma_rx_phy,
1288-
DMA_RX_SIZE, 0);
1285+
stmmac_mode_init(priv, rx_q->dma_rx,
1286+
rx_q->dma_rx_phy, DMA_RX_SIZE, 0);
12891287
}
12901288
}
12911289

@@ -1332,13 +1330,11 @@ static int init_dma_tx_desc_rings(struct net_device *dev)
13321330
/* Setup the chained descriptor addresses */
13331331
if (priv->mode == STMMAC_CHAIN_MODE) {
13341332
if (priv->extend_desc)
1335-
priv->hw->mode->init(tx_q->dma_etx,
1336-
tx_q->dma_tx_phy,
1337-
DMA_TX_SIZE, 1);
1333+
stmmac_mode_init(priv, tx_q->dma_etx,
1334+
tx_q->dma_tx_phy, DMA_TX_SIZE, 1);
13381335
else
1339-
priv->hw->mode->init(tx_q->dma_tx,
1340-
tx_q->dma_tx_phy,
1341-
DMA_TX_SIZE, 0);
1336+
stmmac_mode_init(priv, tx_q->dma_tx,
1337+
tx_q->dma_tx_phy, DMA_TX_SIZE, 0);
13421338
}
13431339

13441340
for (i = 0; i < DMA_TX_SIZE; i++) {
@@ -1886,8 +1882,7 @@ static void stmmac_tx_clean(struct stmmac_priv *priv, u32 queue)
18861882
tx_q->tx_skbuff_dma[entry].map_as_page = false;
18871883
}
18881884

1889-
if (priv->hw->mode->clean_desc3)
1890-
priv->hw->mode->clean_desc3(tx_q, p);
1885+
stmmac_clean_desc3(priv, tx_q, p);
18911886

18921887
tx_q->tx_skbuff_dma[entry].last_segment = false;
18931888
tx_q->tx_skbuff_dma[entry].is_jumbo = false;
@@ -3099,11 +3094,11 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
30993094
enh_desc = priv->plat->enh_desc;
31003095
/* To program the descriptors according to the size of the frame */
31013096
if (enh_desc)
3102-
is_jumbo = priv->hw->mode->is_jumbo_frm(skb->len, enh_desc);
3097+
is_jumbo = stmmac_is_jumbo_frm(priv, skb->len, enh_desc);
31033098

31043099
if (unlikely(is_jumbo) && likely(priv->synopsys_id <
31053100
DWMAC_CORE_4_00)) {
3106-
entry = priv->hw->mode->jumbo_frm(tx_q, skb, csum_insertion);
3101+
entry = stmmac_jumbo_frm(priv, tx_q, skb, csum_insertion);
31073102
if (unlikely(entry < 0))
31083103
goto dma_map_err;
31093104
}
@@ -3332,8 +3327,8 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv, u32 queue)
33323327
} else {
33333328
p->des2 = cpu_to_le32(rx_q->rx_skbuff_dma[entry]);
33343329
}
3335-
if (priv->hw->mode->refill_desc3)
3336-
priv->hw->mode->refill_desc3(rx_q, p);
3330+
3331+
stmmac_refill_desc3(priv, rx_q, p);
33373332

33383333
if (rx_q->rx_zeroc_thresh > 0)
33393334
rx_q->rx_zeroc_thresh--;

0 commit comments

Comments
 (0)