From owner-svn-src-all@freebsd.org Wed Sep 5 21:05:17 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A759AFFCEA4; Wed, 5 Sep 2018 21:05:17 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5D89F7326E; Wed, 5 Sep 2018 21:05:17 +0000 (UTC) (envelope-from marius@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3A4B32B053; Wed, 5 Sep 2018 21:05:17 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w85L5HKR069449; Wed, 5 Sep 2018 21:05:17 GMT (envelope-from marius@FreeBSD.org) Received: (from marius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w85L5HsN069448; Wed, 5 Sep 2018 21:05:17 GMT (envelope-from marius@FreeBSD.org) Message-Id: <201809052105.w85L5HsN069448@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: marius set sender to marius@FreeBSD.org using -f From: Marius Strobl Date: Wed, 5 Sep 2018 21:05:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r338479 - stable/11/sys/dev/sdhci X-SVN-Group: stable-11 X-SVN-Commit-Author: marius X-SVN-Commit-Paths: stable/11/sys/dev/sdhci X-SVN-Commit-Revision: 338479 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.27 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: Wed, 05 Sep 2018 21:05:17 -0000 Author: marius Date: Wed Sep 5 21:05:16 2018 New Revision: 338479 URL: https://svnweb.freebsd.org/changeset/base/338479 Log: MFC: r338261 - According to section 2.2.5 of the SDHCI specification version 4.20, SDHCI_TRNS_ACMD12 is to be set only for multiple-block read/write commands without data length information, so don't unconditionally set this bit. The result matches what e. g. Linux does. - Section 2.2.19 of the SDHCI specification version 4.20 states that SDHCI_ACMD12_ERR should be only valid if SDHCI_INT_ACMD12ERR is set and hardware may clear SDHCI_ACMD12_ERR when SDHCI_INT_ACMD12ERR is cleared (differing silicon behavior is specifically allowed, though). Thus, read SDHCI_ACMD12_ERR before clearing SDHCI_INT_ACMD12ERR. While at it, use the 16-bit accessor rather than the 32-bit one for reading the 16-bit SDHCI_ACMD12_ERR. - SDHCI_INT_TUNEERR isn't one of the ROC bits in SDHCI_INT_STATUS so clear it explicitly. - Add missing prototypes and sort them. Modified: stable/11/sys/dev/sdhci/sdhci.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/sdhci/sdhci.c ============================================================================== --- stable/11/sys/dev/sdhci/sdhci.c Wed Sep 5 20:51:53 2018 (r338478) +++ stable/11/sys/dev/sdhci/sdhci.c Wed Sep 5 21:05:16 2018 (r338479) @@ -80,17 +80,37 @@ SYSCTL_INT(_hw_sdhci, OID_AUTO, quirk_set, CTLFLAG_RWT #define WR_MULTI_4(slot, off, ptr, count) \ SDHCI_WRITE_MULTI_4((slot)->bus, (slot), (off), (ptr), (count)) +static void sdhci_acmd_irq(struct sdhci_slot *slot, uint16_t acmd_err); static void sdhci_card_poll(void *arg); static void sdhci_card_task(void *arg, int pending); +static void sdhci_cmd_irq(struct sdhci_slot *slot, uint32_t intmask); +static void sdhci_data_irq(struct sdhci_slot *slot, uint32_t intmask); static int sdhci_exec_tuning(struct sdhci_slot *slot, bool reset); +static void sdhci_handle_card_present_locked(struct sdhci_slot *slot, + bool is_present); +static void sdhci_finish_command(struct sdhci_slot *slot); +static void sdhci_init(struct sdhci_slot *slot); +static void sdhci_read_block_pio(struct sdhci_slot *slot); +static void sdhci_req_done(struct sdhci_slot *slot); static void sdhci_req_wakeup(struct mmc_request *req); +static void sdhci_reset(struct sdhci_slot *slot, uint8_t mask); static void sdhci_retune(void *arg); static void sdhci_set_clock(struct sdhci_slot *slot, uint32_t clock); +static void sdhci_set_power(struct sdhci_slot *slot, u_char power); +static void sdhci_set_transfer_mode(struct sdhci_slot *slot, + struct mmc_data *data); static void sdhci_start(struct sdhci_slot *slot); +static void sdhci_timeout(void *arg); +static void sdhci_start_command(struct sdhci_slot *slot, + struct mmc_command *cmd); static void sdhci_start_data(struct sdhci_slot *slot, struct mmc_data *data); +static void sdhci_write_block_pio(struct sdhci_slot *slot); +static void sdhci_transfer_pio(struct sdhci_slot *slot); /* helper routines */ static void sdhci_dumpregs(struct sdhci_slot *slot); +static void sdhci_getaddr(void *arg, bus_dma_segment_t *segs, int nsegs, + int error); static int slot_printf(struct sdhci_slot *slot, const char * fmt, ...) __printflike(2, 3); static uint32_t sdhci_tuning_intmask(struct sdhci_slot *slot); @@ -1433,12 +1453,14 @@ sdhci_set_transfer_mode(struct sdhci_slot *slot, struc return; mode = SDHCI_TRNS_BLK_CNT_EN; - if (data->len > 512) + if (data->len > 512) { mode |= SDHCI_TRNS_MULTI; + if (__predict_true(slot->req->stop && + !(slot->quirks & SDHCI_QUIRK_BROKEN_AUTO_STOP))) + mode |= SDHCI_TRNS_ACMD12; + } if (data->flags & MMC_DATA_READ) mode |= SDHCI_TRNS_READ; - if (slot->req->stop && !(slot->quirks & SDHCI_QUIRK_BROKEN_AUTO_STOP)) - mode |= SDHCI_TRNS_ACMD12; if (slot->flags & SDHCI_USE_DMA) mode |= SDHCI_TRNS_DMA; @@ -1957,18 +1979,16 @@ done: } static void -sdhci_acmd_irq(struct sdhci_slot *slot) +sdhci_acmd_irq(struct sdhci_slot *slot, uint16_t acmd_err) { - uint16_t err; - err = RD4(slot, SDHCI_ACMD12_ERR); if (!slot->curcmd) { slot_printf(slot, "Got AutoCMD12 error 0x%04x, but " - "there is no active command.\n", err); + "there is no active command.\n", acmd_err); sdhci_dumpregs(slot); return; } - slot_printf(slot, "Got AutoCMD12 error 0x%04x\n", err); + slot_printf(slot, "Got AutoCMD12 error 0x%04x\n", acmd_err); sdhci_reset(slot, SDHCI_RESET_CMD); } @@ -1976,6 +1996,7 @@ void sdhci_generic_intr(struct sdhci_slot *slot) { uint32_t intmask, present; + uint16_t val16; SDHCI_LOCK(slot); /* Read slot interrupt status. */ @@ -1989,6 +2010,7 @@ sdhci_generic_intr(struct sdhci_slot *slot) /* Handle tuning error interrupt. */ if (__predict_false(intmask & SDHCI_INT_TUNEERR)) { + WR4(slot, SDHCI_INT_STATUS, SDHCI_INT_TUNEERR); slot_printf(slot, "Tuning error indicated\n"); slot->retune_req |= SDHCI_RETUNE_REQ_RESET; if (slot->curcmd) { @@ -2026,8 +2048,10 @@ sdhci_generic_intr(struct sdhci_slot *slot) } /* Handle AutoCMD12 error interrupt. */ if (intmask & SDHCI_INT_ACMD12ERR) { + /* Clearing SDHCI_INT_ACMD12ERR may clear SDHCI_ACMD12_ERR. */ + val16 = RD2(slot, SDHCI_ACMD12_ERR); WR4(slot, SDHCI_INT_STATUS, SDHCI_INT_ACMD12ERR); - sdhci_acmd_irq(slot); + sdhci_acmd_irq(slot, val16); } /* Handle bus power interrupt. */ if (intmask & SDHCI_INT_BUS_POWER) {