Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp146136ima; Fri, 1 Feb 2019 00:50:54 -0800 (PST) X-Google-Smtp-Source: ALg8bN55I6mhxHPx9oRZz3okKoVMISKfpeGfpnEHy31KkZxIcT5OxEjzB8UpXIJ6gf1tqouR8idx X-Received: by 2002:a62:7e13:: with SMTP id z19mr38277281pfc.94.1549011054805; Fri, 01 Feb 2019 00:50:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549011054; cv=none; d=google.com; s=arc-20160816; b=LQMayju6d/OaCzUYFB/idxEBhCjo5HhNBMUU//Bw22GAn/u/smUvmI7iSkjKKTOq1o l4aipDj8bEjDTcCcybLy9PJXJp7JQ3iiGpCfV0q9L2GkuipCGKmUDhah1sGMrW1lyIzu sOlaTxzc6qP3rCSXuNnHJDmnEWiPRAgfOjmauItKsSas2F+zl7t5UWjHG0TZhyqVyZsb vk1OLo+Y1aX8H8llM6BAUt8DrrXNL/ACENYxgtsRLzJlLUPA2asORdhYnS7zY7HywL1W NtnPeQFMb8ep0v190ToX12FsfpNupkFWgarcYTSOiiBoarHKLIUJ2uCKEAtd/YYvW7qR fhnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zMOwIVCHl/3RSZU/IZr6L//+E7MYj6EUe0TSRYGQl6Y=; b=gxf7DraW5m9E09h2xtMX7JOM4bHnOrz10djR8FIH82gveul65d+L38u082X60NJpHT lNf76scwqoefKgi4ptrrd2GoPeZqURw7ago38o2QlzgwGRVDeL6lY1hSEm1jjKzv8TaO 2e2wDfjmC69Y0eJhGiooDLHuV3yw/pL/9GzxB2TubcBUrLpEwMMJ+HlfTJzO4PzrE7Uf uwiIZ0sYFCtANXvB1c/1iB7p1K8mawdPVRpd/qXduSPPTmKt26TWzBu5bCfX7+R+qbJ4 kndosF9TMCHaQfv0kpuPJDUou/hiDfkvgvE8Skz+oXTd3MA08eSvxc9CRssTHc66VjNH qnGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=LiBiSbGo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i16si1812470pgk.445.2019.02.01.00.50.39; Fri, 01 Feb 2019 00:50:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=LiBiSbGo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729595AbfBAIsc (ORCPT + 99 others); Fri, 1 Feb 2019 03:48:32 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:48430 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729556AbfBAIsa (ORCPT ); Fri, 1 Feb 2019 03:48:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=zMOwIVCHl/3RSZU/IZr6L//+E7MYj6EUe0TSRYGQl6Y=; b=LiBiSbGo5IPnaiejGCGng1QljA HXZ0WUc3L7YVimZ6z5jlGBboZ6YKdo0uuqUXkSy7TTJ7B0WtVhWzHy/wNo67WNS05CNQG6NvCFjDa EoqpHqEGFt0HlWOBcOYyH0UwiXtXoP94ercGnU5TanudT4wNnJTQM1/JXUhkTXal3OkAf6SAGNwjR oxd++UEQZvm6Ydtaw90HkQjqPX0E+MySMhsSV3zrkG/xjg0EW4T+syCVvv6Do8R8pfquQsukrPTqa L1XHHiLiigjJJlehTCiDF51ptjTXYtPEaMlwEv1//KHKdrLmaGTBvZE0kCeS1H0XZ8dGNmlXPs8eJ GA1QbSKA==; Received: from 089144212163.atnat0021.highway.a1.net ([89.144.212.163] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gpUUs-0001Qm-OP; Fri, 01 Feb 2019 08:48:27 +0000 From: Christoph Hellwig To: John Crispin , Vinod Koul , Dmitry Tarnyagin , Nicolas Ferre , Sudip Mukherjee , Felipe Balbi , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org, netdev@vger.kernel.org, linux-usb@vger.kernel.org, linux-fbdev@vger.kernel.org, alsa-devel@alsa-project.org Cc: iommu@lists.linux-foundation.org Subject: [PATCH 09/18] meth: pass struct device to DMA API functions Date: Fri, 1 Feb 2019 09:47:52 +0100 Message-Id: <20190201084801.10983-10-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190201084801.10983-1-hch@lst.de> References: <20190201084801.10983-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The DMA API generally relies on a struct device to work properly, and only barely works without one for legacy reasons. Pass the easily available struct device from the platform_device to remedy this. Also use GFP_KERNEL instead of GFP_ATOMIC as the gfp_t for the memory allocation, as we aren't in interrupt context or under a lock. Signed-off-by: Christoph Hellwig --- drivers/net/ethernet/sgi/meth.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/sgi/meth.c b/drivers/net/ethernet/sgi/meth.c index 0e1b7e960b98..67954a9e3675 100644 --- a/drivers/net/ethernet/sgi/meth.c +++ b/drivers/net/ethernet/sgi/meth.c @@ -68,6 +68,8 @@ module_param(timeout, int, 0); * packets in and out, so there is place for a packet */ struct meth_private { + struct platform_device *pdev; + /* in-memory copy of MAC Control register */ u64 mac_ctrl; @@ -211,8 +213,8 @@ static void meth_check_link(struct net_device *dev) static int meth_init_tx_ring(struct meth_private *priv) { /* Init TX ring */ - priv->tx_ring = dma_alloc_coherent(NULL, TX_RING_BUFFER_SIZE, - &priv->tx_ring_dma, GFP_ATOMIC); + priv->tx_ring = dma_alloc_coherent(&priv->pdev->dev, + TX_RING_BUFFER_SIZE, &priv->tx_ring_dma, GFP_KERNEL); if (!priv->tx_ring) return -ENOMEM; @@ -236,7 +238,7 @@ static int meth_init_rx_ring(struct meth_private *priv) priv->rx_ring[i]=(rx_packet*)(priv->rx_skbs[i]->head); /* I'll need to re-sync it after each RX */ priv->rx_ring_dmas[i] = - dma_map_single(NULL, priv->rx_ring[i], + dma_map_single(&priv->pdev->dev, priv->rx_ring[i], METH_RX_BUFF_SIZE, DMA_FROM_DEVICE); mace->eth.rx_fifo = priv->rx_ring_dmas[i]; } @@ -253,7 +255,7 @@ static void meth_free_tx_ring(struct meth_private *priv) dev_kfree_skb(priv->tx_skbs[i]); priv->tx_skbs[i] = NULL; } - dma_free_coherent(NULL, TX_RING_BUFFER_SIZE, priv->tx_ring, + dma_free_coherent(&priv->pdev->dev, TX_RING_BUFFER_SIZE, priv->tx_ring, priv->tx_ring_dma); } @@ -263,7 +265,7 @@ static void meth_free_rx_ring(struct meth_private *priv) int i; for (i = 0; i < RX_RING_ENTRIES; i++) { - dma_unmap_single(NULL, priv->rx_ring_dmas[i], + dma_unmap_single(&priv->pdev->dev, priv->rx_ring_dmas[i], METH_RX_BUFF_SIZE, DMA_FROM_DEVICE); priv->rx_ring[i] = 0; priv->rx_ring_dmas[i] = 0; @@ -393,7 +395,8 @@ static void meth_rx(struct net_device* dev, unsigned long int_status) fifo_rptr = (fifo_rptr - 1) & 0x0f; } while (priv->rx_write != fifo_rptr) { - dma_unmap_single(NULL, priv->rx_ring_dmas[priv->rx_write], + dma_unmap_single(&priv->pdev->dev, + priv->rx_ring_dmas[priv->rx_write], METH_RX_BUFF_SIZE, DMA_FROM_DEVICE); status = priv->rx_ring[priv->rx_write]->status.raw; #if MFE_DEBUG @@ -454,7 +457,8 @@ static void meth_rx(struct net_device* dev, unsigned long int_status) priv->rx_ring[priv->rx_write] = (rx_packet*)skb->head; priv->rx_ring[priv->rx_write]->status.raw = 0; priv->rx_ring_dmas[priv->rx_write] = - dma_map_single(NULL, priv->rx_ring[priv->rx_write], + dma_map_single(&priv->pdev->dev, + priv->rx_ring[priv->rx_write], METH_RX_BUFF_SIZE, DMA_FROM_DEVICE); mace->eth.rx_fifo = priv->rx_ring_dmas[priv->rx_write]; ADVANCE_RX_PTR(priv->rx_write); @@ -637,7 +641,7 @@ static void meth_tx_1page_prepare(struct meth_private *priv, } /* first page */ - catbuf = dma_map_single(NULL, buffer_data, buffer_len, + catbuf = dma_map_single(&priv->pdev->dev, buffer_data, buffer_len, DMA_TO_DEVICE); desc->data.cat_buf[0].form.start_addr = catbuf >> 3; desc->data.cat_buf[0].form.len = buffer_len - 1; @@ -663,12 +667,12 @@ static void meth_tx_2page_prepare(struct meth_private *priv, } /* first page */ - catbuf1 = dma_map_single(NULL, buffer1_data, buffer1_len, + catbuf1 = dma_map_single(&priv->pdev->dev, buffer1_data, buffer1_len, DMA_TO_DEVICE); desc->data.cat_buf[0].form.start_addr = catbuf1 >> 3; desc->data.cat_buf[0].form.len = buffer1_len - 1; /* second page */ - catbuf2 = dma_map_single(NULL, buffer2_data, buffer2_len, + catbuf2 = dma_map_single(&priv->pdev->dev, buffer2_data, buffer2_len, DMA_TO_DEVICE); desc->data.cat_buf[1].form.start_addr = catbuf2 >> 3; desc->data.cat_buf[1].form.len = buffer2_len - 1; @@ -840,6 +844,7 @@ static int meth_probe(struct platform_device *pdev) memcpy(dev->dev_addr, o2meth_eaddr, ETH_ALEN); priv = netdev_priv(dev); + priv->pdev = pdev; spin_lock_init(&priv->meth_lock); SET_NETDEV_DEV(dev, &pdev->dev); -- 2.20.1