Lines Matching refs:state

123 static void xpvtap_drv_fini(xpvtap_state_t *state);
126 typedef void (*xpvtap_rs_cleanup_t)(xpvtap_state_t *state, uint_t rs);
135 static int xpvtap_segmf_register(xpvtap_state_t *state);
138 static int xpvtap_user_init(xpvtap_state_t *state);
139 static void xpvtap_user_fini(xpvtap_state_t *state);
140 static int xpvtap_user_ring_init(xpvtap_state_t *state);
141 static void xpvtap_user_ring_fini(xpvtap_state_t *state);
142 static int xpvtap_user_thread_init(xpvtap_state_t *state);
143 static void xpvtap_user_thread_fini(xpvtap_state_t *state);
145 static void xpvtap_user_thread_stop(xpvtap_state_t *state);
150 static int xpvtap_user_request_map(xpvtap_state_t *state, blkif_request_t *req,
152 static int xpvtap_user_request_push(xpvtap_state_t *state,
154 static int xpvtap_user_response_get(xpvtap_state_t *state,
156 static void xpvtap_user_request_unmap(xpvtap_state_t *state, uint_t uid);
218 xpvtap_state_t *state; in xpvtap_attach() local
236 state = xpvtap_drv_init(instance); in xpvtap_attach()
237 if (state == NULL) { in xpvtap_attach()
240 state->bt_dip = dip; in xpvtap_attach()
243 args.ar_dip = state->bt_dip; in xpvtap_attach()
245 args.ar_intr_arg = (caddr_t)state; in xpvtap_attach()
247 args.ar_ringup_arg = (caddr_t)state; in xpvtap_attach()
249 args.ar_ringdown_arg = (caddr_t)state; in xpvtap_attach()
250 e = blk_ring_init(&args, &state->bt_guest_ring); in xpvtap_attach()
268 blk_ring_fini(&state->bt_guest_ring); in xpvtap_attach()
270 xpvtap_drv_fini(state); in xpvtap_attach()
281 xpvtap_state_t *state; in xpvtap_detach() local
286 state = ddi_get_soft_state(xpvtap_statep, instance); in xpvtap_detach()
287 if (state == NULL) { in xpvtap_detach()
300 xpvtap_user_thread_stop(state); in xpvtap_detach()
301 blk_ring_fini(&state->bt_guest_ring); in xpvtap_detach()
302 xpvtap_drv_fini(state); in xpvtap_detach()
316 xpvtap_state_t *state; in xpvtap_getinfo() local
327 state = ddi_get_soft_state(xpvtap_statep, instance); in xpvtap_getinfo()
328 if (state == NULL) { in xpvtap_getinfo()
331 *result = (void *)state->bt_dip; in xpvtap_getinfo()
356 xpvtap_state_t *state; in xpvtap_open() local
365 state = ddi_get_soft_state(xpvtap_statep, instance); in xpvtap_open()
366 if (state == NULL) { in xpvtap_open()
371 mutex_enter(&state->bt_open.bo_mutex); in xpvtap_open()
372 if (state->bt_open.bo_opened) { in xpvtap_open()
373 mutex_exit(&state->bt_open.bo_mutex); in xpvtap_open()
376 state->bt_open.bo_opened = B_TRUE; in xpvtap_open()
377 mutex_exit(&state->bt_open.bo_mutex); in xpvtap_open()
383 state->bt_map.um_as = curproc->p_as; in xpvtap_open()
396 xpvtap_state_t *state; in xpvtap_close() local
401 state = ddi_get_soft_state(xpvtap_statep, instance); in xpvtap_close()
402 if (state == NULL) { in xpvtap_close()
410 mutex_enter(&state->bt_thread.ut_mutex); in xpvtap_close()
411 state->bt_thread.ut_wake = B_TRUE; in xpvtap_close()
412 state->bt_thread.ut_exit = B_TRUE; in xpvtap_close()
413 cv_signal(&state->bt_thread.ut_wake_cv); in xpvtap_close()
414 if (!state->bt_thread.ut_exit_done) { in xpvtap_close()
415 cv_wait(&state->bt_thread.ut_exit_done_cv, in xpvtap_close()
416 &state->bt_thread.ut_mutex); in xpvtap_close()
418 ASSERT(state->bt_thread.ut_exit_done); in xpvtap_close()
419 mutex_exit(&state->bt_thread.ut_mutex); in xpvtap_close()
421 state->bt_map.um_as = NULL; in xpvtap_close()
422 state->bt_map.um_guest_pages = NULL; in xpvtap_close()
430 mutex_enter(&state->bt_open.bo_mutex); in xpvtap_close()
431 ASSERT(state->bt_open.bo_opened); in xpvtap_close()
432 state->bt_open.bo_opened = B_FALSE; in xpvtap_close()
433 cv_signal(&state->bt_open.bo_exit_cv); in xpvtap_close()
434 mutex_exit(&state->bt_open.bo_mutex); in xpvtap_close()
448 xpvtap_state_t *state; in xpvtap_ioctl() local
461 state = ddi_get_soft_state(xpvtap_statep, instance); in xpvtap_ioctl()
462 if (state == NULL) { in xpvtap_ioctl()
472 mutex_enter(&state->bt_thread.ut_mutex); in xpvtap_ioctl()
473 state->bt_thread.ut_wake = B_TRUE; in xpvtap_ioctl()
474 cv_signal(&state->bt_thread.ut_wake_cv); in xpvtap_ioctl()
475 mutex_exit(&state->bt_thread.ut_mutex); in xpvtap_ioctl()
497 xpvtap_state_t *state; in xpvtap_segmap() local
507 state = ddi_get_soft_state(xpvtap_statep, instance); in xpvtap_segmap()
508 if (state == NULL) { in xpvtap_segmap()
543 ASSERT(asp == state->bt_map.um_as); in xpvtap_segmap()
569 state->bt_map.um_guest_pages = (caddr_t)*addrp; in xpvtap_segmap()
570 state->bt_map.um_guest_size = (size_t)len; in xpvtap_segmap()
573 e = as_add_callback(asp, xpvtap_segmf_unregister, state, in xpvtap_segmap()
581 mutex_enter(&state->bt_thread.ut_mutex); in xpvtap_segmap()
582 state->bt_thread.ut_wake = B_TRUE; in xpvtap_segmap()
583 cv_signal(&state->bt_thread.ut_wake_cv); in xpvtap_segmap()
584 mutex_exit(&state->bt_thread.ut_mutex); in xpvtap_segmap()
599 xpvtap_state_t *state; in xpvtap_devmap() local
605 state = ddi_get_soft_state(xpvtap_statep, instance); in xpvtap_devmap()
606 if (state == NULL) { in xpvtap_devmap()
624 usring = &state->bt_user_ring; in xpvtap_devmap()
625 e = devmap_umem_setup(dhp, state->bt_dip, NULL, usring->ur_cookie, 0, in xpvtap_devmap()
646 xpvtap_state_t *state; in xpvtap_chpoll() local
654 state = ddi_get_soft_state(xpvtap_statep, instance); in xpvtap_chpoll()
655 if (state == NULL) { in xpvtap_chpoll()
668 usring = &state->bt_user_ring; in xpvtap_chpoll()
684 *phpp = &state->bt_pollhead; in xpvtap_chpoll()
697 xpvtap_state_t *state; in xpvtap_drv_init() local
705 state = ddi_get_soft_state(xpvtap_statep, instance); in xpvtap_drv_init()
706 if (state == NULL) { in xpvtap_drv_init()
710 state->bt_instance = instance; in xpvtap_drv_init()
711 mutex_init(&state->bt_open.bo_mutex, NULL, MUTEX_DRIVER, NULL); in xpvtap_drv_init()
712 cv_init(&state->bt_open.bo_exit_cv, NULL, CV_DRIVER, NULL); in xpvtap_drv_init()
713 state->bt_open.bo_opened = B_FALSE; in xpvtap_drv_init()
714 state->bt_map.um_registered = B_FALSE; in xpvtap_drv_init()
717 e = xpvtap_user_init(state); in xpvtap_drv_init()
722 return (state); in xpvtap_drv_init()
725 cv_destroy(&state->bt_open.bo_exit_cv); in xpvtap_drv_init()
726 mutex_destroy(&state->bt_open.bo_mutex); in xpvtap_drv_init()
737 xpvtap_drv_fini(xpvtap_state_t *state) in xpvtap_drv_fini() argument
739 xpvtap_user_fini(state); in xpvtap_drv_fini()
740 cv_destroy(&state->bt_open.bo_exit_cv); in xpvtap_drv_fini()
741 mutex_destroy(&state->bt_open.bo_mutex); in xpvtap_drv_fini()
742 (void) ddi_soft_state_free(xpvtap_statep, state->bt_instance); in xpvtap_drv_fini()
753 xpvtap_state_t *state; in xpvtap_intr() local
756 state = (xpvtap_state_t *)arg; in xpvtap_intr()
759 mutex_enter(&state->bt_thread.ut_mutex); in xpvtap_intr()
760 state->bt_thread.ut_wake = B_TRUE; in xpvtap_intr()
761 cv_signal(&state->bt_thread.ut_wake_cv); in xpvtap_intr()
762 mutex_exit(&state->bt_thread.ut_mutex); in xpvtap_intr()
772 xpvtap_segmf_register(xpvtap_state_t *state) in xpvtap_segmf_register() argument
782 as = state->bt_map.um_as; in xpvtap_segmf_register()
783 pgcnt = btopr(state->bt_map.um_guest_size); in xpvtap_segmf_register()
784 uaddr = state->bt_map.um_guest_pages; in xpvtap_segmf_register()
792 seg = as_findseg(as, state->bt_map.um_guest_pages, 0); in xpvtap_segmf_register()
793 if ((seg == NULL) || ((uaddr + state->bt_map.um_guest_size) > in xpvtap_segmf_register()
814 state->bt_map.um_registered = B_TRUE; in xpvtap_segmf_register()
830 xpvtap_state_t *state; in xpvtap_segmf_unregister() local
836 state = (xpvtap_state_t *)arg; in xpvtap_segmf_unregister()
837 if (!state->bt_map.um_registered) { in xpvtap_segmf_unregister()
843 pgcnt = btopr(state->bt_map.um_guest_size); in xpvtap_segmf_unregister()
844 uaddr = state->bt_map.um_guest_pages; in xpvtap_segmf_unregister()
847 xpvtap_rs_flush(state->bt_map.um_rs, xpvtap_user_request_unmap, state); in xpvtap_segmf_unregister()
862 state->bt_map.um_registered = B_FALSE; in xpvtap_segmf_unregister()
870 xpvtap_user_init(xpvtap_state_t *state) in xpvtap_user_init() argument
876 map = &state->bt_map; in xpvtap_user_init()
879 e = xpvtap_user_ring_init(state); in xpvtap_user_init()
906 e = xpvtap_user_thread_init(state); in xpvtap_user_init()
917 xpvtap_user_ring_fini(state); in xpvtap_user_init()
926 xpvtap_user_ring_init(xpvtap_state_t *state) in xpvtap_user_ring_init() argument
931 usring = &state->bt_user_ring; in xpvtap_user_ring_init()
948 xpvtap_user_thread_init(xpvtap_state_t *state) in xpvtap_user_thread_init() argument
954 thread = &state->bt_thread; in xpvtap_user_thread_init()
964 (void) sprintf(taskqname, "xvptap_%d", state->bt_instance); in xpvtap_user_thread_init()
965 thread->ut_taskq = ddi_taskq_create(state->bt_dip, taskqname, 1, in xpvtap_user_thread_init()
991 xpvtap_state_t *state; in xpvtap_user_thread_start() local
995 state = (xpvtap_state_t *)arg; in xpvtap_user_thread_start()
996 thread = &state->bt_thread; in xpvtap_user_thread_start()
1000 e = ddi_taskq_dispatch(thread->ut_taskq, xpvtap_user_thread, state, in xpvtap_user_thread_start()
1013 xpvtap_user_thread_stop(xpvtap_state_t *state) in xpvtap_user_thread_stop() argument
1016 mutex_enter(&state->bt_thread.ut_mutex); in xpvtap_user_thread_stop()
1017 state->bt_thread.ut_wake = B_TRUE; in xpvtap_user_thread_stop()
1018 state->bt_thread.ut_exit = B_TRUE; in xpvtap_user_thread_stop()
1019 cv_signal(&state->bt_thread.ut_wake_cv); in xpvtap_user_thread_stop()
1020 if (!state->bt_thread.ut_exit_done) { in xpvtap_user_thread_stop()
1021 cv_wait(&state->bt_thread.ut_exit_done_cv, in xpvtap_user_thread_stop()
1022 &state->bt_thread.ut_mutex); in xpvtap_user_thread_stop()
1024 mutex_exit(&state->bt_thread.ut_mutex); in xpvtap_user_thread_stop()
1025 ASSERT(state->bt_thread.ut_exit_done); in xpvtap_user_thread_stop()
1033 xpvtap_user_fini(xpvtap_state_t *state) in xpvtap_user_fini() argument
1038 map = &state->bt_map; in xpvtap_user_fini()
1040 xpvtap_user_thread_fini(state); in xpvtap_user_fini()
1044 xpvtap_user_ring_fini(state); in xpvtap_user_fini()
1052 xpvtap_user_ring_fini(xpvtap_state_t *state) in xpvtap_user_ring_fini() argument
1054 ddi_umem_free(state->bt_user_ring.ur_cookie); in xpvtap_user_ring_fini()
1062 xpvtap_user_thread_fini(xpvtap_state_t *state) in xpvtap_user_thread_fini() argument
1064 ddi_taskq_destroy(state->bt_thread.ut_taskq); in xpvtap_user_thread_fini()
1065 cv_destroy(&state->bt_thread.ut_exit_done_cv); in xpvtap_user_thread_fini()
1066 cv_destroy(&state->bt_thread.ut_wake_cv); in xpvtap_user_thread_fini()
1067 mutex_destroy(&state->bt_thread.ut_mutex); in xpvtap_user_thread_fini()
1079 xpvtap_state_t *state; in xpvtap_user_thread() local
1086 state = (xpvtap_state_t *)arg; in xpvtap_user_thread()
1087 thread = &state->bt_thread; in xpvtap_user_thread()
1094 cv_signal(&state->bt_thread.ut_exit_done_cv); in xpvtap_user_thread()
1128 e = blk_ring_request_get(state->bt_guest_ring, &req); in xpvtap_user_thread()
1134 e = xpvtap_user_request_map(state, &req, &uid); in xpvtap_user_thread()
1141 blk_ring_request_requeue(state->bt_guest_ring); in xpvtap_user_thread()
1146 e = xpvtap_user_request_push(state, &req, uid); in xpvtap_user_thread()
1151 blk_ring_response_put(state->bt_guest_ring, &resp); in xpvtap_user_thread()
1161 b = xpvtap_user_response_get(state, &resp, &uid); in xpvtap_user_thread()
1170 xpvtap_user_request_unmap(state, uid); in xpvtap_user_thread()
1173 blk_ring_response_put(state->bt_guest_ring, &resp); in xpvtap_user_thread()
1184 xpvtap_user_request_map(xpvtap_state_t *state, blkif_request_t *req, in xpvtap_user_request_map() argument
1197 domid = xvdi_get_oeid(state->bt_dip); in xpvtap_user_request_map()
1199 as = state->bt_map.um_as; in xpvtap_user_request_map()
1200 if ((as == NULL) || (state->bt_map.um_guest_pages == NULL)) { in xpvtap_user_request_map()
1205 if (!state->bt_map.um_registered) { in xpvtap_user_request_map()
1207 e = xpvtap_segmf_register(state); in xpvtap_user_request_map()
1214 e = xpvtap_rs_alloc(state->bt_map.um_rs, uid); in xpvtap_user_request_map()
1227 uaddr = XPVTAP_GREF_REQADDR(state->bt_map.um_guest_pages, *uid); in xpvtap_user_request_map()
1230 seg = as_findseg(as, state->bt_map.um_guest_pages, 0); in xpvtap_user_request_map()
1260 xpvtap_user_request_push(xpvtap_state_t *state, blkif_request_t *req, in xpvtap_user_request_push() argument
1269 uring = &state->bt_user_ring.ur_ring; in xpvtap_user_request_push()
1270 map = &state->bt_map; in xpvtap_user_request_push()
1286 pollwakeup(&state->bt_pollhead, POLLIN | POLLRDNORM); in xpvtap_user_request_push()
1293 xpvtap_user_request_unmap(xpvtap_state_t *state, uint_t uid) in xpvtap_user_request_unmap() argument
1302 as = state->bt_map.um_as; in xpvtap_user_request_unmap()
1308 req = &state->bt_map.um_outstanding_reqs[uid]; in xpvtap_user_request_unmap()
1314 uaddr = XPVTAP_GREF_REQADDR(state->bt_map.um_guest_pages, uid); in xpvtap_user_request_unmap()
1316 seg = as_findseg(as, state->bt_map.um_guest_pages, 0); in xpvtap_user_request_unmap()
1320 xpvtap_rs_free(state->bt_map.um_rs, uid); in xpvtap_user_request_unmap()
1333 xpvtap_rs_free(state->bt_map.um_rs, uid); in xpvtap_user_request_unmap()
1338 xpvtap_user_response_get(xpvtap_state_t *state, blkif_response_t *resp, in xpvtap_user_response_get() argument
1345 uring = &state->bt_user_ring.ur_ring; in xpvtap_user_response_get()
1363 resp->id = state->bt_map.um_outstanding_reqs[*uid].id; in xpvtap_user_response_get()
1374 xpvtap_state_t *state; in xpvtap_user_app_stop() local
1377 state = (xpvtap_state_t *)arg; in xpvtap_user_app_stop()
1383 mutex_enter(&state->bt_open.bo_mutex); in xpvtap_user_app_stop()
1384 if (state->bt_open.bo_opened) { in xpvtap_user_app_stop()
1385 rc = cv_reltimedwait(&state->bt_open.bo_exit_cv, in xpvtap_user_app_stop()
1386 &state->bt_open.bo_mutex, drv_usectohz(10000000), in xpvtap_user_app_stop()
1393 mutex_exit(&state->bt_open.bo_mutex); in xpvtap_user_app_stop()