xref: /onnv-gate/usr/src/uts/common/sys/ib/adapters/hermon/hermon_rsrc.h (revision 12965:b65a8427f8fe)
19517SBill.Taylor@Sun.COM /*
29517SBill.Taylor@Sun.COM  * CDDL HEADER START
39517SBill.Taylor@Sun.COM  *
49517SBill.Taylor@Sun.COM  * The contents of this file are subject to the terms of the
59517SBill.Taylor@Sun.COM  * Common Development and Distribution License (the "License").
69517SBill.Taylor@Sun.COM  * You may not use this file except in compliance with the License.
79517SBill.Taylor@Sun.COM  *
89517SBill.Taylor@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
99517SBill.Taylor@Sun.COM  * or http://www.opensolaris.org/os/licensing.
109517SBill.Taylor@Sun.COM  * See the License for the specific language governing permissions
119517SBill.Taylor@Sun.COM  * and limitations under the License.
129517SBill.Taylor@Sun.COM  *
139517SBill.Taylor@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
149517SBill.Taylor@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
159517SBill.Taylor@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
169517SBill.Taylor@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
179517SBill.Taylor@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
189517SBill.Taylor@Sun.COM  *
199517SBill.Taylor@Sun.COM  * CDDL HEADER END
209517SBill.Taylor@Sun.COM  */
219517SBill.Taylor@Sun.COM 
229517SBill.Taylor@Sun.COM /*
23*12965SWilliam.Taylor@Oracle.COM  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
249517SBill.Taylor@Sun.COM  */
259517SBill.Taylor@Sun.COM 
269517SBill.Taylor@Sun.COM #ifndef	_SYS_IB_ADAPTERS_HERMON_RSRC_H
279517SBill.Taylor@Sun.COM #define	_SYS_IB_ADAPTERS_HERMON_RSRC_H
289517SBill.Taylor@Sun.COM 
299517SBill.Taylor@Sun.COM /*
309517SBill.Taylor@Sun.COM  * hermon_rsrc.h
319517SBill.Taylor@Sun.COM  *    Contains all of the prototypes, #defines, and structures necessary
329517SBill.Taylor@Sun.COM  *    for the Hermon Resource Management routines.
339517SBill.Taylor@Sun.COM  *    Specifically it contains the resource names, resource types, and
349517SBill.Taylor@Sun.COM  *    structures used for enabling both init/fini and alloc/free operations.
359517SBill.Taylor@Sun.COM  */
369517SBill.Taylor@Sun.COM 
379517SBill.Taylor@Sun.COM #include <sys/types.h>
389517SBill.Taylor@Sun.COM #include <sys/conf.h>
399517SBill.Taylor@Sun.COM #include <sys/ddi.h>
409517SBill.Taylor@Sun.COM #include <sys/sunddi.h>
419517SBill.Taylor@Sun.COM #include <sys/disp.h>
429517SBill.Taylor@Sun.COM 
439517SBill.Taylor@Sun.COM #ifdef __cplusplus
449517SBill.Taylor@Sun.COM extern "C" {
459517SBill.Taylor@Sun.COM #endif
469517SBill.Taylor@Sun.COM 
479517SBill.Taylor@Sun.COM /*
489517SBill.Taylor@Sun.COM  * The above extern and the following #defines and macro are used to determine
499517SBill.Taylor@Sun.COM  * the current context for purposes of setting the sleepflag.  If the calling
509517SBill.Taylor@Sun.COM  * thread is running in the interrupt context, then macro will return
519517SBill.Taylor@Sun.COM  * HERMON_NOSLEEP (indicating that it is not appropriate to sleep in the current
529517SBill.Taylor@Sun.COM  * context.  In all other cases, this macro will return HERMON_SLEEP.
539517SBill.Taylor@Sun.COM  *
549517SBill.Taylor@Sun.COM  * The HERMON_CMD_SLEEP_NOSPIN and HERMON_CMD_NOSLEEP_SPIN #defines from
559517SBill.Taylor@Sun.COM  * hermon_cmd.h are set to use and be compatible with the following SLEEP
569517SBill.Taylor@Sun.COM  * variables.  It is important that these remain in sync so that the
579517SBill.Taylor@Sun.COM  * HERMON_SLEEPFLAG_FOR_CONTEXT() macro will work in all cases.
589517SBill.Taylor@Sun.COM  */
599517SBill.Taylor@Sun.COM #define	HERMON_SLEEP			0
609517SBill.Taylor@Sun.COM #define	HERMON_NOSLEEP			1
619517SBill.Taylor@Sun.COM #define	HERMON_SLEEPFLAG_FOR_CONTEXT()					\
629517SBill.Taylor@Sun.COM 	((servicing_interrupt() || ddi_in_panic()) ? HERMON_NOSLEEP :	\
639517SBill.Taylor@Sun.COM 	    HERMON_SLEEP)
649517SBill.Taylor@Sun.COM 
659517SBill.Taylor@Sun.COM /*
669517SBill.Taylor@Sun.COM  * The following #defines are used as the names for various resource pools.
679517SBill.Taylor@Sun.COM  * They represent the kmem_cache and vmem_arena names, respectively.  In
689517SBill.Taylor@Sun.COM  * order to provide for unique naming when multiple Hermon drivers are present,
699517SBill.Taylor@Sun.COM  * the HERMON_RSRC_NAME macro below is used to append the driver's instance
709517SBill.Taylor@Sun.COM  * number to the provided string.  Note: resource names should not be longer
719517SBill.Taylor@Sun.COM  * than HERMON_RSRC_NAME_MAXLEN.
729517SBill.Taylor@Sun.COM  */
739517SBill.Taylor@Sun.COM 
749517SBill.Taylor@Sun.COM 
759517SBill.Taylor@Sun.COM #define	HERMON_RSRC_CACHE		"hermon_rsrc_cache"
769517SBill.Taylor@Sun.COM #define	HERMON_PDHDL_CACHE		"hermon_pdhdl_cache"
779517SBill.Taylor@Sun.COM #define	HERMON_MRHDL_CACHE		"hermon_mrhdl_cache"
789517SBill.Taylor@Sun.COM #define	HERMON_EQHDL_CACHE		"hermon_eqhdl_cache"
799517SBill.Taylor@Sun.COM #define	HERMON_CQHDL_CACHE		"hermon_cqhdl_cache"
809517SBill.Taylor@Sun.COM #define	HERMON_SRQHDL_CACHE		"hermon_srqhdl_cache"
819517SBill.Taylor@Sun.COM #define	HERMON_AHHDL_CACHE		"hermon_ahhdl_cache"
829517SBill.Taylor@Sun.COM #define	HERMON_QPHDL_CACHE		"hermon_qphdl_cache"
839517SBill.Taylor@Sun.COM #define	HERMON_REFCNT_CACHE		"hermon_refcnt_cache"
849517SBill.Taylor@Sun.COM 
859517SBill.Taylor@Sun.COM #define	HERMON_ICM_VMEM			"hermon_icm_vmem"
869517SBill.Taylor@Sun.COM #define	HERMON_INMBOX_VMEM		"hermon_inmbox_vmem"
879517SBill.Taylor@Sun.COM #define	HERMON_OUTMBOX_VMEM		"hermon_outmbox_vmem"
889517SBill.Taylor@Sun.COM #define	HERMON_INTR_INMBOX_VMEM		"hermon_intr_inmbox_vmem"
899517SBill.Taylor@Sun.COM #define	HERMON_INTR_OUTMBOX_VMEM	"hermon_intr_outmbox_vmem"
909517SBill.Taylor@Sun.COM /* ICM based vmem */
919517SBill.Taylor@Sun.COM #define	HERMON_CMPT_VMEM		"hermon_cmpt_vmem"
929517SBill.Taylor@Sun.COM #define	HERMON_CMPT_QPC_VMEM		"hermon_cmpt_qpc_vmem"
939517SBill.Taylor@Sun.COM #define	HERMON_CMPT_SRQ_VMEM		"hermon_cmpt_srq_vmem"
949517SBill.Taylor@Sun.COM #define	HERMON_CMPT_CQC_VMEM		"hermon_cmpt_cqc_vmem"
959517SBill.Taylor@Sun.COM #define	HERMON_CMPT_EQC_VMEM		"hermon_cmpt_eqc_vmem"
969517SBill.Taylor@Sun.COM #define	HERMON_DMPT_VMEM		"hermon_dmpt_vmem"
979517SBill.Taylor@Sun.COM #define	HERMON_MTT_VMEM			"hermon_mtt_vmem"
989517SBill.Taylor@Sun.COM #define	HERMON_QPC_VMEM			"hermon_qpc_vmem"
999517SBill.Taylor@Sun.COM #define	HERMON_SRQC_VMEM		"hermon_srqc_vmem"
1009517SBill.Taylor@Sun.COM #define	HERMON_RDB_VMEM			"hermon_rdb_vmem"
1019517SBill.Taylor@Sun.COM #define	HERMON_CQC_VMEM			"hermon_cqc_vmem"
1029517SBill.Taylor@Sun.COM #define	HERMON_ALTC_VMEM		"hermon_altc_vmem"
1039517SBill.Taylor@Sun.COM #define	HERMON_AUXC_VMEM		"hermon_auxc_vmem"
1049517SBill.Taylor@Sun.COM #define	HERMON_EQC_VMEM			"hermon_eqc_vmem"
1059517SBill.Taylor@Sun.COM #define	HERMON_MCG_VMEM			"hermon_mcg_vmem"
1069517SBill.Taylor@Sun.COM /* Add'd vmem arenas */
1079517SBill.Taylor@Sun.COM #define	HERMON_UAR_PAGE_VMEM_ATTCH	"hermon_uar_pg_vmem:a"
1089517SBill.Taylor@Sun.COM #define	HERMON_UAR_PAGE_VMEM_RUNTM	"hermon_uar_pg_vmem:r"
1099517SBill.Taylor@Sun.COM #define	HERMON_BLUEFLAME_VMEM		"hermon_blueflame_vmem"
1109517SBill.Taylor@Sun.COM #define	HERMON_PDHDL_VMEM		"hermon_pd_vmem"
1119517SBill.Taylor@Sun.COM 
1129517SBill.Taylor@Sun.COM /* Macro provided for building unique naming for multiple instance  */
1139517SBill.Taylor@Sun.COM #define	HERMON_RSRC_NAME(rsrc_name, string)		\
1149517SBill.Taylor@Sun.COM 	(void) sprintf((rsrc_name), string"%08X",	\
1159517SBill.Taylor@Sun.COM 	    state->hs_instance)
1169517SBill.Taylor@Sun.COM #define	HERMON_RSRC_NAME_MAXLEN		0x80
1179517SBill.Taylor@Sun.COM 
1189517SBill.Taylor@Sun.COM /* various cMPT types - need to concatenate w/ index to find it in ICM */
1199517SBill.Taylor@Sun.COM typedef enum {
1209517SBill.Taylor@Sun.COM 	HERMON_QP_CMPT	= 0,
1219517SBill.Taylor@Sun.COM 	HERMON_SRQ_CMPT	= 1,
1229517SBill.Taylor@Sun.COM 	HERMON_CQ_CMPT	= 2,
1239517SBill.Taylor@Sun.COM 	HERMON_EQ_CMPT	= 3,
1249517SBill.Taylor@Sun.COM 	HERMON_MPT_DMPT	= 4
1259517SBill.Taylor@Sun.COM } hermon_mpt_rsrc_type_t;
1269517SBill.Taylor@Sun.COM 
1279517SBill.Taylor@Sun.COM 
1289517SBill.Taylor@Sun.COM /*
1299517SBill.Taylor@Sun.COM  * The following enumerated type is used to capture all the various types
1309517SBill.Taylor@Sun.COM  * of Hermon resources.  Note the HERMON_NUM_RESOURCES type is used as a marker
1319517SBill.Taylor@Sun.COM  * for the end of the resource types.  No additional resources should be
1329517SBill.Taylor@Sun.COM  * added after this. Note also that HERMON_NUM_ICM_RESOURCES is used similarly,
1339517SBill.Taylor@Sun.COM  * indicating the number of ICM resource types. If additional ICM types are
1349517SBill.Taylor@Sun.COM  * added, they should be added before MERMON_NUM_ICM_RESOURCES.
1359517SBill.Taylor@Sun.COM  */
1369517SBill.Taylor@Sun.COM 
1379517SBill.Taylor@Sun.COM typedef enum {
1389517SBill.Taylor@Sun.COM 	HERMON_CMPT,		/* for sizing ICM space for control MPTs */
1399517SBill.Taylor@Sun.COM 	HERMON_QPC,
1409517SBill.Taylor@Sun.COM 	HERMON_SRQC,
1419517SBill.Taylor@Sun.COM 	HERMON_CQC,
1429517SBill.Taylor@Sun.COM 	HERMON_EQC,
1439517SBill.Taylor@Sun.COM 	HERMON_DMPT,
1449517SBill.Taylor@Sun.COM 	HERMON_MTT,
1459517SBill.Taylor@Sun.COM 	HERMON_ALTC,		/* for allocation of ICM backing memory */
1469517SBill.Taylor@Sun.COM 	HERMON_AUXC,		/* for allocation of ICM backing memory */
1479517SBill.Taylor@Sun.COM 	HERMON_RDB,		/* for allocation of ICM backing memory */
1489517SBill.Taylor@Sun.COM 	HERMON_CMPT_QPC,	/* for allocation of ICM backing memory */
1499517SBill.Taylor@Sun.COM 	HERMON_CMPT_SRQC,	/* for allocation of ICM backing memory */
1509517SBill.Taylor@Sun.COM 	HERMON_CMPT_CQC,	/* for allocation of ICM backing memory */
1519517SBill.Taylor@Sun.COM 	HERMON_CMPT_EQC,	/* for allocation of ICM backing memory */
1529517SBill.Taylor@Sun.COM 	HERMON_MCG,		/* type 0x0E */
1539517SBill.Taylor@Sun.COM 	/* all types above are in ICM, all below are in non-ICM */
1549517SBill.Taylor@Sun.COM 	HERMON_NUM_ICM_RESOURCES,
1559517SBill.Taylor@Sun.COM 	HERMON_IN_MBOX = HERMON_NUM_ICM_RESOURCES,
1569517SBill.Taylor@Sun.COM 	HERMON_OUT_MBOX,	/* type 0x10 */
1579517SBill.Taylor@Sun.COM 	HERMON_PDHDL,
1589517SBill.Taylor@Sun.COM 	HERMON_MRHDL,
1599517SBill.Taylor@Sun.COM 	HERMON_EQHDL,
1609517SBill.Taylor@Sun.COM 	HERMON_CQHDL,
1619517SBill.Taylor@Sun.COM 	HERMON_QPHDL,
1629517SBill.Taylor@Sun.COM 	HERMON_SRQHDL,
1639517SBill.Taylor@Sun.COM 	HERMON_AHHDL,
1649517SBill.Taylor@Sun.COM 	HERMON_REFCNT,
1659517SBill.Taylor@Sun.COM 	HERMON_UARPG,
1669517SBill.Taylor@Sun.COM 	HERMON_INTR_IN_MBOX,
1679517SBill.Taylor@Sun.COM 	HERMON_INTR_OUT_MBOX,	/* type 0x1B */
168*12965SWilliam.Taylor@Oracle.COM 	HERMON_QPC_FEXCH_PORT1,
169*12965SWilliam.Taylor@Oracle.COM 	HERMON_QPC_FEXCH_PORT2,
170*12965SWilliam.Taylor@Oracle.COM 	HERMON_QPC_RFCI_PORT1,
171*12965SWilliam.Taylor@Oracle.COM 	HERMON_QPC_RFCI_PORT2,
1729517SBill.Taylor@Sun.COM 	HERMON_NUM_RESOURCES
1739517SBill.Taylor@Sun.COM } hermon_rsrc_type_t;
1749517SBill.Taylor@Sun.COM 
1759517SBill.Taylor@Sun.COM /*
1769517SBill.Taylor@Sun.COM  * The following enumerated type and structures are used during resource
1779517SBill.Taylor@Sun.COM  * initialization.  Note: The HERMON_RSRC_CLEANUP_ALL type is used as a marker
1789517SBill.Taylor@Sun.COM  * for end of the cleanup steps.  No cleanup steps should be added after
1799517SBill.Taylor@Sun.COM  * HERMON_RSRC_CLEANUP_ALL.  Any addition steps should be added before it.
1809517SBill.Taylor@Sun.COM  */
1819517SBill.Taylor@Sun.COM typedef enum {
1829517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL0,
1839517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL1,
1849517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL2,
1859517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL3,
1869517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL4,
1879517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL5,
1889517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL6,
1899517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL7,
1909517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_PHASE1_COMPLETE,
1919517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL8,
1929517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL9,
1939517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL10,
1949517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL10QP,
1959517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL10SRQ,
1969517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL10CQ,
1979517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL10EQ,
1989517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL11,
1999517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL12,
2009517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL13,
2019517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL14,
2029517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL15,
2039517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL16,
2049517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL17,
2059517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL18,
2069517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL19,
2079517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL20,
2089517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL21,
2099517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL22,
2109517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL23,
2119517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL24,
2129517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL25,
2139517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL26,
2149517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL27,
2159517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL28,
2169517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL29,
2179517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL30,
2189517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_LEVEL31,
2199517SBill.Taylor@Sun.COM 	/* No more cleanup steps below this point! */
2209517SBill.Taylor@Sun.COM 	HERMON_RSRC_CLEANUP_ALL
2219517SBill.Taylor@Sun.COM } hermon_rsrc_cleanup_level_t;
2229517SBill.Taylor@Sun.COM 
2239517SBill.Taylor@Sun.COM /*
2249517SBill.Taylor@Sun.COM  * The hermon_rsrc_mbox_info_t structure is used when initializing the two
2259517SBill.Taylor@Sun.COM  * Hermon mailbox types ("In" and "Out").  This structure contains the
2269517SBill.Taylor@Sun.COM  * requested number and size of the mailboxes, and the resource pool from
2279517SBill.Taylor@Sun.COM  * which the other relevant properties will come.
2289517SBill.Taylor@Sun.COM  */
2299517SBill.Taylor@Sun.COM typedef struct hermon_rsrc_mbox_info_s {
2309517SBill.Taylor@Sun.COM 	uint64_t		mbi_num;
2319517SBill.Taylor@Sun.COM 	uint64_t		mbi_size;
2329517SBill.Taylor@Sun.COM 	hermon_rsrc_pool_info_t *mbi_rsrcpool;
2339517SBill.Taylor@Sun.COM } hermon_rsrc_mbox_info_t;
2349517SBill.Taylor@Sun.COM 
2359517SBill.Taylor@Sun.COM /*
2369517SBill.Taylor@Sun.COM  * The hermon_rsrc_hw_entry_info_t structure is used when initializing the
2379517SBill.Taylor@Sun.COM  * Hermon HW entry types.  This structure contains the requested number of
2389517SBill.Taylor@Sun.COM  * entries for the resource.  That value is compared against the maximum
2399517SBill.Taylor@Sun.COM  * number (usually determined as a result of the Hermon QUERY_DEV_CAP command).
2409517SBill.Taylor@Sun.COM  * In addition it contains a number of requested entries to be "pre-allocated"
2419517SBill.Taylor@Sun.COM  * (this is generally because the Hermon hardware requires a certain number
2429517SBill.Taylor@Sun.COM  * for its own purposes).  Lastly the resource pool and resource name
2439517SBill.Taylor@Sun.COM  * information.
2449517SBill.Taylor@Sun.COM  */
2459517SBill.Taylor@Sun.COM typedef struct hermon_rsrc_hw_entry_info_s {
2469517SBill.Taylor@Sun.COM 	uint64_t		hwi_num;
2479517SBill.Taylor@Sun.COM 	uint64_t		hwi_max;
2489517SBill.Taylor@Sun.COM 	uint64_t		hwi_prealloc;
2499517SBill.Taylor@Sun.COM 	hermon_rsrc_pool_info_t *hwi_rsrcpool;
2509517SBill.Taylor@Sun.COM 	char			*hwi_rsrcname;
2519517SBill.Taylor@Sun.COM } hermon_rsrc_hw_entry_info_t;
2529517SBill.Taylor@Sun.COM 
2539517SBill.Taylor@Sun.COM /*
2549517SBill.Taylor@Sun.COM  * The hermon_rsrc_sw_hdl_info_t structure is used when initializing the
2559517SBill.Taylor@Sun.COM  * Hermon software handle types.  This structure also contains the requested
2569517SBill.Taylor@Sun.COM  * number of handles for the resource.  That value is compared against a
2579517SBill.Taylor@Sun.COM  * maximum number passed in.  Because many of the software handle resource
2589517SBill.Taylor@Sun.COM  * types are managed through the use of kmem_cache, fields are provided for
2599517SBill.Taylor@Sun.COM  * specifying cache constructor and destructor methods.  Just like above,
2609517SBill.Taylor@Sun.COM  * there is space for resource pool and resource name information.  And,
2619517SBill.Taylor@Sun.COM  * somewhat like above, there is space to provide information (size, type,
2629517SBill.Taylor@Sun.COM  * pointer to table, etc). about any "pre-allocated" resources that need to
2639517SBill.Taylor@Sun.COM  * be set aside.
2649517SBill.Taylor@Sun.COM  * Note specifically that the "swi_flags" field may contain any of the flags
2659517SBill.Taylor@Sun.COM  * #define'd below.  The HERMON_SWHDL_KMEMCACHE_INIT flag indicates that the
2669517SBill.Taylor@Sun.COM  * given resource should have a kmem_cache setup for it, and the
2679517SBill.Taylor@Sun.COM  * HERMON_SWHDL_TABLE_INIT flag indicates that some preallocation (as defined
2689517SBill.Taylor@Sun.COM  * by the "swi_num" and "swi_prealloc_sz" fields) should be done, with the
2699517SBill.Taylor@Sun.COM  * resulting table pointer passed back in "swi_table_ptr".
2709517SBill.Taylor@Sun.COM  */
2719517SBill.Taylor@Sun.COM typedef struct hermon_rsrc_sw_hdl_info_s {
2729517SBill.Taylor@Sun.COM 	uint64_t		swi_num;
2739517SBill.Taylor@Sun.COM 	uint64_t		swi_max;
2749517SBill.Taylor@Sun.COM 	uint64_t		swi_prealloc_sz;
2759517SBill.Taylor@Sun.COM 	hermon_rsrc_pool_info_t 	*swi_rsrcpool;
2769517SBill.Taylor@Sun.COM 	int (*swi_constructor)(void *, void *, int);
2779517SBill.Taylor@Sun.COM 	void (*swi_destructor)(void *, void *);
2789517SBill.Taylor@Sun.COM 	char			*swi_rsrcname;
2799517SBill.Taylor@Sun.COM 	uint_t			swi_flags;
2809517SBill.Taylor@Sun.COM 	void			*swi_table_ptr;
2819517SBill.Taylor@Sun.COM } hermon_rsrc_sw_hdl_info_t;
2829517SBill.Taylor@Sun.COM #define	HERMON_SWHDL_NOFLAGS		0
2839517SBill.Taylor@Sun.COM #define	HERMON_SWHDL_KMEMCACHE_INIT	(1 << 0)
2849517SBill.Taylor@Sun.COM #define	HERMON_SWHDL_TABLE_INIT		(1 << 1)
2859517SBill.Taylor@Sun.COM 
2869517SBill.Taylor@Sun.COM 
2879517SBill.Taylor@Sun.COM /*
2889517SBill.Taylor@Sun.COM  * The following structure is used to specify (at init time) and to track
2899517SBill.Taylor@Sun.COM  * (during allocation and freeing) all the useful information regarding a
2909517SBill.Taylor@Sun.COM  * particular resource type.  An array of these resources (indexed by
2919517SBill.Taylor@Sun.COM  * resource type) is allocated at driver startup time.  It is available
2929517SBill.Taylor@Sun.COM  * through the driver's soft state structure.
2939517SBill.Taylor@Sun.COM  * Each resource has an indication of its type and its location.  Resources
2949517SBill.Taylor@Sun.COM  * may be located in one of three possible places - in the Hermon ICM memory
2959517SBill.Taylor@Sun.COM  * (device virtual, backed by system memory),in system memory, or in
2969517SBill.Taylor@Sun.COM  * Hermon UAR memory (residing behind BAR2).
2979517SBill.Taylor@Sun.COM  * Each resource pool also has properties associated with it and the object
2989517SBill.Taylor@Sun.COM  * that make up the pool.  These include the pool's size, the size of the
2999517SBill.Taylor@Sun.COM  * individual objects (rsrc_quantum), any alignment restrictions placed on
3009517SBill.Taylor@Sun.COM  * the pool of objects, and the shift size (log2) of each object.
3019517SBill.Taylor@Sun.COM  * In addition (depending on object type) the "rsrc_ddr_offset" field may
3029517SBill.Taylor@Sun.COM  * indicate where in DDR memory a given resource pool is located (e.g. a
3039517SBill.Taylor@Sun.COM  * QP context table).  It may have a pointer to a vmem_arena for that table
3049517SBill.Taylor@Sun.COM  * and/or it may point to some other private information (rsrc_private)
3059517SBill.Taylor@Sun.COM  * specific to the given object type.
3069517SBill.Taylor@Sun.COM  * Always, though, the resource pool pointer provides a pointer back to the
3079517SBill.Taylor@Sun.COM  * soft state structure of the Hermon driver instance with which it is
3089517SBill.Taylor@Sun.COM  * associated.
3099517SBill.Taylor@Sun.COM  */
3109517SBill.Taylor@Sun.COM struct hermon_rsrc_pool_info_s {
3119517SBill.Taylor@Sun.COM 	hermon_rsrc_type_t	rsrc_type;
3129517SBill.Taylor@Sun.COM 	uint_t			rsrc_loc;
3139517SBill.Taylor@Sun.COM 	uint64_t		rsrc_pool_size; /* table size (num x size) */
3149517SBill.Taylor@Sun.COM 	uint64_t		rsrc_align;
3159517SBill.Taylor@Sun.COM 	uint_t			rsrc_shift;
3169517SBill.Taylor@Sun.COM 	uint_t			rsrc_quantum; /* size of each content */
3179517SBill.Taylor@Sun.COM 	void			*rsrc_start; /* phys start addr of table */
3189517SBill.Taylor@Sun.COM 	vmem_t			*rsrc_vmp; /* vmem arena for table */
3199517SBill.Taylor@Sun.COM 	hermon_state_t		*rsrc_state;
3209517SBill.Taylor@Sun.COM 	void			*rsrc_private;
3219517SBill.Taylor@Sun.COM };
3229517SBill.Taylor@Sun.COM #define	HERMON_IN_ICM			0x0
3239517SBill.Taylor@Sun.COM #define	HERMON_IN_SYSMEM		0x1
3249517SBill.Taylor@Sun.COM #define	HERMON_IN_UAR			0x2
3259517SBill.Taylor@Sun.COM 
3269517SBill.Taylor@Sun.COM /*
3279517SBill.Taylor@Sun.COM  * The hermon_rsrc_priv_mbox_t structure is used to pass along additional
3289517SBill.Taylor@Sun.COM  * information about the mailbox types.  Specifically, by containing the
3299517SBill.Taylor@Sun.COM  * DMA attributes, access handle, dev access handle, etc., it provides enough
3309517SBill.Taylor@Sun.COM  * information that each mailbox can be later by bound/unbound/etc. for
3319517SBill.Taylor@Sun.COM  * DMA access by the hardware.  Note: we can also specify (using the
3329517SBill.Taylor@Sun.COM  * "pmb_xfer_mode" field), whether a given mailbox type should be bound for
3339517SBill.Taylor@Sun.COM  * DDI_DMA_STREAMING or DDI_DMA_CONSISTENT operations.
3349517SBill.Taylor@Sun.COM  */
3359517SBill.Taylor@Sun.COM typedef struct hermon_rsrc_priv_mbox_s {
3369517SBill.Taylor@Sun.COM 	dev_info_t		*pmb_dip;
3379517SBill.Taylor@Sun.COM 	ddi_dma_attr_t		pmb_dmaattr;
3389517SBill.Taylor@Sun.COM 	/* JBDB what is this handle for? */
3399517SBill.Taylor@Sun.COM 	ddi_acc_handle_t	pmb_acchdl;
3409517SBill.Taylor@Sun.COM 	ddi_device_acc_attr_t	pmb_devaccattr;
3419517SBill.Taylor@Sun.COM 	uint_t			pmb_xfer_mode;
3429517SBill.Taylor@Sun.COM } hermon_rsrc_priv_mbox_t;
3439517SBill.Taylor@Sun.COM 
3449517SBill.Taylor@Sun.COM /*
3459517SBill.Taylor@Sun.COM  * The hermon_rsrc_t structure is the structure returned by the Hermon resource
3469517SBill.Taylor@Sun.COM  * allocation routines.  It contains all the necessary information about the
3479517SBill.Taylor@Sun.COM  * allocated object.  Specifically, it provides an address where the object
3489517SBill.Taylor@Sun.COM  * can be accessed.  It also provides the length and index (specifically, for
3499517SBill.Taylor@Sun.COM  * those resources that are accessed from tables).  In addition it can provide
3509517SBill.Taylor@Sun.COM  * an access handles and DMA handle to be used when accessing or setting DMA
3519517SBill.Taylor@Sun.COM  * to a specific object.  Note: not all of this information is valid for all
3529517SBill.Taylor@Sun.COM  * object types.  See the consumers of each object for more explanation of
3539517SBill.Taylor@Sun.COM  * which fields are used (and for what purpose).
3549517SBill.Taylor@Sun.COM  */
3559517SBill.Taylor@Sun.COM struct hermon_rsrc_s {
3569517SBill.Taylor@Sun.COM 	hermon_rsrc_type_t	rsrc_type;
3579517SBill.Taylor@Sun.COM 	void			*hr_addr;
3589517SBill.Taylor@Sun.COM 	uint32_t		hr_len;
3599517SBill.Taylor@Sun.COM 	uint32_t		hr_indx;
3609517SBill.Taylor@Sun.COM 	ddi_acc_handle_t	hr_acchdl;
3619517SBill.Taylor@Sun.COM 	ddi_dma_handle_t	hr_dmahdl;
3629517SBill.Taylor@Sun.COM };
3639517SBill.Taylor@Sun.COM 
3649517SBill.Taylor@Sun.COM /*
3659517SBill.Taylor@Sun.COM  * The following are the Hermon Resource Management routines that accessible
3669517SBill.Taylor@Sun.COM  * externally (i.e. throughout the rest of the Hermon driver software).
3679517SBill.Taylor@Sun.COM  * These include the alloc/free routines, the initialization routines, which
3689517SBill.Taylor@Sun.COM  * are broken into two phases (see hermon_rsrc.c for further explanation),
3699517SBill.Taylor@Sun.COM  * and the Hermon resource cleanup routines (which are used at driver detach()
3709517SBill.Taylor@Sun.COM  * time.
3719517SBill.Taylor@Sun.COM  */
3729517SBill.Taylor@Sun.COM int hermon_rsrc_alloc(hermon_state_t *state, hermon_rsrc_type_t rsrc,
3739517SBill.Taylor@Sun.COM     uint_t num, uint_t sleepflag, hermon_rsrc_t **hdl);
3749517SBill.Taylor@Sun.COM void hermon_rsrc_free(hermon_state_t *state, hermon_rsrc_t **hdl);
3759517SBill.Taylor@Sun.COM int hermon_rsrc_init_phase1(hermon_state_t *state);
3769517SBill.Taylor@Sun.COM int hermon_rsrc_init_phase2(hermon_state_t *state);
3779517SBill.Taylor@Sun.COM void hermon_rsrc_fini(hermon_state_t *state,
3789517SBill.Taylor@Sun.COM     hermon_rsrc_cleanup_level_t clean);
3799517SBill.Taylor@Sun.COM 
380*12965SWilliam.Taylor@Oracle.COM /* Exporting resource reservation capabilitity to FCoIB */
381*12965SWilliam.Taylor@Oracle.COM int hermon_rsrc_reserve(hermon_state_t *state, hermon_rsrc_type_t rsrc,
382*12965SWilliam.Taylor@Oracle.COM     uint_t num, uint_t sleepflag, hermon_rsrc_t **hdl);
3839517SBill.Taylor@Sun.COM 
3849517SBill.Taylor@Sun.COM #ifdef __cplusplus
3859517SBill.Taylor@Sun.COM }
3869517SBill.Taylor@Sun.COM #endif
3879517SBill.Taylor@Sun.COM 
3889517SBill.Taylor@Sun.COM #endif	/* _SYS_IB_ADAPTERS_HERMON_RSRC_H */
389