From owner-svn-src-all@freebsd.org Mon Sep 11 10:41:43 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3E825E036A7; Mon, 11 Sep 2017 10:41:43 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1588B7FBCC; Mon, 11 Sep 2017 10:41:43 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BAfgJ8074746; Mon, 11 Sep 2017 10:41:42 GMT (envelope-from mw@FreeBSD.org) Received: (from mw@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BAfgWx074745; Mon, 11 Sep 2017 10:41:42 GMT (envelope-from mw@FreeBSD.org) Message-Id: <201709111041.v8BAfgWx074745@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mw set sender to mw@FreeBSD.org using -f From: Marcin Wojtas Date: Mon, 11 Sep 2017 10:41:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323432 - head/sys/dev/usb/controller X-SVN-Group: head X-SVN-Commit-Author: mw X-SVN-Commit-Paths: head/sys/dev/usb/controller X-SVN-Commit-Revision: 323432 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 10:41:43 -0000 Author: mw Date: Mon Sep 11 10:41:42 2017 New Revision: 323432 URL: https://svnweb.freebsd.org/changeset/base/323432 Log: Improve HW type checking in mv_ehci driver This patch adds hwtype parameter which keeps information about hardware revision of Marvell EHCI controller. It allows to replace multiple calls to ofw_bus_is_compatible with comparing hwtype value during driver initialization. Submitted by: Patryk Duda Suggested by: ian Obtained from: Semihalf Sponsored by: Semihalf Modified: head/sys/dev/usb/controller/ehci_mv.c Modified: head/sys/dev/usb/controller/ehci_mv.c ============================================================================== --- head/sys/dev/usb/controller/ehci_mv.c Mon Sep 11 08:48:36 2017 (r323431) +++ head/sys/dev/usb/controller/ehci_mv.c Mon Sep 11 10:41:42 2017 (r323432) @@ -101,11 +101,17 @@ static void *ih_err; #define MV_USB_HOST_OVERFLOW (1 << 2) #define MV_USB_DEVICE_UNDERFLOW (1 << 3) +enum mv_ehci_hwtype { + HWTYPE_NONE = 0, + HWTYPE_MV_EHCI_V1, + HWTYPE_MV_EHCI_V2, +}; + static struct ofw_compat_data compat_data[] = { - {"mrvl,usb-ehci", true}, - {"marvell,orion-ehci", true}, - {"marvell,armada-3700-ehci", true}, - {NULL, false} + {"mrvl,usb-ehci", HWTYPE_MV_EHCI_V1}, + {"marvell,orion-ehci", HWTYPE_MV_EHCI_V2}, + {"marvell,armada-3700-ehci", HWTYPE_MV_EHCI_V2}, + {NULL, HWTYPE_NONE} }; static void @@ -139,6 +145,7 @@ static int mv_ehci_attach(device_t self) { ehci_softc_t *sc = device_get_softc(self); + enum mv_ehci_hwtype hwtype; bus_space_handle_t bsh; int err; int rid; @@ -149,6 +156,12 @@ mv_ehci_attach(device_t self) sc->sc_bus.devices_max = EHCI_MAX_DEVICES; sc->sc_bus.dma_bits = 32; + hwtype = ofw_bus_search_compatible(self, compat_data)->ocd_data; + if (hwtype == HWTYPE_NONE) { + device_printf(self, "Wrong HW type flag detected\n"); + return (ENXIO); + } + /* get all DMA memory */ if (usb_bus_mem_alloc_all(&sc->sc_bus, USB_GET_DMA_TAG(self), &ehci_iterate_hw_softc)) { @@ -177,8 +190,7 @@ mv_ehci_attach(device_t self) device_get_name(self)); rid = 0; - if (!(ofw_bus_is_compatible(self, "marvell,orion-ehci") || - ofw_bus_is_compatible(self, "marvell,armada-3700-ehci"))) { + if (hwtype == HWTYPE_MV_EHCI_V1) { irq_err = bus_alloc_resource_any(self, SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE); if (irq_err == NULL) { @@ -211,8 +223,7 @@ mv_ehci_attach(device_t self) sprintf(sc->sc_vendor, "Marvell"); - if (!(ofw_bus_is_compatible(self, "marvell,orion-ehci") || - ofw_bus_is_compatible(self, "marvell,armada-3700-ehci"))) { + if (hwtype == HWTYPE_MV_EHCI_V1) { err = bus_setup_intr(self, irq_err, INTR_TYPE_BIO, err_intr, NULL, sc, &ih_err); if (err) {