10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*12574SWilliam.Taylor@Oracle.COM * Common Development and Distribution License (the "License").
6*12574SWilliam.Taylor@Oracle.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*12574SWilliam.Taylor@Oracle.COM * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate #include <sys/ib/ibtl/impl/ibtl.h>
260Sstevel@tonic-gate
270Sstevel@tonic-gate /*
280Sstevel@tonic-gate * ibtl_srq.c
290Sstevel@tonic-gate * These routines implement (most of) the verbs related to
300Sstevel@tonic-gate * Shared Receive Queues.
310Sstevel@tonic-gate */
320Sstevel@tonic-gate
330Sstevel@tonic-gate /*
340Sstevel@tonic-gate * Globals
350Sstevel@tonic-gate */
360Sstevel@tonic-gate
370Sstevel@tonic-gate static char ibtf_srq[] = "ibtl_srq";
380Sstevel@tonic-gate
390Sstevel@tonic-gate /*
400Sstevel@tonic-gate * This file contains code for the TI SRQ calls
410Sstevel@tonic-gate */
420Sstevel@tonic-gate
430Sstevel@tonic-gate /*
440Sstevel@tonic-gate *
450Sstevel@tonic-gate * ibt_alloc_srq() - Allocate a completion queue
460Sstevel@tonic-gate */
470Sstevel@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)480Sstevel@tonic-gate ibt_alloc_srq(ibt_hca_hdl_t hca_hdl, ibt_srq_flags_t flags, ibt_pd_hdl_t pd,
490Sstevel@tonic-gate ibt_srq_sizes_t *srq_sizes, ibt_srq_hdl_t *ibt_srq_p,
500Sstevel@tonic-gate ibt_srq_sizes_t *real_sizes_p)
510Sstevel@tonic-gate {
520Sstevel@tonic-gate ibt_status_t status;
530Sstevel@tonic-gate ibt_srq_hdl_t ibt_srq;
540Sstevel@tonic-gate
550Sstevel@tonic-gate IBTF_DPRINTF_L3(ibtf_srq, "ibt_alloc_srq(%p, %p)",
560Sstevel@tonic-gate hca_hdl, srq_sizes);
570Sstevel@tonic-gate
580Sstevel@tonic-gate ibt_srq = kmem_zalloc(sizeof (struct ibtl_srq_s), KM_SLEEP);
590Sstevel@tonic-gate *ibt_srq_p = ibt_srq;
600Sstevel@tonic-gate
610Sstevel@tonic-gate _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(ibt_srq->srq_ibc_srq_hdl))
620Sstevel@tonic-gate _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(ibt_srq->srq_hca))
630Sstevel@tonic-gate /*
640Sstevel@tonic-gate * Set the following values before creating CI SRQ, to avoid race
650Sstevel@tonic-gate * conditions on async callback.
660Sstevel@tonic-gate */
670Sstevel@tonic-gate ibt_srq->srq_hca = hca_hdl;
680Sstevel@tonic-gate
690Sstevel@tonic-gate status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_alloc_srq(
700Sstevel@tonic-gate IBTL_HCA2CIHCA(hca_hdl), flags, ibt_srq, pd, srq_sizes,
710Sstevel@tonic-gate &ibt_srq->srq_ibc_srq_hdl, real_sizes_p);
720Sstevel@tonic-gate
730Sstevel@tonic-gate if (status != IBT_SUCCESS) {
740Sstevel@tonic-gate IBTF_DPRINTF_L2(ibtf_srq, "ibt_alloc_srq: "
750Sstevel@tonic-gate "CI SRQ handle allocation failed: status = %d", status);
760Sstevel@tonic-gate kmem_free(ibt_srq, sizeof (struct ibtl_srq_s));
770Sstevel@tonic-gate *ibt_srq_p = NULL;
780Sstevel@tonic-gate return (status);
790Sstevel@tonic-gate }
800Sstevel@tonic-gate
810Sstevel@tonic-gate _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(ibt_srq->srq_ibc_srq_hdl))
820Sstevel@tonic-gate _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(ibt_srq->srq_hca))
830Sstevel@tonic-gate
840Sstevel@tonic-gate /* Update the srq resource count */
85*12574SWilliam.Taylor@Oracle.COM atomic_inc_32(&hca_hdl->ha_srq_cnt);
860Sstevel@tonic-gate
870Sstevel@tonic-gate return (IBT_SUCCESS);
880Sstevel@tonic-gate }
890Sstevel@tonic-gate
900Sstevel@tonic-gate
910Sstevel@tonic-gate /*
920Sstevel@tonic-gate * ibt_free_srq() - Free a shared receive queue
930Sstevel@tonic-gate *
940Sstevel@tonic-gate */
950Sstevel@tonic-gate ibt_status_t
ibt_free_srq(ibt_srq_hdl_t ibt_srq)960Sstevel@tonic-gate ibt_free_srq(ibt_srq_hdl_t ibt_srq)
970Sstevel@tonic-gate {
980Sstevel@tonic-gate ibt_status_t status;
990Sstevel@tonic-gate ibtl_hca_t *ibt_hca = ibt_srq->srq_hca;
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate IBTF_DPRINTF_L3(ibtf_srq, "ibt_free_srq(%p)", ibt_srq);
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate status = ((IBTL_SRQ2CIHCAOPS_P(ibt_srq))->ibc_free_srq)
1040Sstevel@tonic-gate (IBTL_SRQ2CIHCA(ibt_srq), ibt_srq->srq_ibc_srq_hdl);
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate if (status != IBT_SUCCESS) {
1070Sstevel@tonic-gate IBTF_DPRINTF_L2(ibtf_srq, "ibt_free_srq: "
1080Sstevel@tonic-gate "CI SRQ handle de-allocation failed: status = %d", status);
1090Sstevel@tonic-gate return (status);
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate ibtl_free_srq_async_check(ibt_srq);
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate /* Update the srq resource count */
115*12574SWilliam.Taylor@Oracle.COM atomic_dec_32(&ibt_hca->ha_srq_cnt);
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate return (status);
1180Sstevel@tonic-gate }
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate /*
1220Sstevel@tonic-gate * ibt_query_srq() - Returns the size of the srq
1230Sstevel@tonic-gate */
1240Sstevel@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)1250Sstevel@tonic-gate ibt_query_srq(ibt_srq_hdl_t ibt_srq, ibt_pd_hdl_t *pd_p,
1260Sstevel@tonic-gate ibt_srq_sizes_t *sizes_p, uint_t *limit)
1270Sstevel@tonic-gate {
1280Sstevel@tonic-gate IBTF_DPRINTF_L3(ibtf_srq, "ibt_query_srq(%p)", ibt_srq);
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate return (IBTL_SRQ2CIHCAOPS_P(ibt_srq)->ibc_query_srq(
1310Sstevel@tonic-gate IBTL_SRQ2CIHCA(ibt_srq), ibt_srq->srq_ibc_srq_hdl, pd_p,
1320Sstevel@tonic-gate sizes_p, limit));
1330Sstevel@tonic-gate }
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate /*
1370Sstevel@tonic-gate * ibt_resize_srq() - Change the size of a srq.
1380Sstevel@tonic-gate */
1390Sstevel@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)1400Sstevel@tonic-gate ibt_modify_srq(ibt_srq_hdl_t ibt_srq, ibt_srq_modify_flags_t flags,
1410Sstevel@tonic-gate uint_t size, uint_t limit, uint_t *real_size_p)
1420Sstevel@tonic-gate {
1430Sstevel@tonic-gate IBTF_DPRINTF_L3(ibtf_srq, "ibt_modify_srq(%p, %d, %d, %d)",
1440Sstevel@tonic-gate ibt_srq, flags, size, limit);
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate return (IBTL_SRQ2CIHCAOPS_P(ibt_srq)->ibc_modify_srq(
1470Sstevel@tonic-gate IBTL_SRQ2CIHCA(ibt_srq), ibt_srq->srq_ibc_srq_hdl,
1480Sstevel@tonic-gate flags, size, limit, real_size_p));
1490Sstevel@tonic-gate }
1500Sstevel@tonic-gate
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("client managed", ibtl_srq_s::srq_clnt_private))
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate /*
1550Sstevel@tonic-gate * ibt_set_srq_private - Sets the private data on a given SRQ
1560Sstevel@tonic-gate *
1570Sstevel@tonic-gate * ibt_srq The ibt_srq_hdl_t of the allocated SRQ.
1580Sstevel@tonic-gate * clnt_private The client private data.
1590Sstevel@tonic-gate */
1600Sstevel@tonic-gate void
ibt_set_srq_private(ibt_srq_hdl_t ibt_srq,void * clnt_private)1610Sstevel@tonic-gate ibt_set_srq_private(ibt_srq_hdl_t ibt_srq, void *clnt_private)
1620Sstevel@tonic-gate {
1630Sstevel@tonic-gate ibt_srq->srq_clnt_private = clnt_private;
1640Sstevel@tonic-gate }
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate
1670Sstevel@tonic-gate /*
1680Sstevel@tonic-gate * ibt_get_srq_private - Retrieves the private data for a given SRQ
1690Sstevel@tonic-gate *
1700Sstevel@tonic-gate * ibt_srq The ibt_srq_hdl_t of the allocated SRQ.
1710Sstevel@tonic-gate */
1720Sstevel@tonic-gate void *
ibt_get_srq_private(ibt_srq_hdl_t ibt_srq)1730Sstevel@tonic-gate ibt_get_srq_private(ibt_srq_hdl_t ibt_srq)
1740Sstevel@tonic-gate {
1750Sstevel@tonic-gate return (ibt_srq->srq_clnt_private);
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate
1780Sstevel@tonic-gate /*
1790Sstevel@tonic-gate * Function:
1800Sstevel@tonic-gate * ibt_post_srq
1810Sstevel@tonic-gate * Input:
1820Sstevel@tonic-gate * srq - SRQ.
1830Sstevel@tonic-gate * wr_list - Address of array[size] of work requests.
1840Sstevel@tonic-gate * size - Number of work requests.
1850Sstevel@tonic-gate * Output:
1860Sstevel@tonic-gate * posted - Address to return the number of work requests
1870Sstevel@tonic-gate * successfully posted. May be NULL.
1880Sstevel@tonic-gate * Description:
1890Sstevel@tonic-gate * Post one or more receive work requests to the SRQ.
1900Sstevel@tonic-gate */
1910Sstevel@tonic-gate
1920Sstevel@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)1930Sstevel@tonic-gate ibt_post_srq(ibt_srq_hdl_t srq, ibt_recv_wr_t *wr_list, uint_t size,
1940Sstevel@tonic-gate uint_t *posted)
1950Sstevel@tonic-gate {
1960Sstevel@tonic-gate IBTF_DPRINTF_L4(ibtf_srq, "ibt_post_srq(%p, %p, %d)",
1970Sstevel@tonic-gate srq, wr_list, size);
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate return (IBTL_SRQ2CIHCAOPS_P(srq)->ibc_post_srq(IBTL_SRQ2CIHCA(srq),
2000Sstevel@tonic-gate srq->srq_ibc_srq_hdl, wr_list, size, posted));
2010Sstevel@tonic-gate }
202