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
503494a98SBill Taylor * Common Development and Distribution License (the "License").
603494a98SBill 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 /*
22f7327bbdSBill 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_cq.c
297c478bd9Sstevel@tonic-gate * These routines implement (most of) the verbs related to
307c478bd9Sstevel@tonic-gate * Completion 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_cq[] = "ibtl_cq";
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate * This file contains code for the TI CQ calls
417c478bd9Sstevel@tonic-gate */
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate * ibt_alloc_cq_sched() - Reserve CQ scheduling class resources
457c478bd9Sstevel@tonic-gate *
467c478bd9Sstevel@tonic-gate * chan - IBT Channel Handle.
477c478bd9Sstevel@tonic-gate * load - Expected CQ load in class, 0 = unspecified
487c478bd9Sstevel@tonic-gate * sched_hdl_p - Returned scheduling handle.
497c478bd9Sstevel@tonic-gate */
507c478bd9Sstevel@tonic-gate ibt_status_t
ibt_alloc_cq_sched(ibt_hca_hdl_t hca_hdl,ibt_cq_sched_attr_t * attr,ibt_sched_hdl_t * sched_hdl_p)517c478bd9Sstevel@tonic-gate ibt_alloc_cq_sched(ibt_hca_hdl_t hca_hdl, ibt_cq_sched_attr_t *attr,
527c478bd9Sstevel@tonic-gate ibt_sched_hdl_t *sched_hdl_p)
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L3(ibtf_cq, "ibt_alloc_cq_sched(%p, %p, %p)",
557c478bd9Sstevel@tonic-gate hca_hdl, attr, sched_hdl_p);
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate return (IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_alloc_cq_sched(
58*17a2b317SBill Taylor IBTL_HCA2CIHCA(hca_hdl), attr, sched_hdl_p));
597c478bd9Sstevel@tonic-gate }
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate * ibt_free_cq_sched() - Free CQ scheduling class resources
647c478bd9Sstevel@tonic-gate *
657c478bd9Sstevel@tonic-gate * chan - IBT Channel Handle.
667c478bd9Sstevel@tonic-gate * sched_hdl - Scheduling handle returned from ibt_alloc_cq_sched.
677c478bd9Sstevel@tonic-gate * load - CQ load being removed.
687c478bd9Sstevel@tonic-gate */
697c478bd9Sstevel@tonic-gate ibt_status_t
ibt_free_cq_sched(ibt_hca_hdl_t hca_hdl,ibt_sched_hdl_t sched_hdl)70*17a2b317SBill Taylor ibt_free_cq_sched(ibt_hca_hdl_t hca_hdl, ibt_sched_hdl_t sched_hdl)
717c478bd9Sstevel@tonic-gate {
72*17a2b317SBill Taylor IBTF_DPRINTF_L3(ibtf_cq, "ibt_free_cq_sched(%p, %p)",
73*17a2b317SBill Taylor hca_hdl, sched_hdl);
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate return (IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_free_cq_sched(
76*17a2b317SBill Taylor IBTL_HCA2CIHCA(hca_hdl), sched_hdl));
777c478bd9Sstevel@tonic-gate }
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate /*
817c478bd9Sstevel@tonic-gate *
827c478bd9Sstevel@tonic-gate * ibt_alloc_cq() - Allocate a completion queue
837c478bd9Sstevel@tonic-gate */
847c478bd9Sstevel@tonic-gate ibt_status_t
ibt_alloc_cq(ibt_hca_hdl_t hca_hdl,ibt_cq_attr_t * cq_attr,ibt_cq_hdl_t * ibt_cq_p,uint32_t * real_size)857c478bd9Sstevel@tonic-gate ibt_alloc_cq(ibt_hca_hdl_t hca_hdl, ibt_cq_attr_t *cq_attr,
867c478bd9Sstevel@tonic-gate ibt_cq_hdl_t *ibt_cq_p, uint32_t *real_size)
877c478bd9Sstevel@tonic-gate {
887c478bd9Sstevel@tonic-gate ibt_status_t status;
897c478bd9Sstevel@tonic-gate ibt_cq_hdl_t ibt_cq;
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L3(ibtf_cq, "ibt_alloc_cq(%p, %p)",
927c478bd9Sstevel@tonic-gate hca_hdl, cq_attr);
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate ibt_cq = kmem_zalloc(sizeof (struct ibtl_cq_s), KM_SLEEP);
967c478bd9Sstevel@tonic-gate *ibt_cq_p = ibt_cq;
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(ibt_cq->cq_in_thread))
997c478bd9Sstevel@tonic-gate _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(ibt_cq->cq_ibc_cq_hdl))
1007c478bd9Sstevel@tonic-gate _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(ibt_cq->cq_hca))
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate * Set the following values before creating CI CQ, to avoid race
1037c478bd9Sstevel@tonic-gate * conditions on async callback.
1047c478bd9Sstevel@tonic-gate */
1057c478bd9Sstevel@tonic-gate ibt_cq->cq_hca = hca_hdl;
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate ibtl_qp_flow_control_enter();
1087c478bd9Sstevel@tonic-gate status = IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_alloc_cq(
1097c478bd9Sstevel@tonic-gate IBTL_HCA2CIHCA(hca_hdl), ibt_cq, cq_attr, &ibt_cq->cq_ibc_cq_hdl,
1107c478bd9Sstevel@tonic-gate real_size);
1117c478bd9Sstevel@tonic-gate ibtl_qp_flow_control_exit();
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate if (status != IBT_SUCCESS) {
1147c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2(ibtf_cq, "ibt_alloc_cq: "
1157c478bd9Sstevel@tonic-gate "CI CQ handle allocation failed: status = %d", status);
1167c478bd9Sstevel@tonic-gate kmem_free(ibt_cq, sizeof (struct ibtl_cq_s));
1177c478bd9Sstevel@tonic-gate *ibt_cq_p = NULL;
1187c478bd9Sstevel@tonic-gate return (status);
1197c478bd9Sstevel@tonic-gate }
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate if (cq_attr->cq_flags & IBT_CQ_HANDLER_IN_THREAD) {
1227c478bd9Sstevel@tonic-gate ibt_cq->cq_in_thread = 1;
1237c478bd9Sstevel@tonic-gate /* We may want additional CQ threads now. */
1247c478bd9Sstevel@tonic-gate ibtl_another_cq_handler_in_thread();
1257c478bd9Sstevel@tonic-gate }
1267c478bd9Sstevel@tonic-gate _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(ibt_cq->cq_in_thread))
1277c478bd9Sstevel@tonic-gate _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(ibt_cq->cq_ibc_cq_hdl))
1287c478bd9Sstevel@tonic-gate _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(ibt_cq->cq_hca))
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate mutex_init(&ibt_cq->cq_mutex, NULL, MUTEX_DEFAULT, NULL);
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate /* Update the cq resource count */
133f7327bbdSBill Taylor atomic_inc_32(&hca_hdl->ha_cq_cnt);
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate return (IBT_SUCCESS);
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate /*
1407c478bd9Sstevel@tonic-gate * ibt_free_cq() - Free a completion queue
1417c478bd9Sstevel@tonic-gate *
1427c478bd9Sstevel@tonic-gate */
1437c478bd9Sstevel@tonic-gate ibt_status_t
ibt_free_cq(ibt_cq_hdl_t ibt_cq)1447c478bd9Sstevel@tonic-gate ibt_free_cq(ibt_cq_hdl_t ibt_cq)
1457c478bd9Sstevel@tonic-gate {
1467c478bd9Sstevel@tonic-gate ibt_status_t status;
1477c478bd9Sstevel@tonic-gate ibtl_hca_t *ibt_hca = ibt_cq->cq_hca;
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L3(ibtf_cq, "ibt_free_cq(%p)", ibt_cq);
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate ibtl_free_cq_check(ibt_cq);
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate status = ((IBTL_CQ2CIHCAOPS_P(ibt_cq))->ibc_free_cq)
1547c478bd9Sstevel@tonic-gate (IBTL_CQ2CIHCA(ibt_cq), ibt_cq->cq_ibc_cq_hdl);
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate if (status != IBT_SUCCESS) {
1577c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2(ibtf_cq, "ibt_free_cq: "
1587c478bd9Sstevel@tonic-gate "CI CQ handle de-allocation failed: status = %d", status);
1597c478bd9Sstevel@tonic-gate return (status);
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate /* mutex_destroy(&ibt_cq->cq_mutex); */
1637c478bd9Sstevel@tonic-gate ibtl_free_cq_async_check(ibt_cq);
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate /* Update the cq resource count */
166f7327bbdSBill Taylor atomic_dec_32(&ibt_hca->ha_cq_cnt);
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate return (status);
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate /*
1737c478bd9Sstevel@tonic-gate * ibt_query_cq() - Returns the size of the cq
1747c478bd9Sstevel@tonic-gate */
1757c478bd9Sstevel@tonic-gate ibt_status_t
ibt_query_cq(ibt_cq_hdl_t ibt_cq,uint32_t * entries_p,uint_t * count_p,uint_t * usec_p,ibt_cq_handler_id_t * hid_p)17603494a98SBill Taylor ibt_query_cq(ibt_cq_hdl_t ibt_cq, uint32_t *entries_p, uint_t *count_p,
17703494a98SBill Taylor uint_t *usec_p, ibt_cq_handler_id_t *hid_p)
1787c478bd9Sstevel@tonic-gate {
1797c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L3(ibtf_cq, "ibt_query_cq(%p)", ibt_cq);
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate return (IBTL_CQ2CIHCAOPS_P(ibt_cq)->ibc_query_cq(IBTL_CQ2CIHCA(ibt_cq),
18203494a98SBill Taylor ibt_cq->cq_ibc_cq_hdl, entries_p, count_p, usec_p, hid_p));
1837c478bd9Sstevel@tonic-gate }
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate /*
1877c478bd9Sstevel@tonic-gate * ibt_resize_cq() - Change the size of a cq.
1887c478bd9Sstevel@tonic-gate */
1897c478bd9Sstevel@tonic-gate ibt_status_t
ibt_resize_cq(ibt_cq_hdl_t ibt_cq,uint32_t new_sz,uint32_t * real_sz)1907c478bd9Sstevel@tonic-gate ibt_resize_cq(ibt_cq_hdl_t ibt_cq, uint32_t new_sz, uint32_t *real_sz)
1917c478bd9Sstevel@tonic-gate {
1927c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L3(ibtf_cq, "ibt_resize_cq(%p, %d)", ibt_cq, new_sz);
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate return (IBTL_CQ2CIHCAOPS_P(ibt_cq)->ibc_resize_cq(IBTL_CQ2CIHCA(ibt_cq),
1957c478bd9Sstevel@tonic-gate ibt_cq->cq_ibc_cq_hdl, new_sz, real_sz));
1967c478bd9Sstevel@tonic-gate }
1977c478bd9Sstevel@tonic-gate
19803494a98SBill Taylor ibt_status_t
ibt_modify_cq(ibt_cq_hdl_t ibt_cq,uint_t count,uint_t usec,ibt_cq_handler_id_t hid)19903494a98SBill Taylor ibt_modify_cq(ibt_cq_hdl_t ibt_cq, uint_t count, uint_t usec,
20003494a98SBill Taylor ibt_cq_handler_id_t hid)
20103494a98SBill Taylor {
20203494a98SBill Taylor IBTF_DPRINTF_L3(ibtf_cq, "ibt_modify_cq(%p, %d, %d, %d)", ibt_cq, count,
20303494a98SBill Taylor usec, hid);
20403494a98SBill Taylor
20503494a98SBill Taylor return (IBTL_CQ2CIHCAOPS_P(ibt_cq)->ibc_modify_cq(IBTL_CQ2CIHCA(ibt_cq),
20603494a98SBill Taylor ibt_cq->cq_ibc_cq_hdl, count, usec, hid));
20703494a98SBill Taylor }
20803494a98SBill Taylor
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate /*
2117c478bd9Sstevel@tonic-gate * ibt_poll_cq()
2127c478bd9Sstevel@tonic-gate * Poll the specified CQ for a work request (WR) completion. If a CQ
2137c478bd9Sstevel@tonic-gate * contains a completed WR, the completed WR at the head of the CQ is
2147c478bd9Sstevel@tonic-gate * returned.
2157c478bd9Sstevel@tonic-gate *
2167c478bd9Sstevel@tonic-gate * ibt_cq The CQ handle.
2177c478bd9Sstevel@tonic-gate *
2187c478bd9Sstevel@tonic-gate * work_completions An array of work completions.
2197c478bd9Sstevel@tonic-gate *
2207c478bd9Sstevel@tonic-gate * num_wc Size of the Work completion array. The
2217c478bd9Sstevel@tonic-gate * requested number of completions.
2227c478bd9Sstevel@tonic-gate *
2237c478bd9Sstevel@tonic-gate * num_polled The actual number of completions returned.
2247c478bd9Sstevel@tonic-gate *
2257c478bd9Sstevel@tonic-gate */
2267c478bd9Sstevel@tonic-gate ibt_status_t
ibt_poll_cq(ibt_cq_hdl_t ibt_cq,ibt_wc_t * work_completions,uint_t num_wc,uint_t * num_polled)2277c478bd9Sstevel@tonic-gate ibt_poll_cq(ibt_cq_hdl_t ibt_cq, ibt_wc_t *work_completions, uint_t num_wc,
2287c478bd9Sstevel@tonic-gate uint_t *num_polled)
2297c478bd9Sstevel@tonic-gate {
2307c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4(ibtf_cq, "ibt_poll_cq(%p)", ibt_cq);
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate return (IBTL_CQ2CIHCAOPS_P(ibt_cq)->ibc_poll_cq(IBTL_CQ2CIHCA(ibt_cq),
2337c478bd9Sstevel@tonic-gate ibt_cq->cq_ibc_cq_hdl, work_completions, num_wc, num_polled));
2347c478bd9Sstevel@tonic-gate }
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("client managed", ibtl_cq_s::cq_clnt_private))
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate /*
2397c478bd9Sstevel@tonic-gate * ibt_set_cq_private - Sets the private data on a given CQ
2407c478bd9Sstevel@tonic-gate *
2417c478bd9Sstevel@tonic-gate * ibt_cq The ibt_cq_hdl_t of the allocated CQ.
2427c478bd9Sstevel@tonic-gate * clnt_private The client private data.
2437c478bd9Sstevel@tonic-gate */
2447c478bd9Sstevel@tonic-gate void
ibt_set_cq_private(ibt_cq_hdl_t ibt_cq,void * clnt_private)2457c478bd9Sstevel@tonic-gate ibt_set_cq_private(ibt_cq_hdl_t ibt_cq, void *clnt_private)
2467c478bd9Sstevel@tonic-gate {
2477c478bd9Sstevel@tonic-gate ibt_cq->cq_clnt_private = clnt_private;
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate
2517c478bd9Sstevel@tonic-gate /*
2527c478bd9Sstevel@tonic-gate * ibt_get_cq_private - Retrieves the private data for a given CQ
2537c478bd9Sstevel@tonic-gate *
2547c478bd9Sstevel@tonic-gate * ibt_cq The ibt_cq_hdl_t of the allocated CQ.
2557c478bd9Sstevel@tonic-gate */
2567c478bd9Sstevel@tonic-gate void *
ibt_get_cq_private(ibt_cq_hdl_t ibt_cq)2577c478bd9Sstevel@tonic-gate ibt_get_cq_private(ibt_cq_hdl_t ibt_cq)
2587c478bd9Sstevel@tonic-gate {
2597c478bd9Sstevel@tonic-gate return (ibt_cq->cq_clnt_private);
2607c478bd9Sstevel@tonic-gate }
261*17a2b317SBill Taylor
262*17a2b317SBill Taylor /*
263*17a2b317SBill Taylor * ibt_query_cq_handler_id - Retrieves the attributes of a cq_handler_id.
264*17a2b317SBill Taylor */
265*17a2b317SBill Taylor ibt_status_t
ibt_query_cq_handler_id(ibt_hca_hdl_t hca_hdl,ibt_cq_handler_id_t hid,ibt_cq_handler_attr_t * attrs)266*17a2b317SBill Taylor ibt_query_cq_handler_id(ibt_hca_hdl_t hca_hdl,
267*17a2b317SBill Taylor ibt_cq_handler_id_t hid, ibt_cq_handler_attr_t *attrs)
268*17a2b317SBill Taylor {
269*17a2b317SBill Taylor IBTF_DPRINTF_L3(ibtf_cq, "ibt_query_cq_handler(%p, %d, %p)",
270*17a2b317SBill Taylor hca_hdl, hid, attrs);
271*17a2b317SBill Taylor
272*17a2b317SBill Taylor return (IBTL_HCA2CIHCAOPS_P(hca_hdl)->ibc_query_cq_handler_id(
273*17a2b317SBill Taylor IBTL_HCA2CIHCA(hca_hdl), hid, attrs));
274*17a2b317SBill Taylor }
275