xref: /illumos-gate/usr/src/uts/common/io/ppp/sppptun/sppptun_mod.c (revision dc632b73287253d17d0d918869bc5e852e5d3bb7)
17c478bd9Sstevel@tonic-gate /*
2*dc632b73SJames Carlson  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
4*dc632b73SJames Carlson  * The contents of this file are subject to the terms of the
5*dc632b73SJames Carlson  * Common Development and Distribution License (the "License").
6*dc632b73SJames Carlson  * You may not use this file except in compliance with the License.
7*dc632b73SJames Carlson  *
8*dc632b73SJames Carlson  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*dc632b73SJames Carlson  * or http://www.opensolaris.org/os/licensing.
10*dc632b73SJames Carlson  * See the License for the specific language governing permissions
11*dc632b73SJames Carlson  * and limitations under the License.
12*dc632b73SJames Carlson  *
13*dc632b73SJames Carlson  * When distributing Covered Code, include this CDDL HEADER in each
14*dc632b73SJames Carlson  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*dc632b73SJames Carlson  * If applicable, add the following below this CDDL HEADER, with the
16*dc632b73SJames Carlson  * fields enclosed by brackets "[]" replaced with your own identifying
17*dc632b73SJames Carlson  * information: Portions Copyright [yyyy] [name of copyright owner]
18*dc632b73SJames Carlson  *
19*dc632b73SJames Carlson  * CDDL HEADER END
20*dc632b73SJames Carlson  */
21*dc632b73SJames Carlson 
22*dc632b73SJames Carlson /*
2319397407SSherry Moore  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
27*dc632b73SJames Carlson /*
28*dc632b73SJames Carlson  * sppptun_mod.c - modload support for PPP multiplexing tunnel driver.
29*dc632b73SJames Carlson  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/param.h>
337c478bd9Sstevel@tonic-gate #include <sys/stat.h>
347c478bd9Sstevel@tonic-gate #include <sys/systm.h>
357c478bd9Sstevel@tonic-gate #include <sys/socket.h>
367c478bd9Sstevel@tonic-gate #include <sys/stream.h>
377c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
387c478bd9Sstevel@tonic-gate #include <sys/time.h>
397c478bd9Sstevel@tonic-gate #include <sys/conf.h>
407c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
417c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
427c478bd9Sstevel@tonic-gate #include <net/sppptun.h>
437c478bd9Sstevel@tonic-gate #include <netinet/in.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #include "sppptun_mod.h"
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Descriptions for flags values in cb_flags field:
497c478bd9Sstevel@tonic-gate  *
507c478bd9Sstevel@tonic-gate  * D_MTQPAIR:
517c478bd9Sstevel@tonic-gate  *    An inner perimeter that spans the queue pair.
527c478bd9Sstevel@tonic-gate  * D_MTOUTPERIM:
537c478bd9Sstevel@tonic-gate  *    An outer perimeter that spans over all queues in the module.
547c478bd9Sstevel@tonic-gate  * D_MTOCEXCL:
557c478bd9Sstevel@tonic-gate  *    Open & close procedures are entered exclusively at outer perimeter.
567c478bd9Sstevel@tonic-gate  * D_MTPUTSHARED:
577c478bd9Sstevel@tonic-gate  *    Entry to put procedures are done with SHARED (reader) acess
587c478bd9Sstevel@tonic-gate  *    and not EXCLUSIVE (writer) access.
597c478bd9Sstevel@tonic-gate  *
607c478bd9Sstevel@tonic-gate  * Therefore:
617c478bd9Sstevel@tonic-gate  *
627c478bd9Sstevel@tonic-gate  * 1. Open and close procedures are entered with EXCLUSIVE (writer)
637c478bd9Sstevel@tonic-gate  *    access at the inner perimeter, and with EXCLUSIVE (writer) access at
647c478bd9Sstevel@tonic-gate  *    the outer perimeter.
657c478bd9Sstevel@tonic-gate  *
667c478bd9Sstevel@tonic-gate  * 2. Put procedures are entered with SHARED (reader) access at the inner
677c478bd9Sstevel@tonic-gate  *    perimeter, and with SHARED (reader) access at the outer perimeter.
687c478bd9Sstevel@tonic-gate  *
697c478bd9Sstevel@tonic-gate  * 3. Service procedures are entered with EXCLUSIVE (writer) access at
707c478bd9Sstevel@tonic-gate  *    the inner perimeter, and with SHARED (reader) access at the
717c478bd9Sstevel@tonic-gate  *    outer perimeter.
727c478bd9Sstevel@tonic-gate  *
737c478bd9Sstevel@tonic-gate  * Do not attempt to modify these flags unless the entire corresponding
747c478bd9Sstevel@tonic-gate  * driver code is changed to accomodate the newly represented MT-STREAMS
757c478bd9Sstevel@tonic-gate  * flags. Doing so without making proper modifications to the driver code
767c478bd9Sstevel@tonic-gate  * will severely impact the intended driver behavior, and thus may affect
777c478bd9Sstevel@tonic-gate  * the system's stability and performance.
787c478bd9Sstevel@tonic-gate  */
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate static int	tun_attach(dev_info_t *, ddi_attach_cmd_t);
817c478bd9Sstevel@tonic-gate static int	tun_detach(dev_info_t *, ddi_detach_cmd_t);
827c478bd9Sstevel@tonic-gate static int	tun_info(dev_info_t *, ddi_info_cmd_t, void *, void **);
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate static dev_info_t *tun_dev_info;
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate DDI_DEFINE_STREAM_OPS(sppptun_ops,			\
877c478bd9Sstevel@tonic-gate 	nulldev, nulldev,				\
887c478bd9Sstevel@tonic-gate 	tun_attach, tun_detach, nodev, tun_info,	\
897c478bd9Sstevel@tonic-gate 	D_NEW | D_MP | D_MTQPAIR | D_MTOUTPERIM | D_MTOCEXCL | D_MTPUTSHARED, \
9019397407SSherry Moore 	&sppptun_tab, ddi_quiesce_not_supported);
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate /*
937c478bd9Sstevel@tonic-gate  * This is the loadable module wrapper.
947c478bd9Sstevel@tonic-gate  */
957c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate  * Module linkage information for the kernel.
997c478bd9Sstevel@tonic-gate  */
1007c478bd9Sstevel@tonic-gate static struct fmodsw sppptun_fmodsw = {
1017c478bd9Sstevel@tonic-gate 	PPP_TUN_NAME,
1027c478bd9Sstevel@tonic-gate 	&sppptun_tab,
1037c478bd9Sstevel@tonic-gate 	D_NEW | D_MP | D_MTQPAIR | D_MTOUTPERIM | D_MTOCEXCL | D_MTPUTSHARED
1047c478bd9Sstevel@tonic-gate };
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate static struct modldrv modldrv = {
1077c478bd9Sstevel@tonic-gate 	&mod_driverops,
1087c478bd9Sstevel@tonic-gate 	(char *)sppptun_driver_description,
1097c478bd9Sstevel@tonic-gate 	&sppptun_ops
1107c478bd9Sstevel@tonic-gate };
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate static struct modlstrmod modlstrmod = {
1137c478bd9Sstevel@tonic-gate 	&mod_strmodops,
1147c478bd9Sstevel@tonic-gate 	(char *)sppptun_module_description,
1157c478bd9Sstevel@tonic-gate 	&sppptun_fmodsw
1167c478bd9Sstevel@tonic-gate };
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
1197c478bd9Sstevel@tonic-gate 	MODREV_1,
1207c478bd9Sstevel@tonic-gate 	(void *)&modlstrmod,
1217c478bd9Sstevel@tonic-gate 	(void *)&modldrv,
1227c478bd9Sstevel@tonic-gate 	NULL
1237c478bd9Sstevel@tonic-gate };
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate int
_init(void)1267c478bd9Sstevel@tonic-gate _init(void)
1277c478bd9Sstevel@tonic-gate {
1287c478bd9Sstevel@tonic-gate 	int retv;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	sppptun_init();
131002c70ffScarlsonj 	if ((retv = mod_install(&modlinkage)) == 0)
1327c478bd9Sstevel@tonic-gate 		sppptun_tcl_init();
1337c478bd9Sstevel@tonic-gate 	return (retv);
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate int
_fini(void)1377c478bd9Sstevel@tonic-gate _fini(void)
1387c478bd9Sstevel@tonic-gate {
1397c478bd9Sstevel@tonic-gate 	int retv;
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 	if ((retv = sppptun_tcl_fintest()) != 0)
1427c478bd9Sstevel@tonic-gate 		return (retv);
1437c478bd9Sstevel@tonic-gate 	retv = mod_remove(&modlinkage);
144002c70ffScarlsonj 	if (retv != 0)
1457c478bd9Sstevel@tonic-gate 		return (retv);
1467c478bd9Sstevel@tonic-gate 	sppptun_tcl_fini();
1477c478bd9Sstevel@tonic-gate 	return (0);
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1517c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1527c478bd9Sstevel@tonic-gate {
153002c70ffScarlsonj 	return (mod_info(&modlinkage, modinfop));
1547c478bd9Sstevel@tonic-gate }
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate /*
1577c478bd9Sstevel@tonic-gate  * tun_attach()
1587c478bd9Sstevel@tonic-gate  *
1597c478bd9Sstevel@tonic-gate  * Description:
1607c478bd9Sstevel@tonic-gate  *    Attach a PPP tunnel driver to the system.
1617c478bd9Sstevel@tonic-gate  */
1627c478bd9Sstevel@tonic-gate static int
tun_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)1637c478bd9Sstevel@tonic-gate tun_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
1647c478bd9Sstevel@tonic-gate {
165002c70ffScarlsonj 	if (cmd != DDI_ATTACH)
1667c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
1677c478bd9Sstevel@tonic-gate 	if (ddi_create_minor_node(dip, PPP_TUN_NAME, S_IFCHR, 0, DDI_PSEUDO,
1687c478bd9Sstevel@tonic-gate 	    CLONE_DEV) == DDI_FAILURE) {
1697c478bd9Sstevel@tonic-gate 		ddi_remove_minor_node(dip, NULL);
1707c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
1717c478bd9Sstevel@tonic-gate 	}
1727c478bd9Sstevel@tonic-gate 	tun_dev_info = dip;
1737c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate /*
1777c478bd9Sstevel@tonic-gate  * tun_detach()
1787c478bd9Sstevel@tonic-gate  *
1797c478bd9Sstevel@tonic-gate  * Description:
1807c478bd9Sstevel@tonic-gate  *    Detach an interface to the system.
1817c478bd9Sstevel@tonic-gate  */
1827c478bd9Sstevel@tonic-gate static int
tun_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)1837c478bd9Sstevel@tonic-gate tun_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
1847c478bd9Sstevel@tonic-gate {
185002c70ffScarlsonj 	if (cmd != DDI_DETACH)
1867c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
1877c478bd9Sstevel@tonic-gate 	tun_dev_info = NULL;
1887c478bd9Sstevel@tonic-gate 	ddi_remove_minor_node(dip, NULL);
1897c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
1907c478bd9Sstevel@tonic-gate }
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate /*
1937c478bd9Sstevel@tonic-gate  * tun_info()
1947c478bd9Sstevel@tonic-gate  *
1957c478bd9Sstevel@tonic-gate  * Description:
1967c478bd9Sstevel@tonic-gate  *    Translate "dev_t" to a pointer to the associated "dev_info_t".
1977c478bd9Sstevel@tonic-gate  */
1987c478bd9Sstevel@tonic-gate /* ARGSUSED */
1997c478bd9Sstevel@tonic-gate static int
tun_info(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)2007c478bd9Sstevel@tonic-gate tun_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
2017c478bd9Sstevel@tonic-gate 	void **result)
2027c478bd9Sstevel@tonic-gate {
2037c478bd9Sstevel@tonic-gate 	int	rc;
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	switch (infocmd) {
2067c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
2077c478bd9Sstevel@tonic-gate 		if (tun_dev_info == NULL) {
2087c478bd9Sstevel@tonic-gate 			rc = DDI_FAILURE;
2097c478bd9Sstevel@tonic-gate 		} else {
2107c478bd9Sstevel@tonic-gate 			*result = (void *)tun_dev_info;
2117c478bd9Sstevel@tonic-gate 			rc = DDI_SUCCESS;
2127c478bd9Sstevel@tonic-gate 		}
2137c478bd9Sstevel@tonic-gate 		break;
2147c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
2157c478bd9Sstevel@tonic-gate 		*result = NULL;
2167c478bd9Sstevel@tonic-gate 		rc = DDI_SUCCESS;
2177c478bd9Sstevel@tonic-gate 		break;
2187c478bd9Sstevel@tonic-gate 	default:
2197c478bd9Sstevel@tonic-gate 		rc = DDI_FAILURE;
2207c478bd9Sstevel@tonic-gate 		break;
2217c478bd9Sstevel@tonic-gate 	}
2227c478bd9Sstevel@tonic-gate 	return (rc);
2237c478bd9Sstevel@tonic-gate }
224