]> xenbits.xensource.com Git - people/julieng/freebsd.git/commitdiff
Merge LinuxKPI changes from DragonflyBSD:
authorhselasky <hselasky@FreeBSD.org>
Mon, 19 Oct 2015 12:26:38 +0000 (12:26 +0000)
committerhselasky <hselasky@FreeBSD.org>
Mon, 19 Oct 2015 12:26:38 +0000 (12:26 +0000)
- 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

sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h
sys/dev/cxgbe/iw_cxgbe/qp.c
sys/ofed/drivers/infiniband/core/uverbs_main.c
sys/ofed/include/linux/kref.h

index 5f2542c55c0cf372d163acb45b9352247c9a185b..e6d70f429983c806c894a299d2280043bf8c1fbc 100644 (file)
@@ -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));  \
 }
 
index cf747601110189adb5c064b2dfa2ef034ee89f95..38c61ea8006b5d92b7f13a59a5748cfd56115ea5 100644 (file)
@@ -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) {
index 12bc0d32277f65fe4a259444093f28e621694ae4..5a6b605f3810c6ae6c030f9b2e5947a91b19a786 100644 (file)
@@ -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);
 
index 883e1a1dceb45da83705a757334d58f618dd16e7..ecf3c8a753a737e7bbc986024303b130c13283f4 100644 (file)
@@ -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
 #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_ */