1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#ifndef	_FCHBAPORT_H
27#define	_FCHBAPORT_H
28
29
30
31#include <Lockable.h>
32#include <HBAPort.h>
33#include <Exceptions.h>
34#include <string>
35#include <hbaapi.h>
36#include <sys/param.h>
37#include <sys/fibre-channel/fcio.h>
38
39#ifdef	__cplusplus
40extern "C" {
41#endif
42
43/*
44 * Represents a single HBA port
45 */
46class FCHBAPort : public HBAPort {
47public:
48    FCHBAPort(std::string path);
49    virtual std::string			getPath()
50					    { return path; }
51    virtual uint64_t			getNodeWWN()
52					    { return nodeWWN; }
53    virtual uint64_t			getPortWWN()
54					    { return portWWN; }
55    virtual HBA_PORTATTRIBUTES		getPortAttributes(
56					    uint64_t &stateChange);
57    virtual HBA_PORTNPIVATTRIBUTES		getPortNPIVAttributes(
58					    uint64_t &stateChange);
59    virtual uint32_t			createNPIVPort(
60					    uint64_t vnodewwn,
61					    uint64_t vportwwn,
62					    uint32_t vindex);
63    virtual uint32_t			deleteNPIVPort(
64					    uint64_t vportwwn);
65    virtual HBA_PORTATTRIBUTES		getDiscoveredAttributes(
66					    HBA_UINT32 discoveredport,
67					    uint64_t &stateChange);
68    virtual HBA_PORTATTRIBUTES		getDiscoveredAttributes(
69					    uint64_t wwn,
70					    uint64_t &stateChange);
71    virtual void	    getTargetMappings(
72				PHBA_FCPTARGETMAPPINGV2 userMappings);
73    virtual void	    getRNIDMgmtInfo(PHBA_MGMTINFO info);
74    virtual void	    sendCTPassThru(void *requestBuffer,
75				HBA_UINT32 requestSize,
76				void *responseBuffer,
77				HBA_UINT32 *responseSize);
78    virtual void	    sendRLS(uint64_t destWWN,
79				void *pRspBuffer,
80				HBA_UINT32 *pRspBufferSize);
81    virtual void	    sendRPL(uint64_t destWWN,
82				HBA_UINT32 agent_domain,
83				HBA_UINT32 port_index,
84				void *pRspBuffer,
85				HBA_UINT32 *pRspBufferSize) {
86				throw NotSupportedException(); }
87    virtual void	    sendRPS(uint64_t agentWWN,
88				HBA_UINT32 agentDomain,
89				uint64_t objectWWN,
90				HBA_UINT32 objectPortNum,
91				void *pRspBuffer,
92				HBA_UINT32 *pRspBufferSize) {
93				throw NotSupportedException(); }
94    virtual void	    sendSRL(uint64_t destWWN,
95				HBA_UINT32 agent_domain,
96				void *pRspBuffer,
97				HBA_UINT32 *pRspBufferSize) {
98				throw NotSupportedException(); }
99    virtual void	    sendLIRR(uint64_t destWWN,
100				HBA_UINT8 function,
101				HBA_UINT8 type,
102				void *pRspBuffer,
103				HBA_UINT32 *pRspBufferSize) {
104				throw NotSupportedException(); }
105    virtual void	    sendReportLUNs(uint64_t wwn,
106				void *responseBuffer, HBA_UINT32 *responseSize,
107				HBA_UINT8 *scsiStatus,
108				void *senseBuffer, HBA_UINT32 *senseSize);
109    virtual void	    sendScsiInquiry(uint64_t wwn, HBA_UINT64 fcLun,
110				HBA_UINT8 cdb1, HBA_UINT8 cdb2,
111				void *responseBuffer, HBA_UINT32 *responseSize,
112				HBA_UINT8 *scsiStatus, void *senseBuffer,
113				HBA_UINT32 *senseSize);
114    virtual void	    sendReadCapacity(uint64_t pwwn,
115				HBA_UINT64 fcLun, void *responseBuffer,
116				HBA_UINT32 *responseSize, HBA_UINT8 *scsiStatus,
117				void *senseBuffer, HBA_UINT32 *senseSize);
118    virtual void	    sendRNID(uint64_t destwwn, HBA_UINT32 destfcid,
119				HBA_UINT32 nodeIdDataFormat, void *pRspBuffer,
120				HBA_UINT32 *RspBufferSize);
121    virtual void	    setRNID(HBA_MGMTINFO info);
122
123
124private:
125    std::string		    path;
126    uint64_t		    portWWN;
127    uint64_t		    nodeWWN;
128    uint32_t		    instanceNumber;
129    int			    controllerNumber;
130    void		    sendSCSIPassThru(struct fcp_scsi_cmd *fscsi,
131				HBA_UINT32 *responseSize, HBA_UINT32 *senseSize,
132				HBA_UINT8 *scsiStatus);
133    static const std::string	FCSM_DRIVER_PATH;
134    static const int		MAX_FCIO_MSG_LEN;
135    static const std::string	FCP_DRIVER_PATH;
136    static void transportError(uint32_t fcio_errno, char *message);
137
138	// Wrapper routines to handle error cases
139    static void		    fp_ioctl(std::string path, int cmd, fcio_t *arg);
140    static void		    fp_ioctl(std::string path, int cmd, fcio_t *arg,
141				int openflag);
142    static void		    fcsm_ioctl(int cmd, fcio_t *arg);
143};
144
145#ifdef	__cplusplus
146}
147#endif
148
149#endif /* _FCHBAPORT_H */
150