2020-12-01 22:42:01 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
|
|
|
|
/* Copyright (c) 2020 Mellanox Technologies. */
|
|
|
|
|
|
|
|
#ifndef __MLX5_EN_PTP_H__
|
|
|
|
#define __MLX5_EN_PTP_H__
|
|
|
|
|
|
|
|
#include "en.h"
|
|
|
|
#include "en_stats.h"
|
2022-10-26 13:51:42 +00:00
|
|
|
#include "en/txrx.h"
|
2023-05-02 23:31:40 +00:00
|
|
|
#include <linux/ktime.h>
|
2021-04-19 08:58:31 +00:00
|
|
|
#include <linux/ptp_classify.h>
|
2023-05-02 23:31:40 +00:00
|
|
|
#include <linux/time64.h>
|
2023-08-09 04:10:21 +00:00
|
|
|
#include <linux/workqueue.h>
|
2020-12-01 22:42:01 +00:00
|
|
|
|
2021-08-29 08:26:03 +00:00
|
|
|
#define MLX5E_PTP_CHANNEL_IX 0
|
2023-05-02 23:31:40 +00:00
|
|
|
#define MLX5E_PTP_MAX_LOG_SQ_SIZE (8U)
|
|
|
|
#define MLX5E_PTP_TS_CQE_UNDELIVERED_TIMEOUT (1 * NSEC_PER_SEC)
|
|
|
|
|
|
|
|
struct mlx5e_ptp_metadata_fifo {
|
|
|
|
u8 cc;
|
|
|
|
u8 pc;
|
|
|
|
u8 mask;
|
|
|
|
u8 *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mlx5e_ptp_metadata_map {
|
|
|
|
u16 undelivered_counter;
|
|
|
|
u16 capacity;
|
|
|
|
struct sk_buff **data;
|
|
|
|
};
|
2021-08-29 08:26:03 +00:00
|
|
|
|
2020-12-01 22:42:01 +00:00
|
|
|
struct mlx5e_ptpsq {
|
|
|
|
struct mlx5e_txqsq txqsq;
|
net/mlx5e: Add TX port timestamp support
Transmitted packet timestamping accuracy can be improved when using
timestamp from the port, instead of packet CQE creation timestamp, as
it better reflects the actual time of a packet's transmit.
TX port timestamping is supported starting from ConnectX6-DX hardware.
Although at the original completion, only CQE timestamp can be attached,
we are able to get TX port timestamping via an additional completion over
a special CQ associated with the SQ (in addition to the regular CQ).
Driver to ignore the original packet completion timestamp, and report
back the timestamp of the special CQ completion. If the absolute timestamp
diff between the two completions is greater than 1 / 128 second, ignore
the TX port timestamp as it has a jitter which is too big.
No skb will be generate out of the extra completion.
Allocate additional CQ per ptpsq, to receive the TX port timestamp.
Driver to hold an skb FIFO in order to map between transmitted skb to
the two expected completions. When using ptpsq, hold double refcount on
the skb, to gaurantee it will not get released before both completions
arrive.
Expose dedicated counters of the ptp additional CQ and connect it to the
TX health reporter.
This patch improves TX Hardware timestamping offset to be less than 40ns
at a 100Gbps line rate, compared to 600ns before.
With that, making our HW compliant with G.8273.2 class C, and allow Linux
systems to be deployed in the 5G telco edge, where this standard is a
must.
Signed-off-by: Eran Ben Elisha <eranbe@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
2020-12-01 22:42:02 +00:00
|
|
|
struct mlx5e_cq ts_cq;
|
|
|
|
struct mlx5e_ptp_cq_stats *cq_stats;
|
2022-07-04 16:34:26 +00:00
|
|
|
u16 ts_cqe_ctr_mask;
|
2023-05-02 23:31:40 +00:00
|
|
|
|
2023-08-09 04:10:21 +00:00
|
|
|
struct work_struct report_unhealthy_work;
|
2023-05-02 23:31:40 +00:00
|
|
|
struct mlx5e_ptp_port_ts_cqe_list *ts_cqe_pending_list;
|
|
|
|
struct mlx5e_ptp_metadata_fifo metadata_freelist;
|
|
|
|
struct mlx5e_ptp_metadata_map metadata_map;
|
2020-12-01 22:42:01 +00:00
|
|
|
};
|
|
|
|
|
2021-01-11 14:45:21 +00:00
|
|
|
enum {
|
|
|
|
MLX5E_PTP_STATE_TX,
|
2021-03-07 13:47:37 +00:00
|
|
|
MLX5E_PTP_STATE_RX,
|
2021-01-11 14:45:21 +00:00
|
|
|
MLX5E_PTP_STATE_NUM_STATES,
|
|
|
|
};
|
|
|
|
|
2021-03-07 13:41:27 +00:00
|
|
|
struct mlx5e_ptp {
|
2020-12-01 22:42:01 +00:00
|
|
|
/* data path */
|
|
|
|
struct mlx5e_ptpsq ptpsq[MLX5E_MAX_NUM_TC];
|
2021-03-07 13:47:37 +00:00
|
|
|
struct mlx5e_rq rq;
|
2020-12-01 22:42:01 +00:00
|
|
|
struct napi_struct napi;
|
|
|
|
struct device *pdev;
|
|
|
|
struct net_device *netdev;
|
|
|
|
__be32 mkey_be;
|
|
|
|
u8 num_tc;
|
|
|
|
u8 lag_port;
|
|
|
|
|
|
|
|
/* data path - accessed per napi poll */
|
|
|
|
struct mlx5e_ch_stats *stats;
|
|
|
|
|
|
|
|
/* control */
|
|
|
|
struct mlx5e_priv *priv;
|
|
|
|
struct mlx5_core_dev *mdev;
|
|
|
|
struct hwtstamp_config *tstamp;
|
2021-01-11 14:45:21 +00:00
|
|
|
DECLARE_BITMAP(state, MLX5E_PTP_STATE_NUM_STATES);
|
2020-12-01 22:42:01 +00:00
|
|
|
};
|
|
|
|
|
2021-04-19 08:58:31 +00:00
|
|
|
static inline bool mlx5e_use_ptpsq(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct flow_keys fk;
|
|
|
|
|
|
|
|
if (!(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!skb_flow_dissect_flow_keys(skb, &fk, 0))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (fk.basic.n_proto == htons(ETH_P_1588))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (fk.basic.n_proto != htons(ETH_P_IP) &&
|
|
|
|
fk.basic.n_proto != htons(ETH_P_IPV6))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (fk.basic.ip_proto == IPPROTO_UDP &&
|
|
|
|
fk.ports.dst == htons(PTP_EV_PORT));
|
|
|
|
}
|
|
|
|
|
2023-05-02 23:31:40 +00:00
|
|
|
static inline void mlx5e_ptp_metadata_fifo_push(struct mlx5e_ptp_metadata_fifo *fifo, u8 metadata)
|
2022-10-26 13:51:42 +00:00
|
|
|
{
|
2023-05-02 23:31:40 +00:00
|
|
|
fifo->data[fifo->mask & fifo->pc++] = metadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u8
|
2024-04-09 19:08:17 +00:00
|
|
|
mlx5e_ptp_metadata_fifo_peek(struct mlx5e_ptp_metadata_fifo *fifo)
|
|
|
|
{
|
|
|
|
return fifo->data[fifo->mask & fifo->cc];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2023-05-02 23:31:40 +00:00
|
|
|
mlx5e_ptp_metadata_fifo_pop(struct mlx5e_ptp_metadata_fifo *fifo)
|
|
|
|
{
|
2024-04-09 19:08:17 +00:00
|
|
|
fifo->cc++;
|
2023-05-02 23:31:40 +00:00
|
|
|
}
|
2022-10-26 13:51:42 +00:00
|
|
|
|
2023-05-02 23:31:40 +00:00
|
|
|
static inline void
|
|
|
|
mlx5e_ptp_metadata_map_put(struct mlx5e_ptp_metadata_map *map,
|
|
|
|
struct sk_buff *skb, u8 metadata)
|
|
|
|
{
|
|
|
|
WARN_ON_ONCE(map->data[metadata]);
|
|
|
|
map->data[metadata] = skb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool mlx5e_ptpsq_metadata_freelist_empty(struct mlx5e_ptpsq *ptpsq)
|
|
|
|
{
|
|
|
|
struct mlx5e_ptp_metadata_fifo *freelist;
|
|
|
|
|
|
|
|
if (likely(!ptpsq))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
freelist = &ptpsq->metadata_freelist;
|
|
|
|
|
|
|
|
return freelist->pc == freelist->cc;
|
2022-10-26 13:51:42 +00:00
|
|
|
}
|
|
|
|
|
2021-03-07 13:41:27 +00:00
|
|
|
int mlx5e_ptp_open(struct mlx5e_priv *priv, struct mlx5e_params *params,
|
|
|
|
u8 lag_port, struct mlx5e_ptp **cp);
|
|
|
|
void mlx5e_ptp_close(struct mlx5e_ptp *c);
|
|
|
|
void mlx5e_ptp_activate_channel(struct mlx5e_ptp *c);
|
|
|
|
void mlx5e_ptp_deactivate_channel(struct mlx5e_ptp *c);
|
2021-02-25 17:55:20 +00:00
|
|
|
int mlx5e_ptp_get_rqn(struct mlx5e_ptp *c, u32 *rqn);
|
2022-01-31 20:13:41 +00:00
|
|
|
int mlx5e_ptp_alloc_rx_fs(struct mlx5e_flow_steering *fs,
|
|
|
|
const struct mlx5e_profile *profile);
|
|
|
|
void mlx5e_ptp_free_rx_fs(struct mlx5e_flow_steering *fs,
|
|
|
|
const struct mlx5e_profile *profile);
|
2021-02-16 10:32:48 +00:00
|
|
|
int mlx5e_ptp_rx_manage_fs(struct mlx5e_priv *priv, bool set);
|
2020-12-01 22:42:01 +00:00
|
|
|
|
2023-05-02 23:31:40 +00:00
|
|
|
void mlx5e_ptpsq_track_metadata(struct mlx5e_ptpsq *ptpsq, u8 metadata);
|
|
|
|
|
net/mlx5e: Add TX port timestamp support
Transmitted packet timestamping accuracy can be improved when using
timestamp from the port, instead of packet CQE creation timestamp, as
it better reflects the actual time of a packet's transmit.
TX port timestamping is supported starting from ConnectX6-DX hardware.
Although at the original completion, only CQE timestamp can be attached,
we are able to get TX port timestamping via an additional completion over
a special CQ associated with the SQ (in addition to the regular CQ).
Driver to ignore the original packet completion timestamp, and report
back the timestamp of the special CQ completion. If the absolute timestamp
diff between the two completions is greater than 1 / 128 second, ignore
the TX port timestamp as it has a jitter which is too big.
No skb will be generate out of the extra completion.
Allocate additional CQ per ptpsq, to receive the TX port timestamp.
Driver to hold an skb FIFO in order to map between transmitted skb to
the two expected completions. When using ptpsq, hold double refcount on
the skb, to gaurantee it will not get released before both completions
arrive.
Expose dedicated counters of the ptp additional CQ and connect it to the
TX health reporter.
This patch improves TX Hardware timestamping offset to be less than 40ns
at a 100Gbps line rate, compared to 600ns before.
With that, making our HW compliant with G.8273.2 class C, and allow Linux
systems to be deployed in the 5G telco edge, where this standard is a
must.
Signed-off-by: Eran Ben Elisha <eranbe@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
2020-12-01 22:42:02 +00:00
|
|
|
enum {
|
|
|
|
MLX5E_SKB_CB_CQE_HWTSTAMP = BIT(0),
|
|
|
|
MLX5E_SKB_CB_PORT_HWTSTAMP = BIT(1),
|
|
|
|
};
|
|
|
|
|
|
|
|
void mlx5e_skb_cb_hwtstamp_handler(struct sk_buff *skb, int hwtstamp_type,
|
|
|
|
ktime_t hwtstamp,
|
|
|
|
struct mlx5e_ptp_cq_stats *cq_stats);
|
|
|
|
|
|
|
|
void mlx5e_skb_cb_hwtstamp_init(struct sk_buff *skb);
|
2020-12-01 22:42:01 +00:00
|
|
|
#endif /* __MLX5_EN_PTP_H__ */
|