1*7261Ssam /* if_il.c 4.9 82/06/23 */ 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) 40*7261Ssam 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 */ 60*7261Ssam int is_flags; 61*7261Ssam #define ILF_OACTIVE 0x1 /* output is active */ 62*7261Ssam #define ILF_RCVPENDING 0x2 /* start rcv in ilcint */ 63*7261Ssam #define ILF_STATPENDING 0x4 /* stat cmd pending */ 64*7261Ssam short is_lastcmd; /* can't read csr, so must save it */ 65*7261Ssam short is_scaninterval; /* interval of stat collection */ 66*7261Ssam #define ILWATCHINTERVAL 60 /* once every 60 seconds */ 67*7261Ssam struct il_stats is_stats; /* holds on-board statistics */ 68*7261Ssam struct il_stats is_sum; /* summation over time */ 69*7261Ssam 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; 81*7261Ssam ilrint(0); ilcint(0); ilwatch(0); 826893Sfeldman #endif 836893Sfeldman 846893Sfeldman addr->il_csr = ILC_OFFLINE|IL_CIE; 856893Sfeldman DELAY(100000); 86*7261Ssam 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 /* 112*7261Ssam * Reset the board and map the statistics 113*7261Ssam * buffer onto the Unibus. 1146893Sfeldman */ 115*7261Ssam addr->il_csr = ILC_RESET; 116*7261Ssam while ((addr->il_csr&IL_CDONE) == 0) 117*7261Ssam ; 118*7261Ssam if (addr->il_csr&IL_STATUS) 119*7261Ssam printf("il%d: reset failed, csr=%b\n", ui->ui_unit, 120*7261Ssam addr->il_csr, IL_BITS); 1216893Sfeldman 122*7261Ssam is->is_ubaddr = uballoc(ui->ui_ubanum, &is->is_stats, 123*7261Ssam sizeof (struct il_stats), 0); 124*7261Ssam addr->il_bar = is->is_ubaddr & 0xffff; 125*7261Ssam addr->il_bcr = sizeof (struct il_stats); 126*7261Ssam addr->il_csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT; 127*7261Ssam while ((addr->il_csr&IL_CDONE) == 0) 128*7261Ssam ; 129*7261Ssam if (addr->il_csr&IL_STATUS) 130*7261Ssam printf("il%d: status failed, csr=%b\n", ui->ui_unit, 131*7261Ssam addr->il_csr, IL_BITS); 132*7261Ssam 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, 135*7261Ssam is->is_stats.ils_addr[0]&0xff, is->is_stats.ils_addr[1]&0xff, 136*7261Ssam is->is_stats.ils_addr[2]&0xff, is->is_stats.ils_addr[3]&0xff, 137*7261Ssam is->is_stats.ils_addr[4]&0xff, is->is_stats.ils_addr[5]&0xff, 138*7261Ssam is->is_stats.ils_module, is->is_stats.ils_firmware); 139*7261Ssam ifp->if_host[0] = 140*7261Ssam ((is->is_stats.ils_addr[3]&0xff)<<16) | 0x800000 | 141*7261Ssam ((is->is_stats.ils_addr[4]&0xff)<<8) | 142*7261Ssam (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; 155*7261Ssam ifp->if_watchdog = ilwatch; 156*7261Ssam is->is_scaninterval = ILWATCHINTERVAL; 157*7261Ssam 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; 191*7261Ssam 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 } 199*7261Ssam is->is_ubaddr = uballoc(ui->ui_ubanum, &is->is_stats, 200*7261Ssam 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; 216*7261Ssam addr->il_csr = 217*7261Ssam ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE; 2187220Ssam while ((addr->il_csr & IL_CDONE) == 0) 2197220Ssam ; 220*7261Ssam is->is_flags = ILF_OACTIVE; 2216893Sfeldman is->is_if.if_flags |= IFF_UP; 222*7261Ssam 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); 244*7261Ssam addr = (struct ildevice *)ui->ui_addr; 245*7261Ssam if (m == 0) { 246*7261Ssam if ((is->is_flags & ILF_STATPENDING) == 0) 247*7261Ssam return; 248*7261Ssam addr->il_bar = is->is_ubaddr & 0xfff; 249*7261Ssam addr->il_bcr = sizeof (struct il_stats); 250*7261Ssam csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE; 251*7261Ssam is->is_flags &= ~ILF_STATPENDING; 252*7261Ssam goto startcmd; 253*7261Ssam } 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; 259*7261Ssam csr = 260*7261Ssam ((is->is_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE; 261*7261Ssam 262*7261Ssam startcmd: 263*7261Ssam is->is_lastcmd = csr & IL_CMD; 2647220Ssam addr->il_csr = csr; 265*7261Ssam 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*7261Ssam short status; 2786893Sfeldman 279*7261Ssam if ((is->is_flags & ILF_OACTIVE) == 0) { 2807220Ssam printf("il%d: stray xmit interrupt, csr=%b\n", unit, 281*7261Ssam addr->il_csr, IL_BITS); 2826893Sfeldman return; 2836893Sfeldman } 2847220Ssam 2856893Sfeldman /* 286*7261Ssam * Hang receive buffer if it couldn't 287*7261Ssam * be done earlier (in ilrint). 2886893Sfeldman */ 289*7261Ssam if (is->is_flags & ILF_RCVPENDING) { 2906893Sfeldman addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 2916893Sfeldman addr->il_bcr = sizeof(struct il_rheader) + ILMTU + 6; 292*7261Ssam addr->il_csr = 293*7261Ssam ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE; 2947220Ssam while ((addr->il_csr & IL_CDONE) == 0) 2957220Ssam ; 296*7261Ssam is->is_flags &= ~ILF_RCVPENDING; 2976893Sfeldman } 298*7261Ssam is->is_flags &= ~ILF_OACTIVE; 299*7261Ssam status = addr->il_csr & IL_STATUS; 300*7261Ssam switch (is->is_lastcmd) { 301*7261Ssam 302*7261Ssam case ILC_XMIT: 303*7261Ssam is->is_if.if_opackets++; 304*7261Ssam if (status > ILERR_RETRIES) 305*7261Ssam is->is_if.if_oerrors++; 306*7261Ssam break; 307*7261Ssam 308*7261Ssam case ILC_STAT: 309*7261Ssam if (status == ILERR_SUCCESS) 310*7261Ssam iltotal(is); 311*7261Ssam break; 312*7261Ssam } 3136893Sfeldman if (is->is_ifuba.ifu_xtofree) { 3146893Sfeldman m_freem(is->is_ifuba.ifu_xtofree); 3156893Sfeldman is->is_ifuba.ifu_xtofree = 0; 3166893Sfeldman } 317*7261Ssam ilstart(unit); 3186893Sfeldman } 3196893Sfeldman 3206893Sfeldman /* 3216893Sfeldman * Ethernet interface receiver interrupt. 3226893Sfeldman * If input error just drop packet. 3236893Sfeldman * Otherwise purge input buffered data path and examine 3246893Sfeldman * packet to determine type. If can't determine length 3256893Sfeldman * from type, then have to drop packet. Othewise decapsulate 3266893Sfeldman * packet based on type and pass to type specific higher-level 3276893Sfeldman * input routine. 3286893Sfeldman */ 3296893Sfeldman ilrint(unit) 3306893Sfeldman int unit; 3316893Sfeldman { 3326893Sfeldman register struct il_softc *is = &il_softc[unit]; 3336893Sfeldman struct ildevice *addr = (struct ildevice *)ilinfo[unit]->ui_addr; 3346893Sfeldman register struct il_rheader *il; 3356893Sfeldman struct mbuf *m; 3366893Sfeldman int len, off, resid; 3376893Sfeldman register struct ifqueue *inq; 3386893Sfeldman 3396893Sfeldman is->is_if.if_ipackets++; 3406893Sfeldman if (is->is_ifuba.ifu_flags & UBA_NEEDBDP) 3416893Sfeldman UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp); 3426893Sfeldman il = (struct il_rheader *)(is->is_ifuba.ifu_r.ifrw_addr); 3436893Sfeldman len = il->ilr_length - sizeof(struct il_rheader); 344*7261Ssam if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 || len > ILMTU) { 3456893Sfeldman is->is_if.if_ierrors++; 3466893Sfeldman #ifdef notdef 3476893Sfeldman if (is->is_if.if_ierrors % 100 == 0) 3486893Sfeldman printf("il%d: += 100 input errors\n", unit); 3496893Sfeldman #endif 3506893Sfeldman goto setup; 3516893Sfeldman } 3526893Sfeldman 3536893Sfeldman /* 3546893Sfeldman * Deal with trailer protocol: if type is PUP trailer 3556893Sfeldman * get true type from first 16-bit word past data. 3566893Sfeldman * Remember that type was trailer by setting off. 3576893Sfeldman */ 3586893Sfeldman #define ildataaddr(il, off, type) ((type)(((caddr_t)((il)+1)+(off)))) 3596893Sfeldman if (il->ilr_type >= ILPUP_TRAIL && 3606893Sfeldman il->ilr_type < ILPUP_TRAIL+ILPUP_NTRAILER) { 3616893Sfeldman off = (il->ilr_type - ILPUP_TRAIL) * 512; 3626893Sfeldman if (off >= ILMTU) 3636893Sfeldman goto setup; /* sanity */ 3646893Sfeldman il->ilr_type = *ildataaddr(il, off, u_short *); 3656893Sfeldman resid = *(ildataaddr(il, off+2, u_short *)); 3666893Sfeldman if (off + resid > len) 3676893Sfeldman goto setup; /* sanity */ 3686893Sfeldman len = off + resid; 3696893Sfeldman } else 3706893Sfeldman off = 0; 3716893Sfeldman if (len == 0) 3726893Sfeldman goto setup; 3736893Sfeldman 3746893Sfeldman /* 3756893Sfeldman * Pull packet off interface. Off is nonzero if packet 3766893Sfeldman * has trailing header; ilget will then force this header 3776893Sfeldman * information to be at the front, but we still have to drop 3786893Sfeldman * the type and length which are at the front of any trailer data. 3796893Sfeldman */ 3806893Sfeldman m = if_rubaget(&is->is_ifuba, len, off); 3816893Sfeldman if (m == 0) 3826893Sfeldman goto setup; 3836893Sfeldman if (off) { 3846893Sfeldman m->m_off += 2 * sizeof (u_short); 3856893Sfeldman m->m_len -= 2 * sizeof (u_short); 3866893Sfeldman } 3876893Sfeldman switch (il->ilr_type) { 3886893Sfeldman 3896893Sfeldman #ifdef INET 3906893Sfeldman case ILPUP_IPTYPE: 3916893Sfeldman schednetisr(NETISR_IP); 3926893Sfeldman inq = &ipintrq; 3936893Sfeldman break; 3946893Sfeldman #endif 3956893Sfeldman default: 3966893Sfeldman m_freem(m); 3976893Sfeldman goto setup; 3986893Sfeldman } 3996893Sfeldman 4006893Sfeldman if (IF_QFULL(inq)) { 4016893Sfeldman IF_DROP(inq); 4026893Sfeldman m_freem(m); 4037220Ssam goto setup; 4047220Ssam } 4057220Ssam IF_ENQUEUE(inq, m); 4066893Sfeldman 4076893Sfeldman setup: 4086893Sfeldman /* 4096893Sfeldman * Reset for next packet if possible. 4106893Sfeldman * If waiting for transmit command completion, set flag 4116893Sfeldman * and wait until command completes. 4126893Sfeldman */ 413*7261Ssam if (is->is_flags & ILF_OACTIVE) { 414*7261Ssam is->is_flags |= ILF_RCVPENDING; 4157220Ssam return; 4167220Ssam } 4177220Ssam addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 4187220Ssam addr->il_bcr = sizeof(struct il_rheader) + ILMTU + 6; 419*7261Ssam addr->il_csr = 420*7261Ssam ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE; 4217220Ssam while ((addr->il_csr & IL_CDONE) == 0) 4227220Ssam ; 4236893Sfeldman } 4246893Sfeldman 4256893Sfeldman /* 4266893Sfeldman * Ethernet output routine. 4276893Sfeldman * Encapsulate a packet of type family for the local net. 4286893Sfeldman * Use trailer local net encapsulation if enough data in first 4296893Sfeldman * packet leaves a multiple of 512 bytes of data in remainder. 4306893Sfeldman */ 4316893Sfeldman iloutput(ifp, m0, dst) 4326893Sfeldman struct ifnet *ifp; 4336893Sfeldman struct mbuf *m0; 4346893Sfeldman struct sockaddr *dst; 4356893Sfeldman { 4366893Sfeldman int type, dest, s, error; 4376893Sfeldman register struct il_softc *is = &il_softc[ifp->if_unit]; 4386893Sfeldman register struct mbuf *m = m0; 4396893Sfeldman register struct il_xheader *il; 4407220Ssam register int off, i; 4416893Sfeldman 4426893Sfeldman switch (dst->sa_family) { 4436893Sfeldman 4446893Sfeldman #ifdef INET 4456893Sfeldman case AF_INET: 4466893Sfeldman dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr; 4476893Sfeldman off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len; 4486893Sfeldman if (off > 0 && (off & 0x1ff) == 0 && 4496893Sfeldman m->m_off >= MMINOFF + 2 * sizeof (u_short)) { 4506893Sfeldman type = ILPUP_TRAIL + (off>>9); 4516893Sfeldman m->m_off -= 2 * sizeof (u_short); 4526893Sfeldman m->m_len += 2 * sizeof (u_short); 4536893Sfeldman *mtod(m, u_short *) = ILPUP_IPTYPE; 4546893Sfeldman *(mtod(m, u_short *) + 1) = m->m_len; 4556893Sfeldman goto gottrailertype; 4566893Sfeldman } 4576893Sfeldman type = ILPUP_IPTYPE; 4586893Sfeldman off = 0; 4596893Sfeldman goto gottype; 4606893Sfeldman #endif 4616893Sfeldman 4626893Sfeldman default: 4636893Sfeldman printf("il%d: can't handle af%d\n", ifp->if_unit, 4646893Sfeldman dst->sa_family); 4656893Sfeldman error = EAFNOSUPPORT; 4666893Sfeldman goto bad; 4676893Sfeldman } 4686893Sfeldman 4696893Sfeldman gottrailertype: 4706893Sfeldman /* 4716893Sfeldman * Packet to be sent as trailer: move first packet 4726893Sfeldman * (control information) to end of chain. 4736893Sfeldman */ 4746893Sfeldman while (m->m_next) 4756893Sfeldman m = m->m_next; 4766893Sfeldman m->m_next = m0; 4776893Sfeldman m = m0->m_next; 4786893Sfeldman m0->m_next = 0; 4796893Sfeldman m0 = m; 4806893Sfeldman 4816893Sfeldman gottype: 4826893Sfeldman /* 4836893Sfeldman * Add local net header. If no space in first mbuf, 4846893Sfeldman * allocate another. 4856893Sfeldman */ 4866893Sfeldman if (m->m_off > MMAXOFF || 4876893Sfeldman MMINOFF + sizeof (struct il_xheader) > m->m_off) { 4886893Sfeldman m = m_get(M_DONTWAIT); 4896893Sfeldman if (m == 0) { 4906893Sfeldman error = ENOBUFS; 4916893Sfeldman goto bad; 4926893Sfeldman } 4936893Sfeldman m->m_next = m0; 4946893Sfeldman m->m_off = MMINOFF; 4956893Sfeldman m->m_len = sizeof (struct il_xheader); 4966893Sfeldman } else { 4976893Sfeldman m->m_off -= sizeof (struct il_xheader); 4986893Sfeldman m->m_len += sizeof (struct il_xheader); 4996893Sfeldman } 5006893Sfeldman il = mtod(m, struct il_xheader *); 5016893Sfeldman if ((dest &~ 0xff) == 0) 5027220Ssam bcopy(ilbroadcastaddr, il->ilx_dhost, 6); 5036893Sfeldman else { 504*7261Ssam u_char *to = dest & 0x8000 ? is->is_stats.ils_addr : il_ectop; 5057220Ssam 5067220Ssam bcopy(to, il->ilx_dhost, 3); 5076893Sfeldman il->ilx_dhost[3] = (dest>>8) & 0x7f; 5086893Sfeldman il->ilx_dhost[4] = (dest>>16) & 0xff; 5096893Sfeldman il->ilx_dhost[5] = (dest>>24) & 0xff; 5106893Sfeldman } 5116893Sfeldman il->ilx_type = type; 5126893Sfeldman 5136893Sfeldman /* 5146893Sfeldman * Queue message on interface, and start output if interface 5156893Sfeldman * not yet active. 5166893Sfeldman */ 5176893Sfeldman s = splimp(); 5186893Sfeldman if (IF_QFULL(&ifp->if_snd)) { 5196893Sfeldman IF_DROP(&ifp->if_snd); 5207220Ssam splx(s); 5217220Ssam m_freem(m); 5227220Ssam return (ENOBUFS); 5236893Sfeldman } 5246893Sfeldman IF_ENQUEUE(&ifp->if_snd, m); 525*7261Ssam if ((is->is_flags & ILF_OACTIVE) == 0) 5266893Sfeldman ilstart(ifp->if_unit); 5276893Sfeldman splx(s); 5286893Sfeldman return (0); 5297220Ssam 5306893Sfeldman bad: 5316893Sfeldman m_freem(m0); 5327220Ssam return (error); 5336893Sfeldman } 534*7261Ssam 535*7261Ssam /* 536*7261Ssam * Watchdog routine, request statistics from board. 537*7261Ssam */ 538*7261Ssam ilwatch(unit) 539*7261Ssam int unit; 540*7261Ssam { 541*7261Ssam register struct il_softc *is = &il_softc[unit]; 542*7261Ssam register struct ifnet *ifp = &is->is_if; 543*7261Ssam int s; 544*7261Ssam 545*7261Ssam if (is->is_flags & ILF_STATPENDING) { 546*7261Ssam ifp->if_timer = is->is_scaninterval; 547*7261Ssam return; 548*7261Ssam } 549*7261Ssam s = splimp(); 550*7261Ssam is->is_flags |= ILF_STATPENDING; 551*7261Ssam if ((is->is_flags & ILF_OACTIVE) == 0) 552*7261Ssam ilstart(ifp->if_unit); 553*7261Ssam splx(s); 554*7261Ssam ifp->if_timer = is->is_scaninterval; 555*7261Ssam } 556*7261Ssam 557*7261Ssam /* 558*7261Ssam * Total up the on-board statistics. 559*7261Ssam */ 560*7261Ssam iltotal(is) 561*7261Ssam register struct il_softc *is; 562*7261Ssam { 563*7261Ssam register u_short *interval, *sum, *end; 564*7261Ssam 565*7261Ssam interval = &is->is_stats.ils_frames; 566*7261Ssam sum = &is->is_sum.ils_frames; 567*7261Ssam end = is->is_sum.ils_fill2; 568*7261Ssam while (sum < end) 569*7261Ssam *sum++ += *interval++; 570*7261Ssam is->is_if.if_collisions = is->is_sum.ils_collis; 571*7261Ssam } 572