From patchwork Fri May 20 01:15:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinicius Costa Gomes X-Patchwork-Id: 12856167 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 778FAC433EF for ; Fri, 20 May 2022 01:16:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344333AbiETBQ0 (ORCPT ); Thu, 19 May 2022 21:16:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344287AbiETBP7 (ORCPT ); Thu, 19 May 2022 21:15:59 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 940D12EA26 for ; Thu, 19 May 2022 18:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653009357; x=1684545357; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gS3QmrY8Ouj0uEw4FUK0Bv7IRhzbf1HjggXr/+kO/04=; b=NhWyyuNoAQRU266iUgXil0HmFvsdn324W1GIff2/aRcuqeZ2ypBa59RU gF4dKCoYenDW8BcuopZWY1IBTwf/2mqSB6niX/arZ1uX62EBm5P2g/o8j sJilZviBuJp/FAlYccplLvY8zBAondoUbryJ6vEGMZ+sD1f6ghgUoi4Fo /lW+/Pbin+05ef2qI2el5DmMlegfVkK+7OEpPGKvkWmAfI6jcqSmiuhj4 +ljjzHQ/yWeMWjobIumqYQhqXj7BdFMmY2KTa7H+ne1bKAbeOZd6+0UVw i1pFUmGc4+pm0t3omSEGij4EmWK8111R4Excfh8kxYsYwwcGV69SmRitp g==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="333064149" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="333064149" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:53 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570534535" Received: from vcostago-mobl3.jf.intel.com ([10.24.14.84]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:53 -0700 From: Vinicius Costa Gomes To: netdev@vger.kernel.org Cc: Vinicius Costa Gomes , jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, vladimir.oltean@nxp.com, po.liu@nxp.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH net-next v5 01/11] ethtool: Add support for configuring frame preemption Date: Thu, 19 May 2022 18:15:28 -0700 Message-Id: <20220520011538.1098888-2-vinicius.gomes@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220520011538.1098888-1-vinicius.gomes@intel.com> References: <20220520011538.1098888-1-vinicius.gomes@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Frame preemption (described in IEEE 802.3-2018, Section 99 in particular) defines the concept of preemptible and express queues. It allows traffic from express queues to "interrupt" traffic from preemptible queues, which are "resumed" after the express traffic has finished transmitting. Expose the UAPI bits for applications to enable using ethtool-netlink. Also expose the kernel ethtool functions, so device drivers can support it. Frame preemption can only be used when both the local device and the link partner support it. Signed-off-by: Vinicius Costa Gomes --- Documentation/networking/ethtool-netlink.rst | 52 ++++++ include/linux/ethtool.h | 23 +++ include/uapi/linux/ethtool_netlink.h | 18 ++ net/ethtool/Makefile | 3 +- net/ethtool/common.c | 23 +++ net/ethtool/netlink.c | 19 ++ net/ethtool/netlink.h | 4 + net/ethtool/preempt.c | 177 +++++++++++++++++++ 8 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 net/ethtool/preempt.c diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst index dbca3e9ec782..15d7c025cc4e 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -220,6 +220,8 @@ Userspace to kernel: ``ETHTOOL_MSG_PHC_VCLOCKS_GET`` get PHC virtual clocks info ``ETHTOOL_MSG_MODULE_SET`` set transceiver module parameters ``ETHTOOL_MSG_MODULE_GET`` get transceiver module parameters + ``ETHTOOL_MSG_PREEMPT_GET`` get frame preemption parameters + ``ETHTOOL_MSG_PREEMPT_SET`` set frame preemption parameters ===================================== ================================= Kernel to userspace: @@ -260,6 +262,7 @@ Kernel to userspace: ``ETHTOOL_MSG_STATS_GET_REPLY`` standard statistics ``ETHTOOL_MSG_PHC_VCLOCKS_GET_REPLY`` PHC virtual clocks info ``ETHTOOL_MSG_MODULE_GET_REPLY`` transceiver module parameters + ``ETHTOOL_MSG_PREEMPT_GET_REPLY`` frame preemption parameters ======================================== ================================= ``GET`` requests are sent by userspace applications to retrieve device @@ -1625,6 +1628,53 @@ For SFF-8636 modules, low power mode is forced by the host according to table For CMIS modules, low power mode is forced by the host according to table 6-12 in revision 5.0 of the specification. +PREEMPT_GET +=========== + +Get information about frame preemption state. + +Request contents: + + ==================================== ====== ========================== + ``ETHTOOL_A_PREEMPT_HEADER`` nested request header + ==================================== ====== ========================== + +Kernel response contents: + + ====================================== ====== ========================== + ``ETHTOOL_A_PREEMPT_HEADER`` nested reply header + ``ETHTOOL_A_PREEMPT_ENABLED`` bool frame preemption enabled + ``ETHTOOL_A_PREEMPT_PREEMPTIBLE_MASK`` bitset preemptible queue mask + ``ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE`` u32 Min additional frag size + ====================================== ====== ========================== + +``ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE`` configures the minimum non-final +fragment size that the receiver device supports. + +``ETHTOOL_A_PREEMPT_PREEMPTIBLE_MASK`` configures which queues should +be marked as preemptible. If bit X is '1' then queue X is preemptible, +the queue is express otherwise. + +PREEMPT_SET +=========== + +Sets frame preemption parameters. + +Request contents: + + ====================================== ====== ========================== + ``ETHTOOL_A_PREEMPT_HEADER`` nested reply header + ``ETHTOOL_A_PREEMPT_ENABLED`` bool frame preemption enabled + ``ETHTOOL_A_PREEMPT_PREEMPTIBLE_MASK`` bitset preemptible queue mask + ``ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE`` u32 Min additional frag size + ====================================== ====== ========================== + +``ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE`` configures the minimum non-final +fragment size that the receiver device supports. + +``ETHTOOL_A_PREEMPT_PREEMPTIBLE_MASK`` configures which queues should be marked as +preemptible. + Request translation =================== @@ -1726,4 +1776,6 @@ are netlink only. n/a ``ETHTOOL_MSG_PHC_VCLOCKS_GET`` n/a ``ETHTOOL_MSG_MODULE_GET`` n/a ``ETHTOOL_MSG_MODULE_SET`` + n/a ``ETHTOOL_MSG_PREEMPT_GET`` + n/a ``ETHTOOL_MSG_PREEMPT_SET`` =================================== ===================================== diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 99dc7bfbcd3c..42570ec8ee44 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -453,6 +453,20 @@ struct ethtool_module_power_mode_params { enum ethtool_module_power_mode mode; }; +/** + * struct ethtool_fp - Frame Preemption information + * + * @enabled: Enable frame preemption. + * @add_frag_size: Minimum size for additional (non-final) fragments + * in bytes, for the value defined in the IEEE 802.3-2018 standard see + * ethtool_frag_size_to_mult(). + */ +struct ethtool_fp { + u32 enabled; + u32 preemptible_mask; + u32 add_frag_size; +}; + /** * struct ethtool_ops - optional netdev operations * @cap_link_lanes_supported: indicates if the driver supports lanes @@ -606,6 +620,8 @@ struct ethtool_module_power_mode_params { * not report statistics. * @get_fecparam: Get the network device Forward Error Correction parameters. * @set_fecparam: Set the network device Forward Error Correction parameters. + * @get_preempt: Get the network device Frame Preemption parameters. + * @set_preempt: Set the network device Frame Preemption parameters. * @get_ethtool_phy_stats: Return extended statistics about the PHY device. * This is only useful if the device maintains PHY statistics and * cannot use the standard PHY library helpers. @@ -736,6 +752,10 @@ struct ethtool_ops { struct ethtool_fecparam *); int (*set_fecparam)(struct net_device *, struct ethtool_fecparam *); + int (*get_preempt)(struct net_device *dev, + struct ethtool_fp *fp); + int (*set_preempt)(struct net_device *dev, struct ethtool_fp *fp, + struct netlink_ext_ack *extack); void (*get_ethtool_phy_stats)(struct net_device *, struct ethtool_stats *, u64 *); int (*get_phy_tunable)(struct net_device *, @@ -843,4 +863,7 @@ int ethtool_get_phc_vclocks(struct net_device *dev, int **vclock_index); * next string. */ extern __printf(2, 3) void ethtool_sprintf(u8 **data, const char *fmt, ...); + +u8 ethtool_frag_size_to_mult(u32 frag_size); + #endif /* _LINUX_ETHTOOL_H */ diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h index d2fb4f7be61b..651c7af76776 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -49,6 +49,8 @@ enum { ETHTOOL_MSG_PHC_VCLOCKS_GET, ETHTOOL_MSG_MODULE_GET, ETHTOOL_MSG_MODULE_SET, + ETHTOOL_MSG_PREEMPT_GET, + ETHTOOL_MSG_PREEMPT_SET, /* add new constants above here */ __ETHTOOL_MSG_USER_CNT, @@ -94,6 +96,8 @@ enum { ETHTOOL_MSG_PHC_VCLOCKS_GET_REPLY, ETHTOOL_MSG_MODULE_GET_REPLY, ETHTOOL_MSG_MODULE_NTF, + ETHTOOL_MSG_PREEMPT_GET_REPLY, + ETHTOOL_MSG_PREEMPT_NTF, /* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT, @@ -697,6 +701,20 @@ enum { ETHTOOL_A_FEC_STAT_MAX = (__ETHTOOL_A_FEC_STAT_CNT - 1) }; +/* FRAME PREEMPTION */ + +enum { + ETHTOOL_A_PREEMPT_UNSPEC, + ETHTOOL_A_PREEMPT_HEADER, /* nest - _A_HEADER_* */ + ETHTOOL_A_PREEMPT_ENABLED, /* u8 */ + ETHTOOL_A_PREEMPT_PREEMPTIBLE_MASK, /* bitset */ + ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE, /* u32 */ + + /* add new constants above here */ + __ETHTOOL_A_PREEMPT_CNT, + ETHTOOL_A_PREEMPT_MAX = (__ETHTOOL_A_PREEMPT_CNT - 1) +}; + /* MODULE EEPROM */ enum { diff --git a/net/ethtool/Makefile b/net/ethtool/Makefile index b76432e70e6b..c0ab048b46c9 100644 --- a/net/ethtool/Makefile +++ b/net/ethtool/Makefile @@ -7,4 +7,5 @@ obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o \ linkstate.o debug.o wol.o features.o privflags.o rings.o \ channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \ - tunnels.o fec.o eeprom.o stats.o phc_vclocks.o module.o + tunnels.o fec.o eeprom.o stats.o phc_vclocks.o module.o \ + preempt.o diff --git a/net/ethtool/common.c b/net/ethtool/common.c index 566adf85e658..2232b8ef18b4 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -597,3 +597,26 @@ ethtool_params_from_link_mode(struct ethtool_link_ksettings *link_ksettings, link_ksettings->base.duplex = link_info->duplex; } EXPORT_SYMBOL_GPL(ethtool_params_from_link_mode); + +/** + * ethtool_frag_size_to_mult() - Convert from a Frame Preemption + * Additional Fragment size in bytes to a multiplier. + * @frag_size: minimum non-final fragment size in bytes. + * + * The multiplier is defined as: + * "A 2-bit integer value used to indicate the minimum size of + * non-final fragments supported by the receiver on the given port + * associated with the local System. This value is expressed in units + * of 64 octets of additional fragment length." + * Equivalent to `30.14.1.7 aMACMergeAddFragSize` from the IEEE 802.3-2018 + * standard. + * + * Return: the multiplier is a number in the [0, 2] interval. + */ +u8 ethtool_frag_size_to_mult(u32 frag_size) +{ + u8 mult = (frag_size / 64) - 1; + + return clamp_t(u8, mult, 0, 3); +} +EXPORT_SYMBOL_GPL(ethtool_frag_size_to_mult); diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 5fe8f4ae2ceb..66b35c35fcdb 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -282,6 +282,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_EEE_GET] = ðnl_eee_request_ops, [ETHTOOL_MSG_FEC_GET] = ðnl_fec_request_ops, [ETHTOOL_MSG_TSINFO_GET] = ðnl_tsinfo_request_ops, + [ETHTOOL_MSG_PREEMPT_GET] = ðnl_preempt_request_ops, [ETHTOOL_MSG_MODULE_EEPROM_GET] = ðnl_module_eeprom_request_ops, [ETHTOOL_MSG_STATS_GET] = ðnl_stats_request_ops, [ETHTOOL_MSG_PHC_VCLOCKS_GET] = ðnl_phc_vclocks_request_ops, @@ -598,6 +599,7 @@ ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX + 1] = { [ETHTOOL_MSG_EEE_NTF] = ðnl_eee_request_ops, [ETHTOOL_MSG_FEC_NTF] = ðnl_fec_request_ops, [ETHTOOL_MSG_MODULE_NTF] = ðnl_module_request_ops, + [ETHTOOL_MSG_PREEMPT_NTF] = ðnl_preempt_request_ops, }; /* default notification handler */ @@ -691,6 +693,7 @@ static const ethnl_notify_handler_t ethnl_notify_handlers[] = { [ETHTOOL_MSG_EEE_NTF] = ethnl_default_notify, [ETHTOOL_MSG_FEC_NTF] = ethnl_default_notify, [ETHTOOL_MSG_MODULE_NTF] = ethnl_default_notify, + [ETHTOOL_MSG_PREEMPT_NTF] = ethnl_default_notify, }; void ethtool_notify(struct net_device *dev, unsigned int cmd, const void *data) @@ -1020,6 +1023,22 @@ static const struct genl_ops ethtool_genl_ops[] = { .policy = ethnl_module_set_policy, .maxattr = ARRAY_SIZE(ethnl_module_set_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_PREEMPT_GET, + .doit = ethnl_default_doit, + .start = ethnl_default_start, + .dumpit = ethnl_default_dumpit, + .done = ethnl_default_done, + .policy = ethnl_preempt_get_policy, + .maxattr = ARRAY_SIZE(ethnl_preempt_get_policy) - 1, + }, + { + .cmd = ETHTOOL_MSG_PREEMPT_SET, + .flags = GENL_UNS_ADMIN_PERM, + .doit = ethnl_set_preempt, + .policy = ethnl_preempt_set_policy, + .maxattr = ARRAY_SIZE(ethnl_preempt_set_policy) - 1, + }, }; static const struct genl_multicast_group ethtool_nl_mcgrps[] = { diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 7919ddb2371c..444799f3e91a 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -341,6 +341,7 @@ extern const struct ethnl_request_ops ethnl_pause_request_ops; extern const struct ethnl_request_ops ethnl_eee_request_ops; extern const struct ethnl_request_ops ethnl_tsinfo_request_ops; extern const struct ethnl_request_ops ethnl_fec_request_ops; +extern const struct ethnl_request_ops ethnl_preempt_request_ops; extern const struct ethnl_request_ops ethnl_module_eeprom_request_ops; extern const struct ethnl_request_ops ethnl_stats_request_ops; extern const struct ethnl_request_ops ethnl_phc_vclocks_request_ops; @@ -379,6 +380,8 @@ extern const struct nla_policy ethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INF extern const struct nla_policy ethnl_fec_get_policy[ETHTOOL_A_FEC_HEADER + 1]; extern const struct nla_policy ethnl_fec_set_policy[ETHTOOL_A_FEC_AUTO + 1]; extern const struct nla_policy ethnl_module_eeprom_get_policy[ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS + 1]; +extern const struct nla_policy ethnl_preempt_get_policy[ETHTOOL_A_PREEMPT_HEADER + 1]; +extern const struct nla_policy ethnl_preempt_set_policy[ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE + 1]; extern const struct nla_policy ethnl_stats_get_policy[ETHTOOL_A_STATS_GROUPS + 1]; extern const struct nla_policy ethnl_phc_vclocks_get_policy[ETHTOOL_A_PHC_VCLOCKS_HEADER + 1]; extern const struct nla_policy ethnl_module_get_policy[ETHTOOL_A_MODULE_HEADER + 1]; @@ -402,6 +405,7 @@ int ethnl_tunnel_info_start(struct netlink_callback *cb); int ethnl_tunnel_info_dumpit(struct sk_buff *skb, struct netlink_callback *cb); int ethnl_set_fec(struct sk_buff *skb, struct genl_info *info); int ethnl_set_module(struct sk_buff *skb, struct genl_info *info); +int ethnl_set_preempt(struct sk_buff *skb, struct genl_info *info); extern const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN]; extern const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN]; diff --git a/net/ethtool/preempt.c b/net/ethtool/preempt.c new file mode 100644 index 000000000000..0000ba8cb90c --- /dev/null +++ b/net/ethtool/preempt.c @@ -0,0 +1,177 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include "common.h" +#include "netlink.h" +#include "bitset.h" + +struct preempt_req_info { + struct ethnl_req_info base; +}; + +struct preempt_reply_data { + struct ethnl_reply_data base; + struct ethtool_fp fp; +}; + +#define PREEMPT_QUEUES_COUNT \ + (sizeof_field(struct ethtool_fp, preemptible_mask) * BITS_PER_BYTE) + +#define PREEMPT_REPDATA(__reply_base) \ + container_of(__reply_base, struct preempt_reply_data, base) + +const struct nla_policy +ethnl_preempt_get_policy[] = { + [ETHTOOL_A_PREEMPT_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy), +}; + +static int preempt_prepare_data(const struct ethnl_req_info *req_base, + struct ethnl_reply_data *reply_base, + struct genl_info *info) +{ + struct preempt_reply_data *data = PREEMPT_REPDATA(reply_base); + struct net_device *dev = reply_base->dev; + int ret; + + if (!dev->ethtool_ops->get_preempt) + return -EOPNOTSUPP; + + ret = ethnl_ops_begin(dev); + if (ret < 0) + return ret; + + ret = dev->ethtool_ops->get_preempt(dev, &data->fp); + ethnl_ops_complete(dev); + + return ret; +} + +static int preempt_reply_size(const struct ethnl_req_info *req_base, + const struct ethnl_reply_data *reply_base) +{ + bool compact = req_base->flags & ETHTOOL_FLAG_COMPACT_BITSETS; + const struct preempt_reply_data *data = PREEMPT_REPDATA(reply_base); + const struct ethtool_fp *preempt = &data->fp; + int len = 0; + int ret; + + ret = ethnl_bitset32_size(&preempt->preemptible_mask, NULL, + PREEMPT_QUEUES_COUNT, NULL, compact); + if (ret < 0) + return ret; + + len += ret; + + len += nla_total_size(sizeof(u8)); /* _PREEMPT_ENABLED */ + len += nla_total_size(sizeof(u32)); /* _PREEMPT_ADD_FRAG_SIZE */ + + return len; +} + +static int preempt_fill_reply(struct sk_buff *skb, + const struct ethnl_req_info *req_base, + const struct ethnl_reply_data *reply_base) +{ + bool compact = req_base->flags & ETHTOOL_FLAG_COMPACT_BITSETS; + const struct preempt_reply_data *data = PREEMPT_REPDATA(reply_base); + const struct ethtool_fp *preempt = &data->fp; + int ret; + + if (nla_put_u32(skb, ETHTOOL_A_PREEMPT_ENABLED, preempt->enabled)) + return -EMSGSIZE; + + if (nla_put_u32(skb, ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE, + preempt->add_frag_size)) + return -EMSGSIZE; + + ret = ethnl_put_bitset32(skb, ETHTOOL_A_PREEMPT_PREEMPTIBLE_MASK, + &preempt->preemptible_mask, NULL, PREEMPT_QUEUES_COUNT, + NULL, compact); + if (ret < 0) + return ret; + + return 0; +} + +const struct ethnl_request_ops ethnl_preempt_request_ops = { + .request_cmd = ETHTOOL_MSG_PREEMPT_GET, + .reply_cmd = ETHTOOL_MSG_PREEMPT_GET_REPLY, + .hdr_attr = ETHTOOL_A_PREEMPT_HEADER, + .req_info_size = sizeof(struct preempt_req_info), + .reply_data_size = sizeof(struct preempt_reply_data), + + .prepare_data = preempt_prepare_data, + .reply_size = preempt_reply_size, + .fill_reply = preempt_fill_reply, +}; + +const struct nla_policy +ethnl_preempt_set_policy[ETHTOOL_A_PREEMPT_MAX + 1] = { + [ETHTOOL_A_PREEMPT_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy), + [ETHTOOL_A_PREEMPT_ENABLED] = NLA_POLICY_RANGE(NLA_U8, 0, 1), + [ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE] = { .type = NLA_U32 }, + [ETHTOOL_A_PREEMPT_PREEMPTIBLE_MASK] = { .type = NLA_NESTED }, +}; + +int ethnl_set_preempt(struct sk_buff *skb, struct genl_info *info) +{ + struct ethnl_req_info req_info = {}; + struct nlattr **tb = info->attrs; + struct ethtool_fp preempt = {}; + struct net_device *dev; + bool mod = false; + int ret; + + ret = ethnl_parse_header_dev_get(&req_info, + tb[ETHTOOL_A_PREEMPT_HEADER], + genl_info_net(info), info->extack, + true); + if (ret < 0) + return ret; + dev = req_info.dev; + + ret = -EOPNOTSUPP; + if (!dev->ethtool_ops->get_preempt || + !dev->ethtool_ops->set_preempt) + goto out_dev; + + rtnl_lock(); + ret = ethnl_ops_begin(dev); + if (ret < 0) + goto out_rtnl; + + ret = dev->ethtool_ops->get_preempt(dev, &preempt); + if (ret < 0) { + GENL_SET_ERR_MSG(info, "failed to retrieve frame preemption settings"); + goto out_ops; + } + + ret = ethnl_update_bitset32(&preempt.preemptible_mask, PREEMPT_QUEUES_COUNT, + tb[ETHTOOL_A_PREEMPT_PREEMPTIBLE_MASK], + NULL, info->extack, &mod); + if (ret < 0) + goto out_ops; + + ethnl_update_bool32(&preempt.enabled, + tb[ETHTOOL_A_PREEMPT_ENABLED], &mod); + ethnl_update_u32(&preempt.add_frag_size, + tb[ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE], &mod); + ret = 0; + if (!mod) + goto out_ops; + + ret = dev->ethtool_ops->set_preempt(dev, &preempt, info->extack); + if (ret < 0) { + GENL_SET_ERR_MSG(info, "frame preemption settings update failed"); + goto out_ops; + } + + ethtool_notify(dev, ETHTOOL_MSG_PREEMPT_NTF, NULL); + +out_ops: + ethnl_ops_complete(dev); +out_rtnl: + rtnl_unlock(); +out_dev: + dev_put(dev); + return ret; +} From patchwork Fri May 20 01:15:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinicius Costa Gomes X-Patchwork-Id: 12856162 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F177C433F5 for ; Fri, 20 May 2022 01:16:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344283AbiETBQR (ORCPT ); Thu, 19 May 2022 21:16:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344301AbiETBP7 (ORCPT ); Thu, 19 May 2022 21:15:59 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4EF72ED74 for ; Thu, 19 May 2022 18:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653009357; x=1684545357; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ABPrbRrB7H4era6LahfVmzh6b3s4/Or9defPrr4gSZs=; b=U99ioZIDcqj/kru20OF2KNHcndGQgSY86VOKQjW28PNBofz9ms/ISbXV 4BAbnuO7zNQHumdD0mWk0eoLxLqsGhMT0AaNvLEoo+mtwpdQvA41Be9XK bFq6+k7AaV7BuJ8w2CkNv+wFkqxjGPf41+lWuRp3+DwkOL1ZhMDiwavCV JAoMwP2Yj1fhfTEyQFxYa8L6RPwU2sBq7kDunw083DkmRGX4SeQidBczj zRfj8DG2Q/WFYdIAGb6HcADn78HG6Zf6NXxpilFdkXpPodh0NZRfwdRLT 55mLWVLhZ05NK5qgznwaB1/uJIfgMUHrR6V2vlycL3qUOydnHTC4K3Qed w==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="333064152" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="333064152" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570534539" Received: from vcostago-mobl3.jf.intel.com ([10.24.14.84]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:53 -0700 From: Vinicius Costa Gomes To: netdev@vger.kernel.org Cc: Vinicius Costa Gomes , jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, vladimir.oltean@nxp.com, po.liu@nxp.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH net-next v5 02/11] ethtool: Add support for Frame Preemption verification Date: Thu, 19 May 2022 18:15:29 -0700 Message-Id: <20220520011538.1098888-3-vinicius.gomes@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220520011538.1098888-1-vinicius.gomes@intel.com> References: <20220520011538.1098888-1-vinicius.gomes@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Expose the ethtool parameters to the PREEMPT_SET/_GET commands necessary to support the verification procedure as defined by IEEE 802.3-2018. These include the 'verified' bit to indicate that the verification dialog has concluded successfully with the link partner and frame preemption is supported. There's also the 'disable_verify' config to disable initiating the verification dialog. Signed-off-by: Vinicius Costa Gomes --- Documentation/networking/ethtool-netlink.rst | 3 +++ include/linux/ethtool.h | 3 +++ include/uapi/linux/ethtool_netlink.h | 2 ++ net/ethtool/netlink.h | 2 +- net/ethtool/preempt.c | 11 +++++++++++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst index 15d7c025cc4e..1731e7ad9ee7 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -1646,6 +1646,8 @@ Kernel response contents: ``ETHTOOL_A_PREEMPT_ENABLED`` bool frame preemption enabled ``ETHTOOL_A_PREEMPT_PREEMPTIBLE_MASK`` bitset preemptible queue mask ``ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE`` u32 Min additional frag size + ``ETHTOOL_A_PREEMPT_DISABLE_VERIFY`` u32 disable verification + ``ETHTOOL_A_PREEMPT_VERIFIED`` u32 verification procedure ====================================== ====== ========================== ``ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE`` configures the minimum non-final @@ -1667,6 +1669,7 @@ Request contents: ``ETHTOOL_A_PREEMPT_ENABLED`` bool frame preemption enabled ``ETHTOOL_A_PREEMPT_PREEMPTIBLE_MASK`` bitset preemptible queue mask ``ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE`` u32 Min additional frag size + ``ETHTOOL_A_PREEMPT_DISABLE_VERIFY`` bool disable verification ====================================== ====== ========================== ``ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE`` configures the minimum non-final diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 42570ec8ee44..5600a7610fa1 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -13,6 +13,7 @@ #ifndef _LINUX_ETHTOOL_H #define _LINUX_ETHTOOL_H +#include "asm-generic/int-ll64.h" #include #include #include @@ -464,6 +465,8 @@ struct ethtool_module_power_mode_params { struct ethtool_fp { u32 enabled; u32 preemptible_mask; + u32 disable_verify; + u32 verified; u32 add_frag_size; }; diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h index 651c7af76776..27c9bc5bfa51 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -709,6 +709,8 @@ enum { ETHTOOL_A_PREEMPT_ENABLED, /* u8 */ ETHTOOL_A_PREEMPT_PREEMPTIBLE_MASK, /* bitset */ ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE, /* u32 */ + ETHTOOL_A_PREEMPT_DISABLE_VERIFY, /* u8 */ + ETHTOOL_A_PREEMPT_VERIFIED, /* u8 */ /* add new constants above here */ __ETHTOOL_A_PREEMPT_CNT, diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 444799f3e91a..dfdef5b8fe5b 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -381,7 +381,7 @@ extern const struct nla_policy ethnl_fec_get_policy[ETHTOOL_A_FEC_HEADER + 1]; extern const struct nla_policy ethnl_fec_set_policy[ETHTOOL_A_FEC_AUTO + 1]; extern const struct nla_policy ethnl_module_eeprom_get_policy[ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS + 1]; extern const struct nla_policy ethnl_preempt_get_policy[ETHTOOL_A_PREEMPT_HEADER + 1]; -extern const struct nla_policy ethnl_preempt_set_policy[ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE + 1]; +extern const struct nla_policy ethnl_preempt_set_policy[ETHTOOL_A_PREEMPT_VERIFIED + 1]; extern const struct nla_policy ethnl_stats_get_policy[ETHTOOL_A_STATS_GROUPS + 1]; extern const struct nla_policy ethnl_phc_vclocks_get_policy[ETHTOOL_A_PHC_VCLOCKS_HEADER + 1]; extern const struct nla_policy ethnl_module_get_policy[ETHTOOL_A_MODULE_HEADER + 1]; diff --git a/net/ethtool/preempt.c b/net/ethtool/preempt.c index 0000ba8cb90c..7566ffb948b2 100644 --- a/net/ethtool/preempt.c +++ b/net/ethtool/preempt.c @@ -63,6 +63,8 @@ static int preempt_reply_size(const struct ethnl_req_info *req_base, len += nla_total_size(sizeof(u8)); /* _PREEMPT_ENABLED */ len += nla_total_size(sizeof(u32)); /* _PREEMPT_ADD_FRAG_SIZE */ + len += nla_total_size(sizeof(u8)); /* _PREEMPT_DISABLE_VERIFY */ + len += nla_total_size(sizeof(u8)); /* _PREEMPT_VERIFIED */ return len; } @@ -89,6 +91,12 @@ static int preempt_fill_reply(struct sk_buff *skb, if (ret < 0) return ret; + if (nla_put_u32(skb, ETHTOOL_A_PREEMPT_DISABLE_VERIFY, preempt->disable_verify)) + return -EMSGSIZE; + + if (nla_put_u32(skb, ETHTOOL_A_PREEMPT_VERIFIED, preempt->verified)) + return -EMSGSIZE; + return 0; } @@ -110,6 +118,7 @@ ethnl_preempt_set_policy[ETHTOOL_A_PREEMPT_MAX + 1] = { [ETHTOOL_A_PREEMPT_ENABLED] = NLA_POLICY_RANGE(NLA_U8, 0, 1), [ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE] = { .type = NLA_U32 }, [ETHTOOL_A_PREEMPT_PREEMPTIBLE_MASK] = { .type = NLA_NESTED }, + [ETHTOOL_A_PREEMPT_DISABLE_VERIFY] = NLA_POLICY_RANGE(NLA_U8, 0, 1), }; int ethnl_set_preempt(struct sk_buff *skb, struct genl_info *info) @@ -155,6 +164,8 @@ int ethnl_set_preempt(struct sk_buff *skb, struct genl_info *info) tb[ETHTOOL_A_PREEMPT_ENABLED], &mod); ethnl_update_u32(&preempt.add_frag_size, tb[ETHTOOL_A_PREEMPT_ADD_FRAG_SIZE], &mod); + ethnl_update_bool32(&preempt.disable_verify, + tb[ETHTOOL_A_PREEMPT_DISABLE_VERIFY], &mod); ret = 0; if (!mod) goto out_ops; From patchwork Fri May 20 01:15:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinicius Costa Gomes X-Patchwork-Id: 12856163 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C26EAC433F5 for ; Fri, 20 May 2022 01:16:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344314AbiETBQT (ORCPT ); Thu, 19 May 2022 21:16:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344331AbiETBQA (ORCPT ); Thu, 19 May 2022 21:16:00 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15F33369EF for ; Thu, 19 May 2022 18:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653009359; x=1684545359; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2oGbbUjYj0E3aAlL81he4Ni36pw6OBr/I251pMEuLHY=; b=b46yZrq3U6OrbKxN+Am29jEUkzyKlUJnRVbW90oPo7f2xl0k9WUAy8S9 FWB5syvd4ZMSO9qJOti48kjwnqhs1AOOeDjy0Qkm75GWapqvZGm4JVtso TZ40iPkDYPcCS9FTC5lc+wvYctCg0PccyqznfQL46kOYyhFQvsnLeW7Dt 6dqdXB2qbNgA96DLr5Ziior69gjQ435vL3o1cPumNF0DZVkY82dXyt+Dv Nudto9AZyMZOqNqnXTwOL2Yxtn16isYMXjIRCd/aEpkPuPG2DU95CG3c5 5euFYHrgnDxsYOGbam4yv8uMi+kk7EcprSBsGjDJbYW/oCaEq5bpN+wiz g==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="333064154" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="333064154" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570534542" Received: from vcostago-mobl3.jf.intel.com ([10.24.14.84]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:53 -0700 From: Vinicius Costa Gomes To: netdev@vger.kernel.org Cc: Vinicius Costa Gomes , jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, vladimir.oltean@nxp.com, po.liu@nxp.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH net-next v5 03/11] igc: Add support for receiving frames with all zeroes address Date: Thu, 19 May 2022 18:15:30 -0700 Message-Id: <20220520011538.1098888-4-vinicius.gomes@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220520011538.1098888-1-vinicius.gomes@intel.com> References: <20220520011538.1098888-1-vinicius.gomes@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The frame preemption verification (as defined by IEEE 802.3-2018 Section 99.4.3) handshake is done by the driver, the default configuration of the driver is to only receive frames with the driver address. So, in preparation for that add a second address to the list of acceptable addresses. Because the frame preemption "disable verify" toggle only affects the transmission of verification frames, this needs to always be enabled. As that address is invalid, the impact in practical scenarios should be minimal. But still a bummer that we have to do this. Signed-off-by: Vinicius Costa Gomes --- drivers/net/ethernet/intel/igc/igc.h | 2 ++ drivers/net/ethernet/intel/igc/igc_main.c | 7 +++++++ drivers/net/ethernet/intel/igc/igc_tsn.c | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/drivers/net/ethernet/intel/igc/igc.h b/drivers/net/ethernet/intel/igc/igc.h index 1e7e7071f64d..31e7b4c72894 100644 --- a/drivers/net/ethernet/intel/igc/igc.h +++ b/drivers/net/ethernet/intel/igc/igc.h @@ -622,6 +622,8 @@ struct igc_nfc_rule *igc_get_nfc_rule(struct igc_adapter *adapter, int igc_add_nfc_rule(struct igc_adapter *adapter, struct igc_nfc_rule *rule); void igc_del_nfc_rule(struct igc_adapter *adapter, struct igc_nfc_rule *rule); +int igc_enable_empty_addr_recv(struct igc_adapter *adapter); + void igc_ptp_init(struct igc_adapter *adapter); void igc_ptp_reset(struct igc_adapter *adapter); void igc_ptp_suspend(struct igc_adapter *adapter); diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c index ae17af44fe02..bcbf35b32ef3 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c @@ -3586,6 +3586,13 @@ static int igc_uc_unsync(struct net_device *netdev, const unsigned char *addr) return 0; } +int igc_enable_empty_addr_recv(struct igc_adapter *adapter) +{ + u8 empty[ETH_ALEN] = { }; + + return igc_add_mac_filter(adapter, IGC_MAC_FILTER_TYPE_DST, empty, -1); +} + /** * igc_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set * @netdev: network interface device structure diff --git a/drivers/net/ethernet/intel/igc/igc_tsn.c b/drivers/net/ethernet/intel/igc/igc_tsn.c index 0fce22de2ab8..270a08196f49 100644 --- a/drivers/net/ethernet/intel/igc/igc_tsn.c +++ b/drivers/net/ethernet/intel/igc/igc_tsn.c @@ -235,6 +235,13 @@ int igc_tsn_reset(struct igc_adapter *adapter) unsigned int new_flags; int err = 0; + /* Frame preemption verification requires that packets with + * the all zeroes MAC address are allowed to be received. Add + * the all zeroes destination address to the list of + * acceptable addresses. + */ + igc_enable_empty_addr_recv(adapter); + new_flags = igc_tsn_new_flags(adapter); if (!(new_flags & IGC_FLAG_TSN_ANY_ENABLED)) From patchwork Fri May 20 01:15:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinicius Costa Gomes X-Patchwork-Id: 12856165 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 428ECC433FE for ; Fri, 20 May 2022 01:16:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344362AbiETBQX (ORCPT ); Thu, 19 May 2022 21:16:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344315AbiETBQA (ORCPT ); Thu, 19 May 2022 21:16:00 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41FE837002 for ; Thu, 19 May 2022 18:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653009359; x=1684545359; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5xX/sdy+eR/dQdua3+HvBUCEnqwifRscdxcfvrZZ8tk=; b=I4Q7yelhp/LYJihh6RJuenY8t3Z4mR9G3XvsCdfP/UsHeDJuQ0mELiLh 1Iy2kejX3eWZHhg+U4rtUSNc6W7/FmAWGKrfxl1+0dUXG+0zDDqdrsdPN Lx7DaLWGtpXR/V7fsmHjp6da1nad10cT50qiSDZcmpveA9VsZRNEWcIhJ qdjBP0rlIwZVIBxmNzkHqAyJcjDyWVPiXqgWGEFvvMFRPIlg32l1s+94E 4OXHArFK5xILsVHrwQE04qGFDXfx7QVAB0I93IoWbPpJ2IDzgLcfIRG5O bkl3rGPVPrMWAD++9XLgud5rtPrlTPLChK30nNvJhtrS7ARCAdGBwX3/n w==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="333064156" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="333064156" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570534545" Received: from vcostago-mobl3.jf.intel.com ([10.24.14.84]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 From: Vinicius Costa Gomes To: netdev@vger.kernel.org Cc: Vinicius Costa Gomes , jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, vladimir.oltean@nxp.com, po.liu@nxp.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH net-next v5 04/11] igc: Set the RX packet buffer size for TSN mode Date: Thu, 19 May 2022 18:15:31 -0700 Message-Id: <20220520011538.1098888-5-vinicius.gomes@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220520011538.1098888-1-vinicius.gomes@intel.com> References: <20220520011538.1098888-1-vinicius.gomes@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In preparation for supporting frame preemption, when entering TSN mode set the receive packet buffer to 16KB for the Express MAC, 16KB for the Preemptible MAC and 2KB for the BMC, according to the datasheet section 7.1.3.2. Signed-off-by: Vinicius Costa Gomes --- drivers/net/ethernet/intel/igc/igc_defines.h | 2 ++ drivers/net/ethernet/intel/igc/igc_tsn.c | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/igc/igc_defines.h b/drivers/net/ethernet/intel/igc/igc_defines.h index 5c66b97c0cfa..f609b2dbbc28 100644 --- a/drivers/net/ethernet/intel/igc/igc_defines.h +++ b/drivers/net/ethernet/intel/igc/igc_defines.h @@ -396,6 +396,8 @@ #define IGC_RXPBS_CFG_TS_EN 0x80000000 /* Timestamp in Rx buffer */ #define IGC_TXPBSIZE_TSN 0x04145145 /* 5k bytes buffer for each queue */ +#define IGC_RXPBSIZE_TSN 0x0000f08f /* 15KB for EXP + 15KB for BE + 2KB for BMC */ +#define IGC_RXPBSIZE_SIZE_MASK 0x0001FFFF #define IGC_DTXMXPKTSZ_TSN 0x19 /* 1600 bytes of max TX DMA packet size */ #define IGC_DTXMXPKTSZ_DEFAULT 0x98 /* 9728-byte Jumbo frames */ diff --git a/drivers/net/ethernet/intel/igc/igc_tsn.c b/drivers/net/ethernet/intel/igc/igc_tsn.c index 270a08196f49..40a730f8b3f3 100644 --- a/drivers/net/ethernet/intel/igc/igc_tsn.c +++ b/drivers/net/ethernet/intel/igc/igc_tsn.c @@ -54,12 +54,17 @@ static unsigned int igc_tsn_new_flags(struct igc_adapter *adapter) static int igc_tsn_disable_offload(struct igc_adapter *adapter) { struct igc_hw *hw = &adapter->hw; - u32 tqavctrl; + u32 tqavctrl, rxpbs; int i; wr32(IGC_TXPBS, I225_TXPBSIZE_DEFAULT); wr32(IGC_DTXMXPKTSZ, IGC_DTXMXPKTSZ_DEFAULT); + rxpbs = rd32(IGC_RXPBS) & ~IGC_RXPBSIZE_SIZE_MASK; + rxpbs |= I225_RXPBSIZE_DEFAULT; + + wr32(IGC_RXPBS, rxpbs); + tqavctrl = rd32(IGC_TQAVCTRL); tqavctrl &= ~(IGC_TQAVCTRL_TRANSMIT_MODE_TSN | IGC_TQAVCTRL_ENHANCED_QAV); @@ -83,7 +88,7 @@ static int igc_tsn_enable_offload(struct igc_adapter *adapter) { struct igc_hw *hw = &adapter->hw; u32 tqavctrl, baset_l, baset_h; - u32 sec, nsec, cycle; + u32 sec, nsec, cycle, rxpbs; ktime_t base_time, systim; int i; @@ -94,6 +99,10 @@ static int igc_tsn_enable_offload(struct igc_adapter *adapter) wr32(IGC_DTXMXPKTSZ, IGC_DTXMXPKTSZ_TSN); wr32(IGC_TXPBS, IGC_TXPBSIZE_TSN); + rxpbs = rd32(IGC_RXPBS) & ~IGC_RXPBSIZE_SIZE_MASK; + rxpbs |= IGC_RXPBSIZE_TSN; + wr32(IGC_RXPBS, rxpbs); + tqavctrl = rd32(IGC_TQAVCTRL); tqavctrl |= IGC_TQAVCTRL_TRANSMIT_MODE_TSN | IGC_TQAVCTRL_ENHANCED_QAV; wr32(IGC_TQAVCTRL, tqavctrl); From patchwork Fri May 20 01:15:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinicius Costa Gomes X-Patchwork-Id: 12856164 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 629A9C433EF for ; Fri, 20 May 2022 01:16:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344345AbiETBQV (ORCPT ); Thu, 19 May 2022 21:16:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344335AbiETBQB (ORCPT ); Thu, 19 May 2022 21:16:01 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D21138BC4 for ; Thu, 19 May 2022 18:16:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653009360; x=1684545360; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GvvOSRP3CzY8wou3e94OjmzfEqmZRYgWGPqWk9AlwqA=; b=LT8M4iu9Yptt7Xwc2A4mPMsq6XE0s/vSY0uXMdzXk/8N6S6Ti15rcbc5 maL5HSohFmmFxiT1EWb/TFggSrht/zRt4WZiUTh5g1iAovi1m+gQ6LHs7 tW44bShcqcoNcDRq9BLfNaQs7R5lG2onexdH7zkGJBbYOyApH3kYx8cY0 Pv4/9XPlD/2o+PYRMxcolm4ZhkcxD+oP/5elZxtS6hI9ybmOvetbvGnDS X6gj/OzUPSb4DxOqhb+LIi961RHLafzrQ/APLkPwigKEmXnYR8FtXGS0S GWZKt9z26W76jgo4w727xwACW7cJQzC9kmKRMIk1YSvbuTa6jwJKQe0OG A==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="333064158" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="333064158" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570534548" Received: from vcostago-mobl3.jf.intel.com ([10.24.14.84]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 From: Vinicius Costa Gomes To: netdev@vger.kernel.org Cc: Vinicius Costa Gomes , jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, vladimir.oltean@nxp.com, po.liu@nxp.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH net-next v5 05/11] igc: Optimze TX buffer sizes for TSN Date: Thu, 19 May 2022 18:15:32 -0700 Message-Id: <20220520011538.1098888-6-vinicius.gomes@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220520011538.1098888-1-vinicius.gomes@intel.com> References: <20220520011538.1098888-1-vinicius.gomes@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org There are 64KB buffer space shared for TX and RX (including the BMC). We were only reserving 22KB for TX, increase each TX buffer (per queue) by 2KB, the total is now 30KB for TX. Signed-off-by: Vinicius Costa Gomes --- drivers/net/ethernet/intel/igc/igc_defines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/igc/igc_defines.h b/drivers/net/ethernet/intel/igc/igc_defines.h index f609b2dbbc28..62fff53254dd 100644 --- a/drivers/net/ethernet/intel/igc/igc_defines.h +++ b/drivers/net/ethernet/intel/igc/igc_defines.h @@ -395,7 +395,7 @@ #define I225_TXPBSIZE_DEFAULT 0x04000014 /* TXPBSIZE default */ #define IGC_RXPBS_CFG_TS_EN 0x80000000 /* Timestamp in Rx buffer */ -#define IGC_TXPBSIZE_TSN 0x04145145 /* 5k bytes buffer for each queue */ +#define IGC_TXPBSIZE_TSN 0x041c71c7 /* 7KB buffer for each queue + 2KB for BMC */ #define IGC_RXPBSIZE_TSN 0x0000f08f /* 15KB for EXP + 15KB for BE + 2KB for BMC */ #define IGC_RXPBSIZE_SIZE_MASK 0x0001FFFF From patchwork Fri May 20 01:15:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinicius Costa Gomes X-Patchwork-Id: 12856172 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53F69C433FE for ; Fri, 20 May 2022 01:16:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344375AbiETBQi (ORCPT ); Thu, 19 May 2022 21:16:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344340AbiETBQB (ORCPT ); Thu, 19 May 2022 21:16:01 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0586C377D9 for ; Thu, 19 May 2022 18:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653009360; x=1684545360; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tPQE+Qlryk7avBL9Z3AbOFS6jfrdTs4+uu3FoJxBUqg=; b=HnVAVRiR/semWnyhB0tqSFPD5QOjuN1rNJe8iuvN8qZuljoHyjWnA+qx rP+OWNDIzFx8ff1byEoTAr7VZgK5O1vCc/mB7ULKFcd6/Avzef6qsp6z3 FAAqjYj8J59gxUw7qGUxS8RqBXI9+/clVQ7MecfDgDRxRNpIUhvO2R5rJ Eb+T/OHJbYc2K1k2h5DO5447el395RczVvP1zpw7NW5urWgbt+1/iOaM8 Lz1pZvKMJtdEq3GJbQHOmF2XLiMyxDOf0UxPeio26bEYOyzVsi/e4cDW0 Av/As7JbiqG2A8UmeD4yCeNFjB4h+0td8QB1Ia67J5vH+K6Al62LI7z8y g==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="333064160" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="333064160" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570534552" Received: from vcostago-mobl3.jf.intel.com ([10.24.14.84]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 From: Vinicius Costa Gomes To: netdev@vger.kernel.org Cc: Vinicius Costa Gomes , jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, vladimir.oltean@nxp.com, po.liu@nxp.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH net-next v5 06/11] igc: Add support for receiving errored frames Date: Thu, 19 May 2022 18:15:33 -0700 Message-Id: <20220520011538.1098888-7-vinicius.gomes@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220520011538.1098888-1-vinicius.gomes@intel.com> References: <20220520011538.1098888-1-vinicius.gomes@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org While developing features that require sending potencially ill formed frames, it is useful being able to receive them on the other side. The driver already had all the pieces in place to support that, all that was missing was put the flag in the list of supported features. Signed-off-by: Vinicius Costa Gomes --- drivers/net/ethernet/intel/igc/igc_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c index bcbf35b32ef3..5dd7140bac82 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c @@ -6318,6 +6318,7 @@ static int igc_probe(struct pci_dev *pdev, /* copy netdev features into list of user selectable features */ netdev->hw_features |= NETIF_F_NTUPLE; + netdev->hw_features |= NETIF_F_RXALL; netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX; netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX; netdev->hw_features |= netdev->features; From patchwork Fri May 20 01:15:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinicius Costa Gomes X-Patchwork-Id: 12856166 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A3BDC433F5 for ; Fri, 20 May 2022 01:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344367AbiETBQZ (ORCPT ); Thu, 19 May 2022 21:16:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344333AbiETBQB (ORCPT ); Thu, 19 May 2022 21:16:01 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D13037A3C for ; Thu, 19 May 2022 18:16:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653009360; x=1684545360; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ToFrcGDEUel6f39vr/QY0T+19wegr+R6/XL4zDIn5SM=; b=BRG884aN2Kunn4Q02UPSvfiblZ1Ogqg1IVS1EqmSbkw9hNddGUrudrQW jAwFyxbBbc1pByWjm62AONlvKSvb6oovG3Zbh659lfiRP7ggtWOMKthUS S9RNPDe9XXXMaiO//QuDlMPHiMAPiMpWUNV5Ssd6wKdDGtSNtNDRVFgaF YNzGf3jdi8M51wm8XAa/lUmldusl4gYN/JppuPSwH4ejb9ywIVLxy6fnO I5VZdkAIxrLcwDMMROzqN65FG8zLGd7d+2a8LCsqzk8/SkDUd5nPXfUuW x9jA5v0UGietuLEZs2AfCdbv6T9VVDulEvfifLa5qsHpU6WO6oFJRMkat A==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="333064162" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="333064162" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570534555" Received: from vcostago-mobl3.jf.intel.com ([10.24.14.84]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 From: Vinicius Costa Gomes To: netdev@vger.kernel.org Cc: Vinicius Costa Gomes , jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, vladimir.oltean@nxp.com, po.liu@nxp.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH net-next v5 07/11] igc: Add support for enabling frame preemption via ethtool Date: Thu, 19 May 2022 18:15:34 -0700 Message-Id: <20220520011538.1098888-8-vinicius.gomes@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220520011538.1098888-1-vinicius.gomes@intel.com> References: <20220520011538.1098888-1-vinicius.gomes@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add support for enabling frame preemption via ethtool. All that's left for ethtool is to save the settings in the adapter state, and the request for those settings to be applied. It's done this because the TSN features (frame preemption is part of them) interact with one another and it's better to keep track from a central place. Signed-off-by: Vinicius Costa Gomes --- drivers/net/ethernet/intel/igc/igc.h | 3 ++ drivers/net/ethernet/intel/igc/igc_ethtool.c | 51 ++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/drivers/net/ethernet/intel/igc/igc.h b/drivers/net/ethernet/intel/igc/igc.h index 31e7b4c72894..df2fc71825a6 100644 --- a/drivers/net/ethernet/intel/igc/igc.h +++ b/drivers/net/ethernet/intel/igc/igc.h @@ -94,6 +94,7 @@ struct igc_ring { u8 queue_index; /* logical index of the ring*/ u8 reg_idx; /* physical index of the ring */ bool launchtime_enable; /* true if LaunchTime is enabled */ + bool preemptible; /* true if queue is preemptible */ u32 start_time; u32 end_time; @@ -182,6 +183,8 @@ struct igc_adapter { ktime_t base_time; ktime_t cycle_time; + bool frame_preemption_active; + u32 add_frag_size; /* OS defined structs */ struct pci_dev *pdev; diff --git a/drivers/net/ethernet/intel/igc/igc_ethtool.c b/drivers/net/ethernet/intel/igc/igc_ethtool.c index 8cc077b712ad..401d2cdb3e81 100644 --- a/drivers/net/ethernet/intel/igc/igc_ethtool.c +++ b/drivers/net/ethernet/intel/igc/igc_ethtool.c @@ -8,6 +8,7 @@ #include "igc.h" #include "igc_diag.h" +#include "igc_tsn.h" /* forward declaration */ struct igc_stats { @@ -1670,6 +1671,54 @@ static int igc_ethtool_set_eee(struct net_device *netdev, return 0; } +static int igc_ethtool_get_preempt(struct net_device *netdev, + struct ethtool_fp *fpcmd) +{ + struct igc_adapter *adapter = netdev_priv(netdev); + u32 mask = 0; + int i; + + fpcmd->enabled = adapter->frame_preemption_active; + fpcmd->add_frag_size = adapter->add_frag_size; + + for (i = 0; i < adapter->num_tx_queues; i++) { + struct igc_ring *ring = adapter->tx_ring[i]; + + if (ring->preemptible) + mask |= BIT(i); + } + + fpcmd->preemptible_mask = mask; + + return 0; +} + +static int igc_ethtool_set_preempt(struct net_device *netdev, + struct ethtool_fp *fpcmd, + struct netlink_ext_ack *extack) +{ + struct igc_adapter *adapter = netdev_priv(netdev); + u32 mask; + int i; + + if (fpcmd->add_frag_size < 68 || fpcmd->add_frag_size > 260) { + NL_SET_ERR_MSG_MOD(extack, "Invalid value for add-frag-size"); + return -EINVAL; + } + + adapter->frame_preemption_active = fpcmd->enabled; + adapter->add_frag_size = fpcmd->add_frag_size; + mask = fpcmd->preemptible_mask; + + for (i = 0; i < adapter->num_tx_queues; i++) { + struct igc_ring *ring = adapter->tx_ring[i]; + + ring->preemptible = (mask & BIT(i)); + } + + return igc_tsn_offload_apply(adapter); +} + static int igc_ethtool_begin(struct net_device *netdev) { struct igc_adapter *adapter = netdev_priv(netdev); @@ -1963,6 +2012,8 @@ static const struct ethtool_ops igc_ethtool_ops = { .get_ts_info = igc_ethtool_get_ts_info, .get_channels = igc_ethtool_get_channels, .set_channels = igc_ethtool_set_channels, + .get_preempt = igc_ethtool_get_preempt, + .set_preempt = igc_ethtool_set_preempt, .get_priv_flags = igc_ethtool_get_priv_flags, .set_priv_flags = igc_ethtool_set_priv_flags, .get_eee = igc_ethtool_get_eee, From patchwork Fri May 20 01:15:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinicius Costa Gomes X-Patchwork-Id: 12856170 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B4C3C433EF for ; Fri, 20 May 2022 01:16:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344353AbiETBQe (ORCPT ); Thu, 19 May 2022 21:16:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344351AbiETBQD (ORCPT ); Thu, 19 May 2022 21:16:03 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81D222ED74 for ; Thu, 19 May 2022 18:16:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653009361; x=1684545361; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gqLCMG/R9sxTw+Lomv+Xi2zf1twDlvBLdXZysAz3LpU=; b=Dgo69QtqLC7VTmfp/R20d9/qv+XOd/C6u6VDpqSS/wce9wlli7UHTebV c9HSB8ftzdLYLxBKxLNszMVbZrCBNUVgkjgUKu2soylvGTaC3hP8qpWj0 aBDR+FYgFM1nFhquQoyzcnKKY6h/rQSYh6jvVKVnQYU9kL15+2IjzBe8v 1sAH9ljQxkLF04Vh28R5U+zY35iD8Rqj1mlrfXCOzSJxQCTEz2cx/qQGv v5Wln43odAFzj3ImMHIcZmmt0GI3tuAMaqpa1fqfgaEGyycguzgadGqzN 4GGo0154hCcB2AeCaknIIdS9HHtkkld7yoIWH6vMSLUvtB33TWCLv12xE g==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="333064164" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="333064164" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570534559" Received: from vcostago-mobl3.jf.intel.com ([10.24.14.84]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 From: Vinicius Costa Gomes To: netdev@vger.kernel.org Cc: Vinicius Costa Gomes , jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, vladimir.oltean@nxp.com, po.liu@nxp.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH net-next v5 08/11] igc: Add support for setting frame preemption configuration Date: Thu, 19 May 2022 18:15:35 -0700 Message-Id: <20220520011538.1098888-9-vinicius.gomes@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220520011538.1098888-1-vinicius.gomes@intel.com> References: <20220520011538.1098888-1-vinicius.gomes@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Set the hardware register that enables the frame preemption feature. Some code is moved around because the PREEMPT_ENA bit in the IGC_TQAVCTRL register is recommended to be set after the individual queue registers (IGC_TXQCTL[i]) are set. Signed-off-by: Vinicius Costa Gomes --- drivers/net/ethernet/intel/igc/igc.h | 8 ++++- drivers/net/ethernet/intel/igc/igc_defines.h | 5 +++ drivers/net/ethernet/intel/igc/igc_tsn.c | 37 +++++++++++++++----- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/intel/igc/igc.h b/drivers/net/ethernet/intel/igc/igc.h index df2fc71825a6..11da66bd9c2c 100644 --- a/drivers/net/ethernet/intel/igc/igc.h +++ b/drivers/net/ethernet/intel/igc/igc.h @@ -300,9 +300,10 @@ extern char igc_driver_name[]; #define IGC_FLAG_RX_LEGACY BIT(16) #define IGC_FLAG_TSN_QBV_ENABLED BIT(17) #define IGC_FLAG_TSN_QAV_ENABLED BIT(18) +#define IGC_FLAG_TSN_PREEMPT_ENABLED BIT(19) #define IGC_FLAG_TSN_ANY_ENABLED \ - (IGC_FLAG_TSN_QBV_ENABLED | IGC_FLAG_TSN_QAV_ENABLED) + (IGC_FLAG_TSN_QBV_ENABLED | IGC_FLAG_TSN_PREEMPT_ENABLED | IGC_FLAG_TSN_PREEMPT_ENABLED) #define IGC_FLAG_RSS_FIELD_IPV4_UDP BIT(6) #define IGC_FLAG_RSS_FIELD_IPV6_UDP BIT(7) @@ -351,6 +352,11 @@ extern char igc_driver_name[]; #define IGC_I225_RX_LATENCY_1000 300 #define IGC_I225_RX_LATENCY_2500 1485 +/* From the datasheet section 8.12.4 Tx Qav Control TQAVCTRL, + * MIN_FRAG initial value. + */ +#define IGC_I225_MIN_FRAG_SIZE_DEFAULT 68 + /* RX and TX descriptor control thresholds. * PTHRESH - MAC will consider prefetch if it has fewer than this number of * descriptors available in its onboard memory. diff --git a/drivers/net/ethernet/intel/igc/igc_defines.h b/drivers/net/ethernet/intel/igc/igc_defines.h index 62fff53254dd..68faca584e34 100644 --- a/drivers/net/ethernet/intel/igc/igc_defines.h +++ b/drivers/net/ethernet/intel/igc/igc_defines.h @@ -513,6 +513,9 @@ /* Transmit Scheduling */ #define IGC_TQAVCTRL_TRANSMIT_MODE_TSN 0x00000001 #define IGC_TQAVCTRL_ENHANCED_QAV 0x00000008 +#define IGC_TQAVCTRL_PREEMPT_ENA 0x00000002 +#define IGC_TQAVCTRL_MIN_FRAG_MASK 0x0000C000 +#define IGC_TQAVCTRL_MIN_FRAG_SHIFT 14 #define IGC_TXQCTL_QUEUE_MODE_LAUNCHT 0x00000001 #define IGC_TXQCTL_STRICT_CYCLE 0x00000002 @@ -526,6 +529,8 @@ #define IGC_MAX_SR_QUEUES 2 +#define IGC_TXQCTL_PREEMPTABLE 0x00000008 + /* Receive Checksum Control */ #define IGC_RXCSUM_CRCOFL 0x00000800 /* CRC32 offload enable */ #define IGC_RXCSUM_PCSD 0x00002000 /* packet checksum disabled */ diff --git a/drivers/net/ethernet/intel/igc/igc_tsn.c b/drivers/net/ethernet/intel/igc/igc_tsn.c index 40a730f8b3f3..6e285bc15a6b 100644 --- a/drivers/net/ethernet/intel/igc/igc_tsn.c +++ b/drivers/net/ethernet/intel/igc/igc_tsn.c @@ -45,6 +45,9 @@ static unsigned int igc_tsn_new_flags(struct igc_adapter *adapter) if (is_cbs_enabled(adapter)) new_flags |= IGC_FLAG_TSN_QAV_ENABLED; + if (adapter->frame_preemption_active) + new_flags |= IGC_FLAG_TSN_PREEMPT_ENABLED; + return new_flags; } @@ -57,6 +60,8 @@ static int igc_tsn_disable_offload(struct igc_adapter *adapter) u32 tqavctrl, rxpbs; int i; + adapter->add_frag_size = IGC_I225_MIN_FRAG_SIZE_DEFAULT; + wr32(IGC_TXPBS, I225_TXPBSIZE_DEFAULT); wr32(IGC_DTXMXPKTSZ, IGC_DTXMXPKTSZ_DEFAULT); @@ -67,7 +72,8 @@ static int igc_tsn_disable_offload(struct igc_adapter *adapter) tqavctrl = rd32(IGC_TQAVCTRL); tqavctrl &= ~(IGC_TQAVCTRL_TRANSMIT_MODE_TSN | - IGC_TQAVCTRL_ENHANCED_QAV); + IGC_TQAVCTRL_ENHANCED_QAV | IGC_TQAVCTRL_PREEMPT_ENA | + IGC_TQAVCTRL_MIN_FRAG_MASK); wr32(IGC_TQAVCTRL, tqavctrl); for (i = 0; i < adapter->num_tx_queues; i++) { @@ -79,7 +85,7 @@ static int igc_tsn_disable_offload(struct igc_adapter *adapter) wr32(IGC_QBVCYCLET_S, 0); wr32(IGC_QBVCYCLET, NSEC_PER_SEC); - adapter->flags &= ~IGC_FLAG_TSN_QBV_ENABLED; + adapter->flags &= ~IGC_FLAG_TSN_ANY_ENABLED; return 0; } @@ -90,11 +96,9 @@ static int igc_tsn_enable_offload(struct igc_adapter *adapter) u32 tqavctrl, baset_l, baset_h; u32 sec, nsec, cycle, rxpbs; ktime_t base_time, systim; + u32 frag_size_mult; int i; - cycle = adapter->cycle_time; - base_time = adapter->base_time; - wr32(IGC_TSAUXC, 0); wr32(IGC_DTXMXPKTSZ, IGC_DTXMXPKTSZ_TSN); wr32(IGC_TXPBS, IGC_TXPBSIZE_TSN); @@ -103,9 +107,8 @@ static int igc_tsn_enable_offload(struct igc_adapter *adapter) rxpbs |= IGC_RXPBSIZE_TSN; wr32(IGC_RXPBS, rxpbs); - tqavctrl = rd32(IGC_TQAVCTRL); - tqavctrl |= IGC_TQAVCTRL_TRANSMIT_MODE_TSN | IGC_TQAVCTRL_ENHANCED_QAV; - wr32(IGC_TQAVCTRL, tqavctrl); + cycle = adapter->cycle_time; + base_time = adapter->base_time; wr32(IGC_QBVCYCLET_S, cycle); wr32(IGC_QBVCYCLET, cycle); @@ -216,6 +219,10 @@ static int igc_tsn_enable_offload(struct igc_adapter *adapter) wr32(IGC_TQAVHC(i), 0); } skip_cbs: + + if (adapter->frame_preemption_active && ring->preemptible) + txqctl |= IGC_TXQCTL_PREEMPTABLE; + wr32(IGC_TXQCTL(i), txqctl); } @@ -236,6 +243,20 @@ static int igc_tsn_enable_offload(struct igc_adapter *adapter) wr32(IGC_BASET_H, baset_h); wr32(IGC_BASET_L, baset_l); + tqavctrl = rd32(IGC_TQAVCTRL) & + ~(IGC_TQAVCTRL_MIN_FRAG_MASK | IGC_TQAVCTRL_PREEMPT_ENA); + + tqavctrl |= IGC_TQAVCTRL_TRANSMIT_MODE_TSN | IGC_TQAVCTRL_ENHANCED_QAV; + + if (adapter->frame_preemption_active) + tqavctrl |= IGC_TQAVCTRL_PREEMPT_ENA; + + frag_size_mult = ethtool_frag_size_to_mult(adapter->add_frag_size); + + tqavctrl |= frag_size_mult << IGC_TQAVCTRL_MIN_FRAG_SHIFT; + + wr32(IGC_TQAVCTRL, tqavctrl); + return 0; } From patchwork Fri May 20 01:15:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinicius Costa Gomes X-Patchwork-Id: 12856171 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21B16C433EF for ; Fri, 20 May 2022 01:16:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344359AbiETBQh (ORCPT ); Thu, 19 May 2022 21:16:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344349AbiETBQD (ORCPT ); Thu, 19 May 2022 21:16:03 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB84538BE1 for ; Thu, 19 May 2022 18:16:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653009361; x=1684545361; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Tmqxue1ASQ0cKbhMMIIzHOOF63jPC6+gmcF6k9KJ8PE=; b=VLjJzvm6WasyQBpdFTDpw+B4cdGdWTX3R+y3AbgJZ/re2RfVE22EN4Sx W1qT0exnUWHbuhQJz5SImqqujKxriKIWMwwuOTyvYt96mQ1K/d7uTxY0m cp93KZH6cROhh86jxQJ0BGNSCwahFgaG+rEFwab8TM93M8i0turloq8Wj NrKpgBv8TH8gIDek3ndJP/cd4bb3LC08d1dVAAbzGbGGb/fSyyMLJf4h0 H3Ul27bqVFAyFhB9oQvo5wgNj4CbEHV61RpuPmIU0x5pWxdl3OXgspWBG ffBoClZPMT7/7syiKNoGC5T6caIreRmnWPnfdd2m4gD4Co3OWM0pawHBS g==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="333064166" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="333064166" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570534562" Received: from vcostago-mobl3.jf.intel.com ([10.24.14.84]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 From: Vinicius Costa Gomes To: netdev@vger.kernel.org Cc: Vinicius Costa Gomes , jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, vladimir.oltean@nxp.com, po.liu@nxp.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH net-next v5 09/11] igc: Add support for Frame Preemption verification Date: Thu, 19 May 2022 18:15:36 -0700 Message-Id: <20220520011538.1098888-10-vinicius.gomes@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220520011538.1098888-1-vinicius.gomes@intel.com> References: <20220520011538.1098888-1-vinicius.gomes@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add support for sending/receiving Frame Preemption verification frames. The i225 hardware doesn't implement the process of verification internally, this is left to the driver. Add a simple implementation of the state machine defined in IEEE 802.3-2018, Section 99.4.7. For now, the state machine is started manually by the user, when enabling verification. Example: $ ethtool --set-frame-preemption IFACE disable-verify off The "verified" condition is set to true when the SMD-V frame is sent, and the SMD-R frame is received. So, it only tracks the transmission side. This seems to be what's expected from IEEE 802.3-2018. Signed-off-by: Vinicius Costa Gomes --- drivers/net/ethernet/intel/igc/igc.h | 16 ++ drivers/net/ethernet/intel/igc/igc_defines.h | 13 + drivers/net/ethernet/intel/igc/igc_ethtool.c | 37 ++- drivers/net/ethernet/intel/igc/igc_main.c | 243 +++++++++++++++++++ 4 files changed, 307 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/igc/igc.h b/drivers/net/ethernet/intel/igc/igc.h index 11da66bd9c2c..be4a8362d6d7 100644 --- a/drivers/net/ethernet/intel/igc/igc.h +++ b/drivers/net/ethernet/intel/igc/igc.h @@ -131,6 +131,13 @@ struct igc_ring { struct xsk_buff_pool *xsk_pool; } ____cacheline_internodealigned_in_smp; +enum frame_preemption_state { + FRAME_PREEMPTION_STATE_FAILED, + FRAME_PREEMPTION_STATE_DONE, + FRAME_PREEMPTION_STATE_START, + FRAME_PREEMPTION_STATE_SENT, +}; + /* Board specific private data structure */ struct igc_adapter { struct net_device *netdev; @@ -184,6 +191,7 @@ struct igc_adapter { ktime_t base_time; ktime_t cycle_time; bool frame_preemption_active; + bool frame_preemption_requested; u32 add_frag_size; /* OS defined structs */ @@ -250,6 +258,14 @@ struct igc_adapter { struct timespec64 start; struct timespec64 period; } perout[IGC_N_PEROUT]; + + struct delayed_work fp_verification_work; + unsigned long fp_start; + bool fp_received_smd_v; + bool fp_received_smd_r; + unsigned int fp_verify_cnt; + enum frame_preemption_state fp_tx_state; + bool fp_disable_verify; }; void igc_up(struct igc_adapter *adapter); diff --git a/drivers/net/ethernet/intel/igc/igc_defines.h b/drivers/net/ethernet/intel/igc/igc_defines.h index 68faca584e34..63fc76a0b72a 100644 --- a/drivers/net/ethernet/intel/igc/igc_defines.h +++ b/drivers/net/ethernet/intel/igc/igc_defines.h @@ -307,6 +307,8 @@ #define IGC_TXD_DTYP_C 0x00000000 /* Context Descriptor */ #define IGC_TXD_POPTS_IXSM 0x01 /* Insert IP checksum */ #define IGC_TXD_POPTS_TXSM 0x02 /* Insert TCP/UDP checksum */ +#define IGC_TXD_POPTS_SMD_V 0x10 /* Transmitted packet is a SMD-Verify */ +#define IGC_TXD_POPTS_SMD_R 0x20 /* Transmitted packet is a SMD-Response */ #define IGC_TXD_CMD_EOP 0x01000000 /* End of Packet */ #define IGC_TXD_CMD_IC 0x04000000 /* Insert Checksum */ #define IGC_TXD_CMD_DEXT 0x20000000 /* Desc extension (0 = legacy) */ @@ -366,9 +368,20 @@ #define IGC_RXDEXT_STATERR_LB 0x00040000 +#define IGC_RXD_STAT_SMD_V 0x2000 /* Received packet is SMD-Verify packet */ +#define IGC_RXD_STAT_SMD_R 0x4000 /* Received packet is SMD-Response packet */ + /* Advanced Receive Descriptor bit definitions */ #define IGC_RXDADV_STAT_TSIP 0x08000 /* timestamp in packet */ +#define IGC_RXDADV_STAT_SMD_TYPE_MASK 0x06000 +#define IGC_RXDADV_STAT_SMD_TYPE_SHIFT 13 + +#define IGC_SMD_TYPE_SFD 0x0 +#define IGC_SMD_TYPE_SMD_V 0x1 +#define IGC_SMD_TYPE_SMD_R 0x2 +#define IGC_SMD_TYPE_COMPLETE 0x3 + #define IGC_RXDEXT_STATERR_L4E 0x20000000 #define IGC_RXDEXT_STATERR_IPE 0x40000000 #define IGC_RXDEXT_STATERR_RXE 0x80000000 diff --git a/drivers/net/ethernet/intel/igc/igc_ethtool.c b/drivers/net/ethernet/intel/igc/igc_ethtool.c index 401d2cdb3e81..9a80e2569dc3 100644 --- a/drivers/net/ethernet/intel/igc/igc_ethtool.c +++ b/drivers/net/ethernet/intel/igc/igc_ethtool.c @@ -1680,6 +1680,8 @@ static int igc_ethtool_get_preempt(struct net_device *netdev, fpcmd->enabled = adapter->frame_preemption_active; fpcmd->add_frag_size = adapter->add_frag_size; + fpcmd->verified = adapter->fp_tx_state == FRAME_PREEMPTION_STATE_DONE; + fpcmd->disable_verify = adapter->fp_disable_verify; for (i = 0; i < adapter->num_tx_queues; i++) { struct igc_ring *ring = adapter->tx_ring[i]; @@ -1698,6 +1700,7 @@ static int igc_ethtool_set_preempt(struct net_device *netdev, struct netlink_ext_ack *extack) { struct igc_adapter *adapter = netdev_priv(netdev); + bool verified = false, mask_changed = false; u32 mask; int i; @@ -1706,17 +1709,47 @@ static int igc_ethtool_set_preempt(struct net_device *netdev, return -EINVAL; } - adapter->frame_preemption_active = fpcmd->enabled; + adapter->frame_preemption_requested = fpcmd->enabled; adapter->add_frag_size = fpcmd->add_frag_size; mask = fpcmd->preemptible_mask; for (i = 0; i < adapter->num_tx_queues; i++) { struct igc_ring *ring = adapter->tx_ring[i]; + bool preemptible = mask & BIT(i); + + if (ring->preemptible != preemptible) + mask_changed = true; ring->preemptible = (mask & BIT(i)); } - return igc_tsn_offload_apply(adapter); + if (!fpcmd->disable_verify && adapter->fp_disable_verify) { + adapter->fp_tx_state = FRAME_PREEMPTION_STATE_START; + schedule_delayed_work(&adapter->fp_verification_work, + msecs_to_jiffies(10)); + } + + adapter->fp_disable_verify = fpcmd->disable_verify; + + verified = adapter->fp_tx_state == FRAME_PREEMPTION_STATE_DONE; + + /* If the verification was not done, we want to enable frame + * preemption and we have not finished it, wait for it to + * finish. + */ + if (!verified && !adapter->fp_disable_verify && adapter->frame_preemption_requested) + return 0; + + if (adapter->frame_preemption_active != adapter->frame_preemption_requested || + adapter->add_frag_size != fpcmd->add_frag_size || + mask_changed) { + adapter->frame_preemption_active = adapter->frame_preemption_requested; + adapter->add_frag_size = fpcmd->add_frag_size; + + return igc_tsn_offload_apply(adapter); + } + + return 0; } static int igc_ethtool_begin(struct net_device *netdev) diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c index 5dd7140bac82..69e96e9a3ec8 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c @@ -30,6 +30,11 @@ #define IGC_XDP_TX BIT(1) #define IGC_XDP_REDIRECT BIT(2) +#define IGC_FP_TIMEOUT msecs_to_jiffies(100) +#define IGC_MAX_VERIFY_CNT 3 + +#define IGC_FP_SMD_FRAME_SIZE 60 + static int debug = -1; MODULE_AUTHOR("Intel Corporation, "); @@ -2190,6 +2195,79 @@ static int igc_xdp_init_tx_descriptor(struct igc_ring *ring, return 0; } +static int igc_fp_init_smd_frame(struct igc_ring *ring, struct igc_tx_buffer *buffer, + struct sk_buff *skb) +{ + dma_addr_t dma; + unsigned int size; + + size = skb_headlen(skb); + + dma = dma_map_single(ring->dev, skb->data, size, DMA_TO_DEVICE); + if (dma_mapping_error(ring->dev, dma)) { + netdev_err_once(ring->netdev, "Failed to map DMA for TX\n"); + return -ENOMEM; + } + + buffer->skb = skb; + buffer->protocol = 0; + buffer->bytecount = skb->len; + buffer->gso_segs = 1; + buffer->time_stamp = jiffies; + dma_unmap_len_set(buffer, len, skb->len); + dma_unmap_addr_set(buffer, dma, dma); + + return 0; +} + +static int igc_fp_init_tx_descriptor(struct igc_ring *ring, + struct sk_buff *skb, int type) +{ + struct igc_tx_buffer *buffer; + union igc_adv_tx_desc *desc; + u32 cmd_type, olinfo_status; + int err; + + if (!igc_desc_unused(ring)) + return -EBUSY; + + buffer = &ring->tx_buffer_info[ring->next_to_use]; + err = igc_fp_init_smd_frame(ring, buffer, skb); + if (err) + return err; + + cmd_type = IGC_ADVTXD_DTYP_DATA | IGC_ADVTXD_DCMD_DEXT | + IGC_ADVTXD_DCMD_IFCS | IGC_TXD_DCMD | + buffer->bytecount; + olinfo_status = buffer->bytecount << IGC_ADVTXD_PAYLEN_SHIFT; + + switch (type) { + case IGC_SMD_TYPE_SMD_V: + olinfo_status |= (IGC_TXD_POPTS_SMD_V << 8); + break; + case IGC_SMD_TYPE_SMD_R: + olinfo_status |= (IGC_TXD_POPTS_SMD_R << 8); + break; + default: + return -EINVAL; + } + + desc = IGC_TX_DESC(ring, ring->next_to_use); + desc->read.cmd_type_len = cpu_to_le32(cmd_type); + desc->read.olinfo_status = cpu_to_le32(olinfo_status); + desc->read.buffer_addr = cpu_to_le64(dma_unmap_addr(buffer, dma)); + + netdev_tx_sent_queue(txring_txq(ring), skb->len); + + buffer->next_to_watch = desc; + + ring->next_to_use++; + if (ring->next_to_use == ring->count) + ring->next_to_use = 0; + + return 0; +} + static struct igc_ring *igc_xdp_get_tx_ring(struct igc_adapter *adapter, int cpu) { @@ -2317,6 +2395,43 @@ static void igc_update_rx_stats(struct igc_q_vector *q_vector, q_vector->rx.total_bytes += bytes; } +static int igc_rx_desc_smd_type(union igc_adv_rx_desc *rx_desc) +{ + u32 status = le32_to_cpu(rx_desc->wb.upper.status_error); + + return (status & IGC_RXDADV_STAT_SMD_TYPE_MASK) + >> IGC_RXDADV_STAT_SMD_TYPE_SHIFT; +} + +static bool igc_check_smd_frame(void *pktbuf, unsigned int size) +{ +#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) + const u32 *b; +#else + const u16 *b; +#endif + int i; + + if (size != 60) + return false; + + /* The SMD frames (V and R) have the preamble, the SMD tag, 60 + * octects of zeroes and the mCRC. At this point the hardware + * already discarded most of that, so we only need to check + * the "contents" of the frame. + */ + b = pktbuf; + for (i = 16 / sizeof(*b); i < size / sizeof(*b); i++) + /* FIXME: i226 seems to insert some garbage + * (timestamps?) in SMD frames, ignore the first 16 + * bytes (4 words). Investigate better. + */ + if (b[i] != 0) + return false; + + return true; +} + static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget) { unsigned int total_bytes = 0, total_packets = 0; @@ -2333,6 +2448,7 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget) ktime_t timestamp = 0; struct xdp_buff xdp; int pkt_offset = 0; + int smd_type; void *pktbuf; /* return some buffers to hardware, one at a time is too slow */ @@ -2364,6 +2480,22 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget) size -= IGC_TS_HDR_LEN; } + smd_type = igc_rx_desc_smd_type(rx_desc); + + if (unlikely(smd_type == IGC_SMD_TYPE_SMD_V || smd_type == IGC_SMD_TYPE_SMD_R)) { + if (igc_check_smd_frame(pktbuf, size)) { + adapter->fp_received_smd_v = smd_type == IGC_SMD_TYPE_SMD_V; + adapter->fp_received_smd_r = smd_type == IGC_SMD_TYPE_SMD_R; + schedule_delayed_work(&adapter->fp_verification_work, 0); + } + + /* Advance the ring next-to-clean */ + igc_is_non_eop(rx_ring, rx_desc); + + cleaned_count++; + continue; + } + if (!skb) { xdp_init_buff(&xdp, truesize, &rx_ring->xdp_rxq); xdp_prepare_buff(&xdp, pktbuf - igc_rx_offset(rx_ring), @@ -6003,6 +6135,116 @@ static int igc_tsn_enable_cbs(struct igc_adapter *adapter, return igc_tsn_offload_apply(adapter); } +/* I225 doesn't send the SMD frames automatically, we need to handle + * them ourselves. + */ +static int igc_xmit_smd_frame(struct igc_adapter *adapter, int type) +{ + int cpu = smp_processor_id(); + struct netdev_queue *nq; + struct igc_ring *ring; + struct sk_buff *skb; + void *data; + int err; + + if (!netif_running(adapter->netdev)) + return -ENOTCONN; + + /* FIXME: rename this function to something less specific, as + * it can be used outside XDP. + */ + ring = igc_xdp_get_tx_ring(adapter, cpu); + nq = txring_txq(ring); + + skb = alloc_skb(IGC_FP_SMD_FRAME_SIZE, GFP_KERNEL); + if (!skb) + return -ENOMEM; + + data = skb_put(skb, IGC_FP_SMD_FRAME_SIZE); + memset(data, 0, IGC_FP_SMD_FRAME_SIZE); + + __netif_tx_lock_bh(nq); + + err = igc_fp_init_tx_descriptor(ring, skb, type); + + igc_flush_tx_descriptors(ring); + + __netif_tx_unlock_bh(nq); + + return err; +} + +static void igc_fp_verification_work(struct work_struct *work) +{ + struct delayed_work *dwork = to_delayed_work(work); + struct igc_adapter *adapter; + int err; + + adapter = container_of(dwork, struct igc_adapter, fp_verification_work); + + if (adapter->fp_disable_verify) + goto done; + + switch (adapter->fp_tx_state) { + case FRAME_PREEMPTION_STATE_START: + adapter->fp_received_smd_r = false; + err = igc_xmit_smd_frame(adapter, IGC_SMD_TYPE_SMD_V); + if (err < 0) + netdev_err(adapter->netdev, "Error sending SMD-V frame\n"); + + adapter->fp_tx_state = FRAME_PREEMPTION_STATE_SENT; + adapter->fp_start = jiffies; + schedule_delayed_work(&adapter->fp_verification_work, IGC_FP_TIMEOUT); + break; + + case FRAME_PREEMPTION_STATE_SENT: + if (adapter->fp_received_smd_r) { + /* Verifcation has finished successfully, we + * can enable frame preemption in the hw now + */ + adapter->fp_tx_state = FRAME_PREEMPTION_STATE_DONE; + adapter->fp_received_smd_r = false; + + if (adapter->frame_preemption_requested) { + adapter->frame_preemption_active = true; + igc_tsn_offload_apply(adapter); + } + + break; + } + + if (time_is_before_jiffies(adapter->fp_start + IGC_FP_TIMEOUT)) { + adapter->fp_verify_cnt++; + netdev_warn(adapter->netdev, "Timeout waiting for SMD-R frame\n"); + + if (adapter->fp_verify_cnt > IGC_MAX_VERIFY_CNT) { + adapter->fp_verify_cnt = 0; + adapter->fp_tx_state = FRAME_PREEMPTION_STATE_FAILED; + netdev_err(adapter->netdev, + "Exceeded number of attempts for frame preemption verification\n"); + } else { + adapter->fp_tx_state = FRAME_PREEMPTION_STATE_START; + } + schedule_delayed_work(&adapter->fp_verification_work, IGC_FP_TIMEOUT); + } + + break; + + case FRAME_PREEMPTION_STATE_FAILED: + case FRAME_PREEMPTION_STATE_DONE: + break; + } + +done: + if (adapter->fp_received_smd_v) { + err = igc_xmit_smd_frame(adapter, IGC_SMD_TYPE_SMD_R); + if (err < 0) + netdev_err(adapter->netdev, "Error sending SMD-R frame\n"); + + adapter->fp_received_smd_v = false; + } +} + static int igc_setup_tc(struct net_device *dev, enum tc_setup_type type, void *type_data) { @@ -6369,6 +6611,7 @@ static int igc_probe(struct pci_dev *pdev, INIT_WORK(&adapter->reset_task, igc_reset_task); INIT_WORK(&adapter->watchdog_task, igc_watchdog_task); + INIT_DELAYED_WORK(&adapter->fp_verification_work, igc_fp_verification_work); /* Initialize link properties that are user-changeable */ adapter->fc_autoneg = true; From patchwork Fri May 20 01:15:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinicius Costa Gomes X-Patchwork-Id: 12856169 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F176CC433F5 for ; Fri, 20 May 2022 01:16:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344366AbiETBQa (ORCPT ); Thu, 19 May 2022 21:16:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344359AbiETBQF (ORCPT ); Thu, 19 May 2022 21:16:05 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0460D38BF2 for ; Thu, 19 May 2022 18:16:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653009362; x=1684545362; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Y5alR8X1iiRzv2aqzNRWNZvPhKBChN/toGkywq+hTEA=; b=gsU7rC+RapGiNY9QiqRC+jCvvcCV/aES2idUKC/RI0SXw0Y3iLZN89J9 /u9xtICqh/0taIUZwp/b4QXsvISqdm2gJktmUUn447HeHl3clmiW0XHGt xmMYNod1uTmepzok0kNQcaFw+U0PVaDPu4XWPI7UZfm/BOxpKJlwlFDh2 D7+osHEyGobnBdpyMoM8eA81elR0TWwNIwsktiF11j1d/AjgB2u2cVrYH k6uZWFU9iBSH8R67tqvZJetOefhh/SWBDtvVbSbm6X+DjXNv2NoKV/9sf SFBScSnnIZ1YiG7IZp9VBxcekTrG/OihbMsS/WBQY/RUAndtvYRnWvORd g==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="333064168" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="333064168" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570534566" Received: from vcostago-mobl3.jf.intel.com ([10.24.14.84]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 From: Vinicius Costa Gomes To: netdev@vger.kernel.org Cc: Vinicius Costa Gomes , jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, vladimir.oltean@nxp.com, po.liu@nxp.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH net-next v5 10/11] igc: Check incompatible configs for Frame Preemption Date: Thu, 19 May 2022 18:15:37 -0700 Message-Id: <20220520011538.1098888-11-vinicius.gomes@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220520011538.1098888-1-vinicius.gomes@intel.com> References: <20220520011538.1098888-1-vinicius.gomes@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Frame Preemption and LaunchTime cannot be enabled on the same queue. If that situation happens, emit an error to the user, and log the error. Signed-off-by: Vinicius Costa Gomes Reported-by: kernel test robot --- drivers/net/ethernet/intel/igc/igc_main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c index 69e96e9a3ec8..96ad00e33f4b 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c @@ -5916,6 +5916,11 @@ static int igc_save_launchtime_params(struct igc_adapter *adapter, int queue, if (queue < 0 || queue >= adapter->num_tx_queues) return -EINVAL; + if (ring->preemptible) { + netdev_err(adapter->netdev, "Cannot enable LaunchTime on a preemptible queue\n"); + return -EINVAL; + } + ring = adapter->tx_ring[queue]; ring->launchtime_enable = enable; From patchwork Fri May 20 01:15:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinicius Costa Gomes X-Patchwork-Id: 12856168 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D9A1C433F5 for ; Fri, 20 May 2022 01:16:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344370AbiETBQ2 (ORCPT ); Thu, 19 May 2022 21:16:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344363AbiETBQF (ORCPT ); Thu, 19 May 2022 21:16:05 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8612F2EA26 for ; Thu, 19 May 2022 18:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653009363; x=1684545363; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4CHRXJYeqyil7rTJdqBcblLodLd4q0xWMAdYGKzG05Y=; b=I6cYS79mzS7cJS+hJXWiqz5PawvodyzzqJYDbGuIj0j/bH+N7kMQ2vi5 s9AcGUNrR9Gt+JS5Scz0kAi8ZkFA2X7WOPsB2xhhh7A62qAAVxmidvr1f aGcwMN0jTgVcVVYIY52FdPSUTcyB+Dc62i5dWSM2Njwvw+J6PPqzW/kLF egMocBOHhJc+QMu63va8mt6uMmMyYoGCPkA836yoHGEdep8e7Ds8s50U0 VxxjlfHQ4afaRukB2x5Db6TNYfHBUTQ/srcTxw7degznppPHcgZ0VvyU5 XF3BxjpEXL+gLniaA4bcaPWFVtv8hC6uyR9VCVHQQtkacrmxMpPC66nCO A==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="333064170" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="333064170" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570534569" Received: from vcostago-mobl3.jf.intel.com ([10.24.14.84]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 18:15:54 -0700 From: Vinicius Costa Gomes To: netdev@vger.kernel.org Cc: Vinicius Costa Gomes , jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, vladimir.oltean@nxp.com, po.liu@nxp.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH net-next v5 11/11] igc: Add support for exposing frame preemption stats registers Date: Thu, 19 May 2022 18:15:38 -0700 Message-Id: <20220520011538.1098888-12-vinicius.gomes@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220520011538.1098888-1-vinicius.gomes@intel.com> References: <20220520011538.1098888-1-vinicius.gomes@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Expose the Frame Preemption counters, so the number of express/preemptible packets can be monitored by userspace. These registers are cleared when read, so the value shown is the number of events that happened since the last read. Signed-off-by: Vinicius Costa Gomes --- drivers/net/ethernet/intel/igc/igc_ethtool.c | 8 ++++++++ drivers/net/ethernet/intel/igc/igc_regs.h | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/drivers/net/ethernet/intel/igc/igc_ethtool.c b/drivers/net/ethernet/intel/igc/igc_ethtool.c index 9a80e2569dc3..0a84fbdd494b 100644 --- a/drivers/net/ethernet/intel/igc/igc_ethtool.c +++ b/drivers/net/ethernet/intel/igc/igc_ethtool.c @@ -344,6 +344,14 @@ static void igc_ethtool_get_regs(struct net_device *netdev, regs_buff[213] = adapter->stats.tlpic; regs_buff[214] = adapter->stats.rlpic; + regs_buff[215] = rd32(IGC_PRMPTDTCNT); + regs_buff[216] = rd32(IGC_PRMEVNTTCNT); + regs_buff[217] = rd32(IGC_PRMPTDRCNT); + regs_buff[218] = rd32(IGC_PRMEVNTRCNT); + regs_buff[219] = rd32(IGC_PRMPBLTCNT); + regs_buff[220] = rd32(IGC_PRMPBLRCNT); + regs_buff[221] = rd32(IGC_PRMEXPTCNT); + regs_buff[222] = rd32(IGC_PRMEXPRCNT); } static void igc_ethtool_get_wol(struct net_device *netdev, diff --git a/drivers/net/ethernet/intel/igc/igc_regs.h b/drivers/net/ethernet/intel/igc/igc_regs.h index e197a33d93a0..2b5ef1e80f5f 100644 --- a/drivers/net/ethernet/intel/igc/igc_regs.h +++ b/drivers/net/ethernet/intel/igc/igc_regs.h @@ -224,6 +224,16 @@ #define IGC_FTQF(_n) (0x059E0 + (4 * (_n))) /* 5-tuple Queue Fltr */ +/* Time sync registers - preemption statistics */ +#define IGC_PRMPTDTCNT 0x04280 /* Good TX Preempted Packets */ +#define IGC_PRMEVNTTCNT 0x04298 /* TX Preemption event counter */ +#define IGC_PRMPTDRCNT 0x04284 /* Good RX Preempted Packets */ +#define IGC_PRMEVNTRCNT 0x0429C /* RX Preemption event counter */ +#define IGC_PRMPBLTCNT 0x04288 /* Good TX Preemptable Packets */ +#define IGC_PRMPBLRCNT 0x0428C /* Good RX Preemptable Packets */ +#define IGC_PRMEXPTCNT 0x04290 /* Good TX Express Packets */ +#define IGC_PRMEXPRCNT 0x042A0 /* Preemption Exception Counter */ + /* Transmit Scheduling Registers */ #define IGC_TQAVCTRL 0x3570 #define IGC_TXQCTL(_n) (0x3344 + 0x4 * (_n))