0001
0002
0003
0004
0005
0006 #ifndef _UTIL_H
0007 #define _UTIL_H
0008
0009 #include <linux/kernel.h>
0010 #include <linux/delay.h>
0011
0012 #include "spu.h"
0013
0014 extern int flow_debug_logging;
0015 extern int packet_debug_logging;
0016 extern int debug_logging_sleep;
0017
0018 #ifdef DEBUG
0019 #define flow_log(...) \
0020 do { \
0021 if (flow_debug_logging) { \
0022 printk(__VA_ARGS__); \
0023 if (debug_logging_sleep) \
0024 msleep(debug_logging_sleep); \
0025 } \
0026 } while (0)
0027 #define flow_dump(msg, var, var_len) \
0028 do { \
0029 if (flow_debug_logging) { \
0030 print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE, \
0031 16, 1, var, var_len, false); \
0032 if (debug_logging_sleep) \
0033 msleep(debug_logging_sleep); \
0034 } \
0035 } while (0)
0036
0037 #define packet_log(...) \
0038 do { \
0039 if (packet_debug_logging) { \
0040 printk(__VA_ARGS__); \
0041 if (debug_logging_sleep) \
0042 msleep(debug_logging_sleep); \
0043 } \
0044 } while (0)
0045 #define packet_dump(msg, var, var_len) \
0046 do { \
0047 if (packet_debug_logging) { \
0048 print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE, \
0049 16, 1, var, var_len, false); \
0050 if (debug_logging_sleep) \
0051 msleep(debug_logging_sleep); \
0052 } \
0053 } while (0)
0054
0055 void __dump_sg(struct scatterlist *sg, unsigned int skip, unsigned int len);
0056
0057 #define dump_sg(sg, skip, len) __dump_sg(sg, skip, len)
0058
0059 #else
0060
0061 static inline void flow_log(const char *format, ...)
0062 {
0063 }
0064
0065 static inline void flow_dump(const char *msg, const void *var, size_t var_len)
0066 {
0067 }
0068
0069 static inline void packet_log(const char *format, ...)
0070 {
0071 }
0072
0073 static inline void packet_dump(const char *msg, const void *var, size_t var_len)
0074 {
0075 }
0076
0077 static inline void dump_sg(struct scatterlist *sg, unsigned int skip,
0078 unsigned int len)
0079 {
0080 }
0081
0082 #endif
0083
0084 int spu_sg_at_offset(struct scatterlist *sg, unsigned int skip,
0085 struct scatterlist **sge, unsigned int *sge_offset);
0086
0087
0088 void sg_copy_part_to_buf(struct scatterlist *src, u8 *dest,
0089 unsigned int len, unsigned int skip);
0090
0091 void sg_copy_part_from_buf(struct scatterlist *dest, u8 *src,
0092 unsigned int len, unsigned int skip);
0093
0094 int spu_sg_count(struct scatterlist *sg_list, unsigned int skip, int nbytes);
0095 u32 spu_msg_sg_add(struct scatterlist **to_sg,
0096 struct scatterlist **from_sg, u32 *skip,
0097 u8 from_nents, u32 tot_len);
0098
0099 void add_to_ctr(u8 *ctr_pos, unsigned int increment);
0100
0101
0102 int do_shash(unsigned char *name, unsigned char *result,
0103 const u8 *data1, unsigned int data1_len,
0104 const u8 *data2, unsigned int data2_len,
0105 const u8 *key, unsigned int key_len);
0106
0107 char *spu_alg_name(enum spu_cipher_alg alg, enum spu_cipher_mode mode);
0108
0109 void spu_setup_debugfs(void);
0110 void spu_free_debugfs(void);
0111 void format_value_ccm(unsigned int val, u8 *buf, u8 len);
0112
0113 #endif