i82586.h revision 11961
1198090Srdivacky/*-
2198090Srdivacky * Copyright (c) 1992, University of Vermont and State Agricultural College.
3198090Srdivacky * Copyright (c) 1992, Garrett A. Wollman.
4198090Srdivacky * All rights reserved.
5198090Srdivacky *
6198090Srdivacky * Redistribution and use in source and binary forms, with or without
7198090Srdivacky * modification, are permitted provided that the following conditions
8198090Srdivacky * are met:
9198090Srdivacky * 1. Redistributions of source code must retain the above copyright
10263508Sdim *    notice, this list of conditions and the following disclaimer.
11263508Sdim * 2. Redistributions in binary form must reproduce the above copyright
12263508Sdim *    notice, this list of conditions and the following disclaimer in the
13249423Sdim *    documentation and/or other materials provided with the distribution.
14249423Sdim * 3. All advertising materials mentioning features or use of this software
15226633Sdim *    must display the following acknowledgement:
16226633Sdim *	This product includes software developed by the University of
17249423Sdim *	Vermont and State Agricultural College and Garrett A. Wollman.
18249423Sdim * 4. Neither the name of the University nor the name of the author
19249423Sdim *    may be used to endorse or promote products derived from this software
20249423Sdim *    without specific prior written permission.
21249423Sdim *
22249423Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23223017Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24249423Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25218893Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR AUTHOR BE LIABLE
26249423Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27198090Srdivacky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28198090Srdivacky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29226633Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30263508Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31249423Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32249423Sdim * SUCH DAMAGE.
33249423Sdim *
34226633Sdim *	$Id: i82586.h,v 1.1 1993/10/12 06:53:10 rgrimes Exp $
35249423Sdim */
36224145Sdim
37249423Sdim/*
38226633Sdim * Intel 82586 Ethernet chip
39198090Srdivacky * Register, bit, and structure definitions.
40226633Sdim *
41212904Sdim * Written by GAW with reference to the Clarkson Packet Driver code for this
42224145Sdim * chip written by Russ Nelson and others.
43198090Srdivacky */
44198090Srdivacky
45218893Sdimstruct ie_en_addr {
46218893Sdim	u_char data[6];
47218893Sdim};
48218893Sdim
49234353Sdim/*
50234353Sdim * This is the master configuration block.  It tells the hardware where all
51226633Sdim * the rest of the stuff is.
52224145Sdim */
53198090Srdivackystruct ie_sys_conf_ptr {
54263508Sdim	u_short mbz;			/* must be zero */
55234353Sdim	u_char ie_bus_use;		/* true if 8-bit only */
56198090Srdivacky	u_char mbz2[5];			/* must be zero */
57263508Sdim	caddr_t ie_iscp_ptr;		/* 24-bit physaddr of ISCP */
58263508Sdim};
59263508Sdim
60263508Sdim/*
61263508Sdim * Note that this is wired in hardware; the SCP is always located here, no
62263508Sdim * matter what.
63263508Sdim */
64263508Sdim#define IE_SCP_ADDR 0xfffff4
65263508Sdim
66263508Sdim/*
67263508Sdim * The tells the hardware where all the rest of the stuff is, too.
68263508Sdim * FIXME: some of these should be re-commented after we figure out their
69263508Sdim * REAL function.
70263508Sdim */
71263508Sdimstruct ie_int_sys_conf_ptr {
72263508Sdim	u_char ie_busy;			/* zeroed after init */
73263508Sdim	u_char mbz;
74263508Sdim	u_short ie_scb_offset;		/* 16-bit physaddr of next struct */
75263508Sdim	caddr_t ie_base;		/* 24-bit physaddr for all 16-bit vars */
76234353Sdim};
77234353Sdim
78234353Sdim/*
79263508Sdim * This FINALLY tells the hardware what to do and where to put it.
80263508Sdim */
81226633Sdimstruct ie_sys_ctl_block {
82226633Sdim	u_short ie_status;		/* status word */
83226633Sdim	u_short ie_command;		/* command word */
84226633Sdim	u_short ie_command_list;	/* 16-pointer to command block list */
85226633Sdim	u_short ie_recv_list;		/* 16-pointer to receive frame list */
86226633Sdim	u_short ie_err_crc;		/* CRC errors */
87226633Sdim	u_short ie_err_align;		/* Alignment errors */
88226633Sdim	u_short ie_err_resource;	/* Resource errors */
89226633Sdim	u_short ie_err_overrun;		/* Overrun errors */
90226633Sdim};
91226633Sdim
92226633Sdim/* Command values */
93226633Sdim#define IE_RU_COMMAND	0x0070	/* mask for RU command */
94226633Sdim#define IE_RU_NOP	0	/* for completeness */
95226633Sdim#define IE_RU_START	0x0010	/* start receive unit command */
96226633Sdim#define IE_RU_ENABLE	0x0020	/* enable receiver command */
97226633Sdim#define IE_RU_DISABLE	0x0030	/* disable receiver command */
98226633Sdim#define IE_RU_ABORT	0x0040	/* abort current receive operation */
99226633Sdim
100226633Sdim#define IE_CU_COMMAND	0x0700	/* mask for CU command */
101226633Sdim#define IE_CU_NOP	0	/* included for completeness */
102226633Sdim#define IE_CU_START	0x0100	/* do-command command */
103226633Sdim#define IE_CU_RESUME	0x0200	/* resume a suspended cmd list */
104226633Sdim#define IE_CU_STOP	0x0300	/* SUSPEND was already taken */
105263508Sdim#define IE_CU_ABORT	0x0400	/* abort current command */
106226633Sdim
107226633Sdim#define IE_ACK_COMMAND	0xf000	/* mask for ACK command */
108226633Sdim#define IE_ACK_CX	0x8000	/* ack IE_ST_DONE */
109226633Sdim#define IE_ACK_FR	0x4000	/* ack IE_ST_RECV */
110226633Sdim#define IE_ACK_CNA	0x2000	/* ack IE_ST_ALLDONE */
111198090Srdivacky#define IE_ACK_RNR	0x1000	/* ack IE_ST_RNR */
112198090Srdivacky
113198090Srdivacky#define IE_ACTION_COMMAND(x) (((x) & IE_CU_COMMAND) == IE_CU_START)
114234982Sdim				/* is this command an action command? */
115251662Sdim
116234982Sdim/* Status values */
117234982Sdim#define IE_ST_WHENCE	0xf000	/* mask for cause of interrupt */
118234982Sdim#define IE_ST_DONE	0x8000	/* command with I bit completed */
119251662Sdim#define IE_ST_RECV	0x4000	/* frame received */
120234982Sdim#define IE_ST_ALLDONE	0x2000	/* all commands completed */
121234982Sdim#define IE_ST_RNR	0x1000	/* receive not ready */
122198090Srdivacky
123226633Sdim#define IE_CU_STATUS	0x700	/* mask for command unit status */
124226633Sdim#define IE_CU_ACTIVE	0x200	/* command unit is active */
125226633Sdim#define IE_CU_SUSPEND	0x100	/* command unit is suspended */
126226633Sdim
127226633Sdim#define IE_RU_STATUS	0x70	/* mask for receiver unit status */
128226633Sdim#define IE_RU_SUSPEND	0x10	/* receiver is suspended */
129226633Sdim#define IE_RU_NOSPACE	0x20	/* receiver has no resources */
130226633Sdim#define IE_RU_READY	0x40	/* reveiver is ready */
131226633Sdim
132226633Sdim/*
133226633Sdim * This is filled in partially by the chip, partially by us.
134234353Sdim */
135226633Sdimstruct ie_recv_frame_desc {
136226633Sdim	u_short ie_fd_status;		/* status for this frame */
137226633Sdim	u_short ie_fd_last;		/* end of frame list flag */
138234353Sdim	u_short ie_fd_next;		/* 16-pointer to next RFD */
139234353Sdim	u_short ie_fd_buf_desc;		/* 16-pointer to list of buffer desc's */
140234353Sdim	struct ie_en_addr dest;		/* destination ether */
141234353Sdim	struct ie_en_addr src;		/* source ether */
142263508Sdim	u_short ie_length;		/* 802 length/Ether type */
143263508Sdim	u_short mbz;			/* must be zero */
144263508Sdim};
145263508Sdim
146263508Sdim#define IE_FD_LAST	0x8000	/* last rfd in list */
147263508Sdim#define IE_FD_SUSP	0x4000	/* suspend RU after receipt */
148263508Sdim
149263508Sdim#define IE_FD_COMPLETE	0x8000	/* frame is complete */
150263508Sdim#define IE_FD_BUSY	0x4000	/* frame is busy */
151263508Sdim#define IE_FD_OK	0x2000	/* frame is bad */
152198090Srdivacky#define IE_FD_RNR	0x0200	/* receiver out of resources here */
153226633Sdim
154226633Sdim/*
155226633Sdim * linked list of buffers...
156263508Sdim */
157263508Sdimstruct ie_recv_buf_desc {
158218893Sdim	u_short ie_rbd_actual;		/* status for this buffer */
159198090Srdivacky	u_short ie_rbd_next;		/* 16-pointer to next RBD */
160224145Sdim	caddr_t ie_rbd_buffer;		/* 24-pointer to buffer for this RBD */
161224145Sdim	u_short ie_rbd_length;		/* length of the buffer */
162224145Sdim	u_short mbz;			/* must be zero */
163224145Sdim};
164224145Sdim
165224145Sdim#define IE_RBD_LAST	0x8000	/* last buffer */
166224145Sdim#define IE_RBD_USED	0x4000	/* this buffer has data */
167226633Sdim/*
168226633Sdim * All commands share this in common.
169226633Sdim */
170263508Sdimstruct ie_cmd_common {
171263508Sdim	u_short ie_cmd_status;		/* status of this command */
172263508Sdim	u_short ie_cmd_cmd;		/* command word */
173226633Sdim	u_short ie_cmd_link;		/* link to next command */
174226633Sdim};
175226633Sdim
176263508Sdim#define IE_STAT_COMPL	0x8000	/* command is completed */
177263508Sdim#define IE_STAT_BUSY	0x4000	/* command is running now */
178263508Sdim#define IE_STAT_OK	0x2000	/* command completed successfully */
179226633Sdim
180226633Sdim#define IE_CMD_NOP	0x0000	/* NOP */
181226633Sdim#define IE_CMD_IASETUP	0x0001	/* initial address setup */
182263508Sdim#define IE_CMD_CONFIG	0x0002	/* configure command */
183263508Sdim#define IE_CMD_MCAST	0x0003	/* multicast setup command */
184263508Sdim#define IE_CMD_XMIT	0x0004	/* transmit command */
185263508Sdim#define IE_CMD_TDR	0x0005	/* time-domain reflectometer command */
186263508Sdim#define IE_CMD_DUMP	0x0006	/* dump command */
187263508Sdim#define IE_CMD_DIAGNOSE	0x0007	/* diagnostics command */
188263508Sdim
189224145Sdim#define IE_CMD_LAST	0x8000	/* this is the last command in the list */
190224145Sdim#define IE_CMD_SUSPEND	0x4000	/* suspend CU after this command */
191224145Sdim#define IE_CMD_INTR	0x2000	/* post an interrupt after completion */
192224145Sdim
193226633Sdim/*
194226633Sdim * This is the command to transmit a frame.
195226633Sdim */
196224145Sdimstruct ie_xmit_cmd {
197198090Srdivacky	struct ie_cmd_common com;	/* common part */
198198090Srdivacky#define ie_xmit_status com.ie_cmd_status
199198090Srdivacky
200218893Sdim	u_short ie_xmit_desc;		/* 16-pointer to buffer descriptor */
201218893Sdim	struct ie_en_addr ie_xmit_addr; /* destination address */
202198090Srdivacky
203198090Srdivacky	u_short ie_xmit_length;		/* 802.3 length/Ether type field */
204198090Srdivacky};
205226633Sdim
206226633Sdim#define IE_XS_MAXCOLL  	0x000f	/* number of collisions during transmit */
207218893Sdim#define IE_XS_EXCMAX	0x0020	/* exceeded maximum number of collisions */
208226633Sdim#define IE_XS_SQE	0x0040	/* SQE positive */
209218893Sdim#define IE_XS_DEFERRED	0x0080	/* transmission deferred */
210226633Sdim#define IE_XS_UNDERRUN	0x0100	/* DMA underrun */
211218893Sdim#define IE_XS_LOSTCTS	0x0200	/* Lost CTS */
212226633Sdim#define IE_XS_NOCARRIER	0x0400	/* No Carrier */
213218893Sdim#define IE_XS_LATECOLL	0x0800	/* Late collision */
214263508Sdim
215263508Sdim/*
216226633Sdim * This is a buffer descriptor for a frame to be transmitted.
217218893Sdim */
218226633Sdim
219221345Sdimstruct ie_xmit_buf {
220226633Sdim	u_short ie_xmit_flags;		/* see below */
221226633Sdim	u_short ie_xmit_next;		/* 16-pointer to next desc. */
222226633Sdim	caddr_t ie_xmit_buf;		/* 24-pointer to the actual buffer */
223226633Sdim};
224226633Sdim
225226633Sdim#define IE_XMIT_LAST 0x8000	/* this TBD is the last one */
226226633Sdim/* The rest of the `flags' word is actually the length. */
227226633Sdim
228226633Sdim/*
229226633Sdim * Multicast setup command.
230226633Sdim */
231226633Sdim
232226633Sdim#define MAXMCAST 50		/* must fit in transmit buffer */
233226633Sdim
234226633Sdimstruct ie_mcast_cmd {
235234353Sdim	struct ie_cmd_common com;	/* common part */
236249423Sdim#define ie_mcast_status com.ie_cmd_status
237249423Sdim
238198090Srdivacky	u_short ie_mcast_bytes;	/* size (in bytes) of multicast addresses */
239221345Sdim	struct ie_en_addr ie_mcast_addrs[MAXMCAST + 1];	/* space for them */
240243830Sdim};
241226633Sdim
242263508Sdim/*
243234353Sdim * Time Domain Reflectometer command.
244263508Sdim */
245226633Sdim
246226633Sdimstruct ie_tdr_cmd {
247234353Sdim	struct ie_cmd_common com;	/* common part */
248226633Sdim#define ie_tdr_status com.ie_cmd_status
249226633Sdim
250226633Sdim	u_short ie_tdr_time;		/* error bits and time */
251263508Sdim};
252263508Sdim
253198090Srdivacky#define IE_TDR_SUCCESS	0x8000	/* TDR succeeded without error */
254226633Sdim#define IE_TDR_XCVR	0x4000	/* detected a transceiver problem */
255226633Sdim#define IE_TDR_OPEN	0x2000	/* detected an open */
256226633Sdim#define IE_TDR_SHORT	0x1000	/* TDR detected a short */
257226633Sdim#define IE_TDR_TIME	0x07ff	/* mask for reflection time */
258239462Sdim
259239462Sdim/*
260239462Sdim * Initial Address Setup command
261239462Sdim */
262226633Sdimstruct ie_iasetup_cmd {
263226633Sdim	struct ie_cmd_common com;
264263508Sdim#define ie_iasetup_status com.ie_cmd_status
265263508Sdim
266263508Sdim	struct ie_en_addr ie_address;
267224145Sdim};
268198090Srdivacky
269234353Sdim/*
270263508Sdim * Configuration command
271234353Sdim */
272224145Sdimstruct ie_config_cmd {
273224145Sdim	struct ie_cmd_common com;	/* common part */
274226633Sdim#define ie_config_status com.ie_cmd_status
275226633Sdim
276226633Sdim	u_char ie_config_count;		/* byte count (0x0c) */
277249423Sdim	u_char ie_fifo;			/* fifo (8) */
278263508Sdim	u_char ie_save_bad;		/* save bad frames (0x40) */
279224145Sdim	u_char ie_addr_len;		/* address length (0x2e) (AL-LOC == 1) */
280224145Sdim	u_char ie_priority;		/* priority and backoff (0x0) */
281226633Sdim	u_char ie_ifs;			/* inter-frame spacing (0x60) */
282226633Sdim	u_char ie_slot_low;		/* slot time, LSB (0x0) */
283243830Sdim	u_char ie_slot_high;		/* slot time, MSN, and retries (0xf2) */
284243830Sdim	u_char ie_promisc;		/* 1 if promiscuous, else 0 */
285226633Sdim	u_char ie_crs_cdt;		/* CSMA/CD parameters (0x0) */
286226633Sdim	u_char ie_min_len;		/* min frame length (0x40) */
287226633Sdim	u_char ie_junk;			/* stuff for 82596 (0xff) */
288249423Sdim};
289226633Sdim
290226633Sdim/*
291243830Sdim * Here are a few useful functions.  We could have done these as macros,
292226633Sdim * but since we have the inline facility, it makes sense to use that
293243830Sdim * instead.
294243830Sdim */
295263508Sdiminline void
296263508Sdimie_setup_config(volatile struct ie_config_cmd *cmd,
297198090Srdivacky		int promiscuous, int manchester) {
298218893Sdim	cmd->ie_config_count = 0x0c;
299218893Sdim	cmd->ie_fifo = 8;
300218893Sdim	cmd->ie_save_bad = 0x40;
301218893Sdim	cmd->ie_addr_len = 0x2e;
302198090Srdivacky	cmd->ie_priority = 0;
303249423Sdim	cmd->ie_ifs = 0x60;
304218893Sdim	cmd->ie_slot_low = 0;
305206124Srdivacky	cmd->ie_slot_high = 0xf2;
306226633Sdim	cmd->ie_promisc = !!promiscuous | manchester << 2;
307226633Sdim	cmd->ie_crs_cdt = 0;
308226633Sdim	cmd->ie_min_len = 64;
309226633Sdim	cmd->ie_junk = 0xff;
310226633Sdim}
311226633Sdim
312226633Sdimstatic inline caddr_t
313226633SdimAlign(caddr_t ptr) {
314263508Sdim	unsigned long l = (unsigned long)ptr;
315226633Sdim	l = (l + 3) & ~3L;
316226633Sdim	return (caddr_t)l;
317226633Sdim}
318226633Sdim
319226633Sdimstatic inline void
320226633Sdimie_ack(volatile struct ie_sys_ctl_block *scb,
321226633Sdim				  u_int mask, int unit,
322226633Sdim				  void (*ca)(int)) {
323226633Sdim	scb->ie_command = scb->ie_status & mask;
324234353Sdim	(*ca)(unit);
325234353Sdim}
326234353Sdim