/*---------------------------------------------------------------------------* * i4bread - device driver read routine *---------------------------------------------------------------------------*/ PDEVSTATIC int i4bread(dev_t dev, struct uio *uio, int ioflag) { struct mbuf *m; int x; int error = 0; if(minor(dev)) return(ENODEV); while(IF_QEMPTY(&i4b_rdqueue)) { x = splimp(); readflag = 1; splx(x); tsleep((caddr_t) &i4b_rdqueue, (PZERO + 1) | PCATCH, "bird", 0); } x = splimp(); IF_DEQUEUE(&i4b_rdqueue, m); splx(x); if(m && m->m_len) error = uiomove(m->m_data, m->m_len, uio); else error = EIO; if(m) i4b_Dfreembuf(m); return(error); }
static void fwe_start(struct ifnet *ifp) { struct fwe_softc *fwe = ((struct fwe_eth_softc *)ifp->if_softc)->fwe; int s; FWEDEBUG(ifp, "starting\n"); if (fwe->dma_ch < 0) { struct mbuf *m = NULL; FWEDEBUG(ifp, "not ready\n"); s = splimp(); do { IF_DEQUEUE(&ifp->if_snd, m); if (m != NULL) m_freem(m); if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); } while (m != NULL); splx(s); return; } s = splimp(); ifp->if_drv_flags |= IFF_DRV_OACTIVE; if (ifp->if_snd.ifq_len != 0) fwe_as_output(fwe, ifp); ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; splx(s); }
static int fwe_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) { struct fwe_softc *fwe = ((struct fwe_eth_softc *)ifp->if_softc)->fwe; struct ifstat *ifs = NULL; int s, error, len; switch (cmd) { case SIOCSIFFLAGS: s = splimp(); if (ifp->if_flags & IFF_UP) { if (!(ifp->if_flags & IFF_RUNNING)) fwe_init(&fwe->eth_softc); } else { if (ifp->if_flags & IFF_RUNNING) fwe_stop(fwe); } /* XXX keep promiscoud mode */ ifp->if_flags |= IFF_PROMISC; splx(s); break; case SIOCADDMULTI: case SIOCDELMULTI: break; case SIOCGIFSTATUS: s = splimp(); ifs = (struct ifstat *)data; len = strlen(ifs->ascii); if (len < sizeof(ifs->ascii)) snprintf(ifs->ascii + len, sizeof(ifs->ascii) - len, "\tch %d dma %d\n", fwe->stream_ch, fwe->dma_ch); splx(s); break; #if __FreeBSD_version >= 500000 default: #else case SIOCSIFADDR: case SIOCGIFADDR: case SIOCSIFMTU: #endif s = splimp(); error = ether_ioctl(ifp, cmd, data); splx(s); return (error); #if __FreeBSD_version < 500000 default: return (EINVAL); #endif } return (0); }
static int nsmb_dev_open(struct cdev *dev, int oflags, int devtype, struct thread *td) { struct smb_dev *sdp; struct ucred *cred = td->td_ucred; int s; sdp = SMB_GETDEV(dev); if (sdp && (sdp->sd_flags & NSMBFL_OPEN)) return EBUSY; if (sdp == NULL) { sdp = malloc(sizeof(*sdp), M_NSMBDEV, M_WAITOK); dev->si_drv1 = (void*)sdp; } /* * XXX: this is just crazy - make a device for an already passed device... * someone should take care of it. */ if ((dev->si_flags & SI_NAMED) == 0) make_dev(&nsmb_cdevsw, dev2unit(dev), cred->cr_uid, cred->cr_gid, 0700, NSMB_NAME"%d", dev2unit(dev)); bzero(sdp, sizeof(*sdp)); /* STAILQ_INIT(&sdp->sd_rqlist); STAILQ_INIT(&sdp->sd_rplist); bzero(&sdp->sd_pollinfo, sizeof(struct selinfo)); */ s = splimp(); sdp->sd_level = -1; sdp->sd_flags |= NSMBFL_OPEN; splx(s); return 0; }
/* ======================================================================== Routine Description: Compare two memory block Arguments: Adapter Pointer to our adapter Return Value: 0: memory is equal 1: pSrc1 memory is larger 2: pSrc2 memory is larger Note: ======================================================================== */ void dot1xintr() { //diag_printf("dot1xintr\n"); register struct mbuf *m; struct ifnet *ifp; int s; unsigned char *packet; int len; while (dot1xintrq.ifq_head) { s = splimp(); IF_DEQUEUE(&dot1xintrq, m); splx(s); if (m == 0 || (m->m_flags & M_PKTHDR) == 0) panic("dot1xintr"); packet = m->m_data-14;//br may change something like ATE len = m->m_len+14; DBGPRINT(RT_DEBUG_WARN, "%s :Receive SA (%02x:%02x:%02x:%02x:%02x:%02x)\n",__FUNCTION__,MAC2STR(packet));//PRINTF SA DBGPRINT(RT_DEBUG_WARN, "%s :Receive DA (%02x:%02x:%02x:%02x:%02x:%02x)\n",__FUNCTION__,MAC2STR(packet+6));//PRINTF DA //hex_dump("dot1xintr ===",packet,len); ifp = m->m_pkthdr.rcvif; Dot1xNetReceive(ifp, packet, len); m_freem(m); } }
/*---------------------------------------------------------------------------* * i4bpoll - device driver poll routine *---------------------------------------------------------------------------*/ PDEVSTATIC int i4bpoll(dev_t dev, int events, struct proc *p) { int x; if(minor(dev)) return(ENODEV); if((events & POLLIN) || (events & POLLRDNORM)) { if(!IF_QEMPTY(&i4b_rdqueue)) return(1); x = splimp(); selrecord(p, &select_rd_info); selflag = 1; splx(x); return(0); } else if((events & POLLOUT) || (events & POLLWRNORM)) { return(1); } return(0); }
/*---------------------------------------------------------------------------* * i4bselect - device driver select routine *---------------------------------------------------------------------------*/ PDEVSTATIC int i4bselect(dev_t dev, int rw, struct proc *p) { int x; if(minor(dev)) return(ENODEV); switch(rw) { case FREAD: if(!IF_QEMPTY(&i4b_rdqueue)) return(1); x = splimp(); selrecord(p, &select_rd_info); selflag = 1; splx(x); return(0); break; case FWRITE: return(1); break; } return(0); }
static int fwip_detach(device_t dev) { struct fwip_softc *fwip; struct ifnet *ifp; int s; fwip = (struct fwip_softc *)device_get_softc(dev); ifp = fwip->fw_softc.fwip_ifp; #ifdef DEVICE_POLLING if (ifp->if_capenable & IFCAP_POLLING) ether_poll_deregister(ifp); #endif s = splimp(); fwip_stop(fwip); firewire_ifdetach(ifp); if_free(ifp); mtx_destroy(&fwip->mtx); splx(s); return 0; }
static int fwe_detach(device_t dev) { struct fwe_softc *fwe; struct ifnet *ifp; int s; fwe = device_get_softc(dev); ifp = fwe->eth_softc.ifp; #ifdef DEVICE_POLLING if (ifp->if_capenable & IFCAP_POLLING) ether_poll_deregister(ifp); #endif s = splimp(); fwe_stop(fwe); #if defined(__DragonFly__) || __FreeBSD_version < 500000 ether_ifdetach(ifp, 1); #else ether_ifdetach(ifp); if_free(ifp); #endif splx(s); mtx_destroy(&fwe->mtx); return 0; }
static void fwe_output_callback(struct fw_xfer *xfer) { struct fwe_softc *fwe; struct ifnet *ifp; int s; fwe = (struct fwe_softc *)xfer->sc; ifp = fwe->eth_softc.ifp; /* XXX error check */ FWEDEBUG(ifp, "resp = %d\n", xfer->resp); if (xfer->resp != 0) ifp->if_oerrors ++; m_freem(xfer->mbuf); fw_xfer_unload(xfer); s = splimp(); FWE_LOCK(fwe); STAILQ_INSERT_TAIL(&fwe->xferlist, xfer, link); FWE_UNLOCK(fwe); splx(s); /* for queue full */ if (ifp->if_snd.ifq_head != NULL) fwe_start(ifp); }
static int nsmb_dev_close(struct cdev *dev, int flag, int fmt, struct thread *td) { struct smb_dev *sdp; struct smb_vc *vcp; struct smb_share *ssp; struct smb_cred *scred; int s; scred = malloc(sizeof(struct smb_cred), M_NSMBDEV, M_WAITOK); SMB_CHECKMINOR(dev); s = splimp(); if ((sdp->sd_flags & NSMBFL_OPEN) == 0) { splx(s); free(scred, M_NSMBDEV); return EBADF; } smb_makescred(scred, td, NULL); ssp = sdp->sd_share; if (ssp != NULL) smb_share_rele(ssp, scred); vcp = sdp->sd_vc; if (vcp != NULL) smb_vc_rele(vcp, scred); /* smb_flushq(&sdp->sd_rqlist); smb_flushq(&sdp->sd_rplist); */ dev->si_drv1 = NULL; free(sdp, M_NSMBDEV); destroy_dev_sched(dev); splx(s); free(scred, M_NSMBDEV); return 0; }
/* * Start output on the pflog interface. */ void pflogstart(struct ifnet *ifp) { struct mbuf *m; #ifndef __FreeBSD__ int s; #endif for (;;) { #ifdef __FreeBSD__ IF_LOCK(&ifp->if_snd); _IF_DROP(&ifp->if_snd); _IF_DEQUEUE(&ifp->if_snd, m); if (m == NULL) { IF_UNLOCK(&ifp->if_snd); return; } else m_freem(m); IF_UNLOCK(&ifp->if_snd); #else s = splimp(); IF_DROP(&ifp->if_snd); IF_DEQUEUE(&ifp->if_snd, m); splx(s); if (m == NULL) return; else m_freem(m); #endif } }
int pptp_ctrlconn_disconnect(PPTP_INFO *pInfo) { struct pptp_ctrl_conn *ctrl_conn = pInfo->ctrl_conn; int s; if (!pInfo->ctrl_conn) return 0; s = splimp(); pptp_ctrlconn_stop(pInfo, PPTP_SCCR_REAS_LOCAL); if (ctrl_conn->call) pptp_ctrlconn_call_release(pInfo); if (ctrl_conn) { free(ctrl_conn); pInfo->ctrl_conn = NULL; } if (pInfo->ctrl_sock != -1) { close(pInfo->ctrl_sock); pInfo->ctrl_sock = -1; } pptp_timer_stop(pInfo); splx(s); return 0; }
Static void udbp_in_transfer_cb(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status err) { udbp_p sc = priv; /* XXX see priv above */ int s; int len; struct mbuf *m; if (err) { if (err != USBD_CANCELLED) { DPRINTF(("%s: bulk-out transfer failed: %s\n", USBDEVNAME(sc->sc_dev), usbd_errstr(err))); } else { /* USBD_CANCELLED happens at unload of the driver */ return; } /* Transfer has failed, packet is not received */ } else { len = xfer->actlen; s = splimp(); /* block network stuff too */ if (sc->hook) { /* get packet from device and send on */ m = m_devget(sc->sc_bulkin_buffer, len, 0, NULL, NULL); NG_SEND_DATA_ONLY(err, sc->hook, m); } splx(s); } /* schedule the next in transfer */ udbp_setup_in_transfer(sc); }
/* * Pass some notification to all connections of a protocol * associated with address dst. Call the * protocol specific routine to handle each connection. * Also pass an extra paramter via the lpxpcb. (which may in fact * be a parameter list!) */ void Lpx_PCB_notify( register struct lpx_addr *dst, int errno, void (*notify)(struct lpxpcb *), long param ) { register struct lpxpcb *lpxp, *oinp; int s = splimp(); for (lpxp = (&lpxpcb)->lpxp_next; lpxp != (&lpxpcb);) { if (!lpx_hosteq(*dst,lpxp->lpxp_faddr)) { next: lpxp = lpxp->lpxp_next; continue; } if (lpxp->lpxp_socket == 0) goto next; if (errno) lpxp->lpxp_socket->so_error = errno; oinp = lpxp; lpxp = lpxp->lpxp_next; oinp->lpxp_notify_param = param; (*notify)(oinp); } splx(s); }
static void iereset(struct ie_softc *sc) { int s = splimp(); printf("ie%d: reset\n", sc->unit); sc->arpcom.ac_if.if_flags &= ~IFF_UP; ieioctl(&sc->arpcom.ac_if, SIOCSIFFLAGS, 0); /* * Stop i82586 dead in its tracks. */ if (command_and_wait(sc, IE_RU_ABORT | IE_CU_ABORT, 0, 0)) printf("ie%d: abort commands timed out\n", sc->unit); if (command_and_wait(sc, IE_RU_DISABLE | IE_CU_STOP, 0, 0)) printf("ie%d: disable commands timed out\n", sc->unit); #ifdef notdef if (!check_ie_present(sc)) panic("ie disappeared!"); #endif sc->arpcom.ac_if.if_flags |= IFF_UP; ieioctl(&sc->arpcom.ac_if, SIOCSIFFLAGS, 0); splx(s); return; }
/* * tunclose - close the device - mark i/f down & delete * routing info */ static int tunclose(struct cdev *dev, int foo, int bar, struct thread *td) { struct tun_softc *tp; struct ifnet *ifp; int s; tp = dev->si_drv1; ifp = &tp->tun_if; mtx_lock(&tp->tun_mtx); tp->tun_flags &= ~TUN_OPEN; tp->tun_pid = 0; /* * junk all pending output */ s = splimp(); IFQ_PURGE(&ifp->if_snd); splx(s); mtx_unlock(&tp->tun_mtx); if (ifp->if_flags & IFF_UP) { s = splimp(); if_down(ifp); splx(s); } if (ifp->if_flags & IFF_RUNNING) { struct ifaddr *ifa; s = splimp(); /* find internet addresses and delete routes */ TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) if (ifa->ifa_addr->sa_family == AF_INET) /* Unlocked read. */ rtinit(ifa, (int)RTM_DELETE, tp->tun_flags & TUN_DSTADDR ? RTF_HOST : 0); ifp->if_flags &= ~IFF_RUNNING; splx(s); } funsetown(&tp->tun_sigio); selwakeuppri(&tp->tun_rsel, PZERO + 1); TUNDEBUG (ifp, "closed\n"); return (0); }
static int fwip_attach(device_t dev) { struct fwip_softc *fwip; struct ifnet *ifp; int unit, s; struct fw_hwaddr *hwaddr; fwip = ((struct fwip_softc *)device_get_softc(dev)); unit = device_get_unit(dev); ifp = fwip->fw_softc.fwip_ifp = if_alloc(IFT_IEEE1394); if (ifp == NULL) return (ENOSPC); mtx_init(&fwip->mtx, "fwip", NULL, MTX_DEF); /* XXX */ fwip->dma_ch = -1; fwip->fd.fc = device_get_ivars(dev); if (tx_speed < 0) tx_speed = fwip->fd.fc->speed; fwip->fd.dev = dev; fwip->fd.post_explore = NULL; fwip->fd.post_busreset = fwip_post_busreset; fwip->fw_softc.fwip = fwip; TASK_INIT(&fwip->start_send, 0, fwip_start_send, fwip); /* * Encode our hardware the way that arp likes it. */ hwaddr = &IFP2FWC(fwip->fw_softc.fwip_ifp)->fc_hwaddr; hwaddr->sender_unique_ID_hi = htonl(fwip->fd.fc->eui.hi); hwaddr->sender_unique_ID_lo = htonl(fwip->fd.fc->eui.lo); hwaddr->sender_max_rec = fwip->fd.fc->maxrec; hwaddr->sspd = fwip->fd.fc->speed; hwaddr->sender_unicast_FIFO_hi = htons((uint16_t)(INET_FIFO >> 32)); hwaddr->sender_unicast_FIFO_lo = htonl((uint32_t)INET_FIFO); /* fill the rest and attach interface */ ifp->if_softc = &fwip->fw_softc; if_initname(ifp, device_get_name(dev), unit); ifp->if_init = fwip_init; ifp->if_start = fwip_start; ifp->if_ioctl = fwip_ioctl; ifp->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST); ifp->if_snd.ifq_maxlen = TX_MAX_QUEUE; #ifdef DEVICE_POLLING ifp->if_capabilities |= IFCAP_POLLING; #endif s = splimp(); firewire_ifattach(ifp, hwaddr); splx(s); FWIPDEBUG(ifp, "interface created\n"); return 0; }
struct mbuf *dequeue(struct ifqueue *inq) { struct mbuf *m = NULL; int s = splimp(); IF_DEQUEUE(inq, m); splx(s); return m; }
static __inline void ipq_unlock() { int s; s = splimp(); ipq_locked = 0; splx(s); }
/*---------------------------------------------------------------------------* * clear a B-channel ifqueue from data *---------------------------------------------------------------------------*/ void i4b_Bcleanifq(struct ifqueue *ifq) { int x = splimp(); IF_DRAIN(ifq); splx(x); }
/* This routine resets the interface. */ void el_reset(int unit) { int s; dprintf(("elreset()\n")); s = splimp(); el_stop(unit); el_init(unit); splx(s); }
void enqueue(struct ifqueue *inq, struct mbuf *m) { int s = splimp(); if (IF_QFULL(inq)) { IF_DROP(inq); m_freem(m); } else IF_ENQUEUE(inq, m); splx(s); }
/*---------------------------------------------------------------------------* * i4bclose - device driver close routine *---------------------------------------------------------------------------*/ PDEVSTATIC int i4bclose(dev_t dev, int flag, int fmt, struct proc *p) { int x = splimp(); openflag = 0; i4b_l4_daemon_detached(); i4b_Dcleanifq(&i4b_rdqueue); splx(x); return(0); }
static void fwe_start(struct ifnet *ifp) { struct fwe_softc *fwe = ((struct fwe_eth_softc *)ifp->if_softc)->fwe; int s; FWEDEBUG(ifp, "starting\n"); if (fwe->dma_ch < 0) { struct mbuf *m = NULL; FWEDEBUG(ifp, "not ready\n"); s = splimp(); do { IF_DEQUEUE(&ifp->if_snd, m); if (m != NULL) m_freem(m); ifp->if_oerrors ++; } while (m != NULL); splx(s); return; } s = splimp(); #if defined(__FreeBSD__) ifp->if_drv_flags |= IFF_DRV_OACTIVE; #else ifp->if_flags |= IFF_OACTIVE; #endif if (ifp->if_snd.ifq_len != 0) fwe_as_output(fwe, ifp); #if defined(__FreeBSD__) ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; #else ifp->if_flags &= ~IFF_OACTIVE; #endif splx(s); }
int rmc_modclass(struct rm_class *cl, u_int nsecPerByte, int maxq, u_int maxidle, int minidle, u_int offtime, int pktsize) { struct rm_ifdat *ifd; u_int old_allotment; int s; ifd = cl->ifdat_; old_allotment = cl->allotment_; #ifdef __NetBSD__ s = splnet(); #else s = splimp(); #endif IFQ_LOCK(ifd->ifq_); cl->allotment_ = RM_NS_PER_SEC / nsecPerByte; /* Bytes per sec */ cl->qthresh_ = 0; cl->ns_per_byte_ = nsecPerByte; qlimit(cl->q_) = maxq; #if 1 /* minidle is also scaled in ALTQ */ cl->minidle_ = (minidle * nsecPerByte) / 8; if (cl->minidle_ > 0) cl->minidle_ = 0; #else cl->minidle_ = minidle; #endif cl->maxidle_ = (maxidle * nsecPerByte) / 8; if (cl->maxidle_ == 0) cl->maxidle_ = 1; #if 1 /* offtime is also scaled in ALTQ */ cl->avgidle_ = cl->maxidle_; cl->offtime_ = ((offtime * nsecPerByte) / 8) >> RM_FILTER_GAIN; if (cl->offtime_ == 0) cl->offtime_ = 1; #else cl->avgidle_ = 0; cl->offtime_ = (offtime * nsecPerByte) / 8; #endif /* * If CBQ's WRR is enabled, then initialize the class WRR state. */ if (ifd->wrr_) { ifd->alloc_[cl->pri_] += cl->allotment_ - old_allotment; rmc_wrr_set_weights(ifd); } IFQ_UNLOCK(ifd->ifq_); splx(s); return (0); }
void hdintr() { register struct mbuf *m; register struct hdcb *hdp; register struct ifnet *ifp; register int s; static struct ifnet *lastifp; static struct hdcb *lasthdp; for (;;) { s = splimp(); IF_DEQUEUE(&hdintrq, m); splx(s); if (m == 0) break; if (m->m_len < HDHEADERLN) { printf("hdintr: packet too short (len=%d)\n", m->m_len); m_freem(m); continue; } if ((m->m_flags & M_PKTHDR) == 0) panic("hdintr"); ifp = m->m_pkthdr.rcvif; /* * look up the appropriate hdlc control block */ if (ifp == lastifp) hdp = lasthdp; else { for (hdp = hdcbhead; hdp; hdp = hdp->hd_next) if (hdp->hd_ifp == ifp) break; if (hdp == 0) { printf("hdintr: unknown interface %p\n", ifp); m_freem(m); continue; } lastifp = ifp; lasthdp = hdp; } /* * Process_rxframe returns FALSE if the frame was NOT queued * for the next higher layers. */ if (process_rxframe(hdp, m) == FALSE) m_freem(m); } }
static void start_receiver(struct ie_softc *sc) { int s = splimp(); sc->scb->ie_recv_list = MK_16(MEM(sc), sc->rframes[0]); command_and_wait(sc, IE_RU_START, 0, 0); ie_ack(sc, IE_ST_WHENCE); splx(s); }
void mbinit() { int s; s = splimp(); if (m_clalloc(max(4096/CLBYTES, 1), M_DONTWAIT) == 0) goto bad; splx(s); return; bad: panic("mbinit"); }
static __inline int ipq_lock_try() { int s; s = splimp(); if (ipq_locked) { splx(s); return (0); } ipq_locked = 1; splx(s); return (1); }