From patchwork Sat Jan 27 00:19:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 767085 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F86A17F4 for ; Sat, 27 Jan 2024 00:20:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314815; cv=none; b=kRhD6ZFMnBypDMG6IB4/Ix75RATOuVVgi3opca7ngbd8vtj+DKYA34Xxs82p9A/0PD0l4k5ozy920E/p8qtRh1HvQK3iH4zSW+tYWT4gi0ahNR6kapn57r6vEdhnY9lmgPq2qNFapteggcwuc0vndpKucbeVCgAN3MGCA5LighA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314815; c=relaxed/simple; bh=jja+9BUfY3p7IJ0UBkje+VXn//Mt2abUDD8oxOrr20c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=io4/AqKgeOgdH1mvOh9Ef2E9xJlJ/rmPxoMOyTGfWVwj2054zkARyEYOKz8FuvlRIVaAsjc/G2lsO4ns/ET0m/Fv6Y2hvN+n6E/MPTsJbZZCXuG4spHOjgAEnAjChYo2yAhPSvVzDlJMVRf345pTeplMKMT2to1Inqm36d1fbcs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=hWdWawAa; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="hWdWawAa" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-5102a877d50so601665e87.0 for ; Fri, 26 Jan 2024 16:20:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706314812; x=1706919612; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=b+qf6Kmkzij/J63a/y1MVzoBzMnJtm5VXzLHR9Dn/dQ=; b=hWdWawAaSaItzBtqKbpQEAMuqfjIm5T8WPLYY6pnPzEsZnbwgwa7fBCC+4eEB7Edmr pbAZd7Bt7XE0xgoh3KfWuwItO/+cQ8kfm9infUbwzazIDoW/EzY/FlT5KfkwfwlIPGAX CoagdjgykEN3txTbffYLGO7Ac9581EG4OOfGAfQxy0q2Oa/MjGM2W8Zykty71nFinhXK 2gOsiJraym3QeUL5UZzXMu8jSkas+v3MXfQXm9TVJ/xl748enJgde8c8Z/rp6pLPuaOE DpOdUJkWiTje7Iwc87R7DSLKd+foXPaOWYZHfWRv0TZo0vXd5oIpmU62VuuknYz99kyU 9mwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706314812; x=1706919612; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b+qf6Kmkzij/J63a/y1MVzoBzMnJtm5VXzLHR9Dn/dQ=; b=GzYXGFjXA/e4Er6/wadGPLyNlE78sxdll/r6m3AjBQP9Dm5lrFffgLxdLtykS8CMhx 7bWJjyWIm3E04trYxnGhLbMbaCtINRRXDYQnJIpXzctRfDD60K/lcBNoKjfQr+HPnCPD Mebd+ZjtXGYbs6X6gXllIePgjksHHu/Wd0+kUHyhzoDVYV372mGg1qtPQ/3AAFixou74 663FSEiDjrEkrWKqWof7lxivIJOUUzLb3b/ds38jQlnprNgxcApNSX+LFv1kMvKy5NEd fvoM5wGFT/Zyf2LoBtHO1GRi8tSlkqQmMqGdoaiPR9TaYps229HcXCKbvmTiylZkr44O 49tw== X-Gm-Message-State: AOJu0YyPQmRt+r0TPDzpKrgeCooxlici+/Kc0aBCPTZ9+Y9seczUm/xN WncMJIXOYFFLMwotroKXpTkX+NCEpYrVr12mp95XROxvrYe4Pj0wOBTiB6JYJFU= X-Google-Smtp-Source: AGHT+IGXujxtRX891ftx+e1FMFa5nxtOLkCUmc0pj5Kz6Y/AmfxBMocPdT5qL8vfQz+W0W7Du3/Qvw== X-Received: by 2002:a05:6512:48a:b0:50e:ca97:5afb with SMTP id v10-20020a056512048a00b0050eca975afbmr244799lfq.18.1706314811925; Fri, 26 Jan 2024 16:20:11 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x25-20020a19f619000000b0050e7f5cffa6sm325226lfe.273.2024.01.26.16.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 16:20:11 -0800 (PST) From: Linus Walleij Date: Sat, 27 Jan 2024 01:19:48 +0100 Subject: [PATCH v2 1/9] mmc: davinci_mmc: Use sg_miter for PIO Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240127-mmc-proper-kmap-v2-1-d8e732aa97d1@linaro.org> References: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> In-Reply-To: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> To: Christoph Hellwig , Jens Axboe , Ming Lei , Arnd Bergmann , Ulf Hansson , Nicolas Pitre , Aaro Koskinen , Adrian Hunter , Angelo Dureghello Cc: linux-mmc@vger.kernel.org, linux-block@vger.kernel.org, linux-omap@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 Use the scatterlist memory iterator instead of just dereferencing virtual memory using sg_virt(). This make highmem references work properly. Suggested-by: Christoph Hellwig Link: https://lore.kernel.org/linux-mmc/20240122073423.GA25859@lst.de/ Signed-off-by: Linus Walleij --- drivers/mmc/host/davinci_mmc.c | 61 +++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/drivers/mmc/host/davinci_mmc.c b/drivers/mmc/host/davinci_mmc.c index ee3b1a4e0848..c46577305138 100644 --- a/drivers/mmc/host/davinci_mmc.c +++ b/drivers/mmc/host/davinci_mmc.c @@ -180,12 +180,6 @@ struct mmc_davinci_host { #define DAVINCI_MMC_DATADIR_WRITE 2 unsigned char data_dir; - /* buffer is used during PIO of one scatterlist segment, and - * is updated along with buffer_bytes_left. bytes_left applies - * to all N blocks of the PIO transfer. - */ - u8 *buffer; - u32 buffer_bytes_left; u32 bytes_left; struct dma_chan *dma_tx; @@ -196,8 +190,8 @@ struct mmc_davinci_host { bool active_request; /* For PIO we walk scatterlists one segment at a time. */ + struct sg_mapping_iter sg_miter; unsigned int sg_len; - struct scatterlist *sg; /* Version of the MMC/SD controller */ u8 version; @@ -213,30 +207,24 @@ struct mmc_davinci_host { static irqreturn_t mmc_davinci_irq(int irq, void *dev_id); /* PIO only */ -static void mmc_davinci_sg_to_buf(struct mmc_davinci_host *host) -{ - host->buffer_bytes_left = sg_dma_len(host->sg); - host->buffer = sg_virt(host->sg); - if (host->buffer_bytes_left > host->bytes_left) - host->buffer_bytes_left = host->bytes_left; -} - static void davinci_fifo_data_trans(struct mmc_davinci_host *host, unsigned int n) { + struct sg_mapping_iter *sgm = &host->sg_miter; + size_t sglen; u8 *p; unsigned int i; - if (host->buffer_bytes_left == 0) { - host->sg = sg_next(host->data->sg); - mmc_davinci_sg_to_buf(host); + /* + * By adjusting sgm->consumed this will give a pointer to the + * current index into the sgm. + */ + if (!sg_miter_next(sgm)) { + dev_err(mmc_dev(host->mmc), "ran out of sglist prematurely\n"); + return; } - - p = host->buffer; - if (n > host->buffer_bytes_left) - n = host->buffer_bytes_left; - host->buffer_bytes_left -= n; - host->bytes_left -= n; + p = sgm->addr; + sglen = sgm->length; /* NOTE: we never transfer more than rw_threshold bytes * to/from the fifo here; there's no I/O overlap. @@ -261,7 +249,9 @@ static void davinci_fifo_data_trans(struct mmc_davinci_host *host, p = p + (n & 3); } } - host->buffer = p; + + sgm->consumed = n; + host->bytes_left -= n; } static void mmc_davinci_start_command(struct mmc_davinci_host *host, @@ -517,6 +507,7 @@ mmc_davinci_prepare_data(struct mmc_davinci_host *host, struct mmc_request *req) int fifo_lev = (rw_threshold == 32) ? MMCFIFOCTL_FIFOLEV : 0; int timeout; struct mmc_data *data = req->data; + unsigned int flags = SG_MITER_ATOMIC; /* Used from IRQ */ if (host->version == MMC_CTLR_VERSION_2) fifo_lev = (rw_threshold == 64) ? MMCFIFOCTL_FIFOLEV : 0; @@ -545,12 +536,14 @@ mmc_davinci_prepare_data(struct mmc_davinci_host *host, struct mmc_request *req) /* Configure the FIFO */ if (data->flags & MMC_DATA_WRITE) { + flags |= SG_MITER_FROM_SG; host->data_dir = DAVINCI_MMC_DATADIR_WRITE; writel(fifo_lev | MMCFIFOCTL_FIFODIR_WR | MMCFIFOCTL_FIFORST, host->base + DAVINCI_MMCFIFOCTL); writel(fifo_lev | MMCFIFOCTL_FIFODIR_WR, host->base + DAVINCI_MMCFIFOCTL); } else { + flags |= SG_MITER_TO_SG; host->data_dir = DAVINCI_MMC_DATADIR_READ; writel(fifo_lev | MMCFIFOCTL_FIFODIR_RD | MMCFIFOCTL_FIFORST, host->base + DAVINCI_MMCFIFOCTL); @@ -558,7 +551,6 @@ mmc_davinci_prepare_data(struct mmc_davinci_host *host, struct mmc_request *req) host->base + DAVINCI_MMCFIFOCTL); } - host->buffer = NULL; host->bytes_left = data->blocks * data->blksz; /* For now we try to use DMA whenever we won't need partial FIFO @@ -576,8 +568,7 @@ mmc_davinci_prepare_data(struct mmc_davinci_host *host, struct mmc_request *req) } else { /* Revert to CPU Copy */ host->sg_len = data->sg_len; - host->sg = host->data->sg; - mmc_davinci_sg_to_buf(host); + sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags); } } @@ -843,6 +834,8 @@ davinci_abort_data(struct mmc_davinci_host *host, struct mmc_data *data) { mmc_davinci_reset_ctrl(host, 1); mmc_davinci_reset_ctrl(host, 0); + if (!host->do_dma) + sg_miter_stop(&host->sg_miter); } static irqreturn_t mmc_davinci_sdio_irq(int irq, void *dev_id) @@ -919,11 +912,13 @@ static irqreturn_t mmc_davinci_irq(int irq, void *dev_id) if (qstatus & MMCST0_DATDNE) { /* All blocks sent/received, and CRC checks passed */ if (data != NULL) { - if ((host->do_dma == 0) && (host->bytes_left > 0)) { - /* if datasize < rw_threshold - * no RX ints are generated - */ - davinci_fifo_data_trans(host, host->bytes_left); + if (!host->do_dma) { + if (host->bytes_left > 0) + /* if datasize < rw_threshold + * no RX ints are generated + */ + davinci_fifo_data_trans(host, host->bytes_left); + sg_miter_stop(&host->sg_miter); } end_transfer = 1; data->bytes_xfered = data->blocks * data->blksz; From patchwork Sat Jan 27 00:19:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 767084 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB2B2257B for ; Sat, 27 Jan 2024 00:20:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314820; cv=none; b=d2oIAqx0gGSBlg1dCUjKqFAM1e44Zq2Asn7kqRyaZEPPprzlltbNv8RdHRPGzHiW5cSqX2DW11BF3NR/YEyzya8GdtztUN0wV3vFFOeur2JocM0TQy7PkLt/04HFik9pTJZo1tCFu8TPlomc8py+XLphoXMZX/3PqzojwOV+Jm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314820; c=relaxed/simple; bh=E9ziAqKRF7avg+9XAu41DqCMnZeKd+R+sbDJSS4jrKs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uMMphE5gPK/KgHOTEil/TUH3ekWyFVM6SElpx8bkf9EhKajdZOvX6IsuI6tVraw1iRWTDf3NIxrTkexDyVuw/G8erJ5mL2Xu1doFPMLDry6Kbn70rZxhBnCLWMhnwZgtZADu4RskeNrEA4V5skTjBXNgYQn/X8OrM3T0zKdEpqM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=emnVVWLe; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="emnVVWLe" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5101f2dfdadso1743403e87.2 for ; Fri, 26 Jan 2024 16:20:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706314814; x=1706919614; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=N5SahCLN1505rQ5cLqj1DAZZAA4U+IFMjOwfguXW3/Y=; b=emnVVWLeg/3uw0D7kDOuch6/gCpWAf6ndV4K4LdzZ0euGS/eUBi3wm0zFBLkkWZhcs 2s21lonvVDaMr2EZNprRN/VRd7ta7FYKfBkniU2TnjMpQKEXjoFTeh86V0Bk7Xq0Vv2y WVug8eifCUjXeVoZbOyREIVijrrWUe8iUC0x9vPvFjn8lyMQ1nnwFMJHkEaYSqt06kyR AW5VPt1C6h1PjU1M7+aAu4oYxHysvUB0DASsvX2Ue/aW2Qpp3WpI3jRJvzl/OQc/nH8L Y9tzy2YuqBL1EWbUs7vxVWX5PzYO1xlNzGykYl7KmI818V0ZKZcHunSjIL2wwfwzTA9f Zw4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706314814; x=1706919614; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N5SahCLN1505rQ5cLqj1DAZZAA4U+IFMjOwfguXW3/Y=; b=sdKo3NS1XHMu+kXSF1IduI4vE3CvrZyIGii9mwUs6nyZMyxSjGjSuWOeFMK1YOW6y3 3FfgawBWfQJlcxSnoL0vz9A1KISrwQ50IkZljWviuBCYOHBUz6lIM7ksT720XuymuUtx 0g5QWFnJ5Drf9ARWNW6rLN1qJ4q773VEItgR6bdpDXQDicA5GFbNz78pcIXtdi9GoQjX s7JoVx55LhFzGOgK+dNW0jLNzV4U8wUYcvjmWTKp+RwFaXIwhcaCN9IQZqihyFdEvveJ aPBToQzYweW/UCRpaLVJcxYn1lztGsUHs+LW/dtBCdW8oj3RsYYG70vnjEfBYJ0vEPaw QEOg== X-Gm-Message-State: AOJu0YwGpVTN+EVaV1oGKmsjO3ZbUP/KCjpfl5gflGI5qPip+b3saRNJ s/fJ6xrP75PTiK5o29UDzqttIqESYYzQw0BgkIqIXJGBnz6Ec8meeaLmIro0c3w= X-Google-Smtp-Source: AGHT+IFc5/iBp3Z+YfgOFibaw+mJcjoLiqn1ysw4Wwecz9Q0A3UtJBPMsKwdVvx3H7ibywtjZio/1w== X-Received: by 2002:a05:6512:3b0e:b0:50e:b23c:e37 with SMTP id f14-20020a0565123b0e00b0050eb23c0e37mr373430lfv.48.1706314813988; Fri, 26 Jan 2024 16:20:13 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x25-20020a19f619000000b0050e7f5cffa6sm325226lfe.273.2024.01.26.16.20.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 16:20:12 -0800 (PST) From: Linus Walleij Date: Sat, 27 Jan 2024 01:19:49 +0100 Subject: [PATCH v2 2/9] mmc: moxart-mmc: Factor out moxart_use_dma() helper Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240127-mmc-proper-kmap-v2-2-d8e732aa97d1@linaro.org> References: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> In-Reply-To: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> To: Christoph Hellwig , Jens Axboe , Ming Lei , Arnd Bergmann , Ulf Hansson , Nicolas Pitre , Aaro Koskinen , Adrian Hunter , Angelo Dureghello Cc: linux-mmc@vger.kernel.org, linux-block@vger.kernel.org, linux-omap@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 The same code is in two places and we will add a third place. Break this out into its own function. Signed-off-by: Linus Walleij --- drivers/mmc/host/moxart-mmc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/host/moxart-mmc.c b/drivers/mmc/host/moxart-mmc.c index 5cfdd3a86e54..d12d7d79b19c 100644 --- a/drivers/mmc/host/moxart-mmc.c +++ b/drivers/mmc/host/moxart-mmc.c @@ -254,6 +254,11 @@ static void moxart_dma_complete(void *param) complete(&host->dma_complete); } +static bool moxart_use_dma(struct moxart_host *host) +{ + return (host->data_len > host->fifo_width) && host->have_dma; +} + static void moxart_transfer_dma(struct mmc_data *data, struct moxart_host *host) { u32 len, dir_slave; @@ -375,7 +380,7 @@ static void moxart_prepare_data(struct moxart_host *host) if (data->flags & MMC_DATA_WRITE) datactrl |= DCR_DATA_WRITE; - if ((host->data_len > host->fifo_width) && host->have_dma) + if (moxart_use_dma(host)) datactrl |= DCR_DMA_EN; writel(DCR_DATA_FIFO_RESET, host->base + REG_DATA_CONTROL); @@ -407,7 +412,7 @@ static void moxart_request(struct mmc_host *mmc, struct mmc_request *mrq) moxart_send_command(host, host->mrq->cmd); if (mrq->cmd->data) { - if ((host->data_len > host->fifo_width) && host->have_dma) { + if (moxart_use_dma(host)) { writel(CARD_CHANGE, host->base + REG_INTERRUPT_MASK); From patchwork Sat Jan 27 00:19:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 767949 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B25F2F44 for ; Sat, 27 Jan 2024 00:20:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314819; cv=none; b=Z1GB07DZdDsuV5gSj4oXET4j+Z0xeoD+pxpDuJ1c0XM/E22xsEfYflSI8aWTx2UQ2jOGgfe/PbmDwJHLdaBG6kq86qlQgfm3I9SxGMtA0PioSrXXB9t8r6jIxRdTdnYIgT1f+EQ9up2Sg3vb5URQ/y+I8k5YjA5YrqIh1QTh8Ig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314819; c=relaxed/simple; bh=r6GJCJTqaQQRhKM/4b2T3qgoDHj0cK2/fTlyNuihGgk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DAkfBOL4gcDHveRAoQLXIZ8F6ZCc1Lu6byPFbArSSa3/iHDRtmOeeVqloZv7nEj2Nl0cj+7YoGDmlEZxIg7FZVgRIeHN9cCbuCGTCwnM4SG6lkeb0MH4E0WjLUrF5Guruw7BauSaTIz9I0Q8fV1VmZr26F4xKXuf5TJzbMaiUd0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ANQjOT8w; arc=none smtp.client-ip=209.85.208.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ANQjOT8w" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2cf1288097aso15122761fa.0 for ; Fri, 26 Jan 2024 16:20:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706314815; x=1706919615; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Kus8wRLkItgWvRgBCeH/aGV0whUxwXs/muBiM1oKFIc=; b=ANQjOT8wKhKeFTolKIrWpzCLwM+5Mjn1CEMsc/IWfzZRn0pwGezxthrptX3MCyHL3c fhCrLjB+mJ7z5cZwU9e9/BCaskurrlAXyXg4qEYgxK6m03mpoo04q63+WKhH+I42tM4T J6GFISk+G4f/E26GlNVmgWZkmoXQwKTQ/9mGL/UGUWZmRTa4m/Ucm/HMWY7pNmd+pI6u ECsDjLbDqfWgJsA3HxNn04LuR9wyJJPDUcn48ko5ffIoDZjPBq4jEX7s4YdKnLTvjs7H dAMVpZcLGIPSfA8tnYMJTY5fxUD+Cr0lyBfrapsLyvlCcqDtAKhzoUlACzvDIO27ZZax ywGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706314815; x=1706919615; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Kus8wRLkItgWvRgBCeH/aGV0whUxwXs/muBiM1oKFIc=; b=eEvxziWh46Ix0wJ6x3NS3qLntUpwi4W/+0f2AdU8UyhLLPEFFnmRfQwY2oiklWwIZT g/NJJCTxKJ4THasB6XgkynK+v1RPlPTRt3z7oHOjd2dGwtZe0t9Jh5csEtB4p6AJ3ubr H++9nPg57Rik78pAdN+JbaECV5kZQcpJu7wQ6np7dXzg327Y2wi+8AjcSO3cSnbWpBW+ rSs+rrgrinaHOj4Zx+r8fjpbMj3f1sOdRA+wHKcsGFgHO8TIwGxVFGOdg44lkf4Zm3Ku i6aQcsJEJlXPKkmjYzhm5/2FOUpu3dn4ANHzkH/y9mjgVO1Wh7yRpFIjS0yH5TVNPCGM F6ew== X-Gm-Message-State: AOJu0YyLblqxZnXUGW59ZI7MjlPV3RhEmahBWfArJMwQ5pZuX8HObLvk YhbT4oCLODzIJrkhrn63ayu8LrI1Fp85dp5zeipq90uVlbo6zA9J+hE9kXTfThg= X-Google-Smtp-Source: AGHT+IEpxRIR5WbtJSMP9B8XikMs/Wg95wGD4l3znJD007vGaYsPUxly5zh+a+tVyVBz+XzwNXGKnw== X-Received: by 2002:ac2:5df5:0:b0:50e:5a25:efbf with SMTP id z21-20020ac25df5000000b0050e5a25efbfmr346844lfq.42.1706314814980; Fri, 26 Jan 2024 16:20:14 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x25-20020a19f619000000b0050e7f5cffa6sm325226lfe.273.2024.01.26.16.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 16:20:14 -0800 (PST) From: Linus Walleij Date: Sat, 27 Jan 2024 01:19:50 +0100 Subject: [PATCH v2 3/9] mmc: moxart-mmc: Fix accounting in DMA transfer Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240127-mmc-proper-kmap-v2-3-d8e732aa97d1@linaro.org> References: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> In-Reply-To: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> To: Christoph Hellwig , Jens Axboe , Ming Lei , Arnd Bergmann , Ulf Hansson , Nicolas Pitre , Aaro Koskinen , Adrian Hunter , Angelo Dureghello Cc: linux-mmc@vger.kernel.org, linux-block@vger.kernel.org, linux-omap@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 The whole scatterlist chain is submitted to the DMA engine, but the code is written to just account for the length of the first sg entry. When the DMA transfer is finished, all the data in the request has been transferred, account for this instead. This only works because the moxart_request() function isn't checking that all data was transferred and will unconditionally issue mmc_request_done() after returning successfully from moxart_transfer_dma(). Keep the assignment of accounted bytes in .bytes_xfered but move it after the completion where we know it has actually happened. Signed-off-by: Linus Walleij --- drivers/mmc/host/moxart-mmc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/host/moxart-mmc.c b/drivers/mmc/host/moxart-mmc.c index d12d7d79b19c..8ede4ce93271 100644 --- a/drivers/mmc/host/moxart-mmc.c +++ b/drivers/mmc/host/moxart-mmc.c @@ -296,11 +296,11 @@ static void moxart_transfer_dma(struct mmc_data *data, struct moxart_host *host) dma_async_issue_pending(dma_chan); } - data->bytes_xfered += host->data_remain; - wait_for_completion_interruptible_timeout(&host->dma_complete, host->timeout); + data->bytes_xfered = host->data_len; + dma_unmap_sg(dma_chan->device->dev, data->sg, data->sg_len, mmc_get_dma_dir(data)); From patchwork Sat Jan 27 00:19:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 767083 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C07733F6 for ; Sat, 27 Jan 2024 00:20:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314821; cv=none; b=GQZz691lYP+fv3KzW0shlH4RpO7aszcmc8SIwxqx+Iw45EezkJKCveKZjnXXPLYJp1fRFE+LOV+qk4O4Pg+v3euwXceLHSejqjE5La1uQfTSHJ9Ulh3ssSKYU9WqeHQn62RgpdPTSglXDq4/YpS29NmyjxdKGn+whCJW4rhzLeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314821; c=relaxed/simple; bh=dFn2ks6EacXxE3ISx+PVGru3tsQjDI5FXRhrLZ+AE6Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SIU9Pzw9Vme4r9gSvKNqGJ+RZoK2YfPkDpqu7bbiSIDZRgr/eFZQer1r0P4/S+d+qdJWp1Rg0I/3C1Qp/O67xLejq7B53UvyrP6iRYs+2umLXK/izOw5vmygCXEyB5ol7kxeMjojx4wd7+CCd5x6RsiRVCbG0Wy6rXa3kQpUtxo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=pBOIqkl5; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pBOIqkl5" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5100cb238bcso1630383e87.3 for ; Fri, 26 Jan 2024 16:20:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706314816; x=1706919616; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ofuXItHZiXctDb5vYJexyw4lWFm2o06QaWEWbHlsUFY=; b=pBOIqkl54M8xJ664Cr0wpalsghoMvF6s63n9XN3S0Qv0MVq3j17OvOzWz7jUQK6/KI Vo5oWlKOnHPZ8HWrgC4ciEaJVLIloaIuIYl+qFjy+166stenQ0Nqn/vOrlP6+B9PtTHz JXUjybQ+lbc1JF7nAg+hIrNUDb+OS141Vz6Pgla5x/cUyP81XdxY+O6LVcVMQDoOr0wd sKhqh9dD3bjO5PVBl9quo0VeYScKA7giAUFBXxlB/FQWEqN/KkpiRgMUtbuCCTsAh+Kh VbPjPHor97efBHQq2qxO1vnBZuEwvVMw6PImMlBIfnSIJdHoH9cAbCyomMtYZQuxbtcl naQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706314816; x=1706919616; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ofuXItHZiXctDb5vYJexyw4lWFm2o06QaWEWbHlsUFY=; b=LyRMI5vPTsNis08G6vVHNEEED2rF+4Wexth0DM8qphGAWtAG9ljNMZPZHHxE30wJw3 dLq7md/S1iZlXwwTuEZkj10jNoHsitAocOu4QBTH7p0JaIZhWkkNvHgXb8WTs2y7qF4u VwiXm8q4aFStpdWP8kvJPM+6UMMG6PmSAc8+iotPhPYW0y3eWO150gSlt6P6AHhEre+U ZpjP3J6LhRz5V2ke9tjinSOkL0TfheppLnBRL4ApfQ0ZF3l7Pmq1rDhrpOSyUyUuQWaB gcPm5SUoYQez9YfrSRULhdeRtqKppWDdTVjvkFDrKkq8e/jJP0Ics7rO895EjoCeRsr2 XXHQ== X-Gm-Message-State: AOJu0Yy/XJjIcUxGoto7zDkeS3rV95t7PgUoSTh/Cvd8cNUy4FWuQ6je XxTQXa1LVGrlO52nOpGq7pE9Vsxt8FpqQCg21Y2X2aHAHGy/CLJ59V8MclrJgHY= X-Google-Smtp-Source: AGHT+IGyvgr05EIrw1L+Y9U4iitEjJQ8+0O5OLxehL3iS289M5RLEqax89yMlhsUVY2qH3SITfm7pw== X-Received: by 2002:ac2:4bc9:0:b0:510:893:f8c3 with SMTP id o9-20020ac24bc9000000b005100893f8c3mr412301lfq.20.1706314816586; Fri, 26 Jan 2024 16:20:16 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x25-20020a19f619000000b0050e7f5cffa6sm325226lfe.273.2024.01.26.16.20.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 16:20:15 -0800 (PST) From: Linus Walleij Date: Sat, 27 Jan 2024 01:19:51 +0100 Subject: [PATCH v2 4/9] mmc: moxart-mmc: Use sg_miter for PIO Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240127-mmc-proper-kmap-v2-4-d8e732aa97d1@linaro.org> References: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> In-Reply-To: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> To: Christoph Hellwig , Jens Axboe , Ming Lei , Arnd Bergmann , Ulf Hansson , Nicolas Pitre , Aaro Koskinen , Adrian Hunter , Angelo Dureghello Cc: linux-mmc@vger.kernel.org, linux-block@vger.kernel.org, linux-omap@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 Use the scatterlist memory iterator instead of just dereferencing virtual memory using sg_virt(). This make highmem references work properly. Suggested-by: Christoph Hellwig Link: https://lore.kernel.org/linux-mmc/20240122073423.GA25859@lst.de/ Signed-off-by: Linus Walleij --- drivers/mmc/host/moxart-mmc.c | 77 +++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/drivers/mmc/host/moxart-mmc.c b/drivers/mmc/host/moxart-mmc.c index 8ede4ce93271..b88d6dec209f 100644 --- a/drivers/mmc/host/moxart-mmc.c +++ b/drivers/mmc/host/moxart-mmc.c @@ -131,12 +131,10 @@ struct moxart_host { struct dma_async_tx_descriptor *tx_desc; struct mmc_host *mmc; struct mmc_request *mrq; - struct scatterlist *cur_sg; struct completion dma_complete; struct completion pio_complete; - u32 num_sg; - u32 data_remain; + struct sg_mapping_iter sg_miter; u32 data_len; u32 fifo_width; u32 timeout; @@ -148,35 +146,6 @@ struct moxart_host { bool is_removed; }; -static inline void moxart_init_sg(struct moxart_host *host, - struct mmc_data *data) -{ - host->cur_sg = data->sg; - host->num_sg = data->sg_len; - host->data_remain = host->cur_sg->length; - - if (host->data_remain > host->data_len) - host->data_remain = host->data_len; -} - -static inline int moxart_next_sg(struct moxart_host *host) -{ - int remain; - struct mmc_data *data = host->mrq->cmd->data; - - host->cur_sg++; - host->num_sg--; - - if (host->num_sg > 0) { - host->data_remain = host->cur_sg->length; - remain = host->data_len - data->bytes_xfered; - if (remain > 0 && remain < host->data_remain) - host->data_remain = remain; - } - - return host->num_sg; -} - static int moxart_wait_for_status(struct moxart_host *host, u32 mask, u32 *status) { @@ -309,14 +278,28 @@ static void moxart_transfer_dma(struct mmc_data *data, struct moxart_host *host) static void moxart_transfer_pio(struct moxart_host *host) { + struct sg_mapping_iter *sgm = &host->sg_miter; struct mmc_data *data = host->mrq->cmd->data; u32 *sgp, len = 0, remain, status; if (host->data_len == data->bytes_xfered) return; - sgp = sg_virt(host->cur_sg); - remain = host->data_remain; + /* + * By updating sgm->consumes this will get a proper pointer into the + * buffer at any time. + */ + if (!sg_miter_next(sgm)) { + /* This shold not happen */ + dev_err(mmc_dev(host->mmc), "ran out of scatterlist prematurely\n"); + data->error = -EINVAL; + complete(&host->pio_complete); + return; + } + sgp = sgm->addr; + remain = sgm->length; + if (remain > host->data_len) + remain = host->data_len; if (data->flags & MMC_DATA_WRITE) { while (remain > 0) { @@ -331,6 +314,7 @@ static void moxart_transfer_pio(struct moxart_host *host) sgp++; len += 4; } + sgm->consumed += len; remain -= len; } @@ -347,22 +331,22 @@ static void moxart_transfer_pio(struct moxart_host *host) sgp++; len += 4; } + sgm->consumed += len; remain -= len; } } - data->bytes_xfered += host->data_remain - remain; - host->data_remain = remain; - - if (host->data_len != data->bytes_xfered) - moxart_next_sg(host); - else + data->bytes_xfered += sgm->consumed; + if (host->data_len == data->bytes_xfered) { complete(&host->pio_complete); + return; + } } static void moxart_prepare_data(struct moxart_host *host) { struct mmc_data *data = host->mrq->cmd->data; + unsigned int flags = SG_MITER_ATOMIC; /* Used from IRQ */ u32 datactrl; int blksz_bits; @@ -373,15 +357,19 @@ static void moxart_prepare_data(struct moxart_host *host) blksz_bits = ffs(data->blksz) - 1; BUG_ON(1 << blksz_bits != data->blksz); - moxart_init_sg(host, data); - datactrl = DCR_DATA_EN | (blksz_bits & DCR_BLK_SIZE); - if (data->flags & MMC_DATA_WRITE) + if (data->flags & MMC_DATA_WRITE) { + flags |= SG_MITER_FROM_SG; datactrl |= DCR_DATA_WRITE; + } else { + flags |= SG_MITER_TO_SG; + } if (moxart_use_dma(host)) datactrl |= DCR_DMA_EN; + else + sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags); writel(DCR_DATA_FIFO_RESET, host->base + REG_DATA_CONTROL); writel(MASK_DATA | FIFO_URUN | FIFO_ORUN, host->base + REG_CLEAR); @@ -454,6 +442,9 @@ static void moxart_request(struct mmc_host *mmc, struct mmc_request *mrq) } request_done: + if (!moxart_use_dma(host)) + sg_miter_stop(&host->sg_miter); + spin_unlock_irqrestore(&host->lock, flags); mmc_request_done(host->mmc, mrq); } From patchwork Sat Jan 27 00:19:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 767948 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FD341C6B3 for ; Sat, 27 Jan 2024 00:20:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314821; cv=none; b=T7E3yJSDFY5BNvKJ1B6HzaCkpEXVi9En7oVpfW9VjGmS7tITxvsEYlK48TydQhm3G2wgpDes7NxwieaIlZZLrFqug0Vmk+qxroriOe+a1HfjvbPNKyC+uN1gCx/QC7PTunCS5SxwPvDkBFWnMkiw/8OZX/rJQrKLdsiVIqFWqFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314821; c=relaxed/simple; bh=9/wwLT18BUDyTWXggkK9BCgrhK2swAAIK+73Bo29JTg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CzbMMlADNMJ5XzJ+x6fEjWoUkFrv4Y/huWGdVEtoWgTH7VOivsXfmdxx0bSMqXKYWF8HxcQxulDyvp7NGh6ydQLlll0CdWLn0y9UMN5GdEb7qHTQsEua5kSh4rWNcaI8iNaBrQfKlFhLzZnlbJvZ4zRJsIildSWm4SGP6d3b/xM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Q+MHfxAc; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Q+MHfxAc" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-510218ab26fso1569434e87.2 for ; Fri, 26 Jan 2024 16:20:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706314817; x=1706919617; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=eRirpuRqStGDqBkFHe65SrxV5jM0SILjOXPwd5g5zmY=; b=Q+MHfxAc0cLNJjfF1fRsYczigZHMUGfK5rrDcLpEBNaQNq9LHwP4eqBLVBtLyWXYeZ Lki7Ti9AtPtJbYsmRzLong1EwC6UMh6YYQJFj//SjGyrrWQ+NzOGmB2HNvOHOJ9m6Kmu R4fTgm9rkEfqAY1EPbD1lE10KIKA2F0u5OWEGb60vaKBnPWMjbgLI/+iAGI8GFnMT3yx DGZt7GNT4rybMjokIamuN4GWU6+F4Q5FsyMvgQlU0/18A0WkrT/bqMhrHgivopkfO6iB /+9MGdBG+VSH5bN+Af3SCcrxpy0nXw7IA4A/LYz4Uk6/6dvH0sjaWPRrB2IStf9RzsTi U8kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706314817; x=1706919617; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eRirpuRqStGDqBkFHe65SrxV5jM0SILjOXPwd5g5zmY=; b=sDJg6IWWpUYNOrJqWEOfdRrhUSggUKd1tOEO5gG/fZPGrOdWBgWyZvMhDgbMDK6CIN wU+W1aw7aC3X5jiNXNYQSYMMCjfzywqYaqgI6lZGWxyQCmbxDxOFawdn8SHl4QpHZhnC ypO5npSM6OBy7742hxpqciyKxHTu2+oFx1JkSn3hqLPr6hS5s3l55+NCfqKJbqFI3wRy zlKuFYrRXNnzIh0QeBWkg5Jph4ONynPwWCuvv14Qh3YvHMph6pYI9Qbszd73RGV07MCJ LRg9AfMhagFCSgsoDFsRcmJ+PjL3GNlUagzJ/i0tEtXLF3jIn1xBab07IqOcjFWxb1ZX wjAg== X-Gm-Message-State: AOJu0YxdX4lV7V1jLB81MN4d3uPCmeIBDAPQm6RQ38O7FppKlCHcAMw8 h7NlyHgnxxoEy+F9eDQYAj6NzjWv0fenyV8WSCsWNSDB5HrujnUX/PkMMpney9k= X-Google-Smtp-Source: AGHT+IEieB9VwK0RUyhp0+dIhGeLrFmYpVXkTt01iumobPvcTXn/Pm6yTciatsKZBbXQy4sYm4+lRg== X-Received: by 2002:ac2:4911:0:b0:510:b1b:5db3 with SMTP id n17-20020ac24911000000b005100b1b5db3mr739998lfi.67.1706314817623; Fri, 26 Jan 2024 16:20:17 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x25-20020a19f619000000b0050e7f5cffa6sm325226lfe.273.2024.01.26.16.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 16:20:17 -0800 (PST) From: Linus Walleij Date: Sat, 27 Jan 2024 01:19:52 +0100 Subject: [PATCH v2 5/9] mmc: mvsdio: Use sg_miter for PIO Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240127-mmc-proper-kmap-v2-5-d8e732aa97d1@linaro.org> References: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> In-Reply-To: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> To: Christoph Hellwig , Jens Axboe , Ming Lei , Arnd Bergmann , Ulf Hansson , Nicolas Pitre , Aaro Koskinen , Adrian Hunter , Angelo Dureghello Cc: linux-mmc@vger.kernel.org, linux-block@vger.kernel.org, linux-omap@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 Use the scatterlist memory iterator instead of just dereferencing virtual memory using sg_virt(). This make highmem references work properly. This driver also has a bug in the PIO sglist handling that is fixed as part of the patch: it does not travers the list of scatterbuffers: it will just process the first item in the list. This is fixed by augmenting the logic such that we do not process more than one sgitem per IRQ instead of counting down potentially the whole length of the request. We can suspect that the PIO path is quite untested. Suggested-by: Christoph Hellwig Link: https://lore.kernel.org/linux-mmc/20240122073423.GA25859@lst.de/ Signed-off-by: Linus Walleij --- drivers/mmc/host/mvsdio.c | 71 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 18 deletions(-) diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c index ca01b7d204ba..af7f21888e27 100644 --- a/drivers/mmc/host/mvsdio.c +++ b/drivers/mmc/host/mvsdio.c @@ -38,8 +38,9 @@ struct mvsd_host { unsigned int xfer_mode; unsigned int intr_en; unsigned int ctrl; + bool use_pio; + struct sg_mapping_iter sg_miter; unsigned int pio_size; - void *pio_ptr; unsigned int sg_frags; unsigned int ns_per_clk; unsigned int clock; @@ -114,11 +115,18 @@ static int mvsd_setup_data(struct mvsd_host *host, struct mmc_data *data) * data when the buffer is not aligned on a 64 byte * boundary. */ + unsigned int miter_flags = SG_MITER_ATOMIC; /* Used from IRQ */ + + if (data->flags & MMC_DATA_READ) + miter_flags |= SG_MITER_TO_SG; + else + miter_flags |= SG_MITER_FROM_SG; + host->pio_size = data->blocks * data->blksz; - host->pio_ptr = sg_virt(data->sg); + sg_miter_start(&host->sg_miter, data->sg, data->sg_len, miter_flags); if (!nodma) - dev_dbg(host->dev, "fallback to PIO for data at 0x%p size %d\n", - host->pio_ptr, host->pio_size); + dev_dbg(host->dev, "fallback to PIO for data\n"); + host->use_pio = true; return 1; } else { dma_addr_t phys_addr; @@ -129,6 +137,7 @@ static int mvsd_setup_data(struct mvsd_host *host, struct mmc_data *data) phys_addr = sg_dma_address(data->sg); mvsd_write(MVSD_SYS_ADDR_LOW, (u32)phys_addr & 0xffff); mvsd_write(MVSD_SYS_ADDR_HI, (u32)phys_addr >> 16); + host->use_pio = false; return 0; } } @@ -288,8 +297,8 @@ static u32 mvsd_finish_data(struct mvsd_host *host, struct mmc_data *data, { void __iomem *iobase = host->base; - if (host->pio_ptr) { - host->pio_ptr = NULL; + if (host->use_pio) { + sg_miter_stop(&host->sg_miter); host->pio_size = 0; } else { dma_unmap_sg(mmc_dev(host->mmc), data->sg, host->sg_frags, @@ -344,9 +353,12 @@ static u32 mvsd_finish_data(struct mvsd_host *host, struct mmc_data *data, static irqreturn_t mvsd_irq(int irq, void *dev) { struct mvsd_host *host = dev; + struct sg_mapping_iter *sgm = &host->sg_miter; void __iomem *iobase = host->base; u32 intr_status, intr_done_mask; int irq_handled = 0; + u16 *p; + int s; intr_status = mvsd_read(MVSD_NOR_INTR_STATUS); dev_dbg(host->dev, "intr 0x%04x intr_en 0x%04x hw_state 0x%04x\n", @@ -370,15 +382,36 @@ static irqreturn_t mvsd_irq(int irq, void *dev) spin_lock(&host->lock); /* PIO handling, if needed. Messy business... */ - if (host->pio_size && + if (host->use_pio) { + /* + * As we set sgm->consumed this always gives a valid buffer + * position. + */ + if (!sg_miter_next(sgm)) { + /* This should not happen */ + dev_err(host->dev, "ran out of scatter segments\n"); + spin_unlock(&host->lock); + host->intr_en &= + ~(MVSD_NOR_RX_READY | MVSD_NOR_RX_FIFO_8W | + MVSD_NOR_TX_AVAIL | MVSD_NOR_TX_FIFO_8W); + mvsd_write(MVSD_NOR_INTR_EN, host->intr_en); + return IRQ_HANDLED; + } + p = sgm->addr; + s = sgm->length; + if (s > host->pio_size) + s = host->pio_size; + } + + if (host->use_pio && (intr_status & host->intr_en & (MVSD_NOR_RX_READY | MVSD_NOR_RX_FIFO_8W))) { - u16 *p = host->pio_ptr; - int s = host->pio_size; + while (s >= 32 && (intr_status & MVSD_NOR_RX_FIFO_8W)) { readsw(iobase + MVSD_FIFO, p, 16); p += 16; s -= 32; + sgm->consumed += 32; intr_status = mvsd_read(MVSD_NOR_INTR_STATUS); } /* @@ -391,6 +424,7 @@ static irqreturn_t mvsd_irq(int irq, void *dev) put_unaligned(mvsd_read(MVSD_FIFO), p++); put_unaligned(mvsd_read(MVSD_FIFO), p++); s -= 4; + sgm->consumed += 4; intr_status = mvsd_read(MVSD_NOR_INTR_STATUS); } if (s && s < 4 && (intr_status & MVSD_NOR_RX_READY)) { @@ -398,10 +432,13 @@ static irqreturn_t mvsd_irq(int irq, void *dev) val[0] = mvsd_read(MVSD_FIFO); val[1] = mvsd_read(MVSD_FIFO); memcpy(p, ((void *)&val) + 4 - s, s); + sgm->consumed += s; s = 0; intr_status = mvsd_read(MVSD_NOR_INTR_STATUS); } - if (s == 0) { + /* PIO transfer done */ + host->pio_size -= sgm->consumed; + if (host->pio_size == 0) { host->intr_en &= ~(MVSD_NOR_RX_READY | MVSD_NOR_RX_FIFO_8W); mvsd_write(MVSD_NOR_INTR_EN, host->intr_en); @@ -413,14 +450,10 @@ static irqreturn_t mvsd_irq(int irq, void *dev) } dev_dbg(host->dev, "pio %d intr 0x%04x hw_state 0x%04x\n", s, intr_status, mvsd_read(MVSD_HW_STATE)); - host->pio_ptr = p; - host->pio_size = s; irq_handled = 1; - } else if (host->pio_size && + } else if (host->use_pio && (intr_status & host->intr_en & (MVSD_NOR_TX_AVAIL | MVSD_NOR_TX_FIFO_8W))) { - u16 *p = host->pio_ptr; - int s = host->pio_size; /* * The TX_FIFO_8W bit is unreliable. When set, bursting * 16 halfwords all at once in the FIFO drops data. Actually @@ -431,6 +464,7 @@ static irqreturn_t mvsd_irq(int irq, void *dev) mvsd_write(MVSD_FIFO, get_unaligned(p++)); mvsd_write(MVSD_FIFO, get_unaligned(p++)); s -= 4; + sgm->consumed += 4; intr_status = mvsd_read(MVSD_NOR_INTR_STATUS); } if (s < 4) { @@ -439,10 +473,13 @@ static irqreturn_t mvsd_irq(int irq, void *dev) memcpy(((void *)&val) + 4 - s, p, s); mvsd_write(MVSD_FIFO, val[0]); mvsd_write(MVSD_FIFO, val[1]); + sgm->consumed += s; s = 0; intr_status = mvsd_read(MVSD_NOR_INTR_STATUS); } - if (s == 0) { + /* PIO transfer done */ + host->pio_size -= sgm->consumed; + if (host->pio_size == 0) { host->intr_en &= ~(MVSD_NOR_TX_AVAIL | MVSD_NOR_TX_FIFO_8W); mvsd_write(MVSD_NOR_INTR_EN, host->intr_en); @@ -450,8 +487,6 @@ static irqreturn_t mvsd_irq(int irq, void *dev) } dev_dbg(host->dev, "pio %d intr 0x%04x hw_state 0x%04x\n", s, intr_status, mvsd_read(MVSD_HW_STATE)); - host->pio_ptr = p; - host->pio_size = s; irq_handled = 1; } From patchwork Sat Jan 27 00:19:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 767946 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CBA11D695 for ; Sat, 27 Jan 2024 00:20:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314824; cv=none; b=sXH5cxrsKf/nBEhN4Xqmkw4+1JDJnAO7UdzbGHepUSrCtgGX21bxUoJTZysZJXlXhbEYm2dZr66zpXh7bvizFWrL3x4d7meo9BXG7dkbpVIDp0pB1vNq/dryt4P/C9SmCj4HmtYB75Dx95tCfl/T7KnkOd4N3HFccSKuywA15BE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314824; c=relaxed/simple; bh=HYmGgaLgWEX6oEn5bgILT9HdCgPRXmSHSVRfD6iUtog=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Gc3B8s3gWIYJKeYidJd21He127fG6FzxwhUJqvyIP1iHMwybycGdH1qYXeAV8TghxLWDDj8eMi/UXk5ORFaayOCiWabTFXKr2+hLOD+hABQ8AmYoqUqBAt8Grbc1jbIBHSIuPpbatOFM9vLfF99Z0PB3QssKBiskMNI1kvTDByw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=pN9WT0GY; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pN9WT0GY" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-50ea9daac4cso965146e87.3 for ; Fri, 26 Jan 2024 16:20:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706314818; x=1706919618; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=nXmkhj6L70OQxNCX7S7WA9V64VMJ9cP8ih0oj9vAqT4=; b=pN9WT0GYU2aFARDqTA8f1jSGEHuuxnY1cye9moMOqpsqVUoIFW4eLFLkb3ISKDFjkf yaKNdbO/HMpagsC/USLrIYGcZNwB6qmHI0h4axQw98kfKdk2vPVsqKYn8X3af3HQ8hrR nzrrYh1r4Edzybn3T3ftJsTBgfL2px6fxo1kCOeH8KMAvOJeIAglyo84DhvZin5pCVZC WvAPrdUxiLP8WEq1OZGEfqBpFarn3tDh6I5Ejqlk6/7q33FlJ9c05gdiXgAESFhKgYcN DU5KxIGuwPI16wHnWm7nKvz0rmkzCOgqsPmpbdb49AVdktiNmHJ4Uuy1ZVNDviNXHq03 6JFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706314818; x=1706919618; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nXmkhj6L70OQxNCX7S7WA9V64VMJ9cP8ih0oj9vAqT4=; b=ZnlpwobJeMKCgc6glDizJZuf11rCOIrvyU3o00ET+TmYJ4el//WkLiw6Bvjza8xzUL koeRaPgNTDoC438iFgJ09o6xgMrwuIHX5JR8Cd5WVAt0YKyxnvzDFmTQ4ShxpPMjlVTx iNX++U6vK+BEnAzJx/SugB8tgyKBEzr2OE17VF1/x10TkcGNb+zJPf7MYSksCLdqAW7K Tj0JFSo3jaINvAePDfcARAeMrtQxg9LiI2zh6UETIr2ZplBmt4wIS69e4795EsmOQbU5 Bz+UISbynByR8WLdL4EWbQBI1hS5+BT2/euaj+q3qoF3fV9msN6nGfB33JcnVDjU/6Ca LnVA== X-Gm-Message-State: AOJu0YzpaG55IpodX6LEf51+IgZhQ+TIwqkwCONOg4De2YKRfNc/g87i GxPuamst0jCU4yYGulrpl+LqbAnongzKCF16SOT+T+tqCSbRzX13eKt3yWsNgoQ= X-Google-Smtp-Source: AGHT+IFLVN7BK0qbc3Zc65OltD6GZpGHMU9ydl9RCyNJ4EpmANWYgk2ANjlW0TtzuDB0dHkxtZ0FOw== X-Received: by 2002:a05:6512:3046:b0:510:67d:22c7 with SMTP id b6-20020a056512304600b00510067d22c7mr351403lfb.69.1706314818624; Fri, 26 Jan 2024 16:20:18 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x25-20020a19f619000000b0050e7f5cffa6sm325226lfe.273.2024.01.26.16.20.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 16:20:18 -0800 (PST) From: Linus Walleij Date: Sat, 27 Jan 2024 01:19:53 +0100 Subject: [PATCH v2 6/9] mmc: mxcmmc: Use sg_miter for PIO Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240127-mmc-proper-kmap-v2-6-d8e732aa97d1@linaro.org> References: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> In-Reply-To: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> To: Christoph Hellwig , Jens Axboe , Ming Lei , Arnd Bergmann , Ulf Hansson , Nicolas Pitre , Aaro Koskinen , Adrian Hunter , Angelo Dureghello Cc: linux-mmc@vger.kernel.org, linux-block@vger.kernel.org, linux-omap@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 Use the scatterlist memory iterator instead of just dereferencing virtual memory using sg_virt(). This make highmem references work properly. Since this driver is using a worker, no atomic trickery is needed. Suggested-by: Christoph Hellwig Link: https://lore.kernel.org/linux-mmc/20240122073423.GA25859@lst.de/ Signed-off-by: Linus Walleij --- drivers/mmc/host/mxcmmc.c | 53 +++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c index 5b3ab0e20505..1edf65291354 100644 --- a/drivers/mmc/host/mxcmmc.c +++ b/drivers/mmc/host/mxcmmc.c @@ -266,11 +266,18 @@ static inline void buffer_swap32(u32 *buf, int len) static void mxcmci_swap_buffers(struct mmc_data *data) { - struct scatterlist *sg; - int i; + struct sg_mapping_iter sgm; + u32 *buf; + + sg_miter_start(&sgm, data->sg, data->sg_len, + SG_MITER_TO_SG | SG_MITER_FROM_SG); + + while (sg_miter_next(&sgm)) { + buf = sgm.addr; + buffer_swap32(buf, sgm.length); + } - for_each_sg(data->sg, sg, data->sg_len, i) - buffer_swap32(sg_virt(sg), sg->length); + sg_miter_stop(&sgm); } #else static inline void mxcmci_swap_buffers(struct mmc_data *data) {} @@ -526,10 +533,9 @@ static int mxcmci_poll_status(struct mxcmci_host *host, u32 mask) } while (1); } -static int mxcmci_pull(struct mxcmci_host *host, void *_buf, int bytes) +static int mxcmci_pull(struct mxcmci_host *host, u32 *buf, int bytes) { unsigned int stat; - u32 *buf = _buf; while (bytes > 3) { stat = mxcmci_poll_status(host, @@ -555,10 +561,9 @@ static int mxcmci_pull(struct mxcmci_host *host, void *_buf, int bytes) return 0; } -static int mxcmci_push(struct mxcmci_host *host, void *_buf, int bytes) +static int mxcmci_push(struct mxcmci_host *host, u32 *buf, int bytes) { unsigned int stat; - u32 *buf = _buf; while (bytes > 3) { stat = mxcmci_poll_status(host, STATUS_BUF_WRITE_RDY); @@ -586,31 +591,39 @@ static int mxcmci_push(struct mxcmci_host *host, void *_buf, int bytes) static int mxcmci_transfer_data(struct mxcmci_host *host) { struct mmc_data *data = host->req->data; - struct scatterlist *sg; - int stat, i; + struct sg_mapping_iter sgm; + int stat; + u32 *buf; host->data = data; host->datasize = 0; + sg_miter_start(&sgm, data->sg, data->sg_len, + (data->flags & MMC_DATA_READ) ? SG_MITER_TO_SG : SG_MITER_FROM_SG); if (data->flags & MMC_DATA_READ) { - for_each_sg(data->sg, sg, data->sg_len, i) { - stat = mxcmci_pull(host, sg_virt(sg), sg->length); + while (sg_miter_next(&sgm)) { + buf = sgm.addr; + stat = mxcmci_pull(host, buf, sgm.length); if (stat) - return stat; - host->datasize += sg->length; + goto transfer_error; + host->datasize += sgm.length; } } else { - for_each_sg(data->sg, sg, data->sg_len, i) { - stat = mxcmci_push(host, sg_virt(sg), sg->length); + while (sg_miter_next(&sgm)) { + buf = sgm.addr; + stat = mxcmci_push(host, buf, sgm.length); if (stat) - return stat; - host->datasize += sg->length; + goto transfer_error; + host->datasize += sgm.length; } stat = mxcmci_poll_status(host, STATUS_WRITE_OP_DONE); if (stat) - return stat; + goto transfer_error; } - return 0; + +transfer_error: + sg_miter_stop(&sgm); + return stat; } static void mxcmci_datawork(struct work_struct *work) From patchwork Sat Jan 27 00:19:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 767947 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4AAF21DA2C for ; Sat, 27 Jan 2024 00:20:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314823; cv=none; b=B+zf4uFzWD0bDoUARHStz/KiQwh9OsG5KqYpaTRA4gBQr+HW9w7e5ckehkYmt8VQx0rJdRiWf7px88tFWaGA7uBQg5jBs9WNklCjI6N+1A6G1xr3YvwtJ7fzKdlwlxVf5zPz23nEGXZENSz0IlgDw83TLITS+ryz1yE+XXT45zo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314823; c=relaxed/simple; bh=c+9yx9s+5x1GQ5Cg5aBMoAPtZLahUWjRY70l/Q75qhw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=g8dArW43XoGtuT6sI2gwnNGKZkfS5wZ6UU0ewsYYww+FI+hMhBPN9GUTSBTQIOdymx7RDg1V7SDvDCpdMp93mmoR6dfmGbS6j/XPIN0s3O/qoIo5TQo+cbgQmOn/EJMon25g7xviaYKwzKg2ZwKmHfMpmOUcFgaPhrRU6AcPFy8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=r5Pi+8xs; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="r5Pi+8xs" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-50ea9daac4cso965155e87.3 for ; Fri, 26 Jan 2024 16:20:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706314819; x=1706919619; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=XwHnRqoneohFsF+zXq7jGhhclsZMo81FOvC/Q025Hhg=; b=r5Pi+8xs6BHEq56HV9GpKbVuCOT9jTBkRtlkNyHtt4d8cfV+1C54N1VuripL3AOKMo 2X5JJaiHdWJvRuMXHbxlE4+pwcaS98vlzmtfTjBaYD4fpeEZqI9kqnLKqO+Wx2cD0fcz TvSdVbvccgPLgyNjLHCVz7CzulYC1Mqu9mqgdNnpVpiKlIkb5SvQePJAuufBrEjMvbMP BWcdEzxj9oeEDev7DX/5Y7Dg3/Bd+VApYDLXCwmcyZqTKb5Ko+gfewRDCuAH8Kc1xfQy OKOKHuleqTknQAraSXtEzjhFpaHEqqQRxccaXOw8TGmNpk7f64BN1pZ4UAqf6CvQbHXS lZ8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706314819; x=1706919619; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XwHnRqoneohFsF+zXq7jGhhclsZMo81FOvC/Q025Hhg=; b=w53BxhIBpbhQ6H6fxgkEdjZmiEg/WuuTXZZ9fX0FqKnKCmO3PovDkdxlvy3rZW8R20 wI0rfDln/nj6zhF0tWFn3meJnf2wegulGSKvRYz+//n83nksHSrVu/DIwQS26LdwDqD2 illmPUcFU1MkL+YeyX1zVE8TBJCBmF9l9c+JUGTxRHSIfpNZKnxyKsSmi1uyutdYe7ts W0TszVYhH6p7UNObcVjaZ21+iBzslteAr/5AUnULbo0tdYi2ZPtwhT6Vbu6obOxVc0yN Wv3MfpI5DnzKIUg6xn8Jig/9/7IsLNRpKOOCIfafe4PplvxY0Z8wubAddHbKcjQmUwdz 7wVg== X-Gm-Message-State: AOJu0YwNOTLNQlFwU1RSYx+WfIQYGZn8fGmD2YIeSWyMqM7uLndhd9Wl a6T7d86u1xUfuz2oE+2pU3Uzwr9auRHLC9xPIpnMOxGd1uYlgrcvJwixs8VHXbduqaYoEM5u7jT i X-Google-Smtp-Source: AGHT+IEdPhZaIgW5YEjxOMV90bFpo9Gsr/GbkwQFTPsWSZMJuPq5Re+iu8QRAdA6o8YVrSRAHloNwQ== X-Received: by 2002:a19:6448:0:b0:510:c62:bcd4 with SMTP id b8-20020a196448000000b005100c62bcd4mr307969lfj.55.1706314819522; Fri, 26 Jan 2024 16:20:19 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x25-20020a19f619000000b0050e7f5cffa6sm325226lfe.273.2024.01.26.16.20.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 16:20:19 -0800 (PST) From: Linus Walleij Date: Sat, 27 Jan 2024 01:19:54 +0100 Subject: [PATCH v2 7/9] mmc: omap: Use sg_miter for PIO Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240127-mmc-proper-kmap-v2-7-d8e732aa97d1@linaro.org> References: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> In-Reply-To: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> To: Christoph Hellwig , Jens Axboe , Ming Lei , Arnd Bergmann , Ulf Hansson , Nicolas Pitre , Aaro Koskinen , Adrian Hunter , Angelo Dureghello Cc: linux-mmc@vger.kernel.org, linux-block@vger.kernel.org, linux-omap@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 Use the scatterlist memory iterator instead of just dereferencing virtual memory using sg_virt(). This make highmem references work properly. Suggested-by: Christoph Hellwig Link: https://lore.kernel.org/linux-mmc/20240122073423.GA25859@lst.de/ Signed-off-by: Linus Walleij --- drivers/mmc/host/omap.c | 53 ++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c index 9fb8995b43a1..088f8ed4fdc4 100644 --- a/drivers/mmc/host/omap.c +++ b/drivers/mmc/host/omap.c @@ -148,10 +148,8 @@ struct mmc_omap_host { struct work_struct send_stop_work; struct mmc_data *stop_data; + struct sg_mapping_iter sg_miter; unsigned int sg_len; - int sg_idx; - u16 * buffer; - u32 buffer_bytes_left; u32 total_bytes_left; unsigned features; @@ -456,6 +454,8 @@ mmc_omap_xfer_done(struct mmc_omap_host *host, struct mmc_data *data) { if (host->dma_in_use) mmc_omap_release_dma(host, data, data->error); + else + sg_miter_stop(&host->sg_miter); host->data = NULL; host->sg_len = 0; @@ -651,19 +651,6 @@ mmc_omap_cmd_timer(struct timer_list *t) spin_unlock_irqrestore(&host->slot_lock, flags); } -/* PIO only */ -static void -mmc_omap_sg_to_buf(struct mmc_omap_host *host) -{ - struct scatterlist *sg; - - sg = host->data->sg + host->sg_idx; - host->buffer_bytes_left = sg->length; - host->buffer = sg_virt(sg); - if (host->buffer_bytes_left > host->total_bytes_left) - host->buffer_bytes_left = host->total_bytes_left; -} - static void mmc_omap_clk_timer(struct timer_list *t) { @@ -676,33 +663,37 @@ mmc_omap_clk_timer(struct timer_list *t) static void mmc_omap_xfer_data(struct mmc_omap_host *host, int write) { + struct sg_mapping_iter *sgm = &host->sg_miter; int n, nwords; + u16 *buffer; - if (host->buffer_bytes_left == 0) { - host->sg_idx++; - BUG_ON(host->sg_idx == host->sg_len); - mmc_omap_sg_to_buf(host); + if (!sg_miter_next(sgm)) { + /* This should not happen */ + dev_err(mmc_dev(host->mmc), "ran out of scatterlist prematurely\n"); + return; } + buffer = sgm->addr; + n = 64; - if (n > host->buffer_bytes_left) - n = host->buffer_bytes_left; + if (n > sgm->length) + n = sgm->length; + if (n > host->total_bytes_left) + n = host->total_bytes_left; /* Round up to handle odd number of bytes to transfer */ nwords = DIV_ROUND_UP(n, 2); - host->buffer_bytes_left -= n; + sgm->consumed = n; host->total_bytes_left -= n; host->data->bytes_xfered += n; if (write) { __raw_writesw(host->virt_base + OMAP_MMC_REG(host, DATA), - host->buffer, nwords); + buffer, nwords); } else { __raw_readsw(host->virt_base + OMAP_MMC_REG(host, DATA), - host->buffer, nwords); + buffer, nwords); } - - host->buffer += nwords; } #ifdef CONFIG_MMC_DEBUG @@ -956,6 +947,7 @@ static inline void set_data_timeout(struct mmc_omap_host *host, struct mmc_reque static void mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req) { + unsigned int miter_flags = SG_MITER_ATOMIC; /* Used from IRQ */ struct mmc_data *data = req->data; int i, use_dma = 1, block_size; struct scatterlist *sg; @@ -990,7 +982,6 @@ mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req) } } - host->sg_idx = 0; if (use_dma) { enum dma_data_direction dma_data_dir; struct dma_async_tx_descriptor *tx; @@ -1071,7 +1062,11 @@ mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req) OMAP_MMC_WRITE(host, BUF, 0x1f1f); host->total_bytes_left = data->blocks * block_size; host->sg_len = sg_len; - mmc_omap_sg_to_buf(host); + if (data->flags & MMC_DATA_READ) + miter_flags |= SG_MITER_TO_SG; + else + miter_flags |= SG_MITER_FROM_SG; + sg_miter_start(&host->sg_miter, data->sg, data->sg_len, miter_flags); host->dma_in_use = 0; } From patchwork Sat Jan 27 00:19:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 767082 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 733ADEA8 for ; Sat, 27 Jan 2024 00:20:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314824; cv=none; b=RBYnRy/vcl4lTKzPtY0nmOfBaMAhUDnNu4O0iU4YT2yVqrYlFqqIZfdb9KkZJb663nsk8Mjxu7ASFyMyvmfShLYVvoxxbq1MX4fyemjAFue8QKdmQLXwXZPQky1cyegxBFqCiZwVleggLdu4FZb4nKB4EQxksCM04JP+X0I5XwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314824; c=relaxed/simple; bh=11tgqTYTTcAC/xg5mxKcSDPSUwbnuZsCql+ezd70tYo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=K1eh2ytIWY+kMPFAHuCc+vkWaQK7zl/y4mUEEVwcIH5am5WQtVH+JK07CpeqEKCmnG36dH6UQsItK6wI5dTsTjh7hCwvySWc7l/mP6fjoBfxKVvLm1ZlqnjHEWEyVf2OrR1HMdHPxEIADm2aKKw015vSx2yy7GpE/+Nkm9sB6Kw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=M4fXkVNu; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="M4fXkVNu" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-5102a2e4b7bso1090302e87.1 for ; Fri, 26 Jan 2024 16:20:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706314820; x=1706919620; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=OF+atUpH2jGXdb8/KiqqDPha8EDyadeWwvv8sbSBzHk=; b=M4fXkVNuCAPPcn7ZXSnRL8SP3zLpOJUqHIoVJrAlQHMP/rMy56qtbN3Fv6Tql1/8EB 0mlcxFm9YsXFRA3+Axi1L/hqrUjVA/DzmaNIdFAcsMj5rYdVFGsSdHHugnLGl6IP+Sb5 BBFdcxXGrmamiWLVTt453/IrL3XDDzfFa4rl+ONwLG/1Md6KYe2HEtiK86GlfXQrKAjk ErDQ1Ox8BUgCYAvCJ4QGwlrg8Lgcy+oOMs/3W2robN5rZhtdV6e9DiTRbdwpUh+VTt60 WDWq9cJGsPBrvZkxrzsrAMwgwn54tb1O2zJdNBUxji30qdVNKH/U0VLyhpUAT2rzJSKD UIuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706314820; x=1706919620; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OF+atUpH2jGXdb8/KiqqDPha8EDyadeWwvv8sbSBzHk=; b=OVKlET+Kq7WFjfigcUClJ14l6SvoK9OuMCNDBUpXD189zhVVH9qshM2+UaENTFDJ4T IVEY2QUg5OBb29oN7JT4tEXUUYCHoKRy7qZthXxWKc7CL2LtQ957uEyfvNqbnImPgI5m cOY+2KCXyRltRRHWCfCk7tYuHUP+R0lxxJV6XDuK492pYNVhjggTCf183hzRanlgyuQ/ 8L4hqqwGptlxvKbt7pgOYMVwrns2pswTZB4ZyENOFnKxJkycJMLBIg81VtX/ctSs/VmG QZRTcKY7JcL7aEtYUu9J3160H75MLwCJ0IWNRWwdEkUJzOXBfX6r1tPSenIpJqEwqcFW hXfg== X-Gm-Message-State: AOJu0Yx7MNxqb8ZIj89Q1WC0genZ/6blkEQQpXDVPC1isTN4xzGU2Bhg CV7CSO7B0tRC8ngBMzAd0shnTwNZrgd+6ZgvS5Y2hdClN7pBurESSqJ+hlc3/CM= X-Google-Smtp-Source: AGHT+IGu2Zjg0R7ovqlG5rze1HiowsVGljfHEkvyIteXZVo1ZS9Bo68Lc0U++8crpiCyQbpFoddHYg== X-Received: by 2002:a05:6512:2204:b0:510:27f2:2621 with SMTP id h4-20020a056512220400b0051027f22621mr224564lfu.23.1706314820506; Fri, 26 Jan 2024 16:20:20 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x25-20020a19f619000000b0050e7f5cffa6sm325226lfe.273.2024.01.26.16.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 16:20:20 -0800 (PST) From: Linus Walleij Date: Sat, 27 Jan 2024 01:19:55 +0100 Subject: [PATCH v2 8/9] mmc: sdhci-esdhc-mcf: Use sg_miter for swapping Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240127-mmc-proper-kmap-v2-8-d8e732aa97d1@linaro.org> References: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> In-Reply-To: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> To: Christoph Hellwig , Jens Axboe , Ming Lei , Arnd Bergmann , Ulf Hansson , Nicolas Pitre , Aaro Koskinen , Adrian Hunter , Angelo Dureghello Cc: linux-mmc@vger.kernel.org, linux-block@vger.kernel.org, linux-omap@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 Use sg_miter iterator instead of sg_virt() and custom code to loop over the scatterlist. The memory iterator will do bounce buffering if the page happens to be located in high memory, which the driver may or may not be using. Suggested-by: Christoph Hellwig Link: https://lore.kernel.org/linux-mmc/20240122073423.GA25859@lst.de/ Signed-off-by: Linus Walleij --- drivers/mmc/host/sdhci-esdhc-mcf.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/host/sdhci-esdhc-mcf.c b/drivers/mmc/host/sdhci-esdhc-mcf.c index a07f8333cd6b..1909a11fd065 100644 --- a/drivers/mmc/host/sdhci-esdhc-mcf.c +++ b/drivers/mmc/host/sdhci-esdhc-mcf.c @@ -299,9 +299,8 @@ static void esdhc_mcf_pltfm_set_bus_width(struct sdhci_host *host, int width) static void esdhc_mcf_request_done(struct sdhci_host *host, struct mmc_request *mrq) { - struct scatterlist *sg; + struct sg_mapping_iter sgm; u32 *buffer; - int i; if (!mrq->data || !mrq->data->bytes_xfered) goto exit_done; @@ -313,10 +312,13 @@ static void esdhc_mcf_request_done(struct sdhci_host *host, * On mcf5441x there is no hw sdma option/flag to select the dma * transfer endiannes. A swap after the transfer is needed. */ - for_each_sg(mrq->data->sg, sg, mrq->data->sg_len, i) { - buffer = (u32 *)sg_virt(sg); - esdhc_mcf_buffer_swap32(buffer, sg->length); + sg_miter_start(&sgm, mrq->data->sg, mrq->data->sg_len, + SG_MITER_TO_SG | SG_MITER_FROM_SG); + while (sg_miter_next(&sgm)) { + buffer = sgm.addr; + esdhc_mcf_buffer_swap32(buffer, sgm.length); } + sg_miter_stop(&sgm); exit_done: mmc_request_done(host->mmc, mrq); From patchwork Sat Jan 27 00:19:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 767081 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDE9E3D6C for ; Sat, 27 Jan 2024 00:20:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314825; cv=none; b=rIlS8PS0qPzg1NWpmj2r9F7u4YgccmXOr8WQTIqQkooXsuilFqfh3XyqIPoDl7bOpA3BLhXtbClIIR380OKYhisXKEeIZ4XJGkBPTLNzb7IXFdWalVgIy0mPtiWt7wkXwbk+f0HhW83va9GRry9E5oi1iLf0K2PHOw/U8ydMKLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314825; c=relaxed/simple; bh=m64DINGtjwCb4sGpGFmOo+EROZNKY2mbmaeuUuBBRqU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GGxbd6YUexxYkgKrZqo1YgEPW/6nGHH7WNpHXXouIHpT0NkwVn1t9/3wppgbGXXvndtec0yC0hbS7ZSS+BWdxwxeZukEvSXNgIEOfDIzrMiUcat94Bu54y2U2G/qpTezbx99EnBmhw7tQ5Vw+N6XhVZqdGsAQXpVX4veBbg0JsM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=RYLiIB4A; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="RYLiIB4A" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-51025cafb51so1363745e87.2 for ; Fri, 26 Jan 2024 16:20:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706314822; x=1706919622; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=H6xRTgWpwVbdQrYrVCpj0/5DkwYyjb0pfDixXSPxg08=; b=RYLiIB4ADJHqpt3w+GfoD4jp2simx33+zgqY8KZJz2yIZURm2B9EXPDTS0/r0GfBTp xKSC/l2vAZYkoflIvphhspZYegwjiakFVmaIMr6Lh/XupXMo+GtyOPkF6hSEK/Fuww1g ynPuvL5xEfcWNh2MfR42Y49ks6xzvJi62OnfD6LtAa+IxTBM++2kba+JFO0Bfrlh3KdW FhxK2Nd3DHIjXA8DaPVqlxznpSwwLZ75aLpAV/UN5quT5qev3QXAYIPcFshCb9GsUqUH Qf4thQ0tg81raETEun2Em2qFHwQIO8vj3dvX814xTnGWb0q4ZQE/7v9hf12sUueYqV8H yWlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706314822; x=1706919622; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H6xRTgWpwVbdQrYrVCpj0/5DkwYyjb0pfDixXSPxg08=; b=tFWJfshGfMcQ64wDl16RagDSeba1Ak+Qeb/+ssekLYpmBOgHap8WdBfk/LtPZ+sB8R 8nTevsbee34PlF3erVI1gYlRT3nk3erre2CDQD0/3gX/I1Nmod1zWYd08T2x2ho30e4x moELUwkjd+dEsX5hTJlSfE3UOO8QjpOqKtMcoc62tO+j5dAmY7tVKteSc2dW+Eqzz12r AhvJwQzfGrLUJSitQYo60I14FyWvxJnTBuKrHdNgJX1yEG3tFvdc3/cJ2mwFEyeK4MoM lkVFIu1SHFyxjc7nOxFBCQq53YpnJ9/7WtQwKSqvsJPSMaBIxk9Fq9O2PKEngj0VUc0W pbtA== X-Gm-Message-State: AOJu0YyKH7VpSgYX6F+Ur9SWTWTggh1I6dpRxKDTpfBMRYFFfUVnPyn+ +j346Sem65BAhGOZl17ceksA4C2A2Mlly6XrSgUuCYKZJSf1AFue1l9BWTQqowHizviKt2YaZAD H X-Google-Smtp-Source: AGHT+IFODti9q2E+Agfa3fBrMz3o9POZ0N1iM9LXhM4BVi8Jox9fI3RwAY18ghi+6oR5uiYdJhU9kQ== X-Received: by 2002:ac2:4907:0:b0:510:c62:d97b with SMTP id n7-20020ac24907000000b005100c62d97bmr305904lfi.45.1706314822099; Fri, 26 Jan 2024 16:20:22 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id x25-20020a19f619000000b0050e7f5cffa6sm325226lfe.273.2024.01.26.16.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 16:20:21 -0800 (PST) From: Linus Walleij Date: Sat, 27 Jan 2024 01:19:56 +0100 Subject: [PATCH v2 9/9] mmc: sh_mmcif: Use sg_miter for PIO Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240127-mmc-proper-kmap-v2-9-d8e732aa97d1@linaro.org> References: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> In-Reply-To: <20240127-mmc-proper-kmap-v2-0-d8e732aa97d1@linaro.org> To: Christoph Hellwig , Jens Axboe , Ming Lei , Arnd Bergmann , Ulf Hansson , Nicolas Pitre , Aaro Koskinen , Adrian Hunter , Angelo Dureghello Cc: linux-mmc@vger.kernel.org, linux-block@vger.kernel.org, linux-omap@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 Use sg_miter iterator instead of sg_virt() and custom code to loop over the scatterlist. The memory iterator will do bounce buffering if the page happens to be located in high memory, which the driver may or may not be using. Suggested-by: Christoph Hellwig Link: https://lore.kernel.org/linux-mmc/20240122073423.GA25859@lst.de/ Signed-off-by: Linus Walleij --- drivers/mmc/host/sh_mmcif.c | 102 +++++++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 39 deletions(-) diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c index 077d711e964e..1ef6e153e5a3 100644 --- a/drivers/mmc/host/sh_mmcif.c +++ b/drivers/mmc/host/sh_mmcif.c @@ -227,14 +227,12 @@ struct sh_mmcif_host { bool dying; long timeout; void __iomem *addr; - u32 *pio_ptr; spinlock_t lock; /* protect sh_mmcif_host::state */ enum sh_mmcif_state state; enum sh_mmcif_wait_for wait_for; struct delayed_work timeout_work; size_t blocksize; - int sg_idx; - int sg_blkidx; + struct sg_mapping_iter sg_miter; bool power; bool ccs_enable; /* Command Completion Signal support */ bool clk_ctrl2_enable; @@ -600,32 +598,17 @@ static int sh_mmcif_error_manage(struct sh_mmcif_host *host) return ret; } -static bool sh_mmcif_next_block(struct sh_mmcif_host *host, u32 *p) -{ - struct mmc_data *data = host->mrq->data; - - host->sg_blkidx += host->blocksize; - - /* data->sg->length must be a multiple of host->blocksize? */ - BUG_ON(host->sg_blkidx > data->sg->length); - - if (host->sg_blkidx == data->sg->length) { - host->sg_blkidx = 0; - if (++host->sg_idx < data->sg_len) - host->pio_ptr = sg_virt(++data->sg); - } else { - host->pio_ptr = p; - } - - return host->sg_idx != data->sg_len; -} - static void sh_mmcif_single_read(struct sh_mmcif_host *host, struct mmc_request *mrq) { + struct mmc_data *data = mrq->data; + host->blocksize = (sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) & BLOCK_SIZE_MASK) + 3; + sg_miter_start(&host->sg_miter, data->sg, data->sg_len, + SG_MITER_ATOMIC | SG_MITER_TO_SG); + host->wait_for = MMCIF_WAIT_FOR_READ; /* buf read enable */ @@ -634,20 +617,32 @@ static void sh_mmcif_single_read(struct sh_mmcif_host *host, static bool sh_mmcif_read_block(struct sh_mmcif_host *host) { + struct sg_mapping_iter *sgm = &host->sg_miter; struct device *dev = sh_mmcif_host_to_dev(host); struct mmc_data *data = host->mrq->data; - u32 *p = sg_virt(data->sg); + u32 *p; int i; if (host->sd_error) { + sg_miter_stop(sgm); data->error = sh_mmcif_error_manage(host); dev_dbg(dev, "%s(): %d\n", __func__, data->error); return false; } + if (!sg_miter_next(sgm)) { + /* This should not happen on single blocks */ + sg_miter_stop(sgm); + return false; + } + + p = sgm->addr; + for (i = 0; i < host->blocksize / 4; i++) *p++ = sh_mmcif_readl(host->addr, MMCIF_CE_DATA); + sg_miter_stop(&host->sg_miter); + /* buffer read end */ sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFRE); host->wait_for = MMCIF_WAIT_FOR_READ_END; @@ -666,34 +661,40 @@ static void sh_mmcif_multi_read(struct sh_mmcif_host *host, host->blocksize = sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) & BLOCK_SIZE_MASK; + sg_miter_start(&host->sg_miter, data->sg, data->sg_len, + SG_MITER_ATOMIC | SG_MITER_TO_SG); + host->wait_for = MMCIF_WAIT_FOR_MREAD; - host->sg_idx = 0; - host->sg_blkidx = 0; - host->pio_ptr = sg_virt(data->sg); sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN); } static bool sh_mmcif_mread_block(struct sh_mmcif_host *host) { + struct sg_mapping_iter *sgm = &host->sg_miter; struct device *dev = sh_mmcif_host_to_dev(host); struct mmc_data *data = host->mrq->data; - u32 *p = host->pio_ptr; + u32 *p; int i; if (host->sd_error) { + sg_miter_stop(sgm); data->error = sh_mmcif_error_manage(host); dev_dbg(dev, "%s(): %d\n", __func__, data->error); return false; } - BUG_ON(!data->sg->length); + if (!sg_miter_next(sgm)) { + sg_miter_stop(sgm); + return false; + } + + p = sgm->addr; for (i = 0; i < host->blocksize / 4; i++) *p++ = sh_mmcif_readl(host->addr, MMCIF_CE_DATA); - if (!sh_mmcif_next_block(host, p)) - return false; + sgm->consumed = host->blocksize; sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN); @@ -703,9 +704,14 @@ static bool sh_mmcif_mread_block(struct sh_mmcif_host *host) static void sh_mmcif_single_write(struct sh_mmcif_host *host, struct mmc_request *mrq) { + struct mmc_data *data = mrq->data; + host->blocksize = (sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) & BLOCK_SIZE_MASK) + 3; + sg_miter_start(&host->sg_miter, data->sg, data->sg_len, + SG_MITER_ATOMIC | SG_MITER_FROM_SG); + host->wait_for = MMCIF_WAIT_FOR_WRITE; /* buf write enable */ @@ -714,20 +720,32 @@ static void sh_mmcif_single_write(struct sh_mmcif_host *host, static bool sh_mmcif_write_block(struct sh_mmcif_host *host) { + struct sg_mapping_iter *sgm = &host->sg_miter; struct device *dev = sh_mmcif_host_to_dev(host); struct mmc_data *data = host->mrq->data; - u32 *p = sg_virt(data->sg); + u32 *p; int i; if (host->sd_error) { + sg_miter_stop(sgm); data->error = sh_mmcif_error_manage(host); dev_dbg(dev, "%s(): %d\n", __func__, data->error); return false; } + if (!sg_miter_next(sgm)) { + /* This should not happen on single blocks */ + sg_miter_stop(sgm); + return false; + } + + p = sgm->addr; + for (i = 0; i < host->blocksize / 4; i++) sh_mmcif_writel(host->addr, MMCIF_CE_DATA, *p++); + sg_miter_stop(&host->sg_miter); + /* buffer write end */ sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MDTRANE); host->wait_for = MMCIF_WAIT_FOR_WRITE_END; @@ -746,34 +764,40 @@ static void sh_mmcif_multi_write(struct sh_mmcif_host *host, host->blocksize = sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) & BLOCK_SIZE_MASK; + sg_miter_start(&host->sg_miter, data->sg, data->sg_len, + SG_MITER_ATOMIC | SG_MITER_FROM_SG); + host->wait_for = MMCIF_WAIT_FOR_MWRITE; - host->sg_idx = 0; - host->sg_blkidx = 0; - host->pio_ptr = sg_virt(data->sg); sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN); } static bool sh_mmcif_mwrite_block(struct sh_mmcif_host *host) { + struct sg_mapping_iter *sgm = &host->sg_miter; struct device *dev = sh_mmcif_host_to_dev(host); struct mmc_data *data = host->mrq->data; - u32 *p = host->pio_ptr; + u32 *p; int i; if (host->sd_error) { + sg_miter_stop(sgm); data->error = sh_mmcif_error_manage(host); dev_dbg(dev, "%s(): %d\n", __func__, data->error); return false; } - BUG_ON(!data->sg->length); + if (!sg_miter_next(sgm)) { + sg_miter_stop(sgm); + return false; + } + + p = sgm->addr; for (i = 0; i < host->blocksize / 4; i++) sh_mmcif_writel(host->addr, MMCIF_CE_DATA, *p++); - if (!sh_mmcif_next_block(host, p)) - return false; + sgm->consumed = host->blocksize; sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);