1 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
2 /* Copyright(c) 2015 - 2021 Intel Corporation */
3 #include <linux/bitfield.h>
4 #include "adf_accel_devices.h"
5 #include "adf_common_drv.h"
6 #include "adf_pfvf_msg.h"
7 #include "adf_pfvf_vf_msg.h"
8 #include "adf_pfvf_vf_proto.h"
11 * adf_vf2pf_notify_init() - send init msg to PF
12 * @accel_dev: Pointer to acceleration VF device.
14 * Function sends an init message from the VF to a PF
16 * Return: 0 on success, error code otherwise.
18 int adf_vf2pf_notify_init(struct adf_accel_dev *accel_dev)
20 struct pfvf_message msg = { .type = ADF_VF2PF_MSGTYPE_INIT };
22 if (adf_send_vf2pf_msg(accel_dev, msg)) {
23 dev_err(&GET_DEV(accel_dev),
24 "Failed to send Init event to PF\n");
27 set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status);
30 EXPORT_SYMBOL_GPL(adf_vf2pf_notify_init);
33 * adf_vf2pf_notify_shutdown() - send shutdown msg to PF
34 * @accel_dev: Pointer to acceleration VF device.
36 * Function sends a shutdown message from the VF to a PF
40 void adf_vf2pf_notify_shutdown(struct adf_accel_dev *accel_dev)
42 struct pfvf_message msg = { .type = ADF_VF2PF_MSGTYPE_SHUTDOWN };
44 if (test_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status))
45 if (adf_send_vf2pf_msg(accel_dev, msg))
46 dev_err(&GET_DEV(accel_dev),
47 "Failed to send Shutdown event to PF\n");
49 EXPORT_SYMBOL_GPL(adf_vf2pf_notify_shutdown);
51 void adf_vf2pf_notify_restart_complete(struct adf_accel_dev *accel_dev)
53 struct pfvf_message msg = { .type = ADF_VF2PF_MSGTYPE_RESTARTING_COMPLETE };
55 /* Check compatibility version */
56 if (accel_dev->vf.pf_compat_ver < ADF_PFVF_COMPAT_FALLBACK)
59 if (adf_send_vf2pf_msg(accel_dev, msg))
60 dev_err(&GET_DEV(accel_dev),
61 "Failed to send Restarting complete event to PF\n");
63 EXPORT_SYMBOL_GPL(adf_vf2pf_notify_restart_complete);
65 int adf_vf2pf_request_version(struct adf_accel_dev *accel_dev)
70 struct pfvf_message resp;
71 struct pfvf_message msg = {
72 .type = ADF_VF2PF_MSGTYPE_COMPAT_VER_REQ,
73 .data = ADF_PFVF_COMPAT_THIS_VERSION,
76 BUILD_BUG_ON(ADF_PFVF_COMPAT_THIS_VERSION > 255);
78 ret = adf_send_vf2pf_req(accel_dev, msg, &resp);
80 dev_err(&GET_DEV(accel_dev),
81 "Failed to send Compatibility Version Request.\n");
85 pf_version = FIELD_GET(ADF_PF2VF_VERSION_RESP_VERS_MASK, resp.data);
86 compat = FIELD_GET(ADF_PF2VF_VERSION_RESP_RESULT_MASK, resp.data);
88 /* Response from PF received, check compatibility */
90 case ADF_PF2VF_VF_COMPATIBLE:
92 case ADF_PF2VF_VF_COMPAT_UNKNOWN:
93 /* VF is newer than PF - compatible for now */
95 case ADF_PF2VF_VF_INCOMPATIBLE:
96 dev_err(&GET_DEV(accel_dev),
97 "PF (vers %d) and VF (vers %d) are not compatible\n",
98 pf_version, ADF_PFVF_COMPAT_THIS_VERSION);
101 dev_err(&GET_DEV(accel_dev),
102 "Invalid response from PF; assume not compatible\n");
106 accel_dev->vf.pf_compat_ver = pf_version;
110 int adf_vf2pf_get_capabilities(struct adf_accel_dev *accel_dev)
112 struct adf_hw_device_data *hw_data = accel_dev->hw_device;
113 struct capabilities_v3 cap_msg = { 0 };
114 unsigned int len = sizeof(cap_msg);
116 if (accel_dev->vf.pf_compat_ver < ADF_PFVF_COMPAT_CAPABILITIES)
117 /* The PF is too old to support the extended capabilities */
120 if (adf_send_vf2pf_blkmsg_req(accel_dev, ADF_VF2PF_BLKMSG_REQ_CAP_SUMMARY,
121 (u8 *)&cap_msg, &len)) {
122 dev_err(&GET_DEV(accel_dev),
123 "QAT: Failed to get block message response\n");
127 switch (cap_msg.hdr.version) {
129 /* Newer version received, handle only the know parts */
131 case ADF_PFVF_CAPABILITIES_V3_VERSION:
132 if (likely(len >= sizeof(struct capabilities_v3)))
133 hw_data->clock_frequency = cap_msg.frequency;
135 dev_info(&GET_DEV(accel_dev), "Could not get frequency");
137 case ADF_PFVF_CAPABILITIES_V2_VERSION:
138 if (likely(len >= sizeof(struct capabilities_v2)))
139 hw_data->accel_capabilities_mask = cap_msg.capabilities;
141 dev_info(&GET_DEV(accel_dev), "Could not get capabilities");
143 case ADF_PFVF_CAPABILITIES_V1_VERSION:
144 if (likely(len >= sizeof(struct capabilities_v1))) {
145 hw_data->extended_dc_capabilities = cap_msg.ext_dc_caps;
147 dev_err(&GET_DEV(accel_dev),
148 "Capabilities message truncated to %d bytes\n", len);
156 int adf_vf2pf_get_ring_to_svc(struct adf_accel_dev *accel_dev)
158 struct ring_to_svc_map_v1 rts_map_msg = { 0 };
159 unsigned int len = sizeof(rts_map_msg);
161 if (accel_dev->vf.pf_compat_ver < ADF_PFVF_COMPAT_RING_TO_SVC_MAP)
162 /* Use already set default mappings */
165 if (adf_send_vf2pf_blkmsg_req(accel_dev, ADF_VF2PF_BLKMSG_REQ_RING_SVC_MAP,
166 (u8 *)&rts_map_msg, &len)) {
167 dev_err(&GET_DEV(accel_dev),
168 "QAT: Failed to get block message response\n");
172 if (unlikely(len < sizeof(struct ring_to_svc_map_v1))) {
173 dev_err(&GET_DEV(accel_dev),
174 "RING_TO_SVC message truncated to %d bytes\n", len);
178 /* Only v1 at present */
179 accel_dev->hw_device->ring_to_svc_map = rts_map_msg.map;