2 /* $OpenBSD: crypto.c,v 1.38 2002/06/11 11:14:29 beck Exp $ */
4 * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
6 * This code was written by Angelos D. Keromytis in Athens, Greece, in
7 * February 2000. Network Security Technologies Inc. (NSTI) kindly
8 * supported the development of this code.
10 * Copyright (c) 2000, 2001 Angelos D. Keromytis
12 * Permission to use, copy, and modify this software with or without fee
13 * is hereby granted, provided that this entire notice is included in
14 * all source code copies of any software which is or includes a copy or
15 * modification of this software.
17 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
18 * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
19 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
20 * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
24 #include <sys/param.h>
25 #include <sys/systm.h>
26 #include <sys/eventhandler.h>
27 #include <sys/kernel.h>
28 #include <sys/kthread.h>
30 #include <sys/mutex.h>
31 #include <sys/malloc.h>
33 #include <sys/sysctl.h>
36 #include <opencrypto/cryptodev.h>
38 #define SESID2HID(sid) (((sid) >> 32) & 0xffffffff)
41 * Crypto drivers register themselves by allocating a slot in the
42 * crypto_drivers table with crypto_get_driverid() and then registering
43 * each algorithm they support with crypto_register() and crypto_kregister().
45 static struct mtx crypto_drivers_mtx; /* lock on driver table */
46 #define CRYPTO_DRIVER_LOCK() mtx_lock(&crypto_drivers_mtx)
47 #define CRYPTO_DRIVER_UNLOCK() mtx_unlock(&crypto_drivers_mtx)
48 static struct cryptocap *crypto_drivers = NULL;
49 static int crypto_drivers_num = 0;
52 * There are two queues for crypto requests; one for symmetric (e.g.
53 * cipher) operations and one for asymmetric (e.g. MOD)operations.
54 * A single mutex is used to lock access to both queues. We could
55 * have one per-queue but having one simplifies handling of block/unblock
58 static TAILQ_HEAD(,cryptop) crp_q; /* request queues */
59 static TAILQ_HEAD(,cryptkop) crp_kq;
60 static struct mtx crypto_q_mtx;
61 #define CRYPTO_Q_LOCK() mtx_lock(&crypto_q_mtx)
62 #define CRYPTO_Q_UNLOCK() mtx_unlock(&crypto_q_mtx)
65 * There are two queues for processing completed crypto requests; one
66 * for the symmetric and one for the asymmetric ops. We only need one
67 * but have two to avoid type futzing (cryptop vs. cryptkop). A single
68 * mutex is used to lock access to both queues. Note that this lock
69 * must be separate from the lock on request queues to insure driver
70 * callbacks don't generate lock order reversals.
72 static TAILQ_HEAD(,cryptop) crp_ret_q; /* callback queues */
73 static TAILQ_HEAD(,cryptkop) crp_ret_kq;
74 static struct mtx crypto_ret_q_mtx;
75 #define CRYPTO_RETQ_LOCK() mtx_lock(&crypto_ret_q_mtx)
76 #define CRYPTO_RETQ_UNLOCK() mtx_unlock(&crypto_ret_q_mtx)
78 static uma_zone_t cryptop_zone;
79 static uma_zone_t cryptodesc_zone;
81 int crypto_usercrypto = 1; /* userland may open /dev/crypto */
82 SYSCTL_INT(_kern, OID_AUTO, usercrypto, CTLFLAG_RW,
83 &crypto_usercrypto, 0,
84 "Enable/disable user-mode access to crypto support");
85 int crypto_userasymcrypto = 1; /* userland may do asym crypto reqs */
86 SYSCTL_INT(_kern, OID_AUTO, userasymcrypto, CTLFLAG_RW,
87 &crypto_userasymcrypto, 0,
88 "Enable/disable user-mode access to asymmetric crypto support");
89 int crypto_devallowsoft = 0; /* only use hardware crypto for asym */
90 SYSCTL_INT(_kern, OID_AUTO, cryptodevallowsoft, CTLFLAG_RW,
91 &crypto_devallowsoft, 0,
92 "Enable/disable use of software asym crypto support");
94 MALLOC_DEFINE(M_CRYPTO_DATA, "crypto", "crypto session records");
99 cryptop_zone = uma_zcreate("cryptop", sizeof (struct cryptop),
101 UMA_ALIGN_PTR, UMA_ZONE_ZINIT);
102 cryptodesc_zone = uma_zcreate("cryptodesc", sizeof (struct cryptodesc),
104 UMA_ALIGN_PTR, UMA_ZONE_ZINIT);
105 if (cryptodesc_zone == NULL || cryptop_zone == NULL)
106 panic("cannot setup crypto zones");
108 mtx_init(&crypto_drivers_mtx, "crypto driver table",
109 NULL, MTX_DEF|MTX_QUIET);
111 crypto_drivers_num = CRYPTO_DRIVERS_INITIAL;
112 crypto_drivers = malloc(crypto_drivers_num *
113 sizeof(struct cryptocap), M_CRYPTO_DATA, M_NOWAIT | M_ZERO);
114 if (crypto_drivers == NULL)
115 panic("cannot setup crypto drivers");
119 mtx_init(&crypto_q_mtx, "crypto op queues", NULL, MTX_DEF);
121 TAILQ_INIT(&crp_ret_q);
122 TAILQ_INIT(&crp_ret_kq);
123 mtx_init(&crypto_ret_q_mtx, "crypto return queues", NULL, MTX_DEF);
125 SYSINIT(crypto_init, SI_SUB_DRIVERS, SI_ORDER_FIRST, crypto_init, NULL)
128 * Create a new session.
131 crypto_newsession(u_int64_t *sid, struct cryptoini *cri, int hard)
133 struct cryptoini *cr;
137 CRYPTO_DRIVER_LOCK();
139 if (crypto_drivers == NULL)
143 * The algorithm we use here is pretty stupid; just use the
144 * first driver that supports all the algorithms we need.
146 * XXX We need more smarts here (in real life too, but that's
147 * XXX another story altogether).
150 for (hid = 0; hid < crypto_drivers_num; hid++) {
152 * If it's not initialized or has remaining sessions
153 * referencing it, skip.
155 if (crypto_drivers[hid].cc_newsession == NULL ||
156 (crypto_drivers[hid].cc_flags & CRYPTOCAP_F_CLEANUP))
159 /* Hardware required -- ignore software drivers. */
161 (crypto_drivers[hid].cc_flags & CRYPTOCAP_F_SOFTWARE))
163 /* Software required -- ignore hardware drivers. */
165 (crypto_drivers[hid].cc_flags & CRYPTOCAP_F_SOFTWARE) == 0)
168 /* See if all the algorithms are supported. */
169 for (cr = cri; cr; cr = cr->cri_next)
170 if (crypto_drivers[hid].cc_alg[cr->cri_alg] == 0)
174 /* Ok, all algorithms are supported. */
177 * Can't do everything in one session.
179 * XXX Fix this. We need to inject a "virtual" session layer right
183 /* Call the driver initialization routine. */
184 lid = hid; /* Pass the driver ID. */
185 err = crypto_drivers[hid].cc_newsession(
186 crypto_drivers[hid].cc_arg, &lid, cri);
190 (*sid) |= (lid & 0xffffffff);
191 crypto_drivers[hid].cc_sessions++;
197 CRYPTO_DRIVER_UNLOCK();
202 * Delete an existing session (or a reserved session on an unregistered
206 crypto_freesession(u_int64_t sid)
211 CRYPTO_DRIVER_LOCK();
213 if (crypto_drivers == NULL) {
218 /* Determine two IDs. */
219 hid = SESID2HID(sid);
221 if (hid >= crypto_drivers_num) {
226 if (crypto_drivers[hid].cc_sessions)
227 crypto_drivers[hid].cc_sessions--;
229 /* Call the driver cleanup routine, if available. */
230 if (crypto_drivers[hid].cc_freesession)
231 err = crypto_drivers[hid].cc_freesession(
232 crypto_drivers[hid].cc_arg, sid);
237 * If this was the last session of a driver marked as invalid,
238 * make the entry available for reuse.
240 if ((crypto_drivers[hid].cc_flags & CRYPTOCAP_F_CLEANUP) &&
241 crypto_drivers[hid].cc_sessions == 0)
242 bzero(&crypto_drivers[hid], sizeof(struct cryptocap));
245 CRYPTO_DRIVER_UNLOCK();
250 * Return an unused driver id. Used by drivers prior to registering
251 * support for the algorithms they handle.
254 crypto_get_driverid(u_int32_t flags)
256 struct cryptocap *newdrv;
259 CRYPTO_DRIVER_LOCK();
261 for (i = 0; i < crypto_drivers_num; i++)
262 if (crypto_drivers[i].cc_process == NULL &&
263 (crypto_drivers[i].cc_flags & CRYPTOCAP_F_CLEANUP) == 0 &&
264 crypto_drivers[i].cc_sessions == 0)
267 /* Out of entries, allocate some more. */
268 if (i == crypto_drivers_num) {
269 /* Be careful about wrap-around. */
270 if (2 * crypto_drivers_num <= crypto_drivers_num) {
271 CRYPTO_DRIVER_UNLOCK();
272 printf("crypto: driver count wraparound!\n");
276 newdrv = malloc(2 * crypto_drivers_num *
277 sizeof(struct cryptocap), M_CRYPTO_DATA, M_NOWAIT|M_ZERO);
278 if (newdrv == NULL) {
279 CRYPTO_DRIVER_UNLOCK();
280 printf("crypto: no space to expand driver table!\n");
284 bcopy(crypto_drivers, newdrv,
285 crypto_drivers_num * sizeof(struct cryptocap));
287 crypto_drivers_num *= 2;
289 free(crypto_drivers, M_CRYPTO_DATA);
290 crypto_drivers = newdrv;
293 /* NB: state is zero'd on free */
294 crypto_drivers[i].cc_sessions = 1; /* Mark */
295 crypto_drivers[i].cc_flags = flags;
297 printf("crypto: assign driver %u, flags %u\n", i, flags);
299 CRYPTO_DRIVER_UNLOCK();
304 static struct cryptocap *
305 crypto_checkdriver(u_int32_t hid)
307 if (crypto_drivers == NULL)
309 return (hid >= crypto_drivers_num ? NULL : &crypto_drivers[hid]);
313 * Register support for a key-related algorithm. This routine
314 * is called once for each algorithm supported a driver.
317 crypto_kregister(u_int32_t driverid, int kalg, u_int32_t flags,
318 int (*kprocess)(void*, struct cryptkop *, int),
321 struct cryptocap *cap;
324 CRYPTO_DRIVER_LOCK();
326 cap = crypto_checkdriver(driverid);
328 (CRK_ALGORITM_MIN <= kalg && kalg <= CRK_ALGORITHM_MAX)) {
330 * XXX Do some performance testing to determine placing.
331 * XXX We probably need an auxiliary data structure that
332 * XXX describes relative performances.
335 cap->cc_kalg[kalg] = flags | CRYPTO_ALG_FLAG_SUPPORTED;
337 printf("crypto: driver %u registers key alg %u flags %u\n"
343 if (cap->cc_kprocess == NULL) {
345 cap->cc_kprocess = kprocess;
351 CRYPTO_DRIVER_UNLOCK();
356 * Register support for a non-key-related algorithm. This routine
357 * is called once for each such algorithm supported by a driver.
360 crypto_register(u_int32_t driverid, int alg, u_int16_t maxoplen,
362 int (*newses)(void*, u_int32_t*, struct cryptoini*),
363 int (*freeses)(void*, u_int64_t),
364 int (*process)(void*, struct cryptop *, int),
367 struct cryptocap *cap;
370 CRYPTO_DRIVER_LOCK();
372 cap = crypto_checkdriver(driverid);
373 /* NB: algorithms are in the range [1..max] */
375 (CRYPTO_ALGORITHM_MIN <= alg && alg <= CRYPTO_ALGORITHM_MAX)) {
377 * XXX Do some performance testing to determine placing.
378 * XXX We probably need an auxiliary data structure that
379 * XXX describes relative performances.
382 cap->cc_alg[alg] = flags | CRYPTO_ALG_FLAG_SUPPORTED;
383 cap->cc_max_op_len[alg] = maxoplen;
385 printf("crypto: driver %u registers alg %u flags %u maxoplen %u\n"
392 if (cap->cc_process == NULL) {
394 cap->cc_newsession = newses;
395 cap->cc_process = process;
396 cap->cc_freesession = freeses;
397 cap->cc_sessions = 0; /* Unmark */
403 CRYPTO_DRIVER_UNLOCK();
408 * Unregister a crypto driver. If there are pending sessions using it,
409 * leave enough information around so that subsequent calls using those
410 * sessions will correctly detect the driver has been unregistered and
414 crypto_unregister(u_int32_t driverid, int alg)
418 struct cryptocap *cap;
420 CRYPTO_DRIVER_LOCK();
422 cap = crypto_checkdriver(driverid);
424 (CRYPTO_ALGORITHM_MIN <= alg && alg <= CRYPTO_ALGORITHM_MAX) &&
425 cap->cc_alg[alg] != 0) {
426 cap->cc_alg[alg] = 0;
427 cap->cc_max_op_len[alg] = 0;
429 /* Was this the last algorithm ? */
430 for (i = 1; i <= CRYPTO_ALGORITHM_MAX; i++)
431 if (cap->cc_alg[i] != 0)
434 if (i == CRYPTO_ALGORITHM_MAX + 1) {
435 ses = cap->cc_sessions;
436 bzero(cap, sizeof(struct cryptocap));
439 * If there are pending sessions, just mark as invalid.
441 cap->cc_flags |= CRYPTOCAP_F_CLEANUP;
442 cap->cc_sessions = ses;
449 CRYPTO_DRIVER_UNLOCK();
454 * Unregister all algorithms associated with a crypto driver.
455 * If there are pending sessions using it, leave enough information
456 * around so that subsequent calls using those sessions will
457 * correctly detect the driver has been unregistered and reroute
461 crypto_unregister_all(u_int32_t driverid)
465 struct cryptocap *cap;
467 CRYPTO_DRIVER_LOCK();
469 cap = crypto_checkdriver(driverid);
471 for (i = CRYPTO_ALGORITHM_MIN; i <= CRYPTO_ALGORITHM_MAX; i++) {
473 cap->cc_max_op_len[i] = 0;
475 ses = cap->cc_sessions;
476 bzero(cap, sizeof(struct cryptocap));
479 * If there are pending sessions, just mark as invalid.
481 cap->cc_flags |= CRYPTOCAP_F_CLEANUP;
482 cap->cc_sessions = ses;
488 CRYPTO_DRIVER_UNLOCK();
493 * Clear blockage on a driver. The what parameter indicates whether
494 * the driver is now ready for cryptop's and/or cryptokop's.
497 crypto_unblock(u_int32_t driverid, int what)
499 struct cryptocap *cap;
505 cap = crypto_checkdriver(driverid);
507 if (what & CRYPTO_SYMQ) {
508 needwakeup |= cap->cc_qblocked;
509 cap->cc_qblocked = 0;
511 if (what & CRYPTO_ASYMQ) {
512 needwakeup |= cap->cc_kqblocked;
513 cap->cc_kqblocked = 0;
527 * Add a crypto request to a queue, to be processed by the kernel thread.
530 crypto_dispatch(struct cryptop *crp)
532 struct cryptocap *cap;
536 wasempty = TAILQ_EMPTY(&crp_q);
537 TAILQ_INSERT_TAIL(&crp_q, crp, crp_next);
540 * Wakeup processing thread if driver is not blocked.
542 cap = crypto_checkdriver(SESID2HID(crp->crp_sid));
543 if (cap && !cap->cc_qblocked && wasempty)
551 * Add an asymetric crypto request to a queue,
552 * to be processed by the kernel thread.
555 crypto_kdispatch(struct cryptkop *krp)
557 struct cryptocap *cap;
561 wasempty = TAILQ_EMPTY(&crp_kq);
562 TAILQ_INSERT_TAIL(&crp_kq, krp, krp_next);
565 * Wakeup processing thread if driver is not blocked.
567 cap = crypto_checkdriver(krp->krp_hid);
568 if (cap && !cap->cc_kqblocked && wasempty)
569 wakeup_one(&crp_q); /* NB: shared wait channel */
576 * Dispatch an assymetric crypto request to the appropriate crypto devices.
579 crypto_kinvoke(struct cryptkop *krp, int hint)
584 mtx_assert(&crypto_q_mtx, MA_OWNED);
587 if (krp == NULL || krp->krp_callback == NULL)
590 for (hid = 0; hid < crypto_drivers_num; hid++) {
591 if ((crypto_drivers[hid].cc_flags & CRYPTOCAP_F_SOFTWARE) &&
592 !crypto_devallowsoft)
594 if (crypto_drivers[hid].cc_kprocess == NULL)
596 if ((crypto_drivers[hid].cc_kalg[krp->krp_op] &
597 CRYPTO_ALG_FLAG_SUPPORTED) == 0)
601 if (hid < crypto_drivers_num) {
603 error = crypto_drivers[hid].cc_kprocess(
604 crypto_drivers[hid].cc_karg, krp, hint);
609 krp->krp_status = error;
611 TAILQ_INSERT_TAIL(&crp_ret_kq, krp, krp_next);
612 CRYPTO_RETQ_UNLOCK();
618 * Dispatch a crypto request to the appropriate crypto devices.
621 crypto_invoke(struct cryptop *crp, int hint)
624 int (*process)(void*, struct cryptop *, int);
626 mtx_assert(&crypto_q_mtx, MA_OWNED);
629 if (crp == NULL || crp->crp_callback == NULL)
632 if (crp->crp_desc == NULL) {
633 crp->crp_etype = EINVAL;
635 TAILQ_INSERT_TAIL(&crp_ret_q, crp, crp_next);
636 CRYPTO_RETQ_UNLOCK();
640 hid = SESID2HID(crp->crp_sid);
641 if (hid < crypto_drivers_num) {
642 if (crypto_drivers[hid].cc_flags & CRYPTOCAP_F_CLEANUP)
643 crypto_freesession(crp->crp_sid);
644 process = crypto_drivers[hid].cc_process;
649 if (process == NULL) {
650 struct cryptodesc *crd;
654 * Driver has unregistered; migrate the session and return
655 * an error to the caller so they'll resubmit the op.
657 for (crd = crp->crp_desc; crd->crd_next; crd = crd->crd_next)
658 crd->CRD_INI.cri_next = &(crd->crd_next->CRD_INI);
660 if (crypto_newsession(&nid, &(crp->crp_desc->CRD_INI), 0) == 0)
663 crp->crp_etype = EAGAIN;
665 TAILQ_INSERT_TAIL(&crp_ret_q, crp, crp_next);
666 CRYPTO_RETQ_UNLOCK();
670 * Invoke the driver to process the request.
672 return (*process)(crypto_drivers[hid].cc_arg, crp, hint);
677 * Release a set of crypto descriptors.
680 crypto_freereq(struct cryptop *crp)
682 struct cryptodesc *crd;
687 while ((crd = crp->crp_desc) != NULL) {
688 crp->crp_desc = crd->crd_next;
689 uma_zfree(cryptodesc_zone, crd);
692 uma_zfree(cryptop_zone, crp);
696 * Acquire a set of crypto descriptors.
699 crypto_getreq(int num)
701 struct cryptodesc *crd;
704 crp = uma_zalloc(cryptop_zone, 0);
707 crd = uma_zalloc(cryptodesc_zone, 0);
713 crd->crd_next = crp->crp_desc;
721 * Invoke the callback on behalf of the driver.
724 crypto_done(struct cryptop *crp)
729 wasempty = TAILQ_EMPTY(&crp_ret_q);
730 TAILQ_INSERT_TAIL(&crp_ret_q, crp, crp_next);
731 CRYPTO_RETQ_UNLOCK();
734 wakeup_one(&crp_q); /* shared wait channel */
738 * Invoke the callback on behalf of the driver.
741 crypto_kdone(struct cryptkop *krp)
746 wasempty = TAILQ_EMPTY(&crp_ret_kq);
747 TAILQ_INSERT_TAIL(&crp_ret_kq, krp, krp_next);
748 CRYPTO_RETQ_UNLOCK();
751 wakeup_one(&crp_q); /* shared wait channel */
755 crypto_getfeat(int *featp)
757 int hid, kalg, feat = 0;
759 if (!crypto_userasymcrypto)
762 CRYPTO_DRIVER_LOCK();
763 for (hid = 0; hid < crypto_drivers_num; hid++) {
764 if ((crypto_drivers[hid].cc_flags & CRYPTOCAP_F_SOFTWARE) &&
765 !crypto_devallowsoft) {
768 if (crypto_drivers[hid].cc_kprocess == NULL)
770 for (kalg = 0; kalg < CRK_ALGORITHM_MAX; kalg++)
771 if ((crypto_drivers[hid].cc_kalg[kalg] &
772 CRYPTO_ALG_FLAG_SUPPORTED) != 0)
775 CRYPTO_DRIVER_UNLOCK();
781 static struct proc *cryptoproc;
784 crypto_shutdown(void *arg, int howto)
786 /* XXX flush queues */
790 * Crypto thread, runs as a kernel thread to process crypto requests.
795 struct cryptop *crp, *crpt, *submit;
796 struct cryptkop *krp, *krpt;
797 struct cryptocap *cap;
800 mtx_lock(&Giant); /* XXX for msleep */
802 EVENTHANDLER_REGISTER(shutdown_pre_sync, crypto_shutdown, NULL,
807 * Find the first element in the queue that can be
808 * processed and look-ahead to see if multiple ops
809 * are ready for the same driver.
814 TAILQ_FOREACH(crp, &crp_q, crp_next) {
815 u_int32_t hid = SESID2HID(crp->crp_sid);
816 cap = crypto_checkdriver(hid);
817 if (cap == NULL || cap->cc_process == NULL) {
818 /* Op needs to be migrated, process it. */
823 if (!cap->cc_qblocked) {
824 if (submit != NULL) {
826 * We stop on finding another op,
827 * regardless whether its for the same
828 * driver or not. We could keep
829 * searching the queue but it might be
830 * better to just use a per-driver
833 if (SESID2HID(submit->crp_sid) == hid)
834 hint = CRYPTO_HINT_MORE;
838 if (submit->crp_flags & CRYPTO_F_NODELAY)
840 /* keep scanning for more are q'd */
844 if (submit != NULL) {
845 TAILQ_REMOVE(&crp_q, submit, crp_next);
846 result = crypto_invoke(submit, hint);
847 if (result == ERESTART) {
849 * The driver ran out of resources, mark the
850 * driver ``blocked'' for cryptop's and put
851 * the request back in the queue. It would
852 * best to put the request back where we got
853 * it but that's hard so for now we put it
854 * at the front. This should be ok; putting
855 * it at the end does not work.
857 /* XXX validate sid again? */
858 crypto_drivers[SESID2HID(submit->crp_sid)].cc_qblocked = 1;
859 TAILQ_INSERT_HEAD(&crp_q, submit, crp_next);
863 /* As above, but for key ops */
864 TAILQ_FOREACH(krp, &crp_kq, krp_next) {
865 cap = crypto_checkdriver(krp->krp_hid);
866 if (cap == NULL || cap->cc_kprocess == NULL) {
867 /* Op needs to be migrated, process it. */
870 if (!cap->cc_kqblocked)
874 TAILQ_REMOVE(&crp_kq, krp, krp_next);
875 result = crypto_kinvoke(krp, 0);
876 if (result == ERESTART) {
878 * The driver ran out of resources, mark the
879 * driver ``blocked'' for cryptkop's and put
880 * the request back in the queue. It would
881 * best to put the request back where we got
882 * it but that's hard so for now we put it
883 * at the front. This should be ok; putting
884 * it at the end does not work.
886 /* XXX validate sid again? */
887 crypto_drivers[krp->krp_hid].cc_kqblocked = 1;
888 TAILQ_INSERT_HEAD(&crp_kq, krp, krp_next);
893 /* Harvest return q for completed ops */
895 crpt = TAILQ_FIRST(&crp_ret_q);
897 TAILQ_REMOVE(&crp_ret_q, crpt, crp_next);
898 CRYPTO_RETQ_UNLOCK();
901 crpt->crp_callback(crpt);
903 /* Harvest return q for completed kops */
905 krpt = TAILQ_FIRST(&crp_ret_kq);
907 TAILQ_REMOVE(&crp_ret_kq, krpt, krp_next);
908 CRYPTO_RETQ_UNLOCK();
911 krp->krp_callback(krp);
913 if (crp == NULL && krp == NULL && crpt == NULL && krpt == NULL) {
915 * Nothing more to be processed. Sleep until we're
916 * woken because there are more ops to process.
917 * This happens either by submission or by a driver
918 * becoming unblocked and notifying us through
919 * crypto_unblock. Note that when we wakeup we
920 * start processing each queue again from the
921 * front. It's not clear that it's important to
922 * preserve this ordering since ops may finish
923 * out of order if dispatched to different devices
924 * and some become blocked while others do not.
926 tsleep(&crp_q, PWAIT, "crypto_wait", 0);
931 static struct kproc_desc crypto_kp = {
936 SYSINIT(crypto_proc, SI_SUB_KTHREAD_IDLE, SI_ORDER_ANY, kproc_start, &crypto_kp)