xref: /titanic_51/usr/src/uts/common/sys/multidata_impl.h (revision ff550d0e264b51131fb34e9e83163b348d916640)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*ff550d0eSmasputra  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _SYS_MULTIDATA_IMPL_H
287c478bd9Sstevel@tonic-gate #define	_SYS_MULTIDATA_IMPL_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * Multidata: implementation-private data structure and declarations.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * Structure used for insque/remque circular list operations.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate typedef struct ql_s {
447c478bd9Sstevel@tonic-gate 	struct ql_s *ql_next;	/* pointer to next list element */
457c478bd9Sstevel@tonic-gate 	struct ql_s *ql_prev;	/* pointer to previous list element */
467c478bd9Sstevel@tonic-gate } ql_t;
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #define	QL_INIT(q) {				\
497c478bd9Sstevel@tonic-gate 	((ql_t *)(q))->ql_next = (ql_t *)(q);	\
507c478bd9Sstevel@tonic-gate 	((ql_t *)(q))->ql_prev = (ql_t *)(q);	\
517c478bd9Sstevel@tonic-gate }
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate typedef struct pdesc_slab_s pdesc_slab_t;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * Attribute hash bucket structure.
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate typedef struct patbkt_s {
597c478bd9Sstevel@tonic-gate 	kmutex_t pbkt_lock;	/* per-bucket lock */
607c478bd9Sstevel@tonic-gate 	ql_t	pbkt_pattr_q;	/* list of attributes */
617c478bd9Sstevel@tonic-gate 	uint_t	pbkt_tbl_sz;	/* table size (if this is first bucket) */
627c478bd9Sstevel@tonic-gate } patbkt_t;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * Attribute structure.
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate #define	PATTR_MAGIC	0x50615472	/* "PaTr" */
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate struct pattr_s {
707c478bd9Sstevel@tonic-gate 	pattr_t *pat_next;	/* pointer to next attribute in bucket */
717c478bd9Sstevel@tonic-gate 	pattr_t *pat_prev;	/* pointer to previous attribute in bucket */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	uint_t pat_magic;	/* set to PATTR_MAGIC */
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate 	kmutex_t *pat_lock;	/* pointer to per-bucket lock */
767c478bd9Sstevel@tonic-gate 	multidata_t *pat_mmd;	/* back pointer to Multidata */
777c478bd9Sstevel@tonic-gate 	uint_t	pat_buflen;	/* length of this structure + attribute */
787c478bd9Sstevel@tonic-gate 	uint_t	pat_type;	/* type of encapsulated attribute */
797c478bd9Sstevel@tonic-gate 	uint_t	pat_flags;	/* misc. flags */
807c478bd9Sstevel@tonic-gate };
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /*
837c478bd9Sstevel@tonic-gate  * Values for pat_flags.
847c478bd9Sstevel@tonic-gate  */
857c478bd9Sstevel@tonic-gate #define	PATTR_REM_DEFER	0x1	/* entry is marked unusable but still exists */
867c478bd9Sstevel@tonic-gate #define	PATTR_PERSIST	0x2	/* entry can't be removed */
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #define	Q2PATTR(p)	\
897c478bd9Sstevel@tonic-gate 	((pattr_t *)((caddr_t)(p) - offsetof(pattr_t, pat_next)))
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * Packet descriptor structure.
937c478bd9Sstevel@tonic-gate  */
947c478bd9Sstevel@tonic-gate #define	PDESC_MAGIC	0x506b5464	/* "PkTd" */
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate struct pdesc_s {
977c478bd9Sstevel@tonic-gate 	pdesc_t	*pd_next;	/* pointer to next descriptor */
987c478bd9Sstevel@tonic-gate 	pdesc_t	*pd_prev;	/* pointer to previous descriptor */
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	uint_t pd_magic;	/* set to PDESC_MAGIC */
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	pdesc_slab_t *pd_slab;	/* back pointer to descriptor slab */
1037c478bd9Sstevel@tonic-gate 	patbkt_t *pd_pattbl;	/* hash table of local attributes */
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 	pdescinfo_t pd_pdi;	/* embedded descriptor info structure */
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #define	pd_flags	pd_pdi.flags
1087c478bd9Sstevel@tonic-gate };
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate  * Additional internal flags for pd_flags (see multidata.h for the rest).
1127c478bd9Sstevel@tonic-gate  */
1137c478bd9Sstevel@tonic-gate #define	PDESC_REM_DEFER	0x1000	/* entry is marked unusable but still exists */
1147c478bd9Sstevel@tonic-gate #define	PDESC_HAS_REF	(PDESC_HBUF_REF | PDESC_PBUF_REF)
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate #define	Q2PD(p)		\
1177c478bd9Sstevel@tonic-gate 	((pdesc_t *)((caddr_t)(p) - offsetof(pdesc_t, pd_next)))
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #define	PDI_COPY(pd_src, pd_dst) {				\
1207c478bd9Sstevel@tonic-gate 	(pd_dst)->flags = (pd_src)->flags & PDESC_HAS_REF;	\
1217c478bd9Sstevel@tonic-gate 	if ((pd_dst)->flags & PDESC_HBUF_REF) {			\
1227c478bd9Sstevel@tonic-gate 		(pd_dst)->hdr_base = (pd_src)->hdr_base;	\
1237c478bd9Sstevel@tonic-gate 		(pd_dst)->hdr_rptr = (pd_src)->hdr_rptr;	\
1247c478bd9Sstevel@tonic-gate 		(pd_dst)->hdr_wptr = (pd_src)->hdr_wptr;	\
1257c478bd9Sstevel@tonic-gate 		(pd_dst)->hdr_lim = (pd_src)->hdr_lim;		\
1267c478bd9Sstevel@tonic-gate 	} else {						\
1277c478bd9Sstevel@tonic-gate 		(pd_dst)->hdr_base = NULL;			\
1287c478bd9Sstevel@tonic-gate 		(pd_dst)->hdr_rptr = NULL;			\
1297c478bd9Sstevel@tonic-gate 		(pd_dst)->hdr_wptr = NULL;			\
1307c478bd9Sstevel@tonic-gate 		(pd_dst)->hdr_lim = NULL;			\
1317c478bd9Sstevel@tonic-gate 	}							\
1327c478bd9Sstevel@tonic-gate 								\
1337c478bd9Sstevel@tonic-gate 	if ((pd_dst)->flags & PDESC_PBUF_REF) {			\
1347c478bd9Sstevel@tonic-gate 		int i;						\
1357c478bd9Sstevel@tonic-gate 								\
1367c478bd9Sstevel@tonic-gate 		(pd_dst)->pld_cnt = (pd_src)->pld_cnt;		\
1377c478bd9Sstevel@tonic-gate 		for (i = 0; i < (pd_dst)->pld_cnt; i++) {	\
1387c478bd9Sstevel@tonic-gate 			(pd_dst)->pld_ary[i].pld_pbuf_idx =	\
1397c478bd9Sstevel@tonic-gate 			    (pd_src)->pld_ary[i].pld_pbuf_idx;	\
1407c478bd9Sstevel@tonic-gate 			(pd_dst)->pld_ary[i].pld_rptr =		\
1417c478bd9Sstevel@tonic-gate 			    (pd_src)->pld_ary[i].pld_rptr;	\
1427c478bd9Sstevel@tonic-gate 			(pd_dst)->pld_ary[i].pld_wptr =		\
1437c478bd9Sstevel@tonic-gate 			    (pd_src)->pld_ary[i].pld_wptr;	\
1447c478bd9Sstevel@tonic-gate 		}						\
1457c478bd9Sstevel@tonic-gate 	} else {						\
1467c478bd9Sstevel@tonic-gate 		(pd_dst)->pld_cnt = 0;				\
1477c478bd9Sstevel@tonic-gate 	}							\
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * Packet descriptor slab structure.
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate struct pdesc_slab_s {
1547c478bd9Sstevel@tonic-gate 	pdesc_slab_t *pds_next;	/* pointer to next descriptor slab */
1557c478bd9Sstevel@tonic-gate 	pdesc_slab_t *pds_prev;	/* pointer to previous descriptor slab */
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	multidata_t *pds_mmd;	/* back pointer to Multidata */
1587c478bd9Sstevel@tonic-gate 	uint_t	pds_used;	/* always-increasing index to array */
1597c478bd9Sstevel@tonic-gate 	uint_t	pds_sz;		/* size of descriptor array */
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 	pdesc_t	pds_free_desc[1]; /* array of available descriptors */
1627c478bd9Sstevel@tonic-gate };
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate #define	Q2PDSLAB(p)	\
1657c478bd9Sstevel@tonic-gate 	((pdesc_slab_t *)((caddr_t)(p) - offsetof(pdesc_slab_t, pds_next)))
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate #define	PDESC_SLAB_SIZE(npd)  \
1687c478bd9Sstevel@tonic-gate 	((size_t)(&((pdesc_slab_t *)0)->pds_free_desc[npd]))
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate  * Multidata metadata structure.
1727c478bd9Sstevel@tonic-gate  */
1737c478bd9Sstevel@tonic-gate #define	MULTIDATA_MAGIC	0x4d645461	/* "MdTa" */
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate struct multidata_s {
1767c478bd9Sstevel@tonic-gate 	uint_t	mmd_magic;	/* set to MULTIDATA_MAGIC */
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 	dblk_t	*mmd_dp;	/* back pointer to wrapper dblk structure */
1797c478bd9Sstevel@tonic-gate 	mblk_t	*mmd_hbuf;	/* pointer to header buffer mblk */
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	patbkt_t *mmd_pattbl;	/* hash table of global attributes */
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	kmutex_t mmd_pd_slab_lock; /* lock to protect the following items */
1847c478bd9Sstevel@tonic-gate 	uint_t	mmd_pbuf_cnt;	/* number of data buffer */
1857c478bd9Sstevel@tonic-gate 	mblk_t	*mmd_pbuf[MULTIDATA_MAX_PBUFS];	/* data buffer mblk(s) */
1867c478bd9Sstevel@tonic-gate 	ql_t	mmd_pd_slab_q;	/* list of packet descriptor slabs */
1877c478bd9Sstevel@tonic-gate 	ql_t	mmd_pd_q;	/* list of packet descriptors */
1887c478bd9Sstevel@tonic-gate 	uint_t	mmd_slab_cnt;	/* number of packet descriptor slabs */
1897c478bd9Sstevel@tonic-gate 	uint_t	mmd_pd_cnt;	/* number of in-use packet desciptors */
1907c478bd9Sstevel@tonic-gate 	uint_t	mmd_hbuf_ref;	/* descriptors referring to header buffer */
1917c478bd9Sstevel@tonic-gate 	uint_t	mmd_pbuf_ref;	/* descriptors referring to payload buffer(s) */
1927c478bd9Sstevel@tonic-gate };
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate extern void mmd_init(void);
1977c478bd9Sstevel@tonic-gate extern mblk_t *mmd_copy(mblk_t *, int);
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate #endif
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate #endif	/* _SYS_MULTIDATA_IMPL_H */
206