xref: /titanic_44/usr/src/uts/common/sys/multidata.h (revision 1a7c1b724419d3cb5fa6eea75123c6b2060ba31b)
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 2004 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 typedef struct pdescinfo_s {
72 	uint_t	flags;		/* misc. flags */
73 	uchar_t	*hdr_base;	/* start address of header area */
74 	uchar_t *hdr_rptr;	/* start address of header data */
75 	uchar_t *hdr_wptr;	/* end address of header data */
76 	uchar_t	*hdr_lim;	/* end address of header area */
77 	uint_t	pld_cnt;	/* number of payload area */
78 	struct pld_ary_s {
79 		int pld_pbuf_idx;	/* payload buffer index */
80 		uchar_t *pld_rptr;	/* start address of payload data */
81 		uchar_t *pld_wptr;	/* pointer to end of payload data */
82 	} pld_ary[MULTIDATA_MAX_PBUFS];
83 } pdescinfo_t;
84 
85 /*
86  * Possible values for flags
87  */
88 #define	PDESC_HBUF_REF	0x1	/* descriptor uses header buffer */
89 #define	PDESC_PBUF_REF	0x2	/* descriptor uses payload buffer(s) */
90 
91 #define	PDESC_HDRSIZE(p) ((p)->hdr_lim - (p)->hdr_base)
92 #define	PDESC_HDRL(p)    ((p)->hdr_wptr - (p)->hdr_rptr)
93 #define	PDESC_HDRHEAD(p) ((p)->hdr_rptr - (p)->hdr_base)
94 #define	PDESC_HDRTAIL(p) ((p)->hdr_lim - (p)->hdr_wptr)
95 
96 #define	PDESC_HDR_ADD(p, base, head, len, tail) {		\
97 	(p)->hdr_base = (base);					\
98 	(p)->hdr_rptr = (base) + (head);			\
99 	(p)->hdr_wptr = (p)->hdr_rptr + (len);			\
100 	(p)->hdr_lim = (p)->hdr_wptr + (tail);			\
101 }
102 
103 #define	PDESC_PLD_INIT(p)  ((p)->pld_cnt = 0)
104 
105 #define	PDESC_PLD_SPAN_SIZE(p, n)				\
106 	((p)->pld_ary[(n)].pld_wptr - (p)->pld_ary[(n)].pld_rptr)
107 
108 #define	PDESC_PLDL(p, n) PDESC_PLD_SPAN_SIZE(p, n)
109 
110 #define	PDESC_PLD_SPAN_TRIM(p, n, b) {				\
111 	((p)->pld_ary[(n)].pld_wptr -= (b));			\
112 	ASSERT((p)->pld_ary[(n)].pld_wptr >= (p)->pld_ary[(n)].pld_rptr); \
113 }
114 
115 #define	PDESC_PLD_SPAN_CLEAR(p, n)				\
116 	PDESC_PLD_SPAN_TRIM(p, n, PDESC_PLD_SPAN_SIZE(p, n))
117 
118 #define	PDESC_PLD_SPAN_ADD(p, pbuf_idx, rptr, len) {		\
119 	ASSERT((p)->pld_cnt < MULTIDATA_MAX_PBUFS);		\
120 	(p)->pld_ary[(p)->pld_cnt].pld_pbuf_idx = (pbuf_idx);	\
121 	(p)->pld_ary[(p)->pld_cnt].pld_rptr = (rptr);		\
122 	(p)->pld_ary[(p)->pld_cnt].pld_wptr = (rptr) + (len);	\
123 	(p)->pld_cnt++;						\
124 }
125 
126 /*
127  * These structures are opaque to multidata clients.
128  */
129 struct pdesc_s;
130 typedef struct pdesc_s pdesc_t;
131 
132 struct pattr_s;
133 typedef struct pattr_s pattr_t;
134 
135 struct multidata_s;
136 typedef struct multidata_s multidata_t;
137 
138 #ifdef _KERNEL
139 
140 extern multidata_t *mmd_alloc(mblk_t *, mblk_t **, int);
141 extern int mmd_addpldbuf(multidata_t *, mblk_t *);
142 extern multidata_t *mmd_getmultidata(mblk_t *);
143 extern void mmd_getregions(multidata_t *, mbufinfo_t *);
144 extern uint_t mmd_getcnt(multidata_t *, uint_t *, uint_t *);
145 extern pdesc_t *mmd_addpdesc(multidata_t *, pdescinfo_t *, int *, int);
146 extern void mmd_rempdesc(pdesc_t *);
147 extern pdesc_t *mmd_getfirstpdesc(multidata_t *, pdescinfo_t *);
148 extern pdesc_t *mmd_getlastpdesc(multidata_t *, pdescinfo_t *);
149 extern pdesc_t *mmd_getnextpdesc(pdesc_t *, pdescinfo_t *);
150 extern pdesc_t *mmd_getprevpdesc(pdesc_t *, pdescinfo_t *);
151 extern pdesc_t *mmd_adjpdesc(pdesc_t *, pdescinfo_t *);
152 extern mblk_t *mmd_transform(pdesc_t *);
153 extern mblk_t *mmd_transform_link(pdesc_t *);
154 extern int mmd_dupbufs(multidata_t *, mblk_t **, mblk_t **);
155 extern int mmd_getpdescinfo(pdesc_t *, pdescinfo_t *);
156 extern pattr_t *mmd_addpattr(multidata_t *, pdesc_t *, pattrinfo_t *,
157     boolean_t, int);
158 extern void mmd_rempattr(pattr_t *);
159 extern pattr_t *mmd_getpattr(multidata_t *, pdesc_t *, pattrinfo_t *);
160 extern void mmd_getsize(multidata_t *, uint_t *, uint_t *);
161 
162 #endif /* _KERNEL */
163 
164 #ifdef	__cplusplus
165 }
166 #endif
167 
168 #endif	/* _SYS_MULTIDATA_H */
169