Skip to content

Commit dbc8876

Browse files
CiunasBennettherbertx
authored andcommitted
crypto: qat - add rp2svc sysfs attribute
Add the attribute `rp2svc` to the `qat` attribute group. This provides a way for a user to query a specific ring pair for the type of service that is currently configured for. When read, the service will be returned for the defined ring pair. When written to this value will be stored as the ring pair to return the service of. Signed-off-by: Ciunas Bennett <ciunas.bennett@intel.com> Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Reviewed-by: Damian Muszynski <damian.muszynski@intel.com> Reviewed-by: Tero Kristo <tero.kristo@linux.intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent db74e16 commit dbc8876

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

Documentation/ABI/testing/sysfs-driver-qat

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,35 @@ Description: (RW) This configuration option provides a way to force the device i
9595
0
9696

9797
This attribute is only available for qat_4xxx devices.
98+
99+
What: /sys/bus/pci/devices/<BDF>/qat/rp2srv
100+
Date: January 2024
101+
KernelVersion: 6.7
102+
Contact: qat-linux@intel.com
103+
Description:
104+
(RW) This attribute provides a way for a user to query a
105+
specific ring pair for the type of service that it is currently
106+
configured for.
107+
108+
When written to, the value is cached and used to perform the
109+
read operation. Allowed values are in the range 0 to N-1, where
110+
N is the max number of ring pairs supported by a device. This
111+
can be queried using the attribute qat/num_rps.
112+
113+
A read returns the service associated to the ring pair queried.
114+
115+
The values are:
116+
117+
* dc: the ring pair is configured for running compression services
118+
* sym: the ring pair is configured for running symmetric crypto
119+
services
120+
* asym: the ring pair is configured for running asymmetric crypto
121+
services
122+
123+
Example usage::
124+
125+
# echo 1 > /sys/bus/pci/devices/<BDF>/qat/rp2srv
126+
# cat /sys/bus/pci/devices/<BDF>/qat/rp2srv
127+
sym
128+
129+
This attribute is only available for qat_4xxx devices.

drivers/crypto/intel/qat/qat_common/adf_accel_devices.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ struct adf_pm {
340340
char __user *buf, size_t count, loff_t *pos);
341341
};
342342

343+
struct adf_sysfs {
344+
int ring_num;
345+
struct rw_semaphore lock; /* protects access to the fields in this struct */
346+
};
347+
343348
struct adf_accel_dev {
344349
struct adf_etr_data *transport;
345350
struct adf_hw_device_data *hw_device;
@@ -361,6 +366,7 @@ struct adf_accel_dev {
361366
struct adf_timer *timer;
362367
struct adf_heartbeat *heartbeat;
363368
struct adf_rl *rate_limiting;
369+
struct adf_sysfs sysfs;
364370
union {
365371
struct {
366372
/* protects VF2PF interrupts access */

drivers/crypto/intel/qat/qat_common/adf_sysfs.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "adf_cfg_services.h"
99
#include "adf_common_drv.h"
1010

11+
#define UNSET_RING_NUM -1
12+
1113
static const char * const state_operations[] = {
1214
[DEV_DOWN] = "down",
1315
[DEV_UP] = "up",
@@ -205,10 +207,72 @@ static DEVICE_ATTR_RW(pm_idle_enabled);
205207
static DEVICE_ATTR_RW(state);
206208
static DEVICE_ATTR_RW(cfg_services);
207209

210+
static ssize_t rp2srv_show(struct device *dev, struct device_attribute *attr,
211+
char *buf)
212+
{
213+
struct adf_hw_device_data *hw_data;
214+
struct adf_accel_dev *accel_dev;
215+
enum adf_cfg_service_type svc;
216+
217+
accel_dev = adf_devmgr_pci_to_accel_dev(to_pci_dev(dev));
218+
hw_data = GET_HW_DATA(accel_dev);
219+
220+
if (accel_dev->sysfs.ring_num == UNSET_RING_NUM)
221+
return -EINVAL;
222+
223+
down_read(&accel_dev->sysfs.lock);
224+
svc = GET_SRV_TYPE(accel_dev, accel_dev->sysfs.ring_num %
225+
hw_data->num_banks_per_vf);
226+
up_read(&accel_dev->sysfs.lock);
227+
228+
switch (svc) {
229+
case COMP:
230+
return sysfs_emit(buf, "%s\n", ADF_CFG_DC);
231+
case SYM:
232+
return sysfs_emit(buf, "%s\n", ADF_CFG_SYM);
233+
case ASYM:
234+
return sysfs_emit(buf, "%s\n", ADF_CFG_ASYM);
235+
default:
236+
break;
237+
}
238+
return -EINVAL;
239+
}
240+
241+
static ssize_t rp2srv_store(struct device *dev, struct device_attribute *attr,
242+
const char *buf, size_t count)
243+
{
244+
struct adf_accel_dev *accel_dev;
245+
int ring, num_rings, ret;
246+
247+
accel_dev = adf_devmgr_pci_to_accel_dev(to_pci_dev(dev));
248+
if (!accel_dev)
249+
return -EINVAL;
250+
251+
ret = kstrtouint(buf, 10, &ring);
252+
if (ret)
253+
return ret;
254+
255+
num_rings = GET_MAX_BANKS(accel_dev);
256+
if (ring >= num_rings) {
257+
dev_err(&GET_DEV(accel_dev),
258+
"Device does not support more than %u ring pairs\n",
259+
num_rings);
260+
return -EINVAL;
261+
}
262+
263+
down_write(&accel_dev->sysfs.lock);
264+
accel_dev->sysfs.ring_num = ring;
265+
up_write(&accel_dev->sysfs.lock);
266+
267+
return count;
268+
}
269+
static DEVICE_ATTR_RW(rp2srv);
270+
208271
static struct attribute *qat_attrs[] = {
209272
&dev_attr_state.attr,
210273
&dev_attr_cfg_services.attr,
211274
&dev_attr_pm_idle_enabled.attr,
275+
&dev_attr_rp2srv.attr,
212276
NULL,
213277
};
214278

@@ -227,6 +291,8 @@ int adf_sysfs_init(struct adf_accel_dev *accel_dev)
227291
"Failed to create qat attribute group: %d\n", ret);
228292
}
229293

294+
accel_dev->sysfs.ring_num = UNSET_RING_NUM;
295+
230296
return ret;
231297
}
232298
EXPORT_SYMBOL_GPL(adf_sysfs_init);

0 commit comments

Comments
 (0)