1139749Simp/*-
286752Sfjoe * Copyright (c) 1997-2001 Granch, Ltd. All rights reserved.
386752Sfjoe * Author: Denis I.Timofeev <timofeev@granch.ru>
486752Sfjoe *
586752Sfjoe * Redistributon and use in source and binary forms, with or without
686752Sfjoe * modification, are permitted provided that the following conditions
786752Sfjoe * are met:
886752Sfjoe * 1. Redistributions of source code must retain the above copyright
986752Sfjoe *    notice unmodified, this list of conditions, and the following
1086752Sfjoe *    disclaimer.
1186752Sfjoe * 2. Redistributions in binary form must reproduce the above copyright
1286752Sfjoe *    notice, this list of conditions and the following disclaimer in the
1386752Sfjoe *    documentation and/or other materials provided with the distribution.
1486752Sfjoe *
1586752Sfjoe * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1686752Sfjoe * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1786752Sfjoe * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1886752Sfjoe * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1986752Sfjoe * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2086752Sfjoe * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2186752Sfjoe * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2286752Sfjoe * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2386752Sfjoe * LIABILITY, OR TORT (INCLUDING NEIGENCE OR OTHERWISE) ARISING IN ANY WAY
2486752Sfjoe * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2586752Sfjoe * SUCH DAMAGE.
2686752Sfjoe *
2786752Sfjoe * $FreeBSD$
2886752Sfjoe */
2986752Sfjoe
3086752Sfjoe/*
3186752Sfjoe * SBNI12 definitions
3286752Sfjoe */
3386752Sfjoe
3486752Sfjoe/*
3586752Sfjoe * CONFIGURATION PARAMETER:
3686752Sfjoe *
3786752Sfjoe *	Uncomment this if you want to use model SBNI12D-11/ISA with same IRQ
3886752Sfjoe *	for both first and second channels.
3986752Sfjoe */
4086752Sfjoe#define SBNI_DUAL_COMPOUND 1
4186752Sfjoe
4286752Sfjoe#define SBNI_DEBUG 0
4386752Sfjoe
4486752Sfjoe#if SBNI_DEBUG
4586752Sfjoe#define DP(A) A
4686752Sfjoe#else
4786752Sfjoe#define DP(A)
4886752Sfjoe#endif
4986752Sfjoe
5086752Sfjoestruct sbni_in_stats {
5186752Sfjoe	u_int32_t	all_rx_number;
5286752Sfjoe	u_int32_t	bad_rx_number;
5386752Sfjoe	u_int32_t	timeout_number;
5486752Sfjoe	u_int32_t	all_tx_number;
5586752Sfjoe	u_int32_t	resend_tx_number;
5686752Sfjoe};
5786752Sfjoe
5886752Sfjoestruct sbni_flags {
5986752Sfjoe	u_int	mac_addr	: 24;
6086752Sfjoe	u_int	rxl		: 4;
6186752Sfjoe	u_int	rate		: 2;
6286752Sfjoe	u_int	fixed_rxl	: 1;
6386752Sfjoe	u_int	fixed_rate	: 1;
6486752Sfjoe};
6586752Sfjoe
6686752Sfjoe
6786752Sfjoe#ifdef _KERNEL	/* to avoid compile this decls with sbniconfig */
6886752Sfjoe
6986752Sfjoestruct sbni_softc {
70147256Sbrooks	struct	ifnet *ifp;
71180263Sjhb	device_t dev;
72147256Sbrooks	u_char	enaddr[6];
7386752Sfjoe
7486752Sfjoe	int	io_rid;
75101400Sfjoe	struct	resource *io_res;
76101400Sfjoe	int	io_off;
77101400Sfjoe
7886752Sfjoe	int	irq_rid;
7986752Sfjoe	struct	resource *irq_res;
8086752Sfjoe	void	*irq_handle;
8186752Sfjoe
8286752Sfjoe	struct	mbuf *rx_buf_p;		/* receive buffer ptr */
8386752Sfjoe	struct	mbuf *tx_buf_p;		/* transmit buffer ptr */
8486752Sfjoe
8586752Sfjoe	u_int	pktlen;			/* length of transmitting pkt */
8686752Sfjoe	u_int	framelen;		/* current frame length */
8786752Sfjoe	u_int	maxframe;		/* maximum valid frame length */
8886752Sfjoe	u_int	state;
8986752Sfjoe	u_int	inppos;			/* positions in rx/tx buffers */
9086752Sfjoe	u_int	outpos;			/* positions in rx/tx buffers */
9186752Sfjoe
9286752Sfjoe	/* transmitting frame number - from frames qty to 1 */
9386752Sfjoe	u_int	tx_frameno;
9486752Sfjoe
9586752Sfjoe	/* expected number of next receiving frame */
9686752Sfjoe	u_int	wait_frameno;
9786752Sfjoe
9886752Sfjoe	/* count of failed attempts to frame send - 32 attempts do before
9986752Sfjoe	   error - while receiver tunes on opposite side of wire */
10086752Sfjoe	u_int	trans_errors;
10186752Sfjoe
10286752Sfjoe	/* idle time; send pong when limit exceeded */
10386752Sfjoe	u_int	timer_ticks;
10486752Sfjoe
10586752Sfjoe	/* fields used for receive level autoselection */
10686752Sfjoe	int	delta_rxl;
10786752Sfjoe	u_int	cur_rxl_index;
10886752Sfjoe	u_int	timeout_rxl;
10986752Sfjoe	u_int32_t	cur_rxl_rcvd;
11086752Sfjoe	u_int32_t	prev_rxl_rcvd;
11186752Sfjoe
11286752Sfjoe	struct	sbni_csr1 csr1;			/* current value of CSR1 */
11386752Sfjoe	struct	sbni_in_stats in_stats; 	/* internal statistics */
11486752Sfjoe
115180263Sjhb	struct	callout wch;
116180263Sjhb	struct	mtx lock;
11786752Sfjoe
11886752Sfjoe	struct	sbni_softc *slave_sc;
11986752Sfjoe
12086752Sfjoe#ifdef SBNI_DUAL_COMPOUND
12186752Sfjoe	struct	sbni_softc *link;
12286752Sfjoe#endif
12386752Sfjoe};
12486752Sfjoe
125180263Sjhb#define	SBNI_LOCK(sc)		mtx_lock(&(sc)->lock)
126180263Sjhb#define	SBNI_UNLOCK(sc)		mtx_unlock(&(sc)->lock)
127180263Sjhb#define	SBNI_ASSERT_LOCKED(sc)	mtx_assert(&(sc)->lock, MA_OWNED)
128180263Sjhb
12986752Sfjoevoid	sbni_intr(void *);
13086752Sfjoeint	sbni_probe(struct sbni_softc *);
131180263Sjhbint	sbni_attach(struct sbni_softc *, int, struct sbni_flags);
132180263Sjhbvoid	sbni_detach(struct sbni_softc *);
133180263Sjhbvoid	sbni_release_resources(struct sbni_softc *);
13486752Sfjoe
13586752Sfjoeextern u_int32_t next_sbni_unit;
13686752Sfjoe
13786752Sfjoe#ifdef SBNI_DUAL_COMPOUND
138180263Sjhbvoid			sbni_add(struct sbni_softc *);
13986752Sfjoestruct sbni_softc	*connect_to_master(struct sbni_softc *);
14086752Sfjoe#endif
14186752Sfjoe#endif	/* _KERNEL */
14286752Sfjoe
14386752Sfjoe/*
14486752Sfjoe * SBNI socket ioctl params
14586752Sfjoe */
14686752Sfjoe#define	SIOCGHWFLAGS	_IOWR('i', 62, struct ifreq)	/* get flags */
14786752Sfjoe#define	SIOCSHWFLAGS	_IOWR('i', 61, struct ifreq)	/* set flags */
14886752Sfjoe#define SIOCGINSTATS	_IOWR('i', 60, struct ifreq)	/* get internal stats */
14986752Sfjoe#define SIOCRINSTATS	_IOWR('i', 63, struct ifreq)	/* reset internal stats */
15086752Sfjoe
15186752Sfjoe
15286752Sfjoe/*
15386752Sfjoe * CRC-32 stuff
15486752Sfjoe */
15586752Sfjoe#define CRC32(c,crc) (crc32tab[((size_t)(crc) ^ (c)) & 0xff] ^ (((crc) >> 8) & 0x00ffffff))
15686752Sfjoe      /* CRC generator EDB88320 */
15786752Sfjoe      /* CRC remainder 2144DF1C */
15886752Sfjoe      /* CRC initial value 0 */
15986752Sfjoe#define CRC32_REMAINDER 0x2144df1c
16086752Sfjoe#define CRC32_INITIAL 0x00000000
161