Commit b74d2807 authored by Nicholas Piggin's avatar Nicholas Piggin Committed by Michael Ellerman

powerpc/powernv: Remove OPALv1 support from opal console driver

opal_put_chars deals with partial writes because in OPALv1,
opal_console_write_buffer_space did not work correctly. That firmware
is not supported.

This reworks the opal_put_chars code to no longer deal with partial
writes by turning them into full writes. Partial write handling is still
supported in terms of what gets returned to the caller, but it may not
go to the console atomically. A warning message is printed in this
case.

This allows console flushing to be moved out of the opal_write_lock
spinlock. That could cause the lock to be held for long periods if the
console is busy (especially if it was being spammed by firmware),
which is dangerous because the lock is taken by xmon to debug the
system. Flushing outside the lock improves the situation a bit.

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent d2a2262e
......@@ -346,10 +346,10 @@ int opal_get_chars(uint32_t vtermno, char *buf, int count)
int opal_put_chars(uint32_t vtermno, const char *data, int total_len)
{
int written = 0;
__be64 olen;
s64 len, rc;
unsigned long flags;
int written;
__be64 olen;
s64 rc;
if (!opal.entry)
return -ENODEV;
......@@ -357,52 +357,48 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len)
/* We want put_chars to be atomic to avoid mangling of hvsi
* packets. To do that, we first test for room and return
* -EAGAIN if there isn't enough.
*
* Unfortunately, opal_console_write_buffer_space() doesn't
* appear to work on opal v1, so we just assume there is
* enough room and be done with it
*/
spin_lock_irqsave(&opal_write_lock, flags);
rc = opal_console_write_buffer_space(vtermno, &olen);
len = be64_to_cpu(olen);
if (rc || len < total_len) {
spin_unlock_irqrestore(&opal_write_lock, flags);
if (rc || be64_to_cpu(olen) < total_len) {
/* Closed -> drop characters */
if (rc)
return total_len;
opal_flush_console(vtermno);
return -EAGAIN;
written = total_len;
else
written = -EAGAIN;
goto out;
}
/* We still try to handle partial completions, though they
* should no longer happen.
*/
while (total_len > 0) {
/* Should not get a partial write here because space is available. */
olen = cpu_to_be64(total_len);
rc = OPAL_BUSY;
while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
rc = opal_console_write(vtermno, &olen, data);
if (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
if (rc == OPAL_BUSY_EVENT) {
mdelay(OPAL_BUSY_DELAY_MS);
opal_poll_events(NULL);
} else if (rc == OPAL_BUSY) {
} else if (rc == OPAL_BUSY_EVENT) {
mdelay(OPAL_BUSY_DELAY_MS);
}
written = -EAGAIN;
goto out;
}
len = be64_to_cpu(olen);
/* Closed or other error drop */
if (rc != OPAL_SUCCESS) {
written += total_len; /* drop remaining chars */
break;
written = opal_error_code(rc);
goto out;
}
total_len -= len;
data += len;
written += len;
written = be64_to_cpu(olen);
if (written < total_len) {
/* Should not happen */
pr_warn("atomic console write returned partial len=%d written=%d\n", total_len, written);
if (!written)
written = -EAGAIN;
}
out:
spin_unlock_irqrestore(&opal_write_lock, flags);
/* This is a bit nasty but we need that for the console to
* flush when there aren't any interrupts. We will clean
......@@ -410,8 +406,6 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len)
* such as the kernel console and xmon/udbg
*/
opal_flush_console(vtermno);
}
spin_unlock_irqrestore(&opal_write_lock, flags);
return written;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment