2026N/A/*
2026N/A * CDDL HEADER START
2026N/A *
3427N/A * The contents of this file are subject to the terms of the
3427N/A * Common Development and Distribution License (the "License").
2026N/A * You may not use this file except in compliance with the License.
2026N/A *
2026N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2026N/A * or http://www.opensolaris.org/os/licensing.
2026N/A * See the License for the specific language governing permissions
2026N/A * and limitations under the License.
2026N/A *
2026N/A * When distributing Covered Code, include this CDDL HEADER in each
2026N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2026N/A * If applicable, add the following below this CDDL HEADER, with the
3427N/A * fields enclosed by brackets "[]" replaced with your own identifying
2026N/A * information: Portions Copyright [yyyy] [name of copyright owner]
3427N/A *
3427N/A * CDDL HEADER END
3427N/A */
3427N/A
3427N/A/*
3427N/A * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
3427N/A */
3427N/A
3427N/A/*
3427N/A * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
2026N/A * Use is subject to license terms.
2026N/A */
2026N/A
2026N/A/*
2026N/A *
2026N/A * MODULE: dapl_hca_util.c
2026N/A *
2026N/A * PURPOSE: Manage HCA structure
3427N/A *
2026N/A */
2026N/A
2026N/A#include "dapl.h"
2026N/A#include "dapl_adapter_util.h"
2026N/A#include "dapl_provider.h"
2026N/A#include "dapl_hca_util.h"
2026N/A#include "dapl_hash.h"
2026N/A
2026N/A
2026N/A/*
2026N/A * dapl_hca_alloc
3427N/A *
2026N/A * alloc and initialize an HCA struct
2026N/A *
2026N/A * Input:
2026N/A * name
2026N/A * port
2026N/A *
2026N/A * Output:
2026N/A * hca_ptr
2026N/A *
2026N/A * Returns:
2026N/A * none
2026N/A *
2026N/A */
2026N/A/* ARGSUSED */
2026N/ADAPL_HCA *
2026N/Adapl_hca_alloc(char *name, char *port)
2026N/A{
2026N/A DAPL_HCA *hca_ptr;
2026N/A
2026N/A hca_ptr = dapl_os_alloc(sizeof (DAPL_HCA));
2026N/A if (NULL != hca_ptr) {
2026N/A (void) dapl_os_memzero(hca_ptr, sizeof (DAPL_HCA));
3427N/A
3427N/A if (DAT_SUCCESS ==
3427N/A dapls_hash_create(DAPL_HASH_TABLE_DEFAULT_CAPACITY,
3427N/A DAT_TRUE, &hca_ptr->lmr_hash_table)) {
3427N/A dapl_os_lock_init(&hca_ptr->lock);
3427N/A dapl_llist_init_head(&hca_ptr->ia_list_head);
3427N/A
3427N/A hca_ptr->name = dapl_os_strdup(name);
3427N/A hca_ptr->ib_hca_handle = IB_INVALID_HANDLE;
3427N/A hca_ptr->port_num = 0;
3427N/A hca_ptr->null_ib_cq_handle = IB_INVALID_HANDLE;
2026N/A } else {
2026N/A dapl_os_free(hca_ptr, sizeof (DAPL_HCA));
2026N/A hca_ptr = NULL;
2026N/A }
2026N/A }
2026N/A return (hca_ptr);
2026N/A}
2026N/A
2026N/A/*
2026N/A * dapl_hca_free
2026N/A *
2026N/A * free an IA INFO struct
2026N/A *
2026N/A * Input:
2026N/A * hca_ptr
2026N/A *
2026N/A * Output:
2026N/A * none
2026N/A *
2026N/A * Returns:
2026N/A * none
2026N/A *
2026N/A */
2026N/Avoid
2026N/Adapl_hca_free(DAPL_HCA *hca_ptr)
2026N/A{
2026N/A unsigned int len;
2026N/A
2026N/A (void) dapls_hash_free(hca_ptr->lmr_hash_table);
2026N/A if (NULL != hca_ptr->name) {
2026N/A len = dapl_os_strlen(hca_ptr->name);
2026N/A /* pacify lint dapl_os_free macro doesn't use len */
2026N/A len = len;
2026N/A dapl_os_free(hca_ptr->name, len + 1);
2026N/A }
2026N/A
2026N/A dapl_os_free(hca_ptr, sizeof (DAPL_HCA));
2026N/A}
2026N/A
2026N/A/*
2026N/A * dapl_hca_link_ia
2026N/A *
2026N/A * Add an ia to the HCA structure
2026N/A *
2026N/A * Input:
2026N/A * hca_ptr
2026N/A * ia_ptr
2026N/A *
2026N/A * Output:
2026N/A * none
2026N/A *
2026N/A * Returns:
2026N/A * none
2026N/A *
2026N/A */
2026N/Avoid
2026N/Adapl_hca_link_ia(IN DAPL_HCA *hca_ptr, IN DAPL_IA *ia_ptr)
2026N/A{
2026N/A dapl_os_lock(&hca_ptr->lock);
2026N/A dapl_llist_add_head(&hca_ptr->ia_list_head,
2026N/A &ia_ptr->hca_ia_list_entry, ia_ptr);
2026N/A dapl_os_unlock(&hca_ptr->lock);
2026N/A}
2026N/A
2026N/A/*
2026N/A * dapl_hca_unlink_ia
2026N/A *
2026N/A * Remove an ia from the hca info structure
2026N/A *
2026N/A * Input:
2026N/A * hca_ptr
2026N/A * ia_ptr
2026N/A *
2026N/A * Output:
2026N/A * none
2026N/A *
2026N/A * Returns:
2026N/A * none
2026N/A *
2026N/A */
2026N/Avoid
2026N/Adapl_hca_unlink_ia(IN DAPL_HCA *hca_ptr, IN DAPL_IA *ia_ptr)
2026N/A{
2026N/A dapl_os_lock(&hca_ptr->lock);
2026N/A /*
2026N/A * If an error occurred when we were opening the IA it
2026N/A * will not be linked on the list; don't unlink an unlinked
2026N/A * list!
2026N/A */
2026N/A if (!dapl_llist_is_empty(&hca_ptr->ia_list_head)) {
2026N/A (void) dapl_llist_remove_entry(&hca_ptr->ia_list_head,
2026N/A &ia_ptr->hca_ia_list_entry);
2026N/A }
2026N/A dapl_os_unlock(&hca_ptr->lock);
2026N/A}
2026N/A