Correct typo in comment
[dragonfly.git] / sys / dev / netif / lnc / if_lncvar.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/dev/lnc/if_lncvar.h,v 1.23 2001/07/04 13:00:20 nyan Exp $
34  * $DragonFly: src/sys/dev/netif/lnc/Attic/if_lncvar.h,v 1.2 2005/06/13 22:55:15 joerg Exp $
35  */
36
37 /*
38  * Initialize multicast address hashing registers to accept
39  * all multicasts (only used when in promiscuous mode)
40  */
41 #define MULTI_INIT_ADDR 0xff
42
43 #define NORMAL 0
44
45 #define NRDRE 3
46 #define NTDRE 3
47 #define RECVBUFSIZE 1518        /* Packet size rounded to dword boundary */
48 #define TRANSBUFSIZE 1518
49 #define MBUF_CACHE_LIMIT 0
50
51 #define MEM_SLEW 8
52
53 /* LNC Flags */
54 #define LNC_INITIALISED 1
55 #define LNC_ALLMULTI 2
56
57 /* BICC port addresses */
58 #define BICC_IOSIZE    16
59 #define BICC_RDP     0x0c        /* Register Data Port */
60 #define BICC_RAP     0x0e        /* Register Address Port */
61
62 /* NE2100 port addresses */
63 #define NE2100_IOSIZE  24
64 #define PCNET_RDP    0x10        /* Register Data Port */
65 #define PCNET_RAP    0x12        /* Register Address Port */
66 #define PCNET_RESET  0x14
67 #define PCNET_BDP    0x16
68 #define PCNET_VSW    0x18
69
70 /* DEPCA port addresses */
71 #define DEPCA_IOSIZE   16
72 #define DEPCA_CTRL   0x00        /* NIC Control and status register */
73 #define DEPCA_RDP    0x04        /* Register Data Port */
74 #define DEPCA_RAP    0x06        /* Register Address Port */
75 #define DEPCA_ADP    0x0c
76
77 /* DEPCA specific defines */
78 #define DEPCA_ADDR_ROM_SIZE 32
79
80 /* C-NET(98)S port addresses */
81 /* Notice, we can ignore fragmantation by using isa_alloc_resourcev(). */
82 #define CNET98S_IOSIZE   32     
83 #define CNET98S_RDP    0x10      /* Register Data Port */
84 #define CNET98S_RAP    0x12      /* Register Address Port */
85 #define CNET98S_RESET  0x14
86 #define CNET98S_IDP    0x16
87 #define CNET98S_EEPROM 0x1e
88
89 /* Chip types */
90 #define LANCE           1        /* Am7990   */
91 #define C_LANCE         2        /* Am79C90  */
92 #define PCnet_ISA       3        /* Am79C960 */
93 #define PCnet_ISAplus   4        /* Am79C961 */
94 #define PCnet_ISA_II    5        /* Am79C961A */
95 #define PCnet_32        6        /* Am79C965 */
96 #define PCnet_PCI       7        /* Am79C970 */
97 #define PCnet_PCI_II    8        /* Am79C970A */
98 #define PCnet_FAST      9        /* Am79C971 */
99 #define PCnet_FASTplus  10       /* Am79C972 */
100 #define PCnet_Home      11       /* Am79C978 */
101
102
103 /* CSR88-89: Chip ID masks */
104 #define AMD_MASK  0x003
105 #define PART_MASK 0xffff
106 #define Am79C960  0x0003
107 #define Am79C961  0x2260
108 #define Am79C961A 0x2261
109 #define Am79C965  0x2430
110 #define Am79C970  0x0242
111 #define Am79C970A 0x2621
112 #define Am79C971  0x2623
113 #define Am79C972  0x2624
114 #define Am79C973  0x2625
115 #define Am79C978  0x2626
116
117 /* Board types */
118 #define UNKNOWN         0
119 #define BICC            1
120 #define NE2100          2
121 #define DEPCA           3
122 #define CNET98S         4       /* PC-98 */
123
124 /* mem_mode values */
125 #define DMA_FIXED       1
126 #define DMA_MBUF        2
127 #define SHMEM           4
128
129 #define MEM_MODES \
130         "\20\3SHMEM\2DMA_MBUF\1DMA_FIXED"
131
132 #define CSR0_FLAGS \
133         "\20\20ERR\17BABL\16CERR\15MISS\14MERR\13RINT\12TINT\11IDON\
134             \10INTR\07INEA\06RXON\05TXON\04TDMD\03STOP\02STRT\01INIT"
135
136 #define INIT_MODE \
137         "\20\20PROM\07INTL\06DRTY\05COLL\04DTCR\03LOOP\02DTX\01DRX"
138
139 #define RECV_MD1 \
140         "\20\10OWN\7ERR\6FRAM\5OFLO\4CRC\3BUFF\2STP\1ENP"
141
142 #define TRANS_MD1 \
143         "\20\10OWN\7ERR\6RES\5MORE\4ONE\3DEF\2STP\1ENP"
144
145 #define TRANS_MD3 \
146         "\20\6BUFF\5UFLO\4RES\3LCOL\2LCAR\1RTRY"
147
148 #ifdef LNC_KEEP_STATS
149 #define LNCSTATS_STRUCT \
150         struct lnc_stats { \
151                 int idon; \
152                 int rint; \
153                 int tint; \
154                 int cerr; \
155                 int babl; \
156                 int miss; \
157                 int merr; \
158                 int rxoff; \
159                 int txoff; \
160                 int terr; \
161                 int lcol; \
162                 int lcar; \
163                 int tbuff; \
164                 int def; \
165                 int more; \
166                 int one; \
167                 int uflo; \
168                 int rtry; \
169                 int rerr; \
170                 int fram; \
171                 int oflo; \
172                 int crc; \
173                 int rbuff; \
174                 int drop_packet; \
175                 int trans_ring_full; \
176         } lnc_stats;
177 #define LNCSTATS(X) ++(sc->lnc_stats.X);
178 #else
179 #define LNCSTATS_STRUCT
180 #define LNCSTATS(X)
181 #endif
182
183 struct nic_info {
184         int ident;         /* Type of card */
185         int ic;            /* Type of ic, Am7990, Am79C960 etc. */
186         int mem_mode;
187         int iobase;
188         int mode;          /* Mode setting at initialization */
189 };
190
191 typedef struct lnc_softc {
192         struct resource *irqres;
193         int irqrid;
194         struct resource *drqres;
195         int drqrid;
196         struct resource *portres;
197         int portrid;
198         bus_space_tag_t lnc_btag;
199         bus_space_handle_t lnc_bhandle;
200         void *intrhand;
201         bus_dma_tag_t   dmat;
202         bus_dmamap_t    dmamap;
203         struct arpcom arpcom;               /* see ../../net/if_arp.h */
204         struct nic_info nic;                /* NIC specific info */
205         int nrdre;
206         struct host_ring_entry *recv_ring;  /* start of alloc'd mem */
207         int recv_next;
208         int ntdre;
209         struct host_ring_entry *trans_ring;
210         int trans_next;
211         struct init_block *init_block;      /* Initialisation block */
212         int pending_transmits;        /* No. of transmit descriptors in
213         use */
214         int next_to_send;
215         struct mbuf *mbufs;
216         int mbuf_count;
217         int flags;
218         int rap;
219         int rdp;
220         int bdp;
221         #ifdef DEBUG
222         int lnc_debug;
223         #endif
224         LNCSTATS_STRUCT
225 } lnc_softc_t;
226
227 struct host_ring_entry {
228         struct mds *md;
229         union {
230                 struct mbuf *mbuf;
231                 char *data;
232         }buff;
233 };
234
235 #define NDESC(len2) (1 << len2)
236
237 #define INC_MD_PTR(ptr, no_entries) \
238         if (++ptr >= NDESC(no_entries)) \
239                 ptr = 0;
240
241 #define DEC_MD_PTR(ptr, no_entries) \
242         if (--ptr < 0) \
243                 ptr = NDESC(no_entries) - 1;
244
245 #define RECV_NEXT (sc->recv_ring->base + sc->recv_next)
246 #define TRANS_NEXT (sc->trans_ring->base + sc->trans_next)
247
248 #define lnc_inb(port) \
249         bus_space_read_1(sc->lnc_btag, sc->lnc_bhandle, (port))
250 #define lnc_inw(port) \
251         bus_space_read_2(sc->lnc_btag, sc->lnc_bhandle, (port))
252 #define lnc_outw(port, val) \
253         bus_space_write_2(sc->lnc_btag, sc->lnc_bhandle, (port), (val))
254
255 /* Functional declarations */
256 extern int lance_probe(struct lnc_softc *);
257 extern int lnc_attach_common(device_t);
258 extern void lnc_stop(struct lnc_softc *);
259
260 extern void write_csr(struct lnc_softc *, u_short, u_short);
261 extern u_short read_csr(struct lnc_softc *, u_short);
262
263 /* Variable declarations */
264 extern driver_intr_t lncintr; 
265 extern devclass_t lnc_devclass;