1 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
2 /* Copyright(c) 2021 Intel Corporation */
3 #include <linux/crc8.h>
5 #include <linux/types.h>
6 #include "adf_accel_devices.h"
7 #include "adf_pfvf_msg.h"
8 #include "adf_pfvf_utils.h"
11 DECLARE_CRC8_TABLE(pfvf_crc8_table);
12 #define ADF_PFVF_CRC8_POLYNOMIAL 0x97
14 void adf_pfvf_crc_init(void)
16 crc8_populate_msb(pfvf_crc8_table, ADF_PFVF_CRC8_POLYNOMIAL);
19 u8 adf_pfvf_calc_blkmsg_crc(u8 const *buf, u8 buf_len)
21 return crc8(pfvf_crc8_table, buf, buf_len, CRC8_INIT_VALUE);
24 static bool set_value_on_csr_msg(struct adf_accel_dev *accel_dev, u32 *csr_msg,
25 u32 value, const struct pfvf_field_format *fmt)
27 if (unlikely((value & fmt->mask) != value)) {
28 dev_err(&GET_DEV(accel_dev),
29 "PFVF message value 0x%X out of range, %u max allowed\n",
34 *csr_msg |= value << fmt->offset;
39 u32 adf_pfvf_csr_msg_of(struct adf_accel_dev *accel_dev,
40 struct pfvf_message msg,
41 const struct pfvf_csr_format *fmt)
45 if (!set_value_on_csr_msg(accel_dev, &csr_msg, msg.type, &fmt->type) ||
46 !set_value_on_csr_msg(accel_dev, &csr_msg, msg.data, &fmt->data))
49 return csr_msg | ADF_PFVF_MSGORIGIN_SYSTEM;
52 struct pfvf_message adf_pfvf_message_of(struct adf_accel_dev *accel_dev, u32 csr_msg,
53 const struct pfvf_csr_format *fmt)
55 struct pfvf_message msg = { 0 };
57 msg.type = (csr_msg >> fmt->type.offset) & fmt->type.mask;
58 msg.data = (csr_msg >> fmt->data.offset) & fmt->data.mask;
60 if (unlikely(!msg.type))
61 dev_err(&GET_DEV(accel_dev),
62 "Invalid PFVF msg with no type received\n");