From patchwork Tue Jan 2 19:36:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10141281 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 67E016035E for ; Tue, 2 Jan 2018 19:44:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5682028E0D for ; Tue, 2 Jan 2018 19:44:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A70F28E1C; Tue, 2 Jan 2018 19:44:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6EFA728E0D for ; Tue, 2 Jan 2018 19:44:23 +0000 (UTC) Received: from localhost ([::1]:53036 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWSU2-0002Wb-8h for patchwork-qemu-devel@patchwork.kernel.org; Tue, 02 Jan 2018 14:44:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58709) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWSMi-0003KE-BG for qemu-devel@nongnu.org; Tue, 02 Jan 2018 14:36:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWSMf-0000OY-8P for qemu-devel@nongnu.org; Tue, 02 Jan 2018 14:36:48 -0500 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:37964) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eWSMc-0000LJ-EY; Tue, 02 Jan 2018 14:36:42 -0500 Received: by mail-pg0-x243.google.com with SMTP id t67so2960602pgc.5; Tue, 02 Jan 2018 11:36:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=E08NgLB+iZxe+FQ8+m6OK1RQdn04+8BR1I1ixtM1hXU=; b=uMTPABtXcvoTcA3nmFonEgNk0CbaxGmlmni9VXcxvTIuwjLN5F1Jwu9l41xVYwO5VJ uXnUKRBRLmx+KmNV7SXHKKrJW7Z2dvSfSnnCzIJXQqsHLzk4BpJvSy8qxeJNzK4rQtH2 mInNRoXfm7W4R8TJCJP1+aLpAEGy6NJgXTeBv8clpboeVudswKFp4dI3Xwvgou9Bkwxg jp4rrjm0sAjPZmSWGzQzKQi4kanup/lbnivtTm3RbDMkSSnUPvooGssfcmGlN5a/Hhrb xTMh8SD+edi7ClH0K1YFMpn+WwsKPyMR3SQ/iUYCjmFlb4IGzZlc18EVrQFEvIuhPwYJ rGZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=E08NgLB+iZxe+FQ8+m6OK1RQdn04+8BR1I1ixtM1hXU=; b=HSA0UvQw4IjsOIDykPt8JO5T3byyIlcCVezeI8B5Z2U8SRjxoRBb64B+xBU+OiPO3I 9aoRAoVAo8CE4QGT9xyiMZsQEM04sBv90I4NoXarFLqjcV192k9DDgOOw+TwdxdZyfB3 SutGi73bBcrnnH7s7euHulBXHQBn8MQsxcPTu8aF7FPO6eYL1Un2ToJJO40AJumMUqq+ 2AgcntSlIt0dpmgNBsOsfKf/mShYjtg3i1VPEbprbXqEB2ed2LOKAgdvtODL69qmhhno 1LsllC8ZUxkGVjBAhQJBGhVjx3bttGX11MFFeuKld6lJ85UXqmAoLULd8eWoAxnruU4R IZUg== X-Gm-Message-State: AKGB3mLxjm4lC9dquIROTUzlN13787du4DCSVW0lKEFTTMEFK8pCLUwT fkz2Mzd808VePE0l7+lwX6xJ5dzjlJs= X-Google-Smtp-Source: ACJfBotXTmVCT26JQI7tCw2//ZeVZGjb3zVmGuu5yW0EniUQ/dg7TKA3s5ukGeUQrG9GcvduSLAXiQ== X-Received: by 10.98.153.221 with SMTP id t90mr46107541pfk.210.1514921801180; Tue, 02 Jan 2018 11:36:41 -0800 (PST) Received: from squirtle.westlake.spaceflightindustries.com ([173.226.206.194]) by smtp.gmail.com with ESMTPSA id g9sm97905951pfk.0.2018.01.02.11.36.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Jan 2018 11:36:40 -0800 (PST) From: Andrey Smirnov To: qemu-arm@nongnu.org Date: Tue, 2 Jan 2018 11:36:18 -0800 Message-Id: <20180102193622.27215-8-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180102193622.27215-1-andrew.smirnov@gmail.com> References: <20180102193622.27215-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH v3 07/11] imx_fec: Emulate SHIFT16 in ENETx_RACC X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrey Smirnov , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, yurovsky@gmail.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Needed to support latest Linux kernel driver which relies on that functionality. Cc: Peter Maydell Cc: Jason Wang Cc: Philippe Mathieu-Daudé Cc: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Cc: yurovsky@gmail.com Reviewed-by: Peter Maydell Signed-off-by: Andrey Smirnov --- hw/net/imx_fec.c | 23 +++++++++++++++++++++++ include/hw/net/imx_fec.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c index 6feda18742..825c879a28 100644 --- a/hw/net/imx_fec.c +++ b/hw/net/imx_fec.c @@ -1037,6 +1037,7 @@ static ssize_t imx_enet_receive(NetClientState *nc, const uint8_t *buf, uint8_t *crc_ptr; unsigned int buf_len; size_t size = len; + bool shift16 = s->regs[ENET_RACC] & ENET_RACC_SHIFT16; FEC_PRINTF("len %d\n", (int)size); @@ -1051,6 +1052,10 @@ static ssize_t imx_enet_receive(NetClientState *nc, const uint8_t *buf, crc = cpu_to_be32(crc32(~0, buf, size)); crc_ptr = (uint8_t *) &crc; + if (shift16) { + size += 2; + } + /* Huge frames are truncted. */ if (size > s->regs[ENET_FTRL]) { size = s->regs[ENET_FTRL]; @@ -1087,6 +1092,24 @@ static ssize_t imx_enet_receive(NetClientState *nc, const uint8_t *buf, buf_len += size - 4; } buf_addr = bd.data; + + if (shift16) { + /* + * If SHIFT16 bit of ENETx_RACC register is set we need to + * align the payload to 4-byte boundary. + */ + const uint8_t zeros[2] = { 0 }; + + dma_memory_write(&address_space_memory, buf_addr, + zeros, sizeof(zeros)); + + buf_addr += sizeof(zeros); + buf_len -= sizeof(zeros); + + /* We only do this once per Ethernet frame */ + shift16 = false; + } + dma_memory_write(&address_space_memory, buf_addr, buf, buf_len); buf += buf_len; if (size < 4) { diff --git a/include/hw/net/imx_fec.h b/include/hw/net/imx_fec.h index a390d704a6..af0840a0fa 100644 --- a/include/hw/net/imx_fec.h +++ b/include/hw/net/imx_fec.h @@ -170,6 +170,8 @@ #define ENET_TWFR_TFWR_LENGTH (6) #define ENET_TWFR_STRFWD (1 << 8) +#define ENET_RACC_SHIFT16 BIT(7) + /* Buffer Descriptor. */ typedef struct { uint16_t length;