Path: blob/master/drivers/crypto/intel/qat/qat_common/adf_admin.c
29278 views
// SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)1/* Copyright(c) 2014 - 2020 Intel Corporation */2#include <linux/types.h>3#include <linux/mutex.h>4#include <linux/slab.h>5#include <linux/iopoll.h>6#include <linux/pci.h>7#include <linux/dma-mapping.h>8#include "adf_accel_devices.h"9#include "adf_admin.h"10#include "adf_common_drv.h"11#include "adf_cfg.h"12#include "adf_heartbeat.h"13#include "icp_qat_fw_init_admin.h"1415#define ADF_ADMIN_MAILBOX_STRIDE 0x100016#define ADF_ADMINMSG_LEN 3217#define ADF_CONST_TABLE_SIZE 102418#define ADF_ADMIN_POLL_DELAY_US 2019#define ADF_ADMIN_POLL_TIMEOUT_US (5 * USEC_PER_SEC)20#define ADF_ONE_AE 12122static const u8 const_tab[1024] __aligned(1024) = {230x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,240x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,250x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,260x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,270x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,280x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,290x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00,300x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,310x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,320x00, 0x00, 0x00, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01,330x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,340x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x02, 0x00, 0x00,350x00, 0x00, 0x00, 0x00, 0x13, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,360x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00,370x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,380x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,390x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,400x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,410x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,420x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,430x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,440x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,450x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,460x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,470x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76,480x54, 0x32, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,490x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab,500x89, 0x98, 0xba, 0xdc, 0xfe, 0x10, 0x32, 0x54, 0x76, 0xc3, 0xd2, 0xe1, 0xf0,510x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,520x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,530x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc1, 0x05, 0x9e,540xd8, 0x36, 0x7c, 0xd5, 0x07, 0x30, 0x70, 0xdd, 0x17, 0xf7, 0x0e, 0x59, 0x39,550xff, 0xc0, 0x0b, 0x31, 0x68, 0x58, 0x15, 0x11, 0x64, 0xf9, 0x8f, 0xa7, 0xbe,560xfa, 0x4f, 0xa4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,570x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6a, 0x09, 0xe6, 0x67, 0xbb, 0x67, 0xae,580x85, 0x3c, 0x6e, 0xf3, 0x72, 0xa5, 0x4f, 0xf5, 0x3a, 0x51, 0x0e, 0x52, 0x7f,590x9b, 0x05, 0x68, 0x8c, 0x1f, 0x83, 0xd9, 0xab, 0x5b, 0xe0, 0xcd, 0x19, 0x05,600x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,610x00, 0x00, 0xcb, 0xbb, 0x9d, 0x5d, 0xc1, 0x05, 0x9e, 0xd8, 0x62, 0x9a, 0x29,620x2a, 0x36, 0x7c, 0xd5, 0x07, 0x91, 0x59, 0x01, 0x5a, 0x30, 0x70, 0xdd, 0x17,630x15, 0x2f, 0xec, 0xd8, 0xf7, 0x0e, 0x59, 0x39, 0x67, 0x33, 0x26, 0x67, 0xff,640xc0, 0x0b, 0x31, 0x8e, 0xb4, 0x4a, 0x87, 0x68, 0x58, 0x15, 0x11, 0xdb, 0x0c,650x2e, 0x0d, 0x64, 0xf9, 0x8f, 0xa7, 0x47, 0xb5, 0x48, 0x1d, 0xbe, 0xfa, 0x4f,660xa4, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,670x00, 0x00, 0x00, 0x00, 0x6a, 0x09, 0xe6, 0x67, 0xf3, 0xbc, 0xc9, 0x08, 0xbb,680x67, 0xae, 0x85, 0x84, 0xca, 0xa7, 0x3b, 0x3c, 0x6e, 0xf3, 0x72, 0xfe, 0x94,690xf8, 0x2b, 0xa5, 0x4f, 0xf5, 0x3a, 0x5f, 0x1d, 0x36, 0xf1, 0x51, 0x0e, 0x52,700x7f, 0xad, 0xe6, 0x82, 0xd1, 0x9b, 0x05, 0x68, 0x8c, 0x2b, 0x3e, 0x6c, 0x1f,710x1f, 0x83, 0xd9, 0xab, 0xfb, 0x41, 0xbd, 0x6b, 0x5b, 0xe0, 0xcd, 0x19, 0x13,720x7e, 0x21, 0x79, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,730x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,740x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00,750x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x18,760x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,770x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x01, 0x00,780x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,790x15, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x02, 0x00, 0x00, 0x00,800x00, 0x00, 0x00, 0x14, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x02,810x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,820x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00,830x00, 0x00, 0x00, 0x00, 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25,840x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00,850x00, 0x00, 0x12, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00,860x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,870x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00,880x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x01,890x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,900x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,910x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,920x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00,930x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,940x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,950x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,960x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,970x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,980x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,990x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,1000x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,1010x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};102103struct adf_admin_comms {104dma_addr_t phy_addr;105dma_addr_t const_tbl_addr;106void *virt_addr;107void *virt_tbl_addr;108void __iomem *mailbox_addr;109struct mutex lock; /* protects adf_admin_comms struct */110};111112static int adf_put_admin_msg_sync(struct adf_accel_dev *accel_dev, u32 ae,113void *in, void *out)114{115int ret;116u32 status;117struct adf_admin_comms *admin = accel_dev->admin;118int offset = ae * ADF_ADMINMSG_LEN * 2;119void __iomem *mailbox = admin->mailbox_addr;120int mb_offset = ae * ADF_ADMIN_MAILBOX_STRIDE;121struct icp_qat_fw_init_admin_req *request = in;122123mutex_lock(&admin->lock);124125if (ADF_CSR_RD(mailbox, mb_offset) == 1) {126mutex_unlock(&admin->lock);127return -EAGAIN;128}129130memcpy(admin->virt_addr + offset, in, ADF_ADMINMSG_LEN);131ADF_CSR_WR(mailbox, mb_offset, 1);132133ret = read_poll_timeout(ADF_CSR_RD, status, status == 0,134ADF_ADMIN_POLL_DELAY_US,135ADF_ADMIN_POLL_TIMEOUT_US, true,136mailbox, mb_offset);137if (ret < 0) {138/* Response timeout */139dev_err(&GET_DEV(accel_dev),140"Failed to send admin msg %d to accelerator %d\n",141request->cmd_id, ae);142} else {143/* Response received from admin message, we can now144* make response data available in "out" parameter.145*/146memcpy(out, admin->virt_addr + offset +147ADF_ADMINMSG_LEN, ADF_ADMINMSG_LEN);148}149150mutex_unlock(&admin->lock);151return ret;152}153154static int adf_send_admin(struct adf_accel_dev *accel_dev,155struct icp_qat_fw_init_admin_req *req,156struct icp_qat_fw_init_admin_resp *resp,157const unsigned long ae_mask)158{159u32 ae;160161for_each_set_bit(ae, &ae_mask, ICP_QAT_HW_AE_DELIMITER)162if (adf_put_admin_msg_sync(accel_dev, ae, req, resp) ||163resp->status)164return -EFAULT;165166return 0;167}168169static int adf_init_ae(struct adf_accel_dev *accel_dev)170{171struct icp_qat_fw_init_admin_req req;172struct icp_qat_fw_init_admin_resp resp;173struct adf_hw_device_data *hw_device = accel_dev->hw_device;174u32 ae_mask = hw_device->ae_mask;175176memset(&req, 0, sizeof(req));177memset(&resp, 0, sizeof(resp));178req.cmd_id = ICP_QAT_FW_INIT_AE;179180return adf_send_admin(accel_dev, &req, &resp, ae_mask);181}182183static int adf_set_fw_constants(struct adf_accel_dev *accel_dev)184{185struct icp_qat_fw_init_admin_req req;186struct icp_qat_fw_init_admin_resp resp;187struct adf_hw_device_data *hw_device = accel_dev->hw_device;188u32 ae_mask = hw_device->admin_ae_mask ?: hw_device->ae_mask;189190memset(&req, 0, sizeof(req));191memset(&resp, 0, sizeof(resp));192req.cmd_id = ICP_QAT_FW_CONSTANTS_CFG;193194req.init_cfg_sz = ADF_CONST_TABLE_SIZE;195req.init_cfg_ptr = accel_dev->admin->const_tbl_addr;196197return adf_send_admin(accel_dev, &req, &resp, ae_mask);198}199200int adf_get_fw_timestamp(struct adf_accel_dev *accel_dev, u64 *timestamp)201{202struct icp_qat_fw_init_admin_req req = { };203struct icp_qat_fw_init_admin_resp resp;204unsigned int ae_mask = ADF_ONE_AE;205int ret;206207req.cmd_id = ICP_QAT_FW_TIMER_GET;208ret = adf_send_admin(accel_dev, &req, &resp, ae_mask);209if (ret)210return ret;211212*timestamp = resp.timestamp;213return 0;214}215216static int adf_set_chaining(struct adf_accel_dev *accel_dev)217{218u32 ae_mask = GET_HW_DATA(accel_dev)->ae_mask;219struct icp_qat_fw_init_admin_resp resp = { };220struct icp_qat_fw_init_admin_req req = { };221222req.cmd_id = ICP_QAT_FW_DC_CHAIN_INIT;223224return adf_send_admin(accel_dev, &req, &resp, ae_mask);225}226227static int adf_get_dc_capabilities(struct adf_accel_dev *accel_dev,228u32 *capabilities)229{230struct adf_hw_device_data *hw_device = accel_dev->hw_device;231struct icp_qat_fw_init_admin_resp resp;232struct icp_qat_fw_init_admin_req req;233unsigned long ae_mask;234unsigned long ae;235int ret;236237/* Target only service accelerator engines */238ae_mask = hw_device->ae_mask & ~hw_device->admin_ae_mask;239240memset(&req, 0, sizeof(req));241memset(&resp, 0, sizeof(resp));242req.cmd_id = ICP_QAT_FW_COMP_CAPABILITY_GET;243244*capabilities = 0;245for_each_set_bit(ae, &ae_mask, GET_MAX_ACCELENGINES(accel_dev)) {246ret = adf_send_admin(accel_dev, &req, &resp, 1ULL << ae);247if (ret)248return ret;249250*capabilities |= resp.extended_features;251}252253return 0;254}255256int adf_get_ae_fw_counters(struct adf_accel_dev *accel_dev, u16 ae, u64 *reqs, u64 *resps)257{258struct icp_qat_fw_init_admin_resp resp = { };259struct icp_qat_fw_init_admin_req req = { };260int ret;261262req.cmd_id = ICP_QAT_FW_COUNTERS_GET;263264ret = adf_put_admin_msg_sync(accel_dev, ae, &req, &resp);265if (ret || resp.status)266return -EFAULT;267268*reqs = resp.req_rec_count;269*resps = resp.resp_sent_count;270271return 0;272}273274int adf_send_admin_tim_sync(struct adf_accel_dev *accel_dev, u32 cnt)275{276u32 ae_mask = accel_dev->hw_device->ae_mask;277struct icp_qat_fw_init_admin_req req = { };278struct icp_qat_fw_init_admin_resp resp = { };279280req.cmd_id = ICP_QAT_FW_SYNC;281req.int_timer_ticks = cnt;282283return adf_send_admin(accel_dev, &req, &resp, ae_mask);284}285286int adf_send_admin_hb_timer(struct adf_accel_dev *accel_dev, uint32_t ticks)287{288u32 ae_mask = accel_dev->hw_device->ae_mask;289struct icp_qat_fw_init_admin_req req = { };290struct icp_qat_fw_init_admin_resp resp;291292req.cmd_id = ICP_QAT_FW_HEARTBEAT_TIMER_SET;293req.init_cfg_ptr = accel_dev->heartbeat->dma.phy_addr;294req.heartbeat_ticks = ticks;295296return adf_send_admin(accel_dev, &req, &resp, ae_mask);297}298299static bool is_dcc_enabled(struct adf_accel_dev *accel_dev)300{301char services[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = {0};302int ret;303304ret = adf_cfg_get_param_value(accel_dev, ADF_GENERAL_SEC,305ADF_SERVICES_ENABLED, services);306if (ret)307return false;308309return !strcmp(services, "dcc");310}311312static int adf_get_fw_capabilities(struct adf_accel_dev *accel_dev, u16 *caps)313{314u32 ae_mask = accel_dev->hw_device->admin_ae_mask;315struct icp_qat_fw_init_admin_resp resp = { };316struct icp_qat_fw_init_admin_req req = { };317int ret;318319if (!ae_mask)320return 0;321322req.cmd_id = ICP_QAT_FW_CAPABILITIES_GET;323ret = adf_send_admin(accel_dev, &req, &resp, ae_mask);324if (ret)325return ret;326327*caps = resp.fw_capabilities;328329return 0;330}331332int adf_send_admin_rl_init(struct adf_accel_dev *accel_dev,333struct icp_qat_fw_init_admin_slice_cnt *slices)334{335u32 ae_mask = accel_dev->hw_device->admin_ae_mask;336struct icp_qat_fw_init_admin_resp resp = { };337struct icp_qat_fw_init_admin_req req = { };338int ret;339340req.cmd_id = ICP_QAT_FW_RL_INIT;341342ret = adf_send_admin(accel_dev, &req, &resp, ae_mask);343if (ret)344return ret;345346memcpy(slices, &resp.slices, sizeof(*slices));347348return 0;349}350351int adf_send_admin_rl_add_update(struct adf_accel_dev *accel_dev,352struct icp_qat_fw_init_admin_req *req)353{354u32 ae_mask = accel_dev->hw_device->admin_ae_mask;355struct icp_qat_fw_init_admin_resp resp = { };356357/*358* req struct filled in rl implementation. Used commands359* ICP_QAT_FW_RL_ADD for a new SLA360* ICP_QAT_FW_RL_UPDATE for update SLA361*/362return adf_send_admin(accel_dev, req, &resp, ae_mask);363}364365int adf_send_admin_rl_delete(struct adf_accel_dev *accel_dev, u16 node_id,366u8 node_type)367{368u32 ae_mask = accel_dev->hw_device->admin_ae_mask;369struct icp_qat_fw_init_admin_resp resp = { };370struct icp_qat_fw_init_admin_req req = { };371372req.cmd_id = ICP_QAT_FW_RL_REMOVE;373req.node_id = node_id;374req.node_type = node_type;375376return adf_send_admin(accel_dev, &req, &resp, ae_mask);377}378379/**380* adf_send_admin_init() - Function sends init message to FW381* @accel_dev: Pointer to acceleration device.382*383* Function sends admin init message to the FW384*385* Return: 0 on success, error code otherwise.386*/387int adf_send_admin_init(struct adf_accel_dev *accel_dev)388{389struct adf_hw_device_data *hw_data = GET_HW_DATA(accel_dev);390u32 dc_capabilities = 0;391int ret;392393ret = adf_set_fw_constants(accel_dev);394if (ret)395return ret;396397if (is_dcc_enabled(accel_dev)) {398ret = adf_set_chaining(accel_dev);399if (ret)400return ret;401}402403ret = adf_get_dc_capabilities(accel_dev, &dc_capabilities);404if (ret) {405dev_err(&GET_DEV(accel_dev), "Cannot get dc capabilities\n");406return ret;407}408accel_dev->hw_device->extended_dc_capabilities = dc_capabilities;409410adf_get_fw_capabilities(accel_dev, &hw_data->fw_capabilities);411412return adf_init_ae(accel_dev);413}414EXPORT_SYMBOL_GPL(adf_send_admin_init);415416/**417* adf_init_admin_pm() - Function sends PM init message to FW418* @accel_dev: Pointer to acceleration device.419* @idle_delay: QAT HW idle time before power gating is initiated.420* 000 - 64us421* 001 - 128us422* 010 - 256us423* 011 - 512us424* 100 - 1ms425* 101 - 2ms426* 110 - 4ms427* 111 - 8ms428*429* Function sends to the FW the admin init message for the PM state430* configuration.431*432* Return: 0 on success, error code otherwise.433*/434int adf_init_admin_pm(struct adf_accel_dev *accel_dev, u32 idle_delay)435{436struct adf_hw_device_data *hw_data = accel_dev->hw_device;437struct icp_qat_fw_init_admin_resp resp = {0};438struct icp_qat_fw_init_admin_req req = {0};439u32 ae_mask = hw_data->admin_ae_mask;440441if (!accel_dev->admin) {442dev_err(&GET_DEV(accel_dev), "adf_admin is not available\n");443return -EFAULT;444}445446req.cmd_id = ICP_QAT_FW_PM_STATE_CONFIG;447req.idle_filter = idle_delay;448449return adf_send_admin(accel_dev, &req, &resp, ae_mask);450}451EXPORT_SYMBOL_GPL(adf_init_admin_pm);452453int adf_get_pm_info(struct adf_accel_dev *accel_dev, dma_addr_t p_state_addr,454size_t buff_size)455{456struct adf_hw_device_data *hw_data = accel_dev->hw_device;457struct icp_qat_fw_init_admin_req req = { };458struct icp_qat_fw_init_admin_resp resp;459u32 ae_mask = hw_data->admin_ae_mask;460int ret;461462/* Query pm info via init/admin cmd */463if (!accel_dev->admin) {464dev_err(&GET_DEV(accel_dev), "adf_admin is not available\n");465return -EFAULT;466}467468req.cmd_id = ICP_QAT_FW_PM_INFO;469req.init_cfg_sz = buff_size;470req.init_cfg_ptr = p_state_addr;471472ret = adf_send_admin(accel_dev, &req, &resp, ae_mask);473if (ret)474dev_err(&GET_DEV(accel_dev),475"Failed to query power-management info\n");476477return ret;478}479480int adf_get_cnv_stats(struct adf_accel_dev *accel_dev, u16 ae, u16 *err_cnt,481u16 *latest_err)482{483struct icp_qat_fw_init_admin_req req = { };484struct icp_qat_fw_init_admin_resp resp;485int ret;486487req.cmd_id = ICP_QAT_FW_CNV_STATS_GET;488489ret = adf_put_admin_msg_sync(accel_dev, ae, &req, &resp);490if (ret)491return ret;492if (resp.status)493return -EPROTONOSUPPORT;494495*err_cnt = resp.error_count;496*latest_err = resp.latest_error;497498return ret;499}500501int adf_send_admin_tl_start(struct adf_accel_dev *accel_dev,502dma_addr_t tl_dma_addr, size_t layout_sz, u8 *rp_indexes,503struct icp_qat_fw_init_admin_slice_cnt *slice_count)504{505u32 ae_mask = GET_HW_DATA(accel_dev)->admin_ae_mask;506struct icp_qat_fw_init_admin_resp resp = { };507struct icp_qat_fw_init_admin_req req = { };508int ret;509510req.cmd_id = ICP_QAT_FW_TL_START;511req.init_cfg_ptr = tl_dma_addr;512req.init_cfg_sz = layout_sz;513514if (rp_indexes)515memcpy(&req.rp_indexes, rp_indexes, sizeof(req.rp_indexes));516517ret = adf_send_admin(accel_dev, &req, &resp, ae_mask);518if (ret)519return ret;520521memcpy(slice_count, &resp.slices, sizeof(*slice_count));522523return 0;524}525526int adf_send_admin_tl_stop(struct adf_accel_dev *accel_dev)527{528struct adf_hw_device_data *hw_data = GET_HW_DATA(accel_dev);529struct icp_qat_fw_init_admin_resp resp = { };530struct icp_qat_fw_init_admin_req req = { };531u32 ae_mask = hw_data->admin_ae_mask;532533req.cmd_id = ICP_QAT_FW_TL_STOP;534535return adf_send_admin(accel_dev, &req, &resp, ae_mask);536}537538int adf_init_admin_comms(struct adf_accel_dev *accel_dev)539{540struct adf_admin_comms *admin;541struct adf_hw_device_data *hw_data = accel_dev->hw_device;542void __iomem *pmisc_addr = adf_get_pmisc_base(accel_dev);543struct admin_info admin_csrs_info;544u32 mailbox_offset, adminmsg_u, adminmsg_l;545void __iomem *mailbox;546u64 reg_val;547548admin = kzalloc_node(sizeof(*accel_dev->admin), GFP_KERNEL,549dev_to_node(&GET_DEV(accel_dev)));550if (!admin)551return -ENOMEM;552admin->virt_addr = dma_alloc_coherent(&GET_DEV(accel_dev), PAGE_SIZE,553&admin->phy_addr, GFP_KERNEL);554if (!admin->virt_addr) {555dev_err(&GET_DEV(accel_dev), "Failed to allocate dma buff\n");556kfree(admin);557return -ENOMEM;558}559560admin->virt_tbl_addr = dma_alloc_coherent(&GET_DEV(accel_dev),561PAGE_SIZE,562&admin->const_tbl_addr,563GFP_KERNEL);564if (!admin->virt_tbl_addr) {565dev_err(&GET_DEV(accel_dev), "Failed to allocate const_tbl\n");566dma_free_coherent(&GET_DEV(accel_dev), PAGE_SIZE,567admin->virt_addr, admin->phy_addr);568kfree(admin);569return -ENOMEM;570}571572memcpy(admin->virt_tbl_addr, const_tab, sizeof(const_tab));573hw_data->get_admin_info(&admin_csrs_info);574575mailbox_offset = admin_csrs_info.mailbox_offset;576mailbox = pmisc_addr + mailbox_offset;577adminmsg_u = admin_csrs_info.admin_msg_ur;578adminmsg_l = admin_csrs_info.admin_msg_lr;579580reg_val = (u64)admin->phy_addr;581ADF_CSR_WR(pmisc_addr, adminmsg_u, upper_32_bits(reg_val));582ADF_CSR_WR(pmisc_addr, adminmsg_l, lower_32_bits(reg_val));583584mutex_init(&admin->lock);585admin->mailbox_addr = mailbox;586accel_dev->admin = admin;587return 0;588}589EXPORT_SYMBOL_GPL(adf_init_admin_comms);590591void adf_exit_admin_comms(struct adf_accel_dev *accel_dev)592{593struct adf_admin_comms *admin = accel_dev->admin;594595if (!admin)596return;597598if (admin->virt_addr)599dma_free_coherent(&GET_DEV(accel_dev), PAGE_SIZE,600admin->virt_addr, admin->phy_addr);601if (admin->virt_tbl_addr)602dma_free_coherent(&GET_DEV(accel_dev), PAGE_SIZE,603admin->virt_tbl_addr, admin->const_tbl_addr);604605mutex_destroy(&admin->lock);606kfree(admin);607accel_dev->admin = NULL;608}609EXPORT_SYMBOL_GPL(adf_exit_admin_comms);610611612