1*d9fb8408SDamian Muszynski // SPDX-License-Identifier: GPL-2.0-only
2*d9fb8408SDamian Muszynski /* Copyright(c) 2023 Intel Corporation */
3*d9fb8408SDamian Muszynski
4*d9fb8408SDamian Muszynski #include <linux/dma-mapping.h>
5*d9fb8408SDamian Muszynski #include <linux/pci.h>
6*d9fb8408SDamian Muszynski
7*d9fb8408SDamian Muszynski #include "adf_admin.h"
8*d9fb8408SDamian Muszynski #include "adf_accel_devices.h"
9*d9fb8408SDamian Muszynski #include "adf_rl_admin.h"
10*d9fb8408SDamian Muszynski
11*d9fb8408SDamian Muszynski static void
prep_admin_req_msg(struct rl_sla * sla,dma_addr_t dma_addr,struct icp_qat_fw_init_admin_sla_config_params * fw_params,struct icp_qat_fw_init_admin_req * req,bool is_update)12*d9fb8408SDamian Muszynski prep_admin_req_msg(struct rl_sla *sla, dma_addr_t dma_addr,
13*d9fb8408SDamian Muszynski struct icp_qat_fw_init_admin_sla_config_params *fw_params,
14*d9fb8408SDamian Muszynski struct icp_qat_fw_init_admin_req *req, bool is_update)
15*d9fb8408SDamian Muszynski {
16*d9fb8408SDamian Muszynski req->cmd_id = is_update ? ICP_QAT_FW_RL_UPDATE : ICP_QAT_FW_RL_ADD;
17*d9fb8408SDamian Muszynski req->init_cfg_ptr = dma_addr;
18*d9fb8408SDamian Muszynski req->init_cfg_sz = sizeof(*fw_params);
19*d9fb8408SDamian Muszynski req->node_id = sla->node_id;
20*d9fb8408SDamian Muszynski req->node_type = sla->type;
21*d9fb8408SDamian Muszynski req->rp_count = sla->ring_pairs_cnt;
22*d9fb8408SDamian Muszynski req->svc_type = sla->srv;
23*d9fb8408SDamian Muszynski }
24*d9fb8408SDamian Muszynski
25*d9fb8408SDamian Muszynski static void
prep_admin_req_params(struct adf_accel_dev * accel_dev,struct rl_sla * sla,struct icp_qat_fw_init_admin_sla_config_params * fw_params)26*d9fb8408SDamian Muszynski prep_admin_req_params(struct adf_accel_dev *accel_dev, struct rl_sla *sla,
27*d9fb8408SDamian Muszynski struct icp_qat_fw_init_admin_sla_config_params *fw_params)
28*d9fb8408SDamian Muszynski {
29*d9fb8408SDamian Muszynski fw_params->pcie_in_cir =
30*d9fb8408SDamian Muszynski adf_rl_calculate_pci_bw(accel_dev, sla->cir, sla->srv, false);
31*d9fb8408SDamian Muszynski fw_params->pcie_in_pir =
32*d9fb8408SDamian Muszynski adf_rl_calculate_pci_bw(accel_dev, sla->pir, sla->srv, false);
33*d9fb8408SDamian Muszynski fw_params->pcie_out_cir =
34*d9fb8408SDamian Muszynski adf_rl_calculate_pci_bw(accel_dev, sla->cir, sla->srv, true);
35*d9fb8408SDamian Muszynski fw_params->pcie_out_pir =
36*d9fb8408SDamian Muszynski adf_rl_calculate_pci_bw(accel_dev, sla->pir, sla->srv, true);
37*d9fb8408SDamian Muszynski
38*d9fb8408SDamian Muszynski fw_params->slice_util_cir =
39*d9fb8408SDamian Muszynski adf_rl_calculate_slice_tokens(accel_dev, sla->cir, sla->srv);
40*d9fb8408SDamian Muszynski fw_params->slice_util_pir =
41*d9fb8408SDamian Muszynski adf_rl_calculate_slice_tokens(accel_dev, sla->pir, sla->srv);
42*d9fb8408SDamian Muszynski
43*d9fb8408SDamian Muszynski fw_params->ae_util_cir =
44*d9fb8408SDamian Muszynski adf_rl_calculate_ae_cycles(accel_dev, sla->cir, sla->srv);
45*d9fb8408SDamian Muszynski fw_params->ae_util_pir =
46*d9fb8408SDamian Muszynski adf_rl_calculate_ae_cycles(accel_dev, sla->pir, sla->srv);
47*d9fb8408SDamian Muszynski
48*d9fb8408SDamian Muszynski memcpy(fw_params->rp_ids, sla->ring_pairs_ids,
49*d9fb8408SDamian Muszynski sizeof(sla->ring_pairs_ids));
50*d9fb8408SDamian Muszynski }
51*d9fb8408SDamian Muszynski
adf_rl_send_admin_init_msg(struct adf_accel_dev * accel_dev,struct rl_slice_cnt * slices_int)52*d9fb8408SDamian Muszynski int adf_rl_send_admin_init_msg(struct adf_accel_dev *accel_dev,
53*d9fb8408SDamian Muszynski struct rl_slice_cnt *slices_int)
54*d9fb8408SDamian Muszynski {
55*d9fb8408SDamian Muszynski struct icp_qat_fw_init_admin_slice_cnt slices_resp = { };
56*d9fb8408SDamian Muszynski int ret;
57*d9fb8408SDamian Muszynski
58*d9fb8408SDamian Muszynski ret = adf_send_admin_rl_init(accel_dev, &slices_resp);
59*d9fb8408SDamian Muszynski if (ret)
60*d9fb8408SDamian Muszynski return ret;
61*d9fb8408SDamian Muszynski
62*d9fb8408SDamian Muszynski slices_int->dcpr_cnt = slices_resp.dcpr_cnt;
63*d9fb8408SDamian Muszynski slices_int->pke_cnt = slices_resp.pke_cnt;
64*d9fb8408SDamian Muszynski /* For symmetric crypto, slice tokens are relative to the UCS slice */
65*d9fb8408SDamian Muszynski slices_int->cph_cnt = slices_resp.ucs_cnt;
66*d9fb8408SDamian Muszynski
67*d9fb8408SDamian Muszynski return 0;
68*d9fb8408SDamian Muszynski }
69*d9fb8408SDamian Muszynski
adf_rl_send_admin_add_update_msg(struct adf_accel_dev * accel_dev,struct rl_sla * sla,bool is_update)70*d9fb8408SDamian Muszynski int adf_rl_send_admin_add_update_msg(struct adf_accel_dev *accel_dev,
71*d9fb8408SDamian Muszynski struct rl_sla *sla, bool is_update)
72*d9fb8408SDamian Muszynski {
73*d9fb8408SDamian Muszynski struct icp_qat_fw_init_admin_sla_config_params *fw_params;
74*d9fb8408SDamian Muszynski struct icp_qat_fw_init_admin_req req = { };
75*d9fb8408SDamian Muszynski dma_addr_t dma_addr;
76*d9fb8408SDamian Muszynski int ret;
77*d9fb8408SDamian Muszynski
78*d9fb8408SDamian Muszynski fw_params = dma_alloc_coherent(&GET_DEV(accel_dev), sizeof(*fw_params),
79*d9fb8408SDamian Muszynski &dma_addr, GFP_KERNEL);
80*d9fb8408SDamian Muszynski if (!fw_params)
81*d9fb8408SDamian Muszynski return -ENOMEM;
82*d9fb8408SDamian Muszynski
83*d9fb8408SDamian Muszynski prep_admin_req_params(accel_dev, sla, fw_params);
84*d9fb8408SDamian Muszynski prep_admin_req_msg(sla, dma_addr, fw_params, &req, is_update);
85*d9fb8408SDamian Muszynski ret = adf_send_admin_rl_add_update(accel_dev, &req);
86*d9fb8408SDamian Muszynski
87*d9fb8408SDamian Muszynski dma_free_coherent(&GET_DEV(accel_dev), sizeof(*fw_params), fw_params,
88*d9fb8408SDamian Muszynski dma_addr);
89*d9fb8408SDamian Muszynski
90*d9fb8408SDamian Muszynski return ret;
91*d9fb8408SDamian Muszynski }
92*d9fb8408SDamian Muszynski
adf_rl_send_admin_delete_msg(struct adf_accel_dev * accel_dev,u16 node_id,u8 node_type)93*d9fb8408SDamian Muszynski int adf_rl_send_admin_delete_msg(struct adf_accel_dev *accel_dev, u16 node_id,
94*d9fb8408SDamian Muszynski u8 node_type)
95*d9fb8408SDamian Muszynski {
96*d9fb8408SDamian Muszynski return adf_send_admin_rl_delete(accel_dev, node_id, node_type);
97*d9fb8408SDamian Muszynski }
98