From patchwork Tue Apr 18 06:51:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 751675 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3w6bRh6qWPz9s3s for ; Tue, 18 Apr 2017 16:52:48 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932240AbdDRGwq (ORCPT ); Tue, 18 Apr 2017 02:52:46 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:37953 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932195AbdDRGwl (ORCPT ); Tue, 18 Apr 2017 02:52:41 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3I6mZbl143391 for ; Tue, 18 Apr 2017 02:52:41 -0400 Received: from e23smtp03.au.ibm.com (e23smtp03.au.ibm.com [202.81.31.145]) by mx0a-001b2d01.pphosted.com with ESMTP id 29w26aqms6-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 18 Apr 2017 02:52:40 -0400 Received: from localhost by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 18 Apr 2017 16:52:38 +1000 Received: from d23relay06.au.ibm.com (202.81.31.225) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 18 Apr 2017 16:52:36 +1000 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3I6qRll51773492 for ; Tue, 18 Apr 2017 16:52:35 +1000 Received: from d23av03.au.ibm.com (localhost [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v3I6pwQu002648 for ; Tue, 18 Apr 2017 16:51:59 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av03.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v3I6pwpR002412; Tue, 18 Apr 2017 16:51:58 +1000 Received: from bran.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) by ozlabs.au.ibm.com (Postfix) with ESMTP id CA46AA026B; Tue, 18 Apr 2017 16:51:38 +1000 (AEST) Received: from gwshan.ozlabs.ibm.com (shangw.ozlabs.ibm.com [10.61.2.199]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id BD0C2E3AFB; Tue, 18 Apr 2017 16:51:38 +1000 (AEST) Received: by gwshan.ozlabs.ibm.com (Postfix, from userid 1000) id B2341AC276E; Tue, 18 Apr 2017 16:51:38 +1000 (AEST) From: Gavin Shan To: netdev@vger.kernel.org Cc: joe@perches.com, kubakici@wp.pl, davem@davemloft.net, Gavin Shan Subject: [PATCH v3 net-next 4/8] net/ncsi: Add debugging infrastructurre Date: Tue, 18 Apr 2017 16:51:31 +1000 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492498295-14385-1-git-send-email-gwshan@linux.vnet.ibm.com> References: <1492498295-14385-1-git-send-email-gwshan@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17041806-0008-0000-0000-0000011FE1C4 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17041806-0009-0000-0000-0000094CF88A Message-Id: <1492498295-14385-5-git-send-email-gwshan@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-18_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1704180059 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This creates debugfs directories as NCSI debugging infrastructure. With the patch applied, We will see below debugfs directories. Every NCSI package and channel has one corresponding directory. Other than presenting the NCSI topology, No real function has been achieved through these debugfs directories so far. /sys/kernel/debug/ncsi/eth0 /sys/kernel/debug/ncsi/eth0/p0 /sys/kernel/debug/ncsi/eth0/p0/c0 /sys/kernel/debug/ncsi/eth0/p0/c1 Signed-off-by: Gavin Shan --- net/ncsi/Kconfig | 9 +++++ net/ncsi/Makefile | 1 + net/ncsi/internal.h | 45 +++++++++++++++++++++ net/ncsi/ncsi-debug.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++ net/ncsi/ncsi-manage.c | 16 ++++++++ 5 files changed, 174 insertions(+) create mode 100644 net/ncsi/ncsi-debug.c diff --git a/net/ncsi/Kconfig b/net/ncsi/Kconfig index 08a8a60..baa42501 100644 --- a/net/ncsi/Kconfig +++ b/net/ncsi/Kconfig @@ -10,3 +10,12 @@ config NET_NCSI support. Enable this only if your system connects to a network device via NCSI and the ethernet driver you're using supports the protocol explicitly. + +config NET_NCSI_DEBUG + bool "Enable NCSI debugging" + depends on NET_NCSI && DEBUG_FS + default n + ---help--- + This enables the interfaces (e.g. debugfs) for NCSI debugging purpose. + + If unsure, say Y. diff --git a/net/ncsi/Makefile b/net/ncsi/Makefile index dd12b56..2897fa0 100644 --- a/net/ncsi/Makefile +++ b/net/ncsi/Makefile @@ -2,3 +2,4 @@ # Makefile for NCSI API # obj-$(CONFIG_NET_NCSI) += ncsi-cmd.o ncsi-rsp.o ncsi-aen.o ncsi-manage.o +obj-$(CONFIG_NET_NCSI_DEBUG) += ncsi-debug.o diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h index 1308a56..e9ede4f 100644 --- a/net/ncsi/internal.h +++ b/net/ncsi/internal.h @@ -198,6 +198,9 @@ struct ncsi_channel { } monitor; struct list_head node; struct list_head link; +#ifdef CONFIG_NET_NCSI_DEBUG + struct dentry *dentry; /* Debugfs directory */ +#endif }; struct ncsi_package { @@ -208,6 +211,9 @@ struct ncsi_package { unsigned int channel_num; /* Number of channels */ struct list_head channels; /* List of chanels */ struct list_head node; /* Form list of packages */ +#ifdef CONFIG_NET_NCSI_DEBUG + struct dentry *dentry; /* Debugfs directory */ +#endif }; struct ncsi_request { @@ -276,6 +282,9 @@ struct ncsi_dev_priv { struct work_struct work; /* For channel management */ struct packet_type ptype; /* NCSI packet Rx handler */ struct list_head node; /* Form NCSI device list */ +#ifdef CONFIG_NET_NCSI_DEBUG + struct dentry *dentry; /* Procfs directory */ +#endif }; struct ncsi_cmd_arg { @@ -337,4 +346,40 @@ int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev); int ncsi_aen_handler(struct ncsi_dev_priv *ndp, struct sk_buff *skb); +/* Debugging functionality */ +#ifdef CONFIG_NET_NCSI_DEBUG +int ncsi_dev_init_debug(struct ncsi_dev_priv *ndp); +void ncsi_dev_release_debug(struct ncsi_dev_priv *ndp); +int ncsi_package_init_debug(struct ncsi_package *np); +void ncsi_package_release_debug(struct ncsi_package *np); +int ncsi_channel_init_debug(struct ncsi_channel *nc); +void ncsi_channel_release_debug(struct ncsi_channel *nc); +#else +static inline int ncsi_dev_init_debug(struct ncsi_dev_priv *ndp) +{ + return -ENOTTY; +} + +static inline void ncsi_dev_release_debug(struct ncsi_dev_priv *ndp) +{ +} + +static inline int ncsi_package_init_debug(struct ncsi_package *np) +{ + return -ENOTTY; +} + +static inline void ncsi_package_release_debug(struct ncsi_package *np) +{ +} + +static inline int ncsi_channel_init_debug(struct ncsi_channel *nc) +{ + return -ENOTTY; +} + +static inline void ncsi_channel_release_debug(struct ncsi_channel *nc) +{ +} +#endif /* CONFIG_NET_NCSI_DEBUG */ #endif /* __NCSI_INTERNAL_H__ */ diff --git a/net/ncsi/ncsi-debug.c b/net/ncsi/ncsi-debug.c new file mode 100644 index 0000000..f38483d --- /dev/null +++ b/net/ncsi/ncsi-debug.c @@ -0,0 +1,103 @@ +/* + * Copyright Gavin Shan, IBM Corporation 2017. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "internal.h" +#include "ncsi-pkt.h" + +static struct dentry *ncsi_dentry; + +int ncsi_dev_init_debug(struct ncsi_dev_priv *ndp) +{ + if (WARN_ON_ONCE(ndp->dentry)) + return 0; + + if (!ncsi_dentry) { + ncsi_dentry = debugfs_create_dir("ncsi", NULL); + if (!ncsi_dentry) { + pr_debug("Failed to create debugfs directory 'ncsi'\n"); + return -ENOMEM; + } + } + + ndp->dentry = debugfs_create_dir(netdev_name(ndp->ndev.dev), + ncsi_dentry); + if (!ndp->dentry) { + pr_debug("Failed to create debugfs directory 'ncsi/%s'\n", + netdev_name(ndp->ndev.dev)); + return -ENOMEM; + } + + return 0; +} + +void ncsi_dev_release_debug(struct ncsi_dev_priv *ndp) +{ + debugfs_remove(ndp->dentry); +} + +int ncsi_package_init_debug(struct ncsi_package *np) +{ + struct ncsi_dev_priv *ndp = np->ndp; + char name[4]; + + if (!ndp->dentry) + return -ENOENT; + + sprintf(name, "p%d", np->id); + np->dentry = debugfs_create_dir(name, ndp->dentry); + if (!np->dentry) { + pr_debug("Failed to create debugfs directory ncsi/%s/%s\n", + netdev_name(ndp->ndev.dev), name); + return -ENOMEM; + } + + return 0; +} + +void ncsi_package_release_debug(struct ncsi_package *np) +{ + debugfs_remove(np->dentry); +} + +int ncsi_channel_init_debug(struct ncsi_channel *nc) +{ + struct ncsi_package *np = nc->package; + struct ncsi_dev_priv *ndp = np->ndp; + char name[3]; + + if (!np->dentry) + return -ENOENT; + + sprintf(name, "c%d", nc->id); + nc->dentry = debugfs_create_dir(name, np->dentry); + if (!nc->dentry) { + pr_debug("Failed to create debugfs directory ncsi/%s/p%d/c%d\n", + netdev_name(ndp->ndev.dev), np->id, nc->id); + return -ENOMEM; + } + + return 0; +} + +void ncsi_channel_release_debug(struct ncsi_channel *nc) +{ + debugfs_remove(nc->dentry); +} diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c index 13ad1f26..84f1405 100644 --- a/net/ncsi/ncsi-manage.c +++ b/net/ncsi/ncsi-manage.c @@ -322,6 +322,8 @@ struct ncsi_channel *ncsi_add_channel(struct ncsi_package *np, unsigned char id) np->channel_num++; spin_unlock_irqrestore(&np->lock, flags); + ncsi_channel_init_debug(nc); + return nc; } @@ -332,6 +334,8 @@ static void ncsi_remove_channel(struct ncsi_channel *nc) unsigned long flags; int i; + ncsi_channel_release_debug(nc); + /* Release filters */ spin_lock_irqsave(&nc->lock, flags); for (i = 0; i < NCSI_FILTER_MAX; i++) { @@ -396,6 +400,8 @@ struct ncsi_package *ncsi_add_package(struct ncsi_dev_priv *ndp, ndp->package_num++; spin_unlock_irqrestore(&ndp->lock, flags); + ncsi_package_init_debug(np); + return np; } @@ -409,6 +415,8 @@ void ncsi_remove_package(struct ncsi_package *np) list_for_each_entry_safe(nc, tmp, &np->channels, node) ncsi_remove_channel(nc); + ncsi_package_release_debug(np); + /* Remove and free package */ spin_lock_irqsave(&ndp->lock, flags); list_del_rcu(&np->node); @@ -1280,6 +1288,13 @@ int ncsi_start_dev(struct ncsi_dev *nd) return -ENOTTY; if (!(ndp->flags & NCSI_DEV_PROBED)) { + /* The debugging functionality should have been initialized + * when registerring the NCSI device. As the network device + * name isn't available that time, we have to delay the work + * to here. + */ + ncsi_dev_init_debug(ndp); + nd->state = ncsi_dev_state_probe; schedule_work(&ndp->work); return 0; @@ -1329,6 +1344,7 @@ void ncsi_unregister_dev(struct ncsi_dev *nd) struct ncsi_package *np, *tmp; unsigned long flags; + ncsi_dev_release_debug(ndp); dev_remove_pack(&ndp->ptype); list_for_each_entry_safe(np, tmp, &ndp->packages, node)