[openib-general] [PATCH] [RFC] new test directory + test code for MAD snooping
Sean Hefty
mshefty at ichips.intel.com
Thu Dec 9 14:24:59 PST 2004
This patch creates a new subdirectory under infiniband called 'test', and adds a
new kernel module called 'madeye' that can be used to snoop and display MADs
(until user-mode smpdump and gmpdump programs are created).
We need to decide if we want to include this sort of test code in the openib
tree, and where it might best go.
- Sean
Index: Kconfig
===================================================================
--- Kconfig (revision 1316)
+++ Kconfig (working copy)
@@ -11,4 +11,6 @@
source "drivers/infiniband/ulp/ipoib/Kconfig"
+source "drivers/infiniband/test/madeye/Kconfig"
+
endmenu
Index: Makefile
===================================================================
--- Makefile (revision 1316)
+++ Makefile (working copy)
@@ -1,3 +1,4 @@
obj-$(CONFIG_INFINIBAND) += core/
obj-$(CONFIG_INFINIBAND_MTHCA) += hw/mthca/
obj-$(CONFIG_INFINIBAND_IPOIB) += ulp/ipoib/
+obj-$(CONFIG_INFINIBAND_MADEYE) += test/madeye/
Index: test/madeye/Kconfig
===================================================================
--- test/madeye/Kconfig (revision 0)
+++ test/madeye/Kconfig (revision 0)
@@ -0,0 +1,6 @@
+config INFINIBAND_MADEYE
+ tristate "MAD debug viewer for InfiniBand"
+ depends on INFINIBAND
+ ---help---
+ Prints sent and received MADs on QP 0/1 for debugging.
+
Index: test/madeye/madeye.c
===================================================================
--- test/madeye/madeye.c (revision 0)
+++ test/madeye/madeye.c (revision 0)
@@ -0,0 +1,241 @@
+/*
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available at
+ * <http://www.fsf.org/copyleft/gpl.html>, or the OpenIB.org BSD
+ * license, available in the LICENSE.TXT file accompanying this
+ * software. These details are also available at
+ * <http://openib.org/license.html>.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Copyright (c) 2004 Intel Corporation. All rights reserved.
+ *
+ * $Id$
+ */
+
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/err.h>
+
+#include <ib_mad.h>
+
+MODULE_AUTHOR("Sean Hefty");
+MODULE_DESCRIPTION("InfiniBand MAD viewer");
+MODULE_LICENSE("Dual BSD/GPL");
+
+static void madeye_remove_one(struct ib_device *device);
+static void madeye_add_one(struct ib_device *device);
+
+static struct ib_client madeye_client = {
+ .name = "madeye",
+ .add = madeye_add_one,
+ .remove = madeye_remove_one
+};
+
+struct madeye_port {
+ struct ib_mad_agent *smi_agent;
+ struct ib_mad_agent *gsi_agent;
+};
+
+static char * get_class_name(u8 mgmt_class)
+{
+ switch(mgmt_class) {
+ case IB_MGMT_CLASS_SUBN_LID_ROUTED:
+ return "LID routed SMP";
+ case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
+ return "Directed route SMP";
+ case IB_MGMT_CLASS_SUBN_ADM:
+ return "Subnet admin.";
+ case IB_MGMT_CLASS_PERF_MGMT:
+ return "Perf. mgmt.";
+ case IB_MGMT_CLASS_BM:
+ return "Baseboard mgmt.";
+ case IB_MGMT_CLASS_DEVICE_MGMT:
+ return "Device mgmt.";
+ case IB_MGMT_CLASS_CM:
+ return "Comm. mgmt.";
+ case IB_MGMT_CLASS_SNMP:
+ return "SNMP";
+ default:
+ return "Unknown vendor/application";
+ }
+}
+
+static char * get_method_name(u8 method)
+{
+ switch(method) {
+ case IB_MGMT_METHOD_GET:
+ return "Get";
+ case IB_MGMT_METHOD_SET:
+ return "Set";
+ case IB_MGMT_METHOD_GET_RESP:
+ return "Get response";
+ case IB_MGMT_METHOD_SEND:
+ return "Send";
+ case IB_MGMT_METHOD_TRAP:
+ return "Trap";
+ case IB_MGMT_METHOD_REPORT:
+ return "Report";
+ case IB_MGMT_METHOD_REPORT_RESP:
+ return "Report response";
+ case IB_MGMT_METHOD_TRAP_REPRESS:
+ return "Trap repress";
+ default:
+ return "Unknown";
+ }
+}
+
+static void print_status_details(u16 status)
+{
+ if (status & cpu_to_be16(0x0001))
+ printk(" busy\n");
+ if (status & cpu_to_be16(0x0002))
+ printk(" redirection required\n");
+ switch((be16_to_cpu(status) & 0x001C) >> 2) {
+ case 1:
+ printk(" bad version\n");
+ break;
+ case 2:
+ printk(" method not supported\n");
+ break;
+ case 3:
+ printk(" method/attribute combo not supported\n");
+ break;
+ case 7:
+ printk(" invalid attribute/modifier value\n");
+ break;
+ }
+}
+
+static void print_mad_hdr(struct ib_mad_hdr *mad_hdr)
+{
+ printk("MAD version....0x%01x\n", mad_hdr->base_version);
+ printk("Class..........0x%01x (%s)\n", mad_hdr->mgmt_class,
+ get_class_name(mad_hdr->mgmt_class));
+ printk("Class version..0x%01x\n", mad_hdr->class_version);
+ printk("Method.........0x%01x (%s)\n", mad_hdr->method,
+ get_method_name(mad_hdr->method));
+ printk("Status.........0x%02x\n", mad_hdr->status);
+ if (mad_hdr->status)
+ print_status_details(mad_hdr->status);
+ printk("Class specific.0x%02x\n", mad_hdr->class_specific);
+ printk("Trans ID.......0x%llx\n", mad_hdr->tid);
+ printk("Attr ID........0x%02x\n", mad_hdr->attr_id);
+ printk("Attr modifier..0x%04x\n", mad_hdr->attr_mod);
+}
+
+static void snoop_smi_handler(struct ib_mad_agent *mad_agent,
+ struct ib_send_wr *send_wr,
+ struct ib_mad_send_wc *mad_send_wc)
+{
+ printk("Madeye:sent SMP\n");
+ print_mad_hdr(send_wr->wr.ud.mad_hdr);
+}
+
+static void recv_smi_handler(struct ib_mad_agent *mad_agent,
+ struct ib_mad_recv_wc *mad_recv_wc)
+{
+ printk("Madeye:recv SMP\n");
+ print_mad_hdr(&mad_recv_wc->recv_buf->mad->mad_hdr);
+}
+
+static void snoop_gsi_handler(struct ib_mad_agent *mad_agent,
+ struct ib_send_wr *send_wr,
+ struct ib_mad_send_wc *mad_send_wc)
+{
+ printk("Madeye:sent GMP\n");
+ print_mad_hdr(send_wr->wr.ud.mad_hdr);
+}
+
+static void recv_gsi_handler(struct ib_mad_agent *mad_agent,
+ struct ib_mad_recv_wc *mad_recv_wc)
+{
+ printk("Madeye:recv GMP\n");
+ print_mad_hdr(&mad_recv_wc->recv_buf->mad->mad_hdr);
+}
+
+static void madeye_add_one(struct ib_device *device)
+{
+ struct madeye_port *port;
+ int reg_flags;
+ u8 i, s, e;
+
+ if (device->node_type == IB_NODE_SWITCH) {
+ s = 0;
+ e = 0;
+ } else {
+ s = 1;
+ e = device->phys_port_cnt;
+ }
+
+ port = kmalloc(sizeof *port * (e - s + 1), GFP_KERNEL);
+ if (!port)
+ goto out;
+
+ reg_flags = IB_MAD_SNOOP_SEND_COMPLETIONS | IB_MAD_SNOOP_RECVS;
+ for (i = s; i <= e; i++) {
+ port[i].smi_agent = ib_register_mad_snoop(device, i,
+ IB_QPT_SMI,
+ reg_flags,
+ snoop_smi_handler,
+ recv_smi_handler,
+ &port[i]);
+ port[i].gsi_agent = ib_register_mad_snoop(device, i,
+ IB_QPT_GSI,
+ reg_flags,
+ snoop_gsi_handler,
+ recv_gsi_handler,
+ &port[i]);
+ }
+
+out:
+ ib_set_client_data(device, &madeye_client, port);
+}
+
+static void madeye_remove_one(struct ib_device *device)
+{
+ struct madeye_port *port;
+ int i, s, e;
+
+ port = (struct madeye_port *)
+ ib_get_client_data(device, &madeye_client);
+ if (!port)
+ return;
+
+ if (device->node_type == IB_NODE_SWITCH) {
+ s = 0;
+ e = 0;
+ } else {
+ s = 1;
+ e = device->phys_port_cnt;
+ }
+
+ for (i = s; i <= e; i++) {
+ if (!IS_ERR(port[i].smi_agent))
+ ib_unregister_mad_agent(port[i].smi_agent);
+ if (!IS_ERR(port[i].gsi_agent))
+ ib_unregister_mad_agent(port[i].gsi_agent);
+ }
+ kfree(port);
+}
+
+static int __init ib_madeye_init(void)
+{
+ return ib_register_client(&madeye_client);
+}
+
+static void __exit ib_madeye_cleanup(void)
+{
+ ib_unregister_client(&madeye_client);
+}
+
+module_init(ib_madeye_init);
+module_exit(ib_madeye_cleanup);
Index: test/madeye/Makefile
===================================================================
--- test/madeye/Makefile (revision 0)
+++ test/madeye/Makefile (revision 0)
@@ -0,0 +1,6 @@
+EXTRA_CFLAGS += -Idrivers/infiniband/include
+
+obj-$(CONFIG_INFINIBAND_MADEYE) += ib_madeye.o
+
+ib_madeye-y := madeye.o \
+
More information about the general
mailing list