2 * IBM Accelerator Family 'GenWQE'
4 * (C) Copyright IBM Corp. 2013
6 * Author: Frank Haverkamp <haver@linux.vnet.ibm.com>
7 * Author: Joerg-Stephan Vogt <jsvogt@de.ibm.com>
8 * Author: Michael Jung <mijung@gmx.net>
9 * Author: Michael Ruettger <michael@ibmra.de>
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.
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.
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.
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>
34 #include <linux/sysfs.h>
35 #include <linux/ctype.h>
36 #include <linux/device.h>
38 #include "card_base.h"
39 #include "card_ddcb.h"
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",
48 static ssize_t status_show(struct device *dev, struct device_attribute *attr,
51 struct genwqe_dev *cd = dev_get_drvdata(dev);
52 const char *cs[GENWQE_CARD_STATE_MAX] = { "unused", "used", "error" };
54 return sprintf(buf, "%s\n", cs[cd->card_state]);
56 static DEVICE_ATTR_RO(status);
58 static ssize_t appid_show(struct device *dev, struct device_attribute *attr,
62 struct genwqe_dev *cd = dev_get_drvdata(dev);
64 genwqe_read_app_id(cd, app_name, sizeof(app_name));
65 return sprintf(buf, "%s\n", app_name);
67 static DEVICE_ATTR_RO(appid);
69 static ssize_t version_show(struct device *dev, struct device_attribute *attr,
73 struct genwqe_dev *cd = dev_get_drvdata(dev);
75 slu_id = __genwqe_readq(cd, IO_SLU_UNITCFG);
76 app_id = __genwqe_readq(cd, IO_APP_UNITCFG);
78 return sprintf(buf, "%016llx.%016llx\n", slu_id, app_id);
80 static DEVICE_ATTR_RO(version);
82 static ssize_t type_show(struct device *dev, struct device_attribute *attr,
86 struct genwqe_dev *cd = dev_get_drvdata(dev);
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]);
92 static DEVICE_ATTR_RO(type);
94 static ssize_t tempsens_show(struct device *dev, struct device_attribute *attr,
98 struct genwqe_dev *cd = dev_get_drvdata(dev);
100 tempsens = __genwqe_readq(cd, IO_SLU_TEMPERATURE_SENSOR);
101 return sprintf(buf, "%016llx\n", tempsens);
103 static DEVICE_ATTR_RO(tempsens);
105 static ssize_t freerunning_timer_show(struct device *dev,
106 struct device_attribute *attr,
110 struct genwqe_dev *cd = dev_get_drvdata(dev);
112 t = __genwqe_readq(cd, IO_SLC_FREE_RUNNING_TIMER);
113 return sprintf(buf, "%016llx\n", t);
115 static DEVICE_ATTR_RO(freerunning_timer);
117 static ssize_t queue_working_time_show(struct device *dev,
118 struct device_attribute *attr,
122 struct genwqe_dev *cd = dev_get_drvdata(dev);
124 t = __genwqe_readq(cd, IO_SLC_QUEUE_WTIME);
125 return sprintf(buf, "%016llx\n", t);
127 static DEVICE_ATTR_RO(queue_working_time);
129 static ssize_t base_clock_show(struct device *dev,
130 struct device_attribute *attr,
134 struct genwqe_dev *cd = dev_get_drvdata(dev);
136 base_clock = genwqe_base_clock_frequency(cd);
137 return sprintf(buf, "%lld\n", base_clock);
139 static DEVICE_ATTR_RO(base_clock);
142 * curr_bitstream_show() - Show the current bitstream id
144 * There is a bug in some old versions of the CPLD which selects the
145 * bitstream, which causes the IO_SLU_BITSTREAM register to report
146 * unreliable data in very rare cases. This makes this sysfs
147 * unreliable up to the point were a new CPLD version is being used.
149 * Unfortunately there is no automatic way yet to query the CPLD
150 * version, such that you need to manually ensure via programming
151 * tools that you have a recent version of the CPLD software.
153 * The proposed circumvention is to use a special recovery bitstream
154 * on the backup partition (0) to identify problems while loading the
157 static ssize_t curr_bitstream_show(struct device *dev,
158 struct device_attribute *attr, char *buf)
161 struct genwqe_dev *cd = dev_get_drvdata(dev);
163 curr_bitstream = __genwqe_readq(cd, IO_SLU_BITSTREAM) & 0x1;
164 return sprintf(buf, "%d\n", curr_bitstream);
166 static DEVICE_ATTR_RO(curr_bitstream);
169 * next_bitstream_show() - Show the next activated bitstream
171 * IO_SLC_CFGREG_SOFTRESET: This register can only be accessed by the PF.
173 static ssize_t next_bitstream_show(struct device *dev,
174 struct device_attribute *attr, char *buf)
177 struct genwqe_dev *cd = dev_get_drvdata(dev);
179 switch ((cd->softreset & 0xc) >> 2) {
190 return sprintf(buf, "%d\n", next_bitstream);
193 static ssize_t next_bitstream_store(struct device *dev,
194 struct device_attribute *attr,
195 const char *buf, size_t count)
198 struct genwqe_dev *cd = dev_get_drvdata(dev);
200 if (kstrtoint(buf, 0, &partition) < 0)
205 cd->softreset = 0x78;
208 cd->softreset = 0x7c;
214 __genwqe_writeq(cd, IO_SLC_CFGREG_SOFTRESET, cd->softreset);
217 static DEVICE_ATTR_RW(next_bitstream);
219 static ssize_t reload_bitstream_store(struct device *dev,
220 struct device_attribute *attr,
221 const char *buf, size_t count)
224 struct genwqe_dev *cd = dev_get_drvdata(dev);
226 if (kstrtoint(buf, 0, &reload) < 0)
230 if (cd->card_state == GENWQE_CARD_UNUSED ||
231 cd->card_state == GENWQE_CARD_USED)
232 cd->card_state = GENWQE_CARD_RELOAD_BITSTREAM;
241 static DEVICE_ATTR_WO(reload_bitstream);
244 * Create device_attribute structures / params: name, mode, show, store
245 * additional flag if valid in VF
247 static struct attribute *genwqe_attributes[] = {
248 &dev_attr_tempsens.attr,
249 &dev_attr_next_bitstream.attr,
250 &dev_attr_curr_bitstream.attr,
251 &dev_attr_base_clock.attr,
253 &dev_attr_version.attr,
254 &dev_attr_appid.attr,
255 &dev_attr_status.attr,
256 &dev_attr_freerunning_timer.attr,
257 &dev_attr_queue_working_time.attr,
258 &dev_attr_reload_bitstream.attr,
262 static struct attribute *genwqe_normal_attributes[] = {
264 &dev_attr_version.attr,
265 &dev_attr_appid.attr,
266 &dev_attr_status.attr,
267 &dev_attr_freerunning_timer.attr,
268 &dev_attr_queue_working_time.attr,
273 * genwqe_is_visible() - Determine if sysfs attribute should be visible or not
275 * VFs have restricted mmio capabilities, so not all sysfs entries
276 * are allowed in VFs.
278 static umode_t genwqe_is_visible(struct kobject *kobj,
279 struct attribute *attr, int n)
282 struct device *dev = container_of(kobj, struct device, kobj);
283 struct genwqe_dev *cd = dev_get_drvdata(dev);
284 umode_t mode = attr->mode;
286 if (genwqe_is_privileged(cd))
289 for (j = 0; genwqe_normal_attributes[j] != NULL; j++)
290 if (genwqe_normal_attributes[j] == attr)
296 static struct attribute_group genwqe_attribute_group = {
297 .is_visible = genwqe_is_visible,
298 .attrs = genwqe_attributes,
301 const struct attribute_group *genwqe_attribute_groups[] = {
302 &genwqe_attribute_group,