Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/inet/dlpistub/dlpistub.c
+++ new/usr/src/uts/common/inet/dlpistub/dlpistub.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 /*
27 27 * DLPI stub driver; currently supports VNI and IPMP stub devices.
28 28 */
29 29
30 30 #include <sys/conf.h>
31 31 #include <sys/ddi.h>
32 32 #include <sys/sunddi.h>
33 33 #include <sys/dlpi.h>
34 34 #include <sys/stat.h>
35 35 #include <sys/strsun.h>
36 36 #include <sys/stropts.h>
37 37 #include <sys/types.h>
38 38 #include <sys/id_space.h>
39 39 #include <sys/sysmacros.h>
40 40 #include <sys/kmem.h>
41 41 #include <sys/modctl.h>
42 42 #include <sys/mkdev.h>
43 43 #include <sys/sdt.h>
44 44
45 45 #include "dlpistub_impl.h"
46 46
47 47 static id_space_t *ds_minors;
48 48 static dev_info_t *ds_dip;
49 49
50 50 /*
51 51 * DL_INFO_ACK template.
52 52 */
53 53 static dl_info_ack_t ds_infoack = {
54 54 DL_INFO_ACK, /* dl_primitive */
55 55 0, /* dl_max_sdu */
56 56 0, /* dl_min_sdu */
57 57 0, /* dl_addr_length */
58 58 0, /* dl_mac_type */
59 59 0, /* dl_reserved */
60 60 0, /* dl_current_state */
61 61 0, /* dl_sap_length */
62 62 DL_CLDLS, /* dl_service_mode */
63 63 0, /* dl_qos_length */
64 64 0, /* dl_qos_offset */
65 65 0, /* dl_qos_range_length */
66 66 0, /* dl_qos_range_offset */
67 67 DL_STYLE2, /* dl_provider_style */
68 68 0, /* dl_addr_offset */
69 69 DL_VERSION_2, /* dl_version */
70 70 0, /* dl_brdcst_addr_length */
71 71 0, /* dl_brdcst_addr_offset */
72 72 0 /* dl_growth */
73 73 };
74 74
75 75 static int
76 76 ds_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
77 77 {
78 78 if (cmd != DDI_ATTACH)
79 79 return (DDI_FAILURE);
80 80
81 81 if (ddi_create_minor_node(dip, "vni", S_IFCHR, DS_MINOR_VNI,
82 82 DDI_PSEUDO, 0) == DDI_FAILURE ||
83 83 ddi_create_minor_node(dip, "ipmpstub", S_IFCHR, DS_MINOR_IPMP,
84 84 DDI_PSEUDO, 0) == DDI_FAILURE) {
85 85 ddi_remove_minor_node(dip, NULL);
86 86 cmn_err(CE_NOTE, "ds_attach: cannot create minor nodes");
87 87 return (DDI_FAILURE);
88 88 }
89 89
90 90 ds_dip = dip;
91 91 ds_minors = id_space_create("ds_minors", DS_MINOR_START, MAXMIN32);
92 92 return (DDI_SUCCESS);
93 93 }
94 94
95 95 static int
96 96 ds_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
97 97 {
98 98 if (cmd != DDI_DETACH)
99 99 return (DDI_FAILURE);
100 100
101 101 id_space_destroy(ds_minors);
102 102 ds_minors = NULL;
103 103 ASSERT(dip == ds_dip);
104 104 ddi_remove_minor_node(dip, NULL);
105 105 ds_dip = NULL;
106 106 return (DDI_SUCCESS);
107 107 }
108 108
109 109 /* ARGSUSED */
110 110 static int
111 111 ds_devinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
112 112 {
113 113 int error = DDI_FAILURE;
114 114
115 115 switch (infocmd) {
116 116 case DDI_INFO_DEVT2INSTANCE:
117 117 *result = (void *)0;
118 118 error = DDI_SUCCESS;
119 119 break;
120 120 case DDI_INFO_DEVT2DEVINFO:
121 121 if (ds_dip != NULL) {
122 122 *result = ds_dip;
123 123 error = DDI_SUCCESS;
124 124 }
125 125 break;
126 126 }
127 127 return (error);
128 128 }
129 129
130 130 /* ARGSUSED */
131 131 static int
132 132 ds_open(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *credp)
133 133 {
134 134 int type;
135 135 dlpistub_t *dsp;
136 136
137 137 if (sflag == CLONEOPEN || sflag == MODOPEN)
138 138 return (EINVAL);
139 139
140 140 if (q->q_ptr != NULL)
141 141 return (0);
142 142
143 143 switch (getminor(*devp)) {
144 144 case DS_MINOR_VNI:
145 145 type = SUNW_DL_VNI;
146 146 break;
147 147 case DS_MINOR_IPMP:
148 148 type = SUNW_DL_IPMP;
149 149 break;
150 150 default:
151 151 return (ENXIO);
152 152 }
153 153
154 154 dsp = kmem_zalloc(sizeof (dlpistub_t), KM_SLEEP);
155 155 dsp->ds_type = type;
156 156 dsp->ds_minor = (minor_t)id_alloc(ds_minors);
157 157 dsp->ds_state = DL_UNATTACHED;
158 158 *devp = makedevice(getmajor(*devp), dsp->ds_minor);
159 159 q->q_ptr = WR(q)->q_ptr = dsp;
160 160 qprocson(q);
161 161
162 162 return (0);
163 163 }
164 164
165 165 /* ARGSUSED */
166 166 static int
167 167 ds_close(queue_t *q, int flag, cred_t *credp)
168 168 {
169 169 dlpistub_t *dsp = q->q_ptr;
170 170
171 171 qprocsoff(q);
172 172 q->q_ptr = WR(q)->q_ptr = NULL;
173 173
174 174 id_free(ds_minors, dsp->ds_minor);
175 175 kmem_free(dsp, sizeof (dlpistub_t));
176 176
177 177 return (0);
178 178 }
179 179
180 180 static int
181 181 ds_badprim(queue_t *q, mblk_t *mp, t_scalar_t prim)
182 182 {
183 183 dlerrorack(q, mp, prim, DL_BADPRIM, 0);
184 184 return (0);
185 185 }
186 186
187 187 static int
188 188 ds_outstate(queue_t *q, mblk_t *mp, t_scalar_t prim)
189 189 {
190 190 dlerrorack(q, mp, prim, DL_OUTSTATE, 0);
191 191 return (0);
192 192 }
193 193
194 194 static int
195 195 ds_wput(queue_t *q, mblk_t *mp)
196 196 {
197 197 union DL_primitives *dlp;
198 198 dl_info_ack_t *dlip;
199 199 dlpistub_t *dsp = q->q_ptr;
200 200 t_scalar_t prim;
201 201
202 202 switch (DB_TYPE(mp)) {
203 203 case M_PROTO:
204 204 case M_PCPROTO:
205 205 if (MBLKL(mp) < sizeof (t_scalar_t)) {
206 206 dlerrorack(q, mp, DL_PRIM_INVAL, DL_UNSUPPORTED, 0);
207 207 return (0);
208 208 }
209 209
210 210 dlp = (void *)mp->b_rptr;
211 211 prim = dlp->dl_primitive;
212 212 switch (prim) {
213 213 case DL_ATTACH_REQ:
214 214 if (MBLKL(mp) < DL_ATTACH_REQ_SIZE)
215 215 return (ds_badprim(q, mp, prim));
216 216
217 217 if (dsp->ds_state != DL_UNATTACHED)
218 218 return (ds_outstate(q, mp, prim));
219 219
220 220 dsp->ds_state = DL_UNBOUND;
221 221 dlokack(q, mp, DL_ATTACH_REQ);
222 222 break;
223 223
224 224 case DL_BIND_REQ:
225 225 if (MBLKL(mp) < DL_BIND_REQ_SIZE)
226 226 return (ds_badprim(q, mp, prim));
227 227
228 228 if (dsp->ds_state != DL_UNBOUND)
229 229 return (ds_outstate(q, mp, prim));
230 230
231 231 dsp->ds_state = DL_IDLE;
232 232 dlbindack(q, mp, dlp->bind_req.dl_sap, NULL, 0, 0, 0);
233 233 break;
234 234
235 235 case DL_INFO_REQ:
236 236 if (MBLKL(mp) < DL_INFO_REQ_SIZE)
237 237 return (ds_badprim(q, mp, prim));
238 238
239 239 mp = mexchange(q, mp, sizeof (dl_info_ack_t),
240 240 M_PCPROTO, DL_INFO_ACK);
241 241 if (mp != NULL) {
242 242 dlip = (void *)mp->b_rptr;
243 243 *dlip = ds_infoack;
244 244 dlip->dl_mac_type = dsp->ds_type;
245 245 dlip->dl_current_state = dsp->ds_state;
246 246 qreply(q, mp);
247 247 }
248 248 break;
249 249
250 250 case DL_PHYS_ADDR_REQ:
251 251 if (MBLKL(mp) < DL_PHYS_ADDR_REQ_SIZE)
252 252 return (ds_badprim(q, mp, prim));
253 253
254 254 dlphysaddrack(q, mp, NULL, 0);
255 255 break;
256 256
257 257 case DL_UNBIND_REQ:
258 258 if (MBLKL(mp) < DL_UNBIND_REQ_SIZE)
259 259 return (ds_badprim(q, mp, prim));
260 260
261 261 if (dsp->ds_state != DL_IDLE)
262 262 return (ds_outstate(q, mp, prim));
263 263
264 264 dsp->ds_state = DL_UNBOUND;
265 265 dlokack(q, mp, DL_UNBIND_REQ);
266 266 break;
267 267
268 268 case DL_DETACH_REQ:
269 269 if (MBLKL(mp) < DL_DETACH_REQ_SIZE)
270 270 return (ds_badprim(q, mp, prim));
271 271
272 272 if (dsp->ds_state != DL_UNBOUND)
273 273 return (ds_outstate(q, mp, prim));
274 274
275 275 dsp->ds_state = DL_UNATTACHED;
276 276 dlokack(q, mp, DL_DETACH_REQ);
277 277 break;
278 278
279 279 case DL_UNITDATA_REQ:
280 280 DTRACE_PROBE2(dlpistub__data, dlpistub_t *, dsp,
281 281 mblk_t *, mp);
282 282 freemsg(mp);
283 283 break;
284 284
285 285 default:
286 286 dlerrorack(q, mp, prim, DL_UNSUPPORTED, 0);
287 287 }
288 288 break;
289 289
290 290 case M_IOCTL:
291 291 miocnak(q, mp, 0, EINVAL);
292 292 break;
293 293
294 294 case M_FLUSH:
295 295 *mp->b_rptr &= ~FLUSHW;
296 296 if (*mp->b_rptr & FLUSHR)
297 297 qreply(q, mp);
298 298 else
299 299 freemsg(mp);
300 300 break;
301 301 default:
302 302 freemsg(mp);
303 303 break;
304 304 }
305 305
306 306 return (0);
307 307 }
308 308
309 309 static struct module_info ds_minfo = {
310 310 DS_IDNUM, /* mi_idnum */
311 311 "dlpistub", /* mi_idname */
312 312 0, /* mi_minpsz */
313 313 INFPSZ, /* mi_maxpsz */
314 314 0, /* mi_hiwat */
315 315 0, /* mi_lowat */
316 316 };
317 317
318 318 static struct qinit ds_rinit = {
319 319 NULL, /* qi_putp */
320 320 NULL, /* qi_srvp */
321 321 ds_open, /* qi_qopen */
322 322 ds_close, /* qi_qclose */
323 323 NULL, /* qi_qadmin */
324 324 &ds_minfo, /* qi_minfo */
325 325 };
326 326
327 327 static struct qinit ds_winit = {
328 328 ds_wput, /* qi_putp */
329 329 NULL, /* qi_srvp */
330 330 NULL, /* qi_qopen */
331 331 NULL, /* qi_qclose */
332 332 NULL, /* qi_qadmin */
333 333 &ds_minfo, /* qi_minfo */
334 334 };
335 335
336 336 static struct streamtab ds_info = {
337 337 &ds_rinit, /* st_rdinit */
338 338 &ds_winit /* st_wrinit */
339 339 };
340 340
↓ open down ↓ |
340 lines elided |
↑ open up ↑ |
341 341 DDI_DEFINE_STREAM_OPS(ds_ops, nulldev, nulldev, ds_attach, ds_detach,
342 342 nodev, ds_devinfo, D_MP|D_MTPERMOD, &ds_info, ddi_quiesce_not_supported);
343 343
344 344 static struct modldrv modldrv = {
345 345 &mod_driverops,
346 346 "DLPI stub driver",
347 347 &ds_ops,
348 348 };
349 349
350 350 static struct modlinkage modlinkage = {
351 - MODREV_1, &modldrv, NULL
351 + MODREV_1, { &modldrv, NULL }
352 352 };
353 353
354 354 int
355 355 _init(void)
356 356 {
357 357 return (mod_install(&modlinkage));
358 358 }
359 359
360 360 int
361 361 _fini(void)
362 362 {
363 363 return (mod_remove(&modlinkage));
364 364 }
365 365
366 366 int
367 367 _info(struct modinfo *modinfop)
368 368 {
369 369 return (mod_info(&modlinkage, modinfop));
370 370 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX