From nobody Thu Oct 05 15:35:10 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4S1bGk68qqz4vnX2; Thu, 5 Oct 2023 15:35:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4S1bGk5c6Yz4dQ3; Thu, 5 Oct 2023 15:35:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696520110; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=y3eRb1/0jKw2wsws9XRaB3wKt6EYgnMfaPl4iNnyejE=; b=W8iWVLWtu1C6nsRzg+9BBDkHzm4Fhpd6ItvKKXbMKa8fiqiOTxX3ZERTLWEeZwI+qwseqs GWEU174VDEnDmtjxcBuJ1rHhkDGzXfViKLhu08TtKeHeiy3tFItV6M2b8s4DNj6yBWvh4X rkgfW0hTzdLBS0kQvZDZIMwGiNCh4cG/dpawCOX6kkWDBNGtmey7pg/4qGXhKKhzu02Evf RpVZuYs5FoiONYuk0pJMt0V7MhGPooCtm6N3+0zkOUkoyh8DsPk+m33jfS/Ct/zmOTEoMG 7v+bDbG2dNcZDgcldIJ0R8Je2UkFX9mMHSg6FA/lhmCWpyL0cZw/H+5EH1CmWQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696520110; a=rsa-sha256; cv=none; b=PCuQ66GZYm9Qtds2GKqe4RlX8lL7S2T9OjxDmW+JFXIdTqIKTRROxeyJrC4QmbUd6Me1Yt h3p90EK/GJCxwgmA3LBN1WU2xTqOnxsJXoiHN3/B49jtpJfgO/LD8GqI3lBxzppgaER+Zw sq0v6lnKwu/qSLPpkiTZe2k29bXSZJYvKoGeaIrAAI9ypx0zyKh35dxKJDcco0fnu5P3NK gfkVApB35PBtbCnxmvAslPaCMH/OHZtYSN0csannpdEnhyQmLOZw+9XLX7BUqtlc6Z6ViX H+D80JMVXZTwKHx2IvYpv4dWAp7AicTPuMhLzE1dG0mzihPfkMg7X/uZl8Y75g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696520110; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=y3eRb1/0jKw2wsws9XRaB3wKt6EYgnMfaPl4iNnyejE=; b=jA4e2tXA4wPSAFpESC63crvPeCDsmMGvV2Io6MEQyRNb4gEpaOJuBJg3eIoSAWgvfn9wDA RoOhw9X7kZCIsPvwcvecNW64GUjlG2X/E3UR6Dx3rPmeX5/TA1eaOoikgJUGfH/OP+91jT PpZFPSpdSpoxq8yvhYKL5MaGutSUw+mYBlYhAynld1RZfzSOoZch+EgmTf4uNRQ1gz3uR0 CvFaz1jmfdo6unX1y5rx2zPq694hnDYIcx5Os04Ph18G4oiRpAJfgt8HGb8r94sUyTnlI2 JMu/g6GenubzOh4X1l+t7pcj2xvRuTbNvenQc13Q4X2ZMyuCKVleHM7Zzo5c0Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4S1bGk4hnsz1QCW; Thu, 5 Oct 2023 15:35:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 395FZA4U012894; Thu, 5 Oct 2023 15:35:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 395FZAkY012891; Thu, 5 Oct 2023 15:35:10 GMT (envelope-from git) Date: Thu, 5 Oct 2023 15:35:10 GMT Message-Id: <202310051535.395FZAkY012891@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: 363b7c39fbad - main - dwc: Move the dma reset code in dwc1000_dma.c List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 363b7c39fbad7c03f46e24bb4e435fad5cb56aa7 Auto-Submitted: auto-generated The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=363b7c39fbad7c03f46e24bb4e435fad5cb56aa7 commit 363b7c39fbad7c03f46e24bb4e435fad5cb56aa7 Author: Emmanuel Vadot AuthorDate: 2023-10-04 05:55:11 +0000 Commit: Emmanuel Vadot CommitDate: 2023-10-05 15:34:40 +0000 dwc: Move the dma reset code in dwc1000_dma.c No functional changes intended --- sys/dev/dwc/dwc1000_core.h | 1 + sys/dev/dwc/dwc1000_dma.c | 24 +++++++++++++++++++++++- sys/dev/dwc/dwc1000_dma.h | 1 + sys/dev/dwc/if_dwc.c | 21 +++++---------------- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/sys/dev/dwc/dwc1000_core.h b/sys/dev/dwc/dwc1000_core.h index cb7d1f3946e9..ade5270e25b1 100644 --- a/sys/dev/dwc/dwc1000_core.h +++ b/sys/dev/dwc/dwc1000_core.h @@ -34,6 +34,7 @@ int dwc1000_miibus_read_reg(device_t dev, int phy, int reg); int dwc1000_miibus_write_reg(device_t dev, int phy, int reg, int val); void dwc1000_miibus_statchg(device_t dev); void dwc1000_core_setup(struct dwc_softc *sc); +int dwc1000_core_reset(struct dwc_softc *sc); void dwc1000_enable_mac(struct dwc_softc *sc, bool enable); void dwc1000_enable_csum_offload(struct dwc_softc *sc); void dwc1000_setup_rxfilter(struct dwc_softc *sc); diff --git a/sys/dev/dwc/dwc1000_dma.c b/sys/dev/dwc/dwc1000_dma.c index cdfd24afd574..25916404bb63 100644 --- a/sys/dev/dwc/dwc1000_dma.c +++ b/sys/dev/dwc/dwc1000_dma.c @@ -61,7 +61,7 @@ #include #define WATCHDOG_TIMEOUT_SECS 5 - +#define DMA_RESET_TIMEOUT 100 /* TX descriptors - TDESC0 is almost unified */ #define TDESC0_OWN (1U << 31) @@ -598,6 +598,28 @@ dma1000_stop(struct dwc_softc *sc) WRITE4(sc, OPERATION_MODE, reg); } +int +dma1000_reset(struct dwc_softc *sc) +{ + uint32_t reg; + int i; + + reg = READ4(sc, BUS_MODE); + reg |= (BUS_MODE_SWR); + WRITE4(sc, BUS_MODE, reg); + + for (i = 0; i < DMA_RESET_TIMEOUT; i++) { + if ((READ4(sc, BUS_MODE) & BUS_MODE_SWR) == 0) + break; + DELAY(10); + } + if (i >= DMA_RESET_TIMEOUT) { + return (ENXIO); + } + + return (0); +} + /* * Create the bus_dma resources */ diff --git a/sys/dev/dwc/dwc1000_dma.h b/sys/dev/dwc/dwc1000_dma.h index 96a98c2d6d51..f0d22a67617f 100644 --- a/sys/dev/dwc/dwc1000_dma.h +++ b/sys/dev/dwc/dwc1000_dma.h @@ -46,6 +46,7 @@ int dma1000_init(struct dwc_softc *sc); void dma1000_free(struct dwc_softc *sc); void dma1000_start(struct dwc_softc *sc); void dma1000_stop(struct dwc_softc *sc); +int dma1000_reset(struct dwc_softc *sc); int dma1000_setup_txbuf(struct dwc_softc *sc, int idx, struct mbuf **mp); void dma1000_txfinish_locked(struct dwc_softc *sc); void dma1000_rxfinish_locked(struct dwc_softc *sc); diff --git a/sys/dev/dwc/if_dwc.c b/sys/dev/dwc/if_dwc.c index 0df99a7c205c..a3ce32c95cb9 100644 --- a/sys/dev/dwc/if_dwc.c +++ b/sys/dev/dwc/if_dwc.c @@ -78,8 +78,6 @@ #include "gpio_if.h" #include "miibus_if.h" -#define MAC_RESET_TIMEOUT 100 - static struct resource_spec dwc_spec[] = { { SYS_RES_MEMORY, 0, RF_ACTIVE }, { SYS_RES_IRQ, 0, RF_ACTIVE }, @@ -499,7 +497,7 @@ dwc_attach(device_t dev) uint8_t macaddr[ETHER_ADDR_LEN]; struct dwc_softc *sc; if_t ifp; - int error, i; + int error; uint32_t reg; uint32_t txpbl, rxpbl, pbl; bool nopblx8 = false; @@ -581,19 +579,10 @@ dwc_attach(device_t dev) } /* Reset */ - reg = READ4(sc, BUS_MODE); - reg |= (BUS_MODE_SWR); - WRITE4(sc, BUS_MODE, reg); - - for (i = 0; i < MAC_RESET_TIMEOUT; i++) { - if ((READ4(sc, BUS_MODE) & BUS_MODE_SWR) == 0) - break; - DELAY(10); - } - if (i >= MAC_RESET_TIMEOUT) { - device_printf(sc->dev, "Can't reset DWC.\n"); - bus_release_resources(dev, dwc_spec, sc->res); - return (ENXIO); + if ((error = dma1000_reset(sc)) != 0) { + device_printf(sc->dev, "Can't reset DMA controller.\n"); + bus_release_resources(sc->dev, dwc_spec, sc->res); + return (error); } reg = BUS_MODE_USP;