GNU Linux-libre 4.14.262-gnu1
[releases.git] / drivers / crypto / cavium / cpt / request_manager.h
1 /*
2  * Copyright (C) 2016 Cavium, Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License
6  * as published by the Free Software Foundation.
7  */
8
9 #ifndef __REQUEST_MANAGER_H
10 #define __REQUEST_MANAGER_H
11
12 #include "cpt_common.h"
13
14 #define TIME_IN_RESET_COUNT  5
15 #define COMPLETION_CODE_SIZE 8
16 #define COMPLETION_CODE_INIT 0
17 #define PENDING_THOLD  100
18 #define MAX_SG_IN_CNT 12
19 #define MAX_SG_OUT_CNT 13
20 #define SG_LIST_HDR_SIZE  8
21 #define MAX_BUF_CNT     16
22
23 union ctrl_info {
24         u32 flags;
25         struct {
26 #if defined(__BIG_ENDIAN_BITFIELD)
27                 u32 reserved0:26;
28                 u32 grp:3; /* Group bits */
29                 u32 dma_mode:2; /* DMA mode */
30                 u32 se_req:1;/* To SE core */
31 #else
32                 u32 se_req:1; /* To SE core */
33                 u32 dma_mode:2; /* DMA mode */
34                 u32 grp:3; /* Group bits */
35                 u32 reserved0:26;
36 #endif
37         } s;
38 };
39
40 union opcode_info {
41         u16 flags;
42         struct {
43                 u8 major;
44                 u8 minor;
45         } s;
46 };
47
48 struct cptvf_request {
49         union opcode_info opcode;
50         u16 param1;
51         u16 param2;
52         u16 dlen;
53 };
54
55 struct buf_ptr {
56         u8 *vptr;
57         dma_addr_t dma_addr;
58         u16 size;
59 };
60
61 struct cpt_request_info {
62         u8 incnt; /* Number of input buffers */
63         u8 outcnt; /* Number of output buffers */
64         u16 rlen; /* Output length */
65         union ctrl_info ctrl; /* User control information */
66         struct cptvf_request req; /* Request Information (Core specific) */
67
68         bool may_sleep;
69
70         struct buf_ptr in[MAX_BUF_CNT];
71         struct buf_ptr out[MAX_BUF_CNT];
72
73         void (*callback)(int, void *); /* Kernel ASYNC request callabck */
74         void *callback_arg; /* Kernel ASYNC request callabck arg */
75 };
76
77 struct sglist_component {
78         union {
79                 u64 len;
80                 struct {
81                         u16 len0;
82                         u16 len1;
83                         u16 len2;
84                         u16 len3;
85                 } s;
86         } u;
87         u64 ptr0;
88         u64 ptr1;
89         u64 ptr2;
90         u64 ptr3;
91 };
92
93 struct cpt_info_buffer {
94         struct cpt_vf *cptvf;
95         unsigned long time_in;
96         u8 extra_time;
97
98         struct cpt_request_info *req;
99         dma_addr_t dptr_baddr;
100         u32 dlen;
101         dma_addr_t rptr_baddr;
102         dma_addr_t comp_baddr;
103         u8 *in_buffer;
104         u8 *out_buffer;
105         u8 *gather_components;
106         u8 *scatter_components;
107
108         struct pending_entry *pentry;
109         volatile u64 *completion_addr;
110         volatile u64 *alternate_caddr;
111 };
112
113 /*
114  * CPT_INST_S software command definitions
115  * Words EI (0-3)
116  */
117 union vq_cmd_word0 {
118         u64 u64;
119         struct {
120                 u16 opcode;
121                 u16 param1;
122                 u16 param2;
123                 u16 dlen;
124         } s;
125 };
126
127 union vq_cmd_word3 {
128         u64 u64;
129         struct {
130 #if defined(__BIG_ENDIAN_BITFIELD)
131                 u64 grp:3;
132                 u64 cptr:61;
133 #else
134                 u64 cptr:61;
135                 u64 grp:3;
136 #endif
137         } s;
138 };
139
140 struct cpt_vq_command {
141         union vq_cmd_word0 cmd;
142         u64 dptr;
143         u64 rptr;
144         union vq_cmd_word3 cptr;
145 };
146
147 void vq_post_process(struct cpt_vf *cptvf, u32 qno);
148 int process_request(struct cpt_vf *cptvf, struct cpt_request_info *req);
149 #endif /* __REQUEST_MANAGER_H */