From b454c3ea9e19212a6333dbc8463e4e9f25c0ad65 Mon Sep 17 00:00:00 2001 From: Bill Joy Date: Fri, 4 Dec 1981 01:33:39 -0800 Subject: [PATCH] cleanup SCCS-vsn: sys/kern/init_main.c 4.23 SCCS-vsn: sys/kern/uipc_proto.c 4.10 SCCS-vsn: sys/kern/uipc_socket2.c 4.13 SCCS-vsn: sys/net/if.h 4.6 SCCS-vsn: sys/vax/if/if_en.c 4.17 SCCS-vsn: sys/vax/if/if_en.h 4.3 SCCS-vsn: sys/net/if_loop.c 4.3 SCCS-vsn: sys/vax/if/if_uba.c 4.4 SCCS-vsn: sys/vax/if/if_uba.h 4.3 SCCS-vsn: sys/netinet/in_pcb.c 4.12 SCCS-vsn: sys/netinet/in_pcb.h 4.2 SCCS-vsn: sys/netinet/ip_icmp.c 4.10 SCCS-vsn: sys/netinet/ip_icmp.h 4.3 SCCS-vsn: sys/netinet/ip_input.c 1.22 SCCS-vsn: sys/net/raw_usrreq.c 4.3 SCCS-vsn: sys/netinet/tcp_fsm.h 4.10 SCCS-vsn: sys/netinet/tcp_input.c 1.35 SCCS-vsn: sys/netinet/tcp_subr.c 4.6 SCCS-vsn: sys/netinet/tcp_usrreq.c 1.39 SCCS-vsn: sys/netinet/udp_usrreq.c 4.14 SCCS-vsn: sys/vax/uba/ubareg.h 4.26 --- usr/src/sys/kern/init_main.c | 6 +- usr/src/sys/kern/uipc_proto.c | 10 +-- usr/src/sys/kern/uipc_socket2.c | 8 +-- usr/src/sys/net/if.h | 9 ++- usr/src/sys/net/if_loop.c | 7 ++- usr/src/sys/net/raw_usrreq.c | 3 +- usr/src/sys/netinet/in_pcb.c | 43 ++++++------- usr/src/sys/netinet/in_pcb.h | 4 +- usr/src/sys/netinet/ip_icmp.c | 17 +++-- usr/src/sys/netinet/ip_icmp.h | 4 +- usr/src/sys/netinet/ip_input.c | 4 +- usr/src/sys/netinet/tcp_fsm.h | 5 +- usr/src/sys/netinet/tcp_input.c | 2 +- usr/src/sys/netinet/tcp_subr.c | 2 +- usr/src/sys/netinet/tcp_usrreq.c | 3 +- usr/src/sys/netinet/udp_usrreq.c | 12 +--- usr/src/sys/vax/if/if_en.c | 104 +++++++++++++++++-------------- usr/src/sys/vax/if/if_en.h | 4 +- usr/src/sys/vax/if/if_uba.c | 88 +++++++++++++------------- usr/src/sys/vax/if/if_uba.h | 16 ++--- usr/src/sys/vax/uba/ubareg.h | 4 +- 21 files changed, 180 insertions(+), 175 deletions(-) diff --git a/usr/src/sys/kern/init_main.c b/usr/src/sys/kern/init_main.c index 0d3f4ec77b..61d8e09804 100644 --- a/usr/src/sys/kern/init_main.c +++ b/usr/src/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* init_main.c 4.22 81/11/18 */ +/* init_main.c 4.23 81/12/03 */ #include "../h/param.h" #include "../h/systm.h" @@ -84,6 +84,10 @@ main(firstaddr) mbinit(); #ifdef INET pfinit(); +#endif +#include "lo.h" +#if NLOOP > 0 + loattach(); #endif ihinit(); bhinit(); diff --git a/usr/src/sys/kern/uipc_proto.c b/usr/src/sys/kern/uipc_proto.c index 08f2c2c517..7767d834e2 100644 --- a/usr/src/sys/kern/uipc_proto.c +++ b/usr/src/sys/kern/uipc_proto.c @@ -1,4 +1,4 @@ -/* uipc_proto.c 4.9 81/11/30 */ +/* uipc_proto.c 4.10 81/12/03 */ #include "../h/param.h" #include "../h/socket.h" @@ -23,13 +23,13 @@ int piusrreq(); */ int ip_output(); int ip_init(),ip_slowtimo(),ip_drain(); -int icmp_input(); +int icmp_input(),icmp_ctlinput(); int icmp_drain(); int udp_input(),udp_ctlinput(); -int udp_usrreq(),udp_sense(); +int udp_usrreq(); int udp_init(); int tcp_input(),tcp_ctlinput(); -int tcp_usrreq(),tcp_sense(); +int tcp_usrreq(); int tcp_init(),tcp_fasttimo(),tcp_slowtimo(),tcp_drain(); int rip_input(),rip_output(),rip_ctlinput(); int rip_usrreq(),rip_slowtimo(); @@ -61,7 +61,7 @@ struct protosw protosw[] = { ip_init, 0, ip_slowtimo, ip_drain, }, { 0, 0, IPPROTO_ICMP, 0, - icmp_input, 0, 0, 0, + icmp_input, 0, icmp_ctlinput, 0, 0, 0, 0, 0, icmp_drain, }, diff --git a/usr/src/sys/kern/uipc_socket2.c b/usr/src/sys/kern/uipc_socket2.c index 80d403be0a..b22b3c4f8b 100644 --- a/usr/src/sys/kern/uipc_socket2.c +++ b/usr/src/sys/kern/uipc_socket2.c @@ -1,4 +1,4 @@ -/* uipc_socket2.c 4.12 81/12/02 */ +/* uipc_socket2.c 4.13 81/12/03 */ #include "../h/param.h" #include "../h/systm.h" @@ -62,8 +62,8 @@ soisdisconnecting(so) so->so_state &= ~(SS_ISCONNECTED|SS_ISCONNECTING); so->so_state |= (SS_ISDISCONNECTING|SS_CANTRCVMORE|SS_CANTSENDMORE); wakeup((caddr_t)&so->so_timeo); - sorwakeup(so); sowwakeup(so); + sorwakeup(so); } soisdisconnected(so) @@ -194,7 +194,7 @@ sbwakeup(sb) * first calling m_copy on the socket buffer mbuf chain and sending this * to a peer, and then removing the data from the socket buffer with * sbdrop when the data is acknowledged by the peer (or immediately - * in the case of unreliable protocols. + * in the case of unreliable protocols.) * * Protocols which do not require connections place both source address * and data information in socket buffer queues. The source addresses @@ -207,7 +207,7 @@ sbwakeup(sb) * a mbuf to store the address in. * * The higher-level routines sosend and soreceive (in socket.c) - * also add data to, and remove data from socket buffers. + * also add data to, and remove data from socket buffers repectively. */ /* diff --git a/usr/src/sys/net/if.h b/usr/src/sys/net/if.h index 59139908bb..6b287c2ba6 100644 --- a/usr/src/sys/net/if.h +++ b/usr/src/sys/net/if.h @@ -1,4 +1,4 @@ -/* if.h 4.5 81/12/02 */ +/* if.h 4.6 81/12/03 */ /* * Structures defining a network interface, providing a packet @@ -32,6 +32,7 @@ * (Would like to call this struct ``if'', but C isn't PL/1.) */ struct ifnet { + char *if_name; /* name, e.g. ``en'' or ``lo'' */ short if_unit; /* sub-unit for lower level driver */ short if_mtu; /* maximum transmission unit */ short if_net; /* network number of interface */ @@ -46,9 +47,11 @@ struct ifnet { int (*if_output)(); /* output routine */ int (*if_ubareset)(); /* uba reset routine */ /* generic interface statistics */ + int if_ipackets; /* packets received on interface */ + int if_ierrors; /* input errors on interface */ + int if_opackets; /* packets sent on interface */ + int if_oerrors; /* output errors on interface */ int if_collisions; /* collisions on csma interfaces */ - int if_ierrors; /* input errors */ - int if_oerrors; /* output errors */ /* end statistics */ struct ifnet *if_next; }; diff --git a/usr/src/sys/net/if_loop.c b/usr/src/sys/net/if_loop.c index 6e85fdc221..572929b963 100644 --- a/usr/src/sys/net/if_loop.c +++ b/usr/src/sys/net/if_loop.c @@ -1,4 +1,4 @@ -/* if_loop.c 4.2 81/12/02 */ +/* if_loop.c 4.3 81/12/03 */ /* * Loopback interface driver for protocol testing and timing. @@ -25,10 +25,11 @@ loattach() { register struct ifnet *ifp = &loif; + ifp->if_name = "lo"; ifp->if_mtu = LOMTU; ifp->if_net = LONET; + ifp->if_addr = if_makeaddr(ifp->if_net, 0); ifp->if_output = looutput; - ifp->if_next = ifnet; if_attach(ifp); } @@ -39,6 +40,7 @@ looutput(ifp, m0, pf) { int s = splimp(); + ifp->if_opackets++; switch (pf) { #ifdef INET @@ -54,6 +56,7 @@ looutput(ifp, m0, pf) m_freem(m0); return (0); } + ifp->if_ipackets++; splx(s); return (1); } diff --git a/usr/src/sys/net/raw_usrreq.c b/usr/src/sys/net/raw_usrreq.c index c1dac29fe3..c8706755a0 100644 --- a/usr/src/sys/net/raw_usrreq.c +++ b/usr/src/sys/net/raw_usrreq.c @@ -1,4 +1,4 @@ -/* raw_usrreq.c 4.2 81/12/02 */ +/* raw_usrreq.c 4.3 81/12/03 */ #include "../h/param.h" #include "../h/mbuf.h" @@ -46,7 +46,6 @@ rawintr() COUNT(RAWINTR); next: s = splimp(); -/*###45 [cc] rawintrq undefined %%%*/ IF_DEQUEUE(&rawintrq, m); splx(s); if (m == 0) diff --git a/usr/src/sys/netinet/in_pcb.c b/usr/src/sys/netinet/in_pcb.c index 930704fcf7..67bb414ec1 100644 --- a/usr/src/sys/netinet/in_pcb.c +++ b/usr/src/sys/netinet/in_pcb.c @@ -1,4 +1,4 @@ -/* in_pcb.c 4.11 81/12/02 */ +/* in_pcb.c 4.12 81/12/03 */ #include "../h/param.h" #include "../h/systm.h" @@ -40,6 +40,9 @@ * the disconnect is in progress. We notice that this has happened * when the disconnect is complete, and perform the PRU_DETACH operation, * freeing the socket. + * + * TODO: + * use hashing */ /* @@ -66,20 +69,14 @@ COUNT(IN_PCBATTACH); if (ifp == 0) return (EADDRNOTAVAIL); lport = sin->sin_port; - if (lport) { - xp = head->inp_next; - for (; xp != head; xp = xp->inp_next) - if (xp->inp_laddr.s_addr == - sin->sin_addr.s_addr && - xp->inp_lport == lport && - xp->inp_faddr.s_addr == 0) - return (EADDRINUSE); - } + if (lport && + in_pcblookup(head, 0, 0, sin->sin_addr.s_addr, lport)) + return (EADDRINUSE); } else { ifp = if_ifwithaddr(ifnet->if_addr); lport = 0; } - m = m_getclr(M_WAIT); + m = m_getclr(0); if (m == 0) return (ENOBUFS); if (sbreserve(&so->so_snd, sndcc) == 0) @@ -87,19 +84,16 @@ COUNT(IN_PCBATTACH); if (sbreserve(&so->so_rcv, rcvcc) == 0) goto bad2; inp = mtod(m, struct inpcb *); + inp->inp_head = head; inp->inp_laddr = ifp->if_addr; - if (lport) - goto gotport; -again: - if (head->inp_lport++ < 1024) - head->inp_lport = 1024; - for (xp = head->inp_next; xp != head; xp = xp->inp_next) - if (xp->inp_lport == head->inp_lport) - goto again; - lport = htons(head->inp_lport); -gotport: - inp->inp_socket = so; + if (lport == 0) + do { + if (head->inp_lport++ < 1024) + head->inp_lport = 1024; + lport = htons(head->inp_lport); + } while (in_pcblookup(head, 0, 0, inp->inp_laddr, lport)); inp->inp_lport = lport; + inp->inp_socket = so; insque(inp, head); so->so_pcb = (caddr_t)inp; sin = (struct sockaddr_in *)&so->so_addr; @@ -118,13 +112,16 @@ in_pcbconnect(inp, sin) struct inpcb *inp; struct sockaddr_in *sin; { + struct inpcb *xp; COUNT(IN_PCBCONNECT); if (sin->sin_family != AF_INET) return (EAFNOSUPPORT); if (sin->sin_addr.s_addr == 0 || sin->sin_port == 0) return (EADDRNOTAVAIL); - /* should check not already in use... */ + xp = in_pcblookup(inp->inp_head, sin->sin_addr, sin->sin_port, inp->inp_laddr, inp->inp_lport); + if (xp->inp_faddr) + return (EADDRINUSE); inp->inp_faddr = sin->sin_addr; inp->inp_fport = sin->sin_port; return (0); diff --git a/usr/src/sys/netinet/in_pcb.h b/usr/src/sys/netinet/in_pcb.h index a8cd51179b..743897234a 100644 --- a/usr/src/sys/netinet/in_pcb.h +++ b/usr/src/sys/netinet/in_pcb.h @@ -1,4 +1,4 @@ -/* in_pcb.h 4.1 81/11/20 */ +/* in_pcb.h 4.2 81/12/03 */ /* * Common structure pcb for internet protocol implementation. @@ -10,6 +10,8 @@ struct inpcb { struct inpcb *inp_next,*inp_prev; /* pointers to other pcb's */ + struct inpcb *inp_head; /* pointer back to chain of inpcb's + for this protocol */ struct in_addr inp_faddr; /* foreign host table entry */ u_short inp_fport; /* foreign port */ struct in_addr inp_laddr; /* local host table entry */ diff --git a/usr/src/sys/netinet/ip_icmp.c b/usr/src/sys/netinet/ip_icmp.c index 4bd9cb3400..288c60198a 100644 --- a/usr/src/sys/netinet/ip_icmp.c +++ b/usr/src/sys/netinet/ip_icmp.c @@ -1,4 +1,4 @@ -/* ip_icmp.c 4.9 81/11/29 */ +/* ip_icmp.c 4.10 81/12/03 */ #include "../h/param.h" #include "../h/systm.h" @@ -63,6 +63,7 @@ COUNT(ICMP_ERROR); nip = (struct ip *)mtod(m, struct ip *); *nip = *oip; icmp_reflect(nip); + return; /* * Discard mbufs of original datagram @@ -82,6 +83,7 @@ icmp_input(m) int hlen = ip->ip_hl << 2; int icmplen = ip->ip_len - hlen; int i; + extern u_char ip_protox[]; COUNT(ICMP_INPUT); /* @@ -113,7 +115,7 @@ COUNT(ICMP_INPUT); */ if (icmplen < ICMP_ADVLENMIN || icmplen < ICMP_ADVLEN(icp)) goto free; - icmp_ctlinput(ip); + (*protosw[ip_protox[ip->ip_p]].pr_ctlinput)(m); goto free; case ICMP_ECHO: @@ -182,17 +184,12 @@ COUNT(ICMP_SEND); (void) ip_output(dtom(ip), (struct mbuf *)0); } -/* - * Advise a higher level protocol of a problem reported by - * a gateway or another host. - */ -icmp_ctlinput(ip) - struct ip *ip; +icmp_ctlinput(m) + struct mbuf *m; { - extern u_char ip_protox[]; /* XXX */ COUNT(ICMP_CTLINPUT); - (*protosw[ip_protox[ip->ip_p]].pr_ctlinput)(ip); + m_freem(m); } /* diff --git a/usr/src/sys/netinet/ip_icmp.h b/usr/src/sys/netinet/ip_icmp.h index 63a6e0ea50..239a252a81 100644 --- a/usr/src/sys/netinet/ip_icmp.h +++ b/usr/src/sys/netinet/ip_icmp.h @@ -1,4 +1,4 @@ -/* ip_icmp.h 4.2 81/11/18 */ +/* ip_icmp.h 4.3 81/12/03 */ /* * Interface Control Message Protocol Definitions. @@ -76,8 +76,8 @@ struct icmp { #define ICMP_TIMXCEED 11 /* time exceeded, code: */ #define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */ #define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */ +#define ICMP_PARAMPROB 12 /* ip header bad */ #define ICMP_TSTAMP 13 /* timestamp request */ #define ICMP_TSTAMPREPLY 14 /* timestamp reply */ #define ICMP_IREQ 15 /* information request */ #define ICMP_IREQREPLY 16 /* information reply */ -#define ICMP_PARAMPROB 12 /* ip header bad */ diff --git a/usr/src/sys/netinet/ip_input.c b/usr/src/sys/netinet/ip_input.c index f9aa3aec3b..288c269d64 100644 --- a/usr/src/sys/netinet/ip_input.c +++ b/usr/src/sys/netinet/ip_input.c @@ -1,4 +1,4 @@ -/* ip_input.c 1.21 81/12/02 */ +/* ip_input.c 1.22 81/12/03 */ #include "../h/param.h" #include "../h/systm.h" @@ -17,7 +17,7 @@ u_char ip_protox[IPPROTO_MAX]; /* - * Ip initialization: fill in IP protocol switch table. + * IP initialization: fill in IP protocol switch table. * All protocols not implemented in kernel go to raw IP protocol handler. */ ip_init() diff --git a/usr/src/sys/netinet/tcp_fsm.h b/usr/src/sys/netinet/tcp_fsm.h index b2980781a8..81ccc2beaa 100644 --- a/usr/src/sys/netinet/tcp_fsm.h +++ b/usr/src/sys/netinet/tcp_fsm.h @@ -1,4 +1,4 @@ -/* tcp_fsm.h 4.9 81/11/26 */ +/* tcp_fsm.h 4.10 81/12/03 */ /* * TCP FSM state definitions. @@ -30,7 +30,8 @@ /* * Flags used when sending segments in tcp_output. * Basic flags (TH_RST,TH_ACK,TH_SYN,TH_FIN) are totally - * determined by state. + * determined by state, with the proviso that TH_FIN is sent only + * if all data queued for output is included in the segment. */ u_char tcp_outflags[TCP_NSTATES] = { TH_RST|TH_ACK, 0, TH_SYN, TH_SYN|TH_ACK, diff --git a/usr/src/sys/netinet/tcp_input.c b/usr/src/sys/netinet/tcp_input.c index 44f04bf6f8..1849a50245 100644 --- a/usr/src/sys/netinet/tcp_input.c +++ b/usr/src/sys/netinet/tcp_input.c @@ -1,4 +1,4 @@ -/* tcp_input.c 1.34 81/12/02 */ +/* tcp_input.c 1.35 81/12/03 */ #include "../h/param.h" #include "../h/systm.h" diff --git a/usr/src/sys/netinet/tcp_subr.c b/usr/src/sys/netinet/tcp_subr.c index 9cb31d355a..701f53a9cf 100644 --- a/usr/src/sys/netinet/tcp_subr.c +++ b/usr/src/sys/netinet/tcp_subr.c @@ -1,4 +1,4 @@ -/* tcp_subr.c 4.5 81/12/02 */ +/* tcp_subr.c 4.6 81/12/03 */ #include "../h/param.h" #include "../h/systm.h" diff --git a/usr/src/sys/netinet/tcp_usrreq.c b/usr/src/sys/netinet/tcp_usrreq.c index 90f17cce79..b1374cdbb8 100644 --- a/usr/src/sys/netinet/tcp_usrreq.c +++ b/usr/src/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* tcp_usrreq.c 1.38 81/12/02 */ +/* tcp_usrreq.c 1.39 81/12/03 */ #include "../h/param.h" #include "../h/systm.h" @@ -89,6 +89,7 @@ COUNT(TCP_USRREQ); error = ENOBUFS; break; } + tp->t_template = tcp_template(tp); tp->t_inpcb = inp; inp->inp_ppcb = (caddr_t)tp; soisconnecting(so); diff --git a/usr/src/sys/netinet/udp_usrreq.c b/usr/src/sys/netinet/udp_usrreq.c index 70de8567eb..922e4cb849 100644 --- a/usr/src/sys/netinet/udp_usrreq.c +++ b/usr/src/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* udp_usrreq.c 4.13 81/12/02 */ +/* udp_usrreq.c 4.14 81/12/03 */ #include "../h/param.h" #include "../h/dir.h" @@ -248,13 +248,3 @@ COUNT(UDP_USRREQ); } return (0); } - -/*ARGSUSED*/ -udp_sense(m) - struct mbuf *m; -{ - -COUNT(UDP_SENSE); - printf("udp_sense\n"); - return (EOPNOTSUPP); -} diff --git a/usr/src/sys/vax/if/if_en.c b/usr/src/sys/vax/if/if_en.c index 9b6fa50387..e15236fa96 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.16 81/12/02 */ +/* if_en.c 4.17 81/12/03 */ #include "en.h" @@ -33,7 +33,7 @@ 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(); @@ -67,7 +67,7 @@ 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); @@ -96,14 +96,15 @@ enattach(ui) COUNT(ENATTACH); 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; es->es_if.if_init = eninit; + es->es_if.if_output = enoutput; es->es_if.if_ubareset = enreset; if_attach(&es->es_if); } @@ -118,12 +119,10 @@ enreset(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); } @@ -134,26 +133,28 @@ 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); + printf("en%d: can't initialize\n", unit); 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) + ENMTU) >> 1; + addr->en_istat = EN_IEN|EN_GO; + es->es_oactive = 1; enxint(unit); splx(s); } @@ -171,17 +172,14 @@ 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; @@ -230,23 +228,26 @@ restart: enxint(unit) int unit; { + register struct uba_device *ui = eninfo[unit]; + register struct en_softc *es = &en_softc[unit]; register struct endevice *addr; - register struct uba_device *ui; - register struct en_softc *es; COUNT(ENXINT); - ui = eninfo[unit]; - es = &en_softc[unit]; if (es->es_oactive == 0) return; addr = (struct endevice *)ui->ui_addr; - es = &en_softc[unit]; + 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_if.if_snd.ifq_head == 0) { + es->es_if.if_oerrors++; + if (es->es_ifuba.ifu_xtofree) { + m_freem(es->es_ifuba.ifu_xtofree); + es->es_ifuba.ifu_xtofree = 0; + } es->es_lastx = 0; return; } @@ -261,21 +262,29 @@ COUNT(ENXINT); encollide(unit) int unit; { - register struct en_softc *es; + register struct en_softc *es = &en_softc[unit]; COUNT(ENCOLLIDE); - es = &en_softc[unit]; es->es_if.if_collisions++; if (es->es_oactive == 0) return; + /* + * 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); 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); } /* @@ -290,20 +299,19 @@ 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; + 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 (addr->en_istat&EN_IERROR) { @@ -323,8 +331,9 @@ COUNT(ENRINT); 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; } else off = 0; @@ -353,8 +362,7 @@ COUNT(ENRINT); * 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). + * the two-byte type which is at the front of any trailer data. */ m = if_rubaget(&es->es_ifuba, len, off); if (off) { @@ -397,7 +405,7 @@ enoutput(ifp, m0, pf) dest = ip->ip_dst.s_addr >> 24; off = ip->ip_len - m->m_len; - if (off && off % 512 == 0 && m->m_off >= MMINOFF + 2) { + if (off > 0 && (off & 0x1ff) == 0 && m->m_off >= MMINOFF + 2) { type = ENPUP_TRAIL + (off>>9); m->m_off -= 2; m->m_len += 2; @@ -416,23 +424,23 @@ enoutput(ifp, m0, pf) return (0); } +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 == 0) { diff --git a/usr/src/sys/vax/if/if_en.h b/usr/src/sys/vax/if/if_en.h index 7cf6a1b34a..0a93d59cec 100644 --- a/usr/src/sys/vax/if/if_en.h +++ b/usr/src/sys/vax/if/if_en.h @@ -1,4 +1,4 @@ -/* if_en.h 4.2 81/12/02 */ +/* if_en.h 4.3 81/12/03 */ /* * Structure of a Ethernet header. @@ -11,8 +11,8 @@ struct en_header { #define ENPUP_PUPTYPE 0x0400 /* PUP protocol */ #define ENPUP_IPTYPE 0x0800 /* IP protocol */ -/* +/* * The ENPUP_NTRAILER packet types starting at ENPUP_TRAIL have * (type-ENPUP_TRAIL)*512 bytes of data followed * by a PUP type (as given above) and then the (variable-length) header. diff --git a/usr/src/sys/vax/if/if_uba.c b/usr/src/sys/vax/if/if_uba.c index d08870f3c3..9294c8c646 100644 --- a/usr/src/sys/vax/if/if_uba.c +++ b/usr/src/sys/vax/if/if_uba.c @@ -1,4 +1,4 @@ -/* if_uba.c 4.3 81/11/29 */ +/* if_uba.c 4.4 81/12/03 */ #include "../h/param.h" #include "../h/systm.h" @@ -40,15 +40,16 @@ if_ubainit(ifu, uban, hlen, nmr) COUNT(IF_UBAINIT); if (cp == 0) return (0); + ifu->ifu_hlen = hlen; ifu->ifu_uban = uban; ifu->ifu_uba = uba_hd[uban].uh_uba; ifu->ifu_r.ifrw_addr = cp + NBPG - hlen; ifu->ifu_w.ifrw_addr = ifu->ifu_r.ifrw_addr + (nmr + 1) * NBPG; - if (if_ubaalloc(ifu, &ifu->ifu_r) == 0) + if (if_ubaalloc(ifu, &ifu->ifu_r, nmr) == 0) goto bad; - if (if_ubaalloc(ifu, &ifu->ifu_w) == 0) + if (if_ubaalloc(ifu, &ifu->ifu_w, nmr) == 0) goto bad2; - for (i = 0; i < IF_NUBAMR; i++) + for (i = 0; i < nmr; i++) ifu->ifu_wmap[i] = ifu->ifu_w.ifrw_mr[i+1]; ifu->ifu_xswapd = 0; return (1); @@ -65,15 +66,16 @@ bad: * to minimize run-time overhead. */ static -if_ubaalloc(ifu, ifrw) +if_ubaalloc(ifu, ifrw, nmr) struct ifuba *ifu; register struct ifrw *ifrw; + int nmr; { register int info; COUNT(IF_UBAALLOC); info = - uballoc(ifu->ifu_uban, ifrw->ifrw_addr, IF_NUBAMR*NBPG + ifu->ifu_hlen, + uballoc(ifu->ifu_uban, ifrw->ifrw_addr, nmr*NBPG + ifu->ifu_hlen, UBA_NEED16|UBA_NEEDBDP); if (info == 0) return (0); @@ -99,10 +101,9 @@ if_rubaget(ifu, totlen, off0) register struct ifuba *ifu; int totlen, off0; { - register struct mbuf *m; + struct mbuf *top, **mp, *m; + int off = off0, len; register caddr_t cp; - struct mbuf **mp, *p, *top; - int len, off = off0; COUNT(IF_RUBAGET); @@ -118,45 +119,29 @@ COUNT(IF_RUBAGET); } else len = totlen; if (len >= CLSIZE) { + struct mbuf *p; struct pte *cpte, *ppte; - int i, x, *ip; + int x, *ip, i; MCLGET(p, 1); if (p == 0) goto nopage; m->m_len = CLSIZE; m->m_off = (int)p - (int)m; - if ((int)cp & CLOFF) + if (!claligned(cp)) goto copy; /* - * Cluster size data on cluster size boundary. - * Input by remapping newly allocated pages to - * UNIBUS, and taking pages with data already - * in them. - * - * Cpte is the pte of the virtual memory which - * is mapped to the UNIBUS, and ppte is the pte - * for the fresh pages. We switch the memory - * copies of these pte's, to make the allocated - * virtual memory contain the data (using the old - * physical pages). We have to rewrite - * the UNIBUS map so that the newly allocated - * pages will be used for the next UNIBUS read, - * and invalidate the kernel translations - * for the virtual addresses of the pages - * we are flipping. - * - * The idea here is that this is supposed - * to take less time than copying the data. + * Switch pages mapped to UNIBUS with new page p, + * as quick form of copy. Remap UNIBUS and invalidate. */ - cpte = &Mbmap[mtocl(cp)]; - ppte = &Mbmap[mtocl(p)]; + cpte = &Mbmap[mtocl(cp)*CLSIZE]; + ppte = &Mbmap[mtocl(p)*CLSIZE]; x = btop(cp - ifu->ifu_r.ifrw_addr); ip = (int *)&ifu->ifu_r.ifrw_mr[x+1]; for (i = 0; i < CLSIZE; i++) { struct pte t; - t = *ppte; *ppte = *cpte; *cpte = t; + t = *ppte; *ppte++ = *cpte; *cpte = t; *ip++ = cpte++->pg_pfnum|ifu->ifu_r.ifrw_proto; mtpr(TBIS, cp); @@ -176,6 +161,7 @@ nocopy: *mp = m; mp = &m->m_next; if (off) { + /* sort of an ALGOL-W style for statement... */ off += m->m_len; if (off == totlen) { cp = ifu->ifu_r.ifrw_addr + ifu->ifu_hlen; @@ -204,8 +190,8 @@ if_wubaput(ifu, m) register struct mbuf *mp; register caddr_t cp, dp; register int i; - int xswapd = ifu->ifu_xswapd; - int x; + int xswapd = 0; + int x, cc; COUNT(IF_WUBAPUT); ifu->ifu_xswapd = 0; @@ -214,29 +200,47 @@ COUNT(IF_WUBAPUT); dp = mtod(m, char *); if (claligned(cp) && claligned(dp)) { struct pte *pte; int *ip; - pte = &Mbmap[mtocl(dp)]; + pte = &Mbmap[mtocl(dp)*CLSIZE]; x = btop(cp - ifu->ifu_w.ifrw_addr); ip = (int *)&ifu->ifu_w.ifrw_mr[x + 1]; for (i = 0; i < CLSIZE; i++) *ip++ = ifu->ifu_w.ifrw_proto | pte++->pg_pfnum; - ifu->ifu_xswapd |= 1 << (x>>CLSHIFT); - } else + ifu->ifu_xswapd |= 1 << (x>>(CLSHIFT-PGSHIFT)); + mp = m->m_next; + m->m_next = ifu->ifu_xtofree; + ifu->ifu_xtofree = m; + cp += m->m_len; + } else { bcopy(mtod(m, caddr_t), cp, (unsigned)m->m_len); - cp += m->m_len; - MFREE(m, mp); /* XXX too soon! */ + cp += m->m_len; + MFREE(m, mp); + } m = mp; } + + /* + * Xswapd is the set of clusters we just mapped out. Ifu->ifu_xswapd + * is the set of clusters mapped out from before. We compute + * the number of clusters involved in this operation in x. + * Clusters mapped out before and involved in this operation + * should be unmapped so original pages will be accessed by the device. + */ + cc = cp - ifu->ifu_w.ifrw_addr; + x = ((cc - ifu->ifu_hlen) + CLBYTES - 1) >> CLSHIFT; xswapd &= ~ifu->ifu_xswapd; if (xswapd) while (i = ffs(xswapd)) { i--; + if (i >= x) + break; xswapd &= ~(1<ifu_w.ifrw_mr[i] = ifu->ifu_wmap[i]; i++; } } - return (cp - ifu->ifu_w.ifrw_addr); + ifu->ifu_xswapd |= xswapd; + return (cc); } diff --git a/usr/src/sys/vax/if/if_uba.h b/usr/src/sys/vax/if/if_uba.h index 549fa6919d..8d466f1e92 100644 --- a/usr/src/sys/vax/if/if_uba.h +++ b/usr/src/sys/vax/if/if_uba.h @@ -1,11 +1,11 @@ -/* if_uba.h 4.2 81/11/26 */ +/* if_uba.h 4.3 81/12/03 */ /* * Structure and routine definitions * for UNIBUS network interfaces. */ -#define IF_NUBAMR 6 +#define IF_MAXNUBAMR 10 /* * Each interface has one of these structures giving information * about UNIBUS resources held by the interface. @@ -29,6 +29,7 @@ */ struct ifuba { short ifu_uban; /* uba number */ + short ifu_hlen; /* local net header length */ struct uba_regs *ifu_uba; /* uba regs, in vm */ struct ifrw { int ifrw_info; /* value from ubaalloc */ @@ -37,14 +38,9 @@ struct ifuba { int ifrw_proto; /* map register prototype */ caddr_t ifrw_addr; /* virt addr of header */ } ifu_r, ifu_w; - struct pte ifu_wmap[IF_NUBAMR]; /* base pages for output */ - short ifu_hlen; -/* ifu_xswapd is set when we have swapped write pte's to do direct output */ -/* bit i of ifu_xswapd */ - short ifu_xswapd; /* bit map of pages swapped */ - int ifu_ierrors; - int ifu_oerrors; - int ifu_collisions; + struct pte ifu_wmap[IF_MAXNUBAMR]; /* base pages for output */ + short ifu_xswapd; /* mask of clusters swapped */ + struct mbuf *ifu_xtofree; /* pages being dma'd out */ }; #ifdef KERNEL diff --git a/usr/src/sys/vax/uba/ubareg.h b/usr/src/sys/vax/uba/ubareg.h index 7726060a3a..df02d4345a 100644 --- a/usr/src/sys/vax/uba/ubareg.h +++ b/usr/src/sys/vax/uba/ubareg.h @@ -1,4 +1,4 @@ -/* ubareg.h 4.25 81/12/02 */ +/* ubareg.h 4.26 81/12/03 */ /* * VAX UNIBUS adapter registers @@ -106,7 +106,7 @@ struct uba_regs #if defined(VAX780) && !defined(VAX750) #define UBAPURGE(uba, bdp) { \ if (cpu==VAX_780) { - UBA_PURGE780((uba), (bdp)); break; \ + UBA_PURGE780((uba), (bdp)); \ } \ } #endif -- 2.20.1