Commit b0d35de4 authored by Aya Levin's avatar Aya Levin Committed by Saeed Mahameed
Browse files

net/mlx5e: Generalize PTP implementation



Following patches in the set add support for RX PTP. Rename PTP prefix
from %s/port_ptp/ptp/g to include RX PTP too.

In addition rename indication (used in statistics context) that PTP-SQ
was opened: %s/port_ptp_opened/tx_ptp_opened/g. This will simplify adding
indication that PTP-RQ was opened.

Signed-off-by: default avatarAya Levin <ayal@nvidia.com>
Signed-off-by: default avatarTariq Toukan <tariqt@nvidia.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
parent 42212d99
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -707,11 +707,11 @@ struct mlx5e_channel {
	int                        cpu;
	int                        cpu;
};
};


struct mlx5e_port_ptp;
struct mlx5e_ptp;


struct mlx5e_channels {
struct mlx5e_channels {
	struct mlx5e_channel **c;
	struct mlx5e_channel **c;
	struct mlx5e_port_ptp  *port_ptp;
	struct mlx5e_ptp      *ptp;
	unsigned int           num;
	unsigned int           num;
	struct mlx5e_params    params;
	struct mlx5e_params    params;
};
};
@@ -726,7 +726,7 @@ struct mlx5e_channel_stats {
	struct mlx5e_xdpsq_stats xsksq;
	struct mlx5e_xdpsq_stats xsksq;
} ____cacheline_aligned_in_smp;
} ____cacheline_aligned_in_smp;


struct mlx5e_port_ptp_stats {
struct mlx5e_ptp_stats {
	struct mlx5e_ch_stats ch;
	struct mlx5e_ch_stats ch;
	struct mlx5e_sq_stats sq[MLX5E_MAX_NUM_TC];
	struct mlx5e_sq_stats sq[MLX5E_MAX_NUM_TC];
	struct mlx5e_ptp_cq_stats cq[MLX5E_MAX_NUM_TC];
	struct mlx5e_ptp_cq_stats cq[MLX5E_MAX_NUM_TC];
@@ -855,10 +855,10 @@ struct mlx5e_priv {
	struct mlx5e_stats         stats;
	struct mlx5e_stats         stats;
	struct mlx5e_channel_stats channel_stats[MLX5E_MAX_NUM_CHANNELS];
	struct mlx5e_channel_stats channel_stats[MLX5E_MAX_NUM_CHANNELS];
	struct mlx5e_channel_stats trap_stats;
	struct mlx5e_channel_stats trap_stats;
	struct mlx5e_port_ptp_stats port_ptp_stats;
	struct mlx5e_ptp_stats     ptp_stats;
	u16                        max_nch;
	u16                        max_nch;
	u8                         max_opened_tc;
	u8                         max_opened_tc;
	bool                       port_ptp_opened;
	bool                       tx_ptp_opened;
	struct hwtstamp_config     tstamp;
	struct hwtstamp_config     tstamp;
	u16                        q_counter;
	u16                        q_counter;
	u16                        drop_rq_q_counter;
	u16                        drop_rq_q_counter;
+19 −20
Original line number Original line Diff line number Diff line
@@ -116,8 +116,7 @@ static bool mlx5e_ptp_poll_ts_cq(struct mlx5e_cq *cq, int budget)


static int mlx5e_ptp_napi_poll(struct napi_struct *napi, int budget)
static int mlx5e_ptp_napi_poll(struct napi_struct *napi, int budget)
{
{
	struct mlx5e_port_ptp *c = container_of(napi, struct mlx5e_port_ptp,
	struct mlx5e_ptp *c = container_of(napi, struct mlx5e_ptp, napi);
						napi);
	struct mlx5e_ch_stats *ch_stats = c->stats;
	struct mlx5e_ch_stats *ch_stats = c->stats;
	bool busy = false;
	bool busy = false;
	int work_done = 0;
	int work_done = 0;
@@ -153,7 +152,7 @@ static int mlx5e_ptp_napi_poll(struct napi_struct *napi, int budget)
	return work_done;
	return work_done;
}
}


static int mlx5e_ptp_alloc_txqsq(struct mlx5e_port_ptp *c, int txq_ix,
static int mlx5e_ptp_alloc_txqsq(struct mlx5e_ptp *c, int txq_ix,
				 struct mlx5e_params *params,
				 struct mlx5e_params *params,
				 struct mlx5e_sq_param *param,
				 struct mlx5e_sq_param *param,
				 struct mlx5e_txqsq *sq, int tc,
				 struct mlx5e_txqsq *sq, int tc,
@@ -177,7 +176,7 @@ static int mlx5e_ptp_alloc_txqsq(struct mlx5e_port_ptp *c, int txq_ix,
	sq->uar_map   = mdev->mlx5e_res.hw_objs.bfreg.map;
	sq->uar_map   = mdev->mlx5e_res.hw_objs.bfreg.map;
	sq->min_inline_mode = params->tx_min_inline_mode;
	sq->min_inline_mode = params->tx_min_inline_mode;
	sq->hw_mtu    = MLX5E_SW2HW_MTU(params, params->sw_mtu);
	sq->hw_mtu    = MLX5E_SW2HW_MTU(params, params->sw_mtu);
	sq->stats     = &c->priv->port_ptp_stats.sq[tc];
	sq->stats     = &c->priv->ptp_stats.sq[tc];
	sq->ptpsq     = ptpsq;
	sq->ptpsq     = ptpsq;
	INIT_WORK(&sq->recover_work, mlx5e_tx_err_cqe_work);
	INIT_WORK(&sq->recover_work, mlx5e_tx_err_cqe_work);
	if (!MLX5_CAP_ETH(mdev, wqe_vlan_insert))
	if (!MLX5_CAP_ETH(mdev, wqe_vlan_insert))
@@ -241,7 +240,7 @@ static void mlx5e_ptp_free_traffic_db(struct mlx5e_skb_fifo *skb_fifo)
	kvfree(skb_fifo->fifo);
	kvfree(skb_fifo->fifo);
}
}


static int mlx5e_ptp_open_txqsq(struct mlx5e_port_ptp *c, u32 tisn,
static int mlx5e_ptp_open_txqsq(struct mlx5e_ptp *c, u32 tisn,
				int txq_ix, struct mlx5e_ptp_params *cparams,
				int txq_ix, struct mlx5e_ptp_params *cparams,
				int tc, struct mlx5e_ptpsq *ptpsq)
				int tc, struct mlx5e_ptpsq *ptpsq)
{
{
@@ -291,7 +290,7 @@ static void mlx5e_ptp_close_txqsq(struct mlx5e_ptpsq *ptpsq)
	mlx5e_free_txqsq(sq);
	mlx5e_free_txqsq(sq);
}
}


static int mlx5e_ptp_open_txqsqs(struct mlx5e_port_ptp *c,
static int mlx5e_ptp_open_txqsqs(struct mlx5e_ptp *c,
				 struct mlx5e_ptp_params *cparams)
				 struct mlx5e_ptp_params *cparams)
{
{
	struct mlx5e_params *params = &cparams->params;
	struct mlx5e_params *params = &cparams->params;
@@ -319,7 +318,7 @@ static int mlx5e_ptp_open_txqsqs(struct mlx5e_port_ptp *c,
	return err;
	return err;
}
}


static void mlx5e_ptp_close_txqsqs(struct mlx5e_port_ptp *c)
static void mlx5e_ptp_close_txqsqs(struct mlx5e_ptp *c)
{
{
	int tc;
	int tc;


@@ -327,7 +326,7 @@ static void mlx5e_ptp_close_txqsqs(struct mlx5e_port_ptp *c)
		mlx5e_ptp_close_txqsq(&c->ptpsq[tc]);
		mlx5e_ptp_close_txqsq(&c->ptpsq[tc]);
}
}


static int mlx5e_ptp_open_cqs(struct mlx5e_port_ptp *c,
static int mlx5e_ptp_open_cqs(struct mlx5e_ptp *c,
			      struct mlx5e_ptp_params *cparams)
			      struct mlx5e_ptp_params *cparams)
{
{
	struct mlx5e_params *params = &cparams->params;
	struct mlx5e_params *params = &cparams->params;
@@ -360,7 +359,7 @@ static int mlx5e_ptp_open_cqs(struct mlx5e_port_ptp *c,
		if (err)
		if (err)
			goto out_err_ts_cq;
			goto out_err_ts_cq;


		ptpsq->cq_stats = &c->priv->port_ptp_stats.cq[tc];
		ptpsq->cq_stats = &c->priv->ptp_stats.cq[tc];
	}
	}


	return 0;
	return 0;
@@ -376,7 +375,7 @@ static int mlx5e_ptp_open_cqs(struct mlx5e_port_ptp *c,
	return err;
	return err;
}
}


static void mlx5e_ptp_close_cqs(struct mlx5e_port_ptp *c)
static void mlx5e_ptp_close_cqs(struct mlx5e_ptp *c)
{
{
	int tc;
	int tc;


@@ -402,7 +401,7 @@ static void mlx5e_ptp_build_sq_param(struct mlx5_core_dev *mdev,
	mlx5e_build_tx_cq_param(mdev, params, &param->cqp);
	mlx5e_build_tx_cq_param(mdev, params, &param->cqp);
}
}


static void mlx5e_ptp_build_params(struct mlx5e_port_ptp *c,
static void mlx5e_ptp_build_params(struct mlx5e_ptp *c,
				   struct mlx5e_ptp_params *cparams,
				   struct mlx5e_ptp_params *cparams,
				   struct mlx5e_params *orig)
				   struct mlx5e_params *orig)
{
{
@@ -420,7 +419,7 @@ static void mlx5e_ptp_build_params(struct mlx5e_port_ptp *c,
	mlx5e_ptp_build_sq_param(c->mdev, params, &cparams->txq_sq_param);
	mlx5e_ptp_build_sq_param(c->mdev, params, &cparams->txq_sq_param);
}
}


static int mlx5e_ptp_open_queues(struct mlx5e_port_ptp *c,
static int mlx5e_ptp_open_queues(struct mlx5e_ptp *c,
				 struct mlx5e_ptp_params *cparams)
				 struct mlx5e_ptp_params *cparams)
{
{
	int err;
	int err;
@@ -441,19 +440,19 @@ static int mlx5e_ptp_open_queues(struct mlx5e_port_ptp *c,
	return err;
	return err;
}
}


static void mlx5e_ptp_close_queues(struct mlx5e_port_ptp *c)
static void mlx5e_ptp_close_queues(struct mlx5e_ptp *c)
{
{
	mlx5e_ptp_close_txqsqs(c);
	mlx5e_ptp_close_txqsqs(c);
	mlx5e_ptp_close_cqs(c);
	mlx5e_ptp_close_cqs(c);
}
}


int mlx5e_port_ptp_open(struct mlx5e_priv *priv, struct mlx5e_params *params,
int mlx5e_ptp_open(struct mlx5e_priv *priv, struct mlx5e_params *params,
			u8 lag_port, struct mlx5e_port_ptp **cp)
		   u8 lag_port, struct mlx5e_ptp **cp)
{
{
	struct net_device *netdev = priv->netdev;
	struct net_device *netdev = priv->netdev;
	struct mlx5_core_dev *mdev = priv->mdev;
	struct mlx5_core_dev *mdev = priv->mdev;
	struct mlx5e_ptp_params *cparams;
	struct mlx5e_ptp_params *cparams;
	struct mlx5e_port_ptp *c;
	struct mlx5e_ptp *c;
	unsigned int irq;
	unsigned int irq;
	int err;
	int err;
	int eqn;
	int eqn;
@@ -475,7 +474,7 @@ int mlx5e_port_ptp_open(struct mlx5e_priv *priv, struct mlx5e_params *params,
	c->netdev   = priv->netdev;
	c->netdev   = priv->netdev;
	c->mkey_be  = cpu_to_be32(priv->mdev->mlx5e_res.hw_objs.mkey.key);
	c->mkey_be  = cpu_to_be32(priv->mdev->mlx5e_res.hw_objs.mkey.key);
	c->num_tc   = params->num_tc;
	c->num_tc   = params->num_tc;
	c->stats    = &priv->port_ptp_stats.ch;
	c->stats    = &priv->ptp_stats.ch;
	c->lag_port = lag_port;
	c->lag_port = lag_port;


	netif_napi_add(netdev, &c->napi, mlx5e_ptp_napi_poll, 64);
	netif_napi_add(netdev, &c->napi, mlx5e_ptp_napi_poll, 64);
@@ -500,7 +499,7 @@ int mlx5e_port_ptp_open(struct mlx5e_priv *priv, struct mlx5e_params *params,
	return err;
	return err;
}
}


void mlx5e_port_ptp_close(struct mlx5e_port_ptp *c)
void mlx5e_ptp_close(struct mlx5e_ptp *c)
{
{
	mlx5e_ptp_close_queues(c);
	mlx5e_ptp_close_queues(c);
	netif_napi_del(&c->napi);
	netif_napi_del(&c->napi);
@@ -508,7 +507,7 @@ void mlx5e_port_ptp_close(struct mlx5e_port_ptp *c)
	kvfree(c);
	kvfree(c);
}
}


void mlx5e_ptp_activate_channel(struct mlx5e_port_ptp *c)
void mlx5e_ptp_activate_channel(struct mlx5e_ptp *c)
{
{
	int tc;
	int tc;


@@ -518,7 +517,7 @@ void mlx5e_ptp_activate_channel(struct mlx5e_port_ptp *c)
		mlx5e_activate_txqsq(&c->ptpsq[tc].txqsq);
		mlx5e_activate_txqsq(&c->ptpsq[tc].txqsq);
}
}


void mlx5e_ptp_deactivate_channel(struct mlx5e_port_ptp *c)
void mlx5e_ptp_deactivate_channel(struct mlx5e_ptp *c)
{
{
	int tc;
	int tc;


+6 −6
Original line number Original line Diff line number Diff line
@@ -17,7 +17,7 @@ struct mlx5e_ptpsq {
	struct mlx5e_ptp_cq_stats *cq_stats;
	struct mlx5e_ptp_cq_stats *cq_stats;
};
};


struct mlx5e_port_ptp {
struct mlx5e_ptp {
	/* data path */
	/* data path */
	struct mlx5e_ptpsq         ptpsq[MLX5E_MAX_NUM_TC];
	struct mlx5e_ptpsq         ptpsq[MLX5E_MAX_NUM_TC];
	struct napi_struct         napi;
	struct napi_struct         napi;
@@ -43,11 +43,11 @@ struct mlx5e_ptp_params {
	struct mlx5e_sq_param      txq_sq_param;
	struct mlx5e_sq_param      txq_sq_param;
};
};


int mlx5e_port_ptp_open(struct mlx5e_priv *priv, struct mlx5e_params *params,
int mlx5e_ptp_open(struct mlx5e_priv *priv, struct mlx5e_params *params,
			u8 lag_port, struct mlx5e_port_ptp **cp);
		   u8 lag_port, struct mlx5e_ptp **cp);
void mlx5e_port_ptp_close(struct mlx5e_port_ptp *c);
void mlx5e_ptp_close(struct mlx5e_ptp *c);
void mlx5e_ptp_activate_channel(struct mlx5e_port_ptp *c);
void mlx5e_ptp_activate_channel(struct mlx5e_ptp *c);
void mlx5e_ptp_deactivate_channel(struct mlx5e_port_ptp *c);
void mlx5e_ptp_deactivate_channel(struct mlx5e_ptp *c);


enum {
enum {
	MLX5E_SKB_CB_CQE_HWTSTAMP  = BIT(0),
	MLX5E_SKB_CB_CQE_HWTSTAMP  = BIT(0),
+4 −4
Original line number Original line Diff line number Diff line
@@ -315,8 +315,8 @@ mlx5e_tx_reporter_diagnose_common_config(struct devlink_health_reporter *reporte
	if (err)
	if (err)
		return err;
		return err;


	generic_ptpsq = priv->channels.port_ptp ?
	generic_ptpsq = priv->channels.ptp ?
			&priv->channels.port_ptp->ptpsq[0] :
			&priv->channels.ptp->ptpsq[0] :
			NULL;
			NULL;
	if (!generic_ptpsq)
	if (!generic_ptpsq)
		goto out;
		goto out;
@@ -346,7 +346,7 @@ static int mlx5e_tx_reporter_diagnose(struct devlink_health_reporter *reporter,
				      struct netlink_ext_ack *extack)
				      struct netlink_ext_ack *extack)
{
{
	struct mlx5e_priv *priv = devlink_health_reporter_priv(reporter);
	struct mlx5e_priv *priv = devlink_health_reporter_priv(reporter);
	struct mlx5e_port_ptp *ptp_ch = priv->channels.port_ptp;
	struct mlx5e_ptp *ptp_ch = priv->channels.ptp;


	int i, tc, err = 0;
	int i, tc, err = 0;


@@ -460,7 +460,7 @@ static int mlx5e_tx_reporter_dump_sq(struct mlx5e_priv *priv, struct devlink_fms
static int mlx5e_tx_reporter_dump_all_sqs(struct mlx5e_priv *priv,
static int mlx5e_tx_reporter_dump_all_sqs(struct mlx5e_priv *priv,
					  struct devlink_fmsg *fmsg)
					  struct devlink_fmsg *fmsg)
{
{
	struct mlx5e_port_ptp *ptp_ch = priv->channels.port_ptp;
	struct mlx5e_ptp *ptp_ch = priv->channels.ptp;
	struct mlx5_rsc_key key = {};
	struct mlx5_rsc_key key = {};
	int i, tc, err;
	int i, tc, err;


+1 −1
Original line number Original line Diff line number Diff line
@@ -2032,7 +2032,7 @@ static int set_pflag_tx_port_ts(struct net_device *netdev, bool enable)
					 mlx5e_num_channels_changed_ctx, NULL);
					 mlx5e_num_channels_changed_ctx, NULL);
out:
out:
	if (!err)
	if (!err)
		priv->port_ptp_opened = true;
		priv->tx_ptp_opened = true;


	return err;
	return err;
}
}
Loading