- 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
#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)); \
}
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) {
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);
* 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_ */