diff options
-rw-r--r-- | Documentation/ABI/testing/sysfs-driver-genwqe | 62 | ||||
-rw-r--r-- | drivers/misc/genwqe/card_sysfs.c | 288 |
2 files changed, 350 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-driver-genwqe b/Documentation/ABI/testing/sysfs-driver-genwqe new file mode 100644 index 000000000000..1870737a1f5e --- /dev/null +++ b/Documentation/ABI/testing/sysfs-driver-genwqe | |||
@@ -0,0 +1,62 @@ | |||
1 | What: /sys/class/genwqe/genwqe<n>_card/version | ||
2 | Date: Oct 2013 | ||
3 | Contact: haver@linux.vnet.ibm.com | ||
4 | Description: Unique bitstream identification e.g. | ||
5 | '0000000330336283.00000000475a4950'. | ||
6 | |||
7 | What: /sys/class/genwqe/genwqe<n>_card/appid | ||
8 | Date: Oct 2013 | ||
9 | Contact: haver@linux.vnet.ibm.com | ||
10 | Description: Identifies the currently active card application e.g. 'GZIP' | ||
11 | for compression/decompression. | ||
12 | |||
13 | What: /sys/class/genwqe/genwqe<n>_card/type | ||
14 | Date: Oct 2013 | ||
15 | Contact: haver@linux.vnet.ibm.com | ||
16 | Description: Type of the card e.g. 'GenWQE5-A7'. | ||
17 | |||
18 | What: /sys/class/genwqe/genwqe<n>_card/curr_bitstream | ||
19 | Date: Oct 2013 | ||
20 | Contact: haver@linux.vnet.ibm.com | ||
21 | Description: Currently active bitstream. 1 is default, 0 is backup. | ||
22 | |||
23 | What: /sys/class/genwqe/genwqe<n>_card/next_bitstream | ||
24 | Date: Oct 2013 | ||
25 | Contact: haver@linux.vnet.ibm.com | ||
26 | Description: Interface to set the next bitstream to be used. | ||
27 | |||
28 | What: /sys/class/genwqe/genwqe<n>_card/tempsens | ||
29 | Date: Oct 2013 | ||
30 | Contact: haver@linux.vnet.ibm.com | ||
31 | Description: Interface to read the cards temperature sense register. | ||
32 | |||
33 | What: /sys/class/genwqe/genwqe<n>_card/freerunning_timer | ||
34 | Date: Oct 2013 | ||
35 | Contact: haver@linux.vnet.ibm.com | ||
36 | Description: Interface to read the cards free running timer. | ||
37 | Used for performance and utilization measurements. | ||
38 | |||
39 | What: /sys/class/genwqe/genwqe<n>_card/queue_working_time | ||
40 | Date: Oct 2013 | ||
41 | Contact: haver@linux.vnet.ibm.com | ||
42 | Description: Interface to read queue working time. | ||
43 | Used for performance and utilization measurements. | ||
44 | |||
45 | What: /sys/class/genwqe/genwqe<n>_card/state | ||
46 | Date: Oct 2013 | ||
47 | Contact: haver@linux.vnet.ibm.com | ||
48 | Description: State of the card: "unused", "used", "error". | ||
49 | |||
50 | What: /sys/class/genwqe/genwqe<n>_card/base_clock | ||
51 | Date: Oct 2013 | ||
52 | Contact: haver@linux.vnet.ibm.com | ||
53 | Description: Base clock frequency of the card. | ||
54 | |||
55 | What: /sys/class/genwqe/genwqe<n>_card/device/sriov_numvfs | ||
56 | Date: Oct 2013 | ||
57 | Contact: haver@linux.vnet.ibm.com | ||
58 | Description: Enable VFs (1..15): | ||
59 | sudo sh -c 'echo 15 > \ | ||
60 | /sys/bus/pci/devices/0000\:1b\:00.0/sriov_numvfs' | ||
61 | Disable VFs: | ||
62 | Write a 0 into the same sysfs entry. | ||
diff --git a/drivers/misc/genwqe/card_sysfs.c b/drivers/misc/genwqe/card_sysfs.c new file mode 100644 index 000000000000..a72a99266c3c --- /dev/null +++ b/drivers/misc/genwqe/card_sysfs.c | |||
@@ -0,0 +1,288 @@ | |||
1 | /** | ||
2 | * IBM Accelerator Family 'GenWQE' | ||
3 | * | ||
4 | * (C) Copyright IBM Corp. 2013 | ||
5 | * | ||
6 | * Author: Frank Haverkamp <haver@linux.vnet.ibm.com> | ||
7 | * Author: Joerg-Stephan Vogt <jsvogt@de.ibm.com> | ||
8 | * Author: Michael Jung <mijung@de.ibm.com> | ||
9 | * Author: Michael Ruettger <michael@ibmra.de> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License (version 2 only) | ||
13 | * as published by the Free Software Foundation. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | * Sysfs interfaces for the GenWQE card. There are attributes to query | ||
23 | * the version of the bitstream as well as some for the driver. For | ||
24 | * debugging, please also see the debugfs interfaces of this driver. | ||
25 | */ | ||
26 | |||
27 | #include <linux/version.h> | ||
28 | #include <linux/kernel.h> | ||
29 | #include <linux/types.h> | ||
30 | #include <linux/module.h> | ||
31 | #include <linux/pci.h> | ||
32 | #include <linux/string.h> | ||
33 | #include <linux/fs.h> | ||
34 | #include <linux/sysfs.h> | ||
35 | #include <linux/ctype.h> | ||
36 | #include <linux/device.h> | ||
37 | |||
38 | #include "card_base.h" | ||
39 | #include "card_ddcb.h" | ||
40 | |||
41 | static const char * const genwqe_types[] = { | ||
42 | [GENWQE_TYPE_ALTERA_230] = "GenWQE4-230", | ||
43 | [GENWQE_TYPE_ALTERA_530] = "GenWQE4-530", | ||
44 | [GENWQE_TYPE_ALTERA_A4] = "GenWQE5-A4", | ||
45 | [GENWQE_TYPE_ALTERA_A7] = "GenWQE5-A7", | ||
46 | }; | ||
47 | |||
48 | static ssize_t status_show(struct device *dev, struct device_attribute *attr, | ||
49 | char *buf) | ||
50 | { | ||
51 | struct genwqe_dev *cd = dev_get_drvdata(dev); | ||
52 | const char *cs[GENWQE_CARD_STATE_MAX] = { "unused", "used", "error" }; | ||
53 | |||
54 | return sprintf(buf, "%s\n", cs[cd->card_state]); | ||
55 | } | ||
56 | static DEVICE_ATTR_RO(status); | ||
57 | |||
58 | static ssize_t appid_show(struct device *dev, struct device_attribute *attr, | ||
59 | char *buf) | ||
60 | { | ||
61 | char app_name[5]; | ||
62 | struct genwqe_dev *cd = dev_get_drvdata(dev); | ||
63 | |||
64 | genwqe_read_app_id(cd, app_name, sizeof(app_name)); | ||
65 | return sprintf(buf, "%s\n", app_name); | ||
66 | } | ||
67 | static DEVICE_ATTR_RO(appid); | ||
68 | |||
69 | static ssize_t version_show(struct device *dev, struct device_attribute *attr, | ||
70 | char *buf) | ||
71 | { | ||
72 | u64 slu_id, app_id; | ||
73 | struct genwqe_dev *cd = dev_get_drvdata(dev); | ||
74 | |||
75 | slu_id = __genwqe_readq(cd, IO_SLU_UNITCFG); | ||
76 | app_id = __genwqe_readq(cd, IO_APP_UNITCFG); | ||
77 | |||
78 | return sprintf(buf, "%016llx.%016llx\n", slu_id, app_id); | ||
79 | } | ||
80 | static DEVICE_ATTR_RO(version); | ||
81 | |||
82 | static ssize_t type_show(struct device *dev, struct device_attribute *attr, | ||
83 | char *buf) | ||
84 | { | ||
85 | u8 card_type; | ||
86 | struct genwqe_dev *cd = dev_get_drvdata(dev); | ||
87 | |||
88 | card_type = genwqe_card_type(cd); | ||
89 | return sprintf(buf, "%s\n", (card_type >= ARRAY_SIZE(genwqe_types)) ? | ||
90 | "invalid" : genwqe_types[card_type]); | ||
91 | } | ||
92 | static DEVICE_ATTR_RO(type); | ||
93 | |||
94 | static ssize_t driver_show(struct device *dev, struct device_attribute *attr, | ||
95 | char *buf) | ||
96 | { | ||
97 | return sprintf(buf, "%s\n", DRV_VERS_STRING); | ||
98 | } | ||
99 | static DEVICE_ATTR_RO(driver); | ||
100 | |||
101 | static ssize_t tempsens_show(struct device *dev, struct device_attribute *attr, | ||
102 | char *buf) | ||
103 | { | ||
104 | u64 tempsens; | ||
105 | struct genwqe_dev *cd = dev_get_drvdata(dev); | ||
106 | |||
107 | tempsens = __genwqe_readq(cd, IO_SLU_TEMPERATURE_SENSOR); | ||
108 | return sprintf(buf, "%016llx\n", tempsens); | ||
109 | } | ||
110 | static DEVICE_ATTR_RO(tempsens); | ||
111 | |||
112 | static ssize_t freerunning_timer_show(struct device *dev, | ||
113 | struct device_attribute *attr, | ||
114 | char *buf) | ||
115 | { | ||
116 | u64 t; | ||
117 | struct genwqe_dev *cd = dev_get_drvdata(dev); | ||
118 | |||
119 | t = __genwqe_readq(cd, IO_SLC_FREE_RUNNING_TIMER); | ||
120 | return sprintf(buf, "%016llx\n", t); | ||
121 | } | ||
122 | static DEVICE_ATTR_RO(freerunning_timer); | ||
123 | |||
124 | static ssize_t queue_working_time_show(struct device *dev, | ||
125 | struct device_attribute *attr, | ||
126 | char *buf) | ||
127 | { | ||
128 | u64 t; | ||
129 | struct genwqe_dev *cd = dev_get_drvdata(dev); | ||
130 | |||
131 | t = __genwqe_readq(cd, IO_SLC_QUEUE_WTIME); | ||
132 | return sprintf(buf, "%016llx\n", t); | ||
133 | } | ||
134 | static DEVICE_ATTR_RO(queue_working_time); | ||
135 | |||
136 | static ssize_t base_clock_show(struct device *dev, | ||
137 | struct device_attribute *attr, | ||
138 | char *buf) | ||
139 | { | ||
140 | u64 base_clock; | ||
141 | struct genwqe_dev *cd = dev_get_drvdata(dev); | ||
142 | |||
143 | base_clock = genwqe_base_clock_frequency(cd); | ||
144 | return sprintf(buf, "%lld\n", base_clock); | ||
145 | } | ||
146 | static DEVICE_ATTR_RO(base_clock); | ||
147 | |||
148 | /** | ||
149 | * curr_bitstream_show() - Show the current bitstream id | ||
150 | * | ||
151 | * There is a bug in some old versions of the CPLD which selects the | ||
152 | * bitstream, which causes the IO_SLU_BITSTREAM register to report | ||
153 | * unreliable data in very rare cases. This makes this sysfs | ||
154 | * unreliable up to the point were a new CPLD version is being used. | ||
155 | * | ||
156 | * Unfortunately there is no automatic way yet to query the CPLD | ||
157 | * version, such that you need to manually ensure via programming | ||
158 | * tools that you have a recent version of the CPLD software. | ||
159 | * | ||
160 | * The proposed circumvention is to use a special recovery bitstream | ||
161 | * on the backup partition (0) to identify problems while loading the | ||
162 | * image. | ||
163 | */ | ||
164 | static ssize_t curr_bitstream_show(struct device *dev, | ||
165 | struct device_attribute *attr, char *buf) | ||
166 | { | ||
167 | int curr_bitstream; | ||
168 | struct genwqe_dev *cd = dev_get_drvdata(dev); | ||
169 | |||
170 | curr_bitstream = __genwqe_readq(cd, IO_SLU_BITSTREAM) & 0x1; | ||
171 | return sprintf(buf, "%d\n", curr_bitstream); | ||
172 | } | ||
173 | static DEVICE_ATTR_RO(curr_bitstream); | ||
174 | |||
175 | /** | ||
176 | * next_bitstream_show() - Show the next activated bitstream | ||
177 | * | ||
178 | * IO_SLC_CFGREG_SOFTRESET: This register can only be accessed by the PF. | ||
179 | */ | ||
180 | static ssize_t next_bitstream_show(struct device *dev, | ||
181 | struct device_attribute *attr, char *buf) | ||
182 | { | ||
183 | int next_bitstream; | ||
184 | struct genwqe_dev *cd = dev_get_drvdata(dev); | ||
185 | |||
186 | switch ((cd->softreset & 0xc) >> 2) { | ||
187 | case 0x2: | ||
188 | next_bitstream = 0; | ||
189 | break; | ||
190 | case 0x3: | ||
191 | next_bitstream = 1; | ||
192 | break; | ||
193 | default: | ||
194 | next_bitstream = -1; | ||
195 | break; /* error */ | ||
196 | } | ||
197 | return sprintf(buf, "%d\n", next_bitstream); | ||
198 | } | ||
199 | |||
200 | static ssize_t next_bitstream_store(struct device *dev, | ||
201 | struct device_attribute *attr, | ||
202 | const char *buf, size_t count) | ||
203 | { | ||
204 | int partition; | ||
205 | struct genwqe_dev *cd = dev_get_drvdata(dev); | ||
206 | |||
207 | if (kstrtoint(buf, 0, &partition) < 0) | ||
208 | return -EINVAL; | ||
209 | |||
210 | switch (partition) { | ||
211 | case 0x0: | ||
212 | cd->softreset = 0x78; | ||
213 | break; | ||
214 | case 0x1: | ||
215 | cd->softreset = 0x7c; | ||
216 | break; | ||
217 | default: | ||
218 | return -EINVAL; | ||
219 | } | ||
220 | |||
221 | __genwqe_writeq(cd, IO_SLC_CFGREG_SOFTRESET, cd->softreset); | ||
222 | return count; | ||
223 | } | ||
224 | static DEVICE_ATTR_RW(next_bitstream); | ||
225 | |||
226 | /* | ||
227 | * Create device_attribute structures / params: name, mode, show, store | ||
228 | * additional flag if valid in VF | ||
229 | */ | ||
230 | static struct attribute *genwqe_attributes[] = { | ||
231 | &dev_attr_tempsens.attr, | ||
232 | &dev_attr_next_bitstream.attr, | ||
233 | &dev_attr_curr_bitstream.attr, | ||
234 | &dev_attr_base_clock.attr, | ||
235 | &dev_attr_driver.attr, | ||
236 | &dev_attr_type.attr, | ||
237 | &dev_attr_version.attr, | ||
238 | &dev_attr_appid.attr, | ||
239 | &dev_attr_status.attr, | ||
240 | &dev_attr_freerunning_timer.attr, | ||
241 | &dev_attr_queue_working_time.attr, | ||
242 | NULL, | ||
243 | }; | ||
244 | |||
245 | static struct attribute *genwqe_normal_attributes[] = { | ||
246 | &dev_attr_driver.attr, | ||
247 | &dev_attr_type.attr, | ||
248 | &dev_attr_version.attr, | ||
249 | &dev_attr_appid.attr, | ||
250 | &dev_attr_status.attr, | ||
251 | &dev_attr_freerunning_timer.attr, | ||
252 | &dev_attr_queue_working_time.attr, | ||
253 | NULL, | ||
254 | }; | ||
255 | |||
256 | /** | ||
257 | * genwqe_is_visible() - Determine if sysfs attribute should be visible or not | ||
258 | * | ||
259 | * VFs have restricted mmio capabilities, so not all sysfs entries | ||
260 | * are allowed in VFs. | ||
261 | */ | ||
262 | static umode_t genwqe_is_visible(struct kobject *kobj, | ||
263 | struct attribute *attr, int n) | ||
264 | { | ||
265 | unsigned int j; | ||
266 | struct device *dev = container_of(kobj, struct device, kobj); | ||
267 | struct genwqe_dev *cd = dev_get_drvdata(dev); | ||
268 | umode_t mode = attr->mode; | ||
269 | |||
270 | if (genwqe_is_privileged(cd)) | ||
271 | return mode; | ||
272 | |||
273 | for (j = 0; genwqe_normal_attributes[j] != NULL; j++) | ||
274 | if (genwqe_normal_attributes[j] == attr) | ||
275 | return mode; | ||
276 | |||
277 | return 0; | ||
278 | } | ||
279 | |||
280 | static struct attribute_group genwqe_attribute_group = { | ||
281 | .is_visible = genwqe_is_visible, | ||
282 | .attrs = genwqe_attributes, | ||
283 | }; | ||
284 | |||
285 | const struct attribute_group *genwqe_attribute_groups[] = { | ||
286 | &genwqe_attribute_group, | ||
287 | NULL, | ||
288 | }; | ||