elink.c revision 8876
123353Sdfr/*
223353Sdfr * Copyright (c) 1994 Charles Hannum.  All rights reserved.
323353Sdfr *
423353Sdfr * Redistribution and use in source and binary forms, with or without
523353Sdfr * modification, are permitted provided that the following conditions
623353Sdfr * are met:
723353Sdfr * 1. Redistributions of source code must retain the above copyright
823353Sdfr *    notice, this list of conditions and the following disclaimer.
923353Sdfr * 2. Redistributions in binary form must reproduce the above copyright
1023353Sdfr *    notice, this list of conditions and the following disclaimer in the
1123353Sdfr *    documentation and/or other materials provided with the distribution.
1223353Sdfr * 3. All advertising materials mentioning features or use of this software
1323353Sdfr *    must display the following acknowledgement:
1423353Sdfr *	This product includes software developed by Charles Hannum.
1523353Sdfr * 4. The name of the author may not be used to endorse or promote products
1623353Sdfr *    derived from this software without specific prior written permission.
1723353Sdfr *
1823353Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1923353Sdfr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2023353Sdfr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2123353Sdfr * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2223353Sdfr * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2323353Sdfr * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2423353Sdfr * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2523353Sdfr * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2623353Sdfr * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2723353Sdfr * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2823353Sdfr *
2950476Speter *	$Id: elink.c,v 1.4 1995/02/26 05:14:46 bde Exp $
3023353Sdfr */
3123353Sdfr
32206622Suqs/*
3323353Sdfr * Common code for dealing with 3COM ethernet cards.
3423353Sdfr */
3523353Sdfr
3623353Sdfr#include <sys/types.h>
3723353Sdfr#include <sys/cdefs.h>
3884306Sru
3984306Sru#include <machine/cpufunc.h>
4023353Sdfr
4123353Sdfr#include <i386/isa/elink.h>
4223353Sdfr
4323353Sdfr/*
4423353Sdfr * Issue a `global reset' to all cards.  We have to be careful to do this only
4523353Sdfr * once during autoconfig, to prevent resetting boards that have already been
4670466Sru * configured.
47115440Shmp */
48140931Sruvoid
49115440Shmpelink_reset()
50140931Sru{
51115440Shmp	static int x = 0;
52140931Sru
5323353Sdfr	if (x == 0) {
5423353Sdfr		x = 1;
55107383Sru		outb(ELINK_ID_PORT, ELINK_RESET);
56107383Sru	}
57107383Sru}
58103469Struckman
59107383Sru/*
60107383Sru * The `ID sequence' is really just snapshots of an 8-bit CRC register as 0
61107383Sru * bits are shifted in.  Different board types use different polynomials.
6223353Sdfr */
63108257Sruvoid
64103637Struckmanelink_idseq(p)
65107383Sru	register u_char p;
6623353Sdfr{
6723353Sdfr	register int i;
6823353Sdfr	register u_char c;
6923353Sdfr
7023467Smpp	c = 0xff;
71103469Struckman	for (i = 255; i; i--) {
72103534Struckman		outb(ELINK_ID_PORT, c);
7323353Sdfr		if (c & 0x80) {
74103534Struckman			c <<= 1;
75103469Struckman			c ^= p;
76103534Struckman		} else
77103469Struckman			c <<= 1;
7823353Sdfr	}
79131594Sru}
80131594Sru