Annotation of XNU/bsd/netat/adsp_reset.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * The contents of this file constitute Original Code as defined in and
                      7:  * are subject to the Apple Public Source License Version 1.1 (the
                      8:  * "License").  You may not use this file except in compliance with the
                      9:  * License.  Please obtain a copy of the License at
                     10:  * http://www.apple.com/publicsource and read it before using this file.
                     11:  * 
                     12:  * This Original Code and all software distributed under the License are
                     13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     17:  * License for the specific language governing rights and limitations
                     18:  * under the License.
                     19:  * 
                     20:  * @APPLE_LICENSE_HEADER_END@
                     21:  */
                     22: /* 
                     23:  * Reset.c
                     24:  *
                     25:  * From  v01.15 07/11/90 mbs
                     26:  */
                     27: /*
                     28:  * Change log:
                     29:  *   06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen)
                     30:  *    Modified for MP, 1996 by Tuyen Nguyen
                     31:  *   Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
                     32:  */
                     33: 
                     34: #include <sys/errno.h>
                     35: #include <sys/types.h>
                     36: #include <sys/param.h>
                     37: #include <machine/spl.h>
                     38: #include <sys/systm.h>
                     39: #include <sys/kernel.h>
                     40: #include <sys/proc.h>
                     41: #include <sys/filedesc.h>
                     42: #include <sys/fcntl.h>
                     43: #include <sys/mbuf.h>
                     44: #include <sys/socket.h>
                     45: #include <sys/time.h>
                     46: 
                     47: #include <netat/sysglue.h>
                     48: #include <netat/appletalk.h>
                     49: #include <netat/at_pcb.h>
                     50: #include <netat/debug.h>
                     51: #include <netat/adsp.h>
                     52: #include <netat/adsp_internal.h>
                     53: 
                     54: /*
                     55:  * RXFReset
                     56:  *
                     57:  * We just got a Forward Reset Packet.
                     58:  *
                     59:  * Called with interrupts OFF
                     60:  *
                     61:  * INPUTS:
                     62:  *     stream pointer
                     63:  *     Pointer to ADSP header,
                     64:  * OUTPUTS:
                     65:  *     Returns 1 if packet was ignored
                     66:  */
                     67: int RXFReset(sp, f)            /* (CCBPtr sp, ADSP_FRAMEPtr f) */
                     68:     CCBPtr sp;
                     69:     ADSP_FRAMEPtr f;
                     70: {
                     71:     unsigned int pktFirstByteSeq;
                     72:     unsigned int hi;
                     73:     register gbuf_t *mp;
                     74:     register struct adspcmd *pb;
                     75:     int s;
                     76: 
                     77:     ATDISABLE(s, sp->lock);
                     78:     pktFirstByteSeq = netdw(UAL_VALUE(f->pktFirstByteSeq));
                     79:     
                     80:     hi = sp->recvSeq + CalcRecvWdw(sp);
                     81: 
                     82:     /*
                     83:      * Must do this with interrupts OFF
                     84:      */
                     85:     if (BETWEEN(sp->recvSeq, pktFirstByteSeq, hi)) /* Is this acceptable? */
                     86:     {
                     87:        sp->recvSeq = pktFirstByteSeq;
                     88:        while (mp = sp->rbuf_mb) { /* clear the receive queue */
                     89:            sp->rbuf_mb = gbuf_next(mp);
                     90:            gbuf_freem(mp);
                     91:        }
                     92:        if (sp->crbuf_mb) {
                     93:            gbuf_freem(sp->crbuf_mb);
                     94:            sp->crbuf_mb = 0;
                     95:        }
                     96:        sp->rData = 0;
                     97:        sp->rbufFull = 0;
                     98:        sp->userFlags |= eFwdReset; /* Set forward reset received Flag */
                     99: 
                    100:        mp = gbuf_alloc(sizeof(struct adspcmd), PRI_HI);
                    101:        pb = (struct adspcmd *)gbuf_rptr(mp);
                    102:        gbuf_winc(mp,sizeof(struct adspcmd));
                    103:        pb->ioc = 0;
                    104:        pb->mp = mp;
                    105: 
                    106:        pb->csCode = dspReset;
                    107:        pb->ioResult = 0;
                    108:        completepb(sp, pb);
                    109:        sp->userFlags &= ~eFwdReset;
                    110:     }
                    111: 
                    112:     if (LTE(pktFirstByteSeq, hi)) {
                    113:        sp->sendCtl |= B_CTL_FRESETACK; /* Ack it if it's OK, or a duplicate */
                    114:        sp->callSend = 1;
                    115:     }
                    116: 
                    117:     ATENABLE(s, sp->lock);
                    118:     return 0;
                    119: }
                    120: 
                    121: 
                    122: /*
                    123:  * RXFResetAck
                    124:  *
                    125:  * We just got a Forward Reset Acknowledgement packet
                    126:  *
                    127:  * Called with interrupts OFF
                    128:  *
                    129:  * INPUTS:
                    130:  *       stream pointer
                    131:  *    Pointer to ADSP header,
                    132:  * OUTPUTS:
                    133:  *    Returns 1 if packet was ignored
                    134:  */
                    135: int RXFResetAck(sp, f)         /* (CCBPtr sp, ADSP_FRAMEPtr f) */
                    136:     CCBPtr sp;
                    137:     ADSP_FRAMEPtr f;
                    138: {
                    139:     unsigned int  PktNextRecvSeq;
                    140:     int s;
                    141: 
                    142:     if (sp->frpb == 0)         /* Not expecting frwd reset Ack packet */
                    143:        return 1;
                    144: 
                    145:     ATDISABLE(s, sp->lock);
                    146:     PktNextRecvSeq = netdw(UAL_VALUE(f->pktNextRecvSeq));
                    147: 
                    148:     if (BETWEEN(sp->sendSeq, PktNextRecvSeq, sp->sendWdwSeq+1)) {
                    149:        struct adspcmd *pb;
                    150: 
                    151:        RemoveTimerElem(&adspGlobal.fastTimers, &sp->ResetTimer); 
                    152:                                /* Remove timer */
                    153: 
                    154:        /*
                    155:         * Interrupts are OFF here while we muck with the linked list
                    156:         */
                    157:        pb = sp->frpb;          /* Unlink copy of user's parameter block */
                    158:        sp->frpb = (struct adspcmd *)pb->qLink;
                    159: 
                    160:        pb->ioResult = 0;
                    161:        completepb(sp, pb);     /* complete(pb, 0); */
                    162:                
                    163:        if (sp->state == sClosing) /* this ack may allow us to close... */
                    164:            CheckOkToClose(sp);
                    165:                        
                    166:        if (sp->frpb)           /* Another to send? */
                    167:        {
                    168:            sp->callSend = 1;
                    169:            sp->sendCtl |= B_CTL_FRESET;
                    170:        }
                    171:     }
                    172: 
                    173:     ATENABLE(s, sp->lock);
                    174:     return 0;
                    175: }
                    176: 
                    177: 
                    178: /*
                    179:  * dspReset
                    180:  * 
                    181:  * INPUTS:
                    182:  *     --> ccbRefNum           refnum of connection end
                    183:  *
                    184:  * OUTPUTS:
                    185:  *     none
                    186:  *
                    187:  * ERRORS:
                    188:  *     errRefNum               bad connection refnum
                    189:  *     errState                connection is not open
                    190:  *     errAborted              request aborted by Remove or Close call
                    191:  */
                    192: int adspReset(sp, pb)          /* (DSPPBPtr pb) */
                    193:     CCBPtr sp;
                    194:     struct adspcmd *pb;
                    195: {
                    196:     int s;
                    197:     register gbuf_t *mp;
                    198:     register struct adspcmd *rpb;
                    199:        
                    200:     if (sp == 0) {
                    201:        pb->ioResult = errRefNum;
                    202:        return EINVAL;
                    203:     }
                    204: 
                    205:     if (sp->state != sOpen) {
                    206:        pb->ioResult = errState;
                    207:        return EINVAL;
                    208:     }
                    209:        
                    210:     ATDISABLE(s, sp->lock);
                    211: 
                    212:     while (mp = sp->sbuf_mb) { /* clear the send queue */
                    213:        sp->sbuf_mb = gbuf_next(mp);
                    214:        gbuf_freem(mp);
                    215:     }
                    216:     if (sp->csbuf_mb) {
                    217:        gbuf_freem(sp->csbuf_mb);
                    218:        sp->csbuf_mb = 0;
                    219:     }
                    220:     sp->sData = 0;
                    221:     sp->writeFlush = 0;
                    222:     sp->sendCtl |= B_CTL_FRESET;
                    223: 
                    224:     sp->firstRtmtSeq = sp->sendSeq; /* Reset sequence #'s */
                    225:     if (mp = gbuf_copym(pb->mp)) {     /* copy the parameter block */
                    226:            adspioc_ack(0, pb->ioc, pb->gref); /* release user */
                    227:            rpb = (struct adspcmd *)gbuf_rptr(mp);
                    228:            rpb->ioc = 0;               /* unlink copy */
                    229:            rpb->mp = mp;
                    230: 
                    231:            qAddToEnd(&sp->frpb, rpb); 
                    232:                                /* Hold on to pb (will be completed when */
                    233:                                /* forward reset ack is received). */
                    234:     } else {                   /* assume it will work... but keep no
                    235:                                 * bookkeeping for it.  yetch! */
                    236:            adspioc_ack(0, pb->ioc, pb->gref);
                    237:     }
                    238:     ATENABLE(s, sp->lock);
                    239: 
                    240:     CheckSend(sp);
                    241:     return STR_IGNORE;
                    242: 
                    243: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.