From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 278D5A0C56; Wed, 8 Sep 2021 10:59:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A05B841158; Wed, 8 Sep 2021 10:59:47 +0200 (CEST) Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by mails.dpdk.org (Postfix) with ESMTP id 422534013F for ; Wed, 8 Sep 2021 10:59:46 +0200 (CEST) Received: by mail-wr1-f52.google.com with SMTP id t18so2199821wrb.0 for ; Wed, 08 Sep 2021 01:59:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QG4JZYjhu+uO1p3Fgv05mrT9mBUqsfEUDtrnT9Bre3A=; b=pzawkwZHC3ZWWsmD4sw0AnhUsHlGPofWQTzJaXVk0I3nrm2YuujsCdjvvx3uA1d55h zUzxJ3I5bwGXYuugad3VxpwpyTmxPSrnriSvtmfnJhycJvW1uJpir1rPQ2+AzjfQiMoP lllENVXe6hv3dMz75BF3Zu6el1X4r2Z8ZD2b+mXwyaPC+6RkkxqKl3x+o+N572gmiGFY +5OnTpfldCgUMUWWBOi3Vx298BZZ8WnMlLy9/NPkeAGH4eDlXk2s78NljdcXtrCve4nV 5W2rSlvpFhnv2hGl/IYR9ugA+Y5RK9ScFEeiNQBrBce4ppjEJqRAFZfccsksxhcrkJ4v izvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QG4JZYjhu+uO1p3Fgv05mrT9mBUqsfEUDtrnT9Bre3A=; b=iHJJKTob1iAjKIFw8FFeY0pvw/wYQXoSIHZE/LO7fxPpJftu7WZZFeM4WEncgdlYau qRvqUfiWIbFb+afGec61C6HdoC/hjgqjrOJm1TzAFVFz7u5yrgDi7S/WcG4Uq2/xGkpV YBtgPa6Mzn/5VtAeTGHDM4FvJ3TRGgUlb8Vn2JOmhec6sFH7Fk9KpDs7wAgFUySVQQQT 6ipIvdGnd1mW5JXXLY9ai3P7W9S035tqQIGh9jhX7KNsbU5yXZLqyORwmKEOu5jeEGhB 5sxjEf1I1GxIJ9y6i47ZRHSndW4e0flso4icipjnZc+jwfANQUSx4ALGTaF9cXLDzbOC NmhQ== X-Gm-Message-State: AOAM532N+pdstInN2hPTj3xvba56uNL35WPn73hJMVXXRIgxokWISo4Q LTfUGiR9PqppFTPZNtbTa/0= X-Google-Smtp-Source: ABdhPJxdZlZLEey4jCYQIXcYhwpclZqKLjHKYutDiUuhAHkxKeGddKcbdzOASLM3YgD5yFeJCiERuQ== X-Received: by 2002:adf:fd88:: with SMTP id d8mr2834649wrr.13.1631091586004; Wed, 08 Sep 2021 01:59:46 -0700 (PDT) Received: from tucornea-dev-machine.localdomain ([193.226.172.44]) by smtp.gmail.com with ESMTPSA id 19sm1438559wmo.39.2021.09.08.01.59.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Sep 2021 01:59:45 -0700 (PDT) From: Tudor Cornea To: ferruh.yigit@intel.com, linville@tuxdriver.com, stephen@networkplumber.org, andrew.rybchenko@oktetlabs.ru, thomas@monjalon.net, jerinj@marvell.com Cc: dev@dpdk.org, Tudor Cornea Date: Wed, 8 Sep 2021 11:59:18 +0300 Message-Id: <1631091558-63337-1-git-send-email-tudor.cornea@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1629463607-76292-1-git-send-email-tudor.cornea@gmail.com> References: <1629463607-76292-1-git-send-email-tudor.cornea@gmail.com> Subject: [dpdk-dev] [PATCH v2] net/af_packet: reinsert the stripped vlan tag X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The af_packet pmd driver binds to a raw socket and allows sending and receiving of packets through the kernel. Since commit [1], the kernel strips the vlan tags early in __netif_receive_skb_core(), so we receive untagged packets while running with the af_packet pmd. Luckily for us, the skb vlan-related fields are still populated from the stripped vlan tags, so we end up having all the information that we need in the mbuf. Having the PMD driver support DEV_RX_OFFLOAD_VLAN_STRIP allows the application to control the desired vlan stripping behavior. [1] https://github.com/torvalds/linux/commit/bcc6d47903612c3861201cc3a866fb604f26b8b2 Signed-off-by: Tudor Cornea --- v2: * Add DEV_RX_OFFLOAD_VLAN_STRIP to rxmode->offloads --- drivers/net/af_packet/rte_eth_af_packet.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index b73b211..5ed9dd6 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -48,6 +48,7 @@ struct pkt_rx_queue { struct rte_mempool *mb_pool; uint16_t in_port; + uint8_t vlan_strip; volatile unsigned long rx_pkts; volatile unsigned long rx_bytes; @@ -78,6 +79,7 @@ struct pmd_internals { struct pkt_rx_queue *rx_queue; struct pkt_tx_queue *tx_queue; + uint8_t vlan_strip; }; static const char *valid_arguments[] = { @@ -148,6 +150,9 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) if (ppd->tp_status & TP_STATUS_VLAN_VALID) { mbuf->vlan_tci = ppd->tp_vlan_tci; mbuf->ol_flags |= (PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED); + + if (!pkt_q->vlan_strip && rte_vlan_insert(&mbuf)) + PMD_LOG(ERR, "Failed to reinsert VLAN tag"); } /* release incoming frame and advance ring buffer */ @@ -302,6 +307,11 @@ eth_dev_stop(struct rte_eth_dev *dev) static int eth_dev_configure(struct rte_eth_dev *dev __rte_unused) { + struct rte_eth_conf *dev_conf = &dev->data->dev_conf; + const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode; + struct pmd_internals *internals = dev->data->dev_private; + + internals->vlan_strip = !!(rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP); return 0; } @@ -318,6 +328,7 @@ eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) dev_info->min_rx_bufsize = 0; dev_info->tx_offload_capa = DEV_TX_OFFLOAD_MULTI_SEGS | DEV_TX_OFFLOAD_VLAN_INSERT; + dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP; return 0; } @@ -448,6 +459,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev, dev->data->rx_queues[rx_queue_id] = pkt_q; pkt_q->in_port = dev->data->port_id; + pkt_q->vlan_strip = internals->vlan_strip; return 0; } -- 2.7.4