The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/netccitt/hd_output.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: hd_output.c,v 1.15 2003/08/07 16:33:00 agc Exp $       */
    2 
    3 /*
    4  * Copyright (c) 1990, 1993
    5  *      The Regents of the University of California.  All rights reserved.
    6  *
    7  * This code is derived from software contributed to Berkeley by
    8  * the Laboratory for Computation Vision and the Computer Science Department
    9  * of the University of British Columbia.
   10  *
   11  * Redistribution and use in source and binary forms, with or without
   12  * modification, are permitted provided that the following conditions
   13  * are met:
   14  * 1. Redistributions of source code must retain the above copyright
   15  *    notice, this list of conditions and the following disclaimer.
   16  * 2. Redistributions in binary form must reproduce the above copyright
   17  *    notice, this list of conditions and the following disclaimer in the
   18  *    documentation and/or other materials provided with the distribution.
   19  * 3. Neither the name of the University nor the names of its contributors
   20  *    may be used to endorse or promote products derived from this software
   21  *    without specific prior written permission.
   22  *
   23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   33  * SUCH DAMAGE.
   34  *
   35  *      @(#)hd_output.c 8.1 (Berkeley) 6/10/93
   36  */
   37 
   38 /*
   39  * Copyright (c) 1984 University of British Columbia.
   40  *
   41  * This code is derived from software contributed to Berkeley by
   42  * the Laboratory for Computation Vision and the Computer Science Department
   43  * of the University of British Columbia.
   44  *
   45  * Redistribution and use in source and binary forms, with or without
   46  * modification, are permitted provided that the following conditions
   47  * are met:
   48  * 1. Redistributions of source code must retain the above copyright
   49  *    notice, this list of conditions and the following disclaimer.
   50  * 2. Redistributions in binary form must reproduce the above copyright
   51  *    notice, this list of conditions and the following disclaimer in the
   52  *    documentation and/or other materials provided with the distribution.
   53  * 3. All advertising materials mentioning features or use of this software
   54  *    must display the following acknowledgement:
   55  *      This product includes software developed by the University of
   56  *      California, Berkeley and its contributors.
   57  * 4. Neither the name of the University nor the names of its contributors
   58  *    may be used to endorse or promote products derived from this software
   59  *    without specific prior written permission.
   60  *
   61  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   62  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   63  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   64  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   65  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   66  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   67  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   68  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   69  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   70  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   71  * SUCH DAMAGE.
   72  *
   73  *      @(#)hd_output.c 8.1 (Berkeley) 6/10/93
   74  */
   75 
   76 #include <sys/cdefs.h>
   77 __KERNEL_RCSID(0, "$NetBSD: hd_output.c,v 1.15 2003/08/07 16:33:00 agc Exp $");
   78 
   79 #include <sys/param.h>
   80 #include <sys/systm.h>
   81 #include <sys/mbuf.h>
   82 #include <sys/domain.h>
   83 #include <sys/socket.h>
   84 #include <sys/syslog.h>
   85 #include <sys/protosw.h>
   86 #include <sys/errno.h>
   87 #include <sys/time.h>
   88 #include <sys/kernel.h>
   89 
   90 #include <net/if.h>
   91 
   92 #include <netccitt/hdlc.h>
   93 #include <netccitt/hd_var.h>
   94 #include <netccitt/x25.h>
   95 #include <netccitt/pk_extern.h>
   96 
   97 #include <machine/stdarg.h>
   98 
   99 /*
  100  *      HDLC OUTPUT INTERFACE
  101  *
  102  *      This routine is called when the X.25 packet layer output routine
  103  *      has a information frame (iframe)  to write.   It is  also called
  104  *      by the input and control routines of the HDLC layer.
  105  */
  106 
  107 int
  108 #if __STDC__
  109 hd_output(struct mbuf *m0, ...)
  110 #else
  111 hd_output(m0, va_alist)
  112         struct mbuf    *m0;
  113         va_dcl
  114 #endif
  115 {
  116         struct hdcb *hdp;
  117         struct mbuf *m = m0;
  118         int             len;
  119         va_list ap;
  120 
  121         va_start(ap, m0);
  122         hdp = va_arg(ap, struct hdcb *);
  123         va_end(ap);
  124 
  125         if (m == NULL)
  126                 panic("hd_output");
  127         if ((m->m_flags & M_PKTHDR) == 0)
  128                 panic("hd_output 2");
  129 
  130         if (hdp->hd_state != ABM) {
  131                 m_freem(m);
  132                 return 0;
  133         }
  134         /*
  135          * Make room for the hdlc header either by prepending
  136          * another mbuf, or by adjusting the offset and length
  137          * of the first mbuf in the mbuf chain.
  138          */
  139 
  140         M_PREPEND(m, HDHEADERLN, M_DONTWAIT);
  141         if (m == NULL)
  142                 return 0;
  143         for (len = 0; m; m = m->m_next)
  144                 len += m->m_len;
  145         m = m0;
  146         m->m_pkthdr.len = len;
  147 
  148         hd_append(&hdp->hd_txq, m);
  149         hd_start(hdp);
  150         return 0;
  151 }
  152 
  153 void
  154 hd_start(hdp)
  155         struct hdcb *hdp;
  156 {
  157         struct mbuf *m;
  158 
  159         /*
  160          * The iframe is only transmitted if all these conditions are FALSE.
  161          * The iframe remains queued (hdp->hd_txq) however and will be
  162          * transmitted as soon as these conditions are cleared.
  163          */
  164 
  165         while (!(hdp->hd_condition & (TIMER_RECOVERY_CONDITION |
  166                                      REMOTE_RNR_CONDITION | REJ_CONDITION))) {
  167                 if (hdp->hd_vs ==
  168                         (hdp->hd_lastrxnr + hdp->hd_xcp->xc_lwsize) % MODULUS) {
  169 
  170                         /*
  171                          * We have now exceeded the  maximum  number  of
  172                          * outstanding iframes. Therefore,  we must wait
  173                          * until  at least  one is acknowledged if this
  174                          * condition  is not  turned off before we are
  175                          * requested to write another iframe.
  176                          */
  177                         hdp->hd_window_condition++;
  178                         break;
  179                 }
  180                 /* hd_remove top iframe from transmit queue. */
  181                 if ((m = hd_remove(&hdp->hd_txq)) == NULL)
  182                         break;
  183 
  184                 hd_send_iframe(hdp, m, POLLOFF);
  185         }
  186 }
  187 
  188 /*
  189  * This procedure is passed a buffer descriptor for an iframe. It builds the
  190  * rest of the control part of the frame and then writes it out.  It also
  191  * starts the  acknowledgement  timer and keeps  the iframe in the Retransmit
  192  * queue (Retxq) just in case  we have to do this again.
  193  * 
  194  * Note: This routine is also called from hd_input.c when retransmission of old
  195  * frames is required.
  196  */
  197 void
  198 hd_send_iframe(hdp, buf, poll_bit)
  199         struct hdcb *hdp;
  200         struct mbuf *buf;
  201         int             poll_bit;
  202 {
  203         struct Hdlc_iframe *iframe;
  204         struct mbuf    *m;
  205 
  206         KILL_TIMER(hdp);
  207 
  208         if (buf == 0) {
  209                 printf("hd_send_iframe: zero arg\n");
  210 #ifdef HDLCDEBUG
  211                 hd_status(hdp);
  212                 hd_dumptrace(hdp);
  213 #endif
  214                 hdp->hd_vs = (hdp->hd_vs + 7) % MODULUS;
  215                 return;
  216         }
  217         iframe = mtod(buf, struct Hdlc_iframe *);
  218 
  219         iframe->hdlc_0 = 0;
  220         iframe->nr = hdp->hd_vr;
  221         iframe->pf = poll_bit;
  222         iframe->ns = hdp->hd_vs;
  223         iframe->address = ADDRESS_B;
  224         hdp->hd_lasttxnr = hdp->hd_vr;
  225         hdp->hd_rrtimer = 0;
  226 
  227         if (hdp->hd_vs == hdp->hd_retxqi) {
  228                 /* Check for retransmissions. */
  229                 /* Put iframe only once in the Retransmission queue. */
  230                 hdp->hd_retxq[(u_char) hdp->hd_retxqi] = buf;
  231                 hdp->hd_retxqi = (hdp->hd_retxqi + 1) % MODULUS;
  232                 hdp->hd_iframes_out++;
  233         }
  234         hdp->hd_vs = (hdp->hd_vs + 1) % MODULUS;
  235 
  236         hd_trace(hdp, TX, buf);
  237 
  238         /* Write buffer on device. */
  239         m = hdp->hd_dontcopy ? buf : m_copy(buf, 0, (int) M_COPYALL);
  240         if (m == 0) {
  241                 printf("hdlc: out of mbufs\n");
  242                 return;
  243         }
  244         (*hdp->hd_output) (m, hdp);
  245         SET_TIMER(hdp);
  246 }
  247 
  248 int
  249 #if __STDC__
  250 hd_ifoutput(struct mbuf *m, ...)
  251 #else
  252 hd_ifoutput(m, va_alist)
  253         struct mbuf *m;
  254         va_dcl
  255 #endif
  256 {
  257         struct hdcb *hdp;
  258         struct ifnet *ifp;
  259         int             s = splnet();
  260         va_list ap;
  261 
  262         va_start(ap, m);
  263         hdp = va_arg(ap, struct hdcb *);
  264         va_end(ap);
  265         ifp = hdp->hd_ifp;
  266 
  267         /*
  268          * Queue message on interface, and start output if interface
  269          * not yet active.
  270          */
  271 
  272         if (IF_QFULL(&ifp->if_snd)) {
  273                 IF_DROP(&ifp->if_snd);
  274 #if 0
  275                 printf("%s: HDLC says OK to send but queue full, may hang\n",
  276                     ifp->if_xname);
  277 #endif
  278                 m_freem(m);
  279         } else {
  280                 IF_ENQUEUE(&ifp->if_snd, m);
  281                 if ((ifp->if_flags & IFF_OACTIVE) == 0)
  282                         (*ifp->if_start) (ifp);
  283         }
  284         splx(s);
  285         return 0;
  286 }
  287 
  288 
  289 /*
  290  * This routine gets control when the timer expires because we have not
  291  * received an acknowledgement for a iframe.
  292  */
  293 
  294 void
  295 hd_resend_iframe(hdp)
  296         struct hdcb *hdp;
  297 {
  298 
  299         if (hdp->hd_retxcnt++ < hd_n2) {
  300                 if (!(hdp->hd_condition & TIMER_RECOVERY_CONDITION)) {
  301                         hdp->hd_xx = hdp->hd_vs;
  302                         hdp->hd_condition |= TIMER_RECOVERY_CONDITION;
  303                 }
  304                 hdp->hd_vs = hdp->hd_lastrxnr;
  305                 hd_send_iframe(hdp, hdp->hd_retxq[(u_char)hdp->hd_vs], POLLON);
  306         } else {
  307                 /*
  308                  * At this point we have not received a RR even after N2
  309                  * retries - attempt to reset link.
  310                  */
  311 
  312                 hd_initvars(hdp);
  313                 hd_writeinternal(hdp, SABM, POLLOFF);
  314                 hdp->hd_state = WAIT_UA;
  315                 SET_TIMER(hdp);
  316                 hd_message(hdp, "Timer recovery failed: link down");
  317                 (void) pk_ctlinput(PRC_LINKDOWN,
  318                                    (struct sockaddr *)hdp->hd_pkp, NULL);
  319         }
  320 }

Cache object: e1d9a205f8805ab00e4eec8c9e95c415


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.