2 * Copyright (c) 1993 Herb Peyerl (hpeyerl@novatel.ca) All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: 1. Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer. 2. The name
8 * of the author may not be used to endorse or promote products derived from
9 * this software without specific prior written permission
11 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
12 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
14 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
15 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
16 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
17 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
18 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
20 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 * $FreeBSD: src/sys/dev/vx/if_vxreg.h,v 1.5.6.1 2000/08/02 22:42:34 peter Exp $
23 * $DragonFly: src/sys/dev/netif/vx/if_vxreg.h,v 1.2 2003/06/17 04:28:33 dillon Exp $
27 Modified by: Andres Vega Garcia
29 INRIA - Sophia Antipolis, France
30 e-mail: avega@sophia.inria.fr
31 finger: avega@pax.inria.fr
36 * Created from if_epreg.h by Fred Gray (fgray@rice.edu) to support the
41 * Promiscuous mode added and interrupt logic slightly changed
42 * to reduce the number of adapter failures. Transceiver select
43 * logic changed to use value from EEPROM. Autoconfiguration
47 * Chelindbank (Chelyabinsk, Russia)
48 * babkin@hq.icb.chel.su
52 * Ethernet software status per interface.
55 struct arpcom arpcom; /* Ethernet common part */
56 int unit; /* unit number */
57 u_int vx_io_addr; /* i/o bus address */
58 #define MAX_MBS 8 /* # of mbufs we keep around */
59 struct mbuf *mb[MAX_MBS]; /* spare mbuf storage. */
60 int next_mb; /* Which mbuf to use next. */
61 int last_mb; /* Last mbuf. */
62 char vx_connectors; /* Connectors on this card. */
63 char vx_connector; /* Connector to use. */
64 short tx_start_thresh; /* Current TX_start_thresh. */
65 int tx_succ_ok; /* # packets sent in sequence */
67 struct callout_handle ch; /* Callout handle for timeouts */
72 * Some global constants
75 #define TX_INIT_RATE 16
76 #define TX_INIT_MAX_RATE 64
77 #define RX_INIT_LATENCY 64
78 #define RX_INIT_EARLY_THRESH 64
79 #define MIN_RX_EARLY_THRESHF 16 /* not less than ether_header */
80 #define MIN_RX_EARLY_THRESHL 4
82 #define EEPROMSIZE 0x40
83 #define MAX_EEPROMBUSY 1000
84 #define VX_LAST_TAG 0xd7
85 #define VX_MAX_BOARDS 16
86 #define VX_ID_PORT 0x100
89 * some macros to acces long named fields
91 #define BASE (sc->vx_io_addr)
94 * Commands to read/write EEPROM trough EEPROM command register (Window 0,
97 #define EEPROM_CMD_RD 0x0080 /* Read: Address required (5 bits) */
98 #define EEPROM_CMD_WR 0x0040 /* Write: Address required (5 bits) */
99 #define EEPROM_CMD_ERASE 0x00c0 /* Erase: Address required (5 bits) */
100 #define EEPROM_CMD_EWEN 0x0030 /* Erase/Write Enable: No data required */
102 #define EEPROM_BUSY (1<<15)
105 * Some short functions, worth to let them be a macro
108 /**************************************************************************
110 * These define the EEPROM data structure. They are used in the probe
111 * function to verify the existence of the adapter after having sent
114 * There are others but only the ones we use are defined here.
116 **************************************************************************/
118 #define EEPROM_NODE_ADDR_0 0x0 /* Word */
119 #define EEPROM_NODE_ADDR_1 0x1 /* Word */
120 #define EEPROM_NODE_ADDR_2 0x2 /* Word */
121 #define EEPROM_PROD_ID 0x3 /* 0x9[0-f]50 */
122 #define EEPROM_MFG_ID 0x7 /* 0x6d50 */
123 #define EEPROM_ADDR_CFG 0x8 /* Base addr */
124 #define EEPROM_RESOURCE_CFG 0x9 /* IRQ. Bits 12-15 */
125 #define EEPROM_OEM_ADDR_0 0xa /* Word */
126 #define EEPROM_OEM_ADDR_1 0xb /* Word */
127 #define EEPROM_OEM_ADDR_2 0xc /* Word */
128 #define EEPROM_SOFT_INFO_2 0xf /* Software information 2 */
130 #define NO_RX_OVN_ANOMALY (1<<5)
132 /**************************************************************************
134 * These are the registers for the 3Com 3c509 and their bit patterns when *
135 * applicable. They have been taken out the the "EtherLink III Parallel *
136 * Tasking EISA and ISA Technical Reference" "Beta Draft 10/30/92" manual *
139 **************************************************************************/
141 #define VX_COMMAND 0x0e /* Write. BASE+0x0e is always a
143 #define VX_STATUS 0x0e /* Read. BASE+0x0e is always status
145 #define VX_WINDOW 0x0f /* Read. BASE+0x0f is always window
148 * Window 0 registers. Setup.
151 #define VX_W0_EEPROM_DATA 0x0c
152 #define VX_W0_EEPROM_COMMAND 0x0a
153 #define VX_W0_RESOURCE_CFG 0x08
154 #define VX_W0_ADDRESS_CFG 0x06
155 #define VX_W0_CONFIG_CTRL 0x04
157 #define VX_W0_PRODUCT_ID 0x02
158 #define VX_W0_MFG_ID 0x00
162 * Window 1 registers. Operating Set.
165 #define VX_W1_TX_PIO_WR_2 0x02
166 #define VX_W1_TX_PIO_WR_1 0x00
168 #define VX_W1_FREE_TX 0x0c
169 #define VX_W1_TX_STATUS 0x0b /* byte */
170 #define VX_W1_TIMER 0x0a /* byte */
171 #define VX_W1_RX_STATUS 0x08
172 #define VX_W1_RX_PIO_RD_2 0x02
173 #define VX_W1_RX_PIO_RD_1 0x00
176 * Window 2 registers. Station Address Setup/Read
179 #define VX_W2_ADDR_5 0x05
180 #define VX_W2_ADDR_4 0x04
181 #define VX_W2_ADDR_3 0x03
182 #define VX_W2_ADDR_2 0x02
183 #define VX_W2_ADDR_1 0x01
184 #define VX_W2_ADDR_0 0x00
187 * Window 3 registers. FIFO Management.
190 #define VX_W3_INTERNAL_CFG 0x00
191 #define VX_W3_RESET_OPT 0x08
192 #define VX_W3_FREE_TX 0x0c
193 #define VX_W3_FREE_RX 0x0a
196 * Window 4 registers. Diagnostics.
199 #define VX_W4_MEDIA_TYPE 0x0a
200 #define VX_W4_CTRLR_STATUS 0x08
201 #define VX_W4_NET_DIAG 0x06
202 #define VX_W4_FIFO_DIAG 0x04
203 #define VX_W4_HOST_DIAG 0x02
204 #define VX_W4_TX_DIAG 0x00
207 * Window 5 Registers. Results and Internal status.
210 #define VX_W5_READ_0_MASK 0x0c
211 #define VX_W5_INTR_MASK 0x0a
212 #define VX_W5_RX_FILTER 0x08
213 #define VX_W5_RX_EARLY_THRESH 0x06
214 #define VX_W5_TX_AVAIL_THRESH 0x02
215 #define VX_W5_TX_START_THRESH 0x00
218 * Window 6 registers. Statistics.
221 #define TX_TOTAL_OK 0x0c
222 #define RX_TOTAL_OK 0x0a
223 #define TX_DEFERRALS 0x08
224 #define RX_FRAMES_OK 0x07
225 #define TX_FRAMES_OK 0x06
226 #define RX_OVERRUNS 0x05
227 #define TX_COLLISIONS 0x04
228 #define TX_AFTER_1_COLLISION 0x03
229 #define TX_AFTER_X_COLLISIONS 0x02
230 #define TX_NO_SQE 0x01
231 #define TX_CD_LOST 0x00
233 /****************************************
235 * Register definitions.
237 ****************************************/
240 * Command register. All windows.
243 * 15-11: 5-bit code for command to be executed.
244 * 10-0: 11-bit arg if any. For commands with no args;
245 * this can be set to anything.
247 #define GLOBAL_RESET (u_short) 0x0000 /* Wait at least 1ms
249 #define WINDOW_SELECT (u_short) (0x1<<11)
250 #define START_TRANSCEIVER (u_short) (0x2<<11) /* Read ADDR_CFG reg to
254 * before using trans-
256 #define RX_DISABLE (u_short) (0x3<<11) /* state disabled on
258 #define RX_ENABLE (u_short) (0x4<<11)
259 #define RX_RESET (u_short) (0x5<<11)
260 #define RX_DISCARD_TOP_PACK (u_short) (0x8<<11)
261 #define TX_ENABLE (u_short) (0x9<<11)
262 #define TX_DISABLE (u_short) (0xa<<11)
263 #define TX_RESET (u_short) (0xb<<11)
264 #define REQ_INTR (u_short) (0xc<<11)
266 * The following C_* acknowledge the various interrupts. Some of them don't
267 * do anything. See the manual.
269 #define ACK_INTR (u_short) (0x6800)
270 # define C_INTR_LATCH (u_short) (ACK_INTR|0x1)
271 # define C_CARD_FAILURE (u_short) (ACK_INTR|0x2)
272 # define C_TX_COMPLETE (u_short) (ACK_INTR|0x4)
273 # define C_TX_AVAIL (u_short) (ACK_INTR|0x8)
274 # define C_RX_COMPLETE (u_short) (ACK_INTR|0x10)
275 # define C_RX_EARLY (u_short) (ACK_INTR|0x20)
276 # define C_INT_RQD (u_short) (ACK_INTR|0x40)
277 # define C_UPD_STATS (u_short) (ACK_INTR|0x80)
278 #define SET_INTR_MASK (u_short) (0xe<<11)
279 #define SET_RD_0_MASK (u_short) (0xf<<11)
280 #define SET_RX_FILTER (u_short) (0x10<<11)
281 # define FIL_INDIVIDUAL (u_short) (0x1)
282 # define FIL_MULTICAST (u_short) (0x02)
283 # define FIL_BRDCST (u_short) (0x04)
284 # define FIL_PROMISC (u_short) (0x08)
285 #define SET_RX_EARLY_THRESH (u_short) (0x11<<11)
286 #define SET_TX_AVAIL_THRESH (u_short) (0x12<<11)
287 #define SET_TX_START_THRESH (u_short) (0x13<<11)
288 #define STATS_ENABLE (u_short) (0x15<<11)
289 #define STATS_DISABLE (u_short) (0x16<<11)
290 #define STOP_TRANSCEIVER (u_short) (0x17<<11)
293 * Status register. All windows.
295 * 15-13: Window number(0-7).
296 * 12: Command_in_progress.
301 * 7: Update Statistics.
302 * 6: Interrupt Requested.
307 * 1: Adapter Failure.
308 * 0: Interrupt Latch.
310 #define S_INTR_LATCH (u_short) (0x1)
311 #define S_CARD_FAILURE (u_short) (0x2)
312 #define S_TX_COMPLETE (u_short) (0x4)
313 #define S_TX_AVAIL (u_short) (0x8)
314 #define S_RX_COMPLETE (u_short) (0x10)
315 #define S_RX_EARLY (u_short) (0x20)
316 #define S_INT_RQD (u_short) (0x40)
317 #define S_UPD_STATS (u_short) (0x80)
318 #define S_COMMAND_IN_PROGRESS (u_short) (0x1000)
320 #define VX_BUSY_WAIT while (inw(BASE + VX_STATUS) & S_COMMAND_IN_PROGRESS)
322 /* Address Config. Register.
326 #define ACF_CONNECTOR_BITS 14
327 #define ACF_CONNECTOR_UTP 0
328 #define ACF_CONNECTOR_AUI 1
329 #define ACF_CONNECTOR_BNC 3
331 #define INTERNAL_CONNECTOR_BITS 20
332 #define INTERNAL_CONNECTOR_MASK 0x01700000
335 * FIFO Registers. RX Status.
337 * 15: Incomplete or FIFO empty.
338 * 14: 1: Error in RX Packet 0: Incomplete or no error.
339 * 13-11: Type of error.
341 * 1011 = Run Packet Error.
342 * 1100 = Alignment Error.
344 * 1001 = Oversize Packet Error (>1514 bytes)
345 * 0010 = Dribble Bits.
346 * (all other error codes, no errors.)
348 * 10-0: RX Bytes (0-1514)
350 #define ERR_INCOMPLETE (u_short) (0x8000)
351 #define ERR_RX (u_short) (0x4000)
352 #define ERR_MASK (u_short) (0x7800)
353 #define ERR_OVERRUN (u_short) (0x4000)
354 #define ERR_RUNT (u_short) (0x5800)
355 #define ERR_ALIGNMENT (u_short) (0x6000)
356 #define ERR_CRC (u_short) (0x6800)
357 #define ERR_OVERSIZE (u_short) (0x4800)
358 #define ERR_DRIBBLE (u_short) (0x1000)
363 * Reports the transmit status of a completed transmission. Writing this
364 * register pops the transmit completion stack.
366 * Window 1/Port 0x0b.
369 * 6: Interrupt on successful transmission requested.
370 * 5: Jabber Error (TP Only, TX Reset required. )
371 * 4: Underrun (TX Reset required. )
372 * 3: Maximum Collisions.
373 * 2: TX Status Overflow.
377 #define TXS_COMPLETE 0x80
378 #define TXS_INTR_REQ 0x40
379 #define TXS_JABBER 0x20
380 #define TXS_UNDERRUN 0x10
381 #define TXS_MAX_COLLISION 0x8
382 #define TXS_STATUS_OVERFLOW 0x4
384 #define RS_AUI (1<<5)
385 #define RS_BNC (1<<4)
386 #define RS_UTP (1<<3)
390 #define RS_MII (1<<6)
394 * FIFO Status (Window 4)
396 * Supports FIFO diagnostics
398 * Window 4/Port 0x04.1
400 * 15: 1=RX receiving (RO). Set when a packet is being received
403 * 13: 1=RX underrun (RO). Generates Adapter Failure interrupt.
404 * Requires RX Reset or Global Reset command to recover.
405 * It is generated when you read past the end of a packet -
406 * reading past what has been received so far will give bad
408 * 12: 1=RX status overrun (RO). Set when there are already 8
409 * packets in the RX FIFO. While this bit is set, no additional
410 * packets are received. Requires no action on the part of
411 * the host. The condition is cleared once a packet has been
412 * read out of the RX FIFO.
413 * 11: 1=RX overrun (RO). Set when the RX FIFO is full (there
414 * may not be an overrun packet yet). While this bit is set,
415 * no additional packets will be received (some additional
416 * bytes can still be pending between the wire and the RX
417 * FIFO). Requires no action on the part of the host. The
418 * condition is cleared once a few bytes have been read out
420 * 10: 1=TX overrun (RO). Generates adapter failure interrupt.
421 * Requires TX Reset or Global Reset command to recover.
422 * Disables Transmitter.
424 * 7-0: Built in self test bits for the RX and TX FIFO's.
426 #define FIFOS_RX_RECEIVING (u_short) 0x8000
427 #define FIFOS_RX_UNDERRUN (u_short) 0x2000
428 #define FIFOS_RX_STATUS_OVERRUN (u_short) 0x1000
429 #define FIFOS_RX_OVERRUN (u_short) 0x0800
430 #define FIFOS_TX_OVERRUN (u_short) 0x0400
433 * Misc defines for various things.
435 #define TAG_ADAPTER 0xd0
436 #define ACTIVATE_ADAPTER_TO_CONFIG 0xff
437 #define ENABLE_DRQ_IRQ 0x0001
438 #define MFG_ID 0x506d /* `TCM' */
439 #define PROD_ID 0x5090
440 #define GO_WINDOW(x) outw(BASE+VX_COMMAND, WINDOW_SELECT|(x))
441 #define JABBER_GUARD_ENABLE 0x40
442 #define LINKBEAT_ENABLE 0x80
443 #define ENABLE_UTP (JABBER_GUARD_ENABLE | LINKBEAT_ENABLE)
444 #define DISABLE_UTP 0x0
445 #define RX_BYTES_MASK (u_short) (0x07ff)
446 #define TX_INDICATE 1<<15
448 #define VX_IOSIZE 0x20
450 #define VX_CONNECTORS 8
452 extern struct vx_softc *vx_softc[];
453 extern u_long vx_count;
454 extern struct vx_softc *vxalloc __P((int));
455 extern void vxfree __P((struct vx_softc *));
456 extern int vxattach __P((struct vx_softc *));
457 extern void vxstop __P((struct vx_softc *));
458 extern void vxintr __P((void *));
459 extern int vxbusyeeprom __P((struct vx_softc *));