hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_stats.c
....@@ -38,6 +38,7 @@
3838 #include "accel/ipsec.h"
3939 #include "fpga/sdk.h"
4040 #include "en_accel/ipsec.h"
41
+#include "fpga/ipsec.h"
4142
4243 static const struct counter_desc mlx5e_ipsec_hw_stats_desc[] = {
4344 { MLX5E_DECLARE_STAT(struct mlx5e_ipsec_stats, ipsec_dec_in_packets) },
....@@ -73,61 +74,74 @@
7374 #define NUM_IPSEC_HW_COUNTERS ARRAY_SIZE(mlx5e_ipsec_hw_stats_desc)
7475 #define NUM_IPSEC_SW_COUNTERS ARRAY_SIZE(mlx5e_ipsec_sw_stats_desc)
7576
76
-#define NUM_IPSEC_COUNTERS (NUM_IPSEC_HW_COUNTERS + NUM_IPSEC_SW_COUNTERS)
77
-
78
-int mlx5e_ipsec_get_count(struct mlx5e_priv *priv)
77
+static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(ipsec_sw)
7978 {
80
- if (!priv->ipsec)
81
- return 0;
82
-
83
- return NUM_IPSEC_COUNTERS;
79
+ return priv->ipsec ? NUM_IPSEC_SW_COUNTERS : 0;
8480 }
8581
86
-int mlx5e_ipsec_get_strings(struct mlx5e_priv *priv, uint8_t *data)
82
+static inline MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(ipsec_sw) {}
83
+
84
+static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(ipsec_sw)
8785 {
88
- unsigned int i, idx = 0;
86
+ unsigned int i;
8987
90
- if (!priv->ipsec)
91
- return 0;
92
-
93
- for (i = 0; i < NUM_IPSEC_HW_COUNTERS; i++)
94
- strcpy(data + (idx++) * ETH_GSTRING_LEN,
95
- mlx5e_ipsec_hw_stats_desc[i].format);
96
-
97
- for (i = 0; i < NUM_IPSEC_SW_COUNTERS; i++)
98
- strcpy(data + (idx++) * ETH_GSTRING_LEN,
99
- mlx5e_ipsec_sw_stats_desc[i].format);
100
-
101
- return NUM_IPSEC_COUNTERS;
88
+ if (priv->ipsec)
89
+ for (i = 0; i < NUM_IPSEC_SW_COUNTERS; i++)
90
+ strcpy(data + (idx++) * ETH_GSTRING_LEN,
91
+ mlx5e_ipsec_sw_stats_desc[i].format);
92
+ return idx;
10293 }
10394
104
-void mlx5e_ipsec_update_stats(struct mlx5e_priv *priv)
95
+static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(ipsec_sw)
10596 {
106
- int ret;
97
+ int i;
10798
108
- if (!priv->ipsec)
109
- return;
99
+ if (priv->ipsec)
100
+ for (i = 0; i < NUM_IPSEC_SW_COUNTERS; i++)
101
+ data[idx++] = MLX5E_READ_CTR_ATOMIC64(&priv->ipsec->sw_stats,
102
+ mlx5e_ipsec_sw_stats_desc, i);
103
+ return idx;
104
+}
110105
111
- ret = mlx5_accel_ipsec_counters_read(priv->mdev, (u64 *)&priv->ipsec->stats,
112
- NUM_IPSEC_HW_COUNTERS);
106
+static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(ipsec_hw)
107
+{
108
+ return (priv->ipsec && mlx5_fpga_ipsec_device_caps(priv->mdev)) ? NUM_IPSEC_HW_COUNTERS : 0;
109
+}
110
+
111
+static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(ipsec_hw)
112
+{
113
+ int ret = 0;
114
+
115
+ if (priv->ipsec)
116
+ ret = mlx5_accel_ipsec_counters_read(priv->mdev, (u64 *)&priv->ipsec->stats,
117
+ NUM_IPSEC_HW_COUNTERS);
113118 if (ret)
114119 memset(&priv->ipsec->stats, 0, sizeof(priv->ipsec->stats));
115120 }
116121
117
-int mlx5e_ipsec_get_stats(struct mlx5e_priv *priv, u64 *data)
122
+static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(ipsec_hw)
118123 {
119
- int i, idx = 0;
124
+ unsigned int i;
120125
121
- if (!priv->ipsec)
122
- return 0;
126
+ if (priv->ipsec && mlx5_fpga_ipsec_device_caps(priv->mdev))
127
+ for (i = 0; i < NUM_IPSEC_HW_COUNTERS; i++)
128
+ strcpy(data + (idx++) * ETH_GSTRING_LEN,
129
+ mlx5e_ipsec_hw_stats_desc[i].format);
123130
124
- for (i = 0; i < NUM_IPSEC_HW_COUNTERS; i++)
125
- data[idx++] = MLX5E_READ_CTR64_CPU(&priv->ipsec->stats,
126
- mlx5e_ipsec_hw_stats_desc, i);
127
-
128
- for (i = 0; i < NUM_IPSEC_SW_COUNTERS; i++)
129
- data[idx++] = MLX5E_READ_CTR_ATOMIC64(&priv->ipsec->sw_stats,
130
- mlx5e_ipsec_sw_stats_desc, i);
131
-
132
- return NUM_IPSEC_COUNTERS;
131
+ return idx;
133132 }
133
+
134
+static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(ipsec_hw)
135
+{
136
+ int i;
137
+
138
+ if (priv->ipsec && mlx5_fpga_ipsec_device_caps(priv->mdev))
139
+ for (i = 0; i < NUM_IPSEC_HW_COUNTERS; i++)
140
+ data[idx++] = MLX5E_READ_CTR64_CPU(&priv->ipsec->stats,
141
+ mlx5e_ipsec_hw_stats_desc,
142
+ i);
143
+ return idx;
144
+}
145
+
146
+MLX5E_DEFINE_STATS_GRP(ipsec_sw, 0);
147
+MLX5E_DEFINE_STATS_GRP(ipsec_hw, 0);