18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright 2016 Broadcom
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef _UTIL_H
78c2ecf20Sopenharmony_ci#define _UTIL_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/kernel.h>
108c2ecf20Sopenharmony_ci#include <linux/delay.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include "spu.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciextern int flow_debug_logging;
158c2ecf20Sopenharmony_ciextern int packet_debug_logging;
168c2ecf20Sopenharmony_ciextern int debug_logging_sleep;
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#ifdef DEBUG
198c2ecf20Sopenharmony_ci#define flow_log(...)	                \
208c2ecf20Sopenharmony_ci	do {	                              \
218c2ecf20Sopenharmony_ci		if (flow_debug_logging) {	        \
228c2ecf20Sopenharmony_ci			printk(__VA_ARGS__);	          \
238c2ecf20Sopenharmony_ci			if (debug_logging_sleep)	      \
248c2ecf20Sopenharmony_ci				msleep(debug_logging_sleep);	\
258c2ecf20Sopenharmony_ci		}	                                \
268c2ecf20Sopenharmony_ci	} while (0)
278c2ecf20Sopenharmony_ci#define flow_dump(msg, var, var_len)	   \
288c2ecf20Sopenharmony_ci	do {	                                 \
298c2ecf20Sopenharmony_ci		if (flow_debug_logging) {	           \
308c2ecf20Sopenharmony_ci			print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE,  \
318c2ecf20Sopenharmony_ci					16, 1, var, var_len, false); \
328c2ecf20Sopenharmony_ci				if (debug_logging_sleep)	       \
338c2ecf20Sopenharmony_ci					msleep(debug_logging_sleep);   \
348c2ecf20Sopenharmony_ci		}                                    \
358c2ecf20Sopenharmony_ci	} while (0)
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#define packet_log(...)               \
388c2ecf20Sopenharmony_ci	do {                                \
398c2ecf20Sopenharmony_ci		if (packet_debug_logging) {       \
408c2ecf20Sopenharmony_ci			printk(__VA_ARGS__);            \
418c2ecf20Sopenharmony_ci			if (debug_logging_sleep)        \
428c2ecf20Sopenharmony_ci				msleep(debug_logging_sleep);  \
438c2ecf20Sopenharmony_ci		}                                 \
448c2ecf20Sopenharmony_ci	} while (0)
458c2ecf20Sopenharmony_ci#define packet_dump(msg, var, var_len)   \
468c2ecf20Sopenharmony_ci	do {                                   \
478c2ecf20Sopenharmony_ci		if (packet_debug_logging) {          \
488c2ecf20Sopenharmony_ci			print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE,  \
498c2ecf20Sopenharmony_ci					16, 1, var, var_len, false); \
508c2ecf20Sopenharmony_ci			if (debug_logging_sleep)           \
518c2ecf20Sopenharmony_ci				msleep(debug_logging_sleep);     \
528c2ecf20Sopenharmony_ci		}                                    \
538c2ecf20Sopenharmony_ci	} while (0)
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_civoid __dump_sg(struct scatterlist *sg, unsigned int skip, unsigned int len);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#define dump_sg(sg, skip, len)     __dump_sg(sg, skip, len)
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#else /* !DEBUG_ON */
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci#define flow_log(...) do {} while (0)
628c2ecf20Sopenharmony_ci#define flow_dump(msg, var, var_len) do {} while (0)
638c2ecf20Sopenharmony_ci#define packet_log(...) do {} while (0)
648c2ecf20Sopenharmony_ci#define packet_dump(msg, var, var_len) do {} while (0)
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define dump_sg(sg, skip, len) do {} while (0)
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#endif /* DEBUG_ON */
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ciint spu_sg_at_offset(struct scatterlist *sg, unsigned int skip,
718c2ecf20Sopenharmony_ci		     struct scatterlist **sge, unsigned int *sge_offset);
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/* Copy sg data, from skip, length len, to dest */
748c2ecf20Sopenharmony_civoid sg_copy_part_to_buf(struct scatterlist *src, u8 *dest,
758c2ecf20Sopenharmony_ci			 unsigned int len, unsigned int skip);
768c2ecf20Sopenharmony_ci/* Copy src into scatterlist from offset, length len */
778c2ecf20Sopenharmony_civoid sg_copy_part_from_buf(struct scatterlist *dest, u8 *src,
788c2ecf20Sopenharmony_ci			   unsigned int len, unsigned int skip);
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ciint spu_sg_count(struct scatterlist *sg_list, unsigned int skip, int nbytes);
818c2ecf20Sopenharmony_ciu32 spu_msg_sg_add(struct scatterlist **to_sg,
828c2ecf20Sopenharmony_ci		   struct scatterlist **from_sg, u32 *skip,
838c2ecf20Sopenharmony_ci		   u8 from_nents, u32 tot_len);
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_civoid add_to_ctr(u8 *ctr_pos, unsigned int increment);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci/* produce a message digest from data of length n bytes */
888c2ecf20Sopenharmony_ciint do_shash(unsigned char *name, unsigned char *result,
898c2ecf20Sopenharmony_ci	     const u8 *data1, unsigned int data1_len,
908c2ecf20Sopenharmony_ci	     const u8 *data2, unsigned int data2_len,
918c2ecf20Sopenharmony_ci	     const u8 *key, unsigned int key_len);
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cichar *spu_alg_name(enum spu_cipher_alg alg, enum spu_cipher_mode mode);
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_civoid spu_setup_debugfs(void);
968c2ecf20Sopenharmony_civoid spu_free_debugfs(void);
978c2ecf20Sopenharmony_civoid format_value_ccm(unsigned int val, u8 *buf, u8 len);
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#endif
100