9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * CDDL HEADER START
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The contents of this file are subject to the terms of the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Common Development and Distribution License (the "License").
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * You may not use this file except in compliance with the License.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * See the License for the specific language governing permissions
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * and limitations under the License.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * When distributing Covered Code, include this CDDL HEADER in each
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * If applicable, add the following below this CDDL HEADER, with the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * fields enclosed by brackets "[]" replaced with your own identifying
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * information: Portions Copyright [yyyy] [name of copyright owner]
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * CDDL HEADER END
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Use is subject to license terms.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Contains all of the prototypes, #defines, and structures necessary
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * for the Tavor Resource Management routines.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Specifically it contains the resource names, resource types, and
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * structures used for enabling both init/fini and alloc/free operations.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The above extern and the following #defines and macro are used to determine
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the current context for purposes of setting the sleepflag. If the calling
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * thread is running in the interrupt context, then macro will return
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * TAVOR_NOSLEEP (indicating that it is not appropriate to sleep in the current
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * context. In all other cases, this macro will return TAVOR_SLEEP.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The TAVOR_CMD_SLEEP_NOSPIN and TAVOR_CMD_NOSLEEP_SPIN #defines from
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * tavor_cmd.h are set to use and be compatible with the following SLEEP
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * variables. It is important that these remain in sync so that the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * TAVOR_SLEEPFLAG_FOR_CONTEXT() macro will work in all cases.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ((servicing_interrupt() || ddi_in_panic()) ? TAVOR_NOSLEEP : \
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The following #defines are used as the names for various resource pools.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * They represent the kmem_cache and vmem_arena names, respectively. In
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * order to provide for unique naming when multiple Tavor drivers are present,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the TAVOR_RSRC_NAME macro below is used to append the driver's instance
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * number to the provided string. Note: resource names should not be longer
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * than TAVOR_RSRC_NAME_MAXLEN.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_DDR_INMBOX_VMEM "tavor_ddr_inmbox_vmem"
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_DDR_OUTMBOX_VMEM "tavor_ddr_outmbox_vmem"
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_DDR_INTR_INMBOX_VMEM "tavor_ddr_intr_inmbox_vmem"
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_DDR_INTR_OUTMBOX_VMEM "tavor_ddr_intr_outmbox_vmem"
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_DDR_SRQC_VMEM "tavor_ddr_srqc_vmem"
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_DDR_EQPC_VMEM "tavor_ddr_eqpc_vmem"
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_DDR_UARSCR_VMEM "tavor_ddr_uarscr_vmem"
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_DDR_UDAV_VMEM "tavor_ddr_udav_vmem"
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/* Macro provided for building unique naming for multiple instance */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The following enumerated type is used to capture all the various types
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * of Tavor resources. Note: The TAVOR_NUM_RESOURCES type is used as a
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * marker for the end of the resource types. No additional resources should
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * be added after TAVOR_NUM_RESOURCES. Any addition resources should be
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * added before it.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylortypedef enum {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* No more resources types below this point! */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The following enumerated type and structures are used during resource
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * initialization. Note: The TAVOR_RSRC_CLEANUP_ALL type is used as a marker
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * for end of the cleanup steps. No cleanup steps should be added after
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * TAVOR_RSRC_CLEANUP_ALL. Any addition steps should be added before it.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylortypedef enum {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* No more cleanup steps below this point! */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The tavor_rsrc_mbox_info_t structure is used when initializing the two
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Tavor mailbox types ("In" and "Out"). This structure contains the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * requested number and size of the mailboxes, the resource pool from which
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the other relevant properties will come, and the name of the resource
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The tavor_rsrc_hw_entry_info_t structure is used when initializing the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Tavor HW entry types. This structure contains the requested number of
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * entries for the resource. That value is compared against the maximum
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * number (usually determined as a result of the Tavor QUERY_DEV_LIM command).
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * In addition is contains a number of requested entries to be "pre-allocated"
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * (this is generally because the Tavor hardware requires a certain number
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * for its own purposes). Lastly the resource pool and resource name
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * information.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The tavor_rsrc_sw_hdl_info_t structure is used when initializing the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Tavor software handle types. This structure also contains the requested
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * number of handles for the resource. That value is compared against a
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * maximum number passed in. Because many of the software handle resource
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * types are managed through the use of kmem_cache, fields are provided for
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * specifying cache constructor and destructor methods. Just like above,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * there is space for resource pool and resource name information. And,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * somewhat like above, there is space to provide information (size, type,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * pointer to table, etc). about any "pre-allocated" resources that need to
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * be set aside.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Note specifically that the "swi_flags" field may contain any of the flags
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * #define'd below. The TAVOR_SWHDL_KMEMCACHE_INIT flag indicates that the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * given resource should have a kmem_cache setup for it, and the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * TAVOR_SWHDL_TABLE_INIT flag indicates that some preallocation (as defined
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * by the "swi_num" and "swi_prealloc_sz" fields) should be done, with the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * resulting table pointer passed back in "swi_table_ptr".
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The following structure is used to specify (at init time) and to track
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * (during allocation and freeing) all the useful information regarding a
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * particular resource type. An array of these resources (indexed by
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * resource type) is allocated at driver startup time. It is available
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * through the driver's soft state structure.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Each resource has an indication of its type and its location. Resources
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * may be located in one of three possible places - in Tavor DDR memory,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * in system memory, or in Tavor UAR memory.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Each resource pool also has properties associated with it and the object
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * that make up the pool. These include the pool's size, the size of the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * individual objects (rsrc_quantum), any alignment restrictions placed on
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the pool of objects, and the shift size (log2) of each object.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * In addition (depending on object type) the "rsrc_ddr_offset" field may
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * indicate where in DDR memory a given resource pool is located (e.g. a
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * QP context table). It may have a pointer to a vmem_arena for that table
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * and/or it may point to some other private information (rsrc_private)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * specific to the given object type.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Always, though, the resource pool pointer provides a pointer back to the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * soft state structure of the Tavor driver instance with which it is
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * associated.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The tavor_rsrc_priv_mbox_t structure is used to pass along additional
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * information about the mailbox types. Specifically, by containing the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DMA attributes, access handle, dev access handle, etc., it provides enough
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * information that each mailbox can be later by bound/unbound/etc. for
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DMA access by the hardware. Note: we can also specify (using the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * "pmb_xfer_mode" field), whether a given mailbox type should be bound for
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DDI_DMA_STREAMING or DDI_DMA_CONSISTENT operations.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The tavor_rsrc_t structure is the structure returned by the Tavor resource
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * allocation routines. It contains all the necessary information about the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * allocated object. Specifically, it provides an address where the object
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * can be accessed. It also provides the length and index (specifically, for
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * those resources that are accessed from tables). In addition it can provide
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * an access handles and DMA handle to be used when accessing or setting DMA
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * to a specific object. Note: not all of this information is valid for all
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * object types. See the consumers of each object for more explanation of
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * which fields are used (and for what purpose).
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The following are the Tavor Resource Management routines that accessible
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * externally (i.e. throughout the rest of the Tavor driver software).
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * These include the alloc/free routines, the initialization routines, which
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * are broken into two phases (see tavor_rsrc.c for further explanation),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * and the Tavor resource cleanup routines (which are used at driver detach()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint tavor_rsrc_alloc(tavor_state_t *state, tavor_rsrc_type_t rsrc,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint_t num, uint_t sleepflag, tavor_rsrc_t **hdl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorvoid tavor_rsrc_free(tavor_state_t *state, tavor_rsrc_t **hdl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint tavor_rsrc_init_phase1(tavor_state_t *state);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint tavor_rsrc_init_phase2(tavor_state_t *state);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif /* _SYS_IB_ADAPTERS_TAVOR_RSRC_H */