162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright 2016 Broadcom
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef _UTIL_H
762306a36Sopenharmony_ci#define _UTIL_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/kernel.h>
1062306a36Sopenharmony_ci#include <linux/delay.h>
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include "spu.h"
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ciextern int flow_debug_logging;
1562306a36Sopenharmony_ciextern int packet_debug_logging;
1662306a36Sopenharmony_ciextern int debug_logging_sleep;
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#ifdef DEBUG
1962306a36Sopenharmony_ci#define flow_log(...)	                \
2062306a36Sopenharmony_ci	do {	                              \
2162306a36Sopenharmony_ci		if (flow_debug_logging) {	        \
2262306a36Sopenharmony_ci			printk(__VA_ARGS__);	          \
2362306a36Sopenharmony_ci			if (debug_logging_sleep)	      \
2462306a36Sopenharmony_ci				msleep(debug_logging_sleep);	\
2562306a36Sopenharmony_ci		}	                                \
2662306a36Sopenharmony_ci	} while (0)
2762306a36Sopenharmony_ci#define flow_dump(msg, var, var_len)	   \
2862306a36Sopenharmony_ci	do {	                                 \
2962306a36Sopenharmony_ci		if (flow_debug_logging) {	           \
3062306a36Sopenharmony_ci			print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE,  \
3162306a36Sopenharmony_ci					16, 1, var, var_len, false); \
3262306a36Sopenharmony_ci				if (debug_logging_sleep)	       \
3362306a36Sopenharmony_ci					msleep(debug_logging_sleep);   \
3462306a36Sopenharmony_ci		}                                    \
3562306a36Sopenharmony_ci	} while (0)
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci#define packet_log(...)               \
3862306a36Sopenharmony_ci	do {                                \
3962306a36Sopenharmony_ci		if (packet_debug_logging) {       \
4062306a36Sopenharmony_ci			printk(__VA_ARGS__);            \
4162306a36Sopenharmony_ci			if (debug_logging_sleep)        \
4262306a36Sopenharmony_ci				msleep(debug_logging_sleep);  \
4362306a36Sopenharmony_ci		}                                 \
4462306a36Sopenharmony_ci	} while (0)
4562306a36Sopenharmony_ci#define packet_dump(msg, var, var_len)   \
4662306a36Sopenharmony_ci	do {                                   \
4762306a36Sopenharmony_ci		if (packet_debug_logging) {          \
4862306a36Sopenharmony_ci			print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE,  \
4962306a36Sopenharmony_ci					16, 1, var, var_len, false); \
5062306a36Sopenharmony_ci			if (debug_logging_sleep)           \
5162306a36Sopenharmony_ci				msleep(debug_logging_sleep);     \
5262306a36Sopenharmony_ci		}                                    \
5362306a36Sopenharmony_ci	} while (0)
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_civoid __dump_sg(struct scatterlist *sg, unsigned int skip, unsigned int len);
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci#define dump_sg(sg, skip, len)     __dump_sg(sg, skip, len)
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#else /* !DEBUG_ON */
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_cistatic inline void flow_log(const char *format, ...)
6262306a36Sopenharmony_ci{
6362306a36Sopenharmony_ci}
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_cistatic inline void flow_dump(const char *msg, const void *var, size_t var_len)
6662306a36Sopenharmony_ci{
6762306a36Sopenharmony_ci}
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_cistatic inline void packet_log(const char *format, ...)
7062306a36Sopenharmony_ci{
7162306a36Sopenharmony_ci}
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_cistatic inline void packet_dump(const char *msg, const void *var, size_t var_len)
7462306a36Sopenharmony_ci{
7562306a36Sopenharmony_ci}
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_cistatic inline void dump_sg(struct scatterlist *sg, unsigned int skip,
7862306a36Sopenharmony_ci			   unsigned int len)
7962306a36Sopenharmony_ci{
8062306a36Sopenharmony_ci}
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci#endif /* DEBUG_ON */
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ciint spu_sg_at_offset(struct scatterlist *sg, unsigned int skip,
8562306a36Sopenharmony_ci		     struct scatterlist **sge, unsigned int *sge_offset);
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci/* Copy sg data, from skip, length len, to dest */
8862306a36Sopenharmony_civoid sg_copy_part_to_buf(struct scatterlist *src, u8 *dest,
8962306a36Sopenharmony_ci			 unsigned int len, unsigned int skip);
9062306a36Sopenharmony_ci/* Copy src into scatterlist from offset, length len */
9162306a36Sopenharmony_civoid sg_copy_part_from_buf(struct scatterlist *dest, u8 *src,
9262306a36Sopenharmony_ci			   unsigned int len, unsigned int skip);
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ciint spu_sg_count(struct scatterlist *sg_list, unsigned int skip, int nbytes);
9562306a36Sopenharmony_ciu32 spu_msg_sg_add(struct scatterlist **to_sg,
9662306a36Sopenharmony_ci		   struct scatterlist **from_sg, u32 *skip,
9762306a36Sopenharmony_ci		   u8 from_nents, u32 tot_len);
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_civoid add_to_ctr(u8 *ctr_pos, unsigned int increment);
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci/* produce a message digest from data of length n bytes */
10262306a36Sopenharmony_ciint do_shash(unsigned char *name, unsigned char *result,
10362306a36Sopenharmony_ci	     const u8 *data1, unsigned int data1_len,
10462306a36Sopenharmony_ci	     const u8 *data2, unsigned int data2_len,
10562306a36Sopenharmony_ci	     const u8 *key, unsigned int key_len);
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_cichar *spu_alg_name(enum spu_cipher_alg alg, enum spu_cipher_mode mode);
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_civoid spu_setup_debugfs(void);
11062306a36Sopenharmony_civoid spu_free_debugfs(void);
11162306a36Sopenharmony_civoid format_value_ccm(unsigned int val, u8 *buf, u8 len);
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci#endif
114