brintos

brintos / linux-shallow public Read only

0
0
Text · 5.1 KiB · 10c91e5 Raw
182 lines · c
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"9 10/**11 * adf_vf2pf_notify_init() - send init msg to PF12 * @accel_dev:  Pointer to acceleration VF device.13 *14 * Function sends an init message from the VF to a PF15 *16 * Return: 0 on success, error code otherwise.17 */18int adf_vf2pf_notify_init(struct adf_accel_dev *accel_dev)19{20	struct pfvf_message msg = { .type = ADF_VF2PF_MSGTYPE_INIT };21 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");25		return -EFAULT;26	}27	set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status);28	return 0;29}30EXPORT_SYMBOL_GPL(adf_vf2pf_notify_init);31 32/**33 * adf_vf2pf_notify_shutdown() - send shutdown msg to PF34 * @accel_dev:  Pointer to acceleration VF device.35 *36 * Function sends a shutdown message from the VF to a PF37 *38 * Return: void39 */40void adf_vf2pf_notify_shutdown(struct adf_accel_dev *accel_dev)41{42	struct pfvf_message msg = { .type = ADF_VF2PF_MSGTYPE_SHUTDOWN };43 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");48}49EXPORT_SYMBOL_GPL(adf_vf2pf_notify_shutdown);50 51void adf_vf2pf_notify_restart_complete(struct adf_accel_dev *accel_dev)52{53	struct pfvf_message msg = { .type = ADF_VF2PF_MSGTYPE_RESTARTING_COMPLETE };54 55	/* Check compatibility version */56	if (accel_dev->vf.pf_compat_ver < ADF_PFVF_COMPAT_FALLBACK)57		return;58 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");62}63EXPORT_SYMBOL_GPL(adf_vf2pf_notify_restart_complete);64 65int adf_vf2pf_request_version(struct adf_accel_dev *accel_dev)66{67	u8 pf_version;68	int compat;69	int ret;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,74	};75 76	BUILD_BUG_ON(ADF_PFVF_COMPAT_THIS_VERSION > 255);77 78	ret = adf_send_vf2pf_req(accel_dev, msg, &resp);79	if (ret) {80		dev_err(&GET_DEV(accel_dev),81			"Failed to send Compatibility Version Request.\n");82		return ret;83	}84 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);87 88	/* Response from PF received, check compatibility */89	switch (compat) {90	case ADF_PF2VF_VF_COMPATIBLE:91		break;92	case ADF_PF2VF_VF_COMPAT_UNKNOWN:93		/* VF is newer than PF - compatible for now */94		break;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);99		return -EINVAL;100	default:101		dev_err(&GET_DEV(accel_dev),102			"Invalid response from PF; assume not compatible\n");103		return -EINVAL;104	}105 106	accel_dev->vf.pf_compat_ver = pf_version;107	return 0;108}109 110int adf_vf2pf_get_capabilities(struct adf_accel_dev *accel_dev)111{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);115 116	if (accel_dev->vf.pf_compat_ver < ADF_PFVF_COMPAT_CAPABILITIES)117		/* The PF is too old to support the extended capabilities */118		return 0;119 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");124		return -EFAULT;125	}126 127	switch (cap_msg.hdr.version) {128	default:129		/* Newer version received, handle only the know parts */130		fallthrough;131	case ADF_PFVF_CAPABILITIES_V3_VERSION:132		if (likely(len >= sizeof(struct capabilities_v3)))133			hw_data->clock_frequency = cap_msg.frequency;134		else135			dev_info(&GET_DEV(accel_dev), "Could not get frequency");136		fallthrough;137	case ADF_PFVF_CAPABILITIES_V2_VERSION:138		if (likely(len >= sizeof(struct capabilities_v2)))139			hw_data->accel_capabilities_mask = cap_msg.capabilities;140		else141			dev_info(&GET_DEV(accel_dev), "Could not get capabilities");142		fallthrough;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;146		} else {147			dev_err(&GET_DEV(accel_dev),148				"Capabilities message truncated to %d bytes\n", len);149			return -EFAULT;150		}151	}152 153	return 0;154}155 156int adf_vf2pf_get_ring_to_svc(struct adf_accel_dev *accel_dev)157{158	struct ring_to_svc_map_v1 rts_map_msg = { 0 };159	unsigned int len = sizeof(rts_map_msg);160 161	if (accel_dev->vf.pf_compat_ver < ADF_PFVF_COMPAT_RING_TO_SVC_MAP)162		/* Use already set default mappings */163		return 0;164 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");169		return -EFAULT;170	}171 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);175		return -EFAULT;176	}177 178	/* Only v1 at present */179	accel_dev->hw_device->ring_to_svc_map = rts_map_msg.map;180	return 0;181}182