Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/drivers/s390/cio/cmf.c ($Revision: 1.16 $) | |
3 | * | |
4 | * Linux on zSeries Channel Measurement Facility support | |
5 | * | |
6 | * Copyright 2000,2003 IBM Corporation | |
7 | * | |
8 | * Author: Arnd Bergmann <arndb@de.ibm.com> | |
9 | * | |
10 | * original idea from Natarajan Krishnaswami <nkrishna@us.ibm.com> | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or modify | |
13 | * it under the terms of the GNU General Public License as published by | |
14 | * the Free Software Foundation; either version 2, or (at your option) | |
15 | * any later version. | |
16 | * | |
17 | * This program is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | * GNU General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU General Public License | |
23 | * along with this program; if not, write to the Free Software | |
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
25 | */ | |
26 | ||
27 | #include <linux/bootmem.h> | |
28 | #include <linux/device.h> | |
29 | #include <linux/init.h> | |
30 | #include <linux/list.h> | |
31 | #include <linux/module.h> | |
32 | #include <linux/moduleparam.h> | |
4e57b681 TS |
33 | #include <linux/slab.h> |
34 | #include <linux/timex.h> /* get_clock() */ | |
1da177e4 LT |
35 | |
36 | #include <asm/ccwdev.h> | |
37 | #include <asm/cio.h> | |
38 | #include <asm/cmb.h> | |
4e57b681 | 39 | #include <asm/div64.h> |
1da177e4 LT |
40 | |
41 | #include "cio.h" | |
42 | #include "css.h" | |
43 | #include "device.h" | |
44 | #include "ioasm.h" | |
45 | #include "chsc.h" | |
46 | ||
47 | /* parameter to enable cmf during boot, possible uses are: | |
48 | * "s390cmf" -- enable cmf and allocate 2 MB of ram so measuring can be | |
49 | * used on any subchannel | |
50 | * "s390cmf=<num>" -- enable cmf and allocate enough memory to measure | |
51 | * <num> subchannel, where <num> is an integer | |
52 | * between 1 and 65535, default is 1024 | |
53 | */ | |
54 | #define ARGSTRING "s390cmf" | |
55 | ||
56 | /* indices for READCMB */ | |
57 | enum cmb_index { | |
58 | /* basic and exended format: */ | |
59 | cmb_ssch_rsch_count, | |
60 | cmb_sample_count, | |
61 | cmb_device_connect_time, | |
62 | cmb_function_pending_time, | |
63 | cmb_device_disconnect_time, | |
64 | cmb_control_unit_queuing_time, | |
65 | cmb_device_active_only_time, | |
66 | /* extended format only: */ | |
67 | cmb_device_busy_time, | |
68 | cmb_initial_command_response_time, | |
69 | }; | |
70 | ||
71 | /** | |
72 | * enum cmb_format - types of supported measurement block formats | |
73 | * | |
74 | * @CMF_BASIC: traditional channel measurement blocks supported | |
75 | * by all machines that we run on | |
76 | * @CMF_EXTENDED: improved format that was introduced with the z990 | |
77 | * machine | |
78 | * @CMF_AUTODETECT: default: use extended format when running on a z990 | |
79 | * or later machine, otherwise fall back to basic format | |
80 | **/ | |
81 | enum cmb_format { | |
82 | CMF_BASIC, | |
83 | CMF_EXTENDED, | |
84 | CMF_AUTODETECT = -1, | |
85 | }; | |
86 | /** | |
87 | * format - actual format for all measurement blocks | |
88 | * | |
89 | * The format module parameter can be set to a value of 0 (zero) | |
90 | * or 1, indicating basic or extended format as described for | |
91 | * enum cmb_format. | |
92 | */ | |
93 | static int format = CMF_AUTODETECT; | |
94 | module_param(format, bool, 0444); | |
95 | ||
96 | /** | |
97 | * struct cmb_operations - functions to use depending on cmb_format | |
98 | * | |
99 | * all these functions operate on a struct cmf_device. There is only | |
100 | * one instance of struct cmb_operations because all cmf_device | |
101 | * objects are guaranteed to be of the same type. | |
102 | * | |
103 | * @alloc: allocate memory for a channel measurement block, | |
104 | * either with the help of a special pool or with kmalloc | |
105 | * @free: free memory allocated with @alloc | |
106 | * @set: enable or disable measurement | |
107 | * @readall: read a measurement block in a common format | |
108 | * @reset: clear the data in the associated measurement block and | |
109 | * reset its time stamp | |
110 | */ | |
111 | struct cmb_operations { | |
112 | int (*alloc) (struct ccw_device*); | |
113 | void(*free) (struct ccw_device*); | |
114 | int (*set) (struct ccw_device*, u32); | |
115 | u64 (*read) (struct ccw_device*, int); | |
116 | int (*readall)(struct ccw_device*, struct cmbdata *); | |
117 | void (*reset) (struct ccw_device*); | |
118 | ||
119 | struct attribute_group *attr_group; | |
120 | }; | |
121 | static struct cmb_operations *cmbops; | |
122 | ||
123 | /* our user interface is designed in terms of nanoseconds, | |
124 | * while the hardware measures total times in its own | |
125 | * unit.*/ | |
126 | static inline u64 time_to_nsec(u32 value) | |
127 | { | |
128 | return ((u64)value) * 128000ull; | |
129 | } | |
130 | ||
131 | /* | |
132 | * Users are usually interested in average times, | |
133 | * not accumulated time. | |
134 | * This also helps us with atomicity problems | |
135 | * when reading sinlge values. | |
136 | */ | |
137 | static inline u64 time_to_avg_nsec(u32 value, u32 count) | |
138 | { | |
139 | u64 ret; | |
140 | ||
141 | /* no samples yet, avoid division by 0 */ | |
142 | if (count == 0) | |
143 | return 0; | |
144 | ||
145 |