From patchwork Thu Jun 14 07:36:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 138527 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp1770506lji; Thu, 14 Jun 2018 00:37:59 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIKcpryJdLN3APdekXHRKTvVDrvPbpxEAiTST2wuZNwFsjJpGn0hHRqhXlx+dBQpPAdv30C X-Received: by 2002:a62:3dca:: with SMTP id x71-v6mr8325998pfj.134.1528961879624; Thu, 14 Jun 2018 00:37:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528961879; cv=none; d=google.com; s=arc-20160816; b=Bgi5V+Y1+KWucZhgiWojJOdh7HfEb/ruh3rf/FUuB1JPI5Aulo3d1zL34Pqaq6Fvk9 Dq8q9YZCAHKKKk0mSJIfJs3uS74NAZ9B8QwC9YC8/JoYYemTqSzFPSvxCpO2wsBlglSZ r64HS2yjUa0nXgHTQqiCO2OCZSFvXr/00Qhu/Dc/1/OZ/rsnpnsNr/T0n2cbzm23HvKt HLutdo2ByJ57MR+QmTv3kRC5z3OqTtq5U4MABtMNjTk16y7S8+G2eupWHAwcgJ5m3sHA c3aiTnIzkd7kV9L409CBkDudte5IHCPpnFrmD15EjD7SiPY5Zhtq7MSD6JOAhgEMg0lo 7Jag== 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=gh2ITQCuvB3PSfC4YEndLDdg+ZBajfugI8ie8hVaMzU=; b=pinMPKa3VzLeLeZFDUH44UcgqxokH1VT/OEjcOn3DnWO605dAEPR4utzH7QalKPagW g+fYshR4xc3CRcIcnPco3idEZs58h//1PId7Jz38+REwaf/KtutBVDukz6wcNrPXPdCz 1YJQEm4KHYrPDwpwgt/SP4FxSNkIToAxCDqnP2Kd1Hmw25/UmOw4X+c3EG3cinO71Qeq EGEj5AyHKEBBYK/bkWd9vTJrci87TXTOUvDiCaDHlFP72kcgO+LuqI+IcWdQzas09xoy fAEkYHc0y3+PXIUUiCQhstmIyWBBxrWkz/7vKQ/hoPgS3A0ngihz6uqQRmQhAEQo+ukx c3QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="C/19vKzh"; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-owner@vger.kernel.org; dmarc=fail (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 q24-v6si3830943pgv.658.2018.06.14.00.37.59; Thu, 14 Jun 2018 00:37:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="C/19vKzh"; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754790AbeFNHhZ (ORCPT + 5 others); Thu, 14 Jun 2018 03:37:25 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:39808 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754688AbeFNHhP (ORCPT ); Thu, 14 Jun 2018 03:37:15 -0400 Received: by mail-lf0-f66.google.com with SMTP id t2-v6so1444780lfd.6 for ; Thu, 14 Jun 2018 00:37:14 -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=m0EPNV9PY6l0QgOuy7PjTTS6a92xNNMAKQ2oPnDBFpI=; b=C/19vKzhnBb9Yw4Uu+d4DE+bGscdQuvt4e+SwpW4tFH0T+PazQ9XSx+AROmHLP9i2z U9u3VnJVab2WGsxbxl3jmUNPHWmx/F9N4Q7xW3xUAjjvNrmXoSvZXCv+FrjH76ikjaTT qgk6a1ElXBDAisWck7XIvn9VNgvfNI5CPukOE= 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=m0EPNV9PY6l0QgOuy7PjTTS6a92xNNMAKQ2oPnDBFpI=; b=Q++zBxHM2i3S/TGtiL+EsFRRf9nb95mueqcU468SETfsvQXx4/F9ZQuYOSPpl4LaPU yGNdJw/KIRVH2olV8p+5R4kLGj2xVzJG3OJe4En3zvxtTv2HBkhEZxVnMufbaOT0QH12 obL1gR130Hw7Jd1qLK8IBrUoutshQbBniNNyzOhsY5P/esfMCZHOdTn9lwlSk4arazFt SqDoOoSFte6qKWMQgTdDz13jh9PaIKZwM6oNZzJuGQ1vjNx7yS50pGvFCZl8Pr958XPN OaaLwXpQzl/FjmZ3/i1+nLjGfXvNKbRGWdCvwyQuMVtjyqf/BjvO2OSNoNdKciAVoXGG 3tMA== X-Gm-Message-State: APt69E19IYE4L6fZq8SLxb8EWti/e93tzS3VMsdYE3X3J4GVMNS3jtLb gHq0lRUH5tA4+Ghmf3av8fmRPA== X-Received: by 2002:a2e:994f:: with SMTP id r15-v6mr900004ljj.53.1528961833199; Thu, 14 Jun 2018 00:37:13 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id a195-v6sm957597lfe.44.2018.06.14.00.37.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Jun 2018 00:37:12 -0700 (PDT) From: Ivan Khoronzhuk To: grygorii.strashko@ti.com, davem@davemloft.net 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 v2 net-next 3/6] net: ethernet: ti: cpsw: add MQPRIO Qdisc offload Date: Thu, 14 Jun 2018 10:36:47 +0300 Message-Id: <20180614073650.29659-4-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180614073650.29659-1-ivan.khoronzhuk@linaro.org> References: <20180614073650.29659-1-ivan.khoronzhuk@linaro.org> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@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. Signed-off-by: Ivan Khoronzhuk --- drivers/net/ethernet/ti/cpsw.c | 82 ++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index 406537d74ec1..edd14def98df 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) @@ -453,6 +456,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; }; @@ -1577,6 +1581,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); @@ -2190,6 +2202,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, @@ -2205,6 +2286,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)