1*6575Ssam /* if_en.c 4.58 82/04/20 */ 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; 88*6575Ssam #ifdef ECHACK 89*6575Ssam br = 0x16; 90*6575Ssam #endif 914686Swnj return (1); 924686Swnj } 934686Swnj 945105Swnj /* 955105Swnj * Interface exists: make available by filling in network interface 965105Swnj * record. System will initialize the interface when it is ready 975105Swnj * to accept packets. 985105Swnj */ 994686Swnj enattach(ui) 1004686Swnj struct uba_device *ui; 1014686Swnj { 1025105Swnj register struct en_softc *es = &en_softc[ui->ui_unit]; 1036335Ssam register struct sockaddr_in *sin; 1045105Swnj COUNT(ENATTACH); 1054688Swnj 1065105Swnj es->es_if.if_unit = ui->ui_unit; 1075171Swnj es->es_if.if_name = "en"; 1085105Swnj es->es_if.if_mtu = ENMTU; 1096433Ssam es->es_if.if_net = ui->ui_flags & 0xff; 1105105Swnj es->es_if.if_host[0] = 1116335Ssam (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff; 1126335Ssam sin = (struct sockaddr_in *)&es->es_if.if_addr; 1136335Ssam sin->sin_family = AF_INET; 1146335Ssam sin->sin_addr = if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]); 1156335Ssam sin = (struct sockaddr_in *)&es->es_if.if_broadaddr; 1166335Ssam sin->sin_family = AF_INET; 1176335Ssam sin->sin_addr = if_makeaddr(es->es_if.if_net, 0); 1186335Ssam es->es_if.if_flags = IFF_BROADCAST; 1195171Swnj es->es_if.if_init = eninit; 1205105Swnj es->es_if.if_output = enoutput; 1215105Swnj es->es_if.if_ubareset = enreset; 1226554Ssam es->es_ifuba.ifu_flags = UBA_NEEDBDP | UBA_NEED16 | UBA_CANTWAIT; 1235160Swnj if_attach(&es->es_if); 1246410Ssam #if NIMP == 0 1256410Ssam /* here's one for you john baby.... */ 1266422Sroot enlhinit((ui->ui_flags &~ 0xff) | 0x0a); 1276410Ssam #endif 1284686Swnj } 1294686Swnj 1305105Swnj /* 1315105Swnj * Reset of interface after UNIBUS reset. 1325105Swnj * If interface is on specified uba, reset its state. 1335105Swnj */ 1345105Swnj enreset(unit, uban) 1355105Swnj int unit, uban; 1365105Swnj { 1375105Swnj register struct uba_device *ui; 1385105Swnj COUNT(ENRESET); 1395105Swnj 1405171Swnj if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0 || 1415171Swnj ui->ui_ubanum != uban) 1425105Swnj return; 1435171Swnj printf(" en%d", unit); 1445105Swnj eninit(unit); 1455105Swnj } 1465105Swnj 1475105Swnj /* 1485105Swnj * Initialization of interface; clear recorded pending 1495105Swnj * operations, and reinitialize UNIBUS usage. 1505105Swnj */ 1514688Swnj eninit(unit) 1524686Swnj int unit; 1535083Swnj { 1545171Swnj register struct en_softc *es = &en_softc[unit]; 1555171Swnj register struct uba_device *ui = eninfo[unit]; 1564686Swnj register struct endevice *addr; 1575105Swnj int s; 1584686Swnj 1595105Swnj if (if_ubainit(&es->es_ifuba, ui->ui_ubanum, 1605708Sroot sizeof (struct en_header), (int)btoc(ENMTU)) == 0) { 1615171Swnj printf("en%d: can't initialize\n", unit); 1626335Ssam es->es_if.if_flags &= ~IFF_UP; 1635083Swnj return; 1644686Swnj } 1654686Swnj addr = (struct endevice *)ui->ui_addr; 1665083Swnj addr->en_istat = addr->en_ostat = 0; 1674686Swnj 1685105Swnj /* 1695171Swnj * Hang a receive and start any 1705171Swnj * pending writes by faking a transmit complete. 1715105Swnj */ 1725105Swnj s = splimp(); 1735171Swnj addr->en_iba = es->es_ifuba.ifu_r.ifrw_info; 1745171Swnj addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1; 1755171Swnj addr->en_istat = EN_IEN|EN_GO; 1765171Swnj es->es_oactive = 1; 1776335Ssam es->es_if.if_flags |= IFF_UP; 1785105Swnj enxint(unit); 1795105Swnj splx(s); 1806364Ssam if_rtinit(&es->es_if, RTF_DIRECT|RTF_UP); 1814686Swnj } 1824686Swnj 1836471Sroot int enalldelay = 0; 1844717Swnj int enlastdel = 25; 1856471Sroot int enlastmask = (~0) << 5; 1865083Swnj 1875105Swnj /* 1885105Swnj * Start or restart output on interface. 1895105Swnj * If interface is already active, then this is a retransmit 1905105Swnj * after a collision, and just restuff registers and delay. 1915105Swnj * If interface is not already active, get another datagram 1925105Swnj * to send off of the interface queue, and map it to the interface 1935105Swnj * before starting the output. 1945105Swnj */ 1954688Swnj enstart(dev) 1964686Swnj dev_t dev; 1974686Swnj { 1985171Swnj int unit = ENUNIT(dev); 1995171Swnj struct uba_device *ui = eninfo[unit]; 2005171Swnj register struct en_softc *es = &en_softc[unit]; 2015083Swnj register struct endevice *addr; 2025083Swnj struct mbuf *m; 2035083Swnj int dest; 2044688Swnj COUNT(ENSTART); 2054686Swnj 2065083Swnj if (es->es_oactive) 2075083Swnj goto restart; 2085105Swnj 2095105Swnj /* 2105105Swnj * Not already active: dequeue another request 2115105Swnj * and map it to the UNIBUS. If no more requests, 2125105Swnj * just return. 2135105Swnj */ 2145105Swnj IF_DEQUEUE(&es->es_if.if_snd, m); 2155083Swnj if (m == 0) { 2165083Swnj es->es_oactive = 0; 2174686Swnj return; 2184686Swnj } 2195213Swnj dest = mtod(m, struct en_header *)->en_dhost; 2205105Swnj es->es_olen = if_wubaput(&es->es_ifuba, m); 2215105Swnj 2225105Swnj /* 2235105Swnj * Ethernet cannot take back-to-back packets (no 2246471Sroot * buffering in interface. To help avoid overrunning 2256471Sroot * receivers, enforce a small delay (about 1ms) in interface: 2266471Sroot * * between all packets when enalldelay 2276471Sroot * * whenever last packet was broadcast 2286471Sroot * * whenever this packet is to same host as last packet 2295105Swnj */ 2306471Sroot if (enalldelay || es->es_lastx == 0 || es->es_lastx == dest) { 2315083Swnj es->es_delay = enlastdel; 2326471Sroot es->es_mask = enlastmask; 2336471Sroot } 2346471Sroot es->es_lastx = dest; 2355105Swnj 2365083Swnj restart: 2375105Swnj /* 2385105Swnj * Have request mapped to UNIBUS for transmission. 2395105Swnj * Purge any stale data from this BDP, and start the otput. 2405105Swnj */ 2416335Ssam if (es->es_ifuba.ifu_flags & UBA_NEEDBDP) 2426335Ssam UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_w.ifrw_bdp); 2434686Swnj addr = (struct endevice *)ui->ui_addr; 2445160Swnj addr->en_oba = (int)es->es_ifuba.ifu_w.ifrw_info; 2455083Swnj addr->en_odelay = es->es_delay; 2465083Swnj addr->en_owc = -((es->es_olen + 1) >> 1); 2474771Swnj addr->en_ostat = EN_IEN|EN_GO; 2485083Swnj es->es_oactive = 1; 2494686Swnj } 2504686Swnj 2515105Swnj /* 2525105Swnj * Ethernet interface transmitter interrupt. 2535105Swnj * Start another output if more data to send. 2545105Swnj */ 2554686Swnj enxint(unit) 2564686Swnj int unit; 2574686Swnj { 2585171Swnj register struct uba_device *ui = eninfo[unit]; 2595171Swnj register struct en_softc *es = &en_softc[unit]; 2606242Sroot register struct endevice *addr = (struct endevice *)ui->ui_addr; 2614686Swnj COUNT(ENXINT); 2624686Swnj 2635083Swnj if (es->es_oactive == 0) 2645083Swnj return; 2656242Sroot if (es->es_mask && (addr->en_ostat&EN_OERROR)) { 2666242Sroot es->es_if.if_oerrors++; 2676242Sroot if (es->es_if.if_oerrors % 100 == 0) 2686242Sroot printf("en%d: += 100 output errors\n", unit); 2696242Sroot endocoll(unit); 2706242Sroot return; 2716242Sroot } 2725171Swnj es->es_if.if_opackets++; 2735083Swnj es->es_oactive = 0; 2745083Swnj es->es_delay = 0; 2755083Swnj es->es_mask = ~0; 2765696Sroot if (es->es_ifuba.ifu_xtofree) { 2775696Sroot m_freem(es->es_ifuba.ifu_xtofree); 2785696Sroot es->es_ifuba.ifu_xtofree = 0; 2795696Sroot } 2805105Swnj if (es->es_if.if_snd.ifq_head == 0) { 2816471Sroot es->es_lastx = 256; /* putatively illegal */ 2824686Swnj return; 2834686Swnj } 2845083Swnj enstart(unit); 2854686Swnj } 2864686Swnj 2875105Swnj /* 2885105Swnj * Collision on ethernet interface. Do exponential 2895105Swnj * backoff, and retransmit. If have backed off all 2906335Ssam * the way print warning diagnostic, and drop packet. 2915105Swnj */ 2924686Swnj encollide(unit) 2934686Swnj int unit; 2944686Swnj { 2956242Sroot struct en_softc *es = &en_softc[unit]; 2964686Swnj COUNT(ENCOLLIDE); 2974686Swnj 2985105Swnj es->es_if.if_collisions++; 2995083Swnj if (es->es_oactive == 0) 3004686Swnj return; 3016242Sroot endocoll(unit); 3026242Sroot } 3036242Sroot 3046242Sroot endocoll(unit) 3056242Sroot int unit; 3066242Sroot { 3076242Sroot register struct en_softc *es = &en_softc[unit]; 3086242Sroot 3095171Swnj /* 3105171Swnj * Es_mask is a 16 bit number with n low zero bits, with 3115171Swnj * n the number of backoffs. When es_mask is 0 we have 3125171Swnj * backed off 16 times, and give up. 3135171Swnj */ 3145083Swnj if (es->es_mask == 0) { 3155213Swnj printf("en%d: send error\n", unit); 3165083Swnj enxint(unit); 3175171Swnj return; 3184686Swnj } 3195171Swnj /* 3205171Swnj * Another backoff. Restart with delay based on n low bits 3215171Swnj * of the interval timer. 3225171Swnj */ 3235171Swnj es->es_mask <<= 1; 3245171Swnj es->es_delay = mfpr(ICR) &~ es->es_mask; 3255171Swnj enstart(unit); 3264686Swnj } 3274686Swnj 3286027Ssam struct sockaddr_pup pupsrc = { AF_PUP }; 3296027Ssam struct sockaddr_pup pupdst = { AF_PUP }; 3306027Ssam struct sockproto pupproto = { PF_PUP }; 3315105Swnj /* 3325105Swnj * Ethernet interface receiver interrupt. 3335105Swnj * If input error just drop packet. 3345105Swnj * Otherwise purge input buffered data path and examine 3355105Swnj * packet to determine type. If can't determine length 3365105Swnj * from type, then have to drop packet. Othewise decapsulate 3375105Swnj * packet based on type and pass to type specific higher-level 3385105Swnj * input routine. 3395105Swnj */ 3404686Swnj enrint(unit) 3414686Swnj int unit; 3424686Swnj { 3435171Swnj register struct en_softc *es = &en_softc[unit]; 3445171Swnj struct endevice *addr = (struct endevice *)eninfo[unit]->ui_addr; 3455171Swnj register struct en_header *en; 3465083Swnj struct mbuf *m; 3476471Sroot int len, plen; short resid; 3485171Swnj register struct ifqueue *inq; 3495083Swnj int off; 3504686Swnj COUNT(ENRINT); 3514686Swnj 3525171Swnj es->es_if.if_ipackets++; 3535105Swnj 3545105Swnj /* 3555171Swnj * Purge BDP; drop if input error indicated. 3565105Swnj */ 3576335Ssam if (es->es_ifuba.ifu_flags & UBA_NEEDBDP) 3586335Ssam UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp); 3594771Swnj if (addr->en_istat&EN_IERROR) { 3605105Swnj es->es_if.if_ierrors++; 3616238Sroot if (es->es_if.if_ierrors % 100 == 0) 3626238Sroot printf("en%d: += 100 input errors\n", unit); 3635083Swnj goto setup; 3644686Swnj } 3655105Swnj 3665105Swnj /* 3676471Sroot * Calculate input data length. 3685105Swnj * Get pointer to ethernet header (in input buffer). 3695105Swnj * Deal with trailer protocol: if type is PUP trailer 3705105Swnj * get true type from first 16-bit word past data. 3715105Swnj * Remember that type was trailer by setting off. 3725105Swnj */ 3736471Sroot resid = addr->en_iwc; 3746471Sroot if (resid) 3756471Sroot resid |= 0176000; 3766471Sroot len = (((sizeof (struct en_header) + ENMTU) >> 1) + resid) << 1; 3776471Sroot len -= sizeof (struct en_header); 3786471Sroot if (len >= ENMTU) 3796471Sroot goto setup; /* sanity */ 3805105Swnj en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr); 3815083Swnj #define endataaddr(en, off, type) ((type)(((caddr_t)((en)+1)+(off)))) 3825083Swnj if (en->en_type >= ENPUP_TRAIL && 3835083Swnj en->en_type < ENPUP_TRAIL+ENPUP_NTRAILER) { 3845083Swnj off = (en->en_type - ENPUP_TRAIL) * 512; 3855171Swnj if (off >= ENMTU) 3865171Swnj goto setup; /* sanity */ 3875083Swnj en->en_type = *endataaddr(en, off, u_short *); 3886471Sroot resid = *(endataaddr(en, off+2, u_short *)); 3896471Sroot if (off + resid > len) 3906471Sroot goto setup; /* sanity */ 3916471Sroot len = off + resid; 3925083Swnj } else 3935083Swnj off = 0; 3945083Swnj if (len == 0) 3955083Swnj goto setup; 3965105Swnj /* 3975105Swnj * Pull packet off interface. Off is nonzero if packet 3985105Swnj * has trailing header; if_rubaget will then force this header 3995105Swnj * information to be at the front, but we still have to drop 4006471Sroot * the type and length which are at the front of any trailer data. 4015105Swnj */ 4025105Swnj m = if_rubaget(&es->es_ifuba, len, off); 4035213Swnj if (m == 0) 4045213Swnj goto setup; 4055105Swnj if (off) { 4066471Sroot m->m_off += 2 * sizeof (u_short); 4076471Sroot m->m_len -= 2 * sizeof (u_short); 4085105Swnj } 4096027Ssam switch (en->en_type) { 4106027Ssam 4116027Ssam #ifdef INET 4126027Ssam case ENPUP_IPTYPE: 4136260Swnj schednetisr(NETISR_IP); 4146027Ssam inq = &ipintrq; 4156027Ssam break; 4166027Ssam #endif 4176335Ssam #ifdef PUP 4186027Ssam case ENPUP_PUPTYPE: { 4196027Ssam struct pup_header *pup = mtod(m, struct pup_header *); 4206027Ssam 4216027Ssam pupproto.sp_protocol = pup->pup_type; 4226027Ssam pupdst.spup_addr = pup->pup_dport; 4236027Ssam pupsrc.spup_addr = pup->pup_sport; 4246526Ssam raw_input(m, &pupproto, (struct sockaddr *)&pupsrc, 4256526Ssam (struct sockaddr *)&pupdst); 4266027Ssam goto setup; 4276027Ssam } 4286335Ssam #endif 4296476Swnj default: 4306476Swnj m_freem(m); 4316476Swnj goto setup; 4326335Ssam } 4336335Ssam 4346207Swnj if (IF_QFULL(inq)) { 4356207Swnj IF_DROP(inq); 4366335Ssam m_freem(m); 4376207Swnj } else 4386207Swnj IF_ENQUEUE(inq, m); 4395105Swnj 4404688Swnj setup: 4415105Swnj /* 4425105Swnj * Reset for next packet. 4435105Swnj */ 4445105Swnj addr->en_iba = es->es_ifuba.ifu_r.ifrw_info; 4455083Swnj addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1; 4464771Swnj addr->en_istat = EN_IEN|EN_GO; 4474688Swnj } 4484686Swnj 4495083Swnj /* 4505083Swnj * Ethernet output routine. 4515083Swnj * Encapsulate a packet of type family for the local net. 4525105Swnj * Use trailer local net encapsulation if enough data in first 4535105Swnj * packet leaves a multiple of 512 bytes of data in remainder. 4545083Swnj */ 4556335Ssam enoutput(ifp, m0, dst) 4565083Swnj struct ifnet *ifp; 4575083Swnj struct mbuf *m0; 4586335Ssam struct sockaddr *dst; 4594686Swnj { 4606503Ssam int type, dest, s, error; 4615105Swnj register struct mbuf *m = m0; 4625083Swnj register struct en_header *en; 4636335Ssam register int off; 4644686Swnj 4655927Sroot COUNT(ENOUTPUT); 4666335Ssam switch (dst->sa_family) { 4675083Swnj 4685083Swnj #ifdef INET 4696335Ssam case AF_INET: 4706484Swnj dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr; 4716503Ssam if (dest & 0x00ffff00) { 4726503Ssam error = EPERM; /* ??? */ 4736486Swnj goto bad; 4746503Ssam } 4756484Swnj dest = (dest >> 24) & 0xff; 4766335Ssam off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len; 4776335Ssam if (off > 0 && (off & 0x1ff) == 0 && 4786471Sroot m->m_off >= MMINOFF + 2 * sizeof (u_short)) { 4795083Swnj type = ENPUP_TRAIL + (off>>9); 4806471Sroot m->m_off -= 2 * sizeof (u_short); 4816471Sroot m->m_len += 2 * sizeof (u_short); 4825105Swnj *mtod(m, u_short *) = ENPUP_IPTYPE; 4836471Sroot *(mtod(m, u_short *) + 1) = m->m_len; 4845105Swnj goto gottrailertype; 4855083Swnj } 4865105Swnj type = ENPUP_IPTYPE; 4875105Swnj off = 0; 4885105Swnj goto gottype; 4895083Swnj #endif 4906027Ssam #ifdef PUP 4916335Ssam case AF_PUP: 4926335Ssam dest = ((struct sockaddr_pup *)dst)->spup_addr.pp_host; 4936027Ssam type = ENPUP_PUPTYPE; 4946027Ssam off = 0; 4956027Ssam goto gottype; 4966027Ssam #endif 4976027Ssam 4985083Swnj default: 4996335Ssam printf("en%d: can't handle af%d\n", ifp->if_unit, 5006335Ssam dst->sa_family); 5016503Ssam error = EAFNOSUPPORT; 5026503Ssam goto bad; 5034686Swnj } 5045105Swnj 5055171Swnj gottrailertype: 5065105Swnj /* 5075105Swnj * Packet to be sent as trailer: move first packet 5085105Swnj * (control information) to end of chain. 5095105Swnj */ 5105105Swnj while (m->m_next) 5115105Swnj m = m->m_next; 5125105Swnj m->m_next = m0; 5135105Swnj m = m0->m_next; 5145105Swnj m0->m_next = 0; 5155171Swnj m0 = m; 5165105Swnj 5175171Swnj gottype: 5185105Swnj /* 5195105Swnj * Add local net header. If no space in first mbuf, 5205105Swnj * allocate another. 5215105Swnj */ 5225213Swnj if (m->m_off > MMAXOFF || 5235213Swnj MMINOFF + sizeof (struct en_header) > m->m_off) { 5245584Sroot m = m_get(M_DONTWAIT); 5255083Swnj if (m == 0) { 5266503Ssam error = ENOBUFS; 5276503Ssam goto bad; 5285083Swnj } 5295083Swnj m->m_next = m0; 5305083Swnj m->m_off = MMINOFF; 5315083Swnj m->m_len = sizeof (struct en_header); 5325083Swnj } else { 5335083Swnj m->m_off -= sizeof (struct en_header); 5345083Swnj m->m_len += sizeof (struct en_header); 5355083Swnj } 5365083Swnj en = mtod(m, struct en_header *); 5375083Swnj en->en_shost = ifp->if_host[0]; 5385083Swnj en->en_dhost = dest; 5395083Swnj en->en_type = type; 5405105Swnj 5415105Swnj /* 5425105Swnj * Queue message on interface, and start output if interface 5435105Swnj * not yet active. 5445105Swnj */ 5455083Swnj s = splimp(); 5466207Swnj if (IF_QFULL(&ifp->if_snd)) { 5476207Swnj IF_DROP(&ifp->if_snd); 5486503Ssam error = ENOBUFS; 5496503Ssam goto qfull; 5506207Swnj } 5515083Swnj IF_ENQUEUE(&ifp->if_snd, m); 5525083Swnj if (en_softc[ifp->if_unit].es_oactive == 0) 5535083Swnj enstart(ifp->if_unit); 5545275Swnj splx(s); 5556503Ssam return (0); 5566503Ssam qfull: 5576503Ssam m0 = m; 5586503Ssam splx(s); 5596484Swnj bad: 5606503Ssam m_freem(m0); 5616503Ssam return (error); 5624686Swnj } 5636410Ssam 5646410Ssam #if NIMP == 0 && NEN > 0 5656410Ssam /* 5666410Ssam * Logical host interface driver. 5676410Ssam * Allows host to appear as an ARPAnet 5686410Ssam * logical host. Must also have routing 5696410Ssam * table entry set up to forward packets 5706410Ssam * to appropriate gateway on localnet. 5716410Ssam */ 5726410Ssam 5736410Ssam struct ifnet enlhif; 5746410Ssam int enlhoutput(); 5756410Ssam 5766410Ssam /* 5776410Ssam * Called by localnet interface to allow logical 5786410Ssam * host interface to "attach". Nothing should ever 5796410Ssam * be sent locally to this interface, it's purpose 5806410Ssam * is simply to establish the host's arpanet address. 5816410Ssam */ 5826410Ssam enlhinit(addr) 5836410Ssam int addr; 5846410Ssam { 5856410Ssam register struct ifnet *ifp = &enlhif; 5866410Ssam register struct sockaddr_in *sin; 5876410Ssam 5886410Ssam COUNT(ENLHINIT); 5896410Ssam ifp->if_name = "lh"; 5906410Ssam ifp->if_mtu = ENMTU; 5916410Ssam sin = (struct sockaddr_in *)&ifp->if_addr; 5926410Ssam sin->sin_family = AF_INET; 5936410Ssam sin->sin_addr.s_addr = addr; 5946410Ssam ifp->if_net = sin->sin_addr.s_net; 5956410Ssam ifp->if_flags = IFF_UP; 5966410Ssam ifp->if_output = enlhoutput; /* should never be used */ 5976410Ssam if_attach(ifp); 5986410Ssam } 5996410Ssam 6006410Ssam enlhoutput(ifp, m0, dst) 6016410Ssam struct ifnet *ifp; 6026410Ssam struct mbuf *m0; 6036410Ssam struct sockaddr *dst; 6046410Ssam { 6056410Ssam COUNT(ENLHOUTPUT); 6066410Ssam ifp->if_oerrors++; 6076410Ssam m_freem(m0); 6086410Ssam return (0); 6096410Ssam } 6106410Ssam #endif 611