mirror of
https://github.com/torvalds/linux.git
synced 2026-11-20 13:03:48 +00:00
Merge tag 'spi-fix-v7.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
Pull spi fixes from Mark Brown: "As well as a few driver specific fixes we have a couple of core fixes here. One avoids requesting interrupts until we have validated that we have a SPI device, avoiding triggering warnings on boot. The other avoids a request for a zero length scatterlist triggering a BUG_ON() in swiotlb on 64k page systems, this was due to using both DIV_ROUND_UP() and min() to compute lengths" * tag 'spi-fix-v7.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: spi: cadence-quadspi: Fix race between DMA completion and transfer start spi: ljca: Don't require data in write replies spi: acpi: only look up the IRQ of confirmed SPI devices spi: pic32-sqi: fail transfer when the BD ring is exhausted spi: fix zero-length scatterlist entries for vmalloc buffers spi: rtk-nor: Limit exec_op writes to one byte per operation spi: amd: validate FIFO usage before executing message
This commit is contained in:
+10
-14
@@ -331,13 +331,6 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi,
|
||||
else
|
||||
amd_set_spi_freq(amd_spi, spi->max_speed_hz);
|
||||
|
||||
/* Reject transfers that would overflow the FIFO window */
|
||||
if (fifo_pos + xfer->len >
|
||||
AMD_SPI_FIFO_BASE + AMD_SPI_FIFO_SIZE) {
|
||||
message->status = -EMSGSIZE;
|
||||
goto fin_msg;
|
||||
}
|
||||
|
||||
if (xfer->tx_buf) {
|
||||
buf = (u8 *)xfer->tx_buf;
|
||||
if (!tx_len) {
|
||||
@@ -346,6 +339,10 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi,
|
||||
xfer->len--;
|
||||
}
|
||||
tx_len += xfer->len;
|
||||
if (tx_len + rx_len > AMD_SPI_FIFO_SIZE) {
|
||||
message->status = -EMSGSIZE;
|
||||
goto fin_msg;
|
||||
}
|
||||
|
||||
/* Write data into the FIFO. */
|
||||
for (i = 0; i < xfer->len; i++)
|
||||
@@ -355,8 +352,13 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi,
|
||||
}
|
||||
|
||||
/* Store no. of bytes to be received from FIFO */
|
||||
if (xfer->rx_buf)
|
||||
if (xfer->rx_buf) {
|
||||
rx_len += xfer->len;
|
||||
if (tx_len + rx_len > AMD_SPI_FIFO_SIZE) {
|
||||
message->status = -EMSGSIZE;
|
||||
goto fin_msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!buf) {
|
||||
@@ -380,12 +382,6 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi,
|
||||
|
||||
list_for_each_entry(xfer, &message->transfers, transfer_list)
|
||||
if (xfer->rx_buf) {
|
||||
/* Reject transfers that would overflow the FIFO window */
|
||||
if (fifo_pos + xfer->len >
|
||||
AMD_SPI_FIFO_BASE + AMD_SPI_FIFO_SIZE) {
|
||||
message->status = -EMSGSIZE;
|
||||
goto fin_msg;
|
||||
}
|
||||
buf = (u8 *)xfer->rx_buf;
|
||||
/* Read data from FIFO to receive buffer */
|
||||
for (i = 0; i < xfer->len; i++)
|
||||
|
||||
@@ -955,11 +955,11 @@ static int cqspi_versal_indirect_read_dma(struct cqspi_flash_pdata *f_pdata,
|
||||
writel(CQSPI_REG_VERSAL_DMA_DST_CTRL_VAL,
|
||||
reg_base + CQSPI_REG_VERSAL_DMA_DST_CTRL);
|
||||
|
||||
reinit_completion(&cqspi->transfer_complete);
|
||||
|
||||
writel(CQSPI_REG_INDIRECTRD_START_MASK,
|
||||
reg_base + CQSPI_REG_INDIRECTRD);
|
||||
|
||||
reinit_completion(&cqspi->transfer_complete);
|
||||
|
||||
if (!wait_for_completion_timeout(&cqspi->transfer_complete,
|
||||
msecs_to_jiffies(max_t(size_t, bytes_to_dma, 500)))) {
|
||||
ret = -ETIMEDOUT;
|
||||
|
||||
@@ -109,8 +109,9 @@ static int ljca_spi_read_write(struct ljca_spi_dev *ljca_spi, const u8 *w_data,
|
||||
if (ret < sizeof(*r_packet))
|
||||
return -EIO;
|
||||
|
||||
if (!r_packet->len || ret < sizeof(*r_packet) + r_packet->len ||
|
||||
r_packet->len > len)
|
||||
/* write acks carry no payload */
|
||||
if (!r_packet->len || r_packet->len > len ||
|
||||
(r_data && ret < sizeof(*r_packet) + r_packet->len))
|
||||
return -EIO;
|
||||
|
||||
if (r_data)
|
||||
|
||||
@@ -297,7 +297,7 @@ static int pic32_sqi_one_transfer(struct pic32_sqi *sqi,
|
||||
/* get ring descriptor */
|
||||
rdesc = ring_desc_get(sqi);
|
||||
if (!rdesc)
|
||||
break;
|
||||
return -ENOMEM;
|
||||
|
||||
bd = rdesc->bd;
|
||||
|
||||
@@ -387,6 +387,7 @@ static int pic32_sqi_one_message(struct spi_controller *host,
|
||||
ret = pic32_sqi_one_transfer(sqi, msg, xfer);
|
||||
if (ret) {
|
||||
dev_err(&spi->dev, "xfer %p err\n", xfer);
|
||||
msg->status = ret;
|
||||
goto xfer_out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,6 +357,18 @@ static bool rtk_spi_supports_op(struct spi_mem *mem,
|
||||
return spi_mem_default_supports_op(mem, op);
|
||||
}
|
||||
|
||||
static int rtk_spi_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
|
||||
{
|
||||
/*
|
||||
* A write through exec_op is a single access to the data window,
|
||||
* which programs one byte. Let the caller split longer writes.
|
||||
*/
|
||||
if (op->data.dir == SPI_MEM_DATA_OUT && op->addr.nbytes)
|
||||
op->data.nbytes = min(op->data.nbytes, 1U);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rtk_spi_dirmap_create(struct spi_mem_dirmap_desc *desc)
|
||||
{
|
||||
const struct spi_mem_op *op = desc->info.op_tmpl;
|
||||
@@ -449,6 +461,7 @@ static const struct spi_controller_mem_ops rtk_spi_mem_ops = {
|
||||
.dirmap_create = rtk_spi_dirmap_create,
|
||||
.dirmap_read = rtk_spi_dirmap_read,
|
||||
.dirmap_write = rtk_spi_dirmap_write,
|
||||
.adjust_op_size = rtk_spi_adjust_op_size,
|
||||
};
|
||||
|
||||
static int rtk_spi_probe(struct platform_device *pdev)
|
||||
|
||||
+46
-10
@@ -1349,8 +1349,24 @@ static int spi_map_buf_attrs(struct spi_controller *ctlr, struct device *dev,
|
||||
int i, ret;
|
||||
|
||||
if (vmalloced_buf || kmap_buf) {
|
||||
desc_len = min_t(unsigned long, max_seg_size, PAGE_SIZE);
|
||||
sgs = DIV_ROUND_UP(len + offset_in_page(buf), desc_len);
|
||||
size_t off = offset_in_page(buf);
|
||||
size_t first = min_t(size_t, len, PAGE_SIZE - off);
|
||||
size_t rest;
|
||||
|
||||
desc_len = min_t(size_t, max_seg_size, PAGE_SIZE);
|
||||
/*
|
||||
* The buffer is first split at page boundaries, then every
|
||||
* piece is split into desc_len chunks. Sizing the table with
|
||||
* DIV_ROUND_UP(len + off, desc_len) does not model that and
|
||||
* leaves zero-length entries whenever a page boundary does
|
||||
* not coincide with a chunk boundary (which trips
|
||||
* BUG_ON(!nslots) in swiotlb on 64K pages).
|
||||
*/
|
||||
sgs = DIV_ROUND_UP(first, desc_len);
|
||||
rest = len - first;
|
||||
sgs += (rest / PAGE_SIZE) * DIV_ROUND_UP(PAGE_SIZE, desc_len);
|
||||
if (rest % PAGE_SIZE)
|
||||
sgs += DIV_ROUND_UP(rest % PAGE_SIZE, desc_len);
|
||||
} else if (virt_addr_valid(buf)) {
|
||||
desc_len = min_t(size_t, max_seg_size, ctlr->max_dma_len);
|
||||
sgs = DIV_ROUND_UP(len, desc_len);
|
||||
@@ -2995,7 +3011,6 @@ struct acpi_spi_lookup {
|
||||
acpi_handle device_handle;
|
||||
u32 max_speed_hz;
|
||||
u32 mode;
|
||||
int irq;
|
||||
u8 bits_per_word;
|
||||
u8 chip_select;
|
||||
int n;
|
||||
@@ -3138,17 +3153,25 @@ static int acpi_spi_add_resource(struct acpi_resource *ares, void *data)
|
||||
if (sb->device_polarity == ACPI_SPI_ACTIVE_HIGH)
|
||||
lookup->mode |= SPI_CS_HIGH;
|
||||
}
|
||||
} else if (lookup->irq < 0) {
|
||||
struct resource r;
|
||||
|
||||
if (acpi_dev_resource_interrupt(ares, 0, &r))
|
||||
lookup->irq = r.start;
|
||||
}
|
||||
|
||||
/* Always tell the ACPI core to skip this resource */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int acpi_spi_add_irq_resource(struct acpi_resource *ares, void *data)
|
||||
{
|
||||
int *irq = data;
|
||||
struct resource r;
|
||||
|
||||
if (*irq < 0 && ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS &&
|
||||
acpi_dev_resource_interrupt(ares, 0, &r))
|
||||
*irq = r.start;
|
||||
|
||||
/* Always tell the ACPI core to skip this resource */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* acpi_spi_device_alloc - Allocate a spi device, and fill it in with ACPI information
|
||||
* @ctlr: controller to which the spi device belongs
|
||||
@@ -3173,6 +3196,7 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,
|
||||
struct list_head resource_list;
|
||||
struct acpi_spi_lookup lookup = {};
|
||||
struct spi_device *spi;
|
||||
int irq = -1;
|
||||
int ret;
|
||||
|
||||
if (!ctlr && index == -1)
|
||||
@@ -3180,7 +3204,6 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,
|
||||
|
||||
lookup.ctlr = ctlr;
|
||||
lookup.device_handle = acpi_device_handle(adev);
|
||||
lookup.irq = -1;
|
||||
lookup.index = index;
|
||||
lookup.n = 0;
|
||||
|
||||
@@ -3203,6 +3226,19 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,
|
||||
if (!lookup.max_speed_hz)
|
||||
return ERR_PTR(-ENODEV);
|
||||
|
||||
/*
|
||||
* Only look up the IRQ once we know this is an SPI device for us.
|
||||
* Parsing an interrupt resource maps its GSI, which must not be done
|
||||
* for every unrelated ACPI device walked during enumeration.
|
||||
*/
|
||||
INIT_LIST_HEAD(&resource_list);
|
||||
ret = acpi_dev_get_resources(adev, &resource_list,
|
||||
acpi_spi_add_irq_resource, &irq);
|
||||
if (ret < 0)
|
||||
return ERR_PTR(ret);
|
||||
|
||||
acpi_dev_free_resource_list(&resource_list);
|
||||
|
||||
spi = spi_alloc_device(lookup.ctlr);
|
||||
if (!spi) {
|
||||
dev_err(&lookup.ctlr->dev, "failed to allocate SPI device for %s\n",
|
||||
@@ -3215,7 +3251,7 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,
|
||||
ACPI_COMPANION_SET(&spi->dev, adev);
|
||||
spi->max_speed_hz = lookup.max_speed_hz;
|
||||
spi->mode |= lookup.mode;
|
||||
spi->irq = lookup.irq;
|
||||
spi->irq = irq;
|
||||
spi->bits_per_word = lookup.bits_per_word;
|
||||
/*
|
||||
* By default spi->chip_select[0] will hold the physical CS number,
|
||||
|
||||
Reference in New Issue
Block a user