Skip to content

Commit b903737

Browse files
hmynenimpe
authored andcommitted
powerpc/pseries/vas: sysfs interface to export capabilities
The hypervisor provides the available VAS GZIP capabilities such as default or QoS window type and the target available credits in each type. This patch creates sysfs entries and exports the target, used and the available credits for each feature. This interface can be used by the user space to determine the credits usage or to set the target credits in the case of QoS type (for DLPAR). /sys/devices/vas/vas0/gzip/default_capabilities (default GZIP capabilities) nr_total_credits /* Total credits available. Can be /* changed with DLPAR operation */ nr_used_credits /* Used credits */ /sys/devices/vas/vas0/gzip/qos_capabilities (QoS GZIP capabilities) nr_total_credits nr_used_credits Signed-off-by: Haren Myneni <[email protected]> Reviewed-by: Nicholas Piggin <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent c656cfe commit b903737

File tree

4 files changed

+239
-1
lines changed

4 files changed

+239
-1
lines changed

arch/powerpc/platforms/pseries/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ obj-$(CONFIG_PPC_SVM) += svm.o
2929
obj-$(CONFIG_FA_DUMP) += rtas-fadump.o
3030

3131
obj-$(CONFIG_SUSPEND) += suspend.o
32-
obj-$(CONFIG_PPC_VAS) += vas.o
32+
obj-$(CONFIG_PPC_VAS) += vas.o vas-sysfs.o
3333

3434
obj-$(CONFIG_ARCH_HAS_CC_PLATFORM) += cc_platform.o
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright 2022-23 IBM Corp.
4+
*/
5+
6+
#define pr_fmt(fmt) "vas: " fmt
7+
8+
#include <linux/module.h>
9+
#include <linux/kernel.h>
10+
#include <linux/miscdevice.h>
11+
#include <linux/kobject.h>
12+
#include <linux/slab.h>
13+
#include <linux/mm.h>
14+
15+
#include "vas.h"
16+
17+
#ifdef CONFIG_SYSFS
18+
static struct kobject *pseries_vas_kobj;
19+
static struct kobject *gzip_caps_kobj;
20+
21+
struct vas_caps_entry {
22+
struct kobject kobj;
23+
struct vas_cop_feat_caps *caps;
24+
};
25+
26+
#define to_caps_entry(entry) container_of(entry, struct vas_caps_entry, kobj)
27+
28+
#define sysfs_caps_entry_read(_name) \
29+
static ssize_t _name##_show(struct vas_cop_feat_caps *caps, char *buf) \
30+
{ \
31+
return sprintf(buf, "%d\n", atomic_read(&caps->_name)); \
32+
}
33+
34+
struct vas_sysfs_entry {
35+
struct attribute attr;
36+
ssize_t (*show)(struct vas_cop_feat_caps *, char *);
37+
ssize_t (*store)(struct vas_cop_feat_caps *, const char *, size_t);
38+
};
39+
40+
#define VAS_ATTR_RO(_name) \
41+
sysfs_caps_entry_read(_name); \
42+
static struct vas_sysfs_entry _name##_attribute = __ATTR(_name, \
43+
0444, _name##_show, NULL);
44+
45+
/*
46+
* Create sysfs interface:
47+
* /sys/devices/vas/vas0/gzip/default_capabilities
48+
* This directory contains the following VAS GZIP capabilities
49+
* for the defaule credit type.
50+
* /sys/devices/vas/vas0/gzip/default_capabilities/nr_total_credits
51+
* Total number of default credits assigned to the LPAR which
52+
* can be changed with DLPAR operation.
53+
* /sys/devices/vas/vas0/gzip/default_capabilities/nr_used_credits
54+
* Number of credits used by the user space. One credit will
55+
* be assigned for each window open.
56+
*
57+
* /sys/devices/vas/vas0/gzip/qos_capabilities
58+
* This directory contains the following VAS GZIP capabilities
59+
* for the Quality of Service (QoS) credit type.
60+
* /sys/devices/vas/vas0/gzip/qos_capabilities/nr_total_credits
61+
* Total number of QoS credits assigned to the LPAR. The user
62+
* has to define this value using HMC interface. It can be
63+
* changed dynamically by the user.
64+
* /sys/devices/vas/vas0/gzip/qos_capabilities/nr_used_credits
65+
* Number of credits used by the user space.
66+
*/
67+
68+
VAS_ATTR_RO(nr_total_credits);
69+
VAS_ATTR_RO(nr_used_credits);
70+
71+
static struct attribute *vas_capab_attrs[] = {
72+
&nr_total_credits_attribute.attr,
73+
&nr_used_credits_attribute.attr,
74+
NULL,
75+
};
76+
77+
static ssize_t vas_type_show(struct kobject *kobj, struct attribute *attr,
78+
char *buf)
79+
{
80+
struct vas_caps_entry *centry;
81+
struct vas_cop_feat_caps *caps;
82+
struct vas_sysfs_entry *entry;
83+
84+
centry = to_caps_entry(kobj);
85+
caps = centry->caps;
86+
entry = container_of(attr, struct vas_sysfs_entry, attr);
87+
88+
if (!entry->show)
89+
return -EIO;
90+
91+
return entry->show(caps, buf);
92+
}
93+
94+
static ssize_t vas_type_store(struct kobject *kobj, struct attribute *attr,
95+
const char *buf, size_t count)
96+
{
97+
struct vas_caps_entry *centry;
98+
struct vas_cop_feat_caps *caps;
99+
struct vas_sysfs_entry *entry;
100+
101+
centry = to_caps_entry(kobj);
102+
caps = centry->caps;
103+
entry = container_of(attr, struct vas_sysfs_entry, attr);
104+
if (!entry->store)
105+
return -EIO;
106+
107+
return entry->store(caps, buf, count);
108+
}
109+
110+
static void vas_type_release(struct kobject *kobj)
111+
{
112+
struct vas_caps_entry *centry = to_caps_entry(kobj);
113+
kfree(centry);
114+
}
115+
116+
static const struct sysfs_ops vas_sysfs_ops = {
117+
.show = vas_type_show,
118+
.store = vas_type_store,
119+
};
120+
121+
static struct kobj_type vas_attr_type = {
122+
.release = vas_type_release,
123+
.sysfs_ops = &vas_sysfs_ops,
124+
.default_attrs = vas_capab_attrs,
125+
};
126+
127+
static char *vas_caps_kobj_name(struct vas_cop_feat_caps *caps,
128+
struct kobject **kobj)
129+
{
130+
if (caps->descriptor == VAS_GZIP_QOS_CAPABILITIES) {
131+
*kobj = gzip_caps_kobj;
132+
return "qos_capabilities";
133+
} else if (caps->descriptor == VAS_GZIP_DEFAULT_CAPABILITIES) {
134+
*kobj = gzip_caps_kobj;
135+
return "default_capabilities";
136+
} else
137+
return "Unknown";
138+
}
139+
140+
/*
141+
* Add feature specific capability dir entry.
142+
* Ex: VDefGzip or VQosGzip
143+
*/
144+
int sysfs_add_vas_caps(struct vas_cop_feat_caps *caps)
145+
{
146+
struct vas_caps_entry *centry;
147+
struct kobject *kobj = NULL;
148+
int ret = 0;
149+
char *name;
150+
151+
centry = kzalloc(sizeof(*centry), GFP_KERNEL);
152+
if (!centry)
153+
return -ENOMEM;
154+
155+
kobject_init(&centry->kobj, &vas_attr_type);
156+
centry->caps = caps;
157+
name = vas_caps_kobj_name(caps, &kobj);
158+
159+
if (kobj) {
160+
ret = kobject_add(&centry->kobj, kobj, "%s", name);
161+
162+
if (ret) {
163+
pr_err("VAS: sysfs kobject add / event failed %d\n",
164+
ret);
165+
kobject_put(&centry->kobj);
166+
}
167+
}
168+
169+
return ret;
170+
}
171+
172+
static struct miscdevice vas_miscdev = {
173+
.minor = MISC_DYNAMIC_MINOR,
174+
.name = "vas",
175+
};
176+
177+
/*
178+
* Add VAS and VasCaps (overall capabilities) dir entries.
179+
*/
180+
int __init sysfs_pseries_vas_init(struct vas_all_caps *vas_caps)
181+
{
182+
int ret;
183+
184+
ret = misc_register(&vas_miscdev);
185+
if (ret < 0) {
186+
pr_err("%s: register vas misc device failed\n", __func__);
187+
return ret;
188+
}
189+
190+
/*
191+
* The hypervisor does not expose multiple VAS instances, but can
192+
* see multiple VAS instances on PowerNV. So create 'vas0' directory
193+
* on pseries.
194+
*/
195+
pseries_vas_kobj = kobject_create_and_add("vas0",
196+
&vas_miscdev.this_device->kobj);
197+
if (!pseries_vas_kobj) {
198+
pr_err("Failed to create VAS sysfs entry\n");
199+
return -ENOMEM;
200+
}
201+
202+
if ((vas_caps->feat_type & VAS_GZIP_QOS_FEAT_BIT) ||
203+
(vas_caps->feat_type & VAS_GZIP_DEF_FEAT_BIT)) {
204+
gzip_caps_kobj = kobject_create_and_add("gzip",
205+
pseries_vas_kobj);
206+
if (!gzip_caps_kobj) {
207+
pr_err("Failed to create VAS GZIP capability entry\n");
208+
kobject_put(pseries_vas_kobj);
209+
return -ENOMEM;
210+
}
211+
}
212+
213+
return 0;
214+
}
215+
216+
#else
217+
int sysfs_add_vas_caps(struct vas_cop_feat_caps *caps)
218+
{
219+
return 0;
220+
}
221+
222+
int __init sysfs_pseries_vas_init(struct vas_all_caps *vas_caps)
223+
{
224+
return 0;
225+
}
226+
#endif

arch/powerpc/platforms/pseries/vas.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,10 @@ static int __init get_vas_capabilities(u8 feat, enum vas_cop_feat_type type,
560560
}
561561
}
562562

563+
rc = sysfs_add_vas_caps(caps);
564+
if (rc)
565+
return rc;
566+
563567
copypaste_feat = true;
564568

565569
return 0;
@@ -844,6 +848,8 @@ static int __init pseries_vas_init(void)
844848
caps_all.descriptor = be64_to_cpu(hv_caps->descriptor);
845849
caps_all.feat_type = be64_to_cpu(hv_caps->feat_type);
846850

851+
sysfs_pseries_vas_init(&caps_all);
852+
847853
hv_cop_caps = kmalloc(sizeof(*hv_cop_caps), GFP_KERNEL);
848854
if (!hv_cop_caps) {
849855
rc = -ENOMEM;

arch/powerpc/platforms/pseries/vas.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#define VAS_COPY_PASTE_USER_MODE 0x00000001
3131
#define VAS_COP_OP_USER_MODE 0x00000010
3232

33+
#define VAS_GZIP_QOS_CAPABILITIES 0x56516F73477A6970
34+
#define VAS_GZIP_DEFAULT_CAPABILITIES 0x56446566477A6970
35+
3336
/*
3437
* Co-processor feature - GZIP QoS windows or GZIP default windows
3538
*/
@@ -125,4 +128,7 @@ struct pseries_vas_window {
125128
char *name;
126129
int fault_virq;
127130
};
131+
132+
int sysfs_add_vas_caps(struct vas_cop_feat_caps *caps);
133+
int __init sysfs_pseries_vas_init(struct vas_all_caps *vas_caps);
128134
#endif /* _VAS_H */

0 commit comments

Comments
 (0)