mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Denis Orlov <denorl2009@gmail.com>
To: barebox@lists.infradead.org
Cc: Denis Orlov <denorl2009@gmail.com>
Subject: [PATCH 10/16] ata: ahci: map buffers properly
Date: Wed,  4 May 2022 12:25:47 +0300	[thread overview]
Message-ID: <20220504092553.27961-10-denorl2009@gmail.com> (raw)
In-Reply-To: <20220504092553.27961-1-denorl2009@gmail.com>

Using dma_sync_single_for_*() does not make sense in there - we are
given a cpu side address of a buffer and need to actually map it for
the device.

Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
 drivers/ata/ahci.c | 37 ++++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 1d8099c2ee..ff9093c7b7 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -121,7 +121,7 @@ static void ahci_fill_cmd_slot(struct ahci_port *ahci_port, u32 opts)
 	ahci_port->cmd_slot->tbl_addr_hi = 0;
 }
 
-static int ahci_fill_sg(struct ahci_port *ahci_port, const void *buf, int buf_len)
+static int ahci_fill_sg(struct ahci_port *ahci_port, dma_addr_t buf_dma, int buf_len)
 {
 	struct ahci_sg *ahci_sg = ahci_port->cmd_tbl_sg;
 	u32 sg_count;
@@ -133,12 +133,12 @@ static int ahci_fill_sg(struct ahci_port *ahci_port, const void *buf, int buf_le
 	while (buf_len) {
 		unsigned int now = min(AHCI_MAX_DATA_BYTE_COUNT, buf_len);
 
-		ahci_sg->addr = cpu_to_le32((u32)buf);
+		ahci_sg->addr = cpu_to_le32(buf_dma);
 		ahci_sg->addr_hi = 0;
 		ahci_sg->flags_size = cpu_to_le32(now - 1);
 
 		buf_len -= now;
-		buf += now;
+		buf_dma += now;
 		ahci_sg++;
 	}
 
@@ -151,20 +151,26 @@ static int ahci_io(struct ahci_port *ahci_port, u8 *fis, int fis_len, void *rbuf
 	u32 opts;
 	int sg_count;
 	int ret;
+	void *buf;
+	dma_addr_t buf_dma;
+	enum dma_data_direction dma_dir;
 
 	if (!ahci_link_ok(ahci_port, 1))
 		return -EIO;
 
-	if (wbuf)
-		dma_sync_single_for_device((unsigned long)wbuf, buf_len,
-					   DMA_TO_DEVICE);
-	if (rbuf)
-		dma_sync_single_for_device((unsigned long)rbuf, buf_len,
-					   DMA_FROM_DEVICE);
+	if (wbuf) {
+		buf = (void *)wbuf;
+		dma_dir = DMA_TO_DEVICE;
+	} else {
+		buf = rbuf;
+		dma_dir = DMA_FROM_DEVICE;
+	}
+
+	buf_dma = dma_map_single(ahci_port->ahci->dev, buf, buf_len, dma_dir);
 
 	memcpy((unsigned char *)ahci_port->cmd_tbl, fis, fis_len);
 
-	sg_count = ahci_fill_sg(ahci_port, rbuf ? rbuf : wbuf, buf_len);
+	sg_count = ahci_fill_sg(ahci_port, buf_dma, buf_len);
 	opts = (fis_len >> 2) | (sg_count << 16);
 	if (wbuf)
 		opts |= CMD_LIST_OPTS_WRITE;
@@ -174,17 +180,10 @@ static int ahci_io(struct ahci_port *ahci_port, u8 *fis, int fis_len, void *rbuf
 
 	ret = wait_on_timeout(WAIT_DATAIO,
 			(ahci_port_read(ahci_port, PORT_CMD_ISSUE) & 0x1) == 0);
-	if (ret)
-		return -ETIMEDOUT;
 
-	if (wbuf)
-		dma_sync_single_for_cpu((unsigned long)wbuf, buf_len,
-					DMA_TO_DEVICE);
-	if (rbuf)
-		dma_sync_single_for_cpu((unsigned long)rbuf, buf_len,
-					DMA_FROM_DEVICE);
+	dma_unmap_single(ahci_port->ahci->dev, buf_dma, buf_len, dma_dir);
 
-	return 0;
+	return ret;
 }
 
 /*
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2022-05-04  9:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-04  9:25 [PATCH 01/16] ata: ahci: use abstract read/write functions uniformly Denis Orlov
2022-05-04  9:25 ` [PATCH 02/16] ata: ahci: replace magic numbers with named constants Denis Orlov
2022-05-04  9:25 ` [PATCH 03/16] ata: ahci: fix missing whitespace in ahci_add_host() Denis Orlov
2022-05-04  9:25 ` [PATCH 04/16] ata: ahci: simplify fis structure creation Denis Orlov
2022-05-04  9:25 ` [PATCH 05/16] ata: ahci: do not ignore dma handles Denis Orlov
2022-05-04  9:25 ` [PATCH 06/16] ata: ahci: adjust debug messages in ahci_init_port() Denis Orlov
2022-05-04  9:25 ` [PATCH 07/16] ata: ahci: correct named constants values and names Denis Orlov
2022-05-04  9:25 ` [PATCH 08/16] ata: ahci: properly fill scatter/gather table Denis Orlov
2022-05-04  9:25 ` [PATCH 09/16] ata: ahci: use named constants for capabilities bits Denis Orlov
2022-05-04  9:25 ` Denis Orlov [this message]
2022-05-04  9:25 ` [PATCH 11/16] ata: ahci: use 64-bit addressing if available Denis Orlov
2022-05-04  9:25 ` [PATCH 12/16] ata: ahci: make rx_fis field in ahci_port of type void* Denis Orlov
2022-05-04  9:25 ` [PATCH 13/16] ata: ahci: add missing capability in ahci_print_info() Denis Orlov
2022-05-04  9:25 ` [PATCH 14/16] ata: ahci: remove redundant cast in ahci_io() Denis Orlov
2022-05-04  9:25 ` [PATCH 15/16] ata: ahci: register only implemented ports Denis Orlov
2022-05-04  9:25 ` [PATCH 16/16] ata: ahci: allocate memory in one call in ahci_init_port() Denis Orlov
2022-05-05  7:48 ` [PATCH 01/16] ata: ahci: use abstract read/write functions uniformly Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220504092553.27961-10-denorl2009@gmail.com \
    --to=denorl2009@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox