5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27
28 #include <sys/errno.h>
29 #include <sys/types.h>
30 #include <sys/conf.h>
31 #include <sys/kmem.h>
32 #include <sys/ddi.h>
33 #include <sys/stat.h>
34 #include <sys/sunddi.h>
35 #include <sys/file.h>
36 #include <sys/open.h>
37 #include <sys/modctl.h>
38 #include <sys/ddi_impldefs.h>
39 #include <sys/sysmacros.h>
40 #include <sys/ddidevmap.h>
41 #include <sys/policy.h>
42
43 #include <sys/vmsystm.h>
44 #include <vm/hat_i86.h>
639 */
640 static int
641 xpvtap_chpoll(dev_t dev, short events, int anyyet, short *reventsp,
642 struct pollhead **phpp)
643 {
644 xpvtap_user_ring_t *usring;
645 xpvtap_state_t *state;
646 int instance;
647
648
649 instance = getminor(dev);
650 if (instance == -1) {
651 return (EBADF);
652 }
653 state = ddi_get_soft_state(xpvtap_statep, instance);
654 if (state == NULL) {
655 return (EBADF);
656 }
657
658 if (((events & (POLLIN | POLLRDNORM)) == 0) && !anyyet) {
659 *reventsp = 0;
660 return (EINVAL);
661 }
662
663 /*
664 * if we pushed requests on the user ring since the last poll, wakeup
665 * the user app
666 */
667 usring = &state->bt_user_ring;
668 if (usring->ur_prod_polled != usring->ur_ring.req_prod_pvt) {
669
670 /*
671 * XXX - is this faster here or xpvtap_user_request_push??
672 * prelim data says here. Because less membars or because
673 * user thread will spin in poll requests before getting to
674 * responses?
675 */
676 RING_PUSH_REQUESTS(&usring->ur_ring);
677
678 usring->ur_prod_polled = usring->ur_ring.sring->req_prod;
679 *reventsp = POLLIN | POLLRDNORM;
680
681 /* no new requests */
682 } else {
683 *reventsp = 0;
684 if (!anyyet) {
685 *phpp = &state->bt_pollhead;
686 }
687 }
688
689 return (0);
690 }
691
692
693 /*
694 * xpvtap_drv_init()
695 */
696 static xpvtap_state_t *
697 xpvtap_drv_init(int instance)
698 {
699 xpvtap_state_t *state;
700 int e;
701
702
703 e = ddi_soft_state_zalloc(xpvtap_statep, instance);
704 if (e != DDI_SUCCESS) {
705 return (NULL);
706 }
707 state = ddi_get_soft_state(xpvtap_statep, instance);
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2017 Joyent, Inc.
26 */
27
28
29 #include <sys/errno.h>
30 #include <sys/types.h>
31 #include <sys/conf.h>
32 #include <sys/kmem.h>
33 #include <sys/ddi.h>
34 #include <sys/stat.h>
35 #include <sys/sunddi.h>
36 #include <sys/file.h>
37 #include <sys/open.h>
38 #include <sys/modctl.h>
39 #include <sys/ddi_impldefs.h>
40 #include <sys/sysmacros.h>
41 #include <sys/ddidevmap.h>
42 #include <sys/policy.h>
43
44 #include <sys/vmsystm.h>
45 #include <vm/hat_i86.h>
640 */
641 static int
642 xpvtap_chpoll(dev_t dev, short events, int anyyet, short *reventsp,
643 struct pollhead **phpp)
644 {
645 xpvtap_user_ring_t *usring;
646 xpvtap_state_t *state;
647 int instance;
648
649
650 instance = getminor(dev);
651 if (instance == -1) {
652 return (EBADF);
653 }
654 state = ddi_get_soft_state(xpvtap_statep, instance);
655 if (state == NULL) {
656 return (EBADF);
657 }
658
659 if (((events & (POLLIN | POLLRDNORM)) == 0) && !anyyet) {
660 return (EINVAL);
661 }
662
663 /*
664 * if we pushed requests on the user ring since the last poll, wakeup
665 * the user app
666 */
667 *reventsp = 0;
668 usring = &state->bt_user_ring;
669 if (usring->ur_prod_polled != usring->ur_ring.req_prod_pvt) {
670
671 /*
672 * XXX - is this faster here or xpvtap_user_request_push??
673 * prelim data says here. Because less membars or because
674 * user thread will spin in poll requests before getting to
675 * responses?
676 */
677 RING_PUSH_REQUESTS(&usring->ur_ring);
678
679 usring->ur_prod_polled = usring->ur_ring.sring->req_prod;
680 *reventsp = POLLIN | POLLRDNORM;
681 }
682
683 if ((*reventsp == 0 && !anyyet) || (events & POLLET)) {
684 *phpp = &state->bt_pollhead;
685 }
686
687 return (0);
688 }
689
690
691 /*
692 * xpvtap_drv_init()
693 */
694 static xpvtap_state_t *
695 xpvtap_drv_init(int instance)
696 {
697 xpvtap_state_t *state;
698 int e;
699
700
701 e = ddi_soft_state_zalloc(xpvtap_statep, instance);
702 if (e != DDI_SUCCESS) {
703 return (NULL);
704 }
705 state = ddi_get_soft_state(xpvtap_statep, instance);
|