Home | History | Annotate | Line # | Download | only in ic
dm9000var.h revision 1.3
      1  1.3  christos /*	$NetBSD: dm9000var.h,v 1.3 2018/04/19 21:50:08 christos Exp $	*/
      2  1.1     ahoka 
      3  1.1     ahoka /*
      4  1.1     ahoka  * Copyright (c) 2009 Paul Fleischer
      5  1.1     ahoka  * All rights reserved.
      6  1.1     ahoka  *
      7  1.1     ahoka  * 1. Redistributions of source code must retain the above copyright
      8  1.1     ahoka  *    notice, this list of conditions and the following disclaimer.
      9  1.1     ahoka  * 2. Redistributions in binary form must reproduce the above copyright
     10  1.1     ahoka  *    notice, this list of conditions and the following disclaimer in the
     11  1.1     ahoka  *    documentation and/or other materials provided with the distribution.
     12  1.1     ahoka  * 3. The name of the company nor the name of the author may be used to
     13  1.1     ahoka  *    endorse or promote products derived from this software without specific
     14  1.1     ahoka  *    prior written permission.
     15  1.1     ahoka  *
     16  1.1     ahoka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     17  1.1     ahoka  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  1.1     ahoka  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.1     ahoka  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     20  1.1     ahoka  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     21  1.1     ahoka  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22  1.1     ahoka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.1     ahoka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  1.1     ahoka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.1     ahoka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.1     ahoka  * SUCH DAMAGE.
     27  1.1     ahoka  */
     28  1.1     ahoka 
     29  1.1     ahoka /* Based on sys/dev/ic/cs89x0var.h */
     30  1.1     ahoka /*
     31  1.1     ahoka  * Copyright 1997
     32  1.1     ahoka  * Digital Equipment Corporation. All rights reserved.
     33  1.1     ahoka  *
     34  1.1     ahoka  * This software is furnished under license and may be used and
     35  1.1     ahoka  * copied only in accordance with the following terms and conditions.
     36  1.1     ahoka  * Subject to these conditions, you may download, copy, install,
     37  1.1     ahoka  * use, modify and distribute this software in source and/or binary
     38  1.1     ahoka  * form. No title or ownership is transferred hereby.
     39  1.1     ahoka  *
     40  1.1     ahoka  * 1) Any source code used, modified or distributed must reproduce
     41  1.1     ahoka  *    and retain this copyright notice and list of conditions as
     42  1.1     ahoka  *    they appear in the source file.
     43  1.1     ahoka  *
     44  1.1     ahoka  * 2) No right is granted to use any trade name, trademark, or logo of
     45  1.1     ahoka  *    Digital Equipment Corporation. Neither the "Digital Equipment
     46  1.1     ahoka  *    Corporation" name nor any trademark or logo of Digital Equipment
     47  1.1     ahoka  *    Corporation may be used to endorse or promote products derived
     48  1.1     ahoka  *    from this software without the prior written permission of
     49  1.1     ahoka  *    Digital Equipment Corporation.
     50  1.1     ahoka  *
     51  1.1     ahoka  * 3) This software is provided "AS-IS" and any express or implied
     52  1.1     ahoka  *    warranties, including but not limited to, any implied warranties
     53  1.1     ahoka  *    of merchantability, fitness for a particular purpose, or
     54  1.1     ahoka  *    non-infringement are disclaimed. In no event shall DIGITAL be
     55  1.1     ahoka  *    liable for any damages whatsoever, and in particular, DIGITAL
     56  1.1     ahoka  *    shall not be liable for special, indirect, consequential, or
     57  1.1     ahoka  *    incidental damages or damages for lost profits, loss of
     58  1.1     ahoka  *    revenue or loss of use, whether such damages arise in contract,
     59  1.1     ahoka  *    negligence, tort, under statute, in equity, at law or otherwise,
     60  1.1     ahoka  *    even if advised of the possibility of such damage.
     61  1.1     ahoka  */
     62  1.1     ahoka 
     63  1.1     ahoka #ifndef _DEV_IC_DM9000VAR_H_
     64  1.1     ahoka #define _DEV_IC_DM9000VAR_H_
     65  1.1     ahoka 
     66  1.2  nisimura #include <sys/callout.h>
     67  1.1     ahoka 
     68  1.1     ahoka #define DM9000_MODE_8BIT 2
     69  1.1     ahoka #define DM9000_MODE_16BIT 0
     70  1.1     ahoka #define DM9000_MODE_32BIT 1
     71  1.1     ahoka 
     72  1.1     ahoka struct dme_softc {
     73  1.1     ahoka 	device_t	sc_dev;		/* Generic Base Device */
     74  1.1     ahoka 
     75  1.1     ahoka 	struct ethercom sc_ethercom;	/* Ethernet common data */
     76  1.1     ahoka 	struct ifmedia	sc_media;	/* Media control structures */
     77  1.1     ahoka 
     78  1.2  nisimura 	uint		sc_media_active;
     79  1.2  nisimura 	uint		sc_media_status;
     80  1.2  nisimura 
     81  1.1     ahoka 	bus_space_tag_t		sc_iot;
     82  1.1     ahoka 	bus_space_handle_t	sc_ioh;
     83  1.1     ahoka 	void		*sc_ih;
     84  1.1     ahoka 
     85  1.1     ahoka 	uint		dme_io;
     86  1.1     ahoka 	uint		dme_data;
     87  1.1     ahoka 
     88  1.1     ahoka 	uint16_t	sc_vendor_id;
     89  1.1     ahoka 	uint16_t	sc_product_id;
     90  1.1     ahoka 
     91  1.2  nisimura 	uint8_t		sc_data_width;
     92  1.1     ahoka 
     93  1.1     ahoka 	uint8_t		sc_enaddr[ETHER_ADDR_LEN];
     94  1.1     ahoka 
     95  1.1     ahoka 	int		txbusy;		/* A packet is being transmitted. */
     96  1.1     ahoka 	int		txready;	/* A packet has been sent to the DM9000
     97  1.1     ahoka 					   for transmission. */
     98  1.1     ahoka 	uint16_t	txready_length;
     99  1.1     ahoka 
    100  1.2  nisimura 	int (*sc_pkt_write)(struct dme_softc*, struct mbuf *);
    101  1.2  nisimura 	int (*sc_pkt_read)(struct dme_softc*, struct ifnet *, struct mbuf **);
    102  1.2  nisimura 
    103  1.2  nisimura 	callout_t	sc_link_callout;
    104  1.2  nisimura 
    105  1.2  nisimura 	bool		sc_phy_initialized;
    106  1.2  nisimura 
    107  1.1     ahoka #ifdef DIAGNOSTIC
    108  1.1     ahoka 	bool		sc_inside_interrupt;
    109  1.1     ahoka #endif
    110  1.1     ahoka };
    111  1.1     ahoka 
    112  1.1     ahoka /* Function declarations */
    113  1.2  nisimura int	dme_attach(struct dme_softc *, const uint8_t *);
    114  1.1     ahoka int	dme_detach(struct dme_softc *);
    115  1.1     ahoka int	dme_intr(void *);
    116  1.1     ahoka 
    117  1.2  nisimura /* Helper method used by sc_pkt_read */
    118  1.2  nisimura struct mbuf* dme_alloc_receive_buffer(struct ifnet *, unsigned int);
    119  1.2  nisimura 
    120  1.1     ahoka /* Inline memory access methods */
    121  1.3  christos static __inline uint8_t
    122  1.1     ahoka dme_read(struct dme_softc *sc, int reg)
    123  1.1     ahoka {
    124  1.1     ahoka 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->dme_io, reg);
    125  1.1     ahoka 	return (bus_space_read_1(sc->sc_iot, sc->sc_ioh, sc->dme_data));
    126  1.1     ahoka }
    127  1.1     ahoka 
    128  1.3  christos static __inline void
    129  1.1     ahoka dme_write(struct dme_softc *sc, int reg, uint8_t value)
    130  1.1     ahoka {
    131  1.1     ahoka 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->dme_io, reg);
    132  1.1     ahoka 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->dme_data, value);
    133  1.1     ahoka }
    134  1.1     ahoka 
    135  1.3  christos static __inline void
    136  1.1     ahoka dme_write2(struct dme_softc *sc, int reg, uint16_t value)
    137  1.1     ahoka {
    138  1.1     ahoka 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->dme_io, reg);
    139  1.1     ahoka 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, sc->dme_data, value);
    140  1.1     ahoka }
    141  1.1     ahoka 
    142  1.3  christos static __inline void
    143  1.1     ahoka dme_write_c(struct dme_softc *sc, int reg, uint8_t value[], uint count)
    144  1.1     ahoka {
    145  1.1     ahoka 	for(int i=0; i<count; i++) {
    146  1.1     ahoka 		dme_write(sc, reg+i, value[i]);
    147  1.1     ahoka 	}
    148  1.1     ahoka }
    149  1.1     ahoka 
    150  1.3  christos static __inline void
    151  1.1     ahoka dme_read_c(struct dme_softc *sc, int reg, uint8_t *value, uint count)
    152  1.1     ahoka {
    153  1.1     ahoka 	for(int i=0; i<count; i++) {
    154  1.1     ahoka 		value[i] = dme_read(sc, reg+i);
    155  1.1     ahoka 	}
    156  1.1     ahoka }
    157  1.1     ahoka 
    158  1.1     ahoka #endif /* _DEV_IC_DM9000VAR_H_ */
    159  1.1     ahoka 
    160