From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 54FC8322C for ; Tue, 20 Nov 2018 11:26:50 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2018 02:26:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,256,1539673200"; d="scan'208";a="90712036" Received: from silpixa00399125.ir.intel.com ([10.237.223.34]) by orsmga007.jf.intel.com with ESMTP; 20 Nov 2018 02:26:48 -0800 From: Tiago Lam To: dev@dpdk.org Cc: ferruh.yigit@intel.com, linville@tuxdriver.com, Tiago Lam Date: Tue, 20 Nov 2018 10:26:31 +0000 Message-Id: <1542709592-215007-3-git-send-email-tiago.lam@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1542709592-215007-1-git-send-email-tiago.lam@intel.com> References: <1542707697-175836-1-git-send-email-tiago.lam@intel.com> <1542709592-215007-1-git-send-email-tiago.lam@intel.com> Subject: [dpdk-dev] [PATCH v2 3/3] net/af_packet: get 'framesz' from the iface's MTU X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Nov 2018 10:26:50 -0000 Use the underlying MTU to calculate the framsize to be used for the mmap RINGs. This is to make it more flexible on deployments with different MTU requirements, instead of using a pre-defined value of 2048B. If a 'framsz' option is provided, that value is used instead and the MTU of the underlying interface is ignored. Signed-off-by: Tiago Lam --- v2: Fix checkpatches.sh and check-git-log.sh warnings. --- drivers/net/af_packet/rte_eth_af_packet.c | 33 ++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index 8d749a2..5549211 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -788,7 +788,7 @@ rte_eth_from_packet(struct rte_vdev_device *dev, unsigned k_idx; unsigned int blockcount; unsigned int blocksize = DFLT_BLOCK_SIZE; - unsigned int framesize = DFLT_FRAME_SIZE; + unsigned int framesize = 0; unsigned int framecount = DFLT_FRAME_COUNT; unsigned int qpairs = 1; unsigned int qdisc_bypass = 1; @@ -877,17 +877,40 @@ rte_eth_from_packet(struct rte_vdev_device *dev, } ifnamelen = strlen(ifname); - if (ifnamelen >= sizeof(ifr.ifr_name)) { + if (ifnamelen < sizeof(ifr.ifr_name)) { + memcpy(ifr.ifr_name, ifname, ifnamelen); + ifr.ifr_name[ifnamelen] = '\0'; + } else { RTE_LOG(ERR, PMD, "%s: I/F name too long (%s)\n", name, ifname); return -1; } + /* + * Base framesize on the MTU of the underlying interface, if no + * 'framesz' option is given + */ + if (!framesize) { + if (ioctl(*sockfd, SIOCGIFMTU, &ifr) == -1) { + RTE_LOG(ERR, PMD, + "%s: ioctl failed (SIOCGIFMTU)", + name); + framesize = DFLT_FRAME_SIZE; + } else { + framesize = ifr.ifr_mtu; + /* + * Align to TPACKET_ALIGNMENT and add TPACKET2_HDRLEN, + * to account for the extra needed space + */ + framesize = TPACKET_ALIGN(framesize + TPACKET2_HDRLEN); + } + } + if (framesize > blocksize) { - PMD_LOG(ERR, - "%s: AF_PACKET MMAP frame size exceeds block size!", - name); + RTE_LOG(ERR, PMD, + "%s: AF_PACKET MMAP frame size (%u) exceeds block size (%u)!", + name, framesize, blocksize); return -1; } -- 2.7.4