]>
git.proxmox.com Git - ceph.git/blob - ceph/src/crypto/isa-l/isa-l_crypto/sm3_mb/aarch64/sm3_mb_mgr_asimd_aarch64.c
1 /**********************************************************************
2 Copyright(c) 2020 Arm Corporation All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in
11 the documentation and/or other materials provided with the
13 * Neither the name of Arm Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 **********************************************************************/
34 #define max(a,b) (((a) > (b)) ? (a) : (b))
38 #define min(a,b) (((a) < (b)) ? (a) : (b))
41 #define SM3_MB_CE_MAX_LANES 4
42 void sm3_mb_asimd_x4(SM3_JOB
*, SM3_JOB
*, SM3_JOB
*, SM3_JOB
*, int);
43 void sm3_mb_asimd_x1(SM3_JOB
*, int);
45 #define LANE_IS_NOT_FINISHED(state,i) \
46 (((state->lens[i]&(~0xf))!=0) && state->ldata[i].job_in_lane!=NULL)
47 #define LANE_IS_FINISHED(state,i) \
48 (((state->lens[i]&(~0xf))==0) && state->ldata[i].job_in_lane!=NULL)
49 #define LANE_IS_FREE(state,i) \
50 (((state->lens[i]&(~0xf))==0) && state->ldata[i].job_in_lane==NULL)
51 #define LANE_IS_INVALID(state,i) \
52 (((state->lens[i]&(~0xf))!=0) && state->ldata[i].job_in_lane==NULL)
53 void sm3_mb_mgr_init_asimd(SM3_MB_JOB_MGR
* state
)
57 state
->unused_lanes
= 0xf;
58 state
->num_lanes_inuse
= 0;
59 for (i
= 0; i
< SM3_MB_CE_MAX_LANES
; i
++) {
60 state
->unused_lanes
<<= 4;
61 state
->unused_lanes
|= SM3_MB_CE_MAX_LANES
- 1 - i
;
63 state
->ldata
[i
].job_in_lane
= 0;
66 //lanes > SM3_MB_CE_MAX_LANES is invalid lane
67 for (; i
< SM3_MAX_LANES
; i
++) {
69 state
->ldata
[i
].job_in_lane
= 0;
73 static int sm3_mb_mgr_do_jobs(SM3_MB_JOB_MGR
* state
)
77 if (state
->num_lanes_inuse
== 0) {
80 if (state
->num_lanes_inuse
== 4) {
81 len
= min(min(state
->lens
[0], state
->lens
[1]),
82 min(state
->lens
[2], state
->lens
[3]));
85 sm3_mb_asimd_x4(state
->ldata
[0].job_in_lane
,
86 state
->ldata
[1].job_in_lane
,
87 state
->ldata
[2].job_in_lane
,
88 state
->ldata
[3].job_in_lane
, len
>> 4);
89 //only return the min length job
90 for (i
= 0; i
< SM3_MAX_LANES
; i
++) {
91 if (LANE_IS_NOT_FINISHED(state
, i
)) {
92 state
->lens
[i
] -= len
;
93 state
->ldata
[i
].job_in_lane
->len
-= len
;
94 state
->ldata
[i
].job_in_lane
->buffer
+= len
<< 2;
100 for (i
= 0; i
< SM3_MAX_LANES
; i
++) {
101 if (LANE_IS_NOT_FINISHED(state
, i
)) {
102 len
= state
->lens
[i
] & (~0xf);
103 sm3_mb_asimd_x1(state
->ldata
[i
].job_in_lane
, len
>> 4);
104 state
->lens
[i
] -= len
;
105 state
->ldata
[i
].job_in_lane
->len
-= len
;
106 state
->ldata
[i
].job_in_lane
->buffer
+= len
<< 2;
115 static SM3_JOB
*sm3_mb_mgr_free_lane(SM3_MB_JOB_MGR
* state
)
120 for (i
= 0; i
< SM3_MB_CE_MAX_LANES
; i
++) {
121 if (LANE_IS_FINISHED(state
, i
)) {
123 state
->unused_lanes
<<= 4;
124 state
->unused_lanes
|= i
;
125 state
->num_lanes_inuse
--;
126 ret
= state
->ldata
[i
].job_in_lane
;
127 ret
->status
= STS_COMPLETED
;
128 state
->ldata
[i
].job_in_lane
= NULL
;
135 static void sm3_mb_mgr_insert_job(SM3_MB_JOB_MGR
* state
, SM3_JOB
* job
)
139 lane_idx
= state
->unused_lanes
& 0xf;
141 assert(lane_idx
< SM3_MB_CE_MAX_LANES
);
142 state
->lens
[lane_idx
] = (job
->len
<< 4) | lane_idx
;
143 state
->ldata
[lane_idx
].job_in_lane
= job
;
144 state
->unused_lanes
>>= 4;
145 state
->num_lanes_inuse
++;
148 SM3_JOB
*sm3_mb_mgr_submit_asimd(SM3_MB_JOB_MGR
* state
, SM3_JOB
* job
)
156 sm3_mb_mgr_insert_job(state
, job
);
158 ret
= sm3_mb_mgr_free_lane(state
);
162 //submit will wait all lane has data
163 if (state
->num_lanes_inuse
< SM3_MB_CE_MAX_LANES
)
166 lane_idx
= sm3_mb_mgr_do_jobs(state
);
167 assert(lane_idx
!= -1);
169 sm3_mb_mgr_do_jobs(state
);
173 ret
= sm3_mb_mgr_free_lane(state
);
177 SM3_JOB
*sm3_mb_mgr_flush_asimd(SM3_MB_JOB_MGR
* state
)
180 ret
= sm3_mb_mgr_free_lane(state
);
185 sm3_mb_mgr_do_jobs(state
);
186 return sm3_mb_mgr_free_lane(state
);