Skip to content

Commit c03a6fd

Browse files
chintanv133Paolo Abeni
authored andcommitted
net: ethernet: ti: am65-cpsw/ethtool: Enable RX HW timestamp only for PTP packets
In the current mechanism of timestamping, am65-cpsw-nuss driver enables hardware timestamping for all received packets by setting the TSTAMP_EN bit in CPTS_CONTROL register, which directs the CPTS module to timestamp all received packets, followed by passing timestamp via DMA descriptors. This mechanism causes CPSW Port to Lock up. To prevent port lock up, don't enable rx packet timestamping by setting TSTAMP_EN bit in CPTS_CONTROL register. The workaround for timestamping received packets is to utilize the CPTS Event FIFO that records timestamps corresponding to certain events. The CPTS module is configured to generate timestamps for Multicast Ethernet, UDP/IPv4 and UDP/IPv6 PTP packets. Update supported hwtstamp_rx_filters values for CPSW's timestamping capability. Fixes: b1f66a5 ("net: ethernet: ti: am65-cpsw-nuss: enable packet timestamping support") Signed-off-by: Chintan Vankar <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent c459f60 commit c03a6fd

File tree

4 files changed

+35
-57
lines changed

4 files changed

+35
-57
lines changed

drivers/net/ethernet/ti/am65-cpsw-ethtool.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,17 @@ static int am65_cpsw_get_ethtool_ts_info(struct net_device *ndev,
695695
struct ethtool_ts_info *info)
696696
{
697697
struct am65_cpsw_common *common = am65_ndev_to_common(ndev);
698+
unsigned int ptp_v2_filter;
699+
700+
ptp_v2_filter = BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
701+
BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
702+
BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
703+
BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
704+
BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
705+
BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
706+
BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
707+
BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
708+
BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ);
698709

699710
if (!IS_ENABLED(CONFIG_TI_K3_AM65_CPTS))
700711
return ethtool_op_get_ts_info(ndev, info);
@@ -708,7 +719,7 @@ static int am65_cpsw_get_ethtool_ts_info(struct net_device *ndev,
708719
SOF_TIMESTAMPING_RAW_HARDWARE;
709720
info->phc_index = am65_cpts_phc_index(common->cpts);
710721
info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
711-
info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | BIT(HWTSTAMP_FILTER_ALL);
722+
info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | ptp_v2_filter;
712723
return 0;
713724
}
714725

drivers/net/ethernet/ti/am65-cpsw-nuss.c

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@
103103
#define AM65_CPSW_PN_TS_CTL_TX_HOST_TS_EN BIT(11)
104104
#define AM65_CPSW_PN_TS_CTL_MSG_TYPE_EN_SHIFT 16
105105

106+
#define AM65_CPSW_PN_TS_CTL_RX_ANX_F_EN BIT(0)
107+
#define AM65_CPSW_PN_TS_CTL_RX_VLAN_LT1_EN BIT(1)
108+
#define AM65_CPSW_PN_TS_CTL_RX_VLAN_LT2_EN BIT(2)
109+
#define AM65_CPSW_PN_TS_CTL_RX_ANX_D_EN BIT(3)
110+
#define AM65_CPSW_PN_TS_CTL_RX_ANX_E_EN BIT(9)
111+
106112
/* AM65_CPSW_PORTN_REG_TS_SEQ_LTYPE_REG register fields */
107113
#define AM65_CPSW_PN_TS_SEQ_ID_OFFSET_SHIFT 16
108114

@@ -126,6 +132,11 @@
126132
AM65_CPSW_PN_TS_CTL_TX_ANX_E_EN | \
127133
AM65_CPSW_PN_TS_CTL_TX_ANX_F_EN)
128134

135+
#define AM65_CPSW_TS_RX_ANX_ALL_EN \
136+
(AM65_CPSW_PN_TS_CTL_RX_ANX_D_EN | \
137+
AM65_CPSW_PN_TS_CTL_RX_ANX_E_EN | \
138+
AM65_CPSW_PN_TS_CTL_RX_ANX_F_EN)
139+
129140
#define AM65_CPSW_ALE_AGEOUT_DEFAULT 30
130141
/* Number of TX/RX descriptors */
131142
#define AM65_CPSW_MAX_TX_DESC 500
@@ -1050,18 +1061,6 @@ static int am65_cpsw_run_xdp(struct am65_cpsw_common *common,
10501061
return ret;
10511062
}
10521063

1053-
static void am65_cpsw_nuss_rx_ts(struct sk_buff *skb, u32 *psdata)
1054-
{
1055-
struct skb_shared_hwtstamps *ssh;
1056-
u64 ns;
1057-
1058-
ns = ((u64)psdata[1] << 32) | psdata[0];
1059-
1060-
ssh = skb_hwtstamps(skb);
1061-
memset(ssh, 0, sizeof(*ssh));
1062-
ssh->hwtstamp = ns_to_ktime(ns);
1063-
}
1064-
10651064
/* RX psdata[2] word format - checksum information */
10661065
#define AM65_CPSW_RX_PSD_CSUM_ADD GENMASK(15, 0)
10671066
#define AM65_CPSW_RX_PSD_CSUM_ERR BIT(16)
@@ -1177,13 +1176,11 @@ static int am65_cpsw_nuss_rx_packets(struct am65_cpsw_common *common,
11771176
skb_reserve(skb, headroom);
11781177
}
11791178

1180-
/* Pass skb to netstack if no XDP prog or returned XDP_PASS */
1181-
if (port->rx_ts_enabled)
1182-
am65_cpsw_nuss_rx_ts(skb, psdata);
1183-
11841179
ndev_priv = netdev_priv(ndev);
11851180
am65_cpsw_nuss_set_offload_fwd_mark(skb, ndev_priv->offload_fwd_mark);
11861181
skb_put(skb, pkt_len);
1182+
if (port->rx_ts_enabled)
1183+
am65_cpts_rx_timestamp(common->cpts, skb);
11871184
skb_mark_for_recycle(skb);
11881185
skb->protocol = eth_type_trans(skb, ndev);
11891186
am65_cpsw_nuss_rx_csum(skb, csum_info);
@@ -1736,7 +1733,6 @@ static int am65_cpsw_nuss_ndo_slave_set_mac_address(struct net_device *ndev,
17361733
static int am65_cpsw_nuss_hwtstamp_set(struct net_device *ndev,
17371734
struct ifreq *ifr)
17381735
{
1739-
struct am65_cpsw_common *common = am65_ndev_to_common(ndev);
17401736
struct am65_cpsw_port *port = am65_ndev_to_port(ndev);
17411737
u32 ts_ctrl, seq_id, ts_ctrl_ltype2, ts_vlan_ltype;
17421738
struct hwtstamp_config cfg;
@@ -1760,11 +1756,6 @@ static int am65_cpsw_nuss_hwtstamp_set(struct net_device *ndev,
17601756
case HWTSTAMP_FILTER_NONE:
17611757
port->rx_ts_enabled = false;
17621758
break;
1763-
case HWTSTAMP_FILTER_ALL:
1764-
case HWTSTAMP_FILTER_SOME:
1765-
case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
1766-
case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
1767-
case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
17681759
case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
17691760
case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
17701761
case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
@@ -1774,10 +1765,13 @@ static int am65_cpsw_nuss_hwtstamp_set(struct net_device *ndev,
17741765
case HWTSTAMP_FILTER_PTP_V2_EVENT:
17751766
case HWTSTAMP_FILTER_PTP_V2_SYNC:
17761767
case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
1777-
case HWTSTAMP_FILTER_NTP_ALL:
17781768
port->rx_ts_enabled = true;
1779-
cfg.rx_filter = HWTSTAMP_FILTER_ALL;
1769+
cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
17801770
break;
1771+
case HWTSTAMP_FILTER_ALL:
1772+
case HWTSTAMP_FILTER_SOME:
1773+
case HWTSTAMP_FILTER_NTP_ALL:
1774+
return -EOPNOTSUPP;
17811775
default:
17821776
return -ERANGE;
17831777
}
@@ -1807,16 +1801,17 @@ static int am65_cpsw_nuss_hwtstamp_set(struct net_device *ndev,
18071801
ts_ctrl |= AM65_CPSW_TS_TX_ANX_ALL_EN |
18081802
AM65_CPSW_PN_TS_CTL_TX_VLAN_LT1_EN;
18091803

1804+
if (port->rx_ts_enabled)
1805+
ts_ctrl |= AM65_CPSW_TS_RX_ANX_ALL_EN |
1806+
AM65_CPSW_PN_TS_CTL_RX_VLAN_LT1_EN;
1807+
18101808
writel(seq_id, port->port_base + AM65_CPSW_PORTN_REG_TS_SEQ_LTYPE_REG);
18111809
writel(ts_vlan_ltype, port->port_base +
18121810
AM65_CPSW_PORTN_REG_TS_VLAN_LTYPE_REG);
18131811
writel(ts_ctrl_ltype2, port->port_base +
18141812
AM65_CPSW_PORTN_REG_TS_CTL_LTYPE2);
18151813
writel(ts_ctrl, port->port_base + AM65_CPSW_PORTN_REG_TS_CTL);
18161814

1817-
/* en/dis RX timestamp */
1818-
am65_cpts_rx_enable(common->cpts, port->rx_ts_enabled);
1819-
18201815
return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
18211816
}
18221817

@@ -1833,7 +1828,7 @@ static int am65_cpsw_nuss_hwtstamp_get(struct net_device *ndev,
18331828
cfg.tx_type = port->tx_ts_enabled ?
18341829
HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
18351830
cfg.rx_filter = port->rx_ts_enabled ?
1836-
HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE;
1831+
HWTSTAMP_FILTER_PTP_V2_EVENT : HWTSTAMP_FILTER_NONE;
18371832

18381833
return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
18391834
}

drivers/net/ethernet/ti/am65-cpts.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -866,29 +866,6 @@ static long am65_cpts_ts_work(struct ptp_clock_info *ptp)
866866
return delay;
867867
}
868868

869-
/**
870-
* am65_cpts_rx_enable - enable rx timestamping
871-
* @cpts: cpts handle
872-
* @en: enable
873-
*
874-
* This functions enables rx packets timestamping. The CPTS can timestamp all
875-
* rx packets.
876-
*/
877-
void am65_cpts_rx_enable(struct am65_cpts *cpts, bool en)
878-
{
879-
u32 val;
880-
881-
mutex_lock(&cpts->ptp_clk_lock);
882-
val = am65_cpts_read32(cpts, control);
883-
if (en)
884-
val |= AM65_CPTS_CONTROL_TSTAMP_EN;
885-
else
886-
val &= ~AM65_CPTS_CONTROL_TSTAMP_EN;
887-
am65_cpts_write32(cpts, val, control);
888-
mutex_unlock(&cpts->ptp_clk_lock);
889-
}
890-
EXPORT_SYMBOL_GPL(am65_cpts_rx_enable);
891-
892869
static int am65_skb_get_mtype_seqid(struct sk_buff *skb, u32 *mtype_seqid)
893870
{
894871
unsigned int ptp_class = ptp_classify_raw(skb);

drivers/net/ethernet/ti/am65-cpts.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ int am65_cpts_phc_index(struct am65_cpts *cpts);
2525
void am65_cpts_rx_timestamp(struct am65_cpts *cpts, struct sk_buff *skb);
2626
void am65_cpts_tx_timestamp(struct am65_cpts *cpts, struct sk_buff *skb);
2727
void am65_cpts_prep_tx_timestamp(struct am65_cpts *cpts, struct sk_buff *skb);
28-
void am65_cpts_rx_enable(struct am65_cpts *cpts, bool en);
2928
u64 am65_cpts_ns_gettime(struct am65_cpts *cpts);
3029
int am65_cpts_estf_enable(struct am65_cpts *cpts, int idx,
3130
struct am65_cpts_estf_cfg *cfg);
@@ -64,10 +63,6 @@ static inline void am65_cpts_prep_tx_timestamp(struct am65_cpts *cpts,
6463
{
6564
}
6665

67-
static inline void am65_cpts_rx_enable(struct am65_cpts *cpts, bool en)
68-
{
69-
}
70-
7166
static inline s64 am65_cpts_ns_gettime(struct am65_cpts *cpts)
7267
{
7368
return 0;

0 commit comments

Comments
 (0)