4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Deimos - cryptographic acceleration based upon Broadcom 582x.
33 #include <sys/types.h>
35 #include <sys/sunddi.h>
36 #include <sys/kstat.h>
37 #include <sys/crypto/dca.h>
42 static int dca_ksupdate(kstat_t
*, int);
48 dca_ksinit(dca_t
*dca
)
53 if (ddi_getprop(DDI_DEV_T_ANY
, dca
->dca_dip
,
54 DDI_PROP_CANSLEEP
| DDI_PROP_DONTPASS
, "nostats", 0) != 0) {
56 * sysadmin has explicity disabled stats to prevent
62 instance
= ddi_get_instance(dca
->dca_dip
);
67 (void) sprintf(buf
, "%sc%d", DRIVER
, instance
);
68 if ((dca
->dca_intrstats
= kstat_create(DRIVER
, instance
, buf
,
69 "controller", KSTAT_TYPE_INTR
, 1, 0)) == NULL
) {
70 dca_error(dca
, "unable to create interrupt kstat");
72 kstat_install(dca
->dca_intrstats
);
78 if ((dca
->dca_ksp
= kstat_create(DRIVER
, instance
, NULL
, "misc",
79 KSTAT_TYPE_NAMED
, sizeof (dca_stat_t
) / sizeof (kstat_named_t
),
80 KSTAT_FLAG_WRITABLE
)) == NULL
) {
81 dca_error(dca
, "unable to create kstats");
83 dca_stat_t
*dkp
= (dca_stat_t
*)dca
->dca_ksp
->ks_data
;
84 kstat_named_init(&dkp
->ds_status
, "status", KSTAT_DATA_CHAR
);
85 kstat_named_init(&dkp
->ds_mcr
[0].ds_submit
, "mcr1submit",
86 KSTAT_DATA_ULONGLONG
);
87 kstat_named_init(&dkp
->ds_mcr
[0].ds_flowctl
, "mcr1flowctl",
88 KSTAT_DATA_ULONGLONG
);
89 kstat_named_init(&dkp
->ds_mcr
[0].ds_lowater
, "mcr1lowater",
90 KSTAT_DATA_ULONGLONG
);
91 kstat_named_init(&dkp
->ds_mcr
[0].ds_hiwater
, "mcr1hiwater",
92 KSTAT_DATA_ULONGLONG
);
93 kstat_named_init(&dkp
->ds_mcr
[0].ds_maxreqs
, "mcr1maxreqs",
94 KSTAT_DATA_ULONGLONG
);
95 kstat_named_init(&dkp
->ds_mcr
[1].ds_submit
, "mcr2submit",
96 KSTAT_DATA_ULONGLONG
);
97 kstat_named_init(&dkp
->ds_mcr
[1].ds_flowctl
, "mcr2flowctl",
98 KSTAT_DATA_ULONGLONG
);
99 kstat_named_init(&dkp
->ds_mcr
[1].ds_lowater
, "mcr2lowater",
100 KSTAT_DATA_ULONGLONG
);
101 kstat_named_init(&dkp
->ds_mcr
[1].ds_hiwater
, "mcr2hiwater",
102 KSTAT_DATA_ULONGLONG
);
103 kstat_named_init(&dkp
->ds_mcr
[1].ds_maxreqs
, "mcr2maxreqs",
104 KSTAT_DATA_ULONGLONG
);
107 kstat_named_init(&dkp
->ds_algs
[DS_RC4JOBS
], "rc4jobs",
108 KSTAT_DATA_ULONGLONG
);
111 kstat_named_init(&dkp
->ds_algs
[DS_RC4BYTES
], "rc4bytes",
112 KSTAT_DATA_ULONGLONG
);
115 kstat_named_init(&dkp
->ds_algs
[DS_3DESJOBS
], "3desjobs",
116 KSTAT_DATA_ULONGLONG
);
117 kstat_named_init(&dkp
->ds_algs
[DS_3DESBYTES
], "3desbytes",
118 KSTAT_DATA_ULONGLONG
);
120 kstat_named_init(&dkp
->ds_algs
[DS_RSAPUBLIC
], "rsapublic",
121 KSTAT_DATA_ULONGLONG
);
122 kstat_named_init(&dkp
->ds_algs
[DS_RSAPRIVATE
], "rsaprivate",
123 KSTAT_DATA_ULONGLONG
);
125 kstat_named_init(&dkp
->ds_algs
[DS_DSASIGN
], "dsasign",
126 KSTAT_DATA_ULONGLONG
);
127 kstat_named_init(&dkp
->ds_algs
[DS_DSAVERIFY
], "dsaverify",
128 KSTAT_DATA_ULONGLONG
);
131 kstat_named_init(&dkp
->ds_algs
[DS_DHPUBLIC
], "dhpublic",
132 KSTAT_DATA_ULONGLONG
);
135 kstat_named_init(&dkp
->ds_algs
[DS_DHSECRET
], "dhsecret",
136 KSTAT_DATA_ULONGLONG
);
138 /* random number jobs */
139 kstat_named_init(&dkp
->ds_algs
[DS_RNGJOBS
], "rngjobs",
140 KSTAT_DATA_ULONGLONG
);
141 kstat_named_init(&dkp
->ds_algs
[DS_RNGBYTES
], "rngbytes",
142 KSTAT_DATA_ULONGLONG
);
143 kstat_named_init(&dkp
->ds_algs
[DS_RNGSHA1JOBS
], "rngsha1jobs",
144 KSTAT_DATA_ULONGLONG
);
145 kstat_named_init(&dkp
->ds_algs
[DS_RNGSHA1BYTES
],
146 "rngsha1bytes", KSTAT_DATA_ULONGLONG
);
147 dca
->dca_ksp
->ks_update
= dca_ksupdate
;
148 dca
->dca_ksp
->ks_private
= dca
;
149 kstat_install(dca
->dca_ksp
);
157 dca_ksupdate(kstat_t
*ksp
, int rw
)
163 dca
= (dca_t
*)ksp
->ks_private
;
164 dkp
= (dca_stat_t
*)ksp
->ks_data
;
166 if (rw
== KSTAT_WRITE
) {
167 for (i
= 0; i
< DS_MAX
; i
++) {
168 dca
->dca_stats
[i
] = dkp
->ds_algs
[i
].value
.ull
;
170 for (i
= MCR1
; i
<= MCR2
; i
++) {
171 WORKLIST(dca
, i
)->dwl_submit
=
172 dkp
->ds_mcr
[i
- 1].ds_submit
.value
.ull
;
173 WORKLIST(dca
, i
)->dwl_flowctl
=
174 dkp
->ds_mcr
[i
- 1].ds_flowctl
.value
.ull
;
175 /* hiwater, lowater, and maxreqs are read only */
178 /* handy status value */
179 if (dca
->dca_flags
& DCA_FAILED
) {
180 /* device has failed */
181 (void) strcpy(dkp
->ds_status
.value
.c
, "fail");
182 } else if ((WORKLIST(dca
, MCR1
)->dwl_drain
) ||
183 (WORKLIST(dca
, MCR2
)->dwl_drain
)) {
184 /* device is draining for DR */
185 (void) strcpy(dkp
->ds_status
.value
.c
, "drain");
187 /* everything looks good */
188 (void) strcpy(dkp
->ds_status
.value
.c
, "online");
191 for (i
= 0; i
< DS_MAX
; i
++) {
192 dkp
->ds_algs
[i
].value
.ull
= dca
->dca_stats
[i
];
194 for (i
= MCR1
; i
<= MCR2
; i
++) {
195 dkp
->ds_mcr
[i
- 1].ds_submit
.value
.ull
=
196 WORKLIST(dca
, i
)->dwl_submit
;
197 dkp
->ds_mcr
[i
- 1].ds_flowctl
.value
.ull
=
198 WORKLIST(dca
, i
)->dwl_flowctl
;
199 dkp
->ds_mcr
[i
- 1].ds_lowater
.value
.ull
=
200 WORKLIST(dca
, i
)->dwl_lowater
;
201 dkp
->ds_mcr
[i
- 1].ds_hiwater
.value
.ull
=
202 WORKLIST(dca
, i
)->dwl_hiwater
;
203 dkp
->ds_mcr
[i
- 1].ds_maxreqs
.value
.ull
=
204 WORKLIST(dca
, i
)->dwl_reqspermcr
;