Skip to content

Commit ce73678

Browse files
Joao Pintodavem330
authored andcommitted
net: stmmac: adding multiple buffers for TX
This patch adds the structure stmmac_tx_queue which contains tx queues specific data (previously in stmmac_priv). Signed-off-by: Joao Pinto <jpinto@synopsys.com> Tested-by: Niklas Cassel <niklas.cassel@axis.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 54139cf commit ce73678

File tree

4 files changed

+374
-255
lines changed

4 files changed

+374
-255
lines changed

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

Lines changed: 21 additions & 17 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
}
@@ -152,17 +155,18 @@ static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
152155

153156
static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
154157
{
155-
struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr;
156-
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;
157161

158-
if (priv->tx_skbuff_dma[entry].last_segment && !priv->extend_desc &&
162+
if (tx_q->tx_skbuff_dma[entry].last_segment && !priv->extend_desc &&
159163
priv->hwts_tx_en)
160164
/* NOTE: Device will overwrite des3 with timestamp value if
161165
* 1588-2002 time stamping is enabled, hence reinitialize it
162166
* to keep explicit chaining in the descriptor.
163167
*/
164-
p->des3 = cpu_to_le32((unsigned int)((priv->dma_tx_phy +
165-
((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))
166170
* sizeof(struct dma_desc)));
167171
}
168172

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: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ 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+
4963
struct stmmac_rx_queue {
5064
u32 queue_index;
5165
struct stmmac_priv *priv_data;
@@ -62,16 +76,10 @@ struct stmmac_rx_queue {
6276

6377
struct stmmac_priv {
6478
/* Frequently used values are kept adjacent for cache effect */
65-
struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
66-
struct dma_desc *dma_tx;
67-
struct sk_buff **tx_skbuff;
68-
unsigned int cur_tx;
69-
unsigned int dirty_tx;
7079
u32 tx_count_frames;
7180
u32 tx_coal_frames;
7281
u32 tx_coal_timer;
73-
struct stmmac_tx_info *tx_skbuff_dma;
74-
dma_addr_t dma_tx_phy;
82+
7583
int tx_coalesce;
7684
int hwts_tx_en;
7785
bool tx_path_in_lpi_mode;
@@ -94,6 +102,9 @@ struct stmmac_priv {
94102
/* RX Queue */
95103
struct stmmac_rx_queue rx_queue[MTL_MAX_RX_QUEUES];
96104

105+
/* TX Queue */
106+
struct stmmac_tx_queue tx_queue[MTL_MAX_TX_QUEUES];
107+
97108
int oldlink;
98109
int speed;
99110
int oldduplex;
@@ -128,7 +139,6 @@ struct stmmac_priv {
128139
spinlock_t ptp_lock;
129140
void __iomem *mmcaddr;
130141
void __iomem *ptpaddr;
131-
u32 tx_tail_addr;
132142
u32 mss;
133143

134144
#ifdef CONFIG_DEBUG_FS

0 commit comments

Comments
 (0)