From patchwork Thu Feb 6 18:32:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11369025 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AB9AA921 for ; Thu, 6 Feb 2020 18:33:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8279720659 for ; Thu, 6 Feb 2020 18:33:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rirS6Cd5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8279720659 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44400 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1izlyD-0001Xm-MH for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Feb 2020 13:33:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33845) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1izlx1-0000Hi-CU for qemu-devel@nongnu.org; Thu, 06 Feb 2020 13:32:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1izlwz-0002pq-Kx for qemu-devel@nongnu.org; Thu, 06 Feb 2020 13:32:31 -0500 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:36645) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1izlwv-0002JV-Vp; Thu, 06 Feb 2020 13:32:26 -0500 Received: by mail-pg1-x544.google.com with SMTP id k3so3167489pgc.3; Thu, 06 Feb 2020 10:32:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=ALuZTuN5DfhXqsi8y55rZh7eLMFrbBhU4HDPNxMYbKY=; b=rirS6Cd5G3uxOCsFgXy9CdpIl/E8oFnxeCmQCOCVRMTl5YY0EvIPiQ0Y82YtgJfxg1 O4qb/iX+cU4ah1COUQtieL/oykPycBuzgOy6SeMqy+sRz5uhfScA3V0MpGOhmHiOtchF Y4Nm7eERHOSK7DnAm/SUXAraqKJHCjK3mAh2FZAsmdsQd90y/ymsEqaFCHlqQfqUCYfV x1vFHnNlm2Y1Bmocpmh63gB4OoJzpKyEqR5oMVtdTXQXmp/vE3nMyRDU0WryycFLchvs di3SwFey45cs+/9Hu+/cY5mXNrsQdtyEVOw9tYcRzs0Y2/b2sTu/D98BxKGo/YnwhHP6 Xvuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=ALuZTuN5DfhXqsi8y55rZh7eLMFrbBhU4HDPNxMYbKY=; b=L1F5lvUs8ur+ouferdEIm7HXUn6gi0V2RFDUOaDZ9BcDJKphpqI/R4Bkppe3Ctiy5a Xcg4EHIjm7I99EOsrkVTwIgTDHGLVTDsvbrD/3BwuNp+eZSNwxw+DGO/Bdr8jUR2jTOw v98MABfJ+uN77lRBf94XYxLwTXaG4DCXCK64lR8lmhzN+tKizQ27UXk4Sac5eGJoM5Z2 n/olh+/ckQ7U0WIPbecnCNGB02e9W+4XDSuVsFnO5LFAYecP5hnLSv+8oYTbzS5tN7ow 0muM7IwHn1nUbeQImi0Z1z90TW5CzkQxOE2Dave8CrHwfJ64qZKRgLYpN3SR9gsfRgGj 9pNg== X-Gm-Message-State: APjAAAXZ8JNYFfTISv2F8hZzXvorIEegfnhSuhE+hTE/jkNxN+ETXfAA XCUZwyb4/LCSAIGSwNzRMNo= X-Google-Smtp-Source: APXvYqzCwh2Bjh1FVDQs0HKAVXqvjJQtHPrrd6Ae8gj6X6/M7JDCmvH1ScwZ7Yhkukpal5pDG8fzag== X-Received: by 2002:a63:f648:: with SMTP id u8mr5236001pgj.148.1581013944579; Thu, 06 Feb 2020 10:32:24 -0800 (PST) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id c15sm94514pfo.137.2020.02.06.10.32.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Feb 2020 10:32:23 -0800 (PST) From: Guenter Roeck To: Alistair Francis , Kevin Wolf Subject: [PATCH v2 1/4] m25p80: Convert to support tracing Date: Thu, 6 Feb 2020 10:32:16 -0800 Message-Id: <20200206183219.3756-1-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-block@nongnu.org, Andrew Jeffery , qemu-devel@nongnu.org, Max Reitz , qemu-arm@nongnu.org, Joel Stanley , Guenter Roeck , =?utf-8?q?C=C3=A9dric_Le_Goater?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" While at it, add some trace messages to help debug problems seen when running the latest Linux kernel. Signed-off-by: Guenter Roeck Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis Reviewed-by: Cédric Le Goater Signed-off-by: Guenter Roeck Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis Reviewed-by: Cédric Le Goater Signed-off-by: Guenter Roeck Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis Reviewed-by: Cédric Le Goater Signed-off-by: Guenter Roeck Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Signed-off-by: Guenter Roeck Reviewed-by: Philippe Mathieu-Daudé --- v2: Print pointer to Flash data structure as flash ID with each trace message to support systems with more than one instantiated flash. hw/block/m25p80.c | 48 ++++++++++++++++++++----------------------- hw/block/trace-events | 16 +++++++++++++++ 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c index 61f2fb8f8f..5ff8d270c4 100644 --- a/hw/block/m25p80.c +++ b/hw/block/m25p80.c @@ -32,17 +32,7 @@ #include "qemu/module.h" #include "qemu/error-report.h" #include "qapi/error.h" - -#ifndef M25P80_ERR_DEBUG -#define M25P80_ERR_DEBUG 0 -#endif - -#define DB_PRINT_L(level, ...) do { \ - if (M25P80_ERR_DEBUG > (level)) { \ - fprintf(stderr, ": %s: ", __func__); \ - fprintf(stderr, ## __VA_ARGS__); \ - } \ -} while (0) +#include "trace.h" /* Fields for FlashPartInfo->flags */ @@ -574,7 +564,8 @@ static void flash_erase(Flash *s, int offset, FlashCMD cmd) abort(); } - DB_PRINT_L(0, "offset = %#x, len = %d\n", offset, len); + trace_m25p80_flash_erase(s, offset, len); + if ((s->pi->flags & capa_to_assert) != capa_to_assert) { qemu_log_mask(LOG_GUEST_ERROR, "M25P80: %d erase size not supported by" " device\n", len); @@ -607,8 +598,7 @@ void flash_write8(Flash *s, uint32_t addr, uint8_t data) } if ((prev ^ data) & data) { - DB_PRINT_L(1, "programming zero to one! addr=%" PRIx32 " %" PRIx8 - " -> %" PRIx8 "\n", addr, prev, data); + trace_m25p80_programming_zero_to_one(s, addr, prev, data); } if (s->pi->flags & EEPROM) { @@ -662,6 +652,9 @@ static void complete_collecting_data(Flash *s) s->state = STATE_IDLE; + trace_m25p80_complete_collecting(s, s->cmd_in_progress, n, s->ear, + s->cur_addr); + switch (s->cmd_in_progress) { case DPP: case QPP: @@ -825,7 +818,7 @@ static void reset_memory(Flash *s) break; } - DB_PRINT_L(0, "Reset done.\n"); + trace_m25p80_reset_done(s); } static void decode_fast_read_cmd(Flash *s) @@ -941,9 +934,10 @@ static void decode_qio_read_cmd(Flash *s) static void decode_new_cmd(Flash *s, uint32_t value) { - s->cmd_in_progress = value; int i; - DB_PRINT_L(0, "decoded new command:%x\n", value); + + s->cmd_in_progress = value; + trace_m25p80_command_decoded(s, value); if (value != RESET_MEMORY) { s->reset_enable = false; @@ -1042,7 +1036,7 @@ static void decode_new_cmd(Flash *s, uint32_t value) break; case JEDEC_READ: - DB_PRINT_L(0, "populated jedec code\n"); + trace_m25p80_populated_jedec(s); for (i = 0; i < s->pi->id_len; i++) { s->data[i] = s->pi->id[i]; } @@ -1063,7 +1057,7 @@ static void decode_new_cmd(Flash *s, uint32_t value) case BULK_ERASE_60: case BULK_ERASE: if (s->write_enable) { - DB_PRINT_L(0, "chip erase\n"); + trace_m25p80_chip_erase(s); flash_erase(s, 0, BULK_ERASE); } else { qemu_log_mask(LOG_GUEST_ERROR, "M25P80: chip erase with write " @@ -1184,7 +1178,7 @@ static int m25p80_cs(SSISlave *ss, bool select) s->data_read_loop = false; } - DB_PRINT_L(0, "%sselect\n", select ? "de" : ""); + trace_m25p80_select(s, select ? "de" : ""); return 0; } @@ -1194,19 +1188,20 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx) Flash *s = M25P80(ss); uint32_t r = 0; + trace_m25p80_transfer(s, s->state, s->len, s->needed_bytes, s->pos, + s->cur_addr, (uint8_t)tx); + switch (s->state) { case STATE_PAGE_PROGRAM: - DB_PRINT_L(1, "page program cur_addr=%#" PRIx32 " data=%" PRIx8 "\n", - s->cur_addr, (uint8_t)tx); + trace_m25p80_page_program(s, s->cur_addr, (uint8_t)tx); flash_write8(s, s->cur_addr, (uint8_t)tx); s->cur_addr = (s->cur_addr + 1) & (s->size - 1); break; case STATE_READ: r = s->storage[s->cur_addr]; - DB_PRINT_L(1, "READ 0x%" PRIx32 "=%" PRIx8 "\n", s->cur_addr, - (uint8_t)r); + trace_m25p80_read_byte(s, s->cur_addr, (uint8_t)r); s->cur_addr = (s->cur_addr + 1) & (s->size - 1); break; @@ -1244,6 +1239,7 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx) } r = s->data[s->pos]; + trace_m25p80_read_data(s, s->pos, (uint8_t)r); s->pos++; if (s->pos == s->len) { s->pos = 0; @@ -1281,7 +1277,7 @@ static void m25p80_realize(SSISlave *ss, Error **errp) return; } - DB_PRINT_L(0, "Binding to IF_MTD drive\n"); + trace_m25p80_binding(s); s->storage = blk_blockalign(s->blk, s->size); if (blk_pread(s->blk, 0, s->storage, s->size) != s->size) { @@ -1289,7 +1285,7 @@ static void m25p80_realize(SSISlave *ss, Error **errp) return; } } else { - DB_PRINT_L(0, "No BDRV - binding to RAM\n"); + trace_m25p80_binding_no_bdrv(s); s->storage = blk_blockalign(NULL, s->size); memset(s->storage, 0xFF, s->size); } diff --git a/hw/block/trace-events b/hw/block/trace-events index c03e80c2c9..f78939fa9d 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -134,3 +134,19 @@ xen_block_blockdev_add(char *str) "%s" xen_block_blockdev_del(const char *node_name) "%s" xen_block_device_create(unsigned int number) "%u" xen_block_device_destroy(unsigned int number) "%u" + +# m25p80.c +m25p80_flash_erase(void *s, int offset, uint32_t len) "[%p] offset = 0x%"PRIx32", len = %u" +m25p80_programming_zero_to_one(void *s, uint32_t addr, uint8_t prev, uint8_t data) "[%p] programming zero to one! addr=0x%"PRIx32" 0x%"PRIx8" -> 0x%"PRIx8 +m25p80_reset_done(void *s) "[%p] Reset done." +m25p80_command_decoded(void *s, uint32_t cmd) "[%p] new command:0x%"PRIx32 +m25p80_complete_collecting(void *s, uint32_t cmd, int n, uint8_t ear, uint32_t cur_addr) "[%p] decode cmd: 0x%"PRIx32" len %d ear 0x%"PRIx8" addr 0x%"PRIx32 +m25p80_populated_jedec(void *s) "[%p] populated jedec code" +m25p80_chip_erase(void *s) "[%p] chip erase" +m25p80_select(void *s, const char *what) "[%p] %sselect" +m25p80_page_program(void *s, uint32_t addr, uint8_t tx) "[%p] page program cur_addr=0x%"PRIx32" data=0x%"PRIx8 +m25p80_transfer(void *s, uint8_t state, uint32_t len, uint8_t needed, uint32_t pos, uint32_t cur_addr, uint8_t t) "[%p] Transfer state 0x%"PRIx8" len 0x%"PRIx32" needed 0x%"PRIx8" pos 0x%"PRIx32" addr 0x%"PRIx32" tx 0x%"PRIx8 +m25p80_read_byte(void *s, uint32_t addr, uint8_t v) "[%p] Read byte 0x%"PRIx32"=0x%"PRIx8 +m25p80_read_data(void *s, uint32_t pos, uint8_t v) "[%p] Read data 0x%"PRIx32"=0x%"PRIx8 +m25p80_binding(void *s) "[%p] Binding to IF_MTD drive" +m25p80_binding_no_bdrv(void *s) "[%p] No BDRV - binding to RAM" From patchwork Thu Feb 6 18:32:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11369023 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C8963921 for ; Thu, 6 Feb 2020 18:33:44 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9F30D20659 for ; Thu, 6 Feb 2020 18:33:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LFNVvlMm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F30D20659 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44398 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1izlyB-0001Uk-QK for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Feb 2020 13:33:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33821) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1izlx0-0000H9-C4 for qemu-devel@nongnu.org; Thu, 06 Feb 2020 13:32:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1izlwz-0002nH-Cw for qemu-devel@nongnu.org; Thu, 06 Feb 2020 13:32:30 -0500 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:39398) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1izlwx-0002Tv-1U; Thu, 06 Feb 2020 13:32:27 -0500 Received: by mail-pg1-x542.google.com with SMTP id j15so3167053pgm.6; Thu, 06 Feb 2020 10:32:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KHa/YBhZFNQ20KTVw/CmGFo4SlMalxgAEPAvIgaPvrc=; b=LFNVvlMmrLf25rNwrNDR82Bs347osXagmjsWDE84qnVj8iGW9+k4doSQhtsqymM7Rt lZ501LnnDaOxSX4aVyu+LrdQYg94ZO8b1WmlRQvKjU9mCbJrEmxC8LgKrJUrGXid6BCu wdiJuKQwdYisJl66WezpTkUUpcqwAE6UFaoVfCSVxwwwWZKxRQ+2ekSPuTiu/3rkQzpD Us9IJYTlJ5i0Ha3ELkJfIvNNTOeKxuezooJ/X6dGk4kGhgGH+kUiU/5PpT4KSL0LhtL0 H0NaBdrfYzloxDzcb8aJrX0Xh4XhieWLA+tOJIY4/l0qRkUIPJMXXfrIBD6yY5XozU0k 3BrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=KHa/YBhZFNQ20KTVw/CmGFo4SlMalxgAEPAvIgaPvrc=; b=dDQjF9ZPwuP+vznup3sivIUEthyMYXYra0X0YEZ1CI/eFQI/uLuFBWbMtR3+oEmqEL pEQGVDtckMv0UI4S8jYY+YPHvYTwPWHu+qPFrHR6eXpzrNBb3+q9t1xIlIp22L1RSVAt iy+ORmwI9AVGsorRkkcOtQix6kUBmsa+eEBUvV0vIWGoWuK3F+5GjObWhXvGdX6wDHEq PMBTeP2L8NWlDaeY4DLJVElnBOC+zuFwhMu0ixntivolrAHSUW0yOLAiGKC5entp4o9e d3i8P1UkLcfq2n8XYCU09D2vxigl5Q2/NjcJbuNOZKd/kASpI0BlENF3gGo3Kzgdl1cT f2nA== X-Gm-Message-State: APjAAAUSxlIOmq4JjO/VA2wCqOdgl2iIwfgQv6OWb0PQZbw/AF6XPHbW iovv7IWbv3dwolmSGCy6lTU= X-Google-Smtp-Source: APXvYqx8M66S523j0CAc3jx1Q/n5M3NlplkIwuiYGTznrlVl16ZcwJURe829H/RkxXb1ZBR4dwUAqw== X-Received: by 2002:a63:8dc4:: with SMTP id z187mr5255950pgd.68.1581013946160; Thu, 06 Feb 2020 10:32:26 -0800 (PST) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id i66sm106167pfg.85.2020.02.06.10.32.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Feb 2020 10:32:25 -0800 (PST) From: Guenter Roeck To: Alistair Francis , Kevin Wolf Subject: [PATCH v2 2/4] m25p80: Improve command handling for Jedec commands Date: Thu, 6 Feb 2020 10:32:17 -0800 Message-Id: <20200206183219.3756-2-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200206183219.3756-1-linux@roeck-us.net> References: <20200206183219.3756-1-linux@roeck-us.net> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-block@nongnu.org, Andrew Jeffery , qemu-devel@nongnu.org, Max Reitz , qemu-arm@nongnu.org, Joel Stanley , Guenter Roeck , =?utf-8?q?C=C3=A9dric_Le_Goater?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" When requesting JEDEC data using the JEDEC_READ command, the Linux kernel always requests 6 bytes. The current implementation only returns three bytes, and interprets the remaining three bytes as new commands. While this does not matter most of the time, it is at the very least confusing. To avoid the problem, always report up to 6 bytes of JEDEC data. Fill remaining data with 0. Signed-off-by: Guenter Roeck Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis Reviewed-by: Cédric Le Goater --- v2: Split patch into two parts; improved decription hw/block/m25p80.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c index 5ff8d270c4..53bf63856f 100644 --- a/hw/block/m25p80.c +++ b/hw/block/m25p80.c @@ -1040,8 +1040,11 @@ static void decode_new_cmd(Flash *s, uint32_t value) for (i = 0; i < s->pi->id_len; i++) { s->data[i] = s->pi->id[i]; } + for (; i < SPI_NOR_MAX_ID_LEN; i++) { + s->data[i] = 0; + } - s->len = s->pi->id_len; + s->len = SPI_NOR_MAX_ID_LEN; s->pos = 0; s->state = STATE_READING_DATA; break; From patchwork Thu Feb 6 18:32:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11369029 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6665B921 for ; Thu, 6 Feb 2020 18:35:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3CF5F20659 for ; Thu, 6 Feb 2020 18:35:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BKXJ+pHA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3CF5F20659 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1izm0H-00051D-GI for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Feb 2020 13:35:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33862) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1izlx5-0000IX-St for qemu-devel@nongnu.org; Thu, 06 Feb 2020 13:32:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1izlx1-00031R-0T for qemu-devel@nongnu.org; Thu, 06 Feb 2020 13:32:35 -0500 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]:36309) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1izlwy-0002eB-N9; Thu, 06 Feb 2020 13:32:28 -0500 Received: by mail-pj1-x1044.google.com with SMTP id gv17so347657pjb.1; Thu, 06 Feb 2020 10:32:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TFJ5p1ThS0hsrxJYRVO5wCKqO07TvtEvWzLC69usUMo=; b=BKXJ+pHAIy34MxF73NSkOCFiML1oW02DGqYmirQl8r8f4l6ltSd1vvRctwdh0mOmwh z/F2l1ONMl2EJfbZcozrOor8F4x1MwzIdyIa/iJp1dNAKfZteZnsgDlU4oRzL7+W4jKS L8lj0N+O8xHlLyf8g+E71KuTr1V6DxuX/+KdGEK/jXbwCnmbQ7Xvg6cCvEXJPmiz+IQM XOZ+42oMOxoNpygjAS2qp9MpwdBu/gmjb8a+pMq/ZJbJ8amEkruSB5SiajGMke7xB1xI Ebcv8p+G6E7JYivxIbowUcaoeJfaDa8kEbMr1fgTDCqUp9FxsES983Ug0SofvHCIsHbc MMbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=TFJ5p1ThS0hsrxJYRVO5wCKqO07TvtEvWzLC69usUMo=; b=GjpFGRTwX31Z/gwsCjoePzhPM2VF3hMnonQXCwMOXe9eoiQnZLtsB1R2oG+v5S/NnZ wOmQ6fP3KYgEeShO11Kfsr7BRDs8c4J+6UN0GuY7EvLR0pS+oTQ+5gTjA3O9/krUQELl 7htVIjn0lPE/VmVkchkCxi2C2GcuBpdJHdpmLedF/hjUJhHlBuY0EcQap0/6dxQ6zqQX V8P0FcMqSTfoXpvWkkOpTQM15c44riDjenP/39Fk40+8WT0w4pU4lbaKR9WMDKyLXqeY Jfm2Q5272tAJgU63bAGM/PENCHL6lyVMkD5cu+OPYX2T11flyCh5UaX0UqTWq48nzzJk hPDQ== X-Gm-Message-State: APjAAAUm8wKwTb1SNjvt3EU0rUTVDfFrhs4895vioz3um9OJKoaxQMrL GVeTW8i4e3JB4uZK4YQS/vk= X-Google-Smtp-Source: APXvYqxRfEApRG5pO/lESYf/dZoerR3vB53boCqOGWMuE4ZNihRkP5cC2aezSIGGoRDahk5gLSEOdA== X-Received: by 2002:a17:90a:5285:: with SMTP id w5mr6200743pjh.77.1581013947718; Thu, 06 Feb 2020 10:32:27 -0800 (PST) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 144sm115035pfc.45.2020.02.06.10.32.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Feb 2020 10:32:27 -0800 (PST) From: Guenter Roeck To: Alistair Francis , Kevin Wolf Subject: [PATCH v2 3/4] m25p80: Improve command handling for unsupported commands Date: Thu, 6 Feb 2020 10:32:18 -0800 Message-Id: <20200206183219.3756-3-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200206183219.3756-1-linux@roeck-us.net> References: <20200206183219.3756-1-linux@roeck-us.net> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::1044 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-block@nongnu.org, Andrew Jeffery , qemu-devel@nongnu.org, Max Reitz , qemu-arm@nongnu.org, Joel Stanley , Guenter Roeck , =?utf-8?q?C=C3=A9dric_Le_Goater?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Whenever an unsupported command is encountered, the current code interprets each transferred byte as new command. Most of the time, those 'commands' are interpreted as new unknown commands. However, in rare cases, it may be that for example address or length information passed with the original command is by itself a valid command. If that happens, the state machine may get completely confused and, worst case, start writing data into the flash or even erase it. To avoid the problem, transition into STATE_READING_DATA and keep sending a value of 0 until the chip is deselected after encountering an unsupported command. Signed-off-by: Guenter Roeck Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater --- v2: Split patch into two parts; improved description. hw/block/m25p80.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c index 53bf63856f..8227088441 100644 --- a/hw/block/m25p80.c +++ b/hw/block/m25p80.c @@ -1161,6 +1161,11 @@ static void decode_new_cmd(Flash *s, uint32_t value) s->quad_enable = false; break; default: + s->pos = 0; + s->len = 1; + s->state = STATE_READING_DATA; + s->data_read_loop = true; + s->data[0] = 0; qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Unknown cmd %x\n", value); break; } From patchwork Thu Feb 6 18:32:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11369031 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B01DE14B4 for ; Thu, 6 Feb 2020 18:37:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 873D7214AF for ; Thu, 6 Feb 2020 18:37:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MRYmMeMe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 873D7214AF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1izm1r-0007BZ-Ob for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Feb 2020 13:37:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33911) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1izlx7-0000My-Sw for qemu-devel@nongnu.org; Thu, 06 Feb 2020 13:32:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1izlx6-0003E2-Sk for qemu-devel@nongnu.org; Thu, 06 Feb 2020 13:32:37 -0500 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:43861) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1izlx0-0002rS-CN; Thu, 06 Feb 2020 13:32:30 -0500 Received: by mail-pf1-x442.google.com with SMTP id s1so3529362pfh.10; Thu, 06 Feb 2020 10:32:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IilPI+Sl+B1I6W2BM0SWvCm9l7ZzLSY3Gh4DaMCNP84=; b=MRYmMeMeK0LrfdlBnYA80D6ZOqlWW8huDdFcoVVb5HtB7oJkkCMiuUJ4isEtkJutMQ g6p2VXaPGFBMSHjPxr1FvKs0uYe23MNJY+L7ztF9YpVhHbUhUP7Yn9xe0bhWObP2g4yR WGFKdwS73OTGI1pajnq8ds+WlXrkosbcmusaV9VoD+hyssqfhbw2403nzx2h8BJyAh4U OvPZyhmz/fItlKH4rHtkL5aO92zPEpCy3OcMQFTZSbQgW47e5765V5sGX8XxXMcLsqEm b8ivxDdHuaOpjn+ooGcJdd/51couDDkQiMQ/QRIKi7gipP5zunAc0afqGeQkpVjb53fm RD/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=IilPI+Sl+B1I6W2BM0SWvCm9l7ZzLSY3Gh4DaMCNP84=; b=Jv07uvCVvoANmMmTKJAt8m/yzawU8m0dAM4+B27ToprGLlBhIayULYv1k4xXbnS9Vc GOi0qquINFg3s5mfccDekg3QQEbRHEwVoidY2ZAKcPXq0TbXEwQaR7hH211uaHhS24Qs tlb7vOManzD6FgdQ0Yu/inbtUx3DJIDyyK3/dlECPYQMDPGRLW33lo3sZQnF5B1C6sda NUVlt9iybf12XhXs2f33odp0kjqlChaDlXY3PpL++NefnhCX9P/ju8GQfN/oLdsDoHYU AlwfXhOKs/ETlHTLwkAUmmIgU3ywlLAASEIjLf2TyCPxqmPQ4+oJfCsQmpuXGPduCQdP 9jOg== X-Gm-Message-State: APjAAAWz7vHDMM7K4VKh5gbitS+rLzrfvDrIhnYwUegRbQWB0hnArRer j21goPfIRLmDGav5njGMvgo= X-Google-Smtp-Source: APXvYqwPzrYYEVvvds6kGd54V8A9rorEuu7jXADmNvh8HUjLrfMVFbUUwSHNlNdQ6f3lLCBup7oPXw== X-Received: by 2002:a63:6e8b:: with SMTP id j133mr5030071pgc.6.1581013949370; Thu, 06 Feb 2020 10:32:29 -0800 (PST) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 28sm127082pgl.42.2020.02.06.10.32.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Feb 2020 10:32:28 -0800 (PST) From: Guenter Roeck To: Alistair Francis , Kevin Wolf Subject: [PATCH v2 4/4] aspeed/smc: Fix number of dummy cycles for FAST_READ_4 command Date: Thu, 6 Feb 2020 10:32:19 -0800 Message-Id: <20200206183219.3756-4-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200206183219.3756-1-linux@roeck-us.net> References: <20200206183219.3756-1-linux@roeck-us.net> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-block@nongnu.org, Andrew Jeffery , qemu-devel@nongnu.org, Max Reitz , qemu-arm@nongnu.org, Joel Stanley , Guenter Roeck , =?utf-8?q?C=C3=A9dric_Le_Goater?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The Linux kernel recently started using FAST_READ_4 commands. This results in flash read failures. At the same time, the m25p80 emulation is seen to read 8 more bytes than expected. Adjusting the expected number of dummy cycles to match FAST_READ fixes the problem. Fixes: f95c4bffdc4c ("aspeed/smc: snoop SPI transfers to fake dummy cycles") Reviewed-by: Cédric Le Goater Signed-off-by: Guenter Roeck Reviewed-by: Philippe Mathieu-Daudé --- v2: No change hw/ssi/aspeed_smc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c index 23c8d2f062..0444570750 100644 --- a/hw/ssi/aspeed_smc.c +++ b/hw/ssi/aspeed_smc.c @@ -787,11 +787,11 @@ static int aspeed_smc_num_dummies(uint8_t command) case FAST_READ: case DOR: case QOR: + case FAST_READ_4: case DOR_4: case QOR_4: return 1; case DIOR: - case FAST_READ_4: case DIOR_4: return 2; case QIOR: