xref: /freebsd/sys/dev/ic/i82586.h (revision 42249ef2)
1 /*-
2  * SPDX-License-Identifier: BSD-4-Clause
3  *
4  * Copyright (c) 1992, University of Vermont and State Agricultural College.
5  * Copyright (c) 1992, Garrett A. Wollman.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by the University of
19  *	Vermont and State Agricultural College and Garrett A. Wollman.
20  * 4. Neither the name of the University nor the name of the author
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR AUTHOR BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  * $FreeBSD$
37  */
38 
39 /*
40  * Intel 82586 Ethernet chip
41  * Register, bit, and structure definitions.
42  *
43  * Written by GAW with reference to the Clarkson Packet Driver code for this
44  * chip written by Russ Nelson and others.
45  */
46 
47 struct ie_en_addr {
48 	u_char data[6];
49 };
50 
51 /*
52  * This is the master configuration block.  It tells the hardware where all
53  * the rest of the stuff is.
54  */
55 struct ie_sys_conf_ptr {
56 	u_short mbz;			/* must be zero */
57 	u_char ie_bus_use;		/* true if 8-bit only */
58 	u_char mbz2[5];			/* must be zero */
59 	caddr_t ie_iscp_ptr;		/* 24-bit physaddr of ISCP */
60 };
61 
62 /*
63  * Note that this is wired in hardware; the SCP is always located here, no
64  * matter what.
65  */
66 #define IE_SCP_ADDR 0xfffff4
67 
68 /*
69  * The tells the hardware where all the rest of the stuff is, too.
70  * FIXME: some of these should be re-commented after we figure out their
71  * REAL function.
72  */
73 struct ie_int_sys_conf_ptr {
74 	u_char ie_busy;			/* zeroed after init */
75 	u_char mbz;
76 	u_short ie_scb_offset;		/* 16-bit physaddr of next struct */
77 	caddr_t ie_base;		/* 24-bit physaddr for all 16-bit vars */
78 };
79 
80 /*
81  * This FINALLY tells the hardware what to do and where to put it.
82  */
83 struct ie_sys_ctl_block {
84 	u_short ie_status;		/* status word */
85 	u_short ie_command;		/* command word */
86 	u_short ie_command_list;	/* 16-pointer to command block list */
87 	u_short ie_recv_list;		/* 16-pointer to receive frame list */
88 	u_short ie_err_crc;		/* CRC errors */
89 	u_short ie_err_align;		/* Alignment errors */
90 	u_short ie_err_resource;	/* Resource errors */
91 	u_short ie_err_overrun;		/* Overrun errors */
92 };
93 
94 /* Command values */
95 #define IE_RU_COMMAND	0x0070	/* mask for RU command */
96 #define IE_RU_NOP	0	/* for completeness */
97 #define IE_RU_START	0x0010	/* start receive unit command */
98 #define IE_RU_ENABLE	0x0020	/* enable receiver command */
99 #define IE_RU_DISABLE	0x0030	/* disable receiver command */
100 #define IE_RU_ABORT	0x0040	/* abort current receive operation */
101 
102 #define IE_CU_COMMAND	0x0700	/* mask for CU command */
103 #define IE_CU_NOP	0	/* included for completeness */
104 #define IE_CU_START	0x0100	/* do-command command */
105 #define IE_CU_RESUME	0x0200	/* resume a suspended cmd list */
106 #define IE_CU_STOP	0x0300	/* SUSPEND was already taken */
107 #define IE_CU_ABORT	0x0400	/* abort current command */
108 
109 #define IE_ACK_COMMAND	0xf000	/* mask for ACK command */
110 #define IE_ACK_CX	0x8000	/* ack IE_ST_DONE */
111 #define IE_ACK_FR	0x4000	/* ack IE_ST_RECV */
112 #define IE_ACK_CNA	0x2000	/* ack IE_ST_ALLDONE */
113 #define IE_ACK_RNR	0x1000	/* ack IE_ST_RNR */
114 
115 #define IE_ACTION_COMMAND(x) (((x) & IE_CU_COMMAND) == IE_CU_START)
116 				/* is this command an action command? */
117 
118 /* Status values */
119 #define IE_ST_WHENCE	0xf000	/* mask for cause of interrupt */
120 #define IE_ST_DONE	0x8000	/* command with I bit completed */
121 #define IE_ST_RECV	0x4000	/* frame received */
122 #define IE_ST_ALLDONE	0x2000	/* all commands completed */
123 #define IE_ST_RNR	0x1000	/* receive not ready */
124 
125 #define IE_CU_STATUS	0x700	/* mask for command unit status */
126 #define IE_CU_ACTIVE	0x200	/* command unit is active */
127 #define IE_CU_SUSPEND	0x100	/* command unit is suspended */
128 
129 #define IE_RU_STATUS	0x70	/* mask for receiver unit status */
130 #define IE_RU_SUSPEND	0x10	/* receiver is suspended */
131 #define IE_RU_NOSPACE	0x20	/* receiver has no resources */
132 #define IE_RU_READY	0x40	/* reveiver is ready */
133 
134 /*
135  * This is filled in partially by the chip, partially by us.
136  */
137 struct ie_recv_frame_desc {
138 	u_short ie_fd_status;		/* status for this frame */
139 	u_short ie_fd_last;		/* end of frame list flag */
140 	u_short ie_fd_next;		/* 16-pointer to next RFD */
141 	u_short ie_fd_buf_desc;		/* 16-pointer to list of buffer desc's */
142 	struct ie_en_addr dest;		/* destination ether */
143 	struct ie_en_addr src;		/* source ether */
144 	u_short ie_length;		/* 802 length/Ether type */
145 	u_short mbz;			/* must be zero */
146 };
147 
148 #define IE_FD_LAST	0x8000	/* last rfd in list */
149 #define IE_FD_SUSP	0x4000	/* suspend RU after receipt */
150 
151 #define IE_FD_COMPLETE	0x8000	/* frame is complete */
152 #define IE_FD_BUSY	0x4000	/* frame is busy */
153 #define IE_FD_OK	0x2000	/* frame is bad */
154 #define IE_FD_RNR	0x0200	/* receiver out of resources here */
155 
156 /*
157  * linked list of buffers...
158  */
159 struct ie_recv_buf_desc {
160 	u_short ie_rbd_actual;		/* status for this buffer */
161 	u_short ie_rbd_next;		/* 16-pointer to next RBD */
162 	caddr_t ie_rbd_buffer;		/* 24-pointer to buffer for this RBD */
163 	u_short ie_rbd_length;		/* length of the buffer */
164 	u_short mbz;			/* must be zero */
165 };
166 
167 #define IE_RBD_LAST	0x8000	/* last buffer */
168 #define IE_RBD_USED	0x4000	/* this buffer has data */
169 /*
170  * All commands share this in common.
171  */
172 struct ie_cmd_common {
173 	u_short ie_cmd_status;		/* status of this command */
174 	u_short ie_cmd_cmd;		/* command word */
175 	u_short ie_cmd_link;		/* link to next command */
176 };
177 
178 #define IE_STAT_COMPL	0x8000	/* command is completed */
179 #define IE_STAT_BUSY	0x4000	/* command is running now */
180 #define IE_STAT_OK	0x2000	/* command completed successfully */
181 
182 #define IE_CMD_NOP	0x0000	/* NOP */
183 #define IE_CMD_IASETUP	0x0001	/* initial address setup */
184 #define IE_CMD_CONFIG	0x0002	/* configure command */
185 #define IE_CMD_MCAST	0x0003	/* multicast setup command */
186 #define IE_CMD_XMIT	0x0004	/* transmit command */
187 #define IE_CMD_TDR	0x0005	/* time-domain reflectometer command */
188 #define IE_CMD_DUMP	0x0006	/* dump command */
189 #define IE_CMD_DIAGNOSE	0x0007	/* diagnostics command */
190 
191 #define IE_CMD_LAST	0x8000	/* this is the last command in the list */
192 #define IE_CMD_SUSPEND	0x4000	/* suspend CU after this command */
193 #define IE_CMD_INTR	0x2000	/* post an interrupt after completion */
194 
195 /*
196  * This is the command to transmit a frame.
197  */
198 struct ie_xmit_cmd {
199 	struct ie_cmd_common com;	/* common part */
200 #define ie_xmit_status com.ie_cmd_status
201 
202 	u_short ie_xmit_desc;		/* 16-pointer to buffer descriptor */
203 	struct ie_en_addr ie_xmit_addr; /* destination address */
204 
205 	u_short ie_xmit_length;		/* 802.3 length/Ether type field */
206 };
207 
208 #define IE_XS_MAXCOLL  	0x000f	/* number of collisions during transmit */
209 #define IE_XS_EXCMAX	0x0020	/* exceeded maximum number of collisions */
210 #define IE_XS_SQE	0x0040	/* SQE positive */
211 #define IE_XS_DEFERRED	0x0080	/* transmission deferred */
212 #define IE_XS_UNDERRUN	0x0100	/* DMA underrun */
213 #define IE_XS_LOSTCTS	0x0200	/* Lost CTS */
214 #define IE_XS_NOCARRIER	0x0400	/* No Carrier */
215 #define IE_XS_LATECOLL	0x0800	/* Late collision */
216 
217 /*
218  * This is a buffer descriptor for a frame to be transmitted.
219  */
220 
221 struct ie_xmit_buf {
222 	u_short ie_xmit_flags;		/* see below */
223 	u_short ie_xmit_next;		/* 16-pointer to next desc. */
224 	caddr_t ie_xmit_buf;		/* 24-pointer to the actual buffer */
225 };
226 
227 #define IE_XMIT_LAST 0x8000	/* this TBD is the last one */
228 /* The rest of the `flags' word is actually the length. */
229 
230 /*
231  * Multicast setup command.
232  */
233 
234 #define MAXMCAST 50		/* must fit in transmit buffer */
235 
236 struct ie_mcast_cmd {
237 	struct ie_cmd_common com;	/* common part */
238 #define ie_mcast_status com.ie_cmd_status
239 
240 	u_short ie_mcast_bytes;	/* size (in bytes) of multicast addresses */
241 	struct ie_en_addr ie_mcast_addrs[MAXMCAST + 1];	/* space for them */
242 };
243 
244 /*
245  * Time Domain Reflectometer command.
246  */
247 
248 struct ie_tdr_cmd {
249 	struct ie_cmd_common com;	/* common part */
250 #define ie_tdr_status com.ie_cmd_status
251 
252 	u_short ie_tdr_time;		/* error bits and time */
253 };
254 
255 #define IE_TDR_SUCCESS	0x8000	/* TDR succeeded without error */
256 #define IE_TDR_XCVR	0x4000	/* detected a transceiver problem */
257 #define IE_TDR_OPEN	0x2000	/* detected an open */
258 #define IE_TDR_SHORT	0x1000	/* TDR detected a short */
259 #define IE_TDR_TIME	0x07ff	/* mask for reflection time */
260 
261 /*
262  * Initial Address Setup command
263  */
264 struct ie_iasetup_cmd {
265 	struct ie_cmd_common com;
266 #define ie_iasetup_status com.ie_cmd_status
267 
268 	struct ie_en_addr ie_address;
269 };
270 
271 /*
272  * Configuration command
273  */
274 struct ie_config_cmd {
275 	struct ie_cmd_common com;	/* common part */
276 #define ie_config_status com.ie_cmd_status
277 
278 	u_char ie_config_count;		/* byte count (0x0c) */
279 	u_char ie_fifo;			/* fifo (8) */
280 	u_char ie_save_bad;		/* save bad frames (0x40) */
281 	u_char ie_addr_len;		/* address length (0x2e) (AL-LOC == 1) */
282 	u_char ie_priority;		/* priority and backoff (0x0) */
283 	u_char ie_ifs;			/* inter-frame spacing (0x60) */
284 	u_char ie_slot_low;		/* slot time, LSB (0x0) */
285 	u_char ie_slot_high;		/* slot time, MSN, and retries (0xf2) */
286 	u_char ie_promisc;		/* 1 if promiscuous, else 0 */
287 	u_char ie_crs_cdt;		/* CSMA/CD parameters (0x0) */
288 	u_char ie_min_len;		/* min frame length (0x40) */
289 	u_char ie_junk;			/* stuff for 82596 (0xff) */
290 };
291 
292 /*
293  * Here are a few useful functions.  We could have done these as macros,
294  * but since we have the inline facility, it makes sense to use that
295  * instead.
296  */
297 static __inline void
298 ie_setup_config(volatile struct ie_config_cmd *cmd,
299 		int promiscuous, int manchester) {
300 	cmd->ie_config_count = 0x0c;
301 	cmd->ie_fifo = 8;
302 	cmd->ie_save_bad = 0x40;
303 	cmd->ie_addr_len = 0x2e;
304 	cmd->ie_priority = 0;
305 	cmd->ie_ifs = 0x60;
306 	cmd->ie_slot_low = 0;
307 	cmd->ie_slot_high = 0xf2;
308 	cmd->ie_promisc = !!promiscuous | manchester << 2;
309 	cmd->ie_crs_cdt = 0;
310 	cmd->ie_min_len = 64;
311 	cmd->ie_junk = 0xff;
312 }
313 
314 static __inline void *
315 Align(void *ptr) {
316 	uintptr_t l = (uintptr_t)ptr;
317 	l = (l + 3) & ~3L;
318 	return (void *)l;
319 }
320 
321 static __inline volatile void *
322 Alignvol(volatile void *ptr) {
323 	uintptr_t l = (uintptr_t)ptr;
324 	l = (l + 3) & ~3L;
325 	return (volatile void *)l;
326 }
327 
328 #if 0
329 static __inline void
330 ie_ack(volatile struct ie_sys_ctl_block *scb,
331 				  u_int mask, int unit,
332 				  void (*ca)(int)) {
333 	scb->ie_command = scb->ie_status & mask;
334 	(*ca)(unit);
335 }
336 #endif
337