1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 /* 26 * Copyright (c) 2005 SilverStorm Technologies, Inc. All rights reserved. 27 * 28 * This software is available to you under a choice of one of two 29 * licenses. You may choose to be licensed under the terms of the GNU 30 * General Public License (GPL) Version 2, available from the file 31 * COPYING in the main directory of this source tree, or the 32 * OpenIB.org BSD license below: 33 * 34 * Redistribution and use in source and binary forms, with or 35 * without modification, are permitted provided that the following 36 * conditions are met: 37 * 38 * - Redistributions of source code must retain the above 39 * copyright notice, this list of conditions and the following 40 * disclaimer. 41 * 42 * - Redistributions in binary form must reproduce the above 43 * copyright notice, this list of conditions and the following 44 * disclaimer in the documentation and/or other materials 45 * provided with the distribution. 46 * 47 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 48 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 49 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 50 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 51 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 52 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 53 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 54 * SOFTWARE. 55 * 56 */ 57 /* 58 * Sun elects to include this software in Sun product 59 * under the OpenIB BSD license. 60 * 61 * 62 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 63 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 64 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 65 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 66 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 67 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 68 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 69 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 70 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 71 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 72 * POSSIBILITY OF SUCH DAMAGE. 73 */ 74 75 #ifndef _RDSIB_BUF_H 76 #define _RDSIB_BUF_H 77 78 #pragma ident "%Z%%M% %I% %E% SMI" 79 80 #ifdef __cplusplus 81 extern "C" { 82 #endif 83 84 typedef enum rds_sendbuf_state_s { 85 RDS_SNDBUF_FREE = 0, 86 RDS_SNDBUF_PENDING = 1, 87 RDS_SNDBUF_ERROR = 2 88 } rds_sendbuf_state_t; 89 90 /* Receive buffer states */ 91 typedef enum rds_recvbuf_state_s { 92 RDS_RCVBUF_FREE = 0, 93 RDS_RCVBUF_POSTED = 1, 94 RDS_RCVBUF_ONSOCKQ = 2 95 } rds_recvbuf_state_t; 96 97 /* 98 * RDS Buffer 99 * 100 * nextp - Ptr to the next buffer 101 * ep - Endpoint that is using this buffer 102 * ds - Data segment for SGL 103 * state - rds_sendbuf_state for send buffers and rds_recvbuf_state for 104 * receive buffers. 105 * frtn - Message freeing routine, for use by esballoc(9F), only used 106 * by receive buffers 107 */ 108 typedef struct rds_buf_s { 109 struct rds_buf_s *buf_nextp; 110 struct rds_ep_s *buf_ep; 111 ibt_wr_ds_t buf_ds; 112 uint8_t buf_state; 113 frtn_t buf_frtn; 114 } rds_buf_t; 115 116 /* 117 * RDS Buffer pool 118 * 119 * lock - Synchronize access 120 * nbuffers - SQ depth for send buffer pool and RQ depth for receive buffer 121 * pool 122 * nbusy - Number of buffers in the SQ or RQ 123 * nfree - Number of buffers in the pool(between headp and tailp). 124 * headp - First available buffer 125 * tailp - Last available buffer 126 * memp - pointer to the memory allocated for the buffer pool, 127 * valid only for send pools. 128 * memsize - size of the memory allocated (valid for send pools only). 129 * cv - condition variable to wait for buffers 130 * cv_count - Number of buffers that are being waited on. 131 * sqpoll_pending - Flag to indicate that sendCQ handler is running. 132 * 133 * cv, cv_count and sqpoll_pending are only used when 'rds_no_interrupts' 134 * is set. 135 */ 136 typedef struct rds_bufpool_s { 137 kmutex_t pool_lock; 138 uint32_t pool_nbuffers; 139 uint32_t pool_nbusy; 140 uint32_t pool_nfree; 141 rds_buf_t *pool_headp; 142 rds_buf_t *pool_tailp; 143 uint8_t *pool_memp; 144 uint_t pool_memsize; 145 rds_buf_t *pool_bufmemp; 146 kcondvar_t pool_cv; 147 uint_t pool_cv_count; 148 boolean_t pool_sqpoll_pending; 149 } rds_bufpool_t; 150 151 /* Global pools of buffers */ 152 rds_bufpool_t rds_dpool; /* data pool */ 153 rds_bufpool_t rds_cpool; /* ctrl pool */ 154 155 /* defined in rds_buf.c */ 156 int rds_init_recv_caches(rds_state_t *statep); 157 void rds_free_recv_caches(rds_state_t *statep); 158 int rds_init_send_pool(struct rds_ep_s *ep, ib_guid_t hca_guid); 159 int rds_reinit_send_pool(struct rds_ep_s *ep, ib_guid_t hca_guid); 160 void rds_free_send_pool(struct rds_ep_s *ep); 161 int rds_init_recv_pool(struct rds_ep_s *ep); 162 void rds_free_recv_pool(struct rds_ep_s *ep); 163 void rds_free_buf(rds_bufpool_t *pool, rds_buf_t *bp, uint_t nbuf); 164 rds_buf_t *rds_get_buf(rds_bufpool_t *pool, uint_t nbuf, uint_t *nret); 165 rds_buf_t *rds_get_send_buf(struct rds_ep_s *ep, uint_t nbufs); 166 void rds_free_send_buf(struct rds_ep_s *ep, rds_buf_t *headp, 167 rds_buf_t *tailp, uint_t nbuf, boolean_t lock); 168 void rds_free_recv_buf(rds_buf_t *bp, uint_t nbuf); 169 boolean_t rds_is_sendq_empty(struct rds_ep_s *ep, uint_t); 170 boolean_t rds_is_recvq_empty(struct rds_ep_s *ep, boolean_t); 171 172 #ifdef __cplusplus 173 } 174 #endif 175 176 #endif /* _RDSIB_BUF_H */ 177