1*9746Ssam /* if_il.c 4.16 82/12/16 */ 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/vmmac.h" 168463Sroot #include <errno.h> 178463Sroot 188463Sroot #include "../net/if.h" 198463Sroot #include "../net/netisr.h" 208463Sroot #include "../net/route.h" 218419Swnj #include "../netinet/in.h" 228419Swnj #include "../netinet/in_systm.h" 238419Swnj #include "../netinet/ip.h" 248419Swnj #include "../netinet/ip_var.h" 258419Swnj #include "../netpup/pup.h" 266893Sfeldman 278463Sroot #include "../vax/cpu.h" 288463Sroot #include "../vax/mtpr.h" 29*9746Ssam #include "../vaxif/if_ether.h" 30*9746Ssam #include "../vaxif/if_il.h" 318463Sroot #include "../vaxif/if_ilreg.h" 328463Sroot #include "../vaxif/if_uba.h" 338463Sroot #include "../vaxuba/ubareg.h" 348463Sroot #include "../vaxuba/ubavar.h" 358463Sroot 366893Sfeldman int ilprobe(), ilattach(), ilrint(), ilcint(); 376893Sfeldman struct uba_device *ilinfo[NIL]; 386893Sfeldman u_short ilstd[] = { 0 }; 396893Sfeldman struct uba_driver ildriver = 406893Sfeldman { ilprobe, 0, ilattach, 0, ilstd, "il", ilinfo }; 416893Sfeldman #define ILUNIT(x) minor(x) 427261Ssam int ilinit(),iloutput(),ilreset(),ilwatch(); 436893Sfeldman 447220Ssam u_char il_ectop[3] = { 0x02, 0x60, 0x8c }; 457220Ssam u_char ilbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 467220Ssam 476893Sfeldman /* 486893Sfeldman * Ethernet software status per interface. 496893Sfeldman * 506893Sfeldman * Each interface is referenced by a network interface structure, 516893Sfeldman * is_if, which the routing code uses to locate the interface. 526893Sfeldman * This structure contains the output queue for the interface, its address, ... 536893Sfeldman * We also have, for each interface, a UBA interface structure, which 546893Sfeldman * contains information about the UNIBUS resources held by the interface: 556893Sfeldman * map registers, buffered data paths, etc. Information is cached in this 566893Sfeldman * structure for use by the if_uba.c routines in running the interface 576893Sfeldman * efficiently. 586893Sfeldman */ 596893Sfeldman struct il_softc { 606893Sfeldman struct ifnet is_if; /* network-visible interface */ 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"; 110*9746Ssam ifp->if_mtu = ETHERMTU; 1117220Ssam ifp->if_net = ui->ui_flags; 1126893Sfeldman 1136893Sfeldman /* 1147261Ssam * Reset the board and map the statistics 1157261Ssam * buffer onto the Unibus. 1166893Sfeldman */ 1177261Ssam addr->il_csr = ILC_RESET; 1187261Ssam while ((addr->il_csr&IL_CDONE) == 0) 1197261Ssam ; 1207261Ssam if (addr->il_csr&IL_STATUS) 1217261Ssam printf("il%d: reset failed, csr=%b\n", ui->ui_unit, 1227261Ssam addr->il_csr, IL_BITS); 1236893Sfeldman 1249179Ssam is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats, 1257261Ssam sizeof (struct il_stats), 0); 1267261Ssam addr->il_bar = is->is_ubaddr & 0xffff; 1277261Ssam addr->il_bcr = sizeof (struct il_stats); 1287261Ssam addr->il_csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT; 1297261Ssam while ((addr->il_csr&IL_CDONE) == 0) 1307261Ssam ; 1317261Ssam if (addr->il_csr&IL_STATUS) 1327261Ssam printf("il%d: status failed, csr=%b\n", ui->ui_unit, 1337261Ssam addr->il_csr, IL_BITS); 1347261Ssam ubarelse(ui->ui_ubanum, &is->is_ubaddr); 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); 1417261Ssam ifp->if_host[0] = 1427261Ssam ((is->is_stats.ils_addr[3]&0xff)<<16) | 0x800000 | 1437261Ssam ((is->is_stats.ils_addr[4]&0xff)<<8) | 1447261Ssam (is->is_stats.ils_addr[5]&0xff); 1457220Ssam sin = (struct sockaddr_in *)&ifp->if_addr; 1466893Sfeldman sin->sin_family = AF_INET; 1477220Ssam sin->sin_addr = if_makeaddr(ifp->if_net, ifp->if_host[0]); 1486893Sfeldman 1497220Ssam sin = (struct sockaddr_in *)&ifp->if_broadaddr; 1506893Sfeldman sin->sin_family = AF_INET; 1517220Ssam sin->sin_addr = if_makeaddr(ifp->if_net, INADDR_ANY); 1527220Ssam ifp->if_flags = IFF_BROADCAST; 1536893Sfeldman 1547220Ssam ifp->if_init = ilinit; 1557220Ssam ifp->if_output = iloutput; 1568979Sroot ifp->if_reset = ilreset; 1577261Ssam ifp->if_watchdog = ilwatch; 1587261Ssam is->is_scaninterval = ILWATCHINTERVAL; 1597261Ssam ifp->if_timer = is->is_scaninterval; 1606893Sfeldman is->is_ifuba.ifu_flags = UBA_CANTWAIT; 1617220Ssam #ifdef notdef 1627220Ssam is->is_ifuba.ifu_flags |= UBA_NEEDBDP; 1637220Ssam #endif 1647220Ssam if_attach(ifp); 1656893Sfeldman } 1666893Sfeldman 1676893Sfeldman /* 1686893Sfeldman * Reset of interface after UNIBUS reset. 1696893Sfeldman * If interface is on specified uba, reset its state. 1706893Sfeldman */ 1716893Sfeldman ilreset(unit, uban) 1726893Sfeldman int unit, uban; 1736893Sfeldman { 1746893Sfeldman register struct uba_device *ui; 1756893Sfeldman 1766893Sfeldman if (unit >= NIL || (ui = ilinfo[unit]) == 0 || ui->ui_alive == 0 || 1776893Sfeldman ui->ui_ubanum != uban) 1786893Sfeldman return; 1796893Sfeldman printf(" il%d", unit); 1806893Sfeldman ilinit(unit); 1816893Sfeldman } 1826893Sfeldman 1836893Sfeldman /* 1846893Sfeldman * Initialization of interface; clear recorded pending 1856893Sfeldman * operations, and reinitialize UNIBUS usage. 1866893Sfeldman */ 1876893Sfeldman ilinit(unit) 1886893Sfeldman int unit; 1896893Sfeldman { 1906893Sfeldman register struct il_softc *is = &il_softc[unit]; 1916893Sfeldman register struct uba_device *ui = ilinfo[unit]; 1926893Sfeldman register struct ildevice *addr; 1937261Ssam int s; 1946893Sfeldman 1956893Sfeldman if (if_ubainit(&is->is_ifuba, ui->ui_ubanum, 196*9746Ssam sizeof (struct il_rheader), (int)btoc(ETHERMTU)) == 0) { 1976893Sfeldman printf("il%d: can't initialize\n", unit); 1986893Sfeldman is->is_if.if_flags &= ~IFF_UP; 1996893Sfeldman return; 2006893Sfeldman } 2019179Ssam is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats, 2027261Ssam sizeof (struct il_stats), 0); 2036893Sfeldman addr = (struct ildevice *)ui->ui_addr; 2046893Sfeldman 2056893Sfeldman /* 2069179Ssam * Turn off source address insertion (it's faster this way), 2079179Ssam * and set board online. 2089179Ssam */ 2099179Ssam s = splimp(); 2109179Ssam addr->il_csr = ILC_CISA; 2119179Ssam while ((addr->il_csr & IL_CDONE) == 0) 2129179Ssam ; 2139179Ssam addr->il_csr = ILC_ONLINE; 2149179Ssam while ((addr->il_csr & IL_CDONE) == 0) 2159179Ssam ; 2169179Ssam /* 2176893Sfeldman * Set board online. 2186893Sfeldman * Hang receive buffer and start any pending 2196893Sfeldman * writes by faking a transmit complete. 2206893Sfeldman * Receive bcr is not a muliple of 4 so buffer 2216893Sfeldman * chaining can't happen. 2226893Sfeldman */ 2236893Sfeldman s = splimp(); 2246893Sfeldman addr->il_csr = ILC_ONLINE; 2257220Ssam while ((addr->il_csr & IL_CDONE) == 0) 2267220Ssam ; 2276893Sfeldman addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 228*9746Ssam addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6; 2297261Ssam addr->il_csr = 2307261Ssam ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE; 2317220Ssam while ((addr->il_csr & IL_CDONE) == 0) 2327220Ssam ; 2337261Ssam is->is_flags = ILF_OACTIVE; 2346893Sfeldman is->is_if.if_flags |= IFF_UP; 2357261Ssam is->is_lastcmd = 0; 2366893Sfeldman ilcint(unit); 2376893Sfeldman splx(s); 2387152Swnj if_rtinit(&is->is_if, RTF_UP); 2396893Sfeldman } 2406893Sfeldman 2416893Sfeldman /* 2426893Sfeldman * Start output on interface. 2436893Sfeldman * Get another datagram to send off of the interface queue, 2446893Sfeldman * and map it to the interface before starting the output. 2456893Sfeldman */ 2466893Sfeldman ilstart(dev) 2476893Sfeldman dev_t dev; 2486893Sfeldman { 2499179Ssam int unit = ILUNIT(dev), len; 2506893Sfeldman struct uba_device *ui = ilinfo[unit]; 2516893Sfeldman register struct il_softc *is = &il_softc[unit]; 2526893Sfeldman register struct ildevice *addr; 2536893Sfeldman struct mbuf *m; 2547220Ssam short csr; 2556893Sfeldman 2566893Sfeldman IF_DEQUEUE(&is->is_if.if_snd, m); 2577261Ssam addr = (struct ildevice *)ui->ui_addr; 2587261Ssam if (m == 0) { 2597261Ssam if ((is->is_flags & ILF_STATPENDING) == 0) 2607261Ssam return; 2619179Ssam addr->il_bar = is->is_ubaddr & 0xffff; 2627261Ssam addr->il_bcr = sizeof (struct il_stats); 2637261Ssam csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE; 2647261Ssam is->is_flags &= ~ILF_STATPENDING; 2657261Ssam goto startcmd; 2667261Ssam } 2676893Sfeldman len = if_wubaput(&is->is_ifuba, m); 2689179Ssam /* 2699179Ssam * Ensure minimum packet length. 2709179Ssam * This makes the safe assumtion that there are no virtual holes 2719179Ssam * after the data. 2729179Ssam * For security, it might be wise to zero out the added bytes, 2739179Ssam * but we're mainly interested in speed at the moment. 2749179Ssam */ 275*9746Ssam if (len - sizeof(struct ether_header) < ETHERMIN) 276*9746Ssam len = ETHERMIN + sizeof(struct ether_header); 2776893Sfeldman if (is->is_ifuba.ifu_flags & UBA_NEEDBDP) 2786893Sfeldman UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp); 2796893Sfeldman addr->il_bar = is->is_ifuba.ifu_w.ifrw_info & 0xffff; 2806893Sfeldman addr->il_bcr = len; 2817261Ssam csr = 2827261Ssam ((is->is_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE; 2837261Ssam 2847261Ssam startcmd: 2857261Ssam is->is_lastcmd = csr & IL_CMD; 2867220Ssam addr->il_csr = csr; 2877261Ssam is->is_flags |= ILF_OACTIVE; 2886893Sfeldman } 2896893Sfeldman 2906893Sfeldman /* 2916893Sfeldman * Command done interrupt. 2926893Sfeldman */ 2936893Sfeldman ilcint(unit) 2946893Sfeldman int unit; 2956893Sfeldman { 2966893Sfeldman register struct il_softc *is = &il_softc[unit]; 2977220Ssam struct uba_device *ui = ilinfo[unit]; 2986893Sfeldman register struct ildevice *addr = (struct ildevice *)ui->ui_addr; 2997266Ssam short csr; 3006893Sfeldman 3017261Ssam if ((is->is_flags & ILF_OACTIVE) == 0) { 3027220Ssam printf("il%d: stray xmit interrupt, csr=%b\n", unit, 3037261Ssam addr->il_csr, IL_BITS); 3046893Sfeldman return; 3056893Sfeldman } 3067220Ssam 3077266Ssam csr = addr->il_csr; 3086893Sfeldman /* 3097261Ssam * Hang receive buffer if it couldn't 3107261Ssam * be done earlier (in ilrint). 3116893Sfeldman */ 3127261Ssam if (is->is_flags & ILF_RCVPENDING) { 3136893Sfeldman addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 314*9746Ssam addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6; 3157261Ssam addr->il_csr = 3167261Ssam ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE; 3177220Ssam while ((addr->il_csr & IL_CDONE) == 0) 3187220Ssam ; 3197261Ssam is->is_flags &= ~ILF_RCVPENDING; 3206893Sfeldman } 3217261Ssam is->is_flags &= ~ILF_OACTIVE; 3227266Ssam csr &= IL_STATUS; 3237261Ssam switch (is->is_lastcmd) { 3247261Ssam 3257261Ssam case ILC_XMIT: 3267261Ssam is->is_if.if_opackets++; 3277266Ssam if (csr > ILERR_RETRIES) 3287261Ssam is->is_if.if_oerrors++; 3297261Ssam break; 3307261Ssam 3317261Ssam case ILC_STAT: 3327266Ssam if (csr == ILERR_SUCCESS) 3337261Ssam iltotal(is); 3347261Ssam break; 3357261Ssam } 3366893Sfeldman if (is->is_ifuba.ifu_xtofree) { 3376893Sfeldman m_freem(is->is_ifuba.ifu_xtofree); 3386893Sfeldman is->is_ifuba.ifu_xtofree = 0; 3396893Sfeldman } 3407261Ssam ilstart(unit); 3416893Sfeldman } 3426893Sfeldman 3436893Sfeldman /* 3446893Sfeldman * Ethernet interface receiver interrupt. 3456893Sfeldman * If input error just drop packet. 3466893Sfeldman * Otherwise purge input buffered data path and examine 3476893Sfeldman * packet to determine type. If can't determine length 3486893Sfeldman * from type, then have to drop packet. Othewise decapsulate 3496893Sfeldman * packet based on type and pass to type specific higher-level 3506893Sfeldman * input routine. 3516893Sfeldman */ 3526893Sfeldman ilrint(unit) 3536893Sfeldman int unit; 3546893Sfeldman { 3556893Sfeldman register struct il_softc *is = &il_softc[unit]; 3566893Sfeldman struct ildevice *addr = (struct ildevice *)ilinfo[unit]->ui_addr; 3576893Sfeldman register struct il_rheader *il; 3586893Sfeldman struct mbuf *m; 3596893Sfeldman int len, off, resid; 3606893Sfeldman register struct ifqueue *inq; 3616893Sfeldman 3626893Sfeldman is->is_if.if_ipackets++; 3636893Sfeldman if (is->is_ifuba.ifu_flags & UBA_NEEDBDP) 3646893Sfeldman UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp); 3656893Sfeldman il = (struct il_rheader *)(is->is_ifuba.ifu_r.ifrw_addr); 3666893Sfeldman len = il->ilr_length - sizeof(struct il_rheader); 367*9746Ssam if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 || 368*9746Ssam len > ETHERMTU) { 3696893Sfeldman is->is_if.if_ierrors++; 3706893Sfeldman #ifdef notdef 3716893Sfeldman if (is->is_if.if_ierrors % 100 == 0) 3726893Sfeldman printf("il%d: += 100 input errors\n", unit); 3736893Sfeldman #endif 3746893Sfeldman goto setup; 3756893Sfeldman } 3766893Sfeldman 3776893Sfeldman /* 3786893Sfeldman * Deal with trailer protocol: if type is PUP trailer 3796893Sfeldman * get true type from first 16-bit word past data. 3806893Sfeldman * Remember that type was trailer by setting off. 3816893Sfeldman */ 382*9746Ssam il->ilr_type = ntohs((u_short)il->ilr_type); 3836893Sfeldman #define ildataaddr(il, off, type) ((type)(((caddr_t)((il)+1)+(off)))) 384*9746Ssam if (il->ilr_type >= ETHERPUP_TRAIL && 385*9746Ssam il->ilr_type < ETHERPUP_TRAIL+ETHERPUP_NTRAILER) { 386*9746Ssam off = (il->ilr_type - ETHERPUP_TRAIL) * 512; 387*9746Ssam if (off >= ETHERMTU) 3886893Sfeldman goto setup; /* sanity */ 389*9746Ssam il->ilr_type = ntohs(*ildataaddr(il, off, u_short *)); 390*9746Ssam resid = ntohs(*(ildataaddr(il, off+2, u_short *))); 3916893Sfeldman if (off + resid > len) 3926893Sfeldman goto setup; /* sanity */ 3936893Sfeldman len = off + resid; 3946893Sfeldman } else 3956893Sfeldman off = 0; 3966893Sfeldman if (len == 0) 3976893Sfeldman goto setup; 3986893Sfeldman 3996893Sfeldman /* 4006893Sfeldman * Pull packet off interface. Off is nonzero if packet 4016893Sfeldman * has trailing header; ilget will then force this header 4026893Sfeldman * information to be at the front, but we still have to drop 4036893Sfeldman * the type and length which are at the front of any trailer data. 4046893Sfeldman */ 4056893Sfeldman m = if_rubaget(&is->is_ifuba, len, off); 4066893Sfeldman if (m == 0) 4076893Sfeldman goto setup; 4086893Sfeldman if (off) { 4096893Sfeldman m->m_off += 2 * sizeof (u_short); 4106893Sfeldman m->m_len -= 2 * sizeof (u_short); 4116893Sfeldman } 4126893Sfeldman switch (il->ilr_type) { 4136893Sfeldman 4146893Sfeldman #ifdef INET 415*9746Ssam case ETHERPUP_IPTYPE: 4166893Sfeldman schednetisr(NETISR_IP); 4176893Sfeldman inq = &ipintrq; 4186893Sfeldman break; 4196893Sfeldman #endif 4206893Sfeldman default: 4216893Sfeldman m_freem(m); 4226893Sfeldman goto setup; 4236893Sfeldman } 4246893Sfeldman 4256893Sfeldman if (IF_QFULL(inq)) { 4266893Sfeldman IF_DROP(inq); 4276893Sfeldman m_freem(m); 4287220Ssam goto setup; 4297220Ssam } 4307220Ssam IF_ENQUEUE(inq, m); 4316893Sfeldman 4326893Sfeldman setup: 4336893Sfeldman /* 4346893Sfeldman * Reset for next packet if possible. 4356893Sfeldman * If waiting for transmit command completion, set flag 4366893Sfeldman * and wait until command completes. 4376893Sfeldman */ 4387261Ssam if (is->is_flags & ILF_OACTIVE) { 4397261Ssam is->is_flags |= ILF_RCVPENDING; 4407220Ssam return; 4417220Ssam } 4427220Ssam addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 443*9746Ssam addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6; 4447261Ssam addr->il_csr = 4457261Ssam ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE; 4467220Ssam while ((addr->il_csr & IL_CDONE) == 0) 4477220Ssam ; 4486893Sfeldman } 4496893Sfeldman 4506893Sfeldman /* 4516893Sfeldman * Ethernet output routine. 4526893Sfeldman * Encapsulate a packet of type family for the local net. 4536893Sfeldman * Use trailer local net encapsulation if enough data in first 4546893Sfeldman * packet leaves a multiple of 512 bytes of data in remainder. 4556893Sfeldman */ 4566893Sfeldman iloutput(ifp, m0, dst) 4576893Sfeldman struct ifnet *ifp; 4586893Sfeldman struct mbuf *m0; 4596893Sfeldman struct sockaddr *dst; 4606893Sfeldman { 4616893Sfeldman int type, dest, s, error; 4626893Sfeldman register struct il_softc *is = &il_softc[ifp->if_unit]; 4636893Sfeldman register struct mbuf *m = m0; 464*9746Ssam register struct ether_header *il; 4659179Ssam register int off; 4666893Sfeldman 4676893Sfeldman switch (dst->sa_family) { 4686893Sfeldman 4696893Sfeldman #ifdef INET 4706893Sfeldman case AF_INET: 4716893Sfeldman dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr; 4726893Sfeldman off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len; 4736893Sfeldman if (off > 0 && (off & 0x1ff) == 0 && 4746893Sfeldman m->m_off >= MMINOFF + 2 * sizeof (u_short)) { 475*9746Ssam type = ETHERPUP_TRAIL + (off>>9); 4766893Sfeldman m->m_off -= 2 * sizeof (u_short); 4776893Sfeldman m->m_len += 2 * sizeof (u_short); 478*9746Ssam *mtod(m, u_short *) = htons((u_short)ETHERPUP_IPTYPE); 479*9746Ssam *(mtod(m, u_short *) + 1) = htons((u_short)m->m_len); 4806893Sfeldman goto gottrailertype; 4816893Sfeldman } 482*9746Ssam type = ETHERPUP_IPTYPE; 4836893Sfeldman off = 0; 4846893Sfeldman goto gottype; 4856893Sfeldman #endif 4866893Sfeldman 4876893Sfeldman default: 4886893Sfeldman printf("il%d: can't handle af%d\n", ifp->if_unit, 4896893Sfeldman dst->sa_family); 4906893Sfeldman error = EAFNOSUPPORT; 4916893Sfeldman goto bad; 4926893Sfeldman } 4936893Sfeldman 4946893Sfeldman gottrailertype: 4956893Sfeldman /* 4966893Sfeldman * Packet to be sent as trailer: move first packet 4976893Sfeldman * (control information) to end of chain. 4986893Sfeldman */ 4996893Sfeldman while (m->m_next) 5006893Sfeldman m = m->m_next; 5016893Sfeldman m->m_next = m0; 5026893Sfeldman m = m0->m_next; 5036893Sfeldman m0->m_next = 0; 5046893Sfeldman m0 = m; 5056893Sfeldman 5066893Sfeldman gottype: 5076893Sfeldman /* 5086893Sfeldman * Add local net header. If no space in first mbuf, 5096893Sfeldman * allocate another. 5106893Sfeldman */ 5116893Sfeldman if (m->m_off > MMAXOFF || 512*9746Ssam MMINOFF + sizeof (struct ether_header) > m->m_off) { 5139650Ssam m = m_get(M_DONTWAIT, MT_HEADER); 5146893Sfeldman if (m == 0) { 5156893Sfeldman error = ENOBUFS; 5166893Sfeldman goto bad; 5176893Sfeldman } 5186893Sfeldman m->m_next = m0; 5196893Sfeldman m->m_off = MMINOFF; 520*9746Ssam m->m_len = sizeof (struct ether_header); 5216893Sfeldman } else { 522*9746Ssam m->m_off -= sizeof (struct ether_header); 523*9746Ssam m->m_len += sizeof (struct ether_header); 5246893Sfeldman } 525*9746Ssam il = mtod(m, struct ether_header *); 5266893Sfeldman if ((dest &~ 0xff) == 0) 527*9746Ssam bcopy((caddr_t)ilbroadcastaddr, (caddr_t)il->ether_dhost, 6); 5286893Sfeldman else { 5297261Ssam u_char *to = dest & 0x8000 ? is->is_stats.ils_addr : il_ectop; 5307220Ssam 531*9746Ssam bcopy((caddr_t)to, (caddr_t)il->ether_dhost, 3); 532*9746Ssam il->ether_dhost[3] = (dest>>8) & 0x7f; 533*9746Ssam il->ether_dhost[4] = (dest>>16) & 0xff; 534*9746Ssam il->ether_dhost[5] = (dest>>24) & 0xff; 5356893Sfeldman } 536*9746Ssam bcopy((caddr_t)is->is_stats.ils_addr, (caddr_t)il->ether_shost, 6); 537*9746Ssam il->ether_type = htons((u_short)type); 5386893Sfeldman 5396893Sfeldman /* 5406893Sfeldman * Queue message on interface, and start output if interface 5416893Sfeldman * not yet active. 5426893Sfeldman */ 5436893Sfeldman s = splimp(); 5446893Sfeldman if (IF_QFULL(&ifp->if_snd)) { 5456893Sfeldman IF_DROP(&ifp->if_snd); 5467220Ssam splx(s); 5477220Ssam m_freem(m); 5487220Ssam return (ENOBUFS); 5496893Sfeldman } 5506893Sfeldman IF_ENQUEUE(&ifp->if_snd, m); 5517261Ssam if ((is->is_flags & ILF_OACTIVE) == 0) 5526893Sfeldman ilstart(ifp->if_unit); 5536893Sfeldman splx(s); 5546893Sfeldman return (0); 5557220Ssam 5566893Sfeldman bad: 5576893Sfeldman m_freem(m0); 5587220Ssam return (error); 5596893Sfeldman } 5607261Ssam 5617261Ssam /* 5627261Ssam * Watchdog routine, request statistics from board. 5637261Ssam */ 5647261Ssam ilwatch(unit) 5657261Ssam int unit; 5667261Ssam { 5677261Ssam register struct il_softc *is = &il_softc[unit]; 5687261Ssam register struct ifnet *ifp = &is->is_if; 5697261Ssam int s; 5707261Ssam 5717261Ssam if (is->is_flags & ILF_STATPENDING) { 5727261Ssam ifp->if_timer = is->is_scaninterval; 5737261Ssam return; 5747261Ssam } 5757261Ssam s = splimp(); 5767261Ssam is->is_flags |= ILF_STATPENDING; 5777261Ssam if ((is->is_flags & ILF_OACTIVE) == 0) 5787261Ssam ilstart(ifp->if_unit); 5797261Ssam splx(s); 5807261Ssam ifp->if_timer = is->is_scaninterval; 5817261Ssam } 5827261Ssam 5837261Ssam /* 5847261Ssam * Total up the on-board statistics. 5857261Ssam */ 5867261Ssam iltotal(is) 5877261Ssam register struct il_softc *is; 5887261Ssam { 5897261Ssam register u_short *interval, *sum, *end; 5907261Ssam 5917261Ssam interval = &is->is_stats.ils_frames; 5927261Ssam sum = &is->is_sum.ils_frames; 5937261Ssam end = is->is_sum.ils_fill2; 5947261Ssam while (sum < end) 5957261Ssam *sum++ += *interval++; 5967261Ssam is->is_if.if_collisions = is->is_sum.ils_collis; 5977261Ssam } 598