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