2002-02-27 17:35:48 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Paul Kranenburg.
|
|
|
|
*
|
|
|
|
* 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, 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``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 FOUNDATION OR CONTRIBUTORS
|
|
|
|
* 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.
|
|
|
|
*
|
2004-08-12 20:37:02 +00:00
|
|
|
* from: NetBSD: if_hme_sbus.c,v 1.19 2004/03/17 17:04:58 pk Exp
|
2002-02-27 17:35:48 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2002-02-27 17:35:48 +00:00
|
|
|
/*
|
|
|
|
* SBus front-end device driver for the HME ethernet device.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-06-03 06:10:02 +00:00
|
|
|
#include <sys/module.h>
|
2002-02-27 17:35:48 +00:00
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
- Introduce an ofw_bus kobj-interface for retrieving the OFW node and a
subset ("compatible", "device_type", "model" and "name") of the standard
properties in drivers for devices on Open Firmware supported busses. The
standard properties "reg", "interrupts" und "address" are not covered by
this interface because they are only of interest in the respective bridge
code. There's a remaining standard property "status" which is unclear how
to support properly but which also isn't used in FreeBSD at present.
This ofw_bus kobj-interface allows to replace the various (ebus_get_node(),
ofw_pci_get_node(), etc.) and partially inconsistent (central_get_type()
vs. sbus_get_device_type(), etc.) existing IVAR ones with a common one.
This in turn allows to simplify and remove code-duplication in drivers for
devices that can hang off of more than one OFW supported bus.
- Convert the sparc64 Central, EBus, FHC, PCI and SBus bus drivers and the
drivers for their children to use the ofw_bus kobj-interface. The IVAR-
interfaces of the Central, EBus and FHC are entirely replaced by this. The
PCI bus driver used its own kobj-interface and now also uses the ofw_bus
one. The IVARs special to the SBus, e.g. for retrieving the burst size,
remain.
Beware: this causes an ABI-breakage for modules of drivers which used the
IVAR-interfaces, i.e. esp(4), hme(4), isp(4) and uart(4), which need to be
recompiled.
The style-inconsistencies introduced in some of the bus drivers will be
fixed by tmm@ in a generic clean-up of the respective drivers later (he
requested to add the changes in the "new" style).
- Convert the powerpc MacIO bus driver and the drivers for its children to
use the ofw_bus kobj-interface. This invloves removing the IVARs related
to the "reg" property which were unused and a leftover from the NetBSD
origini of the code. There's no ABI-breakage caused by this because none
of these driver are currently built as modules.
There are other powerpc bus drivers which can be converted to the ofw_bus
kobj-interface, e.g. the PCI bus driver, which should be done together
with converting powerpc to use the OFW PCI code from sparc64.
- Make the SBus and FHC front-end of zs(4) and the sparc64 eeprom(4) take
advantage of the ofw_bus kobj-interface and simplify them a bit.
Reviewed by: grehan, tmm
Approved by: re (scottl)
Discussed with: tmm
Tested with: Sun AX1105, AXe, Ultra 2, Ultra 60; PPC cross-build on i386
2004-08-12 17:41:33 +00:00
|
|
|
#include <dev/ofw/ofw_bus.h>
|
|
|
|
|
2002-02-27 17:35:48 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/ofw_machdep.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
2003-08-23 05:51:03 +00:00
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/miivar.h>
|
2002-02-27 17:35:48 +00:00
|
|
|
|
|
|
|
#include <sparc64/sbus/sbusvar.h>
|
|
|
|
|
2003-08-23 05:51:03 +00:00
|
|
|
#include <dev/hme/if_hmereg.h>
|
|
|
|
#include <dev/hme/if_hmevar.h>
|
2002-02-27 17:35:48 +00:00
|
|
|
|
|
|
|
#include "miibus_if.h"
|
|
|
|
|
|
|
|
struct hme_sbus_softc {
|
|
|
|
struct hme_softc hsc_hme; /* HME device */
|
|
|
|
struct resource *hsc_seb_res;
|
|
|
|
struct resource *hsc_etx_res;
|
|
|
|
struct resource *hsc_erx_res;
|
|
|
|
struct resource *hsc_mac_res;
|
|
|
|
struct resource *hsc_mif_res;
|
|
|
|
struct resource *hsc_ires;
|
|
|
|
void *hsc_ih;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int hme_sbus_probe(device_t);
|
|
|
|
static int hme_sbus_attach(device_t);
|
2003-01-09 00:45:10 +00:00
|
|
|
static int hme_sbus_detach(device_t);
|
|
|
|
static int hme_sbus_suspend(device_t);
|
|
|
|
static int hme_sbus_resume(device_t);
|
2002-02-27 17:35:48 +00:00
|
|
|
|
|
|
|
static device_method_t hme_sbus_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, hme_sbus_probe),
|
|
|
|
DEVMETHOD(device_attach, hme_sbus_attach),
|
2003-01-09 00:45:10 +00:00
|
|
|
DEVMETHOD(device_detach, hme_sbus_detach),
|
|
|
|
DEVMETHOD(device_suspend, hme_sbus_suspend),
|
|
|
|
DEVMETHOD(device_resume, hme_sbus_resume),
|
|
|
|
/* Can just use the suspend method here. */
|
|
|
|
DEVMETHOD(device_shutdown, hme_sbus_suspend),
|
2002-02-27 17:35:48 +00:00
|
|
|
|
|
|
|
/* bus interface */
|
|
|
|
DEVMETHOD(bus_print_child, bus_generic_print_child),
|
|
|
|
DEVMETHOD(bus_driver_added, bus_generic_driver_added),
|
|
|
|
|
|
|
|
/* MII interface */
|
|
|
|
DEVMETHOD(miibus_readreg, hme_mii_readreg),
|
|
|
|
DEVMETHOD(miibus_writereg, hme_mii_writereg),
|
|
|
|
DEVMETHOD(miibus_statchg, hme_mii_statchg),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t hme_sbus_driver = {
|
|
|
|
"hme",
|
|
|
|
hme_sbus_methods,
|
|
|
|
sizeof(struct hme_sbus_softc)
|
|
|
|
};
|
|
|
|
|
2003-04-15 06:37:30 +00:00
|
|
|
DRIVER_MODULE(hme, sbus, hme_sbus_driver, hme_devclass, 0, 0);
|
2008-04-26 14:17:21 +00:00
|
|
|
MODULE_DEPEND(hme, sbus, 1, 1, 1);
|
2003-04-15 06:37:30 +00:00
|
|
|
MODULE_DEPEND(hme, ether, 1, 1, 1);
|
2002-02-27 17:35:48 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
hme_sbus_probe(device_t dev)
|
|
|
|
{
|
- Introduce an ofw_bus kobj-interface for retrieving the OFW node and a
subset ("compatible", "device_type", "model" and "name") of the standard
properties in drivers for devices on Open Firmware supported busses. The
standard properties "reg", "interrupts" und "address" are not covered by
this interface because they are only of interest in the respective bridge
code. There's a remaining standard property "status" which is unclear how
to support properly but which also isn't used in FreeBSD at present.
This ofw_bus kobj-interface allows to replace the various (ebus_get_node(),
ofw_pci_get_node(), etc.) and partially inconsistent (central_get_type()
vs. sbus_get_device_type(), etc.) existing IVAR ones with a common one.
This in turn allows to simplify and remove code-duplication in drivers for
devices that can hang off of more than one OFW supported bus.
- Convert the sparc64 Central, EBus, FHC, PCI and SBus bus drivers and the
drivers for their children to use the ofw_bus kobj-interface. The IVAR-
interfaces of the Central, EBus and FHC are entirely replaced by this. The
PCI bus driver used its own kobj-interface and now also uses the ofw_bus
one. The IVARs special to the SBus, e.g. for retrieving the burst size,
remain.
Beware: this causes an ABI-breakage for modules of drivers which used the
IVAR-interfaces, i.e. esp(4), hme(4), isp(4) and uart(4), which need to be
recompiled.
The style-inconsistencies introduced in some of the bus drivers will be
fixed by tmm@ in a generic clean-up of the respective drivers later (he
requested to add the changes in the "new" style).
- Convert the powerpc MacIO bus driver and the drivers for its children to
use the ofw_bus kobj-interface. This invloves removing the IVARs related
to the "reg" property which were unused and a leftover from the NetBSD
origini of the code. There's no ABI-breakage caused by this because none
of these driver are currently built as modules.
There are other powerpc bus drivers which can be converted to the ofw_bus
kobj-interface, e.g. the PCI bus driver, which should be done together
with converting powerpc to use the OFW PCI code from sparc64.
- Make the SBus and FHC front-end of zs(4) and the sparc64 eeprom(4) take
advantage of the ofw_bus kobj-interface and simplify them a bit.
Reviewed by: grehan, tmm
Approved by: re (scottl)
Discussed with: tmm
Tested with: Sun AX1105, AXe, Ultra 2, Ultra 60; PPC cross-build on i386
2004-08-12 17:41:33 +00:00
|
|
|
const char *name;
|
2002-02-27 17:35:48 +00:00
|
|
|
|
- Introduce an ofw_bus kobj-interface for retrieving the OFW node and a
subset ("compatible", "device_type", "model" and "name") of the standard
properties in drivers for devices on Open Firmware supported busses. The
standard properties "reg", "interrupts" und "address" are not covered by
this interface because they are only of interest in the respective bridge
code. There's a remaining standard property "status" which is unclear how
to support properly but which also isn't used in FreeBSD at present.
This ofw_bus kobj-interface allows to replace the various (ebus_get_node(),
ofw_pci_get_node(), etc.) and partially inconsistent (central_get_type()
vs. sbus_get_device_type(), etc.) existing IVAR ones with a common one.
This in turn allows to simplify and remove code-duplication in drivers for
devices that can hang off of more than one OFW supported bus.
- Convert the sparc64 Central, EBus, FHC, PCI and SBus bus drivers and the
drivers for their children to use the ofw_bus kobj-interface. The IVAR-
interfaces of the Central, EBus and FHC are entirely replaced by this. The
PCI bus driver used its own kobj-interface and now also uses the ofw_bus
one. The IVARs special to the SBus, e.g. for retrieving the burst size,
remain.
Beware: this causes an ABI-breakage for modules of drivers which used the
IVAR-interfaces, i.e. esp(4), hme(4), isp(4) and uart(4), which need to be
recompiled.
The style-inconsistencies introduced in some of the bus drivers will be
fixed by tmm@ in a generic clean-up of the respective drivers later (he
requested to add the changes in the "new" style).
- Convert the powerpc MacIO bus driver and the drivers for its children to
use the ofw_bus kobj-interface. This invloves removing the IVARs related
to the "reg" property which were unused and a leftover from the NetBSD
origini of the code. There's no ABI-breakage caused by this because none
of these driver are currently built as modules.
There are other powerpc bus drivers which can be converted to the ofw_bus
kobj-interface, e.g. the PCI bus driver, which should be done together
with converting powerpc to use the OFW PCI code from sparc64.
- Make the SBus and FHC front-end of zs(4) and the sparc64 eeprom(4) take
advantage of the ofw_bus kobj-interface and simplify them a bit.
Reviewed by: grehan, tmm
Approved by: re (scottl)
Discussed with: tmm
Tested with: Sun AX1105, AXe, Ultra 2, Ultra 60; PPC cross-build on i386
2004-08-12 17:41:33 +00:00
|
|
|
name = ofw_bus_get_name(dev);
|
2002-02-27 17:35:48 +00:00
|
|
|
if (strcmp(name, "SUNW,qfe") == 0 ||
|
|
|
|
strcmp(name, "SUNW,hme") == 0) {
|
|
|
|
device_set_desc(dev, "Sun HME 10/100 Ethernet");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hme_sbus_attach(device_t dev)
|
|
|
|
{
|
2008-04-26 14:17:21 +00:00
|
|
|
struct hme_sbus_softc *hsc;
|
|
|
|
struct hme_softc *sc;
|
2002-02-27 17:35:48 +00:00
|
|
|
u_long start, count;
|
2008-04-26 14:17:21 +00:00
|
|
|
uint32_t burst;
|
|
|
|
int i, error = 0;
|
2002-02-27 17:35:48 +00:00
|
|
|
|
2008-04-26 14:17:21 +00:00
|
|
|
hsc = device_get_softc(dev);
|
|
|
|
sc = &hsc->hsc_hme;
|
2004-11-22 06:46:30 +00:00
|
|
|
mtx_init(&sc->sc_lock, device_get_nameunit(dev), MTX_NETWORK_LOCK,
|
|
|
|
MTX_DEF);
|
2002-02-27 17:35:48 +00:00
|
|
|
/*
|
|
|
|
* Map five register banks:
|
|
|
|
*
|
|
|
|
* bank 0: HME SEB registers
|
|
|
|
* bank 1: HME ETX registers
|
|
|
|
* bank 2: HME ERX registers
|
|
|
|
* bank 3: HME MAC registers
|
|
|
|
* bank 4: HME MIF registers
|
|
|
|
*
|
|
|
|
*/
|
2008-04-26 14:17:21 +00:00
|
|
|
i = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
hsc->hsc_seb_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
|
2008-04-26 14:17:21 +00:00
|
|
|
&i, RF_ACTIVE);
|
2002-02-27 17:35:48 +00:00
|
|
|
if (hsc->hsc_seb_res == NULL) {
|
|
|
|
device_printf(dev, "cannot map SEB registers\n");
|
2004-11-22 06:46:30 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail_mtx_res;
|
2002-02-27 17:35:48 +00:00
|
|
|
}
|
|
|
|
sc->sc_sebt = rman_get_bustag(hsc->hsc_seb_res);
|
|
|
|
sc->sc_sebh = rman_get_bushandle(hsc->hsc_seb_res);
|
|
|
|
|
2008-04-26 14:17:21 +00:00
|
|
|
i = 1;
|
2004-03-17 17:50:55 +00:00
|
|
|
hsc->hsc_etx_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
|
2008-04-26 14:17:21 +00:00
|
|
|
&i, RF_ACTIVE);
|
2002-02-27 17:35:48 +00:00
|
|
|
if (hsc->hsc_etx_res == NULL) {
|
|
|
|
device_printf(dev, "cannot map ETX registers\n");
|
2004-08-12 20:37:02 +00:00
|
|
|
error = ENXIO;
|
2002-02-27 17:35:48 +00:00
|
|
|
goto fail_seb_res;
|
|
|
|
}
|
|
|
|
sc->sc_etxt = rman_get_bustag(hsc->hsc_etx_res);
|
|
|
|
sc->sc_etxh = rman_get_bushandle(hsc->hsc_etx_res);
|
|
|
|
|
2008-04-26 14:17:21 +00:00
|
|
|
i = 2;
|
2004-03-17 17:50:55 +00:00
|
|
|
hsc->hsc_erx_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
|
2008-04-26 14:17:21 +00:00
|
|
|
&i, RF_ACTIVE);
|
2002-02-27 17:35:48 +00:00
|
|
|
if (hsc->hsc_erx_res == NULL) {
|
|
|
|
device_printf(dev, "cannot map ERX registers\n");
|
2004-08-12 20:37:02 +00:00
|
|
|
error = ENXIO;
|
2002-02-27 17:35:48 +00:00
|
|
|
goto fail_etx_res;
|
|
|
|
}
|
|
|
|
sc->sc_erxt = rman_get_bustag(hsc->hsc_erx_res);
|
|
|
|
sc->sc_erxh = rman_get_bushandle(hsc->hsc_erx_res);
|
|
|
|
|
2008-04-26 14:17:21 +00:00
|
|
|
i = 3;
|
2004-03-17 17:50:55 +00:00
|
|
|
hsc->hsc_mac_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
|
2008-04-26 14:17:21 +00:00
|
|
|
&i, RF_ACTIVE);
|
2002-02-27 17:35:48 +00:00
|
|
|
if (hsc->hsc_mac_res == NULL) {
|
|
|
|
device_printf(dev, "cannot map MAC registers\n");
|
2004-08-12 20:37:02 +00:00
|
|
|
error = ENXIO;
|
2002-02-27 17:35:48 +00:00
|
|
|
goto fail_erx_res;
|
|
|
|
}
|
|
|
|
sc->sc_mact = rman_get_bustag(hsc->hsc_mac_res);
|
|
|
|
sc->sc_mach = rman_get_bushandle(hsc->hsc_mac_res);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At least on some HMEs, the MIF registers seem to be inside the MAC
|
2004-08-12 20:37:02 +00:00
|
|
|
* range, so try to kludge around it.
|
2002-02-27 17:35:48 +00:00
|
|
|
*/
|
2008-04-26 14:17:21 +00:00
|
|
|
i = 4;
|
2004-03-17 17:50:55 +00:00
|
|
|
hsc->hsc_mif_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
|
2008-04-26 14:17:21 +00:00
|
|
|
&i, RF_ACTIVE);
|
2002-02-27 17:35:48 +00:00
|
|
|
if (hsc->hsc_mif_res == NULL) {
|
2008-04-26 14:17:21 +00:00
|
|
|
if (bus_get_resource(dev, SYS_RES_MEMORY, i,
|
2002-02-27 17:35:48 +00:00
|
|
|
&start, &count) != 0) {
|
|
|
|
device_printf(dev, "cannot get MIF registers\n");
|
2004-08-12 20:37:02 +00:00
|
|
|
error = ENXIO;
|
2002-02-27 17:35:48 +00:00
|
|
|
goto fail_mac_res;
|
|
|
|
}
|
|
|
|
if (start < rman_get_start(hsc->hsc_mac_res) ||
|
|
|
|
start + count - 1 > rman_get_end(hsc->hsc_mac_res)) {
|
|
|
|
device_printf(dev, "cannot move MIF registers to MAC "
|
|
|
|
"bank\n");
|
2004-08-12 20:37:02 +00:00
|
|
|
error = ENXIO;
|
2002-02-27 17:35:48 +00:00
|
|
|
goto fail_mac_res;
|
|
|
|
}
|
|
|
|
sc->sc_mift = sc->sc_mact;
|
2004-08-12 20:37:02 +00:00
|
|
|
bus_space_subregion(sc->sc_mact, sc->sc_mach,
|
|
|
|
start - rman_get_start(hsc->hsc_mac_res), count,
|
|
|
|
&sc->sc_mifh);
|
2002-02-27 17:35:48 +00:00
|
|
|
} else {
|
|
|
|
sc->sc_mift = rman_get_bustag(hsc->hsc_mif_res);
|
|
|
|
sc->sc_mifh = rman_get_bushandle(hsc->hsc_mif_res);
|
|
|
|
}
|
|
|
|
|
2008-04-26 14:17:21 +00:00
|
|
|
i = 0;
|
|
|
|
hsc->hsc_ires = bus_alloc_resource_any(dev, SYS_RES_IRQ,
|
|
|
|
&i, RF_SHAREABLE | RF_ACTIVE);
|
2002-02-27 17:35:48 +00:00
|
|
|
if (hsc->hsc_ires == NULL) {
|
|
|
|
device_printf(dev, "could not allocate interrupt\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto fail_mif_res;
|
|
|
|
}
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
OF_getetheraddr(dev, sc->sc_enaddr);
|
2002-02-27 17:35:48 +00:00
|
|
|
|
|
|
|
burst = sbus_get_burstsz(dev);
|
|
|
|
/* Translate into plain numerical format */
|
2004-08-05 02:52:33 +00:00
|
|
|
if ((burst & SBUS_BURST_64))
|
|
|
|
sc->sc_burst = 64;
|
|
|
|
else if ((burst & SBUS_BURST_32))
|
|
|
|
sc->sc_burst = 32;
|
|
|
|
else if ((burst & SBUS_BURST_16))
|
|
|
|
sc->sc_burst = 16;
|
|
|
|
else
|
|
|
|
sc->sc_burst = 0;
|
2002-02-27 17:35:48 +00:00
|
|
|
|
|
|
|
sc->sc_dev = dev;
|
o Disable HMEDEBUG by default.
o Add CTASSERTs ensuring that HME_NRXDESC and HME_NTXDESC are set to
legal values.
o Use appropriate maxsize, nsegments and maxsegsize parameters when
creating DMA tags and correct some comments related to them.
o The FreeBSD bus_dmamap_sync(9) supports ored together flags for quite
some time now so collapse calls accordingly.
o Add missing BUS_DMASYNC_PREREAD when syncing the control DMA maps in
hme_rint() and hme_start_locked().
o Keep state of the link state and use it to enable or disable the MAC
in hme_mii_statchg() accordingly as well as to return early from
hme_start_locked() in case the link is down.
o Introduce a sc_flags and use it to replace individual members like
sc_pci.
o Add bus_barrier(9) calls to hme_mac_bitflip(), hme_mii_readreg(),
hme_mii_writereg() and hme_stop() to ensure the respective bit
has been written before we starting polling on it and for the right
bits to change.
o Rather just returning in case hme_mac_bitflip() fails and leaving us
in an undefined state report the problem and move on; chances are
the requested configuration will become active shortly after.
o Don't call hme_start_locked() in hme_init_locked() unconditionally
but only after calls to hme_init_locked() when it's appropriate, i.e.
in hme_watchdog().
o Add a KASSERT which asserts nsegs is valid also to hme_load_txmbuf().
o In hme_load_txmbuf():
- use a maximum of the newly introduced HME_NTXSEGS segments instead
of the incorrect HME_NTXQ, which reflects the maximum TX queue
length, for loading the mbufs and put the DMA segments back onto
the stack instead of the softc as 16 should be ok there.
- use the common errno(2) return values instead of homegrown ones,
- given that hme_load_txmbuf() is allowed to fail resulting in a
packet drop for quite some time now implement the functionality of
hme_txcksum() by means of m_pullup(9), which de-obfuscates the code
and allows to always retrieve the correct length of the IP header, [1]
- also add a KASSERT which asserts nsegs is valid,
- take advantage of m_collapse(9) instead of m_defrag(9) for
performance reasons.
o Don't bother to check whether the interface is running or whether its
queue is empty before calling hme_start_locked() in hme_tint(), the
former will check these anyway.
o In hme_intr() call hme_rint() before hme_tint() as gem_tint() may
take quite a while to return when it calls hme_start_locked().
o Get rid of sc_debug and just check if_flags for IFF_DEBUG directly.
o Add a shadow sc_ifflags so we don't reset the chip when unnecessary.
o Handle IFF_ALLMULTI correctly. [2]
o Use PCIR_BAR instead of a homegrown macro.
o Replace sc_enaddr[6] with sc_enaddr[ETHER_ADDR_LEN].
o Use the maximum of 256 TX descriptors for better performance as using
all of them has no additional static cost rather than using just half
of them.
Reported by: rwatson [2]
Suggested by: yongari [1]
Reviewed by: yongari
MFC after: 1 month
2008-04-24 23:12:03 +00:00
|
|
|
sc->sc_flags = 0;
|
2002-02-27 17:35:48 +00:00
|
|
|
|
|
|
|
if ((error = hme_config(sc)) != 0) {
|
|
|
|
device_printf(dev, "could not be configured\n");
|
|
|
|
goto fail_ires;
|
|
|
|
}
|
|
|
|
|
2004-11-22 06:46:30 +00:00
|
|
|
if ((error = bus_setup_intr(dev, hsc->hsc_ires, INTR_TYPE_NET |
|
2007-02-23 12:19:07 +00:00
|
|
|
INTR_MPSAFE, NULL, hme_intr, sc, &hsc->hsc_ih)) != 0) {
|
2002-02-27 17:35:48 +00:00
|
|
|
device_printf(dev, "couldn't establish interrupt\n");
|
2003-01-09 00:45:10 +00:00
|
|
|
hme_detach(sc);
|
2002-02-27 17:35:48 +00:00
|
|
|
goto fail_ires;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
fail_ires:
|
2008-04-26 14:17:21 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_IRQ,
|
|
|
|
rman_get_rid(hsc->hsc_ires), hsc->hsc_ires);
|
2002-02-27 17:35:48 +00:00
|
|
|
fail_mif_res:
|
|
|
|
if (hsc->hsc_mif_res != NULL) {
|
2008-04-26 14:17:21 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY,
|
|
|
|
rman_get_rid(hsc->hsc_mif_res), hsc->hsc_mif_res);
|
2002-02-27 17:35:48 +00:00
|
|
|
}
|
|
|
|
fail_mac_res:
|
2008-04-26 14:17:21 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY,
|
|
|
|
rman_get_rid(hsc->hsc_mac_res), hsc->hsc_mac_res);
|
2002-02-27 17:35:48 +00:00
|
|
|
fail_erx_res:
|
2008-04-26 14:17:21 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY,
|
|
|
|
rman_get_rid(hsc->hsc_erx_res), hsc->hsc_erx_res);
|
2002-02-27 17:35:48 +00:00
|
|
|
fail_etx_res:
|
2008-04-26 14:17:21 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY,
|
|
|
|
rman_get_rid(hsc->hsc_etx_res), hsc->hsc_etx_res);
|
2002-02-27 17:35:48 +00:00
|
|
|
fail_seb_res:
|
2008-04-26 14:17:21 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY,
|
|
|
|
rman_get_rid(hsc->hsc_seb_res), hsc->hsc_seb_res);
|
2004-11-22 06:46:30 +00:00
|
|
|
fail_mtx_res:
|
|
|
|
mtx_destroy(&sc->sc_lock);
|
2004-08-12 20:37:02 +00:00
|
|
|
return (error);
|
2002-02-27 17:35:48 +00:00
|
|
|
}
|
2003-01-09 00:45:10 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
hme_sbus_detach(device_t dev)
|
|
|
|
{
|
2008-04-26 14:17:21 +00:00
|
|
|
struct hme_sbus_softc *hsc;
|
|
|
|
struct hme_softc *sc;
|
2003-01-09 00:45:10 +00:00
|
|
|
|
2008-04-26 14:17:21 +00:00
|
|
|
hsc = device_get_softc(dev);
|
|
|
|
sc = &hsc->hsc_hme;
|
2003-01-09 00:45:10 +00:00
|
|
|
bus_teardown_intr(dev, hsc->hsc_ires, hsc->hsc_ih);
|
2004-11-22 06:46:30 +00:00
|
|
|
hme_detach(sc);
|
2008-04-26 14:17:21 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_IRQ,
|
|
|
|
rman_get_rid(hsc->hsc_ires), hsc->hsc_ires);
|
2003-01-09 00:45:10 +00:00
|
|
|
if (hsc->hsc_mif_res != NULL) {
|
2008-04-26 14:17:21 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY,
|
|
|
|
rman_get_rid(hsc->hsc_mif_res), hsc->hsc_mif_res);
|
2003-01-09 00:45:10 +00:00
|
|
|
}
|
2008-04-26 14:17:21 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY,
|
|
|
|
rman_get_rid(hsc->hsc_mac_res), hsc->hsc_mac_res);
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY,
|
|
|
|
rman_get_rid(hsc->hsc_erx_res), hsc->hsc_erx_res);
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY,
|
|
|
|
rman_get_rid(hsc->hsc_etx_res), hsc->hsc_etx_res);
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY,
|
|
|
|
rman_get_rid(hsc->hsc_seb_res), hsc->hsc_seb_res);
|
2004-11-22 06:46:30 +00:00
|
|
|
mtx_destroy(&sc->sc_lock);
|
2003-01-09 00:45:10 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hme_sbus_suspend(device_t dev)
|
|
|
|
{
|
2008-04-26 14:17:21 +00:00
|
|
|
struct hme_sbus_softc *hsc;
|
2003-01-09 00:45:10 +00:00
|
|
|
|
2008-04-26 14:17:21 +00:00
|
|
|
hsc = device_get_softc(dev);
|
|
|
|
hme_suspend(&hsc->hsc_hme);
|
2003-01-09 00:45:10 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hme_sbus_resume(device_t dev)
|
|
|
|
{
|
2008-04-26 14:17:21 +00:00
|
|
|
struct hme_sbus_softc *hsc;
|
2003-01-09 00:45:10 +00:00
|
|
|
|
2008-04-26 14:17:21 +00:00
|
|
|
hsc = device_get_softc(dev);
|
|
|
|
hme_resume(&hsc->hsc_hme);
|
2003-01-09 00:45:10 +00:00
|
|
|
return (0);
|
|
|
|
}
|