1582Srgrimes/*-
2582Srgrimes * Copyright (c) 1992, University of Vermont and State Agricultural College.
3582Srgrimes * Copyright (c) 1992, Garrett A. Wollman.
4582Srgrimes * All rights reserved.
5582Srgrimes *
6582Srgrimes * Redistribution and use in source and binary forms, with or without
7582Srgrimes * modification, are permitted provided that the following conditions
8582Srgrimes * are met:
9582Srgrimes * 1. Redistributions of source code must retain the above copyright
10582Srgrimes *    notice, this list of conditions and the following disclaimer.
11582Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
12582Srgrimes *    notice, this list of conditions and the following disclaimer in the
13582Srgrimes *    documentation and/or other materials provided with the distribution.
14582Srgrimes * 3. All advertising materials mentioning features or use of this software
15582Srgrimes *    must display the following acknowledgement:
16582Srgrimes *	This product includes software developed by the University of
17582Srgrimes *	Vermont and State Agricultural College and Garrett A. Wollman.
18582Srgrimes * 4. Neither the name of the University nor the name of the author
19582Srgrimes *    may be used to endorse or promote products derived from this software
20582Srgrimes *    without specific prior written permission.
21582Srgrimes *
22582Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23582Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24582Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25582Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR AUTHOR BE LIABLE
26582Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27582Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28582Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29582Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30582Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31582Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32582Srgrimes * SUCH DAMAGE.
33582Srgrimes *
3450477Speter * $FreeBSD$
35582Srgrimes */
36582Srgrimes
37582Srgrimes/*
38582Srgrimes * Intel 82586 Ethernet chip
39582Srgrimes * Register, bit, and structure definitions.
40582Srgrimes *
41582Srgrimes * Written by GAW with reference to the Clarkson Packet Driver code for this
42582Srgrimes * chip written by Russ Nelson and others.
43582Srgrimes */
44582Srgrimes
45582Srgrimesstruct ie_en_addr {
46582Srgrimes	u_char data[6];
47582Srgrimes};
48582Srgrimes
49582Srgrimes/*
50582Srgrimes * This is the master configuration block.  It tells the hardware where all
51582Srgrimes * the rest of the stuff is.
52582Srgrimes */
53582Srgrimesstruct ie_sys_conf_ptr {
54582Srgrimes	u_short mbz;			/* must be zero */
55582Srgrimes	u_char ie_bus_use;		/* true if 8-bit only */
56582Srgrimes	u_char mbz2[5];			/* must be zero */
57582Srgrimes	caddr_t ie_iscp_ptr;		/* 24-bit physaddr of ISCP */
58582Srgrimes};
59582Srgrimes
60582Srgrimes/*
61582Srgrimes * Note that this is wired in hardware; the SCP is always located here, no
62582Srgrimes * matter what.
63582Srgrimes */
64582Srgrimes#define IE_SCP_ADDR 0xfffff4
65582Srgrimes
66582Srgrimes/*
67582Srgrimes * The tells the hardware where all the rest of the stuff is, too.
68582Srgrimes * FIXME: some of these should be re-commented after we figure out their
69582Srgrimes * REAL function.
70582Srgrimes */
71582Srgrimesstruct ie_int_sys_conf_ptr {
72582Srgrimes	u_char ie_busy;			/* zeroed after init */
73582Srgrimes	u_char mbz;
74582Srgrimes	u_short ie_scb_offset;		/* 16-bit physaddr of next struct */
75582Srgrimes	caddr_t ie_base;		/* 24-bit physaddr for all 16-bit vars */
76582Srgrimes};
77582Srgrimes
78582Srgrimes/*
79582Srgrimes * This FINALLY tells the hardware what to do and where to put it.
80582Srgrimes */
81582Srgrimesstruct ie_sys_ctl_block {
82582Srgrimes	u_short ie_status;		/* status word */
83582Srgrimes	u_short ie_command;		/* command word */
84582Srgrimes	u_short ie_command_list;	/* 16-pointer to command block list */
85582Srgrimes	u_short ie_recv_list;		/* 16-pointer to receive frame list */
86582Srgrimes	u_short ie_err_crc;		/* CRC errors */
87582Srgrimes	u_short ie_err_align;		/* Alignment errors */
88582Srgrimes	u_short ie_err_resource;	/* Resource errors */
89582Srgrimes	u_short ie_err_overrun;		/* Overrun errors */
90582Srgrimes};
91582Srgrimes
92582Srgrimes/* Command values */
93582Srgrimes#define IE_RU_COMMAND	0x0070	/* mask for RU command */
94582Srgrimes#define IE_RU_NOP	0	/* for completeness */
95582Srgrimes#define IE_RU_START	0x0010	/* start receive unit command */
96582Srgrimes#define IE_RU_ENABLE	0x0020	/* enable receiver command */
97582Srgrimes#define IE_RU_DISABLE	0x0030	/* disable receiver command */
98582Srgrimes#define IE_RU_ABORT	0x0040	/* abort current receive operation */
99582Srgrimes
100582Srgrimes#define IE_CU_COMMAND	0x0700	/* mask for CU command */
101582Srgrimes#define IE_CU_NOP	0	/* included for completeness */
102582Srgrimes#define IE_CU_START	0x0100	/* do-command command */
103582Srgrimes#define IE_CU_RESUME	0x0200	/* resume a suspended cmd list */
104582Srgrimes#define IE_CU_STOP	0x0300	/* SUSPEND was already taken */
105582Srgrimes#define IE_CU_ABORT	0x0400	/* abort current command */
106582Srgrimes
107582Srgrimes#define IE_ACK_COMMAND	0xf000	/* mask for ACK command */
108582Srgrimes#define IE_ACK_CX	0x8000	/* ack IE_ST_DONE */
109582Srgrimes#define IE_ACK_FR	0x4000	/* ack IE_ST_RECV */
110582Srgrimes#define IE_ACK_CNA	0x2000	/* ack IE_ST_ALLDONE */
111582Srgrimes#define IE_ACK_RNR	0x1000	/* ack IE_ST_RNR */
112582Srgrimes
113582Srgrimes#define IE_ACTION_COMMAND(x) (((x) & IE_CU_COMMAND) == IE_CU_START)
114582Srgrimes				/* is this command an action command? */
115582Srgrimes
116582Srgrimes/* Status values */
117582Srgrimes#define IE_ST_WHENCE	0xf000	/* mask for cause of interrupt */
118582Srgrimes#define IE_ST_DONE	0x8000	/* command with I bit completed */
119582Srgrimes#define IE_ST_RECV	0x4000	/* frame received */
120582Srgrimes#define IE_ST_ALLDONE	0x2000	/* all commands completed */
121582Srgrimes#define IE_ST_RNR	0x1000	/* receive not ready */
122582Srgrimes
123582Srgrimes#define IE_CU_STATUS	0x700	/* mask for command unit status */
124582Srgrimes#define IE_CU_ACTIVE	0x200	/* command unit is active */
125582Srgrimes#define IE_CU_SUSPEND	0x100	/* command unit is suspended */
126582Srgrimes
127582Srgrimes#define IE_RU_STATUS	0x70	/* mask for receiver unit status */
128582Srgrimes#define IE_RU_SUSPEND	0x10	/* receiver is suspended */
129582Srgrimes#define IE_RU_NOSPACE	0x20	/* receiver has no resources */
130582Srgrimes#define IE_RU_READY	0x40	/* reveiver is ready */
131582Srgrimes
132582Srgrimes/*
133582Srgrimes * This is filled in partially by the chip, partially by us.
134582Srgrimes */
135582Srgrimesstruct ie_recv_frame_desc {
136582Srgrimes	u_short ie_fd_status;		/* status for this frame */
137582Srgrimes	u_short ie_fd_last;		/* end of frame list flag */
138582Srgrimes	u_short ie_fd_next;		/* 16-pointer to next RFD */
139582Srgrimes	u_short ie_fd_buf_desc;		/* 16-pointer to list of buffer desc's */
140582Srgrimes	struct ie_en_addr dest;		/* destination ether */
141582Srgrimes	struct ie_en_addr src;		/* source ether */
142582Srgrimes	u_short ie_length;		/* 802 length/Ether type */
143582Srgrimes	u_short mbz;			/* must be zero */
144582Srgrimes};
145582Srgrimes
146582Srgrimes#define IE_FD_LAST	0x8000	/* last rfd in list */
147582Srgrimes#define IE_FD_SUSP	0x4000	/* suspend RU after receipt */
148582Srgrimes
149582Srgrimes#define IE_FD_COMPLETE	0x8000	/* frame is complete */
150582Srgrimes#define IE_FD_BUSY	0x4000	/* frame is busy */
151582Srgrimes#define IE_FD_OK	0x2000	/* frame is bad */
152582Srgrimes#define IE_FD_RNR	0x0200	/* receiver out of resources here */
153582Srgrimes
154582Srgrimes/*
155582Srgrimes * linked list of buffers...
156582Srgrimes */
157582Srgrimesstruct ie_recv_buf_desc {
158582Srgrimes	u_short ie_rbd_actual;		/* status for this buffer */
159582Srgrimes	u_short ie_rbd_next;		/* 16-pointer to next RBD */
160582Srgrimes	caddr_t ie_rbd_buffer;		/* 24-pointer to buffer for this RBD */
161582Srgrimes	u_short ie_rbd_length;		/* length of the buffer */
162582Srgrimes	u_short mbz;			/* must be zero */
163582Srgrimes};
164582Srgrimes
165582Srgrimes#define IE_RBD_LAST	0x8000	/* last buffer */
166582Srgrimes#define IE_RBD_USED	0x4000	/* this buffer has data */
167582Srgrimes/*
168582Srgrimes * All commands share this in common.
169582Srgrimes */
170582Srgrimesstruct ie_cmd_common {
171582Srgrimes	u_short ie_cmd_status;		/* status of this command */
172582Srgrimes	u_short ie_cmd_cmd;		/* command word */
173582Srgrimes	u_short ie_cmd_link;		/* link to next command */
174582Srgrimes};
175582Srgrimes
176582Srgrimes#define IE_STAT_COMPL	0x8000	/* command is completed */
177582Srgrimes#define IE_STAT_BUSY	0x4000	/* command is running now */
178582Srgrimes#define IE_STAT_OK	0x2000	/* command completed successfully */
179582Srgrimes
180582Srgrimes#define IE_CMD_NOP	0x0000	/* NOP */
181582Srgrimes#define IE_CMD_IASETUP	0x0001	/* initial address setup */
182582Srgrimes#define IE_CMD_CONFIG	0x0002	/* configure command */
183582Srgrimes#define IE_CMD_MCAST	0x0003	/* multicast setup command */
184582Srgrimes#define IE_CMD_XMIT	0x0004	/* transmit command */
185582Srgrimes#define IE_CMD_TDR	0x0005	/* time-domain reflectometer command */
186582Srgrimes#define IE_CMD_DUMP	0x0006	/* dump command */
187582Srgrimes#define IE_CMD_DIAGNOSE	0x0007	/* diagnostics command */
188582Srgrimes
189582Srgrimes#define IE_CMD_LAST	0x8000	/* this is the last command in the list */
190582Srgrimes#define IE_CMD_SUSPEND	0x4000	/* suspend CU after this command */
191582Srgrimes#define IE_CMD_INTR	0x2000	/* post an interrupt after completion */
192582Srgrimes
193582Srgrimes/*
194582Srgrimes * This is the command to transmit a frame.
195582Srgrimes */
196582Srgrimesstruct ie_xmit_cmd {
197582Srgrimes	struct ie_cmd_common com;	/* common part */
198582Srgrimes#define ie_xmit_status com.ie_cmd_status
199582Srgrimes
200582Srgrimes	u_short ie_xmit_desc;		/* 16-pointer to buffer descriptor */
201582Srgrimes	struct ie_en_addr ie_xmit_addr; /* destination address */
202582Srgrimes
203582Srgrimes	u_short ie_xmit_length;		/* 802.3 length/Ether type field */
204582Srgrimes};
205582Srgrimes
206582Srgrimes#define IE_XS_MAXCOLL  	0x000f	/* number of collisions during transmit */
207582Srgrimes#define IE_XS_EXCMAX	0x0020	/* exceeded maximum number of collisions */
208582Srgrimes#define IE_XS_SQE	0x0040	/* SQE positive */
209582Srgrimes#define IE_XS_DEFERRED	0x0080	/* transmission deferred */
210582Srgrimes#define IE_XS_UNDERRUN	0x0100	/* DMA underrun */
211582Srgrimes#define IE_XS_LOSTCTS	0x0200	/* Lost CTS */
212582Srgrimes#define IE_XS_NOCARRIER	0x0400	/* No Carrier */
213582Srgrimes#define IE_XS_LATECOLL	0x0800	/* Late collision */
214582Srgrimes
215582Srgrimes/*
216582Srgrimes * This is a buffer descriptor for a frame to be transmitted.
217582Srgrimes */
218582Srgrimes
219582Srgrimesstruct ie_xmit_buf {
220582Srgrimes	u_short ie_xmit_flags;		/* see below */
221582Srgrimes	u_short ie_xmit_next;		/* 16-pointer to next desc. */
222582Srgrimes	caddr_t ie_xmit_buf;		/* 24-pointer to the actual buffer */
223582Srgrimes};
224582Srgrimes
225582Srgrimes#define IE_XMIT_LAST 0x8000	/* this TBD is the last one */
226582Srgrimes/* The rest of the `flags' word is actually the length. */
227582Srgrimes
228582Srgrimes/*
229582Srgrimes * Multicast setup command.
230582Srgrimes */
231582Srgrimes
232582Srgrimes#define MAXMCAST 50		/* must fit in transmit buffer */
233582Srgrimes
234582Srgrimesstruct ie_mcast_cmd {
235582Srgrimes	struct ie_cmd_common com;	/* common part */
236582Srgrimes#define ie_mcast_status com.ie_cmd_status
237582Srgrimes
238582Srgrimes	u_short ie_mcast_bytes;	/* size (in bytes) of multicast addresses */
239582Srgrimes	struct ie_en_addr ie_mcast_addrs[MAXMCAST + 1];	/* space for them */
240582Srgrimes};
241582Srgrimes
242582Srgrimes/*
243582Srgrimes * Time Domain Reflectometer command.
244582Srgrimes */
245582Srgrimes
246582Srgrimesstruct ie_tdr_cmd {
247582Srgrimes	struct ie_cmd_common com;	/* common part */
248582Srgrimes#define ie_tdr_status com.ie_cmd_status
249582Srgrimes
250582Srgrimes	u_short ie_tdr_time;		/* error bits and time */
251582Srgrimes};
252582Srgrimes
253582Srgrimes#define IE_TDR_SUCCESS	0x8000	/* TDR succeeded without error */
254582Srgrimes#define IE_TDR_XCVR	0x4000	/* detected a transceiver problem */
255582Srgrimes#define IE_TDR_OPEN	0x2000	/* detected an open */
256582Srgrimes#define IE_TDR_SHORT	0x1000	/* TDR detected a short */
257582Srgrimes#define IE_TDR_TIME	0x07ff	/* mask for reflection time */
258582Srgrimes
259582Srgrimes/*
260582Srgrimes * Initial Address Setup command
261582Srgrimes */
262582Srgrimesstruct ie_iasetup_cmd {
263582Srgrimes	struct ie_cmd_common com;
264582Srgrimes#define ie_iasetup_status com.ie_cmd_status
265582Srgrimes
266582Srgrimes	struct ie_en_addr ie_address;
267582Srgrimes};
268582Srgrimes
269582Srgrimes/*
270582Srgrimes * Configuration command
271582Srgrimes */
272582Srgrimesstruct ie_config_cmd {
273582Srgrimes	struct ie_cmd_common com;	/* common part */
274582Srgrimes#define ie_config_status com.ie_cmd_status
275582Srgrimes
276582Srgrimes	u_char ie_config_count;		/* byte count (0x0c) */
277582Srgrimes	u_char ie_fifo;			/* fifo (8) */
278582Srgrimes	u_char ie_save_bad;		/* save bad frames (0x40) */
279582Srgrimes	u_char ie_addr_len;		/* address length (0x2e) (AL-LOC == 1) */
280582Srgrimes	u_char ie_priority;		/* priority and backoff (0x0) */
281582Srgrimes	u_char ie_ifs;			/* inter-frame spacing (0x60) */
282582Srgrimes	u_char ie_slot_low;		/* slot time, LSB (0x0) */
283582Srgrimes	u_char ie_slot_high;		/* slot time, MSN, and retries (0xf2) */
284582Srgrimes	u_char ie_promisc;		/* 1 if promiscuous, else 0 */
285582Srgrimes	u_char ie_crs_cdt;		/* CSMA/CD parameters (0x0) */
286582Srgrimes	u_char ie_min_len;		/* min frame length (0x40) */
287582Srgrimes	u_char ie_junk;			/* stuff for 82596 (0xff) */
288582Srgrimes};
289582Srgrimes
290582Srgrimes/*
291582Srgrimes * Here are a few useful functions.  We could have done these as macros,
292582Srgrimes * but since we have the inline facility, it makes sense to use that
293582Srgrimes * instead.
294582Srgrimes */
29535210Sbdestatic __inline void
296582Srgrimesie_setup_config(volatile struct ie_config_cmd *cmd,
297582Srgrimes		int promiscuous, int manchester) {
298582Srgrimes	cmd->ie_config_count = 0x0c;
299582Srgrimes	cmd->ie_fifo = 8;
300582Srgrimes	cmd->ie_save_bad = 0x40;
301582Srgrimes	cmd->ie_addr_len = 0x2e;
302582Srgrimes	cmd->ie_priority = 0;
303582Srgrimes	cmd->ie_ifs = 0x60;
304582Srgrimes	cmd->ie_slot_low = 0;
305582Srgrimes	cmd->ie_slot_high = 0xf2;
306582Srgrimes	cmd->ie_promisc = !!promiscuous | manchester << 2;
307582Srgrimes	cmd->ie_crs_cdt = 0;
308582Srgrimes	cmd->ie_min_len = 64;
309582Srgrimes	cmd->ie_junk = 0xff;
310582Srgrimes}
311582Srgrimes
31247108Sbdestatic __inline void *
31347108SbdeAlign(void *ptr) {
31438232Sbde	uintptr_t l = (uintptr_t)ptr;
315582Srgrimes	l = (l + 3) & ~3L;
31647108Sbde	return (void *)l;
317582Srgrimes}
318582Srgrimes
31947108Sbdestatic __inline volatile void *
32047108SbdeAlignvol(volatile void *ptr) {
32147108Sbde	uintptr_t l = (uintptr_t)ptr;
32247108Sbde	l = (l + 3) & ~3L;
32347108Sbde	return (volatile void *)l;
32447108Sbde}
32547108Sbde
326112734Smdodd#if 0
32735210Sbdestatic __inline void
328582Srgrimesie_ack(volatile struct ie_sys_ctl_block *scb,
329582Srgrimes				  u_int mask, int unit,
330582Srgrimes				  void (*ca)(int)) {
331582Srgrimes	scb->ie_command = scb->ie_status & mask;
332582Srgrimes	(*ca)(unit);
333582Srgrimes}
334112734Smdodd#endif
335