2019-06-11 23:45:10 +08:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
|
|
|
|
/* Copyright (c) 2019 Mellanox Technologies. All rights reserved */
|
|
|
|
|
|
|
|
#ifndef _MLXSW_SPECTRUM_PTP_H
|
|
|
|
#define _MLXSW_SPECTRUM_PTP_H
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
2019-06-30 14:04:54 +08:00
|
|
|
#include <linux/rhashtable.h>
|
2019-06-11 23:45:10 +08:00
|
|
|
|
2019-06-30 14:04:54 +08:00
|
|
|
struct mlxsw_sp;
|
|
|
|
struct mlxsw_sp_port;
|
2019-06-11 23:45:10 +08:00
|
|
|
struct mlxsw_sp_ptp_clock;
|
|
|
|
|
2019-06-30 14:04:58 +08:00
|
|
|
enum {
|
|
|
|
MLXSW_SP_PTP_MESSAGE_TYPE_SYNC,
|
|
|
|
MLXSW_SP_PTP_MESSAGE_TYPE_DELAY_REQ,
|
|
|
|
MLXSW_SP_PTP_MESSAGE_TYPE_PDELAY_REQ,
|
|
|
|
MLXSW_SP_PTP_MESSAGE_TYPE_PDELAY_RESP,
|
|
|
|
};
|
|
|
|
|
2019-06-30 14:05:00 +08:00
|
|
|
static inline int mlxsw_sp_ptp_get_ts_info_noptp(struct ethtool_ts_info *info)
|
|
|
|
{
|
|
|
|
info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
|
|
|
|
SOF_TIMESTAMPING_SOFTWARE;
|
|
|
|
info->phc_index = -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-11 23:45:10 +08:00
|
|
|
#if IS_REACHABLE(CONFIG_PTP_1588_CLOCK)
|
|
|
|
|
|
|
|
struct mlxsw_sp_ptp_clock *
|
|
|
|
mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
|
|
|
|
|
|
|
|
void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
|
|
|
|
|
2019-06-30 14:04:54 +08:00
|
|
|
struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp);
|
|
|
|
|
|
|
|
void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
|
|
|
|
|
mlxsw: spectrum: PTP: Hook into packet receive path
When configured, the Spectrum hardware can recognize PTP packets and
trap them to the CPU using dedicated traps, PTP0 and PTP1.
One reason to get PTP packets under dedicated traps is to have a
separate policer suitable for the amount of PTP traffic expected when
switch is operated as a boundary clock. For this, add two new trap
groups, MLXSW_REG_HTGT_TRAP_GROUP_SP_PTP0 and _PTP1, and associate the
two PTP traps with these two groups.
In the driver, specifically for Spectrum-1, event PTP packets will need
to be paired up with their timestamps. Those arrive through a different
set of traps, added later in the patch set. To support this future use,
introduce a new PTP op, ptp_receive.
It is possible to configure which PTP messages should be trapped under
which PTP trap. On Spectrum systems, we will use PTP0 for event
packets (which need timestamping), and PTP1 for control packets (which
do not). Thus configure PTP0 trap with a custom callback that defers to
the ptp_receive op.
Additionally, L2 PTP packets are actually trapped through the LLDP trap,
not through any of the PTP traps. So treat the LLDP trap the same way as
the PTP0 trap. Unlike PTP traps, which are currently still disabled,
LLDP trap is active. Correspondingly, have all the implementations of
the ptp_receive op return true, which the handler treats as a signal to
forward the packet immediately.
Signed-off-by: Petr Machata <petrm@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-30 14:04:51 +08:00
|
|
|
void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
|
|
|
|
u8 local_port);
|
|
|
|
|
mlxsw: pci: PTP: Hook into packet transmit path
On Spectrum-1, timestamps are delivered separately from the packets, and
need to paired up. Therefore, at some point after mlxsw_sp_port_xmit()
is invoked, it is necessary to involve the chip-specific driver code to
allow it to do the necessary bookkeeping and matching.
On Spectrum-2, timestamps are delivered in CQE. For that reason,
position the point of driver involvement into mlxsw_pci_cqe_sdq_handle()
to make it hopefully easier to extend for Spectrum-2 in the future.
To tell the driver what port the packet was sent on, keep tx_info
in SKB control buffer.
Introduce a new driver core interface mlxsw_core_ptp_transmitted(), a
driver callback ptp_transmitted, and a PTP op transmitted. The callee is
responsible for taking care of releasing the SKB passed to the new
interfaces, and correspondingly have the new stub callbacks just call
dev_kfree_skb_any().
Follow-up patches will introduce the actual content into
mlxsw_sp1_ptp_transmitted() in particular.
Signed-off-by: Petr Machata <petrm@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-30 14:04:53 +08:00
|
|
|
void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct sk_buff *skb, u8 local_port);
|
|
|
|
|
2019-06-30 14:04:56 +08:00
|
|
|
void mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
|
|
|
|
u8 local_port, u8 message_type,
|
|
|
|
u8 domain_number, u16 sequence_id,
|
|
|
|
u64 timestamp);
|
|
|
|
|
2019-06-30 14:04:59 +08:00
|
|
|
int mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
|
|
|
|
struct hwtstamp_config *config);
|
|
|
|
|
|
|
|
int mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
|
|
|
|
struct hwtstamp_config *config);
|
|
|
|
|
2019-07-04 15:07:39 +08:00
|
|
|
void mlxsw_sp1_ptp_shaper_work(struct work_struct *work);
|
|
|
|
|
2019-06-30 14:05:00 +08:00
|
|
|
int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct ethtool_ts_info *info);
|
|
|
|
|
mlxsw: spectrum_ptp: Add counters for GC events
On Spectrum-1, timestamped PTP packets and the corresponding timestamps need to
be kept in caches until both are available, at which point they are matched up
and packets forwarded as appropriate. However, not all packets will ever see
their timestamp, and not all timestamps will ever see their packet. It is
necessary to dispose of such abandoned entries, so a garbage collector was
introduced in commit 5d23e4159772 ("mlxsw: spectrum: PTP: Garbage-collect
unmatched entries").
If these GC events happen often, it is a sign of a problem. However because this
whole mechanism is taking place behind the scenes, there is no direct way to
determine whether garbage collection took place.
Therefore to fix this, on Spectrum-1 only, expose four artificial ethtool
counters for the GC events: GCd timestamps and packets, in TX and RX directions.
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: Petr Machata <petrm@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-08-28 23:54:37 +08:00
|
|
|
int mlxsw_sp1_get_stats_count(void);
|
|
|
|
void mlxsw_sp1_get_stats_strings(u8 **p);
|
|
|
|
void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
|
|
|
|
u64 *data, int data_index);
|
|
|
|
|
2019-06-11 23:45:10 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
static inline struct mlxsw_sp_ptp_clock *
|
|
|
|
mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-30 14:04:54 +08:00
|
|
|
static inline struct mlxsw_sp_ptp_state *
|
|
|
|
mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
mlxsw: spectrum: PTP: Hook into packet receive path
When configured, the Spectrum hardware can recognize PTP packets and
trap them to the CPU using dedicated traps, PTP0 and PTP1.
One reason to get PTP packets under dedicated traps is to have a
separate policer suitable for the amount of PTP traffic expected when
switch is operated as a boundary clock. For this, add two new trap
groups, MLXSW_REG_HTGT_TRAP_GROUP_SP_PTP0 and _PTP1, and associate the
two PTP traps with these two groups.
In the driver, specifically for Spectrum-1, event PTP packets will need
to be paired up with their timestamps. Those arrive through a different
set of traps, added later in the patch set. To support this future use,
introduce a new PTP op, ptp_receive.
It is possible to configure which PTP messages should be trapped under
which PTP trap. On Spectrum systems, we will use PTP0 for event
packets (which need timestamping), and PTP1 for control packets (which
do not). Thus configure PTP0 trap with a custom callback that defers to
the ptp_receive op.
Additionally, L2 PTP packets are actually trapped through the LLDP trap,
not through any of the PTP traps. So treat the LLDP trap the same way as
the PTP0 trap. Unlike PTP traps, which are currently still disabled,
LLDP trap is active. Correspondingly, have all the implementations of
the ptp_receive op return true, which the handler treats as a signal to
forward the packet immediately.
Signed-off-by: Petr Machata <petrm@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-30 14:04:51 +08:00
|
|
|
static inline void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct sk_buff *skb, u8 local_port)
|
|
|
|
{
|
|
|
|
mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
|
|
|
|
}
|
|
|
|
|
mlxsw: pci: PTP: Hook into packet transmit path
On Spectrum-1, timestamps are delivered separately from the packets, and
need to paired up. Therefore, at some point after mlxsw_sp_port_xmit()
is invoked, it is necessary to involve the chip-specific driver code to
allow it to do the necessary bookkeeping and matching.
On Spectrum-2, timestamps are delivered in CQE. For that reason,
position the point of driver involvement into mlxsw_pci_cqe_sdq_handle()
to make it hopefully easier to extend for Spectrum-2 in the future.
To tell the driver what port the packet was sent on, keep tx_info
in SKB control buffer.
Introduce a new driver core interface mlxsw_core_ptp_transmitted(), a
driver callback ptp_transmitted, and a PTP op transmitted. The callee is
responsible for taking care of releasing the SKB passed to the new
interfaces, and correspondingly have the new stub callbacks just call
dev_kfree_skb_any().
Follow-up patches will introduce the actual content into
mlxsw_sp1_ptp_transmitted() in particular.
Signed-off-by: Petr Machata <petrm@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-30 14:04:53 +08:00
|
|
|
static inline void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct sk_buff *skb, u8 local_port)
|
|
|
|
{
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
}
|
|
|
|
|
2019-06-30 14:04:56 +08:00
|
|
|
static inline void
|
|
|
|
mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
|
|
|
|
u8 local_port, u8 message_type,
|
|
|
|
u8 domain_number,
|
|
|
|
u16 sequence_id, u64 timestamp)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-30 14:04:59 +08:00
|
|
|
static inline int
|
|
|
|
mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
|
|
|
|
struct hwtstamp_config *config)
|
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
|
|
|
|
struct hwtstamp_config *config)
|
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2019-07-04 15:07:39 +08:00
|
|
|
static inline void mlxsw_sp1_ptp_shaper_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-30 14:05:00 +08:00
|
|
|
static inline int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct ethtool_ts_info *info)
|
|
|
|
{
|
|
|
|
return mlxsw_sp_ptp_get_ts_info_noptp(info);
|
|
|
|
}
|
|
|
|
|
mlxsw: spectrum_ptp: Add counters for GC events
On Spectrum-1, timestamped PTP packets and the corresponding timestamps need to
be kept in caches until both are available, at which point they are matched up
and packets forwarded as appropriate. However, not all packets will ever see
their timestamp, and not all timestamps will ever see their packet. It is
necessary to dispose of such abandoned entries, so a garbage collector was
introduced in commit 5d23e4159772 ("mlxsw: spectrum: PTP: Garbage-collect
unmatched entries").
If these GC events happen often, it is a sign of a problem. However because this
whole mechanism is taking place behind the scenes, there is no direct way to
determine whether garbage collection took place.
Therefore to fix this, on Spectrum-1 only, expose four artificial ethtool
counters for the GC events: GCd timestamps and packets, in TX and RX directions.
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: Petr Machata <petrm@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-08-28 23:54:37 +08:00
|
|
|
static inline int mlxsw_sp1_get_stats_count(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mlxsw_sp1_get_stats_strings(u8 **p)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
|
|
|
|
u64 *data, int data_index)
|
|
|
|
{
|
|
|
|
}
|
2019-06-11 23:45:10 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline struct mlxsw_sp_ptp_clock *
|
|
|
|
mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-30 14:04:54 +08:00
|
|
|
static inline struct mlxsw_sp_ptp_state *
|
|
|
|
mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
mlxsw: spectrum: PTP: Hook into packet receive path
When configured, the Spectrum hardware can recognize PTP packets and
trap them to the CPU using dedicated traps, PTP0 and PTP1.
One reason to get PTP packets under dedicated traps is to have a
separate policer suitable for the amount of PTP traffic expected when
switch is operated as a boundary clock. For this, add two new trap
groups, MLXSW_REG_HTGT_TRAP_GROUP_SP_PTP0 and _PTP1, and associate the
two PTP traps with these two groups.
In the driver, specifically for Spectrum-1, event PTP packets will need
to be paired up with their timestamps. Those arrive through a different
set of traps, added later in the patch set. To support this future use,
introduce a new PTP op, ptp_receive.
It is possible to configure which PTP messages should be trapped under
which PTP trap. On Spectrum systems, we will use PTP0 for event
packets (which need timestamping), and PTP1 for control packets (which
do not). Thus configure PTP0 trap with a custom callback that defers to
the ptp_receive op.
Additionally, L2 PTP packets are actually trapped through the LLDP trap,
not through any of the PTP traps. So treat the LLDP trap the same way as
the PTP0 trap. Unlike PTP traps, which are currently still disabled,
LLDP trap is active. Correspondingly, have all the implementations of
the ptp_receive op return true, which the handler treats as a signal to
forward the packet immediately.
Signed-off-by: Petr Machata <petrm@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-30 14:04:51 +08:00
|
|
|
static inline void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct sk_buff *skb, u8 local_port)
|
|
|
|
{
|
|
|
|
mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
|
|
|
|
}
|
|
|
|
|
mlxsw: pci: PTP: Hook into packet transmit path
On Spectrum-1, timestamps are delivered separately from the packets, and
need to paired up. Therefore, at some point after mlxsw_sp_port_xmit()
is invoked, it is necessary to involve the chip-specific driver code to
allow it to do the necessary bookkeeping and matching.
On Spectrum-2, timestamps are delivered in CQE. For that reason,
position the point of driver involvement into mlxsw_pci_cqe_sdq_handle()
to make it hopefully easier to extend for Spectrum-2 in the future.
To tell the driver what port the packet was sent on, keep tx_info
in SKB control buffer.
Introduce a new driver core interface mlxsw_core_ptp_transmitted(), a
driver callback ptp_transmitted, and a PTP op transmitted. The callee is
responsible for taking care of releasing the SKB passed to the new
interfaces, and correspondingly have the new stub callbacks just call
dev_kfree_skb_any().
Follow-up patches will introduce the actual content into
mlxsw_sp1_ptp_transmitted() in particular.
Signed-off-by: Petr Machata <petrm@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-30 14:04:53 +08:00
|
|
|
static inline void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct sk_buff *skb, u8 local_port)
|
|
|
|
{
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
}
|
|
|
|
|
2019-06-30 14:04:59 +08:00
|
|
|
static inline int
|
|
|
|
mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
|
|
|
|
struct hwtstamp_config *config)
|
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
|
|
|
|
struct hwtstamp_config *config)
|
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2019-07-04 15:07:39 +08:00
|
|
|
static inline void mlxsw_sp2_ptp_shaper_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-30 14:05:00 +08:00
|
|
|
static inline int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
|
|
|
|
struct ethtool_ts_info *info)
|
|
|
|
{
|
|
|
|
return mlxsw_sp_ptp_get_ts_info_noptp(info);
|
|
|
|
}
|
|
|
|
|
mlxsw: spectrum_ptp: Add counters for GC events
On Spectrum-1, timestamped PTP packets and the corresponding timestamps need to
be kept in caches until both are available, at which point they are matched up
and packets forwarded as appropriate. However, not all packets will ever see
their timestamp, and not all timestamps will ever see their packet. It is
necessary to dispose of such abandoned entries, so a garbage collector was
introduced in commit 5d23e4159772 ("mlxsw: spectrum: PTP: Garbage-collect
unmatched entries").
If these GC events happen often, it is a sign of a problem. However because this
whole mechanism is taking place behind the scenes, there is no direct way to
determine whether garbage collection took place.
Therefore to fix this, on Spectrum-1 only, expose four artificial ethtool
counters for the GC events: GCd timestamps and packets, in TX and RX directions.
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: Petr Machata <petrm@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-08-28 23:54:37 +08:00
|
|
|
static inline int mlxsw_sp2_get_stats_count(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mlxsw_sp2_get_stats_strings(u8 **p)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mlxsw_sp2_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
|
|
|
|
u64 *data, int data_index)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-11 23:45:10 +08:00
|
|
|
#endif
|