From patchwork Mon Jul 23 21:26:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 142657 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6513316ljj; Mon, 23 Jul 2018 14:27:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdM35iPw7UJIgLPSAqFBpfhsDmzAtTtvvX0+HmnKwne7bIr6jz56XySDS4+G8HWqzBlvOBU X-Received: by 2002:a63:82c7:: with SMTP id w190-v6mr13701759pgd.253.1532381243474; Mon, 23 Jul 2018 14:27:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532381243; cv=none; d=google.com; s=arc-20160816; b=wR4GQZuCqF3hOBFkHtN0jm2lifVVKcV3tZwOf1ycvA/WKuzKokg/IJH+cMYEaPwZF6 Sx0/WpD7v6peryQdojtsH+L3ASUT9WPcoS4OQEgGA5bBYGlNyAqjW377CwAMaaUv8mmD PbljhSY7ZZEFD22aY9vrsyqVBEDqgLu/w5LC6AIxobG6TnawrnzRrh+4ZFcLRHoIM5+U +5B8cJitoAjZbTM6u6aS/JiWB7Z7ZgKkOeF6Edp6EmZBXjNDM7b8Rk6e7uW7vas9Cg2P xomK3A1u5kFHGdzfTrxbEF/j+OVjIQQO06Jdt4FxQ5NaxsIl95eyTYmU5l0d5EXP+ytZ JE/w== 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=d6SxujkB7i/NOWSEmFn7FILLzZO3VffxZbLkIMwnwbU=; b=B2IAqF+jrlBu0Hse7fZZy7xOFHcgvwuLuJj48YqS28Nb98I3FIVyGvrxXhLz2j78V9 lncGFRehoDtwOCWeM7r0mrgFgSXhDFrcbLX1T2Biu7cTvd6FAAfNgqhizzJCdDmJXoro 92tugtlvwtWsFox4pJ2at4OLyo0TTynBbi3aK4HCTdwMWS0T5WzA9crKE45tXuxgKrXZ QlUTSrtb0PYWPnxuIq4WUfDuLO5zfUYKnProPrKftBZsl3KkvumcOhoU/nd2Ls4lM8Q8 GcXZ1U/nV/nPp7gikj428VBmCFqxDrkNtkSDx9xOe7gs3to/QIpW9SDu+n6dXeW9CpGw YACw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SWhHNAwL; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 i130-v6si9207008pgd.691.2018.07.23.14.27.23; Mon, 23 Jul 2018 14:27:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-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=SWhHNAwL; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 S2388293AbeGWWaC (ORCPT + 10 others); Mon, 23 Jul 2018 18:30:02 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:42394 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388239AbeGWWaB (ORCPT ); Mon, 23 Jul 2018 18:30:01 -0400 Received: by mail-lj1-f195.google.com with SMTP id f1-v6so1765060ljc.9 for ; Mon, 23 Jul 2018 14:26:53 -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=d6SxujkB7i/NOWSEmFn7FILLzZO3VffxZbLkIMwnwbU=; b=SWhHNAwLgWGbfrmqJEdZfMSZ0PEQC78FeGL1FkUurnJPCHnG6IVV9Uqrcu9mvQPiZt 3MZYOLNVIIRVpghDSME3KVWqIztPYgSguKZZRq90kOmOC8QzxXfXgfhldxonTWnNHwOy Z5LV6CnuEexgZIlgl+oeO+BJC75f9Xa4rW3pQ= 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=d6SxujkB7i/NOWSEmFn7FILLzZO3VffxZbLkIMwnwbU=; b=NIb6WS1Z+iCW44yTy8VkPbhcxq5OcRxQZwVLsge3FwtU8+L3i4ccgHNOiq90irBAAa VnW68Rno+FlR1C0I3fozyUdr97r4QzN+bpQHrBkGYrUzvGKSGiL+LO+tnYnQaISZA9B6 I/42HLLsOyJX7uab59Q8cAvAPhi+6I0RPyiBonovxqYjRdU8YUNcSfJyirStDuTywoGW OMiinxnpvO89eSgeEqWcsRZybMZZ4pJwmoc+we1k7dtFQXFX7H+l7x5VwBnVx/MiLHR8 ihrXUcBLM/IeoXy6aioDgZF0YMkRzZcc2ia5FmWbN22DgmagGUSsWRFNfrfy3JgTytFx 6iCQ== X-Gm-Message-State: AOUpUlHq1ZC8NkewTZXUkUr71RnQ8B1v/jpCz2B1qt/JD+7G1yOX1WR/ /l2JE8CtpSyaKTBfRXez5LN2SA== X-Received: by 2002:a2e:4d9d:: with SMTP id c29-v6mr9548349ljd.132.1532381212537; Mon, 23 Jul 2018 14:26:52 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id q4-v6sm1990435ljh.36.2018.07.23.14.26.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 14:26:51 -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 v5 net-next 3/6] net: ethernet: ti: cpsw: add MQPRIO Qdisc offload Date: Tue, 24 Jul 2018 00:26:31 +0300 Message-Id: <20180723212634.3219-4-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180723212634.3219-1-ivan.khoronzhuk@linaro.org> References: <20180723212634.3219-1-ivan.khoronzhuk@linaro.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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: Ilias Apalodimas Reviewed-by: Grygorii Strashko Signed-off-by: Ivan Khoronzhuk --- drivers/net/ethernet/ti/cpsw.c | 82 ++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) -- 2.17.1 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)