1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB 2 /* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ 3 4 #include <linux/ethtool.h> 5 #include <net/sock.h> 6 7 #include "en.h" 8 #include "en_accel/macsec.h" 9 10 static const struct counter_desc mlx5e_macsec_hw_stats_desc[] = { 11 { MLX5E_DECLARE_STAT(struct mlx5e_macsec_stats, macsec_rx_pkts) }, 12 { MLX5E_DECLARE_STAT(struct mlx5e_macsec_stats, macsec_rx_bytes) }, 13 { MLX5E_DECLARE_STAT(struct mlx5e_macsec_stats, macsec_rx_pkts_drop) }, 14 { MLX5E_DECLARE_STAT(struct mlx5e_macsec_stats, macsec_rx_bytes_drop) }, 15 { MLX5E_DECLARE_STAT(struct mlx5e_macsec_stats, macsec_tx_pkts) }, 16 { MLX5E_DECLARE_STAT(struct mlx5e_macsec_stats, macsec_tx_bytes) }, 17 { MLX5E_DECLARE_STAT(struct mlx5e_macsec_stats, macsec_tx_pkts_drop) }, 18 { MLX5E_DECLARE_STAT(struct mlx5e_macsec_stats, macsec_tx_bytes_drop) }, 19 }; 20 21 #define NUM_MACSEC_HW_COUNTERS ARRAY_SIZE(mlx5e_macsec_hw_stats_desc) 22 23 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(macsec_hw) 24 { 25 if (!priv->macsec) 26 return 0; 27 28 if (mlx5e_is_macsec_device(priv->mdev)) 29 return NUM_MACSEC_HW_COUNTERS; 30 31 return 0; 32 } 33 34 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(macsec_hw) {} 35 36 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(macsec_hw) 37 { 38 unsigned int i; 39 40 if (!priv->macsec) 41 return idx; 42 43 if (!mlx5e_is_macsec_device(priv->mdev)) 44 return idx; 45 46 for (i = 0; i < NUM_MACSEC_HW_COUNTERS; i++) 47 strcpy(data + (idx++) * ETH_GSTRING_LEN, 48 mlx5e_macsec_hw_stats_desc[i].format); 49 50 return idx; 51 } 52 53 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(macsec_hw) 54 { 55 int i; 56 57 if (!priv->macsec) 58 return idx; 59 60 if (!mlx5e_is_macsec_device(priv->mdev)) 61 return idx; 62 63 mlx5e_macsec_get_stats_fill(priv->macsec, mlx5e_macsec_get_stats(priv->macsec)); 64 for (i = 0; i < NUM_MACSEC_HW_COUNTERS; i++) 65 data[idx++] = MLX5E_READ_CTR64_CPU(mlx5e_macsec_get_stats(priv->macsec), 66 mlx5e_macsec_hw_stats_desc, 67 i); 68 69 return idx; 70 } 71 72 MLX5E_DEFINE_STATS_GRP(macsec_hw, 0); 73