net: sparx5: Add PTP Hardware Clock support
Subsystems (5)
cover net: sparx5: Add PTP Hardware Clock support
Add support for PTP Hardware Clock (PHC) for sparx5.
Horatiu Vultur (9):
net: sparx5: Move ifh from port to local variable
dt-bindings: net: sparx5: Extend with the ptp interrupt
dts: sparx5: Enable ptp interrupt
net: sparx5: Add registers that are used by ptp functionality
net: sparx5: Add support for ptp clocks
net: sparx5: Implement SIOCSHWTSTAMP and SIOCGHWTSTAMP
net: sparx5: Update extraction/injection for timestamping
net: sparx5: Add support for ptp interrupts
net: sparx5: Implement get_ts_info
.../bindings/net/microchip,sparx5-switch.yaml | 2 + arch/arm64/boot/dts/microchip/sparx5.dtsi | 5 +- .../net/ethernet/microchip/sparx5/Makefile | 3 +- .../microchip/sparx5/sparx5_ethtool.c | 34 + .../ethernet/microchip/sparx5/sparx5_fdma.c | 2 + .../ethernet/microchip/sparx5/sparx5_main.c | 21 + .../ethernet/microchip/sparx5/sparx5_main.h | 66 +- .../microchip/sparx5/sparx5_main_regs.h | 335 ++++++++- .../ethernet/microchip/sparx5/sparx5_netdev.c | 42 +- .../ethernet/microchip/sparx5/sparx5_packet.c | 37 +- .../ethernet/microchip/sparx5/sparx5_ptp.c | 685 ++++++++++++++++++ 11 files changed, 1221 insertions(+), 11 deletions(-) create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c
Signature · 1 line
2.33.0
PATCH 1/9 net: sparx5: Move ifh from port to local variable
Currently the ifh is not changed, it is fixed for each frame for each port that is sent out. Move this on the stack because this ifh needs to be change based on the frames that are send out. This is needed for PTP frames.
--- drivers/net/ethernet/microchip/sparx5/sparx5_main.h | 2 +- drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c | 3 +-- drivers/net/ethernet/microchip/sparx5/sparx5_packet.c | 8 ++++++-- 3 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +1 -1
@@ -167,7 +167,6 @@ struct sparx5_port {enum sparx5_port_max_tags max_vlan_tags;enum sparx5_vlan_port_type vlan_type;u32 custom_etype; -u32 ifh[IFH_LEN ];bool vlan_aware;struct hrtimer inj_timer; };
@@ -288,6 +287,7 @@ void sparx5_get_stats64(struct net_device *ndev, struct rtnl_link_stats64 *statsint sparx_stats_init (struct sparx5 *sparx5);/* sparx5_netdev.c */ +void sparx5_set_port_ifh (void *ifh_hdr,u16 portno);bool sparx5_netdevice_check (const struct net_device *dev);struct net_device *sparx5_create_netdev (struct sparx5 *sparx5,u32 portno);int sparx5_register_netdevs (struct sparx5 *sparx5);
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c +1 -2
@@ -54,7 +54,7 @@ static void __ifh_encode_bitfield(void *ifh, u64 value, u32 pos, u32 width) ifh_hdr[byte -5 ] |= (u8)((encode &0xFF0000000000 ) >>40 ); } -static void sparx5_set_port_ifh (void *ifh_hdr,u16 portno) +void sparx5_set_port_ifh (void *ifh_hdr,u16 portno) {/* VSTAX.RSV = 1. MSBit must be 1 */ ifh_encode_bitfield (ifh_hdr,1 ,VSTAX +79 ,1 );
@@ -210,7 +210,6 @@ struct net_device *sparx5_create_netdev(struct sparx5 *sparx5, u32 portno) spx5_port->ndev = ndev; spx5_port->sparx5 = sparx5; spx5_port->portno = portno; -sparx5_set_port_ifh (spx5_port->ifh, portno); ndev->netdev_ops = &sparx5_port_netdev_ops; ndev->ethtool_ops = &sparx5_ethtool_ops;
drivers/net/ethernet/microchip/sparx5/sparx5_packet.c +6 -2
@@ -218,12 +218,16 @@ int sparx5_port_xmit_impl(struct sk_buff *skb, struct net_device *dev)struct net_device_stats *stats = &dev->stats;struct sparx5_port *port =netdev_priv (dev);struct sparx5 *sparx5 = port->sparx5; +u32 ifh[IFH_LEN ];int ret; +memset (ifh,0 ,IFH_LEN *4 ); +sparx5_set_port_ifh (ifh, port->portno); +if (sparx5->fdma_irq >0 ) - ret =sparx5_fdma_xmit (sparx5, port->ifh, skb); + ret =sparx5_fdma_xmit (sparx5, ifh, skb);else - ret =sparx5_inject (sparx5, port->ifh, skb, dev); + ret =sparx5_inject (sparx5, ifh, skb, dev);if (ret ==NETDEV_TX_OK ) { stats->tx_bytes += skb->len;
Signature · 1 line
2.33.0
PATCH 2/9 dt-bindings: net: sparx5: Extend with the ptp interrupt
In reply to Horatiu VulturExtend dt-bindings for sparx5 with ptp interrupt. This is generated when doing 2-step timestamping and the timestamp can be read from the FIFO.
--- .../devicetree/bindings/net/microchip,sparx5-switch.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml +2 -0
@@ -53,12 +53,14 @@ properties: items: - description: register based extraction - description: frame dma based extraction + - description: ptp interrupt interrupt-names: minItems: 1 items: - const: xtr - const: fdma + - const: ptp resets: items:
Signature · 1 line
2.33.0
PATCH 3/9 dts: sparx5: Enable ptp interrupt
In reply to Horatiu VulturAdd support for ptp interrupt. This interrupt is used when using 2-step timestamping. For each timestamp that is added in a queue, an interrupt is generated.
--- arch/arm64/boot/dts/microchip/sparx5.dtsi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/microchip/sparx5.dtsi +3 -2
@@ -468,9 +468,10 @@ switch: switch@0x600000000 { <0x6 0x10004000 0x7fc000>, <0x6 0x11010000 0xaf0000>; reg-names = "cpu", "dev", "gcb"; - interrupt-names = "xtr", "fdma"; + interrupt-names = "xtr", "fdma", "ptp"; interrupts = <GIC_SPI 30 IRQ_TYPE_LEVEL_HIGH>, - <GIC_SPI 25 IRQ_TYPE_LEVEL_HIGH>; + <GIC_SPI 25 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 27 IRQ_TYPE_LEVEL_HIGH>; resets = <&reset 0>; reset-names = "switch"; };
Signature · 1 line
2.33.0
PATCH 4/9 net: sparx5: Add registers that are used by ptp functionality
In reply to Horatiu VulturAdd the registers that will be used to configure the PHC in the HW.
--- .../ethernet/microchip/sparx5/sparx5_main.c | 1 + .../microchip/sparx5/sparx5_main_regs.h | 335 +++++++++++++++++- 2 files changed, 334 insertions(+), 2 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +1 -0
@@ -190,6 +190,7 @@ static const struct sparx5_main_io_resource sparx5_main_iomap[] = { { TARGET_ASM, 0x10600000, 1 }, /* 0x610600000 */ { TARGET_GCB, 0x11010000, 2 }, /* 0x611010000 */ { TARGET_QS, 0x11030000, 2 }, /* 0x611030000 */ + { TARGET_PTP, 0x11040000, 2 }, /* 0x611040000 */ { TARGET_ANA_ACL, 0x11050000, 2 }, /* 0x611050000 */ { TARGET_LRN, 0x11060000, 2 }, /* 0x611060000 */ { TARGET_VCAP_SUPER, 0x11080000, 2 }, /* 0x611080000 */
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h +333 -2
359 lines not on this page · raw message
Signature · 1 line
2.33.0
PATCH 5/9 net: sparx5: Add support for ptp clocks
In reply to Horatiu VulturThe sparx5 has 3 PHC. Enable each of them, for now all the timestamping is happening on the first PHC.
--- .../net/ethernet/microchip/sparx5/Makefile | 3 +- .../ethernet/microchip/sparx5/sparx5_main.c | 7 + .../ethernet/microchip/sparx5/sparx5_main.h | 21 ++ .../ethernet/microchip/sparx5/sparx5_ptp.c | 326 ++++++++++++++++++ 4 files changed, 356 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c
drivers/net/ethernet/microchip/sparx5/Makefile +2 -1
@@ -7,4 +7,5 @@ obj-$(CONFIG_SPARX5_SWITCH) += sparx5-switch.o sparx5-switch-objs := sparx5_main.o sparx5_packet.o \ sparx5_netdev.o sparx5_phylink.o sparx5_port.o sparx5_mactable.o sparx5_vlan.o \ - sparx5_switchdev.o sparx5_calendar.o sparx5_ethtool.o sparx5_fdma.o + sparx5_switchdev.o sparx5_calendar.o sparx5_ethtool.o sparx5_fdma.o \ + sparx5_ptp.o
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +7 -0
@@ -847,6 +847,12 @@ static int mchp_sparx5_probe(struct platform_device *pdev)dev_err (sparx5->dev,"Start failed\n" ); goto cleanup_ports; } + + err =sparx5_ptp_init (sparx5); +if (err) { +dev_err (sparx5->dev,"PTP failed\n" ); + goto cleanup_ports; + } goto cleanup_config; cleanup_ports:
@@ -870,6 +876,7 @@ static int mchp_sparx5_remove(struct platform_device *pdev)disable_irq (sparx5->fdma_irq); sparx5->fdma_irq = -ENXIO ; } +sparx5_ptp_deinit (sparx5);sparx5_fdma_stop (sparx5);sparx5_cleanup_ports (sparx5);/* Unregister netdevs */
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +21 -0
@@ -14,6 +14,8 @@#include <linux/if_vlan.h> #include <linux/bitmap.h> #include <linux/phylink.h> +#include <linux/net_tstamp.h> +#include <linux/ptp_clock_kernel.h> #include <linux/hrtimer.h> #include "sparx5_main_regs.h"
@@ -79,6 +81,9 @@ enum sparx5_vlan_port_type {#define FDMA_RX_DCB_MAX_DBS 15#define FDMA_TX_DCB_MAX_DBS 1 +#define SPARX5_PHC_COUNT 3 +#define SPARX5_PHC_PORT 0 +struct sparx5 ;struct sparx5_db_hw {
@@ -178,6 +183,14 @@ enum sparx5_core_clockfreq { SPX5_CORE_CLOCK_625MHZ, /* 625MHZ core clock frequency */ }; +struct sparx5_phc { +struct ptp_clock *clock; +struct ptp_clock_info info; +struct hwtstamp_config hwtstamp_config; +struct sparx5 *sparx5; +u8 index; +}; +struct sparx5 {struct platform_device *pdev;struct device *dev;
@@ -225,6 +238,10 @@ struct sparx5 {int fdma_irq;struct sparx5_rx rx;struct sparx5_tx tx; +/* PTP */ +bool ptp; +struct sparx5_phc phc[SPARX5_PHC_COUNT ]; +spinlock_t ptp_clock_lock;/* lock for phc */ };/* sparx5_switchdev.c */
@@ -294,6 +311,10 @@ int sparx5_register_netdevs(struct sparx5 *sparx5);void sparx5_destroy_netdevs (struct sparx5 *sparx5);void sparx5_unregister_netdevs (struct sparx5 *sparx5); +/* sparx5_ptp.c */ +int sparx5_ptp_init (struct sparx5 *sparx5); +void sparx5_ptp_deinit (struct sparx5 *sparx5); +/* Clock period in picoseconds */ static inline u32 sparx5_clk_period (enum sparx5_core_clockfreq cclock) {
drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c new file +326 -0
326 lines not on this page · raw message
Signature · 1 line
2.33.0
PATCH 6/9 net: sparx5: Implement SIOCSHWTSTAMP and SIOCGHWTSTAMP
In reply to Horatiu VulturImplement the ioctl callbacks SIOCSHWTSTAMP and SIOCGHWTSTAMP to allow to configure the ports to enable/disable timestamping for TX. The RX timestamping is always enabled. The HW is capable to run both 1-step timestamping and 2-step timestamping.
--- .../ethernet/microchip/sparx5/sparx5_main.h | 9 +++ .../ethernet/microchip/sparx5/sparx5_netdev.c | 19 +++++ .../ethernet/microchip/sparx5/sparx5_ptp.c | 74 +++++++++++++++++++ 3 files changed, 102 insertions(+)
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +9 -0
@@ -84,6 +84,10 @@ enum sparx5_vlan_port_type {#define SPARX5_PHC_COUNT 3#define SPARX5_PHC_PORT 0 +#define IFH_REW_OP_NOOP 0x0 +#define IFH_REW_OP_ONE_STEP_PTP 0x3 +#define IFH_REW_OP_TWO_STEP_PTP 0x4 +struct sparx5 ;struct sparx5_db_hw {
@@ -174,6 +178,8 @@ struct sparx5_port {u32 custom_etype;bool vlan_aware;struct hrtimer inj_timer; +/* ptp */ +u8 ptp_cmd; };enum sparx5_core_clockfreq {
@@ -242,6 +248,7 @@ struct sparx5 {bool ptp;struct sparx5_phc phc[SPARX5_PHC_COUNT ];spinlock_t ptp_clock_lock;/* lock for phc */ +struct mutex ptp_lock;/* lock for ptp interface state */ };/* sparx5_switchdev.c */
@@ -314,6 +321,8 @@ void sparx5_unregister_netdevs(struct sparx5 *sparx5);/* sparx5_ptp.c */ int sparx5_ptp_init (struct sparx5 *sparx5);void sparx5_ptp_deinit (struct sparx5 *sparx5); +int sparx5_ptp_hwtstamp_set (struct sparx5_port *port,struct ifreq *ifr); +int sparx5_ptp_hwtstamp_get (struct sparx5_port *port,struct ifreq *ifr);/* Clock period in picoseconds */ static inline u32 sparx5_clk_period (enum sparx5_core_clockfreq cclock)
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c +19 -0
@@ -179,6 +179,24 @@ static int sparx5_get_port_parent_id(struct net_device *dev,return 0 ; } +static int sparx5_port_ioctl (struct net_device *dev,struct ifreq *ifr, +int cmd) +{ +struct sparx5_port *sparx5_port =netdev_priv (dev); +struct sparx5 *sparx5 = sparx5_port->sparx5; + +if (!phy_has_hwtstamp (dev->phydev) && sparx5->ptp) { +switch (cmd) { +case SIOCSHWTSTAMP : +return sparx5_ptp_hwtstamp_set (sparx5_port, ifr); +case SIOCGHWTSTAMP : +return sparx5_ptp_hwtstamp_get (sparx5_port, ifr); + } + } + +return phy_mii_ioctl (dev->phydev, ifr, cmd); +} +static const struct net_device_ops sparx5_port_netdev_ops = { .ndo_open = sparx5_port_open, .ndo_stop = sparx5_port_stop,
@@ -189,6 +207,7 @@ static const struct net_device_ops sparx5_port_netdev_ops = { .ndo_validate_addr = eth_validate_addr, .ndo_get_stats64 = sparx5_get_stats64, .ndo_get_port_parent_id = sparx5_get_port_parent_id, + .ndo_eth_ioctl = sparx5_port_ioctl, };bool sparx5_netdevice_check (const struct net_device *dev)
drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c +74 -0
86 lines not on this page · raw message
Signature · 1 line
2.33.0
PATCH 7/9 net: sparx5: Update extraction/injection for timestamping
In reply to Horatiu VulturUpdate both the extraction and injection to do timestamping of the frames. The extraction is always doing the timestamping while for injection is doing the timestamping only if it is configured.
--- .../ethernet/microchip/sparx5/sparx5_fdma.c | 2 + .../ethernet/microchip/sparx5/sparx5_main.h | 32 ++++ .../ethernet/microchip/sparx5/sparx5_netdev.c | 20 +++ .../ethernet/microchip/sparx5/sparx5_packet.c | 29 ++- .../ethernet/microchip/sparx5/sparx5_ptp.c | 166 ++++++++++++++++++ 5 files changed, 248 insertions(+), 1 deletion(-)
drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c +2 -0
@@ -240,6 +240,8 @@ static bool sparx5_fdma_rx_get_frame(struct sparx5 *sparx5, struct sparx5_rx *rxskb_pull (skb,IFH_LEN *sizeof (u32));if (likely (!(skb->dev->features &NETIF_F_RXFCS )))skb_trim (skb, skb->len -ETH_FCS_LEN ); + +sparx5_ptp_rxtstamp (sparx5, skb, fi.timestamp); skb->protocol =eth_type_trans (skb, skb->dev);/* Everything we see on an interface that is in the HW bridge * has already been forwarded
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +32 -0
@@ -88,6 +88,11 @@ enum sparx5_vlan_port_type {#define IFH_REW_OP_ONE_STEP_PTP 0x3#define IFH_REW_OP_TWO_STEP_PTP 0x4 +#define IFH_PDU_TYPE_NONE 0x0 +#define IFH_PDU_TYPE_PTP 0x5 +#define IFH_PDU_TYPE_IPV4_UDP_PTP 0x6 +#define IFH_PDU_TYPE_IPV6_UDP_PTP 0x7 +struct sparx5 ;struct sparx5_db_hw {
@@ -180,6 +185,8 @@ struct sparx5_port {struct hrtimer inj_timer;/* ptp */ u8 ptp_cmd; +u16 ts_id; +struct sk_buff_head tx_skbs; };enum sparx5_core_clockfreq {
@@ -197,6 +204,18 @@ struct sparx5_phc {u8 index; }; +struct sparx5_skb_cb { +u8 rew_op; +u8 pdu_type; +u8 pdu_w16_offset; +u16 ts_id; +unsigned long jiffies; +}; + +#define SPARX5_PTP_TIMEOUT msecs_to_jiffies(10) +#define SPARX5_SKB_CB (skb) \ + ((struct sparx5_skb_cb *)((skb)->cb)) +struct sparx5 {struct platform_device *pdev;struct device *dev;
@@ -248,7 +267,9 @@ struct sparx5 {bool ptp;struct sparx5_phc phc[SPARX5_PHC_COUNT ];spinlock_t ptp_clock_lock;/* lock for phc */ +spinlock_t ptp_ts_id_lock;/* lock for ts_id */ struct mutex ptp_lock;/* lock for ptp interface state */ +u16 ptp_skbs; };/* sparx5_switchdev.c */
@@ -258,6 +279,7 @@ void sparx5_unregister_notifier_blocks(struct sparx5 *sparx5);/* sparx5_packet.c */ struct frame_info {int src_port; +u32 timestamp; };void sparx5_xtr_flush (struct sparx5 *sparx5,u8 grp);
@@ -311,6 +333,10 @@ void sparx5_get_stats64(struct net_device *ndev, struct rtnl_link_stats64 *statsint sparx_stats_init (struct sparx5 *sparx5);/* sparx5_netdev.c */ +void sparx5_set_port_ifh_timestamp (void *ifh_hdr,u64 timestamp); +void sparx5_set_port_ifh_rew_op (void *ifh_hdr,u32 rew_op); +void sparx5_set_port_ifh_pdu_type (void *ifh_hdr,u32 pdu_type); +void sparx5_set_port_ifh_pdu_w16_offset (void *ifh_hdr,u32 pdu_w16_offset);void sparx5_set_port_ifh (void *ifh_hdr,u16 portno);bool sparx5_netdevice_check (const struct net_device *dev);struct net_device *sparx5_create_netdev (struct sparx5 *sparx5,u32 portno);
@@ -323,6 +349,12 @@ int sparx5_ptp_init(struct sparx5 *sparx5);void sparx5_ptp_deinit (struct sparx5 *sparx5);int sparx5_ptp_hwtstamp_set (struct sparx5_port *port,struct ifreq *ifr);int sparx5_ptp_hwtstamp_get (struct sparx5_port *port,struct ifreq *ifr); +void sparx5_ptp_rxtstamp (struct sparx5 *sparx5,struct sk_buff *skb, +u64 timestamp); +int sparx5_ptp_txtstamp_request (struct sparx5_port *port, +struct sk_buff *skb); +void sparx5_ptp_txtstamp_release (struct sparx5_port *port, +struct sk_buff *skb);/* Clock period in picoseconds */ static inline u32 sparx5_clk_period (enum sparx5_core_clockfreq cclock)
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c +20 -0
@@ -74,6 +74,26 @@ void sparx5_set_port_ifh(void *ifh_hdr, u16 portno)ifh_encode_bitfield (ifh_hdr,1 ,67 ,1 ); } +void sparx5_set_port_ifh_rew_op (void *ifh_hdr,u32 rew_op) +{ +ifh_encode_bitfield (ifh_hdr, rew_op,VSTAX +32 ,10 ); +} + +void sparx5_set_port_ifh_pdu_type (void *ifh_hdr,u32 pdu_type) +{ +ifh_encode_bitfield (ifh_hdr, pdu_type,191 ,4 ); +} + +void sparx5_set_port_ifh_pdu_w16_offset (void *ifh_hdr,u32 pdu_w16_offset) +{ +ifh_encode_bitfield (ifh_hdr, pdu_w16_offset,195 ,6 ); +} + +void sparx5_set_port_ifh_timestamp (void *ifh_hdr,u64 timestamp) +{ +ifh_encode_bitfield (ifh_hdr, timestamp,232 ,40 ); +} +static int sparx5_port_open (struct net_device *ndev) {struct sparx5_port *port =netdev_priv (ndev);
drivers/net/ethernet/microchip/sparx5/sparx5_packet.c +28 -1
@@ -44,6 +44,12 @@ void sparx5_ifh_parse(u32 *ifh, struct frame_info *info) ((u32 )xtr_hdr[30 ] <<0 ); fwd = (fwd >>5 ); info->src_port =FIELD_GET (GENMASK (7 ,1 ), fwd); + + info->timestamp = + ((u64 )xtr_hdr[2 ] <<24 ) | + ((u64 )xtr_hdr[3 ] <<16 ) | + ((u64 )xtr_hdr[4 ] <<8 ) | + ((u64 )xtr_hdr[5 ] <<0 ); }static void sparx5_xtr_grp (struct sparx5 *sparx5,u8 grp,bool byte_swap)
@@ -144,6 +150,7 @@ static void sparx5_xtr_grp(struct sparx5 *sparx5, u8 grp, bool byte_swap)/* Finish up skb */ skb_put (skb, byte_cnt -ETH_FCS_LEN );eth_skb_pad (skb); +sparx5_ptp_rxtstamp (sparx5, skb, fi.timestamp); skb->protocol =eth_type_trans (skb, netdev); netdev->stats.rx_bytes += skb->len; netdev->stats.rx_packets++;
@@ -224,6 +231,18 @@ int sparx5_port_xmit_impl(struct sk_buff *skb, struct net_device *dev)memset (ifh,0 ,IFH_LEN *4 );sparx5_set_port_ifh (ifh, port->portno); +if (sparx5->ptp &&skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP ) { + ret =sparx5_ptp_txtstamp_request (port, skb); +if (ret) +return ret; + +sparx5_set_port_ifh_rew_op (ifh,SPARX5_SKB_CB (skb)->rew_op); +sparx5_set_port_ifh_pdu_type (ifh,SPARX5_SKB_CB (skb)->pdu_type); +sparx5_set_port_ifh_pdu_w16_offset (ifh,SPARX5_SKB_CB (skb)->pdu_w16_offset); +sparx5_set_port_ifh_timestamp (ifh,SPARX5_SKB_CB (skb)->ts_id); + } + +skb_tx_timestamp (skb);if (sparx5->fdma_irq >0 ) ret =sparx5_fdma_xmit (sparx5, ifh, skb);else
@@ -232,10 +251,18 @@ int sparx5_port_xmit_impl(struct sk_buff *skb, struct net_device *dev)if (ret ==NETDEV_TX_OK ) { stats->tx_bytes += skb->len; stats->tx_packets++; -skb_tx_timestamp (skb); + +if (skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP && +SPARX5_SKB_CB (skb)->rew_op ==IFH_REW_OP_TWO_STEP_PTP ) +return ret; +dev_kfree_skb_any (skb); }else { stats->tx_dropped++; + +if (skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP && +SPARX5_SKB_CB (skb)->rew_op ==IFH_REW_OP_TWO_STEP_PTP ) +sparx5_ptp_txtstamp_release (port, skb); }return ret; }
drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c +166 -0
197 lines not on this page · raw message
Signature · 1 line
2.33.0
PATCH 8/9 net: sparx5: Add support for ptp interrupts
In reply to Horatiu VulturWhen doing 2-step timestamping the HW will generate an interrupt when it managed to timestamp a frame. It is the SW responsibility to read it from the FIFO.
--- .../ethernet/microchip/sparx5/sparx5_main.c | 13 ++ .../ethernet/microchip/sparx5/sparx5_main.h | 2 + .../ethernet/microchip/sparx5/sparx5_ptp.c | 119 ++++++++++++++++++ 3 files changed, 134 insertions(+)
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +13 -0
@@ -693,6 +693,18 @@ static int sparx5_start(struct sparx5 *sparx5) }else { sparx5->xtr_irq = -ENXIO ; } + +if (sparx5->ptp_irq >=0 ) { + err =devm_request_threaded_irq (sparx5->dev, sparx5->ptp_irq, +NULL , sparx5_ptp_irq_handler, +IRQF_ONESHOT ,"sparx5-ptp" , + sparx5); +if (err) + sparx5->ptp_irq = -ENXIO ; + + sparx5->ptp =1 ; + } +return err; }
@@ -809,6 +821,7 @@ static int mchp_sparx5_probe(struct platform_device *pdev) sparx5->fdma_irq =platform_get_irq_byname (sparx5->pdev,"fdma" ); sparx5->xtr_irq =platform_get_irq_byname (sparx5->pdev,"xtr" ); + sparx5->ptp_irq =platform_get_irq_byname (sparx5->pdev,"ptp" );/* Read chip ID to check CPU interface */ sparx5->chip_id =spx5_rd (sparx5,GCB_CHIP_ID );
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +2 -0
@@ -270,6 +270,7 @@ struct sparx5 {spinlock_t ptp_ts_id_lock;/* lock for ts_id */ struct mutex ptp_lock;/* lock for ptp interface state */ u16 ptp_skbs; +int ptp_irq; };/* sparx5_switchdev.c */
@@ -355,6 +356,7 @@ int sparx5_ptp_txtstamp_request(struct sparx5_port *port, struct sk_buff *skb);void sparx5_ptp_txtstamp_release (struct sparx5_port *port,struct sk_buff *skb); +irqreturn_t sparx5_ptp_irq_handler (int irq,void *args);/* Clock period in picoseconds */ static inline u32 sparx5_clk_period (enum sparx5_core_clockfreq cclock)
drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c +119 -0
125 lines not on this page · raw message
Signature · 1 line
2.33.0
PATCH 9/9 net: sparx5: Implement get_ts_info
In reply to Horatiu VulturImplement the function get_ts_info in ethtool_ops which is needed to get the HW capabilities for timestamping.
--- .../microchip/sparx5/sparx5_ethtool.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+)
drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c +34 -0
@@ -1183,6 +1183,39 @@ static void sparx5_config_port_stats(struct sparx5 *sparx5, int portno) sparx5, ANA_AC_PORT_STAT_CFG(portno, SPX5_PORT_POLICER_DROPS)); } +static int sparx5_get_ts_info (struct net_device *dev, +struct ethtool_ts_info *info) +{ +struct sparx5_port *port =netdev_priv (dev); +struct sparx5 *sparx5 = port->sparx5; +struct sparx5_phc *phc; + +if (!sparx5->ptp) +return ethtool_op_get_ts_info (dev, info); + + phc = &sparx5->phc[SPARX5_PHC_PORT ]; + + info->phc_index = phc->clock ?ptp_clock_index (phc->clock) :-1 ; +if (info->phc_index ==-1 ) { + info->so_timestamping |=SOF_TIMESTAMPING_TX_SOFTWARE | +SOF_TIMESTAMPING_RX_SOFTWARE | +SOF_TIMESTAMPING_SOFTWARE ; +return 0 ; + } + info->so_timestamping |=SOF_TIMESTAMPING_TX_SOFTWARE | +SOF_TIMESTAMPING_RX_SOFTWARE | +SOF_TIMESTAMPING_SOFTWARE | +SOF_TIMESTAMPING_TX_HARDWARE | +SOF_TIMESTAMPING_RX_HARDWARE | +SOF_TIMESTAMPING_RAW_HARDWARE ; + info->tx_types =BIT (HWTSTAMP_TX_OFF ) |BIT (HWTSTAMP_TX_ON ) | +BIT (HWTSTAMP_TX_ONESTEP_SYNC ); + info->rx_filters =BIT (HWTSTAMP_FILTER_NONE ) | +BIT (HWTSTAMP_FILTER_ALL ); + +return 0 ; +} +const struct ethtool_ops sparx5_ethtool_ops = { .get_sset_count = sparx5_get_sset_count, .get_strings = sparx5_get_sset_strings,
@@ -1194,6 +1227,7 @@ const struct ethtool_ops sparx5_ethtool_ops = { .get_eth_mac_stats = sparx5_get_eth_mac_stats, .get_eth_ctrl_stats = sparx5_get_eth_mac_ctrl_stats, .get_rmon_stats = sparx5_get_eth_rmon_stats, + .get_ts_info = sparx5_get_ts_info, };int sparx_stats_init (struct sparx5 *sparx5)
Signature · 1 line
2.33.0
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 13 lines · On Fri, 4 Mar 2022 12:08:51 +0100 you wrote:
Add support for PTP Hardware Clock (PHC) for sparx5.
Horatiu Vultur (9):
net: sparx5: Move ifh from port to local variable
dt-bindings: net: sparx5: Extend with the ptp interrupt
dts: sparx5: Enable ptp interrupt
net: sparx5: Add registers that are used by ptp functionality
net: sparx5: Add support for ptp clocks
net: sparx5: Implement SIOCSHWTSTAMP and SIOCGHWTSTAMP
net: sparx5: Update extraction/injection for timestamping
net: sparx5: Add support for ptp interrupts
net: sparx5: Implementget_ts_info
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,1/9] net: sparx5: Move ifh from port to local variable
https://git.kernel.org/netdev/net-next/c/8f68f53a9325 - [net-next,2/9] dt-bindings: net: sparx5: Extend with the ptp interrupt https://git.kernel.org/netdev/net-next/c/b066ad26ebf2 - [net-next,3/9] dts: sparx5: Enable ptp interrupt https://git.kernel.org/netdev/net-next/c/6015fb905d89 - [net-next,4/9] net: sparx5: Add registers that are used by ptp functionality https://git.kernel.org/netdev/net-next/c/3193a6118140 - [net-next,5/9] net: sparx5: Add support for ptp clocks https://git.kernel.org/netdev/net-next/c/0933bd04047c - [net-next,6/9] net: sparx5: Implement SIOCSHWTSTAMP and SIOCGHWTSTAMP https://git.kernel.org/netdev/net-next/c/589a07b8eb49 - [net-next,7/9] net: sparx5: Update extraction/injection for timestamping https://git.kernel.org/netdev/net-next/c/70dfe25cd866 - [net-next,8/9] net: sparx5: Add support for ptp interrupts https://git.kernel.org/netdev/net-next/c/d31d37912ea7 - [net-next,9/9] net: sparx5: Implement get_ts_info https://git.kernel.org/netdev/net-next/c/608111fc580f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html