cltp_usrreq.c made separate file in conf/files
[unix-history] / usr / src / sys / netiso / tp_usrreq.c
index a01d32f..368d83d 100644 (file)
@@ -1,5 +1,5 @@
 /***********************************************************
 /***********************************************************
-               Copyright IBM Corporation 1987
+                               Copyright IBM Corporation 1987
 
                       All Rights Reserved
 
 
                       All Rights Reserved
 
@@ -29,7 +29,7 @@ SOFTWARE.
  *
  * $Header: tp_usrreq.c,v 5.4 88/11/18 17:29:18 nhall Exp $
  * $Source: /usr/argo/sys/netiso/RCS/tp_usrreq.c,v $
  *
  * $Header: tp_usrreq.c,v 5.4 88/11/18 17:29:18 nhall Exp $
  * $Source: /usr/argo/sys/netiso/RCS/tp_usrreq.c,v $
- *     @(#)tp_usrreq.c 7.4 (Berkeley) %G% *
+ *     @(#)tp_usrreq.c 7.8 (Berkeley) %G%
  *
  * tp_usrreq(), the fellow that gets called from most of the socket code.
  * Pretty straighforward.
  *
  * tp_usrreq(), the fellow that gets called from most of the socket code.
  * Pretty straighforward.
@@ -65,6 +65,8 @@ static char *rcsid = "$Header: tp_usrreq.c,v 5.4 88/11/18 17:29:18 nhall Exp $";
 #include "iso_errno.h"
 
 int tp_attach(), tp_driver();
 #include "iso_errno.h"
 
 int tp_attach(), tp_driver();
+int TNew;
+int TPNagle1, TPNagle2;
 
 #ifdef ARGO_DEBUG
 /*
 
 #ifdef ARGO_DEBUG
 /*
@@ -341,10 +343,10 @@ tp_sendoob(tpcb, so, xdata, outflags)
  */
 /*ARGSUSED*/
 ProtoHook
  */
 /*ARGSUSED*/
 ProtoHook
-tp_usrreq(so, req, m, nam, rightsp, controlp)
+tp_usrreq(so, req, m, nam, controlp)
        struct socket *so;
        u_int req;
        struct socket *so;
        u_int req;
-       struct mbuf *m, *nam, *rightsp, *controlp;
+       struct mbuf *m, *nam, *controlp;
 {      
        register struct tp_pcb *tpcb =  sototpcb(so);
        int s = splnet();
 {      
        register struct tp_pcb *tpcb =  sototpcb(so);
        int s = splnet();
@@ -487,8 +489,8 @@ tp_usrreq(so, req, m, nam, rightsp, controlp)
                }
                IFPERF(tpcb)
                        u_int lsufx, fsufx;
                }
                IFPERF(tpcb)
                        u_int lsufx, fsufx;
-                       lsufx = *(u_int *)(tpcb->tp_lsuffix);
-                       fsufx = *(u_int *)(tpcb->tp_fsuffix);
+                       lsufx = *(u_short *)(tpcb->tp_lsuffix);
+                       fsufx = *(u_short *)(tpcb->tp_fsuffix);
 
                        tpmeas( tpcb->tp_lref, 
                                TPtime_open | (tpcb->tp_xtd_format <<4 ), 
 
                        tpmeas( tpcb->tp_lref, 
                                TPtime_open | (tpcb->tp_xtd_format <<4 ), 
@@ -504,8 +506,8 @@ tp_usrreq(so, req, m, nam, rightsp, controlp)
                ENDDEBUG
                IFPERF(tpcb)
                        u_int lsufx, fsufx;
                ENDDEBUG
                IFPERF(tpcb)
                        u_int lsufx, fsufx;
-                       lsufx = *(u_int *)(tpcb->tp_lsuffix);
-                       fsufx = *(u_int *)(tpcb->tp_fsuffix);
+                       lsufx = *(u_short *)(tpcb->tp_lsuffix);
+                       fsufx = *(u_short *)(tpcb->tp_fsuffix);
 
                        tpmeas( tpcb->tp_lref, TPtime_open, 
                                &time, lsufx, fsufx, tpcb->tp_fref);
 
                        tpmeas( tpcb->tp_lref, TPtime_open, 
                                &time, lsufx, fsufx, tpcb->tp_fref);
@@ -591,12 +593,13 @@ tp_usrreq(so, req, m, nam, rightsp, controlp)
                 */
                {
                        register struct mbuf *n = m;
                 */
                {
                        register struct mbuf *n = m;
-                       register int len=0;
                        register struct sockbuf *sb = &so->so_snd;
                        int     maxsize = tpcb->tp_l_tpdusize 
                                    - tp_headersize(DT_TPDU_type, tpcb)
                                    - (tpcb->tp_use_checksum?4:0) ;
                        int totlen = n->m_pkthdr.len;
                        register struct sockbuf *sb = &so->so_snd;
                        int     maxsize = tpcb->tp_l_tpdusize 
                                    - tp_headersize(DT_TPDU_type, tpcb)
                                    - (tpcb->tp_use_checksum?4:0) ;
                        int totlen = n->m_pkthdr.len;
+                       int     mbufcnt = 0;
+                       struct mbuf *nn;
 
                        /*
                         * Could have eotsdu and no data.(presently MUST have
 
                        /*
                         * Could have eotsdu and no data.(presently MUST have
@@ -614,7 +617,7 @@ tp_usrreq(so, req, m, nam, rightsp, controlp)
                        IFDEBUG(D_SYSCALL)
                                printf(
                                "PRU_SEND: eot %d before sbappend 0x%x len 0x%x to sb @ 0x%x\n",
                        IFDEBUG(D_SYSCALL)
                                printf(
                                "PRU_SEND: eot %d before sbappend 0x%x len 0x%x to sb @ 0x%x\n",
-                                       eotsdu, m,len, sb);
+                                       eotsdu, m, totlen, sb);
                                dump_mbuf(sb->sb_mb, "so_snd.sb_mb");
                                dump_mbuf(m, "m : to be added");
                        ENDDEBUG
                                dump_mbuf(sb->sb_mb, "so_snd.sb_mb");
                                dump_mbuf(m, "m : to be added");
                        ENDDEBUG
@@ -622,19 +625,61 @@ tp_usrreq(so, req, m, nam, rightsp, controlp)
                         * Pre-packetize the data in the sockbuf
                         * according to negotiated mtu.  Do it here
                         * where we can safely wait for mbufs.
                         * Pre-packetize the data in the sockbuf
                         * according to negotiated mtu.  Do it here
                         * where we can safely wait for mbufs.
+                        *
+                        * This presumes knowledge of sockbuf conventions.
                         */
                         */
-                       while (n->m_pkthdr.len > maxsize) {
-                               struct mbuf *nn
-                                           = m_copym(n, 0, maxsize, M_WAIT);
+                       if (n = sb->sb_mb)
+                               while (n->m_act)
+                                       n = n->m_act;
+                       if ((nn = n) && n->m_pkthdr.len < maxsize) {
+                               u_int space = maxsize - n->m_pkthdr.len;
+
+                               do {
+                                       if (n->m_flags & M_EOR)
+                                               goto on1;
+                               } while (n->m_next && (n = n->m_next));
+                               if (totlen <= space) {
+                                       TPNagle1++;
+                                       n->m_next = m; 
+                                       nn->m_pkthdr.len += totlen;
+                                       while (n = n->m_next)
+                                               sballoc(sb, n);
+                                       if (eotsdu)
+                                               nn->m_flags |= M_EOR; 
+                                       goto on2; 
+                               } else {
+                                       /*
+                                        * Can't sleep here, because when you wake up
+                                        * packet you want to attach to may be gone!
+                                        */
+                                       if (TNew && (n->m_next = m_copym(m, 0, space, M_NOWAIT))) {
+                                               nn->m_pkthdr.len += space;
+                                               TPNagle2++;
+                                               while (n = n->m_next)
+                                                       sballoc(sb, n);
+                                               m_adj(m, space);
+                                       }
+                               }
+                       }       
+       on1:    mbufcnt++;
+                       for (n = m; n->m_pkthdr.len > maxsize;) {
+                               nn = m_copym(n, 0, maxsize, M_WAIT);
                                sbappendrecord(sb, nn);
                                m_adj(n, maxsize);
                                sbappendrecord(sb, nn);
                                m_adj(n, maxsize);
+                               mbufcnt++;
                        }
                        }
-                       sbappendrecord(sb, n);
-                       if (eotsdu)     /* This presumes knowledge of sbappendrecord() */
+                       if (eotsdu)
                                n->m_flags |= M_EOR;
                                n->m_flags |= M_EOR;
+                       sbappendrecord(sb, n);
+       on2:    
+                       IFTRACE(D_DATA)
+                               tptraceTPCB(TPPTmisc,
+                               "SEND BF: maxsize totlen mbufcnt eotsdu",
+                                       maxsize, totlen, mbufcnt, eotsdu);
+                       ENDTRACE
                        IFDEBUG(D_SYSCALL)
                        IFDEBUG(D_SYSCALL)
-                               printf("PRU_SEND: eot %d after sbappend 0x%x len 0x%x\n",
-                                       eotsdu, n, len);
+                               printf("PRU_SEND: eot %d after sbappend 0x%x mbufcnt 0x%x\n",
+                                       eotsdu, n, mbufcnt);
                                dump_mbuf(sb->sb_mb, "so_snd.sb_mb");
                        ENDDEBUG
                        error = DoEvent(T_DATA_req); 
                                dump_mbuf(sb->sb_mb, "so_snd.sb_mb");
                        ENDDEBUG
                        error = DoEvent(T_DATA_req); 
@@ -686,6 +731,18 @@ tp_usrreq(so, req, m, nam, rightsp, controlp)
        splx(s);
        return error;
 }
        splx(s);
        return error;
 }
+tp_ltrace(so, uio)
+struct socket *so;
+struct uio *uio;
+{
+       IFTRACE(D_DATA)
+               register struct tp_pcb *tpcb =  sototpcb(so);
+               if (tpcb) {
+                       tptraceTPCB(TPPTmisc, "sosend so resid iovcnt", so,
+                               uio->uio_resid, uio->uio_iovcnt, 0);
+               }
+       ENDTRACE
+}
 
 tp_confirm(tpcb)
 register struct tp_pcb *tpcb;
 
 tp_confirm(tpcb)
 register struct tp_pcb *tpcb;
@@ -725,7 +782,7 @@ tp_snd_control(m0, so, data)
                                *data = 0;
                        }
                        m0 = 0;
                                *data = 0;
                        }
                        m0 = 0;
-                       error = tp_usrreq(so, PRU_DISCONNECT, m0, (caddr_t)0, m0, m0);
+                       error = tp_usrreq(so, PRU_DISCONNECT, m0, (caddr_t)0, m0);
                }
        }
        return error;
                }
        }
        return error;