summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorhselasky <hselasky@FreeBSD.org>2015-10-19 12:26:38 +0000
committerhselasky <hselasky@FreeBSD.org>2015-10-19 12:26:38 +0000
commitfd834c513a221af10224dd38154b74cde2b57c62 (patch)
tree9085faf590b9c360afab9220d90c842a4c4d8147 /sys
parentc2a6426cb9ffa31713523a61187c8876c801ed54 (diff)
downloadFreeBSD-src-fd834c513a221af10224dd38154b74cde2b57c62.zip
FreeBSD-src-fd834c513a221af10224dd38154b74cde2b57c62.tar.gz
Merge LinuxKPI changes from DragonflyBSD:
- Define the kref structure identical to the one found in Linux. - Update clients referring inside the kref structure. - Implement kref_sub() for FreeBSD. Reviewed by: np @ Sponsored by: Mellanox Technologies
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h8
-rw-r--r--sys/dev/cxgbe/iw_cxgbe/qp.c3
-rw-r--r--sys/ofed/drivers/infiniband/core/uverbs_main.c2
-rw-r--r--sys/ofed/include/linux/kref.h34
4 files changed, 34 insertions, 13 deletions
diff --git a/sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h b/sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h
index 5f2542c..e6d70f4 100644
--- a/sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h
+++ b/sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h
@@ -606,18 +606,16 @@ enum c4iw_mmid_state {
#define MPA_V2_RDMA_READ_RTR 0x4000
#define MPA_V2_IRD_ORD_MASK 0x3FFF
-/* Fixme: Use atomic_read for kref.count as same as Linux */
#define c4iw_put_ep(ep) { \
CTR4(KTR_IW_CXGBE, "put_ep (%s:%u) ep %p, refcnt %d", \
- __func__, __LINE__, ep, (ep)->kref.count); \
- WARN_ON((ep)->kref.count < 1); \
+ __func__, __LINE__, ep, atomic_read(&(ep)->kref.refcount)); \
+ WARN_ON(atomic_read(&(ep)->kref.refcount) < 1); \
kref_put(&((ep)->kref), _c4iw_free_ep); \
}
-/* Fixme: Use atomic_read for kref.count as same as Linux */
#define c4iw_get_ep(ep) { \
CTR4(KTR_IW_CXGBE, "get_ep (%s:%u) ep %p, refcnt %d", \
- __func__, __LINE__, ep, (ep)->kref.count); \
+ __func__, __LINE__, ep, atomic_read(&(ep)->kref.refcount)); \
kref_get(&((ep)->kref)); \
}
diff --git a/sys/dev/cxgbe/iw_cxgbe/qp.c b/sys/dev/cxgbe/iw_cxgbe/qp.c
index cf74760..38c61ea 100644
--- a/sys/dev/cxgbe/iw_cxgbe/qp.c
+++ b/sys/dev/cxgbe/iw_cxgbe/qp.c
@@ -1257,8 +1257,7 @@ int c4iw_modify_qp(struct c4iw_dev *rhp, struct c4iw_qp *qhp,
case C4IW_QP_STATE_RTS:
switch (attrs->next_state) {
case C4IW_QP_STATE_CLOSING:
- //Fixme: Use atomic_read as same as Linux
- BUG_ON(qhp->ep->com.kref.count < 2);
+ BUG_ON(atomic_read(&qhp->ep->com.kref.refcount) < 2);
set_state(qhp, C4IW_QP_STATE_CLOSING);
ep = qhp->ep;
if (!internal) {
diff --git a/sys/ofed/drivers/infiniband/core/uverbs_main.c b/sys/ofed/drivers/infiniband/core/uverbs_main.c
index 12bc0d3..5a6b605 100644
--- a/sys/ofed/drivers/infiniband/core/uverbs_main.c
+++ b/sys/ofed/drivers/infiniband/core/uverbs_main.c
@@ -1168,7 +1168,7 @@ static ssize_t show_dev_ref_cnt(struct device *device,
if (!dev)
return -ENODEV;
- return sprintf(buf, "%d\n", dev->ref.count);
+ return sprintf(buf, "%d\n", atomic_read(&dev->ref.refcount));
}
static DEVICE_ATTR(ref_cnt, S_IRUGO, show_dev_ref_cnt, NULL);
diff --git a/sys/ofed/include/linux/kref.h b/sys/ofed/include/linux/kref.h
index 883e1a1..ecf3c8a 100644
--- a/sys/ofed/include/linux/kref.h
+++ b/sys/ofed/include/linux/kref.h
@@ -2,7 +2,8 @@
* Copyright (c) 2010 Isilon Systems, Inc.
* Copyright (c) 2010 iX Systems, Inc.
* Copyright (c) 2010 Panasas, Inc.
- * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
+ * Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
+ * Copyright (c) 2013 François Tigeot
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -32,33 +33,56 @@
#include <sys/types.h>
#include <sys/refcount.h>
+#include <asm/atomic.h>
+
struct kref {
- volatile u_int count;
+ atomic_t refcount;
};
static inline void
kref_init(struct kref *kref)
{
- refcount_init(&kref->count, 1);
+ refcount_init(&kref->refcount.counter, 1);
}
static inline void
kref_get(struct kref *kref)
{
- refcount_acquire(&kref->count);
+ refcount_acquire(&kref->refcount.counter);
}
static inline int
kref_put(struct kref *kref, void (*rel)(struct kref *kref))
{
- if (refcount_release(&kref->count)) {
+ if (refcount_release(&kref->refcount.counter)) {
rel(kref);
return 1;
}
return 0;
}
+static inline int
+kref_sub(struct kref *kref, unsigned int count,
+ void (*rel)(struct kref *kref))
+{
+
+ while (count--) {
+ if (refcount_release(&kref->refcount.counter)) {
+ rel(kref);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static inline int __must_check
+kref_get_unless_zero(struct kref *kref)
+{
+
+ return atomic_add_unless(&kref->refcount, 1, 0);
+}
+
#endif /* _LINUX_KREF_H_ */
OpenPOWER on IntegriCloud