common/cpt: fix build with GCC 12
[dpdk.git] / drivers / common / qat / qat_pf2vf.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2021 Intel Corporation
3  */
4
5 #include "qat_pf2vf.h"
6 #include "adf_pf2vf_msg.h"
7
8 #include <rte_cycles.h>
9
10 int qat_pf2vf_exch_msg(struct qat_pci_device *qat_dev,
11                 struct qat_pf2vf_msg pf2vf_msg,
12                 int len, uint8_t *ret)
13 {
14         int i = 0;
15         struct qat_pf2vf_dev *qat_pf2vf =
16         qat_gen_config[qat_dev->qat_dev_gen].pf2vf_dev;
17         void *pmisc_bar_addr = qat_dev->misc_bar_io_addr;
18         uint32_t msg = 0, count = 0, val = 0;
19         uint32_t vf_csr_off = qat_pf2vf->vf2pf_offset;
20         uint32_t pf_csr_off = qat_pf2vf->pf2vf_offset;
21         int type_shift = qat_pf2vf->pf2vf_type_shift;
22         uint32_t type_mask = qat_pf2vf->pf2vf_type_mask;
23         int blck_hdr_shift = qat_pf2vf->pf2vf_data_shift;
24         int data_shift = blck_hdr_shift;
25
26         switch (pf2vf_msg.msg_type) {
27         case ADF_VF2PF_MSGTYPE_GET_SMALL_BLOCK_REQ:
28                 data_shift += ADF_VF2PF_SMALL_BLOCK_BYTE_NUM_SHIFT;
29                 break;
30         case ADF_VF2PF_MSGTYPE_GET_MEDIUM_BLOCK_REQ:
31                 data_shift += ADF_VF2PF_MEDIUM_BLOCK_BYTE_NUM_SHIFT;
32                 break;
33         case ADF_VF2PF_MSGTYPE_GET_LARGE_BLOCK_REQ:
34                 data_shift += ADF_VF2PF_LARGE_BLOCK_BYTE_NUM_SHIFT;
35                 break;
36         }
37
38         if ((pf2vf_msg.msg_type & type_mask) != pf2vf_msg.msg_type) {
39                 QAT_LOG(ERR, "PF2VF message type 0x%X out of range\n",
40                         pf2vf_msg.msg_type);
41                 return -EINVAL;
42         }
43
44         for (; i < len; i++) {
45                 count = 0;
46                 if (len == 1) {
47                         msg = (pf2vf_msg.msg_type << type_shift) |
48                                 (pf2vf_msg.msg_data << (data_shift));
49                 } else
50                         msg = (pf2vf_msg.msg_type << type_shift) |
51                                 ((pf2vf_msg.msg_data + i) << (data_shift));
52                 if (pf2vf_msg.block_hdr > 0)
53                         msg |= pf2vf_msg.block_hdr << blck_hdr_shift;
54                 msg |= ADF_PFVF_INT | ADF_PFVF_MSGORIGIN_SYSTEM;
55
56                 ADF_CSR_WR(pmisc_bar_addr, vf_csr_off, msg);
57                 /*
58                  * Wait for confirmation from remote that it received
59                  * the message
60                  */
61                 do {
62                         rte_delay_us_sleep(5);
63                         val = ADF_CSR_RD(pmisc_bar_addr, vf_csr_off);
64                 } while ((val & ADF_PFVF_INT) &&
65                         (++count < ADF_IOV_MSG_ACK_MAX_RETRY));
66
67                 if (val & ADF_PFVF_INT) {
68                         QAT_LOG(ERR, "ACK not received from remote\n");
69                         return -EIO;
70                 }
71
72                 uint32_t pf_val = ADF_CSR_RD(pmisc_bar_addr, pf_csr_off);
73
74                 *(ret + i) = (uint8_t)(pf_val >> (pf2vf_msg.block_hdr > 0 ?
75                                 10 : 8) & 0xff);
76         }
77         return 0;
78 }