xref: /titanic_50/usr/src/uts/common/sys/multidata.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _SYS_MULTIDATA_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_MULTIDATA_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
33*7c478bd9Sstevel@tonic-gate extern "C" {
34*7c478bd9Sstevel@tonic-gate #endif
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate /*
37*7c478bd9Sstevel@tonic-gate  * Multidata interface declarations.
38*7c478bd9Sstevel@tonic-gate  * These interfaces are still evolving; do not use them in unbundled drivers.
39*7c478bd9Sstevel@tonic-gate  */
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate /*
42*7c478bd9Sstevel@tonic-gate  * Multidata packet attribute information.
43*7c478bd9Sstevel@tonic-gate  */
44*7c478bd9Sstevel@tonic-gate typedef struct pattrinfo_s {
45*7c478bd9Sstevel@tonic-gate 	uint_t	type;		/* attribute type value */
46*7c478bd9Sstevel@tonic-gate 	uint_t	len;		/* attribute length */
47*7c478bd9Sstevel@tonic-gate 	void	*buf;		/* pointer to user data area */
48*7c478bd9Sstevel@tonic-gate } pattrinfo_t;
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate /*
51*7c478bd9Sstevel@tonic-gate  * Maximum number of payload areas for a single packet descriptor.
52*7c478bd9Sstevel@tonic-gate  */
53*7c478bd9Sstevel@tonic-gate #define	MULTIDATA_MAX_PBUFS	16
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate /*
56*7c478bd9Sstevel@tonic-gate  * Multidata buffer information.
57*7c478bd9Sstevel@tonic-gate  */
58*7c478bd9Sstevel@tonic-gate typedef struct mbufinfo_s {
59*7c478bd9Sstevel@tonic-gate 	uchar_t	*hbuf_rptr;	/* start address of header buffer */
60*7c478bd9Sstevel@tonic-gate 	uchar_t	*hbuf_wptr;	/* end address of header buffer */
61*7c478bd9Sstevel@tonic-gate 	uint_t	pbuf_cnt;	/* number of payload buffer */
62*7c478bd9Sstevel@tonic-gate 	struct pbuf_ary_s {
63*7c478bd9Sstevel@tonic-gate 		uchar_t	*pbuf_rptr;	/* start address of payload buffer */
64*7c478bd9Sstevel@tonic-gate 		uchar_t	*pbuf_wptr;	/* end address of payload buffer */
65*7c478bd9Sstevel@tonic-gate 	} pbuf_ary[MULTIDATA_MAX_PBUFS];
66*7c478bd9Sstevel@tonic-gate } mbufinfo_t;
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate /*
69*7c478bd9Sstevel@tonic-gate  * Multidata packet descriptor information.
70*7c478bd9Sstevel@tonic-gate  */
71*7c478bd9Sstevel@tonic-gate typedef struct pdescinfo_s {
72*7c478bd9Sstevel@tonic-gate 	uint_t	flags;		/* misc. flags */
73*7c478bd9Sstevel@tonic-gate 	uchar_t	*hdr_base;	/* start address of header area */
74*7c478bd9Sstevel@tonic-gate 	uchar_t *hdr_rptr;	/* start address of header data */
75*7c478bd9Sstevel@tonic-gate 	uchar_t *hdr_wptr;	/* end address of header data */
76*7c478bd9Sstevel@tonic-gate 	uchar_t	*hdr_lim;	/* end address of header area */
77*7c478bd9Sstevel@tonic-gate 	uint_t	pld_cnt;	/* number of payload area */
78*7c478bd9Sstevel@tonic-gate 	struct pld_ary_s {
79*7c478bd9Sstevel@tonic-gate 		int pld_pbuf_idx;	/* payload buffer index */
80*7c478bd9Sstevel@tonic-gate 		uchar_t *pld_rptr;	/* start address of payload data */
81*7c478bd9Sstevel@tonic-gate 		uchar_t *pld_wptr;	/* pointer to end of payload data */
82*7c478bd9Sstevel@tonic-gate 	} pld_ary[MULTIDATA_MAX_PBUFS];
83*7c478bd9Sstevel@tonic-gate } pdescinfo_t;
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate /*
86*7c478bd9Sstevel@tonic-gate  * Possible values for flags
87*7c478bd9Sstevel@tonic-gate  */
88*7c478bd9Sstevel@tonic-gate #define	PDESC_HBUF_REF	0x1	/* descriptor uses header buffer */
89*7c478bd9Sstevel@tonic-gate #define	PDESC_PBUF_REF	0x2	/* descriptor uses payload buffer(s) */
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate #define	PDESC_HDRSIZE(p) ((p)->hdr_lim - (p)->hdr_base)
92*7c478bd9Sstevel@tonic-gate #define	PDESC_HDRL(p)    ((p)->hdr_wptr - (p)->hdr_rptr)
93*7c478bd9Sstevel@tonic-gate #define	PDESC_HDRHEAD(p) ((p)->hdr_rptr - (p)->hdr_base)
94*7c478bd9Sstevel@tonic-gate #define	PDESC_HDRTAIL(p) ((p)->hdr_lim - (p)->hdr_wptr)
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate #define	PDESC_HDR_ADD(p, base, head, len, tail) {		\
97*7c478bd9Sstevel@tonic-gate 	(p)->hdr_base = (base);					\
98*7c478bd9Sstevel@tonic-gate 	(p)->hdr_rptr = (base) + (head);			\
99*7c478bd9Sstevel@tonic-gate 	(p)->hdr_wptr = (p)->hdr_rptr + (len);			\
100*7c478bd9Sstevel@tonic-gate 	(p)->hdr_lim = (p)->hdr_wptr + (tail);			\
101*7c478bd9Sstevel@tonic-gate }
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate #define	PDESC_PLD_INIT(p)  ((p)->pld_cnt = 0)
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate #define	PDESC_PLD_SPAN_SIZE(p, n)				\
106*7c478bd9Sstevel@tonic-gate 	((p)->pld_ary[(n)].pld_wptr - (p)->pld_ary[(n)].pld_rptr)
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate #define	PDESC_PLDL(p, n) PDESC_PLD_SPAN_SIZE(p, n)
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate #define	PDESC_PLD_SPAN_TRIM(p, n, b) {				\
111*7c478bd9Sstevel@tonic-gate 	((p)->pld_ary[(n)].pld_wptr -= (b));			\
112*7c478bd9Sstevel@tonic-gate 	ASSERT((p)->pld_ary[(n)].pld_wptr >= (p)->pld_ary[(n)].pld_rptr); \
113*7c478bd9Sstevel@tonic-gate }
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate #define	PDESC_PLD_SPAN_CLEAR(p, n)				\
116*7c478bd9Sstevel@tonic-gate 	PDESC_PLD_SPAN_TRIM(p, n, PDESC_PLD_SPAN_SIZE(p, n))
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate #define	PDESC_PLD_SPAN_ADD(p, pbuf_idx, rptr, len) {		\
119*7c478bd9Sstevel@tonic-gate 	ASSERT((p)->pld_cnt < MULTIDATA_MAX_PBUFS);		\
120*7c478bd9Sstevel@tonic-gate 	(p)->pld_ary[(p)->pld_cnt].pld_pbuf_idx = (pbuf_idx);	\
121*7c478bd9Sstevel@tonic-gate 	(p)->pld_ary[(p)->pld_cnt].pld_rptr = (rptr);		\
122*7c478bd9Sstevel@tonic-gate 	(p)->pld_ary[(p)->pld_cnt].pld_wptr = (rptr) + (len);	\
123*7c478bd9Sstevel@tonic-gate 	(p)->pld_cnt++;						\
124*7c478bd9Sstevel@tonic-gate }
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate /*
127*7c478bd9Sstevel@tonic-gate  * These structures are opaque to multidata clients.
128*7c478bd9Sstevel@tonic-gate  */
129*7c478bd9Sstevel@tonic-gate struct pdesc_s;
130*7c478bd9Sstevel@tonic-gate typedef struct pdesc_s pdesc_t;
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate struct pattr_s;
133*7c478bd9Sstevel@tonic-gate typedef struct pattr_s pattr_t;
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate struct multidata_s;
136*7c478bd9Sstevel@tonic-gate typedef struct multidata_s multidata_t;
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate extern multidata_t *mmd_alloc(mblk_t *, mblk_t **, int);
141*7c478bd9Sstevel@tonic-gate extern int mmd_addpldbuf(multidata_t *, mblk_t *);
142*7c478bd9Sstevel@tonic-gate extern multidata_t *mmd_getmultidata(mblk_t *);
143*7c478bd9Sstevel@tonic-gate extern void mmd_getregions(multidata_t *, mbufinfo_t *);
144*7c478bd9Sstevel@tonic-gate extern uint_t mmd_getcnt(multidata_t *, uint_t *, uint_t *);
145*7c478bd9Sstevel@tonic-gate extern pdesc_t *mmd_addpdesc(multidata_t *, pdescinfo_t *, int *, int);
146*7c478bd9Sstevel@tonic-gate extern void mmd_rempdesc(pdesc_t *);
147*7c478bd9Sstevel@tonic-gate extern pdesc_t *mmd_getfirstpdesc(multidata_t *, pdescinfo_t *);
148*7c478bd9Sstevel@tonic-gate extern pdesc_t *mmd_getlastpdesc(multidata_t *, pdescinfo_t *);
149*7c478bd9Sstevel@tonic-gate extern pdesc_t *mmd_getnextpdesc(pdesc_t *, pdescinfo_t *);
150*7c478bd9Sstevel@tonic-gate extern pdesc_t *mmd_getprevpdesc(pdesc_t *, pdescinfo_t *);
151*7c478bd9Sstevel@tonic-gate extern pdesc_t *mmd_adjpdesc(pdesc_t *, pdescinfo_t *);
152*7c478bd9Sstevel@tonic-gate extern mblk_t *mmd_transform(pdesc_t *);
153*7c478bd9Sstevel@tonic-gate extern mblk_t *mmd_transform_link(pdesc_t *);
154*7c478bd9Sstevel@tonic-gate extern int mmd_dupbufs(multidata_t *, mblk_t **, mblk_t **);
155*7c478bd9Sstevel@tonic-gate extern int mmd_getpdescinfo(pdesc_t *, pdescinfo_t *);
156*7c478bd9Sstevel@tonic-gate extern pattr_t *mmd_addpattr(multidata_t *, pdesc_t *, pattrinfo_t *,
157*7c478bd9Sstevel@tonic-gate     boolean_t, int);
158*7c478bd9Sstevel@tonic-gate extern void mmd_rempattr(pattr_t *);
159*7c478bd9Sstevel@tonic-gate extern pattr_t *mmd_getpattr(multidata_t *, pdesc_t *, pattrinfo_t *);
160*7c478bd9Sstevel@tonic-gate extern void mmd_getsize(multidata_t *, uint_t *, uint_t *);
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
165*7c478bd9Sstevel@tonic-gate }
166*7c478bd9Sstevel@tonic-gate #endif
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_MULTIDATA_H */
169