17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * spppcomp.c - STREAMS module for kernel-level compression and CCP support.
37c478bd9Sstevel@tonic-gate  *
4f53eecf5SJames Carlson  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
57c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
648bbca81SDaniel Hoffman  * Copyright (c) 2016 by Delphix. All rights reserved.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * Permission to use, copy, modify, and distribute this software and its
97c478bd9Sstevel@tonic-gate  * documentation is hereby granted, provided that the above copyright
107c478bd9Sstevel@tonic-gate  * notice appears in all copies.
117c478bd9Sstevel@tonic-gate  *
127c478bd9Sstevel@tonic-gate  * SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
137c478bd9Sstevel@tonic-gate  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
147c478bd9Sstevel@tonic-gate  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
157c478bd9Sstevel@tonic-gate  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  SUN SHALL NOT BE LIABLE FOR
167c478bd9Sstevel@tonic-gate  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
177c478bd9Sstevel@tonic-gate  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * Copyright (c) 1994 The Australian National University.
207c478bd9Sstevel@tonic-gate  * All rights reserved.
217c478bd9Sstevel@tonic-gate  *
227c478bd9Sstevel@tonic-gate  * Permission to use, copy, modify, and distribute this software and its
237c478bd9Sstevel@tonic-gate  * documentation is hereby granted, provided that the above copyright
247c478bd9Sstevel@tonic-gate  * notice appears in all copies.  This software is provided without any
257c478bd9Sstevel@tonic-gate  * warranty, express or implied. The Australian National University
267c478bd9Sstevel@tonic-gate  * makes no representations about the suitability of this software for
277c478bd9Sstevel@tonic-gate  * any purpose.
287c478bd9Sstevel@tonic-gate  *
297c478bd9Sstevel@tonic-gate  * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
307c478bd9Sstevel@tonic-gate  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
317c478bd9Sstevel@tonic-gate  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
327c478bd9Sstevel@tonic-gate  * THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY
337c478bd9Sstevel@tonic-gate  * OF SUCH DAMAGE.
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
367c478bd9Sstevel@tonic-gate  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
377c478bd9Sstevel@tonic-gate  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
387c478bd9Sstevel@tonic-gate  * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
397c478bd9Sstevel@tonic-gate  * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
407c478bd9Sstevel@tonic-gate  * OR MODIFICATIONS.
417c478bd9Sstevel@tonic-gate  *
427c478bd9Sstevel@tonic-gate  * This module is derived from the original SVR4 STREAMS PPP compression
437c478bd9Sstevel@tonic-gate  * module originally written by Paul Mackerras <paul.mackerras@cs.anu.edu.au>.
447c478bd9Sstevel@tonic-gate  *
457c478bd9Sstevel@tonic-gate  * James Carlson <james.d.carlson@sun.com> and Adi Masputra
467c478bd9Sstevel@tonic-gate  * <adi.masputra@sun.com> rewrote and restructured the code for improved
477c478bd9Sstevel@tonic-gate  * performance and scalability.
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #define	RCSID	"$Id: spppcomp.c,v 1.0 2000/05/08 01:10:12 masputra Exp $"
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #include <sys/types.h>
537c478bd9Sstevel@tonic-gate #include <sys/debug.h>
547c478bd9Sstevel@tonic-gate #include <sys/param.h>
557c478bd9Sstevel@tonic-gate #include <sys/stream.h>
567c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
577c478bd9Sstevel@tonic-gate #include <sys/errno.h>
587c478bd9Sstevel@tonic-gate #include <sys/conf.h>
597c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
607c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
617c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
627c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
637c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
647c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
657c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
667c478bd9Sstevel@tonic-gate #include <netinet/in.h>
677c478bd9Sstevel@tonic-gate #include <netinet/ip.h>
687c478bd9Sstevel@tonic-gate #include <net/ppp_defs.h>
697c478bd9Sstevel@tonic-gate #include <net/pppio.h>
707c478bd9Sstevel@tonic-gate #include <net/vjcompress.h>
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /* Defined for platform-neutral include file */
737c478bd9Sstevel@tonic-gate #define	PACKETPTR	mblk_t *
747c478bd9Sstevel@tonic-gate #include <net/ppp-comp.h>
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #include "s_common.h"
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #ifdef DEBUG
797c478bd9Sstevel@tonic-gate #define	SPC_DEBUG
807c478bd9Sstevel@tonic-gate #endif
817c478bd9Sstevel@tonic-gate #include "spppcomp.h"
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  * This is used to tag official Solaris sources.  Please do not define
857c478bd9Sstevel@tonic-gate  * "INTERNAL_BUILD" when building this software outside of Sun
867c478bd9Sstevel@tonic-gate  * Microsystems.
877c478bd9Sstevel@tonic-gate  */
887c478bd9Sstevel@tonic-gate #ifdef INTERNAL_BUILD
897c478bd9Sstevel@tonic-gate /* MODINFO is limited to 32 characters. */
90002c70ffScarlsonj const char spppcomp_module_description[] = "PPP 4.0 compression";
917c478bd9Sstevel@tonic-gate #else /* INTERNAL_BUILD */
927c478bd9Sstevel@tonic-gate const char spppcomp_module_description[] =
937c478bd9Sstevel@tonic-gate 	"ANU PPP compression $Revision: 1.16$ ";
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /* LINTED */
967c478bd9Sstevel@tonic-gate static const char buildtime[] = "Built " __DATE__ " at " __TIME__
977c478bd9Sstevel@tonic-gate #ifdef DEBUG
987c478bd9Sstevel@tonic-gate " DEBUG"
997c478bd9Sstevel@tonic-gate #endif
1007c478bd9Sstevel@tonic-gate "\n";
1017c478bd9Sstevel@tonic-gate #endif /* INTERNAL_BUILD */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate static int	spppcomp_open(queue_t *, dev_t *, int, int, cred_t *);
1047c478bd9Sstevel@tonic-gate static int	spppcomp_close(queue_t *, int, cred_t *);
105*c4d76aa4SToomas Soome static int	spppcomp_rput(queue_t *, mblk_t *);
106*c4d76aa4SToomas Soome static int	spppcomp_rsrv(queue_t *);
107*c4d76aa4SToomas Soome static int	spppcomp_wput(queue_t *, mblk_t *);
108*c4d76aa4SToomas Soome static int	spppcomp_wsrv(queue_t *);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate #define	PPPCOMP_MI_MINPSZ	(0)
1117c478bd9Sstevel@tonic-gate #define	PPPCOMP_MI_MAXPSZ	(INFPSZ)
1127c478bd9Sstevel@tonic-gate #define	PPPCOMP_MI_HIWAT	(PPP_MTU * 20)
1137c478bd9Sstevel@tonic-gate #define	PPPCOMP_MI_LOWAT	(PPP_MTU * 18)
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate static struct module_info spppcomp_modinfo = {
1167c478bd9Sstevel@tonic-gate 	COMP_MOD_ID,		/* mi_idnum */
1177c478bd9Sstevel@tonic-gate 	COMP_MOD_NAME,		/* mi_idname */
1187c478bd9Sstevel@tonic-gate 	PPPCOMP_MI_MINPSZ,	/* mi_minpsz */
1197c478bd9Sstevel@tonic-gate 	PPPCOMP_MI_MAXPSZ,	/* mi_maxpsz */
1207c478bd9Sstevel@tonic-gate 	PPPCOMP_MI_HIWAT,	/* mi_hiwat */
1217c478bd9Sstevel@tonic-gate 	PPPCOMP_MI_LOWAT	/* mi_lowat */
1227c478bd9Sstevel@tonic-gate };
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate static struct qinit spppcomp_rinit = {
125*c4d76aa4SToomas Soome 	spppcomp_rput,		/* qi_putp */
126*c4d76aa4SToomas Soome 	spppcomp_rsrv,		/* qi_srvp */
1277c478bd9Sstevel@tonic-gate 	spppcomp_open,		/* qi_qopen */
1287c478bd9Sstevel@tonic-gate 	spppcomp_close,		/* qi_qclose */
1297c478bd9Sstevel@tonic-gate 	NULL,			/* qi_qadmin */
1307c478bd9Sstevel@tonic-gate 	&spppcomp_modinfo,	/* qi_minfo */
1317c478bd9Sstevel@tonic-gate 	NULL			/* qi_mstat */
1327c478bd9Sstevel@tonic-gate };
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate static struct qinit spppcomp_winit = {
135*c4d76aa4SToomas Soome 	spppcomp_wput,		/* qi_putp */
136*c4d76aa4SToomas Soome 	spppcomp_wsrv,		/* qi_srvp */
1377c478bd9Sstevel@tonic-gate 	NULL,			/* qi_qopen */
1387c478bd9Sstevel@tonic-gate 	NULL,			/* qi_qclose */
1397c478bd9Sstevel@tonic-gate 	NULL,			/* qi_qadmin */
1407c478bd9Sstevel@tonic-gate 	&spppcomp_modinfo,	/* qi_minfo */
1417c478bd9Sstevel@tonic-gate 	NULL			/* qi_mstat */
1427c478bd9Sstevel@tonic-gate };
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate struct streamtab spppcomp_tab = {
1457c478bd9Sstevel@tonic-gate 	&spppcomp_rinit,	/* st_rdinit */
1467c478bd9Sstevel@tonic-gate 	&spppcomp_winit,	/* st_wrinit */
1477c478bd9Sstevel@tonic-gate 	NULL,			/* st_muxrinit */
1487c478bd9Sstevel@tonic-gate 	NULL			/* st_muxwinit */
1497c478bd9Sstevel@tonic-gate };
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate /* Set non-zero to debug algorithm-specific problems alone. */
1527c478bd9Sstevel@tonic-gate #define	ALG_DEBUG	0
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate #define	MAX_IPHLEN	(0x0f << 2)
1557c478bd9Sstevel@tonic-gate #define	MAX_TCPHLEN	(0x0f << 2)
1567c478bd9Sstevel@tonic-gate #define	MAX_TCPIPHLEN	(MAX_IPHLEN + MAX_TCPHLEN) /* max TCP/IP header size */
1577c478bd9Sstevel@tonic-gate #define	MAX_VJHDR	(20)		/* max VJ compressed header size (?) */
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate #if 0
1607c478bd9Sstevel@tonic-gate #define	DBGSTART	CE_CONT, COMP_MOD_NAME "%d: "
1617c478bd9Sstevel@tonic-gate #define	CKDEBUG(x)	cmn_err x
1627c478bd9Sstevel@tonic-gate #else
1637c478bd9Sstevel@tonic-gate #define	DBGSTART	COMP_MOD_NAME "%d: "
1647c478bd9Sstevel@tonic-gate #define	CKDEBUG(x)	printf x
1657c478bd9Sstevel@tonic-gate #endif
1667c478bd9Sstevel@tonic-gate #define	CPDEBUG(x)	(IS_CP_KDEBUG(cp) ? CKDEBUG(x) : (void)0)
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate  * List of compressors we know about.
1707c478bd9Sstevel@tonic-gate  */
1717c478bd9Sstevel@tonic-gate #if DO_BSD_COMPRESS
1727c478bd9Sstevel@tonic-gate extern struct compressor ppp_bsd_compress;
1737c478bd9Sstevel@tonic-gate #endif
1747c478bd9Sstevel@tonic-gate #if DO_DEFLATE
1757c478bd9Sstevel@tonic-gate extern struct compressor ppp_deflate;
1767c478bd9Sstevel@tonic-gate extern struct compressor ppp_deflate_draft;
1777c478bd9Sstevel@tonic-gate #endif
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate struct compressor *ppp_compressors[] = {
1807c478bd9Sstevel@tonic-gate #if DO_BSD_COMPRESS
1817c478bd9Sstevel@tonic-gate 	&ppp_bsd_compress,
1827c478bd9Sstevel@tonic-gate #endif
1837c478bd9Sstevel@tonic-gate #if DO_DEFLATE
1847c478bd9Sstevel@tonic-gate 	&ppp_deflate,
1857c478bd9Sstevel@tonic-gate 	&ppp_deflate_draft,
1867c478bd9Sstevel@tonic-gate #endif
1877c478bd9Sstevel@tonic-gate 	NULL
1887c478bd9Sstevel@tonic-gate };
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate /*
1917c478bd9Sstevel@tonic-gate  * LCP_USE_DFLT() removed by James Carlson.  RFC 1661 section 6.6 has
1927c478bd9Sstevel@tonic-gate  * this to say on the topic:
1937c478bd9Sstevel@tonic-gate  *
1947c478bd9Sstevel@tonic-gate  *    The Address and Control fields MUST NOT be compressed when sending
1957c478bd9Sstevel@tonic-gate  *    any LCP packet.  This rule guarantees unambiguous recognition of
1967c478bd9Sstevel@tonic-gate  *    LCP packets.
1977c478bd9Sstevel@tonic-gate  */
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate static void	spppcomp_ioctl(queue_t *, mblk_t *, sppp_comp_t *);
2007c478bd9Sstevel@tonic-gate static int	spppcomp_mctl(queue_t *, mblk_t *);
2017c478bd9Sstevel@tonic-gate static mblk_t	*spppcomp_outpkt(queue_t *, mblk_t *);
2027c478bd9Sstevel@tonic-gate static mblk_t	*spppcomp_inpkt(queue_t *, mblk_t *);
2037c478bd9Sstevel@tonic-gate static int	spppcomp_kstat_update(kstat_t *, int);
2047c478bd9Sstevel@tonic-gate static void	comp_ccp(queue_t *, mblk_t *, sppp_comp_t *, boolean_t);
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate /*
2077c478bd9Sstevel@tonic-gate  * Values for checking inter-arrival times on interrupt stacks.  These
2087c478bd9Sstevel@tonic-gate  * are used to prevent CPU hogging in interrupt context.
2097c478bd9Sstevel@tonic-gate  */
2107c478bd9Sstevel@tonic-gate #define	MIN_ARRIVAL_TIME	5000000	/* interarrival time in nanoseconds */
2117c478bd9Sstevel@tonic-gate #define	MAX_FAST_ARRIVALS	10	/* maximum packet count */
2127c478bd9Sstevel@tonic-gate hrtime_t spppcomp_min_arrival = MIN_ARRIVAL_TIME;
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate static const char *kstats_names[] = {
2157c478bd9Sstevel@tonic-gate #ifdef SPCDEBUG_KSTATS_NAMES
2167c478bd9Sstevel@tonic-gate 	SPPPCOMP_KSTATS_NAMES,
2177c478bd9Sstevel@tonic-gate 	SPCDEBUG_KSTATS_NAMES
2187c478bd9Sstevel@tonic-gate #else
2197c478bd9Sstevel@tonic-gate 	SPPPCOMP_KSTATS_NAMES
2207c478bd9Sstevel@tonic-gate #endif
2217c478bd9Sstevel@tonic-gate };
2227c478bd9Sstevel@tonic-gate static const char *kstats64_names[] = { SPPPCOMP_KSTATS64_NAMES };
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate /*
2257c478bd9Sstevel@tonic-gate  * spppcomp_open()
2267c478bd9Sstevel@tonic-gate  *
2277c478bd9Sstevel@tonic-gate  * MT-Perimeters:
2287c478bd9Sstevel@tonic-gate  *    exclusive inner.
2297c478bd9Sstevel@tonic-gate  *
2307c478bd9Sstevel@tonic-gate  * Description:
2317c478bd9Sstevel@tonic-gate  *    Common open procedure for module.
2327c478bd9Sstevel@tonic-gate  */
2337c478bd9Sstevel@tonic-gate /* ARGSUSED */
2347c478bd9Sstevel@tonic-gate static int
spppcomp_open(queue_t * q,dev_t * devp,int flag,int sflag,cred_t * credp)2357c478bd9Sstevel@tonic-gate spppcomp_open(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *credp)
2367c478bd9Sstevel@tonic-gate {
2377c478bd9Sstevel@tonic-gate 	sppp_comp_t	*cp;
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	if (q->q_ptr != NULL) {
2407c478bd9Sstevel@tonic-gate 		return (0);
2417c478bd9Sstevel@tonic-gate 	}
2427c478bd9Sstevel@tonic-gate 	if (sflag != MODOPEN) {
2437c478bd9Sstevel@tonic-gate 		return (EINVAL);
2447c478bd9Sstevel@tonic-gate 	}
245f53eecf5SJames Carlson 	cp = kmem_zalloc(sizeof (sppp_comp_t), KM_SLEEP);
2467c478bd9Sstevel@tonic-gate 	q->q_ptr = WR(q)->q_ptr = (caddr_t)cp;
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	cp->cp_mru = PPP_MRU;
2497c478bd9Sstevel@tonic-gate 	cp->cp_mtu = PPP_MTU;
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	mutex_init(&cp->cp_pair_lock, NULL, MUTEX_DRIVER, NULL);
2527c478bd9Sstevel@tonic-gate 	vj_compress_init(&cp->cp_vj, -1);
2537c478bd9Sstevel@tonic-gate 	cp->cp_nxslots = -1;
2547c478bd9Sstevel@tonic-gate 	cp->cp_effort = -1;
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate 	qprocson(q);
2577c478bd9Sstevel@tonic-gate 	return (0);
2587c478bd9Sstevel@tonic-gate }
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate /*
2617c478bd9Sstevel@tonic-gate  * spppcomp_close()
2627c478bd9Sstevel@tonic-gate  *
2637c478bd9Sstevel@tonic-gate  * MT-Perimeters:
2647c478bd9Sstevel@tonic-gate  *    exclusive inner.
2657c478bd9Sstevel@tonic-gate  *
2667c478bd9Sstevel@tonic-gate  * Description:
2677c478bd9Sstevel@tonic-gate  *    Common close procedure for module.
2687c478bd9Sstevel@tonic-gate  */
2697c478bd9Sstevel@tonic-gate /* ARGSUSED */
2707c478bd9Sstevel@tonic-gate static int
spppcomp_close(queue_t * q,int flag,cred_t * credp)2717c478bd9Sstevel@tonic-gate spppcomp_close(queue_t *q, int flag, cred_t *credp)
2727c478bd9Sstevel@tonic-gate {
273f53eecf5SJames Carlson 	sppp_comp_t	*cp = q->q_ptr;
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	qprocsoff(q);
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	CPDEBUG((DBGSTART "close flags=0x%b\n",
2787c478bd9Sstevel@tonic-gate 	    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1), cp->cp_flags,
2797c478bd9Sstevel@tonic-gate 	    CP_FLAGSSTR));
2807c478bd9Sstevel@tonic-gate 	mutex_destroy(&cp->cp_pair_lock);
2817c478bd9Sstevel@tonic-gate 	if (cp->cp_kstats) {
2827c478bd9Sstevel@tonic-gate 		ASSERT(IS_CP_HASUNIT(cp));
2837c478bd9Sstevel@tonic-gate 		kstat_delete(cp->cp_kstats);
2847c478bd9Sstevel@tonic-gate 	}
2857c478bd9Sstevel@tonic-gate 	if (cp->cp_xstate != NULL) {
2867c478bd9Sstevel@tonic-gate 		(*cp->cp_xcomp->comp_free)(cp->cp_xstate);
2877c478bd9Sstevel@tonic-gate 	}
2887c478bd9Sstevel@tonic-gate 	if (cp->cp_rstate != NULL) {
2897c478bd9Sstevel@tonic-gate 		(*cp->cp_rcomp->decomp_free)(cp->cp_rstate);
2907c478bd9Sstevel@tonic-gate 	}
2917c478bd9Sstevel@tonic-gate 	kmem_free(cp, sizeof (sppp_comp_t));
2927c478bd9Sstevel@tonic-gate 	q->q_ptr = WR(q)->q_ptr = NULL;
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	return (0);
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate /*
2987c478bd9Sstevel@tonic-gate  * spppcomp_wput()
2997c478bd9Sstevel@tonic-gate  *
3007c478bd9Sstevel@tonic-gate  * MT-Perimeters:
3017c478bd9Sstevel@tonic-gate  *    exclusive inner.
3027c478bd9Sstevel@tonic-gate  *
3037c478bd9Sstevel@tonic-gate  * Description:
3047c478bd9Sstevel@tonic-gate  *    Write-side put procedure.  Packets from above us arrive here.
3057c478bd9Sstevel@tonic-gate  *
3067c478bd9Sstevel@tonic-gate  *	The data handling logic is a little tricky here.  We defer to
3077c478bd9Sstevel@tonic-gate  *	the service routine if q_first isn't NULL (to preserve message
3087c478bd9Sstevel@tonic-gate  *	ordering after deferring a previous message), bcanputnext() is
3097c478bd9Sstevel@tonic-gate  *	FALSE (to handle flow control), or we need a lot of processing
3107c478bd9Sstevel@tonic-gate  *	and we're in an interrupt context (on the theory that we're
3117c478bd9Sstevel@tonic-gate  *	already on a very long call stack at that point).  Since many
3127c478bd9Sstevel@tonic-gate  *	callers will be in a non-interrupt context, this means that
3137c478bd9Sstevel@tonic-gate  *	most processing will be performed here in-line, and deferral
3147c478bd9Sstevel@tonic-gate  *	occurs only when necessary.
3157c478bd9Sstevel@tonic-gate  */
316*c4d76aa4SToomas Soome static int
spppcomp_wput(queue_t * q,mblk_t * mp)3177c478bd9Sstevel@tonic-gate spppcomp_wput(queue_t *q, mblk_t *mp)
3187c478bd9Sstevel@tonic-gate {
319f53eecf5SJames Carlson 	sppp_comp_t *cp = q->q_ptr;
3207c478bd9Sstevel@tonic-gate 	int flag;
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 	switch (MTYPE(mp)) {
3237c478bd9Sstevel@tonic-gate 	case M_DATA:
3247c478bd9Sstevel@tonic-gate 		if (q->q_first != NULL || !bcanputnext(q, mp->b_band) ||
3257c478bd9Sstevel@tonic-gate 		    ((cp->cp_flags & (COMP_VJC|CCP_COMP_RUN)) &&
326002c70ffScarlsonj 		    servicing_interrupt())) {
3277c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
3287c478bd9Sstevel@tonic-gate 			cp->cp_out_queued++;
3297c478bd9Sstevel@tonic-gate #endif
330f53eecf5SJames Carlson 			if (!putq(q, mp))
331f53eecf5SJames Carlson 				freemsg(mp);
3327c478bd9Sstevel@tonic-gate 		} else {
3337c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
3347c478bd9Sstevel@tonic-gate 			cp->cp_out_handled++;
3357c478bd9Sstevel@tonic-gate #endif
336f53eecf5SJames Carlson 			if ((mp = spppcomp_outpkt(q, mp)) != NULL)
3377c478bd9Sstevel@tonic-gate 				putnext(q, mp);
3387c478bd9Sstevel@tonic-gate 		}
3397c478bd9Sstevel@tonic-gate 		break;
3407c478bd9Sstevel@tonic-gate 	case M_IOCTL:
3417c478bd9Sstevel@tonic-gate 		spppcomp_ioctl(q, mp, cp);
3427c478bd9Sstevel@tonic-gate 		break;
3437c478bd9Sstevel@tonic-gate 	case M_CTL:
3447c478bd9Sstevel@tonic-gate 		mutex_enter(&cp->cp_pair_lock);
3457c478bd9Sstevel@tonic-gate 		flag = spppcomp_mctl(q, mp);
3467c478bd9Sstevel@tonic-gate 		mutex_exit(&cp->cp_pair_lock);
3477c478bd9Sstevel@tonic-gate 		if (flag != 0)
3487c478bd9Sstevel@tonic-gate 			putnext(q, mp);
3497c478bd9Sstevel@tonic-gate 		else
3507c478bd9Sstevel@tonic-gate 			freemsg(mp);
3517c478bd9Sstevel@tonic-gate 		break;
3527c478bd9Sstevel@tonic-gate 	case M_FLUSH:
3537c478bd9Sstevel@tonic-gate 		CPDEBUG((DBGSTART "wput M_FLUSH (0x%x) flags=0x%b\n",
3547c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
3557c478bd9Sstevel@tonic-gate 		    *mp->b_rptr, cp->cp_flags,	CP_FLAGSSTR));
3567c478bd9Sstevel@tonic-gate 		/*
3577c478bd9Sstevel@tonic-gate 		 * Just discard pending data.  For CCP, any compressor
3587c478bd9Sstevel@tonic-gate 		 * dictionary sequencing problems caused by this will
3597c478bd9Sstevel@tonic-gate 		 * have to be handled by the compression protocol in
3607c478bd9Sstevel@tonic-gate 		 * use.  For VJ, we need to tell the compressor to
3617c478bd9Sstevel@tonic-gate 		 * start over.
3627c478bd9Sstevel@tonic-gate 		 */
3637c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr & FLUSHW) {
3647c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->cp_pair_lock);
3657c478bd9Sstevel@tonic-gate 			flushq(q, FLUSHDATA);
3667c478bd9Sstevel@tonic-gate 			vj_compress_init(&cp->cp_vj, cp->cp_nxslots);
3677c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->cp_pair_lock);
3687c478bd9Sstevel@tonic-gate 		}
3697c478bd9Sstevel@tonic-gate 		putnext(q, mp);
3707c478bd9Sstevel@tonic-gate 		break;
3717c478bd9Sstevel@tonic-gate 	default:
372f53eecf5SJames Carlson 		if (bcanputnext(q, mp->b_band))
373f53eecf5SJames Carlson 			putnext(q, mp);
374f53eecf5SJames Carlson 		else if (!putq(q, mp))
375f53eecf5SJames Carlson 			freemsg(mp);
3767c478bd9Sstevel@tonic-gate 		break;
3777c478bd9Sstevel@tonic-gate 	}
378*c4d76aa4SToomas Soome 	return (0);
3797c478bd9Sstevel@tonic-gate }
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate /*
3827c478bd9Sstevel@tonic-gate  * spppcomp_wsrv()
3837c478bd9Sstevel@tonic-gate  *
3847c478bd9Sstevel@tonic-gate  * MT-Perimeters:
3857c478bd9Sstevel@tonic-gate  *    exclusive inner
3867c478bd9Sstevel@tonic-gate  *
3877c478bd9Sstevel@tonic-gate  * Description:
3887c478bd9Sstevel@tonic-gate  *    Write-side service procedure.
3897c478bd9Sstevel@tonic-gate  */
390*c4d76aa4SToomas Soome static int
spppcomp_wsrv(queue_t * q)3917c478bd9Sstevel@tonic-gate spppcomp_wsrv(queue_t *q)
3927c478bd9Sstevel@tonic-gate {
3937c478bd9Sstevel@tonic-gate 	mblk_t		*mp;
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 	while ((mp = getq(q)) != NULL) {
3967c478bd9Sstevel@tonic-gate 		/*
3977c478bd9Sstevel@tonic-gate 		 * If the module below us is flow-controlled, then put
3987c478bd9Sstevel@tonic-gate 		 * this message back on the queue again.
3997c478bd9Sstevel@tonic-gate 		 */
4007c478bd9Sstevel@tonic-gate 		if (!bcanputnext(q, mp->b_band)) {
4017c478bd9Sstevel@tonic-gate 			(void) putbq(q, mp);
4027c478bd9Sstevel@tonic-gate 			break;
4037c478bd9Sstevel@tonic-gate 		}
404f53eecf5SJames Carlson 		if (MTYPE(mp) != M_DATA ||
405f53eecf5SJames Carlson 		    (mp = spppcomp_outpkt(q, mp)) != NULL)
4067c478bd9Sstevel@tonic-gate 			putnext(q, mp);
4077c478bd9Sstevel@tonic-gate 	}
408*c4d76aa4SToomas Soome 	return (0);
4097c478bd9Sstevel@tonic-gate }
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate /*
4127c478bd9Sstevel@tonic-gate  * spppcomp_outpkt()
4137c478bd9Sstevel@tonic-gate  *
4147c478bd9Sstevel@tonic-gate  * MT-Perimeters:
4157c478bd9Sstevel@tonic-gate  *    exclusive inner
4167c478bd9Sstevel@tonic-gate  *
4177c478bd9Sstevel@tonic-gate  * Description:
4187c478bd9Sstevel@tonic-gate  *    Process outgoing packet.  Returns new mblk_t pointer on success
4197c478bd9Sstevel@tonic-gate  *    (caller should do putnext through q), NULL on failure (packet has
4207c478bd9Sstevel@tonic-gate  *    been discarded).
4217c478bd9Sstevel@tonic-gate  */
4227c478bd9Sstevel@tonic-gate static mblk_t *
spppcomp_outpkt(queue_t * q,mblk_t * mp)4237c478bd9Sstevel@tonic-gate spppcomp_outpkt(queue_t *q, mblk_t *mp)
4247c478bd9Sstevel@tonic-gate {
4257c478bd9Sstevel@tonic-gate 	mblk_t		*zmp;
4267c478bd9Sstevel@tonic-gate 	int		len;
4277c478bd9Sstevel@tonic-gate 	ushort_t	proto;
428f53eecf5SJames Carlson 	sppp_comp_t	*cp = q->q_ptr;
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 	/*
4317c478bd9Sstevel@tonic-gate 	 * If the entire data size of the mblk is less than the length of the
4327c478bd9Sstevel@tonic-gate 	 * PPP header, then free it. We can't do much with such message anyway,
4337c478bd9Sstevel@tonic-gate 	 * since we can't determine what the PPP protocol is.
4347c478bd9Sstevel@tonic-gate 	 */
4357c478bd9Sstevel@tonic-gate 	len = msgsize(mp);
4367c478bd9Sstevel@tonic-gate 	if (MBLKL(mp) < PPP_HDRLEN) {
4377c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
4387c478bd9Sstevel@tonic-gate 		mutex_enter(&cp->cp_pair_lock);
4397c478bd9Sstevel@tonic-gate 		cp->cp_omsg_pull++;
4407c478bd9Sstevel@tonic-gate 		mutex_exit(&cp->cp_pair_lock);
4417c478bd9Sstevel@tonic-gate #endif
4427c478bd9Sstevel@tonic-gate 		zmp = msgpullup(mp, PPP_HDRLEN);
4437c478bd9Sstevel@tonic-gate 		freemsg(mp);
4447c478bd9Sstevel@tonic-gate 		if ((mp = zmp) == NULL)
4457c478bd9Sstevel@tonic-gate 			goto msg_oerror;
4467c478bd9Sstevel@tonic-gate 	}
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate 	proto = PPP_PROTOCOL(mp->b_rptr);
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate 	/*
4517c478bd9Sstevel@tonic-gate 	 * Do VJ compression if requested.
4527c478bd9Sstevel@tonic-gate 	 */
4537c478bd9Sstevel@tonic-gate 	if (proto == PPP_IP && IS_COMP_VJC(cp) &&
4547c478bd9Sstevel@tonic-gate 	    MSG_BYTE(mp, PPP_HDRLEN+offsetof(struct ip, ip_p)) ==
4557c478bd9Sstevel@tonic-gate 	    IPPROTO_TCP) {
4567c478bd9Sstevel@tonic-gate 		uchar_t		*vjhdr;
4577c478bd9Sstevel@tonic-gate 		int		type;
4587c478bd9Sstevel@tonic-gate 		uint32_t	indata[(PPP_HDRLEN+MAX_TCPIPHLEN) /
4597c478bd9Sstevel@tonic-gate 		    sizeof (uint32_t)];
4607c478bd9Sstevel@tonic-gate 		uchar_t		*dp;
4617c478bd9Sstevel@tonic-gate 		int		tocopy, copied;
4627c478bd9Sstevel@tonic-gate 		mblk_t		*fmb;
4637c478bd9Sstevel@tonic-gate 		void		*srcp;
4647c478bd9Sstevel@tonic-gate 		int		thislen;
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 		tocopy = copied = MIN(len, sizeof (indata));
4687c478bd9Sstevel@tonic-gate 		/*
4697c478bd9Sstevel@tonic-gate 		 * If we can alter this dblk, and there's enough data
4707c478bd9Sstevel@tonic-gate 		 * here to work with, and it's nicely aligned, then
4717c478bd9Sstevel@tonic-gate 		 * avoid the data copy.
4727c478bd9Sstevel@tonic-gate 		 */
4737c478bd9Sstevel@tonic-gate 		if (DB_REF(mp) == 1 && MBLKL(mp) >= tocopy &&
4747c478bd9Sstevel@tonic-gate 		    ((uintptr_t)mp->b_rptr & 3) == 0) {
4757c478bd9Sstevel@tonic-gate 			/* Save off the address/control */
4767c478bd9Sstevel@tonic-gate 			indata[0] = *(uint32_t *)mp->b_rptr;
4777c478bd9Sstevel@tonic-gate 			srcp = (void *)(mp->b_rptr + PPP_HDRLEN);
4787c478bd9Sstevel@tonic-gate 		} else {
4797c478bd9Sstevel@tonic-gate 			fmb = mp;
4807c478bd9Sstevel@tonic-gate 			dp = (uchar_t *)indata;
4817c478bd9Sstevel@tonic-gate 			while (tocopy > 0) {
4827c478bd9Sstevel@tonic-gate 				thislen = MBLKL(fmb);
4837c478bd9Sstevel@tonic-gate 				if (tocopy > thislen) {
4847c478bd9Sstevel@tonic-gate 					bcopy(fmb->b_rptr, dp, thislen);
4857c478bd9Sstevel@tonic-gate 					dp += thislen;
4867c478bd9Sstevel@tonic-gate 					tocopy -= thislen;
4877c478bd9Sstevel@tonic-gate 					fmb = fmb->b_cont;
4887c478bd9Sstevel@tonic-gate 				} else {
4897c478bd9Sstevel@tonic-gate 					bcopy(fmb->b_rptr, dp, tocopy);
4907c478bd9Sstevel@tonic-gate 					break;
4917c478bd9Sstevel@tonic-gate 				}
4927c478bd9Sstevel@tonic-gate 			}
4937c478bd9Sstevel@tonic-gate 			srcp = (void *)(indata + PPP_HDRLEN/sizeof (*indata));
4947c478bd9Sstevel@tonic-gate 		}
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate 		type = vj_compress_tcp((struct ip *)srcp, len - PPP_HDRLEN,
4977c478bd9Sstevel@tonic-gate 		    &cp->cp_vj, IS_COMP_VJCCID(cp), &vjhdr);
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate 		/*
5007c478bd9Sstevel@tonic-gate 		 * If we're going to modify this packet, then we can't modify
5017c478bd9Sstevel@tonic-gate 		 * someone else's data.  Copy instead.
5027c478bd9Sstevel@tonic-gate 		 *
5037c478bd9Sstevel@tonic-gate 		 * (It would be nice to be able to avoid this data copy if CCP
5047c478bd9Sstevel@tonic-gate 		 * is also enabled.  That would require extensive
5057c478bd9Sstevel@tonic-gate 		 * modifications to the compression code.  Users should be
5067c478bd9Sstevel@tonic-gate 		 * told to disable VJ compression when using CCP.)
5077c478bd9Sstevel@tonic-gate 		 */
5087c478bd9Sstevel@tonic-gate 		if (type != TYPE_IP && DB_REF(mp) > 1) {
5097c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
5107c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->cp_pair_lock);
5117c478bd9Sstevel@tonic-gate 			cp->cp_omsg_dcopy++;
5127c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->cp_pair_lock);
5137c478bd9Sstevel@tonic-gate #endif
5147c478bd9Sstevel@tonic-gate 			/* Copy just altered portion. */
5157c478bd9Sstevel@tonic-gate 			zmp = msgpullup(mp, copied);
5167c478bd9Sstevel@tonic-gate 			freemsg(mp);
5177c478bd9Sstevel@tonic-gate 			if ((mp = zmp) == NULL)
5187c478bd9Sstevel@tonic-gate 				goto msg_oerror;
5197c478bd9Sstevel@tonic-gate 		}
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate 		switch (type) {
5227c478bd9Sstevel@tonic-gate 		case TYPE_UNCOMPRESSED_TCP:
5237c478bd9Sstevel@tonic-gate 			mp->b_rptr[3] = proto = PPP_VJC_UNCOMP;
5247c478bd9Sstevel@tonic-gate 			/* No need to update if it was done in place. */
5257c478bd9Sstevel@tonic-gate 			if (srcp ==
5267c478bd9Sstevel@tonic-gate 			    (void *)(indata + PPP_HDRLEN / sizeof (*indata))) {
5277c478bd9Sstevel@tonic-gate 				thislen = PPP_HDRLEN +
5287c478bd9Sstevel@tonic-gate 				    offsetof(struct ip, ip_p);
5297c478bd9Sstevel@tonic-gate 				zmp = mp;
5307c478bd9Sstevel@tonic-gate 				while (zmp != NULL) {
5317c478bd9Sstevel@tonic-gate 					if (MBLKL(zmp) > thislen) {
5327c478bd9Sstevel@tonic-gate 						zmp->b_rptr[thislen] =
5337c478bd9Sstevel@tonic-gate 						    ((struct ip *)srcp)->ip_p;
5347c478bd9Sstevel@tonic-gate 						break;
5357c478bd9Sstevel@tonic-gate 					}
5367c478bd9Sstevel@tonic-gate 					thislen -= MBLKL(zmp);
5377c478bd9Sstevel@tonic-gate 					zmp = zmp->b_cont;
5387c478bd9Sstevel@tonic-gate 				}
5397c478bd9Sstevel@tonic-gate 			}
5407c478bd9Sstevel@tonic-gate 			break;
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 		case TYPE_COMPRESSED_TCP:
5437c478bd9Sstevel@tonic-gate 			/* Calculate amount to remove from front */
5447c478bd9Sstevel@tonic-gate 			thislen = vjhdr - (uchar_t *)srcp;
5457c478bd9Sstevel@tonic-gate 			ASSERT(thislen >= 0);
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate 			/* Try to do a cheap adjmsg by arithmetic first. */
5487c478bd9Sstevel@tonic-gate 			dp = mp->b_rptr + thislen;
5497c478bd9Sstevel@tonic-gate 			if (dp > mp->b_wptr) {
5507c478bd9Sstevel@tonic-gate 				if (!adjmsg(mp, thislen)) {
5517c478bd9Sstevel@tonic-gate 					freemsg(mp);
5527c478bd9Sstevel@tonic-gate 					goto msg_oerror;
5537c478bd9Sstevel@tonic-gate 				}
5547c478bd9Sstevel@tonic-gate 				dp = mp->b_rptr;
5557c478bd9Sstevel@tonic-gate 			}
5567c478bd9Sstevel@tonic-gate 
5577c478bd9Sstevel@tonic-gate 			/*
5587c478bd9Sstevel@tonic-gate 			 * Now make sure first block is big enough to
5597c478bd9Sstevel@tonic-gate 			 * receive modified data.  If we modified in
5607c478bd9Sstevel@tonic-gate 			 * place, then no need to check or copy.
5617c478bd9Sstevel@tonic-gate 			 */
5627c478bd9Sstevel@tonic-gate 			copied -= thislen;
5637c478bd9Sstevel@tonic-gate 			ASSERT(copied >= PPP_HDRLEN);
5647c478bd9Sstevel@tonic-gate 			if (srcp !=
5657c478bd9Sstevel@tonic-gate 			    (void *)(indata + PPP_HDRLEN / sizeof (*indata)))
5667c478bd9Sstevel@tonic-gate 				copied = 0;
5677c478bd9Sstevel@tonic-gate 			mp->b_rptr = dp;
5687c478bd9Sstevel@tonic-gate 			if (MBLKL(mp) < copied) {
5697c478bd9Sstevel@tonic-gate 				zmp = msgpullup(mp, copied);
5707c478bd9Sstevel@tonic-gate 				freemsg(mp);
5717c478bd9Sstevel@tonic-gate 				if ((mp = zmp) == NULL)
5727c478bd9Sstevel@tonic-gate 					goto msg_oerror;
5737c478bd9Sstevel@tonic-gate 				dp = mp->b_rptr;
5747c478bd9Sstevel@tonic-gate 			}
5757c478bd9Sstevel@tonic-gate 
5767c478bd9Sstevel@tonic-gate 			*dp++ = ((uchar_t *)indata)[0];	/* address */
5777c478bd9Sstevel@tonic-gate 			*dp++ = ((uchar_t *)indata)[1];	/* control  */
5787c478bd9Sstevel@tonic-gate 			*dp++ = 0;			/* protocol */
5797c478bd9Sstevel@tonic-gate 			*dp++ = proto = PPP_VJC_COMP;	/* protocol */
5807c478bd9Sstevel@tonic-gate 			copied -= PPP_HDRLEN;
5817c478bd9Sstevel@tonic-gate 			if (copied > 0) {
5827c478bd9Sstevel@tonic-gate 				bcopy(vjhdr, dp, copied);
5837c478bd9Sstevel@tonic-gate 			}
5847c478bd9Sstevel@tonic-gate 			break;
5857c478bd9Sstevel@tonic-gate 		}
5867c478bd9Sstevel@tonic-gate 	}
5877c478bd9Sstevel@tonic-gate 
5887c478bd9Sstevel@tonic-gate 	/*
5897c478bd9Sstevel@tonic-gate 	 * Do packet compression if enabled.
5907c478bd9Sstevel@tonic-gate 	 */
5917c478bd9Sstevel@tonic-gate 	if (proto == PPP_CCP) {
5927c478bd9Sstevel@tonic-gate 		/*
5937c478bd9Sstevel@tonic-gate 		 * Handle any negotiation packets by changing compressor
5947c478bd9Sstevel@tonic-gate 		 * state.  Doing this here rather than with an ioctl keeps
5957c478bd9Sstevel@tonic-gate 		 * the negotiation and the data flow in sync.
5967c478bd9Sstevel@tonic-gate 		 */
5977c478bd9Sstevel@tonic-gate 		mutex_enter(&cp->cp_pair_lock);
5987c478bd9Sstevel@tonic-gate 		comp_ccp(q, mp, cp, B_FALSE);
5997c478bd9Sstevel@tonic-gate 		mutex_exit(&cp->cp_pair_lock);
6007c478bd9Sstevel@tonic-gate 	} else if (proto != PPP_LCP && IS_CCP_COMP_RUN(cp) &&
601002c70ffScarlsonj 	    IS_CCP_ISUP(cp) && cp->cp_xstate != NULL) {
6027c478bd9Sstevel@tonic-gate 		mblk_t	*cmp = NULL;
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate 		len = msgsize(mp);
6057c478bd9Sstevel@tonic-gate 		len = (*cp->cp_xcomp->compress)(cp->cp_xstate, &cmp, mp, len,
606002c70ffScarlsonj 		    cp->cp_mtu + PPP_HDRLEN);
6077c478bd9Sstevel@tonic-gate 
6087c478bd9Sstevel@tonic-gate 		if (cmp != NULL) {
6097c478bd9Sstevel@tonic-gate 			/* Success!  Discard uncompressed version */
6107c478bd9Sstevel@tonic-gate 			cmp->b_band = mp->b_band;
6117c478bd9Sstevel@tonic-gate 			freemsg(mp);
6127c478bd9Sstevel@tonic-gate 			mp = cmp;
6137c478bd9Sstevel@tonic-gate 		}
6147c478bd9Sstevel@tonic-gate 		if (len < 0) {
6157c478bd9Sstevel@tonic-gate 			/*
6167c478bd9Sstevel@tonic-gate 			 * Compressor failure; must discard this
6177c478bd9Sstevel@tonic-gate 			 * packet because the compressor dictionary is
6187c478bd9Sstevel@tonic-gate 			 * now corrupt.
6197c478bd9Sstevel@tonic-gate 			 */
6207c478bd9Sstevel@tonic-gate 			freemsg(mp);
6217c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->cp_pair_lock);
6227c478bd9Sstevel@tonic-gate 			cp->cp_stats.ppp_oerrors++;
6237c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->cp_pair_lock);
6247c478bd9Sstevel@tonic-gate 			(void) putnextctl1(RD(q), M_CTL, PPPCTL_OERROR);
6257c478bd9Sstevel@tonic-gate 			return (NULL);
6267c478bd9Sstevel@tonic-gate 		}
6277c478bd9Sstevel@tonic-gate 	}
6287c478bd9Sstevel@tonic-gate 
6297c478bd9Sstevel@tonic-gate 	/*
6307c478bd9Sstevel@tonic-gate 	 * If either address and control field compression or protocol field
6317c478bd9Sstevel@tonic-gate 	 * compression is enabled, then we'll need a writable packet.  Copy if
6327c478bd9Sstevel@tonic-gate 	 * necessary.
6337c478bd9Sstevel@tonic-gate 	 */
6347c478bd9Sstevel@tonic-gate 	if ((cp->cp_flags & (COMP_AC|COMP_PROT)) && DB_REF(mp) > 1) {
6357c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
6367c478bd9Sstevel@tonic-gate 		mutex_enter(&cp->cp_pair_lock);
6377c478bd9Sstevel@tonic-gate 		cp->cp_omsg_dcopy++;
6387c478bd9Sstevel@tonic-gate 		mutex_exit(&cp->cp_pair_lock);
6397c478bd9Sstevel@tonic-gate #endif
6407c478bd9Sstevel@tonic-gate 		zmp = copymsg(mp);
6417c478bd9Sstevel@tonic-gate 		freemsg(mp);
6427c478bd9Sstevel@tonic-gate 		if ((mp = zmp) == NULL)
6437c478bd9Sstevel@tonic-gate 			goto msg_oerror;
6447c478bd9Sstevel@tonic-gate 	}
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate 	/*
6477c478bd9Sstevel@tonic-gate 	 * Do address/control and protocol compression if enabled.
6487c478bd9Sstevel@tonic-gate 	 */
6497c478bd9Sstevel@tonic-gate 	if (IS_COMP_AC(cp) && (proto != PPP_LCP)) {
6507c478bd9Sstevel@tonic-gate 		mp->b_rptr += 2;	/* drop address & ctrl fields */
6517c478bd9Sstevel@tonic-gate 		/*
6527c478bd9Sstevel@tonic-gate 		 * Protocol field compression omits the first byte if
6537c478bd9Sstevel@tonic-gate 		 * it would be 0x00, thus the check for < 0x100.
6547c478bd9Sstevel@tonic-gate 		 */
6557c478bd9Sstevel@tonic-gate 		if (proto < 0x100 && IS_COMP_PROT(cp)) {
6567c478bd9Sstevel@tonic-gate 			++mp->b_rptr;	/* drop high protocol byte */
6577c478bd9Sstevel@tonic-gate 		}
6587c478bd9Sstevel@tonic-gate 	} else if ((proto < 0x100) && IS_COMP_PROT(cp)) {
6597c478bd9Sstevel@tonic-gate 		/*
6607c478bd9Sstevel@tonic-gate 		 * shuffle up the address & ctrl fields
6617c478bd9Sstevel@tonic-gate 		 */
6627c478bd9Sstevel@tonic-gate 		mp->b_rptr[2] = mp->b_rptr[1];
6637c478bd9Sstevel@tonic-gate 		mp->b_rptr[1] = mp->b_rptr[0];
6647c478bd9Sstevel@tonic-gate 		++mp->b_rptr;
6657c478bd9Sstevel@tonic-gate 	}
6667c478bd9Sstevel@tonic-gate 	mutex_enter(&cp->cp_pair_lock);
6677c478bd9Sstevel@tonic-gate 	cp->cp_stats.ppp_opackets++;
6687c478bd9Sstevel@tonic-gate 	cp->cp_stats.ppp_obytes += msgsize(mp);
6697c478bd9Sstevel@tonic-gate 	mutex_exit(&cp->cp_pair_lock);
6707c478bd9Sstevel@tonic-gate 
6717c478bd9Sstevel@tonic-gate 	CPDEBUG((DBGSTART "send (%ld bytes) flags=0x%b\n",
6727c478bd9Sstevel@tonic-gate 	    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1), msgsize(mp),
6737c478bd9Sstevel@tonic-gate 	    cp->cp_flags, CP_FLAGSSTR));
6747c478bd9Sstevel@tonic-gate 	return (mp);
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate msg_oerror:
6777c478bd9Sstevel@tonic-gate 	mutex_enter(&cp->cp_pair_lock);
6787c478bd9Sstevel@tonic-gate 	cp->cp_stats.ppp_oerrors++;
6797c478bd9Sstevel@tonic-gate 	mutex_exit(&cp->cp_pair_lock);
6807c478bd9Sstevel@tonic-gate 	(void) putnextctl1(RD(q), M_CTL, PPPCTL_OERROR);
6817c478bd9Sstevel@tonic-gate 	return (NULL);
6827c478bd9Sstevel@tonic-gate }
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate /*
6857c478bd9Sstevel@tonic-gate  * spppcomp_inner_ioctl()
6867c478bd9Sstevel@tonic-gate  *
6877c478bd9Sstevel@tonic-gate  * MT-Perimeters:
6887c478bd9Sstevel@tonic-gate  *    exclusive inner; queue pair lock held.
6897c478bd9Sstevel@tonic-gate  *
6907c478bd9Sstevel@tonic-gate  * Description:
6917c478bd9Sstevel@tonic-gate  *	Called by spppcomp_ioctl to handle state-affecting ioctls.
6927c478bd9Sstevel@tonic-gate  *	Returns -1 if caller should do putnext, 0 for miocack, or >0
6937c478bd9Sstevel@tonic-gate  *	for miocnak.  Must *NOT* do putnext in this routine, since
6947c478bd9Sstevel@tonic-gate  *	lock is held here.
6957c478bd9Sstevel@tonic-gate  */
6967c478bd9Sstevel@tonic-gate static int
spppcomp_inner_ioctl(queue_t * q,mblk_t * mp)6977c478bd9Sstevel@tonic-gate spppcomp_inner_ioctl(queue_t *q, mblk_t *mp)
6987c478bd9Sstevel@tonic-gate {
699f53eecf5SJames Carlson 	sppp_comp_t	*cp = q->q_ptr;
7007c478bd9Sstevel@tonic-gate 	int		flags;
7017c478bd9Sstevel@tonic-gate 	int		mask;
7027c478bd9Sstevel@tonic-gate 	int		rc;
7037c478bd9Sstevel@tonic-gate 	int		len;
7047c478bd9Sstevel@tonic-gate 	int		cmd;
7057c478bd9Sstevel@tonic-gate 	int		nxslots;
7067c478bd9Sstevel@tonic-gate 	int		nrslots;
7077c478bd9Sstevel@tonic-gate 	int		val;
7087c478bd9Sstevel@tonic-gate 	uchar_t		*opt_data;
7097c478bd9Sstevel@tonic-gate 	uint32_t	opt_len;
7107c478bd9Sstevel@tonic-gate 	struct compressor **comp;
7117c478bd9Sstevel@tonic-gate 	struct compressor *ccomp;
7127c478bd9Sstevel@tonic-gate 	struct iocblk	*iop;
7137c478bd9Sstevel@tonic-gate 	void		*xtemp;
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate 	iop = (struct iocblk *)mp->b_rptr;
7167c478bd9Sstevel@tonic-gate 	rc = EINVAL;
7177c478bd9Sstevel@tonic-gate 	len = 0;
7187c478bd9Sstevel@tonic-gate 	switch (iop->ioc_cmd) {
7197c478bd9Sstevel@tonic-gate 	case PPPIO_CFLAGS:
7207c478bd9Sstevel@tonic-gate 		if (iop->ioc_count != 2 * sizeof (uint32_t) ||
7217c478bd9Sstevel@tonic-gate 		    mp->b_cont == NULL)
7227c478bd9Sstevel@tonic-gate 			break;
7237c478bd9Sstevel@tonic-gate 
7247c478bd9Sstevel@tonic-gate 		flags = ((uint32_t *)mp->b_cont->b_rptr)[0];
7257c478bd9Sstevel@tonic-gate 		mask = ((uint32_t *)mp->b_cont->b_rptr)[1];
7267c478bd9Sstevel@tonic-gate 
7277c478bd9Sstevel@tonic-gate 		cp->cp_flags = (cp->cp_flags & ~mask) | (flags & mask);
7287c478bd9Sstevel@tonic-gate 
729002c70ffScarlsonj 		if ((mask & CCP_ISOPEN) && !(flags & CCP_ISOPEN)) {
730002c70ffScarlsonj 			cp->cp_flags &= ~CCP_ISUP & ~CCP_COMP_RUN &
731002c70ffScarlsonj 			    ~CCP_DECOMP_RUN;
7327c478bd9Sstevel@tonic-gate 			if (cp->cp_xstate != NULL) {
7337c478bd9Sstevel@tonic-gate 				(*cp->cp_xcomp->comp_free)(cp->cp_xstate);
7347c478bd9Sstevel@tonic-gate 				cp->cp_xstate = NULL;
7357c478bd9Sstevel@tonic-gate 			}
7367c478bd9Sstevel@tonic-gate 			if (cp->cp_rstate != NULL) {
7377c478bd9Sstevel@tonic-gate 				(*cp->cp_rcomp->decomp_free)(cp->cp_rstate);
7387c478bd9Sstevel@tonic-gate 				cp->cp_rstate = NULL;
7397c478bd9Sstevel@tonic-gate 			}
7407c478bd9Sstevel@tonic-gate 		}
7417c478bd9Sstevel@tonic-gate 
7427c478bd9Sstevel@tonic-gate 		CPDEBUG((DBGSTART
7437c478bd9Sstevel@tonic-gate 		    "PPPIO_CFLAGS xflags=0x%b xmask=0x%b flags=0x%b\n",
7447c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
7457c478bd9Sstevel@tonic-gate 		    flags, CP_FLAGSSTR, mask,
7467c478bd9Sstevel@tonic-gate 		    CP_FLAGSSTR, cp->cp_flags, CP_FLAGSSTR));
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate 		/* If we're not the last PPP-speaker, then pass along. */
7497c478bd9Sstevel@tonic-gate 		if (!IS_CP_LASTMOD(cp)) {
7507c478bd9Sstevel@tonic-gate 			return (-1);	/* putnext */
7517c478bd9Sstevel@tonic-gate 		}
7527c478bd9Sstevel@tonic-gate 
7537c478bd9Sstevel@tonic-gate 		*(uint32_t *)mp->b_cont->b_rptr = cp->cp_flags;
7547c478bd9Sstevel@tonic-gate 		len = sizeof (uint32_t);
7557c478bd9Sstevel@tonic-gate 		rc = 0;
7567c478bd9Sstevel@tonic-gate 		break;
7577c478bd9Sstevel@tonic-gate 
7587c478bd9Sstevel@tonic-gate 	case PPPIO_VJINIT:
7597c478bd9Sstevel@tonic-gate 		if (iop->ioc_count != 2 || mp->b_cont == NULL)
7607c478bd9Sstevel@tonic-gate 			break;
7617c478bd9Sstevel@tonic-gate 		/*
7627c478bd9Sstevel@tonic-gate 		 * Even though it's not passed along, we have to
7637c478bd9Sstevel@tonic-gate 		 * validate nrslots so that we don't agree to
7647c478bd9Sstevel@tonic-gate 		 * decompress anything we cannot.
7657c478bd9Sstevel@tonic-gate 		 */
7667c478bd9Sstevel@tonic-gate 		nxslots = mp->b_cont->b_rptr[0] + 1;
7677c478bd9Sstevel@tonic-gate 		nrslots = mp->b_cont->b_rptr[1] + 1;
7687c478bd9Sstevel@tonic-gate 		if (nxslots > MAX_STATES || nrslots > MAX_STATES)
7697c478bd9Sstevel@tonic-gate 			break;
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate 		/* No need to lock here; just reading a word is atomic */
7727c478bd9Sstevel@tonic-gate 		/* mutex_enter(&cp->cp_pair_lock); */
7737c478bd9Sstevel@tonic-gate 		cp->cp_vj_last_ierrors = cp->cp_stats.ppp_ierrors;
7747c478bd9Sstevel@tonic-gate 		/* mutex_exit(&cp->cp_pair_lock); */
7757c478bd9Sstevel@tonic-gate 		vj_compress_init(&cp->cp_vj, nxslots);
7767c478bd9Sstevel@tonic-gate 		cp->cp_nxslots = nxslots;
7777c478bd9Sstevel@tonic-gate 
7787c478bd9Sstevel@tonic-gate 		CPDEBUG((DBGSTART
7797c478bd9Sstevel@tonic-gate 		    "PPPIO_VJINIT txslots=%d rxslots=%d flags=0x%b\n",
7807c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1), nxslots,
7817c478bd9Sstevel@tonic-gate 		    nrslots, cp->cp_flags, CP_FLAGSSTR));
7827c478bd9Sstevel@tonic-gate 		rc = 0;
7837c478bd9Sstevel@tonic-gate 		break;
7847c478bd9Sstevel@tonic-gate 
7857c478bd9Sstevel@tonic-gate 	case PPPIO_XCOMP:
7867c478bd9Sstevel@tonic-gate 	case PPPIO_RCOMP:
7877c478bd9Sstevel@tonic-gate 		if (iop->ioc_count < 2 || mp->b_cont == NULL)
7887c478bd9Sstevel@tonic-gate 			break;
7897c478bd9Sstevel@tonic-gate 		/*
7907c478bd9Sstevel@tonic-gate 		 * The input data here is the raw CCP algorithm option
7917c478bd9Sstevel@tonic-gate 		 * from negotiation.  The format is always one byte of
7927c478bd9Sstevel@tonic-gate 		 * algorithm number, one byte of length, and
7937c478bd9Sstevel@tonic-gate 		 * (length-2) bytes of algorithm-dependent data.  The
7947c478bd9Sstevel@tonic-gate 		 * alloc routine is expected to parse and validate
7957c478bd9Sstevel@tonic-gate 		 * this.
7967c478bd9Sstevel@tonic-gate 		 */
7977c478bd9Sstevel@tonic-gate 		opt_data = mp->b_cont->b_rptr;
7987c478bd9Sstevel@tonic-gate 		opt_len = mp->b_cont->b_wptr - opt_data;
7997c478bd9Sstevel@tonic-gate 		if (opt_len > iop->ioc_count) {
8007c478bd9Sstevel@tonic-gate 			opt_len = iop->ioc_count;
8017c478bd9Sstevel@tonic-gate 		}
8027c478bd9Sstevel@tonic-gate 		len = mp->b_cont->b_rptr[1];
8037c478bd9Sstevel@tonic-gate 		if (len < 2 || len > opt_len)
8047c478bd9Sstevel@tonic-gate 			break;
8057c478bd9Sstevel@tonic-gate 		len = 0;
8067c478bd9Sstevel@tonic-gate 		for (comp = ppp_compressors; *comp != NULL; ++comp) {
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate 			if ((*comp)->compress_proto != opt_data[0]) {
8097c478bd9Sstevel@tonic-gate 				continue;
8107c478bd9Sstevel@tonic-gate 			}
8117c478bd9Sstevel@tonic-gate 			rc = 0;
8127c478bd9Sstevel@tonic-gate 			if (iop->ioc_cmd == PPPIO_XCOMP) {
8137c478bd9Sstevel@tonic-gate 				/*
8147c478bd9Sstevel@tonic-gate 				 * A previous call may have fetched
8157c478bd9Sstevel@tonic-gate 				 * memory for a compressor that's now
8167c478bd9Sstevel@tonic-gate 				 * being retired or reset.  Free it
8177c478bd9Sstevel@tonic-gate 				 * using its mechanism for freeing
8187c478bd9Sstevel@tonic-gate 				 * stuff.
8197c478bd9Sstevel@tonic-gate 				 */
8207c478bd9Sstevel@tonic-gate 				if ((xtemp = cp->cp_xstate) != NULL) {
821002c70ffScarlsonj 					cp->cp_flags &= ~CCP_ISUP &
822002c70ffScarlsonj 					    ~CCP_COMP_RUN;
8237c478bd9Sstevel@tonic-gate 					cp->cp_xstate = NULL;
8247c478bd9Sstevel@tonic-gate 					(*cp->cp_xcomp->comp_free)(xtemp);
8257c478bd9Sstevel@tonic-gate 				}
8267c478bd9Sstevel@tonic-gate 				cp->cp_xcomp = *comp;
8277c478bd9Sstevel@tonic-gate 				cp->cp_xstate = (*comp)->comp_alloc(opt_data,
8287c478bd9Sstevel@tonic-gate 				    opt_len);
8297c478bd9Sstevel@tonic-gate 
8307c478bd9Sstevel@tonic-gate 				if (cp->cp_xstate == NULL) {
8317c478bd9Sstevel@tonic-gate 					rc = ENOSR;
8327c478bd9Sstevel@tonic-gate 				}
8337c478bd9Sstevel@tonic-gate 
8347c478bd9Sstevel@tonic-gate 				CPDEBUG((DBGSTART "PPPIO_XCOMP opt_proto=0x%x "
8357c478bd9Sstevel@tonic-gate 				    "opt_len=0x%d flags=0x%b\n",
8367c478bd9Sstevel@tonic-gate 				    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
8377c478bd9Sstevel@tonic-gate 				    (uchar_t)opt_data[0], opt_len,
8387c478bd9Sstevel@tonic-gate 				    cp->cp_flags,
8397c478bd9Sstevel@tonic-gate 				    CP_FLAGSSTR));
8407c478bd9Sstevel@tonic-gate 			} else {
8417c478bd9Sstevel@tonic-gate 				if ((xtemp = cp->cp_rstate) != NULL) {
842002c70ffScarlsonj 					cp->cp_flags &= ~CCP_ISUP &
843002c70ffScarlsonj 					    ~CCP_DECOMP_RUN;
8447c478bd9Sstevel@tonic-gate 					cp->cp_rstate = NULL;
8457c478bd9Sstevel@tonic-gate 					(*cp->cp_rcomp->decomp_free)(xtemp);
8467c478bd9Sstevel@tonic-gate 				}
8477c478bd9Sstevel@tonic-gate 				cp->cp_rcomp = *comp;
8487c478bd9Sstevel@tonic-gate 				cp->cp_rstate =
8497c478bd9Sstevel@tonic-gate 				    (*comp)->decomp_alloc(opt_data, opt_len);
8507c478bd9Sstevel@tonic-gate 
8517c478bd9Sstevel@tonic-gate 				if (cp->cp_rstate == NULL) {
8527c478bd9Sstevel@tonic-gate 					rc = ENOSR;
8537c478bd9Sstevel@tonic-gate 				}
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate 				CPDEBUG((DBGSTART "PPPIO_RCOMP opt_proto=0x%x "
8567c478bd9Sstevel@tonic-gate 				    "opt_len=0x%d flags=0x%b\n",
8577c478bd9Sstevel@tonic-gate 				    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
8587c478bd9Sstevel@tonic-gate 				    (uchar_t)opt_data[0], opt_len,
8597c478bd9Sstevel@tonic-gate 				    cp->cp_flags,
8607c478bd9Sstevel@tonic-gate 				    CP_FLAGSSTR));
8617c478bd9Sstevel@tonic-gate 			}
8627c478bd9Sstevel@tonic-gate 			if (rc == 0 && (*comp)->set_effort != NULL) {
8637c478bd9Sstevel@tonic-gate 				rc = (*(*comp)->set_effort)(cp->
8647c478bd9Sstevel@tonic-gate 				    cp_xcomp == *comp ? cp->cp_xstate : NULL,
8657c478bd9Sstevel@tonic-gate 				    cp->cp_rcomp == *comp ? cp->cp_rstate :
8667c478bd9Sstevel@tonic-gate 				    NULL, cp->cp_effort);
8677c478bd9Sstevel@tonic-gate 				if (rc != 0) {
8687c478bd9Sstevel@tonic-gate 					CKDEBUG((DBGSTART
8697c478bd9Sstevel@tonic-gate 					    "cannot set effort %d",
8707c478bd9Sstevel@tonic-gate 					    cp->cp_unit, cp->cp_effort));
8717c478bd9Sstevel@tonic-gate 					rc = 0;
8727c478bd9Sstevel@tonic-gate 				}
8737c478bd9Sstevel@tonic-gate 			}
8747c478bd9Sstevel@tonic-gate 			break;
8757c478bd9Sstevel@tonic-gate 		}
8767c478bd9Sstevel@tonic-gate 		break;
8777c478bd9Sstevel@tonic-gate 
8787c478bd9Sstevel@tonic-gate 	case PPPIO_DEBUG:
8797c478bd9Sstevel@tonic-gate 		if (iop->ioc_count != sizeof (uint32_t) || mp->b_cont == NULL)
8807c478bd9Sstevel@tonic-gate 			break;
8817c478bd9Sstevel@tonic-gate 
8827c478bd9Sstevel@tonic-gate 		cmd = *(uint32_t *)mp->b_cont->b_rptr;
8837c478bd9Sstevel@tonic-gate 
8847c478bd9Sstevel@tonic-gate 		/* If it's not for us, then pass along. */
8857c478bd9Sstevel@tonic-gate 		if (cmd != PPPDBG_LOG + PPPDBG_COMP) {
8867c478bd9Sstevel@tonic-gate 			return (-1);	/* putnext */
8877c478bd9Sstevel@tonic-gate 		}
8887c478bd9Sstevel@tonic-gate 		cp->cp_flags |= CP_KDEBUG;
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate 		CKDEBUG((DBGSTART "PPPIO_DEBUG log enabled flags=0x%b\n",
8917c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
8927c478bd9Sstevel@tonic-gate 		    cp->cp_flags, CP_FLAGSSTR));
8937c478bd9Sstevel@tonic-gate 		rc = 0;
8947c478bd9Sstevel@tonic-gate 		break;
8957c478bd9Sstevel@tonic-gate 
8967c478bd9Sstevel@tonic-gate 	case PPPIO_LASTMOD:
8977c478bd9Sstevel@tonic-gate 		cp->cp_flags |= CP_LASTMOD;
8987c478bd9Sstevel@tonic-gate 		CPDEBUG((DBGSTART "PPPIO_LASTMOD last module flags=0x%b\n",
8997c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
9007c478bd9Sstevel@tonic-gate 		    cp->cp_flags, CP_FLAGSSTR));
9017c478bd9Sstevel@tonic-gate 		rc = 0;
9027c478bd9Sstevel@tonic-gate 		break;
9037c478bd9Sstevel@tonic-gate 
9047c478bd9Sstevel@tonic-gate 	case PPPIO_COMPLEV:	/* set compression effort level */
9057c478bd9Sstevel@tonic-gate 		if (iop->ioc_count != sizeof (uint32_t) || mp->b_cont == NULL)
9067c478bd9Sstevel@tonic-gate 			break;
9077c478bd9Sstevel@tonic-gate 		val = *(uint32_t *)mp->b_cont->b_rptr;
9087c478bd9Sstevel@tonic-gate 		cp->cp_effort = val;
9097c478bd9Sstevel@tonic-gate 		/* Silently ignore if compressor doesn't understand this. */
9107c478bd9Sstevel@tonic-gate 		rc = 0;
9117c478bd9Sstevel@tonic-gate 		if ((ccomp = cp->cp_xcomp) != NULL &&
9127c478bd9Sstevel@tonic-gate 		    ccomp->set_effort != NULL) {
9137c478bd9Sstevel@tonic-gate 			rc = (*ccomp->set_effort)(cp->cp_xstate,
9147c478bd9Sstevel@tonic-gate 			    ccomp == cp->cp_rcomp ? cp->cp_rstate : NULL, val);
9157c478bd9Sstevel@tonic-gate 			if (rc != 0)
9167c478bd9Sstevel@tonic-gate 				break;
9177c478bd9Sstevel@tonic-gate 		}
9187c478bd9Sstevel@tonic-gate 		if ((ccomp = cp->cp_rcomp) != NULL && ccomp != cp->cp_xcomp &&
9197c478bd9Sstevel@tonic-gate 		    ccomp->set_effort != NULL)
9207c478bd9Sstevel@tonic-gate 			rc = (*ccomp->set_effort)(NULL, cp->cp_rstate, val);
9217c478bd9Sstevel@tonic-gate 		break;
9227c478bd9Sstevel@tonic-gate 	}
9237c478bd9Sstevel@tonic-gate 	if (rc == 0 && mp->b_cont != NULL)
9247c478bd9Sstevel@tonic-gate 		mp->b_cont->b_wptr = mp->b_cont->b_rptr + len;
9257c478bd9Sstevel@tonic-gate 	return (rc);
9267c478bd9Sstevel@tonic-gate }
9277c478bd9Sstevel@tonic-gate 
9287c478bd9Sstevel@tonic-gate /*
9297c478bd9Sstevel@tonic-gate  * spppcomp_getcstat()
9307c478bd9Sstevel@tonic-gate  *
9317c478bd9Sstevel@tonic-gate  * MT-Perimeters:
9327c478bd9Sstevel@tonic-gate  *    exclusive inner.
9337c478bd9Sstevel@tonic-gate  *
9347c478bd9Sstevel@tonic-gate  * Description:
9357c478bd9Sstevel@tonic-gate  *    Called by spppcomp_ioctl as the result of receiving a PPPIO_GETCSTAT.
9367c478bd9Sstevel@tonic-gate  */
9377c478bd9Sstevel@tonic-gate static void
spppcomp_getcstat(queue_t * q,mblk_t * mp,sppp_comp_t * cp)9387c478bd9Sstevel@tonic-gate spppcomp_getcstat(queue_t *q, mblk_t *mp, sppp_comp_t *cp)
9397c478bd9Sstevel@tonic-gate {
9407c478bd9Sstevel@tonic-gate 	mblk_t		*mpnext;
9417c478bd9Sstevel@tonic-gate 	struct ppp_comp_stats	*csp;
9427c478bd9Sstevel@tonic-gate 
9437c478bd9Sstevel@tonic-gate 	ASSERT(cp != NULL);
9447c478bd9Sstevel@tonic-gate 
9457c478bd9Sstevel@tonic-gate 	mpnext = allocb(sizeof (struct ppp_comp_stats), BPRI_MED);
9467c478bd9Sstevel@tonic-gate 	if (mpnext == NULL) {
9477c478bd9Sstevel@tonic-gate 		miocnak(q, mp, 0, ENOSR);
9487c478bd9Sstevel@tonic-gate 		return;
9497c478bd9Sstevel@tonic-gate 	}
9507c478bd9Sstevel@tonic-gate 	if (mp->b_cont != NULL) {
9517c478bd9Sstevel@tonic-gate 		freemsg(mp->b_cont);
9527c478bd9Sstevel@tonic-gate 	}
9537c478bd9Sstevel@tonic-gate 	mp->b_cont = mpnext;
9547c478bd9Sstevel@tonic-gate 	csp = (struct ppp_comp_stats *)mpnext->b_wptr;
9557c478bd9Sstevel@tonic-gate 	mpnext->b_wptr += sizeof (struct ppp_comp_stats);
9567c478bd9Sstevel@tonic-gate 	bzero((caddr_t)csp, sizeof (struct ppp_comp_stats));
9577c478bd9Sstevel@tonic-gate 
9587c478bd9Sstevel@tonic-gate 	if (cp->cp_xstate != NULL) {
9597c478bd9Sstevel@tonic-gate 		(*cp->cp_xcomp->comp_stat)(cp->cp_xstate, &csp->c);
9607c478bd9Sstevel@tonic-gate 	}
9617c478bd9Sstevel@tonic-gate 	if (cp->cp_rstate != NULL) {
9627c478bd9Sstevel@tonic-gate 		(*cp->cp_rcomp->decomp_stat)(cp->cp_rstate, &csp->d);
9637c478bd9Sstevel@tonic-gate 	}
9647c478bd9Sstevel@tonic-gate 
9657c478bd9Sstevel@tonic-gate 	miocack(q, mp, sizeof (struct ppp_comp_stats), 0);
9667c478bd9Sstevel@tonic-gate }
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate /*
9697c478bd9Sstevel@tonic-gate  * spppcomp_ioctl()
9707c478bd9Sstevel@tonic-gate  *
9717c478bd9Sstevel@tonic-gate  * MT-Perimeters:
9727c478bd9Sstevel@tonic-gate  *    exclusive inner.
9737c478bd9Sstevel@tonic-gate  *
9747c478bd9Sstevel@tonic-gate  * Description:
9757c478bd9Sstevel@tonic-gate  *    Called by spppcomp_wput as the result of receiving an M_IOCTL
9767c478bd9Sstevel@tonic-gate  *    command.
9777c478bd9Sstevel@tonic-gate  */
9787c478bd9Sstevel@tonic-gate static void
spppcomp_ioctl(queue_t * q,mblk_t * mp,sppp_comp_t * cp)9797c478bd9Sstevel@tonic-gate spppcomp_ioctl(queue_t *q, mblk_t *mp, sppp_comp_t *cp)
9807c478bd9Sstevel@tonic-gate {
9817c478bd9Sstevel@tonic-gate 	struct iocblk	*iop;
9827c478bd9Sstevel@tonic-gate 	int flag;
9837c478bd9Sstevel@tonic-gate 
9847c478bd9Sstevel@tonic-gate 	ASSERT(cp != NULL);
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate 	iop = (struct iocblk *)mp->b_rptr;
9877c478bd9Sstevel@tonic-gate 	switch (iop->ioc_cmd) {
9887c478bd9Sstevel@tonic-gate 	case PPPIO_CFLAGS:
9897c478bd9Sstevel@tonic-gate 	case PPPIO_VJINIT:
9907c478bd9Sstevel@tonic-gate 	case PPPIO_XCOMP:
9917c478bd9Sstevel@tonic-gate 	case PPPIO_RCOMP:
9927c478bd9Sstevel@tonic-gate 	case PPPIO_DEBUG:
9937c478bd9Sstevel@tonic-gate 	case PPPIO_LASTMOD:
9947c478bd9Sstevel@tonic-gate 	case PPPIO_COMPLEV:
9957c478bd9Sstevel@tonic-gate 		mutex_enter(&cp->cp_pair_lock);
9967c478bd9Sstevel@tonic-gate 		flag = spppcomp_inner_ioctl(q, mp);
9977c478bd9Sstevel@tonic-gate 		mutex_exit(&cp->cp_pair_lock);
9987c478bd9Sstevel@tonic-gate 		if (flag == -1) {
9997c478bd9Sstevel@tonic-gate 			putnext(q, mp);
10007c478bd9Sstevel@tonic-gate 		} else if (flag == 0) {
10017c478bd9Sstevel@tonic-gate 			miocack(q, mp,
10027c478bd9Sstevel@tonic-gate 			    mp->b_cont == NULL ? 0 : MBLKL(mp->b_cont), 0);
10037c478bd9Sstevel@tonic-gate 		} else {
10047c478bd9Sstevel@tonic-gate 			miocnak(q, mp, 0, flag);
10057c478bd9Sstevel@tonic-gate 		}
10067c478bd9Sstevel@tonic-gate 		break;
10077c478bd9Sstevel@tonic-gate 
10087c478bd9Sstevel@tonic-gate 	case PPPIO_GETCSTAT:
10097c478bd9Sstevel@tonic-gate 		spppcomp_getcstat(q, mp, cp);
10107c478bd9Sstevel@tonic-gate 		break;
10117c478bd9Sstevel@tonic-gate 
10127c478bd9Sstevel@tonic-gate 	case PPPIO_GTYPE:	/* get existing driver type */
10137c478bd9Sstevel@tonic-gate 		if (!IS_CP_LASTMOD(cp)) {
10147c478bd9Sstevel@tonic-gate 			putnext(q, mp);
10157c478bd9Sstevel@tonic-gate 			break;
10167c478bd9Sstevel@tonic-gate 		}
10177c478bd9Sstevel@tonic-gate 		freemsg(mp->b_next);
10187c478bd9Sstevel@tonic-gate 		mp->b_next = allocb(sizeof (uint32_t), BPRI_MED);
10197c478bd9Sstevel@tonic-gate 		if (mp->b_next == NULL) {
10207c478bd9Sstevel@tonic-gate 			miocnak(q, mp, 0, ENOSR);
10217c478bd9Sstevel@tonic-gate 		} else {
10227c478bd9Sstevel@tonic-gate 			*(uint32_t *)mp->b_cont->b_wptr = PPPTYP_HC;
10237c478bd9Sstevel@tonic-gate 			mp->b_cont->b_wptr += sizeof (uint32_t);
10247c478bd9Sstevel@tonic-gate 			miocack(q, mp, sizeof (uint32_t), 0);
10257c478bd9Sstevel@tonic-gate 		}
10267c478bd9Sstevel@tonic-gate 		break;
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate 	default:
10297c478bd9Sstevel@tonic-gate 		putnext(q, mp);
10307c478bd9Sstevel@tonic-gate 		break;
10317c478bd9Sstevel@tonic-gate 	}
10327c478bd9Sstevel@tonic-gate }
10337c478bd9Sstevel@tonic-gate 
10347c478bd9Sstevel@tonic-gate /*
10357c478bd9Sstevel@tonic-gate  * spppcomp_mctl()
10367c478bd9Sstevel@tonic-gate  *
10377c478bd9Sstevel@tonic-gate  * MT-Perimeters:
10387c478bd9Sstevel@tonic-gate  *    exclusive inner; queue pair lock held.
10397c478bd9Sstevel@tonic-gate  *
10407c478bd9Sstevel@tonic-gate  * Description:
10417c478bd9Sstevel@tonic-gate  *	Called by spppcomp_wput as the result of receiving an M_CTL
10427c478bd9Sstevel@tonic-gate  *	message from another STREAMS module, and returns non-zero if
10437c478bd9Sstevel@tonic-gate  *	caller should do putnext or zero for freemsg.  Must *NOT* do
10447c478bd9Sstevel@tonic-gate  *	putnext in this routine, since lock is held here.
10457c478bd9Sstevel@tonic-gate  */
10467c478bd9Sstevel@tonic-gate static int
spppcomp_mctl(queue_t * q,mblk_t * mp)10477c478bd9Sstevel@tonic-gate spppcomp_mctl(queue_t *q, mblk_t *mp)
10487c478bd9Sstevel@tonic-gate {
1049f53eecf5SJames Carlson 	sppp_comp_t		*cp = q->q_ptr;
10507c478bd9Sstevel@tonic-gate 	kstat_t			*ksp;
10517c478bd9Sstevel@tonic-gate 	char			unit[32];
10527c478bd9Sstevel@tonic-gate 	const char **cpp;
10537c478bd9Sstevel@tonic-gate 	kstat_named_t *knt;
10547c478bd9Sstevel@tonic-gate 
10557c478bd9Sstevel@tonic-gate 	switch (*mp->b_rptr) {
10567c478bd9Sstevel@tonic-gate 	case PPPCTL_MTU:
10577c478bd9Sstevel@tonic-gate 		if (MBLKL(mp) < 4) {
10587c478bd9Sstevel@tonic-gate 			break;
10597c478bd9Sstevel@tonic-gate 		}
10607c478bd9Sstevel@tonic-gate 		cp->cp_mtu = ((ushort_t *)mp->b_rptr)[1];
10617c478bd9Sstevel@tonic-gate 
10627c478bd9Sstevel@tonic-gate 		CPDEBUG((DBGSTART "PPPCTL_MTU (%d) flags=0x%b\n",
10637c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
10647c478bd9Sstevel@tonic-gate 		    cp->cp_mtu, cp->cp_flags, CP_FLAGSSTR));
10657c478bd9Sstevel@tonic-gate 		break;
10667c478bd9Sstevel@tonic-gate 	case PPPCTL_MRU:
10677c478bd9Sstevel@tonic-gate 		if (MBLKL(mp) < 4) {
10687c478bd9Sstevel@tonic-gate 			break;
10697c478bd9Sstevel@tonic-gate 		}
10707c478bd9Sstevel@tonic-gate 		cp->cp_mru = ((ushort_t *)mp->b_rptr)[1];
10717c478bd9Sstevel@tonic-gate 
10727c478bd9Sstevel@tonic-gate 		CPDEBUG((DBGSTART "PPPCTL_MRU (%d) flags=0x%b\n",
10737c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
10747c478bd9Sstevel@tonic-gate 		    cp->cp_mru, cp->cp_flags, CP_FLAGSSTR));
10757c478bd9Sstevel@tonic-gate 		break;
10767c478bd9Sstevel@tonic-gate 	case PPPCTL_UNIT:
10777c478bd9Sstevel@tonic-gate 		if (MBLKL(mp) < 8) {
10787c478bd9Sstevel@tonic-gate 			break;
10797c478bd9Sstevel@tonic-gate 		}
10807c478bd9Sstevel@tonic-gate 		/* If PPPCTL_UNIT has already been issued, then ignore. */
10817c478bd9Sstevel@tonic-gate 		if (IS_CP_HASUNIT(cp)) {
10827c478bd9Sstevel@tonic-gate 			break;
10837c478bd9Sstevel@tonic-gate 		}
10847c478bd9Sstevel@tonic-gate 		ASSERT(cp->cp_kstats == NULL);
10857c478bd9Sstevel@tonic-gate 		cp->cp_unit = ((uint32_t *)mp->b_rptr)[1];
10867c478bd9Sstevel@tonic-gate 
10877c478bd9Sstevel@tonic-gate 		/* Create kstats for this unit. */
1088002c70ffScarlsonj 		(void) sprintf(unit, "%s" "%d", COMP_MOD_NAME, cp->cp_unit);
10897c478bd9Sstevel@tonic-gate 		ksp = kstat_create(COMP_MOD_NAME, cp->cp_unit, unit, "net",
1090002c70ffScarlsonj 		    KSTAT_TYPE_NAMED, sizeof (spppcomp_kstats_t) /
1091002c70ffScarlsonj 		    sizeof (kstat_named_t), 0);
10927c478bd9Sstevel@tonic-gate 
10937c478bd9Sstevel@tonic-gate 		if (ksp != NULL) {
10947c478bd9Sstevel@tonic-gate 			cp->cp_flags |= CP_HASUNIT;
10957c478bd9Sstevel@tonic-gate 			cp->cp_kstats = ksp;
10967c478bd9Sstevel@tonic-gate 
10977c478bd9Sstevel@tonic-gate 			knt = (kstat_named_t *)ksp->ks_data;
10987c478bd9Sstevel@tonic-gate 			for (cpp = kstats_names;
10997c478bd9Sstevel@tonic-gate 			    cpp < kstats_names + Dim(kstats_names); cpp++) {
1100d624471bSelowe 				kstat_named_init(knt, *cpp,
11017c478bd9Sstevel@tonic-gate 				    KSTAT_DATA_UINT32);
11027c478bd9Sstevel@tonic-gate 				knt++;
11037c478bd9Sstevel@tonic-gate 			}
11047c478bd9Sstevel@tonic-gate 			for (cpp = kstats64_names;
11057c478bd9Sstevel@tonic-gate 			    cpp < kstats64_names + Dim(kstats64_names); cpp++) {
1106d624471bSelowe 				kstat_named_init(knt, *cpp,
11077c478bd9Sstevel@tonic-gate 				    KSTAT_DATA_UINT64);
11087c478bd9Sstevel@tonic-gate 				knt++;
11097c478bd9Sstevel@tonic-gate 			}
11107c478bd9Sstevel@tonic-gate 			ksp->ks_update = spppcomp_kstat_update;
11117c478bd9Sstevel@tonic-gate 			ksp->ks_private = (void *)cp;
11127c478bd9Sstevel@tonic-gate 			kstat_install(ksp);
11137c478bd9Sstevel@tonic-gate 
11147c478bd9Sstevel@tonic-gate 			CPDEBUG((DBGSTART "PPPCTL_UNIT flags=0x%b\n",
11157c478bd9Sstevel@tonic-gate 			    cp->cp_unit, cp->cp_flags, CP_FLAGSSTR));
11167c478bd9Sstevel@tonic-gate 		}
11177c478bd9Sstevel@tonic-gate 		break;
11187c478bd9Sstevel@tonic-gate 
11197c478bd9Sstevel@tonic-gate 	default:
11207c478bd9Sstevel@tonic-gate 		/* Forward unknown M_CTL messages along */
11217c478bd9Sstevel@tonic-gate 		return (1);
11227c478bd9Sstevel@tonic-gate 	}
11237c478bd9Sstevel@tonic-gate 
11247c478bd9Sstevel@tonic-gate 	/*
11257c478bd9Sstevel@tonic-gate 	 * For known PPP M_CTL messages, forward along only if we're not the
11267c478bd9Sstevel@tonic-gate 	 * last PPP-aware module.
11277c478bd9Sstevel@tonic-gate 	 */
11287c478bd9Sstevel@tonic-gate 	if (IS_CP_LASTMOD(cp))
11297c478bd9Sstevel@tonic-gate 		return (0);
11307c478bd9Sstevel@tonic-gate 	return (1);
11317c478bd9Sstevel@tonic-gate }
11327c478bd9Sstevel@tonic-gate 
11337c478bd9Sstevel@tonic-gate /*
11347c478bd9Sstevel@tonic-gate  * spppcomp_rput()
11357c478bd9Sstevel@tonic-gate  *
11367c478bd9Sstevel@tonic-gate  * MT-Perimeters:
11377c478bd9Sstevel@tonic-gate  *    exclusive inner.
11387c478bd9Sstevel@tonic-gate  *
11397c478bd9Sstevel@tonic-gate  * Description:
11407c478bd9Sstevel@tonic-gate  *    Upper read-side put procedure.  Messages get here from below.
11417c478bd9Sstevel@tonic-gate  *
11427c478bd9Sstevel@tonic-gate  *	The data handling logic is a little more tricky here.  We
11437c478bd9Sstevel@tonic-gate  *	defer to the service routine if q_first isn't NULL (to
11447c478bd9Sstevel@tonic-gate  *	preserve message ordering after deferring a previous message),
11457c478bd9Sstevel@tonic-gate  *	bcanputnext() is FALSE (to handle flow control), or we have
11467c478bd9Sstevel@tonic-gate  *	done a lot of processing recently and we're about to do a lot
11477c478bd9Sstevel@tonic-gate  *	more and we're in an interrupt context (on the theory that
11487c478bd9Sstevel@tonic-gate  *	we're hogging the CPU in this case).
11497c478bd9Sstevel@tonic-gate  */
1150*c4d76aa4SToomas Soome static int
spppcomp_rput(queue_t * q,mblk_t * mp)11517c478bd9Sstevel@tonic-gate spppcomp_rput(queue_t *q, mblk_t *mp)
11527c478bd9Sstevel@tonic-gate {
1153f53eecf5SJames Carlson 	sppp_comp_t		*cp = q->q_ptr;
11547c478bd9Sstevel@tonic-gate 	struct iocblk		*iop;
11557c478bd9Sstevel@tonic-gate 	struct ppp_stats64	*psp;
11567c478bd9Sstevel@tonic-gate 	boolean_t		inter;
11577c478bd9Sstevel@tonic-gate 	hrtime_t		curtime;
11587c478bd9Sstevel@tonic-gate 
11597c478bd9Sstevel@tonic-gate 	switch (MTYPE(mp)) {
11607c478bd9Sstevel@tonic-gate 	case M_DATA:
11617c478bd9Sstevel@tonic-gate 		inter = servicing_interrupt();
11627c478bd9Sstevel@tonic-gate 		if (inter) {
11637c478bd9Sstevel@tonic-gate 			curtime = gethrtime();
11647c478bd9Sstevel@tonic-gate 
11657c478bd9Sstevel@tonic-gate 			/*
11667c478bd9Sstevel@tonic-gate 			 * If little time has passed since last
11677c478bd9Sstevel@tonic-gate 			 * arrival, then bump the counter.
11687c478bd9Sstevel@tonic-gate 			 */
11697c478bd9Sstevel@tonic-gate 			if (curtime - cp->cp_lastfinish < spppcomp_min_arrival)
11707c478bd9Sstevel@tonic-gate 				cp->cp_fastin++;
11717c478bd9Sstevel@tonic-gate 			else
11727c478bd9Sstevel@tonic-gate 				cp->cp_fastin >>= 1;	/* a guess */
11737c478bd9Sstevel@tonic-gate 		}
11747c478bd9Sstevel@tonic-gate 		/*
11757c478bd9Sstevel@tonic-gate 		 * If we're not decompressing, then we'll be fast, so
11767c478bd9Sstevel@tonic-gate 		 * we don't have to worry about hogging here.  If we
11777c478bd9Sstevel@tonic-gate 		 * are decompressing, then we have to check the
11787c478bd9Sstevel@tonic-gate 		 * cp_fastin count.
11797c478bd9Sstevel@tonic-gate 		 */
11807c478bd9Sstevel@tonic-gate 		if ((!(cp->cp_flags & (CCP_DECOMP_RUN | DECOMP_VJC)) ||
11817c478bd9Sstevel@tonic-gate 		    cp->cp_fastin < MAX_FAST_ARRIVALS) &&
11827c478bd9Sstevel@tonic-gate 		    q->q_first == NULL && bcanputnext(q, mp->b_band)) {
11837c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
11847c478bd9Sstevel@tonic-gate 			cp->cp_in_handled++;
11857c478bd9Sstevel@tonic-gate #endif
11867c478bd9Sstevel@tonic-gate 			if ((mp = spppcomp_inpkt(q, mp)) != NULL)
11877c478bd9Sstevel@tonic-gate 				putnext(q, mp);
11887c478bd9Sstevel@tonic-gate 			if (inter) {
11897c478bd9Sstevel@tonic-gate 				cp->cp_lastfinish = gethrtime();
11907c478bd9Sstevel@tonic-gate 			}
11917c478bd9Sstevel@tonic-gate 		} else {
119248bbca81SDaniel Hoffman 			/* Deferring; provide a clean slate */
11937c478bd9Sstevel@tonic-gate 			cp->cp_fastin = 0;
11947c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
11957c478bd9Sstevel@tonic-gate 			cp->cp_in_queued++;
11967c478bd9Sstevel@tonic-gate #endif
1197f53eecf5SJames Carlson 			if (!putq(q, mp))
1198f53eecf5SJames Carlson 				freemsg(mp);
11997c478bd9Sstevel@tonic-gate 		}
12007c478bd9Sstevel@tonic-gate 		break;
12017c478bd9Sstevel@tonic-gate 	case M_IOCACK:
12027c478bd9Sstevel@tonic-gate 		iop = (struct iocblk *)mp->b_rptr;
12037c478bd9Sstevel@tonic-gate 		/*
12047c478bd9Sstevel@tonic-gate 		 * Bundled with pppstats; no need to handle PPPIO_GETSTAT
12057c478bd9Sstevel@tonic-gate 		 * here since we'll never see it.
12067c478bd9Sstevel@tonic-gate 		 */
12077c478bd9Sstevel@tonic-gate 		if (iop->ioc_cmd == PPPIO_GETSTAT64 &&
12087c478bd9Sstevel@tonic-gate 		    iop->ioc_count == sizeof (struct ppp_stats64) &&
12097c478bd9Sstevel@tonic-gate 		    mp->b_cont != NULL) {
12107c478bd9Sstevel@tonic-gate 			/*
12117c478bd9Sstevel@tonic-gate 			 * This crock is to handle a badly-designed
12127c478bd9Sstevel@tonic-gate 			 * but well-known ioctl for ANU PPP.  Both
12137c478bd9Sstevel@tonic-gate 			 * link statistics and VJ statistics are
12147c478bd9Sstevel@tonic-gate 			 * requested together.
12157c478bd9Sstevel@tonic-gate 			 *
12167c478bd9Sstevel@tonic-gate 			 * Catch this on the way back from the
12177c478bd9Sstevel@tonic-gate 			 * spppasyn module so we can fill in the VJ
12187c478bd9Sstevel@tonic-gate 			 * stats.  This happens only when we have
12197c478bd9Sstevel@tonic-gate 			 * PPP-aware modules beneath us.
12207c478bd9Sstevel@tonic-gate 			 */
12217c478bd9Sstevel@tonic-gate 			psp = (struct ppp_stats64 *)mp->b_cont->b_rptr;
12227c478bd9Sstevel@tonic-gate 			psp->vj = cp->cp_vj.stats;
12237c478bd9Sstevel@tonic-gate 			CPDEBUG((DBGSTART
12247c478bd9Sstevel@tonic-gate 			    "PPPIO_GETSTAT64 (VJ filled) flags=0x%b\n",
12257c478bd9Sstevel@tonic-gate 			    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
12267c478bd9Sstevel@tonic-gate 			    cp->cp_flags, CP_FLAGSSTR));
12277c478bd9Sstevel@tonic-gate 		}
12287c478bd9Sstevel@tonic-gate 		putnext(q, mp);
12297c478bd9Sstevel@tonic-gate 		break;
12307c478bd9Sstevel@tonic-gate 	case M_CTL:
12317c478bd9Sstevel@tonic-gate 		/* Increase our statistics and forward it upstream. */
12327c478bd9Sstevel@tonic-gate 		mutex_enter(&cp->cp_pair_lock);
12337c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr == PPPCTL_IERROR) {
12347c478bd9Sstevel@tonic-gate 			cp->cp_stats.ppp_ierrors++;
12357c478bd9Sstevel@tonic-gate 			cp->cp_ierr_low++;
12367c478bd9Sstevel@tonic-gate 		} else if (*mp->b_rptr == PPPCTL_OERROR) {
12377c478bd9Sstevel@tonic-gate 			cp->cp_stats.ppp_oerrors++;
12387c478bd9Sstevel@tonic-gate 			cp->cp_oerr_low++;
12397c478bd9Sstevel@tonic-gate 		}
12407c478bd9Sstevel@tonic-gate 		mutex_exit(&cp->cp_pair_lock);
12417c478bd9Sstevel@tonic-gate 		putnext(q, mp);
12427c478bd9Sstevel@tonic-gate 		break;
12437c478bd9Sstevel@tonic-gate 
12447c478bd9Sstevel@tonic-gate 	case M_FLUSH:
12457c478bd9Sstevel@tonic-gate 		CPDEBUG((DBGSTART "rput M_FLUSH (0x%x) flags=0x%b\n",
12467c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
12477c478bd9Sstevel@tonic-gate 		    *mp->b_rptr, cp->cp_flags,	CP_FLAGSSTR));
12487c478bd9Sstevel@tonic-gate 		/*
12497c478bd9Sstevel@tonic-gate 		 * Just discard pending data.  For CCP, any
12507c478bd9Sstevel@tonic-gate 		 * decompressor dictionary sequencing problems caused
12517c478bd9Sstevel@tonic-gate 		 * by this will have to be handled by the compression
12527c478bd9Sstevel@tonic-gate 		 * protocol in use.  For VJ, we need to give the
12537c478bd9Sstevel@tonic-gate 		 * decompressor a heads-up.
12547c478bd9Sstevel@tonic-gate 		 */
12557c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr & FLUSHR) {
12567c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->cp_pair_lock);
12577c478bd9Sstevel@tonic-gate 			flushq(q, FLUSHDATA);
12587c478bd9Sstevel@tonic-gate 			cp->cp_vj_last_ierrors = cp->cp_stats.ppp_ierrors;
12597c478bd9Sstevel@tonic-gate 			vj_uncompress_err(&cp->cp_vj);
12607c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->cp_pair_lock);
12617c478bd9Sstevel@tonic-gate 		}
12627c478bd9Sstevel@tonic-gate 		putnext(q, mp);
12637c478bd9Sstevel@tonic-gate 		break;
12647c478bd9Sstevel@tonic-gate 
12657c478bd9Sstevel@tonic-gate 	default:
1266f53eecf5SJames Carlson 		if (bcanputnext(q, mp->b_band))
1267f53eecf5SJames Carlson 			putnext(q, mp);
1268f53eecf5SJames Carlson 		else if (!putq(q, mp))
1269f53eecf5SJames Carlson 			freemsg(mp);
12707c478bd9Sstevel@tonic-gate 		break;
12717c478bd9Sstevel@tonic-gate 	}
1272*c4d76aa4SToomas Soome 	return (0);
12737c478bd9Sstevel@tonic-gate }
12747c478bd9Sstevel@tonic-gate 
12757c478bd9Sstevel@tonic-gate /*
12767c478bd9Sstevel@tonic-gate  * spppcomp_rsrv()
12777c478bd9Sstevel@tonic-gate  *
12787c478bd9Sstevel@tonic-gate  * MT-Perimeters:
12797c478bd9Sstevel@tonic-gate  *    exclusive inner.
12807c478bd9Sstevel@tonic-gate  *
12817c478bd9Sstevel@tonic-gate  * Description:
12827c478bd9Sstevel@tonic-gate  *    Upper read-side service procedure.  We handle data deferred from
12837c478bd9Sstevel@tonic-gate  *    spppcomp_rput here.
12847c478bd9Sstevel@tonic-gate  *
12857c478bd9Sstevel@tonic-gate  *	The data on the queue are always compressed (unprocessed).
12867c478bd9Sstevel@tonic-gate  *	The rput procedure tries to do decompression, but if it can't,
12877c478bd9Sstevel@tonic-gate  *	it will put the unprocessed data on the queue for later
12887c478bd9Sstevel@tonic-gate  *	handling.
12897c478bd9Sstevel@tonic-gate  */
1290*c4d76aa4SToomas Soome static int
spppcomp_rsrv(queue_t * q)12917c478bd9Sstevel@tonic-gate spppcomp_rsrv(queue_t *q)
12927c478bd9Sstevel@tonic-gate {
12937c478bd9Sstevel@tonic-gate 	mblk_t		*mp;
12947c478bd9Sstevel@tonic-gate 
12957c478bd9Sstevel@tonic-gate 	while ((mp = getq(q)) != NULL) {
12967c478bd9Sstevel@tonic-gate 		/*
12977c478bd9Sstevel@tonic-gate 		 * If the module above us is flow-controlled, then put
12987c478bd9Sstevel@tonic-gate 		 * this message back on the queue again.
12997c478bd9Sstevel@tonic-gate 		 */
13007c478bd9Sstevel@tonic-gate 		if (!bcanputnext(q, mp->b_band)) {
13017c478bd9Sstevel@tonic-gate 			(void) putbq(q, mp);
13027c478bd9Sstevel@tonic-gate 			break;
13037c478bd9Sstevel@tonic-gate 		}
1304f53eecf5SJames Carlson 		if (MTYPE(mp) != M_DATA ||
1305f53eecf5SJames Carlson 		    (mp = spppcomp_inpkt(q, mp)) != NULL)
13067c478bd9Sstevel@tonic-gate 			putnext(q, mp);
13077c478bd9Sstevel@tonic-gate 	}
1308*c4d76aa4SToomas Soome 	return (0);
13097c478bd9Sstevel@tonic-gate }
13107c478bd9Sstevel@tonic-gate 
13117c478bd9Sstevel@tonic-gate /*
13127c478bd9Sstevel@tonic-gate  * spppcomp_inpkt()
13137c478bd9Sstevel@tonic-gate  *
13147c478bd9Sstevel@tonic-gate  * MT-Perimeters:
13157c478bd9Sstevel@tonic-gate  *    exclusive inner
13167c478bd9Sstevel@tonic-gate  *
13177c478bd9Sstevel@tonic-gate  * Description:
13187c478bd9Sstevel@tonic-gate  *    Process incoming packet.
13197c478bd9Sstevel@tonic-gate  */
13207c478bd9Sstevel@tonic-gate static mblk_t *
spppcomp_inpkt(queue_t * q,mblk_t * mp)13217c478bd9Sstevel@tonic-gate spppcomp_inpkt(queue_t *q, mblk_t *mp)
13227c478bd9Sstevel@tonic-gate {
13237c478bd9Sstevel@tonic-gate 	ushort_t	proto;
13247c478bd9Sstevel@tonic-gate 	int		i;
13257c478bd9Sstevel@tonic-gate 	mblk_t		*zmp;
13267c478bd9Sstevel@tonic-gate 	mblk_t		*np;
13277c478bd9Sstevel@tonic-gate 	uchar_t		*dp;
13287c478bd9Sstevel@tonic-gate 	int		len;
13297c478bd9Sstevel@tonic-gate 	int		hlen;
1330f53eecf5SJames Carlson 	sppp_comp_t	*cp = q->q_ptr;
13317c478bd9Sstevel@tonic-gate 
13327c478bd9Sstevel@tonic-gate 	len = msgsize(mp);
13337c478bd9Sstevel@tonic-gate 
13347c478bd9Sstevel@tonic-gate 	mutex_enter(&cp->cp_pair_lock);
13357c478bd9Sstevel@tonic-gate 	cp->cp_stats.ppp_ibytes += len;
13367c478bd9Sstevel@tonic-gate 	cp->cp_stats.ppp_ipackets++;
13377c478bd9Sstevel@tonic-gate 	mutex_exit(&cp->cp_pair_lock);
13387c478bd9Sstevel@tonic-gate 	/*
13397c478bd9Sstevel@tonic-gate 	 * First work out the protocol and where the PPP header ends.
13407c478bd9Sstevel@tonic-gate 	 */
13417c478bd9Sstevel@tonic-gate 	i = 0;
13427c478bd9Sstevel@tonic-gate 	proto = MSG_BYTE(mp, 0);
13437c478bd9Sstevel@tonic-gate 	if (proto == PPP_ALLSTATIONS) {
13447c478bd9Sstevel@tonic-gate 		i = 2;
13457c478bd9Sstevel@tonic-gate 		proto = MSG_BYTE(mp, 2);
13467c478bd9Sstevel@tonic-gate 	}
13477c478bd9Sstevel@tonic-gate 	if ((proto & 1) == 0) {
13487c478bd9Sstevel@tonic-gate 		++i;
13497c478bd9Sstevel@tonic-gate 		proto = (proto << 8) + MSG_BYTE(mp, i);
13507c478bd9Sstevel@tonic-gate 	}
13517c478bd9Sstevel@tonic-gate 	hlen = i + 1;
13527c478bd9Sstevel@tonic-gate 	/*
13537c478bd9Sstevel@tonic-gate 	 * Now reconstruct a complete, contiguous PPP header at the
13547c478bd9Sstevel@tonic-gate 	 * start of the packet.
13557c478bd9Sstevel@tonic-gate 	 */
13567c478bd9Sstevel@tonic-gate 	if (hlen < (IS_DECOMP_AC(cp) ? 0 : 2) + (IS_DECOMP_PROT(cp) ? 1 : 2)) {
13577c478bd9Sstevel@tonic-gate 		/* count these? */
13587c478bd9Sstevel@tonic-gate 		goto bad;
13597c478bd9Sstevel@tonic-gate 	}
13607c478bd9Sstevel@tonic-gate 	if (mp->b_rptr + hlen > mp->b_wptr) {
13617c478bd9Sstevel@tonic-gate 		/*
13627c478bd9Sstevel@tonic-gate 		 * Header is known to be intact here; so adjmsg will do the
13637c478bd9Sstevel@tonic-gate 		 * right thing here.
13647c478bd9Sstevel@tonic-gate 		 */
13657c478bd9Sstevel@tonic-gate 		if (!adjmsg(mp, hlen)) {
13667c478bd9Sstevel@tonic-gate 			goto bad;
13677c478bd9Sstevel@tonic-gate 		}
13687c478bd9Sstevel@tonic-gate 		hlen = 0;
13697c478bd9Sstevel@tonic-gate 	}
13707c478bd9Sstevel@tonic-gate 	if (hlen != PPP_HDRLEN) {
13717c478bd9Sstevel@tonic-gate 		/*
13727c478bd9Sstevel@tonic-gate 		 * We need to put some bytes on the front of the packet
13737c478bd9Sstevel@tonic-gate 		 * to make a full-length PPP header. If we can put them
13747c478bd9Sstevel@tonic-gate 		 * in mp, we do, otherwise we tack another mblk on the
13757c478bd9Sstevel@tonic-gate 		 * front.
13767c478bd9Sstevel@tonic-gate 		 *
13777c478bd9Sstevel@tonic-gate 		 * XXX we really shouldn't need to carry around the address
13787c478bd9Sstevel@tonic-gate 		 * and control at this stage.  ACFC and PFC need to be
13797c478bd9Sstevel@tonic-gate 		 * reworked.
13807c478bd9Sstevel@tonic-gate 		 */
13817c478bd9Sstevel@tonic-gate 		dp = mp->b_rptr + hlen - PPP_HDRLEN;
13827c478bd9Sstevel@tonic-gate 		if ((dp < mp->b_datap->db_base) || (DB_REF(mp) > 1)) {
13837c478bd9Sstevel@tonic-gate 
13847c478bd9Sstevel@tonic-gate 			np = allocb(PPP_HDRLEN, BPRI_MED);
13857c478bd9Sstevel@tonic-gate 			if (np == 0) {
13867c478bd9Sstevel@tonic-gate 				goto bad;
13877c478bd9Sstevel@tonic-gate 			}
13887c478bd9Sstevel@tonic-gate 			np->b_cont = mp;
13897c478bd9Sstevel@tonic-gate 			mp->b_rptr += hlen;
13907c478bd9Sstevel@tonic-gate 			mp = np;
13917c478bd9Sstevel@tonic-gate 			dp = mp->b_wptr;
13927c478bd9Sstevel@tonic-gate 			mp->b_wptr += PPP_HDRLEN;
13937c478bd9Sstevel@tonic-gate 		} else {
13947c478bd9Sstevel@tonic-gate 			mp->b_rptr = dp;
13957c478bd9Sstevel@tonic-gate 		}
13967c478bd9Sstevel@tonic-gate 		dp[0] = PPP_ALLSTATIONS;
13977c478bd9Sstevel@tonic-gate 		dp[1] = PPP_UI;
13987c478bd9Sstevel@tonic-gate 		dp[2] = (proto >> 8) & 0xff;
13997c478bd9Sstevel@tonic-gate 		dp[3] = proto & 0xff;
14007c478bd9Sstevel@tonic-gate 	}
14017c478bd9Sstevel@tonic-gate 	/*
14027c478bd9Sstevel@tonic-gate 	 * Now see if we have a compressed packet to decompress, or a
14037c478bd9Sstevel@tonic-gate 	 * CCP negotiation packet to take notice of.  It's guaranteed
14047c478bd9Sstevel@tonic-gate 	 * that at least PPP_HDRLEN bytes are contiguous in the first
14057c478bd9Sstevel@tonic-gate 	 * block now.
14067c478bd9Sstevel@tonic-gate 	 */
14077c478bd9Sstevel@tonic-gate 	proto = PPP_PROTOCOL(mp->b_rptr);
14087c478bd9Sstevel@tonic-gate 	if (proto == PPP_CCP) {
14097c478bd9Sstevel@tonic-gate 		len = msgsize(mp);
14107c478bd9Sstevel@tonic-gate 		if (mp->b_wptr < mp->b_rptr + len) {
14117c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
14127c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->cp_pair_lock);
14137c478bd9Sstevel@tonic-gate 			cp->cp_imsg_ccp_pull++;
14147c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->cp_pair_lock);
14157c478bd9Sstevel@tonic-gate #endif
14167c478bd9Sstevel@tonic-gate 			zmp = msgpullup(mp, len);
14177c478bd9Sstevel@tonic-gate 			freemsg(mp);
14187c478bd9Sstevel@tonic-gate 			mp = zmp;
14197c478bd9Sstevel@tonic-gate 			if (mp == 0) {
14207c478bd9Sstevel@tonic-gate 				goto bad;
14217c478bd9Sstevel@tonic-gate 			}
14227c478bd9Sstevel@tonic-gate 		}
14237c478bd9Sstevel@tonic-gate 		mutex_enter(&cp->cp_pair_lock);
14247c478bd9Sstevel@tonic-gate 		comp_ccp(q, mp, cp, B_TRUE);
14257c478bd9Sstevel@tonic-gate 		mutex_exit(&cp->cp_pair_lock);
14267c478bd9Sstevel@tonic-gate 	} else if ((cp->cp_flags & (CCP_ISUP | CCP_DECOMP_RUN | CCP_ERR)) ==
14277c478bd9Sstevel@tonic-gate 	    (CCP_ISUP | CCP_DECOMP_RUN) && cp->cp_rstate != NULL) {
14287c478bd9Sstevel@tonic-gate 		int	rv;
14297c478bd9Sstevel@tonic-gate 
14307c478bd9Sstevel@tonic-gate 		if ((proto == PPP_COMP) || (proto == PPP_COMPFRAG)) {
14317c478bd9Sstevel@tonic-gate 			rv = (*cp->cp_rcomp->decompress)(cp->cp_rstate, &mp);
14327c478bd9Sstevel@tonic-gate 			switch (rv) {
14337c478bd9Sstevel@tonic-gate 			case DECOMP_OK:
14347c478bd9Sstevel@tonic-gate 				break;
14357c478bd9Sstevel@tonic-gate 			case DECOMP_ERROR:
14367c478bd9Sstevel@tonic-gate 				cp->cp_flags |= CCP_ERROR;
14377c478bd9Sstevel@tonic-gate 				mutex_enter(&cp->cp_pair_lock);
14387c478bd9Sstevel@tonic-gate 				++cp->cp_stats.ppp_ierrors;
14397c478bd9Sstevel@tonic-gate 				mutex_exit(&cp->cp_pair_lock);
14407c478bd9Sstevel@tonic-gate 				(void) putnextctl1(q, M_CTL, PPPCTL_IERROR);
14417c478bd9Sstevel@tonic-gate 				break;
14427c478bd9Sstevel@tonic-gate 			case DECOMP_FATALERROR:
14437c478bd9Sstevel@tonic-gate 				cp->cp_flags |= CCP_FATALERROR;
14447c478bd9Sstevel@tonic-gate 				mutex_enter(&cp->cp_pair_lock);
14457c478bd9Sstevel@tonic-gate 				++cp->cp_stats.ppp_ierrors;
14467c478bd9Sstevel@tonic-gate 				mutex_exit(&cp->cp_pair_lock);
14477c478bd9Sstevel@tonic-gate 				(void) putnextctl1(q, M_CTL, PPPCTL_IERROR);
14487c478bd9Sstevel@tonic-gate 				break;
14497c478bd9Sstevel@tonic-gate 			}
14507c478bd9Sstevel@tonic-gate 			if (mp == NULL) {
14517c478bd9Sstevel@tonic-gate 				/* Decompress failed; data are gone. */
14527c478bd9Sstevel@tonic-gate 				return (NULL);
14537c478bd9Sstevel@tonic-gate 			}
14547c478bd9Sstevel@tonic-gate 		} else {
14557c478bd9Sstevel@tonic-gate 			/*
14567c478bd9Sstevel@tonic-gate 			 * For RFCs 1977 and 1979 (BSD Compress and Deflate),
14577c478bd9Sstevel@tonic-gate 			 * the compressor should send incompressible data
14587c478bd9Sstevel@tonic-gate 			 * without encapsulation and the receiver must update
14597c478bd9Sstevel@tonic-gate 			 * its decompression dictionary as though this data
14607c478bd9Sstevel@tonic-gate 			 * were received and decompressed.  This keeps the
14617c478bd9Sstevel@tonic-gate 			 * dictionaries in sync.
14627c478bd9Sstevel@tonic-gate 			 */
14637c478bd9Sstevel@tonic-gate 			rv = (*cp->cp_rcomp->incomp)(cp->cp_rstate, mp);
14647c478bd9Sstevel@tonic-gate 			if (rv < 0) {
14657c478bd9Sstevel@tonic-gate 				cp->cp_flags |= CCP_FATALERROR;
14667c478bd9Sstevel@tonic-gate 				mutex_enter(&cp->cp_pair_lock);
14677c478bd9Sstevel@tonic-gate 				++cp->cp_stats.ppp_ierrors;
14687c478bd9Sstevel@tonic-gate 				mutex_exit(&cp->cp_pair_lock);
14697c478bd9Sstevel@tonic-gate 				(void) putnextctl1(q, M_CTL, PPPCTL_IERROR);
14707c478bd9Sstevel@tonic-gate 			}
14717c478bd9Sstevel@tonic-gate 		}
14727c478bd9Sstevel@tonic-gate 	}
14737c478bd9Sstevel@tonic-gate 	/*
14747c478bd9Sstevel@tonic-gate 	 * Now do VJ decompression.
14757c478bd9Sstevel@tonic-gate 	 */
14767c478bd9Sstevel@tonic-gate 	proto = PPP_PROTOCOL(mp->b_rptr);
14777c478bd9Sstevel@tonic-gate 	if ((proto == PPP_VJC_COMP) || (proto == PPP_VJC_UNCOMP)) {
14787c478bd9Sstevel@tonic-gate 
14797c478bd9Sstevel@tonic-gate 		len = msgsize(mp) - PPP_HDRLEN;
14807c478bd9Sstevel@tonic-gate 
14817c478bd9Sstevel@tonic-gate 		if (!IS_DECOMP_VJC(cp) || (len <= 0)) {
14827c478bd9Sstevel@tonic-gate 			goto bad;
14837c478bd9Sstevel@tonic-gate 		}
14847c478bd9Sstevel@tonic-gate 		/*
14857c478bd9Sstevel@tonic-gate 		 * Advance past the ppp header.  Here we assume that the whole
14867c478bd9Sstevel@tonic-gate 		 * PPP header is in the first mblk.  (This should be true
14877c478bd9Sstevel@tonic-gate 		 * because the above code does pull-ups as necessary on raw
14887c478bd9Sstevel@tonic-gate 		 * data, and the decompressor engines all produce large blocks
14897c478bd9Sstevel@tonic-gate 		 * on output.)
14907c478bd9Sstevel@tonic-gate 		 */
14917c478bd9Sstevel@tonic-gate 		np = mp;
14927c478bd9Sstevel@tonic-gate 		dp = np->b_rptr + PPP_HDRLEN;
14937c478bd9Sstevel@tonic-gate 		if (dp >= mp->b_wptr) {
14947c478bd9Sstevel@tonic-gate 			np = np->b_cont;
14957c478bd9Sstevel@tonic-gate 			dp = np->b_rptr;
14967c478bd9Sstevel@tonic-gate 		}
14977c478bd9Sstevel@tonic-gate 		/*
14987c478bd9Sstevel@tonic-gate 		 * Make sure we have sufficient contiguous data at this point,
14997c478bd9Sstevel@tonic-gate 		 * which in most cases we will always do.
15007c478bd9Sstevel@tonic-gate 		 */
15017c478bd9Sstevel@tonic-gate 		hlen = (proto == PPP_VJC_COMP) ? MAX_VJHDR : MAX_TCPIPHLEN;
15027c478bd9Sstevel@tonic-gate 		if (hlen > len) {
15037c478bd9Sstevel@tonic-gate 			hlen = len;
15047c478bd9Sstevel@tonic-gate 		}
15057c478bd9Sstevel@tonic-gate 		if ((np->b_wptr < dp + hlen) || DB_REF(np) > 1) {
15067c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
15077c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->cp_pair_lock);
15087c478bd9Sstevel@tonic-gate 			cp->cp_imsg_vj_pull++;
15097c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->cp_pair_lock);
15107c478bd9Sstevel@tonic-gate #endif
15117c478bd9Sstevel@tonic-gate 			zmp = msgpullup(mp, hlen + PPP_HDRLEN);
15127c478bd9Sstevel@tonic-gate 			freemsg(mp);
15137c478bd9Sstevel@tonic-gate 			mp = zmp;
15147c478bd9Sstevel@tonic-gate 			if (mp == NULL) {
15157c478bd9Sstevel@tonic-gate 				goto bad;
15167c478bd9Sstevel@tonic-gate 			}
15177c478bd9Sstevel@tonic-gate 			np = mp;
15187c478bd9Sstevel@tonic-gate 			dp = np->b_rptr + PPP_HDRLEN;
15197c478bd9Sstevel@tonic-gate 		}
15207c478bd9Sstevel@tonic-gate 
15217c478bd9Sstevel@tonic-gate 		if (proto == PPP_VJC_COMP) {
15227c478bd9Sstevel@tonic-gate 			uchar_t		*iphdr;
15237c478bd9Sstevel@tonic-gate 			int		vjlen;
15247c478bd9Sstevel@tonic-gate 			uint_t		iphlen;
15257c478bd9Sstevel@tonic-gate 			int		errcnt;
15267c478bd9Sstevel@tonic-gate 
15277c478bd9Sstevel@tonic-gate 			/*
15287c478bd9Sstevel@tonic-gate 			 * Decompress VJ-compressed packet.  First
15297c478bd9Sstevel@tonic-gate 			 * reset compressor if an input error has
15307c478bd9Sstevel@tonic-gate 			 * occurred.  (No need to lock statistics
15317c478bd9Sstevel@tonic-gate 			 * structure for read of a single word.)
15327c478bd9Sstevel@tonic-gate 			 */
15337c478bd9Sstevel@tonic-gate 			errcnt = cp->cp_stats.ppp_ierrors;
15347c478bd9Sstevel@tonic-gate 			if (errcnt != cp->cp_vj_last_ierrors) {
15357c478bd9Sstevel@tonic-gate 				cp->cp_vj_last_ierrors = errcnt;
15367c478bd9Sstevel@tonic-gate 				vj_uncompress_err(&cp->cp_vj);
15377c478bd9Sstevel@tonic-gate 			}
15387c478bd9Sstevel@tonic-gate 
15397c478bd9Sstevel@tonic-gate 			vjlen = vj_uncompress_tcp(dp, np->b_wptr - dp, len,
1540002c70ffScarlsonj 			    &cp->cp_vj, &iphdr, &iphlen);
15417c478bd9Sstevel@tonic-gate 
15427c478bd9Sstevel@tonic-gate 			if (vjlen < 0 || iphlen == 0) {
15437c478bd9Sstevel@tonic-gate 				/*
15447c478bd9Sstevel@tonic-gate 				 * so we don't reset next time
15457c478bd9Sstevel@tonic-gate 				 */
15467c478bd9Sstevel@tonic-gate 				mutex_enter(&cp->cp_pair_lock);
15477c478bd9Sstevel@tonic-gate 				++cp->cp_vj_last_ierrors;
15487c478bd9Sstevel@tonic-gate 				mutex_exit(&cp->cp_pair_lock);
15497c478bd9Sstevel@tonic-gate 				goto bad;
15507c478bd9Sstevel@tonic-gate 			}
15517c478bd9Sstevel@tonic-gate 			/*
15527c478bd9Sstevel@tonic-gate 			 * drop ppp and vj headers off
15537c478bd9Sstevel@tonic-gate 			 */
15547c478bd9Sstevel@tonic-gate 			if (mp != np) {
15557c478bd9Sstevel@tonic-gate 				freeb(mp);
15567c478bd9Sstevel@tonic-gate 				mp = np;
15577c478bd9Sstevel@tonic-gate 			}
15587c478bd9Sstevel@tonic-gate 			mp->b_rptr = dp + vjlen;
15597c478bd9Sstevel@tonic-gate 			/*
15607c478bd9Sstevel@tonic-gate 			 * allocate a new mblk for the ppp and
15617c478bd9Sstevel@tonic-gate 			 * ip headers
15627c478bd9Sstevel@tonic-gate 			 */
15637c478bd9Sstevel@tonic-gate 			np = allocb(iphlen + PPP_HDRLEN, BPRI_MED);
15647c478bd9Sstevel@tonic-gate 			if (np == NULL)
15657c478bd9Sstevel@tonic-gate 				goto bad;
15667c478bd9Sstevel@tonic-gate 			dp = np->b_rptr;
15677c478bd9Sstevel@tonic-gate 			/*
15687c478bd9Sstevel@tonic-gate 			 * reconstruct PPP header
15697c478bd9Sstevel@tonic-gate 			 */
15707c478bd9Sstevel@tonic-gate 			dp[0] = PPP_ALLSTATIONS;
15717c478bd9Sstevel@tonic-gate 			dp[1] = PPP_UI;
15727c478bd9Sstevel@tonic-gate 			dp[2] = PPP_IP >> 8;
15737c478bd9Sstevel@tonic-gate 			dp[3] = PPP_IP;
15747c478bd9Sstevel@tonic-gate 			/*
15757c478bd9Sstevel@tonic-gate 			 * prepend mblk with reconstructed TCP/IP header.
15767c478bd9Sstevel@tonic-gate 			 */
15777c478bd9Sstevel@tonic-gate 			bcopy((caddr_t)iphdr, (caddr_t)dp + PPP_HDRLEN, iphlen);
15787c478bd9Sstevel@tonic-gate 			np->b_wptr = dp + iphlen + PPP_HDRLEN;
15797c478bd9Sstevel@tonic-gate 			np->b_cont = mp;
15807c478bd9Sstevel@tonic-gate 			mp = np;
15817c478bd9Sstevel@tonic-gate 		} else {
15827c478bd9Sstevel@tonic-gate 			/*
15837c478bd9Sstevel@tonic-gate 			 * "Decompress" a VJ-uncompressed packet.
15847c478bd9Sstevel@tonic-gate 			 */
15857c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->cp_pair_lock);
15867c478bd9Sstevel@tonic-gate 			cp->cp_vj_last_ierrors = cp->cp_stats.ppp_ierrors;
15877c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->cp_pair_lock);
15887c478bd9Sstevel@tonic-gate 			if (!vj_uncompress_uncomp(dp, hlen, &cp->cp_vj)) {
15897c478bd9Sstevel@tonic-gate 				/*
15907c478bd9Sstevel@tonic-gate 				 * don't need to reset next time
15917c478bd9Sstevel@tonic-gate 				 */
15927c478bd9Sstevel@tonic-gate 				mutex_enter(&cp->cp_pair_lock);
15937c478bd9Sstevel@tonic-gate 				++cp->cp_vj_last_ierrors;
15947c478bd9Sstevel@tonic-gate 				mutex_exit(&cp->cp_pair_lock);
15957c478bd9Sstevel@tonic-gate 				goto bad;
15967c478bd9Sstevel@tonic-gate 			}
15977c478bd9Sstevel@tonic-gate 			/*
15987c478bd9Sstevel@tonic-gate 			 * fix up the PPP protocol field
15997c478bd9Sstevel@tonic-gate 			 */
16007c478bd9Sstevel@tonic-gate 			mp->b_rptr[3] = PPP_IP;
16017c478bd9Sstevel@tonic-gate 		}
16027c478bd9Sstevel@tonic-gate 	}
16037c478bd9Sstevel@tonic-gate 	CPDEBUG((DBGSTART "recv (%ld bytes) flags=0x%b\n",
16047c478bd9Sstevel@tonic-gate 	    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1), msgsize(mp),
16057c478bd9Sstevel@tonic-gate 	    cp->cp_flags, CP_FLAGSSTR));
16067c478bd9Sstevel@tonic-gate 	return (mp);
16077c478bd9Sstevel@tonic-gate 
16087c478bd9Sstevel@tonic-gate bad:
16097c478bd9Sstevel@tonic-gate 	if (mp != 0) {
16107c478bd9Sstevel@tonic-gate 		freemsg(mp);
16117c478bd9Sstevel@tonic-gate 	}
16127c478bd9Sstevel@tonic-gate 	mutex_enter(&cp->cp_pair_lock);
16137c478bd9Sstevel@tonic-gate 	cp->cp_stats.ppp_ierrors++;
16147c478bd9Sstevel@tonic-gate 	mutex_exit(&cp->cp_pair_lock);
16157c478bd9Sstevel@tonic-gate 	(void) putnextctl1(q, M_CTL, PPPCTL_IERROR);
16167c478bd9Sstevel@tonic-gate 	return (NULL);
16177c478bd9Sstevel@tonic-gate }
16187c478bd9Sstevel@tonic-gate 
16197c478bd9Sstevel@tonic-gate /*
16207c478bd9Sstevel@tonic-gate  * comp_ccp()
16217c478bd9Sstevel@tonic-gate  *
16227c478bd9Sstevel@tonic-gate  * Description:
16237c478bd9Sstevel@tonic-gate  *    Called by spppcomp_outpkt and spppcomp_inpkt to handle a CCP
16247c478bd9Sstevel@tonic-gate  *    negotiation packet being sent or received.  Here all the data in
16257c478bd9Sstevel@tonic-gate  *    the packet is in a single mbuf.
16267c478bd9Sstevel@tonic-gate  *
16277c478bd9Sstevel@tonic-gate  *	Global state is updated.  Must be called with mutex held.
16287c478bd9Sstevel@tonic-gate  */
16297c478bd9Sstevel@tonic-gate /* ARGSUSED */
16307c478bd9Sstevel@tonic-gate static void
comp_ccp(queue_t * q,mblk_t * mp,sppp_comp_t * cp,boolean_t rcvd)16317c478bd9Sstevel@tonic-gate comp_ccp(queue_t *q, mblk_t *mp, sppp_comp_t *cp, boolean_t rcvd)
16327c478bd9Sstevel@tonic-gate {
16337c478bd9Sstevel@tonic-gate 	int	len;
16347c478bd9Sstevel@tonic-gate 	int	clen;
16357c478bd9Sstevel@tonic-gate 	uchar_t	*dp;
16367c478bd9Sstevel@tonic-gate 
16377c478bd9Sstevel@tonic-gate 	len = msgsize(mp);
16387c478bd9Sstevel@tonic-gate 	if (len < PPP_HDRLEN + CCP_HDRLEN) {
16397c478bd9Sstevel@tonic-gate 		return;
16407c478bd9Sstevel@tonic-gate 	}
16417c478bd9Sstevel@tonic-gate 	dp = mp->b_rptr + PPP_HDRLEN;
16427c478bd9Sstevel@tonic-gate 
16437c478bd9Sstevel@tonic-gate 	len -= PPP_HDRLEN;
16447c478bd9Sstevel@tonic-gate 	clen = CCP_LENGTH(dp);
16457c478bd9Sstevel@tonic-gate 	if (clen > len) {
16467c478bd9Sstevel@tonic-gate 		return;
16477c478bd9Sstevel@tonic-gate 	}
16487c478bd9Sstevel@tonic-gate 
16497c478bd9Sstevel@tonic-gate 	CPDEBUG((DBGSTART "CCP code=%d flags=0x%b\n",
16507c478bd9Sstevel@tonic-gate 	    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1), CCP_CODE(dp),
16517c478bd9Sstevel@tonic-gate 	    cp->cp_flags, CP_FLAGSSTR));
16527c478bd9Sstevel@tonic-gate 	switch (CCP_CODE(dp)) {
16537c478bd9Sstevel@tonic-gate 	case CCP_CONFREQ:
16547c478bd9Sstevel@tonic-gate 	case CCP_TERMREQ:
16557c478bd9Sstevel@tonic-gate 	case CCP_TERMACK:
16567c478bd9Sstevel@tonic-gate 		cp->cp_flags &= ~CCP_ISUP;
16577c478bd9Sstevel@tonic-gate 		break;
16587c478bd9Sstevel@tonic-gate 	case CCP_CONFACK:
16597c478bd9Sstevel@tonic-gate 		if ((cp->cp_flags & (CCP_ISOPEN | CCP_ISUP)) == CCP_ISOPEN &&
1660002c70ffScarlsonj 		    clen >= CCP_HDRLEN + CCP_OPT_MINLEN &&
1661002c70ffScarlsonj 		    clen >= CCP_HDRLEN + CCP_OPT_LENGTH(dp + CCP_HDRLEN)) {
16627c478bd9Sstevel@tonic-gate 
16637c478bd9Sstevel@tonic-gate 			int	rc;
16647c478bd9Sstevel@tonic-gate 
16657c478bd9Sstevel@tonic-gate 			if (!rcvd) {
16667c478bd9Sstevel@tonic-gate 				rc = (*cp->cp_xcomp->comp_init)(cp->cp_xstate,
16677c478bd9Sstevel@tonic-gate 				    dp + CCP_HDRLEN, clen - CCP_HDRLEN,
16687c478bd9Sstevel@tonic-gate 				    cp->cp_unit, 0,
16697c478bd9Sstevel@tonic-gate 				    IS_CP_KDEBUG(cp) | ALG_DEBUG);
16707c478bd9Sstevel@tonic-gate 
16717c478bd9Sstevel@tonic-gate 				if (cp->cp_xstate != NULL && rc != 0) {
16727c478bd9Sstevel@tonic-gate 					cp->cp_flags |= CCP_COMP_RUN;
16737c478bd9Sstevel@tonic-gate 				}
16747c478bd9Sstevel@tonic-gate 			} else {
16757c478bd9Sstevel@tonic-gate 				rc = (*cp->cp_rcomp->decomp_init)(cp->
16767c478bd9Sstevel@tonic-gate 				    cp_rstate, dp + CCP_HDRLEN,
16777c478bd9Sstevel@tonic-gate 				    clen - CCP_HDRLEN, cp->cp_unit, 0,
16787c478bd9Sstevel@tonic-gate 				    cp->cp_mru,
16797c478bd9Sstevel@tonic-gate 				    IS_CP_KDEBUG(cp) | ALG_DEBUG);
16807c478bd9Sstevel@tonic-gate 
16817c478bd9Sstevel@tonic-gate 				if (cp->cp_rstate != NULL && rc != 0) {
16827c478bd9Sstevel@tonic-gate 					cp->cp_flags &= ~CCP_ERR;
16837c478bd9Sstevel@tonic-gate 					cp->cp_flags |= CCP_DECOMP_RUN;
16847c478bd9Sstevel@tonic-gate 				}
16857c478bd9Sstevel@tonic-gate 			}
16867c478bd9Sstevel@tonic-gate 		}
16877c478bd9Sstevel@tonic-gate 		break;
16887c478bd9Sstevel@tonic-gate 	case CCP_RESETACK:
16897c478bd9Sstevel@tonic-gate 		if (IS_CCP_ISUP(cp)) {
16907c478bd9Sstevel@tonic-gate 			if (!rcvd) {
16917c478bd9Sstevel@tonic-gate 				if (cp->cp_xstate != NULL &&
16927c478bd9Sstevel@tonic-gate 				    IS_CCP_COMP_RUN(cp)) {
16937c478bd9Sstevel@tonic-gate 					(*cp->cp_xcomp->comp_reset)(cp->
16947c478bd9Sstevel@tonic-gate 					    cp_xstate);
16957c478bd9Sstevel@tonic-gate 				}
16967c478bd9Sstevel@tonic-gate 			} else {
16977c478bd9Sstevel@tonic-gate 				if (cp->cp_rstate != NULL &&
16987c478bd9Sstevel@tonic-gate 				    IS_CCP_DECOMP_RUN(cp)) {
16997c478bd9Sstevel@tonic-gate 					(*cp->cp_rcomp->decomp_reset)(cp->
17007c478bd9Sstevel@tonic-gate 					    cp_rstate);
17017c478bd9Sstevel@tonic-gate 					cp->cp_flags &= ~CCP_ERROR;
17027c478bd9Sstevel@tonic-gate 				}
17037c478bd9Sstevel@tonic-gate 			}
17047c478bd9Sstevel@tonic-gate 		}
17057c478bd9Sstevel@tonic-gate 		break;
17067c478bd9Sstevel@tonic-gate 	}
17077c478bd9Sstevel@tonic-gate }
17087c478bd9Sstevel@tonic-gate 
17097c478bd9Sstevel@tonic-gate /*
17107c478bd9Sstevel@tonic-gate  * spppcomp_kstat_update()
17117c478bd9Sstevel@tonic-gate  *
17127c478bd9Sstevel@tonic-gate  * Description:
17137c478bd9Sstevel@tonic-gate  *    Update per-unit kstat statistics.
17147c478bd9Sstevel@tonic-gate  */
17157c478bd9Sstevel@tonic-gate static int
spppcomp_kstat_update(kstat_t * ksp,int rw)17167c478bd9Sstevel@tonic-gate spppcomp_kstat_update(kstat_t *ksp, int rw)
17177c478bd9Sstevel@tonic-gate {
1718f53eecf5SJames Carlson 	sppp_comp_t		*cp = ksp->ks_private;
1719f53eecf5SJames Carlson 	spppcomp_kstats_t	*cpkp;
1720f53eecf5SJames Carlson 	struct vjstat		*sp;
1721f53eecf5SJames Carlson 	struct pppstat64	*psp;
17227c478bd9Sstevel@tonic-gate 	struct ppp_comp_stats		csp;
17237c478bd9Sstevel@tonic-gate 
17247c478bd9Sstevel@tonic-gate 	if (rw == KSTAT_WRITE) {
17257c478bd9Sstevel@tonic-gate 		return (EACCES);
17267c478bd9Sstevel@tonic-gate 	}
17277c478bd9Sstevel@tonic-gate 
17287c478bd9Sstevel@tonic-gate 	cpkp = (spppcomp_kstats_t *)ksp->ks_data;
17297c478bd9Sstevel@tonic-gate 	bzero((caddr_t)&csp, sizeof (struct ppp_comp_stats));
17307c478bd9Sstevel@tonic-gate 
17317c478bd9Sstevel@tonic-gate 	mutex_enter(&cp->cp_pair_lock);
17327c478bd9Sstevel@tonic-gate 
17337c478bd9Sstevel@tonic-gate 	if (cp->cp_xstate != NULL) {
17347c478bd9Sstevel@tonic-gate 		(*cp->cp_xcomp->comp_stat)(cp->cp_xstate, &csp.c);
17357c478bd9Sstevel@tonic-gate 	}
17367c478bd9Sstevel@tonic-gate 	if (cp->cp_rstate != NULL) {
17377c478bd9Sstevel@tonic-gate 		(*cp->cp_rcomp->decomp_stat)(cp->cp_rstate, &csp.d);
17387c478bd9Sstevel@tonic-gate 	}
17397c478bd9Sstevel@tonic-gate 
17407c478bd9Sstevel@tonic-gate 	sp = &cp->cp_vj.stats;
17417c478bd9Sstevel@tonic-gate 
17427c478bd9Sstevel@tonic-gate 	cpkp->vj_out_pkts.value.ui32		= sp->vjs_packets;
17437c478bd9Sstevel@tonic-gate 	cpkp->vj_out_pkts_comp.value.ui32	= sp->vjs_compressed;
17447c478bd9Sstevel@tonic-gate 	cpkp->vj_cs_searches.value.ui32		= sp->vjs_searches;
17457c478bd9Sstevel@tonic-gate 	cpkp->vj_cs_misses.value.ui32		= sp->vjs_misses;
17467c478bd9Sstevel@tonic-gate 	cpkp->vj_in_pkts_uncomp.value.ui32	= sp->vjs_uncompressedin;
17477c478bd9Sstevel@tonic-gate 	cpkp->vj_in_pkts_comp.value.ui32	= sp->vjs_compressedin;
17487c478bd9Sstevel@tonic-gate 	cpkp->vj_in_error.value.ui32		= sp->vjs_errorin;
17497c478bd9Sstevel@tonic-gate 	cpkp->vj_in_tossed.value.ui32		= sp->vjs_tossed;
17507c478bd9Sstevel@tonic-gate 
17517c478bd9Sstevel@tonic-gate 	psp = &cp->cp_stats;
17527c478bd9Sstevel@tonic-gate 
17537c478bd9Sstevel@tonic-gate 	cpkp->out_bytes.value.ui64		= psp->ppp_obytes;
17547c478bd9Sstevel@tonic-gate 	cpkp->out_pkts.value.ui64		= psp->ppp_opackets;
17557c478bd9Sstevel@tonic-gate 	cpkp->out_errors.value.ui64		= psp->ppp_oerrors;
17567c478bd9Sstevel@tonic-gate 	cpkp->out_errors_low.value.ui32		= cp->cp_oerr_low;
17577c478bd9Sstevel@tonic-gate 	cpkp->out_uncomp_bytes.value.ui32	= csp.c.unc_bytes;
17587c478bd9Sstevel@tonic-gate 	cpkp->out_uncomp_pkts.value.ui32	= csp.c.unc_packets;
17597c478bd9Sstevel@tonic-gate 	cpkp->out_comp_bytes.value.ui32		= csp.c.comp_bytes;
17607c478bd9Sstevel@tonic-gate 	cpkp->out_comp_pkts.value.ui32		= csp.c.comp_packets;
17617c478bd9Sstevel@tonic-gate 	cpkp->out_incomp_bytes.value.ui32	= csp.c.inc_bytes;
17627c478bd9Sstevel@tonic-gate 	cpkp->out_incomp_pkts.value.ui32	= csp.c.inc_packets;
17637c478bd9Sstevel@tonic-gate 
17647c478bd9Sstevel@tonic-gate 	cpkp->in_bytes.value.ui64		= psp->ppp_ibytes;
17657c478bd9Sstevel@tonic-gate 	cpkp->in_pkts.value.ui64		= psp->ppp_ipackets;
17667c478bd9Sstevel@tonic-gate 	cpkp->in_errors.value.ui64		= psp->ppp_ierrors;
17677c478bd9Sstevel@tonic-gate 	cpkp->in_errors_low.value.ui32		= cp->cp_ierr_low;
17687c478bd9Sstevel@tonic-gate 	cpkp->in_uncomp_bytes.value.ui32	= csp.d.unc_bytes;
17697c478bd9Sstevel@tonic-gate 	cpkp->in_uncomp_pkts.value.ui32		= csp.d.unc_packets;
17707c478bd9Sstevel@tonic-gate 	cpkp->in_comp_bytes.value.ui32		= csp.d.comp_bytes;
17717c478bd9Sstevel@tonic-gate 	cpkp->in_comp_pkts.value.ui32		= csp.d.comp_packets;
17727c478bd9Sstevel@tonic-gate 	cpkp->in_incomp_bytes.value.ui32	= csp.d.inc_bytes;
17737c478bd9Sstevel@tonic-gate 	cpkp->in_incomp_pkts.value.ui32		= csp.d.inc_packets;
17747c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
17757c478bd9Sstevel@tonic-gate 	cpkp->in_msg_ccp_pulledup.value.ui32	= cp->cp_imsg_ccp_pull;
17767c478bd9Sstevel@tonic-gate 	cpkp->in_msg_vj_pulledup.value.ui32	= cp->cp_imsg_vj_pull;
17777c478bd9Sstevel@tonic-gate 	cpkp->out_msg_pulledup.value.ui32	= cp->cp_omsg_pull;
17787c478bd9Sstevel@tonic-gate 	cpkp->out_msg_copied.value.ui32		= cp->cp_omsg_dcopy;
17797c478bd9Sstevel@tonic-gate 	cpkp->out_queued.value.ui32		= cp->cp_out_queued;
17807c478bd9Sstevel@tonic-gate 	cpkp->out_handled.value.ui32		= cp->cp_out_handled;
17817c478bd9Sstevel@tonic-gate 	cpkp->in_queued.value.ui32		= cp->cp_in_queued;
17827c478bd9Sstevel@tonic-gate 	cpkp->in_handled.value.ui32		= cp->cp_in_handled;
17837c478bd9Sstevel@tonic-gate #endif
17847c478bd9Sstevel@tonic-gate 	mutex_exit(&cp->cp_pair_lock);
17857c478bd9Sstevel@tonic-gate 	return (0);
17867c478bd9Sstevel@tonic-gate }
1787