Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5562898pxb; Tue, 16 Feb 2021 01:30:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJzV6nCxqi5XZ7vJOrVkUjAEdg6fvMRlrjLKiBSFbIEneC2wCnRlDwyXRKafodu/sjFEQBAl X-Received: by 2002:a17:906:4058:: with SMTP id y24mr16726364ejj.6.1613467820720; Tue, 16 Feb 2021 01:30:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613467820; cv=none; d=google.com; s=arc-20160816; b=VWJICYUymXTOdrLOSSvkulSbVDBrBOYnsoFNcouunVIFfd9zEp2cpSgraNQ2MngbDP ellmTY2rP4bU52zePfremwbhomKvtdZT5EIoctfTmeMF6MQh93XknO0x8WPOukMW9r/F qLhoOgS6Yo0Tb4Cq6T9KarGqHYklmDXghB7BYlelxJqA615Vr2kMO3GAmzfwGYsghPN7 /tRc2cNJZi8aociCA3jAnm+rkxmhABGVx6vK+AeZMv8lbqD4nV0OC03V0kKjeMVAzYtk CfPe1vMGfLBbnOV7O7ugTY7Dsow9k8prDnSBUacvBEWzCOeoxbjSGmo6vcM2oKHkL+Xs gLOA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ZCSBqa6aacwCStOFYjtT3qnQEtskuR6rqpF4N1eHadk=; b=jltz2fwI4gyZTM55DgRXRAVXPQ2Xn4WntGTKTRpWJGziPXkyyQUDJBy1SJPWPVOfbv Pjtxfcg+hHUDmfqU/JlvUa4hipLV8jXJE5/F4sdJN5OmRnc7N6TkfgBWecOeSf1rsbuf pXiXoQ+ks0W36TUmE1f3lnHBPwqM0T6Vb2nkALJQ4rU1HAopd3ZcTpEuWGF0cA+OJbhV j/j/fMPbNDDxG2JszRUJ3urkHNFPQuC8MY7GvhybreaZ6P9yattM5JfomF3SIK8vY41u WiZfnipK8WFgbxIDXeL/T9oQMmHLuHVs5yrz2tQJ0GCxSJ5y4A+s7DfC9TKn9w0rbGpK wJWw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y13si15287308edm.557.2021.02.16.01.29.58; Tue, 16 Feb 2021 01:30:20 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230088AbhBPJ2B (ORCPT + 99 others); Tue, 16 Feb 2021 04:28:01 -0500 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:45093 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229956AbhBPJ0a (ORCPT ); Tue, 16 Feb 2021 04:26:30 -0500 X-Originating-IP: 90.55.97.122 Received: from pc-2.home (apoitiers-259-1-26-122.w90-55.abo.wanadoo.fr [90.55.97.122]) (Authenticated sender: maxime.chevallier@bootlin.com) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 6E0501BF20E; Tue, 16 Feb 2021 09:25:42 +0000 (UTC) From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, gregory.clement@bootlin.com, Andrew Lunn , =?UTF-8?q?Pali=20Roh=C3=A1r?= Subject: [PATCH net-next v2 2/2] net: mvneta: Implement mqprio support Date: Tue, 16 Feb 2021 10:25:36 +0100 Message-Id: <20210216092536.1153864-3-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210216092536.1153864-1-maxime.chevallier@bootlin.com> References: <20210216092536.1153864-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement a basic MQPrio support, inserting rules in RX that translate the TC to prio mapping into vlan prio to queues. The TX logic stays the same as when we don't offload the qdisc. Signed-off-by: Maxime Chevallier --- V2 : Fixed the reverse xmas tree, as per Andrew's review. Fixed a compile warning from the ktest bot drivers/net/ethernet/marvell/mvneta.c | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c index 8e410fafff8d..a635cf84608a 100644 --- a/drivers/net/ethernet/marvell/mvneta.c +++ b/drivers/net/ethernet/marvell/mvneta.c @@ -102,6 +102,8 @@ #define MVNETA_TX_NO_DATA_SWAP BIT(5) #define MVNETA_DESC_SWAP BIT(6) #define MVNETA_TX_BRST_SZ_MASK(burst) ((burst) << 22) +#define MVNETA_VLAN_PRIO_TO_RXQ 0x2440 +#define MVNETA_VLAN_PRIO_RXQ_MAP(prio, rxq) ((rxq) << ((prio) * 3)) #define MVNETA_PORT_STATUS 0x2444 #define MVNETA_TX_IN_PRGRS BIT(1) #define MVNETA_TX_FIFO_EMPTY BIT(8) @@ -490,6 +492,7 @@ struct mvneta_port { u8 mcast_count[256]; u16 tx_ring_size; u16 rx_ring_size; + u8 prio_tc_map[8]; phy_interface_t phy_interface; struct device_node *dn; @@ -4922,6 +4925,63 @@ static int mvneta_ethtool_set_eee(struct net_device *dev, return phylink_ethtool_set_eee(pp->phylink, eee); } +static void mvneta_clear_rx_prio_map(struct mvneta_port *pp) +{ + mvreg_write(pp, MVNETA_VLAN_PRIO_TO_RXQ, 0); +} + +static void mvneta_setup_rx_prio_map(struct mvneta_port *pp) +{ + u32 val = 0; + int i; + + for (i = 0; i < rxq_number; i++) + val |= MVNETA_VLAN_PRIO_RXQ_MAP(i, pp->prio_tc_map[i]); + + mvreg_write(pp, MVNETA_VLAN_PRIO_TO_RXQ, val); +} + +static int mvneta_setup_mqprio(struct net_device *dev, + struct tc_mqprio_qopt *qopt) +{ + struct mvneta_port *pp = netdev_priv(dev); + u8 num_tc; + int i; + + qopt->hw = TC_MQPRIO_HW_OFFLOAD_TCS; + num_tc = qopt->num_tc; + + if (num_tc > rxq_number) + return -EINVAL; + + if (!num_tc) { + mvneta_clear_rx_prio_map(pp); + netdev_reset_tc(dev); + return 0; + } + + memcpy(pp->prio_tc_map, qopt->prio_tc_map, sizeof(pp->prio_tc_map)); + + mvneta_setup_rx_prio_map(pp); + + netdev_set_num_tc(dev, qopt->num_tc); + for (i = 0; i < qopt->num_tc; i++) + netdev_set_tc_queue(dev, i, qopt->count[i], qopt->offset[i]); + + return 0; +} + +static int mvneta_setup_tc(struct net_device *dev, enum tc_setup_type type, + void *type_data) +{ + switch (type) { + case TC_SETUP_QDISC_MQPRIO: + return mvneta_setup_mqprio(dev, type_data); + default: + return -EOPNOTSUPP; + } +} + static const struct net_device_ops mvneta_netdev_ops = { .ndo_open = mvneta_open, .ndo_stop = mvneta_stop, @@ -4934,6 +4994,7 @@ static const struct net_device_ops mvneta_netdev_ops = { .ndo_do_ioctl = mvneta_ioctl, .ndo_bpf = mvneta_xdp, .ndo_xdp_xmit = mvneta_xdp_xmit, + .ndo_setup_tc = mvneta_setup_tc, }; static const struct ethtool_ops mvneta_eth_tool_ops = { -- 2.25.4