1*6410Ssam /* if_en.c 4.47 82/03/31 */ 24686Swnj 34686Swnj #include "en.h" 4*6410Ssam #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" 324686Swnj 335213Swnj #define ENMTU (1024+512) 345083Swnj 354686Swnj int enprobe(), enattach(), enrint(), enxint(), encollide(); 364686Swnj struct uba_device *eninfo[NEN]; 374686Swnj u_short enstd[] = { 0 }; 384686Swnj struct uba_driver endriver = 395171Swnj { enprobe, 0, enattach, 0, enstd, "en", eninfo }; 404686Swnj #define ENUNIT(x) minor(x) 414686Swnj 425105Swnj int eninit(),enoutput(),enreset(); 435105Swnj 445105Swnj /* 455105Swnj * Ethernet software status per interface. 465105Swnj * 475105Swnj * Each interface is referenced by a network interface structure, 485105Swnj * es_if, which the routing code uses to locate the interface. 495105Swnj * This structure contains the output queue for the interface, its address, ... 505105Swnj * We also have, for each interface, a UBA interface structure, which 515105Swnj * contains information about the UNIBUS resources held by the interface: 525105Swnj * map registers, buffered data paths, etc. Information is cached in this 535105Swnj * structure for use by the if_uba.c routines in running the interface 545105Swnj * efficiently. 555105Swnj */ 565083Swnj struct en_softc { 575105Swnj struct ifnet es_if; /* network-visible interface */ 585105Swnj struct ifuba es_ifuba; /* UNIBUS resources */ 595105Swnj short es_delay; /* current output delay */ 605105Swnj short es_mask; /* mask for current output delay */ 615105Swnj u_char es_lastx; /* host last transmitted to */ 625105Swnj short es_oactive; /* is output active? */ 635105Swnj short es_olen; /* length of last output */ 645083Swnj } en_softc[NEN]; 654686Swnj 665105Swnj /* 675105Swnj * Do output DMA to determine interface presence and 685105Swnj * interrupt vector. DMA is too short to disturb other hosts. 695105Swnj */ 704686Swnj enprobe(reg) 714686Swnj caddr_t reg; 724686Swnj { 735171Swnj register int br, cvec; /* r11, r10 value-result */ 744686Swnj register struct endevice *addr = (struct endevice *)reg; 754686Swnj 765083Swnj COUNT(ENPROBE); 774686Swnj #ifdef lint 784686Swnj br = 0; cvec = br; br = cvec; 794922Swnj enrint(0); enxint(0); encollide(0); 804686Swnj #endif 814686Swnj addr->en_istat = 0; 824686Swnj addr->en_owc = -1; 834686Swnj addr->en_oba = 0; 844771Swnj addr->en_ostat = EN_IEN|EN_GO; 854686Swnj DELAY(100000); 864686Swnj addr->en_ostat = 0; 874686Swnj return (1); 884686Swnj } 894686Swnj 905105Swnj /* 915105Swnj * Interface exists: make available by filling in network interface 925105Swnj * record. System will initialize the interface when it is ready 935105Swnj * to accept packets. 945105Swnj */ 954686Swnj enattach(ui) 964686Swnj struct uba_device *ui; 974686Swnj { 985105Swnj register struct en_softc *es = &en_softc[ui->ui_unit]; 996335Ssam register struct sockaddr_in *sin; 1005105Swnj COUNT(ENATTACH); 1014688Swnj 1025105Swnj es->es_if.if_unit = ui->ui_unit; 1035171Swnj es->es_if.if_name = "en"; 1045105Swnj es->es_if.if_mtu = ENMTU; 105*6410Ssam es->es_if.if_net = ui->ui_flags & 0xffff; 1065105Swnj es->es_if.if_host[0] = 1076335Ssam (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff; 1086335Ssam sin = (struct sockaddr_in *)&es->es_if.if_addr; 1096335Ssam sin->sin_family = AF_INET; 1106335Ssam sin->sin_addr = if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]); 1116335Ssam sin = (struct sockaddr_in *)&es->es_if.if_broadaddr; 1126335Ssam sin->sin_family = AF_INET; 1136335Ssam sin->sin_addr = if_makeaddr(es->es_if.if_net, 0); 1146335Ssam es->es_if.if_flags = IFF_BROADCAST; 1155171Swnj es->es_if.if_init = eninit; 1165105Swnj es->es_if.if_output = enoutput; 1175105Swnj es->es_if.if_ubareset = enreset; 1185696Sroot es->es_ifuba.ifu_flags = UBA_NEEDBDP | UBA_NEED16; 1195160Swnj if_attach(&es->es_if); 120*6410Ssam #if NIMP == 0 121*6410Ssam /* here's one for you john baby.... */ 122*6410Ssam enlhinit(&es->es_if, (ui->ui_flags &~ 0xff) | 0x0a); 123*6410Ssam #endif 1244686Swnj } 1254686Swnj 1265105Swnj /* 1275105Swnj * Reset of interface after UNIBUS reset. 1285105Swnj * If interface is on specified uba, reset its state. 1295105Swnj */ 1305105Swnj enreset(unit, uban) 1315105Swnj int unit, uban; 1325105Swnj { 1335105Swnj register struct uba_device *ui; 1345105Swnj COUNT(ENRESET); 1355105Swnj 1365171Swnj if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0 || 1375171Swnj ui->ui_ubanum != uban) 1385105Swnj return; 1395171Swnj printf(" en%d", unit); 1405105Swnj eninit(unit); 1415105Swnj } 1425105Swnj 1435105Swnj /* 1445105Swnj * Initialization of interface; clear recorded pending 1455105Swnj * operations, and reinitialize UNIBUS usage. 1465105Swnj */ 1474688Swnj eninit(unit) 1484686Swnj int unit; 1495083Swnj { 1505171Swnj register struct en_softc *es = &en_softc[unit]; 1515171Swnj register struct uba_device *ui = eninfo[unit]; 1524686Swnj register struct endevice *addr; 1535105Swnj int s; 1544686Swnj 1555105Swnj if (if_ubainit(&es->es_ifuba, ui->ui_ubanum, 1565708Sroot sizeof (struct en_header), (int)btoc(ENMTU)) == 0) { 1575171Swnj printf("en%d: can't initialize\n", unit); 1586335Ssam es->es_if.if_flags &= ~IFF_UP; 1595083Swnj return; 1604686Swnj } 1614686Swnj addr = (struct endevice *)ui->ui_addr; 1625083Swnj addr->en_istat = addr->en_ostat = 0; 1634686Swnj 1645105Swnj /* 1655171Swnj * Hang a receive and start any 1665171Swnj * pending writes by faking a transmit complete. 1675105Swnj */ 1685105Swnj s = splimp(); 1695171Swnj addr->en_iba = es->es_ifuba.ifu_r.ifrw_info; 1705171Swnj addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1; 1715171Swnj addr->en_istat = EN_IEN|EN_GO; 1725171Swnj es->es_oactive = 1; 1736335Ssam es->es_if.if_flags |= IFF_UP; 1745105Swnj enxint(unit); 1755105Swnj splx(s); 1766364Ssam if_rtinit(&es->es_if, RTF_DIRECT|RTF_UP); 1774686Swnj } 1784686Swnj 1794717Swnj int enlastdel = 25; 1805083Swnj 1815105Swnj /* 1825105Swnj * Start or restart output on interface. 1835105Swnj * If interface is already active, then this is a retransmit 1845105Swnj * after a collision, and just restuff registers and delay. 1855105Swnj * If interface is not already active, get another datagram 1865105Swnj * to send off of the interface queue, and map it to the interface 1875105Swnj * before starting the output. 1885105Swnj */ 1894688Swnj enstart(dev) 1904686Swnj dev_t dev; 1914686Swnj { 1925171Swnj int unit = ENUNIT(dev); 1935171Swnj struct uba_device *ui = eninfo[unit]; 1945171Swnj register struct en_softc *es = &en_softc[unit]; 1955083Swnj register struct endevice *addr; 1965083Swnj struct mbuf *m; 1975083Swnj int dest; 1984688Swnj COUNT(ENSTART); 1994686Swnj 2005083Swnj if (es->es_oactive) 2015083Swnj goto restart; 2025105Swnj 2035105Swnj /* 2045105Swnj * Not already active: dequeue another request 2055105Swnj * and map it to the UNIBUS. If no more requests, 2065105Swnj * just return. 2075105Swnj */ 2085105Swnj IF_DEQUEUE(&es->es_if.if_snd, m); 2095083Swnj if (m == 0) { 2105083Swnj es->es_oactive = 0; 2114686Swnj return; 2124686Swnj } 2135213Swnj dest = mtod(m, struct en_header *)->en_dhost; 2145105Swnj es->es_olen = if_wubaput(&es->es_ifuba, m); 2155105Swnj 2165105Swnj /* 2175105Swnj * Ethernet cannot take back-to-back packets (no 2185105Swnj * buffering in interface. To avoid overrunning 2195105Swnj * receiver, enforce a small delay (about 1ms) in interface 2205105Swnj * on successive packets sent to same host. 2215105Swnj */ 2225083Swnj if (es->es_lastx && es->es_lastx == dest) 2235083Swnj es->es_delay = enlastdel; 2245083Swnj else 2255083Swnj es->es_lastx = dest; 2265105Swnj 2275083Swnj restart: 2285105Swnj /* 2295105Swnj * Have request mapped to UNIBUS for transmission. 2305105Swnj * Purge any stale data from this BDP, and start the otput. 2315105Swnj */ 2326335Ssam if (es->es_ifuba.ifu_flags & UBA_NEEDBDP) 2336335Ssam UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_w.ifrw_bdp); 2344686Swnj addr = (struct endevice *)ui->ui_addr; 2355160Swnj addr->en_oba = (int)es->es_ifuba.ifu_w.ifrw_info; 2365083Swnj addr->en_odelay = es->es_delay; 2375083Swnj addr->en_owc = -((es->es_olen + 1) >> 1); 2384771Swnj addr->en_ostat = EN_IEN|EN_GO; 2395083Swnj es->es_oactive = 1; 2404686Swnj } 2414686Swnj 2425105Swnj /* 2435105Swnj * Ethernet interface transmitter interrupt. 2445105Swnj * Start another output if more data to send. 2455105Swnj */ 2464686Swnj enxint(unit) 2474686Swnj int unit; 2484686Swnj { 2495171Swnj register struct uba_device *ui = eninfo[unit]; 2505171Swnj register struct en_softc *es = &en_softc[unit]; 2516242Sroot register struct endevice *addr = (struct endevice *)ui->ui_addr; 2524686Swnj COUNT(ENXINT); 2534686Swnj 2545083Swnj if (es->es_oactive == 0) 2555083Swnj return; 2566242Sroot if (es->es_mask && (addr->en_ostat&EN_OERROR)) { 2576242Sroot es->es_if.if_oerrors++; 2586242Sroot if (es->es_if.if_oerrors % 100 == 0) 2596242Sroot printf("en%d: += 100 output errors\n", unit); 2606242Sroot endocoll(unit); 2616242Sroot return; 2626242Sroot } 2635171Swnj es->es_if.if_opackets++; 2645083Swnj es->es_oactive = 0; 2655083Swnj es->es_delay = 0; 2665083Swnj es->es_mask = ~0; 2675696Sroot if (es->es_ifuba.ifu_xtofree) { 2685696Sroot m_freem(es->es_ifuba.ifu_xtofree); 2695696Sroot es->es_ifuba.ifu_xtofree = 0; 2705696Sroot } 2715105Swnj if (es->es_if.if_snd.ifq_head == 0) { 2725083Swnj es->es_lastx = 0; 2734686Swnj return; 2744686Swnj } 2755083Swnj enstart(unit); 2764686Swnj } 2774686Swnj 2785105Swnj /* 2795105Swnj * Collision on ethernet interface. Do exponential 2805105Swnj * backoff, and retransmit. If have backed off all 2816335Ssam * the way print warning diagnostic, and drop packet. 2825105Swnj */ 2834686Swnj encollide(unit) 2844686Swnj int unit; 2854686Swnj { 2866242Sroot struct en_softc *es = &en_softc[unit]; 2874686Swnj COUNT(ENCOLLIDE); 2884686Swnj 2895105Swnj es->es_if.if_collisions++; 2905083Swnj if (es->es_oactive == 0) 2914686Swnj return; 2926242Sroot endocoll(unit); 2936242Sroot } 2946242Sroot 2956242Sroot endocoll(unit) 2966242Sroot int unit; 2976242Sroot { 2986242Sroot register struct en_softc *es = &en_softc[unit]; 2996242Sroot 3005171Swnj /* 3015171Swnj * Es_mask is a 16 bit number with n low zero bits, with 3025171Swnj * n the number of backoffs. When es_mask is 0 we have 3035171Swnj * backed off 16 times, and give up. 3045171Swnj */ 3055083Swnj if (es->es_mask == 0) { 3065213Swnj printf("en%d: send error\n", unit); 3075083Swnj enxint(unit); 3085171Swnj return; 3094686Swnj } 3105171Swnj /* 3115171Swnj * Another backoff. Restart with delay based on n low bits 3125171Swnj * of the interval timer. 3135171Swnj */ 3145171Swnj es->es_mask <<= 1; 3155171Swnj es->es_delay = mfpr(ICR) &~ es->es_mask; 3165171Swnj enstart(unit); 3174686Swnj } 3184686Swnj 3196027Ssam struct sockaddr_pup pupsrc = { AF_PUP }; 3206027Ssam struct sockaddr_pup pupdst = { AF_PUP }; 3216027Ssam struct sockproto pupproto = { PF_PUP }; 3225105Swnj /* 3235105Swnj * Ethernet interface receiver interrupt. 3245105Swnj * If input error just drop packet. 3255105Swnj * Otherwise purge input buffered data path and examine 3265105Swnj * packet to determine type. If can't determine length 3275105Swnj * from type, then have to drop packet. Othewise decapsulate 3285105Swnj * packet based on type and pass to type specific higher-level 3295105Swnj * input routine. 3305105Swnj */ 3314686Swnj enrint(unit) 3324686Swnj int unit; 3334686Swnj { 3345171Swnj register struct en_softc *es = &en_softc[unit]; 3355171Swnj struct endevice *addr = (struct endevice *)eninfo[unit]->ui_addr; 3365171Swnj register struct en_header *en; 3375083Swnj struct mbuf *m; 3385171Swnj int len; 3395171Swnj register struct ifqueue *inq; 3405083Swnj int off; 3414686Swnj COUNT(ENRINT); 3424686Swnj 3435171Swnj es->es_if.if_ipackets++; 3445105Swnj 3455105Swnj /* 3465171Swnj * Purge BDP; drop if input error indicated. 3475105Swnj */ 3486335Ssam if (es->es_ifuba.ifu_flags & UBA_NEEDBDP) 3496335Ssam UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp); 3504771Swnj if (addr->en_istat&EN_IERROR) { 3515105Swnj es->es_if.if_ierrors++; 3526238Sroot if (es->es_if.if_ierrors % 100 == 0) 3536238Sroot printf("en%d: += 100 input errors\n", unit); 3545083Swnj goto setup; 3554686Swnj } 3565105Swnj 3575105Swnj /* 3585105Swnj * Get pointer to ethernet header (in input buffer). 3595105Swnj * Deal with trailer protocol: if type is PUP trailer 3605105Swnj * get true type from first 16-bit word past data. 3615105Swnj * Remember that type was trailer by setting off. 3625105Swnj */ 3635105Swnj en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr); 3645083Swnj #define endataaddr(en, off, type) ((type)(((caddr_t)((en)+1)+(off)))) 3655083Swnj if (en->en_type >= ENPUP_TRAIL && 3665083Swnj en->en_type < ENPUP_TRAIL+ENPUP_NTRAILER) { 3675083Swnj off = (en->en_type - ENPUP_TRAIL) * 512; 3685171Swnj if (off >= ENMTU) 3695171Swnj goto setup; /* sanity */ 3705083Swnj en->en_type = *endataaddr(en, off, u_short *); 3715083Swnj } else 3725083Swnj off = 0; 3735105Swnj 3745105Swnj /* 3755105Swnj * Attempt to infer packet length from type; 3765105Swnj * can't deal with packet if can't infer length. 3775105Swnj */ 3785083Swnj switch (en->en_type) { 3795083Swnj 3805083Swnj #ifdef INET 3815083Swnj case ENPUP_IPTYPE: 3826335Ssam len = htons((u_short)endataaddr(en, 3836335Ssam off ? off + sizeof (u_short) : 0, struct ip *)->ip_len); 3844686Swnj break; 3854686Swnj #endif 3866027Ssam #ifdef PUP 3876027Ssam case ENPUP_PUPTYPE: 3886335Ssam len = endataaddr(en, off ? off + sizeof (u_short) : 0, 3896335Ssam struct pup_header *)->pup_length; 3906027Ssam break; 3916027Ssam #endif 3926027Ssam 3935083Swnj default: 3946026Sroot printf("en%d: unknown pkt type 0x%x\n", unit, en->en_type); 3955083Swnj goto setup; 3964686Swnj } 3976376Ssam if (off) 3986376Ssam len += sizeof (u_short); 3995083Swnj if (len == 0) 4005083Swnj goto setup; 4015105Swnj 4025105Swnj /* 4035105Swnj * Pull packet off interface. Off is nonzero if packet 4045105Swnj * has trailing header; if_rubaget will then force this header 4055105Swnj * information to be at the front, but we still have to drop 4065171Swnj * the two-byte type which is at the front of any trailer data. 4075105Swnj */ 4085105Swnj m = if_rubaget(&es->es_ifuba, len, off); 4095213Swnj if (m == 0) 4105213Swnj goto setup; 4115105Swnj if (off) { 4126335Ssam m->m_off += sizeof (u_short); 4136335Ssam m->m_len -= sizeof (u_short); 4145105Swnj } 4156027Ssam switch (en->en_type) { 4166027Ssam 4176027Ssam #ifdef INET 4186027Ssam case ENPUP_IPTYPE: 4196260Swnj schednetisr(NETISR_IP); 4206027Ssam inq = &ipintrq; 4216027Ssam break; 4226027Ssam #endif 4236335Ssam #ifdef PUP 4246027Ssam case ENPUP_PUPTYPE: { 4256027Ssam struct pup_header *pup = mtod(m, struct pup_header *); 4266027Ssam 4276027Ssam pupproto.sp_protocol = pup->pup_type; 4286027Ssam pupdst.spup_addr = pup->pup_dport; 4296027Ssam pupsrc.spup_addr = pup->pup_sport; 4306159Ssam raw_input(m, &pupproto, (struct sockaddr *)&pupdst, 4316335Ssam (struct sockaddr *)&pupsrc); 4326027Ssam goto setup; 4336027Ssam } 4346335Ssam #endif 4356335Ssam } 4366335Ssam 4376207Swnj if (IF_QFULL(inq)) { 4386207Swnj IF_DROP(inq); 4396335Ssam m_freem(m); 4406207Swnj } else 4416207Swnj IF_ENQUEUE(inq, m); 4425105Swnj 4434688Swnj setup: 4445105Swnj /* 4455105Swnj * Reset for next packet. 4465105Swnj */ 4475105Swnj addr->en_iba = es->es_ifuba.ifu_r.ifrw_info; 4485083Swnj addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1; 4494771Swnj addr->en_istat = EN_IEN|EN_GO; 4504688Swnj } 4514686Swnj 4525083Swnj /* 4535083Swnj * Ethernet output routine. 4545083Swnj * Encapsulate a packet of type family for the local net. 4555105Swnj * Use trailer local net encapsulation if enough data in first 4565105Swnj * packet leaves a multiple of 512 bytes of data in remainder. 4575083Swnj */ 4586335Ssam enoutput(ifp, m0, dst) 4595083Swnj struct ifnet *ifp; 4605083Swnj struct mbuf *m0; 4616335Ssam struct sockaddr *dst; 4624686Swnj { 4636335Ssam int type, dest, s; 4645105Swnj register struct mbuf *m = m0; 4655083Swnj register struct en_header *en; 4666335Ssam register int off; 4674686Swnj 4685927Sroot COUNT(ENOUTPUT); 4696335Ssam switch (dst->sa_family) { 4705083Swnj 4715083Swnj #ifdef INET 4726335Ssam case AF_INET: 4736335Ssam dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr >> 24; 4746335Ssam off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len; 4756335Ssam if (off > 0 && (off & 0x1ff) == 0 && 4766335Ssam m->m_off >= MMINOFF + sizeof (u_short)) { 4775083Swnj type = ENPUP_TRAIL + (off>>9); 4786335Ssam m->m_off -= sizeof (u_short); 4796335Ssam m->m_len += sizeof (u_short); 4805105Swnj *mtod(m, u_short *) = ENPUP_IPTYPE; 4815105Swnj goto gottrailertype; 4825083Swnj } 4835105Swnj type = ENPUP_IPTYPE; 4845105Swnj off = 0; 4855105Swnj goto gottype; 4865083Swnj #endif 4876027Ssam #ifdef PUP 4886335Ssam case AF_PUP: 4896335Ssam dest = ((struct sockaddr_pup *)dst)->spup_addr.pp_host; 4906335Ssam off = mtod(m, struct pup_header *)->pup_length - m->m_len; 4916335Ssam if (off > 0 && (off & 0x1ff) == 0 && 4926335Ssam m->m_off >= MMINOFF + sizeof (u_short)) { 4936027Ssam type = ENPUP_TRAIL + (off>>9); 4946335Ssam m->m_off -= sizeof (u_short); 4956335Ssam m->m_len += sizeof (u_short); 4966027Ssam *mtod(m, u_short *) = ENPUP_PUPTYPE; 4976027Ssam goto gottrailertype; 4986027Ssam } 4996027Ssam type = ENPUP_PUPTYPE; 5006027Ssam off = 0; 5016027Ssam goto gottype; 5026027Ssam #endif 5036027Ssam 5045083Swnj default: 5056335Ssam printf("en%d: can't handle af%d\n", ifp->if_unit, 5066335Ssam dst->sa_family); 5075083Swnj m_freem(m0); 5085083Swnj return (0); 5094686Swnj } 5105105Swnj 5115171Swnj gottrailertype: 5125105Swnj /* 5135105Swnj * Packet to be sent as trailer: move first packet 5145105Swnj * (control information) to end of chain. 5155105Swnj */ 5165105Swnj while (m->m_next) 5175105Swnj m = m->m_next; 5185105Swnj m->m_next = m0; 5195105Swnj m = m0->m_next; 5205105Swnj m0->m_next = 0; 5215171Swnj m0 = m; 5225105Swnj 5235171Swnj gottype: 5245105Swnj /* 5255105Swnj * Add local net header. If no space in first mbuf, 5265105Swnj * allocate another. 5275105Swnj */ 5285213Swnj if (m->m_off > MMAXOFF || 5295213Swnj MMINOFF + sizeof (struct en_header) > m->m_off) { 5305584Sroot m = m_get(M_DONTWAIT); 5315083Swnj if (m == 0) { 5325083Swnj m_freem(m0); 5335083Swnj return (0); 5345083Swnj } 5355083Swnj m->m_next = m0; 5365083Swnj m->m_off = MMINOFF; 5375083Swnj m->m_len = sizeof (struct en_header); 5385083Swnj } else { 5395083Swnj m->m_off -= sizeof (struct en_header); 5405083Swnj m->m_len += sizeof (struct en_header); 5415083Swnj } 5425083Swnj en = mtod(m, struct en_header *); 5435083Swnj en->en_shost = ifp->if_host[0]; 5445083Swnj en->en_dhost = dest; 5455083Swnj en->en_type = type; 5465105Swnj 5475105Swnj /* 5485105Swnj * Queue message on interface, and start output if interface 5495105Swnj * not yet active. 5505105Swnj */ 5515083Swnj s = splimp(); 5526207Swnj if (IF_QFULL(&ifp->if_snd)) { 5536207Swnj IF_DROP(&ifp->if_snd); 5546207Swnj m_freem(m); 5556207Swnj splx(s); 5566207Swnj return (0); 5576207Swnj } 5585083Swnj IF_ENQUEUE(&ifp->if_snd, m); 5595083Swnj if (en_softc[ifp->if_unit].es_oactive == 0) 5605083Swnj enstart(ifp->if_unit); 5615275Swnj splx(s); 5625105Swnj return (1); 5634686Swnj } 564*6410Ssam 565*6410Ssam #if NIMP == 0 && NEN > 0 566*6410Ssam /* 567*6410Ssam * Logical host interface driver. 568*6410Ssam * Allows host to appear as an ARPAnet 569*6410Ssam * logical host. Must also have routing 570*6410Ssam * table entry set up to forward packets 571*6410Ssam * to appropriate gateway on localnet. 572*6410Ssam */ 573*6410Ssam 574*6410Ssam struct ifnet enlhif; 575*6410Ssam int enlhoutput(); 576*6410Ssam 577*6410Ssam /* 578*6410Ssam * Called by localnet interface to allow logical 579*6410Ssam * host interface to "attach". Nothing should ever 580*6410Ssam * be sent locally to this interface, it's purpose 581*6410Ssam * is simply to establish the host's arpanet address. 582*6410Ssam */ 583*6410Ssam enlhinit(addr) 584*6410Ssam int addr; 585*6410Ssam { 586*6410Ssam register struct ifnet *ifp = &enlhif; 587*6410Ssam register struct sockaddr_in *sin; 588*6410Ssam 589*6410Ssam COUNT(ENLHINIT); 590*6410Ssam ifp->if_name = "lh"; 591*6410Ssam ifp->if_mtu = ENMTU; 592*6410Ssam sin = (struct sockaddr_in *)&ifp->if_addr; 593*6410Ssam sin->sin_family = AF_INET; 594*6410Ssam sin->sin_addr.s_addr = addr; 595*6410Ssam ifp->if_net = sin->sin_addr.s_net; 596*6410Ssam ifp->if_flags = IFF_UP; 597*6410Ssam ifp->if_output = enlhoutput; /* should never be used */ 598*6410Ssam if_attach(ifp); 599*6410Ssam } 600*6410Ssam 601*6410Ssam enlhoutput(ifp, m0, dst) 602*6410Ssam struct ifnet *ifp; 603*6410Ssam struct mbuf *m0; 604*6410Ssam struct sockaddr *dst; 605*6410Ssam { 606*6410Ssam COUNT(ENLHOUTPUT); 607*6410Ssam ifp->if_oerrors++; 608*6410Ssam m_freem(m0); 609*6410Ssam return (0); 610*6410Ssam } 611*6410Ssam #endif 612