util.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2016 Broadcom
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License, version 2, as
  6. * published by the Free Software Foundation (the "GPL").
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License version 2 (GPLv2) for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * version 2 (GPLv2) along with this source code.
  15. */
  16. #ifndef _UTIL_H
  17. #define _UTIL_H
  18. #include <linux/kernel.h>
  19. #include <linux/delay.h>
  20. #include "spu.h"
  21. extern int flow_debug_logging;
  22. extern int packet_debug_logging;
  23. extern int debug_logging_sleep;
  24. #ifdef DEBUG
  25. #define flow_log(...) \
  26. do { \
  27. if (flow_debug_logging) { \
  28. printk(__VA_ARGS__); \
  29. if (debug_logging_sleep) \
  30. msleep(debug_logging_sleep); \
  31. } \
  32. } while (0)
  33. #define flow_dump(msg, var, var_len) \
  34. do { \
  35. if (flow_debug_logging) { \
  36. print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE, \
  37. 16, 1, var, var_len, false); \
  38. if (debug_logging_sleep) \
  39. msleep(debug_logging_sleep); \
  40. } \
  41. } while (0)
  42. #define packet_log(...) \
  43. do { \
  44. if (packet_debug_logging) { \
  45. printk(__VA_ARGS__); \
  46. if (debug_logging_sleep) \
  47. msleep(debug_logging_sleep); \
  48. } \
  49. } while (0)
  50. #define packet_dump(msg, var, var_len) \
  51. do { \
  52. if (packet_debug_logging) { \
  53. print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE, \
  54. 16, 1, var, var_len, false); \
  55. if (debug_logging_sleep) \
  56. msleep(debug_logging_sleep); \
  57. } \
  58. } while (0)
  59. void __dump_sg(struct scatterlist *sg, unsigned int skip, unsigned int len);
  60. #define dump_sg(sg, skip, len) __dump_sg(sg, skip, len)
  61. #else /* !DEBUG_ON */
  62. #define flow_log(...) do {} while (0)
  63. #define flow_dump(msg, var, var_len) do {} while (0)
  64. #define packet_log(...) do {} while (0)
  65. #define packet_dump(msg, var, var_len) do {} while (0)
  66. #define dump_sg(sg, skip, len) do {} while (0)
  67. #endif /* DEBUG_ON */
  68. int spu_sg_at_offset(struct scatterlist *sg, unsigned int skip,
  69. struct scatterlist **sge, unsigned int *sge_offset);
  70. /* Copy sg data, from skip, length len, to dest */
  71. void sg_copy_part_to_buf(struct scatterlist *src, u8 *dest,
  72. unsigned int len, unsigned int skip);
  73. /* Copy src into scatterlist from offset, length len */
  74. void sg_copy_part_from_buf(struct scatterlist *dest, u8 *src,
  75. unsigned int len, unsigned int skip);
  76. int spu_sg_count(struct scatterlist *sg_list, unsigned int skip, int nbytes);
  77. u32 spu_msg_sg_add(struct scatterlist **to_sg,
  78. struct scatterlist **from_sg, u32 *skip,
  79. u8 from_nents, u32 tot_len);
  80. void add_to_ctr(u8 *ctr_pos, unsigned int increment);
  81. /* do a synchronous decrypt operation */
  82. int do_decrypt(char *alg_name,
  83. void *key_ptr, unsigned int key_len,
  84. void *iv_ptr, void *src_ptr, void *dst_ptr,
  85. unsigned int block_len);
  86. /* produce a message digest from data of length n bytes */
  87. int do_shash(unsigned char *name, unsigned char *result,
  88. const u8 *data1, unsigned int data1_len,
  89. const u8 *data2, unsigned int data2_len,
  90. const u8 *key, unsigned int key_len);
  91. char *spu_alg_name(enum spu_cipher_alg alg, enum spu_cipher_mode mode);
  92. void spu_setup_debugfs(void);
  93. void spu_free_debugfs(void);
  94. void format_value_ccm(unsigned int val, u8 *buf, u8 len);
  95. #endif