Lines Matching defs:tp

166  * Returns with tp locked (if found).
171 struct tun_softc *tp;
175 LIST_FOREACH(tp, &tun_softc_list, tun_list)
176 if (unit == tp->tun_unit)
178 if (tp)
179 mutex_enter(&tp->tun_lock);
182 return tp;
187 * Remove tp from list and return it unlocked (if found).
192 struct tun_softc *tp;
195 LIST_FOREACH(tp, &tunz_softc_list, tun_list)
196 if (unit == tp->tun_unit)
198 if (tp)
199 LIST_REMOVE(tp, tun_list);
201 KASSERTMSG(!tp || (tp->tun_flags & (TUN_INITED|TUN_OPEN)) == TUN_OPEN,
202 "tun%d: inconsistent flags: %x", unit, tp->tun_flags);
204 return tp;
208 tun_init(struct tun_softc *tp, int unit)
211 tp->tun_unit = unit;
212 mutex_init(&tp->tun_lock, MUTEX_DEFAULT, IPL_SOFTNET);
213 cv_init(&tp->tun_cv, "tunread");
214 selinit(&tp->tun_rsel);
215 selinit(&tp->tun_wsel);
217 tp->tun_osih = softint_establish(SOFTINT_CLOCK, tun_o_softintr, tp);
218 tp->tun_isih = softint_establish(SOFTINT_CLOCK, tun_i_softintr, tp);
222 tun_fini(struct tun_softc *tp)
225 softint_disestablish(tp->tun_isih);
226 softint_disestablish(tp->tun_osih);
228 seldestroy(&tp->tun_wsel);
229 seldestroy(&tp->tun_rsel);
230 mutex_destroy(&tp->tun_lock);
231 cv_destroy(&tp->tun_cv);
237 struct tun_softc *tp;
239 tp = kmem_zalloc(sizeof(*tp), KM_SLEEP);
240 tun_init(tp, unit);
242 return tp;
246 tun_recycle(struct tun_softc *tp)
249 memset(&tp->tun_if, 0, sizeof(struct ifnet)); /* XXX ??? */
253 tun_free(struct tun_softc *tp)
256 tun_fini(tp);
257 kmem_free(tp, sizeof(*tp));
263 struct tun_softc *tp;
265 if ((tp = tun_find_zunit(unit)) == NULL) {
266 tp = tun_alloc(unit);
268 tun_recycle(tp);
271 if_initname(&tp->tun_if, ifc->ifc_name, unit);
272 tunattach0(tp);
273 tp->tun_flags |= TUN_INITED;
276 LIST_INSERT_HEAD(&tun_softc_list, tp, tun_list);
283 tunattach0(struct tun_softc *tp)
287 ifp = &tp->tun_if;
288 ifp->if_softc = tp;
309 struct tun_softc *tp = (void *)ifp;
316 mutex_enter(&tp->tun_lock);
317 LIST_REMOVE(tp, tun_list);
318 if (tp->tun_flags & TUN_OPEN) {
320 tp->tun_flags &= ~TUN_INITED;
321 LIST_INSERT_HEAD(&tunz_softc_list, tp, tun_list);
326 cv_broadcast(&tp->tun_cv);
327 if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid)
328 fownsignal(tp->tun_pgid, SIGIO, POLL_HUP, 0, NULL);
329 selnotify(&tp->tun_rsel, 0, NOTE_SUBMIT);
330 mutex_exit(&tp->tun_lock);
336 tun_free(tp);
350 struct tun_softc *tp;
358 tp = tun_find_unit(dev);
360 if (tp == NULL) {
362 tp = tun_find_unit(dev);
363 if (tp == NULL) {
368 if (tp->tun_flags & TUN_OPEN) {
369 mutex_exit(&tp->tun_lock);
373 ifp = &tp->tun_if;
374 tp->tun_flags |= TUN_OPEN;
378 mutex_exit(&tp->tun_lock);
391 struct tun_softc *tp;
394 if ((tp = tun_find_zunit(minor(dev))) != NULL) {
396 tun_free(tp);
400 if ((tp = tun_find_unit(dev)) == NULL)
403 ifp = &tp->tun_if;
405 tp->tun_flags &= ~TUN_OPEN;
407 tp->tun_pgid = 0;
408 selnotify(&tp->tun_rsel, 0, NOTE_SUBMIT);
411 mutex_exit(&tp->tun_lock);
428 tp->tun_flags & TUN_DSTADDR
444 tun_enable(struct tun_softc *tp, const struct ifaddr *ifa)
446 struct ifnet *ifp = &tp->tun_if;
450 mutex_enter(&tp->tun_lock);
451 tp->tun_flags &= ~(TUN_IASET|TUN_DSTADDR);
460 tp->tun_flags |= TUN_IASET;
465 tp->tun_flags |= TUN_DSTADDR;
476 tp->tun_flags |= TUN_IASET;
481 tp->tun_flags |= TUN_DSTADDR;
483 tp->tun_flags &= ~TUN_DSTADDR;
491 mutex_exit(&tp->tun_lock);
500 struct tun_softc *tp = (struct tun_softc *)(ifp->if_softc);
507 tun_enable(tp, ifa);
557 struct tun_softc *tp = ifp->if_softc;
564 mutex_enter(&tp->tun_lock);
567 if ((tp->tun_flags & TUN_READY) != TUN_READY) {
569 tp->tun_flags);
571 mutex_exit(&tp->tun_lock);
575 mutex_exit(&tp->tun_lock);
598 if (tp->tun_flags & TUN_PREPADDR) {
607 } else if (tp->tun_flags & TUN_IFHEAD) {
644 mutex_enter(&tp->tun_lock);
645 cv_broadcast(&tp->tun_cv);
646 if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid)
647 softint_schedule(tp->tun_isih);
648 selnotify(&tp->tun_rsel, 0, NOTE_SUBMIT);
649 mutex_exit(&tp->tun_lock);
660 struct tun_softc *tp = cookie;
662 if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid)
663 fownsignal(tp->tun_pgid, SIGIO, POLL_IN, POLLIN|POLLRDNORM,
670 struct tun_softc *tp = cookie;
672 if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid)
673 fownsignal(tp->tun_pgid, SIGIO, POLL_OUT, POLLOUT|POLLWRNORM,
683 struct tun_softc *tp;
686 tp = tun_find_unit(dev);
689 if (tp == NULL) {
706 if (tp->tun_if.if_flags & IFF_UP) {
710 tp->tun_if.if_flags &=
712 tp->tun_if.if_flags |= *(int *)data;
722 tp->tun_flags |= TUN_PREPADDR;
723 tp->tun_flags &= ~TUN_IFHEAD;
725 tp->tun_flags &= ~TUN_PREPADDR;
730 tp->tun_flags |= TUN_IFHEAD;
731 tp->tun_flags &= ~TUN_PREPADDR;
733 tp->tun_flags &= ~TUN_IFHEAD;
737 *(int *)data = (tp->tun_flags & TUN_IFHEAD);
742 tp->tun_flags |= TUN_NBIO;
744 tp->tun_flags &= ~TUN_NBIO;
749 tp->tun_flags |= TUN_ASYNC;
751 tp->tun_flags &= ~TUN_ASYNC;
755 if (tp->tun_if.if_snd.ifq_head)
756 *(int *)data = tp->tun_if.if_snd.ifq_head->m_pkthdr.len;
763 error = fsetown(&tp->tun_pgid, cmd, data);
768 error = fgetown(tp->tun_pgid, cmd, data);
776 mutex_exit(&tp->tun_lock);
788 struct tun_softc *tp;
793 tp = tun_find_unit(dev);
796 if (tp == NULL) {
800 ifp = &tp->tun_if;
803 if ((tp->tun_flags & TUN_READY) != TUN_READY) {
804 TUNDEBUG ("%s: not ready 0%o\n", ifp->if_xname, tp->tun_flags);
812 if (tp->tun_flags & TUN_NBIO) {
816 if (cv_wait_sig(&tp->tun_cv, &tp->tun_lock)) {
823 mutex_exit(&tp->tun_lock);
843 mutex_exit(&tp->tun_lock);
854 struct tun_softc *tp;
862 tp = tun_find_unit(dev);
863 if (tp == NULL) {
869 mutex_exit(&tp->tun_lock);
871 ifp = &tp->tun_if;
875 if (tp->tun_flags & TUN_PREPADDR) {
894 } else if (tp->tun_flags & TUN_IFHEAD) {
974 mutex_enter(&tp->tun_lock);
975 if ((tp->tun_flags & TUN_INITED) == 0) {
984 mutex_exit(&tp->tun_lock);
992 mutex_exit(&tp->tun_lock);
1007 struct tun_softc *tp = ifp->if_softc;
1012 mutex_enter(&tp->tun_lock);
1014 cv_broadcast(&tp->tun_cv);
1015 if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid)
1016 softint_schedule(tp->tun_osih);
1018 selnotify(&tp->tun_rsel, 0, NOTE_SUBMIT);
1020 mutex_exit(&tp->tun_lock);
1031 struct tun_softc *tp;
1035 tp = tun_find_unit(dev);
1036 if (tp == NULL) {
1040 ifp = &tp->tun_if;
1051 selrecord(l, &tp->tun_rsel);
1058 mutex_exit(&tp->tun_lock);
1066 struct tun_softc *tp = kn->kn_hook;
1068 mutex_enter(&tp->tun_lock);
1069 selremove_knote(&tp->tun_rsel, kn);
1070 mutex_exit(&tp->tun_lock);
1076 struct tun_softc *tp = kn->kn_hook;
1077 struct ifnet *ifp = &tp->tun_if;
1082 KASSERT(mutex_owned(&tp->tun_lock));
1084 mutex_enter(&tp->tun_lock);
1092 KASSERT(mutex_owned(&tp->tun_lock));
1094 mutex_exit(&tp->tun_lock);
1109 struct tun_softc *tp;
1112 tp = tun_find_unit(dev);
1113 if (tp == NULL)
1119 kn->kn_hook = tp;
1120 selrecord_knote(&tp->tun_rsel, kn);
1133 mutex_exit(&tp->tun_lock);