xref: /onnv-gate/usr/src/uts/common/sys/ib/clients/rds/rdsib_buf.h (revision 4467:e004b2587f27)
13302Sagiri /*
23302Sagiri  * CDDL HEADER START
33302Sagiri  *
43302Sagiri  * The contents of this file are subject to the terms of the
53302Sagiri  * Common Development and Distribution License (the "License").
63302Sagiri  * You may not use this file except in compliance with the License.
73302Sagiri  *
83302Sagiri  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93302Sagiri  * or http://www.opensolaris.org/os/licensing.
103302Sagiri  * See the License for the specific language governing permissions
113302Sagiri  * and limitations under the License.
123302Sagiri  *
133302Sagiri  * When distributing Covered Code, include this CDDL HEADER in each
143302Sagiri  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153302Sagiri  * If applicable, add the following below this CDDL HEADER, with the
163302Sagiri  * fields enclosed by brackets "[]" replaced with your own identifying
173302Sagiri  * information: Portions Copyright [yyyy] [name of copyright owner]
183302Sagiri  *
193302Sagiri  * CDDL HEADER END
203302Sagiri  */
213302Sagiri /*
224154Sagiri  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
233302Sagiri  * Use is subject to license terms.
243302Sagiri  */
253302Sagiri /*
263302Sagiri  * Copyright (c) 2005 SilverStorm Technologies, Inc. All rights reserved.
273302Sagiri  *
283302Sagiri  * This software is available to you under a choice of one of two
293302Sagiri  * licenses.  You may choose to be licensed under the terms of the GNU
303302Sagiri  * General Public License (GPL) Version 2, available from the file
313302Sagiri  * COPYING in the main directory of this source tree, or the
323302Sagiri  * OpenIB.org BSD license below:
333302Sagiri  *
343302Sagiri  *     Redistribution and use in source and binary forms, with or
353302Sagiri  *     without modification, are permitted provided that the following
363302Sagiri  *     conditions are met:
373302Sagiri  *
383302Sagiri  *	- Redistributions of source code must retain the above
393302Sagiri  *	  copyright notice, this list of conditions and the following
403302Sagiri  *	  disclaimer.
413302Sagiri  *
423302Sagiri  *	- Redistributions in binary form must reproduce the above
433302Sagiri  *	  copyright notice, this list of conditions and the following
443302Sagiri  *	  disclaimer in the documentation and/or other materials
453302Sagiri  *	  provided with the distribution.
463302Sagiri  *
473302Sagiri  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
483302Sagiri  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
493302Sagiri  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
503302Sagiri  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
513302Sagiri  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
523302Sagiri  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
533302Sagiri  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
543302Sagiri  * SOFTWARE.
553302Sagiri  *
563302Sagiri  */
573302Sagiri /*
583302Sagiri  * Sun elects to include this software in Sun product
593302Sagiri  * under the OpenIB BSD license.
603302Sagiri  *
613302Sagiri  *
623302Sagiri  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
633302Sagiri  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
643302Sagiri  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
653302Sagiri  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
663302Sagiri  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
673302Sagiri  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
683302Sagiri  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
693302Sagiri  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
703302Sagiri  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
713302Sagiri  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
723302Sagiri  * POSSIBILITY OF SUCH DAMAGE.
733302Sagiri  */
743302Sagiri 
753302Sagiri #ifndef _RDSIB_BUF_H
763302Sagiri #define	_RDSIB_BUF_H
773302Sagiri 
783302Sagiri #pragma ident	"%Z%%M%	%I%	%E% SMI"
793302Sagiri 
803302Sagiri #ifdef __cplusplus
813302Sagiri extern "C" {
823302Sagiri #endif
833302Sagiri 
843302Sagiri typedef enum rds_sendbuf_state_s {
853302Sagiri 	RDS_SNDBUF_FREE			= 0,
863302Sagiri 	RDS_SNDBUF_PENDING		= 1,
873302Sagiri 	RDS_SNDBUF_ERROR		= 2
883302Sagiri } rds_sendbuf_state_t;
893302Sagiri 
903302Sagiri /* Receive buffer states */
913302Sagiri typedef enum rds_recvbuf_state_s {
923302Sagiri 	RDS_RCVBUF_FREE		= 0,
933302Sagiri 	RDS_RCVBUF_POSTED	= 1,
943302Sagiri 	RDS_RCVBUF_ONSOCKQ	= 2
953302Sagiri } rds_recvbuf_state_t;
963302Sagiri 
973302Sagiri /*
983302Sagiri  * RDS Buffer
993302Sagiri  *
1003302Sagiri  * nextp - Ptr to the next buffer
1013302Sagiri  * ep - Endpoint that is using this buffer
1023302Sagiri  * ds - Data segment for SGL
1033302Sagiri  * state - rds_sendbuf_state for send buffers and rds_recvbuf_state for
1043302Sagiri  *         receive buffers.
1053302Sagiri  * frtn - Message freeing routine, for use by esballoc(9F), only used
1063302Sagiri  *        by receive buffers
1073302Sagiri  */
1083302Sagiri typedef struct rds_buf_s {
1093302Sagiri 	struct rds_buf_s	*buf_nextp;
1103302Sagiri 	struct rds_ep_s		*buf_ep;
1113302Sagiri 	ibt_wr_ds_t		buf_ds;
1123302Sagiri 	uint8_t			buf_state;
1133302Sagiri 	frtn_t			buf_frtn;
1143302Sagiri } rds_buf_t;
1153302Sagiri 
1163302Sagiri /*
1173302Sagiri  * RDS Buffer pool
1183302Sagiri  *
1193302Sagiri  * lock - Synchronize access
1203302Sagiri  * nbuffers - SQ depth for send buffer pool and RQ depth for receive buffer
1213302Sagiri  *	pool
1223302Sagiri  * nbusy - Number of buffers in the SQ or RQ
1233302Sagiri  * nfree - Number of buffers in the pool(between headp and tailp).
1243302Sagiri  * headp - First available buffer
1253302Sagiri  * tailp - Last available buffer
1263302Sagiri  * memp - pointer to the memory allocated for the buffer pool,
1273302Sagiri  *        valid only for send pools.
1283302Sagiri  * memsize - size of the memory allocated (valid for send pools only).
1293302Sagiri  * cv - condition variable to wait for buffers
1303302Sagiri  * cv_count - Number of buffers that are being waited on.
1313302Sagiri  * sqpoll_pending - Flag to indicate that sendCQ handler is running.
1323302Sagiri  *
1333302Sagiri  * cv, cv_count and sqpoll_pending are only used when 'rds_no_interrupts'
1343302Sagiri  * is set.
1353302Sagiri  */
1363302Sagiri typedef struct rds_bufpool_s {
1373302Sagiri 	kmutex_t		pool_lock;
1383302Sagiri 	uint32_t		pool_nbuffers;
1393302Sagiri 	uint32_t		pool_nbusy;
1403302Sagiri 	uint32_t		pool_nfree;
1413302Sagiri 	rds_buf_t		*pool_headp;
1423302Sagiri 	rds_buf_t		*pool_tailp;
1433302Sagiri 	uint8_t			*pool_memp;
1443302Sagiri 	uint_t			pool_memsize;
1453302Sagiri 	rds_buf_t		*pool_bufmemp;
1463302Sagiri 	kcondvar_t		pool_cv;
1473302Sagiri 	uint_t			pool_cv_count;
1483302Sagiri 	boolean_t		pool_sqpoll_pending;
1493302Sagiri } rds_bufpool_t;
1503302Sagiri 
1513302Sagiri /* Global pools of buffers */
1523302Sagiri rds_bufpool_t		rds_dpool; /* data pool */
1533302Sagiri rds_bufpool_t		rds_cpool; /* ctrl pool */
1543302Sagiri 
1553302Sagiri /* defined in rds_buf.c */
1563302Sagiri int rds_init_recv_caches(rds_state_t *statep);
1573302Sagiri void rds_free_recv_caches(rds_state_t *statep);
158*4467Sagiri int rds_init_send_pool(struct rds_ep_s *ep, ib_guid_t hca_guid);
1594154Sagiri int rds_reinit_send_pool(struct rds_ep_s *ep, ib_guid_t hca_guid);
1603302Sagiri void rds_free_send_pool(struct rds_ep_s *ep);
1613302Sagiri int rds_init_recv_pool(struct rds_ep_s *ep);
1623302Sagiri void rds_free_recv_pool(struct rds_ep_s *ep);
1633302Sagiri void rds_free_buf(rds_bufpool_t *pool, rds_buf_t *bp, uint_t nbuf);
1643302Sagiri rds_buf_t *rds_get_buf(rds_bufpool_t *pool, uint_t nbuf, uint_t *nret);
1653302Sagiri rds_buf_t *rds_get_send_buf(struct rds_ep_s *ep, uint_t nbufs);
1663302Sagiri void rds_free_send_buf(struct rds_ep_s *ep, rds_buf_t *headp,
1673302Sagiri     rds_buf_t *tailp, uint_t nbuf, boolean_t lock);
1683302Sagiri void rds_free_recv_buf(rds_buf_t *bp, uint_t nbuf);
1693302Sagiri boolean_t rds_is_sendq_empty(struct rds_ep_s *ep, uint_t);
1703302Sagiri boolean_t rds_is_recvq_empty(struct rds_ep_s *ep, boolean_t);
1713302Sagiri 
1723302Sagiri #ifdef __cplusplus
1733302Sagiri }
1743302Sagiri #endif
1753302Sagiri 
1763302Sagiri #endif	/* _RDSIB_BUF_H */
177