Skip to content

Commit 2382b5a

Browse files
pilotAlpalherbertx
authored andcommitted
crypto: qat - expose pm_idle_enabled through sysfs
Expose 'pm_idle_enabled' sysfs attribute. This attribute controls how idle conditions are handled. If it is set to 1 (idle support enabled) when the device detects an idle condition, the driver will transition the device to the 'MIN' power configuration. In order to set the value of this attribute for a device, the device must be in the 'down' state. This only applies to qat_4xxx generation. Signed-off-by: Lucas Segarra Fernandez <[email protected]> Reviewed-by: Giovanni Cabiddu <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 5005327 commit 2382b5a

File tree

5 files changed

+101
-1
lines changed

5 files changed

+101
-1
lines changed

Documentation/ABI/testing/sysfs-driver-qat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,38 @@ Description: (RW) Reports the current configuration of the QAT device.
5858
dc
5959

6060
This attribute is only available for qat_4xxx devices.
61+
62+
What: /sys/bus/pci/devices/<BDF>/qat/pm_idle_enabled
63+
Date: June 2023
64+
KernelVersion: 6.5
65+
66+
Description: (RW) This configuration option provides a way to force the device into remaining in
67+
the MAX power state.
68+
If idle support is enabled the device will transition to the `MIN` power state when
69+
idle, otherwise will stay in the MAX power state.
70+
Write to the file to enable or disable idle support.
71+
72+
The values are:
73+
74+
* 0: idle support is disabled
75+
* 1: idle support is enabled
76+
77+
Default value is 1.
78+
79+
It is possible to set the pm_idle_enabled value only if the device
80+
is in the `down` state (see /sys/bus/pci/devices/<BDF>/qat/state)
81+
82+
The following example shows how to change the pm_idle_enabled of
83+
a device::
84+
85+
# cat /sys/bus/pci/devices/<BDF>/qat/state
86+
up
87+
# cat /sys/bus/pci/devices/<BDF>/qat/pm_idle_enabled
88+
1
89+
# echo down > /sys/bus/pci/devices/<BDF>/qat/state
90+
# echo 0 > /sys/bus/pci/devices/<BDF>/qat/pm_idle_enabled
91+
# echo up > /sys/bus/pci/devices/<BDF>/qat/state
92+
# cat /sys/bus/pci/devices/<BDF>/qat/pm_idle_enabled
93+
0
94+
95+
This attribute is only available for qat_4xxx devices.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#define ADF_CFG_SYM_DC "sym;dc"
3434
#define ADF_CFG_DC_SYM "dc;sym"
3535
#define ADF_SERVICES_ENABLED "ServicesEnabled"
36+
#define ADF_PM_IDLE_SUPPORT "PmIdleSupport"
3637
#define ADF_ETRMGR_COALESCING_ENABLED "InterruptCoalescingEnabled"
3738
#define ADF_ETRMGR_COALESCING_ENABLED_FORMAT \
3839
ADF_ETRMGR_BANK "%d" ADF_ETRMGR_COALESCING_ENABLED

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,25 @@ struct adf_gen4_pm_data {
2323

2424
static int send_host_msg(struct adf_accel_dev *accel_dev)
2525
{
26+
char pm_idle_support_cfg[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = {};
2627
void __iomem *pmisc = adf_get_pmisc_base(accel_dev);
28+
bool pm_idle_support;
2729
u32 msg;
30+
int ret;
2831

2932
msg = ADF_CSR_RD(pmisc, ADF_GEN4_PM_HOST_MSG);
3033
if (msg & ADF_GEN4_PM_MSG_PENDING)
3134
return -EBUSY;
3235

36+
adf_cfg_get_param_value(accel_dev, ADF_GENERAL_SEC,
37+
ADF_PM_IDLE_SUPPORT, pm_idle_support_cfg);
38+
ret = kstrtobool(pm_idle_support_cfg, &pm_idle_support);
39+
if (ret)
40+
pm_idle_support = true;
41+
3342
/* Send HOST_MSG */
34-
msg = FIELD_PREP(ADF_GEN4_PM_MSG_PAYLOAD_BIT_MASK, PM_SET_MIN);
43+
msg = FIELD_PREP(ADF_GEN4_PM_MSG_PAYLOAD_BIT_MASK,
44+
pm_idle_support ? PM_SET_MIN : PM_NO_CHANGE);
3545
msg |= ADF_GEN4_PM_MSG_PENDING;
3646
ADF_CSR_WR(pmisc, ADF_GEN4_PM_HOST_MSG, msg);
3747

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#define ADF_GEN4_PM_DEFAULT_IDLE_FILTER (0x0)
3939
#define ADF_GEN4_PM_MAX_IDLE_FILTER (0x7)
40+
#define ADF_GEN4_PM_DEFAULT_IDLE_SUPPORT (0x1)
4041

4142
int adf_gen4_enable_pm(struct adf_accel_dev *accel_dev);
4243
bool adf_gen4_handle_pm_interrupt(struct adf_accel_dev *accel_dev);

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,65 @@ static ssize_t cfg_services_store(struct device *dev, struct device_attribute *a
152152
return count;
153153
}
154154

155+
static ssize_t pm_idle_enabled_show(struct device *dev, struct device_attribute *attr,
156+
char *buf)
157+
{
158+
char pm_idle_enabled[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = {};
159+
struct adf_accel_dev *accel_dev;
160+
int ret;
161+
162+
accel_dev = adf_devmgr_pci_to_accel_dev(to_pci_dev(dev));
163+
if (!accel_dev)
164+
return -EINVAL;
165+
166+
ret = adf_cfg_get_param_value(accel_dev, ADF_GENERAL_SEC,
167+
ADF_PM_IDLE_SUPPORT, pm_idle_enabled);
168+
if (ret)
169+
return sysfs_emit(buf, "1\n");
170+
171+
return sysfs_emit(buf, "%s\n", pm_idle_enabled);
172+
}
173+
174+
static ssize_t pm_idle_enabled_store(struct device *dev, struct device_attribute *attr,
175+
const char *buf, size_t count)
176+
{
177+
unsigned long pm_idle_enabled_cfg_val;
178+
struct adf_accel_dev *accel_dev;
179+
bool pm_idle_enabled;
180+
int ret;
181+
182+
ret = kstrtobool(buf, &pm_idle_enabled);
183+
if (ret)
184+
return ret;
185+
186+
pm_idle_enabled_cfg_val = pm_idle_enabled;
187+
accel_dev = adf_devmgr_pci_to_accel_dev(to_pci_dev(dev));
188+
if (!accel_dev)
189+
return -EINVAL;
190+
191+
if (adf_dev_started(accel_dev)) {
192+
dev_info(dev, "Device qat_dev%d must be down to set pm_idle_enabled.\n",
193+
accel_dev->accel_id);
194+
return -EINVAL;
195+
}
196+
197+
ret = adf_cfg_add_key_value_param(accel_dev, ADF_GENERAL_SEC,
198+
ADF_PM_IDLE_SUPPORT, &pm_idle_enabled_cfg_val,
199+
ADF_DEC);
200+
if (ret)
201+
return ret;
202+
203+
return count;
204+
}
205+
static DEVICE_ATTR_RW(pm_idle_enabled);
206+
155207
static DEVICE_ATTR_RW(state);
156208
static DEVICE_ATTR_RW(cfg_services);
157209

158210
static struct attribute *qat_attrs[] = {
159211
&dev_attr_state.attr,
160212
&dev_attr_cfg_services.attr,
213+
&dev_attr_pm_idle_enabled.attr,
161214
NULL,
162215
};
163216

0 commit comments

Comments
 (0)