Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp709209pxv; Thu, 15 Jul 2021 14:06:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkzk+k/ew1DcFi5WjDY/tZ1hE/FDfia8E3eWFsqhTRRJRrGuIQjDyhPyuvl3YH3Aoosk6m X-Received: by 2002:a17:907:a04e:: with SMTP id gz14mr7645056ejc.24.1626383163366; Thu, 15 Jul 2021 14:06:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626383163; cv=none; d=google.com; s=arc-20160816; b=xKG5fYVnZrxTKMihUSuE+r5xifO2X4w/60ZPY6mZLI5higIuhYQ0culg41vIzm58Xd 4YYaqdmhbieEG9qXoijob9HL1soHM8LeZfZ1cnoy1Mq5Qn932WWbRrIxSjz2SICaiaHH LjhSVXqAh6kXUJqRiAlIYK5doN7LvR2TtS72il7A9YHmmJULUa86w/uuBP+Q4m3t6cPj qcW62I4YfQdcyq2M441SmF1ZMbPlNYWIKhRlD6Yh24OK5xbeyukAkXZzkiAFB/kYXsCz 5zlIQqe0cGFTm1PvW6xUUwarrFqs5D7ljv0KY/J7NSE8nb03cbGU3bkHekJjoJsrdXok CF2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5b1hbTcCr2MPABajYn/HDQhGVjykU7ldSsPa7iYH0yw=; b=WwLbguZ70YmzcxX72FkaBNgbE1AvGZ8jI15fMkpuFxEpulznK5vZp8cOVZqXEAiFiu 7axjWM+EKkxXxo5pe0Zn2X2U360giY2KXblN6tsgxso6gUl+hPrW3sqrsiFvOs5J/8/a XkUvqiMYXvZ2Z0ki/aDOS0KPgt2WQLS0H158Re4Hd9gb7vsfu9fnGobV2UUD10Am7JSJ 7bVmvDBSXGMCzL3K+ri9XiylTrGYwe1/9n1+5FkkizTmq3y4SMfJCscsyXEzTEaJHFrW UptafciLn6E99QZCkqNcegCHDPBWhIJa9ZXeIMWWDKsIgdSeRm/3N1aKBy5+ZFYAO2bk vbUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LuaYtun+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u6si2191789edy.75.2021.07.15.14.05.36; Thu, 15 Jul 2021 14:06:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LuaYtun+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244648AbhGOTPA (ORCPT + 99 others); Thu, 15 Jul 2021 15:15:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:39662 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243225AbhGOTBm (ORCPT ); Thu, 15 Jul 2021 15:01:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8DDAC613E4; Thu, 15 Jul 2021 18:58:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375497; bh=AWt8MtIwfOEkzII2XUPUR49DdZGO10IyoYUx105z1Is=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LuaYtun+M6M28UiLUo+cBgjS8XmZyi1c07E5qeGOTIfR2KbdG5YeMB5pHQoKmpCBz kqHRWoRyINTsgzTX9QeFhPYWV/U5qUNxvZwJ0Q3XGbEXhrLmeT01UqwABkMLkU0FHk zymsl2IWGekpXdF+gtTDRFkWSlYDJrGJA8zxe85Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Frieder Schrempf , Fugang Duan , Joakim Zhang , kernel test robot , "David S. Miller" , Sasha Levin Subject: [PATCH 5.12 110/242] net: fec: add ndo_select_queue to fix TX bandwidth fluctuations Date: Thu, 15 Jul 2021 20:37:52 +0200 Message-Id: <20210715182612.437598271@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fugang Duan [ Upstream commit 52c4a1a85f4b346c39c896c0168f4a843b3385ff ] As we know that AVB is enabled by default, and the ENET IP design is queue 0 for best effort, queue 1&2 for AVB Class A&B. Bandwidth of each queue 1&2 set in driver is 50%, TX bandwidth fluctuated when selecting tx queues randomly with FEC_QUIRK_HAS_AVB quirk available. This patch adds ndo_select_queue callback to select queues for transmitting to fix this issue. It will always return queue 0 if this is not a vlan packet, and return queue 1 or 2 based on priority of vlan packet. You may complain that in fact we only use single queue for trasmitting if we are not targeted to VLAN. Yes, but seems we have no choice, since AVB is enabled when the driver probed, we can't switch this feature dynamicly. After compare multiple queues to single queue, TX throughput almost no improvement. One way we can implemet is to configure the driver to multiple queues with Round-robin scheme by default. Then add ndo_setup_tc callback to enable/disable AVB feature for users. Unfortunately, ENET AVB IP seems not follow the standard 802.1Qav spec. We only can program DMAnCFG[IDLE_SLOPE] field to calculate bandwidth fraction. And idle slope is restricted to certain valus (a total of 19). It's far away from CBS QDisc implemented in Linux TC framework. If you strongly suggest to do this, I think we only can support limited numbers of bandwidth and reject others, but it's really urgly and wried. With this patch, VLAN tagged packets route to queue 0/1/2 based on vlan priority; VLAN untagged packets route to queue 0. Tested-by: Frieder Schrempf Reported-by: Frieder Schrempf Signed-off-by: Fugang Duan Signed-off-by: Joakim Zhang Reported-by: kernel test robot Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/freescale/fec_main.c | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 15c9cffa8735..6c097ae3bac5 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -75,6 +75,8 @@ static void fec_enet_itr_coal_init(struct net_device *ndev); #define DRIVER_NAME "fec" +static const u16 fec_enet_vlan_pri_to_queue[8] = {0, 0, 1, 1, 1, 2, 2, 2}; + /* Pause frame feild and FIFO threshold */ #define FEC_ENET_FCE (1 << 5) #define FEC_ENET_RSEM_V 0x84 @@ -3228,10 +3230,40 @@ static int fec_set_features(struct net_device *netdev, return 0; } +static u16 fec_enet_get_raw_vlan_tci(struct sk_buff *skb) +{ + struct vlan_ethhdr *vhdr; + unsigned short vlan_TCI = 0; + + if (skb->protocol == htons(ETH_P_ALL)) { + vhdr = (struct vlan_ethhdr *)(skb->data); + vlan_TCI = ntohs(vhdr->h_vlan_TCI); + } + + return vlan_TCI; +} + +static u16 fec_enet_select_queue(struct net_device *ndev, struct sk_buff *skb, + struct net_device *sb_dev) +{ + struct fec_enet_private *fep = netdev_priv(ndev); + u16 vlan_tag; + + if (!(fep->quirks & FEC_QUIRK_HAS_AVB)) + return netdev_pick_tx(ndev, skb, NULL); + + vlan_tag = fec_enet_get_raw_vlan_tci(skb); + if (!vlan_tag) + return vlan_tag; + + return fec_enet_vlan_pri_to_queue[vlan_tag >> 13]; +} + static const struct net_device_ops fec_netdev_ops = { .ndo_open = fec_enet_open, .ndo_stop = fec_enet_close, .ndo_start_xmit = fec_enet_start_xmit, + .ndo_select_queue = fec_enet_select_queue, .ndo_set_rx_mode = set_multicast_list, .ndo_validate_addr = eth_validate_addr, .ndo_tx_timeout = fec_timeout, -- 2.30.2