1/*
2 * ppp_mod.c - modload support for PPP pseudo-device driver.
3 *
4 * Copyright (c) 1994 Paul Mackerras. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in
15 *    the documentation and/or other materials provided with the
16 *    distribution.
17 *
18 * 3. The name(s) of the authors of this software must not be used to
19 *    endorse or promote products derived from this software without
20 *    prior written permission.
21 *
22 * 4. Redistributions of any form whatsoever must retain the following
23 *    acknowledgment:
24 *    "This product includes software developed by Paul Mackerras
25 *     <paulus@samba.org>".
26 *
27 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
28 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
29 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
30 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
31 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
32 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
33 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
34 *
35 * $Id: ppp_mod.c,v 1.1.1.1 2008/10/15 03:30:44 james26_jang Exp $
36 */
37
38/*
39 * This file is used under Solaris 2.
40 */
41
42#include <sys/types.h>
43#include <sys/param.h>
44#include <sys/stat.h>
45#include <sys/conf.h>
46#include <sys/modctl.h>
47#include <sys/sunddi.h>
48#include <sys/ksynch.h>
49
50#ifdef __STDC__
51#define __P(x)	x
52#else
53#define __P(x)	()
54#endif
55
56static int ppp_identify __P((dev_info_t *));
57static int ppp_attach __P((dev_info_t *, ddi_attach_cmd_t));
58static int ppp_detach __P((dev_info_t *, ddi_detach_cmd_t));
59static int ppp_devinfo __P((dev_info_t *, ddi_info_cmd_t, void *, void **));
60
61extern struct streamtab pppinfo;
62extern krwlock_t ppp_lower_lock;
63
64static dev_info_t *ppp_dip;
65
66static struct cb_ops cb_ppp_ops = {
67    nulldev, nulldev, nodev, nodev,	/* cb_open, ... */
68    nodev, nodev, nodev, nodev,		/* cb_dump, ... */
69    nodev, nodev, nodev, nochpoll,	/* cb_devmap, ... */
70    ddi_prop_op,			/* cb_prop_op */
71    &pppinfo,				/* cb_stream */
72    D_NEW|D_MP|D_MTQPAIR|D_MTOUTPERIM|D_MTOCEXCL	/* cb_flag */
73};
74
75static struct dev_ops ppp_ops = {
76    DEVO_REV,				/* devo_rev */
77    0,					/* devo_refcnt */
78    ppp_devinfo,			/* devo_getinfo */
79    ppp_identify,			/* devo_identify */
80    nulldev,				/* devo_probe */
81    ppp_attach,				/* devo_attach */
82    ppp_detach,				/* devo_detach */
83    nodev,				/* devo_reset */
84    &cb_ppp_ops,			/* devo_cb_ops */
85    NULL				/* devo_bus_ops */
86};
87
88/*
89 * Module linkage information
90 */
91
92static struct modldrv modldrv = {
93    &mod_driverops,			/* says this is a pseudo driver */
94    "PPP-2.3 multiplexing driver",
95    &ppp_ops				/* driver ops */
96};
97
98static struct modlinkage modlinkage = {
99    MODREV_1,
100    (void *) &modldrv,
101    NULL
102};
103
104int
105_init(void)
106{
107    return mod_install(&modlinkage);
108}
109
110int
111_fini(void)
112{
113    return mod_remove(&modlinkage);
114}
115
116int
117_info(mip)
118    struct modinfo *mip;
119{
120    return mod_info(&modlinkage, mip);
121}
122
123static int
124ppp_identify(dip)
125    dev_info_t *dip;
126{
127    return strcmp(ddi_get_name(dip), "ppp") == 0? DDI_IDENTIFIED:
128	DDI_NOT_IDENTIFIED;
129}
130
131static int
132ppp_attach(dip, cmd)
133    dev_info_t *dip;
134    ddi_attach_cmd_t cmd;
135{
136
137    if (cmd != DDI_ATTACH)
138	return DDI_FAILURE;
139    if (ddi_create_minor_node(dip, "ppp", S_IFCHR, 0, DDI_PSEUDO, CLONE_DEV)
140	== DDI_FAILURE) {
141	ddi_remove_minor_node(dip, NULL);
142	return DDI_FAILURE;
143    }
144    rw_init(&ppp_lower_lock, NULL, RW_DRIVER, NULL);
145    return DDI_SUCCESS;
146}
147
148static int
149ppp_detach(dip, cmd)
150    dev_info_t *dip;
151    ddi_detach_cmd_t cmd;
152{
153    rw_destroy(&ppp_lower_lock);
154    ddi_remove_minor_node(dip, NULL);
155    return DDI_SUCCESS;
156}
157
158static int
159ppp_devinfo(dip, cmd, arg, result)
160    dev_info_t *dip;
161    ddi_info_cmd_t cmd;
162    void *arg;
163    void **result;
164{
165    int error;
166
167    error = DDI_SUCCESS;
168    switch (cmd) {
169    case DDI_INFO_DEVT2DEVINFO:
170	if (ppp_dip == NULL)
171	    error = DDI_FAILURE;
172	else
173	    *result = (void *) ppp_dip;
174	break;
175    case DDI_INFO_DEVT2INSTANCE:
176	*result = NULL;
177	break;
178    default:
179	error = DDI_FAILURE;
180    }
181    return error;
182}
183