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
5934f0bccShiremath  * Common Development and Distribution License (the "License").
6934f0bccShiremath  * 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  */
217c478bd9Sstevel@tonic-gate /*
22934f0bccShiremath  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
287c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
297c478bd9Sstevel@tonic-gate #include <sys/ib/mgt/ibmf/ibmf_saa_impl.h>
307c478bd9Sstevel@tonic-gate #include <sys/ib/mgt/ibmf/ibmf_saa_utils.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #define	IBMF_SAA_HDR_SIZE			20
337c478bd9Sstevel@tonic-gate #define	IBMF_SAA_DEFAULT_RID_SIZE		4
347c478bd9Sstevel@tonic-gate #define	IBMF_SAA_PARTITION_RID_SIZE		5
357c478bd9Sstevel@tonic-gate #define	IBMF_SAA_INFORMINFO_RID_SIZE		18
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #define	IB_MAD_NOTICE_SIZE			80
387c478bd9Sstevel@tonic-gate #define	IB_MAD_CLASSPORTINFO_SIZE		72
397c478bd9Sstevel@tonic-gate #define	IB_MAD_INFORMINFO_SIZE			36
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #define	SM_TRAP_DATA_DETAILS_SIZE		54
427c478bd9Sstevel@tonic-gate #define	SM_NODEINFO_SIZE			40
437c478bd9Sstevel@tonic-gate #define	SM_NODEDESC_SIZE			64
447c478bd9Sstevel@tonic-gate #define	SM_PORTINFO_SIZE			54
457c478bd9Sstevel@tonic-gate #define	SM_SLTOVL_SIZE				8
467c478bd9Sstevel@tonic-gate #define	SM_SWITCHINFO_SIZE			17
477c478bd9Sstevel@tonic-gate #define	SM_LINEARFDB_SIZE			64
487c478bd9Sstevel@tonic-gate #define	SM_RANDOMFDB_SIZE			64
497c478bd9Sstevel@tonic-gate #define	SM_MULTICASTFDB_SIZE			64
507c478bd9Sstevel@tonic-gate #define	SM_SMINFO_SIZE				21
517c478bd9Sstevel@tonic-gate #define	SM_GUIDINFO_SIZE			64
527c478bd9Sstevel@tonic-gate #define	SM_PARTITION_SIZE			64
537c478bd9Sstevel@tonic-gate #define	SM_VLARB_SIZE				64
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #define	IBMF_SAA_NODE_RECORD_SIZE		108
567c478bd9Sstevel@tonic-gate #define	IBMF_SAA_PORTINFO_RECORD_SIZE		58
577c478bd9Sstevel@tonic-gate #define	IBMF_SAA_SLTOVL_RECORD_SIZE		16
587c478bd9Sstevel@tonic-gate #define	IBMF_SAA_SWITCHINFO_RECORD_SIZE		21
597c478bd9Sstevel@tonic-gate #define	IBMF_SAA_LINEARFDB_RECORD_SIZE		72
607c478bd9Sstevel@tonic-gate #define	IBMF_SAA_RANDOMFDB_RECORD_SIZE		72
617c478bd9Sstevel@tonic-gate #define	IBMF_SAA_MULTICASTFDB_RECORD_SIZE	72
627c478bd9Sstevel@tonic-gate #define	IBMF_SAA_SMINFO_RECORD_SIZE		25
637c478bd9Sstevel@tonic-gate #define	IBMF_SAA_INFORMINFO_RECORD_SIZE		60
647c478bd9Sstevel@tonic-gate #define	IBMF_SAA_LINK_RECORD_SIZE		6
657c478bd9Sstevel@tonic-gate #define	IBMF_SAA_GUIDINFO_RECORD_SIZE		72
667c478bd9Sstevel@tonic-gate #define	IBMF_SAA_SERVICE_RECORD_SIZE		176
677c478bd9Sstevel@tonic-gate #define	IBMF_SAA_PARTITION_RECORD_SIZE		72
687c478bd9Sstevel@tonic-gate #define	IBMF_SAA_PATH_RECORD_SIZE		64
697c478bd9Sstevel@tonic-gate #define	IBMF_SAA_VLARB_RECORD_SIZE		72
707c478bd9Sstevel@tonic-gate #define	IBMF_SAA_MCMEMBER_RECORD_SIZE		52
717c478bd9Sstevel@tonic-gate #define	IBMF_SAA_TRACE_RECORD_SIZE		46
727c478bd9Sstevel@tonic-gate #define	IBMF_SAA_MULTIPATH_RECORD_SIZE		24
737c478bd9Sstevel@tonic-gate #define	IBMF_SAA_SERVICEASSN_RECORD_SIZE	80
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate extern	int	ibmf_trace_level;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /* These functions have only been tested on a big-endian system */
78934f0bccShiremath static void ibmf_saa_classportinfo_parse_buffer(uchar_t *buffer, void *record);
797c478bd9Sstevel@tonic-gate static void ibmf_saa_notice_parse_buffer(uchar_t *buffer, void *record);
807c478bd9Sstevel@tonic-gate static void ibmf_saa_informinfo_parse_buffer(uchar_t *buffer, void *record);
817c478bd9Sstevel@tonic-gate static void ibmf_saa_node_record_parse_buffer(uchar_t *buffer, void *record);
827c478bd9Sstevel@tonic-gate static void ibmf_saa_portinfo_record_parse_buffer(uchar_t *buffer,
837c478bd9Sstevel@tonic-gate     void *record);
847c478bd9Sstevel@tonic-gate static void ibmf_saa_SLtoVLmapping_record_parse_buffer(uchar_t *buffer,
857c478bd9Sstevel@tonic-gate     void *record);
867c478bd9Sstevel@tonic-gate static void ibmf_saa_switchinfo_record_parse_buffer(uchar_t *buffer,
877c478bd9Sstevel@tonic-gate     void *record);
887c478bd9Sstevel@tonic-gate static void ibmf_saa_linearft_record_parse_buffer(uchar_t *buffer,
897c478bd9Sstevel@tonic-gate     void *record);
907c478bd9Sstevel@tonic-gate static void ibmf_saa_randomft_record_parse_buffer(uchar_t *buffer,
917c478bd9Sstevel@tonic-gate     void *record);
927c478bd9Sstevel@tonic-gate static void ibmf_saa_multicastft_record_parse_buffer(uchar_t *buffer,
937c478bd9Sstevel@tonic-gate     void *record);
947c478bd9Sstevel@tonic-gate static void ibmf_saa_sminfo_record_parse_buffer(uchar_t *buffer, void *record);
957c478bd9Sstevel@tonic-gate static void ibmf_saa_informinfo_record_parse_buffer(uchar_t *buffer,
967c478bd9Sstevel@tonic-gate     void *record);
977c478bd9Sstevel@tonic-gate static void ibmf_saa_link_record_parse_buffer(uchar_t *buffer, void *record);
987c478bd9Sstevel@tonic-gate static void ibmf_saa_guidinfo_record_parse_buffer(uchar_t *buffer,
997c478bd9Sstevel@tonic-gate     void *record);
1007c478bd9Sstevel@tonic-gate static void ibmf_saa_service_record_parse_buffer(uchar_t *buffer, void *record);
1017c478bd9Sstevel@tonic-gate static void ibmf_saa_partition_record_parse_buffer(uchar_t *buffer,
1027c478bd9Sstevel@tonic-gate     void *record);
1037c478bd9Sstevel@tonic-gate static void ibmf_saa_path_record_parse_buffer(uchar_t *buffer, void *record);
1047c478bd9Sstevel@tonic-gate static void ibmf_saa_vlarb_record_parse_buffer(uchar_t *buffer, void *record);
1057c478bd9Sstevel@tonic-gate static void ibmf_saa_mcmember_record_parse_buffer(uchar_t *buffer,
1067c478bd9Sstevel@tonic-gate     void *record);
1077c478bd9Sstevel@tonic-gate static void ibmf_saa_trace_record_parse_buffer(uchar_t *buffer, void *record);
1087c478bd9Sstevel@tonic-gate static void ibmf_saa_multipath_record_parse_buffer(uchar_t *buffer,
1097c478bd9Sstevel@tonic-gate     void *record);
1107c478bd9Sstevel@tonic-gate static void ibmf_saa_service_assn_record_parse_buffer(uchar_t *buffer,
1117c478bd9Sstevel@tonic-gate     void *record);
1127c478bd9Sstevel@tonic-gate 
113934f0bccShiremath static void ibmf_saa_classportinfo_to_buf(void *record, uchar_t *buffer);
1147c478bd9Sstevel@tonic-gate static void ibmf_saa_notice_to_buf(void *record, uchar_t *buffer);
1157c478bd9Sstevel@tonic-gate static void ibmf_saa_informinfo_to_buf(void *record, uchar_t *buffer);
1167c478bd9Sstevel@tonic-gate static void ibmf_saa_node_record_to_buf(void *record, uchar_t *buffer);
1177c478bd9Sstevel@tonic-gate static void ibmf_saa_portinfo_record_to_buf(void *record, uchar_t *buffer);
1187c478bd9Sstevel@tonic-gate static void ibmf_saa_SLtoVLmapping_record_to_buf(void *record, uchar_t *buffer);
1197c478bd9Sstevel@tonic-gate static void ibmf_saa_switchinfo_record_to_buf(void *record, uchar_t *buffer);
1207c478bd9Sstevel@tonic-gate static void ibmf_saa_linearft_record_to_buf(void *record, uchar_t *buffer);
1217c478bd9Sstevel@tonic-gate static void ibmf_saa_randomft_record_to_buf(void *record, uchar_t *buffer);
1227c478bd9Sstevel@tonic-gate static void ibmf_saa_multicastft_record_to_buf(void *record, uchar_t *buffer);
1237c478bd9Sstevel@tonic-gate static void ibmf_saa_sminfo_record_to_buf(void *record, uchar_t *buffer);
1247c478bd9Sstevel@tonic-gate static void ibmf_saa_informinfo_record_to_buf(void *record, uchar_t *buffer);
1257c478bd9Sstevel@tonic-gate static void ibmf_saa_link_record_to_buf(void *record, uchar_t *buffer);
1267c478bd9Sstevel@tonic-gate static void ibmf_saa_guidinfo_record_to_buf(void *record, uchar_t *buffer);
1277c478bd9Sstevel@tonic-gate static void ibmf_saa_service_record_to_buf(void *record, uchar_t *buffer);
1287c478bd9Sstevel@tonic-gate static void ibmf_saa_partition_record_to_buf(void *record, uchar_t *buffer);
1297c478bd9Sstevel@tonic-gate static void ibmf_saa_path_record_to_buf(void *record, uchar_t *buffer);
1307c478bd9Sstevel@tonic-gate static void ibmf_saa_vlarb_record_to_buf(void *record, uchar_t *buffer);
1317c478bd9Sstevel@tonic-gate static void ibmf_saa_mcmember_record_to_buf(void *record, uchar_t *buffer);
1327c478bd9Sstevel@tonic-gate static void ibmf_saa_multipath_record_to_buf(void *record, uchar_t *buffer);
1337c478bd9Sstevel@tonic-gate static void ibmf_saa_service_assn_record_to_buf(void *record, uchar_t *buffer);
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate /*
1367c478bd9Sstevel@tonic-gate  * *_record_parse_buffer functions:
1377c478bd9Sstevel@tonic-gate  *
1387c478bd9Sstevel@tonic-gate  * Each of these functions parses a buffer containing a single SA record.
1397c478bd9Sstevel@tonic-gate  * The function copies the buffer into a structure taking care of any padding
1407c478bd9Sstevel@tonic-gate  * and byte-endianness issues.  There is one function for each of the 22
1417c478bd9Sstevel@tonic-gate  * attributes (Table 155).
1427c478bd9Sstevel@tonic-gate  *
1437c478bd9Sstevel@tonic-gate  * ibmf_utils_unpack_data() must be called for each structure in the structure
1447c478bd9Sstevel@tonic-gate  * since Solaris will align the internal structure on a 64-bit boundary, even if
1457c478bd9Sstevel@tonic-gate  * the first element is a 32-bit value.
1467c478bd9Sstevel@tonic-gate  *
1477c478bd9Sstevel@tonic-gate  * Input Arguments
1487c478bd9Sstevel@tonic-gate  * buffer	pointer character array containing raw data
1497c478bd9Sstevel@tonic-gate  *
1507c478bd9Sstevel@tonic-gate  * Output Arguments
1517c478bd9Sstevel@tonic-gate  * record	pointer to the SA attribute structure
1527c478bd9Sstevel@tonic-gate  *
1537c478bd9Sstevel@tonic-gate  * Returns	void
1547c478bd9Sstevel@tonic-gate  */
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate static void
ibmf_saa_classportinfo_parse_buffer(uchar_t * buffer,void * record)157934f0bccShiremath ibmf_saa_classportinfo_parse_buffer(uchar_t *buffer, void *record)
1587c478bd9Sstevel@tonic-gate {
159934f0bccShiremath 	ib_mad_classportinfo_t	*cpi = (ib_mad_classportinfo_t *)record;
160934f0bccShiremath 
161934f0bccShiremath 	ibmf_utils_unpack_data("2csl2Ll2s2l2Ll2s2l", buffer,
162934f0bccShiremath 	    IB_MAD_CLASSPORTINFO_SIZE, cpi, sizeof (ib_mad_classportinfo_t));
163934f0bccShiremath }
1647c478bd9Sstevel@tonic-gate 
165934f0bccShiremath static void
ibmf_saa_notice_parse_buffer(uchar_t * buffer,void * record)166934f0bccShiremath ibmf_saa_notice_parse_buffer(uchar_t *buffer, void *record)
167934f0bccShiremath {
1687c478bd9Sstevel@tonic-gate 	ib_mad_notice_t		*notice = (ib_mad_notice_t *)record;
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("4c3s54c2L", buffer, IB_MAD_NOTICE_SIZE,
1717c478bd9Sstevel@tonic-gate 	    notice, sizeof (ib_mad_notice_t));
1727c478bd9Sstevel@tonic-gate }
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate static void
ibmf_saa_informinfo_parse_buffer(uchar_t * buffer,void * record)1757c478bd9Sstevel@tonic-gate ibmf_saa_informinfo_parse_buffer(uchar_t *buffer, void *record)
1767c478bd9Sstevel@tonic-gate {
1777c478bd9Sstevel@tonic-gate 	ib_mad_informinfo_t	*informinfo = (ib_mad_informinfo_t *)record;
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("2L3s2c2s2l", buffer, IB_MAD_INFORMINFO_SIZE,
1807c478bd9Sstevel@tonic-gate 	    informinfo, sizeof (ib_mad_informinfo_t));
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate static void
ibmf_saa_node_record_parse_buffer(uchar_t * buffer,void * record)1847c478bd9Sstevel@tonic-gate ibmf_saa_node_record_parse_buffer(uchar_t *buffer, void *record)
1857c478bd9Sstevel@tonic-gate {
1867c478bd9Sstevel@tonic-gate 	sa_node_record_t	*node_record = (sa_node_record_t *)record;
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	/* first get record identifier information */
1897c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("2s", buffer, IBMF_SAA_DEFAULT_RID_SIZE,
1907c478bd9Sstevel@tonic-gate 	    node_record, 4);
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE;
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	/* next get node info */
1957c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("4c3L2s2l", buffer, SM_NODEINFO_SIZE,
1967c478bd9Sstevel@tonic-gate 	    &node_record->NodeInfo, sizeof (sm_nodeinfo_t));
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	buffer += SM_NODEINFO_SIZE;
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("64c", buffer, SM_NODEDESC_SIZE,
2017c478bd9Sstevel@tonic-gate 	    &node_record->NodeDescription, sizeof (sm_nodedesc_t));
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate static void
ibmf_saa_portinfo_record_parse_buffer(uchar_t * buffer,void * record)2057c478bd9Sstevel@tonic-gate ibmf_saa_portinfo_record_parse_buffer(uchar_t *buffer, void *record)
2067c478bd9Sstevel@tonic-gate {
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	sa_portinfo_record_t	*portinfo_record =
2097c478bd9Sstevel@tonic-gate 	    (sa_portinfo_record_t *)record;
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	/* first get record identifier information */
2127c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("s2c", buffer, IBMF_SAA_DEFAULT_RID_SIZE,
2137c478bd9Sstevel@tonic-gate 	    portinfo_record, 4);
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE;
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate 	/* next get portinfo info */
2187c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("LLsslss16c3s4c", buffer, SM_PORTINFO_SIZE,
2197c478bd9Sstevel@tonic-gate 	    &portinfo_record->PortInfo, sizeof (sm_portinfo_t));
2207c478bd9Sstevel@tonic-gate }
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate static void
ibmf_saa_SLtoVLmapping_record_parse_buffer(uchar_t * buffer,void * record)2237c478bd9Sstevel@tonic-gate ibmf_saa_SLtoVLmapping_record_parse_buffer(uchar_t *buffer, void *record)
2247c478bd9Sstevel@tonic-gate {
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 	sa_SLtoVLmapping_record_t	*SLtoVLmapping_record =
2277c478bd9Sstevel@tonic-gate 	    (sa_SLtoVLmapping_record_t *)record;
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	/* first get record identifier information (plus 4 bytes reserved) */
2307c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("s2cl", buffer, IBMF_SAA_DEFAULT_RID_SIZE + 4,
2317c478bd9Sstevel@tonic-gate 	    SLtoVLmapping_record, 8);
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	/* SLtoVL mapping has 4 reserved bytes between RID and attribute */
2347c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE + 4;
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate 	/* next get SLtoVLmapping info */
2377c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("8c", buffer, SM_SLTOVL_SIZE,
2387c478bd9Sstevel@tonic-gate 	    &SLtoVLmapping_record->SLtoVLMappingTable,
2397c478bd9Sstevel@tonic-gate 	    sizeof (sm_SLtoVL_mapping_table_t));
2407c478bd9Sstevel@tonic-gate }
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate static void
ibmf_saa_switchinfo_record_parse_buffer(uchar_t * buffer,void * record)2437c478bd9Sstevel@tonic-gate ibmf_saa_switchinfo_record_parse_buffer(uchar_t *buffer, void *record)
2447c478bd9Sstevel@tonic-gate {
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate 	sa_switchinfo_record_t	*switchinfo_record =
2477c478bd9Sstevel@tonic-gate 	    (sa_switchinfo_record_t *)record;
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	/* first get record identifier information */
2507c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("2s", buffer, IBMF_SAA_DEFAULT_RID_SIZE,
2517c478bd9Sstevel@tonic-gate 	    switchinfo_record, 4);
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE;
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	/* next get switchinfo info */
2567c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("4s4c2sc", buffer, SM_SWITCHINFO_SIZE,
2577c478bd9Sstevel@tonic-gate 	    &switchinfo_record->SwitchInfo, sizeof (sm_switchinfo_t));
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate }
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate static void
ibmf_saa_linearft_record_parse_buffer(uchar_t * buffer,void * record)2627c478bd9Sstevel@tonic-gate ibmf_saa_linearft_record_parse_buffer(uchar_t *buffer, void *record)
2637c478bd9Sstevel@tonic-gate {
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate 	sa_linearft_record_t	*linearft_record =
2667c478bd9Sstevel@tonic-gate 	    (sa_linearft_record_t *)record;
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 	/* first get record identifier information (plus 4 bytes reserved) */
2697c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("2sl", buffer, IBMF_SAA_DEFAULT_RID_SIZE + 4,
2707c478bd9Sstevel@tonic-gate 	    linearft_record, 8);
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	/* LFT has 4 reserved bytes between RID and attribute */
2737c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE + 4;
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	/* next get linearft info */
2767c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("64c", buffer, SM_LINEARFDB_SIZE,
2777c478bd9Sstevel@tonic-gate 	    &linearft_record->LinearFT, sizeof (sm_linear_forwarding_table_t));
2787c478bd9Sstevel@tonic-gate }
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate static void
ibmf_saa_randomft_record_parse_buffer(uchar_t * buffer,void * record)2817c478bd9Sstevel@tonic-gate ibmf_saa_randomft_record_parse_buffer(uchar_t *buffer, void *record)
2827c478bd9Sstevel@tonic-gate {
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	sa_randomft_record_t	*randomft_record =
2857c478bd9Sstevel@tonic-gate 	    (sa_randomft_record_t *)record;
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 	/* first get record identifier information (plus 4 bytes reserved) */
2887c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("2sl", buffer, IBMF_SAA_DEFAULT_RID_SIZE + 4,
2897c478bd9Sstevel@tonic-gate 	    randomft_record, 8);
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 	/* RFT has 4 reserved bytes between RID and attribute */
2927c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE + 4;
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	/* next get randomft info */
2957c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("64c", buffer, SM_RANDOMFDB_SIZE,
2967c478bd9Sstevel@tonic-gate 	    &randomft_record->RandomFT, sizeof (sm_random_forwarding_table_t));
2977c478bd9Sstevel@tonic-gate }
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate static void
ibmf_saa_multicastft_record_parse_buffer(uchar_t * buffer,void * record)3007c478bd9Sstevel@tonic-gate ibmf_saa_multicastft_record_parse_buffer(uchar_t *buffer, void *record)
3017c478bd9Sstevel@tonic-gate {
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	sa_multicastft_record_t	*multicastft_record =
3047c478bd9Sstevel@tonic-gate 	    (sa_multicastft_record_t *)record;
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 	/* first get record identifier information (plus 4 bytes reserved) */
3077c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("2sl", buffer, IBMF_SAA_DEFAULT_RID_SIZE + 4,
3087c478bd9Sstevel@tonic-gate 	    multicastft_record, 8);
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 	/* MFT has 4 reserved bytes between RID and attribute */
3117c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE + 4;
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 	/* next get multicastft info */
3147c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("32s", buffer, SM_MULTICASTFDB_SIZE,
3157c478bd9Sstevel@tonic-gate 	    &multicastft_record->MulticastFT,
3167c478bd9Sstevel@tonic-gate 	    sizeof (sm_multicast_forwarding_table_t));
3177c478bd9Sstevel@tonic-gate }
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate static void
ibmf_saa_sminfo_record_parse_buffer(uchar_t * buffer,void * record)3207c478bd9Sstevel@tonic-gate ibmf_saa_sminfo_record_parse_buffer(uchar_t *buffer, void *record)
3217c478bd9Sstevel@tonic-gate {
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 	sa_sminfo_record_t	*sminfo_record =
3247c478bd9Sstevel@tonic-gate 	    (sa_sminfo_record_t *)record;
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	/* first get record identifier information */
3277c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("2s", buffer, IBMF_SAA_DEFAULT_RID_SIZE,
3287c478bd9Sstevel@tonic-gate 	    sminfo_record, 4);
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE;
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 	/* next get sminfo info */
3337c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("2Llc", buffer, SM_SMINFO_SIZE,
3347c478bd9Sstevel@tonic-gate 	    &sminfo_record->SMInfo,
3357c478bd9Sstevel@tonic-gate 	    sizeof (sm_sminfo_t));
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate static void
ibmf_saa_informinfo_record_parse_buffer(uchar_t * buffer,void * record)3397c478bd9Sstevel@tonic-gate ibmf_saa_informinfo_record_parse_buffer(uchar_t *buffer, void *record)
3407c478bd9Sstevel@tonic-gate {
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	sa_informinfo_record_t	*informinfo_record =
3437c478bd9Sstevel@tonic-gate 	    (sa_informinfo_record_t *)record;
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	/* first get record identifier information */
3467c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("2Ls", buffer, IBMF_SAA_INFORMINFO_RID_SIZE,
3477c478bd9Sstevel@tonic-gate 	    informinfo_record, 18);
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 	/* InformInfo has 6 reserved bytes between RID and attribute */
3507c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_INFORMINFO_RID_SIZE + 6;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	/* next get informinfo info */
3537c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("2L3s2c2s2l", buffer, IB_MAD_INFORMINFO_SIZE,
3547c478bd9Sstevel@tonic-gate 	    &informinfo_record->InformInfo,
3557c478bd9Sstevel@tonic-gate 	    sizeof (ib_mad_informinfo_t));
3567c478bd9Sstevel@tonic-gate }
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate static void
ibmf_saa_link_record_parse_buffer(uchar_t * buffer,void * record)3597c478bd9Sstevel@tonic-gate ibmf_saa_link_record_parse_buffer(uchar_t *buffer, void *record)
3607c478bd9Sstevel@tonic-gate {
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate 	sa_link_record_t	*link_record = (sa_link_record_t *)record;
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("s2cs", buffer, IBMF_SAA_LINK_RECORD_SIZE,
3657c478bd9Sstevel@tonic-gate 	    link_record, sizeof (sa_link_record_t));
3667c478bd9Sstevel@tonic-gate }
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate static void
ibmf_saa_guidinfo_record_parse_buffer(uchar_t * buffer,void * record)3697c478bd9Sstevel@tonic-gate ibmf_saa_guidinfo_record_parse_buffer(uchar_t *buffer, void *record)
3707c478bd9Sstevel@tonic-gate {
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate 	sa_guidinfo_record_t	*guidinfo_record =
3737c478bd9Sstevel@tonic-gate 	    (sa_guidinfo_record_t *)record;
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate 	/* first get record identifier information (plus 4 bytes reserved) */
3767c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("s2cl", buffer, IBMF_SAA_DEFAULT_RID_SIZE + 4,
3777c478bd9Sstevel@tonic-gate 	    guidinfo_record, 8);
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate 	/* GUIDInfo has 4 reserved bytes between RID and attribute */
3807c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE + 4;
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate 	/* next get guidinfo info */
3837c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("8L", buffer, SM_GUIDINFO_SIZE,
3847c478bd9Sstevel@tonic-gate 	    &guidinfo_record->GUIDInfo, sizeof (sm_guidinfo_t));
3857c478bd9Sstevel@tonic-gate }
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate static void
ibmf_saa_service_record_parse_buffer(uchar_t * buffer,void * record)3887c478bd9Sstevel@tonic-gate ibmf_saa_service_record_parse_buffer(uchar_t *buffer, void *record)
3897c478bd9Sstevel@tonic-gate {
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate 	sa_service_record_t	*service_record = (sa_service_record_t *)record;
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("3L2sl2L64c16c8s4l2L", buffer,
3947c478bd9Sstevel@tonic-gate 	    IBMF_SAA_SERVICE_RECORD_SIZE, service_record,
3957c478bd9Sstevel@tonic-gate 	    sizeof (sa_service_record_t));
3967c478bd9Sstevel@tonic-gate }
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate static void
ibmf_saa_partition_record_parse_buffer(uchar_t * buffer,void * record)3997c478bd9Sstevel@tonic-gate ibmf_saa_partition_record_parse_buffer(uchar_t *buffer, void *record)
4007c478bd9Sstevel@tonic-gate {
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate 	sa_pkey_table_record_t	*partition_record =
4037c478bd9Sstevel@tonic-gate 	    (sa_pkey_table_record_t *)record;
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate 	/* first get record identifier information (plus 4 bytes reserved) */
4067c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("2s4c", buffer, IBMF_SAA_PARTITION_RID_SIZE + 3,
4077c478bd9Sstevel@tonic-gate 	    partition_record, 8);
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 	/* Partition record has 3 reserved bytes between RID and attribute */
4107c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_PARTITION_RID_SIZE + 3;
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate 	/* next get partition info */
4137c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("32s",  buffer, SM_PARTITION_SIZE,
4147c478bd9Sstevel@tonic-gate 	    &partition_record->P_KeyTable, sizeof (sm_pkey_table_t));
4157c478bd9Sstevel@tonic-gate }
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate static void
ibmf_saa_path_record_parse_buffer(uchar_t * buffer,void * record)4187c478bd9Sstevel@tonic-gate ibmf_saa_path_record_parse_buffer(uchar_t *buffer, void *record)
4197c478bd9Sstevel@tonic-gate {
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate 	sa_path_record_t	*path_record = (sa_path_record_t *)record;
4227c478bd9Sstevel@tonic-gate 
4237c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("2l4L2sl2c2s4c", buffer,
4247c478bd9Sstevel@tonic-gate 	    IBMF_SAA_PATH_RECORD_SIZE, path_record, sizeof (sa_path_record_t));
4257c478bd9Sstevel@tonic-gate }
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate static void
ibmf_saa_vlarb_record_parse_buffer(uchar_t * buffer,void * record)4287c478bd9Sstevel@tonic-gate ibmf_saa_vlarb_record_parse_buffer(uchar_t *buffer, void *record)
4297c478bd9Sstevel@tonic-gate {
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 	sa_VLarb_table_record_t	*VLarb_table_record =
4327c478bd9Sstevel@tonic-gate 	    (sa_VLarb_table_record_t *)record;
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate 	/* first get record identifier information (plus 4 bytes reserved) */
4357c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("s2c", buffer, IBMF_SAA_DEFAULT_RID_SIZE + 4,
4367c478bd9Sstevel@tonic-gate 	    VLarb_table_record, 8);
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate 	/* VLarb record has 4 reserved bytes between RID and attribute */
4397c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE + 4;
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate 	/* next get VLarb_table info */
4427c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("64c", buffer, SM_VLARB_SIZE,
4437c478bd9Sstevel@tonic-gate 	    &VLarb_table_record->VLArbTable,
4447c478bd9Sstevel@tonic-gate 	    sizeof (sm_VLarb_table_t));
4457c478bd9Sstevel@tonic-gate }
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate static void
ibmf_saa_mcmember_record_parse_buffer(uchar_t * buffer,void * record)4487c478bd9Sstevel@tonic-gate ibmf_saa_mcmember_record_parse_buffer(uchar_t *buffer, void *record)
4497c478bd9Sstevel@tonic-gate {
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate 	sa_mcmember_record_t	*mcmember_record =
4527c478bd9Sstevel@tonic-gate 	    (sa_mcmember_record_t *)record;
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("4Lls2cs2c2l", buffer,
4557c478bd9Sstevel@tonic-gate 	    IBMF_SAA_MCMEMBER_RECORD_SIZE,
4567c478bd9Sstevel@tonic-gate 	    mcmember_record, sizeof (sa_mcmember_record_t));
4577c478bd9Sstevel@tonic-gate }
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate static void
ibmf_saa_trace_record_parse_buffer(uchar_t * buffer,void * record)4607c478bd9Sstevel@tonic-gate ibmf_saa_trace_record_parse_buffer(uchar_t *buffer, void *record)
4617c478bd9Sstevel@tonic-gate {
4627c478bd9Sstevel@tonic-gate 
4637c478bd9Sstevel@tonic-gate 	sa_trace_record_t	*trace_record =
4647c478bd9Sstevel@tonic-gate 	    (sa_trace_record_t *)record;
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("Ls2c4L2c", buffer,
4677c478bd9Sstevel@tonic-gate 	    IBMF_SAA_TRACE_RECORD_SIZE,
4687c478bd9Sstevel@tonic-gate 	    trace_record, sizeof (sa_trace_record_t));
4697c478bd9Sstevel@tonic-gate }
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate /*
4727c478bd9Sstevel@tonic-gate  * ibmf_saa_multipath_record_parse_buffer:
4737c478bd9Sstevel@tonic-gate  *
4747c478bd9Sstevel@tonic-gate  * First unpack the standard part of the multipath record.  Then find the number
4757c478bd9Sstevel@tonic-gate  * of gids and unpack those.  This function will probably never be called as the
4767c478bd9Sstevel@tonic-gate  * ibmf_saa should not receive any multipath records.  It's in here for
4777c478bd9Sstevel@tonic-gate  * completeness.
4787c478bd9Sstevel@tonic-gate  */
ibmf_saa_multipath_record_parse_buffer(uchar_t * buffer,void * record)4797c478bd9Sstevel@tonic-gate static void ibmf_saa_multipath_record_parse_buffer(uchar_t *buffer,
4807c478bd9Sstevel@tonic-gate     void *record)
4817c478bd9Sstevel@tonic-gate {
4827c478bd9Sstevel@tonic-gate 	char			gid_str[20];
4837c478bd9Sstevel@tonic-gate 	uint16_t		num_gids;
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 	sa_multipath_record_t	*multipath_record =
486*03b18ed2SToomas Soome 	    (sa_multipath_record_t *)record;
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("l2c2s14c", buffer,
4897c478bd9Sstevel@tonic-gate 	    IBMF_SAA_MULTIPATH_RECORD_SIZE, multipath_record,
4907c478bd9Sstevel@tonic-gate 	    sizeof (sa_multipath_record_t));
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate 	num_gids = multipath_record->SGIDCount + multipath_record->DGIDCount;
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate 	(void) sprintf(gid_str, "%dL", 2 * num_gids);
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data(gid_str, buffer + IBMF_SAA_MULTIPATH_RECORD_SIZE,
4977c478bd9Sstevel@tonic-gate 	    sizeof (ib_gid_t) * num_gids,
4987c478bd9Sstevel@tonic-gate 	    multipath_record + sizeof (sa_multipath_record_t),
4997c478bd9Sstevel@tonic-gate 	    sizeof (ib_gid_t) * num_gids);
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate }
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate static void
ibmf_saa_service_assn_record_parse_buffer(uchar_t * buffer,void * record)5047c478bd9Sstevel@tonic-gate ibmf_saa_service_assn_record_parse_buffer(uchar_t *buffer, void *record)
5057c478bd9Sstevel@tonic-gate {
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate 	sa_service_assn_record_t	*service_assn_record =
5087c478bd9Sstevel@tonic-gate 	    (sa_service_assn_record_t *)record;
5097c478bd9Sstevel@tonic-gate 
5107c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("2L64c", buffer,
5117c478bd9Sstevel@tonic-gate 	    IBMF_SAA_SERVICEASSN_RECORD_SIZE,
5127c478bd9Sstevel@tonic-gate 	    service_assn_record, sizeof (sa_service_assn_record_t));
5137c478bd9Sstevel@tonic-gate }
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate void
ibmf_saa_gid_trap_parse_buffer(uchar_t * buffer,sm_trap_64_t * sm_trap_64)5167c478bd9Sstevel@tonic-gate ibmf_saa_gid_trap_parse_buffer(uchar_t *buffer, sm_trap_64_t *sm_trap_64)
5177c478bd9Sstevel@tonic-gate {
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("6c2L32c", buffer, SM_TRAP_DATA_DETAILS_SIZE,
5207c478bd9Sstevel@tonic-gate 	    sm_trap_64, sizeof (sm_trap_64_t));
5217c478bd9Sstevel@tonic-gate }
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate void
ibmf_saa_capmask_chg_trap_parse_buffer(uchar_t * buffer,sm_trap_144_t * sm_trap_144)5247c478bd9Sstevel@tonic-gate ibmf_saa_capmask_chg_trap_parse_buffer(uchar_t *buffer,
5257c478bd9Sstevel@tonic-gate     sm_trap_144_t *sm_trap_144)
5267c478bd9Sstevel@tonic-gate {
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("2cs2cl44c", buffer, SM_TRAP_DATA_DETAILS_SIZE,
5297c478bd9Sstevel@tonic-gate 	    sm_trap_144, sizeof (sm_trap_144_t));
5307c478bd9Sstevel@tonic-gate }
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate void
ibmf_saa_sysimg_guid_chg_trap_parse_buffer(uchar_t * buffer,sm_trap_145_t * sm_trap_145)5337c478bd9Sstevel@tonic-gate ibmf_saa_sysimg_guid_chg_trap_parse_buffer(uchar_t *buffer,
5347c478bd9Sstevel@tonic-gate     sm_trap_145_t *sm_trap_145)
5357c478bd9Sstevel@tonic-gate {
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("2cs2cL44c", buffer, SM_TRAP_DATA_DETAILS_SIZE,
5387c478bd9Sstevel@tonic-gate 	    sm_trap_145, sizeof (sm_trap_145_t));
5397c478bd9Sstevel@tonic-gate }
5407c478bd9Sstevel@tonic-gate 
5417c478bd9Sstevel@tonic-gate /*
5427c478bd9Sstevel@tonic-gate  * *_record_to_buf functions:
5437c478bd9Sstevel@tonic-gate  *
5447c478bd9Sstevel@tonic-gate  * Each of these functions copies a single SA record out of a structure and into
5457c478bd9Sstevel@tonic-gate  * a buffer for sending on the wire.  The function will take care of any padding
5467c478bd9Sstevel@tonic-gate  * and byte-endianness isues.  There is one function for each of the 22
5477c478bd9Sstevel@tonic-gate  * attributes (Table 155).
5487c478bd9Sstevel@tonic-gate  *
5497c478bd9Sstevel@tonic-gate  * ibmf_utils_pack_data() must be called for each structure in the structure
5507c478bd9Sstevel@tonic-gate  * since Solaris will align the internal structure on a 64-bit boundary, even if
5517c478bd9Sstevel@tonic-gate  * the first element is a 32-bit value.
5527c478bd9Sstevel@tonic-gate  *
5537c478bd9Sstevel@tonic-gate  * Input Arguments
5547c478bd9Sstevel@tonic-gate  * record	pointer to the structure to be parsed
5557c478bd9Sstevel@tonic-gate  *
5567c478bd9Sstevel@tonic-gate  * Output Arguments
5577c478bd9Sstevel@tonic-gate  * buffer	pointer to array to place the data in (allocated by caller)
5587c478bd9Sstevel@tonic-gate  *
5597c478bd9Sstevel@tonic-gate  * Returns	void
5607c478bd9Sstevel@tonic-gate  */
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate static void
ibmf_saa_classportinfo_to_buf(void * record,uchar_t * buffer)563934f0bccShiremath ibmf_saa_classportinfo_to_buf(void *record, uchar_t *buffer)
5647c478bd9Sstevel@tonic-gate {
565934f0bccShiremath 	ib_mad_classportinfo_t	*cpi = (ib_mad_classportinfo_t *)record;
5667c478bd9Sstevel@tonic-gate 
567934f0bccShiremath 	ibmf_utils_pack_data("2csl2Ll2s2l2Ll2s2l",
568934f0bccShiremath 	    cpi, sizeof (ib_mad_classportinfo_t),
569934f0bccShiremath 	    buffer, IB_MAD_CLASSPORTINFO_SIZE);
570934f0bccShiremath }
571934f0bccShiremath 
572934f0bccShiremath static void
ibmf_saa_notice_to_buf(void * record,uchar_t * buffer)573934f0bccShiremath ibmf_saa_notice_to_buf(void *record, uchar_t *buffer)
574934f0bccShiremath {
5757c478bd9Sstevel@tonic-gate 	ib_mad_notice_t		*notice = (ib_mad_notice_t *)record;
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("4c3s54c2L", notice, sizeof (ib_mad_notice_t),
5787c478bd9Sstevel@tonic-gate 	    buffer, IB_MAD_NOTICE_SIZE);
5797c478bd9Sstevel@tonic-gate }
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate static void
ibmf_saa_informinfo_to_buf(void * record,uchar_t * buffer)5827c478bd9Sstevel@tonic-gate ibmf_saa_informinfo_to_buf(void *record, uchar_t *buffer)
5837c478bd9Sstevel@tonic-gate {
5847c478bd9Sstevel@tonic-gate 	ib_mad_informinfo_t	*informinfo = (ib_mad_informinfo_t *)record;
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("2L3s2c2s2l", informinfo,
5877c478bd9Sstevel@tonic-gate 	    sizeof (ib_mad_informinfo_t), buffer, IB_MAD_INFORMINFO_SIZE);
5887c478bd9Sstevel@tonic-gate }
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate static void
ibmf_saa_node_record_to_buf(void * record,uchar_t * buffer)5917c478bd9Sstevel@tonic-gate ibmf_saa_node_record_to_buf(void *record, uchar_t *buffer)
5927c478bd9Sstevel@tonic-gate {
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate 	sa_node_record_t	*node_record = (sa_node_record_t *)record;
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate 	/* first get record identifier information */
5977c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("2s", node_record, 4, buffer,
5987c478bd9Sstevel@tonic-gate 	    IBMF_SAA_DEFAULT_RID_SIZE);
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE;
6017c478bd9Sstevel@tonic-gate 
6027c478bd9Sstevel@tonic-gate 	/* next get node info */
6037c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("4c3L2s2l", &node_record->NodeInfo,
6047c478bd9Sstevel@tonic-gate 	    sizeof (sm_nodeinfo_t), buffer, SM_NODEINFO_SIZE);
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate 	buffer += SM_NODEINFO_SIZE;
6077c478bd9Sstevel@tonic-gate 
6087c478bd9Sstevel@tonic-gate 	/* next get node description */
6097c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("64c", &node_record->NodeDescription,
6107c478bd9Sstevel@tonic-gate 	    sizeof (sm_nodedesc_t), buffer, SM_NODEDESC_SIZE);
6117c478bd9Sstevel@tonic-gate 
6127c478bd9Sstevel@tonic-gate }
6137c478bd9Sstevel@tonic-gate 
6147c478bd9Sstevel@tonic-gate static void
ibmf_saa_portinfo_record_to_buf(void * record,uchar_t * buffer)6157c478bd9Sstevel@tonic-gate ibmf_saa_portinfo_record_to_buf(void *record, uchar_t *buffer)
6167c478bd9Sstevel@tonic-gate {
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate 	sa_portinfo_record_t	*portinfo_record =
6197c478bd9Sstevel@tonic-gate 	    (sa_portinfo_record_t *)record;
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate 	/* first get record identifier information */
6227c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("s2c", portinfo_record, 4, buffer,
6237c478bd9Sstevel@tonic-gate 	    IBMF_SAA_DEFAULT_RID_SIZE);
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE;
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate 	/* next get portinfo info */
6287c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("LLsslss16c3s4c",
6297c478bd9Sstevel@tonic-gate 	    &portinfo_record->PortInfo, sizeof (sm_portinfo_t), buffer,
6307c478bd9Sstevel@tonic-gate 	    SM_PORTINFO_SIZE);
6317c478bd9Sstevel@tonic-gate 
6327c478bd9Sstevel@tonic-gate }
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate static void
ibmf_saa_SLtoVLmapping_record_to_buf(void * record,uchar_t * buffer)6357c478bd9Sstevel@tonic-gate ibmf_saa_SLtoVLmapping_record_to_buf(void *record, uchar_t *buffer)
6367c478bd9Sstevel@tonic-gate {
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate 	sa_SLtoVLmapping_record_t	*SLtoVLmapping_record =
6397c478bd9Sstevel@tonic-gate 	    (sa_SLtoVLmapping_record_t *)record;
6407c478bd9Sstevel@tonic-gate 
6417c478bd9Sstevel@tonic-gate 	/* first get record identifier information (plus 4 bytes reserved) */
6427c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("s2cl", SLtoVLmapping_record, 8, buffer,
6437c478bd9Sstevel@tonic-gate 	    IBMF_SAA_DEFAULT_RID_SIZE + 4);
6447c478bd9Sstevel@tonic-gate 
6457c478bd9Sstevel@tonic-gate 	/* SLtoVL mapping has 4 reserved bytes between RID and attribute */
6467c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE + 4;
6477c478bd9Sstevel@tonic-gate 
6487c478bd9Sstevel@tonic-gate 	/* next get SLtoVLmapping info */
6497c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("8c", &SLtoVLmapping_record->SLtoVLMappingTable,
6507c478bd9Sstevel@tonic-gate 	    sizeof (sm_SLtoVL_mapping_table_t), buffer, SM_SLTOVL_SIZE);
6517c478bd9Sstevel@tonic-gate }
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate static void
ibmf_saa_switchinfo_record_to_buf(void * record,uchar_t * buffer)6547c478bd9Sstevel@tonic-gate ibmf_saa_switchinfo_record_to_buf(void *record, uchar_t *buffer)
6557c478bd9Sstevel@tonic-gate {
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate 	sa_switchinfo_record_t	*switchinfo_record =
6587c478bd9Sstevel@tonic-gate 	    (sa_switchinfo_record_t *)record;
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 	/* first get record identifier information */
6617c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("2s", switchinfo_record, 4, buffer,
6627c478bd9Sstevel@tonic-gate 	    IBMF_SAA_DEFAULT_RID_SIZE);
6637c478bd9Sstevel@tonic-gate 
6647c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE;
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate 	/* next get switchinfo info */
6677c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("4s4c2sc", &switchinfo_record->SwitchInfo,
6687c478bd9Sstevel@tonic-gate 	    sizeof (sm_switchinfo_t), buffer, SM_SWITCHINFO_SIZE);
6697c478bd9Sstevel@tonic-gate 
6707c478bd9Sstevel@tonic-gate }
6717c478bd9Sstevel@tonic-gate 
6727c478bd9Sstevel@tonic-gate static void
ibmf_saa_linearft_record_to_buf(void * record,uchar_t * buffer)6737c478bd9Sstevel@tonic-gate ibmf_saa_linearft_record_to_buf(void *record, uchar_t *buffer)
6747c478bd9Sstevel@tonic-gate {
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate 	sa_linearft_record_t	*linearft_record =
6777c478bd9Sstevel@tonic-gate 	    (sa_linearft_record_t *)record;
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate 	/* first get record identifier information (plus 4 bytes reserved) */
6807c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("2sl", linearft_record, 8, buffer,
6817c478bd9Sstevel@tonic-gate 	    IBMF_SAA_DEFAULT_RID_SIZE + 4);
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 	/* LFT has 4 reserved bytes between RID and attribute */
6847c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE + 4;
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate 	/* next get linearft info */
6877c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("64c", &linearft_record->LinearFT,
6887c478bd9Sstevel@tonic-gate 	    sizeof (sm_linear_forwarding_table_t), buffer, SM_LINEARFDB_SIZE);
6897c478bd9Sstevel@tonic-gate }
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate static void
ibmf_saa_randomft_record_to_buf(void * record,uchar_t * buffer)6927c478bd9Sstevel@tonic-gate ibmf_saa_randomft_record_to_buf(void *record, uchar_t *buffer)
6937c478bd9Sstevel@tonic-gate {
6947c478bd9Sstevel@tonic-gate 
6957c478bd9Sstevel@tonic-gate 	sa_randomft_record_t	*randomft_record =
6967c478bd9Sstevel@tonic-gate 	    (sa_randomft_record_t *)record;
6977c478bd9Sstevel@tonic-gate 
6987c478bd9Sstevel@tonic-gate 	/* first get record identifier information (plus 4 bytes reserved) */
6997c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("2sl", randomft_record, 8, buffer,
7007c478bd9Sstevel@tonic-gate 	    IBMF_SAA_DEFAULT_RID_SIZE + 4);
7017c478bd9Sstevel@tonic-gate 
7027c478bd9Sstevel@tonic-gate 	/* RFT has 4 reserved bytes between RID and attribute */
7037c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE + 4;
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate 	/* next get randomft info */
7067c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("64c", &randomft_record->RandomFT,
7077c478bd9Sstevel@tonic-gate 	    sizeof (sm_random_forwarding_table_t), buffer, SM_RANDOMFDB_SIZE);
7087c478bd9Sstevel@tonic-gate }
7097c478bd9Sstevel@tonic-gate 
7107c478bd9Sstevel@tonic-gate static void
ibmf_saa_multicastft_record_to_buf(void * record,uchar_t * buffer)7117c478bd9Sstevel@tonic-gate ibmf_saa_multicastft_record_to_buf(void *record, uchar_t *buffer)
7127c478bd9Sstevel@tonic-gate {
7137c478bd9Sstevel@tonic-gate 
7147c478bd9Sstevel@tonic-gate 	sa_multicastft_record_t	*multicastft_record =
7157c478bd9Sstevel@tonic-gate 	    (sa_multicastft_record_t *)record;
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate 	/* first get record identifier information (plus 4 bytes reserved) */
7187c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("2sl", multicastft_record, 8, buffer,
7197c478bd9Sstevel@tonic-gate 	    IBMF_SAA_DEFAULT_RID_SIZE + 4);
7207c478bd9Sstevel@tonic-gate 
7217c478bd9Sstevel@tonic-gate 	/* MFT has 4 reserved bytes between RID and attribute */
7227c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE + 4;
7237c478bd9Sstevel@tonic-gate 
7247c478bd9Sstevel@tonic-gate 	/* next get multicastft info */
7257c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("32s", &multicastft_record->MulticastFT,
7267c478bd9Sstevel@tonic-gate 	    sizeof (sm_multicast_forwarding_table_t), buffer,
7277c478bd9Sstevel@tonic-gate 	    SM_MULTICASTFDB_SIZE);
7287c478bd9Sstevel@tonic-gate }
7297c478bd9Sstevel@tonic-gate 
7307c478bd9Sstevel@tonic-gate static void
ibmf_saa_sminfo_record_to_buf(void * record,uchar_t * buffer)7317c478bd9Sstevel@tonic-gate ibmf_saa_sminfo_record_to_buf(void *record, uchar_t *buffer)
7327c478bd9Sstevel@tonic-gate {
7337c478bd9Sstevel@tonic-gate 
7347c478bd9Sstevel@tonic-gate 	sa_sminfo_record_t	*sminfo_record =
7357c478bd9Sstevel@tonic-gate 	    (sa_sminfo_record_t *)record;
7367c478bd9Sstevel@tonic-gate 
7377c478bd9Sstevel@tonic-gate 	/* first get record identifier information */
7387c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("2s", sminfo_record, 4, buffer,
7397c478bd9Sstevel@tonic-gate 	    IBMF_SAA_DEFAULT_RID_SIZE);
7407c478bd9Sstevel@tonic-gate 
7417c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE;
7427c478bd9Sstevel@tonic-gate 
7437c478bd9Sstevel@tonic-gate 	/* next get sminfo info */
7447c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("2Llc", &sminfo_record->SMInfo,
7457c478bd9Sstevel@tonic-gate 	    sizeof (sm_sminfo_t), buffer, SM_SMINFO_SIZE);
7467c478bd9Sstevel@tonic-gate }
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate static void
ibmf_saa_informinfo_record_to_buf(void * record,uchar_t * buffer)7497c478bd9Sstevel@tonic-gate ibmf_saa_informinfo_record_to_buf(void *record, uchar_t *buffer)
7507c478bd9Sstevel@tonic-gate {
7517c478bd9Sstevel@tonic-gate 
7527c478bd9Sstevel@tonic-gate 	sa_informinfo_record_t	*informinfo_record =
7537c478bd9Sstevel@tonic-gate 	    (sa_informinfo_record_t *)record;
7547c478bd9Sstevel@tonic-gate 
7557c478bd9Sstevel@tonic-gate 	/* first get record identifier information */
7567c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("2Ls", informinfo_record, 18, buffer,
7577c478bd9Sstevel@tonic-gate 	    IBMF_SAA_INFORMINFO_RID_SIZE);
7587c478bd9Sstevel@tonic-gate 
7597c478bd9Sstevel@tonic-gate 	/* InformInfo has 6 reserved bytes between RID and attribute */
7607c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_INFORMINFO_RID_SIZE + 6;
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate 	/* next get informinfo info */
7637c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("2L3s2c2s2l", &informinfo_record->InformInfo,
7647c478bd9Sstevel@tonic-gate 	    sizeof (ib_mad_informinfo_t), buffer, IB_MAD_INFORMINFO_SIZE);
7657c478bd9Sstevel@tonic-gate }
7667c478bd9Sstevel@tonic-gate 
7677c478bd9Sstevel@tonic-gate static void
ibmf_saa_link_record_to_buf(void * record,uchar_t * buffer)7687c478bd9Sstevel@tonic-gate ibmf_saa_link_record_to_buf(void *record, uchar_t *buffer)
7697c478bd9Sstevel@tonic-gate {
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate 	sa_link_record_t	*link_record = (sa_link_record_t *)record;
7727c478bd9Sstevel@tonic-gate 
7737c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("s2cs", link_record,
7747c478bd9Sstevel@tonic-gate 	    sizeof (sa_link_record_t), buffer, IBMF_SAA_LINK_RECORD_SIZE);
7757c478bd9Sstevel@tonic-gate }
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate static void
ibmf_saa_guidinfo_record_to_buf(void * record,uchar_t * buffer)7787c478bd9Sstevel@tonic-gate ibmf_saa_guidinfo_record_to_buf(void *record, uchar_t *buffer)
7797c478bd9Sstevel@tonic-gate {
7807c478bd9Sstevel@tonic-gate 
7817c478bd9Sstevel@tonic-gate 	sa_guidinfo_record_t	*guidinfo_record =
7827c478bd9Sstevel@tonic-gate 	    (sa_guidinfo_record_t *)record;
7837c478bd9Sstevel@tonic-gate 
7847c478bd9Sstevel@tonic-gate 	/* first get record identifier information (plus 4 bytes reserved) */
7857c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("s2cl", guidinfo_record,
7867c478bd9Sstevel@tonic-gate 	    8, buffer, IBMF_SAA_DEFAULT_RID_SIZE + 4);
7877c478bd9Sstevel@tonic-gate 
7887c478bd9Sstevel@tonic-gate 	/* GUIDInfo has 4 reserved bytes between RID and attribute */
7897c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE + 4;
7907c478bd9Sstevel@tonic-gate 
7917c478bd9Sstevel@tonic-gate 	/* next get guidinfo info */
7927c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("8L", &guidinfo_record->GUIDInfo,
7937c478bd9Sstevel@tonic-gate 	    sizeof (sm_guidinfo_t), buffer, SM_GUIDINFO_SIZE);
7947c478bd9Sstevel@tonic-gate }
7957c478bd9Sstevel@tonic-gate 
7967c478bd9Sstevel@tonic-gate static void
ibmf_saa_service_record_to_buf(void * record,uchar_t * buffer)7977c478bd9Sstevel@tonic-gate ibmf_saa_service_record_to_buf(void *record, uchar_t *buffer)
7987c478bd9Sstevel@tonic-gate {
7997c478bd9Sstevel@tonic-gate 
8007c478bd9Sstevel@tonic-gate 	sa_service_record_t	*service_record = (sa_service_record_t *)record;
8017c478bd9Sstevel@tonic-gate 
8027c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("3L2sl2L64c16c8s4l2L", service_record,
8037c478bd9Sstevel@tonic-gate 	    sizeof (sa_service_record_t), buffer, IBMF_SAA_SERVICE_RECORD_SIZE);
8047c478bd9Sstevel@tonic-gate }
8057c478bd9Sstevel@tonic-gate 
8067c478bd9Sstevel@tonic-gate static void
ibmf_saa_partition_record_to_buf(void * record,uchar_t * buffer)8077c478bd9Sstevel@tonic-gate ibmf_saa_partition_record_to_buf(void *record, uchar_t *buffer)
8087c478bd9Sstevel@tonic-gate {
8097c478bd9Sstevel@tonic-gate 
8107c478bd9Sstevel@tonic-gate 	sa_pkey_table_record_t	*partition_record =
8117c478bd9Sstevel@tonic-gate 	    (sa_pkey_table_record_t *)record;
8127c478bd9Sstevel@tonic-gate 
8137c478bd9Sstevel@tonic-gate 	/* first get record identifier information (plus 4 bytes reserved) */
8147c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("2s4c", partition_record, 8, buffer,
8157c478bd9Sstevel@tonic-gate 	    IBMF_SAA_PARTITION_RID_SIZE	+ 3);
8167c478bd9Sstevel@tonic-gate 
8177c478bd9Sstevel@tonic-gate 	/*  Partition record has 3 reserved bytes between RID and attribute */
8187c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_PARTITION_RID_SIZE + 3;
8197c478bd9Sstevel@tonic-gate 
8207c478bd9Sstevel@tonic-gate 	/* next get partition info */
8217c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("32s", &partition_record->P_KeyTable,
8227c478bd9Sstevel@tonic-gate 	    sizeof (sm_pkey_table_t), buffer, SM_PARTITION_SIZE);
8237c478bd9Sstevel@tonic-gate }
8247c478bd9Sstevel@tonic-gate 
8257c478bd9Sstevel@tonic-gate static void
ibmf_saa_path_record_to_buf(void * record,uchar_t * buffer)8267c478bd9Sstevel@tonic-gate ibmf_saa_path_record_to_buf(void *record, uchar_t *buffer)
8277c478bd9Sstevel@tonic-gate {
8287c478bd9Sstevel@tonic-gate 
8297c478bd9Sstevel@tonic-gate 	sa_path_record_t	*path_record = (sa_path_record_t *)record;
8307c478bd9Sstevel@tonic-gate 
8317c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("2l4L2sl2c2s4c", path_record,
8327c478bd9Sstevel@tonic-gate 	    sizeof (sa_path_record_t), buffer, IBMF_SAA_PATH_RECORD_SIZE);
8337c478bd9Sstevel@tonic-gate }
8347c478bd9Sstevel@tonic-gate 
8357c478bd9Sstevel@tonic-gate static void
ibmf_saa_vlarb_record_to_buf(void * record,uchar_t * buffer)8367c478bd9Sstevel@tonic-gate ibmf_saa_vlarb_record_to_buf(void *record, uchar_t *buffer)
8377c478bd9Sstevel@tonic-gate {
8387c478bd9Sstevel@tonic-gate 
8397c478bd9Sstevel@tonic-gate 	sa_VLarb_table_record_t	*VLarb_table_record =
8407c478bd9Sstevel@tonic-gate 	    (sa_VLarb_table_record_t *)record;
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate 	/* first get record identifier information (plus 4 bytes reserved) */
8437c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("s2c", VLarb_table_record, 8, buffer,
8447c478bd9Sstevel@tonic-gate 	    IBMF_SAA_DEFAULT_RID_SIZE + 4);
8457c478bd9Sstevel@tonic-gate 
8467c478bd9Sstevel@tonic-gate 	/*  VLarb record has 4 reserved bytes between RID and attribute */
8477c478bd9Sstevel@tonic-gate 	buffer += IBMF_SAA_DEFAULT_RID_SIZE + 4;
8487c478bd9Sstevel@tonic-gate 
8497c478bd9Sstevel@tonic-gate 	/* next get VLarb_table info */
8507c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("64c", &VLarb_table_record->VLArbTable,
8517c478bd9Sstevel@tonic-gate 	    sizeof (sm_VLarb_table_t), buffer, SM_VLARB_SIZE);
8527c478bd9Sstevel@tonic-gate }
8537c478bd9Sstevel@tonic-gate 
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate static void
ibmf_saa_mcmember_record_to_buf(void * record,uchar_t * buffer)8567c478bd9Sstevel@tonic-gate ibmf_saa_mcmember_record_to_buf(void *record, uchar_t *buffer)
8577c478bd9Sstevel@tonic-gate {
8587c478bd9Sstevel@tonic-gate 
8597c478bd9Sstevel@tonic-gate 	sa_mcmember_record_t	*mcmember_record =
8607c478bd9Sstevel@tonic-gate 	    (sa_mcmember_record_t *)record;
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("4Lls2cs2c2l", mcmember_record,
8637c478bd9Sstevel@tonic-gate 	    sizeof (sa_mcmember_record_t),
8647c478bd9Sstevel@tonic-gate 	    buffer, IBMF_SAA_MCMEMBER_RECORD_SIZE);
8657c478bd9Sstevel@tonic-gate }
8667c478bd9Sstevel@tonic-gate 
ibmf_saa_multipath_record_to_buf(void * record,uchar_t * buffer)8677c478bd9Sstevel@tonic-gate static void ibmf_saa_multipath_record_to_buf(void *record, uchar_t *buffer)
8687c478bd9Sstevel@tonic-gate {
8697c478bd9Sstevel@tonic-gate 	char			gid_str[20];
8707c478bd9Sstevel@tonic-gate 	uint16_t		num_gids;
8717c478bd9Sstevel@tonic-gate 	sa_multipath_record_t	*multipath_record =
872*03b18ed2SToomas Soome 	    (sa_multipath_record_t *)record;
8737c478bd9Sstevel@tonic-gate 
8747c478bd9Sstevel@tonic-gate 	num_gids = multipath_record->SGIDCount + multipath_record->DGIDCount;
8757c478bd9Sstevel@tonic-gate 
8767c478bd9Sstevel@tonic-gate 	(void) sprintf(gid_str, "l2c2s14c%dL", 2 * num_gids);
8777c478bd9Sstevel@tonic-gate 
8787c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data(gid_str, multipath_record,
8797c478bd9Sstevel@tonic-gate 	    sizeof (sa_multipath_record_t) + sizeof (ib_gid_t) * num_gids,
8807c478bd9Sstevel@tonic-gate 	    buffer,
8817c478bd9Sstevel@tonic-gate 	    IBMF_SAA_MULTIPATH_RECORD_SIZE + sizeof (ib_gid_t) * num_gids);
8827c478bd9Sstevel@tonic-gate }
8837c478bd9Sstevel@tonic-gate 
8847c478bd9Sstevel@tonic-gate static void
ibmf_saa_service_assn_record_to_buf(void * record,uchar_t * buffer)8857c478bd9Sstevel@tonic-gate ibmf_saa_service_assn_record_to_buf(void *record, uchar_t *buffer)
8867c478bd9Sstevel@tonic-gate {
8877c478bd9Sstevel@tonic-gate 
8887c478bd9Sstevel@tonic-gate 	sa_service_assn_record_t	*service_assn_record =
8897c478bd9Sstevel@tonic-gate 	    (sa_service_assn_record_t *)record;
8907c478bd9Sstevel@tonic-gate 
8917c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("2L64c", service_assn_record,
8927c478bd9Sstevel@tonic-gate 	    sizeof (sa_service_assn_record_t),
8937c478bd9Sstevel@tonic-gate 	    buffer, IBMF_SAA_SERVICEASSN_RECORD_SIZE);
8947c478bd9Sstevel@tonic-gate }
8957c478bd9Sstevel@tonic-gate 
8967c478bd9Sstevel@tonic-gate int
ibmf_saa_utils_pack_sa_hdr(ib_sa_hdr_t * sa_hdr,void ** packed_class_hdr,size_t * packed_class_hdr_len,int km_sleep_flag)8977c478bd9Sstevel@tonic-gate ibmf_saa_utils_pack_sa_hdr(ib_sa_hdr_t *sa_hdr, void **packed_class_hdr,
8987c478bd9Sstevel@tonic-gate     size_t *packed_class_hdr_len, int km_sleep_flag)
8997c478bd9Sstevel@tonic-gate {
9007c478bd9Sstevel@tonic-gate 
9017c478bd9Sstevel@tonic-gate 	*packed_class_hdr = kmem_zalloc(IBMF_SAA_HDR_SIZE, km_sleep_flag);
9027c478bd9Sstevel@tonic-gate 	if (*packed_class_hdr == NULL) {
9037c478bd9Sstevel@tonic-gate 
9047c478bd9Sstevel@tonic-gate 		IBMF_TRACE_0(IBMF_TNF_DEBUG, DPRINT_L1,
9057c478bd9Sstevel@tonic-gate 		    ibmf_saa_utils_pack_sa_hdr_err,
9067c478bd9Sstevel@tonic-gate 		    IBMF_TNF_ERROR, "", "ibmf_saa_utils_pack_sa_hdr: "
9077c478bd9Sstevel@tonic-gate 		    "could not allocate memory for header\n");
9087c478bd9Sstevel@tonic-gate 
9097c478bd9Sstevel@tonic-gate 		return (IBMF_NO_MEMORY);
9107c478bd9Sstevel@tonic-gate 	}
9117c478bd9Sstevel@tonic-gate 
9127c478bd9Sstevel@tonic-gate 	ibmf_utils_pack_data("LssL", sa_hdr, sizeof (ib_sa_hdr_t),
9137c478bd9Sstevel@tonic-gate 	    (uchar_t *)*packed_class_hdr, IBMF_SAA_HDR_SIZE);
9147c478bd9Sstevel@tonic-gate 
9157c478bd9Sstevel@tonic-gate 	*packed_class_hdr_len = IBMF_SAA_HDR_SIZE;
9167c478bd9Sstevel@tonic-gate 
9177c478bd9Sstevel@tonic-gate 	return (IBMF_SUCCESS);
9187c478bd9Sstevel@tonic-gate }
9197c478bd9Sstevel@tonic-gate 
9207c478bd9Sstevel@tonic-gate int
ibmf_saa_utils_unpack_sa_hdr(void * packed_class_hdr,size_t packed_class_hdr_len,ib_sa_hdr_t ** sa_hdr,int km_sleep_flag)9217c478bd9Sstevel@tonic-gate ibmf_saa_utils_unpack_sa_hdr(void *packed_class_hdr,
9227c478bd9Sstevel@tonic-gate     size_t packed_class_hdr_len, ib_sa_hdr_t **sa_hdr, int km_sleep_flag)
9237c478bd9Sstevel@tonic-gate {
9247c478bd9Sstevel@tonic-gate 	if (packed_class_hdr_len != IBMF_SAA_HDR_SIZE) {
9257c478bd9Sstevel@tonic-gate 
9267c478bd9Sstevel@tonic-gate 		IBMF_TRACE_3(IBMF_TNF_DEBUG, DPRINT_L1,
9277c478bd9Sstevel@tonic-gate 		    ibmf_saa_utils_unpack_sa_hdr_err,
9287c478bd9Sstevel@tonic-gate 		    IBMF_TNF_ERROR, "", "ibmf_saa_utils_unpack_sa_hdr: %s,"
9297c478bd9Sstevel@tonic-gate 		    " sa_class_hdr_len = %d, pkt_class_hdr_len = %d\n",
9307c478bd9Sstevel@tonic-gate 		    tnf_string, msg, "invalid class hdr length for SA packet",
9317c478bd9Sstevel@tonic-gate 		    tnf_int, sa_class_hdr_len, IBMF_SAA_HDR_SIZE,
9327c478bd9Sstevel@tonic-gate 		    tnf_int, pkt_class_hdr_len, packed_class_hdr_len);
9337c478bd9Sstevel@tonic-gate 
9347c478bd9Sstevel@tonic-gate 		return (IBMF_REQ_INVALID);
9357c478bd9Sstevel@tonic-gate 	}
9367c478bd9Sstevel@tonic-gate 
9377c478bd9Sstevel@tonic-gate 	*sa_hdr = kmem_zalloc(sizeof (ib_sa_hdr_t), km_sleep_flag);
9387c478bd9Sstevel@tonic-gate 	if (*sa_hdr == NULL) {
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate 		IBMF_TRACE_0(IBMF_TNF_DEBUG, DPRINT_L1,
9417c478bd9Sstevel@tonic-gate 		    ibmf_saa_utils_unpack_sa_hdr_err,
9427c478bd9Sstevel@tonic-gate 		    IBMF_TNF_ERROR, "", "ibmf_saa_utils_unpack_sa_hdr: "
9437c478bd9Sstevel@tonic-gate 		    "could not allocate memory for header\n");
9447c478bd9Sstevel@tonic-gate 
9457c478bd9Sstevel@tonic-gate 		return (IBMF_NO_MEMORY);
9467c478bd9Sstevel@tonic-gate 	}
9477c478bd9Sstevel@tonic-gate 
9487c478bd9Sstevel@tonic-gate 	ibmf_utils_unpack_data("LssL", (uchar_t *)packed_class_hdr,
9497c478bd9Sstevel@tonic-gate 	    IBMF_SAA_HDR_SIZE, *sa_hdr, sizeof (ib_sa_hdr_t));
9507c478bd9Sstevel@tonic-gate 
9517c478bd9Sstevel@tonic-gate 	return (IBMF_SUCCESS);
9527c478bd9Sstevel@tonic-gate }
9537c478bd9Sstevel@tonic-gate 
9547c478bd9Sstevel@tonic-gate /*
9557c478bd9Sstevel@tonic-gate  * ibmf_saa_utils_pack_payload:
9567c478bd9Sstevel@tonic-gate  *
9577c478bd9Sstevel@tonic-gate  * Takes a pointer to an array of sa record structures.  For each element packs
9587c478bd9Sstevel@tonic-gate  * the structure into a character buffer removing any padding and account for
9597c478bd9Sstevel@tonic-gate  * endianness issues.
9607c478bd9Sstevel@tonic-gate  *
9617c478bd9Sstevel@tonic-gate  */
9627c478bd9Sstevel@tonic-gate int
ibmf_saa_utils_pack_payload(uchar_t * structs_payload,size_t structs_payload_length,uint16_t attr_id,void ** buf_payloadp,size_t * buf_payload_lengthp,int km_sleep_flag)9637c478bd9Sstevel@tonic-gate ibmf_saa_utils_pack_payload(uchar_t *structs_payload, size_t
9647c478bd9Sstevel@tonic-gate     structs_payload_length, uint16_t attr_id, void **buf_payloadp,
9657c478bd9Sstevel@tonic-gate     size_t *buf_payload_lengthp, int km_sleep_flag)
9667c478bd9Sstevel@tonic-gate {
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate 	int	i;
9697c478bd9Sstevel@tonic-gate 	int	struct_size, buf_size;
9707c478bd9Sstevel@tonic-gate 	int	num_records;
9717c478bd9Sstevel@tonic-gate 	void	(*pack_data_fn)(void *, uchar_t *);
9727c478bd9Sstevel@tonic-gate 
9737c478bd9Sstevel@tonic-gate 	if (structs_payload_length == 0) {
9747c478bd9Sstevel@tonic-gate 
975*03b18ed2SToomas Soome 		*buf_payload_lengthp = 0;
9767c478bd9Sstevel@tonic-gate 		*buf_payloadp = NULL;
9777c478bd9Sstevel@tonic-gate 
9787c478bd9Sstevel@tonic-gate 		return (IBMF_SUCCESS);
9797c478bd9Sstevel@tonic-gate 	}
9807c478bd9Sstevel@tonic-gate 
9817c478bd9Sstevel@tonic-gate 	ASSERT(structs_payload != NULL);
9827c478bd9Sstevel@tonic-gate 
9837c478bd9Sstevel@tonic-gate 	/* trace records should never be sent (or packed) by ibmf_saa */
9847c478bd9Sstevel@tonic-gate 	ASSERT(attr_id != SA_TRACERECORD_ATTRID);
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate 	switch (attr_id) {
987934f0bccShiremath 		case SA_CLASSPORTINFO_ATTRID:
988934f0bccShiremath 			struct_size = sizeof (ib_mad_classportinfo_t);
989934f0bccShiremath 			buf_size = IB_MAD_CLASSPORTINFO_SIZE;
990934f0bccShiremath 			pack_data_fn = ibmf_saa_classportinfo_to_buf;
991934f0bccShiremath 			break;
9927c478bd9Sstevel@tonic-gate 		case SA_NOTICE_ATTRID:
9937c478bd9Sstevel@tonic-gate 			struct_size = sizeof (ib_mad_notice_t);
9947c478bd9Sstevel@tonic-gate 			buf_size = IB_MAD_NOTICE_SIZE;
9957c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_notice_to_buf;
9967c478bd9Sstevel@tonic-gate 			break;
9977c478bd9Sstevel@tonic-gate 		case SA_INFORMINFO_ATTRID:
9987c478bd9Sstevel@tonic-gate 			struct_size = sizeof (ib_mad_informinfo_t);
9997c478bd9Sstevel@tonic-gate 			buf_size = IB_MAD_INFORMINFO_SIZE;
10007c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_informinfo_to_buf;
10017c478bd9Sstevel@tonic-gate 			break;
10027c478bd9Sstevel@tonic-gate 		case SA_NODERECORD_ATTRID:
10037c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_node_record_t);
10047c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_NODE_RECORD_SIZE;
10057c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_node_record_to_buf;
10067c478bd9Sstevel@tonic-gate 			break;
10077c478bd9Sstevel@tonic-gate 		case SA_PORTINFORECORD_ATTRID:
10087c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_portinfo_record_t);
10097c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_PORTINFO_RECORD_SIZE;
10107c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_portinfo_record_to_buf;
10117c478bd9Sstevel@tonic-gate 			break;
10127c478bd9Sstevel@tonic-gate 		case SA_SLTOVLRECORD_ATTRID:
10137c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_SLtoVLmapping_record_t);
10147c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_SLTOVL_RECORD_SIZE;
10157c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_SLtoVLmapping_record_to_buf;
10167c478bd9Sstevel@tonic-gate 			break;
10177c478bd9Sstevel@tonic-gate 		case SA_SWITCHINFORECORD_ATTRID:
10187c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_switchinfo_record_t);
10197c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_SWITCHINFO_RECORD_SIZE;
10207c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_switchinfo_record_to_buf;
10217c478bd9Sstevel@tonic-gate 			break;
10227c478bd9Sstevel@tonic-gate 		case SA_LINEARFDBRECORD_ATTRID:
10237c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_linearft_record_t);
10247c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_LINEARFDB_RECORD_SIZE;
10257c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_linearft_record_to_buf;
10267c478bd9Sstevel@tonic-gate 			break;
10277c478bd9Sstevel@tonic-gate 		case SA_RANDOMFDBRECORD_ATTRID:
10287c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_randomft_record_t);
10297c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_RANDOMFDB_RECORD_SIZE;
10307c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_randomft_record_to_buf;
10317c478bd9Sstevel@tonic-gate 			break;
10327c478bd9Sstevel@tonic-gate 		case SA_MULTICASTFDBRECORD_ATTRID:
10337c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_multicastft_record_t);
10347c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_MULTICASTFDB_RECORD_SIZE;
10357c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_multicastft_record_to_buf;
10367c478bd9Sstevel@tonic-gate 			break;
10377c478bd9Sstevel@tonic-gate 		case SA_SMINFORECORD_ATTRID:
10387c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_sminfo_record_t);
10397c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_SMINFO_RECORD_SIZE;
10407c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_sminfo_record_to_buf;
10417c478bd9Sstevel@tonic-gate 			break;
10427c478bd9Sstevel@tonic-gate 		case SA_INFORMINFORECORD_ATTRID:
10437c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_informinfo_record_t);
10447c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_INFORMINFO_RECORD_SIZE;
10457c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_informinfo_record_to_buf;
10467c478bd9Sstevel@tonic-gate 			break;
10477c478bd9Sstevel@tonic-gate 		case SA_LINKRECORD_ATTRID:
10487c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_link_record_t);
10497c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_LINK_RECORD_SIZE;
10507c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_link_record_to_buf;
10517c478bd9Sstevel@tonic-gate 			break;
10527c478bd9Sstevel@tonic-gate 		case SA_GUIDINFORECORD_ATTRID:
10537c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_guidinfo_record_t);
10547c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_GUIDINFO_RECORD_SIZE;
10557c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_guidinfo_record_to_buf;
10567c478bd9Sstevel@tonic-gate 			break;
10577c478bd9Sstevel@tonic-gate 		case SA_SERVICERECORD_ATTRID:
10587c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_service_record_t);
10597c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_SERVICE_RECORD_SIZE;
10607c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_service_record_to_buf;
10617c478bd9Sstevel@tonic-gate 			break;
10627c478bd9Sstevel@tonic-gate 		case SA_PARTITIONRECORD_ATTRID:
10637c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_pkey_table_record_t);
10647c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_PARTITION_RECORD_SIZE;
10657c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_partition_record_to_buf;
10667c478bd9Sstevel@tonic-gate 			break;
10677c478bd9Sstevel@tonic-gate 		case SA_PATHRECORD_ATTRID:
10687c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_path_record_t);
10697c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_PATH_RECORD_SIZE;
10707c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_path_record_to_buf;
10717c478bd9Sstevel@tonic-gate 			break;
10727c478bd9Sstevel@tonic-gate 		case SA_VLARBRECORD_ATTRID:
10737c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_VLarb_table_record_t);
10747c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_VLARB_RECORD_SIZE;
10757c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_vlarb_record_to_buf;
10767c478bd9Sstevel@tonic-gate 			break;
10777c478bd9Sstevel@tonic-gate 		case SA_MCMEMBERRECORD_ATTRID:
10787c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_mcmember_record_t);
10797c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_MCMEMBER_RECORD_SIZE;
10807c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_mcmember_record_to_buf;
10817c478bd9Sstevel@tonic-gate 			break;
10827c478bd9Sstevel@tonic-gate 		case SA_MULTIPATHRECORD_ATTRID:
10837c478bd9Sstevel@tonic-gate 			/*
10847c478bd9Sstevel@tonic-gate 			 * array is of size 1 since multipath can be request
10857c478bd9Sstevel@tonic-gate 			 * only; data size greater than multipath_record_t
10867c478bd9Sstevel@tonic-gate 			 * size is due to gids at the end
10877c478bd9Sstevel@tonic-gate 			 */
10887c478bd9Sstevel@tonic-gate 			struct_size = structs_payload_length;
10897c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_MULTIPATH_RECORD_SIZE +
10907c478bd9Sstevel@tonic-gate 			    struct_size - sizeof (sa_multipath_record_t);
10917c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_multipath_record_to_buf;
10927c478bd9Sstevel@tonic-gate 			break;
10937c478bd9Sstevel@tonic-gate 		case SA_SERVICEASSNRECORD_ATTRID:
10947c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_service_assn_record_t);
10957c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_SERVICEASSN_RECORD_SIZE;
10967c478bd9Sstevel@tonic-gate 			pack_data_fn = ibmf_saa_service_assn_record_to_buf;
10977c478bd9Sstevel@tonic-gate 			break;
10987c478bd9Sstevel@tonic-gate 		default:
10997c478bd9Sstevel@tonic-gate 
11007c478bd9Sstevel@tonic-gate 			/* don't know about structure; do bcopy */
11017c478bd9Sstevel@tonic-gate 			*buf_payload_lengthp = structs_payload_length;
11027c478bd9Sstevel@tonic-gate 			*buf_payloadp = kmem_zalloc(*buf_payload_lengthp,
11037c478bd9Sstevel@tonic-gate 			    km_sleep_flag);
11047c478bd9Sstevel@tonic-gate 			if (*buf_payloadp == NULL) {
11057c478bd9Sstevel@tonic-gate 
11067c478bd9Sstevel@tonic-gate 				*buf_payload_lengthp = 0;
11077c478bd9Sstevel@tonic-gate 				return (IBMF_NO_MEMORY);
11087c478bd9Sstevel@tonic-gate 			}
11097c478bd9Sstevel@tonic-gate 
11107c478bd9Sstevel@tonic-gate 			bcopy(structs_payload, *buf_payloadp,
11117c478bd9Sstevel@tonic-gate 			    *buf_payload_lengthp);
11127c478bd9Sstevel@tonic-gate 
11137c478bd9Sstevel@tonic-gate 			return (IBMF_SUCCESS);
11147c478bd9Sstevel@tonic-gate 	}
11157c478bd9Sstevel@tonic-gate 
11167c478bd9Sstevel@tonic-gate 	*buf_payload_lengthp = structs_payload_length / struct_size * buf_size;
11177c478bd9Sstevel@tonic-gate 	num_records = structs_payload_length / struct_size;
11187c478bd9Sstevel@tonic-gate 	*buf_payloadp = kmem_zalloc(*buf_payload_lengthp, km_sleep_flag);
11197c478bd9Sstevel@tonic-gate 	if (*buf_payloadp == NULL) {
11207c478bd9Sstevel@tonic-gate 
11217c478bd9Sstevel@tonic-gate 		IBMF_TRACE_2(IBMF_TNF_DEBUG, DPRINT_L1,
11227c478bd9Sstevel@tonic-gate 		    ibmf_saa_utils_pack_payload_err,
11237c478bd9Sstevel@tonic-gate 		    IBMF_TNF_ERROR, "", "ibmf_saa_utils_pack_payload: %s,"
11247c478bd9Sstevel@tonic-gate 		    " size = %d\n",
11257c478bd9Sstevel@tonic-gate 		    tnf_string, msg, "could not allocate memory for payload",
11267c478bd9Sstevel@tonic-gate 		    tnf_int, size, *buf_payload_lengthp);
11277c478bd9Sstevel@tonic-gate 
11287c478bd9Sstevel@tonic-gate 		*buf_payload_lengthp = 0;
11297c478bd9Sstevel@tonic-gate 		return (IBMF_NO_MEMORY);
11307c478bd9Sstevel@tonic-gate 	}
11317c478bd9Sstevel@tonic-gate 
11327c478bd9Sstevel@tonic-gate 	for (i = 0; i < num_records; i++) {
11337c478bd9Sstevel@tonic-gate 
11347c478bd9Sstevel@tonic-gate 		pack_data_fn(
11357c478bd9Sstevel@tonic-gate 		    (void *)((uchar_t *)structs_payload + i * struct_size),
11367c478bd9Sstevel@tonic-gate 		    ((uchar_t *)*buf_payloadp + i * buf_size));
11377c478bd9Sstevel@tonic-gate 	}
11387c478bd9Sstevel@tonic-gate 
11397c478bd9Sstevel@tonic-gate 	return (IBMF_SUCCESS);
11407c478bd9Sstevel@tonic-gate }
11417c478bd9Sstevel@tonic-gate 
11427c478bd9Sstevel@tonic-gate 
11437c478bd9Sstevel@tonic-gate /*
11447c478bd9Sstevel@tonic-gate  * ibmf_saa_utils_unpack_payload:
11457c478bd9Sstevel@tonic-gate  *
11467c478bd9Sstevel@tonic-gate  * Unpacks a buffer of data received over the wire and places into an array of
11477c478bd9Sstevel@tonic-gate  * structure in host format.
11487c478bd9Sstevel@tonic-gate  *
11497c478bd9Sstevel@tonic-gate  * for getResp() ibmf always reports payload length as 200 bytes
11507c478bd9Sstevel@tonic-gate  * (MAD_SIZE - headers).  To keep the client from having to determine the actual
11517c478bd9Sstevel@tonic-gate  * length of the one attribute (since we do it here) the is_get_resp parameter
11527c478bd9Sstevel@tonic-gate  * indicates that there is one attribute in the buffer.
11537c478bd9Sstevel@tonic-gate  */
11547c478bd9Sstevel@tonic-gate int
ibmf_saa_utils_unpack_payload(uchar_t * buf_payload,size_t buf_payload_length,uint16_t attr_id,void ** structs_payloadp,size_t * structs_payload_lengthp,uint16_t attr_offset,boolean_t is_get_resp,int km_sleep_flag)11557c478bd9Sstevel@tonic-gate ibmf_saa_utils_unpack_payload(uchar_t *buf_payload, size_t buf_payload_length,
11567c478bd9Sstevel@tonic-gate     uint16_t attr_id, void **structs_payloadp, size_t *structs_payload_lengthp,
11577c478bd9Sstevel@tonic-gate     uint16_t attr_offset, boolean_t is_get_resp, int km_sleep_flag)
11587c478bd9Sstevel@tonic-gate {
11597c478bd9Sstevel@tonic-gate 
11607c478bd9Sstevel@tonic-gate 	int	i;
11617c478bd9Sstevel@tonic-gate 	int	struct_size, buf_size;
11627c478bd9Sstevel@tonic-gate 	int	num_records;
11637c478bd9Sstevel@tonic-gate 	void	(*unpack_data_fn)(uchar_t *, void *);
11647c478bd9Sstevel@tonic-gate 	int	bytes_between_recs;
11657c478bd9Sstevel@tonic-gate 
11667c478bd9Sstevel@tonic-gate 	if (buf_payload_length == 0) {
11677c478bd9Sstevel@tonic-gate 
11687c478bd9Sstevel@tonic-gate 		*structs_payload_lengthp = 0;
11697c478bd9Sstevel@tonic-gate 		*structs_payloadp = NULL;
11707c478bd9Sstevel@tonic-gate 
11717c478bd9Sstevel@tonic-gate 		return (IBMF_SUCCESS);
11727c478bd9Sstevel@tonic-gate 	}
11737c478bd9Sstevel@tonic-gate 
11747c478bd9Sstevel@tonic-gate 	switch (attr_id) {
1175934f0bccShiremath 		case SA_CLASSPORTINFO_ATTRID:
1176934f0bccShiremath 			struct_size = sizeof (ib_mad_classportinfo_t);
1177934f0bccShiremath 			buf_size = IB_MAD_CLASSPORTINFO_SIZE;
1178934f0bccShiremath 			unpack_data_fn = ibmf_saa_classportinfo_parse_buffer;
1179934f0bccShiremath 			break;
11807c478bd9Sstevel@tonic-gate 		case SA_NOTICE_ATTRID:
11817c478bd9Sstevel@tonic-gate 			struct_size = sizeof (ib_mad_notice_t);
11827c478bd9Sstevel@tonic-gate 			buf_size = IB_MAD_NOTICE_SIZE;
11837c478bd9Sstevel@tonic-gate 			unpack_data_fn = ibmf_saa_notice_parse_buffer;
11847c478bd9Sstevel@tonic-gate 			break;
11857c478bd9Sstevel@tonic-gate 		case SA_INFORMINFO_ATTRID:
11867c478bd9Sstevel@tonic-gate 			struct_size = sizeof (ib_mad_informinfo_t);
11877c478bd9Sstevel@tonic-gate 			buf_size = IB_MAD_INFORMINFO_SIZE;
11887c478bd9Sstevel@tonic-gate 			unpack_data_fn = ibmf_saa_informinfo_parse_buffer;
11897c478bd9Sstevel@tonic-gate 			break;
11907c478bd9Sstevel@tonic-gate 		case SA_NODERECORD_ATTRID:
11917c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_node_record_t);
11927c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_NODE_RECORD_SIZE;
11937c478bd9Sstevel@tonic-gate 			unpack_data_fn = ibmf_saa_node_record_parse_buffer;
11947c478bd9Sstevel@tonic-gate 			break;
11957c478bd9Sstevel@tonic-gate 		case SA_PORTINFORECORD_ATTRID:
11967c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_portinfo_record_t);
11977c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_PORTINFO_RECORD_SIZE;
11987c478bd9Sstevel@tonic-gate 			unpack_data_fn = ibmf_saa_portinfo_record_parse_buffer;
11997c478bd9Sstevel@tonic-gate 			break;
12007c478bd9Sstevel@tonic-gate 		case SA_SLTOVLRECORD_ATTRID:
12017c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_SLtoVLmapping_record_t);
12027c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_SLTOVL_RECORD_SIZE;
12037c478bd9Sstevel@tonic-gate 			unpack_data_fn =
12047c478bd9Sstevel@tonic-gate 			    ibmf_saa_SLtoVLmapping_record_parse_buffer;
12057c478bd9Sstevel@tonic-gate 			break;
12067c478bd9Sstevel@tonic-gate 		case SA_SWITCHINFORECORD_ATTRID:
12077c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_switchinfo_record_t);
12087c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_SWITCHINFO_RECORD_SIZE;
12097c478bd9Sstevel@tonic-gate 			unpack_data_fn =
12107c478bd9Sstevel@tonic-gate 			    ibmf_saa_switchinfo_record_parse_buffer;
12117c478bd9Sstevel@tonic-gate 			break;
12127c478bd9Sstevel@tonic-gate 		case SA_LINEARFDBRECORD_ATTRID:
12137c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_linearft_record_t);
12147c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_LINEARFDB_RECORD_SIZE;
12157c478bd9Sstevel@tonic-gate 			unpack_data_fn = ibmf_saa_linearft_record_parse_buffer;
12167c478bd9Sstevel@tonic-gate 			break;
12177c478bd9Sstevel@tonic-gate 		case SA_RANDOMFDBRECORD_ATTRID:
12187c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_randomft_record_t);
12197c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_RANDOMFDB_RECORD_SIZE;
12207c478bd9Sstevel@tonic-gate 			unpack_data_fn = ibmf_saa_randomft_record_parse_buffer;
12217c478bd9Sstevel@tonic-gate 			break;
12227c478bd9Sstevel@tonic-gate 		case SA_MULTICASTFDBRECORD_ATTRID:
12237c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_multicastft_record_t);
12247c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_MULTICASTFDB_RECORD_SIZE;
12257c478bd9Sstevel@tonic-gate 			unpack_data_fn =
12267c478bd9Sstevel@tonic-gate 			    ibmf_saa_multicastft_record_parse_buffer;
12277c478bd9Sstevel@tonic-gate 			break;
12287c478bd9Sstevel@tonic-gate 		case SA_SMINFORECORD_ATTRID:
12297c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_sminfo_record_t);
12307c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_SMINFO_RECORD_SIZE;
12317c478bd9Sstevel@tonic-gate 			unpack_data_fn = ibmf_saa_sminfo_record_parse_buffer;
12327c478bd9Sstevel@tonic-gate 			break;
12337c478bd9Sstevel@tonic-gate 		case SA_INFORMINFORECORD_ATTRID:
12347c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_informinfo_record_t);
12357c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_INFORMINFO_RECORD_SIZE;
12367c478bd9Sstevel@tonic-gate 			unpack_data_fn =
12377c478bd9Sstevel@tonic-gate 			    ibmf_saa_informinfo_record_parse_buffer;
12387c478bd9Sstevel@tonic-gate 			break;
12397c478bd9Sstevel@tonic-gate 		case SA_LINKRECORD_ATTRID:
12407c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_link_record_t);
12417c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_LINK_RECORD_SIZE;
12427c478bd9Sstevel@tonic-gate 			unpack_data_fn = ibmf_saa_link_record_parse_buffer;
12437c478bd9Sstevel@tonic-gate 			break;
12447c478bd9Sstevel@tonic-gate 		case SA_GUIDINFORECORD_ATTRID:
12457c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_guidinfo_record_t);
12467c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_GUIDINFO_RECORD_SIZE;
12477c478bd9Sstevel@tonic-gate 			unpack_data_fn = ibmf_saa_guidinfo_record_parse_buffer;
12487c478bd9Sstevel@tonic-gate 			break;
12497c478bd9Sstevel@tonic-gate 		case SA_SERVICERECORD_ATTRID:
12507c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_service_record_t);
12517c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_SERVICE_RECORD_SIZE;
12527c478bd9Sstevel@tonic-gate 			unpack_data_fn = ibmf_saa_service_record_parse_buffer;
12537c478bd9Sstevel@tonic-gate 			break;
12547c478bd9Sstevel@tonic-gate 		case SA_PARTITIONRECORD_ATTRID:
12557c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_pkey_table_record_t);
12567c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_PARTITION_RECORD_SIZE;
12577c478bd9Sstevel@tonic-gate 			unpack_data_fn =
12587c478bd9Sstevel@tonic-gate 			    ibmf_saa_partition_record_parse_buffer;
12597c478bd9Sstevel@tonic-gate 			break;
12607c478bd9Sstevel@tonic-gate 		case SA_PATHRECORD_ATTRID:
12617c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_path_record_t);
12627c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_PATH_RECORD_SIZE;
12637c478bd9Sstevel@tonic-gate 			unpack_data_fn = ibmf_saa_path_record_parse_buffer;
12647c478bd9Sstevel@tonic-gate 			break;
12657c478bd9Sstevel@tonic-gate 		case SA_VLARBRECORD_ATTRID:
12667c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_VLarb_table_record_t);
12677c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_VLARB_RECORD_SIZE;
12687c478bd9Sstevel@tonic-gate 			unpack_data_fn = ibmf_saa_vlarb_record_parse_buffer;
12697c478bd9Sstevel@tonic-gate 			break;
12707c478bd9Sstevel@tonic-gate 		case SA_MCMEMBERRECORD_ATTRID:
12717c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_mcmember_record_t);
12727c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_MCMEMBER_RECORD_SIZE;
12737c478bd9Sstevel@tonic-gate 			unpack_data_fn = ibmf_saa_mcmember_record_parse_buffer;
12747c478bd9Sstevel@tonic-gate 			break;
12757c478bd9Sstevel@tonic-gate 		case SA_TRACERECORD_ATTRID:
12767c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_trace_record_t);
12777c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_TRACE_RECORD_SIZE;
12787c478bd9Sstevel@tonic-gate 			unpack_data_fn = ibmf_saa_trace_record_parse_buffer;
12797c478bd9Sstevel@tonic-gate 			break;
12807c478bd9Sstevel@tonic-gate 		case SA_MULTIPATHRECORD_ATTRID:
12817c478bd9Sstevel@tonic-gate 			/*
12827c478bd9Sstevel@tonic-gate 			 * array is of size 1 since multipath can be request
12837c478bd9Sstevel@tonic-gate 			 * only; data size greater than multipath_record_t
12847c478bd9Sstevel@tonic-gate 			 * size is due to gids at the end
12857c478bd9Sstevel@tonic-gate 			 */
12867c478bd9Sstevel@tonic-gate 			buf_size = buf_payload_length;
12877c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_multipath_record_t) +
12887c478bd9Sstevel@tonic-gate 			    buf_size - IBMF_SAA_MULTIPATH_RECORD_SIZE;
12897c478bd9Sstevel@tonic-gate 			unpack_data_fn = ibmf_saa_multipath_record_parse_buffer;
12907c478bd9Sstevel@tonic-gate 			break;
12917c478bd9Sstevel@tonic-gate 		case SA_SERVICEASSNRECORD_ATTRID:
12927c478bd9Sstevel@tonic-gate 			struct_size = sizeof (sa_service_assn_record_t);
12937c478bd9Sstevel@tonic-gate 			buf_size = IBMF_SAA_SERVICEASSN_RECORD_SIZE;
12947c478bd9Sstevel@tonic-gate 			unpack_data_fn =
12957c478bd9Sstevel@tonic-gate 			    ibmf_saa_service_assn_record_parse_buffer;
12967c478bd9Sstevel@tonic-gate 			break;
12977c478bd9Sstevel@tonic-gate 		default:
12987c478bd9Sstevel@tonic-gate 			/* don't know about structure; do bcopy */
12997c478bd9Sstevel@tonic-gate 
13007c478bd9Sstevel@tonic-gate 			*structs_payload_lengthp = buf_payload_length;
13017c478bd9Sstevel@tonic-gate 			*structs_payloadp = kmem_zalloc(
13027c478bd9Sstevel@tonic-gate 			    *structs_payload_lengthp, km_sleep_flag);
13037c478bd9Sstevel@tonic-gate 			if (*structs_payloadp == NULL) {
13047c478bd9Sstevel@tonic-gate 
13057c478bd9Sstevel@tonic-gate 				*structs_payload_lengthp = 0;
13067c478bd9Sstevel@tonic-gate 				return (IBMF_NO_MEMORY);
13077c478bd9Sstevel@tonic-gate 			}
13087c478bd9Sstevel@tonic-gate 
13097c478bd9Sstevel@tonic-gate 			bcopy(buf_payload, *structs_payloadp,
13107c478bd9Sstevel@tonic-gate 			    *structs_payload_lengthp);
13117c478bd9Sstevel@tonic-gate 
13127c478bd9Sstevel@tonic-gate 			return (IBMF_SUCCESS);
13137c478bd9Sstevel@tonic-gate 	}
13147c478bd9Sstevel@tonic-gate 
13157c478bd9Sstevel@tonic-gate 	/* compute distance between successive records */
13167c478bd9Sstevel@tonic-gate 	if (attr_offset > 0) {
13177c478bd9Sstevel@tonic-gate 
13187c478bd9Sstevel@tonic-gate 		if ((attr_offset * 8) < buf_size) {
13197c478bd9Sstevel@tonic-gate 
13207c478bd9Sstevel@tonic-gate 			IBMF_TRACE_3(IBMF_TNF_DEBUG, DPRINT_L1,
13217c478bd9Sstevel@tonic-gate 			    ibmf_saa_utils_unpack_payload, IBMF_TNF_ERROR, "",
13227c478bd9Sstevel@tonic-gate 			    "ibmf_saa_utils_unpack_payload: %s, attr_offset = "
13237c478bd9Sstevel@tonic-gate 			    "%d, attr_size = %d\n",
13247c478bd9Sstevel@tonic-gate 			    tnf_string, msg, "attribute offset times 8 is less"
13257c478bd9Sstevel@tonic-gate 			    " than attribute size",
13267c478bd9Sstevel@tonic-gate 			    tnf_int, attr_offset, attr_offset,
13277c478bd9Sstevel@tonic-gate 			    tnf_int, attr_size, buf_size);
13287c478bd9Sstevel@tonic-gate 
13297c478bd9Sstevel@tonic-gate 			return (IBMF_TRANS_FAILURE);
13307c478bd9Sstevel@tonic-gate 		}
13317c478bd9Sstevel@tonic-gate 
13327c478bd9Sstevel@tonic-gate 		bytes_between_recs = attr_offset * 8;
13337c478bd9Sstevel@tonic-gate 	} else {
13347c478bd9Sstevel@tonic-gate 		bytes_between_recs = buf_size;
13357c478bd9Sstevel@tonic-gate 	}
13367c478bd9Sstevel@tonic-gate 
13377c478bd9Sstevel@tonic-gate 	if (is_get_resp == B_TRUE) {
13387c478bd9Sstevel@tonic-gate 
13397c478bd9Sstevel@tonic-gate 		buf_payload_length = buf_size;
13407c478bd9Sstevel@tonic-gate 		num_records = 1;
13417c478bd9Sstevel@tonic-gate 	} else {
13427c478bd9Sstevel@tonic-gate 
13437c478bd9Sstevel@tonic-gate 		num_records = buf_payload_length / bytes_between_recs;
13447c478bd9Sstevel@tonic-gate 	}
13457c478bd9Sstevel@tonic-gate 
13467c478bd9Sstevel@tonic-gate 	*structs_payload_lengthp = num_records * struct_size;
13477c478bd9Sstevel@tonic-gate 
13487c478bd9Sstevel@tonic-gate 	*structs_payloadp = kmem_zalloc(*structs_payload_lengthp,
13497c478bd9Sstevel@tonic-gate 	    km_sleep_flag);
13507c478bd9Sstevel@tonic-gate 	if (*structs_payloadp == NULL) {
13517c478bd9Sstevel@tonic-gate 
13527c478bd9Sstevel@tonic-gate 		IBMF_TRACE_2(IBMF_TNF_DEBUG, DPRINT_L1,
13537c478bd9Sstevel@tonic-gate 		    ibmf_saa_utils_unpack_payload_err,
13547c478bd9Sstevel@tonic-gate 		    IBMF_TNF_ERROR, "", "ibmf_saa_utils_unpack_payload: %s,"
13557c478bd9Sstevel@tonic-gate 		    " size = %d\n",
13567c478bd9Sstevel@tonic-gate 		    tnf_string, msg, "could not allocate memory for payload",
13577c478bd9Sstevel@tonic-gate 		    tnf_int, size, *structs_payload_lengthp);
13587c478bd9Sstevel@tonic-gate 
13597c478bd9Sstevel@tonic-gate 		*structs_payload_lengthp = 0;
13607c478bd9Sstevel@tonic-gate 		return (IBMF_NO_MEMORY);
13617c478bd9Sstevel@tonic-gate 	}
13627c478bd9Sstevel@tonic-gate 
13637c478bd9Sstevel@tonic-gate 
13647c478bd9Sstevel@tonic-gate 	for (i = 0; i < num_records; i++) {
13657c478bd9Sstevel@tonic-gate 
13667c478bd9Sstevel@tonic-gate 		unpack_data_fn(
13677c478bd9Sstevel@tonic-gate 		    (uchar_t *)buf_payload + (i * bytes_between_recs),
13687c478bd9Sstevel@tonic-gate 		    (void *)((uchar_t *)*structs_payloadp + i *
13697c478bd9Sstevel@tonic-gate 		    struct_size));
13707c478bd9Sstevel@tonic-gate 	}
13717c478bd9Sstevel@tonic-gate 
13727c478bd9Sstevel@tonic-gate 	return (IBMF_SUCCESS);
13737c478bd9Sstevel@tonic-gate }
1374