From owner-freebsd-bugs@FreeBSD.ORG Thu Sep 11 19:40:23 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A760216A4BF for ; Thu, 11 Sep 2003 19:40:23 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1973A43FF3 for ; Thu, 11 Sep 2003 19:40:22 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h8C2eLUp065157 for ; Thu, 11 Sep 2003 19:40:21 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h8C2eLfp065156; Thu, 11 Sep 2003 19:40:21 -0700 (PDT) Resent-Date: Thu, 11 Sep 2003 19:40:21 -0700 (PDT) Resent-Message-Id: <200309120240.h8C2eLfp065156@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Edwin Groothuis Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7531016A4BF for ; Thu, 11 Sep 2003 19:38:02 -0700 (PDT) Received: from mag.barnet.com.au (mag.barnet.com.au [218.185.88.3]) by mx1.FreeBSD.org (Postfix) with ESMTP id 26AB543FDF for ; Thu, 11 Sep 2003 19:38:01 -0700 (PDT) (envelope-from edwin@mavetju.org) Received: from extmail.barnet.com.au (tim.direct.int.barnet.com.au [10.10.10.2]) by mag.barnet.com.au (Postfix) with ESMTP id A2CED4A3E; Fri, 12 Sep 2003 12:37:58 +1000 (EST) Received: from k7.mavetju (tim.barnet.com.au [218.185.88.1]) by extmail.barnet.com.au (Postfix) with ESMTP id 244C91E18; Fri, 12 Sep 2003 12:37:53 +1000 (EST) Received: by k7.mavetju (Postfix, from userid 1001) id EDA7A6A7101; Fri, 12 Sep 2003 12:37:51 +1000 (EST) Message-Id: <20030912023751.EDA7A6A7101@k7.mavetju> Date: Fri, 12 Sep 2003 12:37:51 +1000 (EST) From: Edwin Groothuis To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 cc: stu@ipng.org.uk Subject: kern/56726: [PATCH] patches for if_bfe (Broadcom BCM4401 10/100baseTX PHY) under FreeBSD 4.8 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Edwin Groothuis List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Sep 2003 02:40:23 -0000 >Number: 56726 >Category: kern >Synopsis: [PATCH] patches for if_bfe (Broadcom BCM4401 10/100baseTX PHY) under FreeBSD 4.8 >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Thu Sep 11 19:40:21 PDT 2003 >Closed-Date: >Last-Modified: >Originator: Edwin Groothuis >Release: FreeBSD 4.8-RELEASE i386 >Organization: - >Environment: System: FreeBSD k7.mavetju 4.8-RELEASE FreeBSD 4.8-RELEASE #0: Sun Aug 17 16:04:25 EST 2003 edwin@k7.mavetju:/usr/src/sys/compile/k7 i386 >Description: Thanks to Stuart Walsh for the driver BCM4401 device on -current. This patch will add support to get it running under 4.8 >How-To-Repeat: >Fix: Since 4.9 is already in a freeze and I don't think this will ever be MFCd to -STABLE, I would like to just add these patches to the source file so it is recorded and it can be made in a port (or package) for 4.10 (if ever) comes out. Some comments: o BFE_VAR(s) is used to create a variable under 4.8 but not under -current. The other way to do it is to just add "int s;" everywhere and get a million of unused variable warnings when compiling it under -current. An other way is to add a lot of #if (check for proper version)/#endif around the "int s" which will even add more lines to it. o During loading of the module I get the error: /kernel: module_register: module miibus/ukphy already exists! /kernel: linker_file_sysinit "miibus.ko" failed to register! 17 but that one only happens the first time and the module loads without problems. I don't know what it is about. --- if_bfereg.h-1.1 Fri Sep 12 12:05:12 2003 +++ if_bfereg.h Fri Sep 12 12:34:47 2003 @@ -422,8 +422,23 @@ #define BFE_AND(sc, name, val) \ CSR_WRITE_4(sc, name, CSR_READ_4(sc, name) & val) +#if __FreeBSD_version > 500000 #define BFE_LOCK(scp) mtx_lock(&sc->bfe_mtx) #define BFE_UNLOCK(scp) mtx_unlock(&sc->bfe_mtx) +#define BFE_VAR(s) +#else +#define BFE_LOCK(scp) s=splimp() +#define BFE_UNLOCK(scp) splx(s) +#define BFE_VAR(s) int s +#define BPF_MTAP(_ifp,_m) do { \ + if ((_ifp)->if_bpf) \ + bpf_mtap((_ifp), (_m)); \ + } while (0) +#define ETHER_ALIGN 2 +#define mtx_destroy(a) +#define mtx_init(a,b,c,d) +#define device_is_attached(a) 1 +#endif #define BFE_INC(x, y) (x) = ((x) == ((y)-1)) ? 0 : (x)+1 @@ -484,7 +499,9 @@ struct bfe_desc *bfe_tx_list, *bfe_rx_list; struct bfe_data bfe_tx_ring[BFE_TX_LIST_CNT]; /* XXX */ struct bfe_data bfe_rx_ring[BFE_RX_LIST_CNT]; /* XXX */ +#if __FreeBSD_version > 500000 struct mtx bfe_mtx; +#endif u_int32_t bfe_flags; u_int32_t bfe_imask; u_int32_t bfe_dma_offset; --- if_bfe.c-1.2 Fri Sep 12 12:05:12 2003 +++ if_bfe.c Fri Sep 12 12:31:16 2003 @@ -1,6 +1,7 @@ /* * Copyright (c) 2003 Stuart Walsh * and Duncan Barclay + * Modifications for FreeBSD-stable by Edwin Groothuis */ /* @@ -28,7 +29,7 @@ #include -__FBSDID("$FreeBSD: /repoman/r/ncvs/src/sys/dev/bfe/if_bfe.c,v 1.2 2003/09/09 18:21:17 wpaul Exp $"); +FBSDID("$FreeBSD: /repoman/r/ncvs/src/sys/dev/bfe/if_bfe.c,v 1.2 2003/09/09 18:21:17 wpaul Exp $"); #include #include @@ -61,12 +62,19 @@ #include #include +#if __FreeBSD_version < 500000 +#include +#include +#endif + #include #include +#if __FreeBSD_version > 500000 #include "miidevs.h" #include #include +#endif #include @@ -205,14 +213,20 @@ BUS_SPACE_UNRESTRICTED, /* num of segments */ BUS_SPACE_MAXSIZE_32BIT, /* max segment size */ BUS_DMA_ALLOCNOW, /* flags */ +#if __FreeBSD_version > 500000 NULL, NULL, /* lockfunc, lockarg */ +#endif &sc->bfe_parent_tag); /* tag for TX ring */ error = bus_dma_tag_create(sc->bfe_parent_tag, BFE_TX_LIST_SIZE, BFE_TX_LIST_SIZE, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, BFE_TX_LIST_SIZE, 1, BUS_SPACE_MAXSIZE_32BIT, - 0, NULL, NULL, &sc->bfe_tx_tag); + 0, +#if __FreeBSD_version > 500000 + NULL, NULL, &sc->bfe_tx_tag); +#endif + &sc->bfe_tx_tag); if (error) { device_printf(dev, "could not allocate dma tag\n"); @@ -223,7 +237,11 @@ error = bus_dma_tag_create(sc->bfe_parent_tag, BFE_RX_LIST_SIZE, BFE_RX_LIST_SIZE, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, BFE_RX_LIST_SIZE, 1, BUS_SPACE_MAXSIZE_32BIT, - 0, NULL, NULL, &sc->bfe_rx_tag); + 0, +#if __FreeBSD_version > 500000 + NULL, NULL, /* lockfunc, lockarg */ +#endif + &sc->bfe_rx_tag); if (error) { device_printf(dev, "could not allocate dma tag\n"); @@ -233,7 +251,11 @@ /* tag for mbufs */ error = bus_dma_tag_create(sc->bfe_parent_tag, ETHER_ALIGN, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, MCLBYTES, - 1, BUS_SPACE_MAXSIZE_32BIT, 0, NULL, NULL, &sc->bfe_tag); + 1, BUS_SPACE_MAXSIZE_32BIT, 0, +#if __FreeBSD_version > 500000 + NULL, NULL, +#endif + &sc->bfe_tag); if (error) { device_printf(dev, "could not allocate dma tag\n"); @@ -301,6 +323,7 @@ int unit, error = 0, rid; sc = device_get_softc(dev); + mtx_init(&sc->bfe_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, MTX_DEF | MTX_RECURSE); @@ -394,7 +417,11 @@ goto fail; } +#if __FreeBSD_version > 500000 ether_ifattach(ifp, sc->arpcom.ac_enaddr); +#else + ether_ifattach(ifp, ETHER_BPF_SUPPORTED); +#endif callout_handle_init(&sc->bfe_stat_ch); /* @@ -419,6 +446,7 @@ { struct bfe_softc *sc; struct ifnet *ifp; + BFE_VAR(s); sc = device_get_softc(dev); @@ -429,7 +457,11 @@ if (device_is_attached(dev)) { bfe_stop(sc); +#if __FreeBSD_version > 500000 ether_ifdetach(ifp); +#else + ether_ifdetach(ifp, ETHER_BPF_SUPPORTED); +#endif } bfe_chip_reset(sc); @@ -453,6 +485,7 @@ bfe_shutdown(device_t dev) { struct bfe_softc *sc; + BFE_VAR(s); sc = device_get_softc(dev); BFE_LOCK(sc); @@ -640,6 +673,7 @@ bfe_clear_stats(struct bfe_softc *sc) { u_long reg; + BFE_VAR(s); BFE_LOCK(sc); @@ -656,6 +690,7 @@ bfe_resetphy(struct bfe_softc *sc) { u_int32_t val; + BFE_VAR(s); BFE_LOCK(sc); bfe_writephy(sc, 0, BMCR_RESET); @@ -673,6 +708,8 @@ static void bfe_chip_halt(struct bfe_softc *sc) { + BFE_VAR(s); + BFE_LOCK(sc); /* disable interrupts - not that it actually does..*/ CSR_WRITE_4(sc, BFE_IMASK, 0); @@ -692,6 +729,7 @@ bfe_chip_reset(struct bfe_softc *sc) { u_int32_t val; + BFE_VAR(s); BFE_LOCK(sc); @@ -864,6 +902,7 @@ CSR_WRITE_4(sc, BFE_CAM_CTRL, 0); bfe_cam_write(sc, sc->arpcom.ac_enaddr, i++); +#if __FreeBSD_version > 500000 if (ifp->if_flags & IFF_ALLMULTI) val |= BFE_RXCONF_ALLMULTI; else { @@ -875,6 +914,7 @@ i++); } } +#endif CSR_WRITE_4(sc, BFE_RXCONF, val); BFE_OR(sc, BFE_CAM_CTRL, BFE_CAM_ENABLE); @@ -988,6 +1028,7 @@ bfe_readphy(struct bfe_softc *sc, u_int32_t reg, u_int32_t *val) { int err; + BFE_VAR(s); BFE_LOCK(sc); /* Clear MII ISR */ @@ -1008,6 +1049,7 @@ bfe_writephy(struct bfe_softc *sc, u_int32_t reg, u_int32_t val) { int status; + BFE_VAR(s); BFE_LOCK(sc); CSR_WRITE_4(sc, BFE_EMAC_ISTAT, BFE_EMAC_INT_MII); @@ -1031,6 +1073,7 @@ bfe_setupphy(struct bfe_softc *sc) { u_int32_t val; + BFE_VAR(s); BFE_LOCK(sc); /* Enable activity LED */ @@ -1067,6 +1110,7 @@ { struct ifnet *ifp; int i, chipidx; + BFE_VAR(s); BFE_LOCK(sc); @@ -1112,6 +1156,7 @@ struct bfe_data *r; int cons; u_int32_t status, current, len, flags; + BFE_VAR(s); BFE_LOCK(sc); cons = sc->bfe_rx_cons; @@ -1154,8 +1199,12 @@ ifp->if_ipackets++; m->m_pkthdr.rcvif = ifp; - (*ifp->if_input)(ifp, m); +#if __FreeBSD_version > 500000 + (*ifp->if_input)(ifp, m); +#else + ether_input(ifp, NULL, m); +#endif BFE_INC(cons, BFE_RX_LIST_CNT); } sc->bfe_rx_cons = cons; @@ -1168,6 +1217,7 @@ struct bfe_softc *sc = xsc; struct ifnet *ifp; u_int32_t istat, imask, flag; + BFE_VAR(s); ifp = &sc->arpcom.ac_if; @@ -1231,6 +1281,7 @@ if(BFE_TX_LIST_CNT - sc->bfe_tx_cnt < 2) return(ENOBUFS); +#if __FreeBSD_version > 500000 /* * Count the number of frags in this chain to see if * we need to m_defrag. Since the descriptor list is shared @@ -1240,7 +1291,6 @@ for(m = m_head; m != NULL; m = m->m_next) chainlen++; - if ((chainlen > BFE_TX_LIST_CNT / 4) || ((BFE_TX_LIST_CNT - (chainlen + sc->bfe_tx_cnt)) < 2)) { m = m_defrag(m_head, M_DONTWAIT); @@ -1248,6 +1298,7 @@ return(ENOBUFS); m_head = m; } +#endif /* * Start packing the mbufs in this chain into @@ -1306,6 +1357,7 @@ struct bfe_softc *sc; struct mbuf *m_head = NULL; int idx; + BFE_VAR(s); sc = ifp->if_softc; idx = sc->bfe_tx_prod; @@ -1365,6 +1417,7 @@ { struct bfe_softc *sc = (struct bfe_softc*)xsc; struct ifnet *ifp = &sc->arpcom.ac_if; + BFE_VAR(s); BFE_LOCK(sc); @@ -1406,6 +1459,7 @@ { struct bfe_softc *sc; struct mii_data *mii; + BFE_VAR(s); sc = ifp->if_softc; @@ -1433,6 +1487,7 @@ { struct bfe_softc *sc = ifp->if_softc; struct mii_data *mii; + BFE_VAR(s); BFE_LOCK(sc); @@ -1451,6 +1506,7 @@ struct ifreq *ifr = (struct ifreq *) data; struct mii_data *mii; int error = 0; + BFE_VAR(s); BFE_LOCK(sc); @@ -1474,9 +1530,21 @@ mii = device_get_softc(sc->bfe_miibus); error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command); break; +#if __FreeBSD_version > 500000 default: error = ether_ioctl(ifp, command, data); break; +#else + case SIOCSIFADDR: + case SIOCGIFADDR: + case SIOCSIFMTU: + error = ether_ioctl(ifp, command, data); + break; + + default: + error = EINVAL; + break; +#endif } BFE_UNLOCK(sc); @@ -1487,6 +1555,7 @@ bfe_watchdog(struct ifnet *ifp) { struct bfe_softc *sc; + BFE_VAR(s); sc = ifp->if_softc; @@ -1507,6 +1576,7 @@ { struct bfe_softc *sc = xsc; struct mii_data *mii; + BFE_VAR(s); if (sc == NULL) return; @@ -1527,6 +1597,10 @@ if (!sc->bfe_link && mii->mii_media_status & IFM_ACTIVE && IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) sc->bfe_link++; +#ifdef FALSE + if (!sc->bfe_link) + sc->bfe_link++; +#endif BFE_UNLOCK(sc); } @@ -1539,6 +1613,7 @@ bfe_stop(struct bfe_softc *sc) { struct ifnet *ifp; + BFE_VAR(s); BFE_LOCK(sc); >Release-Note: >Audit-Trail: >Unformatted: