linux/drivers/crypto/nx/nx.h
<<
>>
Prefs
   1
   2#ifndef __NX_H__
   3#define __NX_H__
   4
   5#define NX_NAME         "nx-crypto"
   6#define NX_STRING       "IBM Power7+ Nest Accelerator Crypto Driver"
   7#define NX_VERSION      "1.0"
   8
   9static const char nx_driver_string[] = NX_STRING;
  10static const char nx_driver_version[] = NX_VERSION;
  11
  12/* a scatterlist in the format PHYP is expecting */
  13struct nx_sg {
  14        u64 addr;
  15        u32 rsvd;
  16        u32 len;
  17} __attribute((packed));
  18
  19#define NX_PAGE_SIZE            (4096)
  20#define NX_MAX_SG_ENTRIES       (NX_PAGE_SIZE/(sizeof(struct nx_sg)))
  21
  22enum nx_status {
  23        NX_DISABLED,
  24        NX_WAITING,
  25        NX_OKAY
  26};
  27
  28/* msc_triplet and max_sync_cop are used only to assist in parsing the
  29 * openFirmware property */
  30struct msc_triplet {
  31        u32 keybitlen;
  32        u32 databytelen;
  33        u32 sglen;
  34} __packed;
  35
  36struct max_sync_cop {
  37        u32 fc;
  38        u32 mode;
  39        u32 triplets;
  40        struct msc_triplet trip[0];
  41} __packed;
  42
  43struct alg_props {
  44        u32 databytelen;
  45        u32 sglen;
  46};
  47
  48#define NX_OF_FLAG_MAXSGLEN_SET         (1)
  49#define NX_OF_FLAG_STATUS_SET           (2)
  50#define NX_OF_FLAG_MAXSYNCCOP_SET       (4)
  51#define NX_OF_FLAG_MASK_READY           (NX_OF_FLAG_MAXSGLEN_SET | \
  52                                         NX_OF_FLAG_STATUS_SET |   \
  53                                         NX_OF_FLAG_MAXSYNCCOP_SET)
  54struct nx_of {
  55        u32 flags;
  56        u32 max_sg_len;
  57        enum nx_status status;
  58        struct alg_props ap[NX_MAX_FC][NX_MAX_MODE][3];
  59};
  60
  61struct nx_stats {
  62        atomic_t aes_ops;
  63        atomic64_t aes_bytes;
  64        atomic_t sha256_ops;
  65        atomic64_t sha256_bytes;
  66        atomic_t sha512_ops;
  67        atomic64_t sha512_bytes;
  68
  69        atomic_t sync_ops;
  70
  71        atomic_t errors;
  72        atomic_t last_error;
  73        atomic_t last_error_pid;
  74};
  75
  76struct nx_debugfs {
  77        struct dentry *dfs_root;
  78        struct dentry *dfs_aes_ops, *dfs_aes_bytes;
  79        struct dentry *dfs_sha256_ops, *dfs_sha256_bytes;
  80        struct dentry *dfs_sha512_ops, *dfs_sha512_bytes;
  81        struct dentry *dfs_errors, *dfs_last_error, *dfs_last_error_pid;
  82};
  83
  84struct nx_crypto_driver {
  85        struct nx_stats    stats;
  86        struct nx_of       of;
  87        struct vio_dev    *viodev;
  88        struct vio_driver  viodriver;
  89        struct nx_debugfs  dfs;
  90};
  91
  92#define NX_GCM4106_NONCE_LEN            (4)
  93#define NX_GCM_CTR_OFFSET               (12)
  94struct nx_gcm_priv {
  95        u8 iv[16];
  96        u8 iauth_tag[16];
  97        u8 nonce[NX_GCM4106_NONCE_LEN];
  98};
  99
 100#define NX_CCM_AES_KEY_LEN              (16)
 101#define NX_CCM4309_AES_KEY_LEN          (19)
 102#define NX_CCM4309_NONCE_LEN            (3)
 103struct nx_ccm_priv {
 104        u8 iv[16];
 105        u8 b0[16];
 106        u8 iauth_tag[16];
 107        u8 oauth_tag[16];
 108        u8 nonce[NX_CCM4309_NONCE_LEN];
 109};
 110
 111struct nx_xcbc_priv {
 112        u8 key[16];
 113};
 114
 115struct nx_ctr_priv {
 116        u8 iv[16];
 117};
 118
 119struct nx_crypto_ctx {
 120        spinlock_t lock;          /* synchronize access to the context */
 121        void *kmem;               /* unaligned, kmalloc'd buffer */
 122        size_t kmem_len;          /* length of kmem */
 123        struct nx_csbcpb *csbcpb; /* aligned page given to phyp @ hcall time */
 124        struct vio_pfo_op op;     /* operation struct with hcall parameters */
 125        struct nx_csbcpb *csbcpb_aead; /* secondary csbcpb used by AEAD algs */
 126        struct vio_pfo_op op_aead;/* operation struct for csbcpb_aead */
 127
 128        struct nx_sg *in_sg;      /* aligned pointer into kmem to an sg list */
 129        struct nx_sg *out_sg;     /* aligned pointer into kmem to an sg list */
 130
 131        struct alg_props *ap;     /* pointer into props based on our key size */
 132        struct alg_props props[3];/* openFirmware properties for requests */
 133        struct nx_stats *stats;   /* pointer into an nx_crypto_driver for stats
 134                                     reporting */
 135
 136        union {
 137                struct nx_gcm_priv gcm;
 138                struct nx_ccm_priv ccm;
 139                struct nx_xcbc_priv xcbc;
 140                struct nx_ctr_priv ctr;
 141        } priv;
 142};
 143
 144/* prototypes */
 145int nx_crypto_ctx_aes_ccm_init(struct crypto_tfm *tfm);
 146int nx_crypto_ctx_aes_gcm_init(struct crypto_tfm *tfm);
 147int nx_crypto_ctx_aes_xcbc_init(struct crypto_tfm *tfm);
 148int nx_crypto_ctx_aes_ctr_init(struct crypto_tfm *tfm);
 149int nx_crypto_ctx_aes_cbc_init(struct crypto_tfm *tfm);
 150int nx_crypto_ctx_aes_ecb_init(struct crypto_tfm *tfm);
 151int nx_crypto_ctx_sha_init(struct crypto_tfm *tfm);
 152void nx_crypto_ctx_exit(struct crypto_tfm *tfm);
 153void nx_ctx_init(struct nx_crypto_ctx *nx_ctx, unsigned int function);
 154int nx_hcall_sync(struct nx_crypto_ctx *ctx, struct vio_pfo_op *op,
 155                  u32 may_sleep);
 156struct nx_sg *nx_build_sg_list(struct nx_sg *, u8 *, unsigned int, u32);
 157int nx_build_sg_lists(struct nx_crypto_ctx *, struct blkcipher_desc *,
 158                      struct scatterlist *, struct scatterlist *, unsigned int,
 159                      unsigned int, u8 *);
 160struct nx_sg *nx_walk_and_build(struct nx_sg *, unsigned int,
 161                                struct scatterlist *, unsigned int,
 162                                unsigned int);
 163
 164#ifdef CONFIG_DEBUG_FS
 165#define NX_DEBUGFS_INIT(drv)    nx_debugfs_init(drv)
 166#define NX_DEBUGFS_FINI(drv)    nx_debugfs_fini(drv)
 167
 168int nx_debugfs_init(struct nx_crypto_driver *);
 169void nx_debugfs_fini(struct nx_crypto_driver *);
 170#else
 171#define NX_DEBUGFS_INIT(drv)    (0)
 172#define NX_DEBUGFS_FINI(drv)    (0)
 173#endif
 174
 175#define NX_PAGE_NUM(x)          ((u64)(x) & 0xfffffffffffff000ULL)
 176
 177extern struct crypto_alg nx_cbc_aes_alg;
 178extern struct crypto_alg nx_ecb_aes_alg;
 179extern struct crypto_alg nx_gcm_aes_alg;
 180extern struct crypto_alg nx_gcm4106_aes_alg;
 181extern struct crypto_alg nx_ctr_aes_alg;
 182extern struct crypto_alg nx_ctr3686_aes_alg;
 183extern struct crypto_alg nx_ccm_aes_alg;
 184extern struct crypto_alg nx_ccm4309_aes_alg;
 185extern struct shash_alg nx_shash_aes_xcbc_alg;
 186extern struct shash_alg nx_shash_sha512_alg;
 187extern struct shash_alg nx_shash_sha256_alg;
 188
 189extern struct nx_crypto_driver nx_driver;
 190
 191#define SCATTERWALK_TO_SG       1
 192#define SCATTERWALK_FROM_SG     0
 193
 194#endif
 195