fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
a79493184c9332129c9c91500069322f6f3fafddReed * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteusing namespace std;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Global lock for list of Handles
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortepthread_mutex_t Handle::staticLock = PTHREAD_MUTEX_INITIALIZER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Tracking for the previous handle we have opened
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Tracking for the previous target HBA handle we have opened
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Global map from HBA_HANDLE to Handle pointers (our global list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Create a new open handle for a specified HBA
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @precondition HBA port(s) must be loaded
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @postcondition An open handle will be present in the global tracking list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and must be closed at some point to prevent leakage. If no
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle could be assigned (the track list is full), an
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * exception will be thrown. Scope for valid ids in the track
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * list is [1, MAX_INIT_HANDLE_ID].
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param myhba The HBA to open a handle for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Start the search for a free id from the previously assigned one */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Exceeds the max valid value, continue the search from 1 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* the id is not in use */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no usable id for now */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Create a new open handle for a specified HBA
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @precondition HBA port(s) must be loaded
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @postcondition An open handle will be present in the global tracking list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and must be closed at some point to prevent leakage. If no
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle could be assigned (the track list is full), an
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * exception will be thrown. Scope for valid ids in the track
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * list is [0x8000, MAX_TGT_HANDLE_ID].
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param myhba The HBA to open a handle for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * m The mode of HBA to open handle for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte// appears unused
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // if initiator mode call constructor for initiator.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Start the search for a free id from the previously assigned one */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Exceeds the max valid target id value,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * continue the search from 1.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* the id is not in use */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no usable id for now */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Free up the handle (aka, close it)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @postcondition This handle will be removed from the global list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @exception ... underlying exceptions will be thrown
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Remove this handle from the global list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte openHandles.erase(openHandles.find(getHandle()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Now nuke all internal dynamic allocations
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte typedef map<uint64_t, HandlePort *>::const_iterator CI;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (CI port = portHandles.begin(); port != portHandles.end();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Locate a handle in the global list of open handles
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @precondition The requested handle must already be open
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @exception InvalidHandleException Thrown if the id does not match
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * an open handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @return The open Handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param id The id of the handle to fetch
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @doc The HBA API uses a simple integer type to represent
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * an open Handle, but we use an instance of the Handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * class. This interface allows a caller to quickly convert
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * from the API integer value to related the Handle instance.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Find an open handle based on Node or Port WWN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @precondition The given HBA must already be open
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @exception IllegalWWNException Thrown if no matching open Handle found
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @return The open handle matching the wwn argument
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param wwn The Node or Port WWN of the HBA whos open handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is requested.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Refresh underlying index values
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @postcondition All HandlePorts will be reset and prior index values
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will be undefined.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @exception ... underlying exceptions will be thrown
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @doc A number of APIs in the standard interface require
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the use of index values for identifying what "thing"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to operate on. When dynamic reconfiguration occurs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * these indexes may become inconsistent. This routine
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is called to reset the indexes and signify that the caller
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * no longer holds or will refer to any old indexes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte typedef map<uint64_t, HandlePort *>::const_iterator CI;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (CI port = portHandles.begin(); port != portHandles.end();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Close the specified handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @precondition The handle must be open
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @postcondition The handle will be closed and should be discarded.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param id The handle to close
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Get the integer value for return to the API
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @exception ... underlying exceptions will be thrown
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @return The integer value representing the handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @doc The HBA API uses integer values to represent handles.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Call this routine to convert a Handle instance into
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * its representative integer value.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Compare two handles for equality
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @return TRUE if the handles are the same
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @return FALSE if the handles are different
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Get the underlying Handle port based on index
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @return The Handle port for the given port index
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param index The index of the desired port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHandlePort* Handle::getHandlePortByIndex(int index) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Get the underlying Handle port based on Port wwn
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @exception IllegalWWNException thrown if the wwn is not found
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @return The handle port for the specified WWN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param wwn The Port WWN of the HBA port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Check to see if the wwn is in the map
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (portHandles.find(wwn) == portHandles.end()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Not found, add a new one
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portHandles[wwn] = new HandlePort(this, hba, port);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Get the HBA attributes from the underlying HBA
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @see HBA::getHBAAttributes
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBA_ADAPTERATTRIBUTES Handle::getHBAAttributes() {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_ADAPTERATTRIBUTES attributes = hba->getHBAAttributes();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
a79493184c9332129c9c91500069322f6f3fafddReed * @memo Do FORCELIP
a79493184c9332129c9c91500069322f6f3fafddReed * @see HBA::doForceLip
a79493184c9332129c9c91500069322f6f3fafddReed } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBA_ADAPTERATTRIBUTES Handle::npivGetHBAAttributes() {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_ADAPTERATTRIBUTES attributes = hba->npivGetHBAAttributes();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Get the HBA port attributes from the HBA
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @see HBAPort::getPortAttributes
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @see HBAPort::getDisoveredAttributes
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @doc This routine will return either HBA port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * attributes, or discovered port attributes
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBA_PORTATTRIBUTES Handle::getPortAttributes(uint64_t wwn) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Is this a WWN for one of the adapter ports?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes = hba->getPort(wwn)->getPortAttributes(tmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { // Is this a target we know about?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Loop through all ports and look for the first match
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (int i = 0; i < hba->getNumberOfPorts(); i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (HBAException &e) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // If we get to here, then we don't see this WWN on this HBA
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {