129422100SEli Cohen // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
229422100SEli Cohen /* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
329422100SEli Cohen
429422100SEli Cohen #include <linux/debugfs.h>
529422100SEli Cohen #include <linux/mlx5/fs.h>
629422100SEli Cohen #include "mlx5_vnet.h"
729422100SEli Cohen
tirn_show(struct seq_file * file,void * priv)829422100SEli Cohen static int tirn_show(struct seq_file *file, void *priv)
929422100SEli Cohen {
1029422100SEli Cohen struct mlx5_vdpa_net *ndev = file->private;
1129422100SEli Cohen
1229422100SEli Cohen seq_printf(file, "0x%x\n", ndev->res.tirn);
1329422100SEli Cohen return 0;
1429422100SEli Cohen }
1529422100SEli Cohen
1629422100SEli Cohen DEFINE_SHOW_ATTRIBUTE(tirn);
1729422100SEli Cohen
mlx5_vdpa_remove_tirn(struct mlx5_vdpa_net * ndev)1829422100SEli Cohen void mlx5_vdpa_remove_tirn(struct mlx5_vdpa_net *ndev)
1929422100SEli Cohen {
2029422100SEli Cohen if (ndev->debugfs)
2129422100SEli Cohen debugfs_remove(ndev->res.tirn_dent);
2229422100SEli Cohen }
2329422100SEli Cohen
mlx5_vdpa_add_tirn(struct mlx5_vdpa_net * ndev)2429422100SEli Cohen void mlx5_vdpa_add_tirn(struct mlx5_vdpa_net *ndev)
2529422100SEli Cohen {
2629422100SEli Cohen ndev->res.tirn_dent = debugfs_create_file("tirn", 0444, ndev->rx_dent,
2729422100SEli Cohen ndev, &tirn_fops);
2829422100SEli Cohen }
2929422100SEli Cohen
rx_flow_table_show(struct seq_file * file,void * priv)3029422100SEli Cohen static int rx_flow_table_show(struct seq_file *file, void *priv)
3129422100SEli Cohen {
3229422100SEli Cohen struct mlx5_vdpa_net *ndev = file->private;
3329422100SEli Cohen
3429422100SEli Cohen seq_printf(file, "0x%x\n", mlx5_flow_table_id(ndev->rxft));
3529422100SEli Cohen return 0;
3629422100SEli Cohen }
3729422100SEli Cohen
3829422100SEli Cohen DEFINE_SHOW_ATTRIBUTE(rx_flow_table);
3929422100SEli Cohen
mlx5_vdpa_remove_rx_flow_table(struct mlx5_vdpa_net * ndev)4029422100SEli Cohen void mlx5_vdpa_remove_rx_flow_table(struct mlx5_vdpa_net *ndev)
4129422100SEli Cohen {
4229422100SEli Cohen if (ndev->debugfs)
4329422100SEli Cohen debugfs_remove(ndev->rx_table_dent);
4429422100SEli Cohen }
4529422100SEli Cohen
mlx5_vdpa_add_rx_flow_table(struct mlx5_vdpa_net * ndev)4629422100SEli Cohen void mlx5_vdpa_add_rx_flow_table(struct mlx5_vdpa_net *ndev)
4729422100SEli Cohen {
4829422100SEli Cohen ndev->rx_table_dent = debugfs_create_file("table_id", 0444, ndev->rx_dent,
4929422100SEli Cohen ndev, &rx_flow_table_fops);
5029422100SEli Cohen }
5129422100SEli Cohen
520a599750SEli Cohen #if defined(CONFIG_MLX5_VDPA_STEERING_DEBUG)
packets_show(struct seq_file * file,void * priv)530a599750SEli Cohen static int packets_show(struct seq_file *file, void *priv)
540a599750SEli Cohen {
550a599750SEli Cohen struct mlx5_vdpa_counter *counter = file->private;
560a599750SEli Cohen u64 packets;
570a599750SEli Cohen u64 bytes;
580a599750SEli Cohen int err;
590a599750SEli Cohen
600a599750SEli Cohen err = mlx5_fc_query(counter->mdev, counter->counter, &packets, &bytes);
610a599750SEli Cohen if (err)
620a599750SEli Cohen return err;
630a599750SEli Cohen
640a599750SEli Cohen seq_printf(file, "0x%llx\n", packets);
650a599750SEli Cohen return 0;
660a599750SEli Cohen }
670a599750SEli Cohen
bytes_show(struct seq_file * file,void * priv)680a599750SEli Cohen static int bytes_show(struct seq_file *file, void *priv)
690a599750SEli Cohen {
700a599750SEli Cohen struct mlx5_vdpa_counter *counter = file->private;
710a599750SEli Cohen u64 packets;
720a599750SEli Cohen u64 bytes;
730a599750SEli Cohen int err;
740a599750SEli Cohen
750a599750SEli Cohen err = mlx5_fc_query(counter->mdev, counter->counter, &packets, &bytes);
760a599750SEli Cohen if (err)
770a599750SEli Cohen return err;
780a599750SEli Cohen
790a599750SEli Cohen seq_printf(file, "0x%llx\n", bytes);
800a599750SEli Cohen return 0;
810a599750SEli Cohen }
820a599750SEli Cohen
830a599750SEli Cohen DEFINE_SHOW_ATTRIBUTE(packets);
840a599750SEli Cohen DEFINE_SHOW_ATTRIBUTE(bytes);
850a599750SEli Cohen
add_counter_node(struct mlx5_vdpa_counter * counter,struct dentry * parent)860a599750SEli Cohen static void add_counter_node(struct mlx5_vdpa_counter *counter,
870a599750SEli Cohen struct dentry *parent)
880a599750SEli Cohen {
890a599750SEli Cohen debugfs_create_file("packets", 0444, parent, counter,
900a599750SEli Cohen &packets_fops);
910a599750SEli Cohen debugfs_create_file("bytes", 0444, parent, counter,
920a599750SEli Cohen &bytes_fops);
930a599750SEli Cohen }
940a599750SEli Cohen
mlx5_vdpa_add_rx_counters(struct mlx5_vdpa_net * ndev,struct macvlan_node * node)950a599750SEli Cohen void mlx5_vdpa_add_rx_counters(struct mlx5_vdpa_net *ndev,
960a599750SEli Cohen struct macvlan_node *node)
970a599750SEli Cohen {
980a599750SEli Cohen static const char *ut = "untagged";
990a599750SEli Cohen char vidstr[9];
1000a599750SEli Cohen u16 vid;
1010a599750SEli Cohen
1020a599750SEli Cohen node->ucast_counter.mdev = ndev->mvdev.mdev;
1030a599750SEli Cohen node->mcast_counter.mdev = ndev->mvdev.mdev;
1040a599750SEli Cohen if (node->tagged) {
1050a599750SEli Cohen vid = key2vid(node->macvlan);
1060a599750SEli Cohen snprintf(vidstr, sizeof(vidstr), "0x%x", vid);
1070a599750SEli Cohen } else {
1080a599750SEli Cohen strcpy(vidstr, ut);
1090a599750SEli Cohen }
1100a599750SEli Cohen
1110a599750SEli Cohen node->dent = debugfs_create_dir(vidstr, ndev->rx_dent);
1120a599750SEli Cohen if (IS_ERR(node->dent)) {
1130a599750SEli Cohen node->dent = NULL;
1140a599750SEli Cohen return;
1150a599750SEli Cohen }
1160a599750SEli Cohen
1170a599750SEli Cohen node->ucast_counter.dent = debugfs_create_dir("ucast", node->dent);
1180a599750SEli Cohen if (IS_ERR(node->ucast_counter.dent))
1190a599750SEli Cohen return;
1200a599750SEli Cohen
1210a599750SEli Cohen add_counter_node(&node->ucast_counter, node->ucast_counter.dent);
1220a599750SEli Cohen
1230a599750SEli Cohen node->mcast_counter.dent = debugfs_create_dir("mcast", node->dent);
1240a599750SEli Cohen if (IS_ERR(node->mcast_counter.dent))
1250a599750SEli Cohen return;
1260a599750SEli Cohen
1270a599750SEli Cohen add_counter_node(&node->mcast_counter, node->mcast_counter.dent);
1280a599750SEli Cohen }
1290a599750SEli Cohen
mlx5_vdpa_remove_rx_counters(struct mlx5_vdpa_net * ndev,struct macvlan_node * node)1300a599750SEli Cohen void mlx5_vdpa_remove_rx_counters(struct mlx5_vdpa_net *ndev,
1310a599750SEli Cohen struct macvlan_node *node)
1320a599750SEli Cohen {
1330a599750SEli Cohen if (node->dent && ndev->debugfs)
1340a599750SEli Cohen debugfs_remove_recursive(node->dent);
1350a599750SEli Cohen }
1360a599750SEli Cohen #endif
1370a599750SEli Cohen
mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net * ndev)13829422100SEli Cohen void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev)
13929422100SEli Cohen {
14029422100SEli Cohen struct mlx5_core_dev *mdev;
14129422100SEli Cohen
14229422100SEli Cohen mdev = ndev->mvdev.mdev;
14329422100SEli Cohen ndev->debugfs = debugfs_create_dir(dev_name(&ndev->mvdev.vdev.dev),
14429422100SEli Cohen mlx5_debugfs_get_dev_root(mdev));
14529422100SEli Cohen if (!IS_ERR(ndev->debugfs))
14629422100SEli Cohen ndev->rx_dent = debugfs_create_dir("rx", ndev->debugfs);
14729422100SEli Cohen }
14829422100SEli Cohen
mlx5_vdpa_remove_debugfs(struct mlx5_vdpa_net * ndev)149*f8a3db47SDragos Tatulea void mlx5_vdpa_remove_debugfs(struct mlx5_vdpa_net *ndev)
15029422100SEli Cohen {
151*f8a3db47SDragos Tatulea debugfs_remove_recursive(ndev->debugfs);
152*f8a3db47SDragos Tatulea ndev->debugfs = NULL;
15329422100SEli Cohen }
154