* Invoke the callback on behalf of the driver. */
| 1799 | * Invoke the callback on behalf of the driver. |
| 1800 | */ |
| 1801 | void |
| 1802 | crypto_done(struct cryptop *crp) |
| 1803 | { |
| 1804 | KASSERT((crp->crp_flags & CRYPTO_F_DONE) == 0, |
| 1805 | ("crypto_done: op already done, flags 0x%x", crp->crp_flags)); |
| 1806 | crp->crp_flags |= CRYPTO_F_DONE; |
| 1807 | if (crp->crp_etype != 0) |
| 1808 | CRYPTOSTAT_INC(cs_errs); |
| 1809 | |
| 1810 | /* |
| 1811 | * CBIMM means unconditionally do the callback immediately; |
| 1812 | * CBIFSYNC means do the callback immediately only if the |
| 1813 | * operation was done synchronously. Both are used to avoid |
| 1814 | * doing extraneous context switches; the latter is mostly |
| 1815 | * used with the software crypto driver. |
| 1816 | */ |
| 1817 | if (!CRYPTOP_ASYNC_KEEPORDER(crp) && |
| 1818 | ((crp->crp_flags & CRYPTO_F_CBIMM) || |
| 1819 | ((crp->crp_flags & CRYPTO_F_CBIFSYNC) && |
| 1820 | (crypto_ses2caps(crp->crp_session) & CRYPTOCAP_F_SYNC)))) { |
| 1821 | /* |
| 1822 | * Do the callback directly. This is ok when the |
| 1823 | * callback routine does very little (e.g. the |
| 1824 | * /dev/crypto callback method just does a wakeup). |
| 1825 | */ |
| 1826 | crp->crp_callback(crp); |
| 1827 | } else { |
| 1828 | struct crypto_ret_worker *ret_worker; |
| 1829 | bool wake; |
| 1830 | |
| 1831 | ret_worker = CRYPTO_RETW(crp->crp_retw_id); |
| 1832 | wake = false; |
| 1833 | |
| 1834 | /* |
| 1835 | * Normal case; queue the callback for the thread. |
| 1836 | */ |
| 1837 | CRYPTO_RETW_LOCK(ret_worker); |
| 1838 | if (CRYPTOP_ASYNC_KEEPORDER(crp)) { |
| 1839 | struct cryptop *tmp; |
| 1840 | |
| 1841 | TAILQ_FOREACH_REVERSE(tmp, &ret_worker->crp_ordered_ret_q, |
| 1842 | cryptop_q, crp_next) { |
| 1843 | if (CRYPTO_SEQ_GT(crp->crp_seq, tmp->crp_seq)) { |
| 1844 | TAILQ_INSERT_AFTER(&ret_worker->crp_ordered_ret_q, |
| 1845 | tmp, crp, crp_next); |
| 1846 | break; |
| 1847 | } |
| 1848 | } |
| 1849 | if (tmp == NULL) { |
| 1850 | TAILQ_INSERT_HEAD(&ret_worker->crp_ordered_ret_q, |
| 1851 | crp, crp_next); |
| 1852 | } |
| 1853 | |
| 1854 | if (crp->crp_seq == ret_worker->reorder_cur_seq) |
| 1855 | wake = true; |
| 1856 | } |
| 1857 | else { |
| 1858 | if (CRYPTO_RETW_EMPTY(ret_worker)) |
no test coverage detected