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 2006 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 Completion Queue Processing routines.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Specifically it contains the various completion types, flags,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * structures used for managing Tavor completion queues, and prototypes
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * for many of the functions consumed by other parts of the Tavor driver
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * (including those routines directly exposed through the IBTF CI
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * interface).
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The following defines specify the default number of Completion Queues (CQ)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * their maximum size. Settings exist for the supported DDR DIMM sizes of
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * 128MB and 256MB. If a DIMM greater than 256 is found, then the 256MB
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * profile is used. See tavor_cfg.c for more discussion on config profiles.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * For manual configuration (not using config profiles), these values are
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * controllable through the "tavor_log_max_cq_sz" and "tavor_log_num_cq"
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * configuration variables, respectively. To override config profile settings
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the 'tavor_alt_config_enable' configuration variable must first be set.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Note: We also have a define for the minimum size of a CQ. CQs allocated
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * with size 0, 1, 2, or 3 will always get back a CQ of size 4. This is the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * smallest size that Tavor hardware and software can correctly handle.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Minimal configuration values.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The following macro determines whether the contents of CQ memory (CQEs)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * need to be sync'd (with ddi_dma_sync()). This decision is based on whether
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the CQ memory is in DDR memory (no sync) or system memory (sync required).
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Note: It doesn't make much sense to put CQEs in DDR memory (since they are
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * primarily written by HW and read by the CPU), but the driver does support
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * that possibility. And it also supports the possibility that if a CQ in
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * system memory is mapped DDI_DMA_CONSISTENT, it can be configured to not be
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * sync'd because of the "sync override" parameter in the config profile.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ((((((state)->ts_cfg_profile->cp_streaming_consistent) && \
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ((state)->ts_cfg_profile->cp_consistent_syncoverride))) || \
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ((cqinfo).qa_location == TAVOR_QUEUE_LOCATION_INDDR)) \
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The following defines specify the size of the individual Completion Queue
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Context (CQC) entries
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_CQC_SIZE (1 << TAVOR_CQC_SIZE_SHIFT)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * These are the defines for the Tavor CQ completion statuses. They are
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * specified by the Tavor register specification.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_CQE_LOC_EEC_ERR 0x3 /* unsupported: RD */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_CQE_LOCAL_RDD_VIO_ERR 0x20 /* unsupported: RD */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_CQE_REM_INV_RD_REQ_ERR 0x21 /* unsupported: RD */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_CQE_EEC_REM_ABORTED_ERR 0x22 /* unsupported: RD */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_CQE_INV_EEC_NUM_ERR 0x23 /* unsupported: RD */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_CQE_INV_EEC_STATE_ERR 0x24 /* unsupported: RD */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * These are the defines for the Tavor CQ entry types. They are also
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * specified by the Tavor register specification. They indicate what type
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * of work request is completing (for successful completions). Note: The
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * "SND" or "RCV" in each define is used to indicate whether the completion
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * work request was from the Send work queue or the Receive work queue on
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the associated QP.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/* Define for maximum CQ number mask (CQ number is 24 bits) */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * This define and the following macro are used to find an event queue for a
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * new CQ based on its completion queue number. Note: This is a rather
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * simple method that we use today. We simply choose from one of the first
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * 32 EQs based on the 5 least significant bits of the CQ number.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define TAVOR_CQ_EQNUM_GET(cqnum) ((cqnum) & TAVOR_CQ_TO_EQ_MASK)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The following macro is even simpler than the above one. This is used to
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * find an event queue for CQ errors for a new CQ. In theory we could do this
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * based on the CQ's number (as we do above). Today, however, all CQ error
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * events go to one specific EQ (i.e. EQ #32).
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The following defines are used for Tavor CQ error handling. Note: For
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * CQEs which correspond to error events, the Tavor device requires some
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * special handling by software. These defines are used to identify and
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * extract the necessary information from each error CQE, including status
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * code (above), doorbell count, and whether a error completion is for a
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * send or receive work request.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/* Defines for tracking whether a CQ is being used with special QP or not */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The tavor_sw_cq_s structure is also referred to using the "tavor_cqhdl_t"
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * typedef (see tavor_typedef.h). It encodes all the information necessary
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * to track the various resources needed to allocate, initialize, poll, resize,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * and (later) free a completion queue (CQ).
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Specifically, it has a consumer index and a lock to ensure single threaded
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * access to it. It has pointers to the various resources allocated for the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * completion queue, i.e. a CQC resource and the memory for the completion
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * queue itself. It has flags to indicate whether the CQ requires
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * ddi_dma_sync() ("cq_sync"). It also has a reference count and the number(s)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * of the EQs to which it is associated (for success and for errors).
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Additionally, it has a pointer to the associated MR handle (for the mapped
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * queue memory) and a void pointer that holds the argument that should be
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * passed back to the IBTF when events are generated on the CQ.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * We also have the always necessary backpointer to the resource for the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * CQ handle structure itself. But we also have pointers to the "Work Request
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * ID" processing lists (both the lock and the regular list, as well as the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * head and tail for the "reapable" list). See tavor_wrid.c for more details.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* For Work Request ID processing */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor_NOTE(DATA_READABLE_WITHOUT_LOCK(tavor_sw_cq_s::cq_bufsz
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor_NOTE(MUTEX_PROTECTS_DATA(tavor_sw_cq_s::cq_lock,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint tavor_cq_alloc(tavor_state_t *state, ibt_cq_hdl_t ibt_cqhdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ibt_cq_attr_t *attr_p, uint_t *actual_size, tavor_cqhdl_t *cqhdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint tavor_cq_free(tavor_state_t *state, tavor_cqhdl_t *cqhdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint tavor_cq_resize(tavor_state_t *state, tavor_cqhdl_t cqhdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint_t req_size, uint_t *actual_size, uint_t sleepflag);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint tavor_cq_notify(tavor_state_t *state, tavor_cqhdl_t cqhdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint tavor_cq_poll(tavor_state_t *state, tavor_cqhdl_t cqhdl, ibt_wc_t *wc_p,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint tavor_cq_handler(tavor_state_t *state, tavor_eqhdl_t eq,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint tavor_cq_err_handler(tavor_state_t *state, tavor_eqhdl_t eq,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint tavor_cq_refcnt_inc(tavor_cqhdl_t cq, uint_t is_special);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylortavor_cqhdl_t tavor_cqhdl_from_cqnum(tavor_state_t *state, uint_t cqnum);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorvoid tavor_cq_srq_entries_flush(tavor_state_t *state, tavor_qphdl_t qp);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif /* _SYS_IB_ADAPTERS_TAVOR_CQ_H */