Home | History | Annotate | Line # | Download | only in hpc
sqvar.h revision 1.4.10.4
      1  1.4.10.4    skrll /*	$NetBSD: sqvar.h,v 1.4.10.4 2005/01/17 19:30:19 skrll Exp $	*/
      2       1.1  thorpej 
      3       1.1  thorpej /*
      4       1.1  thorpej  * Copyright (c) 2001 Rafal K. Boni
      5       1.1  thorpej  * All rights reserved.
      6       1.3   simonb  *
      7       1.1  thorpej  * Redistribution and use in source and binary forms, with or without
      8       1.1  thorpej  * modification, are permitted provided that the following conditions
      9       1.1  thorpej  * are met:
     10       1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     11       1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     12       1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     14       1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     15       1.1  thorpej  * 3. The name of the author may not be used to endorse or promote products
     16       1.1  thorpej  *    derived from this software without specific prior written permission.
     17       1.3   simonb  *
     18       1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19       1.1  thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20       1.1  thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21       1.1  thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22       1.1  thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23       1.1  thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24       1.1  thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25       1.1  thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26       1.1  thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27       1.1  thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28       1.1  thorpej  */
     29       1.1  thorpej 
     30       1.1  thorpej #ifndef _ARCH_SGIMIPS_HPC_SQVAR_H_
     31       1.1  thorpej #define	_ARCH_SGIMIPS_HPC_SQVAR_H_
     32       1.1  thorpej 
     33       1.1  thorpej #include "rnd.h"
     34       1.3   simonb 
     35       1.1  thorpej #include <sys/queue.h>
     36       1.1  thorpej #include <sys/callout.h>
     37       1.1  thorpej 
     38       1.1  thorpej #if NRND > 0
     39       1.1  thorpej #include <sys/rnd.h>
     40       1.1  thorpej #endif
     41       1.1  thorpej 
     42       1.1  thorpej #include <sgimips/hpc/hpcvar.h>
     43       1.1  thorpej #include <sgimips/hpc/hpcreg.h>
     44       1.1  thorpej 
     45       1.1  thorpej /* Note, these must be powers of two for the magic NEXT/PREV macros to work */
     46  1.4.10.4    skrll #define SQ_NRXDESC		64
     47  1.4.10.4    skrll #define SQ_NTXDESC		64
     48       1.1  thorpej 
     49       1.1  thorpej #define	SQ_NRXDESC_MASK		(SQ_NRXDESC - 1)
     50       1.1  thorpej #define	SQ_NEXTRX(x)		((x + 1) & SQ_NRXDESC_MASK)
     51       1.1  thorpej #define	SQ_PREVRX(x)		((x - 1) & SQ_NRXDESC_MASK)
     52       1.1  thorpej 
     53       1.1  thorpej #define	SQ_NTXDESC_MASK		(SQ_NTXDESC - 1)
     54       1.1  thorpej #define	SQ_NEXTTX(x)		((x + 1) & SQ_NTXDESC_MASK)
     55       1.1  thorpej #define	SQ_PREVTX(x)		((x - 1) & SQ_NTXDESC_MASK)
     56       1.1  thorpej 
     57       1.1  thorpej /*
     58       1.1  thorpej  * We pack all DMA control structures into one container so we can alloc just
     59       1.1  thorpej  * one chunk of DMA-safe memory and pack them into it.  Otherwise, we'd have to
     60       1.1  thorpej  * allocate a page for each descriptor, since the bus_dmamem_alloc() interface
     61       1.1  thorpej  * does not allow us to allocate smaller chunks.
     62       1.1  thorpej  */
     63       1.1  thorpej struct sq_control {
     64       1.1  thorpej 	/* Receive descriptors */
     65       1.1  thorpej 	struct hpc_dma_desc	rx_desc[SQ_NRXDESC];
     66       1.1  thorpej 
     67       1.1  thorpej 	/* Transmit descriptors */
     68       1.1  thorpej 	struct hpc_dma_desc	tx_desc[SQ_NTXDESC];
     69       1.1  thorpej };
     70       1.1  thorpej 
     71       1.1  thorpej #define	SQ_CDOFF(x)		offsetof(struct sq_control, x)
     72       1.1  thorpej #define	SQ_CDTXOFF(x)		SQ_CDOFF(tx_desc[(x)])
     73       1.1  thorpej #define	SQ_CDRXOFF(x)		SQ_CDOFF(rx_desc[(x)])
     74       1.1  thorpej 
     75       1.2  thorpej #define	SQ_TYPE_8003		0
     76       1.2  thorpej #define	SQ_TYPE_80C03		1
     77       1.2  thorpej 
     78  1.4.10.4    skrll /* Trace Actions */
     79  1.4.10.4    skrll #define SQ_RESET		1
     80  1.4.10.4    skrll #define SQ_ADD_TO_DMA		2
     81  1.4.10.4    skrll #define SQ_START_DMA		3
     82  1.4.10.4    skrll #define SQ_DONE_DMA		4
     83  1.4.10.4    skrll #define SQ_RESTART_DMA		5
     84  1.4.10.4    skrll #define SQ_TXINTR_ENTER		6
     85  1.4.10.4    skrll #define SQ_TXINTR_EXIT		7
     86  1.4.10.4    skrll #define SQ_TXINTR_BUSY		8
     87  1.4.10.4    skrll #define SQ_IOCTL		9
     88  1.4.10.4    skrll #define SQ_ENQUEUE		10
     89  1.4.10.4    skrll 
     90  1.4.10.4    skrll struct sq_action_trace {
     91  1.4.10.4    skrll 	int action;
     92  1.4.10.4    skrll 	int line;
     93  1.4.10.4    skrll 	int bufno;
     94  1.4.10.4    skrll 	int status;
     95  1.4.10.4    skrll 	int freebuf;
     96  1.4.10.4    skrll };
     97  1.4.10.4    skrll 
     98  1.4.10.4    skrll #define SQ_TRACEBUF_SIZE	100
     99  1.4.10.4    skrll 
    100  1.4.10.4    skrll #define SQ_TRACE(act, sc, buf, stat) do {				\
    101  1.4.10.4    skrll 	(sc)->sq_trace[(sc)->sq_trace_idx].action = (act);		\
    102  1.4.10.4    skrll 	(sc)->sq_trace[(sc)->sq_trace_idx].line = __LINE__;		\
    103  1.4.10.4    skrll 	(sc)->sq_trace[(sc)->sq_trace_idx].bufno = (buf);		\
    104  1.4.10.4    skrll 	(sc)->sq_trace[(sc)->sq_trace_idx].status = (stat);		\
    105  1.4.10.4    skrll 	(sc)->sq_trace[(sc)->sq_trace_idx].freebuf = (sc)->sc_nfreetx;	\
    106  1.4.10.4    skrll 	if (++(sc)->sq_trace_idx == SQ_TRACEBUF_SIZE)			\
    107  1.4.10.4    skrll 		(sc)->sq_trace_idx = 0;					\
    108  1.4.10.4    skrll } while (0)
    109  1.4.10.4    skrll 
    110       1.1  thorpej struct sq_softc {
    111       1.1  thorpej 	struct device 		sc_dev;
    112       1.1  thorpej 
    113       1.1  thorpej 	/* HPC registers */
    114       1.1  thorpej 	bus_space_tag_t 	sc_hpct;
    115       1.1  thorpej 	bus_space_handle_t 	sc_hpch;
    116       1.1  thorpej 
    117       1.3   simonb 
    118       1.1  thorpej 	/* HPC external ethernet registers: aka Seeq 8003 registers */
    119       1.1  thorpej 	bus_space_tag_t 	sc_regt;
    120       1.1  thorpej 	bus_space_handle_t 	sc_regh;
    121       1.1  thorpej 
    122       1.1  thorpej 	bus_dma_tag_t 		sc_dmat;
    123       1.1  thorpej 
    124       1.1  thorpej 	struct ethercom 	sc_ethercom;
    125       1.1  thorpej 	unsigned char 		sc_enaddr[ETHER_ADDR_LEN];
    126       1.1  thorpej 
    127       1.2  thorpej 	int			sc_type;
    128       1.2  thorpej 
    129       1.1  thorpej 	struct sq_control*	sc_control;
    130       1.1  thorpej #define	sc_rxdesc		sc_control->rx_desc
    131       1.1  thorpej #define	sc_txdesc		sc_control->tx_desc
    132       1.1  thorpej 
    133       1.1  thorpej 	/* DMA structures for control data (DMA RX/TX descriptors) */
    134       1.1  thorpej 	int			sc_ncdseg;
    135       1.1  thorpej 	bus_dma_segment_t	sc_cdseg;
    136       1.1  thorpej 	bus_dmamap_t		sc_cdmap;
    137       1.1  thorpej #define	sc_cddma		sc_cdmap->dm_segs[0].ds_addr
    138       1.1  thorpej 
    139       1.1  thorpej 	int			sc_nextrx;
    140       1.1  thorpej 
    141       1.1  thorpej 	/* DMA structures for RX packet data */
    142       1.1  thorpej 	bus_dma_segment_t	sc_rxseg[SQ_NRXDESC];
    143       1.1  thorpej 	bus_dmamap_t		sc_rxmap[SQ_NRXDESC];
    144       1.1  thorpej 	struct mbuf*		sc_rxmbuf[SQ_NRXDESC];
    145       1.1  thorpej 
    146       1.1  thorpej 	int			sc_nexttx;
    147       1.1  thorpej 	int			sc_prevtx;
    148       1.1  thorpej 	int			sc_nfreetx;
    149       1.1  thorpej 
    150       1.1  thorpej 	/* DMA structures for TX packet data */
    151       1.1  thorpej 	bus_dma_segment_t	sc_txseg[SQ_NTXDESC];
    152       1.1  thorpej 	bus_dmamap_t		sc_txmap[SQ_NTXDESC];
    153       1.1  thorpej 	struct mbuf*		sc_txmbuf[SQ_NTXDESC];
    154       1.2  thorpej 
    155       1.2  thorpej 	u_int8_t		sc_rxcmd;	/* prototype rxcmd */
    156       1.4    rafal 
    157       1.4    rafal 	struct evcnt		sq_intrcnt;	/* count interrupts */
    158       1.1  thorpej 
    159       1.1  thorpej #if NRND > 0
    160       1.1  thorpej 	rndsource_element_t 	rnd_source;	/* random source */
    161       1.1  thorpej #endif
    162  1.4.10.1    skrll 	struct hpc_values       *hpc_regs;      /* HPC register definitions */
    163  1.4.10.4    skrll 
    164  1.4.10.4    skrll 	int			sq_trace_idx;
    165  1.4.10.4    skrll 	struct sq_action_trace	sq_trace[SQ_TRACEBUF_SIZE];
    166       1.1  thorpej };
    167       1.1  thorpej 
    168       1.1  thorpej #define	SQ_CDTXADDR(sc, x)	((sc)->sc_cddma + SQ_CDTXOFF((x)))
    169       1.1  thorpej #define	SQ_CDRXADDR(sc, x)	((sc)->sc_cddma + SQ_CDRXOFF((x)))
    170       1.1  thorpej 
    171  1.4.10.1    skrll static inline void
    172  1.4.10.1    skrll SQ_CDTXSYNC(struct sq_softc *sc, int __x, int __n, int ops)
    173  1.4.10.1    skrll {
    174  1.4.10.1    skrll 	/* If it will wrap around, sync to the end of the ring. */
    175  1.4.10.1    skrll 	if ((__x + __n) > SQ_NTXDESC) {
    176  1.4.10.1    skrll 		bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cdmap,
    177  1.4.10.1    skrll 		    SQ_CDTXOFF(__x), sizeof(struct hpc_dma_desc) *
    178  1.4.10.1    skrll 		    (SQ_NTXDESC - __x), (ops));
    179  1.4.10.1    skrll 		__n -= (SQ_NTXDESC - __x);
    180  1.4.10.1    skrll 		__x = 0;
    181  1.4.10.1    skrll 	}
    182  1.4.10.1    skrll 
    183  1.4.10.1    skrll 	/* Now sync whatever is left. */
    184  1.4.10.1    skrll 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cdmap,
    185  1.4.10.1    skrll 	    SQ_CDTXOFF(__x), sizeof(struct hpc_dma_desc) * __n, (ops));
    186  1.4.10.1    skrll }
    187       1.1  thorpej 
    188       1.1  thorpej #define	SQ_CDRXSYNC(sc, x, ops)						\
    189       1.1  thorpej 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cdmap,			\
    190       1.1  thorpej 	    SQ_CDRXOFF((x)), sizeof(struct hpc_dma_desc), (ops))
    191       1.1  thorpej 
    192  1.4.10.1    skrll static inline void
    193  1.4.10.1    skrll SQ_INIT_RXDESC(struct sq_softc *sc, unsigned int x)
    194  1.4.10.1    skrll {
    195  1.4.10.1    skrll 	struct hpc_dma_desc* __rxd = &(sc)->sc_rxdesc[(x)];
    196  1.4.10.1    skrll 	struct mbuf *__m = (sc)->sc_rxmbuf[(x)];
    197  1.4.10.1    skrll 
    198  1.4.10.1    skrll 	__m->m_data = __m->m_ext.ext_buf;
    199  1.4.10.1    skrll 	if (sc->hpc_regs->revision == 3) {
    200  1.4.10.1    skrll 		__rxd->hpc3_hdd_bufptr =
    201  1.4.10.1    skrll 			(sc)->sc_rxmap[(x)]->dm_segs[0].ds_addr;
    202  1.4.10.4    skrll 		__rxd->hpc3_hdd_ctl = __m->m_ext.ext_size | HPC3_HDD_CTL_OWN |
    203  1.4.10.4    skrll 			HPC3_HDD_CTL_INTR | HPC3_HDD_CTL_EOPACKET |
    204  1.4.10.4    skrll 			((x) == (SQ_NRXDESC  - 1) ? HPC3_HDD_CTL_EOCHAIN : 0);
    205  1.4.10.1    skrll 	} else {
    206  1.4.10.1    skrll 		__rxd->hpc1_hdd_bufptr = (sc)->sc_rxmap[(x)]->dm_segs[0].ds_addr
    207  1.4.10.1    skrll 			| ((x) == (SQ_NRXDESC - 1) ? HPC1_HDD_CTL_EOCHAIN : 0);
    208  1.4.10.1    skrll         	__rxd->hpc1_hdd_ctl = __m->m_ext.ext_size | HPC1_HDD_CTL_OWN |
    209  1.4.10.1    skrll 			HPC1_HDD_CTL_INTR | HPC1_HDD_CTL_EOPACKET;
    210  1.4.10.1    skrll 	}
    211  1.4.10.1    skrll 	__rxd->hdd_descptr = SQ_CDRXADDR((sc), SQ_NEXTRX((x)));
    212  1.4.10.1    skrll 	SQ_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
    213  1.4.10.1    skrll }
    214       1.1  thorpej 
    215       1.1  thorpej #endif	/* _ARCH_SGIMIPS_HPC_SQVAR_H_ */
    216