From patchwork Sun Dec 13 20:05:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 7839641 X-Patchwork-Delegate: horms@verge.net.au Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5607F9F1C2 for ; Sun, 13 Dec 2015 20:06:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 71ACF203C2 for ; Sun, 13 Dec 2015 20:05:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6D5D320397 for ; Sun, 13 Dec 2015 20:05:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752317AbbLMUFh (ORCPT ); Sun, 13 Dec 2015 15:05:37 -0500 Received: from mail-lb0-f179.google.com ([209.85.217.179]:32928 "EHLO mail-lb0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752101AbbLMUFU (ORCPT ); Sun, 13 Dec 2015 15:05:20 -0500 Received: by lbbkw15 with SMTP id kw15so95398768lbb.0 for ; Sun, 13 Dec 2015 12:05:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cogentembedded-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:organization:user-agent :mime-version:content-transfer-encoding:content-type; bh=8q0HITdfiF7fQYqHDDTNeIcqKSNOtB6Z3+h0QrvmO+U=; b=OvgJzDj4AX3mJmioe1AI0lEKus4/eFrE/9yBUOdnfzHIQFVqOj3QE+UiOvucbFXVK/ 8eNf36/9jQPX7+Zawnul+MHd3BrCGHTykmEfP7hYBsDQJiF8+f4lgqFaFyjA5YblorZN O2PSSGDgEZmHrn7RiqgJ1xmYkAJXP8Flm6aIgRMVgJRTtZwasnFYnLqWffnN8m4AD+q1 jEljKwnUcGmw1mQp7uuQFn9LPFY1L6fQSAGgw10/QzOyY9uIA/qFNCFOE2ItuhxQ80pU 89HFVkOz6YgLXGujwWqyMo8HFE4Img2/tEHZYiM4F+sNwwdvByhRNceOtKrQWN8TJgo1 H+rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:organization :user-agent:mime-version:content-transfer-encoding:content-type; bh=8q0HITdfiF7fQYqHDDTNeIcqKSNOtB6Z3+h0QrvmO+U=; b=YhWxDm/rLrWEo8ZG75El8f0Do04nCth3jaTJZMrwSoFd7G7QBvi/Fnl1hqtRDvtYFg ZVB8ZRDkiHeYB/h3riyDYkusE9H4iQB2Ah5ZJFcumWhMK0jn0QFq8j9hOC7m2PiWo0DA 319ys6JL3/OlZruKMrmqsnBRbsbJ4PHbYXgNnbfMd9d6PbZHrwq0U9DqRn9rTyRqqwk5 4MecmIeeJPeW7SqAqe50DAK/6BE44tjzbg5uIDRc/Ao1fe0UxFgiILGPvG+XcLdN1KKQ elyt3nR7SAvFq4YsxJhTNWB4BNJ2Yo/+xs1BEpDYcJDOZ+/+yMgX5dcOBZWv+yzWjrMi qjDw== X-Gm-Message-State: ALoCoQmugWtdWyWS5KcsVJKMXMpDdfpgMmwg6JRgBKIwwWY+rTl8JQdfnOgQkRxmyanMWmXHusrvNPnBljL6FxgHce8akbS+gg== X-Received: by 10.112.141.70 with SMTP id rm6mr9603776lbb.94.1450037118508; Sun, 13 Dec 2015 12:05:18 -0800 (PST) Received: from wasted.cogentembedded.com ([83.149.8.38]) by smtp.gmail.com with ESMTPSA id l67sm5031111lfl.26.2015.12.13.12.05.08 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 13 Dec 2015 12:05:14 -0800 (PST) From: Sergei Shtylyov To: netdev@vger.kernel.org Cc: linux-sh@vger.kernel.org Subject: [PATCH] sh_eth: fix descriptor access endianness Date: Sun, 13 Dec 2015 23:05:07 +0300 Message-ID: <11070795.yxBPvlHg4n@wasted.cogentembedded.com> Organization: Cogent Embedded Inc. User-Agent: KMail/4.14.10 (Linux/4.2.6-201.fc22.x86_64; KDE/4.14.14; x86_64; ; ) MIME-Version: 1.0 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver never calls cpu_to_edmac() when writing the descriptor address and edmac_to_cpu() when reading it, although it should -- fix this. Note that the frame/buffer length descriptor field accesses also need fixing but since they are both 16-bit we can't use {cpu|edmac}_to_{edmac|cpu}()... Signed-off-by: Sergei Shtylyov --- The patch is against DaveM's 'net.git' repo plus the patch I've posted today. drivers/net/ethernet/renesas/sh_eth.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: net/drivers/net/ethernet/renesas/sh_eth.c =================================================================== --- net.orig/drivers/net/ethernet/renesas/sh_eth.c +++ net/drivers/net/ethernet/renesas/sh_eth.c @@ -1172,7 +1172,7 @@ static void sh_eth_ring_format(struct ne break; } mdp->rx_skbuff[i] = skb; - rxdesc->addr = dma_addr; + rxdesc->addr = cpu_to_edmac(mdp, dma_addr); rxdesc->status = cpu_to_edmac(mdp, RD_RACT | RD_RFP); /* Rx descriptor address set */ @@ -1403,7 +1403,8 @@ static int sh_eth_txfree(struct net_devi entry, edmac_to_cpu(mdp, txdesc->status)); /* Free the original skb. */ if (mdp->tx_skbuff[entry]) { - dma_unmap_single(&ndev->dev, txdesc->addr, + dma_unmap_single(&ndev->dev, + edmac_to_cpu(mdp, txdesc->addr), txdesc->buffer_length, DMA_TO_DEVICE); dev_kfree_skb_irq(mdp->tx_skbuff[entry]); mdp->tx_skbuff[entry] = NULL; @@ -1479,14 +1480,15 @@ static int sh_eth_rx(struct net_device * if (desc_status & RD_RFS10) ndev->stats.rx_over_errors++; } else if (skb) { + dma_addr = edmac_to_cpu(mdp, rxdesc->addr); if (!mdp->cd->hw_swap) sh_eth_soft_swap( - phys_to_virt(ALIGN(rxdesc->addr, 4)), + phys_to_virt(ALIGN(dma_addr, 4)), pkt_len + 2); mdp->rx_skbuff[entry] = NULL; if (mdp->cd->rpadir) skb_reserve(skb, NET_IP_ALIGN); - dma_unmap_single(&ndev->dev, rxdesc->addr, + dma_unmap_single(&ndev->dev, dma_addr, ALIGN(mdp->rx_buf_sz, 32), DMA_FROM_DEVICE); skb_put(skb, pkt_len); @@ -1523,7 +1525,7 @@ static int sh_eth_rx(struct net_device * mdp->rx_skbuff[entry] = skb; skb_checksum_none_assert(skb); - rxdesc->addr = dma_addr; + rxdesc->addr = cpu_to_edmac(mdp, dma_addr); } dma_wmb(); /* RACT bit must be set after all the above writes */ if (entry >= mdp->num_rx_ring - 1) @@ -2331,8 +2333,8 @@ static void sh_eth_tx_timeout(struct net /* Free all the skbuffs in the Rx queue. */ for (i = 0; i < mdp->num_rx_ring; i++) { rxdesc = &mdp->rx_ring[i]; - rxdesc->status = 0; - rxdesc->addr = 0xBADF00D0; + rxdesc->status = cpu_to_edmac(mdp, 0); + rxdesc->addr = cpu_to_edmac(mdp, 0xBADF00D0); dev_kfree_skb(mdp->rx_skbuff[i]); mdp->rx_skbuff[i] = NULL; } @@ -2350,6 +2352,7 @@ static int sh_eth_start_xmit(struct sk_b { struct sh_eth_private *mdp = netdev_priv(ndev); struct sh_eth_txdesc *txdesc; + dma_addr_t dma_addr; u32 entry; unsigned long flags; @@ -2373,12 +2376,13 @@ static int sh_eth_start_xmit(struct sk_b /* soft swap. */ if (!mdp->cd->hw_swap) sh_eth_soft_swap(PTR_ALIGN(skb->data, 4), skb->len + 2); - txdesc->addr = dma_map_single(&ndev->dev, skb->data, skb->len, - DMA_TO_DEVICE); - if (dma_mapping_error(&ndev->dev, txdesc->addr)) { + dma_addr = dma_map_single(&ndev->dev, skb->data, skb->len, + DMA_TO_DEVICE); + if (dma_mapping_error(&ndev->dev, dma_addr)) { kfree_skb(skb); return NETDEV_TX_OK; } + txdesc->addr = cpu_to_edmac(mdp, dma_addr); txdesc->buffer_length = skb->len; dma_wmb(); /* TACT bit must be set after all the above writes */