1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 #include "adf_cfg_instance.h"
4 
5 void
6 crypto_instance_init(struct adf_cfg_instance *instance,
7 		     struct adf_cfg_bundle *bundle)
8 {
9 	int i = 0;
10 
11 	instance->stype = CRYPTO;
12 	for (i = 0; i < bundle->num_of_rings / 2; i++) {
13 		if ((bundle->in_use >> bundle->rings[i]->number) & 0x1)
14 			continue;
15 
16 		if (bundle->rings[i]->serv_type == ADF_ACCEL_SERV_ASYM &&
17 		    bundle->rings[i]->mode == TX) {
18 			instance->asym_tx = bundle->rings[i]->number;
19 			bundle->in_use |= 1 << bundle->rings[i]->number;
20 			break;
21 		}
22 	}
23 
24 	for (i = 0; i < bundle->num_of_rings / 2; i++) {
25 		if ((bundle->in_use >> bundle->rings[i]->number) & 0x1)
26 			continue;
27 
28 		if (bundle->rings[i]->serv_type == ADF_ACCEL_SERV_SYM &&
29 		    bundle->rings[i]->mode == TX) {
30 			instance->sym_tx = bundle->rings[i]->number;
31 			bundle->in_use |= 1 << bundle->rings[i]->number;
32 			break;
33 		}
34 	}
35 
36 	for (i = bundle->num_of_rings / 2; i < bundle->num_of_rings; i++) {
37 		if ((bundle->in_use >> bundle->rings[i]->number) & 0x1)
38 			continue;
39 
40 		if (bundle->rings[i]->serv_type == ADF_ACCEL_SERV_ASYM &&
41 		    bundle->rings[i]->mode == RX) {
42 			instance->asym_rx = bundle->rings[i]->number;
43 			bundle->in_use |= 1 << bundle->rings[i]->number;
44 			break;
45 		}
46 	}
47 
48 	for (i = bundle->num_of_rings / 2; i < bundle->num_of_rings; i++) {
49 		if ((bundle->in_use >> bundle->rings[i]->number) & 0x1)
50 			continue;
51 
52 		if (bundle->rings[i]->serv_type == ADF_ACCEL_SERV_SYM &&
53 		    bundle->rings[i]->mode == RX) {
54 			instance->sym_rx = bundle->rings[i]->number;
55 			bundle->in_use |= 1 << bundle->rings[i]->number;
56 			break;
57 		}
58 	}
59 }
60 
61 void
62 dc_instance_init(struct adf_cfg_instance *instance,
63 		 struct adf_cfg_bundle *bundle)
64 {
65 	int i = 0;
66 
67 	instance->stype = COMP;
68 	for (i = 0; i < bundle->num_of_rings / 2; i++) {
69 		if ((bundle->in_use >> bundle->rings[i]->number) & 0x1)
70 			continue;
71 
72 		if (bundle->rings[i]->serv_type == ADF_ACCEL_SERV_DC &&
73 		    bundle->rings[i]->mode == TX) {
74 			instance->dc_tx = bundle->rings[i]->number;
75 			bundle->in_use |= 1 << bundle->rings[i]->number;
76 			break;
77 		}
78 	}
79 
80 	for (i = bundle->num_of_rings / 2; i < bundle->num_of_rings; i++) {
81 		if ((bundle->in_use >> bundle->rings[i]->number) & 0x1)
82 			continue;
83 
84 		if (bundle->rings[i]->serv_type == ADF_ACCEL_SERV_DC &&
85 		    bundle->rings[i]->mode == RX) {
86 			instance->dc_rx = bundle->rings[i]->number;
87 			bundle->in_use |= 1 << bundle->rings[i]->number;
88 			break;
89 		}
90 	}
91 }
92 
93 void
94 asym_instance_init(struct adf_cfg_instance *instance,
95 		   struct adf_cfg_bundle *bundle)
96 {
97 	int i = 0;
98 
99 	instance->stype = ASYM;
100 	for (i = 0; i < bundle->num_of_rings / 2; i++) {
101 		if ((bundle->in_use >> bundle->rings[i]->number) & 0x1)
102 			continue;
103 
104 		if (bundle->rings[i]->serv_type == ADF_ACCEL_SERV_ASYM &&
105 		    bundle->rings[i]->mode == TX) {
106 			instance->asym_tx = bundle->rings[i]->number;
107 			bundle->in_use |= 1 << bundle->rings[i]->number;
108 			break;
109 		}
110 	}
111 
112 	for (i = bundle->num_of_rings / 2; i < bundle->num_of_rings; i++) {
113 		if ((bundle->in_use >> bundle->rings[i]->number) & 0x1)
114 			continue;
115 
116 		if (bundle->rings[i]->serv_type == ADF_ACCEL_SERV_ASYM &&
117 		    bundle->rings[i]->mode == RX) {
118 			instance->asym_rx = bundle->rings[i]->number;
119 			bundle->in_use |= 1 << bundle->rings[i]->number;
120 			break;
121 		}
122 	}
123 }
124 
125 void
126 sym_instance_init(struct adf_cfg_instance *instance,
127 		  struct adf_cfg_bundle *bundle)
128 {
129 	int i = 0;
130 
131 	instance->stype = SYM;
132 	for (i = 0; i < bundle->num_of_rings / 2; i++) {
133 		if ((bundle->in_use >> bundle->rings[i]->number) & 0x1)
134 			continue;
135 
136 		if (bundle->rings[i]->serv_type == ADF_ACCEL_SERV_SYM &&
137 		    bundle->rings[i]->mode == TX) {
138 			instance->sym_tx = bundle->rings[i]->number;
139 			bundle->in_use |= 1 << bundle->rings[i]->number;
140 			break;
141 		}
142 	}
143 
144 	for (i = 0 + bundle->num_of_rings / 2; i < bundle->num_of_rings; i++) {
145 		if ((bundle->in_use >> bundle->rings[i]->number) & 0x1)
146 			continue;
147 
148 		if (bundle->rings[i]->serv_type == ADF_ACCEL_SERV_SYM &&
149 		    bundle->rings[i]->mode == RX) {
150 			instance->sym_rx = bundle->rings[i]->number;
151 			bundle->in_use |= 1 << bundle->rings[i]->number;
152 			break;
153 		}
154 	}
155 }
156