[openib-general] [PATCH] optional functions, ib_mad update
Sean Hefty
mshefty at ichips.intel.com
Wed Sep 1 08:45:49 PDT 2004
Here's a patch that checks for optional functions provided by the device. It also includes a patch from Hal for IB management classes.
- Sean
--
Index: ib_verbs.h
===================================================================
--- ib_verbs.h (revision 705)
+++ ib_verbs.h (working copy)
@@ -29,6 +29,7 @@
#include <asm/atomic.h>
#include <linux/device.h>
#include <linux/types.h>
+#include <linux/err.h>
struct ib_mad;
@@ -763,22 +764,14 @@
return device->query_pkey(device, port_num, index, pkey);
}
-static inline int ib_modify_device(struct ib_device *device,
- int device_modify_mask,
- struct ib_device_modify *device_modify)
-{
- return device->modify_device(device, device_modify_mask,
- device_modify);
-}
-
-static inline int ib_modify_port(struct ib_device *device,
- u8 port_num,
- int port_modify_mask,
- struct ib_port_modify *port_modify)
-{
- return device->modify_port(device, port_num, port_modify_mask,
- port_modify);
-}
+int ib_modify_device(struct ib_device *device,
+ int device_modify_mask,
+ struct ib_device_modify *device_modify);
+
+int ib_modify_port(struct ib_device *device,
+ u8 port_num,
+ int port_modify_mask,
+ struct ib_port_modify *port_modify);
struct ib_pd *ib_alloc_pd(struct ib_device *device);
@@ -787,17 +780,11 @@
struct ib_ah *ib_create_ah(struct ib_pd *pd,
struct ib_ah_attr *ah_attr);
-static inline int ib_modify_ah(struct ib_ah *ah,
- struct ib_ah_attr *ah_attr)
-{
- return ah->device->modify_ah(ah, ah_attr);
-}
+int ib_modify_ah(struct ib_ah *ah,
+ struct ib_ah_attr *ah_attr);
-static inline int ib_query_ah(struct ib_ah *ah,
- struct ib_ah_attr *ah_attr)
-{
- return ah->device->query_ah(ah, ah_attr);
-}
+int ib_query_ah(struct ib_ah *ah,
+ struct ib_ah_attr *ah_attr);
int ib_destroy_ah(struct ib_ah *ah);
@@ -813,13 +800,10 @@
return qp->device->modify_qp(qp, qp_attr, qp_attr_mask, qp_cap);
}
-static inline int ib_query_qp(struct ib_qp *qp,
- struct ib_qp_attr *qp_attr,
- int qp_attr_mask,
- struct ib_qp_init_attr *qp_init_attr)
-{
- return qp->device->query_qp(qp, qp_attr, qp_attr_mask, qp_init_attr);
-}
+int ib_query_qp(struct ib_qp *qp,
+ struct ib_qp_attr *qp_attr,
+ int qp_attr_mask,
+ struct ib_qp_init_attr *qp_init_attr);
int ib_destroy_qp(struct ib_qp *qp);
@@ -827,19 +811,13 @@
void *srq_context,
struct ib_srq_attr *srq_attr);
-static inline int ib_query_srq(struct ib_srq *srq,
- struct ib_srq_attr *srq_attr)
-{
- return srq->device->query_srq(srq, srq_attr);
-}
+int ib_modify_srq(struct ib_srq *srq,
+ struct ib_pd *pd,
+ struct ib_srq_attr *srq_attr,
+ int srq_attr_mask);
-static inline int ib_modify_srq(struct ib_srq *srq,
- struct ib_pd *pd,
- struct ib_srq_attr *srq_attr,
- int srq_attr_mask)
-{
- return srq->device->modify_srq(srq, pd, srq_attr, srq_attr_mask);
-}
+int ib_query_srq(struct ib_srq *srq,
+ struct ib_srq_attr *srq_attr);
static inline int ib_post_srq(struct ib_srq *srq,
struct ib_recv_wr *recv_wr,
@@ -855,11 +833,8 @@
void *cq_context,
int cqe);
-static inline int ib_resize_cq(struct ib_cq *cq,
- int cqe)
-{
- return cq->device->resize_cq(cq, cqe);
-}
+int ib_resize_cq(struct ib_cq *cq,
+ int cqe);
int ib_destroy_cq(struct ib_cq *cq);
@@ -869,11 +844,8 @@
int mr_access_flags,
u64 *iova_start);
-static inline int ib_query_mr(struct ib_mr *mr,
- struct ib_mr_attr *mr_attr)
-{
- return mr->device->query_mr(mr, mr_attr);
-}
+int ib_query_mr(struct ib_mr *mr,
+ struct ib_mr_attr *mr_attr);
int ib_dereg_mr(struct ib_mr *mr);
@@ -916,19 +888,13 @@
int ib_dealloc_fmr(struct ib_fmr *fmr);
-static inline int ib_attach_mcast(struct ib_qp *qp,
- union ib_gid *gid,
- u16 lid)
-{
- return qp->device->attach_mcast(qp, gid, lid);
-}
-
-static inline int ib_detach_mcast(struct ib_qp *qp,
- union ib_gid *gid,
- u16 lid)
-{
- return qp->device->detach_mcast(qp, gid, lid);
-}
+int ib_attach_mcast(struct ib_qp *qp,
+ union ib_gid *gid,
+ u16 lid);
+
+int ib_detach_mcast(struct ib_qp *qp,
+ union ib_gid *gid,
+ u16 lid);
static inline int ib_post_send(struct ib_qp *qp,
struct ib_send_wr *send_wr,
@@ -966,7 +932,9 @@
static inline int ib_peek_cq(struct ib_cq *cq,
int wc_cnt)
{
- return cq->device->peek_cq(cq, wc_cnt);
+ return cq->device->peek_cq ?
+ cq->device->peek_cq(cq, wc_cnt) :
+ -ENOSYS;
}
/**
@@ -984,7 +952,9 @@
static inline int ib_req_n_notify_cq(struct ib_cq *cq,
int wc_cnt)
{
- return cq->device->req_n_notify_cq(cq, wc_cnt);
+ return cq->device->req_n_notify_cq ?
+ cq->device->req_n_notify_cq(cq, wc_cnt) :
+ -ENOSYS;
}
#endif /* IB_VERBS_H */
Index: ib_mad.h
===================================================================
--- ib_mad.h (revision 706)
+++ ib_mad.h (working copy)
@@ -26,7 +26,17 @@
#if !defined( IB_MAD_H )
#define IB_MAD_H
-#include "ib_verbs.h"
+#include <ib_verbs.h>
+
+/* Management classes */
+#define IB_MGMT_CLASS_SUBN_LID_ROUTED 0x01
+#define IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE 0x81
+#define IB_MGMT_CLASS_SUBN_ADM 0x03
+#define IB_MGMT_CLASS_PERF_MGMT 0x04
+#define IB_MGMT_CLASS_BM 0x05
+#define IB_MGMT_CLASS_DEVICE_MGMT 0x06
+#define IB_MGMT_CLASS_CM 0x07
+#define IB_MGMT_CLASS_SNMP 0x08
#define IB_QP0 0
#define IB_QP1 cpu_to_be32(1)
Index: TODO
===================================================================
--- TODO (revision 705)
+++ TODO (working copy)
@@ -9,6 +9,8 @@
- Should ib_unmap_fmr take fmr_array as input, or just fmr?
What should the restriction on the fmr_array be? All from same
device?
+ - Change ib_map_fmr to ib_map_phys_fmr.
+ - Add way to determine if a device is an HCA, router, or switch.
MAD TODOs:
- Need to define queuing model for ib_mad_post_send.
Index: ib_verbs.c
===================================================================
--- ib_verbs.c (revision 708)
+++ ib_verbs.c (working copy)
@@ -26,6 +26,35 @@
#include <linux/err.h>
#include <ib_verbs.h>
+/* Device */
+
+int ib_modify_device(struct ib_device *device,
+ int device_modify_mask,
+ struct ib_device_modify *device_modify)
+{
+ if (!device->modify_device)
+ return -ENOSYS;
+
+ return device->modify_device(device, device_modify_mask,
+ device_modify);
+}
+EXPORT_SYMBOL(ib_modify_device);
+
+int ib_modify_port(struct ib_device *device,
+ u8 port_num,
+ int port_modify_mask,
+ struct ib_port_modify *port_modify)
+{
+ if (!device->modify_port)
+ return -ENOSYS;
+
+ return device->modify_port(device, port_num, port_modify_mask,
+ port_modify);
+}
+EXPORT_SYMBOL(ib_modify_port);
+
+/* Protection domain */
+
struct ib_pd *ib_alloc_pd(struct ib_device *device)
{
struct ib_pd *pd;
@@ -50,6 +79,8 @@
}
EXPORT_SYMBOL(ib_dealloc_pd);
+/* Address handle */
+
struct ib_ah *ib_create_ah(struct ib_pd *pd,
struct ib_ah_attr *ah_attr)
{
@@ -67,6 +98,26 @@
}
EXPORT_SYMBOL(ib_create_ah);
+int ib_modify_ah(struct ib_ah *ah,
+ struct ib_ah_attr *ah_attr)
+{
+ if (!ah->device->modify_ah)
+ return -ENOSYS;
+
+ return ah->device->modify_ah(ah, ah_attr);
+}
+EXPORT_SYMBOL(ib_modify_ah);
+
+int ib_query_ah(struct ib_ah *ah,
+ struct ib_ah_attr *ah_attr)
+{
+ if (!ah->device->query_ah)
+ return -ENOSYS;
+
+ return ah->device->query_ah(ah, ah_attr);
+}
+EXPORT_SYMBOL(ib_query_ah);
+
int ib_destroy_ah(struct ib_ah *ah)
{
struct ib_pd *pd;
@@ -82,6 +133,8 @@
}
EXPORT_SYMBOL(ib_destroy_ah);
+/* Queue pair */
+
struct ib_qp *ib_create_qp(struct ib_pd *pd,
struct ib_qp_init_attr *qp_init_attr,
struct ib_qp_cap *qp_cap)
@@ -109,6 +162,18 @@
}
EXPORT_SYMBOL(ib_create_qp);
+int ib_query_qp(struct ib_qp *qp,
+ struct ib_qp_attr *qp_attr,
+ int qp_attr_mask,
+ struct ib_qp_init_attr *qp_init_attr)
+{
+ if (!qp->device->query_qp)
+ return -ENOSYS;
+
+ return qp->device->query_qp(qp, qp_attr, qp_attr_mask, qp_init_attr);
+}
+EXPORT_SYMBOL(ib_query_qp);
+
int ib_destroy_qp(struct ib_qp *qp)
{
struct ib_pd *pd;
@@ -134,6 +199,8 @@
}
EXPORT_SYMBOL(ib_destroy_qp);
+/* Shared receive queue */
+
struct ib_srq *ib_create_srq(struct ib_pd *pd,
void *srq_context,
struct ib_srq_attr *srq_attr)
@@ -157,6 +224,28 @@
}
EXPORT_SYMBOL(ib_create_srq);
+int ib_modify_srq(struct ib_srq *srq,
+ struct ib_pd *pd,
+ struct ib_srq_attr *srq_attr,
+ int srq_attr_mask)
+{
+ if (!srq->device->modify_srq)
+ return -ENOSYS;
+
+ return srq->device->modify_srq(srq, pd, srq_attr, srq_attr_mask);
+}
+EXPORT_SYMBOL(ib_modify_srq);
+
+int ib_query_srq(struct ib_srq *srq,
+ struct ib_srq_attr *srq_attr)
+{
+ if (!srq->device->query_srq)
+ return -ENOSYS;
+
+ return srq->device->query_srq(srq, srq_attr);
+}
+EXPORT_SYMBOL(ib_modify_srq);
+
int ib_destroy_srq(struct ib_srq *srq)
{
struct ib_pd *pd;
@@ -175,6 +264,8 @@
}
EXPORT_SYMBOL(ib_destroy_srq);
+/* Completion queue */
+
struct ib_cq *ib_create_cq(struct ib_device *device,
ib_comp_handler comp_handler,
void *cq_context,
@@ -195,6 +286,16 @@
}
EXPORT_SYMBOL(ib_create_cq);
+int ib_resize_cq(struct ib_cq *cq,
+ int cqe)
+{
+ if (!cq->device->resize_cq)
+ return -ENOSYS;
+
+ return cq->device->resize_cq(cq, cqe);
+}
+EXPORT_SYMBOL(ib_resize_cq);
+
int ib_destroy_cq(struct ib_cq *cq)
{
if (atomic_read(&cq->usecnt))
@@ -204,6 +305,8 @@
}
EXPORT_SYMBOL(ib_destroy_cq);
+/* Memory region */
+
struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
struct ib_phys_buf *phys_buf_array,
int num_phys_buf,
@@ -226,6 +329,16 @@
}
EXPORT_SYMBOL(ib_reg_phys_mr);
+int ib_query_mr(struct ib_mr *mr,
+ struct ib_mr_attr *mr_attr)
+{
+ if (!mr->device->query_mr)
+ return -ENOSYS;
+
+ return mr->device->query_mr(mr, mr_attr);
+}
+EXPORT_SYMBOL(ib_query_mr);
+
int ib_dereg_mr(struct ib_mr *mr)
{
struct ib_pd *pd;
@@ -255,6 +368,9 @@
struct ib_pd *old_pd;
int ret;
+ if (!mr->device->rereg_phys_mr)
+ return -ENOSYS;
+
if (atomic_read(&mr->usecnt))
return -EBUSY;
@@ -273,10 +389,14 @@
}
EXPORT_SYMBOL(ib_rereg_phys_mr);
+/* Memory window */
struct ib_mw *ib_alloc_mw(struct ib_pd *pd)
{
struct ib_mw *mw;
+ if (!pd->device->alloc_mw)
+ return ERR_PTR(-ENOSYS);
+
mw = pd->device->alloc_mw(pd);
if (!IS_ERR(mw)) {
@@ -304,12 +424,17 @@
}
EXPORT_SYMBOL(ib_dealloc_mw);
+/* Fast-memory registration */
+
struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
int mr_access_flags,
struct ib_fmr_attr *fmr_attr)
{
struct ib_fmr *fmr;
+ if (!pd->device->alloc_fmr)
+ return ERR_PTR(-ENOSYS);
+
fmr = pd->device->alloc_fmr(pd, mr_access_flags, fmr_attr);
if (!IS_ERR(fmr)) {
@@ -336,3 +461,22 @@
return ret;
}
EXPORT_SYMBOL(ib_dealloc_fmr);
+
+/* Multicast */
+
+int ib_attach_mcast(struct ib_qp *qp,
+ union ib_gid *gid,
+ u16 lid)
+{
+ if (!qp->device->attach_mcast)
+ return -ENOSYS;
+
+ return qp->device->attach_mcast(qp, gid, lid);
+}
+
+int ib_detach_mcast(struct ib_qp *qp,
+ union ib_gid *gid,
+ u16 lid)
+{
+ return qp->device->detach_mcast(qp, gid, lid);
+}
More information about the general
mailing list