linux/drivers/crypto/bcm/util.h
<<
>>
Prefs
   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
  17#ifndef _UTIL_H
  18#define _UTIL_H
  19
  20#include <linux/kernel.h>
  21#include <linux/delay.h>
  22
  23#include "spu.h"
  24
  25extern int flow_debug_logging;
  26extern int packet_debug_logging;
  27extern int debug_logging_sleep;
  28
  29#ifdef DEBUG
  30#define flow_log(...)                   \
  31        do {                                  \
  32                if (flow_debug_logging) {               \
  33                        printk(__VA_ARGS__);              \
  34                        if (debug_logging_sleep)              \
  35                                msleep(debug_logging_sleep);    \
  36                }                                       \
  37        } while (0)
  38#define flow_dump(msg, var, var_len)       \
  39        do {                                     \
  40                if (flow_debug_logging) {                  \
  41                        print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE,  \
  42                                        16, 1, var, var_len, false); \
  43                                if (debug_logging_sleep)               \
  44                                        msleep(debug_logging_sleep);   \
  45                }                                    \
  46        } while (0)
  47
  48#define packet_log(...)               \
  49        do {                                \
  50                if (packet_debug_logging) {       \
  51                        printk(__VA_ARGS__);            \
  52                        if (debug_logging_sleep)        \
  53                                msleep(debug_logging_sleep);  \
  54                }                                 \
  55        } while (0)
  56#define packet_dump(msg, var, var_len)   \
  57        do {                                   \
  58                if (packet_debug_logging) {          \
  59                        print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE,  \
  60                                        16, 1, var, var_len, false); \
  61                        if (debug_logging_sleep)           \
  62                                msleep(debug_logging_sleep);     \
  63                }                                    \
  64        } while (0)
  65
  66void __dump_sg(struct scatterlist *sg, unsigned int skip, unsigned int len);
  67
  68#define dump_sg(sg, skip, len)     __dump_sg(sg, skip, len)
  69
  70#else /* !DEBUG_ON */
  71
  72#define flow_log(...) do {} while (0)
  73#define flow_dump(msg, var, var_len) do {} while (0)
  74#define packet_log(...) do {} while (0)
  75#define packet_dump(msg, var, var_len) do {} while (0)
  76
  77#define dump_sg(sg, skip, len) do {} while (0)
  78
  79#endif /* DEBUG_ON */
  80
  81int spu_sg_at_offset(struct scatterlist *sg, unsigned int skip,
  82                     struct scatterlist **sge, unsigned int *sge_offset);
  83
  84/* Copy sg data, from skip, length len, to dest */
  85void sg_copy_part_to_buf(struct scatterlist *src, u8 *dest,
  86                         unsigned int len, unsigned int skip);
  87/* Copy src into scatterlist from offset, length len */
  88void sg_copy_part_from_buf(struct scatterlist *dest, u8 *src,
  89                           unsigned int len, unsigned int skip);
  90
  91int spu_sg_count(struct scatterlist *sg_list, unsigned int skip, int nbytes);
  92u32 spu_msg_sg_add(struct scatterlist **to_sg,
  93                   struct scatterlist **from_sg, u32 *skip,
  94                   u8 from_nents, u32 tot_len);
  95
  96void add_to_ctr(u8 *ctr_pos, unsigned int increment);
  97
  98/* do a synchronous decrypt operation */
  99int do_decrypt(char *alg_name,
 100               void *key_ptr, unsigned int key_len,
 101               void *iv_ptr, void *src_ptr, void *dst_ptr,
 102               unsigned int block_len);
 103
 104/* produce a message digest from data of length n bytes */
 105int do_shash(unsigned char *name, unsigned char *result,
 106             const u8 *data1, unsigned int data1_len,
 107             const u8 *data2, unsigned int data2_len,
 108             const u8 *key, unsigned int key_len);
 109
 110char *spu_alg_name(enum spu_cipher_alg alg, enum spu_cipher_mode mode);
 111
 112void spu_setup_debugfs(void);
 113void spu_free_debugfs(void);
 114void format_value_ccm(unsigned int val, u8 *buf, u8 len);
 115
 116#endif
 117