xref: /onnv-gate/usr/src/uts/common/sys/multidata.h (revision 741:40027a3621ac)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*741Smasputra  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef _SYS_MULTIDATA_H
280Sstevel@tonic-gate #define	_SYS_MULTIDATA_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #ifdef	__cplusplus
330Sstevel@tonic-gate extern "C" {
340Sstevel@tonic-gate #endif
350Sstevel@tonic-gate 
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate  * Multidata interface declarations.
380Sstevel@tonic-gate  * These interfaces are still evolving; do not use them in unbundled drivers.
390Sstevel@tonic-gate  */
400Sstevel@tonic-gate 
410Sstevel@tonic-gate /*
420Sstevel@tonic-gate  * Multidata packet attribute information.
430Sstevel@tonic-gate  */
440Sstevel@tonic-gate typedef struct pattrinfo_s {
450Sstevel@tonic-gate 	uint_t	type;		/* attribute type value */
460Sstevel@tonic-gate 	uint_t	len;		/* attribute length */
470Sstevel@tonic-gate 	void	*buf;		/* pointer to user data area */
480Sstevel@tonic-gate } pattrinfo_t;
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  * Maximum number of payload areas for a single packet descriptor.
520Sstevel@tonic-gate  */
530Sstevel@tonic-gate #define	MULTIDATA_MAX_PBUFS	16
540Sstevel@tonic-gate 
550Sstevel@tonic-gate /*
560Sstevel@tonic-gate  * Multidata buffer information.
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate typedef struct mbufinfo_s {
590Sstevel@tonic-gate 	uchar_t	*hbuf_rptr;	/* start address of header buffer */
600Sstevel@tonic-gate 	uchar_t	*hbuf_wptr;	/* end address of header buffer */
610Sstevel@tonic-gate 	uint_t	pbuf_cnt;	/* number of payload buffer */
620Sstevel@tonic-gate 	struct pbuf_ary_s {
630Sstevel@tonic-gate 		uchar_t	*pbuf_rptr;	/* start address of payload buffer */
640Sstevel@tonic-gate 		uchar_t	*pbuf_wptr;	/* end address of payload buffer */
650Sstevel@tonic-gate 	} pbuf_ary[MULTIDATA_MAX_PBUFS];
660Sstevel@tonic-gate } mbufinfo_t;
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate  * Multidata packet descriptor information.
700Sstevel@tonic-gate  */
71*741Smasputra struct pld_ary_s {
72*741Smasputra 	int pld_pbuf_idx;	/* payload buffer index */
73*741Smasputra 	uchar_t *pld_rptr;	/* start address of payload data */
74*741Smasputra 	uchar_t *pld_wptr;	/* pointer to end of payload data */
75*741Smasputra };
76*741Smasputra 
77*741Smasputra #define	PDESCINFO_STRUCT(elems) 					\
78*741Smasputra {									\
79*741Smasputra 	uint_t	flags;		/* misc. flags */			\
80*741Smasputra 	uchar_t	*hdr_base;	/* start address of header area */	\
81*741Smasputra 	uchar_t *hdr_rptr;	/* start address of header data */	\
82*741Smasputra 	uchar_t *hdr_wptr;	/* end address of header data */	\
83*741Smasputra 	uchar_t	*hdr_lim;	/* end address of header area */	\
84*741Smasputra 	uint_t	pld_cnt;	/* number of payload area */		\
85*741Smasputra 	struct pld_ary_s	pld_ary[(elems)];			\
86*741Smasputra }
87*741Smasputra 
88*741Smasputra typedef struct pdescinfo_s PDESCINFO_STRUCT(MULTIDATA_MAX_PBUFS) pdescinfo_t;
890Sstevel@tonic-gate 
900Sstevel@tonic-gate /*
910Sstevel@tonic-gate  * Possible values for flags
920Sstevel@tonic-gate  */
930Sstevel@tonic-gate #define	PDESC_HBUF_REF	0x1	/* descriptor uses header buffer */
940Sstevel@tonic-gate #define	PDESC_PBUF_REF	0x2	/* descriptor uses payload buffer(s) */
950Sstevel@tonic-gate 
960Sstevel@tonic-gate #define	PDESC_HDRSIZE(p) ((p)->hdr_lim - (p)->hdr_base)
970Sstevel@tonic-gate #define	PDESC_HDRL(p)    ((p)->hdr_wptr - (p)->hdr_rptr)
980Sstevel@tonic-gate #define	PDESC_HDRHEAD(p) ((p)->hdr_rptr - (p)->hdr_base)
990Sstevel@tonic-gate #define	PDESC_HDRTAIL(p) ((p)->hdr_lim - (p)->hdr_wptr)
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate #define	PDESC_HDR_ADD(p, base, head, len, tail) {		\
1020Sstevel@tonic-gate 	(p)->hdr_base = (base);					\
1030Sstevel@tonic-gate 	(p)->hdr_rptr = (base) + (head);			\
1040Sstevel@tonic-gate 	(p)->hdr_wptr = (p)->hdr_rptr + (len);			\
1050Sstevel@tonic-gate 	(p)->hdr_lim = (p)->hdr_wptr + (tail);			\
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate #define	PDESC_PLD_INIT(p)  ((p)->pld_cnt = 0)
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate #define	PDESC_PLD_SPAN_SIZE(p, n)				\
1110Sstevel@tonic-gate 	((p)->pld_ary[(n)].pld_wptr - (p)->pld_ary[(n)].pld_rptr)
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate #define	PDESC_PLDL(p, n) PDESC_PLD_SPAN_SIZE(p, n)
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate #define	PDESC_PLD_SPAN_TRIM(p, n, b) {				\
1160Sstevel@tonic-gate 	((p)->pld_ary[(n)].pld_wptr -= (b));			\
1170Sstevel@tonic-gate 	ASSERT((p)->pld_ary[(n)].pld_wptr >= (p)->pld_ary[(n)].pld_rptr); \
1180Sstevel@tonic-gate }
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate #define	PDESC_PLD_SPAN_CLEAR(p, n)				\
1210Sstevel@tonic-gate 	PDESC_PLD_SPAN_TRIM(p, n, PDESC_PLD_SPAN_SIZE(p, n))
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate #define	PDESC_PLD_SPAN_ADD(p, pbuf_idx, rptr, len) {		\
1240Sstevel@tonic-gate 	ASSERT((p)->pld_cnt < MULTIDATA_MAX_PBUFS);		\
1250Sstevel@tonic-gate 	(p)->pld_ary[(p)->pld_cnt].pld_pbuf_idx = (pbuf_idx);	\
1260Sstevel@tonic-gate 	(p)->pld_ary[(p)->pld_cnt].pld_rptr = (rptr);		\
1270Sstevel@tonic-gate 	(p)->pld_ary[(p)->pld_cnt].pld_wptr = (rptr) + (len);	\
1280Sstevel@tonic-gate 	(p)->pld_cnt++;						\
1290Sstevel@tonic-gate }
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate /*
1320Sstevel@tonic-gate  * These structures are opaque to multidata clients.
1330Sstevel@tonic-gate  */
1340Sstevel@tonic-gate struct pdesc_s;
1350Sstevel@tonic-gate typedef struct pdesc_s pdesc_t;
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate struct pattr_s;
1380Sstevel@tonic-gate typedef struct pattr_s pattr_t;
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate struct multidata_s;
1410Sstevel@tonic-gate typedef struct multidata_s multidata_t;
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate #ifdef _KERNEL
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate extern multidata_t *mmd_alloc(mblk_t *, mblk_t **, int);
1460Sstevel@tonic-gate extern int mmd_addpldbuf(multidata_t *, mblk_t *);
1470Sstevel@tonic-gate extern multidata_t *mmd_getmultidata(mblk_t *);
1480Sstevel@tonic-gate extern void mmd_getregions(multidata_t *, mbufinfo_t *);
1490Sstevel@tonic-gate extern uint_t mmd_getcnt(multidata_t *, uint_t *, uint_t *);
1500Sstevel@tonic-gate extern pdesc_t *mmd_addpdesc(multidata_t *, pdescinfo_t *, int *, int);
1510Sstevel@tonic-gate extern void mmd_rempdesc(pdesc_t *);
1520Sstevel@tonic-gate extern pdesc_t *mmd_getfirstpdesc(multidata_t *, pdescinfo_t *);
1530Sstevel@tonic-gate extern pdesc_t *mmd_getlastpdesc(multidata_t *, pdescinfo_t *);
1540Sstevel@tonic-gate extern pdesc_t *mmd_getnextpdesc(pdesc_t *, pdescinfo_t *);
1550Sstevel@tonic-gate extern pdesc_t *mmd_getprevpdesc(pdesc_t *, pdescinfo_t *);
1560Sstevel@tonic-gate extern pdesc_t *mmd_adjpdesc(pdesc_t *, pdescinfo_t *);
1570Sstevel@tonic-gate extern mblk_t *mmd_transform(pdesc_t *);
1580Sstevel@tonic-gate extern mblk_t *mmd_transform_link(pdesc_t *);
1590Sstevel@tonic-gate extern int mmd_dupbufs(multidata_t *, mblk_t **, mblk_t **);
1600Sstevel@tonic-gate extern int mmd_getpdescinfo(pdesc_t *, pdescinfo_t *);
1610Sstevel@tonic-gate extern pattr_t *mmd_addpattr(multidata_t *, pdesc_t *, pattrinfo_t *,
1620Sstevel@tonic-gate     boolean_t, int);
1630Sstevel@tonic-gate extern void mmd_rempattr(pattr_t *);
1640Sstevel@tonic-gate extern pattr_t *mmd_getpattr(multidata_t *, pdesc_t *, pattrinfo_t *);
1650Sstevel@tonic-gate extern void mmd_getsize(multidata_t *, uint_t *, uint_t *);
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate #endif /* _KERNEL */
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate #ifdef	__cplusplus
1700Sstevel@tonic-gate }
1710Sstevel@tonic-gate #endif
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate #endif	/* _SYS_MULTIDATA_H */
174