Skip to content

Commit 28c1cf7

Browse files
joabreukuba-moo
authored andcommitted
net: stmmac: selftests: Add a test for TBS feature
Add a new test for TBS feature which is used in ETF scheduler. In this test, we send a packet with a launch time specified as now + 500ms and check if the packet was transmitted on that time frame. Changes from v2: - Use the TBS bitfield - Remove debug message Signed-off-by: Jose Abreu <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 05373e3 commit 28c1cf7

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/phy.h>
1515
#include <linux/udp.h>
1616
#include <net/pkt_cls.h>
17+
#include <net/pkt_sched.h>
1718
#include <net/tcp.h>
1819
#include <net/udp.h>
1920
#include <net/tc_act/tc_gact.h>
@@ -50,6 +51,7 @@ struct stmmac_packet_attrs {
5051
u8 id;
5152
int sarc;
5253
u16 queue_mapping;
54+
u64 timestamp;
5355
};
5456

5557
static u8 stmmac_test_next_id;
@@ -208,6 +210,9 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct stmmac_priv *priv,
208210
skb->pkt_type = PACKET_HOST;
209211
skb->dev = priv->dev;
210212

213+
if (attr->timestamp)
214+
skb->tstamp = ns_to_ktime(attr->timestamp);
215+
211216
return skb;
212217
}
213218

@@ -1723,6 +1728,68 @@ static int stmmac_test_sph(struct stmmac_priv *priv)
17231728
return 0;
17241729
}
17251730

1731+
static int stmmac_test_tbs(struct stmmac_priv *priv)
1732+
{
1733+
#define STMMAC_TBS_LT_OFFSET (500 * 1000 * 1000) /* 500 ms*/
1734+
struct stmmac_packet_attrs attr = { };
1735+
struct tc_etf_qopt_offload qopt;
1736+
u64 start_time, curr_time = 0;
1737+
unsigned long flags;
1738+
int ret, i;
1739+
1740+
if (!priv->hwts_tx_en)
1741+
return -EOPNOTSUPP;
1742+
1743+
/* Find first TBS enabled Queue, if any */
1744+
for (i = 0; i < priv->plat->tx_queues_to_use; i++)
1745+
if (priv->tx_queue[i].tbs & STMMAC_TBS_AVAIL)
1746+
break;
1747+
1748+
if (i >= priv->plat->tx_queues_to_use)
1749+
return -EOPNOTSUPP;
1750+
1751+
qopt.enable = true;
1752+
qopt.queue = i;
1753+
1754+
ret = stmmac_tc_setup_etf(priv, priv, &qopt);
1755+
if (ret)
1756+
return ret;
1757+
1758+
spin_lock_irqsave(&priv->ptp_lock, flags);
1759+
stmmac_get_systime(priv, priv->ptpaddr, &curr_time);
1760+
spin_unlock_irqrestore(&priv->ptp_lock, flags);
1761+
1762+
if (!curr_time) {
1763+
ret = -EOPNOTSUPP;
1764+
goto fail_disable;
1765+
}
1766+
1767+
start_time = curr_time;
1768+
curr_time += STMMAC_TBS_LT_OFFSET;
1769+
1770+
attr.dst = priv->dev->dev_addr;
1771+
attr.timestamp = curr_time;
1772+
attr.timeout = nsecs_to_jiffies(2 * STMMAC_TBS_LT_OFFSET);
1773+
attr.queue_mapping = i;
1774+
1775+
ret = __stmmac_test_loopback(priv, &attr);
1776+
if (ret)
1777+
goto fail_disable;
1778+
1779+
/* Check if expected time has elapsed */
1780+
spin_lock_irqsave(&priv->ptp_lock, flags);
1781+
stmmac_get_systime(priv, priv->ptpaddr, &curr_time);
1782+
spin_unlock_irqrestore(&priv->ptp_lock, flags);
1783+
1784+
if ((curr_time - start_time) < STMMAC_TBS_LT_OFFSET)
1785+
ret = -EINVAL;
1786+
1787+
fail_disable:
1788+
qopt.enable = false;
1789+
stmmac_tc_setup_etf(priv, priv, &qopt);
1790+
return ret;
1791+
}
1792+
17261793
#define STMMAC_LOOPBACK_NONE 0
17271794
#define STMMAC_LOOPBACK_MAC 1
17281795
#define STMMAC_LOOPBACK_PHY 2
@@ -1856,6 +1923,10 @@ static const struct stmmac_test {
18561923
.name = "Split Header ",
18571924
.lb = STMMAC_LOOPBACK_PHY,
18581925
.fn = stmmac_test_sph,
1926+
}, {
1927+
.name = "TBS (ETF Scheduler) ",
1928+
.lb = STMMAC_LOOPBACK_PHY,
1929+
.fn = stmmac_test_tbs,
18591930
},
18601931
};
18611932

0 commit comments

Comments
 (0)