fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
a79493184c9332129c9c91500069322f6f3fafddReed * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _HANDLE_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _HANDLE_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte// Forward Declarations
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteclass Handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteclass HandlePort;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "Lockable.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "HBA.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "HandlePort.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <map>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <hbaapi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <hbaapi-sun.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Represents an open HBA port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @doc This class represents an open HBA. However,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * what we really care about is the HBA port's underneath.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * So, we also track HandlePorts internally.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteclass Handle : public Lockable {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortepublic:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte enum MODE { INITIATOR, TARGET };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Handle(HBA *hba); // Generate ID, and add to vector
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Handle(HBA *hba, MODE m); // Generate ID based on target or initiator mode
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ~Handle(); // Free and remove from vector
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static Handle* findHandle(HBA_HANDLE index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static Handle* findHandle(uint64_t wwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static void closeHandle(HBA_HANDLE index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_HANDLE getHandle();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bool operator==(Handle comp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA* getHBA() { return (hba); }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HandlePort* getHandlePortByIndex(int index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HandlePort* getHandlePort(uint64_t wwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MODE getMode() { return (modeVal); };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void refresh();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_ADAPTERATTRIBUTES getHBAAttributes();
a79493184c9332129c9c91500069322f6f3fafddReed int doForceLip();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_ADAPTERATTRIBUTES npivGetHBAAttributes();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES getPortAttributes(uint64_t wwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteprivate:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA *hba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_HANDLE id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MODE modeVal;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static pthread_mutex_t staticLock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static HBA_HANDLE prevOpen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static HBA_HANDLE prevTgtOpen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static std::map<HBA_HANDLE, Handle*> openHandles;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte std::map<uint64_t, HandlePort*> portHandles;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _HANDLE_H */