1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 // Copyright (c) 2020 Mellanox Technologies
7 #include "en/fs_tt_redirect.h"
10 struct mlx5_flow_handle *l2_rule;
11 struct mlx5_flow_handle *udp_v4_rule;
12 struct mlx5_flow_handle *udp_v6_rule;
16 #define MLX5E_PTP_CHANNEL_IX 0
18 struct mlx5e_ptp_params {
19 struct mlx5e_params params;
20 struct mlx5e_sq_param txq_sq_param;
21 struct mlx5e_rq_param rq_param;
24 struct mlx5e_skb_cb_hwtstamp {
26 ktime_t port_hwtstamp;
29 void mlx5e_skb_cb_hwtstamp_init(struct sk_buff *skb)
31 memset(skb->cb, 0, sizeof(struct mlx5e_skb_cb_hwtstamp));
34 static struct mlx5e_skb_cb_hwtstamp *mlx5e_skb_cb_get_hwts(struct sk_buff *skb)
36 BUILD_BUG_ON(sizeof(struct mlx5e_skb_cb_hwtstamp) > sizeof(skb->cb));
37 return (struct mlx5e_skb_cb_hwtstamp *)skb->cb;
40 static void mlx5e_skb_cb_hwtstamp_tx(struct sk_buff *skb,
41 struct mlx5e_ptp_cq_stats *cq_stats)
43 struct skb_shared_hwtstamps hwts = {};
46 diff = abs(mlx5e_skb_cb_get_hwts(skb)->port_hwtstamp -
47 mlx5e_skb_cb_get_hwts(skb)->cqe_hwtstamp);
49 /* Maximal allowed diff is 1 / 128 second */
50 if (diff > (NSEC_PER_SEC >> 7)) {
52 cq_stats->abort_abs_diff_ns += diff;
56 hwts.hwtstamp = mlx5e_skb_cb_get_hwts(skb)->port_hwtstamp;
57 skb_tstamp_tx(skb, &hwts);
60 void mlx5e_skb_cb_hwtstamp_handler(struct sk_buff *skb, int hwtstamp_type,
62 struct mlx5e_ptp_cq_stats *cq_stats)
64 switch (hwtstamp_type) {
65 case (MLX5E_SKB_CB_CQE_HWTSTAMP):
66 mlx5e_skb_cb_get_hwts(skb)->cqe_hwtstamp = hwtstamp;
68 case (MLX5E_SKB_CB_PORT_HWTSTAMP):
69 mlx5e_skb_cb_get_hwts(skb)->port_hwtstamp = hwtstamp;
73 /* If both CQEs arrive, check and report the port tstamp, and clear skb cb as
74 * skb soon to be released.
76 if (!mlx5e_skb_cb_get_hwts(skb)->cqe_hwtstamp ||
77 !mlx5e_skb_cb_get_hwts(skb)->port_hwtstamp)
80 mlx5e_skb_cb_hwtstamp_tx(skb, cq_stats);
81 memset(skb->cb, 0, sizeof(struct mlx5e_skb_cb_hwtstamp));
84 static void mlx5e_ptp_handle_ts_cqe(struct mlx5e_ptpsq *ptpsq,
85 struct mlx5_cqe64 *cqe,
88 struct sk_buff *skb = mlx5e_skb_fifo_pop(&ptpsq->skb_fifo);
89 struct mlx5e_txqsq *sq = &ptpsq->txqsq;
92 if (unlikely(MLX5E_RX_ERR_CQE(cqe))) {
93 ptpsq->cq_stats->err_cqe++;
97 hwtstamp = mlx5e_cqe_ts_to_ns(sq->ptp_cyc2time, sq->clock, get_cqe_ts(cqe));
98 mlx5e_skb_cb_hwtstamp_handler(skb, MLX5E_SKB_CB_PORT_HWTSTAMP,
99 hwtstamp, ptpsq->cq_stats);
100 ptpsq->cq_stats->cqe++;
103 napi_consume_skb(skb, budget);
106 static bool mlx5e_ptp_poll_ts_cq(struct mlx5e_cq *cq, int budget)
108 struct mlx5e_ptpsq *ptpsq = container_of(cq, struct mlx5e_ptpsq, ts_cq);
109 struct mlx5_cqwq *cqwq = &cq->wq;
110 struct mlx5_cqe64 *cqe;
113 if (unlikely(!test_bit(MLX5E_SQ_STATE_ENABLED, &ptpsq->txqsq.state)))
116 cqe = mlx5_cqwq_get_cqe(cqwq);
123 mlx5e_ptp_handle_ts_cqe(ptpsq, cqe, budget);
124 } while ((++work_done < budget) && (cqe = mlx5_cqwq_get_cqe(cqwq)));
126 mlx5_cqwq_update_db_record(cqwq);
128 /* ensure cq space is freed before enabling more cqes */
131 return work_done == budget;
134 static int mlx5e_ptp_napi_poll(struct napi_struct *napi, int budget)
136 struct mlx5e_ptp *c = container_of(napi, struct mlx5e_ptp, napi);
137 struct mlx5e_ch_stats *ch_stats = c->stats;
138 struct mlx5e_rq *rq = &c->rq;
147 if (test_bit(MLX5E_PTP_STATE_TX, c->state)) {
148 for (i = 0; i < c->num_tc; i++) {
149 busy |= mlx5e_poll_tx_cq(&c->ptpsq[i].txqsq.cq, budget);
150 busy |= mlx5e_ptp_poll_ts_cq(&c->ptpsq[i].ts_cq, budget);
153 if (test_bit(MLX5E_PTP_STATE_RX, c->state) && likely(budget)) {
154 work_done = mlx5e_poll_rx_cq(&rq->cq, budget);
155 busy |= work_done == budget;
156 busy |= INDIRECT_CALL_2(rq->post_wqes,
157 mlx5e_post_rx_mpwqes,
167 if (unlikely(!napi_complete_done(napi, work_done)))
172 if (test_bit(MLX5E_PTP_STATE_TX, c->state)) {
173 for (i = 0; i < c->num_tc; i++) {
174 mlx5e_cq_arm(&c->ptpsq[i].txqsq.cq);
175 mlx5e_cq_arm(&c->ptpsq[i].ts_cq);
178 if (test_bit(MLX5E_PTP_STATE_RX, c->state))
179 mlx5e_cq_arm(&rq->cq);
187 static int mlx5e_ptp_alloc_txqsq(struct mlx5e_ptp *c, int txq_ix,
188 struct mlx5e_params *params,
189 struct mlx5e_sq_param *param,
190 struct mlx5e_txqsq *sq, int tc,
191 struct mlx5e_ptpsq *ptpsq)
193 void *sqc_wq = MLX5_ADDR_OF(sqc, param->sqc, wq);
194 struct mlx5_core_dev *mdev = c->mdev;
195 struct mlx5_wq_cyc *wq = &sq->wq;
200 sq->tstamp = c->tstamp;
201 sq->clock = &mdev->clock;
202 sq->mkey_be = c->mkey_be;
203 sq->netdev = c->netdev;
206 sq->ch_ix = MLX5E_PTP_CHANNEL_IX;
208 sq->uar_map = mdev->mlx5e_res.hw_objs.bfreg.map;
209 sq->min_inline_mode = params->tx_min_inline_mode;
210 sq->hw_mtu = MLX5E_SW2HW_MTU(params, params->sw_mtu);
211 sq->stats = &c->priv->ptp_stats.sq[tc];
213 INIT_WORK(&sq->recover_work, mlx5e_tx_err_cqe_work);
214 if (!MLX5_CAP_ETH(mdev, wqe_vlan_insert))
215 set_bit(MLX5E_SQ_STATE_VLAN_NEED_L2_INLINE, &sq->state);
216 sq->stop_room = param->stop_room;
217 sq->ptp_cyc2time = mlx5_sq_ts_translator(mdev);
219 node = dev_to_node(mlx5_core_dma_dev(mdev));
221 param->wq.db_numa_node = node;
222 err = mlx5_wq_cyc_create(mdev, ¶m->wq, sqc_wq, wq, &sq->wq_ctrl);
225 wq->db = &wq->db[MLX5_SND_DBR];
227 err = mlx5e_alloc_txqsq_db(sq, node);
229 goto err_sq_wq_destroy;
234 mlx5_wq_destroy(&sq->wq_ctrl);
239 static void mlx5e_ptp_destroy_sq(struct mlx5_core_dev *mdev, u32 sqn)
241 mlx5_core_destroy_sq(mdev, sqn);
244 static int mlx5e_ptp_alloc_traffic_db(struct mlx5e_ptpsq *ptpsq, int numa)
246 int wq_sz = mlx5_wq_cyc_get_size(&ptpsq->txqsq.wq);
248 ptpsq->skb_fifo.fifo = kvzalloc_node(array_size(wq_sz, sizeof(*ptpsq->skb_fifo.fifo)),
250 if (!ptpsq->skb_fifo.fifo)
253 ptpsq->skb_fifo.pc = &ptpsq->skb_fifo_pc;
254 ptpsq->skb_fifo.cc = &ptpsq->skb_fifo_cc;
255 ptpsq->skb_fifo.mask = wq_sz - 1;
260 static void mlx5e_ptp_drain_skb_fifo(struct mlx5e_skb_fifo *skb_fifo)
262 while (*skb_fifo->pc != *skb_fifo->cc) {
263 struct sk_buff *skb = mlx5e_skb_fifo_pop(skb_fifo);
265 dev_kfree_skb_any(skb);
269 static void mlx5e_ptp_free_traffic_db(struct mlx5e_skb_fifo *skb_fifo)
271 mlx5e_ptp_drain_skb_fifo(skb_fifo);
272 kvfree(skb_fifo->fifo);
275 static int mlx5e_ptp_open_txqsq(struct mlx5e_ptp *c, u32 tisn,
276 int txq_ix, struct mlx5e_ptp_params *cparams,
277 int tc, struct mlx5e_ptpsq *ptpsq)
279 struct mlx5e_sq_param *sqp = &cparams->txq_sq_param;
280 struct mlx5e_txqsq *txqsq = &ptpsq->txqsq;
281 struct mlx5e_create_sq_param csp = {};
284 err = mlx5e_ptp_alloc_txqsq(c, txq_ix, &cparams->params, sqp,
291 csp.cqn = txqsq->cq.mcq.cqn;
292 csp.wq_ctrl = &txqsq->wq_ctrl;
293 csp.min_inline_mode = txqsq->min_inline_mode;
294 csp.ts_cqe_to_dest_cqn = ptpsq->ts_cq.mcq.cqn;
296 err = mlx5e_create_sq_rdy(c->mdev, sqp, &csp, 0, &txqsq->sqn);
300 err = mlx5e_ptp_alloc_traffic_db(ptpsq,
301 dev_to_node(mlx5_core_dma_dev(c->mdev)));
308 mlx5e_free_txqsq(txqsq);
313 static void mlx5e_ptp_close_txqsq(struct mlx5e_ptpsq *ptpsq)
315 struct mlx5e_txqsq *sq = &ptpsq->txqsq;
316 struct mlx5_core_dev *mdev = sq->mdev;
318 mlx5e_ptp_free_traffic_db(&ptpsq->skb_fifo);
319 cancel_work_sync(&sq->recover_work);
320 mlx5e_ptp_destroy_sq(mdev, sq->sqn);
321 mlx5e_free_txqsq_descs(sq);
322 mlx5e_free_txqsq(sq);
325 static int mlx5e_ptp_open_txqsqs(struct mlx5e_ptp *c,
326 struct mlx5e_ptp_params *cparams)
328 struct mlx5e_params *params = &cparams->params;
329 u8 num_tc = mlx5e_get_dcb_num_tc(params);
334 ix_base = num_tc * params->num_channels;
336 for (tc = 0; tc < num_tc; tc++) {
337 int txq_ix = ix_base + tc;
339 err = mlx5e_ptp_open_txqsq(c, c->priv->tisn[c->lag_port][tc], txq_ix,
340 cparams, tc, &c->ptpsq[tc]);
348 for (--tc; tc >= 0; tc--)
349 mlx5e_ptp_close_txqsq(&c->ptpsq[tc]);
354 static void mlx5e_ptp_close_txqsqs(struct mlx5e_ptp *c)
358 for (tc = 0; tc < c->num_tc; tc++)
359 mlx5e_ptp_close_txqsq(&c->ptpsq[tc]);
362 static int mlx5e_ptp_open_tx_cqs(struct mlx5e_ptp *c,
363 struct mlx5e_ptp_params *cparams)
365 struct mlx5e_params *params = &cparams->params;
366 struct mlx5e_create_cq_param ccp = {};
367 struct dim_cq_moder ptp_moder = {};
368 struct mlx5e_cq_param *cq_param;
373 num_tc = mlx5e_get_dcb_num_tc(params);
375 ccp.node = dev_to_node(mlx5_core_dma_dev(c->mdev));
376 ccp.ch_stats = c->stats;
378 ccp.ix = MLX5E_PTP_CHANNEL_IX;
380 cq_param = &cparams->txq_sq_param.cqp;
382 for (tc = 0; tc < num_tc; tc++) {
383 struct mlx5e_cq *cq = &c->ptpsq[tc].txqsq.cq;
385 err = mlx5e_open_cq(c->priv, ptp_moder, cq_param, &ccp, cq);
387 goto out_err_txqsq_cq;
390 for (tc = 0; tc < num_tc; tc++) {
391 struct mlx5e_cq *cq = &c->ptpsq[tc].ts_cq;
392 struct mlx5e_ptpsq *ptpsq = &c->ptpsq[tc];
394 err = mlx5e_open_cq(c->priv, ptp_moder, cq_param, &ccp, cq);
398 ptpsq->cq_stats = &c->priv->ptp_stats.cq[tc];
404 for (--tc; tc >= 0; tc--)
405 mlx5e_close_cq(&c->ptpsq[tc].ts_cq);
408 for (--tc; tc >= 0; tc--)
409 mlx5e_close_cq(&c->ptpsq[tc].txqsq.cq);
414 static int mlx5e_ptp_open_rx_cq(struct mlx5e_ptp *c,
415 struct mlx5e_ptp_params *cparams)
417 struct mlx5e_create_cq_param ccp = {};
418 struct dim_cq_moder ptp_moder = {};
419 struct mlx5e_cq_param *cq_param;
420 struct mlx5e_cq *cq = &c->rq.cq;
422 ccp.node = dev_to_node(mlx5_core_dma_dev(c->mdev));
423 ccp.ch_stats = c->stats;
425 ccp.ix = MLX5E_PTP_CHANNEL_IX;
427 cq_param = &cparams->rq_param.cqp;
429 return mlx5e_open_cq(c->priv, ptp_moder, cq_param, &ccp, cq);
432 static void mlx5e_ptp_close_tx_cqs(struct mlx5e_ptp *c)
436 for (tc = 0; tc < c->num_tc; tc++)
437 mlx5e_close_cq(&c->ptpsq[tc].ts_cq);
439 for (tc = 0; tc < c->num_tc; tc++)
440 mlx5e_close_cq(&c->ptpsq[tc].txqsq.cq);
443 static void mlx5e_ptp_build_sq_param(struct mlx5_core_dev *mdev,
444 struct mlx5e_params *params,
445 struct mlx5e_sq_param *param)
447 void *sqc = param->sqc;
450 mlx5e_build_sq_param_common(mdev, param);
452 wq = MLX5_ADDR_OF(sqc, sqc, wq);
453 MLX5_SET(wq, wq, log_wq_sz, params->log_sq_size);
454 param->stop_room = mlx5e_stop_room_for_wqe(MLX5_SEND_WQE_MAX_WQEBBS);
455 mlx5e_build_tx_cq_param(mdev, params, ¶m->cqp);
458 static void mlx5e_ptp_build_rq_param(struct mlx5_core_dev *mdev,
459 struct net_device *netdev,
461 struct mlx5e_ptp_params *ptp_params)
463 struct mlx5e_rq_param *rq_params = &ptp_params->rq_param;
464 struct mlx5e_params *params = &ptp_params->params;
466 params->rq_wq_type = MLX5_WQ_TYPE_CYCLIC;
467 mlx5e_init_rq_type_params(mdev, params);
468 params->sw_mtu = netdev->max_mtu;
469 mlx5e_build_rq_param(mdev, params, NULL, q_counter, rq_params);
472 static void mlx5e_ptp_build_params(struct mlx5e_ptp *c,
473 struct mlx5e_ptp_params *cparams,
474 struct mlx5e_params *orig)
476 struct mlx5e_params *params = &cparams->params;
478 params->tx_min_inline_mode = orig->tx_min_inline_mode;
479 params->num_channels = orig->num_channels;
480 params->hard_mtu = orig->hard_mtu;
481 params->sw_mtu = orig->sw_mtu;
482 params->mqprio = orig->mqprio;
485 if (test_bit(MLX5E_PTP_STATE_TX, c->state)) {
486 params->log_sq_size = orig->log_sq_size;
487 mlx5e_ptp_build_sq_param(c->mdev, params, &cparams->txq_sq_param);
490 if (test_bit(MLX5E_PTP_STATE_RX, c->state)) {
491 params->vlan_strip_disable = orig->vlan_strip_disable;
492 mlx5e_ptp_build_rq_param(c->mdev, c->netdev, c->priv->q_counter, cparams);
496 static int mlx5e_init_ptp_rq(struct mlx5e_ptp *c, struct mlx5e_params *params,
499 struct mlx5_core_dev *mdev = c->mdev;
500 struct mlx5e_priv *priv = c->priv;
503 rq->wq_type = params->rq_wq_type;
505 rq->netdev = priv->netdev;
507 rq->clock = &mdev->clock;
508 rq->tstamp = &priv->tstamp;
510 rq->hw_mtu = MLX5E_SW2HW_MTU(params, params->sw_mtu);
511 rq->stats = &c->priv->ptp_stats.rq;
512 rq->ptp_cyc2time = mlx5_rq_ts_translator(mdev);
513 err = mlx5e_rq_set_handlers(rq, params, false);
517 return xdp_rxq_info_reg(&rq->xdp_rxq, rq->netdev, rq->ix, 0);
520 static int mlx5e_ptp_open_rq(struct mlx5e_ptp *c, struct mlx5e_params *params,
521 struct mlx5e_rq_param *rq_param)
523 int node = dev_to_node(c->mdev->device);
526 err = mlx5e_init_ptp_rq(c, params, &c->rq);
530 return mlx5e_open_rq(params, rq_param, NULL, node, &c->rq);
533 static int mlx5e_ptp_open_queues(struct mlx5e_ptp *c,
534 struct mlx5e_ptp_params *cparams)
538 if (test_bit(MLX5E_PTP_STATE_TX, c->state)) {
539 err = mlx5e_ptp_open_tx_cqs(c, cparams);
543 err = mlx5e_ptp_open_txqsqs(c, cparams);
547 if (test_bit(MLX5E_PTP_STATE_RX, c->state)) {
548 err = mlx5e_ptp_open_rx_cq(c, cparams);
552 err = mlx5e_ptp_open_rq(c, &cparams->params, &cparams->rq_param);
559 if (test_bit(MLX5E_PTP_STATE_RX, c->state))
560 mlx5e_close_cq(&c->rq.cq);
562 if (test_bit(MLX5E_PTP_STATE_TX, c->state))
563 mlx5e_ptp_close_txqsqs(c);
565 if (test_bit(MLX5E_PTP_STATE_TX, c->state))
566 mlx5e_ptp_close_tx_cqs(c);
571 static void mlx5e_ptp_close_queues(struct mlx5e_ptp *c)
573 if (test_bit(MLX5E_PTP_STATE_RX, c->state)) {
574 mlx5e_close_rq(&c->rq);
575 mlx5e_close_cq(&c->rq.cq);
577 if (test_bit(MLX5E_PTP_STATE_TX, c->state)) {
578 mlx5e_ptp_close_txqsqs(c);
579 mlx5e_ptp_close_tx_cqs(c);
583 static int mlx5e_ptp_set_state(struct mlx5e_ptp *c, struct mlx5e_params *params)
585 if (MLX5E_GET_PFLAG(params, MLX5E_PFLAG_TX_PORT_TS))
586 __set_bit(MLX5E_PTP_STATE_TX, c->state);
589 __set_bit(MLX5E_PTP_STATE_RX, c->state);
591 return bitmap_empty(c->state, MLX5E_PTP_STATE_NUM_STATES) ? -EINVAL : 0;
594 static void mlx5e_ptp_rx_unset_fs(struct mlx5e_priv *priv)
596 struct mlx5e_ptp_fs *ptp_fs = priv->fs.ptp_fs;
601 mlx5e_fs_tt_redirect_del_rule(ptp_fs->l2_rule);
602 mlx5e_fs_tt_redirect_any_destroy(priv);
604 mlx5e_fs_tt_redirect_del_rule(ptp_fs->udp_v6_rule);
605 mlx5e_fs_tt_redirect_del_rule(ptp_fs->udp_v4_rule);
606 mlx5e_fs_tt_redirect_udp_destroy(priv);
607 ptp_fs->valid = false;
610 static int mlx5e_ptp_rx_set_fs(struct mlx5e_priv *priv)
612 u32 tirn = mlx5e_rx_res_get_tirn_ptp(priv->rx_res);
613 struct mlx5e_ptp_fs *ptp_fs = priv->fs.ptp_fs;
614 struct mlx5_flow_handle *rule;
620 err = mlx5e_fs_tt_redirect_udp_create(priv);
624 rule = mlx5e_fs_tt_redirect_udp_add_rule(priv, MLX5_TT_IPV4_UDP,
628 goto out_destroy_fs_udp;
630 ptp_fs->udp_v4_rule = rule;
632 rule = mlx5e_fs_tt_redirect_udp_add_rule(priv, MLX5_TT_IPV6_UDP,
636 goto out_destroy_udp_v4_rule;
638 ptp_fs->udp_v6_rule = rule;
640 err = mlx5e_fs_tt_redirect_any_create(priv);
642 goto out_destroy_udp_v6_rule;
644 rule = mlx5e_fs_tt_redirect_any_add_rule(priv, tirn, ETH_P_1588);
647 goto out_destroy_fs_any;
649 ptp_fs->l2_rule = rule;
650 ptp_fs->valid = true;
655 mlx5e_fs_tt_redirect_any_destroy(priv);
656 out_destroy_udp_v6_rule:
657 mlx5e_fs_tt_redirect_del_rule(ptp_fs->udp_v6_rule);
658 out_destroy_udp_v4_rule:
659 mlx5e_fs_tt_redirect_del_rule(ptp_fs->udp_v4_rule);
661 mlx5e_fs_tt_redirect_udp_destroy(priv);
666 int mlx5e_ptp_open(struct mlx5e_priv *priv, struct mlx5e_params *params,
667 u8 lag_port, struct mlx5e_ptp **cp)
669 struct net_device *netdev = priv->netdev;
670 struct mlx5_core_dev *mdev = priv->mdev;
671 struct mlx5e_ptp_params *cparams;
676 c = kvzalloc_node(sizeof(*c), GFP_KERNEL, dev_to_node(mlx5_core_dma_dev(mdev)));
677 cparams = kvzalloc(sizeof(*cparams), GFP_KERNEL);
682 c->mdev = priv->mdev;
683 c->tstamp = &priv->tstamp;
684 c->pdev = mlx5_core_dma_dev(priv->mdev);
685 c->netdev = priv->netdev;
686 c->mkey_be = cpu_to_be32(priv->mdev->mlx5e_res.hw_objs.mkey.key);
687 c->num_tc = mlx5e_get_dcb_num_tc(params);
688 c->stats = &priv->ptp_stats.ch;
689 c->lag_port = lag_port;
691 err = mlx5e_ptp_set_state(c, params);
695 netif_napi_add(netdev, &c->napi, mlx5e_ptp_napi_poll, 64);
697 mlx5e_ptp_build_params(c, cparams, params);
699 err = mlx5e_ptp_open_queues(c, cparams);
703 if (test_bit(MLX5E_PTP_STATE_RX, c->state))
704 priv->rx_ptp_opened = true;
713 netif_napi_del(&c->napi);
720 void mlx5e_ptp_close(struct mlx5e_ptp *c)
722 mlx5e_ptp_close_queues(c);
723 netif_napi_del(&c->napi);
728 void mlx5e_ptp_activate_channel(struct mlx5e_ptp *c)
732 napi_enable(&c->napi);
734 if (test_bit(MLX5E_PTP_STATE_TX, c->state)) {
735 for (tc = 0; tc < c->num_tc; tc++)
736 mlx5e_activate_txqsq(&c->ptpsq[tc].txqsq);
738 if (test_bit(MLX5E_PTP_STATE_RX, c->state)) {
739 mlx5e_ptp_rx_set_fs(c->priv);
740 mlx5e_activate_rq(&c->rq);
744 void mlx5e_ptp_deactivate_channel(struct mlx5e_ptp *c)
748 if (test_bit(MLX5E_PTP_STATE_RX, c->state))
749 mlx5e_deactivate_rq(&c->rq);
751 if (test_bit(MLX5E_PTP_STATE_TX, c->state)) {
752 for (tc = 0; tc < c->num_tc; tc++)
753 mlx5e_deactivate_txqsq(&c->ptpsq[tc].txqsq);
756 napi_disable(&c->napi);
759 int mlx5e_ptp_get_rqn(struct mlx5e_ptp *c, u32 *rqn)
761 if (!c || !test_bit(MLX5E_PTP_STATE_RX, c->state))
768 int mlx5e_ptp_alloc_rx_fs(struct mlx5e_priv *priv)
770 struct mlx5e_ptp_fs *ptp_fs;
772 if (!priv->profile->rx_ptp_support)
775 ptp_fs = kzalloc(sizeof(*ptp_fs), GFP_KERNEL);
779 priv->fs.ptp_fs = ptp_fs;
783 void mlx5e_ptp_free_rx_fs(struct mlx5e_priv *priv)
785 struct mlx5e_ptp_fs *ptp_fs = priv->fs.ptp_fs;
787 if (!priv->profile->rx_ptp_support)
790 mlx5e_ptp_rx_unset_fs(priv);
794 int mlx5e_ptp_rx_manage_fs(struct mlx5e_priv *priv, bool set)
796 struct mlx5e_ptp *c = priv->channels.ptp;
798 if (!priv->profile->rx_ptp_support)
801 if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
805 if (!c || !test_bit(MLX5E_PTP_STATE_RX, c->state)) {
806 netdev_WARN_ONCE(priv->netdev, "Don't try to add PTP RX-FS rules");
809 return mlx5e_ptp_rx_set_fs(priv);
812 if (c && test_bit(MLX5E_PTP_STATE_RX, c->state)) {
813 netdev_WARN_ONCE(priv->netdev, "Don't try to remove PTP RX-FS rules");
816 mlx5e_ptp_rx_unset_fs(priv);