From owner-svn-src-head@freebsd.org Mon Oct 19 12:26:40 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 97B1CA18703; Mon, 19 Oct 2015 12:26:40 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 562D7164; Mon, 19 Oct 2015 12:26:40 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t9JCQdIP078624; Mon, 19 Oct 2015 12:26:39 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t9JCQdL2078620; Mon, 19 Oct 2015 12:26:39 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201510191226.t9JCQdL2078620@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 19 Oct 2015 12:26:39 +0000 (UTC) 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 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Oct 2015 12:26:40 -0000 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 #include +#include + 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_ */