From 89a895b63cc554b6b7033d72d28a59bfa92532ab Mon Sep 17 00:00:00 2001 From: Ian Lepore Date: Sun, 18 Mar 2018 16:52:31 +0000 Subject: [PATCH] Bugfix: wait for writes/erases to complete after starting them, instead of before starting them. Using the wait-before logic would make sense if there was useful time- consuming work that could be done between the end of one write and the beginning of the next, but it also requires doing the wait-for-ready before reading, because a prior write or erase could still be in progress. Reading is the far more common case, so adding a whole extra bus transaction to check for ready before each read would soak up any small gains that might be had from doing async writes. --- sys/dev/flash/mx25l.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys/dev/flash/mx25l.c b/sys/dev/flash/mx25l.c index 2be23c16838..4953e8e460e 100644 --- a/sys/dev/flash/mx25l.c +++ b/sys/dev/flash/mx25l.c @@ -247,7 +247,6 @@ mx25l_erase_cmd(device_t dev, off_t sector, uint8_t ecmd) sc = device_get_softc(dev); - mx25l_wait_for_device_ready(dev); mx25l_set_writable(dev, 1); memset(&cmd, 0, sizeof(cmd)); @@ -272,6 +271,7 @@ mx25l_erase_cmd(device_t dev, off_t sector, uint8_t ecmd) txBuf[3] = (sector & 0xff); } err = SPIBUS_TRANSFER(device_get_parent(dev), dev, &cmd); + mx25l_wait_for_device_ready(dev); } static int @@ -339,6 +339,7 @@ mx25l_write(device_t dev, off_t offset, caddr_t data, off_t count) mx25l_set_writable(dev, 1); err = SPIBUS_TRANSFER(pdev, dev, &cmd); + mx25l_wait_for_device_ready(dev); if (err) break;