From patchwork Sun Oct 27 09:41:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Jonker X-Patchwork-Id: 13852457 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C40D6D10C16 for ; Sun, 27 Oct 2024 09:42:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:From:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=bxJPDDPH76B44XvgOv9tArHi+778Nu7n90BN5x/QyO0=; b=s7FGNxQ6ut+QrK mP1IPuGzA33PZnCT0dxv/7QOPJNJzZNhGX19BpZvmQHLES5MjQ5S1emQqJg6mtBYoF9KfICU4+ZYH TUH/R1xN+2uQHD9NaGAtYcTmQSRK2wsl78Qb5zAuJWq8lnbC6sYjHCf1hig/qedTzBtrn7tjetjen 6+MSp+aGR+ozPfJPpMW4dseh/m42Y6eVJ1kDvQG9CpzYfqibKRv7aFccCIDXkcyVXKbf+IBTHIc8f VqWw4bXLqv2aTrWebEyj8rVsrtgjtK5Zi9lLNnxz7D5JhgW8IPAooJcOYR9palHcROq69ssRLQ2GV QsbddDW7HLBs2EJLc9Gg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t4zmV-00000007v2o-3wK1; Sun, 27 Oct 2024 09:41:55 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4zmT-00000007v2D-1Y7H for linux-rockchip@lists.infradead.org; Sun, 27 Oct 2024 09:41:55 +0000 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a9a2068f348so45066366b.2 for ; Sun, 27 Oct 2024 02:41:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730022111; x=1730626911; darn=lists.infradead.org; h=content-transfer-encoding:content-language:cc:to:subject:from :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=n2vkwpVcb4kCS4Ij9rwKADi36HiqXNmkZd+FH34mnDY=; b=fnxms25C1T+8v2e1TYtDjFcRC8WWJo1vlNykraiA17XIrfH1Pxux4g8SRsVNh6nSSr UMpYSeVD8T0HLedfECBz0xvAucC9i4W/Epq9H6pMfy0c3NsyZ+TOZyncbSEF9xjqD7dI o8DmfPRYyHkpP9aXCS5GxuQGsS8C6omJwbOJm18uT6R+GfvoC7bVPa1OlNr4ILv3YKGE 0eIB4UnrU2NKj0Rj4RyTvO3jiX7Y5daHwTZyNlwVFfEc9ADE4EIdtwLuy3CWJU/1kjHp Na6jJQZptpXcGnSHazQGEzGUWHrYoL3PaQ3ETPZcx3aTg7Fb0ftqd+a9giu6PE33M/4A tQ7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730022111; x=1730626911; h=content-transfer-encoding:content-language:cc:to:subject:from :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=n2vkwpVcb4kCS4Ij9rwKADi36HiqXNmkZd+FH34mnDY=; b=qudJc1rhvnEuZfadZhlF7+LRzeb19Bxn3umTcjAGVDfMFotDUaTYYYbjnTlR3Ncnp0 nW8hWFZVGsRAYenMvdZ0eXzUnErQtYW/2NEdAwpC1fVj22XOue8NC0A5aou2Dgrn5H5Z ehwehV5o7Zb3buI9MFV8v0ZuDdT9Ss9N24I6QQcpv9A/ItGXIqUBt1qNzbKi6s5ouwUY zwJecMgbvvgfxJapWbCBM39Gcb2CiX3L3qZ6wzyVvKk9nRRcRU1yqoTE7NsR/d3wC2XM BCUPEMj3P1oRUURjprLBaxwRUqlH2cQTU8szF8usWncPSsCjmEppsOCJOROLc6MTg1bS MhTg== X-Forwarded-Encrypted: i=1; AJvYcCXMDOSMq6ZHd8jhk8P9cmSg6v3IZ6ypckSxUJx17N2YR91MTFMB0DgYr4qR2BMifKvGlYP0pljhwWBkeJg6sA==@lists.infradead.org X-Gm-Message-State: AOJu0YyZsvlFXZNRUpSW4tJE1q396kyNGrftq27y/gyeRkIKJtFduorG Ft0xp4Ws8+xyyDtMn7aIfNrFHWll2y+kW6A5Mr7Trm8Hf8R7haNk X-Google-Smtp-Source: AGHT+IF6cXRGWL8cWTAfzT3Nbf0RVAMBXRR65eslgwEvWjHlEu6M4EFg/RFkFWQlQLDO9Izqdc9p0w== X-Received: by 2002:a17:907:7287:b0:a9a:1a17:e1cc with SMTP id a640c23a62f3a-a9de5a4a878mr153647666b.0.1730022110663; Sun, 27 Oct 2024 02:41:50 -0700 (PDT) Received: from ?IPV6:2a02:a449:4071:1:32d0:42ff:fe10:6983? ([2a02:a449:4071:1:32d0:42ff:fe10:6983]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f029564sm262490866b.51.2024.10.27.02.41.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 27 Oct 2024 02:41:49 -0700 (PDT) Message-ID: Date: Sun, 27 Oct 2024 10:41:48 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Johan Jonker Subject: [PATCH v1 1/2] ethernet: arc: fix the device for dma_map_single/dma_unmap_single To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: david.wu@rock-chips.com, andy.yan@rock-chips.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241027_024153_471331_67783FE1 X-CRM114-Status: GOOD ( 13.65 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org The ndev->dev and pdev->dev aren't the same device, use ndev->dev.parent which has dma_mask, ndev->dev.parent is just pdev->dev. Or it would cause the following issue: [ 39.933526] ------------[ cut here ]------------ [ 39.938414] WARNING: CPU: 1 PID: 501 at kernel/dma/mapping.c:149 dma_map_page_attrs+0x90/0x1f8 Signed-off-by: David Wu Signed-off-by: Johan Jonker --- Original: https://github.com/andyshrk/linux/commit/a98b368ca6ae79d227415c34e4ca39934af08a6f Changed: Use dev variable --- drivers/net/ethernet/arc/emac_main.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) -- 2.39.2 diff --git a/drivers/net/ethernet/arc/emac_main.c b/drivers/net/ethernet/arc/emac_main.c index 31ee477dd131..8283aeee35fb 100644 --- a/drivers/net/ethernet/arc/emac_main.c +++ b/drivers/net/ethernet/arc/emac_main.c @@ -111,6 +111,7 @@ static void arc_emac_tx_clean(struct net_device *ndev) { struct arc_emac_priv *priv = netdev_priv(ndev); struct net_device_stats *stats = &ndev->stats; + struct device *dev = ndev->dev.parent; unsigned int i; for (i = 0; i < TX_BD_NUM; i++) { @@ -140,7 +141,7 @@ static void arc_emac_tx_clean(struct net_device *ndev) stats->tx_bytes += skb->len; } - dma_unmap_single(&ndev->dev, dma_unmap_addr(tx_buff, addr), + dma_unmap_single(dev, dma_unmap_addr(tx_buff, addr), dma_unmap_len(tx_buff, len), DMA_TO_DEVICE); /* return the sk_buff to system */ @@ -174,6 +175,7 @@ static void arc_emac_tx_clean(struct net_device *ndev) static int arc_emac_rx(struct net_device *ndev, int budget) { struct arc_emac_priv *priv = netdev_priv(ndev); + struct device *dev = ndev->dev.parent; unsigned int work_done; for (work_done = 0; work_done < budget; work_done++) { @@ -223,9 +225,9 @@ static int arc_emac_rx(struct net_device *ndev, int budget) continue; } - addr = dma_map_single(&ndev->dev, (void *)skb->data, + addr = dma_map_single(dev, (void *)skb->data, EMAC_BUFFER_SIZE, DMA_FROM_DEVICE); - if (dma_mapping_error(&ndev->dev, addr)) { + if (dma_mapping_error(dev, addr)) { if (net_ratelimit()) netdev_err(ndev, "cannot map dma buffer\n"); dev_kfree_skb(skb); @@ -237,7 +239,7 @@ static int arc_emac_rx(struct net_device *ndev, int budget) } /* unmap previosly mapped skb */ - dma_unmap_single(&ndev->dev, dma_unmap_addr(rx_buff, addr), + dma_unmap_single(dev, dma_unmap_addr(rx_buff, addr), dma_unmap_len(rx_buff, len), DMA_FROM_DEVICE); pktlen = info & LEN_MASK; @@ -423,6 +425,7 @@ static int arc_emac_open(struct net_device *ndev) { struct arc_emac_priv *priv = netdev_priv(ndev); struct phy_device *phy_dev = ndev->phydev; + struct device *dev = ndev->dev.parent; int i; phy_dev->autoneg = AUTONEG_ENABLE; @@ -445,9 +448,9 @@ static int arc_emac_open(struct net_device *ndev) if (unlikely(!rx_buff->skb)) return -ENOMEM; - addr = dma_map_single(&ndev->dev, (void *)rx_buff->skb->data, + addr = dma_map_single(dev, (void *)rx_buff->skb->data, EMAC_BUFFER_SIZE, DMA_FROM_DEVICE); - if (dma_mapping_error(&ndev->dev, addr)) { + if (dma_mapping_error(dev, addr)) { netdev_err(ndev, "cannot dma map\n"); dev_kfree_skb(rx_buff->skb); return -ENOMEM; @@ -548,6 +551,7 @@ static void arc_emac_set_rx_mode(struct net_device *ndev) static void arc_free_tx_queue(struct net_device *ndev) { struct arc_emac_priv *priv = netdev_priv(ndev); + struct device *dev = ndev->dev.parent; unsigned int i; for (i = 0; i < TX_BD_NUM; i++) { @@ -555,7 +559,7 @@ static void arc_free_tx_queue(struct net_device *ndev) struct buffer_state *tx_buff = &priv->tx_buff[i]; if (tx_buff->skb) { - dma_unmap_single(&ndev->dev, + dma_unmap_single(dev, dma_unmap_addr(tx_buff, addr), dma_unmap_len(tx_buff, len), DMA_TO_DEVICE); @@ -579,6 +583,7 @@ static void arc_free_tx_queue(struct net_device *ndev) static void arc_free_rx_queue(struct net_device *ndev) { struct arc_emac_priv *priv = netdev_priv(ndev); + struct device *dev = ndev->dev.parent; unsigned int i; for (i = 0; i < RX_BD_NUM; i++) { @@ -586,7 +591,7 @@ static void arc_free_rx_queue(struct net_device *ndev) struct buffer_state *rx_buff = &priv->rx_buff[i]; if (rx_buff->skb) { - dma_unmap_single(&ndev->dev, + dma_unmap_single(dev, dma_unmap_addr(rx_buff, addr), dma_unmap_len(rx_buff, len), DMA_FROM_DEVICE); @@ -679,6 +684,7 @@ static netdev_tx_t arc_emac_tx(struct sk_buff *skb, struct net_device *ndev) unsigned int len, *txbd_curr = &priv->txbd_curr; struct net_device_stats *stats = &ndev->stats; __le32 *info = &priv->txbd[*txbd_curr].info; + struct device *dev = ndev->dev.parent; dma_addr_t addr; if (skb_padto(skb, ETH_ZLEN)) @@ -692,10 +698,9 @@ static netdev_tx_t arc_emac_tx(struct sk_buff *skb, struct net_device *ndev) return NETDEV_TX_BUSY; } - addr = dma_map_single(&ndev->dev, (void *)skb->data, len, - DMA_TO_DEVICE); + addr = dma_map_single(dev, (void *)skb->data, len, DMA_TO_DEVICE); - if (unlikely(dma_mapping_error(&ndev->dev, addr))) { + if (unlikely(dma_mapping_error(dev, addr))) { stats->tx_dropped++; stats->tx_errors++; dev_kfree_skb_any(skb);