0001
0002
0003
0004 #ifndef __MLX5_EN_PTP_H__
0005 #define __MLX5_EN_PTP_H__
0006
0007 #include "en.h"
0008 #include "en_stats.h"
0009 #include <linux/ptp_classify.h>
0010
0011 #define MLX5E_PTP_CHANNEL_IX 0
0012
0013 struct mlx5e_ptpsq {
0014 struct mlx5e_txqsq txqsq;
0015 struct mlx5e_cq ts_cq;
0016 u16 skb_fifo_cc;
0017 u16 skb_fifo_pc;
0018 struct mlx5e_skb_fifo skb_fifo;
0019 struct mlx5e_ptp_cq_stats *cq_stats;
0020 u16 ts_cqe_ctr_mask;
0021 };
0022
0023 enum {
0024 MLX5E_PTP_STATE_TX,
0025 MLX5E_PTP_STATE_RX,
0026 MLX5E_PTP_STATE_NUM_STATES,
0027 };
0028
0029 struct mlx5e_ptp {
0030
0031 struct mlx5e_ptpsq ptpsq[MLX5E_MAX_NUM_TC];
0032 struct mlx5e_rq rq;
0033 struct napi_struct napi;
0034 struct device *pdev;
0035 struct net_device *netdev;
0036 __be32 mkey_be;
0037 u8 num_tc;
0038 u8 lag_port;
0039
0040
0041 struct mlx5e_ch_stats *stats;
0042
0043
0044 struct mlx5e_priv *priv;
0045 struct mlx5_core_dev *mdev;
0046 struct hwtstamp_config *tstamp;
0047 DECLARE_BITMAP(state, MLX5E_PTP_STATE_NUM_STATES);
0048 };
0049
0050 static inline bool mlx5e_use_ptpsq(struct sk_buff *skb)
0051 {
0052 struct flow_keys fk;
0053
0054 if (!(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
0055 return false;
0056
0057 if (!skb_flow_dissect_flow_keys(skb, &fk, 0))
0058 return false;
0059
0060 if (fk.basic.n_proto == htons(ETH_P_1588))
0061 return true;
0062
0063 if (fk.basic.n_proto != htons(ETH_P_IP) &&
0064 fk.basic.n_proto != htons(ETH_P_IPV6))
0065 return false;
0066
0067 return (fk.basic.ip_proto == IPPROTO_UDP &&
0068 fk.ports.dst == htons(PTP_EV_PORT));
0069 }
0070
0071 int mlx5e_ptp_open(struct mlx5e_priv *priv, struct mlx5e_params *params,
0072 u8 lag_port, struct mlx5e_ptp **cp);
0073 void mlx5e_ptp_close(struct mlx5e_ptp *c);
0074 void mlx5e_ptp_activate_channel(struct mlx5e_ptp *c);
0075 void mlx5e_ptp_deactivate_channel(struct mlx5e_ptp *c);
0076 int mlx5e_ptp_get_rqn(struct mlx5e_ptp *c, u32 *rqn);
0077 int mlx5e_ptp_alloc_rx_fs(struct mlx5e_priv *priv);
0078 void mlx5e_ptp_free_rx_fs(struct mlx5e_priv *priv);
0079 int mlx5e_ptp_rx_manage_fs(struct mlx5e_priv *priv, bool set);
0080
0081 enum {
0082 MLX5E_SKB_CB_CQE_HWTSTAMP = BIT(0),
0083 MLX5E_SKB_CB_PORT_HWTSTAMP = BIT(1),
0084 };
0085
0086 void mlx5e_skb_cb_hwtstamp_handler(struct sk_buff *skb, int hwtstamp_type,
0087 ktime_t hwtstamp,
0088 struct mlx5e_ptp_cq_stats *cq_stats);
0089
0090 void mlx5e_skb_cb_hwtstamp_init(struct sk_buff *skb);
0091 #endif