Skip to content

Commit 3e1308a

Browse files
committed
Merge branch '100GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue
Tony Nguyen says: ==================== ice: xsk: ZC changes Maciej Fijalkowski says: This set consists of two fixes to issues that were either pointed out on indirectly (John was reviewing AF_XDP selftests that were testing ice's ZC support) mailing list or were directly reported by customers. First patch allows user space to see done descriptor in CQ even after a single frame being transmitted and second patch removes the need for having HW rings sized to power of 2 number of descriptors when used against AF_XDP. I also forgot to mention that due to the current Tx cleaning algorithm, 4k HW ring was broken and these two patches bring it back to life, so we kill two birds with one stone. * '100GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue: ice: xsk: drop power of 2 ring size restriction for AF_XDP ice: xsk: change batched Tx descriptor cleaning ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents c9da02b + b3056ae commit 3e1308a

File tree

3 files changed

+71
-101
lines changed

3 files changed

+71
-101
lines changed

drivers/net/ethernet/intel/ice/ice_txrx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ int ice_napi_poll(struct napi_struct *napi, int budget)
14671467
bool wd;
14681468

14691469
if (tx_ring->xsk_pool)
1470-
wd = ice_xmit_zc(tx_ring, ICE_DESC_UNUSED(tx_ring), budget);
1470+
wd = ice_xmit_zc(tx_ring);
14711471
else if (ice_ring_is_xdp(tx_ring))
14721472
wd = true;
14731473
else

drivers/net/ethernet/intel/ice/ice_xsk.c

Lines changed: 68 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,6 @@ int ice_xsk_pool_setup(struct ice_vsi *vsi, struct xsk_buff_pool *pool, u16 qid)
392392
goto failure;
393393
}
394394

395-
if (!is_power_of_2(vsi->rx_rings[qid]->count) ||
396-
!is_power_of_2(vsi->tx_rings[qid]->count)) {
397-
netdev_err(vsi->netdev, "Please align ring sizes to power of 2\n");
398-
pool_failure = -EINVAL;
399-
goto failure;
400-
}
401-
402395
if_running = netif_running(vsi->netdev) && ice_is_xdp_ena_vsi(vsi);
403396

404397
if (if_running) {
@@ -534,11 +527,10 @@ static bool __ice_alloc_rx_bufs_zc(struct ice_rx_ring *rx_ring, u16 count)
534527
bool ice_alloc_rx_bufs_zc(struct ice_rx_ring *rx_ring, u16 count)
535528
{
536529
u16 rx_thresh = ICE_RING_QUARTER(rx_ring);
537-
u16 batched, leftover, i, tail_bumps;
530+
u16 leftover, i, tail_bumps;
538531

539-
batched = ALIGN_DOWN(count, rx_thresh);
540-
tail_bumps = batched / rx_thresh;
541-
leftover = count & (rx_thresh - 1);
532+
tail_bumps = count / rx_thresh;
533+
leftover = count - (tail_bumps * rx_thresh);
542534

543535
for (i = 0; i < tail_bumps; i++)
544536
if (!__ice_alloc_rx_bufs_zc(rx_ring, rx_thresh))
@@ -788,69 +780,57 @@ ice_clean_xdp_tx_buf(struct ice_tx_ring *xdp_ring, struct ice_tx_buf *tx_buf)
788780
}
789781

790782
/**
791-
* ice_clean_xdp_irq_zc - Reclaim resources after transmit completes on XDP ring
792-
* @xdp_ring: XDP ring to clean
793-
* @napi_budget: amount of descriptors that NAPI allows us to clean
794-
*
795-
* Returns count of cleaned descriptors
783+
* ice_clean_xdp_irq_zc - produce AF_XDP descriptors to CQ
784+
* @xdp_ring: XDP Tx ring
796785
*/
797-
static u16 ice_clean_xdp_irq_zc(struct ice_tx_ring *xdp_ring, int napi_budget)
786+
static void ice_clean_xdp_irq_zc(struct ice_tx_ring *xdp_ring)
798787
{
799-
u16 tx_thresh = ICE_RING_QUARTER(xdp_ring);
800-
int budget = napi_budget / tx_thresh;
801-
u16 next_dd = xdp_ring->next_dd;
802-
u16 ntc, cleared_dds = 0;
803-
804-
do {
805-
struct ice_tx_desc *next_dd_desc;
806-
u16 desc_cnt = xdp_ring->count;
807-
struct ice_tx_buf *tx_buf;
808-
u32 xsk_frames;
809-
u16 i;
810-
811-
next_dd_desc = ICE_TX_DESC(xdp_ring, next_dd);
812-
if (!(next_dd_desc->cmd_type_offset_bsz &
813-
cpu_to_le64(ICE_TX_DESC_DTYPE_DESC_DONE)))
814-
break;
788+
u16 ntc = xdp_ring->next_to_clean;
789+
struct ice_tx_desc *tx_desc;
790+
u16 cnt = xdp_ring->count;
791+
struct ice_tx_buf *tx_buf;
792+
u16 xsk_frames = 0;
793+
u16 last_rs;
794+
int i;
815795

816-
cleared_dds++;
817-
xsk_frames = 0;
818-
if (likely(!xdp_ring->xdp_tx_active)) {
819-
xsk_frames = tx_thresh;
820-
goto skip;
821-
}
796+
last_rs = xdp_ring->next_to_use ? xdp_ring->next_to_use - 1 : cnt - 1;
797+
tx_desc = ICE_TX_DESC(xdp_ring, last_rs);
798+
if ((tx_desc->cmd_type_offset_bsz &
799+
cpu_to_le64(ICE_TX_DESC_DTYPE_DESC_DONE))) {
800+
if (last_rs >= ntc)
801+
xsk_frames = last_rs - ntc + 1;
802+
else
803+
xsk_frames = last_rs + cnt - ntc + 1;
804+
}
822805

823-
ntc = xdp_ring->next_to_clean;
806+
if (!xsk_frames)
807+
return;
824808

825-
for (i = 0; i < tx_thresh; i++) {
826-
tx_buf = &xdp_ring->tx_buf[ntc];
809+
if (likely(!xdp_ring->xdp_tx_active))
810+
goto skip;
827811

828-
if (tx_buf->raw_buf) {
829-
ice_clean_xdp_tx_buf(xdp_ring, tx_buf);
830-
tx_buf->raw_buf = NULL;
831-
} else {
832-
xsk_frames++;
833-
}
812+
ntc = xdp_ring->next_to_clean;
813+
for (i = 0; i < xsk_frames; i++) {
814+
tx_buf = &xdp_ring->tx_buf[ntc];
834815

835-
ntc++;
836-
if (ntc >= xdp_ring->count)
837-
ntc = 0;
816+
if (tx_buf->raw_buf) {
817+
ice_clean_xdp_tx_buf(xdp_ring, tx_buf);
818+
tx_buf->raw_buf = NULL;
819+
} else {
820+
xsk_frames++;
838821
}
822+
823+
ntc++;
824+
if (ntc >= xdp_ring->count)
825+
ntc = 0;
826+
}
839827
skip:
840-
xdp_ring->next_to_clean += tx_thresh;
841-
if (xdp_ring->next_to_clean >= desc_cnt)
842-
xdp_ring->next_to_clean -= desc_cnt;
843-
if (xsk_frames)
844-
xsk_tx_completed(xdp_ring->xsk_pool, xsk_frames);
845-
next_dd_desc->cmd_type_offset_bsz = 0;
846-
next_dd = next_dd + tx_thresh;
847-
if (next_dd >= desc_cnt)
848-
next_dd = tx_thresh - 1;
849-
} while (--budget);
850-
851-
xdp_ring->next_dd = next_dd;
852-
853-
return cleared_dds * tx_thresh;
828+
tx_desc->cmd_type_offset_bsz = 0;
829+
xdp_ring->next_to_clean += xsk_frames;
830+
if (xdp_ring->next_to_clean >= cnt)
831+
xdp_ring->next_to_clean -= cnt;
832+
if (xsk_frames)
833+
xsk_tx_completed(xdp_ring->xsk_pool, xsk_frames);
854834
}
855835

856836
/**
@@ -885,7 +865,6 @@ static void ice_xmit_pkt(struct ice_tx_ring *xdp_ring, struct xdp_desc *desc,
885865
static void ice_xmit_pkt_batch(struct ice_tx_ring *xdp_ring, struct xdp_desc *descs,
886866
unsigned int *total_bytes)
887867
{
888-
u16 tx_thresh = ICE_RING_QUARTER(xdp_ring);
889868
u16 ntu = xdp_ring->next_to_use;
890869
struct ice_tx_desc *tx_desc;
891870
u32 i;
@@ -905,13 +884,6 @@ static void ice_xmit_pkt_batch(struct ice_tx_ring *xdp_ring, struct xdp_desc *de
905884
}
906885

907886
xdp_ring->next_to_use = ntu;
908-
909-
if (xdp_ring->next_to_use > xdp_ring->next_rs) {
910-
tx_desc = ICE_TX_DESC(xdp_ring, xdp_ring->next_rs);
911-
tx_desc->cmd_type_offset_bsz |=
912-
cpu_to_le64(ICE_TX_DESC_CMD_RS << ICE_TXD_QW1_CMD_S);
913-
xdp_ring->next_rs += tx_thresh;
914-
}
915887
}
916888

917889
/**
@@ -924,7 +896,6 @@ static void ice_xmit_pkt_batch(struct ice_tx_ring *xdp_ring, struct xdp_desc *de
924896
static void ice_fill_tx_hw_ring(struct ice_tx_ring *xdp_ring, struct xdp_desc *descs,
925897
u32 nb_pkts, unsigned int *total_bytes)
926898
{
927-
u16 tx_thresh = ICE_RING_QUARTER(xdp_ring);
928899
u32 batched, leftover, i;
929900

930901
batched = ALIGN_DOWN(nb_pkts, PKTS_PER_BATCH);
@@ -933,54 +904,54 @@ static void ice_fill_tx_hw_ring(struct ice_tx_ring *xdp_ring, struct xdp_desc *d
933904
ice_xmit_pkt_batch(xdp_ring, &descs[i], total_bytes);
934905
for (; i < batched + leftover; i++)
935906
ice_xmit_pkt(xdp_ring, &descs[i], total_bytes);
907+
}
936908

937-
if (xdp_ring->next_to_use > xdp_ring->next_rs) {
938-
struct ice_tx_desc *tx_desc;
909+
/**
910+
* ice_set_rs_bit - set RS bit on last produced descriptor (one behind current NTU)
911+
* @xdp_ring: XDP ring to produce the HW Tx descriptors on
912+
*/
913+
static void ice_set_rs_bit(struct ice_tx_ring *xdp_ring)
914+
{
915+
u16 ntu = xdp_ring->next_to_use ? xdp_ring->next_to_use - 1 : xdp_ring->count - 1;
916+
struct ice_tx_desc *tx_desc;
939917

940-
tx_desc = ICE_TX_DESC(xdp_ring, xdp_ring->next_rs);
941-
tx_desc->cmd_type_offset_bsz |=
942-
cpu_to_le64(ICE_TX_DESC_CMD_RS << ICE_TXD_QW1_CMD_S);
943-
xdp_ring->next_rs += tx_thresh;
944-
}
918+
tx_desc = ICE_TX_DESC(xdp_ring, ntu);
919+
tx_desc->cmd_type_offset_bsz |=
920+
cpu_to_le64(ICE_TX_DESC_CMD_RS << ICE_TXD_QW1_CMD_S);
945921
}
946922

947923
/**
948924
* ice_xmit_zc - take entries from XSK Tx ring and place them onto HW Tx ring
949925
* @xdp_ring: XDP ring to produce the HW Tx descriptors on
950-
* @budget: number of free descriptors on HW Tx ring that can be used
951-
* @napi_budget: amount of descriptors that NAPI allows us to clean
952926
*
953927
* Returns true if there is no more work that needs to be done, false otherwise
954928
*/
955-
bool ice_xmit_zc(struct ice_tx_ring *xdp_ring, u32 budget, int napi_budget)
929+
bool ice_xmit_zc(struct ice_tx_ring *xdp_ring)
956930
{
957931
struct xdp_desc *descs = xdp_ring->xsk_pool->tx_descs;
958-
u16 tx_thresh = ICE_RING_QUARTER(xdp_ring);
959932
u32 nb_pkts, nb_processed = 0;
960933
unsigned int total_bytes = 0;
934+
int budget;
935+
936+
ice_clean_xdp_irq_zc(xdp_ring);
961937

962-
if (budget < tx_thresh)
963-
budget += ice_clean_xdp_irq_zc(xdp_ring, napi_budget);
938+
budget = ICE_DESC_UNUSED(xdp_ring);
939+
budget = min_t(u16, budget, ICE_RING_QUARTER(xdp_ring));
964940

965941
nb_pkts = xsk_tx_peek_release_desc_batch(xdp_ring->xsk_pool, budget);
966942
if (!nb_pkts)
967943
return true;
968944

969945
if (xdp_ring->next_to_use + nb_pkts >= xdp_ring->count) {
970-
struct ice_tx_desc *tx_desc;
971-
972946
nb_processed = xdp_ring->count - xdp_ring->next_to_use;
973947
ice_fill_tx_hw_ring(xdp_ring, descs, nb_processed, &total_bytes);
974-
tx_desc = ICE_TX_DESC(xdp_ring, xdp_ring->next_rs);
975-
tx_desc->cmd_type_offset_bsz |=
976-
cpu_to_le64(ICE_TX_DESC_CMD_RS << ICE_TXD_QW1_CMD_S);
977-
xdp_ring->next_rs = tx_thresh - 1;
978948
xdp_ring->next_to_use = 0;
979949
}
980950

981951
ice_fill_tx_hw_ring(xdp_ring, &descs[nb_processed], nb_pkts - nb_processed,
982952
&total_bytes);
983953

954+
ice_set_rs_bit(xdp_ring);
984955
ice_xdp_ring_update_tail(xdp_ring);
985956
ice_update_tx_ring_stats(xdp_ring, nb_pkts, total_bytes);
986957

@@ -1058,14 +1029,16 @@ bool ice_xsk_any_rx_ring_ena(struct ice_vsi *vsi)
10581029
*/
10591030
void ice_xsk_clean_rx_ring(struct ice_rx_ring *rx_ring)
10601031
{
1061-
u16 count_mask = rx_ring->count - 1;
10621032
u16 ntc = rx_ring->next_to_clean;
10631033
u16 ntu = rx_ring->next_to_use;
10641034

1065-
for ( ; ntc != ntu; ntc = (ntc + 1) & count_mask) {
1035+
while (ntc != ntu) {
10661036
struct xdp_buff *xdp = *ice_xdp_buf(rx_ring, ntc);
10671037

10681038
xsk_buff_free(xdp);
1039+
ntc++;
1040+
if (ntc >= rx_ring->count)
1041+
ntc = 0;
10691042
}
10701043
}
10711044

drivers/net/ethernet/intel/ice/ice_xsk.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@ bool ice_alloc_rx_bufs_zc(struct ice_rx_ring *rx_ring, u16 count);
2626
bool ice_xsk_any_rx_ring_ena(struct ice_vsi *vsi);
2727
void ice_xsk_clean_rx_ring(struct ice_rx_ring *rx_ring);
2828
void ice_xsk_clean_xdp_ring(struct ice_tx_ring *xdp_ring);
29-
bool ice_xmit_zc(struct ice_tx_ring *xdp_ring, u32 budget, int napi_budget);
29+
bool ice_xmit_zc(struct ice_tx_ring *xdp_ring);
3030
int ice_realloc_zc_buf(struct ice_vsi *vsi, bool zc);
3131
#else
32-
static inline bool
33-
ice_xmit_zc(struct ice_tx_ring __always_unused *xdp_ring,
34-
u32 __always_unused budget,
35-
int __always_unused napi_budget)
32+
static inline bool ice_xmit_zc(struct ice_tx_ring __always_unused *xdp_ring)
3633
{
3734
return false;
3835
}

0 commit comments

Comments
 (0)