18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
28c2ecf20Sopenharmony_ci/* Copyright(c) 2014 - 2020 Intel Corporation */
38c2ecf20Sopenharmony_ci#include <linux/types.h>
48c2ecf20Sopenharmony_ci#include <linux/mutex.h>
58c2ecf20Sopenharmony_ci#include <linux/slab.h>
68c2ecf20Sopenharmony_ci#include <linux/iopoll.h>
78c2ecf20Sopenharmony_ci#include <linux/pci.h>
88c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h>
98c2ecf20Sopenharmony_ci#include "adf_accel_devices.h"
108c2ecf20Sopenharmony_ci#include "adf_common_drv.h"
118c2ecf20Sopenharmony_ci#include "icp_qat_fw_init_admin.h"
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* Admin Messages Registers */
148c2ecf20Sopenharmony_ci#define ADF_DH895XCC_ADMINMSGUR_OFFSET (0x3A000 + 0x574)
158c2ecf20Sopenharmony_ci#define ADF_DH895XCC_ADMINMSGLR_OFFSET (0x3A000 + 0x578)
168c2ecf20Sopenharmony_ci#define ADF_DH895XCC_MAILBOX_BASE_OFFSET 0x20970
178c2ecf20Sopenharmony_ci#define ADF_DH895XCC_MAILBOX_STRIDE 0x1000
188c2ecf20Sopenharmony_ci#define ADF_ADMINMSG_LEN 32
198c2ecf20Sopenharmony_ci#define ADF_CONST_TABLE_SIZE 1024
208c2ecf20Sopenharmony_ci#define ADF_ADMIN_POLL_DELAY_US 20
218c2ecf20Sopenharmony_ci#define ADF_ADMIN_POLL_TIMEOUT_US (5 * USEC_PER_SEC)
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistatic const u8 const_tab[1024] __aligned(1024) = {
248c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
258c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
268c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
278c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
288c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
298c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
308c2ecf20Sopenharmony_ci0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00,
318c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
328c2ecf20Sopenharmony_ci0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
338c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01,
348c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
358c2ecf20Sopenharmony_ci0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x02, 0x00, 0x00,
368c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x13, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
378c2ecf20Sopenharmony_ci0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00,
388c2ecf20Sopenharmony_ci0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
398c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
408c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
418c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
428c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
438c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
448c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
458c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
468c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
478c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
488c2ecf20Sopenharmony_ci0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76,
498c2ecf20Sopenharmony_ci0x54, 0x32, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
508c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab,
518c2ecf20Sopenharmony_ci0x89, 0x98, 0xba, 0xdc, 0xfe, 0x10, 0x32, 0x54, 0x76, 0xc3, 0xd2, 0xe1, 0xf0,
528c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
538c2ecf20Sopenharmony_ci0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
548c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc1, 0x05, 0x9e,
558c2ecf20Sopenharmony_ci0xd8, 0x36, 0x7c, 0xd5, 0x07, 0x30, 0x70, 0xdd, 0x17, 0xf7, 0x0e, 0x59, 0x39,
568c2ecf20Sopenharmony_ci0xff, 0xc0, 0x0b, 0x31, 0x68, 0x58, 0x15, 0x11, 0x64, 0xf9, 0x8f, 0xa7, 0xbe,
578c2ecf20Sopenharmony_ci0xfa, 0x4f, 0xa4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
588c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6a, 0x09, 0xe6, 0x67, 0xbb, 0x67, 0xae,
598c2ecf20Sopenharmony_ci0x85, 0x3c, 0x6e, 0xf3, 0x72, 0xa5, 0x4f, 0xf5, 0x3a, 0x51, 0x0e, 0x52, 0x7f,
608c2ecf20Sopenharmony_ci0x9b, 0x05, 0x68, 0x8c, 0x1f, 0x83, 0xd9, 0xab, 0x5b, 0xe0, 0xcd, 0x19, 0x05,
618c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
628c2ecf20Sopenharmony_ci0x00, 0x00, 0xcb, 0xbb, 0x9d, 0x5d, 0xc1, 0x05, 0x9e, 0xd8, 0x62, 0x9a, 0x29,
638c2ecf20Sopenharmony_ci0x2a, 0x36, 0x7c, 0xd5, 0x07, 0x91, 0x59, 0x01, 0x5a, 0x30, 0x70, 0xdd, 0x17,
648c2ecf20Sopenharmony_ci0x15, 0x2f, 0xec, 0xd8, 0xf7, 0x0e, 0x59, 0x39, 0x67, 0x33, 0x26, 0x67, 0xff,
658c2ecf20Sopenharmony_ci0xc0, 0x0b, 0x31, 0x8e, 0xb4, 0x4a, 0x87, 0x68, 0x58, 0x15, 0x11, 0xdb, 0x0c,
668c2ecf20Sopenharmony_ci0x2e, 0x0d, 0x64, 0xf9, 0x8f, 0xa7, 0x47, 0xb5, 0x48, 0x1d, 0xbe, 0xfa, 0x4f,
678c2ecf20Sopenharmony_ci0xa4, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
688c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x6a, 0x09, 0xe6, 0x67, 0xf3, 0xbc, 0xc9, 0x08, 0xbb,
698c2ecf20Sopenharmony_ci0x67, 0xae, 0x85, 0x84, 0xca, 0xa7, 0x3b, 0x3c, 0x6e, 0xf3, 0x72, 0xfe, 0x94,
708c2ecf20Sopenharmony_ci0xf8, 0x2b, 0xa5, 0x4f, 0xf5, 0x3a, 0x5f, 0x1d, 0x36, 0xf1, 0x51, 0x0e, 0x52,
718c2ecf20Sopenharmony_ci0x7f, 0xad, 0xe6, 0x82, 0xd1, 0x9b, 0x05, 0x68, 0x8c, 0x2b, 0x3e, 0x6c, 0x1f,
728c2ecf20Sopenharmony_ci0x1f, 0x83, 0xd9, 0xab, 0xfb, 0x41, 0xbd, 0x6b, 0x5b, 0xe0, 0xcd, 0x19, 0x13,
738c2ecf20Sopenharmony_ci0x7e, 0x21, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
748c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
758c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
768c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
778c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
788c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
798c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
808c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
818c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
828c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
838c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
848c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
858c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
868c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
878c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
888c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
898c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
908c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
918c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
928c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
938c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
948c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
958c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
968c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
978c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
988c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
998c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1008c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1018c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1028c2ecf20Sopenharmony_ci0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistruct adf_admin_comms {
1058c2ecf20Sopenharmony_ci	dma_addr_t phy_addr;
1068c2ecf20Sopenharmony_ci	dma_addr_t const_tbl_addr;
1078c2ecf20Sopenharmony_ci	void *virt_addr;
1088c2ecf20Sopenharmony_ci	void *virt_tbl_addr;
1098c2ecf20Sopenharmony_ci	void __iomem *mailbox_addr;
1108c2ecf20Sopenharmony_ci	struct mutex lock;	/* protects adf_admin_comms struct */
1118c2ecf20Sopenharmony_ci};
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_cistatic int adf_put_admin_msg_sync(struct adf_accel_dev *accel_dev, u32 ae,
1148c2ecf20Sopenharmony_ci				  void *in, void *out)
1158c2ecf20Sopenharmony_ci{
1168c2ecf20Sopenharmony_ci	int ret;
1178c2ecf20Sopenharmony_ci	u32 status;
1188c2ecf20Sopenharmony_ci	struct adf_admin_comms *admin = accel_dev->admin;
1198c2ecf20Sopenharmony_ci	int offset = ae * ADF_ADMINMSG_LEN * 2;
1208c2ecf20Sopenharmony_ci	void __iomem *mailbox = admin->mailbox_addr;
1218c2ecf20Sopenharmony_ci	int mb_offset = ae * ADF_DH895XCC_MAILBOX_STRIDE;
1228c2ecf20Sopenharmony_ci	struct icp_qat_fw_init_admin_req *request = in;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	mutex_lock(&admin->lock);
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	if (ADF_CSR_RD(mailbox, mb_offset) == 1) {
1278c2ecf20Sopenharmony_ci		mutex_unlock(&admin->lock);
1288c2ecf20Sopenharmony_ci		return -EAGAIN;
1298c2ecf20Sopenharmony_ci	}
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	memcpy(admin->virt_addr + offset, in, ADF_ADMINMSG_LEN);
1328c2ecf20Sopenharmony_ci	ADF_CSR_WR(mailbox, mb_offset, 1);
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	ret = read_poll_timeout(ADF_CSR_RD, status, status == 0,
1358c2ecf20Sopenharmony_ci				ADF_ADMIN_POLL_DELAY_US,
1368c2ecf20Sopenharmony_ci				ADF_ADMIN_POLL_TIMEOUT_US, true,
1378c2ecf20Sopenharmony_ci				mailbox, mb_offset);
1388c2ecf20Sopenharmony_ci	if (ret < 0) {
1398c2ecf20Sopenharmony_ci		/* Response timeout */
1408c2ecf20Sopenharmony_ci		dev_err(&GET_DEV(accel_dev),
1418c2ecf20Sopenharmony_ci			"Failed to send admin msg %d to accelerator %d\n",
1428c2ecf20Sopenharmony_ci			request->cmd_id, ae);
1438c2ecf20Sopenharmony_ci	} else {
1448c2ecf20Sopenharmony_ci		/* Response received from admin message, we can now
1458c2ecf20Sopenharmony_ci		 * make response data available in "out" parameter.
1468c2ecf20Sopenharmony_ci		 */
1478c2ecf20Sopenharmony_ci		memcpy(out, admin->virt_addr + offset +
1488c2ecf20Sopenharmony_ci		       ADF_ADMINMSG_LEN, ADF_ADMINMSG_LEN);
1498c2ecf20Sopenharmony_ci	}
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	mutex_unlock(&admin->lock);
1528c2ecf20Sopenharmony_ci	return ret;
1538c2ecf20Sopenharmony_ci}
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_cistatic int adf_send_admin(struct adf_accel_dev *accel_dev,
1568c2ecf20Sopenharmony_ci			  struct icp_qat_fw_init_admin_req *req,
1578c2ecf20Sopenharmony_ci			  struct icp_qat_fw_init_admin_resp *resp,
1588c2ecf20Sopenharmony_ci			  const unsigned long ae_mask)
1598c2ecf20Sopenharmony_ci{
1608c2ecf20Sopenharmony_ci	u32 ae;
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	for_each_set_bit(ae, &ae_mask, ICP_QAT_HW_AE_DELIMITER)
1638c2ecf20Sopenharmony_ci		if (adf_put_admin_msg_sync(accel_dev, ae, req, resp) ||
1648c2ecf20Sopenharmony_ci		    resp->status)
1658c2ecf20Sopenharmony_ci			return -EFAULT;
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci	return 0;
1688c2ecf20Sopenharmony_ci}
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_cistatic int adf_init_me(struct adf_accel_dev *accel_dev)
1718c2ecf20Sopenharmony_ci{
1728c2ecf20Sopenharmony_ci	struct icp_qat_fw_init_admin_req req;
1738c2ecf20Sopenharmony_ci	struct icp_qat_fw_init_admin_resp resp;
1748c2ecf20Sopenharmony_ci	struct adf_hw_device_data *hw_device = accel_dev->hw_device;
1758c2ecf20Sopenharmony_ci	u32 ae_mask = hw_device->ae_mask;
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci	memset(&req, 0, sizeof(req));
1788c2ecf20Sopenharmony_ci	memset(&resp, 0, sizeof(resp));
1798c2ecf20Sopenharmony_ci	req.cmd_id = ICP_QAT_FW_INIT_ME;
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci	return adf_send_admin(accel_dev, &req, &resp, ae_mask);
1828c2ecf20Sopenharmony_ci}
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_cistatic int adf_set_fw_constants(struct adf_accel_dev *accel_dev)
1858c2ecf20Sopenharmony_ci{
1868c2ecf20Sopenharmony_ci	struct icp_qat_fw_init_admin_req req;
1878c2ecf20Sopenharmony_ci	struct icp_qat_fw_init_admin_resp resp;
1888c2ecf20Sopenharmony_ci	struct adf_hw_device_data *hw_device = accel_dev->hw_device;
1898c2ecf20Sopenharmony_ci	u32 ae_mask = hw_device->ae_mask;
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci	memset(&req, 0, sizeof(req));
1928c2ecf20Sopenharmony_ci	memset(&resp, 0, sizeof(resp));
1938c2ecf20Sopenharmony_ci	req.cmd_id = ICP_QAT_FW_CONSTANTS_CFG;
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci	req.init_cfg_sz = ADF_CONST_TABLE_SIZE;
1968c2ecf20Sopenharmony_ci	req.init_cfg_ptr = accel_dev->admin->const_tbl_addr;
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci	return adf_send_admin(accel_dev, &req, &resp, ae_mask);
1998c2ecf20Sopenharmony_ci}
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci/**
2028c2ecf20Sopenharmony_ci * adf_send_admin_init() - Function sends init message to FW
2038c2ecf20Sopenharmony_ci * @accel_dev: Pointer to acceleration device.
2048c2ecf20Sopenharmony_ci *
2058c2ecf20Sopenharmony_ci * Function sends admin init message to the FW
2068c2ecf20Sopenharmony_ci *
2078c2ecf20Sopenharmony_ci * Return: 0 on success, error code otherwise.
2088c2ecf20Sopenharmony_ci */
2098c2ecf20Sopenharmony_ciint adf_send_admin_init(struct adf_accel_dev *accel_dev)
2108c2ecf20Sopenharmony_ci{
2118c2ecf20Sopenharmony_ci	int ret;
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci	ret = adf_init_me(accel_dev);
2148c2ecf20Sopenharmony_ci	if (ret)
2158c2ecf20Sopenharmony_ci		return ret;
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci	return adf_set_fw_constants(accel_dev);
2188c2ecf20Sopenharmony_ci}
2198c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(adf_send_admin_init);
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ciint adf_init_admin_comms(struct adf_accel_dev *accel_dev)
2228c2ecf20Sopenharmony_ci{
2238c2ecf20Sopenharmony_ci	struct adf_admin_comms *admin;
2248c2ecf20Sopenharmony_ci	struct adf_hw_device_data *hw_data = accel_dev->hw_device;
2258c2ecf20Sopenharmony_ci	struct adf_bar *pmisc =
2268c2ecf20Sopenharmony_ci		&GET_BARS(accel_dev)[hw_data->get_misc_bar_id(hw_data)];
2278c2ecf20Sopenharmony_ci	void __iomem *csr = pmisc->virt_addr;
2288c2ecf20Sopenharmony_ci	void __iomem *mailbox = (void __iomem *)((uintptr_t)csr +
2298c2ecf20Sopenharmony_ci				 ADF_DH895XCC_MAILBOX_BASE_OFFSET);
2308c2ecf20Sopenharmony_ci	u64 reg_val;
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci	admin = kzalloc_node(sizeof(*accel_dev->admin), GFP_KERNEL,
2338c2ecf20Sopenharmony_ci			     dev_to_node(&GET_DEV(accel_dev)));
2348c2ecf20Sopenharmony_ci	if (!admin)
2358c2ecf20Sopenharmony_ci		return -ENOMEM;
2368c2ecf20Sopenharmony_ci	admin->virt_addr = dma_alloc_coherent(&GET_DEV(accel_dev), PAGE_SIZE,
2378c2ecf20Sopenharmony_ci					      &admin->phy_addr, GFP_KERNEL);
2388c2ecf20Sopenharmony_ci	if (!admin->virt_addr) {
2398c2ecf20Sopenharmony_ci		dev_err(&GET_DEV(accel_dev), "Failed to allocate dma buff\n");
2408c2ecf20Sopenharmony_ci		kfree(admin);
2418c2ecf20Sopenharmony_ci		return -ENOMEM;
2428c2ecf20Sopenharmony_ci	}
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci	admin->virt_tbl_addr = dma_alloc_coherent(&GET_DEV(accel_dev),
2458c2ecf20Sopenharmony_ci						  PAGE_SIZE,
2468c2ecf20Sopenharmony_ci						  &admin->const_tbl_addr,
2478c2ecf20Sopenharmony_ci						  GFP_KERNEL);
2488c2ecf20Sopenharmony_ci	if (!admin->virt_tbl_addr) {
2498c2ecf20Sopenharmony_ci		dev_err(&GET_DEV(accel_dev), "Failed to allocate const_tbl\n");
2508c2ecf20Sopenharmony_ci		dma_free_coherent(&GET_DEV(accel_dev), PAGE_SIZE,
2518c2ecf20Sopenharmony_ci				  admin->virt_addr, admin->phy_addr);
2528c2ecf20Sopenharmony_ci		kfree(admin);
2538c2ecf20Sopenharmony_ci		return -ENOMEM;
2548c2ecf20Sopenharmony_ci	}
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci	memcpy(admin->virt_tbl_addr, const_tab, sizeof(const_tab));
2578c2ecf20Sopenharmony_ci	reg_val = (u64)admin->phy_addr;
2588c2ecf20Sopenharmony_ci	ADF_CSR_WR(csr, ADF_DH895XCC_ADMINMSGUR_OFFSET, reg_val >> 32);
2598c2ecf20Sopenharmony_ci	ADF_CSR_WR(csr, ADF_DH895XCC_ADMINMSGLR_OFFSET, reg_val);
2608c2ecf20Sopenharmony_ci	mutex_init(&admin->lock);
2618c2ecf20Sopenharmony_ci	admin->mailbox_addr = mailbox;
2628c2ecf20Sopenharmony_ci	accel_dev->admin = admin;
2638c2ecf20Sopenharmony_ci	return 0;
2648c2ecf20Sopenharmony_ci}
2658c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(adf_init_admin_comms);
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_civoid adf_exit_admin_comms(struct adf_accel_dev *accel_dev)
2688c2ecf20Sopenharmony_ci{
2698c2ecf20Sopenharmony_ci	struct adf_admin_comms *admin = accel_dev->admin;
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci	if (!admin)
2728c2ecf20Sopenharmony_ci		return;
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci	if (admin->virt_addr)
2758c2ecf20Sopenharmony_ci		dma_free_coherent(&GET_DEV(accel_dev), PAGE_SIZE,
2768c2ecf20Sopenharmony_ci				  admin->virt_addr, admin->phy_addr);
2778c2ecf20Sopenharmony_ci	if (admin->virt_tbl_addr)
2788c2ecf20Sopenharmony_ci		dma_free_coherent(&GET_DEV(accel_dev), PAGE_SIZE,
2798c2ecf20Sopenharmony_ci				  admin->virt_tbl_addr, admin->const_tbl_addr);
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	mutex_destroy(&admin->lock);
2828c2ecf20Sopenharmony_ci	kfree(admin);
2838c2ecf20Sopenharmony_ci	accel_dev->admin = NULL;
2848c2ecf20Sopenharmony_ci}
2858c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(adf_exit_admin_comms);
286