treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156
[linux-block.git] / drivers / misc / sgi-gru / gruprocfs.c
CommitLineData
1a59d1b8 1// SPDX-License-Identifier: GPL-2.0-or-later
1d09d737
JS
2/*
3 * SN Platform GRU Driver
4 *
5 * PROC INTERFACES
6 *
7 * This file supports the /proc interfaces for the GRU driver
8 *
9 * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
1d09d737
JS
10 */
11
12#include <linux/proc_fs.h>
13#include <linux/device.h>
14#include <linux/seq_file.h>
15#include <linux/uaccess.h>
16#include "gru.h"
17#include "grulib.h"
18#include "grutables.h"
19
20#define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
21
22static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
23{
24 unsigned long val = atomic_long_read(v);
25
563447d7 26 seq_printf(s, "%16lu %s\n", val, id);
1d09d737
JS
27}
28
29static int statistics_show(struct seq_file *s, void *p)
30{
31 printstat(s, vdata_alloc);
32 printstat(s, vdata_free);
33 printstat(s, gts_alloc);
34 printstat(s, gts_free);
563447d7
JS
35 printstat(s, gms_alloc);
36 printstat(s, gms_free);
1d09d737
JS
37 printstat(s, gts_double_allocate);
38 printstat(s, assign_context);
39 printstat(s, assign_context_failed);
40 printstat(s, free_context);
836ce679
JS
41 printstat(s, load_user_context);
42 printstat(s, load_kernel_context);
43 printstat(s, lock_kernel_context);
44 printstat(s, unlock_kernel_context);
45 printstat(s, steal_user_context);
46 printstat(s, steal_kernel_context);
1d09d737
JS
47 printstat(s, steal_context_failed);
48 printstat(s, nopfn);
1d09d737
JS
49 printstat(s, asid_new);
50 printstat(s, asid_next);
51 printstat(s, asid_wrap);
52 printstat(s, asid_reuse);
53 printstat(s, intr);
563447d7
JS
54 printstat(s, intr_cbr);
55 printstat(s, intr_tfh);
2ce4d4c9 56 printstat(s, intr_spurious);
43884604 57 printstat(s, intr_mm_lock_failed);
1d09d737 58 printstat(s, call_os);
1d09d737
JS
59 printstat(s, call_os_wait_queue);
60 printstat(s, user_flush_tlb);
61 printstat(s, user_unload_context);
62 printstat(s, user_exception);
92b39388 63 printstat(s, set_context_option);
55484c45
JS
64 printstat(s, check_context_retarget_intr);
65 printstat(s, check_context_unload);
1d09d737 66 printstat(s, tlb_dropin);
c550222f 67 printstat(s, tlb_preload_page);
1d09d737
JS
68 printstat(s, tlb_dropin_fail_no_asid);
69 printstat(s, tlb_dropin_fail_upm);
70 printstat(s, tlb_dropin_fail_invalid);
71 printstat(s, tlb_dropin_fail_range_active);
72 printstat(s, tlb_dropin_fail_idle);
73 printstat(s, tlb_dropin_fail_fmm);
cd1334f0 74 printstat(s, tlb_dropin_fail_no_exception);
270952a9 75 printstat(s, tfh_stale_on_fault);
1d09d737
JS
76 printstat(s, mmu_invalidate_range);
77 printstat(s, mmu_invalidate_page);
1d09d737
JS
78 printstat(s, flush_tlb);
79 printstat(s, flush_tlb_gru);
80 printstat(s, flush_tlb_gru_tgh);
81 printstat(s, flush_tlb_gru_zero_asid);
82 printstat(s, copy_gpa);
289750d1 83 printstat(s, read_gpa);
1d09d737
JS
84 printstat(s, mesq_receive);
85 printstat(s, mesq_receive_none);
86 printstat(s, mesq_send);
87 printstat(s, mesq_send_failed);
88 printstat(s, mesq_noop);
89 printstat(s, mesq_send_unexpected_error);
90 printstat(s, mesq_send_lb_overflow);
91 printstat(s, mesq_send_qlimit_reached);
92 printstat(s, mesq_send_amo_nacked);
93 printstat(s, mesq_send_put_nacked);
1d09d737
JS
94 printstat(s, mesq_qf_locked);
95 printstat(s, mesq_qf_noop_not_full);
96 printstat(s, mesq_qf_switch_head_failed);
97 printstat(s, mesq_qf_unexpected_error);
98 printstat(s, mesq_noop_unexpected_error);
99 printstat(s, mesq_noop_lb_overflow);
100 printstat(s, mesq_noop_qlimit_reached);
101 printstat(s, mesq_noop_amo_nacked);
102 printstat(s, mesq_noop_put_nacked);
563447d7 103 printstat(s, mesq_noop_page_overflow);
1d09d737
JS
104 return 0;
105}
106
107static ssize_t statistics_write(struct file *file, const char __user *userbuf,
108 size_t count, loff_t *data)
109{
110 memset(&gru_stats, 0, sizeof(gru_stats));
111 return count;
112}
113
e56484da
JS
114static int mcs_statistics_show(struct seq_file *s, void *p)
115{
116 int op;
117 unsigned long total, count, max;
118 static char *id[] = {"cch_allocate", "cch_start", "cch_interrupt",
c550222f
JS
119 "cch_interrupt_sync", "cch_deallocate", "tfh_write_only",
120 "tfh_write_restart", "tgh_invalidate"};
e56484da 121
563447d7 122 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
e56484da
JS
123 for (op = 0; op < mcsop_last; op++) {
124 count = atomic_long_read(&mcs_op_statistics[op].count);
125 total = atomic_long_read(&mcs_op_statistics[op].total);
126 max = mcs_op_statistics[op].max;
127 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
128 count ? total / count : 0, max);
129 }
130 return 0;
131}
132
133static ssize_t mcs_statistics_write(struct file *file,
134 const char __user *userbuf, size_t count, loff_t *data)
135{
136 memset(mcs_op_statistics, 0, sizeof(mcs_op_statistics));
137 return count;
138}
139
1d09d737
JS
140static int options_show(struct seq_file *s, void *p)
141{
563447d7 142 seq_printf(s, "#bitmask: 1=trace, 2=statistics\n");
9ca8e40c 143 seq_printf(s, "0x%lx\n", gru_options);
1d09d737
JS
144 return 0;
145}
146
147static ssize_t options_write(struct file *file, const char __user *userbuf,
148 size_t count, loff_t *data)
149{
f7b41276 150 int ret;
1d09d737 151
f7b41276
JH
152 ret = kstrtoul_from_user(userbuf, count, 0, &gru_options);
153 if (ret)
154 return ret;
1d09d737
JS
155
156 return count;
157}
158
159static int cch_seq_show(struct seq_file *file, void *data)
160{
161 long gid = *(long *)data;
162 int i;
163 struct gru_state *gru = GID_TO_GRU(gid);
164 struct gru_thread_state *ts;
165 const char *mode[] = { "??", "UPM", "INTR", "OS_POLL" };
166
167 if (gid == 0)
563447d7
JS
168 seq_printf(file, "#%5s%5s%6s%7s%9s%6s%8s%8s\n", "gid", "bid",
169 "ctx#", "asid", "pid", "cbrs", "dsbytes", "mode");
1d09d737
JS
170 if (gru)
171 for (i = 0; i < GRU_NUM_CCH; i++) {
172 ts = gru->gs_gts[i];
173 if (!ts)
174 continue;
563447d7 175 seq_printf(file, " %5d%5d%6d%7d%9d%6d%8d%8s\n",
1d09d737 176 gru->gs_gid, gru->gs_blade_id, i,
563447d7
JS
177 is_kernel_context(ts) ? 0 : ts->ts_gms->ms_asids[gid].mt_asid,
178 is_kernel_context(ts) ? 0 : ts->ts_tgid_owner,
1d09d737
JS
179 ts->ts_cbr_au_count * GRU_CBR_AU_SIZE,
180 ts->ts_cbr_au_count * GRU_DSR_AU_BYTES,
181 mode[ts->ts_user_options &
182 GRU_OPT_MISS_MASK]);
183 }
184
185 return 0;
186}
187
188static int gru_seq_show(struct seq_file *file, void *data)
189{
190 long gid = *(long *)data, ctxfree, cbrfree, dsrfree;
191 struct gru_state *gru = GID_TO_GRU(gid);
192
193 if (gid == 0) {
194 seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "gid", "nid",
195 "ctx", "cbr", "dsr", "ctx", "cbr", "dsr");
196 seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "", "", "busy",
197 "busy", "busy", "free", "free", "free");
198 }
199 if (gru) {
200 ctxfree = GRU_NUM_CCH - gru->gs_active_contexts;
201 cbrfree = hweight64(gru->gs_cbr_map) * GRU_CBR_AU_SIZE;
202 dsrfree = hweight64(gru->gs_dsr_map) * GRU_DSR_AU_BYTES;
203 seq_printf(file, " %5d%5d%7ld%6ld%6ld%8ld%6ld%6ld\n",
204 gru->gs_gid, gru->gs_blade_id, GRU_NUM_CCH - ctxfree,
205 GRU_NUM_CBE - cbrfree, GRU_NUM_DSR_BYTES - dsrfree,
206 ctxfree, cbrfree, dsrfree);
207 }
208
209 return 0;
210}
211
212static void seq_stop(struct seq_file *file, void *data)
213{
214}
215
216static void *seq_start(struct seq_file *file, loff_t *gid)
217{
e1c3219d 218 if (*gid < gru_max_gids)
1d09d737
JS
219 return gid;
220 return NULL;
221}
222
223static void *seq_next(struct seq_file *file, void *data, loff_t *gid)
224{
225 (*gid)++;
e1c3219d 226 if (*gid < gru_max_gids)
1d09d737
JS
227 return gid;
228 return NULL;
229}
230
231static const struct seq_operations cch_seq_ops = {
232 .start = seq_start,
233 .next = seq_next,
234 .stop = seq_stop,
235 .show = cch_seq_show
236};
237
238static const struct seq_operations gru_seq_ops = {
239 .start = seq_start,
240 .next = seq_next,
241 .stop = seq_stop,
242 .show = gru_seq_show
243};
244
245static int statistics_open(struct inode *inode, struct file *file)
246{
247 return single_open(file, statistics_show, NULL);
248}
249
e56484da
JS
250static int mcs_statistics_open(struct inode *inode, struct file *file)
251{
252 return single_open(file, mcs_statistics_show, NULL);
253}
254
1d09d737
JS
255static int options_open(struct inode *inode, struct file *file)
256{
257 return single_open(file, options_show, NULL);
258}
259
1d09d737
JS
260/* *INDENT-OFF* */
261static const struct file_operations statistics_fops = {
262 .open = statistics_open,
263 .read = seq_read,
264 .write = statistics_write,
265 .llseek = seq_lseek,
266 .release = single_release,
267};
268
e56484da
JS
269static const struct file_operations mcs_statistics_fops = {
270 .open = mcs_statistics_open,
271 .read = seq_read,
272 .write = mcs_statistics_write,
273 .llseek = seq_lseek,
274 .release = single_release,
275};
276
1d09d737
JS
277static const struct file_operations options_fops = {
278 .open = options_open,
279 .read = seq_read,
280 .write = options_write,
281 .llseek = seq_lseek,
282 .release = single_release,
283};
284
1d09d737
JS
285static struct proc_dir_entry *proc_gru __read_mostly;
286
1d09d737
JS
287int gru_proc_init(void)
288{
1d09d737 289 proc_gru = proc_mkdir("sgi_uv/gru", NULL);
978547c5
CH
290 if (!proc_gru)
291 return -1;
292 if (!proc_create("statistics", 0644, proc_gru, &statistics_fops))
293 goto err;
294 if (!proc_create("mcs_statistics", 0644, proc_gru, &mcs_statistics_fops))
295 goto err;
296 if (!proc_create("debug_options", 0644, proc_gru, &options_fops))
297 goto err;
298 if (!proc_create_seq("cch_status", 0444, proc_gru, &cch_seq_ops))
299 goto err;
300 if (!proc_create_seq("gru_status", 0444, proc_gru, &gru_seq_ops))
301 goto err;
1d09d737 302 return 0;
1d09d737 303err:
978547c5 304 remove_proc_subtree("sgi_uv/gru", NULL);
1d09d737
JS
305 return -1;
306}
307
308void gru_proc_exit(void)
309{
978547c5 310 remove_proc_subtree("sgi_uv/gru", NULL);
1d09d737 311}