X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/f1b2fa5b8a62e80603e6c83b87eaf0b06db3818e..5e35ed2481cff3093e5df1d23606e3f8ce318fba:/usr/src/sys/vax/if/if_en.c?ds=sidebyside diff --git a/usr/src/sys/vax/if/if_en.c b/usr/src/sys/vax/if/if_en.c index 9048145123..6299fcb687 100644 --- a/usr/src/sys/vax/if/if_en.c +++ b/usr/src/sys/vax/if/if_en.c @@ -1,4 +1,4 @@ -/* if_en.c 4.15 81/11/29 */ +/* if_en.c 4.71 82/10/24 */ #include "en.h" @@ -13,27 +13,34 @@ #include "../h/buf.h" #include "../h/protosw.h" #include "../h/socket.h" -#include "../h/ubareg.h" -#include "../h/ubavar.h" -#include "../h/enreg.h" -#include "../h/cpu.h" -#include "../h/mtpr.h" #include "../h/vmmac.h" -#include "../net/in.h" -#include "../net/in_systm.h" -#include "../net/if.h" -#include "../net/if_en.h" -#include "../net/if_uba.h" -#include "../net/ip.h" -#include "../net/ip_var.h" +#include -#define ENMTU 1024 +#include "../net/if.h" +#include "../net/netisr.h" +#include "../net/route.h" +#include "../netinet/in.h" +#include "../netinet/in_systm.h" +#include "../netinet/ip.h" +#include "../netinet/ip_var.h" +#include "../netpup/pup.h" + +#include "../vax/cpu.h" +#include "../vax/mtpr.h" +#include "../vaxif/if_en.h" +#include "../vaxif/if_enreg.h" +#include "../vaxif/if_uba.h" +#include "../vaxuba/ubareg.h" +#include "../vaxuba/ubavar.h" + +#define ENMTU (1024+512) +#define ENMRU (1024+512+16) /* 16 is enough to receive trailer */ int enprobe(), enattach(), enrint(), enxint(), encollide(); struct uba_device *eninfo[NEN]; u_short enstd[] = { 0 }; struct uba_driver endriver = - { enprobe, 0, enattach, 0, enstd, "es", eninfo }; + { enprobe, 0, enattach, 0, enstd, "en", eninfo }; #define ENUNIT(x) minor(x) int eninit(),enoutput(),enreset(); @@ -55,7 +62,7 @@ struct en_softc { struct ifuba es_ifuba; /* UNIBUS resources */ short es_delay; /* current output delay */ short es_mask; /* mask for current output delay */ - u_char es_lastx; /* host last transmitted to */ + short es_lastx; /* host last transmitted to */ short es_oactive; /* is output active? */ short es_olen; /* length of last output */ } en_softc[NEN]; @@ -67,10 +74,9 @@ struct en_softc { enprobe(reg) caddr_t reg; { - register int br, cvec; + register int br, cvec; /* r11, r10 value-result */ register struct endevice *addr = (struct endevice *)reg; -COUNT(ENPROBE); #ifdef lint br = 0; cvec = br; br = cvec; enrint(0); enxint(0); encollide(0); @@ -81,6 +87,9 @@ COUNT(ENPROBE); addr->en_ostat = EN_IEN|EN_GO; DELAY(100000); addr->en_ostat = 0; +#ifdef ECHACK + br = 0x16; +#endif return (1); } @@ -93,18 +102,26 @@ enattach(ui) struct uba_device *ui; { register struct en_softc *es = &en_softc[ui->ui_unit]; -COUNT(ENATTACH); + register struct sockaddr_in *sin; es->es_if.if_unit = ui->ui_unit; + es->es_if.if_name = "en"; es->es_if.if_mtu = ENMTU; es->es_if.if_net = ui->ui_flags; es->es_if.if_host[0] = - ~(((struct endevice *)eninfo[ui->ui_unit])->en_addr) & 0xff; - es->es_if.if_addr = - if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]); - es->es_if.if_output = enoutput; + (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff; + sin = (struct sockaddr_in *)&es->es_if.if_addr; + sin->sin_family = AF_INET; + sin->sin_addr = if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]); + sin = (struct sockaddr_in *)&es->es_if.if_broadaddr; + sin->sin_family = AF_INET; + sin->sin_addr = if_makeaddr(es->es_if.if_net, 0); + es->es_if.if_flags = IFF_BROADCAST; es->es_if.if_init = eninit; + es->es_if.if_output = enoutput; es->es_if.if_ubareset = enreset; + es->es_ifuba.ifu_flags = UBA_NEEDBDP | UBA_NEED16 | UBA_CANTWAIT; + if_attach(&es->es_if); } /* @@ -115,14 +132,11 @@ enreset(unit, uban) int unit, uban; { register struct uba_device *ui; -COUNT(ENRESET); - if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0) { - printf("es%d: not alive\n", unit); - return; - } - if (ui->ui_ubanum != uban) + if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0 || + ui->ui_ubanum != uban) return; + printf(" en%d", unit); eninit(unit); } @@ -133,31 +147,38 @@ COUNT(ENRESET); eninit(unit) int unit; { - register struct uba_device *ui; + register struct en_softc *es = &en_softc[unit]; + register struct uba_device *ui = eninfo[unit]; register struct endevice *addr; - register struct en_softc *es; int s; - es = &en_softc[unit]; - ui = eninfo[unit]; if (if_ubainit(&es->es_ifuba, ui->ui_ubanum, - sizeof (struct en_header), (int)btop(ENMTU)) == 0) { - printf("es%d: can't initialize\n", unit); + sizeof (struct en_header), (int)btoc(ENMRU)) == 0) { + printf("en%d: can't initialize\n", unit); + es->es_if.if_flags &= ~IFF_UP; return; } addr = (struct endevice *)ui->ui_addr; addr->en_istat = addr->en_ostat = 0; /* - * Hang pending read, start any writes. + * Hang a receive and start any + * pending writes by faking a transmit complete. */ s = splimp(); - enstart(unit); + addr->en_iba = es->es_ifuba.ifu_r.ifrw_info; + addr->en_iwc = -(sizeof (struct en_header) + ENMRU) >> 1; + addr->en_istat = EN_IEN|EN_GO; + es->es_oactive = 1; + es->es_if.if_flags |= IFF_UP; enxint(unit); splx(s); + if_rtinit(&es->es_if, RTF_UP); } -int enlastdel = 25; +int enalldelay = 0; +int enlastdel = 50; +int enlastmask = (~0) << 5; /* * Start or restart output on interface. @@ -170,17 +191,13 @@ int enlastdel = 25; enstart(dev) dev_t dev; { - int unit; - struct uba_device *ui; + int unit = ENUNIT(dev); + struct uba_device *ui = eninfo[unit]; + register struct en_softc *es = &en_softc[unit]; register struct endevice *addr; - register struct en_softc *es; struct mbuf *m; int dest; -COUNT(ENSTART); - unit = ENUNIT(dev); - ui = eninfo[unit]; - es = &en_softc[unit]; if (es->es_oactive) goto restart; @@ -194,28 +211,32 @@ COUNT(ENSTART); es->es_oactive = 0; return; } + dest = mtod(m, struct en_header *)->en_dhost; es->es_olen = if_wubaput(&es->es_ifuba, m); /* * Ethernet cannot take back-to-back packets (no - * buffering in interface. To avoid overrunning - * receiver, enforce a small delay (about 1ms) in interface - * on successive packets sent to same host. + * buffering in interface. To help avoid overrunning + * receivers, enforce a small delay (about 1ms) in interface: + * * between all packets when enalldelay + * * whenever last packet was broadcast + * * whenever this packet is to same host as last packet */ - dest = mtod(m, struct en_header *)->en_dhost; - if (es->es_lastx && es->es_lastx == dest) + if (enalldelay || es->es_lastx == 0 || es->es_lastx == dest) { es->es_delay = enlastdel; - else - es->es_lastx = dest; + es->es_mask = enlastmask; + } + es->es_lastx = dest; restart: /* * Have request mapped to UNIBUS for transmission. * Purge any stale data from this BDP, and start the otput. */ - UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_w.ifrw_bdp); + if (es->es_ifuba.ifu_flags & UBA_NEEDBDP) + UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_w.ifrw_bdp); addr = (struct endevice *)ui->ui_addr; - addr->en_oba = (int)es->es_ifuba.ifu_w.ifrw_addr; + addr->en_oba = (int)es->es_ifuba.ifu_w.ifrw_info; addr->en_odelay = es->es_delay; addr->en_owc = -((es->es_olen + 1) >> 1); addr->en_ostat = EN_IEN|EN_GO; @@ -229,24 +250,27 @@ restart: enxint(unit) int unit; { - register struct endevice *addr; - register struct uba_device *ui; - register struct en_softc *es; -COUNT(ENXINT); + register struct uba_device *ui = eninfo[unit]; + register struct en_softc *es = &en_softc[unit]; + register struct endevice *addr = (struct endevice *)ui->ui_addr; - ui = eninfo[unit]; - es = &en_softc[unit]; if (es->es_oactive == 0) return; - addr = (struct endevice *)ui->ui_addr; - es = &en_softc[unit]; + if (es->es_mask && (addr->en_ostat&EN_OERROR)) { + es->es_if.if_oerrors++; + endocoll(unit); + return; + } + es->es_if.if_opackets++; es->es_oactive = 0; es->es_delay = 0; es->es_mask = ~0; - if (addr->en_ostat&EN_OERROR) - printf("es%d: output error\n", unit); + if (es->es_ifuba.ifu_xtofree) { + m_freem(es->es_ifuba.ifu_xtofree); + es->es_ifuba.ifu_xtofree = 0; + } if (es->es_if.if_snd.ifq_head == 0) { - es->es_lastx = 0; + es->es_lastx = 256; /* putatively illegal */ return; } enstart(unit); @@ -255,28 +279,46 @@ COUNT(ENXINT); /* * Collision on ethernet interface. Do exponential * backoff, and retransmit. If have backed off all - * the way printing warning diagnostic, and drop packet. + * the way print warning diagnostic, and drop packet. */ encollide(unit) int unit; { - register struct en_softc *es; -COUNT(ENCOLLIDE); + struct en_softc *es = &en_softc[unit]; - es = &en_softc[unit]; es->es_if.if_collisions++; if (es->es_oactive == 0) return; + endocoll(unit); +} + +endocoll(unit) + int unit; +{ + register struct en_softc *es = &en_softc[unit]; + + /* + * Es_mask is a 16 bit number with n low zero bits, with + * n the number of backoffs. When es_mask is 0 we have + * backed off 16 times, and give up. + */ if (es->es_mask == 0) { - printf("es%d: send error\n", unit); + printf("en%d: send error\n", unit); enxint(unit); - } else { - es->es_mask <<= 1; - es->es_delay = mfpr(ICR) &~ es->es_mask; - enstart(unit); + return; } + /* + * Another backoff. Restart with delay based on n low bits + * of the interval timer. + */ + es->es_mask <<= 1; + es->es_delay = mfpr(ICR) &~ es->es_mask; + enstart(unit); } +struct sockaddr_pup pupsrc = { AF_PUP }; +struct sockaddr_pup pupdst = { AF_PUP }; +struct sockproto pupproto = { PF_PUP }; /* * Ethernet interface receiver interrupt. * If input error just drop packet. @@ -289,85 +331,106 @@ COUNT(ENCOLLIDE); enrint(unit) int unit; { - struct endevice *addr; - register struct en_softc *es; - struct en_header *en; + register struct en_softc *es = &en_softc[unit]; + struct endevice *addr = (struct endevice *)eninfo[unit]->ui_addr; + register struct en_header *en; struct mbuf *m; - struct ifqueue *inq; - register int len; + int len; short resid; + register struct ifqueue *inq; int off; -COUNT(ENRINT); - es = &en_softc[unit]; - addr = (struct endevice *)eninfo[unit]->ui_addr; + es->es_if.if_ipackets++; /* - * Purge BDP; drop error packets. + * Purge BDP; drop if input error indicated. */ - UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp); + if (es->es_ifuba.ifu_flags & UBA_NEEDBDP) + UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp); if (addr->en_istat&EN_IERROR) { es->es_if.if_ierrors++; - printf("es%d: input error\n", unit); goto setup; } /* + * Calculate input data length. * Get pointer to ethernet header (in input buffer). * Deal with trailer protocol: if type is PUP trailer * get true type from first 16-bit word past data. * Remember that type was trailer by setting off. */ + resid = addr->en_iwc; + if (resid) + resid |= 0176000; + len = (((sizeof (struct en_header) + ENMRU) >> 1) + resid) << 1; + len -= sizeof (struct en_header); + if (len > ENMRU) + goto setup; /* sanity */ en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr); #define endataaddr(en, off, type) ((type)(((caddr_t)((en)+1)+(off)))) if (en->en_type >= ENPUP_TRAIL && en->en_type < ENPUP_TRAIL+ENPUP_NTRAILER) { off = (en->en_type - ENPUP_TRAIL) * 512; + if (off > ENMTU) + goto setup; /* sanity */ en->en_type = *endataaddr(en, off, u_short *); - off += 2; + resid = *(endataaddr(en, off+2, u_short *)); + if (off + resid > len) + goto setup; /* sanity */ + len = off + resid; } else off = 0; - + if (len == 0) + goto setup; /* - * Attempt to infer packet length from type; - * can't deal with packet if can't infer length. + * Pull packet off interface. Off is nonzero if packet + * has trailing header; if_rubaget will then force this header + * information to be at the front, but we still have to drop + * the type and length which are at the front of any trailer data. */ + m = if_rubaget(&es->es_ifuba, len, off); + if (m == 0) + goto setup; + if (off) { + m->m_off += 2 * sizeof (u_short); + m->m_len -= 2 * sizeof (u_short); + } switch (en->en_type) { #ifdef INET case ENPUP_IPTYPE: - len = endataaddr(en, off, struct ip *)->ip_len; - setipintr(); + schednetisr(NETISR_IP); inq = &ipintrq; break; #endif - - default: - printf("en%d: unknow pkt type 0x%x\n", en->en_type); +#ifdef PUP + case ENPUP_PUPTYPE: { + struct pup_header *pup = mtod(m, struct pup_header *); + + pupproto.sp_protocol = pup->pup_type; + pupdst.spup_addr = pup->pup_dport; + pupsrc.spup_addr = pup->pup_sport; + raw_input(m, &pupproto, (struct sockaddr *)&pupsrc, + (struct sockaddr *)&pupdst); goto setup; } - if (len == 0) +#endif + default: + m_freem(m); goto setup; - - /* - * Pull packet off interface. Off is nonzero if packet - * has trailing header; if_rubaget will then force this header - * information to be at the front, but we still have to drop - * the two-byte type which is at the front of the trailer data - * (which we ``consumed'' above). - */ - m = if_rubaget(&es->es_ifuba, len, off); - if (off) { - m->m_off += 2; - m->m_len -= 2; } - IF_ENQUEUE(inq, m); + + if (IF_QFULL(inq)) { + IF_DROP(inq); + m_freem(m); + } else + IF_ENQUEUE(inq, m); setup: /* * Reset for next packet. */ addr->en_iba = es->es_ifuba.ifu_r.ifrw_info; - addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1; + addr->en_iwc = -(sizeof (struct en_header) + ENMRU) >> 1; addr->en_istat = EN_IEN|EN_GO; } @@ -377,72 +440,83 @@ setup: * Use trailer local net encapsulation if enough data in first * packet leaves a multiple of 512 bytes of data in remainder. */ -enoutput(ifp, m0, pf) +enoutput(ifp, m0, dst) struct ifnet *ifp; struct mbuf *m0; - int pf; + struct sockaddr *dst; { - int type, dest; + int type, dest, s, error; register struct mbuf *m = m0; register struct en_header *en; - int s; + register int off; - switch (pf) { + switch (dst->sa_family) { #ifdef INET - case PF_INET: { - register struct ip *ip = mtod(m0, struct ip *); - int off; - - dest = ip->ip_dst.s_addr >> 24; - off = ip->ip_len - m->m_len; - if (off && off % 512 == 0 && m->m_off >= MMINOFF + 2) { + case AF_INET: + dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr; + if (dest & 0x00ffff00) { + error = EPERM; /* ??? */ + goto bad; + } + dest = (dest >> 24) & 0xff; + off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len; + if (off > 0 && (off & 0x1ff) == 0 && + m->m_off >= MMINOFF + 2 * sizeof (u_short)) { type = ENPUP_TRAIL + (off>>9); - m->m_off -= 2; - m->m_len += 2; + m->m_off -= 2 * sizeof (u_short); + m->m_len += 2 * sizeof (u_short); *mtod(m, u_short *) = ENPUP_IPTYPE; + *(mtod(m, u_short *) + 1) = m->m_len; goto gottrailertype; } type = ENPUP_IPTYPE; off = 0; goto gottype; - } +#endif +#ifdef PUP + case AF_PUP: + dest = ((struct sockaddr_pup *)dst)->spup_addr.pp_host; + type = ENPUP_PUPTYPE; + off = 0; + goto gottype; #endif default: - printf("en%d: can't encapsulate pf%d\n", ifp->if_unit, pf); - m_freem(m0); - return (0); + printf("en%d: can't handle af%d\n", ifp->if_unit, + dst->sa_family); + error = EAFNOSUPPORT; + goto bad; } +gottrailertype: /* * Packet to be sent as trailer: move first packet * (control information) to end of chain. */ -gottrailertype: while (m->m_next) m = m->m_next; m->m_next = m0; m = m0->m_next; m0->m_next = 0; + m0 = m; +gottype: /* * Add local net header. If no space in first mbuf, * allocate another. */ -gottype: - m0 = m; - if (MMINOFF + sizeof (struct en_header) > m->m_off) { - m = m_get(0); + if (m->m_off > MMAXOFF || + MMINOFF + sizeof (struct en_header) > m->m_off) { + m = m_get(M_DONTWAIT); if (m == 0) { - m_freem(m0); - return (0); + error = ENOBUFS; + goto bad; } m->m_next = m0; m->m_off = MMINOFF; m->m_len = sizeof (struct en_header); } else { - m = m0; m->m_off -= sizeof (struct en_header); m->m_len += sizeof (struct en_header); } @@ -456,9 +530,20 @@ gottype: * not yet active. */ s = splimp(); + if (IF_QFULL(&ifp->if_snd)) { + IF_DROP(&ifp->if_snd); + error = ENOBUFS; + goto qfull; + } IF_ENQUEUE(&ifp->if_snd, m); - splx(s); if (en_softc[ifp->if_unit].es_oactive == 0) enstart(ifp->if_unit); - return (1); + splx(s); + return (0); +qfull: + m0 = m; + splx(s); +bad: + m_freem(m0); + return (error); }