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_IMPL_H 280Sstevel@tonic-gate #define _SYS_MULTIDATA_IMPL_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: implementation-private data structure and declarations. 380Sstevel@tonic-gate */ 390Sstevel@tonic-gate 400Sstevel@tonic-gate /* 410Sstevel@tonic-gate * Structure used for insque/remque circular list operations. 420Sstevel@tonic-gate */ 430Sstevel@tonic-gate typedef struct ql_s { 440Sstevel@tonic-gate struct ql_s *ql_next; /* pointer to next list element */ 450Sstevel@tonic-gate struct ql_s *ql_prev; /* pointer to previous list element */ 460Sstevel@tonic-gate } ql_t; 470Sstevel@tonic-gate 480Sstevel@tonic-gate #define QL_INIT(q) { \ 490Sstevel@tonic-gate ((ql_t *)(q))->ql_next = (ql_t *)(q); \ 500Sstevel@tonic-gate ((ql_t *)(q))->ql_prev = (ql_t *)(q); \ 510Sstevel@tonic-gate } 520Sstevel@tonic-gate 530Sstevel@tonic-gate typedef struct pdesc_slab_s pdesc_slab_t; 540Sstevel@tonic-gate 550Sstevel@tonic-gate /* 560Sstevel@tonic-gate * Attribute hash bucket structure. 570Sstevel@tonic-gate */ 580Sstevel@tonic-gate typedef struct patbkt_s { 590Sstevel@tonic-gate kmutex_t pbkt_lock; /* per-bucket lock */ 600Sstevel@tonic-gate ql_t pbkt_pattr_q; /* list of attributes */ 610Sstevel@tonic-gate uint_t pbkt_tbl_sz; /* table size (if this is first bucket) */ 620Sstevel@tonic-gate } patbkt_t; 630Sstevel@tonic-gate 640Sstevel@tonic-gate /* 650Sstevel@tonic-gate * Attribute structure. 660Sstevel@tonic-gate */ 670Sstevel@tonic-gate #define PATTR_MAGIC 0x50615472 /* "PaTr" */ 680Sstevel@tonic-gate 690Sstevel@tonic-gate struct pattr_s { 700Sstevel@tonic-gate pattr_t *pat_next; /* pointer to next attribute in bucket */ 710Sstevel@tonic-gate pattr_t *pat_prev; /* pointer to previous attribute in bucket */ 720Sstevel@tonic-gate 730Sstevel@tonic-gate uint_t pat_magic; /* set to PATTR_MAGIC */ 740Sstevel@tonic-gate 750Sstevel@tonic-gate kmutex_t *pat_lock; /* pointer to per-bucket lock */ 760Sstevel@tonic-gate multidata_t *pat_mmd; /* back pointer to Multidata */ 770Sstevel@tonic-gate uint_t pat_buflen; /* length of this structure + attribute */ 780Sstevel@tonic-gate uint_t pat_type; /* type of encapsulated attribute */ 790Sstevel@tonic-gate uint_t pat_flags; /* misc. flags */ 800Sstevel@tonic-gate }; 810Sstevel@tonic-gate 820Sstevel@tonic-gate /* 830Sstevel@tonic-gate * Values for pat_flags. 840Sstevel@tonic-gate */ 850Sstevel@tonic-gate #define PATTR_REM_DEFER 0x1 /* entry is marked unusable but still exists */ 860Sstevel@tonic-gate #define PATTR_PERSIST 0x2 /* entry can't be removed */ 870Sstevel@tonic-gate 880Sstevel@tonic-gate #define Q2PATTR(p) \ 890Sstevel@tonic-gate ((pattr_t *)((caddr_t)(p) - offsetof(pattr_t, pat_next))) 900Sstevel@tonic-gate 910Sstevel@tonic-gate /* 920Sstevel@tonic-gate * Packet descriptor structure. 930Sstevel@tonic-gate */ 940Sstevel@tonic-gate #define PDESC_MAGIC 0x506b5464 /* "PkTd" */ 950Sstevel@tonic-gate 960Sstevel@tonic-gate struct pdesc_s { 970Sstevel@tonic-gate pdesc_t *pd_next; /* pointer to next descriptor */ 980Sstevel@tonic-gate pdesc_t *pd_prev; /* pointer to previous descriptor */ 990Sstevel@tonic-gate 1000Sstevel@tonic-gate uint_t pd_magic; /* set to PDESC_MAGIC */ 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate pdesc_slab_t *pd_slab; /* back pointer to descriptor slab */ 1030Sstevel@tonic-gate patbkt_t *pd_pattbl; /* hash table of local attributes */ 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate pdescinfo_t pd_pdi; /* embedded descriptor info structure */ 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate #define pd_flags pd_pdi.flags 1080Sstevel@tonic-gate }; 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate /* 1110Sstevel@tonic-gate * Additional internal flags for pd_flags (see multidata.h for the rest). 1120Sstevel@tonic-gate */ 1130Sstevel@tonic-gate #define PDESC_REM_DEFER 0x1000 /* entry is marked unusable but still exists */ 1140Sstevel@tonic-gate #define PDESC_HAS_REF (PDESC_HBUF_REF | PDESC_PBUF_REF) 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate #define Q2PD(p) \ 1170Sstevel@tonic-gate ((pdesc_t *)((caddr_t)(p) - offsetof(pdesc_t, pd_next))) 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate #define PDI_COPY(pd_src, pd_dst) { \ 1200Sstevel@tonic-gate (pd_dst)->flags = (pd_src)->flags & PDESC_HAS_REF; \ 1210Sstevel@tonic-gate if ((pd_dst)->flags & PDESC_HBUF_REF) { \ 1220Sstevel@tonic-gate (pd_dst)->hdr_base = (pd_src)->hdr_base; \ 1230Sstevel@tonic-gate (pd_dst)->hdr_rptr = (pd_src)->hdr_rptr; \ 1240Sstevel@tonic-gate (pd_dst)->hdr_wptr = (pd_src)->hdr_wptr; \ 1250Sstevel@tonic-gate (pd_dst)->hdr_lim = (pd_src)->hdr_lim; \ 1260Sstevel@tonic-gate } else { \ 1270Sstevel@tonic-gate (pd_dst)->hdr_base = NULL; \ 1280Sstevel@tonic-gate (pd_dst)->hdr_rptr = NULL; \ 1290Sstevel@tonic-gate (pd_dst)->hdr_wptr = NULL; \ 1300Sstevel@tonic-gate (pd_dst)->hdr_lim = NULL; \ 1310Sstevel@tonic-gate } \ 1320Sstevel@tonic-gate \ 1330Sstevel@tonic-gate if ((pd_dst)->flags & PDESC_PBUF_REF) { \ 1340Sstevel@tonic-gate int i; \ 1350Sstevel@tonic-gate \ 1360Sstevel@tonic-gate (pd_dst)->pld_cnt = (pd_src)->pld_cnt; \ 1370Sstevel@tonic-gate for (i = 0; i < (pd_dst)->pld_cnt; i++) { \ 1380Sstevel@tonic-gate (pd_dst)->pld_ary[i].pld_pbuf_idx = \ 1390Sstevel@tonic-gate (pd_src)->pld_ary[i].pld_pbuf_idx; \ 1400Sstevel@tonic-gate (pd_dst)->pld_ary[i].pld_rptr = \ 1410Sstevel@tonic-gate (pd_src)->pld_ary[i].pld_rptr; \ 1420Sstevel@tonic-gate (pd_dst)->pld_ary[i].pld_wptr = \ 1430Sstevel@tonic-gate (pd_src)->pld_ary[i].pld_wptr; \ 1440Sstevel@tonic-gate } \ 1450Sstevel@tonic-gate } else { \ 1460Sstevel@tonic-gate (pd_dst)->pld_cnt = 0; \ 1470Sstevel@tonic-gate } \ 1480Sstevel@tonic-gate } 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate /* 1510Sstevel@tonic-gate * Packet descriptor slab structure. 1520Sstevel@tonic-gate */ 1530Sstevel@tonic-gate struct pdesc_slab_s { 1540Sstevel@tonic-gate pdesc_slab_t *pds_next; /* pointer to next descriptor slab */ 1550Sstevel@tonic-gate pdesc_slab_t *pds_prev; /* pointer to previous descriptor slab */ 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate multidata_t *pds_mmd; /* back pointer to Multidata */ 1580Sstevel@tonic-gate uint_t pds_used; /* always-increasing index to array */ 1590Sstevel@tonic-gate uint_t pds_sz; /* size of descriptor array */ 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate pdesc_t pds_free_desc[1]; /* array of available descriptors */ 1620Sstevel@tonic-gate }; 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate #define Q2PDSLAB(p) \ 1650Sstevel@tonic-gate ((pdesc_slab_t *)((caddr_t)(p) - offsetof(pdesc_slab_t, pds_next))) 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate #define PDESC_SLAB_SIZE(npd) \ 1680Sstevel@tonic-gate ((size_t)(&((pdesc_slab_t *)0)->pds_free_desc[npd])) 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate /* 1710Sstevel@tonic-gate * Multidata metadata structure. 1720Sstevel@tonic-gate */ 1730Sstevel@tonic-gate #define MULTIDATA_MAGIC 0x4d645461 /* "MdTa" */ 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate struct multidata_s { 1760Sstevel@tonic-gate uint_t mmd_magic; /* set to MULTIDATA_MAGIC */ 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate dblk_t *mmd_dp; /* back pointer to wrapper dblk structure */ 1790Sstevel@tonic-gate mblk_t *mmd_hbuf; /* pointer to header buffer mblk */ 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate patbkt_t *mmd_pattbl; /* hash table of global attributes */ 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate kmutex_t mmd_pd_slab_lock; /* lock to protect the following items */ 1840Sstevel@tonic-gate uint_t mmd_pbuf_cnt; /* number of data buffer */ 1850Sstevel@tonic-gate mblk_t *mmd_pbuf[MULTIDATA_MAX_PBUFS]; /* data buffer mblk(s) */ 1860Sstevel@tonic-gate ql_t mmd_pd_slab_q; /* list of packet descriptor slabs */ 1870Sstevel@tonic-gate ql_t mmd_pd_q; /* list of packet descriptors */ 1880Sstevel@tonic-gate uint_t mmd_slab_cnt; /* number of packet descriptor slabs */ 1890Sstevel@tonic-gate uint_t mmd_pd_cnt; /* number of in-use packet desciptors */ 1900Sstevel@tonic-gate uint_t mmd_hbuf_ref; /* descriptors referring to header buffer */ 1910Sstevel@tonic-gate uint_t mmd_pbuf_ref; /* descriptors referring to payload buffer(s) */ 1920Sstevel@tonic-gate }; 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate #ifdef _KERNEL 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate extern void mmd_init(void); 1970Sstevel@tonic-gate extern mblk_t *mmd_copy(mblk_t *, int); 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate #endif /* _KERNEL */ 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate #ifdef __cplusplus 2020Sstevel@tonic-gate } 2030Sstevel@tonic-gate #endif 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate #endif /* _SYS_MULTIDATA_IMPL_H */ 206