]> git.openfabrics.org - ~shefty/libibverbs.git/commitdiff
Implement userspace side of query_device verb
authorRoland Dreier <roland@topspin.com>
Mon, 6 Jun 2005 19:44:17 +0000 (19:44 +0000)
committerRoland Dreier <rolandd@cisco.com>
Thu, 9 Nov 2006 19:35:56 +0000 (11:35 -0800)
Implement query_device verb and add a "devinfo" example.

Signed-off-by: Roland Dreier <roland@topspin.com>
Makefile.am
README
examples/devinfo.c [new file with mode: 0644]
include/infiniband/driver.h
include/infiniband/kern-abi.h
include/infiniband/verbs.h
src/cmd.c
src/libibverbs.map
src/verbs.c

index 5b3fb8c7e6614cf70055232c79e65cffddea0762..e43d54b91de0929f8b2dea71a7dee810a0148e93 100644 (file)
@@ -19,10 +19,12 @@ src_libibverbs_la_LDFLAGS = -version-info 1 -export-dynamic \
     $(libibverbs_version_script)
 src_libibverbs_la_DEPENDENCIES = $(srcdir)/src/libibverbs.map
 
-bin_PROGRAMS = examples/ibv_devices examples/ibv_asyncwatch \
-    examples/ibv_pingpong examples/ibv_ud_pingpong
+bin_PROGRAMS = examples/ibv_devices examples/ibv_devinfo \
+    examples/ibv_asyncwatch examples/ibv_pingpong examples/ibv_ud_pingpong
 examples_ibv_devices_SOURCES = examples/device_list.c
 examples_ibv_devices_LDADD = $(top_builddir)/src/libibverbs.la
+examples_ibv_devinfo_SOURCES = examples/devinfo.c
+examples_ibv_devinfo_LDADD = $(top_builddir)/src/libibverbs.la
 examples_ibv_pingpong_SOURCES = examples/pingpong.c
 examples_ibv_pingpong_LDADD = $(top_builddir)/src/libibverbs.la
 examples_ibv_ud_pingpong_SOURCES = examples/ud-pingpong.c
diff --git a/README b/README
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..d7d7428998f881402dbd87e2ee590581bd73bddb 100644 (file)
--- a/README
+++ b/README
@@ -0,0 +1,14 @@
+Introduction
+------------
+
+The libibverbs
+
+Reporting bugs
+--------------
+
+Submitting patches
+------------------
+
+TODO
+----
+
diff --git a/examples/devinfo.c b/examples/devinfo.c
new file mode 100644 (file)
index 0000000..ae69fe8
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2005 Cisco Systems.  All rights reserved.
+ *
+ * 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 from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * 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.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#  include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#include <stdio.h>
+#include <endian.h>
+#include <byteswap.h>
+
+#include <infiniband/verbs.h>
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+static inline uint64_t be64_to_cpu(uint64_t x) { return bswap_64(x); }
+#elif __BYTE_ORDER == __BIG_ENDIAN
+static inline uint64_t be64_to_cpu(uint64_t x) { return x; }
+#endif
+
+int main(int argc, char *argv[])
+{
+       struct dlist *dev_list;
+       struct ibv_device *ib_dev;
+       struct ibv_context *context;
+       struct ibv_device_attr attr;
+
+       dev_list = ibv_get_devices();
+
+       dlist_start(dev_list);
+       ib_dev = dlist_next(dev_list);
+
+       if (!ib_dev) {
+               fprintf(stderr, "No IB devices found\n");
+               return 1;
+       }
+
+       context = ibv_open_device(ib_dev);
+       if (!context) {
+               fprintf(stderr, "Couldn't get context for %s\n",
+                       ibv_get_device_name(ib_dev));
+               return 1;
+       }
+
+       if (ibv_query_device(context, &attr)) {
+               fprintf(stderr, "Couldn't query device for %s\n",
+                       ibv_get_device_name(ib_dev));
+               return 1;
+       }
+
+       printf("%s properties:\n", ibv_get_device_name(ib_dev));
+       printf("\tNum ports:\t%d\n", attr.phys_port_cnt);
+       printf("\tNode GUID:\t%016llx\n", be64_to_cpu(attr.node_guid));
+       printf("\tMax QPs:\t%d\n", attr.max_qp);
+       printf("\tMax CQs:\t%d\n", attr.max_cq);
+       printf("\tMax PDs:\t%d\n", attr.max_pd);
+       printf("\tMax AHs:\t%d\n", attr.max_ah);
+
+       return 0;
+}
index 45279e33748271ac366d058645ce956b31c11736..ed96cdb10f459d869fb1e85486f1a821150eac05 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
+ * Copyright (c) 2005 Cisco Systems.  All rights reserved.
  *
  * 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
@@ -65,6 +66,9 @@ typedef struct ibv_device *(*ibv_driver_init_func)(struct sysfs_class_device *);
 
 extern int ibv_cmd_get_context(int num_comp, struct ibv_context *context,
                               struct ibv_get_context *cmd, size_t cmd_size);
+extern int ibv_cmd_query_device(struct ibv_context *context,
+                               struct ibv_device_attr *device_attr,
+                               struct ibv_query_device *cmd, size_t cmd_size);
 extern int ibv_cmd_query_port(struct ibv_context *context, uint8_t port_num,
                              struct ibv_port_attr *port_attr,
                              struct ibv_query_port *cmd, size_t cmd_size);
index 8166c83c0aa3b5ccec50f4e6f9cdbb73a9fae9b6..cf76ec8a2a3f3d5590044f5de088f755e1749567 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2005 Topspin Communications.  All rights reserved.
+ * Copyright (c) 2005 Cisco Systems.  All rights reserved.
  *
  * 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
@@ -135,6 +136,58 @@ struct ibv_get_context_resp {
        __u32 cq_fd[1];
 };
 
+struct ibv_query_device {
+       __u32 command;
+       __u16 in_words;
+       __u16 out_words;
+       __u64 response;
+       __u64 driver_data[0];
+};
+
+struct ibv_query_device_resp {
+       __u64 fw_ver;
+       __u64 node_guid;
+       __u64 sys_image_guid;
+       __u64 max_mr_size;
+       __u64 page_size_cap;
+       __u32 vendor_id;
+       __u32 vendor_part_id;
+       __u32 hw_ver;
+       __u32 max_qp;
+       __u32 max_qp_wr;
+       __u32 device_cap_flags;
+       __u32 max_sge;
+       __u32 max_sge_rd;
+       __u32 max_cq;
+       __u32 max_cqe;
+       __u32 max_mr;
+       __u32 max_pd;
+       __u32 max_qp_rd_atom;
+       __u32 max_ee_rd_atom;
+       __u32 max_res_rd_atom;
+       __u32 max_qp_init_rd_atom;
+       __u32 max_ee_init_rd_atom;
+       __u32 atomic_cap;
+       __u32 max_ee;
+       __u32 max_rdd;
+       __u32 max_mw;
+       __u32 max_raw_ipv6_qp;
+       __u32 max_raw_ethy_qp;
+       __u32 max_mcast_grp;
+       __u32 max_mcast_qp_attach;
+       __u32 max_total_mcast_qp_attach;
+       __u32 max_ah;
+       __u32 max_fmr;
+       __u32 max_map_per_fmr;
+       __u32 max_srq;
+       __u32 max_srq_wr;
+       __u32 max_srq_sge;
+       __u16 max_pkeys;
+       __u8  local_ca_ack_delay;
+       __u8  phys_port_cnt;
+       __u8  reserved[4];
+};
+
 struct ibv_query_port {
        __u32 command;
        __u16 in_words;
index 602d6971c0d97967dad8b44579d8e6e6be2a1124..d0746017388694da69616b2d2f99d0347b9e3dd1 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
  * Copyright (c) 2004 Intel Corporation.  All rights reserved.
+ * Copyright (c) 2005 Cisco Systems.  All rights reserved.
  *
  * 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
@@ -58,6 +59,79 @@ union ibv_gid {
        } global;
 };
 
+enum ibv_node_type {
+       IBV_NODE_CA     = 1,
+       IBV_NODE_SWITCH,
+       IBV_NODE_ROUTER
+};
+
+enum ibv_device_cap_flags {
+       IBV_DEVICE_RESIZE_MAX_WR        = 1,
+       IBV_DEVICE_BAD_PKEY_CNTR        = 1 <<  1,
+       IBV_DEVICE_BAD_QKEY_CNTR        = 1 <<  2,
+       IBV_DEVICE_RAW_MULTI            = 1 <<  3,
+       IBV_DEVICE_AUTO_PATH_MIG        = 1 <<  4,
+       IBV_DEVICE_CHANGE_PHY_PORT      = 1 <<  5,
+       IBV_DEVICE_UD_AV_PORT_ENFORCE   = 1 <<  6,
+       IBV_DEVICE_CURR_QP_STATE_MOD    = 1 <<  7,
+       IBV_DEVICE_SHUTDOWN_PORT        = 1 <<  8,
+       IBV_DEVICE_INIT_TYPE            = 1 <<  9,
+       IBV_DEVICE_PORT_ACTIVE_EVENT    = 1 << 10,
+       IBV_DEVICE_SYS_IMAGE_GUID       = 1 << 11,
+       IBV_DEVICE_RC_RNR_NAK_GEN       = 1 << 12,
+       IBV_DEVICE_SRQ_RESIZE           = 1 << 13,
+       IBV_DEVICE_N_NOTIFY_CQ          = 1 << 14,
+};
+
+enum ibv_atomic_cap {
+       IBV_ATOMIC_NONE,
+       IBV_ATOMIC_HCA,
+       IBV_ATOMIC_GLOB
+};
+
+struct ibv_device_attr {
+       uint64_t                fw_ver;
+       uint64_t                node_guid;
+       uint64_t                sys_image_guid;
+       uint64_t                max_mr_size;
+       uint64_t                page_size_cap;
+       uint32_t                vendor_id;
+       uint32_t                vendor_part_id;
+       uint32_t                hw_ver;
+       int                     max_qp;
+       int                     max_qp_wr;
+       int                     device_cap_flags;
+       int                     max_sge;
+       int                     max_sge_rd;
+       int                     max_cq;
+       int                     max_cqe;
+       int                     max_mr;
+       int                     max_pd;
+       int                     max_qp_rd_atom;
+       int                     max_ee_rd_atom;
+       int                     max_res_rd_atom;
+       int                     max_qp_init_rd_atom;
+       int                     max_ee_init_rd_atom;
+       enum ibv_atomic_cap     atomic_cap;
+       int                     max_ee;
+       int                     max_rdd;
+       int                     max_mw;
+       int                     max_raw_ipv6_qp;
+       int                     max_raw_ethy_qp;
+       int                     max_mcast_grp;
+       int                     max_mcast_qp_attach;
+       int                     max_total_mcast_qp_attach;
+       int                     max_ah;
+       int                     max_fmr;
+       int                     max_map_per_fmr;
+       int                     max_srq;
+       int                     max_srq_wr;
+       int                     max_srq_sge;
+       uint16_t                max_pkeys;
+       uint8_t                 local_ca_ack_delay;
+       uint8_t                 phys_port_cnt;
+};
+
 enum ibv_mtu {
        IBV_MTU_256  = 1,
        IBV_MTU_512  = 2,
@@ -412,6 +486,8 @@ struct ibv_device {
 };
 
 struct ibv_context_ops {
+       int                     (*query_device)(struct ibv_context *context,
+                                             struct ibv_device_attr *device_attr);
        int                     (*query_port)(struct ibv_context *context, uint8_t port_num,
                                              struct ibv_port_attr *port_attr);
        int                     (*query_gid)(struct ibv_context *context, uint8_t port_num,
@@ -484,6 +560,12 @@ extern int ibv_close_device(struct ibv_context *context);
 extern int ibv_get_async_event(struct ibv_context *context,
                               struct ibv_async_event *event);
 
+/**
+ * ibv_query_device - Get device properties
+ */
+extern int ibv_query_device(struct ibv_context *context,
+                           struct ibv_device_attr *device_attr);
+
 /**
  * ibv_query_port - Get port properties
  */
index 4e74495ca1e976569ab5a8d6fd42d6a13160e84c..14f4c7c0e5393f3b8eb6da7bcd96b491404e2630 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -62,6 +62,61 @@ int ibv_cmd_get_context(int num_comp, struct ibv_context *context,
        return 0;
 }
 
+int ibv_cmd_query_device(struct ibv_context *context,
+                        struct ibv_device_attr *device_attr,
+                        struct ibv_query_device *cmd, size_t cmd_size)
+{
+       struct ibv_query_device_resp resp;
+
+       IBV_INIT_CMD_RESP(cmd, cmd_size, QUERY_DEVICE, &resp);
+
+       if (write(context->cmd_fd, cmd, cmd_size) != cmd_size)
+               return errno;
+
+       device_attr->fw_ver                    = resp.fw_ver;
+       device_attr->node_guid                 = resp.node_guid;
+       device_attr->sys_image_guid            = resp.sys_image_guid;
+       device_attr->max_mr_size               = resp.max_mr_size;
+       device_attr->page_size_cap             = resp.page_size_cap;
+       device_attr->vendor_id                 = resp.vendor_id;
+       device_attr->vendor_part_id            = resp.vendor_part_id;
+       device_attr->hw_ver                    = resp.hw_ver;
+       device_attr->max_qp                    = resp.max_qp;
+       device_attr->max_qp_wr                 = resp.max_qp_wr;
+       device_attr->device_cap_flags          = resp.device_cap_flags;
+       device_attr->max_sge                   = resp.max_sge;
+       device_attr->max_sge_rd                = resp.max_sge_rd;
+       device_attr->max_cq                    = resp.max_cq;
+       device_attr->max_cqe                   = resp.max_cqe;
+       device_attr->max_mr                    = resp.max_mr;
+       device_attr->max_pd                    = resp.max_pd;
+       device_attr->max_qp_rd_atom            = resp.max_qp_rd_atom;
+       device_attr->max_ee_rd_atom            = resp.max_ee_rd_atom;
+       device_attr->max_res_rd_atom           = resp.max_res_rd_atom;
+       device_attr->max_qp_init_rd_atom       = resp.max_qp_init_rd_atom;
+       device_attr->max_ee_init_rd_atom       = resp.max_ee_init_rd_atom;
+       device_attr->atomic_cap                = resp.atomic_cap;
+       device_attr->max_ee                    = resp.max_ee;
+       device_attr->max_rdd                   = resp.max_rdd;
+       device_attr->max_mw                    = resp.max_mw;
+       device_attr->max_raw_ipv6_qp           = resp.max_raw_ipv6_qp;
+       device_attr->max_raw_ethy_qp           = resp.max_raw_ethy_qp;
+       device_attr->max_mcast_grp             = resp.max_mcast_grp;
+       device_attr->max_mcast_qp_attach       = resp.max_mcast_qp_attach;
+       device_attr->max_total_mcast_qp_attach = resp.max_total_mcast_qp_attach;
+       device_attr->max_ah                    = resp.max_ah;
+       device_attr->max_fmr                   = resp.max_fmr;
+       device_attr->max_map_per_fmr           = resp.max_map_per_fmr;
+       device_attr->max_srq                   = resp.max_srq;
+       device_attr->max_srq_wr                = resp.max_srq_wr;
+       device_attr->max_srq_sge               = resp.max_srq_sge;
+       device_attr->max_pkeys                 = resp.max_pkeys;
+       device_attr->local_ca_ack_delay        = resp.local_ca_ack_delay;
+       device_attr->phys_port_cnt             = resp.phys_port_cnt;
+
+       return 0;
+}
+
 int ibv_cmd_query_port(struct ibv_context *context, uint8_t port_num,
                       struct ibv_port_attr *port_attr,
                       struct ibv_query_port *cmd, size_t cmd_size)
index 64a4f6a5c80fa44c852b3f22c5298885146a7fd2..cf40084a3349d6bfc20318fd9ac81443289f430c 100644 (file)
@@ -6,6 +6,7 @@ IBVERBS_1.0 {
                ibv_open_device;
                ibv_close_device;
                ibv_get_async_event;
+               ibv_query_device;
                ibv_query_port;
                ibv_query_gid;
                ibv_query_pkey;
@@ -24,6 +25,7 @@ IBVERBS_1.0 {
                ibv_attach_mcast;
                ibv_detach_mcast;
                ibv_cmd_get_context;
+               ibv_cmd_query_device;
                ibv_cmd_query_port;
                ibv_cmd_query_gid;
                ibv_cmd_query_pkey;
index 94830b4b4a885d07cdc4cb18b33308dfd9da19c1..68337e13359cd25f31b1e2fa682ae51268ce2236 100644 (file)
 
 #include "ibverbs.h"
 
+int ibv_query_device(struct ibv_context *context,
+                    struct ibv_device_attr *device_attr)
+{
+       return context->ops.query_device(context, device_attr);
+}
+
 int ibv_query_port(struct ibv_context *context, uint8_t port_num,
                   struct ibv_port_attr *port_attr)
 {