Skip to content

Commit 1347b41

Browse files
yoongsiang2Alexei Starovoitov
authored andcommitted
net: stmmac: Add Tx HWTS support to XDP ZC
This patch enables transmit hardware timestamp support to XDP zero copy via XDP Tx metadata framework. This patchset is tested with tools/testing/selftests/bpf/xdp_hw_metadata on Intel Tiger Lake platform. Below are the test steps and results. Command on DUT: sudo ./xdp_hw_metadata <interface name> sudo hwstamp_ctl -i <interface name> -t 1 -r 1 Command on Link Partner: echo -n xdp | nc -u -q1 <destination IPv4 addr> 9091 Result: xsk_ring_cons__peek: 1 0x55bbbf08b6d0: rx_desc[2]->addr=8c100 addr=8c100 comp_addr=8c100 EoP No rx_hash err=-95 rx_timestamp: 1677762688429141540 (sec:1677762688.4291) HW RX-time: 1677762688429141540 (sec:1677762688.4291) delta to User RX-time sec:0.0003 (250.665 usec) XDP RX-time: 1677762688429375597 (sec:1677762688.4294) delta to User RX-time sec:0.0000 (16.608 usec) 0x55bbbf08b6d0: ping-pong with csum=561c (want f488) csum_start=34 csum_offset=6 0x55bbbf08b6d0: complete tx idx=2 addr=2008 tx_timestamp: 1677762688431127273 (sec:1677762688.4311) HW TX-complete-time: 1677762688431127273 (sec:1677762688.4311) delta to User TX-complete-time sec:0.0083 (8331.655 usec) XDP RX-time: 1677762688429375597 (sec:1677762688.4294) delta to User TX-complete-time sec:0.0101 (10083.331 usec) HW RX-time: 1677762688429141540 (sec:1677762688.4291) delta to HW TX-complete-time sec:0.0020 (1985.733 usec) 0x55bbbf08b6d0: complete rx idx=130 addr=8c100 Signed-off-by: Song Yoong Siang <[email protected]> Signed-off-by: Stanislav Fomichev <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent ec706a8 commit 1347b41

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct stmmac_tx_info {
5151
bool last_segment;
5252
bool is_jumbo;
5353
enum stmmac_txbuf_type buf_type;
54+
struct xsk_tx_metadata_compl xsk_meta;
5455
};
5556

5657
#define STMMAC_TBS_AVAIL BIT(0)
@@ -100,6 +101,17 @@ struct stmmac_xdp_buff {
100101
struct dma_desc *ndesc;
101102
};
102103

104+
struct stmmac_metadata_request {
105+
struct stmmac_priv *priv;
106+
struct dma_desc *tx_desc;
107+
bool *set_ic;
108+
};
109+
110+
struct stmmac_xsk_tx_complete {
111+
struct stmmac_priv *priv;
112+
struct dma_desc *desc;
113+
};
114+
103115
struct stmmac_rx_queue {
104116
u32 rx_count_frames;
105117
u32 queue_index;

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

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2430,6 +2430,46 @@ static void stmmac_dma_operation_mode(struct stmmac_priv *priv)
24302430
}
24312431
}
24322432

2433+
static void stmmac_xsk_request_timestamp(void *_priv)
2434+
{
2435+
struct stmmac_metadata_request *meta_req = _priv;
2436+
2437+
stmmac_enable_tx_timestamp(meta_req->priv, meta_req->tx_desc);
2438+
*meta_req->set_ic = true;
2439+
}
2440+
2441+
static u64 stmmac_xsk_fill_timestamp(void *_priv)
2442+
{
2443+
struct stmmac_xsk_tx_complete *tx_compl = _priv;
2444+
struct stmmac_priv *priv = tx_compl->priv;
2445+
struct dma_desc *desc = tx_compl->desc;
2446+
bool found = false;
2447+
u64 ns = 0;
2448+
2449+
if (!priv->hwts_tx_en)
2450+
return 0;
2451+
2452+
/* check tx tstamp status */
2453+
if (stmmac_get_tx_timestamp_status(priv, desc)) {
2454+
stmmac_get_timestamp(priv, desc, priv->adv_ts, &ns);
2455+
found = true;
2456+
} else if (!stmmac_get_mac_tx_timestamp(priv, priv->hw, &ns)) {
2457+
found = true;
2458+
}
2459+
2460+
if (found) {
2461+
ns -= priv->plat->cdc_error_adj;
2462+
return ns_to_ktime(ns);
2463+
}
2464+
2465+
return 0;
2466+
}
2467+
2468+
static const struct xsk_tx_metadata_ops stmmac_xsk_tx_metadata_ops = {
2469+
.tmo_request_timestamp = stmmac_xsk_request_timestamp,
2470+
.tmo_fill_timestamp = stmmac_xsk_fill_timestamp,
2471+
};
2472+
24332473
static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
24342474
{
24352475
struct netdev_queue *nq = netdev_get_tx_queue(priv->dev, queue);
@@ -2449,6 +2489,8 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
24492489
budget = min(budget, stmmac_tx_avail(priv, queue));
24502490

24512491
while (budget-- > 0) {
2492+
struct stmmac_metadata_request meta_req;
2493+
struct xsk_tx_metadata *meta = NULL;
24522494
dma_addr_t dma_addr;
24532495
bool set_ic;
24542496

@@ -2472,6 +2514,7 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
24722514
tx_desc = tx_q->dma_tx + entry;
24732515

24742516
dma_addr = xsk_buff_raw_get_dma(pool, xdp_desc.addr);
2517+
meta = xsk_buff_get_metadata(pool, xdp_desc.addr);
24752518
xsk_buff_raw_dma_sync_for_device(pool, dma_addr, xdp_desc.len);
24762519

24772520
tx_q->tx_skbuff_dma[entry].buf_type = STMMAC_TXBUF_T_XSK_TX;
@@ -2499,6 +2542,11 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
24992542
else
25002543
set_ic = false;
25012544

2545+
meta_req.priv = priv;
2546+
meta_req.tx_desc = tx_desc;
2547+
meta_req.set_ic = &set_ic;
2548+
xsk_tx_metadata_request(meta, &stmmac_xsk_tx_metadata_ops,
2549+
&meta_req);
25022550
if (set_ic) {
25032551
tx_q->tx_count_frames = 0;
25042552
stmmac_set_tx_ic(priv, tx_desc);
@@ -2511,6 +2559,9 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
25112559

25122560
stmmac_enable_dma_transmission(priv, priv->ioaddr);
25132561

2562+
xsk_tx_metadata_to_compl(meta,
2563+
&tx_q->tx_skbuff_dma[entry].xsk_meta);
2564+
25142565
tx_q->cur_tx = STMMAC_GET_ENTRY(tx_q->cur_tx, priv->dma_conf.dma_tx_size);
25152566
entry = tx_q->cur_tx;
25162567
}
@@ -2620,8 +2671,18 @@ static int stmmac_tx_clean(struct stmmac_priv *priv, int budget, u32 queue,
26202671
} else {
26212672
tx_packets++;
26222673
}
2623-
if (skb)
2674+
if (skb) {
26242675
stmmac_get_tx_hwtstamp(priv, p, skb);
2676+
} else {
2677+
struct stmmac_xsk_tx_complete tx_compl = {
2678+
.priv = priv,
2679+
.desc = p,
2680+
};
2681+
2682+
xsk_tx_metadata_complete(&tx_q->tx_skbuff_dma[entry].xsk_meta,
2683+
&stmmac_xsk_tx_metadata_ops,
2684+
&tx_compl);
2685+
}
26252686
}
26262687

26272688
if (likely(tx_q->tx_skbuff_dma[entry].buf &&
@@ -7464,6 +7525,7 @@ int stmmac_dvr_probe(struct device *device,
74647525
ndev->netdev_ops = &stmmac_netdev_ops;
74657526

74667527
ndev->xdp_metadata_ops = &stmmac_xdp_metadata_ops;
7528+
ndev->xsk_tx_metadata_ops = &stmmac_xsk_tx_metadata_ops;
74677529

74687530
ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
74697531
NETIF_F_RXCSUM;

0 commit comments

Comments
 (0)