xref: /openbmc/linux/drivers/crypto/bcm/util.h (revision d0034a7a4ac7fae708146ac0059b9c47a1543f0d)
1cb849fc5SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
29d12ba86SRob Rice /*
39d12ba86SRob Rice  * Copyright 2016 Broadcom
49d12ba86SRob Rice  */
59d12ba86SRob Rice 
69d12ba86SRob Rice #ifndef _UTIL_H
79d12ba86SRob Rice #define _UTIL_H
89d12ba86SRob Rice 
99d12ba86SRob Rice #include <linux/kernel.h>
109d12ba86SRob Rice #include <linux/delay.h>
119d12ba86SRob Rice 
129d12ba86SRob Rice #include "spu.h"
139d12ba86SRob Rice 
149d12ba86SRob Rice extern int flow_debug_logging;
159d12ba86SRob Rice extern int packet_debug_logging;
169d12ba86SRob Rice extern int debug_logging_sleep;
179d12ba86SRob Rice 
189d12ba86SRob Rice #ifdef DEBUG
199d12ba86SRob Rice #define flow_log(...)	                \
209d12ba86SRob Rice 	do {	                              \
219d12ba86SRob Rice 		if (flow_debug_logging) {	        \
229d12ba86SRob Rice 			printk(__VA_ARGS__);	          \
239d12ba86SRob Rice 			if (debug_logging_sleep)	      \
249d12ba86SRob Rice 				msleep(debug_logging_sleep);	\
259d12ba86SRob Rice 		}	                                \
269d12ba86SRob Rice 	} while (0)
279d12ba86SRob Rice #define flow_dump(msg, var, var_len)	   \
289d12ba86SRob Rice 	do {	                                 \
299d12ba86SRob Rice 		if (flow_debug_logging) {	           \
309d12ba86SRob Rice 			print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE,  \
319d12ba86SRob Rice 					16, 1, var, var_len, false); \
329d12ba86SRob Rice 				if (debug_logging_sleep)	       \
339d12ba86SRob Rice 					msleep(debug_logging_sleep);   \
349d12ba86SRob Rice 		}                                    \
359d12ba86SRob Rice 	} while (0)
369d12ba86SRob Rice 
379d12ba86SRob Rice #define packet_log(...)               \
389d12ba86SRob Rice 	do {                                \
399d12ba86SRob Rice 		if (packet_debug_logging) {       \
409d12ba86SRob Rice 			printk(__VA_ARGS__);            \
419d12ba86SRob Rice 			if (debug_logging_sleep)        \
429d12ba86SRob Rice 				msleep(debug_logging_sleep);  \
439d12ba86SRob Rice 		}                                 \
449d12ba86SRob Rice 	} while (0)
459d12ba86SRob Rice #define packet_dump(msg, var, var_len)   \
469d12ba86SRob Rice 	do {                                   \
479d12ba86SRob Rice 		if (packet_debug_logging) {          \
489d12ba86SRob Rice 			print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE,  \
499d12ba86SRob Rice 					16, 1, var, var_len, false); \
509d12ba86SRob Rice 			if (debug_logging_sleep)           \
519d12ba86SRob Rice 				msleep(debug_logging_sleep);     \
529d12ba86SRob Rice 		}                                    \
539d12ba86SRob Rice 	} while (0)
549d12ba86SRob Rice 
559d12ba86SRob Rice void __dump_sg(struct scatterlist *sg, unsigned int skip, unsigned int len);
569d12ba86SRob Rice 
579d12ba86SRob Rice #define dump_sg(sg, skip, len)     __dump_sg(sg, skip, len)
589d12ba86SRob Rice 
599d12ba86SRob Rice #else /* !DEBUG_ON */
609d12ba86SRob Rice 
flow_log(const char * format,...)61*5a17eae4SHerbert Xu static inline void flow_log(const char *format, ...)
62*5a17eae4SHerbert Xu {
63*5a17eae4SHerbert Xu }
649d12ba86SRob Rice 
flow_dump(const char * msg,const void * var,size_t var_len)65*5a17eae4SHerbert Xu static inline void flow_dump(const char *msg, const void *var, size_t var_len)
66*5a17eae4SHerbert Xu {
67*5a17eae4SHerbert Xu }
68*5a17eae4SHerbert Xu 
packet_log(const char * format,...)69*5a17eae4SHerbert Xu static inline void packet_log(const char *format, ...)
70*5a17eae4SHerbert Xu {
71*5a17eae4SHerbert Xu }
72*5a17eae4SHerbert Xu 
packet_dump(const char * msg,const void * var,size_t var_len)73*5a17eae4SHerbert Xu static inline void packet_dump(const char *msg, const void *var, size_t var_len)
74*5a17eae4SHerbert Xu {
75*5a17eae4SHerbert Xu }
76*5a17eae4SHerbert Xu 
dump_sg(struct scatterlist * sg,unsigned int skip,unsigned int len)77*5a17eae4SHerbert Xu static inline void dump_sg(struct scatterlist *sg, unsigned int skip,
78*5a17eae4SHerbert Xu 			   unsigned int len)
79*5a17eae4SHerbert Xu {
80*5a17eae4SHerbert Xu }
819d12ba86SRob Rice 
829d12ba86SRob Rice #endif /* DEBUG_ON */
839d12ba86SRob Rice 
849d12ba86SRob Rice int spu_sg_at_offset(struct scatterlist *sg, unsigned int skip,
859d12ba86SRob Rice 		     struct scatterlist **sge, unsigned int *sge_offset);
869d12ba86SRob Rice 
879d12ba86SRob Rice /* Copy sg data, from skip, length len, to dest */
889d12ba86SRob Rice void sg_copy_part_to_buf(struct scatterlist *src, u8 *dest,
899d12ba86SRob Rice 			 unsigned int len, unsigned int skip);
909d12ba86SRob Rice /* Copy src into scatterlist from offset, length len */
919d12ba86SRob Rice void sg_copy_part_from_buf(struct scatterlist *dest, u8 *src,
929d12ba86SRob Rice 			   unsigned int len, unsigned int skip);
939d12ba86SRob Rice 
949d12ba86SRob Rice int spu_sg_count(struct scatterlist *sg_list, unsigned int skip, int nbytes);
959d12ba86SRob Rice u32 spu_msg_sg_add(struct scatterlist **to_sg,
969d12ba86SRob Rice 		   struct scatterlist **from_sg, u32 *skip,
979d12ba86SRob Rice 		   u8 from_nents, u32 tot_len);
989d12ba86SRob Rice 
999d12ba86SRob Rice void add_to_ctr(u8 *ctr_pos, unsigned int increment);
1009d12ba86SRob Rice 
1019d12ba86SRob Rice /* produce a message digest from data of length n bytes */
1029d12ba86SRob Rice int do_shash(unsigned char *name, unsigned char *result,
1039d12ba86SRob Rice 	     const u8 *data1, unsigned int data1_len,
1049d12ba86SRob Rice 	     const u8 *data2, unsigned int data2_len,
1059d12ba86SRob Rice 	     const u8 *key, unsigned int key_len);
1069d12ba86SRob Rice 
1079d12ba86SRob Rice char *spu_alg_name(enum spu_cipher_alg alg, enum spu_cipher_mode mode);
1089d12ba86SRob Rice 
1099d12ba86SRob Rice void spu_setup_debugfs(void);
1109d12ba86SRob Rice void spu_free_debugfs(void);
1119d12ba86SRob Rice void format_value_ccm(unsigned int val, u8 *buf, u8 len);
1129d12ba86SRob Rice 
1139d12ba86SRob Rice #endif
114