Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/tirdwr.c
+++ new/usr/src/uts/common/io/tirdwr.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, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
21 21 */
22 22 /*
23 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 28 /* All Rights Reserved */
29 29
30 30
31 -#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R4 1.4 */
32 -
33 31 /*
34 32 * Transport Interface Library read/write module - issue 1
35 33 */
36 34
37 35 #include <sys/types.h>
38 36 #include <sys/param.h>
39 37 #include <sys/stream.h>
40 38 #include <sys/stropts.h>
41 39 #include <sys/tihdr.h>
42 40 #include <sys/debug.h>
43 41 #include <sys/errno.h>
44 42 #include <sys/kmem.h>
45 43 #include <sys/tirdwr.h>
46 44 #include <sys/conf.h>
47 45 #include <sys/modctl.h>
48 46 #include <sys/ddi.h>
49 47 #include <sys/sunddi.h>
50 48
51 49 #define ORDREL 002
52 50 #define DISCON 004
53 51 #define FATAL 010
54 52 #define WAITACK 020
55 53 #define TIRDWR_ID 4
56 54
57 55 /*
58 56 * Per-Stream private data structure.
59 57 */
60 58 struct trw_trw {
61 59 queue_t *trw_rdq;
62 60 uint_t trw_flags;
63 61 };
64 62
65 63 /*
66 64 * stream data structure definitions
67 65 */
68 66 static int tirdwropen(queue_t *q, dev_t *dev,
69 67 int flag, int sflag, cred_t *cr);
70 68
71 69 static int tirdwrclose(queue_t *q, int flag, cred_t *cr);
72 70
73 71 static int check_strhead(queue_t *q);
74 72
75 73 /*
76 74 * To save instructions, since STREAMS ignores the return value
77 75 * from these functions, they are defined as void here. Kind of icky, but...
78 76 */
79 77 static void tirdwrrput(queue_t *q, mblk_t *mp);
80 78 static void tirdwrwput(queue_t *q, mblk_t *mp);
81 79
82 80 static struct module_info tirdwr_info = {
83 81 TIRDWR_ID,
84 82 "tirdwr",
85 83 0,
86 84 INFPSZ,
87 85 4096,
88 86 1024
89 87 };
90 88
91 89 static struct qinit tirdwrrinit = {
92 90 (int (*)())tirdwrrput,
93 91 (int (*)())NULL,
94 92 tirdwropen,
95 93 tirdwrclose,
96 94 nulldev,
97 95 &tirdwr_info,
98 96 NULL
99 97 };
100 98
101 99 static struct qinit tirdwrwinit = {
102 100 (int (*)())tirdwrwput,
103 101 (int (*)())NULL,
104 102 tirdwropen,
105 103 tirdwrclose,
106 104 nulldev,
107 105 &tirdwr_info,
108 106 NULL
109 107 };
110 108
111 109 static struct streamtab trwinfo = {
112 110 &tirdwrrinit,
113 111 &tirdwrwinit,
114 112 NULL,
115 113 NULL
116 114 };
117 115
118 116 static struct fmodsw fsw = {
↓ open down ↓ |
76 lines elided |
↑ open up ↑ |
119 117 "tirdwr",
120 118 &trwinfo,
121 119 D_NEW|D_MTQPAIR|D_MP
122 120 };
123 121
124 122 static struct modlstrmod modlstrmod = {
125 123 &mod_strmodops, "xport interface rd/wr str mod", &fsw
126 124 };
127 125
128 126 static struct modlinkage modlinkage = {
129 - MODREV_1, &modlstrmod, NULL
127 + MODREV_1, { &modlstrmod, NULL }
130 128 };
131 129
132 130 int
133 131 _init(void)
134 132 {
135 133 return (mod_install(&modlinkage));
136 134 }
137 135
138 136 int
139 137 _fini(void)
140 138 {
141 139 return (mod_remove(&modlinkage));
142 140 }
143 141
144 142 int
145 143 _info(struct modinfo *modinfop)
146 144 {
147 145 return (mod_info(&modlinkage, modinfop));
148 146 }
149 147
150 148 static void send_fatal(queue_t *q, mblk_t *mp);
151 149 static void strip_strhead(queue_t *q);
152 150
153 151
154 152 /*
155 153 * tirdwropen - open routine gets called when the
156 154 * module gets pushed onto the stream.
157 155 */
158 156 /*ARGSUSED*/
159 157 static int
160 158 tirdwropen(
161 159 queue_t *q,
162 160 dev_t *dev,
163 161 int flag,
164 162 int sflag,
165 163 cred_t *cr)
166 164 {
167 165 struct trw_trw *trwptr;
168 166
169 167 /* check if already open */
170 168 if (q->q_ptr) {
171 169 return (0);
172 170 }
173 171
174 172 /*
175 173 * Allocate a new trw_trw struct.
176 174 */
177 175 trwptr = kmem_alloc(sizeof (struct trw_trw), KM_SLEEP);
178 176
179 177 /* initialize data structure */
180 178 trwptr->trw_flags = 0;
181 179 trwptr->trw_rdq = q;
182 180 q->q_ptr = (caddr_t)trwptr;
183 181 WR(q)->q_ptr = (caddr_t)trwptr;
184 182 qprocson(q);
185 183
186 184 freezestr(q);
187 185
188 186 (void) strqset(WR(q), QMAXPSZ, 0, (uintptr_t)WR(q)->q_next->q_maxpsz);
189 187 (void) strqset(q, QMAXPSZ, 0, (uintptr_t)q->q_next->q_maxpsz);
190 188
191 189 if (!check_strhead(q)) {
192 190 unfreezestr(q);
193 191 qprocsoff(q);
194 192 kmem_free(trwptr, sizeof (struct trw_trw));
195 193 return (EPROTO);
196 194 }
197 195 strip_strhead(q);
198 196 unfreezestr(q);
199 197
200 198 return (0);
201 199 }
202 200
203 201 /*
204 202 * tirdwrclose - This routine gets called when the module
205 203 * gets popped off of the stream.
206 204 */
207 205
208 206 /*ARGSUSED1*/
209 207 static int
210 208 tirdwrclose(queue_t *q, int flag, cred_t *cr)
211 209 {
212 210 struct trw_trw *trwptr;
213 211 mblk_t *mp;
214 212 union T_primitives *pptr;
215 213
216 214 qprocsoff(q);
217 215 trwptr = (struct trw_trw *)q->q_ptr;
218 216
219 217 ASSERT(trwptr != NULL);
220 218
221 219 /*
222 220 * Send up a T_DISCON_IND if necessary.
223 221 */
224 222 if ((trwptr->trw_flags & ORDREL) && !(trwptr->trw_flags & FATAL))
225 223 if (mp = allocb(sizeof (struct T_discon_req), BPRI_LO)) {
226 224 pptr = (union T_primitives *)mp->b_rptr;
227 225 mp->b_wptr = mp->b_rptr + sizeof (struct T_ordrel_req);
228 226 pptr->type = T_ORDREL_REQ;
229 227 mp->b_datap->db_type = M_PROTO;
230 228 putnext(WR(q), mp);
231 229 }
232 230
233 231 kmem_free(trwptr, sizeof (struct trw_trw));
234 232
235 233 return (0);
236 234 }
237 235
238 236 /*
239 237 * tirdwrrput - Module read queue put procedure.
240 238 * This is called from the module or
241 239 * driver downstream.
242 240 */
243 241
244 242 static void
245 243 tirdwrrput(queue_t *q, mblk_t *mp)
246 244 {
247 245 union T_primitives *pptr;
248 246 struct trw_trw *trwptr;
249 247 mblk_t *tmp;
250 248
251 249 trwptr = (struct trw_trw *)q->q_ptr;
252 250
253 251 ASSERT(trwptr != NULL);
254 252
255 253 if ((trwptr->trw_flags & FATAL) && !(trwptr->trw_flags & WAITACK)) {
256 254 freemsg(mp);
257 255 return;
258 256 }
259 257
260 258 switch (mp->b_datap->db_type) {
261 259
262 260 default:
263 261 putnext(q, mp);
264 262 break;
265 263
266 264 case M_DATA:
267 265 putnext(q, mp);
268 266 break;
269 267
270 268 case M_PCPROTO:
271 269 case M_PROTO:
272 270 /* is there enough data to check type */
273 271 if ((mp->b_wptr - mp->b_rptr) < sizeof (t_scalar_t)) {
274 272 /* malformed message */
275 273 freemsg(mp);
276 274 break;
277 275 }
278 276 pptr = (union T_primitives *)mp->b_rptr;
279 277
280 278 switch (pptr->type) {
281 279
282 280 case T_EXDATA_IND:
283 281 send_fatal(q, mp);
284 282 break;
285 283 case T_DATA_IND:
286 284 if (msgdsize(mp) == 0) {
287 285 freemsg(mp);
288 286 break;
289 287 }
290 288
291 289 tmp = (mblk_t *)unlinkb(mp);
292 290 freemsg(mp);
293 291 putnext(q, tmp);
294 292 break;
295 293
296 294 case T_ORDREL_IND:
297 295 trwptr->trw_flags |= ORDREL;
298 296 mp->b_datap->db_type = M_DATA;
299 297 mp->b_wptr = mp->b_rptr;
300 298 putnext(q, mp);
301 299 break;
302 300
303 301 case T_DISCON_IND:
304 302 trwptr->trw_flags |= DISCON;
305 303 trwptr->trw_flags &= ~ORDREL;
306 304 if (msgdsize(mp) != 0) {
307 305 tmp = (mblk_t *)unlinkb(mp);
308 306 putnext(q, tmp);
309 307 }
310 308 mp->b_datap->db_type = M_HANGUP;
311 309 mp->b_wptr = mp->b_rptr;
312 310 putnext(q, mp);
313 311 break;
314 312
315 313 default:
316 314 send_fatal(q, mp);
317 315 break;
318 316 }
319 317 }
320 318 }
321 319
322 320
323 321 /*
324 322 * tirdwrwput - Module write queue put procedure.
325 323 * This is called from the module or
326 324 * stream head upstream.
327 325 */
328 326 static void
329 327 tirdwrwput(queue_t *q, mblk_t *mp)
330 328 {
331 329 struct trw_trw *trwptr;
332 330
333 331 trwptr = (struct trw_trw *)q->q_ptr;
334 332
335 333 ASSERT(trwptr != NULL);
336 334
337 335 if (trwptr->trw_flags & FATAL) {
338 336 freemsg(mp);
339 337 return;
340 338 }
341 339
342 340 switch (mp->b_datap->db_type) {
343 341 default:
344 342 putnext(q, mp);
345 343 break;
346 344
347 345 case M_DATA:
348 346 putnext(q, mp);
349 347 break;
350 348
351 349 case M_PROTO:
352 350 case M_PCPROTO:
353 351 send_fatal(q, mp);
354 352 break;
355 353 }
356 354 }
357 355
358 356
359 357 static void
360 358 send_fatal(queue_t *q, mblk_t *mp)
361 359 {
362 360 struct trw_trw *trwptr;
363 361
364 362 trwptr = (struct trw_trw *)q->q_ptr;
365 363
366 364 trwptr->trw_flags |= FATAL;
367 365 mp->b_datap->db_type = M_ERROR;
368 366 *mp->b_datap->db_base = EPROTO;
369 367 mp->b_rptr = mp->b_datap->db_base;
370 368 mp->b_wptr = mp->b_datap->db_base + sizeof (char);
371 369 freemsg(unlinkb(mp));
372 370 if (q->q_flag&QREADR)
373 371 putnext(q, mp);
374 372 else
375 373 qreply(q, mp);
376 374 }
377 375
378 376 static int
379 377 check_strhead(queue_t *q)
380 378 {
381 379 mblk_t *mp;
382 380 union T_primitives *pptr;
383 381
384 382 for (mp = q->q_next->q_first; mp != NULL; mp = mp->b_next) {
385 383
386 384 switch (mp->b_datap->db_type) {
387 385 case M_PROTO:
388 386 pptr = (union T_primitives *)mp->b_rptr;
389 387 if ((mp->b_wptr - mp->b_rptr) < sizeof (t_scalar_t))
390 388 return (0);
391 389 switch (pptr->type) {
392 390
393 391 case T_EXDATA_IND:
394 392 return (0);
395 393 case T_DATA_IND:
396 394 if (mp->b_cont &&
397 395 (mp->b_cont->b_datap->db_type != M_DATA))
398 396 return (0);
399 397 break;
400 398 default:
401 399 return (0);
402 400 }
403 401 break;
404 402
405 403 case M_PCPROTO:
406 404 return (0);
407 405
408 406 case M_DATA:
409 407 case M_SIG:
410 408 break;
411 409 default:
412 410 return (0);
413 411 }
414 412 }
415 413 return (1);
416 414 }
417 415
418 416 static void
419 417 strip_strhead(queue_t *q)
420 418 {
421 419 mblk_t *mp;
422 420 mblk_t *emp;
423 421 mblk_t *tmp;
424 422 union T_primitives *pptr;
425 423
426 424 q = q->q_next;
427 425 /*CSTYLED*/
428 426 for (mp = q->q_first; mp != NULL; ) {
429 427
430 428 switch (mp->b_datap->db_type) {
431 429 case M_PROTO:
432 430 pptr = (union T_primitives *)mp->b_rptr;
433 431 switch (pptr->type) {
434 432
435 433 case T_DATA_IND:
436 434 if (msgdsize(mp) == 0) {
437 435 strip0:
438 436 tmp = mp->b_next;
439 437 rmvq(q, mp);
440 438 freemsg(mp);
441 439 mp = tmp;
442 440 break;
443 441 }
444 442 emp = mp->b_next;
445 443 rmvq(q, mp);
446 444 tmp = (mblk_t *)unlinkb(mp);
447 445 freeb(mp);
448 446 (void) insq(q, emp, tmp);
449 447 mp = emp;
450 448 break;
451 449 }
452 450 break;
453 451
454 452 case M_DATA:
455 453 if (msgdsize(mp) == 0)
456 454 goto strip0;
457 455 mp = mp->b_next;
458 456 break;
459 457
460 458 case M_SIG:
461 459 mp = mp->b_next;
462 460 break;
463 461 }
464 462 }
465 463 }
↓ open down ↓ |
326 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX