1994-01-10 18:56:26 +00:00
|
|
|
/*
|
1995-01-08 10:47:23 +00:00
|
|
|
* Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
1994-01-10 18:56:26 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
1995-01-08 10:47:23 +00:00
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Herb Peyerl.
|
|
|
|
* 4. The name of Herb Peyerl may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
1995-03-31 06:41:38 +00:00
|
|
|
* if_ep.c,v 1.19 1995/01/24 20:53:45 davidg Exp
|
1995-01-24 20:53:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modified from the FreeBSD 1.1.5.1 version by:
|
1995-05-30 08:16:23 +00:00
|
|
|
* Andres Vega Garcia
|
1995-01-24 20:53:45 +00:00
|
|
|
* INRIA - Sophia Antipolis, France
|
|
|
|
* avega@sophia.inria.fr
|
1994-01-10 18:56:26 +00:00
|
|
|
*/
|
1994-05-02 22:27:33 +00:00
|
|
|
|
1995-03-31 06:41:38 +00:00
|
|
|
/*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1995-03-31 06:41:38 +00:00
|
|
|
*
|
|
|
|
* Promiscuous mode added and interrupt logic slightly changed
|
|
|
|
* to reduce the number of adapter failures. Transceiver select
|
|
|
|
* logic changed to use value from EEPROM. Autoconfiguration
|
|
|
|
* features added.
|
|
|
|
* Done by:
|
|
|
|
* Serge Babkin
|
|
|
|
* Chelindbank (Chelyabinsk, Russia)
|
|
|
|
* babkin@hq.icb.chel.su
|
|
|
|
*/
|
|
|
|
|
1996-06-14 22:11:38 +00:00
|
|
|
/*
|
|
|
|
* Pccard support for 3C589 by:
|
|
|
|
* HAMADA Naoki
|
|
|
|
* nao@tom-yam.or.jp
|
|
|
|
*/
|
|
|
|
|
1994-01-10 18:56:26 +00:00
|
|
|
#include "ep.h"
|
|
|
|
#if NEP > 0
|
1994-01-26 09:06:29 +00:00
|
|
|
|
1999-07-06 19:23:32 +00:00
|
|
|
#include "bpf.h"
|
1998-01-08 23:42:31 +00:00
|
|
|
#include "opt_inet.h"
|
1997-12-15 20:31:25 +00:00
|
|
|
#include "opt_ipx.h"
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-05-02 22:27:33 +00:00
|
|
|
#include <sys/param.h>
|
1994-01-26 09:13:56 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1997-10-26 21:08:42 +00:00
|
|
|
#include <sys/kernel.h>
|
1994-05-02 22:27:33 +00:00
|
|
|
#include <sys/systm.h>
|
1994-01-26 09:13:56 +00:00
|
|
|
#endif
|
1997-09-02 01:19:47 +00:00
|
|
|
#include <sys/malloc.h>
|
1994-05-02 22:27:33 +00:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
1997-03-24 11:33:46 +00:00
|
|
|
#include <sys/sockio.h>
|
1994-01-26 09:13:56 +00:00
|
|
|
#if defined(__NetBSD__)
|
1994-05-02 22:27:33 +00:00
|
|
|
#include <sys/select.h>
|
1994-01-26 09:13:56 +00:00
|
|
|
#endif
|
1994-01-26 09:06:29 +00:00
|
|
|
|
1999-08-18 22:14:24 +00:00
|
|
|
#include <net/ethernet.h>
|
1994-05-02 22:27:33 +00:00
|
|
|
#include <net/if.h>
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1999-08-18 22:14:24 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/if_ether.h>
|
|
|
|
|
1999-07-06 19:23:32 +00:00
|
|
|
#if NBPF > 0
|
1994-05-02 22:27:33 +00:00
|
|
|
#include <net/bpf.h>
|
1994-01-10 18:56:26 +00:00
|
|
|
#endif
|
|
|
|
|
1995-03-28 07:58:53 +00:00
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
#include <machine/clock.h>
|
|
|
|
#endif
|
|
|
|
|
1994-05-02 22:27:33 +00:00
|
|
|
#include <i386/isa/isa_device.h>
|
|
|
|
#include <i386/isa/if_epreg.h>
|
1996-01-29 03:16:14 +00:00
|
|
|
#include <i386/isa/elink.h>
|
1994-01-26 09:06:29 +00:00
|
|
|
|
1999-01-31 22:41:51 +00:00
|
|
|
/* DELAY_MULTIPLE: How much to boost "base" delays, except
|
|
|
|
* for the inter-bit delays in get_eeprom_data. A cyrix Media GX needed this.
|
|
|
|
*/
|
|
|
|
#define DELAY_MULTIPLE 10
|
|
|
|
#define BIT_DELAY_MULTIPLE 10
|
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
/* Exported variables */
|
|
|
|
u_long ep_unit;
|
|
|
|
int ep_boards;
|
|
|
|
struct ep_board ep_board[EP_MAX_BOARDS + 1];
|
1995-12-15 00:54:32 +00:00
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
static int eeprom_rdy __P((struct ep_softc *sc));
|
1994-01-26 09:13:56 +00:00
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
static int ep_isa_probe __P((struct isa_device *));
|
|
|
|
static struct ep_board * ep_look_for_board_at __P((struct isa_device *is));
|
|
|
|
static int ep_isa_attach __P((struct isa_device *));
|
1998-06-07 17:13:14 +00:00
|
|
|
static int epioctl __P((struct ifnet * ifp, u_long, caddr_t));
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1999-08-20 14:12:14 +00:00
|
|
|
static void epinit __P((void *));
|
1998-10-22 05:58:45 +00:00
|
|
|
static ointhand2_t epintr;
|
1996-02-26 01:05:36 +00:00
|
|
|
static void epread __P((struct ep_softc *));
|
|
|
|
void epreset __P((int));
|
|
|
|
static void epstart __P((struct ifnet *));
|
|
|
|
static void epstop __P((struct ep_softc *));
|
|
|
|
static void epwatchdog __P((struct ifnet *));
|
1994-11-13 10:12:37 +00:00
|
|
|
|
1996-06-14 22:11:38 +00:00
|
|
|
#if 0
|
1996-02-26 01:05:36 +00:00
|
|
|
static int send_ID_sequence __P((int));
|
1996-06-14 22:11:38 +00:00
|
|
|
#endif
|
1996-02-26 01:05:36 +00:00
|
|
|
static int get_eeprom_data __P((int, int));
|
|
|
|
|
|
|
|
static struct ep_softc* ep_softc[NEP];
|
|
|
|
static int ep_current_tag = EP_LAST_TAG + 1;
|
|
|
|
static char *ep_conn_type[] = {"UTP", "AUI", "???", "BNC"};
|
1994-11-13 10:12:37 +00:00
|
|
|
|
|
|
|
#define ep_ftst(f) (sc->stat&(f))
|
|
|
|
#define ep_fset(f) (sc->stat|=(f))
|
|
|
|
#define ep_frst(f) (sc->stat&=~(f))
|
|
|
|
|
1994-01-10 18:56:26 +00:00
|
|
|
struct isa_driver epdriver = {
|
1996-02-26 01:05:36 +00:00
|
|
|
ep_isa_probe,
|
|
|
|
ep_isa_attach,
|
1995-03-31 06:41:38 +00:00
|
|
|
"ep",
|
1996-02-26 01:05:36 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
#include "card.h"
|
1996-06-14 22:11:38 +00:00
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
#if NCARD > 0
|
1996-06-14 22:11:38 +00:00
|
|
|
#include <sys/select.h>
|
1999-01-19 00:21:53 +00:00
|
|
|
#include <sys/module.h>
|
1997-11-20 15:48:41 +00:00
|
|
|
#include <pccard/cardinfo.h>
|
1996-06-14 22:11:38 +00:00
|
|
|
#include <pccard/slot.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PC-Card (PCMCIA) specific code.
|
|
|
|
*/
|
1997-10-26 04:54:16 +00:00
|
|
|
static int ep_pccard_init __P((struct pccard_devinfo *));
|
1997-10-26 04:36:24 +00:00
|
|
|
static int ep_pccard_attach __P((struct pccard_devinfo *));
|
|
|
|
static void ep_unload __P((struct pccard_devinfo *));
|
|
|
|
static int card_intr __P((struct pccard_devinfo *));
|
1999-09-19 06:20:23 +00:00
|
|
|
static int ep_pccard_identify (struct ep_board *epb, int unit);
|
1996-06-14 22:11:38 +00:00
|
|
|
|
1999-01-19 00:21:53 +00:00
|
|
|
PCCARD_MODULE(ep, ep_pccard_init, ep_unload, card_intr, 0, net_imask);
|
1997-10-26 21:08:42 +00:00
|
|
|
|
1996-06-14 22:11:38 +00:00
|
|
|
/*
|
1997-10-26 04:36:24 +00:00
|
|
|
* Initialize the device - called from Slot manager.
|
1996-06-14 22:11:38 +00:00
|
|
|
*/
|
|
|
|
static int
|
1997-10-26 04:54:16 +00:00
|
|
|
ep_pccard_init(devi)
|
1997-10-26 04:36:24 +00:00
|
|
|
struct pccard_devinfo *devi;
|
1996-06-14 22:11:38 +00:00
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct isa_device *is = &devi->isahd;
|
1996-06-14 22:11:38 +00:00
|
|
|
struct ep_softc *sc = ep_softc[is->id_unit];
|
|
|
|
struct ep_board *epb;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
epb = &ep_board[is->id_unit];
|
|
|
|
|
|
|
|
if (sc == 0) {
|
|
|
|
if ((sc = ep_alloc(is->id_unit, epb)) == 0) {
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
ep_unit++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get_e() requires these. */
|
|
|
|
sc->ep_io_addr = is->id_iobase;
|
|
|
|
sc->unit = is->id_unit;
|
|
|
|
epb->epb_addr = is->id_iobase;
|
|
|
|
epb->epb_used = 1;
|
1999-07-25 01:20:37 +00:00
|
|
|
|
1999-09-19 06:20:23 +00:00
|
|
|
/*
|
|
|
|
* XXX - Certain (newer?) 3Com cards need epb->cmd_off == 2. Sadly,
|
|
|
|
* you need to have a correct cmd_off in order to identify the card.
|
|
|
|
* So we have to hit it with both and cross our virtual fingers. There's
|
|
|
|
* got to be a better way to do this. jyoung@accessus.net 09/11/1999
|
|
|
|
*/
|
|
|
|
|
|
|
|
epb->cmd_off = 0;
|
|
|
|
epb->prod_id = get_e(sc, EEPROM_PROD_ID);
|
|
|
|
if (bootverbose) printf("ep%d: Pass 1 of 2 detection failed (nonfatal)\n", is->id_unit);
|
|
|
|
if (!ep_pccard_identify(epb, is->id_unit)) {
|
|
|
|
epb->cmd_off = 2;
|
|
|
|
epb->prod_id = get_e(sc, EEPROM_PROD_ID);
|
|
|
|
if (!ep_pccard_identify(epb, is->id_unit)) {
|
|
|
|
if (bootverbose) printf("ep%d: Pass 2 of 2 detection failed (fatal!)\n", is->id_unit);
|
|
|
|
printf("ep%d: Unit failed to come ready or product ID unknown! (id 0x%x)\n", is->id_unit, epb->prod_id);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
1996-06-14 22:11:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
epb->res_cfg = get_e(sc, EEPROM_RESOURCE_CFG);
|
1997-10-26 04:36:24 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
sc->epb->eth_addr[i] = get_e(sc, EEPROM_NODE_ADDR_0 + i);
|
1996-06-14 22:11:38 +00:00
|
|
|
|
1997-10-26 04:54:16 +00:00
|
|
|
if (ep_pccard_attach(devi) == 0)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
sc->arpcom.ac_if.if_snd.ifq_maxlen = ifqmaxlen;
|
1996-06-14 22:11:38 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-09-19 06:20:23 +00:00
|
|
|
static int
|
|
|
|
ep_pccard_identify(epb, unit)
|
|
|
|
struct ep_board *epb;
|
|
|
|
int unit;
|
|
|
|
{
|
|
|
|
/* Determine device type and associated MII capabilities */
|
|
|
|
switch (epb->prod_id) {
|
|
|
|
case 0x6055: /* 3C556 */
|
|
|
|
if (bootverbose) printf("ep%d: 3Com 3C556\n", unit);
|
|
|
|
epb->mii_trans = 1;
|
|
|
|
return (1);
|
|
|
|
break; /* NOTREACHED */
|
|
|
|
case 0x4057: /* 3C574 */
|
|
|
|
if (bootverbose) printf("ep%d: 3Com 3C574\n", unit);
|
|
|
|
epb->mii_trans = 1;
|
|
|
|
return (1);
|
|
|
|
break; /* NOTREACHED */
|
|
|
|
case 0x4b57: /* 3C574B */
|
|
|
|
if (bootverbose) printf("ep%d: 3Com 3C574B, Megahertz 3CCFE574BT or Fast Etherlink 3C574-TX\n", unit);
|
|
|
|
epb->mii_trans = 1;
|
|
|
|
return (1);
|
|
|
|
break; /* NOTREACHED */
|
|
|
|
case 0x9058: /* 3C589 */
|
|
|
|
if (bootverbose) printf("ep%d: 3Com Etherlink III 3C589[B/C/D]\n", unit);
|
|
|
|
epb->mii_trans = 0;
|
|
|
|
return (1);
|
|
|
|
break; /* NOTREACHED */
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-06-14 22:11:38 +00:00
|
|
|
static int
|
1997-10-26 04:36:24 +00:00
|
|
|
ep_pccard_attach(devi)
|
|
|
|
struct pccard_devinfo *devi;
|
1996-06-14 22:11:38 +00:00
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct isa_device *is = &devi->isahd;
|
1996-06-14 22:11:38 +00:00
|
|
|
struct ep_softc *sc = ep_softc[is->id_unit];
|
|
|
|
u_short config;
|
|
|
|
|
|
|
|
sc->ep_connectors = 0;
|
|
|
|
config = inw(IS_BASE + EP_W0_CONFIG_CTRL);
|
|
|
|
if (config & IS_BNC) {
|
|
|
|
sc->ep_connectors |= BNC;
|
|
|
|
}
|
|
|
|
if (config & IS_UTP) {
|
|
|
|
sc->ep_connectors |= UTP;
|
|
|
|
}
|
|
|
|
if (!(sc->ep_connectors & 7))
|
1999-09-19 06:20:23 +00:00
|
|
|
/* (Apparently) non-fatal */
|
|
|
|
if(bootverbose) printf("ep%d: No connectors or MII.\n", is->id_unit);
|
|
|
|
|
1996-06-14 22:11:38 +00:00
|
|
|
sc->ep_connector = inw(BASE + EP_W0_ADDRESS_CFG) >> ACF_CONNECTOR_BITS;
|
|
|
|
|
|
|
|
/* ROM size = 0, ROM base = 0 */
|
|
|
|
/* For now, ignore AUTO SELECT feature of 3C589B and later. */
|
|
|
|
outw(BASE + EP_W0_ADDRESS_CFG, get_e(sc, EEPROM_ADDR_CFG) & 0xc000);
|
|
|
|
|
|
|
|
/* Fake IRQ must be 3 */
|
|
|
|
outw(BASE + EP_W0_RESOURCE_CFG, (sc->epb->res_cfg & 0x0fff) | 0x3000);
|
|
|
|
|
|
|
|
outw(BASE + EP_W0_PRODUCT_ID, sc->epb->prod_id);
|
|
|
|
|
1999-07-25 01:20:37 +00:00
|
|
|
if (sc->epb->mii_trans) {
|
|
|
|
/*
|
1999-09-19 06:20:23 +00:00
|
|
|
* turn on the MII transciever
|
1999-07-25 01:20:37 +00:00
|
|
|
*/
|
|
|
|
GO_WINDOW(3);
|
|
|
|
outw(BASE + EP_W3_OPTIONS, 0x8040);
|
|
|
|
DELAY(1000);
|
|
|
|
outw(BASE + EP_W3_OPTIONS, 0xc040);
|
|
|
|
outw(BASE + EP_COMMAND, RX_RESET);
|
|
|
|
outw(BASE + EP_COMMAND, TX_RESET);
|
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
|
|
|
DELAY(1000);
|
|
|
|
outw(BASE + EP_W3_OPTIONS, 0x8040);
|
|
|
|
}
|
|
|
|
|
1996-06-14 22:11:38 +00:00
|
|
|
ep_attach(sc);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-26 04:36:24 +00:00
|
|
|
ep_unload(devi)
|
|
|
|
struct pccard_devinfo *devi;
|
1996-06-14 22:11:38 +00:00
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct ep_softc *sc = ep_softc[devi->isahd.id_unit];
|
1996-06-14 22:11:38 +00:00
|
|
|
|
1996-09-06 23:09:20 +00:00
|
|
|
if (sc->gone) {
|
1997-10-26 04:36:24 +00:00
|
|
|
printf("ep%d: already unloaded\n", devi->isahd.id_unit);
|
1996-06-14 22:11:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
sc->arpcom.ac_if.if_flags &= ~IFF_RUNNING;
|
|
|
|
sc->gone = 1;
|
1997-10-26 04:36:24 +00:00
|
|
|
printf("ep%d: unload\n", devi->isahd.id_unit);
|
1996-06-14 22:11:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* card_intr - Shared interrupt called from
|
|
|
|
* front end of PC-Card handler.
|
|
|
|
*/
|
|
|
|
static int
|
1997-10-26 04:36:24 +00:00
|
|
|
card_intr(devi)
|
|
|
|
struct pccard_devinfo *devi;
|
1996-06-14 22:11:38 +00:00
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
epintr(devi->isahd.id_unit);
|
1996-06-14 22:11:38 +00:00
|
|
|
return(1);
|
|
|
|
}
|
1997-10-26 04:36:24 +00:00
|
|
|
#endif /* NCARD > 0 */
|
1996-06-14 22:11:38 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
static int
|
1996-02-26 01:05:36 +00:00
|
|
|
eeprom_rdy(sc)
|
|
|
|
struct ep_softc *sc;
|
1994-11-13 10:12:37 +00:00
|
|
|
{
|
|
|
|
int i;
|
1994-09-03 18:10:44 +00:00
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
for (i = 0; is_eeprom_busy(BASE) && i < MAX_EEPROMBUSY; i++)
|
|
|
|
continue;
|
1994-11-13 10:12:37 +00:00
|
|
|
if (i >= MAX_EEPROMBUSY) {
|
1996-02-26 01:05:36 +00:00
|
|
|
printf("ep%d: eeprom failed to come ready.\n", sc->unit);
|
1994-11-13 10:12:37 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
1994-09-03 18:10:44 +00:00
|
|
|
|
1996-01-29 03:16:14 +00:00
|
|
|
static struct ep_board *
|
1994-11-13 10:12:37 +00:00
|
|
|
ep_look_for_board_at(is)
|
|
|
|
struct isa_device *is;
|
1994-09-03 18:10:44 +00:00
|
|
|
{
|
1996-06-12 05:11:41 +00:00
|
|
|
int data, i, j, id_port = ELINK_ID_PORT;
|
1996-02-26 01:05:36 +00:00
|
|
|
int count = 0;
|
1994-11-13 10:12:37 +00:00
|
|
|
|
|
|
|
if (ep_current_tag == (EP_LAST_TAG + 1)) {
|
|
|
|
/* Come here just one time */
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
ep_current_tag--;
|
|
|
|
|
|
|
|
/* Look for the ISA boards. Init and leave them actived */
|
1996-01-29 03:16:14 +00:00
|
|
|
outb(id_port, 0);
|
|
|
|
outb(id_port, 0);
|
|
|
|
|
|
|
|
elink_idseq(0xCF);
|
|
|
|
|
|
|
|
elink_reset();
|
1999-01-31 22:41:51 +00:00
|
|
|
DELAY(DELAY_MULTIPLE * 10000);
|
1994-11-13 10:12:37 +00:00
|
|
|
for (i = 0; i < EP_MAX_BOARDS; i++) {
|
|
|
|
outb(id_port, 0);
|
|
|
|
outb(id_port, 0);
|
1996-01-29 03:16:14 +00:00
|
|
|
elink_idseq(0xCF);
|
1994-11-13 10:12:37 +00:00
|
|
|
|
|
|
|
data = get_eeprom_data(id_port, EEPROM_MFG_ID);
|
|
|
|
if (data != MFG_ID)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* resolve contention using the Ethernet address */
|
1996-01-29 03:16:14 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
for (j = 0; j < 3; j++)
|
1996-01-29 03:16:14 +00:00
|
|
|
get_eeprom_data(id_port, j);
|
|
|
|
|
|
|
|
/* and save this address for later use */
|
|
|
|
|
|
|
|
for (j = 0; j < 3; j++)
|
1996-02-26 01:05:36 +00:00
|
|
|
ep_board[ep_boards].eth_addr[j] = get_eeprom_data(id_port, j);
|
1996-01-29 03:16:14 +00:00
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
ep_board[ep_boards].res_cfg =
|
1996-01-29 03:16:14 +00:00
|
|
|
get_eeprom_data(id_port, EEPROM_RESOURCE_CFG);
|
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
ep_board[ep_boards].prod_id =
|
1996-01-29 03:16:14 +00:00
|
|
|
get_eeprom_data(id_port, EEPROM_PROD_ID);
|
1994-09-03 18:10:44 +00:00
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
ep_board[ep_boards].epb_used = 0;
|
1996-12-19 10:31:10 +00:00
|
|
|
#ifdef PC98
|
|
|
|
ep_board[ep_boards].epb_addr =
|
|
|
|
(get_eeprom_data(id_port, EEPROM_ADDR_CFG) & 0x1f) * 0x100 + 0x40d0;
|
|
|
|
#else
|
1996-02-26 01:05:36 +00:00
|
|
|
ep_board[ep_boards].epb_addr =
|
1996-01-29 03:16:14 +00:00
|
|
|
(get_eeprom_data(id_port, EEPROM_ADDR_CFG) & 0x1f) * 0x10 + 0x200;
|
|
|
|
|
1997-10-14 06:56:09 +00:00
|
|
|
if (ep_board[ep_boards].epb_addr > 0x3E0)
|
1996-02-26 01:05:36 +00:00
|
|
|
/* Board in EISA configuration mode */
|
|
|
|
continue;
|
1996-12-19 10:31:10 +00:00
|
|
|
#endif /* PC98 */
|
1996-02-26 01:05:36 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
outb(id_port, ep_current_tag); /* tags board */
|
|
|
|
outb(id_port, ACTIVATE_ADAPTER_TO_CONFIG);
|
1996-02-26 01:05:36 +00:00
|
|
|
ep_boards++;
|
|
|
|
count++;
|
1994-11-13 10:12:37 +00:00
|
|
|
ep_current_tag--;
|
|
|
|
}
|
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
ep_board[ep_boards].epb_addr = 0;
|
|
|
|
if (count) {
|
|
|
|
printf("%d 3C5x9 board(s) on ISA found at", count);
|
1995-03-31 06:41:38 +00:00
|
|
|
for (j = 0; ep_board[j].epb_addr; j++)
|
1996-02-26 01:05:36 +00:00
|
|
|
if (ep_board[j].epb_addr <= 0x3E0)
|
1995-03-31 06:41:38 +00:00
|
|
|
printf(" 0x%x", ep_board[j].epb_addr);
|
1994-11-13 10:12:37 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-03-31 06:41:38 +00:00
|
|
|
/* we have two cases:
|
|
|
|
*
|
|
|
|
* 1. Device was configured with 'port ?'
|
|
|
|
* In this case we search for the first unused card in list
|
|
|
|
*
|
|
|
|
* 2. Device was configured with 'port xxx'
|
|
|
|
* In this case we search for the unused card with that address
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1997-10-14 06:56:09 +00:00
|
|
|
if (IS_BASE == -1) { /* port? */
|
|
|
|
for (i = 0; ep_board[i].epb_addr && ep_board[i].epb_used; i++)
|
|
|
|
;
|
|
|
|
if (ep_board[i].epb_addr == 0)
|
1995-03-31 06:41:38 +00:00
|
|
|
return 0;
|
|
|
|
|
1997-10-14 06:56:09 +00:00
|
|
|
IS_BASE = ep_board[i].epb_addr;
|
|
|
|
ep_board[i].epb_used = 1;
|
1996-01-29 03:16:14 +00:00
|
|
|
|
|
|
|
return &ep_board[i];
|
1995-03-31 06:41:38 +00:00
|
|
|
} else {
|
1997-10-14 06:56:09 +00:00
|
|
|
for (i = 0;
|
|
|
|
ep_board[i].epb_addr && ep_board[i].epb_addr != IS_BASE;
|
|
|
|
i++)
|
|
|
|
;
|
1995-03-31 06:41:38 +00:00
|
|
|
|
1997-10-14 06:56:09 +00:00
|
|
|
if (ep_board[i].epb_used || ep_board[i].epb_addr != IS_BASE)
|
1995-03-31 06:41:38 +00:00
|
|
|
return 0;
|
|
|
|
|
1997-10-14 06:56:09 +00:00
|
|
|
if (inw(IS_BASE + EP_W0_EEPROM_COMMAND) & EEPROM_TST_MODE) {
|
1996-02-26 01:05:36 +00:00
|
|
|
printf("ep%d: 3c5x9 at 0x%x in PnP mode. Disable PnP mode!\n",
|
1994-11-13 10:12:37 +00:00
|
|
|
is->id_unit, IS_BASE);
|
1997-10-14 06:56:09 +00:00
|
|
|
}
|
|
|
|
ep_board[i].epb_used = 1;
|
1996-01-29 03:16:14 +00:00
|
|
|
|
|
|
|
return &ep_board[i];
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
|
|
|
}
|
1994-01-26 09:06:29 +00:00
|
|
|
|
1994-01-10 18:56:26 +00:00
|
|
|
/*
|
1994-11-13 10:12:37 +00:00
|
|
|
* get_e: gets a 16 bits word from the EEPROM. we must have set the window
|
|
|
|
* before
|
1994-01-10 18:56:26 +00:00
|
|
|
*/
|
1996-02-26 01:05:36 +00:00
|
|
|
u_int16_t
|
|
|
|
get_e(sc, offset)
|
|
|
|
struct ep_softc *sc;
|
1994-11-13 10:12:37 +00:00
|
|
|
int offset;
|
|
|
|
{
|
1996-02-26 01:05:36 +00:00
|
|
|
if (!eeprom_rdy(sc))
|
1994-11-13 10:12:37 +00:00
|
|
|
return (0xffff);
|
1999-07-25 01:20:37 +00:00
|
|
|
outw(BASE + EP_W0_EEPROM_COMMAND, (EEPROM_CMD_RD << sc->epb->cmd_off) | offset);
|
1996-02-26 01:05:36 +00:00
|
|
|
if (!eeprom_rdy(sc))
|
1994-11-13 10:12:37 +00:00
|
|
|
return (0xffff);
|
1996-02-26 01:05:36 +00:00
|
|
|
return (inw(BASE + EP_W0_EEPROM_DATA));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ep_softc *
|
|
|
|
ep_alloc(unit, epb)
|
|
|
|
int unit;
|
|
|
|
struct ep_board *epb;
|
|
|
|
{
|
|
|
|
struct ep_softc *sc;
|
|
|
|
|
|
|
|
if (unit >= NEP) {
|
|
|
|
printf("ep: unit number (%d) too high\n", unit);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a storage area for us
|
|
|
|
*/
|
|
|
|
if (ep_softc[unit]) {
|
|
|
|
printf("ep%d: unit number already allocated to another "
|
|
|
|
"adaptor\n", unit);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc = malloc(sizeof(struct ep_softc), M_DEVBUF, M_NOWAIT);
|
1997-10-14 06:56:09 +00:00
|
|
|
if (!sc) {
|
1996-02-26 01:05:36 +00:00
|
|
|
printf("ep%d: cannot malloc!\n", unit);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
bzero(sc, sizeof(struct ep_softc));
|
|
|
|
ep_softc[unit] = sc;
|
|
|
|
sc->unit = unit;
|
|
|
|
sc->ep_io_addr = epb->epb_addr;
|
|
|
|
sc->epb = epb;
|
|
|
|
|
|
|
|
return(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ep_free(sc)
|
|
|
|
struct ep_softc *sc;
|
|
|
|
{
|
|
|
|
ep_softc[sc->unit] = NULL;
|
|
|
|
free(sc, M_DEVBUF);
|
|
|
|
return;
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
|
|
|
|
1994-01-26 09:06:29 +00:00
|
|
|
int
|
1996-02-26 01:05:36 +00:00
|
|
|
ep_isa_probe(is)
|
1994-11-13 10:12:37 +00:00
|
|
|
struct isa_device *is;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1996-02-26 01:05:36 +00:00
|
|
|
struct ep_softc *sc;
|
|
|
|
struct ep_board *epb;
|
1994-11-13 10:12:37 +00:00
|
|
|
u_short k;
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1997-10-14 06:56:09 +00:00
|
|
|
if ((epb = ep_look_for_board_at(is)) == 0)
|
1996-02-26 01:05:36 +00:00
|
|
|
return (0);
|
1995-04-12 20:48:13 +00:00
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
/*
|
|
|
|
* Allocate a storage area for us
|
|
|
|
*/
|
|
|
|
sc = ep_alloc(ep_unit, epb);
|
1997-10-14 06:56:09 +00:00
|
|
|
if (!sc)
|
1994-11-13 10:12:37 +00:00
|
|
|
return (0);
|
1996-02-26 01:05:36 +00:00
|
|
|
|
|
|
|
is->id_unit = ep_unit++;
|
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/*
|
|
|
|
* The iobase was found and MFG_ID was 0x6d50. PROD_ID should be
|
1997-11-27 12:59:46 +00:00
|
|
|
* 0x9[0-f]50 (IBM-PC)
|
|
|
|
* 0x9[0-f]5[0-f] (PC-98)
|
1994-11-13 10:12:37 +00:00
|
|
|
*/
|
|
|
|
GO_WINDOW(0);
|
1996-02-26 01:05:36 +00:00
|
|
|
k = sc->epb->prod_id;
|
1997-11-27 12:59:46 +00:00
|
|
|
#ifdef PC98
|
|
|
|
if ((k & 0xf0f0) != (PROD_ID & 0xf0f0)) {
|
|
|
|
#else
|
1994-11-13 10:12:37 +00:00
|
|
|
if ((k & 0xf0ff) != (PROD_ID & 0xf0ff)) {
|
1997-11-27 12:59:46 +00:00
|
|
|
#endif
|
1996-02-26 01:05:36 +00:00
|
|
|
printf("ep_isa_probe: ignoring model %04x\n", k);
|
|
|
|
ep_free(sc);
|
1994-11-13 10:12:37 +00:00
|
|
|
return (0);
|
|
|
|
}
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
k = sc->epb->res_cfg;
|
1996-01-29 03:16:14 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
k >>= 12;
|
1995-03-31 06:41:38 +00:00
|
|
|
|
|
|
|
/* Now we have two cases again:
|
|
|
|
*
|
|
|
|
* 1. Device was configured with 'irq?'
|
|
|
|
* In this case we use irq read from the board
|
|
|
|
*
|
|
|
|
* 2. Device was configured with 'irq xxx'
|
|
|
|
* In this case we set up the board to use specified interrupt
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1997-10-14 06:56:09 +00:00
|
|
|
if (is->id_irq == 0) { /* irq? */
|
|
|
|
is->id_irq = 1 << ((k == 2) ? 9 : k);
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
sc->stat = 0; /* 16 bit access */
|
1994-09-03 18:10:44 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/* By now, the adapter is already activated */
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
return (EP_IOSIZE); /* 16 bytes of I/O space used. */
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1994-01-26 09:06:29 +00:00
|
|
|
static int
|
1996-02-26 01:05:36 +00:00
|
|
|
ep_isa_attach(is)
|
1994-11-13 10:12:37 +00:00
|
|
|
struct isa_device *is;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1996-02-26 01:05:36 +00:00
|
|
|
struct ep_softc *sc = ep_softc[is->id_unit];
|
|
|
|
u_short config;
|
1995-03-31 06:41:38 +00:00
|
|
|
int irq;
|
1994-11-13 10:12:37 +00:00
|
|
|
|
1998-10-22 05:58:45 +00:00
|
|
|
is->id_ointr = epintr;
|
1994-11-13 10:12:37 +00:00
|
|
|
sc->ep_connectors = 0;
|
1996-02-26 01:05:36 +00:00
|
|
|
config = inw(IS_BASE + EP_W0_CONFIG_CTRL);
|
|
|
|
if (config & IS_AUI) {
|
1994-11-13 10:12:37 +00:00
|
|
|
sc->ep_connectors |= AUI;
|
|
|
|
}
|
1996-02-26 01:05:36 +00:00
|
|
|
if (config & IS_BNC) {
|
1994-11-13 10:12:37 +00:00
|
|
|
sc->ep_connectors |= BNC;
|
|
|
|
}
|
1996-02-26 01:05:36 +00:00
|
|
|
if (config & IS_UTP) {
|
1994-11-13 10:12:37 +00:00
|
|
|
sc->ep_connectors |= UTP;
|
|
|
|
}
|
|
|
|
if (!(sc->ep_connectors & 7))
|
|
|
|
printf("no connectors!");
|
1996-02-28 17:19:04 +00:00
|
|
|
sc->ep_connector = inw(BASE + EP_W0_ADDRESS_CFG) >> ACF_CONNECTOR_BITS;
|
1995-03-31 06:41:38 +00:00
|
|
|
/*
|
|
|
|
* Write IRQ value to board
|
|
|
|
*/
|
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
irq = ffs(is->id_irq) - 1;
|
1997-10-14 06:56:09 +00:00
|
|
|
if (irq == -1) {
|
1996-02-26 01:05:36 +00:00
|
|
|
printf(" invalid irq... cannot attach\n");
|
1995-03-31 06:41:38 +00:00
|
|
|
return 0;
|
1996-02-26 01:05:36 +00:00
|
|
|
}
|
1995-03-31 06:41:38 +00:00
|
|
|
|
|
|
|
GO_WINDOW(0);
|
1996-07-19 13:20:05 +00:00
|
|
|
SET_IRQ(BASE, irq);
|
1994-11-13 10:12:37 +00:00
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
ep_attach(sc);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ep_attach(sc)
|
|
|
|
struct ep_softc *sc;
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->arpcom.ac_if;
|
|
|
|
u_short *p;
|
|
|
|
int i;
|
1996-06-14 22:11:38 +00:00
|
|
|
int attached;
|
|
|
|
|
|
|
|
sc->gone = 0;
|
|
|
|
attached = (ifp->if_softc != 0);
|
1996-02-26 01:05:36 +00:00
|
|
|
|
|
|
|
printf("ep%d: ", sc->unit);
|
|
|
|
/*
|
|
|
|
* Current media type
|
|
|
|
*/
|
1997-10-14 06:56:09 +00:00
|
|
|
if (sc->ep_connectors & AUI) {
|
1996-02-26 01:05:36 +00:00
|
|
|
printf("aui");
|
1997-10-14 06:56:09 +00:00
|
|
|
if (sc->ep_connectors & ~AUI)
|
1996-02-26 01:05:36 +00:00
|
|
|
printf("/");
|
|
|
|
}
|
1997-10-14 06:56:09 +00:00
|
|
|
if (sc->ep_connectors & UTP) {
|
1996-02-26 01:05:36 +00:00
|
|
|
printf("utp");
|
1997-10-14 06:56:09 +00:00
|
|
|
if (sc->ep_connectors & BNC)
|
1996-02-26 01:05:36 +00:00
|
|
|
printf("/");
|
|
|
|
}
|
1997-10-14 06:56:09 +00:00
|
|
|
if (sc->ep_connectors & BNC) {
|
1996-02-26 01:05:36 +00:00
|
|
|
printf("bnc");
|
|
|
|
}
|
|
|
|
|
1996-02-28 17:19:04 +00:00
|
|
|
printf("[*%s*]", ep_conn_type[sc->ep_connector]);
|
1996-02-26 01:05:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup the station address
|
|
|
|
*/
|
|
|
|
p = (u_short *) & sc->arpcom.ac_enaddr;
|
|
|
|
GO_WINDOW(2);
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
p[i] = htons(sc->epb->eth_addr[i]);
|
|
|
|
outw(BASE + EP_W2_ADDR_0 + (i * 2), ntohs(p[i]));
|
|
|
|
}
|
1996-06-15 00:43:03 +00:00
|
|
|
printf(" address %6D\n", sc->arpcom.ac_enaddr, ":");
|
1996-02-26 01:05:36 +00:00
|
|
|
|
1996-02-06 18:51:28 +00:00
|
|
|
ifp->if_softc = sc;
|
1996-02-26 01:05:36 +00:00
|
|
|
ifp->if_unit = sc->unit;
|
1994-11-13 10:12:37 +00:00
|
|
|
ifp->if_name = "ep";
|
|
|
|
ifp->if_mtu = ETHERMTU;
|
1996-01-29 03:16:14 +00:00
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
1994-11-13 10:12:37 +00:00
|
|
|
ifp->if_output = ether_output;
|
|
|
|
ifp->if_start = epstart;
|
|
|
|
ifp->if_ioctl = epioctl;
|
|
|
|
ifp->if_watchdog = epwatchdog;
|
1999-08-20 14:12:14 +00:00
|
|
|
ifp->if_init = epinit;
|
1994-11-13 10:12:37 +00:00
|
|
|
|
1996-06-14 22:11:38 +00:00
|
|
|
if (!attached) {
|
1997-10-14 06:56:09 +00:00
|
|
|
if_attach(ifp);
|
|
|
|
ether_ifattach(ifp);
|
1996-06-14 22:11:38 +00:00
|
|
|
}
|
1996-01-29 03:16:14 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
#ifdef EP_LOCAL_STATS
|
|
|
|
sc->rx_no_first = sc->rx_no_mbuf =
|
|
|
|
sc->rx_bpf_disc = sc->rx_overrunf = sc->rx_overrunl =
|
|
|
|
sc->tx_underrun = 0;
|
|
|
|
#endif
|
|
|
|
ep_fset(F_RX_FIRST);
|
|
|
|
sc->top = sc->mcur = 0;
|
1994-01-26 09:06:29 +00:00
|
|
|
|
1999-07-06 19:23:32 +00:00
|
|
|
#if NBPF > 0
|
1996-06-14 22:11:38 +00:00
|
|
|
if (!attached) {
|
1997-10-14 06:56:09 +00:00
|
|
|
bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header));
|
1996-06-14 22:11:38 +00:00
|
|
|
}
|
1994-01-10 18:56:26 +00:00
|
|
|
#endif
|
1996-02-26 01:05:36 +00:00
|
|
|
return 0;
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1994-01-26 09:06:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The order in here seems important. Otherwise we may not receive
|
|
|
|
* interrupts. ?!
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
1999-08-20 14:12:14 +00:00
|
|
|
epinit(xsc)
|
|
|
|
void *xsc;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1999-08-20 14:12:14 +00:00
|
|
|
struct ep_softc *sc = xsc;
|
1994-11-13 10:12:37 +00:00
|
|
|
register struct ifnet *ifp = &sc->arpcom.ac_if;
|
1996-06-14 22:11:38 +00:00
|
|
|
int s, i, j;
|
|
|
|
|
|
|
|
if (sc->gone)
|
|
|
|
return;
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1995-04-05 13:12:13 +00:00
|
|
|
/*
|
1994-11-13 10:12:37 +00:00
|
|
|
if (ifp->if_addrlist == (struct ifaddr *) 0)
|
|
|
|
return;
|
1995-04-05 13:12:13 +00:00
|
|
|
*/
|
1994-01-10 19:13:50 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
s = splimp();
|
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1995-03-31 06:41:38 +00:00
|
|
|
GO_WINDOW(0);
|
|
|
|
outw(BASE + EP_COMMAND, STOP_TRANSCEIVER);
|
|
|
|
GO_WINDOW(4);
|
|
|
|
outw(BASE + EP_W4_MEDIA_TYPE, DISABLE_UTP);
|
1994-11-13 10:12:37 +00:00
|
|
|
GO_WINDOW(0);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/* Disable the card */
|
|
|
|
outw(BASE + EP_W0_CONFIG_CTRL, 0);
|
1994-01-26 09:13:56 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/* Enable the card */
|
|
|
|
outw(BASE + EP_W0_CONFIG_CTRL, ENABLE_DRQ_IRQ);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
GO_WINDOW(2);
|
1994-01-26 09:13:56 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/* Reload the ether_addr. */
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
outb(BASE + EP_W2_ADDR_0 + i, sc->arpcom.ac_enaddr[i]);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, RX_RESET);
|
|
|
|
outw(BASE + EP_COMMAND, TX_RESET);
|
1997-10-14 06:56:09 +00:00
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/* Window 1 is operating window */
|
|
|
|
GO_WINDOW(1);
|
|
|
|
for (i = 0; i < 31; i++)
|
|
|
|
inb(BASE + EP_W1_TX_STATUS);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/* get rid of stray intr's */
|
|
|
|
outw(BASE + EP_COMMAND, ACK_INTR | 0xff);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_RD_0_MASK | S_5_INTS);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_INTR_MASK | S_5_INTS);
|
|
|
|
|
1997-10-14 06:56:09 +00:00
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
outw(BASE + EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
|
|
|
|
FIL_GROUP | FIL_BRDCST | FIL_ALL);
|
|
|
|
else
|
|
|
|
outw(BASE + EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
|
|
|
|
FIL_GROUP | FIL_BRDCST);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* S.B.
|
|
|
|
*
|
|
|
|
* Now behavior was slightly changed:
|
|
|
|
*
|
|
|
|
* if any of flags link[0-2] is used and its connector is
|
|
|
|
* physically present the following connectors are used:
|
|
|
|
*
|
|
|
|
* link0 - AUI * highest precedence
|
|
|
|
* link1 - BNC
|
|
|
|
* link2 - UTP * lowest precedence
|
|
|
|
*
|
|
|
|
* If none of them is specified then
|
|
|
|
* connector specified in the EEPROM is used
|
|
|
|
* (if present on card or AUI if not).
|
|
|
|
*
|
|
|
|
*/
|
1995-03-31 06:41:38 +00:00
|
|
|
|
1996-06-14 21:28:35 +00:00
|
|
|
/* Set the xcvr. */
|
1997-10-14 06:56:09 +00:00
|
|
|
if (ifp->if_flags & IFF_LINK0 && sc->ep_connectors & AUI) {
|
1996-06-14 21:28:35 +00:00
|
|
|
i = ACF_CONNECTOR_AUI;
|
1997-10-14 06:56:09 +00:00
|
|
|
} else if (ifp->if_flags & IFF_LINK1 && sc->ep_connectors & BNC) {
|
1996-06-14 21:28:35 +00:00
|
|
|
i = ACF_CONNECTOR_BNC;
|
1997-10-14 06:56:09 +00:00
|
|
|
} else if (ifp->if_flags & IFF_LINK2 && sc->ep_connectors & UTP) {
|
1996-06-14 21:28:35 +00:00
|
|
|
i = ACF_CONNECTOR_UTP;
|
1995-03-31 06:41:38 +00:00
|
|
|
} else {
|
1996-06-14 21:28:35 +00:00
|
|
|
i = sc->ep_connector;
|
|
|
|
}
|
|
|
|
GO_WINDOW(0);
|
|
|
|
j = inw(BASE + EP_W0_ADDRESS_CFG) & 0x3fff;
|
|
|
|
outw(BASE + EP_W0_ADDRESS_CFG, j | (i << ACF_CONNECTOR_BITS));
|
|
|
|
|
|
|
|
switch(i) {
|
|
|
|
case ACF_CONNECTOR_UTP:
|
1997-10-14 06:56:09 +00:00
|
|
|
if (sc->ep_connectors & UTP) {
|
1996-06-14 21:28:35 +00:00
|
|
|
GO_WINDOW(4);
|
|
|
|
outw(BASE + EP_W4_MEDIA_TYPE, ENABLE_UTP);
|
1995-03-31 06:41:38 +00:00
|
|
|
}
|
1996-06-14 21:28:35 +00:00
|
|
|
break;
|
|
|
|
case ACF_CONNECTOR_BNC:
|
1997-10-14 06:56:09 +00:00
|
|
|
if (sc->ep_connectors & BNC) {
|
1996-06-14 21:28:35 +00:00
|
|
|
outw(BASE + EP_COMMAND, START_TRANSCEIVER);
|
1999-01-31 22:41:51 +00:00
|
|
|
DELAY(DELAY_MULTIPLE * 1000);
|
1996-06-14 21:28:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ACF_CONNECTOR_AUI:
|
|
|
|
/* nothing to do */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("ep%d: strange connector type in EEPROM: assuming AUI\n",
|
|
|
|
sc->unit);
|
|
|
|
break;
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
1995-03-31 06:41:38 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, RX_ENABLE);
|
|
|
|
outw(BASE + EP_COMMAND, TX_ENABLE);
|
|
|
|
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE; /* just in case */
|
|
|
|
|
|
|
|
#ifdef EP_LOCAL_STATS
|
|
|
|
sc->rx_no_first = sc->rx_no_mbuf =
|
|
|
|
sc->rx_bpf_disc = sc->rx_overrunf = sc->rx_overrunl =
|
|
|
|
sc->tx_underrun = 0;
|
|
|
|
#endif
|
|
|
|
ep_fset(F_RX_FIRST);
|
|
|
|
if (sc->top) {
|
|
|
|
m_freem(sc->top);
|
|
|
|
sc->top = sc->mcur = 0;
|
|
|
|
}
|
1997-10-14 06:56:09 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
|
1995-04-10 21:25:06 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_TX_START_THRESH | 16);
|
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/*
|
|
|
|
* Store up a bunch of mbuf's for use later. (MAX_MBS). First we free up
|
|
|
|
* any that we had in case we're being called from intr or somewhere
|
|
|
|
* else.
|
|
|
|
*/
|
|
|
|
|
1996-06-14 21:28:35 +00:00
|
|
|
GO_WINDOW(1);
|
1994-11-13 10:12:37 +00:00
|
|
|
epstart(ifp);
|
|
|
|
|
|
|
|
splx(s);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1994-01-26 09:06:29 +00:00
|
|
|
static const char padmap[] = {0, 3, 2, 1};
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
1994-01-26 09:06:29 +00:00
|
|
|
epstart(ifp)
|
1994-11-13 10:12:37 +00:00
|
|
|
struct ifnet *ifp;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1996-02-06 18:51:28 +00:00
|
|
|
register struct ep_softc *sc = ifp->if_softc;
|
1994-11-13 10:12:37 +00:00
|
|
|
register u_int len;
|
|
|
|
register struct mbuf *m;
|
|
|
|
struct mbuf *top;
|
|
|
|
int s, pad;
|
|
|
|
|
1996-06-14 22:11:38 +00:00
|
|
|
if (sc->gone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
s = splimp();
|
1997-10-14 06:56:09 +00:00
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1996-02-13 15:55:33 +00:00
|
|
|
if (ifp->if_flags & IFF_OACTIVE) {
|
1994-11-13 10:12:37 +00:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
1994-01-10 18:56:26 +00:00
|
|
|
startagain:
|
1994-11-13 10:12:37 +00:00
|
|
|
/* Sneak a peek at the next packet */
|
1996-02-13 15:55:33 +00:00
|
|
|
m = ifp->if_snd.ifq_head;
|
1994-11-13 10:12:37 +00:00
|
|
|
if (m == 0) {
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (len = 0, top = m; m; m = m->m_next)
|
|
|
|
len += m->m_len;
|
1994-01-26 09:06:29 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
pad = padmap[len & 3];
|
1994-09-03 18:10:44 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/*
|
|
|
|
* The 3c509 automatically pads short packets to minimum ethernet length,
|
|
|
|
* but we drop packets that are too large. Perhaps we should truncate
|
|
|
|
* them instead?
|
|
|
|
*/
|
|
|
|
if (len + pad > ETHER_MAX_LEN) {
|
|
|
|
/* packet is obviously too large: toss it */
|
1996-02-13 15:55:33 +00:00
|
|
|
++ifp->if_oerrors;
|
|
|
|
IF_DEQUEUE(&ifp->if_snd, m);
|
1994-11-13 10:12:37 +00:00
|
|
|
m_freem(m);
|
|
|
|
goto readcheck;
|
|
|
|
}
|
|
|
|
if (inw(BASE + EP_W1_FREE_TX) < len + pad + 4) {
|
|
|
|
/* no room in FIFO */
|
|
|
|
outw(BASE + EP_COMMAND, SET_TX_AVAIL_THRESH | (len + pad + 4));
|
1997-10-14 06:56:09 +00:00
|
|
|
/* make sure */
|
|
|
|
if (inw(BASE + EP_W1_FREE_TX) < len + pad + 4) {
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
1996-02-13 15:55:33 +00:00
|
|
|
IF_DEQUEUE(&ifp->if_snd, m);
|
1994-11-13 10:12:37 +00:00
|
|
|
|
1996-07-27 12:40:31 +00:00
|
|
|
outw(BASE + EP_W1_TX_PIO_WR_1, len);
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_W1_TX_PIO_WR_1, 0x0); /* Second dword meaningless */
|
|
|
|
|
|
|
|
for (top = m; m != 0; m = m->m_next)
|
1997-10-14 06:56:09 +00:00
|
|
|
if (ep_ftst(F_ACCESS_32_BITS)) {
|
1994-11-13 10:12:37 +00:00
|
|
|
outsl(BASE + EP_W1_TX_PIO_WR_1, mtod(m, caddr_t),
|
|
|
|
m->m_len / 4);
|
|
|
|
if (m->m_len & 3)
|
|
|
|
outsb(BASE + EP_W1_TX_PIO_WR_1,
|
1996-05-24 15:22:36 +00:00
|
|
|
mtod(m, caddr_t) + (m->m_len & (~3)),
|
1994-11-13 10:12:37 +00:00
|
|
|
m->m_len & 3);
|
|
|
|
} else {
|
|
|
|
outsw(BASE + EP_W1_TX_PIO_WR_1, mtod(m, caddr_t), m->m_len / 2);
|
|
|
|
if (m->m_len & 1)
|
|
|
|
outb(BASE + EP_W1_TX_PIO_WR_1,
|
|
|
|
*(mtod(m, caddr_t) + m->m_len - 1));
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
1994-09-03 18:10:44 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
while (pad--)
|
|
|
|
outb(BASE + EP_W1_TX_PIO_WR_1, 0); /* Padding */
|
1994-01-26 09:06:29 +00:00
|
|
|
|
1999-07-06 19:23:32 +00:00
|
|
|
#if NBPF > 0
|
1996-02-13 15:55:33 +00:00
|
|
|
if (ifp->if_bpf) {
|
|
|
|
bpf_mtap(ifp, top);
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1997-10-14 06:56:09 +00:00
|
|
|
ifp->if_timer = 2;
|
1996-02-13 15:55:33 +00:00
|
|
|
ifp->if_opackets++;
|
1994-11-13 10:12:37 +00:00
|
|
|
m_freem(top);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is another packet coming in? We don't want to overflow the tiny RX
|
|
|
|
* fifo.
|
|
|
|
*/
|
1994-01-26 09:06:29 +00:00
|
|
|
readcheck:
|
1994-11-13 10:12:37 +00:00
|
|
|
if (inw(BASE + EP_W1_RX_STATUS) & RX_BYTES_MASK) {
|
|
|
|
/*
|
|
|
|
* we check if we have packets left, in that case we prepare to come
|
|
|
|
* back later
|
|
|
|
*/
|
1996-02-13 15:55:33 +00:00
|
|
|
if (ifp->if_snd.ifq_head) {
|
1997-10-14 06:56:09 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_TX_AVAIL_THRESH | 8);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
1994-11-13 10:12:37 +00:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
goto startagain;
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1998-10-22 05:58:45 +00:00
|
|
|
static void
|
1994-01-26 09:06:29 +00:00
|
|
|
epintr(unit)
|
1994-11-13 10:12:37 +00:00
|
|
|
int unit;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1996-02-26 01:05:36 +00:00
|
|
|
register struct ep_softc *sc = ep_softc[unit];
|
1996-06-14 22:11:38 +00:00
|
|
|
|
|
|
|
if (sc->gone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
ep_intr(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ep_intr(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct ep_softc *sc;
|
1994-11-13 10:12:37 +00:00
|
|
|
register int status;
|
1996-02-13 15:55:33 +00:00
|
|
|
struct ifnet *ifp;
|
1995-04-10 21:25:06 +00:00
|
|
|
int x;
|
|
|
|
|
1997-10-14 06:56:09 +00:00
|
|
|
x = splbio();
|
1994-11-13 10:12:37 +00:00
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
sc = (struct ep_softc *)arg;
|
|
|
|
|
1996-02-13 15:55:33 +00:00
|
|
|
ifp = &sc->arpcom.ac_if;
|
|
|
|
|
1995-04-05 13:12:13 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_INTR_MASK); /* disable all Ints */
|
|
|
|
|
1995-03-23 06:53:39 +00:00
|
|
|
rescan:
|
1994-11-13 10:12:37 +00:00
|
|
|
|
|
|
|
while ((status = inw(BASE + EP_STATUS)) & S_5_INTS) {
|
1995-03-31 06:41:38 +00:00
|
|
|
|
|
|
|
/* first acknowledge all interrupt sources */
|
|
|
|
outw(BASE + EP_COMMAND, ACK_INTR | (status & S_MASK));
|
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
if (status & (S_RX_COMPLETE | S_RX_EARLY)) {
|
|
|
|
epread(sc);
|
|
|
|
continue;
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
if (status & S_TX_AVAIL) {
|
1994-11-13 10:12:37 +00:00
|
|
|
/* we need ACK */
|
1997-10-14 06:56:09 +00:00
|
|
|
ifp->if_timer = 0;
|
1996-02-13 15:55:33 +00:00
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
1995-04-05 13:12:13 +00:00
|
|
|
GO_WINDOW(1);
|
|
|
|
inw(BASE + EP_W1_FREE_TX);
|
1996-02-13 15:55:33 +00:00
|
|
|
epstart(ifp);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
if (status & S_CARD_FAILURE) {
|
1997-10-14 06:56:09 +00:00
|
|
|
ifp->if_timer = 0;
|
1994-11-13 10:12:37 +00:00
|
|
|
#ifdef EP_LOCAL_STATS
|
1996-02-26 01:05:36 +00:00
|
|
|
printf("\nep%d:\n\tStatus: %x\n", sc->unit, status);
|
1994-11-13 10:12:37 +00:00
|
|
|
GO_WINDOW(4);
|
|
|
|
printf("\tFIFO Diagnostic: %x\n", inw(BASE + EP_W4_FIFO_DIAG));
|
|
|
|
printf("\tStat: %x\n", sc->stat);
|
|
|
|
printf("\tIpackets=%d, Opackets=%d\n",
|
1996-02-13 15:55:33 +00:00
|
|
|
ifp->if_ipackets, ifp->if_opackets);
|
1994-11-13 10:12:37 +00:00
|
|
|
printf("\tNOF=%d, NOMB=%d, BPFD=%d, RXOF=%d, RXOL=%d, TXU=%d\n",
|
|
|
|
sc->rx_no_first, sc->rx_no_mbuf, sc->rx_bpf_disc, sc->rx_overrunf,
|
|
|
|
sc->rx_overrunl, sc->tx_underrun);
|
|
|
|
#else
|
1996-01-29 03:16:14 +00:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
1996-02-26 01:05:36 +00:00
|
|
|
printf("ep%d: Status: %x (input buffer overflow)\n", sc->unit, status);
|
1996-01-29 03:16:14 +00:00
|
|
|
#else
|
1996-02-13 15:55:33 +00:00
|
|
|
++ifp->if_ierrors;
|
1996-01-29 03:16:14 +00:00
|
|
|
#endif
|
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
#endif
|
1996-02-26 01:05:36 +00:00
|
|
|
epinit(sc);
|
1995-04-10 21:25:06 +00:00
|
|
|
splx(x);
|
1994-11-13 10:12:37 +00:00
|
|
|
return;
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
if (status & S_TX_COMPLETE) {
|
1997-10-14 06:56:09 +00:00
|
|
|
ifp->if_timer = 0;
|
1994-11-13 10:12:37 +00:00
|
|
|
/* we need ACK. we do it at the end */
|
|
|
|
/*
|
|
|
|
* We need to read TX_STATUS until we get a 0 status in order to
|
|
|
|
* turn off the interrupt flag.
|
|
|
|
*/
|
|
|
|
while ((status = inb(BASE + EP_W1_TX_STATUS)) & TXS_COMPLETE) {
|
|
|
|
if (status & TXS_SUCCES_INTR_REQ);
|
|
|
|
else if (status & (TXS_UNDERRUN | TXS_JABBER | TXS_MAX_COLLISION)) {
|
|
|
|
outw(BASE + EP_COMMAND, TX_RESET);
|
|
|
|
if (status & TXS_UNDERRUN) {
|
|
|
|
#ifdef EP_LOCAL_STATS
|
|
|
|
sc->tx_underrun++;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
if (status & TXS_JABBER);
|
|
|
|
else /* TXS_MAX_COLLISION - we shouldn't get here */
|
1996-02-13 15:55:33 +00:00
|
|
|
++ifp->if_collisions;
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
1996-02-13 15:55:33 +00:00
|
|
|
++ifp->if_oerrors;
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, TX_ENABLE);
|
|
|
|
/*
|
|
|
|
* To have a tx_avail_int but giving the chance to the
|
|
|
|
* Reception
|
|
|
|
*/
|
1996-02-13 15:55:33 +00:00
|
|
|
if (ifp->if_snd.ifq_head) {
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_TX_AVAIL_THRESH | 8);
|
|
|
|
}
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
1994-11-13 10:12:37 +00:00
|
|
|
outb(BASE + EP_W1_TX_STATUS, 0x0); /* pops up the next
|
|
|
|
* status */
|
|
|
|
} /* while */
|
1996-02-13 15:55:33 +00:00
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
1995-04-05 13:12:13 +00:00
|
|
|
GO_WINDOW(1);
|
|
|
|
inw(BASE + EP_W1_FREE_TX);
|
1996-02-13 15:55:33 +00:00
|
|
|
epstart(ifp);
|
1994-11-13 10:12:37 +00:00
|
|
|
} /* end TX_COMPLETE */
|
|
|
|
}
|
1995-03-23 06:53:39 +00:00
|
|
|
|
|
|
|
outw(BASE + EP_COMMAND, C_INTR_LATCH); /* ACK int Latch */
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
if ((status = inw(BASE + EP_STATUS)) & S_5_INTS)
|
1995-03-23 06:53:39 +00:00
|
|
|
goto rescan;
|
1995-04-05 13:12:13 +00:00
|
|
|
|
|
|
|
/* re-enable Ints */
|
|
|
|
outw(BASE + EP_COMMAND, SET_INTR_MASK | S_5_INTS);
|
|
|
|
|
1995-04-10 21:25:06 +00:00
|
|
|
splx(x);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
1994-01-26 09:06:29 +00:00
|
|
|
epread(sc)
|
1994-11-13 10:12:37 +00:00
|
|
|
register struct ep_softc *sc;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1994-11-13 10:12:37 +00:00
|
|
|
struct ether_header *eh;
|
|
|
|
struct mbuf *top, *mcur, *m;
|
1996-02-13 15:55:33 +00:00
|
|
|
struct ifnet *ifp;
|
1994-11-13 10:12:37 +00:00
|
|
|
int lenthisone;
|
|
|
|
|
|
|
|
short rx_fifo2, status;
|
|
|
|
register short rx_fifo;
|
|
|
|
|
1996-02-13 15:55:33 +00:00
|
|
|
ifp = &sc->arpcom.ac_if;
|
1994-11-13 10:12:37 +00:00
|
|
|
status = inw(BASE + EP_W1_RX_STATUS);
|
|
|
|
|
|
|
|
read_again:
|
|
|
|
|
|
|
|
if (status & ERR_RX) {
|
1996-02-13 15:55:33 +00:00
|
|
|
++ifp->if_ierrors;
|
1994-11-13 10:12:37 +00:00
|
|
|
if (status & ERR_RX_OVERRUN) {
|
|
|
|
/*
|
|
|
|
* we can think the rx latency is actually greather than we
|
|
|
|
* expect
|
|
|
|
*/
|
|
|
|
#ifdef EP_LOCAL_STATS
|
|
|
|
if (ep_ftst(F_RX_FIRST))
|
|
|
|
sc->rx_overrunf++;
|
|
|
|
else
|
|
|
|
sc->rx_overrunl++;
|
|
|
|
#endif
|
1994-01-26 09:06:29 +00:00
|
|
|
}
|
1994-11-13 10:12:37 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
rx_fifo = rx_fifo2 = status & RX_BYTES_MASK;
|
|
|
|
|
|
|
|
if (ep_ftst(F_RX_FIRST)) {
|
1997-10-14 06:56:09 +00:00
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (!m)
|
|
|
|
goto out;
|
|
|
|
if (rx_fifo >= MINCLSIZE)
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
1994-11-13 10:12:37 +00:00
|
|
|
sc->top = sc->mcur = top = m;
|
1994-01-26 09:06:29 +00:00
|
|
|
#define EROUND ((sizeof(struct ether_header) + 3) & ~3)
|
|
|
|
#define EOFF (EROUND - sizeof(struct ether_header))
|
1994-11-13 10:12:37 +00:00
|
|
|
top->m_data += EOFF;
|
|
|
|
|
1994-01-10 18:56:26 +00:00
|
|
|
/* Read what should be the header. */
|
1994-01-26 09:06:29 +00:00
|
|
|
insw(BASE + EP_W1_RX_PIO_RD_1,
|
1994-11-13 10:12:37 +00:00
|
|
|
mtod(top, caddr_t), sizeof(struct ether_header) / 2);
|
|
|
|
top->m_len = sizeof(struct ether_header);
|
|
|
|
rx_fifo -= sizeof(struct ether_header);
|
|
|
|
sc->cur_len = rx_fifo2;
|
|
|
|
} else {
|
|
|
|
/* come here if we didn't have a complete packet last time */
|
|
|
|
top = sc->top;
|
|
|
|
m = sc->mcur;
|
|
|
|
sc->cur_len += rx_fifo2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reads what is left in the RX FIFO */
|
|
|
|
while (rx_fifo > 0) {
|
|
|
|
lenthisone = min(rx_fifo, M_TRAILINGSPACE(m));
|
|
|
|
if (lenthisone == 0) { /* no room in this one */
|
|
|
|
mcur = m;
|
1997-10-14 06:56:09 +00:00
|
|
|
MGET(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (!m)
|
|
|
|
goto out;
|
1994-11-13 10:12:37 +00:00
|
|
|
if (rx_fifo >= MINCLSIZE)
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
m->m_len = 0;
|
|
|
|
mcur->m_next = m;
|
|
|
|
lenthisone = min(rx_fifo, M_TRAILINGSPACE(m));
|
|
|
|
}
|
|
|
|
if (ep_ftst(F_ACCESS_32_BITS)) { /* default for EISA configured cards*/
|
|
|
|
insl(BASE + EP_W1_RX_PIO_RD_1, mtod(m, caddr_t) + m->m_len,
|
|
|
|
lenthisone / 4);
|
|
|
|
m->m_len += (lenthisone & ~3);
|
|
|
|
if (lenthisone & 3)
|
|
|
|
insb(BASE + EP_W1_RX_PIO_RD_1,
|
|
|
|
mtod(m, caddr_t) + m->m_len,
|
|
|
|
lenthisone & 3);
|
|
|
|
m->m_len += (lenthisone & 3);
|
|
|
|
} else {
|
|
|
|
insw(BASE + EP_W1_RX_PIO_RD_1, mtod(m, caddr_t) + m->m_len,
|
|
|
|
lenthisone / 2);
|
|
|
|
m->m_len += lenthisone;
|
|
|
|
if (lenthisone & 1)
|
|
|
|
*(mtod(m, caddr_t) + m->m_len - 1) = inb(BASE + EP_W1_RX_PIO_RD_1);
|
|
|
|
}
|
|
|
|
rx_fifo -= lenthisone;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & ERR_RX_INCOMPLETE) { /* we haven't received the complete
|
|
|
|
* packet */
|
|
|
|
sc->mcur = m;
|
|
|
|
#ifdef EP_LOCAL_STATS
|
|
|
|
sc->rx_no_first++; /* to know how often we come here */
|
|
|
|
#endif
|
|
|
|
ep_frst(F_RX_FIRST);
|
|
|
|
if (!((status = inw(BASE + EP_W1_RX_STATUS)) & ERR_RX_INCOMPLETE)) {
|
|
|
|
/* we see if by now, the packet has completly arrived */
|
|
|
|
goto read_again;
|
|
|
|
}
|
1997-10-14 06:56:09 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_RX_EARLY_THRESH | RX_NEXT_EARLY_THRESH);
|
1994-11-13 10:12:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
outw(BASE + EP_COMMAND, RX_DISCARD_TOP_PACK);
|
1996-02-13 15:55:33 +00:00
|
|
|
++ifp->if_ipackets;
|
1994-11-13 10:12:37 +00:00
|
|
|
ep_fset(F_RX_FIRST);
|
|
|
|
top->m_pkthdr.rcvif = &sc->arpcom.ac_if;
|
|
|
|
top->m_pkthdr.len = sc->cur_len;
|
1994-01-26 09:06:29 +00:00
|
|
|
|
1999-07-06 19:23:32 +00:00
|
|
|
#if NBPF > 0
|
1996-02-13 15:55:33 +00:00
|
|
|
if (ifp->if_bpf) {
|
|
|
|
bpf_mtap(ifp, top);
|
1994-01-26 09:06:29 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/*
|
|
|
|
* Note that the interface cannot be in promiscuous mode if there are
|
|
|
|
* no BPF listeners. And if we are in promiscuous mode, we have to
|
|
|
|
* check if this packet is really ours.
|
|
|
|
*/
|
|
|
|
eh = mtod(top, struct ether_header *);
|
1996-02-13 15:55:33 +00:00
|
|
|
if ((ifp->if_flags & IFF_PROMISC) &&
|
1994-11-13 10:12:37 +00:00
|
|
|
(eh->ether_dhost[0] & 1) == 0 &&
|
|
|
|
bcmp(eh->ether_dhost, sc->arpcom.ac_enaddr,
|
|
|
|
sizeof(eh->ether_dhost)) != 0 &&
|
|
|
|
bcmp(eh->ether_dhost, etherbroadcastaddr,
|
|
|
|
sizeof(eh->ether_dhost)) != 0) {
|
|
|
|
if (sc->top) {
|
|
|
|
m_freem(sc->top);
|
|
|
|
sc->top = 0;
|
|
|
|
}
|
|
|
|
ep_fset(F_RX_FIRST);
|
|
|
|
#ifdef EP_LOCAL_STATS
|
|
|
|
sc->rx_bpf_disc++;
|
|
|
|
#endif
|
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1997-10-14 06:56:09 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
|
1994-11-13 10:12:37 +00:00
|
|
|
return;
|
1994-01-26 09:06:29 +00:00
|
|
|
}
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
1994-01-26 09:06:29 +00:00
|
|
|
#endif
|
1994-01-26 09:13:56 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
eh = mtod(top, struct ether_header *);
|
|
|
|
m_adj(top, sizeof(struct ether_header));
|
1996-02-13 15:55:33 +00:00
|
|
|
ether_input(ifp, eh, top);
|
1994-11-13 10:12:37 +00:00
|
|
|
sc->top = 0;
|
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1997-10-14 06:56:09 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
|
1994-11-13 10:12:37 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
out:
|
|
|
|
outw(BASE + EP_COMMAND, RX_DISCARD_TOP_PACK);
|
|
|
|
if (sc->top) {
|
|
|
|
m_freem(sc->top);
|
|
|
|
sc->top = 0;
|
|
|
|
#ifdef EP_LOCAL_STATS
|
|
|
|
sc->rx_no_mbuf++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
ep_fset(F_RX_FIRST);
|
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1997-10-14 06:56:09 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look familiar?
|
|
|
|
*/
|
1994-01-26 09:06:29 +00:00
|
|
|
static int
|
|
|
|
epioctl(ifp, cmd, data)
|
1994-11-13 10:12:37 +00:00
|
|
|
register struct ifnet *ifp;
|
1998-06-07 17:13:14 +00:00
|
|
|
u_long cmd;
|
1994-11-13 10:12:37 +00:00
|
|
|
caddr_t data;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1996-02-06 18:51:28 +00:00
|
|
|
struct ep_softc *sc = ifp->if_softc;
|
1994-11-13 10:12:37 +00:00
|
|
|
int s, error = 0;
|
|
|
|
|
1995-07-05 07:21:34 +00:00
|
|
|
s = splimp();
|
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case SIOCSIFADDR:
|
1995-08-28 12:01:17 +00:00
|
|
|
case SIOCGIFADDR:
|
1999-08-18 06:12:00 +00:00
|
|
|
case SIOCSIFMTU:
|
1999-08-18 22:14:24 +00:00
|
|
|
error = ether_ioctl(ifp, cmd, data);
|
1999-08-18 06:12:00 +00:00
|
|
|
break;
|
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
case SIOCSIFFLAGS:
|
1996-01-29 03:16:14 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
if ((ifp->if_flags & IFF_UP) == 0 && ifp->if_flags & IFF_RUNNING) {
|
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
1996-02-26 01:05:36 +00:00
|
|
|
epstop(sc);
|
1994-11-13 10:12:37 +00:00
|
|
|
break;
|
1995-03-31 06:41:38 +00:00
|
|
|
} else {
|
|
|
|
/* reinitialize card on any parameter change */
|
1996-02-26 01:05:36 +00:00
|
|
|
epinit(sc);
|
1995-03-31 06:41:38 +00:00
|
|
|
break;
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
1995-03-31 06:41:38 +00:00
|
|
|
|
|
|
|
/* NOTREACHED */
|
1994-11-13 10:12:37 +00:00
|
|
|
break;
|
1994-01-10 18:56:26 +00:00
|
|
|
#ifdef notdef
|
1994-11-13 10:12:37 +00:00
|
|
|
case SIOCGHWADDR:
|
|
|
|
bcopy((caddr_t) sc->sc_addr, (caddr_t) & ifr->ifr_data,
|
|
|
|
sizeof(sc->sc_addr));
|
|
|
|
break;
|
1994-01-10 18:56:26 +00:00
|
|
|
#endif
|
1996-01-29 03:16:14 +00:00
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
1997-10-27 00:02:33 +00:00
|
|
|
/*
|
|
|
|
* The Etherlink III has no programmable multicast
|
|
|
|
* filter. We always initialize the card to be
|
|
|
|
* promiscuous to multicast, since we're always a
|
|
|
|
* member of the ALL-SYSTEMS group, so there's no
|
|
|
|
* need to process SIOC*MULTI requests.
|
1996-01-29 03:16:14 +00:00
|
|
|
*/
|
1997-10-14 06:56:09 +00:00
|
|
|
error = 0;
|
1996-01-29 03:16:14 +00:00
|
|
|
break;
|
1994-11-13 10:12:37 +00:00
|
|
|
default:
|
1994-01-10 18:56:26 +00:00
|
|
|
error = EINVAL;
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
1995-07-05 07:21:34 +00:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
return (error);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
1995-12-05 02:01:59 +00:00
|
|
|
epwatchdog(ifp)
|
|
|
|
struct ifnet *ifp;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1996-06-14 22:11:38 +00:00
|
|
|
struct ep_softc *sc = ifp->if_softc;
|
|
|
|
|
1995-04-05 13:12:13 +00:00
|
|
|
/*
|
|
|
|
printf("ep: watchdog\n");
|
1994-01-26 09:13:56 +00:00
|
|
|
|
1995-12-05 02:01:59 +00:00
|
|
|
log(LOG_ERR, "ep%d: watchdog\n", ifp->if_unit);
|
|
|
|
ifp->if_oerrors++;
|
1995-04-05 13:12:13 +00:00
|
|
|
*/
|
|
|
|
|
1996-06-14 22:11:38 +00:00
|
|
|
if (sc->gone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1995-04-05 13:12:13 +00:00
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
epstart(ifp);
|
1996-02-26 01:05:36 +00:00
|
|
|
ep_intr(ifp->if_softc);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
1996-02-26 01:05:36 +00:00
|
|
|
epstop(sc)
|
|
|
|
struct ep_softc *sc;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1996-06-14 22:11:38 +00:00
|
|
|
if (sc->gone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, RX_DISABLE);
|
|
|
|
outw(BASE + EP_COMMAND, RX_DISCARD_TOP_PACK);
|
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
|
|
|
outw(BASE + EP_COMMAND, TX_DISABLE);
|
|
|
|
outw(BASE + EP_COMMAND, STOP_TRANSCEIVER);
|
|
|
|
outw(BASE + EP_COMMAND, RX_RESET);
|
|
|
|
outw(BASE + EP_COMMAND, TX_RESET);
|
1997-10-14 06:56:09 +00:00
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, C_INTR_LATCH);
|
|
|
|
outw(BASE + EP_COMMAND, SET_RD_0_MASK);
|
|
|
|
outw(BASE + EP_COMMAND, SET_INTR_MASK);
|
|
|
|
outw(BASE + EP_COMMAND, SET_RX_FILTER);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1994-01-26 09:06:29 +00:00
|
|
|
|
1996-06-14 22:11:38 +00:00
|
|
|
#if 0
|
1994-01-26 09:06:29 +00:00
|
|
|
static int
|
|
|
|
send_ID_sequence(port)
|
1994-11-13 10:12:37 +00:00
|
|
|
int port;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1994-11-13 10:12:37 +00:00
|
|
|
int cx, al;
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
for (al = 0xff, cx = 0; cx < 255; cx++) {
|
1994-01-10 18:56:26 +00:00
|
|
|
outb(port, al);
|
1994-11-13 10:12:37 +00:00
|
|
|
al <<= 1;
|
|
|
|
if (al & 0x100)
|
|
|
|
al ^= 0xcf;
|
|
|
|
}
|
|
|
|
return (1);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
1996-06-14 22:11:38 +00:00
|
|
|
#endif
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-01-26 09:06:29 +00:00
|
|
|
|
1994-01-10 18:56:26 +00:00
|
|
|
/*
|
1994-11-13 10:12:37 +00:00
|
|
|
* We get eeprom data from the id_port given an offset into the eeprom.
|
|
|
|
* Basically; after the ID_sequence is sent to all of the cards; they enter
|
|
|
|
* the ID_CMD state where they will accept command requests. 0x80-0xbf loads
|
|
|
|
* the eeprom data. We then read the port 16 times and with every read; the
|
|
|
|
* cards check for contention (ie: if one card writes a 0 bit and another
|
|
|
|
* writes a 1 bit then the host sees a 0. At the end of the cycle; each card
|
|
|
|
* compares the data on the bus; if there is a difference then that card goes
|
|
|
|
* into ID_WAIT state again). In the meantime; one bit of data is returned in
|
|
|
|
* the AX register which is conveniently returned to us by inb(). Hence; we
|
|
|
|
* read 16 times getting one bit of data with each read.
|
1994-01-10 18:56:26 +00:00
|
|
|
*/
|
1999-01-31 22:41:51 +00:00
|
|
|
|
1994-01-26 09:06:29 +00:00
|
|
|
static int
|
1994-11-13 10:12:37 +00:00
|
|
|
get_eeprom_data(id_port, offset)
|
|
|
|
int id_port;
|
|
|
|
int offset;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1994-11-13 10:12:37 +00:00
|
|
|
int i, data = 0;
|
|
|
|
outb(id_port, 0x80 + offset);
|
1999-01-31 22:41:51 +00:00
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
DELAY(BIT_DELAY_MULTIPLE * 1000);
|
1994-11-13 10:12:37 +00:00
|
|
|
data = (data << 1) | (inw(id_port) & 1);
|
1999-01-31 22:41:51 +00:00
|
|
|
}
|
1994-11-13 10:12:37 +00:00
|
|
|
return (data);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
#endif /* NEP > 0 */
|