Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/ipp/dlcosmk/dlcosmkddi.c
+++ new/usr/src/uts/common/ipp/dlcosmk/dlcosmkddi.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 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #include <sys/types.h>
27 27 #include <sys/atomic.h>
28 28 #include <sys/systm.h>
29 29 #include <sys/socket.h>
30 30 #include <netinet/in.h>
31 31 #include <sys/modctl.h>
32 32 #include <sys/sunddi.h>
33 33 #include <ipp/ipp.h>
34 34 #include <ipp/ipp_config.h>
35 35 #include <inet/common.h>
36 36 #include <ipp/dlcosmk/dlcosmk_impl.h>
37 37
38 38 #define D_SM_COMMENT "IPP dlcosmk marker module"
39 39
40 40 /* DDI file for dlcosmk ipp module */
41 41
42 42 static int dlcosmk_create_action(ipp_action_id_t, nvlist_t **, ipp_flags_t);
43 43 static int dlcosmk_modify_action(ipp_action_id_t, nvlist_t **, ipp_flags_t);
44 44 static int dlcosmk_destroy_action(ipp_action_id_t, ipp_flags_t);
45 45 static int dlcosmk_info(ipp_action_id_t, int (*)(nvlist_t *, void *), void *,
46 46 ipp_flags_t);
47 47 static int dlcosmk_invoke_action(ipp_action_id_t, ipp_packet_t *);
48 48
49 49 static int dlcosmk_statinit(ipp_action_id_t, dlcosmk_data_t *);
50 50 static int dlcosmk_update_stats(ipp_stat_t *, void *, int);
51 51
52 52 /* Entry points for this IPP module */
53 53 ipp_ops_t dlcosmk_ops = {
54 54 IPPO_REV,
55 55 dlcosmk_create_action, /* ippo_action_create */
56 56 dlcosmk_modify_action, /* ippo_action_modify */
57 57 dlcosmk_destroy_action, /* ippo_action_destroy */
58 58 dlcosmk_info, /* ippo_action_info */
59 59 dlcosmk_invoke_action /* ippo_action_invoke */
60 60 };
61 61
62 62 extern struct mod_ops mod_ippops;
63 63
64 64 /*
↓ open down ↓ |
64 lines elided |
↑ open up ↑ |
65 65 * Module linkage information for the kernel.
66 66 */
67 67 static struct modlipp modlipp = {
68 68 &mod_ippops,
69 69 D_SM_COMMENT,
70 70 &dlcosmk_ops
71 71 };
72 72
73 73 static struct modlinkage modlinkage = {
74 74 MODREV_1,
75 - (void *)&modlipp,
76 - NULL
75 + { (void *)&modlipp, NULL }
77 76 };
78 77
79 78
80 79 int
81 80 _init(void)
82 81 {
83 82 return (mod_install(&modlinkage));
84 83 }
85 84
86 85 int
87 86 _fini(void)
88 87 {
89 88 return (mod_remove(&modlinkage));
90 89 }
91 90
92 91 int
93 92 _info(struct modinfo *modinfop)
94 93 {
95 94 return (mod_info(&modlinkage, modinfop));
96 95 }
97 96
98 97 static int
99 98 dlcosmk_create_action(ipp_action_id_t aid, nvlist_t **nvlpp,
100 99 ipp_flags_t flags)
101 100 {
102 101 nvlist_t *nvlp;
103 102 dlcosmk_data_t *dlcosmk_data;
104 103 char *next_action;
105 104 int err;
106 105 uint32_t bstats, param;
107 106
108 107 ASSERT((nvlpp != NULL) && (*nvlpp != NULL));
109 108
110 109 nvlp = *nvlpp;
111 110 *nvlpp = NULL; /* nvlist should be NULL on return */
112 111
113 112 if ((dlcosmk_data = kmem_zalloc(DLCOSMK_DATA_SZ, KM_NOSLEEP)) == NULL) {
114 113 nvlist_free(nvlp);
115 114 return (ENOMEM);
116 115 }
117 116
118 117 /* parse next action name */
119 118 if ((err = nvlist_lookup_string(nvlp, DLCOSMK_NEXT_ACTION_NAME,
120 119 &next_action)) != 0) {
121 120 nvlist_free(nvlp);
122 121 dlcosmk0dbg(("dlcosmk_create_action: invalid config, "\
123 122 "next_action name missing\n"));
124 123 kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
125 124 return (err);
126 125 }
127 126 if ((dlcosmk_data->next_action =
128 127 ipp_action_lookup(next_action)) == IPP_ACTION_INVAL) {
129 128 nvlist_free(nvlp);
130 129 dlcosmk0dbg(("dlcosmk_create_action: next_action invalid\n"));
131 130 kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
132 131 return (EINVAL);
133 132 }
134 133
135 134 /* parse cos - from the config file */
136 135 if ((err = nvlist_lookup_byte(nvlp, DLCOSMK_COS,
137 136 &dlcosmk_data->usr_pri)) != 0) {
138 137 nvlist_free(nvlp);
139 138 dlcosmk0dbg(("dlcosmk_create_action: invalid config, "\
140 139 "cos missing\n"));
141 140 kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
142 141 return (err);
143 142 }
144 143
145 144 /* parse b_band - mapped from cos */
146 145 if ((err = nvlist_lookup_uint32(nvlp, DLCOSMK_BAND, ¶m)) != 0) {
147 146 nvlist_free(nvlp);
148 147 dlcosmk0dbg(("dlcosmk_create_action: invalid config, "\
149 148 "b_band missing\n"));
150 149 kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
151 150 return (err);
152 151 }
153 152 dlcosmk_data->b_band = param;
154 153
155 154 /* parse dl_priority.dl_max - mapped from cos */
156 155 if ((err = nvlist_lookup_uint32(nvlp, DLCOSMK_PRI, ¶m)) != 0) {
157 156 nvlist_free(nvlp);
158 157 dlcosmk0dbg(("dlcosmk_create_action: invalid config, "\
159 158 "dl_priority missing\n"));
160 159 kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
161 160 return (err);
162 161 }
163 162 dlcosmk_data->dl_max = param;
164 163
165 164 /* parse gather_stats boolean */
166 165 if ((err = nvlist_lookup_uint32(nvlp, IPP_ACTION_STATS_ENABLE, &bstats))
167 166 != 0) {
168 167 dlcosmk_data->gather_stats = B_FALSE;
169 168 } else {
170 169 /* If stats is needed, initialize the stats structure */
171 170 dlcosmk_data->gather_stats = (bstats != 0) ? B_TRUE : B_FALSE;
172 171 if (dlcosmk_data->gather_stats) {
173 172 if ((err = dlcosmk_statinit(aid, dlcosmk_data)) != 0) {
174 173 nvlist_free(nvlp);
175 174 kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
176 175 return (err);
177 176 }
178 177 }
179 178 }
180 179
181 180 /* Free the nvlist */
182 181 nvlist_free(nvlp);
183 182
184 183 /* set action chain reference */
185 184 if ((err = ipp_action_ref(aid, dlcosmk_data->next_action,
186 185 flags)) != 0) {
187 186 dlcosmk0dbg(("dlcosmk_create_action: ipp_action_ref " \
188 187 "returned with error %d\n", err));
189 188 ipp_stat_destroy(dlcosmk_data->stats);
190 189 kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
191 190 return (err);
192 191 }
193 192
194 193 ipp_action_set_ptr(aid, (void *)dlcosmk_data);
195 194 return (0);
196 195 }
197 196
198 197 static int
199 198 dlcosmk_modify_action(ipp_action_id_t aid, nvlist_t **nvlpp, ipp_flags_t flags)
200 199 {
201 200 nvlist_t *nvlp;
202 201 int err = 0;
203 202 uint32_t band, dlpri;
204 203 uint8_t config_type;
205 204 uint8_t cos;
206 205 char *next_action_name;
207 206 ipp_action_id_t next_action;
208 207 dlcosmk_data_t *dlcosmk_data;
209 208 uint32_t bstats;
210 209
211 210 ASSERT((nvlpp != NULL) && (*nvlpp != NULL));
212 211
213 212 nvlp = *nvlpp;
214 213 *nvlpp = NULL; /* nvlist should be NULL when this returns */
215 214
216 215 if ((err = nvlist_lookup_byte(nvlp, IPP_CONFIG_TYPE, &config_type))
217 216 != 0) {
218 217 nvlist_free(nvlp);
219 218 dlcosmk0dbg(("dlcosmk_modify_action: invalid configuration "\
220 219 "type\n"));
221 220 return (err);
222 221 }
223 222
224 223 if (config_type != IPP_SET) {
225 224 nvlist_free(nvlp);
226 225 dlcosmk0dbg(("dlcosmk_modify_action: invalid configuration "\
227 226 "type %d\n", config_type));
228 227 return (EINVAL);
229 228 }
230 229
231 230 dlcosmk_data = (dlcosmk_data_t *)ipp_action_get_ptr(aid);
232 231 ASSERT(dlcosmk_data != NULL);
233 232
234 233 /* parse next action name, if present */
235 234 if ((err = nvlist_lookup_string(nvlp, DLCOSMK_NEXT_ACTION_NAME,
236 235 &next_action_name)) == 0) {
237 236 /* lookup action name to get action id */
238 237 if ((next_action = ipp_action_lookup(next_action_name))
239 238 == IPP_ACTION_INVAL) {
240 239 nvlist_free(nvlp);
241 240 dlcosmk0dbg(("dlcosmk_modify_action: next_action "\
242 241 "invalid\n"));
243 242 return (EINVAL);
244 243 }
245 244 /* reference new action */
246 245 if ((err = ipp_action_ref(aid, next_action, flags)) != 0) {
247 246 nvlist_free(nvlp);
248 247 dlcosmk0dbg(("dlcosmk_modify_action: ipp_action_ref "\
249 248 "returned with error %d\n", err));
250 249 return (err);
251 250 }
252 251 /* unref old action */
253 252 err = ipp_action_unref(aid, dlcosmk_data->next_action, flags);
254 253 ASSERT(err == 0);
255 254 dlcosmk_data->next_action = next_action;
256 255 }
257 256
258 257 /* parse cos, if present */
259 258 if ((err = nvlist_lookup_byte(nvlp, DLCOSMK_COS, &cos)) == 0) {
260 259
261 260 /* parse b_band, mapped from cos */
262 261 if ((err = nvlist_lookup_uint32(nvlp, DLCOSMK_BAND,
263 262 &band)) != 0) {
264 263 nvlist_free(nvlp);
265 264 dlcosmk0dbg(("dlcosmk_modify_action: b_band not "\
266 265 "provided\n"));
267 266 return (err);
268 267 }
269 268
270 269 /* parse dl_priority, mapped from cos */
271 270 if ((err = nvlist_lookup_uint32(nvlp, DLCOSMK_PRI,
272 271 &dlpri)) != 0) {
273 272 nvlist_free(nvlp);
274 273 dlcosmk0dbg(("dlcosmk_modify_action: dl_priority not "\
275 274 "provided\n"));
276 275 return (err);
277 276 }
278 277
279 278 /* Have all the three values, change them */
280 279 dlcosmk_data->usr_pri = cos;
281 280 dlcosmk_data->b_band = band;
282 281 dlcosmk_data->dl_max = dlpri;
283 282 }
284 283
285 284
286 285 /* parse gather_stats boolean, if present */
287 286 if ((err = nvlist_lookup_uint32(nvlp, IPP_ACTION_STATS_ENABLE, &bstats))
288 287 == 0) {
289 288 boolean_t val = (bstats != 0) ? B_TRUE : B_FALSE;
290 289 /* Turning on stats */
291 290 if (!dlcosmk_data->gather_stats && val) {
292 291 if ((err = dlcosmk_statinit(aid, dlcosmk_data)) != 0) {
293 292 nvlist_free(nvlp);
294 293 return (err);
295 294 }
296 295 /* Turning off stats */
297 296 } else if (!val && dlcosmk_data->gather_stats) {
298 297 ipp_stat_destroy(dlcosmk_data->stats);
299 298
300 299 }
301 300 dlcosmk_data->gather_stats = val;
302 301 }
303 302
304 303 /* Free thenvlist */
305 304 nvlist_free(nvlp);
306 305 return (0);
307 306 }
308 307
309 308 static int
310 309 dlcosmk_destroy_action(ipp_action_id_t aid, ipp_flags_t flags)
311 310 {
312 311 dlcosmk_data_t *dlcosmk_data;
313 312 int err;
314 313
315 314 dlcosmk_data = (dlcosmk_data_t *)ipp_action_get_ptr(aid);
316 315 ASSERT(dlcosmk_data != NULL);
317 316
318 317 /* Destroy stats, if gathered */
319 318 if (dlcosmk_data->gather_stats) {
320 319 ipp_stat_destroy(dlcosmk_data->stats);
321 320 }
322 321
323 322 /* unreference the action */
324 323 err = ipp_action_unref(aid, dlcosmk_data->next_action, flags);
325 324 ASSERT(err == 0);
326 325
327 326 kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
328 327 return (0);
329 328 }
330 329
331 330 static int
332 331 dlcosmk_invoke_action(ipp_action_id_t aid, ipp_packet_t *packet)
333 332 {
334 333 dlcosmk_data_t *dlcosmk_data;
335 334 mblk_t *mp = NULL;
336 335 int err;
337 336 ip_priv_t *priv;
338 337
339 338 ASSERT(packet != NULL);
340 339
341 340 /* get mblk from ipp_packet structure */
342 341 mp = ipp_packet_get_data(packet);
343 342 priv = (ip_priv_t *)ipp_packet_get_private(packet);
344 343
345 344 dlcosmk_data = (dlcosmk_data_t *)ipp_action_get_ptr(aid);
346 345 ASSERT(dlcosmk_data != NULL);
347 346
348 347 /* dlcosmk packet as configured */
349 348 if ((err = dlcosmk_process(&mp, dlcosmk_data, priv->ill_index,
350 349 priv->proc)) != 0) {
351 350 return (err);
352 351 } else {
353 352 /* return packet with next action set */
354 353 return (ipp_packet_next(packet, dlcosmk_data->next_action));
355 354 }
356 355 }
357 356
358 357 static int
359 358 dlcosmk_statinit(ipp_action_id_t aid, dlcosmk_data_t *dlcosmk_data)
360 359 {
361 360 int err;
362 361 dlcosmk_stat_t *statp;
363 362
364 363 /* install stats entry */
365 364 if ((err = ipp_stat_create(aid, DLCOSMK_STATS_STRING,
366 365 DLCOSMK_STATS_COUNT, dlcosmk_update_stats, dlcosmk_data,
367 366 &dlcosmk_data->stats)) != 0) {
368 367 dlcosmk0dbg(("dlcosmk_create_action: ipp_stat_create " \
369 368 "returned with error %d\n", err));
370 369 return (err);
371 370 }
372 371
373 372 statp = (dlcosmk_stat_t *)(dlcosmk_data->stats)->ipps_data;
374 373 ASSERT(statp != NULL);
375 374
376 375 if ((err = ipp_stat_named_init(dlcosmk_data->stats, "npackets",
377 376 IPP_STAT_UINT64, &statp->npackets)) != 0) {
378 377 dlcosmk0dbg(("dlcosmk_create_action: ipp_stat_named_init " \
379 378 "returned with error %d\n", err));
380 379 return (err);
381 380 }
382 381
383 382 if ((err = ipp_stat_named_init(dlcosmk_data->stats, "ipackets",
384 383 IPP_STAT_UINT64, &statp->ipackets)) != 0) {
385 384 dlcosmk0dbg(("dlcosmk_create_action: ipp_stat_named_init " \
386 385 "returned with error %d\n", err));
387 386 return (err);
388 387 }
389 388
390 389 if ((err = ipp_stat_named_init(dlcosmk_data->stats, "epackets",
391 390 IPP_STAT_UINT64, &statp->epackets)) != 0) {
392 391 dlcosmk0dbg(("dlcosmk_create_action: ipp_stat_named_init " \
393 392 "returned with error %d\n", err));
394 393 return (err);
395 394 }
396 395
397 396 if ((err = ipp_stat_named_init(dlcosmk_data->stats, "usr_pri",
398 397 IPP_STAT_INT32, &statp->usr_pri)) != 0) {
399 398 dlcosmk0dbg(("dlcosmk_create_action: ipp_stat_named_init " \
400 399 "returned with error %d", err));
401 400 return (err);
402 401 }
403 402
404 403 if ((err = ipp_stat_named_init(dlcosmk_data->stats, "b_band",
405 404 IPP_STAT_INT32, &statp->b_band)) != 0) {
406 405 dlcosmk0dbg(("dlcosmk_create_action: ipp_stat_named_init " \
407 406 "returned with error %d\n", err));
408 407 return (err);
409 408 }
410 409
411 410 if ((err = ipp_stat_named_init(dlcosmk_data->stats, "dl_max",
412 411 IPP_STAT_INT32, &statp->dl_max)) != 0) {
413 412 dlcosmk0dbg(("dlcosmk_create_action: ipp_stat_named_init " \
414 413 "returned with error %d\n", err));
415 414 return (err);
416 415 }
417 416
418 417 ipp_stat_install(dlcosmk_data->stats);
419 418 return (0);
420 419 }
421 420
422 421 static int
423 422 dlcosmk_update_stats(ipp_stat_t *sp, void *arg, int rw)
424 423 {
425 424 dlcosmk_data_t *dlcosmk_data = (dlcosmk_data_t *)arg;
426 425 dlcosmk_stat_t *snames = (dlcosmk_stat_t *)sp->ipps_data;
427 426 uint32_t upri, bband;
428 427
429 428 ASSERT(dlcosmk_data != NULL);
430 429 ASSERT(snames != NULL);
431 430
432 431 upri = dlcosmk_data->usr_pri;
433 432 bband = dlcosmk_data->b_band;
434 433
435 434 (void) ipp_stat_named_op(&snames->npackets, &dlcosmk_data->npackets,
436 435 rw);
437 436 (void) ipp_stat_named_op(&snames->ipackets, &dlcosmk_data->ipackets,
438 437 rw);
439 438 (void) ipp_stat_named_op(&snames->epackets, &dlcosmk_data->epackets,
440 439 rw);
441 440 (void) ipp_stat_named_op(&snames->usr_pri, &upri, rw);
442 441 (void) ipp_stat_named_op(&snames->b_band, &bband, rw);
443 442 (void) ipp_stat_named_op(&snames->dl_max, &dlcosmk_data->dl_max, rw);
444 443
445 444 return (0);
446 445 }
447 446
448 447 /* ARGSUSED */
449 448 static int
450 449 dlcosmk_info(ipp_action_id_t aid, int (*fn)(nvlist_t *, void *), void *arg,
451 450 ipp_flags_t flags)
452 451 {
453 452 nvlist_t *nvlp;
454 453 dlcosmk_data_t *dlcosmk_data;
455 454 char *next_action;
456 455 int err;
457 456
458 457 ASSERT(fn != NULL);
459 458
460 459 dlcosmk_data = (dlcosmk_data_t *)ipp_action_get_ptr(aid);
461 460 ASSERT(dlcosmk_data != NULL);
462 461
463 462 /* allocate nvlist to be passed back */
464 463 if ((err = nvlist_alloc(&nvlp, NV_UNIQUE_NAME, KM_NOSLEEP)) != 0) {
465 464 dlcosmk0dbg(("dlcosmk_info: error allocating memory\n"));
466 465 return (err);
467 466 }
468 467
469 468 /* look up next action with the next action id */
470 469 if ((err = ipp_action_name(dlcosmk_data->next_action,
471 470 &next_action)) != 0) {
472 471 dlcosmk0dbg(("dlcosmk_info: next action not available\n"));
473 472 nvlist_free(nvlp);
474 473 return (err);
475 474 }
476 475
477 476 /* add next action name */
478 477 if ((err = nvlist_add_string(nvlp, DLCOSMK_NEXT_ACTION_NAME,
479 478 next_action)) != 0) {
480 479 dlcosmk0dbg(("dlcosmk_info: error adding next action\n"));
481 480 nvlist_free(nvlp);
482 481 kmem_free(next_action, (strlen(next_action) + 1));
483 482 return (err);
484 483 }
485 484
486 485 /* free action name */
487 486 kmem_free(next_action, (strlen(next_action) + 1));
488 487
489 488 /* add config type */
490 489 if ((err = nvlist_add_byte(nvlp, IPP_CONFIG_TYPE, IPP_SET)) != 0) {
491 490 dlcosmk0dbg(("dlcosmk_info: error adding config. type\n"));
492 491 nvlist_free(nvlp);
493 492 return (err);
494 493 }
495 494
496 495 /* just give the cos, since that is what is provided in the config */
497 496 if ((err = nvlist_add_byte(nvlp, DLCOSMK_COS, dlcosmk_data->usr_pri))
498 497 != 0) {
499 498 dlcosmk0dbg(("dlcosmk_info: error adding cos\n"));
500 499 nvlist_free(nvlp);
501 500 return (err);
502 501 }
503 502
504 503 /* add gather stats boolean */
505 504 if ((err = nvlist_add_uint32(nvlp, IPP_ACTION_STATS_ENABLE,
506 505 (dlcosmk_data->gather_stats ? 1 : 0))) != 0) {
507 506 dlcosmk0dbg(("dlcosmk_info: error adding stats status\n"));
508 507 nvlist_free(nvlp);
509 508 return (err);
510 509 }
511 510
512 511 /* call back with nvlist */
513 512 err = fn(nvlp, arg);
514 513
515 514 nvlist_free(nvlp);
516 515 return (err);
517 516 }
↓ open down ↓ |
431 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX