1*6925Swnj /* if_en.c 4.60 82/05/24 */ 24686Swnj 34686Swnj #include "en.h" 46410Ssam #include "imp.h" 55105Swnj 64686Swnj /* 75105Swnj * Xerox prototype (3 Mb) Ethernet interface driver. 84686Swnj */ 94686Swnj 104686Swnj #include "../h/param.h" 114686Swnj #include "../h/systm.h" 124686Swnj #include "../h/mbuf.h" 134686Swnj #include "../h/pte.h" 144686Swnj #include "../h/buf.h" 155083Swnj #include "../h/protosw.h" 165083Swnj #include "../h/socket.h" 174686Swnj #include "../h/ubareg.h" 184686Swnj #include "../h/ubavar.h" 194686Swnj #include "../h/enreg.h" 205083Swnj #include "../h/cpu.h" 214686Swnj #include "../h/mtpr.h" 225083Swnj #include "../h/vmmac.h" 235083Swnj #include "../net/in.h" 245083Swnj #include "../net/in_systm.h" 255083Swnj #include "../net/if.h" 265083Swnj #include "../net/if_en.h" 275083Swnj #include "../net/if_uba.h" 285083Swnj #include "../net/ip.h" 295083Swnj #include "../net/ip_var.h" 306027Ssam #include "../net/pup.h" 316364Ssam #include "../net/route.h" 326503Ssam #include <errno.h> 334686Swnj 345213Swnj #define ENMTU (1024+512) 35*6925Swnj #define ENMRU (1024+512+16) /* 16 is enough to receive trailer */ 365083Swnj 374686Swnj int enprobe(), enattach(), enrint(), enxint(), encollide(); 384686Swnj struct uba_device *eninfo[NEN]; 394686Swnj u_short enstd[] = { 0 }; 404686Swnj struct uba_driver endriver = 415171Swnj { enprobe, 0, enattach, 0, enstd, "en", eninfo }; 424686Swnj #define ENUNIT(x) minor(x) 434686Swnj 445105Swnj int eninit(),enoutput(),enreset(); 455105Swnj 465105Swnj /* 475105Swnj * Ethernet software status per interface. 485105Swnj * 495105Swnj * Each interface is referenced by a network interface structure, 505105Swnj * es_if, which the routing code uses to locate the interface. 515105Swnj * This structure contains the output queue for the interface, its address, ... 525105Swnj * We also have, for each interface, a UBA interface structure, which 535105Swnj * contains information about the UNIBUS resources held by the interface: 545105Swnj * map registers, buffered data paths, etc. Information is cached in this 555105Swnj * structure for use by the if_uba.c routines in running the interface 565105Swnj * efficiently. 575105Swnj */ 585083Swnj struct en_softc { 595105Swnj struct ifnet es_if; /* network-visible interface */ 605105Swnj struct ifuba es_ifuba; /* UNIBUS resources */ 615105Swnj short es_delay; /* current output delay */ 625105Swnj short es_mask; /* mask for current output delay */ 636471Sroot short es_lastx; /* host last transmitted to */ 645105Swnj short es_oactive; /* is output active? */ 655105Swnj short es_olen; /* length of last output */ 665083Swnj } en_softc[NEN]; 674686Swnj 685105Swnj /* 695105Swnj * Do output DMA to determine interface presence and 705105Swnj * interrupt vector. DMA is too short to disturb other hosts. 715105Swnj */ 724686Swnj enprobe(reg) 734686Swnj caddr_t reg; 744686Swnj { 755171Swnj register int br, cvec; /* r11, r10 value-result */ 764686Swnj register struct endevice *addr = (struct endevice *)reg; 774686Swnj 785083Swnj COUNT(ENPROBE); 794686Swnj #ifdef lint 804686Swnj br = 0; cvec = br; br = cvec; 814922Swnj enrint(0); enxint(0); encollide(0); 824686Swnj #endif 834686Swnj addr->en_istat = 0; 844686Swnj addr->en_owc = -1; 854686Swnj addr->en_oba = 0; 864771Swnj addr->en_ostat = EN_IEN|EN_GO; 874686Swnj DELAY(100000); 884686Swnj addr->en_ostat = 0; 896575Ssam #ifdef ECHACK 906575Ssam br = 0x16; 916575Ssam #endif 924686Swnj return (1); 934686Swnj } 944686Swnj 955105Swnj /* 965105Swnj * Interface exists: make available by filling in network interface 975105Swnj * record. System will initialize the interface when it is ready 985105Swnj * to accept packets. 995105Swnj */ 1004686Swnj enattach(ui) 1014686Swnj struct uba_device *ui; 1024686Swnj { 1035105Swnj register struct en_softc *es = &en_softc[ui->ui_unit]; 1046335Ssam register struct sockaddr_in *sin; 1055105Swnj COUNT(ENATTACH); 1064688Swnj 1075105Swnj es->es_if.if_unit = ui->ui_unit; 1085171Swnj es->es_if.if_name = "en"; 1095105Swnj es->es_if.if_mtu = ENMTU; 1106433Ssam es->es_if.if_net = ui->ui_flags & 0xff; 1115105Swnj es->es_if.if_host[0] = 1126335Ssam (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff; 1136335Ssam sin = (struct sockaddr_in *)&es->es_if.if_addr; 1146335Ssam sin->sin_family = AF_INET; 1156335Ssam sin->sin_addr = if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]); 1166335Ssam sin = (struct sockaddr_in *)&es->es_if.if_broadaddr; 1176335Ssam sin->sin_family = AF_INET; 1186335Ssam sin->sin_addr = if_makeaddr(es->es_if.if_net, 0); 1196335Ssam es->es_if.if_flags = IFF_BROADCAST; 1205171Swnj es->es_if.if_init = eninit; 1215105Swnj es->es_if.if_output = enoutput; 1225105Swnj es->es_if.if_ubareset = enreset; 1236554Ssam es->es_ifuba.ifu_flags = UBA_NEEDBDP | UBA_NEED16 | UBA_CANTWAIT; 1245160Swnj if_attach(&es->es_if); 1256410Ssam #if NIMP == 0 1266410Ssam /* here's one for you john baby.... */ 127*6925Swnj if (ui->ui_flags &~ 0xff) 128*6925Swnj enlhinit(&es->es_if, (ui->ui_flags &~ 0xff) | 0x0a); 1296410Ssam #endif 1304686Swnj } 1314686Swnj 1325105Swnj /* 1335105Swnj * Reset of interface after UNIBUS reset. 1345105Swnj * If interface is on specified uba, reset its state. 1355105Swnj */ 1365105Swnj enreset(unit, uban) 1375105Swnj int unit, uban; 1385105Swnj { 1395105Swnj register struct uba_device *ui; 1405105Swnj COUNT(ENRESET); 1415105Swnj 1425171Swnj if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0 || 1435171Swnj ui->ui_ubanum != uban) 1445105Swnj return; 1455171Swnj printf(" en%d", unit); 1465105Swnj eninit(unit); 1475105Swnj } 1485105Swnj 1495105Swnj /* 1505105Swnj * Initialization of interface; clear recorded pending 1515105Swnj * operations, and reinitialize UNIBUS usage. 1525105Swnj */ 1534688Swnj eninit(unit) 1544686Swnj int unit; 1555083Swnj { 1565171Swnj register struct en_softc *es = &en_softc[unit]; 1575171Swnj register struct uba_device *ui = eninfo[unit]; 1584686Swnj register struct endevice *addr; 1595105Swnj int s; 1604686Swnj 1615105Swnj if (if_ubainit(&es->es_ifuba, ui->ui_ubanum, 162*6925Swnj sizeof (struct en_header), (int)btoc(ENMRU)) == 0) { 1635171Swnj printf("en%d: can't initialize\n", unit); 1646335Ssam es->es_if.if_flags &= ~IFF_UP; 1655083Swnj return; 1664686Swnj } 1674686Swnj addr = (struct endevice *)ui->ui_addr; 1685083Swnj addr->en_istat = addr->en_ostat = 0; 1694686Swnj 1705105Swnj /* 1715171Swnj * Hang a receive and start any 1725171Swnj * pending writes by faking a transmit complete. 1735105Swnj */ 1745105Swnj s = splimp(); 1755171Swnj addr->en_iba = es->es_ifuba.ifu_r.ifrw_info; 176*6925Swnj addr->en_iwc = -(sizeof (struct en_header) + ENMRU) >> 1; 1775171Swnj addr->en_istat = EN_IEN|EN_GO; 1785171Swnj es->es_oactive = 1; 1796335Ssam es->es_if.if_flags |= IFF_UP; 1805105Swnj enxint(unit); 1815105Swnj splx(s); 1826364Ssam if_rtinit(&es->es_if, RTF_DIRECT|RTF_UP); 1834686Swnj } 1844686Swnj 1856471Sroot int enalldelay = 0; 1864717Swnj int enlastdel = 25; 1876471Sroot int enlastmask = (~0) << 5; 1885083Swnj 1895105Swnj /* 1905105Swnj * Start or restart output on interface. 1915105Swnj * If interface is already active, then this is a retransmit 1925105Swnj * after a collision, and just restuff registers and delay. 1935105Swnj * If interface is not already active, get another datagram 1945105Swnj * to send off of the interface queue, and map it to the interface 1955105Swnj * before starting the output. 1965105Swnj */ 1974688Swnj enstart(dev) 1984686Swnj dev_t dev; 1994686Swnj { 2005171Swnj int unit = ENUNIT(dev); 2015171Swnj struct uba_device *ui = eninfo[unit]; 2025171Swnj register struct en_softc *es = &en_softc[unit]; 2035083Swnj register struct endevice *addr; 2045083Swnj struct mbuf *m; 2055083Swnj int dest; 2064688Swnj COUNT(ENSTART); 2074686Swnj 2085083Swnj if (es->es_oactive) 2095083Swnj goto restart; 2105105Swnj 2115105Swnj /* 2125105Swnj * Not already active: dequeue another request 2135105Swnj * and map it to the UNIBUS. If no more requests, 2145105Swnj * just return. 2155105Swnj */ 2165105Swnj IF_DEQUEUE(&es->es_if.if_snd, m); 2175083Swnj if (m == 0) { 2185083Swnj es->es_oactive = 0; 2194686Swnj return; 2204686Swnj } 2215213Swnj dest = mtod(m, struct en_header *)->en_dhost; 2225105Swnj es->es_olen = if_wubaput(&es->es_ifuba, m); 2235105Swnj 2245105Swnj /* 2255105Swnj * Ethernet cannot take back-to-back packets (no 2266471Sroot * buffering in interface. To help avoid overrunning 2276471Sroot * receivers, enforce a small delay (about 1ms) in interface: 2286471Sroot * * between all packets when enalldelay 2296471Sroot * * whenever last packet was broadcast 2306471Sroot * * whenever this packet is to same host as last packet 2315105Swnj */ 2326471Sroot if (enalldelay || es->es_lastx == 0 || es->es_lastx == dest) { 2335083Swnj es->es_delay = enlastdel; 2346471Sroot es->es_mask = enlastmask; 2356471Sroot } 2366471Sroot es->es_lastx = dest; 2375105Swnj 2385083Swnj restart: 2395105Swnj /* 2405105Swnj * Have request mapped to UNIBUS for transmission. 2415105Swnj * Purge any stale data from this BDP, and start the otput. 2425105Swnj */ 2436335Ssam if (es->es_ifuba.ifu_flags & UBA_NEEDBDP) 2446335Ssam UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_w.ifrw_bdp); 2454686Swnj addr = (struct endevice *)ui->ui_addr; 2465160Swnj addr->en_oba = (int)es->es_ifuba.ifu_w.ifrw_info; 2475083Swnj addr->en_odelay = es->es_delay; 2485083Swnj addr->en_owc = -((es->es_olen + 1) >> 1); 2494771Swnj addr->en_ostat = EN_IEN|EN_GO; 2505083Swnj es->es_oactive = 1; 2514686Swnj } 2524686Swnj 2535105Swnj /* 2545105Swnj * Ethernet interface transmitter interrupt. 2555105Swnj * Start another output if more data to send. 2565105Swnj */ 2574686Swnj enxint(unit) 2584686Swnj int unit; 2594686Swnj { 2605171Swnj register struct uba_device *ui = eninfo[unit]; 2615171Swnj register struct en_softc *es = &en_softc[unit]; 2626242Sroot register struct endevice *addr = (struct endevice *)ui->ui_addr; 2634686Swnj COUNT(ENXINT); 2644686Swnj 2655083Swnj if (es->es_oactive == 0) 2665083Swnj return; 2676242Sroot if (es->es_mask && (addr->en_ostat&EN_OERROR)) { 2686242Sroot es->es_if.if_oerrors++; 2696242Sroot if (es->es_if.if_oerrors % 100 == 0) 2706242Sroot printf("en%d: += 100 output errors\n", unit); 2716242Sroot endocoll(unit); 2726242Sroot return; 2736242Sroot } 2745171Swnj es->es_if.if_opackets++; 2755083Swnj es->es_oactive = 0; 2765083Swnj es->es_delay = 0; 2775083Swnj es->es_mask = ~0; 2785696Sroot if (es->es_ifuba.ifu_xtofree) { 2795696Sroot m_freem(es->es_ifuba.ifu_xtofree); 2805696Sroot es->es_ifuba.ifu_xtofree = 0; 2815696Sroot } 2825105Swnj if (es->es_if.if_snd.ifq_head == 0) { 2836471Sroot es->es_lastx = 256; /* putatively illegal */ 2844686Swnj return; 2854686Swnj } 2865083Swnj enstart(unit); 2874686Swnj } 2884686Swnj 2895105Swnj /* 2905105Swnj * Collision on ethernet interface. Do exponential 2915105Swnj * backoff, and retransmit. If have backed off all 2926335Ssam * the way print warning diagnostic, and drop packet. 2935105Swnj */ 2944686Swnj encollide(unit) 2954686Swnj int unit; 2964686Swnj { 2976242Sroot struct en_softc *es = &en_softc[unit]; 2984686Swnj COUNT(ENCOLLIDE); 2994686Swnj 3005105Swnj es->es_if.if_collisions++; 3015083Swnj if (es->es_oactive == 0) 3024686Swnj return; 3036242Sroot endocoll(unit); 3046242Sroot } 3056242Sroot 3066242Sroot endocoll(unit) 3076242Sroot int unit; 3086242Sroot { 3096242Sroot register struct en_softc *es = &en_softc[unit]; 3106242Sroot 3115171Swnj /* 3125171Swnj * Es_mask is a 16 bit number with n low zero bits, with 3135171Swnj * n the number of backoffs. When es_mask is 0 we have 3145171Swnj * backed off 16 times, and give up. 3155171Swnj */ 3165083Swnj if (es->es_mask == 0) { 3175213Swnj printf("en%d: send error\n", unit); 3185083Swnj enxint(unit); 3195171Swnj return; 3204686Swnj } 3215171Swnj /* 3225171Swnj * Another backoff. Restart with delay based on n low bits 3235171Swnj * of the interval timer. 3245171Swnj */ 3255171Swnj es->es_mask <<= 1; 3265171Swnj es->es_delay = mfpr(ICR) &~ es->es_mask; 3275171Swnj enstart(unit); 3284686Swnj } 3294686Swnj 3306027Ssam struct sockaddr_pup pupsrc = { AF_PUP }; 3316027Ssam struct sockaddr_pup pupdst = { AF_PUP }; 3326027Ssam struct sockproto pupproto = { PF_PUP }; 3335105Swnj /* 3345105Swnj * Ethernet interface receiver interrupt. 3355105Swnj * If input error just drop packet. 3365105Swnj * Otherwise purge input buffered data path and examine 3375105Swnj * packet to determine type. If can't determine length 3385105Swnj * from type, then have to drop packet. Othewise decapsulate 3395105Swnj * packet based on type and pass to type specific higher-level 3405105Swnj * input routine. 3415105Swnj */ 3424686Swnj enrint(unit) 3434686Swnj int unit; 3444686Swnj { 3455171Swnj register struct en_softc *es = &en_softc[unit]; 3465171Swnj struct endevice *addr = (struct endevice *)eninfo[unit]->ui_addr; 3475171Swnj register struct en_header *en; 3485083Swnj struct mbuf *m; 3496471Sroot int len, plen; short resid; 3505171Swnj register struct ifqueue *inq; 3515083Swnj int off; 3524686Swnj COUNT(ENRINT); 3534686Swnj 3545171Swnj es->es_if.if_ipackets++; 3555105Swnj 3565105Swnj /* 3575171Swnj * Purge BDP; drop if input error indicated. 3585105Swnj */ 3596335Ssam if (es->es_ifuba.ifu_flags & UBA_NEEDBDP) 3606335Ssam UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp); 3614771Swnj if (addr->en_istat&EN_IERROR) { 3625105Swnj es->es_if.if_ierrors++; 3636238Sroot if (es->es_if.if_ierrors % 100 == 0) 3646238Sroot printf("en%d: += 100 input errors\n", unit); 3655083Swnj goto setup; 3664686Swnj } 3675105Swnj 3685105Swnj /* 3696471Sroot * Calculate input data length. 3705105Swnj * Get pointer to ethernet header (in input buffer). 3715105Swnj * Deal with trailer protocol: if type is PUP trailer 3725105Swnj * get true type from first 16-bit word past data. 3735105Swnj * Remember that type was trailer by setting off. 3745105Swnj */ 3756471Sroot resid = addr->en_iwc; 3766471Sroot if (resid) 3776471Sroot resid |= 0176000; 378*6925Swnj len = (((sizeof (struct en_header) + ENMRU) >> 1) + resid) << 1; 3796471Sroot len -= sizeof (struct en_header); 380*6925Swnj if (len > ENMRU) 3816471Sroot goto setup; /* sanity */ 3825105Swnj en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr); 3835083Swnj #define endataaddr(en, off, type) ((type)(((caddr_t)((en)+1)+(off)))) 3845083Swnj if (en->en_type >= ENPUP_TRAIL && 3855083Swnj en->en_type < ENPUP_TRAIL+ENPUP_NTRAILER) { 3865083Swnj off = (en->en_type - ENPUP_TRAIL) * 512; 387*6925Swnj if (off > ENMTU) 3885171Swnj goto setup; /* sanity */ 3895083Swnj en->en_type = *endataaddr(en, off, u_short *); 3906471Sroot resid = *(endataaddr(en, off+2, u_short *)); 3916471Sroot if (off + resid > len) 3926471Sroot goto setup; /* sanity */ 3936471Sroot len = off + resid; 3945083Swnj } else 3955083Swnj off = 0; 3965083Swnj if (len == 0) 3975083Swnj goto setup; 3985105Swnj /* 3995105Swnj * Pull packet off interface. Off is nonzero if packet 4005105Swnj * has trailing header; if_rubaget will then force this header 4015105Swnj * information to be at the front, but we still have to drop 4026471Sroot * the type and length which are at the front of any trailer data. 4035105Swnj */ 4045105Swnj m = if_rubaget(&es->es_ifuba, len, off); 4055213Swnj if (m == 0) 4065213Swnj goto setup; 4075105Swnj if (off) { 4086471Sroot m->m_off += 2 * sizeof (u_short); 4096471Sroot m->m_len -= 2 * sizeof (u_short); 4105105Swnj } 4116027Ssam switch (en->en_type) { 4126027Ssam 4136027Ssam #ifdef INET 4146027Ssam case ENPUP_IPTYPE: 4156260Swnj schednetisr(NETISR_IP); 4166027Ssam inq = &ipintrq; 4176027Ssam break; 4186027Ssam #endif 4196335Ssam #ifdef PUP 4206027Ssam case ENPUP_PUPTYPE: { 4216027Ssam struct pup_header *pup = mtod(m, struct pup_header *); 4226027Ssam 4236027Ssam pupproto.sp_protocol = pup->pup_type; 4246027Ssam pupdst.spup_addr = pup->pup_dport; 4256027Ssam pupsrc.spup_addr = pup->pup_sport; 4266526Ssam raw_input(m, &pupproto, (struct sockaddr *)&pupsrc, 4276526Ssam (struct sockaddr *)&pupdst); 4286027Ssam goto setup; 4296027Ssam } 4306335Ssam #endif 4316476Swnj default: 4326476Swnj m_freem(m); 4336476Swnj goto setup; 4346335Ssam } 4356335Ssam 4366207Swnj if (IF_QFULL(inq)) { 4376207Swnj IF_DROP(inq); 4386335Ssam m_freem(m); 4396207Swnj } else 4406207Swnj IF_ENQUEUE(inq, m); 4415105Swnj 4424688Swnj setup: 4435105Swnj /* 4445105Swnj * Reset for next packet. 4455105Swnj */ 4465105Swnj addr->en_iba = es->es_ifuba.ifu_r.ifrw_info; 447*6925Swnj addr->en_iwc = -(sizeof (struct en_header) + ENMRU) >> 1; 4484771Swnj addr->en_istat = EN_IEN|EN_GO; 4494688Swnj } 4504686Swnj 4515083Swnj /* 4525083Swnj * Ethernet output routine. 4535083Swnj * Encapsulate a packet of type family for the local net. 4545105Swnj * Use trailer local net encapsulation if enough data in first 4555105Swnj * packet leaves a multiple of 512 bytes of data in remainder. 4565083Swnj */ 4576335Ssam enoutput(ifp, m0, dst) 4585083Swnj struct ifnet *ifp; 4595083Swnj struct mbuf *m0; 4606335Ssam struct sockaddr *dst; 4614686Swnj { 4626503Ssam int type, dest, s, error; 4635105Swnj register struct mbuf *m = m0; 4645083Swnj register struct en_header *en; 4656335Ssam register int off; 4664686Swnj 4675927Sroot COUNT(ENOUTPUT); 4686335Ssam switch (dst->sa_family) { 4695083Swnj 4705083Swnj #ifdef INET 4716335Ssam case AF_INET: 4726484Swnj dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr; 4736503Ssam if (dest & 0x00ffff00) { 4746503Ssam error = EPERM; /* ??? */ 4756486Swnj goto bad; 4766503Ssam } 4776484Swnj dest = (dest >> 24) & 0xff; 4786335Ssam off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len; 4796335Ssam if (off > 0 && (off & 0x1ff) == 0 && 4806471Sroot m->m_off >= MMINOFF + 2 * sizeof (u_short)) { 4815083Swnj type = ENPUP_TRAIL + (off>>9); 4826471Sroot m->m_off -= 2 * sizeof (u_short); 4836471Sroot m->m_len += 2 * sizeof (u_short); 4845105Swnj *mtod(m, u_short *) = ENPUP_IPTYPE; 4856471Sroot *(mtod(m, u_short *) + 1) = m->m_len; 4865105Swnj goto gottrailertype; 4875083Swnj } 4885105Swnj type = ENPUP_IPTYPE; 4895105Swnj off = 0; 4905105Swnj goto gottype; 4915083Swnj #endif 4926027Ssam #ifdef PUP 4936335Ssam case AF_PUP: 4946335Ssam dest = ((struct sockaddr_pup *)dst)->spup_addr.pp_host; 4956027Ssam type = ENPUP_PUPTYPE; 4966027Ssam off = 0; 4976027Ssam goto gottype; 4986027Ssam #endif 4996027Ssam 5005083Swnj default: 5016335Ssam printf("en%d: can't handle af%d\n", ifp->if_unit, 5026335Ssam dst->sa_family); 5036503Ssam error = EAFNOSUPPORT; 5046503Ssam goto bad; 5054686Swnj } 5065105Swnj 5075171Swnj gottrailertype: 5085105Swnj /* 5095105Swnj * Packet to be sent as trailer: move first packet 5105105Swnj * (control information) to end of chain. 5115105Swnj */ 5125105Swnj while (m->m_next) 5135105Swnj m = m->m_next; 5145105Swnj m->m_next = m0; 5155105Swnj m = m0->m_next; 5165105Swnj m0->m_next = 0; 5175171Swnj m0 = m; 5185105Swnj 5195171Swnj gottype: 5205105Swnj /* 5215105Swnj * Add local net header. If no space in first mbuf, 5225105Swnj * allocate another. 5235105Swnj */ 5245213Swnj if (m->m_off > MMAXOFF || 5255213Swnj MMINOFF + sizeof (struct en_header) > m->m_off) { 5265584Sroot m = m_get(M_DONTWAIT); 5275083Swnj if (m == 0) { 5286503Ssam error = ENOBUFS; 5296503Ssam goto bad; 5305083Swnj } 5315083Swnj m->m_next = m0; 5325083Swnj m->m_off = MMINOFF; 5335083Swnj m->m_len = sizeof (struct en_header); 5345083Swnj } else { 5355083Swnj m->m_off -= sizeof (struct en_header); 5365083Swnj m->m_len += sizeof (struct en_header); 5375083Swnj } 5385083Swnj en = mtod(m, struct en_header *); 5395083Swnj en->en_shost = ifp->if_host[0]; 5405083Swnj en->en_dhost = dest; 5415083Swnj en->en_type = type; 5425105Swnj 5435105Swnj /* 5445105Swnj * Queue message on interface, and start output if interface 5455105Swnj * not yet active. 5465105Swnj */ 5475083Swnj s = splimp(); 5486207Swnj if (IF_QFULL(&ifp->if_snd)) { 5496207Swnj IF_DROP(&ifp->if_snd); 5506503Ssam error = ENOBUFS; 5516503Ssam goto qfull; 5526207Swnj } 5535083Swnj IF_ENQUEUE(&ifp->if_snd, m); 5545083Swnj if (en_softc[ifp->if_unit].es_oactive == 0) 5555083Swnj enstart(ifp->if_unit); 5565275Swnj splx(s); 5576503Ssam return (0); 5586503Ssam qfull: 5596503Ssam m0 = m; 5606503Ssam splx(s); 5616484Swnj bad: 5626503Ssam m_freem(m0); 5636503Ssam return (error); 5644686Swnj } 5656410Ssam 5666410Ssam #if NIMP == 0 && NEN > 0 5676410Ssam /* 5686410Ssam * Logical host interface driver. 5696410Ssam * Allows host to appear as an ARPAnet 5706410Ssam * logical host. Must also have routing 5716410Ssam * table entry set up to forward packets 5726410Ssam * to appropriate gateway on localnet. 5736410Ssam */ 5746410Ssam 5756410Ssam struct ifnet enlhif; 576*6925Swnj int looutput(); 5776410Ssam 5786410Ssam /* 5796410Ssam * Called by localnet interface to allow logical 580*6925Swnj * host interface to "attach", it's purpose 5816410Ssam * is simply to establish the host's arpanet address. 5826410Ssam */ 583*6925Swnj enlhinit(esifp, addr) 584*6925Swnj struct ifnet *esifp; 5856410Ssam int addr; 5866410Ssam { 5876410Ssam register struct ifnet *ifp = &enlhif; 5886410Ssam register struct sockaddr_in *sin; 5896410Ssam 5906410Ssam COUNT(ENLHINIT); 5916410Ssam ifp->if_name = "lh"; 5926410Ssam ifp->if_mtu = ENMTU; 5936410Ssam sin = (struct sockaddr_in *)&ifp->if_addr; 5946410Ssam sin->sin_family = AF_INET; 5956410Ssam sin->sin_addr.s_addr = addr; 5966410Ssam ifp->if_net = sin->sin_addr.s_net; 597*6925Swnj ifp->if_flags = IFF_UP|IFF_POINTOPOINT; 598*6925Swnj ifp->if_dstaddr = esifp->if_addr; 599*6925Swnj ifp->if_output = looutput; 6006410Ssam if_attach(ifp); 601*6925Swnj rtinit(&ifp->if_addr, &ifp->if_addr, RTF_UP|RTF_DIRECT); 6026410Ssam } 6036410Ssam #endif 604