123557Ssklower /* 223557Ssklower * Copyright (c) 1982 Regents of the University of California. 323557Ssklower * All rights reserved. The Berkeley software License Agreement 423557Ssklower * specifies the terms and conditions for redistribution. 523557Ssklower * 6*24791Skarels * @(#)if_il.c 6.9 (Berkeley) 09/16/85 723557Ssklower */ 86893Sfeldman 96893Sfeldman #include "il.h" 106893Sfeldman 116893Sfeldman /* 126893Sfeldman * Interlan Ethernet Communications Controller interface 136893Sfeldman */ 149797Ssam #include "../machine/pte.h" 159797Ssam 1617115Sbloom #include "param.h" 1717115Sbloom #include "systm.h" 1817115Sbloom #include "mbuf.h" 1917115Sbloom #include "buf.h" 2017115Sbloom #include "protosw.h" 2117115Sbloom #include "socket.h" 2217115Sbloom #include "vmmac.h" 2317115Sbloom #include "ioctl.h" 2417115Sbloom #include "errno.h" 258463Sroot 268463Sroot #include "../net/if.h" 278463Sroot #include "../net/netisr.h" 288463Sroot #include "../net/route.h" 2923557Ssklower 30*24791Skarels #ifdef BBNNET 31*24791Skarels #define INET 32*24791Skarels #endif 3323557Ssklower #ifdef INET 348419Swnj #include "../netinet/in.h" 358419Swnj #include "../netinet/in_systm.h" 3619865Skarels #include "../netinet/in_var.h" 378419Swnj #include "../netinet/ip.h" 3811575Ssam #include "../netinet/if_ether.h" 3923557Ssklower #endif 4023557Ssklower 4119949Sbloom #ifdef PUP 428419Swnj #include "../netpup/pup.h" 4319949Sbloom #endif 446893Sfeldman 4523557Ssklower #ifdef NS 4623557Ssklower #include "../netns/ns.h" 4723557Ssklower #include "../netns/ns_if.h" 4823557Ssklower #endif 4923557Ssklower 508463Sroot #include "../vax/cpu.h" 518463Sroot #include "../vax/mtpr.h" 5217115Sbloom #include "if_il.h" 5317115Sbloom #include "if_ilreg.h" 5417115Sbloom #include "if_uba.h" 558463Sroot #include "../vaxuba/ubareg.h" 568463Sroot #include "../vaxuba/ubavar.h" 578463Sroot 586893Sfeldman int ilprobe(), ilattach(), ilrint(), ilcint(); 596893Sfeldman struct uba_device *ilinfo[NIL]; 606893Sfeldman u_short ilstd[] = { 0 }; 616893Sfeldman struct uba_driver ildriver = 626893Sfeldman { ilprobe, 0, ilattach, 0, ilstd, "il", ilinfo }; 636893Sfeldman #define ILUNIT(x) minor(x) 6413056Ssam int ilinit(),iloutput(),ilioctl(),ilreset(),ilwatch(); 656893Sfeldman 666893Sfeldman /* 676893Sfeldman * Ethernet software status per interface. 686893Sfeldman * 696893Sfeldman * Each interface is referenced by a network interface structure, 706893Sfeldman * is_if, which the routing code uses to locate the interface. 716893Sfeldman * This structure contains the output queue for the interface, its address, ... 726893Sfeldman * We also have, for each interface, a UBA interface structure, which 736893Sfeldman * contains information about the UNIBUS resources held by the interface: 746893Sfeldman * map registers, buffered data paths, etc. Information is cached in this 756893Sfeldman * structure for use by the if_uba.c routines in running the interface 766893Sfeldman * efficiently. 776893Sfeldman */ 786893Sfeldman struct il_softc { 7911575Ssam struct arpcom is_ac; /* Ethernet common part */ 8011575Ssam #define is_if is_ac.ac_if /* network-visible interface */ 8111575Ssam #define is_addr is_ac.ac_enaddr /* hardware Ethernet address */ 826893Sfeldman struct ifuba is_ifuba; /* UNIBUS resources */ 837261Ssam int is_flags; 847261Ssam #define ILF_OACTIVE 0x1 /* output is active */ 857261Ssam #define ILF_RCVPENDING 0x2 /* start rcv in ilcint */ 867261Ssam #define ILF_STATPENDING 0x4 /* stat cmd pending */ 877261Ssam short is_lastcmd; /* can't read csr, so must save it */ 887261Ssam short is_scaninterval; /* interval of stat collection */ 897261Ssam #define ILWATCHINTERVAL 60 /* once every 60 seconds */ 907261Ssam struct il_stats is_stats; /* holds on-board statistics */ 917261Ssam struct il_stats is_sum; /* summation over time */ 927261Ssam int is_ubaddr; /* mapping registers of is_stats */ 936893Sfeldman } il_softc[NIL]; 946893Sfeldman 956893Sfeldman ilprobe(reg) 966893Sfeldman caddr_t reg; 976893Sfeldman { 986893Sfeldman register int br, cvec; /* r11, r10 value-result */ 996893Sfeldman register struct ildevice *addr = (struct ildevice *)reg; 1006893Sfeldman register i; 1016893Sfeldman 1026893Sfeldman #ifdef lint 1036893Sfeldman br = 0; cvec = br; br = cvec; 1049179Ssam i = 0; ilrint(i); ilcint(i); ilwatch(i); 1056893Sfeldman #endif 1066893Sfeldman 1076893Sfeldman addr->il_csr = ILC_OFFLINE|IL_CIE; 1086893Sfeldman DELAY(100000); 1097261Ssam i = addr->il_csr; /* clear CDONE */ 1106893Sfeldman if (cvec > 0 && cvec != 0x200) 1116893Sfeldman cvec -= 4; 1126893Sfeldman return (1); 1136893Sfeldman } 1146893Sfeldman 1156893Sfeldman /* 1166893Sfeldman * Interface exists: make available by filling in network interface 1176893Sfeldman * record. System will initialize the interface when it is ready 1186893Sfeldman * to accept packets. A STATUS command is done to get the ethernet 1196893Sfeldman * address and other interesting data. 1206893Sfeldman */ 1216893Sfeldman ilattach(ui) 1226893Sfeldman struct uba_device *ui; 1236893Sfeldman { 1246893Sfeldman register struct il_softc *is = &il_softc[ui->ui_unit]; 1257220Ssam register struct ifnet *ifp = &is->is_if; 1266893Sfeldman register struct ildevice *addr = (struct ildevice *)ui->ui_addr; 1276893Sfeldman 1287220Ssam ifp->if_unit = ui->ui_unit; 1297220Ssam ifp->if_name = "il"; 1309746Ssam ifp->if_mtu = ETHERMTU; 13119865Skarels ifp->if_flags = IFF_BROADCAST; 1326893Sfeldman 1336893Sfeldman /* 1347261Ssam * Reset the board and map the statistics 1357261Ssam * buffer onto the Unibus. 1366893Sfeldman */ 1377261Ssam addr->il_csr = ILC_RESET; 1387261Ssam while ((addr->il_csr&IL_CDONE) == 0) 1397261Ssam ; 1407261Ssam if (addr->il_csr&IL_STATUS) 1417261Ssam printf("il%d: reset failed, csr=%b\n", ui->ui_unit, 1427261Ssam addr->il_csr, IL_BITS); 1436893Sfeldman 1449179Ssam is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats, 14513056Ssam sizeof (struct il_stats), 0); 1467261Ssam addr->il_bar = is->is_ubaddr & 0xffff; 1477261Ssam addr->il_bcr = sizeof (struct il_stats); 1487261Ssam addr->il_csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT; 1497261Ssam while ((addr->il_csr&IL_CDONE) == 0) 1507261Ssam ; 1517261Ssam if (addr->il_csr&IL_STATUS) 1527261Ssam printf("il%d: status failed, csr=%b\n", ui->ui_unit, 1537261Ssam addr->il_csr, IL_BITS); 1547261Ssam ubarelse(ui->ui_ubanum, &is->is_ubaddr); 15511575Ssam #ifdef notdef 1566893Sfeldman printf("il%d: addr=%x:%x:%x:%x:%x:%x module=%s firmware=%s\n", 1576893Sfeldman ui->ui_unit, 1587261Ssam is->is_stats.ils_addr[0]&0xff, is->is_stats.ils_addr[1]&0xff, 1597261Ssam is->is_stats.ils_addr[2]&0xff, is->is_stats.ils_addr[3]&0xff, 1607261Ssam is->is_stats.ils_addr[4]&0xff, is->is_stats.ils_addr[5]&0xff, 1617261Ssam is->is_stats.ils_module, is->is_stats.ils_firmware); 16211575Ssam #endif 16319865Skarels bcopy((caddr_t)is->is_stats.ils_addr, (caddr_t)is->is_addr, 16419865Skarels sizeof (is->is_addr)); 1657220Ssam ifp->if_init = ilinit; 1667220Ssam ifp->if_output = iloutput; 16713056Ssam ifp->if_ioctl = ilioctl; 1688979Sroot ifp->if_reset = ilreset; 1696893Sfeldman is->is_ifuba.ifu_flags = UBA_CANTWAIT; 1707220Ssam #ifdef notdef 1717220Ssam is->is_ifuba.ifu_flags |= UBA_NEEDBDP; 1727220Ssam #endif 1737220Ssam if_attach(ifp); 1746893Sfeldman } 1756893Sfeldman 1766893Sfeldman /* 1776893Sfeldman * Reset of interface after UNIBUS reset. 1786893Sfeldman * If interface is on specified uba, reset its state. 1796893Sfeldman */ 1806893Sfeldman ilreset(unit, uban) 1816893Sfeldman int unit, uban; 1826893Sfeldman { 1836893Sfeldman register struct uba_device *ui; 1846893Sfeldman 1856893Sfeldman if (unit >= NIL || (ui = ilinfo[unit]) == 0 || ui->ui_alive == 0 || 1866893Sfeldman ui->ui_ubanum != uban) 1876893Sfeldman return; 1886893Sfeldman printf(" il%d", unit); 1896893Sfeldman ilinit(unit); 1906893Sfeldman } 1916893Sfeldman 1926893Sfeldman /* 1936893Sfeldman * Initialization of interface; clear recorded pending 1946893Sfeldman * operations, and reinitialize UNIBUS usage. 1956893Sfeldman */ 1966893Sfeldman ilinit(unit) 1976893Sfeldman int unit; 1986893Sfeldman { 1996893Sfeldman register struct il_softc *is = &il_softc[unit]; 2006893Sfeldman register struct uba_device *ui = ilinfo[unit]; 2016893Sfeldman register struct ildevice *addr; 20213056Ssam register struct ifnet *ifp = &is->is_if; 2037261Ssam int s; 2046893Sfeldman 20519865Skarels /* not yet, if address still unknown */ 20619865Skarels if (ifp->if_addrlist == (struct ifaddr *)0) 20711575Ssam return; 20811575Ssam 20913056Ssam if (ifp->if_flags & IFF_RUNNING) 21019865Skarels return; 2116893Sfeldman if (if_ubainit(&is->is_ifuba, ui->ui_ubanum, 2129746Ssam sizeof (struct il_rheader), (int)btoc(ETHERMTU)) == 0) { 2136893Sfeldman printf("il%d: can't initialize\n", unit); 2146893Sfeldman is->is_if.if_flags &= ~IFF_UP; 2156893Sfeldman return; 2166893Sfeldman } 2179179Ssam is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats, 21813056Ssam sizeof (struct il_stats), 0); 21915071Skarels ifp->if_watchdog = ilwatch; 22015071Skarels is->is_scaninterval = ILWATCHINTERVAL; 22115071Skarels ifp->if_timer = is->is_scaninterval; 2226893Sfeldman addr = (struct ildevice *)ui->ui_addr; 2236893Sfeldman 2246893Sfeldman /* 2259179Ssam * Turn off source address insertion (it's faster this way), 22612488Ssam * and set board online. Former doesn't work if board is 22712488Ssam * already online (happens on ubareset), so we put it offline 22812488Ssam * first. 2299179Ssam */ 2309179Ssam s = splimp(); 23112488Ssam addr->il_csr = ILC_OFFLINE; 2329179Ssam while ((addr->il_csr & IL_CDONE) == 0) 2339179Ssam ; 23412488Ssam addr->il_csr = ILC_CISA; 2359179Ssam while ((addr->il_csr & IL_CDONE) == 0) 2369179Ssam ; 2379179Ssam /* 2386893Sfeldman * Set board online. 2396893Sfeldman * Hang receive buffer and start any pending 2406893Sfeldman * writes by faking a transmit complete. 2416893Sfeldman * Receive bcr is not a muliple of 4 so buffer 2426893Sfeldman * chaining can't happen. 2436893Sfeldman */ 2446893Sfeldman addr->il_csr = ILC_ONLINE; 2457220Ssam while ((addr->il_csr & IL_CDONE) == 0) 2467220Ssam ; 2476893Sfeldman addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 2489746Ssam addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6; 2497261Ssam addr->il_csr = 25013056Ssam ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE; 2517220Ssam while ((addr->il_csr & IL_CDONE) == 0) 2527220Ssam ; 2537261Ssam is->is_flags = ILF_OACTIVE; 25419865Skarels is->is_if.if_flags |= IFF_RUNNING; 2557261Ssam is->is_lastcmd = 0; 2566893Sfeldman ilcint(unit); 2576893Sfeldman splx(s); 2586893Sfeldman } 2596893Sfeldman 2606893Sfeldman /* 2616893Sfeldman * Start output on interface. 2626893Sfeldman * Get another datagram to send off of the interface queue, 2636893Sfeldman * and map it to the interface before starting the output. 2646893Sfeldman */ 2656893Sfeldman ilstart(dev) 2666893Sfeldman dev_t dev; 2676893Sfeldman { 2689179Ssam int unit = ILUNIT(dev), len; 2696893Sfeldman struct uba_device *ui = ilinfo[unit]; 2706893Sfeldman register struct il_softc *is = &il_softc[unit]; 2716893Sfeldman register struct ildevice *addr; 2726893Sfeldman struct mbuf *m; 2737220Ssam short csr; 2746893Sfeldman 2756893Sfeldman IF_DEQUEUE(&is->is_if.if_snd, m); 2767261Ssam addr = (struct ildevice *)ui->ui_addr; 2777261Ssam if (m == 0) { 2787261Ssam if ((is->is_flags & ILF_STATPENDING) == 0) 2797261Ssam return; 2809179Ssam addr->il_bar = is->is_ubaddr & 0xffff; 2817261Ssam addr->il_bcr = sizeof (struct il_stats); 2827261Ssam csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE; 2837261Ssam is->is_flags &= ~ILF_STATPENDING; 2847261Ssam goto startcmd; 2857261Ssam } 2866893Sfeldman len = if_wubaput(&is->is_ifuba, m); 2879179Ssam /* 2889179Ssam * Ensure minimum packet length. 2899179Ssam * This makes the safe assumtion that there are no virtual holes 2909179Ssam * after the data. 2919179Ssam * For security, it might be wise to zero out the added bytes, 2929179Ssam * but we're mainly interested in speed at the moment. 2939179Ssam */ 2949746Ssam if (len - sizeof(struct ether_header) < ETHERMIN) 2959746Ssam len = ETHERMIN + sizeof(struct ether_header); 2966893Sfeldman if (is->is_ifuba.ifu_flags & UBA_NEEDBDP) 2976893Sfeldman UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp); 2986893Sfeldman addr->il_bar = is->is_ifuba.ifu_w.ifrw_info & 0xffff; 2996893Sfeldman addr->il_bcr = len; 3007261Ssam csr = 3017261Ssam ((is->is_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE; 3027261Ssam 3037261Ssam startcmd: 3047261Ssam is->is_lastcmd = csr & IL_CMD; 3057220Ssam addr->il_csr = csr; 3067261Ssam is->is_flags |= ILF_OACTIVE; 3076893Sfeldman } 3086893Sfeldman 3096893Sfeldman /* 3106893Sfeldman * Command done interrupt. 3116893Sfeldman */ 3126893Sfeldman ilcint(unit) 3136893Sfeldman int unit; 3146893Sfeldman { 3156893Sfeldman register struct il_softc *is = &il_softc[unit]; 3167220Ssam struct uba_device *ui = ilinfo[unit]; 3176893Sfeldman register struct ildevice *addr = (struct ildevice *)ui->ui_addr; 3187266Ssam short csr; 3196893Sfeldman 3207261Ssam if ((is->is_flags & ILF_OACTIVE) == 0) { 3217220Ssam printf("il%d: stray xmit interrupt, csr=%b\n", unit, 3227261Ssam addr->il_csr, IL_BITS); 3236893Sfeldman return; 3246893Sfeldman } 3257220Ssam 3267266Ssam csr = addr->il_csr; 3276893Sfeldman /* 3287261Ssam * Hang receive buffer if it couldn't 3297261Ssam * be done earlier (in ilrint). 3306893Sfeldman */ 3317261Ssam if (is->is_flags & ILF_RCVPENDING) { 3326893Sfeldman addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 3339746Ssam addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6; 3347261Ssam addr->il_csr = 3357261Ssam ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE; 3367220Ssam while ((addr->il_csr & IL_CDONE) == 0) 3377220Ssam ; 3387261Ssam is->is_flags &= ~ILF_RCVPENDING; 3396893Sfeldman } 3407261Ssam is->is_flags &= ~ILF_OACTIVE; 3417266Ssam csr &= IL_STATUS; 3427261Ssam switch (is->is_lastcmd) { 3437261Ssam 3447261Ssam case ILC_XMIT: 3457261Ssam is->is_if.if_opackets++; 3467266Ssam if (csr > ILERR_RETRIES) 3477261Ssam is->is_if.if_oerrors++; 3487261Ssam break; 3497261Ssam 3507261Ssam case ILC_STAT: 3517266Ssam if (csr == ILERR_SUCCESS) 3527261Ssam iltotal(is); 3537261Ssam break; 3547261Ssam } 3556893Sfeldman if (is->is_ifuba.ifu_xtofree) { 3566893Sfeldman m_freem(is->is_ifuba.ifu_xtofree); 3576893Sfeldman is->is_ifuba.ifu_xtofree = 0; 3586893Sfeldman } 3597261Ssam ilstart(unit); 3606893Sfeldman } 3616893Sfeldman 3626893Sfeldman /* 3636893Sfeldman * Ethernet interface receiver interrupt. 3646893Sfeldman * If input error just drop packet. 3656893Sfeldman * Otherwise purge input buffered data path and examine 3666893Sfeldman * packet to determine type. If can't determine length 3676893Sfeldman * from type, then have to drop packet. Othewise decapsulate 3686893Sfeldman * packet based on type and pass to type specific higher-level 3696893Sfeldman * input routine. 3706893Sfeldman */ 3716893Sfeldman ilrint(unit) 3726893Sfeldman int unit; 3736893Sfeldman { 3746893Sfeldman register struct il_softc *is = &il_softc[unit]; 3756893Sfeldman struct ildevice *addr = (struct ildevice *)ilinfo[unit]->ui_addr; 3766893Sfeldman register struct il_rheader *il; 3776893Sfeldman struct mbuf *m; 37815787Sleres int len, off, resid, s; 3796893Sfeldman register struct ifqueue *inq; 3806893Sfeldman 3816893Sfeldman is->is_if.if_ipackets++; 3826893Sfeldman if (is->is_ifuba.ifu_flags & UBA_NEEDBDP) 3836893Sfeldman UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp); 3846893Sfeldman il = (struct il_rheader *)(is->is_ifuba.ifu_r.ifrw_addr); 3856893Sfeldman len = il->ilr_length - sizeof(struct il_rheader); 3869746Ssam if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 || 3879746Ssam len > ETHERMTU) { 3886893Sfeldman is->is_if.if_ierrors++; 3896893Sfeldman #ifdef notdef 3906893Sfeldman if (is->is_if.if_ierrors % 100 == 0) 3916893Sfeldman printf("il%d: += 100 input errors\n", unit); 3926893Sfeldman #endif 3936893Sfeldman goto setup; 3946893Sfeldman } 3956893Sfeldman 3966893Sfeldman /* 39719865Skarels * Deal with trailer protocol: if type is trailer type 3986893Sfeldman * get true type from first 16-bit word past data. 3996893Sfeldman * Remember that type was trailer by setting off. 4006893Sfeldman */ 4019746Ssam il->ilr_type = ntohs((u_short)il->ilr_type); 4026893Sfeldman #define ildataaddr(il, off, type) ((type)(((caddr_t)((il)+1)+(off)))) 40319865Skarels if (il->ilr_type >= ETHERTYPE_TRAIL && 40419865Skarels il->ilr_type < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) { 40519865Skarels off = (il->ilr_type - ETHERTYPE_TRAIL) * 512; 4069746Ssam if (off >= ETHERMTU) 4076893Sfeldman goto setup; /* sanity */ 4089746Ssam il->ilr_type = ntohs(*ildataaddr(il, off, u_short *)); 4099746Ssam resid = ntohs(*(ildataaddr(il, off+2, u_short *))); 4106893Sfeldman if (off + resid > len) 4116893Sfeldman goto setup; /* sanity */ 4126893Sfeldman len = off + resid; 4136893Sfeldman } else 4146893Sfeldman off = 0; 4156893Sfeldman if (len == 0) 4166893Sfeldman goto setup; 4176893Sfeldman 4186893Sfeldman /* 4196893Sfeldman * Pull packet off interface. Off is nonzero if packet 4206893Sfeldman * has trailing header; ilget will then force this header 4216893Sfeldman * information to be at the front, but we still have to drop 4226893Sfeldman * the type and length which are at the front of any trailer data. 4236893Sfeldman */ 424*24791Skarels m = if_rubaget(&is->is_ifuba, len, off, &is->is_if); 4256893Sfeldman if (m == 0) 4266893Sfeldman goto setup; 4276893Sfeldman if (off) { 428*24791Skarels struct ifnet *ifp; 429*24791Skarels 430*24791Skarels ifp = *(mtod(m, struct ifnet **)); 4316893Sfeldman m->m_off += 2 * sizeof (u_short); 4326893Sfeldman m->m_len -= 2 * sizeof (u_short); 433*24791Skarels *(mtod(m, struct ifnet **)) = ifp; 4346893Sfeldman } 4356893Sfeldman switch (il->ilr_type) { 4366893Sfeldman 4376893Sfeldman #ifdef INET 43819865Skarels case ETHERTYPE_IP: 4396893Sfeldman schednetisr(NETISR_IP); 4406893Sfeldman inq = &ipintrq; 4416893Sfeldman break; 44211575Ssam 44319865Skarels case ETHERTYPE_ARP: 44411575Ssam arpinput(&is->is_ac, m); 44513988Ssam goto setup; 4466893Sfeldman #endif 44723557Ssklower #ifdef NS 44823557Ssklower case ETHERTYPE_NS: 44923557Ssklower schednetisr(NETISR_NS); 45023557Ssklower inq = &nsintrq; 45123557Ssklower break; 45223557Ssklower 45323557Ssklower #endif 4546893Sfeldman default: 4556893Sfeldman m_freem(m); 4566893Sfeldman goto setup; 4576893Sfeldman } 4586893Sfeldman 45915787Sleres s = splimp(); 4606893Sfeldman if (IF_QFULL(inq)) { 4616893Sfeldman IF_DROP(inq); 4626893Sfeldman m_freem(m); 46315787Sleres } else 46415787Sleres IF_ENQUEUE(inq, m); 46515787Sleres splx(s); 4666893Sfeldman 4676893Sfeldman setup: 4686893Sfeldman /* 4696893Sfeldman * Reset for next packet if possible. 4706893Sfeldman * If waiting for transmit command completion, set flag 4716893Sfeldman * and wait until command completes. 4726893Sfeldman */ 4737261Ssam if (is->is_flags & ILF_OACTIVE) { 4747261Ssam is->is_flags |= ILF_RCVPENDING; 4757220Ssam return; 4767220Ssam } 4777220Ssam addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 4789746Ssam addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6; 4797261Ssam addr->il_csr = 4807261Ssam ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE; 4817220Ssam while ((addr->il_csr & IL_CDONE) == 0) 4827220Ssam ; 4836893Sfeldman } 4846893Sfeldman 4856893Sfeldman /* 4866893Sfeldman * Ethernet output routine. 4876893Sfeldman * Encapsulate a packet of type family for the local net. 4886893Sfeldman * Use trailer local net encapsulation if enough data in first 4896893Sfeldman * packet leaves a multiple of 512 bytes of data in remainder. 4906893Sfeldman */ 4916893Sfeldman iloutput(ifp, m0, dst) 4926893Sfeldman struct ifnet *ifp; 4936893Sfeldman struct mbuf *m0; 4946893Sfeldman struct sockaddr *dst; 4956893Sfeldman { 49611575Ssam int type, s, error; 49719865Skarels u_char edst[6]; 49811575Ssam struct in_addr idst; 4996893Sfeldman register struct il_softc *is = &il_softc[ifp->if_unit]; 5006893Sfeldman register struct mbuf *m = m0; 5019746Ssam register struct ether_header *il; 5029179Ssam register int off; 5036893Sfeldman 5046893Sfeldman switch (dst->sa_family) { 5056893Sfeldman 5066893Sfeldman #ifdef INET 5076893Sfeldman case AF_INET: 50811575Ssam idst = ((struct sockaddr_in *)dst)->sin_addr; 50919865Skarels if (!arpresolve(&is->is_ac, m, &idst, edst)) 51011575Ssam return (0); /* if not yet resolved */ 5116893Sfeldman off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len; 51213056Ssam /* need per host negotiation */ 51313056Ssam if ((ifp->if_flags & IFF_NOTRAILERS) == 0) 5146893Sfeldman if (off > 0 && (off & 0x1ff) == 0 && 5156893Sfeldman m->m_off >= MMINOFF + 2 * sizeof (u_short)) { 51619865Skarels type = ETHERTYPE_TRAIL + (off>>9); 5176893Sfeldman m->m_off -= 2 * sizeof (u_short); 5186893Sfeldman m->m_len += 2 * sizeof (u_short); 51919865Skarels *mtod(m, u_short *) = htons((u_short)ETHERTYPE_IP); 5209746Ssam *(mtod(m, u_short *) + 1) = htons((u_short)m->m_len); 5216893Sfeldman goto gottrailertype; 5226893Sfeldman } 52319865Skarels type = ETHERTYPE_IP; 5246893Sfeldman off = 0; 5256893Sfeldman goto gottype; 5266893Sfeldman #endif 52723557Ssklower #ifdef NS 52823557Ssklower case AF_NS: 52923557Ssklower type = ETHERTYPE_NS; 53023557Ssklower bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), 53123557Ssklower (caddr_t)edst, sizeof (edst)); 53223557Ssklower off = 0; 53323557Ssklower goto gottype; 53423557Ssklower #endif 5356893Sfeldman 53611575Ssam case AF_UNSPEC: 53711575Ssam il = (struct ether_header *)dst->sa_data; 53819865Skarels bcopy((caddr_t)il->ether_dhost, (caddr_t)edst, sizeof (edst)); 53911575Ssam type = il->ether_type; 54011575Ssam goto gottype; 54111575Ssam 5426893Sfeldman default: 5436893Sfeldman printf("il%d: can't handle af%d\n", ifp->if_unit, 5446893Sfeldman dst->sa_family); 5456893Sfeldman error = EAFNOSUPPORT; 5466893Sfeldman goto bad; 5476893Sfeldman } 5486893Sfeldman 5496893Sfeldman gottrailertype: 5506893Sfeldman /* 5516893Sfeldman * Packet to be sent as trailer: move first packet 5526893Sfeldman * (control information) to end of chain. 5536893Sfeldman */ 5546893Sfeldman while (m->m_next) 5556893Sfeldman m = m->m_next; 5566893Sfeldman m->m_next = m0; 5576893Sfeldman m = m0->m_next; 5586893Sfeldman m0->m_next = 0; 5596893Sfeldman m0 = m; 5606893Sfeldman 5616893Sfeldman gottype: 5626893Sfeldman /* 5636893Sfeldman * Add local net header. If no space in first mbuf, 5646893Sfeldman * allocate another. 5656893Sfeldman */ 5666893Sfeldman if (m->m_off > MMAXOFF || 5679746Ssam MMINOFF + sizeof (struct ether_header) > m->m_off) { 5689650Ssam m = m_get(M_DONTWAIT, MT_HEADER); 5696893Sfeldman if (m == 0) { 5706893Sfeldman error = ENOBUFS; 5716893Sfeldman goto bad; 5726893Sfeldman } 5736893Sfeldman m->m_next = m0; 5746893Sfeldman m->m_off = MMINOFF; 5759746Ssam m->m_len = sizeof (struct ether_header); 5766893Sfeldman } else { 5779746Ssam m->m_off -= sizeof (struct ether_header); 5789746Ssam m->m_len += sizeof (struct ether_header); 5796893Sfeldman } 5809746Ssam il = mtod(m, struct ether_header *); 5819746Ssam il->ether_type = htons((u_short)type); 58219865Skarels bcopy((caddr_t)edst, (caddr_t)il->ether_dhost, sizeof (edst)); 58319865Skarels bcopy((caddr_t)is->is_addr, (caddr_t)il->ether_shost, 58419865Skarels sizeof(il->ether_shost)); 5856893Sfeldman 5866893Sfeldman /* 5876893Sfeldman * Queue message on interface, and start output if interface 5886893Sfeldman * not yet active. 5896893Sfeldman */ 5906893Sfeldman s = splimp(); 5916893Sfeldman if (IF_QFULL(&ifp->if_snd)) { 5926893Sfeldman IF_DROP(&ifp->if_snd); 5937220Ssam splx(s); 5947220Ssam m_freem(m); 5957220Ssam return (ENOBUFS); 5966893Sfeldman } 5976893Sfeldman IF_ENQUEUE(&ifp->if_snd, m); 5987261Ssam if ((is->is_flags & ILF_OACTIVE) == 0) 5996893Sfeldman ilstart(ifp->if_unit); 6006893Sfeldman splx(s); 6016893Sfeldman return (0); 6027220Ssam 6036893Sfeldman bad: 6046893Sfeldman m_freem(m0); 6057220Ssam return (error); 6066893Sfeldman } 6077261Ssam 6087261Ssam /* 6097261Ssam * Watchdog routine, request statistics from board. 6107261Ssam */ 6117261Ssam ilwatch(unit) 6127261Ssam int unit; 6137261Ssam { 6147261Ssam register struct il_softc *is = &il_softc[unit]; 6157261Ssam register struct ifnet *ifp = &is->is_if; 6167261Ssam int s; 6177261Ssam 6187261Ssam if (is->is_flags & ILF_STATPENDING) { 6197261Ssam ifp->if_timer = is->is_scaninterval; 6207261Ssam return; 6217261Ssam } 6227261Ssam s = splimp(); 6237261Ssam is->is_flags |= ILF_STATPENDING; 6247261Ssam if ((is->is_flags & ILF_OACTIVE) == 0) 6257261Ssam ilstart(ifp->if_unit); 6267261Ssam splx(s); 6277261Ssam ifp->if_timer = is->is_scaninterval; 6287261Ssam } 6297261Ssam 6307261Ssam /* 6317261Ssam * Total up the on-board statistics. 6327261Ssam */ 6337261Ssam iltotal(is) 6347261Ssam register struct il_softc *is; 6357261Ssam { 6367261Ssam register u_short *interval, *sum, *end; 6377261Ssam 6387261Ssam interval = &is->is_stats.ils_frames; 6397261Ssam sum = &is->is_sum.ils_frames; 6407261Ssam end = is->is_sum.ils_fill2; 6417261Ssam while (sum < end) 6427261Ssam *sum++ += *interval++; 6437261Ssam is->is_if.if_collisions = is->is_sum.ils_collis; 6447261Ssam } 64513056Ssam 64613056Ssam /* 64713056Ssam * Process an ioctl request. 64813056Ssam */ 64913056Ssam ilioctl(ifp, cmd, data) 65013056Ssam register struct ifnet *ifp; 65113056Ssam int cmd; 65213056Ssam caddr_t data; 65313056Ssam { 65419865Skarels register struct ifaddr *ifa = (struct ifaddr *)data; 65513056Ssam int s = splimp(), error = 0; 65613056Ssam 65713056Ssam switch (cmd) { 65813056Ssam 65913056Ssam case SIOCSIFADDR: 66019865Skarels ifp->if_flags |= IFF_UP; 66113056Ssam ilinit(ifp->if_unit); 66219865Skarels 66319865Skarels switch (ifa->ifa_addr.sa_family) { 66423557Ssklower #ifdef INET 66519865Skarels case AF_INET: 66619865Skarels ((struct arpcom *)ifp)->ac_ipaddr = 66719865Skarels IA_SIN(ifa)->sin_addr; 66819865Skarels arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr); 66919865Skarels break; 67023557Ssklower #endif 67123557Ssklower #ifdef NS 67223557Ssklower case AF_NS: 67323557Ssklower IA_SNS(ifa)->sns_addr.x_host = 67423557Ssklower * (union ns_host *) 67523557Ssklower (il_softc[ifp->if_unit].is_addr); 67623557Ssklower break; 67723557Ssklower #endif 67819865Skarels } 67913056Ssam break; 68013056Ssam 68113056Ssam default: 68213056Ssam error = EINVAL; 68313056Ssam } 68413056Ssam splx(s); 68513056Ssam return (error); 68613056Ssam } 687