1*7266Ssam /* if_il.c 4.10 82/06/24 */ 26893Sfeldman 36893Sfeldman #include "il.h" 46893Sfeldman 56893Sfeldman /* 66893Sfeldman * Interlan Ethernet Communications Controller interface 76893Sfeldman */ 86893Sfeldman #include "../h/param.h" 96893Sfeldman #include "../h/systm.h" 106893Sfeldman #include "../h/mbuf.h" 116893Sfeldman #include "../h/pte.h" 126893Sfeldman #include "../h/buf.h" 136893Sfeldman #include "../h/protosw.h" 146893Sfeldman #include "../h/socket.h" 156893Sfeldman #include "../h/ubareg.h" 166893Sfeldman #include "../h/ubavar.h" 176893Sfeldman #include "../h/ilreg.h" 186893Sfeldman #include "../h/cpu.h" 196893Sfeldman #include "../h/mtpr.h" 206893Sfeldman #include "../h/vmmac.h" 216893Sfeldman #include "../net/in.h" 226893Sfeldman #include "../net/in_systm.h" 236893Sfeldman #include "../net/if.h" 246893Sfeldman #include "../net/if_il.h" 256893Sfeldman #include "../net/if_uba.h" 266893Sfeldman #include "../net/ip.h" 276893Sfeldman #include "../net/ip_var.h" 286893Sfeldman #include "../net/pup.h" 296893Sfeldman #include "../net/route.h" 306893Sfeldman #include <errno.h> 316893Sfeldman 326893Sfeldman #define ILMTU 1500 336893Sfeldman 346893Sfeldman int ilprobe(), ilattach(), ilrint(), ilcint(); 356893Sfeldman struct uba_device *ilinfo[NIL]; 366893Sfeldman u_short ilstd[] = { 0 }; 376893Sfeldman struct uba_driver ildriver = 386893Sfeldman { ilprobe, 0, ilattach, 0, ilstd, "il", ilinfo }; 396893Sfeldman #define ILUNIT(x) minor(x) 407261Ssam int ilinit(),iloutput(),ilreset(),ilwatch(); 416893Sfeldman 427220Ssam u_char il_ectop[3] = { 0x02, 0x60, 0x8c }; 437220Ssam u_char ilbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 447220Ssam 456893Sfeldman /* 466893Sfeldman * Ethernet software status per interface. 476893Sfeldman * 486893Sfeldman * Each interface is referenced by a network interface structure, 496893Sfeldman * is_if, which the routing code uses to locate the interface. 506893Sfeldman * This structure contains the output queue for the interface, its address, ... 516893Sfeldman * We also have, for each interface, a UBA interface structure, which 526893Sfeldman * contains information about the UNIBUS resources held by the interface: 536893Sfeldman * map registers, buffered data paths, etc. Information is cached in this 546893Sfeldman * structure for use by the if_uba.c routines in running the interface 556893Sfeldman * efficiently. 566893Sfeldman */ 576893Sfeldman struct il_softc { 586893Sfeldman struct ifnet is_if; /* network-visible interface */ 596893Sfeldman struct ifuba is_ifuba; /* UNIBUS resources */ 607261Ssam int is_flags; 617261Ssam #define ILF_OACTIVE 0x1 /* output is active */ 627261Ssam #define ILF_RCVPENDING 0x2 /* start rcv in ilcint */ 637261Ssam #define ILF_STATPENDING 0x4 /* stat cmd pending */ 647261Ssam short is_lastcmd; /* can't read csr, so must save it */ 657261Ssam short is_scaninterval; /* interval of stat collection */ 667261Ssam #define ILWATCHINTERVAL 60 /* once every 60 seconds */ 677261Ssam struct il_stats is_stats; /* holds on-board statistics */ 687261Ssam struct il_stats is_sum; /* summation over time */ 697261Ssam int is_ubaddr; /* mapping registers of is_stats */ 706893Sfeldman } il_softc[NIL]; 716893Sfeldman 726893Sfeldman ilprobe(reg) 736893Sfeldman caddr_t reg; 746893Sfeldman { 756893Sfeldman register int br, cvec; /* r11, r10 value-result */ 766893Sfeldman register struct ildevice *addr = (struct ildevice *)reg; 776893Sfeldman register i; 786893Sfeldman 796893Sfeldman #ifdef lint 806893Sfeldman br = 0; cvec = br; br = cvec; 817261Ssam ilrint(0); ilcint(0); ilwatch(0); 826893Sfeldman #endif 836893Sfeldman 846893Sfeldman addr->il_csr = ILC_OFFLINE|IL_CIE; 856893Sfeldman DELAY(100000); 867261Ssam i = addr->il_csr; /* clear CDONE */ 876893Sfeldman if (cvec > 0 && cvec != 0x200) 886893Sfeldman cvec -= 4; 896893Sfeldman return (1); 906893Sfeldman } 916893Sfeldman 926893Sfeldman /* 936893Sfeldman * Interface exists: make available by filling in network interface 946893Sfeldman * record. System will initialize the interface when it is ready 956893Sfeldman * to accept packets. A STATUS command is done to get the ethernet 966893Sfeldman * address and other interesting data. 976893Sfeldman */ 986893Sfeldman ilattach(ui) 996893Sfeldman struct uba_device *ui; 1006893Sfeldman { 1016893Sfeldman register struct il_softc *is = &il_softc[ui->ui_unit]; 1027220Ssam register struct ifnet *ifp = &is->is_if; 1036893Sfeldman register struct ildevice *addr = (struct ildevice *)ui->ui_addr; 1047220Ssam struct sockaddr_in *sin; 1056893Sfeldman 1067220Ssam ifp->if_unit = ui->ui_unit; 1077220Ssam ifp->if_name = "il"; 1087220Ssam ifp->if_mtu = ILMTU; 1097220Ssam ifp->if_net = ui->ui_flags; 1106893Sfeldman 1116893Sfeldman /* 1127261Ssam * Reset the board and map the statistics 1137261Ssam * buffer onto the Unibus. 1146893Sfeldman */ 1157261Ssam addr->il_csr = ILC_RESET; 1167261Ssam while ((addr->il_csr&IL_CDONE) == 0) 1177261Ssam ; 1187261Ssam if (addr->il_csr&IL_STATUS) 1197261Ssam printf("il%d: reset failed, csr=%b\n", ui->ui_unit, 1207261Ssam addr->il_csr, IL_BITS); 1216893Sfeldman 1227261Ssam is->is_ubaddr = uballoc(ui->ui_ubanum, &is->is_stats, 1237261Ssam sizeof (struct il_stats), 0); 1247261Ssam addr->il_bar = is->is_ubaddr & 0xffff; 1257261Ssam addr->il_bcr = sizeof (struct il_stats); 1267261Ssam addr->il_csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT; 1277261Ssam while ((addr->il_csr&IL_CDONE) == 0) 1287261Ssam ; 1297261Ssam if (addr->il_csr&IL_STATUS) 1307261Ssam printf("il%d: status failed, csr=%b\n", ui->ui_unit, 1317261Ssam addr->il_csr, IL_BITS); 1327261Ssam ubarelse(ui->ui_ubanum, &is->is_ubaddr); 1336893Sfeldman printf("il%d: addr=%x:%x:%x:%x:%x:%x module=%s firmware=%s\n", 1346893Sfeldman ui->ui_unit, 1357261Ssam is->is_stats.ils_addr[0]&0xff, is->is_stats.ils_addr[1]&0xff, 1367261Ssam is->is_stats.ils_addr[2]&0xff, is->is_stats.ils_addr[3]&0xff, 1377261Ssam is->is_stats.ils_addr[4]&0xff, is->is_stats.ils_addr[5]&0xff, 1387261Ssam is->is_stats.ils_module, is->is_stats.ils_firmware); 1397261Ssam ifp->if_host[0] = 1407261Ssam ((is->is_stats.ils_addr[3]&0xff)<<16) | 0x800000 | 1417261Ssam ((is->is_stats.ils_addr[4]&0xff)<<8) | 1427261Ssam (is->is_stats.ils_addr[5]&0xff); 1437220Ssam sin = (struct sockaddr_in *)&ifp->if_addr; 1446893Sfeldman sin->sin_family = AF_INET; 1457220Ssam sin->sin_addr = if_makeaddr(ifp->if_net, ifp->if_host[0]); 1466893Sfeldman 1477220Ssam sin = (struct sockaddr_in *)&ifp->if_broadaddr; 1486893Sfeldman sin->sin_family = AF_INET; 1497220Ssam sin->sin_addr = if_makeaddr(ifp->if_net, INADDR_ANY); 1507220Ssam ifp->if_flags = IFF_BROADCAST; 1516893Sfeldman 1527220Ssam ifp->if_init = ilinit; 1537220Ssam ifp->if_output = iloutput; 1547220Ssam ifp->if_ubareset = ilreset; 1557261Ssam ifp->if_watchdog = ilwatch; 1567261Ssam is->is_scaninterval = ILWATCHINTERVAL; 1577261Ssam ifp->if_timer = is->is_scaninterval; 1586893Sfeldman is->is_ifuba.ifu_flags = UBA_CANTWAIT; 1597220Ssam #ifdef notdef 1607220Ssam is->is_ifuba.ifu_flags |= UBA_NEEDBDP; 1617220Ssam #endif 1627220Ssam if_attach(ifp); 1636893Sfeldman } 1646893Sfeldman 1656893Sfeldman /* 1666893Sfeldman * Reset of interface after UNIBUS reset. 1676893Sfeldman * If interface is on specified uba, reset its state. 1686893Sfeldman */ 1696893Sfeldman ilreset(unit, uban) 1706893Sfeldman int unit, uban; 1716893Sfeldman { 1726893Sfeldman register struct uba_device *ui; 1736893Sfeldman 1746893Sfeldman if (unit >= NIL || (ui = ilinfo[unit]) == 0 || ui->ui_alive == 0 || 1756893Sfeldman ui->ui_ubanum != uban) 1766893Sfeldman return; 1776893Sfeldman printf(" il%d", unit); 1786893Sfeldman ilinit(unit); 1796893Sfeldman } 1806893Sfeldman 1816893Sfeldman /* 1826893Sfeldman * Initialization of interface; clear recorded pending 1836893Sfeldman * operations, and reinitialize UNIBUS usage. 1846893Sfeldman */ 1856893Sfeldman ilinit(unit) 1866893Sfeldman int unit; 1876893Sfeldman { 1886893Sfeldman register struct il_softc *is = &il_softc[unit]; 1896893Sfeldman register struct uba_device *ui = ilinfo[unit]; 1906893Sfeldman register struct ildevice *addr; 1917261Ssam int s; 1926893Sfeldman 1936893Sfeldman if (if_ubainit(&is->is_ifuba, ui->ui_ubanum, 1946893Sfeldman sizeof (struct il_rheader), (int)btoc(ILMTU)) == 0) { 1956893Sfeldman printf("il%d: can't initialize\n", unit); 1966893Sfeldman is->is_if.if_flags &= ~IFF_UP; 1976893Sfeldman return; 1986893Sfeldman } 1997261Ssam is->is_ubaddr = uballoc(ui->ui_ubanum, &is->is_stats, 2007261Ssam sizeof (struct il_stats), 0); 2016893Sfeldman addr = (struct ildevice *)ui->ui_addr; 2026893Sfeldman 2036893Sfeldman /* 2046893Sfeldman * Set board online. 2056893Sfeldman * Hang receive buffer and start any pending 2066893Sfeldman * writes by faking a transmit complete. 2076893Sfeldman * Receive bcr is not a muliple of 4 so buffer 2086893Sfeldman * chaining can't happen. 2096893Sfeldman */ 2106893Sfeldman s = splimp(); 2116893Sfeldman addr->il_csr = ILC_ONLINE; 2127220Ssam while ((addr->il_csr & IL_CDONE) == 0) 2137220Ssam ; 2146893Sfeldman addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 2156893Sfeldman addr->il_bcr = sizeof(struct il_rheader) + ILMTU + 6; 2167261Ssam addr->il_csr = 2177261Ssam ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE; 2187220Ssam while ((addr->il_csr & IL_CDONE) == 0) 2197220Ssam ; 2207261Ssam is->is_flags = ILF_OACTIVE; 2216893Sfeldman is->is_if.if_flags |= IFF_UP; 2227261Ssam is->is_lastcmd = 0; 2236893Sfeldman ilcint(unit); 2246893Sfeldman splx(s); 2257152Swnj if_rtinit(&is->is_if, RTF_UP); 2266893Sfeldman } 2276893Sfeldman 2286893Sfeldman /* 2296893Sfeldman * Start output on interface. 2306893Sfeldman * Get another datagram to send off of the interface queue, 2316893Sfeldman * and map it to the interface before starting the output. 2326893Sfeldman */ 2336893Sfeldman ilstart(dev) 2346893Sfeldman dev_t dev; 2356893Sfeldman { 2367220Ssam int unit = ILUNIT(dev), dest, len; 2376893Sfeldman struct uba_device *ui = ilinfo[unit]; 2386893Sfeldman register struct il_softc *is = &il_softc[unit]; 2396893Sfeldman register struct ildevice *addr; 2406893Sfeldman struct mbuf *m; 2417220Ssam short csr; 2426893Sfeldman 2436893Sfeldman IF_DEQUEUE(&is->is_if.if_snd, m); 2447261Ssam addr = (struct ildevice *)ui->ui_addr; 2457261Ssam if (m == 0) { 2467261Ssam if ((is->is_flags & ILF_STATPENDING) == 0) 2477261Ssam return; 2487261Ssam addr->il_bar = is->is_ubaddr & 0xfff; 2497261Ssam addr->il_bcr = sizeof (struct il_stats); 2507261Ssam csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE; 2517261Ssam is->is_flags &= ~ILF_STATPENDING; 2527261Ssam goto startcmd; 2537261Ssam } 2546893Sfeldman len = if_wubaput(&is->is_ifuba, m); 2556893Sfeldman if (is->is_ifuba.ifu_flags & UBA_NEEDBDP) 2566893Sfeldman UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp); 2576893Sfeldman addr->il_bar = is->is_ifuba.ifu_w.ifrw_info & 0xffff; 2586893Sfeldman addr->il_bcr = len; 2597261Ssam csr = 2607261Ssam ((is->is_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE; 2617261Ssam 2627261Ssam startcmd: 2637261Ssam is->is_lastcmd = csr & IL_CMD; 2647220Ssam addr->il_csr = csr; 2657261Ssam is->is_flags |= ILF_OACTIVE; 2666893Sfeldman } 2676893Sfeldman 2686893Sfeldman /* 2696893Sfeldman * Command done interrupt. 2706893Sfeldman */ 2716893Sfeldman ilcint(unit) 2726893Sfeldman int unit; 2736893Sfeldman { 2746893Sfeldman register struct il_softc *is = &il_softc[unit]; 2757220Ssam struct uba_device *ui = ilinfo[unit]; 2766893Sfeldman register struct ildevice *addr = (struct ildevice *)ui->ui_addr; 277*7266Ssam short csr; 2786893Sfeldman 2797261Ssam if ((is->is_flags & ILF_OACTIVE) == 0) { 2807220Ssam printf("il%d: stray xmit interrupt, csr=%b\n", unit, 2817261Ssam addr->il_csr, IL_BITS); 2826893Sfeldman return; 2836893Sfeldman } 2847220Ssam 285*7266Ssam csr = addr->il_csr; 2866893Sfeldman /* 2877261Ssam * Hang receive buffer if it couldn't 2887261Ssam * be done earlier (in ilrint). 2896893Sfeldman */ 2907261Ssam if (is->is_flags & ILF_RCVPENDING) { 2916893Sfeldman addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 2926893Sfeldman addr->il_bcr = sizeof(struct il_rheader) + ILMTU + 6; 2937261Ssam addr->il_csr = 2947261Ssam ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE; 2957220Ssam while ((addr->il_csr & IL_CDONE) == 0) 2967220Ssam ; 2977261Ssam is->is_flags &= ~ILF_RCVPENDING; 2986893Sfeldman } 2997261Ssam is->is_flags &= ~ILF_OACTIVE; 300*7266Ssam csr &= IL_STATUS; 3017261Ssam switch (is->is_lastcmd) { 3027261Ssam 3037261Ssam case ILC_XMIT: 3047261Ssam is->is_if.if_opackets++; 305*7266Ssam if (csr > ILERR_RETRIES) 3067261Ssam is->is_if.if_oerrors++; 3077261Ssam break; 3087261Ssam 3097261Ssam case ILC_STAT: 310*7266Ssam if (csr == ILERR_SUCCESS) 3117261Ssam iltotal(is); 3127261Ssam break; 3137261Ssam } 3146893Sfeldman if (is->is_ifuba.ifu_xtofree) { 3156893Sfeldman m_freem(is->is_ifuba.ifu_xtofree); 3166893Sfeldman is->is_ifuba.ifu_xtofree = 0; 3176893Sfeldman } 3187261Ssam ilstart(unit); 3196893Sfeldman } 3206893Sfeldman 3216893Sfeldman /* 3226893Sfeldman * Ethernet interface receiver interrupt. 3236893Sfeldman * If input error just drop packet. 3246893Sfeldman * Otherwise purge input buffered data path and examine 3256893Sfeldman * packet to determine type. If can't determine length 3266893Sfeldman * from type, then have to drop packet. Othewise decapsulate 3276893Sfeldman * packet based on type and pass to type specific higher-level 3286893Sfeldman * input routine. 3296893Sfeldman */ 3306893Sfeldman ilrint(unit) 3316893Sfeldman int unit; 3326893Sfeldman { 3336893Sfeldman register struct il_softc *is = &il_softc[unit]; 3346893Sfeldman struct ildevice *addr = (struct ildevice *)ilinfo[unit]->ui_addr; 3356893Sfeldman register struct il_rheader *il; 3366893Sfeldman struct mbuf *m; 3376893Sfeldman int len, off, resid; 3386893Sfeldman register struct ifqueue *inq; 3396893Sfeldman 3406893Sfeldman is->is_if.if_ipackets++; 3416893Sfeldman if (is->is_ifuba.ifu_flags & UBA_NEEDBDP) 3426893Sfeldman UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp); 3436893Sfeldman il = (struct il_rheader *)(is->is_ifuba.ifu_r.ifrw_addr); 3446893Sfeldman len = il->ilr_length - sizeof(struct il_rheader); 3457261Ssam if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 || len > ILMTU) { 3466893Sfeldman is->is_if.if_ierrors++; 3476893Sfeldman #ifdef notdef 3486893Sfeldman if (is->is_if.if_ierrors % 100 == 0) 3496893Sfeldman printf("il%d: += 100 input errors\n", unit); 3506893Sfeldman #endif 3516893Sfeldman goto setup; 3526893Sfeldman } 3536893Sfeldman 3546893Sfeldman /* 3556893Sfeldman * Deal with trailer protocol: if type is PUP trailer 3566893Sfeldman * get true type from first 16-bit word past data. 3576893Sfeldman * Remember that type was trailer by setting off. 3586893Sfeldman */ 3596893Sfeldman #define ildataaddr(il, off, type) ((type)(((caddr_t)((il)+1)+(off)))) 3606893Sfeldman if (il->ilr_type >= ILPUP_TRAIL && 3616893Sfeldman il->ilr_type < ILPUP_TRAIL+ILPUP_NTRAILER) { 3626893Sfeldman off = (il->ilr_type - ILPUP_TRAIL) * 512; 3636893Sfeldman if (off >= ILMTU) 3646893Sfeldman goto setup; /* sanity */ 3656893Sfeldman il->ilr_type = *ildataaddr(il, off, u_short *); 3666893Sfeldman resid = *(ildataaddr(il, off+2, u_short *)); 3676893Sfeldman if (off + resid > len) 3686893Sfeldman goto setup; /* sanity */ 3696893Sfeldman len = off + resid; 3706893Sfeldman } else 3716893Sfeldman off = 0; 3726893Sfeldman if (len == 0) 3736893Sfeldman goto setup; 3746893Sfeldman 3756893Sfeldman /* 3766893Sfeldman * Pull packet off interface. Off is nonzero if packet 3776893Sfeldman * has trailing header; ilget will then force this header 3786893Sfeldman * information to be at the front, but we still have to drop 3796893Sfeldman * the type and length which are at the front of any trailer data. 3806893Sfeldman */ 3816893Sfeldman m = if_rubaget(&is->is_ifuba, len, off); 3826893Sfeldman if (m == 0) 3836893Sfeldman goto setup; 3846893Sfeldman if (off) { 3856893Sfeldman m->m_off += 2 * sizeof (u_short); 3866893Sfeldman m->m_len -= 2 * sizeof (u_short); 3876893Sfeldman } 3886893Sfeldman switch (il->ilr_type) { 3896893Sfeldman 3906893Sfeldman #ifdef INET 3916893Sfeldman case ILPUP_IPTYPE: 3926893Sfeldman schednetisr(NETISR_IP); 3936893Sfeldman inq = &ipintrq; 3946893Sfeldman break; 3956893Sfeldman #endif 3966893Sfeldman default: 3976893Sfeldman m_freem(m); 3986893Sfeldman goto setup; 3996893Sfeldman } 4006893Sfeldman 4016893Sfeldman if (IF_QFULL(inq)) { 4026893Sfeldman IF_DROP(inq); 4036893Sfeldman m_freem(m); 4047220Ssam goto setup; 4057220Ssam } 4067220Ssam IF_ENQUEUE(inq, m); 4076893Sfeldman 4086893Sfeldman setup: 4096893Sfeldman /* 4106893Sfeldman * Reset for next packet if possible. 4116893Sfeldman * If waiting for transmit command completion, set flag 4126893Sfeldman * and wait until command completes. 4136893Sfeldman */ 4147261Ssam if (is->is_flags & ILF_OACTIVE) { 4157261Ssam is->is_flags |= ILF_RCVPENDING; 4167220Ssam return; 4177220Ssam } 4187220Ssam addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 4197220Ssam addr->il_bcr = sizeof(struct il_rheader) + ILMTU + 6; 4207261Ssam addr->il_csr = 4217261Ssam ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE; 4227220Ssam while ((addr->il_csr & IL_CDONE) == 0) 4237220Ssam ; 4246893Sfeldman } 4256893Sfeldman 4266893Sfeldman /* 4276893Sfeldman * Ethernet output routine. 4286893Sfeldman * Encapsulate a packet of type family for the local net. 4296893Sfeldman * Use trailer local net encapsulation if enough data in first 4306893Sfeldman * packet leaves a multiple of 512 bytes of data in remainder. 4316893Sfeldman */ 4326893Sfeldman iloutput(ifp, m0, dst) 4336893Sfeldman struct ifnet *ifp; 4346893Sfeldman struct mbuf *m0; 4356893Sfeldman struct sockaddr *dst; 4366893Sfeldman { 4376893Sfeldman int type, dest, s, error; 4386893Sfeldman register struct il_softc *is = &il_softc[ifp->if_unit]; 4396893Sfeldman register struct mbuf *m = m0; 4406893Sfeldman register struct il_xheader *il; 4417220Ssam register int off, i; 4426893Sfeldman 4436893Sfeldman switch (dst->sa_family) { 4446893Sfeldman 4456893Sfeldman #ifdef INET 4466893Sfeldman case AF_INET: 4476893Sfeldman dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr; 4486893Sfeldman off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len; 4496893Sfeldman if (off > 0 && (off & 0x1ff) == 0 && 4506893Sfeldman m->m_off >= MMINOFF + 2 * sizeof (u_short)) { 4516893Sfeldman type = ILPUP_TRAIL + (off>>9); 4526893Sfeldman m->m_off -= 2 * sizeof (u_short); 4536893Sfeldman m->m_len += 2 * sizeof (u_short); 4546893Sfeldman *mtod(m, u_short *) = ILPUP_IPTYPE; 4556893Sfeldman *(mtod(m, u_short *) + 1) = m->m_len; 4566893Sfeldman goto gottrailertype; 4576893Sfeldman } 4586893Sfeldman type = ILPUP_IPTYPE; 4596893Sfeldman off = 0; 4606893Sfeldman goto gottype; 4616893Sfeldman #endif 4626893Sfeldman 4636893Sfeldman default: 4646893Sfeldman printf("il%d: can't handle af%d\n", ifp->if_unit, 4656893Sfeldman dst->sa_family); 4666893Sfeldman error = EAFNOSUPPORT; 4676893Sfeldman goto bad; 4686893Sfeldman } 4696893Sfeldman 4706893Sfeldman gottrailertype: 4716893Sfeldman /* 4726893Sfeldman * Packet to be sent as trailer: move first packet 4736893Sfeldman * (control information) to end of chain. 4746893Sfeldman */ 4756893Sfeldman while (m->m_next) 4766893Sfeldman m = m->m_next; 4776893Sfeldman m->m_next = m0; 4786893Sfeldman m = m0->m_next; 4796893Sfeldman m0->m_next = 0; 4806893Sfeldman m0 = m; 4816893Sfeldman 4826893Sfeldman gottype: 4836893Sfeldman /* 4846893Sfeldman * Add local net header. If no space in first mbuf, 4856893Sfeldman * allocate another. 4866893Sfeldman */ 4876893Sfeldman if (m->m_off > MMAXOFF || 4886893Sfeldman MMINOFF + sizeof (struct il_xheader) > m->m_off) { 4896893Sfeldman m = m_get(M_DONTWAIT); 4906893Sfeldman if (m == 0) { 4916893Sfeldman error = ENOBUFS; 4926893Sfeldman goto bad; 4936893Sfeldman } 4946893Sfeldman m->m_next = m0; 4956893Sfeldman m->m_off = MMINOFF; 4966893Sfeldman m->m_len = sizeof (struct il_xheader); 4976893Sfeldman } else { 4986893Sfeldman m->m_off -= sizeof (struct il_xheader); 4996893Sfeldman m->m_len += sizeof (struct il_xheader); 5006893Sfeldman } 5016893Sfeldman il = mtod(m, struct il_xheader *); 5026893Sfeldman if ((dest &~ 0xff) == 0) 5037220Ssam bcopy(ilbroadcastaddr, il->ilx_dhost, 6); 5046893Sfeldman else { 5057261Ssam u_char *to = dest & 0x8000 ? is->is_stats.ils_addr : il_ectop; 5067220Ssam 5077220Ssam bcopy(to, il->ilx_dhost, 3); 5086893Sfeldman il->ilx_dhost[3] = (dest>>8) & 0x7f; 5096893Sfeldman il->ilx_dhost[4] = (dest>>16) & 0xff; 5106893Sfeldman il->ilx_dhost[5] = (dest>>24) & 0xff; 5116893Sfeldman } 5126893Sfeldman il->ilx_type = type; 5136893Sfeldman 5146893Sfeldman /* 5156893Sfeldman * Queue message on interface, and start output if interface 5166893Sfeldman * not yet active. 5176893Sfeldman */ 5186893Sfeldman s = splimp(); 5196893Sfeldman if (IF_QFULL(&ifp->if_snd)) { 5206893Sfeldman IF_DROP(&ifp->if_snd); 5217220Ssam splx(s); 5227220Ssam m_freem(m); 5237220Ssam return (ENOBUFS); 5246893Sfeldman } 5256893Sfeldman IF_ENQUEUE(&ifp->if_snd, m); 5267261Ssam if ((is->is_flags & ILF_OACTIVE) == 0) 5276893Sfeldman ilstart(ifp->if_unit); 5286893Sfeldman splx(s); 5296893Sfeldman return (0); 5307220Ssam 5316893Sfeldman bad: 5326893Sfeldman m_freem(m0); 5337220Ssam return (error); 5346893Sfeldman } 5357261Ssam 5367261Ssam /* 5377261Ssam * Watchdog routine, request statistics from board. 5387261Ssam */ 5397261Ssam ilwatch(unit) 5407261Ssam int unit; 5417261Ssam { 5427261Ssam register struct il_softc *is = &il_softc[unit]; 5437261Ssam register struct ifnet *ifp = &is->is_if; 5447261Ssam int s; 5457261Ssam 5467261Ssam if (is->is_flags & ILF_STATPENDING) { 5477261Ssam ifp->if_timer = is->is_scaninterval; 5487261Ssam return; 5497261Ssam } 5507261Ssam s = splimp(); 5517261Ssam is->is_flags |= ILF_STATPENDING; 5527261Ssam if ((is->is_flags & ILF_OACTIVE) == 0) 5537261Ssam ilstart(ifp->if_unit); 5547261Ssam splx(s); 5557261Ssam ifp->if_timer = is->is_scaninterval; 5567261Ssam } 5577261Ssam 5587261Ssam /* 5597261Ssam * Total up the on-board statistics. 5607261Ssam */ 5617261Ssam iltotal(is) 5627261Ssam register struct il_softc *is; 5637261Ssam { 5647261Ssam register u_short *interval, *sum, *end; 5657261Ssam 5667261Ssam interval = &is->is_stats.ils_frames; 5677261Ssam sum = &is->is_sum.ils_frames; 5687261Ssam end = is->is_sum.ils_fill2; 5697261Ssam while (sum < end) 5707261Ssam *sum++ += *interval++; 5717261Ssam is->is_if.if_collisions = is->is_sum.ils_collis; 5727261Ssam } 573