1 // SPDX-License-Identifier: GPL-2.0-only
3 * IBM Accelerator Family 'GenWQE'
5 * (C) Copyright IBM Corp. 2013
7 * Author: Frank Haverkamp <haver@linux.vnet.ibm.com>
8 * Author: Joerg-Stephan Vogt <jsvogt@de.ibm.com>
9 * Author: Michael Jung <mijung@gmx.net>
10 * Author: Michael Ruettger <michael@ibmra.de>
14 * Sysfs interfaces for the GenWQE card. There are attributes to query
15 * the version of the bitstream as well as some for the driver. For
16 * debugging, please also see the debugfs interfaces of this driver.
19 #include <linux/kernel.h>
20 #include <linux/types.h>
21 #include <linux/module.h>
22 #include <linux/pci.h>
23 #include <linux/string.h>
25 #include <linux/sysfs.h>
26 #include <linux/ctype.h>
27 #include <linux/device.h>
29 #include "card_base.h"
30 #include "card_ddcb.h"
32 static const char * const genwqe_types
[] = {
33 [GENWQE_TYPE_ALTERA_230
] = "GenWQE4-230",
34 [GENWQE_TYPE_ALTERA_530
] = "GenWQE4-530",
35 [GENWQE_TYPE_ALTERA_A4
] = "GenWQE5-A4",
36 [GENWQE_TYPE_ALTERA_A7
] = "GenWQE5-A7",
39 static ssize_t
status_show(struct device
*dev
, struct device_attribute
*attr
,
42 struct genwqe_dev
*cd
= dev_get_drvdata(dev
);
43 const char *cs
[GENWQE_CARD_STATE_MAX
] = { "unused", "used", "error" };
45 return sprintf(buf
, "%s\n", cs
[cd
->card_state
]);
47 static DEVICE_ATTR_RO(status
);
49 static ssize_t
appid_show(struct device
*dev
, struct device_attribute
*attr
,
53 struct genwqe_dev
*cd
= dev_get_drvdata(dev
);
55 genwqe_read_app_id(cd
, app_name
, sizeof(app_name
));
56 return sprintf(buf
, "%s\n", app_name
);
58 static DEVICE_ATTR_RO(appid
);
60 static ssize_t
version_show(struct device
*dev
, struct device_attribute
*attr
,
64 struct genwqe_dev
*cd
= dev_get_drvdata(dev
);
66 slu_id
= __genwqe_readq(cd
, IO_SLU_UNITCFG
);
67 app_id
= __genwqe_readq(cd
, IO_APP_UNITCFG
);
69 return sprintf(buf
, "%016llx.%016llx\n", slu_id
, app_id
);
71 static DEVICE_ATTR_RO(version
);
73 static ssize_t
type_show(struct device
*dev
, struct device_attribute
*attr
,
77 struct genwqe_dev
*cd
= dev_get_drvdata(dev
);
79 card_type
= genwqe_card_type(cd
);
80 return sprintf(buf
, "%s\n", (card_type
>= ARRAY_SIZE(genwqe_types
)) ?
81 "invalid" : genwqe_types
[card_type
]);
83 static DEVICE_ATTR_RO(type
);
85 static ssize_t
tempsens_show(struct device
*dev
, struct device_attribute
*attr
,
89 struct genwqe_dev
*cd
= dev_get_drvdata(dev
);
91 tempsens
= __genwqe_readq(cd
, IO_SLU_TEMPERATURE_SENSOR
);
92 return sprintf(buf
, "%016llx\n", tempsens
);
94 static DEVICE_ATTR_RO(tempsens
);
96 static ssize_t
freerunning_timer_show(struct device
*dev
,
97 struct device_attribute
*attr
,
101 struct genwqe_dev
*cd
= dev_get_drvdata(dev
);
103 t
= __genwqe_readq(cd
, IO_SLC_FREE_RUNNING_TIMER
);
104 return sprintf(buf
, "%016llx\n", t
);
106 static DEVICE_ATTR_RO(freerunning_timer
);
108 static ssize_t
queue_working_time_show(struct device
*dev
,
109 struct device_attribute
*attr
,
113 struct genwqe_dev
*cd
= dev_get_drvdata(dev
);
115 t
= __genwqe_readq(cd
, IO_SLC_QUEUE_WTIME
);
116 return sprintf(buf
, "%016llx\n", t
);
118 static DEVICE_ATTR_RO(queue_working_time
);
120 static ssize_t
base_clock_show(struct device
*dev
,
121 struct device_attribute
*attr
,
125 struct genwqe_dev
*cd
= dev_get_drvdata(dev
);
127 base_clock
= genwqe_base_clock_frequency(cd
);
128 return sprintf(buf
, "%lld\n", base_clock
);
130 static DEVICE_ATTR_RO(base_clock
);
133 * curr_bitstream_show() - Show the current bitstream id
135 * There is a bug in some old versions of the CPLD which selects the
136 * bitstream, which causes the IO_SLU_BITSTREAM register to report
137 * unreliable data in very rare cases. This makes this sysfs
138 * unreliable up to the point were a new CPLD version is being used.
140 * Unfortunately there is no automatic way yet to query the CPLD
141 * version, such that you need to manually ensure via programming
142 * tools that you have a recent version of the CPLD software.
144 * The proposed circumvention is to use a special recovery bitstream
145 * on the backup partition (0) to identify problems while loading the
148 static ssize_t
curr_bitstream_show(struct device
*dev
,
149 struct device_attribute
*attr
, char *buf
)
152 struct genwqe_dev
*cd
= dev_get_drvdata(dev
);
154 curr_bitstream
= __genwqe_readq(cd
, IO_SLU_BITSTREAM
) & 0x1;
155 return sprintf(buf
, "%d\n", curr_bitstream
);
157 static DEVICE_ATTR_RO(curr_bitstream
);
160 * next_bitstream_show() - Show the next activated bitstream
162 * IO_SLC_CFGREG_SOFTRESET: This register can only be accessed by the PF.
164 static ssize_t
next_bitstream_show(struct device
*dev
,
165 struct device_attribute
*attr
, char *buf
)
168 struct genwqe_dev
*cd
= dev_get_drvdata(dev
);
170 switch ((cd
->softreset
& 0xc) >> 2) {
181 return sprintf(buf
, "%d\n", next_bitstream
);
184 static ssize_t
next_bitstream_store(struct device
*dev
,
185 struct device_attribute
*attr
,
186 const char *buf
, size_t count
)
189 struct genwqe_dev
*cd
= dev_get_drvdata(dev
);
191 if (kstrtoint(buf
, 0, &partition
) < 0)
196 cd
->softreset
= 0x78;
199 cd
->softreset
= 0x7c;
205 __genwqe_writeq(cd
, IO_SLC_CFGREG_SOFTRESET
, cd
->softreset
);
208 static DEVICE_ATTR_RW(next_bitstream
);
210 static ssize_t
reload_bitstream_store(struct device
*dev
,
211 struct device_attribute
*attr
,
212 const char *buf
, size_t count
)
215 struct genwqe_dev
*cd
= dev_get_drvdata(dev
);
217 if (kstrtoint(buf
, 0, &reload
) < 0)
221 if (cd
->card_state
== GENWQE_CARD_UNUSED
||
222 cd
->card_state
== GENWQE_CARD_USED
)
223 cd
->card_state
= GENWQE_CARD_RELOAD_BITSTREAM
;
232 static DEVICE_ATTR_WO(reload_bitstream
);
235 * Create device_attribute structures / params: name, mode, show, store
236 * additional flag if valid in VF
238 static struct attribute
*genwqe_attributes
[] = {
239 &dev_attr_tempsens
.attr
,
240 &dev_attr_next_bitstream
.attr
,
241 &dev_attr_curr_bitstream
.attr
,
242 &dev_attr_base_clock
.attr
,
244 &dev_attr_version
.attr
,
245 &dev_attr_appid
.attr
,
246 &dev_attr_status
.attr
,
247 &dev_attr_freerunning_timer
.attr
,
248 &dev_attr_queue_working_time
.attr
,
249 &dev_attr_reload_bitstream
.attr
,
253 static struct attribute
*genwqe_normal_attributes
[] = {
255 &dev_attr_version
.attr
,
256 &dev_attr_appid
.attr
,
257 &dev_attr_status
.attr
,
258 &dev_attr_freerunning_timer
.attr
,
259 &dev_attr_queue_working_time
.attr
,
264 * genwqe_is_visible() - Determine if sysfs attribute should be visible or not
266 * VFs have restricted mmio capabilities, so not all sysfs entries
267 * are allowed in VFs.
269 static umode_t
genwqe_is_visible(struct kobject
*kobj
,
270 struct attribute
*attr
, int n
)
273 struct device
*dev
= kobj_to_dev(kobj
);
274 struct genwqe_dev
*cd
= dev_get_drvdata(dev
);
275 umode_t mode
= attr
->mode
;
277 if (genwqe_is_privileged(cd
))
280 for (j
= 0; genwqe_normal_attributes
[j
] != NULL
; j
++)
281 if (genwqe_normal_attributes
[j
] == attr
)
287 static struct attribute_group genwqe_attribute_group
= {
288 .is_visible
= genwqe_is_visible
,
289 .attrs
= genwqe_attributes
,
292 const struct attribute_group
*genwqe_attribute_groups
[] = {
293 &genwqe_attribute_group
,