s390/diag: add a statistic for diagnose calls
[linux-2.6-block.git] / arch / s390 / kernel / diag.c
1 /*
2  * Implementation of s390 diagnose codes
3  *
4  * Copyright IBM Corp. 2007
5  * Author(s): Michael Holzheu <holzheu@de.ibm.com>
6  */
7
8 #include <linux/module.h>
9 #include <linux/cpu.h>
10 #include <linux/seq_file.h>
11 #include <linux/debugfs.h>
12 #include <asm/diag.h>
13
14 DEFINE_PER_CPU(struct diag_stat, diag_stat);
15 EXPORT_PER_CPU_SYMBOL(diag_stat);
16
17 struct diag_desc {
18         int code;
19         char *name;
20 };
21
22 static const struct diag_desc diag_map[NR_DIAG_STAT] = {
23         [DIAG_STAT_X008] = { .code = 0x008, .name = "Console Function" },
24         [DIAG_STAT_X00C] = { .code = 0x00c, .name = "Pseudo Timer" },
25         [DIAG_STAT_X010] = { .code = 0x010, .name = "Release Pages" },
26         [DIAG_STAT_X014] = { .code = 0x014, .name = "Spool File Services" },
27         [DIAG_STAT_X044] = { .code = 0x044, .name = "Voluntary Timeslice End" },
28         [DIAG_STAT_X064] = { .code = 0x064, .name = "NSS Manipulation" },
29         [DIAG_STAT_X09C] = { .code = 0x09c, .name = "Relinquish Timeslice" },
30         [DIAG_STAT_X0DC] = { .code = 0x0dc, .name = "Appldata Control" },
31         [DIAG_STAT_X204] = { .code = 0x204, .name = "Logical-CPU Utilization" },
32         [DIAG_STAT_X210] = { .code = 0x210, .name = "Device Information" },
33         [DIAG_STAT_X224] = { .code = 0x224, .name = "EBCDIC-Name Table" },
34         [DIAG_STAT_X250] = { .code = 0x250, .name = "Block I/O" },
35         [DIAG_STAT_X258] = { .code = 0x258, .name = "Page-Reference Services" },
36         [DIAG_STAT_X288] = { .code = 0x288, .name = "Time Bomb" },
37         [DIAG_STAT_X2C4] = { .code = 0x2c4, .name = "FTP Services" },
38         [DIAG_STAT_X2FC] = { .code = 0x2fc, .name = "Guest Performance Data" },
39         [DIAG_STAT_X304] = { .code = 0x304, .name = "Partition-Resource Service" },
40         [DIAG_STAT_X308] = { .code = 0x308, .name = "List-Directed IPL" },
41         [DIAG_STAT_X500] = { .code = 0x500, .name = "Virtio Service" },
42 };
43
44 static int show_diag_stat(struct seq_file *m, void *v)
45 {
46         struct diag_stat *stat;
47         unsigned long n = (unsigned long) v - 1;
48         int cpu, prec, tmp;
49
50         get_online_cpus();
51         if (n == 0) {
52                 seq_puts(m, "         ");
53
54                 for_each_online_cpu(cpu) {
55                         prec = 10;
56                         for (tmp = 10; cpu >= tmp; tmp *= 10)
57                                 prec--;
58                         seq_printf(m, "%*s%d", prec, "CPU", cpu);
59                 }
60                 seq_putc(m, '\n');
61         } else if (n <= NR_DIAG_STAT) {
62                 seq_printf(m, "diag %03x:", diag_map[n-1].code);
63                 for_each_online_cpu(cpu) {
64                         stat = &per_cpu(diag_stat, cpu);
65                         seq_printf(m, " %10u", stat->counter[n-1]);
66                 }
67                 seq_printf(m, "    %s\n", diag_map[n-1].name);
68         }
69         put_online_cpus();
70         return 0;
71 }
72
73 static void *show_diag_stat_start(struct seq_file *m, loff_t *pos)
74 {
75         return *pos <= nr_cpu_ids ? (void *)((unsigned long) *pos + 1) : NULL;
76 }
77
78 static void *show_diag_stat_next(struct seq_file *m, void *v, loff_t *pos)
79 {
80         ++*pos;
81         return show_diag_stat_start(m, pos);
82 }
83
84 static void show_diag_stat_stop(struct seq_file *m, void *v)
85 {
86 }
87
88 static const struct seq_operations show_diag_stat_sops = {
89         .start  = show_diag_stat_start,
90         .next   = show_diag_stat_next,
91         .stop   = show_diag_stat_stop,
92         .show   = show_diag_stat,
93 };
94
95 static int show_diag_stat_open(struct inode *inode, struct file *file)
96 {
97         return seq_open(file, &show_diag_stat_sops);
98 }
99
100 static const struct file_operations show_diag_stat_fops = {
101         .open           = show_diag_stat_open,
102         .read           = seq_read,
103         .llseek         = seq_lseek,
104         .release        = seq_release,
105 };
106
107
108 static int __init show_diag_stat_init(void)
109 {
110         debugfs_create_file("diag_stat", 0400, NULL, NULL,
111                             &show_diag_stat_fops);
112         return 0;
113 }
114
115 device_initcall(show_diag_stat_init);
116
117 /*
118  * Diagnose 14: Input spool file manipulation
119  */
120 static inline int __diag14(unsigned long rx, unsigned long ry1,
121                            unsigned long subcode)
122 {
123         register unsigned long _ry1 asm("2") = ry1;
124         register unsigned long _ry2 asm("3") = subcode;
125         int rc = 0;
126
127         asm volatile(
128                 "   sam31\n"
129                 "   diag    %2,2,0x14\n"
130                 "   sam64\n"
131                 "   ipm     %0\n"
132                 "   srl     %0,28\n"
133                 : "=d" (rc), "+d" (_ry2)
134                 : "d" (rx), "d" (_ry1)
135                 : "cc");
136
137         return rc;
138 }
139
140 int diag14(unsigned long rx, unsigned long ry1, unsigned long subcode)
141 {
142         diag_stat_inc(DIAG_STAT_X014);
143         return __diag14(rx, ry1, subcode);
144 }
145 EXPORT_SYMBOL(diag14);
146
147 /*
148  * Diagnose 210: Get information about a virtual device
149  */
150 int diag210(struct diag210 *addr)
151 {
152         /*
153          * diag 210 needs its data below the 2GB border, so we
154          * use a static data area to be sure
155          */
156         static struct diag210 diag210_tmp;
157         static DEFINE_SPINLOCK(diag210_lock);
158         unsigned long flags;
159         int ccode;
160
161         spin_lock_irqsave(&diag210_lock, flags);
162         diag210_tmp = *addr;
163
164         diag_stat_inc(DIAG_STAT_X210);
165         asm volatile(
166                 "       lhi     %0,-1\n"
167                 "       sam31\n"
168                 "       diag    %1,0,0x210\n"
169                 "0:     ipm     %0\n"
170                 "       srl     %0,28\n"
171                 "1:     sam64\n"
172                 EX_TABLE(0b, 1b)
173                 : "=&d" (ccode) : "a" (&diag210_tmp) : "cc", "memory");
174
175         *addr = diag210_tmp;
176         spin_unlock_irqrestore(&diag210_lock, flags);
177
178         return ccode;
179 }
180 EXPORT_SYMBOL(diag210);