Add device suspend/resume/detach. (Tested with drvctl -S bnx0,
drvctl -Q bnx0, drvctl -d bnx0.) Separate device_t storage from softc storage and use CFATTACH_DECL_NEW().
This commit is contained in:
parent
bc98ae9212
commit
d2a6fcd7d7
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: if_bnx.c,v 1.12 2007/12/15 00:39:29 perry Exp $ */
|
||||
/* $NetBSD: if_bnx.c,v 1.13 2007/12/26 04:06:29 dyoung Exp $ */
|
||||
/* $OpenBSD: if_bnx.c,v 1.43 2007/01/30 03:21:10 krw Exp $ */
|
||||
|
||||
/*-
|
||||
@ -35,7 +35,7 @@
|
||||
#if 0
|
||||
__FBSDID("$FreeBSD: src/sys/dev/bce/if_bce.c,v 1.3 2006/04/13 14:12:26 ru Exp $");
|
||||
#endif
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_bnx.c,v 1.12 2007/12/15 00:39:29 perry Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_bnx.c,v 1.13 2007/12/26 04:06:29 dyoung Exp $");
|
||||
|
||||
/*
|
||||
* The following controllers are supported by this driver:
|
||||
@ -242,11 +242,9 @@ static struct flash_spec flash_table[] =
|
||||
/* OpenBSD device entry points. */
|
||||
/****************************************************************************/
|
||||
static int bnx_probe(device_t, cfdata_t, void *);
|
||||
void bnx_attach(struct device *, struct device *, void *);
|
||||
#if 0
|
||||
void bnx_detach(void *);
|
||||
#endif
|
||||
void bnx_shutdown(void *);
|
||||
bool bnx_suspend_resume(device_t);
|
||||
void bnx_attach(device_t, device_t, void *);
|
||||
int bnx_detach(device_t, int);
|
||||
|
||||
/****************************************************************************/
|
||||
/* BNX Debug Data Structure Dump Routines */
|
||||
@ -273,9 +271,9 @@ void bnx_breakpoint(struct bnx_softc *);
|
||||
u_int32_t bnx_reg_rd_ind(struct bnx_softc *, u_int32_t);
|
||||
void bnx_reg_wr_ind(struct bnx_softc *, u_int32_t, u_int32_t);
|
||||
void bnx_ctx_wr(struct bnx_softc *, u_int32_t, u_int32_t, u_int32_t);
|
||||
int bnx_miibus_read_reg(struct device *, int, int);
|
||||
void bnx_miibus_write_reg(struct device *, int, int, int);
|
||||
void bnx_miibus_statchg(struct device *);
|
||||
int bnx_miibus_read_reg(device_t, int, int);
|
||||
void bnx_miibus_write_reg(device_t, int, int, int);
|
||||
void bnx_miibus_statchg(device_t);
|
||||
|
||||
/****************************************************************************/
|
||||
/* BNX NVRAM Access Routines */
|
||||
@ -315,6 +313,7 @@ void bnx_load_cpu_fw(struct bnx_softc *, struct cpu_reg *,
|
||||
struct fw_info *);
|
||||
void bnx_init_cpus(struct bnx_softc *);
|
||||
|
||||
void bnx_if_stop(struct ifnet *, int);
|
||||
void bnx_stop(struct bnx_softc *);
|
||||
int bnx_reset(struct bnx_softc *, u_int32_t);
|
||||
int bnx_chipinit(struct bnx_softc *);
|
||||
@ -352,8 +351,8 @@ void bnx_tick(void *);
|
||||
/****************************************************************************/
|
||||
/* OpenBSD device dispatch table. */
|
||||
/****************************************************************************/
|
||||
CFATTACH_DECL(bnx, sizeof(struct bnx_softc),
|
||||
bnx_probe, bnx_attach, NULL, NULL);
|
||||
CFATTACH_DECL_NEW(bnx, sizeof(struct bnx_softc),
|
||||
bnx_probe, bnx_attach, bnx_detach, NULL);
|
||||
|
||||
/****************************************************************************/
|
||||
/* Device probe function. */
|
||||
@ -370,7 +369,7 @@ bnx_lookup(const struct pci_attach_args *pa)
|
||||
int i;
|
||||
pcireg_t subid;
|
||||
|
||||
for (i = 0; i < sizeof(bnx_devices)/sizeof(struct bnx_product); i++) {
|
||||
for (i = 0; i < __arraycount(bnx_devices); i++) {
|
||||
if (PCI_VENDOR(pa->pa_id) != bnx_devices[i].bp_vendor ||
|
||||
PCI_PRODUCT(pa->pa_id) != bnx_devices[i].bp_product)
|
||||
continue;
|
||||
@ -395,6 +394,14 @@ bnx_probe(device_t parent, cfdata_t match, void *aux)
|
||||
return (0);
|
||||
}
|
||||
|
||||
bool
|
||||
bnx_suspend_resume(device_t dev)
|
||||
{
|
||||
struct bnx_softc *sc = device_private(dev);
|
||||
|
||||
return bnx_reset(sc, BNX_DRV_MSG_CODE_RESET) == 0;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/* Device attach function. */
|
||||
/* */
|
||||
@ -406,10 +413,10 @@ bnx_probe(device_t parent, cfdata_t match, void *aux)
|
||||
/* 0 on success, positive value on failure. */
|
||||
/****************************************************************************/
|
||||
void
|
||||
bnx_attach(struct device *parent, struct device *self, void *aux)
|
||||
bnx_attach(device_t parent, device_t self, void *aux)
|
||||
{
|
||||
const struct bnx_product *bp;
|
||||
struct bnx_softc *sc = (struct bnx_softc *)self;
|
||||
struct bnx_softc *sc = device_private(self);
|
||||
struct pci_attach_args *pa = aux;
|
||||
pci_chipset_tag_t pc = pa->pa_pc;
|
||||
pci_intr_handle_t ih;
|
||||
@ -423,6 +430,8 @@ bnx_attach(struct device *parent, struct device *self, void *aux)
|
||||
if (bp == NULL)
|
||||
panic("unknown device");
|
||||
|
||||
sc->bnx_dev = self;
|
||||
|
||||
aprint_naive("\n");
|
||||
aprint_normal(": %s\n", bp->bp_name);
|
||||
|
||||
@ -437,8 +446,8 @@ bnx_attach(struct device *parent, struct device *self, void *aux)
|
||||
command = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
|
||||
|
||||
if (!(command & PCI_COMMAND_MEM_ENABLE)) {
|
||||
aprint_error("%s: failed to enable memory mapping!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"failed to enable memory mapping!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -451,14 +460,12 @@ bnx_attach(struct device *parent, struct device *self, void *aux)
|
||||
NULL, &sc->bnx_size) == 0)
|
||||
break;
|
||||
default:
|
||||
aprint_error("%s: can't find mem space\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev, "can't find mem space\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (pci_intr_map(pa, &ih)) {
|
||||
aprint_error("%s: couldn't map interrupt\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev, "couldn't map interrupt\n");
|
||||
goto bnx_attach_fail;
|
||||
}
|
||||
|
||||
@ -483,16 +490,16 @@ bnx_attach(struct device *parent, struct device *self, void *aux)
|
||||
case BNX_CHIP_ID_5706_A1:
|
||||
case BNX_CHIP_ID_5708_A0:
|
||||
case BNX_CHIP_ID_5708_B0:
|
||||
aprint_error("%s: unsupported controller revision (%c%d)!\n",
|
||||
sc->bnx_dev.dv_xname,
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"unsupported controller revision (%c%d)!\n",
|
||||
((PCI_REVISION(pa->pa_class) & 0xf0) >> 4) + 'A',
|
||||
PCI_REVISION(pa->pa_class) & 0x0f);
|
||||
goto bnx_attach_fail;
|
||||
}
|
||||
|
||||
if (BNX_CHIP_BOND_ID(sc) & BNX_CHIP_BOND_ID_SERDES_BIT) {
|
||||
aprint_error("%s: SerDes controllers are not supported!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"SerDes controllers are not supported!\n");
|
||||
goto bnx_attach_fail;
|
||||
}
|
||||
|
||||
@ -562,20 +569,20 @@ bnx_attach(struct device *parent, struct device *self, void *aux)
|
||||
|
||||
/* Initialize the controller. */
|
||||
if (bnx_chipinit(sc)) {
|
||||
aprint_error("%s: Controller initialization failed!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Controller initialization failed!\n");
|
||||
goto bnx_attach_fail;
|
||||
}
|
||||
|
||||
/* Perform NVRAM test. */
|
||||
if (bnx_nvram_test(sc)) {
|
||||
aprint_error("%s: NVRAM test failed!\n", sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev, "NVRAM test failed!\n");
|
||||
goto bnx_attach_fail;
|
||||
}
|
||||
|
||||
/* Fetch the permanent Ethernet MAC address. */
|
||||
bnx_get_mac_addr(sc);
|
||||
aprint_normal("%s: Ethernet address %s\n", sc->bnx_dev.dv_xname,
|
||||
aprint_normal_dev(sc->bnx_dev, "Ethernet address %s\n",
|
||||
ether_sprintf(sc->eaddr));
|
||||
|
||||
/*
|
||||
@ -634,16 +641,16 @@ bnx_attach(struct device *parent, struct device *self, void *aux)
|
||||
}
|
||||
|
||||
if (sc->bnx_phy_flags & BNX_PHY_SERDES_FLAG) {
|
||||
aprint_error("%s: SerDes is not supported by this driver!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"SerDes is not supported by this driver!\n");
|
||||
goto bnx_attach_fail;
|
||||
}
|
||||
|
||||
/* Allocate DMA memory resources. */
|
||||
sc->bnx_dmatag = pa->pa_dmat;
|
||||
if (bnx_dma_alloc(sc)) {
|
||||
aprint_error("%s: DMA resource allocation failed!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"DMA resource allocation failed!\n");
|
||||
goto bnx_attach_fail;
|
||||
}
|
||||
|
||||
@ -652,6 +659,7 @@ bnx_attach(struct device *parent, struct device *self, void *aux)
|
||||
ifp->if_softc = sc;
|
||||
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
||||
ifp->if_ioctl = bnx_ioctl;
|
||||
ifp->if_stop = bnx_if_stop;
|
||||
ifp->if_start = bnx_start;
|
||||
ifp->if_init = bnx_init;
|
||||
ifp->if_timer = 0;
|
||||
@ -662,7 +670,7 @@ bnx_attach(struct device *parent, struct device *self, void *aux)
|
||||
ifp->if_baudrate = IF_Gbps(1);
|
||||
IFQ_SET_MAXLEN(&ifp->if_snd, USABLE_TX_BD - 1);
|
||||
IFQ_SET_READY(&ifp->if_snd);
|
||||
bcopy(sc->bnx_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
|
||||
memcpy(ifp->if_xname, device_xname(self), IFNAMSIZ);
|
||||
|
||||
sc->ethercom.ec_capabilities |= ETHERCAP_JUMBO_MTU |
|
||||
ETHERCAP_VLAN_MTU | ETHERCAP_VLAN_HWTAGGING;
|
||||
@ -675,8 +683,7 @@ bnx_attach(struct device *parent, struct device *self, void *aux)
|
||||
/* Hookup IRQ last. */
|
||||
sc->bnx_intrhand = pci_intr_establish(pc, ih, IPL_NET, bnx_intr, sc);
|
||||
if (sc->bnx_intrhand == NULL) {
|
||||
aprint_error("%s: couldn't establish interrupt",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(self, "couldn't establish interrupt");
|
||||
if (intrstr != NULL)
|
||||
aprint_error(" at %s", intrstr);
|
||||
aprint_error("\n");
|
||||
@ -691,11 +698,11 @@ bnx_attach(struct device *parent, struct device *self, void *aux)
|
||||
/* Look for our PHY. */
|
||||
ifmedia_init(&sc->bnx_mii.mii_media, 0, bnx_ifmedia_upd,
|
||||
bnx_ifmedia_sts);
|
||||
mii_attach(&sc->bnx_dev, &sc->bnx_mii, 0xffffffff,
|
||||
mii_attach(self, &sc->bnx_mii, 0xffffffff,
|
||||
MII_PHY_ANY, MII_OFFSET_ANY, 0);
|
||||
|
||||
if (LIST_FIRST(&sc->bnx_mii.mii_phys) == NULL) {
|
||||
aprint_error("%s: no PHY found!\n", sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(self, "no PHY found!\n");
|
||||
ifmedia_add(&sc->bnx_mii.mii_media,
|
||||
IFM_ETHER|IFM_MANUAL, 0, NULL);
|
||||
ifmedia_set(&sc->bnx_mii.mii_media,
|
||||
@ -711,6 +718,11 @@ bnx_attach(struct device *parent, struct device *self, void *aux)
|
||||
|
||||
callout_init(&sc->bnx_timeout, 0);
|
||||
|
||||
if (!pmf_device_register(self, bnx_suspend_resume, bnx_suspend_resume))
|
||||
aprint_error_dev(self, "couldn't establish power handler\n");
|
||||
else
|
||||
pmf_class_network_register(self, ifp);
|
||||
|
||||
/* Print some important debugging info. */
|
||||
DBRUN(BNX_INFO, bnx_dump_driver_state(sc));
|
||||
|
||||
@ -731,14 +743,14 @@ bnx_attach_exit:
|
||||
/* Returns: */
|
||||
/* 0 on success, positive value on failure. */
|
||||
/****************************************************************************/
|
||||
#if 0
|
||||
void
|
||||
bnx_detach(void *xsc)
|
||||
int
|
||||
bnx_detach(device_t dev, int flags)
|
||||
{
|
||||
struct bnx_softc *sc;
|
||||
struct ifnet *ifp = &sc->arpcom.ac_if;
|
||||
struct ifnet *ifp;
|
||||
|
||||
sc = device_get_softc(dev);
|
||||
sc = device_private(dev);
|
||||
ifp = &sc->ethercom.ec_if;
|
||||
|
||||
DBPRINT(sc, BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
|
||||
|
||||
@ -746,15 +758,10 @@ bnx_detach(void *xsc)
|
||||
bnx_stop(sc);
|
||||
bnx_reset(sc, BNX_DRV_MSG_CODE_RESET);
|
||||
|
||||
pmf_device_deregister(dev);
|
||||
ether_ifdetach(ifp);
|
||||
|
||||
/* If we have a child device on the MII bus remove it too. */
|
||||
if (sc->bnx_phy_flags & BNX_PHY_SERDES_FLAG) {
|
||||
ifmedia_removeall(&sc->bnx_ifmedia);
|
||||
} else {
|
||||
bus_generic_detach(dev);
|
||||
device_delete_child(dev, sc->bnx_mii);
|
||||
}
|
||||
if_detach(ifp);
|
||||
mii_detach(&sc->bnx_mii, MII_PHY_ANY, MII_OFFSET_ANY);
|
||||
|
||||
/* Release all remaining resources. */
|
||||
bnx_release_resources(sc);
|
||||
@ -763,24 +770,6 @@ bnx_detach(void *xsc)
|
||||
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************/
|
||||
/* Device shutdown function. */
|
||||
/* */
|
||||
/* Stops and resets the controller. */
|
||||
/* */
|
||||
/* Returns: */
|
||||
/* Nothing */
|
||||
/****************************************************************************/
|
||||
void
|
||||
bnx_shutdown(void *xsc)
|
||||
{
|
||||
struct bnx_softc *sc = (struct bnx_softc *)xsc;
|
||||
|
||||
bnx_stop(sc);
|
||||
bnx_reset(sc, BNX_DRV_MSG_CODE_RESET);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/* Indirect register read. */
|
||||
@ -867,9 +856,9 @@ bnx_ctx_wr(struct bnx_softc *sc, u_int32_t cid_addr, u_int32_t offset,
|
||||
/* The value of the register. */
|
||||
/****************************************************************************/
|
||||
int
|
||||
bnx_miibus_read_reg(struct device *dev, int phy, int reg)
|
||||
bnx_miibus_read_reg(device_t dev, int phy, int reg)
|
||||
{
|
||||
struct bnx_softc *sc = (struct bnx_softc *)dev;
|
||||
struct bnx_softc *sc = device_private(dev);
|
||||
u_int32_t val;
|
||||
int i;
|
||||
|
||||
@ -942,9 +931,9 @@ bnx_miibus_read_reg(struct device *dev, int phy, int reg)
|
||||
/* The value of the register. */
|
||||
/****************************************************************************/
|
||||
void
|
||||
bnx_miibus_write_reg(struct device *dev, int phy, int reg, int val)
|
||||
bnx_miibus_write_reg(device_t dev, int phy, int reg, int val)
|
||||
{
|
||||
struct bnx_softc *sc = (struct bnx_softc *)dev;
|
||||
struct bnx_softc *sc = device_private(dev);
|
||||
u_int32_t val1;
|
||||
int i;
|
||||
|
||||
@ -1010,9 +999,9 @@ bnx_miibus_write_reg(struct device *dev, int phy, int reg, int val)
|
||||
/* Nothing. */
|
||||
/****************************************************************************/
|
||||
void
|
||||
bnx_miibus_statchg(struct device *dev)
|
||||
bnx_miibus_statchg(device_t dev)
|
||||
{
|
||||
struct bnx_softc *sc = (struct bnx_softc *)dev;
|
||||
struct bnx_softc *sc = device_private(dev);
|
||||
struct mii_data *mii = &sc->bnx_mii;
|
||||
|
||||
BNX_CLRBIT(sc, BNX_EMAC_MODE, BNX_EMAC_MODE_PORT);
|
||||
@ -1976,8 +1965,8 @@ bnx_dma_alloc(struct bnx_softc *sc)
|
||||
*/
|
||||
if (bus_dmamap_create(sc->bnx_dmatag, BNX_STATUS_BLK_SZ, 1,
|
||||
BNX_STATUS_BLK_SZ, 0, BUS_DMA_NOWAIT, &sc->status_map)) {
|
||||
aprint_error("%s: Could not create status block DMA map!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not create status block DMA map!\n");
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
@ -1985,25 +1974,24 @@ bnx_dma_alloc(struct bnx_softc *sc)
|
||||
if (bus_dmamem_alloc(sc->bnx_dmatag, BNX_STATUS_BLK_SZ,
|
||||
BNX_DMA_ALIGN, BNX_DMA_BOUNDARY, &sc->status_seg, 1,
|
||||
&sc->status_rseg, BUS_DMA_NOWAIT)) {
|
||||
aprint_error(
|
||||
"%s: Could not allocate status block DMA memory!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not allocate status block DMA memory!\n");
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
|
||||
if (bus_dmamem_map(sc->bnx_dmatag, &sc->status_seg, sc->status_rseg,
|
||||
BNX_STATUS_BLK_SZ, (void **)&sc->status_block, BUS_DMA_NOWAIT)) {
|
||||
aprint_error("%s: Could not map status block DMA memory!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not map status block DMA memory!\n");
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
|
||||
if (bus_dmamap_load(sc->bnx_dmatag, sc->status_map,
|
||||
sc->status_block, BNX_STATUS_BLK_SZ, NULL, BUS_DMA_NOWAIT)) {
|
||||
aprint_error("%s: Could not load status block DMA memory!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not load status block DMA memory!\n");
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
@ -2021,8 +2009,8 @@ bnx_dma_alloc(struct bnx_softc *sc)
|
||||
*/
|
||||
if (bus_dmamap_create(sc->bnx_dmatag, BNX_STATS_BLK_SZ, 1,
|
||||
BNX_STATS_BLK_SZ, 0, BUS_DMA_NOWAIT, &sc->stats_map)) {
|
||||
aprint_error("%s: Could not create stats block DMA map!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not create stats block DMA map!\n");
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
@ -2030,24 +2018,24 @@ bnx_dma_alloc(struct bnx_softc *sc)
|
||||
if (bus_dmamem_alloc(sc->bnx_dmatag, BNX_STATS_BLK_SZ,
|
||||
BNX_DMA_ALIGN, BNX_DMA_BOUNDARY, &sc->stats_seg, 1,
|
||||
&sc->stats_rseg, BUS_DMA_NOWAIT)) {
|
||||
aprint_error("%s: Could not allocate stats block DMA memory!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not allocate stats block DMA memory!\n");
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
|
||||
if (bus_dmamem_map(sc->bnx_dmatag, &sc->stats_seg, sc->stats_rseg,
|
||||
BNX_STATS_BLK_SZ, (void **)&sc->stats_block, BUS_DMA_NOWAIT)) {
|
||||
aprint_error("%s: Could not map stats block DMA memory!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not map stats block DMA memory!\n");
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
|
||||
if (bus_dmamap_load(sc->bnx_dmatag, sc->stats_map,
|
||||
sc->stats_block, BNX_STATS_BLK_SZ, NULL, BUS_DMA_NOWAIT)) {
|
||||
aprint_error("%s: Could not load status block DMA memory!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not load status block DMA memory!\n");
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
@ -2067,9 +2055,8 @@ bnx_dma_alloc(struct bnx_softc *sc)
|
||||
if (bus_dmamap_create(sc->bnx_dmatag, BNX_TX_CHAIN_PAGE_SZ, 1,
|
||||
BNX_TX_CHAIN_PAGE_SZ, 0, BUS_DMA_NOWAIT,
|
||||
&sc->tx_bd_chain_map[i])) {
|
||||
aprint_error(
|
||||
"%s: Could not create Tx desc %d DMA map!\n",
|
||||
sc->bnx_dev.dv_xname, i);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not create Tx desc %d DMA map!\n", i);
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
@ -2077,9 +2064,9 @@ bnx_dma_alloc(struct bnx_softc *sc)
|
||||
if (bus_dmamem_alloc(sc->bnx_dmatag, BNX_TX_CHAIN_PAGE_SZ,
|
||||
BCM_PAGE_SIZE, BNX_DMA_BOUNDARY, &sc->tx_bd_chain_seg[i], 1,
|
||||
&sc->tx_bd_chain_rseg[i], BUS_DMA_NOWAIT)) {
|
||||
aprint_error(
|
||||
"%s: Could not allocate TX desc %d DMA memory!\n",
|
||||
sc->bnx_dev.dv_xname, i);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not allocate TX desc %d DMA memory!\n",
|
||||
i);
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
@ -2087,9 +2074,8 @@ bnx_dma_alloc(struct bnx_softc *sc)
|
||||
if (bus_dmamem_map(sc->bnx_dmatag, &sc->tx_bd_chain_seg[i],
|
||||
sc->tx_bd_chain_rseg[i], BNX_TX_CHAIN_PAGE_SZ,
|
||||
(void **)&sc->tx_bd_chain[i], BUS_DMA_NOWAIT)) {
|
||||
aprint_error(
|
||||
"%s: Could not map TX desc %d DMA memory!\n",
|
||||
sc->bnx_dev.dv_xname, i);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not map TX desc %d DMA memory!\n", i);
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
@ -2097,9 +2083,8 @@ bnx_dma_alloc(struct bnx_softc *sc)
|
||||
if (bus_dmamap_load(sc->bnx_dmatag, sc->tx_bd_chain_map[i],
|
||||
(void *)sc->tx_bd_chain[i], BNX_TX_CHAIN_PAGE_SZ, NULL,
|
||||
BUS_DMA_NOWAIT)) {
|
||||
aprint_error(
|
||||
"%s: Could not load TX desc %d DMA memory!\n",
|
||||
sc->bnx_dev.dv_xname, i);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not load TX desc %d DMA memory!\n", i);
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
@ -2121,9 +2106,8 @@ bnx_dma_alloc(struct bnx_softc *sc)
|
||||
USABLE_TX_BD - BNX_TX_SLACK_SPACE,
|
||||
MCLBYTES, 0, BUS_DMA_NOWAIT,
|
||||
&sc->tx_mbuf_map[i])) {
|
||||
aprint_error(
|
||||
"%s: Could not create Tx mbuf %d DMA map!\n",
|
||||
sc->bnx_dev.dv_xname, i);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not create Tx mbuf %d DMA map!\n", i);
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
@ -2137,9 +2121,8 @@ bnx_dma_alloc(struct bnx_softc *sc)
|
||||
if (bus_dmamap_create(sc->bnx_dmatag, BNX_RX_CHAIN_PAGE_SZ, 1,
|
||||
BNX_RX_CHAIN_PAGE_SZ, 0, BUS_DMA_NOWAIT,
|
||||
&sc->rx_bd_chain_map[i])) {
|
||||
aprint_error(
|
||||
"%s: Could not create Rx desc %d DMA map!\n",
|
||||
sc->bnx_dev.dv_xname, i);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not create Rx desc %d DMA map!\n", i);
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
@ -2147,9 +2130,8 @@ bnx_dma_alloc(struct bnx_softc *sc)
|
||||
if (bus_dmamem_alloc(sc->bnx_dmatag, BNX_RX_CHAIN_PAGE_SZ,
|
||||
BCM_PAGE_SIZE, BNX_DMA_BOUNDARY, &sc->rx_bd_chain_seg[i], 1,
|
||||
&sc->rx_bd_chain_rseg[i], BUS_DMA_NOWAIT)) {
|
||||
aprint_error(
|
||||
"%s: Could not allocate Rx desc %d DMA memory!\n",
|
||||
sc->bnx_dev.dv_xname, i);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not allocate Rx desc %d DMA memory!\n", i);
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
@ -2157,9 +2139,8 @@ bnx_dma_alloc(struct bnx_softc *sc)
|
||||
if (bus_dmamem_map(sc->bnx_dmatag, &sc->rx_bd_chain_seg[i],
|
||||
sc->rx_bd_chain_rseg[i], BNX_RX_CHAIN_PAGE_SZ,
|
||||
(void **)&sc->rx_bd_chain[i], BUS_DMA_NOWAIT)) {
|
||||
aprint_error(
|
||||
"%s: Could not map Rx desc %d DMA memory!\n",
|
||||
sc->bnx_dev.dv_xname, i);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not map Rx desc %d DMA memory!\n", i);
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
@ -2167,9 +2148,8 @@ bnx_dma_alloc(struct bnx_softc *sc)
|
||||
if (bus_dmamap_load(sc->bnx_dmatag, sc->rx_bd_chain_map[i],
|
||||
(void *)sc->rx_bd_chain[i], BNX_RX_CHAIN_PAGE_SZ, NULL,
|
||||
BUS_DMA_NOWAIT)) {
|
||||
aprint_error(
|
||||
"%s: Could not load Rx desc %d DMA memory!\n",
|
||||
sc->bnx_dev.dv_xname, i);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not load Rx desc %d DMA memory!\n", i);
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
@ -2193,9 +2173,8 @@ bnx_dma_alloc(struct bnx_softc *sc)
|
||||
if (bus_dmamap_create(sc->bnx_dmatag, BNX_MAX_MRU,
|
||||
BNX_MAX_SEGMENTS, BNX_MAX_MRU, 0, BUS_DMA_NOWAIT,
|
||||
&sc->rx_mbuf_map[i])) {
|
||||
aprint_error(
|
||||
"%s: Could not create Rx mbuf %d DMA map!\n",
|
||||
sc->bnx_dev.dv_xname, i);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Could not create Rx mbuf %d DMA map!\n", i);
|
||||
rc = ENOMEM;
|
||||
goto bnx_dma_alloc_exit;
|
||||
}
|
||||
@ -2219,6 +2198,7 @@ bnx_dma_alloc(struct bnx_softc *sc)
|
||||
void
|
||||
bnx_release_resources(struct bnx_softc *sc)
|
||||
{
|
||||
int i;
|
||||
struct pci_attach_args *pa = &(sc->bnx_pa);
|
||||
|
||||
DBPRINT(sc, BNX_VERBOSE_RESET, "Entering %s()\n", __func__);
|
||||
@ -2231,6 +2211,9 @@ bnx_release_resources(struct bnx_softc *sc)
|
||||
if (sc->bnx_size)
|
||||
bus_space_unmap(sc->bnx_btag, sc->bnx_bhandle, sc->bnx_size);
|
||||
|
||||
for (i = 0; i < TOTAL_RX_BD; i++)
|
||||
bus_dmamap_destroy(sc->bnx_dmatag, sc->rx_mbuf_map[i]);
|
||||
|
||||
DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
|
||||
}
|
||||
|
||||
@ -2715,6 +2698,14 @@ bnx_set_mac_addr(struct bnx_softc *sc)
|
||||
REG_WR(sc, BNX_EMAC_MAC_MATCH1, val);
|
||||
}
|
||||
|
||||
void
|
||||
bnx_if_stop(struct ifnet *ifp, int disable)
|
||||
{
|
||||
struct bnx_softc *sc = ifp->if_softc;
|
||||
|
||||
bnx_stop(sc);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/* Stop the controller. */
|
||||
/* */
|
||||
@ -3071,8 +3062,9 @@ bnx_get_buf(struct bnx_softc *sc, struct mbuf *m, u_int16_t *prod,
|
||||
|
||||
/* Make sure the inputs are valid. */
|
||||
DBRUNIF((*chain_prod > MAX_RX_BD),
|
||||
aprint_error("%s: RX producer out of range: 0x%04X > 0x%04X\n",
|
||||
sc->bnx_dev.dv_xname, *chain_prod, (u_int16_t) MAX_RX_BD));
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"RX producer out of range: 0x%04X > 0x%04X\n",
|
||||
*chain_prod, (u_int16_t)MAX_RX_BD));
|
||||
|
||||
DBPRINT(sc, BNX_VERBOSE_RECV, "%s(enter): prod = 0x%04X, chain_prod = "
|
||||
"0x%04X, prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod,
|
||||
@ -3151,9 +3143,9 @@ bnx_get_buf(struct bnx_softc *sc, struct mbuf *m, u_int16_t *prod,
|
||||
|
||||
/* Watch for overflow. */
|
||||
DBRUNIF((sc->free_rx_bd > USABLE_RX_BD),
|
||||
aprint_error("%s: Too many free rx_bd (0x%04X > 0x%04X)!\n",
|
||||
sc->bnx_dev.dv_xname,
|
||||
sc->free_rx_bd, (u_int16_t) USABLE_RX_BD));
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Too many free rx_bd (0x%04X > 0x%04X)!\n",
|
||||
sc->free_rx_bd, (u_int16_t)USABLE_RX_BD));
|
||||
|
||||
DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
|
||||
sc->rx_low_watermark = sc->free_rx_bd);
|
||||
@ -3339,8 +3331,9 @@ bnx_free_tx_chain(struct bnx_softc *sc)
|
||||
|
||||
/* Check if we lost any mbufs in the process. */
|
||||
DBRUNIF((sc->tx_mbuf_alloc),
|
||||
aprint_error("%s: Memory leak! Lost %d mbufs from tx chain!\n",
|
||||
sc->bnx_dev.dv_xname, sc->tx_mbuf_alloc));
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Memory leak! Lost %d mbufs from tx chain!\n",
|
||||
sc->tx_mbuf_alloc));
|
||||
|
||||
DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
|
||||
}
|
||||
@ -3463,8 +3456,9 @@ bnx_free_rx_chain(struct bnx_softc *sc)
|
||||
|
||||
/* Check if we lost any mbufs in the process. */
|
||||
DBRUNIF((sc->rx_mbuf_alloc),
|
||||
aprint_error("%s: Memory leak! Lost %d mbufs from rx chain!\n",
|
||||
sc->bnx_dev.dv_xname, sc->rx_mbuf_alloc));
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Memory leak! Lost %d mbufs from rx chain!\n",
|
||||
sc->rx_mbuf_alloc));
|
||||
|
||||
DBPRINT(sc, BNX_VERBOSE_RESET, "Exiting %s()\n", __func__);
|
||||
}
|
||||
@ -3648,7 +3642,7 @@ bnx_rx_intr(struct bnx_softc *sc)
|
||||
/* Validate that this is the last rx_bd. */
|
||||
if ((rxbd->rx_bd_flags & RX_BD_FLAGS_END) == 0) {
|
||||
printf("%s: Unexpected mbuf found in "
|
||||
"rx_bd[0x%04X]!\n", sc->bnx_dev.dv_xname,
|
||||
"rx_bd[0x%04X]!\n", device_xname(sc->bnx_dev),
|
||||
sw_chain_cons);
|
||||
}
|
||||
#endif
|
||||
@ -3706,10 +3700,11 @@ bnx_rx_intr(struct bnx_softc *sc)
|
||||
/* Watch for unusual sized frames. */
|
||||
DBRUNIF(((len < BNX_MIN_MTU) ||
|
||||
(len > BNX_MAX_JUMBO_ETHER_MTU_VLAN)),
|
||||
aprint_error("%s: Unusual frame size found. "
|
||||
"Min(%d), Actual(%d), Max(%d)\n",
|
||||
sc->bnx_dev.dv_xname, (int)BNX_MIN_MTU, len,
|
||||
(int) BNX_MAX_JUMBO_ETHER_MTU_VLAN);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Unusual frame size found. "
|
||||
"Min(%d), Actual(%d), Max(%d)\n",
|
||||
(int)BNX_MIN_MTU, len,
|
||||
(int)BNX_MAX_JUMBO_ETHER_MTU_VLAN);
|
||||
|
||||
bnx_dump_mbuf(sc, m);
|
||||
bnx_breakpoint(sc));
|
||||
@ -3733,7 +3728,7 @@ bnx_rx_intr(struct bnx_softc *sc)
|
||||
&sw_chain_prod, &sw_prod_bseq)) {
|
||||
DBRUNIF(1, bnx_breakpoint(sc));
|
||||
panic("%s: Can't reuse RX mbuf!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
device_xname(sc->bnx_dev));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -3756,7 +3751,8 @@ bnx_rx_intr(struct bnx_softc *sc)
|
||||
&sw_chain_prod, &sw_prod_bseq)) {
|
||||
DBRUNIF(1, bnx_breakpoint(sc));
|
||||
panic("%s: Double mbuf allocation "
|
||||
"failure!", sc->bnx_dev.dv_xname);
|
||||
"failure!",
|
||||
device_xname(sc->bnx_dev));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -3951,16 +3947,16 @@ bnx_tx_intr(struct bnx_softc *sc)
|
||||
__func__, hw_tx_cons, sw_tx_cons, sw_tx_chain_cons);
|
||||
|
||||
DBRUNIF((sw_tx_chain_cons > MAX_TX_BD),
|
||||
aprint_error("%s: TX chain consumer out of range! "
|
||||
" 0x%04X > 0x%04X\n", sc->bnx_dev.dv_xname,
|
||||
sw_tx_chain_cons, (int)MAX_TX_BD); bnx_breakpoint(sc));
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"TX chain consumer out of range! 0x%04X > 0x%04X\n",
|
||||
sw_tx_chain_cons, (int)MAX_TX_BD); bnx_breakpoint(sc));
|
||||
|
||||
DBRUNIF(1, txbd = &sc->tx_bd_chain
|
||||
[TX_PAGE(sw_tx_chain_cons)][TX_IDX(sw_tx_chain_cons)]);
|
||||
|
||||
DBRUNIF((txbd == NULL),
|
||||
aprint_error("%s: Unexpected NULL tx_bd[0x%04X]!\n",
|
||||
sc->bnx_dev.dv_xname, sw_tx_chain_cons);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Unexpected NULL tx_bd[0x%04X]!\n", sw_tx_chain_cons);
|
||||
bnx_breakpoint(sc));
|
||||
|
||||
DBRUN(BNX_INFO_SEND, aprint_debug("%s: ", __func__);
|
||||
@ -3975,8 +3971,8 @@ bnx_tx_intr(struct bnx_softc *sc)
|
||||
/* Validate that this is the last tx_bd. */
|
||||
DBRUNIF((!(txbd->tx_bd_vlan_tag_flags &
|
||||
TX_BD_FLAGS_END)),
|
||||
aprint_error("%s: tx_bd END flag not set but "
|
||||
"txmbuf == NULL!\n", sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"tx_bd END flag not set but txmbuf == NULL!\n");
|
||||
bnx_breakpoint(sc));
|
||||
|
||||
DBRUN(BNX_INFO_SEND,
|
||||
@ -4019,9 +4015,9 @@ bnx_tx_intr(struct bnx_softc *sc)
|
||||
/* Clear the tx hardware queue full flag. */
|
||||
if ((sc->used_tx_bd + BNX_TX_SLACK_SPACE) < USABLE_TX_BD) {
|
||||
DBRUNIF((ifp->if_flags & IFF_OACTIVE),
|
||||
aprint_debug("%s: TX chain is open for business! Used "
|
||||
"tx_bd = %d\n", sc->bnx_dev.dv_xname,
|
||||
sc->used_tx_bd));
|
||||
aprint_debug_dev(sc->bnx_dev,
|
||||
"TX chain is open for business! Used tx_bd = %d\n",
|
||||
sc->used_tx_bd));
|
||||
ifp->if_flags &= ~IFF_OACTIVE;
|
||||
}
|
||||
|
||||
@ -4196,8 +4192,8 @@ bnx_tx_encap(struct bnx_softc *sc, struct mbuf **m_head)
|
||||
/* Map the mbuf into our DMA address space. */
|
||||
error = bus_dmamap_load_mbuf(sc->bnx_dmatag, map, m0, BUS_DMA_NOWAIT);
|
||||
if (error != 0) {
|
||||
aprint_error("%s: Error mapping mbuf into TX chain!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Error mapping mbuf into TX chain!\n");
|
||||
m_freem(m0);
|
||||
*m_head = NULL;
|
||||
return (error);
|
||||
@ -4450,8 +4446,7 @@ bnx_watchdog(struct ifnet *ifp)
|
||||
DBRUN(BNX_WARN_SEND, bnx_dump_driver_state(sc);
|
||||
bnx_dump_status_block(sc));
|
||||
|
||||
aprint_error("%s: Watchdog timeout -- resetting!\n",
|
||||
sc->bnx_dev.dv_xname);
|
||||
aprint_error_dev(sc->bnx_dev, "Watchdog timeout -- resetting!\n");
|
||||
|
||||
/* DBRUN(BNX_FATAL, bnx_breakpoint(sc)); */
|
||||
|
||||
@ -4479,6 +4474,9 @@ bnx_intr(void *xsc)
|
||||
u_int32_t status_attn_bits;
|
||||
|
||||
sc = xsc;
|
||||
if (!device_is_active(sc->bnx_dev))
|
||||
return 0;
|
||||
|
||||
ifp = &sc->ethercom.ec_if;
|
||||
|
||||
DBRUNIF(1, sc->interrupts_generated++);
|
||||
@ -4523,8 +4521,8 @@ bnx_intr(void *xsc)
|
||||
~STATUS_ATTN_BITS_LINK_STATE))) {
|
||||
DBRUN(1, sc->unexpected_attentions++);
|
||||
|
||||
aprint_error("%s: Fatal attention detected: 0x%08X\n",
|
||||
sc->bnx_dev.dv_xname,
|
||||
aprint_error_dev(sc->bnx_dev,
|
||||
"Fatal attention detected: 0x%08X\n",
|
||||
sc->status_block->status_attn_bits);
|
||||
|
||||
DBRUN(BNX_FATAL,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: if_bnxreg.h,v 1.2 2007/04/09 14:23:16 bouyer Exp $ */
|
||||
/* $NetBSD: if_bnxreg.h,v 1.3 2007/12/26 04:06:29 dyoung Exp $ */
|
||||
/* $OpenBSD: if_bnxreg.h,v 1.17 2006/11/20 21:26:27 brad Exp $ */
|
||||
|
||||
/*-
|
||||
@ -148,8 +148,7 @@
|
||||
/* Print a message based on the logging level and code path. */
|
||||
#define DBPRINT(sc, level, format, args...) \
|
||||
if (BNX_LOG_MSG(level)) { \
|
||||
aprint_debug("%s: " format, \
|
||||
sc->bnx_dev.dv_xname, ## args); \
|
||||
aprint_debug_dev(sc->bnx_dev, format, ## args); \
|
||||
}
|
||||
|
||||
/* Runs a particular command based on the logging level and code path. */
|
||||
@ -664,7 +663,7 @@ struct flash_spec {
|
||||
/****************************************************************************/
|
||||
/* Convenience definitions. */
|
||||
/****************************************************************************/
|
||||
#define BNX_PRINTF(sc, fmt, args...) aprint_error("%s: " fmt, sc->bnx_dev.dv_xname, ##args)
|
||||
#define BNX_PRINTF(sc, fmt, args...) aprint_error_dev(sc->bnx_dev, fmt, ##args)
|
||||
|
||||
#define REG_WR(sc, reg, val) bus_space_write_4(sc->bnx_btag, sc->bnx_bhandle, reg, val)
|
||||
#define REG_WR16(sc, reg, val) bus_space_write_2(sc->bnx_btag, sc->bnx_bhandle, reg, val)
|
||||
@ -4591,7 +4590,7 @@ struct fw_info {
|
||||
|
||||
struct bnx_softc
|
||||
{
|
||||
struct device bnx_dev; /* Parent device handle */
|
||||
device_t bnx_dev;
|
||||
struct ethercom ethercom;
|
||||
struct pci_attach_args bnx_pa;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user