1*13054Ssam /* if_en.c 4.79 83/06/12 */ 24686Swnj 34686Swnj #include "en.h" 45105Swnj 54686Swnj /* 65105Swnj * Xerox prototype (3 Mb) Ethernet interface driver. 74686Swnj */ 89796Ssam #include "../machine/pte.h" 94686Swnj 104686Swnj #include "../h/param.h" 114686Swnj #include "../h/systm.h" 124686Swnj #include "../h/mbuf.h" 134686Swnj #include "../h/buf.h" 145083Swnj #include "../h/protosw.h" 155083Swnj #include "../h/socket.h" 165083Swnj #include "../h/vmmac.h" 17*13054Ssam #include "../h/errno.h" 18*13054Ssam #include "../h/ioctl.h" 198462Sroot 208462Sroot #include "../net/if.h" 218462Sroot #include "../net/netisr.h" 228462Sroot #include "../net/route.h" 238418Swnj #include "../netinet/in.h" 248418Swnj #include "../netinet/in_systm.h" 258418Swnj #include "../netinet/ip.h" 268418Swnj #include "../netinet/ip_var.h" 278418Swnj #include "../netpup/pup.h" 284686Swnj 298462Sroot #include "../vax/cpu.h" 308462Sroot #include "../vax/mtpr.h" 318462Sroot #include "../vaxif/if_en.h" 328462Sroot #include "../vaxif/if_enreg.h" 338462Sroot #include "../vaxif/if_uba.h" 348462Sroot #include "../vaxuba/ubareg.h" 358462Sroot #include "../vaxuba/ubavar.h" 368462Sroot 375213Swnj #define ENMTU (1024+512) 386925Swnj #define ENMRU (1024+512+16) /* 16 is enough to receive trailer */ 395083Swnj 404686Swnj int enprobe(), enattach(), enrint(), enxint(), encollide(); 414686Swnj struct uba_device *eninfo[NEN]; 424686Swnj u_short enstd[] = { 0 }; 434686Swnj struct uba_driver endriver = 445171Swnj { enprobe, 0, enattach, 0, enstd, "en", eninfo }; 454686Swnj #define ENUNIT(x) minor(x) 464686Swnj 47*13054Ssam int eninit(),enoutput(),enreset(),enioctl(); 485105Swnj 495105Swnj /* 505105Swnj * Ethernet software status per interface. 515105Swnj * 525105Swnj * Each interface is referenced by a network interface structure, 535105Swnj * es_if, which the routing code uses to locate the interface. 545105Swnj * This structure contains the output queue for the interface, its address, ... 555105Swnj * We also have, for each interface, a UBA interface structure, which 565105Swnj * contains information about the UNIBUS resources held by the interface: 575105Swnj * map registers, buffered data paths, etc. Information is cached in this 585105Swnj * structure for use by the if_uba.c routines in running the interface 595105Swnj * efficiently. 605105Swnj */ 615083Swnj struct en_softc { 625105Swnj struct ifnet es_if; /* network-visible interface */ 635105Swnj struct ifuba es_ifuba; /* UNIBUS resources */ 645105Swnj short es_delay; /* current output delay */ 655105Swnj short es_mask; /* mask for current output delay */ 666471Sroot short es_lastx; /* host last transmitted to */ 675105Swnj short es_oactive; /* is output active? */ 685105Swnj short es_olen; /* length of last output */ 695083Swnj } en_softc[NEN]; 704686Swnj 715105Swnj /* 725105Swnj * Do output DMA to determine interface presence and 735105Swnj * interrupt vector. DMA is too short to disturb other hosts. 745105Swnj */ 754686Swnj enprobe(reg) 764686Swnj caddr_t reg; 774686Swnj { 785171Swnj register int br, cvec; /* r11, r10 value-result */ 794686Swnj register struct endevice *addr = (struct endevice *)reg; 804686Swnj 814686Swnj #ifdef lint 824686Swnj br = 0; cvec = br; br = cvec; 834922Swnj enrint(0); enxint(0); encollide(0); 844686Swnj #endif 854686Swnj addr->en_istat = 0; 864686Swnj addr->en_owc = -1; 874686Swnj addr->en_oba = 0; 884771Swnj addr->en_ostat = EN_IEN|EN_GO; 894686Swnj DELAY(100000); 904686Swnj addr->en_ostat = 0; 916575Ssam #ifdef ECHACK 926575Ssam br = 0x16; 936575Ssam #endif 944686Swnj return (1); 954686Swnj } 964686Swnj 975105Swnj /* 985105Swnj * Interface exists: make available by filling in network interface 995105Swnj * record. System will initialize the interface when it is ready 1005105Swnj * to accept packets. 1015105Swnj */ 1024686Swnj enattach(ui) 1034686Swnj struct uba_device *ui; 1044686Swnj { 1055105Swnj register struct en_softc *es = &en_softc[ui->ui_unit]; 1064688Swnj 1075105Swnj es->es_if.if_unit = ui->ui_unit; 1085171Swnj es->es_if.if_name = "en"; 1095105Swnj es->es_if.if_mtu = ENMTU; 1105171Swnj es->es_if.if_init = eninit; 1115105Swnj es->es_if.if_output = enoutput; 112*13054Ssam es->es_if.if_ioctl = enioctl; 1138978Sroot es->es_if.if_reset = enreset; 1146554Ssam es->es_ifuba.ifu_flags = UBA_NEEDBDP | UBA_NEED16 | UBA_CANTWAIT; 1159271Ssam #if defined(VAX750) 1169271Ssam /* don't chew up 750 bdp's */ 1179271Ssam if (cpu == VAX_750 && ui->ui_unit > 0) 1189271Ssam es->es_ifuba.ifu_flags &= ~UBA_NEEDBDP; 1199271Ssam #endif 1205160Swnj if_attach(&es->es_if); 1214686Swnj } 1224686Swnj 1235105Swnj /* 1245105Swnj * Reset of interface after UNIBUS reset. 1255105Swnj * If interface is on specified uba, reset its state. 1265105Swnj */ 1275105Swnj enreset(unit, uban) 1285105Swnj int unit, uban; 1295105Swnj { 1305105Swnj register struct uba_device *ui; 1315105Swnj 1325171Swnj if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0 || 1335171Swnj ui->ui_ubanum != uban) 1345105Swnj return; 1355171Swnj printf(" en%d", unit); 1365105Swnj eninit(unit); 1375105Swnj } 1385105Swnj 1395105Swnj /* 1405105Swnj * Initialization of interface; clear recorded pending 1415105Swnj * operations, and reinitialize UNIBUS usage. 1425105Swnj */ 1434688Swnj eninit(unit) 1444686Swnj int unit; 1455083Swnj { 1465171Swnj register struct en_softc *es = &en_softc[unit]; 1475171Swnj register struct uba_device *ui = eninfo[unit]; 1484686Swnj register struct endevice *addr; 14912349Ssam struct sockaddr_in *sin = (struct sockaddr_in *)&es->es_if.if_addr; 150*13054Ssam int s; 1514686Swnj 152*13054Ssam if (in_netof(sin->sin_addr) == 0) 15312349Ssam return; 1545105Swnj if (if_ubainit(&es->es_ifuba, ui->ui_ubanum, 1556925Swnj sizeof (struct en_header), (int)btoc(ENMRU)) == 0) { 1565171Swnj printf("en%d: can't initialize\n", unit); 1576335Ssam es->es_if.if_flags &= ~IFF_UP; 1585083Swnj return; 1594686Swnj } 1604686Swnj addr = (struct endevice *)ui->ui_addr; 1615083Swnj addr->en_istat = addr->en_ostat = 0; 1624686Swnj 1635105Swnj /* 1645171Swnj * Hang a receive and start any 1655171Swnj * pending writes by faking a transmit complete. 1665105Swnj */ 1675105Swnj s = splimp(); 1685171Swnj addr->en_iba = es->es_ifuba.ifu_r.ifrw_info; 1696925Swnj addr->en_iwc = -(sizeof (struct en_header) + ENMRU) >> 1; 1705171Swnj addr->en_istat = EN_IEN|EN_GO; 1715171Swnj es->es_oactive = 1; 172*13054Ssam es->es_if.if_flags |= IFF_UP|IFF_RUNNING; 1735105Swnj enxint(unit); 1745105Swnj splx(s); 1757151Swnj if_rtinit(&es->es_if, RTF_UP); 1764686Swnj } 1774686Swnj 1786471Sroot int enalldelay = 0; 1796951Swnj int enlastdel = 50; 1806471Sroot int enlastmask = (~0) << 5; 1815083Swnj 1825105Swnj /* 1835105Swnj * Start or restart output on interface. 1845105Swnj * If interface is already active, then this is a retransmit 1855105Swnj * after a collision, and just restuff registers and delay. 1865105Swnj * If interface is not already active, get another datagram 1875105Swnj * to send off of the interface queue, and map it to the interface 1885105Swnj * before starting the output. 1895105Swnj */ 1904688Swnj enstart(dev) 1914686Swnj dev_t dev; 1924686Swnj { 1935171Swnj int unit = ENUNIT(dev); 1945171Swnj struct uba_device *ui = eninfo[unit]; 1955171Swnj register struct en_softc *es = &en_softc[unit]; 1965083Swnj register struct endevice *addr; 1975083Swnj struct mbuf *m; 1985083Swnj int dest; 1994686Swnj 2005083Swnj if (es->es_oactive) 2015083Swnj goto restart; 2025105Swnj 2035105Swnj /* 2045105Swnj * Not already active: dequeue another request 2055105Swnj * and map it to the UNIBUS. If no more requests, 2065105Swnj * just return. 2075105Swnj */ 2085105Swnj IF_DEQUEUE(&es->es_if.if_snd, m); 2095083Swnj if (m == 0) { 2105083Swnj es->es_oactive = 0; 2114686Swnj return; 2124686Swnj } 2135213Swnj dest = mtod(m, struct en_header *)->en_dhost; 2145105Swnj es->es_olen = if_wubaput(&es->es_ifuba, m); 2155105Swnj 2165105Swnj /* 2175105Swnj * Ethernet cannot take back-to-back packets (no 2186471Sroot * buffering in interface. To help avoid overrunning 2196471Sroot * receivers, enforce a small delay (about 1ms) in interface: 2206471Sroot * * between all packets when enalldelay 2216471Sroot * * whenever last packet was broadcast 2226471Sroot * * whenever this packet is to same host as last packet 2235105Swnj */ 2246471Sroot if (enalldelay || es->es_lastx == 0 || es->es_lastx == dest) { 2255083Swnj es->es_delay = enlastdel; 2266471Sroot es->es_mask = enlastmask; 2276471Sroot } 2286471Sroot es->es_lastx = dest; 2295105Swnj 2305083Swnj restart: 2315105Swnj /* 2325105Swnj * Have request mapped to UNIBUS for transmission. 2335105Swnj * Purge any stale data from this BDP, and start the otput. 2345105Swnj */ 2356335Ssam if (es->es_ifuba.ifu_flags & UBA_NEEDBDP) 2366335Ssam UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_w.ifrw_bdp); 2374686Swnj addr = (struct endevice *)ui->ui_addr; 2385160Swnj addr->en_oba = (int)es->es_ifuba.ifu_w.ifrw_info; 2395083Swnj addr->en_odelay = es->es_delay; 2405083Swnj addr->en_owc = -((es->es_olen + 1) >> 1); 2414771Swnj addr->en_ostat = EN_IEN|EN_GO; 2425083Swnj es->es_oactive = 1; 2434686Swnj } 2444686Swnj 2455105Swnj /* 2465105Swnj * Ethernet interface transmitter interrupt. 2475105Swnj * Start another output if more data to send. 2485105Swnj */ 2494686Swnj enxint(unit) 2504686Swnj int unit; 2514686Swnj { 2525171Swnj register struct uba_device *ui = eninfo[unit]; 2535171Swnj register struct en_softc *es = &en_softc[unit]; 2546242Sroot register struct endevice *addr = (struct endevice *)ui->ui_addr; 2554686Swnj 2565083Swnj if (es->es_oactive == 0) 2575083Swnj return; 2586242Sroot if (es->es_mask && (addr->en_ostat&EN_OERROR)) { 2596242Sroot es->es_if.if_oerrors++; 2606242Sroot endocoll(unit); 2616242Sroot return; 2626242Sroot } 2635171Swnj es->es_if.if_opackets++; 2645083Swnj es->es_oactive = 0; 2655083Swnj es->es_delay = 0; 2665083Swnj es->es_mask = ~0; 2675696Sroot if (es->es_ifuba.ifu_xtofree) { 2685696Sroot m_freem(es->es_ifuba.ifu_xtofree); 2695696Sroot es->es_ifuba.ifu_xtofree = 0; 2705696Sroot } 2715105Swnj if (es->es_if.if_snd.ifq_head == 0) { 2726471Sroot es->es_lastx = 256; /* putatively illegal */ 2734686Swnj return; 2744686Swnj } 2755083Swnj enstart(unit); 2764686Swnj } 2774686Swnj 2785105Swnj /* 2795105Swnj * Collision on ethernet interface. Do exponential 2805105Swnj * backoff, and retransmit. If have backed off all 2816335Ssam * the way print warning diagnostic, and drop packet. 2825105Swnj */ 2834686Swnj encollide(unit) 2844686Swnj int unit; 2854686Swnj { 2866242Sroot struct en_softc *es = &en_softc[unit]; 2874686Swnj 2885105Swnj es->es_if.if_collisions++; 2895083Swnj if (es->es_oactive == 0) 2904686Swnj return; 2916242Sroot endocoll(unit); 2926242Sroot } 2936242Sroot 2946242Sroot endocoll(unit) 2956242Sroot int unit; 2966242Sroot { 2976242Sroot register struct en_softc *es = &en_softc[unit]; 2986242Sroot 2995171Swnj /* 3005171Swnj * Es_mask is a 16 bit number with n low zero bits, with 3015171Swnj * n the number of backoffs. When es_mask is 0 we have 3025171Swnj * backed off 16 times, and give up. 3035171Swnj */ 3045083Swnj if (es->es_mask == 0) { 3055213Swnj printf("en%d: send error\n", unit); 3065083Swnj enxint(unit); 3075171Swnj return; 3084686Swnj } 3095171Swnj /* 3105171Swnj * Another backoff. Restart with delay based on n low bits 3115171Swnj * of the interval timer. 3125171Swnj */ 3135171Swnj es->es_mask <<= 1; 3145171Swnj es->es_delay = mfpr(ICR) &~ es->es_mask; 3155171Swnj enstart(unit); 3164686Swnj } 3174686Swnj 3186027Ssam struct sockaddr_pup pupsrc = { AF_PUP }; 3196027Ssam struct sockaddr_pup pupdst = { AF_PUP }; 3206027Ssam struct sockproto pupproto = { PF_PUP }; 3215105Swnj /* 3225105Swnj * Ethernet interface receiver interrupt. 3235105Swnj * If input error just drop packet. 3245105Swnj * Otherwise purge input buffered data path and examine 3255105Swnj * packet to determine type. If can't determine length 3265105Swnj * from type, then have to drop packet. Othewise decapsulate 3275105Swnj * packet based on type and pass to type specific higher-level 3285105Swnj * input routine. 3295105Swnj */ 3304686Swnj enrint(unit) 3314686Swnj int unit; 3324686Swnj { 3335171Swnj register struct en_softc *es = &en_softc[unit]; 3345171Swnj struct endevice *addr = (struct endevice *)eninfo[unit]->ui_addr; 3355171Swnj register struct en_header *en; 3365083Swnj struct mbuf *m; 3378603Sroot int len; short resid; 3385171Swnj register struct ifqueue *inq; 3395083Swnj int off; 3404686Swnj 3415171Swnj es->es_if.if_ipackets++; 3425105Swnj 3435105Swnj /* 3445171Swnj * Purge BDP; drop if input error indicated. 3455105Swnj */ 3466335Ssam if (es->es_ifuba.ifu_flags & UBA_NEEDBDP) 3476335Ssam UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp); 3484771Swnj if (addr->en_istat&EN_IERROR) { 3495105Swnj es->es_if.if_ierrors++; 3505083Swnj goto setup; 3514686Swnj } 3525105Swnj 3535105Swnj /* 3546471Sroot * Calculate input data length. 3555105Swnj * Get pointer to ethernet header (in input buffer). 3565105Swnj * Deal with trailer protocol: if type is PUP trailer 3575105Swnj * get true type from first 16-bit word past data. 3585105Swnj * Remember that type was trailer by setting off. 3595105Swnj */ 3606471Sroot resid = addr->en_iwc; 3616471Sroot if (resid) 3626471Sroot resid |= 0176000; 3636925Swnj len = (((sizeof (struct en_header) + ENMRU) >> 1) + resid) << 1; 3646471Sroot len -= sizeof (struct en_header); 3656925Swnj if (len > ENMRU) 3666471Sroot goto setup; /* sanity */ 3675105Swnj en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr); 36812352Ssam en->en_type = ntohs(en->en_type); 3695083Swnj #define endataaddr(en, off, type) ((type)(((caddr_t)((en)+1)+(off)))) 37012352Ssam if (en->en_type >= ENTYPE_TRAIL && 37112352Ssam en->en_type < ENTYPE_TRAIL+ENTYPE_NTRAILER) { 37212352Ssam off = (en->en_type - ENTYPE_TRAIL) * 512; 3736925Swnj if (off > ENMTU) 3745171Swnj goto setup; /* sanity */ 37512352Ssam en->en_type = ntohs(*endataaddr(en, off, u_short *)); 37612352Ssam resid = ntohs(*(endataaddr(en, off+2, u_short *))); 3776471Sroot if (off + resid > len) 3786471Sroot goto setup; /* sanity */ 3796471Sroot len = off + resid; 3805083Swnj } else 3815083Swnj off = 0; 3825083Swnj if (len == 0) 3835083Swnj goto setup; 3845105Swnj /* 3855105Swnj * Pull packet off interface. Off is nonzero if packet 3865105Swnj * has trailing header; if_rubaget will then force this header 3875105Swnj * information to be at the front, but we still have to drop 3886471Sroot * the type and length which are at the front of any trailer data. 3895105Swnj */ 3905105Swnj m = if_rubaget(&es->es_ifuba, len, off); 3915213Swnj if (m == 0) 3925213Swnj goto setup; 3935105Swnj if (off) { 3946471Sroot m->m_off += 2 * sizeof (u_short); 3956471Sroot m->m_len -= 2 * sizeof (u_short); 3965105Swnj } 3976027Ssam switch (en->en_type) { 3986027Ssam 3996027Ssam #ifdef INET 40012352Ssam case ENTYPE_IP: 4016260Swnj schednetisr(NETISR_IP); 4026027Ssam inq = &ipintrq; 4036027Ssam break; 4046027Ssam #endif 4056335Ssam #ifdef PUP 40612352Ssam case ENTYPE_PUP: { 4076027Ssam struct pup_header *pup = mtod(m, struct pup_header *); 4086027Ssam 4096027Ssam pupproto.sp_protocol = pup->pup_type; 41012833Ssam bcopy((caddr_t)pup->pup_dnet, (caddr_t)pupdst.spup_net, 41112833Ssam sizeof (struct pupport)); 41212833Ssam bcopy((caddr_t)pup->pup_snet, (caddr_t)pupsrc.spup_net, 41312833Ssam sizeof (struct pupport)); 4146526Ssam raw_input(m, &pupproto, (struct sockaddr *)&pupsrc, 4156526Ssam (struct sockaddr *)&pupdst); 4166027Ssam goto setup; 4176027Ssam } 4186335Ssam #endif 4196476Swnj default: 4206476Swnj m_freem(m); 4216476Swnj goto setup; 4226335Ssam } 4236335Ssam 4246207Swnj if (IF_QFULL(inq)) { 4256207Swnj IF_DROP(inq); 4266335Ssam m_freem(m); 4276207Swnj } else 4286207Swnj IF_ENQUEUE(inq, m); 4295105Swnj 4304688Swnj setup: 4315105Swnj /* 4325105Swnj * Reset for next packet. 4335105Swnj */ 4345105Swnj addr->en_iba = es->es_ifuba.ifu_r.ifrw_info; 4356925Swnj addr->en_iwc = -(sizeof (struct en_header) + ENMRU) >> 1; 4364771Swnj addr->en_istat = EN_IEN|EN_GO; 4374688Swnj } 4384686Swnj 4395083Swnj /* 4405083Swnj * Ethernet output routine. 4415083Swnj * Encapsulate a packet of type family for the local net. 4425105Swnj * Use trailer local net encapsulation if enough data in first 4435105Swnj * packet leaves a multiple of 512 bytes of data in remainder. 4445083Swnj */ 4456335Ssam enoutput(ifp, m0, dst) 4465083Swnj struct ifnet *ifp; 4475083Swnj struct mbuf *m0; 4486335Ssam struct sockaddr *dst; 4494686Swnj { 4506503Ssam int type, dest, s, error; 4515105Swnj register struct mbuf *m = m0; 4525083Swnj register struct en_header *en; 4536335Ssam register int off; 4544686Swnj 4556335Ssam switch (dst->sa_family) { 4565083Swnj 4575083Swnj #ifdef INET 4586335Ssam case AF_INET: 4596484Swnj dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr; 4609178Ssam if (in_lnaof(*((struct in_addr *)&dest)) >= 0x100) { 4616503Ssam error = EPERM; /* ??? */ 4626486Swnj goto bad; 4636503Ssam } 4646484Swnj dest = (dest >> 24) & 0xff; 4656335Ssam off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len; 466*13054Ssam /* need per host negotiation */ 467*13054Ssam if ((ifp->if_flags & IFF_NOTRAILERS) == 0) 4686335Ssam if (off > 0 && (off & 0x1ff) == 0 && 4696471Sroot m->m_off >= MMINOFF + 2 * sizeof (u_short)) { 47012352Ssam type = ENTYPE_TRAIL + (off>>9); 4716471Sroot m->m_off -= 2 * sizeof (u_short); 4726471Sroot m->m_len += 2 * sizeof (u_short); 47312352Ssam *mtod(m, u_short *) = htons((u_short)ENTYPE_IP); 47412352Ssam *(mtod(m, u_short *) + 1) = ntohs((u_short)m->m_len); 4755105Swnj goto gottrailertype; 4765083Swnj } 47712352Ssam type = ENTYPE_IP; 4785105Swnj off = 0; 4795105Swnj goto gottype; 4805083Swnj #endif 4816027Ssam #ifdef PUP 4826335Ssam case AF_PUP: 48312833Ssam dest = ((struct sockaddr_pup *)dst)->spup_host; 48412352Ssam type = ENTYPE_PUP; 4856027Ssam off = 0; 4866027Ssam goto gottype; 4876027Ssam #endif 4886027Ssam 4895083Swnj default: 4906335Ssam printf("en%d: can't handle af%d\n", ifp->if_unit, 4916335Ssam dst->sa_family); 4926503Ssam error = EAFNOSUPPORT; 4936503Ssam goto bad; 4944686Swnj } 4955105Swnj 4965171Swnj gottrailertype: 4975105Swnj /* 4985105Swnj * Packet to be sent as trailer: move first packet 4995105Swnj * (control information) to end of chain. 5005105Swnj */ 5015105Swnj while (m->m_next) 5025105Swnj m = m->m_next; 5035105Swnj m->m_next = m0; 5045105Swnj m = m0->m_next; 5055105Swnj m0->m_next = 0; 5065171Swnj m0 = m; 5075105Swnj 5085171Swnj gottype: 5095105Swnj /* 5105105Swnj * Add local net header. If no space in first mbuf, 5115105Swnj * allocate another. 5125105Swnj */ 5135213Swnj if (m->m_off > MMAXOFF || 5145213Swnj MMINOFF + sizeof (struct en_header) > m->m_off) { 5159649Ssam m = m_get(M_DONTWAIT, MT_HEADER); 5165083Swnj if (m == 0) { 5176503Ssam error = ENOBUFS; 5186503Ssam goto bad; 5195083Swnj } 5205083Swnj m->m_next = m0; 5215083Swnj m->m_off = MMINOFF; 5225083Swnj m->m_len = sizeof (struct en_header); 5235083Swnj } else { 5245083Swnj m->m_off -= sizeof (struct en_header); 5255083Swnj m->m_len += sizeof (struct en_header); 5265083Swnj } 5275083Swnj en = mtod(m, struct en_header *); 5285083Swnj en->en_shost = ifp->if_host[0]; 5295083Swnj en->en_dhost = dest; 53012352Ssam en->en_type = htons((u_short)type); 5315105Swnj 5325105Swnj /* 5335105Swnj * Queue message on interface, and start output if interface 5345105Swnj * not yet active. 5355105Swnj */ 5365083Swnj s = splimp(); 5376207Swnj if (IF_QFULL(&ifp->if_snd)) { 5386207Swnj IF_DROP(&ifp->if_snd); 5396503Ssam error = ENOBUFS; 5406503Ssam goto qfull; 5416207Swnj } 5425083Swnj IF_ENQUEUE(&ifp->if_snd, m); 5435083Swnj if (en_softc[ifp->if_unit].es_oactive == 0) 5445083Swnj enstart(ifp->if_unit); 5455275Swnj splx(s); 5466503Ssam return (0); 5476503Ssam qfull: 5486503Ssam m0 = m; 5496503Ssam splx(s); 5506484Swnj bad: 5516503Ssam m_freem(m0); 5526503Ssam return (error); 5534686Swnj } 554*13054Ssam 555*13054Ssam /* 556*13054Ssam * Process an ioctl request. 557*13054Ssam */ 558*13054Ssam enioctl(ifp, cmd, data) 559*13054Ssam register struct ifnet *ifp; 560*13054Ssam int cmd; 561*13054Ssam caddr_t data; 562*13054Ssam { 563*13054Ssam struct ifreq *ifr = (struct ifreq *)data; 564*13054Ssam int s = splimp(), error = 0; 565*13054Ssam 566*13054Ssam switch (cmd) { 567*13054Ssam 568*13054Ssam case SIOCSIFADDR: 569*13054Ssam if (ifp->if_flags & IFF_RUNNING) 570*13054Ssam if_rtinit(ifp, -1); /* delete previous route */ 571*13054Ssam ensetaddr(ifp, (struct sockaddr_in *)&ifr->ifr_addr); 572*13054Ssam if (ifp->if_flags & IFF_RUNNING) 573*13054Ssam if_rtinit(ifp, RTF_UP); 574*13054Ssam else 575*13054Ssam eninit(ifp->if_unit); 576*13054Ssam break; 577*13054Ssam 578*13054Ssam default: 579*13054Ssam error = EINVAL; 580*13054Ssam } 581*13054Ssam splx(s); 582*13054Ssam return (error); 583*13054Ssam } 584*13054Ssam 585*13054Ssam ensetaddr(ifp, sin) 586*13054Ssam register struct ifnet *ifp; 587*13054Ssam register struct sockaddr_in *sin; 588*13054Ssam { 589*13054Ssam struct endevice *enaddr; 590*13054Ssam 591*13054Ssam ifp->if_net = in_netof(sin->sin_addr); 592*13054Ssam enaddr = (struct endevice *)eninfo[ifp->if_unit]->ui_addr; 593*13054Ssam ifp->if_host[0] = (~enaddr->en_addr) & 0xff; 594*13054Ssam sin = (struct sockaddr_in *)&ifp->if_addr; 595*13054Ssam sin->sin_family = AF_INET; 596*13054Ssam sin->sin_addr = if_makeaddr(ifp->if_net, ifp->if_host[0]); 597*13054Ssam sin = (struct sockaddr_in *)&ifp->if_broadaddr; 598*13054Ssam sin->sin_family = AF_INET; 599*13054Ssam sin->sin_addr = if_makeaddr(ifp->if_net, INADDR_ANY); 600*13054Ssam ifp->if_flags |= IFF_BROADCAST; 601*13054Ssam } 602