1*6554Ssam /* if_en.c 4.57 82/04/16 */ 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) 355083Swnj 364686Swnj int enprobe(), enattach(), enrint(), enxint(), encollide(); 374686Swnj struct uba_device *eninfo[NEN]; 384686Swnj u_short enstd[] = { 0 }; 394686Swnj struct uba_driver endriver = 405171Swnj { enprobe, 0, enattach, 0, enstd, "en", eninfo }; 414686Swnj #define ENUNIT(x) minor(x) 424686Swnj 435105Swnj int eninit(),enoutput(),enreset(); 445105Swnj 455105Swnj /* 465105Swnj * Ethernet software status per interface. 475105Swnj * 485105Swnj * Each interface is referenced by a network interface structure, 495105Swnj * es_if, which the routing code uses to locate the interface. 505105Swnj * This structure contains the output queue for the interface, its address, ... 515105Swnj * We also have, for each interface, a UBA interface structure, which 525105Swnj * contains information about the UNIBUS resources held by the interface: 535105Swnj * map registers, buffered data paths, etc. Information is cached in this 545105Swnj * structure for use by the if_uba.c routines in running the interface 555105Swnj * efficiently. 565105Swnj */ 575083Swnj struct en_softc { 585105Swnj struct ifnet es_if; /* network-visible interface */ 595105Swnj struct ifuba es_ifuba; /* UNIBUS resources */ 605105Swnj short es_delay; /* current output delay */ 615105Swnj short es_mask; /* mask for current output delay */ 626471Sroot short es_lastx; /* host last transmitted to */ 635105Swnj short es_oactive; /* is output active? */ 645105Swnj short es_olen; /* length of last output */ 655083Swnj } en_softc[NEN]; 664686Swnj 675105Swnj /* 685105Swnj * Do output DMA to determine interface presence and 695105Swnj * interrupt vector. DMA is too short to disturb other hosts. 705105Swnj */ 714686Swnj enprobe(reg) 724686Swnj caddr_t reg; 734686Swnj { 745171Swnj register int br, cvec; /* r11, r10 value-result */ 754686Swnj register struct endevice *addr = (struct endevice *)reg; 764686Swnj 775083Swnj COUNT(ENPROBE); 784686Swnj #ifdef lint 794686Swnj br = 0; cvec = br; br = cvec; 804922Swnj enrint(0); enxint(0); encollide(0); 814686Swnj #endif 824686Swnj addr->en_istat = 0; 834686Swnj addr->en_owc = -1; 844686Swnj addr->en_oba = 0; 854771Swnj addr->en_ostat = EN_IEN|EN_GO; 864686Swnj DELAY(100000); 874686Swnj addr->en_ostat = 0; 886522Sfeldman br = 0x16; /* temporary ec hack */ 894686Swnj return (1); 904686Swnj } 914686Swnj 925105Swnj /* 935105Swnj * Interface exists: make available by filling in network interface 945105Swnj * record. System will initialize the interface when it is ready 955105Swnj * to accept packets. 965105Swnj */ 974686Swnj enattach(ui) 984686Swnj struct uba_device *ui; 994686Swnj { 1005105Swnj register struct en_softc *es = &en_softc[ui->ui_unit]; 1016335Ssam register struct sockaddr_in *sin; 1025105Swnj COUNT(ENATTACH); 1034688Swnj 1045105Swnj es->es_if.if_unit = ui->ui_unit; 1055171Swnj es->es_if.if_name = "en"; 1065105Swnj es->es_if.if_mtu = ENMTU; 1076433Ssam es->es_if.if_net = ui->ui_flags & 0xff; 1085105Swnj es->es_if.if_host[0] = 1096335Ssam (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff; 1106335Ssam sin = (struct sockaddr_in *)&es->es_if.if_addr; 1116335Ssam sin->sin_family = AF_INET; 1126335Ssam sin->sin_addr = if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]); 1136335Ssam sin = (struct sockaddr_in *)&es->es_if.if_broadaddr; 1146335Ssam sin->sin_family = AF_INET; 1156335Ssam sin->sin_addr = if_makeaddr(es->es_if.if_net, 0); 1166335Ssam es->es_if.if_flags = IFF_BROADCAST; 1175171Swnj es->es_if.if_init = eninit; 1185105Swnj es->es_if.if_output = enoutput; 1195105Swnj es->es_if.if_ubareset = enreset; 120*6554Ssam es->es_ifuba.ifu_flags = UBA_NEEDBDP | UBA_NEED16 | UBA_CANTWAIT; 1215160Swnj if_attach(&es->es_if); 1226410Ssam #if NIMP == 0 1236410Ssam /* here's one for you john baby.... */ 1246422Sroot enlhinit((ui->ui_flags &~ 0xff) | 0x0a); 1256410Ssam #endif 1264686Swnj } 1274686Swnj 1285105Swnj /* 1295105Swnj * Reset of interface after UNIBUS reset. 1305105Swnj * If interface is on specified uba, reset its state. 1315105Swnj */ 1325105Swnj enreset(unit, uban) 1335105Swnj int unit, uban; 1345105Swnj { 1355105Swnj register struct uba_device *ui; 1365105Swnj COUNT(ENRESET); 1375105Swnj 1385171Swnj if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0 || 1395171Swnj ui->ui_ubanum != uban) 1405105Swnj return; 1415171Swnj printf(" en%d", unit); 1425105Swnj eninit(unit); 1435105Swnj } 1445105Swnj 1455105Swnj /* 1465105Swnj * Initialization of interface; clear recorded pending 1475105Swnj * operations, and reinitialize UNIBUS usage. 1485105Swnj */ 1494688Swnj eninit(unit) 1504686Swnj int unit; 1515083Swnj { 1525171Swnj register struct en_softc *es = &en_softc[unit]; 1535171Swnj register struct uba_device *ui = eninfo[unit]; 1544686Swnj register struct endevice *addr; 1555105Swnj int s; 1564686Swnj 1575105Swnj if (if_ubainit(&es->es_ifuba, ui->ui_ubanum, 1585708Sroot sizeof (struct en_header), (int)btoc(ENMTU)) == 0) { 1595171Swnj printf("en%d: can't initialize\n", unit); 1606335Ssam es->es_if.if_flags &= ~IFF_UP; 1615083Swnj return; 1624686Swnj } 1634686Swnj addr = (struct endevice *)ui->ui_addr; 1645083Swnj addr->en_istat = addr->en_ostat = 0; 1654686Swnj 1665105Swnj /* 1675171Swnj * Hang a receive and start any 1685171Swnj * pending writes by faking a transmit complete. 1695105Swnj */ 1705105Swnj s = splimp(); 1715171Swnj addr->en_iba = es->es_ifuba.ifu_r.ifrw_info; 1725171Swnj addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1; 1735171Swnj addr->en_istat = EN_IEN|EN_GO; 1745171Swnj es->es_oactive = 1; 1756335Ssam es->es_if.if_flags |= IFF_UP; 1765105Swnj enxint(unit); 1775105Swnj splx(s); 1786364Ssam if_rtinit(&es->es_if, RTF_DIRECT|RTF_UP); 1794686Swnj } 1804686Swnj 1816471Sroot int enalldelay = 0; 1824717Swnj int enlastdel = 25; 1836471Sroot int enlastmask = (~0) << 5; 1845083Swnj 1855105Swnj /* 1865105Swnj * Start or restart output on interface. 1875105Swnj * If interface is already active, then this is a retransmit 1885105Swnj * after a collision, and just restuff registers and delay. 1895105Swnj * If interface is not already active, get another datagram 1905105Swnj * to send off of the interface queue, and map it to the interface 1915105Swnj * before starting the output. 1925105Swnj */ 1934688Swnj enstart(dev) 1944686Swnj dev_t dev; 1954686Swnj { 1965171Swnj int unit = ENUNIT(dev); 1975171Swnj struct uba_device *ui = eninfo[unit]; 1985171Swnj register struct en_softc *es = &en_softc[unit]; 1995083Swnj register struct endevice *addr; 2005083Swnj struct mbuf *m; 2015083Swnj int dest; 2024688Swnj COUNT(ENSTART); 2034686Swnj 2045083Swnj if (es->es_oactive) 2055083Swnj goto restart; 2065105Swnj 2075105Swnj /* 2085105Swnj * Not already active: dequeue another request 2095105Swnj * and map it to the UNIBUS. If no more requests, 2105105Swnj * just return. 2115105Swnj */ 2125105Swnj IF_DEQUEUE(&es->es_if.if_snd, m); 2135083Swnj if (m == 0) { 2145083Swnj es->es_oactive = 0; 2154686Swnj return; 2164686Swnj } 2175213Swnj dest = mtod(m, struct en_header *)->en_dhost; 2185105Swnj es->es_olen = if_wubaput(&es->es_ifuba, m); 2195105Swnj 2205105Swnj /* 2215105Swnj * Ethernet cannot take back-to-back packets (no 2226471Sroot * buffering in interface. To help avoid overrunning 2236471Sroot * receivers, enforce a small delay (about 1ms) in interface: 2246471Sroot * * between all packets when enalldelay 2256471Sroot * * whenever last packet was broadcast 2266471Sroot * * whenever this packet is to same host as last packet 2275105Swnj */ 2286471Sroot if (enalldelay || es->es_lastx == 0 || es->es_lastx == dest) { 2295083Swnj es->es_delay = enlastdel; 2306471Sroot es->es_mask = enlastmask; 2316471Sroot } 2326471Sroot es->es_lastx = dest; 2335105Swnj 2345083Swnj restart: 2355105Swnj /* 2365105Swnj * Have request mapped to UNIBUS for transmission. 2375105Swnj * Purge any stale data from this BDP, and start the otput. 2385105Swnj */ 2396335Ssam if (es->es_ifuba.ifu_flags & UBA_NEEDBDP) 2406335Ssam UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_w.ifrw_bdp); 2414686Swnj addr = (struct endevice *)ui->ui_addr; 2425160Swnj addr->en_oba = (int)es->es_ifuba.ifu_w.ifrw_info; 2435083Swnj addr->en_odelay = es->es_delay; 2445083Swnj addr->en_owc = -((es->es_olen + 1) >> 1); 2454771Swnj addr->en_ostat = EN_IEN|EN_GO; 2465083Swnj es->es_oactive = 1; 2474686Swnj } 2484686Swnj 2495105Swnj /* 2505105Swnj * Ethernet interface transmitter interrupt. 2515105Swnj * Start another output if more data to send. 2525105Swnj */ 2534686Swnj enxint(unit) 2544686Swnj int unit; 2554686Swnj { 2565171Swnj register struct uba_device *ui = eninfo[unit]; 2575171Swnj register struct en_softc *es = &en_softc[unit]; 2586242Sroot register struct endevice *addr = (struct endevice *)ui->ui_addr; 2594686Swnj COUNT(ENXINT); 2604686Swnj 2615083Swnj if (es->es_oactive == 0) 2625083Swnj return; 2636242Sroot if (es->es_mask && (addr->en_ostat&EN_OERROR)) { 2646242Sroot es->es_if.if_oerrors++; 2656242Sroot if (es->es_if.if_oerrors % 100 == 0) 2666242Sroot printf("en%d: += 100 output errors\n", unit); 2676242Sroot endocoll(unit); 2686242Sroot return; 2696242Sroot } 2705171Swnj es->es_if.if_opackets++; 2715083Swnj es->es_oactive = 0; 2725083Swnj es->es_delay = 0; 2735083Swnj es->es_mask = ~0; 2745696Sroot if (es->es_ifuba.ifu_xtofree) { 2755696Sroot m_freem(es->es_ifuba.ifu_xtofree); 2765696Sroot es->es_ifuba.ifu_xtofree = 0; 2775696Sroot } 2785105Swnj if (es->es_if.if_snd.ifq_head == 0) { 2796471Sroot es->es_lastx = 256; /* putatively illegal */ 2804686Swnj return; 2814686Swnj } 2825083Swnj enstart(unit); 2834686Swnj } 2844686Swnj 2855105Swnj /* 2865105Swnj * Collision on ethernet interface. Do exponential 2875105Swnj * backoff, and retransmit. If have backed off all 2886335Ssam * the way print warning diagnostic, and drop packet. 2895105Swnj */ 2904686Swnj encollide(unit) 2914686Swnj int unit; 2924686Swnj { 2936242Sroot struct en_softc *es = &en_softc[unit]; 2944686Swnj COUNT(ENCOLLIDE); 2954686Swnj 2965105Swnj es->es_if.if_collisions++; 2975083Swnj if (es->es_oactive == 0) 2984686Swnj return; 2996242Sroot endocoll(unit); 3006242Sroot } 3016242Sroot 3026242Sroot endocoll(unit) 3036242Sroot int unit; 3046242Sroot { 3056242Sroot register struct en_softc *es = &en_softc[unit]; 3066242Sroot 3075171Swnj /* 3085171Swnj * Es_mask is a 16 bit number with n low zero bits, with 3095171Swnj * n the number of backoffs. When es_mask is 0 we have 3105171Swnj * backed off 16 times, and give up. 3115171Swnj */ 3125083Swnj if (es->es_mask == 0) { 3135213Swnj printf("en%d: send error\n", unit); 3145083Swnj enxint(unit); 3155171Swnj return; 3164686Swnj } 3175171Swnj /* 3185171Swnj * Another backoff. Restart with delay based on n low bits 3195171Swnj * of the interval timer. 3205171Swnj */ 3215171Swnj es->es_mask <<= 1; 3225171Swnj es->es_delay = mfpr(ICR) &~ es->es_mask; 3235171Swnj enstart(unit); 3244686Swnj } 3254686Swnj 3266027Ssam struct sockaddr_pup pupsrc = { AF_PUP }; 3276027Ssam struct sockaddr_pup pupdst = { AF_PUP }; 3286027Ssam struct sockproto pupproto = { PF_PUP }; 3295105Swnj /* 3305105Swnj * Ethernet interface receiver interrupt. 3315105Swnj * If input error just drop packet. 3325105Swnj * Otherwise purge input buffered data path and examine 3335105Swnj * packet to determine type. If can't determine length 3345105Swnj * from type, then have to drop packet. Othewise decapsulate 3355105Swnj * packet based on type and pass to type specific higher-level 3365105Swnj * input routine. 3375105Swnj */ 3384686Swnj enrint(unit) 3394686Swnj int unit; 3404686Swnj { 3415171Swnj register struct en_softc *es = &en_softc[unit]; 3425171Swnj struct endevice *addr = (struct endevice *)eninfo[unit]->ui_addr; 3435171Swnj register struct en_header *en; 3445083Swnj struct mbuf *m; 3456471Sroot int len, plen; short resid; 3465171Swnj register struct ifqueue *inq; 3475083Swnj int off; 3484686Swnj COUNT(ENRINT); 3494686Swnj 3505171Swnj es->es_if.if_ipackets++; 3515105Swnj 3525105Swnj /* 3535171Swnj * Purge BDP; drop if input error indicated. 3545105Swnj */ 3556335Ssam if (es->es_ifuba.ifu_flags & UBA_NEEDBDP) 3566335Ssam UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp); 3574771Swnj if (addr->en_istat&EN_IERROR) { 3585105Swnj es->es_if.if_ierrors++; 3596238Sroot if (es->es_if.if_ierrors % 100 == 0) 3606238Sroot printf("en%d: += 100 input errors\n", unit); 3615083Swnj goto setup; 3624686Swnj } 3635105Swnj 3645105Swnj /* 3656471Sroot * Calculate input data length. 3665105Swnj * Get pointer to ethernet header (in input buffer). 3675105Swnj * Deal with trailer protocol: if type is PUP trailer 3685105Swnj * get true type from first 16-bit word past data. 3695105Swnj * Remember that type was trailer by setting off. 3705105Swnj */ 3716471Sroot resid = addr->en_iwc; 3726471Sroot if (resid) 3736471Sroot resid |= 0176000; 3746471Sroot len = (((sizeof (struct en_header) + ENMTU) >> 1) + resid) << 1; 3756471Sroot len -= sizeof (struct en_header); 3766471Sroot if (len >= ENMTU) 3776471Sroot goto setup; /* sanity */ 3785105Swnj en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr); 3795083Swnj #define endataaddr(en, off, type) ((type)(((caddr_t)((en)+1)+(off)))) 3805083Swnj if (en->en_type >= ENPUP_TRAIL && 3815083Swnj en->en_type < ENPUP_TRAIL+ENPUP_NTRAILER) { 3825083Swnj off = (en->en_type - ENPUP_TRAIL) * 512; 3835171Swnj if (off >= ENMTU) 3845171Swnj goto setup; /* sanity */ 3855083Swnj en->en_type = *endataaddr(en, off, u_short *); 3866471Sroot resid = *(endataaddr(en, off+2, u_short *)); 3876471Sroot if (off + resid > len) 3886471Sroot goto setup; /* sanity */ 3896471Sroot len = off + resid; 3905083Swnj } else 3915083Swnj off = 0; 3925083Swnj if (len == 0) 3935083Swnj goto setup; 3945105Swnj /* 3955105Swnj * Pull packet off interface. Off is nonzero if packet 3965105Swnj * has trailing header; if_rubaget will then force this header 3975105Swnj * information to be at the front, but we still have to drop 3986471Sroot * the type and length which are at the front of any trailer data. 3995105Swnj */ 4005105Swnj m = if_rubaget(&es->es_ifuba, len, off); 4015213Swnj if (m == 0) 4025213Swnj goto setup; 4035105Swnj if (off) { 4046471Sroot m->m_off += 2 * sizeof (u_short); 4056471Sroot m->m_len -= 2 * sizeof (u_short); 4065105Swnj } 4076027Ssam switch (en->en_type) { 4086027Ssam 4096027Ssam #ifdef INET 4106027Ssam case ENPUP_IPTYPE: 4116260Swnj schednetisr(NETISR_IP); 4126027Ssam inq = &ipintrq; 4136027Ssam break; 4146027Ssam #endif 4156335Ssam #ifdef PUP 4166027Ssam case ENPUP_PUPTYPE: { 4176027Ssam struct pup_header *pup = mtod(m, struct pup_header *); 4186027Ssam 4196027Ssam pupproto.sp_protocol = pup->pup_type; 4206027Ssam pupdst.spup_addr = pup->pup_dport; 4216027Ssam pupsrc.spup_addr = pup->pup_sport; 4226526Ssam raw_input(m, &pupproto, (struct sockaddr *)&pupsrc, 4236526Ssam (struct sockaddr *)&pupdst); 4246027Ssam goto setup; 4256027Ssam } 4266335Ssam #endif 4276476Swnj default: 4286476Swnj m_freem(m); 4296476Swnj goto setup; 4306335Ssam } 4316335Ssam 4326207Swnj if (IF_QFULL(inq)) { 4336207Swnj IF_DROP(inq); 4346335Ssam m_freem(m); 4356207Swnj } else 4366207Swnj IF_ENQUEUE(inq, m); 4375105Swnj 4384688Swnj setup: 4395105Swnj /* 4405105Swnj * Reset for next packet. 4415105Swnj */ 4425105Swnj addr->en_iba = es->es_ifuba.ifu_r.ifrw_info; 4435083Swnj addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1; 4444771Swnj addr->en_istat = EN_IEN|EN_GO; 4454688Swnj } 4464686Swnj 4475083Swnj /* 4485083Swnj * Ethernet output routine. 4495083Swnj * Encapsulate a packet of type family for the local net. 4505105Swnj * Use trailer local net encapsulation if enough data in first 4515105Swnj * packet leaves a multiple of 512 bytes of data in remainder. 4525083Swnj */ 4536335Ssam enoutput(ifp, m0, dst) 4545083Swnj struct ifnet *ifp; 4555083Swnj struct mbuf *m0; 4566335Ssam struct sockaddr *dst; 4574686Swnj { 4586503Ssam int type, dest, s, error; 4595105Swnj register struct mbuf *m = m0; 4605083Swnj register struct en_header *en; 4616335Ssam register int off; 4624686Swnj 4635927Sroot COUNT(ENOUTPUT); 4646335Ssam switch (dst->sa_family) { 4655083Swnj 4665083Swnj #ifdef INET 4676335Ssam case AF_INET: 4686484Swnj dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr; 4696503Ssam if (dest & 0x00ffff00) { 4706503Ssam error = EPERM; /* ??? */ 4716486Swnj goto bad; 4726503Ssam } 4736484Swnj dest = (dest >> 24) & 0xff; 4746335Ssam off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len; 4756335Ssam if (off > 0 && (off & 0x1ff) == 0 && 4766471Sroot m->m_off >= MMINOFF + 2 * sizeof (u_short)) { 4775083Swnj type = ENPUP_TRAIL + (off>>9); 4786471Sroot m->m_off -= 2 * sizeof (u_short); 4796471Sroot m->m_len += 2 * sizeof (u_short); 4805105Swnj *mtod(m, u_short *) = ENPUP_IPTYPE; 4816471Sroot *(mtod(m, u_short *) + 1) = m->m_len; 4825105Swnj goto gottrailertype; 4835083Swnj } 4845105Swnj type = ENPUP_IPTYPE; 4855105Swnj off = 0; 4865105Swnj goto gottype; 4875083Swnj #endif 4886027Ssam #ifdef PUP 4896335Ssam case AF_PUP: 4906335Ssam dest = ((struct sockaddr_pup *)dst)->spup_addr.pp_host; 4916027Ssam type = ENPUP_PUPTYPE; 4926027Ssam off = 0; 4936027Ssam goto gottype; 4946027Ssam #endif 4956027Ssam 4965083Swnj default: 4976335Ssam printf("en%d: can't handle af%d\n", ifp->if_unit, 4986335Ssam dst->sa_family); 4996503Ssam error = EAFNOSUPPORT; 5006503Ssam goto bad; 5014686Swnj } 5025105Swnj 5035171Swnj gottrailertype: 5045105Swnj /* 5055105Swnj * Packet to be sent as trailer: move first packet 5065105Swnj * (control information) to end of chain. 5075105Swnj */ 5085105Swnj while (m->m_next) 5095105Swnj m = m->m_next; 5105105Swnj m->m_next = m0; 5115105Swnj m = m0->m_next; 5125105Swnj m0->m_next = 0; 5135171Swnj m0 = m; 5145105Swnj 5155171Swnj gottype: 5165105Swnj /* 5175105Swnj * Add local net header. If no space in first mbuf, 5185105Swnj * allocate another. 5195105Swnj */ 5205213Swnj if (m->m_off > MMAXOFF || 5215213Swnj MMINOFF + sizeof (struct en_header) > m->m_off) { 5225584Sroot m = m_get(M_DONTWAIT); 5235083Swnj if (m == 0) { 5246503Ssam error = ENOBUFS; 5256503Ssam goto bad; 5265083Swnj } 5275083Swnj m->m_next = m0; 5285083Swnj m->m_off = MMINOFF; 5295083Swnj m->m_len = sizeof (struct en_header); 5305083Swnj } else { 5315083Swnj m->m_off -= sizeof (struct en_header); 5325083Swnj m->m_len += sizeof (struct en_header); 5335083Swnj } 5345083Swnj en = mtod(m, struct en_header *); 5355083Swnj en->en_shost = ifp->if_host[0]; 5365083Swnj en->en_dhost = dest; 5375083Swnj en->en_type = type; 5385105Swnj 5395105Swnj /* 5405105Swnj * Queue message on interface, and start output if interface 5415105Swnj * not yet active. 5425105Swnj */ 5435083Swnj s = splimp(); 5446207Swnj if (IF_QFULL(&ifp->if_snd)) { 5456207Swnj IF_DROP(&ifp->if_snd); 5466503Ssam error = ENOBUFS; 5476503Ssam goto qfull; 5486207Swnj } 5495083Swnj IF_ENQUEUE(&ifp->if_snd, m); 5505083Swnj if (en_softc[ifp->if_unit].es_oactive == 0) 5515083Swnj enstart(ifp->if_unit); 5525275Swnj splx(s); 5536503Ssam return (0); 5546503Ssam qfull: 5556503Ssam m0 = m; 5566503Ssam splx(s); 5576484Swnj bad: 5586503Ssam m_freem(m0); 5596503Ssam return (error); 5604686Swnj } 5616410Ssam 5626410Ssam #if NIMP == 0 && NEN > 0 5636410Ssam /* 5646410Ssam * Logical host interface driver. 5656410Ssam * Allows host to appear as an ARPAnet 5666410Ssam * logical host. Must also have routing 5676410Ssam * table entry set up to forward packets 5686410Ssam * to appropriate gateway on localnet. 5696410Ssam */ 5706410Ssam 5716410Ssam struct ifnet enlhif; 5726410Ssam int enlhoutput(); 5736410Ssam 5746410Ssam /* 5756410Ssam * Called by localnet interface to allow logical 5766410Ssam * host interface to "attach". Nothing should ever 5776410Ssam * be sent locally to this interface, it's purpose 5786410Ssam * is simply to establish the host's arpanet address. 5796410Ssam */ 5806410Ssam enlhinit(addr) 5816410Ssam int addr; 5826410Ssam { 5836410Ssam register struct ifnet *ifp = &enlhif; 5846410Ssam register struct sockaddr_in *sin; 5856410Ssam 5866410Ssam COUNT(ENLHINIT); 5876410Ssam ifp->if_name = "lh"; 5886410Ssam ifp->if_mtu = ENMTU; 5896410Ssam sin = (struct sockaddr_in *)&ifp->if_addr; 5906410Ssam sin->sin_family = AF_INET; 5916410Ssam sin->sin_addr.s_addr = addr; 5926410Ssam ifp->if_net = sin->sin_addr.s_net; 5936410Ssam ifp->if_flags = IFF_UP; 5946410Ssam ifp->if_output = enlhoutput; /* should never be used */ 5956410Ssam if_attach(ifp); 5966410Ssam } 5976410Ssam 5986410Ssam enlhoutput(ifp, m0, dst) 5996410Ssam struct ifnet *ifp; 6006410Ssam struct mbuf *m0; 6016410Ssam struct sockaddr *dst; 6026410Ssam { 6036410Ssam COUNT(ENLHOUTPUT); 6046410Ssam ifp->if_oerrors++; 6056410Ssam m_freem(m0); 6066410Ssam return (0); 6076410Ssam } 6086410Ssam #endif 609