diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 18:50:36 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 18:50:36 +0000 |
commit | 50ba0232fd5312410f1b65247e774244f89a628e (patch) | |
tree | fd8f2fc78e9e548af0ff9590276602ee6125be00 /drivers/i3c/master/mipi-i3c-hci | |
parent | Releasing progress-linux version 6.7.12-1~progress7.99u1. (diff) | |
download | linux-50ba0232fd5312410f1b65247e774244f89a628e.tar.xz linux-50ba0232fd5312410f1b65247e774244f89a628e.zip |
Merging upstream version 6.8.9.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'drivers/i3c/master/mipi-i3c-hci')
-rw-r--r-- | drivers/i3c/master/mipi-i3c-hci/cmd_v1.c | 7 | ||||
-rw-r--r-- | drivers/i3c/master/mipi-i3c-hci/core.c | 49 | ||||
-rw-r--r-- | drivers/i3c/master/mipi-i3c-hci/dma.c | 4 | ||||
-rw-r--r-- | drivers/i3c/master/mipi-i3c-hci/hci.h | 1 |
4 files changed, 56 insertions, 5 deletions
diff --git a/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c b/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c index 2b2323aa67..638b054d6c 100644 --- a/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c +++ b/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c @@ -298,7 +298,7 @@ static int hci_cmd_v1_daa(struct i3c_hci *hci) unsigned int dcr, bcr; DECLARE_COMPLETION_ONSTACK(done); - xfer = hci_alloc_xfer(2); + xfer = hci_alloc_xfer(1); if (!xfer) return -ENOMEM; @@ -339,12 +339,13 @@ static int hci_cmd_v1_daa(struct i3c_hci *hci) ret = -ETIME; break; } - if (RESP_STATUS(xfer[0].response) == RESP_ERR_NACK && + if ((RESP_STATUS(xfer->response) == RESP_ERR_ADDR_HEADER || + RESP_STATUS(xfer->response) == RESP_ERR_NACK) && RESP_DATA_LENGTH(xfer->response) == 1) { ret = 0; /* no more devices to be assigned */ break; } - if (RESP_STATUS(xfer[0].response) != RESP_SUCCESS) { + if (RESP_STATUS(xfer->response) != RESP_SUCCESS) { ret = -EIO; break; } diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c index 1ae56a5699..d7e966a255 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -245,7 +245,14 @@ static int i3c_hci_send_ccc_cmd(struct i3c_master_controller *m, if (ccc->rnw) ccc->dests[i - prefixed].payload.len = RESP_DATA_LENGTH(xfer[i].response); - if (RESP_STATUS(xfer[i].response) != RESP_SUCCESS) { + switch (RESP_STATUS(xfer[i].response)) { + case RESP_SUCCESS: + continue; + case RESP_ERR_ADDR_HEADER: + case RESP_ERR_NACK: + ccc->err = I3C_ERROR_M2; + fallthrough; + default: ret = -EIO; goto out; } @@ -269,6 +276,34 @@ static int i3c_hci_daa(struct i3c_master_controller *m) return hci->cmd->perform_daa(hci); } +static int i3c_hci_alloc_safe_xfer_buf(struct i3c_hci *hci, + struct hci_xfer *xfer) +{ + if (hci->io != &mipi_i3c_hci_dma || + xfer->data == NULL || !is_vmalloc_addr(xfer->data)) + return 0; + + if (xfer->rnw) + xfer->bounce_buf = kzalloc(xfer->data_len, GFP_KERNEL); + else + xfer->bounce_buf = kmemdup(xfer->data, + xfer->data_len, GFP_KERNEL); + + return xfer->bounce_buf == NULL ? -ENOMEM : 0; +} + +static void i3c_hci_free_safe_xfer_buf(struct i3c_hci *hci, + struct hci_xfer *xfer) +{ + if (hci->io != &mipi_i3c_hci_dma || xfer->bounce_buf == NULL) + return; + + if (xfer->rnw) + memcpy(xfer->data, xfer->bounce_buf, xfer->data_len); + + kfree(xfer->bounce_buf); +} + static int i3c_hci_priv_xfers(struct i3c_dev_desc *dev, struct i3c_priv_xfer *i3c_xfers, int nxfers) @@ -302,6 +337,9 @@ static int i3c_hci_priv_xfers(struct i3c_dev_desc *dev, } hci->cmd->prep_i3c_xfer(hci, dev, &xfer[i]); xfer[i].cmd_desc[0] |= CMD_0_ROC; + ret = i3c_hci_alloc_safe_xfer_buf(hci, &xfer[i]); + if (ret) + goto out; } last = i - 1; xfer[last].cmd_desc[0] |= CMD_0_TOC; @@ -325,6 +363,9 @@ static int i3c_hci_priv_xfers(struct i3c_dev_desc *dev, } out: + for (i = 0; i < nxfers; i++) + i3c_hci_free_safe_xfer_buf(hci, &xfer[i]); + hci_free_xfer(xfer, nxfers); return ret; } @@ -350,6 +391,9 @@ static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev, xfer[i].rnw = i2c_xfers[i].flags & I2C_M_RD; hci->cmd->prep_i2c_xfer(hci, dev, &xfer[i]); xfer[i].cmd_desc[0] |= CMD_0_ROC; + ret = i3c_hci_alloc_safe_xfer_buf(hci, &xfer[i]); + if (ret) + goto out; } last = i - 1; xfer[last].cmd_desc[0] |= CMD_0_TOC; @@ -371,6 +415,9 @@ static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev, } out: + for (i = 0; i < nxfers; i++) + i3c_hci_free_safe_xfer_buf(hci, &xfer[i]); + hci_free_xfer(xfer, nxfers); return ret; } diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mipi-i3c-hci/dma.c index c805a84973..4e01a95cc4 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -362,6 +362,7 @@ static int hci_dma_queue_xfer(struct i3c_hci *hci, struct hci_rh_data *rh; unsigned int i, ring, enqueue_ptr; u32 op1_val, op2_val; + void *buf; /* For now we only use ring 0 */ ring = 0; @@ -390,9 +391,10 @@ static int hci_dma_queue_xfer(struct i3c_hci *hci, /* 2nd and 3rd words of Data Buffer Descriptor Structure */ if (xfer->data) { + buf = xfer->bounce_buf ? xfer->bounce_buf : xfer->data; xfer->data_dma = dma_map_single(&hci->master.dev, - xfer->data, + buf, xfer->data_len, xfer->rnw ? DMA_FROM_DEVICE : diff --git a/drivers/i3c/master/mipi-i3c-hci/hci.h b/drivers/i3c/master/mipi-i3c-hci/hci.h index f109923f6c..f94d95e024 100644 --- a/drivers/i3c/master/mipi-i3c-hci/hci.h +++ b/drivers/i3c/master/mipi-i3c-hci/hci.h @@ -90,6 +90,7 @@ struct hci_xfer { struct { /* DMA specific */ dma_addr_t data_dma; + void *bounce_buf; int ring_number; int ring_entry; }; |