mlx5 core users are encouraged to use low level API (mlx5_cmd_exec) without the need of helper functions, do this for q counters, remove helper functions and call mlx5_cmd_exec directly from users. This will help reduce the total amount of code and reduction of the mlx5_core symbol table.
Unified · Split
| @@ -5439,15 +5439,21 @@ static bool is_mdev_switchdev_mode(const struct mlx5_core_dev *mdev) · 5438 unmodified lines | |||
| 5439 | 5439 | ||
| 5440 | static void mlx5_ib_dealloc_counters(struct mlx5_ib_dev *dev) | 5440 | static void mlx5_ib_dealloc_counters(struct mlx5_ib_dev *dev) |
| 5441 | { | 5441 | { |
| 5442 | u32 in[MLX5_ST_SZ_DW(dealloc_q_counter_in)] = {}; | ||
| 5442 | int num_cnt_ports; | 5443 | int num_cnt_ports; |
| 5443 | int i; | 5444 | int i; |
| 5444 | 5445 | ||
| 5445 | num_cnt_ports = is_mdev_switchdev_mode(dev->mdev) ? 1 : dev->num_ports; | 5446 | num_cnt_ports = is_mdev_switchdev_mode(dev->mdev) ? 1 : dev->num_ports; |
| 5446 | 5447 | ||
| 5448 | MLX5_SET(dealloc_q_counter_in, in, opcode, | ||
| 5449 | MLX5_CMD_OP_DEALLOC_Q_COUNTER); | ||
| 5450 | |||
| 5447 | for (i = 0; i < num_cnt_ports; i++) { | 5451 | for (i = 0; i < num_cnt_ports; i++) { |
| 5448 | if (dev->port[i].cnts.set_id_valid) | 5452 | if (dev->port[i].cnts.set_id_valid) { |
| 5449 | mlx5_core_dealloc_q_counter(dev->mdev, | 5453 | MLX5_SET(dealloc_q_counter_in, in, counter_set_id, |
| 5450 | dev->port[i].cnts.set_id); | 5454 | dev->port[i].cnts.set_id); |
| 5455 | mlx5_cmd_exec_in(dev->mdev, dealloc_q_counter, in); | ||
| 5456 | } | ||
| 5451 | kfree(dev->port[i].cnts.names); | 5457 | kfree(dev->port[i].cnts.names); |
| 5452 | kfree(dev->port[i].cnts.offsets); | 5458 | kfree(dev->port[i].cnts.offsets); |
| 5453 | } | 5459 | } |
| @@ -5638,27 +5644,23 @@ static int mlx5_ib_query_q_counters(struct mlx5_core_dev *mdev, · 184 unmodified lines | |||
| 5638 | struct rdma_hw_stats *stats, | 5644 | struct rdma_hw_stats *stats, |
| 5639 | u16 set_id) | 5645 | u16 set_id) |
| 5640 | { | 5646 | { |
| 5641 | int outlen = MLX5_ST_SZ_BYTES(query_q_counter_out); | 5647 | u32 out[MLX5_ST_SZ_DW(query_q_counter_out)] = {}; |
| 5642 | void *out; | 5648 | u32 in[MLX5_ST_SZ_DW(query_q_counter_in)] = {}; |
| 5643 | __be32 val; | 5649 | __be32 val; |
| 5644 | int ret, i; | 5650 | int ret, i; |
| 5645 | 5651 | ||
| 5646 | out = kvzalloc(outlen, GFP_KERNEL); | 5652 | MLX5_SET(query_q_counter_in, in, opcode, MLX5_CMD_OP_QUERY_Q_COUNTER); |
| 5647 | if (!out) | 5653 | MLX5_SET(query_q_counter_in, in, counter_set_id, set_id); |
| 5648 | return -ENOMEM; | 5654 | ret = mlx5_cmd_exec_inout(mdev, query_q_counter, in, out); |
| 5649 | |||
| 5650 | ret = mlx5_core_query_q_counter(mdev, set_id, 0, out, outlen); | ||
| 5651 | if (ret) | 5655 | if (ret) |
| 5652 | goto free; | 5656 | return ret; |
| 5653 | 5657 | ||
| 5654 | for (i = 0; i < cnts->num_q_counters; i++) { | 5658 | for (i = 0; i < cnts->num_q_counters; i++) { |
| 5655 | val = *(__be32 *)(out + cnts->offsets[i]); | 5659 | val = *(__be32 *)((void *)out + cnts->offsets[i]); |
| 5656 | stats->value[i] = (u64)be32_to_cpu(val); | 5660 | stats->value[i] = (u64)be32_to_cpu(val); |
| 5657 | } | 5661 | } |
| 5658 | 5662 | ||
| 5659 | free: | 5663 | return 0; |
| 5660 | kvfree(out); | ||
| 5661 | return ret; | ||
| 5662 | } | 5664 | } |
| 5663 | 5665 | ||
| 5664 | static int mlx5_ib_query_ext_ppcnt_counters(struct mlx5_ib_dev *dev, | 5666 | static int mlx5_ib_query_ext_ppcnt_counters(struct mlx5_ib_dev *dev, |
| @@ -5765,6 +5767,20 @@ static int mlx5_ib_counter_update_stats(struct rdma_counter *counter) · 100 unmodified lines | |||
| 5765 | counter->stats, counter->id); | 5767 | counter->stats, counter->id); |
| 5766 | } | 5768 | } |
| 5767 | 5769 | ||
| 5770 | static int mlx5_ib_counter_dealloc(struct rdma_counter *counter) | ||
| 5771 | { | ||
| 5772 | struct mlx5_ib_dev *dev = to_mdev(counter->device); | ||
| 5773 | u32 in[MLX5_ST_SZ_DW(dealloc_q_counter_in)] = {}; | ||
| 5774 | |||
| 5775 | if (!counter->id) | ||
| 5776 | return 0; | ||
| 5777 | |||
| 5778 | MLX5_SET(dealloc_q_counter_in, in, opcode, | ||
| 5779 | MLX5_CMD_OP_DEALLOC_Q_COUNTER); | ||
| 5780 | MLX5_SET(dealloc_q_counter_in, in, counter_set_id, counter->id); | ||
| 5781 | return mlx5_cmd_exec_in(dev->mdev, dealloc_q_counter, in); | ||
| 5782 | } | ||
| 5783 | |||
| 5768 | static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter, | 5784 | static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter, |
| 5769 | struct ib_qp *qp) | 5785 | struct ib_qp *qp) |
| 5770 | { | 5786 | { |
| @@ -5788,7 +5804,7 @@ static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter, · 17 unmodified lines | |||
| 5788 | return 0; | 5804 | return 0; |
| 5789 | 5805 | ||
| 5790 | fail_set_counter: | 5806 | fail_set_counter: |
| 5791 | mlx5_core_dealloc_q_counter(dev->mdev, cnt_set_id); | 5807 | mlx5_ib_counter_dealloc(counter); |
| 5792 | counter->id = 0; | 5808 | counter->id = 0; |
| 5793 | 5809 | ||
| 5794 | return err; | 5810 | return err; |
| @@ -5799,13 +5815,6 @@ static int mlx5_ib_counter_unbind_qp(struct ib_qp *qp) · 4 unmodified lines | |||
| 5799 | return mlx5_ib_qp_set_counter(qp, NULL); | 5815 | return mlx5_ib_qp_set_counter(qp, NULL); |
| 5800 | } | 5816 | } |
| 5801 | 5817 | ||
| 5802 | static int mlx5_ib_counter_dealloc(struct rdma_counter *counter) | ||
| 5803 | { | ||
| 5804 | struct mlx5_ib_dev *dev = to_mdev(counter->device); | ||
| 5805 | |||
| 5806 | return mlx5_core_dealloc_q_counter(dev->mdev, counter->id); | ||
| 5807 | } | ||
| 5808 | |||
| 5809 | static int mlx5_ib_rn_get_params(struct ib_device *device, u8 port_num, | 5818 | static int mlx5_ib_rn_get_params(struct ib_device *device, u8 port_num, |
| 5810 | enum rdma_netdev_t type, | 5819 | enum rdma_netdev_t type, |
| 5811 | struct rdma_netdev_alloc_params *params) | 5820 | struct rdma_netdev_alloc_params *params) |
| @@ -4997,29 +4997,40 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev) · 4996 unmodified lines | |||
| 4997 | 4997 | ||
| 4998 | void mlx5e_create_q_counters(struct mlx5e_priv *priv) | 4998 | void mlx5e_create_q_counters(struct mlx5e_priv *priv) |
| 4999 | { | 4999 | { |
| 5000 | u32 out[MLX5_ST_SZ_DW(alloc_q_counter_out)] = {}; | ||
| 5001 | u32 in[MLX5_ST_SZ_DW(alloc_q_counter_in)] = {}; | ||
| 5000 | struct mlx5_core_dev *mdev = priv->mdev; | 5002 | struct mlx5_core_dev *mdev = priv->mdev; |
| 5001 | int err; | 5003 | int err; |
| 5002 | 5004 | ||
| 5003 | err = mlx5_core_alloc_q_counter(mdev, &priv->q_counter); | 5005 | MLX5_SET(alloc_q_counter_in, in, opcode, MLX5_CMD_OP_ALLOC_Q_COUNTER); |
| 5004 | if (err) { | 5006 | err = mlx5_cmd_exec_inout(mdev, alloc_q_counter, in, out); |
| 5005 | mlx5_core_warn(mdev, "alloc queue counter failed, %d\n", err); | 5007 | if (!err) |
| 5006 | priv->q_counter = 0; | 5008 | priv->q_counter = |
| 5007 | } | 5009 | MLX5_GET(alloc_q_counter_out, out, counter_set_id); |
| 5008 | 5010 | ||
| 5009 | err = mlx5_core_alloc_q_counter(mdev, &priv->drop_rq_q_counter); | 5011 | err = mlx5_cmd_exec_inout(mdev, alloc_q_counter, in, out); |
| 5010 | if (err) { | 5012 | if (!err) |
| 5011 | mlx5_core_warn(mdev, "alloc drop RQ counter failed, %d\n", err); | 5013 | priv->drop_rq_q_counter = |
| 5012 | priv->drop_rq_q_counter = 0; | 5014 | MLX5_GET(alloc_q_counter_out, out, counter_set_id); |
| 5013 | } | ||
| 5014 | } | 5015 | } |
| 5015 | 5016 | ||
| 5016 | void mlx5e_destroy_q_counters(struct mlx5e_priv *priv) | 5017 | void mlx5e_destroy_q_counters(struct mlx5e_priv *priv) |
| 5017 | { | 5018 | { |
| 5018 | if (priv->q_counter) | 5019 | u32 in[MLX5_ST_SZ_DW(dealloc_q_counter_in)] = {}; |
| 5019 | mlx5_core_dealloc_q_counter(priv->mdev, priv->q_counter); | 5020 | |
| 5021 | MLX5_SET(dealloc_q_counter_in, in, opcode, | ||
| 5022 | MLX5_CMD_OP_DEALLOC_Q_COUNTER); | ||
| 5023 | if (priv->q_counter) { | ||
| 5024 | MLX5_SET(dealloc_q_counter_in, in, counter_set_id, | ||
| 5025 | priv->q_counter); | ||
| 5026 | mlx5_cmd_exec_in(priv->mdev, dealloc_q_counter, in); | ||
| 5027 | } | ||
| 5020 | 5028 | ||
| 5021 | if (priv->drop_rq_q_counter) | 5029 | if (priv->drop_rq_q_counter) { |
| 5022 | mlx5_core_dealloc_q_counter(priv->mdev, priv->drop_rq_q_counter); | 5030 | MLX5_SET(dealloc_q_counter_in, in, counter_set_id, |
| 5031 | priv->drop_rq_q_counter); | ||
| 5032 | mlx5_cmd_exec_in(priv->mdev, dealloc_q_counter, in); | ||
| 5033 | } | ||
| 5023 | } | 5034 | } |
| 5024 | 5035 | ||
| 5025 | static int mlx5e_nic_init(struct mlx5_core_dev *mdev, | 5036 | static int mlx5e_nic_init(struct mlx5_core_dev *mdev, |
| @@ -411,18 +411,29 @@ static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(qcnt) · 410 unmodified lines | |||
| 411 | static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(qcnt) | 411 | static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(qcnt) |
| 412 | { | 412 | { |
| 413 | struct mlx5e_qcounter_stats *qcnt = &priv->stats.qcnt; | 413 | struct mlx5e_qcounter_stats *qcnt = &priv->stats.qcnt; |
| 414 | u32 out[MLX5_ST_SZ_DW(query_q_counter_out)]; | 414 | u32 out[MLX5_ST_SZ_DW(query_q_counter_out)] = {}; |
| 415 | 415 | u32 in[MLX5_ST_SZ_DW(query_q_counter_in)] = {}; | |
| 416 | if (priv->q_counter && | 416 | int ret; |
| 417 | !mlx5_core_query_q_counter(priv->mdev, priv->q_counter, 0, out, | 417 | |
| 418 | sizeof(out))) | 418 | MLX5_SET(query_q_counter_in, in, opcode, MLX5_CMD_OP_QUERY_Q_COUNTER); |
| 419 | qcnt->rx_out_of_buffer = MLX5_GET(query_q_counter_out, | 419 | |
| 420 | out, out_of_buffer); | 420 | if (priv->q_counter) { |
| 421 | if (priv->drop_rq_q_counter && | 421 | MLX5_SET(query_q_counter_in, in, counter_set_id, |
| 422 | !mlx5_core_query_q_counter(priv->mdev, priv->drop_rq_q_counter, 0, | 422 | priv->q_counter); |
| 423 | out, sizeof(out))) | 423 | ret = mlx5_cmd_exec_inout(priv->mdev, query_q_counter, in, out); |
| 424 | qcnt->rx_if_down_packets = MLX5_GET(query_q_counter_out, out, | 424 | if (!ret) |
| 425 | out_of_buffer); | 425 | qcnt->rx_out_of_buffer = MLX5_GET(query_q_counter_out, |
| 426 | out, out_of_buffer); | ||
| 427 | } | ||
| 428 | |||
| 429 | if (priv->drop_rq_q_counter) { | ||
| 430 | MLX5_SET(query_q_counter_in, in, counter_set_id, | ||
| 431 | priv->drop_rq_q_counter); | ||
| 432 | ret = mlx5_cmd_exec_inout(priv->mdev, query_q_counter, in, out); | ||
| 433 | if (!ret) | ||
| 434 | qcnt->rx_if_down_packets = MLX5_GET(query_q_counter_out, | ||
| 435 | out, out_of_buffer); | ||
| 436 | } | ||
| 426 | } | 437 | } |
| 427 | 438 | ||
| 428 | #define VNIC_ENV_OFF(c) MLX5_BYTE_OFF(query_vnic_env_out, c) | 439 | #define VNIC_ENV_OFF(c) MLX5_BYTE_OFF(query_vnic_env_out, c) |
| @@ -680,45 +680,6 @@ void mlx5_core_destroy_sq_tracked(struct mlx5_core_dev *dev, · 679 unmodified lines | |||
| 680 | } | 680 | } |
| 681 | EXPORT_SYMBOL(mlx5_core_destroy_sq_tracked); | 681 | EXPORT_SYMBOL(mlx5_core_destroy_sq_tracked); |
| 682 | 682 | ||
| 683 | int mlx5_core_alloc_q_counter(struct mlx5_core_dev *dev, u16 *counter_id) | ||
| 684 | { | ||
| 685 | u32 in[MLX5_ST_SZ_DW(alloc_q_counter_in)] = {0}; | ||
| 686 | u32 out[MLX5_ST_SZ_DW(alloc_q_counter_out)] = {0}; | ||
| 687 | int err; | ||
| 688 | |||
| 689 | MLX5_SET(alloc_q_counter_in, in, opcode, MLX5_CMD_OP_ALLOC_Q_COUNTER); | ||
| 690 | err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); | ||
| 691 | if (!err) | ||
| 692 | *counter_id = MLX5_GET(alloc_q_counter_out, out, | ||
| 693 | counter_set_id); | ||
| 694 | return err; | ||
| 695 | } | ||
| 696 | EXPORT_SYMBOL_GPL(mlx5_core_alloc_q_counter); | ||
| 697 | |||
| 698 | int mlx5_core_dealloc_q_counter(struct mlx5_core_dev *dev, u16 counter_id) | ||
| 699 | { | ||
| 700 | u32 in[MLX5_ST_SZ_DW(dealloc_q_counter_in)] = {0}; | ||
| 701 | u32 out[MLX5_ST_SZ_DW(dealloc_q_counter_out)] = {0}; | ||
| 702 | |||
| 703 | MLX5_SET(dealloc_q_counter_in, in, opcode, | ||
| 704 | MLX5_CMD_OP_DEALLOC_Q_COUNTER); | ||
| 705 | MLX5_SET(dealloc_q_counter_in, in, counter_set_id, counter_id); | ||
| 706 | return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); | ||
| 707 | } | ||
| 708 | EXPORT_SYMBOL_GPL(mlx5_core_dealloc_q_counter); | ||
| 709 | |||
| 710 | int mlx5_core_query_q_counter(struct mlx5_core_dev *dev, u16 counter_id, | ||
| 711 | int reset, void *out, int out_size) | ||
| 712 | { | ||
| 713 | u32 in[MLX5_ST_SZ_DW(query_q_counter_in)] = {0}; | ||
| 714 | |||
| 715 | MLX5_SET(query_q_counter_in, in, opcode, MLX5_CMD_OP_QUERY_Q_COUNTER); | ||
| 716 | MLX5_SET(query_q_counter_in, in, clear, reset); | ||
| 717 | MLX5_SET(query_q_counter_in, in, counter_set_id, counter_id); | ||
| 718 | return mlx5_cmd_exec(dev, in, sizeof(in), out, out_size); | ||
| 719 | } | ||
| 720 | EXPORT_SYMBOL_GPL(mlx5_core_query_q_counter); | ||
| 721 | |||
| 722 | struct mlx5_core_rsc_common *mlx5_core_res_hold(struct mlx5_core_dev *dev, | 683 | struct mlx5_core_rsc_common *mlx5_core_res_hold(struct mlx5_core_dev *dev, |
| 723 | int res_num, | 684 | int res_num, |
| 724 | enum mlx5_res_type res_type) | 685 | enum mlx5_res_type res_type) |
| @@ -595,10 +595,6 @@ int mlx5_core_create_sq_tracked(struct mlx5_core_dev *dev, u32 *in, int inlen, · 594 unmodified lines | |||
| 595 | struct mlx5_core_qp *sq); | 595 | struct mlx5_core_qp *sq); |
| 596 | void mlx5_core_destroy_sq_tracked(struct mlx5_core_dev *dev, | 596 | void mlx5_core_destroy_sq_tracked(struct mlx5_core_dev *dev, |
| 597 | struct mlx5_core_qp *sq); | 597 | struct mlx5_core_qp *sq); |
| 598 | int mlx5_core_alloc_q_counter(struct mlx5_core_dev *dev, u16 *counter_id); | ||
| 599 | int mlx5_core_dealloc_q_counter(struct mlx5_core_dev *dev, u16 counter_id); | ||
| 600 | int mlx5_core_query_q_counter(struct mlx5_core_dev *dev, u16 counter_id, | ||
| 601 | int reset, void *out, int out_size); | ||
| 602 | 598 | ||
| 603 | struct mlx5_core_rsc_common *mlx5_core_res_hold(struct mlx5_core_dev *dev, | 599 | struct mlx5_core_rsc_common *mlx5_core_res_hold(struct mlx5_core_dev *dev, |
| 604 | int res_num, | 600 | int res_num, |