crypto: qat - add internal timer for qat 4xxx
Subsystems (2)
PATCH 1/1 crypto: qat - add internal timer for qat 4xxx
The power management feature in QAT 4xxx devices can disable clock sources used to implement timers. Because of that, the firmware needs to get an external reliable source of time.
Add a kernel timer that periodically sends an event to the firmware. This is triggered every 200ms. At each timeout event, the driver sends a sync request to the firmware reporting the current timestamp counter value.
This is a pre-requisite for enabling the heartbeat, telemetry and rate limiting features.
--- .../intel/qat/qat_4xxx/adf_4xxx_hw_data.c | 3 + drivers/crypto/intel/qat/qat_common/Makefile | 1 + .../intel/qat/qat_common/adf_accel_devices.h | 3 + .../crypto/intel/qat/qat_common/adf_admin.c | 12 ++++ .../intel/qat/qat_common/adf_common_drv.h | 1 + .../intel/qat/qat_common/adf_gen4_timer.c | 72 +++++++++++++++++++ .../intel/qat/qat_common/adf_gen4_timer.h | 23 ++++++ .../crypto/intel/qat/qat_common/adf_init.c | 13 ++++ .../qat/qat_common/icp_qat_fw_init_admin.h | 5 ++ 9 files changed, 133 insertions(+) create mode 100644 drivers/crypto/intel/qat/qat_common/adf_gen4_timer.c create mode 100644 drivers/crypto/intel/qat/qat_common/adf_gen4_timer.h
drivers/crypto/intel/qat/qat_4xxx/adf_4xxx_hw_data.c +3 -0
@@ -8,6 +8,7 @@#include <adf_gen4_hw_data.h> #include <adf_gen4_pfvf.h> #include <adf_gen4_pm.h> +#include <adf_gen4_timer.h> #include "adf_4xxx_hw_data.h" #include "icp_qat_hw.h"
@@ -405,6 +406,8 @@ void adf_init_hw_data_4xxx(struct adf_hw_device_data *hw_data, u32 dev_id) hw_data->enable_pm = adf_gen4_enable_pm; hw_data->handle_pm_interrupt = adf_gen4_handle_pm_interrupt; hw_data->dev_config = adf_gen4_dev_config; + hw_data->start_timer = adf_gen4_timer_start; + hw_data->stop_timer = adf_gen4_timer_stop;adf_gen4_init_hw_csr_ops (&hw_data->csr_ops);adf_gen4_init_pf_pfvf_ops (&hw_data->pfvf_ops);
drivers/crypto/intel/qat/qat_common/Makefile +1 -0
@@ -17,6 +17,7 @@ intel_qat-objs := adf_cfg.o \ adf_gen4_pm.o \ adf_gen2_dc.o \ adf_gen4_dc.o \ + adf_gen4_timer.o \ qat_crypto.o \ qat_compression.o \ qat_comp_algs.o \
drivers/crypto/intel/qat/qat_common/adf_accel_devices.h +3 -0
@@ -188,6 +188,8 @@ struct adf_hw_device_data {int (*init_admin_comms)(struct adf_accel_dev *accel_dev);void (*exit_admin_comms)(struct adf_accel_dev *accel_dev);int (*send_admin_init)(struct adf_accel_dev *accel_dev); +int (*start_timer)(struct adf_accel_dev *accel_dev); +void (*stop_timer)(struct adf_accel_dev *accel_dev);int (*init_arb)(struct adf_accel_dev *accel_dev);void (*exit_arb)(struct adf_accel_dev *accel_dev);const u32 *(*get_arb_mapping)(struct adf_accel_dev *accel_dev);
@@ -295,6 +297,7 @@ struct adf_accel_dev {struct list_head list;struct module *owner;struct adf_accel_pci accel_pci_dev; +struct adf_timer *timer; union { struct { /* protects VF2PF interrupts access */
drivers/crypto/intel/qat/qat_common/adf_admin.c +12 -0
@@ -223,6 +223,18 @@ static int adf_get_dc_capabilities(struct adf_accel_dev *accel_dev,return 0 ; } +int adf_send_admin_tim_sync (struct adf_accel_dev *accel_dev,u32 cnt) +{ +u32 ae_mask = accel_dev->hw_device->ae_mask; +struct icp_qat_fw_init_admin_req req = { }; +struct icp_qat_fw_init_admin_resp resp; + + req.cmd_id =ICP_QAT_FW_SYNC ; + req.int_timer_ticks = cnt; + +return adf_send_admin (accel_dev, &req, &resp, ae_mask); +} +/** * adf_send_admin_init() - Function sends init message to FW * @accel_dev: Pointer to acceleration device.
drivers/crypto/intel/qat/qat_common/adf_common_drv.h +1 -0
@@ -95,6 +95,7 @@ int adf_init_admin_comms(struct adf_accel_dev *accel_dev);void adf_exit_admin_comms (struct adf_accel_dev *accel_dev);int adf_send_admin_init (struct adf_accel_dev *accel_dev);int adf_init_admin_pm (struct adf_accel_dev *accel_dev,u32 idle_delay); +int adf_send_admin_tim_sync (struct adf_accel_dev *accel_dev,u32 cnt);int adf_init_arb (struct adf_accel_dev *accel_dev);void adf_exit_arb (struct adf_accel_dev *accel_dev);void adf_update_ring_arb (struct adf_etr_ring_data *ring);
drivers/crypto/intel/qat/qat_common/adf_gen4_timer.c new file +72 -0
72 lines not on this page · raw message
drivers/crypto/intel/qat/qat_common/adf_gen4_timer.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2023 Intel Corporation */ + +#ifndef ADF_GEN4_TIMER_H_ +#define ADF_GEN4_TIMER_H_ + +#include <linux/timer.h> +#include <linux/workqueue.h> +#include <linux/types.h> + +#include "adf_accel_devices.h" + +struct adf_timer { +struct adf_accel_dev *accel_dev; +struct timer_list timer; +struct work_struct timer_bh; +u32 cnt; +}; + +int adf_gen4_timer_start (struct adf_accel_dev *accel_dev); +void adf_gen4_timer_stop (struct adf_accel_dev *accel_dev); + +#endif /* ADF_GEN4_TIMER_H_ */
drivers/crypto/intel/qat/qat_common/adf_init.c +13 -0
@@ -163,6 +163,7 @@ static int adf_dev_start(struct adf_accel_dev *accel_dev)struct adf_hw_device_data *hw_data = accel_dev->hw_device;struct service_hndl *service;struct list_head *list_itr; +int ret;set_bit (ADF_STATUS_STARTING , &accel_dev->status);
@@ -187,6 +188,14 @@ static int adf_dev_start(struct adf_accel_dev *accel_dev)return -EFAULT ; } +if (hw_data->start_timer) { + ret = hw_data->start_timer (accel_dev); +if (ret) { +dev_err (&GET_DEV (accel_dev),"Failed to start internal sync timer\n" ); +return ret; + } + } +list_for_each (list_itr, &service_table) { service = list_entry(list_itr, struct service_hndl, list);if (service->event_hld (accel_dev,ADF_EVENT_START )) {
@@ -235,6 +244,7 @@ static int adf_dev_start(struct adf_accel_dev *accel_dev)*/ static void adf_dev_stop (struct adf_accel_dev *accel_dev) { +struct adf_hw_device_data *hw_data = accel_dev->hw_device;struct service_hndl *service;struct list_head *list_itr;bool wait = false;
@@ -270,6 +280,9 @@ static void adf_dev_stop(struct adf_accel_dev *accel_dev) } } +if (hw_data->stop_timer) + hw_data->stop_timer (accel_dev); +if (wait)msleep (100 );
drivers/crypto/intel/qat/qat_common/icp_qat_fw_init_admin.h +5 -0
@@ -37,6 +37,9 @@ struct icp_qat_fw_init_admin_req {__u16 ibuf_size_in_kb;__u16 resrvd3; }; +struct { +u32 int_timer_ticks; + };__u32 idle_filter; };
@@ -97,6 +100,8 @@ struct icp_qat_fw_init_admin_resp { }; } __packed; +#define ICP_QAT_FW_SYNC ICP_QAT_FW_HEARTBEAT_SYNC +#define ICP_QAT_FW_COMN_HEARTBEAT_OK 0#define ICP_QAT_FW_COMN_HEARTBEAT_BLOCKED 1#define ICP_QAT_FW_COMN_HEARTBEAT_FLAG_BITPOS 0
base-commit: 8fd3bb7fdffbe273831d727501725547cb9b1b5d
Signature · 1 line
2.40.1
Herbert Xu
maintainerdrivers/crypto/intel/qat/qat_common/adf_gen4_timer.c line 37
Quoted 12 lines · Damian Muszynski
drivers/crypto/intel/qat/qat_common/adf_gen4_timer.c new file +11
-0+static void timer_handler (struct timer_list *tl) +{ +struct adf_timer *timer_ctx =from_timer (timer_ctx, tl, timer); +unsigned long timeout_val =adf_get_next_timeout (); + +/* Schedule a work queue to send admin request */ +adf_misc_wq_queue_work (&timer_ctx->timer_bh); + + timer_ctx->cnt++; +mod_timer (tl, timeout_val); +}
So the timer simply schedules a work. Could you use a delayed work instead?
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Hi Herbert,
Quoted 16 lines · Herbert Xu
drivers/crypto/intel/qat/qat_common/adf_gen4_timer.c line 37
Quoted 12 lines · Damian Muszynski
drivers/crypto/intel/qat/qat_common/adf_gen4_timer.c new file +11
-0+static void timer_handler (struct timer_list *tl) +{ +struct adf_timer *timer_ctx =from_timer (timer_ctx, tl, timer); +unsigned long timeout_val =adf_get_next_timeout (); + +/* Schedule a work queue to send admin request */ +adf_misc_wq_queue_work (&timer_ctx->timer_bh); + + timer_ctx->cnt++; +mod_timer (tl, timeout_val); +}So the timer simply schedules a work. Could you use a delayed work instead?
We considered the usage of delayed work when implementing this, but it will break functionality. Apart from scheduling the work queue, timer_handler() is incrementing a counter which keeps track of how many times the timer was scheduled. This counter is then sent to the firmware in the WQ. For our usecase, the counter needs to be incremented at accurate intervals.
Quoted 6 lines
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Herbert Xu
maintainerQuoted 4 lines · Damian Muszynski
We considered the usage of delayed work when implementing this, but it will break functionality. Apart from scheduling the work queue,
timer_handler()is incrementing a counter which keeps track of how many times the timer was scheduled.
Please be more specific. I don't understand why the counter can't be incremented in the delayed work instead of the timer.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 9 lines · Herbert Xu
Quoted 4 lines · Damian Muszynski
We considered the usage of delayed work when implementing this, but it will break functionality. Apart from scheduling the work queue,
timer_handler()is incrementing a counter which keeps track of how many times the timer was scheduled.Please be more specific. I don't understand why the counter can't be incremented in the delayed work instead of the timer.
We have chosen the timer instead of delayed work because it gives us more accuracy in incrementing this counter. The value of this counter is used by firmware to track the time so it requires that.
---
Best Regards,
Damian Muszynski
Quoted 9 lines · Herbert Xu
Quoted 4 lines · Damian Muszynski
We considered the usage of delayed work when implementing this, but it will break functionality. Apart from scheduling the work queue,
timer_handler()is incrementing a counter which keeps track of how many times the timer was scheduled.Please be more specific. I don't understand why the counter can't be incremented in the delayed work instead of the timer.
We found a solution with which we can be sure about accuracy and replace the timer with delayed work as you suggested. An reworked patch is included with a new version of the heartbeat patchset as the feature development is now finished and this patch is a prerequisite for it.
Best Regards,
Damian Muszynski