xref: /openbsd-src/sys/dev/ic/mtd8xxvar.h (revision aaeadf5eb1ec92519230fd5f9c64c1b72b4e2248)
1*aaeadf5eSjsg /*	$OpenBSD: mtd8xxvar.h,v 1.4 2014/09/06 05:41:35 jsg Exp $	*/
263ec0125Smickey 
363ec0125Smickey /*
463ec0125Smickey  * Copyright (c) 2003 Oleg Safiullin <form@pdp11.org.ru>
563ec0125Smickey  * All rights reserved.
663ec0125Smickey  *
763ec0125Smickey  * Redistribution and use in source and binary forms, with or without
863ec0125Smickey  * modification, are permitted provided that the following conditions
963ec0125Smickey  * are met:
1063ec0125Smickey  * 1. Redistributions of source code must retain the above copyright
1163ec0125Smickey  *    notice unmodified, this list of conditions, and the following
1263ec0125Smickey  *    disclaimer.
1363ec0125Smickey  * 2. Redistributions in binary form must reproduce the above copyright
1463ec0125Smickey  *    notice, this list of conditions and the following disclaimer in the
1563ec0125Smickey  *    documentation and/or other materials provided with the distribution.
1663ec0125Smickey  *
1763ec0125Smickey  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1863ec0125Smickey  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1963ec0125Smickey  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2063ec0125Smickey  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2163ec0125Smickey  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2263ec0125Smickey  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2363ec0125Smickey  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2463ec0125Smickey  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2563ec0125Smickey  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2663ec0125Smickey  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2763ec0125Smickey  * SUCH DAMAGE.
2863ec0125Smickey  *
2963ec0125Smickey  */
3063ec0125Smickey 
3163ec0125Smickey #ifndef __DEV_IC_MTD8XXVAR_H__
3263ec0125Smickey #define __DEV_IC_MTD8XXVAR_H__
3363ec0125Smickey 
3463ec0125Smickey #define MTD_RX_LIST_CNT		64
3563ec0125Smickey #define MTD_TX_LIST_CNT		128
3663ec0125Smickey 
3763ec0125Smickey /*
3863ec0125Smickey  * Transmit descriptor structure.
3963ec0125Smickey  */
4063ec0125Smickey struct mtd_tx_desc {
4163ec0125Smickey 	u_int32_t	td_tsw;		/* Transmit status word */
4263ec0125Smickey #define TSW_OWN		0x80000000U	/* Descriptor owned by NIC */
4363ec0125Smickey #define TSW_TXERR	0x00008000U	/* Transmission error */
4463ec0125Smickey #define TSW_ABORT	0x00002000U	/* Transmission aborted */
4563ec0125Smickey #define TSW_CSL		0x00001000U	/* Carrier sense lost */
4663ec0125Smickey #define TSW_LC		0x00000800U	/* Late collision occurs */
4763ec0125Smickey #define TSW_EC		0x00000400U	/* Excessive collisions */
482408ed96Sjmc #define TSW_DFR		0x00000200U	/* Deferred */
4963ec0125Smickey #define TSW_HF		0x00000100U	/* Heart beat failure */
5063ec0125Smickey #define TSW_NCR_MASK	0x000000FFU
5163ec0125Smickey #define TSW_NCR_SHIFT	0
5263ec0125Smickey #define TSW_NCR_GET(x)	(((x) & TSW_NCR_MASK) >> TSW_NCR_SHIFT)
5363ec0125Smickey 					/* Collision retry count */
5463ec0125Smickey #define TSW_UNSENT	0x00001234U	/* Unsent packet magic */
5563ec0125Smickey 	u_int32_t	td_tcw;		/* Transmit configure word */
5663ec0125Smickey #define TCW_IC		0x80000000U	/* Interrupt control */
5763ec0125Smickey #define TCW_EIC		0x40000000U	/* Early interrupt control */
5863ec0125Smickey #define TCW_LD		0x20000000U	/* Last descriptor */
5963ec0125Smickey #define TCW_FD		0x10000000U	/* First descriptor */
6063ec0125Smickey #define TCW_CRC		0x08000000U	/* Append CRC field to packet */
6163ec0125Smickey #define TCW_PAD		0x04000000U	/* Pad zeroes to the end of packet */
6263ec0125Smickey #define TCW_RTLC	0x02000000U	/* Retry late collision */
6363ec0125Smickey #define TCW_PKTS_MASK	0x00003FF8U
6463ec0125Smickey #define TCW_PKTS_SHIFT	11
6563ec0125Smickey #define TCW_PKTS_GET(x)	(((x) & TCW_PKTS_MASK) >> TCW_PKTS_SHIFT)
6663ec0125Smickey 					/* Packet size */
6763ec0125Smickey #define TCW_TBS_MASK	0x000007FFU
6863ec0125Smickey #define TCW_TBS_SHIFT	0
6963ec0125Smickey #define TCW_TBS_GET(x)	(((x) & TCW_TBS_MASK) >> TCW_TBS_SHIFT)
7063ec0125Smickey 					/* Transmit buffer size */
7163ec0125Smickey 	u_int32_t	td_buf;		/* Transmit buffer address */
7263ec0125Smickey 	u_int32_t	td_next;	/* Next descriptor address */
7363ec0125Smickey };
7463ec0125Smickey 
7563ec0125Smickey 
7663ec0125Smickey /*
7763ec0125Smickey  * Receive descriptor structure.
7863ec0125Smickey  */
7963ec0125Smickey struct mtd_rx_desc {
8063ec0125Smickey 	u_int32_t	rd_rsr;		/* Receive status register */
812408ed96Sjmc #define RSR_OWN		0x80000000U	/* Descriptor owned by NIC */
8263ec0125Smickey #define RSR_FLNG_MASK	0x0FFF0000U
8363ec0125Smickey #define RSR_FLNG_SHIFT	16
8463ec0125Smickey #define RSR_FLNG_GET(x)	(((x) & RSR_FLNG_MASK) >> RSR_FLNG_SHIFT)
8563ec0125Smickey 					/* Frame length */
8663ec0125Smickey #define RSR_MAR		0x00004000U	/* Multicast address received */
8763ec0125Smickey #define RSR_BAR		0x00002000U	/* Broadcast address received */
8863ec0125Smickey #define RSR_PHY		0x00001000U	/* Physical address received */
8963ec0125Smickey #define RSR_FSD		0x00000800U	/* First descriptor */
9063ec0125Smickey #define RSR_LSD		0x00000400U	/* Last descriptor */
9163ec0125Smickey #define RSR_ES		0x00000080U	/* Error summary */
9263ec0125Smickey #define RSR_RUNT	0x00000040U	/* Runt packet received */
9363ec0125Smickey #define RSR_LONG	0x00000020U	/* Long packet received */
9463ec0125Smickey #define RSR_FAE		0x00000010U	/* Frame alignment error */
9563ec0125Smickey #define RSR_CRC		0x00000008U	/* CRC error */
9663ec0125Smickey #define RSR_RXER	0x00000004U	/* Receive error */
9763ec0125Smickey 	u_int32_t	rd_rcw;		/* Receive configure word */
9863ec0125Smickey #define RCW_RBS_MASK	0x000007FFU
9963ec0125Smickey #define RCW_RBS_SHIFT	0
10063ec0125Smickey #define RCW_RBS_GET(x) (((x) & RCW_RBS_MASK) >> RCW_RBS_SHIFT)
10163ec0125Smickey 	u_int32_t	rd_buf;		/* Receive buffer address */
10263ec0125Smickey 	u_int32_t	rd_next;	/* Next descriptor address */
10363ec0125Smickey };
10463ec0125Smickey 
10563ec0125Smickey 
10663ec0125Smickey struct mtd_list_data {
10763ec0125Smickey 	struct mtd_rx_desc	mtd_rx_list[MTD_RX_LIST_CNT];
10863ec0125Smickey 	struct mtd_tx_desc	mtd_tx_list[MTD_TX_LIST_CNT];
10963ec0125Smickey };
11063ec0125Smickey 
11163ec0125Smickey 
11263ec0125Smickey struct mtd_swdesc {
11363ec0125Smickey 	bus_dmamap_t		sd_map;
11463ec0125Smickey 	struct mbuf		*sd_mbuf;
11563ec0125Smickey };
11663ec0125Smickey 
11763ec0125Smickey 
11863ec0125Smickey struct mtd_chain_data {
11963ec0125Smickey 	struct mtd_swdesc	mtd_rx_chain[MTD_RX_LIST_CNT];
12063ec0125Smickey 	struct mtd_swdesc	mtd_tx_chain[MTD_TX_LIST_CNT];
12163ec0125Smickey 	int			mtd_tx_prod;
12263ec0125Smickey 	int			mtd_tx_cons;
12363ec0125Smickey 	int			mtd_tx_cnt;
12463ec0125Smickey 	int			mtd_rx_prod;
12563ec0125Smickey };
12663ec0125Smickey 
12763ec0125Smickey 
12863ec0125Smickey struct mtd_softc {
12963ec0125Smickey 	struct device		sc_dev;
13063ec0125Smickey 	struct arpcom		sc_arpcom;
13163ec0125Smickey 	struct mii_data		sc_mii;
132*aaeadf5eSjsg 	uint16_t		sc_devid;
13363ec0125Smickey 
13463ec0125Smickey 	bus_space_handle_t	sc_bush;
13563ec0125Smickey 	bus_space_tag_t		sc_bust;
13663ec0125Smickey 
13763ec0125Smickey 	struct mtd_list_data	*mtd_ldata;
13863ec0125Smickey 	struct mtd_chain_data	mtd_cdata;
13963ec0125Smickey 
14063ec0125Smickey 	bus_dma_tag_t		sc_dmat;
14163ec0125Smickey 	bus_dmamap_t		sc_listmap;
14263ec0125Smickey 	bus_dma_segment_t	sc_listseg[1];
14363ec0125Smickey 	int			sc_listnseg;
14463ec0125Smickey 	caddr_t			sc_listkva;
14563ec0125Smickey 	bus_dmamap_t		sc_rx_sparemap;
14663ec0125Smickey 	bus_dmamap_t		sc_tx_sparemap;
14763ec0125Smickey };
14863ec0125Smickey 
14963ec0125Smickey __BEGIN_DECLS
15063ec0125Smickey void	mtd_attach(struct mtd_softc *);
15163ec0125Smickey int	mtd_intr(void *);
15263ec0125Smickey __END_DECLS
15363ec0125Smickey 
15463ec0125Smickey #endif	/* __DEV_IC_MTD8XXVAR_H__ */
155