2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/*
2N/A *
2N/A * MODULE: dapl_cno_wait.c
2N/A *
2N/A * PURPOSE: Wait for a consumer notification event
2N/A * Description: Interfaces in this file are completely described in
2N/A * the DAPL 1.1 API, Chapter 6, section 3.2.3
2N/A *
2N/A * $Id: dapl_cno_wait.c,v 1.6 2003/06/16 17:53:32 sjs2 Exp $
2N/A */
2N/A
2N/A#include "dapl.h"
2N/A#include "dapl_adapter_util.h"
2N/A#include "dapl_ring_buffer_util.h"
2N/A
2N/A/*
2N/A * dapl_cno_wait
2N/A *
2N/A * DAPL Requirements Version xxx, 6.3.2.3
2N/A *
2N/A * Wait for a consumer notification event
2N/A *
2N/A * Input:
2N/A * cno_handle
2N/A * timeout
2N/A * evd_handle
2N/A *
2N/A * Output:
2N/A * evd_handle
2N/A *
2N/A * Returns:
2N/A * DAT_SUCCESS
2N/A * DAT_INVALID_HANDLE
2N/A * DAT_QUEUE_EMPTY
2N/A * DAT_INVALID_PARAMETER
2N/A */
2N/ADAT_RETURN
2N/Adapl_cno_wait(
2N/A IN DAT_CNO_HANDLE cno_handle, /* cno_handle */
2N/A IN DAT_TIMEOUT timeout, /* agent */
2N/A OUT DAT_EVD_HANDLE *evd_handle) /* evd_handle */
2N/A{
2N/A DAPL_CNO *cno_ptr;
2N/A DAPL_EVD *evd_ptr, *head_evd_ptr;
2N/A DAT_RETURN dat_status;
2N/A int nevents;
2N/A
2N/A if (DAPL_BAD_HANDLE(cno_handle, DAPL_MAGIC_CNO)) {
2N/A dat_status = DAT_INVALID_HANDLE | DAT_INVALID_HANDLE_CNO;
2N/A goto bail;
2N/A }
2N/A
2N/A dat_status = DAT_SUCCESS;
2N/A cno_ptr = (DAPL_CNO *) cno_handle;
2N/A
2N/A if (cno_ptr->cno_state == DAPL_CNO_STATE_DEAD) {
2N/A dat_status = DAT_ERROR(DAT_INVALID_STATE,
2N/A DAT_INVALID_STATE_CNO_DEAD);
2N/A goto bail;
2N/A }
2N/A
2N/A dapl_os_lock(&cno_ptr->header.lock);
2N/A if (dapl_llist_is_empty(&cno_ptr->evd_list_head)) {
2N/A dapl_os_unlock(&cno_ptr->header.lock);
2N/A return (DAT_ERROR(DAT_QUEUE_EMPTY, 0));
2N/A }
2N/A
2N/A /* scan evd list */
2N/A evd_ptr = (DAPL_EVD *)
2N/A dapl_llist_next_entry(&cno_ptr->evd_list_head, NULL);
2N/A
2N/A for (;;) {
2N/A /*
2N/A * Check the evd ring buffer for events, if nothing is found
2N/A * peek into the CQ to see if there are events
2N/A */
2N/A if (dapls_rbuf_count(&evd_ptr->pending_event_queue) > 0) {
2N/A break;
2N/A }
2N/A
2N/A nevents = 0;
2N/A dapls_ib_cq_peek(evd_ptr, &nevents);
2N/A if (nevents > 0) {
2N/A break;
2N/A }
2N/A
2N/A evd_ptr = (DAPL_EVD *)
2N/A dapl_llist_next_entry(&cno_ptr->evd_list_head,
2N/A &evd_ptr->cno_list_entry);
2N/A if (evd_ptr == NULL) {
2N/A break;
2N/A }
2N/A }
2N/A
2N/A /* shift list by one to simulate round-robin */
2N/A head_evd_ptr = (DAPL_EVD *)
2N/A dapl_llist_remove_head(&cno_ptr->evd_list_head);
2N/A dapl_os_assert(head_evd_ptr != NULL);
2N/A dapl_llist_add_tail(&cno_ptr->evd_list_head,
2N/A &head_evd_ptr->cno_list_entry, head_evd_ptr);
2N/A
2N/A if (evd_ptr != NULL) {
2N/A *evd_handle = evd_ptr;
2N/A dapl_os_unlock(&cno_ptr->header.lock);
2N/A return (DAT_SUCCESS);
2N/A }
2N/A
2N/A cno_ptr->cno_waiters++;
2N/A dapl_os_unlock(&cno_ptr->header.lock);
2N/A
2N/A dat_status = dapls_ib_cno_wait(cno_ptr, timeout, &evd_ptr);
2N/A
2N/A dapl_os_lock(&cno_ptr->header.lock);
2N/A cno_ptr->cno_waiters--;
2N/A
2N/A /* verify that evd_ptr is still in the list */
2N/A head_evd_ptr = dapl_llist_next_entry(&cno_ptr->evd_list_head, NULL);
2N/A for (;;) {
2N/A if (head_evd_ptr == NULL || head_evd_ptr == evd_ptr) {
2N/A break;
2N/A }
2N/A head_evd_ptr = (DAPL_EVD *)
2N/A dapl_llist_next_entry(&cno_ptr->evd_list_head,
2N/A &head_evd_ptr->cno_list_entry);
2N/A }
2N/A
2N/A if (cno_ptr->cno_state == DAPL_CNO_STATE_DEAD) {
2N/A dat_status = DAT_ERROR(DAT_INVALID_STATE,
2N/A DAT_INVALID_STATE_CNO_DEAD);
2N/A } else if (dat_status == DAT_SUCCESS) {
2N/A /*
2N/A * After the first triggering, this will be a valid handle.
2N/A * If we're racing with wakeups of other CNO waiters,
2N/A * that's ok.
2N/A */
2N/A if (head_evd_ptr == evd_ptr && evd_ptr != NULL) {
2N/A *evd_handle = evd_ptr;
2N/A } else {
2N/A dat_status = DAT_ERROR(DAT_QUEUE_EMPTY, 0);
2N/A }
2N/A }
2N/A /*
2N/A * The only other reason we could have made it out of
2N/A * the loop is a timeout.
2N/A */
2N/A dapl_os_unlock(&cno_ptr->header.lock);
2N/Abail:
2N/A return (dat_status);
2N/A}