Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4985860imm; Fri, 18 May 2018 14:18:17 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrjMqsbCyt3YFFR4CvX5Pe4cpJ1vMahC6Hvm5iZj1+NJMrY81yb2N2viRz3wP+Lkd98XSWz X-Received: by 2002:a17:902:380c:: with SMTP id l12-v6mr11133792plc.19.1526678297850; Fri, 18 May 2018 14:18:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526678297; cv=none; d=google.com; s=arc-20160816; b=EfA2uo3ablBMA0O3DGRLCIwDCyf+JIKd40YPpwtzDCmNwyKTXTqQe/F4jFmTa8MjnG 8w7Kr+hqAiwQNxVTDekKgnrN3grhB68xSVrl7hixKR/NkGYTN0le96EX2XCcS7d478tn EUNgOGranHSqG8zAinnE8vgntz34odQDLZO8979/DX5EaxG08rQwNxijgfPT8Fct1SFL ZOFC1Qp0RglY9300kJmqWMe4PkyUEPeqNiEZoiepekWFPEGlGcVOTxy69mNEfbw6P125 2BPXYVW+GqJeLJUHtDDjKDQT/tmbzuSJwcz5VdypOPcZTP8V/Ugf2g4Yzq2m4lrKTEGf eGaw== 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=2goMSuJTLIPVP1LiUGCXld9OtWQKdUTdKAVqXRx0QZ8=; b=DtX3t6O3H0QrDZKoSut1uVkx56UNkxv2TRHPLcTh3dgsa1pDABJVURjizee3RGyxC/ TiYj3diYwjZ1ybkG3yzTzMHhPsWnDQFBSHwCxGpRgyK5U9Yk8PTycqG4sy5hXPe14vzo kQGNmtHM6SORV6sChCCe7MZGYY0EZgmpVt/kqtHGWFg9WjGhXKcre8rsAkc1tjtqj4Wo N9cWb0XJ2yIJ6sfCMCGCFYZ/afgmTAqwutB7stozdpLI6zV74fIcN7EgTZTs2/4Xd/Pe b4ECV5Vj1X7wQ8Ark5QeT7laWBq3ZNd3YzBn8oL4JVnpm1TaA6ll8F/psvchPU3vLh83 gQRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J1+jkHPH; 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 p66-v6si8228545pfg.329.2018.05.18.14.18.03; Fri, 18 May 2018 14:18:17 -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=J1+jkHPH; 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 S1752567AbeERVQd (ORCPT + 99 others); Fri, 18 May 2018 17:16:33 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:37914 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751571AbeERVPW (ORCPT ); Fri, 18 May 2018 17:15:22 -0400 Received: by mail-lf0-f66.google.com with SMTP id z142-v6so15884624lff.5 for ; Fri, 18 May 2018 14:15:20 -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=2goMSuJTLIPVP1LiUGCXld9OtWQKdUTdKAVqXRx0QZ8=; b=J1+jkHPHNpEdUckB4dTrFUnod3h3Gp3RQxZhxJdqAdiWnlb6OZNIMfDkYzQgsH0eM9 ++H2XIT8FVye68gMoW3yCnDeJmcBa2M7XsKLfKA19b3pV0DL84EWDFYkNGm5DtgbHYhy /7Rnddnt4VtQnQH2V+UBpaOZwknIlc4h4z+MQ= 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=2goMSuJTLIPVP1LiUGCXld9OtWQKdUTdKAVqXRx0QZ8=; b=kwH5obbLkOnW/Yh+XoGxbPiMkhapqRwpFZqgZ7i/lBTjJ+7y8U7hbh0W9GsfUzXdfE JG2qV5l8oXvPpN6AbWlNsDai2mkJ5fqdj7X2oBYa2tvwyHQE1cfbJdQYcF6tD6x/6gCW zoHeKgcys3utspeCS7NQ2/2zsDdtTVsNrJwxZkuB9GyQp5nNldve7Slls4q3KcDM3vj+ D6hpnJOA+ppmKWKrcD1Rl69ZBCx3l5tuSMJ4qQaxEMZMw6nOJK/e20jBDKgRrxnZBj8Q HrhqxyHCrZPa2yZreHbXJ3oZtwbtaIc6AleIruU/aZ0WiK5gUdLUEiuATGMEMtbAHXNW jgNw== X-Gm-Message-State: ALKqPwfnzlLz7cJ1sV/NIxpQ4omtcMNoMORrRayCfS4VuFMqjr6g/vNC zHH9mndwd/Zfr3uGA3xfsoL/sQ== X-Received: by 2002:a19:7906:: with SMTP id u6-v6mr21249412lfc.34.1526678120005; Fri, 18 May 2018 14:15:20 -0700 (PDT) Received: from localhost.localdomain (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id g20-v6sm2045991lfk.39.2018.05.18.14.15.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 14:15:19 -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, Ivan Khoronzhuk Subject: [RFC PATCH 3/6] net: ethernet: ti: cpsw: add MQPRIO Qdisc offload Date: Sat, 19 May 2018 00:15:07 +0300 Message-Id: <20180518211510.13341-4-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180518211510.13341-1-ivan.khoronzhuk@linaro.org> References: <20180518211510.13341-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. 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 9bd615da04d3..4b232cda5436 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_tc(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_tc(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) -- 2.17.0