1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
/*
* sppp_mod.c - modload support for PPP pseudo-device driver.
*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appears in all copies.
*
* SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
*
* Copyright (c) 1994 The Australian National University.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appears in all copies. This software is provided without any
* warranty, express or implied. The Australian National University
* makes no representations about the suitability of this software for
* any purpose.
*
* IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
* THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
* OR MODIFICATIONS.
*
* This driver is derived from the original SVR4 STREAMS PPP driver
* originally written by Paul Mackerras <paul.mackerras@cs.anu.edu.au>.
*
* Adi Masputra <adi.masputra@sun.com> rewrote and restructured the code
* for improved performance and scalability.
*/
#define RCSID " $Id: sppp_mod.c,v 1.0 2000/05/08 10:53:28 masputra Exp $"
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/ddi.h>
#include <sys/conf.h>
#include <sys/sunddi.h>
#include <sys/stat.h>
#include <sys/kstat.h>
#include <net/pppio.h>
#include <sys/modctl.h>
#include "s_common.h"
#include "sppp.h"
static int _mi_driver_attach(dev_info_t *, ddi_attach_cmd_t);
static int _mi_driver_detach(dev_info_t *, ddi_detach_cmd_t);
static int _mi_driver_info(dev_info_t *, ddi_info_cmd_t, void *, void **);
/*
* Globals for PPP multiplexer module wrapper
*/
extern const char sppp_module_description[];
static dev_info_t *_mi_dip;
#define PPP_MI_HIWAT (PPP_MTU * 16) /* XXX find more meaningful value */
#define PPP_MI_LOWAT (PPP_MTU * 14) /* XXX find more meaningful value */
static struct module_info sppp_modinfo = {
PPP_MOD_ID, /* mi_idnum */
PPP_DRV_NAME, /* mi_idname */
0, /* mi_minpsz */
PPP_MAXMTU, /* mi_maxpsz */
PPP_MI_HIWAT, /* mi_hiwat */
PPP_MI_LOWAT /* mi_lowat */
};
static struct qinit sppp_urinit = {
NULL, /* qi_putp */
NULL, /* qi_srvp */
sppp_open, /* qi_qopen */
sppp_close, /* qi_qclose */
NULL, /* qi_qadmin */
&sppp_modinfo, /* qi_minfo */
NULL /* qi_mstat */
};
static struct qinit sppp_uwinit = {
sppp_uwput, /* qi_putp */
sppp_uwsrv, /* qi_srvp */
NULL, /* qi_qopen */
NULL, /* qi_qclose */
NULL, /* qi_qadmin */
&sppp_modinfo, /* qi_minfo */
NULL /* qi_mstat */
};
static struct qinit sppp_lrinit = {
sppp_lrput, /* qi_putp */
sppp_lrsrv, /* qi_srvp */
NULL, /* qi_qopen */
NULL, /* qi_qclose */
NULL, /* qi_qadmin */
&sppp_modinfo, /* qi_minfo */
NULL /* qi_mstat */
};
static struct qinit sppp_lwinit = {
NULL, /* qi_putp */
sppp_lwsrv, /* qi_srvp */
NULL, /* qi_qopen */
NULL, /* qi_qclose */
NULL, /* qi_qadmin */
&sppp_modinfo, /* qi_minfo */
NULL /* qi_mstat */
};
static struct streamtab sppp_tab = {
&sppp_urinit, /* st_rdinit */
&sppp_uwinit, /* st_wrinit */
&sppp_lrinit, /* st_muxrinit */
&sppp_lwinit /* st_muxwrinit */
};
/*
* Descriptions for flags values in cb_flags field:
*
* D_MTQPAIR:
* An inner perimeter that spans the queue pair.
* D_MTOUTPERIM:
* An outer perimeter that spans over all queues in the module.
* D_MTOCEXCL:
* Open & close procedures are entered exclusively at outer perimeter.
* D_MTPUTSHARED:
* Entry to put procedures are done with SHARED (reader) acess
* and not EXCLUSIVE (writer) access.
*
* Therefore:
*
* 1. Open and close procedures are entered with EXCLUSIVE (writer)
* access at the inner perimeter, and with EXCLUSIVE (writer) access at
* the outer perimeter.
*
* 2. Put procedures are entered with SHARED (reader) access at the inner
* perimeter, and with SHARED (reader) access at the outer perimeter.
*
* 3. Service procedures are entered with EXCLUSIVE (writer) access at
* the inner perimeter, and with SHARED (reader) access at the
* outer perimeter.
*
* Do not attempt to modify these flags unless the entire corresponding
* driver code is changed to accomodate the newly represented MT-STREAMS
* flags. Doing so without making proper modifications to the driver code
* will severely impact the intended driver behavior, and thus may affect
* the system's stability and performance.
*/
DDI_DEFINE_STREAM_OPS(sppp_ops, \
nulldev, nulldev, \
_mi_driver_attach, _mi_driver_detach, nodev, _mi_driver_info, \
D_NEW | D_MP | D_MTQPAIR | D_MTOUTPERIM | D_MTOCEXCL | D_MTPUTSHARED, \
&sppp_tab, ddi_quiesce_not_supported);
static struct modldrv modldrv = {
&mod_driverops, /* drv_modops */
(char *)sppp_module_description, /* drv_linkinfo */
&sppp_ops /* drv_dev_ops */
};
static struct modlinkage modlinkage = {
MODREV_1, /* ml_rev, has to be MODREV_1 */
&modldrv, /* ml_linkage, NULL-terminated list */
NULL /* of linkage structures */
};
int
_init(void)
{
return (mod_install(&modlinkage));
}
int
_fini(void)
{
return (mod_remove(&modlinkage));
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
/*
* _mi_driver_attach()
*
* Description:
* Attach a point-to-point interface to the system.
*/
static int
_mi_driver_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
{
if (cmd != DDI_ATTACH) {
return (DDI_FAILURE);
}
_mi_dip = dip;
if (ddi_create_minor_node(dip, PPP_DRV_NAME, S_IFCHR,
0, DDI_PSEUDO, CLONE_DEV) == DDI_FAILURE) {
ddi_remove_minor_node(dip, NULL);
return (DDI_FAILURE);
}
sppp_dlpi_pinfoinit();
return (DDI_SUCCESS);
}
/*
* _mi_driver_detach()
*
* Description:
* Detach an interface to the system.
*/
static int
_mi_driver_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
{
if (cmd != DDI_DETACH) {
return (DDI_FAILURE);
}
ddi_remove_minor_node(dip, NULL);
_mi_dip = NULL;
return (DDI_SUCCESS);
}
/*
* _mi_driver_info()
*
* Description:
* Translate "dev_t" to a pointer to the associated "dev_info_t".
*/
/* ARGSUSED */
static int
_mi_driver_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
void **result)
{
int rc;
switch (infocmd) {
case DDI_INFO_DEVT2DEVINFO:
if (_mi_dip == NULL) {
rc = DDI_FAILURE;
} else {
*result = (void *)_mi_dip;
rc = DDI_SUCCESS;
}
break;
case DDI_INFO_DEVT2INSTANCE:
*result = NULL;
rc = DDI_SUCCESS;
break;
default:
rc = DDI_FAILURE;
break;
}
return (rc);
}
|