1996-02-26 01:01:41 +00:00
|
|
|
/*
|
|
|
|
* Product specific probe and attach routines for:
|
|
|
|
* 3COM 3C579 and 3C509(in eisa config mode) ethernet controllers
|
|
|
|
*
|
|
|
|
* Copyright (c) 1996 Justin T. Gibbs
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice immediately at the beginning of the file, without modification,
|
|
|
|
* 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. Absolutely no warranty of function or purpose is made by the author
|
|
|
|
* Justin T. Gibbs.
|
|
|
|
* 4. Modifications may be freely made to this file if the above conditions
|
|
|
|
* are met.
|
|
|
|
*/
|
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1996-02-26 01:01:41 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
1996-10-12 19:49:43 +00:00
|
|
|
#include <sys/socket.h>
|
1999-04-18 15:50:35 +00:00
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
1996-02-26 01:01:41 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
2003-07-17 19:37:56 +00:00
|
|
|
#include <sys/rman.h>
|
1996-02-26 01:01:41 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
1999-10-27 06:25:16 +00:00
|
|
|
#include <net/if_arp.h>
|
2003-07-17 19:37:56 +00:00
|
|
|
#include <net/if_media.h>
|
2003-03-30 08:13:47 +00:00
|
|
|
|
|
|
|
#include <dev/eisa/eisaconf.h>
|
1996-02-26 01:01:41 +00:00
|
|
|
|
1999-10-02 20:22:26 +00:00
|
|
|
#include <dev/ep/if_epreg.h>
|
|
|
|
#include <dev/ep/if_epvar.h>
|
|
|
|
|
1996-02-26 01:01:41 +00:00
|
|
|
#define EISA_DEVICE_ID_3COM_3C509_TP 0x506d5090
|
|
|
|
#define EISA_DEVICE_ID_3COM_3C509_BNC 0x506d5091
|
|
|
|
#define EISA_DEVICE_ID_3COM_3C579_TP 0x506d5092
|
|
|
|
#define EISA_DEVICE_ID_3COM_3C579_BNC 0x506d5093
|
|
|
|
#define EISA_DEVICE_ID_3COM_3C509_COMBO 0x506d5094
|
|
|
|
#define EISA_DEVICE_ID_3COM_3C509_TPO 0x506d5095
|
|
|
|
|
|
|
|
#define EP_EISA_SLOT_OFFSET 0x0c80
|
|
|
|
#define EP_EISA_IOSIZE 0x000a
|
|
|
|
|
|
|
|
#define EISA_IOCONF 0x0008
|
|
|
|
#define IRQ_CHANNEL 0xf000
|
|
|
|
#define INT_3 0x3000
|
|
|
|
#define INT_5 0x5000
|
|
|
|
#define INT_7 0x7000
|
|
|
|
#define INT_9 0x9000
|
|
|
|
#define INT_10 0xa000
|
|
|
|
#define INT_11 0xb000
|
|
|
|
#define INT_12 0xc000
|
|
|
|
#define INT_15 0xf000
|
|
|
|
#define EISA_BPROM_MEDIA_CONF 0x0006
|
|
|
|
#define TRANS_TYPE 0xc000
|
|
|
|
#define TRANS_TP 0x0000
|
|
|
|
#define TRANS_AUI 0x4000
|
|
|
|
#define TRANS_BNC 0xc000
|
|
|
|
|
2002-03-20 02:08:01 +00:00
|
|
|
static const char *ep_match(eisa_id_t type);
|
1996-02-26 01:01:41 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
static const char *
|
1999-04-18 15:50:35 +00:00
|
|
|
ep_match(eisa_id_t type)
|
1996-02-26 01:01:41 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
switch (type) {
|
|
|
|
case EISA_DEVICE_ID_3COM_3C509_TP:
|
|
|
|
return ("3Com 3C509-TP Network Adapter");
|
|
|
|
case EISA_DEVICE_ID_3COM_3C509_BNC:
|
|
|
|
return ("3Com 3C509-BNC Network Adapter");
|
|
|
|
case EISA_DEVICE_ID_3COM_3C579_TP:
|
|
|
|
return ("3Com 3C579-TP EISA Network Adapter");
|
|
|
|
case EISA_DEVICE_ID_3COM_3C579_BNC:
|
|
|
|
return ("3Com 3C579-BNC EISA Network Adapter");
|
|
|
|
case EISA_DEVICE_ID_3COM_3C509_COMBO:
|
|
|
|
return ("3Com 3C509-Combo Network Adapter");
|
|
|
|
case EISA_DEVICE_ID_3COM_3C509_TPO:
|
|
|
|
return ("3Com 3C509-TPO Network Adapter");
|
|
|
|
default:
|
|
|
|
return (NULL);
|
1996-02-26 01:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1999-04-18 15:50:35 +00:00
|
|
|
ep_eisa_probe(device_t dev)
|
1996-02-26 01:01:41 +00:00
|
|
|
{
|
1999-04-18 15:50:35 +00:00
|
|
|
const char *desc;
|
1996-02-26 01:01:41 +00:00
|
|
|
u_long iobase;
|
1999-04-18 15:50:35 +00:00
|
|
|
u_short conf;
|
|
|
|
u_long port;
|
|
|
|
int irq;
|
1999-10-27 06:25:16 +00:00
|
|
|
int int_trig;
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
desc = ep_match(eisa_get_id(dev));
|
|
|
|
if (!desc)
|
|
|
|
return (ENXIO);
|
|
|
|
device_set_desc(dev, desc);
|
|
|
|
|
|
|
|
port = (eisa_get_slot(dev) * EISA_SLOT_SIZE);
|
|
|
|
iobase = port + EP_EISA_SLOT_OFFSET;
|
|
|
|
|
|
|
|
/* We must be in EISA configuration mode */
|
|
|
|
if ((inw(iobase + EP_W0_ADDRESS_CFG) & 0x1f) != 0x1f)
|
2003-07-17 19:37:56 +00:00
|
|
|
return ENXIO;
|
1999-04-18 15:50:35 +00:00
|
|
|
|
2003-03-30 08:13:47 +00:00
|
|
|
eisa_add_iospace(dev, iobase, EP_EISA_IOSIZE, RESVADDR_NONE);
|
|
|
|
eisa_add_iospace(dev, port, EP_IOSIZE, RESVADDR_NONE);
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
conf = inw(iobase + EISA_IOCONF);
|
|
|
|
/* Determine our IRQ */
|
|
|
|
switch (conf & IRQ_CHANNEL) {
|
|
|
|
case INT_3:
|
2003-07-17 19:37:56 +00:00
|
|
|
irq = 3;
|
|
|
|
break;
|
1999-04-18 15:50:35 +00:00
|
|
|
case INT_5:
|
2003-07-17 19:37:56 +00:00
|
|
|
irq = 5;
|
|
|
|
break;
|
1999-04-18 15:50:35 +00:00
|
|
|
case INT_7:
|
2003-07-17 19:37:56 +00:00
|
|
|
irq = 7;
|
|
|
|
break;
|
1999-04-18 15:50:35 +00:00
|
|
|
case INT_9:
|
2003-07-17 19:37:56 +00:00
|
|
|
irq = 9;
|
|
|
|
break;
|
1999-04-18 15:50:35 +00:00
|
|
|
case INT_10:
|
2003-07-17 19:37:56 +00:00
|
|
|
irq = 10;
|
|
|
|
break;
|
1999-04-18 15:50:35 +00:00
|
|
|
case INT_11:
|
2003-07-17 19:37:56 +00:00
|
|
|
irq = 11;
|
|
|
|
break;
|
1999-04-18 15:50:35 +00:00
|
|
|
case INT_12:
|
2003-07-17 19:37:56 +00:00
|
|
|
irq = 12;
|
|
|
|
break;
|
1999-04-18 15:50:35 +00:00
|
|
|
case INT_15:
|
2003-07-17 19:37:56 +00:00
|
|
|
irq = 15;
|
|
|
|
break;
|
1999-04-18 15:50:35 +00:00
|
|
|
default:
|
2003-07-17 19:37:56 +00:00
|
|
|
/* Disabled */
|
|
|
|
printf("ep: 3COM Network Adapter at "
|
|
|
|
"slot %d has its IRQ disabled. "
|
|
|
|
"Probe failed.\n",
|
|
|
|
eisa_get_slot(dev));
|
|
|
|
return (ENXIO);
|
1996-02-26 01:01:41 +00:00
|
|
|
}
|
1999-10-27 06:25:16 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
switch (eisa_get_id(dev)) {
|
|
|
|
case EISA_DEVICE_ID_3COM_3C579_BNC:
|
|
|
|
case EISA_DEVICE_ID_3COM_3C579_TP:
|
|
|
|
int_trig = EISA_TRIGGER_LEVEL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
int_trig = EISA_TRIGGER_EDGE;
|
|
|
|
break;
|
1999-10-27 06:25:16 +00:00
|
|
|
}
|
2003-07-17 19:37:56 +00:00
|
|
|
|
2003-03-30 08:13:47 +00:00
|
|
|
eisa_add_intr(dev, irq, int_trig);
|
1999-04-18 15:50:35 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
return (0);
|
1996-02-26 01:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1999-04-18 15:50:35 +00:00
|
|
|
ep_eisa_attach(device_t dev)
|
1996-02-26 01:01:41 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
struct ep_softc *sc = device_get_softc(dev);
|
|
|
|
struct resource *eisa_io = NULL;
|
|
|
|
u_int32_t eisa_iobase;
|
|
|
|
int irq;
|
|
|
|
int error = 0;
|
|
|
|
int rid;
|
1996-02-26 01:01:41 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
rid = 1;
|
|
|
|
eisa_io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
|
2003-07-17 19:37:56 +00:00
|
|
|
0, ~0, 1, RF_ACTIVE);
|
1999-04-18 15:50:35 +00:00
|
|
|
if (!eisa_io) {
|
|
|
|
device_printf(dev, "No I/O space?!\n");
|
1999-10-27 06:25:16 +00:00
|
|
|
error = ENXIO;
|
1999-04-18 15:50:35 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
1999-10-27 06:25:16 +00:00
|
|
|
eisa_iobase = rman_get_start(eisa_io);
|
1996-02-26 01:01:41 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
/* Reset and Enable the card */
|
|
|
|
outb(eisa_iobase + EP_W0_CONFIG_CTRL, W0_P4_CMD_RESET_ADAPTER);
|
2003-07-17 19:37:56 +00:00
|
|
|
DELAY(1000); /* we must wait at least 1 ms */
|
1999-10-27 06:25:16 +00:00
|
|
|
outb(eisa_iobase + EP_W0_CONFIG_CTRL, W0_P4_CMD_ENABLE_ADAPTER);
|
|
|
|
/* Now the registers are availible through the lower ioport */
|
1996-02-26 01:01:41 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
if ((error = ep_alloc(dev))) {
|
|
|
|
device_printf(dev, "ep_alloc() failed! (%d)\n", error);
|
1999-04-18 15:50:35 +00:00
|
|
|
goto bad;
|
1999-10-27 06:25:16 +00:00
|
|
|
}
|
2003-07-17 19:37:56 +00:00
|
|
|
switch (eisa_get_id(dev)) {
|
|
|
|
case EISA_DEVICE_ID_3COM_3C579_BNC:
|
|
|
|
case EISA_DEVICE_ID_3COM_3C579_TP:
|
|
|
|
sc->stat = F_ACCESS_32_BITS;
|
|
|
|
break;
|
1996-02-26 01:01:41 +00:00
|
|
|
}
|
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
ep_get_media(sc);
|
1996-02-26 01:01:41 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
irq = rman_get_start(sc->irq);
|
|
|
|
if (irq == 9)
|
|
|
|
irq = 2;
|
1996-02-26 01:01:41 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
GO_WINDOW(0);
|
1999-10-27 06:25:16 +00:00
|
|
|
SET_IRQ(BASE, irq);
|
1996-02-26 01:01:41 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
if ((error = ep_attach(sc))) {
|
|
|
|
device_printf(dev, "ep_attach() failed! (%d)\n", error);
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, ep_intr,
|
2003-07-17 19:37:56 +00:00
|
|
|
sc, &sc->ep_intrhand))) {
|
1999-10-27 06:25:16 +00:00
|
|
|
device_printf(dev, "bus_setup_intr() failed! (%d)\n", error);
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
return (0);
|
1999-04-18 15:50:35 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
bad:
|
1999-04-18 15:50:35 +00:00
|
|
|
if (eisa_io)
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, 0, eisa_io);
|
1999-10-27 06:25:16 +00:00
|
|
|
|
|
|
|
ep_free(dev);
|
|
|
|
return (error);
|
1996-02-26 01:01:41 +00:00
|
|
|
}
|
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
static device_method_t ep_eisa_methods[] = {
|
|
|
|
/* Device interface */
|
2003-07-17 19:37:56 +00:00
|
|
|
DEVMETHOD(device_probe, ep_eisa_probe),
|
|
|
|
DEVMETHOD(device_attach, ep_eisa_attach),
|
|
|
|
DEVMETHOD(device_detach, ep_detach),
|
1999-04-18 15:50:35 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
{0, 0}
|
1999-04-18 15:50:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t ep_eisa_driver = {
|
|
|
|
"ep",
|
|
|
|
ep_eisa_methods,
|
1999-10-27 06:25:16 +00:00
|
|
|
sizeof(struct ep_softc),
|
1999-04-18 15:50:35 +00:00
|
|
|
};
|
|
|
|
|
1999-10-25 02:52:16 +00:00
|
|
|
extern devclass_t ep_devclass;
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
DRIVER_MODULE(ep, eisa, ep_eisa_driver, ep_devclass, 0, 0);
|