18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright 2016-17 IBM Corp.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#define pr_fmt(fmt) "vas: " fmt
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/types.h>
98c2ecf20Sopenharmony_ci#include <linux/slab.h>
108c2ecf20Sopenharmony_ci#include <linux/debugfs.h>
118c2ecf20Sopenharmony_ci#include <linux/seq_file.h>
128c2ecf20Sopenharmony_ci#include "vas.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistatic struct dentry *vas_debugfs;
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistatic char *cop_to_str(int cop)
178c2ecf20Sopenharmony_ci{
188c2ecf20Sopenharmony_ci	switch (cop) {
198c2ecf20Sopenharmony_ci	case VAS_COP_TYPE_FAULT:	return "Fault";
208c2ecf20Sopenharmony_ci	case VAS_COP_TYPE_842:		return "NX-842 Normal Priority";
218c2ecf20Sopenharmony_ci	case VAS_COP_TYPE_842_HIPRI:	return "NX-842 High Priority";
228c2ecf20Sopenharmony_ci	case VAS_COP_TYPE_GZIP:		return "NX-GZIP Normal Priority";
238c2ecf20Sopenharmony_ci	case VAS_COP_TYPE_GZIP_HIPRI:	return "NX-GZIP High Priority";
248c2ecf20Sopenharmony_ci	case VAS_COP_TYPE_FTW:		return "Fast Thread-wakeup";
258c2ecf20Sopenharmony_ci	default:			return "Unknown";
268c2ecf20Sopenharmony_ci	}
278c2ecf20Sopenharmony_ci}
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistatic int info_show(struct seq_file *s, void *private)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	struct vas_window *window = s->private;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	mutex_lock(&vas_mutex);
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci	/* ensure window is not unmapped */
368c2ecf20Sopenharmony_ci	if (!window->hvwc_map)
378c2ecf20Sopenharmony_ci		goto unlock;
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	seq_printf(s, "Type: %s, %s\n", cop_to_str(window->cop),
408c2ecf20Sopenharmony_ci					window->tx_win ? "Send" : "Receive");
418c2ecf20Sopenharmony_ci	seq_printf(s, "Pid : %d\n", vas_window_pid(window));
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciunlock:
448c2ecf20Sopenharmony_ci	mutex_unlock(&vas_mutex);
458c2ecf20Sopenharmony_ci	return 0;
468c2ecf20Sopenharmony_ci}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciDEFINE_SHOW_ATTRIBUTE(info);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistatic inline void print_reg(struct seq_file *s, struct vas_window *win,
518c2ecf20Sopenharmony_ci			char *name, u32 reg)
528c2ecf20Sopenharmony_ci{
538c2ecf20Sopenharmony_ci	seq_printf(s, "0x%016llx %s\n", read_hvwc_reg(win, name, reg), name);
548c2ecf20Sopenharmony_ci}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic int hvwc_show(struct seq_file *s, void *private)
578c2ecf20Sopenharmony_ci{
588c2ecf20Sopenharmony_ci	struct vas_window *window = s->private;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	mutex_lock(&vas_mutex);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	/* ensure window is not unmapped */
638c2ecf20Sopenharmony_ci	if (!window->hvwc_map)
648c2ecf20Sopenharmony_ci		goto unlock;
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(LPID));
678c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(PID));
688c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(XLATE_MSR));
698c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(XLATE_LPCR));
708c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(XLATE_CTL));
718c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(AMR));
728c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(SEIDR));
738c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(FAULT_TX_WIN));
748c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(OSU_INTR_SRC_RA));
758c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(HV_INTR_SRC_RA));
768c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(PSWID));
778c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(LFIFO_BAR));
788c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(LDATA_STAMP_CTL));
798c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(LDMA_CACHE_CTL));
808c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(LRFIFO_PUSH));
818c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(CURR_MSG_COUNT));
828c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(LNOTIFY_AFTER_COUNT));
838c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(LRX_WCRED));
848c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(LRX_WCRED_ADDER));
858c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(TX_WCRED));
868c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(TX_WCRED_ADDER));
878c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(LFIFO_SIZE));
888c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(WINCTL));
898c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(WIN_STATUS));
908c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(WIN_CTX_CACHING_CTL));
918c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(TX_RSVD_BUF_COUNT));
928c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(LRFIFO_WIN_PTR));
938c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(LNOTIFY_CTL));
948c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(LNOTIFY_PID));
958c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(LNOTIFY_LPID));
968c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(LNOTIFY_TID));
978c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(LNOTIFY_SCOPE));
988c2ecf20Sopenharmony_ci	print_reg(s, window, VREG(NX_UTIL_ADDER));
998c2ecf20Sopenharmony_ciunlock:
1008c2ecf20Sopenharmony_ci	mutex_unlock(&vas_mutex);
1018c2ecf20Sopenharmony_ci	return 0;
1028c2ecf20Sopenharmony_ci}
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ciDEFINE_SHOW_ATTRIBUTE(hvwc);
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_civoid vas_window_free_dbgdir(struct vas_window *window)
1078c2ecf20Sopenharmony_ci{
1088c2ecf20Sopenharmony_ci	if (window->dbgdir) {
1098c2ecf20Sopenharmony_ci		debugfs_remove_recursive(window->dbgdir);
1108c2ecf20Sopenharmony_ci		kfree(window->dbgname);
1118c2ecf20Sopenharmony_ci		window->dbgdir = NULL;
1128c2ecf20Sopenharmony_ci		window->dbgname = NULL;
1138c2ecf20Sopenharmony_ci	}
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_civoid vas_window_init_dbgdir(struct vas_window *window)
1178c2ecf20Sopenharmony_ci{
1188c2ecf20Sopenharmony_ci	struct dentry *d;
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	if (!window->vinst->dbgdir)
1218c2ecf20Sopenharmony_ci		return;
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci	window->dbgname = kzalloc(16, GFP_KERNEL);
1248c2ecf20Sopenharmony_ci	if (!window->dbgname)
1258c2ecf20Sopenharmony_ci		return;
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci	snprintf(window->dbgname, 16, "w%d", window->winid);
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	d = debugfs_create_dir(window->dbgname, window->vinst->dbgdir);
1308c2ecf20Sopenharmony_ci	window->dbgdir = d;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	debugfs_create_file("info", 0444, d, window, &info_fops);
1338c2ecf20Sopenharmony_ci	debugfs_create_file("hvwc", 0444, d, window, &hvwc_fops);
1348c2ecf20Sopenharmony_ci}
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_civoid vas_instance_init_dbgdir(struct vas_instance *vinst)
1378c2ecf20Sopenharmony_ci{
1388c2ecf20Sopenharmony_ci	struct dentry *d;
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci	vas_init_dbgdir();
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci	vinst->dbgname = kzalloc(16, GFP_KERNEL);
1438c2ecf20Sopenharmony_ci	if (!vinst->dbgname)
1448c2ecf20Sopenharmony_ci		return;
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci	snprintf(vinst->dbgname, 16, "v%d", vinst->vas_id);
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	d = debugfs_create_dir(vinst->dbgname, vas_debugfs);
1498c2ecf20Sopenharmony_ci	vinst->dbgdir = d;
1508c2ecf20Sopenharmony_ci}
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/*
1538c2ecf20Sopenharmony_ci * Set up the "root" VAS debugfs dir. Return if we already set it up
1548c2ecf20Sopenharmony_ci * (or failed to) in an earlier instance of VAS.
1558c2ecf20Sopenharmony_ci */
1568c2ecf20Sopenharmony_civoid vas_init_dbgdir(void)
1578c2ecf20Sopenharmony_ci{
1588c2ecf20Sopenharmony_ci	static bool first_time = true;
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci	if (!first_time)
1618c2ecf20Sopenharmony_ci		return;
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci	first_time = false;
1648c2ecf20Sopenharmony_ci	vas_debugfs = debugfs_create_dir("vas", NULL);
1658c2ecf20Sopenharmony_ci}
166