From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CEC8C43381 for ; Mon, 4 Mar 2019 12:29:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 788282070B for ; Mon, 4 Mar 2019 12:29:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726334AbfCDM3u (ORCPT ); Mon, 4 Mar 2019 07:29:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36326 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726041AbfCDM3s (ORCPT ); Mon, 4 Mar 2019 07:29:48 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 697C0307D84F; Mon, 4 Mar 2019 12:29:48 +0000 (UTC) Received: from carbon (ovpn-200-46.brq.redhat.com [10.40.200.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBC162CFD5; Mon, 4 Mar 2019 12:29:38 +0000 (UTC) Date: Mon, 4 Mar 2019 13:29:37 +0100 From: Jesper Dangaard Brouer To: Ioana Ciornei Cc: "netdev@vger.kernel.org" , "davem@davemloft.net" , Ioana Ciocoi Radulescu , "ilias.apalodimas@linaro.org" , "toke@redhat.com" , brouer@redhat.com Subject: Re: [PATCH v2 2/2] dpaa2-eth: add XDP_REDIRECT support Message-ID: <20190304132937.65efdfed@carbon> In-Reply-To: <1551462396-5115-3-git-send-email-ioana.ciornei@nxp.com> References: <1551462396-5115-1-git-send-email-ioana.ciornei@nxp.com> <1551462396-5115-3-git-send-email-ioana.ciornei@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 04 Mar 2019 12:29:48 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Fri, 1 Mar 2019 17:47:24 +0000 Ioana Ciornei wrote: > +static int dpaa2_eth_xdp_xmit_frame(struct net_device *net_dev, > + struct xdp_frame *xdpf) > +{ > + struct dpaa2_eth_priv *priv = netdev_priv(net_dev); > + struct device *dev = net_dev->dev.parent; > + struct rtnl_link_stats64 *percpu_stats; > + struct dpaa2_eth_drv_stats *percpu_extras; > + unsigned int needed_headroom; > + struct dpaa2_eth_swa *swa; > + struct dpaa2_eth_fq *fq; > + struct dpaa2_fd fd; > + void *buffer_start, *aligned_start; > + dma_addr_t addr; > + int err, i; > + > + /* We require a minimum headroom to be able to transmit the frame. > + * Otherwise return an error and let the original net_device handle it > + */ > + needed_headroom = dpaa2_eth_needed_headroom(priv, NULL); > + if (xdpf->headroom < needed_headroom) > + return -EINVAL; > + > + percpu_stats = this_cpu_ptr(priv->percpu_stats); > + percpu_extras = this_cpu_ptr(priv->percpu_extras); > + > + /* Setup the FD fields */ > + memset(&fd, 0, sizeof(fd)); > + > + /* Align FD address, if possible */ > + buffer_start = xdpf->data - needed_headroom; > + aligned_start = PTR_ALIGN(buffer_start - DPAA2_ETH_TX_BUF_ALIGN, > + DPAA2_ETH_TX_BUF_ALIGN); > + if (aligned_start >= xdpf->data - xdpf->headroom) > + buffer_start = aligned_start; > + > + swa = (struct dpaa2_eth_swa *)buffer_start; > + /* fill in necessary fields here */ > + swa->type = DPAA2_ETH_SWA_XDP; > + swa->xdp.dma_size = xdpf->data + xdpf->len - buffer_start; > + swa->xdp.xdpf = xdpf; > + > + addr = dma_map_single(dev, buffer_start, > + swa->xdp.dma_size, > + DMA_BIDIRECTIONAL); > + if (unlikely(dma_mapping_error(dev, addr))) { > + percpu_stats->tx_dropped++; > + return -ENOMEM; > + } > + > + dpaa2_fd_set_addr(&fd, addr); > + dpaa2_fd_set_offset(&fd, xdpf->data - buffer_start); > + dpaa2_fd_set_len(&fd, xdpf->len); > + dpaa2_fd_set_format(&fd, dpaa2_fd_single); > + dpaa2_fd_set_ctrl(&fd, FD_CTRL_PTA); > + > + fq = &priv->fq[smp_processor_id()]; It is guaranteed that you have one FQ per CPU in the system? > + for (i = 0; i < DPAA2_ETH_ENQUEUE_RETRIES; i++) { > + err = priv->enqueue(priv, fq, &fd, 0); > + if (err != -EBUSY) > + break; -- Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer