12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2ece4e512SSukadev Bhattiprolu /*
3ece4e512SSukadev Bhattiprolu * Copyright 2016-17 IBM Corp.
4ece4e512SSukadev Bhattiprolu */
5ece4e512SSukadev Bhattiprolu
6ece4e512SSukadev Bhattiprolu #define pr_fmt(fmt) "vas: " fmt
7ece4e512SSukadev Bhattiprolu
8ece4e512SSukadev Bhattiprolu #include <linux/types.h>
9ece4e512SSukadev Bhattiprolu #include <linux/slab.h>
10ece4e512SSukadev Bhattiprolu #include <linux/debugfs.h>
11ece4e512SSukadev Bhattiprolu #include <linux/seq_file.h>
12*7bc6f71bSHaren Myneni #include <asm/vas.h>
13ece4e512SSukadev Bhattiprolu #include "vas.h"
14ece4e512SSukadev Bhattiprolu
15ece4e512SSukadev Bhattiprolu static struct dentry *vas_debugfs;
16ece4e512SSukadev Bhattiprolu
cop_to_str(int cop)17ece4e512SSukadev Bhattiprolu static char *cop_to_str(int cop)
18ece4e512SSukadev Bhattiprolu {
19ece4e512SSukadev Bhattiprolu switch (cop) {
20ece4e512SSukadev Bhattiprolu case VAS_COP_TYPE_FAULT: return "Fault";
21ece4e512SSukadev Bhattiprolu case VAS_COP_TYPE_842: return "NX-842 Normal Priority";
22ece4e512SSukadev Bhattiprolu case VAS_COP_TYPE_842_HIPRI: return "NX-842 High Priority";
23ece4e512SSukadev Bhattiprolu case VAS_COP_TYPE_GZIP: return "NX-GZIP Normal Priority";
24ece4e512SSukadev Bhattiprolu case VAS_COP_TYPE_GZIP_HIPRI: return "NX-GZIP High Priority";
25ece4e512SSukadev Bhattiprolu case VAS_COP_TYPE_FTW: return "Fast Thread-wakeup";
26ece4e512SSukadev Bhattiprolu default: return "Unknown";
27ece4e512SSukadev Bhattiprolu }
28ece4e512SSukadev Bhattiprolu }
29ece4e512SSukadev Bhattiprolu
info_show(struct seq_file * s,void * private)30267acedfSYangtao Li static int info_show(struct seq_file *s, void *private)
31ece4e512SSukadev Bhattiprolu {
32*7bc6f71bSHaren Myneni struct pnv_vas_window *window = s->private;
33ece4e512SSukadev Bhattiprolu
34ece4e512SSukadev Bhattiprolu mutex_lock(&vas_mutex);
35ece4e512SSukadev Bhattiprolu
36ece4e512SSukadev Bhattiprolu /* ensure window is not unmapped */
37ece4e512SSukadev Bhattiprolu if (!window->hvwc_map)
38ece4e512SSukadev Bhattiprolu goto unlock;
39ece4e512SSukadev Bhattiprolu
40*7bc6f71bSHaren Myneni seq_printf(s, "Type: %s, %s\n", cop_to_str(window->vas_win.cop),
41ece4e512SSukadev Bhattiprolu window->tx_win ? "Send" : "Receive");
42*7bc6f71bSHaren Myneni seq_printf(s, "Pid : %d\n", vas_window_pid(&window->vas_win));
43ece4e512SSukadev Bhattiprolu
44ece4e512SSukadev Bhattiprolu unlock:
45ece4e512SSukadev Bhattiprolu mutex_unlock(&vas_mutex);
46ece4e512SSukadev Bhattiprolu return 0;
47ece4e512SSukadev Bhattiprolu }
48ece4e512SSukadev Bhattiprolu
49267acedfSYangtao Li DEFINE_SHOW_ATTRIBUTE(info);
50ece4e512SSukadev Bhattiprolu
print_reg(struct seq_file * s,struct pnv_vas_window * win,char * name,u32 reg)51*7bc6f71bSHaren Myneni static inline void print_reg(struct seq_file *s, struct pnv_vas_window *win,
52ece4e512SSukadev Bhattiprolu char *name, u32 reg)
53ece4e512SSukadev Bhattiprolu {
54ece4e512SSukadev Bhattiprolu seq_printf(s, "0x%016llx %s\n", read_hvwc_reg(win, name, reg), name);
55ece4e512SSukadev Bhattiprolu }
56ece4e512SSukadev Bhattiprolu
hvwc_show(struct seq_file * s,void * private)57267acedfSYangtao Li static int hvwc_show(struct seq_file *s, void *private)
58ece4e512SSukadev Bhattiprolu {
59*7bc6f71bSHaren Myneni struct pnv_vas_window *window = s->private;
60ece4e512SSukadev Bhattiprolu
61ece4e512SSukadev Bhattiprolu mutex_lock(&vas_mutex);
62ece4e512SSukadev Bhattiprolu
63ece4e512SSukadev Bhattiprolu /* ensure window is not unmapped */
64ece4e512SSukadev Bhattiprolu if (!window->hvwc_map)
65ece4e512SSukadev Bhattiprolu goto unlock;
66ece4e512SSukadev Bhattiprolu
67ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(LPID));
68ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(PID));
69ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(XLATE_MSR));
70ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(XLATE_LPCR));
71ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(XLATE_CTL));
72ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(AMR));
73ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(SEIDR));
74ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(FAULT_TX_WIN));
75ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(OSU_INTR_SRC_RA));
76ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(HV_INTR_SRC_RA));
77ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(PSWID));
78ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(LFIFO_BAR));
79ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(LDATA_STAMP_CTL));
80ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(LDMA_CACHE_CTL));
81ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(LRFIFO_PUSH));
82ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(CURR_MSG_COUNT));
83ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(LNOTIFY_AFTER_COUNT));
84ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(LRX_WCRED));
85ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(LRX_WCRED_ADDER));
86ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(TX_WCRED));
87ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(TX_WCRED_ADDER));
88ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(LFIFO_SIZE));
89ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(WINCTL));
90ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(WIN_STATUS));
91ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(WIN_CTX_CACHING_CTL));
92ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(TX_RSVD_BUF_COUNT));
93ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(LRFIFO_WIN_PTR));
94ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(LNOTIFY_CTL));
95ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(LNOTIFY_PID));
96ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(LNOTIFY_LPID));
97ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(LNOTIFY_TID));
98ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(LNOTIFY_SCOPE));
99ece4e512SSukadev Bhattiprolu print_reg(s, window, VREG(NX_UTIL_ADDER));
100ece4e512SSukadev Bhattiprolu unlock:
101ece4e512SSukadev Bhattiprolu mutex_unlock(&vas_mutex);
102ece4e512SSukadev Bhattiprolu return 0;
103ece4e512SSukadev Bhattiprolu }
104ece4e512SSukadev Bhattiprolu
105267acedfSYangtao Li DEFINE_SHOW_ATTRIBUTE(hvwc);
106ece4e512SSukadev Bhattiprolu
vas_window_free_dbgdir(struct pnv_vas_window * pnv_win)107*7bc6f71bSHaren Myneni void vas_window_free_dbgdir(struct pnv_vas_window *pnv_win)
108ece4e512SSukadev Bhattiprolu {
109*7bc6f71bSHaren Myneni struct vas_window *window = &pnv_win->vas_win;
110*7bc6f71bSHaren Myneni
111ece4e512SSukadev Bhattiprolu if (window->dbgdir) {
112ece4e512SSukadev Bhattiprolu debugfs_remove_recursive(window->dbgdir);
113ece4e512SSukadev Bhattiprolu kfree(window->dbgname);
114ece4e512SSukadev Bhattiprolu window->dbgdir = NULL;
115ece4e512SSukadev Bhattiprolu window->dbgname = NULL;
116ece4e512SSukadev Bhattiprolu }
117ece4e512SSukadev Bhattiprolu }
118ece4e512SSukadev Bhattiprolu
vas_window_init_dbgdir(struct pnv_vas_window * window)119*7bc6f71bSHaren Myneni void vas_window_init_dbgdir(struct pnv_vas_window *window)
120ece4e512SSukadev Bhattiprolu {
121f344f0abSGreg Kroah-Hartman struct dentry *d;
122ece4e512SSukadev Bhattiprolu
123ece4e512SSukadev Bhattiprolu if (!window->vinst->dbgdir)
124ece4e512SSukadev Bhattiprolu return;
125ece4e512SSukadev Bhattiprolu
126*7bc6f71bSHaren Myneni window->vas_win.dbgname = kzalloc(16, GFP_KERNEL);
127*7bc6f71bSHaren Myneni if (!window->vas_win.dbgname)
128ece4e512SSukadev Bhattiprolu return;
129ece4e512SSukadev Bhattiprolu
130*7bc6f71bSHaren Myneni snprintf(window->vas_win.dbgname, 16, "w%d", window->vas_win.winid);
131ece4e512SSukadev Bhattiprolu
132*7bc6f71bSHaren Myneni d = debugfs_create_dir(window->vas_win.dbgname, window->vinst->dbgdir);
133*7bc6f71bSHaren Myneni window->vas_win.dbgdir = d;
134ece4e512SSukadev Bhattiprolu
135f344f0abSGreg Kroah-Hartman debugfs_create_file("info", 0444, d, window, &info_fops);
136f344f0abSGreg Kroah-Hartman debugfs_create_file("hvwc", 0444, d, window, &hvwc_fops);
137ece4e512SSukadev Bhattiprolu }
138ece4e512SSukadev Bhattiprolu
vas_instance_init_dbgdir(struct vas_instance * vinst)139ece4e512SSukadev Bhattiprolu void vas_instance_init_dbgdir(struct vas_instance *vinst)
140ece4e512SSukadev Bhattiprolu {
141ece4e512SSukadev Bhattiprolu struct dentry *d;
142ece4e512SSukadev Bhattiprolu
14345ddea8aSSukadev Bhattiprolu vas_init_dbgdir();
144ece4e512SSukadev Bhattiprolu
145ece4e512SSukadev Bhattiprolu vinst->dbgname = kzalloc(16, GFP_KERNEL);
146ece4e512SSukadev Bhattiprolu if (!vinst->dbgname)
147ece4e512SSukadev Bhattiprolu return;
148ece4e512SSukadev Bhattiprolu
149ece4e512SSukadev Bhattiprolu snprintf(vinst->dbgname, 16, "v%d", vinst->vas_id);
150ece4e512SSukadev Bhattiprolu
151ece4e512SSukadev Bhattiprolu d = debugfs_create_dir(vinst->dbgname, vas_debugfs);
152ece4e512SSukadev Bhattiprolu vinst->dbgdir = d;
153ece4e512SSukadev Bhattiprolu }
154ece4e512SSukadev Bhattiprolu
15545ddea8aSSukadev Bhattiprolu /*
15645ddea8aSSukadev Bhattiprolu * Set up the "root" VAS debugfs dir. Return if we already set it up
15745ddea8aSSukadev Bhattiprolu * (or failed to) in an earlier instance of VAS.
15845ddea8aSSukadev Bhattiprolu */
vas_init_dbgdir(void)159ece4e512SSukadev Bhattiprolu void vas_init_dbgdir(void)
160ece4e512SSukadev Bhattiprolu {
16145ddea8aSSukadev Bhattiprolu static bool first_time = true;
16245ddea8aSSukadev Bhattiprolu
16345ddea8aSSukadev Bhattiprolu if (!first_time)
16445ddea8aSSukadev Bhattiprolu return;
16545ddea8aSSukadev Bhattiprolu
16645ddea8aSSukadev Bhattiprolu first_time = false;
167ece4e512SSukadev Bhattiprolu vas_debugfs = debugfs_create_dir("vas", NULL);
168ece4e512SSukadev Bhattiprolu }
169