^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright 2016 Broadcom
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #ifndef _UTIL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define _UTIL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "spu.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) extern int flow_debug_logging;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) extern int packet_debug_logging;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) extern int debug_logging_sleep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define flow_log(...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) if (flow_debug_logging) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) printk(__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) if (debug_logging_sleep) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) msleep(debug_logging_sleep); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define flow_dump(msg, var, var_len) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) if (flow_debug_logging) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 16, 1, var, var_len, false); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) if (debug_logging_sleep) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) msleep(debug_logging_sleep); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define packet_log(...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (packet_debug_logging) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) printk(__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (debug_logging_sleep) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) msleep(debug_logging_sleep); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define packet_dump(msg, var, var_len) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (packet_debug_logging) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 16, 1, var, var_len, false); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (debug_logging_sleep) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) msleep(debug_logging_sleep); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) void __dump_sg(struct scatterlist *sg, unsigned int skip, unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define dump_sg(sg, skip, len) __dump_sg(sg, skip, len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #else /* !DEBUG_ON */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define flow_log(...) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define flow_dump(msg, var, var_len) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define packet_log(...) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define packet_dump(msg, var, var_len) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define dump_sg(sg, skip, len) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #endif /* DEBUG_ON */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int spu_sg_at_offset(struct scatterlist *sg, unsigned int skip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct scatterlist **sge, unsigned int *sge_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* Copy sg data, from skip, length len, to dest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) void sg_copy_part_to_buf(struct scatterlist *src, u8 *dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) unsigned int len, unsigned int skip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* Copy src into scatterlist from offset, length len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) void sg_copy_part_from_buf(struct scatterlist *dest, u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) unsigned int len, unsigned int skip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int spu_sg_count(struct scatterlist *sg_list, unsigned int skip, int nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) u32 spu_msg_sg_add(struct scatterlist **to_sg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct scatterlist **from_sg, u32 *skip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) u8 from_nents, u32 tot_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) void add_to_ctr(u8 *ctr_pos, unsigned int increment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /* produce a message digest from data of length n bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) int do_shash(unsigned char *name, unsigned char *result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) const u8 *data1, unsigned int data1_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) const u8 *data2, unsigned int data2_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) const u8 *key, unsigned int key_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) char *spu_alg_name(enum spu_cipher_alg alg, enum spu_cipher_mode mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) void spu_setup_debugfs(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) void spu_free_debugfs(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) void format_value_ccm(unsigned int val, u8 *buf, u8 len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #endif