1*12488Ssam /* if_il.c 4.19 83/05/18 */ 26893Sfeldman 36893Sfeldman #include "il.h" 46893Sfeldman 56893Sfeldman /* 66893Sfeldman * Interlan Ethernet Communications Controller interface 76893Sfeldman */ 89797Ssam #include "../machine/pte.h" 99797Ssam 106893Sfeldman #include "../h/param.h" 116893Sfeldman #include "../h/systm.h" 126893Sfeldman #include "../h/mbuf.h" 136893Sfeldman #include "../h/buf.h" 146893Sfeldman #include "../h/protosw.h" 156893Sfeldman #include "../h/socket.h" 166893Sfeldman #include "../h/vmmac.h" 178463Sroot #include <errno.h> 188463Sroot 198463Sroot #include "../net/if.h" 208463Sroot #include "../net/netisr.h" 218463Sroot #include "../net/route.h" 228419Swnj #include "../netinet/in.h" 238419Swnj #include "../netinet/in_systm.h" 248419Swnj #include "../netinet/ip.h" 258419Swnj #include "../netinet/ip_var.h" 2611575Ssam #include "../netinet/if_ether.h" 278419Swnj #include "../netpup/pup.h" 286893Sfeldman 298463Sroot #include "../vax/cpu.h" 308463Sroot #include "../vax/mtpr.h" 319746Ssam #include "../vaxif/if_il.h" 328463Sroot #include "../vaxif/if_ilreg.h" 338463Sroot #include "../vaxif/if_uba.h" 348463Sroot #include "../vaxuba/ubareg.h" 358463Sroot #include "../vaxuba/ubavar.h" 368463Sroot 376893Sfeldman int ilprobe(), ilattach(), ilrint(), ilcint(); 386893Sfeldman struct uba_device *ilinfo[NIL]; 396893Sfeldman u_short ilstd[] = { 0 }; 406893Sfeldman struct uba_driver ildriver = 416893Sfeldman { ilprobe, 0, ilattach, 0, ilstd, "il", ilinfo }; 426893Sfeldman #define ILUNIT(x) minor(x) 437261Ssam int ilinit(),iloutput(),ilreset(),ilwatch(); 446893Sfeldman 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 { 5811575Ssam struct arpcom is_ac; /* Ethernet common part */ 5911575Ssam #define is_if is_ac.ac_if /* network-visible interface */ 6011575Ssam #define is_addr is_ac.ac_enaddr /* hardware Ethernet address */ 616893Sfeldman struct ifuba is_ifuba; /* UNIBUS resources */ 627261Ssam int is_flags; 637261Ssam #define ILF_OACTIVE 0x1 /* output is active */ 647261Ssam #define ILF_RCVPENDING 0x2 /* start rcv in ilcint */ 657261Ssam #define ILF_STATPENDING 0x4 /* stat cmd pending */ 667261Ssam short is_lastcmd; /* can't read csr, so must save it */ 677261Ssam short is_scaninterval; /* interval of stat collection */ 687261Ssam #define ILWATCHINTERVAL 60 /* once every 60 seconds */ 697261Ssam struct il_stats is_stats; /* holds on-board statistics */ 707261Ssam struct il_stats is_sum; /* summation over time */ 717261Ssam int is_ubaddr; /* mapping registers of is_stats */ 726893Sfeldman } il_softc[NIL]; 736893Sfeldman 746893Sfeldman ilprobe(reg) 756893Sfeldman caddr_t reg; 766893Sfeldman { 776893Sfeldman register int br, cvec; /* r11, r10 value-result */ 786893Sfeldman register struct ildevice *addr = (struct ildevice *)reg; 796893Sfeldman register i; 806893Sfeldman 816893Sfeldman #ifdef lint 826893Sfeldman br = 0; cvec = br; br = cvec; 839179Ssam i = 0; ilrint(i); ilcint(i); ilwatch(i); 846893Sfeldman #endif 856893Sfeldman 866893Sfeldman addr->il_csr = ILC_OFFLINE|IL_CIE; 876893Sfeldman DELAY(100000); 887261Ssam i = addr->il_csr; /* clear CDONE */ 896893Sfeldman if (cvec > 0 && cvec != 0x200) 906893Sfeldman cvec -= 4; 916893Sfeldman return (1); 926893Sfeldman } 936893Sfeldman 946893Sfeldman /* 956893Sfeldman * Interface exists: make available by filling in network interface 966893Sfeldman * record. System will initialize the interface when it is ready 976893Sfeldman * to accept packets. A STATUS command is done to get the ethernet 986893Sfeldman * address and other interesting data. 996893Sfeldman */ 1006893Sfeldman ilattach(ui) 1016893Sfeldman struct uba_device *ui; 1026893Sfeldman { 1036893Sfeldman register struct il_softc *is = &il_softc[ui->ui_unit]; 1047220Ssam register struct ifnet *ifp = &is->is_if; 1056893Sfeldman register struct ildevice *addr = (struct ildevice *)ui->ui_addr; 1067220Ssam struct sockaddr_in *sin; 1076893Sfeldman 1087220Ssam ifp->if_unit = ui->ui_unit; 1097220Ssam ifp->if_name = "il"; 1109746Ssam ifp->if_mtu = ETHERMTU; 1116893Sfeldman 1126893Sfeldman /* 1137261Ssam * Reset the board and map the statistics 1147261Ssam * buffer onto the Unibus. 1156893Sfeldman */ 1167261Ssam addr->il_csr = ILC_RESET; 1177261Ssam while ((addr->il_csr&IL_CDONE) == 0) 1187261Ssam ; 1197261Ssam if (addr->il_csr&IL_STATUS) 1207261Ssam printf("il%d: reset failed, csr=%b\n", ui->ui_unit, 1217261Ssam addr->il_csr, IL_BITS); 1226893Sfeldman 1239179Ssam is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats, 1247261Ssam sizeof (struct il_stats), 0); 1257261Ssam addr->il_bar = is->is_ubaddr & 0xffff; 1267261Ssam addr->il_bcr = sizeof (struct il_stats); 1277261Ssam addr->il_csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT; 1287261Ssam while ((addr->il_csr&IL_CDONE) == 0) 1297261Ssam ; 1307261Ssam if (addr->il_csr&IL_STATUS) 1317261Ssam printf("il%d: status failed, csr=%b\n", ui->ui_unit, 1327261Ssam addr->il_csr, IL_BITS); 1337261Ssam ubarelse(ui->ui_ubanum, &is->is_ubaddr); 13411575Ssam #ifdef notdef 1356893Sfeldman printf("il%d: addr=%x:%x:%x:%x:%x:%x module=%s firmware=%s\n", 1366893Sfeldman ui->ui_unit, 1377261Ssam is->is_stats.ils_addr[0]&0xff, is->is_stats.ils_addr[1]&0xff, 1387261Ssam is->is_stats.ils_addr[2]&0xff, is->is_stats.ils_addr[3]&0xff, 1397261Ssam is->is_stats.ils_addr[4]&0xff, is->is_stats.ils_addr[5]&0xff, 1407261Ssam is->is_stats.ils_module, is->is_stats.ils_firmware); 14111575Ssam #endif 14211575Ssam bcopy(is->is_stats.ils_addr, is->is_addr, sizeof (is->is_addr)); 1437220Ssam sin = (struct sockaddr_in *)&ifp->if_addr; 1446893Sfeldman sin->sin_family = AF_INET; 14511575Ssam if (ui->ui_flags) { 14611575Ssam int i = ((is->is_addr[3]&0xff)<<16) | 14711575Ssam ((is->is_addr[4]&0xff)<<8) | 14811575Ssam (is->is_addr[5]&0xff); 14911575Ssam sin->sin_addr = if_makeaddr(ui->ui_flags, i); 15011575Ssam } else 15111575Ssam sin->sin_addr = arpmyaddr(); 1526893Sfeldman 1537220Ssam ifp->if_init = ilinit; 1547220Ssam ifp->if_output = iloutput; 1558979Sroot ifp->if_reset = ilreset; 1567261Ssam ifp->if_watchdog = ilwatch; 1577261Ssam is->is_scaninterval = ILWATCHINTERVAL; 1587261Ssam ifp->if_timer = is->is_scaninterval; 1596893Sfeldman is->is_ifuba.ifu_flags = UBA_CANTWAIT; 1607220Ssam #ifdef notdef 1617220Ssam is->is_ifuba.ifu_flags |= UBA_NEEDBDP; 1627220Ssam #endif 1637220Ssam if_attach(ifp); 1646893Sfeldman } 1656893Sfeldman 1666893Sfeldman /* 1676893Sfeldman * Reset of interface after UNIBUS reset. 1686893Sfeldman * If interface is on specified uba, reset its state. 1696893Sfeldman */ 1706893Sfeldman ilreset(unit, uban) 1716893Sfeldman int unit, uban; 1726893Sfeldman { 1736893Sfeldman register struct uba_device *ui; 1746893Sfeldman 1756893Sfeldman if (unit >= NIL || (ui = ilinfo[unit]) == 0 || ui->ui_alive == 0 || 1766893Sfeldman ui->ui_ubanum != uban) 1776893Sfeldman return; 1786893Sfeldman printf(" il%d", unit); 1796893Sfeldman ilinit(unit); 1806893Sfeldman } 1816893Sfeldman 1826893Sfeldman /* 1836893Sfeldman * Initialization of interface; clear recorded pending 1846893Sfeldman * operations, and reinitialize UNIBUS usage. 1856893Sfeldman */ 1866893Sfeldman ilinit(unit) 1876893Sfeldman int unit; 1886893Sfeldman { 1896893Sfeldman register struct il_softc *is = &il_softc[unit]; 1906893Sfeldman register struct uba_device *ui = ilinfo[unit]; 1916893Sfeldman register struct ildevice *addr; 1927261Ssam int s; 19311575Ssam register struct ifnet *ifp = &is->is_if; 19411575Ssam register struct sockaddr_in *sin, *sinb; 1956893Sfeldman 19611575Ssam sin = (struct sockaddr_in *)&ifp->if_addr; 19711575Ssam if (sin->sin_addr.s_addr == 0) /* if address still unknown */ 19811575Ssam return; 19911575Ssam ifp->if_net = in_netof(sin->sin_addr); 20011575Ssam ifp->if_host[0] = in_lnaof(sin->sin_addr); 20111575Ssam sinb = (struct sockaddr_in *)&ifp->if_broadaddr; 20211575Ssam sinb->sin_family = AF_INET; 20311575Ssam sinb->sin_addr = if_makeaddr(ifp->if_net, INADDR_ANY); 20411575Ssam ifp->if_flags = IFF_BROADCAST; 20511575Ssam 2066893Sfeldman if (if_ubainit(&is->is_ifuba, ui->ui_ubanum, 2079746Ssam sizeof (struct il_rheader), (int)btoc(ETHERMTU)) == 0) { 2086893Sfeldman printf("il%d: can't initialize\n", unit); 2096893Sfeldman is->is_if.if_flags &= ~IFF_UP; 2106893Sfeldman return; 2116893Sfeldman } 2129179Ssam is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats, 2137261Ssam sizeof (struct il_stats), 0); 2146893Sfeldman addr = (struct ildevice *)ui->ui_addr; 2156893Sfeldman 2166893Sfeldman /* 2179179Ssam * Turn off source address insertion (it's faster this way), 218*12488Ssam * and set board online. Former doesn't work if board is 219*12488Ssam * already online (happens on ubareset), so we put it offline 220*12488Ssam * first. 2219179Ssam */ 2229179Ssam s = splimp(); 223*12488Ssam addr->il_csr = ILC_OFFLINE; 2249179Ssam while ((addr->il_csr & IL_CDONE) == 0) 2259179Ssam ; 226*12488Ssam addr->il_csr = ILC_CISA; 2279179Ssam while ((addr->il_csr & IL_CDONE) == 0) 2289179Ssam ; 2299179Ssam /* 2306893Sfeldman * Set board online. 2316893Sfeldman * Hang receive buffer and start any pending 2326893Sfeldman * writes by faking a transmit complete. 2336893Sfeldman * Receive bcr is not a muliple of 4 so buffer 2346893Sfeldman * chaining can't happen. 2356893Sfeldman */ 2366893Sfeldman addr->il_csr = ILC_ONLINE; 2377220Ssam while ((addr->il_csr & IL_CDONE) == 0) 2387220Ssam ; 2396893Sfeldman addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 2409746Ssam addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6; 2417261Ssam addr->il_csr = 2427261Ssam ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE; 2437220Ssam while ((addr->il_csr & IL_CDONE) == 0) 2447220Ssam ; 2457261Ssam is->is_flags = ILF_OACTIVE; 2466893Sfeldman is->is_if.if_flags |= IFF_UP; 2477261Ssam is->is_lastcmd = 0; 2486893Sfeldman ilcint(unit); 2496893Sfeldman splx(s); 2507152Swnj if_rtinit(&is->is_if, RTF_UP); 25111575Ssam arpattach(&is->is_ac); 25211575Ssam arpwhohas(&is->is_ac, &sin->sin_addr); 2536893Sfeldman } 2546893Sfeldman 2556893Sfeldman /* 2566893Sfeldman * Start output on interface. 2576893Sfeldman * Get another datagram to send off of the interface queue, 2586893Sfeldman * and map it to the interface before starting the output. 2596893Sfeldman */ 2606893Sfeldman ilstart(dev) 2616893Sfeldman dev_t dev; 2626893Sfeldman { 2639179Ssam int unit = ILUNIT(dev), len; 2646893Sfeldman struct uba_device *ui = ilinfo[unit]; 2656893Sfeldman register struct il_softc *is = &il_softc[unit]; 2666893Sfeldman register struct ildevice *addr; 2676893Sfeldman struct mbuf *m; 2687220Ssam short csr; 2696893Sfeldman 2706893Sfeldman IF_DEQUEUE(&is->is_if.if_snd, m); 2717261Ssam addr = (struct ildevice *)ui->ui_addr; 2727261Ssam if (m == 0) { 2737261Ssam if ((is->is_flags & ILF_STATPENDING) == 0) 2747261Ssam return; 2759179Ssam addr->il_bar = is->is_ubaddr & 0xffff; 2767261Ssam addr->il_bcr = sizeof (struct il_stats); 2777261Ssam csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE; 2787261Ssam is->is_flags &= ~ILF_STATPENDING; 2797261Ssam goto startcmd; 2807261Ssam } 2816893Sfeldman len = if_wubaput(&is->is_ifuba, m); 2829179Ssam /* 2839179Ssam * Ensure minimum packet length. 2849179Ssam * This makes the safe assumtion that there are no virtual holes 2859179Ssam * after the data. 2869179Ssam * For security, it might be wise to zero out the added bytes, 2879179Ssam * but we're mainly interested in speed at the moment. 2889179Ssam */ 2899746Ssam if (len - sizeof(struct ether_header) < ETHERMIN) 2909746Ssam len = ETHERMIN + sizeof(struct ether_header); 2916893Sfeldman if (is->is_ifuba.ifu_flags & UBA_NEEDBDP) 2926893Sfeldman UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp); 2936893Sfeldman addr->il_bar = is->is_ifuba.ifu_w.ifrw_info & 0xffff; 2946893Sfeldman addr->il_bcr = len; 2957261Ssam csr = 2967261Ssam ((is->is_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE; 2977261Ssam 2987261Ssam startcmd: 2997261Ssam is->is_lastcmd = csr & IL_CMD; 3007220Ssam addr->il_csr = csr; 3017261Ssam is->is_flags |= ILF_OACTIVE; 3026893Sfeldman } 3036893Sfeldman 3046893Sfeldman /* 3056893Sfeldman * Command done interrupt. 3066893Sfeldman */ 3076893Sfeldman ilcint(unit) 3086893Sfeldman int unit; 3096893Sfeldman { 3106893Sfeldman register struct il_softc *is = &il_softc[unit]; 3117220Ssam struct uba_device *ui = ilinfo[unit]; 3126893Sfeldman register struct ildevice *addr = (struct ildevice *)ui->ui_addr; 3137266Ssam short csr; 3146893Sfeldman 3157261Ssam if ((is->is_flags & ILF_OACTIVE) == 0) { 3167220Ssam printf("il%d: stray xmit interrupt, csr=%b\n", unit, 3177261Ssam addr->il_csr, IL_BITS); 3186893Sfeldman return; 3196893Sfeldman } 3207220Ssam 3217266Ssam csr = addr->il_csr; 3226893Sfeldman /* 3237261Ssam * Hang receive buffer if it couldn't 3247261Ssam * be done earlier (in ilrint). 3256893Sfeldman */ 3267261Ssam if (is->is_flags & ILF_RCVPENDING) { 3276893Sfeldman addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 3289746Ssam addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6; 3297261Ssam addr->il_csr = 3307261Ssam ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE; 3317220Ssam while ((addr->il_csr & IL_CDONE) == 0) 3327220Ssam ; 3337261Ssam is->is_flags &= ~ILF_RCVPENDING; 3346893Sfeldman } 3357261Ssam is->is_flags &= ~ILF_OACTIVE; 3367266Ssam csr &= IL_STATUS; 3377261Ssam switch (is->is_lastcmd) { 3387261Ssam 3397261Ssam case ILC_XMIT: 3407261Ssam is->is_if.if_opackets++; 3417266Ssam if (csr > ILERR_RETRIES) 3427261Ssam is->is_if.if_oerrors++; 3437261Ssam break; 3447261Ssam 3457261Ssam case ILC_STAT: 3467266Ssam if (csr == ILERR_SUCCESS) 3477261Ssam iltotal(is); 3487261Ssam break; 3497261Ssam } 3506893Sfeldman if (is->is_ifuba.ifu_xtofree) { 3516893Sfeldman m_freem(is->is_ifuba.ifu_xtofree); 3526893Sfeldman is->is_ifuba.ifu_xtofree = 0; 3536893Sfeldman } 3547261Ssam ilstart(unit); 3556893Sfeldman } 3566893Sfeldman 3576893Sfeldman /* 3586893Sfeldman * Ethernet interface receiver interrupt. 3596893Sfeldman * If input error just drop packet. 3606893Sfeldman * Otherwise purge input buffered data path and examine 3616893Sfeldman * packet to determine type. If can't determine length 3626893Sfeldman * from type, then have to drop packet. Othewise decapsulate 3636893Sfeldman * packet based on type and pass to type specific higher-level 3646893Sfeldman * input routine. 3656893Sfeldman */ 3666893Sfeldman ilrint(unit) 3676893Sfeldman int unit; 3686893Sfeldman { 3696893Sfeldman register struct il_softc *is = &il_softc[unit]; 3706893Sfeldman struct ildevice *addr = (struct ildevice *)ilinfo[unit]->ui_addr; 3716893Sfeldman register struct il_rheader *il; 3726893Sfeldman struct mbuf *m; 3736893Sfeldman int len, off, resid; 3746893Sfeldman register struct ifqueue *inq; 3756893Sfeldman 3766893Sfeldman is->is_if.if_ipackets++; 3776893Sfeldman if (is->is_ifuba.ifu_flags & UBA_NEEDBDP) 3786893Sfeldman UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp); 3796893Sfeldman il = (struct il_rheader *)(is->is_ifuba.ifu_r.ifrw_addr); 3806893Sfeldman len = il->ilr_length - sizeof(struct il_rheader); 3819746Ssam if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 || 3829746Ssam len > ETHERMTU) { 3836893Sfeldman is->is_if.if_ierrors++; 3846893Sfeldman #ifdef notdef 3856893Sfeldman if (is->is_if.if_ierrors % 100 == 0) 3866893Sfeldman printf("il%d: += 100 input errors\n", unit); 3876893Sfeldman #endif 3886893Sfeldman goto setup; 3896893Sfeldman } 3906893Sfeldman 3916893Sfeldman /* 3926893Sfeldman * Deal with trailer protocol: if type is PUP trailer 3936893Sfeldman * get true type from first 16-bit word past data. 3946893Sfeldman * Remember that type was trailer by setting off. 3956893Sfeldman */ 3969746Ssam il->ilr_type = ntohs((u_short)il->ilr_type); 3976893Sfeldman #define ildataaddr(il, off, type) ((type)(((caddr_t)((il)+1)+(off)))) 3989746Ssam if (il->ilr_type >= ETHERPUP_TRAIL && 3999746Ssam il->ilr_type < ETHERPUP_TRAIL+ETHERPUP_NTRAILER) { 4009746Ssam off = (il->ilr_type - ETHERPUP_TRAIL) * 512; 4019746Ssam if (off >= ETHERMTU) 4026893Sfeldman goto setup; /* sanity */ 4039746Ssam il->ilr_type = ntohs(*ildataaddr(il, off, u_short *)); 4049746Ssam resid = ntohs(*(ildataaddr(il, off+2, u_short *))); 4056893Sfeldman if (off + resid > len) 4066893Sfeldman goto setup; /* sanity */ 4076893Sfeldman len = off + resid; 4086893Sfeldman } else 4096893Sfeldman off = 0; 4106893Sfeldman if (len == 0) 4116893Sfeldman goto setup; 4126893Sfeldman 4136893Sfeldman /* 4146893Sfeldman * Pull packet off interface. Off is nonzero if packet 4156893Sfeldman * has trailing header; ilget will then force this header 4166893Sfeldman * information to be at the front, but we still have to drop 4176893Sfeldman * the type and length which are at the front of any trailer data. 4186893Sfeldman */ 4196893Sfeldman m = if_rubaget(&is->is_ifuba, len, off); 4206893Sfeldman if (m == 0) 4216893Sfeldman goto setup; 4226893Sfeldman if (off) { 4236893Sfeldman m->m_off += 2 * sizeof (u_short); 4246893Sfeldman m->m_len -= 2 * sizeof (u_short); 4256893Sfeldman } 4266893Sfeldman switch (il->ilr_type) { 4276893Sfeldman 4286893Sfeldman #ifdef INET 4299746Ssam case ETHERPUP_IPTYPE: 4306893Sfeldman schednetisr(NETISR_IP); 4316893Sfeldman inq = &ipintrq; 4326893Sfeldman break; 43311575Ssam 43411575Ssam case ETHERPUP_ARPTYPE: 43511575Ssam arpinput(&is->is_ac, m); 43611575Ssam return; 4376893Sfeldman #endif 4386893Sfeldman default: 4396893Sfeldman m_freem(m); 4406893Sfeldman goto setup; 4416893Sfeldman } 4426893Sfeldman 4436893Sfeldman if (IF_QFULL(inq)) { 4446893Sfeldman IF_DROP(inq); 4456893Sfeldman m_freem(m); 4467220Ssam goto setup; 4477220Ssam } 4487220Ssam IF_ENQUEUE(inq, m); 4496893Sfeldman 4506893Sfeldman setup: 4516893Sfeldman /* 4526893Sfeldman * Reset for next packet if possible. 4536893Sfeldman * If waiting for transmit command completion, set flag 4546893Sfeldman * and wait until command completes. 4556893Sfeldman */ 4567261Ssam if (is->is_flags & ILF_OACTIVE) { 4577261Ssam is->is_flags |= ILF_RCVPENDING; 4587220Ssam return; 4597220Ssam } 4607220Ssam addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 4619746Ssam addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6; 4627261Ssam addr->il_csr = 4637261Ssam ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE; 4647220Ssam while ((addr->il_csr & IL_CDONE) == 0) 4657220Ssam ; 4666893Sfeldman } 4676893Sfeldman 4686893Sfeldman /* 4696893Sfeldman * Ethernet output routine. 4706893Sfeldman * Encapsulate a packet of type family for the local net. 4716893Sfeldman * Use trailer local net encapsulation if enough data in first 4726893Sfeldman * packet leaves a multiple of 512 bytes of data in remainder. 4736893Sfeldman */ 4746893Sfeldman iloutput(ifp, m0, dst) 4756893Sfeldman struct ifnet *ifp; 4766893Sfeldman struct mbuf *m0; 4776893Sfeldman struct sockaddr *dst; 4786893Sfeldman { 47911575Ssam int type, s, error; 48011575Ssam u_char edst[6]; 48111575Ssam struct in_addr idst; 4826893Sfeldman register struct il_softc *is = &il_softc[ifp->if_unit]; 4836893Sfeldman register struct mbuf *m = m0; 4849746Ssam register struct ether_header *il; 4859179Ssam register int off; 4866893Sfeldman 4876893Sfeldman switch (dst->sa_family) { 4886893Sfeldman 4896893Sfeldman #ifdef INET 4906893Sfeldman case AF_INET: 49111575Ssam idst = ((struct sockaddr_in *)dst)->sin_addr; 49211575Ssam if (!arpresolve(&is->is_ac, m, &idst, edst)) 49311575Ssam return (0); /* if not yet resolved */ 4946893Sfeldman off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len; 4956893Sfeldman if (off > 0 && (off & 0x1ff) == 0 && 4966893Sfeldman m->m_off >= MMINOFF + 2 * sizeof (u_short)) { 4979746Ssam type = ETHERPUP_TRAIL + (off>>9); 4986893Sfeldman m->m_off -= 2 * sizeof (u_short); 4996893Sfeldman m->m_len += 2 * sizeof (u_short); 5009746Ssam *mtod(m, u_short *) = htons((u_short)ETHERPUP_IPTYPE); 5019746Ssam *(mtod(m, u_short *) + 1) = htons((u_short)m->m_len); 5026893Sfeldman goto gottrailertype; 5036893Sfeldman } 5049746Ssam type = ETHERPUP_IPTYPE; 5056893Sfeldman off = 0; 5066893Sfeldman goto gottype; 5076893Sfeldman #endif 5086893Sfeldman 50911575Ssam case AF_UNSPEC: 51011575Ssam il = (struct ether_header *)dst->sa_data; 51111575Ssam bcopy(il->ether_dhost, edst, sizeof (edst)); 51211575Ssam type = il->ether_type; 51311575Ssam goto gottype; 51411575Ssam 5156893Sfeldman default: 5166893Sfeldman printf("il%d: can't handle af%d\n", ifp->if_unit, 5176893Sfeldman dst->sa_family); 5186893Sfeldman error = EAFNOSUPPORT; 5196893Sfeldman goto bad; 5206893Sfeldman } 5216893Sfeldman 5226893Sfeldman gottrailertype: 5236893Sfeldman /* 5246893Sfeldman * Packet to be sent as trailer: move first packet 5256893Sfeldman * (control information) to end of chain. 5266893Sfeldman */ 5276893Sfeldman while (m->m_next) 5286893Sfeldman m = m->m_next; 5296893Sfeldman m->m_next = m0; 5306893Sfeldman m = m0->m_next; 5316893Sfeldman m0->m_next = 0; 5326893Sfeldman m0 = m; 5336893Sfeldman 5346893Sfeldman gottype: 5356893Sfeldman /* 5366893Sfeldman * Add local net header. If no space in first mbuf, 5376893Sfeldman * allocate another. 5386893Sfeldman */ 5396893Sfeldman if (m->m_off > MMAXOFF || 5409746Ssam MMINOFF + sizeof (struct ether_header) > m->m_off) { 5419650Ssam m = m_get(M_DONTWAIT, MT_HEADER); 5426893Sfeldman if (m == 0) { 5436893Sfeldman error = ENOBUFS; 5446893Sfeldman goto bad; 5456893Sfeldman } 5466893Sfeldman m->m_next = m0; 5476893Sfeldman m->m_off = MMINOFF; 5489746Ssam m->m_len = sizeof (struct ether_header); 5496893Sfeldman } else { 5509746Ssam m->m_off -= sizeof (struct ether_header); 5519746Ssam m->m_len += sizeof (struct ether_header); 5526893Sfeldman } 5539746Ssam il = mtod(m, struct ether_header *); 5549746Ssam il->ether_type = htons((u_short)type); 55511575Ssam bcopy(edst, il->ether_dhost, sizeof (edst)); 55611575Ssam bcopy((caddr_t)is->is_addr, (caddr_t)il->ether_shost, 6); 5576893Sfeldman 5586893Sfeldman /* 5596893Sfeldman * Queue message on interface, and start output if interface 5606893Sfeldman * not yet active. 5616893Sfeldman */ 5626893Sfeldman s = splimp(); 5636893Sfeldman if (IF_QFULL(&ifp->if_snd)) { 5646893Sfeldman IF_DROP(&ifp->if_snd); 5657220Ssam splx(s); 5667220Ssam m_freem(m); 5677220Ssam return (ENOBUFS); 5686893Sfeldman } 5696893Sfeldman IF_ENQUEUE(&ifp->if_snd, m); 5707261Ssam if ((is->is_flags & ILF_OACTIVE) == 0) 5716893Sfeldman ilstart(ifp->if_unit); 5726893Sfeldman splx(s); 5736893Sfeldman return (0); 5747220Ssam 5756893Sfeldman bad: 5766893Sfeldman m_freem(m0); 5777220Ssam return (error); 5786893Sfeldman } 5797261Ssam 5807261Ssam /* 5817261Ssam * Watchdog routine, request statistics from board. 5827261Ssam */ 5837261Ssam ilwatch(unit) 5847261Ssam int unit; 5857261Ssam { 5867261Ssam register struct il_softc *is = &il_softc[unit]; 5877261Ssam register struct ifnet *ifp = &is->is_if; 5887261Ssam int s; 5897261Ssam 5907261Ssam if (is->is_flags & ILF_STATPENDING) { 5917261Ssam ifp->if_timer = is->is_scaninterval; 5927261Ssam return; 5937261Ssam } 5947261Ssam s = splimp(); 5957261Ssam is->is_flags |= ILF_STATPENDING; 5967261Ssam if ((is->is_flags & ILF_OACTIVE) == 0) 5977261Ssam ilstart(ifp->if_unit); 5987261Ssam splx(s); 5997261Ssam ifp->if_timer = is->is_scaninterval; 6007261Ssam } 6017261Ssam 6027261Ssam /* 6037261Ssam * Total up the on-board statistics. 6047261Ssam */ 6057261Ssam iltotal(is) 6067261Ssam register struct il_softc *is; 6077261Ssam { 6087261Ssam register u_short *interval, *sum, *end; 6097261Ssam 6107261Ssam interval = &is->is_stats.ils_frames; 6117261Ssam sum = &is->is_sum.ils_frames; 6127261Ssam end = is->is_sum.ils_fill2; 6137261Ssam while (sum < end) 6147261Ssam *sum++ += *interval++; 6157261Ssam is->is_if.if_collisions = is->is_sum.ils_collis; 6167261Ssam } 617