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 2004 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_provider.c
2N/A *
2N/A * PURPOSE: Provider function table
2N/A * Description: DAT Interfaces to this provider
2N/A *
2N/A * $Id: dapl_provider.c,v 1.7 2003/08/08 19:42:54 sjs2 Exp $
2N/A */
2N/A
2N/A#include "dapl_provider.h"
2N/A
2N/A
2N/A/*
2N/A *
2N/A * Global Data
2N/A *
2N/A */
2N/A
2N/ADAPL_PROVIDER_LIST g_dapl_provider_list;
2N/A
2N/A
2N/A/*
2N/A * the function table for this provider
2N/A */
2N/A
2N/ADAT_PROVIDER g_dapl_provider_template =
2N/A{
2N/A NULL,
2N/A 0,
2N/A &dapl_ia_open,
2N/A &dapl_ia_query,
2N/A &dapl_ia_close,
2N/A
2N/A &dapl_set_consumer_context,
2N/A &dapl_get_consumer_context,
2N/A &dapl_get_handle_type,
2N/A
2N/A &dapl_cno_create,
2N/A &dapl_cno_modify_agent,
2N/A &dapl_cno_query,
2N/A &dapl_cno_free,
2N/A &dapl_cno_wait,
2N/A
2N/A &dapl_cr_query,
2N/A &dapl_cr_accept,
2N/A &dapl_cr_reject,
2N/A &dapl_cr_handoff,
2N/A
2N/A &dapl_evd_create,
2N/A &dapl_evd_query,
2N/A &dapl_evd_modify_cno,
2N/A &dapl_evd_enable,
2N/A &dapl_evd_disable,
2N/A &dapl_evd_wait,
2N/A &dapl_evd_resize,
2N/A &dapl_evd_post_se,
2N/A &dapl_evd_dequeue,
2N/A &dapl_evd_free,
2N/A
2N/A &dapl_ep_create,
2N/A &dapl_ep_query,
2N/A &dapl_ep_modify,
2N/A &dapl_ep_connect,
2N/A &dapl_ep_dup_connect,
2N/A &dapl_ep_disconnect,
2N/A &dapl_ep_post_send,
2N/A &dapl_ep_post_recv,
2N/A &dapl_ep_post_rdma_read,
2N/A &dapl_ep_post_rdma_write,
2N/A &dapl_ep_get_status,
2N/A &dapl_ep_free,
2N/A
2N/A &dapl_lmr_create,
2N/A &dapl_lmr_query,
2N/A &dapl_lmr_free,
2N/A
2N/A &dapl_rmr_create,
2N/A &dapl_rmr_query,
2N/A &dapl_rmr_bind,
2N/A &dapl_rmr_free,
2N/A
2N/A &dapl_psp_create,
2N/A &dapl_psp_query,
2N/A &dapl_psp_free,
2N/A
2N/A &dapl_rsp_create,
2N/A &dapl_rsp_query,
2N/A &dapl_rsp_free,
2N/A
2N/A &dapl_pz_create,
2N/A &dapl_pz_query,
2N/A &dapl_pz_free,
2N/A
2N/A &dapl_psp_create_any,
2N/A &dapl_ep_reset,
2N/A &dapl_evd_set_unwaitable,
2N/A &dapl_evd_clear_unwaitable,
2N/A
2N/A &dapl_lmr_sync_rdma_read,
2N/A &dapl_lmr_sync_rdma_write,
2N/A
2N/A &dapl_ep_create_with_srq,
2N/A &dapl_ep_recv_query,
2N/A &dapl_ep_set_watermark,
2N/A
2N/A &dapl_srq_create,
2N/A &dapl_srq_free,
2N/A &dapl_srq_post_recv,
2N/A &dapl_srq_query,
2N/A &dapl_srq_resize,
2N/A &dapl_srq_set_lw
2N/A};
2N/A
2N/A
2N/A
2N/A/*
2N/A *
2N/A * Function Prototypes
2N/A *
2N/A */
2N/A
2N/Astatic DAT_BOOLEAN
2N/Adapl_provider_list_key_cmp(
2N/A const char *name_a,
2N/A const char *name_b);
2N/A
2N/A
2N/A/*
2N/A *
2N/A * Function Definitions
2N/A *
2N/A */
2N/A
2N/ADAT_RETURN
2N/Adapl_provider_list_create(void)
2N/A{
2N/A DAT_RETURN status;
2N/A
2N/A status = DAT_SUCCESS;
2N/A
2N/A /* create the head node */
2N/A g_dapl_provider_list.head = dapl_os_alloc(
2N/A sizeof (DAPL_PROVIDER_LIST_NODE));
2N/A if (NULL == g_dapl_provider_list.head) {
2N/A status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
2N/A DAT_RESOURCE_MEMORY);
2N/A goto bail;
2N/A }
2N/A
2N/A (void) dapl_os_memzero(g_dapl_provider_list.head,
2N/A sizeof (DAPL_PROVIDER_LIST_NODE));
2N/A
2N/A /* create the tail node */
2N/A g_dapl_provider_list.tail = dapl_os_alloc(
2N/A sizeof (DAPL_PROVIDER_LIST_NODE));
2N/A if (NULL == g_dapl_provider_list.tail) {
2N/A status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
2N/A DAT_RESOURCE_MEMORY);
2N/A goto bail;
2N/A }
2N/A
2N/A (void) dapl_os_memzero(g_dapl_provider_list.tail,
2N/A sizeof (DAPL_PROVIDER_LIST_NODE));
2N/A
2N/A g_dapl_provider_list.head->next = g_dapl_provider_list.tail;
2N/A g_dapl_provider_list.tail->prev = g_dapl_provider_list.head;
2N/A g_dapl_provider_list.size = 0;
2N/A
2N/Abail:
2N/A if (DAT_SUCCESS != status) {
2N/A if (NULL != g_dapl_provider_list.head) {
2N/A dapl_os_free(g_dapl_provider_list.head,
2N/A sizeof (DAPL_PROVIDER_LIST_NODE));
2N/A }
2N/A
2N/A if (NULL != g_dapl_provider_list.tail) {
2N/A dapl_os_free(g_dapl_provider_list.tail,
2N/A sizeof (DAPL_PROVIDER_LIST_NODE));
2N/A }
2N/A }
2N/A
2N/A return (status);
2N/A}
2N/A
2N/A
2N/ADAT_RETURN
2N/Adapl_provider_list_destroy(void)
2N/A{
2N/A DAPL_PROVIDER_LIST_NODE *cur_node;
2N/A
2N/A while (NULL != g_dapl_provider_list.head) {
2N/A cur_node = g_dapl_provider_list.head;
2N/A g_dapl_provider_list.head = cur_node->next;
2N/A
2N/A dapl_os_free(cur_node, sizeof (DAPL_PROVIDER_LIST_NODE));
2N/A }
2N/A
2N/A return (DAT_SUCCESS);
2N/A}
2N/A
2N/A
2N/ADAT_COUNT
2N/Adapl_provider_list_size(void)
2N/A{
2N/A return (g_dapl_provider_list.size);
2N/A}
2N/A
2N/A
2N/ADAT_RETURN
2N/Adapl_provider_list_insert(
2N/A IN const char *name,
2N/A IN DAT_PROVIDER **p_data)
2N/A{
2N/A DAPL_PROVIDER_LIST_NODE *cur_node, *prev_node, *next_node;
2N/A DAT_RETURN status;
2N/A unsigned int len;
2N/A
2N/A status = DAT_SUCCESS;
2N/A *p_data = NULL;
2N/A
2N/A cur_node = dapl_os_alloc(sizeof (DAPL_PROVIDER_LIST_NODE));
2N/A
2N/A if (NULL == cur_node) {
2N/A status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
2N/A DAT_RESOURCE_MEMORY);
2N/A goto bail;
2N/A }
2N/A
2N/A len = dapl_os_strlen(name);
2N/A
2N/A if (DAT_NAME_MAX_LENGTH <= len) {
2N/A status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
2N/A DAT_RESOURCE_MEMORY);
2N/A goto bail;
2N/A }
2N/A
2N/A /* insert node at end of list to preserve registration order */
2N/A prev_node = g_dapl_provider_list.tail->prev;
2N/A next_node = g_dapl_provider_list.tail;
2N/A
2N/A (void) dapl_os_memcpy(cur_node->name, name, len);
2N/A cur_node->name[len] = '\0';
2N/A cur_node->data = g_dapl_provider_template;
2N/A cur_node->data.device_name = cur_node->name;
2N/A cur_node->next = next_node;
2N/A cur_node->prev = prev_node;
2N/A
2N/A prev_node->next = cur_node;
2N/A next_node->prev = cur_node;
2N/A
2N/A g_dapl_provider_list.size++;
2N/A
2N/A if (NULL != p_data) {
2N/A *p_data = &cur_node->data;
2N/A }
2N/A
2N/Abail:
2N/A if (DAT_SUCCESS != status) {
2N/A if (NULL != cur_node) {
2N/A dapl_os_free(cur_node,
2N/A sizeof (DAPL_PROVIDER_LIST_NODE));
2N/A }
2N/A }
2N/A
2N/A return (status);
2N/A}
2N/A
2N/A
2N/ADAT_RETURN
2N/Adapl_provider_list_search(
2N/A IN const char *name,
2N/A OUT DAT_PROVIDER **p_data)
2N/A{
2N/A DAPL_PROVIDER_LIST_NODE *cur_node;
2N/A DAT_RETURN status;
2N/A
2N/A status = DAT_ERROR(DAT_NAME_NOT_FOUND, 0);
2N/A
2N/A for (cur_node = g_dapl_provider_list.head->next;
2N/A g_dapl_provider_list.tail != cur_node;
2N/A cur_node = cur_node->next) {
2N/A if (dapl_provider_list_key_cmp(cur_node->name, name)) {
2N/A if (NULL != p_data) {
2N/A *p_data = &cur_node->data;
2N/A }
2N/A
2N/A status = DAT_SUCCESS;
2N/A goto bail;
2N/A }
2N/A }
2N/A
2N/Abail:
2N/A return (status);
2N/A}
2N/A
2N/A
2N/ADAT_RETURN
2N/Adapl_provider_list_remove(
2N/A IN const char *name)
2N/A{
2N/A DAPL_PROVIDER_LIST_NODE *cur_node, *prev_node, *next_node;
2N/A DAT_RETURN status;
2N/A
2N/A status = DAT_ERROR(DAT_NAME_NOT_FOUND, 0);
2N/A
2N/A for (cur_node = g_dapl_provider_list.head->next;
2N/A g_dapl_provider_list.tail != cur_node;
2N/A cur_node = cur_node->next) {
2N/A if (dapl_provider_list_key_cmp(cur_node->name, name)) {
2N/A prev_node = cur_node->prev;
2N/A next_node = cur_node->next;
2N/A
2N/A prev_node->next = next_node;
2N/A next_node->prev = prev_node;
2N/A
2N/A dapl_os_free(cur_node,
2N/A sizeof (DAPL_PROVIDER_LIST_NODE));
2N/A
2N/A g_dapl_provider_list.size--;
2N/A
2N/A status = DAT_SUCCESS;
2N/A goto bail;
2N/A }
2N/A }
2N/A
2N/Abail:
2N/A return (status);
2N/A}
2N/A
2N/A
2N/ADAT_BOOLEAN
2N/Adapl_provider_list_key_cmp(
2N/A const char *name_a,
2N/A const char *name_b)
2N/A{
2N/A unsigned int len;
2N/A
2N/A len = dapl_os_strlen(name_a);
2N/A
2N/A if (dapl_os_strlen(name_b) != len) {
2N/A return (DAT_FALSE);
2N/A } else if (dapl_os_memcmp(name_a, name_b, len)) {
2N/A return (DAT_FALSE);
2N/A } else {
2N/A return (DAT_TRUE);
2N/A }
2N/A}