From patchwork Sun May 9 17:32:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Birger Koblitz X-Patchwork-Id: 1475987 X-Patchwork-Delegate: hauke@hauke-m.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=AIAG0PcA; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FdWWK72DJz9tlN for ; Mon, 10 May 2021 03:33:49 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:References: Cc:To:Subject:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZORwCKMJi3eVeok9cZhKxUgcAWkfc9A31kX7Sl0HrtY=; b=AIAG0PcA5FWkC82opu954GeNo Og3XMdJlVxxVnxTmiffwY4l2YODSfSqP01BFAvi1ZTrVQDavC8r9er5uv9jpmH+IGzE4ZG/+zxJPh B0a/8nnnZOR9nvAVQezdCxntwf1V/6M4DaiNbDujDLgHO35NkLCqdBu4tnErACf4TRi7Tjgte9Spq TO5fPpause2zMY1/W4b/pkw/y+Ngfpa//nyTSwKt4OfdYxzt47+RXKjtzI4wbnEFrQOkhyVhOcwia 95d4k/efvr7u9oqkma9Hece1VacIXVwMFtIoUOEwdhvlfh5K+aDwT8VNWHqmFhpbznk2zjYfdeXaK yvBhbZB2A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lfnHi-00C0uN-SY; Sun, 09 May 2021 17:32:07 +0000 Received: from wp175.webpack.hosteurope.de ([2a01:488:42:1000:50ed:84b6::]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lfnHe-00C0tC-PL for openwrt-devel@lists.openwrt.org; Sun, 09 May 2021 17:32:04 +0000 Received: from p54bc6a77.dip0.t-ipconnect.de ([84.188.106.119] helo=[192.168.1.113]); authenticated by wp175.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1lfnHc-0004as-GY; Sun, 09 May 2021 19:32:00 +0200 From: Birger Koblitz Subject: [PATCH] realtek: Fix buffer length calculation on RTL8380 with CRC offload To: openwrt-devel@lists.openwrt.org Cc: russell@personaltelco.net, =?utf-8?q?Bj=C3=B8rn_Mork?= References: <87a6p5uz9h.fsf@miraculix.mork.no> <875yztuteu.fsf@miraculix.mork.no> Message-ID: Date: Sun, 9 May 2021 19:32:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <875yztuteu.fsf@miraculix.mork.no> Content-Language: en-US X-bounce-key: webpack.hosteurope.de; mail@birger-koblitz.de; 1620581522; ca0b0354; X-HE-SMSGID: 1lfnHc-0004as-GY X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210509_183203_055485_56768725 X-CRM114-Status: GOOD ( 13.52 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: realtek: Fix buffer length calculation on RTL8380 with CRC offload Fixes the buffer and packet length calculations for Ethernet TX on the RTL8380 SoC when CRC calculation offload is enabled. CRC-offload is always done by the SoC, but additional CRC calculation was pr [...] Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org realtek: Fix buffer length calculation on RTL8380 with CRC offload Fixes the buffer and packet length calculations for Ethernet TX on the RTL8380 SoC when CRC calculation offload is enabled. CRC-offload is always done by the SoC, but additional CRC calculation was previously done also by the kernel. It also fixes detection of the DSA tag for packets on RTL8390 SoCs for ports > 28. Signed-off-by: Birger Koblitz diff --git a/target/linux/realtek/files-5.4/drivers/net/ethernet/rtl838x_eth.c b/target/linux/realtek/files-5.4/drivers/net/ethernet/rtl838x_eth.c index c5c6e3b6b7..9fe4fcd647 100644 --- a/target/linux/realtek/files-5.4/drivers/net/ethernet/rtl838x_eth.c +++ b/target/linux/realtek/files-5.4/drivers/net/ethernet/rtl838x_eth.c @@ -1129,23 +1129,16 @@ static int rtl838x_eth_tx(struct sk_buff *skb, struct net_device *dev) /* Check for DSA tagging at the end of the buffer */ if (netdev_uses_dsa(dev) && skb->data[len-4] == 0x80 && skb->data[len-3] > 0 - && skb->data[len-3] < 28 && skb->data[len-2] == 0x10 + && skb->data[len-3] < priv->cpu_port && skb->data[len-2] == 0x10 && skb->data[len-1] == 0x00) { /* Reuse tag space for CRC if possible */ dest_port = skb->data[len-3]; + skb->data[len-4] = skb->data[len-3] = skb->data[len-2] = skb->data[len-1] = 0x00; len -= 4; } len += 4; // Add space for CRC - // On RTL8380 SoCs, the packet needs extra padding - if (priv->family_id == RTL8380_FAMILY_ID) { - if (len < ETH_ZLEN) - len = ETH_ZLEN; // SoC not automatically padding to ETH_ZLEN - else - len += 4; - } - if (skb_padto(skb, len)) { ret = NETDEV_TX_OK; goto txdone; @@ -1158,6 +1151,11 @@ static int rtl838x_eth_tx(struct sk_buff *skb, struct net_device *dev) h = &ring->tx_header[q][ring->c_tx[q]]; h->size = len; h->len = len; + // On RTL8380 SoCs, small packet lengths being sent need adjustments + if (priv->family_id == RTL8380_FAMILY_ID) { + if (len < ETH_ZLEN - 4) + h->len -= 4; + } priv->r->create_tx_header(h, dest_port, skb->priority >> 1);