Commit 9e58c8b4 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by David S. Miller

net: mvneta: make tx buffer array agnostic

Allow tx buffer array to contain both skb and xdp buffers in order to
enable xdp frame recycling adding XDP_TX verdict support
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fa383f6b
...@@ -561,6 +561,20 @@ struct mvneta_rx_desc { ...@@ -561,6 +561,20 @@ struct mvneta_rx_desc {
}; };
#endif #endif
enum mvneta_tx_buf_type {
MVNETA_TYPE_SKB,
MVNETA_TYPE_XDP_TX,
MVNETA_TYPE_XDP_NDO,
};
struct mvneta_tx_buf {
enum mvneta_tx_buf_type type;
union {
struct xdp_frame *xdpf;
struct sk_buff *skb;
};
};
struct mvneta_tx_queue { struct mvneta_tx_queue {
/* Number of this TX queue, in the range 0-7 */ /* Number of this TX queue, in the range 0-7 */
u8 id; u8 id;
...@@ -576,8 +590,8 @@ struct mvneta_tx_queue { ...@@ -576,8 +590,8 @@ struct mvneta_tx_queue {
int tx_stop_threshold; int tx_stop_threshold;
int tx_wake_threshold; int tx_wake_threshold;
/* Array of transmitted skb */ /* Array of transmitted buffers */
struct sk_buff **tx_skb; struct mvneta_tx_buf *buf;
/* Index of last TX DMA descriptor that was inserted */ /* Index of last TX DMA descriptor that was inserted */
int txq_put_index; int txq_put_index;
...@@ -1780,14 +1794,9 @@ static void mvneta_txq_bufs_free(struct mvneta_port *pp, ...@@ -1780,14 +1794,9 @@ static void mvneta_txq_bufs_free(struct mvneta_port *pp,
int i; int i;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
struct mvneta_tx_buf *buf = &txq->buf[txq->txq_get_index];
struct mvneta_tx_desc *tx_desc = txq->descs + struct mvneta_tx_desc *tx_desc = txq->descs +
txq->txq_get_index; txq->txq_get_index;
struct sk_buff *skb = txq->tx_skb[txq->txq_get_index];
if (skb) {
bytes_compl += skb->len;
pkts_compl++;
}
mvneta_txq_inc_get(txq); mvneta_txq_inc_get(txq);
...@@ -1795,9 +1804,12 @@ static void mvneta_txq_bufs_free(struct mvneta_port *pp, ...@@ -1795,9 +1804,12 @@ static void mvneta_txq_bufs_free(struct mvneta_port *pp,
dma_unmap_single(pp->dev->dev.parent, dma_unmap_single(pp->dev->dev.parent,
tx_desc->buf_phys_addr, tx_desc->buf_phys_addr,
tx_desc->data_size, DMA_TO_DEVICE); tx_desc->data_size, DMA_TO_DEVICE);
if (!skb) if (!buf->skb)
continue; continue;
dev_kfree_skb_any(skb);
bytes_compl += buf->skb->len;
pkts_compl++;
dev_kfree_skb_any(buf->skb);
} }
netdev_tx_completed_queue(nq, pkts_compl, bytes_compl); netdev_tx_completed_queue(nq, pkts_compl, bytes_compl);
...@@ -2324,16 +2336,19 @@ static inline void ...@@ -2324,16 +2336,19 @@ static inline void
mvneta_tso_put_hdr(struct sk_buff *skb, mvneta_tso_put_hdr(struct sk_buff *skb,
struct mvneta_port *pp, struct mvneta_tx_queue *txq) struct mvneta_port *pp, struct mvneta_tx_queue *txq)
{ {
struct mvneta_tx_desc *tx_desc;
int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
struct mvneta_tx_buf *buf = &txq->buf[txq->txq_put_index];
struct mvneta_tx_desc *tx_desc;
txq->tx_skb[txq->txq_put_index] = NULL;
tx_desc = mvneta_txq_next_desc_get(txq); tx_desc = mvneta_txq_next_desc_get(txq);
tx_desc->data_size = hdr_len; tx_desc->data_size = hdr_len;
tx_desc->command = mvneta_skb_tx_csum(pp, skb); tx_desc->command = mvneta_skb_tx_csum(pp, skb);
tx_desc->command |= MVNETA_TXD_F_DESC; tx_desc->command |= MVNETA_TXD_F_DESC;
tx_desc->buf_phys_addr = txq->tso_hdrs_phys + tx_desc->buf_phys_addr = txq->tso_hdrs_phys +
txq->txq_put_index * TSO_HEADER_SIZE; txq->txq_put_index * TSO_HEADER_SIZE;
buf->type = MVNETA_TYPE_SKB;
buf->skb = NULL;
mvneta_txq_inc_put(txq); mvneta_txq_inc_put(txq);
} }
...@@ -2342,6 +2357,7 @@ mvneta_tso_put_data(struct net_device *dev, struct mvneta_tx_queue *txq, ...@@ -2342,6 +2357,7 @@ mvneta_tso_put_data(struct net_device *dev, struct mvneta_tx_queue *txq,
struct sk_buff *skb, char *data, int size, struct sk_buff *skb, char *data, int size,
bool last_tcp, bool is_last) bool last_tcp, bool is_last)
{ {
struct mvneta_tx_buf *buf = &txq->buf[txq->txq_put_index];
struct mvneta_tx_desc *tx_desc; struct mvneta_tx_desc *tx_desc;
tx_desc = mvneta_txq_next_desc_get(txq); tx_desc = mvneta_txq_next_desc_get(txq);
...@@ -2355,7 +2371,8 @@ mvneta_tso_put_data(struct net_device *dev, struct mvneta_tx_queue *txq, ...@@ -2355,7 +2371,8 @@ mvneta_tso_put_data(struct net_device *dev, struct mvneta_tx_queue *txq,
} }
tx_desc->command = 0; tx_desc->command = 0;
txq->tx_skb[txq->txq_put_index] = NULL; buf->type = MVNETA_TYPE_SKB;
buf->skb = NULL;
if (last_tcp) { if (last_tcp) {
/* last descriptor in the TCP packet */ /* last descriptor in the TCP packet */
...@@ -2363,7 +2380,7 @@ mvneta_tso_put_data(struct net_device *dev, struct mvneta_tx_queue *txq, ...@@ -2363,7 +2380,7 @@ mvneta_tso_put_data(struct net_device *dev, struct mvneta_tx_queue *txq,
/* last descriptor in SKB */ /* last descriptor in SKB */
if (is_last) if (is_last)
txq->tx_skb[txq->txq_put_index] = skb; buf->skb = skb;
} }
mvneta_txq_inc_put(txq); mvneta_txq_inc_put(txq);
return 0; return 0;
...@@ -2448,6 +2465,7 @@ static int mvneta_tx_frag_process(struct mvneta_port *pp, struct sk_buff *skb, ...@@ -2448,6 +2465,7 @@ static int mvneta_tx_frag_process(struct mvneta_port *pp, struct sk_buff *skb,
int i, nr_frags = skb_shinfo(skb)->nr_frags; int i, nr_frags = skb_shinfo(skb)->nr_frags;
for (i = 0; i < nr_frags; i++) { for (i = 0; i < nr_frags; i++) {
struct mvneta_tx_buf *buf = &txq->buf[txq->txq_put_index];
skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
void *addr = skb_frag_address(frag); void *addr = skb_frag_address(frag);
...@@ -2467,12 +2485,13 @@ static int mvneta_tx_frag_process(struct mvneta_port *pp, struct sk_buff *skb, ...@@ -2467,12 +2485,13 @@ static int mvneta_tx_frag_process(struct mvneta_port *pp, struct sk_buff *skb,
if (i == nr_frags - 1) { if (i == nr_frags - 1) {
/* Last descriptor */ /* Last descriptor */
tx_desc->command = MVNETA_TXD_L_DESC | MVNETA_TXD_Z_PAD; tx_desc->command = MVNETA_TXD_L_DESC | MVNETA_TXD_Z_PAD;
txq->tx_skb[txq->txq_put_index] = skb; buf->skb = skb;
} else { } else {
/* Descriptor in the middle: Not First, Not Last */ /* Descriptor in the middle: Not First, Not Last */
tx_desc->command = 0; tx_desc->command = 0;
txq->tx_skb[txq->txq_put_index] = NULL; buf->skb = NULL;
} }
buf->type = MVNETA_TYPE_SKB;
mvneta_txq_inc_put(txq); mvneta_txq_inc_put(txq);
} }
...@@ -2500,6 +2519,7 @@ static netdev_tx_t mvneta_tx(struct sk_buff *skb, struct net_device *dev) ...@@ -2500,6 +2519,7 @@ static netdev_tx_t mvneta_tx(struct sk_buff *skb, struct net_device *dev)
struct mvneta_port *pp = netdev_priv(dev); struct mvneta_port *pp = netdev_priv(dev);
u16 txq_id = skb_get_queue_mapping(skb); u16 txq_id = skb_get_queue_mapping(skb);
struct mvneta_tx_queue *txq = &pp->txqs[txq_id]; struct mvneta_tx_queue *txq = &pp->txqs[txq_id];
struct mvneta_tx_buf *buf = &txq->buf[txq->txq_put_index];
struct mvneta_tx_desc *tx_desc; struct mvneta_tx_desc *tx_desc;
int len = skb->len; int len = skb->len;
int frags = 0; int frags = 0;
...@@ -2532,16 +2552,17 @@ static netdev_tx_t mvneta_tx(struct sk_buff *skb, struct net_device *dev) ...@@ -2532,16 +2552,17 @@ static netdev_tx_t mvneta_tx(struct sk_buff *skb, struct net_device *dev)
goto out; goto out;
} }
buf->type = MVNETA_TYPE_SKB;
if (frags == 1) { if (frags == 1) {
/* First and Last descriptor */ /* First and Last descriptor */
tx_cmd |= MVNETA_TXD_FLZ_DESC; tx_cmd |= MVNETA_TXD_FLZ_DESC;
tx_desc->command = tx_cmd; tx_desc->command = tx_cmd;
txq->tx_skb[txq->txq_put_index] = skb; buf->skb = skb;
mvneta_txq_inc_put(txq); mvneta_txq_inc_put(txq);
} else { } else {
/* First but not Last */ /* First but not Last */
tx_cmd |= MVNETA_TXD_F_DESC; tx_cmd |= MVNETA_TXD_F_DESC;
txq->tx_skb[txq->txq_put_index] = NULL; buf->skb = NULL;
mvneta_txq_inc_put(txq); mvneta_txq_inc_put(txq);
tx_desc->command = tx_cmd; tx_desc->command = tx_cmd;
/* Continue with other skb fragments */ /* Continue with other skb fragments */
...@@ -3128,9 +3149,8 @@ static int mvneta_txq_sw_init(struct mvneta_port *pp, ...@@ -3128,9 +3149,8 @@ static int mvneta_txq_sw_init(struct mvneta_port *pp,
txq->last_desc = txq->size - 1; txq->last_desc = txq->size - 1;
txq->tx_skb = kmalloc_array(txq->size, sizeof(*txq->tx_skb), txq->buf = kmalloc_array(txq->size, sizeof(*txq->buf), GFP_KERNEL);
GFP_KERNEL); if (!txq->buf) {
if (!txq->tx_skb) {
dma_free_coherent(pp->dev->dev.parent, dma_free_coherent(pp->dev->dev.parent,
txq->size * MVNETA_DESC_ALIGNED_SIZE, txq->size * MVNETA_DESC_ALIGNED_SIZE,
txq->descs, txq->descs_phys); txq->descs, txq->descs_phys);
...@@ -3142,7 +3162,7 @@ static int mvneta_txq_sw_init(struct mvneta_port *pp, ...@@ -3142,7 +3162,7 @@ static int mvneta_txq_sw_init(struct mvneta_port *pp,
txq->size * TSO_HEADER_SIZE, txq->size * TSO_HEADER_SIZE,
&txq->tso_hdrs_phys, GFP_KERNEL); &txq->tso_hdrs_phys, GFP_KERNEL);
if (!txq->tso_hdrs) { if (!txq->tso_hdrs) {
kfree(txq->tx_skb); kfree(txq->buf);
dma_free_coherent(pp->dev->dev.parent, dma_free_coherent(pp->dev->dev.parent,
txq->size * MVNETA_DESC_ALIGNED_SIZE, txq->size * MVNETA_DESC_ALIGNED_SIZE,
txq->descs, txq->descs_phys); txq->descs, txq->descs_phys);
...@@ -3195,7 +3215,7 @@ static void mvneta_txq_sw_deinit(struct mvneta_port *pp, ...@@ -3195,7 +3215,7 @@ static void mvneta_txq_sw_deinit(struct mvneta_port *pp,
{ {
struct netdev_queue *nq = netdev_get_tx_queue(pp->dev, txq->id); struct netdev_queue *nq = netdev_get_tx_queue(pp->dev, txq->id);
kfree(txq->tx_skb); kfree(txq->buf);
if (txq->tso_hdrs) if (txq->tso_hdrs)
dma_free_coherent(pp->dev->dev.parent, dma_free_coherent(pp->dev->dev.parent,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment