eni_receive.c
来自「基于组件方式开发操作系统的OSKIT源代码」· C语言 代码 · 共 872 行 · 第 1/2 页
C
872 行
DMA_JK; dma[j++] = 0; /* * Reset PDU length to zero */ KB_PLENSET ( m, 0 ); /* * Count some statistics */ /* * Count this as dropped cells */ if ( aal5 ) { eup->eu_stats.eni_st_aal5.aal5_drops += n_cells; eup->eu_stats.eni_st_aal5.aal5_pdu_drops++; } else eup->eu_stats.eni_st_aal0.aal0_drops += n_cells; /* * Drop it */ goto send_dma; } } /* * If necessary, skip AAL layer */ if ( aal5 ) { dma[j++] = (((rdptr + n_cells*WORDS_PER_CELL + 1) & (mask-1)) << DMA_COUNT_SHIFT) | (vcc << DMA_VCC_SHIFT) | DMA_JK; dma[j++] = 0; } } else { /* * We failed to get an initial buffer. Since we * haven't changed anything for this PDU yet and the * PDU is still valid, exit now and try to service it * next time around. We're not very likely to get * another buffer right now anyways. */ eup->eu_stats.eni_st_drv.drv_rv_nobufs++;#ifdef DO_LOG log ( LOG_ERR,"eni_do_service: No buffers available. Exiting without servicing service list.\n" );#endif /* * Clear the IN_SERVICE indicator for this VCC */ vct->vci_control &= ~VCI_IN_SERVICE; return; }send_dma: /* * Set the end bit on the last DMA for this PDU */ dma[j-2] |= DMA_END_BIT; /* * Where are the current DMA pointers */ dma_rd = eup->eu_midway[MIDWAY_RX_RD]; dma_wr = eup->eu_midway[MIDWAY_RX_WR]; /* * Check how much space is available */ if ( dma_rd == dma_wr ) dma_avail = DMA_LIST_SIZE; else dma_avail = ( dma_rd + DMA_LIST_SIZE - dma_wr ) & (DMA_LIST_SIZE-1); /* * Check for queue full or wrap past write okay pointer */ if ( dma_avail < j || ( dma_wr + j > eup->eu_rxdmawr + DMA_LIST_SIZE ) ) { /* * There's no room in the DMA list to insert * this request. Since we haven't changed anything * yet and the PDU is good, exit now and service * it next time around. What we really need to do * is wait for the RX list to drain and that won't * happen if we keep trying to process PDUs here. */ eup->eu_stats.eni_st_drv.drv_rv_nodma++;#ifdef DO_LOG log ( LOG_ERR,"eni_do_service: No room in receive DMA list. Postponing service request.\n" );#endif /* * Free the local buffer chain */ KB_FREEALL ( m ); /* * Clear the IN_SERVICE indicator for this VCC. */ vct->vci_control &= ~VCI_IN_SERVICE; return; } /* * If we have a buffer chain, save the starting * dma_list location. */ if ( upp ) { *upp = dma_wr << 16; } /* * Stuff the DMA list */ j >>= 1; for ( i = 0; i < j; i++ ) { eup->eu_rxdma[dma_wr*2] = dma[i*2]; eup->eu_rxdma[dma_wr*2+1] = dma[i*2+1]; dma_wr = (dma_wr+1) & (DMA_LIST_SIZE-1); } /* * If we have a buffer chain, save the location of * the ending dma_list location and queue the chain * so that we can recover the resources later. */ if ( upp ) { *upp |= dma_wr; /* * Place buffer on receive queue waiting for RX_DMA */ if ( IF_QFULL ( &eup->eu_rxqueue ) ) { /* * We haven't done anything we can't back out * of. Drop request and service it next time. * We've inserted the DMA list but it's not * valid until we advance the RX_WR pointer, * thus it's okay to bail here... */ eup->eu_stats.eni_st_drv.drv_rv_rxq++;#ifdef DO_LOG log ( LOG_ERR, "eni_do_service: RX drain queue full. Postponing servicing.\n" );#endif KB_FREEALL ( m ); /* * Clear the IN_SERVICE indicator for this VCC. */ vct->vci_control &= ~VCI_IN_SERVICE; return; } else { IF_ENQUEUE ( &eup->eu_rxqueue, m ); /* * Advance the RX_WR pointer to cause * the adapter to work on this DMA list. */ eup->eu_midway[MIDWAY_RX_WR] = dma_wr; } } /* * Advance our notion of where the next PDU * should start. */ rdptr = (rdptr + n_cells*WORDS_PER_CELL + 1) & (mask-1); evp->ev_rxpos = rdptr; /* * Increment cells/pdu received stats. */ eup->eu_stats.eni_st_atm.atm_rcvd += n_cells; if ( aal5 ) { eup->eu_stats.eni_st_aal5.aal5_rcvd += n_cells; eup->eu_stats.eni_st_aal5.aal5_pdu_rcvd++; } else { eup->eu_stats.eni_st_aal0.aal0_rcvd += n_cells; } /* * Continue processing PDUs on this same VCI */ }next_vcc: /* * Advance to next entry in the service_list. */ eup->eu_servread = (eup->eu_servread + 1) & SVC_SIZE_MASK; /* * And clear the IN_SERVICE indicator for this VCC. */ vct->vci_control &= ~VCI_IN_SERVICE; } return;}/* * Drain Receive queue * * As we build DMA lists to move PDUs from adapter buffers into host * buffers, we place the request on a private ifqueue so that we can * free any resources AFTER we know they've been successfully DMAed. * As part of the service processing, we record the PDUs start and stop * entries in the DMA list, and prevent wrapping. When we pull the top * entry off, we simply check that the current DMA location is outside * this PDU and if so, it's okay to free things. * * Arguments: * eup pointer to device unit structure * * Returns: * none * */voideni_recv_drain ( eup ) Eni_unit *eup;{ KBuffer *m; Eni_vcc *evp; struct vccb *vcp; u_long vcc; u_long DMA_Rdptr; u_long dma_wrp; u_long start, stop; int que = 0; int s; s = splimp(); /* Pop first buffer */ IF_DEQUEUE ( &eup->eu_rxqueue, m ); while ( m ) { u_long *up; u_long pdulen; KB_DATASTART ( m, up, u_long * ); /* * Grab the VCI number */ vcc = *up++; /* * Check to see if we can process this buffer yet. */ /* Get current DMA_Rdptr */ DMA_Rdptr = eup->eu_midway[MIDWAY_RX_RD]; /* Boundaries for first buffer */ dma_wrp = *up++; start = dma_wrp >> 16; stop = dma_wrp & 0xffff; /* * Start should not equal stop because that would * mean we tried inserting a NULL DMA list. */ if ( start > stop ) { /* We wrapped */ if ( !(DMA_Rdptr >= stop && DMA_Rdptr < start) ) { IF_PREPEND ( &eup->eu_rxqueue, m ); goto finish; } } else { if ( DMA_Rdptr < stop && DMA_Rdptr >= start ) { IF_PREPEND ( &eup->eu_rxqueue, m ); goto finish; } } /* * Adapter is finished with this buffer, we can * continue processing it now. */ /* * Locate incoming VCC for this PDU */ evp = (Eni_vcc *) atm_dev_vcc_find ( (Cmn_unit *)eup, 0, vcc, VCC_IN ); if ( evp == NULL ) { eup->eu_stats.eni_st_drv.drv_rv_novcc++; KB_FREEALL ( m ); goto next_buffer; }#ifdef DIAGNOSTIC if ( eni_pdu_print ) atm_dev_pdu_print ( (Cmn_unit *)eup, (Cmn_vcc *)evp, m, "eni_stack_drain" );#endif /* * Grab theoretical PDU length */ pdulen = *up++; /* * Quick, count the PDU */ eup->eu_pif.pif_ipdus++; eup->eu_pif.pif_ibytes += pdulen; if ( evp ) { vcp = evp->ev_connvc->cvc_vcc; if ( vcp ) { vcp->vc_ipdus++; vcp->vc_ibytes += pdulen; if ( vcp->vc_nif ) { vcp->vc_nif->nif_ibytes += pdulen; vcp->vc_nif->nif_if.if_ipackets++;#if (defined(BSD) && (BSD >= 199103)) vcp->vc_nif->nif_if.if_ibytes += pdulen;#endif } } } /* * Advance DMA write allowable pointer */ eup->eu_rxdmawr = stop; /* * Get packet PDU length */ KB_PLENGET ( m, pdulen ); /* * Only try queueing this if there is data * to be handed up to the next layer. Errors * such as CRC and VC trashing will get us this * far to advance pointers, etc., but the PDU * length will be zero. */ if ( pdulen ) { /* * We saved three words back in eni_do_service() * to use for callback. Since the core only * expects two words, skip over the first one. * Then, reset up pointer to start of buffer data * area and write the callback info. */ KB_HEADADJ ( m, -sizeof(u_long) ); KB_DATASTART ( m, up, u_long * ); *((int *)up) = (int)eni_recv_stack; up++; *((int *)up) = (int)evp; /* * Schedule callback */ if ( !IF_QFULL ( &atm_intrq ) ) { que++; IF_ENQUEUE ( &atm_intrq, m ); } else { eup->eu_stats.eni_st_drv.drv_rv_intrq++; eup->eu_pif.pif_ierrors++;#ifdef DO_LOG log ( LOG_ERR,"eni_receive_drain: ATM_INTRQ is full. Unable to pass up stack.\n" );#endif KB_FREEALL ( m ); } } else { /* * Free zero-length buffer */ KB_FREEALL(m); }next_buffer: /* * Look for next buffer */ IF_DEQUEUE ( &eup->eu_rxqueue, m ); }finish: (void) splx(s); /* * If we found any completed buffers, schedule a call into * the kernel to process the atm_intrq. */ if ( que ) SCHED_ATM; return;}/* * Pass incoming PDU up Stack * * This function is called via the core ATM interrupt queue callback * set in eni_recv_drain(). It will pass the supplied incoming * PDU up the incoming VCC's stack. * * Arguments: * tok token to identify stack instantiation * m pointer to incoming PDU buffer chain * * Returns: * none */static voideni_recv_stack ( tok, m ) void *tok; KBuffer *m;{ Eni_vcc *evp = (Eni_vcc *)tok; int err; /* * This should never happen now but if it does and we don't stop it, * we end up panic'ing in netatm when trying to pull a function * pointer and token value out of a buffer with address zero. */ if ( !m ) {#ifdef DO_LOG log ( LOG_ERR, "eni_recv_stack: NULL buffer, tok = %p\n", tok );#endif return; } /* * Send the data up the stack */ STACK_CALL ( CPCS_UNITDATA_SIG, evp->ev_upper, (void *)evp->ev_toku, evp->ev_connvc, (int)m, 0, err ); if ( err ) { KB_FREEALL ( m ); } return;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?