9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/*
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * CDDL HEADER START
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *
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 *
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * or http://www.opensolaris.org/os/licensing.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * See the License for the specific language governing permissions
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * and limitations under the License.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *
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 *
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * CDDL HEADER END
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/*
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#ifndef _SYS_IB_ADAPTERS_HERMON_MR_H
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define _SYS_IB_ADAPTERS_HERMON_MR_H
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/*
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_mr.h
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Contains all of the prototypes, #defines, and structures necessary
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * for the Hermon Memory Region/Window routines.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Specifically it contains #defines, macros, and prototypes for each of
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the required memory region/window verbs that can be accessed through
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the IBTF's CI interfaces. In particular each of the prototypes defined
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * below is called from a corresponding CI interface routine (as specified
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * in the hermon_ci.c file).
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#include <sys/types.h>
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#include <sys/conf.h>
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#include <sys/ddi.h>
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#include <sys/sunddi.h>
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#ifdef __cplusplus
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorextern "C" {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/*
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The following defines specify the default number of MPT entries to
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * configure. This value is controllable through the "hermon_log_num_mpt"
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * configuration variable.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_NUM_DMPT_SHIFT 0x16
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/*
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The following defines specify the default number of MPT entries to
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * configure. This value is controllable through the "hermon_log_num_mtt"
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * configuration variable. This default value expects an averages of 8
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * MTTs per MPT. We also define a log MTT size, since it's not likely
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * to change.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor#define HERMON_NUM_MTT_SHIFT 0x1d
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_MTT_SIZE_SHIFT 0x3
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/*
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * This define is the maximum size of a memory region or window (log 2), which
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * is used to initialize the "hermon_log_max_mrw_sz" configuration variable.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_MAX_MEM_MPT_SHIFT 0x24
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/*
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Defines used by hermon_mr_deregister() to specify how much/to what extent
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * a given memory regions resources should be freed up. HERMON_MR_DEREG_ALL
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * says what it means, free up all the resources associated with the region.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * HERMON_MR_DEREG_NO_HW2SW_MPT indicates that it is unnecessary to attempt
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the ownership transfer (from hardware to software) for the given MPT entry.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * And HERMON_MR_DEREG_NO_HW2SW_MPT_OR_UNBIND indicates that it is not only
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * unnecessary to attempt the ownership transfer for MPT, but it is also
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * unnecessary to attempt to unbind the memory.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * In general, these last two are specified when hermon_mr_deregister() is
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * called from hermon_mr_reregister(), where the MPT ownership transfer or
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * memory unbinding may have already been successfully performed.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_MR_DEREG_ALL 3
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_MR_DEREG_NO_HW2SW_MPT 2
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_MR_DEREG_NO_HW2SW_MPT_OR_UNBIND 1
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/*
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The following define is used by hermon_mr_rereg_xlat_helper() to determine
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * whether or not a given DMA handle can be reused. If the DMA handle was
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * previously initialized for IOMMU bypass mapping, then it can not be reused
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * to reregister a region for DDI_DMA_STREAMING access.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_MR_REUSE_DMAHDL(mr, flags) \
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (((mr)->mr_bindinfo.bi_bypass != HERMON_BINDMEM_BYPASS) || \
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor !((flags) & IBT_MR_NONCOHERENT))
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/*
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The hermon_sw_refcnt_t structure is used internally by the Hermon driver to
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * track all the information necessary to manage shared memory regions. Since
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * a shared memory region _will_ have its own distinct MPT entry, but will
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * _share_ its MTT entries with another region, it is necessary to track the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * number of times a given MTT structure is shared. This ensures that it will
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * not be prematurely freed up and that can be destroyed only when it is
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * appropriate to do so.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Each hermon_sw_refcnt_t structure contains a lock and a reference count
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * variable which are used to track the necessary information.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The following macros (below) are used to manipulate and query the MTT
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * reference count parameters. HERMON_MTT_REFCNT_INIT() is used to initialize
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * a newly allocated hermon_sw_refcnt_t struct (setting the "swrc_refcnt" to 1).
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * And the HERMON_MTT_IS_NOT_SHARED() and HERMON_MTT_IS_SHARED() macros are
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * used to query the current status of hermon_sw_refcnt_t struct to determine
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * if its "swrc_refcnt" is one or not.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylortypedef struct hermon_sw_refcnt_s {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor kmutex_t swrc_lock;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint_t swrc_refcnt;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor} hermon_sw_refcnt_t;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor_NOTE(DATA_READABLE_WITHOUT_LOCK(hermon_sw_refcnt_t::swrc_refcnt))
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor_NOTE(MUTEX_PROTECTS_DATA(hermon_sw_refcnt_t::swrc_lock,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_refcnt_t::swrc_refcnt))
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_MTT_REFCNT_INIT(swrc_tmp) ((swrc_tmp)->swrc_refcnt = 1)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_MTT_IS_NOT_SHARED(swrc_tmp) ((swrc_tmp)->swrc_refcnt == 1)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_MTT_IS_SHARED(swrc_tmp) ((swrc_tmp)->swrc_refcnt != 1)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/*
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The hermon_bind_info_t structure is used internally by the Hermon driver to
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * track all the information necessary to perform the DMA mappings necessary
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * for memory registration. It is specifically passed into both the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_mr_mem_bind() and hermon_mr_mtt_write() functions which perform most
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * of the necessary operations for Hermon memory registration.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * This structure is used to pass all the information necessary for a call
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * to either ddi_dma_addr_bind_handle() or ddi_dma_buf_bind_handle(). Note:
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the fields which need to be valid for each type of binding are slightly
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * different and that it indicated by the value in the "bi_type" field. The
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * "bi_type" field may be set to either of the following defined values:
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * HERMON_BINDHDL_VADDR (to indicate an "addr" bind) or HERMON_BINDHDL_BUF (to
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * indicate a "buf" bind).
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Upon return from hermon_mr_mem_bind(), the hermon_bind_info_t struct will
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * have its "bi_dmahdl", "bi_dmacookie", and "bi_cookiecnt" fields filled in.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * It is these values which are of particular interest to the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_mr_mtt_write() routine (they hold the PCI mapped addresses).
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Once initialized and used in this way, the hermon_bind_info_t will not to be
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * modified in anyway until it is subsequently passed to hermon_mr_mem_unbind()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * where the memory and resources will be unbound and reclaimed. Note: the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * "bi_free_dmahdl" flag indicated whether the ddi_dma_handle_t should be
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * freed as part of the hermon_mr_mem_unbind() operation or whether it will
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * be freed later elsewhere.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylortypedef struct hermon_bind_info_s {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint64_t bi_addr;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint64_t bi_len;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor struct as *bi_as;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor struct buf *bi_buf;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_dma_handle_t bi_dmahdl;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_dma_cookie_t bi_dmacookie;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint_t bi_cookiecnt;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint_t bi_type;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint_t bi_flags;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint_t bi_bypass;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint_t bi_free_dmahdl;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor} hermon_bind_info_t;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_BINDHDL_NONE 0
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_BINDHDL_VADDR 1
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_BINDHDL_BUF 2
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_BINDHDL_UBUF 3
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor#define HERMON_BINDHDL_LKEY 4
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/*
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The hermon_sw_mr_s structure is also referred to using the "hermon_mrhdl_t"
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * typedef (see hermon_typedef.h). It encodes all the information necessary
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * to track the various resources needed to register, reregister, deregister,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * and perform all the myriad other operations on both memory regions _and_
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * memory windows.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * A pointer to this structure is returned from many of the IBTF's CI verbs
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * interfaces for memory registration.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * It contains pointers to the various resources allocated for a memory
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * region, i.e. MPT resource, MTT resource, and MTT reference count resource.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * In addition it contains the hermon_bind_info_t struct used for the memory
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * bind operation on a given memory region.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * It also has a pointers to the associated PD handle, placeholders for access
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * flags, memory keys, and suggested page size for the region. It also has
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the necessary backpointer to the resource that corresponds to the structure
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * itself. And lastly, it contains a placeholder for a callback which should
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * be called on memory region unpinning.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstruct hermon_sw_mr_s {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor kmutex_t mr_lock;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_rsrc_t *mr_mptrsrcp;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_rsrc_t *mr_mttrsrcp;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_rsrc_t *mr_mttrefcntp;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pdhdl_t mr_pdhdl;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_bind_info_t mr_bindinfo;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ibt_mr_attr_flags_t mr_accflag;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint32_t mr_lkey;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint32_t mr_rkey;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint32_t mr_logmttpgsz;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_mpt_rsrc_type_t mr_mpt_type;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint64_t mr_mttaddr; /* for cMPTs */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint64_t mr_log2_pgsz;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* entity_size (in bytes), for cMPTS */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_rsrc_t *mr_rsrcp;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint_t mr_is_fmr;
c7facc54c4abed9e554ff80225311e6b7048d3c9Bill Taylor uint8_t mr_fmr_key; /* per FMR 8-bit key */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fmr_list_t *mr_fmr;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint_t mr_is_umem;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_umem_cookie_t mr_umemcookie;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor void (*mr_umem_cbfunc)(void *, void *);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor void *mr_umem_cbarg1;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor void *mr_umem_cbarg2;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor};
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor_NOTE(DATA_READABLE_WITHOUT_LOCK(hermon_sw_mr_s::mr_bindinfo
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_lkey
c7facc54c4abed9e554ff80225311e6b7048d3c9Bill Taylor hermon_sw_mr_s::mr_mttaddr
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_is_umem
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_is_fmr
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_fmr))
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor_NOTE(MUTEX_PROTECTS_DATA(hermon_sw_mr_s::mr_lock,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_mptrsrcp
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_mttrsrcp
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_mttrefcntp
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_bindinfo
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_lkey
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_rkey
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_logmttpgsz
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_rsrcp
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_is_umem
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_umemcookie
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_umem_cbfunc
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_umem_cbarg1
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_sw_mr_s::mr_umem_cbarg2))
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/*
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The hermon_mr_options_t structure is used in several of the Hermon memory
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * registration routines to provide additional option functionality. When
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * a NULL pointer is passed in place of a pointer to this struct, it is a
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * way of specifying the "default" behavior. Using this structure, however,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * is a way of controlling any extended behavior.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Currently, the only defined "extended" behaviors are for specifying whether
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * a given memory region should bypass the PCI IOMMU (HERMON_BINDMEM_BYPASS)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * or be mapped into the IOMMU (HERMON_BINDMEM_NORMAL), for specifying whether
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * a given ddi_dma_handle_t should be used in the bind operation, and for
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * specifying whether a memory registration should attempt to return an IB
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * vaddr which is "zero-based" (aids in alignment contraints for QPs).
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * This defaults today to always bypassing the IOMMU (can be changed by using
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the "hermon_iommu_bypass" configuration variable), to always allocating
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * a new dma handle, and to using the virtual address passed in (i.e. not
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * "zero-based").
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylortypedef struct hermon_mr_options_s {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_dma_handle_t mro_bind_dmahdl;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint_t mro_bind_type;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint_t mro_bind_override_addr;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor} hermon_mr_options_t;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_BINDMEM_NORMAL 1
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_BINDMEM_BYPASS 0
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_NO_MPT_OWNERSHIP 0 /* for cMPTs */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#define HERMON_PASS_MPT_OWNERSHIP 1
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/*
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Memory Allocation/Deallocation
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Although this is not strictly related to "memory regions", this is
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the most logical place to define the struct used for the memory
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * allocation/deallocation CI entry points.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * ibc_mem_alloc_s structure is used to store DMA handles for
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * for these allocations.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstruct ibc_mem_alloc_s {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_dma_handle_t ibc_dma_hdl;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_acc_handle_t ibc_acc_hdl;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor};
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor_NOTE(SCHEME_PROTECTS_DATA("safe sharing",
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ibc_mem_alloc_s::ibc_dma_hdl
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ibc_mem_alloc_s::ibc_acc_hdl))
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylorint hermon_dma_mr_register(hermon_state_t *state, hermon_pdhdl_t pdhdl,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor ibt_dmr_attr_t *attr_p, hermon_mrhdl_t *mrhdl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_mr_register(hermon_state_t *state, hermon_pdhdl_t pdhdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ibt_mr_attr_t *attr_p, hermon_mrhdl_t *mrhdl, hermon_mr_options_t *op,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_mpt_rsrc_type_t mpt_type);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_mr_register_buf(hermon_state_t *state, hermon_pdhdl_t pdhdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ibt_smr_attr_t *attrp, struct buf *buf, hermon_mrhdl_t *mrhdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_mr_options_t *op, hermon_mpt_rsrc_type_t mpt_type);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_mr_mtt_bind(hermon_state_t *state, hermon_bind_info_t *bind,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_dma_handle_t bind_dmahdl, hermon_rsrc_t **mtt, uint_t *mtt_pgsz_bits,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint_t is_buffer);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_mr_mtt_unbind(hermon_state_t *state, hermon_bind_info_t *bind,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_rsrc_t *mtt);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_mr_register_shared(hermon_state_t *state, hermon_mrhdl_t mrhdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pdhdl_t pdhdl, ibt_smr_attr_t *attr_p, hermon_mrhdl_t *mrhdl_new);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_mr_deregister(hermon_state_t *state, hermon_mrhdl_t *mrhdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor uint_t level, uint_t sleep);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_mr_query(hermon_state_t *state, hermon_mrhdl_t mrhdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ibt_mr_query_attr_t *attr);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_mr_reregister(hermon_state_t *state, hermon_mrhdl_t mrhdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pdhdl_t pdhdl, ibt_mr_attr_t *attr_p, hermon_mrhdl_t *mrhdl_new,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_mr_options_t *op);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_mr_reregister_buf(hermon_state_t *state, hermon_mrhdl_t mr,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pdhdl_t pd, ibt_smr_attr_t *mr_attr, struct buf *buf,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_mrhdl_t *mrhdl_new, hermon_mr_options_t *op);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_mr_sync(hermon_state_t *state, ibt_mr_sync_t *mr_segs,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor size_t num_segs);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_mw_alloc(hermon_state_t *state, hermon_pdhdl_t pdhdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ibt_mw_flags_t flags, hermon_mwhdl_t *mwhdl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_mw_free(hermon_state_t *state, hermon_mwhdl_t *mwhdl, uint_t sleep);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Tayloruint32_t hermon_mr_keycalc(uint32_t indx);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Tayloruint32_t hermon_mr_key_swap(uint32_t indx);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Tayloruint32_t hermon_index_to_mkey(uint32_t indx);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_mr_alloc_fmr(hermon_state_t *state, hermon_pdhdl_t pd,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fmrhdl_t fmr_pool, hermon_mrhdl_t *mrhdl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_mr_dealloc_fmr(hermon_state_t *state, hermon_mrhdl_t *mrhdl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_mr_register_physical_fmr(hermon_state_t *state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ibt_pmr_attr_t *mem_pattr_p, hermon_mrhdl_t mr, ibt_pmr_desc_t *mem_desc_p);
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylorint hermon_mr_alloc_lkey(hermon_state_t *state, hermon_pdhdl_t pd,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor ibt_lkey_flags_t flags, uint_t sz, hermon_mrhdl_t *mr);
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylorint hermon_mr_fexch_mpt_init(hermon_state_t *state, hermon_pdhdl_t pd,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor uint32_t mpt_indx, uint_t nummtt, uint64_t mtt_addr, uint_t sleep);
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylorint hermon_mr_fexch_mpt_fini(hermon_state_t *state, hermon_pdhdl_t pd,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor uint32_t mpt_indx, uint_t sleep);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#ifdef __cplusplus
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor}
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif /* _SYS_IB_ADAPTERS_HERMON_MR_H */