008-net-mvneta-make-tx-buffer-array-agnostic.patch 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. From 9e58c8b410650b5a6eb5b8fad8474bd8425a4023 Mon Sep 17 00:00:00 2001
  2. From: Lorenzo Bianconi <[email protected]>
  3. Date: Sat, 19 Oct 2019 10:13:26 +0200
  4. Subject: [PATCH 6/7] net: mvneta: make tx buffer array agnostic
  5. Allow tx buffer array to contain both skb and xdp buffers in order to
  6. enable xdp frame recycling adding XDP_TX verdict support
  7. Signed-off-by: Lorenzo Bianconi <[email protected]>
  8. Signed-off-by: David S. Miller <[email protected]>
  9. ---
  10. drivers/net/ethernet/marvell/mvneta.c | 66 +++++++++++++++++----------
  11. 1 file changed, 43 insertions(+), 23 deletions(-)
  12. --- a/drivers/net/ethernet/marvell/mvneta.c
  13. +++ b/drivers/net/ethernet/marvell/mvneta.c
  14. @@ -565,6 +565,20 @@ struct mvneta_rx_desc {
  15. };
  16. #endif
  17. +enum mvneta_tx_buf_type {
  18. + MVNETA_TYPE_SKB,
  19. + MVNETA_TYPE_XDP_TX,
  20. + MVNETA_TYPE_XDP_NDO,
  21. +};
  22. +
  23. +struct mvneta_tx_buf {
  24. + enum mvneta_tx_buf_type type;
  25. + union {
  26. + struct xdp_frame *xdpf;
  27. + struct sk_buff *skb;
  28. + };
  29. +};
  30. +
  31. struct mvneta_tx_queue {
  32. /* Number of this TX queue, in the range 0-7 */
  33. u8 id;
  34. @@ -580,8 +594,8 @@ struct mvneta_tx_queue {
  35. int tx_stop_threshold;
  36. int tx_wake_threshold;
  37. - /* Array of transmitted skb */
  38. - struct sk_buff **tx_skb;
  39. + /* Array of transmitted buffers */
  40. + struct mvneta_tx_buf *buf;
  41. /* Index of last TX DMA descriptor that was inserted */
  42. int txq_put_index;
  43. @@ -1793,14 +1807,9 @@ static void mvneta_txq_bufs_free(struct
  44. int i;
  45. for (i = 0; i < num; i++) {
  46. + struct mvneta_tx_buf *buf = &txq->buf[txq->txq_get_index];
  47. struct mvneta_tx_desc *tx_desc = txq->descs +
  48. txq->txq_get_index;
  49. - struct sk_buff *skb = txq->tx_skb[txq->txq_get_index];
  50. -
  51. - if (skb) {
  52. - bytes_compl += skb->len;
  53. - pkts_compl++;
  54. - }
  55. mvneta_txq_inc_get(txq);
  56. @@ -1808,9 +1817,12 @@ static void mvneta_txq_bufs_free(struct
  57. dma_unmap_single(pp->dev->dev.parent,
  58. tx_desc->buf_phys_addr,
  59. tx_desc->data_size, DMA_TO_DEVICE);
  60. - if (!skb)
  61. + if (!buf->skb)
  62. continue;
  63. - dev_kfree_skb_any(skb);
  64. +
  65. + bytes_compl += buf->skb->len;
  66. + pkts_compl++;
  67. + dev_kfree_skb_any(buf->skb);
  68. }
  69. netdev_tx_completed_queue(nq, pkts_compl, bytes_compl);
  70. @@ -2335,16 +2347,19 @@ static inline void
  71. mvneta_tso_put_hdr(struct sk_buff *skb,
  72. struct mvneta_port *pp, struct mvneta_tx_queue *txq)
  73. {
  74. - struct mvneta_tx_desc *tx_desc;
  75. int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  76. + struct mvneta_tx_buf *buf = &txq->buf[txq->txq_put_index];
  77. + struct mvneta_tx_desc *tx_desc;
  78. - txq->tx_skb[txq->txq_put_index] = NULL;
  79. tx_desc = mvneta_txq_next_desc_get(txq);
  80. tx_desc->data_size = hdr_len;
  81. tx_desc->command = mvneta_skb_tx_csum(pp, skb);
  82. tx_desc->command |= MVNETA_TXD_F_DESC;
  83. tx_desc->buf_phys_addr = txq->tso_hdrs_phys +
  84. txq->txq_put_index * TSO_HEADER_SIZE;
  85. + buf->type = MVNETA_TYPE_SKB;
  86. + buf->skb = NULL;
  87. +
  88. mvneta_txq_inc_put(txq);
  89. }
  90. @@ -2353,6 +2368,7 @@ mvneta_tso_put_data(struct net_device *d
  91. struct sk_buff *skb, char *data, int size,
  92. bool last_tcp, bool is_last)
  93. {
  94. + struct mvneta_tx_buf *buf = &txq->buf[txq->txq_put_index];
  95. struct mvneta_tx_desc *tx_desc;
  96. tx_desc = mvneta_txq_next_desc_get(txq);
  97. @@ -2366,7 +2382,8 @@ mvneta_tso_put_data(struct net_device *d
  98. }
  99. tx_desc->command = 0;
  100. - txq->tx_skb[txq->txq_put_index] = NULL;
  101. + buf->type = MVNETA_TYPE_SKB;
  102. + buf->skb = NULL;
  103. if (last_tcp) {
  104. /* last descriptor in the TCP packet */
  105. @@ -2374,7 +2391,7 @@ mvneta_tso_put_data(struct net_device *d
  106. /* last descriptor in SKB */
  107. if (is_last)
  108. - txq->tx_skb[txq->txq_put_index] = skb;
  109. + buf->skb = skb;
  110. }
  111. mvneta_txq_inc_put(txq);
  112. return 0;
  113. @@ -2459,6 +2476,7 @@ static int mvneta_tx_frag_process(struct
  114. int i, nr_frags = skb_shinfo(skb)->nr_frags;
  115. for (i = 0; i < nr_frags; i++) {
  116. + struct mvneta_tx_buf *buf = &txq->buf[txq->txq_put_index];
  117. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  118. void *addr = skb_frag_address(frag);
  119. @@ -2478,12 +2496,13 @@ static int mvneta_tx_frag_process(struct
  120. if (i == nr_frags - 1) {
  121. /* Last descriptor */
  122. tx_desc->command = MVNETA_TXD_L_DESC | MVNETA_TXD_Z_PAD;
  123. - txq->tx_skb[txq->txq_put_index] = skb;
  124. + buf->skb = skb;
  125. } else {
  126. /* Descriptor in the middle: Not First, Not Last */
  127. tx_desc->command = 0;
  128. - txq->tx_skb[txq->txq_put_index] = NULL;
  129. + buf->skb = NULL;
  130. }
  131. + buf->type = MVNETA_TYPE_SKB;
  132. mvneta_txq_inc_put(txq);
  133. }
  134. @@ -2511,6 +2530,7 @@ static netdev_tx_t mvneta_tx(struct sk_b
  135. struct mvneta_port *pp = netdev_priv(dev);
  136. u16 txq_id = skb_get_queue_mapping(skb);
  137. struct mvneta_tx_queue *txq = &pp->txqs[txq_id];
  138. + struct mvneta_tx_buf *buf = &txq->buf[txq->txq_put_index];
  139. struct mvneta_tx_desc *tx_desc;
  140. int len = skb->len;
  141. int frags = 0;
  142. @@ -2543,16 +2563,17 @@ static netdev_tx_t mvneta_tx(struct sk_b
  143. goto out;
  144. }
  145. + buf->type = MVNETA_TYPE_SKB;
  146. if (frags == 1) {
  147. /* First and Last descriptor */
  148. tx_cmd |= MVNETA_TXD_FLZ_DESC;
  149. tx_desc->command = tx_cmd;
  150. - txq->tx_skb[txq->txq_put_index] = skb;
  151. + buf->skb = skb;
  152. mvneta_txq_inc_put(txq);
  153. } else {
  154. /* First but not Last */
  155. tx_cmd |= MVNETA_TXD_F_DESC;
  156. - txq->tx_skb[txq->txq_put_index] = NULL;
  157. + buf->skb = NULL;
  158. mvneta_txq_inc_put(txq);
  159. tx_desc->command = tx_cmd;
  160. /* Continue with other skb fragments */
  161. @@ -3138,9 +3159,8 @@ static int mvneta_txq_sw_init(struct mvn
  162. txq->last_desc = txq->size - 1;
  163. - txq->tx_skb = kmalloc_array(txq->size, sizeof(*txq->tx_skb),
  164. - GFP_KERNEL);
  165. - if (!txq->tx_skb) {
  166. + txq->buf = kmalloc_array(txq->size, sizeof(*txq->buf), GFP_KERNEL);
  167. + if (!txq->buf) {
  168. dma_free_coherent(pp->dev->dev.parent,
  169. txq->size * MVNETA_DESC_ALIGNED_SIZE,
  170. txq->descs, txq->descs_phys);
  171. @@ -3152,7 +3172,7 @@ static int mvneta_txq_sw_init(struct mvn
  172. txq->size * TSO_HEADER_SIZE,
  173. &txq->tso_hdrs_phys, GFP_KERNEL);
  174. if (!txq->tso_hdrs) {
  175. - kfree(txq->tx_skb);
  176. + kfree(txq->buf);
  177. dma_free_coherent(pp->dev->dev.parent,
  178. txq->size * MVNETA_DESC_ALIGNED_SIZE,
  179. txq->descs, txq->descs_phys);
  180. @@ -3207,7 +3227,7 @@ static void mvneta_txq_sw_deinit(struct
  181. {
  182. struct netdev_queue *nq = netdev_get_tx_queue(pp->dev, txq->id);
  183. - kfree(txq->tx_skb);
  184. + kfree(txq->buf);
  185. if (txq->tso_hdrs)
  186. dma_free_coherent(pp->dev->dev.parent,