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 2005 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_evd_resize.c
2N/A *
2N/A * PURPOSE: EVENT management
2N/A *
2N/A * Description: Interfaces in this file are completely defined in
2N/A * the uDAPL 1.1 API, Chapter 6, section 3
2N/A *
2N/A * $Id: dapl_evd_resize.c,v 1.4 2003/06/16 17:53:32 sjs2 Exp $
2N/A */
2N/A
2N/A#include "dapl_evd_util.h"
2N/A#include "dapl_ring_buffer_util.h"
2N/A#include "dapl_adapter_util.h"
2N/A#include "dapl.h"
2N/A
2N/A#define DAPL_MIN_RESZ_QLEN 4096
2N/A
2N/A/*
2N/A * dapl_evd_resize
2N/A *
2N/A * DAPL Requirements Version xxx, 6.3.2.5
2N/A *
2N/A * Modify the size fo the event queue of an Event Dispatcher
2N/A *
2N/A * Input:
2N/A * evd_handle
2N/A * evd_qlen
2N/A *
2N/A * Output:
2N/A * none
2N/A *
2N/A * Returns:
2N/A * DAT_SUCCESS
2N/A * DAT_INVALID_PARAMETER
2N/A * DAT_INSUFFICIENT_RESOURCES
2N/A * DAT_INVALID_STATE
2N/A */
2N/A
2N/ADAT_RETURN dapl_evd_resize(
2N/A IN DAT_EVD_HANDLE evd_handle,
2N/A IN DAT_COUNT req_evd_qlen)
2N/A{
2N/A int i;
2N/A DAPL_EVD *evd_ptr;
2N/A DAT_EVENT *event_ptr;
2N/A DAT_EVENT *eventp;
2N/A DAT_EVENT *event;
2N/A DAT_EVENT *new_event;
2N/A DAPL_RING_BUFFER free_event_queue;
2N/A DAPL_RING_BUFFER pending_event_queue;
2N/A DAT_RETURN dat_status;
2N/A DAT_COUNT max_evd_qlen;
2N/A DAT_COUNT evd_qlen;
2N/A
2N/A evd_ptr = (DAPL_EVD *)evd_handle;
2N/A dat_status = DAT_SUCCESS;
2N/A
2N/A if (DAPL_BAD_HANDLE(evd_handle, DAPL_MAGIC_EVD)) {
2N/A return (DAT_ERROR(DAT_INVALID_HANDLE, 0));
2N/A }
2N/A
2N/A if (req_evd_qlen < evd_ptr->qlen) {
2N/A return (DAT_ERROR(DAT_INVALID_STATE, 0));
2N/A }
2N/A
2N/A if (req_evd_qlen == evd_ptr->qlen) {
2N/A return (DAT_SUCCESS);
2N/A }
2N/A
2N/A max_evd_qlen = evd_ptr->header.owner_ia->hca_ptr->ia_attr.max_evd_qlen;
2N/A if (req_evd_qlen > max_evd_qlen) {
2N/A return (DAT_ERROR(DAT_INVALID_STATE, 0));
2N/A }
2N/A
2N/A evd_qlen = DAPL_MIN_RESZ_QLEN;
2N/A while (req_evd_qlen > evd_qlen) {
2N/A evd_qlen <<= 1;
2N/A if (evd_qlen > max_evd_qlen)
2N/A evd_qlen = max_evd_qlen;
2N/A }
2N/A
2N/A /* Allocate EVENTs */
2N/A event_ptr = (DAT_EVENT *) dapl_os_alloc(evd_qlen * sizeof (DAT_EVENT));
2N/A if (!event_ptr) {
2N/A return (DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
2N/A DAT_RESOURCE_MEMORY));
2N/A }
2N/A
2N/A /* allocate free event queue */
2N/A dat_status = dapls_rbuf_alloc(&free_event_queue, evd_qlen);
2N/A if (dat_status != DAT_SUCCESS) {
2N/A goto bail;
2N/A }
2N/A
2N/A /* allocate pending event queue */
2N/A dat_status = dapls_rbuf_alloc(&pending_event_queue, evd_qlen);
2N/A if (dat_status != DAT_SUCCESS) {
2N/A goto bail;
2N/A }
2N/A
2N/A /* need to resize the cq only for DTO/BIND evds */
2N/A if (0 != (evd_ptr->evd_flags & ~ (DAT_EVD_SOFTWARE_FLAG |
2N/A DAT_EVD_CONNECTION_FLAG | DAT_EVD_CR_FLAG))) {
2N/A dat_status = dapls_ib_cq_resize(evd_ptr, evd_qlen);
2N/A if (dat_status != DAT_SUCCESS)
2N/A goto bail;
2N/A }
2N/A
2N/A /* add events to free event queue */
2N/A for (i = 0, eventp = event_ptr; i < evd_qlen; i++) {
2N/A (void) dapls_rbuf_add(&free_event_queue, (void *)eventp);
2N/A eventp++;
2N/A }
2N/A /*
2N/A * copy pending events from evd to the new pending event queue
2N/A */
2N/A while (event = (DAT_EVENT *)
2N/A dapls_rbuf_remove(&evd_ptr->pending_event_queue)) {
2N/A new_event = (DAT_EVENT *) dapls_rbuf_remove(&free_event_queue);
2N/A dapl_os_assert(new_event);
2N/A (void) dapl_os_memcpy(new_event, event, sizeof (DAT_EVENT));
2N/A dat_status = dapls_rbuf_add(&pending_event_queue, new_event);
2N/A dapl_os_assert(dat_status == DAT_SUCCESS);
2N/A dat_status = dapls_rbuf_add(&evd_ptr->free_event_queue, event);
2N/A dapl_os_assert(dat_status == DAT_SUCCESS);
2N/A }
2N/A
2N/A dapls_rbuf_destroy(&evd_ptr->free_event_queue);
2N/A dapls_rbuf_destroy(&evd_ptr->pending_event_queue);
2N/A if (evd_ptr->events) {
2N/A dapl_os_free(evd_ptr->events,
2N/A evd_ptr->qlen * sizeof (DAT_EVENT));
2N/A }
2N/A evd_ptr->events = event_ptr;
2N/A evd_ptr->free_event_queue = free_event_queue;
2N/A evd_ptr->pending_event_queue = pending_event_queue;
2N/A evd_ptr->qlen = evd_qlen;
2N/A
2N/A return (DAT_SUCCESS);
2N/Abail:
2N/A /*
2N/A * If we are here means event_ptr was allocd but something else
2N/A * failed
2N/A */
2N/A dapl_os_free(event_ptr, evd_qlen * sizeof (DAT_EVENT));
2N/A dapls_rbuf_destroy(&free_event_queue);
2N/A dapls_rbuf_destroy(&pending_event_queue);
2N/A
2N/A return (dat_status);
2N/A}