1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2020 Mellanox Technologies. */
4 #ifndef __MLX5_EN_PTP_H__
5 #define __MLX5_EN_PTP_H__
10 #include <linux/ptp_classify.h>
12 #define MLX5E_PTP_CHANNEL_IX 0
15 struct mlx5e_txqsq txqsq;
16 struct mlx5e_cq ts_cq;
19 struct mlx5e_skb_fifo skb_fifo;
20 struct mlx5e_ptp_cq_stats *cq_stats;
27 MLX5E_PTP_STATE_NUM_STATES,
32 struct mlx5e_ptpsq ptpsq[MLX5E_MAX_NUM_TC];
34 struct napi_struct napi;
36 struct net_device *netdev;
41 /* data path - accessed per napi poll */
42 struct mlx5e_ch_stats *stats;
45 struct mlx5e_priv *priv;
46 struct mlx5_core_dev *mdev;
47 struct hwtstamp_config *tstamp;
48 DECLARE_BITMAP(state, MLX5E_PTP_STATE_NUM_STATES);
51 static inline bool mlx5e_use_ptpsq(struct sk_buff *skb)
55 if (!(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
58 if (!skb_flow_dissect_flow_keys(skb, &fk, 0))
61 if (fk.basic.n_proto == htons(ETH_P_1588))
64 if (fk.basic.n_proto != htons(ETH_P_IP) &&
65 fk.basic.n_proto != htons(ETH_P_IPV6))
68 return (fk.basic.ip_proto == IPPROTO_UDP &&
69 fk.ports.dst == htons(PTP_EV_PORT));
72 static inline bool mlx5e_ptpsq_fifo_has_room(struct mlx5e_txqsq *sq)
77 return mlx5e_skb_fifo_has_room(&sq->ptpsq->skb_fifo);
80 int mlx5e_ptp_open(struct mlx5e_priv *priv, struct mlx5e_params *params,
81 u8 lag_port, struct mlx5e_ptp **cp);
82 void mlx5e_ptp_close(struct mlx5e_ptp *c);
83 void mlx5e_ptp_activate_channel(struct mlx5e_ptp *c);
84 void mlx5e_ptp_deactivate_channel(struct mlx5e_ptp *c);
85 int mlx5e_ptp_get_rqn(struct mlx5e_ptp *c, u32 *rqn);
86 int mlx5e_ptp_alloc_rx_fs(struct mlx5e_flow_steering *fs,
87 const struct mlx5e_profile *profile);
88 void mlx5e_ptp_free_rx_fs(struct mlx5e_flow_steering *fs,
89 const struct mlx5e_profile *profile);
90 int mlx5e_ptp_rx_manage_fs(struct mlx5e_priv *priv, bool set);
93 MLX5E_SKB_CB_CQE_HWTSTAMP = BIT(0),
94 MLX5E_SKB_CB_PORT_HWTSTAMP = BIT(1),
97 void mlx5e_skb_cb_hwtstamp_handler(struct sk_buff *skb, int hwtstamp_type,
99 struct mlx5e_ptp_cq_stats *cq_stats);
101 void mlx5e_skb_cb_hwtstamp_init(struct sk_buff *skb);
102 #endif /* __MLX5_EN_PTP_H__ */