Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / dev / netif / lnc / if_lnc.h
1 /*-
2  * Copyright (c) 1994-1998
3  *      Paul Richards.  All rights reserved.
4  *
5  * Redistribution 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, this list of conditions and the following disclaimer,
10  *    verbatim and that no modifications are made prior to this
11  *    point in the file.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Paul Richards.
18  * 4. The name Paul Richards may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY PAUL RICHARDS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL PAUL RICHARDS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * $FreeBSD: src/sys/i386/isa/if_lnc.h,v 1.14.2.1 2000/06/18 08:03:51 gj Exp $
34  */
35
36 #include <i386/isa/ic/Am7990.h>
37
38 /*
39  * Initialize multicast address hashing registers to accept
40  * all multicasts (only used when in promiscuous mode)
41  */
42 #define MULTI_INIT_ADDR 0xff
43
44 #define NORMAL 0
45
46 #define NRDRE 3
47 #define NTDRE 3
48 #define RECVBUFSIZE 1518        /* Packet size rounded to dword boundary */
49 #define TRANSBUFSIZE 1518
50 #define MBUF_CACHE_LIMIT 0
51
52 #define MEM_SLEW 8
53
54 /* LNC Flags */
55 #define LNC_INITIALISED 1
56 #define LNC_ALLMULTI 2
57
58 /* BICC port addresses */
59 #define BICC_IOSIZE    16
60 #define BICC_RDP     0x0c        /* Register Data Port */
61 #define BICC_RAP     0x0e        /* Register Address Port */
62
63 /* NE2100 port addresses */
64 #define NE2100_IOSIZE  24
65 #define PCNET_RDP    0x10        /* Register Data Port */
66 #define PCNET_RAP    0x12        /* Register Address Port */
67 #define PCNET_RESET  0x14
68 #define PCNET_BDP    0x16
69 #define PCNET_VSW    0x18
70
71 /* DEPCA port addresses */
72 #define DEPCA_IOSIZE   16
73 #define DEPCA_CTRL   0x00        /* NIC Control and status register */
74 #define DEPCA_RDP    0x04        /* Register Data Port */
75 #define DEPCA_RAP    0x06        /* Register Address Port */
76 #define DEPCA_ADP    0x0c
77
78 /* DEPCA specific defines */
79 #define DEPCA_ADDR_ROM_SIZE 32
80
81 #ifdef PC98
82 /* C-NET(98)S port addresses */
83 #define CNET98S_RDP    0x400     /* Register Data Port */
84 #define CNET98S_RAP    0x402     /* Register Address Port */
85 #define CNET98S_RESET  0x404
86 #define CNET98S_IDP    0x406
87 #define CNET98S_EEPROM 0x40e
88 /*
89  * XXX - The I/O address range is fragmented in the C-NET(98)S.
90  *       This is the number of regs at iobase.
91  */
92 #define CNET98S_IOSIZE    16     /* # of i/o addresses used. */
93 #endif
94
95 /* Chip types */
96 #define LANCE           1        /* Am7990   */
97 #define C_LANCE         2        /* Am79C90  */
98 #define PCnet_ISA       3        /* Am79C960 */
99 #define PCnet_ISAplus   4        /* Am79C961 */
100 #define PCnet_ISA_II    5        /* Am79C961A */
101 #define PCnet_32        6        /* Am79C965 */
102 #define PCnet_PCI       7        /* Am79C970 */
103 #define PCnet_PCI_II    8        /* Am79C970A */
104 #define PCnet_FAST      9        /* Am79C971 */
105 #define PCnet_FASTplus  10       /* Am79C972 */
106 #define PCnet_Home      11       /* Am79C978 */
107
108
109 /* CSR88-89: Chip ID masks */
110 #define AMD_MASK  0x003
111 #define PART_MASK 0xffff
112 #define Am79C960  0x0003
113 #define Am79C961  0x2260
114 #define Am79C961A 0x2261
115 #define Am79C965  0x2430
116 #define Am79C970  0x0242
117 #define Am79C970A 0x2621
118 #define Am79C971  0x2623
119 #define Am79C972  0x2624
120 #define Am79C973  0x2625
121 #define Am79C978  0x2626
122
123 /* Board types */
124 #define UNKNOWN         0
125 #define BICC            1
126 #define NE2100          2
127 #define DEPCA           3
128 #define CNET98S         4       /* PC-98 */
129
130 /* mem_mode values */
131 #define DMA_FIXED       1
132 #define DMA_MBUF        2
133 #define SHMEM           4
134
135 #define MEM_MODES \
136         "\20\3SHMEM\2DMA_MBUF\1DMA_FIXED"
137
138 #define CSR0_FLAGS \
139         "\20\20ERR\17BABL\16CERR\15MISS\14MERR\13RINT\12TINT\11IDON\
140             \10INTR\07INEA\06RXON\05TXON\04TDMD\03STOP\02STRT\01INIT"
141
142 #define INIT_MODE \
143         "\20\20PROM\07INTL\06DRTY\05COLL\04DTCR\03LOOP\02DTX\01DRX"
144
145 #define RECV_MD1 \
146         "\20\10OWN\7ERR\6FRAM\5OFLO\4CRC\3BUFF\2STP\1ENP"
147
148 #define TRANS_MD1 \
149         "\20\10OWN\7ERR\6RES\5MORE\4ONE\3DEF\2STP\1ENP"
150
151 #define TRANS_MD3 \
152         "\20\6BUFF\5UFLO\4RES\3LCOL\2LCAR\1RTRY"
153
154 struct nic_info {
155         int ident;         /* Type of card */
156         int ic;            /* Type of ic, Am7990, Am79C960 etc. */
157         int mem_mode;
158         int iobase;
159         int mode;          /* Mode setting at initialization */
160 };
161
162 struct host_ring_entry {
163         struct mds *md;
164         union {
165                 struct mbuf *mbuf;
166                 char *data;
167         }buff;
168 };
169
170 #ifdef LNC_KEEP_STATS
171 #define LNCSTATS_STRUCT \
172         struct lnc_stats { \
173                 int idon; \
174                 int rint; \
175                 int tint; \
176                 int cerr; \
177                 int babl; \
178                 int miss; \
179                 int merr; \
180                 int rxoff; \
181                 int txoff; \
182                 int terr; \
183                 int lcol; \
184                 int lcar; \
185                 int tbuff; \
186                 int def; \
187                 int more; \
188                 int one; \
189                 int uflo; \
190                 int rtry; \
191                 int rerr; \
192                 int fram; \
193                 int oflo; \
194                 int crc; \
195                 int rbuff; \
196                 int drop_packet; \
197                 int trans_ring_full; \
198         } lnc_stats;
199 #define LNCSTATS(X) ++(sc->lnc_stats.X);
200 #else
201 #define LNCSTATS_STRUCT
202 #define LNCSTATS(X)
203 #endif
204
205 #define NDESC(len2) (1 << len2)
206
207 #define INC_MD_PTR(ptr, no_entries) \
208         if (++ptr >= NDESC(no_entries)) \
209                 ptr = 0;
210
211 #define DEC_MD_PTR(ptr, no_entries) \
212         if (--ptr < 0) \
213                 ptr = NDESC(no_entries) - 1;
214
215 #define RECV_NEXT (sc->recv_ring->base + sc->recv_next)
216 #define TRANS_NEXT (sc->trans_ring->base + sc->trans_next)