* Crypto thread, dispatches crypto requests. */
| 1945 | * Crypto thread, dispatches crypto requests. |
| 1946 | */ |
| 1947 | static void |
| 1948 | crypto_proc(void) |
| 1949 | { |
| 1950 | struct cryptop *crp, *submit; |
| 1951 | struct cryptkop *krp; |
| 1952 | struct cryptocap *cap; |
| 1953 | int result, hint; |
| 1954 | |
| 1955 | #if defined(__i386__) || defined(__amd64__) || defined(__aarch64__) |
| 1956 | fpu_kern_thread(FPU_KERN_NORMAL); |
| 1957 | #endif |
| 1958 | |
| 1959 | CRYPTO_Q_LOCK(); |
| 1960 | for (;;) { |
| 1961 | /* |
| 1962 | * Find the first element in the queue that can be |
| 1963 | * processed and look-ahead to see if multiple ops |
| 1964 | * are ready for the same driver. |
| 1965 | */ |
| 1966 | submit = NULL; |
| 1967 | hint = 0; |
| 1968 | TAILQ_FOREACH(crp, &crp_q, crp_next) { |
| 1969 | cap = crp->crp_session->cap; |
| 1970 | /* |
| 1971 | * Driver cannot disappeared when there is an active |
| 1972 | * session. |
| 1973 | */ |
| 1974 | KASSERT(cap != NULL, ("%s:%u Driver disappeared.", |
| 1975 | __func__, __LINE__)); |
| 1976 | if (cap->cc_flags & CRYPTOCAP_F_CLEANUP) { |
| 1977 | /* Op needs to be migrated, process it. */ |
| 1978 | if (submit == NULL) |
| 1979 | submit = crp; |
| 1980 | break; |
| 1981 | } |
| 1982 | if (!cap->cc_qblocked) { |
| 1983 | if (submit != NULL) { |
| 1984 | /* |
| 1985 | * We stop on finding another op, |
| 1986 | * regardless whether its for the same |
| 1987 | * driver or not. We could keep |
| 1988 | * searching the queue but it might be |
| 1989 | * better to just use a per-driver |
| 1990 | * queue instead. |
| 1991 | */ |
| 1992 | if (submit->crp_session->cap == cap) |
| 1993 | hint = CRYPTO_HINT_MORE; |
| 1994 | break; |
| 1995 | } else { |
| 1996 | submit = crp; |
| 1997 | if ((submit->crp_flags & CRYPTO_F_BATCH) == 0) |
| 1998 | break; |
| 1999 | /* keep scanning for more are q'd */ |
| 2000 | } |
| 2001 | } |
| 2002 | } |
| 2003 | if (submit != NULL) { |
| 2004 | TAILQ_REMOVE(&crp_q, submit, crp_next); |
nothing calls this directly
no test coverage detected