1*9162SPeter.Dunlap@Sun.COM /* 2*9162SPeter.Dunlap@Sun.COM * CDDL HEADER START 3*9162SPeter.Dunlap@Sun.COM * 4*9162SPeter.Dunlap@Sun.COM * The contents of this file are subject to the terms of the 5*9162SPeter.Dunlap@Sun.COM * Common Development and Distribution License (the "License"). 6*9162SPeter.Dunlap@Sun.COM * You may not use this file except in compliance with the License. 7*9162SPeter.Dunlap@Sun.COM * 8*9162SPeter.Dunlap@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*9162SPeter.Dunlap@Sun.COM * or http://www.opensolaris.org/os/licensing. 10*9162SPeter.Dunlap@Sun.COM * See the License for the specific language governing permissions 11*9162SPeter.Dunlap@Sun.COM * and limitations under the License. 12*9162SPeter.Dunlap@Sun.COM * 13*9162SPeter.Dunlap@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 14*9162SPeter.Dunlap@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*9162SPeter.Dunlap@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 16*9162SPeter.Dunlap@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 17*9162SPeter.Dunlap@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 18*9162SPeter.Dunlap@Sun.COM * 19*9162SPeter.Dunlap@Sun.COM * CDDL HEADER END 20*9162SPeter.Dunlap@Sun.COM */ 21*9162SPeter.Dunlap@Sun.COM /* 22*9162SPeter.Dunlap@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23*9162SPeter.Dunlap@Sun.COM * Use is subject to license terms. 24*9162SPeter.Dunlap@Sun.COM */ 25*9162SPeter.Dunlap@Sun.COM 26*9162SPeter.Dunlap@Sun.COM #ifndef _ISER_RESOURCE_H 27*9162SPeter.Dunlap@Sun.COM #define _ISER_RESOURCE_H 28*9162SPeter.Dunlap@Sun.COM 29*9162SPeter.Dunlap@Sun.COM #ifdef __cplusplus 30*9162SPeter.Dunlap@Sun.COM extern "C" { 31*9162SPeter.Dunlap@Sun.COM #endif 32*9162SPeter.Dunlap@Sun.COM 33*9162SPeter.Dunlap@Sun.COM #include <sys/types.h> 34*9162SPeter.Dunlap@Sun.COM #include <sys/ib/ibtl/ibti.h> 35*9162SPeter.Dunlap@Sun.COM #include <sys/ib/ibtl/ibtl_types.h> 36*9162SPeter.Dunlap@Sun.COM #include <sys/iscsi_protocol.h> 37*9162SPeter.Dunlap@Sun.COM 38*9162SPeter.Dunlap@Sun.COM #define ISER_CACHE_NAMELEN 31 /* KMEM_CACHE_NAMELEN */ 39*9162SPeter.Dunlap@Sun.COM 40*9162SPeter.Dunlap@Sun.COM /* Default message lengths */ 41*9162SPeter.Dunlap@Sun.COM #define ISER_MAX_CTRLPDU_LEN 0x4000 42*9162SPeter.Dunlap@Sun.COM #define ISER_MAX_TEXTPDU_LEN 0x4000 43*9162SPeter.Dunlap@Sun.COM 44*9162SPeter.Dunlap@Sun.COM /* Default data buffer length */ 45*9162SPeter.Dunlap@Sun.COM #define ISER_DEFAULT_BUFLEN 0x20000 46*9162SPeter.Dunlap@Sun.COM 47*9162SPeter.Dunlap@Sun.COM /* 48*9162SPeter.Dunlap@Sun.COM * iser_resource.h 49*9162SPeter.Dunlap@Sun.COM * Definitions and functions related to set up buffer allocation from 50*9162SPeter.Dunlap@Sun.COM * IBT memory regions and managment of work requessts. 51*9162SPeter.Dunlap@Sun.COM */ 52*9162SPeter.Dunlap@Sun.COM 53*9162SPeter.Dunlap@Sun.COM struct iser_hca_s; 54*9162SPeter.Dunlap@Sun.COM 55*9162SPeter.Dunlap@Sun.COM /* 56*9162SPeter.Dunlap@Sun.COM * Memory regions 57*9162SPeter.Dunlap@Sun.COM */ 58*9162SPeter.Dunlap@Sun.COM typedef struct iser_mr_s { 59*9162SPeter.Dunlap@Sun.COM ibt_mr_hdl_t is_mrhdl; 60*9162SPeter.Dunlap@Sun.COM ib_vaddr_t is_mrva; 61*9162SPeter.Dunlap@Sun.COM ib_memlen_t is_mrlen; 62*9162SPeter.Dunlap@Sun.COM ibt_lkey_t is_mrlkey; 63*9162SPeter.Dunlap@Sun.COM ibt_rkey_t is_mrrkey; 64*9162SPeter.Dunlap@Sun.COM avl_node_t is_avl_ln; 65*9162SPeter.Dunlap@Sun.COM } iser_mr_t; 66*9162SPeter.Dunlap@Sun.COM 67*9162SPeter.Dunlap@Sun.COM typedef struct iser_vmem_mr_pool_s { 68*9162SPeter.Dunlap@Sun.COM iser_hca_t *ivmp_hca; 69*9162SPeter.Dunlap@Sun.COM ibt_mr_flags_t ivmp_mr_flags; 70*9162SPeter.Dunlap@Sun.COM ib_memlen_t ivmp_chunksize; 71*9162SPeter.Dunlap@Sun.COM vmem_t *ivmp_vmem; 72*9162SPeter.Dunlap@Sun.COM uint64_t ivmp_total_size; 73*9162SPeter.Dunlap@Sun.COM uint64_t ivmp_max_total_size; 74*9162SPeter.Dunlap@Sun.COM avl_tree_t ivmp_mr_list; 75*9162SPeter.Dunlap@Sun.COM kmutex_t ivmp_mutex; 76*9162SPeter.Dunlap@Sun.COM } iser_vmem_mr_pool_t; 77*9162SPeter.Dunlap@Sun.COM 78*9162SPeter.Dunlap@Sun.COM #define ISER_MR_QUANTSIZE 0x400 79*9162SPeter.Dunlap@Sun.COM #define ISER_MIN_CHUNKSIZE 0x100000 /* 1MB */ 80*9162SPeter.Dunlap@Sun.COM 81*9162SPeter.Dunlap@Sun.COM #ifdef _LP64 82*9162SPeter.Dunlap@Sun.COM #define ISER_BUF_MR_CHUNKSIZE 0x8000000 /* 128MB */ 83*9162SPeter.Dunlap@Sun.COM #define ISER_BUF_POOL_MAX 0x40000000 /* 1GB */ 84*9162SPeter.Dunlap@Sun.COM #else 85*9162SPeter.Dunlap@Sun.COM /* Memory is very limited on 32-bit kernels */ 86*9162SPeter.Dunlap@Sun.COM #define ISER_BUF_MR_CHUNKSIZE 0x400000 /* 4MB */ 87*9162SPeter.Dunlap@Sun.COM #define ISER_BUF_POOL_MAX 0x4000000 /* 64MB */ 88*9162SPeter.Dunlap@Sun.COM #endif 89*9162SPeter.Dunlap@Sun.COM #define ISER_BUF_MR_FLAGS IBT_MR_ENABLE_LOCAL_WRITE | \ 90*9162SPeter.Dunlap@Sun.COM IBT_MR_ENABLE_REMOTE_READ | IBT_MR_ENABLE_REMOTE_WRITE 91*9162SPeter.Dunlap@Sun.COM #ifdef _LP64 92*9162SPeter.Dunlap@Sun.COM #define ISER_MSG_MR_CHUNKSIZE 0x2000000 /* 32MB */ 93*9162SPeter.Dunlap@Sun.COM #define ISER_MSG_POOL_MAX 0x10000000 /* 256MB */ 94*9162SPeter.Dunlap@Sun.COM #else 95*9162SPeter.Dunlap@Sun.COM #define ISER_MSG_MR_CHUNKSIZE 0x100000 /* 1MB */ 96*9162SPeter.Dunlap@Sun.COM #define ISER_MSG_POOL_MAX 0x2000000 /* 32MB */ 97*9162SPeter.Dunlap@Sun.COM #endif 98*9162SPeter.Dunlap@Sun.COM #define ISER_MSG_MR_FLAGS IBT_MR_ENABLE_LOCAL_WRITE 99*9162SPeter.Dunlap@Sun.COM 100*9162SPeter.Dunlap@Sun.COM iser_vmem_mr_pool_t *iser_vmem_create(const char *name, iser_hca_t *hca, 101*9162SPeter.Dunlap@Sun.COM ib_memlen_t chunksize, uint64_t max_total_size, 102*9162SPeter.Dunlap@Sun.COM ibt_mr_flags_t arena_mr_flags); 103*9162SPeter.Dunlap@Sun.COM void iser_vmem_destroy(iser_vmem_mr_pool_t *vmr_pool); 104*9162SPeter.Dunlap@Sun.COM void *iser_vmem_alloc(iser_vmem_mr_pool_t *vmr_pool, size_t size); 105*9162SPeter.Dunlap@Sun.COM void iser_vmem_free(iser_vmem_mr_pool_t *vmr_pool, void *vaddr, size_t size); 106*9162SPeter.Dunlap@Sun.COM idm_status_t iser_vmem_mr(iser_vmem_mr_pool_t *vmr_pool, 107*9162SPeter.Dunlap@Sun.COM void *vaddr, size_t size, iser_mr_t *mr); 108*9162SPeter.Dunlap@Sun.COM 109*9162SPeter.Dunlap@Sun.COM /* 110*9162SPeter.Dunlap@Sun.COM * iSER work request structure encodes an iSER Send Queue work request 111*9162SPeter.Dunlap@Sun.COM * context, with pointers to relevant resources related to the work request. 112*9162SPeter.Dunlap@Sun.COM * We hold a pointer to either an IDM PDU handle, an iSER message handle 113*9162SPeter.Dunlap@Sun.COM * or an IDM buffer handle. These are allocated from a kmem_cache when 114*9162SPeter.Dunlap@Sun.COM * we post send WR's, and freed back when the completion is polled. 115*9162SPeter.Dunlap@Sun.COM */ 116*9162SPeter.Dunlap@Sun.COM typedef enum { 117*9162SPeter.Dunlap@Sun.COM ISER_WR_SEND, 118*9162SPeter.Dunlap@Sun.COM ISER_WR_RDMAW, 119*9162SPeter.Dunlap@Sun.COM ISER_WR_RDMAR, 120*9162SPeter.Dunlap@Sun.COM ISER_WR_UNDEFINED 121*9162SPeter.Dunlap@Sun.COM } iser_wr_type_t; 122*9162SPeter.Dunlap@Sun.COM 123*9162SPeter.Dunlap@Sun.COM typedef struct iser_wr_s { 124*9162SPeter.Dunlap@Sun.COM iser_wr_type_t iw_type; 125*9162SPeter.Dunlap@Sun.COM struct iser_msg_s *iw_msg; 126*9162SPeter.Dunlap@Sun.COM struct idm_buf_s *iw_buf; 127*9162SPeter.Dunlap@Sun.COM struct idm_pdu_s *iw_pdu; 128*9162SPeter.Dunlap@Sun.COM } iser_wr_t; 129*9162SPeter.Dunlap@Sun.COM 130*9162SPeter.Dunlap@Sun.COM int iser_wr_cache_constructor(void *mr, void *arg, int flags); 131*9162SPeter.Dunlap@Sun.COM void iser_wr_cache_destructor(void *mr, void *arg); 132*9162SPeter.Dunlap@Sun.COM iser_wr_t *iser_wr_get(); 133*9162SPeter.Dunlap@Sun.COM void iser_wr_free(iser_wr_t *iser_wr); 134*9162SPeter.Dunlap@Sun.COM 135*9162SPeter.Dunlap@Sun.COM /* 136*9162SPeter.Dunlap@Sun.COM * iSER message structure for iSCSI Control PDUs, constructor and 137*9162SPeter.Dunlap@Sun.COM * destructor routines, and utility routines for allocating and 138*9162SPeter.Dunlap@Sun.COM * freeing message handles. 139*9162SPeter.Dunlap@Sun.COM */ 140*9162SPeter.Dunlap@Sun.COM typedef struct iser_msg_s { 141*9162SPeter.Dunlap@Sun.COM struct iser_msg_s *nextp; /* for building lists */ 142*9162SPeter.Dunlap@Sun.COM kmem_cache_t *cache; /* back pointer for cleanup */ 143*9162SPeter.Dunlap@Sun.COM ibt_wr_ds_t msg_ds; /* SGEs for hdr and text */ 144*9162SPeter.Dunlap@Sun.COM ibt_mr_hdl_t mrhdl[2]; /* MR handles for each SGE */ 145*9162SPeter.Dunlap@Sun.COM } iser_msg_t; 146*9162SPeter.Dunlap@Sun.COM 147*9162SPeter.Dunlap@Sun.COM int iser_msg_cache_constructor(void *mr, void *arg, int flags); 148*9162SPeter.Dunlap@Sun.COM void iser_msg_cache_destructor(void *mr, void *arg); 149*9162SPeter.Dunlap@Sun.COM iser_msg_t *iser_msg_get(iser_hca_t *hca, int num, int *ret); 150*9162SPeter.Dunlap@Sun.COM void iser_msg_free(iser_msg_t *msg); 151*9162SPeter.Dunlap@Sun.COM 152*9162SPeter.Dunlap@Sun.COM /* 153*9162SPeter.Dunlap@Sun.COM * iSER data buffer structure for iSER RDMA operations, constructor and 154*9162SPeter.Dunlap@Sun.COM * destructor routines, and utility routines for allocating and freeing 155*9162SPeter.Dunlap@Sun.COM * buffer handles. 156*9162SPeter.Dunlap@Sun.COM */ 157*9162SPeter.Dunlap@Sun.COM typedef struct iser_buf_s { 158*9162SPeter.Dunlap@Sun.COM kmem_cache_t *cache; /* back pointer for cleanup */ 159*9162SPeter.Dunlap@Sun.COM void *buf; /* buffer */ 160*9162SPeter.Dunlap@Sun.COM uint64_t buflen; 161*9162SPeter.Dunlap@Sun.COM iser_mr_t *iser_mr; /* MR handle for this buffer */ 162*9162SPeter.Dunlap@Sun.COM ibt_wr_ds_t buf_ds; /* SGE for this buffer */ 163*9162SPeter.Dunlap@Sun.COM ibt_send_wr_t buf_wr; /* DEBUG, copy of wr from request */ 164*9162SPeter.Dunlap@Sun.COM ibt_wc_t buf_wc; /* DEBUG, copy of wc from completion */ 165*9162SPeter.Dunlap@Sun.COM timespec_t buf_constructed; 166*9162SPeter.Dunlap@Sun.COM timespec_t buf_destructed; 167*9162SPeter.Dunlap@Sun.COM } iser_buf_t; 168*9162SPeter.Dunlap@Sun.COM 169*9162SPeter.Dunlap@Sun.COM int iser_buf_cache_constructor(void *mr, void *arg, int flags); 170*9162SPeter.Dunlap@Sun.COM void iser_buf_cache_destructor(void *mr, void *arg); 171*9162SPeter.Dunlap@Sun.COM 172*9162SPeter.Dunlap@Sun.COM void iser_init_hca_caches(struct iser_hca_s *hca); 173*9162SPeter.Dunlap@Sun.COM void iser_fini_hca_caches(struct iser_hca_s *hca); 174*9162SPeter.Dunlap@Sun.COM 175*9162SPeter.Dunlap@Sun.COM /* Routines to register in-place memory passed on an existing idb */ 176*9162SPeter.Dunlap@Sun.COM int iser_reg_rdma_mem(struct iser_hca_s *hca, idm_buf_t *idb); 177*9162SPeter.Dunlap@Sun.COM void iser_dereg_rdma_mem(struct iser_hca_s *hca, idm_buf_t *idb); 178*9162SPeter.Dunlap@Sun.COM 179*9162SPeter.Dunlap@Sun.COM #ifdef __cplusplus 180*9162SPeter.Dunlap@Sun.COM } 181*9162SPeter.Dunlap@Sun.COM #endif 182*9162SPeter.Dunlap@Sun.COM 183*9162SPeter.Dunlap@Sun.COM #endif /* _ISER_RESOURCE_H */ 184