From patchwork Mon May 28 06:33:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baruch Siach X-Patchwork-Id: 921315 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=tkos.co.il Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40vRsg50jvz9s16 for ; Mon, 28 May 2018 16:34:31 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 612EDC21DD3; Mon, 28 May 2018 06:34:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 382E9C21C27; Mon, 28 May 2018 06:34:24 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id DF97EC21C6A; Mon, 28 May 2018 06:34:22 +0000 (UTC) Received: from mx.tkos.co.il (guitar.tcltek.co.il [192.115.133.116]) by lists.denx.de (Postfix) with ESMTPS id 8339AC21C27 for ; Mon, 28 May 2018 06:34:22 +0000 (UTC) Received: from tarshish.tkos.co.il (unknown [10.0.8.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx.tkos.co.il (Postfix) with ESMTPSA id 46DD84400D0; Mon, 28 May 2018 09:34:21 +0300 (IDT) From: Baruch Siach To: Stefan Roese , Joe Hershberger Date: Mon, 28 May 2018 09:33:54 +0300 Message-Id: <63028ec52402c6473fc144ac9f2a89f5f0604784.1527489235.git.baruch@tkos.co.il> X-Mailer: git-send-email 2.17.0 Cc: u-boot@lists.denx.de, Baruch Siach Subject: [U-Boot] [PATCH 1/2] mvebu: neta: align DMA buffers X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Jon Nettleton This makes sure the DMA buffers are properly aligned for the hardware. Signed-off-by: Jon Nettleton Signed-off-by: Baruch Siach Reviewed-by: Stefan Roese --- drivers/net/mvneta.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/net/mvneta.c b/drivers/net/mvneta.c index 7036b517b445..fc16986a00d6 100644 --- a/drivers/net/mvneta.c +++ b/drivers/net/mvneta.c @@ -1025,6 +1025,9 @@ static int mvneta_rxq_init(struct mvneta_port *pp, if (rxq->descs == NULL) return -ENOMEM; + BUG_ON(rxq->descs != + PTR_ALIGN(rxq->descs, ARCH_DMA_MINALIGN)); + rxq->last_desc = rxq->size - 1; /* Set Rx descriptors queue starting address */ @@ -1061,6 +1064,9 @@ static int mvneta_txq_init(struct mvneta_port *pp, if (txq->descs == NULL) return -ENOMEM; + BUG_ON(txq->descs != + PTR_ALIGN(txq->descs, ARCH_DMA_MINALIGN)); + txq->last_desc = txq->size - 1; /* Set maximum bandwidth for enabled TXQs */ @@ -1694,18 +1700,20 @@ static int mvneta_probe(struct udevice *dev) * be active. Make this area DMA safe by disabling the D-cache */ if (!buffer_loc.tx_descs) { + u32 size; + /* Align buffer area for descs and rx_buffers to 1MiB */ bd_space = memalign(1 << MMU_SECTION_SHIFT, BD_SPACE); mmu_set_region_dcache_behaviour((phys_addr_t)bd_space, BD_SPACE, DCACHE_OFF); buffer_loc.tx_descs = (struct mvneta_tx_desc *)bd_space; + size = roundup(MVNETA_MAX_TXD * sizeof(struct mvneta_tx_desc), + ARCH_DMA_MINALIGN); buffer_loc.rx_descs = (struct mvneta_rx_desc *) - ((phys_addr_t)bd_space + - MVNETA_MAX_TXD * sizeof(struct mvneta_tx_desc)); - buffer_loc.rx_buffers = (phys_addr_t) - (bd_space + - MVNETA_MAX_TXD * sizeof(struct mvneta_tx_desc) + - MVNETA_MAX_RXD * sizeof(struct mvneta_rx_desc)); + ((phys_addr_t)bd_space + size); + size += roundup(MVNETA_MAX_RXD * sizeof(struct mvneta_rx_desc), + ARCH_DMA_MINALIGN); + buffer_loc.rx_buffers = (phys_addr_t)(bd_space + size); } pp->base = (void __iomem *)pdata->iobase; From patchwork Mon May 28 06:33:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baruch Siach X-Patchwork-Id: 921316 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=tkos.co.il Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40vRth5BbMz9s0y for ; Mon, 28 May 2018 16:35:24 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 6028AC21DD4; Mon, 28 May 2018 06:34:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id C245FC21BE5; Mon, 28 May 2018 06:34:24 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E926DC21BE5; Mon, 28 May 2018 06:34:22 +0000 (UTC) Received: from mx.tkos.co.il (guitar.tcltek.co.il [192.115.133.116]) by lists.denx.de (Postfix) with ESMTPS id 745C4C21BE5 for ; Mon, 28 May 2018 06:34:22 +0000 (UTC) Received: from tarshish.tkos.co.il (unknown [10.0.8.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx.tkos.co.il (Postfix) with ESMTPSA id 9156D44044D; Mon, 28 May 2018 09:34:21 +0300 (IDT) From: Baruch Siach To: Stefan Roese , Joe Hershberger Date: Mon, 28 May 2018 09:33:55 +0300 Message-Id: <2c410458fbdf31bbec87a254029b7bde8b029c98.1527489235.git.baruch@tkos.co.il> X-Mailer: git-send-email 2.17.0 In-Reply-To: <63028ec52402c6473fc144ac9f2a89f5f0604784.1527489235.git.baruch@tkos.co.il> References: <63028ec52402c6473fc144ac9f2a89f5f0604784.1527489235.git.baruch@tkos.co.il> Cc: u-boot@lists.denx.de, Baruch Siach Subject: [U-Boot] [PATCH 2/2] net: ping,arp: Fix cache alignment issues X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Jon Nettleton Both ping_receive and arp_receive would transmit a received packet back out using its original point. This causes problems with certain network cards that add a custom header to the packet. Specifically the mvneta driver for the Armada series boards has a 2 byte Marvell header that is bypassed and passed along to the system, but that 2 byte offset now causes a misalignment if it is attempted to be sent back out. Rather than changing the driver to memcpy all the received packets to cache aligned buffers we instead change the two offending network commands to copy the packet into a cache aligned net_tx_packet before sending it back out. This fixes occasional messages like: CACHE: Misaligned operation at range [3fc01082, 3fc010c2] Signed-off-by: Jon Nettleton Signed-off-by: Baruch Siach Reviewed-by: Stefan Roese --- net/arp.c | 3 ++- net/ping.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/net/arp.c b/net/arp.c index 990b771c9211..b8a71684cd76 100644 --- a/net/arp.c +++ b/net/arp.c @@ -182,7 +182,8 @@ void arp_receive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len) (net_read_ip(&arp->ar_spa).s_addr & net_netmask.s_addr)) udelay(5000); #endif - net_send_packet((uchar *)et, eth_hdr_size + ARP_HDR_SIZE); + memcpy(net_tx_packet, et, eth_hdr_size + ARP_HDR_SIZE); + net_send_packet(net_tx_packet, eth_hdr_size + ARP_HDR_SIZE); return; case ARPOP_REPLY: /* arp reply */ diff --git a/net/ping.c b/net/ping.c index 5464f2f785fe..3e5461a36a02 100644 --- a/net/ping.c +++ b/net/ping.c @@ -107,7 +107,8 @@ void ping_receive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len) icmph->type = ICMP_ECHO_REPLY; icmph->checksum = 0; icmph->checksum = compute_ip_checksum(icmph, len - IP_HDR_SIZE); - net_send_packet((uchar *)et, eth_hdr_size + len); + memcpy(net_tx_packet, et, eth_hdr_size + len); + net_send_packet(net_tx_packet, eth_hdr_size + len); return; /* default: return;*/