]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/crypto/nx/nx-842.h
5 #include <linux/kernel.h>
6 #include <linux/module.h>
7 #include <linux/sw842.h>
9 #include <linux/slab.h>
12 #include <linux/ratelimit.h>
14 #define __NX842_PSERIES_MEM_COMPRESS (10240)
15 #define __NX842_POWERNV_MEM_COMPRESS (1024)
17 #define NX842_MEM_COMPRESS (max_t(unsigned int, \
18 __NX842_PSERIES_MEM_COMPRESS, __NX842_POWERNV_MEM_COMPRESS))
20 /* Restrictions on Data Descriptor List (DDL) and Entry (DDE) buffers
22 * From NX P8 workbook, sec 4.9.1 "842 details"
23 * Each DDE buffer is 128 byte aligned
24 * Each DDE buffer size is a multiple of 32 bytes (except the last)
25 * The last DDE buffer size is a multiple of 8 bytes
27 #define DDE_BUFFER_ALIGN (128)
28 #define DDE_BUFFER_SIZE_MULT (32)
29 #define DDE_BUFFER_LAST_MULT (8)
31 /* Arbitrary DDL length limit
32 * Allows max buffer size of MAX-1 to MAX pages
33 * (depending on alignment)
35 #define DDL_LEN_MAX (17)
37 /* CCW 842 CI/FC masks
38 * NX P8 workbook, section 4.3.1, figure 4-6
39 * "CI/FC Boundary by NX CT type"
41 #define CCW_CI_842 (0x00003ff8)
42 #define CCW_FC_842 (0x00000007)
44 /* CCW Function Codes (FC) for 842
45 * NX P8 workbook, section 4.9, table 4-28
46 * "Function Code Definitions for 842 Memory Compression"
48 #define CCW_FC_842_COMP_NOCRC (0)
49 #define CCW_FC_842_COMP_CRC (1)
50 #define CCW_FC_842_DECOMP_NOCRC (2)
51 #define CCW_FC_842_DECOMP_CRC (3)
52 #define CCW_FC_842_MOVE (4)
54 /* CSB CC Error Types for 842
55 * NX P8 workbook, section 4.10.3, table 4-30
56 * "Reported Error Types Summary Table"
58 /* These are all duplicates of existing codes defined in icswx.h. */
59 #define CSB_CC_TRANSLATION_DUP1 (80)
60 #define CSB_CC_TRANSLATION_DUP2 (82)
61 #define CSB_CC_TRANSLATION_DUP3 (84)
62 #define CSB_CC_TRANSLATION_DUP4 (86)
63 #define CSB_CC_TRANSLATION_DUP5 (92)
64 #define CSB_CC_TRANSLATION_DUP6 (94)
65 #define CSB_CC_PROTECTION_DUP1 (81)
66 #define CSB_CC_PROTECTION_DUP2 (83)
67 #define CSB_CC_PROTECTION_DUP3 (85)
68 #define CSB_CC_PROTECTION_DUP4 (87)
69 #define CSB_CC_PROTECTION_DUP5 (93)
70 #define CSB_CC_PROTECTION_DUP6 (95)
71 #define CSB_CC_RD_EXTERNAL_DUP1 (89)
72 #define CSB_CC_RD_EXTERNAL_DUP2 (90)
73 #define CSB_CC_RD_EXTERNAL_DUP3 (91)
74 /* These are specific to NX */
76 #define CSB_CC_TPBC_GT_SPBC (64) /* no error, but >1 comp ratio */
77 #define CSB_CC_CRC_MISMATCH (65) /* decomp crc mismatch */
78 #define CSB_CC_TEMPL_INVALID (66) /* decomp invalid template value */
79 #define CSB_CC_TEMPL_OVERFLOW (67) /* decomp template shows data after end */
81 #define CSB_CC_DECRYPT_OVERFLOW (64)
82 /* asym crypt codes */
83 #define CSB_CC_MINV_OVERFLOW (128)
84 /* These are reserved for hypervisor use */
85 #define CSB_CC_HYP_RESERVE_START (240)
86 #define CSB_CC_HYP_RESERVE_END (253)
87 #define CSB_CC_HYP_NO_HW (254)
88 #define CSB_CC_HYP_HANG_ABORTED (255)
90 /* CCB Completion Modes (CM) for 842
91 * NX P8 workbook, section 4.3, figure 4-5
92 * "CRB Details - Normal Cop_Req (CL=00, C=1)"
94 #define CCB_CM_EXTRA_WRITE (CCB_CM0_ALL_COMPLETIONS & CCB_CM12_STORE)
95 #define CCB_CM_INTERRUPT (CCB_CM0_ALL_COMPLETIONS & CCB_CM12_INTERRUPT)
97 #define LEN_ON_PAGE(pa) (PAGE_SIZE - ((pa) & ~PAGE_MASK))
99 static inline unsigned long nx842_get_pa(void *addr
)
101 if (!is_vmalloc_addr(addr
))
104 return page_to_phys(vmalloc_to_page(addr
)) + offset_in_page(addr
);
107 /* Get/Set bit fields */
108 #define MASK_LSH(m) (__builtin_ffsl(m) - 1)
109 #define GET_FIELD(v, m) (((v) & (m)) >> MASK_LSH(m))
110 #define SET_FIELD(v, m, val) (((v) & ~(m)) | (((val) << MASK_LSH(m)) & (m)))
112 struct nx842_constraints
{
119 struct nx842_driver
{
121 struct module
*owner
;
123 struct nx842_constraints
*constraints
;
125 int (*compress
)(const unsigned char *in
, unsigned int in_len
,
126 unsigned char *out
, unsigned int *out_len
,
128 int (*decompress
)(const unsigned char *in
, unsigned int in_len
,
129 unsigned char *out
, unsigned int *out_len
,
133 struct nx842_driver
*nx842_platform_driver(void);
134 bool nx842_platform_driver_set(struct nx842_driver
*driver
);
135 void nx842_platform_driver_unset(struct nx842_driver
*driver
);
136 bool nx842_platform_driver_get(void);
137 void nx842_platform_driver_put(void);
139 int nx842_constraints(struct nx842_constraints
*constraints
);
141 int nx842_compress(const unsigned char *in
, unsigned int in_len
,
142 unsigned char *out
, unsigned int *out_len
, void *wrkmem
);
143 int nx842_decompress(const unsigned char *in
, unsigned int in_len
,
144 unsigned char *out
, unsigned int *out_len
, void *wrkmem
);
146 #endif /* __NX_842_H__ */