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 mlx5_macsec_stats, macsec_rx_pkts) }, 12 { MLX5E_DECLARE_STAT(struct mlx5_macsec_stats, macsec_rx_bytes) }, 13 { MLX5E_DECLARE_STAT(struct mlx5_macsec_stats, macsec_rx_pkts_drop) }, 14 { MLX5E_DECLARE_STAT(struct mlx5_macsec_stats, macsec_rx_bytes_drop) }, 15 { MLX5E_DECLARE_STAT(struct mlx5_macsec_stats, macsec_tx_pkts) }, 16 { MLX5E_DECLARE_STAT(struct mlx5_macsec_stats, macsec_tx_bytes) }, 17 { MLX5E_DECLARE_STAT(struct mlx5_macsec_stats, macsec_tx_pkts_drop) }, 18 { MLX5E_DECLARE_STAT(struct mlx5_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 struct mlx5_macsec_fs *macsec_fs; 56 int i; 57 58 if (!priv->macsec) 59 return idx; 60 61 if (!mlx5e_is_macsec_device(priv->mdev)) 62 return idx; 63 64 macsec_fs = priv->mdev->macsec_fs; 65 mlx5_macsec_fs_get_stats_fill(macsec_fs, mlx5_macsec_fs_get_stats(macsec_fs)); 66 for (i = 0; i < NUM_MACSEC_HW_COUNTERS; i++) 67 data[idx++] = MLX5E_READ_CTR64_CPU(mlx5_macsec_fs_get_stats(macsec_fs), 68 mlx5e_macsec_hw_stats_desc, 69 i); 70 71 return idx; 72 } 73 74 MLX5E_DEFINE_STATS_GRP(macsec_hw, 0); 75