Skip to content

Commit aa3c686

Browse files
intmcherbertx
authored andcommitted
crypto: qat - extract send and wait from adf_vf2pf_request_version()
In the function adf_vf2pf_request_version(), the VF sends a request to the PF and waits for a response before parsing and handling it. Since this pattern will be used by other requests, define a new function, adf_send_vf2pf_req(), that only deals with sending a VF2PF request and waiting for a response. Signed-off-by: Marco Chiappero <[email protected]> Co-developed-by: Giovanni Cabiddu <[email protected]> Signed-off-by: Giovanni Cabiddu <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 7a73c46 commit aa3c686

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

drivers/crypto/qat/qat_common/adf_pf2vf_msg.c

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,42 @@ int adf_send_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 msg)
181181
return adf_iov_putmsg(accel_dev, msg, 0);
182182
}
183183

184+
/**
185+
* adf_send_vf2pf_req() - send VF2PF request message
186+
* @accel_dev: Pointer to acceleration device.
187+
* @msg: Request message to send
188+
*
189+
* This function sends a message that requires a response from the VF to the PF
190+
* and waits for a reply.
191+
*
192+
* Return: 0 on success, error code otherwise.
193+
*/
194+
static int adf_send_vf2pf_req(struct adf_accel_dev *accel_dev, u32 msg)
195+
{
196+
unsigned long timeout = msecs_to_jiffies(ADF_PFVF_MSG_RESP_TIMEOUT);
197+
int ret;
198+
199+
reinit_completion(&accel_dev->vf.iov_msg_completion);
200+
201+
/* Send request from VF to PF */
202+
ret = adf_send_vf2pf_msg(accel_dev, msg);
203+
if (ret) {
204+
dev_err(&GET_DEV(accel_dev),
205+
"Failed to send request msg to PF\n");
206+
return ret;
207+
}
208+
209+
/* Wait for response */
210+
if (!wait_for_completion_timeout(&accel_dev->vf.iov_msg_completion,
211+
timeout)) {
212+
dev_err(&GET_DEV(accel_dev),
213+
"PFVF request/response message timeout expired\n");
214+
return -EIO;
215+
}
216+
217+
return 0;
218+
}
219+
184220
void adf_vf2pf_req_hndl(struct adf_accel_vf_info *vf_info)
185221
{
186222
struct adf_accel_dev *accel_dev = vf_info->accel_dev;
@@ -306,7 +342,6 @@ void adf_pf2vf_notify_restarting(struct adf_accel_dev *accel_dev)
306342

307343
static int adf_vf2pf_request_version(struct adf_accel_dev *accel_dev)
308344
{
309-
unsigned long timeout = msecs_to_jiffies(ADF_PFVF_MSG_RESP_TIMEOUT);
310345
struct adf_hw_device_data *hw_data = accel_dev->hw_device;
311346
u32 msg = 0;
312347
int ret;
@@ -316,24 +351,13 @@ static int adf_vf2pf_request_version(struct adf_accel_dev *accel_dev)
316351
msg |= ADF_PFVF_COMPAT_THIS_VERSION << ADF_VF2PF_COMPAT_VER_REQ_SHIFT;
317352
BUILD_BUG_ON(ADF_PFVF_COMPAT_THIS_VERSION > 255);
318353

319-
reinit_completion(&accel_dev->vf.iov_msg_completion);
320-
321-
/* Send request from VF to PF */
322-
ret = adf_send_vf2pf_msg(accel_dev, msg);
354+
ret = adf_send_vf2pf_req(accel_dev, msg);
323355
if (ret) {
324356
dev_err(&GET_DEV(accel_dev),
325357
"Failed to send Compatibility Version Request.\n");
326358
return ret;
327359
}
328360

329-
/* Wait for response */
330-
if (!wait_for_completion_timeout(&accel_dev->vf.iov_msg_completion,
331-
timeout)) {
332-
dev_err(&GET_DEV(accel_dev),
333-
"IOV request/response message timeout expired\n");
334-
return -EIO;
335-
}
336-
337361
/* Response from PF received, check compatibility */
338362
switch (accel_dev->vf.compatible) {
339363
case ADF_PF2VF_VF_COMPATIBLE:

0 commit comments

Comments
 (0)