16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * This file contains code imported from the OFED rds source file ib_rdma.c
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * Oracle elects to have and use the contents of ib_rdma.c under and governed
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * by the OpenIB.org BSD license (see below for full license text). However,
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * the following notice accompanied the original version of this file:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Copyright (c) 2006 Oracle. All rights reserved.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * This software is available to you under a choice of one of two
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * licenses. You may choose to be licensed under the terms of the GNU
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * General Public License (GPL) Version 2, available from the file
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * COPYING in the main directory of this source tree, or the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * OpenIB.org BSD license below:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Redistribution and use in source and binary forms, with or
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * without modification, are permitted provided that the following
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * conditions are met:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * - Redistributions of source code must retain the above
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * copyright notice, this list of conditions and the following
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * disclaimer.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * - Redistributions in binary form must reproduce the above
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * copyright notice, this list of conditions and the following
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * disclaimer in the documentation and/or other materials
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * provided with the distribution.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * SOFTWARE.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * This is stored as mr->r_trans_private.
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota list_node_t m_obj; /* list obj of rdsv3_fmr_pool list */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* DDI pinned memory */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* IBTF type definitions */
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota * delayed freed fmr's
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otastatic int rdsv3_ib_flush_mr_pool(struct rdsv3_ib_device *rds_ibdev,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otastatic void rdsv3_ib_teardown_mr(struct rdsv3_ib_mr *ibmr);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otastatic void rdsv3_ib_mr_pool_flush_worker(struct rdsv3_work_s *work);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otastatic struct rdsv3_ib_mr *rdsv3_ib_alloc_fmr(struct rdsv3_ib_device
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otastatic int rdsv3_ib_map_fmr(struct rdsv3_ib_device *rds_ibdev,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota struct rdsv3_ib_mr *ibmr, struct buf *bp, unsigned int nents);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otastatic struct rdsv3_ib_device *
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_get_device", "Enter: ipaddr: 0x%x", ipaddr);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_FOR_EACH_LIST_NODE(rds_ibdev, &rdsv3_ib_devices, list) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_FOR_EACH_LIST_NODE(i_ipaddr, &rds_ibdev->ipaddr_list,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_get_device", "Return: ipaddr: 0x%x", ipaddr);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_add_ipaddr(struct rdsv3_ib_device *rds_ibdev, uint32_be_t ipaddr)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_add_ipaddr", "rds_ibdev: %p ipaddr: %x",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota i_ipaddr = kmem_alloc(sizeof (*i_ipaddr), KM_NOSLEEP);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota list_insert_tail(&rds_ibdev->ipaddr_list, i_ipaddr);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_remove_ipaddr(struct rdsv3_ib_device *rds_ibdev, uint32_be_t ipaddr)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_remove_ipaddr", "rds_ibdev: %p, ipaddr: %x",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_FOR_EACH_LIST_NODE_SAFE(i_ipaddr, next, &rds_ibdev->ipaddr_list,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "Return: rds_ibdev: %p, ipaddr: %x", rds_ibdev, ipaddr);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_update_ipaddr(struct rdsv3_ib_device *rds_ibdev, uint32_be_t ipaddr)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_update_ipaddr", "rds_ibdev: %p, ipaddr: %x",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_add_conn(struct rdsv3_ib_device *rds_ibdev,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota struct rdsv3_ib_connection *ic = conn->c_transport_data;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_add_conn", "rds_ibdev: %p, conn: %p",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* conn was previously on the nodev_conns_list */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_remove_conn(struct rdsv3_ib_device *rds_ibdev,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota struct rdsv3_ib_connection *ic = conn->c_transport_data;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_remove_conn", "rds_ibdev: %p, conn: %p",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* place conn on nodev_conns_list */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "Return: rds_ibdev: %p, conn: %p", rds_ibdev, conn);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota__rdsv3_ib_destroy_conns(struct list *list, kmutex_t *list_lock)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("__rdsv3_ib_destroy_conns", "Enter: list: %p", list);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* avoid calling conn_destroy with irqs off */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_FOR_EACH_LIST_NODE_SAFE(ic, _ic, &tmp_list, ib_node) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("__rdsv3_ib_destroy_conns", "Return: list: %p", list);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_destroy_mr_pool(struct rdsv3_ib_device *rds_ibdev)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_destroy_mr_pool", "Enter: ibdev: %p",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (void) rdsv3_ib_flush_mr_pool(rds_ibdev, rds_ibdev->fmr_pool_hdl, 1);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (void) ibt_destroy_fmr_pool(ib_get_ibt_hca_hdl(rds_ibdev->dev),
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define IB_FMR_MAX_BUF_SIZE 0x1000000 /* 16MB max buf */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_create_mr_pool(struct rdsv3_ib_device *rds_ibdev)
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota pool = (struct rdsv3_fmr_pool *)kmem_zalloc(sizeof (*pool), KM_NOSLEEP);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* setup FMR pool attributes */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota h_page_sz = rds_ibdev->hca_attr.hca_page_sz * 1024;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota fmr_attr.fmr_max_pages_per_fmr = (IB_FMR_MAX_BUF_SIZE / h_page_sz) + 2;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota fmr_attr.fmr_flags = IBT_MR_NOSLEEP | IBT_MR_ENABLE_LOCAL_WRITE |
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota IBT_MR_ENABLE_REMOTE_WRITE | IBT_MR_ENABLE_REMOTE_READ;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* create the FMR pool */
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota ibt_status = ibt_create_fmr_pool(rds_ibdev->ibt_hca_hdl,
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota rds_ibdev->pd->ibt_pd, &fmr_attr, &rds_ibdev->fmr_pool_hdl);
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota list_create(&pool->f_list, sizeof (struct rdsv3_ib_mr),
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota mutex_init(&pool->f_lock, NULL, MUTEX_DRIVER, NULL);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rds_ibdev->fmr_message_size = fmr_attr.fmr_max_pages_per_fmr;
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_get_mr_info(struct rdsv3_ib_device *rds_ibdev,
fe817b6022080da0a98b5d2d8cd179f594d6ca5eEiji Otardsv3_ib_get_mr(struct rds_iovec *args, unsigned long nents,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_get_mr", "Enter: args.addr: %p", args->addr);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rds_ibdev = rdsv3_ib_get_device(rs->rs_bound_addr);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* pin user memory pages */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota umem_addr = (caddr_t)((uintptr_t)args->addr & ~PAGEOFFSET);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (ret != 0) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* transpose umem_cookie to buf structure for rdsv3_ib_map_fmr() */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota ret = rdsv3_ib_map_fmr(rds_ibdev, ibmr, bp, nents);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota if (ret == 0) {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota "Return: ibmr: %p umem_cookie %p", ibmr, ibmr->umem_cookie);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota } else { /* error return */
6e18d381c642549b8bb1774a803d3510aec6baafagiri RDSV3_DPRINTF2("rdsv3_ib_get_mr", "map_fmr failed (errno=%d)\n",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otastatic struct rdsv3_ib_mr *
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_alloc_fmr(struct rdsv3_ib_device *rds_ibdev)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_alloc_fmr", "Enter: ibdev: %p", rds_ibdev);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota ibmr = (struct rdsv3_ib_mr *)kmem_zalloc(sizeof (*ibmr),
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota ibmr->rc_hca_hdl = ib_get_ibt_hca_hdl(rds_ibdev->dev);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_map_fmr(struct rdsv3_ib_device *rds_ibdev, struct rdsv3_ib_mr *ibmr,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* LINTED E_FUNC_SET_NOT_USED */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_map_fmr", "Enter: ibmr: %p", ibmr);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_map_fmr", "buf addr: %p", bp->b_un.b_addr);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* setup ibt_map_mem_area attributes */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota page_sz = rds_ibdev->hca_attr.hca_page_sz * 1024; /* in kbytes */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota paddr_list_len = (bp->b_bcount / page_sz) + 2; /* start + end pg */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* map user buffer to HCA address */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota &va_attr, paddr_list_len, ®_req, &ibmr->rc_ma_hdl);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* use a free entry from FMR pool to register the specified memory */
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota ibt_status = ibt_register_physical_fmr(ibmr->rc_hca_hdl,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota ®_req.fn_arg, &ibmr->rc_fmr_hdl, &ibmr->rc_mem_desc);
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota RDSV3_DPRINTF2("rdsv3_ib_map_fmr", "reg_phy_fmr failed %d",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_map_fmr", "Return: ibmr: %p rkey: 0x%x",
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_sync_mr(void *trans_private, int direction)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* LINTED E_FUNC_SET_NOT_USED */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* LINTED E_FUNC_SET_NOT_USED */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* FMR Sync not needed in Solaris on PCI-ex systems */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_FOR_EACH_LIST_NODE(rds_ibdev, &rdsv3_ib_devices, list) {
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota /* return the fmr to the IBTF pool */
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota (void) ibt_deregister_fmr(ibmr->rc_hca_hdl, ibmr->rc_fmr_hdl);
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota (void) ibt_unmap_mem_area(ibmr->rc_hca_hdl, ibmr->rc_ma_hdl);
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota struct rdsv3_fmr_pool *pool = (struct rdsv3_fmr_pool *)data;
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota ibmr = (struct rdsv3_ib_mr *)list_remove_head(listp);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_free_mr(void *trans_private, int invalidate)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_free_mr", "Enter: ibmr: %p inv: %d",
5d5562f583b2b6affe19bdce0b3c8b1840d667a4Eiji Ota /* save af_thr at local as ibmr might be freed at mutex_exit */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_ib_flush_mr_pool(struct rdsv3_ib_device *rds_ibdev,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* LINTED E_FUNC_SET_NOT_USED */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota RDSV3_DPRINTF4("rdsv3_ib_flush_mr_pool", "Enter: pool: %p", pool_hdl);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota (void) ibt_flush_fmr_pool(ib_get_ibt_hca_hdl(rds_ibdev->dev),
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);