17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
54ab75253Smrj  * Common Development and Distribution License (the "License").
64ab75253Smrj  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21*507c3241Smlf 
227c478bd9Sstevel@tonic-gate /*
23*507c3241Smlf  * Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
244ab75253Smrj  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
27*507c3241Smlf #include <sys/types.h>
28*507c3241Smlf #include <sys/byteorder.h>
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 
31*507c3241Smlf /*
32*507c3241Smlf  * functions to convert between host format and scsi format
33*507c3241Smlf  */
34*507c3241Smlf void
scsi_htos_3byte(unchar * ap,ulong nav)35*507c3241Smlf scsi_htos_3byte(unchar *ap, ulong nav)
36*507c3241Smlf {
37*507c3241Smlf 	*(ushort *)ap = (ushort)(((nav & 0xff0000) >> 16) | (nav & 0xff00));
38*507c3241Smlf 	ap[2] = (unchar)nav;
39*507c3241Smlf }
407c478bd9Sstevel@tonic-gate 
41*507c3241Smlf void
scsi_htos_long(unchar * ap,ulong niv)42*507c3241Smlf scsi_htos_long(unchar *ap, ulong niv)
43*507c3241Smlf {
44*507c3241Smlf 	*(ulong *)ap = htonl(niv);
45*507c3241Smlf }
467c478bd9Sstevel@tonic-gate 
47*507c3241Smlf void
scsi_htos_short(unchar * ap,ushort nsv)48*507c3241Smlf scsi_htos_short(unchar *ap, ushort nsv)
49*507c3241Smlf {
50*507c3241Smlf 	*(ushort *)ap = htons(nsv);
51*507c3241Smlf }
527c478bd9Sstevel@tonic-gate 
53*507c3241Smlf ulong
scsi_stoh_3byte(unchar * ap)54*507c3241Smlf scsi_stoh_3byte(unchar *ap)
55*507c3241Smlf {
56*507c3241Smlf 	register ulong av = *(ulong *)ap;
577c478bd9Sstevel@tonic-gate 
58*507c3241Smlf 	return (((av & 0xff) << 16) | (av & 0xff00) | ((av & 0xff0000) >> 16));
59*507c3241Smlf }
607c478bd9Sstevel@tonic-gate 
61*507c3241Smlf ulong
scsi_stoh_long(ulong ai)62*507c3241Smlf scsi_stoh_long(ulong ai)
63*507c3241Smlf {
64*507c3241Smlf 	return (ntohl(ai));
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate 
67*507c3241Smlf ushort
scsi_stoh_short(ushort as)68*507c3241Smlf scsi_stoh_short(ushort as)
69*507c3241Smlf {
70*507c3241Smlf 	return (ntohs(as));
71*507c3241Smlf }
72