1fcf3ce4John Forte/*
2fcf3ce4John Forte * CDDL HEADER START
3fcf3ce4John Forte *
4fcf3ce4John Forte * The contents of this file are subject to the terms of the
5fcf3ce4John Forte * Common Development and Distribution License (the "License").
6fcf3ce4John Forte * You may not use this file except in compliance with the License.
7fcf3ce4John Forte *
8fcf3ce4John Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fcf3ce4John Forte * or http://www.opensolaris.org/os/licensing.
10fcf3ce4John Forte * See the License for the specific language governing permissions
11fcf3ce4John Forte * and limitations under the License.
12fcf3ce4John Forte *
13fcf3ce4John Forte * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce4John Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce4John Forte * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce4John Forte * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce4John Forte * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce4John Forte *
19fcf3ce4John Forte * CDDL HEADER END
20fcf3ce4John Forte */
21fcf3ce4John Forte/*
22fcf3ce4John Forte * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23fcf3ce4John Forte * Use is subject to license terms.
24a317005Paul Winder * Copyright 2020 RackTop Systems, Inc.
25fcf3ce4John Forte */
26fcf3ce4John Forte
27fcf3ce4John Forte
28fcf3ce4John Forte
29fcf3ce4John Forte#include <stdio.h>
30fcf3ce4John Forte#include <hbaapi.h>
31fcf3ce4John Forte#include <string.h>
32fcf3ce4John Forte#include <sys/types.h>
33fcf3ce4John Forte#include <netinet/in.h>
34fcf3ce4John Forte#include <inttypes.h>
35fcf3ce4John Forte#include <ctype.h>
36fcf3ce4John Forte#include "fcinfo.h"
37fcf3ce4John Forte
38fcf3ce4John Forte#ifdef _BIG_ENDIAN
39fcf3ce4John Forte#define	htonll(x)   (x)
40fcf3ce4John Forte#define	ntohll(x)   (x)
41fcf3ce4John Forte#else
42fcf3ce4John Forte#define	htonll(x)   ((((unsigned long long)htonl(x)) << 32) + htonl(x >> 32))
43fcf3ce4John Forte#define	ntohll(x)   ((((unsigned long long)ntohl(x)) << 32) + ntohl(x >> 32))
44fcf3ce4John Forte#endif
45fcf3ce4John Forte
46fcf3ce4John Forte/* Fc4 Types Format */
47fcf3ce4John Forte#define	FC4_TYPE_WORD_POS(x)	    ((uint_t)((uint_t)(x) >> 5))
48fcf3ce4John Forte#define	FC4_TYPE_BIT_POS(x)	    ((uchar_t)(x) & 0x1F)
49fcf3ce4John Forte
50fcf3ce4John Forte#define	TYPE_IP_FC		    0x05
51fcf3ce4John Forte#define	TYPE_SCSI_FCP		    0x08
52fcf3ce4John Forte
53fcf3ce4John Fortestatic int fc4_map_is_set(uint32_t *map, uchar_t ulp_type);
54fcf3ce4John Fortestatic char *getPortType(HBA_PORTTYPE portType);
55fcf3ce4John Fortestatic char *getPortState(HBA_PORTSTATE portState);
56fcf3ce4John Fortestatic void printPortSpeed(HBA_PORTSPEED portSpeed);
57fcf3ce4John Fortestatic char *getDTypeString(uchar_t dType);
58fcf3ce4John Forte
59fcf3ce4John Forteuint64_t wwnConversion(uchar_t *wwn) {
60fcf3ce4John Forte	uint64_t tmp;
61fcf3ce4John Forte	memcpy(&tmp, wwn, sizeof (uint64_t));
62fcf3ce4John Forte	return (ntohll(tmp));
63fcf3ce4John Forte}
64fcf3ce4John Forte
65fcf3ce4John Fortestatic char *
66fcf3ce4John FortegetPortType(HBA_PORTTYPE portType) {
67fcf3ce4John Forte	switch (portType) {
68fcf3ce4John Forte	case HBA_PORTTYPE_UNKNOWN:
69fcf3ce4John Forte	    return ("unknown");
70fcf3ce4John Forte	case HBA_PORTTYPE_OTHER:
71fcf3ce4John Forte	    return ("other");
72fcf3ce4John Forte	case HBA_PORTTYPE_NOTPRESENT:
73fcf3ce4John Forte	    return ("not present");
74fcf3ce4John Forte	case HBA_PORTTYPE_NPORT:
75fcf3ce4John Forte	    return ("N-port");
76fcf3ce4John Forte	case HBA_PORTTYPE_NLPORT:
77fcf3ce4John Forte	    return ("NL-port");
78fcf3ce4John Forte	case HBA_PORTTYPE_FLPORT:
79fcf3ce4John Forte	    return ("FL-port");
80fcf3ce4John Forte	case HBA_PORTTYPE_FPORT:
81fcf3ce4John Forte	    return ("F-port");
82fcf3ce4John Forte	case HBA_PORTTYPE_LPORT:
83fcf3ce4John Forte	    return ("L-port");
84fcf3ce4John Forte	case HBA_PORTTYPE_PTP:
85fcf3ce4John Forte	    return ("point-to-point");
86fcf3ce4John Forte	default:
87fcf3ce4John Forte	    return ("unrecognized type");
88fcf3ce4John Forte	}
89fcf3ce4John Forte}
90fcf3ce4John Forte
91fcf3ce4John Fortestatic char *
92fcf3ce4John FortegetPortState(HBA_PORTSTATE portState) {
93fcf3ce4John Forte	switch (portState) {
94fcf3ce4John Forte	case HBA_PORTSTATE_UNKNOWN:
95fcf3ce4John Forte	    return ("unknown");
96fcf3ce4John Forte	case HBA_PORTSTATE_ONLINE:
97fcf3ce4John Forte	    return ("online");
98fcf3ce4John Forte	case HBA_PORTSTATE_OFFLINE:
99fcf3ce4John Forte	    return ("offline");
100fcf3ce4John Forte	case HBA_PORTSTATE_BYPASSED:
101fcf3ce4John Forte	    return ("bypassed");
102fcf3ce4John Forte	case HBA_PORTSTATE_DIAGNOSTICS:
103fcf3ce4John Forte	    return ("diagnostics");
104fcf3ce4John Forte	case HBA_PORTSTATE_LINKDOWN:
105fcf3ce4John Forte	    return ("link down");
106fcf3ce4John Forte	case HBA_PORTSTATE_ERROR:
107fcf3ce4John Forte	    return ("error");
108fcf3ce4John Forte	case HBA_PORTSTATE_LOOPBACK:
109fcf3ce4John Forte	    return ("loopback");
110fcf3ce4John Forte	default:
111fcf3ce4John Forte	    return ("unrecognized state");
112fcf3ce4John Forte	}
113fcf3ce4John Forte}
114fcf3ce4John Forte
115fcf3ce4John Fortestatic void
116fcf3ce4John ForteprintPortSpeed(HBA_PORTSPEED portSpeed) {
117fcf3ce4John Forte	int foundSpeed = 0;
118fcf3ce4John Forte
119fcf3ce4John Forte	if ((portSpeed & HBA_PORTSPEED_1GBIT) == HBA_PORTSPEED_1GBIT) {
120fcf3ce4John Forte		fprintf(stdout, "1Gb ");
121fcf3ce4John Forte		foundSpeed = 1;
122fcf3ce4John Forte	}
123fcf3ce4John Forte	if ((portSpeed & HBA_PORTSPEED_2GBIT) == HBA_PORTSPEED_2GBIT) {
124fcf3ce4John Forte		fprintf(stdout, "2Gb ");
125fcf3ce4John Forte		foundSpeed = 1;
126fcf3ce4John Forte	}
127fcf3ce4John Forte	if ((portSpeed & HBA_PORTSPEED_4GBIT) == HBA_PORTSPEED_4GBIT) {
128fcf3ce4John Forte		fprintf(stdout, "4Gb ");
129fcf3ce4John Forte		foundSpeed = 1;
130fcf3ce4John Forte	}
131fcf3ce4John Forte	if ((portSpeed & HBA_PORTSPEED_8GBIT) == HBA_PORTSPEED_8GBIT) {
132fcf3ce4John Forte		fprintf(stdout, "8Gb ");
133fcf3ce4John Forte		foundSpeed = 1;
134fcf3ce4John Forte	}
135fcf3ce4John Forte	if ((portSpeed & HBA_PORTSPEED_10GBIT) == HBA_PORTSPEED_10GBIT) {
136fcf3ce4John Forte		fprintf(stdout, "10Gb ");
137fcf3ce4John Forte		foundSpeed = 1;
138fcf3ce4John Forte	}
139fcf3ce4John Forte	if ((portSpeed & HBA_PORTSPEED_16GBIT) == HBA_PORTSPEED_16GBIT) {
140fcf3ce4John Forte		fprintf(stdout, "16Gb ");
141fcf3ce4John Forte		foundSpeed = 1;
142fcf3ce4John Forte	}
143a317005Paul Winder	if ((portSpeed & HBA_PORTSPEED_32GBIT) == HBA_PORTSPEED_32GBIT) {
144a317005Paul Winder		fprintf(stdout, "32Gb ");
145a317005Paul Winder		foundSpeed = 1;
146a317005Paul Winder	}
147fcf3ce4John Forte	if ((portSpeed & HBA_PORTSPEED_NOT_NEGOTIATED)
148fcf3ce4John Forte	    == HBA_PORTSPEED_NOT_NEGOTIATED) {
149fcf3ce4John Forte		fprintf(stdout, "not established ");
150fcf3ce4John Forte		foundSpeed = 1;
151fcf3ce4John Forte	}
152fcf3ce4John Forte	if (foundSpeed == 0) {
153fcf3ce4John Forte		fprintf(stdout, "not established ");
154fcf3ce4John Forte	}
155fcf3ce4John Forte}
156fcf3ce4John Forte
157fcf3ce4John Fortevoid
158fcf3ce4John ForteprintDiscoPortInfo(HBA_PORTATTRIBUTES *discoPort, int scsiTargetType) {
159fcf3ce4John Forte	int fc4_types = 0;
160fcf3ce4John Forte
161fcf3ce4John Forte	fprintf(stdout, gettext("Remote Port WWN: %016llx\n"),
162fcf3ce4John Forte	    wwnConversion(discoPort->PortWWN.wwn));
163fcf3ce4John Forte	fprintf(stdout, gettext("\tActive FC4 Types: "));
164fcf3ce4John Forte	if (fc4_map_is_set(
165fcf3ce4John Forte		    (uint32_t *)discoPort->PortActiveFc4Types.bits,
166fcf3ce4John Forte		    TYPE_SCSI_FCP)) {
167fcf3ce4John Forte		fprintf(stdout, gettext("SCSI"));
168fcf3ce4John Forte		fc4_types++;
169fcf3ce4John Forte	}
170fcf3ce4John Forte	if (fc4_map_is_set(
171fcf3ce4John Forte		    (uint32_t *)discoPort->PortActiveFc4Types.bits,
172fcf3ce4John Forte		    TYPE_IP_FC)) {
173fcf3ce4John Forte		if (fc4_types != 0) {
174fcf3ce4John Forte			fprintf(stdout, ",");
175fcf3ce4John Forte		}
176fcf3ce4John Forte		fprintf(stdout, gettext("IP"));
177fcf3ce4John Forte		fc4_types++;
178fcf3ce4John Forte	}
179fcf3ce4John Forte	fprintf(stdout, "\n");
180fcf3ce4John Forte
181fcf3ce4John Forte	/* print out scsi target type information */
182fcf3ce4John Forte	fprintf(stdout, gettext("\tSCSI Target: "));
183fcf3ce4John Forte	if (scsiTargetType == SCSI_TARGET_TYPE_YES) {
184fcf3ce4John Forte		fprintf(stdout, gettext("yes\n"));
185fcf3ce4John Forte	} else if (scsiTargetType == SCSI_TARGET_TYPE_NO) {
186fcf3ce4John Forte		fprintf(stdout, gettext("no\n"));
187fcf3ce4John Forte	} else {
188fcf3ce4John Forte		fprintf(stdout, gettext("unknown\n"));
189fcf3ce4John Forte	}
190fcf3ce4John Forte	fprintf(stdout, gettext("\tPort Symbolic Name: %s\n"),
191fcf3ce4John Forte	    discoPort->PortSymbolicName);
192fcf3ce4John Forte	fprintf(stdout, gettext("\tNode WWN: %016llx\n"),
193fcf3ce4John Forte	    wwnConversion(discoPort->NodeWWN.wwn));
194fcf3ce4John Forte}
195fcf3ce4John Forte
196fcf3ce4John Forte/*
197fcf3ce4John Forte * scan the bitmap array for the specifed ULP type. The bit map array
198fcf3ce4John Forte * is 32 bytes long
199fcf3ce4John Forte */
200fcf3ce4John Fortestatic int
201fcf3ce4John Fortefc4_map_is_set(uint32_t *map, uchar_t ulp_type)
202fcf3ce4John Forte{
203fcf3ce4John Forte
204fcf3ce4John Forte	map += FC4_TYPE_WORD_POS(ulp_type) * 4;
205fcf3ce4John Forte
206fcf3ce4John Forte	if (ntohl((*(uint32_t *)map)) & (1 << FC4_TYPE_BIT_POS(ulp_type))) {
207fcf3ce4John Forte		return (1);
208fcf3ce4John Forte	}
209fcf3ce4John Forte
210fcf3ce4John Forte	return (0);
211fcf3ce4John Forte}
212fcf3ce4John Forte
213fcf3ce4John Forte/*
214fcf3ce4John Forte * prints out all the HBA port information
215fcf3ce4John Forte */
216fcf3ce4John Fortevoid
217fcf3ce4John ForteprintHBAPortInfo(HBA_PORTATTRIBUTES *port,
218fcf3ce4John Forte    HBA_ADAPTERATTRIBUTES *attrs, int mode) {
219fcf3ce4John Forte	if (attrs == NULL || port == NULL) {
220fcf3ce4John Forte		return;
221fcf3ce4John Forte	}
222fcf3ce4John Forte	fprintf(stdout, gettext("HBA Port WWN: %016llx\n"),
223fcf3ce4John Forte		wwnConversion(port->PortWWN.wwn));
224fcf3ce4John Forte	fprintf(stdout, gettext("\tPort Mode: %s\n"),
225fcf3ce4John Forte	    (mode == INITIATOR_MODE) ? "Initiator" : "Target");
226fcf3ce4John Forte	fprintf(stdout, gettext("\tPort ID: %x\n"),
227fcf3ce4John Forte	    port->PortFcId);
228fcf3ce4John Forte	fprintf(stdout, gettext("\tOS Device Name: %s\n"), port->OSDeviceName);
229fcf3ce4John Forte
230fcf3ce4John Forte	fprintf(stdout, gettext("\tManufacturer: %s\n"),
231fcf3ce4John Forte	    attrs->Manufacturer);
232fcf3ce4John Forte	fprintf(stdout, gettext("\tModel: %s\n"), attrs->Model);
233fcf3ce4John Forte	fprintf(stdout, gettext("\tFirmware Version: %s\n"),
234fcf3ce4John Forte	    attrs->FirmwareVersion);
235fcf3ce4John Forte	fprintf(stdout, gettext("\tFCode/BIOS Version: %s\n"),
236fcf3ce4John Forte	    attrs->OptionROMVersion);
237fcf3ce4John Forte	fprintf(stdout, gettext("\tSerial Number: %s\n"),
238fcf3ce4John Forte	    attrs->SerialNumber[0] == 0? "not available":attrs->SerialNumber);
239fcf3ce4John Forte
240fcf3ce4John Forte	fprintf(stdout, gettext("\tDriver Name: %s\n"),
241fcf3ce4John Forte	    attrs->DriverName[0] == 0? "not available":attrs->DriverName);
242fcf3ce4John Forte	fprintf(stdout, gettext("\tDriver Version: %s\n"),
243fcf3ce4John Forte	    attrs->DriverVersion[0] == 0? "not available":attrs->DriverVersion);
244fcf3ce4John Forte
245fcf3ce4John Forte	fprintf(stdout, gettext("\tType: %s\n"),
246fcf3ce4John Forte	    getPortType(port->PortType));
247fcf3ce4John Forte	fprintf(stdout, gettext("\tState: %s\n"),
248fcf3ce4John Forte	    getPortState(port->PortState));
249fcf3ce4John Forte
250fcf3ce4John Forte	fprintf(stdout, gettext("\tSupported Speeds: "));
251fcf3ce4John Forte	printPortSpeed(port->PortSupportedSpeed);
252fcf3ce4John Forte	fprintf(stdout, "\n");
253fcf3ce4John Forte
254fcf3ce4John Forte	fprintf(stdout, gettext("\tCurrent Speed: "));
255fcf3ce4John Forte	printPortSpeed(port->PortSpeed);
256fcf3ce4John Forte	fprintf(stdout, "\n");
257fcf3ce4John Forte
258fcf3ce4John Forte	fprintf(stdout, gettext("\tNode WWN: %016llx\n"),
259fcf3ce4John Forte	    wwnConversion(port->NodeWWN.wwn));
260fcf3ce4John Forte}
261fcf3ce4John Forte
262fcf3ce4John Fortevoid
263fcf3ce4John ForteprintStatus(HBA_STATUS status) {
264fcf3ce4John Forte	switch (status) {
265fcf3ce4John Forte		case HBA_STATUS_OK:
266fcf3ce4John Forte			fprintf(stderr, gettext("OK"));
267fcf3ce4John Forte			return;
268fcf3ce4John Forte		case HBA_STATUS_ERROR:
269fcf3ce4John Forte			fprintf(stderr, gettext("ERROR"));
270fcf3ce4John Forte			return;
271fcf3ce4John Forte		case HBA_STATUS_ERROR_NOT_SUPPORTED:
272fcf3ce4John Forte			fprintf(stderr, gettext("NOT SUPPORTED"));
273fcf3ce4John Forte			return;
274fcf3ce4John Forte		case HBA_STATUS_ERROR_INVALID_HANDLE:
275fcf3ce4John Forte			fprintf(stderr, gettext("INVALID HANDLE"));
276fcf3ce4John Forte			return;
277fcf3ce4John Forte		case HBA_STATUS_ERROR_ARG:
278fcf3ce4John Forte			fprintf(stderr, gettext("ERROR ARG"));
279fcf3ce4John Forte			return;
280fcf3ce4John Forte		case HBA_STATUS_ERROR_ILLEGAL_WWN:
281fcf3ce4John Forte			fprintf(stderr, gettext("ILLEGAL WWN"));
282fcf3ce4John Forte			return;
283fcf3ce4John Forte		case HBA_STATUS_ERROR_ILLEGAL_INDEX:
284fcf3ce4John Forte			fprintf(stderr, gettext("ILLEGAL INDEX"));
285fcf3ce4John Forte			return;
286fcf3ce4John Forte		case HBA_STATUS_ERROR_MORE_DATA:
287fcf3ce4John Forte			fprintf(stderr, gettext("MORE DATA"));
288fcf3ce4John Forte			return;
289fcf3ce4John Forte		case HBA_STATUS_ERROR_STALE_DATA:
290fcf3ce4John Forte			fprintf(stderr, gettext("STALE DATA"));
291fcf3ce4John Forte			return;
292fcf3ce4John Forte		case HBA_STATUS_SCSI_CHECK_CONDITION:
293fcf3ce4John Forte			fprintf(stderr, gettext("SCSI CHECK CONDITION"));
294fcf3ce4John Forte			return;
295fcf3ce4John Forte		case HBA_STATUS_ERROR_BUSY:
296fcf3ce4John Forte			fprintf(stderr, gettext("BUSY"));
297fcf3ce4John Forte			return;
298fcf3ce4John Forte		case HBA_STATUS_ERROR_TRY_AGAIN:
299fcf3ce4John Forte			fprintf(stderr, gettext("TRY AGAIN"));
300fcf3ce4John Forte			return;
301fcf3ce4John Forte		case HBA_STATUS_ERROR_UNAVAILABLE:
302fcf3ce4John Forte			fprintf(stderr, gettext("UNAVAILABLE"));
303fcf3ce4John Forte			return;
304fcf3ce4John Forte		default:
305fcf3ce4John Forte			fprintf(stderr, "%s %d",
306fcf3ce4John Forte			    gettext("Undefined error code "), status);
307fcf3ce4John Forte			return;
308fcf3ce4John Forte	}
309fcf3ce4John Forte}
310fcf3ce4John Forte
311fcf3ce4John Fortevoid
312fcf3ce4John ForteprintLUNInfo(struct scsi_inquiry *inq, HBA_UINT32 scsiLUN, char *devpath) {
313fcf3ce4John Forte	fprintf(stdout, "\tLUN: %d\n", scsiLUN);
314fcf3ce4John Forte	fprintf(stdout, "\t  Vendor: %c%c%c%c%c%c%c%c\n",
315fcf3ce4John Forte	    inq->inq_vid[0],
316fcf3ce4John Forte	    inq->inq_vid[1],
317fcf3ce4John Forte	    inq->inq_vid[2],
318fcf3ce4John Forte	    inq->inq_vid[3],
319fcf3ce4John Forte	    inq->inq_vid[4],
320fcf3ce4John Forte	    inq->inq_vid[5],
321fcf3ce4John Forte	    inq->inq_vid[6],
322fcf3ce4John Forte	    inq->inq_vid[7]);
323fcf3ce4John Forte	fprintf(stdout, "\t  Product: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
324fcf3ce4John Forte		    inq->inq_pid[0],
325fcf3ce4John Forte		    inq->inq_pid[1],
326fcf3ce4John Forte		    inq->inq_pid[2],
327fcf3ce4John Forte		    inq->inq_pid[3],
328fcf3ce4John Forte		    inq->inq_pid[4],
329fcf3ce4John Forte		    inq->inq_pid[5],
330fcf3ce4John Forte		    inq->inq_pid[6],
331fcf3ce4John Forte		    inq->inq_pid[7],
332fcf3ce4John Forte		    inq->inq_pid[8],
333fcf3ce4John Forte		    inq->inq_pid[9],
334fcf3ce4John Forte		    inq->inq_pid[10],
335fcf3ce4John Forte		    inq->inq_pid[11],
336fcf3ce4John Forte		    inq->inq_pid[12],
337fcf3ce4John Forte		    inq->inq_pid[13],
338fcf3ce4John Forte		    inq->inq_pid[14],
339fcf3ce4John Forte		    inq->inq_pid[15]);
340fcf3ce4John Forte	fprintf(stdout, gettext("\t  OS Device Name: %s\n"), devpath);
341fcf3ce4John Forte}
342fcf3ce4John Forte
343fcf3ce4John Fortevoid
344fcf3ce4John ForteprintPortStat(fc_rls_acc_t *rls_payload) {
345fcf3ce4John Forte	fprintf(stdout, gettext("\tLink Error Statistics:\n"));
346fcf3ce4John Forte	fprintf(stdout, gettext("\t\tLink Failure Count: %u\n"),
347fcf3ce4John Forte	    rls_payload->rls_link_fail);
348fcf3ce4John Forte	fprintf(stdout, gettext("\t\tLoss of Sync Count: %u\n"),
349fcf3ce4John Forte	    rls_payload->rls_sync_loss);
350fcf3ce4John Forte	fprintf(stdout, gettext("\t\tLoss of Signal Count: %u\n"),
351fcf3ce4John Forte	    rls_payload->rls_sig_loss);
352fcf3ce4John Forte	fprintf(stdout, gettext("\t\tPrimitive Seq Protocol Error Count: %u\n"),
353fcf3ce4John Forte	    rls_payload->rls_prim_seq_err);
354fcf3ce4John Forte	fprintf(stdout, gettext("\t\tInvalid Tx Word Count: %u\n"),
355fcf3ce4John Forte	    rls_payload->rls_invalid_word);
356fcf3ce4John Forte	fprintf(stdout, gettext("\t\tInvalid CRC Count: %u\n"),
357fcf3ce4John Forte	    rls_payload->rls_invalid_crc);
358fcf3ce4John Forte}
359fcf3ce4John Forte
360fcf3ce4John Forte/*
361fcf3ce4John Forte * return device type description
362fcf3ce4John Forte *
363fcf3ce4John Forte * Arguments:
364fcf3ce4John Forte *	dType - Device type returned from Standard INQUIRY
365fcf3ce4John Forte * Returns:
366fcf3ce4John Forte *	char string description for device type
367fcf3ce4John Forte */
368fcf3ce4John Fortestatic char *
369fcf3ce4John FortegetDTypeString(uchar_t dType)
370fcf3ce4John Forte{
371fcf3ce4John Forte	switch (dType & DTYPE_MASK) {
372fcf3ce4John Forte		case DTYPE_DIRECT:
373fcf3ce4John Forte			return ("Disk Device");
374fcf3ce4John Forte		case DTYPE_SEQUENTIAL:
375fcf3ce4John Forte			return ("Tape Device");
376fcf3ce4John Forte		case DTYPE_PRINTER:
377fcf3ce4John Forte			return ("Printer Device");
378fcf3ce4John Forte		case DTYPE_PROCESSOR:
379fcf3ce4John Forte			return ("Processor Device");
380fcf3ce4John Forte		case DTYPE_WORM:
381fcf3ce4John Forte			return ("WORM Device");
382fcf3ce4John Forte		case DTYPE_RODIRECT:
383fcf3ce4John Forte			return ("CD/DVD Device");
384fcf3ce4John Forte		case DTYPE_SCANNER:
385fcf3ce4John Forte			return ("Scanner Device");
386fcf3ce4John Forte		case DTYPE_OPTICAL:
387fcf3ce4John Forte			return ("Optical Memory Device");
388fcf3ce4John Forte		case DTYPE_CHANGER:
389fcf3ce4John Forte			return ("Medium Changer Device");
390fcf3ce4John Forte		case DTYPE_COMM:
391fcf3ce4John Forte			return ("Communications Device");
392fcf3ce4John Forte		case DTYPE_ARRAY_CTRL:
393fcf3ce4John Forte			return ("Storage Array Controller Device");
394fcf3ce4John Forte		case DTYPE_ESI:
395fcf3ce4John Forte			return ("Enclosure Services Device");
396fcf3ce4John Forte		case DTYPE_RBC:
397fcf3ce4John Forte			return ("Simplified Direct-access Device");
398fcf3ce4John Forte		case DTYPE_OCRW:
399fcf3ce4John Forte			return ("Optical Card Reader/Writer Device");
400fcf3ce4John Forte		case DTYPE_BCC:
401fcf3ce4John Forte			return ("Bridge Controller Commands");
402fcf3ce4John Forte		case DTYPE_OSD:
403fcf3ce4John Forte			return ("Object-based Storage Device");
404fcf3ce4John Forte		case DTYPE_ADC:
405fcf3ce4John Forte			return ("Automation/Drive Interface");
406fcf3ce4John Forte		case DTYPE_WELLKNOWN:
407fcf3ce4John Forte			return ("Well Known Logical Unit");
408fcf3ce4John Forte		case DTYPE_UNKNOWN:
409fcf3ce4John Forte			return ("Unknown Device");
410fcf3ce4John Forte		default:
411fcf3ce4John Forte			return ("Undefined");
412fcf3ce4John Forte	}
413fcf3ce4John Forte}
414fcf3ce4John Forte
415fcf3ce4John Forte/*
416fcf3ce4John Forte * print the OS device name for the logical-unit object
417fcf3ce4John Forte *
418fcf3ce4John Forte * Arguments:
419fcf3ce4John Forte *	devListWalk - OS device path info
420fcf3ce4John Forte *	verbose - boolean indicating whether to display additional info
421fcf3ce4John Forte *
422fcf3ce4John Forte * returns:
423fcf3ce4John Forte *	none
424fcf3ce4John Forte */
425fcf3ce4John Fortevoid
426fcf3ce4John ForteprintOSDeviceNameInfo(discoveredDevice *devListWalk, boolean_t verbose)
427fcf3ce4John Forte{
428fcf3ce4John Forte	portWWNList		*WWNList;
429fcf3ce4John Forte	tgtPortWWNList		*tgtWWNList;
430fcf3ce4John Forte	int			i, count;
431fcf3ce4John Forte
432fcf3ce4John Forte	fprintf(stdout, "OS Device Name: %s\n", devListWalk->OSDeviceName);
433fcf3ce4John Forte	if (verbose == B_TRUE) {
434fcf3ce4John Forte		for (WWNList = devListWalk->HBAPortWWN;
435fcf3ce4John Forte		    WWNList != NULL; WWNList = WWNList->next) {
436fcf3ce4John Forte			fprintf(stdout, "\tHBA Port WWN: ");
437fcf3ce4John Forte			fprintf(stdout, "%016llx",
438fcf3ce4John Forte			    wwnConversion(WWNList->portWWN.wwn));
439fcf3ce4John Forte			for (tgtWWNList = WWNList->tgtPortWWN;
440fcf3ce4John Forte			    tgtWWNList != NULL; tgtWWNList = tgtWWNList->next) {
441fcf3ce4John Forte				fprintf(stdout, "\n\t\tRemote Port WWN: ");
442fcf3ce4John Forte				fprintf(stdout, "%016llx",
443fcf3ce4John Forte				    wwnConversion(tgtWWNList->portWWN.wwn));
444fcf3ce4John Forte				fprintf(stdout, "\n\t\t\tLUN: %d",
445fcf3ce4John Forte				    tgtWWNList->scsiOSLun);
446fcf3ce4John Forte			}
447fcf3ce4John Forte			fprintf(stdout, "\n");
448fcf3ce4John Forte		}
449fcf3ce4John Forte
450fcf3ce4John Forte		fprintf(stdout, "\tVendor: ");
451fcf3ce4John Forte		for (count = sizeof (devListWalk->VID), i = 0; i < count; i++) {
452fcf3ce4John Forte			if (isprint(devListWalk->VID[i]))
453fcf3ce4John Forte				fprintf(stdout, "%c", devListWalk->VID[i]);
454fcf3ce4John Forte		}
455fcf3ce4John Forte
456fcf3ce4John Forte		fprintf(stdout, "\n\tProduct: ");
457fcf3ce4John Forte		for (count = sizeof (devListWalk->PID), i = 0; i < count; i++) {
458fcf3ce4John Forte			if (isprint(devListWalk->PID[i]))
459fcf3ce4John Forte				fprintf(stdout, "%c", devListWalk->PID[i]);
460fcf3ce4John Forte		}
461fcf3ce4John Forte
462fcf3ce4John Forte		fprintf(stdout, "\n\tDevice Type: %s\n",
463fcf3ce4John Forte		    getDTypeString(devListWalk->dType));
464fcf3ce4John Forte	}
465fcf3ce4John Forte}
466