TgtFCHBAPort.cc revision c946faca5d4627284fb79c6b04e652b471034495
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
c946faca5d4627284fb79c6b04e652b471034495allan * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteusing namespace std;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteconst string TgtFCHBAPort::FCT_DRIVER_PATH = "/devices/pseudo/fct@0:admin";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Interpret the error code in the fctio_t structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * message must be at least MAX_FCTIO_MSG_LEN in length.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteTgtFCHBAPort::transportError(uint32_t fctio_errno, char *message) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "general failure but fail silently";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "invalid packet specified/supplied";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "invalid unsolicited buffer token";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "ULP not registered to handle this FC4 type";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "port number is out of bounds";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "transport working on this device";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte snprintf(message, MAX_FCTIO_MSG_LEN, "Unknown error code 0x%x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte snprintf(message, MAX_FCTIO_MSG_LEN, "%s", fcioErrorString.c_str());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteTgtFCHBAPort::TgtFCHBAPort(string thePath) : HBAPort() {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.debug("Initializing HBA port %s", path.c_str());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // This routine is not index based, so we can discard stateChange
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES attrs = getPortAttributes(tmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // For reference, here's how to dump WWN's through C++ streams.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // cout << "\tPort WWN: " << hex << setfill('0') << setw(16) << portWWN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // cout << "\tNode WWN: " << hex << setfill('0') << setw(16) << nodeWWN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBA_PORTATTRIBUTES TgtFCHBAPort::getPortAttributes(uint64_t &stateChange) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte string::size_type offset = path.find_last_of(".");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portwwn = strtoull(portwwnString.c_str(), NULL, 16);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fctio.fctio_cmd = FCTIO_GET_ADAPTER_PORT_ATTRIBUTES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortSupportedClassofService = attrs.PortSupportedClassofService;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortSupportedSpeed = attrs.PortSupportedSpeed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortMaxFrameSize = attrs.PortMaxFrameSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.NumberofDiscoveredPorts = attrs.NumberofDiscoveredPorts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.FabricName, &attrs.FabricName, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortSupportedFc4Types, &attrs.PortSupportedFc4Types, 32);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortActiveFc4Types, &attrs.PortActiveFc4Types, 32);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortSymbolicName, &attrs.PortSymbolicName, 256);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy((char *)attributes.OSDeviceName, "Not Applicable", 15);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBA_PORTATTRIBUTES TgtFCHBAPort::getDiscoveredAttributes(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 discoveredport, uint64_t &stateChange) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("TgtFCHBAPort::getDiscoverdAttributes(i)");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte string::size_type offset = path.find_last_of(".");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portwwn = strtoull(portwwnString.c_str(), NULL, 16);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fctio.fctio_cmd = FCTIO_GET_DISCOVERED_PORT_ATTRIBUTES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fctio.fctio_alen = (uint32_t)(sizeof (discoveredport));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fctio.fctio_abuf = (uint64_t)(uintptr_t)&discoveredport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortSupportedClassofService = attrs.PortSupportedClassofService;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortSupportedSpeed = attrs.PortSupportedSpeed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortMaxFrameSize = attrs.PortMaxFrameSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.NumberofDiscoveredPorts = attrs.NumberofDiscoveredPorts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.FabricName, &attrs.FabricName, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortSupportedFc4Types, &attrs.PortSupportedFc4Types, 32);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortActiveFc4Types, &attrs.PortActiveFc4Types, 32);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortSymbolicName, &attrs.PortSymbolicName, 256);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBA_PORTATTRIBUTES TgtFCHBAPort::getDiscoveredAttributes(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("TgtFCHBAPort::getDiscoverdAttributes(p)");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortSupportedClassofService = attrs.PortSupportedClassofService;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortSupportedSpeed = attrs.PortSupportedSpeed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortMaxFrameSize = attrs.PortMaxFrameSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.NumberofDiscoveredPorts = attrs.NumberofDiscoveredPorts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.FabricName, &attrs.FabricName, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortSupportedFc4Types, &attrs.PortSupportedFc4Types, 32);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortActiveFc4Types, &attrs.PortActiveFc4Types, 32);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortSymbolicName, &attrs.PortSymbolicName, 256);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // fc_hba_adapter_port_stats_t fc_port_stat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Validate the arguments
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // check to see if we are sending RLS to the HBA
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The destWWN is either the adapter port or a discovered port. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fctio.fctio_ibuf = (uint64_t)(uintptr_t)&en_portWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fctio.fctio_ilen = (uint32_t)(sizeof (en_portWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fctio.fctio_obuf = (uint64_t)(uintptr_t)new uchar_t[*pRspBufferSize];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(pRspBuffer, (uchar_t *)(uintptr_t)fctio.fctio_obuf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Validate that the port is still present in the system
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @exception UnavailableException if the port is not present
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @version 1.7
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @doc If the port is still present on the system, the routine
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will return normally. If the port is not present
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * an exception will be thrown.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // We already got the adapter list through the ioctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // so calling it again to validate it is too expensive.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid TgtFCHBAPort::fct_ioctl(int cmd, fctio_t *fctio) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd = HBA::_open(FCT_DRIVER_PATH, O_NDELAY | O_RDONLY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte transportError(fctio->fctio_errno, fcioErrorString);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.genericIOError("ioctl (0x%x) failed. Transport: \"%s\"", cmd,