]> CyberLeo.Net >> Repos - FreeBSD/releng/8.2.git/blob - sys/mips/rmi/dev/sec/stats.h
Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.
[FreeBSD/releng/8.2.git] / sys / mips / rmi / dev / sec / stats.h
1 /*-
2  * Copyright (c) 2003-2009 RMI Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of RMI Corporation, nor the names of its contributors,
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * RMI_BSD */
30
31 #ifndef _STATS_H_
32 #define _STATS_H_
33
34 typedef struct hmac_stats
35 {
36   unsigned long md5_count;
37   unsigned long long md5_bytes;
38   unsigned long sha1_count;
39   unsigned long long sha1_bytes;
40   unsigned long sha256_count;
41   unsigned long long sha256_bytes;
42   unsigned long sha384_count;
43   unsigned long long sha384_bytes;
44   unsigned long sha512_count;
45   unsigned long long sha512_bytes;
46   unsigned long gcm_count;
47   unsigned long long gcm_bytes;
48   unsigned long kasumi_f9_count;
49   unsigned long long kasumi_f9_bytes;
50   unsigned long reverts;
51   unsigned long long reverts_bytes;
52 } hmac_stats_t, *hmac_stats_pt;
53
54 typedef struct cipher_stats
55 {
56   unsigned long des_encrypts;
57   unsigned long long des_encrypt_bytes;
58   unsigned long des_decrypts;
59   unsigned long long des_decrypt_bytes;
60   unsigned long des3_encrypts;
61   unsigned long long des3_encrypt_bytes;
62   unsigned long des3_decrypts;
63   unsigned long long des3_decrypt_bytes;
64   unsigned long aes_encrypts;
65   unsigned long long aes_encrypt_bytes;
66   unsigned long aes_decrypts;
67   unsigned long long aes_decrypt_bytes;
68   unsigned long arc4_encrypts;
69   unsigned long long arc4_encrypt_bytes;
70   unsigned long arc4_decrypts;
71   unsigned long long arc4_decrypt_bytes;
72   unsigned long kasumi_f8_encrypts;
73   unsigned long long kasumi_f8_encrypt_bytes;
74   unsigned long kasumi_f8_decrypts;
75   unsigned long long kasumi_f8_decrypt_bytes;
76   unsigned long reverts;
77   unsigned long long reverts_bytes;
78 } cipher_stats_t, *cipher_stats_pt;
79
80
81 typedef struct modexp_stats
82 {
83   unsigned long modexp_512s;
84   unsigned long modexp_1024s;
85 } modexp_stats_t, *modexp_stats_pt;
86
87 typedef struct ecc_stats
88 {
89   unsigned long ecc_mul;
90   unsigned long ecc_add;
91   unsigned long ecc_dbl;
92   unsigned long ecc_vfy;
93   unsigned long ecc_bin_mul;
94   unsigned long ecc_field_bin_inv;
95   unsigned long ecc_field_bin_mul;
96   unsigned long ecc_field_bin_add;
97   unsigned long ecc_field_add;
98   unsigned long ecc_field_sub;
99   unsigned long ecc_field_mul;
100   unsigned long ecc_field_inv;
101   unsigned long ecc_field_div;
102   unsigned long ecc_field_red;
103 } ecc_stats_t, *ecc_stats_pt;
104
105
106 typedef struct opt_stats
107 {
108   unsigned long combined;
109   unsigned long unaligned_auth_dest;
110   unsigned long sym_failed;
111   unsigned long modexp_failed;
112   unsigned long ecc_failed;
113 } opt_stats_t, *opt_stats_pt;
114
115 typedef struct rmisec_stats
116 {
117   uint32_t sent;
118   uint32_t received;
119   uint32_t stats_mask;
120   uint32_t control_mask;
121   rwlock_t rmisec_control_lock;
122   rwlock_t rmisec_stats_lock;
123   char clear_start[0];
124   uint64_t wait_time;
125   uint32_t max_wait_time;
126   uint32_t maxsnd_wait_time;
127   uint32_t wait_count;
128   hmac_stats_t hmac;
129   cipher_stats_t cipher;
130   modexp_stats_t modexp;
131   ecc_stats_t ecc;
132   opt_stats_t opt;
133 } rmisec_stats_t, *rmisec_stats_pt;
134
135
136 /* stats routines */
137
138 static void inline phxdrv_record_sent(rmisec_stats_pt stats)
139 {
140   write_lock(&stats->rmisec_stats_lock);
141   stats->sent++;
142   write_unlock(&stats->rmisec_stats_lock);
143 }
144
145 static void inline phxdrv_record_received(rmisec_stats_pt stats)
146 {
147   write_lock(&stats->rmisec_stats_lock);
148   stats->received++;
149   write_unlock(&stats->rmisec_stats_lock);
150 }
151
152
153 static void inline phxdrv_record_des(rmisec_stats_pt stats, int enc,
154                      int nbytes)
155 {
156   if (stats->stats_mask & PHXDRV_PROFILE_DES) {
157     write_lock(&stats->rmisec_stats_lock);
158     if (enc) {
159       stats->cipher.des_encrypts++;
160       stats->cipher.des_encrypt_bytes += nbytes;
161     }
162     else {
163       stats->cipher.des_decrypts++;
164       stats->cipher.des_decrypt_bytes += nbytes;
165     }
166     write_unlock(&stats->rmisec_stats_lock);
167   }
168 }
169
170
171 static void inline phxdrv_record_3des(rmisec_stats_pt stats, int enc,
172                       int nbytes)
173 {
174   if (stats->stats_mask & PHXDRV_PROFILE_3DES) {
175     write_lock(&stats->rmisec_stats_lock);
176     if (enc) {
177       stats->cipher.des3_encrypts++;
178       stats->cipher.des3_encrypt_bytes += nbytes;
179     }
180     else {
181       stats->cipher.des3_decrypts++;
182       stats->cipher.des3_decrypt_bytes += nbytes;
183     }
184     write_unlock(&stats->rmisec_stats_lock);
185   }
186 }
187
188
189 static void inline phxdrv_record_aes(rmisec_stats_pt stats, int enc,
190                      int nbytes)
191 {
192   if (stats->stats_mask & PHXDRV_PROFILE_AES) {
193     write_lock(&stats->rmisec_stats_lock);
194     if (enc) {
195       stats->cipher.aes_encrypts++;
196       stats->cipher.aes_encrypt_bytes += nbytes;
197     }
198     else {
199       stats->cipher.aes_decrypts++;
200       stats->cipher.aes_decrypt_bytes += nbytes;
201     }
202     write_unlock(&stats->rmisec_stats_lock);
203   }
204 }
205
206
207 static void inline phxdrv_record_arc4(rmisec_stats_pt stats, int enc,
208                      int nbytes)
209 {
210   if (stats->stats_mask & PHXDRV_PROFILE_ARC4) {
211     write_lock(&stats->rmisec_stats_lock);
212     if (enc) {
213       stats->cipher.arc4_encrypts++;
214       stats->cipher.arc4_encrypt_bytes += nbytes;
215     }
216     else {
217       stats->cipher.arc4_decrypts++;
218       stats->cipher.arc4_decrypt_bytes += nbytes;
219     }
220     write_unlock(&stats->rmisec_stats_lock);
221   }
222 }
223
224 static void inline phxdrv_record_kasumi_f8(rmisec_stats_pt stats, int enc,
225                                      int nbytes)
226 {
227   if (stats->stats_mask & PHXDRV_PROFILE_KASUMI_F8) {
228     write_lock(&stats->rmisec_stats_lock);
229     if (enc) {
230       stats->cipher.kasumi_f8_encrypts++;
231       stats->cipher.kasumi_f8_encrypt_bytes += nbytes;
232     }
233     else {
234       stats->cipher.kasumi_f8_decrypts++;
235       stats->cipher.kasumi_f8_decrypt_bytes += nbytes;
236     }
237     write_unlock(&stats->rmisec_stats_lock);
238   }
239 }
240
241
242 static void inline phxdrv_record_modexp(rmisec_stats_pt stats,
243                         int blksize)
244 {
245   if (stats->stats_mask & PHXDRV_PROFILE_MODEXP) {
246     write_lock(&stats->rmisec_stats_lock);
247     if (blksize == 512) {
248       stats->modexp.modexp_512s++;
249     }
250     if (blksize == 1024) {
251       stats->modexp.modexp_1024s++;
252     }
253     write_unlock(&stats->rmisec_stats_lock);
254   }
255 }
256
257
258 static void inline phxdrv_record_ecc(rmisec_stats_pt stats, PHX_ECC_OP op)
259 {
260   if (stats->stats_mask & PHXDRV_PROFILE_ECC) {
261     write_lock(&stats->rmisec_stats_lock);
262     switch (op) {
263     case PHX_ECC_NOP:
264         break;
265     case PHX_ECC_MUL:
266         stats->ecc.ecc_mul++;
267         break;
268     case PHX_ECC_BIN_MUL:
269         stats->ecc.ecc_bin_mul++;
270         break;
271     case PHX_ECC_ADD:
272         stats->ecc.ecc_add++;
273         break;
274     case PHX_ECC_DBL:
275         stats->ecc.ecc_dbl++;
276         break;
277     case PHX_ECC_VFY:
278         stats->ecc.ecc_vfy++;
279         break;
280     case PHX_ECC_FIELD_BIN_INV:
281         stats->ecc.ecc_field_bin_inv++;
282         break;
283     case PHX_ECC_FIELD_BIN_MUL:
284         stats->ecc.ecc_field_bin_mul++;
285         break;
286     case PHX_ECC_FIELD_BIN_ADD:
287         stats->ecc.ecc_field_bin_add++;
288         break;
289     case PHX_ECC_FIELD_ADD:
290         stats->ecc.ecc_field_add++;
291         break;
292     case PHX_ECC_FIELD_SUB:
293         stats->ecc.ecc_field_sub++;
294         break;
295     case PHX_ECC_FIELD_MUL:
296         stats->ecc.ecc_field_mul++;
297         break;
298     case PHX_ECC_FIELD_INV:
299         stats->ecc.ecc_field_inv++;
300         break;
301     case PHX_ECC_FIELD_DIV:
302         stats->ecc.ecc_field_div++;
303         break;
304     case PHX_ECC_FIELD_RED:
305         stats->ecc.ecc_field_red++;
306         break;
307     case PHX_ECC_FIELD:
308     case PHX_ECC_BIN:
309         break;
310     }
311     write_unlock(&stats->rmisec_stats_lock);
312   }
313 }
314
315 static void inline phxdrv_record_cipher_revert(rmisec_stats_pt stats,
316                            int nbytes)
317 {
318   if (stats->stats_mask & PHXDRV_PROFILE_CPHR_REVERTS) {
319     write_lock(&stats->rmisec_stats_lock);
320     stats->cipher.reverts++;
321     stats->cipher.reverts_bytes += nbytes;
322     write_unlock(&stats->rmisec_stats_lock);
323   }
324 }
325
326 static void inline phxdrv_record_hmac_revert(rmisec_stats_pt stats,
327                          int nbytes)
328 {
329   if (stats->stats_mask & PHXDRV_PROFILE_HMAC_REVERTS) {
330     write_lock(&stats->rmisec_stats_lock);
331     stats->hmac.reverts++;
332     stats->hmac.reverts_bytes += nbytes;
333     write_unlock(&stats->rmisec_stats_lock);
334   }
335 }
336
337
338 static void inline phxdrv_record_md5(rmisec_stats_pt stats,
339                      int nbytes)
340 {
341   if (stats->stats_mask & PHXDRV_PROFILE_MD5) {
342     write_lock(&stats->rmisec_stats_lock);
343     stats->hmac.md5_count++;
344     stats->hmac.md5_bytes += nbytes;
345     write_unlock(&stats->rmisec_stats_lock);
346   }
347 }
348
349 static void inline phxdrv_record_sha1(rmisec_stats_pt stats,
350                       int nbytes)
351 {
352   if (stats->stats_mask & PHXDRV_PROFILE_SHA1) {
353     write_lock(&stats->rmisec_stats_lock);
354     stats->hmac.sha1_count++;
355     stats->hmac.sha1_bytes += nbytes;
356     write_unlock(&stats->rmisec_stats_lock);
357   }
358 }
359
360
361 static void inline phxdrv_record_sha256(rmisec_stats_pt stats,
362                     int nbytes)
363 {
364   if (stats->stats_mask & PHXDRV_PROFILE_SHA256) {
365     write_lock(&stats->rmisec_stats_lock);
366     stats->hmac.sha256_count++;
367     stats->hmac.sha256_bytes += nbytes;
368     write_unlock(&stats->rmisec_stats_lock);
369   }
370 }
371
372 static void inline phxdrv_record_sha384(rmisec_stats_pt stats,
373                                       int nbytes)
374 {
375   if (stats->stats_mask & PHXDRV_PROFILE_SHA384) {
376     write_lock(&stats->rmisec_stats_lock);
377     stats->hmac.sha384_count++;
378     stats->hmac.sha384_bytes += nbytes;
379     write_unlock(&stats->rmisec_stats_lock);
380   }
381 }
382
383
384 static void inline phxdrv_record_sha512(rmisec_stats_pt stats,
385                                       int nbytes)
386 {
387   if (stats->stats_mask & PHXDRV_PROFILE_SHA512) {
388     write_lock(&stats->rmisec_stats_lock);
389     stats->hmac.sha512_count++;
390     stats->hmac.sha512_bytes += nbytes;
391     write_unlock(&stats->rmisec_stats_lock);
392   }
393 }
394
395 static void inline phxdrv_record_gcm(rmisec_stats_pt stats,
396                                       int nbytes)
397 {
398   if (stats->stats_mask & PHXDRV_PROFILE_GCM) {
399     write_lock(&stats->rmisec_stats_lock);
400     stats->hmac.gcm_count++;
401     stats->hmac.gcm_bytes += nbytes;
402     write_unlock(&stats->rmisec_stats_lock);
403   }
404 }
405
406
407 static void inline phxdrv_record_kasumi_f9(rmisec_stats_pt stats,
408                                       int nbytes)
409 {
410   if (stats->stats_mask & PHXDRV_PROFILE_KASUMI_F9) {
411     write_lock(&stats->rmisec_stats_lock);
412     stats->hmac.kasumi_f9_count++;
413     stats->hmac.kasumi_f9_bytes += nbytes;
414     write_unlock(&stats->rmisec_stats_lock);
415   }
416 }
417
418 static void inline phxdrv_record_unaligned_auth_dest(rmisec_stats_pt stats,
419                              int nbytes)
420 {
421   if (stats->stats_mask & PHXDRV_PROFILE_UNALIGNED_AUTH_DEST) {
422     write_lock(&stats->rmisec_stats_lock);
423     stats->opt.unaligned_auth_dest++;
424     write_unlock(&stats->rmisec_stats_lock);
425   }
426 }
427
428
429 static void inline phxdrv_record_combined(rmisec_stats_pt stats,
430                       int nbytes)
431 {
432   if (stats->stats_mask & PHXDRV_PROFILE_COMBINED) {
433     write_lock(&stats->rmisec_stats_lock);
434     stats->opt.combined++;
435     write_unlock(&stats->rmisec_stats_lock);
436   }
437 }
438
439 static void inline phxdrv_record_sym_failed(rmisec_stats_pt stats,
440                       int nbytes)
441 {
442   if (stats->stats_mask & PHXDRV_PROFILE_COMBINED) {
443     write_lock(&stats->rmisec_stats_lock);
444     stats->opt.sym_failed++;
445     write_unlock(&stats->rmisec_stats_lock);
446   }
447 }
448
449 static void inline phxdrv_record_modexp_failed(rmisec_stats_pt stats,
450                       int nbytes)
451 {
452   if (stats->stats_mask & PHXDRV_PROFILE_COMBINED) {
453     write_lock(&stats->rmisec_stats_lock);
454     stats->opt.modexp_failed++;
455     write_unlock(&stats->rmisec_stats_lock);
456   }
457 }
458
459 static void inline phxdrv_record_ecc_failed(rmisec_stats_pt stats,
460                                           int nbytes)
461 {
462   if (stats->stats_mask & PHXDRV_PROFILE_COMBINED) {
463     write_lock(&stats->rmisec_stats_lock);
464     stats->opt.ecc_failed++;
465     write_unlock(&stats->rmisec_stats_lock);
466   }
467 }
468
469 #endif