From patchwork Mon Apr 1 03:57:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavan Chebbi X-Patchwork-Id: 13612511 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE8178495 for ; Mon, 1 Apr 2024 03:54:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711943696; cv=none; b=SrnJr0U7IG/xs3mq39yfGZeqpeMlFFpRStWi0seMjrYk+g2xIXejoEPEak12ZfGE8myjRFX+cqxAR12yp8xRY8UysJe/wrIO3odBKbQmE/n7OYG9yeyqSzXDNiz3n6FGE/SMe4w2T+f5u9CPWVtKDI9u59KmSgxi5gFVUAkbCH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711943696; c=relaxed/simple; bh=tfQvJubytWLf9Ir6N7h6RFpZWcwbBqzXG2L9H0MfRFM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Nq0pOkmGA3p9sbDAaC0BjzX3X1rtKObUtaxR2XlHPySzr/lo3o5R8oY1zDZRYWwSCDH2byxAbIemDmouIKagTtFrW1reds4fEZzrOb5O8wdEtnJrskwfACcs7eO0+8Jrh2inO7ziooyngZgnyYH1/Je1SzupP4eve7Xxfzx69Sg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=gEW/Wucq; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="gEW/Wucq" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6e6f69e850bso4126693b3a.0 for ; Sun, 31 Mar 2024 20:54:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1711943694; x=1712548494; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=uypmKG72zh7U1cPnFQmXQqt/IU0mVzKjci1R1LjjDwo=; b=gEW/WucqQ5Bq4ABLHs79+wAgWw4DELWEBCRMB98+/EipH/wmrQ1S/z7YNM8APK27f/ ewiKn/dmnUlapoMWPpAK/VG9MNMBd+hC3um1md4slob2jd8ee0UxRafZEF/i8qcnZEIu FC+DSaapsFRWG1YcjvAB7e9EpHhjnG/foEMj0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711943694; x=1712548494; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uypmKG72zh7U1cPnFQmXQqt/IU0mVzKjci1R1LjjDwo=; b=ZaGMPDaN6WySCdOjcy694gk3x+eH1chdJ/FselMwI5nJ4G7721uKwZCVS/b57BxapG 3TqA3EKgX07X9apDk9NjZHY4B9Sw/1V1dVO/nvRlQpqGyxjmRt2KY+m1gD46er7zsiNV mlATKF601UqtSZelJFeCV5w34sElCWIqtCdGb9TNaZ0pktDhFnp4GxQ2/58xGDyuPOz2 badiNBqhkH6an+qFQQ72sakbzN0Mp3hbazR9gvppoz/4KWtVOz0zVYoykBv+FPaPgElA R0mvWvlkXs7buYtgOQdaV50HXuLMbRCGNz8h2KyJXqdDISF9XCK7mL28ZLg6lK2mVfNH upWw== X-Forwarded-Encrypted: i=1; AJvYcCWKA3g0tIqB/tf0AQMnmTKvQfUZw8xHuH293JwsyGubOjmuTYJoOSzmBH9T49H8SW5sV0erqeSoBRY3XL320aEnxBnjqx2r X-Gm-Message-State: AOJu0YzqN5HbNc0caJfMWJjA1xzJVQwdvrjuRYENmnAPESLDulcLFBKt Ty4kK/HT/Ec4zcg+j6jyMmBQf1SoQGQ0G5t50hGSEgO135J4fPX77ebkw3oZ3Q== X-Google-Smtp-Source: AGHT+IGrmCmCc39bLwkGm81kCtIy4qoDlo3y55UyQNogGYecD7m/KewzCflIxZ8+dZqx8S1S8Hu7tQ== X-Received: by 2002:a05:6a00:14ca:b0:6e6:9942:fd97 with SMTP id w10-20020a056a0014ca00b006e69942fd97mr10467515pfu.15.1711943693822; Sun, 31 Mar 2024 20:54:53 -0700 (PDT) Received: from PC-MID-R740.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id j26-20020a62b61a000000b006e73d1c0c0esm6860781pff.154.2024.03.31.20.54.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Mar 2024 20:54:53 -0700 (PDT) From: Pavan Chebbi To: michael.chan@broadcom.com Cc: davem@davemloft.net, edumazet@google.com, gospo@broadcom.com, kuba@kernel.org, netdev@vger.kernel.org, pabeni@redhat.com, Somnath Kotur , Pavan Chebbi , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend Subject: [PATCH net-next 5/7] bnxt_en: Add XDP Metadata support Date: Sun, 31 Mar 2024 20:57:28 -0700 Message-Id: <20240401035730.306790-6-pavan.chebbi@broadcom.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20240401035730.306790-1-pavan.chebbi@broadcom.com> References: <20240401035730.306790-1-pavan.chebbi@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Somnath Kotur - Change the last arg to xdp_prepare_buff to true from false. - Ensure that when XDP_PASS is returned the xdp->data_meta area is copied to the skb->data area. Account for the meta data size on skb allocation and do a pull after to move it to the "reserved" zone. Signed-off-by: Somnath Kotur Reviewed-by: Michael Chan Reviewed-by: Pavan Chebbi Cc: Alexei Starovoitov Cc: Daniel Borkmann Cc: Jesper Dangaard Brouer Cc: John Fastabend Signed-off-by: Pavan Chebbi --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 44 +++++++++++++++++-- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 2 +- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 7dda4cd76715..1494b550299a 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -1296,9 +1296,9 @@ static int bnxt_agg_bufs_valid(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, return RX_AGG_CMP_VALID(agg, *raw_cons); } -static inline struct sk_buff *bnxt_copy_skb(struct bnxt_napi *bnapi, u8 *data, - unsigned int len, - dma_addr_t mapping) +static inline struct sk_buff *bnxt_copy_data(struct bnxt_napi *bnapi, u8 *data, + unsigned int len, + dma_addr_t mapping) { struct bnxt *bp = bnapi->bp; struct pci_dev *pdev = bp->pdev; @@ -1318,6 +1318,39 @@ static inline struct sk_buff *bnxt_copy_skb(struct bnxt_napi *bnapi, u8 *data, bp->rx_dir); skb_put(skb, len); + + return skb; +} + +static inline struct sk_buff *bnxt_copy_skb(struct bnxt_napi *bnapi, u8 *data, + unsigned int len, + dma_addr_t mapping) +{ + return bnxt_copy_data(bnapi, data, len, mapping); +} + +static inline struct sk_buff *bnxt_copy_xdp(struct bnxt_napi *bnapi, + struct xdp_buff *xdp, + unsigned int len, + dma_addr_t mapping) +{ + unsigned int metasize = 0; + u8 *data = xdp->data; + struct sk_buff *skb; + + len = xdp->data_end - xdp->data_meta; + metasize = xdp->data - xdp->data_meta; + data = xdp->data_meta; + + skb = bnxt_copy_data(bnapi, data, len, mapping); + if (!skb) + return skb; + + if (metasize) { + skb_metadata_set(skb, metasize); + __skb_pull(skb, metasize); + } + return skb; } @@ -2111,7 +2144,10 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, } if (len <= bp->rx_copy_thresh) { - skb = bnxt_copy_skb(bnapi, data_ptr, len, dma_addr); + if (!xdp_active) + skb = bnxt_copy_skb(bnapi, data_ptr, len, dma_addr); + else + skb = bnxt_copy_xdp(bnapi, &xdp, len, dma_addr); bnxt_reuse_rx_data(rxr, cons, data); if (!skb) { if (agg_bufs) { diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c index 6b904b4f4d34..345681d5007e 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c @@ -197,7 +197,7 @@ void bnxt_xdp_buff_init(struct bnxt *bp, struct bnxt_rx_ring_info *rxr, dma_sync_single_for_cpu(&pdev->dev, mapping + offset, len, bp->rx_dir); xdp_init_buff(xdp, buflen, &rxr->xdp_rxq); - xdp_prepare_buff(xdp, data_ptr - offset, offset, len, false); + xdp_prepare_buff(xdp, data_ptr - offset, offset, len, true); } void bnxt_xdp_buff_frags_free(struct bnxt_rx_ring_info *rxr,