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
This commit is contained in:
Hans Petter Selasky 2015-10-19 12:26:38 +00:00
parent 35d974cd0c
commit f556cede8a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=289578
4 changed files with 34 additions and 13 deletions

View 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)); \
}

View 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) {

View 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);

View 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
@ -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_ */