Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Oct 2015 12:26:39 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r289578 - in head/sys: dev/cxgbe/iw_cxgbe ofed/drivers/infiniband/core ofed/include/linux
Message-ID:  <201510191226.t9JCQdL2078620@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Mon Oct 19 12:26:38 2015
New Revision: 289578
URL: https://svnweb.freebsd.org/changeset/base/289578

Log:
  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

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

Modified: head/sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h
==============================================================================
--- head/sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h	Mon Oct 19 12:08:06 2015	(r289577)
+++ head/sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h	Mon Oct 19 12:26:38 2015	(r289578)
@@ -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));  \
 }
 

Modified: head/sys/dev/cxgbe/iw_cxgbe/qp.c
==============================================================================
--- head/sys/dev/cxgbe/iw_cxgbe/qp.c	Mon Oct 19 12:08:06 2015	(r289577)
+++ head/sys/dev/cxgbe/iw_cxgbe/qp.c	Mon Oct 19 12:26:38 2015	(r289578)
@@ -1257,8 +1257,7 @@ int c4iw_modify_qp(struct c4iw_dev *rhp,
 	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) {

Modified: head/sys/ofed/drivers/infiniband/core/uverbs_main.c
==============================================================================
--- head/sys/ofed/drivers/infiniband/core/uverbs_main.c	Mon Oct 19 12:08:06 2015	(r289577)
+++ head/sys/ofed/drivers/infiniband/core/uverbs_main.c	Mon Oct 19 12:26:38 2015	(r289578)
@@ -1168,7 +1168,7 @@ static ssize_t show_dev_ref_cnt(struct d
 	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);
 

Modified: head/sys/ofed/include/linux/kref.h
==============================================================================
--- head/sys/ofed/include/linux/kref.h	Mon Oct 19 12:08:06 2015	(r289577)
+++ head/sys/ofed/include/linux/kref.h	Mon Oct 19 12:26:38 2015	(r289578)
@@ -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_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201510191226.t9JCQdL2078620>