Lines Matching refs:state

191 viorand_rbuf_alloc(viorand_state_t *state)  in viorand_rbuf_alloc()  argument
195 VERIFY(MUTEX_HELD(&state->vio_mutex)); in viorand_rbuf_alloc()
197 while ((rb = list_remove_head(&state->vio_rdbufs_free)) == NULL) in viorand_rbuf_alloc()
198 cv_wait(&state->vio_cv, &state->vio_mutex); in viorand_rbuf_alloc()
200 state->vio_rdbufs_alloc++; in viorand_rbuf_alloc()
208 viorand_rbuf_free(viorand_state_t *state, viorand_rdbuf_t *rb) in viorand_rbuf_free() argument
210 VERIFY(MUTEX_HELD(&state->vio_mutex)); in viorand_rbuf_free()
211 VERIFY3U(state->vio_rdbufs_alloc, >, 0); in viorand_rbuf_free()
213 state->vio_rdbufs_alloc--; in viorand_rbuf_free()
219 list_insert_head(&state->vio_rdbufs_free, rb); in viorand_rbuf_free()
227 viorand_free_bufs(viorand_state_t *state) in viorand_free_bufs() argument
229 VERIFY(MUTEX_HELD(&state->vio_mutex)); in viorand_free_bufs()
231 for (uint_t i = 0; i < state->vio_rdbufs_capacity; i++) { in viorand_free_bufs()
232 viorand_rdbuf_t *rb = &state->vio_rdbuf_mem[i]; in viorand_free_bufs()
245 if (state->vio_rdbuf_mem != NULL) { in viorand_free_bufs()
246 kmem_free(state->vio_rdbuf_mem, in viorand_free_bufs()
247 sizeof (viorand_rdbuf_t) * state->vio_rdbufs_capacity); in viorand_free_bufs()
248 state->vio_rdbuf_mem = NULL; in viorand_free_bufs()
249 state->vio_rdbufs_capacity = 0; in viorand_free_bufs()
250 state->vio_rdbufs_alloc = 0; in viorand_free_bufs()
255 viorand_alloc_bufs(viorand_state_t *state) in viorand_alloc_bufs() argument
257 VERIFY(MUTEX_HELD(&state->vio_mutex)); in viorand_alloc_bufs()
259 state->vio_rdbufs_capacity = virtio_queue_size(state->vio_rq); in viorand_alloc_bufs()
260 state->vio_rdbuf_mem = kmem_zalloc(sizeof (viorand_rdbuf_t) * in viorand_alloc_bufs()
261 state->vio_rdbufs_capacity, KM_SLEEP); in viorand_alloc_bufs()
262 list_create(&state->vio_rdbufs_free, sizeof (viorand_rdbuf_t), in viorand_alloc_bufs()
266 for (uint_t i = 0; i < state->vio_rdbufs_capacity; i++) in viorand_alloc_bufs()
267 list_insert_tail(&state->vio_rdbufs_free, in viorand_alloc_bufs()
268 &state->vio_rdbuf_mem[i]); in viorand_alloc_bufs()
270 for (viorand_rdbuf_t *rb = list_head(&state->vio_rdbufs_free); in viorand_alloc_bufs()
271 rb != NULL; rb = list_next(&state->vio_rdbufs_free, rb)) { in viorand_alloc_bufs()
272 rb->rb_viornd = state; in viorand_alloc_bufs()
273 rb->rb_chain = virtio_chain_alloc(state->vio_rq, KM_SLEEP); in viorand_alloc_bufs()
282 viorand_free_bufs(state); in viorand_alloc_bufs()
291 viorand_state_t *state; in viorand_attach() local
312 state = ddi_get_soft_state(viorand_statep, instance); in viorand_attach()
313 state->vio_dip = dip; in viorand_attach()
314 state->vio_virtio = vio; in viorand_attach()
315 state->vio_rq = virtio_queue_alloc(vio, VIORAND_RQ, "requestq", in viorand_attach()
316 viorand_interrupt, state, B_FALSE, 1); in viorand_attach()
317 if (state->vio_rq == NULL) { in viorand_attach()
318 virtio_fini(state->vio_virtio, B_TRUE); in viorand_attach()
323 if (virtio_init_complete(state->vio_virtio, VIRTIO_ANY_INTR_TYPE) != in viorand_attach()
325 virtio_fini(state->vio_virtio, B_TRUE); in viorand_attach()
330 cv_init(&state->vio_cv, NULL, CV_DRIVER, NULL); in viorand_attach()
331 mutex_init(&state->vio_mutex, NULL, MUTEX_DRIVER, virtio_intr_pri(vio)); in viorand_attach()
332 mutex_enter(&state->vio_mutex); in viorand_attach()
334 if (viorand_alloc_bufs(state) != 0) { in viorand_attach()
335 mutex_exit(&state->vio_mutex); in viorand_attach()
339 mutex_exit(&state->vio_mutex); in viorand_attach()
342 viorand_prov_info.pi_provider_handle = state; in viorand_attach()
344 if (virtio_interrupts_enable(state->vio_virtio) != DDI_SUCCESS) in viorand_attach()
347 rv = crypto_register_provider(&viorand_prov_info, &state->vio_handle); in viorand_attach()
353 virtio_interrupts_disable(state->vio_virtio); in viorand_attach()
354 mutex_enter(&state->vio_mutex); in viorand_attach()
355 viorand_free_bufs(state); in viorand_attach()
356 mutex_exit(&state->vio_mutex); in viorand_attach()
357 cv_destroy(&state->vio_cv); in viorand_attach()
358 mutex_destroy(&state->vio_mutex); in viorand_attach()
359 virtio_fini(state->vio_virtio, B_TRUE); in viorand_attach()
368 viorand_state_t *state = ddi_get_soft_state(viorand_statep, instance); in viorand_detach() local
381 if (crypto_unregister_provider(state->vio_handle) != CRYPTO_SUCCESS) in viorand_detach()
384 virtio_interrupts_disable(state->vio_virtio); in viorand_detach()
385 virtio_shutdown(state->vio_virtio); in viorand_detach()
387 mutex_enter(&state->vio_mutex); in viorand_detach()
391 vic = virtio_queue_evacuate(state->vio_rq); in viorand_detach()
395 viorand_rbuf_free(state, virtio_chain_data(vic)); in viorand_detach()
398 viorand_free_bufs(state); in viorand_detach()
399 mutex_exit(&state->vio_mutex); in viorand_detach()
400 cv_destroy(&state->vio_cv); in viorand_detach()
401 mutex_destroy(&state->vio_mutex); in viorand_detach()
402 (void) virtio_fini(state->vio_virtio, B_FALSE); in viorand_detach()
411 viorand_state_t *state = ddi_get_soft_state(viorand_statep, instance); in viorand_quiesce() local
413 if (state == NULL) in viorand_quiesce()
416 return (virtio_quiesce(state->vio_virtio)); in viorand_quiesce()
474 viorand_state_t *state = (viorand_state_t *)a; in viorand_interrupt() local
478 mutex_enter(&state->vio_mutex); in viorand_interrupt()
479 while ((vic = virtio_queue_poll(state->vio_rq)) != NULL) { in viorand_interrupt()
490 cv_broadcast(&state->vio_cv); in viorand_interrupt()
491 mutex_exit(&state->vio_mutex); in viorand_interrupt()
505 viorand_state_t *state = provider; in viorand_generate_random() local
508 mutex_enter(&state->vio_mutex); in viorand_generate_random()
509 rb = viorand_rbuf_alloc(state); in viorand_generate_random()
510 mutex_exit(&state->vio_mutex); in viorand_generate_random()
516 rb->rb_dma = virtio_dma_alloc(state->vio_virtio, len, in viorand_generate_random()
526 mutex_enter(&state->vio_mutex); in viorand_generate_random()
527 viorand_rbuf_free(state, rb); in viorand_generate_random()
528 mutex_exit(&state->vio_mutex); in viorand_generate_random()