1*cbab9cadSchs /* $NetBSD: hd64570var.h,v 1.11 2012/10/27 17:18:20 chs Exp $ */ 2c5e45095Sexplorer 3c5e45095Sexplorer /* 4d8a4f43dSchopps * Copyright (c) 1999 Christian E. Hopps 5c5e45095Sexplorer * Copyright (c) 1998 Vixie Enterprises 6c5e45095Sexplorer * All rights reserved. 7c5e45095Sexplorer * 8c5e45095Sexplorer * Redistribution and use in source and binary forms, with or without 9c5e45095Sexplorer * modification, are permitted provided that the following conditions 10c5e45095Sexplorer * are met: 11c5e45095Sexplorer * 12c5e45095Sexplorer * 1. Redistributions of source code must retain the above copyright 13c5e45095Sexplorer * notice, this list of conditions and the following disclaimer. 14c5e45095Sexplorer * 2. Redistributions in binary form must reproduce the above copyright 15c5e45095Sexplorer * notice, this list of conditions and the following disclaimer in the 16c5e45095Sexplorer * documentation and/or other materials provided with the distribution. 17c5e45095Sexplorer * 3. Neither the name of Vixie Enterprises nor the names 18c5e45095Sexplorer * of its contributors may be used to endorse or promote products derived 19c5e45095Sexplorer * from this software without specific prior written permission. 20c5e45095Sexplorer * 21c5e45095Sexplorer * THIS SOFTWARE IS PROVIDED BY VIXIE ENTERPRISES AND 22c5e45095Sexplorer * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 23c5e45095Sexplorer * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24c5e45095Sexplorer * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25c5e45095Sexplorer * DISCLAIMED. IN NO EVENT SHALL VIXIE ENTERPRISES OR 26c5e45095Sexplorer * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27c5e45095Sexplorer * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28c5e45095Sexplorer * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 29c5e45095Sexplorer * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30c5e45095Sexplorer * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31c5e45095Sexplorer * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 32c5e45095Sexplorer * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33c5e45095Sexplorer * SUCH DAMAGE. 34c5e45095Sexplorer * 35c5e45095Sexplorer * This software has been written for Vixie Enterprises by Michael Graff 36c5e45095Sexplorer * <explorer@flame.org>. To learn more about Vixie Enterprises, see 37c5e45095Sexplorer * ``http://www.vix.com''. 38c5e45095Sexplorer */ 39c5e45095Sexplorer 40026fcd0cSkleink #ifndef _DEV_IC_HD64570VAR_H_ 41026fcd0cSkleink #define _DEV_IC_HD64570VAR_H_ 42c5e45095Sexplorer 43c5e45095Sexplorer #define SCA_USE_FASTQ /* use a split queue, one for fast traffic */ 44c5e45095Sexplorer 45d8a4f43dSchopps #define SCA_MTU 1500 /* hard coded */ 46d8a4f43dSchopps 47d8a4f43dSchopps #ifndef SCA_BSIZE 48d8a4f43dSchopps #define SCA_BSIZE (SCA_MTU + 4) /* room for HDLC as well */ 49d8a4f43dSchopps #endif 50d8a4f43dSchopps 51d8a4f43dSchopps 52c5e45095Sexplorer struct sca_softc; 53c5e45095Sexplorer typedef struct sca_port sca_port_t; 54c5e45095Sexplorer typedef struct sca_desc sca_desc_t; 55c5e45095Sexplorer 56c5e45095Sexplorer /* 57c5e45095Sexplorer * device DMA descriptor 58c5e45095Sexplorer */ 59c5e45095Sexplorer struct sca_desc { 60d8a4f43dSchopps u_int16_t sd_chainp; /* chain pointer */ 61d8a4f43dSchopps u_int16_t sd_bufp; /* buffer pointer (low bits) */ 62d8a4f43dSchopps u_int8_t sd_hbufp; /* buffer pointer (high bits) */ 63d8a4f43dSchopps u_int8_t sd_unused0; 64d8a4f43dSchopps u_int16_t sd_buflen; /* total length */ 65d8a4f43dSchopps u_int8_t sd_stat; /* status */ 66d8a4f43dSchopps u_int8_t sd_unused1; 67c5e45095Sexplorer }; 68c5e45095Sexplorer #define SCA_DESC_EOT 0x01 69c5e45095Sexplorer #define SCA_DESC_CRC 0x04 70c5e45095Sexplorer #define SCA_DESC_OVRN 0x08 71c5e45095Sexplorer #define SCA_DESC_RESD 0x10 72c5e45095Sexplorer #define SCA_DESC_ABORT 0x20 73c5e45095Sexplorer #define SCA_DESC_SHRTFRM 0x40 74c5e45095Sexplorer #define SCA_DESC_EOM 0x80 75c5e45095Sexplorer #define SCA_DESC_ERRORS 0x7C 76c5e45095Sexplorer 77c5e45095Sexplorer /* 78c5e45095Sexplorer * softc structure for each port 79c5e45095Sexplorer */ 80c5e45095Sexplorer struct sca_port { 81c5e45095Sexplorer u_int msci_off; /* offset for msci address for this port */ 82c5e45095Sexplorer u_int dmac_off; /* offset of dmac address for this port */ 83c5e45095Sexplorer 84c5e45095Sexplorer u_int sp_port; 85c5e45095Sexplorer 86c5e45095Sexplorer /* 87c5e45095Sexplorer * CISCO keepalive stuff 88c5e45095Sexplorer */ 89c5e45095Sexplorer u_int32_t cka_lasttx; 90c5e45095Sexplorer u_int32_t cka_lastrx; 91c5e45095Sexplorer 92c5e45095Sexplorer /* 93d8a4f43dSchopps * clock values, clockrate = sysclock / tmc / 2^div; 94d8a4f43dSchopps */ 95d8a4f43dSchopps u_int8_t sp_eclock; /* enable external clock generate */ 96d8a4f43dSchopps u_int8_t sp_rxs; /* recv clock source */ 97d8a4f43dSchopps u_int8_t sp_txs; /* transmit clock source */ 98d8a4f43dSchopps u_int8_t sp_tmc; /* clock constant */ 99d8a4f43dSchopps 100d8a4f43dSchopps /* 101c5e45095Sexplorer * start of each important bit of information for transmit and 102c5e45095Sexplorer * receive buffers. 103d8a4f43dSchopps * 1041ffa7b76Swiz * note: for non-DMA the phys and virtual version should be 105d8a4f43dSchopps * the same value and should be an _offset_ from the beginning 106d8a4f43dSchopps * of mapped memory described by sc_memt/sc_memh. 107c5e45095Sexplorer */ 108d8a4f43dSchopps u_int sp_ntxdesc; /* number of tx descriptors */ 109792148e6Sjakllsch bus_addr_t sp_txdesc_p; /* paddress of first tx desc */ 110d8a4f43dSchopps sca_desc_t *sp_txdesc; /* vaddress of first tx desc */ 111792148e6Sjakllsch bus_addr_t sp_txbuf_p; /* paddress of first tx buffer */ 112d8a4f43dSchopps u_int8_t *sp_txbuf; /* vaddress of first tx buffer */ 113c5e45095Sexplorer 114d8a4f43dSchopps volatile u_int sp_txcur; /* last descriptor in chain */ 115d8a4f43dSchopps volatile u_int sp_txinuse; /* descriptors in use */ 116d8a4f43dSchopps volatile u_int sp_txstart; /* start descriptor */ 117d8a4f43dSchopps 118d8a4f43dSchopps u_int sp_nrxdesc; /* number of rx descriptors */ 119792148e6Sjakllsch bus_addr_t sp_rxdesc_p; /* paddress of first rx desc */ 120d8a4f43dSchopps sca_desc_t *sp_rxdesc; /* vaddress of first rx desc */ 121792148e6Sjakllsch bus_addr_t sp_rxbuf_p; /* paddress of first rx buffer */ 122d8a4f43dSchopps u_int8_t *sp_rxbuf; /* vaddress of first rx buffer */ 123d8a4f43dSchopps 124d8a4f43dSchopps u_int sp_rxstart; /* index of first descriptor */ 125d8a4f43dSchopps u_int sp_rxend; /* index of last descriptor */ 126c5e45095Sexplorer 127c5e45095Sexplorer struct ifnet sp_if; /* the network information */ 128c5e45095Sexplorer struct ifqueue linkq; /* link-level packets are high prio */ 129c5e45095Sexplorer #ifdef SCA_USE_FASTQ 130c5e45095Sexplorer struct ifqueue fastq; /* interactive packets */ 131c5e45095Sexplorer #endif 132c5e45095Sexplorer 133c5e45095Sexplorer struct sca_softc *sca; /* pointer to parent */ 134c5e45095Sexplorer }; 135c5e45095Sexplorer 136c5e45095Sexplorer /* 137c5e45095Sexplorer * softc structure for the chip itself 138c5e45095Sexplorer */ 139c5e45095Sexplorer struct sca_softc { 140*cbab9cadSchs device_t sc_parent; /* our parent device, or NULL */ 141c5e45095Sexplorer int sc_numports; /* number of ports present */ 142d8a4f43dSchopps u_int32_t sc_baseclock; /* the base operating clock */ 143c5e45095Sexplorer 144c5e45095Sexplorer /* 145c5e45095Sexplorer * a callback into the parent, since the SCA chip has no control 146c5e45095Sexplorer * over DTR, we have to make a callback into the parent, which 147c5e45095Sexplorer * might know about DTR. 148c5e45095Sexplorer * 149c5e45095Sexplorer * If the function pointer is NULL, no callback is specified. 150c5e45095Sexplorer */ 151d8a4f43dSchopps void *sc_aux; 1527f6ed16eSitojun void (*sc_dtr_callback)(void *, int, int); 1537f6ed16eSitojun void (*sc_clock_callback)(void *, int, int); 154d8a4f43dSchopps 155d8a4f43dSchopps /* used to read and write the device registers */ 156d8a4f43dSchopps u_int8_t (*sc_read_1)(struct sca_softc *, u_int); 157d8a4f43dSchopps u_int16_t (*sc_read_2)(struct sca_softc *, u_int); 158d8a4f43dSchopps void (*sc_write_1)(struct sca_softc *, u_int, u_int8_t); 159d8a4f43dSchopps void (*sc_write_2)(struct sca_softc *, u_int, u_int16_t); 160c5e45095Sexplorer 161c5e45095Sexplorer sca_port_t sc_ports[2]; 162c5e45095Sexplorer 163d8a4f43dSchopps bus_space_tag_t sc_iot; /* io space for registers */ 164d8a4f43dSchopps bus_space_handle_t sc_ioh; /* io space for registers */ 165d8a4f43dSchopps 166d8a4f43dSchopps int sc_usedma; 167d8a4f43dSchopps union { 168d8a4f43dSchopps struct { 1691ffa7b76Swiz bus_space_tag_t p_memt; /* mem for non-DMA */ 1701ffa7b76Swiz bus_space_handle_t p_memh; /* mem for non-DMA */ 171d8a4f43dSchopps bus_space_handle_t p_sca_ioh[16]; /* io for sca regs */ 172d8a4f43dSchopps bus_size_t p_pagesize; /* memory page size */ 173d8a4f43dSchopps bus_size_t p_pagemask; /* memory page mask */ 174d8a4f43dSchopps u_int p_pageshift; /* memory page shift */ 175d8a4f43dSchopps bus_size_t p_npages; /* num mem pages */ 176d8a4f43dSchopps 177d8a4f43dSchopps void (*p_set_page)(struct sca_softc *, bus_addr_t); 178d8a4f43dSchopps void (*p_page_on)(struct sca_softc *); 179d8a4f43dSchopps void (*p_page_off)(struct sca_softc *); 180d8a4f43dSchopps } u_paged; 181d8a4f43dSchopps struct { 1821ffa7b76Swiz bus_dma_tag_t d_dmat; /* bus DMA tag */ 1831ffa7b76Swiz bus_dmamap_t d_dmam; /* bus DMA map */ 1841ffa7b76Swiz bus_dma_segment_t d_seg; /* bus DMA segment */ 18553524e44Schristos void * d_dma_addr; /* kva of segment */ 186d8a4f43dSchopps bus_size_t d_allocsize; /* size of region */ 187d8a4f43dSchopps } u_dma; 188d8a4f43dSchopps } sc_u; 189c5e45095Sexplorer }; 190d8a4f43dSchopps #define scu_memt sc_u.u_paged.p_memt 191d8a4f43dSchopps #define scu_memh sc_u.u_paged.p_memh 192d8a4f43dSchopps #define scu_sca_ioh sc_u.u_paged.p_sca_ioh 193d8a4f43dSchopps #define scu_pagesize sc_u.u_paged.p_pagesize 194d8a4f43dSchopps #define scu_pagemask sc_u.u_paged.p_pagemask 195d8a4f43dSchopps #define scu_pageshift sc_u.u_paged.p_pageshift 196d8a4f43dSchopps #define scu_npages sc_u.u_paged.p_npages 197d8a4f43dSchopps #define scu_set_page sc_u.u_paged.p_set_page 198d8a4f43dSchopps #define scu_page_on sc_u.u_paged.p_page_on 199d8a4f43dSchopps #define scu_page_off sc_u.u_paged.p_page_off 200d8a4f43dSchopps #define scu_dmat sc_u.u_dma.d_dmat 201d8a4f43dSchopps #define scu_dmam sc_u.u_dma.d_dmam 202d8a4f43dSchopps #define scu_seg sc_u.u_dma.d_seg 203d8a4f43dSchopps #define scu_dma_addr sc_u.u_dma.d_dma_addr 204d8a4f43dSchopps #define scu_allocsize sc_u.u_dma.d_allocsize 205c5e45095Sexplorer 206d8a4f43dSchopps void sca_init(struct sca_softc *); 207c5e45095Sexplorer void sca_port_attach(struct sca_softc *, u_int); 208c5e45095Sexplorer int sca_hardintr(struct sca_softc *); 209c5e45095Sexplorer void sca_shutdown(struct sca_softc *); 210d8a4f43dSchopps void sca_get_base_clock(struct sca_softc *); 211d8a4f43dSchopps void sca_print_clock_info(struct sca_softc *); 212c5e45095Sexplorer 213026fcd0cSkleink #endif /* _DEV_IC_HD64570VAR_H_ */ 214