Skip to content

Commit aff3d9e

Browse files
Joao Pintodavem330
authored andcommitted
net: stmmac: enable multiple buffers
This patch creates 2 new structures (stmmac_tx_queue and stmmac_rx_queue) in include/linux/stmmac.h, enabling that each RX and TX queue has its own buffers and data. Signed-off-by: Joao Pinto <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent de6b08f commit aff3d9e

File tree

4 files changed

+973
-473
lines changed

4 files changed

+973
-473
lines changed

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

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@
2626

2727
static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
2828
{
29-
struct stmmac_priv *priv = (struct stmmac_priv *)p;
30-
unsigned int entry = priv->cur_tx;
31-
struct dma_desc *desc = priv->dma_tx + entry;
29+
struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)p;
3230
unsigned int nopaged_len = skb_headlen(skb);
31+
struct stmmac_priv *priv = tx_q->priv_data;
32+
unsigned int entry = tx_q->cur_tx;
3333
unsigned int bmax, des2;
3434
unsigned int i = 1, len;
35+
struct dma_desc *desc;
36+
37+
desc = tx_q->dma_tx + entry;
3538

3639
if (priv->plat->enh_desc)
3740
bmax = BUF_SIZE_8KiB;
@@ -45,16 +48,16 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
4548
desc->des2 = cpu_to_le32(des2);
4649
if (dma_mapping_error(priv->device, des2))
4750
return -1;
48-
priv->tx_skbuff_dma[entry].buf = des2;
49-
priv->tx_skbuff_dma[entry].len = bmax;
51+
tx_q->tx_skbuff_dma[entry].buf = des2;
52+
tx_q->tx_skbuff_dma[entry].len = bmax;
5053
/* do not close the descriptor and do not set own bit */
5154
priv->hw->desc->prepare_tx_desc(desc, 1, bmax, csum, STMMAC_CHAIN_MODE,
5255
0, false);
5356

5457
while (len != 0) {
55-
priv->tx_skbuff[entry] = NULL;
58+
tx_q->tx_skbuff[entry] = NULL;
5659
entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE);
57-
desc = priv->dma_tx + entry;
60+
desc = tx_q->dma_tx + entry;
5861

5962
if (len > bmax) {
6063
des2 = dma_map_single(priv->device,
@@ -63,8 +66,8 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
6366
desc->des2 = cpu_to_le32(des2);
6467
if (dma_mapping_error(priv->device, des2))
6568
return -1;
66-
priv->tx_skbuff_dma[entry].buf = des2;
67-
priv->tx_skbuff_dma[entry].len = bmax;
69+
tx_q->tx_skbuff_dma[entry].buf = des2;
70+
tx_q->tx_skbuff_dma[entry].len = bmax;
6871
priv->hw->desc->prepare_tx_desc(desc, 0, bmax, csum,
6972
STMMAC_CHAIN_MODE, 1,
7073
false);
@@ -77,8 +80,8 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
7780
desc->des2 = cpu_to_le32(des2);
7881
if (dma_mapping_error(priv->device, des2))
7982
return -1;
80-
priv->tx_skbuff_dma[entry].buf = des2;
81-
priv->tx_skbuff_dma[entry].len = len;
83+
tx_q->tx_skbuff_dma[entry].buf = des2;
84+
tx_q->tx_skbuff_dma[entry].len = len;
8285
/* last descriptor can be set now */
8386
priv->hw->desc->prepare_tx_desc(desc, 0, len, csum,
8487
STMMAC_CHAIN_MODE, 1,
@@ -87,7 +90,7 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
8790
}
8891
}
8992

90-
priv->cur_tx = entry;
93+
tx_q->cur_tx = entry;
9194

9295
return entry;
9396
}
@@ -136,32 +139,34 @@ static void stmmac_init_dma_chain(void *des, dma_addr_t phy_addr,
136139

137140
static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
138141
{
139-
struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr;
142+
struct stmmac_rx_queue *rx_q = (struct stmmac_rx_queue *)priv_ptr;
143+
struct stmmac_priv *priv = rx_q->priv_data;
140144

141145
if (priv->hwts_rx_en && !priv->extend_desc)
142146
/* NOTE: Device will overwrite des3 with timestamp value if
143147
* 1588-2002 time stamping is enabled, hence reinitialize it
144148
* to keep explicit chaining in the descriptor.
145149
*/
146-
p->des3 = cpu_to_le32((unsigned int)(priv->dma_rx_phy +
147-
(((priv->dirty_rx) + 1) %
150+
p->des3 = cpu_to_le32((unsigned int)(rx_q->dma_rx_phy +
151+
(((rx_q->dirty_rx) + 1) %
148152
DMA_RX_SIZE) *
149153
sizeof(struct dma_desc)));
150154
}
151155

152156
static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
153157
{
154-
struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr;
155-
unsigned int entry = priv->dirty_tx;
158+
struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)priv_ptr;
159+
struct stmmac_priv *priv = tx_q->priv_data;
160+
unsigned int entry = tx_q->dirty_tx;
156161

157-
if (priv->tx_skbuff_dma[entry].last_segment && !priv->extend_desc &&
162+
if (tx_q->tx_skbuff_dma[entry].last_segment && !priv->extend_desc &&
158163
priv->hwts_tx_en)
159164
/* NOTE: Device will overwrite des3 with timestamp value if
160165
* 1588-2002 time stamping is enabled, hence reinitialize it
161166
* to keep explicit chaining in the descriptor.
162167
*/
163-
p->des3 = cpu_to_le32((unsigned int)((priv->dma_tx_phy +
164-
((priv->dirty_tx + 1) % DMA_TX_SIZE))
168+
p->des3 = cpu_to_le32((unsigned int)((tx_q->dma_tx_phy +
169+
((tx_q->dirty_tx + 1) % DMA_TX_SIZE))
165170
* sizeof(struct dma_desc)));
166171
}
167172

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@
2626

2727
static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
2828
{
29-
struct stmmac_priv *priv = (struct stmmac_priv *)p;
30-
unsigned int entry = priv->cur_tx;
31-
struct dma_desc *desc;
29+
struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)p;
3230
unsigned int nopaged_len = skb_headlen(skb);
31+
struct stmmac_priv *priv = tx_q->priv_data;
32+
unsigned int entry = tx_q->cur_tx;
3333
unsigned int bmax, len, des2;
34+
struct dma_desc *desc;
3435

3536
if (priv->extend_desc)
36-
desc = (struct dma_desc *)(priv->dma_etx + entry);
37+
desc = (struct dma_desc *)(tx_q->dma_etx + entry);
3738
else
38-
desc = priv->dma_tx + entry;
39+
desc = tx_q->dma_tx + entry;
3940

4041
if (priv->plat->enh_desc)
4142
bmax = BUF_SIZE_8KiB;
@@ -52,29 +53,29 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
5253
if (dma_mapping_error(priv->device, des2))
5354
return -1;
5455

55-
priv->tx_skbuff_dma[entry].buf = des2;
56-
priv->tx_skbuff_dma[entry].len = bmax;
57-
priv->tx_skbuff_dma[entry].is_jumbo = true;
56+
tx_q->tx_skbuff_dma[entry].buf = des2;
57+
tx_q->tx_skbuff_dma[entry].len = bmax;
58+
tx_q->tx_skbuff_dma[entry].is_jumbo = true;
5859

5960
desc->des3 = cpu_to_le32(des2 + BUF_SIZE_4KiB);
6061
priv->hw->desc->prepare_tx_desc(desc, 1, bmax, csum,
6162
STMMAC_RING_MODE, 0, false);
62-
priv->tx_skbuff[entry] = NULL;
63+
tx_q->tx_skbuff[entry] = NULL;
6364
entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE);
6465

6566
if (priv->extend_desc)
66-
desc = (struct dma_desc *)(priv->dma_etx + entry);
67+
desc = (struct dma_desc *)(tx_q->dma_etx + entry);
6768
else
68-
desc = priv->dma_tx + entry;
69+
desc = tx_q->dma_tx + entry;
6970

7071
des2 = dma_map_single(priv->device, skb->data + bmax, len,
7172
DMA_TO_DEVICE);
7273
desc->des2 = cpu_to_le32(des2);
7374
if (dma_mapping_error(priv->device, des2))
7475
return -1;
75-
priv->tx_skbuff_dma[entry].buf = des2;
76-
priv->tx_skbuff_dma[entry].len = len;
77-
priv->tx_skbuff_dma[entry].is_jumbo = true;
76+
tx_q->tx_skbuff_dma[entry].buf = des2;
77+
tx_q->tx_skbuff_dma[entry].len = len;
78+
tx_q->tx_skbuff_dma[entry].is_jumbo = true;
7879

7980
desc->des3 = cpu_to_le32(des2 + BUF_SIZE_4KiB);
8081
priv->hw->desc->prepare_tx_desc(desc, 0, len, csum,
@@ -85,15 +86,15 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
8586
desc->des2 = cpu_to_le32(des2);
8687
if (dma_mapping_error(priv->device, des2))
8788
return -1;
88-
priv->tx_skbuff_dma[entry].buf = des2;
89-
priv->tx_skbuff_dma[entry].len = nopaged_len;
90-
priv->tx_skbuff_dma[entry].is_jumbo = true;
89+
tx_q->tx_skbuff_dma[entry].buf = des2;
90+
tx_q->tx_skbuff_dma[entry].len = nopaged_len;
91+
tx_q->tx_skbuff_dma[entry].is_jumbo = true;
9192
desc->des3 = cpu_to_le32(des2 + BUF_SIZE_4KiB);
9293
priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, csum,
9394
STMMAC_RING_MODE, 0, true);
9495
}
9596

96-
priv->cur_tx = entry;
97+
tx_q->cur_tx = entry;
9798

9899
return entry;
99100
}
@@ -125,12 +126,13 @@ static void stmmac_init_desc3(struct dma_desc *p)
125126

126127
static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
127128
{
128-
struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr;
129-
unsigned int entry = priv->dirty_tx;
129+
struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)priv_ptr;
130+
struct stmmac_priv *priv = tx_q->priv_data;
131+
unsigned int entry = tx_q->dirty_tx;
130132

131133
/* des3 is only used for jumbo frames tx or time stamping */
132-
if (unlikely(priv->tx_skbuff_dma[entry].is_jumbo ||
133-
(priv->tx_skbuff_dma[entry].last_segment &&
134+
if (unlikely(tx_q->tx_skbuff_dma[entry].is_jumbo ||
135+
(tx_q->tx_skbuff_dma[entry].last_segment &&
134136
!priv->extend_desc && priv->hwts_tx_en)))
135137
p->des3 = 0;
136138
}

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

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,35 @@ struct stmmac_tx_info {
4646
bool is_jumbo;
4747
};
4848

49+
/* Frequently used values are kept adjacent for cache effect */
50+
struct stmmac_tx_queue {
51+
u32 queue_index;
52+
struct stmmac_priv *priv_data;
53+
struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
54+
struct dma_desc *dma_tx;
55+
struct sk_buff **tx_skbuff;
56+
struct stmmac_tx_info *tx_skbuff_dma;
57+
unsigned int cur_tx;
58+
unsigned int dirty_tx;
59+
dma_addr_t dma_tx_phy;
60+
u32 tx_tail_addr;
61+
};
62+
63+
struct stmmac_rx_queue {
64+
u32 queue_index;
65+
struct stmmac_priv *priv_data;
66+
struct dma_extended_desc *dma_erx;
67+
struct dma_desc *dma_rx ____cacheline_aligned_in_smp;
68+
struct sk_buff **rx_skbuff;
69+
dma_addr_t *rx_skbuff_dma;
70+
struct napi_struct napi ____cacheline_aligned_in_smp;
71+
unsigned int cur_rx;
72+
unsigned int dirty_rx;
73+
u32 rx_zeroc_thresh;
74+
dma_addr_t dma_rx_phy;
75+
u32 rx_tail_addr;
76+
};
77+
4978
struct stmmac_priv {
5079
/* Frequently used values are kept adjacent for cache effect */
5180
struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
@@ -56,28 +85,22 @@ struct stmmac_priv {
5685
u32 tx_count_frames;
5786
u32 tx_coal_frames;
5887
u32 tx_coal_timer;
59-
struct stmmac_tx_info *tx_skbuff_dma;
60-
dma_addr_t dma_tx_phy;
6188
int tx_coalesce;
6289
int hwts_tx_en;
6390
bool tx_path_in_lpi_mode;
6491
struct timer_list txtimer;
6592
bool tso;
6693

67-
struct dma_desc *dma_rx ____cacheline_aligned_in_smp;
68-
struct dma_extended_desc *dma_erx;
69-
struct sk_buff **rx_skbuff;
70-
unsigned int cur_rx;
71-
unsigned int dirty_rx;
94+
/* TX Queue */
95+
struct stmmac_tx_queue *tx_queue;
96+
97+
/* RX Queue */
98+
struct stmmac_rx_queue *rx_queue;
99+
72100
unsigned int dma_buf_sz;
73101
unsigned int rx_copybreak;
74-
unsigned int rx_zeroc_thresh;
75102
u32 rx_riwt;
76103
int hwts_rx_en;
77-
dma_addr_t *rx_skbuff_dma;
78-
dma_addr_t dma_rx_phy;
79-
80-
struct napi_struct napi ____cacheline_aligned_in_smp;
81104

82105
void __iomem *ioaddr;
83106
struct net_device *dev;
@@ -119,8 +142,6 @@ struct stmmac_priv {
119142
spinlock_t ptp_lock;
120143
void __iomem *mmcaddr;
121144
void __iomem *ptpaddr;
122-
u32 rx_tail_addr;
123-
u32 tx_tail_addr;
124145
u32 mss;
125146

126147
#ifdef CONFIG_DEBUG_FS

0 commit comments

Comments
 (0)