From patchwork Fri Feb 23 11:44:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13568948 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9D3879DB5 for ; Fri, 23 Feb 2024 11:46:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708688812; cv=none; b=RYGvLy/IdpTtHLuN8PuYU8wkKMjmBL981Das6Yce/5nAMF8T8uaf8GsmJw09eseu+NkD9jPENjeWnOzBRotKLBCr7t8+eIVF6of7sI47fhog8R1g/nDFWDjgYnZvRek19frY3AGzdxSvI7cKUHJodJkw03lvbzyC2dgdRK8re5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708688812; c=relaxed/simple; bh=n1GgHYtHsxsrAzgKRx3jPsMiLP1I7jvaanq3ckoFtwQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=t7rPjsfS92oU0iavMlWmdNvO63lBzDVODcKaOEGYdYOV/BPU+2DTnUK6MqMyeBLLbCmqtxhpqKDIfPZ/9sj8EMIcuTI2CNfrr9TgmV3h/7qhczOoFC+PBynOnyjlD8szu/8b3VtGmjxvqzI74B4+VpJMqu88UF0UaLbJs4/Rkck= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com; spf=pass smtp.mailfrom=waldekranz.com; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b=aWN4KV54; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="aWN4KV54" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2d09cf00214so11127941fa.0 for ; Fri, 23 Feb 2024 03:46:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1708688809; x=1709293609; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=zkDAooeQBr5rThauoM1g1MywPOKO4Mf+GehhCfGa7To=; b=aWN4KV54dKK9VHoKadGzpOckv2CcQOP0AXDE0QFfY9BUUnbjEB9EKgY2xmyPrQEQqM bKWbBKk8lP6zq8udHmbwIgddbShCVyJOLOpV7D5PAahdReE4qioyCjvny/HQz0RQWWFG NZ7TskyYTuhyvPTu06ubla7LabeXFX8Ep7cbdUsH1vqIAKD1qgg/lSLOTw+KFncgvO9d MZ+of1MstLfc+XjLWqneGN5a3HVQ8474KniGVT/Ti4kqrvft6oS+Oh1RPUPnKKn73tHj lTUTZOSCpKVDVFsMDWUt0argyPV7gt2Kt8qq2MqUTD9V/V7R4bUMnnyd7HltkkQ0HVHM DWEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708688809; x=1709293609; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=zkDAooeQBr5rThauoM1g1MywPOKO4Mf+GehhCfGa7To=; b=otJgD4lpdWn+4ya9kWd+8eDsf4DRh7D3wNtYmrgXXeLw6peGF6f++zQ81D5JfJEZQO 7vWqn0ggEpwR4+d7Vd40an02FE1RcIYdn6pCLYMO9S5onIIpwRUi1ka6PJitphxEY+R1 69i4fQgZsh3p5l3sJNNim251vYWonZezc7B8F6OKjoO3LC5AfzRQ6X5wVV9zTvl5rfVO COX4remYorMAKPbI4KhjknMM5x/VucpXD5VIWDSBke4gEZtCh0bO/d0HYGTL6bGcXQ9u lBgltl8QyI38BUuRJMTj0ZU1nDllNKO99DgpzkKNvH1KGdlFVPFKJ6sBMRycrKISMJGo 6dCg== X-Forwarded-Encrypted: i=1; AJvYcCVsaA4C/yE6f9F3b67WBKuLxni5YbP3t2DgXD+hsaKvO+wMQxpvLO08gcWznThctn+ltcQoECjjuDtXl16SM+8wGxiMkAYN X-Gm-Message-State: AOJu0YxKk3MATiMqV3KSYC+hp5pNWwI1sA2+8Mo5O3TeP8ELOHxJ5D4f cfCJVmRWW0Pr4PR5p2Nce3BsEUCYM9GijGae0YdEWXMDFiDWrd44Y2WepQqlm7s= X-Google-Smtp-Source: AGHT+IGDDaf54W831L5Ts8Flm3Ec9j0oLrGHQ4QMtQP0ylEjumhcZqW25LR2wJeBe/FFYgdBRSZ+Mg== X-Received: by 2002:ac2:4d03:0:b0:512:b24c:dba with SMTP id r3-20020ac24d03000000b00512b24c0dbamr1074063lfi.60.1708688809124; Fri, 23 Feb 2024 03:46:49 -0800 (PST) Received: from wkz-x13.addiva.ad (a124.broadband3.quicknet.se. [46.17.184.124]) by smtp.gmail.com with ESMTPSA id 11-20020ac25f0b000000b00512d180fd3asm1011694lfq.144.2024.02.23.03.46.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 03:46:48 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: roopa@nvidia.com, razor@blackwall.org, bridge@lists.linux.dev, netdev@vger.kernel.org, jiri@resnulli.us, ivecera@redhat.com, rostedt@goodmis.org, mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v3 net-next 1/4] net: switchdev: Wrap enums in mapper macros Date: Fri, 23 Feb 2024 12:44:50 +0100 Message-Id: <20240223114453.335809-2-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223114453.335809-1-tobias@waldekranz.com> References: <20240223114453.335809-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org In order to avoid having to maintain separate mappings from enum values to strings, wrap enumerators in mapper macros, so that enum-to-string tables can be generated. This will make it easier to create helpers that convert switchdev objects to strings. Signed-off-by: Tobias Waldekranz --- include/net/switchdev.h | 113 ++++++++++++++++++++++++---------------- 1 file changed, 68 insertions(+), 45 deletions(-) diff --git a/include/net/switchdev.h b/include/net/switchdev.h index 8346b0d29542..86298a21c6c8 100644 --- a/include/net/switchdev.h +++ b/include/net/switchdev.h @@ -16,21 +16,28 @@ #define SWITCHDEV_F_SKIP_EOPNOTSUPP BIT(1) #define SWITCHDEV_F_DEFER BIT(2) +#define SWITCHDEV_ATTR_ID_MAPPER(_fn) \ + _fn(UNDEFINED), \ + _fn(PORT_STP_STATE), \ + _fn(PORT_MST_STATE), \ + _fn(PORT_BRIDGE_FLAGS), \ + _fn(PORT_PRE_BRIDGE_FLAGS), \ + _fn(PORT_MROUTER), \ + _fn(BRIDGE_AGEING_TIME), \ + _fn(BRIDGE_VLAN_FILTERING), \ + _fn(BRIDGE_VLAN_PROTOCOL), \ + _fn(BRIDGE_MC_DISABLED), \ + _fn(BRIDGE_MROUTER), \ + _fn(BRIDGE_MST), \ + _fn(MRP_PORT_ROLE), \ + _fn(VLAN_MSTI), \ + /* */ + +#define SWITCHDEV_ATTR_ID_ENUMERATOR(_id) \ + SWITCHDEV_ATTR_ID_ ## _id + enum switchdev_attr_id { - SWITCHDEV_ATTR_ID_UNDEFINED, - SWITCHDEV_ATTR_ID_PORT_STP_STATE, - SWITCHDEV_ATTR_ID_PORT_MST_STATE, - SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS, - SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS, - SWITCHDEV_ATTR_ID_PORT_MROUTER, - SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME, - SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING, - SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL, - SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED, - SWITCHDEV_ATTR_ID_BRIDGE_MROUTER, - SWITCHDEV_ATTR_ID_BRIDGE_MST, - SWITCHDEV_ATTR_ID_MRP_PORT_ROLE, - SWITCHDEV_ATTR_ID_VLAN_MSTI, + SWITCHDEV_ATTR_ID_MAPPER(SWITCHDEV_ATTR_ID_ENUMERATOR) }; struct switchdev_mst_state { @@ -69,18 +76,25 @@ struct switchdev_attr { } u; }; +#define SWITCHDEV_OBJ_ID_MAPPER(_fn) \ + _fn(UNDEFINED), \ + _fn(PORT_VLAN), \ + _fn(PORT_MDB), \ + _fn(HOST_MDB), \ + _fn(MRP), \ + _fn(RING_TEST_MRP), \ + _fn(RING_ROLE_MRP), \ + _fn(RING_STATE_MRP), \ + _fn(IN_TEST_MRP), \ + _fn(IN_ROLE_MRP), \ + _fn(IN_STATE_MRP), \ + /* */ + +#define SWITCHDEV_OBJ_ID_ENUMERATOR(_id) \ + SWITCHDEV_OBJ_ID_ ## _id + enum switchdev_obj_id { - SWITCHDEV_OBJ_ID_UNDEFINED, - SWITCHDEV_OBJ_ID_PORT_VLAN, - SWITCHDEV_OBJ_ID_PORT_MDB, - SWITCHDEV_OBJ_ID_HOST_MDB, - SWITCHDEV_OBJ_ID_MRP, - SWITCHDEV_OBJ_ID_RING_TEST_MRP, - SWITCHDEV_OBJ_ID_RING_ROLE_MRP, - SWITCHDEV_OBJ_ID_RING_STATE_MRP, - SWITCHDEV_OBJ_ID_IN_TEST_MRP, - SWITCHDEV_OBJ_ID_IN_ROLE_MRP, - SWITCHDEV_OBJ_ID_IN_STATE_MRP, + SWITCHDEV_OBJ_ID_MAPPER(SWITCHDEV_OBJ_ID_ENUMERATOR) }; struct switchdev_obj { @@ -209,27 +223,36 @@ struct switchdev_brport { bool tx_fwd_offload; }; +#define SWITCHDEV_TYPE_MAPPER(_fn) \ + _fn(UNKNOWN), \ + \ + _fn(FDB_ADD_TO_BRIDGE), \ + _fn(FDB_DEL_TO_BRIDGE), \ + _fn(FDB_ADD_TO_DEVICE), \ + _fn(FDB_DEL_TO_DEVICE), \ + _fn(FDB_OFFLOADED), \ + _fn(FDB_FLUSH_TO_BRIDGE), \ + \ + _fn(PORT_OBJ_ADD), \ + _fn(PORT_OBJ_DEL), \ + _fn(PORT_ATTR_SET), \ + \ + _fn(VXLAN_FDB_ADD_TO_BRIDGE), \ + _fn(VXLAN_FDB_DEL_TO_BRIDGE), \ + _fn(VXLAN_FDB_ADD_TO_DEVICE), \ + _fn(VXLAN_FDB_DEL_TO_DEVICE), \ + _fn(VXLAN_FDB_OFFLOADED), \ + \ + _fn(BRPORT_OFFLOADED), \ + _fn(BRPORT_UNOFFLOADED), \ + _fn(BRPORT_REPLAY), \ + /* */ + +#define SWITCHDEV_TYPE_ENUMERATOR(_id) \ + SWITCHDEV_ ## _id + enum switchdev_notifier_type { - SWITCHDEV_FDB_ADD_TO_BRIDGE = 1, - SWITCHDEV_FDB_DEL_TO_BRIDGE, - SWITCHDEV_FDB_ADD_TO_DEVICE, - SWITCHDEV_FDB_DEL_TO_DEVICE, - SWITCHDEV_FDB_OFFLOADED, - SWITCHDEV_FDB_FLUSH_TO_BRIDGE, - - SWITCHDEV_PORT_OBJ_ADD, /* Blocking. */ - SWITCHDEV_PORT_OBJ_DEL, /* Blocking. */ - SWITCHDEV_PORT_ATTR_SET, /* May be blocking . */ - - SWITCHDEV_VXLAN_FDB_ADD_TO_BRIDGE, - SWITCHDEV_VXLAN_FDB_DEL_TO_BRIDGE, - SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE, - SWITCHDEV_VXLAN_FDB_DEL_TO_DEVICE, - SWITCHDEV_VXLAN_FDB_OFFLOADED, - - SWITCHDEV_BRPORT_OFFLOADED, - SWITCHDEV_BRPORT_UNOFFLOADED, - SWITCHDEV_BRPORT_REPLAY, + SWITCHDEV_TYPE_MAPPER(SWITCHDEV_TYPE_ENUMERATOR) }; struct switchdev_notifier_info { From patchwork Fri Feb 23 11:44:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13568949 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43AA67AE47 for ; Fri, 23 Feb 2024 11:46:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708688814; cv=none; b=DgXu9nhTnhtOFDY3meZchYvSHkfZXfiAjAwMxN8P8yBzF/aOTqvFrq8wmWnMOiKA/ZjlFeaahMGiOOmEwIWldrKSinbTYEK/2/N94+/1+jIvxaO1SB0nx+JEEMc8QeH3sx/BaHoPpC7Ik6HVbHrj8r+KAzRhHaM4NP2J7/R85ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708688814; c=relaxed/simple; bh=8I/5DOW5gW4lbco+7gFw8uvyQqN/6Ux3tmUrXsaJIkg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kCZm4U1LX6rhW3OMaTw+P84WiBdXUX+AEVQ9KKJrOfqKzOAjWrpKra4RfS1yO8Nq5gzADylpY83E5oYI9C68u5ySRknMz6eo0Qs+G3C5fElXFucdDk7CuPIoAsc5xMCJ5o2TrphtaRzUxX5YxQzMNr/1hTe6Zpa4YDs1krYmTLk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com; spf=pass smtp.mailfrom=waldekranz.com; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b=k7LPgUaP; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="k7LPgUaP" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-512cba0f953so890076e87.2 for ; Fri, 23 Feb 2024 03:46:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1708688810; x=1709293610; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=HiVTpXcFGxZ36jj3cKnJQtbHcUpuJpU/8Cq1LhZQMSg=; b=k7LPgUaPjZr0hf5Tcyk9+Momy8BIMDnQovyohkRDbsjnCoCAlvwxj2YUiD3bmDcK16 k44Qs8zAVPv+DqlYftbr5A6QBgPFWHKZ+pZZ1GjVOI3ijGKycT9fZUl8k8LWTmRACTdM HoXvtm1DGhYxOR7gFYfrqR/S1MzuhqjiWXQ7YIbsWP/VTTRS5N6gI5Nj0ZwOY6I4sGq1 S92AOSZRqi6ZArg0WPmaHy1gB2QBhqLsUPoYzzIfVKDCD1ydGZ+efnF6rsXlfx9BSzTN vMNyzOZpwP1jQ/Di7w5WUSfQDFrwc9vGoDgvk2HCEIoGzBvNiXmYK2tfKUU+Zawxfame 0QBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708688810; x=1709293610; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=HiVTpXcFGxZ36jj3cKnJQtbHcUpuJpU/8Cq1LhZQMSg=; b=WvdPBxZBpfy8vFw/EN9v6KQS5M6q0GndSdS+24N4ZHqOG8O5KjwTkPQZdx1msj3M81 m9QmAV4CQM/KJN4XNyBxX5t2MpfBwHsZtZ8tOFwoDuZyBXZfqA84fN3w4fxJCvWT9g7c xSsgVvkdp1DdS/kD7//YatRi4GkA3fpVZ6n6DMcIW1X+R1WsYLR/2IeInvfoLVo7O1ZF QismKBaAiwMuQHB2mqeBbm/mUFB+3c230QxL0VnzT2m/GoZdsUpjmfkT4VqNIzppwcZQ kW7mzCWDIH74/RK5h1/7jvPqhG3VSFcRl3QkCYUCIcPxa4FuYZX6yaqFpgrkCHPVyGCI 1u9g== X-Forwarded-Encrypted: i=1; AJvYcCWJ8OrLWboG6QuCRAWAZBh0KXzmF8siz8uQ82y1qa6d62Qp3oTf7TVN/ojX6AVjKOD/t80rvwBgrAjCflJv7KKL8fNKvh/t X-Gm-Message-State: AOJu0YwsvGTdlo+zoU89IrWiYK4Ch738dNp3fY77mdCl/2++BgkZoEVG 1l2kivWyVdVqGGjuLo81wy2Y8jYiMdetwPDIXbNLrNlysgurfmqUQLn4WWSJpcg= X-Google-Smtp-Source: AGHT+IHnvrfG+0bMJ2aDuSPshp30LXi/eioIOLjyUv8r3s1ySbENhqicUXk6EzkNy603h2zbbzTOmA== X-Received: by 2002:ac2:5049:0:b0:512:9e9f:2f1d with SMTP id a9-20020ac25049000000b005129e9f2f1dmr1156913lfm.58.1708688810303; Fri, 23 Feb 2024 03:46:50 -0800 (PST) Received: from wkz-x13.addiva.ad (a124.broadband3.quicknet.se. [46.17.184.124]) by smtp.gmail.com with ESMTPSA id 11-20020ac25f0b000000b00512d180fd3asm1011694lfq.144.2024.02.23.03.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 03:46:49 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: roopa@nvidia.com, razor@blackwall.org, bridge@lists.linux.dev, netdev@vger.kernel.org, jiri@resnulli.us, ivecera@redhat.com, rostedt@goodmis.org, mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v3 net-next 2/4] net: switchdev: Add helpers to display switchdev objects as strings Date: Fri, 23 Feb 2024 12:44:51 +0100 Message-Id: <20240223114453.335809-3-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223114453.335809-1-tobias@waldekranz.com> References: <20240223114453.335809-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org Useful both in error messages and in tracepoints. Signed-off-by: Tobias Waldekranz --- include/net/switchdev.h | 14 ++ net/switchdev/Makefile | 2 +- net/switchdev/switchdev-str.c | 278 ++++++++++++++++++++++++++++++++++ 3 files changed, 293 insertions(+), 1 deletion(-) create mode 100644 net/switchdev/switchdev-str.c diff --git a/include/net/switchdev.h b/include/net/switchdev.h index 86298a21c6c8..9bf387664e71 100644 --- a/include/net/switchdev.h +++ b/include/net/switchdev.h @@ -394,6 +394,20 @@ int switchdev_handle_port_attr_set(struct net_device *dev, int (*set_cb)(struct net_device *dev, const void *ctx, const struct switchdev_attr *attr, struct netlink_ext_ack *extack)); + +/* switchdev-str.c */ +ssize_t switchdev_attr_str(const struct switchdev_attr *attr, + char *buf, size_t len); +ssize_t switchdev_obj_str(const struct switchdev_obj *obj, + char *buf, size_t len); +ssize_t switchdev_fdb_info_str(enum switchdev_notifier_type nt, + const struct switchdev_notifier_fdb_info *fdbi, + char *buf, size_t len); +ssize_t switchdev_brport_str(const struct switchdev_brport *brport, + char *buf, size_t len); +ssize_t switchdev_notifier_str(enum switchdev_notifier_type nt, + const struct switchdev_notifier_info *info, + char *buf, size_t len); #else static inline int diff --git a/net/switchdev/Makefile b/net/switchdev/Makefile index c5561d7f3a7c..a40e4421087b 100644 --- a/net/switchdev/Makefile +++ b/net/switchdev/Makefile @@ -3,4 +3,4 @@ # Makefile for the Switch device API # -obj-y += switchdev.o +obj-y += switchdev.o switchdev-str.o diff --git a/net/switchdev/switchdev-str.c b/net/switchdev/switchdev-str.c new file mode 100644 index 000000000000..a1fa7315cc28 --- /dev/null +++ b/net/switchdev/switchdev-str.c @@ -0,0 +1,278 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include +#include + +static ssize_t switchdev_str_write_id(char *buf, size_t len, unsigned long id, + const char *const *names, size_t n_names) +{ + if (id < n_names && names[id]) + return snprintf(buf, len, "%s", names[id]); + + return snprintf(buf, len, "UNKNOWN<%lu>", id); +} + +ssize_t switchdev_attr_str(const struct switchdev_attr *attr, + char *buf, size_t len) +{ +#define _ATTR_ID_STRINGER(_id) [SWITCHDEV_ATTR_ID_ ## _id] = #_id + static const char *const attr_id_strs[] = { + SWITCHDEV_ATTR_ID_MAPPER(_ATTR_ID_STRINGER) + }; +#undef _ATTR_ID_STRINGER + + static const char *const stp_state_strs[] = { + [BR_STATE_DISABLED] = "disabled", + [BR_STATE_LISTENING] = "listening", + [BR_STATE_LEARNING] = "learning", + [BR_STATE_FORWARDING] = "forwarding", + [BR_STATE_BLOCKING] = "blocking", + }; + + char *cur = buf; + ssize_t n; + + n = switchdev_str_write_id(cur, len, attr->id, attr_id_strs, + ARRAY_SIZE(attr_id_strs)); + if (n < 0) + return n; + + cur += n; + len -= n; + + n = snprintf(cur, len, "(flags %#x orig %s) ", attr->flags, + attr->orig_dev ? netdev_name(attr->orig_dev) : "(null)"); + if (n < 0) + return n; + + cur += n; + len -= n; + + switch (attr->id) { + case SWITCHDEV_ATTR_ID_PORT_STP_STATE: + n = switchdev_str_write_id(cur, len, attr->u.stp_state, + stp_state_strs, ARRAY_SIZE(stp_state_strs)); + break; + case SWITCHDEV_ATTR_ID_PORT_MST_STATE: + n = snprintf(cur, len, "msti %u", attr->u.mst_state.msti); + if (n < 0) + return n; + + cur += n; + len -= n; + + n = switchdev_str_write_id(cur, len, attr->u.mst_state.state, + stp_state_strs, ARRAY_SIZE(stp_state_strs)); + break; + case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS: + case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS: + n = snprintf(cur, len, "val %#lx mask %#lx", + attr->u.brport_flags.val, + attr->u.brport_flags.mask); + break; + case SWITCHDEV_ATTR_ID_PORT_MROUTER: + case SWITCHDEV_ATTR_ID_BRIDGE_MROUTER: + n = snprintf(cur, len, "%s", + attr->u.mrouter ? "enabled" : "disabled"); + break; + case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME: + n = snprintf(cur, len, "%ums", + jiffies_to_msecs(clock_t_to_jiffies(attr->u.ageing_time))); + break; + case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING: + n = snprintf(cur, len, "%s", + attr->u.vlan_filtering ? "enabled" : "disabled"); + break; + case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL: + n = snprintf(cur, len, "%#x", attr->u.vlan_protocol); + break; + case SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED: + n = snprintf(cur, len, "%s", + attr->u.mc_disabled ? "active" : "inactive"); + break; + case SWITCHDEV_ATTR_ID_BRIDGE_MST: + n = snprintf(cur, len, "%s", + attr->u.mst ? "enabled" : "disabled"); + break; + case SWITCHDEV_ATTR_ID_VLAN_MSTI: + n = snprintf(cur, len, "vid %u msti %u", + attr->u.vlan_msti.vid, attr->u.vlan_msti.msti); + break; + default: + /* Trim trailing space */ + return --cur - buf; + } + + if (n < 0) + return n; + + cur += n; + return cur - buf; +} +EXPORT_SYMBOL_GPL(switchdev_attr_str); + +ssize_t switchdev_obj_str(const struct switchdev_obj *obj, + char *buf, size_t len) +{ +#define _OBJ_ID_STRINGER(_id) [SWITCHDEV_OBJ_ID_ ## _id] = #_id + static const char *const obj_id_strs[] = { + SWITCHDEV_OBJ_ID_MAPPER(_OBJ_ID_STRINGER) + }; +#undef _OBJ_ID_STRINGER + + const struct switchdev_obj_port_vlan *vlan; + const struct switchdev_obj_port_mdb *mdb; + char *cur = buf; + ssize_t n; + + n = switchdev_str_write_id(cur, len, obj->id, obj_id_strs, + ARRAY_SIZE(obj_id_strs)); + if (n < 0) + return n; + + cur += n; + len -= n; + + n = snprintf(cur, len, "(flags %#x orig %s) ", obj->flags, + obj->orig_dev ? netdev_name(obj->orig_dev) : "(null)"); + if (n < 0) + return n; + + cur += n; + len -= n; + + switch (obj->id) { + case SWITCHDEV_OBJ_ID_PORT_VLAN: + vlan = SWITCHDEV_OBJ_PORT_VLAN(obj); + n = snprintf(cur, len, "vid %u flags %#x%s", vlan->vid, + vlan->flags, vlan->changed ? "(changed)" : ""); + break; + case SWITCHDEV_OBJ_ID_PORT_MDB: + case SWITCHDEV_OBJ_ID_HOST_MDB: + mdb = SWITCHDEV_OBJ_PORT_MDB(obj); + n = snprintf(cur, len, "vid %u addr %pM", mdb->vid, mdb->addr); + break; + default: + /* Trim trailing space */ + return --cur - buf; + } + + if (n < 0) + return n; + + cur += n; + return cur - buf; +} +EXPORT_SYMBOL_GPL(switchdev_obj_str); + +ssize_t switchdev_fdb_info_str(enum switchdev_notifier_type nt, + const struct switchdev_notifier_fdb_info *fdbi, + char *buf, size_t len) +{ + switch (nt) { + case SWITCHDEV_FDB_FLUSH_TO_BRIDGE: + return snprintf(buf, len, "vid %u", fdbi->vid); + case SWITCHDEV_FDB_ADD_TO_BRIDGE: + case SWITCHDEV_FDB_DEL_TO_BRIDGE: + case SWITCHDEV_FDB_ADD_TO_DEVICE: + case SWITCHDEV_FDB_DEL_TO_DEVICE: + case SWITCHDEV_FDB_OFFLOADED: + case SWITCHDEV_VXLAN_FDB_ADD_TO_BRIDGE: + case SWITCHDEV_VXLAN_FDB_DEL_TO_BRIDGE: + case SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE: + case SWITCHDEV_VXLAN_FDB_DEL_TO_DEVICE: + case SWITCHDEV_VXLAN_FDB_OFFLOADED: + return snprintf(buf, len, "vid %u addr %pM%s%s%s%s", + fdbi->vid, fdbi->addr, + fdbi->added_by_user ? " added_by_user" : "", + fdbi->is_local ? " is_local" : "", + fdbi->locked ? " locked" : "", + fdbi->offloaded ? " offloaded" : ""); + default: + break; + } + + return 0; +} +EXPORT_SYMBOL_GPL(switchdev_fdb_info_str); + +ssize_t switchdev_brport_str(const struct switchdev_brport *brport, + char *buf, size_t len) +{ + return snprintf(buf, len, "dev %s%s", + brport->dev ? netdev_name(brport->dev) : "(null)", + brport->tx_fwd_offload ? " tx_fwd_offload" : ""); +} +EXPORT_SYMBOL_GPL(switchdev_brport_str); + +ssize_t switchdev_notifier_str(enum switchdev_notifier_type nt, + const struct switchdev_notifier_info *info, + char *buf, size_t len) +{ +#define _TYPE_STRINGER(_id) [SWITCHDEV_ ## _id] = #_id + static const char *const type_strs[] = { + SWITCHDEV_TYPE_MAPPER(_TYPE_STRINGER) + }; +#undef _TYPE_STRINGER + + const struct switchdev_notifier_port_attr_info *attri; + const struct switchdev_notifier_brport_info *brporti; + const struct switchdev_notifier_port_obj_info *obji; + const struct switchdev_notifier_fdb_info *fdbi; + char *cur = buf; + ssize_t n; + + n = switchdev_str_write_id(cur, len, nt, type_strs, + ARRAY_SIZE(type_strs)); + if (n < 0) + return n; + + cur += n; + len -= n; + + if (len > 0) { + *cur++ = ' '; + len--; + } + + switch (nt) { + case SWITCHDEV_FDB_FLUSH_TO_BRIDGE: + case SWITCHDEV_FDB_ADD_TO_BRIDGE: + case SWITCHDEV_FDB_DEL_TO_BRIDGE: + case SWITCHDEV_FDB_ADD_TO_DEVICE: + case SWITCHDEV_FDB_DEL_TO_DEVICE: + case SWITCHDEV_FDB_OFFLOADED: + case SWITCHDEV_VXLAN_FDB_ADD_TO_BRIDGE: + case SWITCHDEV_VXLAN_FDB_DEL_TO_BRIDGE: + case SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE: + case SWITCHDEV_VXLAN_FDB_DEL_TO_DEVICE: + case SWITCHDEV_VXLAN_FDB_OFFLOADED: + fdbi = container_of(info, typeof(*fdbi), info); + n = switchdev_fdb_info_str(nt, fdbi, cur, len); + break; + case SWITCHDEV_PORT_OBJ_ADD: + case SWITCHDEV_PORT_OBJ_DEL: + obji = container_of(info, typeof(*obji), info); + n = switchdev_obj_str(obji->obj, cur, len); + break; + case SWITCHDEV_PORT_ATTR_SET: + attri = container_of(info, typeof(*attri), info); + n = switchdev_attr_str(attri->attr, cur, len); + break; + case SWITCHDEV_BRPORT_OFFLOADED: + case SWITCHDEV_BRPORT_UNOFFLOADED: + case SWITCHDEV_BRPORT_REPLAY: + brporti = container_of(info, typeof(*brporti), info); + n = switchdev_brport_str(&brporti->brport, cur, len); + break; + default: + /* Trim trailing space */ + return --cur - buf; + } + + if (n < 0) + return n; + + cur += n; + return cur - buf; +} +EXPORT_SYMBOL_GPL(switchdev_notifier_str); From patchwork Fri Feb 23 11:44:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13568950 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B9067B3D4 for ; Fri, 23 Feb 2024 11:46:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708688814; cv=none; b=DbnktcBpdvq4b7DIudLc2S0vUFeLe4FP6Y5+sggjZKPjMO+ZBduzEh9vAUz2HJbL+5e2ekUkFiDkbISip1fuOd3EjgT3uKEPd8VdpXmU4uj17msOlADmqXCZzI7AT3mwgNqOmkHmklXTidRMdS9BrNRfiWvSfbkj11dAG5upekQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708688814; c=relaxed/simple; bh=AL59q193AhGQ1MjN1i4e9LV1QO1+0Mpm+Q7EAlw3k8k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fTiT06ZMpWLZfr834luk0qMcbmhGg+EvcrYk4A7ftHUurr4OZSzDEH0n1ge2nkSm6xGr8JAKcule7sa/3Jeg/zsEZYi0AGBOgOAfS0CKY3wfY/+3UE/I4NLhNMwHCefxyqGryjCqmhqfkiw/mRYgzTdi4SC3f3dVkYNk3n3sLls= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com; spf=pass smtp.mailfrom=waldekranz.com; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b=OlH4nMjh; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="OlH4nMjh" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-512b700c8ebso964978e87.0 for ; Fri, 23 Feb 2024 03:46:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1708688811; x=1709293611; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=mBRSSCMEADMA+/NeZM3v/YJ5K3VaAW012IQALFAOI+E=; b=OlH4nMjh0EloGzrJWFBsJpUG2iSmTL9g/7ig3moN4NpE/n/o9hdn+OGilrtJrGPAFW onB4t89dAUbt/GRgf0gjMVFm2H2WUFuQTXcyLL5bLj/GiWk+39Zm0Pi4OVGA4uIWA46M Sj3A9HxxvsbDSvcKy/yx4SHddG19JOtwefA+vHuzX+bTH2/VNVGmlv8uCNgVMUp/p1Kw 7KJuqEOAkfQEgIIzrQDiKjBf6E+hyReXCjChB3oaDsCVzHEMVj4ERnnoLL9utq29NXqd jlTGSslHYJWyhhKUG7JnDBsTtTUum4mZncvvqqfl/VFWlsEkaZSyp8ZR3f8VBg42qKfM 5ucQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708688811; x=1709293611; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mBRSSCMEADMA+/NeZM3v/YJ5K3VaAW012IQALFAOI+E=; b=TEFa7KRPMd3Rya8RIJhbFKHu5/w267e0BXOWnCYjlEgga9S3M0ybnmE4WowZ88EplX +/Dg+xv2oxe3QS+2zROIceBNc6EO/jWkIPpXm4DJKoQie3zsLNTgJFKXpBos79DoA3Ih JDoLEJ/PoA7LWgLlw6ZUYbycGtHSy87eFcGrg9mpunvSPBPcHbz9EDUSdL/ya26vcKnQ YHjtu0ntsojxuDcdVny/xvgKj7DEl3Ci5ooAFkXXq40HkgQJh7tR6wXjbMNqOZX3Sxto uIB8nCoH5DOs+GG9WaQjPZwBsnpX5tA7kCb8JqttUpmX7S5p72md3J9b7zR650wVpwRO 9YSA== X-Forwarded-Encrypted: i=1; AJvYcCXhEzaZ4uMXJP/tLZ+LG1E9ZGurp2rvGmfjUGweGylSyqz3gza2dqK9o309jxsR+mm8ww7dxKw2MOX8b0vwPMFo0XOhIwsb X-Gm-Message-State: AOJu0YxA6XS0raSHFCIWUGsqgy9oZUXS67vDxc7+0wANGpFH+O1tbDtg prIyh3P+nqATbpPq8nlmW+E4hvtc/Y4G9J7/Zic+aJYJJwLTlcddmL18RqLqJlQ= X-Google-Smtp-Source: AGHT+IE1FodzdIAUfG29+EdpmzWKwJ/TMGMZMZ1OL3CbEJZ1hWlBLWck+b5rA0SpDIRUtCsXMcBquw== X-Received: by 2002:a05:6512:12cb:b0:512:be57:6dcf with SMTP id p11-20020a05651212cb00b00512be576dcfmr1554566lfg.8.1708688811358; Fri, 23 Feb 2024 03:46:51 -0800 (PST) Received: from wkz-x13.addiva.ad (a124.broadband3.quicknet.se. [46.17.184.124]) by smtp.gmail.com with ESMTPSA id 11-20020ac25f0b000000b00512d180fd3asm1011694lfq.144.2024.02.23.03.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 03:46:50 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: roopa@nvidia.com, razor@blackwall.org, bridge@lists.linux.dev, netdev@vger.kernel.org, jiri@resnulli.us, ivecera@redhat.com, rostedt@goodmis.org, mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v3 net-next 3/4] net: switchdev: Relay all replay messages through a central function Date: Fri, 23 Feb 2024 12:44:52 +0100 Message-Id: <20240223114453.335809-4-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223114453.335809-1-tobias@waldekranz.com> References: <20240223114453.335809-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org This will make it easier to add a tracepoint for all replay messages later on. Signed-off-by: Tobias Waldekranz --- include/net/switchdev.h | 3 +++ net/bridge/br_switchdev.c | 10 +++++----- net/switchdev/switchdev.c | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/include/net/switchdev.h b/include/net/switchdev.h index 9bf387664e71..df4db720183f 100644 --- a/include/net/switchdev.h +++ b/include/net/switchdev.h @@ -340,6 +340,9 @@ int switchdev_port_obj_add(struct net_device *dev, int switchdev_port_obj_del(struct net_device *dev, const struct switchdev_obj *obj); +int switchdev_call_replay(struct notifier_block *nb, unsigned long type, + struct switchdev_notifier_info *info); + int register_switchdev_notifier(struct notifier_block *nb); int unregister_switchdev_notifier(struct notifier_block *nb); int call_switchdev_notifiers(unsigned long val, struct net_device *dev, diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c index 7b41ee8740cb..cc9ed7f6bf1c 100644 --- a/net/bridge/br_switchdev.c +++ b/net/bridge/br_switchdev.c @@ -306,7 +306,7 @@ br_switchdev_fdb_replay_one(struct net_bridge *br, struct notifier_block *nb, br_switchdev_fdb_populate(br, &item, fdb, ctx); - err = nb->notifier_call(nb, action, &item); + err = switchdev_call_replay(nb, action, &item.info); return notifier_to_errno(err); } @@ -376,8 +376,8 @@ static int br_switchdev_vlan_attr_replay(struct net_device *br_dev, attr.u.vlan_msti.vid = v->vid; attr.u.vlan_msti.msti = v->msti; - err = nb->notifier_call(nb, SWITCHDEV_PORT_ATTR_SET, - &attr_info); + err = switchdev_call_replay(nb, SWITCHDEV_PORT_ATTR_SET, + &attr_info.info); err = notifier_to_errno(err); if (err) return err; @@ -404,7 +404,7 @@ br_switchdev_vlan_replay_one(struct notifier_block *nb, }; int err; - err = nb->notifier_call(nb, action, &obj_info); + err = switchdev_call_replay(nb, action, &obj_info.info); return notifier_to_errno(err); } @@ -590,7 +590,7 @@ br_switchdev_mdb_replay_one(struct notifier_block *nb, struct net_device *dev, }; int err; - err = nb->notifier_call(nb, action, &obj_info); + err = switchdev_call_replay(nb, action, &obj_info.info); return notifier_to_errno(err); } diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c index c9189a970eec..f73249269a87 100644 --- a/net/switchdev/switchdev.c +++ b/net/switchdev/switchdev.c @@ -380,6 +380,24 @@ bool switchdev_port_obj_act_is_deferred(struct net_device *dev, } EXPORT_SYMBOL_GPL(switchdev_port_obj_act_is_deferred); +/** + * switchdev_call_replay - Replay switchdev message to driver + * + * @nb: notifier block to send the message to + * @type: value passed unmodified to notifier function + * @info: notifier information data + * + * Called by a bridge, in a response to a replay request + * initiated by a port that is either attaching to, or detaching + * from, that bridge. + */ +int switchdev_call_replay(struct notifier_block *nb, unsigned long type, + struct switchdev_notifier_info *info) +{ + return nb->notifier_call(nb, type, info); +} +EXPORT_SYMBOL_GPL(switchdev_call_replay); + static ATOMIC_NOTIFIER_HEAD(switchdev_notif_chain); static BLOCKING_NOTIFIER_HEAD(switchdev_blocking_notif_chain); From patchwork Fri Feb 23 11:44:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13568951 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57FC27B3F9 for ; Fri, 23 Feb 2024 11:46:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708688816; cv=none; b=pC/9t9AKvuJoTlpy1/FTe3JkgKgI51uODAGtADdaE4eCA2cosSF4mhSWjIZEkjgi0Q6dmLJBkTTs4CaoDp0hYnHEowo/8l8hVKNF4E26PEnY6R3nYUS7dpQLldeoRmLJouGJK/mz3Z6qcPD766URZ7JN+TucRbCWyTIeEQCr0qI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708688816; c=relaxed/simple; bh=Aklu3AOTd5lHiK77HWRI2BGxuV00bQ+Z+t85v8TanpU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P/KTckv5n3ZjqudF2MDkLcQ3Usd6QTaEgNTOXmJkI40PTtsI7zTotEj7v36Se60Y2zgNxktaKUj1SZVrr1BtCFxfWus5Uq9HiEZwPXyT9tsV7vA7amCzhw6j9UOJo49MVQXCJWnYmlUmXDC+p10LfgpiNfxgz2GDPhcZCHK1Npc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com; spf=pass smtp.mailfrom=waldekranz.com; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b=TgLW/B3S; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="TgLW/B3S" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-512b700c8ebso965013e87.0 for ; Fri, 23 Feb 2024 03:46:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1708688812; x=1709293612; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=5fiokJc9zM6smEbrCoaTInj6Uw6RY6DPtGrC3zqaCf0=; b=TgLW/B3SAxAycEwIpc9F6XKnVl27mYYPCozNQQxUNMcKQ6nB4hOztM+uuU5QBZ6HNz I63M3/wU2ZtvwEXJ79w3QEVkEu1+vfBJqJ3XUgfPycjNAtp9STHFSBrEON17nF3y9Hmy ywdNySgZAzwchejgSCZrZZX5UlDX6IEb4nLxUjDP9T+DcufP+QCw92BHQaoOdTK0wuLv 4XzHOynIHoKnIHd8eyTPzxSHElTNOvqMDcJEIj6wt/NhFCH1fAso1rD2y+1k4MYMNo0F rBSz0faoMHNukbUEWqJbHVctatXc1rEZy1HDwSuolYYqd+3MS9puUyQvionrgHeIlHKI fHNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708688812; x=1709293612; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=5fiokJc9zM6smEbrCoaTInj6Uw6RY6DPtGrC3zqaCf0=; b=ihIWpnIVvgiOI4Vsmqvd5SYoYWwFXndMLvDjWywtIqY4S9Vl3lhoCr9rv5SkjhRiXA 4qpkGI4wZdogA5AMxeWONyiarVJEMrq+kQnfIFKSGK6lgWGIDfaynGNhWpLcigo0aC4A oGxs3Go7QLnrhnr01zYlCjfJXpdy2r9cPsai50zoKuSNGSV0cEMY4WJJbjf8tH+psNUk tHWKhxXBEaCcVstd0eOLFqNcXw5LW4Hs1/N5J7CnAkZeEmUiQoPs6xF5+8sbsjWIHJjC PFOkEVpNpJGxrjg7MFVydkGBxUWemt4c6bI5f2lZ7rgMS8EQUx/KfVVoQA3xSLBBOPZG oUrg== X-Forwarded-Encrypted: i=1; AJvYcCWX+zK51gpuxl6fGE6j3hxoWzS8oNeNUgSDIYplehxs11wVi9UYceDzVNyiskOidNiBjG/A51ZRwNUd6G7MPJ9GU5nndF+c X-Gm-Message-State: AOJu0YyojS53jZAFvFgnnXWPoXi5e72PRHeD0l0hQDkcaFQ79hYNqkwK UWhrXbFXZCGtObuiAA8gPOEVcEweJAXnD6i8mERuXxDfHnCDqJ6vUwvTiE83VzM= X-Google-Smtp-Source: AGHT+IGBYXLp3kgxZ52vrpr0KeBz25IpYvIgdCgnLA0WXvBUzRaSDJyjGBlXkb3ZmlOXmDfSlXQQtw== X-Received: by 2002:a05:6512:6d0:b0:512:ac4a:4e07 with SMTP id u16-20020a05651206d000b00512ac4a4e07mr1773844lff.30.1708688812362; Fri, 23 Feb 2024 03:46:52 -0800 (PST) Received: from wkz-x13.addiva.ad (a124.broadband3.quicknet.se. [46.17.184.124]) by smtp.gmail.com with ESMTPSA id 11-20020ac25f0b000000b00512d180fd3asm1011694lfq.144.2024.02.23.03.46.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 03:46:51 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: roopa@nvidia.com, razor@blackwall.org, bridge@lists.linux.dev, netdev@vger.kernel.org, jiri@resnulli.us, ivecera@redhat.com, rostedt@goodmis.org, mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v3 net-next 4/4] net: switchdev: Add tracepoints Date: Fri, 23 Feb 2024 12:44:53 +0100 Message-Id: <20240223114453.335809-5-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223114453.335809-1-tobias@waldekranz.com> References: <20240223114453.335809-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org Add a basic set of tracepoints: - switchdev_defer: Fires whenever an operation is enqueued to the switchdev workqueue for deferred delivery. - switchdev_call_{atomic,blocking}: Fires whenever a notification is sent to the corresponding switchdev notifier chain. - switchdev_call_replay: Fires whenever a notification is sent to a specific driver's notifier block, in response to a replay request. Signed-off-by: Tobias Waldekranz --- include/trace/events/switchdev.h | 74 ++++++++++++++++++++++++++++++++ net/switchdev/switchdev.c | 71 +++++++++++++++++++++++++----- 2 files changed, 135 insertions(+), 10 deletions(-) create mode 100644 include/trace/events/switchdev.h diff --git a/include/trace/events/switchdev.h b/include/trace/events/switchdev.h new file mode 100644 index 000000000000..dcaf6870d017 --- /dev/null +++ b/include/trace/events/switchdev.h @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM switchdev + +#if !defined(_TRACE_SWITCHDEV_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_SWITCHDEV_H + +#include +#include + +#define SWITCHDEV_TRACE_MSG_MAX 128 + +DECLARE_EVENT_CLASS(switchdev_call, + TP_PROTO(unsigned long val, + const struct switchdev_notifier_info *info, + int err), + + TP_ARGS(val, info, err), + + TP_STRUCT__entry( + __field(unsigned long, val) + __string(dev, info->dev ? netdev_name(info->dev) : "(null)") + __field(const struct switchdev_notifier_info *, info) + __field(int, err) + __array(char, msg, SWITCHDEV_TRACE_MSG_MAX) + ), + + TP_fast_assign( + __entry->val = val; + __assign_str(dev, info->dev ? netdev_name(info->dev) : "(null)"); + __entry->info = info; + __entry->err = err; + switchdev_notifier_str(val, info, __entry->msg, SWITCHDEV_TRACE_MSG_MAX); + ), + + TP_printk("dev %s %s -> %d", __get_str(dev), __entry->msg, __entry->err) +); + +DEFINE_EVENT(switchdev_call, switchdev_defer, + TP_PROTO(unsigned long val, + const struct switchdev_notifier_info *info, + int err), + + TP_ARGS(val, info, err) +); + +DEFINE_EVENT(switchdev_call, switchdev_call_atomic, + TP_PROTO(unsigned long val, + const struct switchdev_notifier_info *info, + int err), + + TP_ARGS(val, info, err) +); + +DEFINE_EVENT(switchdev_call, switchdev_call_blocking, + TP_PROTO(unsigned long val, + const struct switchdev_notifier_info *info, + int err), + + TP_ARGS(val, info, err) +); + +DEFINE_EVENT(switchdev_call, switchdev_call_replay, + TP_PROTO(unsigned long val, + const struct switchdev_notifier_info *info, + int err), + + TP_ARGS(val, info, err) +); + +#endif /* _TRACE_SWITCHDEV_H */ + +/* This part must be outside protection */ +#include diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c index f73249269a87..74d715166981 100644 --- a/net/switchdev/switchdev.c +++ b/net/switchdev/switchdev.c @@ -19,6 +19,9 @@ #include #include +#define CREATE_TRACE_POINTS +#include + static bool switchdev_obj_eq(const struct switchdev_obj *a, const struct switchdev_obj *b) { @@ -180,8 +183,20 @@ static void switchdev_port_attr_set_deferred(struct net_device *dev, static int switchdev_port_attr_set_defer(struct net_device *dev, const struct switchdev_attr *attr) { - return switchdev_deferred_enqueue(dev, attr, sizeof(*attr), - switchdev_port_attr_set_deferred); + int err; + + err = switchdev_deferred_enqueue(dev, attr, sizeof(*attr), + switchdev_port_attr_set_deferred); + + if (trace_switchdev_defer_enabled()) { + struct switchdev_notifier_port_attr_info attr_info = { + .info.dev = dev, + .attr = attr, + }; + + trace_switchdev_defer(SWITCHDEV_PORT_ATTR_SET, &attr_info.info, err); + } + return err; } /** @@ -263,8 +278,20 @@ static void switchdev_port_obj_add_deferred(struct net_device *dev, static int switchdev_port_obj_add_defer(struct net_device *dev, const struct switchdev_obj *obj) { - return switchdev_deferred_enqueue(dev, obj, switchdev_obj_size(obj), - switchdev_port_obj_add_deferred); + int err; + + err = switchdev_deferred_enqueue(dev, obj, switchdev_obj_size(obj), + switchdev_port_obj_add_deferred); + + if (trace_switchdev_defer_enabled()) { + struct switchdev_notifier_port_obj_info obj_info = { + .info.dev = dev, + .obj = obj, + }; + + trace_switchdev_defer(SWITCHDEV_PORT_OBJ_ADD, &obj_info.info, err); + } + return err; } /** @@ -313,8 +340,20 @@ static void switchdev_port_obj_del_deferred(struct net_device *dev, static int switchdev_port_obj_del_defer(struct net_device *dev, const struct switchdev_obj *obj) { - return switchdev_deferred_enqueue(dev, obj, switchdev_obj_size(obj), - switchdev_port_obj_del_deferred); + int err; + + err = switchdev_deferred_enqueue(dev, obj, switchdev_obj_size(obj), + switchdev_port_obj_del_deferred); + + if (trace_switchdev_defer_enabled()) { + struct switchdev_notifier_port_obj_info obj_info = { + .info.dev = dev, + .obj = obj, + }; + + trace_switchdev_defer(SWITCHDEV_PORT_OBJ_DEL, &obj_info.info, err); + } + return err; } /** @@ -394,7 +433,11 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_act_is_deferred); int switchdev_call_replay(struct notifier_block *nb, unsigned long type, struct switchdev_notifier_info *info) { - return nb->notifier_call(nb, type, info); + int ret; + + ret = nb->notifier_call(nb, type, info); + trace_switchdev_call_replay(type, info, notifier_to_errno(ret)); + return ret; } EXPORT_SYMBOL_GPL(switchdev_call_replay); @@ -437,9 +480,13 @@ int call_switchdev_notifiers(unsigned long val, struct net_device *dev, struct switchdev_notifier_info *info, struct netlink_ext_ack *extack) { + int ret; + info->dev = dev; info->extack = extack; - return atomic_notifier_call_chain(&switchdev_notif_chain, val, info); + ret = atomic_notifier_call_chain(&switchdev_notif_chain, val, info); + trace_switchdev_call_atomic(val, info, notifier_to_errno(ret)); + return ret; } EXPORT_SYMBOL_GPL(call_switchdev_notifiers); @@ -463,10 +510,14 @@ int call_switchdev_blocking_notifiers(unsigned long val, struct net_device *dev, struct switchdev_notifier_info *info, struct netlink_ext_ack *extack) { + int ret; + info->dev = dev; info->extack = extack; - return blocking_notifier_call_chain(&switchdev_blocking_notif_chain, - val, info); + ret = blocking_notifier_call_chain(&switchdev_blocking_notif_chain, + val, info); + trace_switchdev_call_blocking(val, info, notifier_to_errno(ret)); + return ret; } EXPORT_SYMBOL_GPL(call_switchdev_blocking_notifiers);