1423530beSHans Petter Selasky /*-
2423530beSHans Petter Selasky * Copyright (c) 2018 Mellanox Technologies. All rights reserved.
3423530beSHans Petter Selasky *
4423530beSHans Petter Selasky * Redistribution and use in source and binary forms, with or without
5423530beSHans Petter Selasky * modification, are permitted provided that the following conditions
6423530beSHans Petter Selasky * are met:
7423530beSHans Petter Selasky * 1. Redistributions of source code must retain the above copyright
8423530beSHans Petter Selasky * notice, this list of conditions and the following disclaimer.
9423530beSHans Petter Selasky * 2. Redistributions in binary form must reproduce the above copyright
10423530beSHans Petter Selasky * notice, this list of conditions and the following disclaimer in the
11423530beSHans Petter Selasky * documentation and/or other materials provided with the distribution.
12423530beSHans Petter Selasky *
13423530beSHans Petter Selasky * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
14423530beSHans Petter Selasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15423530beSHans Petter Selasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16423530beSHans Petter Selasky * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17423530beSHans Petter Selasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18423530beSHans Petter Selasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19423530beSHans Petter Selasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20423530beSHans Petter Selasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21423530beSHans Petter Selasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22423530beSHans Petter Selasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23423530beSHans Petter Selasky * SUCH DAMAGE.
24423530beSHans Petter Selasky */
25423530beSHans Petter Selasky
26b984b956SKonstantin Belousov #include "opt_rss.h"
27b984b956SKonstantin Belousov #include "opt_ratelimit.h"
28b984b956SKonstantin Belousov
29*89918a23SKonstantin Belousov #include <dev/mlx5/mlx5_en/en.h>
30423530beSHans Petter Selasky
31423530beSHans Petter Selasky void
mlx5e_dim_build_cq_param(struct mlx5e_priv * priv,struct mlx5e_cq_param * param)32423530beSHans Petter Selasky mlx5e_dim_build_cq_param(struct mlx5e_priv *priv,
33423530beSHans Petter Selasky struct mlx5e_cq_param *param)
34423530beSHans Petter Selasky {
35423530beSHans Petter Selasky struct net_dim_cq_moder prof;
36423530beSHans Petter Selasky void *cqc = param->cqc;
37423530beSHans Petter Selasky
38423530beSHans Petter Selasky if (priv->params.rx_cq_moderation_mode < 2)
39423530beSHans Petter Selasky return;
40423530beSHans Petter Selasky
41423530beSHans Petter Selasky switch (MLX5_GET(cqc, cqc, cq_period_mode)) {
42423530beSHans Petter Selasky case MLX5_CQ_PERIOD_MODE_START_FROM_CQE:
43423530beSHans Petter Selasky prof = net_dim_profile[NET_DIM_CQ_PERIOD_MODE_START_FROM_CQE]
44423530beSHans Petter Selasky [NET_DIM_DEF_PROFILE_CQE];
45423530beSHans Petter Selasky MLX5_SET(cqc, cqc, cq_period, prof.usec);
46423530beSHans Petter Selasky MLX5_SET(cqc, cqc, cq_max_count, prof.pkts);
47423530beSHans Petter Selasky break;
48423530beSHans Petter Selasky
49423530beSHans Petter Selasky case MLX5_CQ_PERIOD_MODE_START_FROM_EQE:
50423530beSHans Petter Selasky prof = net_dim_profile[NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE]
51423530beSHans Petter Selasky [NET_DIM_DEF_PROFILE_EQE];
52423530beSHans Petter Selasky MLX5_SET(cqc, cqc, cq_period, prof.usec);
53423530beSHans Petter Selasky MLX5_SET(cqc, cqc, cq_max_count, prof.pkts);
54423530beSHans Petter Selasky break;
55423530beSHans Petter Selasky default:
56423530beSHans Petter Selasky break;
57423530beSHans Petter Selasky }
58423530beSHans Petter Selasky }
59423530beSHans Petter Selasky
60423530beSHans Petter Selasky void
mlx5e_dim_work(struct work_struct * work)61423530beSHans Petter Selasky mlx5e_dim_work(struct work_struct *work)
62423530beSHans Petter Selasky {
63423530beSHans Petter Selasky struct net_dim *dim = container_of(work, struct net_dim, work);
64423530beSHans Petter Selasky struct mlx5e_rq *rq = container_of(dim, struct mlx5e_rq, dim);
65423530beSHans Petter Selasky struct mlx5e_channel *c = container_of(rq, struct mlx5e_channel, rq);
66423530beSHans Petter Selasky struct net_dim_cq_moder cur_profile;
67423530beSHans Petter Selasky u8 profile_ix;
68423530beSHans Petter Selasky u8 mode;
69423530beSHans Petter Selasky
70423530beSHans Petter Selasky /* copy current auto moderation settings and set new state */
71423530beSHans Petter Selasky mtx_lock(&rq->mtx);
72423530beSHans Petter Selasky profile_ix = dim->profile_ix;
73423530beSHans Petter Selasky mode = dim->mode;
74423530beSHans Petter Selasky dim->state = NET_DIM_START_MEASURE;
75423530beSHans Petter Selasky mtx_unlock(&rq->mtx);
76423530beSHans Petter Selasky
77423530beSHans Petter Selasky /* check for invalid mode */
78423530beSHans Petter Selasky if (mode == 255)
79423530beSHans Petter Selasky return;
80423530beSHans Petter Selasky
81423530beSHans Petter Selasky /* get current profile */
82423530beSHans Petter Selasky cur_profile = net_dim_profile[mode][profile_ix];
83423530beSHans Petter Selasky
84423530beSHans Petter Selasky /* apply LRO restrictions */
85423530beSHans Petter Selasky if (c->priv->params.hw_lro_en &&
86423530beSHans Petter Selasky cur_profile.pkts > MLX5E_DIM_MAX_RX_CQ_MODERATION_PKTS_WITH_LRO) {
87423530beSHans Petter Selasky cur_profile.pkts = MLX5E_DIM_MAX_RX_CQ_MODERATION_PKTS_WITH_LRO;
88423530beSHans Petter Selasky }
89423530beSHans Petter Selasky
90423530beSHans Petter Selasky /* modify CQ */
91423530beSHans Petter Selasky mlx5_core_modify_cq_moderation(c->priv->mdev, &rq->cq.mcq,
92423530beSHans Petter Selasky cur_profile.usec, cur_profile.pkts);
93423530beSHans Petter Selasky }
94