xref: /illumos-gate/usr/src/uts/common/io/ib/ibtl/ibtl_srq.c (revision f7327bbd)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*f7327bbdSBill Taylor  * Common Development and Distribution License (the "License").
6*f7327bbdSBill Taylor  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*f7327bbdSBill Taylor  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #include <sys/ib/ibtl/impl/ibtl.h>
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * ibtl_srq.c
297c478bd9Sstevel@tonic-gate  *	These routines implement (most of) the verbs related to
307c478bd9Sstevel@tonic-gate  *	Shared Receive Queues.
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * Globals
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate static char ibtf_srq[] = "ibtl_srq";
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * This file contains code for the TI SRQ calls
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  *
457c478bd9Sstevel@tonic-gate  * ibt_alloc_srq() - Allocate a completion queue
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate ibt_status_t
ibt_alloc_srq(ibt_hca_hdl_t hca_hdl,ibt_srq_flags_t flags,ibt_pd_hdl_t pd,ibt_srq_sizes_t * srq_sizes,ibt_srq_hdl_t * ibt_srq_p,ibt_srq_sizes_t * real_sizes_p)487c478bd9Sstevel@tonic-gate ibt_alloc_srq(ibt_hca_hdl_t hca_hdl, ibt_srq_flags_t flags, ibt_pd_hdl_t pd,
497c478bd9Sstevel@tonic-gate     ibt_srq_sizes_t *srq_sizes, ibt_srq_hdl_t *ibt_srq_p,
507c478bd9Sstevel@tonic-gate     ibt_srq_sizes_t *real_sizes_p)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate 	ibt_status_t 		status;
537c478bd9Sstevel@tonic-gate 	ibt_srq_hdl_t		ibt_srq;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_srq, "ibt_alloc_srq(%p, %p)",
567c478bd9Sstevel@tonic-gate 	    hca_hdl, srq_sizes);
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	ibt_srq = kmem_zalloc(sizeof (struct ibtl_srq_s), KM_SLEEP);
597c478bd9Sstevel@tonic-gate 	*ibt_srq_p = ibt_srq;
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate 	_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(ibt_srq->srq_ibc_srq_hdl))
627c478bd9Sstevel@tonic-gate 	_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(ibt_srq->srq_hca))
637c478bd9Sstevel@tonic-gate 	/*
647c478bd9Sstevel@tonic-gate 	 * Set the following values before creating CI SRQ, to avoid race
657c478bd9Sstevel@tonic-gate 	 * conditions on async callback.
667c478bd9Sstevel@tonic-gate 	 */
677c478bd9Sstevel@tonic-gate 	ibt_srq->srq_hca = hca_hdl;
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 	status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_alloc_srq(
707c478bd9Sstevel@tonic-gate 	    IBTL_HCA2CIHCA(hca_hdl), flags, ibt_srq, pd, srq_sizes,
717c478bd9Sstevel@tonic-gate 	    &ibt_srq->srq_ibc_srq_hdl, real_sizes_p);
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	if (status != IBT_SUCCESS) {
747c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_srq, "ibt_alloc_srq: "
757c478bd9Sstevel@tonic-gate 		    "CI SRQ handle allocation failed: status = %d", status);
767c478bd9Sstevel@tonic-gate 		kmem_free(ibt_srq, sizeof (struct ibtl_srq_s));
777c478bd9Sstevel@tonic-gate 		*ibt_srq_p = NULL;
787c478bd9Sstevel@tonic-gate 		return (status);
797c478bd9Sstevel@tonic-gate 	}
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	_NOTE(NOW_VISIBLE_TO_OTHER_THREADS(ibt_srq->srq_ibc_srq_hdl))
827c478bd9Sstevel@tonic-gate 	_NOTE(NOW_VISIBLE_TO_OTHER_THREADS(ibt_srq->srq_hca))
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	/* Update the srq resource count */
85*f7327bbdSBill Taylor 	atomic_inc_32(&hca_hdl->ha_srq_cnt);
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	return (IBT_SUCCESS);
887c478bd9Sstevel@tonic-gate }
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * ibt_free_srq() - Free a shared receive queue
937c478bd9Sstevel@tonic-gate  *
947c478bd9Sstevel@tonic-gate  */
957c478bd9Sstevel@tonic-gate ibt_status_t
ibt_free_srq(ibt_srq_hdl_t ibt_srq)967c478bd9Sstevel@tonic-gate ibt_free_srq(ibt_srq_hdl_t ibt_srq)
977c478bd9Sstevel@tonic-gate {
987c478bd9Sstevel@tonic-gate 	ibt_status_t	status;
997c478bd9Sstevel@tonic-gate 	ibtl_hca_t	*ibt_hca = ibt_srq->srq_hca;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_srq, "ibt_free_srq(%p)", ibt_srq);
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	status = ((IBTL_SRQ2CIHCAOPS_P(ibt_srq))->ibc_free_srq)
1047c478bd9Sstevel@tonic-gate 	    (IBTL_SRQ2CIHCA(ibt_srq), ibt_srq->srq_ibc_srq_hdl);
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	if (status != IBT_SUCCESS) {
1077c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2(ibtf_srq, "ibt_free_srq: "
1087c478bd9Sstevel@tonic-gate 		    "CI SRQ handle de-allocation failed: status = %d", status);
1097c478bd9Sstevel@tonic-gate 		return (status);
1107c478bd9Sstevel@tonic-gate 	}
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	ibtl_free_srq_async_check(ibt_srq);
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 	/* Update the srq resource count */
115*f7327bbdSBill Taylor 	atomic_dec_32(&ibt_hca->ha_srq_cnt);
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	return (status);
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate /*
1227c478bd9Sstevel@tonic-gate  * ibt_query_srq() - Returns the size of the srq
1237c478bd9Sstevel@tonic-gate  */
1247c478bd9Sstevel@tonic-gate ibt_status_t
ibt_query_srq(ibt_srq_hdl_t ibt_srq,ibt_pd_hdl_t * pd_p,ibt_srq_sizes_t * sizes_p,uint_t * limit)1257c478bd9Sstevel@tonic-gate ibt_query_srq(ibt_srq_hdl_t ibt_srq, ibt_pd_hdl_t *pd_p,
1267c478bd9Sstevel@tonic-gate     ibt_srq_sizes_t *sizes_p, uint_t *limit)
1277c478bd9Sstevel@tonic-gate {
1287c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_srq, "ibt_query_srq(%p)", ibt_srq);
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	return (IBTL_SRQ2CIHCAOPS_P(ibt_srq)->ibc_query_srq(
1317c478bd9Sstevel@tonic-gate 	    IBTL_SRQ2CIHCA(ibt_srq), ibt_srq->srq_ibc_srq_hdl, pd_p,
1327c478bd9Sstevel@tonic-gate 	    sizes_p, limit));
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  *  ibt_resize_srq() - Change the size of a srq.
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate ibt_status_t
ibt_modify_srq(ibt_srq_hdl_t ibt_srq,ibt_srq_modify_flags_t flags,uint_t size,uint_t limit,uint_t * real_size_p)1407c478bd9Sstevel@tonic-gate ibt_modify_srq(ibt_srq_hdl_t ibt_srq, ibt_srq_modify_flags_t flags,
1417c478bd9Sstevel@tonic-gate     uint_t size, uint_t limit, uint_t *real_size_p)
1427c478bd9Sstevel@tonic-gate {
1437c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L3(ibtf_srq, "ibt_modify_srq(%p, %d, %d, %d)",
1447c478bd9Sstevel@tonic-gate 	    ibt_srq, flags, size, limit);
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	return (IBTL_SRQ2CIHCAOPS_P(ibt_srq)->ibc_modify_srq(
1477c478bd9Sstevel@tonic-gate 	    IBTL_SRQ2CIHCA(ibt_srq), ibt_srq->srq_ibc_srq_hdl,
1487c478bd9Sstevel@tonic-gate 	    flags, size, limit, real_size_p));
1497c478bd9Sstevel@tonic-gate }
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("client managed", ibtl_srq_s::srq_clnt_private))
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate  * ibt_set_srq_private - Sets the private data on a given SRQ
1567c478bd9Sstevel@tonic-gate  *
1577c478bd9Sstevel@tonic-gate  *      ibt_srq          The ibt_srq_hdl_t of the allocated SRQ.
1587c478bd9Sstevel@tonic-gate  *      clnt_private    The client private data.
1597c478bd9Sstevel@tonic-gate  */
1607c478bd9Sstevel@tonic-gate void
ibt_set_srq_private(ibt_srq_hdl_t ibt_srq,void * clnt_private)1617c478bd9Sstevel@tonic-gate ibt_set_srq_private(ibt_srq_hdl_t ibt_srq, void *clnt_private)
1627c478bd9Sstevel@tonic-gate {
1637c478bd9Sstevel@tonic-gate 	ibt_srq->srq_clnt_private = clnt_private;
1647c478bd9Sstevel@tonic-gate }
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate  * ibt_get_srq_private - Retrieves the private data for a given SRQ
1697c478bd9Sstevel@tonic-gate  *
1707c478bd9Sstevel@tonic-gate  *      ibt_srq          The ibt_srq_hdl_t of the allocated SRQ.
1717c478bd9Sstevel@tonic-gate  */
1727c478bd9Sstevel@tonic-gate void *
ibt_get_srq_private(ibt_srq_hdl_t ibt_srq)1737c478bd9Sstevel@tonic-gate ibt_get_srq_private(ibt_srq_hdl_t ibt_srq)
1747c478bd9Sstevel@tonic-gate {
1757c478bd9Sstevel@tonic-gate 	return (ibt_srq->srq_clnt_private);
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate /*
1797c478bd9Sstevel@tonic-gate  * Function:
1807c478bd9Sstevel@tonic-gate  *	ibt_post_srq
1817c478bd9Sstevel@tonic-gate  * Input:
1827c478bd9Sstevel@tonic-gate  *	srq	- SRQ.
1837c478bd9Sstevel@tonic-gate  *	wr_list	- Address of array[size] of work requests.
1847c478bd9Sstevel@tonic-gate  *	size	- Number of work requests.
1857c478bd9Sstevel@tonic-gate  * Output:
1867c478bd9Sstevel@tonic-gate  *	posted	- Address to return the number of work requests
1877c478bd9Sstevel@tonic-gate  *		  successfully posted.  May be NULL.
1887c478bd9Sstevel@tonic-gate  * Description:
1897c478bd9Sstevel@tonic-gate  *	Post one or more receive work requests to the SRQ.
1907c478bd9Sstevel@tonic-gate  */
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate ibt_status_t
ibt_post_srq(ibt_srq_hdl_t srq,ibt_recv_wr_t * wr_list,uint_t size,uint_t * posted)1937c478bd9Sstevel@tonic-gate ibt_post_srq(ibt_srq_hdl_t srq, ibt_recv_wr_t *wr_list, uint_t size,
1947c478bd9Sstevel@tonic-gate     uint_t *posted)
1957c478bd9Sstevel@tonic-gate {
1967c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4(ibtf_srq, "ibt_post_srq(%p, %p, %d)",
1977c478bd9Sstevel@tonic-gate 	    srq, wr_list, size);
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	return (IBTL_SRQ2CIHCAOPS_P(srq)->ibc_post_srq(IBTL_SRQ2CIHCA(srq),
2007c478bd9Sstevel@tonic-gate 	    srq->srq_ibc_srq_hdl, wr_list, size, posted));
2017c478bd9Sstevel@tonic-gate }
202