1*6893Sfeldman /* if_il.c 4.1 82/05/21 */ 2*6893Sfeldman 3*6893Sfeldman #include "il.h" 4*6893Sfeldman #include "imp.h" 5*6893Sfeldman #include "loop.h" 6*6893Sfeldman 7*6893Sfeldman /* 8*6893Sfeldman * Interlan Ethernet Communications Controller interface 9*6893Sfeldman */ 10*6893Sfeldman 11*6893Sfeldman #include "../h/param.h" 12*6893Sfeldman #include "../h/systm.h" 13*6893Sfeldman #include "../h/mbuf.h" 14*6893Sfeldman #include "../h/pte.h" 15*6893Sfeldman #include "../h/buf.h" 16*6893Sfeldman #include "../h/protosw.h" 17*6893Sfeldman #include "../h/socket.h" 18*6893Sfeldman #include "../h/ubareg.h" 19*6893Sfeldman #include "../h/ubavar.h" 20*6893Sfeldman #include "../h/ilreg.h" 21*6893Sfeldman #include "../h/cpu.h" 22*6893Sfeldman #include "../h/mtpr.h" 23*6893Sfeldman #include "../h/vmmac.h" 24*6893Sfeldman #include "../net/in.h" 25*6893Sfeldman #include "../net/in_systm.h" 26*6893Sfeldman #include "../net/if.h" 27*6893Sfeldman #include "../net/if_il.h" 28*6893Sfeldman #include "../net/if_uba.h" 29*6893Sfeldman #include "../net/ip.h" 30*6893Sfeldman #include "../net/ip_var.h" 31*6893Sfeldman #include "../net/pup.h" 32*6893Sfeldman #include "../net/route.h" 33*6893Sfeldman #include <errno.h> 34*6893Sfeldman 35*6893Sfeldman #define ILMTU 1500 36*6893Sfeldman 37*6893Sfeldman int ilprobe(), ilattach(), ilrint(), ilcint(); 38*6893Sfeldman struct uba_device *ilinfo[NIL]; 39*6893Sfeldman u_short ilstd[] = { 0 }; 40*6893Sfeldman struct uba_driver ildriver = 41*6893Sfeldman { ilprobe, 0, ilattach, 0, ilstd, "il", ilinfo }; 42*6893Sfeldman u_char il_ectop[3] = { 0x02, 0x60, 0x8c }; 43*6893Sfeldman #define ILUNIT(x) minor(x) 44*6893Sfeldman 45*6893Sfeldman int ilinit(),iloutput(),ilreset(); 46*6893Sfeldman 47*6893Sfeldman /* 48*6893Sfeldman * Ethernet software status per interface. 49*6893Sfeldman * 50*6893Sfeldman * Each interface is referenced by a network interface structure, 51*6893Sfeldman * is_if, which the routing code uses to locate the interface. 52*6893Sfeldman * This structure contains the output queue for the interface, its address, ... 53*6893Sfeldman * We also have, for each interface, a UBA interface structure, which 54*6893Sfeldman * contains information about the UNIBUS resources held by the interface: 55*6893Sfeldman * map registers, buffered data paths, etc. Information is cached in this 56*6893Sfeldman * structure for use by the if_uba.c routines in running the interface 57*6893Sfeldman * efficiently. 58*6893Sfeldman */ 59*6893Sfeldman struct il_softc { 60*6893Sfeldman struct ifnet is_if; /* network-visible interface */ 61*6893Sfeldman struct ifuba is_ifuba; /* UNIBUS resources */ 62*6893Sfeldman short is_oactive; /* is output active? */ 63*6893Sfeldman short is_startrcv; /* hang receive next chance */ 64*6893Sfeldman u_char is_enaddr[6]; /* board's ethernet address */ 65*6893Sfeldman } il_softc[NIL]; 66*6893Sfeldman 67*6893Sfeldman /* 68*6893Sfeldman * Do an OFFLINE command. This will cause an interrupt for the 69*6893Sfeldman * autoconfigure stuff. 70*6893Sfeldman */ 71*6893Sfeldman ilprobe(reg) 72*6893Sfeldman caddr_t reg; 73*6893Sfeldman { 74*6893Sfeldman register int br, cvec; /* r11, r10 value-result */ 75*6893Sfeldman register struct ildevice *addr = (struct ildevice *)reg; 76*6893Sfeldman register i; 77*6893Sfeldman 78*6893Sfeldman COUNT(ILPROBE); 79*6893Sfeldman #ifdef lint 80*6893Sfeldman br = 0; cvec = br; br = cvec; 81*6893Sfeldman ilrint(0); ilcint(0); 82*6893Sfeldman #endif 83*6893Sfeldman 84*6893Sfeldman addr->il_csr = ILC_OFFLINE|IL_CIE; 85*6893Sfeldman DELAY(100000); 86*6893Sfeldman i = addr->il_csr; /* Clear CDONE */ 87*6893Sfeldman if (cvec > 0 && cvec != 0x200) 88*6893Sfeldman cvec -= 4; 89*6893Sfeldman return (1); 90*6893Sfeldman } 91*6893Sfeldman 92*6893Sfeldman struct il_stat ilbuf; 93*6893Sfeldman /* 94*6893Sfeldman * Interface exists: make available by filling in network interface 95*6893Sfeldman * record. System will initialize the interface when it is ready 96*6893Sfeldman * to accept packets. A STATUS command is done to get the ethernet 97*6893Sfeldman * address and other interesting data. 98*6893Sfeldman */ 99*6893Sfeldman ilattach(ui) 100*6893Sfeldman struct uba_device *ui; 101*6893Sfeldman { 102*6893Sfeldman register struct il_softc *is = &il_softc[ui->ui_unit]; 103*6893Sfeldman register struct sockaddr_in *sin; 104*6893Sfeldman register struct ildevice *addr = (struct ildevice *)ui->ui_addr; 105*6893Sfeldman register int i; 106*6893Sfeldman int s; 107*6893Sfeldman int ubaddr; 108*6893Sfeldman COUNT(ILATTACH); 109*6893Sfeldman 110*6893Sfeldman is->is_if.if_unit = ui->ui_unit; 111*6893Sfeldman is->is_if.if_name = "il"; 112*6893Sfeldman is->is_if.if_mtu = ILMTU; 113*6893Sfeldman is->is_if.if_net = ui->ui_flags & 0xff; 114*6893Sfeldman 115*6893Sfeldman /* 116*6893Sfeldman * Reset the board 117*6893Sfeldman */ 118*6893Sfeldman s = splimp(); 119*6893Sfeldman addr->il_csr = ((ubaddr>>2)&0xc000)|ILC_RESET; 120*6893Sfeldman while (!(addr->il_csr & IL_CDONE)) 121*6893Sfeldman /* Busy wait */; 122*6893Sfeldman if (addr->il_csr & IL_STATUS) 123*6893Sfeldman printf("il%d: %s\n", ui->ui_unit, 124*6893Sfeldman ildiag[addr->il_csr & IL_STATUS]); 125*6893Sfeldman splx(s); 126*6893Sfeldman 127*6893Sfeldman /* 128*6893Sfeldman * Map the status buffer to the Unibus, do the status command, 129*6893Sfeldman * and unmap the buffer. 130*6893Sfeldman */ 131*6893Sfeldman ubaddr = uballoc(ui->ui_ubanum, &ilbuf, sizeof(ilbuf), 0); 132*6893Sfeldman s = splimp(); 133*6893Sfeldman addr->il_bar = ubaddr & 0xffff; 134*6893Sfeldman addr->il_bcr = sizeof(ilbuf); 135*6893Sfeldman addr->il_csr = ((ubaddr>>2)&0xc000)|ILC_STAT; 136*6893Sfeldman while (!(addr->il_csr & IL_CDONE)) 137*6893Sfeldman /* Busy wait */; 138*6893Sfeldman if (addr->il_csr & IL_STATUS) 139*6893Sfeldman printf("il%d: %s\n", ui->ui_unit, 140*6893Sfeldman ilerrs[addr->il_csr & IL_STATUS]); 141*6893Sfeldman splx(s); 142*6893Sfeldman ubarelse(ui->ui_ubanum, &ubaddr); 143*6893Sfeldman /* 144*6893Sfeldman * Fill in the Ethernet address from the status buffer 145*6893Sfeldman */ 146*6893Sfeldman for (i=0; i<6; i++) 147*6893Sfeldman is->is_enaddr[i] = ilbuf.ils_addr[i]; 148*6893Sfeldman printf("il%d: addr=%x:%x:%x:%x:%x:%x module=%s firmware=%s\n", 149*6893Sfeldman ui->ui_unit, 150*6893Sfeldman is->is_enaddr[0]&0xff, is->is_enaddr[1]&0xff, 151*6893Sfeldman is->is_enaddr[2]&0xff, is->is_enaddr[3]&0xff, 152*6893Sfeldman is->is_enaddr[4]&0xff, is->is_enaddr[5]&0xff, 153*6893Sfeldman ilbuf.ils_module, ilbuf.ils_firmware); 154*6893Sfeldman is->is_if.if_host[0] = ((is->is_enaddr[3]&0xff)<<16) | 0x800000 | 155*6893Sfeldman ((is->is_enaddr[4]&0xff)<<8) | (is->is_enaddr[5]&0xff); 156*6893Sfeldman sin = (struct sockaddr_in *)&is->is_if.if_addr; 157*6893Sfeldman sin->sin_family = AF_INET; 158*6893Sfeldman sin->sin_addr = if_makeaddr(is->is_if.if_net, is->is_if.if_host[0]); 159*6893Sfeldman 160*6893Sfeldman sin = (struct sockaddr_in *)&is->is_if.if_broadaddr; 161*6893Sfeldman sin->sin_family = AF_INET; 162*6893Sfeldman sin->sin_addr = if_makeaddr(is->is_if.if_net, 0); 163*6893Sfeldman is->is_if.if_flags = IFF_BROADCAST; 164*6893Sfeldman 165*6893Sfeldman is->is_if.if_init = ilinit; 166*6893Sfeldman is->is_if.if_output = iloutput; 167*6893Sfeldman is->is_if.if_ubareset = ilreset; 168*6893Sfeldman is->is_ifuba.ifu_flags = UBA_CANTWAIT; 169*6893Sfeldman if_attach(&is->is_if); 170*6893Sfeldman #if NIMP == 0 171*6893Sfeldman if (ui->ui_flags &~ 0xff) 172*6893Sfeldman illhinit((ui->ui_flags &~ 0xff) | 0x0a); 173*6893Sfeldman #endif 174*6893Sfeldman } 175*6893Sfeldman 176*6893Sfeldman /* 177*6893Sfeldman * Reset of interface after UNIBUS reset. 178*6893Sfeldman * If interface is on specified uba, reset its state. 179*6893Sfeldman */ 180*6893Sfeldman ilreset(unit, uban) 181*6893Sfeldman int unit, uban; 182*6893Sfeldman { 183*6893Sfeldman register struct uba_device *ui; 184*6893Sfeldman COUNT(ILRESET); 185*6893Sfeldman 186*6893Sfeldman if (unit >= NIL || (ui = ilinfo[unit]) == 0 || ui->ui_alive == 0 || 187*6893Sfeldman ui->ui_ubanum != uban) 188*6893Sfeldman return; 189*6893Sfeldman printf(" il%d", unit); 190*6893Sfeldman ilinit(unit); 191*6893Sfeldman } 192*6893Sfeldman 193*6893Sfeldman /* 194*6893Sfeldman * Initialization of interface; clear recorded pending 195*6893Sfeldman * operations, and reinitialize UNIBUS usage. 196*6893Sfeldman */ 197*6893Sfeldman ilinit(unit) 198*6893Sfeldman int unit; 199*6893Sfeldman { 200*6893Sfeldman register struct il_softc *is = &il_softc[unit]; 201*6893Sfeldman register struct uba_device *ui = ilinfo[unit]; 202*6893Sfeldman register struct ildevice *addr; 203*6893Sfeldman register i; 204*6893Sfeldman int s; 205*6893Sfeldman 206*6893Sfeldman if (if_ubainit(&is->is_ifuba, ui->ui_ubanum, 207*6893Sfeldman sizeof (struct il_rheader), (int)btoc(ILMTU)) == 0) { 208*6893Sfeldman printf("il%d: can't initialize\n", unit); 209*6893Sfeldman is->is_if.if_flags &= ~IFF_UP; 210*6893Sfeldman return; 211*6893Sfeldman } 212*6893Sfeldman addr = (struct ildevice *)ui->ui_addr; 213*6893Sfeldman 214*6893Sfeldman /* 215*6893Sfeldman * Set board online. 216*6893Sfeldman * Hang receive buffer and start any pending 217*6893Sfeldman * writes by faking a transmit complete. 218*6893Sfeldman * Receive bcr is not a muliple of 4 so buffer 219*6893Sfeldman * chaining can't happen. 220*6893Sfeldman */ 221*6893Sfeldman s = splimp(); 222*6893Sfeldman addr->il_csr = ILC_ONLINE; 223*6893Sfeldman while (!(addr->il_csr & IL_CDONE)) 224*6893Sfeldman /* Busy wait */; 225*6893Sfeldman addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 226*6893Sfeldman addr->il_bcr = sizeof(struct il_rheader) + ILMTU + 6; 227*6893Sfeldman addr->il_csr = ((is->is_ifuba.ifu_r.ifrw_info>>2)&0xc000)| 228*6893Sfeldman ILC_RCV|IL_RIE; 229*6893Sfeldman while (!(addr->il_csr & IL_CDONE)) 230*6893Sfeldman /* Busy wait */; 231*6893Sfeldman is->is_startrcv = 0; 232*6893Sfeldman is->is_oactive = 1; 233*6893Sfeldman is->is_if.if_flags |= IFF_UP; 234*6893Sfeldman ilcint(unit); 235*6893Sfeldman splx(s); 236*6893Sfeldman if_rtinit(&is->is_if, RTF_DIRECT|RTF_UP); 237*6893Sfeldman } 238*6893Sfeldman 239*6893Sfeldman /* 240*6893Sfeldman * Start output on interface. 241*6893Sfeldman * Get another datagram to send off of the interface queue, 242*6893Sfeldman * and map it to the interface before starting the output. 243*6893Sfeldman */ 244*6893Sfeldman ilstart(dev) 245*6893Sfeldman dev_t dev; 246*6893Sfeldman { 247*6893Sfeldman int unit = ILUNIT(dev); 248*6893Sfeldman struct uba_device *ui = ilinfo[unit]; 249*6893Sfeldman register struct il_softc *is = &il_softc[unit]; 250*6893Sfeldman register struct ildevice *addr; 251*6893Sfeldman register len; 252*6893Sfeldman struct mbuf *m; 253*6893Sfeldman int dest; 254*6893Sfeldman COUNT(ILSTART); 255*6893Sfeldman 256*6893Sfeldman /* 257*6893Sfeldman * Dequeue another request and copy it into the buffer. 258*6893Sfeldman * If no more requests, just return. 259*6893Sfeldman */ 260*6893Sfeldman IF_DEQUEUE(&is->is_if.if_snd, m); 261*6893Sfeldman if (m == 0) 262*6893Sfeldman return; 263*6893Sfeldman len = if_wubaput(&is->is_ifuba, m); 264*6893Sfeldman 265*6893Sfeldman /* 266*6893Sfeldman * Flush BDP, then start the output. 267*6893Sfeldman */ 268*6893Sfeldman if (is->is_ifuba.ifu_flags & UBA_NEEDBDP) 269*6893Sfeldman UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp); 270*6893Sfeldman addr = (struct ildevice *)ui->ui_addr; 271*6893Sfeldman addr->il_bar = is->is_ifuba.ifu_w.ifrw_info & 0xffff; 272*6893Sfeldman addr->il_bcr = len; 273*6893Sfeldman addr->il_csr = ((is->is_ifuba.ifu_w.ifrw_info>>2)&0xc000)| 274*6893Sfeldman ILC_XMIT|IL_CIE|IL_RIE; 275*6893Sfeldman is->is_oactive = 1; 276*6893Sfeldman } 277*6893Sfeldman 278*6893Sfeldman /* 279*6893Sfeldman * Command done interrupt. 280*6893Sfeldman * This should only happen after a transmit command, 281*6893Sfeldman * so it is equivalent to a transmit interrupt. 282*6893Sfeldman * Start another output if more data to send. 283*6893Sfeldman */ 284*6893Sfeldman ilcint(unit) 285*6893Sfeldman int unit; 286*6893Sfeldman { 287*6893Sfeldman register struct uba_device *ui = ilinfo[unit]; 288*6893Sfeldman register struct il_softc *is = &il_softc[unit]; 289*6893Sfeldman register struct ildevice *addr = (struct ildevice *)ui->ui_addr; 290*6893Sfeldman register int err; 291*6893Sfeldman COUNT(ILCINT); 292*6893Sfeldman 293*6893Sfeldman if (is->is_oactive == 0) { 294*6893Sfeldman printf("il%d: strange xmit interrupt!\n", unit); 295*6893Sfeldman return; 296*6893Sfeldman } 297*6893Sfeldman is->is_if.if_opackets++; 298*6893Sfeldman is->is_oactive = 0; 299*6893Sfeldman if (err = (addr->il_csr & IL_STATUS)){ 300*6893Sfeldman is->is_if.if_oerrors++; 301*6893Sfeldman printf("il%d: output error %d\n", unit, err); 302*6893Sfeldman } 303*6893Sfeldman /* 304*6893Sfeldman * Hang receive buffer if it couldn't be done earlier (in ilrint). 305*6893Sfeldman */ 306*6893Sfeldman if (is->is_startrcv) { 307*6893Sfeldman addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 308*6893Sfeldman addr->il_bcr = sizeof(struct il_rheader) + ILMTU + 6; 309*6893Sfeldman addr->il_csr = ((is->is_ifuba.ifu_r.ifrw_info>>2)&0xc000)| 310*6893Sfeldman ILC_RCV|IL_RIE; 311*6893Sfeldman while (!(addr->il_csr & IL_CDONE)) 312*6893Sfeldman /* Busy wait */; 313*6893Sfeldman is->is_startrcv = 0; 314*6893Sfeldman } 315*6893Sfeldman if (is->is_ifuba.ifu_xtofree) { 316*6893Sfeldman m_freem(is->is_ifuba.ifu_xtofree); 317*6893Sfeldman is->is_ifuba.ifu_xtofree = 0; 318*6893Sfeldman } 319*6893Sfeldman if (is->is_if.if_snd.ifq_head == 0) { 320*6893Sfeldman return; 321*6893Sfeldman } 322*6893Sfeldman ilstart(unit); 323*6893Sfeldman } 324*6893Sfeldman 325*6893Sfeldman /* 326*6893Sfeldman * Ethernet interface receiver interrupt. 327*6893Sfeldman * If input error just drop packet. 328*6893Sfeldman * Otherwise purge input buffered data path and examine 329*6893Sfeldman * packet to determine type. If can't determine length 330*6893Sfeldman * from type, then have to drop packet. Othewise decapsulate 331*6893Sfeldman * packet based on type and pass to type specific higher-level 332*6893Sfeldman * input routine. 333*6893Sfeldman */ 334*6893Sfeldman ilrint(unit) 335*6893Sfeldman int unit; 336*6893Sfeldman { 337*6893Sfeldman register struct il_softc *is = &il_softc[unit]; 338*6893Sfeldman struct ildevice *addr = (struct ildevice *)ilinfo[unit]->ui_addr; 339*6893Sfeldman register struct il_rheader *il; 340*6893Sfeldman struct mbuf *m; 341*6893Sfeldman int len, off, resid; 342*6893Sfeldman register struct ifqueue *inq; 343*6893Sfeldman 344*6893Sfeldman COUNT(ILRINT); 345*6893Sfeldman is->is_if.if_ipackets++; 346*6893Sfeldman if (is->is_ifuba.ifu_flags & UBA_NEEDBDP) 347*6893Sfeldman UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp); 348*6893Sfeldman il = (struct il_rheader *)(is->is_ifuba.ifu_r.ifrw_addr); 349*6893Sfeldman len = il->ilr_length - sizeof(struct il_rheader); 350*6893Sfeldman if (il->ilr_status&0x3 || len < 46 || len > ILMTU) { 351*6893Sfeldman is->is_if.if_ierrors++; 352*6893Sfeldman #ifdef notdef 353*6893Sfeldman if (is->is_if.if_ierrors % 100 == 0) 354*6893Sfeldman printf("il%d: += 100 input errors\n", unit); 355*6893Sfeldman #endif 356*6893Sfeldman printf("il%d: input error (status=%x, len=%d)\n", unit, 357*6893Sfeldman il->ilr_status, len); 358*6893Sfeldman goto setup; 359*6893Sfeldman } 360*6893Sfeldman 361*6893Sfeldman /* 362*6893Sfeldman * Deal with trailer protocol: if type is PUP trailer 363*6893Sfeldman * get true type from first 16-bit word past data. 364*6893Sfeldman * Remember that type was trailer by setting off. 365*6893Sfeldman */ 366*6893Sfeldman #define ildataaddr(il, off, type) ((type)(((caddr_t)((il)+1)+(off)))) 367*6893Sfeldman if (il->ilr_type >= ILPUP_TRAIL && 368*6893Sfeldman il->ilr_type < ILPUP_TRAIL+ILPUP_NTRAILER) { 369*6893Sfeldman off = (il->ilr_type - ILPUP_TRAIL) * 512; 370*6893Sfeldman if (off >= ILMTU) 371*6893Sfeldman goto setup; /* sanity */ 372*6893Sfeldman il->ilr_type = *ildataaddr(il, off, u_short *); 373*6893Sfeldman resid = *(ildataaddr(il, off+2, u_short *)); 374*6893Sfeldman if (off + resid > len) 375*6893Sfeldman goto setup; /* sanity */ 376*6893Sfeldman len = off + resid; 377*6893Sfeldman } else 378*6893Sfeldman off = 0; 379*6893Sfeldman if (len == 0) 380*6893Sfeldman goto setup; 381*6893Sfeldman 382*6893Sfeldman /* 383*6893Sfeldman * Pull packet off interface. Off is nonzero if packet 384*6893Sfeldman * has trailing header; ilget will then force this header 385*6893Sfeldman * information to be at the front, but we still have to drop 386*6893Sfeldman * the type and length which are at the front of any trailer data. 387*6893Sfeldman */ 388*6893Sfeldman m = if_rubaget(&is->is_ifuba, len, off); 389*6893Sfeldman if (m == 0) 390*6893Sfeldman goto setup; 391*6893Sfeldman if (off) { 392*6893Sfeldman m->m_off += 2 * sizeof (u_short); 393*6893Sfeldman m->m_len -= 2 * sizeof (u_short); 394*6893Sfeldman } 395*6893Sfeldman switch (il->ilr_type) { 396*6893Sfeldman 397*6893Sfeldman #ifdef INET 398*6893Sfeldman case ILPUP_IPTYPE: 399*6893Sfeldman schednetisr(NETISR_IP); 400*6893Sfeldman inq = &ipintrq; 401*6893Sfeldman break; 402*6893Sfeldman #endif 403*6893Sfeldman default: 404*6893Sfeldman m_freem(m); 405*6893Sfeldman goto setup; 406*6893Sfeldman } 407*6893Sfeldman 408*6893Sfeldman if (IF_QFULL(inq)) { 409*6893Sfeldman IF_DROP(inq); 410*6893Sfeldman m_freem(m); 411*6893Sfeldman } else 412*6893Sfeldman IF_ENQUEUE(inq, m); 413*6893Sfeldman 414*6893Sfeldman setup: 415*6893Sfeldman /* 416*6893Sfeldman * Reset for next packet if possible. 417*6893Sfeldman * If waiting for transmit command completion, set flag 418*6893Sfeldman * and wait until command completes. 419*6893Sfeldman */ 420*6893Sfeldman if (!is->is_oactive) { 421*6893Sfeldman addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff; 422*6893Sfeldman addr->il_bcr = sizeof(struct il_rheader) + ILMTU + 6; 423*6893Sfeldman addr->il_csr = ((is->is_ifuba.ifu_r.ifrw_info>>2)&0xc000)| 424*6893Sfeldman ILC_RCV|IL_RIE; 425*6893Sfeldman while (!(addr->il_csr & IL_CDONE)) 426*6893Sfeldman /* Busy wait */; 427*6893Sfeldman } else 428*6893Sfeldman is->is_startrcv = 1; 429*6893Sfeldman } 430*6893Sfeldman 431*6893Sfeldman /* 432*6893Sfeldman * Ethernet output routine. 433*6893Sfeldman * Encapsulate a packet of type family for the local net. 434*6893Sfeldman * Use trailer local net encapsulation if enough data in first 435*6893Sfeldman * packet leaves a multiple of 512 bytes of data in remainder. 436*6893Sfeldman */ 437*6893Sfeldman iloutput(ifp, m0, dst) 438*6893Sfeldman struct ifnet *ifp; 439*6893Sfeldman struct mbuf *m0; 440*6893Sfeldman struct sockaddr *dst; 441*6893Sfeldman { 442*6893Sfeldman int type, dest, s, error; 443*6893Sfeldman register struct il_softc *is = &il_softc[ifp->if_unit]; 444*6893Sfeldman register struct mbuf *m = m0; 445*6893Sfeldman register struct il_xheader *il; 446*6893Sfeldman register int off; 447*6893Sfeldman register int i; 448*6893Sfeldman 449*6893Sfeldman COUNT(ILOUTPUT); 450*6893Sfeldman switch (dst->sa_family) { 451*6893Sfeldman 452*6893Sfeldman #ifdef INET 453*6893Sfeldman case AF_INET: 454*6893Sfeldman dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr; 455*6893Sfeldman off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len; 456*6893Sfeldman if (off > 0 && (off & 0x1ff) == 0 && 457*6893Sfeldman m->m_off >= MMINOFF + 2 * sizeof (u_short)) { 458*6893Sfeldman type = ILPUP_TRAIL + (off>>9); 459*6893Sfeldman m->m_off -= 2 * sizeof (u_short); 460*6893Sfeldman m->m_len += 2 * sizeof (u_short); 461*6893Sfeldman *mtod(m, u_short *) = ILPUP_IPTYPE; 462*6893Sfeldman *(mtod(m, u_short *) + 1) = m->m_len; 463*6893Sfeldman goto gottrailertype; 464*6893Sfeldman } 465*6893Sfeldman type = ILPUP_IPTYPE; 466*6893Sfeldman off = 0; 467*6893Sfeldman goto gottype; 468*6893Sfeldman #endif 469*6893Sfeldman 470*6893Sfeldman default: 471*6893Sfeldman printf("il%d: can't handle af%d\n", ifp->if_unit, 472*6893Sfeldman dst->sa_family); 473*6893Sfeldman error = EAFNOSUPPORT; 474*6893Sfeldman goto bad; 475*6893Sfeldman } 476*6893Sfeldman 477*6893Sfeldman gottrailertype: 478*6893Sfeldman /* 479*6893Sfeldman * Packet to be sent as trailer: move first packet 480*6893Sfeldman * (control information) to end of chain. 481*6893Sfeldman */ 482*6893Sfeldman while (m->m_next) 483*6893Sfeldman m = m->m_next; 484*6893Sfeldman m->m_next = m0; 485*6893Sfeldman m = m0->m_next; 486*6893Sfeldman m0->m_next = 0; 487*6893Sfeldman m0 = m; 488*6893Sfeldman 489*6893Sfeldman gottype: 490*6893Sfeldman /* 491*6893Sfeldman * Add local net header. If no space in first mbuf, 492*6893Sfeldman * allocate another. 493*6893Sfeldman */ 494*6893Sfeldman if (m->m_off > MMAXOFF || 495*6893Sfeldman MMINOFF + sizeof (struct il_xheader) > m->m_off) { 496*6893Sfeldman m = m_get(M_DONTWAIT); 497*6893Sfeldman if (m == 0) { 498*6893Sfeldman error = ENOBUFS; 499*6893Sfeldman goto bad; 500*6893Sfeldman } 501*6893Sfeldman m->m_next = m0; 502*6893Sfeldman m->m_off = MMINOFF; 503*6893Sfeldman m->m_len = sizeof (struct il_xheader); 504*6893Sfeldman } else { 505*6893Sfeldman m->m_off -= sizeof (struct il_xheader); 506*6893Sfeldman m->m_len += sizeof (struct il_xheader); 507*6893Sfeldman } 508*6893Sfeldman il = mtod(m, struct il_xheader *); 509*6893Sfeldman if ((dest &~ 0xff) == 0) 510*6893Sfeldman for (i=0; i<6; i++) 511*6893Sfeldman il->ilx_dhost[i] = 0xff; 512*6893Sfeldman else { 513*6893Sfeldman if (dest & 0x8000) { 514*6893Sfeldman il->ilx_dhost[0] = is->is_enaddr[0]; 515*6893Sfeldman il->ilx_dhost[1] = is->is_enaddr[1]; 516*6893Sfeldman il->ilx_dhost[2] = is->is_enaddr[2]; 517*6893Sfeldman } else { 518*6893Sfeldman il->ilx_dhost[0] = il_ectop[0]; 519*6893Sfeldman il->ilx_dhost[1] = il_ectop[1]; 520*6893Sfeldman il->ilx_dhost[2] = il_ectop[2]; 521*6893Sfeldman } 522*6893Sfeldman il->ilx_dhost[3] = (dest>>8) & 0x7f; 523*6893Sfeldman il->ilx_dhost[4] = (dest>>16) & 0xff; 524*6893Sfeldman il->ilx_dhost[5] = (dest>>24) & 0xff; 525*6893Sfeldman } 526*6893Sfeldman il->ilx_type = type; 527*6893Sfeldman 528*6893Sfeldman /* 529*6893Sfeldman * Queue message on interface, and start output if interface 530*6893Sfeldman * not yet active. 531*6893Sfeldman */ 532*6893Sfeldman s = splimp(); 533*6893Sfeldman if (IF_QFULL(&ifp->if_snd)) { 534*6893Sfeldman IF_DROP(&ifp->if_snd); 535*6893Sfeldman error = ENOBUFS; 536*6893Sfeldman goto qfull; 537*6893Sfeldman } 538*6893Sfeldman IF_ENQUEUE(&ifp->if_snd, m); 539*6893Sfeldman if (is->is_oactive == 0) 540*6893Sfeldman ilstart(ifp->if_unit); 541*6893Sfeldman splx(s); 542*6893Sfeldman return (0); 543*6893Sfeldman qfull: 544*6893Sfeldman m0 = m; 545*6893Sfeldman splx(s); 546*6893Sfeldman bad: 547*6893Sfeldman m_freem(m0); 548*6893Sfeldman return(error); 549*6893Sfeldman } 550*6893Sfeldman 551*6893Sfeldman #if NIMP == 0 && NIL > 0 552*6893Sfeldman /* 553*6893Sfeldman * Logical host interface driver. 554*6893Sfeldman * Allows host to appear as an ARPAnet 555*6893Sfeldman * logical host. Must also have routing 556*6893Sfeldman * table entry set up to forward packets 557*6893Sfeldman * to appropriate gateway on localnet. 558*6893Sfeldman */ 559*6893Sfeldman 560*6893Sfeldman struct ifnet illhif; 561*6893Sfeldman int illhoutput(); 562*6893Sfeldman 563*6893Sfeldman /* 564*6893Sfeldman * Called by localnet interface to allow logical 565*6893Sfeldman * host interface to "attach". Nothing should ever 566*6893Sfeldman * be sent locally to this interface, it's purpose 567*6893Sfeldman * is simply to establish the host's arpanet address. 568*6893Sfeldman */ 569*6893Sfeldman illhinit(addr) 570*6893Sfeldman int addr; 571*6893Sfeldman { 572*6893Sfeldman register struct ifnet *ifp = &illhif; 573*6893Sfeldman register struct sockaddr_in *sin; 574*6893Sfeldman 575*6893Sfeldman COUNT(ILLHINIT); 576*6893Sfeldman ifp->if_name = "lh"; 577*6893Sfeldman ifp->if_mtu = ILMTU; 578*6893Sfeldman sin = (struct sockaddr_in *)&ifp->if_addr; 579*6893Sfeldman sin->sin_family = AF_INET; 580*6893Sfeldman sin->sin_addr.s_addr = addr; 581*6893Sfeldman ifp->if_net = sin->sin_addr.s_net; 582*6893Sfeldman ifp->if_flags = IFF_UP; 583*6893Sfeldman ifp->if_output = illhoutput; /* should never be used */ 584*6893Sfeldman if_attach(ifp); 585*6893Sfeldman } 586*6893Sfeldman 587*6893Sfeldman illhoutput(ifp, m0, dst) 588*6893Sfeldman struct ifnet *ifp; 589*6893Sfeldman struct mbuf *m0; 590*6893Sfeldman struct sockaddr *dst; 591*6893Sfeldman { 592*6893Sfeldman COUNT(ILLHOUTPUT); 593*6893Sfeldman ifp->if_oerrors++; 594*6893Sfeldman m_freem(m0); 595*6893Sfeldman return (0); 596*6893Sfeldman } 597*6893Sfeldman #endif 598