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