Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3861644imm; Sat, 21 Jul 2018 05:01:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpej4kF6dbvplNUKZuuhs0Xaz2d9Ui/r2Yj6RWBRTWEj92FMDPEjI3yiGWufp2IkCKWZcYec X-Received: by 2002:a62:5f82:: with SMTP id t124-v6mr5843677pfb.223.1532174479020; Sat, 21 Jul 2018 05:01:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532174478; cv=none; d=google.com; s=arc-20160816; b=QQAl1R499sKiqKVGFLYOu0tu7JiGtMpw3IY3wOAp5ElY0dMnBO+ojDkqcUhUl9sVeO jNnVnTebptdZp4PzxFwZkmpNmRVr18z0oQ2cmxuwZHPC0f/9adJOdQ0JU8xBKH/WpT28 GYTW3rXqcgbfSvRP0zb2xOQx4iIRq5clDeY+3a/D7ATMYobbiTmjk53k381k5u5lsH3+ TAWm+KzUaNnG4eut8XXCOtSqUVA0dmukEWXp8+e19Xmu8Sr/rO1DYsDjbWBHpMc8BPO8 YUUYXy+WYPf87s/5NvVFoJ0AuiVMcoW+rUCjsiJD1AC32ihi3F/TwoWUiLPfJvFeSjSG USAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=95EtP6zyKXSlPMkmbpywBc8oLM61zDOoygw4GvJUQCc=; b=FuHUeECleqvvl3Sbcvgt19U56n787VClZpwqWXXTuEq+NH9+zhmTfd5NW6goXlKiVj dCx50v7Yy+wPl8P0/91lkif815Zx4cOXw1qTvy7w1QUJ8Qb3WyLdCa3jff++uyDL2L31 8K8VyqGFyWVpymaVt5TKVBOtj3QWkCodteTN8gCRbCClEP+E/VgOtD22ONnocafl4MuD 2umEECak2H+9oyqsqhrBKqkRhTcaikhgphlbDpfXS4Tl1CvRCf2XKDoO+dwIpbgNzgMv DkTGuX/zXebJHr30GErG/jglikdfLntkI1f+b9P2J4Qb1UFcv6OeohXtJur4hiIossAb tlCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K1UtCUGX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 123-v6si4022616pfd.201.2018.07.21.05.01.04; Sat, 21 Jul 2018 05:01:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K1UtCUGX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728175AbeGUMwK (ORCPT + 99 others); Sat, 21 Jul 2018 08:52:10 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:45555 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728021AbeGUMwI (ORCPT ); Sat, 21 Jul 2018 08:52:08 -0400 Received: by mail-lj1-f195.google.com with SMTP id q5-v6so13181238ljh.12 for ; Sat, 21 Jul 2018 04:59:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=95EtP6zyKXSlPMkmbpywBc8oLM61zDOoygw4GvJUQCc=; b=K1UtCUGXtWv0A3op8kRX6qqCsyZZsJ5qGKGwl5nBuKpyUt52VL/lH2eOztMiR6Wif6 jqlomxagmQlWz9QjU3vvYKOyyLS2+GEaNbt95szzvxVOqKRS6DiU1/RXFdK0JQRpNUQd HJnmnU8vxaF9O16R8JzY+uj6e3/GCNbbsMZR4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=95EtP6zyKXSlPMkmbpywBc8oLM61zDOoygw4GvJUQCc=; b=AEWl1KTyKt1eFr3foC9xzhaAcXExQyk+49iexjZqZVu2vXhHpGYzPri0RL/q1NncH0 MyLv3LkmvnV3D7pMupkpujs4+odxC+V726nENlle5HWValQ7/44aeIH6OJrpKESt194i Fkvhox+MeucCjYkoVD4TpHcjtIqknq8k0Vi5VpGxHOEQnWirSJTZ/yBXCRa6l6lZ/AYy LFPIQ8o1ucW/WaogyOL1ozk4B2A+e/s+0+yXqKp3OHKnMrmqlNc/dI41vraN07CVOorn YgWzV0Jh1+fKNOmjFTSFeqnJuwBNm0Pdmc3ISHpx0dm/rysnMyJT06PsDb6S9pd01Kbp WG7w== X-Gm-Message-State: AOUpUlGoIN8cjGg1A9FRCoc6C1mAzFpzqvSqQJbXrhPC2WZnbYq0g+b9 HNUwXBGLPBzwgjBhtx95jBtHYw== X-Received: by 2002:a2e:2d0a:: with SMTP id t10-v6mr2716696ljt.8.1532174377296; Sat, 21 Jul 2018 04:59:37 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id 73-v6sm664260lfs.44.2018.07.21.04.59.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 04:59:36 -0700 (PDT) From: Ivan Khoronzhuk To: davem@davemloft.net, grygorii.strashko@ti.com Cc: corbet@lwn.net, akpm@linux-foundation.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, vinicius.gomes@intel.com, henrik@austad.us, jesus.sanchez-palencia@intel.com, ilias.apalodimas@linaro.org, p-varis@ti.com, spatton@ti.com, francois.ozog@linaro.org, yogeshs@ti.com, nsekhar@ti.com, andrew@lunn.ch, Ivan Khoronzhuk Subject: [PATCH v4 net-next 3/6] net: ethernet: ti: cpsw: add MQPRIO Qdisc offload Date: Sat, 21 Jul 2018 14:59:20 +0300 Message-Id: <20180721115923.1389-4-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180721115923.1389-1-ivan.khoronzhuk@linaro.org> References: <20180721115923.1389-1-ivan.khoronzhuk@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org That's possible to offload vlan to tc priority mapping with assumption sk_prio == L2 prio. Example: $ ethtool -L eth0 rx 1 tx 4 $ qdisc replace dev eth0 handle 100: parent root mqprio num_tc 3 \ map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 queues 1@0 1@1 2@2 hw 1 $ tc -g class show dev eth0 +---(100:ffe2) mqprio |    +---(100:3) mqprio |    +---(100:4) mqprio |     +---(100:ffe1) mqprio |    +---(100:2) mqprio |     +---(100:ffe0) mqprio     +---(100:1) mqprio Here, 100:1 is txq0, 100:2 is txq1, 100:3 is txq2, 100:4 is txq3 txq0 belongs to tc0, txq1 to tc1, txq2 and txq3 to tc2 The offload part only maps L2 prio to classes of traffic, but not to transmit queues, so to direct traffic to traffic class vlan has to be created with appropriate egress map. Reviewed-by: Grygorii Strashko Signed-off-by: Ivan Khoronzhuk --- drivers/net/ethernet/ti/cpsw.c | 82 ++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index 4425b537b9dd..f099e0ed138d 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -39,6 +39,7 @@ #include #include +#include #include "cpsw.h" #include "cpsw_ale.h" @@ -153,6 +154,8 @@ do { \ #define IRQ_NUM 2 #define CPSW_MAX_QUEUES 8 #define CPSW_CPDMA_DESCS_POOL_SIZE_DEFAULT 256 +#define CPSW_TC_NUM 4 +#define CPSW_FIFO_SHAPERS_NUM (CPSW_TC_NUM - 1) #define CPSW_RX_VLAN_ENCAP_HDR_PRIO_SHIFT 29 #define CPSW_RX_VLAN_ENCAP_HDR_PRIO_MSK GENMASK(2, 0) @@ -454,6 +457,7 @@ struct cpsw_priv { u8 mac_addr[ETH_ALEN]; bool rx_pause; bool tx_pause; + bool mqprio_hw; u32 emac_port; struct cpsw_common *cpsw; }; @@ -1578,6 +1582,14 @@ static void cpsw_slave_stop(struct cpsw_slave *slave, struct cpsw_common *cpsw) soft_reset_slave(slave); } +static int cpsw_tc_to_fifo(int tc, int num_tc) +{ + if (tc == num_tc - 1) + return 0; + + return CPSW_FIFO_SHAPERS_NUM - tc; +} + static int cpsw_ndo_open(struct net_device *ndev) { struct cpsw_priv *priv = netdev_priv(ndev); @@ -2191,6 +2203,75 @@ static int cpsw_ndo_set_tx_maxrate(struct net_device *ndev, int queue, u32 rate) return ret; } +static int cpsw_set_mqprio(struct net_device *ndev, void *type_data) +{ + struct tc_mqprio_qopt_offload *mqprio = type_data; + struct cpsw_priv *priv = netdev_priv(ndev); + struct cpsw_common *cpsw = priv->cpsw; + int fifo, num_tc, count, offset; + struct cpsw_slave *slave; + u32 tx_prio_map = 0; + int i, tc, ret; + + num_tc = mqprio->qopt.num_tc; + if (num_tc > CPSW_TC_NUM) + return -EINVAL; + + if (mqprio->mode != TC_MQPRIO_MODE_DCB) + return -EINVAL; + + ret = pm_runtime_get_sync(cpsw->dev); + if (ret < 0) { + pm_runtime_put_noidle(cpsw->dev); + return ret; + } + + if (num_tc) { + for (i = 0; i < 8; i++) { + tc = mqprio->qopt.prio_tc_map[i]; + fifo = cpsw_tc_to_fifo(tc, num_tc); + tx_prio_map |= fifo << (4 * i); + } + + netdev_set_num_tc(ndev, num_tc); + for (i = 0; i < num_tc; i++) { + count = mqprio->qopt.count[i]; + offset = mqprio->qopt.offset[i]; + netdev_set_tc_queue(ndev, i, count, offset); + } + } + + if (!mqprio->qopt.hw) { + /* restore default configuration */ + netdev_reset_tc(ndev); + tx_prio_map = TX_PRIORITY_MAPPING; + } + + priv->mqprio_hw = mqprio->qopt.hw; + + offset = cpsw->version == CPSW_VERSION_1 ? + CPSW1_TX_PRI_MAP : CPSW2_TX_PRI_MAP; + + slave = &cpsw->slaves[cpsw_slave_index(cpsw, priv)]; + slave_write(slave, tx_prio_map, offset); + + pm_runtime_put_sync(cpsw->dev); + + return 0; +} + +static int cpsw_ndo_setup_tc(struct net_device *ndev, enum tc_setup_type type, + void *type_data) +{ + switch (type) { + case TC_SETUP_QDISC_MQPRIO: + return cpsw_set_mqprio(ndev, type_data); + + default: + return -EOPNOTSUPP; + } +} + static const struct net_device_ops cpsw_netdev_ops = { .ndo_open = cpsw_ndo_open, .ndo_stop = cpsw_ndo_stop, @@ -2206,6 +2287,7 @@ static const struct net_device_ops cpsw_netdev_ops = { #endif .ndo_vlan_rx_add_vid = cpsw_ndo_vlan_rx_add_vid, .ndo_vlan_rx_kill_vid = cpsw_ndo_vlan_rx_kill_vid, + .ndo_setup_tc = cpsw_ndo_setup_tc, }; static int cpsw_get_regs_len(struct net_device *ndev) -- 2.17.1