Skip to content

Commit 286a837

Browse files
cavagiudavem330
authored andcommitted
stmmac: add CHAINED descriptor mode support (V4)
This patch enhances the STMMAC driver to support CHAINED mode of descriptor. STMMAC supports DMA descriptor to operate both in dual buffer(RING) and linked-list(CHAINED) mode. In RING mode (default) each descriptor points to two data buffer pointers whereas in CHAINED mode they point to only one data buffer pointer. In CHAINED mode each descriptor will have pointer to next descriptor in the list, hence creating the explicit chaining in the descriptor itself, whereas such explicit chaining is not possible in RING mode. First version of this work has been done by Rayagond. Then the patch has been reworked avoiding ifdef inside the C code. A new header file has been added to define all the functions needed for managing enhanced and normal descriptors. In fact, these have to be specialized according to the ring/chain usage. Two new C files have been also added to implement the helper routines needed to manage: jumbo frames, chain and ring setup (i.e. desc3). Signed-off-by: Rayagond Kokatanur <rayagond@vayavyalabs.com> Signed-off-by: Giuseppe Cavallaro <peppe.cavallaro@st.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 38fe7a9 commit 286a837

File tree

10 files changed

+491
-105
lines changed

10 files changed

+491
-105
lines changed

drivers/net/ethernet/stmicro/stmmac/Kconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,22 @@ config STMMAC_RTC_TIMER
6363

6464
endchoice
6565

66+
choice
67+
prompt "Select the DMA TX/RX descriptor operating modes"
68+
depends on STMMAC_ETH
69+
---help---
70+
This driver supports DMA descriptor to operate both in dual buffer
71+
(RING) and linked-list(CHAINED) mode. In RING mode each descriptor
72+
points to two data buffer pointers whereas in CHAINED mode they
73+
points to only one data buffer pointer.
74+
75+
config STMMAC_RING
76+
bool "Enable Descriptor Ring Mode"
77+
78+
config STMMAC_CHAINED
79+
bool "Enable Descriptor Chained Mode"
80+
81+
endchoice
82+
83+
6684
endif

drivers/net/ethernet/stmicro/stmmac/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
obj-$(CONFIG_STMMAC_ETH) += stmmac.o
22
stmmac-$(CONFIG_STMMAC_TIMER) += stmmac_timer.o
3+
stmmac-$(CONFIG_STMMAC_RING) += ring_mode.o
4+
stmmac-$(CONFIG_STMMAC_CHAINED) += chain_mode.o
35
stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o \
46
dwmac_lib.o dwmac1000_core.o dwmac1000_dma.o \
57
dwmac100_core.o dwmac100_dma.o enh_desc.o norm_desc.o \
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*******************************************************************************
2+
Specialised functions for managing Chained mode
3+
4+
Copyright(C) 2011 STMicroelectronics Ltd
5+
6+
It defines all the functions used to handle the normal/enhanced
7+
descriptors in case of the DMA is configured to work in chained or
8+
in ring mode.
9+
10+
This program is free software; you can redistribute it and/or modify it
11+
under the terms and conditions of the GNU General Public License,
12+
version 2, as published by the Free Software Foundation.
13+
14+
This program is distributed in the hope it will be useful, but WITHOUT
15+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17+
more details.
18+
19+
You should have received a copy of the GNU General Public License along with
20+
this program; if not, write to the Free Software Foundation, Inc.,
21+
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
22+
23+
The full GNU General Public License is included in this distribution in
24+
the file called "COPYING".
25+
26+
Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
27+
*******************************************************************************/
28+
29+
#include "stmmac.h"
30+
31+
unsigned int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
32+
{
33+
struct stmmac_priv *priv = (struct stmmac_priv *) p;
34+
unsigned int txsize = priv->dma_tx_size;
35+
unsigned int entry = priv->cur_tx % txsize;
36+
struct dma_desc *desc = priv->dma_tx + entry;
37+
unsigned int nopaged_len = skb_headlen(skb);
38+
unsigned int bmax;
39+
unsigned int i = 1, len;
40+
41+
if (priv->plat->enh_desc)
42+
bmax = BUF_SIZE_8KiB;
43+
else
44+
bmax = BUF_SIZE_2KiB;
45+
46+
len = nopaged_len - bmax;
47+
48+
desc->des2 = dma_map_single(priv->device, skb->data,
49+
bmax, DMA_TO_DEVICE);
50+
priv->hw->desc->prepare_tx_desc(desc, 1, bmax, csum);
51+
52+
while (len != 0) {
53+
entry = (++priv->cur_tx) % txsize;
54+
desc = priv->dma_tx + entry;
55+
56+
if (len > bmax) {
57+
desc->des2 = dma_map_single(priv->device,
58+
(skb->data + bmax * i),
59+
bmax, DMA_TO_DEVICE);
60+
priv->hw->desc->prepare_tx_desc(desc, 0, bmax,
61+
csum);
62+
priv->hw->desc->set_tx_owner(desc);
63+
priv->tx_skbuff[entry] = NULL;
64+
len -= bmax;
65+
i++;
66+
} else {
67+
desc->des2 = dma_map_single(priv->device,
68+
(skb->data + bmax * i), len,
69+
DMA_TO_DEVICE);
70+
priv->hw->desc->prepare_tx_desc(desc, 0, len,
71+
csum);
72+
priv->hw->desc->set_tx_owner(desc);
73+
priv->tx_skbuff[entry] = NULL;
74+
len = 0;
75+
}
76+
}
77+
return entry;
78+
}
79+
80+
static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc)
81+
{
82+
unsigned int ret = 0;
83+
84+
if ((enh_desc && (len > BUF_SIZE_8KiB)) ||
85+
(!enh_desc && (len > BUF_SIZE_2KiB))) {
86+
ret = 1;
87+
}
88+
89+
return ret;
90+
}
91+
92+
static void stmmac_refill_desc3(int bfsize, struct dma_desc *p)
93+
{
94+
}
95+
96+
static void stmmac_init_desc3(int des3_as_data_buf, struct dma_desc *p)
97+
{
98+
}
99+
100+
static void stmmac_clean_desc3(struct dma_desc *p)
101+
{
102+
}
103+
104+
static void stmmac_init_dma_chain(struct dma_desc *des, dma_addr_t phy_addr,
105+
unsigned int size)
106+
{
107+
/*
108+
* In chained mode the des3 points to the next element in the ring.
109+
* The latest element has to point to the head.
110+
*/
111+
int i;
112+
struct dma_desc *p = des;
113+
dma_addr_t dma_phy = phy_addr;
114+
115+
for (i = 0; i < (size - 1); i++) {
116+
dma_phy += sizeof(struct dma_desc);
117+
p->des3 = (unsigned int)dma_phy;
118+
p++;
119+
}
120+
p->des3 = (unsigned int)phy_addr;
121+
}
122+
123+
static int stmmac_set_16kib_bfsize(int mtu)
124+
{
125+
/* Not supported */
126+
return 0;
127+
}
128+
129+
const struct stmmac_ring_mode_ops ring_mode_ops = {
130+
.is_jumbo_frm = stmmac_is_jumbo_frm,
131+
.jumbo_frm = stmmac_jumbo_frm,
132+
.refill_desc3 = stmmac_refill_desc3,
133+
.init_desc3 = stmmac_init_desc3,
134+
.init_dma_chain = stmmac_init_dma_chain,
135+
.clean_desc3 = stmmac_clean_desc3,
136+
.set_16kib_bfsize = stmmac_set_16kib_bfsize,
137+
};

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,22 @@ struct mii_regs {
287287
unsigned int data; /* MII Data */
288288
};
289289

290+
struct stmmac_ring_mode_ops {
291+
unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
292+
unsigned int (*jumbo_frm) (void *priv, struct sk_buff *skb, int csum);
293+
void (*refill_desc3) (int bfsize, struct dma_desc *p);
294+
void (*init_desc3) (int des3_as_data_buf, struct dma_desc *p);
295+
void (*init_dma_chain) (struct dma_desc *des, dma_addr_t phy_addr,
296+
unsigned int size);
297+
void (*clean_desc3) (struct dma_desc *p);
298+
int (*set_16kib_bfsize) (int mtu);
299+
};
300+
290301
struct mac_device_info {
291302
const struct stmmac_ops *mac;
292303
const struct stmmac_desc_ops *desc;
293304
const struct stmmac_dma_ops *dma;
305+
const struct stmmac_ring_mode_ops *ring;
294306
struct mii_regs mii; /* MII register Addresses */
295307
struct mac_link link;
296308
unsigned int synopsys_uid;
@@ -304,3 +316,4 @@ extern void stmmac_set_mac_addr(void __iomem *ioaddr, u8 addr[6],
304316
extern void stmmac_get_mac_addr(void __iomem *ioaddr, unsigned char *addr,
305317
unsigned int high, unsigned int low);
306318
extern void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr);
319+
extern const struct stmmac_ring_mode_ops ring_mode_ops;
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*******************************************************************************
2+
Header File to describe Normal/enhanced descriptor functions used for RING
3+
and CHAINED modes.
4+
5+
Copyright(C) 2011 STMicroelectronics Ltd
6+
7+
It defines all the functions used to handle the normal/enhanced
8+
descriptors in case of the DMA is configured to work in chained or
9+
in ring mode.
10+
11+
This program is free software; you can redistribute it and/or modify it
12+
under the terms and conditions of the GNU General Public License,
13+
version 2, as published by the Free Software Foundation.
14+
15+
This program is distributed in the hope it will be useful, but WITHOUT
16+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18+
more details.
19+
20+
You should have received a copy of the GNU General Public License along with
21+
this program; if not, write to the Free Software Foundation, Inc.,
22+
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23+
24+
The full GNU General Public License is included in this distribution in
25+
the file called "COPYING".
26+
27+
Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
28+
*******************************************************************************/
29+
30+
#if defined(CONFIG_STMMAC_RING)
31+
static inline void ehn_desc_rx_set_on_ring_chain(struct dma_desc *p, int end)
32+
{
33+
p->des01.erx.buffer2_size = BUF_SIZE_8KiB - 1;
34+
if (end)
35+
p->des01.erx.end_ring = 1;
36+
}
37+
38+
static inline void ehn_desc_tx_set_on_ring_chain(struct dma_desc *p, int end)
39+
{
40+
if (end)
41+
p->des01.etx.end_ring = 1;
42+
}
43+
44+
static inline void enh_desc_end_tx_desc(struct dma_desc *p, int ter)
45+
{
46+
p->des01.etx.end_ring = ter;
47+
}
48+
49+
static inline void enh_set_tx_desc_len(struct dma_desc *p, int len)
50+
{
51+
if (unlikely(len > BUF_SIZE_4KiB)) {
52+
p->des01.etx.buffer1_size = BUF_SIZE_4KiB;
53+
p->des01.etx.buffer2_size = len - BUF_SIZE_4KiB;
54+
} else
55+
p->des01.etx.buffer1_size = len;
56+
}
57+
58+
static inline void ndesc_rx_set_on_ring_chain(struct dma_desc *p, int end)
59+
{
60+
p->des01.rx.buffer2_size = BUF_SIZE_2KiB - 1;
61+
if (end)
62+
p->des01.rx.end_ring = 1;
63+
}
64+
65+
static inline void ndesc_tx_set_on_ring_chain(struct dma_desc *p, int end)
66+
{
67+
if (end)
68+
p->des01.tx.end_ring = 1;
69+
}
70+
71+
static inline void ndesc_end_tx_desc(struct dma_desc *p, int ter)
72+
{
73+
p->des01.tx.end_ring = ter;
74+
}
75+
76+
static inline void norm_set_tx_desc_len(struct dma_desc *p, int len)
77+
{
78+
if (unlikely(len > BUF_SIZE_2KiB)) {
79+
p->des01.etx.buffer1_size = BUF_SIZE_2KiB - 1;
80+
p->des01.etx.buffer2_size = len - p->des01.etx.buffer1_size;
81+
} else
82+
p->des01.tx.buffer1_size = len;
83+
}
84+
85+
#else
86+
87+
static inline void ehn_desc_rx_set_on_ring_chain(struct dma_desc *p, int end)
88+
{
89+
p->des01.erx.second_address_chained = 1;
90+
}
91+
92+
static inline void ehn_desc_tx_set_on_ring_chain(struct dma_desc *p, int end)
93+
{
94+
p->des01.etx.second_address_chained = 1;
95+
}
96+
97+
static inline void enh_desc_end_tx_desc(struct dma_desc *p, int ter)
98+
{
99+
p->des01.etx.second_address_chained = 1;
100+
}
101+
102+
static inline void enh_set_tx_desc_len(struct dma_desc *p, int len)
103+
{
104+
p->des01.etx.buffer1_size = len;
105+
}
106+
107+
static inline void ndesc_rx_set_on_ring_chain(struct dma_desc *p, int end)
108+
{
109+
p->des01.rx.second_address_chained = 1;
110+
}
111+
112+
static inline void ndesc_tx_set_on_ring_chain(struct dma_desc *p, int ring_size)
113+
{
114+
p->des01.tx.second_address_chained = 1;
115+
}
116+
117+
static inline void ndesc_end_tx_desc(struct dma_desc *p, int ter)
118+
{
119+
p->des01.tx.second_address_chained = 1;
120+
}
121+
122+
static inline void norm_set_tx_desc_len(struct dma_desc *p, int len)
123+
{
124+
p->des01.tx.buffer1_size = len;
125+
}
126+
#endif

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*******************************************************************************/
2424

2525
#include "common.h"
26+
#include "descs_com.h"
2627

2728
static int enh_desc_get_tx_status(void *data, struct stmmac_extra_stats *x,
2829
struct dma_desc *p, void __iomem *ioaddr)
@@ -233,10 +234,9 @@ static void enh_desc_init_rx_desc(struct dma_desc *p, unsigned int ring_size,
233234
for (i = 0; i < ring_size; i++) {
234235
p->des01.erx.own = 1;
235236
p->des01.erx.buffer1_size = BUF_SIZE_8KiB - 1;
236-
/* To support jumbo frames */
237-
p->des01.erx.buffer2_size = BUF_SIZE_8KiB - 1;
238-
if (i == ring_size - 1)
239-
p->des01.erx.end_ring = 1;
237+
238+
ehn_desc_rx_set_on_ring_chain(p, (i == ring_size - 1));
239+
240240
if (disable_rx_ic)
241241
p->des01.erx.disable_ic = 1;
242242
p++;
@@ -249,8 +249,7 @@ static void enh_desc_init_tx_desc(struct dma_desc *p, unsigned int ring_size)
249249

250250
for (i = 0; i < ring_size; i++) {
251251
p->des01.etx.own = 0;
252-
if (i == ring_size - 1)
253-
p->des01.etx.end_ring = 1;
252+
ehn_desc_tx_set_on_ring_chain(p, (i == ring_size - 1));
254253
p++;
255254
}
256255
}
@@ -285,19 +284,16 @@ static void enh_desc_release_tx_desc(struct dma_desc *p)
285284
int ter = p->des01.etx.end_ring;
286285

287286
memset(p, 0, offsetof(struct dma_desc, des2));
288-
p->des01.etx.end_ring = ter;
287+
enh_desc_end_tx_desc(p, ter);
289288
}
290289

291290
static void enh_desc_prepare_tx_desc(struct dma_desc *p, int is_fs, int len,
292291
int csum_flag)
293292
{
294293
p->des01.etx.first_segment = is_fs;
295-
if (unlikely(len > BUF_SIZE_4KiB)) {
296-
p->des01.etx.buffer1_size = BUF_SIZE_4KiB;
297-
p->des01.etx.buffer2_size = len - BUF_SIZE_4KiB;
298-
} else {
299-
p->des01.etx.buffer1_size = len;
300-
}
294+
295+
enh_set_tx_desc_len(p, len);
296+
301297
if (likely(csum_flag))
302298
p->des01.etx.checksum_insertion = cic_full;
303299
}

0 commit comments

Comments
 (0)