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