/*
* Copyright (c) 2001 Rafal K. Boni
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* We pack all DMA control structures into one container so we can alloc just
* one chunk of DMA-safe memory and pack them into it. Otherwise, we'd have to
* allocate a page for each descriptor, since the bus_dmamem_alloc() interface
* does not allow us to allocate smaller chunks.
*/
struct sq_control {
/* Receive descriptors */
struct hpc_dma_desc rx_desc[SQ_NRXDESC];
/* DMA structures for control data (DMA RX/TX descriptors) */
int sc_ncdseg;
bus_dma_segment_t sc_cdseg;
bus_dmamap_t sc_cdmap;
#define sc_cddma sc_cdmap->dm_segs[0].ds_addr
int sc_nextrx;
/* DMA structures for RX packet data */
bus_dma_segment_t sc_rxseg[SQ_NRXDESC];
bus_dmamap_t sc_rxmap[SQ_NRXDESC];
struct mbuf* sc_rxmbuf[SQ_NRXDESC];
int sc_nexttx;
int sc_prevtx;
int sc_nfreetx;
/* DMA structures for TX packet data */
bus_dma_segment_t sc_txseg[SQ_NTXDESC];
bus_dmamap_t sc_txmap[SQ_NTXDESC];
struct mbuf* sc_txmbuf[SQ_NTXDESC];
static inline void
SQ_CDTXSYNC(struct sq_softc *sc, int __x, int __n, int ops)
{
/* If it will wrap around, sync to the end of the ring. */
if ((__x + __n) > SQ_NTXDESC) {
bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cdmap,
SQ_CDTXOFF(__x), sizeof(struct hpc_dma_desc) *
(SQ_NTXDESC - __x), (ops));
__n -= (SQ_NTXDESC - __x);
__x = 0;
}
/* Now sync whatever is left. */
bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cdmap,
SQ_CDTXOFF(__x), sizeof(struct hpc_dma_desc) * __n, (ops));
}