|
14 | 14 | #include <linux/phy.h>
|
15 | 15 | #include <linux/udp.h>
|
16 | 16 | #include <net/pkt_cls.h>
|
| 17 | +#include <net/pkt_sched.h> |
17 | 18 | #include <net/tcp.h>
|
18 | 19 | #include <net/udp.h>
|
19 | 20 | #include <net/tc_act/tc_gact.h>
|
@@ -50,6 +51,7 @@ struct stmmac_packet_attrs {
|
50 | 51 | u8 id;
|
51 | 52 | int sarc;
|
52 | 53 | u16 queue_mapping;
|
| 54 | + u64 timestamp; |
53 | 55 | };
|
54 | 56 |
|
55 | 57 | static u8 stmmac_test_next_id;
|
@@ -208,6 +210,9 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct stmmac_priv *priv,
|
208 | 210 | skb->pkt_type = PACKET_HOST;
|
209 | 211 | skb->dev = priv->dev;
|
210 | 212 |
|
| 213 | + if (attr->timestamp) |
| 214 | + skb->tstamp = ns_to_ktime(attr->timestamp); |
| 215 | + |
211 | 216 | return skb;
|
212 | 217 | }
|
213 | 218 |
|
@@ -1723,6 +1728,68 @@ static int stmmac_test_sph(struct stmmac_priv *priv)
|
1723 | 1728 | return 0;
|
1724 | 1729 | }
|
1725 | 1730 |
|
| 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 | + |
1726 | 1793 | #define STMMAC_LOOPBACK_NONE 0
|
1727 | 1794 | #define STMMAC_LOOPBACK_MAC 1
|
1728 | 1795 | #define STMMAC_LOOPBACK_PHY 2
|
@@ -1856,6 +1923,10 @@ static const struct stmmac_test {
|
1856 | 1923 | .name = "Split Header ",
|
1857 | 1924 | .lb = STMMAC_LOOPBACK_PHY,
|
1858 | 1925 | .fn = stmmac_test_sph,
|
| 1926 | + }, { |
| 1927 | + .name = "TBS (ETF Scheduler) ", |
| 1928 | + .lb = STMMAC_LOOPBACK_PHY, |
| 1929 | + .fn = stmmac_test_tbs, |
1859 | 1930 | },
|
1860 | 1931 | };
|
1861 | 1932 |
|
|
0 commit comments