xref: /freebsd/sys/dev/sbni/if_sbnivar.h (revision 7899f917b1c0ea178f1d2be0cfb452086d079d23)
1 /*-
2  * Copyright (c) 1997-2001 Granch, Ltd. All rights reserved.
3  * Author: Denis I.Timofeev <timofeev@granch.ru>
4  *
5  * Redistributon and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice unmodified, this list of conditions, and the following
10  *    disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 /*
29  * SBNI12 definitions
30  */
31 
32 /*
33  * CONFIGURATION PARAMETER:
34  *
35  *	Uncomment this if you want to use model SBNI12D-11/ISA with same IRQ
36  *	for both first and second channels.
37  */
38 #define SBNI_DUAL_COMPOUND 1
39 
40 #define SBNI_DEBUG 0
41 
42 #if SBNI_DEBUG
43 #define DP(A) A
44 #else
45 #define DP(A)
46 #endif
47 
48 struct sbni_in_stats {
49 	u_int32_t	all_rx_number;
50 	u_int32_t	bad_rx_number;
51 	u_int32_t	timeout_number;
52 	u_int32_t	all_tx_number;
53 	u_int32_t	resend_tx_number;
54 };
55 
56 struct sbni_flags {
57 	u_int	mac_addr	: 24;
58 	u_int	rxl		: 4;
59 	u_int	rate		: 2;
60 	u_int	fixed_rxl	: 1;
61 	u_int	fixed_rate	: 1;
62 };
63 
64 #ifdef _KERNEL	/* to avoid compile this decls with sbniconfig */
65 
66 struct sbni_softc {
67 	struct	ifnet *ifp;
68 	device_t dev;
69 	u_char	enaddr[6];
70 
71 	int	io_rid;
72 	struct	resource *io_res;
73 	int	io_off;
74 
75 	int	irq_rid;
76 	struct	resource *irq_res;
77 	void	*irq_handle;
78 
79 	struct	mbuf *rx_buf_p;		/* receive buffer ptr */
80 	struct	mbuf *tx_buf_p;		/* transmit buffer ptr */
81 
82 	u_int	pktlen;			/* length of transmitting pkt */
83 	u_int	framelen;		/* current frame length */
84 	u_int	maxframe;		/* maximum valid frame length */
85 	u_int	state;
86 	u_int	inppos;			/* positions in rx/tx buffers */
87 	u_int	outpos;			/* positions in rx/tx buffers */
88 
89 	/* transmitting frame number - from frames qty to 1 */
90 	u_int	tx_frameno;
91 
92 	/* expected number of next receiving frame */
93 	u_int	wait_frameno;
94 
95 	/* count of failed attempts to frame send - 32 attempts do before
96 	   error - while receiver tunes on opposite side of wire */
97 	u_int	trans_errors;
98 
99 	/* idle time; send pong when limit exceeded */
100 	u_int	timer_ticks;
101 
102 	/* fields used for receive level autoselection */
103 	int	delta_rxl;
104 	u_int	cur_rxl_index;
105 	u_int	timeout_rxl;
106 	u_int32_t	cur_rxl_rcvd;
107 	u_int32_t	prev_rxl_rcvd;
108 
109 	struct	sbni_csr1 csr1;			/* current value of CSR1 */
110 	struct	sbni_in_stats in_stats; 	/* internal statistics */
111 
112 	struct	callout wch;
113 	struct	mtx lock;
114 
115 	struct	sbni_softc *slave_sc;
116 
117 #ifdef SBNI_DUAL_COMPOUND
118 	struct	sbni_softc *link;
119 #endif
120 };
121 
122 #define	SBNI_LOCK(sc)		mtx_lock(&(sc)->lock)
123 #define	SBNI_UNLOCK(sc)		mtx_unlock(&(sc)->lock)
124 #define	SBNI_ASSERT_LOCKED(sc)	mtx_assert(&(sc)->lock, MA_OWNED)
125 
126 void	sbni_intr(void *);
127 int	sbni_probe(struct sbni_softc *);
128 void	sbni_attach(struct sbni_softc *, int, struct sbni_flags);
129 void	sbni_detach(struct sbni_softc *);
130 void	sbni_release_resources(struct sbni_softc *);
131 
132 extern u_int32_t next_sbni_unit;
133 
134 #ifdef SBNI_DUAL_COMPOUND
135 void			sbni_add(struct sbni_softc *);
136 struct sbni_softc	*connect_to_master(struct sbni_softc *);
137 #endif
138 #endif	/* _KERNEL */
139 
140 /*
141  * SBNI socket ioctl params
142  */
143 #define	SIOCGHWFLAGS	_IOWR('i', 62, struct ifreq)	/* get flags */
144 #define	SIOCSHWFLAGS	_IOWR('i', 61, struct ifreq)	/* set flags */
145 #define SIOCGINSTATS	_IOWR('i', 60, struct ifreq)	/* get internal stats */
146 #define SIOCRINSTATS	_IOWR('i', 63, struct ifreq)	/* reset internal stats */
147 
148 /*
149  * CRC-32 stuff
150  */
151 #define CRC32(c,crc) (crc32tab[((size_t)(crc) ^ (c)) & 0xff] ^ (((crc) >> 8) & 0x00ffffff))
152       /* CRC generator EDB88320 */
153       /* CRC remainder 2144DF1C */
154       /* CRC initial value 0 */
155 #define CRC32_REMAINDER 0x2144df1c
156 #define CRC32_INITIAL 0x00000000
157